@luxalgo/vela 0.7.1 → 0.7.3

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.
@@ -1028,5 +1028,5 @@ ${Sr(".vela-sd-pane")}
1028
1028
  [data-layout='mobile'] .vela-attribution .vela-attr-wordmark svg { height: 21px; }
1029
1029
  [data-vela-layout='mobile'] .vela-attribution:hover .vela-attr-wordmark,
1030
1030
  [data-layout='mobile'] .vela-attribution:hover .vela-attr-wordmark { transform: translateX(0); }
1031
- `;function qP(r){let e=r.getElementById(gx);e||(e=r.createElement("style"),e.id=gx,r.head.appendChild(e)),e.textContent=jP;}function np(r){return lt(r)?"#ffffff":"#000000"}function rp(r,e){let t=lt(e);r.style.color=t?"#ffffff":"#000000",r.style.setProperty("--vela-attr-shadow",t?"rgba(0,0,0,0.45)":"rgba(255,255,255,0.55)");}function bx(r,e,t){let n=r.createElement("div");return n.className="vela-attribution-custom",Object.assign(n.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",display:"flex",alignItems:"center",lineHeight:"1"}),n.style.color=np(t),n.innerHTML=e,n.dataset.velaScreenshot="1",n}function vx(r,e){qP(r);let t=r.createElement("a");t.className="vela-attribution",t.href=XP,t.target="_blank",t.rel="noopener",t.title="Charting by Vela",t.setAttribute("aria-label","Charting by Vela"),Object.assign(t.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",cursor:"pointer"}),rp(t,e),t.dataset.velaScreenshot="1";let n=r.createElement("span");n.className="vela-attr-symbol",n.setAttribute("aria-hidden","true"),n.innerHTML=mx;let i=r.createElement("span");return i.className="vela-attr-wordmark",i.innerHTML=fx,t.append(n,i),t}function iu(r){if(!r||r==="transparent")return false;let e=/rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*,\s*([\d.]+)\s*\)/.exec(r);return e?parseFloat(e[1])>.001:true}function yx(r,e,t){let n=r.borderTopLeftRadius,i=parseFloat(n)||0,o=n.endsWith("%")?i/100*Math.min(e,t):i;return Math.max(0,Math.min(o,Math.min(e,t)/2))}function ip(r,e,t,n,i,o){r.beginPath(),o>0&&typeof r.roundRect=="function"?r.roundRect(e,t,n,i,o):r.rect(e,t,n,i);}function ZP(r){try{let e=r.ownerDocument.createElement("canvas");e.width=1,e.height=1;let t=e.getContext("2d");return t?(t.drawImage(r,0,0,1,1),e.toDataURL(),!0):!1}catch{return false}}function ou(r,e,t){let n=e.ownerDocument.defaultView;if(!n)return;r.save(),r.scale(t.dpr,t.dpr);let i=(c,u,d)=>{let h=c.textContent?.replace(/\s+/g," ").trim();if(!h)return;let p=c.ownerDocument.createRange();p.selectNodeContents(c);let m=p.getBoundingClientRect();m.width<=0||m.height<=0||(r.globalAlpha=d,r.fillStyle=u.color,r.font=`${u.fontStyle} ${u.fontWeight} ${u.fontSize} ${u.fontFamily}`,r.textBaseline="middle",r.textAlign="left",r.fillText(h,m.left-t.left,m.top-t.top+m.height/2));},o=(c,u,d)=>{if(!c.complete||c.naturalWidth<=0||!ZP(c))return;let h=c.getBoundingClientRect();if(h.width<=0||h.height<=0)return;let p=h.left-t.left,m=h.top-t.top;r.save(),r.globalAlpha=d,ip(r,p,m,h.width,h.height,yx(u,h.width,h.height)),r.clip(),r.drawImage(c,p,m,h.width,h.height),r.restore();},s=(c,u)=>{for(let d of c.children){if(d.hasAttribute("transform"))continue;let h=d.tagName.toLowerCase();if(h==="g"){s(d,u);continue}let p=b=>parseFloat(d.getAttribute(b)??"0")||0,m=null;if(h==="path"){let b=d.getAttribute("d");b&&(m=new Path2D(b));}else if(h==="circle")m=new Path2D,m.arc(p("cx"),p("cy"),p("r"),0,Math.PI*2);else if(h==="ellipse")m=new Path2D,m.ellipse(p("cx"),p("cy"),p("rx"),p("ry"),0,0,Math.PI*2);else if(h==="rect")m=new Path2D,m.rect(p("x"),p("y"),p("width"),p("height"));else if(h==="line")m=new Path2D,m.moveTo(p("x1"),p("y1")),m.lineTo(p("x2"),p("y2"));else if(h==="polyline"||h==="polygon"){let b=(d.getAttribute("points")??"").trim().split(/[\s,]+/).map(Number);if(b.length<4||b.some(Number.isNaN))continue;m=new Path2D,m.moveTo(b[0],b[1]);for(let y=2;y+1<b.length;y+=2)m.lineTo(b[y],b[y+1]);h==="polygon"&&m.closePath();}if(!m)continue;let f=n.getComputedStyle(d);f.fill&&f.fill!=="none"&&iu(f.fill)&&(r.globalAlpha=u*(parseFloat(f.fillOpacity)||1),r.fillStyle=f.fill,r.fill(m));let g=parseFloat(f.strokeWidth)||0;f.stroke&&f.stroke!=="none"&&iu(f.stroke)&&g>0&&(r.globalAlpha=u*(parseFloat(f.strokeOpacity)||1),r.strokeStyle=f.stroke,r.lineWidth=g,(f.strokeLinecap==="round"||f.strokeLinecap==="square"||f.strokeLinecap==="butt")&&(r.lineCap=f.strokeLinecap),(f.strokeLinejoin==="round"||f.strokeLinejoin==="bevel"||f.strokeLinejoin==="miter")&&(r.lineJoin=f.strokeLinejoin),r.stroke(m));}},a=(c,u)=>{let d=c.getBoundingClientRect();if(d.width<=0||d.height<=0)return;let h=n.getComputedStyle(c);if(h.display==="none"||h.visibility==="hidden")return;let p=u*(parseFloat(h.opacity)||1);if(p<=.001)return;let m=c.viewBox.baseVal,f=m&&m.width>0?m.width:d.width,g=m&&m.height>0?m.height:d.height;r.save(),r.translate(d.left-t.left,d.top-t.top),r.scale(d.width/f,d.height/g),m&&r.translate(-m.x,-m.y),s(c,p),r.restore();},l=(c,u)=>{let d=n.getComputedStyle(c);if(d.display==="none"||d.visibility==="hidden")return;let h=u*(parseFloat(d.opacity)||1);if(h<=.001)return;let p=c.getBoundingClientRect();if(p.width>0&&p.height>0){let m=p.left-t.left,f=p.top-t.top,g=yx(d,p.width,p.height);iu(d.backgroundColor)&&(r.globalAlpha=h,r.fillStyle=d.backgroundColor,ip(r,m,f,p.width,p.height,g),r.fill());let b=parseFloat(d.borderTopWidth)||0;b>0&&d.borderTopStyle!=="none"&&iu(d.borderTopColor)&&(r.globalAlpha=h,r.strokeStyle=d.borderTopColor,r.lineWidth=b,ip(r,m+b/2,f+b/2,p.width-b,p.height-b,Math.max(0,g-b/2)),r.stroke());}for(let m of c.childNodes)m.nodeType===3?i(m,d,h):m instanceof n.HTMLImageElement?o(m,n.getComputedStyle(m),h):m instanceof n.SVGSVGElement?a(m,h):m instanceof n.HTMLElement&&l(m,h);};e instanceof n.HTMLElement&&l(e,1),r.restore();}function wx(r,e,t,n,i){let o=Math.max(0,e),s=Math.min(r.length-1,t);if(o>s)return null;let a=1/0,l=-1/0;for(let v=o;v<=s;v+=1){let S=r[v];S.volume!=null&&S.volume>0&&(S.low<a&&(a=S.low),S.high>l&&(l=S.high));}if(!Number.isFinite(a))return null;let c=l>a?Math.max(1,Math.round(n)):1,u=l>a?(l-a)/c:1,d=Array.from({length:c},(v,S)=>({price:a+S*u,up:0,down:0}));for(let v=o;v<=s;v+=1){let S=r[v],E=S.volume;if(!(E!=null&&E>0))continue;let T=S.close>=S.open?"up":"down",k=S.high-S.low;if(k<=0){let w=op(Math.floor((S.low-a)/u),c);d[w][T]+=E;continue}let x=op(Math.floor((S.low-a)/u),c),L=op(Math.floor((S.high-a)/u-1e-9),c);for(let w=x;w<=L;w+=1){let M=a+w*u,P=Math.min(S.high,M+u)-Math.max(S.low,M);P>0&&(d[w][T]+=E*P/k);}}let h=0,p=0,m=0;for(let v=0;v<c;v+=1){let S=d[v].up+d[v].down;h+=S,S>p&&(p=S,m=v);}if(p<=0)return null;let f=h*Math.min(1,Math.max(0,i)),g=m,b=m,y=p;for(;y<f&&(g>0||b<c-1);){let v=g>0?d[g-1].up+d[g-1].down:-1,S=b<c-1?d[b+1].up+d[b+1].down:-1;S>v?(b+=1,y+=S):(g-=1,y+=v);}return {rows:d,rowH:u,min:a,maxTotal:p,poc:m,vaFrom:g,vaTo:b}}function op(r,e){return r<0?0:r>=e?e-1:r}function xx(r,e,t,n){let{rows:i,rowH:o,maxTotal:s,poc:a,vaFrom:l,vaTo:c}=e,{rightX:u,maxW:d,yOf:h}=t;if(!(s<=0||d<=0)){for(let p=0;p<i.length;p+=1){let m=i[p],f=m.up+m.down;if(f<=0)continue;let g=h(m.price+o),b=Math.max(1,h(m.price)-g-1),y=f/s*d,v=m.up/f*y;r.globalAlpha=p>=l&&p<=c?.62:.28,v>0&&(r.fillStyle=n.upColor,r.fillRect(u-y,g,v,b)),y-v>0&&(r.fillStyle=n.downColor,r.fillRect(u-y+v,g,y-v,b));}if(n.showPoc){let p=i[a],m=h(p.price+o),f=Math.max(1,h(p.price)-m-1);r.globalAlpha=.9,r.strokeStyle=n.pocColor,r.lineWidth=1,r.strokeRect(u-d+.5,m+.5,d-1,f);}r.globalAlpha=1;}}var su=class{constructor(){this.canvas=null;this.ctx=null;this.memoKey="";this.memo=null;}mount(e){this.canvas=e,this.ctx=e.getContext("2d");}destroy(){this.canvas=null,this.ctx=null,this.memoKey="",this.memo=null;}render(e){let t=this.ctx,n=this.canvas;if(!t||!n)return;let{bars:i,data:o,visible:s,coords:a,scale:l,bounds:c,theme:u}=e,d=a.dpr;if(t.setTransform(d,0,0,d,0,0),t.clearRect(0,0,n.width/d,n.height/d),!o||!s||i.length===0||c.height<=0)return;let h=a.visibleLogicalRange(),p=Math.max(0,Math.floor(h.from)),m=Math.min(i.length-1,Math.ceil(h.to));if(p>m)return;let f=i[m],g=`${p}:${m}:${i.length}:${f.high}:${f.low}:${f.close}:${f.volume??0}:${o.rows}:${o.valueAreaFrac}`;g!==this.memoKey&&(this.memoKey=g,this.memo=wx(i,p,m,o.rows,o.valueAreaFrac));let b=this.memo;b&&(t.save(),t.beginPath(),t.rect(0,c.top,a.width,c.height),t.clip(),xx(t,b,{rightX:a.width,maxW:a.width*o.widthFrac,yOf:y=>a.priceToY(y,l,c)},{upColor:o.upColor,downColor:o.downColor,showPoc:o.showPoc,pocColor:u.textColor}),t.restore());}};var He="price",nI=8,rI="rgba(0,0,0,0)",au=64,iI=56,Lx=26,Hi=22,ks=26,sp=24,oI=5,sI="0 2px 8px rgba(0,0,0,0.4)",aI=12,Dx=12,Mx=au+Dx,ap=Hi+14,lI=120,cI=2,Px=6,Ix=350,uI=.02,dI=220;function lp(){return typeof performance<"u"?performance.now():Date.now()}var hI=.004,pI=.2,mI=4,Es=class{constructor(e){this.capabilities=yy;this.surfaceBackground=Yt.background;this.surfaceTextColor=Yt.textColor;this.toolbarGutter=0;this.mountContainer=null;this.userDrawings=null;this.backdropRenderer=new nu;this.volumeRenderer=new ru;this.extLayers=[];this.layerOrderSig="";this.attributionEl=null;this.attributionEnabled=true;this.attributionHtml=null;this.vpvrRenderer=new su;this.resizeObserver=null;this.dprMedia=null;this.plotDeviceSize=null;this.coords=new xc;this.scene=new Mc;this.backendMode="auto";this.glowAmount=0;this.chrome=new Vc;this.indicatorSlices=new Qc;this.labelTooltip=null;this.markPopover=null;this.marksExpandedBy="hover";this.markPulseRaf=null;this.markClickCbs=new Set;this.crosshairLayer=new Bc;this.hostClock=null;this.ownClock=null;this.countdownUnsub=null;this.symbolPicker=null;this.indicatorTitlesOn=true;this.indicatorValuesOn=true;this.legendActionsProvider=null;this.legendCalloutsProvider=null;this.legendOverviewAction=null;this.keyboard=null;this.keyboardEnabled=true;this.historyChordsEnabled=true;this.liveRegion=null;this.animZoom=new Yn(70);this.animPan=new Yn(110);this.animScroll=new Yn(130);this.animAutoscale=new Yn(80);this.animLiveBar=new Yn(90,0);this.candleUp=z;this.candleDown=W;this.intro={style:"settle",duration:650};this.introOnStyle="settle";this.introPlayed=false;this.introRaf=null;this.loadingEl=null;this.modelAlpha=1;this.targetBarSpacing=0;this.zoomAnchorLogical=0;this.zoomAnchorX=0;this.zoomAnchorMode="right";this.panVelocity=0;this.bars=[];this.didInitialFit=false;this.paintedData=false;this.skeletonClockMs=0;this.candleBodyAlpha=1;this.candleStructureAlpha=1;this.lastPointer=null;this.volumeActive=false;this.volumeHidden=false;this.vpvrActive=false;this.vpvrHidden=false;this.liveEaseTime=0;this.liveEaseHigh=0;this.liveEaseLow=0;this.liveEaseClose=0;this.axisDragEnabled=true;this.scaleDragHolder=null;this.scaleDragHeight=0;this.scaleDragStart=null;this.paneResizeEnabled=true;this.resizeAbove=null;this.resizeBelow=null;this.resizeSplitStart=null;this.hoverSeparatorY=null;this.maximizedPaneId=null;this.rightAxisW=au;this.paneControls=null;this.axisScaleButtons=null;this.paneActionCbs=new Set;this.hoverLogical=null;this.settingsDialog=null;this.hiddenSettings=[];this.dialogHost=null;this.settingsButton=null;this.settingsEnabled=false;this.scrollButton=null;this.pointerNearScrollBtn=false;this.scrollTargetRO=null;this.scrollBtnBottomPx=ap;this.scrollBtnRightPx=Mx;this.layoutMode="desktop";this.viewportCbs=new Set;this.crosshairCbs=new Set;this.chartTypeSettingsCbs=new Set;this.configChangedCbs=new Set;this.themeSelectCbs=new Set;this.factoryConfig=null;this.hostSettingsSections=[];this.clickCbs=new Set;this.axisLongPressCbs=new Set;this.inputChangeCbs=new Set;this.removeIndicatorCbs=new Set;this.toggleVisibleCbs=new Set;this.moveIndicatorCbs=new Set;this.priceStyleCbs=new Set;this.name="native";this.features=["logScale","currentPriceLine","priceLabel","countdown","upColor","downColor","glow","animZoom","animPan","animScroll","animAutoscale","animLiveBar","intro","zoomAnchor","axisDrag","paneResize","candleZOrder","candleVisible","seriesOrder","highlights","sessionZones","gridlines","axisLabels","scaleMode","invertScale","paneScales","autoScale","timezone","keyboard","historyChords","priceStyle","priceBaseline","baselinePrice","settings","attribution","dialogHost","tradeMarkers","marks","indicatorTitles","indicatorValues"];this.onScrollProximityMove=e=>{if(!this.scrollButton||!this.plot)return;let t=this.plot.getBoundingClientRect(),n=t.width-this.scrollBtnRightPx-ks/2,i=t.height-this.scrollBtnBottomPx-ks/2,o=Math.hypot(e.clientX-t.left-n,e.clientY-t.top-i)<=lI;o!==this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=o,this.updateScrollToRealtimeButton());};this.onScrollProximityLeave=()=>{this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=false,this.updateScrollToRealtimeButton());};this.onDprChange=()=>{this.watchDpr(),this.resize();};this.externalCross=null;this.snapMode="off";e&&(this.scene.showPriceLine=e.currentPriceLine,this.scene.logScale=e.logScale,this.backendMode=e.nativeBackend,this.animZoom.set(e.animZoom),this.animPan.set(e.animPan),this.animScroll.set(e.animScroll),this.animAutoscale.set(e.animAutoscale),this.animLiveBar.set(e.animLiveBar),this.setIntro(e.animIntro),this.glowAmount=e.glow,this.candleUp=e.upColor,this.candleDown=e.downColor,this.scene.priceStyle=e.priceStyle,this.scene.basePainting=hh(e.priceStyle),this.scene.candleOverride=bc(e.priceStyle,this.scene.style.chartTypes)),this.theme=this.deriveTheme(Yt);}applyFeature(e,t){switch(e){case "logScale":if(t&&typeof t=="object"){let n=t;this.setPaneLog(n.pane??He,!!n.value);return}this.scene.logScale=!!t;break;case "currentPriceLine":this.scene.showPriceLine=!!t;break;case "priceLabel":this.scene.showPriceLabel=!!t;break;case "countdown":this.scene.showCountdown=!!t,this.syncCountdownTimer();break;case "upColor":this.candleUp=String(t),this.theme&&(this.theme=this.deriveTheme(this.theme));break;case "downColor":this.candleDown=String(t),this.theme&&(this.theme=this.deriveTheme(this.theme));break;case "glow":this.glowAmount=Number(t)||0,this.backend&&"glow"in this.backend&&(this.backend.glow=this.glowAmount);break;case "animZoom":this.animZoom.set(_t(t,70));return;case "animPan":{let n=_t(t,110);this.animPan.set(n),this.animScroll.toggle(n>0);return}case "animScroll":this.animScroll.set(_t(t,130));return;case "animAutoscale":this.animAutoscale.set(_t(t,80));return;case "animLiveBar":this.animLiveBar.set(Cu(t));return;case "intro":{this.setIntro(Tu(t)),this.intro.style&&this.playIntro();return}case "zoomAnchor":this.zoomAnchorMode=t==="right"?"right":"cursor",this.input&&(this.input.rightEdgeZoom=this.zoomAnchorMode==="right");return;case "axisDrag":this.axisDragEnabled=!!t,this.input&&(this.input.axisDrag=this.axisDragEnabled);return;case "paneResize":this.paneResizeEnabled=!!t,this.input&&(this.input.paneResize=this.paneResizeEnabled);return;case "candleZOrder":this.scene.candleZ=Number(t)||0;break;case "candleVisible":this.scene.candlesHidden=t===false;break;case "seriesOrder":this.applySeriesOrder(t);break;case "highlights":this.scene.highlights=vI(t);break;case "sessionZones":this.scene.sessionZones=yI(t);break;case "gridlines":this.scene.showGrid=!!t;break;case "axisLabels":this.scene.showAxisLabels=!!t;break;case "scaleMode":if(t&&typeof t=="object"){let n=t;this.setPaneScaleMode(n.pane??He,Ax(n.mode));return}this.scene.scaleMode=Ax(t);break;case "invertScale":if(t&&typeof t=="object"){let n=t;this.setPaneInvert(n.pane??He,!!n.value);return}this.scene.invertScale=!!t;break;case "autoScale":for(let n of this.scene.panes.values())n.manualScale=t?null:{...n.scale};break;case "timezone":this.scene.timezone=typeof t=="string"&&t?t:"UTC";break;case "priceStyle":this.setPriceStyle(wI(t)?t:"candles");break;case "priceBaseline":this.scene.baselineValue=t==null?null:Number(t);break;case "tradeMarkers":this.scene.tradeMarkers=Wy(this.scene.tradeMarkers,t);break;case "marks":this.scene.marks=qy(this.scene.marks,t),this.markPopover?.close();break;case "keyboard":this.setKeyboardEnabled(!!t);return;case "historyChords":this.historyChordsEnabled=!!t,this.userDrawings&&(this.userDrawings.historyChords=this.historyChordsEnabled);return;case "settings":this.setSettingsEnabled(!!t);return;case "indicatorTitles":this.indicatorTitlesOn=t!==false,this.inputsUI?.setTitlesVisible(this.indicatorTitlesOn);return;case "indicatorValues":this.indicatorValuesOn=t!==false,this.inputsUI?.setValuesVisible(this.indicatorValuesOn);return;case "attribution":this.attributionHtml=typeof t=="string"&&t.trim()?t:null,this.attributionEnabled=this.attributionHtml!==null||!!t,this.rebuildAttribution();return;case "dialogHost":this.dialogHost=t instanceof HTMLElement?t:null,this.settingsDialog?.close(),this.settingsDialog=null,this.inputsUI?.setDialogHost(this.dialogHost);return;default:return}this.scheduler?.invalidate(4);}readFeature(e){switch(e){case "logScale":return this.scene.logScale;case "currentPriceLine":return this.scene.showPriceLine;case "priceLabel":return this.scene.showPriceLabel;case "countdown":return this.scene.showCountdown;case "upColor":return this.candleUp;case "downColor":return this.candleDown;case "glow":return this.glowAmount;case "animZoom":return this.animZoom.tau;case "animPan":return this.animPan.tau;case "animScroll":return this.animScroll.tau;case "animAutoscale":return this.animAutoscale.tau;case "animLiveBar":return this.animLiveBar.tau;case "intro":return this.intro.style;case "zoomAnchor":return this.zoomAnchorMode;case "axisDrag":return this.input?this.input.axisDrag:this.axisDragEnabled;case "paneResize":return this.input?this.input.paneResize:this.paneResizeEnabled;case "candleZOrder":return this.scene.candleZ;case "candleVisible":return !this.scene.candlesHidden;case "seriesOrder":return this.scene.indicatorZOrder();case "highlights":return this.scene.highlights;case "sessionZones":return this.scene.sessionZones;case "gridlines":return this.scene.showGrid;case "axisLabels":return this.scene.showAxisLabels;case "scaleMode":return this.scene.scaleMode;case "invertScale":return this.scene.invertScale;case "paneScales":return this.paneScaleInfos();case "autoScale":{let t=this.scene.orderedPanes().find(n=>n.kind==="price");return t?t.manualScale==null:true}case "timezone":return this.scene.timezone;case "priceStyle":return this.scene.priceStyle;case "priceBaseline":return this.scene.baselineValue;case "baselinePrice":{let t=this.scene.panes.get(He);return t?this.scene.baselinePriceFor(t.scale):this.scene.baselineValue}case "tradeMarkers":return {...this.scene.tradeMarkers,colors:{...this.scene.tradeMarkers.colors}};case "marks":return {visible:this.scene.marks.visible,groups:{...this.scene.marks.groups}};case "keyboard":return this.keyboardEnabled;case "historyChords":return this.historyChordsEnabled;case "settings":return this.settingsEnabled;case "indicatorTitles":return this.indicatorTitlesOn;case "indicatorValues":return this.indicatorValuesOn;case "attribution":return this.attributionHtml??this.attributionEnabled;case "dialogHost":return this.dialogHost??void 0;default:return}}setNativeData(e,t){e==="volume"?(this.scene.volumeLayer=t??null,this.scheduler?.invalidate(3)):e==="vpvr"?(this.scene.vpvrLayer=t??null,this.scheduler?.invalidate(3)):e.endsWith("-pending")?(this.scene.nativePending.set(e.slice(0,-8),t??[]),this.scheduler?.invalidate(3)):(this.scene.nativeData.set(e,t),this.scheduler?.invalidate(3));}setIndicatorStatus(e,t){this.inputsUI.setStatus(e.id,t);}setLoading(e){if(!e||!this.wrapper){this.loadingEl?.remove(),this.loadingEl=null;return}if(this.loadingEl)return;let t=this.wrapper.ownerDocument,n=t.createElement("div");n.className="vela-loading",Object.assign(n.style,{position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",gap:"7px",pointerEvents:"none"});for(let i=0;i<3;i+=1){let o=t.createElement("span");Object.assign(o.style,{width:"7px",height:"7px",borderRadius:"50%",background:this.chromeTheme().textColor,opacity:"0.15"}),o.animate([{opacity:.12},{opacity:.55}],{duration:800,iterations:1/0,direction:"alternate",easing:"ease-in-out",delay:-i*260}),n.appendChild(o);}this.wrapper.appendChild(n),this.loadingEl=n;}setPricePrecision(e){let t=typeof e=="number"&&e>0?e:void 0;t!==this.scene.priceMintick&&(this.scene.priceMintick=t,this.scheduler?.invalidate(4));}getConfig(){let e=this.scene.style,t=Object.fromEntries(Object.entries(e.chartTypes).map(([i,o])=>[i,{...o}])),n=this.theme;return {version:dh,chartTypes:t,layout:{background:n.background,textColor:n.textColor,fontFamily:n.fontFamily,fontSize:e.fontSize},grid:{vertLines:{visible:e.gridVert.visible,color:e.gridVert.color??n.gridColor},horzLines:{visible:e.gridHorz.visible,color:e.gridHorz.color??n.gridColor}},crosshair:{color:e.crosshair.color??n.textColor,width:e.crosshair.width,style:e.crosshair.style,opacity:e.crosshair.opacity,labelBackground:e.crosshair.labelBackground??n.textColor},priceScale:{mode:this.scene.scaleMode,log:this.scene.logScale,invert:this.scene.invertScale,borderColor:e.borderColor??n.borderColor,labelsVisible:this.scene.showAxisLabels,currentPriceLine:this.scene.showPriceLine,priceLabel:this.scene.showPriceLabel,countdown:this.scene.showCountdown,animateLastPrice:this.animLiveBar.on},animations:{zoom:this.animZoom.on,pan:this.animPan.on,autoscale:this.animAutoscale.on,intro:this.intro.style!==false},panes:{separatorColor:e.separatorColor??n.borderColor},trades:{visible:this.scene.tradeMarkers.visible,labels:this.scene.tradeMarkers.labels,qty:this.scene.tradeMarkers.qty,longColor:this.scene.tradeMarkers.colors.long,shortColor:this.scene.tradeMarkers.colors.short,exitColor:this.scene.tradeMarkers.colors.exit},timeScale:{timezone:this.scene.timezone},marks:{visible:this.scene.marks.visible,groups:{...this.scene.marks.groups}},candles:{upColor:this.candleUp,downColor:this.candleDown,bodyVisible:e.candle.bodyVisible,borderVisible:e.candle.borderVisible,borderUpColor:e.candle.borderUpColor??this.candleUp,borderDownColor:e.candle.borderDownColor??this.candleDown,wickVisible:e.candle.wickVisible,wickUpColor:e.candle.wickUpColor??this.candleUp,wickDownColor:e.candle.wickDownColor??this.candleDown},bars:{upColor:e.bars.upColor??this.candleUp,downColor:e.bars.downColor??this.candleDown},line:{color:e.line.color??this.candleUp,width:e.line.width},stacking:{candles:this.scene.candleZ,series:Object.fromEntries(this.scene.indicatorZOrder().map(({id:i,z:o})=>[i,o]))},area:(()=>{let i=e.area.lineColor??this.candleUp;return {lineColor:i,width:e.area.width,topColor:e.area.topColor??i,bottomColor:e.area.bottomColor??rI}})(),baseline:(()=>{let i=e.baseline.topLineColor??Ei,o=e.baseline.bottomLineColor??Li;return {topLineColor:i,bottomLineColor:o,topFillColor:e.baseline.topFillColor??q(i,Cn),topFillColor2:e.baseline.topFillColor2??q(i,Tn),bottomFillColor:e.baseline.bottomFillColor??q(o,Cn),bottomFillColor2:e.baseline.bottomFillColor2??q(o,Tn),width:e.baseline.width,baselineLevel:e.baseline.baselineLevel}})(),series:{style:this.scene.priceStyle,baseline:this.scene.baselineValue,spacing:this.coords.spacingScale},sessions:{premarketColor:e.sessions.premarketColor,postmarketColor:e.sessions.postmarketColor,extendedColor:e.sessions.extendedColor}}}applyConfig(e){let t=ky(this.getConfig(),e),n=this.scene.style;for(let[u,d]of Object.entries(t.chartTypes))if(JSON.stringify(n.chartTypes[u])!==JSON.stringify(d)){this.scene.nativeData.set(`${u}-settings`,{...d});for(let h of this.chartTypeSettingsCbs)h(u,{...d});}n.chartTypes=Object.fromEntries(Object.entries(t.chartTypes).map(([u,d])=>[u,{...d}]));let i=e&&typeof e=="object"?e.layout:void 0,o=i&&typeof i=="object"?i.textColor:void 0,s=typeof o=="string"&&o.trim().length>0,a=this.theme,l={textColor:t.layout.textColor,gridColor:a.gridColor,borderColor:a.borderColor};if(!s&&lt(t.layout.textColor)===lt(t.layout.background)){let u=lt(t.layout.background)?Yt:lo;l={textColor:u.textColor,gridColor:u.gridColor,borderColor:u.borderColor};}this.theme={...this.theme,background:t.layout.background,textColor:l.textColor,gridColor:l.gridColor,borderColor:l.borderColor,fontFamily:t.layout.fontFamily},n.fontSize=t.layout.fontSize;let c=(u,d,h)=>u===null&&d===h?null:d;n.gridVert={visible:t.grid.vertLines.visible,color:c(n.gridVert.color,t.grid.vertLines.color,a.gridColor)},n.gridHorz={visible:t.grid.horzLines.visible,color:c(n.gridHorz.color,t.grid.horzLines.color,a.gridColor)},n.crosshair={color:t.crosshair.color,width:t.crosshair.width,style:t.crosshair.style,opacity:t.crosshair.opacity,labelBackground:t.crosshair.labelBackground},this.scene.scaleMode=t.priceScale.mode,this.scene.logScale=t.priceScale.log,this.scene.invertScale=t.priceScale.invert,n.borderColor=c(n.borderColor,t.priceScale.borderColor,a.borderColor),this.scene.showAxisLabels=t.priceScale.labelsVisible,this.scene.showPriceLine=t.priceScale.currentPriceLine,this.scene.showPriceLabel=t.priceScale.priceLabel,this.scene.showCountdown=t.priceScale.countdown,this.syncCountdownTimer(),this.animLiveBar.toggle(t.priceScale.animateLastPrice),this.animZoom.toggle(t.animations.zoom),this.animPan.toggle(t.animations.pan),this.animScroll.toggle(t.animations.pan),this.animAutoscale.toggle(t.animations.autoscale),this.intro={style:t.animations.intro?this.introOnStyle:false,duration:this.intro.duration||650},n.separatorColor=c(n.separatorColor,t.panes.separatorColor,a.borderColor),this.scene.tradeMarkers={visible:t.trades.visible,labels:t.trades.labels,qty:t.trades.qty,colors:{long:t.trades.longColor,short:t.trades.shortColor,exit:t.trades.exitColor}},this.scene.timezone=t.timeScale.timezone,this.scene.marks={visible:t.marks.visible,groups:{...t.marks.groups}},this.candleUp=t.candles.upColor,this.candleDown=t.candles.downColor,n.candle={bodyVisible:t.candles.bodyVisible,borderVisible:t.candles.borderVisible,borderUpColor:t.candles.borderUpColor,borderDownColor:t.candles.borderDownColor,wickVisible:t.candles.wickVisible,wickUpColor:t.candles.wickUpColor,wickDownColor:t.candles.wickDownColor},this.scene.candleZ=t.stacking.candles;for(let[u,d]of Object.entries(t.stacking.series))this.scene.setIndicatorZ(u,d);n.bars={upColor:t.bars.upColor,downColor:t.bars.downColor},n.line={color:t.line.color,width:t.line.width},n.area={lineColor:t.area.lineColor,width:t.area.width,topColor:t.area.topColor,bottomColor:t.area.bottomColor},n.baseline={topLineColor:t.baseline.topLineColor,bottomLineColor:t.baseline.bottomLineColor,topFillColor:t.baseline.topFillColor,topFillColor2:t.baseline.topFillColor2,bottomFillColor:t.baseline.bottomFillColor,bottomFillColor2:t.baseline.bottomFillColor2,width:t.baseline.width,baselineLevel:t.baseline.baselineLevel},n.sessions={premarketColor:t.sessions.premarketColor,postmarketColor:t.sessions.postmarketColor,extendedColor:t.sessions.extendedColor},this.setPriceStyle(t.series.style),this.scene.candleOverride=bc(this.scene.priceStyle,n.chartTypes),this.scene.baselineValue=t.series.baseline,this.coords.setPitchScale(t.series.spacing),this.coords.setViewport(this.clampViewport(this.coords.getViewport().barSpacing,this.coords.getViewport().rightOffset)),this.targetBarSpacing=this.coords.getViewport().barSpacing,this.theme=this.deriveTheme(this.theme),this.wrapper&&(Re(this.wrapper,this.chromeTheme()),this.applyBackground()),this.inputsUI?.setTheme(this.theme),this.paneControls?.setTheme(this.theme),this.axisScaleButtons?.setTheme(this.theme),this.userDrawings?.setTheme(this.chromeTheme()),this.refreshScrollButtonTheme(),this.refreshAttributionColor(),this.scheduler?.invalidate(4);for(let u of this.configChangedCbs)u();}applySeriesOrder(e){if(!e||typeof e!="object")return;let t=e;typeof t.id=="string"&&(typeof t.z=="number"?this.scene.setIndicatorZ(t.id,t.z):t.to==="front"?this.scene.bringIndicatorToFront(t.id):t.to==="back"&&this.scene.sendIndicatorToBack(t.id));}setSettingsEnabled(e){this.settingsEnabled=e,e?(this.plot&&!this.settingsButton&&(this.settingsButton=this.makeSettingsButton(),this.plot.appendChild(this.settingsButton)),this.settingsButton&&(this.settingsButton.style.display="flex"),this.plot&&!this.settingsDialog&&(this.settingsDialog=new vs(this.dialogHost??this.plot,this.theme))):(this.settingsButton?.style.setProperty("display","none"),this.settingsDialog?.close());}makeSettingsButton(){let e=document.createElement("button");return e.type="button",e.title="Chart settings",e.innerHTML=ye("gear",14),Object.assign(e.style,{position:"absolute",bottom:`${Hi+10}px`,right:`${au+10}px`,zIndex:"6",width:"26px",height:"26px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",borderRadius:"50%",border:`1px solid ${this.theme.borderColor}`,background:this.theme.background,color:this.theme.textColor,fontSize:"14px",lineHeight:"1",opacity:"0.75",pointerEvents:"auto",padding:"0"}),e.addEventListener("mouseenter",()=>e.style.opacity="1"),e.addEventListener("mouseleave",()=>e.style.opacity="0.75"),e.addEventListener("click",()=>this.toggleSettingsDialog()),e}openSettingsDialog(e){!this.settingsDialog&&this.plot&&(this.settingsDialog=new vs(this.dialogHost??this.plot,this.theme),this.settingsDialog.setLayoutMode(this.layoutMode)),this.toggleSettingsDialog(e);}syncThemeControl(){this.settingsDialog?.setThemeControl(lt(this.surfaceBackground)?"dark":"light",e=>{for(let t of this.themeSelectCbs)t(e);});}toggleSettingsDialog(e){if(this.settingsDialog){if(e!==void 0&&this.settingsDialog.isOpen()){this.settingsDialog.showSection(e);return}this.settingsDialog.setTheme(this.theme),this.settingsDialog.setHostSections(this.hostSettingsSections),this.settingsDialog.setMarkGroups(this.markGroupsInUse(),t=>Lc(this.scene.marks,t,this.scene.markGroups)),this.settingsDialog.setHiddenSettings(this.hiddenSettings),this.syncThemeControl(),this.settingsDialog.toggle(this.getConfig(),t=>this.applyConfig(t),t=>this.applyConfig(t),()=>{this.factoryConfig&&this.applyConfig(Ty(this.factoryConfig)),this.settingsDialog?.close(),this.openSettingsDialog();},e);}}closeDialogs(){this.inputsUI?.closeOpenDialog(),this.settingsDialog?.close();}makeScrollToRealtimeButton(){let e=document.createElement("button");return e.type="button",e.title="Scroll to most recent bar (Alt+Shift+\u2192)",e.setAttribute("aria-label","Scroll to most recent bar"),e.innerHTML=this.scrollButtonIcon(),Object.assign(e.style,{position:"absolute",bottom:`${ap}px`,right:`${Mx}px`,zIndex:"6",width:`${ks}px`,height:`${ks}px`,boxSizing:"border-box",display:"none",alignItems:"center",justifyContent:"center",cursor:"pointer",borderRadius:`${oI}px`,border:`1px solid ${this.theme.borderColor}`,boxShadow:sI,background:this.scrollButtonSurface(),color:this.theme.textColor,lineHeight:"0",opacity:"0.85",pointerEvents:"auto",padding:"0"}),e.addEventListener("mouseenter",()=>e.style.opacity="1"),e.addEventListener("mouseleave",()=>e.style.opacity="0.85"),e.addEventListener("click",()=>this.scrollToRealtime()),e}scrollButtonIcon(){return ye("chevrons-right",aI)}scrollButtonSurface(){return q(this.theme.background,.5)}refreshScrollButtonTheme(){this.scrollButton&&(this.scrollButton.style.background=this.scrollButtonSurface(),this.scrollButton.style.color=this.theme.textColor,this.scrollButton.style.borderColor=this.theme.borderColor);}updateScrollToRealtimeButton(){let e=this.scrollButton;if(!e)return;let t=this.coords.barCount>0&&this.coords.getViewport().rightOffset<0;if(this.layoutMode==="mobile"){e.style.display=t?"flex":"none";return}e.style.display=t&&this.pointerNearScrollBtn?"flex":"none";}scrollToRealtime(){this.coords.barCount!==0&&this.glideRightOffset(Px);}glideRightOffset(e){let t=this.coords.getViewport();if(!this.animScroll.on){this.applyViewport({barSpacing:t.barSpacing,rightOffset:e});return}this.panVelocity=0,this.targetBarSpacing=t.barSpacing,this.scrollTargetRO=e,this.animator.start();}screenshotCanvas(){if(!this.dataCanvas)return null;this.computeScales(),this.paintData();let e=document.createElement("canvas");e.width=this.dataCanvas.width,e.height=this.dataCanvas.height;let t=e.getContext("2d");if(!t)return null;t.fillStyle=this.theme.background,t.fillRect(0,0,e.width,e.height);let n=this.plot?.getBoundingClientRect(),i=n&&n.width>0?{left:n.left,top:n.top,dpr:e.width/n.width}:null,o=[...this.mountContainer?.querySelectorAll("[data-vela-screenshot]")??[]];if(i)for(let s of o)s.getAttribute("data-vela-screenshot")==="under"&&ou(t,s,i);for(let s of [...this.canvasPile(),this.chromeCanvas,this.drawingsCanvas])s&&s.width>0&&s.height>0&&t.drawImage(s,0,0);if(i){for(let s of this.plot?.querySelectorAll("[data-vela-pane]")??[])ou(t,s,i);for(let s of o)s.getAttribute("data-vela-screenshot")!=="under"&&ou(t,s,i);}return e}screenshot(){return this.screenshotCanvas()?.toDataURL("image/png")??null}playIntro(){this.introRaf!=null&&cancelAnimationFrame(this.introRaf),this.introRaf=null;let{style:e,duration:t}=this.intro,n=this.bars,i=n.length;if(i===0||!e)return;this.computeScales();for(let a of this.scene.panes.values())a.scale={...a.scaleTarget};this.modelAlpha=0;let o=performance.now(),s=a=>{let l=Math.min(1,(a-o)/t);this.scene.bars=l>=1?n:n.map((c,u)=>this.revealCandle(c,u,l,i,e)),this.paintData(),l<1?this.introRaf=requestAnimationFrame(s):(this.scene.bars=n,this.fadeInModels());};this.introRaf=requestAnimationFrame(s);}fadeInModels(){let e=Math.min(Ix,this.intro.duration||Ix),t=performance.now(),n=i=>{this.modelAlpha=Math.min(1,(i-t)/e),this.paintData(),this.modelAlpha<1?this.introRaf=requestAnimationFrame(n):(this.modelAlpha=1,this.introRaf=null);};this.introRaf=requestAnimationFrame(n);}revealCandle(e,t,n,i,o){let a=Math.max(0,Math.min(1,(n-t/Math.max(1,i-1)*.55)/.44999999999999996)),l;if(o==="settle"){let d=a-1;l=1+(1.70158+1)*d*d*d+1.70158*d*d;}else {let u=1-a;l=1-u*u*u;}let c=e.open;return {...e,high:c+(e.high-c)*l,low:c+(e.low-c)*l,close:c+(e.close-c)*l}}deriveTheme(e){return {...e,upColor:this.candleUp,downColor:this.candleDown}}chromeTheme(){return {...this.theme,background:this.surfaceBackground,textColor:this.surfaceTextColor,borderColor:lt(this.surfaceBackground)?Yt.borderColor:lo.borderColor}}axisSurface(){return {background:this.theme.background,textColor:this.theme.textColor}}mount(e,t){this.mountContainer=e,this.publishGutters(),this.theme=this.deriveTheme(t),this.surfaceBackground=t.background,this.surfaceTextColor=t.textColor,this.wrapper=document.createElement("div"),Object.assign(this.wrapper.style,{position:"relative",width:"100%",height:"100%",overflow:"hidden",cursor:"crosshair",userSelect:"none",webkitUserSelect:"none"}),Re(this.wrapper,this.chromeTheme()),this.backdropCanvas=document.createElement("canvas"),Object.assign(this.backdropCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.volumeCanvas=document.createElement("canvas"),Object.assign(this.volumeCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.dataCanvas=this.createGeometryBackend(),this.vpvrCanvas=document.createElement("canvas"),Object.assign(this.vpvrCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.chromeCanvas=document.createElement("canvas"),Object.assign(this.chromeCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.drawingsCanvas=document.createElement("canvas"),Object.assign(this.drawingsCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.cursorCanvas=document.createElement("canvas"),Object.assign(this.cursorCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.overlayRoot=document.createElement("div"),Object.assign(this.overlayRoot.style,{position:"absolute",inset:"0",pointerEvents:"none"}),this.plot=document.createElement("div"),Object.assign(this.plot.style,{position:"absolute",top:"0",right:"0",bottom:"0",left:"0"}),this.extLayers=tp().map(o=>({def:o,instance:o.create(),canvas:this.createLayerCanvas(),channel:o.id,owner:null}));let n=this.extLayers.filter(o=>o.def.placement==="below-data").map(o=>o.canvas),i=this.extLayers.filter(o=>o.def.placement!=="below-data").map(o=>o.canvas);this.plot.append(this.backdropCanvas,...n,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...i,this.chromeCanvas,this.drawingsCanvas,this.cursorCanvas,this.overlayRoot),this.layerOrderSig="",this.wrapper.appendChild(this.plot),this.factoryConfig=this.getConfig(),this.attributionEl=this.buildAttributionEl(),this.attributionEnabled||(this.attributionEl.style.display="none"),this.positionAttribution(),this.wrapper.appendChild(this.attributionEl),e.appendChild(this.wrapper),this.applyBackground(),this.backdropRenderer.mount(this.backdropCanvas),this.volumeRenderer.mount(this.volumeCanvas),this.vpvrRenderer.mount(this.vpvrCanvas);for(let o of this.extLayers)o.instance.mount(o.canvas);for(let o of this.scene.indicators.values())this.ensureInstanceLayer(o);this.chrome.mount(this.chromeCanvas),this.crosshairLayer.mount(this.cursorCanvas),this.coords.setViewport(cs()),this.scene.ensurePane(He,"price",0,3),this.scheduler=new Sc(o=>this.renderFrame(o)),this.animator=new Cc(o=>this.animTick(o)),this.targetBarSpacing=this.coords.getViewport().barSpacing,this.input=new Tc({getCoords:()=>this.coords,apply:o=>this.applyViewport(o),zoomTo:(o,s,a)=>this.zoomTo(o,s,a),fling:o=>this.fling(o),onPointerMove:(o,s)=>this.handlePointerMove(o,s),onClick:(o,s)=>{this.handleMarkClick(o,s)||(this.userDrawings?.deselect(),this.handleClick(o));},onAxisLongPress:(o,s,a)=>{for(let l of this.axisLongPressCbs)l({axis:o,x:s,y:a});},beginPriceScale:(o,s)=>this.beginPriceScale(o,s),priceScaleBy:o=>this.priceScaleBy(o),beginPricePan:o=>this.beginPricePan(o),pricePanBy:o=>this.pricePanBy(o),resetPriceScale:(o,s)=>this.resetPriceScale(o,s),dataDblClick:(o,s)=>this.dataDblClick(o,s),paneSeparatorAt:o=>this.paneSeparatorAt(o),beginPaneResize:o=>this.beginPaneResize(o),paneResizeBy:o=>this.paneResizeBy(o),resetPaneSize:o=>this.resetPaneSize(o),resetView:()=>this.resetView(),drawingsClaim:(o,s)=>this.userDrawings?.claim(o,s)??false,drawingsMeasureStart:(o,s,a)=>this.userDrawings?.beginMeasureAt(o,s,a)??false,drawingsMarqueeStart:(o,s)=>this.userDrawings?.beginMarqueeAt(o,s)??false,drawingsDeleteAt:(o,s)=>this.userDrawings?.deleteAt(o,s,true)??false,drawingsCancelPlacement:()=>this.userDrawings?.cancelPlacement()??false,drawingsSnapMode:()=>this.snapMode,drawingsPointerDown:(o,s,a,l,c)=>this.userDrawings?.pointerDown(o,s,a,l,c),drawingsPointerMove:(o,s,a,l,c)=>this.userDrawings?.pointerMove(o,s,a,l,c),drawingsPointerUp:(o,s,a)=>this.userDrawings?.pointerUp(o,s,a),drawingsCursor:(o,s)=>this.userDrawings?.cursorAt(o,s)??(this.chrome.markGlyphAt(o,s)?"pointer":null),drawingsDblClick:(o,s)=>this.userDrawings?.dblClick(o,s)??false,drawingsClearTransient:()=>this.userDrawings?.clearTransient()}),this.input.rightEdgeZoom=this.zoomAnchorMode==="right",this.input.axisDrag=this.axisDragEnabled,this.input.paneResize=this.paneResizeEnabled,this.input.attach(this.dataCanvas),this.settingsEnabled&&this.setSettingsEnabled(true),this.syncCountdownTimer(),this.scrollButton=this.makeScrollToRealtimeButton(),this.plot.appendChild(this.scrollButton),this.plot.addEventListener("pointermove",this.onScrollProximityMove),this.plot.addEventListener("pointerleave",this.onScrollProximityLeave),this.labelTooltip=new _c(this.plot,{theme:()=>this.chromeTheme(),lookup:(o,s)=>this.indicatorSlices.labelTooltipAt(o,s)??this.chrome.markTooltipAt(o,s,this.markGroupsInUse())}),this.markPopover=new tu({plot:this.plot,host:()=>this.dialogHost??this.plot,theme:()=>this.chromeTheme(),onOpenChange:o=>{this.scene.marksActiveKey=o,this.scheduler?.invalidate(2);}}),this.chrome.setMarkIconReady(()=>this.scheduler?.invalidate(2)),this.userDrawings=new Zc(this.wrapper,this.plot,this.drawingsCanvas,{projector:()=>this.drawingProjector(),dpr:()=>this.coords.dpr,theme:()=>this.theme,requestScaleUpdate:()=>this.scheduler.invalidate(3),seriesBoundaries:o=>this.scene.seriesBoundaries(o),priceZ:o=>o===He?this.scene.candleZ:null,requestDataPaint:()=>this.scheduler.invalidate(3),seriesLook:()=>{let o=this.scene.style,s=Mi(o.candle,this.scene.candleOverride,this.theme.upColor,this.theme.downColor),a=o.bars.upColor??this.theme.upColor,l=o.bars.downColor??this.theme.downColor,c=this.scene.priceStyle;return {style:c,upColor:c==="bars"?a:s.up,downColor:c==="bars"?l:s.down,lineColor:c==="area"?o.area.lineColor??this.theme.upColor:o.line.color??this.theme.upColor}},chartBarMs:()=>this.coords.barInterval,snap:(o,s,a,l)=>this.snapToCandle(o,s,a,l),setSnapMode:o=>this.setSnapMode(o),setToolbarGutter:o=>this.setToolbarGutter(o)}),this.userDrawings.historyChords=this.historyChordsEnabled,this.layoutMode==="mobile"&&(this.mountContainer?.setAttribute("data-vela-layout",this.layoutMode),this.userDrawings.setLayoutMode(this.layoutMode),this.scrollButton&&(this.scrollButton.style.width=`${sp}px`,this.scrollButton.style.height=`${sp}px`)),this.keyboard=new kc({panByBars:o=>this.panByBars(o),zoomByStep:o=>this.zoomByStep(o),stepCrosshair:o=>this.stepCrosshair(o),jumpToEdge:o=>this.focusBar(o==="first"?0:this.coords.barCount-1),resetView:()=>this.resetView(),scrollToRealtime:()=>this.scrollToRealtime(),clearCrosshair:()=>this.handlePointerMove(null,null),preempt:o=>this.userDrawings?.handleKey(o)??false}),this.setKeyboardEnabled(this.keyboardEnabled),this.inputsUI=new hc(this.plot,t,o=>this.paneBoundsFor(o)),this.inputsUI.setLayoutMode(this.layoutMode),this.inputsUI.setTitlesVisible(this.indicatorTitlesOn),this.inputsUI.setValuesVisible(this.indicatorValuesOn),this.inputsUI.setDialogHost(this.dialogHost),this.inputsUI.setSymbolPicker(this.symbolPicker),this.inputsUI.setLegendActions(this.legendActionsProvider),this.inputsUI.setLegendCallouts(this.legendCalloutsProvider),this.inputsUI.setLegendOverviewAction(this.legendOverviewAction),this.inputsUI.setOnChange(o=>{for(let s of this.inputChangeCbs)s({indicatorId:o.indicatorId,key:o.key,value:o.value,...o.kind?{kind:o.kind}:{}});}),this.inputsUI.setOnRemove(o=>{for(let s of this.removeIndicatorCbs)s(o);}),this.inputsUI.setOnToggleVisible((o,s)=>{for(let a of this.toggleVisibleCbs)a(o,s);}),this.inputsUI.setMoveApi({panes:()=>this.scene.orderedPanes().map((o,s)=>({id:o.id,kind:o.kind,label:o.kind==="price"?"Main chart":this.paneMasterTitle(o.id)??`Pane ${s}`,top:o.bounds.top,height:o.bounds.height})),move:(o,s)=>{for(let a of this.moveIndicatorCbs)a(o,s);}}),this.paneControls=new pc(this.plot,t,{panes:()=>this.paneControlViews(),rightAxis:()=>this.rightAxisW,onMove:(o,s)=>this.movePaneLocal(o,s),onToggleCollapse:o=>{let s=this.scene.panes.get(o);if(!s)return;let a=!s.collapsed;s.collapsed=a,this.afterPaneLayoutChange(),this.emitPaneAction({type:"collapse",paneId:o,collapsed:a});},onToggleMaximize:o=>{let s=this.maximizedPaneId!==o;this.maximizedPaneId=s?o:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:o,maximized:s});}}),this.paneControls.setSuspended(this.layoutMode==="mobile"),this.axisScaleButtons=new mc(this.plot,t,{panes:()=>this.axisScaleViews(),rightAxis:()=>this.rightAxisW,onToggleAuto:o=>this.togglePaneAuto(o),onToggleLog:o=>{let s=this.scene.panes.get(o);s&&this.setPaneLog(o,!Ri(this.scene,s));}}),this.resizeObserver=new ResizeObserver(o=>{for(let s of o){if(s.target!==this.plot)continue;let a=s.devicePixelContentBoxSize?.[0];a&&(this.plotDeviceSize={width:a.inlineSize,height:a.blockSize});}this.resize();}),this.resizeObserver.observe(this.wrapper);try{this.resizeObserver.observe(this.plot,{box:"device-pixel-content-box"});}catch{}this.watchDpr(),this.syncSize();}makeDataCanvas(){let e=document.createElement("canvas");return Object.assign(e.style,{position:"absolute",inset:"0",width:"100%",height:"100%"}),e}createGeometryBackend(){if((this.backendMode==="auto"||this.backendMode==="webgl2")&&wy()){let n=this.makeDataCanvas(),i=new wc;if(i.glow=this.glowAmount,i.onNeedsRedraw=()=>this.scheduler?.invalidate(4),i.onContextFailed=()=>this.swapToCanvas2dFallback(),i.mount(n),i.ok)return this.backend=i,n;i.destroy();}let e=this.makeDataCanvas(),t=new us;return t.mount(e),this.backend=t,e}swapToCanvas2dFallback(){if(this.backend.kind==="canvas2d")return;let e=this.dataCanvas;this.input?.detach(),this.backend.destroy();let t=this.makeDataCanvas(),n=new us;n.mount(t),this.backend=n,e.replaceWith(t),this.dataCanvas=t,this.input?.attach(t),this.syncSize();}watchDpr(){typeof window.matchMedia=="function"&&(this.dprMedia?.removeEventListener("change",this.onDprChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDprChange,{once:true}));}setTheme(e){this.theme=this.deriveTheme(e),this.surfaceBackground=e.background,this.surfaceTextColor=e.textColor,this.wrapper&&Re(this.wrapper,this.chromeTheme()),this.applyBackground(),this.inputsUI.setTheme(e),this.paneControls?.setTheme(this.theme),this.axisScaleButtons?.setTheme(this.theme),this.settingsDialog?.refreshConfig(this.getConfig()),this.syncThemeControl(),this.settingsDialog?.setTheme(this.theme),this.settingsButton&&(this.settingsButton.style.background=this.theme.background,this.settingsButton.style.color=this.theme.textColor,this.settingsButton.style.borderColor=this.theme.borderColor),this.refreshScrollButtonTheme(),this.userDrawings?.setTheme(this.chromeTheme()),this.refreshAttributionColor(),this.scheduler.invalidate(4);}resize(){this.syncSize();}setWallClock(e){e!==this.hostClock&&(this.hostClock=e,this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null),this.syncCountdownTimer());}syncCountdownTimer(){if(this.scene.showCountdown){if(this.countdownUnsub==null){let e=this.hostClock??this.ownClock??(this.ownClock=new yo);this.countdownUnsub=e.onTick(()=>{this.scene.showCountdown&&this.scene.bars.length>0&&this.scheduler?.invalidate(2);});}}else this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null);}destroy(){this.introRaf!=null&&cancelAnimationFrame(this.introRaf),this.loadingEl?.remove(),this.loadingEl=null,this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null),this.scheduler?.destroy(),this.animator?.stop(),this.input?.detach(),this.keyboard?.detach(),this.keyboard=null,this.liveRegion=null,this.inputsUI?.destroy(),this.paneControls?.destroy(),this.axisScaleButtons?.destroy(),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.dprMedia?.removeEventListener("change",this.onDprChange),this.dprMedia=null,this.userDrawings?.destroy(),this.userDrawings=null,this.settingsDialog?.destroy(),this.settingsDialog=null,this.settingsButton?.remove(),this.settingsButton=null,this.plot?.removeEventListener("pointermove",this.onScrollProximityMove),this.plot?.removeEventListener("pointerleave",this.onScrollProximityLeave),this.labelTooltip?.destroy(),this.labelTooltip=null,this.markPopover?.destroy(),this.markPopover=null,this.chrome.setMarkIconReady(null),this.markPulseRaf!==null&&cancelAnimationFrame(this.markPulseRaf),this.markPulseRaf=null,this.scrollButton?.remove(),this.scrollButton=null;for(let e of this.extLayers)e.instance.destroy?.();this.extLayers=[],this.backdropRenderer.destroy(),this.volumeRenderer.destroy(),this.vpvrRenderer.destroy(),this.backend.destroy(),this.chrome.destroy(),this.crosshairLayer.destroy(),this.attributionEl?.remove(),this.attributionEl=null,this.mountContainer?.style.removeProperty("--vela-toolbar-gutter"),this.mountContainer?.style.removeProperty("--vela-scale-gutter"),this.mountContainer?.style.removeProperty("--vela-bottom-gutter"),this.mountContainer?.style.removeProperty("--vela-price-pane-top"),this.mountContainer?.style.removeProperty("--vela-price-pane-bottom"),this.mountContainer=null,this.wrapper?.remove();}setBars(e,t){this.introRaf!=null&&(cancelAnimationFrame(this.introRaf),this.introRaf=null,this.modelAlpha=1),this.liveEaseTime=0;let n=this.bars,i=n[0]?.time;this.bars=xI(e),this.scene.bars=this.bars,this.coords.setBars(this.bars.map(s=>s.time));for(let s of this.scene.indicators.values())this.refreshAnchorOffset(s);if(t?.preserveView===true&&i!=null&&this.bars.length>0){let s=this.bars[0].time,a=0;if(s!==i){let l=this.bars.findIndex(c=>c.time===i);if(l>0)a=l;else {let c=n.findIndex(u=>u.time===s);c>0&&(a=-c);}}a!==0&&(this.zoomAnchorLogical+=a,this.hoverLogical!=null&&(this.hoverLogical+=a));}let o=t?.preserveView===true&&this.didInitialFit;if(this.coords.width>0&&!o&&(this.didInitialFit?this.reframeKeepZoom():this.fitContent(),this.didInitialFit=true),!this.introPlayed&&this.bars.length>0&&(this.introPlayed=true,this.intro.style)){this.playIntro();return}this.scheduler.invalidate(4);}updateBar(e){let t=this.bars.length,n=this.bars[t-1];if(n&&e.time===n.time)this.bars[t-1]=e,!this.animLiveBar.on||this.liveEaseTime!==e.time?this.syncLiveEase(e):this.animator.start();else if(!n||e.time>n.time)this.bars.push(e),this.syncLiveEase(e),this.coords.barInterval>0?this.coords.appendBar(e.time):this.coords.setBars(this.bars.map(i=>i.time));else return;this.scene.bars=this.bars,this.scheduler.invalidate(4);}setIntro(e){this.intro=e,e.style&&(this.introOnStyle=e.style);}syncLiveEase(e){this.liveEaseTime=e.time,this.liveEaseHigh=e.high,this.liveEaseLow=e.low,this.liveEaseClose=e.close;}easeLiveBar(e){let t=this.bars[this.bars.length-1];if(!t||this.liveEaseTime!==t.time)return false;let n=Math.max(1e-9,Math.abs(t.close)*1e-6),i=this.animLiveBar.tau,o=vt(this.liveEaseHigh,t.high,e,i),s=vt(this.liveEaseLow,t.low,e,i),a=vt(this.liveEaseClose,t.close,e,i),l=Math.abs(o-t.high)>n||Math.abs(s-t.low)>n||Math.abs(a-t.close)>n;return this.liveEaseHigh=l?o:t.high,this.liveEaseLow=l?s:t.low,this.liveEaseClose=l?a:t.close,l}ensurePane(e){this.scene.ensurePane(e.id,e.kind,e.order,e.heightWeight??(e.kind==="price"?3:1)),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}removePane(e){e!==He&&(this.scene.removePane(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null),this.refreshAxisWidth(),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}setIndicatorPane(e,t,n){let i=this.scene.indicators.get(e.id);i&&(i.paneId=t,i.ownScale=n?.ownScale===true,i.ownScale||this.scene.dropIndicatorScale(e.id),this.inputsUI.setPane(e.id,t),this.refreshAnchorOffset(i),this.refreshAxisWidth(),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}orderPanes(e){this.scene.orderPanes(e),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}setPaneCollapsed(e,t){let n=this.scene.panes.get(e);!n||n.collapsed===t||(n.collapsed=t,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}setPaneMaximized(e){e!==null&&!this.scene.panes.has(e)&&(e=null),this.maximizedPaneId=e,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}onPaneAction(e){return this.paneActionCbs.add(e),()=>this.paneActionCbs.delete(e)}emitPaneAction(e){for(let t of this.paneActionCbs)t(e);}onMoveIndicator(e){return this.moveIndicatorCbs.add(e),()=>this.moveIndicatorCbs.delete(e)}maxOwnScaleColumns(){let e=0;for(let t of this.scene.panes.values()){let n=this.scene.ownScaleIndicatorsForPane(t.id).length;n>e&&(e=n);}return e}refreshAxisWidth(){let e=au+iI*this.maxOwnScaleColumns();return e===this.rightAxisW?false:(this.rightAxisW=e,this.publishGutters(),this.coords.width>0&&this.syncSize(),true)}refreshAnchorOffset(e){let t=e.anchorTime;if(t==null||this.bars.length===0){this.scene.setAnchorOffset(e.id,0);return}let n=this.bars[0].time;if(t===n){this.scene.setAnchorOffset(e.id,0);return}if(t<n){let a=fI(e,n);if(a==null){console.warn(`[vela] indicator "${e.id}" starts before the first bar with no series to align on \u2014 rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,-a);return}let i=0,o=this.bars.length-1,s=this.bars.length;for(;i<=o;){let a=i+o>>1;this.bars[a].time>=t?(s=a,o=a-1):i=a+1;}if(s>=this.bars.length||this.bars[s].time!==t){console.warn(`[vela] indicator "${e.id}" anchorTime matches no chart bar \u2014 rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,s);}mountIndicator(e){return this.scene.indicators.set(e.id,e),this.refreshAnchorOffset(e),e.native&&this.extLayers.some(t=>t.def.id===e.native.type)?this.scene.assignIndicatorZTop(e.id):this.scene.assignIndicatorZ(e.id),this.ensureInstanceLayer(e),e.legend!==false&&this.inputsUI.upsert(e.id,e.shorttitle??e.title,e.inputs,e.inputValues,e.paneId,{native:!!e.native,...e.props?{props:e.props,propValues:e.propValues??{}}:{}}),e.native?.type==="volume"?(this.volumeActive=true,this.volumeHidden=false):e.native?.type==="vpvr"&&(this.vpvrActive=true,this.vpvrHidden=false),e.ownScale&&this.refreshAxisWidth(),this.paneControls?.refresh(),this.scheduler.invalidate(4),{id:e.id}}updateIndicator(e,t){let n=this.scene.indicators.get(e.id);if(n){if(t.kind==="value"&&t.anchorTime!==void 0){let i=t.anchorTime??void 0;i!==n.anchorTime&&(n.anchorTime=i,this.refreshAnchorOffset(n));}gI(n,t),this.scheduler.invalidate(3);}}removeIndicator(e){let t=this.scene.indicators.get(e.id)?.native?.type;t==="volume"?(this.volumeActive=false,this.volumeHidden=false,this.scene.volumeLayer=null):t==="vpvr"&&(this.vpvrActive=false,this.vpvrHidden=false,this.scene.vpvrLayer=null),this.scene.indicators.delete(e.id),this.dropInstanceLayer(e.id),this.scene.forgetIndicatorZ(e.id),this.scene.forgetAnchorOffset(e.id),this.scene.dropIndicatorScale(e.id),this.inputsUI.remove(e.id),this.refreshAxisWidth(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}setIndicatorInputs(e,t,n){this.inputsUI.setValues(e.id,t,n);}setSymbolPicker(e){this.symbolPicker=e,this.inputsUI?.setSymbolPicker(e);}setLegendActions(e){this.legendActionsProvider=e,this.inputsUI?.setLegendActions(e);}setLegendCallouts(e){this.legendCalloutsProvider=e,this.inputsUI?.setLegendCallouts(e);}setLegendOverviewAction(e){this.legendOverviewAction=e,this.inputsUI?.setLegendOverviewAction(e);}openIndicatorSettings(e){this.inputsUI?.openSettingsFor(e);}setIndicatorVisible(e,t){let n=this.scene.indicators.get(e.id)?.native?.type;if(n==="volume"||n==="vpvr"){n==="volume"?this.volumeHidden=!t:this.vpvrHidden=!t,this.inputsUI.setVisible(e.id,t),this.scheduler.invalidate(4);return}t||this.scene.indicators.delete(e.id),this.inputsUI.setVisible(e.id,t),this.scheduler.invalidate(4);}onInputChange(e){return this.inputChangeCbs.add(e),()=>this.inputChangeCbs.delete(e)}onToggleIndicatorVisible(e){return this.toggleVisibleCbs.add(e),()=>this.toggleVisibleCbs.delete(e)}onPriceStyleChange(e){return this.priceStyleCbs.add(e),()=>this.priceStyleCbs.delete(e)}setPriceStyle(e){if(e!==this.scene.priceStyle){this.scene.priceStyle=e,this.scene.basePainting=hh(e),this.scene.candleOverride=bc(e,this.scene.style.chartTypes);for(let t of this.priceStyleCbs)t(e);}}onRemoveIndicator(e){return this.removeIndicatorCbs.add(e),()=>this.removeIndicatorCbs.delete(e)}setLayoutMode(e){if(e!==this.layoutMode){if(this.layoutMode=e,this.mountContainer?.setAttribute("data-vela-layout",e),this.userDrawings?.setLayoutMode(e),this.settingsDialog?.setLayoutMode(e),this.inputsUI?.setLayoutMode(e),this.paneControls?.setSuspended(e==="mobile"),this.scrollButton){let t=e==="mobile"?sp:ks;this.scrollButton.style.width=`${t}px`,this.scrollButton.style.height=`${t}px`;}this.updateScrollToRealtimeButton();}}setSettingsSections(e){this.hostSettingsSections=e,this.settingsDialog?.setHostSections(e);}setSettingsVisibility(e){this.hiddenSettings=[...e.hidden??[]],this.settingsDialog?.setHiddenSettings(this.hiddenSettings);}listSettingsIds(){return Sw(this.hostSettingsSections,this.markGroupsInUse())}onChartTypeSettingsChange(e){return this.chartTypeSettingsCbs.add(e),()=>this.chartTypeSettingsCbs.delete(e)}onConfigChanged(e){return this.configChangedCbs.add(e),()=>this.configChangedCbs.delete(e)}onThemeSelect(e){return this.themeSelectCbs.add(e),()=>this.themeSelectCbs.delete(e)}onCrosshairMove(e){return this.crosshairCbs.add(e),()=>this.crosshairCbs.delete(e)}onClick(e){return this.clickCbs.add(e),()=>this.clickCbs.delete(e)}onAxisLongPress(e){return this.axisLongPressCbs.add(e),()=>this.axisLongPressCbs.delete(e)}setTimelineMarks(e,t){this.scene.timelineMarks=e,this.scene.markGroups=t,this.scene.marksExpandedStack=null,this.markPopover?.close(),this.scheduler?.invalidate(2);}onMarkClick(e){return this.markClickCbs.add(e),()=>this.markClickCbs.delete(e)}markGroupsInUse(){return mw(this.scene.timelineMarks,this.scene.markGroups)}onViewportChange(e){return this.viewportCbs.add(e),()=>this.viewportCbs.delete(e)}getVisibleRange(){let e=this.coords.barCount;if(e===0||this.coords.width===0)return null;let t=this.coords.visibleLogicalRange(),n=Math.max(0,Math.ceil(t.from)),i=Math.min(e-1,Math.floor(t.to));return i<n?null:{from:this.coords.logicalToTime(n),to:this.coords.logicalToTime(i)}}setVisibleRange(e){let t=this.coords.timeToLogical(e.from),n=this.coords.timeToLogical(e.to),i=Math.max(1e-6,n-t),o=rn(this.coords.width/(i*this.coords.spacingScale)),s=n-(this.coords.barCount-1);this.applyViewport({barSpacing:o,rightOffset:s});}panBy(e){if(this.coords.barCount===0||this.coords.width===0)return;let t=this.coords.getViewport(),n=this.coords.width/this.coords.pxPerBar(),i=this.scrollTargetRO??t.rightOffset;this.glideRightOffset(this.clampViewport(t.barSpacing,i+e*n).rightOffset);}applyViewport(e){this.animator.stop(),this.panVelocity=0,this.scrollTargetRO=null;let t=this.clampViewport(e.barSpacing,e.rightOffset);this.coords.setViewport(t),this.targetBarSpacing=t.barSpacing,this.scheduler.invalidate(4),this.emitViewportChange();}zoomTo(e,t,n){let i=this.clampViewport(e,this.coords.getViewport().rightOffset).barSpacing;if(this.zoomAnchorLogical=t,this.zoomAnchorX=n,this.panVelocity=0,this.scrollTargetRO=null,!this.animZoom.on){let o=this.clampViewport(i,this.anchoredRightOffset(i));this.coords.setViewport(o),this.targetBarSpacing=o.barSpacing,this.scheduler.invalidate(4),this.emitViewportChange();return}this.targetBarSpacing=i,this.animator.start();}fling(e){this.animPan.on&&(this.scrollTargetRO=null,this.panVelocity=e,this.animator.start());}anchoredRightOffset(e){let t=e*this.coords.spacingScale;return this.zoomAnchorLogical+(this.coords.width-this.zoomAnchorX)/t-(this.coords.barCount-1)}clampViewport(e,t){let n=this.coords.barCount,i=this.coords.width;if(n<=1||i<=0)return {barSpacing:rn(e),rightOffset:t};let o=Math.min(cI,n),s=this.coords.spacingScale,a=Math.min(1e3,i/(o*s)),l=Math.max(.5,Math.min(a,i/((n+Px)*s))),c=Math.max(l,Math.min(a,e)),d=i/(c*s)-(o-1),h=o-n,p=Math.max(h,Math.min(d,t));return {barSpacing:c,rightOffset:p}}animTick(e){let t=this.coords.getViewport(),n=t.barSpacing,i=t.rightOffset,o=false,s=this.targetBarSpacing;Math.abs(n-s)>s*.001?(n=rn(vt(n,s,e,this.animZoom.tau)),i=this.anchoredRightOffset(n),o=true):n!==s&&(n=s,i=this.anchoredRightOffset(n));let a=uI/Math.max(1e-6,n*this.coords.spacingScale);if(Math.abs(this.panVelocity)>a){i+=this.panVelocity*e;let c=this.animPan.tau;this.panVelocity=c>0?this.panVelocity*Math.exp(-e/c):0,Math.abs(this.panVelocity)<=a?this.panVelocity=0:o=true;}if(this.scrollTargetRO!=null){let c=this.scrollTargetRO,u=vt(i,c,e,this.animScroll.tau);Math.abs(u-c)<.001?(i=c,this.scrollTargetRO=null):(i=u,o=true);}let l=this.clampViewport(n,i);return l.barSpacing!==n&&(this.targetBarSpacing=l.barSpacing),this.scrollTargetRO!=null&&l.rightOffset!==i&&(this.scrollTargetRO=l.rightOffset),this.coords.setViewport(l),this.computeScales(),this.easeScales(e)&&(o=true),this.easeLiveBar(e)&&(o=true),this.skeletonClockMs+=e,this.paintData(),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx()),this.updateLegendValues(),this.emitViewportChange(),o}easeScales(e){let t=false,n=this.animAutoscale.tau;for(let i of this.scene.panes.values()){let o=i.scaleTarget,s=i.scale;if(o.log&&s.min>0&&o.min>0){let u=Math.log(o.min),d=Math.log(o.max),h=Math.max(1e-9,Math.abs(d-u)),p=vt(Math.log(s.min),u,e,n),m=vt(Math.log(s.max),d,e,n);Math.abs(p-u)<=h*.001&&Math.abs(m-d)<=h*.001?i.scale={min:o.min,max:o.max,log:true}:(t=true,i.scale={min:Math.exp(p),max:Math.exp(m),log:true});continue}let a=Math.max(1e-9,Math.abs(o.max-o.min)),l=vt(s.min,o.min,e,n),c=vt(s.max,o.max,e,n);Math.abs(l-o.min)<=a*.001&&Math.abs(c-o.max)<=a*.001?(l=o.min,c=o.max):t=true,i.scale={min:l,max:c,log:o.log};}for(let i of this.scene.indicatorScales.values()){let o=i.scaleTarget,s=i.scale,a=Math.max(1e-9,Math.abs(o.max-o.min)),l=vt(s.min,o.min,e,n),c=vt(s.max,o.max,e,n);Math.abs(l-o.min)<=a*.001&&Math.abs(c-o.max)<=a*.001?(l=o.min,c=o.max):t=true,i.scale={min:l,max:c};}return t}emitViewportChange(){this.updateScrollToRealtimeButton();let e=this.getVisibleRange();if(e)for(let t of this.viewportCbs)t(e);}handlePointerMove(e,t){if(e===null||t===null||this.coords.barCount===0){this.scene.crosshair=null,this.hoverSeparatorY=null,this.lastPointer=null,this.marksExpandedBy==="hover"&&this.setMarksExpanded(null),this.setMarkHover(null),this.scheduler.invalidate(1),this.hoverLogical=null;let p={time:null,price:null,paneKind:null,values:new Map,ohlc:null};for(let m of this.crosshairCbs)m(p);return}let n=e>=0&&t>=0&&e<=this.coords.width&&t<=this.coords.height;this.scene.crosshair=n?{x:e,y:t}:null,this.lastPointer=n?{x:e,y:t}:null,this.hoverSeparatorY=e>=0&&t>=0&&t<=this.coords.height?this.separatorHoverY(t):null,this.scheduler.invalidate(1),this.setMarksExpanded(n?this.chrome.markStackAt(e,t):null),this.setMarkHover(n?this.chrome.markGlyphAt(e,t)?.cluster.key??null:null);let i=Math.round(this.coords.xToLogical(e)),o=i>=0&&i<this.coords.barCount,s=o?this.coords.logicalToTime(i):null,a=this.paneNodeAtY(t),l=n&&a?this.coords.yToPrice(t,a.scale,a.bounds):null,c=new Map;if(o)for(let p of this.scene.indicators.values()){let m=this.scene.offsetOf(p.id);for(let f of p.series)if(Fe(f)){let g=f.points[i-m]?.value;g!=null&&c.set(f.id,g);}}let u=o?this.bars[i]:void 0,d=u?{time:u.time,open:u.open,high:u.high,low:u.low,close:u.close,volume:u.volume}:null;this.hoverLogical=o?i:null;let h={time:s,price:l,paneKind:n&&a?a.kind:null,values:c,ohlc:d};for(let p of this.crosshairCbs)p(h);}handleClick(e){if(this.coords.barCount===0)return;let t=Math.round(this.coords.xToLogical(e)),n=t>=0&&t<this.coords.barCount;for(let i of this.clickCbs)i({time:n?this.coords.logicalToTime(t):null,price:null});}setMarksExpanded(e,t="hover"){if(this.scene.marksExpandedStack!==e){if(e===null&&this.markPopover?.key){let n=this.chrome.markGlyphByKey(this.markPopover.key);if(n&&n.stack===this.scene.marksExpandedStack)return}this.scene.marksExpandedStack=e,this.marksExpandedBy=t,this.scheduler?.invalidate(2);}}handleMarkClick(e,t){let n=this.chrome.markGlyphAt(e,t);if(!n)return this.scene.marksExpandedStack!==null&&this.chrome.markStackAt(e,t)===null&&this.setMarksExpanded(null),false;if(n.decked)return this.setMarksExpanded(n.stack,"tap"),true;let i=n.cluster.marks,o=i[0],s={id:o.id,ids:i.map(a=>a.id),time:o.time,...n.cluster.group!==void 0?{group:n.cluster.group}:{}};for(let a of this.markClickCbs)a(s);return i.some(a=>a.content!==void 0)?this.markPopover?.open(n.cluster,{x:n.x,y:n.y,size:n.size}):(this.scene.marksFlash={key:n.cluster.key,until:lp()+dI},this.syncMarkPulse()),true}trackMarkPopover(){let e=this.markPopover?.key;if(!e)return;let t=this.chrome.markGlyphByKey(e);this.markPopover.track(t&&!(t.decked&&t.depth!==0)?{x:t.x,y:t.y,size:t.size}:null);}setMarkHover(e){this.scene.marksHoverKey!==e&&(this.scene.marksHoverKey=e,this.scene.marksHoverSince=lp(),this.scheduler?.invalidate(2),this.syncMarkPulse());}syncMarkPulse(){if(this.markPulseRaf!==null||typeof requestAnimationFrame!="function")return;let e=()=>{this.markPulseRaf=null;let t=lp();this.scene.marksFlash&&this.scene.marksFlash.until<=t&&(this.scene.marksFlash=null),this.scheduler?.invalidate(2),(this.scene.marksHoverKey!==null&&t-this.scene.marksHoverSince<Nc||this.scene.marksFlash!==null)&&(this.markPulseRaf=requestAnimationFrame(e));};this.markPulseRaf=requestAnimationFrame(e);}paneAtY(e){return this.paneNodeAtY(e)}paneNodeAtY(e){for(let t of this.scene.panes.values())if(e>=t.bounds.top&&e<=t.bounds.top+t.bounds.height)return t;return null}nearestPaneToY(e){let t=null,n=1/0;for(let i of this.scene.panes.values()){let o=e<i.bounds.top?i.bounds.top-e:e-(i.bounds.top+i.bounds.height);o<n&&(n=o,t=i);}return t}resolveScaleHolder(e,t){let n=this.paneNodeAtY(t);if(!n)return null;let i=this.coords.width,o=this.scene.ownScaleIndicatorsForPane(n.id);if(e>=i+64&&o.length>0){let s=Math.floor((e-i-64)/56),a=o[s];if(a)return {holder:this.scene.ensureIndicatorScale(a.id,n.scaleTarget),height:n.bounds.height}}return {holder:n,height:n.bounds.height}}beginPriceScale(e,t){let n=this.resolveScaleHolder(e,t);n&&(this.scaleDragHolder=n.holder,this.scaleDragHeight=n.height,this.scaleDragStart={...n.holder.scale},n.holder.manualScale={...n.holder.scale},this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4));}priceScaleBy(e){let t=this.scaleDragHolder,n=this.scaleDragStart;!t||!n||this.setManualScale(t,lx(n,Math.exp(e*hI)));}beginPricePan(e){let t=this.paneNodeAtY(e);return !t||!t.manualScale?false:(this.scaleDragHolder=t,this.scaleDragHeight=t.bounds.height,this.scaleDragStart={...t.scale},true)}pricePanBy(e){let t=this.scaleDragHolder,n=this.scaleDragStart;!t||!n||this.setManualScale(t,cx(n,e,this.scaleDragHeight));}resetPriceScale(e,t){let n=this.resolveScaleHolder(e,t);n&&(n.holder.manualScale=null,this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4));}dataDblClick(e,t){let n=this.paneNodeAtY(t)??this.nearestPaneToY(t);if(!n)return;let i=this.maximizedPaneId!==n.id;this.maximizedPaneId=i?n.id:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:n.id,maximized:i});}resetView(){this.fitContent(),this.scheduler.invalidate(4),this.emitViewportChange();}setManualScale(e,t){e.manualScale=t,e.scale={...t},e.scaleTarget={...t},e.initialized=true,this.scheduler.invalidate(4);}afterPaneLayoutChange(){this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}paneControlViews(){let e=this.scene.orderedPanes();return e.map((t,n)=>({id:t.id,kind:t.kind,collapsed:t.collapsed,maximized:this.maximizedPaneId===t.id,top:t.bounds.top,height:t.bounds.height,index:n,count:e.length}))}movePaneLocal(e,t){let n=this.scene.orderedPanes(),i=n.findIndex(l=>l.id===e);if(i<0)return;let o=t==="up"?i-1:i+1;if(o<1||o>=n.length)return;let s=n.map(l=>l.id),a=s[i];s[i]=s[o],s[o]=a,this.scene.orderPanes(s),this.afterPaneLayoutChange(),this.emitPaneAction({type:"move",paneId:e,dir:t});}paneSeparatorAt(e){return this.separatorPaneIndexAt(e)!==null}separatorHoverY(e){if(!this.paneResizeEnabled)return null;let t=this.separatorPaneIndexAt(e);return t===null?null:this.scene.orderedPanes()[t].bounds.top}separatorPaneIndexAt(e){let t=this.scene.orderedPanes();for(let n=1;n<t.length;n++)if(Math.abs(e-t[n].bounds.top)<=mI)return n;return null}beginPaneResize(e){let t=this.separatorPaneIndexAt(e);if(t===null)return;let n=this.scene.orderedPanes(),i=n[t-1],o=n[t];this.resizeAbove=i,this.resizeBelow=o,this.resizeSplitStart={combinedTop:i.bounds.top,combinedHeight:i.bounds.height+o.bounds.height,combinedWeight:i.heightWeight+o.heightWeight,startBoundaryY:o.bounds.top};}paneResizeBy(e){let t=this.resizeAbove,n=this.resizeBelow,i=this.resizeSplitStart;if(!t||!n||!i)return;let o=ux(i,e);t.heightWeight=o.above,n.heightWeight=o.below,this.layoutPanes(),this.scheduler.invalidate(4);}resetPaneSize(e){let t=this.separatorPaneIndexAt(e);if(t===null)return;let n=this.scene.orderedPanes(),i=n[t-1],o=n[t],s=(i.heightWeight+o.heightWeight)/2;i.heightWeight=s,o.heightWeight=s,this.layoutPanes(),this.scheduler.invalidate(4);}setKeyboardEnabled(e){this.keyboardEnabled=e,!(!this.dataCanvas||!this.keyboard)&&(e?(this.dataCanvas.tabIndex=0,this.dataCanvas.setAttribute("role","application"),this.dataCanvas.setAttribute("aria-label","Interactive price chart. Use Left/Right arrows to move between bars, Shift+Arrow to pan, plus/minus to zoom, Home/End to jump, 0 to reset."),!this.liveRegion&&this.wrapper&&(this.liveRegion=document.createElement("div"),this.liveRegion.setAttribute("aria-live","polite"),this.liveRegion.setAttribute("role","status"),Object.assign(this.liveRegion.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:"0"}),this.wrapper.appendChild(this.liveRegion)),this.keyboard.attach(this.dataCanvas)):(this.keyboard.detach(),this.dataCanvas.removeAttribute("tabindex"),this.dataCanvas.removeAttribute("role"),this.dataCanvas.removeAttribute("aria-label")));}panByBars(e){let t=this.coords.getViewport();this.applyViewport({barSpacing:t.barSpacing,rightOffset:t.rightOffset+e});}zoomByStep(e){let t=this.coords.getViewport(),n=rn(t.barSpacing*Math.exp(e*pI));this.zoomTo(n,this.coords.rightEdgeLogical,this.coords.width);}stepCrosshair(e){let t=this.coords.barCount;if(t===0)return;let n=this.hoverLogical??Math.min(t-1,Math.round(this.coords.xToLogical(this.coords.width)));this.focusBar(n+e);}focusBar(e){let t=this.coords.barCount;if(t===0)return;let n=Math.max(0,Math.min(t-1,e)),i=this.coords.getViewport(),o=2,s=this.coords.xToLogical(0),a=this.coords.xToLogical(this.coords.width),l=i.rightOffset;n<s+o?l-=s+o-n:n>a-o&&(l+=n-(a-o)),l!==i.rightOffset&&this.applyViewport({barSpacing:i.barSpacing,rightOffset:l});let c=this.scene.orderedPanes().find(d=>d.kind==="price")??this.scene.orderedPanes()[0]??null,u=this.scene.crosshair?.y??(c?c.bounds.top+c.bounds.height/2:this.coords.height/2);this.handlePointerMove(this.coords.logicalToX(n),u),this.announceBar(n);}announceBar(e){if(!this.liveRegion)return;let t=this.bars[e],n=this.dataWindowPricePane(),i=this.dataWindowOHLC(t,n),o=[];t&&o.push(bI(t.time,this.scene.timezone)),i&&o.push(`Open ${i.o}, High ${i.h}, Low ${i.l}, Close ${i.c}`);for(let s of this.dataWindowGroups(e,n))for(let a of s.rows)o.push(`${a.label} ${a.value}`);this.liveRegion.textContent=o.join(". ");}getDataWindowReadout(){let e=this.bars.length;if(e===0)return {date:"",time:"",ohlc:null,groups:[]};let t=this.hoverLogical!=null?this.hoverLogical:e-1,n=this.bars[t],i=this.dataWindowPricePane(),o=n?Ox(n.time,this.scene.timezone):{date:"",time:""};return {date:o.date,time:o.time,ohlc:this.dataWindowOHLC(n,i),groups:this.dataWindowGroups(t,i)}}dataWindowPricePane(){return this.scene.orderedPanes().find(e=>e.kind==="price")??null}dataWindowFmt(e,t){return t?Dc(t.scale,t.bounds.height,e,this.scene.priceMintick):String(e)}dataWindowOHLC(e,t){return e?{o:this.dataWindowFmt(e.open,t),h:this.dataWindowFmt(e.high,t),l:this.dataWindowFmt(e.low,t),c:this.dataWindowFmt(e.close,t),vol:e.volume!=null?Rx(e.volume):void 0,up:e.close>=e.open}:null}dataWindowGroups(e,t){let n=[];for(let i of this.scene.indicators.values()){let o=this.readoutRowsFor(i,e,t,"dataWindow");o.length&&n.push({name:i.title,rows:o});}return n}readoutRowsFor(e,t,n,i){if(e.native?.type==="volume")return this.volumeReadoutRows(e,t);let o=(e.paneId?this.scene.panes.get(e.paneId):null)??n,s=this.scene.offsetOf(e.id),a=[];for(let l of e.series){if(!Ct(l,i))continue;let c,u;if(l.kind==="candle"||l.kind==="bar")c=l.bars[t-s]?.close,u=l.style?.up??this.theme.upColor;else if(Fe(l))c=l.points[t-s]?.value,u=l.points[t-s]?.color??l.style.color;else continue;c==null||!Number.isFinite(c)||a.push({label:l.title||e.title,value:this.dataWindowFmt(c,o),color:u});}return a}volumeReadoutRows(e,t){if(this.volumeHidden)return [];let n=this.bars[t],i=n?.volume;if(n==null||i==null||!Number.isFinite(i))return [];let o=this.scene.volumeLayer,s=n.close>=n.open?o?.upColor??this.theme.upColor:o?.downColor??this.theme.downColor;return [{label:e.title,value:Rx(i),color:s}]}updateLegendValues(){if(!this.inputsUI)return;let e=this.bars.length,t=new Map;if(e>0){let n=this.hoverLogical!=null?this.hoverLogical:e-1,i=this.dataWindowPricePane();for(let o of this.scene.indicators.values())t.set(o.id,this.readoutRowsFor(o,n,i,"legend").map(s=>({value:s.value,color:s.color})));}this.inputsUI.setPlotValues(t);}renderFrame(e){this.animator.active||(bh(e)?(this.computeScales(),this.paintData()):Oy(e)&&this.paintedData&&(this.chrome.prepare(this.scene,this.coords,this.theme),this.chrome.render(this.scene,this.coords,this.theme,this.axisSurface()),this.trackMarkPopover()),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx()),!bh(e)&&this.paintedData&&this.repaintCursorLayers(),this.updateLegendValues());}repaintCursorLayers(){let e=this.scene.panes.get(He);if(!e)return;let t=typeof performance<"u"?performance.now():Date.now();for(let n of this.extLayers){if(!n.def.repaintOnCursor)continue;let i=this.layerPane(n)??e;i.collapsed||(n.instance.render(this.extLayerArgs(n,i.scale,i.bounds,t)),this.animZoom.on&&n.instance.animating?.()&&this.animator.start());}}clearLayerCanvas(e){e.width===0||e.height===0||e.getContext("2d")?.clearRect(0,0,e.width,e.height);}extLayerArgs(e,t,n,i){return {bars:this.scene.bars,data:this.scene.nativeData.get(e.channel),settings:this.scene.nativeData.get(`${e.def.id}-settings`)??{},pending:this.scene.nativePending.get(e.channel)??[],coords:this.coords,scale:t,bounds:n,theme:this.theme,priceStyle:this.scene.priceStyle,nowMs:i,cursor:this.lastPointer}}paintData(){this.syncLayerCanvasOrder(),this.stampScaleInvert(),this.backend.modelAlpha=this.modelAlpha,this.backend.candleBodyAlpha=this.candleBodyAlpha,this.backend.candleStructureAlpha=this.candleStructureAlpha;let e=1,t=1;this.backend.candleBodyScale=t;let n=this.scene.panes.get(He);if(n){let a=this.nativeLayerPane("volume")??n;this.volumeRenderer.render({bars:this.scene.bars,data:this.scene.volumeLayer,visible:this.volumeActive&&!this.volumeHidden&&!a.collapsed,coords:this.coords,bounds:a.bounds,fillPane:a.kind!=="price"}),this.vpvrRenderer.render({bars:this.scene.bars,data:this.scene.vpvrLayer,visible:this.vpvrActive&&!this.vpvrHidden,coords:this.coords,scale:n.scale,bounds:n.bounds,theme:this.theme});let l=typeof performance<"u"?performance.now():Date.now(),c=null;for(let u of this.extLayers){let d=this.layerPane(u)??n;if(d.collapsed){this.clearLayerCanvas(u.canvas);continue}let h=this.extLayerArgs(u,d.scale,d.bounds,l);u.instance.render(h),d===n&&(c=hx(c,u.instance.modulateBase?.(h)??null)),this.animZoom.on&&u.instance.animating?.()&&this.animator.start();}c&&(c.candleBodyScale!=null&&(this.backend.candleBodyScale=cp(c.candleBodyScale)||.01),c.candleBodyAlpha!=null&&(this.backend.candleBodyAlpha=cp(c.candleBodyAlpha)*this.candleBodyAlpha),c.gridAlpha!=null&&(e=cp(c.gridAlpha)));}let i=this.bars.length-1,o=i>=0?this.bars[i]:void 0,s=!!o&&this.liveEaseTime===o.time&&(o.high!==this.liveEaseHigh||o.low!==this.liveEaseLow||o.close!==this.liveEaseClose);s&&o&&(this.bars[i]={...o,high:this.liveEaseHigh,low:this.liveEaseLow,close:this.liveEaseClose}),this.scene.drawingSlices=ex(this.indicatorSlices.prepare(this.scene,this.coords,this.theme,this.dataCanvas),this.userDrawings?.prepareSlices(this.scene.orderedPanes().map(a=>a.id))??new Map),this.backdropRenderer.render(this.scene,this.coords,this.theme,e),this.backend.render(this.scene,this.coords,this.theme),this.chrome.render(this.scene,this.coords,this.theme,this.axisSurface()),this.trackMarkPopover(),this.userDrawings?.render(),s&&o&&(this.bars[i]=o),this.paintedData=true;}drawingProjector(){return tx(this.coords,e=>{let t=this.scene.panes.get(e);return t?{scale:t.scale,bounds:t.bounds,collapsed:t.collapsed}:null},e=>this.paneNodeAtY(e)?.id??null,(e,t)=>this.barsInTimeRange(e,t),this.userDrawings?.seriesGateway?(e,t,n)=>this.userDrawings.seriesGateway.seriesInRange(e,t,n):void 0)}barsInTimeRange(e,t){let n=Math.min(e,t),i=Math.max(e,t),o=[];for(let s of this.bars)if(!(s.time<n)){if(s.time>i)break;o.push(s);}return o}get userDrawingsPort(){return this.userDrawings??void 0}focus(){this.dataCanvas?.focus({preventScroll:true});}setExternalCrosshair(e,t=null){let n=e==null?null:{time:e,price:t},i=this.externalCross;!n&&!i||n&&i&&i.time===n.time&&i.price===n.price||(this.externalCross=n,this.scheduler.invalidate(1));}externalCrossPx(){let e=this.externalCross;if(!e||this.coords.barCount===0)return null;let t=Math.floor(this.coords.timeToLogical(e.time));if(t<0||t>=this.coords.barCount)return null;let n=this.coords.logicalToX(t);if(!Number.isFinite(n)||n<0||n>this.coords.width)return null;let i=null;if(e.price!=null){let o=this.scene.orderedPanes().find(s=>s.kind==="price");o&&(i=this.coords.priceToY(e.price,o.scale,o.bounds),(!Number.isFinite(i)||i<o.bounds.top||i>o.bounds.top+o.bounds.height)&&(i=null));}return {x:n,y:i,time:this.coords.logicalToTime(t),price:i!=null?e.price:null}}setSnapMode(e){this.snapMode=e;}snapToCandle(e,t,n="strong",i){if(n==="off")return e;let o=this.bars.length;if(o===0)return e;let s=Math.max(0,Math.min(o-1,Math.round(this.coords.timeToLogical(e.time)))),a=this.bars[s];if(!a)return e;let l;if(t!==He)l={time:a.time,price:e.price};else {let c=a.open;for(let u of [a.high,a.low,a.close])Math.abs(u-e.price)<Math.abs(c-e.price)&&(c=u);l={time:a.time,price:c};}if(n==="weak"&&i){let c=this.drawingProjector(),u=c.yOf(l.price,t);if(Math.hypot(c.xOf(l.time)-i.x,(u??i.y)-i.y)>nI)return e}return l}computeScales(){let e=this.coords.barCount;if(e===0)return;let t=this.coords.visibleLogicalRange(),n=Math.max(0,Math.floor(t.from)),i=Math.min(e-1,Math.ceil(t.to));if(i<n)return;this.scene.percentBaseline=this.bars[n]?.close??0;let o=this.scene.orderedPanes(),s=o.find(l=>l.kind==="price")??null;this.chrome.prepare(this.scene,this.coords,this.theme);let a=this.animator.active;for(let l of o){if(l.manualScale){l.scaleTarget=l.manualScale,l.scale={...l.manualScale},l.initialized=true;continue}let u=this.scene.indicatorsForPane(l.id).filter(p=>p.ownScale!==true),d=this.chrome.paneDrawingsRange(u,this.scene,l===s,t);if(l===s){let p=ox(this.scene.indicators.values(),n,i,m=>this.scene.offsetOf(m));p&&(d=d?{min:Math.min(d.min,p.min),max:Math.max(d.max,p.max)}:p);}let h=l.kind==="price"&&!this.scene.candlesHidden;if(l.scaleTarget=eu(u,this.bars,h,n,i,d,Ri(this.scene,l),p=>this.scene.offsetOf(p)),l.percentBaseline=l.kind==="price"?this.bars[n]?.close??0:this.firstVisibleValue(u,n),l.axisFormat=void 0,l.axisBands=void 0,this.volumeOwnsPane(l,u)){let p=this.maxVisibleVolume(n,i);p>0&&(l.scaleTarget={min:0,max:p/Jh},l.axisFormat="volume");}else if(this.layerNativesOwnPane(l,u)&&(l.scaleTarget=eu([],this.bars,true,n,i,d,Ri(this.scene,l),p=>this.scene.offsetOf(p)),l.percentBaseline=this.bars[n]?.close??0,u.every(p=>p.paneAxis!=null))){l.axisFormat="none";let p=u.find(m=>typeof m.paneAxis=="object");l.axisBands=p?p.paneAxis.bands:void 0;}if(l===s&&this.scene.tradeMarkers.visible&&l.bounds.height>0){let p=this.tradesScaleHints(t);if(p){let m=l.scaleTarget,f={...m,min:Math.min(m.min,p.min),max:Math.max(m.max,p.max)};l.scaleTarget=sx(f,l.bounds.height,p.abovePx,p.belowPx);}}(!a||!l.initialized)&&(l.scale={...l.scaleTarget},l.initialized=true);for(let p of this.scene.ownScaleIndicatorsForPane(l.id)){let m=this.scene.ensureIndicatorScale(p.id,l.scaleTarget);if(m.manualScale){m.scaleTarget=m.manualScale,m.scale={...m.manualScale},m.initialized=true;continue}let f=this.chrome.paneDrawingsRange([p],this.scene,false,t);m.scaleTarget=eu([p],this.bars,false,n,i,f,false,g=>this.scene.offsetOf(g)),(!a||!m.initialized)&&(m.scale={...m.scaleTarget},m.initialized=true);}}}tradesScaleHints(e){let t=null,n={timeToLogical:i=>this.coords.timeToLogical(i),barAt:i=>{let o=this.bars[Math.round(i)];return o?{high:o.high,low:o.low}:null}};for(let i of this.scene.indicators.values()){if(!i.trades?.length)continue;let o=Ky(i.trades,this.scene.tradeMarkers,n,e.from,e.to,this.scene.style.fontSize);o&&(t=t?{min:Math.min(t.min,o.min),max:Math.max(t.max,o.max),abovePx:Math.max(t.abovePx,o.abovePx),belowPx:Math.max(t.belowPx,o.belowPx)}:o);}return t}fitContent(){let e=this.coords.barCount,t=this.coords.width;if(e<=0||t<=0)return;this.animator?.stop(),this.panVelocity=0;for(let s of this.scene.panes.values())s.manualScale=null;for(let s of this.scene.indicatorScales.values())s.manualScale=null;let n=Math.min(e,200),i=6,o=this.clampViewport(t/((n+i)*this.coords.spacingScale),i);this.coords.setViewport(o),this.targetBarSpacing=o.barSpacing;}reframeKeepZoom(){this.animator?.stop(),this.panVelocity=0;for(let t of this.scene.panes.values())t.manualScale=null;for(let t of this.scene.indicatorScales.values())t.manualScale=null;let e={barSpacing:rn(this.coords.getViewport().barSpacing),rightOffset:cs().rightOffset};this.coords.setViewport(e),this.targetBarSpacing=e.barSpacing;}paneBoundsFor(e){let t=this.scene.panes.get(e);return {top:t?.bounds.top??0,height:t?.bounds.height??0,rightAxis:this.rightAxisW}}paneMasterTitle(e){let t=this.scene.orderedIndicatorsForPane(e);return (t.find(i=>i.ownScale!==true)??t[0])?.title||null}nativeLayerPane(e){for(let t of this.scene.indicators.values())if(t.native?.type===e)return this.scene.panes.get(t.paneId??He)??null;return null}createLayerCanvas(){let e=document.createElement("canvas");return Object.assign(e.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),e}ensureInstanceLayer(e){let t=e.native?.channel;if(!t||!this.plot||this.extLayers.some(s=>s.owner===e.id))return;let n=this.extLayers.find(s=>s.owner===null&&s.def.id===e.native.type);if(!n)return;let i=this.createLayerCanvas();i.width=this.dataCanvas.width,i.height=this.dataCanvas.height,i.style.width=this.dataCanvas.style.width||"100%",i.style.height=this.dataCanvas.style.height||"100%";let o={def:n.def,instance:n.def.create(),canvas:i,channel:t,owner:e.id};this.extLayers.push(o),this.plot.insertBefore(i,this.chromeCanvas),o.instance.mount(i);}dropInstanceLayer(e){let t=this.extLayers.findIndex(i=>i.owner===e);if(t<0)return;let[n]=this.extLayers.splice(t,1);n.instance.destroy?.(),n.canvas.remove();}layerOwner(e){if(e.owner!==null)return this.scene.indicators.get(e.owner)??null;for(let t of this.scene.indicators.values())if(t.native?.type===e.def.id&&!t.native.channel)return t;return null}layerPane(e){let t=this.layerOwner(e),n=t?t.paneId??He:He;return this.scene.panes.get(n)??null}orderedLayerCanvases(){let e=new Map(this.extLayers.map(i=>[i.channel,i.canvas])),{below:t,above:n}=px(this.extLayers.map(i=>{let o=this.layerOwner(i);return {id:i.channel,placement:i.def.placement==="below-data"?"below-data":"above-data",ownerZ:o?this.scene.zOf(o.id):null}}),this.scene.candleZ);return {below:t.map(i=>e.get(i)),above:n.map(i=>e.get(i))}}canvasPile(){let{below:e,above:t}=this.orderedLayerCanvases();return [this.backdropCanvas,...e,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...t]}syncLayerCanvasOrder(){if(this.extLayers.length===0||!this.plot)return;let{below:e,above:t}=this.orderedLayerCanvases(),n=[...e.map(i=>this.extLayers.find(o=>o.canvas===i).channel),"|",...t.map(i=>this.extLayers.find(o=>o.canvas===i).channel)].join(",");if(n!==this.layerOrderSig){this.layerOrderSig=n;for(let i of e)this.plot.insertBefore(i,this.dataCanvas);for(let i of t)this.plot.insertBefore(i,this.chromeCanvas);}}volumeOwnsPane(e,t){return e.kind==="price"||!this.volumeActive||this.volumeHidden||!this.scene.volumeLayer||this.nativeLayerPane("volume")!==e?false:t.every(n=>n.native?.type==="volume")}layerNativesOwnPane(e,t){return e.kind==="price"||t.length===0?false:t.every(n=>n.series.length===0&&!!n.native&&this.extLayers.some(i=>i.def.id===n.native.type))}paneScaleInfos(){return this.scene.orderedPanes().map(e=>({id:e.id,kind:e.kind,top:e.bounds.top,height:e.bounds.height,mode:Sh(this.scene,e),log:Ri(this.scene,e),invert:Ch(this.scene,e)}))}axisScaleViews(){return this.scene.orderedPanes().map(e=>({id:e.id,top:e.bounds.top,height:e.bounds.height,collapsed:e.collapsed,auto:e.manualScale==null,log:Ri(this.scene,e)}))}togglePaneAuto(e){let t=this.scene.panes.get(e);t&&(t.manualScale=t.manualScale==null?{...t.scale}:null,this.scheduler?.invalidate(4));}setPaneScaleMode(e,t){if(e===He)this.scene.scaleMode=t;else {let n=this.scene.panes.get(e);if(!n)return;n.scaleMode=t;}this.scheduler?.invalidate(4);}setPaneLog(e,t){let n=e===He?this.scene.orderedPanes().find(i=>i.kind==="price"):this.scene.panes.get(e);if(e===He)this.scene.logScale=t;else {if(!n)return;n.logScale=t;}n?.manualScale&&(n.manualScale.log=t),this.scheduler?.invalidate(4);}setPaneInvert(e,t){if(e===He)this.scene.invertScale=t;else {let n=this.scene.panes.get(e);if(!n)return;n.invert=t;}this.scheduler?.invalidate(4);}stampScaleInvert(){for(let e of this.scene.panes.values()){let t=Ch(this.scene,e);e.scale.invert=t,e.scaleTarget.invert=t,e.manualScale&&(e.manualScale.invert=t);for(let n of this.scene.ownScaleIndicatorsForPane(e.id)){let i=this.scene.indicatorScales.get(n.id);i&&(i.scale.invert=t,i.scaleTarget.invert=t,i.manualScale&&(i.manualScale.invert=t));}}}firstVisibleValue(e,t){for(let n of e){let i=this.scene.offsetOf(n.id);for(let o of n.series)if(o.overlay!==true){if(Fe(o)){let s=o.points[t-i]?.value;if(s!=null&&Number.isFinite(s))return s}else if(o.kind==="candle"||o.kind==="bar"){let s=o.bars[t-i];if(s&&Number.isFinite(s.close))return s.close}}}return 0}maxVisibleVolume(e,t){let n=0;for(let i=e;i<=t;i+=1){let o=this.bars[i]?.volume;o!=null&&o>n&&(n=o);}return n}layoutPanes(){let e=this.scene.orderedPanes(),t=this.coords.height;this.inputsUI?.setCollapsedPanes(this.collapsedMasterMap());let n=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null;if(n){let u=0;for(let d of e)d===n?d.bounds={top:0,height:t}:d.bounds={top:t,height:0},u+=d.bounds.height;this.inputsUI?.reposition(),this.paneControls?.reposition(),this.axisScaleButtons?.reposition(),this.repositionScrollButton(),this.positionAttribution(),this.publishPricePaneBounds();return}let i=e.filter(u=>u.collapsed),o=e.filter(u=>!u.collapsed),s=i.length*Lx,a=Math.max(0,t-s),l=o.reduce((u,d)=>u+(d.heightWeight||1),0)||1,c=0;for(let u of e){let d=u.collapsed?Lx:a*(u.heightWeight||1)/l;u.bounds={top:c,height:d},c+=d;}this.inputsUI?.reposition(),this.paneControls?.reposition(),this.axisScaleButtons?.reposition(),this.repositionScrollButton(),this.positionAttribution(),this.publishPricePaneBounds();}repositionScrollButton(){let e=this.coords.height;if(e<=0)return;let t=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null,n=t?[t]:this.scene.orderedPanes().filter(o=>!o.collapsed),i=n.length?Math.max(...n.map(o=>o.bounds.top+o.bounds.height)):e;this.scrollBtnBottomPx=ap+Math.max(0,e-i),this.mountContainer?.style.setProperty("--vela-bottom-gutter",`${Hi+Math.max(0,e-i)}px`),this.scrollBtnRightPx=this.rightAxisW+Dx,this.scrollButton&&(this.scrollButton.style.bottom=`${this.scrollBtnBottomPx}px`,this.scrollButton.style.right=`${this.scrollBtnRightPx}px`);}collapsedMasterMap(){let e=new Map;for(let t of this.scene.panes.values()){if(!t.collapsed)continue;let n=this.scene.orderedIndicatorsForPane(t.id).filter(s=>s.legend!==false),i=new Set(this.scene.ownScaleIndicatorsForPane(t.id).map(s=>s.id)),o=n.find(s=>!i.has(s.id))??n[0];e.set(t.id,o?.id??null);}return e}setToolbarGutter(e){e!==this.toolbarGutter&&(this.toolbarGutter=e,this.publishGutters(),this.positionAttribution(),this.syncSize());}publishGutters(){this.mountContainer?.style.setProperty("--vela-toolbar-gutter",`${this.toolbarGutter}px`),this.mountContainer?.style.setProperty("--vela-scale-gutter",`${this.rightAxisW}px`);}publishPricePaneBounds(){if(!this.mountContainer)return;let e=this.coords.height+Hi,t=this.scene.panes.get(He),n=t?t.bounds.top:0,i=t?t.bounds.height:this.coords.height,o=Math.max(0,e-(n+i));this.mountContainer.style.setProperty("--vela-price-pane-top",`${n}px`),this.mountContainer.style.setProperty("--vela-price-pane-bottom",`${o}px`);}buildAttributionEl(){return this.attributionHtml!==null?bx(document,this.attributionHtml,this.theme.background):vx(document,this.theme.background)}rebuildAttribution(){this.attributionEl&&(this.attributionEl.remove(),this.attributionEl=this.buildAttributionEl(),this.attributionEnabled||(this.attributionEl.style.display="none"),this.positionAttribution(),this.wrapper.appendChild(this.attributionEl));}positionAttribution(){if(!this.attributionEl)return;let e=this.coords?.height??0,t=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null,n=t?[t]:this.scene.orderedPanes().filter(o=>!o.collapsed),i=e>0&&n.length?Math.max(...n.map(o=>o.bounds.top+o.bounds.height)):e;Object.assign(this.attributionEl.style,{left:`${(this.toolbarGutter||0)+12}px`,bottom:`${Hi+10+Math.max(0,e-i)}px`});}refreshAttributionColor(){this.attributionEl&&(this.attributionHtml!==null?this.attributionEl.style.color=np(this.theme.background):rp(this.attributionEl,this.theme.background));}syncSize(){let e=this.wrapper.clientWidth,t=this.wrapper.clientHeight;if(e<=0||t<=0)return;let n=window.devicePixelRatio||1;this.plot.style.left=`${this.toolbarGutter}px`;let i=this.plot.getBoundingClientRect(),o=Math.max(1,Math.round(i.width*n)),s=Math.max(1,Math.round(i.height*n)),a=this.plotDeviceSize;a&&Math.abs(a.width-i.width*n)<=1&&Math.abs(a.height-i.height*n)<=1&&(o=Math.max(1,a.width),s=Math.max(1,a.height));let l=o/n,c=s/n,u=d=>{d.width=o,d.height=s,d.style.width=`${l}px`,d.style.height=`${c}px`;};u(this.dataCanvas),u(this.backdropCanvas),u(this.volumeCanvas);for(let d of this.extLayers)u(d.canvas);u(this.vpvrCanvas),u(this.chromeCanvas),u(this.drawingsCanvas),u(this.cursorCanvas),this.coords.setSize(Math.max(1,l-this.rightAxisW),Math.max(1,c-Hi),n),this.scene.crosshair=null,this.layoutPanes(),this.userDrawings?.onResize(),!this.didInitialFit&&this.coords.barCount>0&&(this.fitContent(),this.didInitialFit=true),this.animator.active?(this.computeScales(),this.paintData(),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx())):this.scheduler.flushNow(4);}applyBackground(){this.wrapper.style.background=this.theme.background;}};function fI(r,e){for(let t of r.series){let n=t.kind==="candle"||t.kind==="bar"?t.bars:Fe(t)?t.points:null;if(!n||n.length===0)continue;let i=0,o=n.length;for(;i<o;){let s=i+o>>1;n[s].time<e?i=s+1:o=s;}return i}return null}function gI(r,e){if(e.kind==="value"){for(let t of e.series){let n=r.series.find(i=>i.id===t.seriesId);n&&(t.kind==="points"&&Fe(n)?n.points=t.points:t.kind==="bars"&&(n.kind==="candle"||n.kind==="bar")&&(n.bars=t.bars));}e.lines&&(r.lines=e.lines),e.boxes&&(r.boxes=e.boxes),e.labels&&(r.labels=e.labels),e.polylines&&(r.polylines=e.polylines),e.linefills&&(r.linefills=e.linefills),e.tables&&(r.tables=e.tables),e.trades&&(r.trades=e.trades);return}for(let t of e.removed){let n=r.series.findIndex(i=>i.id===t);n>=0&&r.series.splice(n,1);}for(let t of e.added)r.series.push(t);}function Ox(r,e){let t=Pc(r,e),n=i=>i<10?`0${i}`:String(i);return {date:`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())}`,time:`${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}}function bI(r,e){let{date:t,time:n}=Ox(r,e);return `${t} ${n}`}function vI(r){if(!Array.isArray(r))return [];let e=[];for(let t of r){if(!t||typeof t!="object")continue;let n=t,i=Number(n.from),o=Number(n.to);!Number.isFinite(i)||!Number.isFinite(o)||o<=i||e.push({from:i,to:o,color:typeof n.color=="string"?n.color:"rgba(120,130,160,0.10)"});}return e.sort((t,n)=>t.from-n.from)}function yI(r){if(r==null||typeof r!="object")return null;let e=r,t=n=>{if(!Array.isArray(n))return [];let i=[];for(let o of n){if(!Array.isArray(o))continue;let s=Number(o[0]),a=Number(o[1]);Number.isFinite(s)&&Number.isFinite(a)&&a>s&&i.push([s,a]);}return i.sort((o,s)=>o[0]-s[0])};return {pre:t(e.pre),post:t(e.post),extended:t(e.extended)}}function cp(r){return Math.max(0,Math.min(1,r))}function wI(r){return typeof r=="string"&&Pi().includes(r)}function Ax(r){return r==="percent"||r==="indexed"?r:"price"}function Rx(r){let e=Math.abs(r);return e>=1e9?`${(r/1e9).toFixed(2)}B`:e>=1e6?`${(r/1e6).toFixed(2)}M`:e>=1e3?`${(r/1e3).toFixed(2)}K`:r.toFixed(2)}function xI(r){let e=[...r].sort((n,i)=>n.time-i.time),t=[];for(let n of e){let i=t[t.length-1];i&&i.time===n.time?t[t.length-1]=n:t.push(n);}return t}function up(r,e){let t=(r.open+r.high+r.low+r.close)/4,n=e?(e.open+e.close)/2:(r.open+r.close)/2;return {time:r.time,open:n,high:Math.max(r.high,n,t),low:Math.min(r.low,n,t),close:t,...r.volume!=null?{volume:r.volume}:{}}}function Nx(r){let e=new Array(r.length),t;for(let n=0;n<r.length;n+=1)t=up(r[n],t),e[n]=t;return e}var SI={full:Nx,next:up};function Fx(){_u({id:"heikinashi",label:"Heikin Ashi",barTransform:SI});}var dp=z,hp=W,pp=20;function CI(r,e){return typeof r=="number"&&Number.isFinite(r)?r:e}function Vx(r,e){return typeof r=="string"&&r!==""?r:e}function lu(r){return {upColor:Vx(r.upColor,dp),downColor:Vx(r.downColor,hp),heightFrac:Math.min(.5,Math.max(.05,CI(r.heightPct,pp)/100))}}var mp=class{constructor(){this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(lu(t));}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(lu(e));}suspend(){}resume(){this.ctx?.pushData(lu(this.inputs));}stop(){}},_x={type:"volume",title:"Volume",paneHint:"price",overlay:true,inputsSchema:()=>[{key:"upColor",title:"Up color",type:"color",defval:dp},{key:"downColor",title:"Down color",type:"color",defval:hp},{key:"heightPct",title:"Height %",type:"int",defval:pp,min:5,max:50,step:1,tooltip:"Pane height the tallest visible bar occupies"}],defaultInputs:()=>({upColor:dp,downColor:hp,heightPct:pp}),create:()=>new mp};function fp(){Pn(_x);}var bp=24,vp=30,yp=Ke,wp=W,xp=70;function gp(r,e){return typeof r=="number"&&Number.isFinite(r)?r:e}function Bx(r,e){return typeof r=="string"&&r!==""?r:e}function cu(r){return {rows:Math.round(Math.min(400,Math.max(2,gp(r.rows,bp)))),widthFrac:Math.min(.9,Math.max(.05,gp(r.widthPct,vp)/100)),upColor:Bx(r.upColor,yp),downColor:Bx(r.downColor,wp),showPoc:r.showPoc!==false,valueAreaFrac:Math.min(1,Math.max(0,gp(r.valueAreaPct,xp)/100))}}var Sp=class{constructor(){this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(cu(t));}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(cu(e));}suspend(){}resume(){this.ctx?.pushData(cu(this.inputs));}stop(){}},Hx={type:"vpvr",title:"Visible Range Volume Profile",shortTitle:"VRVP",paneHint:"price",overlay:true,inputsSchema:()=>[{key:"rows",title:"Rows",type:"int",defval:bp,min:2,max:400,step:1},{key:"widthPct",title:"Width %",type:"int",defval:vp,min:5,max:90,step:1,tooltip:"Pane width the largest row occupies"},{key:"upColor",title:"Up color",type:"color",defval:yp},{key:"downColor",title:"Down color",type:"color",defval:wp},{key:"showPoc",title:"Point of control",type:"bool",defval:true},{key:"valueAreaPct",title:"Value area %",type:"int",defval:xp,min:0,max:100,step:1}],defaultInputs:()=>({rows:bp,widthPct:vp,upColor:yp,downColor:wp,showPoc:true,valueAreaPct:xp}),create:()=>new Sp};function Cp(){Pn(Hx);}function Jn(r){let e=r.title.trim().toLowerCase().replace(/\s+/g,"-");return `${r.instanceId}:${r.kind}:${e}#${r.ordinal}`}function I(r,e,t){let n=r[e];return typeof n=="number"&&Number.isFinite(n)?n:t}function F(r,e,t){let n=r[e];return typeof n=="string"&&n!==""?n:t}function kp(r,e,t){let n=r[e];return typeof n=="boolean"?n:t}function TI(r,e,t){let n=new Array(r.length);for(let i=0;i<r.length;i++){let o=e[i],s={time:r[i].time,value:o!=null&&Number.isFinite(o)?o:null},a=t?.[i];a!=null&&(s.color=a),n[i]=s;}return n}var Tp=class{constructor(e){this.spec=e;this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,this.recompute();}onBars(){this.recompute();}onViewport(){}setInputs(e){this.inputs=e,this.ctx&&this.recompute();}suspend(){}resume(){this.recompute();}stop(){}recompute(){if(!this.ctx)return;let e=this.ctx.bars(),t=this.spec.compute(e,this.inputs),n=this.spec.type,i=[],o=new Map;t.plots.forEach((c,u)=>{let d=c.kind??"line",h=Jn({instanceId:n,kind:d,title:c.title,ordinal:u});o.set(c.key,h),i.push({id:h,title:c.title,paneId:"",kind:d,points:TI(e,c.values,c.colors),style:{color:c.color,width:c.width??1,lineStyle:c.lineStyle??"solid",...c.base!=null?{base:c.base}:{}},...c.overlay?{overlay:true}:{}});}),t.markers&&t.markers.length>0&&i.push({id:Jn({instanceId:n,kind:"markers",title:"markers",ordinal:0}),title:this.spec.shortTitle??this.spec.title,paneId:"",kind:"markers",markers:t.markers});let s=(t.bands??[]).flatMap((c,u)=>{let d=o.get(c.from),h=o.get(c.to);return !d||!h?[]:[{id:Jn({instanceId:n,kind:"fill",title:c.key,ordinal:u}),paneId:"",fromSeriesId:d,toSeriesId:h,color:c.color}]}),a=(t.levels??[]).map((c,u)=>({id:Jn({instanceId:n,kind:"hline",title:c.key,ordinal:u}),paneId:"",price:c.price,...c.color!=null?{color:c.color}:{},lineStyle:c.lineStyle??"dashed",width:1,...c.title!=null?{title:c.title}:{}})),l=(t.polylines??[]).map((c,u)=>{let{key:d,...h}=c;return {id:Jn({instanceId:n,kind:"polyline",title:d,ordinal:u}),paneId:"",...h}});this.ctx.emit({series:i,fills:s,priceLines:a,polylines:l}),this.ctx.setStatus("idle");}};function zx(r){return {type:r.type,title:r.title,...r.shortTitle!=null?{shortTitle:r.shortTitle}:{},paneHint:r.overlay?"price":"new",overlay:r.overlay,multiInstance:true,inputsSchema:()=>r.inputs,defaultInputs:()=>Object.fromEntries(r.inputs.map(e=>[e.key,e.defval])),create:()=>new Tp(r)}}var $x=["Close","Open","High","Low","HL2","HLC3","OHLC4","HLCC4"];function ee(r,e){let t=new Array(r.length);for(let n=0;n<r.length;n++){let i=r[n];switch(e){case "Open":t[n]=i.open;break;case "High":t[n]=i.high;break;case "Low":t[n]=i.low;break;case "HL2":t[n]=(i.high+i.low)/2;break;case "HLC3":t[n]=(i.high+i.low+i.close)/3;break;case "OHLC4":t[n]=(i.open+i.high+i.low+i.close)/4;break;case "HLCC4":t[n]=(i.high+i.low+i.close+i.close)/4;break;default:t[n]=i.close;}}return t}function xt(r){return r.map(e=>e.volume!=null&&Number.isFinite(e.volume)?e.volume:Number.NaN)}function Ue(r){return r.map(e=>e.high)}function Ye(r){return r.map(e=>e.low)}function Oe(r){return r.map(e=>e.close)}function Wx(r){return r.map(e=>e.open)}function K(r,e,t){let n=new Array(r.length);for(let i=0;i<r.length;i++){let o=r[i],s=e[i];n[i]=Number.isFinite(o)&&Number.isFinite(s)?t(o,s):Number.NaN;}return n}function ae(r,e){let t=new Array(r.length);for(let n=0;n<r.length;n++){let i=r[n];t[n]=Number.isFinite(i)?e(i):Number.NaN;}return t}function ke(r,e){return K(r,e,(t,n)=>t-n)}function Ln(r,e,t){let n=new Array(r.length).fill(Number.NaN);if(e<=0)return n;let i=0;for(let o=0;o<r.length;o++)i=Number.isFinite(r[o])?i+1:0,i>=e&&(n[o]=t(r,o-e+1,o));return n}function xe(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let s=n;s<=i;s++)o+=t[s];return o})}function ge(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let s=n;s<=i;s++)o+=t[s];return o/e})}function uu(r,e){let t=e*(e+1)/2;return Ln(r,e,(n,i,o)=>{let s=0;for(let a=i;a<=o;a++)s+=n[a]*(a-i+1);return s/t})}function Gx(r,e,t){let n=K(r,e,(i,o)=>i*o);return K(xe(n,t),xe(e,t),(i,o)=>o>0?i/o:Number.NaN)}function sn(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let l=n;l<=i;l++)o+=t[l];let s=o/e,a=0;for(let l=n;l<=i;l++){let c=t[l]-s;a+=c*c;}return Math.sqrt(a/e)})}function ct(r,e){return Ln(r,e,(t,n,i)=>{let o=-1/0;for(let s=n;s<=i;s++)t[s]>o&&(o=t[s]);return o})}function St(r,e){return Ln(r,e,(t,n,i)=>{let o=1/0;for(let s=n;s<=i;s++)t[s]<o&&(o=t[s]);return o})}function Ux(r,e){return Ln(r,e,(t,n,i)=>{let o=-1/0,s=i;for(let a=n;a<=i;a++)t[a]>=o&&(o=t[a],s=a);return i-s})}function Yx(r,e){return Ln(r,e,(t,n,i)=>{let o=1/0,s=i;for(let a=n;a<=i;a++)t[a]<=o&&(o=t[a],s=a);return i-s})}function Kx(r,e,t){let n=new Array(r.length).fill(Number.NaN),i=0,o=Number.NaN;for(let s=0;s<r.length;s++){let a=r[s];if(!Number.isFinite(a)){i=0,o=Number.NaN;continue}if(i+=1,Number.isFinite(o))o=t*a+(1-t)*o,n[s]=o;else if(i>=e){let l=0;for(let c=s-e+1;c<=s;c++)l+=r[c];o=l/e,n[s]=o;}}return n}function Q(r,e){return Kx(r,e,2/(e+1))}function Pe(r,e){return Kx(r,e,1/e)}function ze(r,e=1){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n],o=r[n-e];Number.isFinite(i)&&Number.isFinite(o)&&(t[n]=i-o);}return t}function Vt(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n],o=r[n-e];Number.isFinite(i)&&Number.isFinite(o)&&o!==0&&(t[n]=100*(i-o)/o);}return t}function ot(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=0;n<r.length;n++){let i=n-e;i>=0&&i<r.length&&(t[n]=r[i]);}return t}function Qn(r){let e=new Array(r.length).fill(Number.NaN);for(let t=0;t<r.length;t++){let n=r[t];if(t===0){e[t]=n.high-n.low;continue}let i=r[t-1].close;e[t]=Math.max(n.high-n.low,Math.abs(n.high-i),Math.abs(n.low-i));}return e}function Hr(r,e){return Pe(Qn(r),e)}function Ls(r,e){let t=ze(r),n=ae(t,o=>Math.max(o,0)),i=ae(t,o=>Math.max(-o,0));return K(Pe(n,e),Pe(i,e),(o,s)=>s===0?100:100-100/(1+o/s))}function du(r,e,t,n){let i=ct(e,n),o=St(t,n),s=new Array(r.length).fill(Number.NaN);for(let a=0;a<r.length;a++){let l=r[a],c=i[a],u=o[a];!Number.isFinite(l)||!Number.isFinite(c)||!Number.isFinite(u)||(s[a]=c===u?50:100*(l-u)/(c-u));}return s}function hu(r,e){let t=(e-1)*e/2,n=(e-1)*e*(2*e-1)/6,i=e*n-t*t;return Ln(r,e,(o,s,a)=>{let l=0,c=0;for(let h=s;h<=a;h++){let p=h-s;l+=o[h],c+=p*o[h];}let u=i===0?0:(e*c-t*l)/i;return (l-u*t)/e+u*(e-1)})}function pu(r){let e=new Array(r.length).fill(Number.NaN);for(let t=3;t<r.length;t++){let n=r[t-3],i=r[t-2],o=r[t-1],s=r[t];Number.isFinite(n)&&Number.isFinite(i)&&Number.isFinite(o)&&Number.isFinite(s)&&(e[t]=(n+2*i+2*o+s)/6);}return e}function Xx(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n];if(!Number.isFinite(i))continue;let o=0,s=0;for(let a=n-e;a<n;a++){let l=r[a];if(!Number.isFinite(l)){s=-1;break}s+=1,l<=i&&(o+=1);}s===e&&(t[n]=100*o/e);}return t}function Ms(r){let e=new Array(r.length).fill(Number.NaN),t=0,n=false;for(let i=0;i<r.length;i++){let o=r[i];Number.isFinite(o)&&(t+=o,n=true),n&&(e[i]=t);}return e}function D(r,e="length",t="Length",n=5e3){return {key:e,title:t,type:"int",defval:r,min:1,max:n,step:1}}function be(r="Close"){return {key:"source",title:"Source",type:"string",defval:r,options:$x}}function X(r=_,e="Color",t="color"){return {key:t,title:e,type:"color",defval:r}}function Mn(r,e=.08){let t=/^#([0-9a-f]{6})$/i.exec(r.trim());if(!t)return r;let n=Math.round(e*255).toString(16).padStart(2,"0");return `#${t[1]}${n}`}var kI=["SMA","EMA","WMA","RMA","VWMA"],jx={key:"offset",title:"Offset",type:"int",defval:0,min:-500,max:500,step:1};function qx(r,e,t,n){return {type:r,title:e,shortTitle:t,overlay:true,inputs:[D(20),be(),jx,X()],compute:(i,o)=>{let s=I(o,"length",20),a=n(ee(i,F(o,"source","Close")),s),l=Math.trunc(I(o,"offset",0));return l!==0&&(a=ot(a,l)),{plots:[{key:t.toLowerCase(),title:t,values:a,color:F(o,"color",_),width:2}]}}}}var EI=qx("sma","Simple Moving Average","SMA",ge),LI=qx("ema","Exponential Moving Average","EMA",Q),MI={type:"moving-average",title:"Moving Average",shortTitle:"MA",overlay:true,inputs:[{key:"maType",title:"Type",type:"string",defval:"SMA",options:kI},D(20),be(),jx,X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","Close")),i=F(e,"maType","SMA"),o;switch(i){case "EMA":o=Q(n,t);break;case "WMA":o=uu(n,t);break;case "RMA":o=Pe(n,t);break;case "VWMA":o=Gx(n,xt(r),t);break;default:o=ge(n,t);}let s=Math.trunc(I(e,"offset",0));return s!==0&&(o=ot(o,s)),{plots:[{key:"ma",title:i,values:o,color:F(e,"color",_),width:2}]}}},PI={type:"rma",title:"Smoothed Moving Average",shortTitle:"RMA",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"rma",title:"RMA",values:Pe(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}]})},II={type:"zlema",title:"Zero-Lag Exponential Moving Average",shortTitle:"ZLEMA",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>{let t=I(e,"length",14),n=ee(r,F(e,"source","Close")),i=Math.floor((t-1)/2),o=ot(n,i),s=K(n,o,(a,l)=>2*a-l);return {plots:[{key:"zlema",title:"ZLEMA",values:Q(s,t),color:F(e,"color",_),width:2}]}}},AI={type:"vidya",title:"Variable Index Dynamic Average",shortTitle:"VIDYA",overlay:true,inputs:[D(14),{key:"cmoLength",title:"Momentum length",type:"int",defval:9,min:1,max:500,step:1},be(),X()],compute:(r,e)=>{let t=I(e,"length",14),n=I(e,"cmoLength",9),i=ee(r,F(e,"source","Close")),o=ze(i),s=new Array(i.length).fill(Number.NaN),a=new Array(i.length).fill(Number.NaN);for(let d=n;d<i.length;d++){let h=0,p=0,m=true;for(let f=d-n+1;f<=d;f++){let g=o[f];if(!Number.isFinite(g)){m=false;break}g>0?h+=g:p-=g;}m&&(s[d]=h,a[d]=p);}let l=2/(t+1),c=new Array(i.length).fill(Number.NaN),u=Number.NaN;for(let d=0;d<i.length;d++){let h=i[d],p=s[d],m=a[d];if(!Number.isFinite(h)||!Number.isFinite(p)||!Number.isFinite(m))continue;let f=p+m,g=f===0?0:Math.abs((p-m)/f);u=Number.isFinite(u)?l*g*h+(1-l*g)*u:h,c[d]=u;}return {plots:[{key:"vidya",title:"VIDYA",values:c,color:F(e,"color",_),width:2}]}}},RI={type:"ma-envelope",title:"Moving Average Envelope",shortTitle:"MA Env",overlay:true,inputs:[{key:"maType",title:"Type",type:"string",defval:"SMA",options:["SMA","EMA"]},D(20),be(),{key:"percent",title:"Percent",type:"float",defval:2.5,min:.01,max:50,step:.1},X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","Close")),i=F(e,"maType","SMA")==="EMA"?Q(n,t):ge(n,t),o=I(e,"percent",2.5)/100,s=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:i,color:s,width:2},{key:"upper",title:"Upper",values:ae(i,a=>a*(1+o)),color:s},{key:"lower",title:"Lower",values:ae(i,a=>a*(1-o)),color:s}],bands:[{key:"envelope",from:"upper",to:"lower",color:Mn(s)}]}}},DI={type:"linear-regression",title:"Linear Regression Curve",shortTitle:"LinReg",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"linreg",title:"LinReg",values:hu(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}]})},Zx=[EI,LI,MI,PI,II,AI,RI,DI];function Ep(r,e){let t=I(e,"length",20),n=I(e,"mult",2),i=ee(r,F(e,"source","Close")),o=ge(i,t),s=ae(sn(i,t),a=>a*n);return {basis:o,upper:K(o,s,(a,l)=>a+l),lower:K(o,s,(a,l)=>a-l)}}var Lp=[D(20),be(),{key:"mult",title:"StdDev",type:"float",defval:2,min:.1,max:50,step:.1}],OI={type:"bollinger-bands",title:"Bollinger Bands",shortTitle:"BB",overlay:true,inputs:[...Lp,X()],compute:(r,e)=>{let{basis:t,upper:n,lower:i}=Ep(r,e),o=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:t,color:ue},{key:"upper",title:"Upper",values:n,color:o},{key:"lower",title:"Lower",values:i,color:o}],bands:[{key:"bb",from:"upper",to:"lower",color:Mn(o)}]}}},NI={type:"percent-b",title:"Bollinger Bands %B",shortTitle:"%B",overlay:false,inputs:[...Lp,X()],compute:(r,e)=>{let{upper:t,lower:n}=Ep(r,e);return {plots:[{key:"pb",title:"%B",values:ee(r,F(e,"source","Close")).map((s,a)=>{let l=t[a],c=n[a];return Number.isFinite(l)&&Number.isFinite(c)&&l!==c?(s-c)/(l-c):Number.NaN}),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:1,color:J},{key:"middle",price:.5,color:J,lineStyle:"dotted"},{key:"lower",price:0,color:J}]}}},FI={type:"bandwidth",title:"Bollinger Bands Width",shortTitle:"BandWidth",overlay:false,inputs:[...Lp,X()],compute:(r,e)=>{let{basis:t,upper:n,lower:i}=Ep(r,e);return {plots:[{key:"bbw",title:"BBW",values:t.map((s,a)=>{let l=n[a],c=i[a];return Number.isFinite(s)&&s!==0&&Number.isFinite(l)&&Number.isFinite(c)?(l-c)/s*100:Number.NaN}),color:F(e,"color",_),width:2}]}}},VI={type:"keltner-channels",title:"Keltner Channels",shortTitle:"KC",overlay:true,inputs:[D(20),{key:"mult",title:"Multiplier",type:"float",defval:2,min:.1,max:50,step:.1},{key:"atrLength",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},be(),X()],compute:(r,e)=>{let t=I(e,"length",20),n=I(e,"mult",2),i=Q(ee(r,F(e,"source","Close")),t),o=ae(Hr(r,I(e,"atrLength",10)),a=>a*n),s=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:i,color:ue},{key:"upper",title:"Upper",values:K(i,o,(a,l)=>a+l),color:s},{key:"lower",title:"Lower",values:K(i,o,(a,l)=>a-l),color:s}],bands:[{key:"kc",from:"upper",to:"lower",color:Mn(s)}]}}},_I={type:"donchian-channels",title:"Donchian Channels",shortTitle:"DC",overlay:true,inputs:[D(20),X()],compute:(r,e)=>{let t=I(e,"length",20),n=ct(Ue(r),t),i=St(Ye(r),t),o=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:K(n,i,(s,a)=>(s+a)/2),color:ue},{key:"upper",title:"Upper",values:n,color:o},{key:"lower",title:"Lower",values:i,color:o}],bands:[{key:"dc",from:"upper",to:"lower",color:Mn(o)}]}}},BI={type:"chandelier-exit",title:"Chandelier Exit",shortTitle:"CE",overlay:true,inputs:[D(22),{key:"mult",title:"ATR multiplier",type:"float",defval:3,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"length",22),n=ae(Hr(r,t),s=>s*I(e,"mult",3)),i=K(ct(Ue(r),t),n,(s,a)=>s-a),o=K(St(Ye(r),t),n,(s,a)=>s+a);return {plots:[{key:"long",title:"Long stop",values:i,color:z},{key:"short",title:"Short stop",values:o,color:W}]}}},HI={type:"chande-kroll-stop",title:"Chande Kroll Stop",shortTitle:"CKS",overlay:true,inputs:[{key:"p",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},{key:"x",title:"ATR multiplier",type:"float",defval:1,min:.1,max:50,step:.1},{key:"q",title:"Stop length",type:"int",defval:9,min:1,max:500,step:1}],compute:(r,e)=>{let t=I(e,"p",10),n=I(e,"x",1),i=I(e,"q",9),o=ae(Hr(r,t),l=>l*n),s=K(ct(Ue(r),t),o,(l,c)=>l-c),a=K(St(Ye(r),t),o,(l,c)=>l+c);return {plots:[{key:"stopShort",title:"Stop short",values:ct(s,i),color:W},{key:"stopLong",title:"Stop long",values:St(a,i),color:z}]}}},zI={type:"supertrend",title:"SuperTrend",shortTitle:"SuperTrend",overlay:true,inputs:[{key:"atrLength",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},{key:"mult",title:"Factor",type:"float",defval:3,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"atrLength",10),n=I(e,"mult",3),i=Hr(r,t),o=r.length,s=new Array(o).fill(Number.NaN),a=new Array(o).fill(1),l=Number.NaN,c=Number.NaN,u=1;for(let h=0;h<o;h++){let p=i[h];if(!Number.isFinite(p))continue;let m=r[h],f=(m.high+m.low)/2,g=f-n*p,b=f+n*p,y=h>0?r[h-1].close:m.close;l=Number.isFinite(l)&&y>l?Math.max(g,l):g,c=Number.isFinite(c)&&y<c?Math.min(b,c):b,u===1&&m.close<l?u=-1:u===-1&&m.close>c&&(u=1),a[h]=u,s[h]=u===1?l:c;}let d=a.map((h,p)=>Number.isFinite(s[p])?h===1?z:W:null);return {plots:[{key:"st",title:"SuperTrend",values:s,color:z,width:2,colors:d}]}}},$I={type:"williams-alligator",title:"Williams Alligator",shortTitle:"Alligator",overlay:true,inputs:[{key:"jawLength",title:"Jaw length",type:"int",defval:13,min:1,max:500,step:1},{key:"teethLength",title:"Teeth length",type:"int",defval:8,min:1,max:500,step:1},{key:"lipsLength",title:"Lips length",type:"int",defval:5,min:1,max:500,step:1},{key:"jawOffset",title:"Jaw offset",type:"int",defval:8,min:0,max:100,step:1},{key:"teethOffset",title:"Teeth offset",type:"int",defval:5,min:0,max:100,step:1},{key:"lipsOffset",title:"Lips offset",type:"int",defval:3,min:0,max:100,step:1}],compute:(r,e)=>{let t=ee(r,"HL2"),n=ot(Pe(t,I(e,"jawLength",13)),I(e,"jawOffset",8)),i=ot(Pe(t,I(e,"teethLength",8)),I(e,"teethOffset",5)),o=ot(Pe(t,I(e,"lipsLength",5)),I(e,"lipsOffset",3));return {plots:[{key:"jaw",title:"Jaw",values:n,color:_},{key:"teeth",title:"Teeth",values:i,color:W},{key:"lips",title:"Lips",values:o,color:z}]}}},WI={type:"gator-oscillator",title:"Gator Oscillator",shortTitle:"Gator Oscillator",overlay:false,inputs:[],compute:r=>{let e=ee(r,"HL2"),t=ot(Pe(e,13),8),n=ot(Pe(e,8),5),i=ot(Pe(e,5),3),o=ae(ke(t,n),Math.abs),s=ae(ke(n,i),l=>-Math.abs(l)),a=l=>l.map((c,u)=>{if(!Number.isFinite(c))return null;let d=u>0?l[u-1]:Number.NaN;return Number.isFinite(d)&&Math.abs(c)>Math.abs(d)?z:W});return {plots:[{key:"upper",title:"Upper",values:o,kind:"histogram",color:z,colors:a(o),base:0},{key:"lower",title:"Lower",values:s,kind:"histogram",color:W,colors:a(s),base:0}]}}},Jx=[OI,NI,FI,VI,_I,BI,HI,zI,$I,WI];function an(r,e,t){let n=[{key:"upper",price:e,color:J},{key:"lower",price:r,color:J}];return t!=null&&n.splice(1,0,{key:"middle",price:t,color:J,lineStyle:"dotted"}),n}var st=[{key:"zero",price:0,color:J}];function mu(r){return r.map((e,t)=>{if(!Number.isFinite(e))return null;let n=t>0?r[t-1]:Number.NaN,i=Number.isFinite(n)?e>=n:true;return e>=0?i?z:`${z}80`:i?`${W}80`:W})}var GI={type:"rsi",title:"Relative Strength Index",shortTitle:"RSI",overlay:false,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"rsi",title:"RSI",values:Ls(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}],levels:an(30,70,50)})},UI={type:"stochastic",title:"Stochastic",shortTitle:"Stoch",overlay:false,inputs:[D(14,"kLength","%K length"),D(1,"kSmoothing","%K smoothing",500),D(3,"dLength","%D smoothing",500)],compute:(r,e)=>{let t=ge(du(Oe(r),Ue(r),Ye(r),I(e,"kLength",14)),I(e,"kSmoothing",1)),n=ge(t,I(e,"dLength",3));return {plots:[{key:"k",title:"%K",values:t,color:_,width:2},{key:"d",title:"%D",values:n,color:ue}],levels:an(20,80)}}},YI={type:"stochastic-rsi",title:"Stochastic RSI",shortTitle:"Stoch RSI",overlay:false,inputs:[D(14,"rsiLength","RSI length"),D(14,"stochLength","Stochastic length"),D(3,"kSmoothing","%K smoothing",500),D(3,"dLength","%D smoothing",500),be()],compute:(r,e)=>{let t=Ls(ee(r,F(e,"source","Close")),I(e,"rsiLength",14)),n=ge(du(t,t,t,I(e,"stochLength",14)),I(e,"kSmoothing",3)),i=ge(n,I(e,"dLength",3));return {plots:[{key:"k",title:"%K",values:n,color:_,width:2},{key:"d",title:"%D",values:i,color:ue}],levels:an(20,80)}}},KI={type:"macd",title:"MACD",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal smoothing",500),be()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=ke(Q(t,I(e,"fastLength",12)),Q(t,I(e,"slowLength",26))),i=Q(n,I(e,"signalLength",9)),o=ke(n,i);return {plots:[{key:"hist",title:"Histogram",values:o,kind:"histogram",color:z,colors:mu(o),base:0},{key:"macd",title:"MACD",values:n,color:_,width:2},{key:"signal",title:"Signal",values:i,color:ue}],levels:st}}},XI={type:"ppo",title:"Percentage Price Oscillator",shortTitle:"PPO",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal smoothing",500),be()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=Q(t,I(e,"fastLength",12)),i=Q(t,I(e,"slowLength",26)),o=K(n,i,(l,c)=>c===0?Number.NaN:(l-c)/c*100),s=Q(o,I(e,"signalLength",9)),a=ke(o,s);return {plots:[{key:"hist",title:"Histogram",values:a,kind:"histogram",color:z,colors:mu(a),base:0},{key:"ppo",title:"PPO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:s,color:ue}],levels:st}}},jI={type:"awesome-oscillator",title:"Awesome Oscillator",shortTitle:"AO",overlay:false,inputs:[],compute:r=>{let e=ee(r,"HL2"),t=ke(ge(e,5),ge(e,34)),n=t.map((i,o)=>{if(!Number.isFinite(i))return null;let s=o>0?t[o-1]:Number.NaN;return Number.isFinite(s)&&i<s?W:z});return {plots:[{key:"ao",title:"AO",values:t,kind:"histogram",color:z,colors:n,base:0}],levels:st}}},qI={type:"commodity-channel-index",title:"Commodity Channel Index",shortTitle:"CCI",overlay:false,inputs:[D(20),be("HLC3"),X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","HLC3")),i=ge(n,t),o=new Array(n.length).fill(Number.NaN);for(let a=t-1;a<n.length;a++){let l=i[a];if(!Number.isFinite(l))continue;let c=0;for(let u=a-t+1;u<=a;u++)c+=Math.abs(n[u]-l);o[a]=c/t;}return {plots:[{key:"cci",title:"CCI",values:n.map((a,l)=>{let c=i[l],u=o[l];return Number.isFinite(c)&&Number.isFinite(u)&&u!==0?(a-c)/(.015*u):Number.NaN}),color:F(e,"color",_),width:2}],levels:an(-100,100,0)}}},ZI={type:"williams-percent-r",title:"Williams %R",shortTitle:"%R",overlay:false,inputs:[D(14),X()],compute:(r,e)=>({plots:[{key:"wr",title:"%R",values:ae(du(Oe(r),Ue(r),Ye(r),I(e,"length",14)),n=>n-100),color:F(e,"color",_),width:2}],levels:an(-80,-20)})},JI={type:"chande-momentum-oscillator",title:"Chande Momentum Oscillator",shortTitle:"CMO",overlay:false,inputs:[D(9),be(),X()],compute:(r,e)=>{let t=I(e,"length",9),n=ze(ee(r,F(e,"source","Close"))),i=xe(ae(n,a=>Math.max(a,0)),t),o=xe(ae(n,a=>Math.max(-a,0)),t);return {plots:[{key:"cmo",title:"CMO",values:K(i,o,(a,l)=>a+l===0?0:100*(a-l)/(a+l)),color:F(e,"color",_),width:2}],levels:an(-50,50,0)}}},QI={type:"connors-rsi",title:"Connors RSI",shortTitle:"CRSI",overlay:false,inputs:[D(3,"rsiLength","RSI length"),D(2,"streakLength","Streak RSI length"),D(100,"rankLength","Percent-rank length"),X()],compute:(r,e)=>{let t=Oe(r),n=new Array(t.length).fill(0);for(let l=1;l<t.length;l++){let c=t[l]-t[l-1];n[l]=c>0?Math.max(n[l-1],0)+1:c<0?Math.min(n[l-1],0)-1:0;}let i=Ls(t,I(e,"rsiLength",3)),o=Ls(n,I(e,"streakLength",2)),s=Xx(Vt(t,1),I(e,"rankLength",100));return {plots:[{key:"crsi",title:"CRSI",values:t.map((l,c)=>{let u=i[c],d=o[c],h=s[c];return Number.isFinite(u)&&Number.isFinite(d)&&Number.isFinite(h)?(u+d+h)/3:Number.NaN}),color:F(e,"color",_),width:2}],levels:an(20,80,50)}}},eA={type:"fisher-transform",title:"Fisher Transform",shortTitle:"Fisher",overlay:false,inputs:[D(9)],compute:(r,e)=>{let t=I(e,"length",9),n=ee(r,"HL2"),i=ct(n,t),o=St(n,t),s=r.length,a=new Array(s).fill(Number.NaN),l=0,c=0;for(let u=0;u<s;u++){let d=i[u],h=o[u];if(!Number.isFinite(d)||!Number.isFinite(h))continue;let p=d===h?0:(n[u]-h)/(d-h)-.5;l=Math.max(-0.999,Math.min(.999,.66*p+.67*l)),c=.5*Math.log((1+l)/(1-l))+.5*c,a[u]=c;}return {plots:[{key:"fisher",title:"Fisher",values:a,color:_,width:2},{key:"trigger",title:"Trigger",values:ot(a,1),color:ue}],levels:st}}},tA={type:"trix",title:"TRIX",overlay:false,inputs:[D(18),X()],compute:(r,e)=>{let t=I(e,"length",18),n=ae(Oe(r),Math.log),i=Q(Q(Q(n,t),t),t);return {plots:[{key:"trix",title:"TRIX",values:ae(ze(i),s=>s*1e4),color:F(e,"color",_),width:2}],levels:st}}};function Qx(r,e,t){let n=ze(r),i=Q(Q(n,e),t),o=Q(Q(ae(n,Math.abs),e),t);return K(i,o,(s,a)=>a===0?0:100*s/a)}var nA={type:"true-strength-index",title:"True Strength Index",shortTitle:"TSI",overlay:false,inputs:[D(25,"longLength","Long length"),D(13,"shortLength","Short length"),D(13,"signalLength","Signal length")],compute:(r,e)=>{let t=Qx(Oe(r),I(e,"longLength",25),I(e,"shortLength",13));return {plots:[{key:"tsi",title:"TSI",values:t,color:_,width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",13)),color:ue}],levels:st}}},rA={type:"smi-ergodic",title:"SMI Ergodic Oscillator",shortTitle:"SMIE",overlay:false,inputs:[D(5,"shortLength","Short length"),D(20,"longLength","Long length"),D(5,"signalLength","Signal length")],compute:(r,e)=>{let t=Qx(Oe(r),I(e,"longLength",20),I(e,"shortLength",5)),n=Q(t,I(e,"signalLength",5)),i=ke(t,n);return {plots:[{key:"osc",title:"Oscillator",values:i,kind:"histogram",color:z,colors:mu(i),base:0},{key:"smi",title:"SMI",values:t,color:_,width:2},{key:"signal",title:"Signal",values:n,color:ue}],levels:st}}},iA={type:"schaff-trend-cycle",title:"Schaff Trend Cycle",shortTitle:"Schaff Trend Cycle",overlay:false,inputs:[D(10,"cycleLength","Cycle length"),D(23,"fastLength","Fast length"),D(50,"slowLength","Slow length")],compute:(r,e)=>{let t=I(e,"cycleLength",10),n=Oe(r),i=ke(Q(n,I(e,"fastLength",23)),Q(n,I(e,"slowLength",50))),o=a=>{let l=St(a,t),c=ct(a,t),u=new Array(a.length).fill(Number.NaN),d=Number.NaN,h=Number.NaN;for(let p=0;p<a.length;p++){let m=a[p],f=l[p],g=c[p];if(!Number.isFinite(m)||!Number.isFinite(f)||!Number.isFinite(g))continue;let b=g>f?(m-f)/(g-f)*100:Number.isFinite(d)?d:50;d=b,h=Number.isFinite(h)?h+.5*(b-h):b,u[p]=h;}return u};return {plots:[{key:"stc",title:"STC",values:o(o(i)),color:_,width:2}],levels:an(25,75)}}},oA={type:"know-sure-thing",title:"Know Sure Thing",shortTitle:"KST",overlay:false,inputs:[be(),D(9,"signalLength","Signal length")],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=[ge(Vt(t,10),10),ge(Vt(t,15),10),ge(Vt(t,20),10),ge(Vt(t,30),15)].reduce((i,o,s)=>K(i,o,(a,l)=>a+l*(s+1)),new Array(t.length).fill(0));return {plots:[{key:"kst",title:"KST",values:n,color:_,width:2},{key:"signal",title:"Signal",values:ge(n,I(e,"signalLength",9)),color:ue}],levels:st}}},sA={type:"coppock-curve",title:"Coppock Curve",shortTitle:"Coppock",overlay:false,inputs:[D(10,"wmaLength","WMA length"),D(14,"longRoc","Long RoC length"),D(11,"shortRoc","Short RoC length"),be(),X()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close"));return {plots:[{key:"coppock",title:"Coppock",values:uu(K(Vt(t,I(e,"longRoc",14)),Vt(t,I(e,"shortRoc",11)),(i,o)=>i+o),I(e,"wmaLength",10)),color:F(e,"color",_),width:2}],levels:st}}},aA={type:"detrended-price-oscillator",title:"Detrended Price Oscillator",shortTitle:"DPO",overlay:false,inputs:[D(21),X()],compute:(r,e)=>{let t=I(e,"length",21),n=Math.floor(t/2)+1;return {plots:[{key:"dpo",title:"DPO",values:ke(Oe(r),ot(ge(Oe(r),t),n)),color:F(e,"color",_),width:2}],levels:st}}},lA={type:"rate-of-change",title:"Rate of Change",shortTitle:"ROC",overlay:false,inputs:[D(9),be(),X()],compute:(r,e)=>({plots:[{key:"roc",title:"RoC",values:Vt(ee(r,F(e,"source","Close")),I(e,"length",9)),color:F(e,"color",_),width:2}],levels:st})},cA={type:"ultimate-oscillator",title:"Ultimate Oscillator",shortTitle:"UO",overlay:false,inputs:[D(7,"fastLength","Fast length"),D(14,"middleLength","Middle length"),D(28,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=r.length,n=new Array(t).fill(Number.NaN),i=new Array(t).fill(Number.NaN);for(let u=0;u<t;u++){let d=r[u],h=u>0?r[u-1].close:d.close,p=Math.min(d.low,h),m=Math.max(d.high,h);n[u]=d.close-p,i[u]=m-p;}let o=u=>K(xe(n,u),xe(i,u),(d,h)=>h===0?Number.NaN:d/h),s=o(I(e,"fastLength",7)),a=o(I(e,"middleLength",14)),l=o(I(e,"slowLength",28));return {plots:[{key:"uo",title:"UO",values:s.map((u,d)=>{let h=a[d],p=l[d];return Number.isFinite(u)&&Number.isFinite(h)&&Number.isFinite(p)?100*(4*u+2*h+p)/7:Number.NaN}),color:F(e,"color",_),width:2}],levels:an(30,70,50)}}},uA={type:"relative-vigor-index",title:"Relative Vigor Index",shortTitle:"RVGI",overlay:false,inputs:[D(10)],compute:(r,e)=>{let t=I(e,"length",10),n=pu(ke(Oe(r),Wx(r))),i=pu(ke(Ue(r),Ye(r))),o=K(xe(n,t),xe(i,t),(s,a)=>a===0?0:s/a);return {plots:[{key:"rvgi",title:"RVGI",values:o,color:_,width:2},{key:"signal",title:"Signal",values:pu(o),color:ue}],levels:st}}},dA={type:"relative-volatility-index",title:"Relative Volatility Index",shortTitle:"RVI",overlay:false,inputs:[D(10,"stdevLength","StdDev length"),D(14,"smoothLength","Smoothing length"),be(),X()],compute:(r,e)=>{let t=I(e,"smoothLength",14),n=ee(r,F(e,"source","Close")),i=sn(n,I(e,"stdevLength",10)),o=ze(n),s=Pe(K(i,o,(c,u)=>u>0?c:0),t),a=Pe(K(i,o,(c,u)=>u<=0?c:0),t);return {plots:[{key:"rvi",title:"RVI",values:K(s,a,(c,u)=>c+u===0?50:100*c/(c+u)),color:F(e,"color",_),width:2}],levels:an(20,80,50)}}},hA={type:"balance-of-power",title:"Balance of Power",shortTitle:"BOP",overlay:false,inputs:[X()],compute:(r,e)=>({plots:[{key:"bop",title:"BOP",values:r.map(n=>n.high===n.low?0:(n.close-n.open)/(n.high-n.low)),color:F(e,"color",_),width:2}],levels:st})},pA={type:"elder-ray",title:"Elder Ray",overlay:false,inputs:[D(13)],compute:(r,e)=>{let t=Q(Oe(r),I(e,"length",13));return {plots:[{key:"bull",title:"Bull power",values:ke(Ue(r),t),kind:"histogram",color:z,base:0},{key:"bear",title:"Bear power",values:ke(Ye(r),t),kind:"histogram",color:W,base:0}],levels:st}}},mA={type:"ttm-squeeze",title:"TTM Squeeze",overlay:false,inputs:[D(20),{key:"bbMult",title:"Bollinger multiplier",type:"float",defval:2,min:.1,max:50,step:.1},{key:"kcMult",title:"Keltner multiplier",type:"float",defval:1.5,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"length",20),n=Oe(r),i=ge(n,t),o=ae(sn(n,t),h=>h*I(e,"bbMult",2)),s=ae(Pe(Qn(r),t),h=>h*I(e,"kcMult",1.5)),a=K(ct(Ue(r),t),St(Ye(r),t),(h,p)=>(h+p)/2),l=K(a,i,(h,p)=>(h+p)/2),c=hu(ke(n,l),t),d=n.map((h,p)=>{let m=o[p],f=s[p];return Number.isFinite(m)&&Number.isFinite(f)?m<f:false}).map((h,p)=>Number.isFinite(c[p])?h?W:z:null);return {plots:[{key:"mom",title:"Momentum",values:c,kind:"histogram",color:z,colors:mu(c),base:0},{key:"squeeze",title:"Squeeze",values:c.map(h=>Number.isFinite(h)?0:Number.NaN),kind:"cross",color:Je,colors:d}]}}},e0=[GI,UI,YI,KI,XI,jI,qI,ZI,JI,QI,eA,tA,nA,rA,iA,oA,sA,aA,lA,cA,uA,dA,hA,pA,mA];var fA={type:"aroon",title:"Aroon",overlay:false,inputs:[D(14)],compute:(r,e)=>{let t=I(e,"length",14),n=ae(Ux(Ue(r),t+1),o=>100*(t-o)/t),i=ae(Yx(Ye(r),t+1),o=>100*(t-o)/t);return {plots:[{key:"up",title:"Aroon up",values:n,color:z,width:2},{key:"down",title:"Aroon down",values:i,color:W,width:2}]}}},gA={type:"average-directional-index",title:"Average Directional Index",shortTitle:"ADX",overlay:false,inputs:[D(14,"diLength","DI length"),D(14,"adxLength","ADX smoothing")],compute:(r,e)=>{let t=I(e,"diLength",14),n=I(e,"adxLength",14),i=r.length,o=new Array(i).fill(Number.NaN),s=new Array(i).fill(Number.NaN);for(let d=1;d<i;d++){let h=r[d].high-r[d-1].high,p=r[d-1].low-r[d].low;o[d]=h>p&&h>0?h:0,s[d]=p>h&&p>0?p:0;}let a=Pe(Qn(r),t),l=K(Pe(o,t),a,(d,h)=>h===0?0:100*d/h),c=K(Pe(s,t),a,(d,h)=>h===0?0:100*d/h),u=K(l,c,(d,h)=>d+h===0?0:100*Math.abs(d-h)/(d+h));return {plots:[{key:"adx",title:"ADX",values:Pe(u,n),color:_,width:2},{key:"plusDi",title:"+DI",values:l,color:z},{key:"minusDi",title:"-DI",values:c,color:W}],levels:[{key:"threshold",price:25,color:J,lineStyle:"dotted"}]}}},bA={type:"vortex-indicator",title:"Vortex Indicator",shortTitle:"VI",overlay:false,inputs:[D(14)],compute:(r,e)=>{let t=I(e,"length",14),n=r.length,i=new Array(n).fill(Number.NaN),o=new Array(n).fill(Number.NaN);for(let a=1;a<n;a++)i[a]=Math.abs(r[a].high-r[a-1].low),o[a]=Math.abs(r[a].low-r[a-1].high);let s=xe(Qn(r),t);return {plots:[{key:"viPlus",title:"VI+",values:K(xe(i,t),s,(a,l)=>l===0?Number.NaN:a/l),color:z,width:2},{key:"viMinus",title:"VI-",values:K(xe(o,t),s,(a,l)=>l===0?Number.NaN:a/l),color:W,width:2}],levels:[{key:"one",price:1,color:J,lineStyle:"dotted"}]}}},t0=[fA,gA,bA];var vA={type:"average-true-range",title:"Average True Range",shortTitle:"ATR",overlay:false,inputs:[D(14),X()],compute:(r,e)=>({plots:[{key:"atr",title:"ATR",values:Hr(r,I(e,"length",14)),color:F(e,"color",_),width:2}]})},yA={type:"historical-volatility",title:"Historical Volatility",shortTitle:"HV",overlay:false,inputs:[D(10),{key:"annual",title:"Periods per year",type:"int",defval:365,min:1,max:1e5,step:1,tooltip:"Annualization factor (365 for daily crypto bars, 252 for stock sessions)"},X()],compute:(r,e)=>{let t=ae(ze(ae(Oe(r),Math.log)),i=>i);return {plots:[{key:"hv",title:"HV",values:ae(sn(t,I(e,"length",10)),i=>i*Math.sqrt(I(e,"annual",365))*100),color:F(e,"color",_),width:2}]}}},wA={type:"chaikin-volatility",title:"Chaikin Volatility",shortTitle:"CHV",overlay:false,inputs:[D(10,"emaLength","EMA length"),D(10,"rocLength","RoC length"),X()],compute:(r,e)=>{let t=Q(ke(Ue(r),Ye(r)),I(e,"emaLength",10));return {plots:[{key:"cv",title:"Chaikin Vol",values:Vt(t,I(e,"rocLength",10)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},xA={type:"mass-index",title:"Mass Index",shortTitle:"MI",overlay:false,inputs:[D(25),X()],compute:(r,e)=>{let t=ke(Ue(r),Ye(r)),n=Q(t,9),i=K(n,Q(n,9),(o,s)=>s===0?Number.NaN:o/s);return {plots:[{key:"mi",title:"Mass Index",values:xe(i,I(e,"length",25)),color:F(e,"color",_),width:2}],levels:[{key:"reversal",price:27,color:J,lineStyle:"dotted"}]}}},SA={type:"standard-deviation",title:"Standard Deviation",shortTitle:"StdDev",overlay:false,inputs:[D(20),be(),X()],compute:(r,e)=>({plots:[{key:"stdev",title:"StdDev",values:sn(ee(r,F(e,"source","Close")),I(e,"length",20)),color:F(e,"color",_),width:2}]})},CA={type:"ulcer-index",title:"Ulcer Index",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=Oe(r),i=K(n,ct(n,t),(s,a)=>a===0?0:100*(s-a)/a);return {plots:[{key:"ui",title:"Ulcer",values:ae(ge(ae(i,s=>s*s),t),Math.sqrt),color:F(e,"color",_),width:2}]}}},TA={type:"choppiness-index",title:"Choppiness Index",shortTitle:"CHOP",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=xe(Qn(r),t),i=K(ct(Ue(r),t),St(Ye(r),t),(s,a)=>s-a);return {plots:[{key:"chop",title:"CHOP",values:K(n,i,(s,a)=>a>0&&s>0?100*Math.log10(s/a)/Math.log10(t):Number.NaN),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:61.8,color:J},{key:"lower",price:38.2,color:J}]}}},n0=[vA,yA,wA,xA,SA,CA,TA];function fu(r){return r.map(e=>e.volume==null||!Number.isFinite(e.volume)?Number.NaN:e.high===e.low?0:(2*e.close-e.high-e.low)/(e.high-e.low)*e.volume)}var kA={type:"on-balance-volume",title:"On Balance Volume",shortTitle:"OBV",overlay:false,inputs:[X()],compute:(r,e)=>{let t=xt(r),n=ze(Oe(r)),i=K(t,n,(o,s)=>s>0?o:s<0?-o:0);return {plots:[{key:"obv",title:"OBV",values:Ms(i),color:F(e,"color",_),width:2}]}}},EA={type:"accumulation-distribution",title:"Accumulation / Distribution",shortTitle:"A/D",overlay:false,inputs:[X()],compute:(r,e)=>({plots:[{key:"ad",title:"A/D",values:Ms(fu(r)),color:F(e,"color",_),width:2}]})},LA={type:"chaikin-money-flow",title:"Chaikin Money Flow",shortTitle:"CMF",overlay:false,inputs:[D(20),X()],compute:(r,e)=>{let t=I(e,"length",20);return {plots:[{key:"cmf",title:"CMF",values:K(xe(fu(r),t),xe(xt(r),t),(i,o)=>o===0?0:i/o),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},MA={type:"chaikin-oscillator",title:"Chaikin Oscillator",shortTitle:"Chaikin Osc",overlay:false,inputs:[D(3,"fastLength","Fast length"),D(10,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=Ms(fu(r));return {plots:[{key:"co",title:"Chaikin Osc",values:ke(Q(t,I(e,"fastLength",3)),Q(t,I(e,"slowLength",10))),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},PA={type:"ease-of-movement",title:"Ease of Movement",shortTitle:"EOM",overlay:false,inputs:[D(14),{key:"divisor",title:"Divisor",type:"int",defval:1e4,min:1,max:1e9,step:1},X()],compute:(r,e)=>{let t=I(e,"divisor",1e4),n=ee(r,"HL2"),i=ze(n),o=r.map((s,a)=>{let l=i[a];return s.volume==null||!Number.isFinite(s.volume)||s.volume===0||!Number.isFinite(l)?Number.NaN:t*l*(s.high-s.low)/s.volume});return {plots:[{key:"eom",title:"EOM",values:ge(o,I(e,"length",14)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},IA={type:"force-index",title:"Force Index",shortTitle:"FI",overlay:false,inputs:[D(13),X()],compute:(r,e)=>{let t=K(ze(Oe(r)),xt(r),(n,i)=>n*i);return {plots:[{key:"force",title:"Force",values:Q(t,I(e,"length",13)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},AA={type:"klinger-oscillator",title:"Klinger Oscillator",shortTitle:"KVO",overlay:false,inputs:[D(34,"fastLength","Fast length"),D(55,"slowLength","Slow length"),D(13,"signalLength","Signal length")],compute:(r,e)=>{let t=ee(r,"HLC3"),n=ze(t),i=K(xt(r),n,(s,a)=>a>=0?s:-s),o=ke(Q(i,I(e,"fastLength",34)),Q(i,I(e,"slowLength",55)));return {plots:[{key:"kvo",title:"KVO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:Q(o,I(e,"signalLength",13)),color:ue}],levels:[{key:"zero",price:0,color:J}]}}},RA={type:"money-flow-index",title:"Money Flow Index",shortTitle:"MFI",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=ee(r,"HLC3"),i=K(n,xt(r),(c,u)=>c*u),o=ze(n),s=xe(K(i,o,(c,u)=>u>0?c:0),t),a=xe(K(i,o,(c,u)=>u<0?c:0),t);return {plots:[{key:"mfi",title:"MFI",values:K(s,a,(c,u)=>u===0?100:100-100/(1+c/u)),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:80,color:J},{key:"lower",price:20,color:J}]}}};function r0(r,e){let t=new Array(r.length).fill(Number.NaN),n=1e3,i=false;for(let o=1;o<r.length;o++){let s=r[o].volume,a=r[o-1].volume,l=r[o-1].close;if(s==null||a==null||!Number.isFinite(s)||!Number.isFinite(a)||l===0){i&&(t[o]=n);continue}i=true,e(s,a)&&(n+=(r[o].close-l)/l*n),t[o]=n;}return t}var DA={type:"negative-volume-index",title:"Negative Volume Index",shortTitle:"Negative Volume Index",overlay:false,inputs:[D(255,"signalLength","Signal length"),X()],compute:(r,e)=>{let t=r0(r,(n,i)=>n<i);return {plots:[{key:"nvi",title:"NVI",values:t,color:F(e,"color",_),width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",255)),color:ue}]}}},OA={type:"positive-volume-index",title:"Positive Volume Index",shortTitle:"Positive Volume Index",overlay:false,inputs:[D(255,"signalLength","Signal length"),X()],compute:(r,e)=>{let t=r0(r,(n,i)=>n>i);return {plots:[{key:"pvi",title:"PVI",values:t,color:F(e,"color",_),width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",255)),color:ue}]}}},NA={type:"price-volume-trend",title:"Price Volume Trend",shortTitle:"PVT",overlay:false,inputs:[X()],compute:(r,e)=>{let t=Oe(r),n=r.map((i,o)=>{if(o===0||i.volume==null||!Number.isFinite(i.volume))return Number.NaN;let s=t[o-1];return s===0?0:(t[o]-s)/s*i.volume});return {plots:[{key:"pvt",title:"PVT",values:Ms(n),color:F(e,"color",_),width:2}]}}},FA={type:"volume-oscillator",title:"Volume Oscillator",shortTitle:"Vol Osc",overlay:false,inputs:[D(5,"fastLength","Fast length"),D(10,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=xt(r),n=Q(t,I(e,"fastLength",5)),i=Q(t,I(e,"slowLength",10));return {plots:[{key:"vo",title:"Volume Osc",values:K(n,i,(s,a)=>a===0?Number.NaN:100*(s-a)/a),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},VA={type:"pvo",title:"Percentage Volume Oscillator",shortTitle:"PVO",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal length")],compute:(r,e)=>{let t=xt(r),n=Q(t,I(e,"fastLength",12)),i=Q(t,I(e,"slowLength",26)),o=K(n,i,(l,c)=>c===0?Number.NaN:100*(l-c)/c),s=Q(o,I(e,"signalLength",9)),a=ke(o,s);return {plots:[{key:"hist",title:"Histogram",values:a,kind:"histogram",color:z,colors:a.map(l=>Number.isFinite(l)?l>=0?z:W:null),base:0},{key:"pvo",title:"PVO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:s,color:ue}],levels:[{key:"zero",price:0,color:J}]}}},_A={type:"volume-flow-indicator",title:"Volume Flow Indicator",shortTitle:"Volume Flow Indicator",overlay:false,inputs:[D(130),{key:"coef",title:"Cutoff coefficient",type:"float",defval:.2,min:.01,max:10,step:.01},{key:"volCoef",title:"Volume cap",type:"float",defval:2.5,min:.1,max:50,step:.1},D(3,"smoothLength","Smoothing length")],compute:(r,e)=>{let t=I(e,"length",130),n=I(e,"coef",.2),i=I(e,"volCoef",2.5),o=ae(ee(r,"HLC3"),Math.log),s=ze(o),a=sn(s,30),l=xt(r),c=ge(l,t),u=ze(ee(r,"HLC3")),d=r.map((f,g)=>{let b=Number.isFinite(a[g])?n*a[g]*f.close:Number.NaN,y=l[g],v=g>0?c[g-1]:Number.NaN,S=u[g];if(!Number.isFinite(b)||!Number.isFinite(y)||!Number.isFinite(v)||!Number.isFinite(S))return Number.NaN;let E=Math.min(y,v*i);return S>b?E:S<-b?-E:0}),h=r.map((f,g)=>{let b=g>0?c[g-1]:Number.NaN;return Number.isFinite(b)&&b!==0?b:Number.NaN}),p=xe(d,t),m=K(p,h,(f,g)=>f/g);return {plots:[{key:"vfi",title:"VFI",values:ge(m,I(e,"smoothLength",3)),color:_,width:2}],levels:[{key:"zero",price:0,color:J}]}}},BA={type:"intraday-intensity",title:"Intraday Intensity",shortTitle:"Intraday Intensity",overlay:false,inputs:[D(21),X()],compute:(r,e)=>{let t=I(e,"length",21);return {plots:[{key:"ii",title:"II%",values:K(xe(fu(r),t),xe(xt(r),t),(i,o)=>o===0?0:100*i/o),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},i0=[kA,EA,LA,MA,PA,IA,AA,RA,DA,OA,NA,FA,VA,_A,BA];var Pp=864e5;function Ip(r,e){if(r==="Week")return Math.floor((Math.floor(e/Pp)+3)/7);if(r==="Month"||r==="Quarter"||r==="Year"){let t=new Date(e);return r==="Year"?t.getUTCFullYear():r==="Quarter"?t.getUTCFullYear()*4+Math.floor(t.getUTCMonth()/3):t.getUTCFullYear()*12+t.getUTCMonth()}return Math.floor(e/Pp)}var HA={type:"parabolic-sar",title:"Parabolic SAR",shortTitle:"SAR",overlay:true,inputs:[{key:"start",title:"Start",type:"float",defval:.02,min:.001,max:1,step:.001},{key:"increment",title:"Increment",type:"float",defval:.02,min:.001,max:1,step:.001},{key:"maximum",title:"Max value",type:"float",defval:.2,min:.01,max:1,step:.01}],compute:(r,e)=>{let t=I(e,"start",.02),n=I(e,"increment",.02),i=I(e,"maximum",.2),o=r.length,s=new Array(o).fill(Number.NaN),a=new Array(o).fill(null);if(o>=2){let l=r[1].close>=r[0].close,c=l?r[0].low:r[0].high,u=l?r[0].high:r[0].low,d=t;for(let h=1;h<o;h++){let p=r[h];c+=d*(u-c),l?c=Math.min(c,r[h-1].low,h>=2?r[h-2].low:r[h-1].low):c=Math.max(c,r[h-1].high,h>=2?r[h-2].high:r[h-1].high),(l?p.low<c:p.high>c)?(l=!l,c=u,u=l?p.high:p.low,d=t):l&&p.high>u?(u=p.high,d=Math.min(i,d+n)):!l&&p.low<u&&(u=p.low,d=Math.min(i,d+n)),s[h]=c,a[h]=l?z:W;}}return {plots:[{key:"sar",title:"PSAR",values:s,kind:"circles",color:_,colors:a}]}}},o0="Bands",gu="Style",Mp=[{on:"band1",mult:"band1Mult",color:"band1Color",fill:"band1Fill",fillColor:"band1FillColor",defMult:1,defOn:true,defColor:z},{on:"band2",mult:"band2Mult",color:"band2Color",fill:"band2Fill",fillColor:"band2FillColor",defMult:2,defOn:false,defColor:ue},{on:"band3",mult:"band3Mult",color:"band3Color",fill:"band3Fill",fillColor:"band3FillColor",defMult:3,defOn:false,defColor:Bs[4]}],zA={type:"vwap",title:"Volume Weighted Average Price",shortTitle:"VWAP",overlay:true,inputs:[{key:"anchor",title:"Period",type:"string",defval:"Day",options:["Day","Week","Month","Quarter","Year"],tooltip:"Where the accumulation resets (UTC periods)"},be("HLC3"),...Mp.flatMap((r,e)=>[{key:r.on,title:`Band ${e+1} multiplier`,type:"bool",defval:r.defOn,inline:r.on,group:o0},{key:r.mult,title:"",type:"float",defval:r.defMult,min:.1,max:10,step:.1,inline:r.on,group:o0}]),{...X(Je,"VWAP color"),group:gu},...Mp.flatMap((r,e)=>[{...X(r.defColor,`Band ${e+1} color`,r.color),inline:r.color,group:gu},{key:r.fill,title:"Fill",type:"bool",defval:true,inline:r.color,group:gu},{...X(Mn(r.defColor),"",r.fillColor),inline:r.color,group:gu}])],compute:(r,e)=>{let t=F(e,"anchor","Day"),n=ee(r,F(e,"source","HLC3")),i=r.length,o=new Array(i).fill(Number.NaN),s=Mp.filter(p=>kp(e,p.on,p.defOn)).map(p=>({mult:Math.max(0,I(e,p.mult,p.defMult)),color:F(e,p.color,p.defColor),fill:kp(e,p.fill,true),fillColor:F(e,p.fillColor,Mn(p.defColor)),up:new Array(i).fill(Number.NaN),down:new Array(i).fill(Number.NaN)})),a=Number.NaN,l=0,c=0,u=0;for(let p=0;p<i;p++){let m=r[p],f=Ip(t,m.time);f!==a&&(a=f,l=0,c=0,u=0);let g=m.volume;if(g!=null&&Number.isFinite(g)&&g>0){let v=n[p];l+=v*g,c+=v*v*g,u+=g;}if(u<=0)continue;let b=l/u,y=Math.sqrt(Math.max(0,c/u-b*b));o[p]=b;for(let v of s)v.up[p]=b+v.mult*y,v.down[p]=b-v.mult*y;}let d=[{key:"vwap",title:"VWAP",values:o,color:F(e,"color",Je),width:2}],h=[];return s.forEach((p,m)=>{d.push({key:`up${m}`,title:`Upper ${p.mult}\u03C3`,values:p.up,color:p.color},{key:`down${m}`,title:`Lower ${p.mult}\u03C3`,values:p.down,color:p.color}),p.fill&&h.push({key:`band${m}`,from:`up${m}`,to:`down${m}`,color:p.fillColor});}),{plots:d,bands:h}}},$A={type:"pivot-points",title:"Pivot Points",shortTitle:"Pivots",overlay:true,inputs:[{key:"anchor",title:"Period",type:"string",defval:"Day",options:["Day","Week","Month"]}],compute:(r,e)=>{let t=F(e,"anchor","Day"),n=new Map;for(let l of r){let c=Ip(t,l.time),u=n.get(c);u?(u.high=Math.max(u.high,l.high),u.low=Math.min(u.low,l.low),u.close=l.close):n.set(c,{high:l.high,low:l.low,close:l.close});}let i=r.length,o=()=>new Array(i).fill(Number.NaN),s={p:o(),r1:o(),s1:o(),r2:o(),s2:o(),r3:o(),s3:o()};for(let l=0;l<i;l++){let c=n.get(Ip(t,r[l].time)-1);if(!c)continue;let u=(c.high+c.low+c.close)/3;s.p[l]=u,s.r1[l]=2*u-c.low,s.s1[l]=2*u-c.high,s.r2[l]=u+(c.high-c.low),s.s2[l]=u-(c.high-c.low),s.r3[l]=c.high+2*(u-c.low),s.s3[l]=c.low-2*(c.high-u);}let a=(l,c,u)=>({key:l,title:c,kind:"step",values:s[l],color:u});return {plots:[a("p","P",ue),a("r1","R1",W),a("s1","S1",z),a("r2","R2",W),a("s2","S2",z),a("r3","R3",W),a("s3","S3",z)]}}},WA={type:"52-week-high-low",title:"52 Week High/Low",shortTitle:"52W H/L",overlay:true,inputs:[{key:"weeks",title:"Weeks",type:"int",defval:52,min:1,max:520,step:1}],compute:(r,e)=>{let t=I(e,"weeks",52)*7*Pp,n=r.length,i=new Array(n).fill(Number.NaN),o=new Array(n).fill(Number.NaN),s=[],a=[],l=0;for(let c=0;c<n;c++){let u=r[c];for(;s.length>0&&r[s[s.length-1]].high<=u.high;)s.pop();for(s.push(c);a.length>0&&r[a[a.length-1]].low>=u.low;)a.pop();for(a.push(c);r[l].time<u.time-t;)l+=1;for(;s[0]<l;)s.shift();for(;a[0]<l;)a.shift();i[c]=r[s[0]].high,o[c]=r[a[0]].low;}return {plots:[{key:"high",title:"52W high",values:i,kind:"step",color:z},{key:"low",title:"52W low",values:o,kind:"step",color:W}]}}},GA={type:"zigzag",title:"ZigZag",overlay:true,inputs:[{key:"deviation",title:"Deviation %",type:"float",defval:5,min:.01,max:100,step:.1},{key:"depth",title:"Depth",type:"int",defval:10,min:1,max:500,step:1},X()],compute:(r,e)=>{let t=I(e,"deviation",5)/100,n=I(e,"depth",10),i=[];if(r.length>1){let o=r[1].close>=r[0].close,s=o?{i:0,price:r[0].high}:{i:0,price:r[0].low};for(let a=1;a<r.length;a++){let l=r[a];o?l.high>=s.price?s={i:a,price:l.high}:l.low<=s.price*(1-t)&&a-(i[i.length-1]?.i??-n)>=n&&(i.push(s),o=false,s={i:a,price:l.low}):l.low<=s.price?s={i:a,price:l.low}:l.high>=s.price*(1+t)&&a-(i[i.length-1]?.i??-n)>=n&&(i.push(s),o=true,s={i:a,price:l.high});}i.push(s);}return {plots:[],polylines:[{key:"zigzag",points:i.map(o=>({xloc:"bar_time",x:r[o.i].time,price:o.price})),curved:false,closed:false,lineColor:F(e,"color",_),lineWidth:2,lineStyle:"solid",arrowLeft:false,arrowRight:false}]}}},UA={type:"williams-fractal",title:"Williams Fractal",shortTitle:"Fractals",overlay:true,inputs:[{key:"periods",title:"Periods",type:"int",defval:2,min:1,max:50,step:1}],compute:(r,e)=>{let t=I(e,"periods",2),n=[],i=(o,s,a)=>{let l=s(r[o]);for(let c=o-t;c<=o+t;c++)if(c!==o&&!a(l,s(r[c])))return false;return true};for(let o=t;o<r.length-t;o++)i(o,s=>s.high,(s,a)=>s>=a)&&n.push({time:r[o].time,position:"aboveBar",shape:"triangleup",color:z}),i(o,s=>s.low,(s,a)=>s<=a)&&n.push({time:r[o].time,position:"belowBar",shape:"triangledown",color:W});return {plots:[],markers:n}}},s0=[HA,zA,$A,WA,GA,UA];var YA=[...Zx,...Jx,...e0,...t0,...n0,...i0,...s0];function a0(){for(let r of YA)Pn(zx(r));}var Ap=class{constructor(e,t={},n={}){Fx(),fp(),Cp(),a0();let i=KA(e),o=Qr(t.theme),s={currentPriceLine:t.currentPriceLine??true,logScale:t.logScale??false,nativeBackend:t.nativeBackend??"auto",...Wp(t.animations),glow:t.glow??0,upColor:t.upColor??z,downColor:t.downColor??W,priceStyle:t.priceStyle??"candles"},a=t.renderer??Es;if(typeof a!="function")throw new Error("[vela] options.renderer must be a renderer class, e.g. import { LwcRenderer } from 'vela/renderers/lwc'. The 'lwc'/'native' string options were removed.");let l=n.renderer??new a(s),c=n.engines??[],u=n.dataFeed??new vr,d={market:{symbol:t.symbol,timeframe:t.timeframe,bars:t.bars,session:t.session,visibleRange:t.visibleRange,data:t.data},live:t.live??false,theme:o,defaultLanguage:t.defaultLanguage??c[0]?.language??"pine",drawings:t.drawings,volume:t.volume??true};this.rendererControl=new co(l),t.settings&&this.rendererControl.setSettingsVisibility(t.settings),this.dataControl=new go(u),this.orchestrator=new tl(i,l,u,c,d,this.dataControl);let h=Hu();Object.keys(h).length>0&&this.rendererControl.set(h),this.panesControl=new nl(this.orchestrator),this.drawingsControl=new bo(this.orchestrator.drawings),this.marksControl=new vo(this.orchestrator.marks);}registerEngine(e,t){return this.orchestrator.registerEngine(e,t),this}addIndicator(e,t){return this.orchestrator.addIndicator(e,t)}addNativeIndicator(e,t){return this.orchestrator.addNativeIndicator(e,t)}availableNativeIndicators(){return this.orchestrator.availableNativeIndicators()}presentNativeIndicators(){return this.orchestrator.presentNativeIndicators()}indicators(){return this.orchestrator.listIndicators()}runScript(e,t){let n=this.addIndicator(e,t),i=new Set,o=()=>{try{n.remove();}catch{}};return new Promise(s=>{let a=false,l=this.on("script:run",u=>{if(u.id===n.id){if(a){for(let d of i)d(u);return}a=true,c(),s({ok:true,run:u,error:null,onUpdate:d=>(i.add(d),()=>i.delete(d)),remove:()=>{l(),i.clear(),o();}});}}),c=n.on("error",({error:u})=>{a||(a=true,l(),c(),o(),s({ok:false,run:null,error:u,onUpdate:()=>()=>{},remove:()=>{}}));});})}runIndicator(e,t){let n=this.addIndicator(e,t);return new Promise(i=>{let o=n.on("ready",()=>{o(),s(),i({ok:true,handle:n,error:null,context:null});}),s=n.on("error",({error:a})=>{o(),s(),n.context().catch(()=>null).then(l=>{try{n.remove();}catch{}i({ok:false,handle:null,error:a,context:l});});});})}setMarket(e){return this.orchestrator.setMarket(e)}get market(){return this.orchestrator.marketSnapshot()}ready(){return this.orchestrator.ready()}historyComplete(){return this.orchestrator.historyComplete()}inspect(){return this.orchestrator.inspect()}get renderer(){return this.rendererControl}get panes(){return this.panesControl}get data(){return this.dataControl}get drawings(){return this.drawingsControl}get marks(){return this.marksControl}on(e,t){return this.orchestrator.events.on(e,t)}getVisibleRange(){return this.orchestrator.getVisibleRange()}setVisibleRange(e){return this.orchestrator.setVisibleRange(e),this}panBy(e){return this.orchestrator.panBy(e),this}setVisibleRangePreset(e){return this.orchestrator.setVisibleRangePreset(e),this}resize(){this.orchestrator.resize();}setTheme(e){return this.orchestrator.setTheme(Qr(e)),this}destroy(){this.orchestrator.destroy();}};function KA(r){if(typeof r!="string")return r;let e=document.querySelector(r);if(!e)throw new Error(`[vela] container not found for selector "${r}"`);return e}var l0=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var zi=new Map,Ps=new Map,Is=new Map;function XA(r){return Ps.set(r.id,r),()=>{Ps.get(r.id)===r&&Ps.delete(r.id);}}function jA(r){Ps.delete(r);}function qA(){return [...Ps.values()]}var c0=100;function ZA(r){return Is.set(r.id,r),()=>{Is.get(r.id)===r&&Is.delete(r.id);}}function JA(r){Is.delete(r);}function QA(){return [...Is.values()].sort((r,e)=>(r.order??c0)-(e.order??c0))}var Rp=["indicators","screenshot"],u0=new Set(Rp),eR=new Set(l0);function tR(r){if(u0.has(r))return zi.get(r)}function nR(r){return eR.has(r.id)&&!u0.has(r.id)?(console.warn(`[vela] widget action "${r.id}": this built-in topbar slot is a stateful control and cannot be overridden \u2014 ignored. Overridable slots: ${Rp.join(", ")}.`),()=>{}):(zi.set(r.id,r),()=>{zi.get(r.id)===r&&zi.delete(r.id);})}function rR(r){zi.delete(r);}function iR(r,e){let t=[...zi.values()].filter(n=>n.target===r);return t.sort((n,i)=>(n.order??0)-(i.order??0)),e?t.filter(n=>!n.when||n.when(e)):t}var As=new Map;function oR(r){return As.set(r.id,r),()=>{As.get(r.id)===r&&As.delete(r.id);}}function sR(r){As.delete(r);}function aR(){return [...As.values()].sort((r,e)=>(r.order??0)-(e.order??0))}var Rs=new Map;function lR(r){return Rs.set(r.id,r),()=>{Rs.get(r.id)===r&&Rs.delete(r.id);}}function cR(r){Rs.delete(r);}function uR(){return [...Rs.values()].sort((r,e)=>(r.order??0)-(e.order??0))}var Ds=new Map;function dR(r){return Ds.set(r.key,r),()=>{Ds.get(r.key)===r&&Ds.delete(r.key);}}function hR(r){Ds.delete(r);}function pR(r){return [...Ds.values()].filter(e=>e.scope===r)}var bu;function mR(r){return bu=r,()=>{bu===r&&(bu=void 0);}}function fR(){return bu}var Os=new Map;function gR(r,e){return Os.set(r,e),()=>{Os.get(r)===e&&Os.delete(r);}}function bR(r){Os.delete(r);}function vR(r){return {...Object.fromEntries(Os),...r}}var d0=280,Dp=200,h0=640;function yR(r,e=Dp,t=h0){let n=Number.isFinite(e)&&e>0?e:Dp,i=Number.isFinite(t)?Math.max(t,n):Number.POSITIVE_INFINITY;return Number.isFinite(r)?Math.round(Math.min(Math.max(r,n),i)):n}function $i(r){let e=r.description?.split("/")[0]?.trim();return e?e.replace(/\s+Perpetual$/i,""):r.ticker.replace(/[-_/]?(USDT|USDC|USD1|USDS|BUSD|USD|EUR|PERP)$/i,"")||r.ticker}function Wi(r){let e=r.trim().toUpperCase();return e?`https://crypto-icons.ledger.com/${encodeURIComponent(e)}.png`:void 0}var p0="https://api.binance.com/api/v3",wR="https://api.binance.us/api/v3",Op="https://fapi.binance.com/fapi/v1",xR="wss://stream.binance.com:9443",SR="wss://stream.binance.us:9443",CR="wss://fstream.binance.com",TR=15e3,kR=2e3,m0={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",360:"6h",480:"8h",720:"12h",D:"1d",W:"1w",M:"1M"},f0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},ER=[1,3,5,15,30,60,120,240,360,480,720],LR={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",360:"6h",480:"8h",720:"12h"},MR=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function g0(r){return f0[r]??f0[r.toLowerCase()]??r}function Np(r){let e=r.trim().toUpperCase();return e.endsWith(".P")?{apiSymbol:e.slice(0,-2),isFutures:true}:{apiSymbol:e,isFutures:false}}function b0(r){return r.map(e=>({time:Number(e[0]),open:Number(e[1]),high:Number(e[2]),low:Number(e[3]),close:Number(e[4]),volume:Number(e[5])}))}function PR(r){return {time:Number(r.t),open:Number(r.o),high:Number(r.h),low:Number(r.l),close:Number(r.c),volume:Number(r.v)}}function IR(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function AR(r,e){let t=new Map;for(let n of r){let i=Math.floor(n.time/e)*e,o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function RR(r){return ER.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}var vu=class{constructor(){this.spotBaseUrl=null;this.spotBaseProbe=null;this.symbolsPromise=null;}info(){return {name:"binance",displayName:"Binance",requiresApiKey:false,supportedTimeframes:MR,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let{apiSymbol:i,isFutures:o}=Np(e),s=o?Op:await this.spotBase(),a=g0(t),l=m0[a];if(l)return IR(b0(await this.fetchKlines(s,i,l,n)));let c=/^\d+$/.test(a)?parseInt(a,10):null,u=c!=null?RR(c):null;if(c==null||u==null)return console.warn(`[vela] Binance: timeframe "${t}" is not supported and cannot be aggregated.`),[];let d=c/u,h={...n,limit:n.limit!=null?n.limit*d+d:void 0},p=b0(await this.fetchKlines(s,i,LR[u],h)),m=AR(p,c*6e4);return n.limit!=null&&m.length>n.limit?m.slice(-n.limit):m}catch(i){return console.warn(`[vela] Binance: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let{apiSymbol:t,isFutures:n}=Np(e),i=n?Op:await this.spotBase(),o=n?`${i}/exchangeInfo`:`${i}/exchangeInfo?symbol=${t}`,a=(await this.json(o).catch(()=>null))?.symbols??[],l=n?a.find(d=>d.symbol===t):a[0];if(!l)return;let c=l.filters?.find(d=>d.filterType==="PRICE_FILTER"),u=c?parseFloat(c.tickSize??"0.01"):.01;return {ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",description:`${l.baseAsset} / ${l.quoteAsset}${n?" Perpetual":""}`,type:n?"futures":"crypto",basecurrency:l.baseAsset,currency:l.quoteAsset,mintick:u,pricescale:Math.round(1/u),timezone:"Etc/UTC",session:"24x7"}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=Promise.all([this.listSpot().catch(()=>[]),this.listFutures().catch(()=>[])]).then(([e,t])=>[...e,...t])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let{apiSymbol:i,isFutures:o}=Np(e),s=m0[g0(t)];return s&&typeof WebSocket<"u"?this.streamKlines(e,t,i,o,s,n):this.pollBars(e,t,n)}streamKlines(e,t,n,i,o,s){let a=false,l=null,c=null,u=null,d=null,h=`${n.toLowerCase()}@kline_${o}`,p=()=>{u&&(clearTimeout(u),u=null);},m=()=>{if(!(a||d)){p(),c&&(clearTimeout(c),c=null);try{l?.close();}catch{}l=null,console.warn(`[vela] Binance: ${e} ${t} stream delivered no data; falling back to polling.`),d=this.pollBars(e,t,s);}},f=async()=>{if(a)return;let g=i?CR:await this.spotWsBase();a||(l=new WebSocket(`${g}/ws/${h}`),u=setTimeout(m,TR),l.onmessage=b=>{if(!(a||d))try{let y=JSON.parse(typeof b.data=="string"?b.data:"");y.k&&(p(),s(PR(y.k)));}catch{}},l.onclose=()=>{!a&&!d&&(c=setTimeout(()=>{f();},kR));},l.onerror=()=>{try{l?.close();}catch{}});};return f(),()=>{a=true,p(),c&&clearTimeout(c),d?.();try{l?.close();}catch{}}}async spotWsBase(){return (await this.spotBase()).includes("binance.us")?SR:xR}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}async listSpot(){let e=await this.spotBase();return ((await this.json(`${e}/exchangeInfo`)).symbols??[]).filter(n=>n.status==="TRADING").map(n=>({ticker:n.symbol,description:`${n.baseAsset} / ${n.quoteAsset}`,type:"crypto"}))}async listFutures(){return ((await this.json(`${Op}/exchangeInfo`)).symbols??[]).filter(t=>t.contractType==="PERPETUAL"&&t.status==="TRADING").map(t=>({ticker:`${t.symbol}.P`,description:`${t.baseAsset} / ${t.quoteAsset} Perpetual`,type:"futures"}))}async fetchKlines(e,t,n,i){if(i.from!=null)return this.paginateForward(e,t,n,i.from,i.to??Date.now(),i.limit);let o=i.limit??500;return o>1e3?this.paginateBackward(e,t,n,o,i.to):this.klinesChunk(e,{symbol:t,interval:n,limit:o,endTime:i.to})}async paginateForward(e,t,n,i,o,s){let a=[],l=i;for(;l<o;){let c=await this.klinesChunk(e,{symbol:t,interval:n,limit:1e3,startTime:l,endTime:o});if(c.length===0||(a.push(...c),l=Number(c[c.length-1][6])+1,c.length<1e3)||s&&a.length>=s)break}return s?a.slice(0,s):a}async paginateBackward(e,t,n,i,o){let s=[],a=i,l=o,c=Math.ceil(i/1e3)+5;for(;a>0&&c-- >0;){let u=Math.min(a,1e3),d=await this.klinesChunk(e,{symbol:t,interval:n,limit:u,endTime:l});if(d.length===0||(s=d.concat(s),a-=d.length,l=Number(d[0][0])-1,d.length<u))break}return s}async klinesChunk(e,t){let n=new URL(`${e}/klines`);n.searchParams.set("symbol",t.symbol),n.searchParams.set("interval",t.interval),t.limit&&n.searchParams.set("limit",String(Math.min(t.limit,1e3))),t.startTime!=null&&n.searchParams.set("startTime",String(t.startTime)),t.endTime!=null&&n.searchParams.set("endTime",String(t.endTime));let i=await this.json(n.toString());return Array.isArray(i)?i.length>0&&!Array.isArray(i[0])?[]:i:[]}spotBase(){return this.spotBaseUrl?Promise.resolve(this.spotBaseUrl):(this.spotBaseProbe||(this.spotBaseProbe=(async()=>{try{for(let e of [p0,wR])try{if((await fetch(`${e}/ping`,{signal:AbortSignal.timeout(5e3)})).ok)return this.spotBaseUrl=e}catch{}return p0}finally{this.spotBaseProbe=null;}})()),this.spotBaseProbe)}async json(e){let t=await fetch(e);if(!t.ok)throw new Error(`Binance HTTP ${t.status} for ${e}`);return t.json()}};var DR="https://api.hyperliquid.xyz/info",OR="wss://api.hyperliquid.xyz/ws",NR=15e3,FR=2e3,v0={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h",D:"1d",W:"1w",M:"1M"},y0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},VR=[1,3,5,15,30,60,120,240,480,720],_R={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h"},BR=["1","3","5","15","30","45","60","120","180","240","360","480","720","D","W","M"],w0={D:864e5,W:6048e5,M:2592e6};function HR(r){if(w0[r])return w0[r];let e=parseInt(r,10);return Number.isFinite(e)&&e>0?e*6e4:36e5}function x0(r){return y0[r]??y0[r.toLowerCase()]??r}function Fp(r){let e=r.trim();return e.includes("/")?e:e.toUpperCase()}function Vp(r){return {time:Number(r.t),open:Number(r.o),high:Number(r.h),low:Number(r.l),close:Number(r.c),volume:Number(r.v)}}function zR(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function $R(r,e){let t=new Map;for(let n of r){let i=Math.floor(n.time/e)*e,o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function WR(r){return VR.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}var yu=class{constructor(){this.metaPromise=null;this.spotMetaPromise=null;this.symbolsPromise=null;}info(){return {name:"hyperliquid",displayName:"Hyperliquid",requiresApiKey:false,supportedTimeframes:BR,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let i=Fp(e),o=x0(t),s=v0[o];if(s)return zR((await this.fetchCandles(i,s,HR(o),n)).map(Vp));let a=/^\d+$/.test(o)?parseInt(o,10):null,l=a!=null?WR(a):null;if(a==null||l==null)return console.warn(`[vela] Hyperliquid: timeframe "${t}" is not supported and cannot be aggregated.`),[];let c=a/l,u={...n,limit:n.limit!=null?n.limit*c+c:void 0},d=(await this.fetchCandles(i,_R[l],l*6e4,u)).map(Vp),h=$R(d,a*6e4);return n.limit!=null&&h.length>n.limit?h.slice(-n.limit):h}catch(i){return console.warn(`[vela] Hyperliquid: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let t=Fp(e),i=(await this.fetchMeta().catch(()=>null))?.universe?.find(o=>o.name===t);if(i){let o=C0(Math.max(0,6-(i.szDecimals??2)));return S0(e,t,"USD","futures",`${t} / USD Perpetual`,o)}if(t.includes("/")){let o=await this.fetchSpotMeta().catch(()=>null),s=o?.universe?.find(d=>d.name===t),a=s&&o?.tokens?o.tokens[s.tokens?.[0]??-1]:void 0,[l=t,c="USDC"]=t.split("/"),u=C0(Math.max(0,8-(a?.szDecimals??2)));return S0(e,l,c,"crypto",`${l} / ${c}`,u)}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=Promise.all([this.listPerps().catch(()=>[]),this.listSpot().catch(()=>[])]).then(([e,t])=>[...e,...t])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let i=Fp(e),o=v0[x0(t)];return o&&typeof WebSocket<"u"?this.streamCandles(e,t,i,o,n):this.pollBars(e,t,n)}async listPerps(){return ((await this.fetchMeta()).universe??[]).filter(t=>!t.isDelisted).map(t=>({ticker:t.name,description:`${t.name} / USD Perpetual`,type:"futures"}))}async listSpot(){let e=await this.fetchSpotMeta(),t=e.tokens??[],n=i=>i!=null?t[i]?.name??null:null;return (e.universe??[]).map(i=>{let o=n(i.tokens?.[0]),s=n(i.tokens?.[1]),a=o&&s?`${o} / ${s}`:i.name;return {ticker:i.name,description:a,type:"crypto"}})}async fetchCandles(e,t,n,i){let o=i.to??Date.now(),s=i.from!=null?i.from:o-((i.limit??500)+2)*n,a=await this.candleSnapshot(e,t,s,o);return i.from==null&&i.limit!=null&&a.length>i.limit?a.slice(-i.limit):a}async candleSnapshot(e,t,n,i){let o=await this.post({type:"candleSnapshot",req:{coin:e,interval:t,startTime:Math.floor(n),endTime:Math.floor(i)}});return Array.isArray(o)?o:[]}streamCandles(e,t,n,i,o){let s=false,a=null,l=null,c=null,u=null,d=null,h=()=>{u&&(clearTimeout(u),u=null);},p=()=>{l&&(clearInterval(l),l=null);},m=()=>{if(!(s||d)){h(),p(),c&&(clearTimeout(c),c=null);try{a?.close();}catch{}a=null,console.warn(`[vela] Hyperliquid: ${e} ${t} stream delivered no data; falling back to polling.`),d=this.pollBars(e,t,o);}},f=()=>{s||d||(a=new WebSocket(OR),u=setTimeout(m,NR),a.onopen=()=>{try{a?.send(JSON.stringify({method:"subscribe",subscription:{type:"candle",coin:n,interval:i}}));}catch{}l=setInterval(()=>{try{a?.send(JSON.stringify({method:"ping"}));}catch{}},3e4);},a.onmessage=g=>{if(!(s||d))try{let b=JSON.parse(typeof g.data=="string"?g.data:"");b.channel==="candle"&&b.data&&b.data.s===n&&(h(),o(Vp(b.data)));}catch{}},a.onclose=()=>{p(),!s&&!d&&(c=setTimeout(f,FR));},a.onerror=()=>{try{a?.close();}catch{}});};return f(),()=>{s=true,h(),p(),c&&clearTimeout(c),d?.();try{a?.close();}catch{}}}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}fetchMeta(){return this.metaPromise??(this.metaPromise=this.post({type:"meta"}).then(e=>e))}fetchSpotMeta(){return this.spotMetaPromise??(this.spotMetaPromise=this.post({type:"spotMeta"}).then(e=>e))}async post(e){let t=await fetch(DR,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Hyperliquid HTTP ${t.status}`);return t.json()}};function S0(r,e,t,n,i,o){return {ticker:r,tickerid:`HYPERLIQUID:${r}`,prefix:"HYPERLIQUID",description:i,type:n,basecurrency:e,currency:t,mintick:o,pricescale:Math.round(1/o),timezone:"Etc/UTC",session:"24x7"}}function C0(r){return Math.pow(10,-r)}var GR={now:()=>Date.now(),delay:r=>new Promise(e=>setTimeout(e,r))},wu=class{constructor(e,t,n=GR){this.maxConcurrent=e;this.minIntervalMs=t;this.clock=n;this.active=0;this.waiters=[];this.nextStartAt=0;this.pausedUntil=0;}async run(e){await this.acquire();try{return await this.waitForTurn(),await e()}finally{this.release();}}pauseFor(e){e>0&&(this.pausedUntil=Math.max(this.pausedUntil,this.clock.now()+e));}async waitForTurn(){for(;;){let e=this.clock.now(),t=Math.max(this.pausedUntil-e,this.nextStartAt-e);if(t<=0)break;await this.clock.delay(t);}this.nextStartAt=Math.max(this.clock.now(),this.nextStartAt)+this.minIntervalMs;}acquire(){return this.active<this.maxConcurrent?(this.active+=1,Promise.resolve()):new Promise(e=>{this.waiters.push(()=>{this.active+=1,e();});})}release(){this.active-=1;let e=this.waiters.shift();e&&e();}};var _p="https://api.exchange.coinbase.com",UR="wss://ws-feed.exchange.coinbase.com",YR={Accept:"application/json"},KR=15e3,XR=2e3,jR=5e3,xu=300,qR=4,ZR=120,JR=4,QR=600,e2=400;function t2(r,e){let t=Number(r.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t*1e3:e}var T0={1:60,5:300,15:900,60:3600,360:21600,D:86400},k0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},n2=[1,5,15,60,360,1440],r2={1:60,5:300,15:900,60:3600,360:21600,1440:86400},i2=["1","3","5","15","30","45","60","120","180","240","360","480","720","D","W","M"],Bp=864e5;function E0(r){return k0[r]??k0[r.toLowerCase()]??r}function Hp(r){return r.trim().toUpperCase()}function o2(r){return {time:Number(r[0])*1e3,open:Number(r[3]),high:Number(r[2]),low:Number(r[1]),close:Number(r[4]),volume:Number(r[5])}}function zp(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function s2(r,e){return L0(r,t=>Math.floor(t/e)*e)}function a2(r,e){return L0(r,e==="W"?l2:c2)}function L0(r,e){let t=new Map;for(let n of r){let i=e(n.time),o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function l2(r){let e=new Date(r),t=(e.getUTCDay()+6)%7;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()-t)}function c2(r){let e=new Date(r);return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),1)}function u2(r){return n2.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}function $p(r,e){return e!=null&&r.length>e?r.slice(-e):r}var Su=class{constructor(){this.symbolsPromise=null;this.gate=new wu(qR,ZR);}info(){return {name:"coinbase",displayName:"Coinbase",requiresApiKey:false,supportedTimeframes:i2,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let i=Hp(e),o=E0(t),s=T0[o];if(s)return zp(await this.fetchCandles(i,s,n));if(o==="W"||o==="M"){let h=o==="W"?7*Bp:31*Bp,p=n.from!=null?n:{...n,limit:n.limit!=null?Math.ceil(n.limit*h/Bp)+31:void 0},m=await this.fetchCandles(i,86400,p);return $p(a2(m,o),n.limit)}let a=/^\d+$/.test(o)?parseInt(o,10):null,l=a!=null?u2(a):null;if(a==null||l==null)return console.warn(`[vela] Coinbase: timeframe "${t}" is not supported and cannot be aggregated.`),[];let c=a/l,u={...n,limit:n.limit!=null?n.limit*c+c:void 0},d=await this.fetchCandles(i,r2[l],u);return $p(s2(d,a*6e4),n.limit)}catch(i){return console.warn(`[vela] Coinbase: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let t=Hp(e),n=await this.json(`${_p}/products/${t}`).catch(()=>null);if(!n||!n.id)return;let i=n.quote_increment!=null?parseFloat(n.quote_increment):.01,o=i>0?i:.01;return {ticker:e,tickerid:`COINBASE:${e}`,prefix:"COINBASE",description:`${n.base_currency} / ${n.quote_currency}`,type:"crypto",basecurrency:n.base_currency,currency:n.quote_currency,mintick:o,pricescale:Math.round(1/o),timezone:"Etc/UTC",session:"24x7"}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=this.fetchProducts().then(e=>e.filter(t=>t.status==="online"&&!t.trading_disabled).map(t=>({ticker:t.id,description:`${t.base_currency} / ${t.quote_currency}`,type:"crypto"}))).catch(()=>[])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let i=T0[E0(t)];return i&&typeof WebSocket<"u"?this.streamTicker(e,t,i,n):this.pollBars(e,t,n)}async fetchProducts(){let e=await this.json(`${_p}/products`);return Array.isArray(e)?e:[]}async fetchCandles(e,t,n){return n.from!=null?this.paginateForward(e,t,n.from,n.to??Date.now(),n.limit):this.paginateBackward(e,t,n.limit??500,n.to??Date.now())}async paginateBackward(e,t,n,i){let o=t*1e3,s=[],a=n,l=i,c=Math.ceil(n/xu)+4;for(;a>0&&c-- >0;){let u=Math.min(a,xu),d=l-u*o,h=await this.candlesChunk(e,t,d,l);if(h.length===0||(s=h.concat(s),a-=h.length,l=h[0].time-1,h.length<u))break}return $p(zp(s),n)}async paginateForward(e,t,n,i,o){let s=t*1e3,a=[],l=n,c=Math.ceil((i-n)/(xu*s))+4;for(;l<i&&c-- >0;){let d=Math.min(l+xu*s,i),h=await this.candlesChunk(e,t,l,d);if(h.length>0&&a.push(...h),l=d,o!=null&&a.length>=o)break}let u=zp(a);return o!=null?u.slice(0,o):u}async candlesChunk(e,t,n,i){let o=new URL(`${_p}/products/${e}/candles`);o.searchParams.set("granularity",String(t)),o.searchParams.set("start",String(Math.floor(n/1e3))),o.searchParams.set("end",String(Math.floor(i/1e3)));let s=await this.json(o.toString());return !Array.isArray(s)||s.length>0&&!Array.isArray(s[0])?[]:s.map(o2).sort((a,l)=>a.time-l.time)}streamTicker(e,t,n,i){let o=Hp(e),s=n*1e3,a=T=>Math.floor(T/s)*s,l=false,c=null,u=null,d=null,h=null,p=null,m=null,f=()=>{d&&(clearTimeout(d),d=null);},g=()=>{h&&(clearInterval(h),h=null);},b=()=>{m&&i({...m});},y=async T=>{try{let k=await this.getBars(e,t,{limit:2});if(l||k.length===0)return;T&&k.length>=2&&i(k[k.length-2]);let x=k[k.length-1];m=m&&m.time===x.time?{...x,high:Math.max(x.high,m.high),low:Math.min(x.low,m.low),close:m.close}:{...x},b();}catch{}},v=(T,k)=>{let x=Number(T);if(!Number.isFinite(x))return;let L=a(k);!m||L>m.time?(m={time:L,open:x,high:x,low:x,close:x,volume:0},b(),y(false)):L===m.time&&(m={...m,close:x,high:Math.max(m.high,x),low:Math.min(m.low,x)},b());},S=()=>{if(!(l||p)){f(),g(),u&&(clearTimeout(u),u=null);try{c?.close();}catch{}c=null,console.warn(`[vela] Coinbase: ${e} ${t} stream delivered no data; falling back to polling.`),p=this.pollBars(e,t,i);}},E=()=>{l||p||(c=new WebSocket(UR),d=setTimeout(S,KR),c.onopen=()=>{try{c?.send(JSON.stringify({type:"subscribe",product_ids:[o],channels:["ticker"]}));}catch{}y(false),h=setInterval(()=>{y(false);},jR);},c.onmessage=T=>{if(!(l||p))try{let k=JSON.parse(typeof T.data=="string"?T.data:"");k.type==="ticker"&&k.product_id===o&&k.price!=null&&(f(),v(k.price,k.time?Date.parse(k.time):Date.now()));}catch{}},c.onclose=()=>{g(),!l&&!p&&(u=setTimeout(E,XR));},c.onerror=()=>{try{c?.close();}catch{}});};return E(),()=>{l=true,f(),g(),u&&clearTimeout(u),p?.();try{c?.close();}catch{}}}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}async json(e){return (await this.request(e)).json()}async request(e){for(let t=0;;t+=1){let n=await this.gate.run(()=>fetch(e,{headers:YR}));if(n.status===429&&t<JR){let i=QR*2**t+Math.random()*e2;this.gate.pauseFor(Math.max(t2(n,0),i));continue}if(!n.ok)throw new Error(`Coinbase HTTP ${n.status} for ${e}`);return n}}};
1031
+ `;function qP(r){let e=r.getElementById(gx);e||(e=r.createElement("style"),e.id=gx,r.head.appendChild(e)),e.textContent=jP;}function np(r){return lt(r)?"#ffffff":"#000000"}function rp(r,e){let t=lt(e);r.style.color=t?"#ffffff":"#000000",r.style.setProperty("--vela-attr-shadow",t?"rgba(0,0,0,0.45)":"rgba(255,255,255,0.55)");}function bx(r,e,t){let n=r.createElement("div");return n.className="vela-attribution-custom",Object.assign(n.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",display:"flex",alignItems:"center",lineHeight:"1"}),n.style.color=np(t),n.innerHTML=e,n.dataset.velaScreenshot="1",n}function vx(r,e){qP(r);let t=r.createElement("a");t.className="vela-attribution",t.href=XP,t.target="_blank",t.rel="noopener",t.title="Charting by Vela",t.setAttribute("aria-label","Charting by Vela"),Object.assign(t.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",cursor:"pointer"}),rp(t,e),t.dataset.velaScreenshot="1";let n=r.createElement("span");n.className="vela-attr-symbol",n.setAttribute("aria-hidden","true"),n.innerHTML=mx;let i=r.createElement("span");return i.className="vela-attr-wordmark",i.innerHTML=fx,t.append(n,i),t}function iu(r){if(!r||r==="transparent")return false;let e=/rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*,\s*([\d.]+)\s*\)/.exec(r);return e?parseFloat(e[1])>.001:true}function yx(r,e,t){let n=r.borderTopLeftRadius,i=parseFloat(n)||0,o=n.endsWith("%")?i/100*Math.min(e,t):i;return Math.max(0,Math.min(o,Math.min(e,t)/2))}function ip(r,e,t,n,i,o){r.beginPath(),o>0&&typeof r.roundRect=="function"?r.roundRect(e,t,n,i,o):r.rect(e,t,n,i);}function ZP(r){try{let e=r.ownerDocument.createElement("canvas");e.width=1,e.height=1;let t=e.getContext("2d");return t?(t.drawImage(r,0,0,1,1),e.toDataURL(),!0):!1}catch{return false}}function ou(r,e,t){let n=e.ownerDocument.defaultView;if(!n)return;r.save(),r.scale(t.dpr,t.dpr);let i=(c,u,d)=>{let h=c.textContent?.replace(/\s+/g," ").trim();if(!h)return;let p=c.ownerDocument.createRange();p.selectNodeContents(c);let m=p.getBoundingClientRect();m.width<=0||m.height<=0||(r.globalAlpha=d,r.fillStyle=u.color,r.font=`${u.fontStyle} ${u.fontWeight} ${u.fontSize} ${u.fontFamily}`,r.textBaseline="middle",r.textAlign="left",r.fillText(h,m.left-t.left,m.top-t.top+m.height/2));},o=(c,u,d)=>{if(!c.complete||c.naturalWidth<=0||!ZP(c))return;let h=c.getBoundingClientRect();if(h.width<=0||h.height<=0)return;let p=h.left-t.left,m=h.top-t.top;r.save(),r.globalAlpha=d,ip(r,p,m,h.width,h.height,yx(u,h.width,h.height)),r.clip(),r.drawImage(c,p,m,h.width,h.height),r.restore();},s=(c,u)=>{for(let d of c.children){if(d.hasAttribute("transform"))continue;let h=d.tagName.toLowerCase();if(h==="g"){s(d,u);continue}let p=b=>parseFloat(d.getAttribute(b)??"0")||0,m=null;if(h==="path"){let b=d.getAttribute("d");b&&(m=new Path2D(b));}else if(h==="circle")m=new Path2D,m.arc(p("cx"),p("cy"),p("r"),0,Math.PI*2);else if(h==="ellipse")m=new Path2D,m.ellipse(p("cx"),p("cy"),p("rx"),p("ry"),0,0,Math.PI*2);else if(h==="rect")m=new Path2D,m.rect(p("x"),p("y"),p("width"),p("height"));else if(h==="line")m=new Path2D,m.moveTo(p("x1"),p("y1")),m.lineTo(p("x2"),p("y2"));else if(h==="polyline"||h==="polygon"){let b=(d.getAttribute("points")??"").trim().split(/[\s,]+/).map(Number);if(b.length<4||b.some(Number.isNaN))continue;m=new Path2D,m.moveTo(b[0],b[1]);for(let y=2;y+1<b.length;y+=2)m.lineTo(b[y],b[y+1]);h==="polygon"&&m.closePath();}if(!m)continue;let f=n.getComputedStyle(d);f.fill&&f.fill!=="none"&&iu(f.fill)&&(r.globalAlpha=u*(parseFloat(f.fillOpacity)||1),r.fillStyle=f.fill,r.fill(m));let g=parseFloat(f.strokeWidth)||0;f.stroke&&f.stroke!=="none"&&iu(f.stroke)&&g>0&&(r.globalAlpha=u*(parseFloat(f.strokeOpacity)||1),r.strokeStyle=f.stroke,r.lineWidth=g,(f.strokeLinecap==="round"||f.strokeLinecap==="square"||f.strokeLinecap==="butt")&&(r.lineCap=f.strokeLinecap),(f.strokeLinejoin==="round"||f.strokeLinejoin==="bevel"||f.strokeLinejoin==="miter")&&(r.lineJoin=f.strokeLinejoin),r.stroke(m));}},a=(c,u)=>{let d=c.getBoundingClientRect();if(d.width<=0||d.height<=0)return;let h=n.getComputedStyle(c);if(h.display==="none"||h.visibility==="hidden")return;let p=u*(parseFloat(h.opacity)||1);if(p<=.001)return;let m=c.viewBox.baseVal,f=m&&m.width>0?m.width:d.width,g=m&&m.height>0?m.height:d.height;r.save(),r.translate(d.left-t.left,d.top-t.top),r.scale(d.width/f,d.height/g),m&&r.translate(-m.x,-m.y),s(c,p),r.restore();},l=(c,u)=>{let d=n.getComputedStyle(c);if(d.display==="none"||d.visibility==="hidden")return;let h=u*(parseFloat(d.opacity)||1);if(h<=.001)return;let p=c.getBoundingClientRect();if(p.width>0&&p.height>0){let m=p.left-t.left,f=p.top-t.top,g=yx(d,p.width,p.height);iu(d.backgroundColor)&&(r.globalAlpha=h,r.fillStyle=d.backgroundColor,ip(r,m,f,p.width,p.height,g),r.fill());let b=parseFloat(d.borderTopWidth)||0;b>0&&d.borderTopStyle!=="none"&&iu(d.borderTopColor)&&(r.globalAlpha=h,r.strokeStyle=d.borderTopColor,r.lineWidth=b,ip(r,m+b/2,f+b/2,p.width-b,p.height-b,Math.max(0,g-b/2)),r.stroke());}for(let m of c.childNodes)m.nodeType===3?i(m,d,h):m instanceof n.HTMLImageElement?o(m,n.getComputedStyle(m),h):m instanceof n.SVGSVGElement?a(m,h):m instanceof n.HTMLElement&&l(m,h);};e instanceof n.HTMLElement&&l(e,1),r.restore();}function wx(r,e,t,n,i){let o=Math.max(0,e),s=Math.min(r.length-1,t);if(o>s)return null;let a=1/0,l=-1/0;for(let v=o;v<=s;v+=1){let S=r[v];S.volume!=null&&S.volume>0&&(S.low<a&&(a=S.low),S.high>l&&(l=S.high));}if(!Number.isFinite(a))return null;let c=l>a?Math.max(1,Math.round(n)):1,u=l>a?(l-a)/c:1,d=Array.from({length:c},(v,S)=>({price:a+S*u,up:0,down:0}));for(let v=o;v<=s;v+=1){let S=r[v],E=S.volume;if(!(E!=null&&E>0))continue;let T=S.close>=S.open?"up":"down",k=S.high-S.low;if(k<=0){let w=op(Math.floor((S.low-a)/u),c);d[w][T]+=E;continue}let x=op(Math.floor((S.low-a)/u),c),L=op(Math.floor((S.high-a)/u-1e-9),c);for(let w=x;w<=L;w+=1){let M=a+w*u,P=Math.min(S.high,M+u)-Math.max(S.low,M);P>0&&(d[w][T]+=E*P/k);}}let h=0,p=0,m=0;for(let v=0;v<c;v+=1){let S=d[v].up+d[v].down;h+=S,S>p&&(p=S,m=v);}if(p<=0)return null;let f=h*Math.min(1,Math.max(0,i)),g=m,b=m,y=p;for(;y<f&&(g>0||b<c-1);){let v=g>0?d[g-1].up+d[g-1].down:-1,S=b<c-1?d[b+1].up+d[b+1].down:-1;S>v?(b+=1,y+=S):(g-=1,y+=v);}return {rows:d,rowH:u,min:a,maxTotal:p,poc:m,vaFrom:g,vaTo:b}}function op(r,e){return r<0?0:r>=e?e-1:r}function xx(r,e,t,n){let{rows:i,rowH:o,maxTotal:s,poc:a,vaFrom:l,vaTo:c}=e,{rightX:u,maxW:d,yOf:h}=t;if(!(s<=0||d<=0)){for(let p=0;p<i.length;p+=1){let m=i[p],f=m.up+m.down;if(f<=0)continue;let g=h(m.price+o),b=Math.max(1,h(m.price)-g-1),y=f/s*d,v=m.up/f*y;r.globalAlpha=p>=l&&p<=c?.62:.28,v>0&&(r.fillStyle=n.upColor,r.fillRect(u-y,g,v,b)),y-v>0&&(r.fillStyle=n.downColor,r.fillRect(u-y+v,g,y-v,b));}if(n.showPoc){let p=i[a],m=h(p.price+o),f=Math.max(1,h(p.price)-m-1);r.globalAlpha=.9,r.strokeStyle=n.pocColor,r.lineWidth=1,r.strokeRect(u-d+.5,m+.5,d-1,f);}r.globalAlpha=1;}}var su=class{constructor(){this.canvas=null;this.ctx=null;this.memoKey="";this.memo=null;}mount(e){this.canvas=e,this.ctx=e.getContext("2d");}destroy(){this.canvas=null,this.ctx=null,this.memoKey="",this.memo=null;}render(e){let t=this.ctx,n=this.canvas;if(!t||!n)return;let{bars:i,data:o,visible:s,coords:a,scale:l,bounds:c,theme:u}=e,d=a.dpr;if(t.setTransform(d,0,0,d,0,0),t.clearRect(0,0,n.width/d,n.height/d),!o||!s||i.length===0||c.height<=0)return;let h=a.visibleLogicalRange(),p=Math.max(0,Math.floor(h.from)),m=Math.min(i.length-1,Math.ceil(h.to));if(p>m)return;let f=i[m],g=`${p}:${m}:${i.length}:${f.high}:${f.low}:${f.close}:${f.volume??0}:${o.rows}:${o.valueAreaFrac}`;g!==this.memoKey&&(this.memoKey=g,this.memo=wx(i,p,m,o.rows,o.valueAreaFrac));let b=this.memo;b&&(t.save(),t.beginPath(),t.rect(0,c.top,a.width,c.height),t.clip(),xx(t,b,{rightX:a.width,maxW:a.width*o.widthFrac,yOf:y=>a.priceToY(y,l,c)},{upColor:o.upColor,downColor:o.downColor,showPoc:o.showPoc,pocColor:u.textColor}),t.restore());}};var He="price",nI=8,rI="rgba(0,0,0,0)",au=64,iI=56,Lx=26,Hi=22,ks=26,sp=24,oI=5,sI="0 2px 8px rgba(0,0,0,0.4)",aI=12,Dx=12,Mx=au+Dx,ap=Hi+14,lI=120,cI=2,Px=6,Ix=350,uI=.02,dI=220;function lp(){return typeof performance<"u"?performance.now():Date.now()}var hI=.004,pI=.2,mI=4,Es=class{constructor(e){this.capabilities=yy;this.surfaceBackground=Yt.background;this.surfaceTextColor=Yt.textColor;this.toolbarGutter=0;this.mountContainer=null;this.userDrawings=null;this.backdropRenderer=new nu;this.volumeRenderer=new ru;this.extLayers=[];this.layerOrderSig="";this.attributionEl=null;this.attributionEnabled=true;this.attributionHtml=null;this.vpvrRenderer=new su;this.resizeObserver=null;this.dprMedia=null;this.plotDeviceSize=null;this.coords=new xc;this.scene=new Mc;this.backendMode="auto";this.glowAmount=0;this.chrome=new Vc;this.indicatorSlices=new Qc;this.labelTooltip=null;this.markPopover=null;this.marksExpandedBy="hover";this.markPulseRaf=null;this.markClickCbs=new Set;this.crosshairLayer=new Bc;this.hostClock=null;this.ownClock=null;this.countdownUnsub=null;this.symbolPicker=null;this.indicatorTitlesOn=true;this.indicatorValuesOn=true;this.legendActionsProvider=null;this.legendCalloutsProvider=null;this.legendOverviewAction=null;this.keyboard=null;this.keyboardEnabled=true;this.historyChordsEnabled=true;this.liveRegion=null;this.animZoom=new Yn(70);this.animPan=new Yn(110);this.animScroll=new Yn(130);this.animAutoscale=new Yn(80);this.animLiveBar=new Yn(90,0);this.candleUp=z;this.candleDown=W;this.intro={style:"settle",duration:650};this.introOnStyle="settle";this.introPlayed=false;this.introRaf=null;this.loadingEl=null;this.modelAlpha=1;this.targetBarSpacing=0;this.zoomAnchorLogical=0;this.zoomAnchorX=0;this.zoomAnchorMode="right";this.panVelocity=0;this.bars=[];this.didInitialFit=false;this.paintedData=false;this.skeletonClockMs=0;this.candleBodyAlpha=1;this.candleStructureAlpha=1;this.lastPointer=null;this.volumeActive=false;this.volumeHidden=false;this.vpvrActive=false;this.vpvrHidden=false;this.liveEaseTime=0;this.liveEaseHigh=0;this.liveEaseLow=0;this.liveEaseClose=0;this.axisDragEnabled=true;this.scaleDragHolder=null;this.scaleDragHeight=0;this.scaleDragStart=null;this.paneResizeEnabled=true;this.resizeAbove=null;this.resizeBelow=null;this.resizeSplitStart=null;this.hoverSeparatorY=null;this.maximizedPaneId=null;this.rightAxisW=au;this.paneControls=null;this.axisScaleButtons=null;this.paneActionCbs=new Set;this.hoverLogical=null;this.settingsDialog=null;this.hiddenSettings=[];this.dialogHost=null;this.settingsButton=null;this.settingsEnabled=false;this.scrollButton=null;this.pointerNearScrollBtn=false;this.scrollTargetRO=null;this.scrollBtnBottomPx=ap;this.scrollBtnRightPx=Mx;this.layoutMode="desktop";this.viewportCbs=new Set;this.crosshairCbs=new Set;this.chartTypeSettingsCbs=new Set;this.configChangedCbs=new Set;this.themeSelectCbs=new Set;this.factoryConfig=null;this.hostSettingsSections=[];this.clickCbs=new Set;this.axisLongPressCbs=new Set;this.inputChangeCbs=new Set;this.removeIndicatorCbs=new Set;this.toggleVisibleCbs=new Set;this.moveIndicatorCbs=new Set;this.priceStyleCbs=new Set;this.name="native";this.features=["logScale","currentPriceLine","priceLabel","countdown","upColor","downColor","glow","animZoom","animPan","animScroll","animAutoscale","animLiveBar","intro","zoomAnchor","axisDrag","paneResize","candleZOrder","candleVisible","seriesOrder","highlights","sessionZones","gridlines","axisLabels","scaleMode","invertScale","paneScales","autoScale","timezone","keyboard","historyChords","priceStyle","priceBaseline","baselinePrice","settings","attribution","dialogHost","tradeMarkers","marks","indicatorTitles","indicatorValues"];this.onScrollProximityMove=e=>{if(!this.scrollButton||!this.plot)return;let t=this.plot.getBoundingClientRect(),n=t.width-this.scrollBtnRightPx-ks/2,i=t.height-this.scrollBtnBottomPx-ks/2,o=Math.hypot(e.clientX-t.left-n,e.clientY-t.top-i)<=lI;o!==this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=o,this.updateScrollToRealtimeButton());};this.onScrollProximityLeave=()=>{this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=false,this.updateScrollToRealtimeButton());};this.onDprChange=()=>{this.watchDpr(),this.resize();};this.externalCross=null;this.snapMode="off";e&&(this.scene.showPriceLine=e.currentPriceLine,this.scene.logScale=e.logScale,this.backendMode=e.nativeBackend,this.animZoom.set(e.animZoom),this.animPan.set(e.animPan),this.animScroll.set(e.animScroll),this.animAutoscale.set(e.animAutoscale),this.animLiveBar.set(e.animLiveBar),this.setIntro(e.animIntro),this.glowAmount=e.glow,this.candleUp=e.upColor,this.candleDown=e.downColor,this.scene.priceStyle=e.priceStyle,this.scene.basePainting=hh(e.priceStyle),this.scene.candleOverride=bc(e.priceStyle,this.scene.style.chartTypes)),this.theme=this.deriveTheme(Yt);}applyFeature(e,t){switch(e){case "logScale":if(t&&typeof t=="object"){let n=t;this.setPaneLog(n.pane??He,!!n.value);return}this.scene.logScale=!!t;break;case "currentPriceLine":this.scene.showPriceLine=!!t;break;case "priceLabel":this.scene.showPriceLabel=!!t;break;case "countdown":this.scene.showCountdown=!!t,this.syncCountdownTimer();break;case "upColor":this.candleUp=String(t),this.theme&&(this.theme=this.deriveTheme(this.theme));break;case "downColor":this.candleDown=String(t),this.theme&&(this.theme=this.deriveTheme(this.theme));break;case "glow":this.glowAmount=Number(t)||0,this.backend&&"glow"in this.backend&&(this.backend.glow=this.glowAmount);break;case "animZoom":this.animZoom.set(_t(t,70));return;case "animPan":{let n=_t(t,110);this.animPan.set(n),this.animScroll.toggle(n>0);return}case "animScroll":this.animScroll.set(_t(t,130));return;case "animAutoscale":this.animAutoscale.set(_t(t,80));return;case "animLiveBar":this.animLiveBar.set(Cu(t));return;case "intro":{this.setIntro(Tu(t)),this.intro.style&&this.playIntro();return}case "zoomAnchor":this.zoomAnchorMode=t==="right"?"right":"cursor",this.input&&(this.input.rightEdgeZoom=this.zoomAnchorMode==="right");return;case "axisDrag":this.axisDragEnabled=!!t,this.input&&(this.input.axisDrag=this.axisDragEnabled);return;case "paneResize":this.paneResizeEnabled=!!t,this.input&&(this.input.paneResize=this.paneResizeEnabled);return;case "candleZOrder":this.scene.candleZ=Number(t)||0;break;case "candleVisible":this.scene.candlesHidden=t===false;break;case "seriesOrder":this.applySeriesOrder(t);break;case "highlights":this.scene.highlights=vI(t);break;case "sessionZones":this.scene.sessionZones=yI(t);break;case "gridlines":this.scene.showGrid=!!t;break;case "axisLabels":this.scene.showAxisLabels=!!t;break;case "scaleMode":if(t&&typeof t=="object"){let n=t;this.setPaneScaleMode(n.pane??He,Ax(n.mode));return}this.scene.scaleMode=Ax(t);break;case "invertScale":if(t&&typeof t=="object"){let n=t;this.setPaneInvert(n.pane??He,!!n.value);return}this.scene.invertScale=!!t;break;case "autoScale":for(let n of this.scene.panes.values())n.manualScale=t?null:{...n.scale};break;case "timezone":this.scene.timezone=typeof t=="string"&&t?t:"UTC";break;case "priceStyle":this.setPriceStyle(wI(t)?t:"candles");break;case "priceBaseline":this.scene.baselineValue=t==null?null:Number(t);break;case "tradeMarkers":this.scene.tradeMarkers=Wy(this.scene.tradeMarkers,t);break;case "marks":this.scene.marks=qy(this.scene.marks,t),this.markPopover?.close();break;case "keyboard":this.setKeyboardEnabled(!!t);return;case "historyChords":this.historyChordsEnabled=!!t,this.userDrawings&&(this.userDrawings.historyChords=this.historyChordsEnabled);return;case "settings":this.setSettingsEnabled(!!t);return;case "indicatorTitles":this.indicatorTitlesOn=t!==false,this.inputsUI?.setTitlesVisible(this.indicatorTitlesOn);return;case "indicatorValues":this.indicatorValuesOn=t!==false,this.inputsUI?.setValuesVisible(this.indicatorValuesOn);return;case "attribution":this.attributionHtml=typeof t=="string"&&t.trim()?t:null,this.attributionEnabled=this.attributionHtml!==null||!!t,this.rebuildAttribution();return;case "dialogHost":this.dialogHost=t instanceof HTMLElement?t:null,this.settingsDialog?.close(),this.settingsDialog=null,this.inputsUI?.setDialogHost(this.dialogHost);return;default:return}this.scheduler?.invalidate(4);}readFeature(e){switch(e){case "logScale":return this.scene.logScale;case "currentPriceLine":return this.scene.showPriceLine;case "priceLabel":return this.scene.showPriceLabel;case "countdown":return this.scene.showCountdown;case "upColor":return this.candleUp;case "downColor":return this.candleDown;case "glow":return this.glowAmount;case "animZoom":return this.animZoom.tau;case "animPan":return this.animPan.tau;case "animScroll":return this.animScroll.tau;case "animAutoscale":return this.animAutoscale.tau;case "animLiveBar":return this.animLiveBar.tau;case "intro":return this.intro.style;case "zoomAnchor":return this.zoomAnchorMode;case "axisDrag":return this.input?this.input.axisDrag:this.axisDragEnabled;case "paneResize":return this.input?this.input.paneResize:this.paneResizeEnabled;case "candleZOrder":return this.scene.candleZ;case "candleVisible":return !this.scene.candlesHidden;case "seriesOrder":return this.scene.indicatorZOrder();case "highlights":return this.scene.highlights;case "sessionZones":return this.scene.sessionZones;case "gridlines":return this.scene.showGrid;case "axisLabels":return this.scene.showAxisLabels;case "scaleMode":return this.scene.scaleMode;case "invertScale":return this.scene.invertScale;case "paneScales":return this.paneScaleInfos();case "autoScale":{let t=this.scene.orderedPanes().find(n=>n.kind==="price");return t?t.manualScale==null:true}case "timezone":return this.scene.timezone;case "priceStyle":return this.scene.priceStyle;case "priceBaseline":return this.scene.baselineValue;case "baselinePrice":{let t=this.scene.panes.get(He);return t?this.scene.baselinePriceFor(t.scale):this.scene.baselineValue}case "tradeMarkers":return {...this.scene.tradeMarkers,colors:{...this.scene.tradeMarkers.colors}};case "marks":return {visible:this.scene.marks.visible,groups:{...this.scene.marks.groups}};case "keyboard":return this.keyboardEnabled;case "historyChords":return this.historyChordsEnabled;case "settings":return this.settingsEnabled;case "indicatorTitles":return this.indicatorTitlesOn;case "indicatorValues":return this.indicatorValuesOn;case "attribution":return this.attributionHtml??this.attributionEnabled;case "dialogHost":return this.dialogHost??void 0;default:return}}setNativeData(e,t){e==="volume"?(this.scene.volumeLayer=t??null,this.scheduler?.invalidate(3)):e==="vpvr"?(this.scene.vpvrLayer=t??null,this.scheduler?.invalidate(3)):e.endsWith("-pending")?(this.scene.nativePending.set(e.slice(0,-8),t??[]),this.scheduler?.invalidate(3)):(this.scene.nativeData.set(e,t),this.scheduler?.invalidate(3));}setIndicatorStatus(e,t){this.inputsUI.setStatus(e.id,t);}setLoading(e){if(!e||!this.wrapper){this.loadingEl?.remove(),this.loadingEl=null;return}if(this.loadingEl)return;let t=this.wrapper.ownerDocument,n=t.createElement("div");n.className="vela-loading",Object.assign(n.style,{position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",gap:"7px",pointerEvents:"none"});for(let i=0;i<3;i+=1){let o=t.createElement("span");Object.assign(o.style,{width:"7px",height:"7px",borderRadius:"50%",background:this.chromeTheme().textColor,opacity:"0.15"}),o.animate([{opacity:.12},{opacity:.55}],{duration:800,iterations:1/0,direction:"alternate",easing:"ease-in-out",delay:-i*260}),n.appendChild(o);}this.wrapper.appendChild(n),this.loadingEl=n;}setPricePrecision(e){let t=typeof e=="number"&&e>0?e:void 0;t!==this.scene.priceMintick&&(this.scene.priceMintick=t,this.scheduler?.invalidate(4));}getConfig(){let e=this.scene.style,t=Object.fromEntries(Object.entries(e.chartTypes).map(([i,o])=>[i,{...o}])),n=this.theme;return {version:dh,chartTypes:t,layout:{background:n.background,textColor:n.textColor,fontFamily:n.fontFamily,fontSize:e.fontSize},grid:{vertLines:{visible:e.gridVert.visible,color:e.gridVert.color??n.gridColor},horzLines:{visible:e.gridHorz.visible,color:e.gridHorz.color??n.gridColor}},crosshair:{color:e.crosshair.color??n.textColor,width:e.crosshair.width,style:e.crosshair.style,opacity:e.crosshair.opacity,labelBackground:e.crosshair.labelBackground??n.textColor},priceScale:{mode:this.scene.scaleMode,log:this.scene.logScale,invert:this.scene.invertScale,borderColor:e.borderColor??n.borderColor,labelsVisible:this.scene.showAxisLabels,currentPriceLine:this.scene.showPriceLine,priceLabel:this.scene.showPriceLabel,countdown:this.scene.showCountdown,animateLastPrice:this.animLiveBar.on},animations:{zoom:this.animZoom.on,pan:this.animPan.on,autoscale:this.animAutoscale.on,intro:this.intro.style!==false},panes:{separatorColor:e.separatorColor??n.borderColor},trades:{visible:this.scene.tradeMarkers.visible,labels:this.scene.tradeMarkers.labels,qty:this.scene.tradeMarkers.qty,longColor:this.scene.tradeMarkers.colors.long,shortColor:this.scene.tradeMarkers.colors.short,exitColor:this.scene.tradeMarkers.colors.exit},timeScale:{timezone:this.scene.timezone},marks:{visible:this.scene.marks.visible,groups:{...this.scene.marks.groups}},candles:{upColor:this.candleUp,downColor:this.candleDown,bodyVisible:e.candle.bodyVisible,borderVisible:e.candle.borderVisible,borderUpColor:e.candle.borderUpColor??this.candleUp,borderDownColor:e.candle.borderDownColor??this.candleDown,wickVisible:e.candle.wickVisible,wickUpColor:e.candle.wickUpColor??this.candleUp,wickDownColor:e.candle.wickDownColor??this.candleDown},bars:{upColor:e.bars.upColor??this.candleUp,downColor:e.bars.downColor??this.candleDown},line:{color:e.line.color??this.candleUp,width:e.line.width},stacking:{candles:this.scene.candleZ,series:Object.fromEntries(this.scene.indicatorZOrder().map(({id:i,z:o})=>[i,o]))},area:(()=>{let i=e.area.lineColor??this.candleUp;return {lineColor:i,width:e.area.width,topColor:e.area.topColor??i,bottomColor:e.area.bottomColor??rI}})(),baseline:(()=>{let i=e.baseline.topLineColor??Ei,o=e.baseline.bottomLineColor??Li;return {topLineColor:i,bottomLineColor:o,topFillColor:e.baseline.topFillColor??q(i,Cn),topFillColor2:e.baseline.topFillColor2??q(i,Tn),bottomFillColor:e.baseline.bottomFillColor??q(o,Cn),bottomFillColor2:e.baseline.bottomFillColor2??q(o,Tn),width:e.baseline.width,baselineLevel:e.baseline.baselineLevel}})(),series:{style:this.scene.priceStyle,baseline:this.scene.baselineValue,spacing:this.coords.spacingScale},sessions:{premarketColor:e.sessions.premarketColor,postmarketColor:e.sessions.postmarketColor,extendedColor:e.sessions.extendedColor}}}applyConfig(e){let t=ky(this.getConfig(),e),n=this.scene.style;for(let[u,d]of Object.entries(t.chartTypes))if(JSON.stringify(n.chartTypes[u])!==JSON.stringify(d)){this.scene.nativeData.set(`${u}-settings`,{...d});for(let h of this.chartTypeSettingsCbs)h(u,{...d});}n.chartTypes=Object.fromEntries(Object.entries(t.chartTypes).map(([u,d])=>[u,{...d}]));let i=e&&typeof e=="object"?e.layout:void 0,o=i&&typeof i=="object"?i.textColor:void 0,s=typeof o=="string"&&o.trim().length>0,a=this.theme,l={textColor:t.layout.textColor,gridColor:a.gridColor,borderColor:a.borderColor};if(!s&&lt(t.layout.textColor)===lt(t.layout.background)){let u=lt(t.layout.background)?Yt:lo;l={textColor:u.textColor,gridColor:u.gridColor,borderColor:u.borderColor};}this.theme={...this.theme,background:t.layout.background,textColor:l.textColor,gridColor:l.gridColor,borderColor:l.borderColor,fontFamily:t.layout.fontFamily},n.fontSize=t.layout.fontSize;let c=(u,d,h)=>u===null&&d===h?null:d;n.gridVert={visible:t.grid.vertLines.visible,color:c(n.gridVert.color,t.grid.vertLines.color,a.gridColor)},n.gridHorz={visible:t.grid.horzLines.visible,color:c(n.gridHorz.color,t.grid.horzLines.color,a.gridColor)},n.crosshair={color:t.crosshair.color,width:t.crosshair.width,style:t.crosshair.style,opacity:t.crosshair.opacity,labelBackground:t.crosshair.labelBackground},this.scene.scaleMode=t.priceScale.mode,this.scene.logScale=t.priceScale.log,this.scene.invertScale=t.priceScale.invert,n.borderColor=c(n.borderColor,t.priceScale.borderColor,a.borderColor),this.scene.showAxisLabels=t.priceScale.labelsVisible,this.scene.showPriceLine=t.priceScale.currentPriceLine,this.scene.showPriceLabel=t.priceScale.priceLabel,this.scene.showCountdown=t.priceScale.countdown,this.syncCountdownTimer(),this.animLiveBar.toggle(t.priceScale.animateLastPrice),this.animZoom.toggle(t.animations.zoom),this.animPan.toggle(t.animations.pan),this.animScroll.toggle(t.animations.pan),this.animAutoscale.toggle(t.animations.autoscale),this.intro={style:t.animations.intro?this.introOnStyle:false,duration:this.intro.duration||650},n.separatorColor=c(n.separatorColor,t.panes.separatorColor,a.borderColor),this.scene.tradeMarkers={visible:t.trades.visible,labels:t.trades.labels,qty:t.trades.qty,colors:{long:t.trades.longColor,short:t.trades.shortColor,exit:t.trades.exitColor}},this.scene.timezone=t.timeScale.timezone,this.scene.marks={visible:t.marks.visible,groups:{...t.marks.groups}},this.candleUp=t.candles.upColor,this.candleDown=t.candles.downColor,n.candle={bodyVisible:t.candles.bodyVisible,borderVisible:t.candles.borderVisible,borderUpColor:t.candles.borderUpColor,borderDownColor:t.candles.borderDownColor,wickVisible:t.candles.wickVisible,wickUpColor:t.candles.wickUpColor,wickDownColor:t.candles.wickDownColor},this.scene.candleZ=t.stacking.candles;for(let[u,d]of Object.entries(t.stacking.series))this.scene.setIndicatorZ(u,d);n.bars={upColor:t.bars.upColor,downColor:t.bars.downColor},n.line={color:t.line.color,width:t.line.width},n.area={lineColor:t.area.lineColor,width:t.area.width,topColor:t.area.topColor,bottomColor:t.area.bottomColor},n.baseline={topLineColor:t.baseline.topLineColor,bottomLineColor:t.baseline.bottomLineColor,topFillColor:t.baseline.topFillColor,topFillColor2:t.baseline.topFillColor2,bottomFillColor:t.baseline.bottomFillColor,bottomFillColor2:t.baseline.bottomFillColor2,width:t.baseline.width,baselineLevel:t.baseline.baselineLevel},n.sessions={premarketColor:t.sessions.premarketColor,postmarketColor:t.sessions.postmarketColor,extendedColor:t.sessions.extendedColor},this.setPriceStyle(t.series.style),this.scene.candleOverride=bc(this.scene.priceStyle,n.chartTypes),this.scene.baselineValue=t.series.baseline,this.coords.setPitchScale(t.series.spacing),this.coords.setViewport(this.clampViewport(this.coords.getViewport().barSpacing,this.coords.getViewport().rightOffset)),this.targetBarSpacing=this.coords.getViewport().barSpacing,this.theme=this.deriveTheme(this.theme),this.wrapper&&(Re(this.wrapper,this.chromeTheme()),this.applyBackground()),this.inputsUI?.setTheme(this.theme),this.paneControls?.setTheme(this.theme),this.axisScaleButtons?.setTheme(this.theme),this.userDrawings?.setTheme(this.chromeTheme()),this.refreshScrollButtonTheme(),this.refreshAttributionColor(),this.scheduler?.invalidate(4);for(let u of this.configChangedCbs)u();}applySeriesOrder(e){if(!e||typeof e!="object")return;let t=e;typeof t.id=="string"&&(typeof t.z=="number"?this.scene.setIndicatorZ(t.id,t.z):t.to==="front"?this.scene.bringIndicatorToFront(t.id):t.to==="back"&&this.scene.sendIndicatorToBack(t.id));}setSettingsEnabled(e){this.settingsEnabled=e,e?(this.plot&&!this.settingsButton&&(this.settingsButton=this.makeSettingsButton(),this.plot.appendChild(this.settingsButton)),this.settingsButton&&(this.settingsButton.style.display="flex"),this.plot&&!this.settingsDialog&&(this.settingsDialog=new vs(this.dialogHost??this.plot,this.theme))):(this.settingsButton?.style.setProperty("display","none"),this.settingsDialog?.close());}makeSettingsButton(){let e=document.createElement("button");return e.type="button",e.title="Chart settings",e.innerHTML=ye("gear",14),Object.assign(e.style,{position:"absolute",bottom:`${Hi+10}px`,right:`${au+10}px`,zIndex:"6",width:"26px",height:"26px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",borderRadius:"50%",border:`1px solid ${this.theme.borderColor}`,background:this.theme.background,color:this.theme.textColor,fontSize:"14px",lineHeight:"1",opacity:"0.75",pointerEvents:"auto",padding:"0"}),e.addEventListener("mouseenter",()=>e.style.opacity="1"),e.addEventListener("mouseleave",()=>e.style.opacity="0.75"),e.addEventListener("click",()=>this.toggleSettingsDialog()),e}openSettingsDialog(e){!this.settingsDialog&&this.plot&&(this.settingsDialog=new vs(this.dialogHost??this.plot,this.theme),this.settingsDialog.setLayoutMode(this.layoutMode)),this.toggleSettingsDialog(e);}syncThemeControl(){this.settingsDialog?.setThemeControl(lt(this.surfaceBackground)?"dark":"light",e=>{for(let t of this.themeSelectCbs)t(e);});}toggleSettingsDialog(e){if(this.settingsDialog){if(e!==void 0&&this.settingsDialog.isOpen()){this.settingsDialog.showSection(e);return}this.settingsDialog.setTheme(this.theme),this.settingsDialog.setHostSections(this.hostSettingsSections),this.settingsDialog.setMarkGroups(this.markGroupsInUse(),t=>Lc(this.scene.marks,t,this.scene.markGroups)),this.settingsDialog.setHiddenSettings(this.hiddenSettings),this.syncThemeControl(),this.settingsDialog.toggle(this.getConfig(),t=>this.applyConfig(t),t=>this.applyConfig(t),()=>{this.factoryConfig&&this.applyConfig(Ty(this.factoryConfig)),this.settingsDialog?.close(),this.openSettingsDialog();},e);}}closeDialogs(){this.inputsUI?.closeOpenDialog(),this.settingsDialog?.close();}makeScrollToRealtimeButton(){let e=document.createElement("button");return e.type="button",e.title="Scroll to most recent bar (Alt+Shift+\u2192)",e.setAttribute("aria-label","Scroll to most recent bar"),e.innerHTML=this.scrollButtonIcon(),Object.assign(e.style,{position:"absolute",bottom:`${ap}px`,right:`${Mx}px`,zIndex:"6",width:`${ks}px`,height:`${ks}px`,boxSizing:"border-box",display:"none",alignItems:"center",justifyContent:"center",cursor:"pointer",borderRadius:`${oI}px`,border:`1px solid ${this.theme.borderColor}`,boxShadow:sI,background:this.scrollButtonSurface(),color:this.theme.textColor,lineHeight:"0",opacity:"0.85",pointerEvents:"auto",padding:"0"}),e.addEventListener("mouseenter",()=>e.style.opacity="1"),e.addEventListener("mouseleave",()=>e.style.opacity="0.85"),e.addEventListener("click",()=>this.scrollToRealtime()),e}scrollButtonIcon(){return ye("chevrons-right",aI)}scrollButtonSurface(){return q(this.theme.background,.5)}refreshScrollButtonTheme(){this.scrollButton&&(this.scrollButton.style.background=this.scrollButtonSurface(),this.scrollButton.style.color=this.theme.textColor,this.scrollButton.style.borderColor=this.theme.borderColor);}updateScrollToRealtimeButton(){let e=this.scrollButton;if(!e)return;let t=this.coords.barCount>0&&this.coords.getViewport().rightOffset<0;if(this.layoutMode==="mobile"){e.style.display=t?"flex":"none";return}e.style.display=t&&this.pointerNearScrollBtn?"flex":"none";}scrollToRealtime(){this.coords.barCount!==0&&this.glideRightOffset(Px);}glideRightOffset(e){let t=this.coords.getViewport();if(!this.animScroll.on){this.applyViewport({barSpacing:t.barSpacing,rightOffset:e});return}this.panVelocity=0,this.targetBarSpacing=t.barSpacing,this.scrollTargetRO=e,this.animator.start();}screenshotCanvas(){if(!this.dataCanvas)return null;this.computeScales(),this.paintData();let e=document.createElement("canvas");e.width=this.dataCanvas.width,e.height=this.dataCanvas.height;let t=e.getContext("2d");if(!t)return null;t.fillStyle=this.theme.background,t.fillRect(0,0,e.width,e.height);let n=this.plot?.getBoundingClientRect(),i=n&&n.width>0?{left:n.left,top:n.top,dpr:e.width/n.width}:null,o=[...this.mountContainer?.querySelectorAll("[data-vela-screenshot]")??[]];if(i)for(let s of o)s.getAttribute("data-vela-screenshot")==="under"&&ou(t,s,i);for(let s of [...this.canvasPile(),this.chromeCanvas,this.drawingsCanvas])s&&s.width>0&&s.height>0&&t.drawImage(s,0,0);if(i){for(let s of this.plot?.querySelectorAll("[data-vela-pane]")??[])ou(t,s,i);for(let s of o)s.getAttribute("data-vela-screenshot")!=="under"&&ou(t,s,i);}return e}screenshot(){return this.screenshotCanvas()?.toDataURL("image/png")??null}playIntro(){this.introRaf!=null&&cancelAnimationFrame(this.introRaf),this.introRaf=null;let{style:e,duration:t}=this.intro,n=this.bars,i=n.length;if(i===0||!e)return;this.computeScales();for(let a of this.scene.panes.values())a.scale={...a.scaleTarget};this.modelAlpha=0;let o=performance.now(),s=a=>{let l=Math.min(1,(a-o)/t);this.scene.bars=l>=1?n:n.map((c,u)=>this.revealCandle(c,u,l,i,e)),this.paintData(),l<1?this.introRaf=requestAnimationFrame(s):(this.scene.bars=n,this.fadeInModels());};this.introRaf=requestAnimationFrame(s);}fadeInModels(){let e=Math.min(Ix,this.intro.duration||Ix),t=performance.now(),n=i=>{this.modelAlpha=Math.min(1,(i-t)/e),this.paintData(),this.modelAlpha<1?this.introRaf=requestAnimationFrame(n):(this.modelAlpha=1,this.introRaf=null);};this.introRaf=requestAnimationFrame(n);}revealCandle(e,t,n,i,o){let a=Math.max(0,Math.min(1,(n-t/Math.max(1,i-1)*.55)/.44999999999999996)),l;if(o==="settle"){let d=a-1;l=1+(1.70158+1)*d*d*d+1.70158*d*d;}else {let u=1-a;l=1-u*u*u;}let c=e.open;return {...e,high:c+(e.high-c)*l,low:c+(e.low-c)*l,close:c+(e.close-c)*l}}deriveTheme(e){return {...e,upColor:this.candleUp,downColor:this.candleDown}}chromeTheme(){return {...this.theme,background:this.surfaceBackground,textColor:this.surfaceTextColor,borderColor:lt(this.surfaceBackground)?Yt.borderColor:lo.borderColor}}axisSurface(){return {background:this.theme.background,textColor:this.theme.textColor}}mount(e,t){this.mountContainer=e,this.publishGutters(),this.theme=this.deriveTheme(t),this.surfaceBackground=t.background,this.surfaceTextColor=t.textColor,this.wrapper=document.createElement("div"),Object.assign(this.wrapper.style,{position:"relative",width:"100%",height:"100%",overflow:"hidden",cursor:"crosshair",userSelect:"none",webkitUserSelect:"none"}),Re(this.wrapper,this.chromeTheme()),this.backdropCanvas=document.createElement("canvas"),Object.assign(this.backdropCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.volumeCanvas=document.createElement("canvas"),Object.assign(this.volumeCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.dataCanvas=this.createGeometryBackend(),this.vpvrCanvas=document.createElement("canvas"),Object.assign(this.vpvrCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.chromeCanvas=document.createElement("canvas"),Object.assign(this.chromeCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.drawingsCanvas=document.createElement("canvas"),Object.assign(this.drawingsCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.cursorCanvas=document.createElement("canvas"),Object.assign(this.cursorCanvas.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),this.overlayRoot=document.createElement("div"),Object.assign(this.overlayRoot.style,{position:"absolute",inset:"0",pointerEvents:"none"}),this.plot=document.createElement("div"),Object.assign(this.plot.style,{position:"absolute",top:"0",right:"0",bottom:"0",left:"0"}),this.extLayers=tp().map(o=>({def:o,instance:o.create(),canvas:this.createLayerCanvas(),channel:o.id,owner:null}));let n=this.extLayers.filter(o=>o.def.placement==="below-data").map(o=>o.canvas),i=this.extLayers.filter(o=>o.def.placement!=="below-data").map(o=>o.canvas);this.plot.append(this.backdropCanvas,...n,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...i,this.chromeCanvas,this.drawingsCanvas,this.cursorCanvas,this.overlayRoot),this.layerOrderSig="",this.wrapper.appendChild(this.plot),this.factoryConfig=this.getConfig(),this.attributionEl=this.buildAttributionEl(),this.attributionEnabled||(this.attributionEl.style.display="none"),this.positionAttribution(),this.wrapper.appendChild(this.attributionEl),e.appendChild(this.wrapper),this.applyBackground(),this.backdropRenderer.mount(this.backdropCanvas),this.volumeRenderer.mount(this.volumeCanvas),this.vpvrRenderer.mount(this.vpvrCanvas);for(let o of this.extLayers)o.instance.mount(o.canvas);for(let o of this.scene.indicators.values())this.ensureInstanceLayer(o);this.chrome.mount(this.chromeCanvas),this.crosshairLayer.mount(this.cursorCanvas),this.coords.setViewport(cs()),this.scene.ensurePane(He,"price",0,3),this.scheduler=new Sc(o=>this.renderFrame(o)),this.animator=new Cc(o=>this.animTick(o)),this.targetBarSpacing=this.coords.getViewport().barSpacing,this.input=new Tc({getCoords:()=>this.coords,apply:o=>this.applyViewport(o),zoomTo:(o,s,a)=>this.zoomTo(o,s,a),fling:o=>this.fling(o),onPointerMove:(o,s)=>this.handlePointerMove(o,s),onClick:(o,s)=>{this.handleMarkClick(o,s)||(this.userDrawings?.deselect(),this.handleClick(o));},onAxisLongPress:(o,s,a)=>{for(let l of this.axisLongPressCbs)l({axis:o,x:s,y:a});},beginPriceScale:(o,s)=>this.beginPriceScale(o,s),priceScaleBy:o=>this.priceScaleBy(o),beginPricePan:o=>this.beginPricePan(o),pricePanBy:o=>this.pricePanBy(o),resetPriceScale:(o,s)=>this.resetPriceScale(o,s),dataDblClick:(o,s)=>this.dataDblClick(o,s),paneSeparatorAt:o=>this.paneSeparatorAt(o),beginPaneResize:o=>this.beginPaneResize(o),paneResizeBy:o=>this.paneResizeBy(o),resetPaneSize:o=>this.resetPaneSize(o),resetView:()=>this.resetView(),drawingsClaim:(o,s)=>this.userDrawings?.claim(o,s)??false,drawingsMeasureStart:(o,s,a)=>this.userDrawings?.beginMeasureAt(o,s,a)??false,drawingsMarqueeStart:(o,s)=>this.userDrawings?.beginMarqueeAt(o,s)??false,drawingsDeleteAt:(o,s)=>this.userDrawings?.deleteAt(o,s,true)??false,drawingsCancelPlacement:()=>this.userDrawings?.cancelPlacement()??false,drawingsSnapMode:()=>this.snapMode,drawingsPointerDown:(o,s,a,l,c)=>this.userDrawings?.pointerDown(o,s,a,l,c),drawingsPointerMove:(o,s,a,l,c)=>this.userDrawings?.pointerMove(o,s,a,l,c),drawingsPointerUp:(o,s,a)=>this.userDrawings?.pointerUp(o,s,a),drawingsCursor:(o,s)=>this.userDrawings?.cursorAt(o,s)??(this.chrome.markGlyphAt(o,s)?"pointer":null),drawingsDblClick:(o,s)=>this.userDrawings?.dblClick(o,s)??false,drawingsClearTransient:()=>this.userDrawings?.clearTransient()}),this.input.rightEdgeZoom=this.zoomAnchorMode==="right",this.input.axisDrag=this.axisDragEnabled,this.input.paneResize=this.paneResizeEnabled,this.input.attach(this.dataCanvas),this.settingsEnabled&&this.setSettingsEnabled(true),this.syncCountdownTimer(),this.scrollButton=this.makeScrollToRealtimeButton(),this.plot.appendChild(this.scrollButton),this.plot.addEventListener("pointermove",this.onScrollProximityMove),this.plot.addEventListener("pointerleave",this.onScrollProximityLeave),this.labelTooltip=new _c(this.plot,{theme:()=>this.chromeTheme(),lookup:(o,s)=>this.indicatorSlices.labelTooltipAt(o,s)??this.chrome.markTooltipAt(o,s,this.markGroupsInUse())}),this.markPopover=new tu({plot:this.plot,host:()=>this.dialogHost??this.plot,theme:()=>this.chromeTheme(),onOpenChange:o=>{this.scene.marksActiveKey=o,this.scheduler?.invalidate(2);}}),this.chrome.setMarkIconReady(()=>this.scheduler?.invalidate(2)),this.userDrawings=new Zc(this.wrapper,this.plot,this.drawingsCanvas,{projector:()=>this.drawingProjector(),dpr:()=>this.coords.dpr,theme:()=>this.theme,requestScaleUpdate:()=>this.scheduler.invalidate(3),seriesBoundaries:o=>this.scene.seriesBoundaries(o),priceZ:o=>o===He?this.scene.candleZ:null,requestDataPaint:()=>this.scheduler.invalidate(3),seriesLook:()=>{let o=this.scene.style,s=Mi(o.candle,this.scene.candleOverride,this.theme.upColor,this.theme.downColor),a=o.bars.upColor??this.theme.upColor,l=o.bars.downColor??this.theme.downColor,c=this.scene.priceStyle;return {style:c,upColor:c==="bars"?a:s.up,downColor:c==="bars"?l:s.down,lineColor:c==="area"?o.area.lineColor??this.theme.upColor:o.line.color??this.theme.upColor}},chartBarMs:()=>this.coords.barInterval,snap:(o,s,a,l)=>this.snapToCandle(o,s,a,l),setSnapMode:o=>this.setSnapMode(o),setToolbarGutter:o=>this.setToolbarGutter(o)}),this.userDrawings.historyChords=this.historyChordsEnabled,this.layoutMode==="mobile"&&(this.mountContainer?.setAttribute("data-vela-layout",this.layoutMode),this.userDrawings.setLayoutMode(this.layoutMode),this.scrollButton&&(this.scrollButton.style.width=`${sp}px`,this.scrollButton.style.height=`${sp}px`)),this.keyboard=new kc({panByBars:o=>this.panByBars(o),zoomByStep:o=>this.zoomByStep(o),stepCrosshair:o=>this.stepCrosshair(o),jumpToEdge:o=>this.focusBar(o==="first"?0:this.coords.barCount-1),resetView:()=>this.resetView(),scrollToRealtime:()=>this.scrollToRealtime(),clearCrosshair:()=>this.handlePointerMove(null,null),preempt:o=>this.userDrawings?.handleKey(o)??false}),this.setKeyboardEnabled(this.keyboardEnabled),this.inputsUI=new hc(this.plot,t,o=>this.paneBoundsFor(o)),this.inputsUI.setLayoutMode(this.layoutMode),this.inputsUI.setTitlesVisible(this.indicatorTitlesOn),this.inputsUI.setValuesVisible(this.indicatorValuesOn),this.inputsUI.setDialogHost(this.dialogHost),this.inputsUI.setSymbolPicker(this.symbolPicker),this.inputsUI.setLegendActions(this.legendActionsProvider),this.inputsUI.setLegendCallouts(this.legendCalloutsProvider),this.inputsUI.setLegendOverviewAction(this.legendOverviewAction),this.inputsUI.setOnChange(o=>{for(let s of this.inputChangeCbs)s({indicatorId:o.indicatorId,key:o.key,value:o.value,...o.kind?{kind:o.kind}:{}});}),this.inputsUI.setOnRemove(o=>{for(let s of this.removeIndicatorCbs)s(o);}),this.inputsUI.setOnToggleVisible((o,s)=>{for(let a of this.toggleVisibleCbs)a(o,s);}),this.inputsUI.setMoveApi({panes:()=>this.scene.orderedPanes().map((o,s)=>({id:o.id,kind:o.kind,label:o.kind==="price"?"Main chart":this.paneMasterTitle(o.id)??`Pane ${s}`,top:o.bounds.top,height:o.bounds.height})),move:(o,s)=>{for(let a of this.moveIndicatorCbs)a(o,s);}}),this.paneControls=new pc(this.plot,t,{panes:()=>this.paneControlViews(),rightAxis:()=>this.rightAxisW,onMove:(o,s)=>this.movePaneLocal(o,s),onToggleCollapse:o=>{let s=this.scene.panes.get(o);if(!s)return;let a=!s.collapsed;s.collapsed=a,this.afterPaneLayoutChange(),this.emitPaneAction({type:"collapse",paneId:o,collapsed:a});},onToggleMaximize:o=>{let s=this.maximizedPaneId!==o;this.maximizedPaneId=s?o:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:o,maximized:s});}}),this.paneControls.setSuspended(this.layoutMode==="mobile"),this.axisScaleButtons=new mc(this.plot,t,{panes:()=>this.axisScaleViews(),rightAxis:()=>this.rightAxisW,onToggleAuto:o=>this.togglePaneAuto(o),onToggleLog:o=>{let s=this.scene.panes.get(o);s&&this.setPaneLog(o,!Ri(this.scene,s));}}),this.resizeObserver=new ResizeObserver(o=>{for(let s of o){if(s.target!==this.plot)continue;let a=s.devicePixelContentBoxSize?.[0];a&&(this.plotDeviceSize={width:a.inlineSize,height:a.blockSize});}this.resize();}),this.resizeObserver.observe(this.wrapper);try{this.resizeObserver.observe(this.plot,{box:"device-pixel-content-box"});}catch{}this.watchDpr(),this.syncSize();}makeDataCanvas(){let e=document.createElement("canvas");return Object.assign(e.style,{position:"absolute",inset:"0",width:"100%",height:"100%"}),e}createGeometryBackend(){if((this.backendMode==="auto"||this.backendMode==="webgl2")&&wy()){let n=this.makeDataCanvas(),i=new wc;if(i.glow=this.glowAmount,i.onNeedsRedraw=()=>this.scheduler?.invalidate(4),i.onContextFailed=()=>this.swapToCanvas2dFallback(),i.mount(n),i.ok)return this.backend=i,n;i.destroy();}let e=this.makeDataCanvas(),t=new us;return t.mount(e),this.backend=t,e}swapToCanvas2dFallback(){if(this.backend.kind==="canvas2d")return;let e=this.dataCanvas;this.input?.detach(),this.backend.destroy();let t=this.makeDataCanvas(),n=new us;n.mount(t),this.backend=n,e.replaceWith(t),this.dataCanvas=t,this.input?.attach(t),this.syncSize();}watchDpr(){typeof window.matchMedia=="function"&&(this.dprMedia?.removeEventListener("change",this.onDprChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDprChange,{once:true}));}setTheme(e){this.theme=this.deriveTheme(e),this.surfaceBackground=e.background,this.surfaceTextColor=e.textColor,this.wrapper&&Re(this.wrapper,this.chromeTheme()),this.applyBackground(),this.inputsUI.setTheme(e),this.paneControls?.setTheme(this.theme),this.axisScaleButtons?.setTheme(this.theme),this.settingsDialog?.refreshConfig(this.getConfig()),this.syncThemeControl(),this.settingsDialog?.setTheme(this.theme),this.settingsButton&&(this.settingsButton.style.background=this.theme.background,this.settingsButton.style.color=this.theme.textColor,this.settingsButton.style.borderColor=this.theme.borderColor),this.refreshScrollButtonTheme(),this.userDrawings?.setTheme(this.chromeTheme()),this.refreshAttributionColor(),this.scheduler.invalidate(4);}resize(){this.syncSize();}setWallClock(e){e!==this.hostClock&&(this.hostClock=e,this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null),this.syncCountdownTimer());}syncCountdownTimer(){if(this.scene.showCountdown){if(this.countdownUnsub==null){let e=this.hostClock??this.ownClock??(this.ownClock=new yo);this.countdownUnsub=e.onTick(()=>{this.scene.showCountdown&&this.scene.bars.length>0&&this.scheduler?.invalidate(2);});}}else this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null);}destroy(){this.introRaf!=null&&cancelAnimationFrame(this.introRaf),this.loadingEl?.remove(),this.loadingEl=null,this.countdownUnsub!=null&&(this.countdownUnsub(),this.countdownUnsub=null),this.scheduler?.destroy(),this.animator?.stop(),this.input?.detach(),this.keyboard?.detach(),this.keyboard=null,this.liveRegion=null,this.inputsUI?.destroy(),this.paneControls?.destroy(),this.axisScaleButtons?.destroy(),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.dprMedia?.removeEventListener("change",this.onDprChange),this.dprMedia=null,this.userDrawings?.destroy(),this.userDrawings=null,this.settingsDialog?.destroy(),this.settingsDialog=null,this.settingsButton?.remove(),this.settingsButton=null,this.plot?.removeEventListener("pointermove",this.onScrollProximityMove),this.plot?.removeEventListener("pointerleave",this.onScrollProximityLeave),this.labelTooltip?.destroy(),this.labelTooltip=null,this.markPopover?.destroy(),this.markPopover=null,this.chrome.setMarkIconReady(null),this.markPulseRaf!==null&&cancelAnimationFrame(this.markPulseRaf),this.markPulseRaf=null,this.scrollButton?.remove(),this.scrollButton=null;for(let e of this.extLayers)e.instance.destroy?.();this.extLayers=[],this.backdropRenderer.destroy(),this.volumeRenderer.destroy(),this.vpvrRenderer.destroy(),this.backend.destroy(),this.chrome.destroy(),this.crosshairLayer.destroy(),this.attributionEl?.remove(),this.attributionEl=null,this.mountContainer?.style.removeProperty("--vela-toolbar-gutter"),this.mountContainer?.style.removeProperty("--vela-scale-gutter"),this.mountContainer?.style.removeProperty("--vela-bottom-gutter"),this.mountContainer?.style.removeProperty("--vela-price-pane-top"),this.mountContainer?.style.removeProperty("--vela-price-pane-bottom"),this.mountContainer=null,this.wrapper?.remove();}setBars(e,t){this.introRaf!=null&&(cancelAnimationFrame(this.introRaf),this.introRaf=null,this.modelAlpha=1),this.liveEaseTime=0;let n=this.bars,i=n[0]?.time;this.bars=xI(e),this.scene.bars=this.bars,this.coords.setBars(this.bars.map(s=>s.time));for(let s of this.scene.indicators.values())this.refreshAnchorOffset(s);if(t?.preserveView===true&&i!=null&&this.bars.length>0){let s=this.bars[0].time,a=0;if(s!==i){let l=this.bars.findIndex(c=>c.time===i);if(l>0)a=l;else {let c=n.findIndex(u=>u.time===s);c>0&&(a=-c);}}a!==0&&(this.zoomAnchorLogical+=a,this.hoverLogical!=null&&(this.hoverLogical+=a));}let o=t?.preserveView===true&&this.didInitialFit;if(this.coords.width>0&&!o&&(this.didInitialFit?this.reframeKeepZoom():this.fitContent(),this.didInitialFit=true),!this.introPlayed&&this.bars.length>0&&(this.introPlayed=true,this.intro.style)){this.playIntro();return}this.scheduler.invalidate(4);}updateBar(e){let t=this.bars.length,n=this.bars[t-1];if(n&&e.time===n.time)this.bars[t-1]=e,!this.animLiveBar.on||this.liveEaseTime!==e.time?this.syncLiveEase(e):this.animator.start();else if(!n||e.time>n.time)this.bars.push(e),this.syncLiveEase(e),this.coords.barInterval>0?this.coords.appendBar(e.time):this.coords.setBars(this.bars.map(i=>i.time));else return;this.scene.bars=this.bars,this.scheduler.invalidate(4);}setIntro(e){this.intro=e,e.style&&(this.introOnStyle=e.style);}syncLiveEase(e){this.liveEaseTime=e.time,this.liveEaseHigh=e.high,this.liveEaseLow=e.low,this.liveEaseClose=e.close;}easeLiveBar(e){let t=this.bars[this.bars.length-1];if(!t||this.liveEaseTime!==t.time)return false;let n=Math.max(1e-9,Math.abs(t.close)*1e-6),i=this.animLiveBar.tau,o=vt(this.liveEaseHigh,t.high,e,i),s=vt(this.liveEaseLow,t.low,e,i),a=vt(this.liveEaseClose,t.close,e,i),l=Math.abs(o-t.high)>n||Math.abs(s-t.low)>n||Math.abs(a-t.close)>n;return this.liveEaseHigh=l?o:t.high,this.liveEaseLow=l?s:t.low,this.liveEaseClose=l?a:t.close,l}ensurePane(e){this.scene.ensurePane(e.id,e.kind,e.order,e.heightWeight??(e.kind==="price"?3:1)),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}removePane(e){e!==He&&(this.scene.removePane(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null),this.refreshAxisWidth(),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}setIndicatorPane(e,t,n){let i=this.scene.indicators.get(e.id);i&&(i.paneId=t,i.ownScale=n?.ownScale===true,i.ownScale||this.scene.dropIndicatorScale(e.id),this.inputsUI.setPane(e.id,t),this.refreshAnchorOffset(i),this.refreshAxisWidth(),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}orderPanes(e){this.scene.orderPanes(e),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}setPaneCollapsed(e,t){let n=this.scene.panes.get(e);!n||n.collapsed===t||(n.collapsed=t,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4));}setPaneMaximized(e){e!==null&&!this.scene.panes.has(e)&&(e=null),this.maximizedPaneId=e,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}onPaneAction(e){return this.paneActionCbs.add(e),()=>this.paneActionCbs.delete(e)}emitPaneAction(e){for(let t of this.paneActionCbs)t(e);}onMoveIndicator(e){return this.moveIndicatorCbs.add(e),()=>this.moveIndicatorCbs.delete(e)}maxOwnScaleColumns(){let e=0;for(let t of this.scene.panes.values()){let n=this.scene.ownScaleIndicatorsForPane(t.id).length;n>e&&(e=n);}return e}refreshAxisWidth(){let e=au+iI*this.maxOwnScaleColumns();return e===this.rightAxisW?false:(this.rightAxisW=e,this.publishGutters(),this.coords.width>0&&this.syncSize(),true)}refreshAnchorOffset(e){let t=e.anchorTime;if(t==null||this.bars.length===0){this.scene.setAnchorOffset(e.id,0);return}let n=this.bars[0].time;if(t===n){this.scene.setAnchorOffset(e.id,0);return}if(t<n){let a=fI(e,n);if(a==null){console.warn(`[vela] indicator "${e.id}" starts before the first bar with no series to align on \u2014 rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,-a);return}let i=0,o=this.bars.length-1,s=this.bars.length;for(;i<=o;){let a=i+o>>1;this.bars[a].time>=t?(s=a,o=a-1):i=a+1;}if(s>=this.bars.length||this.bars[s].time!==t){console.warn(`[vela] indicator "${e.id}" anchorTime matches no chart bar \u2014 rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,s);}mountIndicator(e){return this.scene.indicators.set(e.id,e),this.refreshAnchorOffset(e),e.native&&this.extLayers.some(t=>t.def.id===e.native.type)?this.scene.assignIndicatorZTop(e.id):this.scene.assignIndicatorZ(e.id),this.ensureInstanceLayer(e),e.legend!==false&&this.inputsUI.upsert(e.id,e.shorttitle??e.title,e.inputs,e.inputValues,e.paneId,{native:!!e.native,...e.props?{props:e.props,propValues:e.propValues??{}}:{}}),e.native?.type==="volume"?(this.volumeActive=true,this.volumeHidden=false):e.native?.type==="vpvr"&&(this.vpvrActive=true,this.vpvrHidden=false),e.ownScale&&this.refreshAxisWidth(),this.paneControls?.refresh(),this.scheduler.invalidate(4),{id:e.id}}updateIndicator(e,t){let n=this.scene.indicators.get(e.id);if(n){if(t.kind==="value"&&t.anchorTime!==void 0){let i=t.anchorTime??void 0;i!==n.anchorTime&&(n.anchorTime=i,this.refreshAnchorOffset(n));}gI(n,t),this.scheduler.invalidate(3);}}removeIndicator(e){let t=this.scene.indicators.get(e.id)?.native?.type;t==="volume"?(this.volumeActive=false,this.volumeHidden=false,this.scene.volumeLayer=null):t==="vpvr"&&(this.vpvrActive=false,this.vpvrHidden=false,this.scene.vpvrLayer=null),this.scene.indicators.delete(e.id),this.dropInstanceLayer(e.id),this.scene.forgetIndicatorZ(e.id),this.scene.forgetAnchorOffset(e.id),this.scene.dropIndicatorScale(e.id),this.inputsUI.remove(e.id),this.refreshAxisWidth(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}setIndicatorInputs(e,t,n){this.inputsUI.setValues(e.id,t,n);}setSymbolPicker(e){this.symbolPicker=e,this.inputsUI?.setSymbolPicker(e);}setLegendActions(e){this.legendActionsProvider=e,this.inputsUI?.setLegendActions(e);}setLegendCallouts(e){this.legendCalloutsProvider=e,this.inputsUI?.setLegendCallouts(e);}setLegendOverviewAction(e){this.legendOverviewAction=e,this.inputsUI?.setLegendOverviewAction(e);}openIndicatorSettings(e){this.inputsUI?.openSettingsFor(e);}setIndicatorVisible(e,t){let n=this.scene.indicators.get(e.id)?.native?.type;if(n==="volume"||n==="vpvr"){n==="volume"?this.volumeHidden=!t:this.vpvrHidden=!t,this.inputsUI.setVisible(e.id,t),this.scheduler.invalidate(4);return}t||this.scene.indicators.delete(e.id),this.inputsUI.setVisible(e.id,t),this.scheduler.invalidate(4);}onInputChange(e){return this.inputChangeCbs.add(e),()=>this.inputChangeCbs.delete(e)}onToggleIndicatorVisible(e){return this.toggleVisibleCbs.add(e),()=>this.toggleVisibleCbs.delete(e)}onPriceStyleChange(e){return this.priceStyleCbs.add(e),()=>this.priceStyleCbs.delete(e)}setPriceStyle(e){if(e!==this.scene.priceStyle){this.scene.priceStyle=e,this.scene.basePainting=hh(e),this.scene.candleOverride=bc(e,this.scene.style.chartTypes);for(let t of this.priceStyleCbs)t(e);}}onRemoveIndicator(e){return this.removeIndicatorCbs.add(e),()=>this.removeIndicatorCbs.delete(e)}setLayoutMode(e){if(e!==this.layoutMode){if(this.layoutMode=e,this.mountContainer?.setAttribute("data-vela-layout",e),this.userDrawings?.setLayoutMode(e),this.settingsDialog?.setLayoutMode(e),this.inputsUI?.setLayoutMode(e),this.paneControls?.setSuspended(e==="mobile"),this.scrollButton){let t=e==="mobile"?sp:ks;this.scrollButton.style.width=`${t}px`,this.scrollButton.style.height=`${t}px`;}this.updateScrollToRealtimeButton();}}setSettingsSections(e){this.hostSettingsSections=e,this.settingsDialog?.setHostSections(e);}setSettingsVisibility(e){this.hiddenSettings=[...e.hidden??[]],this.settingsDialog?.setHiddenSettings(this.hiddenSettings);}listSettingsIds(){return Sw(this.hostSettingsSections,this.markGroupsInUse())}onChartTypeSettingsChange(e){return this.chartTypeSettingsCbs.add(e),()=>this.chartTypeSettingsCbs.delete(e)}onConfigChanged(e){return this.configChangedCbs.add(e),()=>this.configChangedCbs.delete(e)}onThemeSelect(e){return this.themeSelectCbs.add(e),()=>this.themeSelectCbs.delete(e)}onCrosshairMove(e){return this.crosshairCbs.add(e),()=>this.crosshairCbs.delete(e)}onClick(e){return this.clickCbs.add(e),()=>this.clickCbs.delete(e)}onAxisLongPress(e){return this.axisLongPressCbs.add(e),()=>this.axisLongPressCbs.delete(e)}setTimelineMarks(e,t){this.scene.timelineMarks=e,this.scene.markGroups=t,this.scene.marksExpandedStack=null,this.markPopover?.close(),this.scheduler?.invalidate(2);}onMarkClick(e){return this.markClickCbs.add(e),()=>this.markClickCbs.delete(e)}markGroupsInUse(){return mw(this.scene.timelineMarks,this.scene.markGroups)}onViewportChange(e){return this.viewportCbs.add(e),()=>this.viewportCbs.delete(e)}getVisibleRange(){let e=this.coords.barCount;if(e===0||this.coords.width===0)return null;let t=this.coords.visibleLogicalRange(),n=Math.max(0,Math.ceil(t.from)),i=Math.min(e-1,Math.floor(t.to));return i<n?null:{from:this.coords.logicalToTime(n),to:this.coords.logicalToTime(i)}}setVisibleRange(e){let t=this.coords.timeToLogical(e.from),n=this.coords.timeToLogical(e.to),i=Math.max(1e-6,n-t),o=rn(this.coords.width/(i*this.coords.spacingScale)),s=n-(this.coords.barCount-1);this.applyViewport({barSpacing:o,rightOffset:s});}panBy(e){if(this.coords.barCount===0||this.coords.width===0)return;let t=this.coords.getViewport(),n=this.coords.width/this.coords.pxPerBar(),i=this.scrollTargetRO??t.rightOffset;this.glideRightOffset(this.clampViewport(t.barSpacing,i+e*n).rightOffset);}applyViewport(e){this.animator.stop(),this.panVelocity=0,this.scrollTargetRO=null;let t=this.clampViewport(e.barSpacing,e.rightOffset);this.coords.setViewport(t),this.targetBarSpacing=t.barSpacing,this.scheduler.invalidate(4),this.emitViewportChange();}zoomTo(e,t,n){let i=this.clampViewport(e,this.coords.getViewport().rightOffset).barSpacing;if(this.zoomAnchorLogical=t,this.zoomAnchorX=n,this.panVelocity=0,this.scrollTargetRO=null,!this.animZoom.on){let o=this.clampViewport(i,this.anchoredRightOffset(i));this.coords.setViewport(o),this.targetBarSpacing=o.barSpacing,this.scheduler.invalidate(4),this.emitViewportChange();return}this.targetBarSpacing=i,this.animator.start();}fling(e){this.animPan.on&&(this.scrollTargetRO=null,this.panVelocity=e,this.animator.start());}anchoredRightOffset(e){let t=e*this.coords.spacingScale;return this.zoomAnchorLogical+(this.coords.width-this.zoomAnchorX)/t-(this.coords.barCount-1)}clampViewport(e,t){let n=this.coords.barCount,i=this.coords.width;if(n<=1||i<=0)return {barSpacing:rn(e),rightOffset:t};let o=Math.min(cI,n),s=this.coords.spacingScale,a=Math.min(1e3,i/(o*s)),l=Math.max(.5,Math.min(a,i/((n+Px)*s))),c=Math.max(l,Math.min(a,e)),d=i/(c*s)-(o-1),h=o-n,p=Math.max(h,Math.min(d,t));return {barSpacing:c,rightOffset:p}}animTick(e){let t=this.coords.getViewport(),n=t.barSpacing,i=t.rightOffset,o=false,s=this.targetBarSpacing;Math.abs(n-s)>s*.001?(n=rn(vt(n,s,e,this.animZoom.tau)),i=this.anchoredRightOffset(n),o=true):n!==s&&(n=s,i=this.anchoredRightOffset(n));let a=uI/Math.max(1e-6,n*this.coords.spacingScale);if(Math.abs(this.panVelocity)>a){i+=this.panVelocity*e;let c=this.animPan.tau;this.panVelocity=c>0?this.panVelocity*Math.exp(-e/c):0,Math.abs(this.panVelocity)<=a?this.panVelocity=0:o=true;}if(this.scrollTargetRO!=null){let c=this.scrollTargetRO,u=vt(i,c,e,this.animScroll.tau);Math.abs(u-c)<.001?(i=c,this.scrollTargetRO=null):(i=u,o=true);}let l=this.clampViewport(n,i);return l.barSpacing!==n&&(this.targetBarSpacing=l.barSpacing),this.scrollTargetRO!=null&&l.rightOffset!==i&&(this.scrollTargetRO=l.rightOffset),this.coords.setViewport(l),this.computeScales(),this.easeScales(e)&&(o=true),this.easeLiveBar(e)&&(o=true),this.skeletonClockMs+=e,this.paintData(),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx()),this.updateLegendValues(),this.emitViewportChange(),o}easeScales(e){let t=false,n=this.animAutoscale.tau;for(let i of this.scene.panes.values()){let o=i.scaleTarget,s=i.scale;if(o.log&&s.min>0&&o.min>0){let u=Math.log(o.min),d=Math.log(o.max),h=Math.max(1e-9,Math.abs(d-u)),p=vt(Math.log(s.min),u,e,n),m=vt(Math.log(s.max),d,e,n);Math.abs(p-u)<=h*.001&&Math.abs(m-d)<=h*.001?i.scale={min:o.min,max:o.max,log:true}:(t=true,i.scale={min:Math.exp(p),max:Math.exp(m),log:true});continue}let a=Math.max(1e-9,Math.abs(o.max-o.min)),l=vt(s.min,o.min,e,n),c=vt(s.max,o.max,e,n);Math.abs(l-o.min)<=a*.001&&Math.abs(c-o.max)<=a*.001?(l=o.min,c=o.max):t=true,i.scale={min:l,max:c,log:o.log};}for(let i of this.scene.indicatorScales.values()){let o=i.scaleTarget,s=i.scale,a=Math.max(1e-9,Math.abs(o.max-o.min)),l=vt(s.min,o.min,e,n),c=vt(s.max,o.max,e,n);Math.abs(l-o.min)<=a*.001&&Math.abs(c-o.max)<=a*.001?(l=o.min,c=o.max):t=true,i.scale={min:l,max:c};}return t}emitViewportChange(){this.updateScrollToRealtimeButton();let e=this.getVisibleRange();if(e)for(let t of this.viewportCbs)t(e);}handlePointerMove(e,t){if(e===null||t===null||this.coords.barCount===0){this.scene.crosshair=null,this.hoverSeparatorY=null,this.lastPointer=null,this.marksExpandedBy==="hover"&&this.setMarksExpanded(null),this.setMarkHover(null),this.scheduler.invalidate(1),this.hoverLogical=null;let p={time:null,price:null,paneKind:null,values:new Map,ohlc:null};for(let m of this.crosshairCbs)m(p);return}let n=e>=0&&t>=0&&e<=this.coords.width&&t<=this.coords.height;this.scene.crosshair=n?{x:e,y:t}:null,this.lastPointer=n?{x:e,y:t}:null,this.hoverSeparatorY=e>=0&&t>=0&&t<=this.coords.height?this.separatorHoverY(t):null,this.scheduler.invalidate(1),this.setMarksExpanded(n?this.chrome.markStackAt(e,t):null),this.setMarkHover(n?this.chrome.markGlyphAt(e,t)?.cluster.key??null:null);let i=Math.round(this.coords.xToLogical(e)),o=i>=0&&i<this.coords.barCount,s=o?this.coords.logicalToTime(i):null,a=this.paneNodeAtY(t),l=n&&a?this.coords.yToPrice(t,a.scale,a.bounds):null,c=new Map;if(o)for(let p of this.scene.indicators.values()){let m=this.scene.offsetOf(p.id);for(let f of p.series)if(Fe(f)){let g=f.points[i-m]?.value;g!=null&&c.set(f.id,g);}}let u=o?this.bars[i]:void 0,d=u?{time:u.time,open:u.open,high:u.high,low:u.low,close:u.close,volume:u.volume}:null;this.hoverLogical=o?i:null;let h={time:s,price:l,paneKind:n&&a?a.kind:null,values:c,ohlc:d};for(let p of this.crosshairCbs)p(h);}handleClick(e){if(this.coords.barCount===0)return;let t=Math.round(this.coords.xToLogical(e)),n=t>=0&&t<this.coords.barCount;for(let i of this.clickCbs)i({time:n?this.coords.logicalToTime(t):null,price:null});}setMarksExpanded(e,t="hover"){if(this.scene.marksExpandedStack!==e){if(e===null&&this.markPopover?.key){let n=this.chrome.markGlyphByKey(this.markPopover.key);if(n&&n.stack===this.scene.marksExpandedStack)return}this.scene.marksExpandedStack=e,this.marksExpandedBy=t,this.scheduler?.invalidate(2);}}handleMarkClick(e,t){let n=this.chrome.markGlyphAt(e,t);if(!n)return this.scene.marksExpandedStack!==null&&this.chrome.markStackAt(e,t)===null&&this.setMarksExpanded(null),false;if(n.decked)return this.setMarksExpanded(n.stack,"tap"),true;let i=n.cluster.marks,o=i[0],s={id:o.id,ids:i.map(a=>a.id),time:o.time,...n.cluster.group!==void 0?{group:n.cluster.group}:{}};for(let a of this.markClickCbs)a(s);return i.some(a=>a.content!==void 0)?this.markPopover?.open(n.cluster,{x:n.x,y:n.y,size:n.size}):(this.scene.marksFlash={key:n.cluster.key,until:lp()+dI},this.syncMarkPulse()),true}trackMarkPopover(){let e=this.markPopover?.key;if(!e)return;let t=this.chrome.markGlyphByKey(e);this.markPopover.track(t&&!(t.decked&&t.depth!==0)?{x:t.x,y:t.y,size:t.size}:null);}setMarkHover(e){this.scene.marksHoverKey!==e&&(this.scene.marksHoverKey=e,this.scene.marksHoverSince=lp(),this.scheduler?.invalidate(2),this.syncMarkPulse());}syncMarkPulse(){if(this.markPulseRaf!==null||typeof requestAnimationFrame!="function")return;let e=()=>{this.markPulseRaf=null;let t=lp();this.scene.marksFlash&&this.scene.marksFlash.until<=t&&(this.scene.marksFlash=null),this.scheduler?.invalidate(2),(this.scene.marksHoverKey!==null&&t-this.scene.marksHoverSince<Nc||this.scene.marksFlash!==null)&&(this.markPulseRaf=requestAnimationFrame(e));};this.markPulseRaf=requestAnimationFrame(e);}paneAtY(e){return this.paneNodeAtY(e)}paneNodeAtY(e){for(let t of this.scene.panes.values())if(e>=t.bounds.top&&e<=t.bounds.top+t.bounds.height)return t;return null}nearestPaneToY(e){let t=null,n=1/0;for(let i of this.scene.panes.values()){let o=e<i.bounds.top?i.bounds.top-e:e-(i.bounds.top+i.bounds.height);o<n&&(n=o,t=i);}return t}resolveScaleHolder(e,t){let n=this.paneNodeAtY(t);if(!n)return null;let i=this.coords.width,o=this.scene.ownScaleIndicatorsForPane(n.id);if(e>=i+64&&o.length>0){let s=Math.floor((e-i-64)/56),a=o[s];if(a)return {holder:this.scene.ensureIndicatorScale(a.id,n.scaleTarget),height:n.bounds.height}}return {holder:n,height:n.bounds.height}}beginPriceScale(e,t){let n=this.resolveScaleHolder(e,t);n&&(this.scaleDragHolder=n.holder,this.scaleDragHeight=n.height,this.scaleDragStart={...n.holder.scale},n.holder.manualScale={...n.holder.scale},this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4));}priceScaleBy(e){let t=this.scaleDragHolder,n=this.scaleDragStart;!t||!n||this.setManualScale(t,lx(n,Math.exp(e*hI)));}beginPricePan(e){let t=this.paneNodeAtY(e);return !t||!t.manualScale?false:(this.scaleDragHolder=t,this.scaleDragHeight=t.bounds.height,this.scaleDragStart={...t.scale},true)}pricePanBy(e){let t=this.scaleDragHolder,n=this.scaleDragStart;!t||!n||this.setManualScale(t,cx(n,e,this.scaleDragHeight));}resetPriceScale(e,t){let n=this.resolveScaleHolder(e,t);n&&(n.holder.manualScale=null,this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4));}dataDblClick(e,t){let n=this.paneNodeAtY(t)??this.nearestPaneToY(t);if(!n)return;let i=this.maximizedPaneId!==n.id;this.maximizedPaneId=i?n.id:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:n.id,maximized:i});}resetView(){this.fitContent(),this.scheduler.invalidate(4),this.emitViewportChange();}setManualScale(e,t){e.manualScale=t,e.scale={...t},e.scaleTarget={...t},e.initialized=true,this.scheduler.invalidate(4);}afterPaneLayoutChange(){this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4);}paneControlViews(){let e=this.scene.orderedPanes();return e.map((t,n)=>({id:t.id,kind:t.kind,collapsed:t.collapsed,maximized:this.maximizedPaneId===t.id,top:t.bounds.top,height:t.bounds.height,index:n,count:e.length}))}movePaneLocal(e,t){let n=this.scene.orderedPanes(),i=n.findIndex(l=>l.id===e);if(i<0)return;let o=t==="up"?i-1:i+1;if(o<1||o>=n.length)return;let s=n.map(l=>l.id),a=s[i];s[i]=s[o],s[o]=a,this.scene.orderPanes(s),this.afterPaneLayoutChange(),this.emitPaneAction({type:"move",paneId:e,dir:t});}paneSeparatorAt(e){return this.separatorPaneIndexAt(e)!==null}separatorHoverY(e){if(!this.paneResizeEnabled)return null;let t=this.separatorPaneIndexAt(e);return t===null?null:this.scene.orderedPanes()[t].bounds.top}separatorPaneIndexAt(e){let t=this.scene.orderedPanes();for(let n=1;n<t.length;n++)if(Math.abs(e-t[n].bounds.top)<=mI)return n;return null}beginPaneResize(e){let t=this.separatorPaneIndexAt(e);if(t===null)return;let n=this.scene.orderedPanes(),i=n[t-1],o=n[t];this.resizeAbove=i,this.resizeBelow=o,this.resizeSplitStart={combinedTop:i.bounds.top,combinedHeight:i.bounds.height+o.bounds.height,combinedWeight:i.heightWeight+o.heightWeight,startBoundaryY:o.bounds.top};}paneResizeBy(e){let t=this.resizeAbove,n=this.resizeBelow,i=this.resizeSplitStart;if(!t||!n||!i)return;let o=ux(i,e);t.heightWeight=o.above,n.heightWeight=o.below,this.layoutPanes(),this.scheduler.invalidate(4);}resetPaneSize(e){let t=this.separatorPaneIndexAt(e);if(t===null)return;let n=this.scene.orderedPanes(),i=n[t-1],o=n[t],s=(i.heightWeight+o.heightWeight)/2;i.heightWeight=s,o.heightWeight=s,this.layoutPanes(),this.scheduler.invalidate(4);}setKeyboardEnabled(e){this.keyboardEnabled=e,!(!this.dataCanvas||!this.keyboard)&&(e?(this.dataCanvas.tabIndex=0,this.dataCanvas.setAttribute("role","application"),this.dataCanvas.setAttribute("aria-label","Interactive price chart. Use Left/Right arrows to move between bars, Shift+Arrow to pan, plus/minus to zoom, Home/End to jump, 0 to reset."),!this.liveRegion&&this.wrapper&&(this.liveRegion=document.createElement("div"),this.liveRegion.setAttribute("aria-live","polite"),this.liveRegion.setAttribute("role","status"),Object.assign(this.liveRegion.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:"0"}),this.wrapper.appendChild(this.liveRegion)),this.keyboard.attach(this.dataCanvas)):(this.keyboard.detach(),this.dataCanvas.removeAttribute("tabindex"),this.dataCanvas.removeAttribute("role"),this.dataCanvas.removeAttribute("aria-label")));}panByBars(e){let t=this.coords.getViewport();this.applyViewport({barSpacing:t.barSpacing,rightOffset:t.rightOffset+e});}zoomByStep(e){let t=this.coords.getViewport(),n=rn(t.barSpacing*Math.exp(e*pI));this.zoomTo(n,this.coords.rightEdgeLogical,this.coords.width);}stepCrosshair(e){let t=this.coords.barCount;if(t===0)return;let n=this.hoverLogical??Math.min(t-1,Math.round(this.coords.xToLogical(this.coords.width)));this.focusBar(n+e);}focusBar(e){let t=this.coords.barCount;if(t===0)return;let n=Math.max(0,Math.min(t-1,e)),i=this.coords.getViewport(),o=2,s=this.coords.xToLogical(0),a=this.coords.xToLogical(this.coords.width),l=i.rightOffset;n<s+o?l-=s+o-n:n>a-o&&(l+=n-(a-o)),l!==i.rightOffset&&this.applyViewport({barSpacing:i.barSpacing,rightOffset:l});let c=this.scene.orderedPanes().find(d=>d.kind==="price")??this.scene.orderedPanes()[0]??null,u=this.scene.crosshair?.y??(c?c.bounds.top+c.bounds.height/2:this.coords.height/2);this.handlePointerMove(this.coords.logicalToX(n),u),this.announceBar(n);}announceBar(e){if(!this.liveRegion)return;let t=this.bars[e],n=this.dataWindowPricePane(),i=this.dataWindowOHLC(t,n),o=[];t&&o.push(bI(t.time,this.scene.timezone)),i&&o.push(`Open ${i.o}, High ${i.h}, Low ${i.l}, Close ${i.c}`);for(let s of this.dataWindowGroups(e,n))for(let a of s.rows)o.push(`${a.label} ${a.value}`);this.liveRegion.textContent=o.join(". ");}getDataWindowReadout(){let e=this.bars.length;if(e===0)return {date:"",time:"",ohlc:null,groups:[]};let t=this.hoverLogical!=null?this.hoverLogical:e-1,n=this.bars[t],i=this.dataWindowPricePane(),o=n?Ox(n.time,this.scene.timezone):{date:"",time:""};return {date:o.date,time:o.time,ohlc:this.dataWindowOHLC(n,i),groups:this.dataWindowGroups(t,i)}}dataWindowPricePane(){return this.scene.orderedPanes().find(e=>e.kind==="price")??null}dataWindowFmt(e,t){return t?Dc(t.scale,t.bounds.height,e,this.scene.priceMintick):String(e)}dataWindowOHLC(e,t){return e?{o:this.dataWindowFmt(e.open,t),h:this.dataWindowFmt(e.high,t),l:this.dataWindowFmt(e.low,t),c:this.dataWindowFmt(e.close,t),vol:e.volume!=null?Rx(e.volume):void 0,up:e.close>=e.open}:null}dataWindowGroups(e,t){let n=[];for(let i of this.scene.indicators.values()){let o=this.readoutRowsFor(i,e,t,"dataWindow");o.length&&n.push({name:i.title,rows:o});}return n}readoutRowsFor(e,t,n,i){if(e.native?.type==="volume")return this.volumeReadoutRows(e,t);let o=(e.paneId?this.scene.panes.get(e.paneId):null)??n,s=this.scene.offsetOf(e.id),a=[];for(let l of e.series){if(!Ct(l,i))continue;let c,u;if(l.kind==="candle"||l.kind==="bar")c=l.bars[t-s]?.close,u=l.style?.up??this.theme.upColor;else if(Fe(l))c=l.points[t-s]?.value,u=l.points[t-s]?.color??l.style.color;else continue;c==null||!Number.isFinite(c)||a.push({label:l.title||e.title,value:this.dataWindowFmt(c,o),color:u});}return a}volumeReadoutRows(e,t){if(this.volumeHidden)return [];let n=this.bars[t],i=n?.volume;if(n==null||i==null||!Number.isFinite(i))return [];let o=this.scene.volumeLayer,s=n.close>=n.open?o?.upColor??this.theme.upColor:o?.downColor??this.theme.downColor;return [{label:e.title,value:Rx(i),color:s}]}updateLegendValues(){if(!this.inputsUI)return;let e=this.bars.length,t=new Map;if(e>0){let n=this.hoverLogical!=null?this.hoverLogical:e-1,i=this.dataWindowPricePane();for(let o of this.scene.indicators.values())t.set(o.id,this.readoutRowsFor(o,n,i,"legend").map(s=>({value:s.value,color:s.color})));}this.inputsUI.setPlotValues(t);}renderFrame(e){this.animator.active||(bh(e)?(this.computeScales(),this.paintData()):Oy(e)&&this.paintedData&&(this.chrome.prepare(this.scene,this.coords,this.theme),this.chrome.render(this.scene,this.coords,this.theme,this.axisSurface()),this.trackMarkPopover()),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx()),!bh(e)&&this.paintedData&&this.repaintCursorLayers(),this.updateLegendValues());}repaintCursorLayers(){let e=this.scene.panes.get(He);if(!e)return;let t=typeof performance<"u"?performance.now():Date.now();for(let n of this.extLayers){if(!n.def.repaintOnCursor)continue;let i=this.layerPane(n)??e;i.collapsed||this.layerHiddenWithCandles(n)||(n.instance.render(this.extLayerArgs(n,i.scale,i.bounds,t)),this.animZoom.on&&n.instance.animating?.()&&this.animator.start());}}clearLayerCanvas(e){e.width===0||e.height===0||e.getContext("2d")?.clearRect(0,0,e.width,e.height);}extLayerArgs(e,t,n,i){return {bars:this.scene.bars,data:this.scene.nativeData.get(e.channel),settings:this.scene.nativeData.get(`${e.def.id}-settings`)??{},pending:this.scene.nativePending.get(e.channel)??[],coords:this.coords,scale:t,bounds:n,theme:this.theme,priceStyle:this.scene.priceStyle,nowMs:i,cursor:this.lastPointer}}paintData(){this.syncLayerCanvasOrder(),this.stampScaleInvert(),this.backend.modelAlpha=this.modelAlpha,this.backend.candleBodyAlpha=this.candleBodyAlpha,this.backend.candleStructureAlpha=this.candleStructureAlpha;let e=1,t=1;this.backend.candleBodyScale=t;let n=this.scene.panes.get(He);if(n){let a=this.nativeLayerPane("volume")??n;this.volumeRenderer.render({bars:this.scene.bars,data:this.scene.volumeLayer,visible:this.volumeActive&&!this.volumeHidden&&!a.collapsed,coords:this.coords,bounds:a.bounds,fillPane:a.kind!=="price"}),this.vpvrRenderer.render({bars:this.scene.bars,data:this.scene.vpvrLayer,visible:this.vpvrActive&&!this.vpvrHidden,coords:this.coords,scale:n.scale,bounds:n.bounds,theme:this.theme});let l=typeof performance<"u"?performance.now():Date.now(),c=null;for(let u of this.extLayers){let d=this.layerPane(u)??n;if(d.collapsed||this.layerHiddenWithCandles(u)){this.clearLayerCanvas(u.canvas);continue}let h=this.extLayerArgs(u,d.scale,d.bounds,l);u.instance.render(h),d===n&&(c=hx(c,u.instance.modulateBase?.(h)??null)),this.animZoom.on&&u.instance.animating?.()&&this.animator.start();}c&&(c.candleBodyScale!=null&&(this.backend.candleBodyScale=cp(c.candleBodyScale)||.01),c.candleBodyAlpha!=null&&(this.backend.candleBodyAlpha=cp(c.candleBodyAlpha)*this.candleBodyAlpha),c.gridAlpha!=null&&(e=cp(c.gridAlpha)));}let i=this.bars.length-1,o=i>=0?this.bars[i]:void 0,s=!!o&&this.liveEaseTime===o.time&&(o.high!==this.liveEaseHigh||o.low!==this.liveEaseLow||o.close!==this.liveEaseClose);s&&o&&(this.bars[i]={...o,high:this.liveEaseHigh,low:this.liveEaseLow,close:this.liveEaseClose}),this.scene.drawingSlices=ex(this.indicatorSlices.prepare(this.scene,this.coords,this.theme,this.dataCanvas),this.userDrawings?.prepareSlices(this.scene.orderedPanes().map(a=>a.id))??new Map),this.backdropRenderer.render(this.scene,this.coords,this.theme,e),this.backend.render(this.scene,this.coords,this.theme),this.chrome.render(this.scene,this.coords,this.theme,this.axisSurface()),this.trackMarkPopover(),this.userDrawings?.render(),s&&o&&(this.bars[i]=o),this.paintedData=true;}drawingProjector(){return tx(this.coords,e=>{let t=this.scene.panes.get(e);return t?{scale:t.scale,bounds:t.bounds,collapsed:t.collapsed}:null},e=>this.paneNodeAtY(e)?.id??null,(e,t)=>this.barsInTimeRange(e,t),this.userDrawings?.seriesGateway?(e,t,n)=>this.userDrawings.seriesGateway.seriesInRange(e,t,n):void 0)}barsInTimeRange(e,t){let n=Math.min(e,t),i=Math.max(e,t),o=[];for(let s of this.bars)if(!(s.time<n)){if(s.time>i)break;o.push(s);}return o}get userDrawingsPort(){return this.userDrawings??void 0}focus(){this.dataCanvas?.focus({preventScroll:true});}setExternalCrosshair(e,t=null){let n=e==null?null:{time:e,price:t},i=this.externalCross;!n&&!i||n&&i&&i.time===n.time&&i.price===n.price||(this.externalCross=n,this.scheduler.invalidate(1));}externalCrossPx(){let e=this.externalCross;if(!e||this.coords.barCount===0)return null;let t=Math.floor(this.coords.timeToLogical(e.time));if(t<0||t>=this.coords.barCount)return null;let n=this.coords.logicalToX(t);if(!Number.isFinite(n)||n<0||n>this.coords.width)return null;let i=null;if(e.price!=null){let o=this.scene.orderedPanes().find(s=>s.kind==="price");o&&(i=this.coords.priceToY(e.price,o.scale,o.bounds),(!Number.isFinite(i)||i<o.bounds.top||i>o.bounds.top+o.bounds.height)&&(i=null));}return {x:n,y:i,time:this.coords.logicalToTime(t),price:i!=null?e.price:null}}setSnapMode(e){this.snapMode=e;}snapToCandle(e,t,n="strong",i){if(n==="off")return e;let o=this.bars.length;if(o===0)return e;let s=Math.max(0,Math.min(o-1,Math.round(this.coords.timeToLogical(e.time)))),a=this.bars[s];if(!a)return e;let l;if(t!==He)l={time:a.time,price:e.price};else {let c=a.open;for(let u of [a.high,a.low,a.close])Math.abs(u-e.price)<Math.abs(c-e.price)&&(c=u);l={time:a.time,price:c};}if(n==="weak"&&i){let c=this.drawingProjector(),u=c.yOf(l.price,t);if(Math.hypot(c.xOf(l.time)-i.x,(u??i.y)-i.y)>nI)return e}return l}computeScales(){let e=this.coords.barCount;if(e===0)return;let t=this.coords.visibleLogicalRange(),n=Math.max(0,Math.floor(t.from)),i=Math.min(e-1,Math.ceil(t.to));if(i<n)return;this.scene.percentBaseline=this.bars[n]?.close??0;let o=this.scene.orderedPanes(),s=o.find(l=>l.kind==="price")??null;this.chrome.prepare(this.scene,this.coords,this.theme);let a=this.animator.active;for(let l of o){if(l.manualScale){l.scaleTarget=l.manualScale,l.scale={...l.manualScale},l.initialized=true;continue}let u=this.scene.indicatorsForPane(l.id).filter(p=>p.ownScale!==true),d=this.chrome.paneDrawingsRange(u,this.scene,l===s,t);if(l===s){let p=ox(this.scene.indicators.values(),n,i,m=>this.scene.offsetOf(m));p&&(d=d?{min:Math.min(d.min,p.min),max:Math.max(d.max,p.max)}:p);}let h=l.kind==="price"&&(!this.scene.candlesHidden||this.priceLayersAnchoredToBars(u));if(l.scaleTarget=eu(u,this.bars,h,n,i,d,Ri(this.scene,l),p=>this.scene.offsetOf(p)),l.percentBaseline=l.kind==="price"?this.bars[n]?.close??0:this.firstVisibleValue(u,n),l.axisFormat=void 0,l.axisBands=void 0,this.volumeOwnsPane(l,u)){let p=this.maxVisibleVolume(n,i);p>0&&(l.scaleTarget={min:0,max:p/Jh},l.axisFormat="volume");}else if(this.layerNativesOwnPane(l,u)&&(l.scaleTarget=eu([],this.bars,true,n,i,d,Ri(this.scene,l),p=>this.scene.offsetOf(p)),l.percentBaseline=this.bars[n]?.close??0,u.every(p=>p.paneAxis!=null))){l.axisFormat="none";let p=u.find(m=>typeof m.paneAxis=="object");l.axisBands=p?p.paneAxis.bands:void 0;}if(l===s&&this.scene.tradeMarkers.visible&&l.bounds.height>0){let p=this.tradesScaleHints(t);if(p){let m=l.scaleTarget,f={...m,min:Math.min(m.min,p.min),max:Math.max(m.max,p.max)};l.scaleTarget=sx(f,l.bounds.height,p.abovePx,p.belowPx);}}(!a||!l.initialized)&&(l.scale={...l.scaleTarget},l.initialized=true);for(let p of this.scene.ownScaleIndicatorsForPane(l.id)){let m=this.scene.ensureIndicatorScale(p.id,l.scaleTarget);if(m.manualScale){m.scaleTarget=m.manualScale,m.scale={...m.manualScale},m.initialized=true;continue}let f=this.chrome.paneDrawingsRange([p],this.scene,false,t);m.scaleTarget=eu([p],this.bars,false,n,i,f,false,g=>this.scene.offsetOf(g)),(!a||!m.initialized)&&(m.scale={...m.scaleTarget},m.initialized=true);}}}tradesScaleHints(e){let t=null,n={timeToLogical:i=>this.coords.timeToLogical(i),barAt:i=>{let o=this.bars[Math.round(i)];return o?{high:o.high,low:o.low}:null}};for(let i of this.scene.indicators.values()){if(!i.trades?.length)continue;let o=Ky(i.trades,this.scene.tradeMarkers,n,e.from,e.to,this.scene.style.fontSize);o&&(t=t?{min:Math.min(t.min,o.min),max:Math.max(t.max,o.max),abovePx:Math.max(t.abovePx,o.abovePx),belowPx:Math.max(t.belowPx,o.belowPx)}:o);}return t}fitContent(){let e=this.coords.barCount,t=this.coords.width;if(e<=0||t<=0)return;this.animator?.stop(),this.panVelocity=0;for(let s of this.scene.panes.values())s.manualScale=null;for(let s of this.scene.indicatorScales.values())s.manualScale=null;let n=Math.min(e,200),i=6,o=this.clampViewport(t/((n+i)*this.coords.spacingScale),i);this.coords.setViewport(o),this.targetBarSpacing=o.barSpacing;}reframeKeepZoom(){this.animator?.stop(),this.panVelocity=0;for(let t of this.scene.panes.values())t.manualScale=null;for(let t of this.scene.indicatorScales.values())t.manualScale=null;let e={barSpacing:rn(this.coords.getViewport().barSpacing),rightOffset:cs().rightOffset};this.coords.setViewport(e),this.targetBarSpacing=e.barSpacing;}paneBoundsFor(e){let t=this.scene.panes.get(e);return {top:t?.bounds.top??0,height:t?.bounds.height??0,rightAxis:this.rightAxisW}}paneMasterTitle(e){let t=this.scene.orderedIndicatorsForPane(e);return (t.find(i=>i.ownScale!==true)??t[0])?.title||null}nativeLayerPane(e){for(let t of this.scene.indicators.values())if(t.native?.type===e)return this.scene.panes.get(t.paneId??He)??null;return null}createLayerCanvas(){let e=document.createElement("canvas");return Object.assign(e.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none"}),e}ensureInstanceLayer(e){let t=e.native?.channel;if(!t||!this.plot||this.extLayers.some(s=>s.owner===e.id))return;let n=this.extLayers.find(s=>s.owner===null&&s.def.id===e.native.type);if(!n)return;let i=this.createLayerCanvas();i.width=this.dataCanvas.width,i.height=this.dataCanvas.height,i.style.width=this.dataCanvas.style.width||"100%",i.style.height=this.dataCanvas.style.height||"100%";let o={def:n.def,instance:n.def.create(),canvas:i,channel:t,owner:e.id};this.extLayers.push(o),this.plot.insertBefore(i,this.chromeCanvas),o.instance.mount(i);}dropInstanceLayer(e){let t=this.extLayers.findIndex(i=>i.owner===e);if(t<0)return;let[n]=this.extLayers.splice(t,1);n.instance.destroy?.(),n.canvas.remove();}layerOwner(e){if(e.owner!==null)return this.scene.indicators.get(e.owner)??null;for(let t of this.scene.indicators.values())if(t.native?.type===e.def.id&&!t.native.channel)return t;return null}layerPane(e){let t=this.layerOwner(e),n=t?t.paneId??He:He;return this.scene.panes.get(n)??null}orderedLayerCanvases(){let e=new Map(this.extLayers.map(i=>[i.channel,i.canvas])),{below:t,above:n}=px(this.extLayers.map(i=>{let o=this.layerOwner(i);return {id:i.channel,placement:i.def.placement==="below-data"?"below-data":"above-data",ownerZ:o?this.scene.zOf(o.id):null}}),this.scene.candleZ);return {below:t.map(i=>e.get(i)),above:n.map(i=>e.get(i))}}canvasPile(){let{below:e,above:t}=this.orderedLayerCanvases();return [this.backdropCanvas,...e,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...t]}syncLayerCanvasOrder(){if(this.extLayers.length===0||!this.plot)return;let{below:e,above:t}=this.orderedLayerCanvases(),n=[...e.map(i=>this.extLayers.find(o=>o.canvas===i).channel),"|",...t.map(i=>this.extLayers.find(o=>o.canvas===i).channel)].join(",");if(n!==this.layerOrderSig){this.layerOrderSig=n;for(let i of e)this.plot.insertBefore(i,this.dataCanvas);for(let i of t)this.plot.insertBefore(i,this.chromeCanvas);}}volumeOwnsPane(e,t){return e.kind==="price"||!this.volumeActive||this.volumeHidden||!this.scene.volumeLayer||this.nativeLayerPane("volume")!==e?false:t.every(n=>n.native?.type==="volume")}layerNativesOwnPane(e,t){return e.kind==="price"||t.length===0?false:t.every(n=>n.series.length===0&&!!n.native&&this.extLayers.some(i=>i.def.id===n.native.type))}layerHiddenWithCandles(e){return this.scene.candlesHidden&&e.owner===null&&e.def.id===this.scene.priceStyle}priceLayersAnchoredToBars(e){return e.some(t=>t.series.length===0&&!!t.native&&this.extLayers.some(n=>n.def.id===t.native.type))}paneScaleInfos(){return this.scene.orderedPanes().map(e=>({id:e.id,kind:e.kind,top:e.bounds.top,height:e.bounds.height,mode:Sh(this.scene,e),log:Ri(this.scene,e),invert:Ch(this.scene,e)}))}axisScaleViews(){return this.scene.orderedPanes().map(e=>({id:e.id,top:e.bounds.top,height:e.bounds.height,collapsed:e.collapsed,auto:e.manualScale==null,log:Ri(this.scene,e)}))}togglePaneAuto(e){let t=this.scene.panes.get(e);t&&(t.manualScale=t.manualScale==null?{...t.scale}:null,this.scheduler?.invalidate(4));}setPaneScaleMode(e,t){if(e===He)this.scene.scaleMode=t;else {let n=this.scene.panes.get(e);if(!n)return;n.scaleMode=t;}this.scheduler?.invalidate(4);}setPaneLog(e,t){let n=e===He?this.scene.orderedPanes().find(i=>i.kind==="price"):this.scene.panes.get(e);if(e===He)this.scene.logScale=t;else {if(!n)return;n.logScale=t;}n?.manualScale&&(n.manualScale.log=t),this.scheduler?.invalidate(4);}setPaneInvert(e,t){if(e===He)this.scene.invertScale=t;else {let n=this.scene.panes.get(e);if(!n)return;n.invert=t;}this.scheduler?.invalidate(4);}stampScaleInvert(){for(let e of this.scene.panes.values()){let t=Ch(this.scene,e);e.scale.invert=t,e.scaleTarget.invert=t,e.manualScale&&(e.manualScale.invert=t);for(let n of this.scene.ownScaleIndicatorsForPane(e.id)){let i=this.scene.indicatorScales.get(n.id);i&&(i.scale.invert=t,i.scaleTarget.invert=t,i.manualScale&&(i.manualScale.invert=t));}}}firstVisibleValue(e,t){for(let n of e){let i=this.scene.offsetOf(n.id);for(let o of n.series)if(o.overlay!==true){if(Fe(o)){let s=o.points[t-i]?.value;if(s!=null&&Number.isFinite(s))return s}else if(o.kind==="candle"||o.kind==="bar"){let s=o.bars[t-i];if(s&&Number.isFinite(s.close))return s.close}}}return 0}maxVisibleVolume(e,t){let n=0;for(let i=e;i<=t;i+=1){let o=this.bars[i]?.volume;o!=null&&o>n&&(n=o);}return n}layoutPanes(){let e=this.scene.orderedPanes(),t=this.coords.height;this.inputsUI?.setCollapsedPanes(this.collapsedMasterMap());let n=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null;if(n){let u=0;for(let d of e)d===n?d.bounds={top:0,height:t}:d.bounds={top:t,height:0},u+=d.bounds.height;this.inputsUI?.reposition(),this.paneControls?.reposition(),this.axisScaleButtons?.reposition(),this.repositionScrollButton(),this.positionAttribution(),this.publishPricePaneBounds();return}let i=e.filter(u=>u.collapsed),o=e.filter(u=>!u.collapsed),s=i.length*Lx,a=Math.max(0,t-s),l=o.reduce((u,d)=>u+(d.heightWeight||1),0)||1,c=0;for(let u of e){let d=u.collapsed?Lx:a*(u.heightWeight||1)/l;u.bounds={top:c,height:d},c+=d;}this.inputsUI?.reposition(),this.paneControls?.reposition(),this.axisScaleButtons?.reposition(),this.repositionScrollButton(),this.positionAttribution(),this.publishPricePaneBounds();}repositionScrollButton(){let e=this.coords.height;if(e<=0)return;let t=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null,n=t?[t]:this.scene.orderedPanes().filter(o=>!o.collapsed),i=n.length?Math.max(...n.map(o=>o.bounds.top+o.bounds.height)):e;this.scrollBtnBottomPx=ap+Math.max(0,e-i),this.mountContainer?.style.setProperty("--vela-bottom-gutter",`${Hi+Math.max(0,e-i)}px`),this.scrollBtnRightPx=this.rightAxisW+Dx,this.scrollButton&&(this.scrollButton.style.bottom=`${this.scrollBtnBottomPx}px`,this.scrollButton.style.right=`${this.scrollBtnRightPx}px`);}collapsedMasterMap(){let e=new Map;for(let t of this.scene.panes.values()){if(!t.collapsed)continue;let n=this.scene.orderedIndicatorsForPane(t.id).filter(s=>s.legend!==false),i=new Set(this.scene.ownScaleIndicatorsForPane(t.id).map(s=>s.id)),o=n.find(s=>!i.has(s.id))??n[0];e.set(t.id,o?.id??null);}return e}setToolbarGutter(e){e!==this.toolbarGutter&&(this.toolbarGutter=e,this.publishGutters(),this.positionAttribution(),this.syncSize());}publishGutters(){this.mountContainer?.style.setProperty("--vela-toolbar-gutter",`${this.toolbarGutter}px`),this.mountContainer?.style.setProperty("--vela-scale-gutter",`${this.rightAxisW}px`);}publishPricePaneBounds(){if(!this.mountContainer)return;let e=this.coords.height+Hi,t=this.scene.panes.get(He),n=t?t.bounds.top:0,i=t?t.bounds.height:this.coords.height,o=Math.max(0,e-(n+i));this.mountContainer.style.setProperty("--vela-price-pane-top",`${n}px`),this.mountContainer.style.setProperty("--vela-price-pane-bottom",`${o}px`);}buildAttributionEl(){return this.attributionHtml!==null?bx(document,this.attributionHtml,this.theme.background):vx(document,this.theme.background)}rebuildAttribution(){this.attributionEl&&(this.attributionEl.remove(),this.attributionEl=this.buildAttributionEl(),this.attributionEnabled||(this.attributionEl.style.display="none"),this.positionAttribution(),this.wrapper.appendChild(this.attributionEl));}positionAttribution(){if(!this.attributionEl)return;let e=this.coords?.height??0,t=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null,n=t?[t]:this.scene.orderedPanes().filter(o=>!o.collapsed),i=e>0&&n.length?Math.max(...n.map(o=>o.bounds.top+o.bounds.height)):e;Object.assign(this.attributionEl.style,{left:`${(this.toolbarGutter||0)+12}px`,bottom:`${Hi+10+Math.max(0,e-i)}px`});}refreshAttributionColor(){this.attributionEl&&(this.attributionHtml!==null?this.attributionEl.style.color=np(this.theme.background):rp(this.attributionEl,this.theme.background));}syncSize(){let e=this.wrapper.clientWidth,t=this.wrapper.clientHeight;if(e<=0||t<=0)return;let n=window.devicePixelRatio||1;this.plot.style.left=`${this.toolbarGutter}px`;let i=this.plot.getBoundingClientRect(),o=Math.max(1,Math.round(i.width*n)),s=Math.max(1,Math.round(i.height*n)),a=this.plotDeviceSize;a&&Math.abs(a.width-i.width*n)<=1&&Math.abs(a.height-i.height*n)<=1&&(o=Math.max(1,a.width),s=Math.max(1,a.height));let l=o/n,c=s/n,u=d=>{d.width=o,d.height=s,d.style.width=`${l}px`,d.style.height=`${c}px`;};u(this.dataCanvas),u(this.backdropCanvas),u(this.volumeCanvas);for(let d of this.extLayers)u(d.canvas);u(this.vpvrCanvas),u(this.chromeCanvas),u(this.drawingsCanvas),u(this.cursorCanvas),this.coords.setSize(Math.max(1,l-this.rightAxisW),Math.max(1,c-Hi),n),this.scene.crosshair=null,this.layoutPanes(),this.userDrawings?.onResize(),!this.didInitialFit&&this.coords.barCount>0&&(this.fitContent(),this.didInitialFit=true),this.animator.active?(this.computeScales(),this.paintData(),this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx())):this.scheduler.flushNow(4);}applyBackground(){this.wrapper.style.background=this.theme.background;}};function fI(r,e){for(let t of r.series){let n=t.kind==="candle"||t.kind==="bar"?t.bars:Fe(t)?t.points:null;if(!n||n.length===0)continue;let i=0,o=n.length;for(;i<o;){let s=i+o>>1;n[s].time<e?i=s+1:o=s;}return i}return null}function gI(r,e){if(e.kind==="value"){for(let t of e.series){let n=r.series.find(i=>i.id===t.seriesId);n&&(t.kind==="points"&&Fe(n)?n.points=t.points:t.kind==="bars"&&(n.kind==="candle"||n.kind==="bar")&&(n.bars=t.bars));}e.lines&&(r.lines=e.lines),e.boxes&&(r.boxes=e.boxes),e.labels&&(r.labels=e.labels),e.polylines&&(r.polylines=e.polylines),e.linefills&&(r.linefills=e.linefills),e.tables&&(r.tables=e.tables),e.trades&&(r.trades=e.trades);return}for(let t of e.removed){let n=r.series.findIndex(i=>i.id===t);n>=0&&r.series.splice(n,1);}for(let t of e.added)r.series.push(t);}function Ox(r,e){let t=Pc(r,e),n=i=>i<10?`0${i}`:String(i);return {date:`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())}`,time:`${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}}function bI(r,e){let{date:t,time:n}=Ox(r,e);return `${t} ${n}`}function vI(r){if(!Array.isArray(r))return [];let e=[];for(let t of r){if(!t||typeof t!="object")continue;let n=t,i=Number(n.from),o=Number(n.to);!Number.isFinite(i)||!Number.isFinite(o)||o<=i||e.push({from:i,to:o,color:typeof n.color=="string"?n.color:"rgba(120,130,160,0.10)"});}return e.sort((t,n)=>t.from-n.from)}function yI(r){if(r==null||typeof r!="object")return null;let e=r,t=n=>{if(!Array.isArray(n))return [];let i=[];for(let o of n){if(!Array.isArray(o))continue;let s=Number(o[0]),a=Number(o[1]);Number.isFinite(s)&&Number.isFinite(a)&&a>s&&i.push([s,a]);}return i.sort((o,s)=>o[0]-s[0])};return {pre:t(e.pre),post:t(e.post),extended:t(e.extended)}}function cp(r){return Math.max(0,Math.min(1,r))}function wI(r){return typeof r=="string"&&Pi().includes(r)}function Ax(r){return r==="percent"||r==="indexed"?r:"price"}function Rx(r){let e=Math.abs(r);return e>=1e9?`${(r/1e9).toFixed(2)}B`:e>=1e6?`${(r/1e6).toFixed(2)}M`:e>=1e3?`${(r/1e3).toFixed(2)}K`:r.toFixed(2)}function xI(r){let e=[...r].sort((n,i)=>n.time-i.time),t=[];for(let n of e){let i=t[t.length-1];i&&i.time===n.time?t[t.length-1]=n:t.push(n);}return t}function up(r,e){let t=(r.open+r.high+r.low+r.close)/4,n=e?(e.open+e.close)/2:(r.open+r.close)/2;return {time:r.time,open:n,high:Math.max(r.high,n,t),low:Math.min(r.low,n,t),close:t,...r.volume!=null?{volume:r.volume}:{}}}function Nx(r){let e=new Array(r.length),t;for(let n=0;n<r.length;n+=1)t=up(r[n],t),e[n]=t;return e}var SI={full:Nx,next:up};function Fx(){_u({id:"heikinashi",label:"Heikin Ashi",barTransform:SI});}var dp=z,hp=W,pp=20;function CI(r,e){return typeof r=="number"&&Number.isFinite(r)?r:e}function Vx(r,e){return typeof r=="string"&&r!==""?r:e}function lu(r){return {upColor:Vx(r.upColor,dp),downColor:Vx(r.downColor,hp),heightFrac:Math.min(.5,Math.max(.05,CI(r.heightPct,pp)/100))}}var mp=class{constructor(){this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(lu(t));}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(lu(e));}suspend(){}resume(){this.ctx?.pushData(lu(this.inputs));}stop(){}},_x={type:"volume",title:"Volume",paneHint:"price",overlay:true,inputsSchema:()=>[{key:"upColor",title:"Up color",type:"color",defval:dp},{key:"downColor",title:"Down color",type:"color",defval:hp},{key:"heightPct",title:"Height %",type:"int",defval:pp,min:5,max:50,step:1,tooltip:"Pane height the tallest visible bar occupies"}],defaultInputs:()=>({upColor:dp,downColor:hp,heightPct:pp}),create:()=>new mp};function fp(){Pn(_x);}var bp=24,vp=30,yp=Ke,wp=W,xp=70;function gp(r,e){return typeof r=="number"&&Number.isFinite(r)?r:e}function Bx(r,e){return typeof r=="string"&&r!==""?r:e}function cu(r){return {rows:Math.round(Math.min(400,Math.max(2,gp(r.rows,bp)))),widthFrac:Math.min(.9,Math.max(.05,gp(r.widthPct,vp)/100)),upColor:Bx(r.upColor,yp),downColor:Bx(r.downColor,wp),showPoc:r.showPoc!==false,valueAreaFrac:Math.min(1,Math.max(0,gp(r.valueAreaPct,xp)/100))}}var Sp=class{constructor(){this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(cu(t));}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(cu(e));}suspend(){}resume(){this.ctx?.pushData(cu(this.inputs));}stop(){}},Hx={type:"vpvr",title:"Visible Range Volume Profile",shortTitle:"VRVP",paneHint:"price",overlay:true,inputsSchema:()=>[{key:"rows",title:"Rows",type:"int",defval:bp,min:2,max:400,step:1},{key:"widthPct",title:"Width %",type:"int",defval:vp,min:5,max:90,step:1,tooltip:"Pane width the largest row occupies"},{key:"upColor",title:"Up color",type:"color",defval:yp},{key:"downColor",title:"Down color",type:"color",defval:wp},{key:"showPoc",title:"Point of control",type:"bool",defval:true},{key:"valueAreaPct",title:"Value area %",type:"int",defval:xp,min:0,max:100,step:1}],defaultInputs:()=>({rows:bp,widthPct:vp,upColor:yp,downColor:wp,showPoc:true,valueAreaPct:xp}),create:()=>new Sp};function Cp(){Pn(Hx);}function Jn(r){let e=r.title.trim().toLowerCase().replace(/\s+/g,"-");return `${r.instanceId}:${r.kind}:${e}#${r.ordinal}`}function I(r,e,t){let n=r[e];return typeof n=="number"&&Number.isFinite(n)?n:t}function F(r,e,t){let n=r[e];return typeof n=="string"&&n!==""?n:t}function kp(r,e,t){let n=r[e];return typeof n=="boolean"?n:t}function TI(r,e,t){let n=new Array(r.length);for(let i=0;i<r.length;i++){let o=e[i],s={time:r[i].time,value:o!=null&&Number.isFinite(o)?o:null},a=t?.[i];a!=null&&(s.color=a),n[i]=s;}return n}var Tp=class{constructor(e){this.spec=e;this.ctx=null;this.inputs={};}start(e,t){this.ctx=e,this.inputs=t,this.recompute();}onBars(){this.recompute();}onViewport(){}setInputs(e){this.inputs=e,this.ctx&&this.recompute();}suspend(){}resume(){this.recompute();}stop(){}recompute(){if(!this.ctx)return;let e=this.ctx.bars(),t=this.spec.compute(e,this.inputs),n=this.spec.type,i=[],o=new Map;t.plots.forEach((c,u)=>{let d=c.kind??"line",h=Jn({instanceId:n,kind:d,title:c.title,ordinal:u});o.set(c.key,h),i.push({id:h,title:c.title,paneId:"",kind:d,points:TI(e,c.values,c.colors),style:{color:c.color,width:c.width??1,lineStyle:c.lineStyle??"solid",...c.base!=null?{base:c.base}:{}},...c.overlay?{overlay:true}:{}});}),t.markers&&t.markers.length>0&&i.push({id:Jn({instanceId:n,kind:"markers",title:"markers",ordinal:0}),title:this.spec.shortTitle??this.spec.title,paneId:"",kind:"markers",markers:t.markers});let s=(t.bands??[]).flatMap((c,u)=>{let d=o.get(c.from),h=o.get(c.to);return !d||!h?[]:[{id:Jn({instanceId:n,kind:"fill",title:c.key,ordinal:u}),paneId:"",fromSeriesId:d,toSeriesId:h,color:c.color}]}),a=(t.levels??[]).map((c,u)=>({id:Jn({instanceId:n,kind:"hline",title:c.key,ordinal:u}),paneId:"",price:c.price,...c.color!=null?{color:c.color}:{},lineStyle:c.lineStyle??"dashed",width:1,...c.title!=null?{title:c.title}:{}})),l=(t.polylines??[]).map((c,u)=>{let{key:d,...h}=c;return {id:Jn({instanceId:n,kind:"polyline",title:d,ordinal:u}),paneId:"",...h}});this.ctx.emit({series:i,fills:s,priceLines:a,polylines:l}),this.ctx.setStatus("idle");}};function zx(r){return {type:r.type,title:r.title,...r.shortTitle!=null?{shortTitle:r.shortTitle}:{},paneHint:r.overlay?"price":"new",overlay:r.overlay,multiInstance:true,inputsSchema:()=>r.inputs,defaultInputs:()=>Object.fromEntries(r.inputs.map(e=>[e.key,e.defval])),create:()=>new Tp(r)}}var $x=["Close","Open","High","Low","HL2","HLC3","OHLC4","HLCC4"];function ee(r,e){let t=new Array(r.length);for(let n=0;n<r.length;n++){let i=r[n];switch(e){case "Open":t[n]=i.open;break;case "High":t[n]=i.high;break;case "Low":t[n]=i.low;break;case "HL2":t[n]=(i.high+i.low)/2;break;case "HLC3":t[n]=(i.high+i.low+i.close)/3;break;case "OHLC4":t[n]=(i.open+i.high+i.low+i.close)/4;break;case "HLCC4":t[n]=(i.high+i.low+i.close+i.close)/4;break;default:t[n]=i.close;}}return t}function xt(r){return r.map(e=>e.volume!=null&&Number.isFinite(e.volume)?e.volume:Number.NaN)}function Ue(r){return r.map(e=>e.high)}function Ye(r){return r.map(e=>e.low)}function Oe(r){return r.map(e=>e.close)}function Wx(r){return r.map(e=>e.open)}function K(r,e,t){let n=new Array(r.length);for(let i=0;i<r.length;i++){let o=r[i],s=e[i];n[i]=Number.isFinite(o)&&Number.isFinite(s)?t(o,s):Number.NaN;}return n}function ae(r,e){let t=new Array(r.length);for(let n=0;n<r.length;n++){let i=r[n];t[n]=Number.isFinite(i)?e(i):Number.NaN;}return t}function ke(r,e){return K(r,e,(t,n)=>t-n)}function Ln(r,e,t){let n=new Array(r.length).fill(Number.NaN);if(e<=0)return n;let i=0;for(let o=0;o<r.length;o++)i=Number.isFinite(r[o])?i+1:0,i>=e&&(n[o]=t(r,o-e+1,o));return n}function xe(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let s=n;s<=i;s++)o+=t[s];return o})}function ge(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let s=n;s<=i;s++)o+=t[s];return o/e})}function uu(r,e){let t=e*(e+1)/2;return Ln(r,e,(n,i,o)=>{let s=0;for(let a=i;a<=o;a++)s+=n[a]*(a-i+1);return s/t})}function Gx(r,e,t){let n=K(r,e,(i,o)=>i*o);return K(xe(n,t),xe(e,t),(i,o)=>o>0?i/o:Number.NaN)}function sn(r,e){return Ln(r,e,(t,n,i)=>{let o=0;for(let l=n;l<=i;l++)o+=t[l];let s=o/e,a=0;for(let l=n;l<=i;l++){let c=t[l]-s;a+=c*c;}return Math.sqrt(a/e)})}function ct(r,e){return Ln(r,e,(t,n,i)=>{let o=-1/0;for(let s=n;s<=i;s++)t[s]>o&&(o=t[s]);return o})}function St(r,e){return Ln(r,e,(t,n,i)=>{let o=1/0;for(let s=n;s<=i;s++)t[s]<o&&(o=t[s]);return o})}function Ux(r,e){return Ln(r,e,(t,n,i)=>{let o=-1/0,s=i;for(let a=n;a<=i;a++)t[a]>=o&&(o=t[a],s=a);return i-s})}function Yx(r,e){return Ln(r,e,(t,n,i)=>{let o=1/0,s=i;for(let a=n;a<=i;a++)t[a]<=o&&(o=t[a],s=a);return i-s})}function Kx(r,e,t){let n=new Array(r.length).fill(Number.NaN),i=0,o=Number.NaN;for(let s=0;s<r.length;s++){let a=r[s];if(!Number.isFinite(a)){i=0,o=Number.NaN;continue}if(i+=1,Number.isFinite(o))o=t*a+(1-t)*o,n[s]=o;else if(i>=e){let l=0;for(let c=s-e+1;c<=s;c++)l+=r[c];o=l/e,n[s]=o;}}return n}function Q(r,e){return Kx(r,e,2/(e+1))}function Pe(r,e){return Kx(r,e,1/e)}function ze(r,e=1){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n],o=r[n-e];Number.isFinite(i)&&Number.isFinite(o)&&(t[n]=i-o);}return t}function Vt(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n],o=r[n-e];Number.isFinite(i)&&Number.isFinite(o)&&o!==0&&(t[n]=100*(i-o)/o);}return t}function ot(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=0;n<r.length;n++){let i=n-e;i>=0&&i<r.length&&(t[n]=r[i]);}return t}function Qn(r){let e=new Array(r.length).fill(Number.NaN);for(let t=0;t<r.length;t++){let n=r[t];if(t===0){e[t]=n.high-n.low;continue}let i=r[t-1].close;e[t]=Math.max(n.high-n.low,Math.abs(n.high-i),Math.abs(n.low-i));}return e}function Hr(r,e){return Pe(Qn(r),e)}function Ls(r,e){let t=ze(r),n=ae(t,o=>Math.max(o,0)),i=ae(t,o=>Math.max(-o,0));return K(Pe(n,e),Pe(i,e),(o,s)=>s===0?100:100-100/(1+o/s))}function du(r,e,t,n){let i=ct(e,n),o=St(t,n),s=new Array(r.length).fill(Number.NaN);for(let a=0;a<r.length;a++){let l=r[a],c=i[a],u=o[a];!Number.isFinite(l)||!Number.isFinite(c)||!Number.isFinite(u)||(s[a]=c===u?50:100*(l-u)/(c-u));}return s}function hu(r,e){let t=(e-1)*e/2,n=(e-1)*e*(2*e-1)/6,i=e*n-t*t;return Ln(r,e,(o,s,a)=>{let l=0,c=0;for(let h=s;h<=a;h++){let p=h-s;l+=o[h],c+=p*o[h];}let u=i===0?0:(e*c-t*l)/i;return (l-u*t)/e+u*(e-1)})}function pu(r){let e=new Array(r.length).fill(Number.NaN);for(let t=3;t<r.length;t++){let n=r[t-3],i=r[t-2],o=r[t-1],s=r[t];Number.isFinite(n)&&Number.isFinite(i)&&Number.isFinite(o)&&Number.isFinite(s)&&(e[t]=(n+2*i+2*o+s)/6);}return e}function Xx(r,e){let t=new Array(r.length).fill(Number.NaN);for(let n=e;n<r.length;n++){let i=r[n];if(!Number.isFinite(i))continue;let o=0,s=0;for(let a=n-e;a<n;a++){let l=r[a];if(!Number.isFinite(l)){s=-1;break}s+=1,l<=i&&(o+=1);}s===e&&(t[n]=100*o/e);}return t}function Ms(r){let e=new Array(r.length).fill(Number.NaN),t=0,n=false;for(let i=0;i<r.length;i++){let o=r[i];Number.isFinite(o)&&(t+=o,n=true),n&&(e[i]=t);}return e}function D(r,e="length",t="Length",n=5e3){return {key:e,title:t,type:"int",defval:r,min:1,max:n,step:1}}function be(r="Close"){return {key:"source",title:"Source",type:"string",defval:r,options:$x}}function X(r=_,e="Color",t="color"){return {key:t,title:e,type:"color",defval:r}}function Mn(r,e=.08){let t=/^#([0-9a-f]{6})$/i.exec(r.trim());if(!t)return r;let n=Math.round(e*255).toString(16).padStart(2,"0");return `#${t[1]}${n}`}var kI=["SMA","EMA","WMA","RMA","VWMA"],jx={key:"offset",title:"Offset",type:"int",defval:0,min:-500,max:500,step:1};function qx(r,e,t,n){return {type:r,title:e,shortTitle:t,overlay:true,inputs:[D(20),be(),jx,X()],compute:(i,o)=>{let s=I(o,"length",20),a=n(ee(i,F(o,"source","Close")),s),l=Math.trunc(I(o,"offset",0));return l!==0&&(a=ot(a,l)),{plots:[{key:t.toLowerCase(),title:t,values:a,color:F(o,"color",_),width:2}]}}}}var EI=qx("sma","Simple Moving Average","SMA",ge),LI=qx("ema","Exponential Moving Average","EMA",Q),MI={type:"moving-average",title:"Moving Average",shortTitle:"MA",overlay:true,inputs:[{key:"maType",title:"Type",type:"string",defval:"SMA",options:kI},D(20),be(),jx,X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","Close")),i=F(e,"maType","SMA"),o;switch(i){case "EMA":o=Q(n,t);break;case "WMA":o=uu(n,t);break;case "RMA":o=Pe(n,t);break;case "VWMA":o=Gx(n,xt(r),t);break;default:o=ge(n,t);}let s=Math.trunc(I(e,"offset",0));return s!==0&&(o=ot(o,s)),{plots:[{key:"ma",title:i,values:o,color:F(e,"color",_),width:2}]}}},PI={type:"rma",title:"Smoothed Moving Average",shortTitle:"RMA",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"rma",title:"RMA",values:Pe(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}]})},II={type:"zlema",title:"Zero-Lag Exponential Moving Average",shortTitle:"ZLEMA",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>{let t=I(e,"length",14),n=ee(r,F(e,"source","Close")),i=Math.floor((t-1)/2),o=ot(n,i),s=K(n,o,(a,l)=>2*a-l);return {plots:[{key:"zlema",title:"ZLEMA",values:Q(s,t),color:F(e,"color",_),width:2}]}}},AI={type:"vidya",title:"Variable Index Dynamic Average",shortTitle:"VIDYA",overlay:true,inputs:[D(14),{key:"cmoLength",title:"Momentum length",type:"int",defval:9,min:1,max:500,step:1},be(),X()],compute:(r,e)=>{let t=I(e,"length",14),n=I(e,"cmoLength",9),i=ee(r,F(e,"source","Close")),o=ze(i),s=new Array(i.length).fill(Number.NaN),a=new Array(i.length).fill(Number.NaN);for(let d=n;d<i.length;d++){let h=0,p=0,m=true;for(let f=d-n+1;f<=d;f++){let g=o[f];if(!Number.isFinite(g)){m=false;break}g>0?h+=g:p-=g;}m&&(s[d]=h,a[d]=p);}let l=2/(t+1),c=new Array(i.length).fill(Number.NaN),u=Number.NaN;for(let d=0;d<i.length;d++){let h=i[d],p=s[d],m=a[d];if(!Number.isFinite(h)||!Number.isFinite(p)||!Number.isFinite(m))continue;let f=p+m,g=f===0?0:Math.abs((p-m)/f);u=Number.isFinite(u)?l*g*h+(1-l*g)*u:h,c[d]=u;}return {plots:[{key:"vidya",title:"VIDYA",values:c,color:F(e,"color",_),width:2}]}}},RI={type:"ma-envelope",title:"Moving Average Envelope",shortTitle:"MA Env",overlay:true,inputs:[{key:"maType",title:"Type",type:"string",defval:"SMA",options:["SMA","EMA"]},D(20),be(),{key:"percent",title:"Percent",type:"float",defval:2.5,min:.01,max:50,step:.1},X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","Close")),i=F(e,"maType","SMA")==="EMA"?Q(n,t):ge(n,t),o=I(e,"percent",2.5)/100,s=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:i,color:s,width:2},{key:"upper",title:"Upper",values:ae(i,a=>a*(1+o)),color:s},{key:"lower",title:"Lower",values:ae(i,a=>a*(1-o)),color:s}],bands:[{key:"envelope",from:"upper",to:"lower",color:Mn(s)}]}}},DI={type:"linear-regression",title:"Linear Regression Curve",shortTitle:"LinReg",overlay:true,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"linreg",title:"LinReg",values:hu(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}]})},Zx=[EI,LI,MI,PI,II,AI,RI,DI];function Ep(r,e){let t=I(e,"length",20),n=I(e,"mult",2),i=ee(r,F(e,"source","Close")),o=ge(i,t),s=ae(sn(i,t),a=>a*n);return {basis:o,upper:K(o,s,(a,l)=>a+l),lower:K(o,s,(a,l)=>a-l)}}var Lp=[D(20),be(),{key:"mult",title:"StdDev",type:"float",defval:2,min:.1,max:50,step:.1}],OI={type:"bollinger-bands",title:"Bollinger Bands",shortTitle:"BB",overlay:true,inputs:[...Lp,X()],compute:(r,e)=>{let{basis:t,upper:n,lower:i}=Ep(r,e),o=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:t,color:ue},{key:"upper",title:"Upper",values:n,color:o},{key:"lower",title:"Lower",values:i,color:o}],bands:[{key:"bb",from:"upper",to:"lower",color:Mn(o)}]}}},NI={type:"percent-b",title:"Bollinger Bands %B",shortTitle:"%B",overlay:false,inputs:[...Lp,X()],compute:(r,e)=>{let{upper:t,lower:n}=Ep(r,e);return {plots:[{key:"pb",title:"%B",values:ee(r,F(e,"source","Close")).map((s,a)=>{let l=t[a],c=n[a];return Number.isFinite(l)&&Number.isFinite(c)&&l!==c?(s-c)/(l-c):Number.NaN}),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:1,color:J},{key:"middle",price:.5,color:J,lineStyle:"dotted"},{key:"lower",price:0,color:J}]}}},FI={type:"bandwidth",title:"Bollinger Bands Width",shortTitle:"BandWidth",overlay:false,inputs:[...Lp,X()],compute:(r,e)=>{let{basis:t,upper:n,lower:i}=Ep(r,e);return {plots:[{key:"bbw",title:"BBW",values:t.map((s,a)=>{let l=n[a],c=i[a];return Number.isFinite(s)&&s!==0&&Number.isFinite(l)&&Number.isFinite(c)?(l-c)/s*100:Number.NaN}),color:F(e,"color",_),width:2}]}}},VI={type:"keltner-channels",title:"Keltner Channels",shortTitle:"KC",overlay:true,inputs:[D(20),{key:"mult",title:"Multiplier",type:"float",defval:2,min:.1,max:50,step:.1},{key:"atrLength",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},be(),X()],compute:(r,e)=>{let t=I(e,"length",20),n=I(e,"mult",2),i=Q(ee(r,F(e,"source","Close")),t),o=ae(Hr(r,I(e,"atrLength",10)),a=>a*n),s=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:i,color:ue},{key:"upper",title:"Upper",values:K(i,o,(a,l)=>a+l),color:s},{key:"lower",title:"Lower",values:K(i,o,(a,l)=>a-l),color:s}],bands:[{key:"kc",from:"upper",to:"lower",color:Mn(s)}]}}},_I={type:"donchian-channels",title:"Donchian Channels",shortTitle:"DC",overlay:true,inputs:[D(20),X()],compute:(r,e)=>{let t=I(e,"length",20),n=ct(Ue(r),t),i=St(Ye(r),t),o=F(e,"color",_);return {plots:[{key:"basis",title:"Basis",values:K(n,i,(s,a)=>(s+a)/2),color:ue},{key:"upper",title:"Upper",values:n,color:o},{key:"lower",title:"Lower",values:i,color:o}],bands:[{key:"dc",from:"upper",to:"lower",color:Mn(o)}]}}},BI={type:"chandelier-exit",title:"Chandelier Exit",shortTitle:"CE",overlay:true,inputs:[D(22),{key:"mult",title:"ATR multiplier",type:"float",defval:3,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"length",22),n=ae(Hr(r,t),s=>s*I(e,"mult",3)),i=K(ct(Ue(r),t),n,(s,a)=>s-a),o=K(St(Ye(r),t),n,(s,a)=>s+a);return {plots:[{key:"long",title:"Long stop",values:i,color:z},{key:"short",title:"Short stop",values:o,color:W}]}}},HI={type:"chande-kroll-stop",title:"Chande Kroll Stop",shortTitle:"CKS",overlay:true,inputs:[{key:"p",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},{key:"x",title:"ATR multiplier",type:"float",defval:1,min:.1,max:50,step:.1},{key:"q",title:"Stop length",type:"int",defval:9,min:1,max:500,step:1}],compute:(r,e)=>{let t=I(e,"p",10),n=I(e,"x",1),i=I(e,"q",9),o=ae(Hr(r,t),l=>l*n),s=K(ct(Ue(r),t),o,(l,c)=>l-c),a=K(St(Ye(r),t),o,(l,c)=>l+c);return {plots:[{key:"stopShort",title:"Stop short",values:ct(s,i),color:W},{key:"stopLong",title:"Stop long",values:St(a,i),color:z}]}}},zI={type:"supertrend",title:"SuperTrend",shortTitle:"SuperTrend",overlay:true,inputs:[{key:"atrLength",title:"ATR length",type:"int",defval:10,min:1,max:500,step:1},{key:"mult",title:"Factor",type:"float",defval:3,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"atrLength",10),n=I(e,"mult",3),i=Hr(r,t),o=r.length,s=new Array(o).fill(Number.NaN),a=new Array(o).fill(1),l=Number.NaN,c=Number.NaN,u=1;for(let h=0;h<o;h++){let p=i[h];if(!Number.isFinite(p))continue;let m=r[h],f=(m.high+m.low)/2,g=f-n*p,b=f+n*p,y=h>0?r[h-1].close:m.close;l=Number.isFinite(l)&&y>l?Math.max(g,l):g,c=Number.isFinite(c)&&y<c?Math.min(b,c):b,u===1&&m.close<l?u=-1:u===-1&&m.close>c&&(u=1),a[h]=u,s[h]=u===1?l:c;}let d=a.map((h,p)=>Number.isFinite(s[p])?h===1?z:W:null);return {plots:[{key:"st",title:"SuperTrend",values:s,color:z,width:2,colors:d}]}}},$I={type:"williams-alligator",title:"Williams Alligator",shortTitle:"Alligator",overlay:true,inputs:[{key:"jawLength",title:"Jaw length",type:"int",defval:13,min:1,max:500,step:1},{key:"teethLength",title:"Teeth length",type:"int",defval:8,min:1,max:500,step:1},{key:"lipsLength",title:"Lips length",type:"int",defval:5,min:1,max:500,step:1},{key:"jawOffset",title:"Jaw offset",type:"int",defval:8,min:0,max:100,step:1},{key:"teethOffset",title:"Teeth offset",type:"int",defval:5,min:0,max:100,step:1},{key:"lipsOffset",title:"Lips offset",type:"int",defval:3,min:0,max:100,step:1}],compute:(r,e)=>{let t=ee(r,"HL2"),n=ot(Pe(t,I(e,"jawLength",13)),I(e,"jawOffset",8)),i=ot(Pe(t,I(e,"teethLength",8)),I(e,"teethOffset",5)),o=ot(Pe(t,I(e,"lipsLength",5)),I(e,"lipsOffset",3));return {plots:[{key:"jaw",title:"Jaw",values:n,color:_},{key:"teeth",title:"Teeth",values:i,color:W},{key:"lips",title:"Lips",values:o,color:z}]}}},WI={type:"gator-oscillator",title:"Gator Oscillator",shortTitle:"Gator Oscillator",overlay:false,inputs:[],compute:r=>{let e=ee(r,"HL2"),t=ot(Pe(e,13),8),n=ot(Pe(e,8),5),i=ot(Pe(e,5),3),o=ae(ke(t,n),Math.abs),s=ae(ke(n,i),l=>-Math.abs(l)),a=l=>l.map((c,u)=>{if(!Number.isFinite(c))return null;let d=u>0?l[u-1]:Number.NaN;return Number.isFinite(d)&&Math.abs(c)>Math.abs(d)?z:W});return {plots:[{key:"upper",title:"Upper",values:o,kind:"histogram",color:z,colors:a(o),base:0},{key:"lower",title:"Lower",values:s,kind:"histogram",color:W,colors:a(s),base:0}]}}},Jx=[OI,NI,FI,VI,_I,BI,HI,zI,$I,WI];function an(r,e,t){let n=[{key:"upper",price:e,color:J},{key:"lower",price:r,color:J}];return t!=null&&n.splice(1,0,{key:"middle",price:t,color:J,lineStyle:"dotted"}),n}var st=[{key:"zero",price:0,color:J}];function mu(r){return r.map((e,t)=>{if(!Number.isFinite(e))return null;let n=t>0?r[t-1]:Number.NaN,i=Number.isFinite(n)?e>=n:true;return e>=0?i?z:`${z}80`:i?`${W}80`:W})}var GI={type:"rsi",title:"Relative Strength Index",shortTitle:"RSI",overlay:false,inputs:[D(14),be(),X()],compute:(r,e)=>({plots:[{key:"rsi",title:"RSI",values:Ls(ee(r,F(e,"source","Close")),I(e,"length",14)),color:F(e,"color",_),width:2}],levels:an(30,70,50)})},UI={type:"stochastic",title:"Stochastic",shortTitle:"Stoch",overlay:false,inputs:[D(14,"kLength","%K length"),D(1,"kSmoothing","%K smoothing",500),D(3,"dLength","%D smoothing",500)],compute:(r,e)=>{let t=ge(du(Oe(r),Ue(r),Ye(r),I(e,"kLength",14)),I(e,"kSmoothing",1)),n=ge(t,I(e,"dLength",3));return {plots:[{key:"k",title:"%K",values:t,color:_,width:2},{key:"d",title:"%D",values:n,color:ue}],levels:an(20,80)}}},YI={type:"stochastic-rsi",title:"Stochastic RSI",shortTitle:"Stoch RSI",overlay:false,inputs:[D(14,"rsiLength","RSI length"),D(14,"stochLength","Stochastic length"),D(3,"kSmoothing","%K smoothing",500),D(3,"dLength","%D smoothing",500),be()],compute:(r,e)=>{let t=Ls(ee(r,F(e,"source","Close")),I(e,"rsiLength",14)),n=ge(du(t,t,t,I(e,"stochLength",14)),I(e,"kSmoothing",3)),i=ge(n,I(e,"dLength",3));return {plots:[{key:"k",title:"%K",values:n,color:_,width:2},{key:"d",title:"%D",values:i,color:ue}],levels:an(20,80)}}},KI={type:"macd",title:"MACD",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal smoothing",500),be()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=ke(Q(t,I(e,"fastLength",12)),Q(t,I(e,"slowLength",26))),i=Q(n,I(e,"signalLength",9)),o=ke(n,i);return {plots:[{key:"hist",title:"Histogram",values:o,kind:"histogram",color:z,colors:mu(o),base:0},{key:"macd",title:"MACD",values:n,color:_,width:2},{key:"signal",title:"Signal",values:i,color:ue}],levels:st}}},XI={type:"ppo",title:"Percentage Price Oscillator",shortTitle:"PPO",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal smoothing",500),be()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=Q(t,I(e,"fastLength",12)),i=Q(t,I(e,"slowLength",26)),o=K(n,i,(l,c)=>c===0?Number.NaN:(l-c)/c*100),s=Q(o,I(e,"signalLength",9)),a=ke(o,s);return {plots:[{key:"hist",title:"Histogram",values:a,kind:"histogram",color:z,colors:mu(a),base:0},{key:"ppo",title:"PPO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:s,color:ue}],levels:st}}},jI={type:"awesome-oscillator",title:"Awesome Oscillator",shortTitle:"AO",overlay:false,inputs:[],compute:r=>{let e=ee(r,"HL2"),t=ke(ge(e,5),ge(e,34)),n=t.map((i,o)=>{if(!Number.isFinite(i))return null;let s=o>0?t[o-1]:Number.NaN;return Number.isFinite(s)&&i<s?W:z});return {plots:[{key:"ao",title:"AO",values:t,kind:"histogram",color:z,colors:n,base:0}],levels:st}}},qI={type:"commodity-channel-index",title:"Commodity Channel Index",shortTitle:"CCI",overlay:false,inputs:[D(20),be("HLC3"),X()],compute:(r,e)=>{let t=I(e,"length",20),n=ee(r,F(e,"source","HLC3")),i=ge(n,t),o=new Array(n.length).fill(Number.NaN);for(let a=t-1;a<n.length;a++){let l=i[a];if(!Number.isFinite(l))continue;let c=0;for(let u=a-t+1;u<=a;u++)c+=Math.abs(n[u]-l);o[a]=c/t;}return {plots:[{key:"cci",title:"CCI",values:n.map((a,l)=>{let c=i[l],u=o[l];return Number.isFinite(c)&&Number.isFinite(u)&&u!==0?(a-c)/(.015*u):Number.NaN}),color:F(e,"color",_),width:2}],levels:an(-100,100,0)}}},ZI={type:"williams-percent-r",title:"Williams %R",shortTitle:"%R",overlay:false,inputs:[D(14),X()],compute:(r,e)=>({plots:[{key:"wr",title:"%R",values:ae(du(Oe(r),Ue(r),Ye(r),I(e,"length",14)),n=>n-100),color:F(e,"color",_),width:2}],levels:an(-80,-20)})},JI={type:"chande-momentum-oscillator",title:"Chande Momentum Oscillator",shortTitle:"CMO",overlay:false,inputs:[D(9),be(),X()],compute:(r,e)=>{let t=I(e,"length",9),n=ze(ee(r,F(e,"source","Close"))),i=xe(ae(n,a=>Math.max(a,0)),t),o=xe(ae(n,a=>Math.max(-a,0)),t);return {plots:[{key:"cmo",title:"CMO",values:K(i,o,(a,l)=>a+l===0?0:100*(a-l)/(a+l)),color:F(e,"color",_),width:2}],levels:an(-50,50,0)}}},QI={type:"connors-rsi",title:"Connors RSI",shortTitle:"CRSI",overlay:false,inputs:[D(3,"rsiLength","RSI length"),D(2,"streakLength","Streak RSI length"),D(100,"rankLength","Percent-rank length"),X()],compute:(r,e)=>{let t=Oe(r),n=new Array(t.length).fill(0);for(let l=1;l<t.length;l++){let c=t[l]-t[l-1];n[l]=c>0?Math.max(n[l-1],0)+1:c<0?Math.min(n[l-1],0)-1:0;}let i=Ls(t,I(e,"rsiLength",3)),o=Ls(n,I(e,"streakLength",2)),s=Xx(Vt(t,1),I(e,"rankLength",100));return {plots:[{key:"crsi",title:"CRSI",values:t.map((l,c)=>{let u=i[c],d=o[c],h=s[c];return Number.isFinite(u)&&Number.isFinite(d)&&Number.isFinite(h)?(u+d+h)/3:Number.NaN}),color:F(e,"color",_),width:2}],levels:an(20,80,50)}}},eA={type:"fisher-transform",title:"Fisher Transform",shortTitle:"Fisher",overlay:false,inputs:[D(9)],compute:(r,e)=>{let t=I(e,"length",9),n=ee(r,"HL2"),i=ct(n,t),o=St(n,t),s=r.length,a=new Array(s).fill(Number.NaN),l=0,c=0;for(let u=0;u<s;u++){let d=i[u],h=o[u];if(!Number.isFinite(d)||!Number.isFinite(h))continue;let p=d===h?0:(n[u]-h)/(d-h)-.5;l=Math.max(-0.999,Math.min(.999,.66*p+.67*l)),c=.5*Math.log((1+l)/(1-l))+.5*c,a[u]=c;}return {plots:[{key:"fisher",title:"Fisher",values:a,color:_,width:2},{key:"trigger",title:"Trigger",values:ot(a,1),color:ue}],levels:st}}},tA={type:"trix",title:"TRIX",overlay:false,inputs:[D(18),X()],compute:(r,e)=>{let t=I(e,"length",18),n=ae(Oe(r),Math.log),i=Q(Q(Q(n,t),t),t);return {plots:[{key:"trix",title:"TRIX",values:ae(ze(i),s=>s*1e4),color:F(e,"color",_),width:2}],levels:st}}};function Qx(r,e,t){let n=ze(r),i=Q(Q(n,e),t),o=Q(Q(ae(n,Math.abs),e),t);return K(i,o,(s,a)=>a===0?0:100*s/a)}var nA={type:"true-strength-index",title:"True Strength Index",shortTitle:"TSI",overlay:false,inputs:[D(25,"longLength","Long length"),D(13,"shortLength","Short length"),D(13,"signalLength","Signal length")],compute:(r,e)=>{let t=Qx(Oe(r),I(e,"longLength",25),I(e,"shortLength",13));return {plots:[{key:"tsi",title:"TSI",values:t,color:_,width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",13)),color:ue}],levels:st}}},rA={type:"smi-ergodic",title:"SMI Ergodic Oscillator",shortTitle:"SMIE",overlay:false,inputs:[D(5,"shortLength","Short length"),D(20,"longLength","Long length"),D(5,"signalLength","Signal length")],compute:(r,e)=>{let t=Qx(Oe(r),I(e,"longLength",20),I(e,"shortLength",5)),n=Q(t,I(e,"signalLength",5)),i=ke(t,n);return {plots:[{key:"osc",title:"Oscillator",values:i,kind:"histogram",color:z,colors:mu(i),base:0},{key:"smi",title:"SMI",values:t,color:_,width:2},{key:"signal",title:"Signal",values:n,color:ue}],levels:st}}},iA={type:"schaff-trend-cycle",title:"Schaff Trend Cycle",shortTitle:"Schaff Trend Cycle",overlay:false,inputs:[D(10,"cycleLength","Cycle length"),D(23,"fastLength","Fast length"),D(50,"slowLength","Slow length")],compute:(r,e)=>{let t=I(e,"cycleLength",10),n=Oe(r),i=ke(Q(n,I(e,"fastLength",23)),Q(n,I(e,"slowLength",50))),o=a=>{let l=St(a,t),c=ct(a,t),u=new Array(a.length).fill(Number.NaN),d=Number.NaN,h=Number.NaN;for(let p=0;p<a.length;p++){let m=a[p],f=l[p],g=c[p];if(!Number.isFinite(m)||!Number.isFinite(f)||!Number.isFinite(g))continue;let b=g>f?(m-f)/(g-f)*100:Number.isFinite(d)?d:50;d=b,h=Number.isFinite(h)?h+.5*(b-h):b,u[p]=h;}return u};return {plots:[{key:"stc",title:"STC",values:o(o(i)),color:_,width:2}],levels:an(25,75)}}},oA={type:"know-sure-thing",title:"Know Sure Thing",shortTitle:"KST",overlay:false,inputs:[be(),D(9,"signalLength","Signal length")],compute:(r,e)=>{let t=ee(r,F(e,"source","Close")),n=[ge(Vt(t,10),10),ge(Vt(t,15),10),ge(Vt(t,20),10),ge(Vt(t,30),15)].reduce((i,o,s)=>K(i,o,(a,l)=>a+l*(s+1)),new Array(t.length).fill(0));return {plots:[{key:"kst",title:"KST",values:n,color:_,width:2},{key:"signal",title:"Signal",values:ge(n,I(e,"signalLength",9)),color:ue}],levels:st}}},sA={type:"coppock-curve",title:"Coppock Curve",shortTitle:"Coppock",overlay:false,inputs:[D(10,"wmaLength","WMA length"),D(14,"longRoc","Long RoC length"),D(11,"shortRoc","Short RoC length"),be(),X()],compute:(r,e)=>{let t=ee(r,F(e,"source","Close"));return {plots:[{key:"coppock",title:"Coppock",values:uu(K(Vt(t,I(e,"longRoc",14)),Vt(t,I(e,"shortRoc",11)),(i,o)=>i+o),I(e,"wmaLength",10)),color:F(e,"color",_),width:2}],levels:st}}},aA={type:"detrended-price-oscillator",title:"Detrended Price Oscillator",shortTitle:"DPO",overlay:false,inputs:[D(21),X()],compute:(r,e)=>{let t=I(e,"length",21),n=Math.floor(t/2)+1;return {plots:[{key:"dpo",title:"DPO",values:ke(Oe(r),ot(ge(Oe(r),t),n)),color:F(e,"color",_),width:2}],levels:st}}},lA={type:"rate-of-change",title:"Rate of Change",shortTitle:"ROC",overlay:false,inputs:[D(9),be(),X()],compute:(r,e)=>({plots:[{key:"roc",title:"RoC",values:Vt(ee(r,F(e,"source","Close")),I(e,"length",9)),color:F(e,"color",_),width:2}],levels:st})},cA={type:"ultimate-oscillator",title:"Ultimate Oscillator",shortTitle:"UO",overlay:false,inputs:[D(7,"fastLength","Fast length"),D(14,"middleLength","Middle length"),D(28,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=r.length,n=new Array(t).fill(Number.NaN),i=new Array(t).fill(Number.NaN);for(let u=0;u<t;u++){let d=r[u],h=u>0?r[u-1].close:d.close,p=Math.min(d.low,h),m=Math.max(d.high,h);n[u]=d.close-p,i[u]=m-p;}let o=u=>K(xe(n,u),xe(i,u),(d,h)=>h===0?Number.NaN:d/h),s=o(I(e,"fastLength",7)),a=o(I(e,"middleLength",14)),l=o(I(e,"slowLength",28));return {plots:[{key:"uo",title:"UO",values:s.map((u,d)=>{let h=a[d],p=l[d];return Number.isFinite(u)&&Number.isFinite(h)&&Number.isFinite(p)?100*(4*u+2*h+p)/7:Number.NaN}),color:F(e,"color",_),width:2}],levels:an(30,70,50)}}},uA={type:"relative-vigor-index",title:"Relative Vigor Index",shortTitle:"RVGI",overlay:false,inputs:[D(10)],compute:(r,e)=>{let t=I(e,"length",10),n=pu(ke(Oe(r),Wx(r))),i=pu(ke(Ue(r),Ye(r))),o=K(xe(n,t),xe(i,t),(s,a)=>a===0?0:s/a);return {plots:[{key:"rvgi",title:"RVGI",values:o,color:_,width:2},{key:"signal",title:"Signal",values:pu(o),color:ue}],levels:st}}},dA={type:"relative-volatility-index",title:"Relative Volatility Index",shortTitle:"RVI",overlay:false,inputs:[D(10,"stdevLength","StdDev length"),D(14,"smoothLength","Smoothing length"),be(),X()],compute:(r,e)=>{let t=I(e,"smoothLength",14),n=ee(r,F(e,"source","Close")),i=sn(n,I(e,"stdevLength",10)),o=ze(n),s=Pe(K(i,o,(c,u)=>u>0?c:0),t),a=Pe(K(i,o,(c,u)=>u<=0?c:0),t);return {plots:[{key:"rvi",title:"RVI",values:K(s,a,(c,u)=>c+u===0?50:100*c/(c+u)),color:F(e,"color",_),width:2}],levels:an(20,80,50)}}},hA={type:"balance-of-power",title:"Balance of Power",shortTitle:"BOP",overlay:false,inputs:[X()],compute:(r,e)=>({plots:[{key:"bop",title:"BOP",values:r.map(n=>n.high===n.low?0:(n.close-n.open)/(n.high-n.low)),color:F(e,"color",_),width:2}],levels:st})},pA={type:"elder-ray",title:"Elder Ray",overlay:false,inputs:[D(13)],compute:(r,e)=>{let t=Q(Oe(r),I(e,"length",13));return {plots:[{key:"bull",title:"Bull power",values:ke(Ue(r),t),kind:"histogram",color:z,base:0},{key:"bear",title:"Bear power",values:ke(Ye(r),t),kind:"histogram",color:W,base:0}],levels:st}}},mA={type:"ttm-squeeze",title:"TTM Squeeze",overlay:false,inputs:[D(20),{key:"bbMult",title:"Bollinger multiplier",type:"float",defval:2,min:.1,max:50,step:.1},{key:"kcMult",title:"Keltner multiplier",type:"float",defval:1.5,min:.1,max:50,step:.1}],compute:(r,e)=>{let t=I(e,"length",20),n=Oe(r),i=ge(n,t),o=ae(sn(n,t),h=>h*I(e,"bbMult",2)),s=ae(Pe(Qn(r),t),h=>h*I(e,"kcMult",1.5)),a=K(ct(Ue(r),t),St(Ye(r),t),(h,p)=>(h+p)/2),l=K(a,i,(h,p)=>(h+p)/2),c=hu(ke(n,l),t),d=n.map((h,p)=>{let m=o[p],f=s[p];return Number.isFinite(m)&&Number.isFinite(f)?m<f:false}).map((h,p)=>Number.isFinite(c[p])?h?W:z:null);return {plots:[{key:"mom",title:"Momentum",values:c,kind:"histogram",color:z,colors:mu(c),base:0},{key:"squeeze",title:"Squeeze",values:c.map(h=>Number.isFinite(h)?0:Number.NaN),kind:"cross",color:Je,colors:d}]}}},e0=[GI,UI,YI,KI,XI,jI,qI,ZI,JI,QI,eA,tA,nA,rA,iA,oA,sA,aA,lA,cA,uA,dA,hA,pA,mA];var fA={type:"aroon",title:"Aroon",overlay:false,inputs:[D(14)],compute:(r,e)=>{let t=I(e,"length",14),n=ae(Ux(Ue(r),t+1),o=>100*(t-o)/t),i=ae(Yx(Ye(r),t+1),o=>100*(t-o)/t);return {plots:[{key:"up",title:"Aroon up",values:n,color:z,width:2},{key:"down",title:"Aroon down",values:i,color:W,width:2}]}}},gA={type:"average-directional-index",title:"Average Directional Index",shortTitle:"ADX",overlay:false,inputs:[D(14,"diLength","DI length"),D(14,"adxLength","ADX smoothing")],compute:(r,e)=>{let t=I(e,"diLength",14),n=I(e,"adxLength",14),i=r.length,o=new Array(i).fill(Number.NaN),s=new Array(i).fill(Number.NaN);for(let d=1;d<i;d++){let h=r[d].high-r[d-1].high,p=r[d-1].low-r[d].low;o[d]=h>p&&h>0?h:0,s[d]=p>h&&p>0?p:0;}let a=Pe(Qn(r),t),l=K(Pe(o,t),a,(d,h)=>h===0?0:100*d/h),c=K(Pe(s,t),a,(d,h)=>h===0?0:100*d/h),u=K(l,c,(d,h)=>d+h===0?0:100*Math.abs(d-h)/(d+h));return {plots:[{key:"adx",title:"ADX",values:Pe(u,n),color:_,width:2},{key:"plusDi",title:"+DI",values:l,color:z},{key:"minusDi",title:"-DI",values:c,color:W}],levels:[{key:"threshold",price:25,color:J,lineStyle:"dotted"}]}}},bA={type:"vortex-indicator",title:"Vortex Indicator",shortTitle:"VI",overlay:false,inputs:[D(14)],compute:(r,e)=>{let t=I(e,"length",14),n=r.length,i=new Array(n).fill(Number.NaN),o=new Array(n).fill(Number.NaN);for(let a=1;a<n;a++)i[a]=Math.abs(r[a].high-r[a-1].low),o[a]=Math.abs(r[a].low-r[a-1].high);let s=xe(Qn(r),t);return {plots:[{key:"viPlus",title:"VI+",values:K(xe(i,t),s,(a,l)=>l===0?Number.NaN:a/l),color:z,width:2},{key:"viMinus",title:"VI-",values:K(xe(o,t),s,(a,l)=>l===0?Number.NaN:a/l),color:W,width:2}],levels:[{key:"one",price:1,color:J,lineStyle:"dotted"}]}}},t0=[fA,gA,bA];var vA={type:"average-true-range",title:"Average True Range",shortTitle:"ATR",overlay:false,inputs:[D(14),X()],compute:(r,e)=>({plots:[{key:"atr",title:"ATR",values:Hr(r,I(e,"length",14)),color:F(e,"color",_),width:2}]})},yA={type:"historical-volatility",title:"Historical Volatility",shortTitle:"HV",overlay:false,inputs:[D(10),{key:"annual",title:"Periods per year",type:"int",defval:365,min:1,max:1e5,step:1,tooltip:"Annualization factor (365 for daily crypto bars, 252 for stock sessions)"},X()],compute:(r,e)=>{let t=ae(ze(ae(Oe(r),Math.log)),i=>i);return {plots:[{key:"hv",title:"HV",values:ae(sn(t,I(e,"length",10)),i=>i*Math.sqrt(I(e,"annual",365))*100),color:F(e,"color",_),width:2}]}}},wA={type:"chaikin-volatility",title:"Chaikin Volatility",shortTitle:"CHV",overlay:false,inputs:[D(10,"emaLength","EMA length"),D(10,"rocLength","RoC length"),X()],compute:(r,e)=>{let t=Q(ke(Ue(r),Ye(r)),I(e,"emaLength",10));return {plots:[{key:"cv",title:"Chaikin Vol",values:Vt(t,I(e,"rocLength",10)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},xA={type:"mass-index",title:"Mass Index",shortTitle:"MI",overlay:false,inputs:[D(25),X()],compute:(r,e)=>{let t=ke(Ue(r),Ye(r)),n=Q(t,9),i=K(n,Q(n,9),(o,s)=>s===0?Number.NaN:o/s);return {plots:[{key:"mi",title:"Mass Index",values:xe(i,I(e,"length",25)),color:F(e,"color",_),width:2}],levels:[{key:"reversal",price:27,color:J,lineStyle:"dotted"}]}}},SA={type:"standard-deviation",title:"Standard Deviation",shortTitle:"StdDev",overlay:false,inputs:[D(20),be(),X()],compute:(r,e)=>({plots:[{key:"stdev",title:"StdDev",values:sn(ee(r,F(e,"source","Close")),I(e,"length",20)),color:F(e,"color",_),width:2}]})},CA={type:"ulcer-index",title:"Ulcer Index",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=Oe(r),i=K(n,ct(n,t),(s,a)=>a===0?0:100*(s-a)/a);return {plots:[{key:"ui",title:"Ulcer",values:ae(ge(ae(i,s=>s*s),t),Math.sqrt),color:F(e,"color",_),width:2}]}}},TA={type:"choppiness-index",title:"Choppiness Index",shortTitle:"CHOP",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=xe(Qn(r),t),i=K(ct(Ue(r),t),St(Ye(r),t),(s,a)=>s-a);return {plots:[{key:"chop",title:"CHOP",values:K(n,i,(s,a)=>a>0&&s>0?100*Math.log10(s/a)/Math.log10(t):Number.NaN),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:61.8,color:J},{key:"lower",price:38.2,color:J}]}}},n0=[vA,yA,wA,xA,SA,CA,TA];function fu(r){return r.map(e=>e.volume==null||!Number.isFinite(e.volume)?Number.NaN:e.high===e.low?0:(2*e.close-e.high-e.low)/(e.high-e.low)*e.volume)}var kA={type:"on-balance-volume",title:"On Balance Volume",shortTitle:"OBV",overlay:false,inputs:[X()],compute:(r,e)=>{let t=xt(r),n=ze(Oe(r)),i=K(t,n,(o,s)=>s>0?o:s<0?-o:0);return {plots:[{key:"obv",title:"OBV",values:Ms(i),color:F(e,"color",_),width:2}]}}},EA={type:"accumulation-distribution",title:"Accumulation / Distribution",shortTitle:"A/D",overlay:false,inputs:[X()],compute:(r,e)=>({plots:[{key:"ad",title:"A/D",values:Ms(fu(r)),color:F(e,"color",_),width:2}]})},LA={type:"chaikin-money-flow",title:"Chaikin Money Flow",shortTitle:"CMF",overlay:false,inputs:[D(20),X()],compute:(r,e)=>{let t=I(e,"length",20);return {plots:[{key:"cmf",title:"CMF",values:K(xe(fu(r),t),xe(xt(r),t),(i,o)=>o===0?0:i/o),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},MA={type:"chaikin-oscillator",title:"Chaikin Oscillator",shortTitle:"Chaikin Osc",overlay:false,inputs:[D(3,"fastLength","Fast length"),D(10,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=Ms(fu(r));return {plots:[{key:"co",title:"Chaikin Osc",values:ke(Q(t,I(e,"fastLength",3)),Q(t,I(e,"slowLength",10))),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},PA={type:"ease-of-movement",title:"Ease of Movement",shortTitle:"EOM",overlay:false,inputs:[D(14),{key:"divisor",title:"Divisor",type:"int",defval:1e4,min:1,max:1e9,step:1},X()],compute:(r,e)=>{let t=I(e,"divisor",1e4),n=ee(r,"HL2"),i=ze(n),o=r.map((s,a)=>{let l=i[a];return s.volume==null||!Number.isFinite(s.volume)||s.volume===0||!Number.isFinite(l)?Number.NaN:t*l*(s.high-s.low)/s.volume});return {plots:[{key:"eom",title:"EOM",values:ge(o,I(e,"length",14)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},IA={type:"force-index",title:"Force Index",shortTitle:"FI",overlay:false,inputs:[D(13),X()],compute:(r,e)=>{let t=K(ze(Oe(r)),xt(r),(n,i)=>n*i);return {plots:[{key:"force",title:"Force",values:Q(t,I(e,"length",13)),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},AA={type:"klinger-oscillator",title:"Klinger Oscillator",shortTitle:"KVO",overlay:false,inputs:[D(34,"fastLength","Fast length"),D(55,"slowLength","Slow length"),D(13,"signalLength","Signal length")],compute:(r,e)=>{let t=ee(r,"HLC3"),n=ze(t),i=K(xt(r),n,(s,a)=>a>=0?s:-s),o=ke(Q(i,I(e,"fastLength",34)),Q(i,I(e,"slowLength",55)));return {plots:[{key:"kvo",title:"KVO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:Q(o,I(e,"signalLength",13)),color:ue}],levels:[{key:"zero",price:0,color:J}]}}},RA={type:"money-flow-index",title:"Money Flow Index",shortTitle:"MFI",overlay:false,inputs:[D(14),X()],compute:(r,e)=>{let t=I(e,"length",14),n=ee(r,"HLC3"),i=K(n,xt(r),(c,u)=>c*u),o=ze(n),s=xe(K(i,o,(c,u)=>u>0?c:0),t),a=xe(K(i,o,(c,u)=>u<0?c:0),t);return {plots:[{key:"mfi",title:"MFI",values:K(s,a,(c,u)=>u===0?100:100-100/(1+c/u)),color:F(e,"color",_),width:2}],levels:[{key:"upper",price:80,color:J},{key:"lower",price:20,color:J}]}}};function r0(r,e){let t=new Array(r.length).fill(Number.NaN),n=1e3,i=false;for(let o=1;o<r.length;o++){let s=r[o].volume,a=r[o-1].volume,l=r[o-1].close;if(s==null||a==null||!Number.isFinite(s)||!Number.isFinite(a)||l===0){i&&(t[o]=n);continue}i=true,e(s,a)&&(n+=(r[o].close-l)/l*n),t[o]=n;}return t}var DA={type:"negative-volume-index",title:"Negative Volume Index",shortTitle:"Negative Volume Index",overlay:false,inputs:[D(255,"signalLength","Signal length"),X()],compute:(r,e)=>{let t=r0(r,(n,i)=>n<i);return {plots:[{key:"nvi",title:"NVI",values:t,color:F(e,"color",_),width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",255)),color:ue}]}}},OA={type:"positive-volume-index",title:"Positive Volume Index",shortTitle:"Positive Volume Index",overlay:false,inputs:[D(255,"signalLength","Signal length"),X()],compute:(r,e)=>{let t=r0(r,(n,i)=>n>i);return {plots:[{key:"pvi",title:"PVI",values:t,color:F(e,"color",_),width:2},{key:"signal",title:"Signal",values:Q(t,I(e,"signalLength",255)),color:ue}]}}},NA={type:"price-volume-trend",title:"Price Volume Trend",shortTitle:"PVT",overlay:false,inputs:[X()],compute:(r,e)=>{let t=Oe(r),n=r.map((i,o)=>{if(o===0||i.volume==null||!Number.isFinite(i.volume))return Number.NaN;let s=t[o-1];return s===0?0:(t[o]-s)/s*i.volume});return {plots:[{key:"pvt",title:"PVT",values:Ms(n),color:F(e,"color",_),width:2}]}}},FA={type:"volume-oscillator",title:"Volume Oscillator",shortTitle:"Vol Osc",overlay:false,inputs:[D(5,"fastLength","Fast length"),D(10,"slowLength","Slow length"),X()],compute:(r,e)=>{let t=xt(r),n=Q(t,I(e,"fastLength",5)),i=Q(t,I(e,"slowLength",10));return {plots:[{key:"vo",title:"Volume Osc",values:K(n,i,(s,a)=>a===0?Number.NaN:100*(s-a)/a),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},VA={type:"pvo",title:"Percentage Volume Oscillator",shortTitle:"PVO",overlay:false,inputs:[D(12,"fastLength","Fast length"),D(26,"slowLength","Slow length"),D(9,"signalLength","Signal length")],compute:(r,e)=>{let t=xt(r),n=Q(t,I(e,"fastLength",12)),i=Q(t,I(e,"slowLength",26)),o=K(n,i,(l,c)=>c===0?Number.NaN:100*(l-c)/c),s=Q(o,I(e,"signalLength",9)),a=ke(o,s);return {plots:[{key:"hist",title:"Histogram",values:a,kind:"histogram",color:z,colors:a.map(l=>Number.isFinite(l)?l>=0?z:W:null),base:0},{key:"pvo",title:"PVO",values:o,color:_,width:2},{key:"signal",title:"Signal",values:s,color:ue}],levels:[{key:"zero",price:0,color:J}]}}},_A={type:"volume-flow-indicator",title:"Volume Flow Indicator",shortTitle:"Volume Flow Indicator",overlay:false,inputs:[D(130),{key:"coef",title:"Cutoff coefficient",type:"float",defval:.2,min:.01,max:10,step:.01},{key:"volCoef",title:"Volume cap",type:"float",defval:2.5,min:.1,max:50,step:.1},D(3,"smoothLength","Smoothing length")],compute:(r,e)=>{let t=I(e,"length",130),n=I(e,"coef",.2),i=I(e,"volCoef",2.5),o=ae(ee(r,"HLC3"),Math.log),s=ze(o),a=sn(s,30),l=xt(r),c=ge(l,t),u=ze(ee(r,"HLC3")),d=r.map((f,g)=>{let b=Number.isFinite(a[g])?n*a[g]*f.close:Number.NaN,y=l[g],v=g>0?c[g-1]:Number.NaN,S=u[g];if(!Number.isFinite(b)||!Number.isFinite(y)||!Number.isFinite(v)||!Number.isFinite(S))return Number.NaN;let E=Math.min(y,v*i);return S>b?E:S<-b?-E:0}),h=r.map((f,g)=>{let b=g>0?c[g-1]:Number.NaN;return Number.isFinite(b)&&b!==0?b:Number.NaN}),p=xe(d,t),m=K(p,h,(f,g)=>f/g);return {plots:[{key:"vfi",title:"VFI",values:ge(m,I(e,"smoothLength",3)),color:_,width:2}],levels:[{key:"zero",price:0,color:J}]}}},BA={type:"intraday-intensity",title:"Intraday Intensity",shortTitle:"Intraday Intensity",overlay:false,inputs:[D(21),X()],compute:(r,e)=>{let t=I(e,"length",21);return {plots:[{key:"ii",title:"II%",values:K(xe(fu(r),t),xe(xt(r),t),(i,o)=>o===0?0:100*i/o),color:F(e,"color",_),width:2}],levels:[{key:"zero",price:0,color:J}]}}},i0=[kA,EA,LA,MA,PA,IA,AA,RA,DA,OA,NA,FA,VA,_A,BA];var Pp=864e5;function Ip(r,e){if(r==="Week")return Math.floor((Math.floor(e/Pp)+3)/7);if(r==="Month"||r==="Quarter"||r==="Year"){let t=new Date(e);return r==="Year"?t.getUTCFullYear():r==="Quarter"?t.getUTCFullYear()*4+Math.floor(t.getUTCMonth()/3):t.getUTCFullYear()*12+t.getUTCMonth()}return Math.floor(e/Pp)}var HA={type:"parabolic-sar",title:"Parabolic SAR",shortTitle:"SAR",overlay:true,inputs:[{key:"start",title:"Start",type:"float",defval:.02,min:.001,max:1,step:.001},{key:"increment",title:"Increment",type:"float",defval:.02,min:.001,max:1,step:.001},{key:"maximum",title:"Max value",type:"float",defval:.2,min:.01,max:1,step:.01}],compute:(r,e)=>{let t=I(e,"start",.02),n=I(e,"increment",.02),i=I(e,"maximum",.2),o=r.length,s=new Array(o).fill(Number.NaN),a=new Array(o).fill(null);if(o>=2){let l=r[1].close>=r[0].close,c=l?r[0].low:r[0].high,u=l?r[0].high:r[0].low,d=t;for(let h=1;h<o;h++){let p=r[h];c+=d*(u-c),l?c=Math.min(c,r[h-1].low,h>=2?r[h-2].low:r[h-1].low):c=Math.max(c,r[h-1].high,h>=2?r[h-2].high:r[h-1].high),(l?p.low<c:p.high>c)?(l=!l,c=u,u=l?p.high:p.low,d=t):l&&p.high>u?(u=p.high,d=Math.min(i,d+n)):!l&&p.low<u&&(u=p.low,d=Math.min(i,d+n)),s[h]=c,a[h]=l?z:W;}}return {plots:[{key:"sar",title:"PSAR",values:s,kind:"circles",color:_,colors:a}]}}},o0="Bands",gu="Style",Mp=[{on:"band1",mult:"band1Mult",color:"band1Color",fill:"band1Fill",fillColor:"band1FillColor",defMult:1,defOn:true,defColor:z},{on:"band2",mult:"band2Mult",color:"band2Color",fill:"band2Fill",fillColor:"band2FillColor",defMult:2,defOn:false,defColor:ue},{on:"band3",mult:"band3Mult",color:"band3Color",fill:"band3Fill",fillColor:"band3FillColor",defMult:3,defOn:false,defColor:Bs[4]}],zA={type:"vwap",title:"Volume Weighted Average Price",shortTitle:"VWAP",overlay:true,inputs:[{key:"anchor",title:"Period",type:"string",defval:"Day",options:["Day","Week","Month","Quarter","Year"],tooltip:"Where the accumulation resets (UTC periods)"},be("HLC3"),...Mp.flatMap((r,e)=>[{key:r.on,title:`Band ${e+1} multiplier`,type:"bool",defval:r.defOn,inline:r.on,group:o0},{key:r.mult,title:"",type:"float",defval:r.defMult,min:.1,max:10,step:.1,inline:r.on,group:o0}]),{...X(Je,"VWAP color"),group:gu},...Mp.flatMap((r,e)=>[{...X(r.defColor,`Band ${e+1} color`,r.color),inline:r.color,group:gu},{key:r.fill,title:"Fill",type:"bool",defval:true,inline:r.color,group:gu},{...X(Mn(r.defColor),"",r.fillColor),inline:r.color,group:gu}])],compute:(r,e)=>{let t=F(e,"anchor","Day"),n=ee(r,F(e,"source","HLC3")),i=r.length,o=new Array(i).fill(Number.NaN),s=Mp.filter(p=>kp(e,p.on,p.defOn)).map(p=>({mult:Math.max(0,I(e,p.mult,p.defMult)),color:F(e,p.color,p.defColor),fill:kp(e,p.fill,true),fillColor:F(e,p.fillColor,Mn(p.defColor)),up:new Array(i).fill(Number.NaN),down:new Array(i).fill(Number.NaN)})),a=Number.NaN,l=0,c=0,u=0;for(let p=0;p<i;p++){let m=r[p],f=Ip(t,m.time);f!==a&&(a=f,l=0,c=0,u=0);let g=m.volume;if(g!=null&&Number.isFinite(g)&&g>0){let v=n[p];l+=v*g,c+=v*v*g,u+=g;}if(u<=0)continue;let b=l/u,y=Math.sqrt(Math.max(0,c/u-b*b));o[p]=b;for(let v of s)v.up[p]=b+v.mult*y,v.down[p]=b-v.mult*y;}let d=[{key:"vwap",title:"VWAP",values:o,color:F(e,"color",Je),width:2}],h=[];return s.forEach((p,m)=>{d.push({key:`up${m}`,title:`Upper ${p.mult}\u03C3`,values:p.up,color:p.color},{key:`down${m}`,title:`Lower ${p.mult}\u03C3`,values:p.down,color:p.color}),p.fill&&h.push({key:`band${m}`,from:`up${m}`,to:`down${m}`,color:p.fillColor});}),{plots:d,bands:h}}},$A={type:"pivot-points",title:"Pivot Points",shortTitle:"Pivots",overlay:true,inputs:[{key:"anchor",title:"Period",type:"string",defval:"Day",options:["Day","Week","Month"]}],compute:(r,e)=>{let t=F(e,"anchor","Day"),n=new Map;for(let l of r){let c=Ip(t,l.time),u=n.get(c);u?(u.high=Math.max(u.high,l.high),u.low=Math.min(u.low,l.low),u.close=l.close):n.set(c,{high:l.high,low:l.low,close:l.close});}let i=r.length,o=()=>new Array(i).fill(Number.NaN),s={p:o(),r1:o(),s1:o(),r2:o(),s2:o(),r3:o(),s3:o()};for(let l=0;l<i;l++){let c=n.get(Ip(t,r[l].time)-1);if(!c)continue;let u=(c.high+c.low+c.close)/3;s.p[l]=u,s.r1[l]=2*u-c.low,s.s1[l]=2*u-c.high,s.r2[l]=u+(c.high-c.low),s.s2[l]=u-(c.high-c.low),s.r3[l]=c.high+2*(u-c.low),s.s3[l]=c.low-2*(c.high-u);}let a=(l,c,u)=>({key:l,title:c,kind:"step",values:s[l],color:u});return {plots:[a("p","P",ue),a("r1","R1",W),a("s1","S1",z),a("r2","R2",W),a("s2","S2",z),a("r3","R3",W),a("s3","S3",z)]}}},WA={type:"52-week-high-low",title:"52 Week High/Low",shortTitle:"52W H/L",overlay:true,inputs:[{key:"weeks",title:"Weeks",type:"int",defval:52,min:1,max:520,step:1}],compute:(r,e)=>{let t=I(e,"weeks",52)*7*Pp,n=r.length,i=new Array(n).fill(Number.NaN),o=new Array(n).fill(Number.NaN),s=[],a=[],l=0;for(let c=0;c<n;c++){let u=r[c];for(;s.length>0&&r[s[s.length-1]].high<=u.high;)s.pop();for(s.push(c);a.length>0&&r[a[a.length-1]].low>=u.low;)a.pop();for(a.push(c);r[l].time<u.time-t;)l+=1;for(;s[0]<l;)s.shift();for(;a[0]<l;)a.shift();i[c]=r[s[0]].high,o[c]=r[a[0]].low;}return {plots:[{key:"high",title:"52W high",values:i,kind:"step",color:z},{key:"low",title:"52W low",values:o,kind:"step",color:W}]}}},GA={type:"zigzag",title:"ZigZag",overlay:true,inputs:[{key:"deviation",title:"Deviation %",type:"float",defval:5,min:.01,max:100,step:.1},{key:"depth",title:"Depth",type:"int",defval:10,min:1,max:500,step:1},X()],compute:(r,e)=>{let t=I(e,"deviation",5)/100,n=I(e,"depth",10),i=[];if(r.length>1){let o=r[1].close>=r[0].close,s=o?{i:0,price:r[0].high}:{i:0,price:r[0].low};for(let a=1;a<r.length;a++){let l=r[a];o?l.high>=s.price?s={i:a,price:l.high}:l.low<=s.price*(1-t)&&a-(i[i.length-1]?.i??-n)>=n&&(i.push(s),o=false,s={i:a,price:l.low}):l.low<=s.price?s={i:a,price:l.low}:l.high>=s.price*(1+t)&&a-(i[i.length-1]?.i??-n)>=n&&(i.push(s),o=true,s={i:a,price:l.high});}i.push(s);}return {plots:[],polylines:[{key:"zigzag",points:i.map(o=>({xloc:"bar_time",x:r[o.i].time,price:o.price})),curved:false,closed:false,lineColor:F(e,"color",_),lineWidth:2,lineStyle:"solid",arrowLeft:false,arrowRight:false}]}}},UA={type:"williams-fractal",title:"Williams Fractal",shortTitle:"Fractals",overlay:true,inputs:[{key:"periods",title:"Periods",type:"int",defval:2,min:1,max:50,step:1}],compute:(r,e)=>{let t=I(e,"periods",2),n=[],i=(o,s,a)=>{let l=s(r[o]);for(let c=o-t;c<=o+t;c++)if(c!==o&&!a(l,s(r[c])))return false;return true};for(let o=t;o<r.length-t;o++)i(o,s=>s.high,(s,a)=>s>=a)&&n.push({time:r[o].time,position:"aboveBar",shape:"triangleup",color:z}),i(o,s=>s.low,(s,a)=>s<=a)&&n.push({time:r[o].time,position:"belowBar",shape:"triangledown",color:W});return {plots:[],markers:n}}},s0=[HA,zA,$A,WA,GA,UA];var YA=[...Zx,...Jx,...e0,...t0,...n0,...i0,...s0];function a0(){for(let r of YA)Pn(zx(r));}var Ap=class{constructor(e,t={},n={}){Fx(),fp(),Cp(),a0();let i=KA(e),o=Qr(t.theme),s={currentPriceLine:t.currentPriceLine??true,logScale:t.logScale??false,nativeBackend:t.nativeBackend??"auto",...Wp(t.animations),glow:t.glow??0,upColor:t.upColor??z,downColor:t.downColor??W,priceStyle:t.priceStyle??"candles"},a=t.renderer??Es;if(typeof a!="function")throw new Error("[vela] options.renderer must be a renderer class, e.g. import { LwcRenderer } from 'vela/renderers/lwc'. The 'lwc'/'native' string options were removed.");let l=n.renderer??new a(s),c=n.engines??[],u=n.dataFeed??new vr,d={market:{symbol:t.symbol,timeframe:t.timeframe,bars:t.bars,session:t.session,visibleRange:t.visibleRange,data:t.data},live:t.live??false,theme:o,defaultLanguage:t.defaultLanguage??c[0]?.language??"pine",drawings:t.drawings,volume:t.volume??true};this.rendererControl=new co(l),t.settings&&this.rendererControl.setSettingsVisibility(t.settings),this.dataControl=new go(u),this.orchestrator=new tl(i,l,u,c,d,this.dataControl);let h=Hu();Object.keys(h).length>0&&this.rendererControl.set(h),this.panesControl=new nl(this.orchestrator),this.drawingsControl=new bo(this.orchestrator.drawings),this.marksControl=new vo(this.orchestrator.marks);}registerEngine(e,t){return this.orchestrator.registerEngine(e,t),this}addIndicator(e,t){return this.orchestrator.addIndicator(e,t)}addNativeIndicator(e,t){return this.orchestrator.addNativeIndicator(e,t)}availableNativeIndicators(){return this.orchestrator.availableNativeIndicators()}presentNativeIndicators(){return this.orchestrator.presentNativeIndicators()}indicators(){return this.orchestrator.listIndicators()}runScript(e,t){let n=this.addIndicator(e,t),i=new Set,o=()=>{try{n.remove();}catch{}};return new Promise(s=>{let a=false,l=this.on("script:run",u=>{if(u.id===n.id){if(a){for(let d of i)d(u);return}a=true,c(),s({ok:true,run:u,error:null,onUpdate:d=>(i.add(d),()=>i.delete(d)),remove:()=>{l(),i.clear(),o();}});}}),c=n.on("error",({error:u})=>{a||(a=true,l(),c(),o(),s({ok:false,run:null,error:u,onUpdate:()=>()=>{},remove:()=>{}}));});})}runIndicator(e,t){let n=this.addIndicator(e,t);return new Promise(i=>{let o=n.on("ready",()=>{o(),s(),i({ok:true,handle:n,error:null,context:null});}),s=n.on("error",({error:a})=>{o(),s(),n.context().catch(()=>null).then(l=>{try{n.remove();}catch{}i({ok:false,handle:null,error:a,context:l});});});})}setMarket(e){return this.orchestrator.setMarket(e)}get market(){return this.orchestrator.marketSnapshot()}ready(){return this.orchestrator.ready()}historyComplete(){return this.orchestrator.historyComplete()}inspect(){return this.orchestrator.inspect()}get renderer(){return this.rendererControl}get panes(){return this.panesControl}get data(){return this.dataControl}get drawings(){return this.drawingsControl}get marks(){return this.marksControl}on(e,t){return this.orchestrator.events.on(e,t)}getVisibleRange(){return this.orchestrator.getVisibleRange()}setVisibleRange(e){return this.orchestrator.setVisibleRange(e),this}panBy(e){return this.orchestrator.panBy(e),this}setVisibleRangePreset(e){return this.orchestrator.setVisibleRangePreset(e),this}resize(){this.orchestrator.resize();}setTheme(e){return this.orchestrator.setTheme(Qr(e)),this}destroy(){this.orchestrator.destroy();}};function KA(r){if(typeof r!="string")return r;let e=document.querySelector(r);if(!e)throw new Error(`[vela] container not found for selector "${r}"`);return e}var l0=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var zi=new Map,Ps=new Map,Is=new Map;function XA(r){return Ps.set(r.id,r),()=>{Ps.get(r.id)===r&&Ps.delete(r.id);}}function jA(r){Ps.delete(r);}function qA(){return [...Ps.values()]}var c0=100;function ZA(r){return Is.set(r.id,r),()=>{Is.get(r.id)===r&&Is.delete(r.id);}}function JA(r){Is.delete(r);}function QA(){return [...Is.values()].sort((r,e)=>(r.order??c0)-(e.order??c0))}var Rp=["indicators","screenshot"],u0=new Set(Rp),eR=new Set(l0);function tR(r){if(u0.has(r))return zi.get(r)}function nR(r){return eR.has(r.id)&&!u0.has(r.id)?(console.warn(`[vela] widget action "${r.id}": this built-in topbar slot is a stateful control and cannot be overridden \u2014 ignored. Overridable slots: ${Rp.join(", ")}.`),()=>{}):(zi.set(r.id,r),()=>{zi.get(r.id)===r&&zi.delete(r.id);})}function rR(r){zi.delete(r);}function iR(r,e){let t=[...zi.values()].filter(n=>n.target===r);return t.sort((n,i)=>(n.order??0)-(i.order??0)),e?t.filter(n=>!n.when||n.when(e)):t}var As=new Map;function oR(r){return As.set(r.id,r),()=>{As.get(r.id)===r&&As.delete(r.id);}}function sR(r){As.delete(r);}function aR(){return [...As.values()].sort((r,e)=>(r.order??0)-(e.order??0))}var Rs=new Map;function lR(r){return Rs.set(r.id,r),()=>{Rs.get(r.id)===r&&Rs.delete(r.id);}}function cR(r){Rs.delete(r);}function uR(){return [...Rs.values()].sort((r,e)=>(r.order??0)-(e.order??0))}var Ds=new Map;function dR(r){return Ds.set(r.key,r),()=>{Ds.get(r.key)===r&&Ds.delete(r.key);}}function hR(r){Ds.delete(r);}function pR(r){return [...Ds.values()].filter(e=>e.scope===r)}var bu;function mR(r){return bu=r,()=>{bu===r&&(bu=void 0);}}function fR(){return bu}var Os=new Map;function gR(r,e){return Os.set(r,e),()=>{Os.get(r)===e&&Os.delete(r);}}function bR(r){Os.delete(r);}function vR(r){return {...Object.fromEntries(Os),...r}}var d0=280,Dp=200,h0=640;function yR(r,e=Dp,t=h0){let n=Number.isFinite(e)&&e>0?e:Dp,i=Number.isFinite(t)?Math.max(t,n):Number.POSITIVE_INFINITY;return Number.isFinite(r)?Math.round(Math.min(Math.max(r,n),i)):n}function $i(r){let e=r.description?.split("/")[0]?.trim();return e?e.replace(/\s+Perpetual$/i,""):r.ticker.replace(/[-_/]?(USDT|USDC|USD1|USDS|BUSD|USD|EUR|PERP)$/i,"")||r.ticker}function Wi(r){let e=r.trim().toUpperCase();return e?`https://crypto-icons.ledger.com/${encodeURIComponent(e)}.png`:void 0}var p0="https://api.binance.com/api/v3",wR="https://api.binance.us/api/v3",Op="https://fapi.binance.com/fapi/v1",xR="wss://stream.binance.com:9443",SR="wss://stream.binance.us:9443",CR="wss://fstream.binance.com",TR=15e3,kR=2e3,m0={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",360:"6h",480:"8h",720:"12h",D:"1d",W:"1w",M:"1M"},f0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},ER=[1,3,5,15,30,60,120,240,360,480,720],LR={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",360:"6h",480:"8h",720:"12h"},MR=["1","3","5","15","30","45","60","120","180","240","D","W","M"];function g0(r){return f0[r]??f0[r.toLowerCase()]??r}function Np(r){let e=r.trim().toUpperCase();return e.endsWith(".P")?{apiSymbol:e.slice(0,-2),isFutures:true}:{apiSymbol:e,isFutures:false}}function b0(r){return r.map(e=>({time:Number(e[0]),open:Number(e[1]),high:Number(e[2]),low:Number(e[3]),close:Number(e[4]),volume:Number(e[5])}))}function PR(r){return {time:Number(r.t),open:Number(r.o),high:Number(r.h),low:Number(r.l),close:Number(r.c),volume:Number(r.v)}}function IR(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function AR(r,e){let t=new Map;for(let n of r){let i=Math.floor(n.time/e)*e,o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function RR(r){return ER.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}var vu=class{constructor(){this.spotBaseUrl=null;this.spotBaseProbe=null;this.symbolsPromise=null;}info(){return {name:"binance",displayName:"Binance",requiresApiKey:false,supportedTimeframes:MR,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let{apiSymbol:i,isFutures:o}=Np(e),s=o?Op:await this.spotBase(),a=g0(t),l=m0[a];if(l)return IR(b0(await this.fetchKlines(s,i,l,n)));let c=/^\d+$/.test(a)?parseInt(a,10):null,u=c!=null?RR(c):null;if(c==null||u==null)return console.warn(`[vela] Binance: timeframe "${t}" is not supported and cannot be aggregated.`),[];let d=c/u,h={...n,limit:n.limit!=null?n.limit*d+d:void 0},p=b0(await this.fetchKlines(s,i,LR[u],h)),m=AR(p,c*6e4);return n.limit!=null&&m.length>n.limit?m.slice(-n.limit):m}catch(i){return console.warn(`[vela] Binance: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let{apiSymbol:t,isFutures:n}=Np(e),i=n?Op:await this.spotBase(),o=n?`${i}/exchangeInfo`:`${i}/exchangeInfo?symbol=${t}`,a=(await this.json(o).catch(()=>null))?.symbols??[],l=n?a.find(d=>d.symbol===t):a[0];if(!l)return;let c=l.filters?.find(d=>d.filterType==="PRICE_FILTER"),u=c?parseFloat(c.tickSize??"0.01"):.01;return {ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",description:`${l.baseAsset} / ${l.quoteAsset}${n?" Perpetual":""}`,type:n?"futures":"crypto",basecurrency:l.baseAsset,currency:l.quoteAsset,mintick:u,pricescale:Math.round(1/u),timezone:"Etc/UTC",session:"24x7"}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=Promise.all([this.listSpot().catch(()=>[]),this.listFutures().catch(()=>[])]).then(([e,t])=>[...e,...t])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let{apiSymbol:i,isFutures:o}=Np(e),s=m0[g0(t)];return s&&typeof WebSocket<"u"?this.streamKlines(e,t,i,o,s,n):this.pollBars(e,t,n)}streamKlines(e,t,n,i,o,s){let a=false,l=null,c=null,u=null,d=null,h=`${n.toLowerCase()}@kline_${o}`,p=()=>{u&&(clearTimeout(u),u=null);},m=()=>{if(!(a||d)){p(),c&&(clearTimeout(c),c=null);try{l?.close();}catch{}l=null,console.warn(`[vela] Binance: ${e} ${t} stream delivered no data; falling back to polling.`),d=this.pollBars(e,t,s);}},f=async()=>{if(a)return;let g=i?CR:await this.spotWsBase();a||(l=new WebSocket(`${g}/ws/${h}`),u=setTimeout(m,TR),l.onmessage=b=>{if(!(a||d))try{let y=JSON.parse(typeof b.data=="string"?b.data:"");y.k&&(p(),s(PR(y.k)));}catch{}},l.onclose=()=>{!a&&!d&&(c=setTimeout(()=>{f();},kR));},l.onerror=()=>{try{l?.close();}catch{}});};return f(),()=>{a=true,p(),c&&clearTimeout(c),d?.();try{l?.close();}catch{}}}async spotWsBase(){return (await this.spotBase()).includes("binance.us")?SR:xR}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}async listSpot(){let e=await this.spotBase();return ((await this.json(`${e}/exchangeInfo`)).symbols??[]).filter(n=>n.status==="TRADING").map(n=>({ticker:n.symbol,description:`${n.baseAsset} / ${n.quoteAsset}`,type:"crypto"}))}async listFutures(){return ((await this.json(`${Op}/exchangeInfo`)).symbols??[]).filter(t=>t.contractType==="PERPETUAL"&&t.status==="TRADING").map(t=>({ticker:`${t.symbol}.P`,description:`${t.baseAsset} / ${t.quoteAsset} Perpetual`,type:"futures"}))}async fetchKlines(e,t,n,i){if(i.from!=null)return this.paginateForward(e,t,n,i.from,i.to??Date.now(),i.limit);let o=i.limit??500;return o>1e3?this.paginateBackward(e,t,n,o,i.to):this.klinesChunk(e,{symbol:t,interval:n,limit:o,endTime:i.to})}async paginateForward(e,t,n,i,o,s){let a=[],l=i;for(;l<o;){let c=await this.klinesChunk(e,{symbol:t,interval:n,limit:1e3,startTime:l,endTime:o});if(c.length===0||(a.push(...c),l=Number(c[c.length-1][6])+1,c.length<1e3)||s&&a.length>=s)break}return s?a.slice(0,s):a}async paginateBackward(e,t,n,i,o){let s=[],a=i,l=o,c=Math.ceil(i/1e3)+5;for(;a>0&&c-- >0;){let u=Math.min(a,1e3),d=await this.klinesChunk(e,{symbol:t,interval:n,limit:u,endTime:l});if(d.length===0||(s=d.concat(s),a-=d.length,l=Number(d[0][0])-1,d.length<u))break}return s}async klinesChunk(e,t){let n=new URL(`${e}/klines`);n.searchParams.set("symbol",t.symbol),n.searchParams.set("interval",t.interval),t.limit&&n.searchParams.set("limit",String(Math.min(t.limit,1e3))),t.startTime!=null&&n.searchParams.set("startTime",String(t.startTime)),t.endTime!=null&&n.searchParams.set("endTime",String(t.endTime));let i=await this.json(n.toString());return Array.isArray(i)?i.length>0&&!Array.isArray(i[0])?[]:i:[]}spotBase(){return this.spotBaseUrl?Promise.resolve(this.spotBaseUrl):(this.spotBaseProbe||(this.spotBaseProbe=(async()=>{try{for(let e of [p0,wR])try{if((await fetch(`${e}/ping`,{signal:AbortSignal.timeout(5e3)})).ok)return this.spotBaseUrl=e}catch{}return p0}finally{this.spotBaseProbe=null;}})()),this.spotBaseProbe)}async json(e){let t=await fetch(e);if(!t.ok)throw new Error(`Binance HTTP ${t.status} for ${e}`);return t.json()}};var DR="https://api.hyperliquid.xyz/info",OR="wss://api.hyperliquid.xyz/ws",NR=15e3,FR=2e3,v0={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h",D:"1d",W:"1w",M:"1M"},y0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},VR=[1,3,5,15,30,60,120,240,480,720],_R={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h"},BR=["1","3","5","15","30","45","60","120","180","240","360","480","720","D","W","M"],w0={D:864e5,W:6048e5,M:2592e6};function HR(r){if(w0[r])return w0[r];let e=parseInt(r,10);return Number.isFinite(e)&&e>0?e*6e4:36e5}function x0(r){return y0[r]??y0[r.toLowerCase()]??r}function Fp(r){let e=r.trim();return e.includes("/")?e:e.toUpperCase()}function Vp(r){return {time:Number(r.t),open:Number(r.o),high:Number(r.h),low:Number(r.l),close:Number(r.c),volume:Number(r.v)}}function zR(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function $R(r,e){let t=new Map;for(let n of r){let i=Math.floor(n.time/e)*e,o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function WR(r){return VR.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}var yu=class{constructor(){this.metaPromise=null;this.spotMetaPromise=null;this.symbolsPromise=null;}info(){return {name:"hyperliquid",displayName:"Hyperliquid",requiresApiKey:false,supportedTimeframes:BR,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let i=Fp(e),o=x0(t),s=v0[o];if(s)return zR((await this.fetchCandles(i,s,HR(o),n)).map(Vp));let a=/^\d+$/.test(o)?parseInt(o,10):null,l=a!=null?WR(a):null;if(a==null||l==null)return console.warn(`[vela] Hyperliquid: timeframe "${t}" is not supported and cannot be aggregated.`),[];let c=a/l,u={...n,limit:n.limit!=null?n.limit*c+c:void 0},d=(await this.fetchCandles(i,_R[l],l*6e4,u)).map(Vp),h=$R(d,a*6e4);return n.limit!=null&&h.length>n.limit?h.slice(-n.limit):h}catch(i){return console.warn(`[vela] Hyperliquid: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let t=Fp(e),i=(await this.fetchMeta().catch(()=>null))?.universe?.find(o=>o.name===t);if(i){let o=C0(Math.max(0,6-(i.szDecimals??2)));return S0(e,t,"USD","futures",`${t} / USD Perpetual`,o)}if(t.includes("/")){let o=await this.fetchSpotMeta().catch(()=>null),s=o?.universe?.find(d=>d.name===t),a=s&&o?.tokens?o.tokens[s.tokens?.[0]??-1]:void 0,[l=t,c="USDC"]=t.split("/"),u=C0(Math.max(0,8-(a?.szDecimals??2)));return S0(e,l,c,"crypto",`${l} / ${c}`,u)}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=Promise.all([this.listPerps().catch(()=>[]),this.listSpot().catch(()=>[])]).then(([e,t])=>[...e,...t])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let i=Fp(e),o=v0[x0(t)];return o&&typeof WebSocket<"u"?this.streamCandles(e,t,i,o,n):this.pollBars(e,t,n)}async listPerps(){return ((await this.fetchMeta()).universe??[]).filter(t=>!t.isDelisted).map(t=>({ticker:t.name,description:`${t.name} / USD Perpetual`,type:"futures"}))}async listSpot(){let e=await this.fetchSpotMeta(),t=e.tokens??[],n=i=>i!=null?t[i]?.name??null:null;return (e.universe??[]).map(i=>{let o=n(i.tokens?.[0]),s=n(i.tokens?.[1]),a=o&&s?`${o} / ${s}`:i.name;return {ticker:i.name,description:a,type:"crypto"}})}async fetchCandles(e,t,n,i){let o=i.to??Date.now(),s=i.from!=null?i.from:o-((i.limit??500)+2)*n,a=await this.candleSnapshot(e,t,s,o);return i.from==null&&i.limit!=null&&a.length>i.limit?a.slice(-i.limit):a}async candleSnapshot(e,t,n,i){let o=await this.post({type:"candleSnapshot",req:{coin:e,interval:t,startTime:Math.floor(n),endTime:Math.floor(i)}});return Array.isArray(o)?o:[]}streamCandles(e,t,n,i,o){let s=false,a=null,l=null,c=null,u=null,d=null,h=()=>{u&&(clearTimeout(u),u=null);},p=()=>{l&&(clearInterval(l),l=null);},m=()=>{if(!(s||d)){h(),p(),c&&(clearTimeout(c),c=null);try{a?.close();}catch{}a=null,console.warn(`[vela] Hyperliquid: ${e} ${t} stream delivered no data; falling back to polling.`),d=this.pollBars(e,t,o);}},f=()=>{s||d||(a=new WebSocket(OR),u=setTimeout(m,NR),a.onopen=()=>{try{a?.send(JSON.stringify({method:"subscribe",subscription:{type:"candle",coin:n,interval:i}}));}catch{}l=setInterval(()=>{try{a?.send(JSON.stringify({method:"ping"}));}catch{}},3e4);},a.onmessage=g=>{if(!(s||d))try{let b=JSON.parse(typeof g.data=="string"?g.data:"");b.channel==="candle"&&b.data&&b.data.s===n&&(h(),o(Vp(b.data)));}catch{}},a.onclose=()=>{p(),!s&&!d&&(c=setTimeout(f,FR));},a.onerror=()=>{try{a?.close();}catch{}});};return f(),()=>{s=true,h(),p(),c&&clearTimeout(c),d?.();try{a?.close();}catch{}}}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}fetchMeta(){return this.metaPromise??(this.metaPromise=this.post({type:"meta"}).then(e=>e))}fetchSpotMeta(){return this.spotMetaPromise??(this.spotMetaPromise=this.post({type:"spotMeta"}).then(e=>e))}async post(e){let t=await fetch(DR,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Hyperliquid HTTP ${t.status}`);return t.json()}};function S0(r,e,t,n,i,o){return {ticker:r,tickerid:`HYPERLIQUID:${r}`,prefix:"HYPERLIQUID",description:i,type:n,basecurrency:e,currency:t,mintick:o,pricescale:Math.round(1/o),timezone:"Etc/UTC",session:"24x7"}}function C0(r){return Math.pow(10,-r)}var GR={now:()=>Date.now(),delay:r=>new Promise(e=>setTimeout(e,r))},wu=class{constructor(e,t,n=GR){this.maxConcurrent=e;this.minIntervalMs=t;this.clock=n;this.active=0;this.waiters=[];this.nextStartAt=0;this.pausedUntil=0;}async run(e){await this.acquire();try{return await this.waitForTurn(),await e()}finally{this.release();}}pauseFor(e){e>0&&(this.pausedUntil=Math.max(this.pausedUntil,this.clock.now()+e));}async waitForTurn(){for(;;){let e=this.clock.now(),t=Math.max(this.pausedUntil-e,this.nextStartAt-e);if(t<=0)break;await this.clock.delay(t);}this.nextStartAt=Math.max(this.clock.now(),this.nextStartAt)+this.minIntervalMs;}acquire(){return this.active<this.maxConcurrent?(this.active+=1,Promise.resolve()):new Promise(e=>{this.waiters.push(()=>{this.active+=1,e();});})}release(){this.active-=1;let e=this.waiters.shift();e&&e();}};var _p="https://api.exchange.coinbase.com",UR="wss://ws-feed.exchange.coinbase.com",YR={Accept:"application/json"},KR=15e3,XR=2e3,jR=5e3,xu=300,qR=4,ZR=120,JR=4,QR=600,e2=400;function t2(r,e){let t=Number(r.headers.get("retry-after"));return Number.isFinite(t)&&t>0?t*1e3:e}var T0={1:60,5:300,15:900,60:3600,360:21600,D:86400},k0={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},n2=[1,5,15,60,360,1440],r2={1:60,5:300,15:900,60:3600,360:21600,1440:86400},i2=["1","3","5","15","30","45","60","120","180","240","360","480","720","D","W","M"],Bp=864e5;function E0(r){return k0[r]??k0[r.toLowerCase()]??r}function Hp(r){return r.trim().toUpperCase()}function o2(r){return {time:Number(r[0])*1e3,open:Number(r[3]),high:Number(r[2]),low:Number(r[1]),close:Number(r[4]),volume:Number(r[5])}}function zp(r){let e=new Map;for(let t of r)e.set(t.time,t);return [...e.values()].sort((t,n)=>t.time-n.time)}function s2(r,e){return L0(r,t=>Math.floor(t/e)*e)}function a2(r,e){return L0(r,e==="W"?l2:c2)}function L0(r,e){let t=new Map;for(let n of r){let i=e(n.time),o=t.get(i);o?(o.high=Math.max(o.high,n.high),o.low=Math.min(o.low,n.low),o.close=n.close,o.volume=(o.volume??0)+(n.volume??0)):t.set(i,{time:i,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume??0});}return [...t.values()].sort((n,i)=>n.time-i.time)}function l2(r){let e=new Date(r),t=(e.getUTCDay()+6)%7;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()-t)}function c2(r){let e=new Date(r);return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),1)}function u2(r){return n2.filter(e=>e<r&&r%e===0).sort((e,t)=>t-e)[0]??null}function $p(r,e){return e!=null&&r.length>e?r.slice(-e):r}var Su=class{constructor(){this.symbolsPromise=null;this.gate=new wu(qR,ZR);}info(){return {name:"coinbase",displayName:"Coinbase",requiresApiKey:false,supportedTimeframes:i2,capabilities:{enumerate:true,stream:true,symbolInfo:true}}}async getBars(e,t,n){try{let i=Hp(e),o=E0(t),s=T0[o];if(s)return zp(await this.fetchCandles(i,s,n));if(o==="W"||o==="M"){let h=o==="W"?7*Bp:31*Bp,p=n.from!=null?n:{...n,limit:n.limit!=null?Math.ceil(n.limit*h/Bp)+31:void 0},m=await this.fetchCandles(i,86400,p);return $p(a2(m,o),n.limit)}let a=/^\d+$/.test(o)?parseInt(o,10):null,l=a!=null?u2(a):null;if(a==null||l==null)return console.warn(`[vela] Coinbase: timeframe "${t}" is not supported and cannot be aggregated.`),[];let c=a/l,u={...n,limit:n.limit!=null?n.limit*c+c:void 0},d=await this.fetchCandles(i,r2[l],u);return $p(s2(d,a*6e4),n.limit)}catch(i){return console.warn(`[vela] Coinbase: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let t=Hp(e),n=await this.json(`${_p}/products/${t}`).catch(()=>null);if(!n||!n.id)return;let i=n.quote_increment!=null?parseFloat(n.quote_increment):.01,o=i>0?i:.01;return {ticker:e,tickerid:`COINBASE:${e}`,prefix:"COINBASE",description:`${n.base_currency} / ${n.quote_currency}`,type:"crypto",basecurrency:n.base_currency,currency:n.quote_currency,mintick:o,pricescale:Math.round(1/o),timezone:"Etc/UTC",session:"24x7"}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=this.fetchProducts().then(e=>e.filter(t=>t.status==="online"&&!t.trading_disabled).map(t=>({ticker:t.id,description:`${t.base_currency} / ${t.quote_currency}`,type:"crypto"}))).catch(()=>[])),this.symbolsPromise}resolveSymbolIcon(e){return Wi($i(e))}subscribe(e,t,n){let i=T0[E0(t)];return i&&typeof WebSocket<"u"?this.streamTicker(e,t,i,n):this.pollBars(e,t,n)}async fetchProducts(){let e=await this.json(`${_p}/products`);return Array.isArray(e)?e:[]}async fetchCandles(e,t,n){return n.from!=null?this.paginateForward(e,t,n.from,n.to??Date.now(),n.limit):this.paginateBackward(e,t,n.limit??500,n.to??Date.now())}async paginateBackward(e,t,n,i){let o=t*1e3,s=[],a=n,l=i,c=Math.ceil(n/xu)+4;for(;a>0&&c-- >0;){let u=Math.min(a,xu),d=l-u*o,h=await this.candlesChunk(e,t,d,l);if(h.length===0||(s=h.concat(s),a-=h.length,l=h[0].time-1,h.length<u))break}return $p(zp(s),n)}async paginateForward(e,t,n,i,o){let s=t*1e3,a=[],l=n,c=Math.ceil((i-n)/(xu*s))+4;for(;l<i&&c-- >0;){let d=Math.min(l+xu*s,i),h=await this.candlesChunk(e,t,l,d);if(h.length>0&&a.push(...h),l=d,o!=null&&a.length>=o)break}let u=zp(a);return o!=null?u.slice(0,o):u}async candlesChunk(e,t,n,i){let o=new URL(`${_p}/products/${e}/candles`);o.searchParams.set("granularity",String(t)),o.searchParams.set("start",String(Math.floor(n/1e3))),o.searchParams.set("end",String(Math.floor(i/1e3)));let s=await this.json(o.toString());return !Array.isArray(s)||s.length>0&&!Array.isArray(s[0])?[]:s.map(o2).sort((a,l)=>a.time-l.time)}streamTicker(e,t,n,i){let o=Hp(e),s=n*1e3,a=T=>Math.floor(T/s)*s,l=false,c=null,u=null,d=null,h=null,p=null,m=null,f=()=>{d&&(clearTimeout(d),d=null);},g=()=>{h&&(clearInterval(h),h=null);},b=()=>{m&&i({...m});},y=async T=>{try{let k=await this.getBars(e,t,{limit:2});if(l||k.length===0)return;T&&k.length>=2&&i(k[k.length-2]);let x=k[k.length-1];m=m&&m.time===x.time?{...x,high:Math.max(x.high,m.high),low:Math.min(x.low,m.low),close:m.close}:{...x},b();}catch{}},v=(T,k)=>{let x=Number(T);if(!Number.isFinite(x))return;let L=a(k);!m||L>m.time?(m={time:L,open:x,high:x,low:x,close:x,volume:0},b(),y(false)):L===m.time&&(m={...m,close:x,high:Math.max(m.high,x),low:Math.min(m.low,x)},b());},S=()=>{if(!(l||p)){f(),g(),u&&(clearTimeout(u),u=null);try{c?.close();}catch{}c=null,console.warn(`[vela] Coinbase: ${e} ${t} stream delivered no data; falling back to polling.`),p=this.pollBars(e,t,i);}},E=()=>{l||p||(c=new WebSocket(UR),d=setTimeout(S,KR),c.onopen=()=>{try{c?.send(JSON.stringify({type:"subscribe",product_ids:[o],channels:["ticker"]}));}catch{}y(false),h=setInterval(()=>{y(false);},jR);},c.onmessage=T=>{if(!(l||p))try{let k=JSON.parse(typeof T.data=="string"?T.data:"");k.type==="ticker"&&k.product_id===o&&k.price!=null&&(f(),v(k.price,k.time?Date.parse(k.time):Date.now()));}catch{}},c.onclose=()=>{g(),!l&&!p&&(u=setTimeout(E,XR));},c.onerror=()=>{try{c?.close();}catch{}});};return E(),()=>{l=true,f(),g(),u&&clearTimeout(u),p?.();try{c?.close();}catch{}}}pollBars(e,t,n){let i=false,o=null,s=async()=>{if(!i){try{let a=await this.getBars(e,t,{limit:2});for(let l of a)n(l);}catch{}i||(o=setTimeout(()=>{s();},3e3));}};return o=setTimeout(()=>{s();},3e3),()=>{i=true,o&&clearTimeout(o);}}async json(e){return (await this.request(e)).json()}async request(e){for(let t=0;;t+=1){let n=await this.gate.run(()=>fetch(e,{headers:YR}));if(n.status===429&&t<JR){let i=QR*2**t+Math.random()*e2;this.gate.pauseFor(Math.max(t2(n,0),i));continue}if(!n.ok)throw new Error(`Coinbase HTTP ${n.status} for ${e}`);return n}}};
1032
1032
  exports.ACCENT=Ke;exports.ACCENT_BRIGHT=$r;exports.BEARISH=W;exports.BULLISH=z;exports.BarStore=rl;exports.BinanceProvider=vu;exports.CATEGORICAL=Bs;exports.CHIP_PLATE=em;exports.CROSSHAIR=Zp;exports.CachingDataFeed=mo;exports.CoinbaseProvider=Su;exports.DARK_THEME=Yt;exports.DEFAULT_PANEL_MAX_WIDTH=h0;exports.DEFAULT_PANEL_MIN_WIDTH=Dp;exports.DEFAULT_PANEL_WIDTH=d0;exports.DataControl=go;exports.Drawing=G;exports.DrawingStore=qr;exports.DrawingToolbar=Ts;exports.DrawingsControl=bo;exports.HIGHLIGHT=jp;exports.HyperliquidProvider=yu;exports.INFO=Je;exports.INVALID=zs;exports.LIGHT_THEME=lo;exports.MARKER=qp;exports.MarksControl=vo;exports.MultiProviderFeed=vr;exports.NEUTRAL=J;exports.NativeRenderer=Es;exports.OVERRIDABLE_TOPBAR_IDS=Rp;exports.RendererControl=co;exports.SERIES_LINE=_;exports.SESSION_OFF=C2;exports.SESSION_POST=S2;exports.SESSION_PRE=x2;exports.SLATE=Qp;exports.SLATE_DEEP=Jp;exports.SecondClock=yo;exports.TRADE_EXIT=rm;exports.TRADE_LONG=tm;exports.TRADE_SHORT=nm;exports.TypedEventBus=er;exports.VALID=Hs;exports.Vela=Ap;exports.WARNING=ue;exports.buildColorPicker=Qo;exports.buildToolbar=io;exports.categoricalColor=T2;exports.chartType=pn;exports.chartTypes=Mt;exports.clampPanelWidth=yR;exports.combineColor=ec;exports.createDrawing=On;exports.defaultToolbar=ro;exports.deserializeDrawing=pt;exports.drawingTypes=Xa;exports.getDrawingType=Et;exports.getNativeIndicator=Ui;exports.iconMarkup=Wr;exports.inputDeltas=rv;exports.inputVisible=Xo;exports.legendActions=aR;exports.legendCallouts=uR;exports.nativeIndicatorDescriptors=Vs;exports.nativeIndicatorTypes=Yp;exports.normalizeSettingsRow=Zr;exports.registerChartType=_u;exports.registerDefaultEngine=gR;exports.registerDrawingType=V;exports.registerIcon=N;exports.registerLegendAction=oR;exports.registerLegendCallout=lR;exports.registerNativeIndicator=Pn;exports.registerRendererDefaults=x1;exports.registerRendererLayer=YP;exports.registerSidePanel=ZA;exports.registerStatePersistence=dR;exports.registerSymbolRanking=mR;exports.registerWidgetAction=nR;exports.registerWidgetAttachment=XA;exports.rendererDefaults=Hu;exports.rendererLayers=tp;exports.resolveEngines=vR;exports.resolveTheme=Qr;exports.seriesInScale=Ns;exports.seriesShownOn=Ct;exports.settingsRowValueKeys=so;exports.sharedBarStore=uo;exports.sidePanels=QA;exports.splitColor=Gn;exports.stableSeriesId=Jn;exports.statePersistenceHandlers=pR;exports.symbolRanking=fR;exports.tickerModifierIds=Bu;exports.timeframeToMs=Lt;exports.topbarActionOverride=tR;exports.unregisterChartType=d1;exports.unregisterDefaultEngine=bR;exports.unregisterLegendAction=sR;exports.unregisterLegendCallout=cR;exports.unregisterNativeIndicator=Up;exports.unregisterRendererDefaults=S1;exports.unregisterRendererLayer=KP;exports.unregisterSidePanel=JA;exports.unregisterStatePersistence=hR;exports.unregisterWidgetAction=rR;exports.unregisterWidgetAttachment=jA;exports.widgetActions=iR;exports.widgetAttachments=qA;return exports;})({});