@tradecanvas/core 1.0.3 → 1.1.0

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/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@tradecanvas/commons`);var t=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.remove()}},n=class{layers=new Map;constructor(e){this.container=e}createLayers(){this.destroy();for(let n of[e.LayerType.Background,e.LayerType.Main,e.LayerType.Overlay,e.LayerType.UI])this.layers.set(n,new t(this.container,n))}getLayer(e){return this.layers.get(e)}resize(e,t){for(let n of this.layers.values())n.resize(e,t)}destroy(){for(let e of this.layers.values())e.destroy();this.layers.clear()}},r=class{animFrameId=0;running=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(e.LayerType.Background),this.dirtyLayers.add(e.LayerType.Main),this.dirtyLayers.add(e.LayerType.Overlay),this.dirtyLayers.add(e.LayerType.UI),this.running&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},i=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;constructor(e){this.container=e,this.currentDpr=window.devicePixelRatio||1,this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.currentDpr=window.devicePixelRatio||1;let e=this.container.clientWidth,t=this.container.clientHeight;e===this.cachedSize.width&&t===this.cachedSize.height||(this.cachedSize={width:e,height:t},this.callback?.(this.cachedSize,this.currentDpr))}))}),this.observer.observe(this.container)}destroy(){this.observer?.disconnect(),this.observer=null,this.callback=null}};function a(e,t){return e*(t.barWidth+t.barSpacing)-t.offset+t.chartRect.x+t.barWidth/2}function o(e,t){let{min:n,max:r}=t.priceRange;if(t.logScale&&n>0&&r>0){let i=Math.log(n),a=Math.log(r)-i;if(a===0)return t.chartRect.y+t.chartRect.height/2;let o=(Math.log(Math.max(e,2**-52))-i)/a;return t.chartRect.y+t.chartRect.height*(1-o)}let i=r-n;if(i===0)return t.chartRect.y+t.chartRect.height/2;let a=(e-n)/i;return t.chartRect.y+t.chartRect.height*(1-a)}function s(e,t){let n=t.barWidth+t.barSpacing;return Math.round((e-t.chartRect.x-t.barWidth/2+t.offset)/n)}function c(e,t){let{min:n,max:r}=t.priceRange,i=1-(e-t.chartRect.y)/t.chartRect.height;if(t.logScale&&n>0&&r>0){let e=Math.log(n);return Math.exp(e+(Math.log(r)-e)*i)}return n+(r-n)*i}function l(e,t){if(t.length===0)return-1;if(e<=t[0].time)return 0;if(e>=t[t.length-1].time)return t.length-1;let n=0,r=t.length-1;for(;n<=r;){let i=n+r>>>1;if(t[i].time===e)return i;t[i].time<e?n=i+1:r=i-1}if(n>=t.length)return t.length-1;if(r<0)return 0;let i=t[r].time,a=t[n].time,o=a===i?0:(e-i)/(a-i);return r+o}function u(e,t){let n=t.data;return n&&n.length>0?l(e,n):e}function d(e,t){return a(u(e,t),t)}function f(e,t){let n=s(e,t),r=t.data;return r&&r.length>0?r[Math.max(0,Math.min(r.length-1,n))].time:n}var p=class{layerManager;renderLoop;dprManager;renderCtx=null;bgLayer;mainLayer;overlayLayer;uiLayer;onContainerResize=null;constructor(e){this.layerManager=new n(e),this.renderLoop=new r,this.dprManager=new i(e),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let t=this.dprManager.getContainerSize(),a=this.dprManager.getDpr();this.layerManager.resize(t,a)}cacheLayerRefs(){this.bgLayer=this.layerManager.getLayer(e.LayerType.Background),this.mainLayer=this.layerManager.getLayer(e.LayerType.Main),this.overlayLayer=this.layerManager.getLayer(e.LayerType.Overlay),this.uiLayer=this.layerManager.getLayer(e.LayerType.UI)}setRenderContext(e){this.renderCtx=e}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(t){let n=this.renderCtx;if(!n)return;let{viewport:r,theme:i,data:l}=n,u=n.numberLocale??`en-US`;if(!(r.chartRect.width<=0||r.chartRect.height<=0)){if(t.has(e.LayerType.Background)&&this.bgLayer&&(this.bgLayer.clear(),n.gridRenderer?.render(this.bgLayer.ctx,r,i),n.sessionShading?.render(this.bgLayer.ctx,l,r,i),n.sessionBreaks?.render(this.bgLayer.ctx,r,i,l),n.watermark?.render(this.bgLayer.ctx,r,i)),t.has(e.LayerType.Main)&&this.mainLayer){this.mainLayer.clear();let e=this.mainLayer.ctx;e.save(),e.beginPath(),e.rect(r.chartRect.x,r.chartRect.y,r.chartRect.width,r.chartRect.height),e.clip(),n.depthHeatmap?.render(e,r,i),n.volumeRenderer?.render(e,l,r,i),n.volumeProfile?.render(e,l,r,i),n.marketProfile?.render(e,l,r,i),n.chartRenderer?.render(e,l,r,i),n.compareRenderer?.render(e,l,r,i),n.indicatorEngine?.renderOverlays(e,r),n.periodLevels?.render(e,l,r,i),n.pivotMarkers?.render(e,l,r,i),n.renderOverlayPlugins?.(e,`main`),e.restore();let t=n.panels,a=n.indicatorEngine;if(a&&t.length>0){let n=`10px ${i.font.family}`,r=a.getPanelIndicators(),o=new Map;for(let e of r)o.set(e.instanceId,e);for(let r of t){if(r.rect.width<=0||r.rect.height<=0)continue;e.save(),e.beginPath(),e.rect(r.rect.x,r.rect.y,r.rect.width,r.rect.height),e.clip(),e.fillStyle=i.background,e.fillRect(r.rect.x,r.rect.y,r.rect.width,r.rect.height),e.fillStyle=i.axisLine,e.fillRect(r.rect.x,r.rect.y,r.rect.width,3),e.fillStyle=i.textSecondary,e.font=n,e.textBaseline=`top`,e.textAlign=`left`;let t=o.get(r.instanceId);t&&e.fillText(t.descriptor.name,r.rect.x+6,r.rect.y+6),e.save(),e.beginPath(),e.rect(r.rect.x,r.rect.y+20,r.rect.width,r.rect.height-20),e.clip(),a.renderPanel(e,r.instanceId,r.viewport),e.restore(),e.restore()}}}if(t.has(e.LayerType.Overlay)&&this.overlayLayer){this.overlayLayer.clear();let e=this.overlayLayer.ctx;n.priceLimits&&this.renderPriceLimits(e,r,i,n.priceLimits),n.tradeZoneManager?.render(e,r,i),n.drawingRenderer?.render(e,r),n.tradingRenderer?.render(e,r,i),n.signalMarkerManager?.render(e,r,i),n.alertManager?.render(e,r,i),n.measureOverlay?.render(e,r,i),n.crosshairHandler?.render(e,r,i),n.renderOverlayPlugins?.(e,`overlay`);let t=n.crosshairHandler?.getPosition();if(t&&n.panels.length>0)for(let r of n.panels){let o=r.rect;if(t.x>=o.x&&t.x<=o.x+o.width&&t.y>=o.y&&t.y<=o.y+o.height){let c=r.viewport,l=t.x,u=s(l,c);l=a(Math.max(0,Math.min((n.data?.length??1)-1,Math.round(u))),c),e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),e.setLineDash([4,4]),e.strokeStyle=i.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(l)+.5,o.y),e.lineTo(Math.round(l)+.5,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(o.x,Math.round(t.y)+.5),e.lineTo(o.x+o.width,Math.round(t.y)+.5),e.stroke(),e.setLineDash([]),e.restore();break}}}if(t.has(e.LayerType.UI)&&this.uiLayer){this.uiLayer.clear();let t=this.uiLayer.ctx;if(n.priceAxis?.render(t,r,i),n.tradingRenderer?.renderAxisBadges(t,r,i),n.currentPriceLine?.render(t,r,i),n.timeAxis?.render(t,r,i,l,n.timeAxisY),n.crosshairHandler?.renderAxisLabels(t,r,i,l,n.timeAxisY),n.chartLegend?.render(t,r,i,l),n.barCountdown?.render(t,r,i,l),n.renderOverlayPlugins?.(t,`ui`),n.panels.length>0){let r=n.crosshairHandler?.getPosition(),a=n.indicatorEngine,d=`${i.font.sizeSmall}px ${i.font.family}`,f;if(a){let e=a.getPanelIndicators();f=new Map;for(let t of e)f.set(t.instanceId,t)}for(let p of n.panels){let n=p.viewport,m=p.rect,{min:h,max:g}=n.priceRange;if(g-h<=0||m.height<=0)continue;let _=m.x+m.width,v=n.chartRect;t.strokeStyle=i.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(_+.5,m.y),t.lineTo(_+.5,m.y+m.height),t.stroke();let y=(0,e.computeTickStep)(h,g,4),b=Math.ceil(h/y)*y,x=y<1?Math.ceil(-Math.log10(y))+1:+(y<10);t.font=d,t.textBaseline=`middle`,t.textAlign=`left`;for(let r=b;r<=g;r+=y){let a=o(r,n);a<v.y||a>v.y+v.height||(t.strokeStyle=i.axisLine,t.beginPath(),t.moveTo(_,Math.round(a)+.5),t.lineTo(_+4,Math.round(a)+.5),t.stroke(),t.fillStyle=i.axisLabel,t.fillText((0,e.formatPrice)(r,x,u),_+6,a))}if(r&&r.x>=m.x&&r.x<=m.x+m.width&&r.y>=m.y&&r.y<=m.y+m.height){let a=(0,e.formatPrice)(c(r.y,n),x,u);t.font=`bold ${i.font.sizeSmall}px ${i.font.family}`;let o=t.measureText(a).width,s=Math.min(o+10,e.PRICE_AXIS_WIDTH-2);t.fillStyle=i.crosshair,t.fillRect(_+1,r.y-9,s,18),t.fillStyle=i.background,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(a,_+5,r.y)}if(r&&a){let e=s(r.x,n),o=Math.max(0,Math.min((l?.length??1)-1,Math.round(e))),c=a.getOutput(p.instanceId);if(c?.series&&o<c.series.length){let e=c.series[o];if(e){let n=[];for(let t in e){let r=e[t];r!==void 0&&n.push(`${t}: ${r.toFixed(x)}`)}if(n.length>0){let e=f?.get(p.instanceId),r=e?t.measureText(e.descriptor.name).width+14:10;t.font=d,t.fillStyle=i.textSecondary,t.textBaseline=`top`,t.textAlign=`left`,t.fillText(n.join(` `),m.x+r,m.y+6)}}}}}}}}}renderPriceLimits(t,n,r,i){let{chartRect:a}=n,s=[{price:i.ceiling,color:i.colors?.ceiling??`#FF00FF`,label:`CE`},{price:i.floor,color:i.colors?.floor??`#00FFFF`,label:`FL`},{price:i.reference,color:i.colors?.reference??`#FFD700`,label:`REF`}],c=`bold 9px ${r.font.family}`,l=`10px ${r.font.family}`;for(let{price:r,color:i,label:u}of s){let s=o(r,n);if(s<a.y||s>a.y+a.height)continue;t.setLineDash([8,4]),t.strokeStyle=i,t.lineWidth=1,t.beginPath(),t.moveTo(a.x,Math.round(s)+.5),t.lineTo(a.x+a.width,Math.round(s)+.5),t.stroke(),t.setLineDash([]),t.font=c,t.fillStyle=i,t.textBaseline=`bottom`,t.textAlign=`left`,t.fillText(`${u} ${r.toFixed(2)}`,a.x+4,s-2);let d=a.x+a.width+1;t.fillStyle=i,t.fillRect(d,s-7,e.PRICE_AXIS_WIDTH-2,14),t.fillStyle=`#000`,t.font=l,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(r.toFixed(2),d+4,s)}}destroy(){this.renderLoop.stop(),this.dprManager.destroy(),this.layerManager.destroy()}},m=class{state;dataLength=0;minBarWidth;maxBarWidth;rightMarginBars;constructor(t,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(t,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:e.DEFAULT_BAR_WIDTH,barSpacing:e.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return{visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline}}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setScaleBaseline(e){this.state.scaleBaseline=e}setRightMargin(e){this.rightMarginBars=e}computeChartRect(t,n){return{x:0,y:0,width:Math.max(0,t-e.PRICE_AXIS_WIDTH),height:Math.max(0,n-e.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.clampOffset(),this.updateVisibleRange()}updateData(t,n){this.dataLength=t.length,this.dataLength!==0&&(this.clampOffset(),this.updateVisibleRange(),n&&(this.state.priceRange=(0,e.computePriceRange)(t,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),.08)))}setPriceRange(e,t){this.state.priceRange={min:e,max:t}}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a}}scrollBy(e){this.state.offset+=e,this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=e/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)};return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a}}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing,t=this.rightMarginBars*e,n=this.dataLength*e-this.state.chartRect.width+t;return this.state.offset>=n-e*2}scrollToEnd(){let e=this.state.barWidth+this.state.barSpacing,t=this.rightMarginBars*e,n=this.dataLength*e;this.state.offset=n-this.state.chartRect.width+t,this.updateVisibleRange()}zoom(t,n){let r=this.state.barWidth,i=(0,e.clamp)(r*(1+t),this.minBarWidth,this.maxBarWidth);if(i===r)return;let a=this.state.barWidth+this.state.barSpacing,o=(this.state.offset+n)/a;this.state.barWidth=i;let s=i+this.state.barSpacing;this.state.offset=o*s-n,this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let t=this.state.barWidth+this.state.barSpacing,n=this.dataLength*t,r=this.rightMarginBars*t,i=n-this.state.chartRect.width+r,a,o;if(i>0)a=-(this.state.chartRect.width*.5),o=i;else{let e=this.state.chartRect.width*.5;a=i-e,o=i+e}this.state.offset=(0,e.clamp)(this.state.offset,a,o)}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)}}};function h(t,n){return(0,e.sliceVisibleData)(t,n.visibleRange.from,n.visibleRange.to)}var g=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=g(n.high),a=g(n.low),c=g(n.open),l=g(n.close),u=n.close>=n.open,d=u?_:v;d.moveTo(r,i),d.lineTo(r,a);let f=u?l:c,p=Math.max(Math.abs(l-c),1);(u?y:b).rect(r-s,f,o,p)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(_),e.strokeStyle=r.candleDownWick,e.stroke(v),e.fillStyle=r.candleUp,e.fill(y),e.fillStyle=r.candleDown,e.fill(b)}};function _(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var v=64;function y(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(v,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=_(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var b=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,s=-n.offset+n.chartRect.x+n.barWidth/2,{min:c,max:l}=n.priceRange,u=l-c;if(u===0)return;let d=n.chartRect.y,f=n.chartRect.height/u;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let p=y(i,a,t.length,n.chartRect.width,e=>t[e].close),m=!1;for(let n of p){let r=n*o+s,i=d+(l-t[n].close)*f;m?e.lineTo(r,i):(e.moveTo(r,i),m=!0)}e.stroke()}},x=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,s=-n.offset+n.chartRect.x+n.barWidth/2,{min:c,max:l}=n.priceRange,u=l-c;if(u===0)return;let d=n.chartRect.y,f=n.chartRect.height,p=f/u,m=d+f,h=y(i,a,t.length,n.chartRect.width,e=>t[e].close);if(h.length===0)return;let g=h[0],_=g*o+s,v=d+(l-t[g].close)*p,b=e.createLinearGradient(0,d,0,m);b.addColorStop(0,r.areaTopColor),b.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(_,m),e.lineTo(_,v);let x=_;for(let n=1;n<h.length;n++){let r=h[n];x=r*o+s,e.lineTo(x,d+(l-t[r].close)*p)}e.lineTo(x,m),e.closePath(),e.fillStyle=b,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`,e.moveTo(_,v);for(let n=1;n<h.length;n++){let r=h[n];e.lineTo(r*o+s,d+(l-t[r].close)*p)}e.stroke()}},S=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open?_:v,a=g(n.high),o=g(n.low),c=g(n.open),l=g(n.close);i.moveTo(r,a),i.lineTo(r,o),i.moveTo(r-s,c),i.lineTo(r,c),i.moveTo(r,l),i.lineTo(r+s,l)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v)}},C=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=[],b=[],x=new Path2D,S=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=e===0||n.close>=t[e-1].close,c=g(n.high),l=g(n.low),u=g(n.open),d=g(n.close),f=Math.min(u,d),p=Math.max(Math.abs(d-u),1),m=a?_:v;m.moveTo(r,c),m.lineTo(r,l),i?(a?y:b).push({x:r-s,y:f,w:o,h:p}):(a?x:S).rect(r-s,f,o,p)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v),e.fillStyle=r.candleUp,e.fill(x),e.fillStyle=r.candleDown,e.fill(S),e.lineWidth=1.5,e.strokeStyle=r.candleUp;for(let t of y)e.strokeRect(t.x,t.y,t.w,t.h);e.strokeStyle=r.candleDown;for(let t of b)e.strokeRect(t.x,t.y,t.w,t.h)}},w=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=g(this.baselinePrice??this.computeBaseline(t,i,a)),{chartRect:v}=n,y=[],b=[];for(let e=i;e<=a&&e<t.length;e++)y.push(h(e)),b.push(g(t[e].close));if(y.length<2)return;let x=y.length-1;e.save();let S=new Path2D;S.rect(v.x,v.y,v.width,_-v.y),e.clip(S);let C=new Path2D;C.moveTo(y[0],_);for(let e=0;e<=x;e++)C.lineTo(y[e],b[e]);C.lineTo(y[x],_),C.closePath(),e.fillStyle=`${r.candleUp}20`,e.fill(C),e.restore(),e.save();let w=new Path2D;w.rect(v.x,_,v.width,v.y+v.height-_),e.clip(w);let T=new Path2D;T.moveTo(y[0],_);for(let e=0;e<=x;e++)T.lineTo(y[e],b[e]);T.lineTo(y[x],_),T.closePath(),e.fillStyle=`${r.candleDown}20`,e.fill(T),e.restore();let E=new Path2D,D=new Path2D;for(let e=1;e<=x;e++){let t=b[e]<=_?E:D;t.moveTo(y[e-1],b[e-1]),t.lineTo(y[e],b[e])}e.lineWidth=2,e.strokeStyle=r.candleUp,e.stroke(E),e.strokeStyle=r.candleDown,e.stroke(D),e.setLineDash([6,4]),e.strokeStyle=r.textSecondary,e.lineWidth=1;let O=new Path2D;O.moveTo(v.x,_),O.lineTo(v.x+v.width,_),e.stroke(O),e.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},T=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=g(Math.max(n.open,n.close)),c=g(Math.min(n.open,n.close)),l=Math.max(c-a,1),u=r-s;i?(_.rect(u,a,o,l),y.rect(u,a,o,l)):(v.rect(u,a,o,l),b.rect(u,a,o,l))}e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v),e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},E=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,o=g(n.high),s=g(n.low),c=i?_:v;if(c.moveTo(r,o),c.lineTo(r,s),e<a&&e+1<t.length){let t=h(e+1),n=i?s:o;c.moveTo(r,n),c.lineTo(t,n)}}e.strokeStyle=r.candleUp,e.lineWidth=3,e.stroke(_),e.strokeStyle=r.candleDown,e.lineWidth=1,e.stroke(v)}},D=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=Math.abs(this.boxSize*m),v=Math.min(s*.8,_*.8)*.5,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=n.high,o=n.low,s=Math.max(1,Math.round((a-o)/this.boxSize));for(let e=0;e<s;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),y.moveTo(r+v,t-v),y.lineTo(r-v,t+v)):(b.moveTo(r+v,t),b.arc(r,t,v,0,Math.PI*2))}}e.lineWidth=1.5,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},O=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:s}=n.priceRange,c=s-o;if(c===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=n.barWidth,m=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>m&&(m=t[e].volume);m===0&&(m=1);let h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=e=>e*l+u,b=e=>d+(s-e)*f;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=y(e),i=b(n.high),a=b(n.low),o=b(n.open),s=b(n.close),c=n.close>=n.open,l=p*Math.max(.2,n.volume/m),u=l/2,d=c?h:g;d.moveTo(r,i),d.lineTo(r,a);let f=c?s:o,x=Math.max(Math.abs(s-o),1);(c?_:v).rect(r-u,f,l,x)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g),e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v)}},k=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:s}=n.priceRange,c=s-o;if(c===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=n.barWidth,m=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>m&&(m=t[e].volume);m===0&&(m=1);let h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=e=>e*l+u,b=e=>d+(s-e)*f;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e>0?t[e-1]:n,i=y(e),a=b(n.high),o=b(n.low),s=n.close>=r.close,c=p*Math.max(.15,n.volume/m),l=c/2,u=Math.max(o-a,1),d=s?h:g,f=s?_:v;d.rect(i-l,a,c,u),f.rect(i-l,a,c,u)}e.fillStyle=A(r.candleUp,.55),e.fill(h),e.fillStyle=A(r.candleDown,.55),e.fill(g),e.lineWidth=1,e.strokeStyle=r.candleUpWick,e.stroke(_),e.strokeStyle=r.candleDownWick,e.stroke(v)}};function A(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var ee=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f,h=[],g=[];for(let e=i;e<=a&&e<t.length;e++){let n=p(e);h.push({x:n,y:m(t[e].high)}),g.push({x:n,y:m(t[e].low)})}if(h.length===0)return;let _=e.createLinearGradient(0,d,0,d+n.chartRect.height);_.addColorStop(0,r.areaTopColor),_.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(h[0].x,h[0].y);for(let t=1;t<h.length;t++)e.lineTo(h[t].x,h[t].y);for(let t=g.length-1;t>=0;t--)e.lineTo(g[t].x,g[t].y);e.closePath(),e.fillStyle=_,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke()}},te=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`miter`;let h=0;for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);n===i?e.moveTo(r,a):(e.lineTo(r,h),e.lineTo(r,a)),h=a}e.stroke()}},ne=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let h=[];for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);h.push({x:r,y:a}),n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke();let g=Math.max(2,Math.min(4,n.barWidth*.3)),_=new Path2D;for(let{x:e,y:t}of h)_.moveTo(e+g,t),_.arc(e,t,g,0,Math.PI*2);e.fillStyle=r.lineColor,e.fill(_),e.strokeStyle=r.background,e.lineWidth=1,e.stroke(_)}},re=class{visible=!0;heightRatio=.2;setVisible(e){this.visible=e}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o}=n,s=n.barWidth,c=s/2,l=s+n.barSpacing,u=-n.offset+o.x+c,d=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>d&&(d=t[e].volume);if(d===0)return;let f=o.height*this.heightRatio,p=o.y+o.height,m=f/d,h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e*l+u,i=n.volume*m;(n.close>=n.open?h:g).rect(r-c,p-i,s,i)}e.globalAlpha=.35,e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.globalAlpha=1}},ie=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:s}=n,c=s.max-s.min;if(c<=0)return;let l=new Float64Array(this.buckets),u=new Float64Array(this.buckets),d=new Float64Array(this.buckets);for(let e=i;e<=a&&e<t.length;e++){let n=t[e];if(n.volume<=0)continue;let r=Math.max(n.low,s.min),i=Math.min(n.high,s.max);if(i<=r)continue;let a=(r-s.min)/c,o=(i-s.min)/c,f=Math.max(0,Math.floor(a*this.buckets)),p=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,p-f+1),h=n.volume/m,g=n.close>=n.open;for(let e=f;e<=p;e++)l[e]+=h,g?u[e]+=h:d[e]+=h}let f=0,p=-1;for(let e=0;e<l.length;e++)l[e]>f&&(f=l[e],p=e);if(f===0)return;let m=o.width*this.widthRatio,h=o.x+o.width,g=o.height/this.buckets,_=1/f;e.save(),e.globalAlpha=this.opacity;for(let t=0;t<this.buckets;t++){let n=l[t];if(n===0)continue;let i=o.y+o.height-(t+1)*g,a=n*_*m,s=u[t]*_*m,c=d[t]*_*m;s>0&&(e.fillStyle=r.candleUp,e.fillRect(h-s,i+.5,s,g-1)),c>0&&(e.fillStyle=r.candleDown,e.fillRect(h-a,i+.5,c,g-1)),this.highlightPoC&&t===p&&(e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(o.x,i+g/2+.5),e.lineTo(h-a-2,i+g/2+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=this.opacity)}e.restore()}};function ae(e,t){return e<0?0:e>t?t:e}function j(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=ae(Math.floor((e-t)/o),i-1),l=ae(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function oe(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function se(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function ce(t,n,r,i={}){if(t.length===0||r-n<=0)return[];let a=[],o=0,s=(0,e.timeframeBucketStart)(t[0].time,`1d`),c=(e,o,s)=>{let c=j(t.slice(e,o+1),n,r,i);c&&a.push({startIndex:e,endIndex:o,startTime:s,profile:c})};for(let n=1;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,`1d`);r!==s&&(c(o,n-1,s),o=n,s=r)}return c(o,t.length-1,s),a}var le=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}setLetters(e){this.letters=e}getStats(){return this.lastStats}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:s}=n,c=Math.max(0,i),l=Math.min(a,t.length-1);if(l<c)return;let u=t.slice(c,l+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(e,u,c,n,r);return}let d=j(u,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!d){this.lastStats=null;return}let f=d.buckets[d.pocIndex].mid;this.lastStats={poc:f,vah:d.valueAreaHigh,val:d.valueAreaLow,valueAreaPct:this.valueAreaPct};let p=d.buckets.length,m=o.width*this.widthRatio,h=o.x,g=o.height/p,_=1/d.maxCount;e.save();for(let t=0;t<p;t++){let n=d.buckets[t];if(n.count===0)continue;let i=o.y+o.height-(t+1)*g,a=n.count*_*m,s=n.mid>=d.valueAreaLow&&n.mid<=d.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?r.candleUp:r.textSecondary,e.fillRect(h,i+.5,a,g-1)}let v=e=>o.y+o.height*(1-(e-s.min)/(s.max-s.min));e.globalAlpha=.6,e.strokeStyle=r.candleUp,e.lineWidth=1,e.setLineDash([1,3]);for(let t of[d.valueAreaHigh,d.valueAreaLow]){let n=v(t);e.beginPath(),e.moveTo(h,Math.round(n)+.5),e.lineTo(o.x+o.width,Math.round(n)+.5),e.stroke()}if(e.setLineDash([]),this.highlightPoC){let t=v(f);e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(h,Math.round(t)+.5),e.lineTo(o.x+o.width,Math.round(t)+.5),e.stroke(),e.setLineDash([])}this.showStats&&this.drawStats(e,o.x+6,o.y+6,f,d.valueAreaHigh,d.valueAreaLow,r),e.restore()}renderSplit(e,t,n,r,i){let{chartRect:o,priceRange:s}=r,c=ce(t,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(c.length===0)return;let l=s.max-s.min,u=e=>o.y+o.height*(1-(e-s.min)/l),d=r.barWidth/2;e.save();for(let l of c){let c=l.profile,f=c.buckets.length,p=o.height/f,m=a(n+l.startIndex,r)-d,h=a(n+l.endIndex,r)+d,g=Math.max(2,h-m),_=1/c.maxCount,v=this.letters&&p>=7,y=v?se(t.slice(l.startIndex,l.endIndex+1),s.min,s.max,this.buckets):null;if(v&&y){e.font=`${Math.min(11,Math.floor(p))}px ui-monospace, monospace`,e.textBaseline=`middle`,e.textAlign=`left`;let t=Math.max(1,Math.floor(g/6));for(let n=0;n<f;n++){let r=y[n];if(r.length===0)continue;let a=o.y+o.height-(n+.5)*p,s=c.buckets[n].mid>=c.valueAreaLow&&c.buckets[n].mid<=c.valueAreaHigh;e.globalAlpha=s?.95:.6,e.fillStyle=s?i.candleUp:i.textSecondary;let l=Math.min(r.length,t);for(let t=0;t<l;t++)e.fillText(oe(r[t]),m+t*6,a)}}else for(let t=0;t<f;t++){let n=c.buckets[t];if(n.count===0)continue;let r=o.y+o.height-(t+1)*p,a=n.count*_*g,s=n.mid>=c.valueAreaLow&&n.mid<=c.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?i.candleUp:i.textSecondary,e.fillRect(m,r+.5,a,p-1)}if(this.highlightPoC){let t=u(c.buckets[c.pocIndex].mid);e.globalAlpha=1,e.strokeStyle=i.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(m,Math.round(t)+.5),e.lineTo(Math.min(h,o.x+o.width),Math.round(t)+.5),e.stroke(),e.setLineDash([])}}e.restore()}drawStats(e,t,n,r,i,a,o){let s=ue(r),c=[[`POC`,r.toFixed(s),o.crosshair],[`VAH`,i.toFixed(s),o.candleUp],[`VAL`,a.toFixed(s),o.candleUp]];e.globalAlpha=1,e.font=`600 10px ${o.font.family}`,e.textBaseline=`middle`;let l=0;for(let[,t]of c)l=Math.max(l,e.measureText(t).width);let u=38+l,d=6+c.length*14;e.fillStyle=o.background,e.globalAlpha=.82,de(e,t,n,u,d,4),e.fill(),e.globalAlpha=1,c.forEach(([r,i,a],s)=>{let c=n+6/2+14/2+s*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(r,t+6,c),e.fillStyle=o.text,e.textAlign=`right`,e.fillText(i,t+u-6,c)}),e.textAlign=`left`}};function ue(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function de(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function fe(t,n){let r=n===`day`?`1d`:`1w`,i=[];for(let n of t){let t=(0,e.timeframeBucketStart)(n.time,r),a=i[i.length-1];a&&a.key===t?(a.high=Math.max(a.high,n.high),a.low=Math.min(a.low,n.low),a.close=n.close):i.push({key:t,open:n.open,high:n.high,low:n.low,close:n.close})}return i}function pe(e,t=`day`){let n=fe(e,t);if(n.length<2)return[];let r=n[n.length-2],i=n[n.length-1],a=t===`day`?`D`:`W`;return[{id:`p${a}h`,label:`P${a}H`,price:r.high},{id:`p${a}c`,label:`P${a}C`,price:r.close},{id:`p${a}l`,label:`P${a}L`,price:r.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:i.open}]}var me=class{visible=!1;period=`day`;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=pe(t,this.period);if(i.length===0)return;let{chartRect:a}=n,s=a.y,c=a.y+a.height;e.save(),e.font=`600 10px ${r.font.family}`,e.textBaseline=`middle`;for(let t of i){let i=o(t.price,n);if(i<s||i>c)continue;let l=he(t,r);e.strokeStyle=l,e.globalAlpha=.7,e.lineWidth=1,e.setLineDash([5,4]),e.beginPath(),e.moveTo(a.x,Math.round(i)+.5),e.lineTo(a.x+a.width,Math.round(i)+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=1;let u=t.label,d=e.measureText(u).width,f=a.x+a.width-d-10;e.fillStyle=r.background,e.globalAlpha=.85,e.fillRect(f-4,i-7,d+8,14),e.globalAlpha=1,e.fillStyle=l,e.textAlign=`left`,e.fillText(u,f,i+.5)}e.restore()}};function he(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function ge(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function _e(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var ve=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=_e(t,this.left,this.right);if(i.length===0)return;let s=this.structureLabels?ge(i):i,{from:c,to:l}=n.visibleRange;e.save(),e.font=`10px ${r.font.family}`,e.textAlign=`center`;for(let t of s){if(t.index<c-1||t.index>l+1)continue;let i=a(t.index,n),s=o(t.price,n),u=t.type===`high`,d=u?r.candleDown:r.candleUp,f=u?s-8:s+8;e.fillStyle=d,e.beginPath(),u?(e.moveTo(i-5,f-5),e.lineTo(i+5,f-5),e.lineTo(i,f)):(e.moveTo(i-5,f+5),e.lineTo(i+5,f+5),e.lineTo(i,f)),e.closePath(),e.fill();let p=this.structureLabels&&`label`in t?String(t.label):this.showLabels?ye(t.price):null;p&&(e.textBaseline=u?`bottom`:`top`,e.fillText(p,i,u?f-5-1:f+5+1))}e.restore()}};function ye(e){let t=Math.abs(e);return t>=1e3||t>=1?e.toFixed(2):e.toPrecision(4)}var be=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e}))},r=this.buffer[this.buffer.length-1];r&&r.time===e?this.buffer[this.buffer.length-1]=n:(this.buffer.push(n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity)))}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},xe=class{buffer=new be(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(e,t,n){if(!this.visible)return;let r=this.buffer.snapshots();if(r.length===0)return;let i=this.buffer.maxVolume();if(i<=0)return;let a=1/i,{chartRect:o}=t,s=Math.max(2,t.barWidth+t.barSpacing),c=o.x,l=o.x+o.width,u=o.y,f=o.y+o.height;e.save();for(let i of r){let r=d(i.time,t);if(r<c-s||r>l+s)continue;let o=r-s/2;this.drawSide(e,i.bids,n.candleUp,o,s,t,a,u,f),this.drawSide(e,i.asks,n.candleDown,o,s,t,a,u,f)}e.restore()}drawSide(e,t,n,r,i,a,s,c,l){if(t.length===0)return;let u=Se(t,a);e.fillStyle=n;for(let n of t){let t=o(n.price,a);t<c-u||t>l+u||(e.globalAlpha=Math.min(1,Math.sqrt(n.volume*s))*this.opacity,e.fillRect(r,t-u/2,i,u))}e.globalAlpha=1}};function Se(e,t){if(e.length<2)return 3;let n=e.map(e=>e.price).sort((e,t)=>e-t),r=[];for(let e=1;e<n.length;e++){let t=n[e]-n[e-1];t>0&&r.push(t)}if(r.length===0)return 3;r.sort((e,t)=>e-t);let i=r[Math.floor(r.length/2)],a=Math.abs(o(n[0],t)-o(n[0]+i,t));return Math.max(2,Math.min(a,12))}var Ce=class{symbols=new Map;mode=`percent`;setMode(e){this.mode=e}addSymbol(e){this.symbols.set(e.id,e)}removeSymbol(e){this.symbols.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t)}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){this.symbols.clear()}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.symbols.values())!i.visible||i.data.length===0||this.renderSymbol(e,i,t,n,r);e.restore()}renderSymbol(e,t,n,r,i){let{chartRect:s}=r,c=r.barWidth+r.barSpacing,l=Math.max(0,Math.floor(r.offset/c));if(l>=n.length||l>=t.data.length)return;let u=n[l].close,d=t.data[l].close;if(u===0||d===0)return;e.strokeStyle=t.color,e.lineWidth=t.lineWidth??1.5,e.lineJoin=`round`,e.beginPath();let f=!1,p=Math.min(n.length,t.data.length);for(let n=l;n<p;n++){let i=a(n,r);if(i<s.x-c)continue;if(i>s.x+s.width+c)break;let l;l=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r):o(t.data[n].close,r),f?e.lineTo(i,l):(e.moveTo(i,l),f=!0)}if(e.stroke(),f){let n=Math.min(l+2,p-1),i=a(n,r)+4,s;s=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r)-4:o(t.data[n].close,r)-4,e.fillStyle=t.color,e.font=`bold 10px sans-serif`,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(t.label,i,s)}}};function we(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}function Te(e,t){if(e.length===0)return[];let n=t.brickSize;t.useATR&&e.length>(t.atrPeriod??14)&&(n=Ee(e,t.atrPeriod??14)),n<=0&&(n=1);let r=[],i=Math.round(e[0].close/n)*n,a=e[0].time;for(let t=1;t<e.length;t++){let o=e[t].close-i,s=Math.floor(Math.abs(o)/n);if(s>=1){let c=o>0?1:-1;for(let o=0;o<s;o++){let o=i;i+=c*n,r.push({time:a++,open:o,high:Math.max(o,i),low:Math.min(o,i),close:i,volume:e[t].volume/s})}}}return r}function Ee(e,t){let n=0;for(let r=1;r<=Math.min(t,e.length-1);r++){let t=Math.max(e[r].high-e[r].low,Math.abs(e[r].high-e[r-1].close),Math.abs(e[r].low-e[r-1].close));n+=t}return n/t}function De(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume});for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume}):!s&&a<o.close||s&&a<u?n.push({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume}):!s&&a>l&&n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume})}return n}function Oe(e,t=4){if(e.length<2)return e.slice();let n=[],r=e[1].close>=e[0].close?1:-1,i=e[0].close,a=e[0].close,o=e[0].close,s=0;for(let c=1;c<e.length;c++){let l=e[c].close,u=t/100*o;r===1?(l>i&&(i=l),i-l>=u&&(n.push({time:s++,open:o,high:i,low:o,close:i,volume:e[c].volume}),r=-1,o=i,a=l,i=l)):(l<a&&(a=l),l-a>=u&&(n.push({time:s++,open:o,high:o,low:a,close:a,volume:e[c].volume}),r=1,o=a,i=l,a=l))}return r===1?n.push({time:s,open:o,high:i,low:o,close:i,volume:0}):n.push({time:s,open:o,high:o,low:a,close:a,volume:0}),n}function ke(e,t,n=3){if(e.length===0||t<=0)return[];let r=[],i=0,a=0,o=0,s=0,c=Math.round(e[0].close/t)*t;a=c,o=c,i=1;for(let c=1;c<e.length;c++){let l=e[c].close,u=Math.round(l/t)*t;i===1?u>a?a=u:a-u>=t*n&&(r.push({time:s++,open:o,high:a,low:o,close:a,volume:e[c].volume}),i=-1,o=u,a-=t):u<o?o=u:u-o>=t*n&&(r.push({time:s++,open:a,high:a,low:o,close:o,volume:e[c].volume}),i=1,a=u,o+=t)}return r.push({time:s,open:i===1?o:a,high:a,low:o,close:i===1?a:o,volume:0}),r}function Ae(e,t){if(e.length===0||t.rangeSize<=0)return[];let n=[],r=e[0].time,i=e[0].open,a=i,o=i,s=0,c=(e,c)=>{for(e>a&&(a=e),e<o&&(o=e),s+=c;a-o>=t.rangeSize;){let c=e>=i,l=c?i+t.rangeSize:i-t.rangeSize;n.push({time:r++,open:i,high:c?l:i,low:c?i:l,close:l,volume:s}),i=l,a=l,o=l,s=0}};for(let t of e){let e=t.close>=t.open?[t.low,t.high,t.close]:[t.high,t.low,t.close],n=t.volume/e.length;for(let t of e)c(t,n)}return n}var M=class{drawLine(e,t,n,r){if(!(t.length<2)){e.beginPath(),e.strokeStyle=n,e.lineWidth=r,e.lineJoin=`round`,e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.stroke()}}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(e,t,n,r){let i=[],{from:s,to:c}=r.visibleRange;for(let l=s;l<=c&&l<n.length;l++){let s=e.values.get(n[l].time);s&&s[t]!==void 0&&i.push({x:a(l,r),y:o(s[t],r)})}return i}},je=1,Me=class{registry=new Map;instances=new Map;register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(e,t={},n){let r=this.registry.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);let i=`tc_${e}_${je++}`,a={id:e,instanceId:i,params:{...r.descriptor.defaultConfig,...t},visible:!0},o={plugin:r,config:a,output:null,style:{colors:a.style?.colors??[`#2196F3`,`#FF9800`,`#4CAF50`,`#E91E63`,`#9C27B0`],lineWidths:a.style?.lineWidths??[1.5],opacity:a.style?.opacity??1}};return n&&(o.output=r.calculate(n,a)),this.instances.set(i,o),i}removeIndicator(e){this.instances.delete(e)}updateIndicator(e,t,n){let r=this.instances.get(e);r&&(Object.assign(r.config.params,t),n&&(r.output=r.plugin.calculate(n,r.config)))}recalculateAll(e){for(let t of this.instances.values())t.output=t.plugin.calculate(e,t.config)}getOutput(e){return this.instances.get(e)?.output??null}renderOverlays(e,t){for(let n of this.instances.values())!n.output||!n.config.visible||n.plugin.descriptor.placement===`overlay`&&n.plugin.render(e,n.output,t,n.style)}renderPanel(e,t,n){let r=this.instances.get(t);!r?.output||!r.config.visible||r.plugin.render(e,r.output,n,r.style)}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0});return e}updateIndicatorStyle(e,t){let n=this.instances.get(e);n&&Object.assign(n.style,t)}getOverlayPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.instances.values()){if(!i.output||!i.config.visible||i.plugin.descriptor.placement!==`overlay`)continue;let a=0;for(let[,o]of i.output.values){if(a>=e&&a<=t)for(let e in o){let t=o[e];t!==void 0&&isFinite(t)&&(t<n&&(n=t),t>r&&(r=t))}a++}}return n===1/0?null:{min:n,max:r}}getPanelIndicators(){let e=[];for(let[t,n]of this.instances)n.plugin.descriptor.placement===`panel`&&e.push({instanceId:t,descriptor:n.plugin.descriptor});return e}};function N(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function P(e,t,n,r=1){let i=N(e,t,n);return Math.max(r,Math.floor(i))}var Ne=class extends M{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Pe=class extends M{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=2/(n+1),i=new Map,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Fe=class extends M{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2}};calculate(e,t){let n=P(t,`period`,20,1),r=N(t,`stdDev`,2),i=new Map,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=0,d=l-c+1,f=new Float64Array(d),p=new Float64Array(d),m=new Float64Array(d),h=new Float64Array(d),g=new Float64Array(d),_=new Float64Array(d);for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);f[u]=n,p[u]=o(t.upper,r),m[u]=n,h[u]=o(t.middle,r),g[u]=n,_[u]=o(t.lower,r),u++}if(!(u<2)){t.beginPath(),t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);for(let e=u-1;e>=0;e--)t.lineTo(g[e],_[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[0],.1),t.fill(),t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`,t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[1]??i.colors[0],t.moveTo(m[0],h[0]);for(let e=1;e<u;e++)t.lineTo(m[e],h[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[0],t.moveTo(g[0],_[0]);for(let e=1;e<u;e++)t.lineTo(g[e],_[e]);t.stroke()}}},Ie=class extends M{descriptor={id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=0,a=0;for(let t=0;t<e.length;t++){let o=(e[t].high+e[t].low+e[t].close)/3;if(i+=e[t].volume,a+=o*e[t].volume,i>0){let o={value:a/i};n.set(e[t].time,o),r[t]=o}}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Le=class extends M{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26}};calculate(e,t){let n=P(t,`tenkan`,9,1),r=P(t,`kijun`,26,1),i=P(t,`senkou`,52,1),a=new Map,o=Array(e.length).fill(null),s=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},c=s(n),l=s(r),u=s(i);for(let t=0;t<e.length;t++){let s={};t>=n-1&&(s.tenkan=(c.highs[t]+c.lows[t])/2),t>=r-1&&(s.kijun=(l.highs[t]+l.lows[t])/2),s.tenkan!==void 0&&s.kijun!==void 0&&(s.senkouA=(s.tenkan+s.kijun)/2),t>=i-1&&(s.senkouB=(u.highs[t]+u.lows[t])/2),t>=r-1&&(s.chikou=e[t].close),(s.tenkan!==void 0||s.kijun!==void 0||s.senkouA!==void 0||s.senkouB!==void 0)&&(a.set(e[t].time,s),o[t]=s)}return{values:a,series:o}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=l-c+1,d=new Float64Array(u),f=new Float64Array(u),p=0,m=new Float64Array(u),h=new Float64Array(u),g=0,_=new Float64Array(u),v=new Float64Array(u),y=0,b=new Float64Array(u),x=new Float64Array(u),S=0;for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.tenkan!==void 0&&(d[p]=n,f[p]=o(t.tenkan,r),p++),t.kijun!==void 0&&(m[g]=n,h[g]=o(t.kijun,r),g++),t.senkouA!==void 0&&(_[y]=n,v[y]=o(t.senkouA,r),y++),t.senkouB!==void 0&&(b[S]=n,x[S]=o(t.senkouB,r),S++)}if(y>1&&S>1){let n=Math.min(y,S);t.beginPath(),t.moveTo(_[0],v[0]);for(let e=1;e<n;e++)t.lineTo(_[e],v[e]);for(let e=n-1;e>=0;e--)t.lineTo(b[e],x[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[2]??`#26A69A`,.15),t.fill()}let C=(e,n,r,i,a)=>{if(!(r<2)){t.beginPath(),t.strokeStyle=i,t.lineWidth=a,t.lineJoin=`round`,t.moveTo(e[0],n[0]);for(let i=1;i<r;i++)t.lineTo(e[i],n[i]);t.stroke()}};C(d,f,p,i.colors[0],i.lineWidths[0]),C(m,h,g,i.colors[1]??`#FF9800`,i.lineWidths[0]),C(_,v,y,i.colors[2]??`#26A69A`,1),C(b,x,S,i.colors[3]??`#EF5350`,1)}},Re=class extends M{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2}};calculate(e,t){let n=N(t,`step`,.02),r=N(t,`max`,.2),i=new Map,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=Math.max(1.5,n.barWidth*.15);for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),u=o(s.value,n);e.beginPath(),e.arc(c,u,l,0,Math.PI*2),e.fillStyle=s.trend===1?r.colors[0]:r.colors[1]??`#EF5350`,e.fill()}}},ze=class extends M{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3}};calculate(e,t){let n=P(t,`period`,10,1),r=N(t,`multiplier`,3),i=new Map,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s;c=g<u||e[t-1].close>u?g:u,l=_>d||e[t-1].close<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let v={value:f,trend:m};i.set(e[t].time,v),a[t]=v,u=c,d=l,p=f}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#EF5350`,d=0,f=0,p=0;for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),m=o(s.value,n),h=s.trend??1;p!==0&&(e.beginPath(),e.strokeStyle=h===1?l:u,e.lineWidth=r.lineWidths[0]+.5,e.moveTo(d,f),e.lineTo(c,m),e.stroke()),d=c,f=m,p=h}}},Be=class extends M{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5}};calculate(e,t){let n=P(t,`emaPeriod`,20,1),r=P(t,`atrPeriod`,10,1),i=N(t,`multiplier`,1.5),a=new Map;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Ve=class extends M{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??`#787B86`,1),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},He=[`s3`,`s2`,`s1`,`pp`,`r1`,`r2`,`r3`],Ue=class extends M{descriptor={id:`pivots`,name:`Pivot Points (Classic)`,placement:`overlay`,defaultConfig:{lookback:24}};calculate(e,t){let n=P(t,`lookback`,24,1),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};for(let t=n;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n;r<t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s=e[t-1].close,c=(a+o+s)/3,l=a-o,u={pp:c,r1:2*c-o,s1:2*c-a,r2:c+l,s2:c-l,r3:a+2*(c-o),s3:o-2*(a-c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#EF5350`,d=r.colors[2]??`#26A69A`,f=r.lineWidths[0],p=e=>e===`pp`?l:e.startsWith(`r`)?u:d;for(let t of He){e.beginPath(),e.strokeStyle=p(t),e.lineWidth=t===`pp`?f:Math.max(1,f-1),t!==`pp`&&e.setLineDash([4,3]);let r=!1;for(let l=s;l<=c&&l<i.length;l++){let s=i[l]?.[t];if(s===void 0)continue;let c=a(l,n),u=o(s,n);r?e.lineTo(c,u):(e.moveTo(c,u),r=!0)}e.stroke(),e.setLineDash([])}}},We=class extends M{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0}};calculate(e,t){let n=N(t,`anchorTime`,0),r=new Map,i=Array(e.length).fill(null),a=0;if(n>0&&(a=e.findIndex(e=>e.time>=n),a<0))return{values:r,series:i};let o=0,s=0;for(let t=a;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(o+=e[t].volume,s+=n*e[t].volume,o>0){let n={value:s/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Ge=class extends M{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5}};calculate(e,t){let n=Math.max(.01,N(t,`deviation`,5))/100,r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(e,t,n,r){let i=t.meta?.pivots;if(!(!i||i.length<2)){e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;for(let t=0;t<i.length;t++){let r=i[t],s=a(r.idx,n),c=o(r.price,n);t===0?e.moveTo(s,c):e.lineTo(s,c)}e.stroke()}}},Ke=class extends M{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2}};calculate(e,t){let n=P(t,`period`,100,2),r=N(t,`stdDev`,2),i=new Map,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},qe=class extends M{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21}};calculate(e,t){let n=P(t,`period`,21,2),r=new Map,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=Je(a,n),l=Je(a,o),u=Ye(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}};function Je(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function Ye(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var Xe=class extends M{descriptor={id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`}};calculate(t,n){let r=P(n,`period`,50,1),i=String(n.params.timeframe??`1d`),a=new Map,o=Array(t.length).fill(null);if(t.length===0)return{values:a,series:o};let s=[],c=(0,e.timeframeBucketStart)(t[0].time,i),l=t[0].close,u=null,d=()=>{if(s.length<r)return;let e=0;for(let t=s.length-r;t<s.length;t++)e+=s[t];u=e/r};for(let n=0;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,i);if(r!==c&&(s.push(l),d(),c=r),l=t[n].close,u!==null){let e={value:u};a.set(t[n].time,e),o[n]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Ze=class extends M{descriptor={id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1}};calculate(t,n){let r=Math.min(3,P(n,`bands`,1,0)),i=new Map,a=Array(t.length).fill(null);if(t.length===0)return{values:i,series:a};let o=(0,e.timeframeBucketStart)(t[0].time,`1d`),s=0,c=0,l=0;for(let n=0;n<t.length;n++){let u=t[n],d=(0,e.timeframeBucketStart)(u.time,`1d`);d!==o&&(s=0,c=0,l=0,o=d);let f=(u.high+u.low+u.close)/3;if(s+=f*u.volume,c+=f*f*u.volume,l+=u.volume,l>0){let e=s/l,t={value:e,session:o};if(r>0){let n=Math.max(0,c/l-e*e),i=Math.sqrt(n);for(let n=1;n<=r;n++)t[`u${n}`]=e+n*i,t[`l${n}`]=e-n*i}i.set(u.time,t),a[n]=t}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:a,to:o}=n.visibleRange;e.globalAlpha=.55,e.lineWidth=1,e.setLineDash([4,3]),e.strokeStyle=r.colors[1]??r.colors[0];for(let t=1;t<=3;t++)this.strokeBandSeries(e,i,n,a,o,e=>e[`u${t}`]),this.strokeBandSeries(e,i,n,a,o,e=>e[`l${t}`]);e.setLineDash([]),e.globalAlpha=1,e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,this.strokeBandSeries(e,i,n,a,o,e=>e.value)}strokeBandSeries(e,t,n,r,i,s){e.beginPath();let c,l=!1;for(let u=r;u<=i&&u<t.length;u++){let r=t[u],i=r?s(r):void 0;if(r===null||i===void 0){l=!1;continue}let d=a(u,n),f=o(i,n),p=r.session!==c;!l||p?(e.moveTo(d,f),l=!0):e.lineTo(d,f),c=r.session}e.stroke()}},Qe=class extends M{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3}};calculate(e,t){let n=P(t,`period`,22,1),r=N(t,`multiplier`,3),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.setLineDash([5,3]);let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke(),e.setLineDash([])};l(`long`,r.colors[0]??`#26A69A`),l(`short`,r.colors[1]??`#EF5350`)}},$e=class extends M{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3}};calculate(e,t){let n=P(t,`jaw`,13,1),r=P(t,`teeth`,8,1),i=P(t,`lips`,5,1),a=P(t,`jawShift`,8,0),o=P(t,`teethShift`,5,0),s=P(t,`lipsShift`,3,0),c=new Map,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=et(d,n),p=et(d,r),m=et(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke()};l(`jaw`,r.colors[0]??`#2962FF`),l(`teeth`,r.colors[1]??`#EF5350`),l(`lips`,r.colors[2]??`#26A69A`)}};function et(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var tt=class extends M{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34}};calculate(e,t){let n=P(t,`fast`,5,1),r=P(t,`slow`,34,1),i=new Map,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#26A69A`,g=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.up?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},nt=class extends M{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10}};calculate(e,t){let n=P(t,`fast`,3,1),r=P(t,`slow`,10,1),i=new Map,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#26A69A`,g=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.value>=0?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},rt=class extends M{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=0,o=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?a+=n:o-=n}a/=n,o/=n;let s={value:o===0?100:100-100/(1+a/o)};r.set(e[n].time,s),i[n]=s;for(let t=n+1;t<e.length;t++){let s=e[t].close-e[t-1].close,c=s>0?s:0,l=s<0?-s:0;a=(a*(n-1)+c)/n,o=(o*(n-1)+l)/n;let u={value:o===0?100:100-100/(1+a/o)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath();for(let t of[30,70]){let n=l(t);e.moveTo(o.x,n),e.lineTo(o.x+o.width,n)}e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},it=class extends M{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};calculate(e,t){let n=P(t,`fast`,12,1),r=P(t,`slow`,26,1),i=P(t,`signal`,9,1),a=new Map,o=Array(e.length).fill(null);if(e.length<r)return{values:a,series:o};let s=2/(n+1),c=2/(r+1),l=2/(i+1),u=e[0].close,d=e[0].close,f=0,p=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(u=n,d=n):(u=(n-u)*s+u,d=(n-d)*c+d),t>=r-1){let n=u-d;p?f=(n-f)*l+f:(f=n,p=!0);let r=n-f,i={macd:n,signal:f,histogram:r};a.set(e[t].time,i),o[t]=i}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.macd!==void 0&&(t.macd<l&&(l=t.macd),t.macd>u&&(u=t.macd)),t.signal!==void 0&&(t.signal<l&&(l=t.signal),t.signal>u&&(u=t.signal)),t.histogram!==void 0&&(t.histogram<l&&(l=t.histogram),t.histogram>u&&(u=t.histogram)))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d),p=f(0),m=n.barWidth/2,h=r.colors[2]??`#26A69A`,g=r.colors[3]??`#EF5350`,_=r.colors[0],v=r.colors[1]??`#FF9800`;e.beginPath();let y=new Path2D,b=new Path2D,x=!1,S=!1,C=new Path2D,w=new Path2D;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(!t)continue;let r=a(e,n);if(t.histogram!==void 0){let e=f(t.histogram),i=Math.min(e,p),a=Math.max(Math.abs(e-p),1);t.histogram>=0?y.rect(r-m,i,n.barWidth,a):b.rect(r-m,i,n.barWidth,a)}if(t.macd!==void 0){let e=f(t.macd);x?C.lineTo(r,e):(C.moveTo(r,e),x=!0)}if(t.signal!==void 0){let e=f(t.signal);S?w.lineTo(r,e):(w.moveTo(r,e),S=!0)}}e.fillStyle=h,e.fill(y),e.fillStyle=g,e.fill(b),e.strokeStyle=_,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.stroke(C),e.strokeStyle=v,e.stroke(w)}},at=class extends M{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3}};calculate(e,t){let n=P(t,`kPeriod`,14,1),r=P(t,`dPeriod`,3,1),i=P(t,`smooth`,3,1),a=new Map,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]),u(`d`,r.colors[1]??`#FF9800`)}},ot=class extends M{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},st=class extends M{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`adx`,r.colors[0]),u(`plusDI`,r.colors[1]??`#26A69A`),u(`minusDI`,r.colors[2]??`#EF5350`)}},ct=class extends M{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},lt=class extends M{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-20,-80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},ut=class extends M{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-100,0,100])if(t>=f&&t<=p){let n=h(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},dt=class extends M{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},ft=class extends M{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25}};calculate(e,t){let n=P(t,`period`,25,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`up`,r.colors[0]),u(`down`,r.colors[1]??`#EF5350`)}},pt=class extends M{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12}};calculate(e,t){let n=P(t,`period`,12,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);if(0>=f&&0<=p){e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);let t=h(0);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},mt=class extends M{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7}};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=P(t,`longPeriod`,25,1),r=P(t,`shortPeriod`,13,1),i=P(t,`signalPeriod`,7,1),a=new Map,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.tsi!==void 0&&(l=Math.min(l,t.tsi),u=Math.max(u,t.tsi)),t.signal!==void 0&&(l=Math.min(l,t.signal),u=Math.max(u,t.signal)))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=h(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};g(`tsi`,r.colors[0]),g(`signal`,r.colors[1]??`#FF9800`)}},ht=class extends M{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=n.barWidth/2;for(let t=s;t<=c&&t<i.length;t++){let o=i[t];if(o&&o.value!==void 0){let i=a(t,n),s=h(o.value),c=h(0);e.fillStyle=o.value>=0?r.colors[0]:r.colors[1]??`#EF5350`;let l=Math.min(s,c);e.fillRect(i-g,l,n.barWidth,Math.max(Math.abs(s-c),1))}}}},gt=class extends M{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0}};calculate(e,t){let n=N(t,`mode`,0)>=1,r=new Map,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2,p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value),c=Math.min(s,d),l=Math.max(Math.abs(s-d),1);e.fillStyle=r.up?p:m,e.fillRect(o-f,c,n.barWidth,l)}}},_t=class extends M{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`viPlus`,`viMinus`]){let n=t[e];n!==void 0&&(n<l&&(l=n),n>u&&(u=n))}}if(l===1/0)return;let d=(u-l)*.1||.1;l-=d,u+=d;let f=u-l||1,p=e=>o.y+o.height*(1-(e-l)/f);if(1>=l&&1<=u){e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);let t=p(1);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}let m=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=p(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};m(`viPlus`,r.colors[0]??`#26A69A`),m(`viMinus`,r.colors[1]??`#EF5350`)}},vt=class extends M{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,2),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[38.2,61.8]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},yt=class extends M{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28}};calculate(e,t){let n=P(t,`fast`,7,1),r=P(t,`mid`,14,1),i=P(t,`slow`,28,1),a=new Map,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=bt(l(s,t,n),l(c,t,n)),d=bt(l(s,t,r),l(c,t,r)),f=bt(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function bt(e,t){return t===0?0:e/t}var xt=class extends M{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=P(t,`period`,13,1),r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},St=class extends M{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100}};calculate(e,t){let n=P(t,`rsiPeriod`,3,1),r=P(t,`streakPeriod`,2,1),i=P(t,`rankPeriod`,100,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=Ct(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=Ct(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[10,90]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function Ct(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var wt=class extends M{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10}};calculate(e,t){let n=P(t,`longRoc`,14,1),r=P(t,`shortRoc`,11,1),i=P(t,`wma`,10,1),a=new Map,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},Tt=class extends M{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9}};calculate(e,t){let n=P(t,`roc1`,10,1),r=P(t,`roc2`,15,1),i=P(t,`roc3`,20,1),a=P(t,`roc4`,30,1),o=P(t,`sma1`,10,1),s=P(t,`sma2`,10,1),c=P(t,`sma3`,10,1),l=P(t,`sma4`,15,1),u=P(t,`signal`,9,1),d=new Map,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=I(F(m,n),o),g=I(F(m,r),s),_=I(F(m,i),c),v=I(F(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=I(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}};function F(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function I(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var Et=class extends M{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=P(t,`period`,13,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`bull`,`bear`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r)continue;let o=a(t,n);if(r.bull!==void 0){let t=u(r.bull);e.fillStyle=p,e.globalAlpha=.8,e.fillRect(o-f,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}if(r.bear!==void 0){let t=u(r.bear);e.fillStyle=m,e.globalAlpha=.8,e.fillRect(o,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}}e.globalAlpha=1}},Dt=class extends M{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10}};calculate(e,t){let n=P(t,`fast`,23,1),r=P(t,`slow`,50,1),i=P(t,`cycle`,10,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=Ot(Ot(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[25,75]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function Ot(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var kt=class extends M{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13}};calculate(e,t){let n=P(t,`fast`,34,1),r=P(t,`slow`,55,1),i=P(t,`signal`,13,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}},At=class extends M{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=P(t,`period`,9,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`trigger`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`trigger`,r.colors[1]??`#FF9800`)}},jt=class extends M{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,2),r=Math.floor(n/2)+1,i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);e.fillStyle=r.value>=0?p:m,e.fillRect(o-f,Math.min(s,d),n.barWidth,Math.max(1,Math.abs(s-d)))}}},Mt=class extends M{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14}};calculate(e,t){let n=P(t,`smooth`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+1)/2),u=l(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,u),e.lineTo(o.x+o.width,u),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(Math.max(-1,Math.min(1,r.value)));d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},Nt=class extends M{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25}};calculate(e,t){let n=P(t,`ema`,9,1),r=P(t,`sum`,25,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;l=Math.min(l,26),u=Math.max(u,27.5);let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[26.5,27]){let n=f(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}},Pt=class extends M{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=P(t,`period`,9,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/200);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-50,0,50]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Ft=class extends M{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9}};calculate(e,t){let n=P(t,`period`,15,1),r=P(t,`signal`,9,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=L(L(L(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=L(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}};function L(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var It=class extends M{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){R(e,t,n,r)}};function R(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}var Lt=class extends M{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){Rt(e,t,n,r,a)}};function Rt(e,t,n,r,i){let a=t.series;if(!a)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<a.length;e++){let t=a[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<a.length;t++){let r=a[t];if(!r||r.value===void 0)continue;let o=i(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}var zt=class extends M{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}render(e,t,n,r){Rt(e,t,n,r,a)}},Bt=class extends M{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10}};calculate(e,t){let n=P(t,`ema`,10,1),r=P(t,`roc`,10,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}render(e,t,n,r){R(e,t,n,r)}},Vt=class extends M{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10}};calculate(e,t){let n=P(t,`period`,10,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}},Ht=class extends M{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3}};calculate(e,t){let n=P(t,`rsiPeriod`,14,1),r=P(t,`stochPeriod`,14,1),i=P(t,`k`,3,1),a=P(t,`d`,3,1),o=new Map,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=Ut(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=Wt(u,i),f=Wt(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){u=!1;continue}let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]??`#2962FF`),u(`d`,r.colors[1]??`#FF9800`)}};function Ut(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function Wt(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var Gt=class extends M{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};calculate(e,t){let n=P(t,`fast`,12,1),r=P(t,`slow`,26,1),i=P(t,`signal`,9,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=Kt(c,n),u=Kt(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=Kt(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`,`hist`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=Math.max(1,o.width/(c-s+1)*.6);for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.hist;if(r===void 0)continue;let o=a(t,n),s=u(r);e.fillStyle=r>=0?`rgba(38,166,154,0.5)`:`rgba(239,83,80,0.5)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d)))}e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};p(`value`,r.colors[0]??`#2962FF`),p(`signal`,r.colors[1]??`#FF9800`)}};function Kt(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var qt=class extends M{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{}};calculate(e){let t=new Map,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=Jt(i,e,5)-Jt(i,e,34);for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let o={value:a[i]-r/5};t.set(e[i].time,o),n[i]=o}return{values:t,series:n}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=Math.max(1,o.width/(c-s+1)*.6),p;for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.value;if(r===void 0){p=void 0;continue}let o=a(t,n),s=u(r);e.fillStyle=(p===void 0?r>=0:r>=p)?`rgba(38,166,154,0.85)`:`rgba(239,83,80,0.85)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d))),p=r}}};function Jt(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var Yt=class extends M{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5}};calculate(e,t){let n=P(t,`period`,20,1),r=P(t,`momentum`,5,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#2962FF`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){u=!1;continue}let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Xt=class extends M{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){R(e,t,n,r)}},Zt=class extends M{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8}};calculate(e,t){let n=P(t,`period`,8,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}render(e,t,n,r){R(e,t,n,r)}},Qt=class extends M{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=3;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}let u=e=>o.y+o.height*(1-(e+l)/(2*l));e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-3,0,3]){let n=u(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#2962FF`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){d=!1;continue}let o=a(t,n),s=u(r.value);d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},$t=class extends M{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},en=class extends M{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`panel`,defaultConfig:{rows:24}};calculate(e,t){let n=P(t,`rows`,24,1),r=new Map,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(e,t,n,r){let{chartRect:i}=n,a=t.meta;if(!a||a.maxVolume===0)return;let{minPrice:o,rows:s,rowHeight:c,bins:l,maxVolume:u}=a,d=i.height/s,f=i.width*.3;for(let t=0;t<s;t++){let a=(o+(t+.5)*c-n.priceRange.min)/(n.priceRange.max-n.priceRange.min),s=i.y+i.height*(1-a),p=l[t]/u*f;e.fillStyle=l[t]>u*.7?r.colors[1]??`rgba(255, 152, 0, 0.5)`:r.colors[0]??`rgba(33, 150, 243, 0.3)`,e.fillRect(i.x,s-d/2,p,Math.max(d-1,1))}}},tn=class extends M{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},nn=class extends M{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([])),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}};function rn(e){e.register(new Ne),e.register(new Pe),e.register(new Fe),e.register(new Ie),e.register(new Le),e.register(new Re),e.register(new ze),e.register(new Be),e.register(new Ve),e.register(new Ue),e.register(new We),e.register(new Ge),e.register(new Ke),e.register(new qe),e.register(new Xe),e.register(new Ze),e.register(new Qe),e.register(new $e),e.register(new rt),e.register(new it),e.register(new at),e.register(new ot),e.register(new st),e.register(new ct),e.register(new lt),e.register(new ut),e.register(new dt),e.register(new ft),e.register(new pt),e.register(new mt),e.register(new ht),e.register(new $t),e.register(new en),e.register(new tn),e.register(new nn),e.register(new tt),e.register(new nt),e.register(new gt),e.register(new _t),e.register(new vt),e.register(new yt),e.register(new xt),e.register(new St),e.register(new wt),e.register(new Tt),e.register(new Et),e.register(new Dt),e.register(new kt),e.register(new At),e.register(new jt),e.register(new Mt),e.register(new Nt),e.register(new Pt),e.register(new Ft),e.register(new It),e.register(new zt),e.register(new Lt),e.register(new Bt),e.register(new Vt),e.register(new Ht),e.register(new Gt),e.register(new qt),e.register(new Yt),e.register(new Xt),e.register(new Zt),e.register(new Qt)}function an(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var on=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i={type:`calculate`,requestId:r,indicatorId:e,config:t,data:n};return new Promise((t,n)=>{let a={resolve:t,reject:n,timer:null};this.timeoutMs>0&&(a.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,a),this.worker.postMessage(i)})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!an(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(e.output)}}},sn=class{visible=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}render(t,n,r){if(!this.visible)return;let{chartRect:i,priceRange:a}=n;t.strokeStyle=r.grid,t.lineWidth=1;let o=a.max-a.min;if(o<=0)return;let s=1/o;t.beginPath();let c=(0,e.computeTickStep)(a.min,a.max,8),l=Math.ceil(a.min/c)*c;for(let e=l;e<=a.max;e+=c){let n=Math.round(i.y+i.height*(1-(e-a.min)*s))+.5;t.moveTo(i.x,n),t.lineTo(i.x+i.width,n)}let u=n.barWidth+n.barSpacing,d=Math.max(1,Math.ceil(80/u)),{from:f,to:p}=n.visibleRange,m=-n.offset+i.x+n.barWidth/2;for(let e=f;e<=p;e++){if(e%d!==0)continue;let n=Math.round(e*u+m)+.5;t.moveTo(n,i.y),t.lineTo(n,i.y+i.height)}t.stroke()}},cn=class{locale=`en-US`;setLocale(e){this.locale=e}render(t,n,r){let{chartRect:i,priceRange:a}=n,o=i.x+i.width,s=a.max-a.min;if(s<=0)return;let c=1/s;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o+.5,i.y),t.lineTo(o+.5,i.y+i.height),t.stroke(),t.globalAlpha=1;let l=(0,e.computeTickStep)(a.min,a.max,8),u=Math.ceil(a.min/l)*l,d=l<1?Math.ceil(-Math.log10(l))+1:2,f=`500 ${r.font.sizeSmall}px ${r.font.family}`,p=n.scaleMode??(n.logScale?`logarithmic`:`regular`),m=n.scaleBaseline,h=[];for(let t=u;t<=a.max;t+=l){let n=i.y+i.height*(1-(t-a.min)*c);h.push({y:n,text:(0,e.formatPriceScaleLabel)(t,p,m,d,this.locale)})}t.font=f,t.textBaseline=`middle`,t.textAlign=`left`,t.strokeStyle=r.axisLine,t.globalAlpha=.45,t.beginPath();for(let{y:e}of h)t.moveTo(o+1,e+.5),t.lineTo(o+4,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.axisLabel;for(let{y:e,text:n}of h)t.fillText(n,o+8,e)}},ln=e=>e<10?`0`+e:``+e,un=class{tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}render(t,n,r,i,a){let{chartRect:o}=n,s=a??o.y+o.height;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o.x,s+.5),t.lineTo(o.x+o.width,s+.5),t.stroke(),t.globalAlpha=1;let c=n.barWidth+n.barSpacing,l=Math.max(1,Math.ceil(80/c)),{from:u,to:d}=n.visibleRange,f=-n.offset+o.x+n.barWidth/2;t.font=`500 ${r.font.sizeSmall}px ${r.font.family}`,t.textBaseline=`top`,t.textAlign=`center`,t.fillStyle=r.axisLabel;let p=-1;for(let n=u;n<=d&&n<i.length;n++){if(n%l!==0)continue;let r=n*c+f,a=i[n].time,o=(0,e.timeParts)(a>0xe8d4a51000?a:a*1e3,this.tzOffsetMinutes),{year:u,day:d,month:m,hours:h,minutes:g}=o,_;(0,e.isDateOnly)(o)?_=`${m}/${d}/${u}`:d===p?_=`${ln(h)}:${ln(g)}`:(_=`${m}/${d}`,p=d),t.fillText(_,r,s+7)}let m=o.x+o.width-4,h=s+7;t.font=`500 ${r.font.sizeSmall-1}px ${r.font.family}`,t.textAlign=`right`,t.textBaseline=`top`,t.globalAlpha=.75,t.fillStyle=r.textSecondary,t.fillText((0,e.tzLabel)(this.tzOffsetMinutes),m,h),t.globalAlpha=1}},dn=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;measureHandlers=null;measuring=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressMs=500;longPressMaxMove=8;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e}setZoomHandler(e){this.zoomHandler=e}setCrosshairHandler(e){this.crosshairHandler=e}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setClickHandler(e){this.onClick=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setPaneResizeHandler(e){this.paneResizeHandler=e}attach(){let e=()=>this.viewportGetter?.()??null,t=e=>{let t=this.axisViewportGetter?.();if(!t)return null;let n=t.chartRect;return e.y>n.y+n.height?`time`:e.x>n.x+n.width?`price`:null},n=n=>{this.invalidateRect();let r=this.getMousePos(n),i=e();this.downPos=r,this.downMoved=!1,this.pressForClick=!1;let a=t(r);if(a&&this.axisDragHandler){this.axisDragHandler.begin(a,r);return}if(!this.paneResizeHandler?.tryBegin(r)){if(n.shiftKey&&this.measureHandlers){this.measuring=!0,this.measureHandlers.begin(r),this.onOverlayDirty?.();return}if(n.altKey&&this.onAltClick){this.onAltClick(r);return}if(!(this.tradingManager&&i&&this.tradingManager.onPointerDown(r,i))&&!(this.drawingManager&&i&&this.drawingManager.onPointerDown(r,i))){if(this.alertDragHandler?.tryBegin(r)){this.onOverlayDirty?.();return}this.pressForClick=!0,this.panHandler?.onPointerDown(r)}}},r=n=>{let r=this.getMousePos(n),i=e();if(this.downPos&&!this.downMoved){let e=r.x-this.downPos.x,t=r.y-this.downPos.y;e*e+t*t>16&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(r);return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(r);return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(r),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(r),this.onOverlayDirty?.();return}let a=t(r),o=this.paneResizeHandler?.cursorAt(r)??null;if(a===`price`?this.element.style.cursor=`ns-resize`:a===`time`?this.element.style.cursor=`ew-resize`:this.alertDragHandler?.isOverAlert(r)?this.element.style.cursor=`ns-resize`:o?this.element.style.cursor=o:(this.element.style.cursor===`ns-resize`||this.element.style.cursor===`ew-resize`)&&(this.element.style.cursor=``),this.tradingManager&&i&&this.tradingManager.onPointerMove(r,i)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}if(this.drawingManager&&i&&this.drawingManager.onPointerMove(r,i)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(r),this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.()},i=()=>{if(this.axisDragHandler?.isActive()){this.axisDragHandler.end();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.end();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.end(),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.();return}this.tradingManager?.onPointerUp()||this.drawingManager?.onPointerUp()||(this.panHandler?.onPointerUp(),this.pressForClick&&!this.downMoved&&this.downPos&&this.onClick&&this.onClick(this.downPos),this.pressForClick=!1,this.downPos=null)},a=e=>{let n=t(this.getMousePos(e));n&&this.onAxisDoubleClick&&this.onAxisDoubleClick(n)},o=()=>{this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},s=e=>{e.preventDefault();let t=this.getMousePos(e);this.zoomHandler?.onWheel(e.deltaY,t)},c=e=>{if(e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey)&&e.preventDefault()},l=t=>{let n=e();!this.tradingManager||!n||this.tradingManager.onContextMenu(this.getMousePos(t),n)&&t.preventDefault()},u=n=>{if(n.preventDefault(),this.invalidateRect(),n.touches.length===1){let r=this.getTouchPos(n.touches[0]);this.touchStartPos=r;let i=t(r);if(i&&this.axisDragHandler){this.axisDragHandler.begin(i,r),this.touchActive=!0;return}if(this.paneResizeHandler?.tryBegin(r)){this.touchActive=!0;return}let a=e();if(this.tradingManager&&a&&this.tradingManager.onPointerDown(r,a)){this.touchActive=!0,this.onOverlayDirty?.();return}this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.onAltClick?.(r),this.panHandler?.onPointerUp(),this.onOverlayDirty?.()},this.longPressMs)),this.panHandler?.onPointerDown(r),this.crosshairHandler?.onPointerMove(r),this.touchActive=!0}else n.touches.length===2&&(this.clearLongPress(),this.panHandler?.onPointerUp(),this.lastTouchDist=this.getTouchDistance(n.touches[0],n.touches[1]),this.lastTouchMid=this.getTouchMidpoint(n.touches[0],n.touches[1]),this.touchActive=!0)},d=t=>{if(t.preventDefault(),t.touches.length===1&&this.touchActive){let n=this.getTouchPos(t.touches[0]);if(this.longPressTimer){let e=n.x-this.touchStartPos.x,t=n.y-this.touchStartPos.y;Math.hypot(e,t)>this.longPressMaxMove&&this.clearLongPress()}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(n),this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(n),this.onOverlayDirty?.();return}let r=e();if(this.tradingManager&&r&&this.tradingManager.onPointerMove(n,r)){this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(n),this.crosshairHandler?.onPointerMove(n)}else if(t.touches.length===2){let e=this.getTouchDistance(t.touches[0],t.touches[1]),n=this.getTouchMidpoint(t.touches[0],t.touches[1]);if(this.lastTouchDist>0){let t=(e/this.lastTouchDist-1)*.5;this.zoomHandler?.onWheel(-t*100,n)}let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=e,this.lastTouchMid=n}this.onOverlayDirty?.()},f=e=>{if(this.clearLongPress(),e.touches.length===0)this.axisDragHandler?.isActive()&&this.axisDragHandler.end(),this.paneResizeHandler?.end(),this.tradingManager?.onPointerUp(),this.panHandler?.onPointerUp(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.lastTouchDist=0;else if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.panHandler?.onPointerDown(t)}},p=()=>this.invalidateRect(),m=()=>this.invalidateRect();this.element.addEventListener(`mousedown`,n),this.element.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i),this.element.addEventListener(`mouseleave`,o),this.element.addEventListener(`dblclick`,a),this.element.addEventListener(`wheel`,s,{passive:!1}),this.element.addEventListener(`contextmenu`,l),this.element.addEventListener(`touchstart`,u,{passive:!1}),this.element.addEventListener(`touchmove`,d,{passive:!1}),this.element.addEventListener(`touchend`,f),document.addEventListener(`keydown`,c),window.addEventListener(`resize`,p),this.element.addEventListener(`scroll`,m,{passive:!0}),this.boundHandlers.push(()=>this.element.removeEventListener(`mousedown`,n),()=>this.element.removeEventListener(`mousemove`,r),()=>document.removeEventListener(`mouseup`,i),()=>this.element.removeEventListener(`mouseleave`,o),()=>this.element.removeEventListener(`dblclick`,a),()=>this.element.removeEventListener(`wheel`,s),()=>this.element.removeEventListener(`contextmenu`,l),()=>this.element.removeEventListener(`touchstart`,u),()=>this.element.removeEventListener(`touchmove`,d),()=>this.element.removeEventListener(`touchend`,f),()=>document.removeEventListener(`keydown`,c),()=>window.removeEventListener(`resize`,p),()=>this.element.removeEventListener(`scroll`,m))}detach(){for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},fn=class{dragging=!1;lastX=0;lastY=0;lastTime=0;velocityX=0;velocityY=0;momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.lastTime=Date.now(),this.velocityX=0,this.velocityY=0,this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=Date.now(),n=this.lastX-e.x,r=this.lastY-e.y,i=t-this.lastTime;i>0&&(this.velocityX=n/i,this.velocityY=r/i),this.lastX=e.x,this.lastY=e.y,this.lastTime=t,this.callback(n,r)}onPointerUp(){this.dragging&&(this.dragging=!1,Math.hypot(this.velocityX,this.velocityY)>.1&&this.startMomentum())}startMomentum(){this.stopMomentum();let e=this.velocityX*16,t=this.velocityY*16,n=()=>{if(e*=this.friction,t*=this.friction,Math.hypot(e,t)<.5){this.momentumId=0;return}this.callback(e,t),this.momentumId=requestAnimationFrame(n)};this.momentumId=requestAnimationFrame(n)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},pn=class{callback;sensitivity;pendingDelta=0;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=this.pendingDelta,t=this.pendingCenterX;this.pendingDelta=0,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},mn=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},hn=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e){let t=this.viewportGetter();if(!t)return!1;let n=this.alerts.getAlertAtPoint(e,t);return n?(this.draggingId=n.id,!0):!1}move(e){if(this.draggingId===null)return;let t=this.viewportGetter();t&&this.alerts.updateAlertPrice(this.draggingId,c(e.y,t))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},gn=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t){for(let n of t.dividers)if(_n(e,n.rect,this.tolerance)){let e=t.panels.find(e=>e.config.id===n.panelId);if(e)return{panelId:n.panelId,orientation:n.orientation,position:e.config.position,size:e.config.size}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e){let t=this.layoutGetter?.();if(!t)return!1;let n=this.hitTest(e,t);return n?(this.state={panelId:n.panelId,position:n.position,startSize:n.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function _n(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var vn=class{position=null;callback=null;data=[];tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}magnetMode=!0;mode=`magnet`;pricePrecision=2;locale=`en-US`;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;setCallback(e){this.callback=e}setData(e){this.data=e}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}onPointerMove(e){this.position=e}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(e,t,n){if(!this.position||this.mode===`hidden`)return;let{chartRect:r}=t,{x:i,y:o}=this.position;if(i<r.x||i>r.x+r.width||o<r.y||o>r.y+r.height)return;let c=s(i,t);if(c=Math.max(0,Math.min(this.data.length-1,c)),this.magnetMode&&c>=0&&c<this.data.length&&(i=a(c,t)),c!==this.lastCallbackBarIndex&&(this.pendingBarIndex=c,this.pendingPoint={x:i,y:o},this.lastCallbackBarIndex=c,this.scheduleCallback()),this.magnetMode&&c>=0&&c<this.data.length){let a=t.barWidth+t.barSpacing,o=a/2;e.fillStyle=n.crosshair,e.globalAlpha=.08,e.fillRect(i-o,r.y,a,r.height),e.globalAlpha=1}e.setLineDash([4,4]),e.strokeStyle=n.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(i)+.5,r.y),e.lineTo(Math.round(i)+.5,r.y+r.height),e.stroke(),e.beginPath(),e.moveTo(r.x,Math.round(o)+.5),e.lineTo(r.x+r.width,Math.round(o)+.5),e.stroke(),e.setLineDash([])}renderAxisLabels(t,n,r,i,o){if(!this.position||this.mode===`hidden`)return;let{chartRect:l}=n,{x:u,y:d}=this.position;if(u<l.x||u>l.x+l.width||d<l.y||d>l.y+l.height)return;let f=s(u,n);f=Math.max(0,Math.min(i.length-1,f)),this.magnetMode&&f>=0&&f<i.length&&(u=a(f,n));let p=`600 ${r.font.sizeSmall}px ${r.font.family}`;if(yn(t,{text:(0,e.formatPrice)(c(d,n),this.pricePrecision,this.locale),anchorX:l.x+l.width,anchorY:d,orientation:`right`,bg:r.text,fg:r.background,font:p}),f>=0&&f<i.length){let e=bn(i[f].time,this.tzOffsetMinutes),n=o??l.y+l.height;yn(t,{text:e,anchorX:u,anchorY:n,orientation:`bottom`,bg:r.text,fg:r.background,font:p})}}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}};function yn(e,t){e.save(),e.font=t.font;let n=Math.ceil(e.measureText(t.text).width)+16;if(t.orientation===`right`){let r=t.anchorX+5,i=t.anchorY-20/2;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(r,t.anchorY-5),e.lineTo(r,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,t.anchorY+5),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(t.text,r+8,t.anchorY)}else{let r=t.anchorX-n/2,i=t.anchorY+5;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX+5,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,i),e.lineTo(t.anchorX-5,i),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`center`,e.fillText(t.text,t.anchorX,i+20/2)}e.restore()}function bn(t,n){let r=(0,e.timeParts)(t>0xe8d4a51000?t:t*1e3,n),{year:i,month:a,day:o,hours:s,minutes:c}=r;return(0,e.isDateOnly)(r)?`${a}/${o}/${i}`:`${a}/${o} ${s<10?`0`+s:s}:${c<10?`0`+c:c}`}var xn=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},Sn=class{el=null;visible=!1;timeEl;openEl;highEl;lowEl;closeEl;changeEl;volEl;measuredWidth=155;measuredHeight=95;measured=!1;create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`4px`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=this.addLine(this.el);let t=this.addLine(this.el),n=this.addLine(this.el);this.changeEl=this.addLine(this.el),this.volEl=this.addLine(this.el),t.append(this.label(`O `),this.openEl=this.val(),this.label(` H `),this.highEl=this.val()),n.append(this.label(`L `),this.lowEl=this.val(),this.label(` C `),this.closeEl=this.val()),e.appendChild(this.el)}show(e,t,n,r){if(!this.el)return;let i=t.close>=t.open?n.candleUp:n.candleDown,a=e=>e.toFixed(2),o=new Date(t.time);this.timeEl.textContent=`${o.getMonth()+1}/${o.getDate()} ${String(o.getHours()).padStart(2,`0`)}:${String(o.getMinutes()).padStart(2,`0`)}`,this.timeEl.style.color=n.textSecondary,this.openEl.textContent=a(t.open),this.highEl.textContent=a(t.high),this.lowEl.textContent=a(t.low),this.closeEl.textContent=a(t.close),this.openEl.style.color=i,this.highEl.style.color=i,this.lowEl.style.color=i,this.closeEl.style.color=i;let s=t.close-t.open,c=t.open===0?0:s/t.open*100,l=s>=0?`+`:``;this.changeEl.textContent=`${l}${a(s)} (${l}${c.toFixed(2)}%)`,this.changeEl.style.color=i;let u=t.volume;this.volEl.textContent=`Vol ${u>=1e6?(u/1e6).toFixed(1)+`M`:u>=1e3?(u/1e3).toFixed(1)+`K`:u.toFixed(0)}`,this.volEl.style.color=n.textSecondary;let d=Cn(n.background);this.el.style.background=d?wn(n.background,.95):wn(n.background,.97),this.el.style.border=`1px solid ${n.axisLine}`,this.el.style.boxShadow=d?`0 4px 12px rgba(0,0,0,0.5)`:`0 4px 12px rgba(0,0,0,0.15)`,this.el.style.color=n.text,this.el.style.backdropFilter=`blur(8px)`,!this.measured&&this.visible&&(this.measuredWidth=this.el.offsetWidth,this.measuredHeight=this.el.offsetHeight,this.measured=!0);let f=e.x+16,p=e.y-40;f+this.measuredWidth>r.width-80&&(f=e.x-this.measuredWidth-16),p<4&&(p=4),p+this.measuredHeight>r.height&&(p=r.height-this.measuredHeight-4),this.el.style.transform=`translate(${Math.round(f)}px, ${Math.round(p)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.visible||=(this.el.style.display=`block`,!0)}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.measured=!1}addLine(e){let t=document.createElement(`div`);return e.appendChild(t),t}label(e){let t=document.createElement(`span`);return t.textContent=e,t.style.opacity=`0.6`,t}val(){return document.createElement(`span`)}};function Cn(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(t){let e=parseInt(t[1]),n=parseInt(t[2]),r=parseInt(t[3]);return(.299*e+.587*n+.114*r)/255<.5}return!0}function wn(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var Tn=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`4px`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let t=document.createElement(`div`);t.textContent=`📌 pinned`,t.style.fontSize=`9px`,t.style.opacity=`0.6`,t.style.marginBottom=`2px`,t.style.letterSpacing=`0.04em`,t.style.textTransform=`uppercase`,this.el.insertBefore(t,this.timeEl),e.appendChild(this.el)}pin(e,t,n){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=e,this.pinnedIndex=t;let r=e.close>=e.open?n.candleUp:n.candleDown,i=new Date(e.time>0xe8d4a51000?e.time:e.time*1e3);this.timeEl.textContent=`${i.getMonth()+1}/${i.getDate()} ${En(i.getHours())}:${En(i.getMinutes())}`,this.timeEl.style.color=n.textSecondary,this.ohlcEl.innerHTML=`
2
- <span style="opacity:.6">O </span><span style="color:${r}">${z(e.open)}</span>
3
- <span style="opacity:.6"> H </span><span style="color:${r}">${z(e.high)}</span>
4
- <span style="opacity:.6"> L </span><span style="color:${r}">${z(e.low)}</span>
5
- <span style="opacity:.6"> C </span><span style="color:${r}">${z(e.close)}</span>
6
- `;let a=Dn(n.background);this.el.style.background=On(n.background,a?.96:.97),this.el.style.border=`1px solid ${r}`,this.el.style.boxShadow=a?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=n.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(e,t,n,r){if(!this.el||!this.pinnedBar)return;let i=a(this.pinnedIndex,e),s=o(this.pinnedBar.close,e),c=e.chartRect,l=i>=c.x-4&&i<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,i+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(t&&n!==null&&n!==this.pinnedIndex){let e=t.close-this.pinnedBar.close,i=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,a=e>0?`+`:e<0?`−`:``,o=n-this.pinnedIndex,s=e>=0?r.candleUp:r.candleDown;this.deltaEl.style.color=s,this.deltaEl.innerHTML=`Δ ${a}${z(Math.abs(e))} <span style="opacity:.7">(${a}${Math.abs(i).toFixed(2)}%)</span> · ${o>0?`+`:``}${o} bars`,this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function z(e){return e.toFixed(2)}function En(e){return e<10?`0`+e:``+e}function Dn(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function On(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var kn=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},B=class{hitTestAnchor(e,t,n,r){for(let i=0;i<t.anchors.length;i++){let a=this.anchorToPixel(t.anchors[i],n);if(Math.hypot(e.x-a.x,e.y-a.y)<=r)return i}return-1}anchorToPixel(e,t){return{x:d(e.time,t),y:o(e.price,t)}}pixelToAnchor(e,t){return{time:f(e.x,t),price:c(e.y,t)}}applyLineStyle(e,t){switch(e.strokeStyle=t.color,e.lineWidth=t.lineWidth,t.lineStyle){case`dashed`:e.setLineDash([6,4]);break;case`dotted`:e.setLineDash([2,2]);break;default:e.setLineDash([]);break}}resetLineStyle(e){e.setLineDash([])}renderAnchorHandles(e,t,n){e.fillStyle=`#FFFFFF`,e.strokeStyle=t.style.color,e.lineWidth=1;for(let r of t.anchors){let t=this.anchorToPixel(r,n);e.fillRect(t.x-4,t.y-4,8,8),e.strokeRect(t.x-4,t.y-4,8,8)}}distanceToLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;o=Math.max(0,Math.min(1,o));let s=t.x+o*r,c=t.y+o*i;return Math.hypot(e.x-s,e.y-c)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}},V=1;function H(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},meta:e.meta?{...e.meta}:void 0}}var An=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#2196F3`,lineWidth:1,lineStyle:`solid`,fillColor:`rgba(33, 150, 243, 0.1)`,fillOpacity:.1,fontSize:12};creatingDrawing=null;committedAnchors=0;previewAnchor=null;selectedDrawingId=null;dragAnchorIndex=-1;dragStartPoint=null;dragStartAnchors=[];dragBeforeState=null;eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;dataGetter=null;displayDataGetter=null;register(e){this.registry.set(e.descriptor.type,e)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setDataGetter(e){this.dataGetter=e}setDisplayDataGetter(e){this.displayDataGetter=e}snapToOHLC(e,t,n){if(this.magnetMode===`none`||!this.dataGetter)return{time:e,price:t};let r=this.displayDataGetter?.()??this.dataGetter();if(r.length===0)return{time:e,price:t};let i=!!(n?.data&&n.data.length>0),a=Math.max(0,Math.min(r.length-1,Math.round(i?l(e,r):e))),o=r[a],s=[o.open,o.high,o.low,o.close],c=s[0],u=Math.abs(t-c);for(let e=1;e<s.length;e++){let n=Math.abs(t-s[e]);n<u&&(u=n,c=s[e])}if(n){let e=n.chartRect.height/(n.priceRange.max-n.priceRange.min||1);if(u*e>30)return{time:i?o.time:a,price:t}}return{time:i?o.time:a,price:c}}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}applyUndoAction(e){switch(e.type){case`drawingCreate`:e.after&&(this.drawings=this.drawings.filter(t=>t.id!==e.after.id));break;case`drawingRemove`:e.before&&this.drawings.push(e.before);break;case`drawingModify`:if(e.before){let t=this.drawings.findIndex(t=>t.id===e.before.id);t>=0&&(this.drawings[t]=structuredClone(e.before))}break}this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}applyRedoAction(e){switch(e.type){case`drawingCreate`:e.after&&this.drawings.push(structuredClone(e.after));break;case`drawingRemove`:e.before&&(this.drawings=this.drawings.filter(t=>t.id!==e.before.id));break;case`drawingModify`:if(e.after){let t=this.drawings.findIndex(t=>t.id===e.after.id);t>=0&&(this.drawings[t]=structuredClone(e.after))}break}this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}lockAllDrawings(){for(let e of this.drawings)e.locked=!0;this.requestRender?.()}unlockAllDrawings(){for(let e of this.drawings)e.locked=!1;this.requestRender?.()}hideAllDrawings(){for(let e of this.drawings)e.visible=!1;this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}showAllDrawings(){for(let e of this.drawings)e.visible=!0;this.requestRender?.()}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.visible=t,!t&&this.selectedDrawingId===e&&(this.selectedDrawingId=null),this.requestRender?.(),t):null}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.locked=t,this.requestRender?.(),t):null}setActiveTool(e){this.activeTool=e,this.state=e?`creating`:`idle`,this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t??this.selectedDrawingId;if(!n)return!1;let r=this.drawings.find(e=>e.id===n);if(!r||r.locked)return!1;let i=H(r);return r.style={...r.style,...e},this.undoRedo?.push({type:`drawingModify`,before:i,after:H(r)}),this.requestRender?.(),!0}onPointerDown(e,t){return this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t):!1}onPointerMove(e,t){if(this.state===`creating`&&this.creatingDrawing){let n=this.registry.get(this.creatingDrawing.type);if(n&&this.committedAnchors<n.descriptor.requiredAnchors){let n=f(e.x,t),r=c(e.y,t);return this.previewAnchor=this.snapToOHLC(n,r,t),this.requestRender?.(),!0}}return this.state===`moving`&&this.selectedDrawingId&&this.dragStartPoint?this.handleMove(e,t):this.state===`resizing`&&this.selectedDrawingId&&this.dragAnchorIndex>=0?this.handleResize(e,t):!1}onPointerUp(){if(this.state===`moving`||this.state===`resizing`){if(this.dragBeforeState&&this.selectedDrawingId){let e=this.drawings.find(e=>e.id===this.selectedDrawingId);e&&this.undoRedo?.push({type:`drawingModify`,before:this.dragBeforeState,after:H(e)})}return this.state=`selected`,this.dragStartPoint=null,this.dragStartAnchors=[],this.dragAnchorIndex=-1,this.dragBeforeState=null,!0}return!1}onKeyDown(e,t=!1){if(t&&(e===`d`||e===`D`)&&this.state===`selected`&&this.selectedDrawingId&&this.duplicateDrawing(this.selectedDrawingId)||t&&(e===`z`||e===`Z`)&&this.undo()||t&&(e===`y`||e===`Y`)&&this.redo())return!0;if(e===`Escape`){if(this.state===`creating`)return this.setActiveTool(null),this.requestRender?.(),!0;if(this.state===`selected`)return this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.(),!0}return(e===`Delete`||e===`Backspace`)&&this.state===`selected`&&this.selectedDrawingId?this.drawings.find(e=>e.id===this.selectedDrawingId)?.locked?!1:(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.(),!0):!1}getDrawings(){return this.drawings}setDrawings(e){this.drawings=this.upgradeLegacyAnchors(e),this.requestRender?.()}addDrawing(e){let t=e.id??`tc_drawing_${V++}`,n={id:t,type:e.type,anchors:e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,meta:e.meta};return this.drawings=[...this.drawings,n],this.undoRedo?.push({type:`drawingCreate`,before:null,after:H(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();return!t||t.length===0?e:e.map(e=>({...e,anchors:e.anchors.map(e=>{if(e.time>=1e9)return e;let n=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[n].time}})}))}removeDrawing(e){let t=this.drawings.find(t=>t.id===e);this.drawings=this.drawings.filter(t=>t.id!==e),t&&this.undoRedo?.push({type:`drawingRemove`,before:structuredClone(t),after:null}),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=`tc_drawing_${V++}`;let r=this.computeBarOffsetTime(3);return n.anchors=n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selectedDrawingId=n.id,this.state=`selected`,this.eventCallback?.(`drawingCreate`,{drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.drawings=[],this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selectedDrawingId}render(e,t){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip();for(let n of this.drawings){if(!n.visible)continue;let r=this.registry.get(n.type);if(!r)continue;let i=n.id===this.selectedDrawingId;r.render(e,n,t,i)}if(this.creatingDrawing&&this.committedAnchors>0){let n=this.registry.get(this.creatingDrawing.type);if(n){let r={...this.creatingDrawing,anchors:this.previewAnchor?[...this.creatingDrawing.anchors,this.previewAnchor]:[...this.creatingDrawing.anchors]};n.render(e,r,t,!1)}}e.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}handleCreationClick(e,t){if(!this.activeTool)return!1;let n=this.registry.get(this.activeTool);if(!n)return!1;let r=f(e.x,t),i=c(e.y,t),a=this.snapToOHLC(r,i,t);return this.creatingDrawing?(this.creatingDrawing.anchors.push(a),this.committedAnchors++,this.previewAnchor=null,this.committedAnchors>=n.descriptor.requiredAnchors&&this.finalizeCreation(),this.requestRender?.(),!0):(this.creatingDrawing={id:`tc_drawing_${V++}`,type:this.activeTool,anchors:[a],style:{...this.activeStyle},visible:!0,locked:!1},this.committedAnchors=1,this.previewAnchor=null,n.descriptor.requiredAnchors===1&&this.finalizeCreation(),this.requestRender?.(),!0)}finalizeCreation(){this.creatingDrawing&&(this.drawings.push(this.creatingDrawing),this.selectedDrawingId=this.creatingDrawing.id,this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(this.creatingDrawing)}),this.eventCallback?.(`drawingCreate`,{drawing:this.creatingDrawing}),this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null,this.activeTool=null,this.state=`selected`)}handleSelectionClick(e,t){if(this.selectedDrawingId){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(n&&!n.locked){let r=this.registry.get(n.type);if(r){let i=r.hitTestAnchor(e,n,t,8);if(i>=0)return this.state=`resizing`,this.dragAnchorIndex=i,this.dragStartPoint=e,this.dragBeforeState=H(n),!0;if(r.hitTest(e,n,t,8))return this.state=`moving`,this.dragStartPoint=e,this.dragStartAnchors=n.anchors.map(e=>({...e})),this.dragBeforeState=H(n),!0}}}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!r.visible)continue;let i=this.registry.get(r.type);if(i&&i.hitTest(e,r,t,8))return this.selectedDrawingId=r.id,this.state=`selected`,this.requestRender?.(),!0}return this.selectedDrawingId&&(this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()),!1}handleMove(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(!n||!this.dragStartPoint)return!1;let r=f(e.x,t)-f(this.dragStartPoint.x,t),i=c(e.y,t)-c(this.dragStartPoint.y,t);return n.anchors=this.dragStartAnchors.map(e=>({time:e.time+r,price:e.price+i})),this.requestRender?.(),!0}handleResize(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);return!n||this.dragAnchorIndex<0?!1:(n.anchors[this.dragAnchorIndex]={time:f(e.x,t),price:c(e.y,t)},this.requestRender?.(),!0)}},jn=class{constructor(e){this.manager=e}render(e,t){this.manager.render(e,t)}};function Mn(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}var Nn=class extends B{descriptor={type:`trendLine`,name:`Trend Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},Pn=class extends B{descriptor={type:`horizontalLine`,name:`Horizontal Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=o(t.anchors[0].price,n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i),e.lineTo(a.x+a.width,i),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(t.anchors[0].price.toFixed(2),a.x+4,i-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=o(t.anchors[0].price,n);return Math.abs(e.y-i)<=r&&e.x>=n.chartRect.x&&e.x<=n.chartRect.x+n.chartRect.width}},Fn=class extends B{descriptor={type:`verticalLine`,name:`Vertical Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;return Math.abs(e.x-i.x)<=r&&e.y>=a.y&&e.y<=a.y+a.height}},In=class extends B{descriptor={type:`ray`,name:`Ray`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x+s/l*u,f=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(d,f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;return((e.x-i.x)*o+(e.y-i.y)*s)/(o*o+s*s)<0?!1:this.distanceToInfiniteLine(e,i,a)<=r}},Ln=class extends B{descriptor={type:`extendedLine`,name:`Extended Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x-s/l*u,f=i.y-c/l*u,p=i.x+s/l*u,m=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToInfiniteLine(e,i,a)<=r}},Rn=class extends B{descriptor={type:`parallelChannel`,name:`Parallel Channel`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),t.anchors.length>=3){let r=this.anchorToPixel(t.anchors[2],n),o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s)||1,l=-s/c,u=o/c,d=(r.x-i.x)*l+(r.y-i.y)*u,f={x:i.x+l*d,y:i.y+u*d},p={x:a.x+l*d,y:a.y+u*d};e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(p.x,p.y),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.lineTo(p.x,p.y),e.lineTo(f.x,f.y),e.closePath(),e.fill())}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.distanceToLine(e,i,a)<=r)return!0;if(t.anchors.length>=3){let o=this.anchorToPixel(t.anchors[2],n),s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c)||1,u=-c/l,d=s/l,f=(o.x-i.x)*u+(o.y-i.y)*d,p={x:i.x+u*f,y:i.y+d*f},m={x:a.x+u*f,y:a.y+d*f};if(this.distanceToLine(e,p,m)<=r)return!0}return!1}},zn=class extends B{descriptor={type:`regressionChannel`,name:`Regression Channel`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s);if(c===0){this.resetLineStyle(e);return}let l=Math.max(10,Math.min(c*.2,100)),u=-s/c*l,d=o/c*l;e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.stroke(),e.beginPath(),e.moveTo(i.x-u,i.y-d),e.lineTo(a.x-u,a.y-d),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.lineTo(a.x-u,a.y-d),e.lineTo(i.x-u,i.y-d),e.closePath(),e.fill()),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.hypot(a.x-i.x,a.y-i.y),s=Math.max(10,Math.min(o*.2,100));return this.distanceToLine(e,i,a)<=r+s}},U=[0,.236,.382,.5,.618,.786,1],Bn=class extends B{descriptor={type:`fibRetracement`,name:`Fibonacci Retracement`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`;for(let r of U){let a=s+c*(1-r),l=o(a,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.7,e.beginPath(),e.moveTo(i.x,l),e.lineTo(i.x+i.width,l),e.stroke(),e.fillStyle=t.style.color,e.textAlign=`left`,e.fillText(`${(r*100).toFixed(1)}% (${a.toFixed(2)})`,i.x+4,l-2)}if(e.globalAlpha=1,t.style.fillColor){for(let r=0;r<U.length-1;r++){let a=s+c*(1-U[r]),l=s+c*(1-U[r+1]),u=o(a,n),d=o(l,n);e.fillStyle=t.style.fillColor,e.globalAlpha=.05+r*.02,e.fillRect(i.x,Math.min(u,d),i.width,Math.abs(d-u))}e.globalAlpha=1}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;for(let t of U){let i=o(s+c*(1-t),n);if(Math.abs(e.y-i)<=r)return!0}return!1}},Vn=[0,.618,1,1.618,2,2.618,3.618,4.236],Hn=class extends B{descriptor={type:`fibExtension`,name:`Fibonacci Extension`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=t.anchors[2].price,l=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;for(let r of Vn){let a=o(c+l*r,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.6,e.beginPath(),e.moveTo(i.x,a),e.lineTo(i.x+i.width,a),e.stroke(),e.fillStyle=t.style.color,e.fillText(`${(r*100).toFixed(1)}%`,i.x+4,a-2)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price-t.anchors[1].price;for(let i of Vn){let s=o(t.anchors[2].price+a*i,n);if(Math.abs(e.y-s)<=r)return!0}return!1}},Un=class extends B{descriptor={type:`rectangle`,name:`Rectangle`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y);t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fillRect(o,s,c,l)),this.applyLineStyle(e,t.style),e.strokeRect(o,s,c,l),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.min(i.y,a.y)-r,c=Math.max(i.x,a.x)+r,l=Math.max(i.y,a.y)+r;if(e.x<o||e.x>c||e.y<s||e.y>l)return!1;let u=Math.min(i.x,a.x)+r,d=Math.min(i.y,a.y)+r,f=Math.max(i.x,a.x)-r,p=Math.max(i.y,a.y)-r;return!(e.x>u&&e.x<f&&e.y>d&&e.y<p)||!!t.style.fillColor}},Wn=class extends B{descriptor={type:`ellipse`,name:`Ellipse`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.abs(a.x-i.x)/2,l=Math.abs(a.y-i.y)/2;e.beginPath(),e.ellipse(o,s,Math.max(c,1),Math.max(l,1),0,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.max(Math.abs(a.x-i.x)/2,1),l=Math.max(Math.abs(a.y-i.y)/2,1),u=(e.x-o)/c,d=(e.y-s)/l,f=Math.sqrt(u*u+d*d),p=r/Math.max(Math.min(c,l),4);return t.style.fillColor?f<=1+p:Math.abs(f-1)<=p}},Gn=class extends B{descriptor={type:`triangle`,name:`Triangle`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=t.anchors.map(e=>this.anchorToPixel(e,n));e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.lineTo(i[2].x,i[2].y),e.closePath(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<3;t++){let n=(t+1)%3;if(this.distanceToLine(e,i[t],i[n])<=r)return!0}return!1}},Kn=class extends B{descriptor={type:`pitchfork`,name:`Andrews' Pitchfork`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s={x:(a.x+o.x)/2,y:(a.y+o.y)/2},c=s.x-i.x,l=s.y-i.y,u=Math.hypot(c,l)||1,d=Math.hypot(n.chartRect.width,n.chartRect.height),f=i.x+c/u*d,p=i.y+l/u*d;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(f,p),e.stroke(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x+c/u*d,a.y+l/u*d),e.stroke(),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x+c/u*d,o.y+l/u*d),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s={x:(a.x+o.x)/2,y:(a.y+o.y)/2};if(this.distanceToInfiniteLine(e,i,s)<=r)return!0;let c=s.x-i.x,l=s.y-i.y,u={x:a.x+c,y:a.y+l},d={x:o.x+c,y:o.y+l};return this.distanceToInfiniteLine(e,a,u)<=r||this.distanceToInfiniteLine(e,o,d)<=r}},qn=[`1`,`2`,`3`,`4`,`5`,`A`,`B`,`C`],Jn=class extends B{descriptor={type:`elliottWave`,name:`Elliott Wave`,requiredAnchors:8};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<i.length&&t<qn.length;t++){let n=t%2==0?-12:12;e.textBaseline=n<0?`bottom`:`top`,e.fillText(qn[t],i[t].x,i[t].y+n)}r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},Yn=class extends B{descriptor={type:`priceRange`,name:`Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.abs(a.x-i.x),c=Math.min(i.y,a.y),l=Math.abs(a.y-i.y),u=t.anchors[1].price>t.anchors[0].price;e.fillStyle=u?`rgba(38, 166, 154, 0.15)`:`rgba(239, 83, 80, 0.15)`,e.fillRect(o,c,s,l),this.applyLineStyle(e,t.style),e.strokeRect(o,c,s,l),this.resetLineStyle(e);let d=t.anchors[1].price-t.anchors[0].price,f=t.anchors[0].price===0?0:d/t.anchors[0].price*100,p=`${d>=0?`+`:``}${d.toFixed(2)} (${f>=0?`+`:``}${f.toFixed(2)}%)`;e.font=`12px sans-serif`,e.fillStyle=u?`#26A69A`:`#EF5350`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(p,o+s/2,c+l/2),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return e.x>=o-r&&e.x<=s+r&&e.y>=c-r&&e.y<=l+r}},Xn=class extends B{descriptor={type:`dateRange`,name:`Date Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);e.fillStyle=`rgba(33, 150, 243, 0.08)`,e.fillRect(s,o.y,c-s,o.height),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(c,o.y),e.lineTo(c,o.y+o.height),e.stroke(),this.resetLineStyle(e);let l=u(t.anchors[0].time,n),d=u(t.anchors[1].time,n),f=Math.max(0,Math.round(Math.abs(d-l)));e.font=`12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`,e.textBaseline=`top`,e.fillText(`${f} bars`,(s+c)/2,o.y+4),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);return e.x>=s-r&&e.x<=c+r&&e.y>=o.y&&e.y<=o.y+o.height}},Zn=class extends B{descriptor={type:`measure`,name:`Measure`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=t.anchors[1].price-t.anchors[0].price,s=u(t.anchors[0].time,n),c=u(t.anchors[1].time,n),l=Math.max(0,Math.round(Math.abs(c-s))),d=t.anchors[0].price===0?0:o/t.anchors[0].price*100,f=[`Price: ${o>=0?`+`:``}${o.toFixed(2)} (${d>=0?`+`:``}${d.toFixed(2)}%)`,`Bars: ${l}`],p=(i.x+a.x)/2,m=(i.y+a.y)/2;e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`bottom`;let h=Math.max(...f.map(t=>e.measureText(t).width));e.fillStyle=`rgba(0, 0, 0, 0.7)`,e.fillRect(p-h/2-6,m-f.length*14-4,h+12,f.length*14+8),e.fillStyle=`#FFFFFF`;for(let t=0;t<f.length;t++)e.fillText(f[t],p,m-(f.length-1-t)*14);r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}};function Qn(e,t=`Text`){if(typeof e.style.text==`string`&&e.style.text.length>0)return e.style.text;let n=e.meta?.text;return typeof n==`string`&&n.length>0?n:t}var $n=class extends B{descriptor={type:`text`,name:`Text`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=Qn(t),o=t.style.fontSize||14;if(e.font=`${o}px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`left`,e.textBaseline=`top`,r){let n=e.measureText(a);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.strokeRect(i.x-2,i.y-2,n.width+4,o+4),e.setLineDash([])}e.fillText(a,i.x,i.y),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=t.style.fontSize||14;return e.x>=i.x-r&&e.x<=i.x+80+r&&e.y>=i.y-r&&e.y<=i.y+a+r}},er=class extends B{descriptor={type:`arrow`,name:`Arrow`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=Math.atan2(a.y-i.y,a.x-i.x);e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x-12*Math.cos(o-Math.PI/6),a.y-12*Math.sin(o-Math.PI/6)),e.lineTo(a.x-12*Math.cos(o+Math.PI/6),a.y-12*Math.sin(o+Math.PI/6)),e.closePath(),e.fillStyle=t.style.color,e.fill(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},tr=[{label:`8x1`,ratio:8},{label:`4x1`,ratio:4},{label:`3x1`,ratio:3},{label:`2x1`,ratio:2},{label:`1x1`,ratio:1},{label:`1x2`,ratio:.5},{label:`1x3`,ratio:1/3},{label:`1x4`,ratio:.25},{label:`1x8`,ratio:.125}],nr=class extends B{descriptor={type:`gannFan`,name:`Gann Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;this.applyLineStyle(e,t.style);for(let{label:n,ratio:r}of tr){let a=c*r,o=d,s=i.y+a*(o-i.x);e.globalAlpha=r===1?1:.5,e.lineWidth=r===1?t.style.lineWidth:Math.max(.5,t.style.lineWidth*.7),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o,s),e.stroke();let f=o-l*4,p=s;p>u.y&&p<u.y+u.height&&(e.globalAlpha=.7,e.fillStyle=t.style.color,e.font=`9px sans-serif`,e.textAlign=l>0?`right`:`left`,e.textBaseline=`bottom`,e.fillText(n,f,p-2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return!1;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;for(let{ratio:t}of tr){let n=c*t,a=d,o=i.y+n*(a-i.x);if(this.distanceToLine(e,i,{x:a,y:o})<=r)return!0}return!1}},rr=[0,.25,.333,.5,.667,.75,1],ir=class extends B{descriptor={type:`gannBox`,name:`Gann Box`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y),u=s-o,d=l-c;if(!(u<2||d<2)){this.applyLineStyle(e,t.style),e.strokeRect(o,c,u,d),e.save(),e.globalAlpha=.35;for(let t of rr){if(t===0||t===1)continue;let n=c+d*t;e.beginPath(),e.moveTo(o,n),e.lineTo(s,n),e.stroke()}for(let t of rr){if(t===0||t===1)continue;let n=o+u*t;e.beginPath(),e.moveTo(n,c),e.lineTo(n,l),e.stroke()}e.globalAlpha=.5,e.setLineDash([4,3]),e.beginPath(),e.moveTo(o,c),e.lineTo(s,l),e.stroke(),e.beginPath(),e.moveTo(s,c),e.lineTo(o,l),e.stroke(),e.restore(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`8px sans-serif`,e.globalAlpha=.6,e.textBaseline=`bottom`,e.textAlign=`right`;for(let t of rr){if(t===0||t===1)continue;let n=c+d*t;e.fillText(`${(t*100).toFixed(0)}%`,o-3,n)}e.globalAlpha=1,r&&this.renderAnchorHandles(e,t,n)}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return Math.abs(e.x-o)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.x-s)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.y-c)<=r&&e.x>=o-r&&e.x<=s+r||Math.abs(e.y-l)<=r&&e.x>=o-r&&e.x<=s+r||this.distanceToLine(e,{x:o,y:c},{x:s,y:l})<=r||this.distanceToLine(e,{x:s,y:c},{x:o,y:l})<=r}},ar=class extends B{descriptor={type:`anchoredVWAP`,name:`Anchored VWAP`,requiredAnchors:1};dataGetter=null;showBands=!0;setDataGetter(e){this.dataGetter=e}setShowBands(e){this.showBands=e}render(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return;let i=this.dataGetter(),s=Math.max(0,Math.round(u(t.anchors[0].time,n)));if(s>=i.length)return;let{vwap:c,upper1:l,lower1:d,upper2:f,lower2:p}=this.computeVWAP(i,s),{chartRect:m}=n,h=n.barWidth+n.barSpacing;if(this.applyLineStyle(e,t.style),e.lineWidth=t.style.lineWidth+.5,this.drawLine(e,c,s,n,m,h),this.showBands&&c.length>1&&(e.globalAlpha=.4,e.lineWidth=Math.max(.5,t.style.lineWidth*.6),e.setLineDash([4,3]),this.drawLine(e,l,s,n,m,h),this.drawLine(e,d,s,n,m,h),e.globalAlpha=.25,this.drawLine(e,f,s,n,m,h),this.drawLine(e,p,s,n,m,h),e.globalAlpha=1),this.resetLineStyle(e),c.length>0){let r=c[c.length-1],i=a(s+c.length-1,n),l=o(r,n);i>=m.x&&i<=m.x+m.width&&(e.fillStyle=t.style.color,e.font=`bold 9px sans-serif`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`AVWAP ${r.toFixed(2)}`,i+6,l))}r&&this.renderAnchorHandles(e,t,n)}drawLine(e,t,n,r,i,s){e.beginPath();let c=!1;for(let l=0;l<t.length;l++){let u=a(n+l,r);if(u<i.x-s)continue;if(u>i.x+i.width+s)break;let d=o(t[l],r);c?e.lineTo(u,d):(e.moveTo(u,d),c=!0)}e.stroke()}computeVWAP(e,t){let n=e.length-t,r=Array(n),i=Array(n),a=Array(n),o=Array(n),s=Array(n),c=0,l=0,u=0;for(let d=0;d<n;d++){let n=e[t+d],f=(n.high+n.low+n.close)/3,p=n.volume??1;c+=f*p,l+=p,u+=f*f*p;let m=l>0?c/l:f;r[d]=m;let h=l>0?u/l-m*m:0,g=Math.sqrt(Math.max(0,h));i[d]=m+g,a[d]=m-g,o[d]=m+2*g,s[d]=m-2*g}return{vwap:r,upper1:i,lower1:a,upper2:o,lower2:s}}hitTest(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return!1;let i=this.dataGetter(),s=Math.max(0,Math.round(u(t.anchors[0].time,n)));if(s>=i.length)return!1;let{vwap:c}=this.computeVWAP(i,s);for(let t=1;t<c.length;t++){let i=a(s+t-1,n),l=o(c[t-1],n),u=a(s+t,n),d=o(c[t],n);if(this.distanceToLine(e,{x:i,y:l},{x:u,y:d})<=r)return!0}return!1}},or=class extends B{descriptor={type:`volumeProfileRange`,name:`Volume Profile (Range)`,requiredAnchors:2};dataGetter=null;numBins=40;setDataGetter(e){this.dataGetter=e}render(e,t,n,r){if(t.anchors.length<2||!this.dataGetter)return;let i=this.dataGetter(),s=Math.round(u(t.anchors[0].time,n)),c=Math.round(u(t.anchors[1].time,n)),l=Math.max(0,Math.min(s,c)),d=Math.min(i.length-1,Math.max(s,c));if(l>=i.length||d<0||l>d)return;let f=1/0,p=-1/0;for(let e=l;e<=d;e++)i[e].low<f&&(f=i[e].low),i[e].high>p&&(p=i[e].high);if(f>=p)return;let m=(p-f)/this.numBins,h=new Float64Array(this.numBins),g=0;for(let e=l;e<=d;e++){let t=i[e],n=t.volume??1,r=Math.max(0,Math.floor((t.low-f)/m)),a=Math.min(this.numBins-1,Math.floor((t.high-f)/m)),o=n/(a-r+1);for(let e=r;e<=a;e++)h[e]+=o,h[e]>g&&(g=h[e])}if(g===0)return;let _=0;for(let e=1;e<this.numBins;e++)h[e]>h[_]&&(_=e);let v=a(d,n)+n.barWidth,y=t.style.color,b=t.style.fillColor??`#FF9800`;e.save();for(let t=0;t<this.numBins;t++){let r=h[t]/g*100,i=f+(t+1)*m,a=f+t*m,s=o(i,n),c=o(a,n),l=Math.abs(c-s);e.globalAlpha=.35,e.fillStyle=t===_?b:y,e.fillRect(v,Math.min(s,c),r,Math.max(1,l-.5))}let x=f+(_+.5)*m,S=o(x,n);e.globalAlpha=.7,e.strokeStyle=b,e.lineWidth=1,e.setLineDash([4,3]),e.beginPath();let C=a(l,n)-n.barWidth/2;e.moveTo(C,S),e.lineTo(v+100,S),e.stroke(),e.fillStyle=b,e.font=`9px sans-serif`,e.textAlign=`left`,e.textBaseline=`bottom`,e.globalAlpha=.8,e.fillText(`POC ${x.toFixed(2)}`,v+100+4,S-2),e.restore(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.max(i.x,a.x)+100+r,c=Math.min(i.y,a.y)-r,l=Math.max(i.y,a.y)+r;return e.x>=o&&e.x<=s&&e.y>=c&&e.y<=l}},sr=[1,2,3,5,8,13,21,34,55],cr=class extends B{descriptor={type:`fibTimeZones`,name:`Fibonacci Time Zones`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return;let{chartRect:o}=n;e.font=`11px sans-serif`,e.textBaseline=`top`,e.textAlign=`center`,this.applyLineStyle(e,t.style);for(let r of sr){let s=d(i.time+a*r,n);s<o.x||s>o.x+o.width||(e.globalAlpha=r===1?1:.55,e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.fillStyle=t.style.color,e.fillText(String(r),s,o.y+2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return!1;let{chartRect:o}=n;if(e.y<o.y||e.y>o.y+o.height)return!1;for(let t of sr){let o=d(i.time+a*t,n);if(Math.abs(e.x-o)<=r)return!0}return!1}};function lr(e){e.register(new Nn),e.register(new Pn),e.register(new Fn),e.register(new In),e.register(new Ln),e.register(new Rn),e.register(new zn),e.register(new Bn),e.register(new Hn),e.register(new Un),e.register(new Wn),e.register(new Gn),e.register(new Kn),e.register(new Jn),e.register(new Yn),e.register(new Xn),e.register(new Zn),e.register(new $n),e.register(new er),e.register(new nr),e.register(new ir),e.register(new ar),e.register(new or),e.register(new cr)}var ur=class{render(e,t,n,r,i,a){let s=i.orderColors?.buy??`#26A69A`,c=i.orderColors?.sell??`#EF5350`,{chartRect:l}=n;for(let i of t){let t=a?.orderId===i.id&&a.sourceType===`order`,u=o(t?a.currentPrice:i.price,n);if(u<l.y||u>l.y+l.height)continue;let d=i.side===`buy`?s:c;e.setLineDash([6,4]),e.strokeStyle=d,e.lineWidth=1,e.beginPath(),e.moveTo(l.x,Math.round(u)+.5),e.lineTo(l.x+l.width,Math.round(u)+.5),e.stroke(),e.setLineDash([]);let f=i.label??i.type.toUpperCase();e.font=`bold 10px ${r.font.family}`;let p=e.measureText(f).width+8;e.fillStyle=d,e.fillRect(l.x+4,u-8,p,16),e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(f,l.x+8,u);let m=l.x+4+p+6;if(e.fillStyle=d,e.beginPath(),i.side===`buy`?(e.moveTo(m,u+4),e.lineTo(m+5,u-2),e.lineTo(m+10,u+4)):(e.moveTo(m,u-4),e.lineTo(m+5,u+2),e.lineTo(m+10,u-4)),e.fill(),t){let t=o(a.startPrice,n);e.setLineDash([2,4]),e.strokeStyle=d,e.globalAlpha=.3,e.beginPath(),e.moveTo(l.x,Math.round(t)+.5),e.lineTo(l.x+l.width,Math.round(t)+.5),e.stroke(),e.globalAlpha=1,e.setLineDash([])}}}renderAxisBadges(t,n,r,i,a,s){let c=a.orderColors?.buy??`#26A69A`,l=a.orderColors?.sell??`#EF5350`,u=a.pricePrecision??2,{chartRect:d}=r,f=d.x+d.width+1;for(let a of n){let n=s?.orderId===a.id&&s.sourceType===`order`?s.currentPrice:a.price,p=o(n,r);if(p<d.y||p>d.y+d.height)continue;let m=a.side===`buy`?c:l,h=`${n.toFixed(u)} x ${a.quantity}`;t.font=`11px ${i.font.family}`;let g=t.measureText(h).width+10;t.fillStyle=m,t.fillRect(f,p-9,Math.min(g,e.PRICE_AXIS_WIDTH-2),18),t.fillStyle=`#FFFFFF`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(h,f+5,p)}}hitTest(e,t,n,r){for(let i of t){if(i.draggable===!1)continue;let t=o(i.price,n);if(Math.abs(e-t)<=r)return i}return null}};function dr(e,t,n){let r=Math.min(Math.max(e.closedQuantity??0,0),e.quantity),i=e.quantity-r,a=e.side===`buy`?1:-1,o=(t-e.entryPrice)*i*a,s=e.entryPrice===0?0:(t-e.entryPrice)/e.entryPrice*100*a;return{side:e.side,quantity:e.quantity,closedQuantity:r,openQuantity:i,entryPrice:e.entryPrice,currentPrice:t,pnl:o,pnlPct:s,precision:n}}var fr=/\{(side|qty|closedQty|openQty|entry|price|pnl|pnlPct|pnlSign)\}/g;function pr(e,t){return e.replace(fr,(e,n)=>{switch(n){case`side`:return t.side.toUpperCase();case`qty`:return String(t.quantity);case`closedQty`:return String(t.closedQuantity);case`openQty`:return String(t.openQuantity);case`entry`:return t.entryPrice.toFixed(t.precision);case`price`:return t.currentPrice.toFixed(t.precision);case`pnl`:return t.pnl.toFixed(t.precision);case`pnlPct`:return`${t.pnlPct.toFixed(2)}%`;case`pnlSign`:return t.pnl>=0?`+`:``;default:return``}})}function mr(e,t){return typeof e==`function`?e(t):pr(e??`{side} {qty} | P&L: {pnlSign}{pnl}`,t)}function hr(e,t,n){if(!t||t.length===0)return n;let r=[...t].sort((e,t)=>e.pnl-t.pnl),i;for(let t of r)if(e>=t.pnl)i=t.color;else break;return i??n}var gr=class{render(e,t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.profit??`#26A69A`,l=a.positionColors?.loss??`#EF5350`,u=a.positionColors?.entry??`#2196F3`,d=a.pricePrecision??2;for(let f of t){let t=o(f.entryPrice,r);if(e.strokeStyle=u,e.lineWidth=1.5,e.setLineDash([]),e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),n!==null){let p=o(n,r),m=dr(f,n,d),h=m.pnl,g=h>=0?c:l,_=hr(h,a.pnlThresholds,g);e.fillStyle=_,e.globalAlpha=.08;let v=Math.min(t,p),y=Math.abs(p-t);if(e.fillRect(s.x,v,s.width,y),e.globalAlpha=1,m.closedQuantity>0&&f.quantity>0){let t=m.closedQuantity/f.quantity;e.fillStyle=u,e.globalAlpha=.25,e.fillRect(s.x,v,Math.max(2,s.width*t*.04)+2,y),e.globalAlpha=1}let b=mr(a.positionLabel,m);e.font=`bold 11px ${i.font.family}`;let x=e.measureText(b).width+12,S=s.x+8;e.fillStyle=_,e.globalAlpha=.9,e.fillRect(S,t-10,x,20),e.globalAlpha=1,e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(b,S+6,t)}if(f.stopLoss!==void 0){let t=o(f.stopLoss,r);e.setLineDash([4,4]),e.strokeStyle=l,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=l,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`SL`,s.x+8,t)}if(f.takeProfit!==void 0){let t=o(f.takeProfit,r);e.setLineDash([4,4]),e.strokeStyle=c,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=c,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`TP`,s.x+8,t)}e.setLineDash([])}}renderAxisBadges(t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.entry??`#2196F3`,l=a.pricePrecision??2,u=s.x+s.width+1;for(let a of n){let n=o(a.entryPrice,r);t.fillStyle=c,t.fillRect(u,n-9,e.PRICE_AXIS_WIDTH-2,18),t.fillStyle=`#FFFFFF`,t.font=`11px ${i.font.family}`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(a.entryPrice.toFixed(l),u+5,n)}}},_r=class{render(e,t,n,r){if(!r.depthOverlay?.enabled)return;let{chartRect:i}=n,a=r.depthOverlay.bidColor??`rgba(38,166,154,0.15)`,s=r.depthOverlay.askColor??`rgba(239,83,80,0.15)`,c=r.depthOverlay.maxWidth??100,l=0,u=[],d=0;for(let e of t.bids)d+=e.volume,u.push({price:e.price,cumVol:d}),d>l&&(l=d);let f=[];d=0;for(let e of t.asks)d+=e.volume,f.push({price:e.price,cumVol:d}),d>l&&(l=d);if(l===0)return;let p=Math.max(1,t.bids.length>1?Math.abs(o(t.bids[0].price,n)-o(t.bids[1].price,n)):4),m=i.x+i.width;e.fillStyle=a;for(let{price:t,cumVol:r}of u){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}e.fillStyle=s;for(let{price:t,cumVol:r}of f){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}}},vr=class{dragState=null;startY=0;dragging=!1;constructor(e=3){this.dragThreshold=e}onPointerDown(e,t,n,r,i){for(let n of t){if(n.draggable===!1)continue;let t=o(n.price,r);if(Math.abs(e.y-t)<=i)return this.dragState={orderId:n.id,sourceType:`order`,startPrice:n.price,currentPrice:n.price},this.startY=e.y,this.dragging=!1,!0}for(let t of n){if(t.stopLoss!==void 0){let n=o(t.stopLoss,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`stopLoss`,startPrice:t.stopLoss,currentPrice:t.stopLoss},this.startY=e.y,this.dragging=!1,!0}if(t.takeProfit!==void 0){let n=o(t.takeProfit,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`takeProfit`,startPrice:t.takeProfit,currentPrice:t.takeProfit},this.startY=e.y,this.dragging=!1,!0}}return!1}onPointerMove(e,t){if(!this.dragState)return!1;if(!this.dragging){if(Math.abs(e.y-this.startY)<this.dragThreshold)return!0;this.dragging=!0}return this.dragState.currentPrice=c(e.y,t),!0}onPointerUp(){if(!this.dragState)return null;let e=this.dragState;return this.dragState=null,this.dragging?(this.dragging=!1,{sourceType:e.sourceType,id:e.orderId,newPrice:e.currentPrice,previousPrice:e.startPrice}):null}getDragState(){return this.dragState}isActive(){return this.dragState!==null}},yr=class{menuElement=null;removeHandler=null;onItemSelect=null;show(e,t,n,r){if(this.hide(),!r.contextMenu?.enabled)return;let i=r.pricePrecision??2,a=t.toFixed(i),o=document.createElement(`div`);o.style.cssText=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@tradecanvas/commons`);var t=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.remove()}},n=class{layers=new Map;constructor(e){this.container=e}createLayers(){this.destroy();for(let n of[e.LayerType.Background,e.LayerType.Main,e.LayerType.Overlay,e.LayerType.UI])this.layers.set(n,new t(this.container,n))}getLayer(e){return this.layers.get(e)}resize(e,t){for(let n of this.layers.values())n.resize(e,t)}destroy(){for(let e of this.layers.values())e.destroy();this.layers.clear()}},r=class{animFrameId=0;running=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(e.LayerType.Background),this.dirtyLayers.add(e.LayerType.Main),this.dirtyLayers.add(e.LayerType.Overlay),this.dirtyLayers.add(e.LayerType.UI),this.running&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},i=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;constructor(e){this.container=e,this.currentDpr=window.devicePixelRatio||1,this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.currentDpr=window.devicePixelRatio||1;let e=this.container.clientWidth,t=this.container.clientHeight;e===this.cachedSize.width&&t===this.cachedSize.height||(this.cachedSize={width:e,height:t},this.callback?.(this.cachedSize,this.currentDpr))}))}),this.observer.observe(this.container)}destroy(){this.observer?.disconnect(),this.observer=null,this.callback=null}};function a(e,t){return e*(t.barWidth+t.barSpacing)-t.offset+t.chartRect.x+t.barWidth/2}function o(e,t){let{min:n,max:r}=t.priceRange;if(t.logScale&&n>0&&r>0){let i=Math.log(n),a=Math.log(r)-i;if(a===0)return t.chartRect.y+t.chartRect.height/2;let o=(Math.log(Math.max(e,2**-52))-i)/a;return t.chartRect.y+t.chartRect.height*(1-o)}let i=r-n;if(i===0)return t.chartRect.y+t.chartRect.height/2;let a=(e-n)/i;return t.chartRect.y+t.chartRect.height*(1-a)}function s(e,t){let n=t.barWidth+t.barSpacing;return Math.round((e-t.chartRect.x-t.barWidth/2+t.offset)/n)}function c(e,t){let{min:n,max:r}=t.priceRange,i=1-(e-t.chartRect.y)/t.chartRect.height;if(t.logScale&&n>0&&r>0){let e=Math.log(n);return Math.exp(e+(Math.log(r)-e)*i)}return n+(r-n)*i}function l(e,t){if(t.length===0)return-1;if(e<=t[0].time)return 0;if(e>=t[t.length-1].time)return t.length-1;let n=0,r=t.length-1;for(;n<=r;){let i=n+r>>>1;if(t[i].time===e)return i;t[i].time<e?n=i+1:r=i-1}if(n>=t.length)return t.length-1;if(r<0)return 0;let i=t[r].time,a=t[n].time,o=a===i?0:(e-i)/(a-i);return r+o}function u(e,t){let n=t.data;return n&&n.length>0?l(e,n):e}function d(e,t){return a(u(e,t),t)}function f(e,t){let n=s(e,t),r=t.data;return r&&r.length>0?r[Math.max(0,Math.min(r.length-1,n))].time:n}var p=class{layerManager;renderLoop;dprManager;renderCtx=null;bgLayer;mainLayer;overlayLayer;uiLayer;onContainerResize=null;constructor(e){this.layerManager=new n(e),this.renderLoop=new r,this.dprManager=new i(e),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let t=this.dprManager.getContainerSize(),a=this.dprManager.getDpr();this.layerManager.resize(t,a)}cacheLayerRefs(){this.bgLayer=this.layerManager.getLayer(e.LayerType.Background),this.mainLayer=this.layerManager.getLayer(e.LayerType.Main),this.overlayLayer=this.layerManager.getLayer(e.LayerType.Overlay),this.uiLayer=this.layerManager.getLayer(e.LayerType.UI)}setRenderContext(e){this.renderCtx=e}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(t){let n=this.renderCtx;if(!n)return;let{viewport:r,theme:i,data:l}=n,u=n.numberLocale??`en-US`;if(!(r.chartRect.width<=0||r.chartRect.height<=0)){if(t.has(e.LayerType.Background)&&this.bgLayer&&(this.bgLayer.clear(),n.gridRenderer?.render(this.bgLayer.ctx,r,i),n.sessionShading?.render(this.bgLayer.ctx,l,r,i),n.sessionBreaks?.render(this.bgLayer.ctx,r,i,l),n.watermark?.render(this.bgLayer.ctx,r,i)),t.has(e.LayerType.Main)&&this.mainLayer){this.mainLayer.clear();let e=this.mainLayer.ctx;e.save(),e.beginPath(),e.rect(r.chartRect.x,r.chartRect.y,r.chartRect.width,r.chartRect.height),e.clip(),n.depthHeatmap?.render(e,r,i),n.volumeRenderer?.render(e,l,r,i),n.volumeProfile?.render(e,l,r,i),n.marketProfile?.render(e,l,r,i),n.chartRenderer?.render(e,l,r,i),n.compareRenderer?.render(e,l,r,i),n.indicatorEngine?.renderOverlays(e,r),n.periodLevels?.render(e,l,r,i),n.pivotMarkers?.render(e,l,r,i),n.renderOverlayPlugins?.(e,`main`),e.restore();let t=n.panels,a=n.indicatorEngine;if(a&&t.length>0){let n=`10px ${i.font.family}`,r=a.getPanelIndicators(),o=new Map;for(let e of r)o.set(e.instanceId,e);for(let r of t){if(r.rect.width<=0||r.rect.height<=0)continue;e.save(),e.beginPath(),e.rect(r.rect.x,r.rect.y,r.rect.width,r.rect.height),e.clip(),e.fillStyle=i.background,e.fillRect(r.rect.x,r.rect.y,r.rect.width,r.rect.height),e.fillStyle=i.axisLine,e.fillRect(r.rect.x,r.rect.y,r.rect.width,3),e.fillStyle=i.textSecondary,e.font=n,e.textBaseline=`top`,e.textAlign=`left`;let t=o.get(r.instanceId);t&&e.fillText(t.descriptor.name,r.rect.x+6,r.rect.y+6),e.save(),e.beginPath(),e.rect(r.rect.x,r.rect.y+20,r.rect.width,r.rect.height-20),e.clip(),a.renderPanel(e,r.instanceId,r.viewport),e.restore(),e.restore()}}}if(t.has(e.LayerType.Overlay)&&this.overlayLayer){this.overlayLayer.clear();let e=this.overlayLayer.ctx;n.priceLimits&&this.renderPriceLimits(e,r,i,n.priceLimits),n.tradeZoneManager?.render(e,r,i),n.drawingRenderer?.render(e,r),n.tradingRenderer?.render(e,r,i),n.signalMarkerManager?.render(e,r,i),n.alertManager?.render(e,r,i),n.measureOverlay?.render(e,r,i),n.crosshairHandler?.render(e,r,i),n.renderOverlayPlugins?.(e,`overlay`);let t=n.crosshairHandler?.getPosition();if(t&&n.panels.length>0)for(let r of n.panels){let o=r.rect;if(t.x>=o.x&&t.x<=o.x+o.width&&t.y>=o.y&&t.y<=o.y+o.height){let c=r.viewport,l=t.x,u=s(l,c);l=a(Math.max(0,Math.min((n.data?.length??1)-1,Math.round(u))),c),e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),e.setLineDash([4,4]),e.strokeStyle=i.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(l)+.5,o.y),e.lineTo(Math.round(l)+.5,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(o.x,Math.round(t.y)+.5),e.lineTo(o.x+o.width,Math.round(t.y)+.5),e.stroke(),e.setLineDash([]),e.restore();break}}}if(t.has(e.LayerType.UI)&&this.uiLayer){this.uiLayer.clear();let t=this.uiLayer.ctx;if(n.priceAxis?.render(t,r,i),n.tradingRenderer?.renderAxisBadges(t,r,i),n.currentPriceLine?.render(t,r,i),n.timeAxis?.render(t,r,i,l,n.timeAxisY),n.crosshairHandler?.renderAxisLabels(t,r,i,l,n.timeAxisY),n.chartLegend?.render(t,r,i,l),n.barCountdown?.render(t,r,i,l),n.renderOverlayPlugins?.(t,`ui`),n.panels.length>0){let r=n.crosshairHandler?.getPosition(),a=n.indicatorEngine,d=`${i.font.sizeSmall}px ${i.font.family}`,f;if(a){let e=a.getPanelIndicators();f=new Map;for(let t of e)f.set(t.instanceId,t)}for(let p of n.panels){let n=p.viewport,m=p.rect,{min:h,max:g}=n.priceRange;if(g-h<=0||m.height<=0)continue;let _=m.x+m.width,v=n.chartRect;t.strokeStyle=i.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(_+.5,m.y),t.lineTo(_+.5,m.y+m.height),t.stroke();let y=(0,e.computeTickStep)(h,g,4),b=Math.ceil(h/y)*y,x=y<1?Math.ceil(-Math.log10(y))+1:+(y<10);t.font=d,t.textBaseline=`middle`,t.textAlign=`left`;for(let r=b;r<=g;r+=y){let a=o(r,n);a<v.y||a>v.y+v.height||(t.strokeStyle=i.axisLine,t.beginPath(),t.moveTo(_,Math.round(a)+.5),t.lineTo(_+4,Math.round(a)+.5),t.stroke(),t.fillStyle=i.axisLabel,t.fillText((0,e.formatPrice)(r,x,u),_+6,a))}if(r&&r.x>=m.x&&r.x<=m.x+m.width&&r.y>=m.y&&r.y<=m.y+m.height){let a=(0,e.formatPrice)(c(r.y,n),x,u);t.font=`bold ${i.font.sizeSmall}px ${i.font.family}`;let o=t.measureText(a).width,s=Math.min(o+10,e.PRICE_AXIS_WIDTH-2);t.fillStyle=i.crosshair,t.fillRect(_+1,r.y-9,s,18),t.fillStyle=i.background,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(a,_+5,r.y)}if(r&&a){let e=s(r.x,n),o=Math.max(0,Math.min((l?.length??1)-1,Math.round(e))),c=a.getOutput(p.instanceId);if(c?.series&&o<c.series.length){let e=c.series[o];if(e){let n=[];for(let t in e){let r=e[t];r!==void 0&&n.push(`${t}: ${r.toFixed(x)}`)}if(n.length>0){let e=f?.get(p.instanceId),r=e?t.measureText(e.descriptor.name).width+14:10;t.font=d,t.fillStyle=i.textSecondary,t.textBaseline=`top`,t.textAlign=`left`,t.fillText(n.join(` `),m.x+r,m.y+6)}}}}}}}}}renderPriceLimits(t,n,r,i){let{chartRect:a}=n,s=[{price:i.ceiling,color:i.colors?.ceiling??`#FF00FF`,label:`CE`},{price:i.floor,color:i.colors?.floor??`#00FFFF`,label:`FL`},{price:i.reference,color:i.colors?.reference??`#FFD700`,label:`REF`}],c=`bold 9px ${r.font.family}`,l=`10px ${r.font.family}`;for(let{price:r,color:i,label:u}of s){let s=o(r,n);if(s<a.y||s>a.y+a.height)continue;t.setLineDash([8,4]),t.strokeStyle=i,t.lineWidth=1,t.beginPath(),t.moveTo(a.x,Math.round(s)+.5),t.lineTo(a.x+a.width,Math.round(s)+.5),t.stroke(),t.setLineDash([]),t.font=c,t.fillStyle=i,t.textBaseline=`bottom`,t.textAlign=`left`,t.fillText(`${u} ${r.toFixed(2)}`,a.x+4,s-2);let d=a.x+a.width+1;t.fillStyle=i,t.fillRect(d,s-7,e.PRICE_AXIS_WIDTH-2,14),t.fillStyle=`#000`,t.font=l,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(r.toFixed(2),d+4,s)}}destroy(){this.renderLoop.stop(),this.dprManager.destroy(),this.layerManager.destroy()}},m=class{state;dataLength=0;minBarWidth;maxBarWidth;rightMarginBars;constructor(t,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(t,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:e.DEFAULT_BAR_WIDTH,barSpacing:e.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return{visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline}}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setScaleBaseline(e){this.state.scaleBaseline=e}setRightMargin(e){this.rightMarginBars=e}computeChartRect(t,n){return{x:0,y:0,width:Math.max(0,t-e.PRICE_AXIS_WIDTH),height:Math.max(0,n-e.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.clampOffset(),this.updateVisibleRange()}updateData(t,n){this.dataLength=t.length,this.dataLength!==0&&(this.clampOffset(),this.updateVisibleRange(),n&&(this.state.priceRange=(0,e.computePriceRange)(t,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),.08)))}setPriceRange(e,t){this.state.priceRange={min:e,max:t}}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a}}scrollBy(e){this.state.offset+=e,this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=e/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)};return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a}}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing,t=this.rightMarginBars*e,n=this.dataLength*e-this.state.chartRect.width+t;return this.state.offset>=n-e*2}scrollToEnd(){let e=this.state.barWidth+this.state.barSpacing,t=this.rightMarginBars*e,n=this.dataLength*e;this.state.offset=n-this.state.chartRect.width+t,this.updateVisibleRange()}zoom(t,n){let r=this.state.barWidth,i=(0,e.clamp)(r*(1+t),this.minBarWidth,this.maxBarWidth);if(i===r)return;let a=this.state.barWidth+this.state.barSpacing,o=(this.state.offset+n)/a;this.state.barWidth=i;let s=i+this.state.barSpacing;this.state.offset=o*s-n,this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let t=this.state.barWidth+this.state.barSpacing,n=this.dataLength*t,r=this.rightMarginBars*t,i=n-this.state.chartRect.width+r,a,o;if(i>0)a=-(this.state.chartRect.width*.5),o=i;else{let e=this.state.chartRect.width*.5;a=i-e,o=i+e}this.state.offset=(0,e.clamp)(this.state.offset,a,o)}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)}}};function h(t,n){return(0,e.sliceVisibleData)(t,n.visibleRange.from,n.visibleRange.to)}var g=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=g(n.high),a=g(n.low),c=g(n.open),l=g(n.close),u=n.close>=n.open,d=u?_:v;d.moveTo(r,i),d.lineTo(r,a);let f=u?l:c,p=Math.max(Math.abs(l-c),1);(u?y:b).rect(r-s,f,o,p)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(_),e.strokeStyle=r.candleDownWick,e.stroke(v),e.fillStyle=r.candleUp,e.fill(y),e.fillStyle=r.candleDown,e.fill(b)}};function _(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var v=64;function y(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(v,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=_(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var b=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,s=-n.offset+n.chartRect.x+n.barWidth/2,{min:c,max:l}=n.priceRange,u=l-c;if(u===0)return;let d=n.chartRect.y,f=n.chartRect.height/u;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let p=y(i,a,t.length,n.chartRect.width,e=>t[e].close),m=!1;for(let n of p){let r=n*o+s,i=d+(l-t[n].close)*f;m?e.lineTo(r,i):(e.moveTo(r,i),m=!0)}e.stroke()}},x=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,s=-n.offset+n.chartRect.x+n.barWidth/2,{min:c,max:l}=n.priceRange,u=l-c;if(u===0)return;let d=n.chartRect.y,f=n.chartRect.height,p=f/u,m=d+f,h=y(i,a,t.length,n.chartRect.width,e=>t[e].close);if(h.length===0)return;let g=h[0],_=g*o+s,v=d+(l-t[g].close)*p,b=e.createLinearGradient(0,d,0,m);b.addColorStop(0,r.areaTopColor),b.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(_,m),e.lineTo(_,v);let x=_;for(let n=1;n<h.length;n++){let r=h[n];x=r*o+s,e.lineTo(x,d+(l-t[r].close)*p)}e.lineTo(x,m),e.closePath(),e.fillStyle=b,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`,e.moveTo(_,v);for(let n=1;n<h.length;n++){let r=h[n];e.lineTo(r*o+s,d+(l-t[r].close)*p)}e.stroke()}},S=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open?_:v,a=g(n.high),o=g(n.low),c=g(n.open),l=g(n.close);i.moveTo(r,a),i.lineTo(r,o),i.moveTo(r-s,c),i.lineTo(r,c),i.moveTo(r,l),i.lineTo(r+s,l)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v)}},C=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=[],b=[],x=new Path2D,S=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=e===0||n.close>=t[e-1].close,c=g(n.high),l=g(n.low),u=g(n.open),d=g(n.close),f=Math.min(u,d),p=Math.max(Math.abs(d-u),1),m=a?_:v;m.moveTo(r,c),m.lineTo(r,l),i?(a?y:b).push({x:r-s,y:f,w:o,h:p}):(a?x:S).rect(r-s,f,o,p)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v),e.fillStyle=r.candleUp,e.fill(x),e.fillStyle=r.candleDown,e.fill(S),e.lineWidth=1.5,e.strokeStyle=r.candleUp;for(let t of y)e.strokeRect(t.x,t.y,t.w,t.h);e.strokeStyle=r.candleDown;for(let t of b)e.strokeRect(t.x,t.y,t.w,t.h)}},w=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=g(this.baselinePrice??this.computeBaseline(t,i,a)),{chartRect:v}=n,y=[],b=[];for(let e=i;e<=a&&e<t.length;e++)y.push(h(e)),b.push(g(t[e].close));if(y.length<2)return;let x=y.length-1;e.save();let S=new Path2D;S.rect(v.x,v.y,v.width,_-v.y),e.clip(S);let C=new Path2D;C.moveTo(y[0],_);for(let e=0;e<=x;e++)C.lineTo(y[e],b[e]);C.lineTo(y[x],_),C.closePath(),e.fillStyle=`${r.candleUp}20`,e.fill(C),e.restore(),e.save();let w=new Path2D;w.rect(v.x,_,v.width,v.y+v.height-_),e.clip(w);let T=new Path2D;T.moveTo(y[0],_);for(let e=0;e<=x;e++)T.lineTo(y[e],b[e]);T.lineTo(y[x],_),T.closePath(),e.fillStyle=`${r.candleDown}20`,e.fill(T),e.restore();let E=new Path2D,D=new Path2D;for(let e=1;e<=x;e++){let t=b[e]<=_?E:D;t.moveTo(y[e-1],b[e-1]),t.lineTo(y[e],b[e])}e.lineWidth=2,e.strokeStyle=r.candleUp,e.stroke(E),e.strokeStyle=r.candleDown,e.stroke(D),e.setLineDash([6,4]),e.strokeStyle=r.textSecondary,e.lineWidth=1;let O=new Path2D;O.moveTo(v.x,_),O.lineTo(v.x+v.width,_),e.stroke(O),e.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},T=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=g(Math.max(n.open,n.close)),c=g(Math.min(n.open,n.close)),l=Math.max(c-a,1),u=r-s;i?(_.rect(u,a,o,l),y.rect(u,a,o,l)):(v.rect(u,a,o,l),b.rect(u,a,o,l))}e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v),e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},E=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,o=g(n.high),s=g(n.low),c=i?_:v;if(c.moveTo(r,o),c.lineTo(r,s),e<a&&e+1<t.length){let t=h(e+1),n=i?s:o;c.moveTo(r,n),c.lineTo(t,n)}}e.strokeStyle=r.candleUp,e.lineWidth=3,e.stroke(_),e.strokeStyle=r.candleDown,e.lineWidth=1,e.stroke(v)}},D=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,s=o/2,c=o+n.barSpacing,l=-n.offset+n.chartRect.x+s,{min:u,max:d}=n.priceRange,f=d-u;if(f===0)return;let p=n.chartRect.y,m=n.chartRect.height/f,h=e=>e*c+l,g=e=>p+(d-e)*m,_=Math.abs(this.boxSize*m),v=Math.min(s*.8,_*.8)*.5,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=n.high,o=n.low,s=Math.max(1,Math.round((a-o)/this.boxSize));for(let e=0;e<s;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),y.moveTo(r+v,t-v),y.lineTo(r-v,t+v)):(b.moveTo(r+v,t),b.arc(r,t,v,0,Math.PI*2))}}e.lineWidth=1.5,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},O=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:s}=n.priceRange,c=s-o;if(c===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=n.barWidth,m=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>m&&(m=t[e].volume);m===0&&(m=1);let h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=e=>e*l+u,b=e=>d+(s-e)*f;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=y(e),i=b(n.high),a=b(n.low),o=b(n.open),s=b(n.close),c=n.close>=n.open,l=p*Math.max(.2,n.volume/m),u=l/2,d=c?h:g;d.moveTo(r,i),d.lineTo(r,a);let f=c?s:o,x=Math.max(Math.abs(s-o),1);(c?_:v).rect(r-u,f,l,x)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g),e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v)}},k=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:s}=n.priceRange,c=s-o;if(c===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=n.barWidth,m=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>m&&(m=t[e].volume);m===0&&(m=1);let h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=e=>e*l+u,b=e=>d+(s-e)*f;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e>0?t[e-1]:n,i=y(e),a=b(n.high),o=b(n.low),s=n.close>=r.close,c=p*Math.max(.15,n.volume/m),l=c/2,u=Math.max(o-a,1),d=s?h:g,f=s?_:v;d.rect(i-l,a,c,u),f.rect(i-l,a,c,u)}e.fillStyle=A(r.candleUp,.55),e.fill(h),e.fillStyle=A(r.candleDown,.55),e.fill(g),e.lineWidth=1,e.strokeStyle=r.candleUpWick,e.stroke(_),e.strokeStyle=r.candleDownWick,e.stroke(v)}};function A(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var ee=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f,h=[],g=[];for(let e=i;e<=a&&e<t.length;e++){let n=p(e);h.push({x:n,y:m(t[e].high)}),g.push({x:n,y:m(t[e].low)})}if(h.length===0)return;let _=e.createLinearGradient(0,d,0,d+n.chartRect.height);_.addColorStop(0,r.areaTopColor),_.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(h[0].x,h[0].y);for(let t=1;t<h.length;t++)e.lineTo(h[t].x,h[t].y);for(let t=g.length-1;t>=0;t--)e.lineTo(g[t].x,g[t].y);e.closePath(),e.fillStyle=_,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke()}},te=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`miter`;let h=0;for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);n===i?e.moveTo(r,a):(e.lineTo(r,h),e.lineTo(r,a)),h=a}e.stroke()}},ne=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:s}=n.priceRange,c=s-o;if(c===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.chartRect.y,f=n.chartRect.height/c,p=e=>e*l+u,m=e=>d+(s-e)*f;e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let h=[];for(let n=i;n<=a&&n<t.length;n++){let r=p(n),a=m(t[n].close);h.push({x:r,y:a}),n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke();let g=Math.max(2,Math.min(4,n.barWidth*.3)),_=new Path2D;for(let{x:e,y:t}of h)_.moveTo(e+g,t),_.arc(e,t,g,0,Math.PI*2);e.fillStyle=r.lineColor,e.fill(_),e.strokeStyle=r.background,e.lineWidth=1,e.stroke(_)}},re=class{visible=!0;heightRatio=.2;setVisible(e){this.visible=e}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o}=n,s=n.barWidth,c=s/2,l=s+n.barSpacing,u=-n.offset+o.x+c,d=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>d&&(d=t[e].volume);if(d===0)return;let f=o.height*this.heightRatio,p=o.y+o.height,m=f/d,h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e*l+u,i=n.volume*m;(n.close>=n.open?h:g).rect(r-c,p-i,s,i)}e.globalAlpha=.35,e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.globalAlpha=1}},ie=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:s}=n,c=s.max-s.min;if(c<=0)return;let l=new Float64Array(this.buckets),u=new Float64Array(this.buckets),d=new Float64Array(this.buckets);for(let e=i;e<=a&&e<t.length;e++){let n=t[e];if(n.volume<=0)continue;let r=Math.max(n.low,s.min),i=Math.min(n.high,s.max);if(i<=r)continue;let a=(r-s.min)/c,o=(i-s.min)/c,f=Math.max(0,Math.floor(a*this.buckets)),p=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,p-f+1),h=n.volume/m,g=n.close>=n.open;for(let e=f;e<=p;e++)l[e]+=h,g?u[e]+=h:d[e]+=h}let f=0,p=-1;for(let e=0;e<l.length;e++)l[e]>f&&(f=l[e],p=e);if(f===0)return;let m=o.width*this.widthRatio,h=o.x+o.width,g=o.height/this.buckets,_=1/f;e.save(),e.globalAlpha=this.opacity;for(let t=0;t<this.buckets;t++){let n=l[t];if(n===0)continue;let i=o.y+o.height-(t+1)*g,a=n*_*m,s=u[t]*_*m,c=d[t]*_*m;s>0&&(e.fillStyle=r.candleUp,e.fillRect(h-s,i+.5,s,g-1)),c>0&&(e.fillStyle=r.candleDown,e.fillRect(h-a,i+.5,c,g-1)),this.highlightPoC&&t===p&&(e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(o.x,i+g/2+.5),e.lineTo(h-a-2,i+g/2+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=this.opacity)}e.restore()}};function ae(e,t){return e<0?0:e>t?t:e}function oe(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=ae(Math.floor((e-t)/o),i-1),l=ae(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function se(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function ce(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function le(t,n,r,i={}){if(t.length===0||r-n<=0)return[];let a=[],o=0,s=(0,e.timeframeBucketStart)(t[0].time,`1d`),c=(e,o,s)=>{let c=oe(t.slice(e,o+1),n,r,i);c&&a.push({startIndex:e,endIndex:o,startTime:s,profile:c})};for(let n=1;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,`1d`);r!==s&&(c(o,n-1,s),o=n,s=r)}return c(o,t.length-1,s),a}var ue=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}setLetters(e){this.letters=e}getStats(){return this.lastStats}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:s}=n,c=Math.max(0,i),l=Math.min(a,t.length-1);if(l<c)return;let u=t.slice(c,l+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(e,u,c,n,r);return}let d=oe(u,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!d){this.lastStats=null;return}let f=d.buckets[d.pocIndex].mid;this.lastStats={poc:f,vah:d.valueAreaHigh,val:d.valueAreaLow,valueAreaPct:this.valueAreaPct};let p=d.buckets.length,m=o.width*this.widthRatio,h=o.x,g=o.height/p,_=1/d.maxCount;e.save();for(let t=0;t<p;t++){let n=d.buckets[t];if(n.count===0)continue;let i=o.y+o.height-(t+1)*g,a=n.count*_*m,s=n.mid>=d.valueAreaLow&&n.mid<=d.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?r.candleUp:r.textSecondary,e.fillRect(h,i+.5,a,g-1)}let v=e=>o.y+o.height*(1-(e-s.min)/(s.max-s.min));e.globalAlpha=.6,e.strokeStyle=r.candleUp,e.lineWidth=1,e.setLineDash([1,3]);for(let t of[d.valueAreaHigh,d.valueAreaLow]){let n=v(t);e.beginPath(),e.moveTo(h,Math.round(n)+.5),e.lineTo(o.x+o.width,Math.round(n)+.5),e.stroke()}if(e.setLineDash([]),this.highlightPoC){let t=v(f);e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(h,Math.round(t)+.5),e.lineTo(o.x+o.width,Math.round(t)+.5),e.stroke(),e.setLineDash([])}this.showStats&&this.drawStats(e,o.x+6,o.y+6,f,d.valueAreaHigh,d.valueAreaLow,r),e.restore()}renderSplit(e,t,n,r,i){let{chartRect:o,priceRange:s}=r,c=le(t,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(c.length===0)return;let l=s.max-s.min,u=e=>o.y+o.height*(1-(e-s.min)/l),d=r.barWidth/2;e.save();for(let l of c){let c=l.profile,f=c.buckets.length,p=o.height/f,m=a(n+l.startIndex,r)-d,h=a(n+l.endIndex,r)+d,g=Math.max(2,h-m),_=1/c.maxCount,v=this.letters&&p>=7,y=v?ce(t.slice(l.startIndex,l.endIndex+1),s.min,s.max,this.buckets):null;if(v&&y){e.font=`${Math.min(11,Math.floor(p))}px ui-monospace, monospace`,e.textBaseline=`middle`,e.textAlign=`left`;let t=Math.max(1,Math.floor(g/6));for(let n=0;n<f;n++){let r=y[n];if(r.length===0)continue;let a=o.y+o.height-(n+.5)*p,s=c.buckets[n].mid>=c.valueAreaLow&&c.buckets[n].mid<=c.valueAreaHigh;e.globalAlpha=s?.95:.6,e.fillStyle=s?i.candleUp:i.textSecondary;let l=Math.min(r.length,t);for(let t=0;t<l;t++)e.fillText(se(r[t]),m+t*6,a)}}else for(let t=0;t<f;t++){let n=c.buckets[t];if(n.count===0)continue;let r=o.y+o.height-(t+1)*p,a=n.count*_*g,s=n.mid>=c.valueAreaLow&&n.mid<=c.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?i.candleUp:i.textSecondary,e.fillRect(m,r+.5,a,p-1)}if(this.highlightPoC){let t=u(c.buckets[c.pocIndex].mid);e.globalAlpha=1,e.strokeStyle=i.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(m,Math.round(t)+.5),e.lineTo(Math.min(h,o.x+o.width),Math.round(t)+.5),e.stroke(),e.setLineDash([])}}e.restore()}drawStats(e,t,n,r,i,a,o){let s=de(r),c=[[`POC`,r.toFixed(s),o.crosshair],[`VAH`,i.toFixed(s),o.candleUp],[`VAL`,a.toFixed(s),o.candleUp]];e.globalAlpha=1,e.font=`600 10px ${o.font.family}`,e.textBaseline=`middle`;let l=0;for(let[,t]of c)l=Math.max(l,e.measureText(t).width);let u=38+l,d=6+c.length*14;e.fillStyle=o.background,e.globalAlpha=.82,fe(e,t,n,u,d,4),e.fill(),e.globalAlpha=1,c.forEach(([r,i,a],s)=>{let c=n+6/2+14/2+s*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(r,t+6,c),e.fillStyle=o.text,e.textAlign=`right`,e.fillText(i,t+u-6,c)}),e.textAlign=`left`}};function de(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function fe(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function pe(t,n){let r=n===`day`?`1d`:`1w`,i=[];for(let n of t){let t=(0,e.timeframeBucketStart)(n.time,r),a=i[i.length-1];a&&a.key===t?(a.high=Math.max(a.high,n.high),a.low=Math.min(a.low,n.low),a.close=n.close):i.push({key:t,open:n.open,high:n.high,low:n.low,close:n.close})}return i}function me(e,t=`day`){let n=pe(e,t);if(n.length<2)return[];let r=n[n.length-2],i=n[n.length-1],a=t===`day`?`D`:`W`;return[{id:`p${a}h`,label:`P${a}H`,price:r.high},{id:`p${a}c`,label:`P${a}C`,price:r.close},{id:`p${a}l`,label:`P${a}L`,price:r.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:i.open}]}var he=class{visible=!1;period=`day`;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=me(t,this.period);if(i.length===0)return;let{chartRect:a}=n,s=a.y,c=a.y+a.height;e.save(),e.font=`600 10px ${r.font.family}`,e.textBaseline=`middle`;for(let t of i){let i=o(t.price,n);if(i<s||i>c)continue;let l=ge(t,r);e.strokeStyle=l,e.globalAlpha=.7,e.lineWidth=1,e.setLineDash([5,4]),e.beginPath(),e.moveTo(a.x,Math.round(i)+.5),e.lineTo(a.x+a.width,Math.round(i)+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=1;let u=t.label,d=e.measureText(u).width,f=a.x+a.width-d-10;e.fillStyle=r.background,e.globalAlpha=.85,e.fillRect(f-4,i-7,d+8,14),e.globalAlpha=1,e.fillStyle=l,e.textAlign=`left`,e.fillText(u,f,i+.5)}e.restore()}};function ge(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function _e(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function ve(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var ye=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=ve(t,this.left,this.right);if(i.length===0)return;let s=this.structureLabels?_e(i):i,{from:c,to:l}=n.visibleRange;e.save(),e.font=`10px ${r.font.family}`,e.textAlign=`center`;for(let t of s){if(t.index<c-1||t.index>l+1)continue;let i=a(t.index,n),s=o(t.price,n),u=t.type===`high`,d=u?r.candleDown:r.candleUp,f=u?s-8:s+8;e.fillStyle=d,e.beginPath(),u?(e.moveTo(i-5,f-5),e.lineTo(i+5,f-5),e.lineTo(i,f)):(e.moveTo(i-5,f+5),e.lineTo(i+5,f+5),e.lineTo(i,f)),e.closePath(),e.fill();let p=this.structureLabels&&`label`in t?String(t.label):this.showLabels?be(t.price):null;p&&(e.textBaseline=u?`bottom`:`top`,e.fillText(p,i,u?f-5-1:f+5+1))}e.restore()}};function be(e){let t=Math.abs(e);return t>=1e3||t>=1?e.toFixed(2):e.toPrecision(4)}var xe=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e}))},r=this.buffer[this.buffer.length-1];r&&r.time===e?this.buffer[this.buffer.length-1]=n:(this.buffer.push(n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity)))}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},Se=class{buffer=new xe(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(e,t,n){if(!this.visible)return;let r=this.buffer.snapshots();if(r.length===0)return;let i=this.buffer.maxVolume();if(i<=0)return;let a=1/i,{chartRect:o}=t,s=Math.max(2,t.barWidth+t.barSpacing),c=o.x,l=o.x+o.width,u=o.y,f=o.y+o.height;e.save();for(let i of r){let r=d(i.time,t);if(r<c-s||r>l+s)continue;let o=r-s/2;this.drawSide(e,i.bids,n.candleUp,o,s,t,a,u,f),this.drawSide(e,i.asks,n.candleDown,o,s,t,a,u,f)}e.restore()}drawSide(e,t,n,r,i,a,s,c,l){if(t.length===0)return;let u=Ce(t,a);e.fillStyle=n;for(let n of t){let t=o(n.price,a);t<c-u||t>l+u||(e.globalAlpha=Math.min(1,Math.sqrt(n.volume*s))*this.opacity,e.fillRect(r,t-u/2,i,u))}e.globalAlpha=1}};function Ce(e,t){if(e.length<2)return 3;let n=e.map(e=>e.price).sort((e,t)=>e-t),r=[];for(let e=1;e<n.length;e++){let t=n[e]-n[e-1];t>0&&r.push(t)}if(r.length===0)return 3;r.sort((e,t)=>e-t);let i=r[Math.floor(r.length/2)],a=Math.abs(o(n[0],t)-o(n[0]+i,t));return Math.max(2,Math.min(a,12))}var we=class{symbols=new Map;mode=`percent`;setMode(e){this.mode=e}addSymbol(e){this.symbols.set(e.id,e)}removeSymbol(e){this.symbols.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t)}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){this.symbols.clear()}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.symbols.values())!i.visible||i.data.length===0||this.renderSymbol(e,i,t,n,r);e.restore()}renderSymbol(e,t,n,r,i){let{chartRect:s}=r,c=r.barWidth+r.barSpacing,l=Math.max(0,Math.floor(r.offset/c));if(l>=n.length||l>=t.data.length)return;let u=n[l].close,d=t.data[l].close;if(u===0||d===0)return;e.strokeStyle=t.color,e.lineWidth=t.lineWidth??1.5,e.lineJoin=`round`,e.beginPath();let f=!1,p=Math.min(n.length,t.data.length);for(let n=l;n<p;n++){let i=a(n,r);if(i<s.x-c)continue;if(i>s.x+s.width+c)break;let l;l=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r):o(t.data[n].close,r),f?e.lineTo(i,l):(e.moveTo(i,l),f=!0)}if(e.stroke(),f){let n=Math.min(l+2,p-1),i=a(n,r)+4,s;s=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r)-4:o(t.data[n].close,r)-4,e.fillStyle=t.color,e.font=`bold 10px sans-serif`,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(t.label,i,s)}}};function Te(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}function Ee(e,t){if(e.length===0)return[];let n=t.brickSize;t.useATR&&e.length>(t.atrPeriod??14)&&(n=De(e,t.atrPeriod??14)),n<=0&&(n=1);let r=[],i=Math.round(e[0].close/n)*n,a=e[0].time;for(let t=1;t<e.length;t++){let o=e[t].close-i,s=Math.floor(Math.abs(o)/n);if(s>=1){let c=o>0?1:-1;for(let o=0;o<s;o++){let o=i;i+=c*n,r.push({time:a++,open:o,high:Math.max(o,i),low:Math.min(o,i),close:i,volume:e[t].volume/s})}}}return r}function De(e,t){let n=0;for(let r=1;r<=Math.min(t,e.length-1);r++){let t=Math.max(e[r].high-e[r].low,Math.abs(e[r].high-e[r-1].close),Math.abs(e[r].low-e[r-1].close));n+=t}return n/t}function Oe(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume});for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume}):!s&&a<o.close||s&&a<u?n.push({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume}):!s&&a>l&&n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume})}return n}function ke(e,t=4){if(e.length<2)return e.slice();let n=[],r=e[1].close>=e[0].close?1:-1,i=e[0].close,a=e[0].close,o=e[0].close,s=0;for(let c=1;c<e.length;c++){let l=e[c].close,u=t/100*o;r===1?(l>i&&(i=l),i-l>=u&&(n.push({time:s++,open:o,high:i,low:o,close:i,volume:e[c].volume}),r=-1,o=i,a=l,i=l)):(l<a&&(a=l),l-a>=u&&(n.push({time:s++,open:o,high:o,low:a,close:a,volume:e[c].volume}),r=1,o=a,i=l,a=l))}return r===1?n.push({time:s,open:o,high:i,low:o,close:i,volume:0}):n.push({time:s,open:o,high:o,low:a,close:a,volume:0}),n}function Ae(e,t,n=3){if(e.length===0||t<=0)return[];let r=[],i=0,a=0,o=0,s=0,c=Math.round(e[0].close/t)*t;a=c,o=c,i=1;for(let c=1;c<e.length;c++){let l=e[c].close,u=Math.round(l/t)*t;i===1?u>a?a=u:a-u>=t*n&&(r.push({time:s++,open:o,high:a,low:o,close:a,volume:e[c].volume}),i=-1,o=u,a-=t):u<o?o=u:u-o>=t*n&&(r.push({time:s++,open:a,high:a,low:o,close:o,volume:e[c].volume}),i=1,a=u,o+=t)}return r.push({time:s,open:i===1?o:a,high:a,low:o,close:i===1?a:o,volume:0}),r}function je(e,t){if(e.length===0||t.rangeSize<=0)return[];let n=[],r=e[0].time,i=e[0].open,a=i,o=i,s=0,c=(e,c)=>{for(e>a&&(a=e),e<o&&(o=e),s+=c;a-o>=t.rangeSize;){let c=e>=i,l=c?i+t.rangeSize:i-t.rangeSize;n.push({time:r++,open:i,high:c?l:i,low:c?i:l,close:l,volume:s}),i=l,a=l,o=l,s=0}};for(let t of e){let e=t.close>=t.open?[t.low,t.high,t.close]:[t.high,t.low,t.close],n=t.volume/e.length;for(let t of e)c(t,n)}return n}var j=class{drawLine(e,t,n,r){if(!(t.length<2)){e.beginPath(),e.strokeStyle=n,e.lineWidth=r,e.lineJoin=`round`,e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.stroke()}}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(e,t,n,r){let i=[],{from:s,to:c}=r.visibleRange;for(let l=s;l<=c&&l<n.length;l++){let s=e.values.get(n[l].time);s&&s[t]!==void 0&&i.push({x:a(l,r),y:o(s[t],r)})}return i}},Me=1,Ne=class{registry=new Map;instances=new Map;register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(e,t={},n){let r=this.registry.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);let i=`tc_${e}_${Me++}`,a={id:e,instanceId:i,params:{...r.descriptor.defaultConfig,...t},visible:!0},o={plugin:r,config:a,output:null,style:{colors:a.style?.colors??[`#2196F3`,`#FF9800`,`#4CAF50`,`#E91E63`,`#9C27B0`],lineWidths:a.style?.lineWidths??[1.5],opacity:a.style?.opacity??1}};return n&&(o.output=r.calculate(n,a)),this.instances.set(i,o),i}removeIndicator(e){this.instances.delete(e)}updateIndicator(e,t,n){let r=this.instances.get(e);r&&(Object.assign(r.config.params,t),n&&(r.output=r.plugin.calculate(n,r.config)))}recalculateAll(e){for(let t of this.instances.values())t.output=t.plugin.calculate(e,t.config)}getOutput(e){return this.instances.get(e)?.output??null}renderOverlays(e,t){for(let n of this.instances.values())!n.output||!n.config.visible||n.plugin.descriptor.placement===`overlay`&&n.plugin.render(e,n.output,t,n.style)}renderPanel(e,t,n){let r=this.instances.get(t);!r?.output||!r.config.visible||r.plugin.render(e,r.output,n,r.style)}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0});return e}updateIndicatorStyle(e,t){let n=this.instances.get(e);n&&Object.assign(n.style,t)}getOverlayPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.instances.values()){if(!i.output||!i.config.visible||i.plugin.descriptor.placement!==`overlay`)continue;let a=0;for(let[,o]of i.output.values){if(a>=e&&a<=t)for(let e in o){let t=o[e];t!==void 0&&isFinite(t)&&(t<n&&(n=t),t>r&&(r=t))}a++}}return n===1/0?null:{min:n,max:r}}getPanelIndicators(){let e=[];for(let[t,n]of this.instances)n.plugin.descriptor.placement===`panel`&&e.push({instanceId:t,descriptor:n.plugin.descriptor});return e}};function M(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function N(e,t,n,r=1){let i=M(e,t,n);return Math.max(r,Math.floor(i))}var Pe=class extends j{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Fe=class extends j{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=2/(n+1),i=new Map,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Ie=class extends j{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2}};calculate(e,t){let n=N(t,`period`,20,1),r=M(t,`stdDev`,2),i=new Map,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=0,d=l-c+1,f=new Float64Array(d),p=new Float64Array(d),m=new Float64Array(d),h=new Float64Array(d),g=new Float64Array(d),_=new Float64Array(d);for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);f[u]=n,p[u]=o(t.upper,r),m[u]=n,h[u]=o(t.middle,r),g[u]=n,_[u]=o(t.lower,r),u++}if(!(u<2)){t.beginPath(),t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);for(let e=u-1;e>=0;e--)t.lineTo(g[e],_[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[0],.1),t.fill(),t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`,t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[1]??i.colors[0],t.moveTo(m[0],h[0]);for(let e=1;e<u;e++)t.lineTo(m[e],h[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[0],t.moveTo(g[0],_[0]);for(let e=1;e<u;e++)t.lineTo(g[e],_[e]);t.stroke()}}},Le=class extends j{descriptor={id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=0,a=0;for(let t=0;t<e.length;t++){let o=(e[t].high+e[t].low+e[t].close)/3;if(i+=e[t].volume,a+=o*e[t].volume,i>0){let o={value:a/i};n.set(e[t].time,o),r[t]=o}}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Re=class extends j{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26}};calculate(e,t){let n=N(t,`tenkan`,9,1),r=N(t,`kijun`,26,1),i=N(t,`senkou`,52,1),a=new Map,o=Array(e.length).fill(null),s=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},c=s(n),l=s(r),u=s(i);for(let t=0;t<e.length;t++){let s={};t>=n-1&&(s.tenkan=(c.highs[t]+c.lows[t])/2),t>=r-1&&(s.kijun=(l.highs[t]+l.lows[t])/2),s.tenkan!==void 0&&s.kijun!==void 0&&(s.senkouA=(s.tenkan+s.kijun)/2),t>=i-1&&(s.senkouB=(u.highs[t]+u.lows[t])/2),t>=r-1&&(s.chikou=e[t].close),(s.tenkan!==void 0||s.kijun!==void 0||s.senkouA!==void 0||s.senkouB!==void 0)&&(a.set(e[t].time,s),o[t]=s)}return{values:a,series:o}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=l-c+1,d=new Float64Array(u),f=new Float64Array(u),p=0,m=new Float64Array(u),h=new Float64Array(u),g=0,_=new Float64Array(u),v=new Float64Array(u),y=0,b=new Float64Array(u),x=new Float64Array(u),S=0;for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.tenkan!==void 0&&(d[p]=n,f[p]=o(t.tenkan,r),p++),t.kijun!==void 0&&(m[g]=n,h[g]=o(t.kijun,r),g++),t.senkouA!==void 0&&(_[y]=n,v[y]=o(t.senkouA,r),y++),t.senkouB!==void 0&&(b[S]=n,x[S]=o(t.senkouB,r),S++)}if(y>1&&S>1){let n=Math.min(y,S);t.beginPath(),t.moveTo(_[0],v[0]);for(let e=1;e<n;e++)t.lineTo(_[e],v[e]);for(let e=n-1;e>=0;e--)t.lineTo(b[e],x[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[2]??`#26A69A`,.15),t.fill()}let C=(e,n,r,i,a)=>{if(!(r<2)){t.beginPath(),t.strokeStyle=i,t.lineWidth=a,t.lineJoin=`round`,t.moveTo(e[0],n[0]);for(let i=1;i<r;i++)t.lineTo(e[i],n[i]);t.stroke()}};C(d,f,p,i.colors[0],i.lineWidths[0]),C(m,h,g,i.colors[1]??`#FF9800`,i.lineWidths[0]),C(_,v,y,i.colors[2]??`#26A69A`,1),C(b,x,S,i.colors[3]??`#EF5350`,1)}},ze=class extends j{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2}};calculate(e,t){let n=M(t,`step`,.02),r=M(t,`max`,.2),i=new Map,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=Math.max(1.5,n.barWidth*.15);for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),u=o(s.value,n);e.beginPath(),e.arc(c,u,l,0,Math.PI*2),e.fillStyle=s.trend===1?r.colors[0]:r.colors[1]??`#EF5350`,e.fill()}}},Be=class extends j{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3}};calculate(e,t){let n=N(t,`period`,10,1),r=M(t,`multiplier`,3),i=new Map,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s;c=g<u||e[t-1].close>u?g:u,l=_>d||e[t-1].close<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let v={value:f,trend:m};i.set(e[t].time,v),a[t]=v,u=c,d=l,p=f}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#EF5350`,d=0,f=0,p=0;for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),m=o(s.value,n),h=s.trend??1;p!==0&&(e.beginPath(),e.strokeStyle=h===1?l:u,e.lineWidth=r.lineWidths[0]+.5,e.moveTo(d,f),e.lineTo(c,m),e.stroke()),d=c,f=m,p=h}}},Ve=class extends j{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5}};calculate(e,t){let n=N(t,`emaPeriod`,20,1),r=N(t,`atrPeriod`,10,1),i=M(t,`multiplier`,1.5),a=new Map;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},He=class extends j{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??`#787B86`,1),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Ue=[`s3`,`s2`,`s1`,`pp`,`r1`,`r2`,`r3`],We=class extends j{descriptor={id:`pivots`,name:`Pivot Points (Classic)`,placement:`overlay`,defaultConfig:{lookback:24}};calculate(e,t){let n=N(t,`lookback`,24,1),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};for(let t=n;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n;r<t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s=e[t-1].close,c=(a+o+s)/3,l=a-o,u={pp:c,r1:2*c-o,s1:2*c-a,r2:c+l,s2:c-l,r3:a+2*(c-o),s3:o-2*(a-c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#EF5350`,d=r.colors[2]??`#26A69A`,f=r.lineWidths[0],p=e=>e===`pp`?l:e.startsWith(`r`)?u:d;for(let t of Ue){e.beginPath(),e.strokeStyle=p(t),e.lineWidth=t===`pp`?f:Math.max(1,f-1),t!==`pp`&&e.setLineDash([4,3]);let r=!1;for(let l=s;l<=c&&l<i.length;l++){let s=i[l]?.[t];if(s===void 0)continue;let c=a(l,n),u=o(s,n);r?e.lineTo(c,u):(e.moveTo(c,u),r=!0)}e.stroke(),e.setLineDash([])}}},Ge=class extends j{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0}};calculate(e,t){let n=M(t,`anchorTime`,0),r=new Map,i=Array(e.length).fill(null),a=0;if(n>0&&(a=e.findIndex(e=>e.time>=n),a<0))return{values:r,series:i};let o=0,s=0;for(let t=a;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(o+=e[t].volume,s+=n*e[t].volume,o>0){let n={value:s/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Ke=class extends j{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5}};calculate(e,t){let n=Math.max(.01,M(t,`deviation`,5))/100,r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(e,t,n,r){let i=t.meta?.pivots;if(!(!i||i.length<2)){e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;for(let t=0;t<i.length;t++){let r=i[t],s=a(r.idx,n),c=o(r.price,n);t===0?e.moveTo(s,c):e.lineTo(s,c)}e.stroke()}}},qe=class extends j{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2}};calculate(e,t){let n=N(t,`period`,100,2),r=M(t,`stdDev`,2),i=new Map,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Je=class extends j{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21}};calculate(e,t){let n=N(t,`period`,21,2),r=new Map,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=Ye(a,n),l=Ye(a,o),u=Xe(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}};function Ye(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function Xe(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var Ze=class extends j{descriptor={id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`}};calculate(t,n){let r=N(n,`period`,50,1),i=String(n.params.timeframe??`1d`),a=new Map,o=Array(t.length).fill(null);if(t.length===0)return{values:a,series:o};let s=[],c=(0,e.timeframeBucketStart)(t[0].time,i),l=t[0].close,u=null,d=()=>{if(s.length<r)return;let e=0;for(let t=s.length-r;t<s.length;t++)e+=s[t];u=e/r};for(let n=0;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,i);if(r!==c&&(s.push(l),d(),c=r),l=t[n].close,u!==null){let e={value:u};a.set(t[n].time,e),o[n]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Qe=class extends j{descriptor={id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1}};calculate(t,n){let r=Math.min(3,N(n,`bands`,1,0)),i=new Map,a=Array(t.length).fill(null);if(t.length===0)return{values:i,series:a};let o=(0,e.timeframeBucketStart)(t[0].time,`1d`),s=0,c=0,l=0;for(let n=0;n<t.length;n++){let u=t[n],d=(0,e.timeframeBucketStart)(u.time,`1d`);d!==o&&(s=0,c=0,l=0,o=d);let f=(u.high+u.low+u.close)/3;if(s+=f*u.volume,c+=f*f*u.volume,l+=u.volume,l>0){let e=s/l,t={value:e,session:o};if(r>0){let n=Math.max(0,c/l-e*e),i=Math.sqrt(n);for(let n=1;n<=r;n++)t[`u${n}`]=e+n*i,t[`l${n}`]=e-n*i}i.set(u.time,t),a[n]=t}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:a,to:o}=n.visibleRange;e.globalAlpha=.55,e.lineWidth=1,e.setLineDash([4,3]),e.strokeStyle=r.colors[1]??r.colors[0];for(let t=1;t<=3;t++)this.strokeBandSeries(e,i,n,a,o,e=>e[`u${t}`]),this.strokeBandSeries(e,i,n,a,o,e=>e[`l${t}`]);e.setLineDash([]),e.globalAlpha=1,e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,this.strokeBandSeries(e,i,n,a,o,e=>e.value)}strokeBandSeries(e,t,n,r,i,s){e.beginPath();let c,l=!1;for(let u=r;u<=i&&u<t.length;u++){let r=t[u],i=r?s(r):void 0;if(r===null||i===void 0){l=!1;continue}let d=a(u,n),f=o(i,n),p=r.session!==c;!l||p?(e.moveTo(d,f),l=!0):e.lineTo(d,f),c=r.session}e.stroke()}},$e=class extends j{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3}};calculate(e,t){let n=N(t,`period`,22,1),r=M(t,`multiplier`,3),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.setLineDash([5,3]);let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke(),e.setLineDash([])};l(`long`,r.colors[0]??`#26A69A`),l(`short`,r.colors[1]??`#EF5350`)}},et=class extends j{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3}};calculate(e,t){let n=N(t,`jaw`,13,1),r=N(t,`teeth`,8,1),i=N(t,`lips`,5,1),a=N(t,`jawShift`,8,0),o=N(t,`teethShift`,5,0),s=N(t,`lipsShift`,3,0),c=new Map,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=tt(d,n),p=tt(d,r),m=tt(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke()};l(`jaw`,r.colors[0]??`#2962FF`),l(`teeth`,r.colors[1]??`#EF5350`),l(`lips`,r.colors[2]??`#26A69A`)}};function tt(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var nt=class extends j{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34}};calculate(e,t){let n=N(t,`fast`,5,1),r=N(t,`slow`,34,1),i=new Map,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#26A69A`,g=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.up?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},rt=class extends j{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10}};calculate(e,t){let n=N(t,`fast`,3,1),r=N(t,`slow`,10,1),i=new Map,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#26A69A`,g=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.value>=0?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},it=class extends j{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=0,o=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?a+=n:o-=n}a/=n,o/=n;let s={value:o===0?100:100-100/(1+a/o)};r.set(e[n].time,s),i[n]=s;for(let t=n+1;t<e.length;t++){let s=e[t].close-e[t-1].close,c=s>0?s:0,l=s<0?-s:0;a=(a*(n-1)+c)/n,o=(o*(n-1)+l)/n;let u={value:o===0?100:100-100/(1+a/o)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath();for(let t of[30,70]){let n=l(t);e.moveTo(o.x,n),e.lineTo(o.x+o.width,n)}e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},at=class extends j{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};calculate(e,t){let n=N(t,`fast`,12,1),r=N(t,`slow`,26,1),i=N(t,`signal`,9,1),a=new Map,o=Array(e.length).fill(null);if(e.length<r)return{values:a,series:o};let s=2/(n+1),c=2/(r+1),l=2/(i+1),u=e[0].close,d=e[0].close,f=0,p=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(u=n,d=n):(u=(n-u)*s+u,d=(n-d)*c+d),t>=r-1){let n=u-d;p?f=(n-f)*l+f:(f=n,p=!0);let r=n-f,i={macd:n,signal:f,histogram:r};a.set(e[t].time,i),o[t]=i}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.macd!==void 0&&(t.macd<l&&(l=t.macd),t.macd>u&&(u=t.macd)),t.signal!==void 0&&(t.signal<l&&(l=t.signal),t.signal>u&&(u=t.signal)),t.histogram!==void 0&&(t.histogram<l&&(l=t.histogram),t.histogram>u&&(u=t.histogram)))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d),p=f(0),m=n.barWidth/2,h=r.colors[2]??`#26A69A`,g=r.colors[3]??`#EF5350`,_=r.colors[0],v=r.colors[1]??`#FF9800`;e.beginPath();let y=new Path2D,b=new Path2D,x=!1,S=!1,C=new Path2D,w=new Path2D;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(!t)continue;let r=a(e,n);if(t.histogram!==void 0){let e=f(t.histogram),i=Math.min(e,p),a=Math.max(Math.abs(e-p),1);t.histogram>=0?y.rect(r-m,i,n.barWidth,a):b.rect(r-m,i,n.barWidth,a)}if(t.macd!==void 0){let e=f(t.macd);x?C.lineTo(r,e):(C.moveTo(r,e),x=!0)}if(t.signal!==void 0){let e=f(t.signal);S?w.lineTo(r,e):(w.moveTo(r,e),S=!0)}}e.fillStyle=h,e.fill(y),e.fillStyle=g,e.fill(b),e.strokeStyle=_,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.stroke(C),e.strokeStyle=v,e.stroke(w)}},ot=class extends j{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3}};calculate(e,t){let n=N(t,`kPeriod`,14,1),r=N(t,`dPeriod`,3,1),i=N(t,`smooth`,3,1),a=new Map,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]),u(`d`,r.colors[1]??`#FF9800`)}},st=class extends j{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},ct=class extends j{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`adx`,r.colors[0]),u(`plusDI`,r.colors[1]??`#26A69A`),u(`minusDI`,r.colors[2]??`#EF5350`)}},lt=class extends j{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},ut=class extends j{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-20,-80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},dt=class extends j{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-100,0,100])if(t>=f&&t<=p){let n=h(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},ft=class extends j{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},pt=class extends j{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25}};calculate(e,t){let n=N(t,`period`,25,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`up`,r.colors[0]),u(`down`,r.colors[1]??`#EF5350`)}},mt=class extends j{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12}};calculate(e,t){let n=N(t,`period`,12,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);if(0>=f&&0<=p){e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);let t=h(0);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},ht=class extends j{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7}};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=N(t,`longPeriod`,25,1),r=N(t,`shortPeriod`,13,1),i=N(t,`signalPeriod`,7,1),a=new Map,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.tsi!==void 0&&(l=Math.min(l,t.tsi),u=Math.max(u,t.tsi)),t.signal!==void 0&&(l=Math.min(l,t.signal),u=Math.max(u,t.signal)))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=h(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};g(`tsi`,r.colors[0]),g(`signal`,r.colors[1]??`#FF9800`)}},gt=class extends j{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=n.barWidth/2;for(let t=s;t<=c&&t<i.length;t++){let o=i[t];if(o&&o.value!==void 0){let i=a(t,n),s=h(o.value),c=h(0);e.fillStyle=o.value>=0?r.colors[0]:r.colors[1]??`#EF5350`;let l=Math.min(s,c);e.fillRect(i-g,l,n.barWidth,Math.max(Math.abs(s-c),1))}}}},_t=class extends j{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0}};calculate(e,t){let n=M(t,`mode`,0)>=1,r=new Map,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2,p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value),c=Math.min(s,d),l=Math.max(Math.abs(s-d),1);e.fillStyle=r.up?p:m,e.fillRect(o-f,c,n.barWidth,l)}}},vt=class extends j{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`viPlus`,`viMinus`]){let n=t[e];n!==void 0&&(n<l&&(l=n),n>u&&(u=n))}}if(l===1/0)return;let d=(u-l)*.1||.1;l-=d,u+=d;let f=u-l||1,p=e=>o.y+o.height*(1-(e-l)/f);if(1>=l&&1<=u){e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);let t=p(1);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}let m=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=p(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};m(`viPlus`,r.colors[0]??`#26A69A`),m(`viMinus`,r.colors[1]??`#EF5350`)}},yt=class extends j{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,2),r=new Map,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[38.2,61.8]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},bt=class extends j{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28}};calculate(e,t){let n=N(t,`fast`,7,1),r=N(t,`mid`,14,1),i=N(t,`slow`,28,1),a=new Map,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=xt(l(s,t,n),l(c,t,n)),d=xt(l(s,t,r),l(c,t,r)),f=xt(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function xt(e,t){return t===0?0:e/t}var St=class extends j{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=N(t,`period`,13,1),r=new Map,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},Ct=class extends j{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100}};calculate(e,t){let n=N(t,`rsiPeriod`,3,1),r=N(t,`streakPeriod`,2,1),i=N(t,`rankPeriod`,100,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=wt(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=wt(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[10,90]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function wt(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var Tt=class extends j{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10}};calculate(e,t){let n=N(t,`longRoc`,14,1),r=N(t,`shortRoc`,11,1),i=N(t,`wma`,10,1),a=new Map,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},Et=class extends j{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9}};calculate(e,t){let n=N(t,`roc1`,10,1),r=N(t,`roc2`,15,1),i=N(t,`roc3`,20,1),a=N(t,`roc4`,30,1),o=N(t,`sma1`,10,1),s=N(t,`sma2`,10,1),c=N(t,`sma3`,10,1),l=N(t,`sma4`,15,1),u=N(t,`signal`,9,1),d=new Map,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=F(P(m,n),o),g=F(P(m,r),s),_=F(P(m,i),c),v=F(P(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=F(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}};function P(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function F(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var Dt=class extends j{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=N(t,`period`,13,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`bull`,`bear`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r)continue;let o=a(t,n);if(r.bull!==void 0){let t=u(r.bull);e.fillStyle=p,e.globalAlpha=.8,e.fillRect(o-f,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}if(r.bear!==void 0){let t=u(r.bear);e.fillStyle=m,e.globalAlpha=.8,e.fillRect(o,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}}e.globalAlpha=1}},Ot=class extends j{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10}};calculate(e,t){let n=N(t,`fast`,23,1),r=N(t,`slow`,50,1),i=N(t,`cycle`,10,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=kt(kt(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[25,75]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function kt(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var At=class extends j{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13}};calculate(e,t){let n=N(t,`fast`,34,1),r=N(t,`slow`,55,1),i=N(t,`signal`,13,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}},jt=class extends j{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=N(t,`period`,9,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`trigger`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`trigger`,r.colors[1]??`#FF9800`)}},Mt=class extends j{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,2),r=Math.floor(n/2)+1,i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#26A69A`,m=r.colors[1]??`#EF5350`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);e.fillStyle=r.value>=0?p:m,e.fillRect(o-f,Math.min(s,d),n.barWidth,Math.max(1,Math.abs(s-d)))}}},Nt=class extends j{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14}};calculate(e,t){let n=N(t,`smooth`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+1)/2),u=l(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,u),e.lineTo(o.x+o.width,u),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(Math.max(-1,Math.min(1,r.value)));d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},Pt=class extends j{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25}};calculate(e,t){let n=N(t,`ema`,9,1),r=N(t,`sum`,25,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;l=Math.min(l,26),u=Math.max(u,27.5);let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[26.5,27]){let n=f(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}},Ft=class extends j{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=N(t,`period`,9,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/200);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-50,0,50]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},It=class extends j{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9}};calculate(e,t){let n=N(t,`period`,15,1),r=N(t,`signal`,9,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=I(I(I(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=I(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}};function I(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var Lt=class extends j{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){L(e,t,n,r)}};function L(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}var Rt=class extends j{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){zt(e,t,n,r,a)}};function zt(e,t,n,r,i){let a=t.series;if(!a)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<a.length;e++){let t=a[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<a.length;t++){let r=a[t];if(!r||r.value===void 0)continue;let o=i(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}var Bt=class extends j{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}render(e,t,n,r){zt(e,t,n,r,a)}},Vt=class extends j{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10}};calculate(e,t){let n=N(t,`ema`,10,1),r=N(t,`roc`,10,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}render(e,t,n,r){L(e,t,n,r)}},Ht=class extends j{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10}};calculate(e,t){let n=N(t,`period`,10,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#2962FF`),f(`signal`,r.colors[1]??`#FF9800`)}},Ut=class extends j{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3}};calculate(e,t){let n=N(t,`rsiPeriod`,14,1),r=N(t,`stochPeriod`,14,1),i=N(t,`k`,3,1),a=N(t,`d`,3,1),o=new Map,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=Wt(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=Gt(u,i),f=Gt(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){u=!1;continue}let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]??`#2962FF`),u(`d`,r.colors[1]??`#FF9800`)}};function Wt(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function Gt(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var Kt=class extends j{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};calculate(e,t){let n=N(t,`fast`,12,1),r=N(t,`slow`,26,1),i=N(t,`signal`,9,1),a=new Map,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=qt(c,n),u=qt(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=qt(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`,`hist`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=Math.max(1,o.width/(c-s+1)*.6);for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.hist;if(r===void 0)continue;let o=a(t,n),s=u(r);e.fillStyle=r>=0?`rgba(38,166,154,0.5)`:`rgba(239,83,80,0.5)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d)))}e.strokeStyle=r.colors[2]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};p(`value`,r.colors[0]??`#2962FF`),p(`signal`,r.colors[1]??`#FF9800`)}};function qt(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var Jt=class extends j{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{}};calculate(e){let t=new Map,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=Yt(i,e,5)-Yt(i,e,34);for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let o={value:a[i]-r/5};t.set(e[i].time,o),n[i]=o}return{values:t,series:n}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=Math.max(1,o.width/(c-s+1)*.6),p;for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.value;if(r===void 0){p=void 0;continue}let o=a(t,n),s=u(r);e.fillStyle=(p===void 0?r>=0:r>=p)?`rgba(38,166,154,0.85)`:`rgba(239,83,80,0.85)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d))),p=r}}};function Yt(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var Xt=class extends j{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5}};calculate(e,t){let n=N(t,`period`,20,1),r=N(t,`momentum`,5,1),i=new Map,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#2962FF`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){u=!1;continue}let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Zt=class extends j{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){L(e,t,n,r)}},Qt=class extends j{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8}};calculate(e,t){let n=N(t,`period`,8,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}render(e,t,n,r){L(e,t,n,r)}},$t=class extends j{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=3;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}let u=e=>o.y+o.height*(1-(e+l)/(2*l));e.strokeStyle=r.colors[1]??`#787B86`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-3,0,3]){let n=u(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#2962FF`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){d=!1;continue}let o=a(t,n),s=u(r.value);d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},en=class extends j{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=N(t,`period`,20,1),r=new Map,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},tn=class extends j{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`panel`,defaultConfig:{rows:24}};calculate(e,t){let n=N(t,`rows`,24,1),r=new Map,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(e,t,n,r){let{chartRect:i}=n,a=t.meta;if(!a||a.maxVolume===0)return;let{minPrice:o,rows:s,rowHeight:c,bins:l,maxVolume:u}=a,d=i.height/s,f=i.width*.3;for(let t=0;t<s;t++){let a=(o+(t+.5)*c-n.priceRange.min)/(n.priceRange.max-n.priceRange.min),s=i.y+i.height*(1-a),p=l[t]/u*f;e.fillStyle=l[t]>u*.7?r.colors[1]??`rgba(255, 152, 0, 0.5)`:r.colors[0]??`rgba(33, 150, 243, 0.3)`,e.fillRect(i.x,s-d/2,p,Math.max(d-1,1))}}},nn=class extends j{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new Map,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},rn=class extends j{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=N(t,`period`,14,1),r=new Map,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#787B86`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([])),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}};function an(e){e.register(new Pe),e.register(new Fe),e.register(new Ie),e.register(new Le),e.register(new Re),e.register(new ze),e.register(new Be),e.register(new Ve),e.register(new He),e.register(new We),e.register(new Ge),e.register(new Ke),e.register(new qe),e.register(new Je),e.register(new Ze),e.register(new Qe),e.register(new $e),e.register(new et),e.register(new it),e.register(new at),e.register(new ot),e.register(new st),e.register(new ct),e.register(new lt),e.register(new ut),e.register(new dt),e.register(new ft),e.register(new pt),e.register(new mt),e.register(new ht),e.register(new gt),e.register(new en),e.register(new tn),e.register(new nn),e.register(new rn),e.register(new nt),e.register(new rt),e.register(new _t),e.register(new vt),e.register(new yt),e.register(new bt),e.register(new St),e.register(new Ct),e.register(new Tt),e.register(new Et),e.register(new Dt),e.register(new Ot),e.register(new At),e.register(new jt),e.register(new Mt),e.register(new Nt),e.register(new Pt),e.register(new Ft),e.register(new It),e.register(new Lt),e.register(new Bt),e.register(new Rt),e.register(new Vt),e.register(new Ht),e.register(new Ut),e.register(new Kt),e.register(new Jt),e.register(new Xt),e.register(new Zt),e.register(new Qt),e.register(new $t)}function on(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var sn=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i={type:`calculate`,requestId:r,indicatorId:e,config:t,data:n};return new Promise((t,n)=>{let a={resolve:t,reject:n,timer:null};this.timeoutMs>0&&(a.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,a),this.worker.postMessage(i)})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!on(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(e.output)}}},cn=class{visible=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}render(t,n,r){if(!this.visible)return;let{chartRect:i,priceRange:a}=n;t.strokeStyle=r.grid,t.lineWidth=1;let o=a.max-a.min;if(o<=0)return;let s=1/o;t.beginPath();let c=(0,e.computeTickStep)(a.min,a.max,8),l=Math.ceil(a.min/c)*c;for(let e=l;e<=a.max;e+=c){let n=Math.round(i.y+i.height*(1-(e-a.min)*s))+.5;t.moveTo(i.x,n),t.lineTo(i.x+i.width,n)}let u=n.barWidth+n.barSpacing,d=Math.max(1,Math.ceil(80/u)),{from:f,to:p}=n.visibleRange,m=-n.offset+i.x+n.barWidth/2;for(let e=f;e<=p;e++){if(e%d!==0)continue;let n=Math.round(e*u+m)+.5;t.moveTo(n,i.y),t.lineTo(n,i.y+i.height)}t.stroke()}},ln=class{locale=`en-US`;setLocale(e){this.locale=e}render(t,n,r){let{chartRect:i,priceRange:a}=n,o=i.x+i.width,s=a.max-a.min;if(s<=0)return;let c=1/s;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o+.5,i.y),t.lineTo(o+.5,i.y+i.height),t.stroke(),t.globalAlpha=1;let l=(0,e.computeTickStep)(a.min,a.max,8),u=Math.ceil(a.min/l)*l,d=l<1?Math.ceil(-Math.log10(l))+1:2,f=`500 ${r.font.sizeSmall}px ${r.font.family}`,p=n.scaleMode??(n.logScale?`logarithmic`:`regular`),m=n.scaleBaseline,h=[];for(let t=u;t<=a.max;t+=l){let n=i.y+i.height*(1-(t-a.min)*c);h.push({y:n,text:(0,e.formatPriceScaleLabel)(t,p,m,d,this.locale)})}t.font=f,t.textBaseline=`middle`,t.textAlign=`left`,t.strokeStyle=r.axisLine,t.globalAlpha=.45,t.beginPath();for(let{y:e}of h)t.moveTo(o+1,e+.5),t.lineTo(o+4,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.axisLabel;for(let{y:e,text:n}of h)t.fillText(n,o+8,e)}},un=e=>e<10?`0`+e:``+e,dn=class{tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}render(t,n,r,i,a){let{chartRect:o}=n,s=a??o.y+o.height;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o.x,s+.5),t.lineTo(o.x+o.width,s+.5),t.stroke(),t.globalAlpha=1;let c=n.barWidth+n.barSpacing,l=Math.max(1,Math.ceil(80/c)),{from:u,to:d}=n.visibleRange,f=-n.offset+o.x+n.barWidth/2;t.font=`500 ${r.font.sizeSmall}px ${r.font.family}`,t.textBaseline=`top`,t.textAlign=`center`,t.fillStyle=r.axisLabel;let p=-1;for(let n=u;n<=d&&n<i.length;n++){if(n%l!==0)continue;let r=n*c+f,a=i[n].time,o=(0,e.timeParts)(a>0xe8d4a51000?a:a*1e3,this.tzOffsetMinutes),{year:u,day:d,month:m,hours:h,minutes:g}=o,_;(0,e.isDateOnly)(o)?_=`${m}/${d}/${u}`:d===p?_=`${un(h)}:${un(g)}`:(_=`${m}/${d}`,p=d),t.fillText(_,r,s+7)}let m=o.x+o.width-4,h=s+7;t.font=`500 ${r.font.sizeSmall-1}px ${r.font.family}`,t.textAlign=`right`,t.textBaseline=`top`,t.globalAlpha=.75,t.fillStyle=r.textSecondary,t.fillText((0,e.tzLabel)(this.tzOffsetMinutes),m,h),t.globalAlpha=1}},fn=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;measureHandlers=null;measuring=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressMs=500;longPressMaxMove=8;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e}setZoomHandler(e){this.zoomHandler=e}setCrosshairHandler(e){this.crosshairHandler=e}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setClickHandler(e){this.onClick=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setPaneResizeHandler(e){this.paneResizeHandler=e}attach(){let e=()=>this.viewportGetter?.()??null,t=e=>{let t=this.axisViewportGetter?.();if(!t)return null;let n=t.chartRect;return e.y>n.y+n.height?`time`:e.x>n.x+n.width?`price`:null},n=n=>{this.invalidateRect();let r=this.getMousePos(n),i=e();this.downPos=r,this.downMoved=!1,this.pressForClick=!1;let a=t(r);if(a&&this.axisDragHandler){this.axisDragHandler.begin(a,r);return}if(!this.paneResizeHandler?.tryBegin(r)){if(n.shiftKey&&this.measureHandlers){this.measuring=!0,this.measureHandlers.begin(r),this.onOverlayDirty?.();return}if(n.altKey&&this.onAltClick){this.onAltClick(r);return}if(!(this.tradingManager&&i&&this.tradingManager.onPointerDown(r,i))&&!(this.drawingManager&&i&&this.drawingManager.onPointerDown(r,i))){if(this.alertDragHandler?.tryBegin(r)){this.onOverlayDirty?.();return}this.pressForClick=!0,this.panHandler?.onPointerDown(r)}}},r=n=>{let r=this.getMousePos(n),i=e();if(this.downPos&&!this.downMoved){let e=r.x-this.downPos.x,t=r.y-this.downPos.y;e*e+t*t>16&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(r);return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(r);return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(r),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(r),this.onOverlayDirty?.();return}let a=t(r),o=this.paneResizeHandler?.cursorAt(r)??null;if(a===`price`?this.element.style.cursor=`ns-resize`:a===`time`?this.element.style.cursor=`ew-resize`:this.alertDragHandler?.isOverAlert(r)?this.element.style.cursor=`ns-resize`:o?this.element.style.cursor=o:(this.element.style.cursor===`ns-resize`||this.element.style.cursor===`ew-resize`)&&(this.element.style.cursor=``),this.tradingManager&&i&&this.tradingManager.onPointerMove(r,i)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}if(this.drawingManager&&i&&this.drawingManager.onPointerMove(r,i)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(r),this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.()},i=()=>{if(this.axisDragHandler?.isActive()){this.axisDragHandler.end();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.end();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.end(),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.();return}this.tradingManager?.onPointerUp()||this.drawingManager?.onPointerUp()||(this.panHandler?.onPointerUp(),this.pressForClick&&!this.downMoved&&this.downPos&&this.onClick&&this.onClick(this.downPos),this.pressForClick=!1,this.downPos=null)},a=e=>{let n=t(this.getMousePos(e));n&&this.onAxisDoubleClick&&this.onAxisDoubleClick(n)},o=()=>{this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},s=e=>{e.preventDefault();let t=this.getMousePos(e);this.zoomHandler?.onWheel(e.deltaY,t)},c=e=>{if(e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey)&&e.preventDefault()},l=t=>{let n=e();!this.tradingManager||!n||this.tradingManager.onContextMenu(this.getMousePos(t),n)&&t.preventDefault()},u=n=>{if(n.preventDefault(),this.invalidateRect(),n.touches.length===1){let r=this.getTouchPos(n.touches[0]);this.touchStartPos=r;let i=t(r);if(i&&this.axisDragHandler){this.axisDragHandler.begin(i,r),this.touchActive=!0;return}if(this.paneResizeHandler?.tryBegin(r)){this.touchActive=!0;return}let a=e();if(this.tradingManager&&a&&this.tradingManager.onPointerDown(r,a)){this.touchActive=!0,this.onOverlayDirty?.();return}this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.onAltClick?.(r),this.panHandler?.onPointerUp(),this.onOverlayDirty?.()},this.longPressMs)),this.panHandler?.onPointerDown(r),this.crosshairHandler?.onPointerMove(r),this.touchActive=!0}else n.touches.length===2&&(this.clearLongPress(),this.panHandler?.onPointerUp(),this.lastTouchDist=this.getTouchDistance(n.touches[0],n.touches[1]),this.lastTouchMid=this.getTouchMidpoint(n.touches[0],n.touches[1]),this.touchActive=!0)},d=t=>{if(t.preventDefault(),t.touches.length===1&&this.touchActive){let n=this.getTouchPos(t.touches[0]);if(this.longPressTimer){let e=n.x-this.touchStartPos.x,t=n.y-this.touchStartPos.y;Math.hypot(e,t)>this.longPressMaxMove&&this.clearLongPress()}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(n),this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(n),this.onOverlayDirty?.();return}let r=e();if(this.tradingManager&&r&&this.tradingManager.onPointerMove(n,r)){this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(n),this.crosshairHandler?.onPointerMove(n)}else if(t.touches.length===2){let e=this.getTouchDistance(t.touches[0],t.touches[1]),n=this.getTouchMidpoint(t.touches[0],t.touches[1]);if(this.lastTouchDist>0){let t=(e/this.lastTouchDist-1)*.5;this.zoomHandler?.onWheel(-t*100,n)}let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=e,this.lastTouchMid=n}this.onOverlayDirty?.()},f=e=>{if(this.clearLongPress(),e.touches.length===0)this.axisDragHandler?.isActive()&&this.axisDragHandler.end(),this.paneResizeHandler?.end(),this.tradingManager?.onPointerUp(),this.panHandler?.onPointerUp(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.lastTouchDist=0;else if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.panHandler?.onPointerDown(t)}},p=()=>this.invalidateRect(),m=()=>this.invalidateRect();this.element.addEventListener(`mousedown`,n),this.element.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i),this.element.addEventListener(`mouseleave`,o),this.element.addEventListener(`dblclick`,a),this.element.addEventListener(`wheel`,s,{passive:!1}),this.element.addEventListener(`contextmenu`,l),this.element.addEventListener(`touchstart`,u,{passive:!1}),this.element.addEventListener(`touchmove`,d,{passive:!1}),this.element.addEventListener(`touchend`,f),document.addEventListener(`keydown`,c),window.addEventListener(`resize`,p),this.element.addEventListener(`scroll`,m,{passive:!0}),this.boundHandlers.push(()=>this.element.removeEventListener(`mousedown`,n),()=>this.element.removeEventListener(`mousemove`,r),()=>document.removeEventListener(`mouseup`,i),()=>this.element.removeEventListener(`mouseleave`,o),()=>this.element.removeEventListener(`dblclick`,a),()=>this.element.removeEventListener(`wheel`,s),()=>this.element.removeEventListener(`contextmenu`,l),()=>this.element.removeEventListener(`touchstart`,u),()=>this.element.removeEventListener(`touchmove`,d),()=>this.element.removeEventListener(`touchend`,f),()=>document.removeEventListener(`keydown`,c),()=>window.removeEventListener(`resize`,p),()=>this.element.removeEventListener(`scroll`,m))}detach(){for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},pn=class{dragging=!1;lastX=0;lastY=0;lastTime=0;velocityX=0;velocityY=0;momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.lastTime=Date.now(),this.velocityX=0,this.velocityY=0,this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=Date.now(),n=this.lastX-e.x,r=this.lastY-e.y,i=t-this.lastTime;i>0&&(this.velocityX=n/i,this.velocityY=r/i),this.lastX=e.x,this.lastY=e.y,this.lastTime=t,this.callback(n,r)}onPointerUp(){this.dragging&&(this.dragging=!1,Math.hypot(this.velocityX,this.velocityY)>.1&&this.startMomentum())}startMomentum(){this.stopMomentum();let e=this.velocityX*16,t=this.velocityY*16,n=()=>{if(e*=this.friction,t*=this.friction,Math.hypot(e,t)<.5){this.momentumId=0;return}this.callback(e,t),this.momentumId=requestAnimationFrame(n)};this.momentumId=requestAnimationFrame(n)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},mn=class{callback;sensitivity;pendingDelta=0;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=this.pendingDelta,t=this.pendingCenterX;this.pendingDelta=0,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},hn=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},gn=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e){let t=this.viewportGetter();if(!t)return!1;let n=this.alerts.getAlertAtPoint(e,t);return n?(this.draggingId=n.id,!0):!1}move(e){if(this.draggingId===null)return;let t=this.viewportGetter();t&&this.alerts.updateAlertPrice(this.draggingId,c(e.y,t))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},_n=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t){for(let n of t.dividers)if(vn(e,n.rect,this.tolerance)){let e=t.panels.find(e=>e.config.id===n.panelId);if(e)return{panelId:n.panelId,orientation:n.orientation,position:e.config.position,size:e.config.size}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e){let t=this.layoutGetter?.();if(!t)return!1;let n=this.hitTest(e,t);return n?(this.state={panelId:n.panelId,position:n.position,startSize:n.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function vn(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var yn=class{position=null;callback=null;data=[];tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}magnetMode=!0;mode=`magnet`;pricePrecision=2;locale=`en-US`;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;setCallback(e){this.callback=e}setData(e){this.data=e}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}onPointerMove(e){this.position=e}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(e,t,n){if(!this.position||this.mode===`hidden`)return;let{chartRect:r}=t,{x:i,y:o}=this.position;if(i<r.x||i>r.x+r.width||o<r.y||o>r.y+r.height)return;let c=s(i,t);if(c=Math.max(0,Math.min(this.data.length-1,c)),this.magnetMode&&c>=0&&c<this.data.length&&(i=a(c,t)),c!==this.lastCallbackBarIndex&&(this.pendingBarIndex=c,this.pendingPoint={x:i,y:o},this.lastCallbackBarIndex=c,this.scheduleCallback()),this.magnetMode&&c>=0&&c<this.data.length){let a=t.barWidth+t.barSpacing,o=a/2;e.fillStyle=n.crosshair,e.globalAlpha=.08,e.fillRect(i-o,r.y,a,r.height),e.globalAlpha=1}e.setLineDash([4,4]),e.strokeStyle=n.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(i)+.5,r.y),e.lineTo(Math.round(i)+.5,r.y+r.height),e.stroke(),e.beginPath(),e.moveTo(r.x,Math.round(o)+.5),e.lineTo(r.x+r.width,Math.round(o)+.5),e.stroke(),e.setLineDash([])}renderAxisLabels(t,n,r,i,o){if(!this.position||this.mode===`hidden`)return;let{chartRect:l}=n,{x:u,y:d}=this.position;if(u<l.x||u>l.x+l.width||d<l.y||d>l.y+l.height)return;let f=s(u,n);f=Math.max(0,Math.min(i.length-1,f)),this.magnetMode&&f>=0&&f<i.length&&(u=a(f,n));let p=`600 ${r.font.sizeSmall}px ${r.font.family}`;if(bn(t,{text:(0,e.formatPrice)(c(d,n),this.pricePrecision,this.locale),anchorX:l.x+l.width,anchorY:d,orientation:`right`,bg:r.text,fg:r.background,font:p}),f>=0&&f<i.length){let e=xn(i[f].time,this.tzOffsetMinutes),n=o??l.y+l.height;bn(t,{text:e,anchorX:u,anchorY:n,orientation:`bottom`,bg:r.text,fg:r.background,font:p})}}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}};function bn(e,t){e.save(),e.font=t.font;let n=Math.ceil(e.measureText(t.text).width)+16;if(t.orientation===`right`){let r=t.anchorX+5,i=t.anchorY-20/2;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(r,t.anchorY-5),e.lineTo(r,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,t.anchorY+5),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(t.text,r+8,t.anchorY)}else{let r=t.anchorX-n/2,i=t.anchorY+5;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX+5,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,i),e.lineTo(t.anchorX-5,i),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`center`,e.fillText(t.text,t.anchorX,i+20/2)}e.restore()}function xn(t,n){let r=(0,e.timeParts)(t>0xe8d4a51000?t:t*1e3,n),{year:i,month:a,day:o,hours:s,minutes:c}=r;return(0,e.isDateOnly)(r)?`${a}/${o}/${i}`:`${a}/${o} ${s<10?`0`+s:s}:${c<10?`0`+c:c}`}var Sn=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},Cn=class{el=null;visible=!1;timeEl;openEl;highEl;lowEl;closeEl;changeEl;volEl;measuredWidth=155;measuredHeight=95;measured=!1;create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`4px`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=this.addLine(this.el);let t=this.addLine(this.el),n=this.addLine(this.el);this.changeEl=this.addLine(this.el),this.volEl=this.addLine(this.el),t.append(this.label(`O `),this.openEl=this.val(),this.label(` H `),this.highEl=this.val()),n.append(this.label(`L `),this.lowEl=this.val(),this.label(` C `),this.closeEl=this.val()),e.appendChild(this.el)}show(e,t,n,r){if(!this.el)return;let i=t.close>=t.open?n.candleUp:n.candleDown,a=e=>e.toFixed(2),o=new Date(t.time);this.timeEl.textContent=`${o.getMonth()+1}/${o.getDate()} ${String(o.getHours()).padStart(2,`0`)}:${String(o.getMinutes()).padStart(2,`0`)}`,this.timeEl.style.color=n.textSecondary,this.openEl.textContent=a(t.open),this.highEl.textContent=a(t.high),this.lowEl.textContent=a(t.low),this.closeEl.textContent=a(t.close),this.openEl.style.color=i,this.highEl.style.color=i,this.lowEl.style.color=i,this.closeEl.style.color=i;let s=t.close-t.open,c=t.open===0?0:s/t.open*100,l=s>=0?`+`:``;this.changeEl.textContent=`${l}${a(s)} (${l}${c.toFixed(2)}%)`,this.changeEl.style.color=i;let u=t.volume;this.volEl.textContent=`Vol ${u>=1e6?(u/1e6).toFixed(1)+`M`:u>=1e3?(u/1e3).toFixed(1)+`K`:u.toFixed(0)}`,this.volEl.style.color=n.textSecondary;let d=wn(n.background);this.el.style.background=d?Tn(n.background,.95):Tn(n.background,.97),this.el.style.border=`1px solid ${n.axisLine}`,this.el.style.boxShadow=d?`0 4px 12px rgba(0,0,0,0.5)`:`0 4px 12px rgba(0,0,0,0.15)`,this.el.style.color=n.text,this.el.style.backdropFilter=`blur(8px)`,!this.measured&&this.visible&&(this.measuredWidth=this.el.offsetWidth,this.measuredHeight=this.el.offsetHeight,this.measured=!0);let f=e.x+16,p=e.y-40;f+this.measuredWidth>r.width-80&&(f=e.x-this.measuredWidth-16),p<4&&(p=4),p+this.measuredHeight>r.height&&(p=r.height-this.measuredHeight-4),this.el.style.transform=`translate(${Math.round(f)}px, ${Math.round(p)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.visible||=(this.el.style.display=`block`,!0)}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.measured=!1}addLine(e){let t=document.createElement(`div`);return e.appendChild(t),t}label(e){let t=document.createElement(`span`);return t.textContent=e,t.style.opacity=`0.6`,t}val(){return document.createElement(`span`)}};function wn(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(t){let e=parseInt(t[1]),n=parseInt(t[2]),r=parseInt(t[3]);return(.299*e+.587*n+.114*r)/255<.5}return!0}function Tn(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var En=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`4px`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let t=document.createElement(`div`);t.textContent=`📌 pinned`,t.style.fontSize=`9px`,t.style.opacity=`0.6`,t.style.marginBottom=`2px`,t.style.letterSpacing=`0.04em`,t.style.textTransform=`uppercase`,this.el.insertBefore(t,this.timeEl),e.appendChild(this.el)}pin(e,t,n){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=e,this.pinnedIndex=t;let r=e.close>=e.open?n.candleUp:n.candleDown,i=new Date(e.time>0xe8d4a51000?e.time:e.time*1e3);this.timeEl.textContent=`${i.getMonth()+1}/${i.getDate()} ${Dn(i.getHours())}:${Dn(i.getMinutes())}`,this.timeEl.style.color=n.textSecondary,this.ohlcEl.innerHTML=`
2
+ <span style="opacity:.6">O </span><span style="color:${r}">${R(e.open)}</span>
3
+ <span style="opacity:.6"> H </span><span style="color:${r}">${R(e.high)}</span>
4
+ <span style="opacity:.6"> L </span><span style="color:${r}">${R(e.low)}</span>
5
+ <span style="opacity:.6"> C </span><span style="color:${r}">${R(e.close)}</span>
6
+ `;let a=On(n.background);this.el.style.background=kn(n.background,a?.96:.97),this.el.style.border=`1px solid ${r}`,this.el.style.boxShadow=a?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=n.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(e,t,n,r){if(!this.el||!this.pinnedBar)return;let i=a(this.pinnedIndex,e),s=o(this.pinnedBar.close,e),c=e.chartRect,l=i>=c.x-4&&i<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,i+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(t&&n!==null&&n!==this.pinnedIndex){let e=t.close-this.pinnedBar.close,i=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,a=e>0?`+`:e<0?`−`:``,o=n-this.pinnedIndex,s=e>=0?r.candleUp:r.candleDown;this.deltaEl.style.color=s,this.deltaEl.innerHTML=`Δ ${a}${R(Math.abs(e))} <span style="opacity:.7">(${a}${Math.abs(i).toFixed(2)}%)</span> · ${o>0?`+`:``}${o} bars`,this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function R(e){return e.toFixed(2)}function Dn(e){return e<10?`0`+e:``+e}function On(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function kn(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var An=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},z=class{hitTestAnchor(e,t,n,r){for(let i=0;i<t.anchors.length;i++){let a=this.anchorToPixel(t.anchors[i],n);if(Math.hypot(e.x-a.x,e.y-a.y)<=r)return i}return-1}anchorToPixel(e,t){return{x:d(e.time,t),y:o(e.price,t)}}pixelToAnchor(e,t){return{time:f(e.x,t),price:c(e.y,t)}}applyLineStyle(e,t){switch(e.strokeStyle=t.color,e.lineWidth=t.lineWidth,t.lineStyle){case`dashed`:e.setLineDash([6,4]);break;case`dotted`:e.setLineDash([2,2]);break;default:e.setLineDash([]);break}}resetLineStyle(e){e.setLineDash([])}renderAnchorHandles(e,t,n){e.fillStyle=`#FFFFFF`,e.strokeStyle=t.style.color,e.lineWidth=1;for(let r of t.anchors){let t=this.anchorToPixel(r,n);e.fillRect(t.x-4,t.y-4,8,8),e.strokeRect(t.x-4,t.y-4,8,8)}}distanceToLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;o=Math.max(0,Math.min(1,o));let s=t.x+o*r,c=t.y+o*i;return Math.hypot(e.x-s,e.y-c)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}},jn=1;function B(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},meta:e.meta?{...e.meta}:void 0}}var Mn=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#2196F3`,lineWidth:1,lineStyle:`solid`,fillColor:`rgba(33, 150, 243, 0.1)`,fillOpacity:.1,fontSize:12};creatingDrawing=null;committedAnchors=0;previewAnchor=null;selectedDrawingId=null;dragAnchorIndex=-1;dragStartPoint=null;dragStartAnchors=[];dragBeforeState=null;eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;dataGetter=null;displayDataGetter=null;register(e){this.registry.set(e.descriptor.type,e)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setDataGetter(e){this.dataGetter=e}setDisplayDataGetter(e){this.displayDataGetter=e}snapToOHLC(e,t,n){if(this.magnetMode===`none`||!this.dataGetter)return{time:e,price:t};let r=this.displayDataGetter?.()??this.dataGetter();if(r.length===0)return{time:e,price:t};let i=!!(n?.data&&n.data.length>0),a=Math.max(0,Math.min(r.length-1,Math.round(i?l(e,r):e))),o=r[a],s=[o.open,o.high,o.low,o.close],c=s[0],u=Math.abs(t-c);for(let e=1;e<s.length;e++){let n=Math.abs(t-s[e]);n<u&&(u=n,c=s[e])}if(n){let e=n.chartRect.height/(n.priceRange.max-n.priceRange.min||1);if(u*e>30)return{time:i?o.time:a,price:t}}return{time:i?o.time:a,price:c}}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}applyUndoAction(e){switch(e.type){case`drawingCreate`:e.after&&(this.drawings=this.drawings.filter(t=>t.id!==e.after.id));break;case`drawingRemove`:e.before&&this.drawings.push(e.before);break;case`drawingModify`:if(e.before){let t=this.drawings.findIndex(t=>t.id===e.before.id);t>=0&&(this.drawings[t]=structuredClone(e.before))}break}this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}applyRedoAction(e){switch(e.type){case`drawingCreate`:e.after&&this.drawings.push(structuredClone(e.after));break;case`drawingRemove`:e.before&&(this.drawings=this.drawings.filter(t=>t.id!==e.before.id));break;case`drawingModify`:if(e.after){let t=this.drawings.findIndex(t=>t.id===e.after.id);t>=0&&(this.drawings[t]=structuredClone(e.after))}break}this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}lockAllDrawings(){for(let e of this.drawings)e.locked=!0;this.requestRender?.()}unlockAllDrawings(){for(let e of this.drawings)e.locked=!1;this.requestRender?.()}hideAllDrawings(){for(let e of this.drawings)e.visible=!1;this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}showAllDrawings(){for(let e of this.drawings)e.visible=!0;this.requestRender?.()}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.visible=t,!t&&this.selectedDrawingId===e&&(this.selectedDrawingId=null),this.requestRender?.(),t):null}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.locked=t,this.requestRender?.(),t):null}setActiveTool(e){this.activeTool=e,this.state=e?`creating`:`idle`,this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t??this.selectedDrawingId;if(!n)return!1;let r=this.drawings.find(e=>e.id===n);if(!r||r.locked)return!1;let i=B(r);return r.style={...r.style,...e},this.undoRedo?.push({type:`drawingModify`,before:i,after:B(r)}),this.requestRender?.(),!0}onPointerDown(e,t){return this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t):!1}onPointerMove(e,t){if(this.state===`creating`&&this.creatingDrawing){let n=this.registry.get(this.creatingDrawing.type);if(n&&this.committedAnchors<n.descriptor.requiredAnchors){let n=f(e.x,t),r=c(e.y,t);return this.previewAnchor=this.snapToOHLC(n,r,t),this.requestRender?.(),!0}}return this.state===`moving`&&this.selectedDrawingId&&this.dragStartPoint?this.handleMove(e,t):this.state===`resizing`&&this.selectedDrawingId&&this.dragAnchorIndex>=0?this.handleResize(e,t):!1}onPointerUp(){if(this.state===`moving`||this.state===`resizing`){if(this.dragBeforeState&&this.selectedDrawingId){let e=this.drawings.find(e=>e.id===this.selectedDrawingId);e&&this.undoRedo?.push({type:`drawingModify`,before:this.dragBeforeState,after:B(e)})}return this.state=`selected`,this.dragStartPoint=null,this.dragStartAnchors=[],this.dragAnchorIndex=-1,this.dragBeforeState=null,!0}return!1}onKeyDown(e,t=!1){if(t&&(e===`d`||e===`D`)&&this.state===`selected`&&this.selectedDrawingId&&this.duplicateDrawing(this.selectedDrawingId)||t&&(e===`z`||e===`Z`)&&this.undo()||t&&(e===`y`||e===`Y`)&&this.redo())return!0;if(e===`Escape`){if(this.state===`creating`)return this.setActiveTool(null),this.requestRender?.(),!0;if(this.state===`selected`)return this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.(),!0}return(e===`Delete`||e===`Backspace`)&&this.state===`selected`&&this.selectedDrawingId?this.drawings.find(e=>e.id===this.selectedDrawingId)?.locked?!1:(this.removeDrawing(this.selectedDrawingId),this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.(),!0):!1}getDrawings(){return this.drawings}setDrawings(e){this.drawings=this.upgradeLegacyAnchors(e),this.requestRender?.()}addDrawing(e){let t=e.id??`tc_drawing_${jn++}`,n={id:t,type:e.type,anchors:e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,meta:e.meta};return this.drawings=[...this.drawings,n],this.undoRedo?.push({type:`drawingCreate`,before:null,after:B(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();return!t||t.length===0?e:e.map(e=>({...e,anchors:e.anchors.map(e=>{if(e.time>=1e9)return e;let n=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[n].time}})}))}removeDrawing(e){let t=this.drawings.find(t=>t.id===e);this.drawings=this.drawings.filter(t=>t.id!==e),t&&this.undoRedo?.push({type:`drawingRemove`,before:structuredClone(t),after:null}),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=`tc_drawing_${jn++}`;let r=this.computeBarOffsetTime(3);return n.anchors=n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selectedDrawingId=n.id,this.state=`selected`,this.eventCallback?.(`drawingCreate`,{drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.drawings=[],this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selectedDrawingId}render(e,t){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip();for(let n of this.drawings){if(!n.visible)continue;let r=this.registry.get(n.type);if(!r)continue;let i=n.id===this.selectedDrawingId;r.render(e,n,t,i)}if(this.creatingDrawing&&this.committedAnchors>0){let n=this.registry.get(this.creatingDrawing.type);if(n){let r={...this.creatingDrawing,anchors:this.previewAnchor?[...this.creatingDrawing.anchors,this.previewAnchor]:[...this.creatingDrawing.anchors]};n.render(e,r,t,!1)}}e.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}handleCreationClick(e,t){if(!this.activeTool)return!1;let n=this.registry.get(this.activeTool);if(!n)return!1;let r=f(e.x,t),i=c(e.y,t),a=this.snapToOHLC(r,i,t);return this.creatingDrawing?(this.creatingDrawing.anchors.push(a),this.committedAnchors++,this.previewAnchor=null,this.committedAnchors>=n.descriptor.requiredAnchors&&this.finalizeCreation(),this.requestRender?.(),!0):(this.creatingDrawing={id:`tc_drawing_${jn++}`,type:this.activeTool,anchors:[a],style:{...this.activeStyle},visible:!0,locked:!1},this.committedAnchors=1,this.previewAnchor=null,n.descriptor.requiredAnchors===1&&this.finalizeCreation(),this.requestRender?.(),!0)}finalizeCreation(){this.creatingDrawing&&(this.drawings.push(this.creatingDrawing),this.selectedDrawingId=this.creatingDrawing.id,this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(this.creatingDrawing)}),this.eventCallback?.(`drawingCreate`,{drawing:this.creatingDrawing}),this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null,this.activeTool=null,this.state=`selected`)}handleSelectionClick(e,t){if(this.selectedDrawingId){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(n&&!n.locked){let r=this.registry.get(n.type);if(r){let i=r.hitTestAnchor(e,n,t,8);if(i>=0)return this.state=`resizing`,this.dragAnchorIndex=i,this.dragStartPoint=e,this.dragBeforeState=B(n),!0;if(r.hitTest(e,n,t,8))return this.state=`moving`,this.dragStartPoint=e,this.dragStartAnchors=n.anchors.map(e=>({...e})),this.dragBeforeState=B(n),!0}}}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!r.visible)continue;let i=this.registry.get(r.type);if(i&&i.hitTest(e,r,t,8))return this.selectedDrawingId=r.id,this.state=`selected`,this.requestRender?.(),!0}return this.selectedDrawingId&&(this.selectedDrawingId=null,this.state=`idle`,this.requestRender?.()),!1}handleMove(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(!n||!this.dragStartPoint)return!1;let r=f(e.x,t)-f(this.dragStartPoint.x,t),i=c(e.y,t)-c(this.dragStartPoint.y,t);return n.anchors=this.dragStartAnchors.map(e=>({time:e.time+r,price:e.price+i})),this.requestRender?.(),!0}handleResize(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);return!n||this.dragAnchorIndex<0?!1:(n.anchors[this.dragAnchorIndex]={time:f(e.x,t),price:c(e.y,t)},this.requestRender?.(),!0)}},Nn=class{constructor(e){this.manager=e}render(e,t){this.manager.render(e,t)}};function Pn(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}var Fn=class extends z{descriptor={type:`trendLine`,name:`Trend Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},In=class extends z{descriptor={type:`horizontalLine`,name:`Horizontal Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=o(t.anchors[0].price,n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i),e.lineTo(a.x+a.width,i),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(t.anchors[0].price.toFixed(2),a.x+4,i-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=o(t.anchors[0].price,n);return Math.abs(e.y-i)<=r&&e.x>=n.chartRect.x&&e.x<=n.chartRect.x+n.chartRect.width}},Ln=class extends z{descriptor={type:`verticalLine`,name:`Vertical Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;return Math.abs(e.x-i.x)<=r&&e.y>=a.y&&e.y<=a.y+a.height}},Rn=class extends z{descriptor={type:`ray`,name:`Ray`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x+s/l*u,f=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(d,f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;return((e.x-i.x)*o+(e.y-i.y)*s)/(o*o+s*s)<0?!1:this.distanceToInfiniteLine(e,i,a)<=r}},zn=class extends z{descriptor={type:`extendedLine`,name:`Extended Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x-s/l*u,f=i.y-c/l*u,p=i.x+s/l*u,m=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToInfiniteLine(e,i,a)<=r}},Bn=class extends z{descriptor={type:`parallelChannel`,name:`Parallel Channel`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),t.anchors.length>=3){let r=this.anchorToPixel(t.anchors[2],n),o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s)||1,l=-s/c,u=o/c,d=(r.x-i.x)*l+(r.y-i.y)*u,f={x:i.x+l*d,y:i.y+u*d},p={x:a.x+l*d,y:a.y+u*d};e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(p.x,p.y),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.lineTo(p.x,p.y),e.lineTo(f.x,f.y),e.closePath(),e.fill())}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.distanceToLine(e,i,a)<=r)return!0;if(t.anchors.length>=3){let o=this.anchorToPixel(t.anchors[2],n),s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c)||1,u=-c/l,d=s/l,f=(o.x-i.x)*u+(o.y-i.y)*d,p={x:i.x+u*f,y:i.y+d*f},m={x:a.x+u*f,y:a.y+d*f};if(this.distanceToLine(e,p,m)<=r)return!0}return!1}},Vn=class extends z{descriptor={type:`regressionChannel`,name:`Regression Channel`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s);if(c===0){this.resetLineStyle(e);return}let l=Math.max(10,Math.min(c*.2,100)),u=-s/c*l,d=o/c*l;e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.stroke(),e.beginPath(),e.moveTo(i.x-u,i.y-d),e.lineTo(a.x-u,a.y-d),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.lineTo(a.x-u,a.y-d),e.lineTo(i.x-u,i.y-d),e.closePath(),e.fill()),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.hypot(a.x-i.x,a.y-i.y),s=Math.max(10,Math.min(o*.2,100));return this.distanceToLine(e,i,a)<=r+s}},V=[0,.236,.382,.5,.618,.786,1],Hn=class extends z{descriptor={type:`fibRetracement`,name:`Fibonacci Retracement`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`;for(let r of V){let a=s+c*(1-r),l=o(a,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.7,e.beginPath(),e.moveTo(i.x,l),e.lineTo(i.x+i.width,l),e.stroke(),e.fillStyle=t.style.color,e.textAlign=`left`,e.fillText(`${(r*100).toFixed(1)}% (${a.toFixed(2)})`,i.x+4,l-2)}if(e.globalAlpha=1,t.style.fillColor){for(let r=0;r<V.length-1;r++){let a=s+c*(1-V[r]),l=s+c*(1-V[r+1]),u=o(a,n),d=o(l,n);e.fillStyle=t.style.fillColor,e.globalAlpha=.05+r*.02,e.fillRect(i.x,Math.min(u,d),i.width,Math.abs(d-u))}e.globalAlpha=1}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;for(let t of V){let i=o(s+c*(1-t),n);if(Math.abs(e.y-i)<=r)return!0}return!1}},Un=[0,.618,1,1.618,2,2.618,3.618,4.236],Wn=class extends z{descriptor={type:`fibExtension`,name:`Fibonacci Extension`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=t.anchors[2].price,l=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;for(let r of Un){let a=o(c+l*r,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.6,e.beginPath(),e.moveTo(i.x,a),e.lineTo(i.x+i.width,a),e.stroke(),e.fillStyle=t.style.color,e.fillText(`${(r*100).toFixed(1)}%`,i.x+4,a-2)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price-t.anchors[1].price;for(let i of Un){let s=o(t.anchors[2].price+a*i,n);if(Math.abs(e.y-s)<=r)return!0}return!1}},Gn=class extends z{descriptor={type:`rectangle`,name:`Rectangle`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y);t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fillRect(o,s,c,l)),this.applyLineStyle(e,t.style),e.strokeRect(o,s,c,l),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.min(i.y,a.y)-r,c=Math.max(i.x,a.x)+r,l=Math.max(i.y,a.y)+r;if(e.x<o||e.x>c||e.y<s||e.y>l)return!1;let u=Math.min(i.x,a.x)+r,d=Math.min(i.y,a.y)+r,f=Math.max(i.x,a.x)-r,p=Math.max(i.y,a.y)-r;return!(e.x>u&&e.x<f&&e.y>d&&e.y<p)||!!t.style.fillColor}},Kn=class extends z{descriptor={type:`ellipse`,name:`Ellipse`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.abs(a.x-i.x)/2,l=Math.abs(a.y-i.y)/2;e.beginPath(),e.ellipse(o,s,Math.max(c,1),Math.max(l,1),0,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.max(Math.abs(a.x-i.x)/2,1),l=Math.max(Math.abs(a.y-i.y)/2,1),u=(e.x-o)/c,d=(e.y-s)/l,f=Math.sqrt(u*u+d*d),p=r/Math.max(Math.min(c,l),4);return t.style.fillColor?f<=1+p:Math.abs(f-1)<=p}},qn=class extends z{descriptor={type:`triangle`,name:`Triangle`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=t.anchors.map(e=>this.anchorToPixel(e,n));e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.lineTo(i[2].x,i[2].y),e.closePath(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<3;t++){let n=(t+1)%3;if(this.distanceToLine(e,i[t],i[n])<=r)return!0}return!1}},Jn=class extends z{descriptor={type:`pitchfork`,name:`Andrews' Pitchfork`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s={x:(a.x+o.x)/2,y:(a.y+o.y)/2},c=s.x-i.x,l=s.y-i.y,u=Math.hypot(c,l)||1,d=Math.hypot(n.chartRect.width,n.chartRect.height),f=i.x+c/u*d,p=i.y+l/u*d;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(f,p),e.stroke(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x+c/u*d,a.y+l/u*d),e.stroke(),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x+c/u*d,o.y+l/u*d),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s={x:(a.x+o.x)/2,y:(a.y+o.y)/2};if(this.distanceToInfiniteLine(e,i,s)<=r)return!0;let c=s.x-i.x,l=s.y-i.y,u={x:a.x+c,y:a.y+l},d={x:o.x+c,y:o.y+l};return this.distanceToInfiniteLine(e,a,u)<=r||this.distanceToInfiniteLine(e,o,d)<=r}},Yn=[`1`,`2`,`3`,`4`,`5`,`A`,`B`,`C`],Xn=class extends z{descriptor={type:`elliottWave`,name:`Elliott Wave`,requiredAnchors:8};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<i.length&&t<Yn.length;t++){let n=t%2==0?-12:12;e.textBaseline=n<0?`bottom`:`top`,e.fillText(Yn[t],i[t].x,i[t].y+n)}r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},Zn=class extends z{descriptor={type:`priceRange`,name:`Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.abs(a.x-i.x),c=Math.min(i.y,a.y),l=Math.abs(a.y-i.y),u=t.anchors[1].price>t.anchors[0].price;e.fillStyle=u?`rgba(38, 166, 154, 0.15)`:`rgba(239, 83, 80, 0.15)`,e.fillRect(o,c,s,l),this.applyLineStyle(e,t.style),e.strokeRect(o,c,s,l),this.resetLineStyle(e);let d=t.anchors[1].price-t.anchors[0].price,f=t.anchors[0].price===0?0:d/t.anchors[0].price*100,p=`${d>=0?`+`:``}${d.toFixed(2)} (${f>=0?`+`:``}${f.toFixed(2)}%)`;e.font=`12px sans-serif`,e.fillStyle=u?`#26A69A`:`#EF5350`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(p,o+s/2,c+l/2),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return e.x>=o-r&&e.x<=s+r&&e.y>=c-r&&e.y<=l+r}},Qn=class extends z{descriptor={type:`dateRange`,name:`Date Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);e.fillStyle=`rgba(33, 150, 243, 0.08)`,e.fillRect(s,o.y,c-s,o.height),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(c,o.y),e.lineTo(c,o.y+o.height),e.stroke(),this.resetLineStyle(e);let l=u(t.anchors[0].time,n),d=u(t.anchors[1].time,n),f=Math.max(0,Math.round(Math.abs(d-l)));e.font=`12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`,e.textBaseline=`top`,e.fillText(`${f} bars`,(s+c)/2,o.y+4),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);return e.x>=s-r&&e.x<=c+r&&e.y>=o.y&&e.y<=o.y+o.height}},$n=class extends z{descriptor={type:`measure`,name:`Measure`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=t.anchors[1].price-t.anchors[0].price,s=u(t.anchors[0].time,n),c=u(t.anchors[1].time,n),l=Math.max(0,Math.round(Math.abs(c-s))),d=t.anchors[0].price===0?0:o/t.anchors[0].price*100,f=[`Price: ${o>=0?`+`:``}${o.toFixed(2)} (${d>=0?`+`:``}${d.toFixed(2)}%)`,`Bars: ${l}`],p=(i.x+a.x)/2,m=(i.y+a.y)/2;e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`bottom`;let h=Math.max(...f.map(t=>e.measureText(t).width));e.fillStyle=`rgba(0, 0, 0, 0.7)`,e.fillRect(p-h/2-6,m-f.length*14-4,h+12,f.length*14+8),e.fillStyle=`#FFFFFF`;for(let t=0;t<f.length;t++)e.fillText(f[t],p,m-(f.length-1-t)*14);r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}};function er(e,t=`Text`){if(typeof e.style.text==`string`&&e.style.text.length>0)return e.style.text;let n=e.meta?.text;return typeof n==`string`&&n.length>0?n:t}var tr=class extends z{descriptor={type:`text`,name:`Text`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=er(t),o=t.style.fontSize||14;if(e.font=`${o}px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`left`,e.textBaseline=`top`,r){let n=e.measureText(a);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.strokeRect(i.x-2,i.y-2,n.width+4,o+4),e.setLineDash([])}e.fillText(a,i.x,i.y),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=t.style.fontSize||14;return e.x>=i.x-r&&e.x<=i.x+80+r&&e.y>=i.y-r&&e.y<=i.y+a+r}},nr=class extends z{descriptor={type:`arrow`,name:`Arrow`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=Math.atan2(a.y-i.y,a.x-i.x);e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x-12*Math.cos(o-Math.PI/6),a.y-12*Math.sin(o-Math.PI/6)),e.lineTo(a.x-12*Math.cos(o+Math.PI/6),a.y-12*Math.sin(o+Math.PI/6)),e.closePath(),e.fillStyle=t.style.color,e.fill(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},rr=[{label:`8x1`,ratio:8},{label:`4x1`,ratio:4},{label:`3x1`,ratio:3},{label:`2x1`,ratio:2},{label:`1x1`,ratio:1},{label:`1x2`,ratio:.5},{label:`1x3`,ratio:1/3},{label:`1x4`,ratio:.25},{label:`1x8`,ratio:.125}],ir=class extends z{descriptor={type:`gannFan`,name:`Gann Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;this.applyLineStyle(e,t.style);for(let{label:n,ratio:r}of rr){let a=c*r,o=d,s=i.y+a*(o-i.x);e.globalAlpha=r===1?1:.5,e.lineWidth=r===1?t.style.lineWidth:Math.max(.5,t.style.lineWidth*.7),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o,s),e.stroke();let f=o-l*4,p=s;p>u.y&&p<u.y+u.height&&(e.globalAlpha=.7,e.fillStyle=t.style.color,e.font=`9px sans-serif`,e.textAlign=l>0?`right`:`left`,e.textBaseline=`bottom`,e.fillText(n,f,p-2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return!1;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;for(let{ratio:t}of rr){let n=c*t,a=d,o=i.y+n*(a-i.x);if(this.distanceToLine(e,i,{x:a,y:o})<=r)return!0}return!1}},ar=[0,.25,.333,.5,.667,.75,1],or=class extends z{descriptor={type:`gannBox`,name:`Gann Box`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y),u=s-o,d=l-c;if(!(u<2||d<2)){this.applyLineStyle(e,t.style),e.strokeRect(o,c,u,d),e.save(),e.globalAlpha=.35;for(let t of ar){if(t===0||t===1)continue;let n=c+d*t;e.beginPath(),e.moveTo(o,n),e.lineTo(s,n),e.stroke()}for(let t of ar){if(t===0||t===1)continue;let n=o+u*t;e.beginPath(),e.moveTo(n,c),e.lineTo(n,l),e.stroke()}e.globalAlpha=.5,e.setLineDash([4,3]),e.beginPath(),e.moveTo(o,c),e.lineTo(s,l),e.stroke(),e.beginPath(),e.moveTo(s,c),e.lineTo(o,l),e.stroke(),e.restore(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`8px sans-serif`,e.globalAlpha=.6,e.textBaseline=`bottom`,e.textAlign=`right`;for(let t of ar){if(t===0||t===1)continue;let n=c+d*t;e.fillText(`${(t*100).toFixed(0)}%`,o-3,n)}e.globalAlpha=1,r&&this.renderAnchorHandles(e,t,n)}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return Math.abs(e.x-o)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.x-s)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.y-c)<=r&&e.x>=o-r&&e.x<=s+r||Math.abs(e.y-l)<=r&&e.x>=o-r&&e.x<=s+r||this.distanceToLine(e,{x:o,y:c},{x:s,y:l})<=r||this.distanceToLine(e,{x:s,y:c},{x:o,y:l})<=r}},sr=class extends z{descriptor={type:`anchoredVWAP`,name:`Anchored VWAP`,requiredAnchors:1};dataGetter=null;showBands=!0;setDataGetter(e){this.dataGetter=e}setShowBands(e){this.showBands=e}render(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return;let i=this.dataGetter(),s=Math.max(0,Math.round(u(t.anchors[0].time,n)));if(s>=i.length)return;let{vwap:c,upper1:l,lower1:d,upper2:f,lower2:p}=this.computeVWAP(i,s),{chartRect:m}=n,h=n.barWidth+n.barSpacing;if(this.applyLineStyle(e,t.style),e.lineWidth=t.style.lineWidth+.5,this.drawLine(e,c,s,n,m,h),this.showBands&&c.length>1&&(e.globalAlpha=.4,e.lineWidth=Math.max(.5,t.style.lineWidth*.6),e.setLineDash([4,3]),this.drawLine(e,l,s,n,m,h),this.drawLine(e,d,s,n,m,h),e.globalAlpha=.25,this.drawLine(e,f,s,n,m,h),this.drawLine(e,p,s,n,m,h),e.globalAlpha=1),this.resetLineStyle(e),c.length>0){let r=c[c.length-1],i=a(s+c.length-1,n),l=o(r,n);i>=m.x&&i<=m.x+m.width&&(e.fillStyle=t.style.color,e.font=`bold 9px sans-serif`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`AVWAP ${r.toFixed(2)}`,i+6,l))}r&&this.renderAnchorHandles(e,t,n)}drawLine(e,t,n,r,i,s){e.beginPath();let c=!1;for(let l=0;l<t.length;l++){let u=a(n+l,r);if(u<i.x-s)continue;if(u>i.x+i.width+s)break;let d=o(t[l],r);c?e.lineTo(u,d):(e.moveTo(u,d),c=!0)}e.stroke()}computeVWAP(e,t){let n=e.length-t,r=Array(n),i=Array(n),a=Array(n),o=Array(n),s=Array(n),c=0,l=0,u=0;for(let d=0;d<n;d++){let n=e[t+d],f=(n.high+n.low+n.close)/3,p=n.volume??1;c+=f*p,l+=p,u+=f*f*p;let m=l>0?c/l:f;r[d]=m;let h=l>0?u/l-m*m:0,g=Math.sqrt(Math.max(0,h));i[d]=m+g,a[d]=m-g,o[d]=m+2*g,s[d]=m-2*g}return{vwap:r,upper1:i,lower1:a,upper2:o,lower2:s}}hitTest(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return!1;let i=this.dataGetter(),s=Math.max(0,Math.round(u(t.anchors[0].time,n)));if(s>=i.length)return!1;let{vwap:c}=this.computeVWAP(i,s);for(let t=1;t<c.length;t++){let i=a(s+t-1,n),l=o(c[t-1],n),u=a(s+t,n),d=o(c[t],n);if(this.distanceToLine(e,{x:i,y:l},{x:u,y:d})<=r)return!0}return!1}},cr=class extends z{descriptor={type:`volumeProfileRange`,name:`Volume Profile (Range)`,requiredAnchors:2};dataGetter=null;numBins=40;setDataGetter(e){this.dataGetter=e}render(e,t,n,r){if(t.anchors.length<2||!this.dataGetter)return;let i=this.dataGetter(),s=Math.round(u(t.anchors[0].time,n)),c=Math.round(u(t.anchors[1].time,n)),l=Math.max(0,Math.min(s,c)),d=Math.min(i.length-1,Math.max(s,c));if(l>=i.length||d<0||l>d)return;let f=1/0,p=-1/0;for(let e=l;e<=d;e++)i[e].low<f&&(f=i[e].low),i[e].high>p&&(p=i[e].high);if(f>=p)return;let m=(p-f)/this.numBins,h=new Float64Array(this.numBins),g=0;for(let e=l;e<=d;e++){let t=i[e],n=t.volume??1,r=Math.max(0,Math.floor((t.low-f)/m)),a=Math.min(this.numBins-1,Math.floor((t.high-f)/m)),o=n/(a-r+1);for(let e=r;e<=a;e++)h[e]+=o,h[e]>g&&(g=h[e])}if(g===0)return;let _=0;for(let e=1;e<this.numBins;e++)h[e]>h[_]&&(_=e);let v=a(d,n)+n.barWidth,y=t.style.color,b=t.style.fillColor??`#FF9800`;e.save();for(let t=0;t<this.numBins;t++){let r=h[t]/g*100,i=f+(t+1)*m,a=f+t*m,s=o(i,n),c=o(a,n),l=Math.abs(c-s);e.globalAlpha=.35,e.fillStyle=t===_?b:y,e.fillRect(v,Math.min(s,c),r,Math.max(1,l-.5))}let x=f+(_+.5)*m,S=o(x,n);e.globalAlpha=.7,e.strokeStyle=b,e.lineWidth=1,e.setLineDash([4,3]),e.beginPath();let C=a(l,n)-n.barWidth/2;e.moveTo(C,S),e.lineTo(v+100,S),e.stroke(),e.fillStyle=b,e.font=`9px sans-serif`,e.textAlign=`left`,e.textBaseline=`bottom`,e.globalAlpha=.8,e.fillText(`POC ${x.toFixed(2)}`,v+100+4,S-2),e.restore(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.max(i.x,a.x)+100+r,c=Math.min(i.y,a.y)-r,l=Math.max(i.y,a.y)+r;return e.x>=o&&e.x<=s&&e.y>=c&&e.y<=l}},lr=[1,2,3,5,8,13,21,34,55],ur=class extends z{descriptor={type:`fibTimeZones`,name:`Fibonacci Time Zones`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return;let{chartRect:o}=n;e.font=`11px sans-serif`,e.textBaseline=`top`,e.textAlign=`center`,this.applyLineStyle(e,t.style);for(let r of lr){let s=d(i.time+a*r,n);s<o.x||s>o.x+o.width||(e.globalAlpha=r===1?1:.55,e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.fillStyle=t.style.color,e.fillText(String(r),s,o.y+2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return!1;let{chartRect:o}=n;if(e.y<o.y||e.y>o.y+o.height)return!1;for(let t of lr){let o=d(i.time+a*t,n);if(Math.abs(e.x-o)<=r)return!0}return!1}};function dr(e){e.register(new Fn),e.register(new In),e.register(new Ln),e.register(new Rn),e.register(new zn),e.register(new Bn),e.register(new Vn),e.register(new Hn),e.register(new Wn),e.register(new Gn),e.register(new Kn),e.register(new qn),e.register(new Jn),e.register(new Xn),e.register(new Zn),e.register(new Qn),e.register(new $n),e.register(new tr),e.register(new nr),e.register(new ir),e.register(new or),e.register(new sr),e.register(new cr),e.register(new ur)}var fr=class{render(e,t,n,r,i,a){let s=i.orderColors?.buy??`#26A69A`,c=i.orderColors?.sell??`#EF5350`,{chartRect:l}=n;for(let i of t){let t=a?.orderId===i.id&&a.sourceType===`order`,u=o(t?a.currentPrice:i.price,n);if(u<l.y||u>l.y+l.height)continue;let d=i.side===`buy`?s:c;e.setLineDash([6,4]),e.strokeStyle=d,e.lineWidth=1,e.beginPath(),e.moveTo(l.x,Math.round(u)+.5),e.lineTo(l.x+l.width,Math.round(u)+.5),e.stroke(),e.setLineDash([]);let f=i.label??i.type.toUpperCase();e.font=`bold 10px ${r.font.family}`;let p=e.measureText(f).width+8;e.fillStyle=d,e.fillRect(l.x+4,u-8,p,16),e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(f,l.x+8,u);let m=l.x+4+p+6;if(e.fillStyle=d,e.beginPath(),i.side===`buy`?(e.moveTo(m,u+4),e.lineTo(m+5,u-2),e.lineTo(m+10,u+4)):(e.moveTo(m,u-4),e.lineTo(m+5,u+2),e.lineTo(m+10,u-4)),e.fill(),t){let t=o(a.startPrice,n);e.setLineDash([2,4]),e.strokeStyle=d,e.globalAlpha=.3,e.beginPath(),e.moveTo(l.x,Math.round(t)+.5),e.lineTo(l.x+l.width,Math.round(t)+.5),e.stroke(),e.globalAlpha=1,e.setLineDash([])}}}renderAxisBadges(t,n,r,i,a,s){let c=a.orderColors?.buy??`#26A69A`,l=a.orderColors?.sell??`#EF5350`,u=a.pricePrecision??2,{chartRect:d}=r,f=d.x+d.width+1;for(let a of n){let n=s?.orderId===a.id&&s.sourceType===`order`?s.currentPrice:a.price,p=o(n,r);if(p<d.y||p>d.y+d.height)continue;let m=a.side===`buy`?c:l,h=`${n.toFixed(u)} x ${a.quantity}`;t.font=`11px ${i.font.family}`;let g=t.measureText(h).width+10;t.fillStyle=m,t.fillRect(f,p-9,Math.min(g,e.PRICE_AXIS_WIDTH-2),18),t.fillStyle=`#FFFFFF`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(h,f+5,p)}}hitTest(e,t,n,r){for(let i of t){if(i.draggable===!1)continue;let t=o(i.price,n);if(Math.abs(e-t)<=r)return i}return null}};function pr(e,t,n){let r=Math.min(Math.max(e.closedQuantity??0,0),e.quantity),i=e.quantity-r,a=e.side===`buy`?1:-1,o=(t-e.entryPrice)*i*a,s=e.entryPrice===0?0:(t-e.entryPrice)/e.entryPrice*100*a;return{side:e.side,quantity:e.quantity,closedQuantity:r,openQuantity:i,entryPrice:e.entryPrice,currentPrice:t,pnl:o,pnlPct:s,precision:n}}var mr=/\{(side|qty|closedQty|openQty|entry|price|pnl|pnlPct|pnlSign)\}/g;function hr(e,t){return e.replace(mr,(e,n)=>{switch(n){case`side`:return t.side.toUpperCase();case`qty`:return String(t.quantity);case`closedQty`:return String(t.closedQuantity);case`openQty`:return String(t.openQuantity);case`entry`:return t.entryPrice.toFixed(t.precision);case`price`:return t.currentPrice.toFixed(t.precision);case`pnl`:return t.pnl.toFixed(t.precision);case`pnlPct`:return`${t.pnlPct.toFixed(2)}%`;case`pnlSign`:return t.pnl>=0?`+`:``;default:return``}})}function gr(e,t){return typeof e==`function`?e(t):hr(e??`{side} {qty} | P&L: {pnlSign}{pnl}`,t)}function _r(e,t,n){if(!t||t.length===0)return n;let r=[...t].sort((e,t)=>e.pnl-t.pnl),i;for(let t of r)if(e>=t.pnl)i=t.color;else break;return i??n}var vr=class{render(e,t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.profit??`#26A69A`,l=a.positionColors?.loss??`#EF5350`,u=a.positionColors?.entry??`#2196F3`,d=a.pricePrecision??2;for(let f of t){let t=o(f.entryPrice,r);if(e.strokeStyle=u,e.lineWidth=1.5,e.setLineDash([]),e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),n!==null){let p=o(n,r),m=pr(f,n,d),h=m.pnl,g=h>=0?c:l,_=_r(h,a.pnlThresholds,g);e.fillStyle=_,e.globalAlpha=.08;let v=Math.min(t,p),y=Math.abs(p-t);if(e.fillRect(s.x,v,s.width,y),e.globalAlpha=1,m.closedQuantity>0&&f.quantity>0){let t=m.closedQuantity/f.quantity;e.fillStyle=u,e.globalAlpha=.25,e.fillRect(s.x,v,Math.max(2,s.width*t*.04)+2,y),e.globalAlpha=1}let b=gr(a.positionLabel,m);e.font=`bold 11px ${i.font.family}`;let x=e.measureText(b).width+12,S=s.x+8;e.fillStyle=_,e.globalAlpha=.9,e.fillRect(S,t-10,x,20),e.globalAlpha=1,e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(b,S+6,t)}if(f.stopLoss!==void 0){let t=o(f.stopLoss,r);e.setLineDash([4,4]),e.strokeStyle=l,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=l,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`SL`,s.x+8,t)}if(f.takeProfit!==void 0){let t=o(f.takeProfit,r);e.setLineDash([4,4]),e.strokeStyle=c,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=c,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`TP`,s.x+8,t)}e.setLineDash([])}}renderAxisBadges(t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.entry??`#2196F3`,l=a.pricePrecision??2,u=s.x+s.width+1;for(let a of n){let n=o(a.entryPrice,r);t.fillStyle=c,t.fillRect(u,n-9,e.PRICE_AXIS_WIDTH-2,18),t.fillStyle=`#FFFFFF`,t.font=`11px ${i.font.family}`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(a.entryPrice.toFixed(l),u+5,n)}}},yr=class{render(e,t,n,r){if(!r.depthOverlay?.enabled)return;let{chartRect:i}=n,a=r.depthOverlay.bidColor??`rgba(38,166,154,0.15)`,s=r.depthOverlay.askColor??`rgba(239,83,80,0.15)`,c=r.depthOverlay.maxWidth??100,l=0,u=[],d=0;for(let e of t.bids)d+=e.volume,u.push({price:e.price,cumVol:d}),d>l&&(l=d);let f=[];d=0;for(let e of t.asks)d+=e.volume,f.push({price:e.price,cumVol:d}),d>l&&(l=d);if(l===0)return;let p=Math.max(1,t.bids.length>1?Math.abs(o(t.bids[0].price,n)-o(t.bids[1].price,n)):4),m=i.x+i.width;e.fillStyle=a;for(let{price:t,cumVol:r}of u){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}e.fillStyle=s;for(let{price:t,cumVol:r}of f){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}}},br=class{dragState=null;startY=0;dragging=!1;constructor(e=3){this.dragThreshold=e}onPointerDown(e,t,n,r,i){for(let n of t){if(n.draggable===!1)continue;let t=o(n.price,r);if(Math.abs(e.y-t)<=i)return this.dragState={orderId:n.id,sourceType:`order`,startPrice:n.price,currentPrice:n.price},this.startY=e.y,this.dragging=!1,!0}for(let t of n){if(t.stopLoss!==void 0){let n=o(t.stopLoss,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`stopLoss`,startPrice:t.stopLoss,currentPrice:t.stopLoss},this.startY=e.y,this.dragging=!1,!0}if(t.takeProfit!==void 0){let n=o(t.takeProfit,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`takeProfit`,startPrice:t.takeProfit,currentPrice:t.takeProfit},this.startY=e.y,this.dragging=!1,!0}}return!1}onPointerMove(e,t){if(!this.dragState)return!1;if(!this.dragging){if(Math.abs(e.y-this.startY)<this.dragThreshold)return!0;this.dragging=!0}return this.dragState.currentPrice=c(e.y,t),!0}onPointerUp(){if(!this.dragState)return null;let e=this.dragState;return this.dragState=null,this.dragging?(this.dragging=!1,{sourceType:e.sourceType,id:e.orderId,newPrice:e.currentPrice,previousPrice:e.startPrice}):null}getDragState(){return this.dragState}isActive(){return this.dragState!==null}},xr=class{menuElement=null;removeHandler=null;onItemSelect=null;show(e,t,n,r){if(this.hide(),!r.contextMenu?.enabled)return;let i=r.pricePrecision??2,a=t.toFixed(i),o=document.createElement(`div`);o.style.cssText=`
7
7
  position: absolute;
8
8
  left: ${e.x}px;
9
9
  top: ${e.y}px;
@@ -21,6 +21,6 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
21
21
  cursor: pointer;
22
22
  color: ${n?`#26A69A`:`#EF5350`};
23
23
  transition: background 0.1s;
24
- `,t.addEventListener(`mouseenter`,()=>{t.style.background=`#2a2e39`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),o.appendChild(t)}n.appendChild(o),this.menuElement=o;let c=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!o.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,c),document.addEventListener(`keydown`,c),this.removeHandler=()=>{document.removeEventListener(`mousedown`,c),document.removeEventListener(`keydown`,c)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function br(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function xr(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var Sr=6,Cr=class{draft=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=br(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(e,t){if(!this.draft)return null;let n=[`entry`,`sl`,`tp`],r=null,i=Sr;for(let a of n){let n=o(this.priceOf(a),t),s=Math.abs(n-e.y);s<=i&&(i=s,r=a)}return r}beginDrag(e,t){let n=this.hitTest(e,t);return n?(this.dragging=n,!0):!1}drag(e,t){if(!this.draft||!this.dragging)return!1;let n=c(e.y,t);return this.draft=wr(this.draft,this.dragging,n),!0}endDrag(){this.dragging=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r=2){let i=this.draft;if(!i)return;let{chartRect:a}=t,s=a.x,c=a.x+a.width,l=o(i.entry,t),u=o(i.stopLoss,t),d=o(i.takeProfit,t),f=n.candleUp,p=n.candleDown;e.save(),e.globalAlpha=.12,e.fillStyle=f,e.fillRect(s,Math.min(l,d),a.width,Math.abs(d-l)),e.fillStyle=p,e.fillRect(s,Math.min(l,u),a.width,Math.abs(u-l)),e.globalAlpha=1,Tr(e,s,c,l,n.text,[6,3]),Tr(e,s,c,d,f,[]),Tr(e,s,c,u,p,[]);let m=xr(i),h=i.side===`buy`?`LONG`:`SHORT`;Er(e,s+6,l,`${h} entry ${i.entry.toFixed(r)}`,n.text,n.background),Er(e,s+6,d,`TP ${i.takeProfit.toFixed(r)} · ${m.toFixed(2)}R`,f,n.background),Er(e,s+6,u,`SL ${i.stopLoss.toFixed(r)}`,p,n.background);for(let[r,a]of[[i.entry,n.text],[i.takeProfit,f],[i.stopLoss,p]]){let n=o(r,t);e.fillStyle=a,e.beginPath(),e.arc(c-6,n,3.5,0,Math.PI*2),e.fill()}e.restore()}};function wr(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function Tr(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Er(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}function Dr(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Or=6,kr=class{draft=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:Dr(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(e,t){return this.draft?Math.abs(o(this.draft.price,t)-e.y)<=Or:!1}beginDrag(e,t){return this.hitTest(e,t)?(this.dragging=!0,!0):!1}drag(e,t){return!this.draft||!this.dragging?!1:this.setPrice(c(e.y,t))}endDrag(){this.dragging=!1}render(e,t,n,r,i=2){let a=this.draft;if(!a)return;let{chartRect:s}=t,c=s.x,l=s.x+s.width,u=o(a.price,t),d=Dr(a.side,a.price,r),f=a.side===`buy`?n.candleUp:n.candleDown;e.save(),Ar(e,c,l,u,f,[6,3]);let p=a.side===`buy`?`BUY`:`SELL`;jr(e,c+6,u,`${p} ${d.toUpperCase()} ${a.price.toFixed(i)}`,f,n.background),e.fillStyle=f,e.beginPath(),e.arc(l-6,u,3.5,0,Math.PI*2),e.fill(),e.restore()}};function Ar(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function jr(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}var Mr=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new ur;positionRenderer=new gr;depthOverlay=new _r;dragHandler;contextMenu=new yr;bracket=new Cr;orderDraft=new kr;requestRender=null;eventCallback=null;container=null;constructor(t){this.config={...e.DEFAULT_TRADING_CONFIG,...t},this.dragHandler=new vr(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:xr(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}onPointerDown(e,t){return this.config.enabled?this.bracket.isActive()&&this.bracket.beginDrag(e,t)||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t)?(this.requestRender?.(),!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,8):!1}onPointerMove(e,t){if(this.bracket.isDragging()){let n=this.bracket.drag(e,t);return n&&this.requestRender?.(),n}if(this.orderDraft.isDragging()){let n=this.orderDraft.drag(e,t);return n&&this.requestRender?.(),n}if(!this.dragHandler.isActive())return!1;let n=this.dragHandler.onPointerMove(e,t);return n&&this.requestRender?.(),n}onPointerUp(){if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let e=this.dragHandler.onPointerUp();return e?(e.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:e.id,newPrice:e.newPrice,previousPrice:e.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:e.id,[e.sourceType]:e.newPrice}),this.requestRender?.(),!0):!1}onContextMenu(e,t){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let n=c(e.y,t);return this.contextMenu.show(e,n,this.container,this.config),!0}render(e,t,n){this.config.enabled&&(this.depthData&&this.depthOverlay.render(e,this.depthData,t,this.config),this.positions.length>0&&this.positionRenderer.render(e,this.positions,this.currentPrice,t,n,this.config),this.orders.length>0&&this.orderRenderer.render(e,this.orders,t,n,this.config,this.dragHandler.getDragState()),this.bracket.isActive()&&this.bracket.render(e,t,n,this.config.pricePrecision??2),this.orderDraft.isActive()&&this.orderDraft.render(e,t,n,this.currentPrice,this.config.pricePrecision??2))}renderAxisBadges(e,t,n){this.config.enabled&&(this.positions.length>0&&this.positionRenderer.renderAxisBadges(e,this.positions,t,n,this.config),this.orders.length>0&&this.orderRenderer.renderAxisBadges(e,this.orders,t,n,this.config,this.dragHandler.getDragState()))}destroy(){this.contextMenu.destroy()}},Nr=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}},Pr=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e){this.markPrice=e,this.checkPendingOrders(),this.checkStops()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:Fr(e.type),draggable:!0};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){this.positions=this.positions.map(t=>t.id===e.positionId?{...t,stopLoss:e.stopLoss??t.stopLoss,takeProfit:e.takeProfit??t.takeProfit}:t),this.emit(`positions`,this.positions)}async closePosition(e){this.positions=this.positions.filter(t=>t.id!==e.positionId),this.emit(`positions`,this.positions)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:Date.now()};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=[],t=!1;for(let n of this.positions){let r=n.stopLoss!==void 0&&(n.side===`buy`?this.markPrice<=n.stopLoss:this.markPrice>=n.stopLoss),i=n.takeProfit!==void 0&&(n.side===`buy`?this.markPrice>=n.takeProfit:this.markPrice<=n.takeProfit);if(r||i){t=!0;continue}e.push(n)}t&&(this.positions=e,this.emit(`positions`,this.positions))}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Fr(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var W=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},Ir=class extends W{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(t,n=1e3){super(),this.timeframeMs=(0,e.timeframeToMs)(t),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(t){this.timeframeMs=(0,e.timeframeToMs)(t),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return Math.floor(e/this.timeframeMs)*this.timeframeMs}},Lr=class extends W{config;attempt=0;timer=null;active=!1;constructor(t){super(),this.config={...e.DEFAULT_RECONNECT,...t}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},Rr=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=2;setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}render(t,n,r){if(!this.visible||this.price===null)return;let i=o(this.price,n),{chartRect:a}=n;if(i<a.y||i>a.y+a.height)return;let s=this.previousClose===null||this.price>=this.previousClose?r.candleUp??`#26A69A`:r.candleDown??`#EF5350`,c=Date.now()<this.flashUntil;t.setLineDash([4,3]),t.strokeStyle=s,t.lineWidth=1,t.globalAlpha=c?1:.7,t.beginPath(),t.moveTo(a.x,Math.round(i)+.5),t.lineTo(a.x+a.width,Math.round(i)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let l=a.x+a.width+1,u=this.price.toFixed(this.pricePrecision);t.font=`bold 11px ${r.font.family}`;let d=t.measureText(u).width,f=Math.min(d+12,e.PRICE_AXIS_WIDTH-2);t.fillStyle=s,t.fillRect(l,i-10,f,20);let p=l-5;t.beginPath(),t.moveTo(p,i),t.lineTo(p+5,i-5),t.lineTo(p+5,i+5),t.closePath(),t.fill(),t.fillStyle=`#FFFFFF`,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(u,l+5,i)}},zr=class extends W{config=null;adapter=null;aggregator=null;reconnector;priceLine=new Rr;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;constructor(){super(),this.reconnector=new Lr,this.wireReconnector()}async connect(t){this.disconnect(),this.config={...e.DEFAULT_STREAM_CONFIG,...t},this.adapter=t.adapter,this.aggregator=new Ir(t.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new Lr(t.reconnect??e.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.adapter.disconnect(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!(!this.config||!this.adapter)){this.setState(`connecting`);try{let e=await this.adapter.fetchHistory(this.config.symbol,this.config.timeframe,this.config.historyLimit??500);e.length>0&&(this.previousClose=e[e.length-1].close,this.updatePrice(e[e.length-1].close)),this.emit(`snapshot`,e),this.adapter.connect({symbol:this.config.symbol,timeframe:this.config.timeframe}),this.startHeartbeat()}catch(e){let t=e instanceof Error?e.message:String(e);this.emit(`error`,{message:t,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i))}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Br=class extends W{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Vr(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=G(e[1]),r=G(e[2]),i=G(e[3]),a=G(e[4]),o=G(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Hr(e){if(!Ur(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=G(e.o),r=G(e.h),i=G(e.l),a=G(e.c),o=G(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function G(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Ur(e){return typeof e==`object`&&!!e}var Wr={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},Gr=class{name=`binance`;ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){this.ws&&=(this.ws.onclose=null,this.ws.close(),null),this.setState(`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n=500){let r=Wr[t]??`15m`,i=`${this.restBase}/klines?symbol=${e}&interval=${r}&limit=${n}`,a=await fetch(i);if(!a.ok)throw Error(`Binance REST error: ${a.status}`);let o=await a.json();if(!Array.isArray(o))return[];let s=[];for(let e of o){let t=Vr(e);t&&s.push(t)}return s}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Wr[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Hr(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Kr=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n){return this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(t,n){let r=[],i=Date.now(),a=(0,e.timeframeToMs)(t),o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=i-e*a,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let t=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let t=this.options.volatility/100,n=(Math.random()-.48)*this.currentPrice*t*.3;this.currentPrice+=n;let r=Date.now(),i=(0,e.timeframeToMs)(this.config.timeframe),a={time:Math.floor(r/i)*i,open:this.currentPrice-n,high:Math.max(this.currentPrice,this.currentPrice-n)+Math.abs(n)*.2,low:Math.min(this.currentPrice,this.currentPrice-n)-Math.abs(n)*.2,close:this.currentPrice,volume:Math.floor(100+Math.random()*5e3)};this.emitEvent(`bar`,{bar:a,closed:!1}),this.emitEvent(`tick`,{time:r,price:this.currentPrice,volume:a.volume})},t)}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},qr=class{name;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}this.ws.onclose=null,this.ws.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Jr=class{name;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function K(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function q(e){return typeof e==`object`&&!!e}var Yr={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function Xr(e){return Yr[e]??3600}var Zr=class extends Jr{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>Qr(t,e,n)})}};async function Qr(e,t,n){let r=`${e}/products/${t}/candles?granularity=${Xr(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return $r(await i.json())}function $r(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=ei(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function ei(e){if(!Array.isArray(e)||e.length<6)return null;let t=K(e[0]),n=K(e[1]),r=K(e[2]),i=K(e[3]),a=K(e[4]),o=K(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var ti={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function ni(e){return ti[e]??`1`}var ri=class extends qr{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${ni(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${ni(e.timeframe)}.${e.symbol}`]}),parseMessage:ii,fetchHistory:(e,n,i)=>ai(t,r,e,n,i)})}};function ii(e){if(!q(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!q(n))return null;let r=K(n.start),i=K(n.open),a=K(n.high),o=K(n.low),s=K(n.close),c=K(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function ai(e,t,n,r,i){let a=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${ni(r)}&limit=${Math.min(Math.max(i,1),1e3)}`,o=await fetch(a);if(!o.ok)throw Error(`Bybit REST error: ${o.status}`);return oi(await o.json())}function oi(e){if(!q(e)||!q(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=si(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function si(e){if(!Array.isArray(e)||e.length<6)return null;let t=K(e[0]),n=K(e[1]),r=K(e[2]),i=K(e[3]),a=K(e[4]),o=K(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var ci={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function li(e){return ci[e]??1}var ui=class extends qr{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:li(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:li(e.timeframe)}}),parseMessage:di,fetchHistory:(e,n)=>fi(t,e,n)})}};function di(e){if(!q(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!q(n))return null;let r=K(n.open),i=K(n.high),a=K(n.low),o=K(n.close),s=K(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function fi(e,t,n){let r=li(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return pi(await o.json())}function pi(e){if(!q(e)||!q(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=mi(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function mi(e){if(!Array.isArray(e)||e.length<7)return null;let t=K(e[0]),n=K(e[1]),r=K(e[2]),i=K(e[3]),a=K(e[4]),o=K(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var hi={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12},gi=class{config={...hi};symbol=``;timeframe=``;hoverBar=null;indicators=[];statusText=null;setConfig(e){Object.assign(this.config,e)}setSymbol(e){this.symbol=e}setTimeframe(e){this.timeframe=e}setChartType(e){}setHoverBar(e){this.hoverBar=e}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e}render(e,t,n,r){if(!this.config.visible||r.length===0)return;let i=this.hoverBar??r[r.length-1],a=r.length>1?r[r.length-2]:i,{chartRect:o}=t,s=this.config.fontSize,c=this.config.position===`top-left`,l=c?o.x+8:o.x+o.width-8,u=o.y+6;if(e.textAlign=c?`left`:`right`,e.textBaseline=`top`,this.config.showSymbol){e.font=`bold ${s+2}px ${n.font.family}`,e.fillStyle=n.text;let t=[this.symbol,this.timeframe].filter(Boolean).join(` · `),r=this.statusText?`${t} ${this.statusText}`:t;e.fillText(r,l,u),u+=s+6}else this.statusText&&(e.font=`${s}px ${n.font.family}`,e.fillStyle=n.textSecondary,e.fillText(this.statusText,l,u),u+=s+4);if(this.config.showOHLC){e.font=`${s}px ${n.font.family}`;let t=i.close>=i.open,r=e=>e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),o=[{label:`O`,value:r(i.open),color:n.text},{label:`H`,value:r(i.high),color:n.text},{label:`L`,value:r(i.low),color:n.text},{label:`C`,value:r(i.close),color:t?n.candleUp:n.candleDown}];if(this.config.showChange){let e=i.close-a.close,t=a.close===0?0:e/a.close*100,s=e>=0?`+`:``;o.push({label:``,value:`${s}${r(e)} (${s}${t.toFixed(2)}%)`,color:e>=0?n.candleUp:n.candleDown})}let d=l;if(c)for(let t of o)t.label&&(e.fillStyle=n.textSecondary,e.fillText(t.label,d,u),d+=e.measureText(t.label+` `).width),e.fillStyle=t.color,e.fillText(t.value,d,u),d+=e.measureText(t.value+` `).width;else{let t=o.map(e=>`${e.label} ${e.value}`).join(` `);e.fillStyle=n.text,e.fillText(t,l,u)}u+=s+3}if(this.config.showVolume){e.font=`${s-1}px ${n.font.family}`,e.fillStyle=n.textSecondary;let t=i.volume>=1e6?`${(i.volume/1e6).toFixed(2)}M`:i.volume>=1e3?`${(i.volume/1e3).toFixed(2)}K`:i.volume.toFixed(0);e.fillText(`Vol ${t}`,l,u),u+=s+2}if(this.indicators.length>0){e.font=`${s-1}px ${n.font.family}`;let t=l;for(let n of this.indicators){e.fillStyle=n.color;let r=`${n.name} ${n.value}`;e.fillText(r,t,u),t+=e.measureText(r+` `).width}}}},_i=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},vi=class{config=null;setConfig(e){this.config=e}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},yi=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}render(e,t,n,r){if(!this.visible||this.timeframeMs<=0||r.length===0)return;let i=r[r.length-1],o=(i.time>0xe8d4a51000?i.time:i.time*1e3)+this.timeframeMs-Date.now();if(o<=0)return;let s=this.formatRemaining(o),c=a(r.length-1,t),l=t.chartRect.y+t.chartRect.height-4;c<t.chartRect.x||c>t.chartRect.x+t.chartRect.width||(e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`bottom`,e.textAlign=`center`,e.fillStyle=n.textSecondary,e.fillText(s,c,l))}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}},bi=class{config={visible:!1};cachedBreaksTyped=[];lastDataLength=0;setConfig(e){Object.assign(this.config,e)}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(e){if(e.length<2)return[];if(e.length===this.lastDataLength&&this.cachedBreaksTyped.length>0)return this.cachedBreaksTyped;let t=[],n=new Date(this.toMs(e[0].time));for(let r=1;r<e.length;r++){let i=new Date(this.toMs(e[r].time));if(i.getFullYear()!==n.getFullYear())t.push({idx:r,kind:`year`,date:i});else if(i.getMonth()!==n.getMonth())t.push({idx:r,kind:`month`,date:i});else if(i.getDate()!==n.getDate()){let e=i.getDay()===1;t.push({idx:r,kind:e?`week`:`day`,date:i})}n=i}return this.lastDataLength=e.length,this.cachedBreaksTyped=t,t}toMs(e){return e>0xe8d4a51000?e:e*1e3}render(e,t,n,r){if(!this.config.visible||r.length<2)return;let i=this.computeBreaksTyped(r);if(i.length===0||wi(r)>=1380*60*1e3)return;let{chartRect:o}=t,s=this.config.color??n.axisLine,c=this.config.lineWidth??1,l=this.config.lineStyle??`dashed`;e.save(),l===`dashed`?e.setLineDash([6,4]):l===`dotted`&&e.setLineDash([2,3]),e.font=`600 11px ${n.font.family}`,e.textBaseline=`top`,e.textAlign=`left`;for(let r of i){let i=a(r.idx,t)-(t.barWidth+t.barSpacing)/2;if(i<o.x-1||i>o.x+o.width+1)continue;let l=Math.round(i)+.5,u=.25,d=c,f=null;r.kind===`day`?u=.22:r.kind===`week`?(u=.34,f=Si(r.date)):r.kind===`month`?(u=.5,d=c+.5,f=Ci(r.date)):(u=.7,d=c+1,f=String(r.date.getFullYear())),e.globalAlpha=u,e.strokeStyle=s,e.lineWidth=d,e.beginPath(),e.moveTo(l,o.y),e.lineTo(l,o.y+o.height),e.stroke(),f&&(e.globalAlpha=Math.min(1,u+.35),e.fillStyle=n.textSecondary,e.fillText(f,l+4,o.y+4))}e.restore()}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[]}},xi=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Si(e){return`${xi[e.getMonth()]} ${e.getDate()}`}function Ci(e){return`${xi[e.getMonth()]} ${String(e.getFullYear()).slice(-2)}`}function wi(e){if(e.length<2)return 0;let t=Math.min(50,e.length-1),n=[];for(let r=1;r<=t;r++){let t=e[r-1].time,i=e[r].time,a=t>0xe8d4a51000?t:t*1e3,o=i>0xe8d4a51000?i:i*1e3;n.push(o-a)}return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]}var Ti=864e5;function Ei(e,t){let n=((e+t*6e4)%Ti+Ti)%Ti;return Math.floor(n/6e4)}function Di(e,t){let n=Ei(e,t.tzOffsetMinutes),{startMinute:r,endMinute:i}=t;return r===i?!0:r<i?n>=r&&n<i:n>=r||n<i}var Oi={startMinute:570,endMinute:960,tzOffsetMinutes:-300},ki=class{visible=!1;config={...Oi};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){this.config={...this.config,...e}}getConfig(){return{...this.config}}render(e,t,n,r){if(!this.visible||t.length===0)return;let{chartRect:i}=n,{from:o,to:s}=n.visibleRange,c=Math.max(0,o),l=Math.min(s,t.length-1);if(l<c)return;let u=n.barWidth+n.barSpacing,d=r.name===`light`;e.save(),e.fillStyle=d?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`;let f=-1,p=(t,r)=>{let o=a(t,n)-u/2,s=a(r,n)+u/2;e.fillRect(o,i.y,s-o,i.height)};for(let e=c;e<=l;e++){let n=!Di(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}f!==-1&&p(f,l),e.restore()}},Ai=1,ji=class extends W{alerts=[];lastValues=new Map;requestRender=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a){let o=`tc_alert_${Ai++}`,s={id:o,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a};return this.alerts.push(s),this.emit(`added`,s),this.requestRender?.(),o}removeAlert(e){this.alerts=this.alerts.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(e,t,n=6){let{chartRect:r}=t;if(e.y<r.y||e.y>r.y+r.height)return null;let i=null,a=n;for(let n of this.alerts){if(n.channel!==`price`)continue;let r=Math.abs(o(n.price,t)-e.y);r<=a&&(a=r,i=n)}return i}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e)}checkChannel(e,t){if(!Number.isFinite(t))return;let n=this.lastValues.get(e);if(n===void 0){this.lastValues.set(e,t);return}for(let r of this.alerts){if(r.channel!==e)continue;let i=!1;switch(r.condition){case`crossingUp`:i=n<r.price&&t>=r.price;break;case`crossingDown`:i=n>r.price&&t<=r.price;break;case`crossing`:i=n<r.price&&t>=r.price||n>r.price&&t<=r.price;break;case`greaterThan`:i=t>r.price;break;case`lessThan`:i=t<r.price;break}i?r.triggered||(r.triggered=!0,this.emit(`triggered`,{...r})):r.repeating&&(r.triggered=!1)}this.lastValues.set(e,t)}clearLastValues(){this.lastValues.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n)e.price!=null&&Number.isFinite(e.price)&&e.condition&&!e.triggered&&this.addAlert(e.price,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label)}catch{}}render(e,t,n){let{chartRect:r}=t;for(let i of this.alerts){if(i.channel!==`price`)continue;let a=o(i.price,t);if(a<r.y||a>r.y+r.height)continue;let s=i.triggered?`#FF9800`:`#FFD700`;e.setLineDash([2,6]),e.strokeStyle=s,e.lineWidth=1,e.beginPath(),e.moveTo(r.x,Math.round(a)+.5),e.lineTo(r.x+r.width,Math.round(a)+.5),e.stroke(),e.setLineDash([]),e.font=`10px ${n.font.family}`,e.fillStyle=s,e.textBaseline=`bottom`,e.textAlign=`right`;let c=`🔔 ${i.price.toFixed(this.pricePrecision)}${i.message?` - ${i.message}`:``}`;e.fillText(c,r.x+r.width-4,a-2)}}},Mi=class extends W{data=[];currentIndex=0;timer=null;state=`stopped`;config={speed:1,interval:500};load(e){this.stop(),this.data=e,this.currentIndex=0}play(e){this.data.length!==0&&(e&&Object.assign(this.config,e),e?.startIndex!==void 0&&(this.currentIndex=e.startIndex),this.state=`playing`,this.emit(`stateChange`,`playing`),this.timer=setInterval(()=>{if(this.currentIndex>=this.data.length){this.stop(),this.emit(`complete`,void 0);return}let e=this.data[this.currentIndex];this.emit(`bar`,{bar:e,index:this.currentIndex,total:this.data.length}),this.currentIndex++},this.config.interval/this.config.speed))}pause(){this.timer&&=(clearInterval(this.timer),null),this.state=`paused`,this.emit(`stateChange`,`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.timer&&=(clearInterval(this.timer),null),this.state=`stopped`,this.currentIndex=0,this.emit(`stateChange`,`stopped`)}seekTo(e){if(this.data.length===0)return;let t=Math.max(0,Math.min(e,this.data.length-1));this.currentIndex=t;let n=this.data[t];this.emit(`bar`,{bar:n,index:t,total:this.data.length})}setSpeed(e){this.config.speed=e,this.state===`playing`&&(this.pause(),this.play())}getState(){return this.state}getProgress(){return{current:this.currentIndex,total:this.data.length,percent:this.data.length>0?this.currentIndex/this.data.length*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}},J=1;function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e){return Array.isArray(e)?e:[]}function Ni(e,t){return typeof e==`string`?e:t}function Z(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function Pi(e){if(!Y(e)||typeof e.id!=`string`||typeof e.type!=`string`||!Array.isArray(e.anchors)||e.anchors.length===0||!Y(e.style))return null;let t=[];for(let n of e.anchors){if(!Y(n)||typeof n.time!=`number`||typeof n.price!=`number`||!Number.isFinite(n.time)||!Number.isFinite(n.price))return null;t.push({time:n.time,price:n.price})}let n=e.style;return typeof n.color!=`string`||typeof n.lineWidth!=`number`?null:{id:e.id,type:e.type,anchors:t,style:n,visible:typeof e.visible==`boolean`?e.visible:!0,locked:typeof e.locked==`boolean`?e.locked:!1,meta:Y(e.meta)?e.meta:void 0}}function Fi(e){return!Y(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function Ii(e){return!Y(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}function Li(e){if(!Y(e))return Ri();typeof e.version==`number`&&e.version!==J&&console.warn(`Chart state version mismatch: ${e.version} vs ${J}`);let t=Y(e.viewport)?e.viewport:{},n=[];for(let t of X(e.indicators))Y(t)&&(typeof t.id!=`string`||typeof t.instanceId!=`string`||Y(t.params)&&n.push({id:t.id,instanceId:t.instanceId,params:t.params,position:typeof t.position==`string`?t.position:void 0}));let r=[];for(let t of X(e.drawings)){let e=Pi(t);e&&r.push(e)}let i=[];for(let t of X(e.orders)){let e=Fi(t);e&&i.push(e)}let a=[];for(let t of X(e.positions)){let e=Ii(t);e&&a.push(e)}let o=[];for(let t of X(e.alerts))Y(t)&&typeof t.id==`string`&&o.push(t);return{version:typeof e.version==`number`?e.version:J,timestamp:Z(e.timestamp,Date.now()),symbol:typeof e.symbol==`string`?e.symbol:void 0,timeframe:typeof e.timeframe==`string`?e.timeframe:void 0,chartType:Ni(e.chartType,`candlestick`),viewport:{barWidth:Z(t.barWidth,8),barSpacing:Z(t.barSpacing,2),offset:Z(t.offset,0)},theme:typeof e.theme==`string`?e.theme:void 0,locale:typeof e.locale==`string`?e.locale:void 0,indicators:n,drawings:r,orders:i,positions:a,alerts:o}}function Ri(){return{version:J,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var zi=class{static capture(e,t){return{version:J,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return Li(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},Bi=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},Vi=class{static toCSV(e){return[`Time,Open,High,Low,Close,Volume`,...e.map(e=>`${new Date(e.time).toISOString()},${e.open},${e.high},${e.low},${e.close},${e.volume}`)].join(`
25
- `)}static toJSON(e){return JSON.stringify(e.map(e=>({time:new Date(e.time).toISOString(),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})),null,2)}static download(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}},Hi=1,Ui=class extends W{markers=[];style={...e.DEFAULT_SIGNAL_STYLE};requestRender=null;dataGetter=null;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addMarker(e){let t=e.id??`tc_signal_${Hi++}`,n={...e,id:t};return this.markers.push(n),this.emit(`added`,n),this.requestRender?.(),t}removeMarker(e){this.markers=this.markers.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getMarkers(){return[...this.markers]}clearMarkers(){this.markers=[],this.emit(`cleared`,void 0),this.requestRender?.()}setMarkers(e){this.markers=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.markers.length===0)return;let{chartRect:i,visibleRange:s}=t,c=this.style,u=c.arrowSize??12;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let d of this.markers){let f=l(d.time,r);if(f<s.from-1||f>s.to+1)continue;let p=a(f,t),m=o(d.price,t);if(p<i.x-u||p>i.x+i.width+u||m<i.y-u||m>i.y+i.height+u)continue;let h=this.resolveColor(d,c),g=u*Math.max(.6,Math.min(1,d.confidence));if(this.renderArrow(e,p,m,d.direction,g,h),c.showLabel&&d.label){e.font=`10px ${n.font.family}`,e.fillStyle=h,e.textAlign=`center`,e.textBaseline=d.direction===`long`?`top`:`bottom`;let t=d.direction===`long`?m+g+3:m-g-3;e.fillText(d.label,p,t)}if(c.showConfidence&&d.confidence<1){e.font=`9px ${n.font.family}`,e.fillStyle=h,e.globalAlpha=.7,e.textAlign=`center`,e.textBaseline=d.direction===`long`?`top`:`bottom`;let t=d.direction===`long`?m+g+(d.label?14:3):m-g-(d.label?14:3);e.fillText(`${Math.round(d.confidence*100)}%`,p,t),e.globalAlpha=1}}e.restore()}resolveColor(e,t){if(e.color)return e.color;if(t.sourceColors?.[e.source])return t.sourceColors[e.source];switch(e.direction){case`long`:return t.longColor??`#26A69A`;case`short`:return t.shortColor??`#EF5350`;default:return t.neutralColor??`#9E9E9E`}}renderArrow(e,t,n,r,i,a){e.fillStyle=a,e.beginPath(),r===`long`?(e.moveTo(t,n-i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n+i*.4),e.lineTo(t+i*.2,n+i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):r===`short`?(e.moveTo(t,n+i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n-i*.4),e.lineTo(t+i*.2,n-i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):e.arc(t,n,i*.4,0,Math.PI*2),e.closePath(),e.fill()}},Wi=1,Gi=class extends W{zones=[];style={...e.DEFAULT_TRADE_ZONE_STYLE};requestRender=null;dataGetter=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setPricePrecision(e){this.pricePrecision=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addZone(e){let t=e.id??`tc_zone_${Wi++}`,n={...e,id:t};return this.zones.push(n),this.emit(`added`,n),this.requestRender?.(),t}updateZone(e,t){let n=this.zones.findIndex(t=>t.id===e);n!==-1&&(this.zones[n]={...this.zones[n],...t},this.requestRender?.())}removeZone(e){this.zones=this.zones.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getZones(){return[...this.zones]}clearZones(){this.zones=[],this.emit(`cleared`,void 0),this.requestRender?.()}setZones(e){this.zones=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.zones.length===0)return;let{chartRect:i}=t,a=this.style;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.zones)this.renderZone(e,i,r,t,n,a);e.restore()}renderZone(e,t,n,r,i,s){let{chartRect:c,visibleRange:u}=r,d=l(t.entryTime,n),f=t.exitTime==null?n.length-1:l(t.exitTime,n);if(f<u.from||d>u.to)return;let p=a(d,r),m=a(f,r),h=Math.max(c.x,Math.min(p,m)),g=Math.min(c.x+c.width,Math.max(p,m));if(g-h<1)return;let _=o(t.entryPrice,r),v=t.exitPrice==null?o(t.entryPrice,r):o(t.exitPrice,r),y=Math.min(_,v),b=Math.max(Math.max(_,v)-y,2),x=t.exitTime==null,S=t.pnl==null?t.direction===`long`?(t.exitPrice??t.entryPrice)>=t.entryPrice:(t.exitPrice??t.entryPrice)<=t.entryPrice:t.pnl>=0,C=x?s.activeColor??`#2196F3`:S?s.profitColor??`#26A69A`:s.lossColor??`#EF5350`;e.fillStyle=C,e.globalAlpha=s.fillOpacity??.12,e.fillRect(h,y,g-h,b),e.globalAlpha=1;let w=s.borderWidth??1;e.strokeStyle=C,e.lineWidth=w,e.setLineDash([]),e.beginPath(),e.moveTo(h,Math.round(_)+.5),e.lineTo(g,Math.round(_)+.5),e.stroke(),!x&&t.exitPrice!=null&&(e.setLineDash([3,3]),e.beginPath(),e.moveTo(h,Math.round(v)+.5),e.lineTo(g,Math.round(v)+.5),e.stroke(),e.setLineDash([]));let T=t.direction===`long`?`▲`:`▼`;if(e.font=`bold 10px ${i.font.family}`,e.fillStyle=C,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(`${T} ${t.entryPrice.toFixed(this.pricePrecision)}`,h+4,_-3),s.showPnl&&!x&&t.pnl!=null){let n=t.pnl>=0?`+`:``,r=t.pnlPercent==null?`${n}${t.pnl.toFixed(2)}`:`${n}${t.pnl.toFixed(2)} (${n}${t.pnlPercent.toFixed(2)}%)`;e.font=`bold 10px ${i.font.family}`,e.fillStyle=C,e.textBaseline=`top`,e.textAlign=`right`;let a=e.measureText(r).width+8,o=g-a-2,s=y+2;e.globalAlpha=.85,e.fillStyle=i.background,e.fillRect(o,s,a,14),e.globalAlpha=1,e.fillStyle=C,e.fillText(r,g-4,s+1)}s.showLabel&&t.label&&(e.font=`9px ${i.font.family}`,e.fillStyle=C,e.globalAlpha=.8,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(t.label,h+4,_+3),e.globalAlpha=1)}},Ki=class{active=!1;startBar=0;startPrice=0;endBar=0;endPrice=0;startTime=null;endTime=null;isActive(){return this.active}begin(e,t,n){let r=Math.round(s(e.x,t)),i=c(e.y,t);this.startBar=r,this.startPrice=i,this.endBar=r,this.endPrice=i,this.startTime=qi(r,n),this.endTime=this.startTime,this.active=!0}update(e,t,n){if(!this.active)return;let r=Math.round(s(e.x,t));this.endBar=r,this.endPrice=c(e.y,t),this.endTime=qi(r,n)}end(){this.active=!1}render(e,t,n){if(!this.active)return;let r=a(this.startBar,t),i=a(this.endBar,t),s=o(this.startPrice,t),c=o(this.endPrice,t),l=Math.min(r,i),u=Math.max(r,i),d=Math.min(s,c),f=Math.max(s,c),p=u-l,m=f-d,h=this.endPrice>=this.startPrice?n.candleUp:n.candleDown,g=$i(h,.14);e.save(),e.fillStyle=g,e.fillRect(l,d,p,m),e.strokeStyle=h,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(l+.5,d+.5,p,m),e.setLineDash([]),e.strokeStyle=h,e.lineWidth=1.5,e.beginPath(),e.moveTo(r,s),e.lineTo(i,c),e.stroke(),Xi(e,r,s,h),Xi(e,i,c,h);let _=Math.abs(this.endBar-this.startBar),v=this.endPrice-this.startPrice,y=this.startPrice===0?0:v/this.startPrice*100,b=this.startTime!==null&&this.endTime!==null?Yi(Math.abs(this.endTime-this.startTime)):null,x=[],S=v>0?`+`:v<0?`−`:``,C=Math.abs(v);x.push(`${S}${Ji(C)} (${S}${Math.abs(y).toFixed(2)}%)`),x.push(`${_} bars${b?` · `+b:``}`),Zi(e,i,c,x,h,n),e.restore()}};function qi(e,t){if(e<0||e>=t.length)return null;let n=t[e].time;return n>0xe8d4a51000?n:n*1e3}function Ji(e){return e>=1e3?e.toFixed(2):e>=1?e.toFixed(4):e.toPrecision(4)}function Yi(e){let t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;let n=t/60;if(n<60)return`${n.toFixed(1)}m`;let r=n/60;if(r<24)return`${r.toFixed(1)}h`;let i=r/24;if(i<30)return`${i.toFixed(1)}d`;let a=i/30;return a<12?`${a.toFixed(1)}mo`:`${(i/365).toFixed(1)}y`}function Xi(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t,n,3.5,0,Math.PI*2),e.fill(),e.fillStyle=`#fff`,e.beginPath(),e.arc(t,n,1.5,0,Math.PI*2),e.fill()}function Zi(e,t,n,r,i,a){e.font=`600 11px ${a.font.family}`;let o=0;for(let t of r){let n=e.measureText(t).width;n>o&&(o=n)}let s=Math.ceil(o)+16,c=r.length*14+12,l=t+8,u=n+8,d=e.canvas.clientWidth||e.canvas.width;l+s>d-4&&(l=t-s-8),l<4&&(l=4),e.fillStyle=a.background,e.globalAlpha=.96,Qi(e,l,u,s,c,6),e.fill(),e.globalAlpha=1,e.strokeStyle=i,e.lineWidth=1,Qi(e,l+.5,u+.5,s-1,c-1,6),e.stroke(),e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<r.length;t++)e.fillStyle=t===0?i:a.textSecondary,e.fillText(r[t],l+8,u+6+t*14)}function Qi(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function $i(e,t){if(e.startsWith(`#`)){let n=0,r=0,i=0;return e.length===4?(n=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16),i=parseInt(e[3]+e[3],16)):e.length>=7&&(n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16)),`rgba(${n},${r},${i},${t})`}if(e.startsWith(`rgb`)){let n=e.match(/[\d.]+/g);if(n&&n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${t})`}return e}var ea={linear:e=>e,easeOutCubic:e=>1-(1-e)**3,easeOutQuart:e=>1-(1-e)**4,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeOutExpo:e=>e===1?1:1-2**(-10*e),easeOutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,spring:e=>1-Math.E**(-6*e)*Math.cos(8*e)},ta=class{animations=new Map;frameId=0;running=!1;animate(e,t){this.animations.set(e,{startTime:-1,duration:t.duration,easing:t.easing??ea.easeOutCubic,onUpdate:t.onUpdate,onComplete:t.onComplete}),this.running||(this.running=!0,this.tick())}cancel(e){this.animations.delete(e),this.animations.size===0&&this.stop()}cancelAll(){this.animations.clear(),this.stop()}isAnimating(e){return e?this.animations.has(e):this.animations.size>0}tick(){this.frameId=requestAnimationFrame(e=>{let t=[];for(let[n,r]of this.animations){r.startTime<0&&(r.startTime=e);let i=e-r.startTime,a=Math.min(1,i/r.duration),o=r.easing(a);r.onUpdate(o),a>=1&&(r.onComplete?.(),t.push(n))}for(let e of t)this.animations.delete(e);this.animations.size>0?this.tick():this.running=!1})}stop(){this.frameId&&=(cancelAnimationFrame(this.frameId),0),this.running=!1}dispose(){this.cancelAll()}};function na(t){return!t||t===`dark`?e.DARK_THEME:t===`light`?e.LIGHT_THEME:t}var ra=class{canvas;ctx;container;theme;width=0;height=0;dpr=1;frameId=null;resizeObserver;constructor(e,t){this.container=e,this.theme=na(t),this.canvas=document.createElement(`canvas`),this.canvas.style.width=`100%`,this.canvas.style.height=`100%`,this.canvas.style.display=`block`,e.appendChild(this.canvas),this.ctx=this.canvas.getContext(`2d`),this.dpr=window.devicePixelRatio||1,this.updateSize(),this.resizeObserver=new ResizeObserver(()=>{this.updateSize(),this.requestRender()}),this.resizeObserver.observe(e)}updateSize(){this.dpr=window.devicePixelRatio||1;let e=this.container.getBoundingClientRect();this.width=e.width||this.container.clientWidth,this.height=e.height||this.container.clientHeight,this.canvas.width=Math.max(1,Math.floor(this.width*this.dpr)),this.canvas.height=Math.max(1,Math.floor(this.height*this.dpr))}requestRender(){this.frameId===null&&(this.frameId=requestAnimationFrame(()=>{this.frameId=null,(this.width===0||this.height===0)&&this.updateSize(),!(this.width===0||this.height===0)&&(this.ctx.save(),this.ctx.scale(this.dpr,this.dpr),this.ctx.clearRect(0,0,this.width,this.height),this.renderChart(this.ctx,this.width,this.height,this.theme),this.ctx.restore())}))}setTheme(e){this.theme=na(e),this.requestRender()}destroy(){this.frameId!==null&&cancelAnimationFrame(this.frameId),this.resizeObserver.disconnect(),this.canvas.remove()}},ia=class{pos=null;canvas;onUpdate;handleMove;handleLeave;constructor(e,t){this.canvas=e,this.onUpdate=t,this.handleMove=t=>{let n=e.getBoundingClientRect();this.pos={x:t.clientX-n.left,y:t.clientY-n.top},this.onUpdate()},this.handleLeave=()=>{this.pos=null,this.onUpdate()},e.addEventListener(`pointermove`,this.handleMove),e.addEventListener(`pointerleave`,this.handleLeave)}getPosition(){return this.pos}isActive(){return this.pos!==null}drawCrosshair(e,t,n,r){this.pos&&(e.save(),e.strokeStyle=r,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(this.pos.x,0),e.lineTo(this.pos.x,n),e.stroke(),e.beginPath(),e.moveTo(0,this.pos.y),e.lineTo(t,this.pos.y),e.stroke(),e.restore())}destroy(){this.canvas.removeEventListener(`pointermove`,this.handleMove),this.canvas.removeEventListener(`pointerleave`,this.handleLeave)}};function aa(e,t,n,r,i){let{data:a,mode:o=`area`,lineWidth:s=1.5,showLastPoint:c=!1,showMinMax:l=!1}=r;if(a.length<2||t<=0||n<=0)return;let u=r.color??i.lineColor,d=r.fillColor??u,f=t-4,p=n-4,m=1/0,h=-1/0,g=0,_=0;for(let e=0;e<a.length;e++)a[e]<m&&(m=a[e],g=e),a[e]>h&&(h=a[e],_=e);let v=h-m||1,y=e=>2+e/(a.length-1)*f,b=e=>2+p-(e-m)/v*p;if(o===`area`){let t=e.createLinearGradient(0,2,0,n-2);t.addColorStop(0,d+(d.startsWith(`#`)?`40`:``)),t.addColorStop(1,`transparent`),e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));e.lineTo(y(a.length-1),n-2),e.lineTo(y(0),n-2),e.closePath(),e.fillStyle=t,e.fill()}e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));if(e.strokeStyle=u,e.lineWidth=s,e.lineJoin=`round`,e.stroke(),c){let t=r.lastPointColor??u,n=y(a.length-1),i=b(a[a.length-1]);e.beginPath(),e.arc(n,i,3,0,Math.PI*2),e.fillStyle=t,e.fill()}if(l){let t=r.minPointColor??i.candleDown,n=r.maxPointColor??i.candleUp;e.beginPath(),e.arc(y(g),b(m),2.5,0,Math.PI*2),e.fillStyle=t,e.fill(),e.beginPath(),e.arc(y(_),b(h),2.5,0,Math.PI*2),e.fillStyle=n,e.fill()}}var oa=50,sa=60,ca=20,la=.2;function ua(e){let t=[...e].sort((e,t)=>t.price-e.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function da(e){let t=[...e].sort((e,t)=>e.price-t.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function fa(e,t){return{left:oa,right:e-sa,top:ca,bottom:t-ca,plotWidth:e-oa-sa,plotHeight:t-ca*2}}function pa(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function ma(t,n,r,i,a,o,s,c){let{left:l,right:u,top:d,bottom:f,plotWidth:p,plotHeight:m}=n;t.save(),t.strokeStyle=o.grid,t.lineWidth=.5,t.fillStyle=o.axisLabel,t.font=`${o.font.sizeSmall}px ${o.font.family}`;let h=(0,e.computeTickStep)(0,a,5);for(let e=0;e<=a;e+=h){let n=f-e/a*m;t.beginPath(),t.moveTo(l,n),t.lineTo(u,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),l-4,n)}let g=i-r,_=(0,e.computeTickStep)(r,i,6),v=Math.ceil(r/_)*_;for(let e=v;e<=i;e+=_){let n=l+(e-r)/g*p;t.beginPath(),t.moveTo(n,d),t.lineTo(n,f),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(s(e),n,f+4)}t.restore()}function ha(e,t,n,r,i,a,o,s,c){if(t.length===0)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-e/a*f;if(e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}else{e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}if(e.closePath(),e.fillStyle=o,e.fill(),e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);n>0&&e.lineTo(r,m(t[n-1].cumulativeVolume)),e.lineTo(r,i)}}else{e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=1;n<t.length;n++){let r=m(t[n-1].cumulativeVolume),i=p(t[n].price),a=m(t[n].cumulativeVolume);e.lineTo(i,r),e.lineTo(i,a)}}e.strokeStyle=s,e.lineWidth=1.5,e.stroke()}function ga(e,t,n,r,i,a,o,s,c){let{left:l,top:u,bottom:d,plotWidth:f}=r,p=l+(t-i)/a*f;if(e.save(),e.strokeStyle=o.textSecondary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(p,u),e.lineTo(p,d),e.stroke(),e.restore(),s){let t=`Spread: ${c(n)}`;e.save(),e.font=`${o.font.sizeSmall}px ${o.font.family}`,e.fillStyle=o.textSecondary,e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t,p,u-2),e.restore()}}function _a(e,t,n,r,i,a,o,s,c,l,u){let{left:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=i,g=t.x;if(g<d||g>i.right)return;let _=a+(g-d)/m*o,v=0,y=``;if(n.length>0&&_<=n[0].price){y=`Bid`;for(let e of n)if(_<=e.price)v=e.cumulativeVolume;else break}if(r.length>0&&_>=r[0].price){y=`Ask`;for(let e of r)if(_>=e.price)v=e.cumulativeVolume;else break}if(e.save(),e.strokeStyle=c.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(g,f),e.lineTo(g,p),e.stroke(),v>0){let t=p-v/s*h;e.beginPath(),e.moveTo(d,t),e.lineTo(i.right,t),e.stroke()}e.restore();let b=[`Price: ${l(_)}`,y?`${y} Vol: ${u(v)}`:``].filter(Boolean);e.save(),e.font=`${c.font.sizeSmall}px ${c.font.family}`;let x=Math.max(...b.map(t=>e.measureText(t).width))+16,S=b.length*(c.font.sizeSmall+4)+12,C=g+10,w=t.y-S/2;C+x>i.right&&(C=g-x-10),w<f&&(w=f),w+S>p&&(w=p-S),e.fillStyle=c.axisLabelBackground,e.globalAlpha=.9,e.fillRect(C,w,x,S),e.globalAlpha=1,e.fillStyle=c.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<b.length;t++)e.fillText(b[t],C+8,w+6+t*(c.font.sizeSmall+4));e.restore()}function va(e){return e.toFixed(2)}function ya(e){return e>=1e6?(e/1e6).toFixed(2)+`M`:e>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(0)}function ba(e,t,n,r,i,a){let{data:o}=r;if(o.bids.length===0&&o.asks.length===0||t<=0||n<=0)return;let s=r.bidColor??i.candleUp,c=r.askColor??i.candleDown,l=r.bidFillColor??s+`40`,u=r.askFillColor??c+`40`,d=r.midPriceLine!==!1,f=r.spreadLabel!==!1,p=r.priceFormat??va,m=r.volumeFormat??ya,h=ua(o.bids),g=da(o.asks),_=h.length>0?h[0].price:0,v=g.length>0?g[0].price:0,y=h.length>0&&g.length>0?(_+v)/2:_||v,b=g.length>0&&h.length>0?v-_:0,x=h.length>0?h[h.length-1].price:y,S=g.length>0?g[g.length-1].price:y,C=Math.max(y-x,S-y)*(1+la),w=y-C,T=y+C,E=T-w,D=h.length>0?h[h.length-1].cumulativeVolume:0,O=g.length>0?g[g.length-1].cumulativeVolume:0,k=Math.max(D,O)||1,A=fa(t,n);pa(e,t,n,i.background),ma(e,A,w,T,k,i,p,m),ha(e,h,A,w,E,k,l,s,`bid`),ha(e,g,A,w,E,k,u,c,`ask`),d&&ga(e,y,b,A,w,E,i,f,p),a&&_a(e,a,h,g,A,w,E,k,i,p,m)}var xa=70,Sa=30,Ca=20,wa=20,Ta=.05;function Ea(e,t){return{left:xa,right:e-Ca,top:wa,bottom:t-Sa,plotWidth:e-xa-Ca,plotHeight:t-wa-Sa}}function Da(e,t){let n=1/0,r=-1/0;for(let t of e)t.value<n&&(n=t.value),t.value>r&&(r=t.value);if(t)for(let e of t)e.value<n&&(n=e.value),e.value>r&&(r=e.value);let i=(r-n)*Ta;return{valMin:n-i,valMax:r+i}}function Oa(e){let t=[],n=-1/0;for(let r of e)r.value>n&&(n=r.value),t.push(n);return t}function ka(e){let t=864e5;if(365.25*t,e<7*t){let e=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`});return t=>e.format(new Date(t))}if(e<315576e5){let e=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`});return t=>e.format(new Date(t))}let n=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});return e=>n.format(new Date(e))}function Aa(e){return Math.abs(e)>=1e6?(e/1e6).toFixed(2)+`M`:Math.abs(e)>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function ja(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Ma(t,n,r,i,a,o,s,c,l){let{left:u,right:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=n;t.save(),t.strokeStyle=s.grid,t.lineWidth=.5,t.fillStyle=s.axisLabel,t.font=`${s.font.sizeSmall}px ${s.font.family}`;let g=(0,e.computeTickStep)(r,i,6),_=Math.ceil(r/g)*g;for(let e=_;e<=i;e+=g){let n=p-(e-r)/(i-r)*h;t.beginPath(),t.moveTo(u,n),t.lineTo(d,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),u-6,n)}let v=o-a,y=(0,e.computeTickStep)(a,o,6),b=Math.ceil(a/y)*y;for(let e=b;e<=o;e+=y){let n=u+(e-a)/v*m;t.beginPath(),t.moveTo(n,f),t.lineTo(n,p),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(l(e),n,p+4)}t.restore()}function Na(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-(e-a)/o*f;e.save(),e.beginPath(),e.moveTo(p(t[0].time),m(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(p(t[n].time),m(t[n].value));e.strokeStyle=s,e.lineWidth=c,e.lineJoin=`round`,e.stroke(),e.restore()}function Pa(e,t,n,r,i,a,o,s){if(t.length<2)return;let{left:c,bottom:l,plotWidth:u,plotHeight:d}=n,f=e=>c+(e-r)/i*u,p=e=>l-(e-a)/o*d,m=e.createLinearGradient(0,n.top,0,l);m.addColorStop(0,s+`40`),m.addColorStop(1,`transparent`),e.save(),e.beginPath(),e.moveTo(f(t[0].time),p(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(f(t[n].time),p(t[n].value));e.lineTo(f(t[t.length-1].time),l),e.lineTo(f(t[0].time),l),e.closePath(),e.fillStyle=m,e.fill(),e.restore()}function Fa(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=r,p=e=>l+(e-i)/a*d,m=e=>u-(e-o)/s*f;e.save(),e.fillStyle=c,e.beginPath(),e.moveTo(p(t[0].time),m(n[0]));for(let r=1;r<t.length;r++)e.lineTo(p(t[r].time),m(n[r]));for(let n=t.length-1;n>=0;n--)e.lineTo(p(t[n].time),m(t[n].value));e.closePath(),e.fill(),e.restore()}function Ia(e,t,n,r,i,a,o,s,c,l){if(t.length===0)return;let{left:u,bottom:d,plotWidth:f,plotHeight:p}=n,m=t[t.length-1],h=u+(m.time-r)/i*f,g=d-(m.value-a)/o*p;e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`,e.fillStyle=c,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(s,h+4,g),e.restore()}function La(e,t,n,r,i,a,o,s,c,l,u,d){let{left:f,top:p,bottom:m,plotWidth:h,plotHeight:g}=i,_=t.x;if(_<f||_>i.right)return;e.save(),e.strokeStyle=l.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(_,p),e.lineTo(_,m),e.stroke(),e.restore();let v=a+(_-f)/h*o,y=0,b=1/0;for(let e=0;e<n.length;e++){let t=Math.abs(n[e].time-v);t<b&&(b=t,y=e)}let x=n[y],S=[u(x.time),`Value: ${d(x.value)}`];r&&r.length>y&&S.push(`Benchmark: ${d(r[y].value)}`);let C=f+(x.time-a)/o*h,w=m-(x.value-s)/c*g;e.beginPath(),e.arc(C,w,3,0,Math.PI*2),e.fillStyle=l.lineColor,e.fill(),e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`;let T=Math.max(...S.map(t=>e.measureText(t).width))+16,E=S.length*(l.font.sizeSmall+4)+12,D=_+10,O=t.y-E/2;D+T>i.right&&(D=_-T-10),O<p&&(O=p),O+E>m&&(O=m-E),e.fillStyle=l.axisLabelBackground,e.globalAlpha=.9,e.fillRect(D,O,T,E),e.globalAlpha=1,e.fillStyle=l.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<S.length;t++)e.fillText(S[t],D+8,O+6+t*(l.font.sizeSmall+4));e.restore()}function Ra(e,t,n,r,i,a){let{data:o}=r;if(o.length<2||t<=0||n<=0)return;let s=r.lineColor??i.lineColor,c=r.lineWidth??1.5,l=r.drawdown===!0,u=r.drawdownColor??i.candleDown+`30`,d=r.fillArea===!0,f=r.benchmark,p=r.benchmarkColor??i.textSecondary,m=r.benchmarkLabel??`Benchmark`,h=r.valueFormat??Aa,{valMin:g,valMax:_}=Da(o,f),v=_-g||1,y=o[0].time,b=o[o.length-1].time,x=b-y||1,S=r.timeFormat??ka(x),C=Ea(t,n);ja(e,t,n,i.background),Ma(e,C,g,_,y,b,i,h,S),l&&Fa(e,o,Oa(o),C,y,x,g,v,u),d&&Pa(e,o,C,y,x,g,v,s),Na(e,o,C,y,x,g,v,s,c),f&&f.length>=2&&(Na(e,f,C,y,x,g,v,p,1),Ia(e,f,C,y,x,g,v,m,p,i)),a&&La(e,a,o,f,C,y,x,g,v,i,S,h)}function za(e,t,n){if(e.length===0)return[];let r=e.length,i=Math.ceil(Math.sqrt(r)),a=Math.ceil(r/i),o=t.width/i,s=t.height/a,c=[];for(let a=0;a<r;a++){let r=a%i,l=Math.floor(a/i);c.push({id:e[a].id,rect:{x:t.x+r*o+n,y:t.y+l*s+n,width:Math.max(0,o-n*2),height:Math.max(0,s-n*2)}})}return c}function Ba(e,t){let n=e.reduce((e,t)=>e+t,0);if(n===0||t===0)return 1/0;let r=0;for(let i of e){let e=n/t,a=i/e,o=e>a?e/a:a/e;o>r&&(r=o)}return r}function Va(e,t,n,r,i,a){let o=r?n.height:n.width,s=e.reduce((e,t)=>e+t,0),c=o>0?s/o:0,l=0;for(let o=0;o<e.length;o++){let s=c>0?e[o]/c:0,u;u=r?{x:n.x+i,y:n.y+l+i,width:Math.max(0,c-i*2),height:Math.max(0,s-i*2)}:{x:n.x+l+i,y:n.y+i,width:Math.max(0,s-i*2),height:Math.max(0,c-i*2)},a.push({id:t[o],rect:u}),l+=s}}function Ha(e,t,n,r,i){if(e.length===0)return;let a=n.width>=n.height,o=a?n.height:n.width;if(e.length===1){Va(e,t,n,a,r,i);return}let s=[],c=[],l=0;for(;l<e.length;){let u=[...s,e[l]];if(s.length===0||Ba(u,o)<=Ba(s,o))s.push(e[l]),c.push(t[l]),l++;else{Va(s,c,n,a,r,i);let u=s.reduce((e,t)=>e+t,0),d=o>0?u/o:0;n=a?{x:n.x+d,y:n.y,width:n.width-d,height:n.height}:{x:n.x,y:n.y+d,width:n.width,height:n.height-d},Ha(e.slice(l),t.slice(l),n,r,i);return}}s.length>0&&Va(s,c,n,a,r,i)}function Ua(e,t,n){if(e.length===0)return[];let r=[...e].sort((e,t)=>t.weight-e.weight),i=r.reduce((e,t)=>e+Math.max(0,t.weight),0);if(i===0)return[];let a=t.width*t.height,o=r.map(e=>Math.max(0,e.weight)/i*a),s=r.map(e=>e.id),c=[];return Ha(o,s,{...t},n,c),c}function Wa(e){return(e>=0?`+`:``)+e.toFixed(2)+`%`}function Ga(e){return e.label}function Ka(t,n){let r=n.min??-5,i=n.max??5;if(t<=r)return n.negative;if(t>=i)return n.positive;if(t<0){let i=1-t/r;return(0,e.lerpColor)(n.negative,n.zero,i)}let a=t/i;return(0,e.lerpColor)(n.zero,n.positive,a)}function qa(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function Ja(e,t,n,r,i,a,o,s,c,l,u){if(i<40||a<30)return;let d=n+i/2,f=r+a/2;if(e.save(),e.shadowColor=`rgba(0,0,0,0.6)`,e.shadowBlur=2,e.fillStyle=`#FFFFFF`,e.textAlign=`center`,s){let n=l(t),r=Math.min(o.font.sizeMedium,i/n.length*1.5,a/4);e.font=`bold `+Math.max(8,r)+`px `+o.font.family,e.textBaseline=c?`bottom`:`middle`,e.fillText(n,d,c?f-1:f,i-8)}if(c){let n=u(t.value),r=Math.min(o.font.sizeSmall,i/n.length*1.5,a/4);e.font=Math.max(7,r)+`px `+o.font.family,e.textBaseline=s?`top`:`middle`,e.fillText(n,d,s?f+1:f,i-8)}e.restore()}function Ya(e,t,n,r,i,a,o,s){let c=[o(t),s(t.value)];if(t.meta)for(let[e,n]of Object.entries(t.meta))c.push(e+`: `+String(n));e.save(),e.font=a.font.sizeSmall+`px `+a.font.family;let l=Math.max(...c.map(t=>e.measureText(t).width))+16,u=a.font.sizeSmall+4,d=c.length*u+12,f=n.x+14,p=n.y-d/2;f+l>r&&(f=n.x-l-14),p<0&&(p=0),p+d>i&&(p=i-d),e.fillStyle=a.axisLabelBackground,e.globalAlpha=.92,qa(e,f,p,l,d,4),e.fill(),e.globalAlpha=1,e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<c.length;t++)e.fillText(c[t],f+8,p+6+t*u);e.restore()}function Xa(e,t,n,r,i,a,o,s){if(r.length===0||i.length===0||t<=0||n<=0)return null;let c=a.colorScale??{negative:`#EF5350`,zero:`#424242`,positive:`#26A69A`},l=a.cellRadius??4,u=a.showLabels!==!1,d=a.showValues!==!1,f=a.valueFormat??Wa,p=a.labelFormat??Ga,m=new Map;for(let e of r)m.set(e.id,e);let h=null,g=null;if(s)for(let e of i){let{x:t,y:n,width:r,height:i}=e.rect;if(s.x>=t&&s.x<=t+r&&s.y>=n&&s.y<=n+i){h=e.id;let t=m.get(e.id);t&&(g={cell:t,rect:e});break}}e.fillStyle=o.background,e.fillRect(0,0,t,n);for(let t of i){let n=m.get(t.id);if(!n)continue;let{x:r,y:i,width:a,height:s}=t.rect;if(a<=0||s<=0)continue;let g=Ka(n.value,c);qa(e,r,i,a,s,l),e.fillStyle=g,e.fill(),Ja(e,n,r,i,a,s,o,u,d,p,f),t.id===h&&(qa(e,r,i,a,s,l),e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.stroke())}return g&&s&&Ya(e,g.cell,s,t,n,o,p,f),g}var Za=60,Qa=12,$a=24,eo=40,to=.7,no=1;function ro(e){return e.type?e.type:e.value>0?`positive`:e.value<0?`negative`:`subtotal`}function io(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function ao(e,t){return{left:Za,right:e-Qa,top:$a,bottom:t-eo,plotWidth:e-Za-Qa,plotHeight:t-$a-eo}}function oo(e,t,n,r,i){let a=Array(e.length),o=Array(e.length),s=t.plotWidth/e.length,c=s*n,l=(s-c)/2,{left:u,bottom:d,plotHeight:f}=t,p=0;for(let t=0;t<e.length;t++){let n=e[t],m=ro(n),h,g;m===`total`||m===`subtotal`?(h=0,g=n.value,p=n.value):(h=p,g=p+n.value,p=g);let _=Math.min(h,g),v=Math.max(h,g),y=d-(_-r)/i*f,b=d-(v-r)/i*f,x=Math.min(y,b),S=Math.max(Math.abs(b-y),no),C=u+t*s,w=C+l;a[t]={label:n.label,value:n.value,start:h,end:g,type:m,rectX:w,rectY:x,rectW:c,rectH:S,slotX:C,slotW:s},o[t]=p}return{bars:a,cumulatives:o}}function so(e){if(e.length===0)return{valMin:0,valMax:1};let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=ro(a),s,c;o===`total`||o===`subtotal`?(s=0,c=a.value,r=a.value):(s=r,c=r+a.value,r=c),s<t&&(t=s),c<t&&(t=c),s>n&&(n=s),c>n&&(n=c)}let i=(n-t||1)*.1;return{valMin:t-i,valMax:n+i}}function co(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function lo(t,n,r,i,a,o){let{left:s,right:c,top:l,bottom:u,plotHeight:d}=n,f=i-r||1;t.strokeStyle=a.grid,t.lineWidth=.5,t.fillStyle=a.axisLabel,t.font=`${a.font.sizeSmall}px ${a.font.family}`,t.textAlign=`right`,t.textBaseline=`middle`;let p=(0,e.computeTickStep)(r,i,5),m=Math.ceil(r/p)*p;t.beginPath();for(let e=m;e<=i;e+=p){let n=Math.round(u-(e-r)/f*d)+.5;n<l||n>u||(t.moveTo(s,n),t.lineTo(c,n))}t.stroke();for(let e=m;e<=i;e+=p){let n=u-(e-r)/f*d;n<l-1||n>u+1||t.fillText(o(e),s-6,n)}if(r<0&&i>0){let e=Math.round(u-(0-r)/f*d)+.5;t.strokeStyle=a.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(s,e),t.lineTo(c,e),t.stroke()}}function uo(e,t,n){let r=[`positive`,`negative`,`total`,`subtotal`];for(let i=0;i<r.length;i++){let a=r[i],o=n[a],s=!1;e.beginPath();for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==a)continue;let i=Math.round(r.rectX),o=Math.round(r.rectY),c=Math.round(r.rectW),l=Math.round(r.rectH);e.rect(i,o,c,l),s=!0}s&&(e.fillStyle=o,e.fill())}}function fo(e,t,n,r,i,a,o){if(o===`none`||t.length<2)return;let{bottom:s,plotHeight:c}=n;e.strokeStyle=a,e.lineWidth=1,o===`dashed`?e.setLineDash([4,4]):e.setLineDash([]),e.beginPath();for(let n=0;n<t.length-1;n++){let a=t[n],o=t[n+1],l=a.end,u=Math.round(s-(l-r)/i*c)+.5,d=Math.round(a.rectX+a.rectW),f=Math.round(o.rectX);f<=d||(e.moveTo(d,u),e.lineTo(f,u))}e.stroke(),e.setLineDash([])}function po(e,t,n,r,i,a){e.fillStyle=r.text,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`;for(let r=0;r<t.length;r++){let o=t[r],s;s=o.type===`total`||o.type===`subtotal`?i(o.value):a?`${o.value>=0?`+`:``}${i(o.value)}`:i(n[r]);let c=o.rectX+o.rectW/2;o.end<o.start?(e.textBaseline=`top`,e.fillText(s,c,o.rectY+o.rectH+4)):(e.textBaseline=`bottom`,e.fillText(s,c,o.rectY-4))}}function mo(e,t,n,r,i){e.fillStyle=r.axisLabel,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`top`;let a=n.bottom+6,o=t.length>0?t[0].slotW-4:0,s=!1;for(let n=0;n<t.length;n++)if(e.measureText(i(t[n].label)).width>o){s=!0;break}if(!s){for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.fillText(i(r.label),o,a)}return}e.save(),e.textAlign=`right`,e.textBaseline=`middle`;for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.setTransform(1,0,0,1,o,a+4),e.rotate(-Math.PI/4),e.fillText(i(r.label),0,0)}e.setTransform(1,0,0,1,0,0),e.restore()}function ho(e,t,n){if(t<n.left||t>n.right)return null;for(let n=0;n<e.length;n++){let r=e[n];if(t>=r.slotX&&t<=r.slotX+r.slotW)return n}return null}function go(e,t,n,r,i,a,o,s){let c=t[r],l=n[r],u=Math.round(c.slotX+c.slotW/2)+.5;e.strokeStyle=o.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(u,a.top),e.lineTo(u,a.bottom),e.stroke(),e.setLineDash([]);let d=[c.label,`Value: ${c.value>=0&&(c.type===`positive`||c.type===`negative`)?`+`:``}${s(c.value)}`,`Total: ${s(l)}`];e.font=`${o.font.sizeSmall}px ${o.font.family}`;let f=0;for(let t=0;t<d.length;t++){let n=e.measureText(d[t]).width;n>f&&(f=n)}let p=f+16,m=d.length*(o.font.sizeSmall+4)+12,h=i.x+10,g=i.y-m/2;h+p>a.right&&(h=i.x-p-10),g<a.top&&(g=a.top),g+m>a.bottom&&(g=a.bottom-m),e.fillStyle=o.axisLabelBackground,e.globalAlpha=.9,e.fillRect(h,g,p,m),e.globalAlpha=1,e.fillStyle=o.text,e.textAlign=`left`,e.textBaseline=`top`;let _=o.font.sizeSmall+4;for(let t=0;t<d.length;t++)e.fillText(d[t],h+8,g+6+t*_)}function _o(e,t,n,r,i,a){let{data:o}=r;if(!o||o.length===0||t<=0||n<=0)return{hitBar:null};let s=r.positiveColor??i.candleUp,c=r.negativeColor??i.candleDown,l=r.totalColor??i.lineColor,u=r.subtotalColor??i.textSecondary,d=r.connectorColor??i.textSecondary,f=r.connectorStyle??`dashed`,p=r.barWidth??to,m=r.showValues!==!1,h=r.showDelta!==!1,g=r.valueFormat??io,_=r.labelFormat??(e=>e),{valMin:v,valMax:y}=so(o),b=y-v||1,x=ao(t,n),{bars:S,cumulatives:C}=oo(o,x,p,v,b);co(e,t,n,i.background),lo(e,x,v,y,i,g),fo(e,S,x,v,b,d,f),uo(e,S,{positive:s,negative:c,total:l,subtotal:u}),m&&po(e,S,C,i,g,h),mo(e,S,x,i,_);let w=a?ho(S,a.x,x):null;return a&&w!==null&&go(e,S,C,w,a,x,i,g),{hitBar:w}}var vo=Math.PI/180,yo=135,bo=405,xo=.25;function So(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:Number.isInteger(e)?e.toFixed(0):e.toFixed(1)}function Q(e,t,n){return e<t?t:e>n?n:e}function Co(e,t,n){let r=n.min??0,i=n.max??100,a=i-r||1,o=(n.startAngle??yo)*vo,s=(n.endAngle??bo)*vo,c=n.thickness??xo,l=e/2,u=t/2+t*.05,d=Math.max(10,Math.min(e,t)/2-24);return{cx:l,cy:u,radius:d,innerRadius:Math.max(2,d*(1-c)),startAngle:o,endAngle:s,angleRange:s-o,min:r,max:i,range:a}}function $(e,t){let n=Q((e-t.min)/t.range,0,1);return t.startAngle+t.angleRange*n}function wo(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function To(e,t,n){e.beginPath(),e.arc(t.cx,t.cy,t.radius,t.startAngle,t.endAngle,!1),e.arc(t.cx,t.cy,t.innerRadius,t.endAngle,t.startAngle,!0),e.closePath(),e.fillStyle=n,e.fill()}function Eo(e,t,n){let r=Q(n.from,t.min,t.max),i=Q(n.to,t.min,t.max);if(i<=r)return;let a=$(r,t),o=$(i,t);e.beginPath(),e.arc(t.cx,t.cy,t.radius,a,o,!1),e.arc(t.cx,t.cy,t.innerRadius,o,a,!0),e.closePath(),e.fillStyle=n.color,e.fill()}function Do(e,t,n,r,i){let a=$(n,t);a<=t.startAngle||(e.globalAlpha=i,e.beginPath(),e.arc(t.cx,t.cy,t.radius,t.startAngle,a,!1),e.arc(t.cx,t.cy,t.innerRadius,a,t.startAngle,!0),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1)}function Oo(e,t,n,r){let i=$(n,t),a=Math.cos(i),o=Math.sin(i),s=t.radius-2,c=t.innerRadius*.25,l=-o,u=a,d=t.cx+a*s,f=t.cy+o*s,p=t.cx+l*4-a*c,m=t.cy+u*4-o*c,h=t.cx-l*4-a*c,g=t.cy-u*4-o*c;e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.lineTo(h,g),e.closePath(),e.fillStyle=r,e.fill(),e.beginPath(),e.arc(t.cx,t.cy,Math.max(4,t.innerRadius*.12),0,Math.PI*2),e.fill()}function ko(e,t,n,r,i){let a=Math.round(t.innerRadius*.55),o=Math.round(i.font.sizeMedium);e.fillStyle=i.text,e.textAlign=`center`,e.textBaseline=`middle`,e.font=`600 ${a}px ${i.font.family}`;let s=!!r,c=s?t.cy-o*.6:t.cy-a*.1;e.fillText(n,t.cx,c),s&&(e.fillStyle=i.textSecondary,e.font=`${o}px ${i.font.family}`,e.fillText(r,t.cx,t.cy+a*.55))}function Ao(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`;let i=t.radius+10,a=Math.cos(t.startAngle),o=Math.sin(t.startAngle),s=Math.cos(t.endAngle),c=Math.sin(t.endAngle),l=t.cx+a*i,u=t.cy+o*i,d=t.cx+s*i,f=t.cy+c*i;e.textBaseline=`middle`,e.textAlign=a<-.2?`right`:a>.2?`left`:`center`,e.fillText(n(t.min),l,u),e.textAlign=s<-.2?`right`:s>.2?`left`:`center`,e.fillText(n(t.max),d,f)}function jo(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`middle`;let i=(t.radius+t.innerRadius)/2;for(let r=0;r<n.length;r++){let a=n[r];if(!a.label)continue;let o=$((Q(a.from,t.min,t.max)+Q(a.to,t.min,t.max))/2,t),s=t.cx+Math.cos(o)*i,c=t.cy+Math.sin(o)*i;e.fillText(a.label,s,c)}}function Mo(e,t,n,r,i,a){if(t<=0||n<=0)return;let o=Co(t,n,r),s=r.trackColor??i.grid,c=r.needleColor??i.text,l=r.showValue!==!1,u=r.showZoneLabels===!0,d=r.valueFormat??So,f=Q(a,o.min,o.max);wo(e,t,n,i.background),To(e,o,s);let p=r.zones;if(p&&p.length>0)for(let t=0;t<p.length;t++)Eo(e,o,p[t]);Do(e,o,f,c,.12),Oo(e,o,f,c),l&&ko(e,o,d(f),r.label,i),Ao(e,o,d,i),u&&p&&p.length>0&&jo(e,o,p,i)}exports.ADXIndicator=st,exports.ATRIndicator=ot,exports.AcceleratorOscillatorIndicator=qt,exports.AccumulationDistributionIndicator=tn,exports.AlertDragHandler=hn,exports.AlertManager=ji,exports.AlligatorIndicator=$e,exports.AnchoredVWAPIndicator=We,exports.AnchoredVWAPTool=ar,exports.Animator=ta,exports.AreaRenderer=x,exports.AroonIndicator=ft,exports.ArrowTool=er,exports.AwesomeOscillatorIndicator=tt,exports.AxisDragHandler=mn,exports.BalanceOfPowerIndicator=Mt,exports.BarCountdown=yi,exports.BarRenderer=S,exports.BaseFinanceChart=ra,exports.BaselineRenderer=w,exports.BinanceAdapter=Gr,exports.BollingerBandsIndicator=Fe,exports.BracketTool=Cr,exports.BybitAdapter=ri,exports.CCIIndicator=ut,exports.CMFIndicator=ht,exports.CandlestickRenderer=g,exports.CanvasLayer=t,exports.ChaikinOscillatorIndicator=nt,exports.ChaikinVolatilityIndicator=Bt,exports.ChandeMomentumIndicator=Pt,exports.ChandelierExitIndicator=Qe,exports.ChartLegend=gi,exports.ChartStateManager=zi,exports.ChoppinessIndexIndicator=vt,exports.CoinbaseAdapter=Zr,exports.CompareRenderer=Ce,exports.ConnorsRSIIndicator=St,exports.CoppockIndicator=wt,exports.CrosshairHandler=vn,exports.CrosshairTooltip=Sn,exports.CurrentPriceLine=Rr,exports.DEFAULT_LEGEND_CONFIG=hi,exports.DEFAULT_SESSION_HOURS=Oi,exports.DPRManager=i,exports.DataExporter=Vi,exports.DateRangeTool=Xn,exports.DepthHeatmapBuffer=be,exports.DepthHeatmapRenderer=xe,exports.DepthOverlay=_r,exports.DetrendedPriceOscillatorIndicator=jt,exports.DisparityIndexIndicator=Xt,exports.DonchianChannelIndicator=Ve,exports.DrawingBase=B,exports.DrawingManager=An,exports.DrawingRenderer=jn,exports.EMAIndicator=Pe,exports.EaseOfMovementIndicator=It,exports.Easing=ea,exports.ElderRayIndicator=Et,exports.ElliottWaveTool=Jn,exports.EllipseTool=Wn,exports.Emitter=W,exports.EquivolumeRenderer=k,exports.EventBus=kn,exports.ExtendedLineTool=Ln,exports.FibExtensionTool=Hn,exports.FibRetracementTool=Bn,exports.FibTimeZonesTool=cr,exports.FinanceCrosshair=ia,exports.FisherTransformIndicator=At,exports.ForceIndexIndicator=xt,exports.GannBoxTool=ir,exports.GannFanTool=nr,exports.GridRenderer=sn,exports.HLCAreaRenderer=ee,exports.HollowCandleRenderer=C,exports.HorizontalLineTool=Pn,exports.HullMAIndicator=qe,exports.IchimokuIndicator=Le,exports.IndicatorBase=M,exports.IndicatorEngine=Me,exports.IndicatorWorkerHost=on,exports.InteractionManager=dn,exports.KSTIndicator=Tt,exports.KagiRenderer=E,exports.KeltnerChannelIndicator=Be,exports.KeyboardHandler=xn,exports.KlingerIndicator=kt,exports.KrakenAdapter=ui,exports.LayerManager=n,exports.LineRenderer=b,exports.LineWithMarkersRenderer=ne,exports.LinearRegressionChannelIndicator=Ke,exports.MACDIndicator=it,exports.MFIIndicator=dt,exports.MTFMovingAverageIndicator=Xe,exports.MarketProfileRenderer=le,exports.MassIndexIndicator=Nt,exports.MeasureOverlay=Ki,exports.MeasureTool=Zn,exports.MockAdapter=Kr,exports.OBVIndicator=ct,exports.OrderDraftTool=kr,exports.OrderRenderer=ur,exports.PanHandler=fn,exports.PaneResizeHandler=gn,exports.PaperExecutionAdapter=Pr,exports.ParabolicSARIndicator=Re,exports.ParallelChannelTool=Rn,exports.PercentagePriceOscillatorIndicator=Gt,exports.PeriodLevelsRenderer=me,exports.PinnedTooltip=Tn,exports.PitchforkTool=Kn,exports.PivotMarkersRenderer=ve,exports.PivotPointsIndicator=Ue,exports.PointAndFigureRenderer=D,exports.PollingAdapter=Jr,exports.PositionRenderer=gr,exports.PrettyGoodOscillatorIndicator=Qt,exports.PriceAxis=cn,exports.PriceRangeTool=Yn,exports.PriceVolumeTrendIndicator=zt,exports.QstickIndicator=Zt,exports.ROCIndicator=pt,exports.RSIIndicator=rt,exports.RayTool=In,exports.ReconnectManager=Lr,exports.RectangleTool=Un,exports.RegressionChannelTool=zn,exports.RelativeMomentumIndexIndicator=Yt,exports.RelativeVigorIndicator=Vt,exports.RenderEngine=p,exports.RenderLoop=r,exports.RenkoRenderer=T,exports.ReplayController=Br,exports.ReplayManager=Mi,exports.SMAIndicator=Ne,exports.SchaffTrendCycleIndicator=Dt,exports.Screenshot=_i,exports.SessionBreaks=bi,exports.SessionShading=ki,exports.SessionVWAPIndicator=Ze,exports.SignalMarkerManager=Ui,exports.StdDevIndicator=$t,exports.StepLineRenderer=te,exports.StochasticIndicator=at,exports.StochasticRSIIndicator=Ht,exports.StreamManager=zr,exports.SupertrendIndicator=ze,exports.TRIXIndicator=Ft,exports.TSIIndicator=mt,exports.TextAnnotationTool=$n,exports.TickAggregator=Ir,exports.TimeAxis=un,exports.TradeZoneManager=Gi,exports.TradingContextMenu=yr,exports.TradingDragHandler=vr,exports.TradingManager=Mr,exports.TradingRenderer=Nr,exports.TrendLineTool=Nn,exports.TriangleTool=Gn,exports.UltimateOscillatorIndicator=yt,exports.UndoRedoManager=Bi,exports.VROCIndicator=nn,exports.VWAPIndicator=Ie,exports.VerticalLineTool=Fn,exports.Viewport=m,exports.VolumeCandleRenderer=O,exports.VolumeDeltaIndicator=gt,exports.VolumeProfileIndicator=en,exports.VolumeProfileRangeTool=or,exports.VolumeProfileRenderer=ie,exports.VolumeRenderer=re,exports.VortexIndicator=_t,exports.Watermark=vi,exports.WebSocketAdapter=qr,exports.WilliamsADIndicator=Lt,exports.WilliamsRIndicator=lt,exports.ZigZagIndicator=Ge,exports.ZoomHandler=pn,exports.assignSessionLetters=se,exports.barIndexToX=a,exports.bracketRiskReward=xr,exports.classifyPivots=ge,exports.computeBracketDefaults=br,exports.computeMarketProfile=j,exports.computePeriodLevels=pe,exports.computeSessionProfiles=ce,exports.findDominantSwing=Mn,exports.findPivots=_e,exports.getIntParam=P,exports.getNumberParam=N,exports.getVisibleData=h,exports.inferOrderType=Dr,exports.isRegularSession=Di,exports.isWorkerResponse=an,exports.layoutSquarifiedTreemap=Ua,exports.layoutUniformGrid=za,exports.lttbDownsample=_,exports.lttbVisibleIndices=y,exports.minuteOfDay=Ei,exports.priceToY=o,exports.registerBuiltInDrawingTools=lr,exports.registerBuiltInIndicators=rn,exports.renderDepthChart=ba,exports.renderEquityCurve=Ra,exports.renderGauge=Mo,exports.renderHeatmap=Xa,exports.renderSparkline=aa,exports.renderWaterfall=_o,exports.resolveBarIndex=u,exports.timeToX=d,exports.timestampToBarIndex=l,exports.toHeikinAshi=we,exports.toKagi=Oe,exports.toLineBreak=De,exports.toPointAndFigure=ke,exports.toRangeBars=Ae,exports.toRenko=Te,exports.tpoLetter=oe,exports.xToBarIndex=s,exports.xToTime=f,exports.yToPrice=c;
24
+ `,t.addEventListener(`mouseenter`,()=>{t.style.background=`#2a2e39`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),o.appendChild(t)}n.appendChild(o),this.menuElement=o;let c=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!o.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,c),document.addEventListener(`keydown`,c),this.removeHandler=()=>{document.removeEventListener(`mousedown`,c),document.removeEventListener(`keydown`,c)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function Sr(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function Cr(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var wr=6,Tr=class{draft=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=Sr(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(e,t){if(!this.draft)return null;let n=[`entry`,`sl`,`tp`],r=null,i=wr;for(let a of n){let n=o(this.priceOf(a),t),s=Math.abs(n-e.y);s<=i&&(i=s,r=a)}return r}beginDrag(e,t){let n=this.hitTest(e,t);return n?(this.dragging=n,!0):!1}drag(e,t){if(!this.draft||!this.dragging)return!1;let n=c(e.y,t);return this.draft=Er(this.draft,this.dragging,n),!0}endDrag(){this.dragging=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r=2){let i=this.draft;if(!i)return;let{chartRect:a}=t,s=a.x,c=a.x+a.width,l=o(i.entry,t),u=o(i.stopLoss,t),d=o(i.takeProfit,t),f=n.candleUp,p=n.candleDown;e.save(),e.globalAlpha=.12,e.fillStyle=f,e.fillRect(s,Math.min(l,d),a.width,Math.abs(d-l)),e.fillStyle=p,e.fillRect(s,Math.min(l,u),a.width,Math.abs(u-l)),e.globalAlpha=1,Dr(e,s,c,l,n.text,[6,3]),Dr(e,s,c,d,f,[]),Dr(e,s,c,u,p,[]);let m=Cr(i),h=i.side===`buy`?`LONG`:`SHORT`;Or(e,s+6,l,`${h} entry ${i.entry.toFixed(r)}`,n.text,n.background),Or(e,s+6,d,`TP ${i.takeProfit.toFixed(r)} · ${m.toFixed(2)}R`,f,n.background),Or(e,s+6,u,`SL ${i.stopLoss.toFixed(r)}`,p,n.background);for(let[r,a]of[[i.entry,n.text],[i.takeProfit,f],[i.stopLoss,p]]){let n=o(r,t);e.fillStyle=a,e.beginPath(),e.arc(c-6,n,3.5,0,Math.PI*2),e.fill()}e.restore()}};function Er(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function Dr(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Or(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}function kr(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Ar=6,jr=class{draft=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:kr(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(e,t){return this.draft?Math.abs(o(this.draft.price,t)-e.y)<=Ar:!1}beginDrag(e,t){return this.hitTest(e,t)?(this.dragging=!0,!0):!1}drag(e,t){return!this.draft||!this.dragging?!1:this.setPrice(c(e.y,t))}endDrag(){this.dragging=!1}render(e,t,n,r,i=2){let a=this.draft;if(!a)return;let{chartRect:s}=t,c=s.x,l=s.x+s.width,u=o(a.price,t),d=kr(a.side,a.price,r),f=a.side===`buy`?n.candleUp:n.candleDown;e.save(),Mr(e,c,l,u,f,[6,3]);let p=a.side===`buy`?`BUY`:`SELL`;Nr(e,c+6,u,`${p} ${d.toUpperCase()} ${a.price.toFixed(i)}`,f,n.background),e.fillStyle=f,e.beginPath(),e.arc(l-6,u,3.5,0,Math.PI*2),e.fill(),e.restore()}};function Mr(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Nr(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}var Pr=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new fr;positionRenderer=new vr;depthOverlay=new yr;dragHandler;contextMenu=new xr;bracket=new Tr;orderDraft=new jr;requestRender=null;eventCallback=null;container=null;constructor(t){this.config={...e.DEFAULT_TRADING_CONFIG,...t},this.dragHandler=new br(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:Cr(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}onPointerDown(e,t){return this.config.enabled?this.bracket.isActive()&&this.bracket.beginDrag(e,t)||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t)?(this.requestRender?.(),!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,8):!1}onPointerMove(e,t){if(this.bracket.isDragging()){let n=this.bracket.drag(e,t);return n&&this.requestRender?.(),n}if(this.orderDraft.isDragging()){let n=this.orderDraft.drag(e,t);return n&&this.requestRender?.(),n}if(!this.dragHandler.isActive())return!1;let n=this.dragHandler.onPointerMove(e,t);return n&&this.requestRender?.(),n}onPointerUp(){if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let e=this.dragHandler.onPointerUp();return e?(e.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:e.id,newPrice:e.newPrice,previousPrice:e.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:e.id,[e.sourceType]:e.newPrice}),this.requestRender?.(),!0):!1}onContextMenu(e,t){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let n=c(e.y,t);return this.contextMenu.show(e,n,this.container,this.config),!0}render(e,t,n){this.config.enabled&&(this.depthData&&this.depthOverlay.render(e,this.depthData,t,this.config),this.positions.length>0&&this.positionRenderer.render(e,this.positions,this.currentPrice,t,n,this.config),this.orders.length>0&&this.orderRenderer.render(e,this.orders,t,n,this.config,this.dragHandler.getDragState()),this.bracket.isActive()&&this.bracket.render(e,t,n,this.config.pricePrecision??2),this.orderDraft.isActive()&&this.orderDraft.render(e,t,n,this.currentPrice,this.config.pricePrecision??2))}renderAxisBadges(e,t,n){this.config.enabled&&(this.positions.length>0&&this.positionRenderer.renderAxisBadges(e,this.positions,t,n,this.config),this.orders.length>0&&this.orderRenderer.renderAxisBadges(e,this.orders,t,n,this.config,this.dragHandler.getDragState()))}destroy(){this.contextMenu.destroy()}},Fr=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}},Ir=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e){this.markPrice=e,this.checkPendingOrders(),this.checkStops()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:Lr(e.type),draggable:!0};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){this.positions=this.positions.map(t=>t.id===e.positionId?{...t,stopLoss:e.stopLoss??t.stopLoss,takeProfit:e.takeProfit??t.takeProfit}:t),this.emit(`positions`,this.positions)}async closePosition(e){this.positions=this.positions.filter(t=>t.id!==e.positionId),this.emit(`positions`,this.positions)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:Date.now()};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=[],t=!1;for(let n of this.positions){let r=n.stopLoss!==void 0&&(n.side===`buy`?this.markPrice<=n.stopLoss:this.markPrice>=n.stopLoss),i=n.takeProfit!==void 0&&(n.side===`buy`?this.markPrice>=n.takeProfit:this.markPrice<=n.takeProfit);if(r||i){t=!0;continue}e.push(n)}t&&(this.positions=e,this.emit(`positions`,this.positions))}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Lr(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var H=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},Rr=class extends H{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(t,n=1e3){super(),this.timeframeMs=(0,e.timeframeToMs)(t),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(t){this.timeframeMs=(0,e.timeframeToMs)(t),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return Math.floor(e/this.timeframeMs)*this.timeframeMs}},U=class extends H{config;attempt=0;timer=null;active=!1;constructor(t){super(),this.config={...e.DEFAULT_RECONNECT,...t}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},zr=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=2;setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}render(t,n,r){if(!this.visible||this.price===null)return;let i=o(this.price,n),{chartRect:a}=n;if(i<a.y||i>a.y+a.height)return;let s=this.previousClose===null||this.price>=this.previousClose?r.candleUp??`#26A69A`:r.candleDown??`#EF5350`,c=Date.now()<this.flashUntil;t.setLineDash([4,3]),t.strokeStyle=s,t.lineWidth=1,t.globalAlpha=c?1:.7,t.beginPath(),t.moveTo(a.x,Math.round(i)+.5),t.lineTo(a.x+a.width,Math.round(i)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let l=a.x+a.width+1,u=this.price.toFixed(this.pricePrecision);t.font=`bold 11px ${r.font.family}`;let d=t.measureText(u).width,f=Math.min(d+12,e.PRICE_AXIS_WIDTH-2);t.fillStyle=s,t.fillRect(l,i-10,f,20);let p=l-5;t.beginPath(),t.moveTo(p,i),t.lineTo(p+5,i-5),t.lineTo(p+5,i+5),t.closePath(),t.fill(),t.fillStyle=`#FFFFFF`,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(u,l+5,i)}},Br=class extends H{config=null;adapter=null;aggregator=null;reconnector;priceLine=new zr;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;constructor(){super(),this.reconnector=new U,this.wireReconnector()}async connect(t){this.disconnect(),this.config={...e.DEFAULT_STREAM_CONFIG,...t},this.adapter=t.adapter,this.aggregator=new Rr(t.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new U(t.reconnect??e.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.adapter.disconnect(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!(!this.config||!this.adapter)){this.setState(`connecting`);try{let e=await this.adapter.fetchHistory(this.config.symbol,this.config.timeframe,this.config.historyLimit??500);e.length>0&&(this.previousClose=e[e.length-1].close,this.updatePrice(e[e.length-1].close)),this.emit(`snapshot`,e),this.adapter.connect({symbol:this.config.symbol,timeframe:this.config.timeframe}),this.startHeartbeat()}catch(e){let t=e instanceof Error?e.message:String(e);this.emit(`error`,{message:t,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i))}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Vr=class extends H{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Hr(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=W(e[1]),r=W(e[2]),i=W(e[3]),a=W(e[4]),o=W(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Ur(e){if(!Wr(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=W(e.o),r=W(e.h),i=W(e.l),a=W(e.c),o=W(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function W(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Wr(e){return typeof e==`object`&&!!e}var Gr={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},Kr=class{name=`binance`;ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){this.ws&&=(this.ws.onclose=null,this.ws.close(),null),this.setState(`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n=500){let r=Gr[t]??`15m`,i=`${this.restBase}/klines?symbol=${e}&interval=${r}&limit=${n}`,a=await fetch(i);if(!a.ok)throw Error(`Binance REST error: ${a.status}`);let o=await a.json();if(!Array.isArray(o))return[];let s=[];for(let e of o){let t=Hr(e);t&&s.push(t)}return s}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Gr[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Ur(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},qr=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n){return this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(t,n){let r=[],i=Date.now(),a=(0,e.timeframeToMs)(t),o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=i-e*a,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let t=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let t=this.options.volatility/100,n=(Math.random()-.48)*this.currentPrice*t*.3;this.currentPrice+=n;let r=Date.now(),i=(0,e.timeframeToMs)(this.config.timeframe),a={time:Math.floor(r/i)*i,open:this.currentPrice-n,high:Math.max(this.currentPrice,this.currentPrice-n)+Math.abs(n)*.2,low:Math.min(this.currentPrice,this.currentPrice-n)-Math.abs(n)*.2,close:this.currentPrice,volume:Math.floor(100+Math.random()*5e3)};this.emitEvent(`bar`,{bar:a,closed:!1}),this.emitEvent(`tick`,{time:r,price:this.currentPrice,volume:a.volume})},t)}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Jr=class{name;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}this.ws.onclose=null,this.ws.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Yr=class{name;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function G(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function K(e){return typeof e==`object`&&!!e}var Xr={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function Zr(e){return Xr[e]??3600}var Qr=class extends Yr{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>$r(t,e,n)})}};async function $r(e,t,n){let r=`${e}/products/${t}/candles?granularity=${Zr(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return ei(await i.json())}function ei(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=ti(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function ti(e){if(!Array.isArray(e)||e.length<6)return null;let t=G(e[0]),n=G(e[1]),r=G(e[2]),i=G(e[3]),a=G(e[4]),o=G(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var ni={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function ri(e){return ni[e]??`1`}var ii=class extends Jr{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${ri(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${ri(e.timeframe)}.${e.symbol}`]}),parseMessage:ai,fetchHistory:(e,n,i)=>oi(t,r,e,n,i)})}};function ai(e){if(!K(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!K(n))return null;let r=G(n.start),i=G(n.open),a=G(n.high),o=G(n.low),s=G(n.close),c=G(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function oi(e,t,n,r,i){let a=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${ri(r)}&limit=${Math.min(Math.max(i,1),1e3)}`,o=await fetch(a);if(!o.ok)throw Error(`Bybit REST error: ${o.status}`);return si(await o.json())}function si(e){if(!K(e)||!K(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=ci(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function ci(e){if(!Array.isArray(e)||e.length<6)return null;let t=G(e[0]),n=G(e[1]),r=G(e[2]),i=G(e[3]),a=G(e[4]),o=G(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var li={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function ui(e){return li[e]??1}var di=class extends Jr{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ui(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ui(e.timeframe)}}),parseMessage:fi,fetchHistory:(e,n)=>pi(t,e,n)})}};function fi(e){if(!K(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!K(n))return null;let r=G(n.open),i=G(n.high),a=G(n.low),o=G(n.close),s=G(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function pi(e,t,n){let r=ui(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return mi(await o.json())}function mi(e){if(!K(e)||!K(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=hi(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function hi(e){if(!Array.isArray(e)||e.length<7)return null;let t=G(e[0]),n=G(e[1]),r=G(e[2]),i=G(e[3]),a=G(e[4]),o=G(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var gi={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12},_i=class{config={...gi};symbol=``;timeframe=``;hoverBar=null;indicators=[];statusText=null;setConfig(e){Object.assign(this.config,e)}setSymbol(e){this.symbol=e}setTimeframe(e){this.timeframe=e}setChartType(e){}setHoverBar(e){this.hoverBar=e}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e}render(e,t,n,r){if(!this.config.visible||r.length===0)return;let i=this.hoverBar??r[r.length-1],a=r.length>1?r[r.length-2]:i,{chartRect:o}=t,s=this.config.fontSize,c=this.config.position===`top-left`,l=c?o.x+8:o.x+o.width-8,u=o.y+6;if(e.textAlign=c?`left`:`right`,e.textBaseline=`top`,this.config.showSymbol){e.font=`bold ${s+2}px ${n.font.family}`,e.fillStyle=n.text;let t=[this.symbol,this.timeframe].filter(Boolean).join(` · `),r=this.statusText?`${t} ${this.statusText}`:t;e.fillText(r,l,u),u+=s+6}else this.statusText&&(e.font=`${s}px ${n.font.family}`,e.fillStyle=n.textSecondary,e.fillText(this.statusText,l,u),u+=s+4);if(this.config.showOHLC){e.font=`${s}px ${n.font.family}`;let t=i.close>=i.open,r=e=>e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),o=[{label:`O`,value:r(i.open),color:n.text},{label:`H`,value:r(i.high),color:n.text},{label:`L`,value:r(i.low),color:n.text},{label:`C`,value:r(i.close),color:t?n.candleUp:n.candleDown}];if(this.config.showChange){let e=i.close-a.close,t=a.close===0?0:e/a.close*100,s=e>=0?`+`:``;o.push({label:``,value:`${s}${r(e)} (${s}${t.toFixed(2)}%)`,color:e>=0?n.candleUp:n.candleDown})}let d=l;if(c)for(let t of o)t.label&&(e.fillStyle=n.textSecondary,e.fillText(t.label,d,u),d+=e.measureText(t.label+` `).width),e.fillStyle=t.color,e.fillText(t.value,d,u),d+=e.measureText(t.value+` `).width;else{let t=o.map(e=>`${e.label} ${e.value}`).join(` `);e.fillStyle=n.text,e.fillText(t,l,u)}u+=s+3}if(this.config.showVolume){e.font=`${s-1}px ${n.font.family}`,e.fillStyle=n.textSecondary;let t=i.volume>=1e6?`${(i.volume/1e6).toFixed(2)}M`:i.volume>=1e3?`${(i.volume/1e3).toFixed(2)}K`:i.volume.toFixed(0);e.fillText(`Vol ${t}`,l,u),u+=s+2}if(this.indicators.length>0){e.font=`${s-1}px ${n.font.family}`;let t=l;for(let n of this.indicators){e.fillStyle=n.color;let r=`${n.name} ${n.value}`;e.fillText(r,t,u),t+=e.measureText(r+` `).width}}}},vi=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},yi=class{config=null;setConfig(e){this.config=e}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},bi=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}render(e,t,n,r){if(!this.visible||this.timeframeMs<=0||r.length===0)return;let i=r[r.length-1],o=(i.time>0xe8d4a51000?i.time:i.time*1e3)+this.timeframeMs-Date.now();if(o<=0)return;let s=this.formatRemaining(o),c=a(r.length-1,t),l=t.chartRect.y+t.chartRect.height-4;c<t.chartRect.x||c>t.chartRect.x+t.chartRect.width||(e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`bottom`,e.textAlign=`center`,e.fillStyle=n.textSecondary,e.fillText(s,c,l))}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}},xi=class{config={visible:!1};cachedBreaksTyped=[];lastDataLength=0;setConfig(e){Object.assign(this.config,e)}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(e){if(e.length<2)return[];if(e.length===this.lastDataLength&&this.cachedBreaksTyped.length>0)return this.cachedBreaksTyped;let t=[],n=new Date(this.toMs(e[0].time));for(let r=1;r<e.length;r++){let i=new Date(this.toMs(e[r].time));if(i.getFullYear()!==n.getFullYear())t.push({idx:r,kind:`year`,date:i});else if(i.getMonth()!==n.getMonth())t.push({idx:r,kind:`month`,date:i});else if(i.getDate()!==n.getDate()){let e=i.getDay()===1;t.push({idx:r,kind:e?`week`:`day`,date:i})}n=i}return this.lastDataLength=e.length,this.cachedBreaksTyped=t,t}toMs(e){return e>0xe8d4a51000?e:e*1e3}render(e,t,n,r){if(!this.config.visible||r.length<2)return;let i=this.computeBreaksTyped(r);if(i.length===0||Ti(r)>=1380*60*1e3)return;let{chartRect:o}=t,s=this.config.color??n.axisLine,c=this.config.lineWidth??1,l=this.config.lineStyle??`dashed`;e.save(),l===`dashed`?e.setLineDash([6,4]):l===`dotted`&&e.setLineDash([2,3]),e.font=`600 11px ${n.font.family}`,e.textBaseline=`top`,e.textAlign=`left`;for(let r of i){let i=a(r.idx,t)-(t.barWidth+t.barSpacing)/2;if(i<o.x-1||i>o.x+o.width+1)continue;let l=Math.round(i)+.5,u=.25,d=c,f=null;r.kind===`day`?u=.22:r.kind===`week`?(u=.34,f=Ci(r.date)):r.kind===`month`?(u=.5,d=c+.5,f=wi(r.date)):(u=.7,d=c+1,f=String(r.date.getFullYear())),e.globalAlpha=u,e.strokeStyle=s,e.lineWidth=d,e.beginPath(),e.moveTo(l,o.y),e.lineTo(l,o.y+o.height),e.stroke(),f&&(e.globalAlpha=Math.min(1,u+.35),e.fillStyle=n.textSecondary,e.fillText(f,l+4,o.y+4))}e.restore()}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[]}},Si=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Ci(e){return`${Si[e.getMonth()]} ${e.getDate()}`}function wi(e){return`${Si[e.getMonth()]} ${String(e.getFullYear()).slice(-2)}`}function Ti(e){if(e.length<2)return 0;let t=Math.min(50,e.length-1),n=[];for(let r=1;r<=t;r++){let t=e[r-1].time,i=e[r].time,a=t>0xe8d4a51000?t:t*1e3,o=i>0xe8d4a51000?i:i*1e3;n.push(o-a)}return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]}var q=864e5;function Ei(e,t){let n=((e+t*6e4)%q+q)%q;return Math.floor(n/6e4)}function Di(e,t,n){return t===n?!0:t<n?e>=t&&e<n:e>=t||e<n}function Oi(e,t){let n=Ei(e,t.tzOffsetMinutes);return t.windows&&t.windows.length>0?t.windows.some(e=>Di(n,e.startMinute,e.endMinute)):Di(n,t.startMinute,t.endMinute)}var ki={startMinute:570,endMinute:960,tzOffsetMinutes:-300},Ai=class{visible=!1;config={...ki};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){let t={...this.config,...e};t.windows=t.windows?t.windows.map(e=>({...e})):void 0,this.config=t}getConfig(){return{...this.config,windows:this.config.windows?.map(e=>({...e}))}}render(e,t,n,r){if(!this.visible||t.length===0)return;let{chartRect:i}=n,{from:o,to:s}=n.visibleRange,c=Math.max(0,o),l=Math.min(s,t.length-1);if(l<c)return;let u=n.barWidth+n.barSpacing,d=r.name===`light`;e.save(),e.fillStyle=d?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`;let f=-1,p=(t,r)=>{let o=a(t,n)-u/2,s=a(r,n)+u/2;e.fillRect(o,i.y,s-o,i.height)};for(let e=c;e<=l;e++){let n=!Oi(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}f!==-1&&p(f,l),e.restore()}},ji=1,Mi=class extends H{alerts=[];lastValues=new Map;requestRender=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a){let o=`tc_alert_${ji++}`,s={id:o,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a};return this.alerts.push(s),this.emit(`added`,s),this.requestRender?.(),o}removeAlert(e){this.alerts=this.alerts.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(e,t,n=6){let{chartRect:r}=t;if(e.y<r.y||e.y>r.y+r.height)return null;let i=null,a=n;for(let n of this.alerts){if(n.channel!==`price`)continue;let r=Math.abs(o(n.price,t)-e.y);r<=a&&(a=r,i=n)}return i}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e)}checkChannel(e,t){if(!Number.isFinite(t))return;let n=this.lastValues.get(e);if(n===void 0){this.lastValues.set(e,t);return}for(let r of this.alerts){if(r.channel!==e)continue;let i=!1;switch(r.condition){case`crossingUp`:i=n<r.price&&t>=r.price;break;case`crossingDown`:i=n>r.price&&t<=r.price;break;case`crossing`:i=n<r.price&&t>=r.price||n>r.price&&t<=r.price;break;case`greaterThan`:i=t>r.price;break;case`lessThan`:i=t<r.price;break}i?r.triggered||(r.triggered=!0,this.emit(`triggered`,{...r})):r.repeating&&(r.triggered=!1)}this.lastValues.set(e,t)}clearLastValues(){this.lastValues.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n)e.price!=null&&Number.isFinite(e.price)&&e.condition&&!e.triggered&&this.addAlert(e.price,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label)}catch{}}render(e,t,n){let{chartRect:r}=t;for(let i of this.alerts){if(i.channel!==`price`)continue;let a=o(i.price,t);if(a<r.y||a>r.y+r.height)continue;let s=i.triggered?`#FF9800`:`#FFD700`;e.setLineDash([2,6]),e.strokeStyle=s,e.lineWidth=1,e.beginPath(),e.moveTo(r.x,Math.round(a)+.5),e.lineTo(r.x+r.width,Math.round(a)+.5),e.stroke(),e.setLineDash([]),e.font=`10px ${n.font.family}`,e.fillStyle=s,e.textBaseline=`bottom`,e.textAlign=`right`;let c=`🔔 ${i.price.toFixed(this.pricePrecision)}${i.message?` - ${i.message}`:``}`;e.fillText(c,r.x+r.width-4,a-2)}}},Ni=class extends H{data=[];currentIndex=0;timer=null;state=`stopped`;config={speed:1,interval:500};load(e){this.stop(),this.data=e,this.currentIndex=0}play(e){this.data.length!==0&&(e&&Object.assign(this.config,e),e?.startIndex!==void 0&&(this.currentIndex=e.startIndex),this.state=`playing`,this.emit(`stateChange`,`playing`),this.timer=setInterval(()=>{if(this.currentIndex>=this.data.length){this.stop(),this.emit(`complete`,void 0);return}let e=this.data[this.currentIndex];this.emit(`bar`,{bar:e,index:this.currentIndex,total:this.data.length}),this.currentIndex++},this.config.interval/this.config.speed))}pause(){this.timer&&=(clearInterval(this.timer),null),this.state=`paused`,this.emit(`stateChange`,`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.timer&&=(clearInterval(this.timer),null),this.state=`stopped`,this.currentIndex=0,this.emit(`stateChange`,`stopped`)}seekTo(e){if(this.data.length===0)return;let t=Math.max(0,Math.min(e,this.data.length-1));this.currentIndex=t;let n=this.data[t];this.emit(`bar`,{bar:n,index:t,total:this.data.length})}setSpeed(e){this.config.speed=e,this.state===`playing`&&(this.pause(),this.play())}getState(){return this.state}getProgress(){return{current:this.currentIndex,total:this.data.length,percent:this.data.length>0?this.currentIndex/this.data.length*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}},J=1;function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e){return Array.isArray(e)?e:[]}function Pi(e,t){return typeof e==`string`?e:t}function Z(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function Fi(e){if(!Y(e)||typeof e.id!=`string`||typeof e.type!=`string`||!Array.isArray(e.anchors)||e.anchors.length===0||!Y(e.style))return null;let t=[];for(let n of e.anchors){if(!Y(n)||typeof n.time!=`number`||typeof n.price!=`number`||!Number.isFinite(n.time)||!Number.isFinite(n.price))return null;t.push({time:n.time,price:n.price})}let n=e.style;return typeof n.color!=`string`||typeof n.lineWidth!=`number`?null:{id:e.id,type:e.type,anchors:t,style:n,visible:typeof e.visible==`boolean`?e.visible:!0,locked:typeof e.locked==`boolean`?e.locked:!1,meta:Y(e.meta)?e.meta:void 0}}function Ii(e){return!Y(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function Li(e){return!Y(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}function Ri(e){if(!Y(e))return zi();typeof e.version==`number`&&e.version!==J&&console.warn(`Chart state version mismatch: ${e.version} vs ${J}`);let t=Y(e.viewport)?e.viewport:{},n=[];for(let t of X(e.indicators))Y(t)&&(typeof t.id!=`string`||typeof t.instanceId!=`string`||Y(t.params)&&n.push({id:t.id,instanceId:t.instanceId,params:t.params,position:typeof t.position==`string`?t.position:void 0}));let r=[];for(let t of X(e.drawings)){let e=Fi(t);e&&r.push(e)}let i=[];for(let t of X(e.orders)){let e=Ii(t);e&&i.push(e)}let a=[];for(let t of X(e.positions)){let e=Li(t);e&&a.push(e)}let o=[];for(let t of X(e.alerts))Y(t)&&typeof t.id==`string`&&o.push(t);return{version:typeof e.version==`number`?e.version:J,timestamp:Z(e.timestamp,Date.now()),symbol:typeof e.symbol==`string`?e.symbol:void 0,timeframe:typeof e.timeframe==`string`?e.timeframe:void 0,chartType:Pi(e.chartType,`candlestick`),viewport:{barWidth:Z(t.barWidth,8),barSpacing:Z(t.barSpacing,2),offset:Z(t.offset,0)},theme:typeof e.theme==`string`?e.theme:void 0,locale:typeof e.locale==`string`?e.locale:void 0,indicators:n,drawings:r,orders:i,positions:a,alerts:o}}function zi(){return{version:J,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var Bi=class{static capture(e,t){return{version:J,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return Ri(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},Vi=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},Hi=class{static toCSV(e){return[`Time,Open,High,Low,Close,Volume`,...e.map(e=>`${new Date(e.time).toISOString()},${e.open},${e.high},${e.low},${e.close},${e.volume}`)].join(`
25
+ `)}static toJSON(e){return JSON.stringify(e.map(e=>({time:new Date(e.time).toISOString(),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})),null,2)}static download(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}},Ui=1,Wi=class extends H{markers=[];style={...e.DEFAULT_SIGNAL_STYLE};requestRender=null;dataGetter=null;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addMarker(e){let t=e.id??`tc_signal_${Ui++}`,n={...e,id:t};return this.markers.push(n),this.emit(`added`,n),this.requestRender?.(),t}removeMarker(e){this.markers=this.markers.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getMarkers(){return[...this.markers]}clearMarkers(){this.markers=[],this.emit(`cleared`,void 0),this.requestRender?.()}setMarkers(e){this.markers=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.markers.length===0)return;let{chartRect:i,visibleRange:s}=t,c=this.style,u=c.arrowSize??12;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let d of this.markers){let f=l(d.time,r);if(f<s.from-1||f>s.to+1)continue;let p=a(f,t),m=o(d.price,t);if(p<i.x-u||p>i.x+i.width+u||m<i.y-u||m>i.y+i.height+u)continue;let h=this.resolveColor(d,c),g=u*Math.max(.6,Math.min(1,d.confidence));if(this.renderArrow(e,p,m,d.direction,g,h),c.showLabel&&d.label){e.font=`10px ${n.font.family}`,e.fillStyle=h,e.textAlign=`center`,e.textBaseline=d.direction===`long`?`top`:`bottom`;let t=d.direction===`long`?m+g+3:m-g-3;e.fillText(d.label,p,t)}if(c.showConfidence&&d.confidence<1){e.font=`9px ${n.font.family}`,e.fillStyle=h,e.globalAlpha=.7,e.textAlign=`center`,e.textBaseline=d.direction===`long`?`top`:`bottom`;let t=d.direction===`long`?m+g+(d.label?14:3):m-g-(d.label?14:3);e.fillText(`${Math.round(d.confidence*100)}%`,p,t),e.globalAlpha=1}}e.restore()}resolveColor(e,t){if(e.color)return e.color;if(t.sourceColors?.[e.source])return t.sourceColors[e.source];switch(e.direction){case`long`:return t.longColor??`#26A69A`;case`short`:return t.shortColor??`#EF5350`;default:return t.neutralColor??`#9E9E9E`}}renderArrow(e,t,n,r,i,a){e.fillStyle=a,e.beginPath(),r===`long`?(e.moveTo(t,n-i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n+i*.4),e.lineTo(t+i*.2,n+i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):r===`short`?(e.moveTo(t,n+i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n-i*.4),e.lineTo(t+i*.2,n-i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):e.arc(t,n,i*.4,0,Math.PI*2),e.closePath(),e.fill()}},Gi=1,Ki=class extends H{zones=[];style={...e.DEFAULT_TRADE_ZONE_STYLE};requestRender=null;dataGetter=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setPricePrecision(e){this.pricePrecision=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addZone(e){let t=e.id??`tc_zone_${Gi++}`,n={...e,id:t};return this.zones.push(n),this.emit(`added`,n),this.requestRender?.(),t}updateZone(e,t){let n=this.zones.findIndex(t=>t.id===e);n!==-1&&(this.zones[n]={...this.zones[n],...t},this.requestRender?.())}removeZone(e){this.zones=this.zones.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getZones(){return[...this.zones]}clearZones(){this.zones=[],this.emit(`cleared`,void 0),this.requestRender?.()}setZones(e){this.zones=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.zones.length===0)return;let{chartRect:i}=t,a=this.style;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.zones)this.renderZone(e,i,r,t,n,a);e.restore()}renderZone(e,t,n,r,i,s){let{chartRect:c,visibleRange:u}=r,d=l(t.entryTime,n),f=t.exitTime==null?n.length-1:l(t.exitTime,n);if(f<u.from||d>u.to)return;let p=a(d,r),m=a(f,r),h=Math.max(c.x,Math.min(p,m)),g=Math.min(c.x+c.width,Math.max(p,m));if(g-h<1)return;let _=o(t.entryPrice,r),v=t.exitPrice==null?o(t.entryPrice,r):o(t.exitPrice,r),y=Math.min(_,v),b=Math.max(Math.max(_,v)-y,2),x=t.exitTime==null,S=t.pnl==null?t.direction===`long`?(t.exitPrice??t.entryPrice)>=t.entryPrice:(t.exitPrice??t.entryPrice)<=t.entryPrice:t.pnl>=0,C=x?s.activeColor??`#2196F3`:S?s.profitColor??`#26A69A`:s.lossColor??`#EF5350`;e.fillStyle=C,e.globalAlpha=s.fillOpacity??.12,e.fillRect(h,y,g-h,b),e.globalAlpha=1;let w=s.borderWidth??1;e.strokeStyle=C,e.lineWidth=w,e.setLineDash([]),e.beginPath(),e.moveTo(h,Math.round(_)+.5),e.lineTo(g,Math.round(_)+.5),e.stroke(),!x&&t.exitPrice!=null&&(e.setLineDash([3,3]),e.beginPath(),e.moveTo(h,Math.round(v)+.5),e.lineTo(g,Math.round(v)+.5),e.stroke(),e.setLineDash([]));let T=t.direction===`long`?`▲`:`▼`;if(e.font=`bold 10px ${i.font.family}`,e.fillStyle=C,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(`${T} ${t.entryPrice.toFixed(this.pricePrecision)}`,h+4,_-3),s.showPnl&&!x&&t.pnl!=null){let n=t.pnl>=0?`+`:``,r=t.pnlPercent==null?`${n}${t.pnl.toFixed(2)}`:`${n}${t.pnl.toFixed(2)} (${n}${t.pnlPercent.toFixed(2)}%)`;e.font=`bold 10px ${i.font.family}`,e.fillStyle=C,e.textBaseline=`top`,e.textAlign=`right`;let a=e.measureText(r).width+8,o=g-a-2,s=y+2;e.globalAlpha=.85,e.fillStyle=i.background,e.fillRect(o,s,a,14),e.globalAlpha=1,e.fillStyle=C,e.fillText(r,g-4,s+1)}s.showLabel&&t.label&&(e.font=`9px ${i.font.family}`,e.fillStyle=C,e.globalAlpha=.8,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(t.label,h+4,_+3),e.globalAlpha=1)}},qi=class{active=!1;startBar=0;startPrice=0;endBar=0;endPrice=0;startTime=null;endTime=null;isActive(){return this.active}begin(e,t,n){let r=Math.round(s(e.x,t)),i=c(e.y,t);this.startBar=r,this.startPrice=i,this.endBar=r,this.endPrice=i,this.startTime=Ji(r,n),this.endTime=this.startTime,this.active=!0}update(e,t,n){if(!this.active)return;let r=Math.round(s(e.x,t));this.endBar=r,this.endPrice=c(e.y,t),this.endTime=Ji(r,n)}end(){this.active=!1}render(e,t,n){if(!this.active)return;let r=a(this.startBar,t),i=a(this.endBar,t),s=o(this.startPrice,t),c=o(this.endPrice,t),l=Math.min(r,i),u=Math.max(r,i),d=Math.min(s,c),f=Math.max(s,c),p=u-l,m=f-d,h=this.endPrice>=this.startPrice?n.candleUp:n.candleDown,g=ea(h,.14);e.save(),e.fillStyle=g,e.fillRect(l,d,p,m),e.strokeStyle=h,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(l+.5,d+.5,p,m),e.setLineDash([]),e.strokeStyle=h,e.lineWidth=1.5,e.beginPath(),e.moveTo(r,s),e.lineTo(i,c),e.stroke(),Zi(e,r,s,h),Zi(e,i,c,h);let _=Math.abs(this.endBar-this.startBar),v=this.endPrice-this.startPrice,y=this.startPrice===0?0:v/this.startPrice*100,b=this.startTime!==null&&this.endTime!==null?Xi(Math.abs(this.endTime-this.startTime)):null,x=[],S=v>0?`+`:v<0?`−`:``,C=Math.abs(v);x.push(`${S}${Yi(C)} (${S}${Math.abs(y).toFixed(2)}%)`),x.push(`${_} bars${b?` · `+b:``}`),Qi(e,i,c,x,h,n),e.restore()}};function Ji(e,t){if(e<0||e>=t.length)return null;let n=t[e].time;return n>0xe8d4a51000?n:n*1e3}function Yi(e){return e>=1e3?e.toFixed(2):e>=1?e.toFixed(4):e.toPrecision(4)}function Xi(e){let t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;let n=t/60;if(n<60)return`${n.toFixed(1)}m`;let r=n/60;if(r<24)return`${r.toFixed(1)}h`;let i=r/24;if(i<30)return`${i.toFixed(1)}d`;let a=i/30;return a<12?`${a.toFixed(1)}mo`:`${(i/365).toFixed(1)}y`}function Zi(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t,n,3.5,0,Math.PI*2),e.fill(),e.fillStyle=`#fff`,e.beginPath(),e.arc(t,n,1.5,0,Math.PI*2),e.fill()}function Qi(e,t,n,r,i,a){e.font=`600 11px ${a.font.family}`;let o=0;for(let t of r){let n=e.measureText(t).width;n>o&&(o=n)}let s=Math.ceil(o)+16,c=r.length*14+12,l=t+8,u=n+8,d=e.canvas.clientWidth||e.canvas.width;l+s>d-4&&(l=t-s-8),l<4&&(l=4),e.fillStyle=a.background,e.globalAlpha=.96,$i(e,l,u,s,c,6),e.fill(),e.globalAlpha=1,e.strokeStyle=i,e.lineWidth=1,$i(e,l+.5,u+.5,s-1,c-1,6),e.stroke(),e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<r.length;t++)e.fillStyle=t===0?i:a.textSecondary,e.fillText(r[t],l+8,u+6+t*14)}function $i(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function ea(e,t){if(e.startsWith(`#`)){let n=0,r=0,i=0;return e.length===4?(n=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16),i=parseInt(e[3]+e[3],16)):e.length>=7&&(n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16)),`rgba(${n},${r},${i},${t})`}if(e.startsWith(`rgb`)){let n=e.match(/[\d.]+/g);if(n&&n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${t})`}return e}var ta={linear:e=>e,easeOutCubic:e=>1-(1-e)**3,easeOutQuart:e=>1-(1-e)**4,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeOutExpo:e=>e===1?1:1-2**(-10*e),easeOutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,spring:e=>1-Math.E**(-6*e)*Math.cos(8*e)},na=class{animations=new Map;frameId=0;running=!1;animate(e,t){this.animations.set(e,{startTime:-1,duration:t.duration,easing:t.easing??ta.easeOutCubic,onUpdate:t.onUpdate,onComplete:t.onComplete}),this.running||(this.running=!0,this.tick())}cancel(e){this.animations.delete(e),this.animations.size===0&&this.stop()}cancelAll(){this.animations.clear(),this.stop()}isAnimating(e){return e?this.animations.has(e):this.animations.size>0}tick(){this.frameId=requestAnimationFrame(e=>{let t=[];for(let[n,r]of this.animations){r.startTime<0&&(r.startTime=e);let i=e-r.startTime,a=Math.min(1,i/r.duration),o=r.easing(a);r.onUpdate(o),a>=1&&(r.onComplete?.(),t.push(n))}for(let e of t)this.animations.delete(e);this.animations.size>0?this.tick():this.running=!1})}stop(){this.frameId&&=(cancelAnimationFrame(this.frameId),0),this.running=!1}dispose(){this.cancelAll()}};function ra(t){return!t||t===`dark`?e.DARK_THEME:t===`light`?e.LIGHT_THEME:t}var ia=class{canvas;ctx;container;theme;width=0;height=0;dpr=1;frameId=null;resizeObserver;constructor(e,t){this.container=e,this.theme=ra(t),this.canvas=document.createElement(`canvas`),this.canvas.style.width=`100%`,this.canvas.style.height=`100%`,this.canvas.style.display=`block`,e.appendChild(this.canvas),this.ctx=this.canvas.getContext(`2d`),this.dpr=window.devicePixelRatio||1,this.updateSize(),this.resizeObserver=new ResizeObserver(()=>{this.updateSize(),this.requestRender()}),this.resizeObserver.observe(e)}updateSize(){this.dpr=window.devicePixelRatio||1;let e=this.container.getBoundingClientRect();this.width=e.width||this.container.clientWidth,this.height=e.height||this.container.clientHeight,this.canvas.width=Math.max(1,Math.floor(this.width*this.dpr)),this.canvas.height=Math.max(1,Math.floor(this.height*this.dpr))}requestRender(){this.frameId===null&&(this.frameId=requestAnimationFrame(()=>{this.frameId=null,(this.width===0||this.height===0)&&this.updateSize(),!(this.width===0||this.height===0)&&(this.ctx.save(),this.ctx.scale(this.dpr,this.dpr),this.ctx.clearRect(0,0,this.width,this.height),this.renderChart(this.ctx,this.width,this.height,this.theme),this.ctx.restore())}))}setTheme(e){this.theme=ra(e),this.requestRender()}destroy(){this.frameId!==null&&cancelAnimationFrame(this.frameId),this.resizeObserver.disconnect(),this.canvas.remove()}},aa=class{pos=null;canvas;onUpdate;handleMove;handleLeave;constructor(e,t){this.canvas=e,this.onUpdate=t,this.handleMove=t=>{let n=e.getBoundingClientRect();this.pos={x:t.clientX-n.left,y:t.clientY-n.top},this.onUpdate()},this.handleLeave=()=>{this.pos=null,this.onUpdate()},e.addEventListener(`pointermove`,this.handleMove),e.addEventListener(`pointerleave`,this.handleLeave)}getPosition(){return this.pos}isActive(){return this.pos!==null}drawCrosshair(e,t,n,r){this.pos&&(e.save(),e.strokeStyle=r,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(this.pos.x,0),e.lineTo(this.pos.x,n),e.stroke(),e.beginPath(),e.moveTo(0,this.pos.y),e.lineTo(t,this.pos.y),e.stroke(),e.restore())}destroy(){this.canvas.removeEventListener(`pointermove`,this.handleMove),this.canvas.removeEventListener(`pointerleave`,this.handleLeave)}};function oa(e,t,n,r,i){let{data:a,mode:o=`area`,lineWidth:s=1.5,showLastPoint:c=!1,showMinMax:l=!1}=r;if(a.length<2||t<=0||n<=0)return;let u=r.color??i.lineColor,d=r.fillColor??u,f=t-4,p=n-4,m=1/0,h=-1/0,g=0,_=0;for(let e=0;e<a.length;e++)a[e]<m&&(m=a[e],g=e),a[e]>h&&(h=a[e],_=e);let v=h-m||1,y=e=>2+e/(a.length-1)*f,b=e=>2+p-(e-m)/v*p;if(o===`area`){let t=e.createLinearGradient(0,2,0,n-2);t.addColorStop(0,d+(d.startsWith(`#`)?`40`:``)),t.addColorStop(1,`transparent`),e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));e.lineTo(y(a.length-1),n-2),e.lineTo(y(0),n-2),e.closePath(),e.fillStyle=t,e.fill()}e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));if(e.strokeStyle=u,e.lineWidth=s,e.lineJoin=`round`,e.stroke(),c){let t=r.lastPointColor??u,n=y(a.length-1),i=b(a[a.length-1]);e.beginPath(),e.arc(n,i,3,0,Math.PI*2),e.fillStyle=t,e.fill()}if(l){let t=r.minPointColor??i.candleDown,n=r.maxPointColor??i.candleUp;e.beginPath(),e.arc(y(g),b(m),2.5,0,Math.PI*2),e.fillStyle=t,e.fill(),e.beginPath(),e.arc(y(_),b(h),2.5,0,Math.PI*2),e.fillStyle=n,e.fill()}}var sa=50,ca=60,la=20,ua=.2;function da(e){let t=[...e].sort((e,t)=>t.price-e.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function fa(e){let t=[...e].sort((e,t)=>e.price-t.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function pa(e,t){return{left:sa,right:e-ca,top:la,bottom:t-la,plotWidth:e-sa-ca,plotHeight:t-la*2}}function ma(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function ha(t,n,r,i,a,o,s,c){let{left:l,right:u,top:d,bottom:f,plotWidth:p,plotHeight:m}=n;t.save(),t.strokeStyle=o.grid,t.lineWidth=.5,t.fillStyle=o.axisLabel,t.font=`${o.font.sizeSmall}px ${o.font.family}`;let h=(0,e.computeTickStep)(0,a,5);for(let e=0;e<=a;e+=h){let n=f-e/a*m;t.beginPath(),t.moveTo(l,n),t.lineTo(u,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),l-4,n)}let g=i-r,_=(0,e.computeTickStep)(r,i,6),v=Math.ceil(r/_)*_;for(let e=v;e<=i;e+=_){let n=l+(e-r)/g*p;t.beginPath(),t.moveTo(n,d),t.lineTo(n,f),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(s(e),n,f+4)}t.restore()}function ga(e,t,n,r,i,a,o,s,c){if(t.length===0)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-e/a*f;if(e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}else{e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}if(e.closePath(),e.fillStyle=o,e.fill(),e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);n>0&&e.lineTo(r,m(t[n-1].cumulativeVolume)),e.lineTo(r,i)}}else{e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=1;n<t.length;n++){let r=m(t[n-1].cumulativeVolume),i=p(t[n].price),a=m(t[n].cumulativeVolume);e.lineTo(i,r),e.lineTo(i,a)}}e.strokeStyle=s,e.lineWidth=1.5,e.stroke()}function _a(e,t,n,r,i,a,o,s,c){let{left:l,top:u,bottom:d,plotWidth:f}=r,p=l+(t-i)/a*f;if(e.save(),e.strokeStyle=o.textSecondary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(p,u),e.lineTo(p,d),e.stroke(),e.restore(),s){let t=`Spread: ${c(n)}`;e.save(),e.font=`${o.font.sizeSmall}px ${o.font.family}`,e.fillStyle=o.textSecondary,e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t,p,u-2),e.restore()}}function va(e,t,n,r,i,a,o,s,c,l,u){let{left:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=i,g=t.x;if(g<d||g>i.right)return;let _=a+(g-d)/m*o,v=0,y=``;if(n.length>0&&_<=n[0].price){y=`Bid`;for(let e of n)if(_<=e.price)v=e.cumulativeVolume;else break}if(r.length>0&&_>=r[0].price){y=`Ask`;for(let e of r)if(_>=e.price)v=e.cumulativeVolume;else break}if(e.save(),e.strokeStyle=c.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(g,f),e.lineTo(g,p),e.stroke(),v>0){let t=p-v/s*h;e.beginPath(),e.moveTo(d,t),e.lineTo(i.right,t),e.stroke()}e.restore();let b=[`Price: ${l(_)}`,y?`${y} Vol: ${u(v)}`:``].filter(Boolean);e.save(),e.font=`${c.font.sizeSmall}px ${c.font.family}`;let x=Math.max(...b.map(t=>e.measureText(t).width))+16,S=b.length*(c.font.sizeSmall+4)+12,C=g+10,w=t.y-S/2;C+x>i.right&&(C=g-x-10),w<f&&(w=f),w+S>p&&(w=p-S),e.fillStyle=c.axisLabelBackground,e.globalAlpha=.9,e.fillRect(C,w,x,S),e.globalAlpha=1,e.fillStyle=c.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<b.length;t++)e.fillText(b[t],C+8,w+6+t*(c.font.sizeSmall+4));e.restore()}function ya(e){return e.toFixed(2)}function ba(e){return e>=1e6?(e/1e6).toFixed(2)+`M`:e>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(0)}function xa(e,t,n,r,i,a){let{data:o}=r;if(o.bids.length===0&&o.asks.length===0||t<=0||n<=0)return;let s=r.bidColor??i.candleUp,c=r.askColor??i.candleDown,l=r.bidFillColor??s+`40`,u=r.askFillColor??c+`40`,d=r.midPriceLine!==!1,f=r.spreadLabel!==!1,p=r.priceFormat??ya,m=r.volumeFormat??ba,h=da(o.bids),g=fa(o.asks),_=h.length>0?h[0].price:0,v=g.length>0?g[0].price:0,y=h.length>0&&g.length>0?(_+v)/2:_||v,b=g.length>0&&h.length>0?v-_:0,x=h.length>0?h[h.length-1].price:y,S=g.length>0?g[g.length-1].price:y,C=Math.max(y-x,S-y)*(1+ua),w=y-C,T=y+C,E=T-w,D=h.length>0?h[h.length-1].cumulativeVolume:0,O=g.length>0?g[g.length-1].cumulativeVolume:0,k=Math.max(D,O)||1,A=pa(t,n);ma(e,t,n,i.background),ha(e,A,w,T,k,i,p,m),ga(e,h,A,w,E,k,l,s,`bid`),ga(e,g,A,w,E,k,u,c,`ask`),d&&_a(e,y,b,A,w,E,i,f,p),a&&va(e,a,h,g,A,w,E,k,i,p,m)}var Sa=70,Ca=30,wa=20,Ta=20,Ea=.05;function Da(e,t){return{left:Sa,right:e-wa,top:Ta,bottom:t-Ca,plotWidth:e-Sa-wa,plotHeight:t-Ta-Ca}}function Oa(e,t){let n=1/0,r=-1/0;for(let t of e)t.value<n&&(n=t.value),t.value>r&&(r=t.value);if(t)for(let e of t)e.value<n&&(n=e.value),e.value>r&&(r=e.value);let i=(r-n)*Ea;return{valMin:n-i,valMax:r+i}}function ka(e){let t=[],n=-1/0;for(let r of e)r.value>n&&(n=r.value),t.push(n);return t}function Aa(e){let t=864e5;if(365.25*t,e<7*t){let e=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`});return t=>e.format(new Date(t))}if(e<315576e5){let e=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`});return t=>e.format(new Date(t))}let n=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});return e=>n.format(new Date(e))}function ja(e){return Math.abs(e)>=1e6?(e/1e6).toFixed(2)+`M`:Math.abs(e)>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function Ma(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Na(t,n,r,i,a,o,s,c,l){let{left:u,right:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=n;t.save(),t.strokeStyle=s.grid,t.lineWidth=.5,t.fillStyle=s.axisLabel,t.font=`${s.font.sizeSmall}px ${s.font.family}`;let g=(0,e.computeTickStep)(r,i,6),_=Math.ceil(r/g)*g;for(let e=_;e<=i;e+=g){let n=p-(e-r)/(i-r)*h;t.beginPath(),t.moveTo(u,n),t.lineTo(d,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),u-6,n)}let v=o-a,y=(0,e.computeTickStep)(a,o,6),b=Math.ceil(a/y)*y;for(let e=b;e<=o;e+=y){let n=u+(e-a)/v*m;t.beginPath(),t.moveTo(n,f),t.lineTo(n,p),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(l(e),n,p+4)}t.restore()}function Pa(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-(e-a)/o*f;e.save(),e.beginPath(),e.moveTo(p(t[0].time),m(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(p(t[n].time),m(t[n].value));e.strokeStyle=s,e.lineWidth=c,e.lineJoin=`round`,e.stroke(),e.restore()}function Fa(e,t,n,r,i,a,o,s){if(t.length<2)return;let{left:c,bottom:l,plotWidth:u,plotHeight:d}=n,f=e=>c+(e-r)/i*u,p=e=>l-(e-a)/o*d,m=e.createLinearGradient(0,n.top,0,l);m.addColorStop(0,s+`40`),m.addColorStop(1,`transparent`),e.save(),e.beginPath(),e.moveTo(f(t[0].time),p(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(f(t[n].time),p(t[n].value));e.lineTo(f(t[t.length-1].time),l),e.lineTo(f(t[0].time),l),e.closePath(),e.fillStyle=m,e.fill(),e.restore()}function Ia(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=r,p=e=>l+(e-i)/a*d,m=e=>u-(e-o)/s*f;e.save(),e.fillStyle=c,e.beginPath(),e.moveTo(p(t[0].time),m(n[0]));for(let r=1;r<t.length;r++)e.lineTo(p(t[r].time),m(n[r]));for(let n=t.length-1;n>=0;n--)e.lineTo(p(t[n].time),m(t[n].value));e.closePath(),e.fill(),e.restore()}function La(e,t,n,r,i,a,o,s,c,l){if(t.length===0)return;let{left:u,bottom:d,plotWidth:f,plotHeight:p}=n,m=t[t.length-1],h=u+(m.time-r)/i*f,g=d-(m.value-a)/o*p;e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`,e.fillStyle=c,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(s,h+4,g),e.restore()}function Ra(e,t,n,r,i,a,o,s,c,l,u,d){let{left:f,top:p,bottom:m,plotWidth:h,plotHeight:g}=i,_=t.x;if(_<f||_>i.right)return;e.save(),e.strokeStyle=l.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(_,p),e.lineTo(_,m),e.stroke(),e.restore();let v=a+(_-f)/h*o,y=0,b=1/0;for(let e=0;e<n.length;e++){let t=Math.abs(n[e].time-v);t<b&&(b=t,y=e)}let x=n[y],S=[u(x.time),`Value: ${d(x.value)}`];r&&r.length>y&&S.push(`Benchmark: ${d(r[y].value)}`);let C=f+(x.time-a)/o*h,w=m-(x.value-s)/c*g;e.beginPath(),e.arc(C,w,3,0,Math.PI*2),e.fillStyle=l.lineColor,e.fill(),e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`;let T=Math.max(...S.map(t=>e.measureText(t).width))+16,E=S.length*(l.font.sizeSmall+4)+12,D=_+10,O=t.y-E/2;D+T>i.right&&(D=_-T-10),O<p&&(O=p),O+E>m&&(O=m-E),e.fillStyle=l.axisLabelBackground,e.globalAlpha=.9,e.fillRect(D,O,T,E),e.globalAlpha=1,e.fillStyle=l.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<S.length;t++)e.fillText(S[t],D+8,O+6+t*(l.font.sizeSmall+4));e.restore()}function za(e,t,n,r,i,a){let{data:o}=r;if(o.length<2||t<=0||n<=0)return;let s=r.lineColor??i.lineColor,c=r.lineWidth??1.5,l=r.drawdown===!0,u=r.drawdownColor??i.candleDown+`30`,d=r.fillArea===!0,f=r.benchmark,p=r.benchmarkColor??i.textSecondary,m=r.benchmarkLabel??`Benchmark`,h=r.valueFormat??ja,{valMin:g,valMax:_}=Oa(o,f),v=_-g||1,y=o[0].time,b=o[o.length-1].time,x=b-y||1,S=r.timeFormat??Aa(x),C=Da(t,n);Ma(e,t,n,i.background),Na(e,C,g,_,y,b,i,h,S),l&&Ia(e,o,ka(o),C,y,x,g,v,u),d&&Fa(e,o,C,y,x,g,v,s),Pa(e,o,C,y,x,g,v,s,c),f&&f.length>=2&&(Pa(e,f,C,y,x,g,v,p,1),La(e,f,C,y,x,g,v,m,p,i)),a&&Ra(e,a,o,f,C,y,x,g,v,i,S,h)}function Ba(e,t,n){if(e.length===0)return[];let r=e.length,i=Math.ceil(Math.sqrt(r)),a=Math.ceil(r/i),o=t.width/i,s=t.height/a,c=[];for(let a=0;a<r;a++){let r=a%i,l=Math.floor(a/i);c.push({id:e[a].id,rect:{x:t.x+r*o+n,y:t.y+l*s+n,width:Math.max(0,o-n*2),height:Math.max(0,s-n*2)}})}return c}function Va(e,t){let n=e.reduce((e,t)=>e+t,0);if(n===0||t===0)return 1/0;let r=0;for(let i of e){let e=n/t,a=i/e,o=e>a?e/a:a/e;o>r&&(r=o)}return r}function Ha(e,t,n,r,i,a){let o=r?n.height:n.width,s=e.reduce((e,t)=>e+t,0),c=o>0?s/o:0,l=0;for(let o=0;o<e.length;o++){let s=c>0?e[o]/c:0,u;u=r?{x:n.x+i,y:n.y+l+i,width:Math.max(0,c-i*2),height:Math.max(0,s-i*2)}:{x:n.x+l+i,y:n.y+i,width:Math.max(0,s-i*2),height:Math.max(0,c-i*2)},a.push({id:t[o],rect:u}),l+=s}}function Ua(e,t,n,r,i){if(e.length===0)return;let a=n.width>=n.height,o=a?n.height:n.width;if(e.length===1){Ha(e,t,n,a,r,i);return}let s=[],c=[],l=0;for(;l<e.length;){let u=[...s,e[l]];if(s.length===0||Va(u,o)<=Va(s,o))s.push(e[l]),c.push(t[l]),l++;else{Ha(s,c,n,a,r,i);let u=s.reduce((e,t)=>e+t,0),d=o>0?u/o:0;n=a?{x:n.x+d,y:n.y,width:n.width-d,height:n.height}:{x:n.x,y:n.y+d,width:n.width,height:n.height-d},Ua(e.slice(l),t.slice(l),n,r,i);return}}s.length>0&&Ha(s,c,n,a,r,i)}function Wa(e,t,n){if(e.length===0)return[];let r=[...e].sort((e,t)=>t.weight-e.weight),i=r.reduce((e,t)=>e+Math.max(0,t.weight),0);if(i===0)return[];let a=t.width*t.height,o=r.map(e=>Math.max(0,e.weight)/i*a),s=r.map(e=>e.id),c=[];return Ua(o,s,{...t},n,c),c}function Ga(e){return(e>=0?`+`:``)+e.toFixed(2)+`%`}function Ka(e){return e.label}function qa(t,n){let r=n.min??-5,i=n.max??5;if(t<=r)return n.negative;if(t>=i)return n.positive;if(t<0){let i=1-t/r;return(0,e.lerpColor)(n.negative,n.zero,i)}let a=t/i;return(0,e.lerpColor)(n.zero,n.positive,a)}function Ja(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function Ya(e,t,n,r,i,a,o,s,c,l,u){if(i<40||a<30)return;let d=n+i/2,f=r+a/2;if(e.save(),e.shadowColor=`rgba(0,0,0,0.6)`,e.shadowBlur=2,e.fillStyle=`#FFFFFF`,e.textAlign=`center`,s){let n=l(t),r=Math.min(o.font.sizeMedium,i/n.length*1.5,a/4);e.font=`bold `+Math.max(8,r)+`px `+o.font.family,e.textBaseline=c?`bottom`:`middle`,e.fillText(n,d,c?f-1:f,i-8)}if(c){let n=u(t.value),r=Math.min(o.font.sizeSmall,i/n.length*1.5,a/4);e.font=Math.max(7,r)+`px `+o.font.family,e.textBaseline=s?`top`:`middle`,e.fillText(n,d,s?f+1:f,i-8)}e.restore()}function Xa(e,t,n,r,i,a,o,s){let c=[o(t),s(t.value)];if(t.meta)for(let[e,n]of Object.entries(t.meta))c.push(e+`: `+String(n));e.save(),e.font=a.font.sizeSmall+`px `+a.font.family;let l=Math.max(...c.map(t=>e.measureText(t).width))+16,u=a.font.sizeSmall+4,d=c.length*u+12,f=n.x+14,p=n.y-d/2;f+l>r&&(f=n.x-l-14),p<0&&(p=0),p+d>i&&(p=i-d),e.fillStyle=a.axisLabelBackground,e.globalAlpha=.92,Ja(e,f,p,l,d,4),e.fill(),e.globalAlpha=1,e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<c.length;t++)e.fillText(c[t],f+8,p+6+t*u);e.restore()}function Za(e,t,n,r,i,a,o,s){if(r.length===0||i.length===0||t<=0||n<=0)return null;let c=a.colorScale??{negative:`#EF5350`,zero:`#424242`,positive:`#26A69A`},l=a.cellRadius??4,u=a.showLabels!==!1,d=a.showValues!==!1,f=a.valueFormat??Ga,p=a.labelFormat??Ka,m=new Map;for(let e of r)m.set(e.id,e);let h=null,g=null;if(s)for(let e of i){let{x:t,y:n,width:r,height:i}=e.rect;if(s.x>=t&&s.x<=t+r&&s.y>=n&&s.y<=n+i){h=e.id;let t=m.get(e.id);t&&(g={cell:t,rect:e});break}}e.fillStyle=o.background,e.fillRect(0,0,t,n);for(let t of i){let n=m.get(t.id);if(!n)continue;let{x:r,y:i,width:a,height:s}=t.rect;if(a<=0||s<=0)continue;let g=qa(n.value,c);Ja(e,r,i,a,s,l),e.fillStyle=g,e.fill(),Ya(e,n,r,i,a,s,o,u,d,p,f),t.id===h&&(Ja(e,r,i,a,s,l),e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.stroke())}return g&&s&&Xa(e,g.cell,s,t,n,o,p,f),g}var Qa=60,$a=12,eo=24,to=40,no=.7,ro=1;function io(e){return e.type?e.type:e.value>0?`positive`:e.value<0?`negative`:`subtotal`}function ao(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function oo(e,t){return{left:Qa,right:e-$a,top:eo,bottom:t-to,plotWidth:e-Qa-$a,plotHeight:t-eo-to}}function so(e,t,n,r,i){let a=Array(e.length),o=Array(e.length),s=t.plotWidth/e.length,c=s*n,l=(s-c)/2,{left:u,bottom:d,plotHeight:f}=t,p=0;for(let t=0;t<e.length;t++){let n=e[t],m=io(n),h,g;m===`total`||m===`subtotal`?(h=0,g=n.value,p=n.value):(h=p,g=p+n.value,p=g);let _=Math.min(h,g),v=Math.max(h,g),y=d-(_-r)/i*f,b=d-(v-r)/i*f,x=Math.min(y,b),S=Math.max(Math.abs(b-y),ro),C=u+t*s,w=C+l;a[t]={label:n.label,value:n.value,start:h,end:g,type:m,rectX:w,rectY:x,rectW:c,rectH:S,slotX:C,slotW:s},o[t]=p}return{bars:a,cumulatives:o}}function co(e){if(e.length===0)return{valMin:0,valMax:1};let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=io(a),s,c;o===`total`||o===`subtotal`?(s=0,c=a.value,r=a.value):(s=r,c=r+a.value,r=c),s<t&&(t=s),c<t&&(t=c),s>n&&(n=s),c>n&&(n=c)}let i=(n-t||1)*.1;return{valMin:t-i,valMax:n+i}}function lo(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function uo(t,n,r,i,a,o){let{left:s,right:c,top:l,bottom:u,plotHeight:d}=n,f=i-r||1;t.strokeStyle=a.grid,t.lineWidth=.5,t.fillStyle=a.axisLabel,t.font=`${a.font.sizeSmall}px ${a.font.family}`,t.textAlign=`right`,t.textBaseline=`middle`;let p=(0,e.computeTickStep)(r,i,5),m=Math.ceil(r/p)*p;t.beginPath();for(let e=m;e<=i;e+=p){let n=Math.round(u-(e-r)/f*d)+.5;n<l||n>u||(t.moveTo(s,n),t.lineTo(c,n))}t.stroke();for(let e=m;e<=i;e+=p){let n=u-(e-r)/f*d;n<l-1||n>u+1||t.fillText(o(e),s-6,n)}if(r<0&&i>0){let e=Math.round(u-(0-r)/f*d)+.5;t.strokeStyle=a.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(s,e),t.lineTo(c,e),t.stroke()}}function fo(e,t,n){let r=[`positive`,`negative`,`total`,`subtotal`];for(let i=0;i<r.length;i++){let a=r[i],o=n[a],s=!1;e.beginPath();for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==a)continue;let i=Math.round(r.rectX),o=Math.round(r.rectY),c=Math.round(r.rectW),l=Math.round(r.rectH);e.rect(i,o,c,l),s=!0}s&&(e.fillStyle=o,e.fill())}}function po(e,t,n,r,i,a,o){if(o===`none`||t.length<2)return;let{bottom:s,plotHeight:c}=n;e.strokeStyle=a,e.lineWidth=1,o===`dashed`?e.setLineDash([4,4]):e.setLineDash([]),e.beginPath();for(let n=0;n<t.length-1;n++){let a=t[n],o=t[n+1],l=a.end,u=Math.round(s-(l-r)/i*c)+.5,d=Math.round(a.rectX+a.rectW),f=Math.round(o.rectX);f<=d||(e.moveTo(d,u),e.lineTo(f,u))}e.stroke(),e.setLineDash([])}function mo(e,t,n,r,i,a){e.fillStyle=r.text,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`;for(let r=0;r<t.length;r++){let o=t[r],s;s=o.type===`total`||o.type===`subtotal`?i(o.value):a?`${o.value>=0?`+`:``}${i(o.value)}`:i(n[r]);let c=o.rectX+o.rectW/2;o.end<o.start?(e.textBaseline=`top`,e.fillText(s,c,o.rectY+o.rectH+4)):(e.textBaseline=`bottom`,e.fillText(s,c,o.rectY-4))}}function ho(e,t,n,r,i){e.fillStyle=r.axisLabel,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`top`;let a=n.bottom+6,o=t.length>0?t[0].slotW-4:0,s=!1;for(let n=0;n<t.length;n++)if(e.measureText(i(t[n].label)).width>o){s=!0;break}if(!s){for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.fillText(i(r.label),o,a)}return}e.save(),e.textAlign=`right`,e.textBaseline=`middle`;for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.setTransform(1,0,0,1,o,a+4),e.rotate(-Math.PI/4),e.fillText(i(r.label),0,0)}e.setTransform(1,0,0,1,0,0),e.restore()}function go(e,t,n){if(t<n.left||t>n.right)return null;for(let n=0;n<e.length;n++){let r=e[n];if(t>=r.slotX&&t<=r.slotX+r.slotW)return n}return null}function _o(e,t,n,r,i,a,o,s){let c=t[r],l=n[r],u=Math.round(c.slotX+c.slotW/2)+.5;e.strokeStyle=o.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(u,a.top),e.lineTo(u,a.bottom),e.stroke(),e.setLineDash([]);let d=[c.label,`Value: ${c.value>=0&&(c.type===`positive`||c.type===`negative`)?`+`:``}${s(c.value)}`,`Total: ${s(l)}`];e.font=`${o.font.sizeSmall}px ${o.font.family}`;let f=0;for(let t=0;t<d.length;t++){let n=e.measureText(d[t]).width;n>f&&(f=n)}let p=f+16,m=d.length*(o.font.sizeSmall+4)+12,h=i.x+10,g=i.y-m/2;h+p>a.right&&(h=i.x-p-10),g<a.top&&(g=a.top),g+m>a.bottom&&(g=a.bottom-m),e.fillStyle=o.axisLabelBackground,e.globalAlpha=.9,e.fillRect(h,g,p,m),e.globalAlpha=1,e.fillStyle=o.text,e.textAlign=`left`,e.textBaseline=`top`;let _=o.font.sizeSmall+4;for(let t=0;t<d.length;t++)e.fillText(d[t],h+8,g+6+t*_)}function vo(e,t,n,r,i,a){let{data:o}=r;if(!o||o.length===0||t<=0||n<=0)return{hitBar:null};let s=r.positiveColor??i.candleUp,c=r.negativeColor??i.candleDown,l=r.totalColor??i.lineColor,u=r.subtotalColor??i.textSecondary,d=r.connectorColor??i.textSecondary,f=r.connectorStyle??`dashed`,p=r.barWidth??no,m=r.showValues!==!1,h=r.showDelta!==!1,g=r.valueFormat??ao,_=r.labelFormat??(e=>e),{valMin:v,valMax:y}=co(o),b=y-v||1,x=oo(t,n),{bars:S,cumulatives:C}=so(o,x,p,v,b);lo(e,t,n,i.background),uo(e,x,v,y,i,g),po(e,S,x,v,b,d,f),fo(e,S,{positive:s,negative:c,total:l,subtotal:u}),m&&mo(e,S,C,i,g,h),ho(e,S,x,i,_);let w=a?go(S,a.x,x):null;return a&&w!==null&&_o(e,S,C,w,a,x,i,g),{hitBar:w}}var yo=Math.PI/180,bo=135,xo=405,So=.25;function Co(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:Number.isInteger(e)?e.toFixed(0):e.toFixed(1)}function Q(e,t,n){return e<t?t:e>n?n:e}function wo(e,t,n){let r=n.min??0,i=n.max??100,a=i-r||1,o=(n.startAngle??bo)*yo,s=(n.endAngle??xo)*yo,c=n.thickness??So,l=e/2,u=t/2+t*.05,d=Math.max(10,Math.min(e,t)/2-24);return{cx:l,cy:u,radius:d,innerRadius:Math.max(2,d*(1-c)),startAngle:o,endAngle:s,angleRange:s-o,min:r,max:i,range:a}}function $(e,t){let n=Q((e-t.min)/t.range,0,1);return t.startAngle+t.angleRange*n}function To(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Eo(e,t,n){e.beginPath(),e.arc(t.cx,t.cy,t.radius,t.startAngle,t.endAngle,!1),e.arc(t.cx,t.cy,t.innerRadius,t.endAngle,t.startAngle,!0),e.closePath(),e.fillStyle=n,e.fill()}function Do(e,t,n){let r=Q(n.from,t.min,t.max),i=Q(n.to,t.min,t.max);if(i<=r)return;let a=$(r,t),o=$(i,t);e.beginPath(),e.arc(t.cx,t.cy,t.radius,a,o,!1),e.arc(t.cx,t.cy,t.innerRadius,o,a,!0),e.closePath(),e.fillStyle=n.color,e.fill()}function Oo(e,t,n,r,i){let a=$(n,t);a<=t.startAngle||(e.globalAlpha=i,e.beginPath(),e.arc(t.cx,t.cy,t.radius,t.startAngle,a,!1),e.arc(t.cx,t.cy,t.innerRadius,a,t.startAngle,!0),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1)}function ko(e,t,n,r){let i=$(n,t),a=Math.cos(i),o=Math.sin(i),s=t.radius-2,c=t.innerRadius*.25,l=-o,u=a,d=t.cx+a*s,f=t.cy+o*s,p=t.cx+l*4-a*c,m=t.cy+u*4-o*c,h=t.cx-l*4-a*c,g=t.cy-u*4-o*c;e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.lineTo(h,g),e.closePath(),e.fillStyle=r,e.fill(),e.beginPath(),e.arc(t.cx,t.cy,Math.max(4,t.innerRadius*.12),0,Math.PI*2),e.fill()}function Ao(e,t,n,r,i){let a=Math.round(t.innerRadius*.55),o=Math.round(i.font.sizeMedium);e.fillStyle=i.text,e.textAlign=`center`,e.textBaseline=`middle`,e.font=`600 ${a}px ${i.font.family}`;let s=!!r,c=s?t.cy-o*.6:t.cy-a*.1;e.fillText(n,t.cx,c),s&&(e.fillStyle=i.textSecondary,e.font=`${o}px ${i.font.family}`,e.fillText(r,t.cx,t.cy+a*.55))}function jo(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`;let i=t.radius+10,a=Math.cos(t.startAngle),o=Math.sin(t.startAngle),s=Math.cos(t.endAngle),c=Math.sin(t.endAngle),l=t.cx+a*i,u=t.cy+o*i,d=t.cx+s*i,f=t.cy+c*i;e.textBaseline=`middle`,e.textAlign=a<-.2?`right`:a>.2?`left`:`center`,e.fillText(n(t.min),l,u),e.textAlign=s<-.2?`right`:s>.2?`left`:`center`,e.fillText(n(t.max),d,f)}function Mo(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`middle`;let i=(t.radius+t.innerRadius)/2;for(let r=0;r<n.length;r++){let a=n[r];if(!a.label)continue;let o=$((Q(a.from,t.min,t.max)+Q(a.to,t.min,t.max))/2,t),s=t.cx+Math.cos(o)*i,c=t.cy+Math.sin(o)*i;e.fillText(a.label,s,c)}}function No(e,t,n,r,i,a){if(t<=0||n<=0)return;let o=wo(t,n,r),s=r.trackColor??i.grid,c=r.needleColor??i.text,l=r.showValue!==!1,u=r.showZoneLabels===!0,d=r.valueFormat??Co,f=Q(a,o.min,o.max);To(e,t,n,i.background),Eo(e,o,s);let p=r.zones;if(p&&p.length>0)for(let t=0;t<p.length;t++)Do(e,o,p[t]);Oo(e,o,f,c,.12),ko(e,o,f,c),l&&Ao(e,o,d(f),r.label,i),jo(e,o,d,i),u&&p&&p.length>0&&Mo(e,o,p,i)}exports.ADXIndicator=ct,exports.ATRIndicator=st,exports.AcceleratorOscillatorIndicator=Jt,exports.AccumulationDistributionIndicator=nn,exports.AlertDragHandler=gn,exports.AlertManager=Mi,exports.AlligatorIndicator=et,exports.AnchoredVWAPIndicator=Ge,exports.AnchoredVWAPTool=sr,exports.Animator=na,exports.AreaRenderer=x,exports.AroonIndicator=pt,exports.ArrowTool=nr,exports.AwesomeOscillatorIndicator=nt,exports.AxisDragHandler=hn,exports.BalanceOfPowerIndicator=Nt,exports.BarCountdown=bi,exports.BarRenderer=S,exports.BaseFinanceChart=ia,exports.BaselineRenderer=w,exports.BinanceAdapter=Kr,exports.BollingerBandsIndicator=Ie,exports.BracketTool=Tr,exports.BybitAdapter=ii,exports.CCIIndicator=dt,exports.CMFIndicator=gt,exports.CandlestickRenderer=g,exports.CanvasLayer=t,exports.ChaikinOscillatorIndicator=rt,exports.ChaikinVolatilityIndicator=Vt,exports.ChandeMomentumIndicator=Ft,exports.ChandelierExitIndicator=$e,exports.ChartLegend=_i,exports.ChartStateManager=Bi,exports.ChoppinessIndexIndicator=yt,exports.CoinbaseAdapter=Qr,exports.CompareRenderer=we,exports.ConnorsRSIIndicator=Ct,exports.CoppockIndicator=Tt,exports.CrosshairHandler=yn,exports.CrosshairTooltip=Cn,exports.CurrentPriceLine=zr,exports.DEFAULT_LEGEND_CONFIG=gi,exports.DEFAULT_SESSION_HOURS=ki,exports.DPRManager=i,exports.DataExporter=Hi,exports.DateRangeTool=Qn,exports.DepthHeatmapBuffer=xe,exports.DepthHeatmapRenderer=Se,exports.DepthOverlay=yr,exports.DetrendedPriceOscillatorIndicator=Mt,exports.DisparityIndexIndicator=Zt,exports.DonchianChannelIndicator=He,exports.DrawingBase=z,exports.DrawingManager=Mn,exports.DrawingRenderer=Nn,exports.EMAIndicator=Fe,exports.EaseOfMovementIndicator=Lt,exports.Easing=ta,exports.ElderRayIndicator=Dt,exports.ElliottWaveTool=Xn,exports.EllipseTool=Kn,exports.Emitter=H,exports.EquivolumeRenderer=k,exports.EventBus=An,exports.ExtendedLineTool=zn,exports.FibExtensionTool=Wn,exports.FibRetracementTool=Hn,exports.FibTimeZonesTool=ur,exports.FinanceCrosshair=aa,exports.FisherTransformIndicator=jt,exports.ForceIndexIndicator=St,exports.GannBoxTool=or,exports.GannFanTool=ir,exports.GridRenderer=cn,exports.HLCAreaRenderer=ee,exports.HollowCandleRenderer=C,exports.HorizontalLineTool=In,exports.HullMAIndicator=Je,exports.IchimokuIndicator=Re,exports.IndicatorBase=j,exports.IndicatorEngine=Ne,exports.IndicatorWorkerHost=sn,exports.InteractionManager=fn,exports.KSTIndicator=Et,exports.KagiRenderer=E,exports.KeltnerChannelIndicator=Ve,exports.KeyboardHandler=Sn,exports.KlingerIndicator=At,exports.KrakenAdapter=di,exports.LayerManager=n,exports.LineRenderer=b,exports.LineWithMarkersRenderer=ne,exports.LinearRegressionChannelIndicator=qe,exports.MACDIndicator=at,exports.MFIIndicator=ft,exports.MTFMovingAverageIndicator=Ze,exports.MarketProfileRenderer=ue,exports.MassIndexIndicator=Pt,exports.MeasureOverlay=qi,exports.MeasureTool=$n,exports.MockAdapter=qr,exports.OBVIndicator=lt,exports.OrderDraftTool=jr,exports.OrderRenderer=fr,exports.PanHandler=pn,exports.PaneResizeHandler=_n,exports.PaperExecutionAdapter=Ir,exports.ParabolicSARIndicator=ze,exports.ParallelChannelTool=Bn,exports.PercentagePriceOscillatorIndicator=Kt,exports.PeriodLevelsRenderer=he,exports.PinnedTooltip=En,exports.PitchforkTool=Jn,exports.PivotMarkersRenderer=ye,exports.PivotPointsIndicator=We,exports.PointAndFigureRenderer=D,exports.PollingAdapter=Yr,exports.PositionRenderer=vr,exports.PrettyGoodOscillatorIndicator=$t,exports.PriceAxis=ln,exports.PriceRangeTool=Zn,exports.PriceVolumeTrendIndicator=Bt,exports.QstickIndicator=Qt,exports.ROCIndicator=mt,exports.RSIIndicator=it,exports.RayTool=Rn,exports.ReconnectManager=U,exports.RectangleTool=Gn,exports.RegressionChannelTool=Vn,exports.RelativeMomentumIndexIndicator=Xt,exports.RelativeVigorIndicator=Ht,exports.RenderEngine=p,exports.RenderLoop=r,exports.RenkoRenderer=T,exports.ReplayController=Vr,exports.ReplayManager=Ni,exports.SMAIndicator=Pe,exports.SchaffTrendCycleIndicator=Ot,exports.Screenshot=vi,exports.SessionBreaks=xi,exports.SessionShading=Ai,exports.SessionVWAPIndicator=Qe,exports.SignalMarkerManager=Wi,exports.StdDevIndicator=en,exports.StepLineRenderer=te,exports.StochasticIndicator=ot,exports.StochasticRSIIndicator=Ut,exports.StreamManager=Br,exports.SupertrendIndicator=Be,exports.TRIXIndicator=It,exports.TSIIndicator=ht,exports.TextAnnotationTool=tr,exports.TickAggregator=Rr,exports.TimeAxis=dn,exports.TradeZoneManager=Ki,exports.TradingContextMenu=xr,exports.TradingDragHandler=br,exports.TradingManager=Pr,exports.TradingRenderer=Fr,exports.TrendLineTool=Fn,exports.TriangleTool=qn,exports.UltimateOscillatorIndicator=bt,exports.UndoRedoManager=Vi,exports.VROCIndicator=rn,exports.VWAPIndicator=Le,exports.VerticalLineTool=Ln,exports.Viewport=m,exports.VolumeCandleRenderer=O,exports.VolumeDeltaIndicator=_t,exports.VolumeProfileIndicator=tn,exports.VolumeProfileRangeTool=cr,exports.VolumeProfileRenderer=ie,exports.VolumeRenderer=re,exports.VortexIndicator=vt,exports.Watermark=yi,exports.WebSocketAdapter=Jr,exports.WilliamsADIndicator=Rt,exports.WilliamsRIndicator=ut,exports.ZigZagIndicator=Ke,exports.ZoomHandler=mn,exports.assignSessionLetters=ce,exports.barIndexToX=a,exports.bracketRiskReward=Cr,exports.classifyPivots=_e,exports.computeBracketDefaults=Sr,exports.computeMarketProfile=oe,exports.computePeriodLevels=me,exports.computeSessionProfiles=le,exports.findDominantSwing=Pn,exports.findPivots=ve,exports.getIntParam=N,exports.getNumberParam=M,exports.getVisibleData=h,exports.inferOrderType=kr,exports.isInWindow=Di,exports.isRegularSession=Oi,exports.isWorkerResponse=on,exports.layoutSquarifiedTreemap=Wa,exports.layoutUniformGrid=Ba,exports.lttbDownsample=_,exports.lttbVisibleIndices=y,exports.minuteOfDay=Ei,exports.priceToY=o,exports.registerBuiltInDrawingTools=dr,exports.registerBuiltInIndicators=an,exports.renderDepthChart=xa,exports.renderEquityCurve=za,exports.renderGauge=No,exports.renderHeatmap=Za,exports.renderSparkline=oa,exports.renderWaterfall=vo,exports.resolveBarIndex=u,exports.timeToX=d,exports.timestampToBarIndex=l,exports.toHeikinAshi=Te,exports.toKagi=ke,exports.toLineBreak=Oe,exports.toPointAndFigure=Ae,exports.toRangeBars=je,exports.toRenko=Ee,exports.tpoLetter=se,exports.xToBarIndex=s,exports.xToTime=f,exports.yToPrice=c;
26
26
  //# sourceMappingURL=index.cjs.map