@devexperts/dxcharts-lite 2.7.10 → 2.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chart/chart.js +2 -1
- package/dist/chart/components/chart/price-formatters/treasury-price.formatter.d.ts +1 -0
- package/dist/chart/components/chart/price-formatters/treasury-price.formatter.js +1 -0
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.d.ts +2 -2
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.js +2 -4
- package/dist/chart/components/pane/pane.component.d.ts +1 -1
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.d.ts +2 -1
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.js +7 -2
- package/dist/chart/model/data-series.model.d.ts +4 -4
- package/dist/chart/model/data-series.model.js +3 -2
- package/dist/dxchart.min.js +1 -1
- package/package.json +1 -1
package/dist/dxchart.min.js
CHANGED
|
@@ -21,4 +21,4 @@ ${s?` <p style="position: absolute; visibility: hidden;">If you have any sugge
|
|
|
21
21
|
`:""} </div>
|
|
22
22
|
</div>
|
|
23
23
|
</div>
|
|
24
|
-
`;function Bl(s){const t=document.createElement("template");return t.innerHTML=Ol(s.devexpertsPromoLink),t}function Rl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),Ll(t))return t;throw new Error("Some chart elements are missing")}function Fl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const Hl=s=>t=>s?new Date(t).setHours(0,0,0,0):t,Te=(s,t={},e,n=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=Hl(!!c),u=d(s),f=d((r=(i=ce(e))==null?void 0:i.timestamp)!=null?r:0),p=d((a=(o=yt(e))==null?void 0:o.timestamp)!=null?a:0);return u>p?h?{index:e.length-1+Math.ceil((u-p)/n),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:it((u-f)/n),exact:!0}:{index:-1,exact:!0}:Ot(e,u,v=>d(v.timestamp))},xi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},_i={paintConfig:[xi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var kl=Object.defineProperty,Pi=Object.getOwnPropertySymbols,jl=Object.prototype.hasOwnProperty,Yl=Object.prototype.propertyIsEnumerable,Ti=(s,t,e)=>t in s?kl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Nl=(s,t)=>{for(var e in t||(t={}))jl.call(t,e)&&Ti(s,e,t[e]);if(Pi)for(var e of Pi(t))Yl.call(t,e)&&Ti(s,e,t[e]);return s};class Xl{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Nl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:xi).color;return{textColor:Jt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function zl(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>Wl(a,l,e)).filter(Wn).sort(Vl),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<n.length;a++){const l=n[a],c=n[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const Wl=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,Vl=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var Ul=Object.defineProperty,Gl=Object.defineProperties,Zl=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,$l=Object.prototype.hasOwnProperty,Kl=Object.prototype.propertyIsEnumerable,Ai=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ei=(s,t)=>{for(var e in t||(t={}))$l.call(t,e)&&Ai(s,e,t[e]);if(Mi)for(var e of Mi(t))Kl.call(t,e)&&Ai(s,e,t[e]);return s},Ii=(s,t)=>Gl(s,Zl(t));const te={MAIN:"MAIN"};class ql extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new R,this.animFrameId=`anim_cache_${bt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,vt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),be(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=Ct(Object.values(i).map(l=>l.getUnorderedLabels())),o=Ct(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=zl(o,n);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return Ii(Ei({},t),{labels:t.labels.map((n,i)=>Ii(Ei({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Hs=()=>{Ke.removeEventListener("change",Hs),Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),Ke.addEventListener("change",Hs)};Ke.addEventListener("change",Hs);const Jl=()=>Bt,Bp=s=>round(Bt*s)/Bt,Mt=s=>it(Bt*s)/Bt,ks=s=>Ma(Bt*s)/Bt,ee=s=>JSON.parse(JSON.stringify(s));function js(s){return Object.entries(s)}const Di=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Li(s){return Object.keys(s)}function Oi(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Oi(s[e[i]],t[e[i]]))return!1;return!0}const Ql=s=>Object.keys(s).length===0&&s.constructor===Object;function Bi(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new R}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,p=!1,v=!1,P=function(){d==null||d.unsubscribe(),d=void 0},_=function(){P(),h=u=void 0,p=v=!1},D=function(){var O=h;_(),O==null||O.unsubscribe()};return N(function(O,j){f++,!v&&!p&&P();var H=u=u!=null?u:e();j.add(function(){f--,f===0&&!v&&!p&&(d=Ys(D,l))}),H.subscribe(j),!h&&f>0&&(h=new ve({next:function(B){return H.next(B)},error:function(B){v=!0,P(),d=Ys(_,i,B),H.error(B)},complete:function(){p=!0,P(),d=Ys(_,o),H.complete()}}),Dt(O).subscribe(h))})(c)}}function Ys(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new ve({next:function(){i.unsubscribe(),s()}});return Dt(t.apply(void 0,I([],m(e)))).subscribe(i)}}const qe=(s,t)=>s/t,ft=(s,t)=>s/t,Nt=(s,t)=>s*t,Ri=(s,t)=>(s-t)*100/t,Fi=(s,t)=>s*t/100+t,Hi=s=>Math.log2(s),Ns=s=>Math.pow(2,s);class tc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new R,this.xChanged=this.changed.pipe(ht(()=>({start:this.xStart,end:this.xEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.yChanged=this.changed.pipe(ht(()=>({start:this.yStart,end:this.yEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ft(t-this.xStart,this.zoomX)}xPixels(t){return ft(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ft(t-this.yStart,this.zoomY):e.y+e.height-ft(t-this.yStart,this.zoomY)}yPixels(t){return ft(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Nt(e+ft(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Nt(n+ft(this.yStart,this.zoomY),this.zoomY):Nt(e.height-n+ft(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return qe(e-t,this.getBounds().width)}calculateZoomY(t,e){return qe(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const ec=(s,t)=>!Li(s).some(e=>s[e]!==t[e]);class sc{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Ot(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Ot(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class ki{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new sc(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ri(t,n);case"logarithmic":return t<=0?t:Hi(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return Fi(t,this.getBaseline());case"logarithmic":return Ns(t);case"regular":return t}}}var nc=Object.defineProperty,ic=Object.defineProperties,rc=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,oc=Object.prototype.hasOwnProperty,ac=Object.prototype.propertyIsEnumerable,Yi=(s,t,e)=>t in s?nc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ni=(s,t)=>{for(var e in t||(t={}))oc.call(t,e)&&Yi(s,e,t[e]);if(ji)for(var e of ji(t))ac.call(t,e)&&Yi(s,e,t[e]);return s},lc=(s,t)=>ic(s,rc(t));class Me{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Me(this.centerUnit,this.close)}}class Xi extends X{constructor(t,e,n,i,r=ee(_i)){var o;super(),this.extentComponent=t,this.id=e,this.htId=n,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=a=>{var l;return(l=this.config.paintConfig[a])!=null?l:this.config.paintConfig[0]},this.getBaseline=(a=this.dataIdxStart)=>{var l,c,h;return(l=this.visualPoints[a])!=null&&l.close&&((c=this.visualPoints[a])==null?void 0:c.close)>=0?(h=this.visualPoints[a])==null?void 0:h.close:1},this.getTextForPoint=a=>`${a.close}`,this.getLastVisualSeriesPoint=()=>{const a=this.visualPoints,l=Ot(a,this.scale.xEnd,c=>c.centerUnit).index;return a[l]},this.getLastDataSeriesPoint=()=>{const a=this.visualPoints;return yt(a)},this.config=Tt(r,_i),this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Xl(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=hc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Gn(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=Gn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const n=Ni({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=n.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(te.MAIN,a,r),n.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(te.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=Ot(this.visualPoints,t,r=>r.centerUnit).index,i=Ot(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Ua(this.visualPoints2D,n,i)}}const cc=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},hc=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=cc(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return lc(Ni({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),dc=s=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(s);return dt.makeDecimal(s,i)};class Je extends Me{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),n=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const de=60,Ae=(s,t,e=de)=>{const n=zi(s,t,e);return{id:ei(n,n),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:n,volume:NaN,expansion:!0,idx:t}},uc=(s,t,e=de)=>({close:NaN,timestamp:zi(s,t,e)});function zi(s,t,e=de){var n,i;const r=ye(t);if(s.length===0)return 0;const o=yt(s);if(r>=s.length&&o)return Wi(o,s.length-1,r,e);const a=ce(s);return r<0&&a?Wi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Wi=(s,t,e,n=de)=>s.timestamp+(e-(t!=null?t:0))*n,Vi=(s,t,e,n,i=de)=>{const r=Ae(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Je(o,e,r.open,r.close,r.lo,r.hi,Ue(r.open,r.close),r)},fc=(s,t,e,n,i=de)=>{const r=uc(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Me(o,r.close)};class gc{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new R,this.dataSetSubject=new R,this.dataRemovedSubject=new R,this.dataPrependSubject=new R,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},n=this.mainDataPoints){const i=Te(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=Fl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Vi(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):fc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var pc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,Gi=(s,t,e)=>t in s?pc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,bc=(s,t)=>{for(var e in t||(t={}))mc.call(t,e)&&Gi(s,e,t[e]);if(Ui)for(var e of Ui(t))vc.call(t,e)&&Gi(s,e,t[e]);return s};class Cc{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={},this.isColorsChanged=()=>!Oi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=bc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const yc=(s,t,e,n,i,r,o)=>{const a=Jl(),l=[e*a,n*a,i*a,r*a];let c=s.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=it(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Zi=(s,{x:t,width:e,activeCandle:n})=>new Je(t,e,s.open,s.close,s.hi,s.lo,Ue(s.open,s.close),s,!0,Xs(s,n)),wc=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,rl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},$i=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,Ue((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},Sc=$i,Xs=(s,t)=>{const e=t&&t.id===s.id;return e!=null?e:!1},Ki=()=>Ds,se=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=se.getPriceIncrement(e||s,t);return dt.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=se.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*se.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<se.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*se.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return se.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Rt=se;Rt.DEFAULT_INCREMENT=.01,Rt.DEFAULT_PRECISION=2,Rt.RELATIVE_EPS=1e-8,Rt.MAXIMUM_PRECISION=10;const xc=(s,t)=>{var e;const n=(e=yt(t))!=null?e:1;return Math.pow(10,-n)};var _c=Object.defineProperty,Pc=Object.defineProperties,Tc=Object.getOwnPropertyDescriptors,qi=Object.getOwnPropertySymbols,Mc=Object.prototype.hasOwnProperty,Ac=Object.prototype.propertyIsEnumerable,Ji=(s,t,e)=>t in s?_c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ec=(s,t)=>{for(var e in t||(t={}))Mc.call(t,e)&&Ji(s,e,t[e]);if(qi)for(var e of qi(t))Ac.call(t,e)&&Ji(s,e,t[e]);return s},Ic=(s,t)=>Pc(s,Tc(t));const Dc=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Qi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return Ic(Ec({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Qi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},Lc=400,tr=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:Lc,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},We,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class Oc{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){Bc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const Bc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=er(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function er(s){if(s.length===0)return Rc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const Rc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),sr=(s,t)=>s/t,Fc=(s,t)=>s/t,Hc=(s,t)=>s*t,nr=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.yEnd-s.yStart;t.zoomY=Fc(t.zoomX,i);const o=t.zoomY/n,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},kc=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.xEnd-s.xStart;t.zoomX=Hc(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},jc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},Yc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},ir=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=s.calculateZoomX(t.xStart,t.xEnd),t},Nc=(s,t,e,n)=>ir(s,t,1,e,n);var Xc=Object.defineProperty,zc=Object.defineProperties,Wc=Object.getOwnPropertyDescriptors,rr=Object.getOwnPropertySymbols,Vc=Object.prototype.hasOwnProperty,Uc=Object.prototype.propertyIsEnumerable,or=(s,t,e)=>t in s?Xc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Qe=(s,t)=>{for(var e in t||(t={}))Vc.call(t,e)&&or(s,e,t[e]);if(rr)for(var e of rr(t))Uc.call(t,e)&&or(s,e,t[e]);return s},Gc=(s,t)=>zc(s,Wc(t));const Zc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class ar extends tc{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=ee(t.scale),this.autoScaleModel=new Oc(this),this.offsets=this.config.components.offsets}doActivate(){super.doActivate(),this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=Qe(Qe({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();ir(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();Nc(this,n,e,t),this.zoomXTo(n,t,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e,n){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),n?this.apply(o):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const n=this.getBounds().width,i=.001;if(n>0){const r=qe(this.config.components.chart.minCandles,n),a=t!==r&&t-r<=i&&e,l=qe(n/this.config.components.chart.minWidth,n),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,n=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Gc(Qe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,l)))}setYScale(t,e,n=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio){this.setLockedYScale(t,e,n,i);return}super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,n=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,n);const o=this.export(),a=this.scalePostProcessor(i,o);kc(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),n=Qe({},e);this.haltAnimation(),jc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Yc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),ec(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}}class $c extends ar{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Kc=Ge().colors;class Ut extends Xi{constructor(t,e,n,i,r,o,a,l,c=Kc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Zc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new R,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=Dc(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=Rt.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const n=Ot(this.visualPoints,t,r=>r.startUnit).index,i=Ot(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=yt(this.dataPoints);t&&(this.lastPriceMovement=Ue(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Qi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Ki;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,p=(i=this.candlesTransformersByChartType[r])!=null?i:Zi;o.push(p(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ds}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Rp(s){switch(s){case"line":case"area":return!0;default:return!1}}class qc{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=!!i.color;if(n instanceof Ut){const a=Ct(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=n.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:n.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=n.extentComponent.getBounds(),c=a[0],h=n.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],p=a[d],v=n.view.toX(p.centerUnit),P=n.view.toY(p.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(it(v),_),t.moveTo(it(v),P);else if(f===void 0){t.lineTo(it(v),P),t.stroke(),t.lineTo(it(v),_),t.lineTo(it(h),_),t.closePath();let D;i.color?t.fillStyle=i.color:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(D=t.createLinearGradient(0,0,0,l.height),D.addColorStop(0,n.colors.areaTheme.startColor),D.addColorStop(1,n.colors.areaTheme.stopColor),D):"",o||t.fill()}else t.lineTo(v,P)}}}}function lr(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Jc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,p=c==="right"?h:-h,v=h;s.save(),s.beginPath(),l?s.moveTo(r+p,o):s.moveTo(r,o),l?(s.lineTo(r+f-p,o),s.quadraticCurveTo(r+f,o,r+f,o-v),s.lineTo(r+f,e+v),s.quadraticCurveTo(r+f,e,r+f-p,e),s.lineTo(t+p,e)):(s.lineTo(r+f,o),s.lineTo(r+f,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-p/3,e+v/3),s.lineTo(n+p/3,i-v/3),s.quadraticCurveTo(n,i,n+p/3,i+v/3),s.lineTo(r-p/3,o-v/3),s.quadraticCurveTo(r,o,r+p/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Qc(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function ne(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function cr(s,t,e){const n=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);s.fillRect(n,i,r,o)}const Gt=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Fp=s=>Array.isArray(s[0])?s:[s];class th{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Gt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const n=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||n&&!Ql(n)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const ie=(s,t,e,n,i=t)=>{n.hoverWidth?s.lineWidth=n.hoverWidth:e.highlighted?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class eh{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.color)t.strokeStyle=e.color;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.barLineWidth,n,i),ne(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=n.view.toX(o.centerUnit),l=n.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(n.view),f=Mt(n.view.xPixels(o.width)/2),p=n.view.toY(o.close),v=n.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,p),t.lineTo(a+f,p),t.moveTo(l,v),t.lineTo(a,v),t.stroke()}})}}}class sh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Ut){const r=Ct(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],p=n.view.toX(c.centerUnit),v=n.view.toX(d.centerUnit),P=n.view.toY(d.close),_=u?n.view.toY(u.close)<l:!1,D=P<l;if(u!==void 0&&_!==D){hr(t,n,i,_);const O=n.view.toX(u.centerUnit),j=n.view.toY(u.close),H=v-O,B=P-j,Y=H/B,W=P-l,G=Y*W,V=O+(H-G);t.lineTo(V,l),t.stroke(),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(V,l)}u===void 0?(t.beginPath(),t.moveTo(v,P)):f===void 0?(hr(t,n,i,D),t.lineTo(v,P),t.stroke(),t.lineTo(v,l),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(p,l),t.lineTo(v,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(v,P)}}}}const hr=(s,t,e,n)=>{e.color?(s.fillStyle=e.color,s.strokeStyle=e.color):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class nh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),ne(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=n.view.toX(i.startUnit),d=n.view.xPixels(i.width),u=i.bodyHeight(n.view),[f,p,v,P]=i.yBodyKeyPoints(n.view),_=p===v?p+1:v,D=f===P?f+1:P,O=l[`${a}Color`],j=a==="none"?O:l[`${a}WickColor`];t.fillStyle=O,e.color?t.strokeStyle=e.color:t.strokeStyle=j;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.moveTo(h+1,p),t.lineTo(h+1,_),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,f,D,p,_),c||(t.beginPath(),t.moveTo(h+Y,p),t.lineTo(h+Y,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,p+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,f,D,p,_);const W=this.config.candlePaddingPercent,G=Math.max(d*W/2,this.pixelLength),V=h+G,U=d-G*2;if(!c){e.color&&(t.fillStyle=e.color);const Z=e.hoverWidth?d+G:U,$=e.hoverWidth?u+e.hoverWidth+G:u;t.fillRect(V,p,Z,$)}H&&this.drawCandleBorder(t,e,l,i,V+this.halfLineWidthCU,p+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class ih{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),f=n.view.toY(l.close),p=Mt(n.view.xPixels(l.width));t.fillRect(u,f,p,h);const v=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(v.addColorStop(0,d[`${c}Cap`]),v.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=v),p===0?(t.beginPath(),t.strokeStyle=v,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,p,a-f-h)}}}}class rh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),f=n.view.toX(c.centerUnit),p=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,p),t.stroke()}}}}const oh=1.5;class ah{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=i.hoverWidth?i.hoverWidth/2:oh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of Ct(e)){t.beginPath();const l=n.view.toX(a.centerUnit),c=n.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const lh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class ch{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Gt(t,this.chartBounds())}isChartTypeAllowed(){return lh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Gt(t,e.scale.getBounds())}}class hh{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(it(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(ft(h.width,u)),p=Mt(h.bodyHeight(this.chartModel.scale)),v=h.xCenter(this.chartModel.scale)-f/2,P=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,D=Mt(f*_/2),O=v+D,j=f-D*2;t.fillRect(O,P,j,p)}})})}}const dh=(s,t,e,n)=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);n===0?t.moveTo(o,a):t.lineTo(o,a)},dr=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{dh(n,t,e,i)})},uh=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,fh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,gh=/^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*[)]$/,ph=s=>uh.exec(s),mh=s=>fh.exec(s),Hp=s=>gh.exec(s);function vh(s){const t=ph(s)||mh(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const ur={};function bh(s,t){let e=ur[s+t];if(!e){const n=vh(s);e=n&&"rgba("+n.join(",")+","+t+")",ur[s+t]=e}return e}class Ch{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.color)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(fr(r.config.type)&&fr(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{var f,p;const v=Math.min(d.length,(p=(f=h[u])==null?void 0:f.length)!=null?p:0);for(let D=0;D<v;D++){const O=[d[D].clone(),h[u][D].clone()];a.push({diffPoints:O})}const P=l.getPaintConfig(u).color,_=r.getPaintConfig(o).color;this.drawDifference(t,P,_,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[f,p]=u.diffPoints;l.push(f),c.push(p)});const h=this.mapDataSeriesDiffPointsIntoPoints(l,r.view),d=this.mapDataSeriesDiffPointsIntoPoints(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=ce(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=yt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,f)=>{f===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.color?r.color:bh(e||"#383838",.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(n=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const fr=s=>s==="DIFFERENCE";class yh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ie(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class wh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}}class Sh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class xh{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=Pt(d,t,c),f=jt(c,t),p=n.view.toX(h.centerUnit)-u/2,v=n.view.toY(h.close)+f;t.fillText(d,p,v)})}),t.restore()}}class _h{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const zs="resized_local",ts="draw",kp="draw_last_candle",ue={width:20,height:20};class gr{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Ws;var a;i.push(this),this.parent=Mh(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ue.width&&this.height>ue.height}}const Ws={name:"candle"},Ph={candle:Ws,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function Th(s,t,e,n,i,r,o){var a;const l=re(s,t,i,r,o,e);return l.type=(a=Ph[n])!=null?a:Ws,l}function re(s,t,e,n,i,r,o){const a=new gr(s,t,n,i,r,o);return pr(a,e),a}function pr(s,t){const e=s.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function Mh(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const es="HIT_TEST_",Xp=null;class Ah{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${bt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(es)!==-1&&this.drawersMap[n].draw()})},t.on(ts,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),Yn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(es)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(es)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}za(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ue.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ue.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=bt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=Vn(this.drawingOrder,t)}}class mr{static paneResizer(t){return`PANE_RESIZER_${t}`}}const Eh=7;class Ih{constructor(t,e,n,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Gt(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:Eh};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const vr={dragPredicate:()=>!0};class br extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class ss extends br{constructor(t,e,n,i,r=vr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const Dh="BASELINE_RESIZER";class Lh extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=n,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Rs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&xl(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new ss(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[Dh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const Oh=16,Bh=s=>{var t;try{const e=Ce(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=Ce(s.hi,Math.max(s.open,s.close),e),i=Ce(s.lo,Math.min(s.open,s.close),e),r=Ce(s.open,s.lo,e),o=Ce(s.close,s.hi,e),a=Number.isNaN(s.vwap)?void 0:s.vwap;return{id:s.id,hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility,vwap:a,typicalPrice:s.typicalPrice}}catch(e){console.warn(e);return}},Ee=(s,t=0)=>{for(let e=t;e<s.length;++e)s[e].idx=e},Cr=s=>{s.forEach(t=>{t.idx=void 0})},Rh=s=>s!==void 0;class Fh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0),o=Ct(e),a=n.getPaintConfig(0);ie(t,a.lineWidth,n,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,p,v,P,_;const D=Hh(o,c),O=D&&l.close<D;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(O?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){O&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!O&&l.close<0&&(t.strokeStyle=(p=i.color)!=null?p:a.multiplyColors[1]||a.color||"#FF00FF"),O&&l.close>0&&(t.strokeStyle=(v=i.color)!=null?v:a.multiplyColors[2]||a.color||"#FF00FF"),!O&&l.close>0&&(t.strokeStyle=(P=i.color)!=null?P:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const j=n.view.toX(l.centerUnit),H=n.view.toY(l.close);t.moveTo(j,r),t.lineTo(j,H),t.stroke()})}}const Hh=(s,t)=>{do t--;while(t>=0&&!isFinite(s[t]&&s[t].close));return s[t]?s[t].close:void 0},kh=(s,t)=>{let e=0;return(...n)=>{clearTimeout(e),e=+setTimeout(()=>s(...n),t)}};var jh=Object.defineProperty,yr=Object.getOwnPropertySymbols,Yh=Object.prototype.hasOwnProperty,Nh=Object.prototype.propertyIsEnumerable,wr=(s,t,e)=>t in s?jh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Sr=(s,t)=>{for(var e in t||(t={}))Yh.call(t,e)&&wr(s,e,t[e]);if(yr)for(var e of yr(t))Nh.call(t,e)&&wr(s,e,t[e]);return s};class Xh{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class zh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=p,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=P=>{var _;return(_=this.barTypeValues.find(D=>D===P))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Lh(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const v=new Ih(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(v,es+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new Cc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new th(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(kh(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Oh))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Zi),this.registerCandlesTransformer("trend",$i),this.registerCandlesTransformer("hollow",wc),this.registerCandlesTransformer("line",Sc)}get barTypeValues(){return Li(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new nh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new eh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new rh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new ah(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new qc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new sh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new ih(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new wh),this.registerDataSeriesTypeDrawer("HISTOGRAM",new yh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Fh),this.registerDataSeriesTypeDrawer("POINTS",new Sh),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new ch(new hh(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new xh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new _h),this.registerDataSeriesTypeDrawer("DIFFERENCE",new Ch)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(Sr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=Sr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Cr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,n=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,n)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!Rt.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Rt.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}class xr extends Ut{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var Wh=Object.defineProperty,_r=Object.getOwnPropertySymbols,Vh=Object.prototype.hasOwnProperty,Uh=Object.prototype.propertyIsEnumerable,Pr=(s,t,e)=>t in s?Wh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gh=(s,t)=>{for(var e in t||(t={}))Vh.call(t,e)&&Pr(s,e,t[e]);if(_r)for(var e of _r(t))Uh.call(t,e)&&Pr(s,e,t[e]);return s};const Zh=(s,t,e,n)=>{var i,r,o,a;const l=Gh({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ga(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Nt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},$h=s=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const n=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),i=n[0],r=n[n.length-1];s.setXScale(i.startUnit,r.startUnit+r.width+s.offsets.right)}e.yScale&&s.doAutoScale(!0),s.fireChanged()}},Kh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var qh=Object.defineProperty,Jh=Object.defineProperties,Qh=Object.getOwnPropertyDescriptors,Tr=Object.getOwnPropertySymbols,td=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,Mr=(s,t,e)=>t in s?qh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ie=(s,t)=>{for(var e in t||(t={}))td.call(t,e)&&Mr(s,e,t[e]);if(Tr)for(var e of Tr(t))ed.call(t,e)&&Mr(s,e,t[e]);return s},Vs=(s,t)=>Jh(s,Qh(t));class sd{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,n)=>Vs(Ie({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=Vs(Ie({},ee(this.config.colors)),{lineTheme:Ie({},n.lineTheme),areaTheme:Ie({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=Vs(Ie({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var nd=Object.defineProperty,Ar=Object.getOwnPropertySymbols,id=Object.prototype.hasOwnProperty,rd=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?nd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ns=(s,t)=>{for(var e in t||(t={}))id.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))rd.call(t,e)&&Er(s,e,t[e]);return s};class od extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new R,this.mainInstrumentChangedSubject=new R,this.offsetsChanged=new R,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(Bh).filter(Rh),{sortCandles:p}=this.config.components.chart;return p?p(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new sd(this.config);const d=new xr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Xh,this.candlesTransformersByChartType,this.candleWidthByChartType,ns({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Zh(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=$h(o),this.timeFrameViewportTransformer=Kh(o,this),this.pane=this.paneManager.panes[q]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(q)).pipe(At(bi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ue.width&&t.height>ue.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),n=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Nt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=Nt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return Cr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Ee(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=ns({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Dr(this.mainCandleSeries.dataPoints,i),o=r.candles;Ee(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),p=Dr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(p,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(n=>{const i=Ot(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=ns(ns({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Ut(this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)n.push(a);else{let l=Ir(e,o,-1);if(l||(l=Ir(e,o,1)),l){const c=ol(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Tt(t,Ge().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=Ot(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=ye((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Ae(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Ae(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(n=>n.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(n=>n.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return yt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return yt(t)}getMaxCandlesFitLength(){return it(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=Te(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Te(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const p=f>=o.length-1,v=c&&h.timestamp<c.timestamp;if(p&&!v&&(c=h),a&&c&&n&&l){const P=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Ki;this.scale.moveXStart(this.scale.xStart+P(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return vt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const n=t.slice(),i=[];return e.forEach(r=>{const a=Te(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Ee(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const n=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(n<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,n).concat(e.dataPoints.slice(i+1)),Ee(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(n=>this.removeCandleByIdx(this.candleIdxFromId(n,e)))}addCandlesById(t,e,n){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=n.dataPoints.slice(0,i),o=n.dataPoints.slice(i);n.dataPoints=r.concat(t).concat(o),Ee(n.dataPoints),n.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Ir=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Dr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=Te(r.timestamp,{extrapolate:!0},s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class fe{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Us{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Di(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=Di(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=Ct(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class ad{constructor(t,e,n,i){this.model=t,this.config=e,this.crossToolCanvasModel=n,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var ld=Object.defineProperty,cd=Object.defineProperties,hd=Object.getOwnPropertyDescriptors,Lr=Object.getOwnPropertySymbols,dd=Object.prototype.hasOwnProperty,ud=Object.prototype.propertyIsEnumerable,Or=(s,t,e)=>t in s?ld(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fd=(s,t)=>{for(var e in t||(t={}))dd.call(t,e)&&Or(s,e,t[e]);if(Lr)for(var e of Lr(t))ud.call(t,e)&&Or(s,e,t[e]);return s},gd=(s,t)=>cd(s,hd(t));class pd extends X{constructor(t,e,n,i,r,o){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?kt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(kt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,q]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:n,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(x.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=n.x+l,d=n.y+c,u=o.y+a,f=o.y+o.height-a,p=h<a?a:h>o.width-a?o.width-a:h,v=d<u?u:d>f?f:d,P=(e=this.hoverProducer.createHover(p,v,t.paneId))!=null?e:t,_=gd(fd({},P),{x:p,y:v});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const Et=4;function md(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p;const v=r.align,P=(l=i.textFont)!=null?l:Qt(r),_=i.bgColor,D=(c=i.textColor)!=null?c:Jt(_,o.labelTextColor,o.labelInvertedTextColor),O=(h=i.paddingTop)!=null?h:Et,j=(d=i.paddingBottom)!=null?d:Et,H=(u=i.paddingEnd)!=null?u:Et,B=ye(jt(P,s)/2),Y=n-B-O,G=n+B+j-Y;if(a&&!is(n,t,G))return;s.save(),s.fillStyle=_,s.strokeStyle=_;const V=ye(t.width/6),U=v==="right"?t.x:t.x+t.width,Z=v==="right"?U+V:U-V,$=r.labelBoxMargin.end,et=$-H,tt=t.width-V-et;Jc(s,Z,Y,U,Y+ye(G/2),Z,Y+G,tt,(p=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?p:!1,v),s.fillStyle=D,s.font=P;const Q=v==="right"?t.x+t.width-Pt(e,s,P)-$:t.x+$;s.fillText(e,Q,n+B-1),s.restore()}function vd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P,_,D;const O=r.align,j=(l=i.textFont)!=null?l:Qt(r),H=i.bgColor,B=(c=i.textColor)!=null?c:Jt(H,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,W=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Et,G=(p=(f=i.paddingBottom)!=null?f:Y==null?void 0:Y.bottom)!=null?p:Et,V=(P=(v=i.paddingEnd)!=null?v:Y==null?void 0:Y.end)!=null?P:Et,U=i.paddingStart,Z=jt(j,s),$=n-Z/2-W,tt=n+Z/2+G-$,Q=(D=i.rounded)!=null?D:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!is(n,t,tt))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const rt=r.labelBoxMargin.end;s.font=j;const lt=Pt(e,s,j),ot=rt-V,xt=U!==void 0?lt+U+V:t.width-ot,Vt=O==="right"?t.x+t.width-ot-xt:t.x+ot,me=O==="right"?t.x+t.width-lt-rt:rt;Q?lr(s,Vt,$,xt,tt,4,!0):s.fillRect(Vt,$,xt,tt),s.fillStyle=B,s.fillText(e,me,n+Z/2-1),s.restore()}function bd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P;const _=r.align,D=(l=i.textFont)!=null?l:Qt(r),O=o.backgroundColor,j=(c=i.textColor)!=null?c:Jt(O,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Et,Y=(p=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?p:Et,W=(P=(v=i.paddingEnd)!=null?v:H==null?void 0:H.end)!=null?P:Et,G=i.paddingStart,V=jt(D,s),U=n-V/2-B,$=n+V/2+Y-U;if(a&&!is(n,t,$))return;s.save(),s.fillStyle=O,s.strokeStyle=O;const et=r.labelBoxMargin.end;s.font=D;const tt=Pt(e,s,D),Q=et-W,rt=G!==void 0?tt+G+W:t.width-Q,lt=_==="right"?t.x+t.width-Q-rt:t.x+Q,ot=_==="right"?t.x+t.width-tt-et:et;s.fillStyle=O,s.strokeStyle=O,s.fillRect(lt,U,rt,$),s.fillStyle=j,s.fillText(e,ot,n+V/2-1),s.restore()}function Cd(s,t,e=Et){return jt(s,t)/2+e}function is(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const yd="badge",Br=4,Rr={badge:md,rectangle:vd,plain:bd};function Fr(s,t,e,n,i,r,o,a,l){var c,h,d,u,f;const p=r.y,v=r.labelText,P=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:yd,D=r.description,O=(d=r.textFont)!=null?d:Qt(a),j=r.bgColor,H=(u=r.lineColor)!=null?u:j,B=Pt(D!=null?D:"",s,O)+8,Y=it(r.y),W=jt(O,s),G=p-W/2,U=p+W/2-G;s.save(),s.fillStyle=j,s.strokeStyle=H;const Z=o.getBounds(x.PANE_UUID(q)),$=Rr[_],et=a.labels.descriptions,tt=wd(n,Y,U),Q=()=>et&&Sd(e,t,n,i,r,a);let rt,lt;const ot=2;a.align==="right"?(rt=Z.x,lt=et?Z.x+Z.width-B:Z.x+Z.width+ot):(rt=et?Z.x+B:Z.x-ot,lt=Z.x+Z.width);const xt=(f=r.lineY)!=null?f:r.y,Vt=()=>tt&&ne(s,()=>Qc(s,rt,xt,lt,xt,1)),me=()=>$(s,n,v,p,r,a,l.yAxis,!1),dn={line:()=>{Vt(),Q()},"line-label":()=>{Vt(),me(),Q()},label:()=>{Q(),me()}};P!=="none"&&is(p,n,U)&&dn[P](),s.restore()}const wd=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Sd(s,t,e,n,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=Qt(r),f=Pt(h,t,u),p=jt(u,t),v=(o=i.paddingTop)!=null?o:Br,P=(a=i.paddingBottom)!=null?a:Br,_=d-p/2-v,O=d+p/2+P-_;t.save();const j=f+5,H=4,B=f+H*2,Y=n.x+n.width,W=c==="right"?Y-B:n.x+H;yc(s,t,W,_,j,O,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const G=c==="right"?Y-f-H*2:n.x+H*2;t.fillText(h,G,d+p/2-1),t.restore()}class Hr{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&ne(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const p={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},v={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},P=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),P&&(t.moveTo(...p.start),t.lineTo(...p.end)),t.moveTo(...v.start),t.lineTo(...v.end),t.stroke()),P&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,p=this.config.components.xAxis.fontSize,v=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const P=(n=l==null?void 0:l.left)!=null?n:0,_=(i=l==null?void 0:l.right)!=null?i:0,D=(r=l==null?void 0:l.top)!=null?r:0,O=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,H=f+P+_,B=p+D+O,Y=Math.max(d-H/2,0),W=v.y+j+Se/2;lr(t,Y,W,H,B),t.fillStyle=h.labelTextColor;const G=Math.max(d-f/2,P),V=v.y+j+p+Se/2+D-1;t.fillText(u,G,V),t.restore()}}drawYLabel(t,e){const n=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=Rr[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class xd{draw(){}}class _d extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.crossToolTypeDrawers={},this.model=new pd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel),this.addChildEntity(this.model);const c=new fe(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const h=new ad(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),d=new Us;d.addDrawer(c,"CLEAR_CANVAS"),d.addDrawer(h,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(d,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new xd)}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 Pd{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Xt{constructor(t){this.data=t,this.next=null}}class Td{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new Xt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new Xt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class Md extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new Xt(n);return i.getNodePosition(r)}addObject(t){var e,n;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new Td;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((n=t.parentId)!=null?n:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[n]=e;this.removeObject(n.id),this.addObject(t)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class Ad extends X{constructor(t,e){super();const n=new Md(t);this.model=n,this.addChildEntity(n);const i=new Pd(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Ed=()=>s=>s.toString(),Id=(s,t)=>{var e;const n="date.get"+(t((e=s.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return n+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:Dd(s),shortMonths:Ld(s),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=s.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Od(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Dd(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Ld(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const kr=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Ed()},Od=(s,t,e,n)=>{t||(t="M/d/yyyy");const i=s.getDate(),r=s.getMonth(),o=s.getFullYear(),a=s.getHours(),l=s.getMinutes(),c=s.getSeconds(),h=s.getMilliseconds(),d=a%12,u=ge(d),f=ge(a),p=ge(l),v=ge(c),P=a<12?"AM":"PM",_=e[s.getDay()],D=_.substring(0,3),O=ge(i),j=r+1,H=ge(j),B=n[r],Y=B.substring(0,3),W=o+"",G=W.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",p+"").replace("m",l+"").replace("ss",v+"").replace("s",c+"").replace("S",h+"").replace("dd",O+"").replace("d",i+"").replace("EEEE",_).replace("EEE",D).replace("YYYY",W).replace("yyyy",W).replace("YY",G).replace("yy",G).replace("aaa",P),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",Y):t=t.replace("MM",H+"").replace("M",j+""),t},ge=s=>typeof s=="number"&&s<10?"0"+s:s,De=(s,t)=>`${s}_${t}`,Bd=(s,t)=>{if(t){const e=jr(t.normal),n=jr(t.hover);return{type:s,normal:e,hover:n}}},jr=s=>{var t;const n=new DOMParser().parseFromString(s,"text/html").querySelector("svg");let i=0;n&&(i=parseInt((t=n.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(s),l=new Image;return l.src=a,{img:l,svgHeight:i}},Rd=(s,t,e,n,i)=>{if(i){const r=t[De(n,"hover")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[De(n,"normal")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Fd={"rhombus-small":4,rhombus:6,"rhombus-large":8},Hd=["earnings","dividends","splits","conference-calls"];class kd{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&Hd.forEach(l=>{const c=Bd(l,a[l]);c&&(this.customIcons[De(c.type,"normal")]=c.normal,this.customIcons[De(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(n.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[De(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Rd(n,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(n,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);n.lineWidth=u!=null?u:1,n.beginPath(),n.setLineDash(f!=null?f:[]),n.moveTo(c,e.y),n.lineTo(c,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),n.restore()}drawDefaultEvent(t,e,n,i,r){var o,a,l;const c=n.y+n.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=Gs(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function Gs(s){return Fd[s.style]}const rs=5;class jd{constructor(t,e,n,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{if(!this.config.components.events.eventsVisibility[n.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[n.type].color;t.strokeStyle=c,t.fillStyle=c;const h=Gs(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const d=(h+rs)*2;if(a!==void 0){const u=Gs(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const v=h*2+rs;t.fillRect(a+u,e.y,v,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Yd=Object.defineProperty,Yr=Object.getOwnPropertySymbols,Nd=Object.prototype.hasOwnProperty,Xd=Object.prototype.propertyIsEnumerable,Nr=(s,t,e)=>t in s?Yd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,zd=(s,t)=>{for(var e in t||(t={}))Nd.call(t,e)&&Nr(s,e,t[e]);if(Yr)for(var e of Yr(t))Xd.call(t,e)&&Nr(s,e,t[e]);return s};const Xr=317,Zs={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class Wd extends gr{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new R,this.touchStartSubject=new R,this.dblClickSubject=new R,this.rightClickSubject=new R,this.hitTestDrawersPredicateSubject=new ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,pr(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Pe(100,_e,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=vt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=vt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ht(()=>zd({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,n,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*Xr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Xr}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ss&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ss),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=$s(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=$s(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var n,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,p]=$s(this.hitTestSubscribers,u),v=f==null?void 0:f.lookup(d),P={point:t,model:v};switch(e){case"mousedown":v&&((n=f==null?void 0:f.onMouseDown)==null||n.call(f,v,t)),p.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":v&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,v,t)),p.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":v&&((r=f==null?void 0:f.onHover)==null||r.call(f,v,t)),p.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(P);break;case"touchstart":v&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,v,t)),p.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(P);break;case"dblclick":v&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,v,t)),this.dblClickSubject.next(P);break;case"contextmenu":v&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,v,t)),this.rightClickSubject.next(P);break;case"zoom":v&&((c=f==null?void 0:f.onZoom)==null||c.call(f,v,t)),p.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const $s=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var Vd=Object.defineProperty,Ud=Object.defineProperties,Gd=Object.getOwnPropertyDescriptors,zr=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,$d=Object.prototype.propertyIsEnumerable,Wr=(s,t,e)=>t in s?Vd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Kd=(s,t)=>{for(var e in t||(t={}))Zd.call(t,e)&&Wr(s,e,t[e]);if(zr)for(var e of zr(t))$d.call(t,e)&&Wr(s,e,t[e]);return s},qd=(s,t)=>Ud(s,Gd(t));class Jd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>qd(Kd({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Zs.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Qd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>kr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Jd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new kd(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new jd(n,i,t,r,c,()=>n.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class tu{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;ne(t,()=>this.drawVertical(t)),ne(t,()=>this.drawHorizontal(t)),ne(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=it(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=Mt(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=it(this.viewportModel.toY(i.value)),o=Cd(i.text,t,Et);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Vr extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new tu(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class eu{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,n,i){const r=this.getMarkerY(t,n,i==="low"),o=Ve(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Gt(t,h)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=Ve(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class su extends X{constructor(t,e,n,i,r){super();const o=new eu(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const nu=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],iu=24*60*60*1e3;class ru extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new R}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+iu;qa(this.highlights,t,e,ou).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const ou=s=>s.to,Zt=[20,10];class au{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(x.ALL_PANES);o.save(),Gt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(n=this.config.components.highlights.fontSize)!=null?n:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",p=`${u}px ${f}, monospace`;o.font=p,o.lineWidth=h,o.setLineDash(d),nu.forEach(v=>{var P,_;const D=a[v];if(D){const O=this.config.colors.highlights[v],j=(P=O==null?void 0:O.border)!=null?P:"#ffffff",H=(_=O==null?void 0:O.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=j,D.forEach(B=>{var Y,W,G;const V=this.chartModel.candleFromTimestamp(B.from),U=ft(V.width,this.chartModel.scale.zoomX),Z=V.xStart(this.chartModel.scale),$=B.to-this.chartModel.chartBaseModel.period,et=this.chartModel.candleFromTimestamp($),tt=ft(et.width,this.chartModel.scale.zoomX),Q=et.xStart(this.chartModel.scale)+tt;if(B.border&&this.drawBorders(B.border,o,Z+U,Q-tt,c),o.fillRect(Z,c.y,Q-Z,c.y+c.height),B.label){const rt=(Y=B.label.text)!=null?Y:"",lt=this.config.colors.highlights[B.type];o.save(),o.fillStyle=(W=lt==null?void 0:lt.label)!=null?W:"#ffffff";const ot=Pt(rt,o,p),[xt,Vt]=this.resolveHighlightLabelPosition((G=B.label.placement)!=null?G:"left-left",c,[Z,Q],ot);o.fillText(rt,xt,Vt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Zt[1]-i,e.y+Zt[0]];case"left-left":return[r-Zt[1]-i,e.y+Zt[0]];case"right-right":return[o+Zt[1],e.y+Zt[0]];case"left-right":default:return[r+Zt[1],e.y+Zt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const lu="HIGHLIGHTS_PLUGIN";class cu extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new ru(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new au(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,lu)}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 hu(){return N(function(s,t){var e,n=!1;s.subscribe(mt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function J(s,t){return N(function(e,n){var i=0;e.subscribe(mt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var du=Object.defineProperty,uu=Object.defineProperties,fu=Object.getOwnPropertyDescriptors,Ur=Object.getOwnPropertySymbols,gu=Object.prototype.hasOwnProperty,pu=Object.prototype.propertyIsEnumerable,Gr=(s,t,e)=>t in s?du(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zr=(s,t)=>{for(var e in t||(t={}))gu.call(t,e)&&Gr(s,e,t[e]);if(Ur)for(var e of Ur(t))pu.call(t,e)&&Gr(s,e,t[e]);return s},$r=(s,t)=>uu(s,fu(t));const zt=4;class mu{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),n.width!==0&&this.drawLeftArrowButton(c,n,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=n.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=Ct(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:$r(Zr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:$r(Zr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=qn(n,i.dateFormat,this.formatterFactory);Zn(t,i.textProperties);const a=Ve(t),l=Kn(o);Qa(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Le extends br{constructor(t,e,n,i,r=vr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const Kr=4;class vu extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-p.x-Kr},this.leftKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-p.x+Kr},this.rightKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:p}=f,v=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),P=this.chartModel.mainCandleSeries.meanCandleWidth/(v.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-p)*P;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=p};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Le(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Le(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new Le(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class bu extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new mu(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new vu(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(hu(),J(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,f,p;for(f=0;f<h;f++)p=it(f*o/h)-r,p in e?(d[f]=e[p].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((v,P)=>[P+c.x,(a+l-v)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(zs),this.canvasModel.fireDraw())}}const qr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},zp=(s,t)=>s==="apple"||s==="mobile"?3:t,Cu=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),yu=!!window.chrome,Jr=typeof InstallTrigger!="undefined",wu=navigator.platform.indexOf("Win")>-1,Wp=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Cu)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(yu){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,wu){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else Jr?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return Jr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Su=(s,t)=>s==="percent"?t/4:t;var Ks=Math.pow;class xu extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=15,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const v=this.canvasBoundsContainer.getBounds(x.CANVAS).width,_=d.offsetX/v;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(We),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Nt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Le(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(J(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Pe(this.wheelThrottleTime,_e,{trailing:!0,leading:!0})).subscribe(e=>{const n=qr(),i=n==="apple"||n==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Nt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return Su(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(We),this.currentPoint={x:0,y:0},n=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)_u(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Nt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new ss(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const _u=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Ks(Ks(Math.abs(s.x),2)+Ks(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle},Pu=2;class Tu extends X{constructor(t,e,n,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:n}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:n}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:n}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=Qr(e,i.x,n,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=n+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;n>=i||e[0]===e[1]||this.scale.setXScale(n,i)}}const Qr=(s,t,e,n,i=Pu)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-n,2))>i;class Mu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c,this.chartAreaPanHandler=new xu(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new Tu(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const to=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},eo=(s,t)=>{const e=to(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function Au(){return Ln(1)}function so(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return Au()(Ye(s,je(s)))}function Eu(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s);return N(function(n,i){(e?so(s,n,e):so(s,n)).subscribe(i)})}function Iu(s){return J(function(t,e){return s<=e})}class Du{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const no=8;class qs extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new R,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=p=>{const{delta:v,draggedPixels:P}=p;Math.abs(this.initialY-this.boundsProvider().y+P)>=0&&(this.dragTickCb(v),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new ss(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:kt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:kt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Eu(!1),J(this.dragPredicate),At(),Iu(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Du(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,mr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(mr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const io=1/32,Lu=s=>{const t=Math.floor(s),e=s-t,n=Math.round(e*64),r=Math.floor(n/2).toString().padStart(2,"0");return`${t}'${r}`},Ou=(s,t)=>e=>{let n;if(typeof e=="number")n=e;else if(typeof e=="string")n=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return Lu(n);const[r]=s.dataSeries;if(r!==void 0){const o=Rt.getPricePrecision(n,r.pricePrecisions);return n.toFixed(o)}return`${n}`},Bu=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ri(t,r.getBaseline()));const o=i.toFixed(Rt.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Ru=(s,t)=>({percent:Bu(s),regular:Ou(s,t)});class Fu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u=new Set,f={regular:dc}){super(),this.config=t,this.paneUUID=e,this.idx=n,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(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=p=>p.map(v=>new Me(this.chartBaseModel.dataFromTimestamp(v.timestamp).centerUnit,v.close)),this.toY=p=>{var v,P;return(P=(v=this.mainDataSeries)==null?void 0:v.view.toY(p))!=null?P:1},this.valueFormatter=(p,v)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(p);const{regular:P,percent:_,logarithmic:D}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(p);case"percent":return _?_(p,v):P(p);case"logarithmic":return D?D(p):P(p);default:return this.regularFormatter(p)}},this.addChildEntity(c),this.setValueFormatters(Ru(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 Xi(this,bt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const ro=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return er(e)}});class Hu{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Zs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Zs.DATA_SERIES}get allDataSeries(){return we(we(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Wt="#FF00FF";function Vp(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const ku=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,ju=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Wt},Yu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Wt},Nu=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Wt},Xu=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Wt},zu=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Wt},Wu=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:Wt},Vu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Wt},oo=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Wt},Uu=()=>(console.warn("Fallback for label default color"),Wt),ao=10;class lo extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new R,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(x.Y_AXIS).height,ui),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(ao-1)):d=1+h/this.lastYPxHeight*(ao-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,p=this.lastYStart-f,v=this.lastYEnd+f;(this.lastYStart!==p||this.lastYEnd!==v)&&(this.scale.setYScale(p,v),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new ss(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Gu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${bt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Yn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const Zu=0,$u=.01;class Js{constructor(t,e,n,i,r=!1,o,a,l=Ms,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new R,this.newGeneratedLabelsSubject=new R,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Gu(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=dt.roundToNearest(t,n);for(;r<e;){const o=dt.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=dt.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=dt.roundToNearest(t,n);for(;o<e;){const a=dt.roundToNearest(o,n),l=Fi(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=dt.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=dt.roundToNearest(t,n);for(;r<e;){const o=Ns(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=dt.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),n=this.lengthProvider(),i=Js.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const n=(e=this.treasuryFormat)!=null&&e.enabled?io:Rt.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(n)}return this.adjustIncrementOnAxisType($u)}adjustIncrementOnAxisType(t){var e;const n=(e=this.treasuryFormat)!=null&&e.enabled?io:t;switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[i]=this.calculateMinMax(),o=Ns(i)+n;return Hi(o)-i;case"regular":return n}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,n){const i=Math.abs((e-t)*(Zu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class Ku extends Js{constructor(t,e,n,i,r=()=>"regular",o=23,a){super(t,()=>[n.yStart,n.yEnd],()=>n.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,n)=>n.text.length>e.length?n.text:e,"")}calculateIncrement(t){var e;const n=this.dataSeriesProvider();if(n){const i=yt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=xc(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function co(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?N(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(mt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):le}class qu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${bt()}`}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ht(t=>t.height),J(t=>Pa(t,this.prevYAxisHeight,1.5)),co(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class Ju extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Ku(null,l,o,a,()=>this.state.type,n.labelHeight,n),this.baseLabelsModel=new qu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new ql(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class Qu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=a,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.hitTestCanvasModel=f,this.chartResizeHandler=p,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new R,this.axisAlignSetSubject=new R,this.axisAlignMovedSubject=new R,this.setDblClickCallback=_=>this.yAxisScaleHandler.setDblClickCallback(_),this.setDblTapCallback=_=>this.yAxisScaleHandler.setDblTapCallback(_);const P=v?ee(v):{};this.state=Tt(P,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new lo(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),f),this.addChildEntity(this.yAxisScaleHandler),this.model=new Ju(this.paneUUID,t,this.state,o,n,i,c,h,u,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new lo(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Nu),this.registerLabelColorResolver("bar",ju),this.registerLabelColorResolver("line",Yu),this.registerLabelColorResolver("area",Xu),this.registerLabelColorResolver("scatterPlot",zu),this.registerLabelColorResolver("histogram",Wu),this.registerLabelColorResolver("baseline",Vu),this.registerLabelColorResolver("trend",oo),this.registerLabelColorResolver("hollow",oo)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Uu}registerYAxisLabelsProvider(t,e=te.MAIN,n=bt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=te.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class tf extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_,D,O,j){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=p,this.uuid=v,this.seriesAddedSubject=P,this.seriesRemovedSubject=_,this.hitTestCanvasModel=D,this.chartResizeHandler=O,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new R,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,Y)=>this.mainExtent.valueFormatter(B,Y);const H=this.createExtentComponent(j);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(v),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return we(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(At(bi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i,r){const o=x.PANE_UUID(t);return new Vr(this.mainCanvasModel,e,this.config,n,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(o),()=>this.canvasBoundsContainer.getBounds(o),()=>[],i,r,()=>this.config.components.grid.visible)}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new $c(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(v,P)=>new Qu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,v,P,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Fu(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),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",eo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),ro(u)));const p=this.createGridComponent(this.uuid,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(p),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(n=>n.idx).includes(e.idx)),this.yExtentComponents.forEach((e,n)=>{e.yAxis.setExtentIdx(n),e.idx=n,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,n,i="right"){const r=ee(n.yAxis.state),o=ee(n.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),n.dataSeries.size===0&&e.removeExtentComponents([n])}moveDataSeriesToExistingExtentComponent(t,e,n,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&n.dataSeries.size===0&&e.removeExtentComponents([n]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(n=>n.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=ce(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=yt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var ef=Object.defineProperty,sf=Object.defineProperties,nf=Object.getOwnPropertyDescriptors,ho=Object.getOwnPropertySymbols,rf=Object.prototype.hasOwnProperty,of=Object.prototype.propertyIsEnumerable,uo=(s,t,e)=>t in s?ef(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,af=(s,t)=>{for(var e in t||(t={}))rf.call(t,e)&&uo(s,e,t[e]);if(ho)for(var e of ho(t))of.call(t,e)&&uo(s,e,t[e]);return s},lf=(s,t)=>sf(s,nf(t));class cf extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=p,this.yAxisLabelsCanvasModel=v,this.hitTestCanvasModel=P,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new R,this.paneAddedSubject=new R,this.dataSeriesAddedSubject=new R,this.dataSeriesRemovedSubject=new R,this.hitTestController=new Hu(this.panes,this.dynamicObjectsCanvasModel);const D=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});D.mainExtent.scale.autoScaleModel.setHighLowProvider("series",ro(D.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",to(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+no}),n=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=x.PANE_UUID_RESIZER(t),o=new qs(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,n,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return we(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=bt(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new tf(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,n;const i=ce(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}canMovePaneDown(t){var e,n;const i=yt(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const n=x.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof qs&&r.id===n);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],n=x.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof qs&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,n,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?lf(af({},n.yAxis.state),{align:l}):void 0,p=c&&c>0;if(!u){const v=a&&a==="above"?d:d+1,P=this.createPane(r,{order:v,initialYAxisState:f,inverse:n.scale.state.inverse,lockToPriceRatio:n.scale.state.lockPriceToBarRatio});P.moveDataSeriesToExistingExtentComponent(t,e,n,P.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!p?u.moveDataSeriesToExistingExtentComponent(t,e,n,o):u.moveDataSeriesToNewExtentComponent(t,e,n,l!=null?l:n.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+no),()=>{this.cursorHandler.removeCursorForCanvasEl(n),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class hf extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const df=(s,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function n(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return n(s)},os=class extends X{constructor(s,t,e,n){super(),this.chartComponent=s,this.config=t,this.volumesModel=e,this.paneManager=n,t.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[os.UUID]===void 0){const t=this.paneManager.createPane(os.UUID,{paneFormatters:{regular:i=>df(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=eo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(os.UUID),delete this.pane}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let fo=os;fo.UUID="volumes";const as=.3,uf=(s,t)=>{const e=t.barTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},ff=(s,t)=>{const e=t.volume[`${s}BarColor`];return Lt()(e).alpha(as).toString()},gf=(s,t)=>{const e=t.lineTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},Qs=(s,t)=>{const e=t.candleTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},pf=3;class mf{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:ff;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const n=this.getViewportModel().getBounds();Gt(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=Ct(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?Mt(i.toX(n[o+1].startUnit)):void 0,h=Mt(i.toX(r.startUnit)),d=c!==void 0?c-h:Mt(ft(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(i.toY(r.candle.volume)),f=ks(i.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=e/(l/pf),f=Math.max(ks(ft(r.candle.volume,u)),2),p=Mt(a.y+l-f);this.drawVolume(t,r,h,p,d,f)}}})}drawVolume(t,e,n,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(n,l),a.lineTo(n,ks(c)),a.stroke()):a.fillRect(n,i,r,o)}}const vf=Ka(s=>s.candle.volume),go="volumes";class bf extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=go,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;this.volumeMax.next((t=ce(vf(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Cf extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new bf(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new fo(e,o,c,a),this.volumesDrawer=new mf(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:n},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",Qs),this.registerVolumeColorResolver("trend",Qs),this.registerVolumeColorResolver("hollow",Qs),this.registerVolumeColorResolver("line",gf),this.registerVolumeColorResolver("bar",uf)}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?go:q,n={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(n);return}this.dynamicObjectsComponent.model.updateObject(n)}}class yf{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:p,offsetY:v,offsetX:P}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=ls(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=wf(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),p){case"left-top":return{x:P+f.x,y:v+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:P+f.x,y:f.height-h-v+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let p=0,v=0,P=0,_=0,D=0;if(f.save(),d.firstRowFontSize&&l){f.font=ls(this.config,d.firstRowFontSize);const B=f.measureText(l);p=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=ls(this.config,d.secondRowFontSize);const B=f.measureText(c);v=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,P=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=ls(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,D=(n=d.secondRowBottomPadding)!=null?n:0}const O=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,H=p+v+P+_+D+O+j;if(l&&this.drawWaterMark(this.getConfig(p,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(p+P+v,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(p+P+v+D+_,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(p+P+v+D+_+O,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const wf=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},ls=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Sf=Object.defineProperty,po=Object.getOwnPropertySymbols,xf=Object.prototype.hasOwnProperty,_f=Object.prototype.propertyIsEnumerable,mo=(s,t,e)=>t in s?Sf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,vo=(s,t)=>{for(var e in t||(t={}))xf.call(t,e)&&mo(s,e,t[e]);if(po)for(var e of po(t))_f.call(t,e)&&mo(s,e,t[e]);return s};class Pf extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new yf(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return vo(vo({},this.config.components.waterMark),h)}}const bo={x:4,y:4};function Tf(s,t,e,n){var i,r;const o=(i=n.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const p=s.measureText(n.text).width+bo.x*2;let v=0;const P=n.x;switch(o){case"start":v=P-p;break;case"end":v=P;break;case"middle":default:v=P-p/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(v,u.y,p,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(P,u.y),s.lineTo(P,u.y+u.height),s.stroke()),s.fillStyle=n.color;const _=v+bo.x,D=u.y+d+a+Se/2;s.fillText(n.text,_,D),s.restore()}class Mf{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Tf(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=Lt().rgb(r[0].color).alpha(.1).toString(),cr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const Up="week-weekday",Af=["second","minute","hour","day","month","year"],Ef=["lessThanSecond"],If=s=>Af.some(t=>t===s),Df=s=>s==="week-weekday",Lf=s=>Ef.some(t=>t===s),Co=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},tn=s=>parseInt(s,10),yo=s=>{const[t,...e]=s.split("_");if(If(t)){const[n]=e,i=Co(n),r=tn(n);return{key:t,value:r,exact:i["!"]}}else if(Df(t)){const[n,i]=e,r=Co(n),o=tn(n),a=tn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Lf(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class cs{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Se/2),e.restore()}}drawLabels(t,e,n,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Pt(c.text,t,l)/2;if(h<n.x||h>n.width)continue;const d=n.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const en={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},wo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return en[s.key]+s.value;case"lessThanSecond":return en[s.key];case"week-weekday":return en[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},So=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Of=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],p=f.idx;for(;c<a;){const v=o[c],P=v.idx;if(p>P)c++,n.push(v),d=P,h=1/0;else{h=P;break}}h-p>=t&&p-d>=t&&(n.push(f),d=p)}for(;c<a;)n.push(o[c]),c++}return n},Bf=(s,t,e,n,i,r)=>{const o=cs.getFontFromConfig(t),a=Pt(e.text,s,o),l=Pt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function sn(s){"@babel/helpers - typeof";return sn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},sn(s)}function wt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function St(s){wt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||sn(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Rf(s){return wt(1,arguments),St(s).getDay()===1}function Ff(s){return wt(1,arguments),St(s).getDay()===2}function Hf(s){return wt(1,arguments),St(s).getDay()===3}function kf(s){return wt(1,arguments),St(s).getDay()===4}function jf(s){return wt(1,arguments),St(s).getDay()===5}function Yf(s){return wt(1,arguments),St(s).getDay()===6}function Nf(s){return wt(1,arguments),St(s).getDay()===0}function Xf(s,t){var e;wt(1,arguments);var n=s||{},i=St(n.start),r=St(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(St(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function zf(s){wt(1,arguments);var t=St(s);return t.setDate(1),t.setHours(0,0,0,0),t}function Wf(s){wt(1,arguments);var t=St(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function xo(s){wt(1,arguments);var t=St(s);return t.setHours(0,0,0,0),t}function _o(s,t){wt(2,arguments);var e=xo(s),n=xo(t);return e.getTime()===n.getTime()}const Vf=s=>{switch(s.key){case"lessThanSecond":return $f(s);case"month":return Kf(s);case"second":case"minute":case"hour":case"day":case"year":return qf(s);case"week-weekday":return Jf(s);default:return()=>!1}},$t=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},nn=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n!==i},Uf=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n>=i},Gf={1:Rf,2:Ff,3:Hf,4:kf,5:jf,6:Yf,7:Nf},Zf=(s,t,e)=>{var n;const i=Xf({start:zf(s),end:Wf(s)}),r=(n=Gf[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return _o(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return _o(s,a);o++}}return!1},Po=(s,t)=>t===1?s===1:s/t===1,To=(s,t)=>t===1?!0:s%t===0,$f=s=>(t,e)=>Uf(s.key)(t,e),Kf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?Po($t(t,s.key)+1,s.value):To($t(t,s.key)+1,s.value);return n&&i},qf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?Po($t(t,s.key),s.value):To($t(t,s.key),s.value);return n&&i},Jf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=Zf(t,s.week,s.weekday);return n&&i},Qf=s=>{switch(s.key){case"second":case"minute":return tg(s.value);case"hour":return eg(s.value);case"day":return sg(s.value);case"month":return rg(s.value);case"year":return og(s.value);case"week-weekday":const t=ig(s.week),e=ng(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},tg=s=>s>0&&s<=60,eg=s=>s>0&&s<=24,sg=s=>s>0&&s<=31,ng=s=>Mo(s)?s>=1&&s<=7:!1,ig=s=>s==="$"?!0:Mo(s)?s>=1&&s<=6:!1,rg=s=>s>0&&s<=12,og=s=>s>0,Mo=s=>!isNaN(s)&&isFinite(s),ag=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function rn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:ag(a,i,t)};n[r]=l,i=a}return n}const Ao=s=>{const t={},e={};return js(s).forEach(([n,i])=>{const r=yo(n),o=r===null?!1:Qf(r);if(r&&o){const a=wo(r);t[a]=i,e[a]=Vf(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Eo{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?ft(d,h.animationConfig.targetZoomX):ft(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,p=Object.values(this.formatsByWeightMap).reduce((P,_)=>Math.max(_.length,P),1),v=f*p;return Math.round(v/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Ao(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>Vi(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}mapWeightedPointsToLabels(t,e){var n;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=Ao(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(t=[]){const e=this.getAllCandlesWithFake(t),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e);this.labelsGroupedByWeight=So(i),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=rn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=So(i),o=ee(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const p=f.map(v=>(v.idx=v.idx+t.length,v.value=a.startUnit+a.width+v.value,v));r[u]?c[h]=d.concat(p):c[h]=p}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t){this.generateWeightedLabels(t)}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const n=Of(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Bf(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=yo(o);if(l){const c=wo(l);i[c]=a}}return i},{});return js(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class lg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(ts,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const Io=3;class cg extends X{constructor(t,e,n,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,p=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(p,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(Io-1)):u=1+h/this.lastXPxWidth*(Io-1);const p=(this.lastXWidth*u-this.lastXWidth)/2,v=this.lastXStart-p,P=this.lastXEnd+p;(this.lastXStart!==v||this.lastXEnd!==P)&&this.scale.setXScale(v,P)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Le(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class hg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=P=>this.xAxisScaleHandler.setDblClickCallback(P),this.setDblTapCallback=P=>this.xAxisScaleHandler.setDblTapCallback(P);const p=new Eo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=p,this.xAxisLabelsModel=new lg(t,[]);const v=new Us;c.addDrawer(v,"X_AXIS"),this.xAxisDrawer=new cs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),v.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new Mf(e,n,o,this.xAxisLabelsModel),v.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new cg(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(x.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(J(({prependedCandles:t})=>t.length!==0),ht(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;ul.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(vt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ht(()=>yt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),At((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),J(Wn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Eo?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 dg=Object.defineProperty,Do=Object.getOwnPropertySymbols,ug=Object.prototype.hasOwnProperty,fg=Object.prototype.propertyIsEnumerable,Lo=(s,t,e)=>t in s?dg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,hs=(s,t)=>{for(var e in t||(t={}))ug.call(t,e)&&Lo(s,e,t[e]);if(Do)for(var e of Do(t))fg.call(t,e)&&Lo(s,e,t[e]);return s};class gg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&hs(hs({},n),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&hs(hs({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=yt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:Jt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:ku(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,h,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,r,o),rounded:!0}}}class pg{constructor(t,e,n,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=n,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,n=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(x.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>Fr(t,n,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>Fr(t,n,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];cr(e,{x:h.x,y:vi(d,h)},{x:h.x+h.width-6,y:vi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class mg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=Qt(e.state),a=jt(o,r),l=this.getLabelTextColor();r.save(),Gt(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&vg(t,n,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const vg=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class bg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Za.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new R,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(ts,t)}}class Cg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ht(r=>i.components.chart.highlightActiveCandle?r:void 0),At()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class yg{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${bt()}`,this.canvasResized=new R,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){be(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(zs,e),this.bus.fire(ts))}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.previousBCR!==void 0}}var wg=Array.isArray,Sg=Object.getPrototypeOf,xg=Object.prototype,_g=Object.keys;function Pg(s){if(s.length===1){var t=s[0];if(wg(t))return{args:t,keys:null};if(Tg(t)){var e=_g(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Tg(s){return s&&typeof s=="object"&&Sg(s)===xg}var Mg=Array.isArray;function Ag(s,t){return Mg(t)?s.apply(void 0,I([],m(t))):s(t)}function Eg(s){return ht(function(t){return Ag(s,t)})}function Ig(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Dg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=ga(s),i=Pg(s),r=i.args,o=i.keys;if(r.length===0)return Ye([],e);var a=new pt(Lg(r,e,o?function(l){return Ig(o,l)}:le));return n?a.pipe(Eg(n)):a}function Lg(s,t,e){return e===void 0&&(e=le),function(n){Oo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){Oo(t,function(){var d=Ye(s[h],t),u=!1;d.subscribe(mt(n,function(f){r[h]=f,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function Oo(s,t,e){s?Ht(e,s,t):t()}class Og extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Dg([n,i]).pipe(J(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!kt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Bg(s,t){return N(function(e,n){var i=null,r=0,o=!1,a=function(){return o&&!i&&n.complete()};e.subscribe(mt(n,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(s(l,h)).subscribe(i=mt(n,function(d){return n.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Rg{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Fg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Rg(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Hg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof xr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var kg=Object.defineProperty,jg=Object.defineProperties,Yg=Object.getOwnPropertyDescriptors,Bo=Object.getOwnPropertySymbols,Ng=Object.prototype.hasOwnProperty,Xg=Object.prototype.propertyIsEnumerable,Ro=(s,t,e)=>t in s?kg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Oe=(s,t)=>{for(var e in t||(t={}))Ng.call(t,e)&&Ro(s,e,t[e]);if(Bo)for(var e of Bo(t))Xg.call(t,e)&&Ro(s,e,t[e]);return s},on=(s,t)=>jg(s,Yg(t));class zg extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new Fg(this.chartModel),u=new Hg(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Bg(()=>this.scale.initialViewportValidSubject.pipe(J(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(vt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((n=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:n.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var n,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!Qr(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(n=this.crossEventProducer.crossToolHover)==null?void 0:n.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(x.PANE_UUID(d)),f=u.y+5,p=u.y+u.height-5,v=c-l.x,P=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=v,D=a.y<f?f:a.y>p?p:a.y+=P;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:D}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=kr(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,q)}createHover(t,e,n){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>on(Oe({},l),{[c[0]]:c[1].getData(o)}),{});return Oe(Oe({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=on(Oe({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e,n;if(t){if(kt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(n=t.candleHover)==null?void 0:n.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=on(Oe({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const Fo={left:0,middle:1,right:2};function gt(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function pe(s){return t=>{t.button===Fo.left&&s(t)}}var Wg=Object.defineProperty,Ho=Object.getOwnPropertySymbols,Vg=Object.prototype.hasOwnProperty,Ug=Object.prototype.propertyIsEnumerable,ko=(s,t,e)=>t in s?Wg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gg=(s,t)=>{for(var e in t||(t={}))Vg.call(t,e)&&ko(s,e,t[e]);if(Ho)for(var e of Ho(t))Ug.call(t,e)&&ko(s,e,t[e]);return s};const oe=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new R,this.xDragSubject=new R,this.xDragTickSubject=new R,this.xDragEndSubject=new R,this.yDragStartSubject=new R,this.yDragSubject=new R,this.yDragTickSubject=new R,this.yDragEndSubject=new R,this.mouseMoveSubject=new R,this.mouseMoveDocumentSubject=new R,this.clickSubject=new R,this.clickDocumentSubject=new R,this.dbClickSubject=new R,this.dbTapSubject=new R,this.mouseDownSubject=new R,this.mouseUpSubject=new R,this.mouseUpDocumentSubject=new R,this.wheelSubject=new R,this.touchStartSubject=new R,this.touchStartTimestamp=0,this.touchMoveSubject=new R,this.touchEndSubject=new R,this.touchCancelSubject=new R,this.longTouchStartSubject=new R,this.longTouchEndSubject=new R,this.contextMenuSubject=new R,this.fastTouchScroll=new R,this.mouseLeavesCanvasSubject=new R,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=oe.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Gg({},this.dragStartPoint),oe.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===Fo.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],oe.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),oe.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),oe.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,pe(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,pe(e=>this.clickDocumentSubject.next(e)),"click"));const s=qr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(gt(this.element,n,"touchend"));const i=(o,a=200)=>{o.preventDefault();let l=!1,c=null;c=setTimeout(()=>{l=!0,this.longTouchStartSubject.next(o)},a);const h=u=>{u.preventDefault(),u.touches.length>1&&c&&clearTimeout(c)},d=u=>{u.preventDefault(),c&&clearTimeout(c),l&&(l=!1,this.longTouchEndSubject.next(u)),this.element.removeEventListener("touchend",d),this.element.removeEventListener("touchmove",h)};this.element.addEventListener("touchmove",h),this.element.addEventListener("touchend",d)};this.addSubscription(gt(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,f=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,p=d<=250;f&&p&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,pe(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(gt(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(gt(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(gt(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(gt(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(gt(this.element,e=>{this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(gt(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(gt(this.element,pe(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,pe(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,pe(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(zs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){oe.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(J(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ht(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(J(()=>!(t&&this.dragging)),ht(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ht(()=>!1));return vt(e,n).pipe(At())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)),co(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let ds=oe;ds.DRAG_START_EVENTS=["mousedown","touchstart"],ds.DRAG_EVENTS=["mousemove","touchmove"],ds.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var Zg=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Fs);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t}(R);const an={};function $g(s){return an[s]||(an[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),an[s]}const jo=(s,t=Date.now())=>{const n=$g(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},Yo=60*1e3;class Kg{constructor(t){this.config=t,this.timeZoneChangedSubject=new Zg,this.currentTzOffset=e=>jo(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Yo,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Id(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+jo(t,e)+new Date(e).getTimezoneOffset()*Yo):e=>new Date(e)}}class qg extends X{constructor(t,e,n){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=n}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(At((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class ln{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;fl(r),this.config=r;const o=Bl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new Kg(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Rl(t);this.elements=c;const h=new bg;this.bus=h;const d=new yg(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 Ah(h,d);this.drawingManager=u;const f=Th(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=re(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const p=new fe(this.dynamicObjectsCanvasModel);u.addDrawer(p,"SERIES_CLEAR");const v=re(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),P=re(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Rs(r,h,f,l,d);this.canvasBoundsContainer=_;const D=c.mainCanvas.parentElement;if(D===null)throw new Error("Couldn't get main canvas parent");const O=new ds(h,D);this.canvasInputListener=O,this.chartComponents.push(this.canvasInputListener);const j=new Wd(h,c.hitTestCanvas,O,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=j;const H=new fe(j);u.addDrawer(H,"HIT_TEST_CLEAR");const B=new Ya(h);this.canvasAnimation=B;const Y=x.PANE_UUID(q),W=new ar(r,()=>_.getBounds(Y),B);this.scaleModel=W;const G=re(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=G,this.cursorHandler=new Dl(c.canvasArea,O,_,j),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Og(O,_),this.chartComponents.push(this.crossEventProducer);const V=new gc("candle");this.chartBaseModel=V;const U=new Mu(h,W,_,r,B,O,D,V,j);this.chartPanComponent=U,this.chartComponents.push(U),this.userInputListenerComponents.push(U.chartAreaPanHandler);const Z=new qg(j,B,h);this.hitTestComponent=Z,this.chartComponents.push(Z);const $=new cf(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,B,O,u,this.cursorHandler,this.crossEventProducer,U,f,v,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=$;const et=this.paneManager.panes[q];this.mainPane=et,this.chartComponents.push($),this.dynamicObjects=new Ad(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new od(V,$,h,this.dynamicObjectsCanvasModel,r,W,l,D,_,d);const tt=new zh(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,j,O,G,U,$,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),j.addSubscriber($.hitTestController),this.xAxisComponent=new hg(h,r,f,tt,W,_,O,d,this.drawingManager,a,U,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const rt=new fe(f);u.addDrawer(rt,"MAIN_CLEAR");const lt=new Cg(D,Q,O,r);this.chartComponents.push(lt),this.watermarkComponent=new Pf($,Q,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=re(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new cu(h,r,Q,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new bu(h,Q,f,r,O,_,u,l,U,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const xt=new su(r,this.dynamicObjectsCanvasModel,Q,_,u);this.chartComponents.push(xt),this.initYAxisDrawer(v,P),this.yAxisComponent=et.mainExtent.yAxis;const Vt=new gg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(Vt,te.MAIN),this.volumesComponent=new Cf(this.dynamicObjectsCanvasModel,tt,W,_,u,r,$,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const me=new Vr(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(Y),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,()=>r.components.grid.visible);this.chartComponents.push(me),this.hoverProducer=new zg(this.crossEventProducer,W,r,Q,O,this.canvasBoundsContainer,this.paneManager,a,U.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new _d(r,ot,_,u,$,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel),this.chartComponents.push(this.crossToolComponent);const Vo=re(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),cn=new hf(this.elements,Vo);this.snapshotComponent=cn,this.chartComponents.push(cn);const hn=new Qd(r,this.dynamicObjectsCanvasModel,j,Q,_,u,l,this.cursorHandler);this.eventsComponent=hn,this.chartComponents.push(hn),this.chartComponents.forEach(dn=>dn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Xa(this.components)}initYAxisDrawer(t,e){const n=new Us,i=new fe(t),r=new fe(e);n.addDrawer(i,"YAXIS_CLEAR"),n.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(n,"Y_AXIS");const o=new mg(this.config,t,this.paneManager);n.addDrawer(o);const a=new pg(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&ln.mergeConfig(t[n],e[n]):t[n]=e[n];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Tt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=vt(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class No extends ln{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var n;(n=this.paneManager.panes[t])==null||n.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}setTreasuryFormat(t){this.config.components.yAxis.treasuryFormat=t,this.paneManager.yExtents.forEach(e=>{e.yAxis.updateOrderedLabels(!0),e.yAxis.model.fancyLabelsModel.updateLabels(!0),e.yAxis.model.baseLabelsModel.updateLabels()})}createPane(){return this.paneManager.createPane()}}var Jg=Object.defineProperty,Qg=Object.defineProperties,tp=Object.getOwnPropertyDescriptors,Xo=Object.getOwnPropertySymbols,ep=Object.prototype.hasOwnProperty,sp=Object.prototype.propertyIsEnumerable,zo=(s,t,e)=>t in s?Jg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,np=(s,t)=>{for(var e in t||(t={}))ep.call(t,e)&&zo(s,e,t[e]);if(Xo)for(var e of Xo(t))sp.call(t,e)&&zo(s,e,t[e]);return s},ip=(s,t)=>Qg(s,tp(t));function Wo(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=us(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ap(t[t.length-1],a,n)):d>3?t=t.concat(rp(t[t.length-1],a,r)):t=t.concat(op(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let f=0;f<t.length;f++){const p=t[f];Object.assign(p,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(p.volume=Math.ceil(Math.random()*1e3+200))}return t}function us(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:ei(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function rp(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=us(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),n.push(c)}return n}function op(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=us(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),n.push(c)}return n}function ap(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var f,p;return Math.random()>.5?(f=u.lo-t*.2,p=u.hi+t*1.2):(f=u.lo-t*1.2,p=u.hi+t*.2),{from:f,to:p}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=us(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),n.push(d)}return n}window.DXChart=ip(np({},window.DXChart),{generateCandlesData:Wo});function lp(s){return Wo(s)}const cp=(s,t={})=>new No(s,t)})(),window.DXChart=fs})();})();
|
|
24
|
+
`;function Bl(s){const t=document.createElement("template");return t.innerHTML=Ol(s.devexpertsPromoLink),t}function Rl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),Ll(t))return t;throw new Error("Some chart elements are missing")}function Fl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const Hl=s=>t=>s?new Date(t).setHours(0,0,0,0):t,Te=(s,t={},e,n=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=Hl(!!c),u=d(s),f=d((r=(i=ce(e))==null?void 0:i.timestamp)!=null?r:0),p=d((a=(o=yt(e))==null?void 0:o.timestamp)!=null?a:0);return u>p?h?{index:e.length-1+Math.ceil((u-p)/n),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:it((u-f)/n),exact:!0}:{index:-1,exact:!0}:Ot(e,u,v=>d(v.timestamp))},xi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},_i={paintConfig:[xi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var kl=Object.defineProperty,Pi=Object.getOwnPropertySymbols,jl=Object.prototype.hasOwnProperty,Yl=Object.prototype.propertyIsEnumerable,Ti=(s,t,e)=>t in s?kl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Nl=(s,t)=>{for(var e in t||(t={}))jl.call(t,e)&&Ti(s,e,t[e]);if(Pi)for(var e of Pi(t))Yl.call(t,e)&&Ti(s,e,t[e]);return s};class Xl{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Nl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:xi).color;return{textColor:Jt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function zl(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>Wl(a,l,e)).filter(Wn).sort(Vl),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<n.length;a++){const l=n[a],c=n[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const Wl=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,Vl=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var Ul=Object.defineProperty,Gl=Object.defineProperties,Zl=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,$l=Object.prototype.hasOwnProperty,Kl=Object.prototype.propertyIsEnumerable,Ai=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ei=(s,t)=>{for(var e in t||(t={}))$l.call(t,e)&&Ai(s,e,t[e]);if(Mi)for(var e of Mi(t))Kl.call(t,e)&&Ai(s,e,t[e]);return s},Ii=(s,t)=>Gl(s,Zl(t));const te={MAIN:"MAIN"};class ql extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new R,this.animFrameId=`anim_cache_${bt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,vt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),be(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=Ct(Object.values(i).map(l=>l.getUnorderedLabels())),o=Ct(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=zl(o,n);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return Ii(Ei({},t),{labels:t.labels.map((n,i)=>Ii(Ei({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Hs=()=>{Ke.removeEventListener("change",Hs),Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),Ke.addEventListener("change",Hs)};Ke.addEventListener("change",Hs);const Jl=()=>Bt,Bp=s=>round(Bt*s)/Bt,Mt=s=>it(Bt*s)/Bt,ks=s=>Ma(Bt*s)/Bt,ee=s=>JSON.parse(JSON.stringify(s));function js(s){return Object.entries(s)}const Di=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Li(s){return Object.keys(s)}function Oi(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Oi(s[e[i]],t[e[i]]))return!1;return!0}const Ql=s=>Object.keys(s).length===0&&s.constructor===Object;function Bi(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new R}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,p=!1,v=!1,P=function(){d==null||d.unsubscribe(),d=void 0},_=function(){P(),h=u=void 0,p=v=!1},D=function(){var O=h;_(),O==null||O.unsubscribe()};return N(function(O,j){f++,!v&&!p&&P();var H=u=u!=null?u:e();j.add(function(){f--,f===0&&!v&&!p&&(d=Ys(D,l))}),H.subscribe(j),!h&&f>0&&(h=new ve({next:function(B){return H.next(B)},error:function(B){v=!0,P(),d=Ys(_,i,B),H.error(B)},complete:function(){p=!0,P(),d=Ys(_,o),H.complete()}}),Dt(O).subscribe(h))})(c)}}function Ys(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new ve({next:function(){i.unsubscribe(),s()}});return Dt(t.apply(void 0,I([],m(e)))).subscribe(i)}}const qe=(s,t)=>s/t,ft=(s,t)=>s/t,Nt=(s,t)=>s*t,Ri=(s,t)=>(s-t)*100/t,Fi=(s,t)=>s*t/100+t,Hi=s=>Math.log2(s),Ns=s=>Math.pow(2,s);class tc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new R,this.xChanged=this.changed.pipe(ht(()=>({start:this.xStart,end:this.xEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.yChanged=this.changed.pipe(ht(()=>({start:this.yStart,end:this.yEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ft(t-this.xStart,this.zoomX)}xPixels(t){return ft(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ft(t-this.yStart,this.zoomY):e.y+e.height-ft(t-this.yStart,this.zoomY)}yPixels(t){return ft(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Nt(e+ft(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Nt(n+ft(this.yStart,this.zoomY),this.zoomY):Nt(e.height-n+ft(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return qe(e-t,this.getBounds().width)}calculateZoomY(t,e){return qe(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const ec=(s,t)=>!Li(s).some(e=>s[e]!==t[e]);class sc{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Ot(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Ot(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class ki{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new sc(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ri(t,n);case"logarithmic":return t<=0?t:Hi(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return Fi(t,this.getBaseline());case"logarithmic":return Ns(t);case"regular":return t}}}var nc=Object.defineProperty,ic=Object.defineProperties,rc=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,oc=Object.prototype.hasOwnProperty,ac=Object.prototype.propertyIsEnumerable,Yi=(s,t,e)=>t in s?nc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ni=(s,t)=>{for(var e in t||(t={}))oc.call(t,e)&&Yi(s,e,t[e]);if(ji)for(var e of ji(t))ac.call(t,e)&&Yi(s,e,t[e]);return s},lc=(s,t)=>ic(s,rc(t));class Me{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Me(this.centerUnit,this.close)}}class Xi extends X{constructor(t,e,n,i,r){var o;super(),this.extentComponent=t,this.id=e,this.htId=n,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=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,c=Ot(l,this.scale.xEnd,h=>h.centerUnit).index;return l[c]},this.getLastDataSeriesPoint=()=>{const l=this.visualPoints;return yt(l)};const a=r!=null?r:ee(_i);this.config=Tt(a,_i),this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Xl(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=hc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Gn(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=Gn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const n=Ni({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=n.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(te.MAIN,a,r),n.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(te.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=Ot(this.visualPoints,t,r=>r.centerUnit).index,i=Ot(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Ua(this.visualPoints2D,n,i)}}const cc=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},hc=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=cc(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return lc(Ni({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),dc=s=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(s);return dt.makeDecimal(s,i)};class Je extends Me{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),n=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const de=60,Ae=(s,t,e=de)=>{const n=zi(s,t,e);return{id:ei(n,n),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:n,volume:NaN,expansion:!0,idx:t}},uc=(s,t,e=de)=>({close:NaN,timestamp:zi(s,t,e)});function zi(s,t,e=de){var n,i;const r=ye(t);if(s.length===0)return 0;const o=yt(s);if(r>=s.length&&o)return Wi(o,s.length-1,r,e);const a=ce(s);return r<0&&a?Wi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Wi=(s,t,e,n=de)=>s.timestamp+(e-(t!=null?t:0))*n,Vi=(s,t,e,n,i=de)=>{const r=Ae(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Je(o,e,r.open,r.close,r.lo,r.hi,Ue(r.open,r.close),r)},fc=(s,t,e,n,i=de)=>{const r=uc(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Me(o,r.close)};class gc{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new R,this.dataSetSubject=new R,this.dataRemovedSubject=new R,this.dataPrependSubject=new R,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},n=this.mainDataPoints){const i=Te(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=Fl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Vi(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):fc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var pc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,Gi=(s,t,e)=>t in s?pc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,bc=(s,t)=>{for(var e in t||(t={}))mc.call(t,e)&&Gi(s,e,t[e]);if(Ui)for(var e of Ui(t))vc.call(t,e)&&Gi(s,e,t[e]);return s};class Cc{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={},this.isColorsChanged=()=>!Oi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=bc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const yc=(s,t,e,n,i,r,o)=>{const a=Jl(),l=[e*a,n*a,i*a,r*a];let c=s.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=it(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Zi=(s,{x:t,width:e,activeCandle:n})=>new Je(t,e,s.open,s.close,s.hi,s.lo,Ue(s.open,s.close),s,!0,Xs(s,n)),wc=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,rl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},$i=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,Ue((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},Sc=$i,Xs=(s,t)=>{const e=t&&t.id===s.id;return e!=null?e:!1},Ki=()=>Ds,se=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=se.getPriceIncrement(e||s,t);return dt.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=se.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*se.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<se.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*se.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return se.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Rt=se;Rt.DEFAULT_INCREMENT=.01,Rt.DEFAULT_PRECISION=2,Rt.RELATIVE_EPS=1e-8,Rt.MAXIMUM_PRECISION=10;const xc=(s,t)=>{var e;const n=(e=yt(t))!=null?e:1;return Math.pow(10,-n)};var _c=Object.defineProperty,Pc=Object.defineProperties,Tc=Object.getOwnPropertyDescriptors,qi=Object.getOwnPropertySymbols,Mc=Object.prototype.hasOwnProperty,Ac=Object.prototype.propertyIsEnumerable,Ji=(s,t,e)=>t in s?_c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ec=(s,t)=>{for(var e in t||(t={}))Mc.call(t,e)&&Ji(s,e,t[e]);if(qi)for(var e of qi(t))Ac.call(t,e)&&Ji(s,e,t[e]);return s},Ic=(s,t)=>Pc(s,Tc(t));const Dc=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Qi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return Ic(Ec({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Qi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},Lc=400,tr=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:Lc,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},We,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class Oc{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){Bc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const Bc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=er(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function er(s){if(s.length===0)return Rc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const Rc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),sr=(s,t)=>s/t,Fc=(s,t)=>s/t,Hc=(s,t)=>s*t,nr=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.yEnd-s.yStart;t.zoomY=Fc(t.zoomX,i);const o=t.zoomY/n,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},kc=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.xEnd-s.xStart;t.zoomX=Hc(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},jc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},Yc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},ir=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=s.calculateZoomX(t.xStart,t.xEnd),t},Nc=(s,t,e,n)=>ir(s,t,1,e,n);var Xc=Object.defineProperty,zc=Object.defineProperties,Wc=Object.getOwnPropertyDescriptors,rr=Object.getOwnPropertySymbols,Vc=Object.prototype.hasOwnProperty,Uc=Object.prototype.propertyIsEnumerable,or=(s,t,e)=>t in s?Xc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Qe=(s,t)=>{for(var e in t||(t={}))Vc.call(t,e)&&or(s,e,t[e]);if(rr)for(var e of rr(t))Uc.call(t,e)&&or(s,e,t[e]);return s},Gc=(s,t)=>zc(s,Wc(t));const Zc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class ar extends tc{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=ee(t.scale),this.autoScaleModel=new Oc(this),this.offsets=this.config.components.offsets}doActivate(){super.doActivate(),this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=Qe(Qe({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();ir(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();Nc(this,n,e,t),this.zoomXTo(n,t,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e,n){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),n?this.apply(o):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const n=this.getBounds().width,i=.001;if(n>0){const r=qe(this.config.components.chart.minCandles,n),a=t!==r&&t-r<=i&&e,l=qe(n/this.config.components.chart.minWidth,n),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,n=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Gc(Qe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,l)))}setYScale(t,e,n=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio){this.setLockedYScale(t,e,n,i);return}super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,n=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,n);const o=this.export(),a=this.scalePostProcessor(i,o);kc(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),n=Qe({},e);this.haltAnimation(),jc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Yc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),ec(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}}class $c extends ar{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Kc=Ge().colors;class Ut extends Xi{constructor(t,e,n,i,r,o,a,l,c=Kc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Zc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new R,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=Dc(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=Rt.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const n=Ot(this.visualPoints,t,r=>r.startUnit).index,i=Ot(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=yt(this.dataPoints);t&&(this.lastPriceMovement=Ue(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Qi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Ki;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,p=(i=this.candlesTransformersByChartType[r])!=null?i:Zi;o.push(p(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ds}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Rp(s){switch(s){case"line":case"area":return!0;default:return!1}}class qc{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=!!i.color;if(n instanceof Ut){const a=Ct(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=n.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:n.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=n.extentComponent.getBounds(),c=a[0],h=n.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],p=a[d],v=n.view.toX(p.centerUnit),P=n.view.toY(p.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(it(v),_),t.moveTo(it(v),P);else if(f===void 0){t.lineTo(it(v),P),t.stroke(),t.lineTo(it(v),_),t.lineTo(it(h),_),t.closePath();let D;i.color?t.fillStyle=i.color:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(D=t.createLinearGradient(0,0,0,l.height),D.addColorStop(0,n.colors.areaTheme.startColor),D.addColorStop(1,n.colors.areaTheme.stopColor),D):"",o||t.fill()}else t.lineTo(v,P)}}}}function lr(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Jc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,p=c==="right"?h:-h,v=h;s.save(),s.beginPath(),l?s.moveTo(r+p,o):s.moveTo(r,o),l?(s.lineTo(r+f-p,o),s.quadraticCurveTo(r+f,o,r+f,o-v),s.lineTo(r+f,e+v),s.quadraticCurveTo(r+f,e,r+f-p,e),s.lineTo(t+p,e)):(s.lineTo(r+f,o),s.lineTo(r+f,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-p/3,e+v/3),s.lineTo(n+p/3,i-v/3),s.quadraticCurveTo(n,i,n+p/3,i+v/3),s.lineTo(r-p/3,o-v/3),s.quadraticCurveTo(r,o,r+p/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Qc(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function ne(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function cr(s,t,e){const n=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);s.fillRect(n,i,r,o)}const Gt=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Fp=s=>Array.isArray(s[0])?s:[s];class th{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Gt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const n=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||n&&!Ql(n)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const ie=(s,t,e,n,i=t)=>{n.hoverWidth?s.lineWidth=n.hoverWidth:e.highlighted?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class eh{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.color)t.strokeStyle=e.color;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.barLineWidth,n,i),ne(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=n.view.toX(o.centerUnit),l=n.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(n.view),f=Mt(n.view.xPixels(o.width)/2),p=n.view.toY(o.close),v=n.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,p),t.lineTo(a+f,p),t.moveTo(l,v),t.lineTo(a,v),t.stroke()}})}}}class sh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Ut){const r=Ct(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],p=n.view.toX(c.centerUnit),v=n.view.toX(d.centerUnit),P=n.view.toY(d.close),_=u?n.view.toY(u.close)<l:!1,D=P<l;if(u!==void 0&&_!==D){hr(t,n,i,_);const O=n.view.toX(u.centerUnit),j=n.view.toY(u.close),H=v-O,B=P-j,Y=H/B,W=P-l,G=Y*W,V=O+(H-G);t.lineTo(V,l),t.stroke(),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(V,l)}u===void 0?(t.beginPath(),t.moveTo(v,P)):f===void 0?(hr(t,n,i,D),t.lineTo(v,P),t.stroke(),t.lineTo(v,l),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(p,l),t.lineTo(v,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(v,P)}}}}const hr=(s,t,e,n)=>{e.color?(s.fillStyle=e.color,s.strokeStyle=e.color):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class nh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),ne(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=n.view.toX(i.startUnit),d=n.view.xPixels(i.width),u=i.bodyHeight(n.view),[f,p,v,P]=i.yBodyKeyPoints(n.view),_=p===v?p+1:v,D=f===P?f+1:P,O=l[`${a}Color`],j=a==="none"?O:l[`${a}WickColor`];t.fillStyle=O,e.color?t.strokeStyle=e.color:t.strokeStyle=j;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.moveTo(h+1,p),t.lineTo(h+1,_),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,f,D,p,_),c||(t.beginPath(),t.moveTo(h+Y,p),t.lineTo(h+Y,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,p+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,f,D,p,_);const W=this.config.candlePaddingPercent,G=Math.max(d*W/2,this.pixelLength),V=h+G,U=d-G*2;if(!c){e.color&&(t.fillStyle=e.color);const Z=e.hoverWidth?d+G:U,$=e.hoverWidth?u+e.hoverWidth+G:u;t.fillRect(V,p,Z,$)}H&&this.drawCandleBorder(t,e,l,i,V+this.halfLineWidthCU,p+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class ih{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),f=n.view.toY(l.close),p=Mt(n.view.xPixels(l.width));t.fillRect(u,f,p,h);const v=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(v.addColorStop(0,d[`${c}Cap`]),v.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=v),p===0?(t.beginPath(),t.strokeStyle=v,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,p,a-f-h)}}}}class rh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),f=n.view.toX(c.centerUnit),p=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,p),t.stroke()}}}}const oh=1.5;class ah{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=i.hoverWidth?i.hoverWidth/2:oh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of Ct(e)){t.beginPath();const l=n.view.toX(a.centerUnit),c=n.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const lh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class ch{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Gt(t,this.chartBounds())}isChartTypeAllowed(){return lh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Gt(t,e.scale.getBounds())}}class hh{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(it(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(ft(h.width,u)),p=Mt(h.bodyHeight(this.chartModel.scale)),v=h.xCenter(this.chartModel.scale)-f/2,P=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,D=Mt(f*_/2),O=v+D,j=f-D*2;t.fillRect(O,P,j,p)}})})}}const dh=(s,t,e,n)=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);n===0?t.moveTo(o,a):t.lineTo(o,a)},dr=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{dh(n,t,e,i)})},uh=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,fh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,gh=/^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*[)]$/,ph=s=>uh.exec(s),mh=s=>fh.exec(s),Hp=s=>gh.exec(s);function vh(s){const t=ph(s)||mh(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const ur={};function bh(s,t){let e=ur[s+t];if(!e){const n=vh(s);e=n&&"rgba("+n.join(",")+","+t+")",ur[s+t]=e}return e}class Ch{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.color)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(fr(r.config.type)&&fr(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{var f,p;const v=Math.min(d.length,(p=(f=h[u])==null?void 0:f.length)!=null?p:0);for(let D=0;D<v;D++){const O=[d[D].clone(),h[u][D].clone()];a.push({diffPoints:O})}const P=l.getPaintConfig(u).color,_=r.getPaintConfig(o).color;this.drawDifference(t,P,_,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[f,p]=u.diffPoints;l.push(f),c.push(p)});const h=this.mapDataSeriesDiffPointsIntoPoints(l,r.view),d=this.mapDataSeriesDiffPointsIntoPoints(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=ce(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=yt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,f)=>{f===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.color?r.color:bh(e||"#383838",.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(n=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const fr=s=>s==="DIFFERENCE";class yh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ie(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class wh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}}class Sh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class xh{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=Pt(d,t,c),f=jt(c,t),p=n.view.toX(h.centerUnit)-u/2,v=n.view.toY(h.close)+f;t.fillText(d,p,v)})}),t.restore()}}class _h{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const zs="resized_local",ts="draw",kp="draw_last_candle",ue={width:20,height:20};class gr{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Ws;var a;i.push(this),this.parent=Mh(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ue.width&&this.height>ue.height}}const Ws={name:"candle"},Ph={candle:Ws,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function Th(s,t,e,n,i,r,o){var a;const l=re(s,t,i,r,o,e);return l.type=(a=Ph[n])!=null?a:Ws,l}function re(s,t,e,n,i,r,o){const a=new gr(s,t,n,i,r,o);return pr(a,e),a}function pr(s,t){const e=s.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function Mh(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const es="HIT_TEST_",Xp=null;class Ah{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${bt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(es)!==-1&&this.drawersMap[n].draw()})},t.on(ts,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),Yn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(es)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(es)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}za(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ue.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ue.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=bt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=Vn(this.drawingOrder,t)}}class mr{static paneResizer(t){return`PANE_RESIZER_${t}`}}const Eh=7;class Ih{constructor(t,e,n,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Gt(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:Eh};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const vr={dragPredicate:()=>!0};class br extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class ss extends br{constructor(t,e,n,i,r=vr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const Dh="BASELINE_RESIZER";class Lh extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=n,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Rs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&xl(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new ss(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[Dh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const Oh=16,Bh=s=>{var t;try{const e=Ce(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=Ce(s.hi,Math.max(s.open,s.close),e),i=Ce(s.lo,Math.min(s.open,s.close),e),r=Ce(s.open,s.lo,e),o=Ce(s.close,s.hi,e),a=Number.isNaN(s.vwap)?void 0:s.vwap;return{id:s.id,hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility,vwap:a,typicalPrice:s.typicalPrice}}catch(e){console.warn(e);return}},Ee=(s,t=0)=>{for(let e=t;e<s.length;++e)s[e].idx=e},Cr=s=>{s.forEach(t=>{t.idx=void 0})},Rh=s=>s!==void 0;class Fh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0),o=Ct(e),a=n.getPaintConfig(0);ie(t,a.lineWidth,n,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,p,v,P,_;const D=Hh(o,c),O=D&&l.close<D;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(O?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){O&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!O&&l.close<0&&(t.strokeStyle=(p=i.color)!=null?p:a.multiplyColors[1]||a.color||"#FF00FF"),O&&l.close>0&&(t.strokeStyle=(v=i.color)!=null?v:a.multiplyColors[2]||a.color||"#FF00FF"),!O&&l.close>0&&(t.strokeStyle=(P=i.color)!=null?P:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const j=n.view.toX(l.centerUnit),H=n.view.toY(l.close);t.moveTo(j,r),t.lineTo(j,H),t.stroke()})}}const Hh=(s,t)=>{do t--;while(t>=0&&!isFinite(s[t]&&s[t].close));return s[t]?s[t].close:void 0},kh=(s,t)=>{let e=0;return(...n)=>{clearTimeout(e),e=+setTimeout(()=>s(...n),t)}};var jh=Object.defineProperty,yr=Object.getOwnPropertySymbols,Yh=Object.prototype.hasOwnProperty,Nh=Object.prototype.propertyIsEnumerable,wr=(s,t,e)=>t in s?jh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Sr=(s,t)=>{for(var e in t||(t={}))Yh.call(t,e)&&wr(s,e,t[e]);if(yr)for(var e of yr(t))Nh.call(t,e)&&wr(s,e,t[e]);return s};class Xh{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class zh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=p,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=P=>{var _;return(_=this.barTypeValues.find(D=>D===P))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Lh(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const v=new Ih(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(v,es+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new Cc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new th(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(kh(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Oh))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Zi),this.registerCandlesTransformer("trend",$i),this.registerCandlesTransformer("hollow",wc),this.registerCandlesTransformer("line",Sc)}get barTypeValues(){return Li(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new nh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new eh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new rh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new ah(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new qc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new sh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new ih(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new wh),this.registerDataSeriesTypeDrawer("HISTOGRAM",new yh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Fh),this.registerDataSeriesTypeDrawer("POINTS",new Sh),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new ch(new hh(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new xh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new _h),this.registerDataSeriesTypeDrawer("DIFFERENCE",new Ch)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(Sr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=Sr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Cr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,n=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,n)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!Rt.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Rt.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}class xr extends Ut{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var Wh=Object.defineProperty,_r=Object.getOwnPropertySymbols,Vh=Object.prototype.hasOwnProperty,Uh=Object.prototype.propertyIsEnumerable,Pr=(s,t,e)=>t in s?Wh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gh=(s,t)=>{for(var e in t||(t={}))Vh.call(t,e)&&Pr(s,e,t[e]);if(_r)for(var e of _r(t))Uh.call(t,e)&&Pr(s,e,t[e]);return s};const Zh=(s,t,e,n)=>{var i,r,o,a;const l=Gh({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ga(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Nt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},$h=s=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const n=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),i=n[0],r=n[n.length-1];s.setXScale(i.startUnit,r.startUnit+r.width+s.offsets.right)}e.yScale&&s.doAutoScale(!0),s.fireChanged()}},Kh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var qh=Object.defineProperty,Jh=Object.defineProperties,Qh=Object.getOwnPropertyDescriptors,Tr=Object.getOwnPropertySymbols,td=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,Mr=(s,t,e)=>t in s?qh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ie=(s,t)=>{for(var e in t||(t={}))td.call(t,e)&&Mr(s,e,t[e]);if(Tr)for(var e of Tr(t))ed.call(t,e)&&Mr(s,e,t[e]);return s},Vs=(s,t)=>Jh(s,Qh(t));class sd{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,n)=>Vs(Ie({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=Vs(Ie({},ee(this.config.colors)),{lineTheme:Ie({},n.lineTheme),areaTheme:Ie({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=Vs(Ie({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var nd=Object.defineProperty,Ar=Object.getOwnPropertySymbols,id=Object.prototype.hasOwnProperty,rd=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?nd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ns=(s,t)=>{for(var e in t||(t={}))id.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))rd.call(t,e)&&Er(s,e,t[e]);return s};class od extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new R,this.mainInstrumentChangedSubject=new R,this.offsetsChanged=new R,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(Bh).filter(Rh),{sortCandles:p}=this.config.components.chart;return p?p(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new sd(this.config);const d=new xr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Xh,this.candlesTransformersByChartType,this.candleWidthByChartType,ns({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Zh(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=$h(o),this.timeFrameViewportTransformer=Kh(o,this),this.pane=this.paneManager.panes[q]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(q)).pipe(At(bi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ue.width&&t.height>ue.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),n=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Nt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=Nt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return Cr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Ee(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=ns({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Dr(this.mainCandleSeries.dataPoints,i),o=r.candles;Ee(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),p=Dr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(p,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(n=>{const i=Ot(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=ns(ns({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Ut(this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)n.push(a);else{let l=Ir(e,o,-1);if(l||(l=Ir(e,o,1)),l){const c=ol(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Tt(t,Ge().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=Ot(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=ye((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Ae(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Ae(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(n=>n.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(n=>n.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return yt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return yt(t)}getMaxCandlesFitLength(){return it(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=Te(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Te(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const p=f>=o.length-1,v=c&&h.timestamp<c.timestamp;if(p&&!v&&(c=h),a&&c&&n&&l){const P=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Ki;this.scale.moveXStart(this.scale.xStart+P(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return vt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const n=t.slice(),i=[];return e.forEach(r=>{const a=Te(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Ee(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const n=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(n<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,n).concat(e.dataPoints.slice(i+1)),Ee(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(n=>this.removeCandleByIdx(this.candleIdxFromId(n,e)))}addCandlesById(t,e,n){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=n.dataPoints.slice(0,i),o=n.dataPoints.slice(i);n.dataPoints=r.concat(t).concat(o),Ee(n.dataPoints),n.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Ir=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Dr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=Te(r.timestamp,{extrapolate:!0},s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class fe{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Us{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Di(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=Di(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=Ct(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class ad{constructor(t,e,n,i){this.model=t,this.config=e,this.crossToolCanvasModel=n,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var ld=Object.defineProperty,cd=Object.defineProperties,hd=Object.getOwnPropertyDescriptors,Lr=Object.getOwnPropertySymbols,dd=Object.prototype.hasOwnProperty,ud=Object.prototype.propertyIsEnumerable,Or=(s,t,e)=>t in s?ld(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fd=(s,t)=>{for(var e in t||(t={}))dd.call(t,e)&&Or(s,e,t[e]);if(Lr)for(var e of Lr(t))ud.call(t,e)&&Or(s,e,t[e]);return s},gd=(s,t)=>cd(s,hd(t));class pd extends X{constructor(t,e,n,i,r,o){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?kt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(kt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,q]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:n,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(x.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=n.x+l,d=n.y+c,u=o.y+a,f=o.y+o.height-a,p=h<a?a:h>o.width-a?o.width-a:h,v=d<u?u:d>f?f:d,P=(e=this.hoverProducer.createHover(p,v,t.paneId))!=null?e:t,_=gd(fd({},P),{x:p,y:v});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const Et=4;function md(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p;const v=r.align,P=(l=i.textFont)!=null?l:Qt(r),_=i.bgColor,D=(c=i.textColor)!=null?c:Jt(_,o.labelTextColor,o.labelInvertedTextColor),O=(h=i.paddingTop)!=null?h:Et,j=(d=i.paddingBottom)!=null?d:Et,H=(u=i.paddingEnd)!=null?u:Et,B=ye(jt(P,s)/2),Y=n-B-O,G=n+B+j-Y;if(a&&!is(n,t,G))return;s.save(),s.fillStyle=_,s.strokeStyle=_;const V=ye(t.width/6),U=v==="right"?t.x:t.x+t.width,Z=v==="right"?U+V:U-V,$=r.labelBoxMargin.end,et=$-H,tt=t.width-V-et;Jc(s,Z,Y,U,Y+ye(G/2),Z,Y+G,tt,(p=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?p:!1,v),s.fillStyle=D,s.font=P;const Q=v==="right"?t.x+t.width-Pt(e,s,P)-$:t.x+$;s.fillText(e,Q,n+B-1),s.restore()}function vd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P,_,D;const O=r.align,j=(l=i.textFont)!=null?l:Qt(r),H=i.bgColor,B=(c=i.textColor)!=null?c:Jt(H,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,W=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Et,G=(p=(f=i.paddingBottom)!=null?f:Y==null?void 0:Y.bottom)!=null?p:Et,V=(P=(v=i.paddingEnd)!=null?v:Y==null?void 0:Y.end)!=null?P:Et,U=i.paddingStart,Z=jt(j,s),$=n-Z/2-W,tt=n+Z/2+G-$,Q=(D=i.rounded)!=null?D:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!is(n,t,tt))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const rt=r.labelBoxMargin.end;s.font=j;const lt=Pt(e,s,j),ot=rt-V,xt=U!==void 0?lt+U+V:t.width-ot,Vt=O==="right"?t.x+t.width-ot-xt:t.x+ot,me=O==="right"?t.x+t.width-lt-rt:rt;Q?lr(s,Vt,$,xt,tt,4,!0):s.fillRect(Vt,$,xt,tt),s.fillStyle=B,s.fillText(e,me,n+Z/2-1),s.restore()}function bd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P;const _=r.align,D=(l=i.textFont)!=null?l:Qt(r),O=o.backgroundColor,j=(c=i.textColor)!=null?c:Jt(O,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Et,Y=(p=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?p:Et,W=(P=(v=i.paddingEnd)!=null?v:H==null?void 0:H.end)!=null?P:Et,G=i.paddingStart,V=jt(D,s),U=n-V/2-B,$=n+V/2+Y-U;if(a&&!is(n,t,$))return;s.save(),s.fillStyle=O,s.strokeStyle=O;const et=r.labelBoxMargin.end;s.font=D;const tt=Pt(e,s,D),Q=et-W,rt=G!==void 0?tt+G+W:t.width-Q,lt=_==="right"?t.x+t.width-Q-rt:t.x+Q,ot=_==="right"?t.x+t.width-tt-et:et;s.fillStyle=O,s.strokeStyle=O,s.fillRect(lt,U,rt,$),s.fillStyle=j,s.fillText(e,ot,n+V/2-1),s.restore()}function Cd(s,t,e=Et){return jt(s,t)/2+e}function is(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const yd="badge",Br=4,Rr={badge:md,rectangle:vd,plain:bd};function Fr(s,t,e,n,i,r,o,a,l){var c,h,d,u,f;const p=r.y,v=r.labelText,P=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:yd,D=r.description,O=(d=r.textFont)!=null?d:Qt(a),j=r.bgColor,H=(u=r.lineColor)!=null?u:j,B=Pt(D!=null?D:"",s,O)+8,Y=it(r.y),W=jt(O,s),G=p-W/2,U=p+W/2-G;s.save(),s.fillStyle=j,s.strokeStyle=H;const Z=o.getBounds(x.PANE_UUID(q)),$=Rr[_],et=a.labels.descriptions,tt=wd(n,Y,U),Q=()=>et&&Sd(e,t,n,i,r,a);let rt,lt;const ot=2;a.align==="right"?(rt=Z.x,lt=et?Z.x+Z.width-B:Z.x+Z.width+ot):(rt=et?Z.x+B:Z.x-ot,lt=Z.x+Z.width);const xt=(f=r.lineY)!=null?f:r.y,Vt=()=>tt&&ne(s,()=>Qc(s,rt,xt,lt,xt,1)),me=()=>$(s,n,v,p,r,a,l.yAxis,!1),dn={line:()=>{Vt(),Q()},"line-label":()=>{Vt(),me(),Q()},label:()=>{Q(),me()}};P!=="none"&&is(p,n,U)&&dn[P](),s.restore()}const wd=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Sd(s,t,e,n,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=Qt(r),f=Pt(h,t,u),p=jt(u,t),v=(o=i.paddingTop)!=null?o:Br,P=(a=i.paddingBottom)!=null?a:Br,_=d-p/2-v,O=d+p/2+P-_;t.save();const j=f+5,H=4,B=f+H*2,Y=n.x+n.width,W=c==="right"?Y-B:n.x+H;yc(s,t,W,_,j,O,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const G=c==="right"?Y-f-H*2:n.x+H*2;t.fillText(h,G,d+p/2-1),t.restore()}class Hr{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&ne(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const p={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},v={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},P=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),P&&(t.moveTo(...p.start),t.lineTo(...p.end)),t.moveTo(...v.start),t.lineTo(...v.end),t.stroke()),P&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,p=this.config.components.xAxis.fontSize,v=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const P=(n=l==null?void 0:l.left)!=null?n:0,_=(i=l==null?void 0:l.right)!=null?i:0,D=(r=l==null?void 0:l.top)!=null?r:0,O=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,H=f+P+_,B=p+D+O,Y=Math.max(d-H/2,0),W=v.y+j+Se/2;lr(t,Y,W,H,B),t.fillStyle=h.labelTextColor;const G=Math.max(d-f/2,P),V=v.y+j+p+Se/2+D-1;t.fillText(u,G,V),t.restore()}}drawYLabel(t,e){const n=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=Rr[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class xd{draw(){}}class _d extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.crossToolTypeDrawers={},this.model=new pd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel),this.addChildEntity(this.model);const c=new fe(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const h=new ad(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),d=new Us;d.addDrawer(c,"CLEAR_CANVAS"),d.addDrawer(h,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(d,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new xd)}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 Pd{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Xt{constructor(t){this.data=t,this.next=null}}class Td{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new Xt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new Xt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class Md extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new Xt(n);return i.getNodePosition(r)}addObject(t){var e,n;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new Td;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((n=t.parentId)!=null?n:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[n]=e;this.removeObject(n.id),this.addObject(t)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Xt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class Ad extends X{constructor(t,e){super();const n=new Md(t);this.model=n,this.addChildEntity(n);const i=new Pd(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Ed=()=>s=>s.toString(),Id=(s,t)=>{var e;const n="date.get"+(t((e=s.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return n+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:Dd(s),shortMonths:Ld(s),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=s.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Od(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Dd(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Ld(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const kr=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Ed()},Od=(s,t,e,n)=>{t||(t="M/d/yyyy");const i=s.getDate(),r=s.getMonth(),o=s.getFullYear(),a=s.getHours(),l=s.getMinutes(),c=s.getSeconds(),h=s.getMilliseconds(),d=a%12,u=ge(d),f=ge(a),p=ge(l),v=ge(c),P=a<12?"AM":"PM",_=e[s.getDay()],D=_.substring(0,3),O=ge(i),j=r+1,H=ge(j),B=n[r],Y=B.substring(0,3),W=o+"",G=W.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",p+"").replace("m",l+"").replace("ss",v+"").replace("s",c+"").replace("S",h+"").replace("dd",O+"").replace("d",i+"").replace("EEEE",_).replace("EEE",D).replace("YYYY",W).replace("yyyy",W).replace("YY",G).replace("yy",G).replace("aaa",P),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",Y):t=t.replace("MM",H+"").replace("M",j+""),t},ge=s=>typeof s=="number"&&s<10?"0"+s:s,De=(s,t)=>`${s}_${t}`,Bd=(s,t)=>{if(t){const e=jr(t.normal),n=jr(t.hover);return{type:s,normal:e,hover:n}}},jr=s=>{var t;const n=new DOMParser().parseFromString(s,"text/html").querySelector("svg");let i=0;n&&(i=parseInt((t=n.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(s),l=new Image;return l.src=a,{img:l,svgHeight:i}},Rd=(s,t,e,n,i)=>{if(i){const r=t[De(n,"hover")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[De(n,"normal")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Fd={"rhombus-small":4,rhombus:6,"rhombus-large":8},Hd=["earnings","dividends","splits","conference-calls"];class kd{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&Hd.forEach(l=>{const c=Bd(l,a[l]);c&&(this.customIcons[De(c.type,"normal")]=c.normal,this.customIcons[De(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(n.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[De(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Rd(n,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(n,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);n.lineWidth=u!=null?u:1,n.beginPath(),n.setLineDash(f!=null?f:[]),n.moveTo(c,e.y),n.lineTo(c,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),n.restore()}drawDefaultEvent(t,e,n,i,r){var o,a,l;const c=n.y+n.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=Gs(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function Gs(s){return Fd[s.style]}const rs=5;class jd{constructor(t,e,n,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{if(!this.config.components.events.eventsVisibility[n.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[n.type].color;t.strokeStyle=c,t.fillStyle=c;const h=Gs(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const d=(h+rs)*2;if(a!==void 0){const u=Gs(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const v=h*2+rs;t.fillRect(a+u,e.y,v,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Yd=Object.defineProperty,Yr=Object.getOwnPropertySymbols,Nd=Object.prototype.hasOwnProperty,Xd=Object.prototype.propertyIsEnumerable,Nr=(s,t,e)=>t in s?Yd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,zd=(s,t)=>{for(var e in t||(t={}))Nd.call(t,e)&&Nr(s,e,t[e]);if(Yr)for(var e of Yr(t))Xd.call(t,e)&&Nr(s,e,t[e]);return s};const Xr=317,Zs={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class Wd extends gr{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new R,this.touchStartSubject=new R,this.dblClickSubject=new R,this.rightClickSubject=new R,this.hitTestDrawersPredicateSubject=new ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,pr(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Pe(100,_e,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=vt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=vt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ht(()=>zd({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,n,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*Xr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Xr}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ss&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ss),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=$s(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=$s(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var n,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,p]=$s(this.hitTestSubscribers,u),v=f==null?void 0:f.lookup(d),P={point:t,model:v};switch(e){case"mousedown":v&&((n=f==null?void 0:f.onMouseDown)==null||n.call(f,v,t)),p.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":v&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,v,t)),p.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":v&&((r=f==null?void 0:f.onHover)==null||r.call(f,v,t)),p.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(P);break;case"touchstart":v&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,v,t)),p.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(P);break;case"dblclick":v&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,v,t)),this.dblClickSubject.next(P);break;case"contextmenu":v&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,v,t)),this.rightClickSubject.next(P);break;case"zoom":v&&((c=f==null?void 0:f.onZoom)==null||c.call(f,v,t)),p.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const $s=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var Vd=Object.defineProperty,Ud=Object.defineProperties,Gd=Object.getOwnPropertyDescriptors,zr=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,$d=Object.prototype.propertyIsEnumerable,Wr=(s,t,e)=>t in s?Vd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Kd=(s,t)=>{for(var e in t||(t={}))Zd.call(t,e)&&Wr(s,e,t[e]);if(zr)for(var e of zr(t))$d.call(t,e)&&Wr(s,e,t[e]);return s},qd=(s,t)=>Ud(s,Gd(t));class Jd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>qd(Kd({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Zs.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Qd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>kr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Jd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new kd(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new jd(n,i,t,r,c,()=>n.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class tu{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;ne(t,()=>this.drawVertical(t)),ne(t,()=>this.drawHorizontal(t)),ne(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=it(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=Mt(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=it(this.viewportModel.toY(i.value)),o=Cd(i.text,t,Et);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Vr extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new tu(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class eu{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,n,i){const r=this.getMarkerY(t,n,i==="low"),o=Ve(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Gt(t,h)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=Ve(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class su extends X{constructor(t,e,n,i,r){super();const o=new eu(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const nu=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],iu=24*60*60*1e3;class ru extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new R}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+iu;qa(this.highlights,t,e,ou).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const ou=s=>s.to,Zt=[20,10];class au{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(x.ALL_PANES);o.save(),Gt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(n=this.config.components.highlights.fontSize)!=null?n:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",p=`${u}px ${f}, monospace`;o.font=p,o.lineWidth=h,o.setLineDash(d),nu.forEach(v=>{var P,_;const D=a[v];if(D){const O=this.config.colors.highlights[v],j=(P=O==null?void 0:O.border)!=null?P:"#ffffff",H=(_=O==null?void 0:O.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=j,D.forEach(B=>{var Y,W,G;const V=this.chartModel.candleFromTimestamp(B.from),U=ft(V.width,this.chartModel.scale.zoomX),Z=V.xStart(this.chartModel.scale),$=B.to-this.chartModel.chartBaseModel.period,et=this.chartModel.candleFromTimestamp($),tt=ft(et.width,this.chartModel.scale.zoomX),Q=et.xStart(this.chartModel.scale)+tt;if(B.border&&this.drawBorders(B.border,o,Z+U,Q-tt,c),o.fillRect(Z,c.y,Q-Z,c.y+c.height),B.label){const rt=(Y=B.label.text)!=null?Y:"",lt=this.config.colors.highlights[B.type];o.save(),o.fillStyle=(W=lt==null?void 0:lt.label)!=null?W:"#ffffff";const ot=Pt(rt,o,p),[xt,Vt]=this.resolveHighlightLabelPosition((G=B.label.placement)!=null?G:"left-left",c,[Z,Q],ot);o.fillText(rt,xt,Vt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Zt[1]-i,e.y+Zt[0]];case"left-left":return[r-Zt[1]-i,e.y+Zt[0]];case"right-right":return[o+Zt[1],e.y+Zt[0]];case"left-right":default:return[r+Zt[1],e.y+Zt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const lu="HIGHLIGHTS_PLUGIN";class cu extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new ru(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new au(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,lu)}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 hu(){return N(function(s,t){var e,n=!1;s.subscribe(mt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function J(s,t){return N(function(e,n){var i=0;e.subscribe(mt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var du=Object.defineProperty,uu=Object.defineProperties,fu=Object.getOwnPropertyDescriptors,Ur=Object.getOwnPropertySymbols,gu=Object.prototype.hasOwnProperty,pu=Object.prototype.propertyIsEnumerable,Gr=(s,t,e)=>t in s?du(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zr=(s,t)=>{for(var e in t||(t={}))gu.call(t,e)&&Gr(s,e,t[e]);if(Ur)for(var e of Ur(t))pu.call(t,e)&&Gr(s,e,t[e]);return s},$r=(s,t)=>uu(s,fu(t));const zt=4;class mu{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),n.width!==0&&this.drawLeftArrowButton(c,n,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=n.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=Ct(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:$r(Zr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:$r(Zr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=qn(n,i.dateFormat,this.formatterFactory);Zn(t,i.textProperties);const a=Ve(t),l=Kn(o);Qa(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Le extends br{constructor(t,e,n,i,r=vr){super(t,e,n,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const Kr=4;class vu extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-p.x-Kr},this.leftKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-p.x+Kr},this.rightKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:p}=f,v=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),P=this.chartModel.mainCandleSeries.meanCandleWidth/(v.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-p)*P;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=p};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Le(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Le(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new Le(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class bu extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new mu(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new vu(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(hu(),J(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,f,p;for(f=0;f<h;f++)p=it(f*o/h)-r,p in e?(d[f]=e[p].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((v,P)=>[P+c.x,(a+l-v)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(zs),this.canvasModel.fireDraw())}}const qr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},zp=(s,t)=>s==="apple"||s==="mobile"?3:t,Cu=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),yu=!!window.chrome,Jr=typeof InstallTrigger!="undefined",wu=navigator.platform.indexOf("Win")>-1,Wp=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Cu)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(yu){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,wu){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else Jr?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return Jr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Su=(s,t)=>s==="percent"?t/4:t;var Ks=Math.pow;class xu extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=15,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const v=this.canvasBoundsContainer.getBounds(x.CANVAS).width,_=d.offsetX/v;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(We),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Nt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Le(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(J(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Pe(this.wheelThrottleTime,_e,{trailing:!0,leading:!0})).subscribe(e=>{const n=qr(),i=n==="apple"||n==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Nt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return Su(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(We),this.currentPoint={x:0,y:0},n=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)_u(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Nt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new ss(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const _u=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Ks(Ks(Math.abs(s.x),2)+Ks(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle},Pu=2;class Tu extends X{constructor(t,e,n,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:n}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:n}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:n}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=Qr(e,i.x,n,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=n+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;n>=i||e[0]===e[1]||this.scale.setXScale(n,i)}}const Qr=(s,t,e,n,i=Pu)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-n,2))>i;class Mu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c,this.chartAreaPanHandler=new xu(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new Tu(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const to=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},eo=(s,t)=>{const e=to(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function Au(){return Ln(1)}function so(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return Au()(Ye(s,je(s)))}function Eu(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s);return N(function(n,i){(e?so(s,n,e):so(s,n)).subscribe(i)})}function Iu(s){return J(function(t,e){return s<=e})}class Du{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const no=8;class qs extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new R,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=p=>{const{delta:v,draggedPixels:P}=p;Math.abs(this.initialY-this.boundsProvider().y+P)>=0&&(this.dragTickCb(v),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new ss(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:kt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:kt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Eu(!1),J(this.dragPredicate),At(),Iu(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Du(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,mr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(mr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const io=1/32,Lu=s=>{const t=Math.floor(s),e=s-t,n=Math.round(e*64),r=Math.floor(n/2).toString().padStart(2,"0");return`${t}'${r}`},Vp=s=>!!s.match(/^\-?0*(\d+)'(\d{2})$/),Ou=(s,t)=>e=>{let n;if(typeof e=="number")n=e;else if(typeof e=="string")n=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return Lu(n);const[r]=s.dataSeries;if(r!==void 0){const o=Rt.getPricePrecision(n,r.pricePrecisions);return n.toFixed(o)}return`${n}`},Bu=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ri(t,r.getBaseline()));const o=i.toFixed(Rt.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Ru=(s,t)=>({percent:Bu(s),regular:Ou(s,t)});class Fu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u=new Set,f={regular:dc}){super(),this.config=t,this.paneUUID=e,this.idx=n,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(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=p=>p.map(v=>new Me(this.chartBaseModel.dataFromTimestamp(v.timestamp).centerUnit,v.close)),this.toY=p=>{var v,P;return(P=(v=this.mainDataSeries)==null?void 0:v.view.toY(p))!=null?P:1},this.valueFormatter=(p,v)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(p);const{regular:P,percent:_,logarithmic:D}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(p);case"percent":return _?_(p,v):P(p);case"logarithmic":return D?D(p):P(p);default:return this.regularFormatter(p)}},this.addChildEntity(c),this.setValueFormatters(Ru(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 Xi(this,bt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const ro=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return er(e)}});class Hu{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Zs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Zs.DATA_SERIES}get allDataSeries(){return we(we(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Wt="#FF00FF";function Up(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const ku=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,ju=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Wt},Yu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Wt},Nu=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Wt},Xu=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Wt},zu=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Wt},Wu=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:Wt},Vu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Wt},oo=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Wt},Uu=()=>(console.warn("Fallback for label default color"),Wt),ao=10;class lo extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new R,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(x.Y_AXIS).height,ui),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(ao-1)):d=1+h/this.lastYPxHeight*(ao-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,p=this.lastYStart-f,v=this.lastYEnd+f;(this.lastYStart!==p||this.lastYEnd!==v)&&(this.scale.setYScale(p,v),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new ss(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Gu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${bt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Yn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const Zu=0,$u=.01;class Js{constructor(t,e,n,i,r=!1,o,a,l=Ms,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new R,this.newGeneratedLabelsSubject=new R,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Gu(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=dt.roundToNearest(t,n);for(;r<e;){const o=dt.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=dt.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=dt.roundToNearest(t,n);for(;o<e;){const a=dt.roundToNearest(o,n),l=Fi(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=dt.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=dt.roundToNearest(t,n);for(;r<e;){const o=Ns(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=dt.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),n=this.lengthProvider(),i=Js.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const n=(e=this.treasuryFormat)!=null&&e.enabled?io:Rt.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(n)}return this.adjustIncrementOnAxisType($u)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Ns(e)+t;return Hi(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,n){const i=Math.abs((e-t)*(Zu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class Ku extends Js{constructor(t,e,n,i,r=()=>"regular",o=23,a){super(t,()=>[n.yStart,n.yEnd],()=>n.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,n)=>n.text.length>e.length?n.text:e,"")}updateTreasuryFormat(t){this.treasuryFormat=t}calculateIncrement(t){var e,n;const i=this.dataSeriesProvider();if(i){const r=yt(i.dataPoints),o=(e=r==null?void 0:r.close)!=null?e:0,a=xc(o,i.pricePrecisions),l=(n=this.treasuryFormat)!=null&&n.enabled?io:a;return this.adjustIncrementOnAxisType(l)}return super.calculateIncrement(t)}}function co(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?N(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(mt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):le}class qu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${bt()}`}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ht(t=>t.height),J(t=>Pa(t,this.prevYAxisHeight,1.5)),co(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class Ju extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Ku(null,l,o,a,()=>this.state.type,n.labelHeight,n),this.baseLabelsModel=new qu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new ql(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class Qu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=a,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.hitTestCanvasModel=f,this.chartResizeHandler=p,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new R,this.axisAlignSetSubject=new R,this.axisAlignMovedSubject=new R,this.setDblClickCallback=_=>this.yAxisScaleHandler.setDblClickCallback(_),this.setDblTapCallback=_=>this.yAxisScaleHandler.setDblTapCallback(_);const P=v?ee(v):{};this.state=Tt(P,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new lo(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),f),this.addChildEntity(this.yAxisScaleHandler),this.model=new Ju(this.paneUUID,t,this.state,o,n,i,c,h,u,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new lo(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Nu),this.registerLabelColorResolver("bar",ju),this.registerLabelColorResolver("line",Yu),this.registerLabelColorResolver("area",Xu),this.registerLabelColorResolver("scatterPlot",zu),this.registerLabelColorResolver("histogram",Wu),this.registerLabelColorResolver("baseline",Vu),this.registerLabelColorResolver("trend",oo),this.registerLabelColorResolver("hollow",oo)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Uu}registerYAxisLabelsProvider(t,e=te.MAIN,n=bt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=te.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class tf extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_,D,O,j){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=p,this.uuid=v,this.seriesAddedSubject=P,this.seriesRemovedSubject=_,this.hitTestCanvasModel=D,this.chartResizeHandler=O,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new R,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,Y)=>this.mainExtent.valueFormatter(B,Y);const H=this.createExtentComponent(j);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(v),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return we(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(At(bi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i,r){const o=x.PANE_UUID(t);return new Vr(this.mainCanvasModel,e,this.config,n,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(o),()=>this.canvasBoundsContainer.getBounds(o),()=>[],i,r,()=>this.config.components.grid.visible)}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new $c(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(v,P)=>new Qu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,v,P,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Fu(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),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",eo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),ro(u)));const p=this.createGridComponent(this.uuid,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(p),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(n=>n.idx).includes(e.idx)),this.yExtentComponents.forEach((e,n)=>{e.yAxis.setExtentIdx(n),e.idx=n,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,n,i="right"){const r=ee(n.yAxis.state),o=ee(n.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),n.dataSeries.size===0&&e.removeExtentComponents([n])}moveDataSeriesToExistingExtentComponent(t,e,n,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&n.dataSeries.size===0&&e.removeExtentComponents([n]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(n=>n.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=ce(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=yt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var ef=Object.defineProperty,sf=Object.defineProperties,nf=Object.getOwnPropertyDescriptors,ho=Object.getOwnPropertySymbols,rf=Object.prototype.hasOwnProperty,of=Object.prototype.propertyIsEnumerable,uo=(s,t,e)=>t in s?ef(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,af=(s,t)=>{for(var e in t||(t={}))rf.call(t,e)&&uo(s,e,t[e]);if(ho)for(var e of ho(t))of.call(t,e)&&uo(s,e,t[e]);return s},lf=(s,t)=>sf(s,nf(t));class cf extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=p,this.yAxisLabelsCanvasModel=v,this.hitTestCanvasModel=P,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new R,this.paneAddedSubject=new R,this.dataSeriesAddedSubject=new R,this.dataSeriesRemovedSubject=new R,this.hitTestController=new Hu(this.panes,this.dynamicObjectsCanvasModel);const D=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});D.mainExtent.scale.autoScaleModel.setHighLowProvider("series",ro(D.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",to(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+no}),n=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=x.PANE_UUID_RESIZER(t),o=new qs(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,n,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return we(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=bt(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new tf(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,n;const i=ce(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}canMovePaneDown(t){var e,n;const i=yt(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const n=x.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof qs&&r.id===n);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],n=x.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof qs&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,n,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?lf(af({},n.yAxis.state),{align:l}):void 0,p=c&&c>0;if(!u){const v=a&&a==="above"?d:d+1,P=this.createPane(r,{order:v,initialYAxisState:f,inverse:n.scale.state.inverse,lockToPriceRatio:n.scale.state.lockPriceToBarRatio});P.moveDataSeriesToExistingExtentComponent(t,e,n,P.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!p?u.moveDataSeriesToExistingExtentComponent(t,e,n,o):u.moveDataSeriesToNewExtentComponent(t,e,n,l!=null?l:n.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+no),()=>{this.cursorHandler.removeCursorForCanvasEl(n),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class hf extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const df=(s,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function n(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return n(s)},os=class extends X{constructor(s,t,e,n){super(),this.chartComponent=s,this.config=t,this.volumesModel=e,this.paneManager=n,t.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[os.UUID]===void 0){const t=this.paneManager.createPane(os.UUID,{paneFormatters:{regular:i=>df(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=eo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(os.UUID),delete this.pane}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let fo=os;fo.UUID="volumes";const as=.3,uf=(s,t)=>{const e=t.barTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},ff=(s,t)=>{const e=t.volume[`${s}BarColor`];return Lt()(e).alpha(as).toString()},gf=(s,t)=>{const e=t.lineTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},Qs=(s,t)=>{const e=t.candleTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},pf=3;class mf{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:ff;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const n=this.getViewportModel().getBounds();Gt(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=Ct(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?Mt(i.toX(n[o+1].startUnit)):void 0,h=Mt(i.toX(r.startUnit)),d=c!==void 0?c-h:Mt(ft(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(i.toY(r.candle.volume)),f=ks(i.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=e/(l/pf),f=Math.max(ks(ft(r.candle.volume,u)),2),p=Mt(a.y+l-f);this.drawVolume(t,r,h,p,d,f)}}})}drawVolume(t,e,n,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(n,l),a.lineTo(n,ks(c)),a.stroke()):a.fillRect(n,i,r,o)}}const vf=Ka(s=>s.candle.volume),go="volumes";class bf extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=go,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;this.volumeMax.next((t=ce(vf(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Cf extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new bf(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new fo(e,o,c,a),this.volumesDrawer=new mf(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:n},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",Qs),this.registerVolumeColorResolver("trend",Qs),this.registerVolumeColorResolver("hollow",Qs),this.registerVolumeColorResolver("line",gf),this.registerVolumeColorResolver("bar",uf)}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?go:q,n={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(n);return}this.dynamicObjectsComponent.model.updateObject(n)}}class yf{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:p,offsetY:v,offsetX:P}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=ls(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=wf(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),p){case"left-top":return{x:P+f.x,y:v+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:P+f.x,y:f.height-h-v+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let p=0,v=0,P=0,_=0,D=0;if(f.save(),d.firstRowFontSize&&l){f.font=ls(this.config,d.firstRowFontSize);const B=f.measureText(l);p=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=ls(this.config,d.secondRowFontSize);const B=f.measureText(c);v=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,P=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=ls(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,D=(n=d.secondRowBottomPadding)!=null?n:0}const O=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,H=p+v+P+_+D+O+j;if(l&&this.drawWaterMark(this.getConfig(p,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(p+P+v,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(p+P+v+D+_,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(p+P+v+D+_+O,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const wf=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},ls=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Sf=Object.defineProperty,po=Object.getOwnPropertySymbols,xf=Object.prototype.hasOwnProperty,_f=Object.prototype.propertyIsEnumerable,mo=(s,t,e)=>t in s?Sf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,vo=(s,t)=>{for(var e in t||(t={}))xf.call(t,e)&&mo(s,e,t[e]);if(po)for(var e of po(t))_f.call(t,e)&&mo(s,e,t[e]);return s};class Pf extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new yf(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return vo(vo({},this.config.components.waterMark),h)}}const bo={x:4,y:4};function Tf(s,t,e,n){var i,r;const o=(i=n.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const p=s.measureText(n.text).width+bo.x*2;let v=0;const P=n.x;switch(o){case"start":v=P-p;break;case"end":v=P;break;case"middle":default:v=P-p/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(v,u.y,p,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(P,u.y),s.lineTo(P,u.y+u.height),s.stroke()),s.fillStyle=n.color;const _=v+bo.x,D=u.y+d+a+Se/2;s.fillText(n.text,_,D),s.restore()}class Mf{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Tf(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=Lt().rgb(r[0].color).alpha(.1).toString(),cr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const Gp="week-weekday",Af=["second","minute","hour","day","month","year"],Ef=["lessThanSecond"],If=s=>Af.some(t=>t===s),Df=s=>s==="week-weekday",Lf=s=>Ef.some(t=>t===s),Co=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},tn=s=>parseInt(s,10),yo=s=>{const[t,...e]=s.split("_");if(If(t)){const[n]=e,i=Co(n),r=tn(n);return{key:t,value:r,exact:i["!"]}}else if(Df(t)){const[n,i]=e,r=Co(n),o=tn(n),a=tn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Lf(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class cs{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Se/2),e.restore()}}drawLabels(t,e,n,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Pt(c.text,t,l)/2;if(h<n.x||h>n.width)continue;const d=n.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const en={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},wo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return en[s.key]+s.value;case"lessThanSecond":return en[s.key];case"week-weekday":return en[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},So=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Of=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],p=f.idx;for(;c<a;){const v=o[c],P=v.idx;if(p>P)c++,n.push(v),d=P,h=1/0;else{h=P;break}}h-p>=t&&p-d>=t&&(n.push(f),d=p)}for(;c<a;)n.push(o[c]),c++}return n},Bf=(s,t,e,n,i,r)=>{const o=cs.getFontFromConfig(t),a=Pt(e.text,s,o),l=Pt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function sn(s){"@babel/helpers - typeof";return sn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},sn(s)}function wt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function St(s){wt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||sn(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Rf(s){return wt(1,arguments),St(s).getDay()===1}function Ff(s){return wt(1,arguments),St(s).getDay()===2}function Hf(s){return wt(1,arguments),St(s).getDay()===3}function kf(s){return wt(1,arguments),St(s).getDay()===4}function jf(s){return wt(1,arguments),St(s).getDay()===5}function Yf(s){return wt(1,arguments),St(s).getDay()===6}function Nf(s){return wt(1,arguments),St(s).getDay()===0}function Xf(s,t){var e;wt(1,arguments);var n=s||{},i=St(n.start),r=St(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(St(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function zf(s){wt(1,arguments);var t=St(s);return t.setDate(1),t.setHours(0,0,0,0),t}function Wf(s){wt(1,arguments);var t=St(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function xo(s){wt(1,arguments);var t=St(s);return t.setHours(0,0,0,0),t}function _o(s,t){wt(2,arguments);var e=xo(s),n=xo(t);return e.getTime()===n.getTime()}const Vf=s=>{switch(s.key){case"lessThanSecond":return $f(s);case"month":return Kf(s);case"second":case"minute":case"hour":case"day":case"year":return qf(s);case"week-weekday":return Jf(s);default:return()=>!1}},$t=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},nn=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n!==i},Uf=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n>=i},Gf={1:Rf,2:Ff,3:Hf,4:kf,5:jf,6:Yf,7:Nf},Zf=(s,t,e)=>{var n;const i=Xf({start:zf(s),end:Wf(s)}),r=(n=Gf[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return _o(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return _o(s,a);o++}}return!1},Po=(s,t)=>t===1?s===1:s/t===1,To=(s,t)=>t===1?!0:s%t===0,$f=s=>(t,e)=>Uf(s.key)(t,e),Kf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?Po($t(t,s.key)+1,s.value):To($t(t,s.key)+1,s.value);return n&&i},qf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?Po($t(t,s.key),s.value):To($t(t,s.key),s.value);return n&&i},Jf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=Zf(t,s.week,s.weekday);return n&&i},Qf=s=>{switch(s.key){case"second":case"minute":return tg(s.value);case"hour":return eg(s.value);case"day":return sg(s.value);case"month":return rg(s.value);case"year":return og(s.value);case"week-weekday":const t=ig(s.week),e=ng(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},tg=s=>s>0&&s<=60,eg=s=>s>0&&s<=24,sg=s=>s>0&&s<=31,ng=s=>Mo(s)?s>=1&&s<=7:!1,ig=s=>s==="$"?!0:Mo(s)?s>=1&&s<=6:!1,rg=s=>s>0&&s<=12,og=s=>s>0,Mo=s=>!isNaN(s)&&isFinite(s),ag=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function rn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:ag(a,i,t)};n[r]=l,i=a}return n}const Ao=s=>{const t={},e={};return js(s).forEach(([n,i])=>{const r=yo(n),o=r===null?!1:Qf(r);if(r&&o){const a=wo(r);t[a]=i,e[a]=Vf(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Eo{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?ft(d,h.animationConfig.targetZoomX):ft(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,p=Object.values(this.formatsByWeightMap).reduce((P,_)=>Math.max(_.length,P),1),v=f*p;return Math.round(v/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Ao(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>Vi(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}mapWeightedPointsToLabels(t,e){var n;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=Ao(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(t=[]){const e=this.getAllCandlesWithFake(t),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e);this.labelsGroupedByWeight=So(i),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=rn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=So(i),o=ee(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const p=f.map(v=>(v.idx=v.idx+t.length,v.value=a.startUnit+a.width+v.value,v));r[u]?c[h]=d.concat(p):c[h]=p}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t){this.generateWeightedLabels(t)}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const n=Of(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Bf(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=yo(o);if(l){const c=wo(l);i[c]=a}}return i},{});return js(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class lg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(ts,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const Io=3;class cg extends X{constructor(t,e,n,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,p=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(p,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(Io-1)):u=1+h/this.lastXPxWidth*(Io-1);const p=(this.lastXWidth*u-this.lastXWidth)/2,v=this.lastXStart-p,P=this.lastXEnd+p;(this.lastXStart!==v||this.lastXEnd!==P)&&this.scale.setXScale(v,P)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Le(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class hg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=P=>this.xAxisScaleHandler.setDblClickCallback(P),this.setDblTapCallback=P=>this.xAxisScaleHandler.setDblTapCallback(P);const p=new Eo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=p,this.xAxisLabelsModel=new lg(t,[]);const v=new Us;c.addDrawer(v,"X_AXIS"),this.xAxisDrawer=new cs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),v.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new Mf(e,n,o,this.xAxisLabelsModel),v.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new cg(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(x.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(J(({prependedCandles:t})=>t.length!==0),ht(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;ul.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(vt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ht(()=>yt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),At((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),J(Wn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Eo?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 dg=Object.defineProperty,Do=Object.getOwnPropertySymbols,ug=Object.prototype.hasOwnProperty,fg=Object.prototype.propertyIsEnumerable,Lo=(s,t,e)=>t in s?dg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,hs=(s,t)=>{for(var e in t||(t={}))ug.call(t,e)&&Lo(s,e,t[e]);if(Do)for(var e of Do(t))fg.call(t,e)&&Lo(s,e,t[e]);return s};class gg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&hs(hs({},n),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&hs(hs({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=yt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:Jt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:ku(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,h,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,r,o),rounded:!0}}}class pg{constructor(t,e,n,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=n,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,n=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(x.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>Fr(t,n,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>Fr(t,n,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(q));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];cr(e,{x:h.x,y:vi(d,h)},{x:h.x+h.width-6,y:vi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class mg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=Qt(e.state),a=jt(o,r),l=this.getLabelTextColor();r.save(),Gt(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&vg(t,n,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const vg=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class bg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Za.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new R,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(ts,t)}}class Cg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ht(r=>i.components.chart.highlightActiveCandle?r:void 0),At()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class yg{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${bt()}`,this.canvasResized=new R,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){be(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(zs,e),this.bus.fire(ts))}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.previousBCR!==void 0}}var wg=Array.isArray,Sg=Object.getPrototypeOf,xg=Object.prototype,_g=Object.keys;function Pg(s){if(s.length===1){var t=s[0];if(wg(t))return{args:t,keys:null};if(Tg(t)){var e=_g(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Tg(s){return s&&typeof s=="object"&&Sg(s)===xg}var Mg=Array.isArray;function Ag(s,t){return Mg(t)?s.apply(void 0,I([],m(t))):s(t)}function Eg(s){return ht(function(t){return Ag(s,t)})}function Ig(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Dg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=ga(s),i=Pg(s),r=i.args,o=i.keys;if(r.length===0)return Ye([],e);var a=new pt(Lg(r,e,o?function(l){return Ig(o,l)}:le));return n?a.pipe(Eg(n)):a}function Lg(s,t,e){return e===void 0&&(e=le),function(n){Oo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){Oo(t,function(){var d=Ye(s[h],t),u=!1;d.subscribe(mt(n,function(f){r[h]=f,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function Oo(s,t,e){s?Ht(e,s,t):t()}class Og extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Dg([n,i]).pipe(J(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!kt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Bg(s,t){return N(function(e,n){var i=null,r=0,o=!1,a=function(){return o&&!i&&n.complete()};e.subscribe(mt(n,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(s(l,h)).subscribe(i=mt(n,function(d){return n.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Rg{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Fg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Rg(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Hg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof xr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var kg=Object.defineProperty,jg=Object.defineProperties,Yg=Object.getOwnPropertyDescriptors,Bo=Object.getOwnPropertySymbols,Ng=Object.prototype.hasOwnProperty,Xg=Object.prototype.propertyIsEnumerable,Ro=(s,t,e)=>t in s?kg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Oe=(s,t)=>{for(var e in t||(t={}))Ng.call(t,e)&&Ro(s,e,t[e]);if(Bo)for(var e of Bo(t))Xg.call(t,e)&&Ro(s,e,t[e]);return s},on=(s,t)=>jg(s,Yg(t));class zg extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new Fg(this.chartModel),u=new Hg(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Bg(()=>this.scale.initialViewportValidSubject.pipe(J(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(vt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((n=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:n.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var n,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!Qr(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(n=this.crossEventProducer.crossToolHover)==null?void 0:n.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(x.PANE_UUID(d)),f=u.y+5,p=u.y+u.height-5,v=c-l.x,P=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=v,D=a.y<f?f:a.y>p?p:a.y+=P;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:D}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=kr(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,q)}createHover(t,e,n){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>on(Oe({},l),{[c[0]]:c[1].getData(o)}),{});return Oe(Oe({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=on(Oe({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e,n;if(t){if(kt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(n=t.candleHover)==null?void 0:n.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=on(Oe({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const Fo={left:0,middle:1,right:2};function gt(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function pe(s){return t=>{t.button===Fo.left&&s(t)}}var Wg=Object.defineProperty,Ho=Object.getOwnPropertySymbols,Vg=Object.prototype.hasOwnProperty,Ug=Object.prototype.propertyIsEnumerable,ko=(s,t,e)=>t in s?Wg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gg=(s,t)=>{for(var e in t||(t={}))Vg.call(t,e)&&ko(s,e,t[e]);if(Ho)for(var e of Ho(t))Ug.call(t,e)&&ko(s,e,t[e]);return s};const oe=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new R,this.xDragSubject=new R,this.xDragTickSubject=new R,this.xDragEndSubject=new R,this.yDragStartSubject=new R,this.yDragSubject=new R,this.yDragTickSubject=new R,this.yDragEndSubject=new R,this.mouseMoveSubject=new R,this.mouseMoveDocumentSubject=new R,this.clickSubject=new R,this.clickDocumentSubject=new R,this.dbClickSubject=new R,this.dbTapSubject=new R,this.mouseDownSubject=new R,this.mouseUpSubject=new R,this.mouseUpDocumentSubject=new R,this.wheelSubject=new R,this.touchStartSubject=new R,this.touchStartTimestamp=0,this.touchMoveSubject=new R,this.touchEndSubject=new R,this.touchCancelSubject=new R,this.longTouchStartSubject=new R,this.longTouchEndSubject=new R,this.contextMenuSubject=new R,this.fastTouchScroll=new R,this.mouseLeavesCanvasSubject=new R,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=oe.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Gg({},this.dragStartPoint),oe.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===Fo.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],oe.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),oe.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),oe.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,pe(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,pe(e=>this.clickDocumentSubject.next(e)),"click"));const s=qr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(gt(this.element,n,"touchend"));const i=(o,a=200)=>{o.preventDefault();let l=!1,c=null;c=setTimeout(()=>{l=!0,this.longTouchStartSubject.next(o)},a);const h=u=>{u.preventDefault(),u.touches.length>1&&c&&clearTimeout(c)},d=u=>{u.preventDefault(),c&&clearTimeout(c),l&&(l=!1,this.longTouchEndSubject.next(u)),this.element.removeEventListener("touchend",d),this.element.removeEventListener("touchmove",h)};this.element.addEventListener("touchmove",h),this.element.addEventListener("touchend",d)};this.addSubscription(gt(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,f=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,p=d<=250;f&&p&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,pe(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(gt(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(gt(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(gt(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(gt(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(gt(this.element,e=>{this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(gt(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(gt(this.element,pe(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,pe(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,pe(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(zs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){oe.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(J(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ht(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(J(()=>!(t&&this.dragging)),ht(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ht(()=>!1));return vt(e,n).pipe(At())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)),co(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let ds=oe;ds.DRAG_START_EVENTS=["mousedown","touchstart"],ds.DRAG_EVENTS=["mousemove","touchmove"],ds.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var Zg=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Fs);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t}(R);const an={};function $g(s){return an[s]||(an[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),an[s]}const jo=(s,t=Date.now())=>{const n=$g(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},Yo=60*1e3;class Kg{constructor(t){this.config=t,this.timeZoneChangedSubject=new Zg,this.currentTzOffset=e=>jo(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Yo,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Id(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+jo(t,e)+new Date(e).getTimezoneOffset()*Yo):e=>new Date(e)}}class qg extends X{constructor(t,e,n){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=n}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(At((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class ln{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;fl(r),this.config=r;const o=Bl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new Kg(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Rl(t);this.elements=c;const h=new bg;this.bus=h;const d=new yg(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 Ah(h,d);this.drawingManager=u;const f=Th(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=re(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const p=new fe(this.dynamicObjectsCanvasModel);u.addDrawer(p,"SERIES_CLEAR");const v=re(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),P=re(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Rs(r,h,f,l,d);this.canvasBoundsContainer=_;const D=c.mainCanvas.parentElement;if(D===null)throw new Error("Couldn't get main canvas parent");const O=new ds(h,D);this.canvasInputListener=O,this.chartComponents.push(this.canvasInputListener);const j=new Wd(h,c.hitTestCanvas,O,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=j;const H=new fe(j);u.addDrawer(H,"HIT_TEST_CLEAR");const B=new Ya(h);this.canvasAnimation=B;const Y=x.PANE_UUID(q),W=new ar(r,()=>_.getBounds(Y),B);this.scaleModel=W;const G=re(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=G,this.cursorHandler=new Dl(c.canvasArea,O,_,j),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Og(O,_),this.chartComponents.push(this.crossEventProducer);const V=new gc("candle");this.chartBaseModel=V;const U=new Mu(h,W,_,r,B,O,D,V,j);this.chartPanComponent=U,this.chartComponents.push(U),this.userInputListenerComponents.push(U.chartAreaPanHandler);const Z=new qg(j,B,h);this.hitTestComponent=Z,this.chartComponents.push(Z);const $=new cf(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,B,O,u,this.cursorHandler,this.crossEventProducer,U,f,v,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=$;const et=this.paneManager.panes[q];this.mainPane=et,this.chartComponents.push($),this.dynamicObjects=new Ad(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new od(V,$,h,this.dynamicObjectsCanvasModel,r,W,l,D,_,d);const tt=new zh(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,j,O,G,U,$,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),j.addSubscriber($.hitTestController),this.xAxisComponent=new hg(h,r,f,tt,W,_,O,d,this.drawingManager,a,U,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const rt=new fe(f);u.addDrawer(rt,"MAIN_CLEAR");const lt=new Cg(D,Q,O,r);this.chartComponents.push(lt),this.watermarkComponent=new Pf($,Q,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=re(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new cu(h,r,Q,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new bu(h,Q,f,r,O,_,u,l,U,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const xt=new su(r,this.dynamicObjectsCanvasModel,Q,_,u);this.chartComponents.push(xt),this.initYAxisDrawer(v,P),this.yAxisComponent=et.mainExtent.yAxis;const Vt=new gg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(Vt,te.MAIN),this.volumesComponent=new Cf(this.dynamicObjectsCanvasModel,tt,W,_,u,r,$,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const me=new Vr(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(Y),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,()=>r.components.grid.visible);this.chartComponents.push(me),this.hoverProducer=new zg(this.crossEventProducer,W,r,Q,O,this.canvasBoundsContainer,this.paneManager,a,U.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new _d(r,ot,_,u,$,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel),this.chartComponents.push(this.crossToolComponent);const Vo=re(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),cn=new hf(this.elements,Vo);this.snapshotComponent=cn,this.chartComponents.push(cn);const hn=new Qd(r,this.dynamicObjectsCanvasModel,j,Q,_,u,l,this.cursorHandler);this.eventsComponent=hn,this.chartComponents.push(hn),this.chartComponents.forEach(dn=>dn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Xa(this.components)}initYAxisDrawer(t,e){const n=new Us,i=new fe(t),r=new fe(e);n.addDrawer(i,"YAXIS_CLEAR"),n.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(n,"Y_AXIS");const o=new mg(this.config,t,this.paneManager);n.addDrawer(o);const a=new pg(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&ln.mergeConfig(t[n],e[n]):t[n]=e[n];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Tt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=vt(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class No extends ln{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var n;(n=this.paneManager.panes[t])==null||n.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}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 Jg=Object.defineProperty,Qg=Object.defineProperties,tp=Object.getOwnPropertyDescriptors,Xo=Object.getOwnPropertySymbols,ep=Object.prototype.hasOwnProperty,sp=Object.prototype.propertyIsEnumerable,zo=(s,t,e)=>t in s?Jg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,np=(s,t)=>{for(var e in t||(t={}))ep.call(t,e)&&zo(s,e,t[e]);if(Xo)for(var e of Xo(t))sp.call(t,e)&&zo(s,e,t[e]);return s},ip=(s,t)=>Qg(s,tp(t));function Wo(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=us(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ap(t[t.length-1],a,n)):d>3?t=t.concat(rp(t[t.length-1],a,r)):t=t.concat(op(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let f=0;f<t.length;f++){const p=t[f];Object.assign(p,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(p.volume=Math.ceil(Math.random()*1e3+200))}return t}function us(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:ei(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function rp(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=us(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),n.push(c)}return n}function op(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=us(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),n.push(c)}return n}function ap(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var f,p;return Math.random()>.5?(f=u.lo-t*.2,p=u.hi+t*1.2):(f=u.lo-t*1.2,p=u.hi+t*.2),{from:f,to:p}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=us(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),n.push(d)}return n}window.DXChart=ip(np({},window.DXChart),{generateCandlesData:Wo});function lp(s){return Wo(s)}const cp=(s,t={})=>new No(s,t)})(),window.DXChart=fs})();})();
|