pine2profit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +243 -2
  2. package/build/.gitkeep +0 -0
  3. package/build/index.cjs +1152 -0
  4. package/build/index.mjs +1142 -0
  5. package/build/modules/frontend/build/.nojekyll +0 -0
  6. package/build/modules/frontend/build/404/index.html +1 -0
  7. package/build/modules/frontend/build/404.html +1 -0
  8. package/build/modules/frontend/build/_next/static/chunks/11.78c5bec5897e1148.js +1 -0
  9. package/build/modules/frontend/build/_next/static/chunks/195.64632be71175c993.js +63 -0
  10. package/build/modules/frontend/build/_next/static/chunks/204.008bcbcf48844ee2.js +1 -0
  11. package/build/modules/frontend/build/_next/static/chunks/255-da04dc9178303a31.js +1 -0
  12. package/build/modules/frontend/build/_next/static/chunks/2738385b.306f7750ad5b8be4.js +372 -0
  13. package/build/modules/frontend/build/_next/static/chunks/338-31711140cb6d61e5.js +1 -0
  14. package/build/modules/frontend/build/_next/static/chunks/4bd1b696-c023c6e3521b1417.js +1 -0
  15. package/build/modules/frontend/build/_next/static/chunks/50e49f97.75feacc2b3cc7709.js +433 -0
  16. package/build/modules/frontend/build/_next/static/chunks/554.dd4ac9a0aff9b782.js +1 -0
  17. package/build/modules/frontend/build/_next/static/chunks/570-33c81efca66c4bc9.js +3 -0
  18. package/build/modules/frontend/build/_next/static/chunks/5957d0c3.7b96612772854e2d.js +2 -0
  19. package/build/modules/frontend/build/_next/static/chunks/619-f09bc47e24909021.js +1 -0
  20. package/build/modules/frontend/build/_next/static/chunks/7589b812.60f2b16513f3aa42.js +1 -0
  21. package/build/modules/frontend/build/_next/static/chunks/771.5c62ba94f930669e.js +1 -0
  22. package/build/modules/frontend/build/_next/static/chunks/796.4b04b2b64c066b03.js +1 -0
  23. package/build/modules/frontend/build/_next/static/chunks/897-b727cc7229802490.js +1 -0
  24. package/build/modules/frontend/build/_next/static/chunks/app/_not-found/page-b6d9300903c2ab41.js +1 -0
  25. package/build/modules/frontend/build/_next/static/chunks/app/layout-0da8bd54f47c9e1b.js +1 -0
  26. package/build/modules/frontend/build/_next/static/chunks/app/page-7ab911a70ef48cfe.js +1 -0
  27. package/build/modules/frontend/build/_next/static/chunks/app/run/page-42836fc705c46a59.js +1 -0
  28. package/build/modules/frontend/build/_next/static/chunks/c525c9ef.018edb9552a70fc2.js +143 -0
  29. package/build/modules/frontend/build/_next/static/chunks/e1865c21-8d63eb0f5b25cb0c.js +1 -0
  30. package/build/modules/frontend/build/_next/static/chunks/framework-28b60818f5cffd83.js +1 -0
  31. package/build/modules/frontend/build/_next/static/chunks/main-45ecedd1f28e3a74.js +1 -0
  32. package/build/modules/frontend/build/_next/static/chunks/main-app-4ff0bbe1b367fcb5.js +1 -0
  33. package/build/modules/frontend/build/_next/static/chunks/pages/_app-7d307437aca18ad4.js +1 -0
  34. package/build/modules/frontend/build/_next/static/chunks/pages/_error-cb2a52f75f2162e2.js +1 -0
  35. package/build/modules/frontend/build/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  36. package/build/modules/frontend/build/_next/static/chunks/webpack-bb5ccf34ea47f1d7.js +1 -0
  37. package/build/modules/frontend/build/_next/static/css/91363587ff8467b5.css +1 -0
  38. package/build/modules/frontend/build/_next/static/media/29b98dbfba401fa9-s.p.woff2 +0 -0
  39. package/build/modules/frontend/build/_next/static/media/313510e2713fb214-s.p.woff2 +0 -0
  40. package/build/modules/frontend/build/_next/static/media/558ca1a6aa3cb55e-s.p.woff2 +0 -0
  41. package/build/modules/frontend/build/_next/static/media/64d784ea54a4acde-s.woff2 +0 -0
  42. package/build/modules/frontend/build/_next/static/media/6d831b18ae5b01dc-s.woff2 +0 -0
  43. package/build/modules/frontend/build/_next/static/media/8048a25e80cc4179-s.woff2 +0 -0
  44. package/build/modules/frontend/build/_next/static/media/851c4691abdf3def-s.woff2 +0 -0
  45. package/build/modules/frontend/build/_next/static/media/87bc17f7c8b98e48-s.woff2 +0 -0
  46. package/build/modules/frontend/build/_next/static/media/982ceffe7b733b3b-s.p.woff2 +0 -0
  47. package/build/modules/frontend/build/_next/static/media/a6c19694cd327cd4-s.woff2 +0 -0
  48. package/build/modules/frontend/build/_next/static/media/a8a8dd7277bab4cf-s.woff2 +0 -0
  49. package/build/modules/frontend/build/_next/static/media/ac0e76ddaeeb7981-s.woff2 +0 -0
  50. package/build/modules/frontend/build/_next/static/media/b8bfb68ab9ab617c-s.woff2 +0 -0
  51. package/build/modules/frontend/build/_next/static/media/d76fe899475ae4d7-s.woff2 +0 -0
  52. package/build/modules/frontend/build/_next/static/media/e546cf32c9d4702c-s.woff2 +0 -0
  53. package/build/modules/frontend/build/_next/static/media/edc640959b0c7826-s.woff2 +0 -0
  54. package/build/modules/frontend/build/_next/static/media/ff71da380fbe67dd-s.woff2 +0 -0
  55. package/build/modules/frontend/build/_next/static/vHsenj52Jy0T31oXW8dJX/_buildManifest.js +1 -0
  56. package/build/modules/frontend/build/_next/static/vHsenj52Jy0T31oXW8dJX/_ssgManifest.js +1 -0
  57. package/build/modules/frontend/build/icon.svg +1 -0
  58. package/build/modules/frontend/build/index.html +1 -0
  59. package/build/modules/frontend/build/index.txt +23 -0
  60. package/build/modules/frontend/build/run/index.html +1 -0
  61. package/build/modules/frontend/build/run/index.txt +23 -0
  62. package/package.json +93 -4
  63. package/types.d.ts +124 -0
@@ -0,0 +1,372 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[819],{5854:(e,t,i)=>{i.d(t,{$S:()=>j,Bq:()=>eS,FN:()=>Z,HO:()=>dE,IK:()=>$,IU:()=>ey,RN:()=>ev,Rz:()=>X,TR:()=>eM,YE:()=>z,bf:()=>U,cm:()=>ef,dA:()=>W,dK:()=>eT,dL:()=>es,e1:()=>el,eW:()=>K,g7:()=>eU,i5:()=>_,n0:()=>H,rP:()=>N,vZ:()=>E,xg:()=>nm,z6:()=>ew});var o=i(8592),r=i(3678),l=i(4897),n=i(7040),a=i(7062),s=i(187),h=i(6262),d=i(542),c=i(6806),p=i(1689),u=i(7660),g=i(9171),m=i(1471),b=i(8621),f=i(3825),v=i(7657),y=i(479),w=i(1381),C=i(8161),x=i(9508),k=i(2271),S=i(1849),T=i(9748),M=i(9138),L=i(5788),A=i(9900),P=i(1953),I=i(4209),E=class{constructor(){this.handlers=new Map}on(e,t){let i=this.handlers.get(e);i||(i=new Set,this.handlers.set(e,i));let o=i;return o.add(t),()=>{o.delete(t)}}off(e,t){this.handlers.get(e)?.delete(t)}hasListeners(e){return(this.handlers.get(e)?.size??0)>0}emit(e,t){let i=this.handlers.get(e);if(i)for(let o of i)try{o(t)}catch(t){console.error(`[vela] event handler error for "${String(e)}"`,t)}}clear(){this.handlers.clear()}},B=[{id:"lines-channels-pitchforks",label:(0,n.ab)("drawing.toolbar.group.linesChannelsPitchforks","Lines"),sections:[{label:(0,n.ab)("drawing.toolbar.section.lines","Lines"),registryGroup:"lines"},{label:(0,n.ab)("drawing.toolbar.section.channels","Channels"),registryGroup:"channels"},{label:(0,n.ab)("drawing.toolbar.section.pitchforks","Pitchforks"),registryGroup:"pitchforks"}]},{id:"fibonacci-gann",label:(0,n.ab)("drawing.toolbar.group.fibonacciGann","Fibonacci"),sections:[{label:(0,n.ab)("drawing.toolbar.section.fibonacci","Fibonacci"),types:["fibretracement","fibextension","fibextensiontrend","fibfan","fibtimezones","fibchannel","fibspeedfan","trendfibtime","fibcircles","fibarcs","fibwedge","fibspiral"]},{label:(0,n.ab)("drawing.toolbar.section.priceAction","Price Action"),types:["fairvaluegap","orderblock","liquidity"]},{label:(0,n.ab)("drawing.toolbar.section.gann","Gann"),types:["gannfan","gannbox","gannsquare"]},{label:(0,n.ab)("drawing.toolbar.section.geometry","Geometry"),types:["dedekind","sonic","supersonic","goldensonic","goldensupersonic"]}]},{id:"patterns-waves-harmonics",label:(0,n.ab)("drawing.toolbar.group.patternsWavesHarmonics","Patterns"),sections:[{label:(0,n.ab)("drawing.toolbar.section.patterns","Patterns"),types:["xabcd","abcd","headshoulders"]},{label:(0,n.ab)("drawing.toolbar.section.elliottWaves","Elliott Waves"),types:["elliottimpulse","elliottcorrection"]},{label:(0,n.ab)("drawing.toolbar.section.harmonics","Harmonics"),types:["gartley","bat","butterfly","crab","shark","cypher"]}]},{id:"measurements",label:(0,n.ab)("drawing.toolbar.group.measurements","Measurements"),sections:[{label:(0,n.ab)("drawing.toolbar.section.measurements","Measurements"),types:["position","datepricerange","magnifier"]},{label:(0,n.ab)("drawing.toolbar.section.volume","Volume"),types:["anchoredvwap","fixedrangevp"]}]},{id:"brushes-arrows-shapes",label:(0,n.ab)("drawing.toolbar.group.brushesArrowsShapes","Shapes"),sections:[{label:(0,n.ab)("drawing.toolbar.section.brushes","Brushes"),types:["freehand","highlighter"]},{label:(0,n.ab)("drawing.toolbar.section.arrows","Arrows"),types:["arrow","arrowmarkup","arrowmarkdown"]},{label:(0,n.ab)("drawing.toolbar.section.shapes","Shapes"),types:["box","ellipse","triangle","polyline","circle","rotatedrect","path","arc","curve"]}]},{id:"text",label:(0,n.ab)("drawing.toolbar.group.text","Text"),sections:[{label:(0,n.ab)("drawing.toolbar.section.text","Text"),types:["text","callout","note","pricenote","comment","pricelabel","signpost"]}]},{id:"icons",label:(0,n.ab)("drawing.toolbar.group.icons","Icons"),sections:[{label:(0,n.ab)("drawing.toolbar.section.icons","Icons"),types:["flagmark","iconstamp"]}]}];function F(e){let t=(0,o.JDD)(e);return t?{type:t.type,label:t.label,icon:t.icon}:null}function O(e){let t=function(e){let t=new Map;for(let i of(0,o.Dge)()){if(e&&!e.has(i.type))continue;let o={type:i.type,label:i.label,icon:i.icon};t.has(i.group)||t.set(i.group,[]),t.get(i.group).push(o)}return t}(e),i=new Map;for(let e of t.values())for(let t of e)i.set(t.type,t);let r=[];for(let e of B){let o=[],l=[];for(let r of e.sections){let e=function(e,t,i){return"registryGroup"in e?t.get(e.registryGroup)??[]:e.types.map(e=>i.get(e)).filter(e=>null!=e)}(r,t,i);0!==e.length&&(o.push({label:r.label,tools:e}),l.push(...e))}0!==l.length&&r.push({id:e.id,label:e.label,tools:l,sections:o.length>0?o:void 0})}return{groups:r}}function R(e,t){let i=new Map,o=e=>{let o=i.get(e);return o||(o={type:e.type,label:(0,n.b6)(t,e.label),icon:e.icon},i.set(e,o)),o};return{groups:e.groups.map(e=>({id:e.id,label:(0,n.b6)(t,e.label),tools:e.tools.map(o),sections:e.sections?.map(e=>({label:(0,n.b6)(t,e.label),tools:e.tools.map(o)}))}))}}function N(e){return R(O(),e)}function z(e,t){let{definition:i,visible:r}=function(e){if(!1===e)return{definition:O(),visible:!1};if(void 0===e||!0===e)return{definition:O(),visible:!0};let t=e.toolbar??!0;return e.groups?{definition:function(e){let t=[];for(let i of e){let e=i.tools.map(F).filter(e=>null!=e);e.length>0&&t.push({id:i.id,label:i.label,tools:e})}return{groups:t}}(e.groups),visible:t}:e.tools?{definition:function(e){let t=new Set;for(let i of e)(0,o.JDD)(i)&&t.add(i);return O(t)}(e.tools),visible:t}:{definition:O(),visible:t}}(e);return{definition:R(i,t),visible:r}}function V(e){let t=globalThis.structuredClone;return t?t(e):JSON.parse(JSON.stringify(e))}function D(e){return!!e&&"object"==typeof e&&"string"==typeof e.id&&"string"==typeof e.type&&"string"==typeof e.paneId&&Array.isArray(e.anchors)&&e.anchors.every(e=>e&&"number"==typeof e.time&&"number"==typeof e.price)&&!!e.style&&"object"==typeof e.style}var $=class{constructor(){this.byId=new Map,this.seq=0,this.zCounter=1,this.listeners=new Set}nextId(){return this.seq+=1,`dw-${this.seq}`}add(e){return e.zIndex||(e.zIndex=this.zCounter),this.zCounter=Math.max(this.zCounter,Math.ceil(e.zIndex))+1,this.byId.set(e.id,e),this.emit(),e}remove(e){let t=this.byId.delete(e);return t&&this.emit(),t}get(e){return this.byId.get(e)}has(e){return this.byId.has(e)}update(e,t){let i=this.byId.get(e);return i?(t.anchors&&(i.anchors=t.anchors.map(e=>({time:e.time,price:e.price}))),t.style&&(i.style={...t.style}),void 0!==t.text&&(i.text=t.text?{...t.text}:void 0),void 0!==t.paneId&&(i.paneId=t.paneId),void 0!==t.locked&&(i.locked=t.locked),void 0!==t.visible&&(i.visible=t.visible),void 0!==t.zIndex&&(i.zIndex=t.zIndex),void 0!==t.props&&i.applyProps(t.props),"showOn"in t&&(i.showOn=(0,o.MiJ)(t.showOn)),this.emit(),i):null}all(){return[...this.byId.values()].sort((e,t)=>e.zIndex-t.zIndex)}byPane(e){return this.all().filter(t=>t.paneId===e)}bringToFront(e,t=0){let i=this.byId.get(e);i&&(i.zIndex=Math.max(this.zCounter,Math.floor(t)+1),this.zCounter=i.zIndex+1,this.emit())}sendToBack(e,t=1){let i=this.byId.get(e);i&&(i.zIndex=Math.min(...[...this.byId.values()].map(e=>e.zIndex),Math.ceil(t))-1,this.emit())}setLocked(e,t){let i=this.byId.get(e);i&&(i.locked=t,this.emit())}setVisible(e,t){let i=this.byId.get(e);i&&(i.visible=t,this.emit())}clear(){0!==this.byId.size&&(this.byId.clear(),this.emit())}serialize(){return{version:1,drawings:this.all().map(e=>e.serialize())}}load(e){let t=e&&"object"==typeof e&&1===e.version&&Array.isArray(e.drawings)?{version:1,drawings:e.drawings.filter(D)}:{version:1,drawings:[]};for(let e of(this.byId.clear(),this.seq=0,this.zCounter=1,t.drawings)){let t=(0,o.erJ)(e);t&&(this.byId.set(t.id,t),this.zCounter=Math.max(this.zCounter,t.zIndex)+1,this.bumpSeqPast(t.id))}this.emit()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}bumpSeqPast(e){let t=/^dw-(\d+)$/.exec(e);t&&(this.seq=Math.max(this.seq,Number(t[1])))}emit(){for(let e of this.listeners)e()}},H=a.Wj,W=a.CY,q=new Map;function U(e){if("dark"===e.id||"light"===e.id)throw Error(`registerTheme: "${e.id}" is a built-in theme`);return q.set(e.id,e),()=>{q.get(e.id)===e&&q.delete(e.id)}}function j(){return[...q.values()]}var G=new WeakMap;function K(e){if(!e||"dark"===e)return H;if("light"===e)return W;if("string"==typeof e){let t=q.get(e);return t?K(t.theme):H}if("tokens"in e){let t=G.get(e);return t||G.set(e,t={...e.chart,ui:e.settings}),t}return e}var Y=e=>JSON.stringify([e.background,e.textColor,e.gridColor,e.borderColor,e.upColor,e.downColor,e.fontFamily,e.ui??null]),Z=class{constructor(e){this.renderer=e}get name(){return this.renderer.name}get capabilities(){return this.renderer.capabilities}supports(e){return this.renderer.features.includes(e)}get(e){return this.renderer.readFeature(e)}set(e,t){for(let[i,o]of"string"==typeof e?[[e,t]]:Object.entries(e))this.renderer.features.includes(i)?this.renderer.applyFeature(i,o):console.warn(`[vela] renderer "${this.renderer.name}" has no feature "${i}" — set ignored.`);return this}setLegendActions(e){this.renderer.setLegendActions?.(e)}setDrawingActions(e){this.renderer.setDrawingActions?.(e)}setLegendCallouts(e){this.renderer.setLegendCallouts?.(e)}setLegendOverviewAction(e){return this.renderer.setLegendOverviewAction?.(e),this}get supportsIndicatorSettings(){return"function"==typeof this.renderer.openIndicatorSettings}openIndicatorSettings(e){return this.renderer.openIndicatorSettings?.(e),this}screenshot(){return"function"==typeof this.renderer.screenshot?this.renderer.screenshot():(console.warn(`[vela] renderer "${this.renderer.name}" does not support screenshot().`),null)}screenshotCanvas(){return"function"==typeof this.renderer.screenshotCanvas?this.renderer.screenshotCanvas():null}getConfig(){return"function"==typeof this.renderer.getConfig?this.renderer.getConfig():(console.warn(`[vela] renderer "${this.renderer.name}" does not support getConfig().`),null)}applyConfig(e){return"function"==typeof this.renderer.applyConfig?this.renderer.applyConfig(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support applyConfig().`),this}onConfigChanged(e){return this.renderer.onConfigChanged?.(e)??(()=>void 0)}onCrosshairMove(e){return this.renderer.onCrosshairMove(e)}onClick(e){return this.renderer.onClick(e)}onAxisLongPress(e){return this.renderer.onAxisLongPress?.(e)??(()=>void 0)}dataWindowReadout(){return this.renderer.getDataWindowReadout?.()??null}setSymbolPicker(e){return"function"==typeof this.renderer.setSymbolPicker?this.renderer.setSymbolPicker(e):console.warn(`[vela] renderer "${this.renderer.name}" does not support setSymbolPicker().`),this}focus(){return this.renderer.focus?.(),this}get supportsExternalCrosshair(){return"function"==typeof this.renderer.setExternalCrosshair}setExternalCrosshair(e,t=null){return this.renderer.setExternalCrosshair?.(e,t),this}closeDialogs(){return this.renderer.closeDialogs?.(),this}openSettings(e){return this.renderer.openSettingsDialog?.(e),this}setSettingsSections(e){return this.renderer.setSettingsSections?.(e),this}setSettingsVisibility(e){return this.renderer.setSettingsVisibility?.(e),this}listSettingsIds(){return this.renderer.listSettingsIds?.()??[]}setLayoutMode(e){return this.renderer.setLayoutMode?.(e),this}setWallClock(e){return this.renderer.setWallClock?.(e),this}},X=class{constructor(){this.series=new Map,this.coveredFrom=new Map,this.retained=new Set,this.retainedByOwner=new Map}get(e){return this.series.get(e)}markCovered(e,t){this.coveredFrom.set(e,Math.min(this.coveredFrom.get(e)??1/0,t))}coveredFromOf(e){return this.coveredFrom.get(e)}merge(e,t){if(0===t.length)return this.series.get(e)??[];let i=new Map;for(let t of this.series.get(e)??[])i.set(t.time,t);for(let e of t)i.set(e.time,e);let o=[...i.values()].sort((e,t)=>e.time-t.time);return this.series.set(e,o),o}retainSymbol(e){this.currentSymbol!==e&&(this.currentSymbol=e,this.purgeOutside(e))}retain(e,t="default"){0===e.size?this.retainedByOwner.delete(t):this.retainedByOwner.set(t,new Set(e));let i=new Set;for(let e of this.retainedByOwner.values())for(let t of e)i.add(t);this.retained=i,this.purgeOutside(this.currentSymbol)}purgeOutside(e){for(let t of[...this.series.keys()]){let i=t.split("|")[1]??"";i===e||this.retained.has(i)||(this.series.delete(t),this.coveredFrom.delete(t))}}clear(){this.series.clear(),this.coveredFrom.clear()}},_=new X;function Q(e){return null!=e.group&&e.ticker===e.group}function J(e){return`${(e.prefix??e.provider??"").toLowerCase()}:${(e.group??"").toUpperCase()}`}var ee=e=>e.trim().toLowerCase(),et=e=>e.trim().toUpperCase();function ei(e){let t=e.trim(),i=/^(?:([A-Za-z0-9_.]+):)?(.+)$/.exec(t);if(!i)return{provider:null,ticker:t};let o=i[1]?ee(i[1]):null,r=i[2],l=r.lastIndexOf("."),n=l>0?r.slice(l+1):void 0;return{provider:o,ticker:r,ext:n}}var eo=class{constructor(){this.entries=new Map,this.changeListeners=new Set,this.waits=new Set,this.unresolvedCbs=new Set}register(e,t){let i=ee(e),o={name:i,provider:t,index:null,prefixIndex:null,byTicker:null,descriptors:[],settled:!1,settle:Promise.resolve()};return this.entries.set(i,o),o.settle=this.buildIndex(o),queueMicrotask(()=>this.notify(!1)),o.settle}async buildIndex(e){await Promise.resolve();try{if(e.provider.listSymbols){let t=await e.provider.listSymbols();for(let i of(e.descriptors=t,e.index=new Set(t.map(e=>et(e.ticker))),e.byTicker=new Map(t.map(e=>[et(e.ticker),e])),e.prefixIndex=new Map,t))i.prefix&&e.prefixIndex.set(`${ee(i.prefix)}:${et(i.ticker)}`,i)}}catch{e.index=null}finally{e.settled=!0,this.notify(!0)}}notify(e){for(let t of[...this.changeListeners])t(e)}onChange(e){return this.changeListeners.add(e),()=>this.changeListeners.delete(e)}unregister(e){this.entries.delete(ee(e)),this.notify(!1)}has(e){return this.entries.has(ee(e))}get(e){return this.entries.get(ee(e))?.provider}names(){return[...this.entries.keys()]}parse(e){return ei(e)}resolve(e,t={}){let{provider:i,ticker:o}=this.parse(e);if(i){if(this.entries.has(i)){let e=this.entries.get(i).byTicker?.get(et(o));return{provider:i,ticker:null!=e&&Q(e)?this.loadableTicker(i,e):o}}let e=`${i}:${et(o)}`;for(let i of this.candidateOrder(t.default)){let t=this.entries.get(i).prefixIndex?.get(e);if(t)return{provider:i,ticker:this.loadableTicker(i,t)}}return null}let r=et(o);for(let e of this.candidateOrder(t.default)){let t=this.entries.get(e);if(t.index?.has(r)){let i=t.byTicker?.get(r);return{provider:e,ticker:null!=i&&Q(i)?this.loadableTicker(e,i):o}}}if(t.lenient&&1===this.entries.size){let e=this.names()[0],t=this.entries.get(e);if(t.settled&&null==t.index)return{provider:e,ticker:o}}return null}loadableTicker(e,t){return Q(t)?function(e,t){let i=function(e,t){let i=J(t);return e.filter(e=>null!=e.group&&!Q(e)&&J(e)===i)}(e,t),o=i.filter(e=>e.default);return(1===o.length?o[0]:i[0])??null}(this.entries.get(e)?.descriptors??[],t)?.ticker??t.ticker:t.ticker}whenResolvable(e,t={}){let i=this.resolve(e,{...t,lenient:!0});return i?Promise.resolve(i):new Promise(i=>{let o=this.onChange(o=>{let l=this.resolve(e,{...t,lenient:!0});l?(r(),i(l)):o&&this.allSettled()&&this.reportUnresolved(e)}),r=()=>{o(),this.waits.delete(r)};this.waits.add(r)})}allSettled(){for(let e of this.entries.values())if(!e.settled)return!1;return!0}cancelWaits(){for(let e of[...this.waits])e()}onUnresolved(e){return this.unresolvedCbs.add(e),()=>this.unresolvedCbs.delete(e)}reportUnresolved(e){let t=this.names();for(let i of(console.warn(`[vela] symbol "${e}" not yet resolvable — registered providers: [${t.join(", ")||"none"}]. Register a provider that serves it.`),this.unresolvedCbs))i({symbol:e,providers:t})}candidateOrder(e){let t=this.names();if(e){let i=ee(e);if(this.entries.has(i))return[i,...t.filter(e=>e!==i)]}return t}displayPrefixOf(e){let t=this.entries.get(e.provider)?.byTicker?.get(et(e.ticker));return t?.prefix??e.provider}canonicalSymbol(e){let t=this.entries.get(e.provider)?.byTicker?.get(et(e.ticker));return`${t?.prefix??e.provider}:${t?.ticker??e.ticker}`}symbolIconOf(e){let t=e.provider?ee(e.provider):[...this.entries.keys()][0],i=void 0!==t?this.entries.get(t):void 0;try{return i?.provider.resolveSymbolIcon?.(e)??void 0}catch{return}}symbolIcon(e){if(!e)return;let t=this.entries.get(e.provider)?.byTicker?.get(et(e.ticker));return this.symbolIconOf({...t??{ticker:e.ticker},provider:t?.provider??e.provider})}symbolsOf(e){return null!=e?this.entries.get(ee(e))?.descriptors??[]:[...this.entries.entries()].flatMap(([e,t])=>t.descriptors.map(t=>({...t,provider:e})))}infoOf(e){let t=ee(e),i=this.entries.get(t);if(!i)return{name:t,capabilities:{enumerate:!1,stream:!1,symbolInfo:!1}};let o=i.provider;return o.info?.()??{name:i.name,capabilities:{enumerate:!!o.listSymbols,stream:!!o.subscribe,symbolInfo:!!o.getSymbolInfo}}}indexReady(){return Promise.all([...this.entries.values()].map(e=>e.settle)).then(()=>void 0)}};function er(e,t,i){var o;let{provider:r,ticker:l}=ei(e);return o=r??"",`${o}|${l}|${t}${i&&"regular"!==i?`|${i}`:""}`}var el=class{constructor(e,t=_){this.inner=e,this.store=t,this.loadInflight=new Map}async load(e){if(e.data&&e.data.length>0||(0,o.jJY)(e.timeframe??""))return this.inner.load(e);let t=e.symbol??"TEST",i=er(t,e.timeframe??"60",e.session),r=e.bars??500,l=`${i}|${r}`,n=this.loadInflight.get(l);return n||(n=this.loadSeries(e,t,i,r).finally(()=>this.loadInflight.delete(l)),this.loadInflight.set(l,n)),(await n).map(e=>({...e}))}async loadSeries(e,t,i,o){this.store.retainSymbol(t);let r=this.store.get(i),l=r?.[r.length-1];if(r&&l&&r.length>=o-1&&this.inner.loadRange){let{bars:t}=await this.fetchRange(e,{from:l.time});return ea(this.store.merge(i,en(t)),t[t.length-1]).slice(-o)}let n=await this.inner.load(e);return this.store.merge(i,en(n)),n}async loadProgressive(e,t,i){if(e.data&&e.data.length>0)return this.inner.load(e);if(!this.inner.loadProgressive)return null;if((0,o.jJY)(e.timeframe??""))return this.inner.loadProgressive(e,t,i);let r=e.symbol??"TEST",l=er(r,e.timeframe??"60",e.session),n=this.store.get(l),a=e.bars??500,s=n?.[n.length-1];if(n&&s&&n.length>=a-1&&this.inner.loadRange)return this.load(e);this.store.retainSymbol(r);let h=await this.inner.loadProgressive(e,t,i);return null==h?null:(this.store.merge(l,en(h)),h)}async loadRange(e,t){if(!this.inner.loadRange)return this.inner.load(e);if((0,o.jJY)(e.timeframe??""))return this.inner.loadRange(e,t);let i=er(e.symbol??"TEST",e.timeframe??"60",e.session),r=this.store.get(i),l=r?.[r.length-1];if(null!=t.to&&l&&t.to<l.time){let o=r.filter(e=>e.time<=t.to),l=this.store.coveredFromOf(i)??1/0;if(null!=t.limit?o.length>=t.limit&&(null==t.from||l<=t.from):null!=t.from&&l<=t.from){let e=null!=t.from?o.filter(e=>e.time>=t.from):o;return null!=t.limit&&e.length>t.limit&&(e=e.slice(-t.limit)),e}let n=await this.fetchRange(e,t),a=n.bars.filter(e=>e.time<=t.to);return a.length>0&&(this.store.merge(i,a),this.store.markCovered(i,n.coveredDownTo??a[0].time)),a}if(l&&null!=t.from){let o=this.store.coveredFromOf(i);if(null!=o&&o>t.from){let{bars:n,coveredDownTo:a}=await this.fetchRange(e,{from:t.from,to:o});this.store.merge(i,n.filter(e=>e.time<=o)),this.store.markCovered(i,a??t.from),r=this.store.get(i),l=r?.[r.length-1]}}let n=this.store.coveredFromOf(i);if(r&&r.length>0&&l&&(null!=t.from?null!=n&&n<=t.from:null==t.limit||r.length>=t.limit)&&l){let{bars:o}=await this.fetchRange(e,{from:l.time,to:t.to,limit:t.limit}),r=ea(this.store.merge(i,en(o)),o[o.length-1]),n=null!=t.from?r.filter(e=>e.time>=t.from):r;return null!=t.to&&(n=n.filter(e=>e.time<=t.to)),n}let{bars:a,coveredDownTo:s}=await this.fetchRange(e,t);return this.store.merge(i,en(a)),this.store.markCovered(i,s??t.from??a[0]?.time??0),a}async fetchRange(e,t){var i,r;let l=(0,o.cle)(e.timeframe??"60"),n=(i=t,r=l,null!=i.limit?i.limit:null==i.from?1e4:Math.ceil(Math.max(0,(i.to??Date.now())-i.from)/r*1.1)+2);if(n<=10001){let i=await this.inner.loadRange(e,{...t,limit:t.limit??n});return{bars:i,coveredDownTo:t.from??i[0]?.time}}let a=new Map,s=t.to??Date.now();for(;null==t.from||!(s<t.from);){let i=null!=t.limit?t.limit-a.size:1e4;if(i<=0)break;let o=await this.inner.loadRange(e,{to:s,limit:Math.min(1e4,i)}),r=1/0;for(let e of o)e.time<r&&(r=e.time),e.time<=s&&(null==t.from||e.time>=t.from)&&a.set(e.time,e);if(0===o.length){if(null==t.from)break;s-=1e4*l;continue}if(r-1>=s)break;s=r-1}let h=[...a.values()].sort((e,t)=>e.time-t.time);return{bars:h,coveredDownTo:null!=t.from&&s<t.from?t.from:h[0]?.time}}subscribe(e,t){return this.inner.subscribe(e,t)}symbolInfo(e){return this.inner.symbolInfo?.(e)}};function en(e){return e.length>0?e.slice(0,-1):e}function ea(e,t){if(!t)return e;let i=e[e.length-1];return!i||t.time>i.time?[...e,t]:e}var es=class{constructor(e=_){this.registry=new eo,this.primaryProvider=null,this.symInfoCache=new Map,this.symInfoInflight=new Map,this.cache=new el(new eb(this.registry,e=>this.fetchSymbolInfo(e)),e)}registerProvider(e,t){return this.registry.register(e,t)}unregisterProvider(e){this.registry.unregister(e)}providers(){return this.registry.names().map(e=>this.registry.infoOf(e))}resolveSymbol(e){return this.registry.resolve(e,{default:this.primaryProvider})}displayPrefix(e){let t=this.resolveSymbol(e);return t?this.registry.displayPrefixOf(t):null}canonicalSymbol(e){let t=this.resolveSymbol(e);return t?this.registry.canonicalSymbol(t):null}providerInstance(e){return this.registry.get(e)}symbolIconOf(e){return this.registry.symbolIconOf(e)}symbolIcon(e){return this.registry.symbolIcon(this.resolveSymbol(e))}symbols(e){return this.registry.symbolsOf(e)}onUnresolved(e){return this.registry.onUnresolved(e)}destroy(){this.registry.cancelWaits()}ready(){return this.registry.indexReady()}async symbolInfoFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(t)return this.fetchSymbolInfo(t)}fetchSymbolInfo(e){let t=ec(e),i=this.symInfoCache.get(t);if(i&&Date.now()-i.at<ep)return Promise.resolve(i.info);let o=this.symInfoInflight.get(t);if(o)return o;let r=this.registry.get(e.provider)?.getSymbolInfo;if(!r)return Promise.resolve(void 0);let l=Promise.resolve(r.call(this.registry.get(e.provider),e.ticker)).then(e=>(e&&this.symInfoCache.set(t,{info:e,at:Date.now()}),e)).finally(()=>{this.symInfoInflight.delete(t)});return this.symInfoInflight.set(t,l),l}capabilitiesFor(e){let t=this.registry.resolve(e,{default:this.primaryProvider});if(!t)return null;let i=this.registry.get(t.provider);return i?i.capabilitiesFor?.(t.ticker)??this.registry.infoOf(t.provider).capabilities:null}async load(e){if(e.data&&e.data.length>0)return e.data;let t=await this.registry.whenResolvable(eh(e),{default:this.primaryProvider});return this.primaryProvider=t.provider,this.prefetchSymbolInfo(t),this.cache.load(ed(e,t))}async loadProgressive(e,t,i){if(e.data&&e.data.length>0)return e.data;let o=await this.registry.whenResolvable(eh(e),{default:this.primaryProvider});return this.primaryProvider=o.provider,this.prefetchSymbolInfo(o),this.cache.loadProgressive(ed(e,o),t,i)}symbolInfo(e){if(e.data&&e.data.length>0)return;let t=this.registry.resolve(eh(e),{default:this.primaryProvider});return t?this.symInfoCache.get(ec(t))?.info:void 0}prefetchSymbolInfo(e){this.fetchSymbolInfo(e).catch(()=>{})}async loadRange(e,t){if(e.data&&e.data.length>0)return this.cache.loadRange(e,t);let i=this.registry.resolve(eh(e),{default:this.primaryProvider});return i?this.cache.loadRange(ed(e,i),t):[]}subscribe(e,t){if(e.data&&e.data.length>0)return()=>{};let i=this.registry.resolve(eh(e),{default:this.primaryProvider});return i?this.cache.subscribe(ed(e,i),t):()=>{}}};function eh(e){return e.symbol??""}function ed(e,t){return{...e,symbol:`${t.provider}:${t.ticker}`}}function ec(e){return`${e.provider}|${e.ticker.trim().toUpperCase()}`}var ep=6e5;async function eu(e,t,i,r){try{return await e.getBars(t,i,r)}catch(e){if((0,o.DhR)(e))throw eg(e,t,i);return console.warn(`[vela] data fetch failed for ${t} ${i} — ${e instanceof Error?e.message:String(e)}`),[]}}function eg(e,t,i){if(void 0!==e.symbol&&void 0!==e.timeframe)return e;let r={reason:e.reason,symbol:e.symbol??t,timeframe:e.timeframe??i,finest:e.finest,default:e.default};return new o.F8H(r,e.message===(0,o.ec6)(e)?void 0:e.message)}async function em(e,t,i){try{return await e.getBars(t,i)}catch(i){if((0,o.DhR)(i))throw eg(i,t.ticker,t.timeframe);return console.warn(`[vela] series adapter "${e.id}" fetch failed for ${t.ticker} ${t.timeframe} — ${i instanceof Error?i.message:String(i)}`),[]}}var eb=class{constructor(e,t){this.registry=e,this.readSymbolInfo=t}adapterContext(e,t,i,o,r){return{providerName:e,provider:t,ticker:i,timeframe:o,...void 0!==r?{session:r}:{},symbolInfo:()=>this.readSymbolInfo({provider:e,ticker:i})}}load(e){let{provider:t,ticker:i}=ei(e.symbol??""),r=this.registry.get(t??"");if(!r)return Promise.resolve([]);let l=e.timeframe??"60",n={limit:e.bars??500,session:e.session},a=(0,o.Kvt)(l,r,t??"");return a?em(a,this.adapterContext(t??"",r,i,l,e.session),n):eu(r,i,l,n)}async loadProgressive(e,t,i){let{provider:r,ticker:l}=ei(e.symbol??""),n=this.registry.get(r??"");if(!n)return[];let a=e.timeframe??"60";if((0,o.Kvt)(a,n,r??"")||!n.getBarsProgressive)return null;try{return await n.getBarsProgressive(l,a,{limit:e.bars??500,session:e.session},t,i)}catch(e){if((0,o.DhR)(e))throw eg(e,l,a);return console.warn(`[vela] progressive fetch failed for ${l} ${a} — ${e instanceof Error?e.message:String(e)}`),[]}}loadRange(e,t){let{provider:i,ticker:r}=ei(e.symbol??""),l=this.registry.get(i??"");if(!l)return Promise.resolve([]);let n=e.timeframe??"60",a={...t,session:e.session},s=(0,o.Kvt)(n,l,i??"");return s?em(s,this.adapterContext(i??"",l,r,n,e.session),a):eu(l,r,n,a)}subscribe(e,t){let{provider:i,ticker:r}=ei(e.symbol??""),l=this.registry.get(i??"");if(!l)return()=>{};let n=e.timeframe??"60",a=(0,o.Kvt)(n,l,i??"");if(a){let o=this.adapterContext(i??"",l,r,n,e.session);return a.subscribe?a.subscribe(o,t):this.poll(()=>a.getBars(o,{limit:2,session:e.session}),t)}return l.subscribe?l.subscribe(r,n,t,e.session?{session:e.session}:void 0):this.poll(()=>l.getBars(r,n,{limit:2,session:e.session}),t)}poll(e,t){let i=!1,r=null,l=async()=>{if(!i){try{let o=await e();if(i)return;for(let e of o)t(e)}catch(e){if((0,o.DhR)(e)){console.warn(`[vela] live updates stopped — ${e.message}`),i=!0;return}}i||(r=setTimeout(()=>void l(),3e3))}};return r=setTimeout(()=>void l(),3e3),()=>{i=!0,r&&clearTimeout(r)}}},ef=class{constructor(e){this.registry=e instanceof es?e:null}registerProvider(e,t){return this.registry?this.registry.registerProvider(e,t):console.warn(`[vela] chart.data.registerProvider("${e}") ignored — the active data feed is a custom feed (deps.dataFeed), not the default provider registry.`),this}unregisterProvider(e){return this.registry?.unregisterProvider(e),this}providers(){return this.registry?.providers()??[]}resolve(e){return this.registry?.resolveSymbol(e)??null}displayPrefix(e){return this.registry?.displayPrefix(e)??null}canonicalSymbol(e){return this.registry?.canonicalSymbol(e)??null}providerInstance(e){return this.registry?.providerInstance(e)}symbols(e){return this.registry?.symbols(e)??[]}symbolIcon(e){return this.registry?.symbolIcon(e)}symbolInfo(e){return this.registry?.symbolInfoFor(e)??Promise.resolve(void 0)}capabilities(e){return this.registry?.capabilitiesFor(e)??null}ready(){return this.registry?.ready()??Promise.resolve()}},ev=class{constructor(e){this.ctrl=e}get supported(){return this.ctrl.supported}setTool(e){return this.ok("setTool")&&this.ctrl.setTool(e),this}getTool(){return this.ctrl.getTool()}setSnapMode(e){return this.ok("setSnapMode")&&this.ctrl.setSnapMode(e),this}getSnapMode(){return this.ctrl.getSnapMode()}setStayMode(e){return this.ok("setStayMode")&&this.ctrl.setStayMode(e),this}getStayMode(){return this.ctrl.getStayMode()}setMode(e){return this.ok("setMode")&&this.ctrl.setMode(e),this}getMode(){return this.ctrl.getMode()}showToolbar(e=!0){return this.ok("showToolbar")&&this.ctrl.showToolbar(e),this}setToolbar(e){return this.ok("setToolbar")&&this.ctrl.setToolbar(e),this}setToolShortcuts(e){return this.ok("setToolShortcuts")&&this.ctrl.setToolShortcuts(e),this}setExternalGhost(e){return this.ctrl.setExternalGhost(e),this}add(e,t={}){return this.ok("add")?this.ctrl.add(e,t):null}remove(e){return this.ctrl.remove(e),this}update(e,t){return this.ctrl.update(e,t),this}updateMany(e){return this.ctrl.updateMany(e),this}removeMany(e){return this.ctrl.removeMany(e),this}clear(){return this.ctrl.clear(),this}setClearOnSymbolChange(e){return this.ctrl.setClearOnSymbolChange(e),this}getClearOnSymbolChange(){return this.ctrl.getClearOnSymbolChange()}lock(e,t=!0){return this.ctrl.setLocked(e,t),this}show(e,t=!0){return this.ctrl.setVisible(e,t),this}select(e){return this.ok("select")&&this.ctrl.select(null==e?[]:"string"==typeof e?[e]:e),this}openSettings(e){return this.ok("openSettings")&&this.ctrl.openSettings(e),this}bringToFront(e){return this.ctrl.bringToFront(e),this}sendToBack(e){return this.ctrl.sendToBack(e),this}undo(){return this.ctrl.undo(),this}redo(){return this.ctrl.redo(),this}canUndo(){return this.ctrl.canUndo()}canRedo(){return this.ctrl.canRedo()}clone(e){return this.ok("clone")&&this.ctrl.clone(e),this}duplicate(e){return this.ok("duplicate")&&this.ctrl.duplicate(e),this}copyToClipboard(e){return this.ok("copy")&&this.ctrl.copy(e),this}paste(){return this.ok("paste")&&this.ctrl.paste(),this}all(){return this.ctrl.all()}toJSON(){return this.ctrl.toJSON()}fromJSON(e){return this.ctrl.fromJSON(e),this}favorites(){return this.ctrl.favorites()}isFavorite(e){return this.ctrl.isFavorite(e)}setFavorite(e,t){return this.ok("setFavorite")&&this.ctrl.setFavorite(e,t),this}setFavorites(e){return this.ok("setFavorites")&&this.ctrl.setFavorites([...e]),this}toolDefaults(){return this.ctrl.toolDefaults()}setToolDefaults(e){return this.ctrl.setToolDefaults(e),this}resetToolDefaults(e){return this.ctrl.resetToolDefaults(e),this}toolTemplates(){return this.ctrl.toolTemplates()}setToolTemplates(e){return this.ctrl.setToolTemplates(e),this}getConfig(){return this.ctrl.toJSON()}applyConfig(e){return this.ctrl.fromJSON(e),this}ok(e){return!!this.ctrl.supported||(console.warn(`[vela] chart.drawings.${e}() ignored — the active renderer has no userDrawings capability.`),!1)}},ey=class{constructor(e){this.ctrl=e}get supported(){return this.ctrl.supported}add(e){return this.ctrl.add(e),this}set(e){return this.ctrl.set(e),this}remove(e){return this.ctrl.remove(e),this}clear(){return this.ctrl.clear(),this}all(){return this.ctrl.all()}defineGroup(e){return this.ctrl.defineGroup(e),this}groups(){return this.ctrl.groupDefinitions()}setGroupVisible(e,t=!0){return this.ctrl.setGroupVisible(e,t),this}isGroupVisible(e){return this.ctrl.isGroupVisible(e)}},ew=class{constructor(e){this.ctrl=e}start(e){return this.ctrl.replayStart(e)}step(){return this.ctrl.replayStep()}stepUpdate(){return this.ctrl.replayStepUpdate()}play(e){return this.ctrl.replayPlay(e),this}pause(){return this.ctrl.replayPause(),this}stop(){return this.ctrl.replayStop(),this}get state(){return this.ctrl.replayState()}get bounds(){return this.ctrl.replayBounds()}setTicks(e){return this.ctrl.replaySetTicks(e),this}},eC=2*6e4,ex=60*6e4,ek=()=>"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now(),eS=class{constructor(e=()=>Date.now(),t=ek){this.deviceNow=e,this.monotonic=t,this.behindMs=0,this.skew=null}observeCandle(e,t){if(!Number.isFinite(e)||!(t>0)||t>ex)return;let i=e-this.readDevice();i>this.behindMs&&i<=eC&&(this.behindMs=i)}get offsetMs(){return this.readDevice(),this.behindMs}now(){return this.readDevice()+this.behindMs}reset(){this.behindMs=0,this.skew=null}readDevice(){let e=this.deviceNow(),t=e-this.monotonic();return null!==this.skew&&Math.abs(t-this.skew)>1e3&&(this.behindMs=0),this.skew=t,e}},eT=new eS,eM=class e{constructor(e=()=>eT.now()){this.now=e,this.subs=new Set,this.timer=null}onTick(e){return this.subs.add(e),null==this.timer&&this.arm(),()=>{this.subs.delete(e),0===this.subs.size&&null!=this.timer&&(clearTimeout(this.timer),this.timer=null)}}static delayToNextSecond(e){return 1e3-(e%1e3+1e3)%1e3+5}arm(){this.timer=setTimeout(()=>{this.timer=null;let e=this.now();for(let t of this.subs)t(e);this.subs.size>0&&this.arm()},e.delayToNextSecond(this.now()))}};function eL(e){let t={style:{...e.style}};if(e.text){let{value:i,...o}=e.text;t.text=o}let i=e.serialize().props;return void 0!==i&&(t.props=V(i)),t}function eA(e,t){t&&(t.style&&(e.style={...e.style,...t.style}),t.text&&(e.text={...e.text??(0,o.VCu)(),...t.text,value:e.text?.value??""}),t.props&&e.applyProps(V(t.props)))}function eP(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function eI(e){if(null==e||"object"!=typeof e||Array.isArray(e))return null;let t=e=>null==e||"object"!=typeof e||Array.isArray(e)?void 0:e,i={},o=t(e.style);o&&(i.style=o);let r=t(e.text);if(r){let{value:e,...t}=r;i.text=t}let l=t(e.props);return l&&(i.props=l),i.style||i.text||i.props?i:null}function eE(e){if(!Array.isArray(e))return[];let t=new Map;for(let i of e){if(null==i||"object"!=typeof i)continue;let e="string"==typeof i.name?i.name.trim().slice(0,60):"",o=eI(i.settings);e&&o&&t.set(e,{name:e,settings:o})}return[...t.values()]}var eB=new Set(["trendline","ray","extendedline","hline","hray","vline","crossline","infoline","trendangle"]),eF=new Set(["box","rotatedrect","ellipse","circle","triangle","parallelchannel","disjointchannel","flattopbottom"]);function eO(e){return eB.has(e)?[{name:"Support",label:(0,n.ab)("drawing.template.support","Support"),settings:{style:{lineColor:r.cr,lineWidth:2,lineStyle:"solid"}}},{name:"Resistance",label:(0,n.ab)("drawing.template.resistance","Resistance"),settings:{style:{lineColor:r.TV,lineWidth:2,lineStyle:"solid"}}},{name:"Projection",label:(0,n.ab)("drawing.template.projection","Projection"),settings:{style:{lineColor:r.qm,lineWidth:1,lineStyle:"dashed"}}}]:eF.has(e)?[{name:"Demand",label:(0,n.ab)("drawing.template.demand","Demand"),settings:{style:{lineColor:r.cr,fillColor:`${r.cr}26`}}},{name:"Supply",label:(0,n.ab)("drawing.template.supply","Supply"),settings:{style:{lineColor:r.TV,fillColor:`${r.TV}26`}}}]:[]}var eR=r.dO,eN=r.uY;function ez(e,t){if(e instanceof o.btd){if(!e.fillTriangles().length)return null;let t=e.valid();return e.style.fillColor??(null==t?e.style.lineColor:t?eR:eN)}return e instanceof o.uzv?e.style.fillColor??t.background:e.style.fillColor??null}var eV=class{constructor(e=100){this.cap=e,this.undoStack=[],this.redoStack=[],this.pending=null,this.dirtied=!1,this.depth=0}begin(e){this.depth+=1,1===this.depth&&(this.pending=V(e),this.dirtied=!1)}markDirty(){0!==this.depth&&!this.dirtied&&this.pending&&(this.push(this.pending),this.dirtied=!0)}commit(){0!==this.depth&&(this.depth-=1,0===this.depth&&(this.pending=null,this.dirtied=!1))}abort(){this.commit()}record(e){if(this.depth>0)return void this.markDirty();this.push(V(e))}undo(e){let t=this.undoStack.pop();return t?(this.redoStack.push(V(e)),t):null}redo(e){let t=this.redoStack.pop();return t?(this.undoStack.push(V(e)),t):null}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[],this.pending=null,this.dirtied=!1,this.depth=0}push(e){this.undoStack.push(e),this.undoStack.length>this.cap&&this.undoStack.shift(),this.redoStack=[]}},eD=class{constructor(e,t,i,o,r=()=>null){if(this.events=t,this.i18n=r,this.store=new $,this.history=new eV,this.activeTool=null,this.snapMode="off",this.stayInDrawingMode=!1,this.clearOnSymbolChange=!1,this.mode=null,this.favs=new Set,this.selectedIds=[],this.clipboard=[],this.defaults=new Map,this.templates=new Map,this.subs=[],this.enabled=!!e.capabilities.userDrawings&&!!e.userDrawingsPort,this.port=this.enabled?e.userDrawingsPort:null,this.toolbarOption=i,this.clearOnSymbolChange="object"==typeof i&&!0===i.clearOnSymbolChange,this.port){let{definition:e,visible:t}=z(i,this.i18n());this.port.setToolbar(e),this.port.showToolbar(t),o&&this.port.setSeriesGateway?.(o),this.subs.push(this.port.onDrawingIntent(e=>this.onIntent(e))),this.subs.push(this.store.onChange(()=>this.sync()))}}get supported(){return this.enabled}setTool(e){if(!this.port)return;let t=e!==this.activeTool;this.activeTool=e;let i=e?this.defaults.get(e):void 0;this.port.setActiveTool(e,i?.style,i),t&&this.events.emit("drawing:tool",{type:e})}getTool(){return this.activeTool}getSnapMode(){return this.snapMode}setSnapMode(e){this.port&&e!==this.snapMode&&(this.snapMode=e,this.port.setSnapMode?.(e),this.events.emit("drawing:snap",{mode:e}))}getStayMode(){return this.stayInDrawingMode}setStayMode(e){this.port&&e!==this.stayInDrawingMode&&(this.stayInDrawingMode=e,this.port.setStayMode?.(e),this.events.emit("drawing:stay",{on:e}))}getMode(){return this.mode}setMode(e){this.port&&e!==this.mode&&(this.mode=e,this.port.setMode?.(e),this.events.emit("drawing:mode",{mode:e}))}showToolbar(e){this.port?.showToolbar(e)}favorites(){return[...this.favs]}isFavorite(e){return this.favs.has(e)}setFavorite(e,t){(0,o.jOy)(e)&&t!==this.favs.has(e)&&(t?this.favs.add(e):this.favs.delete(e),this.pushFavorites())}setFavorites(e){let t=e.filter(e=>null!=(0,o.jOy)(e));t.length===this.favs.size&&t.every(e=>this.favs.has(e))||(this.favs=new Set(t),this.pushFavorites())}pushFavorites(){let e=[...this.favs];this.port?.setFavorites?.(e),this.events.emit("drawing:favorites",{favorites:e})}toolDefaults(){let e={};for(let[t,i]of this.defaults)e[t]=V(i);return e}setToolDefaults(e){let t=new Map;for(let[i,r]of Object.entries(e??{})){if(!(0,o.jOy)(i))continue;let e=eI(r);e&&t.set(i,V(e))}let i=new Set([...this.defaults.keys(),...t.keys()]);for(let e of[...i])eP(this.defaults.get(e),t.get(e))&&i.delete(e);if(0!==i.size){for(let[e,i]of(this.defaults.clear(),t))this.defaults.set(e,i);for(let e of(this.activeTool&&i.has(this.activeTool)&&this.setTool(this.activeTool),i))this.events.emit("drawing:defaults",{type:e})}}resetToolDefaults(e){for(let t of e?this.defaults.has(e)?[e]:[]:[...this.defaults.keys()])this.defaults.delete(t),this.events.emit("drawing:defaults",{type:t})}toolTemplates(){let e={};for(let[t,i]of this.templates)e[t]=V(i);return e}setToolTemplates(e){let t=new Map;for(let[i,r]of Object.entries(e??{})){if(!(0,o.jOy)(i))continue;let e=eE(r);e.length>0&&t.set(i,e)}let i=[...new Set([...this.templates.keys(),...t.keys()])].filter(e=>JSON.stringify(this.templates.get(e)??[])!==JSON.stringify(t.get(e)??[]));if(0!==i.length)for(let e of(this.templates=t,this.pushTemplates(),i))this.events.emit("drawing:templates",{type:e})}saveToolTemplate(e,t,i){if(!(0,o.jOy)(e))return;let[r]=eE([{name:t,settings:i}]);if(!r)return;let l=(this.templates.get(e)??[]).filter(e=>e.name!==r.name);this.templates.set(e,[...l,V(r)]),this.pushTemplates(),this.events.emit("drawing:templates",{type:e})}removeToolTemplate(e,t){let i=this.templates.get(e);if(!i?.some(e=>e.name===t))return;let o=i.filter(e=>e.name!==t);o.length>0?this.templates.set(e,o):this.templates.delete(e),this.pushTemplates(),this.events.emit("drawing:templates",{type:e})}pushTemplates(){this.port?.setToolTemplates?.(this.toolTemplates())}setToolbar(e){this.toolbarOption=e,this.port?.setToolbar(z(e,this.i18n()).definition)}relocalize(){this.port?.setToolbar(z(this.toolbarOption,this.i18n()).definition)}setExternalGhost(e){this.port?.setExternalGhost?.(e)}setToolShortcuts(e){this.port?.setToolShortcuts?.(e)}add(e,t={}){if(!this.enabled)return null;let i=this.defaults.get(e),r=(0,o.vBD)(e,{id:this.store.nextId(),paneId:t.paneId??"price",anchors:t.anchors,text:t.text,zIndex:t.zIndex??this.startZ(e,t.paneId??"price")});return r?(eA(r,i),t.style&&(r.style={...r.style,...t.style}),t.text&&(r.text={...r.text??t.text,...t.text}),t.props&&r.applyProps(t.props),this.history.record(this.store.serialize()),this.store.add(r),this.captureDefaults(r.id),this.events.emit("drawing:created",{id:r.id}),r):null}remove(e){this.deleteMany([e])}update(e,t){let i=this.store.serialize(),o=t.style?this.store.get(e):void 0,r=t.style&&o?{...t,style:{...o.style,...t.style}}:t;this.updateDrawing(e,r)&&(this.history.record(i),this.events.emit("drawing:edited",{id:e}))}updateMany(e){for(let{id:t,patch:i}of(this.history.begin(this.store.serialize()),e))this.updateDrawing(t,i)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t}));this.history.commit()}removeMany(e){this.deleteMany(e)}clear(){this.deleteMany(this.store.serialize().drawings.map(e=>e.id))}getClearOnSymbolChange(){return this.clearOnSymbolChange}setClearOnSymbolChange(e){this.clearOnSymbolChange=e}onSymbolChange(){this.clearOnSymbolChange&&this.store.serialize().drawings.length>0&&this.replace(null,"symbol")}setLocked(e,t){let i=this.store.serialize();this.history.record(i),this.store.setLocked(e,t),this.events.emit("drawing:edited",{id:e})}setVisible(e,t){let i=this.store.serialize();this.history.record(i),this.store.setVisible(e,t),this.events.emit("drawing:edited",{id:e})}bringToFront(e){let t=this.store.serialize();this.history.record(t),this.store.bringToFront(e,this.seriesTopZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e})}sendToBack(e){let t=this.store.serialize();this.history.record(t),this.store.sendToBack(e,this.seriesBottomZ(this.store.get(e)?.paneId)),this.events.emit("drawing:edited",{id:e})}seriesTopZ(e){return void 0!==e?this.port?.stackRange?.(e)?.front??0:0}seriesBottomZ(e){return void 0!==e?this.port?.stackRange?.(e)?.back??1:1}startZ(e,t){let i=this.port?.stackRange?.(t);if(i)return(0,o.jOy)(e)?.coversSeries?i.front+.5:(i.price??i.front)-.5}select(e,t=!1){this.setSelection(e,t)}openSettings(e){this.port?.openSettings(e)}undo(){let e=this.history.undo(this.store.serialize());e&&(this.restoreSnapshot(e),this.events.emit("drawing:history",{action:"undo"}))}redo(){let e=this.history.redo(this.store.serialize());e&&(this.restoreSnapshot(e),this.events.emit("drawing:history",{action:"redo"}))}canUndo(){return this.history.canUndo()}canRedo(){return this.history.canRedo()}duplicate(e){if(!this.enabled)return[];let t=this.resolve(e);return 0===t.length?[]:this.insertClones(t.map(e=>e.serialize()))}clone(e){return this.duplicate([e])[0]??null}copy(e){let t=this.resolve(e).map(e=>V(e.serialize()));t.length&&(this.clipboard=t)}paste(){return this.enabled&&0!==this.clipboard.length?this.insertClones(this.clipboard):[]}all(){return this.store.serialize().drawings}toJSON(){return this.store.serialize()}fromJSON(e){this.replace(e,"load")}replace(e,t){this.history.clear(),this.selectedIds=[],this.store.load(e),this.events.emit("drawing:replaced",{cause:t})}destroy(){for(let e of this.subs)e();this.subs.length=0}setSelection(e,t=!1){let i;if(t)for(let t of(i=[...this.selectedIds],e)){let e=i.indexOf(t);e>=0?i.splice(e,1):i.push(t)}else i=[...e];this.selectedIds=i.filter(e=>this.store.has(e)),this.announceSelection()}announceSelection(){this.port?.setSelection(this.selectedIds),this.events.emit("drawing:selected",{id:this.selectedIds[0]??null,ids:[...this.selectedIds]})}restoreSnapshot(e){this.store.load(e),this.selectedIds=this.selectedIds.filter(e=>this.store.has(e)),this.announceSelection()}deleteMany(e){this.history.begin(this.store.serialize());let t=[];for(let i of e)this.store.remove(i)&&t.push(i),this.history.markDirty();if(this.history.commit(),0===t.length)return;let i=this.selectedIds.filter(e=>this.store.has(e));for(let e of(i.length!==this.selectedIds.length&&this.setSelection(i),t))this.events.emit("drawing:removed",{id:e})}insertClones(e){this.history.begin(this.store.serialize());let t=[];for(let i of e){let e=(0,o.erJ)({...i,id:this.store.nextId()});e&&(this.store.add(e),this.history.markDirty(),t.push(e))}if(this.history.commit(),t.length)for(let e of(this.setSelection(t.map(e=>e.id)),t))this.events.emit("drawing:created",{id:e.id});return t}resolve(e){return e.map(e=>this.store.get(e)).filter(e=>null!=e)}updateDrawing(e,t){let i=this.store.get(e),o=i?eL(i):void 0;if(!this.store.update(e,t))return!1;let r=this.store.get(e);return r&&!eP(o,eL(r))&&this.captureDefaults(e),!0}captureDefaults(e){let t=this.store.get(e);if(!t)return;let i=eL(t),r=eP(i,function(e){let t=(0,o.vBD)(e.type,{paneId:e.paneId});return t?eL(t):void 0}(t))?void 0:i;eP(this.defaults.get(t.type),r)||(r?this.defaults.set(t.type,r):this.defaults.delete(t.type),this.events.emit("drawing:defaults",{type:t.type}))}sync(){this.port?.syncDrawings(this.store.serialize().drawings)}onIntent(e){switch(e.kind){case"arm":this.setTool(e.type);break;case"draft":this.events.emit("drawing:draft",{doc:e.doc});break;case"create":{let t=this.store.serialize(),i=(0,o.erJ)({...e.doc,id:this.store.nextId()});if(!i)return;eA(i,this.defaults.get(i.type)),i.zIndex||(i.zIndex=this.startZ(i.type,i.paneId)??0),this.history.record(t),this.store.add(i),this.captureDefaults(i.id),this.events.emit("drawing:created",{id:i.id});break}case"edit":{let t=this.store.serialize();this.updateDrawing(e.doc.id,e.doc)&&(this.history.record(t),this.events.emit("drawing:edited",{id:e.doc.id}));break}case"edit-many":for(let t of(this.history.begin(this.store.serialize()),e.docs))this.updateDrawing(t.id,t)&&(this.history.markDirty(),this.events.emit("drawing:edited",{id:t.id}));this.history.commit();break;case"select":this.setSelection(e.ids,e.additive);break;case"delete":this.deleteMany(e.ids);break;case"reorder":"front"===e.to?this.bringToFront(e.id):this.sendToBack(e.id);break;case"settings":this.events.emit("drawing:settings",{id:e.id});break;case"favorite":this.setFavorite(e.type,e.on);break;case"template-save":this.saveToolTemplate(e.type,e.name,e.settings);break;case"template-remove":this.removeToolTemplate(e.type,e.name);break;case"snap-mode":e.mode!==this.snapMode&&(this.snapMode=e.mode,this.events.emit("drawing:snap",{mode:e.mode}));break;case"stay-mode":e.on!==this.stayInDrawingMode&&(this.stayInDrawingMode=e.on,this.events.emit("drawing:stay",{on:e.on}));break;case"mode":e.mode!==this.mode&&(this.mode=e.mode,this.events.emit("drawing:mode",{mode:e.mode}));break;case"tool-finished":this.stayInDrawingMode||"freehand"===e.type||"highlighter"===e.type||this.setTool(null);break;case"undo":this.undo();break;case"redo":this.redo();break;case"duplicate":this.duplicate(e.ids);break;case"clone":this.enabled&&e.docs.length&&this.insertClones(e.docs);break;case"copy":this.copy(e.ids);break;case"paste":this.paste()}}};function e$(e,t){(0,a.AZ)(e,t)}function eH(e,t){let i=null,o=null,r=()=>{null!==i&&(clearTimeout(i),i=null),o?.remove(),o=null},l=()=>{let i=t.text();if(!i)return;(o=e.ownerDocument.createElement("div")).textContent=i,o.style.cssText="position:absolute;z-index:var(--vela-z-tooltip);pointer-events:none;background:var(--vela-bg);border:1px solid var(--vela-border);color:var(--vela-fg);border-radius:var(--vela-radius-md);padding:4px 9px;box-shadow:var(--vela-shadow);font:var(--vela-font-size-md) var(--vela-font);"+(t.wrap?"max-width:260px;":"white-space:nowrap;"),e$(o,t.theme()),t.host.appendChild(o);let r=e.getBoundingClientRect(),l=t.host.getBoundingClientRect();if("right"===t.placement)o.style.left=`${r.right-l.left+8}px`,o.style.top=`${r.top-l.top+(r.height-o.offsetHeight)/2}px`;else{let e=Math.min(r.left-l.left,Math.max(0,l.width-o.offsetWidth-4));o.style.left=`${Math.max(0,e)}px`,o.style.top="above"===t.placement?`${Math.max(0,r.top-l.top-o.offsetHeight-6)}px`:`${r.bottom-l.top+6}px`}},n=e=>{"mouse"===e.pointerType&&(r(),i=window.setTimeout(l,t.delayMs??700))};return e.addEventListener("pointerenter",n),e.addEventListener("pointerleave",r),e.addEventListener("pointerdown",r),()=>{e.removeEventListener("pointerenter",n),e.removeEventListener("pointerleave",r),e.removeEventListener("pointerdown",r),r()}}function eW(e,t){let i,o=t.size??16;if(t.href){let e=document.createElement("a");e.href=t.href,e.target="_blank",e.rel="noopener noreferrer",i=e}else(i=document.createElement("span")).setAttribute("role","img");i.className="vela-hint",i.setAttribute("aria-label",e||t.label||""),i.innerHTML=(0,l.N0)(t.icon??"info",o),i.style.cssText=`flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:${o}px;height:${o}px;border-radius:50%;cursor:${t.href?"pointer":"help"};user-select:none;background:var(--vela-hover);color:var(--vela-fg-muted);transition:background var(--vela-dur-fast) ease,color var(--vela-dur-fast) ease;`;let r=e=>{i.style.background=e?"var(--vela-active)":"var(--vela-hover)",i.style.color=e?"var(--vela-fg-bright)":"var(--vela-fg-muted)"};i.addEventListener("pointerenter",()=>r(!0)),i.addEventListener("pointerleave",()=>r(!1));let n=eH(i,{host:t.host,theme:t.theme,text:()=>e,wrap:!0,delayMs:250});return{el:i,dispose:n}}var eq={cursor:(0,n.ab)("drawing.toolbar.cursor","Cursor"),measure:(0,n.ab)("drawing.toolbar.measure","Measure"),eraser:(0,n.ab)("drawing.toolbar.eraser","Eraser (click/drag to delete)"),stay:(0,n.ab)("drawing.toolbar.stay","Stay in drawing mode"),sync:(0,n.ab)("drawing.toolbar.sync","Sync drawings on all charts"),collapse:(0,n.ab)("drawing.toolbar.collapse","Collapse toolbar"),expand:(0,n.ab)("drawing.toolbar.expand","Expand toolbar"),removeFavorite:(0,n.ab)("drawing.toolbar.removeFavorite","Remove from favorites"),addFavorite:(0,n.ab)("drawing.toolbar.addFavorite","Add to favorites"),more:(0,n.ab)("drawing.toolbar.more","{tool} — more"),magnetSnap:(0,n.ab)("drawing.toolbar.magnetSnap","Magnet snap"),magnetOff:(0,n.ab)("drawing.toolbar.magnetSnapOff","Magnet snap: Off"),magnetWeak:(0,n.ab)("drawing.toolbar.magnetSnapWeak","Magnet snap: Weak"),magnetStrong:(0,n.ab)("drawing.toolbar.magnetSnapStrong","Magnet snap: Strong"),magnet:(0,n.ab)("drawing.toolbar.magnet","Magnet"),off:(0,n.ab)("drawing.toolbar.magnet.off","Off"),weak:(0,n.ab)("drawing.toolbar.magnet.weak","Weak"),strong:(0,n.ab)("drawing.toolbar.magnet.strong","Strong")},eU=class{constructor(e,t,i,o=()=>{},r=()=>{},l=()=>{},n=()=>{},a=()=>{},s={}){this.host=e,this.theme=t,this.onArm=i,this.onMagnet=o,this.onMeasure=r,this.onEraser=l,this.onToggleFavorite=n,this.onStayMode=a,this.def={groups:[]},this.active=null,this.lastUsed=new Map,this.favorites=new Set,this.shortcuts=new Map,this.starEls=new Map,this.flyout=null,this.flyoutOwnerId=null,this.flyoutCell=null,this.exitingFlyouts=new Map,this.groupCells=new Map,this.groupIcons=new Map,this.cursorBtn=null,this.magnetCell=null,this.magnetIcon=null,this.magnetMode="off",this.lastMagnetOn="weak",this.measureBtn=null,this.measureActive=!1,this.eraserBtn=null,this.eraserActive=!1,this.stayBtn=null,this.stayActive=!1,this.syncBtn=null,this.syncActive=!1,this.collapseBtn=null,this.collapsed=!1,this.visible=!1,this.tipText=new WeakMap,this.tipDisposers=[],this.onOutside=e=>{let t=e.target;!this.flyout||this.flyout.contains(t)||this.root.contains(t)||this.closeFlyout()},this.borderOverride=s.borderColor??null,this.width=s.width??44,this.dock=s.dock??"absolute",this.onCollapse=s.onCollapse??(()=>{}),this.onDrawingsSync=s.onDrawingsSync??null,this.i18n=s.i18n??null,function(){if("undefined"==typeof document)return;let e=document.getElementById(eG);e||((e=document.createElement("style")).id=eG,document.head.appendChild(e)),e.textContent=(0,d.AH)`@layer vela.chrome {
2
+
3
+ .vela-dtb-hit{width:22px;height:22px;display:flex;align-items:center;justify-content:center;border-radius:${c.t.radius.md};transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
4
+ .vela-dtb-hit--arrow{width:11px;height:22px;}
5
+ .vela-dtb-btn{position:relative;width:100%;height:30px;flex:none;display:flex;align-items:center;justify-content:center;cursor:pointer;color:inherit;background:transparent;border:none;padding:0;transition:color ${c.t.dur.fast} ease;}
6
+ .vela-dtb-btn:hover{color:${c.t.fg.bright};}
7
+ .vela-dtb-btn:hover .vela-dtb-hit{background:${c.t.hover};}
8
+ .vela-dtb-btn[data-active='1']{color:${c.t.fg.bright};}
9
+ .vela-dtb-btn[data-active='1'] .vela-dtb-hit{background:${c.t.active};}
10
+ .vela-dtb-cell{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;}
11
+ .vela-dtb-icon{flex:none;width:26px;height:30px;display:flex;align-items:center;justify-content:center;background:transparent;border:none;color:inherit;cursor:pointer;padding:0;transition:color ${c.t.dur.fast} ease;}
12
+ .vela-dtb-icon:hover{color:${c.t.fg.bright};}
13
+ .vela-dtb-cell[data-active='1'] .vela-dtb-icon{color:${c.t.fg.bright};}
14
+ .vela-dtb-cell[data-active='1'] .vela-dtb-icon .vela-dtb-hit{background:${c.t.active};}
15
+ .vela-dtb-arrow{position:absolute;inset-inline-end:1px;top:50%;transform:translateY(-50%);display:flex;align-items:center;justify-content:center;background:transparent;border:none;color:inherit;cursor:pointer;padding:0;opacity:0;pointer-events:none;transition:opacity ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
16
+ .vela-dtb-cell:hover .vela-dtb-arrow,.vela-dtb-icon:hover~.vela-dtb-arrow,.vela-dtb-cell.vela-open .vela-dtb-arrow{opacity:1;pointer-events:auto;}
17
+ .vela-dtb-arrow:hover{color:${c.t.fg.bright};}
18
+ .vela-dtb-icon:hover .vela-dtb-hit,.vela-dtb-arrow:hover .vela-dtb-hit{background:${c.t.hover};}
19
+ .vela-dtb-cell.vela-open .vela-dtb-arrow .vela-dtb-hit{background:${c.t.active};}
20
+ .vela-dtb-cell.vela-open .vela-dtb-arrow:hover .vela-dtb-hit{background:${c.t.hover};}
21
+ .vela-dtb-collapse{margin-top:auto;}
22
+ .vela-dtb[data-collapsed='1']>*:not(.vela-dtb-collapse){display:none;}
23
+ .vela-dtb[data-collapsed='1'] .vela-dtb-collapse .vela-dtb-hit{width:14px;}
24
+ .vela-dtb-item{background:transparent;border:none;transition:background ${c.t.dur.fast} ease;}
25
+ .vela-dtb-item:hover{background:${c.t.hover.strong};}
26
+ .vela-dtb-badge{width:24px;height:24px;padding:3px;box-sizing:border-box;display:flex;align-items:center;justify-content:center;flex:none;border-radius:${c.t.radius.md};background:${c.t.hover};border:1px solid ${c.t.border};color:${c.t.fg.muted};transition:background ${c.t.dur.fast} ease,border-color ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
27
+ .vela-dtb-badge:empty{background:transparent;border-color:transparent;}
28
+ .vela-dtb-badge svg{width:100%;height:100%;}
29
+ .vela-dtb-item:hover .vela-dtb-badge:not(:empty){background:${c.t.active};color:${c.t.fg.bright};}
30
+ .vela-dtb-item[data-selected='1'] .vela-dtb-badge:not(:empty){background:color-mix(in srgb,${c.t.fg.bright} 83%,${c.t.surface});border-color:color-mix(in srgb,${c.t.fg.bright} 40%,transparent);color:${c.t.surface};}
31
+ .vela-dtb-star{width:26px;height:22px;margin:-3px -5px -3px 0;padding:3px 5px;box-sizing:border-box;display:flex;align-items:center;justify-content:center;flex:none;opacity:0;color:inherit;border-radius:${c.t.radius.sm};transition:opacity .1s ease,color .1s ease,background .1s ease;}
32
+ .vela-dtb-star svg{width:16px;height:16px;}
33
+ .vela-dtb-item:hover .vela-dtb-star{opacity:.55;}
34
+ .vela-dtb-star:hover{opacity:1 !important;background:${c.t.hover.strong};}
35
+ .vela-dtb-star.vela-fav{opacity:.95;color:${c.t.highlight};}
36
+ }`}(),this.root=document.createElement("div"),this.root.className="vela-dtb",this.styleRoot(),e.appendChild(this.root)}t(e,t){return(0,n.b6)(this.i18n?.()??null,e,t)}relabel(){this.closeFlyout(),this.rebuild()}get borderColor(){return this.borderOverride??this.theme.borderColor}styleRoot(){let e=this.theme;e$(this.root,e);let t=this.collapsed?16:this.width;this.root.dataset.collapsed=this.collapsed?"1":"";let i="absolute"===this.dock?`position:absolute;left:0;top:0;height:100%;width:${t}px;z-index:21;`:`position:relative;height:100%;width:${t}px;flex:none;`;this.root.style.cssText=i+`display:${this.visible?"flex":"none"};flex-direction:column;gap:4px;padding:6px 0;box-sizing:border-box;background:${e.background};border-right:1px solid ${this.borderColor};color:var(--vela-fg-muted);pointer-events:auto;overflow-y:auto;overflow-x:hidden;`}setDefinition(e){for(let t of(this.def=e,e.groups)){let e=t.tools[0];e&&!this.lastUsed.has(t.id)&&this.lastUsed.set(t.id,e.type)}this.rebuild()}setFavorites(e){for(let[t,i]of(this.favorites=new Set(e),this.starEls))this.paintStar(i,t)}setShortcuts(e){this.shortcuts=new Map(Object.entries(e))}paintStar(e,t){let i=this.favorites.has(t);e.classList.toggle("vela-fav",i),e.setAttribute("aria-label",this.t(i?eq.removeFavorite:eq.addFavorite)),e.setAttribute("aria-pressed",i?"true":"false"),e.innerHTML=e4(i?e3:e5)}setVisible(e){this.visible=e,this.root.style.display=e?"flex":"none"}setActiveTool(e){if(this.active=e,e){let t=this.def.groups.find(t=>t.tools.some(t=>t.type===e));t&&(this.lastUsed.set(t.id,e),this.paintGroupIcon(t))}this.closeFlyout(),this.highlight()}setTheme(e){this.theme=e,this.styleRoot(),this.rebuild()}destroy(){for(let{exit:e}of(this.closeFlyout(),[...this.exitingFlyouts.values()]))e.finish();for(let e of this.tipDisposers.splice(0))e();this.root.remove()}rebuild(){for(let e of this.tipDisposers.splice(0))e();for(let e of(this.root.replaceChildren(),this.groupCells.clear(),this.groupIcons.clear(),this.cursorBtn=this.makeButton(eK,this.t(eq.cursor),()=>this.onCursorClick()),this.root.appendChild(this.cursorBtn),this.def.groups.length>0&&this.root.appendChild(this.divider()),this.def.groups)){let t=this.makeGroupCell(e);this.root.appendChild(t),this.paintGroupIcon(e)}this.root.appendChild(this.divider()),this.measureBtn=this.makeButton(eY,this.t(eq.measure),()=>this.onMeasure()),this.root.appendChild(this.measureBtn),this.eraserBtn=this.makeButton(e0,this.t(eq.eraser),()=>this.onEraser()),this.root.appendChild(this.eraserBtn),this.root.appendChild(this.makeMagnetCell()),this.stayBtn=this.makeButton(eQ,this.t(eq.stay),()=>this.toggleStay()),this.root.appendChild(this.stayBtn),this.onDrawingsSync&&(this.syncBtn=this.makeButton(eJ,this.t(eq.sync),()=>this.toggleDrawingsSync()),this.root.appendChild(this.syncBtn)),this.collapseBtn=this.makeButton(eZ,this.t(eq.collapse),()=>this.toggleCollapsed()),this.collapseBtn.classList.add("vela-dtb-collapse"),this.root.appendChild(this.collapseBtn),this.paintMeasure(),this.paintEraser(),this.paintMagnet(),this.paintStay(),this.paintDrawingsSync(),this.paintCollapse(),this.highlight()}toggleCollapsed(){this.collapsed=!this.collapsed,this.closeFlyout(),this.styleRoot(),this.paintCollapse(),this.onCollapse(this.collapsed)}paintCollapse(){let e=this.collapseBtn;if(!e)return;let t=this.t(this.collapsed?eq.expand:eq.collapse);e.innerHTML=e8(this.collapsed?eX:eZ,12),e.setAttribute("aria-label",t),this.tipText.set(e,t)}makeCell(e,t){let i=document.createElement("div");i.className="vela-dtb-cell";let o=document.createElement("button");o.type="button",o.className="vela-dtb-icon",o.setAttribute("aria-label",e),t.iconSvg&&(o.innerHTML=e8(t.iconSvg)),o.addEventListener("click",t.onIcon),i.appendChild(o);let r=null;if(t.multi&&t.onArrow){var l;let o=t.onArrow;(r=document.createElement("button")).type="button",r.className="vela-dtb-arrow",r.setAttribute("aria-label",this.t(eq.more,{tool:e})),r.innerHTML=(l=e1,`<span class="vela-dtb-hit vela-dtb-hit--arrow">${e6(l,11)}</span>`),r.addEventListener("click",e=>{e.stopPropagation(),o()}),i.appendChild(r)}return this.tipDisposers.push(eH(i,{host:this.host,theme:()=>this.theme,text:()=>this.tipText.get(i)??e,placement:"right"})),{cell:i,icon:o,arrow:r}}makeGroupCell(e){let t=e.tools.length>1,{cell:i,icon:o}=this.makeCell(this.t(e.label),{multi:t,onIcon:()=>this.onGroupIconClick(e),onArrow:t?()=>this.onArrowClick(e):void 0});return this.groupCells.set(e.id,i),this.groupIcons.set(e.id,o),i}makeMagnetCell(){let{cell:e,icon:t}=this.makeCell(this.t(eq.magnetSnap),{iconSvg:e_,multi:!0,onIcon:()=>this.toggleMagnet(),onArrow:()=>this.onMagnetArrowClick()});return this.magnetCell=e,this.magnetIcon=t,e}onCursorClick(){this.measureActive&&this.onMeasure(),this.eraserActive&&this.onEraser(),this.onArm(null)}onGroupIconClick(e){let t=this.lastUsed.get(e.id)??e.tools[0]?.type;t&&this.onArm(t)}onArrowClick(e){let t=this.flyoutOwnerId===e.id;this.closeFlyout(),t||this.openGroupFlyout(e)}toggleMagnet(){this.applyMagnet("off"===this.magnetMode?this.lastMagnetOn:"off")}onMagnetArrowClick(){let e=this.flyoutOwnerId===ej;this.closeFlyout(),e||this.openMagnetFlyout()}applyMagnet(e){this.magnetMode=e,"off"!==e&&(this.lastMagnetOn=e),this.onMagnet(e),this.paintMagnet(),this.highlight()}setMagnetMode(e){this.magnetMode=e,"off"!==e&&(this.lastMagnetOn=e),this.paintMagnet(),this.highlight()}setMeasureActive(e){this.measureActive=e,this.paintMeasure(),this.highlight()}paintMeasure(){let e=this.measureBtn;e&&(e.dataset.active=this.measureActive?"1":"")}setEraserActive(e){this.eraserActive=e,this.paintEraser(),this.highlight()}paintEraser(){let e=this.eraserBtn;e&&(e.dataset.active=this.eraserActive?"1":"")}paintMagnet(){let e=this.magnetCell,t=this.magnetIcon;if(!e||!t)return;this.tipText.set(e,this.t("off"===this.magnetMode?eq.magnetOff:"weak"===this.magnetMode?eq.magnetWeak:eq.magnetStrong));let i="off"!==this.magnetMode;e.dataset.active=i?"1":"",t.style.opacity=i?"1":"0.5"}toggleStay(){this.stayActive=!this.stayActive,this.onStayMode(this.stayActive),this.paintStay()}setStayMode(e){this.stayActive=e,this.paintStay()}paintStay(){let e=this.stayBtn;e&&(e.dataset.active=this.stayActive?"1":"",e.style.opacity=this.stayActive?"1":"0.5")}toggleDrawingsSync(){this.syncActive=!this.syncActive,this.onDrawingsSync?.(this.syncActive),this.paintDrawingsSync()}setDrawingsSyncMode(e){this.syncActive=e,this.paintDrawingsSync()}paintDrawingsSync(){let e=this.syncBtn;e&&(e.dataset.active=this.syncActive?"1":"",e.style.opacity=this.syncActive?"1":"0.5")}beginFlyout(e,t){let i=this.theme,o=this.exitingFlyouts.get(e);o&&(this.exitingFlyouts.delete(e),o.exit.cancel(),o.fly.replaceChildren());let r=o?.fly??document.createElement("div");r.className="vela-dtb-flyout",r.style.cssText=`position:absolute;z-index:23;display:flex;flex-direction:column;gap:2px;padding:4px;border-radius:var(--vela-radius-md);background:var(--vela-surface);border:1px solid ${this.borderOverride??"var(--vela-border-strong)"};box-shadow:var(--vela-shadow);pointer-events:auto;overflow-y:auto;overscroll-behavior:contain;`,e$(r,i),this.host.appendChild(r);let l=t.getBoundingClientRect(),n=this.root.getBoundingClientRect(),a=this.host.getBoundingClientRect(),s=l.top-a.top;return r.style.left=`${n.right-a.left+3}px`,r.style.top=`${s}px`,r.style.maxHeight=`${Math.max(120,a.height-s-8)}px`,this.flyout=r,this.flyoutOwnerId=e,this.flyoutCell=t,t.classList.add("vela-open"),this.highlight(),document.addEventListener("pointerdown",this.onOutside),r}openGroupFlyout(e){let t=this.groupCells.get(e.id);if(!t)return;let i=this.beginFlyout(e.id,t),o=e.sections??[{label:"",tools:e.tools}],r=o.some(e=>e.tools.some(e=>!!e.icon));for(let e=0;e<o.length;e++){let t=o[e];for(let o of(t.label&&(e>0&&i.appendChild(this.flyoutSeparator()),i.appendChild(this.flyoutHeader(this.t(t.label)))),t.tools))i.appendChild(this.makeFlyoutItem({icon:o.icon,badge:r,label:this.t(o.label),selected:o.type===this.active,shortcut:this.shortcuts.get(o.type),onSelect:()=>this.onArm(o.type),favorite:{type:o.type,toggle:()=>this.onToggleFavorite(o.type,!this.favorites.has(o.type))}}))}(0,s.$5)(i,!0,"menu",t)}openMagnetFlyout(){let e=this.magnetCell;if(!e)return;let t=this.beginFlyout(ej,e);for(let[e,i]of(t.appendChild(this.flyoutHeader(this.t(eq.magnet))),[["off",eq.off],["weak",eq.weak],["strong",eq.strong]]))t.appendChild(this.makeFlyoutItem({label:this.t(i),selected:e===this.magnetMode,onSelect:()=>{this.applyMagnet(e),this.closeFlyout()}}));(0,s.$5)(t,!0,"menu",e)}flyoutHeader(e){let t=this.theme,i=document.createElement("div");return i.textContent=(0,n.lb)(e,this.i18n?.().locale),i.style.cssText=`padding:6px 12px 2px 8px;font:var(--vela-font-size-sm) ${t.fontFamily};font-weight:600;letter-spacing:0.04em;color:var(--vela-fg-muted);user-select:none;`,i}flyoutSeparator(){let e=document.createElement("div");return e.style.cssText=`height:1px;margin:4px 8px;background:${this.borderColor};`,e}makeFlyoutItem(e){let t=this.theme,i=document.createElement("button");i.type="button",i.className="vela-dtb-item",i.setAttribute("aria-label",e.label);let o=!0===e.badge||!!e.icon;if(i.style.cssText=`display:flex;align-items:center;${o?"gap:10px;padding:4px 10px 4px 6px;":"gap:8px;padding:5px 10px 5px 8px;"}cursor:pointer;color:${t.textColor};border-radius:var(--vela-radius-sm);font:13px ${t.fontFamily};white-space:nowrap;min-width:148px;`,e.selected&&(i.dataset.selected="1"),o){let t=document.createElement("span");t.className="vela-dtb-badge",e.icon&&(t.innerHTML=e.icon),i.appendChild(t)}let r=document.createElement("span");r.textContent=e.label,r.style.cssText="flex:1 1 auto;text-align:left;",i.appendChild(r);let l=document.createElement("span");if(l.style.cssText="width:14px;height:14px;display:flex;align-items:center;justify-content:center;flex:none;",e.selected&&(l.innerHTML=e4(e2)),i.appendChild(l),e.shortcut){let o=document.createElement("span");o.className="vela-dtb-hint",o.textContent=e.shortcut,o.style.cssText=`flex:none;font:var(--vela-font-size-md) ${t.fontFamily};color:var(--vela-fg-muted);`,i.appendChild(o)}if(e.favorite){let t=document.createElement("span");for(let i of(t.className="vela-dtb-star",t.setAttribute("role","button"),this.paintStar(t,e.favorite.type),this.starEls.set(e.favorite.type,t),["pointerdown","pointerup","mousedown","mouseup"]))t.addEventListener(i,e=>e.stopPropagation());t.addEventListener("click",t=>{t.stopPropagation(),t.preventDefault(),e.favorite.toggle()}),i.appendChild(t)}return i.addEventListener("click",t=>{t.stopPropagation(),e.onSelect()}),i}closeFlyout(){this.starEls.clear();let e=this.flyout;if(e){this.flyout=null,(0,s.$5)(e,!1,"menu",this.flyoutCell);let t=this.flyoutOwnerId??"",i=(0,h.O)(e,()=>{this.exitingFlyouts.get(t)?.fly===e&&this.exitingFlyouts.delete(t),e.remove()});i&&this.exitingFlyouts.set(t,{fly:e,exit:i}),this.flyoutCell?.classList.remove("vela-open"),this.flyoutCell=null,this.flyoutOwnerId=null,document.removeEventListener("pointerdown",this.onOutside),this.highlight()}}paintGroupIcon(e){let t=this.groupIcons.get(e.id);if(!t)return;let i=this.lastUsed.get(e.id)??e.tools[0]?.type,o=e.tools.find(e=>e.type===i)??e.tools[0];t.innerHTML=e8(o?.icon??"");let r=this.groupCells.get(e.id);r&&this.tipText.set(r,this.t(o?.label??e.label))}highlight(){let e=this.active?this.def.groups.find(e=>e.tools.some(e=>e.type===this.active)):null;for(let[t,i]of this.groupCells){let o=t===e?.id;i.dataset.active=o?"1":""}this.cursorBtn&&(this.cursorBtn.dataset.active=null!=this.active||this.measureActive||this.eraserActive?"":"1"),this.paintMeasure(),this.paintEraser(),this.paintMagnet(),this.paintStay()}makeButton(e,t,i){let o=document.createElement("button");return o.type="button",o.className="vela-dtb-btn",o.setAttribute("aria-label",t),this.tipText.set(o,t),e&&(o.innerHTML=e8(e)),this.tipDisposers.push(eH(o,{host:this.host,theme:()=>this.theme,text:()=>this.tipText.get(o)??t,placement:"right"})),o.addEventListener("click",i),o}divider(){let e=document.createElement("div");return e.style.cssText=`width:24px;height:1px;margin:2px auto;flex:none;background:${this.borderColor};`,e}},ej="__magnet__",eG="vela-drawing-toolbar-styles",eK=(0,l.Kk)("cursor"),eY=(0,l.Kk)("ruler"),eZ=(0,l.Kk)("chevrons-left"),eX=(0,l.Kk)("chevrons-right"),e_=(0,l.Kk)("magnet"),eQ=(0,l.Kk)("pen-lock"),eJ=(0,l.Kk)("pen-sync"),e0=(0,l.Kk)("eraser"),e1=(0,l.Kk)("chevron-right"),e2=(0,l.Kk)("check"),e5=(0,l.Kk)("star"),e3=(0,l.Kk)("star-filled");function e4(e){return e.replace("<svg ",'<svg width="100%" height="100%" ')}function e6(e,t=18){return e?`<span style="width:${t}px;height:${t}px;display:flex;align-items:center;justify-content:center;">${e4(e)}</span>`:""}function e8(e,t=18){return`<span class="vela-dtb-hit">${e6(e,t)}</span>`}function e7(e,t,i=1e3){return!0===e?t:"number"!=typeof e||!Number.isFinite(e)||e<=0?0:Math.min(e,i)}function e9(e){return e7(e,90,1e3)}function te(e){if(!0===e)return{style:"settle",duration:650};if("settle"===e||"grow"===e)return{style:e,duration:650};if(e&&"object"==typeof e){let t=e.duration;return{style:"grow"===e.style?"grow":"settle",duration:"number"==typeof t&&Number.isFinite(t)&&t>0?Math.min(t,5e3):650}}return{style:!1,duration:0}}var tt=new Set(["a","abbr","b","blockquote","br","code","dd","del","div","dl","dt","em","h1","h2","h3","h4","h5","h6","hr","i","img","ins","kbd","li","mark","ol","p","pre","q","s","small","span","strong","sub","sup","table","tbody","td","tfoot","th","thead","tr","u","ul"]),ti=new Set(["script","style","iframe","frame","frameset","object","embed","applet","form","input","textarea","button","select","option","link","meta","base","svg","math","template","noscript","audio","video","canvas","dialog","head","title"]),to={a:new Set(["href"]),img:new Set(["src","alt","width","height"]),td:new Set(["colspan","rowspan"]),th:new Set(["colspan","rowspan"]),ol:new Set(["start"])},tr=new Set(["javascript","vbscript","data","file","blob"]);function tl(e,t=!1){let i="";for(let t of e)t.charCodeAt(0)>32&&(i+=t);let o=/^([a-z][a-z0-9+.-]*):/i.exec(i),r=o?o[1].toLowerCase():null;return null!==r&&tr.has(r)||t&&"http"!==r&&"https"!==r?null:i}var tn="Properties";function ta(e,t){return t.prop?e.propValues:e.values}var ts=["close","open","high","low","hl2","hlc3","ohlc4","volume"],th={cancel:(0,n.ab)("chart.indicatorSettings.cancel","Cancel"),ok:(0,n.ab)("chart.indicatorSettings.ok","OK"),resetDefaults:(0,n.ab)("chart.indicatorSettings.resetDefaults","Reset defaults"),close:(0,n.ab)("chart.indicatorSettings.close","Close"),inputsTab:(0,n.ab)("chart.indicatorSettings.inputsTab","Inputs"),propertiesTab:(0,n.ab)("chart.indicatorSettings.propertiesTab","Properties"),openTimeList:(0,n.ab)("chart.indicatorSettings.openTimeList","Open time list"),openCalendar:(0,n.ab)("chart.indicatorSettings.openCalendar","Open calendar"),selectSymbol:(0,n.ab)("chart.indicatorSettings.selectSymbol","Select symbol…"),help:(0,n.ab)("chart.indicatorSettings.help","Help"),noneChecked:(0,n.ab)("chart.indicatorSettings.noneChecked","None")},td=class{constructor(e){this.host=e,this.dialog=null,this.backdrop=null,this.uiDialog=null,this.openId=null,this.row=null,this.snapshot=null,this.propSnapshot=null,this.dialogTips=[],this.refreshVisibility=null,this.choicePop=null,this.calendarPop=null,this.calendarAnchor=null,this.onDialogKey=e=>{if("Escape"===e.key){let t=e.target?.closest('[role="dialog"]');if((!t||t===this.dialog)&&![...(this.dialog?.ownerDocument??document).querySelectorAll('[role="dialog"][data-state="open"]')].some(e=>e!==this.dialog&&(!this.dialog||!!(this.dialog.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING)))){if(e.preventDefault(),(0,f.KJ)())return void(0,f.$b)();this.close()}}}}get i18n(){return this.host.i18n?.()??null}t(e){return(0,n.b6)(this.i18n,e)}isOpen(){return null!==this.dialog}open(e){(0,T.z)(this.i18n,()=>this.build(e))}build(e){if(this.close(),0===e.inputs.length&&0===e.props.length)return;this.row=e,this.openId=e.id,this.snapshot={...e.values},this.propSnapshot={...e.propValues},tx();let t=this.host.theme(),i=this.host.dialogHost()??this.host.container,r=this.i18n,l=new v.lG({host:i,title:e.title,...r?{i18n:r}:{},modal:!1,contained:!0,align:"center",draggable:!this.host.mobile(),flush:!0,variant:"form",className:"vela-ind-dialog",closeOnEscape:!1,footer:e=>{e.append(this.resetAction(),this.dialogButton(this.t(th.cancel),!1,()=>this.revertAndClose()),this.dialogButton(this.t(th.ok),!0,()=>this.close()))},onOpenChange:e=>{e||this.uiDialog!==l||this.close()}});e$(l.panel,t),l.panel.style.colorScheme=this.isDarkTheme()?"dark":"light",this.dialogTips.push(eH(l.panel.querySelector(".vela-dialog-close"),{host:this.host.container,theme:()=>this.host.theme(),text:()=>this.t(th.close)}));let n=function(e){let t=new Map;for(let i of e){let e=i.tab&&i.tab.length>0?i.tab:tf;t.has(e)||t.set(e,[]),t.get(e).push(i)}let i=[...t.keys()];return i.includes(tf)&&(i.splice(i.indexOf(tf),1),i.unshift(tf)),i.map(e=>({name:e,inputs:t.get(e)}))}(e.inputs);if(e.props.length>0){let t=e.props.map(e=>{let t={...e,prop:!0};return delete t.tab,t}),i=n.find(e=>e.name===tn);i?i.inputs.push(...t):n.push({name:tn,inputs:t})}let a=[],s=[],h=[],d=e=>{a.forEach((t,i)=>{t.style.display=String(i)===e?"grid":"none"})},c=(0,C.fF)({variant:"line",className:"vela-ind-tabs",items:n.map((e,t)=>({value:String(t),label:this.tabLabel(e.name)})),onValueChange:d});for(let[t,i]of n.entries())a.push(this.buildTabBody(i.inputs,e,s)),i.inputs.every(e=>e.when)&&h.push({id:String(t),visible:e=>i.inputs.some(t=>(0,o.dxV)(t.when,e))});l.body.appendChild(c.el),a.forEach((e,t)=>{c.panel(String(t),e),l.body.appendChild(e)}),d(c.value??"0");let p=()=>{let t=function(e){let t={};for(let i of e.inputs)t[i.key]=e.values[i.key]??i.defval;return t}(e);for(let e of s)e.el.style.display=e.visible(t)?"":"none";for(let e of h)c.setHidden(e.id,!e.visible(t))};this.refreshVisibility=p,p();let u=e=>{if(e.target===l.backdrop||e.target===l.positioner){if((0,f.KJ)()||(0,f.fH)(e))return void(0,f.$b)();this.close(),this.host.onBackdropClose()}};l.backdrop.addEventListener("pointerdown",u),l.positioner.addEventListener("pointerdown",u),this.uiDialog=l,this.dialog=l.panel,this.backdrop=l.backdrop,l.show(),document.addEventListener("keydown",this.onDialogKey)}buildTabBody(e,t,i){let o=document.createElement("div");for(let r of(o.style.cssText=function(e){let t=(0,k.ix)("inputs",e);return`padding:16px 20px;overflow-y:auto;overflow-x:hidden;overflow-anchor:none;flex:1 1 auto;display:grid;grid-template-columns:${t};align-items:center;align-content:start;column-gap:${tb}px;row-gap:${tb}px;`}(this.host.mobile()),function(e){let t=[],i=new Map;for(let o of e){let e=o.group&&o.group.length>0?o.group:null;i.has(e)||(i.set(e,[]),t.push(e)),i.get(e).push(o)}return t.map(e=>{let t=i.get(e),o=t.find(e=>e.display?.group)?.display?.group,r=t.find(e=>e.groupHelp)?.groupHelp,l=[],n=new Map;for(let e of t){let t=e.inline&&e.inline.length>0?e.inline:null;t&&n.has(t)?l[n.get(t)].push(e):(t&&n.set(t,l.length),l.push([e]))}return{name:e,...o?{label:o}:{},...r?{help:r}:{},rows:l}})}(e))){let e=document.createElement("div");e.style.cssText="display:contents;";let l=null;for(let n of(r.name&&(l=(0,k.uJ)(r.label?this.t(r.label):r.name,{variant:"inputs",first:0===o.childElementCount,info:r.help?this.groupHelpMark(r.help):void 0}),e.appendChild(l)),r.rows)){let o=this.buildInputRow(e,n,t);n.some(e=>e.when)&&i.push({el:o,visible:e=>tv(n,e)})}if(l&&r.rows.every(e=>e.every(e=>e.when))){let e=r.rows;i.push({el:l,visible:t=>e.some(e=>tv(e,t))})}o.appendChild(e)}return o}close(){for(let e of(document.removeEventListener("keydown",this.onDialogKey),(0,f.$b)(),this.refreshVisibility=null,this.choicePop=null,this.calendarPop=null,this.calendarAnchor=null,this.dialogTips.splice(0)))e();let e=this.uiDialog;this.uiDialog=null,this.backdrop=null,this.dialog=null,this.openId=null,this.row=null,this.snapshot=null,this.propSnapshot=null,e?.destroy()}revertAndClose(){let e=this.row,t=this.snapshot;if(e&&t)for(let i of e.inputs){let o=t[i.key],r=void 0!==o?o:i.defval;e.values[i.key]!==r&&(e.values[i.key]=r,this.host.onChange?.({indicatorId:e.id,key:i.key,value:r}))}let i=this.propSnapshot;if(e&&i)for(let t of e.props){let o=i[t.key],r=void 0!==o?o:t.defval;e.propValues[t.key]!==r&&(e.propValues[t.key]=r,this.host.onChange?.({indicatorId:e.id,key:t.key,value:r,kind:"prop"}))}this.close()}resetAction(){let e=this.dialogButton(this.t(th.resetDefaults),!1,()=>this.resetToDefaults());return e.style.marginRight="auto",e}resetToDefaults(){let e=this.row;if(!e)return;let t=this.snapshot,i=this.propSnapshot;for(let t of e.inputs)e.values[t.key]!==t.defval&&(e.values[t.key]=t.defval,this.host.onChange?.({indicatorId:e.id,key:t.key,value:t.defval}));for(let t of e.props)e.propValues[t.key]!==t.defval&&(e.propValues[t.key]=t.defval,this.host.onChange?.({indicatorId:e.id,key:t.key,value:t.defval,kind:"prop"}));this.open(e),t&&(this.snapshot=t),i&&(this.propSnapshot=i)}commit(e,t,i){ta(e,t)[t.key]=i,this.host.onChange?.({indicatorId:e.id,key:t.key,value:i,...t.prop?{kind:"prop"}:{}}),this.refreshVisibility?.()}buildInputRow(e,t,i){let o=e=>`vela-inp-${i.id}-${e.key}`,r=t=>(e.appendChild(t),t);if(t.length>1)return r((0,k.h0)({label:"",inline:t.map(e=>({label:tm(e,this.i18n)||void 0,id:o(e),control:this.buildControl(i,e,o(e)),toggleFirst:"bool"===e.type,fit:tu(e)})),info:[...t].reverse().find(e=>e.tooltip)?.tooltip?this.infoButton(this.tooltipOf([...t].reverse().find(e=>e.tooltip))):void 0}));let l=t[0],n=o(l),a=l.tooltip?this.infoButton(this.tooltipOf(l)):void 0;if("bool"===l.type){let e=!!(ta(i,l)[l.key]??l.defval);return r((0,k.h0)({label:tm(l,this.i18n),id:n,bool:!0,info:a,toggle:{id:n,checked:e,onChange:e=>this.commit(i,l,e)}}))}if("text_area"===l.type)return r((0,k.h0)({label:tm(l,this.i18n),id:n,stacked:!0,info:a,control:this.buildControl(i,l,n)}));let s=tu(l),h=s?void 0:"symbol"===l.type?tp:tc;return r((0,k.h0)({label:tm(l,this.i18n),id:n,fit:s,controlWidth:h,info:a,control:this.buildControl(i,l,n)}))}buildControl(e,t,i){let o=ta(e,t)[t.key]??t.defval,r=i=>this.commit(e,t,i);if("bool"===t.type)return(0,k.yF)({kind:"switch",id:i,checked:!!o,onChange:e=>r(e)}).el;if(t.options&&t.options.length>0){let e=t.display?.options,l=t.options.map(t=>{let i=String(t),o=e?.[i];return{value:i,label:o?this.t(o):i}});return t.multiple&&"string"===t.type?this.buildMultiSelect(i,t,l,o,r):this.selectPairs(i,l,String(o),r)}return"source"===t.type?this.select(i,ts,String(o),r):"color"===t.type?(0,k.yF)({kind:"color",id:i,theme:this.host.theme(),get:()=>String(ta(e,t)[t.key]??t.defval),onChange:e=>r(e),commit:"release"}).el:"symbol"===t.type?this.buildSymbol(i,String(o),r):"timeframe"===t.type?this.selectPairs(i,tT.map(e=>({value:e.value,label:this.t(e.label)})),String(o),r):"session"===t.type?this.buildSession(i,String(o),r):"time"===t.type?this.buildTime(i,Number(o)||0,r):"text_area"===t.type?(0,k.yF)({kind:"textarea",id:i,value:String(o),onChange:e=>r(e)}).el:"int"===t.type||"float"===t.type||"price"===t.type?(0,k.yF)({kind:"number",id:i,value:Number(o),min:t.min,max:t.max,step:t.step??("int"===t.type?1:.1),integer:"int"===t.type,commit:"blur",onChange:e=>r(e)}).el:this.buildTextField(i,String(o),r)}buildTextField(e,t,i){return(0,k.yF)({kind:"text",id:e,value:t,onChange:i}).el}tooltipOf(e){return e.display?.tooltip?this.t(e.display.tooltip):e.tooltip??""}tabLabel(e){return e===tf?this.t(th.inputsTab):e===tn?this.t(th.propertiesTab):e}infoButton(e){let{el:t,dispose:i}=eW(e,{host:this.host.container,theme:()=>this.host.theme(),size:18});return this.dialogTips.push(i),t}groupHelpMark(e){let t=e.text?this.t(e.text):"",i=e.url?tl(e.url,!0)??void 0:void 0;if(!t&&!i)return;let{el:o,dispose:r}=eW(t,{host:this.host.container,theme:()=>this.host.theme(),size:16,icon:"help",href:i,label:this.t(th.help)});return this.dialogTips.push(r),o}select(e,t,i,o){return this.selectPairs(e,t.map(e=>({value:e,label:e})),i,o)}selectPairs(e,t,i,o){return tg((0,k.yF)({kind:"select",id:e,options:t,value:i,theme:this.host.theme(),list:this.listPopover(),onChange:o}).el,t.map(e=>e.label),this.host.mobile())}buildMultiSelect(e,t,i,r,n){let a=t.multiple?.separator??"",s=new Set(t.multiple?.locked??[]),h=new Map(i.map(e=>[e.value,e.label])),d=(0,o.cGA)(t,r),c=document.createElement("button");c.type="button",c.id=e,c.className="vela-ind-multi-trigger",c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false");let p=document.createElement("span");p.className="vela-ind-multi-value";let u=document.createElement("span");u.className="vela-ind-multi-chevron",u.innerHTML=(0,l.N0)("chevron-down",12),c.append(p,u);let g=()=>{let e=d.map(e=>h.get(e)??e).join(a);p.textContent=e||this.t(th.noneChecked),p.toggleAttribute("data-placeholder",""===e)};g();let m=()=>{let r=[],l=new f.AM({trigger:c,theme:this.host.theme(),matchWidth:!0,collisionBoundary:this.dialog??"viewport",boundaryInset:8,sideOffset:4,className:"vela-ind-multi",onClose:()=>{c.setAttribute("aria-expanded","false");let e=document.activeElement;for(let t of((!e||e===document.body||l.el.contains(e))&&c.focus({preventScroll:!0}),r.splice(0)))t.destroy()},content:a=>{a.setAttribute("role","group"),document.getElementById(`${e}--title`)&&a.setAttribute("aria-labelledby",`${e}--title`),i.forEach((i,l)=>{let h=`${e}-opt-${l}`,c=document.createElement("div");c.className="vela-ind-multi-row",s.has(i.value)&&(c.dataset.locked="");let p=new w.Sc({id:h,checked:d.includes(i.value),disabled:s.has(i.value),onCheckedChange:e=>((e,i)=>{let r=new Set(d);i?r.add(e):r.delete(e);let l=(0,o.hri)(t,r);d=(0,o.cGA)(t,l),g(),n(l)})(i.value,e)});r.push(p);let u=document.createElement("label");u.className="vela-ind-multi-label",u.htmlFor=h,u.textContent=i.label,c.append(p.el,u),c.addEventListener("click",e=>{e.target===c&&c.querySelector("input")?.click()}),a.appendChild(c)}),a.addEventListener("keydown",e=>{let t=[...a.querySelectorAll("input:not(:disabled)")],i=t.indexOf(document.activeElement),o=i=>{e.preventDefault();let o=t[(i+t.length)%t.length];o?.focus({preventScroll:!0}),o?.closest(".vela-ind-multi-row")?.scrollIntoView?.({block:"nearest"})};"ArrowDown"===e.key?o(i+1):"ArrowUp"===e.key?o(i<0?-1:i-1):"Home"===e.key?o(0):"End"===e.key?o(-1):"Enter"===e.key&&i>=0?(e.preventDefault(),t[i].click()):"Tab"===e.key&&l.hide()})}});l.show(),c.setAttribute("aria-expanded","true"),l.el.querySelector("input:not(:disabled)")?.focus({preventScroll:!0})};return c.addEventListener("pointerdown",e=>{e.preventDefault(),c.focus({preventScroll:!0})}),c.addEventListener("click",e=>{e.stopPropagation(),(0,f.s0)()===c?(0,f.$b)():m()}),c.addEventListener("keydown",e=>{("ArrowDown"===e.key||"ArrowUp"===e.key)&&(0,f.s0)()!==c&&(e.preventDefault(),m())}),tg(c,[i.map(e=>e.label).join(a)],this.host.mobile())}buildSession(e,t,i){let[o,r]=function(e){let t=/^(\d{2})(\d{2})-(\d{2})(\d{2})$/.exec(e.trim());return t?[`${t[1]}:${t[2]}`,`${t[3]}:${t[4]}`]:["09:00","16:00"]}(t),l=document.createElement("div");l.style.cssText="display:flex;align-items:center;gap:6px;flex:none;";let n=o,a=r,s=()=>{var e,t;return i((e=n,t=a,`${e.replace(":","")}-${t.replace(":","")}`))};return l.append(this.timeCombobox(e,n,86,e=>{n=e,s()}),this.timeCombobox(`${e}-end`,a,86,e=>{a=e,s()})),l}buildTime(e,t,i){let o=function(e){if(!e)return{date:"",time:"09:30"};let t=new Date(e<1e12?1e3*e:e);if(Number.isNaN(t.getTime()))return{date:"",time:"09:30"};let i=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,o=30*Math.round((60*t.getHours()+t.getMinutes())/30),r=String(Math.floor(o/60)%24).padStart(2,"0"),l=String(o%60).padStart(2,"0");return{date:i,time:`${r}:${l}`}}(t),r=document.createElement("div");r.style.cssText="display:flex;align-items:center;gap:6px;flex:none;";let l=o.date,n=o.time,a=()=>{if(!l)return;let e=Date.parse(`${l}T${n}:00`);Number.isFinite(e)&&i(e)},s=this.dateField(e,l,e=>{l=e,a()}),h=this.timeCombobox(`${e}-time`,n,86,e=>{n=e,a()});return r.append(s,h),r}timeCombobox(e,t,i,o){let r=document.createElement("div");r.className="vela-ind-combo",r.style.cssText=`position:relative;width:${i}px;flex:none;`;let l=document.createElement("input");l.type="text",l.id=e,l.value=t,l.autocomplete="off",l.spellcheck=!1,l.style.cssText=`${this.ctrlStyle()}padding-right:26px;`;let n=document.createElement("button");n.type="button",n.tabIndex=-1,n.className="vela-ind-combo-chevron",n.setAttribute("aria-label",this.t(th.openTimeList)),n.innerHTML=tw;let a=t,s=()=>{let e=function(e){let t=e.trim(),i=/^(\d{1,2}):(\d{2})$/.exec(t)??/^(\d{2})(\d{2})$/.exec(t);if(!i)return null;let o=Number(i[1]),r=Number(i[2]);return o>23||r>59?null:`${String(o).padStart(2,"0")}:${String(r).padStart(2,"0")}`}(l.value);if(!e){l.value=a;return}l.value=e,e!==a&&(a=e,o(e))};l.addEventListener("blur",()=>{(0,f.KJ)()||s()});let h=e=>{a=e,l.value=e,o(e)},d=()=>{this.choicePop=(0,b.Zm)(r,tM,a,h,{...this.listPopover(),onClose:()=>{this.choicePop=null}})};l.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),s(),l.blur()),"ArrowDown"===e.key&&(e.preventDefault(),d())});let c=e=>{e.preventDefault(),e.stopPropagation(),d()};return l.addEventListener("click",c),n.addEventListener("mousedown",e=>e.preventDefault()),n.addEventListener("click",c),r.append(l,n),r}dateField(e,t,i){let o=document.createElement("div");o.className="vela-ind-combo",o.style.cssText="position:relative;width:128px;flex:none;";let r=document.createElement("input");r.type="text",r.id=e,r.value=t,r.autocomplete="off",r.spellcheck=!1,r.style.cssText=`${this.ctrlStyle()}padding-right:26px;`;let l=document.createElement("button");l.type="button",l.tabIndex=-1,l.className="vela-ind-combo-chevron",l.setAttribute("aria-label",this.t(th.openCalendar)),l.innerHTML=ty;let n=t,a=()=>{let e=(0,x.eq)(r.value);if(!e){r.value=n;return}r.value=e,e!==n&&(n=e,i(e))};r.addEventListener("blur",()=>{(0,f.KJ)()||a()});let s=e=>{n=e,r.value=e,i(e)};r.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),a(),r.blur()),"ArrowDown"===e.key&&(e.preventDefault(),this.openCalendar(o,n,s))});let h=e=>{if(e.preventDefault(),e.stopPropagation(),(0,f.s0)()===o)return void(0,f.$b)();this.openCalendar(o,n,s)};return r.addEventListener("click",h),l.addEventListener("mousedown",e=>e.preventDefault()),l.addEventListener("click",h),o.append(r,l),o}listPopover(){return{theme:this.host.theme(),matchWidth:!0,collisionBoundary:this.dialog??"viewport",boundaryInset:8,sideOffset:4}}openCalendar(e,t,i){let o=new f.AM({trigger:e,theme:this.host.theme(),className:"vela-ind-cal",collisionBoundary:this.dialog??"viewport",boundaryInset:8,sideOffset:4,onClose:()=>{this.calendarPop=null,this.calendarAnchor=null},content:e=>{let r=new x.lr({value:t,i18n:this.host.i18n?.()??void 0,onPick:e=>{o.hide(),i(e)}});e.append(r.el)}});this.calendarPop=o,this.calendarAnchor=e,o.show()}buildSymbol(e,t,i){let o=this.host.symbolPicker();if(!o)return this.buildTextField(e,t,i);let r=t,l=document.createElement("button");l.type="button",l.id=e,l.style.cssText=`${this.ctrlStyle()}display:flex;align-items:center;cursor:pointer;text-align:left;`;let n=document.createElement("span"),a=()=>{n.textContent=r||this.t(th.selectSymbol),n.style.color=r?"":"var(--vela-fg-muted)"};return n.style.cssText="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;",a(),l.append(n),l.addEventListener("click",()=>o(r,e=>{e&&(r=e,a(),i(e))})),l}ctrlStyle(){return"width:100%;box-sizing:border-box;height:34px;background:transparent;border:1px solid var(--vela-border-strong);color:var(--vela-fg-bright);border-radius:6px;padding:0 8px;font-size:14px;font-family:inherit;outline:none;"}isDarkTheme(){return(0,p.cP)(this.host.theme().background)}dialogButton(e,t,i){return(0,y.Tf)({text:e,variant:t?"default":"outline",onClick:i}).el}},tc=100,tp=160;function tu(e){return"bool"!==e.type&&((e.options?.length??0)>0||"source"===e.type||"timeframe"===e.type)||"color"===e.type||"bool"===e.type||"session"===e.type||"time"===e.type}function tg(e,t,i){let o=document.createElement("div");o.className="vela-ind-hug",i&&(o.dataset.mobile="");let r=document.createElement("div");for(let e of(r.className="vela-ind-hug-sizer",r.setAttribute("aria-hidden","true"),t)){let t=document.createElement("span");t.textContent=e,r.appendChild(t)}return o.append(e,r),o}function tm(e,t){let i=e.display?.title?(0,n.b6)(t,e.display.title):e.title;return i.length>0?i.charAt(0).toUpperCase()+i.slice(1):""}var tb=k.Rq,tf="Inputs";function tv(e,t){return e.some(e=>(0,o.dxV)(e.when,t))}var ty=(0,l.N0)("calendar",14),tw=(0,l.N0)("clock",14),tC="vela-ind-dialog-styles";function tx(){if("undefined"==typeof document)return;let e=document.getElementById(tC);if(e?.dataset.rev==="31")return;let t=e??document.createElement("style");t.id=tC,t.dataset.rev="31",t.textContent=(0,d.AH)`@layer vela.chrome {
37
+
38
+ .vela-ind-combo input{${S.QL}}
39
+ .vela-ind-combo input:hover{border-color:${c.t.fg.muted};}
40
+ .vela-ind-combo input:focus{${S.XS}}
41
+ .vela-ind-combo-chevron{position:absolute;inset-inline-end:0;top:0;bottom:0;width:26px;border:none;background:transparent;color:inherit;opacity:0.55;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0;}
42
+ .vela-ind-combo-chevron:hover{opacity:0.9;}
43
+ .vela-ind-cal{background:${c.t.bg};color:${c.t.fg};border:none;border-radius:${c.t.radius.md};box-shadow:${c.t.shadow};font:14px ${c.t.font};padding:10px 12px;user-select:none;}
44
+ ${(0,S.u9)(".vela-dialog.vela-ind-dialog *")}
45
+ .vela-ind-tabs{padding:0 20px;flex:0 0 auto;}
46
+ .vela-ind-tabs>.vela-tab:only-child{cursor:default;}
47
+ .vela-ind-ctl,.vela-ind-close{background-color:transparent;color:inherit;transition:color ${c.t.dur.fast} ease,background-color ${c.t.dur.fast} ease;}
48
+ .vela-ind-ctl svg,.vela-ind-close svg{width:${16}px;height:${16}px;display:block;flex:none;stroke-width:1;}
49
+ .vela-ind-ctl:hover{background-color:${c.t.hover.strong};}
50
+ .vela-ind-close:hover{color:${c.t.danger} !important;background-color:${c.t.hover.strong};}
51
+ .vela-ind-fold{transition:border-color ${c.t.dur.fast} ease,opacity ${c.t.dur.fast} ease;}
52
+ .vela-ind-fold:hover{border-color:${c.t.border.strong};opacity:0.9;}
53
+ .vela-ind-hug{display:grid;grid-template-columns:minmax(0,1fr);min-width:${tc}px;}
54
+ .vela-ind-hug[data-mobile]{max-width:50vw;}
55
+ .vela-ind-hug-sizer{visibility:hidden;height:0;overflow:hidden;font-size:14px;}
56
+ .vela-ind-hug-sizer>span{display:block;height:0;white-space:nowrap;padding-inline:8px 26px;border-inline:1px solid transparent;}
57
+ .vela-ind-multi-trigger{position:relative;display:flex;align-items:center;width:100%;min-width:0;box-sizing:border-box;height:34px;padding-block:0;padding-inline:8px 26px;background:transparent;border:1px solid ${c.t.border.strong};border-radius:${c.t.radius.md};color:${c.t.fg.bright};font-size:14px;font-family:inherit;cursor:pointer;text-align:start;${S.QL}}
58
+ .vela-ind-multi-trigger:hover{border-color:${c.t.fg.muted};}
59
+ .vela-ind-multi-trigger:focus{${S.XS}}
60
+ .vela-ind-multi-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
61
+ .vela-ind-multi-value[data-placeholder]{color:${c.t.fg.muted};}
62
+ .vela-ind-multi-chevron{position:absolute;inset-inline-end:8px;top:50%;transform:translateY(-50%);display:flex;opacity:0.55;line-height:0;pointer-events:none;}
63
+ .vela-ind-multi{background:${c.t.bg};color:${c.t.fg};border-radius:${c.t.radius.md};box-shadow:${c.t.shadow};font:14px ${c.t.font};padding:4px;max-height:min(280px,50vh);overflow-y:auto;user-select:none;}
64
+ ${(0,S.u9)(".vela-ind-multi")}
65
+ .vela-ind-multi-row{display:flex;align-items:center;gap:10px;padding-inline-start:10px;border-radius:${c.t.radius.sm};white-space:nowrap;cursor:pointer;}
66
+ .vela-ind-multi-row:hover,.vela-ind-multi-row:has([data-focus-visible]){background:${c.t.hover};}
67
+ .vela-ind-multi-label{flex:1;padding-block:7px;padding-inline:0 10px;cursor:inherit;}
68
+ .vela-ind-multi-row[data-locked]{cursor:default;}
69
+ .vela-ind-multi-row[data-locked]:hover{background:transparent;}
70
+ .vela-ind-multi-row[data-locked] .vela-ind-multi-label{color:${c.t.fg.muted};}
71
+ }`,e||document.head.appendChild(t)}var tk=(0,n.ab)("chart.indicatorSettings.timeframe.minutes","{count, plural, one {# minute} other {# minutes}}"),tS=(0,n.ab)("chart.indicatorSettings.timeframe.hours","{count, plural, one {# hour} other {# hours}}"),tT=[{value:"",label:(0,n.ab)("chart.indicatorSettings.timeframe.chart","Chart")},{value:"1",label:(0,n.tV)(tk,{count:1})},{value:"3",label:(0,n.tV)(tk,{count:3})},{value:"5",label:(0,n.tV)(tk,{count:5})},{value:"15",label:(0,n.tV)(tk,{count:15})},{value:"30",label:(0,n.tV)(tk,{count:30})},{value:"45",label:(0,n.tV)(tk,{count:45})},{value:"60",label:(0,n.tV)(tS,{count:1})},{value:"120",label:(0,n.tV)(tS,{count:2})},{value:"180",label:(0,n.tV)(tS,{count:3})},{value:"240",label:(0,n.tV)(tS,{count:4})},{value:"D",label:(0,n.ab)("chart.indicatorSettings.timeframe.day","1 day")},{value:"W",label:(0,n.ab)("chart.indicatorSettings.timeframe.week","1 week")},{value:"M",label:(0,n.ab)("chart.indicatorSettings.timeframe.month","1 month")}],tM=Array.from({length:48},(e,t)=>{let i=String(Math.floor(t/2)).padStart(2,"0"),o=`${i}:${t%2==0?"00":"30"}`;return{value:o,label:o}}),tL=(0,d.AH)`@layer vela.chrome {
72
+ @keyframes vela-ind-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.3;transform:scale(.6)}}
73
+ }`,tA="cursor:pointer;display:inline-flex;align-items:center;justify-content:center;border:none;line-height:0;padding:0;width:18px;height:18px;border-radius:3px;box-sizing:border-box;flex:none;",tP={moveToMainChart:(0,n.ab)("chart.legend.moveToMainChart","Move to main chart"),moveToPane:(0,n.ab)("chart.legend.moveToPane","Move to {pane}"),newPaneAbove:(0,n.ab)("chart.legend.newPaneAbove","New panel above"),newPaneBelow:(0,n.ab)("chart.legend.newPaneBelow","New panel below"),indicatorValues:(0,n.ab)("chart.legend.indicatorValues","Indicator values"),bringInFrontOfPrice:(0,n.ab)("chart.legend.bringInFrontOfPrice","Bring in front of price"),bringInFrontOf:(0,n.ab)("chart.legend.bringInFrontOf","Bring in front of {indicator}"),bringInFrontOfNext:(0,n.ab)("chart.legend.bringInFrontOfNext","Bring in front of the indicator in front"),sendBehindPrice:(0,n.ab)("chart.legend.sendBehindPrice","Send behind price"),sendBehind:(0,n.ab)("chart.legend.sendBehind","Send behind {indicator}"),sendBehindNext:(0,n.ab)("chart.legend.sendBehindNext","Send behind the indicator behind"),indicators:(0,n.ab)("chart.legend.indicators","Indicators"),showLegend:(0,n.ab)("chart.legend.showLegend","Show indicator legend"),hideLegend:(0,n.ab)("chart.legend.hideLegend","Hide indicator legend"),beta:(0,n.ab)("chart.legend.beta","beta"),hide:(0,n.ab)("chart.legend.hide","Hide"),show:(0,n.ab)("chart.legend.show","Show"),settings:(0,n.ab)("chart.legend.settings","Settings"),moveToPaneButton:(0,n.ab)("chart.legend.moveToPaneButton","Move to panel"),remove:(0,n.ab)("chart.legend.remove","Remove indicator")},tI="stack:raise",tE="stack:lower",tB=(0,l.N0)("eye",16),tF=(0,l.N0)("eye-off",16),tO=(0,l.N0)("gear",16),tR=(0,l.N0)("close",16),tN=(0,l.N0)("chevron-up",16),tz=(0,l.N0)("chevron-down",16),tV=(0,l.N0)("objects",16);function tD(e,t){return!e&&t?"inline-flex":"none"}var t$=class{constructor(e,t,i){this.container=e,this.theme=t,this.paneBoundsOf=i,this.legends=new Map,this.rows=new Map,this.selectedId=null,this.onChange=null,this.onRemove=null,this.onToggleVisible=null,this.symbolPicker=null,this.mobileLayout=!1,this.moveApi=null,this.stackApi=null,this.rowOrderKey="",this.legendActions=null,this.legendCallouts=null,this.rowTips=new Map,this.extrasTips=new Map,this.calloutTips=new Map,this.moveMenu=null,this.moveTargets=[],this.moveMenuId=null,this.paneCollapse=new Map,this.legendFolded=!1,this.titlesVisible=!0,this.valuesVisible=!0,this.foldToggle=null,this.overviewAction=null,this.onDocClick=e=>{if(!this.selectedId)return;let t=e.target;if(t){for(let e of this.rows.values())if(e.el.contains(t))return}this.clearSelection()},this.dialogHost=null,this.i18n=null,e.style.position||(e.style.position="relative"),"undefined"!=typeof document&&document.addEventListener("click",this.onDocClick),tx(),this.inputsDialog=new td({container:e,theme:()=>this.theme,mobile:()=>this.mobileLayout,dialogHost:()=>this.dialogHost,symbolPicker:()=>this.symbolPicker,i18n:()=>this.i18n,onChange:e=>this.onChange?.(e),onBackdropClose:()=>this.clearSelection()})}setI18n(e){this.i18n=e,this.relabel()}t(e,t){return(0,n.b6)(this.i18n,e,t)}relabel(){for(let e of this.rows.values()){e.eyeEl?.setAttribute("aria-label",this.t(e.hidden?tP.show:tP.hide));let t=(t,i)=>e.el.querySelector(`[data-vela-ctl="${t}"]`)?.setAttribute("aria-label",this.t(i));t("settings",tP.settings),t("move",tP.moveToPaneButton),t("remove",tP.remove);let i=e.el.querySelector('[data-vela-ctl="beta"]');i&&(i.textContent=this.t(tP.beta))}this.foldToggle&&this.foldToggle.setAttribute("aria-label",this.foldLabel())}foldLabel(){return this.t(null!==this.overviewAction?tP.indicators:this.legendFolded?tP.showLegend:tP.hideLegend)}setDialogHost(e){this.dialogHost=e,e&&"static"===getComputedStyle(e).position&&(e.style.position="relative")}setLayoutMode(e){let t="mobile"===e;if(t!==this.mobileLayout&&(this.mobileLayout=t,null===this.overviewAction&&(this.legendFolded=t),this.syncFoldToggle(),null!==this.inputsDialog.openId)){let e=this.inputsDialog.openId;this.closeOpenDialog(),this.openDialog(e)}}setLegendOverviewAction(e){e!==this.overviewAction&&(this.overviewAction=e,this.legendFolded=null!==e||this.mobileLayout,this.syncFoldToggle())}openSettingsFor(e){this.rows.has(e)&&this.openDialog(e)}tip(e,t,i,o,r=!1){let l=e.get(t)??[];l.push(eH(i,{host:this.container,theme:()=>this.theme,text:"function"==typeof o?o:()=>o,wrap:r})),e.set(t,l)}disposeTips(e,t){for(let i of e.get(t)??[])i();e.delete(t)}setOnChange(e){this.onChange=e}setOnRemove(e){this.onRemove=e}setOnToggleVisible(e){this.onToggleVisible=e}setTheme(e){for(let t of(this.theme=e,this.legends.values()))e$(t,e);for(let t of this.rows.values())t.el.style.background=t.highlighted?e.background:this.idleRowFill(),t.el.style.color=e.textColor;this.foldToggle&&this.syncFoldToggle()}setSymbolPicker(e){this.symbolPicker=e}setMoveApi(e){this.moveApi=e}setStackApi(e){this.stackApi=e}setLegendActions(e){for(let t of(this.legendActions=e,this.rows.values()))this.renderExtras(t.id,t.extrasEl)}renderExtras(e,t){for(let i of(this.disposeTips(this.extrasTips,e),t.replaceChildren(),this.legendActions?.(e)??[])){let o=document.createElement("button");o.type="button",o.setAttribute("aria-label",i.tooltip),this.tip(this.extrasTips,e,o,i.tooltip),o.innerHTML=(0,l.N0)(i.icon,16),o.className="vela-ind-ctl",o.dataset.legendAction=i.id,o.style.cssText=tA,o.addEventListener("click",e=>{e.stopPropagation(),i.run()}),t.appendChild(o)}}setLegendCallouts(e){for(let t of(this.legendCallouts=e,this.rows.values()))this.renderCallouts(t)}renderCallouts(e){for(let t of(this.disposeTips(this.calloutTips,e.id),e.callouts))t.destroy();e.callouts=[],e.calloutsEl.replaceChildren();let t=this.legendCallouts?.(e.id)??[];for(let i of(e.calloutsEl.style.display=tD(e.highlighted,t.length>0),t)){let t=new m.zx({icon:i.icon,background:i.background,...void 0!==i.color?{color:i.color}:{},label:i.tooltip,...void 0!==i.content?{panel:i.content}:{},host:this.container,theme:()=>this.theme});t.el.dataset.legendCallout=i.id,this.tip(this.calloutTips,e.id,t.el,i.tooltip),e.callouts.push(t),e.calloutsEl.appendChild(t.el)}}reposition(){for(let[e,t]of this.legends)this.positionLegend(t,e)}setTitlesVisible(e){this.titlesVisible!==e&&(this.titlesVisible=e,this.reposition())}setValuesVisible(e){for(let t of(this.valuesVisible=e,this.rows.values()))t.showValues=null,this.renderRowValues(t)}setPlotValues(e){for(let t of this.rows.values()){let i=e.get(t.id)??[],o=i.map(e=>`${e.value}|${e.color}`).join("\0");o!==t.plotValuesKey&&(t.plotValues=i,t.plotValuesKey=o,this.renderRowValues(t))}}rowValuesShown(e){return e.showValues??this.valuesVisible}renderRowValues(e){if(!this.rowValuesShown(e)||0===e.plotValues.length||e.highlighted){e.valuesEl.style.display="none",e.valuesEl.replaceChildren();return}e.valuesEl.style.display="block",e.valuesEl.replaceChildren(),e.plotValues.forEach((t,i)=>{let o=document.createElement("span");o.style.color=t.color,i>0&&(o.style.marginInlineStart="5px");let r=document.createElement("span");r.dir="ltr",r.style.unicodeBidi="isolate",r.textContent=t.value,o.appendChild(r),e.valuesEl.appendChild(o)})}openMoveMenu(e,t){this.closeMoveMenu();let i=this.moveApi;if(!i)return;let o=this.rows.get(e),r=o?.paneId??"price",l=i.panes(),n=[];for(let e of l){if(e.id===r)continue;let t="price"===e.kind?this.t(tP.moveToMainChart):this.t(tP.moveToPane,{pane:e.label});n.push({label:t,target:"price"===e.kind?"price":{pane:e.id}})}"price"!==r&&[...this.rows.values()].filter(e=>e.paneId===r).length<=1||("price"!==r&&n.push({label:this.t(tP.newPaneAbove),target:{newPane:{before:r}}}),n.push({label:this.t(tP.newPaneBelow),target:{newPane:{after:r}}})),this.moveTargets=n.map(e=>e.target),this.moveMenuId=e;let a=this.stackItems(e),s=n.map((e,t)=>({id:String(t),label:e.label}));s[0]&&a.length>0&&(s[0].separatorBefore=!0);let h=[...a,...s];this.moveMenu?this.moveMenu.setItems(h):this.moveMenu=new u.rI({host:this.container,items:h,side:"bottom",align:"start",onSelect:e=>{let t=this.moveMenuId;if(!t||this.runStackItem(e,t))return;let o=this.moveTargets[Number(e)];o&&i.move(t,o)}});let d=t.getBoundingClientRect();this.moveMenu.openAt(d.left,d.bottom+4)}closeMoveMenu(){this.moveMenu?.close()}rowMenu(e,t){return new g.t({target:t,host:this.container,longPress:!1,items:t=>(t.stopPropagation(),this.closeMoveMenu(),this.rowMenuItems(e)),onSelect:t=>{if(this.runStackItem(t,e)||"values"!==t)return;let i=this.rows.get(e);i&&(i.showValues=!this.rowValuesShown(i),this.renderRowValues(i))}})}rowMenuItems(e){let t=this.rows.get(e);if(!t)return null;let i=this.stackItems(e);return[...i,{id:"values",label:this.t(tP.indicatorValues),checked:this.rowValuesShown(t),separatorBefore:i.length>0}]}stackItems(e){let t=this.stackApi;if(!t)return[];let i=[],o=this.stackLabel(t.above(e),{price:tP.bringInFrontOfPrice,named:tP.bringInFrontOf,unnamed:tP.bringInFrontOfNext});o&&i.push({id:tI,label:o});let r=this.stackLabel(t.below(e),{price:tP.sendBehindPrice,named:tP.sendBehind,unnamed:tP.sendBehindNext});return r&&i.push({id:tE,label:r}),i}stackLabel(e,t){if(null===e)return null;if("price"===e)return this.t(t.price);let i=this.rows.get(e.indicator)?.title;return void 0!==i?this.t(t.named,{indicator:i}):this.t(t.unnamed)}runStackItem(e,t){if(e===tI)this.stackApi?.raise(t);else{if(e!==tE)return!1;this.stackApi?.lower(t)}return!0}orderRows(e){let t=`${e.join(",")}|${[...this.rows.values()].map(e=>`${e.id}@${e.paneId}`).join(",")}`;if(t===this.rowOrderKey)return;this.rowOrderKey=t;let i=new Map(e.map((e,t)=>[e,t]));for(let e of this.legends.values()){let t=[...this.rows.values()].filter(t=>t.el.parentElement===e).map(e=>e.el),o=[...e.children],r=new Map([...this.rows.values()].map(e=>[e.el,e.id])),l=e=>i.get(r.get(e))??-1;t.sort((e,t)=>{let i=l(e),r=l(t);return i>=0&&r>=0?r-i:i>=0||r>=0?i>=0?-1:1:o.indexOf(e)-o.indexOf(t)});let n=this.foldToggle?.parentElement===e?this.foldToggle:null;for(let i of t)e.insertBefore(i,n)}}setPane(e,t){let i=this.rows.get(e);if(!i||i.paneId===t)return;let o=i.paneId;if(i.paneId=t,this.attach(this.legendFor(t),i.el,i.native),this.syncFoldToggle(),"price"!==o){let e=this.legends.get(o);e&&0===e.childElementCount&&(e.remove(),this.legends.delete(o))}}legendFor(e){let t=this.legends.get(e);return t||((t=document.createElement("div")).dataset.velaPane=e,t.style.cssText="position:absolute;left:10px;z-index:5;display:flex;flex-direction:column;align-items:flex-start;gap:0;pointer-events:none;font:12px -apple-system,Segoe UI,sans-serif;",e$(t,this.theme),this.positionLegend(t,e),this.container.appendChild(t),this.legends.set(e,t)),t}positionLegend(e,t){let i=this.paneBoundsOf?this.paneBoundsOf(t):{top:0,height:1/0};e.toggleAttribute("data-vela-pane-at-top",0===i.top),e.style.display=i.height<4||!this.titlesVisible?"none":"flex",e.style.maxWidth=`calc(100% - ${(i.rightAxis??0)+10+6}px)`;let o=this.paneCollapse.has(t),r=this.paneCollapse.get(t)??null;for(let e of this.rows.values())e.paneId===t&&(e.el.style.display=(o?e.id!==r:this.legendFolded)?"none":"flex");let l=i.top+8;if(o&&Number.isFinite(i.height)){let t=e.offsetHeight||20;l=i.top+Math.max(1,Math.round((i.height-t)/2))}e.style.top=`${l}px`}setCollapsedPanes(e){this.paneCollapse=e}syncFoldToggle(){let e=this.rows.size;if(e<(null!==this.overviewAction||this.mobileLayout?1:2)){let t=this.legendFolded;e>0&&(this.legendFolded=!1),this.foldToggle&&(this.foldToggle.remove(),this.foldToggle=null,this.disposeTips(this.rowTips,"fold")),t&&e>0&&this.reposition();return}let t=this.foldToggle;t||((t=document.createElement("button")).type="button",t.className="vela-ind-fold",this.tip(this.rowTips,"fold",t,()=>this.foldLabel()),t.addEventListener("click",()=>{if(null!==this.overviewAction)return void this.overviewAction();this.legendFolded=!this.legendFolded,this.syncFoldToggle()}),this.foldToggle=t);let i=this.legendFolded;t.setAttribute("aria-label",this.foldLabel());let o=this.theme.textColor;t.style.cssText=`pointer-events:auto;display:inline-flex;align-items:center;gap:4px;background:${this.theme.background};color:${o};border:1px solid ${this.theme.borderColor};border-radius:4px;padding:2px 6px;margin-top:6px;cursor:pointer;font:inherit;line-height:0;`,t.replaceChildren();let r=document.createElement("span");if(r.style.cssText="display:inline-flex;align-items:center;line-height:0;opacity:0.7;",r.innerHTML=null!==this.overviewAction?tV:i?tz:tN,t.appendChild(r),i){let i=document.createElement("span");i.textContent=String(e),i.style.cssText=`font-weight:600;line-height:normal;font-size:12px;color:${o};`,t.appendChild(i)}this.legendFor("price").appendChild(t),this.reposition()}setTitle(e,t){let i=this.rows.get(e);i&&i.title!==t&&(i.title=t,i.titleEl.textContent=t)}upsert(e,t,i,o,r="price",n={}){let a=this.rows.get(e);if(a){a.title=t,a.inputs=i,a.values={...o},a.props=n.props??[],a.propValues={...n.propValues??{}},a.titleEl.textContent=t,a.paneId!==r&&(a.paneId=r,this.attach(this.legendFor(r),a.el,a.native),this.syncFoldToggle());return}tx();let s=document.createElement("div");s.style.cssText=`pointer-events:auto;display:flex;align-items:center;background:${this.idleRowFill()};border-radius:4px;padding:2px 6px;margin-left:-6px;max-width:calc(100% + 6px);min-height:22px;box-sizing:border-box;color:${this.theme.textColor};user-select:none;-webkit-user-select:none;`,s.addEventListener("mouseleave",()=>{this.selectedId!==e&&this.setRowHighlighted(e,!1)}),s.addEventListener("click",t=>{0!==t.button||t.target.closest("button")||this.selectRow(e)}),s.addEventListener("dblclick",t=>{t.target.closest("button")||this.openDialog(e)}),s.addEventListener("mousedown",e=>{1===e.button&&e.preventDefault()}),s.addEventListener("auxclick",t=>{1===t.button&&(t.preventDefault(),this.onRemove?.(e))});let h=document.createElement("span");h.style.cssText="display:none;box-sizing:border-box;flex:none;";let d=document.createElement("span");d.style.cssText="white-space:nowrap;min-width:0;overflow:hidden;text-overflow:ellipsis;",d.addEventListener("mouseenter",()=>this.setRowHighlighted(e,!0));let c=document.createElement("span");if(c.textContent=t,c.style.cssText="font-weight:600;",d.appendChild(c),n.beta){let e=document.createElement("sup");e.textContent=this.t(tP.beta),e.dataset.velaCtl="beta",e.style.cssText="font-size:8px;font-weight:700;opacity:0.7;margin-left:1px;letter-spacing:0.2px;",d.appendChild(e)}s.appendChild(d);let p=document.createElement("span");p.style.cssText="display:none;align-items:center;gap:4px;flex:none;margin-left:8px;",s.appendChild(p),s.appendChild(h);let u=document.createElement("span");u.style.cssText="display:none;flex:1 1 0%;min-width:0;overflow:hidden;text-overflow:ellipsis;margin-inline-start:6px;white-space:nowrap;font-variant-numeric:tabular-nums;",s.appendChild(u);let g=document.createElement("span");g.style.cssText="display:none;align-items:center;gap:6px;flex:none;margin-left:6px;";let m=null;if(this.onToggleVisible){let t=document.createElement("button");t.type="button",t.setAttribute("aria-label",this.t(tP.hide)),this.tip(this.rowTips,e,t,()=>this.t(this.rows.get(e)?.hidden?tP.show:tP.hide)),t.innerHTML=tB,t.className="vela-ind-ctl",t.style.cssText=tA,t.addEventListener("click",()=>{let t=this.rows.get(e);this.onToggleVisible?.(e,!!t?.hidden)}),g.appendChild(t),m=t}if(i.length>0||(n.props??[]).length>0){let t=document.createElement("button");t.type="button",t.setAttribute("aria-label",this.t(tP.settings)),t.dataset.velaCtl="settings",this.tip(this.rowTips,e,t,()=>this.t(tP.settings)),t.innerHTML=tO,t.className="vela-ind-ctl",t.style.cssText=tA,t.addEventListener("click",()=>this.openDialog(e)),g.appendChild(t)}if(this.moveApi){let t=document.createElement("button");t.type="button",t.setAttribute("aria-label",this.t(tP.moveToPaneButton)),t.dataset.velaCtl="move",this.tip(this.rowTips,e,t,()=>this.t(tP.moveToPaneButton)),t.innerHTML=(0,l.N0)("move",16),t.className="vela-ind-ctl",t.style.cssText=tA,t.addEventListener("click",i=>{i.stopPropagation(),this.openMoveMenu(e,t)}),g.appendChild(t)}let b=document.createElement("span");b.style.cssText="display:contents;",this.renderExtras(e,b),g.appendChild(b);let f=document.createElement("button");f.type="button",f.setAttribute("aria-label",this.t(tP.remove)),f.dataset.velaCtl="remove",this.tip(this.rowTips,e,f,()=>this.t(tP.remove)),f.innerHTML=tR,f.className="vela-ind-close",f.style.cssText=tA,f.addEventListener("click",()=>this.onRemove?.(e)),g.appendChild(f),s.appendChild(g),this.attach(this.legendFor(r),s,!!n.native);let v={id:e,title:t,inputs:i,values:{...o},props:n.props??[],propValues:{...n.propValues??{}},el:s,titleEl:c,statusEl:h,valuesEl:u,plotValues:[],plotValuesKey:"",showValues:null,highlighted:!1,paneId:r,hidden:!1,eyeEl:m,controlsEl:g,extrasEl:b,calloutsEl:p,callouts:[],native:!!n.native,menu:this.rowMenu(e,s)};this.rows.set(e,v),this.renderCallouts(v),this.syncFoldToggle()}attach(e,t,i){i?e.prepend(t):e.appendChild(t)}setValues(e,t,i){let o=this.rows.get(e);o&&(o.values={...o.values,...t},i&&(o.propValues={...o.propValues,...i}))}setStatus(e,t){let i=this.rows.get(e);if(!i)return;let o=i.statusEl;if(o.replaceChildren(),"idle"===t){o.style.cssText="display:none;box-sizing:border-box;flex:none;";return}if("loading"===t){o.style.cssText="display:inline-flex;align-items:center;gap:3px;box-sizing:border-box;flex:none;margin-left:8px;line-height:0;transform:translateY(1px);";for(let e=0;e<3;e+=1){let t=document.createElement("span");t.style.cssText="width:4px;height:4px;border-radius:50%;background:currentColor;opacity:0.15;flex:none;",t.animate?.([{opacity:.12},{opacity:.55}],{duration:800,iterations:1/0,direction:"alternate",easing:"ease-in-out",delay:-(260*e)}),o.appendChild(t)}return}this.ensureStatusKeyframes(),o.style.cssText=`display:inline-block;box-sizing:border-box;flex:none;width:8px;height:8px;border-radius:50%;margin-left:8px;transform:translateY(1px);background:${this.theme.upColor};animation:vela-ind-pulse 1.2s ease-in-out infinite;`}ensureStatusKeyframes(){if("undefined"==typeof document||document.getElementById("vela-ind-status-kf"))return;let e=document.createElement("style");e.id="vela-ind-status-kf",e.textContent=tL,document.head.appendChild(e)}setVisible(e,t){let i=this.rows.get(e);i&&(i.hidden=!t,i.el.style.opacity=t?"1":"0.5",i.eyeEl&&(i.eyeEl.innerHTML=t?tB:tF,i.eyeEl.setAttribute("aria-label",this.t(t?tP.hide:tP.show))),this.syncRowActions(i))}selectRow(e){this.selectedId!==e&&(this.clearSelection(),this.selectedId=e,this.setRowHighlighted(e,!0))}setRowHighlighted(e,t){let i=this.rows.get(e);i&&(i.highlighted=t,this.renderRowValues(i),i.el.style.boxShadow=t?`inset 0 0 0 1px ${this.neutralBorder()}`:"none",i.el.style.background=t?this.theme.background:this.idleRowFill(),this.syncRowActions(i))}syncRowActions(e){let t=e.highlighted;if(e.controlsEl.style.display=t||e.hidden?"inline-flex":"none",t)for(let t of(e.el.appendChild(e.statusEl),e.callouts))t.hidePanel();else e.el.insertBefore(e.statusEl,e.valuesEl);for(let i of(e.calloutsEl.style.display=tD(t,e.callouts.length>0),Array.from(e.controlsEl.children)))if(i instanceof HTMLElement&&i!==e.eyeEl){if(i===e.extrasEl){i.style.display=t?"contents":"none";continue}i.style.display=t?"inline-flex":"none"}}clearSelection(){this.selectedId&&(this.setRowHighlighted(this.selectedId,!1),this.selectedId=null)}remove(e){let t=this.rows.get(e);for(let e of t?.callouts??[])e.destroy();if(t?.menu.destroy(),t?.el.remove(),this.rows.delete(e),this.disposeTips(this.rowTips,e),this.disposeTips(this.extrasTips,e),this.disposeTips(this.calloutTips,e),this.selectedId===e&&(this.selectedId=null),this.inputsDialog.openId===e&&this.inputsDialog.close(),this.syncFoldToggle(),t&&"price"!==t.paneId){let e=this.legends.get(t.paneId);e&&0===e.childElementCount&&(e.remove(),this.legends.delete(t.paneId))}}destroy(){for(let e of(this.inputsDialog.close(),this.moveMenu?.destroy(),this.moveMenu=null,this.rows.values()))e.menu.destroy();for(let e of[...this.rowTips.keys()])this.disposeTips(this.rowTips,e);for(let e of[...this.extrasTips.keys()])this.disposeTips(this.extrasTips,e);for(let e of[...this.calloutTips.keys()])this.disposeTips(this.calloutTips,e);for(let e of this.rows.values())for(let t of e.callouts)t.destroy();for(let e of this.legends.values())e.remove();this.legends.clear(),this.rows.clear(),this.foldToggle=null,this.legendFolded=!1,this.selectedId=null,"undefined"!=typeof document&&document.removeEventListener("click",this.onDocClick)}isDialogOpen(){return this.inputsDialog.isOpen()}closeOpenDialog(){this.inputsDialog.close()}openDialog(e){let t=this.rows.get(e);t&&this.inputsDialog.open(t)}idleRowFill(){return(0,p.fu)(this.theme.background,.6)}neutralBorder(){return"var(--vela-border)"}},tH={moveUp:(0,n.ab)("chart.paneControls.moveUp","Move panel up"),moveDown:(0,n.ab)("chart.paneControls.moveDown","Move panel down"),expand:(0,n.ab)("chart.paneControls.expand","Expand panel"),collapse:(0,n.ab)("chart.paneControls.collapse","Collapse panel"),restore:(0,n.ab)("chart.paneControls.restore","Restore panel"),maximize:(0,n.ab)("chart.paneControls.maximize","Maximize panel")},tW={up:(0,l.Kk)("chevron-up"),down:(0,l.Kk)("chevron-down"),collapse:(0,l.Kk)("pane-collapse"),expand:(0,l.Kk)("pane-expand"),maximize:(0,l.Kk)("maximize"),restore:(0,l.Kk)("restore")},tq="vela-pane-controls",tU="rgba(0,0,0,0.65)",tj=class{constructor(e,t,i){this.plot=e,this.theme=t,this.deps=i,this.clusters=new Map,this.hoverPaneId=null,this.suspended=!1,this.onPlotMove=e=>{if(this.suspended)return;let t=this.plot.getBoundingClientRect(),i=e.clientY-t.top,o=null;for(let e of this.deps.panes())if(i>=e.top&&i<=e.top+e.height){o=e.id;break}this.setHoverPane(o)},this.onPlotLeave=()=>this.setHoverPane(null),function(){if("undefined"==typeof document||document.getElementById(tq))return;let e=document.createElement("style");e.id=tq,e.textContent=(0,d.AH)`@layer vela.chrome {
74
+
75
+ .vela-pc-btn{display:inline-flex;align-items:center;justify-content:center;padding:0;border:none;border-radius:${c.t.radius.sm};background:transparent;line-height:0;font-size:${12}px;color:${c.t.fg.muted};}
76
+ .vela-pc-btn svg{display:block;}
77
+ .vela-pc-btn:not(:disabled):hover{opacity:1 !important;background:${c.t.active};color:${c.t.fg.bright};}
78
+ .vela-pc-on,.vela-pc-on:not(:disabled):hover{background:${c.t.selected.bg};color:${c.t.selected.fg};}
79
+
80
+ }`,document.head.appendChild(e)}(),this.root=document.createElement("div"),Object.assign(this.root.style,{position:"absolute",inset:"0",pointerEvents:"none",zIndex:"6"}),this.plot.appendChild(this.root),this.plot.addEventListener("pointermove",this.onPlotMove),this.plot.addEventListener("pointerleave",this.onPlotLeave),this.refresh()}setTheme(e){this.theme=e,this.refresh()}refresh(){let e=this.deps.panes(),t=new Set;for(let i of e){t.add(i.id);let e=this.clusters.get(i.id);e||(Object.assign((e=document.createElement("div")).style,{position:"absolute",display:"flex",gap:"2px",padding:"2px",borderRadius:"var(--vela-radius-md)",background:tU,pointerEvents:"auto"}),this.root.appendChild(e),this.clusters.set(i.id,e)),this.buildButtons(e,i)}for(let[e,i]of this.clusters)t.has(e)||(i.remove(),this.clusters.delete(e));this.reposition()}t(e){return(0,n.b6)(this.deps.i18n?.()??null,e)}buildButtons(e,t){e.textContent="","study"===t.kind&&(e.appendChild(this.button(tW.up,this.t(tH.moveUp),t.index<=1,()=>this.deps.onMove(t.id,"up"),{role:"up"})),e.appendChild(this.button(tW.down,this.t(tH.moveDown),t.index>=t.count-1,()=>this.deps.onMove(t.id,"down"),{role:"down"})),e.appendChild(this.button(t.collapsed?tW.expand:tW.collapse,this.t(t.collapsed?tH.expand:tH.collapse),!1,()=>this.deps.onToggleCollapse(t.id),{role:"collapse",selected:t.collapsed}))),t.count>1&&e.appendChild(this.button(t.maximized?tW.restore:tW.maximize,this.t(t.maximized?tH.restore:tH.maximize),!1,()=>this.deps.onToggleMaximize(t.id),{role:"maximize",selected:t.maximized}))}button(e,t,i,o,r){let l=document.createElement("button");return l.type="button",l.title=t,l.innerHTML=e,l.disabled=i,l.dataset.role=r.role,l.className=!0===r.selected?"vela-pc-btn vela-pc-on":"vela-pc-btn",Object.assign(l.style,{cursor:i?"default":"pointer",width:"20px",height:"20px",opacity:i?"0.3":"1"}),i||l.addEventListener("click",e=>{e.stopPropagation(),o()}),l}reposition(){let e=this.deps.rightAxis()+6,t=new Map(this.deps.panes().map(e=>[e.id,e]));for(let[i,o]of this.clusters){let r=t.get(i);if(!r){o.style.display="none";continue}let l=i===this.hoverPaneId,n=o.children.length>0,a=r.collapsed?"collapse":!this.suspended&&r.maximized?"maximize":null,s=n&&(l||null!=a)&&r.height>8;if(o.style.right=`${e}px`,o.style.top=r.collapsed?`${r.top+Math.max(1,Math.round((r.height-24)/2))}px`:`${r.top+4}px`,o.style.display=s?"flex":"none",!s)continue;let h=null!=a&&!l;for(let e of(o.style.background=h?"transparent":tU,o.children))e.style.display="inline-flex",e.style.visibility=h&&e.dataset.role!==a?"hidden":"visible"}}setHoverPane(e){this.hoverPaneId!==e&&(this.hoverPaneId=e,this.reposition())}setSuspended(e){e!==this.suspended&&(this.suspended=e,e&&(this.hoverPaneId=null),this.reposition())}destroy(){this.plot.removeEventListener("pointermove",this.onPlotMove),this.plot.removeEventListener("pointerleave",this.onPlotLeave),this.root.remove(),this.clusters.clear()}};function tG(e,t){return 0===t?e:e+64+(t-1)*56}var tK={auto:(0,n.ab)("chart.axisButtons.auto","Auto (fits data to screen)"),log:(0,n.ab)("chart.axisButtons.log","Logarithmic scale"),percent:(0,n.ab)("chart.axisButtons.percent","Percentage scale"),autoLetter:(0,n.ab)("chart.axisButtons.autoLetter","A"),logLetter:(0,n.ab)("chart.axisButtons.logLetter","L"),percentLetter:(0,n.ab)("chart.axisButtons.percentLetter","%")},tY="vela-axis-scale-buttons",tZ=class{constructor(e,t,i){this.plot=e,this.theme=t,this.deps=i,this.tipDisposers=[],this.hoverPaneId=null,this.onPlotMove=e=>{if("mouse"!==e.pointerType)return;let t=this.plot.getBoundingClientRect(),i=e.clientX-t.left,o=t.width-this.deps.rightAxis(),r=null;if(i>=o&&i<=o+64){let i=e.clientY-t.top;for(let e of this.deps.panes())if(!e.collapsed&&!(e.height<48)&&i>=e.top&&i<=e.top+e.height){r=e.id;break}}this.setHoverPane(r),r&&this.sync()},this.onPlotLeave=()=>this.setHoverPane(null),function(){if("undefined"==typeof document||document.getElementById(tY))return;let e=document.createElement("style");e.id=tY,e.textContent=(0,d.AH)`@layer vela.chrome {
81
+
82
+ .vela-axis-btn{display:inline-flex;align-items:center;justify-content:center;padding:0;border:none;border-radius:${c.t.radius.sm};background:transparent;cursor:pointer;font:600 10px/1 -apple-system,Segoe UI,sans-serif;color:${c.t.fg.muted};}
83
+ .vela-axis-btn:hover{background:${c.t.active};color:${c.t.fg.bright};}
84
+ .vela-axis-on,.vela-axis-on:hover{background:${c.t.selected.bg};color:${c.t.selected.fg};}
85
+
86
+ }`,document.head.appendChild(e)}(),this.cluster=document.createElement("div"),Object.assign(this.cluster.style,{position:"absolute",display:"none",justifyContent:"center",alignItems:"center",gap:"3px",padding:"8px 0 6px",width:"63px",boxSizing:"border-box",zIndex:"6",pointerEvents:"auto"}),this.applyTheme(),this.percentBtn=this.button(tK.percentLetter,tK.percent,()=>this.deps.onTogglePercent(this.hoverPaneId??"")),this.logBtn=this.button(tK.logLetter,tK.log,()=>this.deps.onToggleLog(this.hoverPaneId??"")),this.autoBtn=this.button(tK.autoLetter,tK.auto,()=>this.deps.onToggleAuto(this.hoverPaneId??"")),this.cluster.append(this.percentBtn,this.logBtn,this.autoBtn),this.plot.appendChild(this.cluster),this.plot.addEventListener("pointermove",this.onPlotMove),this.plot.addEventListener("pointerleave",this.onPlotLeave)}t(e){return(0,n.b6)(this.deps.i18n?.()??null,e)}relabel(){this.percentBtn.setAttribute("aria-label",this.t(tK.percent)),this.autoBtn.setAttribute("aria-label",this.t(tK.auto)),this.logBtn.setAttribute("aria-label",this.t(tK.log)),this.percentBtn.textContent=this.t(tK.percentLetter),this.autoBtn.textContent=this.t(tK.autoLetter),this.logBtn.textContent=this.t(tK.logLetter)}button(e,t,i){let o=document.createElement("button");return o.type="button",o.setAttribute("aria-label",this.t(t)),o.textContent=this.t(e),o.className="vela-axis-btn",Object.assign(o.style,{width:"18px",height:"18px"}),this.tipDisposers.push(eH(o,{host:this.plot,theme:()=>this.theme,text:()=>this.t(t),placement:"above"})),o.addEventListener("click",e=>{e.stopPropagation(),i(),this.sync()}),o}setTheme(e){this.theme=e,this.applyTheme()}applyTheme(){this.cluster.style.background=this.theme.background}setHoverPane(e){this.hoverPaneId!==e&&(this.hoverPaneId=e,this.reposition())}reposition(){let e=this.hoverPaneId?this.deps.panes().find(e=>e.id===this.hoverPaneId):void 0;if(!e||e.collapsed||e.height<48){this.cluster.style.display="none";return}this.cluster.style.right=`${this.deps.rightAxis()-64}px`,this.cluster.style.top=`${e.top+e.height-32}px`,this.cluster.style.display="flex",this.sync()}sync(){let e=this.deps.panes().find(e=>e.id===this.hoverPaneId);e&&(this.percentBtn.classList.toggle("vela-axis-on",e.percent),this.autoBtn.classList.toggle("vela-axis-on",e.auto),this.logBtn.classList.toggle("vela-axis-on",e.log))}destroy(){for(let e of(this.plot.removeEventListener("pointermove",this.onPlotMove),this.plot.removeEventListener("pointerleave",this.onPlotLeave),this.tipDisposers))e();this.tipDisposers.length=0,this.cluster.remove()}},tX={panes:!0,paneManagement:!0,fills:"native",bgcolor:"native",hline:"native",markers:!0,barcolor:"native",perPointColor:!0,drawings:!0,userDrawings:!0,drawingDepth:!0,tables:!0,trades:!0,timelineMarks:!0,inputsUI:!0},t_=null;function tQ(e){return e.wickVisible?"range":e.bodyVisible||e.borderVisible?"body":"none"}function tJ(e,t,i,o){return"range"===t?(i?e.wickUpColor:e.wickDownColor)??o:e.bodyVisible?o:(i?e.borderUpColor:e.borderDownColor)??o}function t0(e){return Math.max(1,Math.min(1.5,Math.max(.5,Math.floor(.7*e)/2)))}function t1(e){return e<1?"aggregate":e<3?"wick":"full"}function t2(e,t){return Math.round(e*t)/t}function t5(e,t,i,o=1){let r=Math.max(1,Math.round(t0(t)*i)),l=Math.round(e*i-r/2),n=Math.max(r,Math.round(Math.floor(.7*t*o)*i));(n-r)%2!=0&&(n+=1);let a=(n-r)/2;return{wickX:l/i,wickW:r/i,bodyX:(l-a)/i,bodyW:n/i,center:(l+r/2)/i}}function t3(e,t,i,o,r,l,n="range"){let a=[],s=NaN,h=[],d=()=>{if(0===h.length)return;h.sort((e,t)=>e.lo-t.lo);let e=[];for(let t of h){let i;for(let o=e.length-1;o>=0;o-=1)if(e[o].color===t.color){i=e[o];break}i&&1>Math.abs(r(i.hi)-r(t.lo))?(i.hi=t.hi,t.lastIdx>i.lastIdx&&(i.lastIdx=t.lastIdx)):e.push(t)}for(let t of(e.sort((e,t)=>e.lastIdx-t.lastIdx),e))a.push({x:s,hi:t.hi,lo:t.lo,color:t.color});h=[]};for(let r=t;r<=i;r+=1){let t=e[r];if(!t||t.high<=t.low)continue;let i=Math.round(o(r));i!==s&&(d(),s=i);let a=l(t),c="body"===n?Math.min(t.open,t.close):t.low,p="body"===n?Math.max(t.open,t.close):t.high;for(let e=h.length-1;e>=0;e-=1){let t=h[e];t.color!==a||t.lo>p||t.hi<c||(t.lo<c&&(c=t.lo),t.hi>p&&(p=t.hi),h.splice(e,1))}h.push({lo:c,hi:p,color:a,lastIdx:r})}return d(),a}var t4=r.cr,t6=r.TV,t8=(0,p.fu)(r.Nz,.08),t7=(0,p.fu)(r.bg,.08),t9={top:10,bottom:10,right:10},ie=["solid","dashed","dotted"],it=["candles","bars","line","linemarkers","stepline","area","baseline","columns","heikinashi"];function ii(e){for(let t of(0,o.AHy)())if(t.id===e)return t.basePainting??"candles";return"candles"}function io(e){if(it.includes(e))return!1;for(let t of(0,o.AHy)())if(t.id===e)return(t.basePainting??"candles")==="candles";return!1}var ir=["candleUpColor","candleDownColor","candleBodyVisible","candleBorderVisible","candleBorderUpColor","candleBorderDownColor","candleWickVisible","candleWickUpColor","candleWickDownColor"];function il(e,t){if(!io(e))return null;let i=t[e]??{},o=e=>ih(e)?e:null,r=e=>id(e)?e:null;return{upColor:o(i.candleUpColor),downColor:o(i.candleDownColor),bodyVisible:r(i.candleBodyVisible),borderVisible:r(i.candleBorderVisible),borderUpColor:o(i.candleBorderUpColor),borderDownColor:o(i.candleBorderDownColor),wickVisible:r(i.candleWickVisible),wickUpColor:o(i.candleWickUpColor),wickDownColor:o(i.candleWickDownColor)}}function ia(e,t,i,o){return t?{up:t.upColor??i,down:t.downColor??o,candle:{bodyVisible:t.bodyVisible??e.bodyVisible,borderVisible:t.borderVisible??e.borderVisible,borderUpColor:t.borderUpColor??e.borderUpColor,borderDownColor:t.borderDownColor??e.borderDownColor,wickVisible:t.wickVisible??e.wickVisible,wickUpColor:t.wickUpColor??e.wickUpColor,wickDownColor:t.wickDownColor??e.wickDownColor}}:{up:i,down:o,candle:e}}function is(){let e=[...it];for(let t of(0,o.AHy)())e.includes(t.id)||e.push(t.id);return e}function ih(e){return"string"==typeof e&&e.trim().length>0}function id(e){return"boolean"==typeof e}function ic(e){return"number"==typeof e&&Number.isFinite(e)}function ip(e){return"string"==typeof e&&ie.includes(e)}function iu(e){return e&&"object"==typeof e?e:{}}function ig(e){return e<0?0:e>1?1:e}function im(e){return e<1?1:e>10?10:e}function ib(e){return e<0?0:e>40?40:e}function iv(e,t){return i=>i===e.upColor?t.upColor:i===e.downColor?t.downColor:i}function iy(e){return{upColor:(0,p.fu)(e.upColor,.5),downColor:(0,p.fu)(e.downColor,.5)}}function iw(e,t){let i=iv(e,t),o=iv(iy(e),iy(t));return e=>o(i(e))}function iC(e){return Math.max(1,e)/2+3}function ix(e,t){let i=e[t],o=e[t-1];return!i||!o||i.close>=o.close}function ik(e,t,i){let o=t/2,r=Math.round((e-o)*i),l=Math.round((e+o)*i),n=t>=3?Math.max(1,Math.round(+i)):0,a=Math.max(1,l-r-n);return{left:(r+Math.floor(n/2))/i,width:a/i}}function iS(e,t,i){let o=.5*(Math.max(1,Math.round(t*i))%2==1);return(Math.round(e*i-o)+o)/i}function iT(e,t,i){let o=[],r=[];for(let l=e;l<=t;l+=1){let e=i(l);if(e){r.push(e);continue}r.length>0&&o.push(r),r=[]}return r.length>0&&o.push(r),o}function iM(e){let t=[];for(let i=0;i<e.length;i+=1){let o=e[i];if(0===i){t.push({x:o.x,y:o.y});continue}let r=e[i-1].y;t.push({x:o.x,y:r}),o.y!==r&&t.push({x:o.x,y:o.y})}return t}var iL=new Map,iA=class{constructor(e=4096){this.n=0,this.alpha=1,this.buf=new Float32Array(8*e)}reset(){this.n=0}get vertexCount(){return this.n/8}get view(){return this.buf.subarray(0,this.n)}ensure(e){let t=this.n+8*e;if(t<=this.buf.length)return;let i=this.buf.length||8;for(;i<t;)i*=2;let o=new Float32Array(i);o.set(this.buf.subarray(0,this.n)),this.buf=o}v(e,t,i,o=0,r=-1){let l=this.buf,n=this.n;l[n++]=e,l[n++]=t,l[n++]=i[0],l[n++]=i[1],l[n++]=i[2],l[n++]=i[3]*this.alpha,l[n++]=o,l[n++]=r,this.n=n}tri(e,t,i,o,r,l,n,a,s){this.ensure(3),this.v(e,t,i),this.v(o,r,l),this.v(n,a,s)}quad4(e,t,i,o,r,l,n,a,s,h,d,c){this.ensure(6),this.v(e,t,i),this.v(o,r,l),this.v(n,a,s),this.v(e,t,i),this.v(n,a,s),this.v(h,d,c)}quad(e,t,i,o,r,l,n,a,s){this.quad4(e,t,s,i,o,s,r,l,s,n,a,s)}rect(e,t,i,o,r){this.quad(e,t,e+i,t,e+i,t+o,e,t+o,r)}seg(e,t,i,o,r,l){let n=i-e,a=o-t,s=Math.hypot(n,a);if(s<1e-6)return;let h=r/2,d=h+1,c=-a/s*d,p=n/s*d,u=e+c,g=t+p,m=i-c,b=o-p;this.ensure(6),this.v(u,g,l,d,h),this.v(i+c,o+p,l,d,h),this.v(m,b,l,-d,h),this.v(u,g,l,d,h),this.v(m,b,l,-d,h),this.v(e-c,t-p,l,-d,h)}dashedSeg(e,t,i,o,r,l,n){if(!n)return void this.seg(e,t,i,o,r,l);let a=i-e,s=o-t,h=Math.hypot(a,s);if(h<1e-6)return;let d=a/h,c=s/h,p=n[0]+n[1];if(p<=0)return void this.seg(e,t,i,o,r,l);let u=0;for(;u<h;){let i=Math.min(n[0],h-u),o=u,a=u+i;this.seg(e+d*o,t+c*o,e+d*a,t+c*a,r,l),u+=p}}rectStroke(e,t,i,o,r,l){this.seg(e,t,e+i,t,r,l),this.seg(e+i,t,e+i,t+o,r,l),this.seg(e+i,t+o,e,t+o,r,l),this.seg(e,t+o,e,t,r,l)}circle(e,t,i,o,r=16){let l=i+1,n=function(e){let t=iL.get(e);if(!t){let i=Math.max(0,Math.floor(e));t=new Float64Array(2*i);for(let o=1;o<=i;o+=1){let i=o/e*Math.PI*2;t[(o-1)*2]=Math.cos(i),t[(o-1)*2+1]=Math.sin(i)}iL.set(e,t)}return t}(r),a=e+l,s=t;this.ensure(3*r);for(let r=0;r<n.length;r+=2){let h=e+n[r]*l,d=t+n[r+1]*l;this.v(e,t,o,0,i),this.v(a,s,o,l,i),this.v(h,d,o,l,i),a=h,s=d}}},iP=[0,0,0,1],iI=null,iE=new Map,iB=new Map;function iF(e){if(!e)return iP;let t=iE.get(e);return t||((t=iB.get(e))?iE.set(e,t):(t=function(e){if(!iI){let e=document.createElement("canvas");e.width=1,e.height=1,iI=e.getContext("2d",{willReadFrequently:!0})}if(!iI)return iP;iI.clearRect(0,0,1,1),iI.fillStyle="#000",iI.fillStyle=e,iI.fillRect(0,0,1,1);let t=iI.getImageData(0,0,1,1).data;return[t[0]/255,t[1]/255,t[2]/255,t[3]/255]}(e),iE.set(e,t),iE.size>=8192&&(iB=iE,iE=new Map))),t}function iO(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}var iR=`#version 300 es
87
+ layout(location=0) in vec2 aPos;
88
+ layout(location=1) in vec4 aColor;
89
+ layout(location=2) in vec2 aEdge; // (signed perpendicular distance from line center, half-width)
90
+ uniform vec2 uRes;
91
+ out vec4 vColor;
92
+ out vec2 vEdge;
93
+ void main() {
94
+ vec2 clip = vec2(aPos.x / uRes.x * 2.0 - 1.0, 1.0 - aPos.y / uRes.y * 2.0);
95
+ gl_Position = vec4(clip, 0.0, 1.0);
96
+ vColor = aColor;
97
+ vEdge = aEdge;
98
+ }`,iN=`#version 300 es
99
+ precision highp float;
100
+ in vec4 vColor;
101
+ in vec2 vEdge;
102
+ out vec4 frag;
103
+ void main() {
104
+ if (vEdge.y < 0.0) { frag = vColor; return; }
105
+ float aa = fwidth(vEdge.x);
106
+ float cov = clamp((vEdge.y - abs(vEdge.x)) / max(aa, 1e-4) + 0.5, 0.0, 1.0);
107
+ frag = vec4(vColor.rgb, vColor.a * cov);
108
+ }`,iz=`#version 300 es
109
+ layout(location=0) in vec2 aPos;
110
+ out vec2 vUv;
111
+ void main() {
112
+ vUv = aPos * 0.5 + 0.5;
113
+ gl_Position = vec4(aPos, 0.0, 1.0);
114
+ }`,iV=`#version 300 es
115
+ precision mediump float;
116
+ in vec2 vUv;
117
+ uniform sampler2D uTex;
118
+ uniform vec2 uDir; // blur direction (texel step); (0,0) = composite passthrough
119
+ uniform float uIntensity;
120
+ out vec4 frag;
121
+ void main() {
122
+ if (uDir.x == 0.0 && uDir.y == 0.0) {
123
+ frag = texture(uTex, vUv) * uIntensity;
124
+ return;
125
+ }
126
+ vec2 o1 = uDir * 1.3846153846;
127
+ vec2 o2 = uDir * 3.2307692308;
128
+ vec4 sum = texture(uTex, vUv) * 0.2270270270;
129
+ sum += texture(uTex, vUv + o1) * 0.3162162162;
130
+ sum += texture(uTex, vUv - o1) * 0.3162162162;
131
+ sum += texture(uTex, vUv + o2) * 0.0702702703;
132
+ sum += texture(uTex, vUv - o2) * 0.0702702703;
133
+ frag = sum;
134
+ }`,iD={solid:null,dashed:[6,4],dotted:[2,3]};function i$(e){return Math.max(6,Math.min(20,Math.round(4*e)))}var iH=class{constructor(){this.kind="webgl2",this.modelAlpha=1,this.candleBodyAlpha=1,this.candleStructureAlpha=1,this.candleBodyScale=1,this.onNeedsRedraw=null,this.onContextFailed=null,this.glow=0,this.canvas=null,this.gl=null,this.program=null,this.vao=null,this.vbo=null,this.uRes=null,this.batch=new iA,this.contextLost=!1,this.screenProgram=null,this.uTex=null,this.uDir=null,this.uIntensity=null,this.quadVao=null,this.quadVbo=null,this.fboA=null,this.texA=null,this.fboB=null,this.texB=null,this.fboW=0,this.fboH=0,this.glowBatch=new iA,this.sliceTex=new Map,this.onLost=e=>{e.preventDefault(),this.contextLost=!0},this.onRestored=()=>{this.contextLost=!1,this.initGL()?this.onNeedsRedraw?.():this.onContextFailed?.()}}get ok(){return null!==this.gl}mount(e){if(this.canvas=e,this.gl=e.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0}),this.gl){if(!this.initGL()){this.gl=null;return}e.addEventListener("webglcontextlost",this.onLost,!1),e.addEventListener("webglcontextrestored",this.onRestored,!1)}}initGL(){let e=this.gl;if(!e)return!1;this.screenProgram=null,this.quadVao=null,this.quadVbo=null,this.fboA=this.fboB=null,this.texA=this.texB=null,this.fboW=this.fboH=0,this.sliceTex.clear();let t=iW(e,e.VERTEX_SHADER,iR),i=iW(e,e.FRAGMENT_SHADER,iN),o=e.createProgram();return t&&i&&o?(e.attachShader(o,t),e.attachShader(o,i),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))?(e.deleteShader(t),e.deleteShader(i),this.program=o,this.uRes=e.getUniformLocation(o,"uRes"),this.vbo=e.createBuffer(),this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,this.vbo),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,32,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,4,e.FLOAT,!1,32,8),e.enableVertexAttribArray(2),e.vertexAttribPointer(2,2,e.FLOAT,!1,32,24),e.bindVertexArray(null),this.glow>0&&!this.ensureScreenPipeline()&&(this.glow=0),!0):(e.deleteProgram(o),e.deleteShader(t),e.deleteShader(i),!1):(t&&e.deleteShader(t),i&&e.deleteShader(i),o&&e.deleteProgram(o),!1)}ensureScreenPipeline(){if(this.screenProgram&&this.quadVao)return!0;let e=this.gl;if(!e)return!1;let t=iW(e,e.VERTEX_SHADER,iz),i=iW(e,e.FRAGMENT_SHADER,iV),o=e.createProgram();return t&&i&&o?(e.attachShader(o,t),e.attachShader(o,i),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS))?(e.deleteShader(t),e.deleteShader(i),this.screenProgram=o,this.uTex=e.getUniformLocation(o,"uTex"),this.uDir=e.getUniformLocation(o,"uDir"),this.uIntensity=e.getUniformLocation(o,"uIntensity"),this.quadVbo=e.createBuffer(),this.quadVao=e.createVertexArray(),e.bindVertexArray(this.quadVao),e.bindBuffer(e.ARRAY_BUFFER,this.quadVbo),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),!0):(e.deleteProgram(o),!1):(t&&e.deleteShader(t),i&&e.deleteShader(i),o&&e.deleteProgram(o),!1)}ensureFbos(e,t,i){if(this.fboA&&this.fboW===t&&this.fboH===i)return!0;this.deleteFbos(e);let o=()=>{let o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,i,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);let r=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fbo:r}},r=o(),l=o();return e.bindFramebuffer(e.FRAMEBUFFER,null),this.texA=r.tex,this.fboA=r.fbo,this.texB=l.tex,this.fboB=l.fbo,this.fboW=t,this.fboH=i,!!(this.fboA&&this.fboB)}deleteFbos(e){this.fboA&&e.deleteFramebuffer(this.fboA),this.fboB&&e.deleteFramebuffer(this.fboB),this.texA&&e.deleteTexture(this.texA),this.texB&&e.deleteTexture(this.texB),this.fboA=this.fboB=null,this.texA=this.texB=null,this.fboW=this.fboH=0}render(e,t,i){let o=this.gl,r=this.canvas;if(!o||!r||!this.program||this.contextLost||o.isContextLost())return;let l=t.dpr,n=t.width;o.viewport(0,0,r.width,r.height),o.disable(o.SCISSOR_TEST),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT);let a=t.barCount;if(0===a)return;let s=t.visibleLogicalRange(),h=Math.max(0,Math.floor(s.from)),d=Math.min(a-1,Math.ceil(s.to));if(d<h)return;let c=Math.max(d,Math.ceil(s.to));o.enable(o.BLEND),o.enable(o.SCISSOR_TEST);let p=function(e){let t=!1;for(let i of e.values())if(i.barColors&&i.barColors.length>0){t=!0;break}if(!t)return iK;let i=new Map;for(let t of e.values())if(t.barColors)for(let e of t.barColors)i.set(e.time,e.color);return i}(e.indicators),u=e.orderedPanes(),g=new Set;for(let a of u){let s=this.batch;s.reset();let u=Math.round(a.bounds.top*l),m=Math.round((a.bounds.top+a.bounds.height)*l);o.scissor(0,r.height-m,Math.round(n*l),m-u);let b=()=>{0!==s.vertexCount&&(o.blendFuncSeparate(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA),o.useProgram(this.program),o.bindVertexArray(this.vao),o.uniform2f(this.uRes,r.width/l,r.height/l),o.bindBuffer(o.ARRAY_BUFFER,this.vbo),o.bufferData(o.ARRAY_BUFFER,s.view,o.DYNAMIC_DRAW),o.drawArrays(o.TRIANGLES,0,s.vertexCount),s.reset())},f=a.collapsed?[]:e.drawingSlices.get(a.id)??[],v=0,y=e=>{for(;v<f.length&&f[v].beforeZ<=e;v+=1)b(),this.drawSliceTexture(o,f[v].canvas)&&g.add(f[v].canvas)};if(s.alpha=1,!a.collapsed){let o=e.orderedIndicatorsForPane(a.id),r="price"===a.kind,l=t=>{let i=e.scaleFor(t,a);return i===a.scale?a:{...a,scale:i}};for(let e of(s.alpha=this.modelAlpha,o))for(let i of e.backgrounds)!0!==i.overlay&&this.emitBackground(s,i,a,t);if(r)for(let i of e.indicators.values())for(let e of i.backgrounds)!0===e.overlay&&this.emitBackground(s,e,a,t);let u=r&&!e.candlesHidden,g=!1;for(let r of o){u&&!g&&e.zOf(r.id)>=e.candleZ&&(y(e.candleZ),s.alpha=this.candleStructureAlpha,this.emitPriceSeries(s,e,h,d,t,a,i,p,n),g=!0),y(e.zOf(r.id)),s.alpha=this.modelAlpha;let o=e.offsetOf(r.id),m=l(r);for(let e of r.fills)!0!==e.overlay&&this.emitFill(s,r,e,m,t,h,c,o);for(let e of r.series)!0!==e.overlay&&this.emitSeries(s,e,m,t,h,c,i,o)}if(u&&!g&&(y(e.candleZ),s.alpha=this.candleStructureAlpha,this.emitPriceSeries(s,e,h,d,t,a,i,p,n)),s.alpha=this.modelAlpha,r){for(let i of e.indicators.values()){let o=e.offsetOf(i.id);for(let e of i.fills)!0===e.overlay&&this.emitFill(s,i,e,a,t,h,c,o)}for(let o of e.indicators.values()){let r=e.offsetOf(o.id);for(let e of o.series)!0===e.overlay&&this.emitSeries(s,e,a,t,h,c,i,r)}}for(let e of(y(1/0),o)){let o=l(e);for(let r of e.priceLines)this.emitHline(s,r,o,t,n,i)}s.alpha=1}b()}for(let[e,t]of(o.disable(o.SCISSOR_TEST),this.sliceTex))g.has(e)||(o.deleteTexture(t),this.sliceTex.delete(e));!(this.glow>0)||this.screenProgram||this.ensureScreenPipeline()||(this.glow=0),this.glow>0&&this.screenProgram&&(this.glowBatch.alpha=this.modelAlpha,this.renderGlow(o,e,t,h,c))}renderGlow(e,t,i,o,r){let l=this.canvas,n=Math.max(1,l.width>>1),a=Math.max(1,l.height>>1);if(!this.ensureFbos(e,n,a))return;let s=i.dpr,h=i.width;for(let d of(e.bindFramebuffer(e.FRAMEBUFFER,this.fboA),e.viewport(0,0,n,a),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(this.program),e.bindVertexArray(this.vao),e.uniform2f(this.uRes,l.width/s,l.height/s),e.enable(e.SCISSOR_TEST),t.orderedPanes())){let l=this.glowBatch;if(l.reset(),this.emitGlowSources(l,t,d,i,o,r),0===l.vertexCount)continue;let n=Math.round(d.bounds.top*s*.5),c=Math.round((d.bounds.top+d.bounds.height)*s*.5);e.scissor(0,a-c,Math.round(h*s*.5),c-n),e.bindBuffer(e.ARRAY_BUFFER,this.vbo),e.bufferData(e.ARRAY_BUFFER,l.view,e.DYNAMIC_DRAW),e.drawArrays(e.TRIANGLES,0,l.vertexCount)}e.disable(e.SCISSOR_TEST),e.useProgram(this.screenProgram),e.bindVertexArray(this.quadVao),e.uniform1i(this.uTex,0),e.uniform1f(this.uIntensity,1),e.activeTexture(e.TEXTURE0),e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,this.fboB),e.bindTexture(e.TEXTURE_2D,this.texA),e.uniform2f(this.uDir,1/n,0),e.drawArrays(e.TRIANGLE_STRIP,0,4),e.bindFramebuffer(e.FRAMEBUFFER,this.fboA),e.bindTexture(e.TEXTURE_2D,this.texB),e.uniform2f(this.uDir,0,1/a),e.drawArrays(e.TRIANGLE_STRIP,0,4),e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,l.width,l.height),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),e.bindTexture(e.TEXTURE_2D,this.texA),e.uniform2f(this.uDir,0,0),e.uniform1f(this.uIntensity,this.glow),e.drawArrays(e.TRIANGLE_STRIP,0,4),e.bindTexture(e.TEXTURE_2D,null),e.bindVertexArray(null)}drawSliceTexture(e,t){if(!this.ensureScreenPipeline()||!this.screenProgram)return!1;let i=this.sliceTex.get(t)??null;if(!i){if(!(i=e.createTexture()))return!1;this.sliceTex.set(t,i),e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.useProgram(this.screenProgram),e.bindVertexArray(this.quadVao),e.uniform1i(this.uTex,0),e.uniform2f(this.uDir,0,0),e.uniform1f(this.uIntensity,1),e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLE_STRIP,0,4),e.bindVertexArray(null),!0}emitGlowSources(e,t,i,r,l,n){let a=(t,i,a)=>{(0,o.xcs)(t)&&(0,o.oBL)(t,"pane")&&"histogram"!==t.kind&&"columns"!==t.kind&&("circles"===t.kind||"cross"===t.kind?this.emitPointMarkers(e,t,i,r,l,n,a):this.emitPolyline(e,t,i,r,l,n,"step"===t.kind,a))};for(let e of t.indicatorsForPane(i.id)){let o=t.offsetOf(e.id),r=t.scaleFor(e,i),l=r===i.scale?i:{...i,scale:r};for(let t of e.series)!0!==t.overlay&&a(t,l,o)}if("price"===i.kind)for(let e of t.indicators.values()){let o=t.offsetOf(e.id);for(let t of e.series)!0===t.overlay&&a(t,i,o)}}destroy(){let e=this.gl;if(this.canvas&&(this.canvas.removeEventListener("webglcontextlost",this.onLost),this.canvas.removeEventListener("webglcontextrestored",this.onRestored)),e){for(let t of(this.program&&e.deleteProgram(this.program),this.vbo&&e.deleteBuffer(this.vbo),this.vao&&e.deleteVertexArray(this.vao),this.screenProgram&&e.deleteProgram(this.screenProgram),this.quadVbo&&e.deleteBuffer(this.quadVbo),this.quadVao&&e.deleteVertexArray(this.quadVao),this.sliceTex.values()))e.deleteTexture(t);this.sliceTex.clear(),this.deleteFbos(e),e.getExtension("WEBGL_lose_context")?.loseContext()}this.gl=null,this.canvas=null,this.program=null,this.vao=null,this.vbo=null,this.screenProgram=null}emitBackground(e,t,i,o){let r=o.timeToX(t.from),l=o.timeToX(t.to);l<0||r>o.width||l<=r||e.rect(r,i.bounds.top,l-r,i.bounds.height,iF(t.color))}emitFill(e,t,i,o,r,l,n,a=0){let s=iG(t,i.fromSeriesId),h=iG(t,i.toSeriesId);if(s&&h)for(let t=Math.max(1,l);t<=n;t+=1){let l=s[t-1-a],n=h[t-1-a],d=s[t-a],c=h[t-a];if(!l||!n||!d||!c||null===l.value||null===n.value||null===d.value||null===c.value)continue;let p=r.logicalToX(t-1),u=r.logicalToX(t),g=r.priceToY(l.value,o.scale,o.bounds),m=r.priceToY(n.value,o.scale,o.bounds),b=r.priceToY(d.value,o.scale,o.bounds),f=r.priceToY(c.value,o.scale,o.bounds),v=g-m,y=b-f,w=v*y<0,C=i.gradient?.[t-1-a];if(C){let t=r.priceToY(C.topValue,o.scale,o.bounds),i=r.priceToY(C.bottomValue,o.scale,o.bounds),l=i===t?t+1:i,n=iF(C.topColor),a=iF(C.bottomColor),s=l-t,h=e=>ij(n,a,iU((e-t)/s));if(w){let t=v/(v-y),i=p+t*(u-p),o=g+t*(b-g),r=h(o);e.tri(p,g,h(g),i,o,r,p,m,h(m)),e.tri(i,o,r,u,b,h(b),u,f,h(f))}else e.quad4(p,g,h(g),u,b,h(b),u,f,h(f),p,m,h(m))}else{let o=i.colors?i.colors[t-1-a]:i.color;if(!o)continue;let r=iF(o);if(w){let t=v/(v-y),i=p+t*(u-p),o=g+t*(b-g);e.tri(p,g,r,i,o,r,p,m,r),e.tri(i,o,r,u,b,r,u,f,r)}else e.quad(p,g,u,b,u,f,p,m,r)}}}emitPriceSeries(e,t,i,o,r,l,n,a,s){if("none"===t.basePainting)return;let h=t.bars,d=t.style;switch(t.priceStyle){case"bars":this.emitBars(e,h,i,o,r,l,d.bars.upColor??n.upColor,d.bars.downColor??n.downColor,a);return;case"line":this.emitPriceLine(e,h,i,o,r,l,iF(d.line.color??n.upColor),d.line.width);return;case"linemarkers":{let t=iF(d.line.color??n.upColor);this.emitPriceLine(e,h,i,o,r,l,t,d.line.width),this.emitLineMarkers(e,h,i,o,r,l,t,d.line.width);return}case"stepline":this.emitStepLine(e,h,i,o,r,l,iF(d.line.color??n.upColor),d.line.width);return;case"area":{let t=d.area.lineColor??n.upColor;this.emitPriceArea(e,h,i,o,r,l,iF(d.area.topColor??t),iF(d.area.bottomColor??"rgba(0,0,0,0)")),this.emitPriceLine(e,h,i,o,r,l,iF(t),d.area.width);return}case"baseline":this.emitBaseline(e,h,i,o,r,l,t,n,s);return;case"columns":{let t=d.columns.upColor??(0,p.fu)(n.upColor,.5),s=d.columns.downColor??(0,p.fu)(n.downColor,.5);this.emitColumns(e,h,i,o,r,l,t,s,a);return}default:this.emitCandles(e,t,h,i,o,r,l,n,a)}}emitBars(e,t,i,o,r,l,n,a,s){let h=r.bodySpacing(),d=t1(h);if("aggregate"===d)return void this.emitCandlesAggregated(e,t,i,o,r,l,e=>s.get(e.time)??(e.close>=e.open?n:a));let c=Math.max(1,Math.round(.35*h)),p="full"===d;for(let h=i;h<=o;h+=1){let i=t[h];if(!i||i.high<=i.low)continue;let o=iF(s.get(i.time)??(i.close>=i.open?n:a)),d=Math.round(r.logicalToX(h)),u=r.priceToY(i.high,l.scale,l.bounds),g=r.priceToY(i.low,l.scale,l.bounds);if(e.rect(d-.5,u,1,g-u,o),p){let t=r.priceToY(i.open,l.scale,l.bounds),n=r.priceToY(i.close,l.scale,l.bounds);e.rect(d-c,t-.5,c,1,o),e.rect(d,n-.5,c,1,o)}}}emitPriceLine(e,t,i,o,r,l,n,a){let s=Math.max(1,a)/2,h=i$(s),d=!1,c=0,p=0;for(let u=Math.max(0,i-1);u<=o;u+=1){let i=t[u];if(!i){d=!1;continue}let o=r.logicalToX(u),g=r.priceToY(i.close,l.scale,l.bounds);d&&e.seg(c,p,o,g,a,n),e.circle(o,g,s,n,h),c=o,p=g,d=!0}}emitLineMarkers(e,t,i,o,r,l,n,a){let s=iC(a);if(!(r.pxPerBar()>=2*s+2))return;let h=Math.max(16,Math.ceil(2*s));for(let a=Math.max(0,i-1);a<=o;a+=1){let i=t[a];i&&e.circle(r.logicalToX(a),r.priceToY(i.close,l.scale,l.bounds),s,n,h)}}emitStepLine(e,t,i,o,r,l,n,a){let s=r.dpr,h=Math.max(1,a)/2;for(let d of iT(Math.max(0,i-1),o,e=>{let i=t[e];return i?{x:iS(r.logicalToX(e),a,s),y:iS(r.priceToY(i.close,l.scale,l.bounds),a,s)}:null})){let t=iM(d);for(let i=1;i<t.length;i+=1){let o=t[i-1],r=t[i];if(o.y===r.y){let t=1===i?o.x-h:o.x+h,l=r.x+h;l>t&&e.rect(t,o.y-h,l-t,2*h,n)}else{let t=r.y>o.y?o.y+h:r.y-h,i=r.y>o.y?r.y+h:o.y-h;i>t&&e.rect(o.x-h,t,2*h,i-t,n)}}}}emitColumns(e,t,i,o,r,l,n,a,s){let h=r.bodySpacing(),d=r.dpr,c=t2(l.bounds.top+l.bounds.height,d),p=iF(n),u=iF(a);for(let n=i;n<=o;n+=1){let i=t[n];if(!i)continue;let o=t2(r.priceToY(i.close,l.scale,l.bounds),d);if(!(o<c))continue;let a=ik(r.logicalToX(n),h,d),g=s.get(i.time);e.rect(a.left,o,a.width,c-o,g?iF(g):ix(t,n)?p:u)}}emitPriceArea(e,t,i,o,r,l,n,a){let s=l.bounds.top+l.bounds.height,h=[],d=1/0,c=()=>{if(h.length>=2){let t=s-d,i=e=>ij(n,a,t<1e-6?0:iU((e-d)/t));for(let t=1;t<h.length;t+=1){let o=h[t-1],r=h[t];e.quad4(o.x,o.y,i(o.y),r.x,r.y,i(r.y),r.x,s,a,o.x,s,a)}}h.length=0,d=1/0};for(let e=Math.max(0,i-1);e<=o;e+=1){let i=t[e];if(!i){c();continue}let o=r.logicalToX(e),n=r.priceToY(i.close,l.scale,l.bounds);h.push({x:o,y:n}),n<d&&(d=n)}c()}emitBaseline(e,t,i,o,r,l,n,a,s){let h=n.baselinePriceFor(l.scale),d=r.priceToY(h,l.scale,l.bounds),c=n.style.baseline,u=c.topLineColor??t4,g=c.bottomLineColor??t6,m=iF(u),b=iF(g),f=iF(c.topFillColor??(0,p.fu)(u,.25)),v=iF(c.topFillColor2??(0,p.fu)(u,.05)),y=iF(c.bottomFillColor??(0,p.fu)(g,.25)),w=iF(c.bottomFillColor2??(0,p.fu)(g,.05)),C=[];for(let e=Math.max(0,i-1);e<=o;e+=1){let i=t[e];i&&C.push({x:r.logicalToX(e),y:r.priceToY(i.close,l.scale,l.bounds)})}if(C.length<2)return;let x=l.bounds.top,k=l.bounds.top+l.bounds.height,S=e=>e<=d?v:w,T=e=>{let t=e<=d,i=t?d-x:k-d;return ij(t?v:w,t?f:y,i>0?iU(Math.abs(e-d)/i):0)};for(let t=1;t<C.length;t+=1){let i=C[t-1],o=C[t];if(i.y<=d!=o.y<=d&&o.y!==i.y){let t=(d-i.y)/(o.y-i.y),r=i.x+(o.x-i.x)*t;e.tri(i.x,i.y,T(i.y),r,d,S(i.y),i.x,d,S(i.y)),e.tri(r,d,S(o.y),o.x,o.y,T(o.y),o.x,d,S(o.y))}else e.quad4(i.x,i.y,T(i.y),o.x,o.y,T(o.y),o.x,d,S(o.y),i.x,d,S(i.y))}e.dashedSeg(0,d,s,d,1,iF(n.style.borderColor??a.borderColor),iD.dashed??null);for(let t=1;t<C.length;t+=1){let i=C[t-1],o=C[t],r=i.y<=d,l=o.y<=d;if(r!==l&&o.y!==i.y){let t=(d-i.y)/(o.y-i.y),n=i.x+(o.x-i.x)*t;e.seg(i.x,i.y,n,d,c.width,r?m:b),e.seg(n,d,o.x,o.y,c.width,l?m:b)}else e.seg(i.x,i.y,o.x,o.y,c.width,r?m:b)}}emitCandles(e,t,i,o,r,l,n,a,s){let h=l.bodySpacing(),d=t1(h),c=ia(t.style.candle,t.candleOverride,a.upColor,a.downColor),p=c.up,u=c.down,g=c.candle,m=tQ(g);if("none"===m)return;let b=g.bodyVisible?this.candleBodyAlpha:this.candleStructureAlpha;if("aggregate"===d){"body"===m&&(e.alpha=b),this.emitCandlesAggregated(e,i,o,r,l,n,e=>{let t=e.close>=e.open;return tJ(g,m,t,s.get(e.time)??(t?p:u))},m);return}let f="full"===d,v=!f&&"body"===m,y=this.candleStructureAlpha>this.candleBodyAlpha+.001;for(let t=o;t<=r;t+=1){let o=i[t];if(!o||o.high<=o.low)continue;let r=t5(l.logicalToX(t),h,l.dpr,this.candleBodyScale),a=o.close>=o.open,d=a?p:u,c=s.get(o.time)??d,m=iF(c),w=0,C=0;if(f||v){let e=l.priceToY(o.open,n.scale,n.bounds),t=l.priceToY(o.close,n.scale,n.bounds);w=t2(Math.min(e,t),l.dpr),C=Math.max(1/l.dpr,t2(Math.max(e,t),l.dpr)-w)}if(v)e.alpha=b,e.rect(r.wickX,w,r.wickW,C,iF(tJ(g,"body",a,c)));else if(g.wickVisible){let t=t2(l.priceToY(o.high,n.scale,n.bounds),l.dpr),i=t2(l.priceToY(o.low,n.scale,n.bounds),l.dpr);e.alpha=this.candleStructureAlpha;let s=iF((a?g.wickUpColor:g.wickDownColor)??(f?d:c));f?(e.rect(r.wickX,t,r.wickW,Math.max(0,w-t),s),e.rect(r.wickX,w+C,r.wickW,Math.max(0,i-(w+C)),s)):e.rect(r.wickX,t,r.wickW,i-t,s)}if(f&&(g.bodyVisible&&(e.alpha=this.candleBodyAlpha,e.rect(r.bodyX,w,r.bodyW,C,m)),g.borderVisible||y&&g.bodyVisible)){e.alpha=this.candleStructureAlpha;let t=g.borderVisible?iF((a?g.borderUpColor:g.borderDownColor)??c):m,i=Math.max(0,r.bodyW-1),o=Math.max(0,C-1);e.rectStroke(r.bodyX+.5,w+.5,i,o,1,t)}}}emitCandlesAggregated(e,t,i,o,r,l,n,a="range"){let s=e=>r.priceToY(e,l.scale,l.bounds),h="body"===a?1/r.dpr:0;for(let l of t3(t,i,o,e=>r.logicalToX(e),s,n,a)){let t=iF(l.color),i=s(l.hi);e.rect(l.x-.5,i,1,Math.max(h,s(l.lo)-i),t)}}emitSeries(e,t,i,r,l,n,a,s=0){if((0,o.oBL)(t,"pane")){if("candle"===t.kind||"bar"===t.kind)return void this.emitPlotCandles(e,t,i,r,l,n,a,s);if((0,o.xcs)(t))switch(t.kind){case"histogram":case"columns":this.emitHistogram(e,t,i,r,l,n,s);break;case"area":this.emitArea(e,t,i,r,l,n,s),this.emitPolyline(e,t,i,r,l,n,!1,s);break;case"circles":case"cross":this.emitPointMarkers(e,t,i,r,l,n,s);break;case"step":this.emitPolyline(e,t,i,r,l,n,!0,s);break;default:this.emitPolyline(e,t,i,r,l,n,!1,s)}}}emitPolyline(e,t,i,o,r,l,n,a=0){let s=Math.max(1,t.style.width),h=s/2,d=iD[t.style.lineStyle]??null,c=!d&&!n,p=i$(h),u=!1;for(let g=Math.max(1,r-1);g<=l;g+=1){let r=t.points[g-a],l=t.points[g-1-a];if(!r||null===r.value||!l||null===l.value){u=!1;continue}let m=o.logicalToX(g),b=o.priceToY(r.value,i.scale,i.bounds),f=o.logicalToX(g-1),v=o.priceToY(l.value,i.scale,i.bounds),y=iF(r.color??t.style.color);n?(e.dashedSeg(f,v,m,v,s,y,d),e.dashedSeg(m,v,m,b,s,y,d)):e.dashedSeg(f,v,m,b,s,y,d),c&&(u||e.circle(f,v,h,iF(l.color??t.style.color),p),e.circle(m,b,h,y,p)),u=!0}}emitArea(e,t,i,o,r,l,n=0){let a=i.bounds.top+i.bounds.height,s=iF(t.style.color),h=[],d=1/0,c=()=>{if(h.length<1){h=[],d=1/0;return}let t=a-d,i=e=>(function(e,t){let i=1-t;return[e[0]*i,e[1]*i,e[2]*i,e[3]*i]})(s,t<1e-6?0:iU((e-d)/t));for(let t=1;t<h.length;t+=1){let o=h[t-1],r=h[t];e.quad4(o.x,o.y,i(o.y),r.x,r.y,i(r.y),r.x,a,iq,o.x,a,iq)}h=[],d=1/0};for(let e=r;e<=l;e+=1){let r=t.points[e-n];if(!r||null===r.value){c();continue}let l=o.logicalToX(e),a=o.priceToY(r.value,i.scale,i.bounds);h.push({x:l,y:a}),a<d&&(d=a)}c()}emitHistogram(e,t,i,o,r,l,n=0){let a=o.bodySpacing(),s=Math.max(1,("columns"===t.kind?.7:.8)*a),h=s/2,d=t.style.base??0,c=o.priceToY(d,i.scale,i.bounds);for(let a=r;a<=l;a+=1){let r=t.points[a-n];if(!r||null===r.value)continue;let l=o.logicalToX(a),d=o.priceToY(r.value,i.scale,i.bounds);e.rect(l-h,Math.min(c,d),s,Math.max(1,Math.abs(d-c)),iF(r.color??t.style.color))}}emitPointMarkers(e,t,i,o,r,l,n=0){let a=Math.max(1.5,t.style.width);for(let s=r;s<=l;s+=1){let r=t.points[s-n];if(!r||null===r.value)continue;let l=o.logicalToX(s),h=o.priceToY(r.value,i.scale,i.bounds),d=iF(r.color??t.style.color);"cross"===t.kind?(e.seg(l-a,h,l+a,h,1,d),e.seg(l,h-a,l,h+a,1,d)):e.circle(l,h,a,d,Math.max(16,Math.ceil(2*a)))}}emitPlotCandles(e,t,i,o,r,l,n,a=0){let s=o.bodySpacing(),h=t.style?.up??n.upColor,d=t.style?.down??n.downColor,c="bar"===t.kind,p=Math.max(.5,Math.floor(.7*s)/2),u=Math.max(1,Math.round(.35*s));for(let n=r;n<=l;n+=1){let r=t.bars[n-a];if(!r||!Number.isFinite(r.open+r.high+r.low+r.close))continue;let l=t.barColors?.[n-a],g=iF(l?.color??(r.close>=r.open?h:d)),m=Math.round(o.logicalToX(n)),b=o.priceToY(r.high,i.scale,i.bounds),f=o.priceToY(r.low,i.scale,i.bounds),v=o.priceToY(r.open,i.scale,i.bounds),y=o.priceToY(r.close,i.scale,i.bounds);if(c){e.rect(m-.5,b,1,f-b,g),e.rect(m-u,v-.5,u,1,g),e.rect(m,y-.5,u,1,g);continue}let w=Math.max(1,Math.round(t0(s)*o.dpr)),C=(Math.round(m*o.dpr)-(w>>1))/o.dpr;e.rect(C,b,w/o.dpr,f-b,iF(l?.wickColor??l?.color??(r.close>=r.open?h:d)));let x=Math.min(v,y),k=Math.max(1,Math.abs(y-v));if(e.rect(m-p,x,2*p,k,g),l?.borderColor){let t=iF(l.borderColor);e.rect(m-p,x,2*p,1,t),e.rect(m-p,x+k-1,2*p,1,t),e.rect(m-p,x,1,k,t),e.rect(m+p-1,x,1,k,t)}}}emitHline(e,t,i,o,r,l){let n=Math.round(o.priceToY(t.price,i.scale,i.bounds));n<i.bounds.top||n>i.bounds.top+i.bounds.height||e.dashedSeg(0,n,r,n,t.width??1,iF(t.color??l.textColor),iD[t.lineStyle??"solid"]??null)}};function iW(e,t,i){let o=e.createShader(t);return o?(e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS))?o:(e.deleteShader(o),null):null}var iq=[0,0,0,0];function iU(e){return e<0?0:e>1?1:e}function ij(e,t,i){return[e[0]+(t[0]-e[0])*i,e[1]+(t[1]-e[1])*i,e[2]+(t[2]-e[2])*i,e[3]+(t[3]-e[3])*i]}function iG(e,t){let i=e.series.find(e=>e.id===t);return i&&(0,o.xcs)(i)?i.points:null}var iK=new Map;function iY(){return{barSpacing:8,rightOffset:6}}function iZ(e){return Math.max(.5,Math.min(1e3,e))}function iX(e){if(e.length<2)return 0;let t=[];for(let i=1;i<e.length;i+=1){let o=e[i]-e[i-1];o>0&&t.push(o)}return 0===t.length?0:(t.sort((e,t)=>e-t),t[Math.floor(t.length/2)])}var i_=class{constructor(){this.widthPx=0,this.dataHeightPx=0,this.devicePixelRatio=1,this.viewport=iY(),this.pitchScale=1,this.times=[],this.intervalMs=0}setSize(e,t,i){this.widthPx=e,this.dataHeightPx=t,this.devicePixelRatio=i>0?i:1}setBars(e){this.times=e.slice(),this.intervalMs=iX(this.times)}appendBar(e){this.times.push(e),this.intervalMs<=0&&this.times.length>=2&&(this.intervalMs=iX(this.times))}setViewport(e){this.viewport=e}getViewport(){return this.viewport}setPitchScale(e){this.pitchScale=Number.isFinite(e)&&e>0?e:1}get spacingScale(){return this.pitchScale}pxPerBar(){return this.viewport.barSpacing*this.pitchScale}bodySpacing(){return this.viewport.barSpacing*Math.min(1,this.pitchScale)}get width(){return this.widthPx}get height(){return this.dataHeightPx}get dpr(){return this.devicePixelRatio}get barCount(){return this.times.length}get barInterval(){return this.intervalMs}get rightEdgeLogical(){return this.barCount-1+this.viewport.rightOffset}logicalToX(e){return this.widthPx-(this.rightEdgeLogical-e)*this.pxPerBar()}xToLogical(e){return this.rightEdgeLogical-(this.widthPx-e)/this.pxPerBar()}timeToLogical(e){return function(e,t,i){let o=t.length;if(0===o)return 0;let r=t[0],l=t[o-1];if(e<=r)return i>0?(e-r)/i:0;if(e>=l)return o-1+(i>0?(e-l)/i:0);let n=0,a=o-1;for(;a-n>1;){let i=n+a>>1;t[i]<=e?n=i:a=i}let s=t[a]-t[n];return s>0?n+(e-t[n])/s:n}(e,this.times,this.intervalMs)}logicalToTime(e){return function(e,t,i){let o=t.length;if(0===o)return 0;if(e<=0)return t[0]+(i>0?e*i:0);if(e>=o-1)return t[o-1]+(i>0?(e-(o-1))*i:0);let r=Math.floor(e);return t[r]+(t[r+1]-t[r])*(e-r)}(e,this.times,this.intervalMs)}timeToX(e){return this.logicalToX(this.timeToLogical(e))}priceToY(e,t,i){if(t.log&&t.min>0&&t.max>t.min&&e>0){let o=Math.log(t.min),r=(Math.log(e)-o)/(Math.log(t.max)-o);return i.top+i.height*(t.invert?r:1-r)}let o=t.max-t.min;if(o<=0)return i.top+i.height/2;let r=(e-t.min)/o;return i.top+i.height*(t.invert?r:1-r)}yToPrice(e,t,i){if(i.height<=0)return t.min;let o=(e-i.top)/i.height,r=t.invert?o:1-o;if(t.log&&t.min>0&&t.max>t.min){let e=Math.log(t.min);return Math.exp(e+r*(Math.log(t.max)-e))}return t.min+(t.max-t.min)*r}visibleLogicalRange(){return{from:this.xToLogical(0),to:this.xToLogical(this.widthPx)}}visibleTimeRange(){let e=this.visibleLogicalRange();return{from:this.logicalToTime(e.from),to:this.logicalToTime(e.to)}}toBitmap(e){return Math.round(e*this.devicePixelRatio)}};function iQ(e,t){e.setTransform(t,0,0,t,0,0),e.direction="ltr"}var iJ=class{constructor(e,t,i){this.onFrame=e,this.level=0,this.handle=null,this.raf=t??(e=>requestAnimationFrame(e)),this.cancel=i??(e=>cancelAnimationFrame(e))}invalidate(e){e<=0||(e>this.level&&(this.level=e),null===this.handle&&(this.handle=this.raf(()=>this.flush())))}flushNow(e){null!==this.handle&&(this.cancel(this.handle),this.handle=null),e>this.level&&(this.level=e),this.flush()}flush(){this.handle=null;let e=this.level;this.level=0,0!==e&&this.onFrame(e)}destroy(){null!==this.handle&&(this.cancel(this.handle),this.handle=null),this.level=0}},i0=class{constructor(e,t,i,o){this.tick=e,this.handle=null,this.last=0,this.stopped=!1,this.loop=()=>{let e=this.now(),t=e-this.last;this.last=e;let i=this.tick(Math.min(t,64));this.handle=i&&!this.stopped?this.raf(this.loop):null},this.raf=t??(e=>requestAnimationFrame(e)),this.cancel=i??(e=>cancelAnimationFrame(e)),this.now=o??(()=>performance.now())}get active(){return null!==this.handle}start(){this.stopped=!1,null===this.handle&&(this.last=this.now(),this.handle=this.raf(this.loop))}stop(){this.stopped=!0,null!==this.handle&&(this.cancel(this.handle),this.handle=null)}},i1=class{constructor(e,t=e){this.onMs=e,this.ms=t}get tau(){return this.ms}get on(){return this.ms>0}set(e){this.ms=e,e>0&&(this.onMs=e)}toggle(e){this.ms=e?this.onMs:0}};function i2(e,t,i,o){return o<=0?t:e+(t-e)*(1-Math.exp(-i/o))}var i5=class{constructor(e){this.deps=e,this.rightEdgeZoom=!0,this.axisDrag=!0,this.paneResize=!0,this.drawings=!0,this.freePan=!1,this.el=null,this.dragging=!1,this.moved=!1,this.region="data",this.verticalPan=!1,this.freePending=!1,this.startX=0,this.startY=0,this.startRightOffset=0,this.startBarSpacing=0,this.lastX=0,this.lastT=0,this.vx=0,this.middleDeleted=!1,this.rightCancelled=!1,this.cursorX=NaN,this.cursorY=NaN,this.touches=new Map,this.lpTimer=null,this.pinchStartDist=1,this.pinchStartBarSpacing=0,this.pinchAnchorLogical=0,this.lastTapT=0,this.lastTapX=0,this.lastTapY=0,this.lastPressDrawing=!1,this.prevPressDrawing=!1,this.onTouchContextMenu=e=>{0!==this.touches.size&&e.target instanceof Node&&this.el?.contains(e.target)&&(e.preventDefault(),e.stopImmediatePropagation())},this.onMiddleGuard=e=>{1===e.button&&this.middleDeleted&&e.preventDefault()},this.onContextGuard=e=>{this.rightCancelled&&(this.rightCancelled=!1,e.preventDefault(),e.stopPropagation())},this.onModifier=e=>{!(e.repeat||"Shift"!==e.key&&"Control"!==e.key&&"Meta"!==e.key||Number.isNaN(this.cursorX))&&(this.dragging?"drawing"===this.region:this.drawings)&&this.deps.drawingsPointerMove?.(this.cursorX,this.cursorY,this.snapMode(e),e.shiftKey,e.ctrlKey||e.metaKey)},this.onDown=e=>{let{x:t,y:i}=this.local(e),o="data"===this.regionAt(t,i)&&function(e,t){return!!e&&"touch"!==t.pointerType&&("function"==typeof e?!!e(t):0===t.button&&(!0===e||"drag"===e?!t.altKey&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey:"alt"===e?t.altKey&&!t.shiftKey&&!t.ctrlKey&&!t.metaKey:"shift"===e?t.shiftKey&&!t.altKey&&!t.ctrlKey&&!t.metaKey:"mod"===e&&(t.ctrlKey||t.metaKey)&&!t.altKey&&!t.shiftKey))}(this.freePan,e);if(1===e.button&&!o){this.middleDeleted=this.drawings&&(this.deps.drawingsDeleteAt?.(t,i)??!1),this.middleDeleted&&e.preventDefault();return}if(2===e.button&&!o){this.rightCancelled=this.drawings&&(this.deps.drawingsCancelPlacement?.()??!1),this.rightCancelled&&e.preventDefault();return}if(0!==e.button&&!o)return;if(0!==e.button&&(1===e.button&&(this.middleDeleted=!0),e.preventDefault()),"touch"===e.pointerType){if(1===this.touches.size&&this.dragging&&("data"===this.region||"crosshair"===this.region)){this.touches.set(e.pointerId,{x:t,y:i}),this.beginPinch(e);return}if(this.touches.size>=1)return;this.touches.set(e.pointerId,{x:t,y:i})}if(this.deps.drawingsClearTransient?.(),this.dragging=!0,this.moved=!1,this.startX=t,this.startY=i,this.prevPressDrawing=this.lastPressDrawing,this.lastPressDrawing=!1,0===e.button&&this.drawings&&this.deps.drawingsClaim?.(t,i)){this.region="drawing",this.lastPressDrawing=!0,this.deps.drawingsPointerDown?.(t,i,this.snapMode(e),e.shiftKey,e.ctrlKey||e.metaKey),this.capture(e.pointerId);return}if(!o&&this.drawings&&e.shiftKey&&"data"===this.regionAt(t,i)&&this.deps.drawingsMeasureStart?.(t,i,this.snapMode(e))||!o&&this.drawings&&(e.ctrlKey||e.metaKey)&&"data"===this.regionAt(t,i)&&this.deps.drawingsMarqueeStart?.(t,i)){this.region="drawing",this.lastPressDrawing=!0,this.capture(e.pointerId);return}let r=this.deps.getCoords().getViewport();this.deps.apply(r),this.startRightOffset=r.rightOffset,this.startBarSpacing=r.barSpacing,this.region=this.regionAt(t,i),this.verticalPan=!1,this.freePending=!1,"price"===this.region?this.deps.beginPriceScale(t,i):"separator"===this.region?this.deps.beginPaneResize(i):"data"===this.region&&(this.verticalPan=this.deps.beginPricePan(i),this.freePending=!this.verticalPan&&o),"touch"===e.pointerType&&("data"===this.region||"price"===this.region||"time"===this.region)&&this.startLongPress(t,i,this.region),this.lastX=t,this.lastT=e.timeStamp,this.vx=0,this.capture(e.pointerId)},this.onMove=e=>{let{x:t,y:i}=this.local(e);if(this.cursorX=t,this.cursorY=i,"touch"===e.pointerType&&this.touches.has(e.pointerId)&&this.touches.set(e.pointerId,{x:t,y:i}),this.dragging&&"pinch"===this.region)return void this.applyPinch();if(this.dragging&&"crosshair"===this.region)return void this.deps.onPointerMove(t,i);if(this.dragging&&"axis-sheet"===this.region)return;null!==this.lpTimer&&Math.hypot(t-this.startX,i-this.startY)>8&&this.cancelLongPress();let o="touch"===e.pointerType?8:2;if(this.dragging)if("price"===this.region)Math.abs(i-this.startY)>o&&(this.moved=!0),this.deps.priceScaleBy(i-this.startY);else if("separator"===this.region)Math.abs(i-this.startY)>o&&(this.moved=!0),this.deps.paneResizeBy(i-this.startY);else if("time"===this.region){Math.abs(t-this.startX)>o&&(this.moved=!0);let e=iZ(this.startBarSpacing*Math.exp((this.startX-t)*.004));this.deps.apply({barSpacing:e,rightOffset:this.startRightOffset})}else if("drawing"===this.region)(Math.abs(t-this.startX)>o||Math.abs(i-this.startY)>o)&&(this.moved=!0),this.deps.drawingsPointerMove?.(t,i,this.snapMode(e),e.shiftKey,e.ctrlKey||e.metaKey);else{let r=this.deps.getCoords(),l=r.getViewport(),n=t-this.startX;Math.abs(n)>o&&(this.moved=!0),this.freePending&&(this.moved||Math.abs(i-this.startY)>o)&&(this.freePending=!1,this.moved=!0,this.verticalPan=this.deps.beginPricePan(this.startY,!0)),this.deps.apply({barSpacing:l.barSpacing,rightOffset:this.startRightOffset-n/r.pxPerBar()}),this.verticalPan&&(Math.abs(i-this.startY)>o&&(this.moved=!0),this.deps.pricePanBy(i-this.startY));let a=e.timeStamp-this.lastT;if(a>0){let i=(t-this.lastX)/a;this.vx=.6*this.vx+.4*i,this.lastX=t,this.lastT=e.timeStamp}}else if(this.el){let o=this.deps.drawingsCursor?.(t,i),r=this.regionAt(t,i);this.el.style.cursor=o??("price"===r?"ns-resize":"time"===r?"ew-resize":"separator"===r?"row-resize":""),this.drawings&&this.deps.drawingsPointerMove?.(t,i,this.snapMode(e),e.shiftKey,e.ctrlKey||e.metaKey)}"touch"!==e.pointerType&&this.deps.onPointerMove(t,i)},this.onUp=e=>{if("touch"===e.pointerType&&this.touches.delete(e.pointerId),this.cancelLongPress(),this.dragging&&"pinch"===this.region){if(1===this.touches.size){let t=[...this.touches.values()][0],i=this.deps.getCoords().getViewport();this.region="data",this.verticalPan=!1,this.startX=t.x,this.startY=t.y,this.startRightOffset=i.rightOffset,this.startBarSpacing=i.barSpacing,this.lastX=t.x,this.lastT=e.timeStamp,this.vx=0;return}this.endGesture(e);return}if(this.dragging&&"crosshair"===this.region){this.deps.onPointerMove(null,null),this.endGesture(e);return}if(this.dragging&&"axis-sheet"===this.region)return void this.endGesture(e);let{x:t,y:i}=this.local(e),o="touch"===e.pointerType,r=this.dragging&&!this.moved&&(!o||14>=Math.hypot(t-this.startX,i-this.startY));if(this.dragging&&"drawing"===this.region)this.deps.drawingsPointerUp?.(t,i,this.snapMode(e));else if(this.dragging&&"separator"===this.region)this.deps.endPaneResize?.();else if(r&&"data"===this.region&&0===e.button)this.deps.onClick(t,i);else if(this.dragging&&"data"===this.region&&o&&!(e.timeStamp-this.lastT>60)&&Math.abs(this.vx)>.04){let e=this.deps.getCoords().pxPerBar();this.deps.fling(-this.vx/e)}this.endGesture(e),o&&this.deps.onPointerMove(null,null),o&&r&&this.registerTap(e.timeStamp,t,i)},this.onCancel=e=>{"touch"===e.pointerType&&this.touches.delete(e.pointerId),this.cancelLongPress(),this.dragging&&("drawing"!==this.region||Number.isNaN(this.cursorX)||this.deps.drawingsPointerUp?.(this.cursorX,this.cursorY,this.snapMode(e)),"separator"===this.region&&this.deps.endPaneResize?.(),("crosshair"===this.region||"touch"===e.pointerType)&&this.deps.onPointerMove(null,null),this.endGesture(e))},this.onLeave=()=>{this.cursorX=NaN,this.cursorY=NaN,this.deps.onPointerMove(null,null)},this.onDblClick=e=>{let{x:t,y:i}=this.local(e);this.doubleActivate(t,i)},this.onWheel=e=>{e.preventDefault(),this.deps.drawingsClearTransient?.();let{x:t,y:i}=this.local(e);if("price"===this.regionAt(t,i)&&0!==e.deltaY){this.deps.beginPriceScale(t,i),this.deps.priceScaleBy(.25*e.deltaY);return}let o=this.deps.getCoords(),r=o.getViewport(),l=function(e,t,i){return Math.abs(e)>Math.abs(t)?e:i?t:null}(e.deltaX,e.deltaY,e.shiftKey);if(null!=l)return void this.deps.apply({barSpacing:r.barSpacing,rightOffset:r.rightOffset+l/o.pxPerBar()});let n=function(e,t,i){return i?{logical:e.rightEdgeLogical,x:e.width}:{logical:e.xToLogical(t),x:t}}(o,t,this.rightEdgeZoom&&!(e.ctrlKey||e.metaKey)),a=iZ(r.barSpacing*Math.exp(-(.004*e.deltaY)));this.deps.zoomTo(a,n.logical,n.x)}}attach(e){this.el=e,void 0!==e.style&&(e.style.touchAction="none",e.style.userSelect="none",e.style.setProperty("-webkit-user-select","none"),e.style.setProperty("-webkit-touch-callout","none")),e.addEventListener("pointerdown",this.onDown),e.addEventListener("pointermove",this.onMove),e.addEventListener("pointerup",this.onUp),e.addEventListener("pointerleave",this.onLeave),e.addEventListener("pointercancel",this.onCancel),e.addEventListener("dblclick",this.onDblClick),e.addEventListener("wheel",this.onWheel,{passive:!1}),e.addEventListener("mousedown",this.onMiddleGuard),e.addEventListener("auxclick",this.onMiddleGuard),e.addEventListener("contextmenu",this.onContextGuard);let t=e.ownerDocument?.defaultView;t?.addEventListener("keydown",this.onModifier),t?.addEventListener("keyup",this.onModifier),t?.addEventListener("contextmenu",this.onTouchContextMenu,!0)}detach(){let e=this.el;if(!e)return;let t=e.ownerDocument?.defaultView;t?.removeEventListener("keydown",this.onModifier),t?.removeEventListener("keyup",this.onModifier),t?.removeEventListener("contextmenu",this.onTouchContextMenu,!0),e.removeEventListener("pointerdown",this.onDown),e.removeEventListener("pointermove",this.onMove),e.removeEventListener("pointerup",this.onUp),e.removeEventListener("pointerleave",this.onLeave),e.removeEventListener("pointercancel",this.onCancel),e.removeEventListener("dblclick",this.onDblClick),e.removeEventListener("wheel",this.onWheel),e.removeEventListener("mousedown",this.onMiddleGuard),e.removeEventListener("auxclick",this.onMiddleGuard),e.removeEventListener("contextmenu",this.onContextGuard),this.cancelLongPress(),this.touches.clear(),this.el=null}local(e){let t=this.el.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}regionAt(e,t){let i=this.deps.getCoords();if(this.paneResize&&t<=i.height&&this.deps.paneSeparatorAt(t))return"separator";if(this.axisDrag){if(e>i.width&&t<=i.height)return"price";if(t>i.height&&e<=i.width)return"time"}return"data"}snapMode(e){var t,i;return t=e.ctrlKey||e.metaKey,i=this.deps.drawingsSnapMode?.()??"off",t?"strong":i}startLongPress(e,t,i){this.cancelLongPress(),this.lpTimer=setTimeout(()=>{if(this.lpTimer=null,this.dragging&&this.region===i){if("data"===i){this.region="crosshair",this.deps.onPointerMove(e,t);return}this.region="axis-sheet",this.moved=!0,this.deps.onAxisLongPress?.(i,e,t)}},350)}cancelLongPress(){null!==this.lpTimer&&clearTimeout(this.lpTimer),this.lpTimer=null}beginPinch(e){this.cancelLongPress(),"crosshair"===this.region&&this.deps.onPointerMove(null,null);let t=this.deps.getCoords(),i=t.getViewport();this.deps.apply(i);let[o,r]=[...this.touches.values()];this.pinchStartDist=Math.max(1,Math.hypot(o.x-r.x,o.y-r.y)),this.pinchStartBarSpacing=i.barSpacing,this.pinchAnchorLogical=t.xToLogical((o.x+r.x)/2),this.region="pinch",this.dragging=!0,this.moved=!0,this.vx=0,this.capture(e.pointerId)}applyPinch(){var e,t,i,o;let r=this.deps.getCoords(),l=[...this.touches.values()];if(l.length<2)return;let[n,a]=l,s=(e=this.pinchStartBarSpacing,t=this.pinchStartDist,iZ(Math.hypot(n.x-a.x,n.y-a.y)/Math.max(1,t)*e)),h=r.getViewport(),d=h.barSpacing>0?r.pxPerBar()/h.barSpacing:1,c=(n.x+a.x)/2;this.deps.apply({barSpacing:s,rightOffset:(i=this.pinchAnchorLogical,o=r.barCount,i-(o-1)+(r.width-c)/(s*d))})}capture(e){try{this.el?.setPointerCapture(e)}catch{}}registerTap(e,t,i){if(this.lastTapT>0&&e-this.lastTapT<=350&&30>=Math.hypot(t-this.lastTapX,i-this.lastTapY)){this.lastTapT=0,this.doubleActivate(this.lastTapX,this.lastTapY);return}this.lastTapT=e,this.lastTapX=t,this.lastTapY=i}endGesture(e){this.dragging=!1,this.freePending=!1;try{this.el?.releasePointerCapture(e.pointerId)}catch{}}doubleActivate(e,t){if(this.drawings&&this.deps.drawingsDblClick?.(e,t))return;let i=this.regionAt(e,t);if("price"===i)this.deps.resetPriceScale(e,t);else if("separator"===i)this.deps.resetPaneSize(t);else if("time"===i)this.deps.resetView();else{if(this.lastPressDrawing||this.prevPressDrawing)return;this.deps.dataDblClick(e,t)}}},i3=class{constructor(e){this.deps=e,this.el=null,this.onKey=e=>{if(this.deps.preempt?.(e))return void e.preventDefault();let t=function(e){if(e.ctrlKey||e.metaKey)return null;switch(e.key){case"ArrowLeft":return e.shiftKey?{kind:"pan",bars:-10}:{kind:"step",delta:-1};case"ArrowRight":if(e.altKey&&e.shiftKey)return{kind:"realtime"};return e.shiftKey?{kind:"pan",bars:10}:{kind:"step",delta:1};case"+":case"=":return{kind:"zoom",direction:1};case"-":case"_":return{kind:"zoom",direction:-1};case"Home":return{kind:"edge",edge:"first"};case"End":return{kind:"edge",edge:"last"};case"0":return{kind:"reset"};case"Escape":return{kind:"clear"};default:return null}}(e);if(t)switch(e.preventDefault(),t.kind){case"pan":this.deps.panByBars(t.bars);break;case"zoom":this.deps.zoomByStep(t.direction);break;case"step":this.deps.stepCrosshair(t.delta);break;case"edge":this.deps.jumpToEdge(t.edge);break;case"reset":this.deps.resetView();break;case"realtime":this.deps.scrollToRealtime();break;case"clear":this.deps.clearCrosshair()}}}attach(e){this.el=e,e.addEventListener("keydown",this.onKey)}detach(){this.el?.removeEventListener("keydown",this.onKey),this.el=null}},i4=r.kh,i6=r.UT,i8=r.we;function i7(e,t,i,o,r,l){let n=new Map;for(let a of e){let e=Math.round(i.timeToLogical(a.time));if(e<o||e>r)continue;let s=n.get(e);s||(s={logical:e,buys:[],sells:[]},n.set(e,s)),("buy"===a.side?s.buys:s.sells).push(function(e,t,i){let o=[];if(t.labels&&e.label&&o.push(e.label),t.qty){let t=function(e){if(null==e.qty||!Number.isFinite(e.qty))return null;let t=Number(Math.abs(e.qty).toFixed(8));return`${"buy"===e.side?"+":"-"}${t}`}(e);t&&o.push(t)}return{exec:e,lines:o,height:14+(o.length?3+o.length*i:0)}}(a,t,l))}return[...n.values()]}function i9(e){if(0===e.length)return 0;let t=10;for(let i of e)t+=i.height;return t+(e.length-1)*6}function oe(e,t){return"exit"===e.kind?t.exit:"buy"===e.side?t.long:t.short}function ot(e,t,i,o,r){let l="buy"===t?i-r:i+r,n="buy"===t?l-6:l+6;e.beginPath(),e.moveTo(l,o),e.lineTo(n,o-4),e.lineTo(n,o+4),e.closePath(),e.fill()}function oi(e,t,i,o,r,l){if(0!==t.length){e.fillStyle=l;for(let l=0;l<t.length;l+=1)e.fillText(t[l],i,o+l*r)}}function oo(e,t,i){let o=e[t];return"boolean"==typeof o?o:i.find(e=>e.id===t)?.visible!==!1}function or(e,t,i){if(void 0===t)return!0;let o=new Set,r=t;for(;void 0!==r&&!o.has(r);){if(o.add(r),!oo(e,r,i))return!1;let t=i.find(e=>e.id===r)?.parent;r=void 0!==t&&i.some(e=>e.id===t)?t:void 0}return!0}var ol=class{constructor(){this.panes=new Map,this.indicators=new Map,this.bars=[],this.volumeLayer=null,this.nativeData=new Map,this.nativePending=new Map,this.vpvrLayer=null,this.crosshair=null,this.crosshairOverride=null,this.priceStyle="candles",this.basePainting="candles",this.candleOverride=null,this.baselineValue=null,this.showPriceLine=!0,this.showPriceLabel=!0,this.showCountdown=!0,this.showIndicatorValueLabels=!0,this.showIndicatorNameLabels=!1,this.variableDuration=!1,this.logScale=!1,this.invertScale=!1,this.scalePriceOnly=!1,this.priceMintick=void 0,this.symbolName=void 0,this.scaleMode="price",this.percentBaseline=0,this.modelPercentBaselines=new Map,this.timezone="UTC",this.format=void 0,this.showGrid=!0,this.style={chartTypes:{},fontSize:11,margins:{...t9},gridVert:{visible:!0,color:null},gridHorz:{visible:!0,color:null},borderColor:null,separatorColor:null,crosshair:{color:r.tH,width:1,style:"dashed",opacity:.4,labelBackground:r.me},candle:{bodyVisible:!0,borderVisible:!1,borderUpColor:null,borderDownColor:null,wickVisible:!0,wickUpColor:null,wickDownColor:null},bars:{upColor:null,downColor:null},line:{color:r.NP,width:2},area:{lineColor:r.NP,width:2,topColor:(0,p.fu)(r.NP,.28),bottomColor:(0,p.fu)(r.NP,.02)},baseline:{topLineColor:null,bottomLineColor:null,topFillColor:null,topFillColor2:null,bottomFillColor:null,bottomFillColor2:null,width:2,baselineLevel:50},columns:{upColor:null,downColor:null},sessions:{premarketColor:t8,postmarketColor:t7,extendedColor:t7}},this.showAxisLabels=!0,this.tradeMarkers={visible:!0,labels:!0,qty:!0,colors:{long:i4,short:i6,exit:i8}},this.marks={visible:!0,groups:{}},this.timelineMarks=[],this.markGroups=[],this.marksExpandedStack=null,this.marksHoverKey=null,this.marksHoverSince=0,this.marksActiveKey=null,this.marksFlash=null,this.highlights=[],this.sessionZones=null,this.candleZ=0,this.candlesHidden=!1,this.seriesZ=new Map,this.drawingSlices=new Map,this.anchorOffsets=new Map,this.indicatorScales=new Map,this.orderedCache=null}orderedPanes(){return this.orderedCache||(this.orderedCache=[...this.panes.values()].sort((e,t)=>e.order-t.order)),this.orderedCache}sessionHighlightBands(){if(!this.sessionZones)return[];let e=[];for(let[t,i]of this.sessionZones.pre)e.push({from:t,to:i,color:this.style.sessions.premarketColor});for(let[t,i]of this.sessionZones.post)e.push({from:t,to:i,color:this.style.sessions.postmarketColor});for(let[t,i]of this.sessionZones.extended)e.push({from:t,to:i,color:this.style.sessions.extendedColor});return e}indicatorsForPane(e){let t=[];for(let i of this.indicators.values())i.paneId===e&&t.push(i);return t}ownScaleIndicatorsForPane(e){return this.orderedIndicatorsForPane(e).filter(e=>!0===e.ownScale)}ensureIndicatorScale(e,t){let i=this.indicatorScales.get(e);if(!i){let o=t??{min:0,max:1};i={scale:{...o},scaleTarget:{...o},initialized:!1,manualScale:null},this.indicatorScales.set(e,i)}return i}dropIndicatorScale(e){this.indicatorScales.delete(e)}scaleFor(e,t){if(!0===e.ownScale){let t=this.indicatorScales.get(e.id);if(t)return t.scale}if("own"===e.percentBaseline){let i=oh(this,t),o=this.modelPercentBaselines.get(e.id);if(i&&null!=o&&Number.isFinite(o)&&0!==o){let e=o/i.baseline;return e<0?{...t.scale,min:t.scale.max*e,max:t.scale.min*e,invert:!t.scale.invert}:{...t.scale,min:t.scale.min*e,max:t.scale.max*e}}}return t.scale}orderPanes(e){e.forEach((e,t)=>{let i=this.panes.get(e);i&&(i.order=t)}),this.orderedCache=null}orderedIndicatorsForPane(e){return this.indicatorsForPane(e).sort((e,t)=>this.zOf(e.id)-this.zOf(t.id))}zOf(e){return this.seriesZ.get(e)??0}offsetOf(e){return this.anchorOffsets.get(e)??0}setAnchorOffset(e,t){0!==t&&Number.isFinite(t)?this.anchorOffsets.set(e,t):this.anchorOffsets.delete(e)}forgetAnchorOffset(e){this.anchorOffsets.delete(e)}baselinePriceFor(e){if(null!=this.baselineValue)return this.baselineValue;let t=this.style.baseline.baselineLevel/100;if(e.log&&e.min>0&&e.max>e.min){let i=Math.log(e.min);return Math.exp(i+t*(Math.log(e.max)-i))}return e.min+(e.max-e.min)*t}assignIndicatorZ(e){this.seriesZ.has(e)||this.seriesZ.set(e,this.bottomZ()-1)}assignIndicatorZTop(e){this.seriesZ.has(e)||this.seriesZ.set(e,this.topZ()+1)}forgetIndicatorZ(e){this.seriesZ.delete(e)}setIndicatorZ(e,t){this.seriesZ.set(e,t)}indicatorZOrder(){let e=new Map([...this.indicators.keys()].map((e,t)=>[e,t])),t=t=>e.get(t)??Number.MAX_SAFE_INTEGER;return[...this.seriesZ.entries()].map(([e,t])=>({id:e,z:t})).sort((e,i)=>e.z-i.z||t(e.id)-t(i.id))}seriesBoundaries(e){let t=new Set;for(let i of("price"===e&&t.add(this.candleZ),this.indicatorsForPane(e)))t.add(this.zOf(i.id));return[...t].sort((e,t)=>e-t)}bringIndicatorToFront(e){this.seriesZ.set(e,this.topZ()+1)}sendIndicatorToBack(e){this.seriesZ.set(e,this.bottomZ()-1)}topZ(){let e=this.candleZ;for(let t of this.seriesZ.values())t>e&&(e=t);return e}bottomZ(){let e=this.candleZ;for(let t of this.seriesZ.values())t<e&&(e=t);return e}ensurePane(e,t,i,o){this.orderedCache=null;let r=this.panes.get(e);if(r)return r.order=i,void 0!==o&&(r.heightWeight=o),r.kind=t,r;let l={id:e,kind:t,order:i,heightWeight:o??("price"===t?3:1),bounds:{top:0,height:0},scale:{min:0,max:1},scaleTarget:{min:0,max:1},initialized:!1,manualScale:null,collapsed:!1,percentBaseline:0};return this.panes.set(e,l),l}removePane(e){this.panes.delete(e),this.orderedCache=null}};function on(e,t){return"price"===t.kind?e.scaleMode:t.scaleMode??"price"}function oa(e,t){return"price"===t.kind?e.logScale:t.logScale??!1}function os(e,t){return"price"===t.kind?e.invertScale:t.invert??!1}function oh(e,t){let i=on(e,t);if("percent"!==i&&"indexed"!==i)return;let o=t.percentBaseline;if(Number.isFinite(o)&&0!==o)return{baseline:o,indexed:"indexed"===i}}function od(e,t,i){if(!0===i.ownScale)return;let o=oh(e,t);if(o){if("own"===i.percentBaseline){let t=e.modelPercentBaselines.get(i.id);return null!=t&&Number.isFinite(t)&&0!==t?{baseline:t,indexed:o.indexed}:void 0}return o}}var oc=class{constructor(){this.kind="canvas2d",this.modelAlpha=1,this.candleBodyAlpha=1,this.candleStructureAlpha=1,this.candleBodyScale=1,this.canvas=null,this.ctx=null}mount(e){this.canvas=e,this.ctx=e.getContext("2d")}render(e,t,i){let o=this.ctx,r=this.canvas;if(!o||!r)return;let l=t.dpr,n=r.width/l,a=r.height/l,s=t.width;iQ(o,l),o.clearRect(0,0,n,a);let h=t.barCount;if(0===h)return;let d=t.visibleLogicalRange(),c=Math.max(0,Math.floor(d.from)),p=Math.min(h-1,Math.ceil(d.to));if(p<c)return;let u=Math.max(p,Math.ceil(d.to)),g=function(e){let t=!1;for(let i of e.values())if(i.barColors&&i.barColors.length>0){t=!0;break}if(!t)return og;let i=new Map;for(let t of e.values())if(t.barColors)for(let e of t.barColors)i.set(e.time,e.color);return i}(e.indicators);for(let r of e.orderedPanes()){if(r.collapsed)continue;let l=e.orderedIndicatorsForPane(r.id),h="price"===r.kind;o.save(),o.beginPath(),o.rect(0,r.bounds.top,s,r.bounds.height),o.clip();let d=t=>{let i=e.scaleFor(t,r);return i===r.scale?r:{...r,scale:i}};for(let e of(o.globalAlpha=this.modelAlpha,l))for(let i of e.backgrounds)!0!==i.overlay&&this.drawBackground(o,i,r,t);if(h)for(let i of e.indicators.values())for(let e of i.backgrounds)!0===e.overlay&&this.drawBackground(o,e,r,t);let m=e.drawingSlices.get(r.id)??[],b=0,f=e=>{for(;b<m.length&&m[b].beforeZ<=e;b+=1)o.globalAlpha=1,o.drawImage(m[b].canvas,0,0,n,a)},v=h&&!e.candlesHidden,y=!1;for(let n of l){v&&!y&&e.zOf(n.id)>=e.candleZ&&(f(e.candleZ),o.globalAlpha=this.candleStructureAlpha,this.drawPriceSeries(o,e,c,p,t,r,i,g,s),y=!0),f(e.zOf(n.id)),o.globalAlpha=this.modelAlpha;let l=e.offsetOf(n.id),a=d(n);for(let e of n.fills)!0!==e.overlay&&this.drawFill(o,n,e,a,t,c,u,l);for(let e of n.series)!0!==e.overlay&&this.drawSeries(o,e,a,t,c,u,i,l)}if(v&&!y&&(f(e.candleZ),o.globalAlpha=this.candleStructureAlpha,this.drawPriceSeries(o,e,c,p,t,r,i,g,s)),h){for(let i of(o.globalAlpha=this.modelAlpha,e.indicators.values())){let l=e.offsetOf(i.id);for(let e of i.fills)!0===e.overlay&&this.drawFill(o,i,e,r,t,c,u,l)}for(let l of e.indicators.values()){let n=e.offsetOf(l.id);for(let e of l.series)!0===e.overlay&&this.drawSeries(o,e,r,t,c,u,i,n)}}for(let e of(f(1/0),o.globalAlpha=this.modelAlpha,l)){let r=d(e);for(let l of e.priceLines)this.drawHline(o,l,r,t,s,i)}o.restore()}}destroy(){this.canvas=null,this.ctx=null}drawPriceSeries(e,t,i,o,r,l,n,a,s){if("none"===t.basePainting)return;let h=t.bars,d=t.style;switch(t.priceStyle){case"bars":this.drawBars(e,h,i,o,r,l,d.bars.upColor??n.upColor,d.bars.downColor??n.downColor,a);return;case"line":this.drawPriceLine(e,h,i,o,r,l,d.line.color??n.upColor,d.line.width);return;case"linemarkers":{let t=d.line.color??n.upColor;this.drawPriceLine(e,h,i,o,r,l,t,d.line.width),this.drawLineMarkers(e,h,i,o,r,l,t,d.line.width);return}case"stepline":this.drawStepLine(e,h,i,o,r,l,d.line.color??n.upColor,d.line.width);return;case"area":{let t=d.area.lineColor??n.upColor;this.drawPriceArea(e,h,i,o,r,l,d.area.topColor??t,d.area.bottomColor??"rgba(0,0,0,0)"),this.drawPriceLine(e,h,i,o,r,l,t,d.area.width);return}case"baseline":this.drawBaseline(e,h,i,o,r,l,t,n,s);return;case"columns":{let t=d.columns.upColor??(0,p.fu)(n.upColor,.5),s=d.columns.downColor??(0,p.fu)(n.downColor,.5);this.drawColumns(e,h,i,o,r,l,t,s,a);return}default:this.drawCandles(e,t,h,i,o,r,l,n,a)}}drawBars(e,t,i,o,r,l,n,a,s){let h=r.bodySpacing(),d=t1(h);if("aggregate"===d)return void this.drawCandlesAggregated(e,t,i,o,r,l,e=>s.get(e.time)??(e.close>=e.open?n:a));let c=Math.max(1,Math.round(.35*h)),p="full"===d;e.lineWidth=1;for(let h=i;h<=o;h+=1){let i=t[h];if(!i||i.high<=i.low)continue;let o=Math.round(r.logicalToX(h))+.5,d=s.get(i.time)??(i.close>=i.open?n:a),u=r.priceToY(i.high,l.scale,l.bounds),g=r.priceToY(i.low,l.scale,l.bounds);if(e.strokeStyle=d,e.beginPath(),e.moveTo(o,u),e.lineTo(o,g),p){let t=r.priceToY(i.open,l.scale,l.bounds),n=r.priceToY(i.close,l.scale,l.bounds);e.moveTo(o-c,t),e.lineTo(o,t),e.moveTo(o,n),e.lineTo(o+c,n)}e.stroke()}}drawPriceLine(e,t,i,o,r,l,n,a){e.lineWidth=a,e.lineJoin="round",e.lineCap="round",e.strokeStyle=n,e.beginPath();let s=!1;for(let n=Math.max(0,i-1);n<=o;n+=1){let i=t[n];if(!i){s=!1;continue}let o=r.logicalToX(n),a=r.priceToY(i.close,l.scale,l.bounds);s?e.lineTo(o,a):(e.moveTo(o,a),s=!0)}e.stroke(),e.lineCap="butt"}drawLineMarkers(e,t,i,o,r,l,n,a){let s=iC(a);if(r.pxPerBar()>=2*s+2){e.fillStyle=n,e.beginPath();for(let n=Math.max(0,i-1);n<=o;n+=1){let i=t[n];if(!i)continue;let o=r.logicalToX(n),a=r.priceToY(i.close,l.scale,l.bounds);e.moveTo(o+s,a),e.arc(o,a,s,0,2*Math.PI)}e.fill()}}drawStepLine(e,t,i,o,r,l,n,a){let s=r.dpr;for(let h of(e.lineWidth=a,e.lineJoin="miter",e.lineCap="square",e.strokeStyle=n,e.beginPath(),iT(Math.max(0,i-1),o,e=>{let i=t[e];return i?{x:iS(r.logicalToX(e),a,s),y:iS(r.priceToY(i.close,l.scale,l.bounds),a,s)}:null}))){let t=iM(h);e.moveTo(t[0].x,t[0].y);for(let i=1;i<t.length;i+=1)e.lineTo(t[i].x,t[i].y)}e.stroke(),e.lineCap="butt"}drawColumns(e,t,i,o,r,l,n,a,s){let h=r.bodySpacing(),d=r.dpr,c=t2(l.bounds.top+l.bounds.height,d);for(let p=i;p<=o;p+=1){let i=t[p];if(!i)continue;let o=t2(r.priceToY(i.close,l.scale,l.bounds),d);if(!(o<c))continue;let u=ik(r.logicalToX(p),h,d);e.fillStyle=s.get(i.time)??(ix(t,p)?n:a),e.fillRect(u.left,o,u.width,c-o)}}drawPriceArea(e,t,i,o,r,l,n,a){let s=l.bounds.top+l.bounds.height,h=[],d=1/0;for(let e=Math.max(0,i-1);e<=o;e+=1){let i=t[e];if(!i)continue;let o=r.logicalToX(e),n=r.priceToY(i.close,l.scale,l.bounds);h.push({x:o,y:n}),n<d&&(d=n)}if(h.length<2)return;let c=e.createLinearGradient(0,d,0,s);for(let t of(c.addColorStop(0,n),c.addColorStop(1,a),e.fillStyle=c,e.beginPath(),e.moveTo(h[0].x,s),h))e.lineTo(t.x,t.y);e.lineTo(h[h.length-1].x,s),e.closePath(),e.fill()}drawBaseline(e,t,i,o,r,l,n,a,s){let h=n.baselinePriceFor(l.scale),d=r.priceToY(h,l.scale,l.bounds),c=l.bounds.top,u=l.bounds.top+l.bounds.height,g=n.style.baseline,m=g.topLineColor??t4,b=g.bottomLineColor??t6,f=g.topFillColor??(0,p.fu)(m,.25),v=g.topFillColor2??(0,p.fu)(m,.05),y=g.bottomFillColor??(0,p.fu)(b,.25),w=g.bottomFillColor2??(0,p.fu)(b,.05),C=[];for(let e=Math.max(0,i-1);e<=o;e+=1){let i=t[e];i&&C.push({x:r.logicalToX(e),y:r.priceToY(i.close,l.scale,l.bounds)})}if(C.length<2)return;let x=()=>{for(let t of(e.beginPath(),e.moveTo(C[0].x,d),C))e.lineTo(t.x,t.y);e.lineTo(C[C.length-1].x,d),e.closePath()};if(d>c){e.save(),e.beginPath(),e.rect(0,c,s,d-c),e.clip();let t=e.createLinearGradient(0,c,0,d);t.addColorStop(0,f),t.addColorStop(1,v),e.fillStyle=t,x(),e.fill(),e.restore()}if(d<u){e.save(),e.beginPath(),e.rect(0,d,s,u-d),e.clip();let t=e.createLinearGradient(0,d,0,u);t.addColorStop(0,w),t.addColorStop(1,y),e.fillStyle=t,x(),e.fill(),e.restore()}e.strokeStyle=n.style.borderColor??a.borderColor,e.lineWidth=1,op(e,"dashed"),e.beginPath(),e.moveTo(0,Math.round(d)+.5),e.lineTo(s,Math.round(d)+.5),e.stroke(),op(e,"solid"),e.lineWidth=g.width,e.lineJoin="round",e.lineCap="round";let k=(t,i,o,r,l)=>{e.strokeStyle=l,e.beginPath(),e.moveTo(t,i),e.lineTo(o,r),e.stroke()};for(let e=1;e<C.length;e+=1){let t=C[e-1],i=C[e],o=t.y<=d,r=i.y<=d;if(o!==r&&i.y!==t.y){let e=(d-t.y)/(i.y-t.y),l=t.x+(i.x-t.x)*e;k(t.x,t.y,l,d,o?m:b),k(l,d,i.x,i.y,r?m:b)}else k(t.x,t.y,i.x,i.y,o?m:b)}e.lineCap="butt"}drawCandles(e,t,i,o,r,l,n,a,s){let h=l.bodySpacing(),d=t1(h),c=ia(t.style.candle,t.candleOverride,a.upColor,a.downColor),p=c.candle,u=tQ(p);if("none"===u)return;let g=p.bodyVisible?this.candleBodyAlpha:this.candleStructureAlpha;if("aggregate"===d){"body"===u&&(e.globalAlpha=g),this.drawCandlesAggregated(e,i,o,r,l,n,e=>{let t=e.close>=e.open;return tJ(p,u,t,s.get(e.time)??(t?c.up:c.down))},u);return}let m="full"===d,b=!m&&"body"===u,f=this.candleStructureAlpha>this.candleBodyAlpha+.001;for(let t=o;t<=r;t+=1){let o=i[t];if(!o||o.high<=o.low)continue;let r=t5(l.logicalToX(t),h,l.dpr,this.candleBodyScale),a=r.center,d=o.close>=o.open,u=d?c.up:c.down,v=s.get(o.time)??u,y=0,w=0;if(m||b){let e=l.priceToY(o.open,n.scale,n.bounds),t=l.priceToY(o.close,n.scale,n.bounds);y=t2(Math.min(e,t),l.dpr),w=Math.max(1/l.dpr,t2(Math.max(e,t),l.dpr)-y)}if(b)e.globalAlpha=g,e.strokeStyle=tJ(p,"body",d,v),e.lineWidth=r.wickW,e.beginPath(),e.moveTo(a,y),e.lineTo(a,y+w),e.stroke();else if(p.wickVisible){let t=(d?p.wickUpColor:p.wickDownColor)??(m?u:v),i=t2(l.priceToY(o.high,n.scale,n.bounds),l.dpr),s=t2(l.priceToY(o.low,n.scale,n.bounds),l.dpr);e.globalAlpha=this.candleStructureAlpha,e.strokeStyle=t,e.lineWidth=r.wickW,e.beginPath(),m?(e.moveTo(a,i),e.lineTo(a,y),e.moveTo(a,y+w)):e.moveTo(a,i),e.lineTo(a,s),e.stroke()}if(m&&(p.bodyVisible&&(e.globalAlpha=this.candleBodyAlpha,e.fillStyle=v,e.fillRect(r.bodyX,y,r.bodyW,w)),p.borderVisible||f&&p.bodyVisible)){e.globalAlpha=this.candleStructureAlpha,e.strokeStyle=p.borderVisible?(d?p.borderUpColor:p.borderDownColor)??v:v,e.lineWidth=1;let t=Math.max(0,r.bodyW-1),i=Math.max(0,w-1);e.strokeRect(r.bodyX+.5,y+.5,t,i)}}}drawCandlesAggregated(e,t,i,o,r,l,n,a="range"){let s=e=>r.priceToY(e,l.scale,l.bounds),h="body"===a?1/r.dpr:0;for(let l of(e.lineWidth=1,t3(t,i,o,e=>r.logicalToX(e),s,n,a))){let t=l.x+.5,i=s(l.hi);e.strokeStyle=l.color,e.beginPath(),e.moveTo(t,i),e.lineTo(t,Math.max(i+h,s(l.lo))),e.stroke()}}drawSeries(e,t,i,r,l,n,a,s=0){if((0,o.oBL)(t,"pane")){if("candle"===t.kind||"bar"===t.kind)return void this.drawPlotCandles(e,t,i,r,l,n,a,s);if((0,o.xcs)(t))switch(t.kind){case"histogram":case"columns":this.drawHistogram(e,t,i,r,l,n,s);break;case"area":this.drawArea(e,t,i,r,l,n,s),this.drawPolyline(e,t,i,r,l,n,!1,s);break;case"circles":case"cross":this.drawPointMarkers(e,t,i,r,l,n,s);break;case"step":this.drawPolyline(e,t,i,r,l,n,!0,s);break;default:this.drawPolyline(e,t,i,r,l,n,!1,s)}}}drawPolyline(e,t,i,o,r,l,n,a=0){e.lineWidth=Math.max(1,t.style.width),e.lineJoin="round",op(e,t.style.lineStyle);let s=0,h=0,d=!1;for(let c=Math.max(1,r-1);c<=l;c+=1){let r=t.points[c-a],l=t.points[c-1-a];if(!r||null===r.value||!l||null===l.value){d=!1;continue}let p=o.logicalToX(c),u=o.priceToY(r.value,i.scale,i.bounds);d||(s=o.logicalToX(c-1),h=o.priceToY(l.value,i.scale,i.bounds)),e.strokeStyle=r.color??t.style.color,e.beginPath(),e.moveTo(s,h),n&&e.lineTo(p,h),e.lineTo(p,u),e.stroke(),s=p,h=u,d=!0}op(e,"solid")}drawArea(e,t,i,o,r,l,n=0){let a=i.bounds.top+i.bounds.height,s=[],h=1/0,d=()=>{if(0===s.length)return;let i=e.createLinearGradient(0,h,0,a);for(let o of(i.addColorStop(0,t.style.color),i.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=i,e.beginPath(),e.moveTo(s[0].x,a),s))e.lineTo(o.x,o.y);e.lineTo(s[s.length-1].x,a),e.closePath(),e.fill(),s=[],h=1/0};for(let e=r;e<=l;e+=1){let r=t.points[e-n];if(!r||null===r.value){d();continue}let l=o.logicalToX(e),a=o.priceToY(r.value,i.scale,i.bounds);s.push({x:l,y:a}),a<h&&(h=a)}d()}drawHistogram(e,t,i,o,r,l,n=0){let a=o.bodySpacing(),s=Math.max(1,("columns"===t.kind?.7:.8)*a),h=s/2,d=t.style.base??0,c=o.priceToY(d,i.scale,i.bounds);for(let a=r;a<=l;a+=1){let r=t.points[a-n];if(!r||null===r.value)continue;let l=o.logicalToX(a),d=o.priceToY(r.value,i.scale,i.bounds);e.fillStyle=r.color??t.style.color,e.fillRect(l-h,Math.min(c,d),s,Math.max(1,Math.abs(d-c)))}}drawPointMarkers(e,t,i,o,r,l,n=0){let a=Math.max(1.5,t.style.width);for(let s=r;s<=l;s+=1){let r=t.points[s-n];if(!r||null===r.value)continue;let l=o.logicalToX(s),h=o.priceToY(r.value,i.scale,i.bounds);e.strokeStyle=r.color??t.style.color,e.fillStyle=r.color??t.style.color,"cross"===t.kind?(e.lineWidth=1,e.beginPath(),e.moveTo(l-a,h),e.lineTo(l+a,h),e.moveTo(l,h-a),e.lineTo(l,h+a),e.stroke()):(e.beginPath(),e.arc(l,h,a,0,2*Math.PI),e.fill())}}drawPlotCandles(e,t,i,o,r,l,n,a=0){let s=o.bodySpacing(),h=t.style?.up??n.upColor,d=t.style?.down??n.downColor,c="bar"===t.kind,p=Math.max(.5,Math.floor(.7*s)/2),u=Math.max(1,Math.round(.35*s));for(let n=r;n<=l;n+=1){let r=t.bars[n-a];if(!r||!Number.isFinite(r.open+r.high+r.low+r.close))continue;let l=t.barColors?.[n-a],g=l?.color??(r.close>=r.open?h:d),m=Math.round(o.logicalToX(n))+.5,b=o.priceToY(r.high,i.scale,i.bounds),f=o.priceToY(r.low,i.scale,i.bounds),v=o.priceToY(r.open,i.scale,i.bounds),y=o.priceToY(r.close,i.scale,i.bounds);if(c){e.strokeStyle=g,e.lineWidth=1,e.beginPath(),e.moveTo(m,b),e.lineTo(m,f),e.moveTo(m-u,v),e.lineTo(m,v),e.moveTo(m,y),e.lineTo(m+u,y),e.stroke();continue}e.strokeStyle=l?.wickColor??g,e.lineWidth=t0(s),e.beginPath(),e.moveTo(m,b),e.lineTo(m,f),e.stroke(),e.fillStyle=g,e.fillRect(m-p,Math.min(v,y),2*p,Math.max(1,Math.abs(y-v))),l?.borderColor&&(e.strokeStyle=l.borderColor,e.strokeRect(m-p,Math.min(v,y),2*p,Math.max(1,Math.abs(y-v))))}}drawFill(e,t,i,o,r,l,n,a=0){let s=ou(t,i.fromSeriesId),h=ou(t,i.toSeriesId);if(!s||!h)return;let d=NaN,c=NaN,p="",u="",g=null;for(let t=Math.max(1,l);t<=n;t+=1){let l=s[t-1-a],n=h[t-1-a],m=s[t-a],b=h[t-a];if(!l||!n||!m||!b||null===l.value||null===n.value||null===m.value||null===b.value)continue;let f=r.logicalToX(t-1),v=r.logicalToX(t),y=r.priceToY(l.value,o.scale,o.bounds),w=r.priceToY(n.value,o.scale,o.bounds),C=r.priceToY(m.value,o.scale,o.bounds),x=r.priceToY(b.value,o.scale,o.bounds),k=i.gradient?.[t-1-a];if(k){let t=r.priceToY(k.topValue,o.scale,o.bounds),i=r.priceToY(k.bottomValue,o.scale,o.bounds),l=i===t?t+1:i;g&&t===d&&l===c&&k.topColor===p&&k.bottomColor===u||((g=e.createLinearGradient(0,t,0,l)).addColorStop(0,k.topColor),g.addColorStop(1,k.bottomColor),d=t,c=l,p=k.topColor,u=k.bottomColor),e.fillStyle=g}else{let o=i.colors?i.colors[t-1-a]:i.color;if(!o)continue;e.fillStyle=o}e.beginPath(),e.moveTo(f,y),e.lineTo(v,C),e.lineTo(v,x),e.lineTo(f,w),e.closePath(),e.fill()}}drawBackground(e,t,i,o){let r=o.timeToX(t.from),l=o.timeToX(t.to);l<0||r>o.width||l<=r||(e.fillStyle=t.color,e.fillRect(r,i.bounds.top,l-r,i.bounds.height))}drawHline(e,t,i,o,r,l){let n=Math.round(o.priceToY(t.price,i.scale,i.bounds))+.5;n<i.bounds.top||n>i.bounds.top+i.bounds.height||(e.strokeStyle=t.color??l.textColor,e.lineWidth=t.width??1,op(e,t.lineStyle??"solid"),e.beginPath(),e.moveTo(0,n),e.lineTo(r,n),e.stroke(),op(e,"solid"))}};function op(e,t){"dashed"===t?e.setLineDash([6,4]):"dotted"===t?e.setLineDash([2,3]):e.setLineDash([])}function ou(e,t){let i=e.series.find(e=>e.id===t);return i&&(0,o.xcs)(i)?i.points:null}var og=new Map,om=e=>e<0?0:e>1?1:e,ob=e=>void 0===e?1:om(e.endsWith("%")?parseFloat(e)/100:parseFloat(e));function of(e){let t=e.trim().toLowerCase();if("transparent"===t)return[0,0,0,0];let i=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(t);if(i){let e=i[1];e.length<=4&&(e=[...e].map(e=>e+e).join(""));let t=t=>parseInt(e.slice(t,t+2),16)/255;return[t(0),t(2),t(4),8===e.length?t(6):1]}let o=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+%?)\s*)?\)$/.exec(t);if(o)return[om(o[1]/255),om(o[2]/255),om(o[3]/255),ob(o[4])];let r=/^hsla?\(\s*(-?[\d.]+)(?:deg)?\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*([\d.]+%?)\s*)?\)$/.exec(t);return r?[...function(e,t,i){let o=(e%360+360)%360/360;if(0===t)return[i,i,i];let r=i<.5?i*(1+t):i+t-i*t,l=2*i-r,n=e=>{let t=e<0?e+1:e>1?e-1:e;return t<1/6?l+(r-l)*6*t:t<.5?r:t<2/3?l+(r-l)*(2/3-t)*6:l};return[n(o+1/3),n(o),n(o-1/3)]}(+r[1],om(r[2]/100),om(r[3]/100)),ob(r[4])]:iF(e)}function ov(e,t){let i=e=>Math.round(255*om(e));return`rgba(${i(e[0])}, ${i(e[1])}, ${i(e[2])}, ${t})`}function oy(e,t,i){let o=(e,t)=>e*(1-i)+t*i;return[o(e[0],t[0]),o(e[1],t[1]),o(e[2],t[2]),1]}function ow(e){let t=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);return .2126*t(e[0])+.7152*t(e[1])+.0722*t(e[2])}function oC(e,t){let i=ow(e),o=ow(t);return(Math.max(i,o)+.05)/(Math.min(i,o)+.05)}function ox(e,t){let i=Math.max(1,t);return"dotted"===e?[i,2*i]:"dashed"===e?[4*i,3*i]:[]}function ok(e,t,i,o,r,l,n){if("none"===r)return[e,t,i,o];let a=i-e,s="left"===r||"both"===r,h="right"===r||"both"===r;if(1e-6>Math.abs(a)){if(s&&h)return[e,0,i,n];let r=o>=t;return h?r?[e,t,i,n]:[e,t,i,0]:r?[e,0,i,o]:[e,n,i,o]}let d=(o-t)/a,c=i=>t+d*(i-e),p=s?-2:Math.min(e,i),u=h?l+2:Math.max(e,i);return[p,c(p),u,c(u)]}function oS(e){var t;if(!e)return"#000000";let i=function(e){let t=e.trim(),i=/^#([0-9a-f]{3})$/i.exec(t);if(i){let e=i[1];return{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:1}}if(i=/^#([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(t)){let e=i[1];return{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:i[2]?parseInt(i[2],16)/255:1}}if(i=/^rgba?\(([^)]+)\)$/i.exec(t)){let e=i[1].split(",").map(e=>parseFloat(e.trim()));return{r:e[0]??0,g:e[1]??0,b:e[2]??0,a:e[3]??1}}return null}(e);return i?(t=i.r,(.299*t+.587*i.g+.114*i.b)/255>.55)?"#000000":"#ffffff":"#000000"}function oT(e){return Math.round(1.4*e)}function oM(e){switch(e){case"tiny":return 10;case"small":return 12;case"large":return 18;case"huge":return 28;case"normal":return 14;default:return 0}}var oL=/[฀-໿က-႟ក-៿぀-ヿ㐀-䶿一-鿿豈-﫿]/,oA={lines:[],boxes:[],labels:[],polylines:[],linefills:[]};function oP(e,t){let i=e=>!!e.overlay===t;return{lines:(e.lines??[]).filter(i),boxes:(e.boxes??[]).filter(i),labels:(e.labels??[]).filter(i),polylines:(e.polylines??[]).filter(i),linefills:(e.linefills??[]).filter(i)}}function oI(e){return!e.lines.length&&!e.boxes.length&&!e.labels.length&&!e.polylines.length&&!e.linefills.length}function oE(e){return"auto"===e?12:oM(e)}var oB=class{constructor(e,t=oA){this.deps=e,this.set=t,this.widthCache=new Map,this.tipRegions=[],this.indexOffset=0}setSet(e,t=0){this.set=e,this.indexOffset=t}setDeps(e){this.deps=e}isEmpty(){let e=this.set;return!e.lines.length&&!e.boxes.length&&!e.labels.length&&!e.polylines.length&&!e.linefills.length}labelTipRegions(){return this.tipRegions}render(e,t,i,o,r){this.tipRegions=[],this.isEmpty()||(e.save(),this.drawLinefills(e,t,i,o,r),this.drawBoxes(e,t,i,o,r),this.drawPolylines(e,t,o,r),this.drawLines(e,t,i,o,r),this.drawLabels(e,t,i,o,r),e.restore())}priceRange(e,t){let i=Math.min(e,t),o=Math.max(e,t),r=(e,t,r)=>"both"===r||("left"===r?Math.max(e,t)>=i:"right"===r?Math.min(e,t)<=o:Math.max(e,t)>=i&&Math.min(e,t)<=o),l=1/0,n=-1/0,a=e=>{e<l&&(l=e),e>n&&(n=e)};for(let e of this.set.lines)!e.invisible&&function(e,t,i,o,r){let l=Math.min(e,t),n=Math.max(e,t);return e===t?e>=o&&e<=r:"both"===i||("left"===i?n>=o:"right"===i?l<=r:n>=o&&l<=r)}(this.logicalOf(e.xloc,e.x1),this.logicalOf(e.xloc,e.x2),e.extend,i,o)&&(a(e.y1),a(e.y2));for(let e of this.set.boxes)(e.bgColor||e.borderColor&&e.borderWidth>0||e.text)&&r(this.logicalOf(e.xloc,e.left),this.logicalOf(e.xloc,e.right),e.extend)&&(a(e.top),a(e.bottom));for(let e of this.set.linefills){if(!e.color)continue;let t=[e.line1.x1,e.line1.x2,e.line2.x1,e.line2.x2].map((t,i)=>this.logicalOf(i<2?e.line1.xloc:e.line2.xloc,t));r(Math.min(...t),Math.max(...t),"none"!==e.line1.extend||"none"!==e.line2.extend?"both":"none")&&(a(e.line1.y1),a(e.line1.y2),a(e.line2.y1),a(e.line2.y2))}for(let e of this.set.polylines){if(e.points.length<2)continue;let t=e.points.map(e=>this.logicalOf(e.xloc,e.x));if(r(Math.min(...t),Math.max(...t),"none"))for(let t of e.points)a(t.price)}let s=0,h=0;for(let e of this.set.labels){let t=this.logicalOf(e.xloc,e.x);if(!r(t,t,"none"))continue;if("price"===e.yloc){a(e.y);continue}if("top"===e.yloc||"bottom"===e.yloc)continue;let i=this.deps.barAt(t);if(!i)continue;a("abovebar"===e.yloc?i.high:i.low);let o=oE(e.size),l=Math.max(1,(e.text??"").split("\n").length),n=this.isPointShape(e.style)?14+Math.max(4,.6*o)+2:14+1.25*o*l+8+7;"abovebar"===e.yloc?s=Math.max(s,n):h=Math.max(h,n)}return Number.isFinite(l)&&Number.isFinite(n)?{min:l,max:n,aboveMargin:s,belowMargin:h}:null}logicalOf(e,t){return"bar_time"===e?this.deps.timeToLogical(t):t+this.indexOffset}drawLines(e,t,i,o,r){for(let l of this.set.lines){if(l.invisible)continue;let n=o(this.logicalOf(l.xloc,l.x1)),a=o(this.logicalOf(l.xloc,l.x2)),s=r(l.y1),h=r(l.y2);if(null===s||null===h)continue;let d="left"===l.extend||"both"===l.extend,c="right"===l.extend||"both"===l.extend;if(!d&&!c&&(0>Math.max(n,a)||Math.min(n,a)>t))continue;let[p,u,g,m]=ok(n,s,a,h,l.extend,t,i),b=l.color??this.deps.theme.textColor;e.beginPath(),e.moveTo(p,u),e.lineTo(g,m),e.strokeStyle=b,e.lineWidth=l.width,e.setLineDash(ox(l.style,l.width)),e.stroke(),e.setLineDash([]);let f=a>=n;if(l.arrowRight){let t=(f?c:d)?f?[g,m]:[p,u]:[a,h];this.drawArrow(e,t[0],t[1],n,s,l.width,b)}if(l.arrowLeft){let t=(f?d:c)?f?[p,u]:[g,m]:[n,s];this.drawArrow(e,t[0],t[1],a,h,l.width,b)}}}drawArrow(e,t,i,o,r,l,n){let a=Math.atan2(i-r,t-o),s=6+2*l;e.beginPath(),e.moveTo(t,i),e.lineTo(t-s*Math.cos(a-.45),i-s*Math.sin(a-.45)),e.lineTo(t-s*Math.cos(a+.45),i-s*Math.sin(a+.45)),e.closePath(),e.fillStyle=n,e.fill()}drawLinefills(e,t,i,o,r){for(let l of this.set.linefills){if(!l.color)continue;let n=this.resolveLine(l.line1,t,i,o,r),a=this.resolveLine(l.line2,t,i,o,r);if(!n||!a)continue;let s=e=>e[0]>e[2]||e[0]===e[2]&&e[1]>e[3]?[e[2],e[3],e[0],e[1]]:e,h=s(n),d=s(a);e.beginPath(),e.moveTo(h[0],h[1]),e.lineTo(h[2],h[3]),e.lineTo(d[2],d[3]),e.lineTo(d[0],d[1]),e.closePath(),e.fillStyle=l.color,e.fill()}}resolveLine(e,t,i,o,r){let l=o(this.logicalOf(e.xloc,e.x1)),n=o(this.logicalOf(e.xloc,e.x2)),a=r(e.y1),s=r(e.y2);return null===a||null===s?null:ok(l,a,n,s,e.extend,t,i)}drawPolylines(e,t,i,o){for(let r of this.set.polylines){let l=[];for(let e of r.points){let t=o(e.price);null!==t&&l.push([i(this.logicalOf(e.xloc,e.x)),t])}if(l.length<2)continue;let n=1/0,a=-1/0;for(let e of l)e[0]<n&&(n=e[0]),e[0]>a&&(a=e[0]);if(!(a<0)&&!(n>t)){if(e.beginPath(),r.curved)this.curvedPath(e,l,r.closed);else{e.moveTo(l[0][0],l[0][1]);for(let t=1;t<l.length;t+=1)e.lineTo(l[t][0],l[t][1])}if(r.closed&&e.closePath(),r.fillColor&&(e.fillStyle=r.fillColor,e.fill()),r.lineColor&&(e.strokeStyle=r.lineColor,e.lineWidth=r.lineWidth,e.setLineDash(ox(r.lineStyle,r.lineWidth)),e.stroke(),e.setLineDash([]),r.arrowLeft||r.arrowRight)){let t=r.closed?l.length:l.length-1;for(let i=0;i<t;i+=1){let t=l[i],o=l[(i+1)%l.length];r.arrowRight&&this.drawArrow(e,o[0],o[1],t[0],t[1],r.lineWidth,r.lineColor),r.arrowLeft&&this.drawArrow(e,t[0],t[1],o[0],o[1],r.lineWidth,r.lineColor)}}}}}curvedPath(e,t,i){let o=t.length,r=e=>i?t[(e%o+o)%o]:t[Math.max(0,Math.min(o-1,e))];e.moveTo(t[0][0],t[0][1]);let l=i?o:o-1;for(let t=0;t<l;t+=1){let i=r(t-1),o=r(t),l=r(t+1),n=r(t+2),a=o[0]+(l[0]-i[0])/6,s=o[1]+(l[1]-i[1])/6,h=l[0]-(n[0]-o[0])/6,d=l[1]-(n[1]-o[1])/6;e.bezierCurveTo(a,s,h,d,l[0],l[1])}}drawBoxes(e,t,i,o,r){for(let l of this.set.boxes){let n=o(this.logicalOf(l.xloc,l.left)),a=o(this.logicalOf(l.xloc,l.right));("left"===l.extend||"both"===l.extend)&&(n=-2),("right"===l.extend||"both"===l.extend)&&(a=t+2);let s=r(l.top),h=r(l.bottom);if(null===s||null===h)continue;let d=Math.min(n,a),c=Math.max(n,a),p=Math.min(s,h),u=Math.max(s,h),g=c-d,m=u-p;c<0||d>t||u<0||p>i||(l.bgColor&&(e.fillStyle=l.bgColor,e.fillRect(d,p,g,m)),l.borderColor&&l.borderWidth>0&&(e.strokeStyle=l.borderColor,e.lineWidth=l.borderWidth,e.setLineDash(ox(l.borderStyle,l.borderWidth)),e.strokeRect(d,p,g,m),e.setLineDash([])),l.text&&this.drawBoxText(e,l,d,p,g,m))}}measure(e,t,i){let o=`${t} ${i}`,r=this.widthCache.get(o);return void 0===r&&(e.font=t,r=e.measureText(i).width,this.widthCache.set(o,r)),r}wrapText(e,t,i,o){return function(e,t,i){let o=[];for(let r of e.split("\n")){if(i(r)<=t){o.push(r);continue}let e="";for(let l of r.split(/(\s+)/))for(let r of/^\s*$/.test(l)?[l]:function(e){if(!oL.test(e))return[e];let t=(0,n.C8)(void 0,"word");if(!t)return[e];let i=[];for(let{segment:o,isWordLike:r}of t.segment(e))i.length>0&&!1===r?i[i.length-1]+=o:i.push(o);return i}(l)){let l=e+r;e&&i(l)>t?(o.push(e.trimEnd()),e=r.trimStart()):e=l}e.trim()&&o.push(e.trimEnd())}return o}(i,o,i=>this.measure(e,t,i))}drawBoxText(e,t,i,o,r,l){let n,a,s,h=t.text,d="monospace"===t.fontFamily?"monospace":this.deps.theme.fontFamily||"sans-serif",c=`${t.italic?"italic ":""}${t.bold?"bold ":""}`,p=oM(t.textSize);if(0===p){let i=`${c}14px ${d}`;n=t.wrap?this.wrapText(e,i,h,Math.max(1,r-8)):h.split("\n");let o=0;for(let t of n)o=Math.max(o,this.measure(e,i,t));if(0===(p=function(e,t,i,o){let r=Math.min(e>0?14*i/e:1/0,.85*o/(1.3*t),48);return r>=6?r:0}(o,n.length,r-8,l)))return}else{let i=`${c}${p}px ${d}`;n=t.wrap?this.wrapText(e,i,h,Math.max(1,r-8)):h.split("\n")}e.font=`${c}${p}px ${d}`,e.fillStyle=t.textColor??oS(t.bgColor);let u=1.3*p,g=u*n.length;"left"===t.hAlign?(e.textAlign="left",a=i+4):"right"===t.hAlign?(e.textAlign="right",a=i+r-4):(e.textAlign="center",a=i+r/2),e.textBaseline="middle",s="top"===t.vAlign?o+4:"bottom"===t.vAlign?o+l-4-g:o+(l-g)/2;for(let t=0;t<n.length;t+=1)e.fillText(n[t],a,s+(t+.5)*u)}drawLabels(e,t,i,o,r){for(let l of this.set.labels){let n,a=o(this.logicalOf(l.xloc,l.x));if(a<-50||a>t+50)continue;if("price"===l.yloc)n=r(l.y);else if("top"===l.yloc)n=14;else if("bottom"===l.yloc)n=i-14;else{let e=this.deps.barAt(this.logicalOf(l.xloc,l.x));if(!e)continue;let t=r("abovebar"===l.yloc?e.high:e.low);n=null===t?null:t+("abovebar"===l.yloc?-14:14)}if(null===n)continue;let s=l.color??this.deps.theme.textColor,h=oE(l.size);if(this.isPointShape(l.style)){if(l.noFill||this.drawLabelShape(e,l.style,a,n,h,s),l.text&&this.drawLabelText(e,l,a,n+h,h),l.tooltip){let e=Math.max(4,.6*h)+3;this.tipRegions.push({left:a-e,top:n-e,right:a+e,bottom:n+e,text:l.tooltip})}}else if("none"===l.style||"text_outline"===l.style)l.text&&(this.drawLabelText(e,l,a,n,h,"text_outline"===l.style),l.tooltip&&this.tipRegions.push(this.textRegion(e,l,a,n,h,l.tooltip)));else{let t=this.drawBubble(e,l,a,n,h,s);l.tooltip&&this.tipRegions.push({left:t.x,top:t.y,right:t.x+t.w,bottom:t.y+t.h,text:l.tooltip})}}}labelFont(e,t){let i="monospace"===e.fontFamily?"monospace":this.deps.theme.fontFamily||"sans-serif";return`${e.italic?"italic ":""}${e.bold?"bold ":""}${t}px ${i}`}textRegion(e,t,i,o,r,l){let n=this.labelFont(t,r),a=(t.text??"").split("\n"),s=Math.max(1,...a.map(t=>this.measure(e,n,t))),h=1.25*r*a.length,d="left"===t.textAlign?i:"right"===t.textAlign?i-s:i-s/2;return{left:d,top:o-h/2,right:d+s,bottom:o+h/2,text:l}}isPointShape(e){switch(e){case"circle":case"square":case"diamond":case"flag":case"arrowup":case"arrowdown":case"triangleup":case"triangledown":case"cross":case"xcross":return!0;default:return!1}}drawLabelText(e,t,i,o,r,l=!1){e.font=this.labelFont(t,r),e.textAlign="left"===t.textAlign?"left":"right"===t.textAlign?"right":"center",e.textBaseline="middle";let n=t.text.split("\n"),a=1.25*r,s=o-a*(n.length-1)/2;if(l){e.lineWidth=3,e.strokeStyle=oS(t.textColor??this.deps.theme.textColor);for(let t=0;t<n.length;t+=1)e.strokeText(n[t],i,s+t*a)}e.fillStyle=t.textColor??this.deps.theme.textColor;for(let t=0;t<n.length;t+=1)e.fillText(n[t],i,s+t*a)}drawLabelShape(e,t,i,o,r,l){let n=Math.max(4,.6*r);switch(e.fillStyle=l,e.strokeStyle=l,e.lineWidth=Math.max(1,.3*n),e.beginPath(),t){case"circle":default:e.arc(i,o,n,0,2*Math.PI),e.fill();break;case"square":e.fillRect(i-n,o-n,2*n,2*n);break;case"diamond":e.moveTo(i,o-n),e.lineTo(i+n,o),e.lineTo(i,o+n),e.lineTo(i-n,o),e.closePath(),e.fill();break;case"triangleup":case"arrowup":e.moveTo(i,o-n),e.lineTo(i+n,o+n),e.lineTo(i-n,o+n),e.closePath(),e.fill();break;case"triangledown":case"arrowdown":e.moveTo(i,o+n),e.lineTo(i+n,o-n),e.lineTo(i-n,o-n),e.closePath(),e.fill();break;case"flag":e.moveTo(i-.7*n,o-n),e.lineTo(i-.7*n,o+n),e.moveTo(i-.7*n,o-n),e.lineTo(i+n,o-.4*n),e.lineTo(i-.7*n,o+.2*n),e.stroke(),e.fill();break;case"cross":e.moveTo(i,o-n),e.lineTo(i,o+n),e.moveTo(i-n,o),e.lineTo(i+n,o),e.stroke();break;case"xcross":e.moveTo(i-n,o-n),e.lineTo(i+n,o+n),e.moveTo(i+n,o-n),e.lineTo(i-n,o+n),e.stroke()}}drawBubble(e,t,i,o,r,l){e.font=this.labelFont(t,r);let n=(t.text??"").split("\n"),a=1.25*r,s=Math.max(1,...n.map(t=>this.measure(e,e.font,t)))+12,h=a*n.length+8,d=i-s/2,c=o-h-7,p="down";switch(t.style){case"label_up":d=i-s/2,c=o+7,p="up";break;case"label_left":d=i+7,c=o-h/2,p="left";break;case"label_right":d=i-s-7,c=o-h/2,p="right";break;case"label_center":d=i-s/2,c=o-h/2,p="none";break;case"label_lower_left":d=i+7,c=o-h-7,p="none";break;case"label_lower_right":d=i-s-7,c=o-h-7,p="none";break;case"label_upper_left":d=i+7,c=o+7,p="none";break;case"label_upper_right":d=i-s-7,c=o+7,p="none";break;default:d=i-s/2,c=o-h-7,p="down"}if(t.noFill||(e.fillStyle=l,this.roundRect(e,d,c,s,h,4),e.fill(),"none"!==p&&(e.beginPath(),"down"===p?(e.moveTo(i-7,c+h),e.lineTo(i+7,c+h)):"up"===p?(e.moveTo(i-7,c),e.lineTo(i+7,c)):"left"===p?(e.moveTo(d,o-7),e.lineTo(d,o+7)):(e.moveTo(d+s,o-7),e.lineTo(d+s,o+7)),e.lineTo(i,o),e.closePath(),e.fill())),t.text){let i;e.fillStyle=t.textColor??(t.noFill?this.deps.theme.textColor:oS(l)),e.textBaseline="middle","left"===t.textAlign?(e.textAlign="left",i=d+6):"right"===t.textAlign?(e.textAlign="right",i=d+s-6):(e.textAlign="center",i=d+s/2);let o=c+4+a/2;for(let t=0;t<n.length;t+=1)e.fillText(n[t],i,o+t*a)}return{x:d,y:c,w:s,h}}roundRect(e,t,i,o,r,l){let n=Math.min(l,o/2,r/2);e.beginPath(),e.moveTo(t+n,i),e.arcTo(t+o,i,t+o,i+r,n),e.arcTo(t+o,i+r,t,i+r,n),e.arcTo(t,i+r,t,i,n),e.arcTo(t,i,t+o,i,n),e.closePath()}};function oF(e,t){return t>=864e5?"UTC":e}function oO(e,t){return(0,n._s)(e,t)}function oR(e,t,i=6){if(!(t>e)||!Number.isFinite(e)||!Number.isFinite(t))return[];let o=(t-e)/Math.max(1,i),r=Math.pow(10,Math.floor(Math.log10(o))),l=o/r,n=(l<1.5?1:l<3?2:l<7?5:10)*r,a=Math.max(0,-Math.floor(Math.log10(n))+1),s=Math.ceil(e/n)*n;if(!(n>0)||s+n===s)return[];let h=Math.floor((t-s)/n+1e-6)+1;if(!(h>0)||h>1e3)return[];let d=[];for(let e=0;e<h;e+=1)d.push(Number((s+e*n).toFixed(a)));return d}function oN(e){let t=Math.abs(e);return t>=100?0:t>=1?2:t>=.01?4:6}function oz(e){return Math.max(2,Math.min(16,Math.round(e/50)))}function oV(e,t){return e.log?function(e,t,i=6){if(e<=0||!(t>e)||!Number.isFinite(e)||!Number.isFinite(t))return[];if(Math.log10(t)-Math.log10(e)<1.1)return oR(e,t,i);let o=[],r=Math.floor(Math.log10(e)),l=Math.ceil(Math.log10(t));for(let i=r;i<=l;i+=1)for(let r of[1,2,5]){let l=r*Math.pow(10,i);l>=e&&l<=t&&o.push(l)}return o}(e.min,e.max,oz(t)):oR(e.min,e.max,oz(t))}function oD(e,t=n.$S,i="priceAxis"){return t.price(e,{decimals:2,mode:"percent",surface:i})}function o$(e,t=n.$S,i="priceAxis"){return t.price(e,{decimals:2,mode:"indexed",surface:i})}function oH(e,t=n.$S,i="priceAxis"){return t.compact(e,{decimals:2,trimZeros:!0,surface:i})}function oW(e,t,i,o,r,l=n.$S){if("none"===r)return[];if(i){let{baseline:o,indexed:r}=i,n=Math.min(e.min,e.max),a=Math.max(e.min,e.max);return r?oR(n/o*100,a/o*100,oz(t)).map(e=>({price:o*e/100,label:o$(e,l)})):oR((n/o-1)*100,(a/o-1)*100,oz(t)).map(e=>({price:o*(1+e/100),label:oD(e,l)}))}return"volume"===r?oV(e,t).map(e=>({price:e,label:oH(e,l)})):oV(e,t).map(i=>({price:i,label:oU(e,t,i,o,l)}))}function oq(e,t,i,o,r,l,a=n.$S,s="priceAxis"){return"none"===l?"":o?o.indexed?o$(i/o.baseline*100,a,s):oD((i/o.baseline-1)*100,a,s):"volume"===l?oH(i,a,s):oU(e,t,i,r,a,s)}function oU(e,t,i,o,r=n.$S,l="priceAxis"){let a=e.log&&Math.log10(e.max)-Math.log10(e.min)>=1.1,s=a?oN(i):0,h=a?0===s?2:s:function(e,t,i){let o=null!=i&&i>0?(0,n.a4)(i):function(e,t,i=6){if(!(t>e))return 2;let o=(t-e)/Math.max(1,i),r=Math.pow(10,Math.floor(Math.log10(o))),l=o/r;return Math.max(0,Math.min(8,-Math.floor(Math.log10((l<1.5?1:l<3?2:l<7?5:10)*r))+1))}(e.min,e.max,oz(t));return 0===o?2:o}(e,t,o);return r.price(i,{decimals:h,mintick:o,mode:"price",surface:l})}var oj=2592e6,oG=31536e6,oK=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,72e5,144e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6];function oY(e,t,i,o=n.$S,r="crosshair",l){return o.timeStamp(e,{timeZone:oF(t,i),withTime:i<864e5,withSeconds:l??(i>0&&i<6e4),surface:r})}function oZ(e,t,i=8,o=0,r=n.$S,l=-1/0){let a=t-e;if(!(a>0))return[];let s=function(e){for(let t of oK)if(t>=e)return t;return oK[oK.length-1]}(a/Math.max(1,i)),h=Math.max(e,l)+o,d=t+o;if(s>=oj)return function(e,t,i,o,r){let l=new Date(e),n=12*l.getUTCFullYear()+l.getUTCMonth();oX(n)<e&&(n+=1),n=Math.ceil(n/i)*i;let a=i>=12?"year":"month",s=[];for(let e=oX(n);e<=t;n+=i,e=oX(n)){let t=e-o;s.push({time:t,label:r.timeTick(t,{unit:a,major:!0,offsetMs:o,surface:"timeAxis"}),major:!0})}return s}(h,d,s>=oG?12*function(e,t){let i=e/(2*Math.max(1,t)*oG);if(!(i>1))return 1;let o=Math.pow(10,Math.floor(Math.log10(i))),r=i/o;return(r<=1?1:r<=2?2:r<=5?5:10)*o}(a,i):s>=3*oj?3:1,o,r);let c=Math.ceil(h/s)*s,p=s<6e4?"second":s<36e5?"minute":"hour",u=[];for(let e=c;e<=d;e+=s){let t,i=e-o,l=new Date(e),n=!1;s<864e5?t=(n=0===l.getUTCHours()&&0===l.getUTCMinutes())?"day":p:s<oG?t=(n=1===l.getUTCDate())?"month":"day":(t="year",n=!0),u.push({time:i,label:r.timeTick(i,{unit:t,major:n,offsetMs:o,surface:"timeAxis"}),major:n})}return u}function oX(e){let t=Math.floor(e/12);return new Date(0).setUTCFullYear(t,e-12*t,1)}var o_=class{constructor(){this.fn=null,this.memo=new WeakMap,this.warned=!1}get hook(){return this.fn}setHook(e){this.fn=e,this.memo=new WeakMap}ticksFor(e,t,i){let o=t.axisFormat;if("none"===o)return[];let r=oh(e,t),l=t.bounds.height,n=this.fn;if(!n||!(l>0))return oW(t.scale,l,r,e.priceMintick,o,e.format);let a=t.scale,s=this.memo.get(t),h=e.style.fontSize;if(s&&s.kind===t.kind&&s.min===a.min&&s.max===a.max&&!!a.log===s.log&&!!a.invert===s.invert&&s.height===l&&s.baseline===r?.baseline&&!!r?.indexed===s.indexed&&s.mintick===e.priceMintick&&s.format===o&&s.fmt===e.format&&s.fontSize===h)return s.ticks;let d=oW(a,l,r,e.priceMintick,o,e.format),c=this.callHook(n,e,t,i,d,r?.baseline,r?r.indexed?"indexed":"percent":"price");return this.memo.set(t,{kind:t.kind,min:a.min,max:a.max,log:!!a.log,invert:!!a.invert,height:l,baseline:r?.baseline,indexed:!!r?.indexed,mintick:e.priceMintick,format:o,fmt:e.format,fontSize:h,ticks:c}),c}callHook(e,t,i,o,r,l,n){let a,s={min:i.scale.min,max:i.scale.max,log:!!i.scale.log,invert:!!i.scale.invert},h={top:0,height:i.bounds.height},d={pane:{id:i.id,kind:i.kind},min:Math.min(s.min,s.max),max:Math.max(s.min,s.max),log:!!s.log,height:h.height,mode:n,baseline:l,mintick:t.priceMintick,fontSize:t.style.fontSize,priceToY:e=>o.priceToY(e,s,h),defaults:r};try{a=e(d)}catch(e){return this.warnOnce("threw",e),r}if(null==a)return r;if(!Array.isArray(a))return this.warnOnce("returned a non-array",a),r;let c=[];for(let e of a){if(!e||"object"!=typeof e)continue;let{price:t,label:i,major:o}=e;"number"==typeof t&&Number.isFinite(t)&&"string"==typeof i&&c.push("boolean"==typeof o?{price:t,label:i,major:o}:{price:t,label:i})}return c}warnOnce(e,t){this.warned||(this.warned=!0,console.warn(`[vela] the priceAxisTicks function ${e} — the default ticks are used instead.`,t))}};function oQ(e,t,i,o=n.$S){if(!(t>0))return null;let r=e+t-i;return r<=0?null:function(e,t=n.$S){return t.duration(e,{style:"countdown",surface:"lastPrice"})}(r,o)}function oJ(e,t){let[i,o,r,l]=iF(e),n=i,a=o,s=r;if(l<1){let[e,h,d]=iF(t);n=i*l+e*(1-l),a=o*l+h*(1-l),s=r*l+d*(1-l)}let h=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);return .2126*h(n)+.7152*h(a)+.0722*h(s)>=.4?"#000000":"#ffffff"}var o0=(0,n.ab)("chart.marks.cluster","{label} \xb7 {count}"),o1=(0,n.ab)("chart.marks.marks","Marks");function o2(e,t){let i=t.find(t=>t.id===e);return i?i.label:e.charAt(0).toUpperCase()+e.slice(1)}function o5(e){return(0,n.dq)(e,1)!==e}var o3=class{constructor(e){this.onReady=e,this.cache=new Map}get(e,t,i,o){let r=`${e}|${t}|${i}|${o}`;if(this.cache.has(r)){let e=this.cache.get(r);return e&&e.complete&&e.naturalWidth>0?e:null}let n=(0,l.UT)(e);if(!n||"undefined"==typeof document||"undefined"==typeof Image||"undefined"==typeof XMLSerializer)return this.cache.set(r,null),null;let a=function(e,t,i){let o=document.createElement("template");o.innerHTML=e;let r=o.content.firstElementChild;return r&&"svg"===r.tagName.toLowerCase()?(r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r.setAttribute("width",String(i)),r.setAttribute("height",String(i)),r.setAttribute("color",t),new XMLSerializer().serializeToString(r)):null}(n,t,Math.max(1,Math.ceil(i*o)));if(!a)return this.cache.set(r,null),null;let s=new Image;return s.onload=()=>this.onReady(),s.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(a)}`,this.cache.set(r,s),null}clear(){this.cache.clear()}};function o4(e,t){let i=[];for(let r of e.series){if(!(0,o.xcs)(r)||!(0,o.oBL)(r,"priceScale"))continue;let e=r.points[t];if(!e||null===e.value||!Number.isFinite(e.value))continue;let l=e.color??r.style.color;if(!l)continue;let[n,a,s,h]=of(l);h>0&&i.push({series:r,value:e.value,color:[n,a,s,1]})}return i}var o6=class{constructor(e=new o_){this.axisTicks=e,this.canvas=null,this.ctx=null,this.axisTextColor=H.textColor,this.drawScene=new oB({timeToLogical:()=>0,barAt:()=>null,theme:{}}),this.markLayout={glyphs:[],stacks:new Map},this.markIcons=new o3(()=>this.onMarkIconReady?.()),this.onMarkIconReady=null,this.barTimesSrc=null,this.barTimesCache=[],this.i18n=null}mount(e){this.canvas=e,this.ctx=e.getContext("2d")}setMarkIconReady(e){this.onMarkIconReady=e}markGlyphAt(e,t){return function(e,t,i){for(let o=e.glyphs.length-1;o>=0;o--){let r=e.glyphs[o];if(r.decked&&0!==r.depth)continue;let l=r.size/2+3;if(Math.abs(t-r.x)<=l&&Math.abs(i-r.y)<=l)return r}return null}(this.markLayout,e,t)}markStackAt(e,t){return function(e,t,i){for(let[o,r]of e.stacks){for(let e of r){let r=e.size/2+3;if(Math.abs(t-e.x)<=r&&Math.abs(i-e.y)<=r)return o}if(r.length>1&&!r[0].decked){let e=r[r.length-1],l=r[0],n=Math.max(e.size,l.size)/2+3;if(Math.abs(t-l.x)<=n&&i>=e.y-e.size/2-8&&i<=l.y+l.size/2+3)return o}}return null}(this.markLayout,e,t)}markGlyphByKey(e){return this.markLayout.glyphs.find(t=>t.cluster.key===e)??null}markTooltipAt(e,t,i,o){let r=this.markGlyphAt(e,t);return r?function(e,t,i){let o=e.marks[0];if(!o)return null;if(1===e.marks.length)return o.tooltip??o.title??null;let r=void 0!==e.group?o2(e.group,t):o.title??o.tooltip??(0,n.b6)(i,o1);return(0,n.b6)(i,o0,{label:r,count:(0,n.EJ)(String(e.marks.length),i)})}(r.cluster,i,o):null}prepare(e,t,i){this.drawScene.setDeps({timeToLogical:e=>t.timeToLogical(e),barAt:t=>{let i=e.bars[Math.round(t)];return i?{high:i.high,low:i.low}:null},theme:i})}paneDrawingsRange(e,t,i,o){let r=null;for(let i of e)r=o8(r,this.drawingsRange(oP(i,!1),o,t.offsetOf(i.id)));if(i)for(let e of t.indicators.values())r=o8(r,this.drawingsRange(oP(e,!0),o,t.offsetOf(e.id)));return r}render(e,t,i,o){let r=this.ctx,l=this.canvas;if(!r||!l)return;let n=t.dpr,a=l.width/n,s=l.height/n,h=t.width,d=t.height;this.axisTextColor=o?.textColor??i.textColor,iQ(r,n),r.clearRect(0,0,a,s),o&&(a>h||s>d)&&(r.fillStyle=o.background,a>h&&r.fillRect(h,0,a-h,s),s>d&&r.fillRect(0,d,h,s-d)),r.font=`${e.style.fontSize}px ${i.fontFamily}`,r.textBaseline="middle";let c=e.orderedPanes();if(0===t.barCount){this.drawPaneSeparators(r,e,i,a,c),this.markLayout={glyphs:[],stacks:new Map};return}let p=c.find(e=>"price"===e.kind)??null;if(p&&!p.collapsed&&e.tradeMarkers.visible)for(let o of e.indicators.values())o.trades?.length&&this.renderTrades(r,t,e,i,o.trades,p,h);this.drawPriceAxes(r,e,t,i,h,c),this.drawMergedScaleColumns(r,e,t,h),this.drawPaneSeparators(r,e,i,a,c),this.drawIndicatorTags(r,e,t,i,h,a,c,p),this.drawPriceLineAndCountdown(r,e,t,i,h,p),this.drawTimeAxis(r,e,t,i,h,d,s),this.drawMarkLane(r,e,t,i,h,d)}drawMarkLane(e,t,i,o,r,l){if(!t.marks.visible||0===t.timelineMarks.length){this.markLayout={glyphs:[],stacks:new Map};return}this.markLayout=function(e){let t=function(e,t,i=20){let o=new Map;for(let t of e){let e=o.get(t.group);e?e.push(t):o.set(t.group,[t])}let r=[];for(let e of o.values()){e.sort((e,t)=>e.bar-t.bar);let o=[],l=NaN;for(let r of e){let e=t(r.bar),n=o[o.length-1];n&&Number.isFinite(e)&&Number.isFinite(l)&&e-l<i?n.marks.push(...r.marks):(o.push({key:r.key,bar:r.bar,group:r.group,marks:[...r.marks]}),l=e)}r.push(...o)}return r}(function(e,t,i,o){let r=new Map;e.forEach((e,l)=>{if(void 0!==e.group&&o(e.group))return;let n=function(e,t,i){let o=t.length;if(0===o||!(i>0)||!Number.isFinite(e)||e<t[0])return null;let r=t[o-1];if(e>=r+i)return o-1+Math.floor((e-r)/i);let l=0,n=o-1;for(;l<n;){let i=l+n+1>>1;t[i]<=e?l=i:n=i-1}return e<t[l]+i?l:l+1}(e.time,t,i);if(null===n)return;let a=`${n}|${e.group??""}`,s=r.get(a);s||(s={key:a,bar:n,group:e.group,marks:[],seq:[]},r.set(a,s)),s.marks.push(e),s.seq.push(l)});let l=[];for(let e of r.values()){let t=e.marks.map((t,i)=>({m:t,seq:e.seq[i]})).sort((e,t)=>e.m.time-t.m.time||e.seq-t.seq);l.push({key:e.key,bar:e.bar,group:e.group,marks:t.map(e=>e.m)})}return l}(e.marks,e.barTimes,e.intervalMs,e.hidden),e.xOf),i=function(e,t){let i=new Map;for(let o of(e.forEach((e,t)=>i.set(e.id,t)),t))void 0===o.group||i.has(o.group)||i.set(o.group,i.size);return e=>void 0===e?Number.MAX_SAFE_INTEGER:i.get(e)??Number.MAX_SAFE_INTEGER-1}(e.groups,t),o=new Map;for(let e of t){let t=o.get(e.bar);t?t.push(e):o.set(e.bar,[e])}let r=[],l=new Map;for(let[t,n]of o){let o=e.xOf(t);if(!Number.isFinite(o)||o<-20||o>e.dataW+20)continue;n.sort((e,t)=>i(e.group)-i(t.group));let a=n.length>1,s=a&&e.expanded===t,h=a&&!s,d=[],c=n[0].marks.length>1?20:16,p=e.axisY-4;n.forEach((i,r)=>{let l,n=h?c:i.marks.length>1?20:16;s?(l=p-n/2,p-=n+4):l=e.axisY-4-n/2-3*r,d.push({cluster:i,x:o,y:l,size:n,stack:t,depth:r,decked:h})});for(let e=d.length-1;e>=0;e--)r.push(d[e]);l.set(t,d)}return{glyphs:r,stacks:l}}({marks:t.timelineMarks,groups:t.markGroups,hidden:e=>{var i,o;return i=t.marks,o=t.markGroups,!or(i.groups,e,o)},barTimes:this.barTimes(t),intervalMs:i.barInterval,xOf:e=>i.logicalToX(e),axisY:l,dataW:r,expanded:t.marksExpandedStack});let a="undefined"!=typeof performance?performance.now():Date.now();e.save(),e.beginPath(),e.rect(0,0,r,l),e.clip(),function(e,t,i){if(0!==t.glyphs.length){for(let d of(e.save(),e.setLineDash([]),e.textAlign="center",e.textBaseline="middle",t.glyphs)){var o,r,l,a,s,h;let t=d.cluster.marks[0];if(!t)continue;let c=d.cluster.key,p=t.glyph.color,u=c===i.activeKey||c===i.flashKey,g=d.size*(c===i.hoverKey?!((o=i.nowMs-i.hoverSince)>0)||o>=360?1:1+.1*Math.sin(Math.PI*o/360):1);if(0===d.depth){let t=Math.round(d.x)+.5;e.lineWidth=1,e.strokeStyle=i.stemColor,e.beginPath(),e.moveTo(t,d.y+d.size/2),e.lineTo(t,i.axisY),e.stroke()}let m=t.glyph.shape??"circle",b=function(e,t,i,o,r){let l=r/2;switch(e.beginPath(),t){case"square":{var n,a,s,h,d,c;let t=Math.min(3,l/2);return n=e,a=i-l,s=o-l,h=r,d=r,c=t,n.moveTo(a+c,s),n.lineTo(a+h-c,s),n.quadraticCurveTo(a+h,s,a+h,s+c),n.lineTo(a+h,s+d-c),n.quadraticCurveTo(a+h,s+d,a+h-c,s+d),n.lineTo(a+c,s+d),n.quadraticCurveTo(a,s+d,a,s+d-c),n.lineTo(a,s+c),n.quadraticCurveTo(a,s,a+c,s),n.closePath(),{x:i,y:o}}case"diamond":return e.moveTo(i,o-l),e.lineTo(i+l,o),e.lineTo(i,o+l),e.lineTo(i-l,o),e.closePath(),{x:i,y:o};case"pin":{let t=.82*l,r=o-l+t;return e.arc(i,r,t,.75*Math.PI,.25*Math.PI,!1),e.lineTo(i,o+l),e.closePath(),{x:i,y:r}}default:return e.arc(i,o,l,0,2*Math.PI),{x:i,y:o}}}(e,m,d.x,d.y,g);e.lineWidth=4,e.strokeStyle=i.background,e.stroke(),e.fillStyle=u?p:i.background,e.fill(),e.lineWidth=1.5,e.strokeStyle=p,e.stroke();let f=u?"#ffffff":p,v=Math.round(.62*g);if(t.glyph.icon){let o=i.icons.get(t.glyph.icon,f,v,i.dpr);o&&e.drawImage(o,b.x-v/2,b.y-v/2,v,v)}else if(t.glyph.letter){let o=(0,n.dq)(t.glyph.letter,2);e.fillStyle=f;let d=Math.round(g*(o5(o)?.38:.58));e.font=`600 ${d}px ${i.fontFamily}`,o5(o)&&(a=d,d=(s=e.measureText(o).width)>(h=(r=m,l=g,("pin"===r?.82*l:l)-3))&&s>0?Math.max(4,Math.floor(a*h/s)):a,e.font=`600 ${d}px ${i.fontFamily}`),e.fillText(o,b.x,b.y+.5)}}e.restore()}}(e,this.markLayout,{axisY:l,background:o.background,stemColor:t.style.borderColor??o.borderColor,fontFamily:o.fontFamily,dpr:i.dpr,icons:this.markIcons,hoverKey:t.marksHoverKey,hoverSince:t.marksHoverSince,activeKey:t.marksActiveKey,flashKey:t.marksFlash&&t.marksFlash.until>a?t.marksFlash.key:null,nowMs:a}),e.restore()}barTimes(e){return(this.barTimesSrc!==e.bars||this.barTimesCache.length!==e.bars.length)&&(this.barTimesSrc=e.bars,this.barTimesCache=e.bars.map(e=>e.time)),this.barTimesCache}destroy(){this.canvas=null,this.ctx=null}drawingsRange(e,t,i=0){if(this.drawScene.setSet(e,i),this.drawScene.isEmpty())return null;let o=this.drawScene.priceRange(t.from,t.to);return o?{min:o.min,max:o.max}:null}renderTrades(e,t,i,o,r,l,n){e.save(),e.translate(0,l.bounds.top),e.beginPath(),e.rect(0,0,n,l.bounds.height),e.clip(),function(e,t,i,o,r,l,n,a,s){if(0===t.length)return;let h=n.fontSize+4,d=i7(t,i,o,-1/0,1/0,h);if(0!==d.length){for(let t of(e.save(),e.font=`${n.fontSize}px ${n.fontFamily}`,e.textAlign="center",e.textBaseline="middle",d)){var c,p,u,g,m,b,f,v;let d=r(t.logical);if(d<-150||d>a+150)continue;let y=o.barAt(t.logical);if(!y)continue;let w=Math.max(l(y.low),l(y.high)),C=Math.min(l(y.low),l(y.high)),x=w+10;for(let o of t.buys){e.fillStyle=oe(o.exec,i.colors),c=e,p=d,u=x,g="exit"===o.exec.kind,c.beginPath(),c.moveTo(p,u),c.lineTo(p-4.5,u+6),c.lineTo(p+4.5,u+6),c.closePath(),c.fill(),c.fillRect(p-1.5,u+6,3,8),g&&c.fillRect(p-4.5,u-2-2,9,2),ot(e,o.exec.side,d,l(o.exec.price),s),oi(e,o.lines,d,x+14+3+h/2,h,n.color),x+=o.height+6}for(let o of(x=C-10,t.sells)){e.fillStyle=oe(o.exec,i.colors),m=e,b=d,f=x,v="exit"===o.exec.kind,m.beginPath(),m.moveTo(b,f),m.lineTo(b-4.5,f-6),m.lineTo(b+4.5,f-6),m.closePath(),m.fill(),m.fillRect(b-1.5,f-14,3,8),v&&m.fillRect(b-4.5,f+2,9,2),ot(e,o.exec.side,d,l(o.exec.price),s),oi(e,o.lines,d,x-14-3-h/2,-h,n.color),x-=o.height+6}}e.restore()}}(e,r,i.tradeMarkers,{timeToLogical:e=>t.timeToLogical(e),barAt:e=>{let t=i.bars[Math.round(e)];return t?{high:t.high,low:t.low}:null}},e=>t.logicalToX(e),e=>t.priceToY(e,l.scale,l.bounds)-l.bounds.top,{fontSize:i.style.fontSize,fontFamily:o.fontFamily,color:o.textColor},n,Math.max(1.5,.4*t.bodySpacing())),e.restore()}drawPriceAxes(e,t,i,o,r,l){if(e.strokeStyle=t.style.borderColor??o.borderColor,e.lineWidth=1,e.beginPath(),e.moveTo(r+.5,0),e.lineTo(r+.5,i.height),e.stroke(),!t.showAxisLabels)return;e.fillStyle=this.axisTextColor,e.textAlign="left";let n=`${t.style.fontSize}px ${o.fontFamily}`,a=`600 ${n}`,s=e.globalAlpha;for(let o of l)if(!o.collapsed){for(let l of this.axisTicks.ticksFor(t,o,i)){let t=i.priceToY(l.price,o.scale,o.bounds);t<o.bounds.top+6||t>o.bounds.top+o.bounds.height-4||(!0===l.major?e.font=a:!1===l.major&&(e.globalAlpha=.5*s),e.fillText(l.label,r+6,t),!0===l.major?e.font=n:!1===l.major&&(e.globalAlpha=s))}if(o.axisBands)for(let t of o.axisBands){let i=o.bounds.top+t.frac*o.bounds.height;i<o.bounds.top+6||i>o.bounds.top+o.bounds.height-4||e.fillText(t.label,r+6,i)}}e.textAlign="start"}drawPaneSeparators(e,t,i,o,r){for(let l of(e.fillStyle=t.style.separatorColor??i.borderColor,r))l.order<=0||e.fillRect(0,Math.round(l.bounds.top)-1,o,3)}drawMergedScaleColumns(e,t,i,o){if(t.showAxisLabels){for(let r of(e.textAlign="left",e.fillStyle=this.axisTextColor,t.orderedPanes()))r.collapsed||t.ownScaleIndicatorsForPane(r.id).forEach((l,n)=>{let a=t.indicatorScales.get(l.id)?.scale;if(!a)return;let s=tG(o,n+1);for(let o of oW(a,r.bounds.height,void 0,t.priceMintick,void 0,t.format)){let t=i.priceToY(o.price,a,r.bounds);t<r.bounds.top+6||t>r.bounds.top+r.bounds.height-4||e.fillText(o.label,s+5,t)}});e.textAlign="start"}}drawIndicatorTags(e,t,i,o,r,l,n,a){let s=t.showIndicatorValueLabels,h=t.showIndicatorNameLabels,d=t.showPriceLabel&&[...t.indicators.values()].some(e=>!0===e.priceAxisLabel);if(!s&&!h&&!d)return;let c=t.bars.length-1;if(c<0)return;let p=of(o.background),u=Math.min(160,.4*r),g=new Map;for(let e of t.indicators.values())g.set(e.id,o4(e,c-t.offsetOf(e.id)));for(let d of n){if(d.collapsed||!(d.bounds.height>0))continue;let n=d.bounds.top,c=n+d.bounds.height,m=t.ownScaleIndicatorsForPane(d.id),b=[],f=(e,o,r,l,a)=>{let p=!0===e.priceAxisLabel&&t.showPriceLabel;if(!s&&!h&&!p)return;let u=i.priceToY(o.value,l,d.bounds);if(!(u>=n&&u<=c))return;let m="own"===e.percentBaseline?void 0:t.priceMintick,f=a?oq(l,d.bounds.height,o.value,od(t,d,e),m,d.axisFormat,t.format,p?"lastPrice":"priceAxis"):oq(l,d.bounds.height,o.value,void 0,m,void 0,t.format,p?"lastPrice":"priceAxis");if(!f)return;let v=p&&o.series.title||this.tagName(e,o.series,g.get(e.id).length);b.push({column:r,slot:{top:u-8,height:16},text:f,color:o.color,name:v,...p?{solidPill:!0}:{}})};for(let e of t.orderedIndicatorsForPane(d.id)){let i=!0===e.ownScale?m.indexOf(e):-1;for(let o of g.get(e.id))!0!==o.series.overlay&&f(e,o,i+1,t.scaleFor(e,d),i<0)}if(d===a)for(let e of t.indicators.values())for(let t of g.get(e.id))!0===t.series.overlay&&f(e,t,0,d.scale,!0);if(0===b.length)continue;let v=d===a?this.priceChipSlot(t,i,d):null,y=h||b.some(e=>e.solidPill&&0===e.column),w=new Map;for(let e of b){let t=y?0:e.column,i=w.get(t);i?i.push(e):w.set(t,[e])}for(let[t,i]of(e.save(),e.beginPath(),e.rect(0,n,l,c-n),e.clip(),e.textBaseline="middle",e.textAlign="center",w)){let l=i.map(e=>e.slot);v&&0===t&&l.push(v);let a=function(e,t,i){let o=e.map((e,t)=>t).sort((t,i)=>e[t].top-e[i].top||Number(!0===e[i].fixed)-Number(!0===e[t].fixed)||t-i).map(t=>({items:[t],top:e[t].top,height:e[t].height})),r=o=>{let r=0,l=null,n=0;for(let t of o.items){let i=e[t];i.fixed&&null===l&&(l=i.top-r),n+=i.top-r,r+=i.height}if(o.height=r,null!==l){o.top=l;return}let a=n/o.items.length;o.top=o.height>i-t?t:Math.min(Math.max(a,t),i-o.height)};for(o.forEach(r);;){let e=!1,t=[];for(let i of o){let o=t[t.length-1];o&&o.top+o.height>i.top+1e-6?(o.items.push(...i.items),r(o),e=!0):t.push(i)}if(o=t,!e)break}let l=Array(e.length);for(let t of o){let i=t.top;for(let o of t.items)l[o]=i,i+=e[o].height}return l}(l,n,c);i.forEach((t,i)=>{let l=a[i];if(l<n||l+16>c)return;let d=l+8,g=ov(t.color,1);if(s||t.solidPill){let i=tG(r,t.column)+1,n=e.measureText(t.text).width+8;e.fillStyle=g,e.fillRect(i,l,n,16),e.fillStyle=oJ(g,o.background),e.fillText(t.text,i+n/2,d)}if(t.solidPill&&0===t.column&&t.name){let i=re(e,t.name,u);o7(e,i,r,d,g,oJ(g,o.background)),e.textAlign="center"}else if(h&&t.name){let i=re(e,t.name,u),o=e.measureText(i).width+8,n=r-o-2,a=oy(p,t.color,.18);e.fillStyle=ov(a,1),e.fillRect(n,l,o,16),e.strokeStyle=ov(t.color,.55),e.lineWidth=1,e.strokeRect(n+.5,l+.5,o-1,15),e.fillStyle=ov(function(e,t){if(oC(e,t)>=4.5)return e;let i=[0,0,0,1],o=[1,1,1,1],r=oC(i,t)>=oC(o,t)?i:o;for(let i=1;i<=20;i+=1){let o=oy(e,r,i/20);if(oC(o,t)>=4.5)return o}return r}(t.color,a),1),e.fillText(i,n+o/2,d)}})}e.restore()}e.textAlign="start"}tagName(e,t,i){let o=e.displayShorttitle??e.shorttitle,r=(0,n.b6)(this.i18n,o??e.displayTitle??e.title);if(i<=1)return r;let l=t.displayTitle?(0,n.b6)(this.i18n,t.displayTitle):t.title;return l&&l!==r?`${r} ${l}`:r}priceChipSlot(e,t,i){let o=e.bars.length;if(0===o||e.candlesHidden)return null;let r=e.bars[o-1],l=t.priceToY(r.close,i.scale,i.bounds);if(l<i.bounds.top||l>i.bounds.top+i.bounds.height)return null;let n=e.showCountdown&&!e.variableDuration&&null!==oQ(r.time,t.barInterval,eT.now(),e.format);return e.showPriceLabel||n?{top:l-8,height:e.showPriceLabel&&n?32:16,fixed:!0}:null}drawPriceLineAndCountdown(e,t,i,o,r,l){let n=t.bars.length;if(!l||0===n||t.candlesHidden||l.collapsed||l.bounds.height<=0)return;let a=t.bars[n-1],s=i.priceToY(a.close,l.scale,l.bounds);if(s<l.bounds.top||s>l.bounds.top+l.bounds.height)return;let h=function(e,t,i,o){let r=e.style;switch(e.priceStyle){case"bars":return o.close>=o.open?r.bars.upColor??i.upColor:r.bars.downColor??i.downColor;case"line":case"linemarkers":case"stepline":return r.line.color??i.upColor;case"columns":{let t=ix(e.bars,e.bars.length-1);return(0,p.fu)(t?r.columns.upColor??i.upColor:r.columns.downColor??i.downColor,1)}case"area":return r.area.lineColor??i.upColor;case"baseline":{let l=Math.max(0,Math.floor(t.visibleLogicalRange().from)),n=e.baselineValue??e.bars[l]?.close??0;return o.close>=n?r.baseline.topLineColor??i.upColor:r.baseline.bottomLineColor??i.downColor}default:{let t=ia(r.candle,e.candleOverride,i.upColor,i.downColor),l=o.close>=o.open,n=l?t.up:t.down;if(!t.candle.bodyVisible&&t.candle.borderVisible)return(l?t.candle.borderUpColor:t.candle.borderDownColor)??n;return n}}}(t,i,o,a);if(t.showPriceLine){let t=Math.round(s)+.5;e.strokeStyle=h,e.lineWidth=1,o9(e,"dotted"),e.beginPath(),e.moveTo(0,t),e.lineTo(r,t),e.stroke(),o9(e,"solid")}let d=t.showCountdown&&!t.variableDuration?oQ(a.time,i.barInterval,eT.now(),t.format):null,c=null!==d,u=t.showPriceLabel;if(!u&&!c)return;let g=oq(l.scale,l.bounds.height,a.close,oh(t,l),t.priceMintick,void 0,t.format,"lastPrice"),m=r+1,b=oJ(h,o.background);if(e.textBaseline="middle",u&&t.symbolName&&t.indicatorsForPane(l.id).some(e=>!0===e.priceAxisLabel&&!0!==e.ownScale&&o4(e,n-1-t.offsetOf(e.id)).length>0)&&t.symbolName&&o7(e,t.symbolName,r,s,h,b),u&&null!==d){let t=Math.max(e.measureText(g).width,e.measureText(d).width)+8,i=s-8,o=m+4;e.fillStyle=h,e.fillRect(m,i,t,32),e.fillStyle=b,e.textAlign="left",e.fillText(g,o,i+8),e.fillText(d,o,i+24),e.textAlign="start";return}let f=u?g:d??"",v=e.measureText(f).width+8;e.fillStyle=h,e.fillRect(m,s-8,v,16),e.fillStyle=b,e.textAlign="center",e.fillText(f,m+v/2,s),e.textAlign="start"}drawTimeAxis(e,t,i,o,r,l,n){if(e.strokeStyle=t.style.borderColor??o.borderColor,e.lineWidth=1,e.beginPath(),e.moveTo(0,l+.5),e.lineTo(r,l+.5),e.stroke(),!t.showAxisLabels)return;e.fillStyle=this.axisTextColor,e.textAlign="center";let a=l+(n-l)/2,s=i.visibleTimeRange(),h=oO((s.from+s.to)/2,oF(t.timezone,i.barInterval)),d=Math.max(3,Math.min(8,Math.floor(r/64))),c=oZ(s.from,s.to,d,h,t.format,i.logicalToTime(0)).map(t=>({...t,x:i.timeToX(t.time),half:e.measureText(t.label).width/2})).filter(e=>e.x>=20&&e.x<=r-20),p=[],u=t=>{let i=t.x-t.half,o=t.x+t.half;p.every(e=>o+12<=e.l||i-12>=e.r)&&(p.push({l:i,r:o}),e.fillText(t.label,t.x,a))};for(let e of c)e.major&&u(e);for(let e of c)e.major||u(e);e.textAlign="start"}};function o8(e,t){return e?t?{min:Math.min(e.min,t.min),max:Math.max(e.max,t.max)}:e:t}function o7(e,t,i,o,r,l){let n=Math.ceil(e.measureText(t).width)+12,a=i-n-1,s=o-8;e.fillStyle=r,e.beginPath(),e.moveTo(a+2,s),e.lineTo(a+n,s),e.lineTo(a+n,s+16),e.lineTo(a+2,s+16),e.quadraticCurveTo(a,s+16,a,s+16-2),e.lineTo(a,s+2),e.quadraticCurveTo(a,s,a+2,s),e.closePath(),e.fill(),e.fillStyle=l,e.textAlign="center",e.fillText(t,a+n/2,o),e.textAlign="start"}function o9(e,t){"dashed"===t?e.setLineDash([6,4]):"dotted"===t?e.setLineDash([2,3]):e.setLineDash([])}function re(e,t,i){if(e.measureText(t).width<=i)return t;let o=t;for(;o.length>1&&e.measureText(`${o}…`).width>i;)o=o.slice(0,-1);return`${o.trimEnd()}…`}var rt=class{constructor(e,t){this.plot=e,this.deps=t,this.tip=null,this.timer=null,this.current=null,this.onMove=e=>{if("mouse"!==e.pointerType)return;let t=this.plot.getBoundingClientRect(),i=e.clientX-t.left,o=e.clientY-t.top,r=this.deps.lookup(i,o);if(!r)return void this.clear();r!==this.current&&(this.clear(),this.current=r,this.timer=window.setTimeout(()=>this.show(r,i,o),350))},this.onLeave=()=>{this.clear()},e.addEventListener("pointermove",this.onMove),e.addEventListener("pointerleave",this.onLeave),e.addEventListener("pointerdown",this.onLeave)}destroy(){this.plot.removeEventListener("pointermove",this.onMove),this.plot.removeEventListener("pointerleave",this.onLeave),this.plot.removeEventListener("pointerdown",this.onLeave),this.clear()}show(e,t,i){let o=this.plot.ownerDocument.createElement("div");o.textContent=e,o.style.cssText="position:absolute;z-index:var(--vela-z-tooltip);pointer-events:none;background:var(--vela-bg);border:1px solid var(--vela-border);color:var(--vela-fg);border-radius:var(--vela-radius-md);padding:4px 9px;box-shadow:var(--vela-shadow);font:var(--vela-font-size-md) var(--vela-font);max-width:260px;",e$(o,this.deps.theme()),this.plot.appendChild(o);let r=this.plot.clientWidth,l=this.plot.clientHeight;o.style.left=`${Math.max(0,Math.min(t+12,r-o.offsetWidth-4))}px`,o.style.top=`${Math.max(0,Math.min(i+16,l-o.offsetHeight-4))}px`,this.tip=o}clear(){null!==this.timer&&(clearTimeout(this.timer),this.timer=null),this.tip?.remove(),this.tip=null,this.current=null}},ri=class{constructor(){this.canvas=null,this.ctx=null,this.shade=null}mount(e){this.canvas=e,this.ctx=e.getContext("2d")}get shadeRightArea(){return this.shade}render(e,t,i,o=null,r=null){let l;this.shade=null;let n=this.ctx,a=this.canvas;if(!n||!a)return;let s=t.dpr;iQ(n,s),n.clearRect(0,0,a.width/s,a.height/s),null!==o&&this.drawSeparatorHover(n,a.width/s,i,o),r&&this.drawExternal(n,r,e,t,i);let h=e.crosshair,d=t.width,c=t.height;if(!h||h.x<0||h.x>d||h.y<0||h.y>c)return;let p=e.style.crosshair,u=e.crosshairOverride,g=u?.vertical!==!1,m=u?.horizontal!==!1;n.font=`${e.style.fontSize}px ${i.fontFamily}`,n.textBaseline="middle";let b=Math.round(t.xToLogical(h.x)),f=ro(t.logicalToX(b),u?.width??p.width);if(g&&u?.shadeRight){let e=Math.max(0,Math.round(t.logicalToX(b+.5)));e<d&&this.paintShade(n,u.shadeRight,e,d,c)}for(let t of(n.strokeStyle=u?.color??p.color??i.textColor,n.lineWidth=u?.width??p.width,n.globalAlpha=u?.opacity??p.opacity,rr(n,u?.style??p.style),n.beginPath(),g&&(n.moveTo(f,0),n.lineTo(f,c)),m&&(n.moveTo(0,Math.round(h.y)+.5),n.lineTo(d,Math.round(h.y)+.5)),n.stroke(),n.setLineDash([]),n.lineWidth=1,n.globalAlpha=1,e.panes.values()))if(h.y>=t.bounds.top&&h.y<=t.bounds.top+t.bounds.height){l=t;break}let v=p.labelBackground??i.borderColor;if(m&&l&&"none"!==l.axisFormat){let o=t.yToPrice(h.y,l.scale,l.bounds);this.chip(n,d+1,h.y,oq(l.scale,l.bounds.height,o,oh(e,l),e.priceMintick,l.axisFormat,e.format,"crosshair"),v,"left",!1,i.background)}let y=e.variableDuration||t.barInterval>0&&t.barInterval<6e4;g&&this.chip(n,f,c+1,oY(t.logicalToTime(b),e.timezone,t.barInterval,e.format,"crosshair",y),v,"center",!0,i.background)}destroy(){this.canvas=null,this.ctx=null,this.shade=null}drawExternal(e,t,i,o,r){let l=i.style.crosshair,n=i.crosshairOverride,a=o.width,s=o.height,h=ro(t.x,n?.width??l.width);if(n?.vertical===!1)return;if(n?.shadeRight){let i=Math.max(0,Math.round(o.logicalToX(Math.round(o.xToLogical(t.x))+.5)));i<a&&this.paintShade(e,n.shadeRight,i,a,s)}if(!1===t.line||h<0||h>a)return;e.font=`${i.style.fontSize}px ${r.fontFamily}`,e.textBaseline="middle",e.strokeStyle=n?.color??l.color??r.textColor,e.lineWidth=n?.width??l.width,e.globalAlpha=(n?.opacity??l.opacity)*.55,rr(e,n?.style??l.style),e.beginPath(),e.moveTo(h,0),e.lineTo(h,s),null!=t.y&&n?.horizontal!==!1&&(e.moveTo(0,Math.round(t.y)+.5),e.lineTo(a,Math.round(t.y)+.5)),e.stroke(),e.setLineDash([]),e.lineWidth=1,e.globalAlpha=.8;let d=l.labelBackground??r.borderColor;if(null!=t.y&&null!=t.price&&n?.horizontal!==!1){let o;for(let e of i.panes.values())if(t.y>=e.bounds.top&&t.y<=e.bounds.top+e.bounds.height){o=e;break}o&&"none"!==o.axisFormat&&this.chip(e,a+1,t.y,oq(o.scale,o.bounds.height,t.price,oh(i,o),i.priceMintick,o.axisFormat,i.format,"crosshair"),d,"left",!1,r.background)}let c=i.variableDuration||o.barInterval>0&&o.barInterval<6e4;this.chip(e,h,s+1,oY(t.time,i.timezone,o.barInterval,i.format,"crosshair",c),d,"center",!0,r.background),e.globalAlpha=1}paintShade(e,t,i,o,r){e.fillStyle=t.color,e.globalAlpha=t.opacity??1,e.fillRect(i,0,o-i,r),e.globalAlpha=1;let l=this.shade?Math.min(this.shade.x,i):i;this.shade={x:l,width:o-l,height:r}}drawSeparatorHover(e,t,i,o){let r=Math.round(o);e.fillStyle=i.textColor,e.globalAlpha=.1,e.fillRect(0,r-4,t,8),e.globalAlpha=.55,e.fillRect(0,r-1,t,2),e.globalAlpha=1}chip(e,t,i,o,r,l,n=!1,a="#000000"){let s=e.measureText(o).width+8,h="left"===l?t:t-s/2,d=n?i:i-8;e.fillStyle=r,e.fillRect(h,d,s,16),e.fillStyle=function(e,t="#000000"){let[i,o,r,l]=iF(e),n=i,a=o,s=r;if(l<1){let[e,h,d]=iF(t);n=i*l+e*(1-l),a=o*l+h*(1-l),s=r*l+d*(1-l)}let h=.2126*iO(n)+.7152*iO(a)+.0722*iO(s);return(h+.05)/.05>=1.05/(h+.05)?"#000000":"#ffffff"}(r,a),e.textAlign="center",e.fillText(o,h+s/2,d+8+2*!!n),e.textAlign="start"}};function ro(e,t){return Math.round(e)+.5*(Math.round(t)%2==1)}function rr(e,t){"dashed"===t?e.setLineDash([6,4]):"dotted"===t?e.setLineDash([2,3]):e.setLineDash([])}var rl={candles:(0,n.ab)("chart.priceStyle.candles","Candles"),bars:(0,n.ab)("chart.priceStyle.bars","Bars"),line:(0,n.ab)("chart.priceStyle.line","Line"),linemarkers:(0,n.ab)("chart.priceStyle.linemarkers","Line with markers"),stepline:(0,n.ab)("chart.priceStyle.stepline","Step line"),area:(0,n.ab)("chart.priceStyle.area","Area"),baseline:(0,n.ab)("chart.priceStyle.baseline","Baseline"),columns:(0,n.ab)("chart.priceStyle.columns","Columns")},rn=(0,n.ab)("chart.priceStyle.unavailable","Not available for this symbol's data");function ra(e){return(0,n.rI)(e).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}var rs="events",rh="events.groups";function rd(e){return`${rh}.${ra(e)}`}function rc(e,t){if(0===t.size)return!1;let i=e;for(;;){if(t.has(i))return!0;let e=i.lastIndexOf(".");if(e<0)return!1;i=i.slice(0,e)}}function rp(e){if("heading"===e.kind||"header"===e.kind)return ra(e.label);let t=(0,o.ZNF)(e);if(t.toggle)return t.toggle.key;for(let e of t.controls)if("hint"!==e.kind)return e.key;return ra(t.label)}function ru(e,t,i){if(0===i.size)return[...e];let o=[],r=!1,l=!1;for(let n of e){let e=`${t}.${rp(n)}`;if("heading"===n.kind){r=rc(e,i),l=!1,r||o.push(n);continue}if("header"===n.kind){if(r)continue;(l=rc(e,i))||o.push(n);continue}r||l||rc(e,i)||o.push(n)}return o}function rg(e){return e.id??ra(e.title)}function rm(e){return e.id??ra(e.label)}var rb=["symbol","symbol.type","symbol.style.candles","symbol.style.candles.body","symbol.style.candles.borders","symbol.style.candles.wick","symbol.style.candles.spacing","symbol.style.bars","symbol.style.bars.up-color","symbol.style.bars.down-color","symbol.style.bars.spacing","symbol.style.line","symbol.style.line.color","symbol.style.line.width","symbol.style.area","symbol.style.area.line-color","symbol.style.area.width","symbol.style.area.top-fill","symbol.style.area.bottom-fill","symbol.style.baseline","symbol.style.baseline.top-line","symbol.style.baseline.bottom-line","symbol.style.baseline.fill-top","symbol.style.baseline.fill-bottom","symbol.style.baseline.base-level","symbol.style.baseline.width","symbol.style.columns","symbol.style.columns.up-color","symbol.style.columns.down-color","symbol.style.columns.spacing","symbol.animation","symbol.animation.zoom","symbol.animation.pan","symbol.animation.autoscale","symbol.animation.price-changes","symbol.animation.intro","symbol.timezone","scales","scales.price-scale","scales.price-scale.mode","scales.price-scale.invert","scales.price-scale.price-only","scales.price-scale.free-pan","scales.price-scale.last-price-line","scales.price-scale.last-price-label","scales.price-scale.countdown","scales.price-scale.indicator-value-labels","scales.price-scale.indicator-name-labels","scales.price-scale.axis-labels","scales.price-scale.border-color","scales.crosshair","scales.crosshair.color","scales.crosshair.width","scales.crosshair.style","canvas","canvas.background","canvas.background.color","canvas.background.text-color","canvas.background.text-size","canvas.background.pane-separator","canvas.grid","canvas.grid.vertical","canvas.grid.horizontal","canvas.margins","canvas.margins.top","canvas.margins.bottom","canvas.margins.right","canvas.theme"],rf={sections:(0,n.ab)("chart.settings.sections","Sections"),chartSettings:(0,n.ab)("chart.settings.chartSettings","Chart settings"),resetDefaults:(0,n.ab)("chart.settings.resetDefaults","Reset defaults"),symbol:(0,n.ab)("chart.settings.symbol","Symbol"),chartType:(0,n.ab)("chart.settings.chartType","Chart type"),type:(0,n.ab)("chart.settings.type","Type"),candles:(0,n.ab)("chart.settings.candles","Candles"),body:(0,n.ab)("chart.settings.body","Body"),borders:(0,n.ab)("chart.settings.borders","Borders"),wick:(0,n.ab)("chart.settings.wick","Wick"),spacing:(0,n.ab)("chart.settings.spacing","Spacing"),bars:(0,n.ab)("chart.settings.bars","Bars"),colorUp:(0,n.ab)("chart.settings.colorUp","Up color"),colorDown:(0,n.ab)("chart.settings.colorDown","Down color"),line:(0,n.ab)("chart.settings.line","Line"),color:(0,n.ab)("chart.settings.color","Color"),width:(0,n.ab)("chart.settings.width","Width"),area:(0,n.ab)("chart.settings.area","Area"),lineColor:(0,n.ab)("chart.settings.lineColor","Line color"),topFill:(0,n.ab)("chart.settings.topFill","Top fill"),bottomFill:(0,n.ab)("chart.settings.bottomFill","Bottom fill"),baseline:(0,n.ab)("chart.settings.baseline","Baseline"),topLine:(0,n.ab)("chart.settings.topLine","Top line"),bottomLine:(0,n.ab)("chart.settings.bottomLine","Bottom line"),fillTopArea:(0,n.ab)("chart.settings.fillTopArea","Fill top area"),fillBottomArea:(0,n.ab)("chart.settings.fillBottomArea","Fill bottom area"),baseLevelPct:(0,n.ab)("chart.settings.baseLevelPct","Base level %"),columns:(0,n.ab)("chart.settings.columns","Columns"),animation:(0,n.ab)("chart.settings.animation","Animation"),animateZoom:(0,n.ab)("chart.settings.animateZoom","Animate zoom"),animateZoomHint:(0,n.ab)("chart.settings.animateZoomHint","Glide the chart to each zoom step instead of jumping."),panMomentum:(0,n.ab)("chart.settings.panMomentum","Pan momentum"),panMomentumHint:(0,n.ab)("chart.settings.panMomentumHint","Keep gliding briefly after a drag release, and ease scroll-to-latest and keyboard pans."),animatePriceScale:(0,n.ab)("chart.settings.animatePriceScale","Animate price scale"),animatePriceScaleHint:(0,n.ab)("chart.settings.animatePriceScaleHint","Glide the price scale to its new range while zooming or panning."),animatePriceChanges:(0,n.ab)("chart.settings.animatePriceChanges","Animate price changes"),animatePriceChangesHint:(0,n.ab)("chart.settings.animatePriceChangesHint","Glide the live bar to each new price instead of snapping."),revealOnLoad:(0,n.ab)("chart.settings.revealOnLoad","Reveal on load"),revealOnLoadHint:(0,n.ab)("chart.settings.revealOnLoadHint","Draw the candles in when a chart first loads. Takes effect on the next load."),timeZone:(0,n.ab)("chart.settings.timeZone","Time zone"),scalesAndLines:(0,n.ab)("chart.settings.scalesAndLines","Scales and lines"),priceScale:(0,n.ab)("chart.settings.priceScale","Price scale"),mode:(0,n.ab)("chart.settings.mode","Mode"),regular:(0,n.ab)("chart.settings.regular","Regular"),percent:(0,n.ab)("chart.settings.percent","Percent"),indexedTo100:(0,n.ab)("chart.settings.indexedTo100","Indexed to 100"),logarithmic:(0,n.ab)("chart.settings.logarithmic","Logarithmic"),invertScale:(0,n.ab)("chart.settings.invertScale","Invert scale"),scalePriceOnly:(0,n.ab)("chart.settings.scalePriceOnly","Scale price chart only"),freePan:(0,n.ab)("chart.settings.freePan","Free pan"),lastPriceLine:(0,n.ab)("chart.settings.lastPriceLine","Last price line"),lastPriceLabel:(0,n.ab)("chart.settings.lastPriceLabel","Last price label"),countdownToBarClose:(0,n.ab)("chart.settings.countdownToBarClose","Countdown to bar close"),indicatorValueLabels:(0,n.ab)("chart.settings.indicatorValueLabels","Indicator value labels"),indicatorNameLabels:(0,n.ab)("chart.settings.indicatorNameLabels","Indicator name labels"),axisLabels:(0,n.ab)("chart.settings.axisLabels","Axis labels"),scaleBorderColor:(0,n.ab)("chart.settings.scaleBorderColor","Scale border color"),crosshair:(0,n.ab)("chart.settings.crosshair","Crosshair"),style:(0,n.ab)("chart.settings.style","Style"),solid:(0,n.ab)("chart.settings.solid","Solid"),dashed:(0,n.ab)("chart.settings.dashed","Dashed"),dotted:(0,n.ab)("chart.settings.dotted","Dotted"),canvas:(0,n.ab)("chart.settings.canvas","Canvas"),backgroundAndText:(0,n.ab)("chart.settings.backgroundAndText","Background & text"),background:(0,n.ab)("chart.settings.background","Background"),textColor:(0,n.ab)("chart.settings.textColor","Text color"),textSize:(0,n.ab)("chart.settings.textSize","Text size"),paneSeparatorColor:(0,n.ab)("chart.settings.paneSeparatorColor","Panel separator color"),grid:(0,n.ab)("chart.settings.grid","Grid"),vertical:(0,n.ab)("chart.settings.vertical","Vertical"),horizontal:(0,n.ab)("chart.settings.horizontal","Horizontal"),margins:(0,n.ab)("chart.settings.margins","Margins"),top:(0,n.ab)("chart.settings.top","Top"),bottom:(0,n.ab)("chart.settings.bottom","Bottom"),right:(0,n.ab)("chart.settings.right","Right"),theme:(0,n.ab)("chart.settings.theme","Theme"),events:(0,n.ab)("chart.settings.events","Events"),visibleEvents:(0,n.ab)("chart.settings.visibleEvents","Visible events")},rv=new Map([["heikinashi","candles"],["linemarkers","line"],["stepline","line"]]),ry={colorTheme:(0,n.ab)("chart.settings.colorTheme","Color theme"),dark:(0,n.ab)("chart.settings.themeDark","Dark"),light:(0,n.ab)("chart.settings.themeLight","Light")},rw={bars:(0,n.ab)("chart.settings.unitBars","{count, plural, one {bar} other {bars}}")},rC={remove:(0,n.ab)("chart.settings.removeInstance","Remove {name}"),add:(0,n.ab)("chart.settings.addInstance","Add {name}")},rx="vela-settings-controls",rk=class{constructor(e,t,i=null){this.container=e,this.theme=t,this.i18n=i,this.root=null,this.ui=null,this.onChange=null,this.onImport=null,this.onReset=null,this.config=null,this.priceStyleState=null,this.syncTypeTabs=null,this.hostSections=[],this.markGroups=[],this.markGroupOwnVisible=()=>!0,this.markGroupVisible=()=>!0,this.themeControl=null,this.tabs=[],this.hintTips=[],this.typeActiveInstance=new Map,this.typeActiveGroup=new Map,this.activeSection=null,this.mobileLayout=!1,this.toggleRail=null,this.hiddenSettings=new Set,"static"===getComputedStyle(e).position&&(e.style.position="relative")}setHostSections(e){this.hostSections=e}setMarkGroups(e,t,i=t){this.markGroupOwnVisible=i,this.markGroups=e,this.markGroupVisible=t}setHiddenSettings(e){let t=new Set(e),i=t.size===this.hiddenSettings.size&&[...t].every(e=>this.hiddenSettings.has(e));this.hiddenSettings=t,i||this.reopenIfLive()}setPriceStyleState(e){this.priceStyleState=e}setThemeControl(e,t){this.themeControl={current:e,onSelect:t}}refreshConfig(e){this.config&&(this.config=e)}t(e,t){return(0,n.b6)(this.i18n?.()??null,e,t)}relocalize(){this.reopenIfLive()}setTheme(e){this.theme=e,this.reopenIfLive()}setLayoutMode(e){let t="mobile"===e;t!==this.mobileLayout&&(this.mobileLayout=t,this.reopenIfLive())}reopenIfLive(){if(!this.root)return;let e=this.config,t=this.onChange,i=this.onImport,o=this.onReset,r=this.activeSection;this.close(),e&&t&&this.open(e,t,i??void 0,o??void 0,r??void 0)}isOpen(){return null!==this.root}toggle(e,t,i,o,r){this.root?this.close():this.open(e,t,i,o,r)}showSection(e){this.tabs.find(t=>t.title.toLowerCase()===e.toLowerCase())?.show()}open(e,t,i,o,r){let n;this.close(),this.config=e,this.onChange=t,this.onImport=i??null,this.onReset=o??null,function(){if("undefined"==typeof document)return;let e=document.getElementById(rx);if(e?.dataset.rev==="6")return;let t=e??document.createElement("style");t.id=rx,t.dataset.rev="6",t.textContent=(0,d.AH)`@layer vela.chrome {
135
+
136
+ ${(0,S.u9)(".vela-sd-pane")}
137
+ /* Tab rail / footer button / header close: base styles live HERE, not inline on the
138
+ elements — inline declarations always beat stylesheet :hover rules, which is exactly
139
+ what killed these hovers before. Active tab state is the .on class,
140
+ hover fills follow the app convention (--vela-hover + --vela-fg-bright, fast transition). */
141
+ .vela-sd-tab{text-align:start;padding:9px 12px;background:transparent;border:none;border-radius:${c.t.radius.md};color:${c.t.fg.muted};font-weight:600;font-size:13px;font-family:inherit;cursor:pointer;transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
142
+ .vela-sd-tab:hover{background:${c.t.hover};color:${c.t.fg.bright};}
143
+ .vela-sd-tab.on{background:${c.t.active};color:${c.t.fg.bright};}
144
+ .vela-sd-btn{height:30px;padding:0 14px;font-size:${c.t.fontSize.md};color:${c.t.fg};background:${c.t.surface.sunken};border:1px solid ${c.t.border};border-radius:${c.t.radius.md};cursor:pointer;font-family:inherit;transition:background ${c.t.dur.fast} ease,border-color ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
145
+ .vela-sd-btn:hover{background:${c.t.hover};border-color:${c.t.border.strong};color:${c.t.fg.bright};}
146
+ .vela-sd-close{cursor:pointer;display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;color:${c.t.fg.muted};line-height:0;width:30px;height:30px;border-radius:${c.t.radius.sm};transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
147
+ .vela-sd-close:hover{background:${c.t.hover};color:${c.t.fg.bright};}
148
+ /* Rows/blocks gated away by chart-type conditions, TOC filters, or the instance strip.
149
+ !important: the pane grid rewrites inline display ('contents') AFTER the initial
150
+ visibility pass, so a class must win. */
151
+ .vela-sd-hide{display:none !important;}
152
+ /* Indented rail sub-entry (a chart-type section's subsection tab). */
153
+ .vela-sd-tab-sub{padding-inline-start:28px;font-weight:600;font-size:12px;}
154
+ /* Instance strip: a tab per present instance (label, ✕ on the active removable one)
155
+ and a dashed + that turns on the next absent instance. The rule under it separates
156
+ the strip from the instance's TOC + rows area. */
157
+ .vela-sd-itabs{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:14px 0 0;padding-bottom:12px;border-bottom:1px solid ${c.t.border};}
158
+ .vela-sd-itab{display:inline-flex;align-items:center;gap:7px;height:30px;padding:0 11px;background:transparent;border:1px solid ${c.t.border};border-radius:${c.t.radius.md};color:${c.t.fg.muted};font-family:inherit;font-size:${c.t.fontSize.md};font-weight:600;cursor:pointer;transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease,border-color ${c.t.dur.fast} ease;}
159
+ .vela-sd-itab:hover{background:${c.t.hover};color:${c.t.fg.bright};}
160
+ .vela-sd-itab.on{background:${c.t.active};color:${c.t.fg.bright};border-color:${c.t.border.strong};}
161
+ .vela-sd-ix{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;margin-inline-end:-4px;border-radius:${c.t.radius.sm};color:${c.t.fg.muted};font-size:10px;line-height:1;}
162
+ .vela-sd-ix:hover{background:${c.t.hover};color:${c.t.fg.bright};}
163
+ .vela-sd-itab-add{border-style:dashed;min-width:30px;justify-content:center;padding:0;}
164
+ /* Structured pane: group TOC column + rows column, TOP-ALIGNED (the shared padding-top
165
+ lives on the wrap, never on one column). The TOC sticks while the pane scrolls; the
166
+ vertical rule sits on the rows column so it spans the full content height. When every
167
+ group gates out the TOC hides and .no-toc drops the rule with it. */
168
+ .vela-sd-struct{display:flex;align-items:flex-start;padding-top:14px;}
169
+ .vela-sd-toc{position:sticky;top:0;flex:0 0 auto;min-width:104px;display:flex;flex-direction:column;gap:2px;padding:2px 14px 0 0;}
170
+ .vela-sd-struct>[data-sd-rows-host]{border-inline-start:1px solid ${c.t.border};padding-inline-start:18px;}
171
+ .vela-sd-struct.no-toc>[data-sd-rows-host]{border-inline-start:none;padding-inline-start:0;}
172
+ .vela-sd-toc-btn{text-align:start;padding:6px 10px;background:transparent;border:none;border-radius:${c.t.radius.sm};color:${c.t.fg.muted};font-family:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
173
+ .vela-sd-toc-btn:hover{background:${c.t.hover};color:${c.t.fg.bright};}
174
+ .vela-sd-toc-btn.on{background:${c.t.active};color:${c.t.fg.bright};}
175
+ /* Soft-disable: a subsection's enableKey is off — rows stay visible (browseable) but
176
+ muted and non-interactive. Applied to each row's children so it survives display:contents;
177
+ !important beats the inline opacity on labels. */
178
+ .vela-sd-soft>*{opacity:0.4 !important;pointer-events:none !important;}
179
+ /* A mark group nested under a parent group on the Events tab: indented one step per level
180
+ (--vela-sd-depth). The indent rides the first child (the switch) as a MARGIN — padding
181
+ would push the switch's own tick out of its box. */
182
+ .vela-sd-nested>*:first-child{margin-inline-start:calc(var(--vela-sd-depth,1)*24px);}
183
+ /* ── mobile presentation (.vela-sd-mobile on the scrim; structural sizes are inline in open()) ──
184
+ The tab rail becomes a burger-opened overlay sidebar; the group TOC becomes a sticky
185
+ row of horizontally scrollable tabs; the instance strip scrolls instead of wrapping;
186
+ controls grow to touch size and labels may wrap (the grid gives them a flexible track). */
187
+ .vela-sd-mobile .vela-sd-burger{cursor:pointer;display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;color:${c.t.fg};line-height:0;width:36px;height:36px;border-radius:${c.t.radius.sm};margin-inline-end:2px;}
188
+ .vela-sd-mobile .vela-sd-burger:active{background:${c.t.hover};}
189
+ .vela-sd-mobile .vela-sd-railscrim{position:absolute;inset:0;z-index:2;background:${c.t.backdrop};display:none;}
190
+ .vela-sd-mobile .vela-sd-railscrim.open{display:block;}
191
+ .vela-sd-mobile .vela-sd-rail{position:absolute;inset-inline-start:0;top:0;bottom:0;z-index:3;width:min(240px,80%);box-sizing:border-box;background:${c.t.surface};border-inline-end:1px solid ${c.t.border};box-shadow:${c.t.shadow.dialog};transform:translateX(-105%);transition:transform ${c.t.dur.med} ${c.t.ease};}
192
+ .vela-sd-mobile .vela-sd-rail.open{transform:translateX(0);}
193
+ .vela-sd-mobile .vela-sd-tab{padding:12px;}
194
+ .vela-sd-mobile .vela-sd-struct{flex-direction:column;padding-top:8px;}
195
+ .vela-sd-mobile .vela-sd-toc{position:sticky;top:0;z-index:1;background:${c.t.surface};flex-direction:row;overflow-x:auto;scrollbar-width:none;min-width:0;width:100%;box-sizing:border-box;gap:4px;padding:2px 0 8px;}
196
+ .vela-sd-mobile .vela-sd-toc::-webkit-scrollbar{display:none;}
197
+ .vela-sd-mobile .vela-sd-toc-btn{flex:none;padding:8px 12px;font-size:13px;}
198
+ .vela-sd-mobile .vela-sd-struct>[data-sd-rows-host]{border-inline-start:none;padding-inline-start:0;width:100%;}
199
+ .vela-sd-mobile .vela-sd-itabs{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;}
200
+ .vela-sd-mobile .vela-sd-itabs::-webkit-scrollbar{display:none;}
201
+ .vela-sd-mobile .vela-sd-itab{height:36px;flex:none;}
202
+ .vela-sd-mobile .vela-switch{width:22px;height:22px;}
203
+ .vela-sd-mobile .vela-select-trigger,.vela-sd-mobile .vela-num input,.vela-sd-mobile .vela-width-field{height:34px;}
204
+ .vela-sd-mobile .vela-sd-close{width:40px;height:40px;}
205
+ .vela-sd-mobile .vela-sd-btn{height:38px;}
206
+ .vela-sd-mobile .vela-sd-row span,.vela-sd-mobile .vela-sd-bool span,.vela-sd-mobile .vela-field-label{white-space:normal !important;}
207
+ /* The wrap rule above is for ROW LABELS only: a select's closed value must keep its
208
+ single-line ellipsis, or a long option wraps to several lines inside the 34px
209
+ trigger and spills over the rows around it. Three classes so it outranks the
210
+ two-classes-plus-element selector above. The kit's fixed 100px column is a desktop
211
+ alignment device; on mobile the trigger hugs its value instead (the grid's control
212
+ column is max-content), capped so a long option still ellipsizes before the label. */
213
+ .vela-sd-mobile .vela-select-trigger .vela-select-label{white-space:nowrap !important;}
214
+ .vela-sd-mobile .vela-select:not([data-fill]){width:auto;min-width:100px;max-width:min(220px,55vw);}
215
+ }`,e||document.head.appendChild(t)}();let a=this.mobileLayout;a&&((n=document.createElement("button")).type="button",n.className="vela-sd-burger",n.innerHTML=(0,l.N0)("burger",16),n.title=this.t(rf.sections),n.addEventListener("click",()=>this.toggleRail?.()));let s=this.i18n?.(),h=new v.lG({host:this.container,title:this.t(rf.chartSettings),...s?{i18n:s}:{},modal:!1,contained:!0,align:"top",draggable:!a,flush:!0,variant:"settings",headerStart:n,closeOnBackdrop:!0,footer:e=>{e.style.cssText="padding:10px 14px;display:flex;align-items:center;justify-content:flex-start;gap:8px;";let t=document.createElement("button");t.type="button",t.textContent=this.t(rf.resetDefaults),t.className="vela-sd-btn",t.addEventListener("click",()=>this.onReset?.()),e.appendChild(t)},onOpenChange:e=>{e||this.ui!==h||this.close()}});a&&h.positioner.classList.add("vela-sd-mobile"),h.positioner.style.paddingTop=a?"0":"8vh",this.root=h.positioner,this.ui=h;let p=(0,T.z)(this.i18n?.(),()=>this.buildContent(h,e,r,a));h.show(),this.layoutPanes(p)}refresh(e){let t=this.ui;if(t){for(let e of((0,f.$b)(),(0,M.qD)(),this.hintTips))e();this.hintTips=[],this.config=e,(0,L.X)(t.body),t.body.replaceChildren(),this.layoutPanes((0,T.z)(this.i18n?.(),()=>this.buildContent(t,e,this.activeSection??void 0,this.mobileLayout)))}}layoutPanes(e){for(let t of e){let e=[...t.querySelectorAll("[data-sd-rows-host]")];if(0===e.length){this.layoutSettingsGrids(t);continue}for(let t of e)this.layoutSettingsGrids(t)}}buildContent(e,t,i,r){let l=document.createElement("div");l.style.cssText="display:flex;flex-direction:column;gap:0;";let n=(e,t)=>(e.dataset.sdId=t,e);l.append(n(this.section(rf.symbol),"symbol")),l.append(n(this.sectionTitle(rf.chartType),"symbol.type"));let a=this.priceStyleState?.()??{shown:t.series.style,unavailable:[]},s=a.shown,h=new Set(a.unavailable),d={},c=e=>{let t=rv.get(e)??e;for(let e of is())d[e]?.classList.toggle("vela-sd-hide",e!==t)};l.append(n(this.selectRowLabeled(rf.type,s,is().map(e=>[e,(0,o.V$N)(e)?.label??rl[e]??e]),e=>{this.emit({series:{style:e}}),c(e),this.syncTypeTabs?.(e)},{ids:h,title:rn}),"symbol.type"));let p=n(this.group(),"symbol.style.candles");p.append(this.sectionTitle(rf.candles)),p.append(n(this.toggleRow(rf.body,t.candles.bodyVisible,e=>this.emit({candles:{bodyVisible:e}}),[this.swatch(t.candles.upColor,e=>this.emit({candles:{upColor:e}})),this.swatch(t.candles.downColor,e=>this.emit({candles:{downColor:e}}))]),"symbol.style.candles.body")),p.append(n(this.toggleRow(rf.borders,t.candles.borderVisible,e=>this.emit({candles:{borderVisible:e}}),[this.swatch(t.candles.borderUpColor,e=>this.emit({candles:{borderUpColor:e}})),this.swatch(t.candles.borderDownColor,e=>this.emit({candles:{borderDownColor:e}}))]),"symbol.style.candles.borders")),p.append(n(this.toggleRow(rf.wick,t.candles.wickVisible,e=>this.emit({candles:{wickVisible:e}}),[this.swatch(t.candles.wickUpColor,e=>this.emit({candles:{wickUpColor:e}})),this.swatch(t.candles.wickDownColor,e=>this.emit({candles:{wickDownColor:e}}))]),"symbol.style.candles.wick")),p.append(n(this.numberRow(rf.spacing,t.series.spacing,.1,10,.1,e=>this.emit({series:{spacing:e}})),"symbol.style.candles.spacing")),d.candles=p,l.append(p);let u=n(this.group(),"symbol.style.bars");u.append(this.sectionTitle(rf.bars)),u.append(n(this.colorRow(rf.colorUp,t.bars.upColor,e=>this.emit({bars:{upColor:e}})),"symbol.style.bars.up-color")),u.append(n(this.colorRow(rf.colorDown,t.bars.downColor,e=>this.emit({bars:{downColor:e}})),"symbol.style.bars.down-color")),u.append(n(this.numberRow(rf.spacing,t.series.spacing,.1,10,.1,e=>this.emit({series:{spacing:e}})),"symbol.style.bars.spacing")),d.bars=u,l.append(u);let g=n(this.group(),"symbol.style.line");g.append(this.sectionTitle(rf.line)),g.append(n(this.colorRow(rf.color,t.line.color,e=>this.emit({line:{color:e}})),"symbol.style.line.color")),g.append(n(this.numberRow(rf.width,t.line.width,1,10,1,e=>this.emit({line:{width:e}})),"symbol.style.line.width")),d.line=g,l.append(g);let m=n(this.group(),"symbol.style.area");m.append(this.sectionTitle(rf.area)),m.append(n(this.colorRow(rf.lineColor,t.area.lineColor,e=>this.emit({area:{lineColor:e}})),"symbol.style.area.line-color")),m.append(n(this.numberRow(rf.width,t.area.width,1,10,1,e=>this.emit({area:{width:e}})),"symbol.style.area.width")),m.append(n(this.colorRow(rf.topFill,t.area.topColor,e=>this.emit({area:{topColor:e}})),"symbol.style.area.top-fill")),m.append(n(this.colorRow(rf.bottomFill,t.area.bottomColor,e=>this.emit({area:{bottomColor:e}})),"symbol.style.area.bottom-fill")),d.area=m,l.append(m);let b=n(this.group(),"symbol.style.baseline");b.append(this.sectionTitle(rf.baseline)),b.append(n(this.rowWith(rf.topLine,[this.swatch(t.baseline.topLineColor,e=>this.emit({baseline:{topLineColor:e}}))]),"symbol.style.baseline.top-line")),b.append(n(this.rowWith(rf.bottomLine,[this.swatch(t.baseline.bottomLineColor,e=>this.emit({baseline:{bottomLineColor:e}}))]),"symbol.style.baseline.bottom-line")),b.append(n(this.rowWith(rf.fillTopArea,[this.swatch(t.baseline.topFillColor,e=>this.emit({baseline:{topFillColor:e}})),this.swatch(t.baseline.topFillColor2,e=>this.emit({baseline:{topFillColor2:e}}))]),"symbol.style.baseline.fill-top")),b.append(n(this.rowWith(rf.fillBottomArea,[this.swatch(t.baseline.bottomFillColor2,e=>this.emit({baseline:{bottomFillColor2:e}})),this.swatch(t.baseline.bottomFillColor,e=>this.emit({baseline:{bottomFillColor:e}}))]),"symbol.style.baseline.fill-bottom")),b.append(n(this.numberRow(rf.baseLevelPct,t.baseline.baselineLevel,0,100,1,e=>this.emit({baseline:{baselineLevel:e}})),"symbol.style.baseline.base-level")),b.append(n(this.numberRow(rf.width,t.baseline.width,1,10,1,e=>this.emit({baseline:{width:e}})),"symbol.style.baseline.width")),d.baseline=b,l.append(b);let f=n(this.group(),"symbol.style.columns");for(let e of(f.append(this.sectionTitle(rf.columns)),f.append(n(this.colorRow(rf.colorUp,t.columns.upColor,e=>this.emit({columns:{upColor:e}})),"symbol.style.columns.up-color")),f.append(n(this.colorRow(rf.colorDown,t.columns.downColor,e=>this.emit({columns:{downColor:e}})),"symbol.style.columns.down-color")),f.append(n(this.numberRow(rf.spacing,t.series.spacing,.1,10,.1,e=>this.emit({series:{spacing:e}})),"symbol.style.columns.spacing")),d.columns=f,l.append(f),(0,o.AHy)())){if(!io(e.id))continue;let i=t.chartTypes[e.id]??{},o=(e,t)=>"string"==typeof i[e]&&""!==i[e]?i[e]:t,r=(e,t)=>"boolean"==typeof i[e]?i[e]:t,a=n(this.group(),`symbol.style.${e.id}`);a.append(this.sectionTitle(rf.candles)),a.append(n(this.toggleRow(rf.body,r("candleBodyVisible",t.candles.bodyVisible),t=>this.emitType(e.id,"candleBodyVisible",t),[this.swatch(o("candleUpColor",t.candles.upColor),t=>this.emitType(e.id,"candleUpColor",t)),this.swatch(o("candleDownColor",t.candles.downColor),t=>this.emitType(e.id,"candleDownColor",t))]),`symbol.style.${e.id}.body`)),a.append(n(this.toggleRow(rf.borders,r("candleBorderVisible",t.candles.borderVisible),t=>this.emitType(e.id,"candleBorderVisible",t),[this.swatch(o("candleBorderUpColor",t.candles.borderUpColor),t=>this.emitType(e.id,"candleBorderUpColor",t)),this.swatch(o("candleBorderDownColor",t.candles.borderDownColor),t=>this.emitType(e.id,"candleBorderDownColor",t))]),`symbol.style.${e.id}.borders`)),a.append(n(this.toggleRow(rf.wick,r("candleWickVisible",t.candles.wickVisible),t=>this.emitType(e.id,"candleWickVisible",t),[this.swatch(o("candleWickUpColor",t.candles.wickUpColor),t=>this.emitType(e.id,"candleWickUpColor",t)),this.swatch(o("candleWickDownColor",t.candles.wickDownColor),t=>this.emitType(e.id,"candleWickDownColor",t))]),`symbol.style.${e.id}.wick`)),a.append(n(this.numberRow(rf.spacing,t.series.spacing,.1,10,.1,e=>this.emit({series:{spacing:e}})),`symbol.style.${e.id}.spacing`)),d[e.id]=a,l.append(a)}c(s),l.append(n(this.sectionTitle(rf.animation),"symbol.animation")),l.append(n(this.boolRow(rf.animateZoom,t.animations.zoom,e=>this.emit({animations:{zoom:e}}),this.hint(rf.animateZoomHint)),"symbol.animation.zoom")),l.append(n(this.boolRow(rf.panMomentum,t.animations.pan,e=>this.emit({animations:{pan:e}}),this.hint(rf.panMomentumHint)),"symbol.animation.pan")),l.append(n(this.boolRow(rf.animatePriceScale,t.animations.autoscale,e=>this.emit({animations:{autoscale:e}}),this.hint(rf.animatePriceScaleHint)),"symbol.animation.autoscale")),l.append(n(this.boolRow(rf.animatePriceChanges,t.priceScale.animateLastPrice,e=>this.emit({priceScale:{animateLastPrice:e}}),this.hint(rf.animatePriceChangesHint)),"symbol.animation.price-changes")),l.append(n(this.boolRow(rf.revealOnLoad,t.animations.intro,e=>this.emit({animations:{intro:e}}),this.hint(rf.revealOnLoadHint)),"symbol.animation.intro")),l.append(n(this.sectionTitle(rf.timeZone),"symbol.timezone")),l.append(n(this.selectRowLabeled(rf.timeZone,(0,o.hry)(t.timeScale.timezone),this.timezoneOptions(t.timeScale.timezone),e=>this.emit({timeScale:{timezone:e}})),"symbol.timezone"));let v=e=>{for(let t of this.hostSections){if((t.placement??"after-symbol")!==e)continue;let i=rg(t);if(rc(i,this.hiddenSettings))continue;let o=function(e,t,i){if(0===i.size)return[...e];let o=[],r=!1;for(let l of e){let e=`${t}.${rm(l)}`;if("heading"===l.kind){(r=rc(e,i))||o.push(l);continue}r||rc(e,i)||o.push(l)}return o}(t.rows,i,this.hiddenSettings);if(0!==o.length)for(let i of(l.append("symbol"===e?this.sectionTitle(t.title):this.section(t.title)),o))"heading"===i.kind?l.append(this.sectionTitle(i.label)):"toggle"===i.kind?l.append(this.boolRow(i.label,i.get(),e=>i.set(e))):"color"===i.kind?l.append(this.colorRow(i.label,i.get(),e=>i.set(e))):l.append(this.selectRowLabeled(i.label,i.get(),rS(i.options),e=>i.set(e)))}},y=e=>{for(let i of(0,o.AHy)()){let o=i.settings;o&&(o.placement??"end")===e&&(rc(`type:${i.id}`,this.hiddenSettings)||this.chartTypeSection(i.id,o,t,l))}};if(v("symbol"),y("after-symbol"),v("after-symbol"),l.append(n(this.section(rf.scalesAndLines),"scales")),l.append(n(this.sectionTitle(rf.priceScale),"scales.price-scale")),l.append(n(this.selectRowLabeled(rf.mode,t.priceScale.log?"log":t.priceScale.mode,[["price",rf.regular],["percent",rf.percent],["indexed",rf.indexedTo100],["log",rf.logarithmic]],e=>this.emit({priceScale:"log"===e?{mode:"price",log:!0}:{mode:e,log:!1}})),"scales.price-scale.mode")),l.append(n(this.boolRow(rf.invertScale,t.priceScale.invert,e=>this.emit({priceScale:{invert:e}})),"scales.price-scale.invert")),l.append(n(this.boolRow(rf.scalePriceOnly,t.priceScale.priceOnly,e=>this.emit({priceScale:{priceOnly:e}})),"scales.price-scale.price-only")),l.append(n(this.boolRow(rf.freePan,t.priceScale.freePan,e=>this.emit({priceScale:{freePan:e}})),"scales.price-scale.free-pan")),l.append(n(this.separator(),"scales.price-scale")),l.append(n(this.boolRow(rf.lastPriceLine,t.priceScale.currentPriceLine,e=>this.emit({priceScale:{currentPriceLine:e}})),"scales.price-scale.last-price-line")),l.append(n(this.boolRow(rf.lastPriceLabel,t.priceScale.priceLabel,e=>this.emit({priceScale:{priceLabel:e}})),"scales.price-scale.last-price-label")),l.append(n(this.boolRow(rf.countdownToBarClose,t.priceScale.countdown,e=>this.emit({priceScale:{countdown:e}})),"scales.price-scale.countdown")),l.append(n(this.boolRow(rf.indicatorValueLabels,t.priceScale.indicatorValueLabels,e=>this.emit({priceScale:{indicatorValueLabels:e}})),"scales.price-scale.indicator-value-labels")),l.append(n(this.boolRow(rf.indicatorNameLabels,t.priceScale.indicatorNameLabels,e=>this.emit({priceScale:{indicatorNameLabels:e}})),"scales.price-scale.indicator-name-labels")),l.append(n(this.boolRow(rf.axisLabels,t.priceScale.labelsVisible,e=>this.emit({priceScale:{labelsVisible:e}})),"scales.price-scale.axis-labels")),l.append(n(this.colorRow(rf.scaleBorderColor,t.priceScale.borderColor,e=>this.emit({priceScale:{borderColor:e}})),"scales.price-scale.border-color")),l.append(n(this.sectionTitle(rf.crosshair),"scales.crosshair")),l.append(n(this.colorRow(rf.color,t.crosshair.color,e=>this.emit({crosshair:{color:e}})),"scales.crosshair.color")),l.append(n(this.numberRow(rf.width,t.crosshair.width,.5,8,.5,e=>this.emit({crosshair:{width:e}})),"scales.crosshair.width")),l.append(n(this.selectRowLabeled(rf.style,t.crosshair.style,[["solid",rf.solid],["dashed",rf.dashed],["dotted",rf.dotted]],e=>this.emit({crosshair:{style:e}})),"scales.crosshair.style")),l.append(n(this.section(rf.canvas),"canvas")),l.append(n(this.sectionTitle(rf.backgroundAndText),"canvas.background")),l.append(n(this.colorRow(rf.background,t.layout.background,e=>this.emit({layout:{background:e}})),"canvas.background.color")),l.append(n(this.colorRow(rf.textColor,t.layout.textColor,e=>this.emit({layout:{textColor:e}})),"canvas.background.text-color")),l.append(n(this.numberRow(rf.textSize,t.layout.fontSize,6,32,1,e=>this.emit({layout:{fontSize:e}})),"canvas.background.text-size")),l.append(n(this.colorRow(rf.paneSeparatorColor,t.panes.separatorColor,e=>this.emit({panes:{separatorColor:e}})),"canvas.background.pane-separator")),l.append(n(this.sectionTitle(rf.grid),"canvas.grid")),l.append(n(this.toggleRow(rf.vertical,t.grid.vertLines.visible,e=>this.emit({grid:{vertLines:{visible:e}}}),[this.swatch(t.grid.vertLines.color,e=>this.emit({grid:{vertLines:{color:e}}}))]),"canvas.grid.vertical")),l.append(n(this.toggleRow(rf.horizontal,t.grid.horzLines.visible,e=>this.emit({grid:{horzLines:{visible:e}}}),[this.swatch(t.grid.horzLines.color,e=>this.emit({grid:{horzLines:{color:e}}}))]),"canvas.grid.horizontal")),l.append(n(this.sectionTitle(rf.margins),"canvas.margins")),l.append(n(this.numberRow(rf.top,t.margins.top,0,40,1,e=>this.emit({margins:{top:e}}),"%"),"canvas.margins.top")),l.append(n(this.numberRow(rf.bottom,t.margins.bottom,0,40,1,e=>this.emit({margins:{bottom:e}}),"%"),"canvas.margins.bottom")),l.append(n(this.numberRow(rf.right,t.margins.right,0,200,1,e=>this.emit({margins:{right:e}}),rw.bars),"canvas.margins.right")),this.themeControl){let e=this.themeControl;l.append(n(this.sectionTitle(rf.theme),"canvas.theme"));let t=[["dark",ry.dark],["light",ry.light],...j().map(e=>[e.id,e.label])];l.append(n(this.selectRowLabeled(ry.colorTheme,e.current,t,t=>e.onSelect(t)),"canvas.theme"))}if(this.markGroups.length>0){l.append(n(this.section(rf.events),rs)),l.append(n(this.sectionTitle(rf.visibleEvents),rh));let e=new Map,t=function(e){let t=new Set(e.map(e=>e.id)),i=[],o=new Set,r=(t,l)=>{if(!o.has(t.id))for(let n of(o.add(t.id),i.push({group:t,depth:l}),e))n.parent===t.id&&n.id!==t.id&&r(n,l+1)};for(let i of e)void 0!==i.parent&&t.has(i.parent)&&i.parent!==i.id||r(i,0);for(let t of e)r(t,0);return i}(this.markGroups),i=()=>{for(let{group:i}of t){let t=e.get(i.id);t&&void 0!==i.parent&&t.classList.toggle("vela-sd-soft",!this.markGroupVisible(i.parent))}};for(let{group:o,depth:r}of t){let t=this.boolRow(o.label,this.markGroupOwnVisible(o.id),e=>{this.emit({marks:{groups:{[o.id]:e}}}),i()});r>0&&(t.classList.add("vela-sd-nested"),t.style.setProperty("--vela-sd-depth",String(r))),e.set(o.id,t),l.append(n(t,rd(o.id)))}i()}if(y("end"),v("end"),this.hiddenSettings.size>0){let e=!1;for(let t of[...l.children]){if(void 0!==t.dataset.sdTab&&(e=void 0!==t.dataset.sdId&&rc(t.dataset.sdId,this.hiddenSettings)),e||void 0!==t.dataset.sdId&&rc(t.dataset.sdId,this.hiddenSettings)){(0,L.X)(t),t.remove();continue}for(let e of[...t.querySelectorAll("[data-sd-id]")])rc(e.dataset.sdId,this.hiddenSettings)&&((0,L.X)(e),e.remove())}}let w=document.createElement("div");w.style.cssText=r?"display:flex;min-height:0;flex:1 1 auto;position:relative;overflow:hidden;":"display:flex;min-height:360px;max-height:calc(70vh - 100px);flex:1 1 auto;";let C=document.createElement("div");C.className="vela-sd-rail",C.style.cssText=r?"display:flex;flex-direction:column;gap:2px;padding:10px 8px;overflow-y:auto;":"flex:0 0 170px;display:flex;flex-direction:column;gap:2px;padding:10px 8px;border-right:1px solid var(--vela-border);overflow-y:auto;";let x=null;r&&((x=document.createElement("div")).className="vela-sd-railscrim",x.addEventListener("click",()=>this.toggleRail?.()),this.toggleRail=e=>{let t=e??!C.classList.contains("open");C.classList.toggle("open",t),x?.classList.toggle("open",t)});let k=document.createElement("div");k.className="vela-sd-pane",k.style.cssText=r?"flex:1;min-width:0;overflow-y:auto;overflow-anchor:none;padding:6px 14px calc(14px + env(safe-area-inset-bottom, 0px));":"flex:1;overflow-y:auto;overflow-anchor:none;padding:6px 18px 14px;";let S=[],T=null;for(let e of[...l.children]){let t=e.dataset.sdTab;if(void 0!==t){let i=e.dataset.sdTabLabel??t,o=document.createElement("div");o.style.display="none";let r=document.createElement("button");r.type="button",r.textContent=i,r.className="vela-sd-tab"+(void 0!==e.dataset.sdSub?" vela-sd-tab-sub":""),S.push({title:t,label:i,el:o,tab:r,style:e.dataset.sdStyle,visibility:e.dataset.sdVisibility}),T=o,e.remove();continue}T&&T.appendChild(e)}for(let e=S.length-1;e>=0;e--)0===S[e].el.childElementCount&&S.splice(e,1);this.syncTypeTabs=e=>{let t=!1;S.forEach((i,o)=>{if(!i.style)return;let r="always"===i.visibility||i.style===e||"heikinashi"===e&&"heikinashi"===i.style;i.tab.style.display=r?"":"none",r||"block"!==i.el.style.display||(t=!0)}),t&&M(0)};let M=t=>{S.forEach((e,i)=>{e.el.style.display=i===t?"block":"none",e.tab.classList.toggle("on",i===t)}),this.activeSection=S[t]?.title??null,r&&(e.titleEl.textContent=S[t]?.label??this.t(rf.chartSettings),this.toggleRail?.(!1))};S.forEach((e,t)=>{e.tab.addEventListener("click",()=>M(t)),C.appendChild(e.tab),k.appendChild(e.el)}),this.tabs=S.map((e,t)=>({title:e.title,show:()=>M(t)}));let A=void 0!==i?S.findIndex(e=>e.title.toLowerCase()===i.toLowerCase()):S.findIndex(e=>e.style===s&&!e.tab.classList.contains("vela-sd-tab-sub"));return M(A>=0?A:0),this.syncTypeTabs?.(s),w.append(C,k),x&&w.append(x),e.body.appendChild(w),S.map(e=>e.el)}close(){(0,f.$b)(),(0,M.qD)();let e=this.ui;for(let e of(this.ui=null,this.root=null,this.toggleRail=null,this.tabs=[],this.hintTips))e();this.hintTips=[],e?.destroy()}destroy(){this.close(),this.onChange=null,this.onImport=null,this.config=null}emitType(e,t,i){this.emit({chartTypes:{[e]:{[t]:i}}})}emit(e){this.onChange?.(e)}sectionTitle(e){return(0,k.uJ)(this.t(e))}chartTypeSection(e,t,i,r){let l=this.section(t.title);l.dataset.sdStyle=e,l.dataset.sdVisibility=t.visibility??"active",r.append(l);let a=i.chartTypes[e]??{},s={},h=e=>{for(let t of e)for(let e of(0,o.JwL)(t)){let t=a[e.key];s[e.key]=typeof t===e.type?t:e.defval}};for(let e of(t.rows&&h(t.rows),t.instances??[]))h(e.rows);for(let e of t.subsections??[])h(e.rows);for(let e of t.instances??[])!e.enableKey||e.enableKey in s||(s[e.enableKey]=!0===a[e.enableKey]);for(let e of t.subsections??[])!e.enableKey||e.enableKey in s||(s[e.enableKey]=!0===a[e.enableKey]);let d=[],c=(t,i)=>{for(let o of(s[t]=i,this.emitType(e,t,i),d))o()},p=`type:${e}`;if(t.instances&&t.instances.length>0){let i=t.instances.map(e=>({...e,rows:ru(e.rows,p,this.hiddenSettings)}));r.append(this.instancesBlock(e,i,s,c,d))}else if(t.rows){let i=ru(t.rows,p,this.hiddenSettings);"grouped"===t.layout?r.append(this.groupedRows(`${e}/rows`,i,s,c,d)):this.flatTypeRows(i,s,c,d,r)}for(let i of t.subsections??[]){if(rc(`${p}.${ra(i.title)}`,this.hiddenSettings))continue;let o=ru(i.rows,p,this.hiddenSettings);if(0===o.length)continue;let l=this.section(i.title);l.dataset.sdStyle=e,l.dataset.sdVisibility=t.visibility??"active",l.dataset.sdSub="1",r.append(l),r.append(this.groupedRows(`${e}/${(0,n.rI)(i.title)}`,o,s,c,d,i.enableKey))}for(let e of d)e()}flatTypeRows(e,t,i,r,l){let n=[];for(let o of e){let e="heading"===o.kind||"header"===o.kind?this.sectionTitle(o.label):this.typeRow(o,t,i,r);n.push({el:e,when:o.when}),l.append(e)}r.push(()=>{for(let e of n)e.el.classList.toggle("vela-sd-hide",!(0,o.QyP)(e.when,t))})}typeRow(e,t,i,r){let l=(0,o.ZNF)(e),n=[];for(let e of l.controls){let a=this.inlineControl(e,t,i,void 0!==l.toggle);if("hint"!==e.kind&&r.push(()=>a.dispatchEvent(new Event("vela-sync"))),"hint"!==e.kind&&e.when){a.dataset.sdSelfGated="1";let i=e.when;r.push(()=>{a.style.display=(0,o.QyP)(i,t)?"":"none"})}n.push(a)}if(l.toggle){let e=l.toggle,o=this.toggleRow(l.label,t[e.key],t=>i(e.key,t),n,()=>!0===t[e.key]);return r.push(()=>o.dispatchEvent(new Event("vela-sync"))),o}return this.rowWith(l.label,n)}inlineControl(e,t,i,o){if("hint"===e.kind){let t=document.createElement("span");return t.textContent=this.t(e.text),t.style.cssText="color:var(--vela-fg-muted);",t}if("color"===e.kind)return(0,k.yF)({kind:"color",theme:this.theme,get:()=>t[e.key],onChange:t=>i(e.key,t),title:this.t(e.label)}).el;if("width"===e.kind){let o="number"==typeof t[e.key]?t[e.key]:e.defval;return(0,k.yF)({kind:"width",theme:this.theme,get:()=>"number"==typeof t[e.key]?t[e.key]:o,onChange:t=>i(e.key,t),title:this.t(e.label)}).el}if("select"===e.kind){let o="string"==typeof t[e.key]?t[e.key]:e.defval;return(0,k.yF)({kind:"select",options:rS(e.options).map(([e,t])=>({value:e,label:this.t(t)})),value:o,fill:!1,theme:this.theme,title:this.t(e.label),onChange:t=>i(e.key,t),sync:()=>"string"==typeof t[e.key]?t[e.key]:e.defval}).el}let r="number"==typeof t[e.key]?t[e.key]:e.defval;return(0,k.yF)({kind:"number",value:r,min:e.min,max:e.max,step:e.step??1,fill:!1,commit:"live",clamp:void 0!==e.placeholder,steppers:!0,compact:o,title:this.t(e.label),placeholder:void 0!==e.placeholder?this.t(e.placeholder):void 0,emptyValue:void 0!==e.placeholder?e.defval:void 0,onChange:t=>i(e.key,t),sync:()=>"number"==typeof t[e.key]?t[e.key]:e.defval}).el}instancesBlock(e,t,i,o,r){let l=document.createElement("div"),n=document.createElement("div");n.className="vela-sd-itabs",(t.length>1||t[0]?.enableKey!==void 0)&&l.append(n);let a=t.map((t,n)=>{let a=this.groupedRows(`${e}/#${n}`,t.rows,i,o,r);return l.append(a),a}),s=e=>!e.enableKey||!0===i[e.enableKey],h=()=>{let i=this.typeActiveInstance.get(e)??0;s(t[i]??t[0])||(i=0),this.typeActiveInstance.set(e,i),n.replaceChildren(),t.forEach((t,r)=>{if(!s(t))return;let l=document.createElement("button");l.type="button",l.className="vela-sd-itab"+(r===i?" on":"");let a=document.createElement("span");if(a.textContent=this.t(t.label),l.append(a),r===i&&t.enableKey){let i=document.createElement("span");i.className="vela-sd-ix",i.textContent="✕",i.title=this.t(rC.remove,{name:t.label}),i.addEventListener("click",i=>{i.stopPropagation(),this.typeActiveInstance.set(e,0),o(t.enableKey,!1)}),l.append(i)}l.addEventListener("click",()=>{this.typeActiveInstance.set(e,r),h()}),n.append(l)});let r=t.findIndex(e=>!s(e));if(r>=0){let i=document.createElement("button");i.type="button",i.className="vela-sd-itab vela-sd-itab-add",i.textContent="+",i.title=this.t(rC.add,{name:t[r].label}),i.addEventListener("click",()=>{this.typeActiveInstance.set(e,r),o(t[r].enableKey,!0)}),n.append(i)}a.forEach((e,t)=>e.classList.toggle("vela-sd-hide",t!==i))};return r.push(h),l}groupedRows(e,t,i,r,l,a){let s=document.createElement("div");s.className="vela-sd-struct";let h=document.createElement("div");h.className="vela-sd-toc";let d=document.createElement("div");d.dataset.sdRowsHost="1",d.style.cssText="flex:1 1 auto;min-width:0;",s.append(h,d);let c=[],p=[],u=[],g=[],m=-1;for(let e of t){if("heading"===e.kind){m=p.length,p.push((0,n.rI)(e.label)),u.push(e.label),g.push(e.when);continue}if("header"===e.kind){c.push({el:this.sectionTitle(e.label),when:e.when,group:m,header:!0}),d.append(c[c.length-1].el);continue}let t=this.typeRow(e,i,r,l),o="row"===e.kind?e.toggle?.key:"range"===e.kind?void 0:e.key;c.push({el:t,when:e.when,group:m,key:o}),d.append(t)}let b=()=>{let t=p.map((e,t)=>(0,o.QyP)(g[t],i)&&c.some(e=>e.group===t&&!e.header&&(0,o.QyP)(e.when,i))),r=p.indexOf(this.typeActiveGroup.get(e)??"");(r<0||!t[r])&&(r=t.findIndex(Boolean)),r>=0&&this.typeActiveGroup.set(e,p[r]),h.replaceChildren(),p.forEach((i,o)=>{if(!t[o])return;let l=document.createElement("button");l.type="button",l.className="vela-sd-toc-btn"+(o===r?" on":""),l.textContent=this.t(u[o]??i),l.addEventListener("click",()=>{this.typeActiveGroup.set(e,i),b()}),h.append(l)});let l=t.some(Boolean);h.classList.toggle("vela-sd-hide",!l),s.classList.toggle("no-toc",!l);let n=!a||!0===i[a];for(let e=0;e<c.length;e++){let t=c[e],l=(-1===t.group||t.group===r)&&(0,o.QyP)(t.when,i);if(l&&t.header){let r=!1;for(let l=e+1;l<c.length;l++){let e=c[l];if(e.group!==t.group||e.header)break;if((0,o.QyP)(e.when,i)){r=!0;break}}l=r}t.el.classList.toggle("vela-sd-hide",!l),t.el.classList.toggle("vela-sd-soft",l&&!n&&t.key!==a)}};return l.push(b),s}separator(){return(0,k.Qs)()}layoutSettingsGrids(e){if(0===e.childElementCount)return;let t=(0,k.lb)({variant:"settings",mobile:this.mobileLayout});for(;e.firstChild;)t.appendChild(e.firstChild);for(let i of(e.appendChild(t),[...t.children]))void 0!==i.dataset.sdGroup&&this.flattenGroup(i,t)}flattenGroup(e,t){for(let i of(e.style.display="contents",[...e.children]))void 0!==i.dataset.sdGroup&&this.flattenGroup(i,t)}swatch(e,t,i){let o=e;return(0,k.yF)({kind:"color",theme:this.theme,get:()=>i?i():o,onChange:e=>{o=e,t(e)}}).el}rowWith(e,t){return(0,k.h0)({label:this.t(e),labelSize:"sm",control:t,className:"vela-sd-row"})}section(e){let t=document.createElement("div");return t.dataset.sdTab=(0,n.rI)(e),t.dataset.sdTabLabel=this.t(e),t.style.display="none",t}group(){let e=document.createElement("div");return e.dataset.sdGroup="",e.style.cssText="display:contents;",e}colorRow(e,t,i){let o=t;return(0,k.h0)({label:this.t(e),labelSize:"sm",fit:!0,className:"vela-sd-row",control:(0,k.yF)({kind:"color",theme:this.theme,get:()=>o,onChange:e=>{o=e,i(e)}}).el})}boolRow(e,t,i,o){return this.toggleRow(e,t,i,[],void 0,o)}toggleRow(e,t,i,o,r,l){return(0,k.h0)({label:this.t(e),labelSize:"sm",bool:0===o.length,toggle:{checked:t,onChange:i,get:r},control:o,info:l,className:0===o.length?"vela-sd-bool":"vela-sd-row"})}hint(e){let{el:t,dispose:i}=eW(this.t(e),{host:this.container,theme:()=>this.theme});return this.hintTips.push(i),t}numberRow(e,t,i,o,r,l,n){let a=n?document.createElement("span"):null,s=e=>{a&&n&&(a.textContent=this.t(n,{count:e}))},h=[(0,k.yF)({kind:"number",value:t,min:i,max:o,step:r,fill:!1,commit:"live",steppers:!0,onChange:e=>{s(e),l(e)}}).el];return a&&(s(t),a.style.cssText="color:var(--vela-fg-muted);",h.push(a)),this.rowWith(e,h)}selectRowLabeled(e,t,i,o,r){let l=r&&r.ids.size>0?{ids:r.ids,title:this.t(r.title)}:null;return(0,k.h0)({label:this.t(e),labelSize:"sm",className:"vela-sd-row",control:(0,k.yF)({kind:"select",options:i.map(([e,t])=>l?.ids.has(e)?{value:e,label:this.t(t),disabled:!0,title:l.title}:{value:e,label:this.t(t)}),value:t,fill:!1,theme:this.theme,onChange:o}).el})}timezoneOptions(e){let t=this.i18n?.()??null,i=o.TAq.map(e=>[e.value,(0,o.W1v)(e.value,(0,n.b6)(t,e.name),t)]),r=(0,o.hry)(e);return o.TAq.some(e=>e.value===r)?i:[[r,(0,o.W1v)(r,r,t)],...i]}};function rS(e){return e.map(e=>"string"==typeof e?[e,e]:e)}function rT(e){return(0,o.V$N)(e)?.barTransform??null}function rM(e){let t=e.lastIndexOf(";");if(t<=0||t===e.length-1)return{symbol:e,modifier:null,transform:null};let i=e.slice(t+1).toLowerCase();return"standard"===i||(0,o.sFz)().includes(i)?{symbol:e.slice(0,t),modifier:i,transform:rT(i)}:{symbol:e,modifier:null,transform:null}}var rL={loading:(0,n.ab)("drawing.magnifier.loading","Loading…"),noData:(0,n.ab)("drawing.magnifier.noData","No lower-timeframe data"),tooWide:(0,n.ab)("drawing.magnifier.tooWide","Area too wide for this timeframe"),noneLower:(0,n.ab)("drawing.magnifier.noneLower","No lower timeframe available"),notLower:(0,n.ab)("drawing.magnifier.notLower","Pick a timeframe lower than the chart's"),noSource:(0,n.ab)("drawing.magnifier.noSource","No data source"),infoLine:(0,n.ab)("drawing.infoline.measure","{change} ({percent}%) {count, plural, one {{bars} bar} other {{bars} bars}}")},rA=o.lx5,rP=(0,p.fu)(r.qm,.55),rI=r.$J,rE=r.EA,rB={selected:.3,hovered:.12},rF=new Map([["bars","bars"],["line","line"],["linemarkers","line"],["stepline","line"],["baseline","line"],["area","area"],["columns","area"]]);function rO(e){let t=new Set(e.selected);return e.dragged&&t.add(e.dragged),e.hovered&&t.add(e.hovered),e.mutedLabel&&t.delete(e.mutedLabel),t}var rR=class{constructor(){this.targets={},this.i18n=(0,n.Db)(),this.seriesLook={style:"candles",upColor:r.cr,downColor:r.TV,lineColor:r.cr}}t(e,t){return(0,n.b6)(this.i18n,e,t)}priceTag(e){return this.i18n.format.price(e,{decimals:oN(e),grouping:!0,surface:"drawing"})}num(e){return(0,n.EJ)(e,this.i18n)}paintAll(e,t,i,o,r={}){for(let l of(this.targets=r,t))l.visible&&this.paintClipped(e,l,i,()=>this.paintOne(e,l,i,o));this.targets={},this.paintHighlights(e,t,i,rO(r))}paintHighlights(e,t,i,o){if(0!==o.size)for(let r of t)r.visible&&o.has(r.id)&&this.paintClipped(e,r,i,()=>this.paintHandles(e,r.handlePoints(i)))}paintClipped(e,t,i,o){if(!i.paneRect)return void o();let r=i.paneRect(t.paneId);r&&!(r.height<=0)&&(e.save(),e.beginPath(),e.rect(0,r.top,i.width,r.height),e.clip(),o(),e.restore())}paintGhost(e,t,i,r){e.globalAlpha=.7,t instanceof o.Twx||t instanceof o.npk?this.paintTimeSpanGhost(e,t,i):t instanceof o.NvN?this.paintMagnifierGhost(e,t,i,r):this.paintOne(e,t,i,r),e.globalAlpha=1}paintTimeSpanGhost(e,t,i){let l=t.anchors[0],n=t.anchors[1];if(!l)return;let a=t instanceof o.Twx&&t.reg?.midColor||r.qm,s=t=>{let o=i.xOf(t);e.save(),e.strokeStyle=a,e.globalAlpha=.6*e.globalAlpha,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o,0),e.lineTo(o,i.height),e.stroke(),e.restore()};s(l.time),n&&s(n.time);let h=i.yOf(l.price,t.paneId),d=n?i.yOf(n.price,t.paneId):null,c=[];null!=h&&c.push([i.xOf(l.time),h]),n&&null!=d&&(e.save(),e.strokeStyle=a,e.lineWidth=1,e.setLineDash([]),e.beginPath(),e.moveTo(i.xOf(l.time),h??d),e.lineTo(i.xOf(n.time),d),e.stroke(),e.restore(),c.push([i.xOf(n.time),d])),this.paintHandles(e,c)}paintMarquee(e,t){e.save(),e.fillStyle=(0,p.fu)(rA,.08),e.fillRect(t.x,t.y,t.w,t.h),e.strokeStyle=rA,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(t.x+.5,t.y+.5,t.w,t.h),e.restore()}paintSnapRing(e,t,i,o){e.setLineDash([]),e.globalAlpha=.9,e.beginPath(),e.arc(t,i,5.5,0,2*Math.PI),e.strokeStyle=o.textColor,e.lineWidth=1.5,e.stroke(),e.globalAlpha=1}paintOne(e,t,i,r){if("highlighter"===t.type&&t instanceof o.eot){this.paintHighlighter(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.eot){if(this.paintSegments(e,t,i),"path"===t.type){let o=t.handlePoints(i);o.length>=2&&this.paintArrowhead(e,o[o.length-2],o[o.length-1],t.style)}this.paintLabel(e,t,i,r);return}if(t instanceof o.vi5){this.paintArrowMark(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.wjm){this.paintGlyphStamp(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.lL$){this.paintRadialFib(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.XM0){this.paintFibSpiral(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o._$h){this.paintDedekind(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.sLj){this.paintMachFigure(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.QOr){this.paintFibRatios(e,t,i,r),this.paintGannArcs(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.aTP){this.paintFibRatios(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.CUD)return void this.paintMeasureBox(e,t,i,r);if(t instanceof o.m4Q)return void this.paintPosition(e,t,i,r);if(t instanceof o.Twx){this.paintRegressionChannel(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.Zb0){this.paintAnchoredVwap(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.npk){this.paintFixedRangeVp(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.NvN)return void this.paintMagnifier(e,t,i,r);if(t instanceof o.oQW){this.paintPriceZone(e,t,i,r),this.paintLabel(e,t,i,r);return}if(t instanceof o.rCp){this.paintLiquidity(e,t,i),this.paintLabel(e,t,i,r);return}if(t instanceof o.btd)return void this.paintPattern(e,t,i,r);if(t instanceof o.MwB)return void this.paintComment(e,t,i,r);if(t instanceof o.IyY)return void this.paintPriceNote(e,t,i,r);if(t instanceof o.OBn)return void this.paintSignpost(e,t,i,r);if(t instanceof o.PqE)return void this.paintCallout(e,t,i,r);if(t instanceof o.L7S)return void this.paintNote(e,t,i,r);if(t instanceof o.MNw)return void this.paintPriceLabel(e,t,i,r);switch(t.type){case"hline":{let o=t.handlePoints(i);if(0===o.length)return;this.stroke(e,t.style,()=>{e.moveTo(0,o[0][1]),e.lineTo(i.width,o[0][1])});break}case"trendline":case"arrow":{let r=t.handlePoints(i);if(r.length<2)return;let l=t instanceof o.O5K?t.extension():"none",[n,a,s,h]=ok(r[0][0],r[0][1],r[1][0],r[1][1],l,i.width,i.height);this.stroke(e,t.style,()=>{e.moveTo(n,a),e.lineTo(s,h)}),t.style.arrowRight&&this.paintArrowhead(e,r[0],r[1],t.style),t.style.arrowLeft&&this.paintArrowhead(e,r[1],r[0],t.style);break}case"ellipse":{let o=t.handlePoints(i);if(o.length<2)return;let r=(o[0][0]+o[1][0])/2,l=(o[0][1]+o[1][1])/2,n=Math.abs(o[1][0]-o[0][0])/2,a=Math.abs(o[1][1]-o[0][1])/2;t.style.fillColor&&(e.save(),e.fillStyle=t.style.fillColor,e.beginPath(),e.ellipse(r,l,n,a,0,0,2*Math.PI),e.fill(),e.restore()),this.applyStroke(e,t.style),e.beginPath(),e.ellipse(r,l,n,a,0,0,2*Math.PI),e.stroke(),e.setLineDash([]);break}case"ray":{let o=t.handlePoints(i);if(o.length<2)return;let[r,l,n,a]=ok(o[0][0],o[0][1],o[1][0],o[1][1],"right",i.width,i.height);this.stroke(e,t.style,()=>{e.moveTo(r,l),e.lineTo(n,a)});break}case"extendedline":{let o=t.handlePoints(i);if(o.length<2)return;let[r,l,n,a]=ok(o[0][0],o[0][1],o[1][0],o[1][1],"both",i.width,i.height);this.stroke(e,t.style,()=>{e.moveTo(r,l),e.lineTo(n,a)});break}case"vline":{let o=t.handlePoints(i);if(0===o.length)return;this.stroke(e,t.style,()=>{e.moveTo(o[0][0],0),e.lineTo(o[0][0],i.height)});break}case"hray":{let o=t.handlePoints(i);if(0===o.length)return;this.stroke(e,t.style,()=>{e.moveTo(o[0][0],o[0][1]),e.lineTo(i.width,o[0][1])});break}case"crossline":{let o=t.handlePoints(i);if(0===o.length)return;this.stroke(e,t.style,()=>{e.moveTo(0,o[0][1]),e.lineTo(i.width,o[0][1]),e.moveTo(o[0][0],0),e.lineTo(o[0][0],i.height)});break}case"infoline":this.paintInfoLine(e,t,i);break;case"trendangle":this.paintTrendAngle(e,t,i,r);break;case"circle":{let o=t.handlePoints(i);if(o.length<2)return;let r=o[0][0],l=o[0][1],n=Math.hypot(o[1][0]-r,o[1][1]-l);if(n<1)return;t.style.fillColor&&(e.save(),e.fillStyle=t.style.fillColor,e.beginPath(),e.arc(r,l,n,0,2*Math.PI),e.fill(),e.restore()),this.applyStroke(e,t.style),e.beginPath(),e.arc(r,l,n,0,2*Math.PI),e.stroke(),e.setLineDash([]);break}case"box":{let l=t.handlePoints(i);if(l.length<2)return;let n=Math.min(l[0][0],l[1][0]),a=Math.min(l[0][1],l[1][1]),s=Math.abs(l[1][0]-l[0][0]),h=Math.abs(l[1][1]-l[0][1]);t.style.fillColor&&(e.save(),e.fillStyle=t.style.fillColor,e.fillRect(n,a,s,h),e.restore());let d=t instanceof o.azJ?t.midline(i):null;if(d){let o=this.boxLabelGap(e,t,i,r,d.y);this.stroke(e,{lineColor:d.color,lineWidth:t.style.lineWidth,lineStyle:d.lineStyle},()=>{for(let[t,i]of function(e,t,i){if(!i||i[1]<=e||i[0]>=t)return[[e,t]];let o=[];return i[0]>e&&o.push([e,i[0]]),i[1]<t&&o.push([i[1],t]),o}(d.x1,d.x2,o))e.moveTo(t,d.y),e.lineTo(i,d.y)})}this.applyStroke(e,t.style),e.strokeRect(n,a,s,h),e.setLineDash([])}}this.paintLabel(e,t,i,r)}boxLabelGap(e,t,i,o,r){let l=t.text;if(!l||!l.value)return null;let n=r$(t,i);if(!n)return null;let a=oM(l.size),s=l.value.split("\n");if(r<n.top||r>n.top+oT(a)*s.length)return null;e.save(),e.font=`${l.bold?"bold ":""}${l.italic?"italic ":""}${a}px ${o.fontFamily}`;let h=Math.max(...s.map(t=>e.measureText(t).width));e.restore();let d=h/2+rD;return[n.x-d,n.x+d]}paintLabel(e,t,i,o){let r=t.text;if(!r||!r.value||t.id===this.targets.mutedLabel)return;let l=r$(t,i);if(!l)return;let n=oM(r.size);e.save(),l.rotate&&(e.translate(l.rotate.cx,l.rotate.cy),e.rotate(l.rotate.angle)),e.font=`${r.bold?"bold ":""}${r.italic?"italic ":""}${n}px ${o.fontFamily}`,e.textBaseline="top",e.textAlign=l.align;let a=oT(n),s=r.value.split("\n");"text"!==t.type&&"box"!==t.type&&(e.lineJoin="round",e.lineWidth=3,e.strokeStyle=o.background,s.forEach((t,i)=>e.strokeText(t,l.x,l.top+i*a))),e.fillStyle=r.color??o.textColor,s.forEach((t,i)=>e.fillText(t,l.x,l.top+i*a)),"text"===t.type&&this.paintTextFrame(e,t.id,l.x,l.top,s,n,o),e.restore()}paintTextFrame(e,t,i,o,r,l,n){let a=this.targets,s=a.selected?.has(t)?rB.selected:a.hovered===t?rB.hovered:0;if(0===s)return;let h=oT(l),d=Math.max(8,...r.map(t=>e.measureText(t).width));e.save(),e.setLineDash([]),e.lineWidth=1,e.strokeStyle=(0,p.fu)(n.textColor,s),rz(e,i-5,o-(h-l)/2-3,d+10,r.length*h+6,4),e.stroke(),e.restore()}paintFibRatios(e,t,i,o){let r=t.entryLines(i);if(!r||0===r.length)return;for(let o of t.fillBands(i))e.save(),e.globalAlpha=.06*e.globalAlpha,e.fillStyle=o.color,e.fillRect(o.x,o.y,o.w,o.h),e.restore();e.textBaseline="middle";let l=`${oM(t.numbersSize)}px ${o.fontFamily}`,n=`${oM(t.labelsSize)}px ${o.fontFamily}`;for(let i of r)this.stroke(e,{...t.style,lineColor:i.color},()=>{e.moveTo(i.x1,i.y1),e.lineTo(i.x2,i.y2)}),e.fillStyle=i.color,e.font=l,e.textAlign=i.numberAlign,e.fillText(this.num(i.numberText),i.numberX,i.numberY),i.label&&(e.font=n,e.textAlign="center",e.fillText(i.label,i.labelX,i.labelY));e.textAlign="left",e.textBaseline="alphabetic"}paintPriceZone(e,t,i,o){let r=t.zone(i);if(!r){let r=t.anchors[0];if(!r)return;let l=Math.round(i.xOf(r.time))+.5;this.stroke(e,{lineColor:(0,p.fu)(o.textColor,.35),lineWidth:1,lineStyle:"dashed"},()=>{e.moveTo(l,0),e.lineTo(l,i.height)});return}let l=r.yBottom-r.yTop,n=(0,p.hS)(r.fill,r.fill);if(e.save(),e.globalAlpha*=r.faded?.6:1,e.fillStyle=r.fill,e.fillRect(r.x1,r.yTop,r.x2-r.x1,l),r.border&&(e.lineWidth=1,e.setLineDash([]),e.strokeStyle=n,e.strokeRect(Math.round(r.x1)+.5,Math.round(r.yTop)+.5,Math.round(r.x2-r.x1),Math.round(l))),null!=r.midY){let t=Math.round(r.midY)+.5;this.stroke(e,{lineColor:n,lineWidth:1,lineStyle:"dashed"},()=>{e.moveTo(r.x1,t),e.lineTo(r.x2,t)})}if(e.restore(),r.flip){let t=r.flip;e.save(),e.fillStyle=t.fill,e.fillRect(t.x1,r.yTop,t.x2-t.x1,l),e.lineWidth=1,e.strokeStyle=(0,p.hS)(t.fill,t.fill),e.setLineDash([5,4]),e.strokeRect(Math.round(t.x1)+.5,Math.round(r.yTop)+.5,Math.round(t.x2-t.x1),Math.round(l)),e.restore()}r.marker&&(e.beginPath(),e.arc(r.marker.x,r.marker.y,3.5,0,2*Math.PI),e.fillStyle=n,e.fill())}paintLiquidity(e,t,i){let o=t.line(i);if(!o)return;let r=Math.round(o.y)+.5;if(this.stroke(e,t.style,()=>{e.moveTo(o.x1,r),e.lineTo(o.x2,r)}),o.sweep){let{x:i,y:r}=o.sweep;this.stroke(e,{lineColor:t.style.lineColor,lineWidth:1.75,lineStyle:"solid"},()=>{e.moveTo(i-4,r-4),e.lineTo(i+4,r+4),e.moveTo(i+4,r-4),e.lineTo(i-4,r+4)})}}paintRadialFib(e,t,i,o){let r=t.radial(i);if(r&&r.R0>=1){let i=`${oM(t.numbersSize)}px ${o.fontFamily}`,l=(r.a0+r.a1)/2;for(let o of(e.textBaseline="middle",t.levels)){if(!o.enabled)continue;let n=r.R0*o.ratio;n<.5||(this.applyStroke(e,{...t.style,lineColor:o.color}),e.beginPath(),e.arc(r.cx,r.cy,n,r.a0,r.a1),e.stroke(),e.setLineDash([]),e.fillStyle=o.color,e.font=i,e.textAlign="left",e.fillText(String(o.ratio),r.cx+Math.cos(l)*n+3,r.cy+Math.sin(l)*n))}e.textBaseline="alphabetic",e.textAlign="left"}for(let o of t.boundingLines(i))this.stroke(e,t.style,()=>{e.moveTo(o[0],o[1]),e.lineTo(o[2],o[3])})}paintGannArcs(e,t,i){let r=t.arcGeom(i);if(!(!r||1>Math.abs(r.bx)||1>Math.abs(r.py))){for(let i of o.VBq){this.applyStroke(e,{...t.style,lineColor:i.color}),e.beginPath();for(let t=0;t<=24;t+=1){let o=t/24*(Math.PI/2),l=r.ox+i.k*r.bx*Math.cos(o),n=r.oy+i.k*r.py*Math.sin(o);0===t?e.moveTo(l,n):e.lineTo(l,n)}e.stroke()}e.setLineDash([])}}paintFibSpiral(e,t,i){let o=t.spiralPoints(i);o&&!(o.length<2)&&this.stroke(e,t.style,()=>{e.moveTo(o[0][0],o[0][1]);for(let t=1;t<o.length;t+=1)e.lineTo(o[t][0],o[t][1])})}paintMachFigure(e,t,i,o){let r=t.geom(i);if(r){for(let i of r.circles)this.applyStroke(e,{...t.style,lineColor:i.color}),e.beginPath(),e.arc(i.cx,i.cy,i.r,0,2*Math.PI),e.stroke();for(let i of(this.applyStroke(e,t.style),e.lineWidth=t.style.lineWidth+.5,r.rays))e.beginPath(),e.moveTo(i[0],i[1]),e.lineTo(i[2],i[3]),e.stroke();if(e.beginPath(),e.arc(r.noseX,r.noseY,Math.max(2.5,t.style.lineWidth+1.5),0,2*Math.PI),e.fillStyle=t.style.lineColor,e.fill(),e.setLineDash([]),!1!==t.showRatios){for(let t of(e.font=`${oM("small")}px ${o.fontFamily}`,e.textBaseline="middle",e.textAlign="left",r.circles)){let i=t.cx+r.fx*t.r+4,o=t.cy+r.fy*t.r;e.fillStyle=t.color,e.fillText(function(e){if(!Number.isFinite(e))return"";let t=Math.round(1e3*e)/1e3;return Number.isInteger(t),String(t)}(t.ratio),i,o)}e.textBaseline="alphabetic",e.textAlign="left"}}}paintDedekind(e,t,i){let o=t.box(i),r=t.geodesics(i);if(!o||!r)return;let{left:l,right:n,top:a,bot:s}=o;for(let i of(e.save(),this.applyStroke(e,t.style),e.globalAlpha*=.45,e.strokeRect(l,a,n-l,s-a),e.restore(),e.save(),e.beginPath(),e.rect(l,a,n-l,s-a),e.clip(),this.applyStroke(e,t.style),r))e.beginPath(),"vline"===i.kind?(e.moveTo(i.x,i.y0),e.lineTo(i.x,i.y1)):e.arc(i.cx,i.cy,i.r,Math.PI,0,!1),e.stroke();e.setLineDash([]),e.restore()}paintMeasureBox(e,t,i,o){let l=t.handlePoints(i);if(l.length<2)return;let n=Math.min(l[0][0],l[1][0]),a=Math.min(l[0][1],l[1][1]),s=Math.abs(l[1][0]-l[0][0]),h=Math.abs(l[1][1]-l[0][1]),d=t.isUp()?r.cr:r.TV;e.save(),e.globalAlpha=.12*e.globalAlpha,e.fillStyle=d,e.fillRect(n,a,s,h),e.restore(),e.setLineDash(ox(t.style.lineStyle,t.style.lineWidth)),e.strokeStyle=d,e.lineWidth=t.style.lineWidth,e.strokeRect(n,a,s,h),e.setLineDash([]);let c=t.measureLabel(i,this.i18n),p=oM(t.text?.size??"normal");e.fillStyle=t.text?.color??o.textColor,e.font=`${p}px ${o.fontFamily}`,e.textAlign="center",e.textBaseline="middle";let u=Math.round(1.35*p),g=a+h/2-(c.length-1)*u/2;c.forEach((t,i)=>e.fillText(t,n+s/2,g+i*u)),e.textAlign="left",e.textBaseline="alphabetic"}paintPosition(e,t,i,o){let r=t.layout(i);if(!r)return;let{x1:l,x2:n,ey:a,sy:s,ty:h}=r,d=n-l,c=(t,i,o)=>{e.save(),e.globalAlpha=.13*e.globalAlpha,e.fillStyle=o,e.fillRect(l,Math.min(t,i),d,Math.abs(i-t)),e.restore()};c(a,h,t.profitColor),c(a,s,t.lossColor);let p=(i,o)=>this.stroke(e,{...t.style,lineColor:o},()=>{e.moveTo(l,i),e.lineTo(n,i)});if(p(h,t.profitColor),p(s,t.lossColor),p(a,t.style.lineColor),!t.showText)return;let u=oM(t.text?.size??"normal");e.fillStyle=t.text?.color??o.textColor,e.textAlign="center",e.textBaseline="middle",e.font=`${u}px ${o.fontFamily}`;let g=l+d/2,m=Math.min(a,s,h)-9;t.showHeader&&e.fillText(t.headerLabel(this.i18n),g,t.showLossSize?m-Math.round(1.15*u):m),e.font=`${Math.max(10,u-1)}px ${o.fontFamily}`,t.showLossSize&&e.fillText(t.lossSizeLabel(this.i18n),g,m),t.showTargetLabel&&e.fillText(t.targetLabel(this.i18n),g,(a+h)/2),t.showStopLabel&&e.fillText(t.stopLabel(this.i18n),g,(a+s)/2),e.textAlign="left",e.textBaseline="alphabetic"}paintRegressionChannel(e,t,i,o){let r=t.layout(i);if(!r)return;let l=t.reg,n=(t,i,o,l,n)=>{e.save(),e.fillStyle=t,e.beginPath(),e.moveTo(r.x0,i),e.lineTo(r.x1,o),e.lineTo(r.x1,n),e.lineTo(r.x0,l),e.closePath(),e.fill(),e.restore()};n(l.upperFill,r.midY0,r.midY1,r.upperY0,r.upperY1),n(l.lowerFill,r.midY0,r.midY1,r.lowerY0,r.lowerY1);let a=(i,o,l,n)=>this.stroke(e,{lineColor:i,lineWidth:t.style.lineWidth,lineStyle:o},()=>{e.moveTo(r.x0,l),e.lineTo(r.x1,n)});if(a(l.upperColor,l.upperStyle,r.upperY0,r.upperY1),a(l.lowerColor,l.lowerStyle,r.lowerY0,r.lowerY1),a(l.midColor,l.midStyle,r.midY0,r.midY1),r.showR2){let t=`R\xb2 ${Math.round(100*r.r2)}%`;e.font=`11px ${o.fontFamily}`;let i=e.measureText(t).width+10,l=r.x0-4-i,n=r.midY0-9;e.save(),e.globalAlpha=.9*e.globalAlpha,rz(e,l,n-8,i,16,3),e.fillStyle=rI,e.fill(),e.restore(),e.fillStyle=o.textColor,e.textAlign="left",e.textBaseline="middle",e.fillText(t,l+5,n),e.textBaseline="alphabetic"}}paintMagnifierGhost(e,t,i,o){let r=t.rect(i);r&&(e.save(),e.strokeStyle=t.style.lineColor||oS(o.background),e.lineWidth=1,e.setLineDash([4,4]),e.strokeRect(Math.min(r.x1,r.x2),Math.min(r.y1,r.y2),Math.abs(r.x2-r.x1),Math.abs(r.y2-r.y1)),e.restore())}paintMagnifier(e,t,i,r){let l=t.rect(i),n=t.anchors[0],a=t.anchors[1];if(!l||!n||!a)return;let s=Math.min(l.x1,l.x2),h=Math.max(l.x1,l.x2),d=Math.min(l.y1,l.y2),c=Math.max(l.y1,l.y2),u=h-s,g=c-d;e.save(),e.globalAlpha=1,e.fillStyle=r.background,e.fillRect(s,d,u,g),e.restore();let m=Math.min(n.time,a.time),b=Math.max(n.time,a.time),f=i.barsBetween?i.barsBetween(m,b):0,v=f>0?(b-m)/f:0,y=i.seriesInRange&&v>0&&u>1&&g>1?i.seriesInRange(t.magnifier.timeframe,m,b+v):void 0,w=y?.state==="ready"||y?.state==="loading"?y.bars??[]:[];if(y&&("ready"===y.state||"loading"===y.state)&&w.length>0){let o=this.seriesLook,r="candles"!==o.style?rT(o.style):null;r&&(w=r.full(w));let l=rF.get(o.style)??"candles",n=(i.xOf(m+v)-i.xOf(m))/2;e.save(),e.beginPath(),e.rect(s,d,u,g),e.clip(),"line"===l||"area"===l?this.paintMagnifierLine(e,t,i,w,y.barMs,n,c,"area"===l,t.magnifier.upColor||o.lineColor):this.paintMagnifierBars(e,t,i,w,y.barMs,n,s,h,l,t.magnifier.upColor||o.upColor,t.magnifier.downColor||o.downColor),e.restore()}else if(y){let t="loading"===y.state?rL.loading:"ready"===y.state?rL.noData:"too-wide"===y.reason?rL.tooWide:"none-lower"===y.reason?rL.noneLower:"not-lower"===y.reason?rL.notLower:rL.noSource;this.paintMagnifierNotice(e,this.t(t),s,d,u,g,r)}if(e.save(),e.strokeStyle=t.style.lineColor||oS(r.background),e.lineWidth=t.style.lineWidth||1,e.setLineDash(ox(t.style.lineStyle,t.style.lineWidth||1)),e.strokeRect(s,d,u,g),e.restore(),u>44){let l=this.t((0,o.HkK)(y?.state==="ready"||y?.state==="loading"?y.timeframe:t.magnifier.timeframe)),n=i.paneRect?.(t.paneId),a=c+4+17<=(n?n.top+n.height:i.height)?c+4:c-4-17;e.save(),e.font=`10px ${r.fontFamily}`;let h=e.measureText(l).width,d=h+12+11;rz(e,s,a,d,17,3),e.fillStyle=r.background,e.fill(),e.strokeStyle=(0,p.fu)(r.textColor,.28),e.lineWidth=1,e.setLineDash([]),e.stroke(),e.fillStyle=r.textColor,e.textAlign="left",e.textBaseline="middle",e.fillText(l,s+6,a+8.5+.5);let u=s+6+h+5,g=a+8.5;e.strokeStyle=(0,p.fu)(r.textColor,.7),e.lineWidth=1.2,e.beginPath(),e.moveTo(u,g-1.5),e.lineTo(u+2.5,g+1.5),e.lineTo(u+5,g-1.5),e.stroke(),e.restore(),t.chipRect={x:s,y:a,w:d,h:17}}else t.chipRect=null}paintMagnifierBars(e,t,i,o,r,l,n,a,s,h,d){for(let c of(e.setLineDash([]),e.lineWidth=1,o)){let o=i.xOf(c.time)-l,p=i.xOf(c.time+r)-l;if(p<n||o>a)continue;let u=i.yOf(c.high,t.paneId),g=i.yOf(c.low,t.paneId),m=i.yOf(c.open,t.paneId),b=i.yOf(c.close,t.paneId);if(null==u||null==g||null==m||null==b)continue;let f=c.close>=c.open?h:d,v=p-o,y=(o+p)/2;if(e.strokeStyle=f,e.beginPath(),e.moveTo(y,u),e.lineTo(y,g),e.stroke(),!(v<3))if("bars"===s){let t=Math.max(1,.35*v);e.beginPath(),e.moveTo(y-t,m),e.lineTo(y,m),e.moveTo(y,b),e.lineTo(y+t,b),e.stroke()}else{let t=Math.max(1,.7*v);e.fillStyle=f,e.fillRect(y-t/2,Math.min(m,b),t,Math.max(1,Math.abs(b-m)))}}}paintMagnifierLine(e,t,i,o,r,l,n,a,s){let h=[];for(let e of o){let o=i.yOf(e.close,t.paneId);null!=o&&h.push([i.xOf(e.time+r/2)-l,o])}if(!(h.length<2)){if(a){for(let[t,i]of(e.beginPath(),e.moveTo(h[0][0],n),h))e.lineTo(t,i);e.lineTo(h[h.length-1][0],n),e.closePath(),e.fillStyle=(0,p.fu)(s,.15),e.fill()}e.setLineDash([]),e.lineWidth=1.5,e.strokeStyle=s,e.beginPath(),e.moveTo(h[0][0],h[0][1]);for(let t=1;t<h.length;t+=1)e.lineTo(h[t][0],h[t][1]);e.stroke()}}paintMagnifierNotice(e,t,i,o,r,l,n){r<60||l<20||(e.save(),e.beginPath(),e.rect(i,o,r,l),e.clip(),e.font=`11px ${n.fontFamily}`,e.fillStyle=(0,p.fu)(n.textColor,.55),e.textAlign="center",e.textBaseline="middle",e.fillText(t,i+r/2,o+l/2),e.restore())}paintPlacementHint(e,t,i,o,r){e.save(),e.font=`11px ${i.fontFamily}`;let l=e.measureText(t).width+24,n=r-24-14;rz(e,(o-l)/2,n,l,24,12),e.fillStyle=i.background,e.fill(),e.strokeStyle=(0,p.fu)(i.textColor,.28),e.lineWidth=1,e.setLineDash([]),e.stroke(),e.fillStyle=i.textColor,e.textAlign="center",e.textBaseline="middle",e.fillText(t,o/2,n+12+.5),e.restore()}paintFixedRangeVp(e,t,i,o){let r=t.layout(i);if(!r)return;let l=t.frvp,{profile:n,maxW:a,anchorX:s,grow:h,yEdges:d}=r;if(n.maxTotal<=0||a<=0)return;for(let t=0;t<n.rows.length;t+=1){let i=n.rows[t],o=i.up+i.down;if(o<=0)continue;let r=d[t],c=d[t+1],p=Math.min(r,c),u=Math.max(1,Math.abs(c-r)-1),g=o/n.maxTotal*a,m=i.up/o*g,b=t>=n.vaFrom&&t<=n.vaTo,f=b?l.vaUpColor:l.upColor,v=b?l.vaDownColor:l.downColor,y=1===h?s:s-g;m>0&&(e.fillStyle=f,e.fillRect(y,p,m,u)),g-m>0&&(e.fillStyle=v,e.fillRect(y+m,p,g-m,u))}let c=t.style.lineWidth,p=(t,i,o,l)=>{!t||null==l||rN(i)||this.stroke(e,{lineColor:i,lineWidth:c,lineStyle:o},()=>{e.moveTo(r.x0,l),e.lineTo(r.x1,l)})};p(l.showVah,l.vahColor,l.vahStyle,r.vahY),p(l.showVal,l.valColor,l.valStyle,r.valY),p(l.showPoc,l.pocColor??oS(o.background),l.pocStyle,r.pocY);let u=Math.max(1,c);if(l.showDevelopingPoc&&this.strokePolyline(e,r.developingPoc,{lineColor:l.developingPocColor,lineWidth:u,lineStyle:l.developingPocStyle}),l.showDevelopingVa){let t={lineColor:l.developingVaColor,lineWidth:u,lineStyle:l.developingVaStyle};this.strokePolyline(e,r.developingVaHigh,t),this.strokePolyline(e,r.developingVaLow,t)}}paintAnchoredVwap(e,t,i){let o=t.layout(i);if(!o)return;let r=t.vwap,l=t.style.lineWidth;if(o.upper.length>=2&&r.bandFill){e.save(),e.fillStyle=r.bandFill,e.beginPath(),e.moveTo(o.upper[0][0],o.upper[0][1]);for(let t=1;t<o.upper.length;t+=1)e.lineTo(o.upper[t][0],o.upper[t][1]);for(let t=o.lower.length-1;t>=0;t-=1)e.lineTo(o.lower[t][0],o.lower[t][1]);e.closePath(),e.fill(),e.restore()}this.strokePolyline(e,o.upper,{lineColor:r.upperColor,lineWidth:l,lineStyle:r.upperStyle}),this.strokePolyline(e,o.lower,{lineColor:r.lowerColor,lineWidth:l,lineStyle:r.lowerStyle}),this.strokePolyline(e,o.mid,{lineColor:r.midColor,lineWidth:l,lineStyle:r.midStyle})}strokePolyline(e,t,i){t.length<2||rN(i.lineColor)||this.stroke(e,i,()=>{e.moveTo(t[0][0],t[0][1]);for(let i=1;i<t.length;i+=1)e.lineTo(t[i][0],t[i][1])})}paintCallout(e,t,i,o){this.paintBubble(e,t,i,o,5)}paintComment(e,t,i,o){this.paintBubble(e,t,i,o,999)}paintBubble(e,t,i,o,r){let l=t.points(i);if(!l)return;let n=l[0][0],a=l[0][1],s=l[1][0],h=l[1][1],d=t.text,c=oM(d?.size??"normal");e.font=`${d?.bold?"bold ":""}${d?.italic?"italic ":""}${c}px ${o.fontFamily}`;let p=(d?.value??"").split("\n"),u=Math.max(8,...p.map(t=>e.measureText(t).width)),g=oT(c),m=u+18,b=p.length*g+12,f=s-m/2,v=h-b/2,y=m/2,w=b/2,C=n-s,x=a-h,k=Math.min(r,m/2,b/2),S=null;if(Math.abs(C)>y||Math.abs(x)>w){let e=Math.max(6,.18*Math.min(m,b));if(Math.abs(C)/y>=Math.abs(x)/w){let t=Math.max(v+k+e,Math.min(v+b-k-e,h+x*((C>0?f+m:f)-s)/(C||1)));S={edge:C>0?"right":"left",at:t,apex:[n,a],half:e}}else{let t=Math.max(f+k+e,Math.min(f+m-k-e,s+C*((x>0?v+b:v)-h)/(x||1)));S={edge:x>0?"bottom":"top",at:t,apex:[n,a],half:e}}}e.save(),e.fillStyle=ez(t,o)??o.background,rV(e,f,v,m,b,k,S),e.fill(),e.restore(),this.applyStroke(e,t.style),rV(e,f,v,m,b,k,S),e.stroke(),e.setLineDash([]),e.fillStyle=d?.color??oS(ez(t,o)??o.background),e.textBaseline="top",e.textAlign="left",p.forEach((t,i)=>e.fillText(t,f+9,v+6+i*g))}paintTextPlate(e,t,i,o,r,l,n,a,s,h,d){e.save(),e.fillStyle=ez(t,i)??i.background,rz(e,o,r,l,n,5),e.fill(),e.restore(),this.applyStroke(e,t.style),rz(e,o,r,l,n,5),e.stroke(),e.setLineDash([]),e.fillStyle=t.text?.color??oS(ez(t,i)??i.background),e.textBaseline="top",e.textAlign="left",a.forEach((t,i)=>e.fillText(t,o+h,r+d+i*s))}measureText(e,t,i,o){let r=t.text,l=oM(r?.size??"normal");e.font=`${r?.bold?"bold ":""}${r?.italic?"italic ":""}${l}px ${i.fontFamily}`;let n=(r?.value||o).split("\n"),a=Math.max(8,...n.map(t=>e.measureText(t).width));return{lines:n,tw:a,fs:l,lh:oT(l)}}paintNote(e,t,i,o){let r=t.handlePoints(i);if(!r.length)return;let[l,n]=r[0],{lines:a,tw:s,lh:h}=this.measureText(e,t,o,this.t(t.placeholderText()??""));this.paintTextPlate(e,t,o,l,n,s+16,a.length*h+10,a,h,8,5)}paintPriceNote(e,t,i,o){let r=t.points(i),l=t.anchors[0];if(!r||!l)return;let[n,a]=r[0],[s,h]=r[1],d=this.priceTag(l.price),c=t.text,p=oM(c?.size??"normal");e.font=`${c?.bold?"bold ":""}${c?.italic?"italic ":""}${p}px ${o.fontFamily}`;let u=e.measureText(d).width+18,g=oT(p)+12,m=s-u/2,b=h-g/2;this.stroke(e,t.style,()=>{e.moveTo(n,a),e.lineTo(s,h)}),e.fillStyle=t.style.lineColor,e.beginPath(),e.arc(n,a,3,0,2*Math.PI),e.fill(),e.save(),e.fillStyle=ez(t,o)??o.background,rz(e,m,b,u,g,5),e.fill(),e.restore(),this.applyStroke(e,t.style),rz(e,m,b,u,g,5),e.stroke(),e.setLineDash([]),e.fillStyle=c?.color??oS(ez(t,o)??o.background),e.textBaseline="middle",e.textAlign="center",e.fillText(d,s,h+.5)}paintSignpost(e,t,i,o){let r=t.points(i);if(!r)return;let[l,n]=r[0],[a,s]=r[1],{lines:h,tw:d,lh:c}=this.measureText(e,t,o,this.t(t.placeholderText()??"")),p=d+18,u=h.length*c+12;this.stroke(e,t.style,()=>{e.moveTo(l,n),e.lineTo(a,s)}),e.fillStyle=t.style.lineColor,e.beginPath(),e.arc(l,n,3.5,0,2*Math.PI),e.fill(),this.paintTextPlate(e,t,o,a-p/2,s-u/2,p,u,h,c,9,6)}paintPriceLabel(e,t,i,o){let r=t.handlePoints(i),l=t.anchors[0];if(!r.length||!l)return;let[n,a]=r[0],s=this.priceTag(l.price),h=t.text,d=oM(h?.size??"normal");e.font=`${h?.bold?"bold ":""}${h?.italic?"italic ":""}${d}px ${o.fontFamily}`;let c=e.measureText(s).width+16,p=oT(d)+8,u=a-p/2,g=ez(t,o)??o.background;e.save(),e.fillStyle=g,e.beginPath(),e.moveTo(n,a),e.lineTo(n+6,a-5),e.lineTo(n+6,a+5),e.closePath(),e.fill(),rz(e,n+6,u,c,p,4),e.fill(),e.restore(),this.applyStroke(e,t.style),rz(e,n+6,u,c,p,4),e.stroke(),e.setLineDash([]),e.fillStyle=h?.color??oS(g),e.textBaseline="middle",e.textAlign="left",e.fillText(s,n+6+8,a+.5)}paintPattern(e,t,i,r){let l=t.handlePoints(i);if(l.length<2)return;let n=t.valid(),a=ez(t,r)??t.style.lineColor,s=t.style.fillColor?1:.1;for(let[i,o,r]of t.fillTriangles()){let t=l[i],n=l[o],h=l[r];t&&n&&h&&(e.save(),e.globalAlpha=s*e.globalAlpha,e.fillStyle=a,e.beginPath(),e.moveTo(t[0],t[1]),e.lineTo(n[0],n[1]),e.lineTo(h[0],h[1]),e.closePath(),e.fill(),e.restore())}this.stroke(e,t.style,()=>{e.moveTo(l[0][0],l[0][1]);for(let t=1;t<l.length;t+=1)e.lineTo(l[t][0],l[t][1])});let h=t.necklineIndices();if(h){let i=l[h[0]],r=l[h[1]],n=l.length;if(i&&r&&n>=2){let a=(0,o.P9v)(i[0],i[1],r[0],r[1],l[0][0],l[0][1],l[1][0],l[1][1])??i,s=(0,o.P9v)(i[0],i[1],r[0],r[1],l[n-2][0],l[n-2][1],l[n-1][0],l[n-1][1])??r;this.stroke(e,{...t.style,lineStyle:"dashed"},()=>{e.moveTo(a[0],a[1]),e.lineTo(s[0],s[1])})}}let d=t.vertexLabels();if(e.fillStyle=r.textColor,e.font=`bold 12px ${r.fontFamily}`,e.textAlign="center",l.forEach((t,i)=>{let o=d[i];if(!o)return;let r=((l[i-1]?.[1]??t[1])+(l[i+1]?.[1]??t[1]))/2,n=t[1]<=r;e.textBaseline=n?"bottom":"top",e.fillText(this.t(o),t[0],n?t[1]-7:t[1]+7)}),t.legRatios()){e.font=`11px ${r.fontFamily}`,e.textAlign="left",e.textBaseline="middle";for(let i=2;i<l.length;i+=1){let o=t.ratioAt(i),n=l[i-1],a=l[i];if(null==o||!n||!a)continue;let s=t.ratioOk(i);e.fillStyle=!0===s?eR:!1===s?eN:r.textColor,e.fillText(this.num(o.toFixed(3)),(n[0]+a[0])/2+6,(n[1]+a[1])/2)}}let c=t.patternName();if(c&&l.length>=2){let t=l[l.length-1],i=l[l.length-2],o=!!i&&t[1]<=i[1];e.font=`bold 12px ${r.fontFamily}`,e.fillStyle=!1===n?eN:eR,e.textAlign="center",e.textBaseline=o?"bottom":"top",e.fillText(`${this.t(c)} ${n?"✓":"✗"}`,t[0],o?t[1]-22:t[1]+22)}e.textAlign="left",e.textBaseline="alphabetic"}paintHighlighter(e,t,i){let o=t.geometry(i);if(!o||0===o.segments.length)return;e.save(),e.strokeStyle=t.style.lineColor,e.lineWidth=t.style.lineWidth,e.lineCap="round",e.lineJoin="round",e.setLineDash([]),e.beginPath();let r=o.segments[0];for(let t of(e.moveTo(r[0],r[1]),o.segments))e.lineTo(t[2],t[3]);e.stroke(),e.restore()}paintSegments(e,t,i){let o=t.geometry(i);if(o){if(o.fill&&o.fill.length>=3&&t.style.fillColor){e.save(),e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(o.fill[0][0],o.fill[0][1]);for(let t=1;t<o.fill.length;t+=1)e.lineTo(o.fill[t][0],o.fill[t][1]);e.closePath(),e.fill(),e.restore()}for(let i of o.segments)this.stroke(e,t.style,()=>{e.moveTo(i[0],i[1]),e.lineTo(i[2],i[3])})}}paintInfoLine(e,t,i){let o=t.handlePoints(i);if(o.length<2)return;let[l,n]=o[0],[a,s]=o[1];this.stroke(e,t.style,()=>{e.moveTo(l,n),e.lineTo(a,s)});let h=t.anchors[0],d=t.anchors[1];if(!h||!d)return;let c=d.price-h.price,p=0!==h.price?c/h.price*100:0,u=i.barsBetween?Math.abs(Math.round(i.barsBetween(h.time,d.time))):0,g=c>=0?"+":"",m=this.t(rL.infoLine,{change:this.num(`${g}${c.toFixed(2)}`),percent:this.num(`${g}${p.toFixed(2)}`),count:u,bars:this.num(String(u))}),b=(l+a)/2,f=(n+s)/2;e.font="11px monospace";let v=e.measureText(m).width+12,y=b-2,w=f-18-4;e.save(),e.globalAlpha=.9*e.globalAlpha,rz(e,y,w,v,18,3),e.fillStyle=rI,e.fill(),e.strokeStyle=rE,e.lineWidth=1,e.stroke(),e.restore(),e.fillStyle=c>=0?r.cr:r.TV,e.textAlign="left",e.textBaseline="middle",e.fillText(m,y+6,w+9),e.textBaseline="alphabetic"}paintTrendAngle(e,t,i,o){let r=t.handlePoints(i);if(r.length<2)return;let[l,n]=r[0],[a,s]=r[1];this.stroke(e,t.style,()=>{e.moveTo(l,n),e.lineTo(a,s)});let h=a-l,d=s-n,c=Math.atan2(-d,h),p=180/Math.PI*c,u=Math.min(30,.3*Math.hypot(h,d)),g=t.style.lineColor;if(e.save(),e.globalAlpha=.4*e.globalAlpha,e.strokeStyle=g,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(l,n),e.lineTo(l+Math.max(Math.abs(h),u+20),n),e.stroke(),e.restore(),e.setLineDash([]),u>1){let t=-c;e.strokeStyle=g,e.lineWidth=1.5,e.beginPath(),e.arc(l,n,u,Math.min(0,t),Math.max(0,t)),e.stroke()}let m=`${this.num(p.toFixed(1))}\xb0`,b=l+u+6,f=d<0?n+14:n-6;e.font=`11px ${o.fontFamily}`,e.textAlign="left",e.textBaseline="alphabetic",e.save(),e.lineJoin="round",e.lineWidth=3,e.strokeStyle=o.background,e.strokeText(m,b,f),e.restore(),e.fillStyle=g,e.fillText(m,b,f)}paintArrowMark(e,t,i){let o=t.glyphPoints(i);if(o&&!(o.length<3)){e.save(),e.setLineDash([]),e.fillStyle=t.style.lineColor,e.beginPath(),e.moveTo(o[0][0],o[0][1]);for(let t=1;t<o.length;t+=1)e.lineTo(o[t][0],o[t][1]);e.closePath(),e.fill(),e.restore()}}paintGlyphStamp(e,t,i,o){let r=t.center(i);r&&(e.save(),e.setLineDash([]),e.font=`${t.sizePx()}px ${o.fontFamily}`,e.fillStyle=t.style.lineColor,e.textAlign="center",e.textBaseline="middle",e.fillText(t.glyph,r[0],r[1]),e.textAlign="left",e.textBaseline="alphabetic",e.restore())}paintArrowhead(e,t,i,o){let r=Math.atan2(i[1]-t[1],i[0]-t[0]),l=Math.max(9,3.5*o.lineWidth),n=Math.PI/7;e.save(),e.setLineDash([]),e.fillStyle=o.lineColor,e.beginPath(),e.moveTo(i[0],i[1]),e.lineTo(i[0]-l*Math.cos(r-n),i[1]-l*Math.sin(r-n)),e.lineTo(i[0]-l*Math.cos(r+n),i[1]-l*Math.sin(r+n)),e.closePath(),e.fill(),e.restore()}stroke(e,t,i){this.applyStroke(e,t),e.beginPath(),i(),e.stroke(),e.setLineDash([])}applyStroke(e,t){e.strokeStyle=t.lineColor,e.lineWidth=t.lineWidth,e.setLineDash(ox(t.lineStyle,t.lineWidth))}paintHandles(e,t){for(let[i,o]of(e.setLineDash([]),e.lineWidth=1.5,t))e.beginPath(),e.arc(i,o,4.5,0,2*Math.PI),e.fillStyle=rP,e.fill(),e.strokeStyle=rA,e.stroke()}};function rN(e){let t=e.trim().toLowerCase();if(/^#[0-9a-f]{8}$/.test(t))return t.endsWith("00");let i=/rgba?\([^)]*,\s*([\d.]+)\s*\)$/.exec(t);return!!i&&0===parseFloat(i[1])}function rz(e,t,i,o,r,l){let n=Math.min(l,o/2,r/2);e.beginPath(),e.moveTo(t+n,i),e.arcTo(t+o,i,t+o,i+r,n),e.arcTo(t+o,i+r,t,i+r,n),e.arcTo(t,i+r,t,i,n),e.arcTo(t,i,t+o,i,n),e.closePath()}function rV(e,t,i,o,r,l,n){let a=(l,a,s)=>{if(n&&n.edge===l){let[a,s]=n.apex;"top"===l?(e.lineTo(n.at-n.half,i),e.lineTo(a,s),e.lineTo(n.at+n.half,i)):"bottom"===l?(e.lineTo(n.at+n.half,i+r),e.lineTo(a,s),e.lineTo(n.at-n.half,i+r)):"right"===l?(e.lineTo(t+o,n.at-n.half),e.lineTo(a,s),e.lineTo(t+o,n.at+n.half)):(e.lineTo(t,n.at+n.half),e.lineTo(a,s),e.lineTo(t,n.at-n.half))}e.lineTo(a,s)};e.beginPath(),e.moveTo(t+l,i),a("top",t+o-l,i),e.arcTo(t+o,i,t+o,i+l,l),a("right",t+o,i+r-l),e.arcTo(t+o,i+r,t+o-l,i+r,l),a("bottom",t+l,i+r),e.arcTo(t,i+r,t,i+r-l,l),a("left",t,i+l),e.arcTo(t,i,t+l,i,l),e.closePath()}var rD=6;function r$(e,t){let i=e.text;if(!i)return null;let r=e.handlePoints(t),l=i.value.split("\n").length,n=oT(oM(i.size));if(e instanceof o.vi5){let i=e.bounds(t);if(!i)return null;let o=i.x+i.w/2;return"arrowmarkdown"===e.type?{x:o,top:i.y-4-n*l,align:"center"}:{x:o,top:i.y+i.h+4,align:"center"}}switch(e.type){case"text":return r[0]?{x:r[0][0]+2,top:r[0][1]+2,align:"left"}:null;case"hline":return r[0]?{x:r[0][0]+8,top:r[0][1]-4-n*l,align:"left"}:null;case"trendline":case"ray":case"extendedline":case"infoline":case"trendangle":{let e;if(r.length<2)return null;let[t,o]=r[0],[a,s]=r[1],h="start"===i.place?.12:"end"===i.place?.88:.5;return{x:0,top:"below"===i.side?6:-6-n*l,align:"center",rotate:{angle:((e=Math.atan2(s-o,a-t))>Math.PI/2&&(e-=Math.PI),e<-Math.PI/2&&(e+=Math.PI),e),cx:t+(a-t)*h,cy:o+(s-o)*h}}}case"box":if(r.length<2)return null;return{x:(r[0][0]+r[1][0])/2,top:(r[0][1]+r[1][1])/2-n*l/2,align:"center"};default:return r[0]?{x:r[0][0],top:r[0][1],align:"left"}:null}}function rH(e,t,i,o,r=6){for(let l=e.length-1;l>=0;l-=1){let n=e[l];if(!n.visible)continue;let a=o.paneRect?.(n.paneId);if((!a||!(a.height<=0))&&n.hitTest(t,i,o,r))return n}return null}function rW(e,t){let i=[...e];return i.length<2?i:i.filter(e=>!t.find(t=>t.id===e)?.locked)}var rq=Math.PI/4,rU=new Set(["trendline","ray","extendedline","infoline","trendangle","arrow"]),rj=class{constructor(e){this.deps=e,this.state={kind:"idle"},this.snapAt=null}snapMarker(){return this.snapAt}placingMarkers(e){if("placing"!==this.state.kind)return null;let{draft:t}=this.state;if("freehand"===t.placementMode())return null;let i=[];for(let o of t.anchors){let r=e.yOf(o.price,t.paneId);null!=r&&i.push([e.xOf(o.time),r])}return i.length?i:null}resolve(e,t,i,o){let r=this.deps.projector().pxToPoint(e,t,i);if("off"===o)return this.snapAt=null,r;let l=this.deps.snap(r,i,o,{x:e,y:t}),n=l.time!==r.time||l.price!==r.price;return this.snapAt=n?{point:l,paneId:i}:null,l}snapCursor(e,t,i){let o=this.deps.projector(),r=o.paneIdAtY(t)??"price",l=this.resolve(e,t,r,i),n=o.yOf(l.price,r);return{x:o.xOf(l.time),y:n??t}}clearSnapMarker(){this.snapAt=null}resolveAngleSnapped(e,t,i,o){let r=this.deps.projector(),l=r.xOf(e.time),n=r.yOf(e.price,t);if(this.snapAt=null,null==n)return r.pxToPoint(i,o,t);let a=Math.hypot(i-l,o-n);if(a<1)return r.pxToPoint(i,o,t);let s=Math.round(Math.atan2(o-n,i-l)/rq)*rq;return r.pxToPoint(l+a*Math.cos(s),n+a*Math.sin(s),t)}placingPivot(e){return rU.has(e.type)?e.anchors[e.anchors.length-1]??null:null}claim(e,t){return null!=this.deps.activeTool()||"idle"!==this.state.kind||null!=this.hitAt(e,t)}cursorAt(e,t){return null!=this.deps.activeTool()?null:this.hitAt(e,t)?"pointer":null}isPlacing(){return"placing"===this.state.kind}isDragging(){return"pressed"===this.state.kind&&this.state.moved}activeDragId(){return"pressed"===this.state.kind&&this.state.moved?this.state.id:null}movingIds(){return"pressed"!==this.state.kind||!this.state.moved||this.state.clones?new Set:new Set([this.state.id,...this.state.riders.map(e=>e.id)])}pressedId(){return"pressed"===this.state.kind?this.state.id:null}dragClones(){return"pressed"===this.state.kind&&this.state.moved&&this.state.clones?this.state.clones.map(e=>e.d):null}marqueeRect(){if("marquee"!==this.state.kind)return null;let{x0:e,y0:t,x1:i,y1:o}=this.state;return{x:Math.min(e,i),y:Math.min(t,o),w:Math.abs(i-e),h:Math.abs(o-t)}}beginMarquee(e,t){return"idle"===this.state.kind&&null==this.deps.activeTool()&&(this.state={kind:"marquee",x0:e,y0:t,x1:e,y1:t},!0)}down(e,t,i="off",r=!1,l=!1){let n=this.deps.projector();if("placing"===this.state.kind){if("click"!==this.state.draft.placementMode())return;let o=r?this.placingPivot(this.state.draft):null,l=o?this.resolveAngleSnapped(o,this.state.draft.paneId,e,t):this.resolve(e,t,this.state.draft.paneId,i);this.state.draft.anchors.push(this.placementAnchor(this.state.draft,l)),this.state.draft.anchors.length>=this.state.need?this.finalize():this.deps.changed();return}let a=this.deps.activeTool();if(a){let r=n.paneIdAtY(t)??"price",l=(0,o.vBD)(a,{paneId:r,anchors:[this.resolve(e,t,r,i)]});if(!l)return;eA(l,this.deps.toolDefaults()),this.state={kind:"placing",draft:l,need:l.anchorSchema().max,cursor:null},"click"===l.placementMode()&&l.anchors.length>=this.state.need?this.finalize():this.deps.changed();return}let s=this.hitAt(e,t);if(s){if(r)return void this.deps.emit({kind:"select",ids:[s.id],additive:!0});let i=s.hitHandle(e,t,n,6),o=[];if(i<0&&this.deps.selectedIds().has(s.id))for(let e of this.deps.selectedIds()){let t=e===s.id?null:this.byId(e);t&&!t.locked&&t.visible&&o.push({id:e,orig:rG(t)})}this.state={kind:"pressed",id:s.id,handle:i,orig:rG(s),px:e,py:t,moved:!1,riders:o,mod:l,clones:null}}}bodyDelta(e,t,i){if("pressed"!==this.state.kind)return{dt:0,dp:0};let o=this.deps.projector(),r=o.pxToPoint(this.state.px,this.state.py,e),l=o.pxToPoint(t,i,e);return{dt:l.time-r.time,dp:l.price-r.price}}dragSources(e){if("pressed"!==this.state.kind)return[];let t=[{d:e,orig:this.state.orig}];for(let e of this.state.riders){let i=this.byId(e.id);i&&t.push({d:i,orig:e.orig})}return t}dragBody(e,t,i){if("pressed"===this.state.kind)for(let r of(this.snapAt=null,this.state.mod&&!this.state.clones&&(this.state.clones=this.dragSources(e).flatMap(e=>{let t=(0,o.erJ)(e.d.serialize());return t?[{d:t,orig:rG(t)}]:[]})),this.state.clones??this.dragSources(e))){let{dt:e,dp:o}=this.bodyDelta(r.d.paneId,t,i);r.d.anchors=r.d.translateBody(e,o,r.orig)}}move(e,t,i="off",o=!1){if("idle"===this.state.kind){let o=this.deps.activeTool(),r=null!=this.snapAt;o&&"off"!==i?this.resolve(e,t,this.deps.projector().paneIdAtY(t)??"price",i):this.snapAt=null,(null!=this.snapAt||r)&&this.deps.changed();return}if("placing"===this.state.kind){if("freehand"===this.state.draft.placementMode())return void this.captureFreehand(e,t);let r=o?this.placingPivot(this.state.draft):null;return this.state.cursor=r?this.resolveAngleSnapped(r,this.state.draft.paneId,e,t):this.resolve(e,t,this.state.draft.paneId,i),void this.deps.changed()}if("marquee"===this.state.kind){this.state.x1=e,this.state.y1=t,this.deps.changed();return}if("pressed"!==this.state.kind)return;let r=this.byId(this.state.id);if(r&&!r.locked&&!(!this.state.moved&&3>=Math.abs(e-this.state.px)&&3>=Math.abs(t-this.state.py))){if(this.state.moved=!0,this.state.handle<0)this.dragBody(r,e,t);else{let l=o&&rU.has(r.type)&&2===r.anchors.length?r.anchors[1-this.state.handle]:void 0,n=l?this.resolveAngleSnapped(l,r.paneId,e,t):this.resolve(e,t,r.paneId,i);r.dragHandle(this.state.handle,n),r.constrainHandleDrag(this.state.handle)}this.deps.changed()}}up(e,t){if(this.snapAt=null,"placing"===this.state.kind){let e=this.state.draft.placementMode();"drag"===e?(this.state.cursor&&this.state.draft.anchors.push(this.state.cursor),this.state.draft.anchors.length>=this.state.draft.anchorSchema().min?this.finalize():this.discardPlacing()):"freehand"===e&&(this.state.draft.anchors.length>=this.state.draft.anchorSchema().min?this.finalize():this.discardPlacing());return}if("marquee"===this.state.kind){let e=this.marqueeRect();this.state={kind:"idle"},(e.w>3||e.h>3)&&this.selectWithin(e),this.deps.changed();return}if("pressed"!==this.state.kind)return;let{id:i,moved:o,riders:r,mod:l,clones:n}=this.state;this.state={kind:"idle"};let a=this.byId(i);if(!o)return void(l?this.deps.emit({kind:"select",ids:[i],additive:!0}):this.deps.openSettings(i,e,t));if(n)this.deps.emit({kind:"clone",docs:n.map(e=>e.d.serialize())});else if(a){let e=[a.serialize()];for(let t of r){let i=this.byId(t.id);i&&e.push(i.serialize())}e.length>1?this.deps.emit({kind:"edit-many",docs:e}):this.deps.emit({kind:"edit",doc:e[0]})}this.deps.changed()}selectWithin(e){let t=this.deps.projector(),i=[...this.deps.selectedIds()];for(let l of this.deps.drawings()){var o,r;if(!l.visible||i.includes(l.id))continue;let n=l.bounds(t);n&&(o=e,r=n,o.x<=r.x+r.w&&r.x<=o.x+o.w&&o.y<=r.y+r.h&&r.y<=o.y+o.h)&&i.push(l.id)}i.length>this.deps.selectedIds().size&&this.deps.emit({kind:"select",ids:i})}cancel(){if(this.snapAt=null,"placing"===this.state.kind){let e=this.state.draft.type;return this.state={kind:"idle"},this.deps.emit({kind:"tool-finished",type:e}),this.deps.changed(),!0}if("pressed"===this.state.kind){if(this.state.moved&&!this.state.clones){let e=this.byId(this.state.id);if(e)for(let t of this.dragSources(e))t.d.anchors=t.orig.map(e=>({time:e.time,price:e.price}))}return this.state={kind:"idle"},this.deps.changed(),!0}return"marquee"===this.state.kind&&(this.state={kind:"idle"},this.deps.changed(),!0)}onToolCleared(){"placing"===this.state.kind&&(this.state={kind:"idle"},this.deps.changed())}ghost(){if("placing"!==this.state.kind)return null;let{draft:e,cursor:t}=this.state;if(!t)return e.anchors.length>=1&&"hline"===e.type?e:null;let{paneId:i,style:r,text:l,props:n}=e.serialize();return(0,o.vBD)(e.type,{paneId:i,anchors:[...e.anchors,this.placementAnchor(e,t)],style:r,text:l,props:n})}placementAnchor(e,t){if("parallelchannel"!==e.type||2!==e.anchors.length)return t;let i=e.anchors[0],o=e.anchors[1],r=o.time-i.time,l=0===r?i.price:i.price+(o.price-i.price)*(t.time-i.time)/r,n=t.price-l;return{time:(i.time+o.time)/2,price:(i.price+o.price)/2+n}}captureFreehand(e,t){if("placing"!==this.state.kind)return;this.snapAt=null;let i=this.state.draft,o=this.deps.projector(),r=i.anchors[i.anchors.length-1];if(Math.hypot(e-(r?o.xOf(r.time):NaN),t-(r?o.yOf(r.price,i.paneId)??NaN:NaN))>4){if(i.anchors.length>=this.state.need){let e=i.anchors.length-1;i.anchors=i.anchors.filter((t,i)=>i%2==0||i===e)}i.anchors.push(o.pxToPoint(e,t,i.paneId))}this.state.cursor=o.pxToPoint(e,t,i.paneId),this.deps.changed()}finishPlacing(e){if("placing"!==this.state.kind)return!1;let t=this.state.draft,i=t.anchorSchema();return"click"===t.placementMode()&&!(i.max<=i.min)&&(e&&t.anchors.length>i.min&&t.anchors.pop(),!(t.anchors.length<i.min)&&(this.finalize(),!0))}discardPlacing(){if("placing"!==this.state.kind)return;let e=this.state.draft.type;this.state={kind:"idle"},this.deps.emit({kind:"tool-finished",type:e}),this.deps.changed()}finalize(){if("placing"!==this.state.kind)return;this.snapAt=null;let e=this.state.draft;e.onPlaced(this.deps.projector());let t=e.type;this.state={kind:"idle"},this.deps.emit({kind:"create",doc:e.serialize()}),this.deps.emit({kind:"tool-finished",type:t}),this.deps.changed()}hitAt(e,t){let i=this.deps.projector();for(let o of this.handleDrawings())if(o.hitHandle(e,t,i,6)>=0)return o;return rH(this.deps.drawings(),e,t,i,6)}handleDrawings(){let e=new Set(this.deps.selectedIds()),t=this.deps.hoveredId();t&&e.add(t);let i=[];for(let t of e){let e=this.byId(t);e&&i.push(e)}return i}byId(e){return this.deps.drawings().find(t=>t.id===e)??null}};function rG(e){return e.anchors.map(e=>({time:e.time,price:e.price}))}var rK={account:(0,n.ab)("drawing.section.account","Account"),riskPct:(0,n.ab)("drawing.section.riskPct","Risk %"),accountBalance:(0,n.ab)("drawing.section.accountBalance","Account balance"),positionSize:(0,n.ab)("drawing.section.positionSize","Position size"),levels:(0,n.ab)("drawing.section.levels","Levels"),direction:(0,n.ab)("drawing.section.direction","Direction"),entryPrice:(0,n.ab)("drawing.section.entryPrice","Entry price"),stop:(0,n.ab)("drawing.section.stop","Stop"),target:(0,n.ab)("drawing.section.target","Target"),display:(0,n.ab)("drawing.section.display","Display"),showText:(0,n.ab)("drawing.section.showText","Show text"),showDirectionAndRatio:(0,n.ab)("drawing.section.showDirectionAndRatio","Show direction & ratio"),showLossAndSize:(0,n.ab)("drawing.section.showLossAndSize","Show loss & size"),showTargetLabel:(0,n.ab)("drawing.section.showTargetLabel","Show target label"),showStopLabel:(0,n.ab)("drawing.section.showStopLabel","Show stop label"),showLevelPrices:(0,n.ab)("drawing.section.showLevelPrices","Show level prices"),rows:(0,n.ab)("drawing.section.rows","Rows"),valueArea:(0,n.ab)("drawing.section.valueArea","Value Area"),widthPct:(0,n.ab)("drawing.section.widthPct","Width %"),anchor:(0,n.ab)("drawing.section.anchor","Anchor"),upVolume:(0,n.ab)("drawing.section.upVolume","Up Volume"),downVolume:(0,n.ab)("drawing.section.downVolume","Down Volume"),valueAreaUp:(0,n.ab)("drawing.section.valueAreaUp","Value Area Up"),valueAreaDown:(0,n.ab)("drawing.section.valueAreaDown","Value Area Down"),vah:(0,n.ab)("drawing.section.vah","VAH"),val:(0,n.ab)("drawing.section.val","VAL"),poc:(0,n.ab)("drawing.section.poc","POC"),developingPOC:(0,n.ab)("drawing.section.developingPOC","Developing POC"),developingVA:(0,n.ab)("drawing.section.developingVA","Developing VA")},rY=[{value:"price",label:(0,n.ab)("drawing.position.unit.price","Price")},{value:"points",label:(0,n.ab)("drawing.position.unit.points","Points")}],rZ=[{value:"right",label:(0,n.ab)("drawing.fixedrangevp.anchor.right","Right")},{value:"left",label:(0,n.ab)("drawing.fixedrangevp.anchor.left","Left")}];function rX(e,t){return e.map(e=>({value:e.value,label:t(e.label)}))}var r_={settings:(0,n.ab)("drawing.settings.settings","Settings"),cancel:(0,n.ab)("drawing.settings.cancel","Cancel"),ok:(0,n.ab)("drawing.settings.ok","OK"),position:(0,n.ab)("drawing.settings.position","Position"),profile:(0,n.ab)("drawing.settings.profile","Profile"),lineColor:(0,n.ab)("drawing.settings.lineColor","Line color"),lineWidth:(0,n.ab)("drawing.settings.lineWidth","Line width"),line:(0,n.ab)("drawing.settings.line","Line"),style:(0,n.ab)("drawing.settings.style","Style"),lineStyle:(0,n.ab)("drawing.settings.lineStyle","Line style"),dontExtend:(0,n.ab)("drawing.settings.dontExtend","Don't extend"),extendLeft:(0,n.ab)("drawing.settings.extendLeft","Extend left"),extendRight:(0,n.ab)("drawing.settings.extendRight","Extend right"),extendBothWays:(0,n.ab)("drawing.settings.extendBothWays","Extend both ways"),extend:(0,n.ab)("drawing.settings.extend","Extend"),startArrow:(0,n.ab)("drawing.settings.startArrow","Start arrow"),endArrow:(0,n.ab)("drawing.settings.endArrow","End arrow"),arrow:(0,n.ab)("drawing.settings.arrow","Arrow"),ends:(0,n.ab)("drawing.settings.ends","Ends"),fill:(0,n.ab)("drawing.settings.fill","Fill"),text:(0,n.ab)("drawing.settings.text","Text"),numbers:(0,n.ab)("drawing.settings.numbers","Numbers"),numbersSize:(0,n.ab)("drawing.settings.numbersSize","Numbers size"),labels:(0,n.ab)("drawing.settings.labels","Labels"),labelsSize:(0,n.ab)("drawing.settings.labelsSize","Labels size"),levelSet:(0,n.ab)("drawing.settings.levelSet","Level set"),ratios:(0,n.ab)("drawing.settings.ratios","Ratios"),prices:(0,n.ab)("drawing.settings.prices","Prices"),background:(0,n.ab)("drawing.settings.background","Background"),reverse:(0,n.ab)("drawing.settings.reverse","Reverse"),show:(0,n.ab)("drawing.settings.show","Show"),labelSide:(0,n.ab)("drawing.settings.labelSide","Label side"),left:(0,n.ab)("drawing.settings.left","Left"),right:(0,n.ab)("drawing.settings.right","Right"),levels:(0,n.ab)("drawing.settings.levels","Levels"),none:(0,n.ab)("drawing.settings.none","None"),label:(0,n.ab)("drawing.settings.label","Label"),addALabel:(0,n.ab)("drawing.settings.addALabel","Add a label"),place:(0,n.ab)("drawing.settings.place","Position"),positionAlongTheLine:(0,n.ab)("drawing.settings.positionAlongTheLine","Position along the line"),start:(0,n.ab)("drawing.settings.start","Start"),middle:(0,n.ab)("drawing.settings.middle","Middle"),end:(0,n.ab)("drawing.settings.end","End"),side:(0,n.ab)("drawing.settings.side","Side"),sideOfTheLine:(0,n.ab)("drawing.settings.sideOfTheLine","Side of the line"),above:(0,n.ab)("drawing.settings.above","Above"),below:(0,n.ab)("drawing.settings.below","Below"),textColor:(0,n.ab)("drawing.settings.textColor","Text color"),bold:(0,n.ab)("drawing.settings.bold","Bold"),italic:(0,n.ab)("drawing.settings.italic","Italic"),points:(0,n.ab)("drawing.settings.points","Points"),allTimeframes:(0,n.ab)("drawing.settings.allTimeframes","All timeframes"),intraday:(0,n.ab)("drawing.settings.intraday","Intraday"),n1HAndUp:(0,n.ab)("drawing.settings.n1HAndUp","1H and up"),nowhere:(0,n.ab)("drawing.settings.nowhere","Nowhere"),showOn:(0,n.ab)("drawing.settings.showOn","Show on"),all:(0,n.ab)("drawing.settings.all","All"),custom:(0,n.ab)("drawing.settings.custom","Custom"),chartTimeframe:(0,n.ab)("drawing.settings.chartTimeframe","The chart's timeframe"),hiddenOnEveryTimeframe:(0,n.ab)("drawing.settings.hiddenOnEveryTimeframe","Hidden on every timeframe."),hiddenOnThisTimeframe:(0,n.ab)("drawing.settings.hiddenOnThisTimeframe","Hidden on this chart's timeframe."),styles:(0,n.ab)("drawing.settings.styles","Styles"),presets:(0,n.ab)("drawing.settings.presets","Presets"),saved:(0,n.ab)("drawing.settings.saved","Saved"),resetToDefault:(0,n.ab)("drawing.settings.resetToDefault","Reset to default"),saveAsStyle:(0,n.ab)("drawing.settings.saveAsStyle","Save as style…"),pointCount:(0,n.ab)("drawing.settings.pointCount","{count, plural, one {# point} other {# points}}"),pointTime:(0,n.ab)("drawing.settings.pointTime","Time"),pointPrice:(0,n.ab)("drawing.settings.pointPrice","Price"),pointPriceTitle:(0,n.ab)("drawing.settings.pointPriceTitle","Point {point} price"),level:(0,n.ab)("drawing.settings.level","Level {n}"),levelColor:(0,n.ab)("drawing.settings.levelColor","Level {n} color"),styleTitle:(0,n.ab)("drawing.settings.styleTitle","Style: {name}"),deleteStyle:(0,n.ab)("drawing.settings.deleteStyle","Delete {name}"),styleName:(0,n.ab)("drawing.settings.styleName","Style name"),save:(0,n.ab)("drawing.settings.save","Save"),normal:(0,n.ab)("drawing.settings.normal","Normal")},rQ=new Set(["trendline","ray","extendedline","infoline","trendangle"]),rJ=new Set(["freehand","highlighter","vline","position"]),r0=new Set(["riskPercent","accountBalance","quantity","direction","entryPrice","stopPrice","targetPrice","showText","showHeader","showLossSize","showTargetLabel","showStopLabel","showPrices"]),r1=new Set(["showRatios"]),r2=["s","1","5","15","60","240"],r5=["60","240","D","W","M"],r3=new Map,r4="vela-dsp-styles",r6={none:'<svg viewBox="0 0 18 14" width="18" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M5 7h8"/><circle cx="5" cy="7" r="1.5" fill="currentColor"/><circle cx="13" cy="7" r="1.5" fill="currentColor"/></svg>',left:'<svg viewBox="0 0 18 14" width="18" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M1 7h12"/><path d="m3.5 4.5-2.5 2.5 2.5 2.5"/><circle cx="13" cy="7" r="1.5" fill="currentColor"/></svg>',right:'<svg viewBox="0 0 18 14" width="18" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M5 7h12"/><path d="m14.5 4.5 2.5 2.5-2.5 2.5"/><circle cx="5" cy="7" r="1.5" fill="currentColor"/></svg>',both:'<svg viewBox="0 0 18 14" width="18" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M1 7h16"/><path d="m3.5 4.5-2.5 2.5 2.5 2.5M14.5 4.5l2.5 2.5-2.5 2.5"/></svg>'},r8=e=>`<svg viewBox="0 0 18 14" width="18" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-dasharray="${"dashed"===e?"4 3":"dotted"===e?"0.1 3.5":"0"}"><path d="M2 7h14"/></svg>`,r7=class{constructor(e,t,i){this.host=e,this.env=i,this.ui=null,this.menu=null,this.refresh=null,this.theme=t}setTheme(e){this.theme=e}t(e,t){return(0,n.b6)(this.env.i18n?.()??null,e,t)}isOpen(){return null!=this.ui}contains(e){return null!=e&&this.ui?.contains(e)===!0}sync(){(0,T.z)(this.env.i18n?.(),()=>this.refresh?.())}open(e,t,i,o=null){(0,T.z)(this.env.i18n?.(),()=>this.build(e,t,i,o))}build(e,t,i,r){this.close(),function(){if("undefined"==typeof document)return;let e=document.getElementById(r4);if(e?.dataset.rev==="1")return;let t=e??document.createElement("style");t.id=r4,t.dataset.rev="1",t.textContent=(0,d.AH)`@layer vela.chrome {
216
+
217
+ .vela-dsp-pass { pointer-events: none !important; }
218
+ .vela-dialog.vela-dsp { pointer-events: auto; width: 360px; min-width: 0; max-width: calc(100% - 24px); max-height: calc(100% - 24px); font-size: 13px; }
219
+ .vela-dsp .vela-dialog-header { padding: 8px 8px 8px 16px; gap: 6px; }
220
+ .vela-dsp .vela-dialog-title { font-size: 15px; line-height: 22px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
221
+ .vela-dsp .vela-dialog-footer { padding: 10px 12px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid ${c.t.border}; }
222
+ .vela-dsp-scroll { overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; }
223
+ .vela-dsp-block { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
224
+ .vela-dsp-block + .vela-dsp-block, .vela-dsp-fold { border-top: 1px solid ${c.t.border}; }
225
+ .vela-dsp-h { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: ${c.t.fg.muted}; }
226
+ .vela-dsp-row { display: flex; align-items: center; gap: 8px; min-height: 30px; }
227
+ .vela-dsp-row[hidden] { display: none; }
228
+ .vela-dsp-lab { flex: 0 0 96px; color: ${c.t.fg.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
229
+ .vela-dsp-row > .vela-dsp-lab + * { min-width: 0; }
230
+ .vela-dsp-spacer { flex: 1; }
231
+ .vela-dsp-fold-h { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 8px; padding: 11px 16px; cursor: pointer; }
232
+ .vela-dsp-fold-h:hover { background: ${c.t.hover}; }
233
+ .vela-dsp-fold-h:focus-visible { outline: 2px solid ${c.t.selected.bg}; outline-offset: -2px; }
234
+ .vela-dsp-fold-t { font-weight: 600; color: ${c.t.fg.bright}; white-space: nowrap; }
235
+ .vela-dsp-fold-s { flex: 1; min-width: 0; text-align: end; color: ${c.t.fg.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
236
+ .vela-dsp-chev { display: flex; color: ${c.t.fg.muted}; transition: transform ${c.t.dur.fast} ease; }
237
+ .vela-dsp-fold[data-open] .vela-dsp-chev { transform: rotate(90deg); }
238
+ .vela-dsp-fold-b { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 8px; }
239
+ .vela-dsp-fold:not([data-open]) .vela-dsp-fold-b { display: none; }
240
+ .vela-dsp-seg { display: inline-flex; flex: none; border: 1px solid ${c.t.border.strong}; border-radius: ${c.t.radius.md}; overflow: hidden; }
241
+ .vela-dsp-seg[data-full] { display: flex; flex: 1; }
242
+ .vela-dsp-seg > button { all: unset; box-sizing: border-box; cursor: pointer; height: 28px; min-width: 32px; padding: 0 8px; display: flex; align-items: center; justify-content: center; color: ${c.t.fg.muted}; white-space: nowrap; }
243
+ .vela-dsp-seg[data-full] > button { flex: 1 1 0; min-width: 0; }
244
+ .vela-dsp-seg > button + button { border-inline-start: 1px solid ${c.t.border}; }
245
+ .vela-dsp-seg > button:hover { background: ${c.t.hover}; color: ${c.t.fg.bright}; }
246
+ .vela-dsp-seg > button[aria-pressed='true'] { background: ${c.t.active}; color: ${c.t.fg.bright}; }
247
+ .vela-dsp-seg > button:focus-visible { outline: 2px solid ${c.t.selected.bg}; outline-offset: -2px; }
248
+ .vela-dsp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
249
+ .vela-dsp-chip { all: unset; box-sizing: border-box; cursor: pointer; height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid ${c.t.border.strong}; color: ${c.t.fg.muted}; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
250
+ .vela-dsp-chip:hover { color: ${c.t.fg.bright}; border-color: ${c.t.fg.muted}; }
251
+ .vela-dsp-chip[aria-pressed='true'] { background: ${c.t.active}; border-color: transparent; color: ${c.t.fg.bright}; }
252
+ .vela-dsp-chip:focus-visible { outline: 2px solid ${c.t.selected.bg}; outline-offset: 1px; }
253
+ .vela-dsp-note { font-size: 12px; color: ${c.t.fg.muted}; line-height: 1.45; }
254
+ .vela-dsp-pt { display: grid; grid-template-columns: 34px minmax(0, 120px) minmax(0, 1fr); align-items: center; gap: 8px; min-height: 30px; }
255
+ .vela-dsp-pt-k { font-weight: 600; color: ${c.t.fg.muted}; }
256
+ .vela-dsp-pt-t { color: ${c.t.fg.muted}; font-size: 12px; text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
257
+ .vela-dsp-tf[hidden], .vela-dsp-note[hidden] { display: none; }
258
+ .vela-dsp-tf { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
259
+ .vela-dsp-tf > button { all: unset; box-sizing: border-box; cursor: pointer; position: relative; height: 28px; border-radius: ${c.t.radius.md}; border: 1px solid ${c.t.border.strong}; color: ${c.t.fg.muted}; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
260
+ .vela-dsp-tf > button:hover { color: ${c.t.fg.bright}; border-color: ${c.t.fg.muted}; }
261
+ .vela-dsp-tf > button[aria-pressed='true'] { background: ${c.t.active}; border-color: transparent; color: ${c.t.fg.bright}; }
262
+ .vela-dsp-tf > button[data-here]::after { content: ''; position: absolute; top: 3px; inset-inline-end: 3px; width: 5px; height: 5px; border-radius: 50%; background: ${c.t.selected.bg}; }
263
+ .vela-dsp-grid { padding: 0; }
264
+ .vela-dsp-lv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
265
+ .vela-dsp-lv-c { display: flex; align-items: center; gap: 6px; min-width: 0; }
266
+ .vela-dsp-lv-c .vela-num:not([data-fill])[data-compact] { width: 76px; }
267
+ .vela-dsp-lv-c .vela-num input { height: 28px; }
268
+ .vela-dsp-lv-c[data-off] .vela-num input { color: ${c.t.fg.muted}; }
269
+ .vela-dsp-style { all: unset; box-sizing: border-box; cursor: pointer; flex: none; height: 28px; max-width: 150px; padding: 0 6px 0 10px; border-radius: ${c.t.radius.md}; border: 1px solid ${c.t.border.strong}; display: inline-flex; align-items: center; gap: 4px; color: ${c.t.fg}; font-size: 12px; }
270
+ .vela-dsp-style > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
271
+ .vela-dsp-style:hover, .vela-dsp-style[aria-expanded='true'] { background: ${c.t.hover}; color: ${c.t.fg.bright}; }
272
+ .vela-dsp-menu { min-width: 220px; max-height: 320px; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; gap: 1px; }
273
+ .vela-dsp-mh { padding: 6px 8px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: ${c.t.fg.muted}; }
274
+ .vela-dsp-mi { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 0 4px 0 8px; height: 30px; border-radius: 5px; color: inherit; }
275
+ .vela-dsp-mi:hover, .vela-dsp-mi:focus-visible { background: ${c.t.hover.strong}; }
276
+ .vela-dsp-mi[data-current] { color: ${c.t.fg.bright}; font-weight: 600; }
277
+ .vela-dsp-mi > .vela-dsp-mi-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
278
+ .vela-dsp-mi-dot { flex: none; width: 14px; height: 14px; border-radius: ${c.t.radius.sm}; border: 1px solid ${c.t.border.strong}; }
279
+ .vela-dsp-mi-x { all: unset; cursor: pointer; flex: none; width: 24px; height: 24px; border-radius: ${c.t.radius.sm}; display: flex; align-items: center; justify-content: center; color: ${c.t.fg.muted}; }
280
+ .vela-dsp-mi-x:hover { background: ${c.t.hover}; color: ${c.t.danger}; }
281
+ .vela-dsp-msep { height: 1px; background: ${c.t.border}; margin: 4px 0; }
282
+ .vela-dsp-mname { display: flex; gap: 6px; padding: 4px; }
283
+ .vela-dsp-mname > input { flex: 1; min-width: 0; height: 28px; box-sizing: border-box; padding: 0 8px; border-radius: ${c.t.radius.md}; border: 1px solid ${c.t.border.strong}; background: transparent; color: inherit; font: inherit; outline: none; }
284
+ .vela-dsp-mname > input:focus { border-color: ${c.t.selected.bg}; }
285
+ }`,e||document.head.appendChild(t)}();let l=t.resolve()??e,n=V(l.serialize()),a=(0,o.jOy)(l.type),s=document.createElement("div");s.className="vela-dsp-scroll";let h=[],p=()=>{for(let e of h)e()},u={live:()=>t.resolve()??l,edit:e=>{t.patch(e),p()},watch:e=>{h.push(e),e()},rebuild:()=>{let e=s.scrollTop;h=[];let t=this.sections(u);(0,L.X)(s),s.replaceChildren(...t),s.scrollTop=e,C.refresh()},actions:t},g=()=>{t.preview?.(null),t.restore?.(n),this.close()},m=this.env.i18n?.(),b=new v.lG({host:this.host,title:a?.label??this.t(r_.settings),...m?{i18n:m}:{},modal:!1,contained:!0,align:"center",draggable:!0,flush:!0,className:"vela-dsp",closeOnEscape:!1,footer:e=>{let i=(t.extras?.()??[]).filter(e=>e.settings);for(let t of i){let i=(0,y.Tf)({text:t.label,icon:t.icon,variant:"ghost",size:"sm",onClick:()=>t.run()}).el;i.dataset.drawingAction=t.id,e.append(i)}let o=lo(this.t(r_.cancel),!1,g);i.length>0&&(o.style.marginInlineStart="auto"),e.append(o,lo(this.t(r_.ok),!0,()=>this.close()))},onOpenChange:e=>{e||this.close()}});e$(b.panel,this.theme),b.backdrop.classList.add("vela-dsp-pass"),b.positioner.classList.add("vela-dsp-pass");let f=this.host.clientWidth,w=null!=i&&f>0&&i.x+i.w/2<f/2;b.positioner.style.justifyContent=w?"flex-end":"flex-start",b.positioner.style.padding="0 12px";let C=this.styleMenuButton(u);b.titleEl.after(C.el),b.body.appendChild(s),b.panel.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),this.menu?this.menu.hide():g())}),this.ui=b,this.refresh=()=>{if(!t.resolve())return void this.close();p(),C.refresh()},u.rebuild(),b.show(),r&&this.placeBeside(b,r,i)}placeBeside(e,t,i){if(e.positioner.closest('[data-layout="mobile"]'))return;let o=this.host.clientWidth,r=this.host.clientHeight;if(0===o||0===r)return;let l=e.panel;e.positioner.style.padding="0",l.style.position="absolute",l.style.margin="0";let n=e.positioner.style.display;e.positioner.style.display="";let a=l.offsetWidth,s=l.offsetHeight;e.positioner.style.display=n;let h={above:t.y-8-12,below:r-(t.y+t.h)-8-12},d=(null!=i&&i.y+i.h/2>t.y+t.h/2?["above","below"]:["below","above"]).find(e=>h[e]>=s)??(h.above>h.below?"above":"below");if(l.style.left=`${Math.max(4,Math.min(t.x,o-a-4))}px`,h[d]<200){l.style.top=`${Math.max(12,Math.min(t.y,r-s-12))}px`;return}l.style.maxHeight=`${h[d]}px`,"below"===d?l.style.top=`${t.y+t.h+8}px`:l.style.bottom=`${r-t.y+8}px`}close(){this.menu?.hide(),this.menu=null,this.refresh=null;let e=this.ui;this.ui=null,e?.destroy()}destroy(){this.close()}sections(e){let t=e.live(),i=t.schema(),r=i.fields,l=e=>r.some(t=>t.path===e),n=[];i.textIsContent&&l("text.value")&&n.push(this.textContentBlock(e,l));let a=this.styleBlock(e,r,l);a&&n.push(a),t.editableLevels()&&n.push(this.levelsBlock(e)),t instanceof o.m4Q&&n.push(this.richBlock(this.t(r_.position),i=>(function(e,t,i,r,l){let n=()=>{let e=i.resolve();return e instanceof o.m4Q?e:t},a=[],s=()=>a.forEach(e=>e()),h=e=>Math.round(1e8*e)/1e8,d=(t,o,r)=>{let l=(0,k.yF)({kind:"number",value:h(n()[o]),min:r?.min,max:r?.max,step:r?.step,integer:r?.integer,fill:!1,commit:"blur",onChange:e=>{i.patch({[o]:e}),s()}});a.push(()=>{document.activeElement!==l.el.querySelector("input")&&l.setValue?.(h(n()[o]))}),e.appendChild((0,k.h0)({label:t,control:l.el}))},c=(t,o,d)=>{let c="price",p=()=>h(n().levelDisplayValue(d,c)),u=(0,k.yF)({kind:"number",value:p(),fill:!1,commit:"blur",onChange:e=>{i.patch({[o]:n().levelPriceFromDisplay(d,c,e)}),s()}}),g=(0,k.yF)({kind:"select",options:rX(rY,l),value:c,fill:!1,theme:r,onChange:e=>{c=e,u.setValue?.(p())}});a.push(()=>{document.activeElement!==u.el.querySelector("input")&&u.setValue?.(p())}),e.appendChild((0,k.h0)({label:t,control:[u.el,g.el]}))};e.appendChild((0,k.uJ)(l(rK.account),{variant:"inputs",first:!0})),d(l(rK.riskPct),"riskPercent",{min:0,max:100,step:.1}),d(l(rK.accountBalance),"accountBalance",{min:0,max:1e12,step:1,integer:!0}),d(l(rK.positionSize),"quantity"),e.appendChild((0,k.uJ)(l(rK.levels),{variant:"inputs"}));let p=(0,k.yF)({kind:"select",options:rX(o.PuK,l),value:n().direction,fill:!1,theme:r,onChange:e=>{i.patch({direction:e}),s()}});for(let[t,o]of(a.push(()=>p.setValue?.(n().direction)),e.appendChild((0,k.h0)({label:l(rK.direction),control:p.el})),d(l(rK.entryPrice),"entryPrice"),c(l(rK.stop),"stopPrice","stop"),c(l(rK.target),"targetPrice","target"),e.appendChild((0,k.uJ)(l(rK.display),{variant:"inputs"})),[[l(rK.showText),"showText"],[l(rK.showDirectionAndRatio),"showHeader"],[l(rK.showLossAndSize),"showLossSize"],[l(rK.showTargetLabel),"showTargetLabel"],[l(rK.showStopLabel),"showStopLabel"],[l(rK.showLevelPrices),"showPrices"]]))e.appendChild((0,k.h0)({label:t,bool:!0,toggle:{checked:n()[o],onChange:e=>{i.patch({[o]:e}),s()},get:()=>n()[o]}}));let u=document.createElement("div");u.className="vela-field-span",u.dataset.slot="field-span",u.style.cssText="opacity:0.7;font-size:11px;line-height:1.4;border-top:1px solid var(--vela-border);padding-top:6px;font-variant-numeric:tabular-nums;",a.push(()=>{let e=n();u.textContent=`${e.headerLabel()} — ${e.lossSizeLabel()}`}),e.appendChild(u),s()})(i,t,e.actions,this.theme,(e,t)=>this.t(e,t)))),t instanceof o.npk&&n.push(this.richBlock(this.t(r_.profile),i=>(function(e,t,i,r,l){let n=()=>{let e=i.resolve();return e instanceof o.npk?e.frvp:t.frvp},a=n(),s=(t,o,r,l,n,s=!0)=>{e.appendChild((0,k.h0)({label:t,control:(0,k.yF)({kind:"number",value:a[o],min:r,max:l,step:n,integer:s,fill:!1,commit:"blur",onChange:e=>i.patch({[`frvp.${o}`]:e})}).el}))};s(l(rK.rows),"rows",1,500,1),s(l(rK.valueArea),"valueAreaPct",0,100,1),s(l(rK.widthPct),"widthPct",0,100,1),e.appendChild((0,k.h0)({label:l(rK.anchor),control:(0,k.yF)({kind:"select",options:rX(rZ,l),value:a.anchor,fill:!1,theme:r,onChange:e=>i.patch({"frvp.anchor":e})}).el}));let h=(t,o)=>{e.appendChild((0,k.h0)({label:t,fit:!0,control:(0,k.yF)({kind:"color",theme:r,get:()=>n()[o],onChange:e=>i.patch({[`frvp.${o}`]:e})}).el}))};h(l(rK.upVolume),"upColor"),h(l(rK.downVolume),"downColor"),h(l(rK.valueAreaUp),"vaUpColor"),h(l(rK.valueAreaDown),"vaDownColor");let d=rX(o.m6i,l),c=(t,o,l,n)=>{let s=document.createElement("div");s.className="vela-field-span",s.dataset.slot="field-span",s.style.cssText="display:flex;align-items:center;gap:8px;";let h=(0,k.yF)({kind:"switch",checked:!!a[o],onChange:e=>i.patch({[`frvp.${o}`]:e})}),c=document.createElement("span");c.className="vela-field-label",c.dataset.slot="field-label",c.style.flex="1",c.textContent=t;let p=a[l]??oS(r.background),u=(0,k.yF)({kind:"color",theme:r,get:()=>p,onChange:e=>{p=e,i.patch({[`frvp.${l}`]:e})}}),g=(0,k.yF)({kind:"select",options:d,value:a[n],fill:!1,theme:r,onChange:e=>i.patch({[`frvp.${n}`]:e})});s.append(h.el,c,u.el,g.el),e.appendChild(s)};c(l(rK.vah),"showVah","vahColor","vahStyle"),c(l(rK.val),"showVal","valColor","valStyle"),c(l(rK.poc),"showPoc","pocColor","pocStyle"),c(l(rK.developingPOC),"showDevelopingPoc","developingPocColor","developingPocStyle"),c(l(rK.developingVA),"showDevelopingVa","developingVaColor","developingVaStyle")})(i,t,e.actions,this.theme,(e,t)=>this.t(e,t))));let s=this.optionsBlock(e,r,t);s&&n.push(s),!i.textIsContent&&r.some(e=>e.path.startsWith("text."))&&n.push(this.textFold(e,l));let h=this.pointsFold(e);return h&&n.push(h),n.push(this.showOnFold(e)),n}styleBlock(e,t,i){let r=[];if(i("style.lineColor")||i("style.lineWidth")){let l=[];i("style.lineColor")&&l.push(this.swatch(e,this.t(r_.lineColor),()=>e.live().style.lineColor||o.lx5,"style.lineColor"));let n=t.find(e=>"style.lineWidth"===e.path);n&&((n.min??1)>1?l.push(this.number(e,this.t(r_.lineWidth),()=>e.live().style.lineWidth,"style.lineWidth",n)):l.push(this.seg(e,this.t(r_.lineWidth),[1,2,3,4].map(e=>({value:e,html:`<svg viewBox="0 0 18 14" width="18" height="14"><rect x="2" y="${7-e/2}" width="14" height="${e}" rx="${e/2}" fill="currentColor"/></svg>`,title:`${e}px`})),()=>e.live().style.lineWidth,t=>e.edit({"style.lineWidth":t})))),r.push(le(this.t(r_.line),...l))}if(i("style.lineStyle")&&r.push(le(this.t(r_.style),this.seg(e,this.t(r_.lineStyle),o.m6i.map(e=>({value:e.value,html:r8(e.value),title:this.t(e.label)})),()=>e.live().style.lineStyle,t=>e.edit({"style.lineStyle":t})))),i("style.extendLeft")&&i("style.extendRight")){let t=[{value:"none",html:r6.none,title:this.t(r_.dontExtend)},{value:"left",html:r6.left,title:this.t(r_.extendLeft)},{value:"right",html:r6.right,title:this.t(r_.extendRight)},{value:"both",html:r6.both,title:this.t(r_.extendBothWays)}];r.push(le(this.t(r_.extend),this.seg(e,this.t(r_.extend),t,()=>{let{extendLeft:t,extendRight:i}=e.live().style;return t&&i?"both":t?"left":i?"right":"none"},t=>e.edit({"style.extendLeft":"left"===t||"both"===t,"style.extendRight":"right"===t||"both"===t}))))}let l=[];return i("style.arrowLeft")&&l.push(this.chip(e,this.t(r_.startArrow),()=>!!e.live().style.arrowLeft,t=>e.edit({"style.arrowLeft":t}))),i("style.arrowRight")&&l.push(this.chip(e,i("style.arrowLeft")?this.t(r_.endArrow):this.t(r_.arrow),()=>!!e.live().style.arrowRight,t=>e.edit({"style.arrowRight":t}))),l.length&&r.push(le(this.t(r_.ends),lt(...l))),i("style.fillColor")&&r.push(le(this.t(r_.fill),this.swatch(e,this.t(r_.fill),()=>ez(e.live(),this.theme)??e.live().style.fillColor??o.lx5,"style.fillColor"))),!i("text.value")&&i("text.color")&&r.push(le(this.t(r_.text),...this.textStyling(e,i))),r.length?r9(null,...r):null}optionsBlock(e,t,i){let r=[],l=t.filter(e=>!(e.path.startsWith("style.")||e.path.startsWith("text.")||e.path.startsWith("frvp.")||i instanceof o.m4Q&&r0.has(e.path)||null!=i.editableLevels()&&r1.has(e.path)));for(let t=0;t<l.length;t+=1){let i=l[t],o=l[t+1],n=this.pairLabel(i,o);if(n){let l=this.fieldControl(e,i),a=this.fieldControl(e,o);l&&a&&r.push(le(n,l,a)),t+=1;continue}let a=this.fieldControl(e,i);if(!a)continue;let s=le(this.t(i.label),a),h=i.when;h&&e.watch(()=>s.hidden=!h.in.includes(ll(e.live(),h.path))),r.push(s)}let n=i.serialize().props??{},a=o.Jjx.map(e=>({value:e.value,html:this.t(e.label)}));return"numbersSize"in n&&r.push(le(this.t(r_.numbers),this.seg(e,this.t(r_.numbersSize),a,()=>e.live().serialize().props?.numbersSize??"small",t=>e.edit({numbersSize:t}),!0))),"labelsSize"in n&&r.push(le(this.t(r_.labels),this.seg(e,this.t(r_.labelsSize),a,()=>e.live().serialize().props?.labelsSize??"normal",t=>e.edit({labelsSize:t}),!0))),r.length?r9(null,...r):null}pairLabel(e,t){return"color"!==e.kind||t?.kind!=="lineStyle"&&t?.kind!=="color"?null:e.rowLabel?this.t(e.rowLabel):"string"!=typeof e.label||"string"!=typeof t.label?null:"lineStyle"===t.kind?function(e,t){let i=/^(.*) colou?r$/i.exec(e),o=/^(.*) style$/i.exec(t);return i&&o&&i[1]===o[1]?i[1]:null}(e.label,t.label):function(e,t){let i=/^Upper (.+)$/i.exec(e),o=/^Lower (.+)$/i.exec(t);if(!i||!o||i[1]!==o[1])return null;let r=i[1].replace(/ colou?r$/i,""),l=r.charAt(0).toUpperCase()+r.slice(1);return/fill$/i.test(l)?l:`${l}s`}(e.label,t.label)}fieldControl(e,t){let i=()=>ll(e.live(),t.path);switch(t.kind){case"color":return this.swatch(e,this.t(t.label),()=>i()||(t.fallback?ll(e.live(),t.fallback):void 0)||o.lx5,t.path);case"lineStyle":return this.seg(e,this.t(t.label),o.m6i.map(e=>({value:e.value,html:r8(e.value),title:this.t(e.label)})),()=>i(),i=>e.edit({[t.path]:i}));case"boolean":return this.switch(e,()=>!1!==i()&&null!=i(),i=>e.edit({[t.path]:i}));case"number":case"opacity":return this.number(e,this.t(t.label),()=>Number(i()??0),t.path,t);case"select":{let r="magnifier.timeframe"===t.path?(0,o.nTO)(this.env.chartBarMs()):t.options??[];if(0===r.length)return null;let l=r.map(e=>({value:e.value,label:this.t(e.label)})),n=(0,k.yF)({kind:"select",options:l,value:String(i()??l[0].value),fill:!1,theme:this.theme,onChange:i=>e.edit({[t.path]:i})});return e.watch(()=>n.setValue?.(String(i()??""))),n.el}case"text":return(0,k.yF)({kind:"text",value:String(i()??""),fill:!0,onChange:i=>e.edit({[t.path]:i})}).el;default:return null}}levelsBlock(e){let t=e.live(),i=[],r=document.createElement("div");r.className="vela-dsp-lv";let l=()=>JSON.stringify(e.live().editableLevels()??[]),n="",a=!1,s=t=>{a=!0;try{e.edit(t)}finally{a=!1}n=l()},h=()=>{n=l(),(0,L.X)(r),r.replaceChildren();let t=e.live()instanceof o.H9m;(e.live().editableLevels()??[]).forEach((e,i)=>{let o=document.createElement("div");o.className="vela-dsp-lv-c",o.toggleAttribute("data-off",!e.enabled);let l=(0,k.yF)({kind:"switch",checked:e.enabled,onChange:e=>{o.toggleAttribute("data-off",!e),s({[`levels.${i}.enabled`]:e})}}),n=e.ratio,a=(0,k.yF)({kind:"number",value:e.ratio,min:t?void 0:0,step:.01,compact:!0,fill:!1,commit:"blur",title:this.t(r_.level,{n:i+1}),onChange:e=>{if(!Number.isFinite(e)||!t&&e<=0)return void a.setValue?.(n);n=e,s({[`levels.${i}.ratio`]:e})}}),h=e.color,d=(0,k.yF)({kind:"color",theme:this.theme,title:this.t(r_.levelColor,{n:i+1}),get:()=>h,onChange:e=>{h=e,s({[`levels.${i}.color`]:e})}});o.append(l.el,a.el,d.el),r.appendChild(o)})};if(e.watch(()=>{a||l()===n||r.contains(document.activeElement)||h()}),t instanceof o.Gcb&&i.push(this.seg(e,this.t(r_.levelSet),o.t_5.map(e=>({value:e.key,html:this.t(e.label)})),()=>{let t=e.live();return(0,o.SKP)(t.levels,t.reverse)??void 0},t=>{let i=o.t_5.find(e=>e.key===t);e.edit({levels:V(i.levels),reverse:i.reverse})},!0)),t instanceof o.sLj&&i.push(le(this.t(r_.ratios),this.switch(e,()=>!1!==e.live().showRatios,t=>e.edit({showRatios:t})))),i.push(r),t instanceof o.H9m){let r=()=>e.live(),l=[this.chip(e,this.t(r_.ratios),()=>r().showRatios,t=>e.edit({showRatios:t})),this.chip(e,this.t(r_.prices),()=>r().showPrices,t=>e.edit({showPrices:t})),this.chip(e,this.t(r_.background),()=>r().background,t=>e.edit({background:t}))];t instanceof o.Gcb&&l.push(this.chip(e,this.t(r_.reverse),()=>e.live().reverse,t=>e.edit({reverse:t}))),i.push(le(this.t(r_.show),lt(...l))),i.push(le(this.t(r_.labelSide),this.seg(e,this.t(r_.labelSide),[{value:"left",html:this.t(r_.left)},{value:"right",html:this.t(r_.right)}],()=>r().labelSide,t=>e.edit({labelSide:t}))))}return r9(this.t(r_.levels),...i)}richBlock(e,t){let i=(0,k.lb)({variant:"inputs"});return i.classList.add("vela-dsp-grid"),t(i),r9(e,i)}textContentBlock(e,t){return r9(null,this.textArea(e,this.t(r_.text),3),le(this.t(r_.style),...this.textStyling(e,t)))}textFold(e,t){let i=e.live().type,r=()=>e.live().text?.value?.trim()??"",l=()=>{if(!t("text.value")){var i;return this.t((i=e.live().text?.size,o.Jjx.find(e=>e.value===(i??"normal"))?.label??r_.normal))}let l=r();return l?`“${l.split("\n")[0]}”`:this.t(r_.none)};return this.fold(e,"text",t("text.value")?this.t(r_.label):this.t(r_.text),l,()=>{let o=[];if(t("text.value")&&o.push(this.textArea(e,this.t(r_.addALabel),1)),o.push(le(this.t(r_.style),...this.textStyling(e,t))),rQ.has(i)&&t("text.value")){let t=le(this.t(r_.place),this.seg(e,this.t(r_.positionAlongTheLine),[{value:"start",html:this.t(r_.start)},{value:"middle",html:this.t(r_.middle)},{value:"end",html:this.t(r_.end)}],()=>e.live().text?.place??"middle",t=>e.edit({"text.place":t}),!0)),i=le(this.t(r_.side),this.seg(e,this.t(r_.sideOfTheLine),[{value:"above",html:this.t(r_.above)},{value:"below",html:this.t(r_.below)}],()=>e.live().text?.side??"above",t=>e.edit({"text.side":t}),!0));e.watch(()=>t.hidden=i.hidden=""===r()),o.push(t,i)}return o})}textArea(e,t,i){let o=new I.fs({value:e.live().text?.value??"",rows:i,size:"sm",autoGrow:!0,maxLines:6,placeholder:t,onChange:t=>e.edit({"text.value":t})});return o.input.addEventListener("keydown",e=>{"Escape"!==e.key&&e.stopPropagation()}),e.watch(()=>{let t=e.live().text?.value??"";document.activeElement!==o.input&&o.input.value!==t&&(o.input.value=t)}),o.el.style.width="100%",o.el}textStyling(e,t){let i=[];if(t("text.color")&&i.push(this.swatch(e,this.t(r_.textColor),()=>e.live().text?.color||this.theme.textColor,"text.color")),t("text.size")){let t=(0,k.yF)({kind:"select",options:o.Jjx.map(e=>({value:e.value,label:this.t(e.label)})),value:e.live().text?.size??"normal",fill:!1,theme:this.theme,onChange:t=>e.edit({"text.size":t})});e.watch(()=>t.setValue?.(e.live().text?.size??"normal")),i.push(t.el)}let r=[];return t("text.bold")&&r.push(this.chip(e,"B",()=>!!e.live().text?.bold,t=>e.edit({"text.bold":t}),this.t(r_.bold))),t("text.italic")&&r.push(this.chip(e,"I",()=>!!e.live().text?.italic,t=>e.edit({"text.italic":t}),this.t(r_.italic))),r.length&&i.push(lt(...r)),i}pointsFold(e){let t=e.live();if(rJ.has(t.type)||0===t.anchors.length||t.anchors.length>8)return null;let i=t.anchorSchema().slots,o=e=>i[e]?.free??i[i.length-1]?.free??"both",r=t.anchors.map((e,t)=>t).filter(e=>"none"!==o(e));if(0===r.length)return null;let l=r.filter(e=>"x"!==o(e)),n=e=>{let t=this.env.priceDecimals()??Math.max(2,oN(e));return Number(e.toFixed(Math.min(t,10)))},a=()=>{let t=e.live().anchors;if(l.length)return l.map(e=>String(n(t[e]?.price??0))).join(" → ");let i=t[r[0]]?.time;return 1===r.length&&null!=i?oY(i,this.env.timeZone(),this.env.chartBarMs()):this.t(r_.pointCount,{count:r.length})};return this.fold(e,"points",this.t(r_.points),a,()=>r.map((i,l)=>{let a=1===r.length?this.t("x"===o(i)?r_.pointTime:r_.pointPrice):String.fromCharCode(65+l),s=document.createElement("div");s.className="vela-dsp-pt";let h=document.createElement("span");if(h.className="vela-dsp-pt-k",h.textContent=a,s.appendChild(h),"x"!==o(i)){let o=(0,k.yF)({kind:"number",value:n(t.anchors[i].price),fill:!0,commit:"blur",title:this.t(r_.pointPriceTitle,{point:a}),onChange:t=>e.edit({[`anchors.${i}.price`]:t})}),r=o.el.querySelector("input");e.watch(()=>{document.activeElement!==r&&o.setValue?.(n(e.live().anchors[i]?.price??0))}),s.appendChild(o.el)}else s.appendChild(document.createElement("span"));let d=document.createElement("span");return d.className="vela-dsp-pt-t",e.watch(()=>{let t=e.live().anchors[i]?.time;d.textContent=null!=t?oY(t,this.env.timeZone(),this.env.chartBarMs()):""}),s.appendChild(d),s}))}showOnFold(e){let t=()=>e.live().showOn,i=!1,r=()=>i&&t()?"custom":function(e){if(!e)return"all";let t=t=>t.length===e.length&&t.every(t=>e.includes(t));return t(r2)?"intraday":t(r5)?"higher":"custom"}(t()),l=(0,o.lTI)(this.env.chartBarMs()),n=()=>{let e=t();return e?"intraday"===r()?this.t(r_.intraday):"higher"===r()?this.t(r_.n1HAndUp):0===e.length?this.t(r_.nowhere):e.map(e=>{let t=o.uD5.find(t=>t.key===e);return t?this.t(t.label):e}).join(", "):this.t(r_.allTimeframes)};return this.fold(e,"show",this.t(r_.showOn),n,()=>{let n=t=>e.edit({showOn:t}),a=this.seg(e,this.t(r_.showOn),[{value:"all",html:this.t(r_.all)},{value:"intraday",html:this.t(r_.intraday)},{value:"higher",html:this.t(r_.n1HAndUp)},{value:"custom",html:this.t(r_.custom)}],r,e=>{i="custom"===e,"all"===e?n(void 0):"intraday"===e?n([...r2]):"higher"===e?n([...r5]):n([...t()??o.uD5.map(e=>e.key)])},!0),s=document.createElement("div");for(let i of(s.className="vela-dsp-tf",o.uD5)){let r=document.createElement("button");r.type="button",r.textContent=this.t(i.label),i.key===l&&(r.dataset.here="",r.title=this.t(r_.chartTimeframe)),r.addEventListener("click",()=>{let e=new Set(t()??[]);e.has(i.key)?e.delete(i.key):e.add(i.key),n(o.uD5.map(e=>e.key).filter(t=>e.has(t)))}),e.watch(()=>r.setAttribute("aria-pressed",String(t()?.includes(i.key)??!0))),s.appendChild(r)}let h=document.createElement("div");return h.className="vela-dsp-note",e.watch(()=>{s.hidden="custom"!==r();let e=t();h.hidden=!(null!=e&&null!=l&&!e.includes(l)),h.textContent=e?.length===0?this.t(r_.hiddenOnEveryTimeframe):this.t(r_.hiddenOnThisTimeframe)}),[a,s,h]})}styleMenuButton(e){let t=document.createElement("button");t.type="button",t.className="vela-dsp-style",t.setAttribute("aria-haspopup","menu"),t.setAttribute("aria-expanded","false");let i=document.createElement("span"),o=document.createElement("span");o.style.display="flex",o.innerHTML='<svg viewBox="0 0 12 12" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m2.5 4.5 3.5 3.5 3.5-3.5"/></svg>',t.append(i,o);let r=()=>[...eO(e.live().type),...e.actions.templates?.()??[]],l=()=>{let o=r().filter(t=>ln(e.live(),t.settings)).pop();i.textContent=o?this.templateName(o):this.t(r_.style),t.title=o?this.t(r_.styleTitle,{name:this.templateName(o)}):this.t(r_.styles)};return t.addEventListener("pointerdown",e=>e.stopPropagation()),t.addEventListener("click",i=>{if(i.stopPropagation(),this.menu)return void this.menu.hide();this.openStyleMenu(t,e,r,l)}),l(),{el:t,refresh:l}}openStyleMenu(e,t,i,o){(0,f.$b)();let r=this.theme,l=new f.AM({trigger:e,host:this.host,theme:r,position:"absolute",collisionBoundary:this.host,boundaryInset:4,viewportInset:0,sideOffset:6,align:"end",zIndex:6e3,onClose:()=>{t.actions.preview?.(null),e.setAttribute("aria-expanded","false"),this.menu===l&&(this.menu=null)}}),n=l.el;n.classList.add("vela-dsp-menu"),n.setAttribute("role","menu"),n.style.cssText+=`background:${r.background};border:1px solid var(--vela-border);border-radius:var(--vela-radius-lg);box-shadow:var(--vela-shadow);color:${r.textColor};font:13px ${r.fontFamily};pointer-events:auto;`,e$(n,r);let a=()=>{n.replaceChildren();let e=eO(t.live().type),i=t.actions.templates?.()??[],r=(e,i)=>{var r;let n=document.createElement("button");n.type="button",n.className="vela-dsp-mi",n.setAttribute("role","menuitem"),ln(t.live(),e.settings)&&(n.dataset.current="");let s=document.createElement("span");s.className="vela-dsp-mi-dot",s.style.background=(r=e.settings,r.style?.lineColor??r.style?.fillColor??r.text?.color??"transparent");let h=document.createElement("span");if(h.className="vela-dsp-mi-t",h.textContent=this.templateName(e),n.append(s,h),i){let i=document.createElement("span");i.className="vela-dsp-mi-x",i.setAttribute("role","button"),i.setAttribute("aria-label",this.t(r_.deleteStyle,{name:this.templateName(e)})),i.innerHTML='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><path d="m4.5 4.5 7 7M11.5 4.5l-7 7"/></svg>',i.addEventListener("click",i=>{i.stopPropagation(),t.actions.preview?.(null),t.actions.removeTemplate?.(e.name),a(),o()}),n.appendChild(i)}return n.addEventListener("pointerenter",()=>t.actions.preview?.(e.settings)),n.addEventListener("pointerleave",()=>t.actions.preview?.(null)),n.addEventListener("click",()=>{t.actions.preview?.(null),t.actions.applyToolSettings?.(e.settings),l.hide(),t.rebuild()}),n};if(e.length)for(let t of(n.appendChild(li(this.t(r_.presets))),e))n.appendChild(r(t,!1));if(i.length)for(let e of(n.appendChild(li(this.t(r_.saved))),i))n.appendChild(r(e,!0));(e.length||i.length)&&n.appendChild(function(){let e=document.createElement("div");return e.className="vela-dsp-msep",e}()),t.actions.saveTemplate&&n.appendChild(this.saveRow(t,a,o));let s=document.createElement("button");s.type="button",s.className="vela-dsp-mi",s.setAttribute("role","menuitem"),s.appendChild(lr(this.t(r_.resetToDefault))),s.addEventListener("click",()=>{t.actions.resetSettings(),l.hide(),t.rebuild()}),n.appendChild(s)};a(),e.setAttribute("aria-expanded","true"),this.menu=l,l.show()}templateName(e){return e.label?this.t(e.label):e.name}saveRow(e,t,i){let o=document.createElement("div"),r=document.createElement("button");return r.type="button",r.className="vela-dsp-mi",r.setAttribute("role","menuitem"),r.appendChild(lr(this.t(r_.saveAsStyle))),r.addEventListener("click",r=>{r.stopPropagation();let l=document.createElement("div");l.className="vela-dsp-mname";let n=document.createElement("input");n.type="text",n.placeholder=this.t(r_.styleName),n.maxLength=60,n.setAttribute("aria-label",this.t(r_.styleName));let a=lo(this.t(r_.save),!0,()=>s());a.style.height="28px";let s=()=>{let o=n.value.trim();o&&(e.actions.saveTemplate?.(o),t(),i())};n.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&s(),"Escape"===e.key&&t()}),l.append(n,a),o.replaceChildren(l),n.focus()}),o.appendChild(r),o}fold(e,t,i,o,r){let l=e.live().type,n=r3.get(l)??new Set;r3.set(l,n);let a=document.createElement("div");a.className="vela-dsp-fold";let s=document.createElement("button");s.type="button",s.className="vela-dsp-fold-h";let h=document.createElement("span");h.className="vela-dsp-fold-t",h.textContent=i;let d=document.createElement("span");d.className="vela-dsp-fold-s";let c=document.createElement("span");c.className="vela-dsp-chev",c.innerHTML='<svg viewBox="0 0 12 12" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m4.5 2.5 3.5 3.5-3.5 3.5"/></svg>',s.append(h,d,c);let p=document.createElement("div");p.className="vela-dsp-fold-b";let u=!1,g=e=>{e?n.add(t):n.delete(t),a.toggleAttribute("data-open",e),s.setAttribute("aria-expanded",String(e)),e&&!u&&(u=!0,p.append(...r()))};return s.addEventListener("click",()=>g(!n.has(t))),e.watch(()=>d.textContent=o()),g(n.has(t)),a.append(s,p),a}seg(e,t,i,o,r,l=!1){let n=document.createElement("div");n.className="vela-dsp-seg",n.setAttribute("role","group"),n.setAttribute("aria-label",t),l&&(n.dataset.full="");let a=i.map(e=>{let t=document.createElement("button");return t.type="button",t.innerHTML=e.html,e.title&&(t.title=e.title,t.setAttribute("aria-label",e.title)),t.addEventListener("click",()=>{r(e.value),s()}),n.appendChild(t),t}),s=()=>{let e=o();i.forEach((t,i)=>a[i].setAttribute("aria-pressed",String(t.value===e)))};return e.watch(s),n}chip(e,t,i,o,r){let l=document.createElement("button");return l.type="button",l.className="vela-dsp-chip",l.textContent=t,r&&(l.title=r,l.setAttribute("aria-label",r)),"B"===t&&(l.style.fontWeight="700"),"I"===t&&(l.style.fontStyle="italic"),l.addEventListener("click",()=>o(!i())),e.watch(()=>l.setAttribute("aria-pressed",String(i()))),l}swatch(e,t,i,o){return(0,k.yF)({kind:"color",theme:this.theme,title:t,get:i,onChange:t=>e.edit({[o]:t})}).el}switch(e,t,i){let o=(0,k.yF)({kind:"switch",checked:t(),onChange:i});e.watch(()=>o.setValue?.(t()));let r=document.createElement("div");return r.style.cssText="display:flex;flex:1;justify-content:flex-end;",r.appendChild(o.el),r}number(e,t,i,o,r){let l=r.step??1,n=(0,k.yF)({kind:"number",value:i(),min:r.min,max:r.max,step:l,integer:l>=1&&Number.isInteger(l),fill:!1,commit:"blur",title:t,onChange:t=>e.edit({[o]:t})}),a=n.el.querySelector("input");return e.watch(()=>{document.activeElement!==a&&n.setValue?.(i())}),n.el}};function r9(e,...t){let i=document.createElement("div");if(i.className="vela-dsp-block",e){let t=document.createElement("div");t.className="vela-dsp-h",t.textContent=e,i.appendChild(t)}return i.append(...t),i}function le(e,...t){let i=document.createElement("div");i.className="vela-dsp-row";let o=document.createElement("span");return o.className="vela-dsp-lab",o.textContent=e,o.title=e,i.append(o,...t),i}function lt(...e){let t=document.createElement("div");return t.className="vela-dsp-chips",t.append(...e),t}function li(e){let t=document.createElement("div");return t.className="vela-dsp-mh",t.textContent=e,t}function lo(e,t,i){return(0,y.Tf)({text:e,variant:t?"default":"outline",size:"sm",onClick:i}).el}function lr(e){let t=document.createElement("span");return t.className="vela-dsp-mi-t",t.textContent=e,t}function ll(e,t){let i=e;for(let e of t.split(".")){if(null==i||"object"!=typeof i)return;i=i[e]}return i}function ln(e,t){let i=(e,t)=>JSON.stringify(e??null)===JSON.stringify(t??null),o=e.style;for(let[e,r]of Object.entries(t.style??{}))if(!i(o[e],r))return!1;let r=e.text??{};for(let[e,o]of Object.entries(t.text??{}))if(!i(r[e],o))return!1;let l=e.serialize().props??{};for(let[e,o]of Object.entries(t.props??{}))if(!i(l[e],o))return!1;return Object.keys(t.style??{}).length+Object.keys(t.text??{}).length+Object.keys(t.props??{}).length>0}var la={icon:(0,n.ab)("drawing.bar.icon","Icon"),iconSize:(0,n.ab)("drawing.bar.iconSize","Icon size"),lowerTimeframe:(0,n.ab)("drawing.bar.lowerTimeframe","Lower timeframe"),upCandles:(0,n.ab)("drawing.bar.upCandles","Up candles"),downCandles:(0,n.ab)("drawing.bar.downCandles","Down candles"),lineColor:(0,n.ab)("drawing.bar.lineColor","Line color"),lineWidth:(0,n.ab)("drawing.bar.lineWidth","Line width"),lineStyle:(0,n.ab)("drawing.bar.lineStyle","Line style"),fill:(0,n.ab)("drawing.bar.fill","Fill"),profitZone:(0,n.ab)("drawing.bar.profitZone","Profit zone"),lossZone:(0,n.ab)("drawing.bar.lossZone","Loss zone"),midlineColor:(0,n.ab)("drawing.bar.midlineColor","Midline color"),midlineStyle:(0,n.ab)("drawing.bar.midlineStyle","Midline style"),upperLineColor:(0,n.ab)("drawing.bar.upperLineColor","Upper line color"),upperLineStyle:(0,n.ab)("drawing.bar.upperLineStyle","Upper line style"),lowerLineColor:(0,n.ab)("drawing.bar.lowerLineColor","Lower line color"),lowerLineStyle:(0,n.ab)("drawing.bar.lowerLineStyle","Lower line style"),upperFill:(0,n.ab)("drawing.bar.upperFill","Upper fill"),lowerFill:(0,n.ab)("drawing.bar.lowerFill","Lower fill"),showRSquared:(0,n.ab)("drawing.bar.showRSquared","Show R\xb2"),vwapColor:(0,n.ab)("drawing.bar.vwapColor","VWAP color"),vwapStyle:(0,n.ab)("drawing.bar.vwapStyle","VWAP style"),bandMultiplier:(0,n.ab)("drawing.bar.bandMultiplier","Band multiplier"),upperBandColor:(0,n.ab)("drawing.bar.upperBandColor","Upper band color"),lowerBandColor:(0,n.ab)("drawing.bar.lowerBandColor","Lower band color"),bandFill:(0,n.ab)("drawing.bar.bandFill","Band fill"),maxCurvature:(0,n.ab)("drawing.bar.maxCurvature","Max curvature"),machNumber:(0,n.ab)("drawing.bar.machNumber","Mach number"),waves:(0,n.ab)("drawing.bar.waves","Waves"),showPrice:(0,n.ab)("drawing.bar.showPrice","Show price"),showDate:(0,n.ab)("drawing.bar.showDate","Show date"),textColor:(0,n.ab)("drawing.bar.textColor","Text color"),textSize:(0,n.ab)("drawing.bar.textSize","Text size"),bold:(0,n.ab)("drawing.bar.bold","Bold"),italic:(0,n.ab)("drawing.bar.italic","Italic"),text:(0,n.ab)("drawing.bar.text","Text"),numbersSize:(0,n.ab)("drawing.bar.numbersSize","Numbers size"),labelSize:(0,n.ab)("drawing.bar.labelSize","Label size"),settings:(0,n.ab)("drawing.bar.settings","Settings"),lock:(0,n.ab)("drawing.bar.lock","Lock"),delete:(0,n.ab)("drawing.bar.delete","Delete"),label:(0,n.ab)("drawing.bar.label","Label…"),more:(0,n.ab)("drawing.bar.more","More"),duplicate:(0,n.ab)("drawing.bar.duplicate","Duplicate"),bringToFront:(0,n.ab)("drawing.bar.bringToFront","Bring to front"),sendToBack:(0,n.ab)("drawing.bar.sendToBack","Send to back"),resetSettings:(0,n.ab)("drawing.bar.resetSettings","Reset settings"),noLowerTimeframeAvailable:(0,n.ab)("drawing.bar.noLowerTimeframeAvailable","No lower timeframe available"),inUse:(0,n.ab)("drawing.bar.inUse","In use")},ls=Symbol("mixed"),lh="vela-drawing-popup-styles";function ld(){if("undefined"==typeof document)return;let e=document.getElementById(lh);if(e?.dataset.rev==="4")return;let t=e??document.createElement("style");t.id=lh,t.dataset.rev="4",t.textContent=(0,d.AH)`@layer vela.chrome {
286
+
287
+ .vela-dpop-btn{background:transparent;color:${c.t.fg.muted};transition:background ${c.t.dur.fast} ease,color ${c.t.dur.fast} ease;}
288
+ .vela-dpop-btn:hover{background:${c.t.hover.strong};color:${c.t.fg.bright};}
289
+ .vela-dpop-btn[data-active='1']{background:${c.t.active};color:${c.t.fg.bright};}
290
+ /* Mixed (a multi-selection disagrees): the active fill at half strength behind a dashed ring. */
291
+ .vela-dpop-btn[data-active='mixed']{background:${c.t.hover.strong};color:${c.t.fg.bright};outline:1px dashed ${c.t.fg.muted};outline-offset:-2px;}
292
+ .vela-dpop-item{background:transparent;transition:background ${c.t.dur.fast} ease;}
293
+ .vela-dpop-item:hover{background:${c.t.hover.strong};}
294
+ .vela-dpop-item[data-active='1']{background:${c.t.active};}
295
+ /* A finger needs a wider grab zone than a cursor — grow the move handle on touch-first
296
+ devices (the glyph stays centered; only the hit target widens). */
297
+ @media (pointer: coarse){.vela-dpop-grip{width:${44}px !important;}}
298
+ }`,e||document.head.appendChild(t)}var lc=class{constructor(e,t,i={}){this.host=e,this.el=null,this.tipEl=null,this.textPanel=null,this.current=null,this.colorPop=null,this.colorOwner=null,this.menuPop=null,this.menuOwner=null,this.onClose=null,this.onOutside=e=>{let t=e.target;if(this.panel.isOpen()){if(this.panel.contains(t)||this.isOwnChrome(t)||this.host.contains(t))return;this.panel.close();return}if(this.isOwnChrome(t))return;let i=this.onClose;this.close(),i?.(e)},this.theme=t,this.chartBarMs=i.chartBarMs??(()=>0),this.i18n=i.i18n??null,this.panel=new r7(e,t,{chartBarMs:this.chartBarMs,timeZone:i.timeZone??(()=>"UTC"),priceDecimals:i.priceDecimals??(()=>null),...i.i18n?{i18n:i.i18n}:{}})}t(e,t){return(0,n.b6)(this.i18n?.()??null,e,t)}sizeLabel(e){let t=o.Jjx.find(t=>t.value===e);return t?this.t(t.label):lD(String(e))}styleLabel(e){let t=o.m6i.find(t=>t.value===e);return t?this.t(t.label):lD(String(e))}setTheme(e){this.theme=e,this.panel.setTheme(e)}isOpen(){return null!=this.el}contains(e){return null!=e&&(this.isOwnChrome(e)||this.panel.contains(e))}openPanel(){let e=this.current;return!!e&&(this.hideTip(),this.closeColorPopover(),this.closeMenu(),this.panel.open(e.drawing,e.actions,e.anchor,this.barBox()),!0)}barBox(){if(!this.el)return null;let e=this.host.getBoundingClientRect(),t=this.el.getBoundingClientRect();return 0===t.width&&0===t.height?null:{x:t.left-e.left,y:t.top-e.top,w:t.width,h:t.height}}syncPanel(){this.panel.sync()}open(e,t,i,r){let n=e[0],a=this.panel.isOpen()&&1===e.length&&null!=n&&this.current?.drawing.id===n.id;if(this.close(a),!n)return;this.current=1===e.length?{drawing:n,actions:i,anchor:t}:null,ld(),this.onClose=r??null;let s=this.theme,h=e.length>1,d=n.schema(),c=function(e){let[t,...i]=e,o=new Set(t?.schema().fields.map(e=>e.path)??[]);for(let e of i){let t=new Set(e.schema().fields.map(e=>e.path));for(let e of o)t.has(e)||o.delete(e)}return o}(e),p=t=>(function(e,t){let i=t(e[0]);return e.every(e=>t(e)===i)?i:ls})(e,t),u=t=>e.every(t),g=(t,o,r,l)=>this.colorButton(t,o,p(r),e=>i.patch({[l]:e}),void 0,[...new Set(e.map(r))]),m=h||!0===d.textIsContent||!c.has("text.value"),b=document.createElement("div");b.className="vela-dpop",b.style.cssText=`position:absolute;z-index:22;background:${s.background};border:1px solid var(--vela-border);border-radius:var(--vela-radius-lg);box-shadow:var(--vela-shadow);color:${s.textColor};font:var(--vela-font-size-md) ${s.fontFamily};display:flex;flex-direction:column;pointer-events:auto;overflow:hidden;`,e$(b,s),b.addEventListener("pointerdown",e=>{let t=e.target;t?.closest(".vela-select-trigger, .vela-color-field")||(0,f.$b)()});let v=document.createElement("div");if(v.style.cssText="display:flex;align-items:center;gap:2px;padding:4px;",v.appendChild(this.dragHandle()),c.has("glyph")){let e=p(e=>e.glyph??o.KIE[0]);v.appendChild(this.dropdown(this.t(la.icon),o.KIE,e,e=>lN(String(e),15),e=>i.patch({glyph:e})))}if(c.has("size")){let e=p(e=>e.size??"normal");v.appendChild(this.dropdown(this.t(la.iconSize),o.j97,e,e=>lN("●",(lz[String(e)]??13)+4),e=>i.patch({size:e}),{label:e=>this.sizeLabel(e)}))}if(c.has("magnifier.timeframe")&&u(e=>e instanceof o.NvN)){let e=(0,o.nTO)(this.chartBarMs());e.length>0&&v.appendChild(this.dropdown(this.t(la.lowerTimeframe),e.map(e=>e.value),p(e=>e.magnifier.timeframe),()=>"",e=>i.patch({"magnifier.timeframe":e}),{label:e=>this.t((0,o.HkK)(String(e))),labelInTrigger:!0})),v.appendChild(g(this.t(la.upCandles),lu,e=>e.magnifier.upColor||s.upColor,"magnifier.upColor")),v.appendChild(g(this.t(la.downCandles),lu,e=>e.magnifier.downColor||s.downColor,"magnifier.downColor"))}if(c.has("style.lineColor")&&v.appendChild(g(this.t(la.lineColor),lp,e=>e.style.lineColor||(e instanceof o.NvN?oS(this.theme.background):o.lx5),"style.lineColor")),c.has("style.lineWidth")){let e=e=>e.schema().fields.find(e=>"style.lineWidth"===e.path),t=e(n),o=p(e=>e.style.lineWidth);u(t=>{let i=e(t);return i?.kind==="number"&&(i.min??1)>1})&&t?.kind==="number"?v.appendChild(this.widthInput(this.t(la.lineWidth),o,t.min??1,t.max??60,t.step??1,e=>i.patch({"style.lineWidth":e}))):v.appendChild(this.dropdown(this.t(la.lineWidth),[1,2,3,4],o,e=>lR(e,"solid"),e=>i.patch({"style.lineWidth":e}),{label:e=>`${e}px`,labelInTrigger:!0}))}if(c.has("style.lineStyle")&&v.appendChild(this.dropdown(this.t(la.lineStyle),o.m6i.map(e=>e.value),p(e=>e.style.lineStyle),e=>lR(2,e),e=>i.patch({"style.lineStyle":e}),{label:e=>this.styleLabel(e)})),c.has("style.fillColor")&&v.appendChild(g(this.t(la.fill),lu,e=>ez(e,this.theme)??e.style.fillColor??o.lx5,"style.fillColor")),c.has("riskPercent")&&u(e=>e instanceof o.m4Q)&&(v.appendChild(g(this.t(la.profitZone),lu,e=>e.profitColor,"profitColor")),v.appendChild(g(this.t(la.lossZone),lu,e=>e.lossColor,"lossColor"))),c.has("reg.midColor")&&u(e=>null!=e.reg)){let e=o.m6i.map(e=>e.value);v.appendChild(g(this.t(la.midlineColor),lp,e=>e.reg.midColor,"reg.midColor")),v.appendChild(this.dropdown(this.t(la.midlineStyle),e,p(e=>e.reg.midStyle),e=>lR(2,e),e=>i.patch({"reg.midStyle":e}),{label:e=>this.styleLabel(e)})),v.appendChild(g(this.t(la.upperLineColor),lp,e=>e.reg.upperColor,"reg.upperColor")),v.appendChild(this.dropdown(this.t(la.upperLineStyle),e,p(e=>e.reg.upperStyle),e=>lR(2,e),e=>i.patch({"reg.upperStyle":e}),{label:e=>this.styleLabel(e)})),v.appendChild(g(this.t(la.lowerLineColor),lp,e=>e.reg.lowerColor,"reg.lowerColor")),v.appendChild(this.dropdown(this.t(la.lowerLineStyle),e,p(e=>e.reg.lowerStyle),e=>lR(2,e),e=>i.patch({"reg.lowerStyle":e}),{label:e=>this.styleLabel(e)})),v.appendChild(g(this.t(la.upperFill),lu,e=>e.reg.upperFill,"reg.upperFill")),v.appendChild(g(this.t(la.lowerFill),lu,e=>e.reg.lowerFill,"reg.lowerFill")),v.appendChild(this.toggle(this.t(la.showRSquared),lI,p(e=>e.reg.showR2),e=>i.patch({"reg.showR2":e})))}if(c.has("vwap.midColor")&&u(e=>null!=e.vwap)){let e=o.m6i.map(e=>e.value);v.appendChild(g(this.t(la.vwapColor),lp,e=>e.vwap.midColor,"vwap.midColor")),v.appendChild(this.dropdown(this.t(la.vwapStyle),e,p(e=>e.vwap.midStyle),e=>lR(2,e),e=>i.patch({"vwap.midStyle":e}),{label:e=>this.styleLabel(e)})),v.appendChild(this.dropdown(this.t(la.bandMultiplier),[.5,1,1.5,2,2.5,3,4,5],p(e=>e.vwap.multiplier),()=>lE,e=>i.patch({"vwap.multiplier":e}),{label:e=>`${e}σ`,labelInTrigger:!0})),v.appendChild(g(this.t(la.upperBandColor),lp,e=>e.vwap.upperColor,"vwap.upperColor")),v.appendChild(g(this.t(la.lowerBandColor),lp,e=>e.vwap.lowerColor,"vwap.lowerColor")),v.appendChild(g(this.t(la.bandFill),lu,e=>e.vwap.bandFill,"vwap.bandFill"))}if(c.has("maxCurvature")){let e=p(e=>e.maxCurvature??24);v.appendChild(this.dropdown(this.t(la.maxCurvature),o.cRd,e,()=>lB,e=>i.patch({maxCurvature:e}),{label:e=>`n=${e}`,labelInTrigger:!0}))}if(c.has("mach")){let e=p(e=>e.mach??2);v.appendChild(this.dropdown(this.t(la.machNumber),o.Bgg,e,()=>lO,e=>i.patch({mach:e}),{label:e=>`M=${e}`,labelInTrigger:!0}))}if(c.has("waveCount")){let e=p(e=>e.waveCount??6);v.appendChild(this.dropdown(this.t(la.waves),o.vZR,e,()=>lF,e=>i.patch({waveCount:e}),{label:e=>`${e}`,labelInTrigger:!0}))}c.has("showPrice")&&v.appendChild(this.toggle(this.t(la.showPrice),lm,p(e=>!1!==e.showPrice),e=>i.patch({showPrice:e}))),c.has("showDate")&&v.appendChild(this.toggle(this.t(la.showDate),lb,p(e=>!1!==e.showDate),e=>i.patch({showDate:e}))),c.has("text.color")&&m&&v.appendChild(g(this.t(la.textColor),lg,e=>e.text?.color||s.textColor,"text.color")),c.has("text.size")&&m&&v.appendChild(this.dropdown(this.t(la.textSize),o.Jjx.map(e=>e.value),p(e=>e.text?.size??"normal"),e=>lV(e),e=>i.patch({"text.size":e}),{label:e=>this.sizeLabel(e)}));let y=!h&&c.has("text.value");if(c.has("text.bold")&&!y&&v.appendChild(this.toggle(this.t(la.bold),lx,p(e=>!!e.text?.bold),e=>i.patch({"text.bold":e}))),c.has("text.italic")&&!y&&v.appendChild(this.toggle(this.t(la.italic),lk,p(e=>!!e.text?.italic),e=>i.patch({"text.italic":e}))),y&&v.appendChild(this.iconBtn(this.t(la.text),lg,()=>this.toggleTextPanel(n,i,!m))),n.editableLevels()&&u(e=>null!=e.editableLevels()&&!(e instanceof o.sLj))){let e=o.Jjx.map(e=>e.value);v.appendChild(this.dropdown(this.t(la.numbersSize),e,p(e=>e.numbersSize??"small"),e=>lN("12",(lz[String(e)]??13)-1,16.5,'font-weight="600"'),e=>i.patch({numbersSize:e}),{label:e=>this.sizeLabel(e)})),v.appendChild(this.dropdown(this.t(la.labelSize),e,p(e=>e.labelsSize??"normal"),e=>lV(e),e=>i.patch({labelsSize:e}),{label:e=>this.sizeLabel(e)}))}if(v.appendChild(this.divider()),!h)for(let e of i.extras?.()??[]){if(!e.toolbar)continue;let t=this.iconBtn(e.label,(0,l.Kk)(e.icon),()=>e.run());t.setAttribute("aria-label",e.label),t.dataset.drawingAction=e.id,v.appendChild(t)}h||v.appendChild(this.iconBtn(this.t(la.settings),lA,()=>this.openPanel())),v.appendChild(this.toggle(this.t(la.lock),lf,p(e=>e.locked),e=>i.setLocked(e),lv));let w=this.iconBtn(this.t(la.delete),lC,()=>i.remove());w.style.color="var(--vela-danger)",v.appendChild(w),v.appendChild(this.kebabButton(i)),b.append(v),this.host.appendChild(b),this.el=b,b.addEventListener("mouseover",e=>{let t=e.target.closest("[data-tip]");t?this.showTip(t):this.hideTip()}),b.addEventListener("mouseleave",()=>this.hideTip()),this.position(t),setTimeout(()=>document.addEventListener("pointerdown",this.onOutside),0)}close(e=!1){document.removeEventListener("pointerdown",this.onOutside),this.closeColorPopover(),this.closeMenu(),this.hideTip(),e||this.panel.close(),(0,L.X)(this.el),this.el?.remove(),this.el=null,this.textPanel=null,this.onClose=null,this.current=null}destroy(){this.close()}isOwnChrome(e){if(this.el?.contains(e)||this.colorPop?.el.contains(e)||this.menuPop?.el.contains(e))return!0;let t=e instanceof Element?e:e.parentElement;if(!t)return!1;let i=t.closest(".vela-popover");return null!=i&&this.host.contains(i)}toggleTextPanel(e,t,i){if(this.textPanel){(0,L.X)(this.textPanel),this.textPanel.remove(),this.textPanel=null,this.reposition();return}let r=(t.resolve()??e).text,l=document.createElement("div");l.style.cssText="padding:6px;border-top:1px solid var(--vela-border);display:flex;flex-direction:column;gap:4px;";let n=new I.fs({value:r?.value??"",rows:1,size:"sm",autoGrow:!0,maxLines:4,placeholder:this.t(la.label),onChange:e=>{t.patch({"text.value":e}),this.reposition()}});n.el.style.minWidth="220px",n.input.addEventListener("input",()=>{t.patch({"text.value":n.input.value}),this.reposition()}),n.input.addEventListener("keydown",e=>{if(e.stopPropagation(),"Escape"===e.key){e.preventDefault();let t=this.onClose;this.close(),t?.()}});let a=document.createElement("div");a.style.cssText="display:flex;align-items:center;justify-content:flex-start;gap:0;transform:scale(0.8);transform-origin:left center;",i&&a.append(this.colorButton(this.t(la.textColor),lg,r?.color||this.theme.textColor,e=>t.patch({"text.color":e}),14),this.dropdown(this.t(la.textSize),o.Jjx.map(e=>e.value),r?.size??"normal",e=>lN(String(e).charAt(0).toUpperCase(),15),e=>t.patch({"text.size":e}),{label:e=>this.sizeLabel(e)})),a.append(this.toggle(this.t(la.bold),lx,!!r?.bold,e=>t.patch({"text.bold":e})),this.toggle(this.t(la.italic),lk,!!r?.italic,e=>t.patch({"text.italic":e}))),l.append(n.el,a),this.el?.appendChild(l),this.textPanel=l,this.reposition(),n.input.focus()}position(e){let t=this.el;if(!t)return;let i=this.host.getBoundingClientRect(),o=t.offsetWidth,r=t.offsetHeight,l=i.width/2-o/2,n=12;e&&(l=e.x+e.w/2-o/2,(n=e.y-r-10)<4&&(n=e.y+e.h+10)),t.style.left=`${Math.max(4,Math.min(l,i.width-o-4))}px`,t.style.top=`${Math.max(4,Math.min(n,i.height-r-4))}px`}reposition(){let e=this.el;if(!e)return;let t=this.host.getBoundingClientRect(),i=e.offsetWidth,o=e.offsetHeight,r=parseFloat(e.style.left)||0,l=parseFloat(e.style.top)||0;e.style.left=`${Math.max(4,Math.min(r,t.width-i-4))}px`,e.style.top=`${Math.max(4,Math.min(l,t.height-o-4))}px`}base(e){let t=document.createElement("button");return t.type="button",t.dataset.tip=e,t.className="vela-dpop-btn",t.style.cssText="width:30px;height:30px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:inherit;border:none;border-radius:5px;padding:0;",t}iconBtn(e,t,i){let o=this.base(e);return o.innerHTML=l$(t),o.addEventListener("click",i),o}dragHandle(){let e=document.createElement("button");return e.type="button",e.className="vela-dpop-grip",e.style.cssText="width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:transparent;border:none;padding:0;cursor:grab;touch-action:none;color:var(--vela-fg-faint);",e.innerHTML=l$(lS),e.addEventListener("pointerdown",t=>{let i=this.el;if(!i||0!==t.button)return;t.preventDefault(),t.stopPropagation(),this.hideTip(),this.closeColorPopover(),this.closeMenu();let o=this.host.getBoundingClientRect(),r=t.clientX,l=t.clientY,n=parseFloat(i.style.left)||0,a=parseFloat(i.style.top)||0;e.style.cursor="grabbing";try{e.setPointerCapture(t.pointerId)}catch{}let s=e=>{let t=i.offsetWidth,s=i.offsetHeight,h=n+(e.clientX-r),d=a+(e.clientY-l);i.style.left=`${Math.max(4,Math.min(h,o.width-t-4))}px`,i.style.top=`${Math.max(4,Math.min(d,o.height-s-4))}px`},h=()=>{e.style.cursor="grab",window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h)};window.addEventListener("pointermove",s),window.addEventListener("pointerup",h),window.addEventListener("pointercancel",h)}),e}kebabButton(e){let t=this.base(this.t(la.more));return t.innerHTML=l$(lT),t.addEventListener("pointerdown",e=>e.stopPropagation()),t.addEventListener("click",i=>{if(i.stopPropagation(),this.menuOwner===t)return void this.closeMenu();this.openActionMenu(t,[{icon:lM,label:this.t(la.duplicate),onClick:()=>e.duplicate()},{icon:ly,label:this.t(la.bringToFront),onClick:()=>e.reorder("front")},{icon:lw,label:this.t(la.sendToBack),onClick:()=>e.reorder("back")},{icon:lL,label:this.t(la.resetSettings),onClick:()=>e.resetSettings()}])}),t}hostFloat(e,t){let i=this.theme,o=new f.AM({trigger:e,host:this.host,theme:i,position:"absolute",collisionBoundary:this.host,boundaryInset:4,viewportInset:0,sideOffset:6,align:t.align??"start",zIndex:t.zIndex,onClose:()=>{this.menuPop===o&&(this.menuPop=null,this.menuOwner=null),this.colorPop===o&&(this.colorPop=null,this.colorOwner=null),(0,L.X)(o.el),t.onClose?.()}}),r=o.el;return r.style.background=i.background,r.style.border="1px solid var(--vela-border)",r.style.borderRadius="var(--vela-radius-lg)",r.style.boxShadow="var(--vela-shadow)",r.style.padding=t.padding,r.style.display="flex",r.style.flexDirection="column",r.style.gap="1px",r.style.color=i.textColor,r.style.font=`var(--vela-font-size-md) ${i.fontFamily}`,r.style.pointerEvents="auto",t.fill(r,o),o.show(),o}openMagnifierTimeframeMenu(e,t,i){ld(),(0,f.$b)();let r=(0,o.nTO)(this.chartBarMs()),l=document.createElement("div");l.style.cssText=`position:absolute;left:${e.x}px;top:${e.y}px;width:${e.w}px;height:${e.h}px;pointer-events:none;`,this.host.appendChild(l),this.menuPop=this.hostFloat(l,{zIndex:26,padding:"4px",onClose:()=>l.remove(),fill:(e,o)=>{if(0===r.length){let t=document.createElement("div");t.style.cssText="padding:6px 10px;opacity:0.65;white-space:nowrap;",t.textContent=this.t(la.noLowerTimeframeAvailable),e.appendChild(t);return}for(let l of r){let r=document.createElement("button");r.type="button",r.className="vela-dpop-item",r.dataset.active=l.value===t?"1":"0",r.style.cssText="display:flex;align-items:center;min-width:88px;padding:5px 10px;border:none;border-radius:5px;color:inherit;cursor:pointer;text-align:left;font:inherit;font-variant-numeric:tabular-nums;",r.textContent=this.t(l.label),r.addEventListener("click",e=>{e.stopPropagation(),o.hide(),i(l.value)}),e.appendChild(r)}}}),this.menuOwner=l}openActionMenu(e,t){this.menuPop=this.hostFloat(e,{align:"end",zIndex:26,padding:"4px",fill:(e,i)=>{for(let o of t){let t=document.createElement("button");t.type="button",t.className="vela-dpop-item",t.style.cssText="display:flex;align-items:center;gap:9px;min-width:150px;padding:6px 9px;border:none;border-radius:5px;color:inherit;cursor:pointer;text-align:left;font:inherit;";let r=document.createElement("span");r.style.cssText="display:flex;flex:none;width:20px;justify-content:center;",r.innerHTML=l$(o.icon,18);let l=document.createElement("span");l.textContent=o.label,l.style.cssText="flex:1;",t.append(r,l),t.addEventListener("click",e=>{e.stopPropagation(),i.hide(),o.onClick()}),e.appendChild(t)}}}),this.menuOwner=e}showTip(e){let t=e.dataset.tip;if(!t)return void this.hideTip();let i=this.theme;if(!this.tipEl){let e=document.createElement("div");e.style.cssText=`position:absolute;z-index:27;pointer-events:none;white-space:nowrap;background:${i.textColor};color:${i.background};padding:3px 7px;border-radius:5px;font:var(--vela-font-size-sm) ${i.fontFamily};box-shadow:var(--vela-shadow);`,this.host.appendChild(e),this.tipEl=e}let o=this.tipEl;o.textContent=t;let r=this.host.getBoundingClientRect(),l=e.getBoundingClientRect(),n=o.offsetWidth,a=o.offsetHeight,s=l.left-r.left+l.width/2-n/2;s=Math.max(4,Math.min(s,r.width-n-4));let h=l.top-r.top-a-6,d=h>=4?h:l.bottom-r.top+6;o.style.left=`${Math.round(s)}px`,o.style.top=`${Math.round(d)}px`}hideTip(){this.tipEl?.remove(),this.tipEl=null}toggle(e,t,i,o,r){let l=this.base(e),n=e=>{l.dataset.active=e===ls?"mixed":e?"1":"0",l.innerHTML=l$(r&&!1===e?r:t)};n(i);let a=i;return l.addEventListener("click",()=>{n(a=a===ls||!a),o(a)}),l}widthInput(e,t,i,o,r,l){let n=new P.Q7({i18n:this.i18n?.()??null,value:t===ls?i:t,min:i,max:o,step:r,integer:r>=1,size:"sm",fill:!1,compact:!0,commit:"blur",title:e,onChange:l});return t===ls&&(n.input.value="",n.input.placeholder="—"),n.el.dataset.tip=e,n.el.addEventListener("keydown",e=>e.stopPropagation()),n.el}dropdown(e,t,i,o,r,l={}){let n=this.base(e);n.style.width="auto",n.style.minWidth="30px",n.style.padding="0 4px",n.style.gap="2px";let a=i,s=e=>{if(n.replaceChildren(),e===ls){let e=document.createElement("span");e.textContent="—",e.style.cssText="min-width:18px;text-align:center;opacity:0.85;",n.appendChild(e)}let t=e===ls?"":o(e);if(t){let e=document.createElement("span");e.style.cssText="display:flex;",e.innerHTML=l$(t),n.appendChild(e)}if(l.label&&l.labelInTrigger&&e!==ls){let t=document.createElement("span");t.textContent=l.label(e),t.style.cssText="font-size:11px;opacity:0.85;font-variant-numeric:tabular-nums;",n.appendChild(t)}let i=document.createElement("span");i.style.cssText="display:flex;opacity:0.55;",i.innerHTML=l$(lP,12),n.appendChild(i)};return s(a),n.addEventListener("pointerdown",e=>e.stopPropagation()),n.addEventListener("click",e=>{if(e.stopPropagation(),this.menuOwner===n)return void this.closeMenu();this.openMenu(n,t,a,o,l.label,e=>{a=e,s(e),r(e)})}),n}openMenu(e,t,i,o,r,l){this.menuPop=this.hostFloat(e,{zIndex:26,padding:"4px",fill:(e,n)=>{for(let a of t){let t=a===i,s=document.createElement("button");s.type="button",s.className="vela-dpop-item",s.dataset.active=t?"1":"0",s.style.cssText=`display:flex;align-items:center;gap:8px;${r?"min-width:118px;":""}padding:5px 8px;border:none;border-radius:5px;color:inherit;cursor:pointer;text-align:left;font:inherit;`;let h=o(a);if(h){let e=document.createElement("span");e.style.cssText="display:flex;flex:none;width:22px;justify-content:center;",e.innerHTML=l$(h,18),s.appendChild(e)}if(r){let e=document.createElement("span");e.textContent=r(a),e.style.cssText="flex:1;font-variant-numeric:tabular-nums;",s.appendChild(e)}s.addEventListener("click",e=>{e.stopPropagation(),n.hide(),l(a)}),e.appendChild(s)}}}),this.menuOwner=e}closeMenu(){this.menuPop?.hide()}colorButton(e,t,i,r,l=17,n=[]){let a=document.createElement("button");a.type="button",a.dataset.tip=e,a.className="vela-dpop-btn",a.style.cssText="position:relative;width:30px;height:30px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;cursor:pointer;border-radius:5px;border:none;color:inherit;padding:0;";let s=document.createElement("span");s.style.cssText="display:flex;",s.innerHTML=l$(t,l);let h=document.createElement("span");h.style.cssText=`display:block;height:3px;width:${Math.round(.85*l)}px;border-radius:2px;background:${i===ls?function(e){let t=e.length>1?e:["var(--vela-fg-faint)","var(--vela-fg-muted)"],i=100/t.length,o=t.map((e,t)=>`${e} ${t*i}% ${(t+1)*i}%`).join(",");return`linear-gradient(90deg,${o})`}(n):i};`,a.append(s,h);let d=i;return a.addEventListener("pointerdown",e=>e.stopPropagation()),a.addEventListener("click",e=>{e.stopPropagation();let t=d===ls?n[0]??o.lx5:d;this.toggleColorPopover(a,t,d===ls?n:[],e=>{d=e,h.style.background=e,r(e)})}),a}toggleColorPopover(e,t,i,o){if(this.colorOwner===e)return void this.closeColorPopover();this.openColorPopover(e,t,i,o)}openColorPopover(e,t,i,o){let r=this.theme;this.colorPop=this.hostFloat(e,{zIndex:25,padding:"10px",fill:(e,l)=>{if(i.length>1){let t=document.createElement("div");t.style.cssText="display:flex;align-items:center;gap:6px;padding-bottom:9px;border-bottom:1px solid var(--vela-border);";let r=document.createElement("span");for(let e of(r.textContent=this.t(la.inUse),r.style.cssText="font:var(--vela-font-size-sm) inherit;opacity:0.7;margin-right:2px;",t.appendChild(r),i)){let i=document.createElement("button");i.type="button",i.dataset.tip=e,i.style.cssText=`width:18px;height:18px;border-radius:4px;border:1px solid var(--vela-border-strong);cursor:pointer;background:${e};padding:0;`,i.addEventListener("click",t=>{t.stopPropagation(),l.hide(),o(e)}),t.appendChild(i)}e.appendChild(t)}e.appendChild((0,A.Yv)(t,r,o,{i18n:this.i18n?.()??null}))}}),this.colorOwner=e}closeColorPopover(){this.colorPop?.hide()}divider(){let e=document.createElement("div");return e.style.cssText="width:1px;height:18px;margin:0 3px;background:var(--vela-border);",e}},lp=(0,l.Kk)("brush"),lu=(0,l.Kk)("bucket"),lg=(0,l.Kk)("type"),lm=(0,l.Kk)("price-delta"),lb=(0,l.Kk)("date-delta"),lf=(0,l.Kk)("lock"),lv=(0,l.Kk)("unlock"),ly=(0,l.Kk)("bring-front"),lw=(0,l.Kk)("send-back"),lC=(0,l.Kk)("trash"),lx=(0,l.Kk)("bold"),lk=(0,l.Kk)("italic"),lS=(0,l.Kk)("grip"),lT=(0,l.Kk)("kebab"),lM=(0,l.Kk)("clone"),lL=(0,l.Kk)("reset"),lA=(0,l.Kk)("gear"),lP=(0,l.Kk)("chevron-down"),lI=(0,l.Kk)("r-squared"),lE=(0,l.Kk)("bands"),lB=(0,l.Kk)("dedekind"),lF=(0,l.Kk)("sonic"),lO=(0,l.Kk)("supersonic");function lR(e,t){return(0,l.tJ)(`<line x1="3.5" y1="12" x2="20.5" y2="12" stroke-width="${Number(e)||2}" stroke-dasharray="${"dashed"===t?"5,3":"dotted"===t?"1.5,3":""}"/>`)}function lN(e,t,i=17,o=""){return(0,l.Uu)(`<text x="12" y="${i}" font-size="${t}" text-anchor="middle"${o?" "+o:""}>${e}</text>`)}var lz={small:10,normal:13,large:16,huge:20};function lV(e){return lN("T",(lz[String(e)]??13)+2)}function lD(e){return e.charAt(0).toUpperCase()+e.slice(1)}function l$(e,t=21){return e.replace("<svg ",`<svg width="${t}" height="${t}" `)}var lH={priceChange:(0,n.ab)("drawing.ruler.priceChange","{change} ({percent}%)"),barsAndDuration:(0,n.ab)("drawing.ruler.barsAndDuration","{count, plural, one {{bars} bar} other {{bars} bars}}, {duration}")};function lW(e){return`${e>=0?"+":""}${e.toFixed(2)}`}var lq=r.cr,lU=r.TV,lj=class{constructor(e){this.projector=e,this.state="idle",this.paneId=null,this.start=null,this.end=null,this.pressX=0,this.pressY=0}isActive(){return"idle"!==this.state}isFinished(){return"finished"===this.state}toPoint(e,t){if(null==this.paneId)return null;let i=this.projector().pxToPoint(e,t,this.paneId);return{time:i.time,price:i.price}}toPx(e,t){if(null==this.paneId)return null;let i=e.yOf(t.price,this.paneId);return null==i?null:{x:e.xOf(t.time),y:i}}down(e,t,i=e,o=t){if("measuring"===this.state){this.end=this.toPoint(i,o)??this.end,this.state="finished";return}this.paneId=this.projector().paneIdAtY(o),this.start=this.toPoint(i,o),this.end=this.start,this.pressX=e,this.pressY=t,this.state="measuring"}move(e,t){"measuring"===this.state&&(this.end=this.toPoint(e,t)??this.end)}up(e,t,i=e,o=t){"measuring"===this.state&&Math.hypot(e-this.pressX,t-this.pressY)>3&&(this.end=this.toPoint(i,o)??this.end,this.state="finished")}points(){if(!this.start||!this.end)return null;let e=this.projector(),t=this.toPx(e,this.start),i=this.toPx(e,this.end);return t&&i?{start:t,end:i}:null}clear(){this.state="idle",this.paneId=null,this.start=null,this.end=null}paint(e,t,i,o=(0,n.Db)()){if(!this.start||!this.end)return;let r=this.toPx(t,this.start),l=this.toPx(t,this.end);if(!r||!l)return;let{x:a,y:s}=r,{x:h,y:d}=l,c=this.start,p=this.end,u=p.price-c.price,g=0!==c.price?u/c.price*100:0,m=t.barsBetween?Math.round(t.barsBetween(c.time,p.time)):null,b=u>=0,f=b?lq:lU,v=Math.min(a,h),y=Math.max(a,h),w=Math.min(s,d),C=Math.max(s,d),x=(a+h)/2,k=(s+d)/2;e.save(),e.globalAlpha=.12,e.fillStyle=f,e.fillRect(v,w,y-v,C-w),e.globalAlpha=1,e.strokeStyle=f,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(x,s),e.lineTo(x,d),e.moveTo(a,k),e.lineTo(h,k),e.stroke(),e.setLineDash([]);let S=b?w:C,T=b?1:-1;e.fillStyle=f,e.beginPath(),e.moveTo(x,S),e.lineTo(x-5,S+7*T),e.lineTo(x+5,S+7*T),e.closePath(),e.fill(),e.restore();let M=o.format.duration(p.time-c.time,{style:"span",surface:"drawing"});this.paintLabel(e,t,i,x,w,C,f,[o.t(lH.priceChange,{change:(0,n.EJ)(lW(u),o),percent:(0,n.EJ)(lW(g),o)}),null!=m?o.t(lH.barsAndDuration,{count:m,bars:(0,n.EJ)(String(m),o),duration:M}):M])}paintLabel(e,t,i,o,r,l,n,a){e.save(),e.font=`12px ${i.fontFamily}`;let s=Math.max(...a.map(t=>e.measureText(t).width))+16,h=16*a.length+8,d=l+8;d+h>t.height&&(d=r-h-8),e.fillStyle=i.background,e.strokeStyle=n,e.lineWidth=1,e.beginPath(),e.roundRect(o-s/2,d,s,h,4),e.fill(),e.stroke(),e.fillStyle=i.textColor,e.textAlign="center",e.textBaseline="middle",a.forEach((t,i)=>e.fillText(t,o,d+8+8+16*i)),e.restore()}},lG=(0,n.ab)("drawing.inlineEditor.placeholder","Enter Text");function lK(e){return e instanceof o.PqE||e instanceof o.asL}var lY={};function lZ(e,t){return 0===t.length||e>t[t.length-1]?null:t.find(t=>t>=e)}var lX=class{constructor(e,t,i,o){this.toolbarHost=e,this.overlayHost=t,this.canvas=i,this.deps=o,this.ctx=null,this.drawings=[],this.sliced=new Set,this.lifted=new Set,this.sliceCache=new Map,this.lastBounds=new Map,this.selectedIds=new Set,this.hoveredId=null,this.activeTool=null,this.toolTemplates={},this.intentCb=null,this.externalGhost=null,this.seriesGw=null,this.seriesGwUnsub=null,this.lastDraftKey=null,this.measure=new lj(()=>this.deps.projector()),this.toolbarVisible=!1,this.toolbarCollapsed=!1,this.mobileLayout=!1,this.historyChords=!0,this.measureMode=!1,this.eraserMode=!1,this.erasing=!1,this.textEditor=null,this.painter=new rR,this.popupMulti=!1,this.drawingActions=null,this.onPopupDismissed=e=>{if(e&&(e.shiftKey||e.ctrlKey||e.metaKey))return;let t=this.interaction.pressedId();t&&this.selectedIds.has(t)||this.clearSelection()},this.ctx=i.getContext("2d"),this.popup=new lc(t,o.theme(),{chartBarMs:()=>o.chartBarMs(),timeZone:()=>o.timeZone?.()??"UTC",priceDecimals:()=>o.priceDecimals?.()??null,i18n:()=>this.i18n()}),this.toolbar=new eU(e,o.theme(),e=>this.emit({kind:"arm",type:e}),e=>{this.deps.setSnapMode(e),this.emit({kind:"snap-mode",mode:e})},()=>this.withModeIntent(()=>this.toggleMeasure()),()=>this.withModeIntent(()=>this.toggleEraser()),(e,t)=>this.emit({kind:"favorite",type:e,on:t}),e=>this.emit({kind:"stay-mode",on:e}),{onCollapse:e=>{this.toolbarCollapsed=e,this.syncToolbarGutter()},i18n:()=>this.i18n()}),this.interaction=new rj({projector:()=>this.deps.projector(),activeTool:()=>this.activeTool,drawings:()=>this.onScreen(),hoveredId:()=>this.hoveredId,selectedIds:()=>this.selectedIds,emit:e=>this.emit(e),changed:()=>{this.syncLift(),this.render()},openSettings:(e,t,i)=>this.openSettingsById(e,t,i),snap:(e,t,i,o)=>this.deps.snap(e,t,i,o),toolDefaults:()=>this.activeToolDefaults})}i18n(){return this.deps.i18n?.()??(0,n.Db)()}t(e){return this.i18n().t(e)}relocalize(){this.toolbar.relabel(),this.popup.close(),this.render()}setDrawingActions(e){this.drawingActions=e}setToolbar(e){this.toolbar.setDefinition(e)}showToolbar(e){this.toolbarVisible=e,this.toolbar.setVisible(e&&!this.mobileLayout),this.syncToolbarGutter()}setLayoutMode(e){this.mobileLayout="mobile"===e,this.toolbar.setVisible(this.toolbarVisible&&!this.mobileLayout),this.syncToolbarGutter()}syncToolbarGutter(){let e=this.toolbarVisible&&!this.mobileLayout;this.deps.setToolbarGutter(e?this.toolbarCollapsed?16:44:0)}setSeriesGateway(e){this.seriesGwUnsub?.(),this.seriesGw=e,this.seriesGwUnsub=e.onUpdate(()=>{this.invalidateSlices(),this.render(),this.deps.requestDataPaint()})}get seriesGateway(){return this.seriesGw}setExternalGhost(e){this.externalGhost=e?(0,o.erJ)(e):null,this.render()}syncDrawings(e){this.drawings=e.map(e=>(0,o.erJ)(e)).filter(e=>null!=e),this.textEditor&&!this.editedDrawing(this.textEditor.id)&&this.closeTextEditor(),this.invalidateSlices(),this.render(),this.deps.requestScaleUpdate(),this.popup.syncPanel()}stackRange(e){let t=this.deps.seriesBoundaries(e);return{front:Math.max(0,...t),back:Math.min(0,...t),price:this.deps.priceZ(e)??void 0}}priceRangeForPane(e,t,i){let o=1/0,r=-1/0;for(let l of this.drawings){if(!l.visible||l.paneId!==e)continue;let n=l.timeExtent();if(n&&(n.max<t||n.min>i))continue;let a=l.priceRange();a&&(a.min<o&&(o=a.min),a.max>r&&(r=a.max))}return o<=r?{min:o,max:r}:null}setActiveTool(e,t,i){null!=e&&(this.finishTextEditor(!0),this.withModeIntent(()=>{this.measureMode&&this.exitMeasure(),this.eraserMode&&this.exitEraser()})),this.activeTool=e,this.activeToolDefaults=i??(t?{style:t}:void 0),this.toolbar.setActiveTool(e),null==e?this.interaction.onToolCleared():this.clearSelection(),this.render()}setFavorites(e){this.toolbar.setFavorites(e)}setToolTemplates(e){this.toolTemplates=e}setToolShortcuts(e){this.toolbar.setShortcuts(e)}setSnapMode(e){this.deps.setSnapMode(e),this.toolbar.setMagnetMode(e)}setStayMode(e){this.toolbar.setStayMode(e)}setMode(e){this.withModeIntent(()=>{"measure"===e?this.measureMode||this.toggleMeasure():"eraser"===e?this.eraserMode||this.toggleEraser():(this.measureMode&&this.exitMeasure(),this.eraserMode&&this.exitEraser())})}modeOf(){return this.measureMode?"measure":this.eraserMode?"eraser":null}withModeIntent(e){let t=this.modeOf();e();let i=this.modeOf();i!==t&&this.emit({kind:"mode",mode:i})}setSelection(e){this.selectedIds=new Set(e),e.length>=2?this.openSettingsForSelection(e):this.popupMulti&&(this.popupMulti=!1,this.popup.close(),1===e.length&&this.openSettingsById(e[0],0,0)),this.render()}openSettings(e){this.openSettingsById(e,0,0)}onDrawingIntent(e){return this.intentCb=e,()=>{this.intentCb===e&&(this.intentCb=null)}}claim(e,t){return!!(this.measureMode||this.eraserMode||this.magnifierChipAt(e,t))||this.interaction.claim(e,t)}magnifierChipAt(e,t){let i=this.onScreen();for(let r=i.length-1;r>=0;r-=1){let l=i[r];if(!(l instanceof o.NvN)||!l.visible||l.locked)continue;let n=l.chipRect;if(n&&e>=n.x&&e<=n.x+n.w&&t>=n.y&&t<=n.y+n.h)return l}return null}openMagnifierChipMenu(e){let t=e.chipRect;if(!t)return;let i=e.id;this.popup.openMagnifierTimeframeMenu(t,e.magnifier.timeframe,e=>{let t=this.drawings.find(e=>e.id===i);t instanceof o.NvN&&(t.applySettings({"magnifier.timeframe":e}),this.render(),this.emit({kind:"edit",doc:t.serialize()}))})}deleteAt(e,t,i=!1){var o,r;let l=rH(this.onScreen(),e,t,this.deps.projector(),6);if(!l)return!1;let n=(o=this.selectedIds,r=this.drawings,i&&o.size>=2&&o.has(l.id)?rW(o,r):l.locked?[]:[l.id]);return 0!==n.length&&(this.popup.close(),this.emit({kind:"delete",ids:n}),!0)}beginMeasureAt(e,t,i="off"){if(this.measureMode||this.eraserMode||null!=this.activeTool)return!1;this.withModeIntent(()=>this.toggleMeasure());let o=this.interaction.snapCursor(e,t,i);return this.measure.down(e,t,o.x,o.y),this.render(),!0}clearTransient(){this.textEditor&&this.finishTextEditor(!0),this.measure.isFinished()&&(this.measure.clear(),this.render())}beginMarqueeAt(e,t){return!this.measureMode&&!this.eraserMode&&!!this.interaction.beginMarquee(e,t)&&(this.render(),!0)}pointerDown(e,t,i="off",o=!1,r=!1){if(this.eraserMode){this.erasing=!0,this.deleteAt(e,t);return}if(this.measureMode){let o=this.interaction.snapCursor(e,t,i);this.measure.down(e,t,o.x,o.y),this.measure.isFinished()&&this.withModeIntent(()=>this.exitMeasure(!1)),this.render();return}if(null==this.activeTool){let i=this.magnifierChipAt(e,t);if(i)return void this.openMagnifierChipMenu(i)}this.interaction.down(e,t,i,o,r)}pointerMove(e,t,i="off",o=!1,r=!1){if(this.eraserMode){this.erasing&&this.deleteAt(e,t);return}if(this.measureMode){let o=this.interaction.snapCursor(e,t,i);this.measure.move(o.x,o.y),this.render();return}this.interaction.move(e,t,i,o),this.updateHover(e,t,r)}updateHover(e,t,i=!1){let o=null;i||null!=this.activeTool||this.interaction.isPlacing()||this.interaction.isDragging()||(o=rH(this.onScreen(),e,t,this.deps.projector(),6)?.id??null),o!==this.hoveredId&&(this.hoveredId=o,this.render())}clearHover(){null!=this.hoveredId&&(this.hoveredId=null,this.render())}pointerUp(e,t,i="off"){if(this.eraserMode){this.erasing=!1;return}if(this.measureMode){let o=this.interaction.snapCursor(e,t,i);this.measure.up(e,t,o.x,o.y),this.measure.isFinished()&&this.withModeIntent(()=>this.exitMeasure(!1)),this.render();return}let o=this.interaction.isDragging()?this.interaction.pressedId():null;this.interaction.up(e,t),o&&this.selectedIds.has(o)&&!this.popup.isOpen()&&(this.selectedIds.size>=2?this.openSettingsForSelection(this.selectionIds()):this.openSettingsById(o,e,t))}toggleMeasure(){if(this.measureMode)return void this.exitMeasure();this.eraserMode&&this.exitEraser(),this.measure.clear(),this.measureMode=!0,this.emit({kind:"arm",type:null}),this.clearSelection(),this.toolbar.setMeasureActive(!0),this.render()}toggleEraser(){if(this.eraserMode)return void this.exitEraser();this.measureMode&&this.exitMeasure(),this.eraserMode=!0,this.erasing=!1,this.emit({kind:"arm",type:null}),this.clearSelection(),this.toolbar.setEraserActive(!0),this.render()}exitEraser(){this.eraserMode=!1,this.erasing=!1,this.toolbar.setEraserActive(!1),this.render()}exitMeasure(e=!0){this.measureMode=!1,this.interaction.clearSnapMarker(),e&&this.measure.clear(),this.toolbar.setMeasureActive(!1),this.render()}editTextInline(e){let t=this.editedDrawing(e);if(!t)return;this.closeTextEditor();let i=t.text?.value??"",o=this.inlineEditorCss(t,i);if(!o)return;let r=document.createElement("textarea");r.value=i,r.placeholder=this.t(lG),r.spellcheck=!1,r.style.cssText=o;let l=()=>{this.editedDrawing(e)?.applySettings({"text.value":r.value}),this.render()};r.addEventListener("input",l),r.addEventListener("pointerdown",e=>e.stopPropagation()),r.addEventListener("keydown",e=>{if(e.stopPropagation(),"Enter"!==e.key||e.ctrlKey||e.metaKey)"Enter"===e.key?(e.preventDefault(),this.finishTextEditor(!0)):"Escape"===e.key&&(e.preventDefault(),this.finishTextEditor(!1));else{e.preventDefault();let t=r.selectionStart;r.setRangeText("\n",t,r.selectionEnd,"end"),l()}}),r.addEventListener("blur",e=>{this.popup.contains(e.relatedTarget)?this.storeText(r.value):this.finishTextEditor(!0)}),this.overlayHost.appendChild(r),this.textEditor={el:r,id:e,initial:i,stored:i},r.focus(),r.setSelectionRange(r.value.length,r.value.length)}storeText(e){let t=this.textEditor,i=t&&this.editedDrawing(t.id);t&&i&&(i.applySettings({"text.value":e}),e!==t.stored&&(t.stored=e,this.emit({kind:"edit",doc:i.serialize()})))}editedDrawing(e){let t=this.drawings.find(t=>t.id===e);return lK(t)?t:null}finishTextEditor(e){let t=this.textEditor;if(!t)return;let i=e?t.el.value:t.initial;this.closeTextEditor();let r=this.editedDrawing(t.id);r&&(r.applySettings({"text.value":i}),this.render(),r instanceof o.asL&&""===i.trim()?(this.clearSelection(),this.emit({kind:"delete",ids:[r.id]})):i!==t.stored&&this.emit({kind:"edit",doc:r.serialize()}))}inlineEditorCss(e,t){let i=this.deps.projector(),r=this.deps.theme(),l=e.text,n=oM(l?.size??"normal"),a=`${l?.italic?"italic ":""}${l?.bold?"bold ":""}${n}px ${r.fontFamily}`,s="position:absolute;z-index:24;box-sizing:border-box;resize:none;overflow:hidden;margin:0;outline:none;pointer-events:auto;text-align:left;";if(e instanceof o.PqE){let t=e.box(i);if(!t)return null;let o=e.style.fillColor??r.background;return s+`left:${Math.round(t.x)}px;top:${Math.round(t.y)}px;width:${Math.round(t.w)}px;height:${Math.round(t.h)}px;padding:5px 8px;border-radius:5px;border:1px solid ${e.style.lineColor??r.borderColor};background:${(0,A.a5)(o,r.background,(0,A.qz)(o).alpha)};color:${l?.color??r.textColor};font:${a};`}let h=e.handlePoints(i)[0];if(!h)return null;let d=oT(n),c=(t||this.t(lG)).split("\n"),u=Math.ceil(this.measureTextWidth(c,a))+8;return s+`left:${Math.round(h[0]+2)-5}px;top:${Math.round(h[1]+2-(d-n)/2)-3}px;width:${u+10}px;height:${c.length*d+6}px;padding:2px 4px;border:1px solid ${(0,p.fu)(r.textColor,.3)};border-radius:4px;background:transparent;color:${l?.color??r.textColor};font:${a};line-height:${d}px;white-space:pre;`}measureTextWidth(e,t){let i=this.ctx;if(!i)return 120;let o=i.font;i.font=t;let r=Math.max(8,...e.map(e=>i.measureText(e).width));return i.font=o,r}layoutTextEditor(){let e=this.textEditor;if(!e)return;let t=this.editedDrawing(e.id),i=t&&this.inlineEditorCss(t,e.el.value);i&&(e.el.style.cssText=i)}closeTextEditor(){let e=this.textEditor;e&&(this.textEditor=null,e.el.remove(),this.render())}cursorAt(e,t){return this.eraserMode||null==this.activeTool&&this.magnifierChipAt(e,t)?"pointer":this.interaction.cursorAt(e,t)}cancelPlacement(){return this.measureMode||this.eraserMode?(this.withModeIntent(()=>this.measureMode?this.exitMeasure():this.exitEraser()),!0):this.interaction.isPlacing()?(this.interaction.cancel(),null!=this.activeTool&&this.emit({kind:"arm",type:null}),!0):null!=this.activeTool&&(this.emit({kind:"arm",type:null}),!0)}dblClick(e,t){if(this.interaction.finishPlacing(!0))return!0;let i=rH(this.onScreen(),e,t,this.deps.projector(),6);return lK(i)?(this.editTextInline(i.id),!0):!!i&&(!this.popupMulti&&this.selectedIds.has(i.id)&&this.popup.isOpen()||this.openSettingsById(i.id,0,0),this.popup.openPanel(),!0)}handleKey(e){var t;if("Escape"===e.key)return this.textEditor?(this.finishTextEditor(!1),!0):this.popup.isOpen()?(this.clearSelection(),!0):!!this.interaction.cancel()||(this.measureMode?(this.withModeIntent(()=>this.exitMeasure()),!0):!!this.selectedIds.size&&(this.clearSelection(),!0));if("Enter"===e.key&&this.interaction.finishPlacing(!1))return!0;let i=function(e,t){if(t.editingText)return null;if(e.ctrlKey||e.metaKey)switch(e.key.toLowerCase()){case"z":return e.shiftKey?{kind:"redo"}:{kind:"undo"};case"y":return{kind:"redo"};case"c":return t.hasSelection?{kind:"copy"}:null;case"v":return{kind:"paste"};case"d":return t.hasSelection?{kind:"duplicate"}:null;default:return null}if("Delete"===e.key||"Backspace"===e.key)return t.hasTarget?{kind:"delete"}:null;if(t.hasSelection){let t=e.shiftKey?10:1;switch(e.key){case"ArrowLeft":return{kind:"nudge",dx:-t,dy:0};case"ArrowRight":return{kind:"nudge",dx:t,dy:0};case"ArrowUp":return{kind:"nudge",dx:0,dy:-t};case"ArrowDown":return{kind:"nudge",dx:0,dy:t}}}return null}(e,{hasSelection:this.selectedIds.size>0,hasTarget:this.selectedIds.size>0||null!=this.hoveredId,editingText:!!(t=e.target)&&!!t.tagName&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||!0===t.isContentEditable)});if(!i)return!1;switch(i.kind){case"undo":if(!this.historyChords)return!1;this.emit({kind:"undo"});break;case"redo":if(!this.historyChords)return!1;this.emit({kind:"redo"});break;case"copy":this.emit({kind:"copy",ids:this.selectionIds()});break;case"paste":this.emit({kind:"paste"});break;case"duplicate":this.emit({kind:"duplicate",ids:this.selectionIds()});break;case"delete":{let e=this.selectedIds.size?this.deletableSelection():this.hoveredId?[this.hoveredId]:[];e.length&&(this.popup.close(),this.emit({kind:"delete",ids:e}));break}case"nudge":this.nudgeSelection(i.dx,i.dy)}return!0}selectionIds(){return[...this.selectedIds]}deletableSelection(){return rW(this.selectedIds,this.drawings)}nudgeSelection(e,t){let i=this.deps.projector(),o=[];for(let r of this.drawings){if(!this.selectedIds.has(r.id)||r.locked)continue;let l=r.anchors.map(o=>{let l=i.yOf(o.price,r.paneId);return null==l?{time:o.time,price:o.price}:i.pxToPoint(i.xOf(o.time)+e,l+t,r.paneId)}),n=r.serialize();n.anchors=l,o.push(n)}1===o.length?this.emit({kind:"edit",doc:o[0]}):o.length>1&&this.emit({kind:"edit-many",docs:o})}setTheme(e){this.popup.setTheme(e),this.toolbar.setTheme(e),this.render()}onResize(){this.finishTextEditor(!0),this.popup.close(),this.render()}onScreen(){let e=this.deps.chartBarMs();return this.drawings.filter(t=>(0,o.N5D)(t.showOn,e))}isInterleaved(e){return null!==lZ(e.zIndex,this.lastBounds.get(e.paneId)??[])}syncLift(){let e=this.interaction.movingIds(),t=e.size===this.lifted.size;if(t)for(let i of e)this.lifted.has(i)||(t=!1);t||(this.lifted=new Set(e),this.invalidateSlices())}invalidateSlices(){(this.sliced.size>0||this.drawings.some(e=>this.isInterleaved(e)))&&this.deps.requestDataPaint()}prepareSlices(e){this.sliced.clear(),this.lastBounds=new Map(e.map(e=>[e,this.deps.seriesBoundaries(e)]));let t=new Map,i=this.deps.dpr(),o=this.deps.projector(),r=this.deps.theme(),l=new Map;for(let e of this.onScreen()){if(!e.visible||this.lifted.has(e.id))continue;let t=lZ(e.zIndex,this.lastBounds.get(e.paneId)??[]);if(null===t)continue;let i=`${e.paneId}|${t}`,o=l.get(i);o?o.drawings.push(e):l.set(i,{paneId:e.paneId,beforeZ:t,drawings:[e]}),this.sliced.add(e.id)}for(let[e,{paneId:n,beforeZ:a,drawings:s}]of l){let l=this.sliceCache.get(e);l||(l=document.createElement("canvas"),this.sliceCache.set(e,l)),(l.width!==this.canvas.width||l.height!==this.canvas.height)&&(l.width=this.canvas.width,l.height=this.canvas.height);let h=l.getContext("2d");if(!h)continue;iQ(h,i),h.clearRect(0,0,l.width/i,l.height/i),this.painter.seriesLook=this.deps.seriesLook(),this.painter.i18n=this.i18n(),this.painter.paintAll(h,s,o,r,lY);let d=t.get(n)??[];d.push({beforeZ:a,canvas:l}),t.set(n,d)}for(let e of[...this.sliceCache.keys()])l.has(e)||this.sliceCache.delete(e);for(let e of t.values())e.sort((e,t)=>e.beforeZ-t.beforeZ);return t}render(){let e=this.ctx;if(!e)return;let t=this.deps.dpr();iQ(e,t),e.clearRect(0,0,this.canvas.width/t,this.canvas.height/t);let i=this.deps.projector(),r=this.textEditor?this.editedDrawing(this.textEditor.id):null,l={selected:this.selectedIds,hovered:this.hoveredId,dragged:this.interaction.activeDragId(),mutedLabel:r instanceof o.asL?r.id:null};this.painter.seriesLook=this.deps.seriesLook(),this.painter.i18n=this.i18n();let n=e=>!this.isInterleaved(e)||this.lifted.has(e.id),a=this.onScreen();this.painter.paintAll(e,a.filter(n),i,this.deps.theme(),l),this.painter.paintHighlights(e,a.filter(e=>!n(e)),i,rO(l));let s=this.interaction.dragClones();s&&this.painter.paintAll(e,s,i,this.deps.theme(),{selected:new Set(s.map(e=>e.id))}),this.layoutTextEditor();let h=this.interaction.ghost();if(h&&this.painter.paintGhost(e,h,i,this.deps.theme()),this.externalGhost&&this.painter.paintGhost(e,this.externalGhost,i,this.deps.theme()),this.emitDraft(h),this.activeTool&&!h){let t=(0,o.jOy)(this.activeTool,this.i18n())?.placementHint;t&&this.painter.paintPlacementHint(e,t,this.deps.theme(),i.width,i.height)}let d=this.interaction.placingMarkers(i);d&&this.painter.paintHandles(e,d);let c=this.interaction.snapMarker(),p=c?i.yOf(c.point.price,c.paneId):null;c&&null!=p&&this.painter.paintSnapRing(e,i.xOf(c.point.time),p,this.deps.theme()),this.measure.isActive()&&this.measure.paint(e,i,this.deps.theme(),this.i18n());let u=this.interaction.marqueeRect();u&&this.painter.paintMarquee(e,u)}destroy(){this.closeTextEditor(),this.popup.destroy(),this.toolbar.destroy(),this.seriesGwUnsub?.(),this.seriesGwUnsub=null,this.seriesGw=null,this.intentCb=null,this.drawings=[]}clearSelection(){this.popup.close(),this.selectedIds.size&&this.emit({kind:"select",ids:[]}),this.render()}emitEdits(e){let t=e.map(e=>e.serialize());1===t.length?this.emit({kind:"edit",doc:t[0]}):t.length>1&&this.emit({kind:"edit-many",docs:t})}openSettingsForSelection(e){let t=()=>e.map(e=>this.drawings.find(t=>t.id===e)).filter(e=>null!=e),i=t();if(i.length<2)return;let r=this.deps.projector(),l=null;for(let e of i){let t=e.bounds(r);if(t)if(l){let e=Math.max(l.x+l.w,t.x+t.w),i=Math.max(l.y+l.h,t.y+t.h);l.x=Math.min(l.x,t.x),l.y=Math.min(l.y,t.y),l.w=e-l.x,l.h=i-l.y}else l={...t}}this.popupMulti=!0,this.emit({kind:"settings",id:i[0].id}),this.popup.open(i,l,{resolve:()=>t()[0]??null,patch:e=>{let i=t();for(let t of i)t.applySettings(e);this.render(),this.emitEdits(i)},setLocked:e=>{let i=t();for(let t of i)t.locked=e;this.emitEdits(i)},reorder:e=>{for(let i of t())this.emit({kind:"reorder",id:i.id,to:e})},duplicate:()=>{this.popup.close(),this.emit({kind:"duplicate",ids:t().map(e=>e.id)})},resetSettings:()=>{let i=t();for(let e of i)(0,o.hNP)(e);this.render(),this.emitEdits(i),this.openSettingsForSelection(e)},remove:()=>{let e=t().filter(e=>!e.locked).map(e=>e.id);0!==e.length&&(this.popup.close(),this.emit({kind:"delete",ids:e}))}},this.onPopupDismissed)}openSettingsById(e,t,i){let r=this.drawings.find(t=>t.id===e);if(!r)return;let l=()=>this.drawings.find(t=>t.id===e);this.popupMulti=!1,this.emit({kind:"select",ids:[e]}),this.emit({kind:"settings",id:e});let n=r.bounds(this.deps.projector()),a=null;this.popup.open([r],n,{resolve:()=>l()??null,patch:e=>{let t=l();t&&(t.applySettings(e),this.render(),this.emit({kind:"edit",doc:t.serialize()}))},setLocked:e=>{let t=l();t&&(t.locked=e,this.emit({kind:"edit",doc:t.serialize()}))},reorder:t=>this.emit({kind:"reorder",id:e,to:t}),duplicate:()=>{this.finishTextEditor(!0),this.popup.close(),this.emit({kind:"duplicate",ids:[e]})},resetSettings:()=>{let t=l();t&&((0,o.hNP)(t),this.render(),this.emit({kind:"edit",doc:t.serialize()}),this.openSettingsById(e,0,0))},restore:e=>{let t=l();if(!t)return;let i=e.text??(t.text?{...t.text,value:""}:void 0);l_(t,{...e,text:i}),t.anchors=e.anchors.map(e=>({...e})),t.showOn=e.showOn?[...e.showOn]:void 0,this.render(),this.emit({kind:"edit",doc:{...e,text:i}})},templates:()=>this.toolTemplates[r.type]??[],extras:()=>this.drawingActions?.(e)??[],saveTemplate:e=>{let t=l();t&&this.emit({kind:"template-save",type:t.type,name:e,settings:eL(t)})},removeTemplate:e=>this.emit({kind:"template-remove",type:r.type,name:e}),applyToolSettings:e=>{let t=l();t&&(eA(t,e),this.render(),this.emit({kind:"edit",doc:t.serialize()}))},preview:e=>{let t=l();if(t){if(e)a?l_(t,a):a=t.serialize(),eA(t,e);else{if(!a)return;l_(t,a),a=null}this.render()}},remove:()=>{this.closeTextEditor(),this.popup.close(),this.emit({kind:"delete",ids:[e]})}},this.onPopupDismissed)}deselect(){this.clearSelection()}emitDraft(e){let t=e?JSON.stringify({t:e.type,p:e.paneId,a:e.anchors,s:e.style,x:e.text}):null;t!==this.lastDraftKey&&(this.lastDraftKey=t,this.intentCb?.({kind:"draft",doc:e?e.serialize():null}))}emit(e){if("create"===e.kind){e.doc.text&&void 0===e.doc.text.color&&(e.doc.text={...e.doc.text,color:oS(this.deps.theme().background)});let t=e.doc.text?(0,o.erJ)(e.doc)?.placeholderText():null;e.doc.text&&t&&e.doc.text.value===(0,n.rI)(t)&&(e.doc.text={...e.doc.text,value:this.t(t)});let i=new Set(this.drawings.map(e=>e.id));this.intentCb?.(e),setTimeout(()=>{let e=this.drawings.find(e=>!i.has(e.id));e&&(this.openSettingsById(e.id,0,0),lK(e)&&this.editTextInline(e.id))},0);return}if("clone"===e.kind){let t=new Set(this.drawings.map(e=>e.id));this.intentCb?.(e);let i=this.drawings.filter(e=>!t.has(e.id));1===i.length&&this.openSettingsById(i[0].id,0,0);return}this.intentCb?.(e)}};function l_(e,t){e.style={...t.style},e.text=t.text?{...t.text}:void 0,void 0!==t.props&&e.applyProps(t.props)}var lQ={auto:13,tiny:10,small:11,normal:13,large:16,huge:20};function lJ(e){return"number"==typeof e?e>0?e:lQ.auto:lQ[e]??lQ.auto}function l0(e,t,i){let o="monospace"===e.fontFamily?"monospace":i.fontFamily||"sans-serif";return`${e.italic?"italic ":""}${e.bold?"bold ":""}${t}px ${o}`}var l1=class{constructor(){this.drawScene=new oB({timeToLogical:()=>0,barAt:()=>null,theme:{}}),this.sliceCache=new Map,this.tips=[]}prepare(e,t,i,o){this.tips=[];let r=new Map;if(0===o.width||0===o.height)return this.sliceCache.clear(),r;this.drawScene.setDeps({timeToLogical:e=>t.timeToLogical(e),barAt:t=>{let i=e.bars[Math.round(t)];return i?{high:i.high,low:i.low}:null},theme:i});let l=t.dpr,n=t.width,a=new Map,s=(e,t,i)=>{let o=`${e}|${t}`,r=a.get(o);r?r.entries.push(i):a.set(o,{paneId:e,beforeZ:t,entries:[i]})};for(let t of e.orderedPanes()){if(t.collapsed)continue;let i=e.seriesBoundaries(t.id);for(let o of e.orderedIndicatorsForPane(t.id)){let r=oP(o,!1),l=(o.tables??[]).filter(e=>!e.overlay);if(oI(r)&&0===l.length)continue;let n=e.scaleFor(o,t),a=n===t.scale?t:{...t,scale:n},h=function(e,t){return t.find(t=>t>e)??1/0}(e.zOf(o.id),i);s(t.id,h,{set:r,tables:l,pane:a,indexOffset:e.offsetOf(o.id)})}if("price"===t.kind)for(let i of e.indicators.values()){let o=oP(i,!0),r=(i.tables??[]).filter(e=>!0===e.overlay);oI(o)&&0===r.length||s(t.id,1/0,{set:o,tables:r,pane:t,indexOffset:e.offsetOf(i.id)})}}for(let[e,{paneId:s,beforeZ:h,entries:d}]of a){let a=this.sliceCache.get(e);a||(a=document.createElement("canvas"),this.sliceCache.set(e,a)),(a.width!==o.width||a.height!==o.height)&&(a.width=o.width,a.height=o.height);let c=a.getContext("2d");if(!c)continue;for(let e of(iQ(c,l),c.clearRect(0,0,a.width/l,a.height/l),d))this.paintEntry(c,e,t,n,i);let p=r.get(s)??[];p.push({beforeZ:h,canvas:a}),r.set(s,p)}for(let e of[...this.sliceCache.keys()])a.has(e)||this.sliceCache.delete(e);for(let e of r.values())e.sort((e,t)=>e.beforeZ-t.beforeZ);return r}paintEntry(e,t,i,o,r){let{pane:l}=t,n=[];for(let a of(e.save(),e.translate(0,l.bounds.top),e.beginPath(),e.rect(0,0,o,l.bounds.height),e.clip(),this.drawScene.setSet(t.set,t.indexOffset),this.drawScene.render(e,o,l.bounds.height,e=>i.logicalToX(e),e=>i.priceToY(e,l.scale,l.bounds)-l.bounds.top),n.push(...this.drawScene.labelTipRegions()),t.tables))!function(e,t,i,o){if(!t.cells.some(e=>e?.some(e=>null!=e&&!e.merged)))return;let r=function(e,t,i){let{span:o,omit:r}=function(e){let t=new Map,i=new Set;for(let o of e.merges){t.set(`${o.startRow}:${o.startCol}`,{cs:o.endCol-o.startCol+1,rs:o.endRow-o.startRow+1});for(let e=o.startRow;e<=o.endRow;e+=1)for(let t=o.startCol;t<=o.endCol;t+=1)(e!==o.startRow||t!==o.startCol)&&i.add(`${e}:${t}`)}for(let o=0;o<e.rows;o+=1)for(let r=0;r<e.columns;r+=1)e.cells[o]?.[r]?.merged&&!t.has(`${o}:${r}`)&&i.add(`${o}:${r}`);for(let e of t.keys())i.delete(e);return{span:t,omit:i}}(t),l=Array(t.columns).fill(0),n=Array(t.rows).fill(0),a=[];for(let e=0;e<t.rows;e+=1)for(let i=0;i<t.columns;i+=1){if(r.has(`${e}:${i}`))continue;let l=t.cells[e]?.[i];if(null==l)continue;let n=o.get(`${e}:${i}`);a.push({cell:l,r:e,c:i,cs:Math.min(n?.cs??1,t.columns-i),rs:Math.min(n?.rs??1,t.rows-e)})}if(0===a.length)return null;let s=t=>{let o=lJ(t.textSize);e.font=l0(t,o,i.theme);let r=(t.text??"").split("\n"),l=0;for(let t of r)l=Math.max(l,e.measureText(t).width);let n=Math.ceil(l)+12,a=Math.ceil(r.length*o*1.2)+4;return t.width&&(n=Math.max(n,t.width/100*i.plotWidth)),t.height&&(a=Math.max(a,t.height/100*i.paneHeight)),{w:n,h:a}},h=[];for(let e of a){let{w:t,h:i}=s(e.cell);1===e.cs&&(l[e.c]=Math.max(l[e.c],t)),1===e.rs&&(n[e.r]=Math.max(n[e.r],i)),(e.cs>1||e.rs>1)&&h.push({box:e,w:t,h:i})}for(let{box:e,w:t,h:i}of h){if(e.cs>1){let i=0;for(let t=e.c;t<e.c+e.cs;t+=1)i+=l[t];if(t>i)for(let o=e.c;o<e.c+e.cs;o+=1)l[o]+=(t-i)/e.cs}if(e.rs>1){let t=0;for(let i=e.r;i<e.r+e.rs;i+=1)t+=n[i];if(i>t)for(let o=e.r;o<e.r+e.rs;o+=1)n[o]+=(i-t)/e.rs}}let d=0;for(let e of l)d+=e;let c=0;for(let e of n)c+=e;return{colW:l,rowH:n,w:d,h:c,boxes:a}}(e,t,i);if(!r||r.w<=0||r.h<=0)return;let l=t.frameColor&&t.frameWidth>0?t.frameWidth:0,{x:n,y:a}=function(e,t,i,o){let r;return r=e.startsWith("top")?6:e.startsWith("bottom")?o.paneHeight-6-i:o.paneHeight/2-i/2,{x:e.endsWith("left")?6:e.endsWith("right")?o.plotWidth-6-t:o.plotWidth/2-t/2,y:r}}(t.position,r.w+2*l,r.h+2*l,i),s=n+l,h=a+l;t.bgColor&&(e.fillStyle=t.bgColor,e.fillRect(s,h,r.w,r.h)),l>0&&t.frameColor&&(e.strokeStyle=t.frameColor,e.lineWidth=l,e.strokeRect(n+l/2,a+l/2,r.w+l,r.h+l));let d=[0];for(let e of r.colW)d.push(d[d.length-1]+e);let c=[0];for(let e of r.rowH)c.push(c[c.length-1]+e);let p=e.textBaseline,u=e.textAlign;for(let t of(e.textBaseline="middle",r.boxes)){let r=s+d[t.c],l=h+c[t.r],n=d[t.c+t.cs]-d[t.c],a=c[t.r+t.rs]-c[t.r],p=t.cell;p.bgColor&&(e.fillStyle=p.bgColor,e.fillRect(r,l,n,a));let u=p.text??"";if(u.length>0){let t=lJ(p.textSize);e.font=l0(p,t,i.theme),e.fillStyle=p.textColor??i.theme.textColor;let o=u.split("\n"),s=o.length*t*1.2,h="top"===p.vAlign?l+2:"bottom"===p.vAlign?l+a-2-s:l+(a-s)/2,d="left"===p.hAlign?r+6:"right"===p.hAlign?r+n-6:r+n/2;e.textAlign=p.hAlign,o.forEach((i,o)=>e.fillText(i,d,h+(o+.5)*t*1.2))}p.tooltip&&o.push({left:r,top:l,right:r+n,bottom:l+a,text:p.tooltip})}if(e.textBaseline=p,e.textAlign=u,t.borderColor&&t.borderWidth>0){e.strokeStyle=t.borderColor,e.lineWidth=t.borderWidth;let i=new Set;e.beginPath();let o=(t,o,r,l)=>{let n=`${t},${o},${r},${l}`;i.has(n)||(i.add(n),e.moveTo(t,o),e.lineTo(r,l))};for(let e of r.boxes){let t=Math.round(s+d[e.c]),i=Math.round(s+d[e.c+e.cs]),r=Math.round(h+c[e.r]),l=Math.round(h+c[e.r+e.rs]);o(t,r,i,r),o(t,l,i,l),o(t,r,t,l),o(i,r,i,l)}e.stroke()}}(e,a,{paneHeight:l.bounds.height,plotWidth:o,theme:r},n);for(let t of(e.restore(),n))this.tips.push({...t,top:t.top+l.bounds.top,bottom:t.bottom+l.bounds.top})}labelTooltipAt(e,t){for(let i=this.tips.length-1;i>=0;i-=1){let o=this.tips[i];if(e>=o.left&&e<=o.right&&t>=o.top&&t<=o.bottom)return o.text}return null}};function l2(e,t,i,o,r,l,n=!1,a=()=>0,s=t9,h=()=>1){let d=1/0,c=-1/0,p=e=>{null!=e&&Number.isFinite(e)&&(e<d&&(d=e),e>c&&(c=e))};if(i)for(let e=o;e<=r;e+=1){let i=t[e];i&&(p(i.high),p(i.low))}for(let t of e){let e=a(t.id),i=h(t.id);if(0===i)continue;let l=1===i?p:e=>p(null!=e?e*i:e);for(let i of t.series)!0!==i.overlay&&l5(i,o,r,e,l);for(let e of t.priceLines)l(e.price)}if(l&&(p(l.min),p(l.max)),d===1/0||c===-1/0)return{min:0,max:1};if(c-d<=1e-12*Math.max(Math.abs(d),Math.abs(c))){let e=(d+c)/2,t=.1*Math.abs(e)||1;return{min:e-t,max:e+t,log:n&&e-t>0}}let u=Math.max(.1,1-(s.top+s.bottom)/100),g=s.top/100/u,m=s.bottom/100/u;if(n&&d>0){let e=Math.log(d),t=Math.log(c),i=t-e;return{min:Math.exp(e-i*m),max:Math.exp(t+i*g),log:!0}}let b=c-d;return{min:d-b*m,max:c+b*g}}function l5(e,t,i,r,l){if((0,o.JVt)(e)){if("candle"===e.kind||"bar"===e.kind)for(let o=t;o<=i;o+=1){let t=e.bars[o-r];t&&(l(t.high),l(t.low))}else if((0,o.xcs)(e)){for(let o=t;o<=i;o+=1)l(e.points[o-r]?.value);"histogram"===e.kind||"columns"===e.kind?l(e.style?.base??0):e.style?.base!=null&&l(e.style.base)}}}var l3=(0,d.AH)`@layer vela.chrome {
299
+
300
+ .vela-marks-panel { padding: 0; gap: 0; min-width: 220px; max-width: 320px; max-height: 320px; overflow-y: auto; overscroll-behavior: contain; }
301
+ .vela-marks-section { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; }
302
+ .vela-marks-section + .vela-marks-section { border-top: 1px solid ${c.t.border}; }
303
+ .vela-marks-field { display: flex; justify-content: space-between; gap: 16px; line-height: 1.45; }
304
+ .vela-marks-field-label { color: ${c.t.fg.muted}; }
305
+ .vela-marks-field-value { color: ${c.t.fg.bright}; text-align: end; font-variant-numeric: tabular-nums; }
306
+ .vela-marks-html { color: ${c.t.fg}; line-height: 1.45; overflow-wrap: anywhere; }
307
+ .vela-marks-html p { margin: 0 0 6px; }
308
+ .vela-marks-html p:last-child { margin-bottom: 0; }
309
+ .vela-marks-html a { color: ${c.t.accent}; }
310
+ .vela-marks-html img { max-width: 100%; height: auto; }
311
+ .vela-marks-html table { border-collapse: collapse; }
312
+ .vela-marks-html td, .vela-marks-html th { padding: 2px 6px; border: 1px solid ${c.t.border}; }
313
+ .vela-marks-html pre, .vela-marks-html code { font-family: var(--vela-font-mono, monospace); font-size: 0.92em; }
314
+ .vela-marks-loading, .vela-marks-error { color: ${c.t.fg.muted}; font-style: italic; }
315
+
316
+ }`,l4={loading:(0,n.ab)("chart.marks.loading","Loading…"),failed:(0,n.ab)("chart.marks.failed","Couldn’t load this entry.")},l6=class{constructor(e){this.deps=e,this.pop=null,this.openKey=null,this.generation=0,this.pressKey=null,this.onPress=()=>{if(null===this.openKey)return;this.pressKey=this.openKey;let e=this.deps.plot.ownerDocument,t=()=>void setTimeout(()=>this.pressKey=null,0);e.addEventListener("pointerup",t,{capture:!0,once:!0}),e.addEventListener("pointercancel",t,{capture:!0,once:!0})};let t=e.plot.ownerDocument;(0,o.ya5)("vela-marks-popover",l3,t),this.anchor=t.createElement("div"),this.anchor.className="vela-marks-anchor",Object.assign(this.anchor.style,{position:"absolute",pointerEvents:"none",left:"0",top:"0",width:"0",height:"0"}),e.plot.appendChild(this.anchor),t.addEventListener("pointerdown",this.onPress,!0)}get key(){return this.openKey}open(e,t){if(this.pressKey===e.key)return;this.close(),this.place(t);let i=++this.generation;this.openKey=e.key,this.pop=new f.AM({trigger:this.anchor,host:this.deps.host(),theme:this.deps.theme(),sideOffset:8,align:"center",fadeMs:120,className:"vela-marks-pop",content:t=>this.build(t,e,i),onClose:()=>{this.generation===i&&(this.openKey=null,this.pop=null,this.deps.onOpenChange?.(null))}}),this.pop.show(),this.deps.onOpenChange?.(e.key)}track(e){if(this.pop){if(!e)return void this.close();this.place(e),this.pop.reposition()}}close(){let e=this.pop,t=null!==this.openKey;this.pop=null,this.openKey=null,this.generation++,e?.destroy(),t&&this.deps.onOpenChange?.(null)}destroy(){this.close(),this.deps.plot.ownerDocument.removeEventListener("pointerdown",this.onPress,!0),this.anchor.remove()}place(e){Object.assign(this.anchor.style,{left:`${e.x-e.size/2}px`,top:`${e.y-e.size/2}px`,width:`${e.size}px`,height:`${e.size}px`})}build(e,t,i){let o=e.ownerDocument,r=o.createElement("div");r.className="vela-callout-panel vela-marks-panel",(0,m.M2)(r,"panel");let l=[];for(let e of t.marks){let t=o.createElement("section");if(t.className="vela-marks-section",e.title){let i=o.createElement("div");i.className="vela-callout-title",(0,m.M2)(i,"title"),i.textContent=e.title,t.appendChild(i)}let a=e.content;if("function"==typeof a){let e=o.createElement("div");e.className="vela-marks-loading",e.textContent=(0,n.b6)(this.deps.i18n?.()??null,l4.loading),t.appendChild(e),l.push({el:t,resolve:()=>this.resolveLazy(a,e,i)})}else void 0!==a&&this.renderContent(t,a);t.childElementCount>0&&r.appendChild(t)}e.appendChild(r),l.length>0&&function(e,t){if("undefined"==typeof IntersectionObserver){for(let e of t)e.resolve();return}let i=new IntersectionObserver(e=>{for(let o of e){if(!o.isIntersecting)continue;let e=t.find(e=>e.el===o.target);e&&(i.unobserve(o.target),e.resolve())}},{root:e});for(let e of t)i.observe(e.el)}(r,l)}resolveLazy(e,t,i){let o;try{o=Promise.resolve(e())}catch(e){o=Promise.reject(e instanceof Error?e:Error(String(e)))}o.then(e=>{if(i!==this.generation)return;let o=t.parentElement;o&&(t.remove(),this.renderContent(o,e),this.pop?.reposition())},()=>{i===this.generation&&(t.className="vela-marks-error",t.textContent=(0,n.b6)(this.deps.i18n?.()??null,l4.failed))})}renderContent(e,t){let i=e.ownerDocument;if(t&&"object"==typeof t){if("text"in t){let o=i.createElement("div");o.className="vela-callout-text",(0,m.M2)(o,"text"),o.textContent=String(t.text),e.appendChild(o);return}if("html"in t){let o=i.createElement("div");o.className="vela-marks-html",o.appendChild(function(e,t){let i=t.createElement("template");i.innerHTML=e;let o=t.createDocumentFragment();return function e(t,i,o){for(let r of Array.from(t.childNodes)){if(3===r.nodeType){i.appendChild(o.createTextNode(r.textContent??""));continue}if(1!==r.nodeType)continue;let t=r.tagName.toLowerCase(),l=function(e){let t=e.toLowerCase();return ti.has(t)?"drop":tt.has(t)?"keep":"unwrap"}(t);if("drop"===l)continue;if("unwrap"===l){e(r,i,o);continue}let n=o.createElement(t);for(let e of Array.from(r.attributes)){let i=e.name.toLowerCase();if(!function(e,t){let i=t.toLowerCase();return!i.startsWith("on")&&"style"!==i&&("title"===i||(to[e.toLowerCase()]?.has(i)??!1))}(t,i))continue;let o=e.value;if("href"===i||"src"===i){let e=tl(o,"src"===i);if(null===e)continue;o=e}n.setAttribute(i,o)}"a"===t&&(n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer")),e(r,n,o),i.appendChild(n)}}(i.content,o,t),o}(String(t.html),i)),e.appendChild(o);return}if("panel"in t&&t.panel&&Array.isArray(t.panel.items)){let o=null;for(let r of t.panel.items)if(r&&"object"==typeof r){if("button"===r.type){o||((o=i.createElement("div")).className="vela-callout-actions",(0,m.M2)(o,"actions"),e.appendChild(o));let t=i.createElement("button");t.type="button",t.className="vela-callout-btn"+(r.primary?" vela-callout-btn-primary":""),(0,m.M2)(t,"button"),r.primary&&(t.dataset.primary=""),t.textContent=r.label,t.addEventListener("click",()=>{r.run(),!1!==r.close&&this.close()}),o.appendChild(t);continue}if(o=null,"text"===r.type){let t=i.createElement("div");t.className="vela-callout-text",(0,m.M2)(t,"text"),t.textContent=r.text,e.appendChild(t)}else if("field"===r.type){let t=i.createElement("div");t.className="vela-marks-field";let o=i.createElement("span");o.className="vela-marks-field-label",o.textContent=r.label;let l=i.createElement("span");l.className="vela-marks-field-value",l.textContent=r.value,t.append(o,l),e.appendChild(t)}}}}}},l8=class{constructor(e=new o_){this.axisTicks=e,this.canvas=null,this.ctx=null}mount(e){this.canvas=e,this.ctx=e.getContext("2d")}destroy(){this.canvas=null,this.ctx=null}render(e,t,i,o){let r=this.ctx,l=this.canvas;if(!r||!l)return;let n=t.dpr;iQ(r,n),r.clearRect(0,0,l.width/n,l.height/n);let a=t.barCount;if(0===a)return;let s=t.visibleLogicalRange();Math.min(a-1,Math.ceil(s.to))<Math.max(0,Math.floor(s.from))||(this.drawHighlights(r,e,t),this.drawGrid(r,e,t,i,t.width,o))}drawHighlights(e,t,i){let o=t.sessionHighlightBands();if(o.length>0){let t=Math.max(0,i.logicalToX(-.5)),r=Math.min(i.width,i.logicalToX(i.barCount-.5));this.drawHighlightSet(e,o,i,t,r,!0)}this.drawHighlightSet(e,t.highlights,i,0,i.width,!1)}drawHighlightSet(e,t,i,o,r,l){let n=e=>l?i.logicalToX(Math.ceil(i.timeToLogical(e))-.5):i.timeToX(e);for(let l of t){let t=function(e,t,i,o){let r=Math.max(i,e),l=Math.min(o,t);return l>r?{x:r,width:l-r}:null}(n(l.from),n(l.to),o,r);t&&(e.fillStyle=l.color,e.fillRect(t.x,0,t.width,i.height))}}drawGrid(e,t,i,o,r,l){let n=t.orderedPanes(),{gridVert:a,gridHorz:s}=t.style,h=a.color??o.gridColor,d=s.color??o.gridColor;if(e.lineWidth=1,t.showGrid&&a.visible){e.globalAlpha=l,e.strokeStyle=h;let o=i.visibleTimeRange(),n=oO((o.from+o.to)/2,oF(t.timezone,i.barInterval));for(let t of(e.beginPath(),oZ(o.from,o.to,8,n,void 0,i.logicalToTime(0)))){let o=Math.round(i.timeToX(t.time))+.5;o<0||o>r||(e.moveTo(o,0),e.lineTo(o,i.height))}e.stroke()}for(let o of n)if(t.showGrid&&s.visible&&!o.collapsed){for(let n of(e.globalAlpha=l,e.strokeStyle=d,e.beginPath(),this.axisTicks.ticksFor(t,o,i))){let t=Math.round(i.priceToY(n.price,o.scale,o.bounds))+.5;t<o.bounds.top||t>o.bounds.top+o.bounds.height||(e.moveTo(0,t),e.lineTo(r,t))}e.stroke()}e.globalAlpha=1}},l7=class{constructor(){this.canvas=null,this.ctx=null}mount(e){this.canvas=e,this.ctx=e.getContext("2d")}destroy(){this.canvas=null,this.ctx=null}render(e){let t=this.ctx,i=this.canvas;if(!t||!i)return;let{bars:o,data:r,visible:l,coords:n,bounds:a,fillPane:s}=e,h=n.dpr;if(iQ(t,h),t.clearRect(0,0,i.width/h,i.height/h),!r||!l||0===o.length||a.height<=0)return;let d=n.visibleLogicalRange(),c=Math.max(0,Math.floor(d.from)),p=Math.min(o.length-1,Math.ceil(d.to));if(c>p)return;let u=0;for(let e=c;e<=p;e+=1){let t=o[e]?.volume;null!=t&&t>u&&(u=t)}u<=0||(t.save(),t.beginPath(),t.rect(0,a.top,n.width,a.height),t.clip(),function(e,t,i,o){let{i0:r,i1:l,xOf:n,halfW:a,bottomY:s,maxH:h,maxVol:d}=i;if(!(d<=0)&&!(h<=0)){e.globalAlpha=.5;for(let i=r;i<=l;i+=1){let r=t[i],l=r?.volume;if(null==r||null==l||!(l>0))continue;let c=Math.max(1,l/d*h);e.fillStyle=r.close>=r.open?o.up:o.down,e.fillRect(n(i)-a,s-c,2*a,c)}e.globalAlpha=1}}(t,o,{i0:c,i1:p,xOf:e=>n.logicalToX(e),halfW:Math.max(.5,Math.floor(.7*n.bodySpacing())/2),bottomY:a.top+a.height,maxH:a.height*(s?.96:r.heightFrac),maxVol:u},{up:r.upColor,down:r.downColor}),t.restore())}};function l9(e,t){let i=e.findIndex(e=>e.id===t);if(i<0||i===e.length-1)return null;let o=e[i+1],r=e[i+2];return r?(o.z+r.z)/2:o.z+1}function ne(e,t){let i=e.findIndex(e=>e.id===t);if(i<=0)return null;let o=e[i-1],r=e[i-2];return r?(r.z+o.z)/2:o.z-1}var nt="vela-attribution-styles",ni=(0,d.AH)`@layer vela.chrome {
317
+
318
+ .vela-attribution {
319
+ text-decoration: none;
320
+ display: flex;
321
+ align-items: center;
322
+ /* No gutter: the V is the wordmark's first letter, and the letters' viewBox starts
323
+ where the V's ends, so the kit's own letter spacing comes with them. */
324
+ gap: 0;
325
+ }
326
+ .vela-attribution .vela-attr-symbol {
327
+ flex: none;
328
+ display: block;
329
+ line-height: 0;
330
+ }
331
+ .vela-attribution .vela-attr-symbol svg {
332
+ height: 24px;
333
+ width: auto;
334
+ display: block;
335
+ filter: drop-shadow(0 1px 2px var(--vela-attr-shadow, rgba(0,0,0,0.45)));
336
+ }
337
+ .vela-attribution .vela-attr-wordmark {
338
+ max-width: 0;
339
+ overflow: hidden;
340
+ opacity: 0;
341
+ display: flex;
342
+ align-items: center;
343
+ /* Same height and baseline as the V (one viewBox height), so no vertical offset. */
344
+ transform: translateX(-8px);
345
+ transition: max-width 0.3s ease, opacity 0.25s ease, transform 0.3s ease;
346
+ flex: none;
347
+ }
348
+ .vela-attribution .vela-attr-wordmark svg {
349
+ height: 24px;
350
+ width: auto;
351
+ display: block;
352
+ filter: drop-shadow(0 1px 2px var(--vela-attr-shadow, rgba(0,0,0,0.45)));
353
+ }
354
+ .vela-attribution:hover .vela-attr-wordmark {
355
+ max-width: 240px;
356
+ opacity: 1;
357
+ transform: translateX(0);
358
+ }
359
+ /* Mobile: a hair smaller so the mark doesn't dominate a phone-width plot. Keyed on the
360
+ renderer's own container attribute (data-vela-layout) AND the shell root's
361
+ (data-layout): the workspace's single grid-wide mark lives OUTSIDE any renderer
362
+ container, so only the shell attribute reaches it. */
363
+ [data-vela-layout='mobile'] .vela-attribution .vela-attr-symbol svg,
364
+ [data-layout='mobile'] .vela-attribution .vela-attr-symbol svg { height: 20px; }
365
+ [data-vela-layout='mobile'] .vela-attribution .vela-attr-wordmark,
366
+ [data-layout='mobile'] .vela-attribution .vela-attr-wordmark { transform: translateX(-6px); }
367
+ [data-vela-layout='mobile'] .vela-attribution .vela-attr-wordmark svg,
368
+ [data-layout='mobile'] .vela-attribution .vela-attr-wordmark svg { height: 20px; }
369
+ [data-vela-layout='mobile'] .vela-attribution:hover .vela-attr-wordmark,
370
+ [data-layout='mobile'] .vela-attribution:hover .vela-attr-wordmark { transform: translateX(0); }
371
+
372
+ }`;function no(e){return(0,p.cP)(e)?"#ffffff":"#000000"}function nr(e,t){let i=(0,p.cP)(t);e.style.color=i?"#ffffff":"#000000",e.style.setProperty("--vela-attr-shadow",i?"rgba(0,0,0,0.45)":"rgba(255,255,255,0.55)")}var nl=(0,n.ab)("chart.attribution","Charting by Vela");function nn(e){if(!e||"transparent"===e)return!1;let t=/rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*,\s*([\d.]+)\s*\)/.exec(e);return!t||parseFloat(t[1])>.001}function na(e,t,i){let o=e.borderTopLeftRadius,r=parseFloat(o)||0;return Math.max(0,Math.min(o.endsWith("%")?r/100*Math.min(t,i):r,Math.min(t,i)/2))}function ns(e,t,i,o,r,l){e.beginPath(),l>0&&"function"==typeof e.roundRect?e.roundRect(t,i,o,r,l):e.rect(t,i,o,r)}function nh(e,t,i){let o=t.ownerDocument.defaultView;if(!o)return;e.save(),e.scale(i.dpr,i.dpr);let r=(t,o,r)=>{let l=t.textContent?.replace(/\s+/g," ").trim();if(!l)return;let n=t.ownerDocument.createRange();n.selectNodeContents(t);let a=n.getBoundingClientRect();a.width<=0||a.height<=0||(e.globalAlpha=r,e.fillStyle=o.color,e.font=`${o.fontStyle} ${o.fontWeight} ${o.fontSize} ${o.fontFamily}`,e.textBaseline="middle",e.textAlign="left",e.fillText(l,a.left-i.left,a.top-i.top+a.height/2))},l=(t,o,r)=>{if(!t.complete||t.naturalWidth<=0||!function(e){try{let t=e.ownerDocument.createElement("canvas");t.width=1,t.height=1;let i=t.getContext("2d");if(!i)return!1;return i.drawImage(e,0,0,1,1),t.toDataURL(),!0}catch{return!1}}(t))return;let l=t.getBoundingClientRect();if(l.width<=0||l.height<=0)return;let n=l.left-i.left,a=l.top-i.top;e.save(),e.globalAlpha=r,ns(e,n,a,l.width,l.height,na(o,l.width,l.height)),e.clip(),e.drawImage(t,n,a,l.width,l.height),e.restore()},n=(t,i)=>{for(let r of t.children){if(r.hasAttribute("transform"))continue;let t=r.tagName.toLowerCase();if("g"===t){n(r,i);continue}let l=e=>parseFloat(r.getAttribute(e)??"0")||0,a=null;if("path"===t){let e=r.getAttribute("d");e&&(a=new Path2D(e))}else if("circle"===t)(a=new Path2D).arc(l("cx"),l("cy"),l("r"),0,2*Math.PI);else if("ellipse"===t)(a=new Path2D).ellipse(l("cx"),l("cy"),l("rx"),l("ry"),0,0,2*Math.PI);else if("rect"===t)(a=new Path2D).rect(l("x"),l("y"),l("width"),l("height"));else if("line"===t)(a=new Path2D).moveTo(l("x1"),l("y1")),a.lineTo(l("x2"),l("y2"));else if("polyline"===t||"polygon"===t){let e=(r.getAttribute("points")??"").trim().split(/[\s,]+/).map(Number);if(e.length<4||e.some(Number.isNaN))continue;(a=new Path2D).moveTo(e[0],e[1]);for(let t=2;t+1<e.length;t+=2)a.lineTo(e[t],e[t+1]);"polygon"===t&&a.closePath()}if(!a)continue;let s=o.getComputedStyle(r);s.fill&&"none"!==s.fill&&nn(s.fill)&&(e.globalAlpha=i*(parseFloat(s.fillOpacity)||1),e.fillStyle=s.fill,e.fill(a));let h=parseFloat(s.strokeWidth)||0;s.stroke&&"none"!==s.stroke&&nn(s.stroke)&&h>0&&(e.globalAlpha=i*(parseFloat(s.strokeOpacity)||1),e.strokeStyle=s.stroke,e.lineWidth=h,("round"===s.strokeLinecap||"square"===s.strokeLinecap||"butt"===s.strokeLinecap)&&(e.lineCap=s.strokeLinecap),("round"===s.strokeLinejoin||"bevel"===s.strokeLinejoin||"miter"===s.strokeLinejoin)&&(e.lineJoin=s.strokeLinejoin),e.stroke(a))}},a=(t,r)=>{let l=t.getBoundingClientRect();if(l.width<=0||l.height<=0)return;let a=o.getComputedStyle(t);if("none"===a.display||"hidden"===a.visibility)return;let s=r*(parseFloat(a.opacity)||1);if(s<=.001)return;let h=t.viewBox.baseVal,d=h&&h.width>0?h.width:l.width,c=h&&h.height>0?h.height:l.height;e.save(),e.translate(l.left-i.left,l.top-i.top),e.scale(l.width/d,l.height/c),h&&e.translate(-h.x,-h.y),n(t,s),e.restore()},s=(t,n)=>{let h=o.getComputedStyle(t);if("none"===h.display||"hidden"===h.visibility)return;let d=n*(parseFloat(h.opacity)||1);if(d<=.001)return;let c=t.getBoundingClientRect();if(c.width>0&&c.height>0){let t=c.left-i.left,o=c.top-i.top,r=na(h,c.width,c.height);nn(h.backgroundColor)&&(e.globalAlpha=d,e.fillStyle=h.backgroundColor,ns(e,t,o,c.width,c.height,r),e.fill());let l=parseFloat(h.borderTopWidth)||0;l>0&&"none"!==h.borderTopStyle&&nn(h.borderTopColor)&&(e.globalAlpha=d,e.strokeStyle=h.borderTopColor,e.lineWidth=l,ns(e,t+l/2,o+l/2,c.width-l,c.height-l,Math.max(0,r-l/2)),e.stroke())}for(let e of t.childNodes)3===e.nodeType?r(e,h,d):e instanceof o.HTMLImageElement?l(e,o.getComputedStyle(e),d):e instanceof o.SVGSVGElement?a(e,d):e instanceof o.HTMLElement&&s(e,d)};t instanceof o.HTMLElement&&s(t,1),e.restore()}function nd(e,t){return e<0?0:e>=t?t-1:e}var nc=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,i=this.canvas;if(!t||!i)return;let{bars:o,data:r,visible:l,coords:n,scale:a,bounds:s,theme:h}=e,d=n.dpr;if(iQ(t,d),t.clearRect(0,0,i.width/d,i.height/d),!r||!l||0===o.length||s.height<=0)return;let c=n.visibleLogicalRange(),p=Math.max(0,Math.floor(c.from)),u=Math.min(o.length-1,Math.ceil(c.to));if(p>u)return;let g=o[u],m=`${p}:${u}:${o.length}:${g.high}:${g.low}:${g.close}:${g.volume??0}:${r.rows}:${r.valueAreaFrac}`;m!==this.memoKey&&(this.memoKey=m,this.memo=function(e,t,i,o,r){let l=Math.max(0,t),n=Math.min(e.length-1,i);if(l>n)return null;let a=1/0,s=-1/0;for(let t=l;t<=n;t+=1){let i=e[t];null!=i.volume&&i.volume>0&&(i.low<a&&(a=i.low),i.high>s&&(s=i.high))}if(!Number.isFinite(a))return null;let h=s>a?Math.max(1,Math.round(o)):1,d=s>a?(s-a)/h:1,c=Array.from({length:h},(e,t)=>({price:a+t*d,up:0,down:0}));for(let t=l;t<=n;t+=1){let i=e[t],o=i.volume;if(!(null!=o&&o>0))continue;let r=i.close>=i.open?"up":"down",l=i.high-i.low;if(l<=0){let e=nd(Math.floor((i.low-a)/d),h);c[e][r]+=o;continue}let n=nd(Math.floor((i.low-a)/d),h),s=nd(Math.floor((i.high-a)/d-1e-9),h);for(let e=n;e<=s;e+=1){let t=a+e*d,n=Math.min(i.high,t+d)-Math.max(i.low,t);n>0&&(c[e][r]+=o*n/l)}}let p=0,u=0,g=0;for(let e=0;e<h;e+=1){let t=c[e].up+c[e].down;p+=t,t>u&&(u=t,g=e)}if(u<=0)return null;let m=p*Math.min(1,Math.max(0,r)),b=g,f=g,v=u;for(;v<m&&(b>0||f<h-1);){let e=b>0?c[b-1].up+c[b-1].down:-1,t=f<h-1?c[f+1].up+c[f+1].down:-1;t>e?(f+=1,v+=t):(b-=1,v+=e)}return{rows:c,rowH:d,min:a,maxTotal:u,poc:g,vaFrom:b,vaTo:f}}(o,p,u,r.rows,r.valueAreaFrac));let b=this.memo;b&&(t.save(),t.beginPath(),t.rect(0,s.top,n.width,s.height),t.clip(),function(e,t,i,o){let{rows:r,rowH:l,maxTotal:n,poc:a,vaFrom:s,vaTo:h}=t,{rightX:d,maxW:c,yOf:p}=i;if(!(n<=0)&&!(c<=0)){for(let t=0;t<r.length;t+=1){let i=r[t],a=i.up+i.down;if(a<=0)continue;let u=p(i.price+l),g=Math.max(1,p(i.price)-u-1),m=a/n*c,b=i.up/a*m;e.globalAlpha=t>=s&&t<=h?.62:.28,b>0&&(e.fillStyle=o.upColor,e.fillRect(d-m,u,b,g)),m-b>0&&(e.fillStyle=o.downColor,e.fillRect(d-m+b,u,m-b,g))}if(o.showPoc){let t=r[a],i=p(t.price+l),n=Math.max(1,p(t.price)-i-1);e.globalAlpha=.9,e.strokeStyle=o.pocColor,e.lineWidth=1,e.strokeRect(d-c+.5,i+.5,c-1,n)}e.globalAlpha=1}}(t,b,{rightX:n.width,maxW:n.width*r.widthFrac,yOf:e=>n.priceToY(e,a,s)},{upColor:r.upColor,downColor:r.downColor,showPoc:r.showPoc,pocColor:h.textColor}),t.restore())}},np="price";function nu(){return"undefined"!=typeof performance?performance.now():Date.now()}var ng={chartSettings:(0,n.ab)("chart.settingsButton","Chart settings"),scrollToLatest:(0,n.ab)("chart.scrollToLatest.label","Scroll to most recent bar"),scrollToLatestTitle:(0,n.ab)("chart.scrollToLatest.title","Scroll to most recent bar (Alt+Shift+→)"),mainChart:(0,n.ab)("chart.pane.mainChart","Main chart"),pane:(0,n.ab)("chart.pane.numbered","Panel {n}"),keyboardHelp:(0,n.ab)("chart.a11y.keyboardHelp","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."),barSummary:(0,n.ab)("chart.a11y.barSummary","Open {open}, High {high}, Low {low}, Close {close}"),valueSummary:(0,n.ab)("chart.a11y.valueSummary","{name} {value}")},nm=class{constructor(e){this.capabilities=tX,this.appTheme=H,this.surfaceBackground=H.background,this.surfaceTextColor=H.textColor,this.i18n=null,this.rootAttrs={lang:null,dir:null},this.toolbarGutter=0,this.mountContainer=null,this.shadeRightEl=null,this.shadeRightSig="",this.userDrawings=null,this.priceAxisTicks=new o_,this.backdropRenderer=new l8(this.priceAxisTicks),this.volumeRenderer=new l7,this.extLayers=[],this.layerOrderSig="",this.attributionEl=null,this.attributionEnabled=!0,this.attributionHtml=null,this.vpvrRenderer=new nc,this.resizeObserver=null,this.dprMedia=null,this.plotDeviceSize=null,this.coords=new i_,this.scene=new ol,this.backendMode="auto",this.glowAmount=0,this.chrome=new o6(this.priceAxisTicks),this.indicatorSlices=new l1,this.labelTooltip=null,this.markPopover=null,this.marksExpandedBy="hover",this.markPulseRaf=null,this.markClickCbs=new Set,this.crosshairLayer=new ri,this.hostClock=null,this.ownClock=null,this.countdownUnsub=null,this.symbolPicker=null,this.indicatorTitlesOn=!0,this.indicatorValuesOn=!0,this.legendActionsProvider=null,this.drawingActionsProvider=null,this.legendCalloutsProvider=null,this.legendOverviewAction=null,this.keyboard=null,this.keyboardEnabled=!0,this.historyChordsEnabled=!0,this.liveRegion=null,this.animZoom=new i1(70),this.animPan=new i1(110),this.animScroll=new i1(130),this.animAutoscale=new i1(80),this.animLiveBar=new i1(90,0),this.candleUp=r.cr,this.candleDown=r.TV,this.intro={style:"settle",duration:650},this.introOnStyle="settle",this.introPlayed=!1,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=!1,this.paintedData=!1,this.skeletonClockMs=0,this.candleBodyAlpha=1,this.candleStructureAlpha=1,this.lastPointer=null,this.volumeActive=!1,this.volumeHidden=!1,this.vpvrActive=!1,this.vpvrHidden=!1,this.liveEaseTime=0,this.liveEaseHigh=0,this.liveEaseLow=0,this.liveEaseClose=0,this.axisDragEnabled=!0,this.freePanOn=!1,this.freePanTrigger="drag",this.scaleDragHolder=null,this.scaleDragHeight=0,this.scaleDragStart=null,this.paneResizeEnabled=!0,this.resizeAbove=null,this.resizeBelow=null,this.resizeSplitStart=null,this.resizeStartAboveWeight=0,this.drawingsInteractive=!0,this.hoverSeparatorY=null,this.maximizedPaneId=null,this.rightAxisW=64,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=!1,this.scrollButton=null,this.pointerNearScrollBtn=!1,this.scrollTargetRO=null,this.scrollBtnBottomPx=36,this.scrollBtnRightPx=76,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.factoryTheme=H,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.priceStyleWillChangeCbs=new Set,this.chosenStyle="candles",this.symbolFacts=null,this.name="native",this.features=["logScale","currentPriceLine","priceLabel","countdown","indicatorValueLabels","indicatorNameLabels","upColor","downColor","glow","animZoom","animPan","animScroll","animAutoscale","animLiveBar","intro","zoomAnchor","axisDrag","paneResize","freePan","candleZOrder","candleVisible","seriesOrder","highlights","sessionZones","gridlines","axisLabels","scaleMode","invertScale","scalePriceOnly","paneScales","autoScale","timezone","keyboard","historyChords","priceStyle","shownPriceStyle","priceBaseline","baselinePrice","previousClose","settings","attribution","dialogHost","tradeMarkers","marks","indicatorTitles","indicatorValues","crosshairOverride","drawingsInteractive","priceAxisTicks"],this.onScrollProximityMove=e=>{if(!this.scrollButton||!this.plot)return;let t=this.plot.getBoundingClientRect(),i=t.width-this.scrollBtnRightPx-13,o=t.height-this.scrollBtnBottomPx-13,r=120>=Math.hypot(e.clientX-t.left-i,e.clientY-t.top-o);r!==this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=r,this.updateScrollToRealtimeButton())},this.onScrollProximityLeave=()=>{this.pointerNearScrollBtn&&(this.pointerNearScrollBtn=!1,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.chosenStyle=e.priceStyle,this.scene.priceStyle=e.priceStyle,this.scene.basePainting=ii(e.priceStyle),this.scene.candleOverride=il(e.priceStyle,this.scene.style.chartTypes),"function"==typeof e.priceAxisTicks&&this.priceAxisTicks.setHook(e.priceAxisTicks),void 0!==e.freePan&&this.applyFreePan(e.freePan)),this.theme=this.deriveTheme(H)}applyFeature(e,t){switch(e){case"logScale":if(t&&"object"==typeof t)return void this.setPaneLog(t.pane??np,!!t.value);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"indicatorValueLabels":this.scene.showIndicatorValueLabels=!!t;break;case"indicatorNameLabels":this.scene.showIndicatorNameLabels=!!t;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(e7(t,70));return;case"animPan":{let e=e7(t,110);this.animPan.set(e),this.animScroll.toggle(e>0);return}case"animScroll":this.animScroll.set(e7(t,130));return;case"animAutoscale":this.animAutoscale.set(e7(t,80));return;case"animLiveBar":this.animLiveBar.set(e9(t));return;case"intro":this.setIntro(te(t)),this.intro.style&&this.playIntro();return;case"zoomAnchor":this.zoomAnchorMode="right"===t?"right":"cursor",this.input&&(this.input.rightEdgeZoom="right"===this.zoomAnchorMode);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"freePan":this.applyFreePan(t);return;case"candleZOrder":this.scene.candleZ=Number(t)||0;break;case"candleVisible":this.scene.candlesHidden=!1===t;break;case"seriesOrder":this.applySeriesOrder(t);break;case"highlights":this.scene.highlights=function(e){if(!Array.isArray(e))return[];let t=[];for(let i of e){if(!i||"object"!=typeof i)continue;let e=Number(i.from),o=Number(i.to);Number.isFinite(e)&&Number.isFinite(o)&&!(o<=e)&&t.push({from:e,to:o,color:"string"==typeof i.color?i.color:"rgba(120,130,160,0.10)"})}return t.sort((e,t)=>e.from-t.from)}(t);break;case"sessionZones":this.scene.sessionZones=function(e){if(null==e||"object"!=typeof e)return null;let t=e=>{if(!Array.isArray(e))return[];let t=[];for(let i of e){if(!Array.isArray(i))continue;let e=Number(i[0]),o=Number(i[1]);Number.isFinite(e)&&Number.isFinite(o)&&o>e&&t.push([e,o])}return t.sort((e,t)=>e[0]-t[0])};return{pre:t(e.pre),post:t(e.post),extended:t(e.extended)}}(t);break;case"gridlines":this.scene.showGrid=!!t;break;case"axisLabels":this.scene.showAxisLabels=!!t;break;case"scaleMode":if(t&&"object"==typeof t)return void this.setPaneScaleMode(t.pane??np,nv(t.mode));this.scene.scaleMode=nv(t);break;case"invertScale":if(t&&"object"==typeof t)return void this.setPaneInvert(t.pane??np,!!t.value);this.scene.invertScale=!!t;break;case"scalePriceOnly":this.scene.scalePriceOnly=!!t;break;case"autoScale":for(let e of this.scene.panes.values())e.manualScale=t?null:{...e.scale};break;case"timezone":this.scene.timezone="string"==typeof t&&t?t:"UTC";break;case"priceStyle":var i;this.setPriceStyle("string"==typeof(i=t)&&is().includes(i)?t:"candles");break;case"priceBaseline":this.scene.baselineValue=null==t?null:Number(t);break;case"tradeMarkers":this.scene.tradeMarkers=function(e,t){let i=t&&"object"==typeof t?t:{},o=i.colors&&"object"==typeof i.colors?i.colors:{},r=(e,t)=>"boolean"==typeof e?e:t,l=(e,t)=>"string"==typeof e&&e.trim().length>0?e:t;return{visible:r(i.visible,e.visible),labels:r(i.labels,e.labels),qty:r(i.qty,e.qty),colors:{long:l(o.long,e.colors.long),short:l(o.short,e.colors.short),exit:l(o.exit,e.colors.exit)}}}(this.scene.tradeMarkers,t);break;case"marks":this.scene.marks=function(e,t){if("boolean"==typeof t)return{visible:t,groups:{...e.groups}};let i=t&&"object"==typeof t?t:{},o=i.groups&&"object"==typeof i.groups?i.groups:{},r={...e.groups};for(let[e,t]of Object.entries(o))"boolean"==typeof t&&(r[e]=t);return{visible:"boolean"==typeof i.visible?i.visible:e.visible,groups:r}}(this.scene.marks,t),this.markPopover?.close();break;case"crosshairOverride":this.scene.crosshairOverride=function(e){if(!e||"object"!=typeof e)return null;let t={};id(e.vertical)&&(t.vertical=e.vertical),id(e.horizontal)&&(t.horizontal=e.horizontal),ih(e.color)&&(t.color=e.color),ic(e.width)&&(t.width=Math.max(.5,Math.min(8,e.width))),ip(e.style)&&(t.style=e.style),ic(e.opacity)&&(t.opacity=ig(e.opacity));let i=e.shadeRight;return i&&"object"==typeof i&&ih(i.color)&&(t.shadeRight=ic(i.opacity)?{color:i.color,opacity:ig(i.opacity)}:{color:i.color}),Object.keys(t).length>0?t:null}(t);break;case"drawingsInteractive":this.drawingsInteractive=!1!==t,this.input&&(this.input.drawings=this.drawingsInteractive),this.drawingsInteractive||this.userDrawings?.clearHover();return;case"priceAxisTicks":this.priceAxisTicks.setHook("function"==typeof t?t:null);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=!1!==t,this.inputsUI?.setTitlesVisible(this.indicatorTitlesOn);return;case"indicatorValues":this.indicatorValuesOn=!1!==t,this.inputsUI?.setValuesVisible(this.indicatorValuesOn);return;case"attribution":this.attributionHtml="string"==typeof t&&t.trim()?t:null,this.attributionEnabled=null!==this.attributionHtml||!!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"indicatorValueLabels":return this.scene.showIndicatorValueLabels;case"indicatorNameLabels":return this.scene.showIndicatorNameLabels;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"freePan":return!!this.freePanOn&&("drag"===this.freePanTrigger||this.freePanTrigger);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"scalePriceOnly":return this.scene.scalePriceOnly;case"paneScales":return this.paneScaleInfos();case"autoScale":{let e=this.scene.orderedPanes().find(e=>"price"===e.kind);return!e||null==e.manualScale}case"timezone":return this.scene.timezone;case"priceStyle":return this.chosenStyle;case"shownPriceStyle":return this.scene.priceStyle;case"priceBaseline":return this.scene.baselineValue;case"baselinePrice":{let e=this.scene.panes.get(np);return e?this.scene.baselinePriceFor(e.scale):this.scene.baselineValue}case"previousClose":{let e=this.hoverLogical??this.bars.length-1,t=this.bars[e-1];return t&&Number.isFinite(t.close)?t.close:null}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"crosshairOverride":return this.scene.crosshairOverride?{...this.scene.crosshairOverride}:null;case"drawingsInteractive":return this.drawingsInteractive;case"priceAxisTicks":return this.priceAxisTicks.hook;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){"volume"===e?this.scene.volumeLayer=t??null:"vpvr"===e?this.scene.vpvrLayer=t??null:e.endsWith("-pending")?this.scene.nativePending.set(e.slice(0,-8),t??[]):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,i=t.createElement("div");i.className="vela-loading",Object.assign(i.style,{position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",gap:"7px",pointerEvents:"none"});for(let e=0;e<3;e+=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:-(260*e)}),i.appendChild(o)}this.wrapper.appendChild(i),this.loadingEl=i}setPricePrecision(e){let t="number"==typeof e&&e>0?e:void 0;t!==this.scene.priceMintick&&(this.scene.priceMintick=t,this.scheduler?.invalidate(4))}setSymbolFacts(e){this.symbolFacts=e?{...e}:null;let t=this.scene.priceStyle;this.showPriceStyle(),this.scene.priceStyle!==t&&this.scheduler?.invalidate(4),this.settingsDialog?.isOpen()&&this.settingsDialog.refresh(this.getConfig())}setSymbolName(e){this.scene.symbolName!==e&&(this.scene.symbolName=e,this.scheduler?.invalidate(2))}unavailablePriceStyles(){return is().filter(e=>!(0,o.hGA)(e,this.symbolFacts))}getConfig(){let e=this.scene.style,t=Object.fromEntries(Object.entries(e.chartTypes).map(([e,t])=>[e,{...t}])),i=this.theme;return{version:1,chartTypes:t,layout:{background:i.background,textColor:i.textColor,fontFamily:i.fontFamily,fontSize:e.fontSize},grid:{vertLines:{visible:e.gridVert.visible,color:e.gridVert.color??i.gridColor},horzLines:{visible:e.gridHorz.visible,color:e.gridHorz.color??i.gridColor}},crosshair:{color:e.crosshair.color??i.textColor,width:e.crosshair.width,style:e.crosshair.style,opacity:e.crosshair.opacity,labelBackground:e.crosshair.labelBackground??i.textColor},priceScale:{mode:this.scene.scaleMode,log:this.scene.logScale,invert:this.scene.invertScale,priceOnly:this.scene.scalePriceOnly,freePan:this.freePanOn,borderColor:e.borderColor??i.borderColor,labelsVisible:this.scene.showAxisLabels,currentPriceLine:this.scene.showPriceLine,priceLabel:this.scene.showPriceLabel,countdown:this.scene.showCountdown,indicatorValueLabels:this.scene.showIndicatorValueLabels,indicatorNameLabels:this.scene.showIndicatorNameLabels,animateLastPrice:this.animLiveBar.on},animations:{zoom:this.animZoom.on,pan:this.animPan.on,autoscale:this.animAutoscale.on,intro:!1!==this.intro.style},panes:{separatorColor:e.separatorColor??i.borderColor},margins:{...e.margins},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:e,z:t})=>[e,t]))},area:(()=>{let t=e.area.lineColor??this.candleUp;return{lineColor:t,width:e.area.width,topColor:e.area.topColor??t,bottomColor:e.area.bottomColor??"rgba(0,0,0,0)"}})(),baseline:(()=>{let t=e.baseline.topLineColor??t4,i=e.baseline.bottomLineColor??t6;return{topLineColor:t,bottomLineColor:i,topFillColor:e.baseline.topFillColor??(0,p.fu)(t,.25),topFillColor2:e.baseline.topFillColor2??(0,p.fu)(t,.05),bottomFillColor:e.baseline.bottomFillColor??(0,p.fu)(i,.25),bottomFillColor2:e.baseline.bottomFillColor2??(0,p.fu)(i,.05),width:e.baseline.width,baselineLevel:e.baseline.baselineLevel}})(),columns:(()=>{let t=iy({upColor:this.candleUp,downColor:this.candleDown});return{upColor:e.columns.upColor??t.upColor,downColor:e.columns.downColor??t.downColor}})(),series:{style:this.chosenStyle,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=function(e,t){var i,o,r,l,n;let a=iu(t),s=iu(a.chartTypes),h={...e.chartTypes};for(let[e,t]of Object.entries(s))h[e]={...h[e]??{},...iu(t)};let d=iu(a.layout),c=iu(a.grid),p=iu(c.vertLines),u=iu(c.horzLines),g=iu(a.crosshair),m=iu(a.priceScale),b=iu(a.animations),f=iu(a.panes),v=iu(a.margins),y=iu(a.trades),w=iu(a.timeScale),C=iu(a.marks),x=iu(C.groups),k=iu(a.candles),S=iu(a.bars),T=iu(a.line),M=iu(a.area),L=iu(a.baseline),A=iu(a.columns),P=iu(a.series),I=iu(a.sessions),E=iu(a.stacking),B=iu(E.series);return{version:1,chartTypes:h,layout:{background:ih(d.background)?d.background:e.layout.background,textColor:ih(d.textColor)?d.textColor:e.layout.textColor,fontFamily:ih(d.fontFamily)?d.fontFamily:e.layout.fontFamily,fontSize:ic(d.fontSize)?Math.max(6,Math.min(32,d.fontSize)):e.layout.fontSize},grid:{vertLines:{visible:id(p.visible)?p.visible:e.grid.vertLines.visible,color:ih(p.color)?p.color:e.grid.vertLines.color},horzLines:{visible:id(u.visible)?u.visible:e.grid.horzLines.visible,color:ih(u.color)?u.color:e.grid.horzLines.color}},crosshair:{color:ih(g.color)?g.color:e.crosshair.color,width:ic(g.width)?Math.max(.5,Math.min(8,g.width)):e.crosshair.width,style:ip(g.style)?g.style:e.crosshair.style,opacity:ic(g.opacity)?ig(g.opacity):e.crosshair.opacity,labelBackground:ih(g.labelBackground)?g.labelBackground:e.crosshair.labelBackground},priceScale:{mode:"price"===(i=m.mode)||"percent"===i||"indexed"===i?m.mode:e.priceScale.mode,log:id(m.log)?m.log:e.priceScale.log,invert:id(m.invert)?m.invert:e.priceScale.invert,priceOnly:id(m.priceOnly)?m.priceOnly:e.priceScale.priceOnly,freePan:id(m.freePan)?m.freePan:e.priceScale.freePan,borderColor:ih(m.borderColor)?m.borderColor:e.priceScale.borderColor,labelsVisible:id(m.labelsVisible)?m.labelsVisible:e.priceScale.labelsVisible,currentPriceLine:id(m.currentPriceLine)?m.currentPriceLine:e.priceScale.currentPriceLine,priceLabel:id(m.priceLabel)?m.priceLabel:e.priceScale.priceLabel,countdown:id(m.countdown)?m.countdown:e.priceScale.countdown,indicatorValueLabels:id(m.indicatorValueLabels)?m.indicatorValueLabels:e.priceScale.indicatorValueLabels,indicatorNameLabels:id(m.indicatorNameLabels)?m.indicatorNameLabels:e.priceScale.indicatorNameLabels,animateLastPrice:id(m.animateLastPrice)?m.animateLastPrice:e.priceScale.animateLastPrice},animations:{zoom:id(b.zoom)?b.zoom:e.animations.zoom,pan:id(b.pan)?b.pan:e.animations.pan,autoscale:id(b.autoscale)?b.autoscale:e.animations.autoscale,intro:id(b.intro)?b.intro:e.animations.intro},panes:{separatorColor:ih(f.separatorColor)?f.separatorColor:e.panes.separatorColor},margins:{top:ic(v.top)?ib(v.top):e.margins.top,bottom:ic(v.bottom)?ib(v.bottom):e.margins.bottom,right:ic(v.right)?Math.round((o=v.right)<0?0:o>200?200:o):e.margins.right},trades:{visible:id(y.visible)?y.visible:e.trades.visible,labels:id(y.labels)?y.labels:e.trades.labels,qty:id(y.qty)?y.qty:e.trades.qty,longColor:ih(y.longColor)?y.longColor:e.trades.longColor,shortColor:ih(y.shortColor)?y.shortColor:e.trades.shortColor,exitColor:ih(y.exitColor)?y.exitColor:e.trades.exitColor},timeScale:{timezone:"string"==typeof w.timezone&&w.timezone?w.timezone:e.timeScale.timezone},marks:{visible:id(C.visible)?C.visible:e.marks.visible,groups:{...e.marks.groups,...Object.fromEntries(Object.entries(x).filter(([,e])=>id(e)))}},candles:{upColor:ih(k.upColor)?k.upColor:e.candles.upColor,downColor:ih(k.downColor)?k.downColor:e.candles.downColor,bodyVisible:id(k.bodyVisible)?k.bodyVisible:e.candles.bodyVisible,borderVisible:id(k.borderVisible)?k.borderVisible:e.candles.borderVisible,borderUpColor:ih(k.borderUpColor)?k.borderUpColor:e.candles.borderUpColor,borderDownColor:ih(k.borderDownColor)?k.borderDownColor:e.candles.borderDownColor,wickVisible:id(k.wickVisible)?k.wickVisible:e.candles.wickVisible,wickUpColor:ih(k.wickUpColor)?k.wickUpColor:e.candles.wickUpColor,wickDownColor:ih(k.wickDownColor)?k.wickDownColor:e.candles.wickDownColor},bars:{upColor:ih(S.upColor)?S.upColor:e.bars.upColor,downColor:ih(S.downColor)?S.downColor:e.bars.downColor},line:{color:ih(T.color)?T.color:e.line.color,width:ic(T.width)?im(T.width):e.line.width},area:{lineColor:ih(M.lineColor)?M.lineColor:e.area.lineColor,width:ic(M.width)?im(M.width):e.area.width,topColor:ih(M.topColor)?M.topColor:e.area.topColor,bottomColor:ih(M.bottomColor)?M.bottomColor:e.area.bottomColor},baseline:{topLineColor:ih(L.topLineColor)?L.topLineColor:e.baseline.topLineColor,bottomLineColor:ih(L.bottomLineColor)?L.bottomLineColor:e.baseline.bottomLineColor,topFillColor:ih(L.topFillColor)?L.topFillColor:e.baseline.topFillColor,topFillColor2:ih(L.topFillColor2)?L.topFillColor2:e.baseline.topFillColor2,bottomFillColor:ih(L.bottomFillColor)?L.bottomFillColor:e.baseline.bottomFillColor,bottomFillColor2:ih(L.bottomFillColor2)?L.bottomFillColor2:e.baseline.bottomFillColor2,width:ic(L.width)?im(L.width):e.baseline.width,baselineLevel:ic(L.baselineLevel)?(r=L.baselineLevel)<0?0:r>100?100:r:e.baseline.baselineLevel},columns:{upColor:ih(A.upColor)?A.upColor:e.columns.upColor,downColor:ih(A.downColor)?A.downColor:e.columns.downColor},series:{style:"string"==typeof(l=P.style)&&is().includes(l)?P.style:e.series.style,baseline:null===P.baseline?null:ic(P.baseline)?P.baseline:e.series.baseline,spacing:ic(P.spacing)?(n=P.spacing)<.1?.1:n>10?10:n:e.series.spacing},sessions:{premarketColor:ih(I.premarketColor)?I.premarketColor:e.sessions.premarketColor,postmarketColor:ih(I.postmarketColor)?I.postmarketColor:e.sessions.postmarketColor,extendedColor:ih(I.extendedColor)?I.extendedColor:e.sessions.extendedColor},stacking:{candles:ic(E.candles)?E.candles:e.stacking.candles,series:{...e.stacking.series,...Object.fromEntries(Object.entries(B).filter(([,e])=>ic(e)))}}}}(this.getConfig(),e),i=this.scene.style;for(let[e,o]of Object.entries(t.chartTypes))if(JSON.stringify(i.chartTypes[e])!==JSON.stringify(o))for(let t of(this.scene.nativeData.set(`${e}-settings`,{...o}),this.chartTypeSettingsCbs))t(e,{...o});i.chartTypes=Object.fromEntries(Object.entries(t.chartTypes).map(([e,t])=>[e,{...t}]));let o=e&&"object"==typeof e?e.layout:void 0,r=o&&"object"==typeof o?o.textColor:void 0,l="string"==typeof r&&r.trim().length>0,n=this.theme,a={textColor:t.layout.textColor,gridColor:n.gridColor,borderColor:n.borderColor};if(!l&&(0,p.cP)(t.layout.textColor)===(0,p.cP)(t.layout.background)){let e=(0,p.cP)(t.layout.background)?H:W;a={textColor:e.textColor,gridColor:e.gridColor,borderColor:e.borderColor}}this.theme={...this.theme,background:t.layout.background,textColor:a.textColor,gridColor:a.gridColor,borderColor:a.borderColor,fontFamily:t.layout.fontFamily},i.fontSize=t.layout.fontSize;let s=(e,t,i)=>null===e&&t===i?null:t;for(let[e,o]of(i.gridVert={visible:t.grid.vertLines.visible,color:s(i.gridVert.color,t.grid.vertLines.color,n.gridColor)},i.gridHorz={visible:t.grid.horzLines.visible,color:s(i.gridHorz.color,t.grid.horzLines.color,n.gridColor)},i.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,this.scene.scalePriceOnly=t.priceScale.priceOnly,this.freePanOn=t.priceScale.freePan,this.input&&(this.input.freePan=!!this.freePanOn&&this.freePanTrigger),i.borderColor=s(i.borderColor,t.priceScale.borderColor,n.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.scene.showIndicatorValueLabels=t.priceScale.indicatorValueLabels,this.scene.showIndicatorNameLabels=t.priceScale.indicatorNameLabels,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,duration:this.intro.duration||650},i.separatorColor=s(i.separatorColor,t.panes.separatorColor,n.borderColor),t.margins.right!==i.margins.right&&this.coords.barCount>0&&this.applyViewport({barSpacing:this.coords.getViewport().barSpacing,rightOffset:t.margins.right}),i.margins={...t.margins},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,i.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,Object.entries(t.stacking.series)))this.scene.setIndicatorZ(e,o);for(let e of(this.syncLegendOrder(),i.bars={upColor:t.bars.upColor,downColor:t.bars.downColor},i.line={color:t.line.color,width:t.line.width},i.area={lineColor:t.area.lineColor,width:t.area.width,topColor:t.area.topColor,bottomColor:t.area.bottomColor},i.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},i.columns={upColor:t.columns.upColor,downColor:t.columns.downColor},i.sessions={premarketColor:t.sessions.premarketColor,postmarketColor:t.sessions.postmarketColor,extendedColor:t.sessions.extendedColor},this.setPriceStyle(t.series.style),this.scene.candleOverride=il(this.scene.priceStyle,i.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&&(e$(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),this.configChangedCbs))e()}applySeriesOrder(e){e&&"object"==typeof e&&"string"==typeof e.id&&("number"==typeof e.z?this.scene.setIndicatorZ(e.id,e.z):"front"===e.to?this.scene.bringIndicatorToFront(e.id):"back"===e.to&&this.scene.sendIndicatorToBack(e.id),this.syncLegendOrder())}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 rk(this.dialogHost??this.plot,this.theme,()=>this.i18n??(0,n.Db)()))):(this.settingsButton?.style.setProperty("display","none"),this.settingsDialog?.close())}makeSettingsButton(){let e=document.createElement("button");return e.type="button",e.title=this.t(ng.chartSettings),e.innerHTML=(0,l.N0)("gear",14),Object.assign(e.style,{position:"absolute",bottom:"32px",right:"74px",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 rk(this.dialogHost??this.plot,this.theme,()=>this.i18n??(0,n.Db)()),this.settingsDialog.setLayoutMode(this.layoutMode)),this.toggleSettingsDialog(e)}syncThemeControl(){let e=function(e){let t=Y(e);for(let e of q.values())if(Y(K(e.theme))===t)return e.id;return null}(this.appTheme)??((0,p.cP)(this.surfaceBackground)?"dark":"light");this.settingsDialog?.setThemeControl(e,e=>{for(let t of this.themeSelectCbs)t(e)})}toggleSettingsDialog(e){if(this.settingsDialog){if(void 0!==e&&this.settingsDialog.isOpen())return void this.settingsDialog.showSection(e);this.settingsDialog.setTheme(this.theme),this.settingsDialog.setHostSections(this.hostSettingsSections),this.settingsDialog.setMarkGroups(this.markGroupsForEventsTab(),e=>{var t,i;return t=this.scene.marks,i=this.scene.markGroups,or(t.groups,e,i)},e=>oo(this.scene.marks.groups,e,this.scene.markGroups)),this.settingsDialog.setHiddenSettings(this.hiddenSettings),this.settingsDialog.setPriceStyleState(()=>({shown:this.scene.priceStyle,unavailable:this.unavailablePriceStyles()})),this.syncThemeControl(),this.settingsDialog.toggle(this.getConfig(),e=>this.applyConfig(e),e=>this.applyConfig(e),()=>{this.factoryConfig&&this.applyConfig(this.factoryResetDocument(this.factoryConfig)),this.settingsDialog?.refresh(this.getConfig())},e)}}factoryResetDocument(e){let t=function(e,t,i){let o=iv(t,i),r=iw(t,i),{candles:l,bars:n,line:a,area:s,columns:h}=e;return{...e,candles:{...l,upColor:o(l.upColor),downColor:o(l.downColor),borderUpColor:o(l.borderUpColor),borderDownColor:o(l.borderDownColor),wickUpColor:o(l.wickUpColor),wickDownColor:o(l.wickDownColor)},bars:{upColor:o(n.upColor),downColor:o(n.downColor)},line:{...a,color:o(a.color)},area:{...s,lineColor:o(s.lineColor),topColor:o(s.topColor)},columns:{upColor:r(h.upColor),downColor:r(h.downColor)}}}(function(e,t=e.series.style){let i={};for(let e of(0,o.AHy)()){let t=e.settings;if(!t)continue;let r={},l=e=>{for(let t of e??[])for(let e of(0,o.JwL)(t))r[e.key]=e.defval};for(let e of t.instances??[])e.enableKey&&(r[e.enableKey]=!1),l(e.rows);for(let e of t.subsections??[])e.enableKey&&(r[e.enableKey]=!1),l(e.rows);t.instances||l(t.rows),i[e.id]=r}for(let e of(0,o.AHy)()){if(!io(e.id))continue;let t=i[e.id]??{};for(let e of ir)t[e]=null;i[e.id]=t}for(let[t,o]of Object.entries(e.chartTypes))i[t]={...i[t]??{},...o};return{...e,chartTypes:i,series:{...e.series,style:t}}}(e,this.chosenStyle),this.factoryTheme,this.appTheme),i={...t.marks.groups};for(let e of this.markGroupsInUse())i[e.id]=!1!==e.visible;return{...t,marks:{...t.marks,groups:i}}}closeDialogs(){this.inputsUI?.closeOpenDialog(),this.settingsDialog?.close()}makeScrollToRealtimeButton(){let e=document.createElement("button");return e.type="button",e.title=this.t(ng.scrollToLatestTitle),e.setAttribute("aria-label",this.t(ng.scrollToLatest)),e.innerHTML=this.scrollButtonIcon(),Object.assign(e.style,{position:"absolute",bottom:"36px",right:"76px",zIndex:"6",width:"26px",height:"26px",boxSizing:"border-box",display:"none",alignItems:"center",justifyContent:"center",cursor:"pointer",borderRadius:"5px",border:`1px solid ${this.theme.borderColor}`,boxShadow:"0 2px 8px rgba(0,0,0,0.4)",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(0,l.N0)("chevrons-right",12)}scrollButtonSurface(){return(0,p.fu)(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("mobile"===this.layoutMode){e.style.display=t?"flex":"none";return}e.style.display=t&&this.pointerNearScrollBtn?"flex":"none"}scrollToRealtime(){0!==this.coords.barCount&&this.glideRightOffset(this.scene.style.margins.right)}glideRightOffset(e){let t=this.coords.getViewport();if(!this.animScroll.on)return void this.applyViewport({barSpacing:t.barSpacing,rightOffset:e});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 i=this.plot?.getBoundingClientRect(),o=i&&i.width>0?{left:i.left,top:i.top,dpr:e.width/i.width}:null,r=[...this.mountContainer?.querySelectorAll("[data-vela-screenshot]")??[]];if(o)for(let e of r)"under"===e.getAttribute("data-vela-screenshot")&&nh(t,e,o);for(let e of[...this.canvasPile(),this.chromeCanvas,this.drawingsCanvas])e&&e.width>0&&e.height>0&&t.drawImage(e,0,0);if(o){for(let e of this.plot?.querySelectorAll("[data-vela-pane]")??[])nh(t,e,o);for(let e of r)"under"!==e.getAttribute("data-vela-screenshot")&&nh(t,e,o)}return e}screenshot(){return this.screenshotCanvas()?.toDataURL("image/png")??null}playIntro(){null!=this.introRaf&&cancelAnimationFrame(this.introRaf),this.introRaf=null;let{style:e,duration:t}=this.intro,i=this.bars,o=i.length;if(0===o||!e)return;for(let e of(this.computeScales(),this.scene.panes.values()))e.scale={...e.scaleTarget};this.modelAlpha=0;let r=performance.now(),l=n=>{let a=Math.min(1,(n-r)/t);this.scene.bars=a>=1?i:i.map((t,i)=>this.revealCandle(t,i,a,o,e)),this.paintData(),a<1?this.introRaf=requestAnimationFrame(l):(this.scene.bars=i,this.fadeInModels())};this.introRaf=requestAnimationFrame(l)}fadeInModels(){let e=Math.min(350,this.intro.duration||350),t=performance.now(),i=o=>{this.modelAlpha=Math.min(1,(o-t)/e),this.paintData(),this.modelAlpha<1?this.introRaf=requestAnimationFrame(i):(this.modelAlpha=1,this.introRaf=null)};this.introRaf=requestAnimationFrame(i)}revealCandle(e,t,i,o,r){let l,n=Math.max(0,Math.min(1,(i-t/Math.max(1,o-1)*.55)/.44999999999999996));if("settle"===r){let e=n-1;l=1+2.70158*e*e*e+1.70158*e*e}else{let e=1-n;l=1-e*e*e}let a=e.open;return{...e,high:a+(e.high-a)*l,low:a+(e.low-a)*l,close:a+(e.close-a)*l}}followThemeCandles(e,t){if(e.upColor===t.upColor&&e.downColor===t.downColor)return;let i=iv(e,t),o=this.scene.style;this.candleUp=i(this.candleUp),this.candleDown=i(this.candleDown),o.candle={...o.candle,borderUpColor:i(o.candle.borderUpColor),borderDownColor:i(o.candle.borderDownColor),wickUpColor:i(o.candle.wickUpColor),wickDownColor:i(o.candle.wickDownColor)},o.bars={upColor:i(o.bars.upColor),downColor:i(o.bars.downColor)},o.line={...o.line,color:i(o.line.color)},o.area={...o.area,lineColor:i(o.area.lineColor),topColor:i(o.area.topColor)};let r=iw(e,t);o.columns={upColor:r(o.columns.upColor),downColor:r(o.columns.downColor)}}deriveTheme(e){return{...e,upColor:this.candleUp,downColor:this.candleDown}}chromeTheme(){return{...this.theme,background:this.surfaceBackground,textColor:this.surfaceTextColor,borderColor:(0,p.cP)(this.surfaceBackground)?H.borderColor:W.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.appTheme=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"}),e$(this.wrapper,this.chromeTheme()),this.backdropCanvas=this.createPlotCanvas(),this.volumeCanvas=this.createPlotCanvas(),this.dataCanvas=this.createGeometryBackend(),this.vpvrCanvas=this.createPlotCanvas(),this.chromeCanvas=this.createPlotCanvas(),this.drawingsCanvas=this.createPlotCanvas(),this.cursorCanvas=this.createPlotCanvas(),this.shadeRightEl=document.createElement("div"),this.shadeRightEl.className="vela-shade-right",this.shadeRightEl.setAttribute("aria-hidden","true"),this.shadeRightEl.hidden=!0,Object.assign(this.shadeRightEl.style,{position:"absolute",top:"0",left:"0",width:"0",height:"0",pointerEvents:"none",display:"none"}),this.shadeRightSig="",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=(0,o.Sw8)().map(e=>({def:e,instance:e.create(),canvas:this.createPlotCanvas(),channel:e.id,owner:null}));let i=this.extLayers.filter(e=>"below-data"===e.def.placement).map(e=>e.canvas),r=this.extLayers.filter(e=>"below-data"!==e.def.placement).map(e=>e.canvas);for(let o of(this.plot.append(this.backdropCanvas,...i,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...r,this.chromeCanvas,this.drawingsCanvas,this.shadeRightEl,this.cursorCanvas,this.overlayRoot),this.layerOrderSig="",this.wrapper.appendChild(this.plot),this.factoryConfig=this.getConfig(),this.factoryTheme=t,this.attributionEl=this.buildAttributionEl(),this.attributionEnabled||(this.attributionEl.style.display="none"),this.positionAttribution(),this.wrapper.appendChild(this.attributionEl),e.appendChild(this.wrapper),this.applyRootAttributes(),this.applyBackground(),this.backdropRenderer.mount(this.backdropCanvas),this.volumeRenderer.mount(this.volumeCanvas),this.vpvrRenderer.mount(this.vpvrCanvas),this.extLayers))o.instance.mount(o.canvas);for(let e of this.scene.indicators.values())this.ensureInstanceLayer(e);this.chrome.mount(this.chromeCanvas),this.crosshairLayer.mount(this.cursorCanvas),this.coords.setViewport(iY()),this.scene.ensurePane(np,"price",0),this.scheduler=new iJ(e=>this.renderFrame(e)),this.animator=new i0(e=>this.animTick(e)),this.targetBarSpacing=this.coords.getViewport().barSpacing,this.input=new i5({getCoords:()=>this.coords,apply:e=>this.applyViewport(e),zoomTo:(e,t,i)=>this.zoomTo(e,t,i),fling:e=>this.fling(e),onPointerMove:(e,t)=>this.handlePointerMove(e,t),onClick:(e,t)=>{this.handleMarkClick(e,t)||(this.userDrawings?.deselect(),this.handleClick(e,t))},onAxisLongPress:(e,t,i)=>{for(let o of this.axisLongPressCbs)o({axis:e,x:t,y:i})},beginPriceScale:(e,t)=>this.beginPriceScale(e,t),priceScaleBy:e=>this.priceScaleBy(e),beginPricePan:(e,t)=>this.beginPricePan(e,t),pricePanBy:e=>this.pricePanBy(e),resetPriceScale:(e,t)=>this.resetPriceScale(e,t),dataDblClick:(e,t)=>this.dataDblClick(e,t),paneSeparatorAt:e=>this.paneSeparatorAt(e),beginPaneResize:e=>this.beginPaneResize(e),paneResizeBy:e=>this.paneResizeBy(e),endPaneResize:()=>this.endPaneResize(),resetPaneSize:e=>this.resetPaneSize(e),resetView:()=>this.resetView(),drawingsClaim:(e,t)=>this.userDrawings?.claim(e,t)??!1,drawingsMeasureStart:(e,t,i)=>this.userDrawings?.beginMeasureAt(e,t,i)??!1,drawingsMarqueeStart:(e,t)=>this.userDrawings?.beginMarqueeAt(e,t)??!1,drawingsDeleteAt:(e,t)=>this.userDrawings?.deleteAt(e,t,!0)??!1,drawingsCancelPlacement:()=>this.userDrawings?.cancelPlacement()??!1,drawingsSnapMode:()=>this.snapMode,drawingsPointerDown:(e,t,i,o,r)=>this.userDrawings?.pointerDown(e,t,i,o,r),drawingsPointerMove:(e,t,i,o,r)=>this.userDrawings?.pointerMove(e,t,i,o,r),drawingsPointerUp:(e,t,i)=>this.userDrawings?.pointerUp(e,t,i),drawingsCursor:(e,t)=>(this.drawingsInteractive?this.userDrawings?.cursorAt(e,t):null)??(this.chrome.markGlyphAt(e,t)?"pointer":null),drawingsDblClick:(e,t)=>this.userDrawings?.dblClick(e,t)??!1,drawingsClearTransient:()=>this.userDrawings?.clearTransient()}),this.input.rightEdgeZoom="right"===this.zoomAnchorMode,this.input.axisDrag=this.axisDragEnabled,this.input.paneResize=this.paneResizeEnabled,this.input.drawings=this.drawingsInteractive,this.input.freePan=!!this.freePanOn&&this.freePanTrigger,this.input.attach(this.dataCanvas),this.settingsEnabled&&this.setSettingsEnabled(!0),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 rt(this.plot,{theme:()=>this.chromeTheme(),lookup:(e,t)=>this.indicatorSlices.labelTooltipAt(e,t)??this.chrome.markTooltipAt(e,t,this.markGroupsInUse(),this.i18n)}),this.markPopover=new l6({i18n:()=>this.i18n??(0,n.Db)(),plot:this.plot,host:()=>this.dialogHost??this.plot,theme:()=>this.chromeTheme(),onOpenChange:e=>{this.scene.marksActiveKey=e,this.scheduler?.invalidate(2)}}),this.chrome.setMarkIconReady(()=>this.scheduler?.invalidate(2)),this.userDrawings=new lX(this.wrapper,this.plot,this.drawingsCanvas,{i18n:()=>this.i18n??(0,n.Db)(),projector:()=>this.drawingProjector(),dpr:()=>this.coords.dpr,theme:()=>this.theme,requestScaleUpdate:()=>this.scheduler.invalidate(3),seriesBoundaries:e=>this.scene.seriesBoundaries(e),priceZ:e=>e===np?this.scene.candleZ:null,requestDataPaint:()=>this.scheduler.invalidate(3),seriesLook:()=>{let e=this.scene.style,t=ia(e.candle,this.scene.candleOverride,this.theme.upColor,this.theme.downColor),i=e.bars.upColor??this.theme.upColor,o=e.bars.downColor??this.theme.downColor,r=this.scene.priceStyle;return{style:r,upColor:"bars"===r?i:t.up,downColor:"bars"===r?o:t.down,lineColor:"area"===r?e.area.lineColor??this.theme.upColor:"columns"===r?(0,p.fu)(e.columns.upColor??this.theme.upColor,1):e.line.color??this.theme.upColor}},chartBarMs:()=>this.coords.barInterval,timeZone:()=>this.scene.timezone,priceDecimals:()=>this.scene.priceMintick?(0,n.a4)(this.scene.priceMintick):null,snap:(e,t,i,o)=>this.snapToCandle(e,t,i,o),setSnapMode:e=>this.setSnapMode(e),setToolbarGutter:e=>this.setToolbarGutter(e)}),this.userDrawings.historyChords=this.historyChordsEnabled,this.userDrawings.setDrawingActions(this.drawingActionsProvider),"mobile"===this.layoutMode&&(this.mountContainer?.setAttribute("data-vela-layout",this.layoutMode),this.userDrawings.setLayoutMode(this.layoutMode),this.scrollButton&&(this.scrollButton.style.width="24px",this.scrollButton.style.height="24px")),this.keyboard=new i3({panByBars:e=>this.panByBars(e),zoomByStep:e=>this.zoomByStep(e),stepCrosshair:e=>this.stepCrosshair(e),jumpToEdge:e=>this.focusBar("first"===e?0:this.coords.barCount-1),resetView:()=>this.resetView(),scrollToRealtime:()=>this.scrollToRealtime(),clearCrosshair:()=>this.handlePointerMove(null,null),preempt:e=>this.userDrawings?.handleKey(e)??!1}),this.setKeyboardEnabled(this.keyboardEnabled),this.inputsUI=new t$(this.plot,t,e=>this.paneBoundsFor(e)),this.inputsUI.setI18n(this.i18n),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(e=>{for(let t of this.inputChangeCbs)t({indicatorId:e.indicatorId,key:e.key,value:e.value,...e.kind?{kind:e.kind}:{}})}),this.inputsUI.setOnRemove(e=>{for(let t of this.removeIndicatorCbs)t(e)}),this.inputsUI.setOnToggleVisible((e,t)=>{for(let i of this.toggleVisibleCbs)i(e,t)}),this.inputsUI.setMoveApi({panes:()=>this.scene.orderedPanes().map((e,t)=>({id:e.id,kind:e.kind,label:"price"===e.kind?this.t(ng.mainChart):this.paneMasterTitle(e.id)??this.t(ng.pane,{n:t}),top:e.bounds.top,height:e.bounds.height})),move:(e,t)=>{for(let i of this.moveIndicatorCbs)i(e,t)}}),this.inputsUI.setStackApi({above:e=>(function(e,t){let i=e.findIndex(e=>e.id===t);if(i<0||i===e.length-1)return null;let o=e[i+1];return null===o.id?"price":{indicator:o.id}})(this.overlayStack(),e),below:e=>(function(e,t){let i=e.findIndex(e=>e.id===t);if(i<=0)return null;let o=e[i-1];return null===o.id?"price":{indicator:o.id}})(this.overlayStack(),e),raise:e=>this.restackOverlay(e,l9),lower:e=>this.restackOverlay(e,ne)}),this.paneControls=new tj(this.plot,t,{i18n:()=>this.i18n??(0,n.Db)(),panes:()=>this.paneControlViews(),rightAxis:()=>this.rightAxisW,onMove:(e,t)=>this.movePaneLocal(e,t),onToggleCollapse:e=>{let t=this.scene.panes.get(e);if(!t)return;let i=!t.collapsed;t.collapsed=i,this.afterPaneLayoutChange(),this.emitPaneAction({type:"collapse",paneId:e,collapsed:i})},onToggleMaximize:e=>{let t=this.maximizedPaneId!==e;this.maximizedPaneId=t?e:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:e,maximized:t})}}),this.paneControls.setSuspended("mobile"===this.layoutMode),this.axisScaleButtons=new tZ(this.plot,t,{i18n:()=>this.i18n??(0,n.Db)(),panes:()=>this.axisScaleViews(),rightAxis:()=>this.rightAxisW,onToggleAuto:e=>this.togglePaneAuto(e),onToggleLog:e=>{let t=this.scene.panes.get(e);if(!t)return;let i=!oa(this.scene,t);i&&"price"!==on(this.scene,t)&&this.setPaneScaleMode(e,"price"),this.setPaneLog(e,i)},onTogglePercent:e=>{let t=this.scene.panes.get(e);if(!t)return;let i="percent"!==on(this.scene,t);i&&oa(this.scene,t)&&this.setPaneLog(e,!1),this.setPaneScaleMode(e,i?"percent":"price")}}),this.resizeObserver=new ResizeObserver(e=>{for(let t of e){if(t.target!==this.plot)continue;let e=t.devicePixelContentBoxSize?.[0];e&&(this.plotDeviceSize={width:e.inlineSize,height:e.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(){return this.createPlotCanvas({pointerEvents:!0})}createGeometryBackend(){if(("auto"===this.backendMode||"webgl2"===this.backendMode)&&function(){if(null!==t_)return t_;try{t_=!!document.createElement("canvas").getContext("webgl2")}catch{t_=!1}return t_}()){let e=this.makeDataCanvas(),t=new iH;if(t.glow=this.glowAmount,t.onNeedsRedraw=()=>this.scheduler?.invalidate(4),t.onContextFailed=()=>this.swapToCanvas2dFallback(),t.mount(e),t.ok)return this.backend=t,e;t.destroy()}let e=this.makeDataCanvas(),t=new oc;return t.mount(e),this.backend=t,e}swapToCanvas2dFallback(){if("canvas2d"===this.backend.kind)return;let e=this.dataCanvas;this.input?.detach(),this.backend.destroy();let t=this.makeDataCanvas(),i=new oc;i.mount(t),this.backend=i,e.replaceWith(t),this.dataCanvas=t,this.input?.attach(t),this.syncSize()}watchDpr(){"function"==typeof window.matchMedia&&(this.dprMedia?.removeEventListener("change",this.onDprChange),this.dprMedia=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this.dprMedia.addEventListener("change",this.onDprChange,{once:!0}))}setTheme(e){this.followThemeCandles(this.appTheme,e),this.theme=this.deriveTheme(e),this.appTheme=e,this.surfaceBackground=e.background,this.surfaceTextColor=e.textColor,this.wrapper&&e$(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)}setLocalization(e,t){this.i18n=e,this.chrome.i18n=e,this.rootAttrs={lang:t.lang,dir:t.dir},this.scene.format=e.format,this.inputsUI?.setI18n(e),this.applyRootAttributes(),this.relabel(),this.userDrawings?.relocalize(),this.settingsDialog?.relocalize(),this.scheduler&&this.scheduler.invalidate(4)}t(e,t){return(0,n.b6)(this.i18n,e,t)}modelTitle(e){return this.t(e.displayTitle??e.title)}legendTitle(e){let t=e.displayShorttitle??e.shorttitle;return void 0!==t?this.t(t):this.modelTitle(e)}seriesTitle(e,t){return e.displayTitle?this.t(e.displayTitle):e.title||this.modelTitle(t)}relabel(){if(this.settingsButton&&(this.settingsButton.title=this.t(ng.chartSettings)),this.scrollButton&&(this.scrollButton.title=this.t(ng.scrollToLatestTitle),this.scrollButton.setAttribute("aria-label",this.t(ng.scrollToLatest))),this.keyboardEnabled&&this.dataCanvas?.hasAttribute("aria-label")&&this.dataCanvas.setAttribute("aria-label",this.t(ng.keyboardHelp)),this.paneControls?.refresh(),this.axisScaleButtons?.relabel(),this.attributionEl&&null===this.attributionHtml&&this.rebuildAttribution(),this.inputsUI)for(let e of this.scene.indicators.values())!1!==e.legend&&this.inputsUI.setTitle(e.id,this.legendTitle(e))}applyRootAttributes(){let e=this.wrapper;if(!e)return;let{lang:t,dir:i}=this.rootAttrs;t?e.setAttribute("lang",t):e.removeAttribute("lang"),i?e.setAttribute("dir",i):e.removeAttribute("dir")}resize(){this.syncSize()}setWallClock(e){e!==this.hostClock&&(this.hostClock=e,null!=this.countdownUnsub&&(this.countdownUnsub(),this.countdownUnsub=null),this.syncCountdownTimer())}syncCountdownTimer(){if(this.scene.showCountdown){if(null==this.countdownUnsub){let e=this.hostClock??this.ownClock??(this.ownClock=new eM);this.countdownUnsub=e.onTick(()=>{this.scene.showCountdown&&this.scene.bars.length>0&&this.scheduler?.invalidate(2)})}}else null!=this.countdownUnsub&&(this.countdownUnsub(),this.countdownUnsub=null)}destroy(){for(let e of(null!=this.introRaf&&cancelAnimationFrame(this.introRaf),this.loadingEl?.remove(),this.loadingEl=null,null!=this.countdownUnsub&&(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),null!==this.markPulseRaf&&cancelAnimationFrame(this.markPulseRaf),this.markPulseRaf=null,this.scrollButton?.remove(),this.scrollButton=null,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.shadeRightEl?.remove(),this.shadeRightEl=null,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){null!=this.introRaf&&(cancelAnimationFrame(this.introRaf),this.introRaf=null,this.modelAlpha=1),this.liveEaseTime=0;let i=this.bars,o=i[0]?.time;this.scene.variableDuration=t?.variableDuration===!0,this.bars=function(e,t=!1){let i=[...e].sort((e,t)=>e.time-t.time||(e.seq??0)-(t.seq??0)),o=[];for(let e of i){let i=o[o.length-1];if(i&&i.time===e.time&&(!t||void 0!==i.seq&&void 0!==e.seq&&i.seq===e.seq)){o[o.length-1]=e;continue}o.push(e)}return o}(e,this.scene.variableDuration),this.scene.bars=this.bars,this.coords.setBars(this.bars.map(e=>e.time));let r=this.bars[this.bars.length-1];for(let e of(r&&!this.scene.variableDuration&&eT.observeCandle(r.time,this.coords.barInterval),this.scene.indicators.values()))this.refreshAnchorOffset(e);if(t?.preserveView===!0&&null!=o&&this.bars.length>0){let e=this.bars[0].time,t=0;if(e!==o){let r=this.bars.findIndex(e=>e.time===o);if(r>0)t=r;else{let o=i.findIndex(t=>t.time===e);o>0&&(t=-o)}}0!==t&&(this.zoomAnchorLogical+=t,null!=this.hoverLogical&&(this.hoverLogical+=t))}let l=t?.preserveView===!0&&this.didInitialFit;if(this.coords.width>0&&!l&&(this.didInitialFit?this.reframeKeepZoom():this.fitContent(),this.didInitialFit=!0),!this.introPlayed&&this.bars.length>0&&(this.introPlayed=!0,this.intro.style))return void this.playIntro();this.scheduler.invalidate(4)}updateBar(e){let t=this.bars.length,i=this.bars[t-1];if(i&&(0,o.SyC)(i,e))this.bars[t-1]=e,this.animLiveBar.on&&this.liveEaseTime===e.time?this.animator.start():this.syncLiveEase(e);else{if(!(!i||(0,o.vQt)(e,i)))return;let r=this.coords.getViewport(),l=t>0&&r.rightOffset<0&&null===this.scrollTargetRO;this.bars.push(e),this.syncLiveEase(e),this.coords.barInterval>0?this.coords.appendBar(e.time):this.coords.setBars(this.bars.map(e=>e.time)),l&&this.coords.setViewport({...r,rightOffset:r.rightOffset-1}),this.scene.variableDuration||eT.observeCandle(e.time,this.coords.barInterval)}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!1;let i=Math.max(1e-9,1e-6*Math.abs(t.close)),o=this.animLiveBar.tau,r=i2(this.liveEaseHigh,t.high,e,o),l=i2(this.liveEaseLow,t.low,e,o),n=i2(this.liveEaseClose,t.close,e,o),a=Math.abs(r-t.high)>i||Math.abs(l-t.low)>i||Math.abs(n-t.close)>i;return this.liveEaseHigh=a?r:t.high,this.liveEaseLow=a?l:t.low,this.liveEaseClose=a?n:t.close,a}ensurePane(e){this.scene.ensurePane(e.id,e.kind,e.order,e.heightWeight),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4)}removePane(e){e!==np&&(this.scene.removePane(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null),this.refreshAxisWidth(),this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4))}setIndicatorPane(e,t,i){let o=this.scene.indicators.get(e.id);o&&(o.paneId=t,o.ownScale=i?.ownScale===!0,o.ownScale||this.scene.dropIndicatorScale(e.id),this.inputsUI.setPane(e.id,t),this.syncLegendOrder(),this.refreshAnchorOffset(o),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 i=this.scene.panes.get(e);i&&i.collapsed!==t&&(i.collapsed=t,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4))}setPaneMaximized(e){null===e||this.scene.panes.has(e)||(e=null),this.maximizedPaneId=e,this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4)}setPaneHeightWeight(e,t){let i=this.scene.panes.get(e);i&&t>0&&i.heightWeight!==t&&(i.heightWeight=t,this.afterPaneLayoutChange())}paneHeightWeight(e){return this.scene.panes.get(e)?.heightWeight??null}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 i=this.scene.ownScaleIndicatorsForPane(t.id).length;i>e&&(e=i)}return e}refreshAxisWidth(){let e=64+56*this.maxOwnScaleColumns();return e!==this.rightAxisW&&(this.rightAxisW=e,this.publishGutters(),this.coords.width>0&&this.syncSize(),!0)}refreshAnchorOffset(e){let t=e.anchorTime;if(null==t||0===this.bars.length)return void this.scene.setAnchorOffset(e.id,0);let i=this.bars[0].time;if(t===i)return void this.scene.setAnchorOffset(e.id,0);if(t<i){let t=function(e,t){for(let i of e.series){let e="candle"===i.kind||"bar"===i.kind?i.bars:(0,o.xcs)(i)?i.points:null;if(!e||0===e.length)continue;let r=function(e,t){let i=0,o=e.length;for(;i<o;){let r=i+o>>1,l=e[r]?.time;if(void 0===l)return function(e,t){let i=-1,o=!1;for(let r=0;r<e.length;r+=1){let l=e[r]?.time;if(void 0!==l){if(o=!0,l>=t)return l===t?r:i+1;i=r}}return o?e.length:null}(e,t);l<t?i=r+1:o=r}return i}(e,t);if(null!==r)return r}return null}(e,i);if(null==t){console.warn(`[vela] indicator "${e.id}" starts before the first bar with no series to align on — rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,-t);return}let r=0,l=this.bars.length-1,n=this.bars.length;for(;r<=l;){let e=r+l>>1;this.bars[e].time>=t?(n=e,l=e-1):r=e+1}if(n>=this.bars.length||this.bars[n].time!==t){console.warn(`[vela] indicator "${e.id}" anchorTime matches no chart bar — rendering unanchored`),this.scene.setAnchorOffset(e.id,0);return}this.scene.setAnchorOffset(e.id,n)}mountIndicator(e){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),!1!==e.legend&&this.inputsUI.upsert(e.id,this.legendTitle(e),e.inputs,e.inputValues,e.paneId,{native:!!e.native,...e.props?{props:e.props,propValues:e.propValues??{}}:{}}),e.native?.type==="volume"?(this.volumeActive=!0,this.volumeHidden=!1):e.native?.type==="vpvr"&&(this.vpvrActive=!0,this.vpvrHidden=!1);let t=this.scene.indicatorScales.has(e.id);return!e.ownScale&&t&&this.scene.dropIndicatorScale(e.id),(e.ownScale||t)&&this.refreshAxisWidth(),this.syncLegendOrder(),this.paneControls?.refresh(),this.scheduler.invalidate(4),{id:e.id}}updateIndicator(e,t){let i=this.scene.indicators.get(e.id);if(i){if("value"===t.kind&&void 0!==t.anchorTime){let e=t.anchorTime??void 0;e!==i.anchorTime&&(i.anchorTime=e,this.refreshAnchorOffset(i))}(function(e,t){if("value"===t.kind){for(let i of t.series){let t=e.series.find(e=>e.id===i.seriesId);t&&("points"===i.kind&&(0,o.xcs)(t)?t.points=i.points:"bars"===i.kind&&("candle"===t.kind||"bar"===t.kind)&&(t.bars=i.bars,void 0!==i.barColors&&(t.barColors=i.barColors)))}t.lines&&(e.lines=t.lines),t.boxes&&(e.boxes=t.boxes),t.labels&&(e.labels=t.labels),t.polylines&&(e.polylines=t.polylines),t.linefills&&(e.linefills=t.linefills),t.tables&&(e.tables=t.tables),t.trades&&(e.trades=t.trades),t.fills&&(e.fills=t.fills),t.backgrounds&&(e.backgrounds=t.backgrounds),t.priceLines&&(e.priceLines=t.priceLines),t.barColors&&(e.barColors=t.barColors);return}for(let i of t.removed){let t=e.series.findIndex(e=>e.id===i);t>=0&&e.series.splice(t,1)}for(let i of t.added)e.series.push(i)})(i,t),this.scheduler.invalidate(3)}}removeIndicator(e){let t=this.scene.indicators.get(e.id)?.native?.type;"volume"===t?(this.volumeActive=!1,this.volumeHidden=!1,this.scene.volumeLayer=null):"vpvr"===t&&(this.vpvrActive=!1,this.vpvrHidden=!1,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,i){this.inputsUI.setValues(e.id,t,i)}setSymbolPicker(e){this.symbolPicker=e,this.inputsUI?.setSymbolPicker(e)}setLegendActions(e){this.legendActionsProvider=e,this.inputsUI?.setLegendActions(e)}setDrawingActions(e){this.drawingActionsProvider=e,this.userDrawings?.setDrawingActions(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 i=this.scene.indicators.get(e.id)?.native?.type;if("volume"===i||"vpvr"===i){"volume"===i?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)}onPriceStyleWillChange(e){return this.priceStyleWillChangeCbs.add(e),()=>this.priceStyleWillChangeCbs.delete(e)}setPriceStyle(e){this.showPriceStyle(e)}showPriceStyle(e=this.chosenStyle){let t=(0,o.g7Z)(e,this.symbolFacts,is());if(t===this.scene.priceStyle){this.chosenStyle=e;return}let i=this.scene.priceStyle;for(let e of this.priceStyleWillChangeCbs)e(i,t);for(let i of(this.chosenStyle=e,this.scene.priceStyle=t,this.scene.basePainting=ii(t),this.scene.candleOverride=il(t,this.scene.style.chartTypes),this.priceStyleCbs))i(t)}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("mobile"===e),this.scrollButton){let t="mobile"===e?24:26;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 function(e,t=[]){let i=new Set(rb);if(t.length>0)for(let e of(i.add(rs),i.add(rh),t))i.add(rd(e.id));for(let e of(0,o.AHy)()){if(io(e.id)){let t=`symbol.style.${e.id}`;for(let e of["",".body",".borders",".wick",".spacing"])i.add(t+e)}let t=e.settings;if(!t)continue;let o=`type:${e.id}`;i.add(o);let r=e=>{for(let t of e)i.add(`${o}.${rp(t)}`)};for(let e of(t.rows&&r(t.rows),t.instances??[]))r(e.rows);for(let e of t.subsections??[])i.add(`${o}.${ra(e.title)}`),r(e.rows)}for(let t of e){let e=rg(t);for(let o of(i.add(e),t.rows))i.add(`${e}.${rm(o)}`)}return[...i]}(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 function(e,t){let i=t.map(e=>({...e})),o=new Set(i.map(e=>e.id));for(let r of e)void 0===r.group||o.has(r.group)||(o.add(r.group),i.push({id:r.group,label:o2(r.group,t)}));return i}(this.scene.timelineMarks,this.scene.markGroups)}markGroupsForEventsTab(){let e=new Set(this.scene.markGroups.map(e=>e.id));return this.markGroupsInUse().map(t=>void 0===t.parent||e.has(t.parent)?t:{...t,parent:void 0})}onViewportChange(e){return this.viewportCbs.add(e),()=>this.viewportCbs.delete(e)}getVisibleRange(){let e=this.coords.barCount;if(0===e||0===this.coords.width)return null;let t=this.coords.visibleLogicalRange(),i=Math.max(0,Math.ceil(t.from)),o=Math.min(e-1,Math.floor(t.to));return o<i?null:{from:this.coords.logicalToTime(i),to:this.coords.logicalToTime(o)}}setVisibleRange(e,t){let i=this.coords.timeToLogical(e.from),o=this.coords.timeToLogical(e.to),r=Math.max(1e-6,o-i),l=t?.rightMargin?this.scene.style.margins.right:0,n=iZ(this.coords.width/((r+l)*this.coords.spacingScale)),a=o-(this.coords.barCount-1)+l;this.applyViewport({barSpacing:n,rightOffset:a})}panBy(e){if(0===this.coords.barCount||0===this.coords.width)return;let t=this.coords.getViewport(),i=this.coords.width/this.coords.pxPerBar(),o=this.scrollTargetRO??t.rightOffset;this.glideRightOffset(this.clampViewport(t.barSpacing,o+e*i).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,i){let o=this.clampViewport(e,this.coords.getViewport().rightOffset).barSpacing;if(this.zoomAnchorLogical=t,this.zoomAnchorX=i,this.panVelocity=0,this.scrollTargetRO=null,!this.animZoom.on){let e=this.clampViewport(o,this.anchoredRightOffset(o));this.coords.setViewport(e),this.targetBarSpacing=e.barSpacing,this.scheduler.invalidate(4),this.emitViewportChange();return}this.targetBarSpacing=o,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 i=this.coords.barCount,o=this.coords.width;if(i<=1||o<=0)return{barSpacing:iZ(e),rightOffset:t};let r=Math.min(2,i),l=this.coords.spacingScale,n=Math.max(.5,Math.min(Math.min(1e3,o/(r*l)),e)),a=Math.max(r-i,Math.min(o/(n*l)-(r-1),t));return{barSpacing:n,rightOffset:a}}animTick(e){let t=this.coords.getViewport(),i=t.barSpacing,o=t.rightOffset,r=!1,l=this.targetBarSpacing;Math.abs(i-l)>.001*l?(i=iZ(i2(i,l,e,this.animZoom.tau)),o=this.anchoredRightOffset(i),r=!0):i!==l&&(i=l,o=this.anchoredRightOffset(i));let n=.02/Math.max(1e-6,i*this.coords.spacingScale);if(Math.abs(this.panVelocity)>n){o+=this.panVelocity*e;let t=this.animPan.tau;this.panVelocity=t>0?this.panVelocity*Math.exp(-e/t):0,Math.abs(this.panVelocity)<=n?this.panVelocity=0:r=!0}if(null!=this.scrollTargetRO){let t=this.scrollTargetRO,i=i2(o,t,e,this.animScroll.tau);.001>Math.abs(i-t)?(o=t,this.scrollTargetRO=null):(o=i,r=!0)}let a=this.clampViewport(i,o);return a.barSpacing!==i&&(this.targetBarSpacing=a.barSpacing),null!=this.scrollTargetRO&&a.rightOffset!==o&&(this.scrollTargetRO=a.rightOffset),this.coords.setViewport(a),this.computeScales(),this.easeScales(e)&&(r=!0),this.easeLiveBar(e)&&(r=!0),this.skeletonClockMs+=e,this.paintData(),this.renderCrosshairLayer(),this.updateLegendValues(),this.emitViewportChange(),r}easeScales(e){let t=!1,i=this.animAutoscale.tau;for(let o of this.scene.panes.values()){let r=o.scaleTarget,l=o.scale;if(r.log&&l.min>0&&r.min>0){let n=Math.log(r.min),a=Math.log(r.max),s=Math.max(1e-9,Math.abs(a-n)),h=i2(Math.log(l.min),n,e,i),d=i2(Math.log(l.max),a,e,i);Math.abs(h-n)<=.001*s&&Math.abs(d-a)<=.001*s?o.scale={min:r.min,max:r.max,log:!0}:(t=!0,o.scale={min:Math.exp(h),max:Math.exp(d),log:!0});continue}let n=Math.max(1e-9,Math.abs(r.max-r.min)),a=i2(l.min,r.min,e,i),s=i2(l.max,r.max,e,i);Math.abs(a-r.min)<=.001*n&&Math.abs(s-r.max)<=.001*n?(a=r.min,s=r.max):t=!0,o.scale={min:a,max:s,log:r.log}}for(let o of this.scene.indicatorScales.values()){let r=o.scaleTarget,l=o.scale,n=Math.max(1e-9,Math.abs(r.max-r.min)),a=i2(l.min,r.min,e,i),s=i2(l.max,r.max,e,i);Math.abs(a-r.min)<=.001*n&&Math.abs(s-r.max)<=.001*n?(a=r.min,s=r.max):t=!0,o.scale={min:a,max:s}}return t}emitViewportChange(){this.updateScrollToRealtimeButton();let e=this.getVisibleRange();if(e)for(let t of this.viewportCbs)t(e)}handlePointerMove(e,t){if(null===e||null===t||0===this.coords.barCount){this.scene.crosshair=null,this.hoverSeparatorY=null,this.lastPointer=null,"hover"===this.marksExpandedBy&&this.setMarksExpanded(null),this.setMarkHover(null),this.scheduler.invalidate(1),this.hoverLogical=null;let e={time:null,price:null,paneKind:null,paneId:null,values:new Map,ohlc:null};for(let t of this.crosshairCbs)t(e);return}let i=e>=0&&t>=0&&e<=this.coords.width&&t<=this.coords.height;this.scene.crosshair=i?{x:e,y:t}:null,this.lastPointer=i?{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(i?this.chrome.markStackAt(e,t):null),this.setMarkHover(i?this.chrome.markGlyphAt(e,t)?.cluster.key??null:null);let r=Math.round(this.coords.xToLogical(e)),l=r>=0&&r<this.coords.barCount,n=l?this.coords.logicalToTime(r):null,a=this.paneNodeAtY(t),s=i&&a?this.coords.yToPrice(t,a.scale,a.bounds):null,h=new Map;if(l)for(let e of this.scene.indicators.values()){let t=this.scene.offsetOf(e.id);for(let i of e.series)if((0,o.xcs)(i)){let e=i.points[r-t]?.value;null!=e&&h.set(i.id,e)}}let d=l?this.bars[r]:void 0,c=d?{time:d.time,open:d.open,high:d.high,low:d.low,close:d.close,volume:d.volume}:null;this.hoverLogical=l?r:null;let p=i&&a?a:null,u={time:n,price:s,paneKind:p?.kind??null,paneId:p?.id??null,values:h,ohlc:c};for(let e of this.crosshairCbs)e(u)}handleClick(e,t){if(0===this.coords.barCount)return;let i=Math.round(this.coords.xToLogical(e)),o=i>=0&&i<this.coords.barCount,r=e>=0&&t>=0&&e<=this.coords.width&&t<=this.coords.height?this.paneNodeAtY(t):null,l={time:o?this.coords.logicalToTime(i):null,price:r?this.coords.yToPrice(t,r.scale,r.bounds):null,paneKind:r?.kind??null,paneId:r?.id??null};for(let e of this.clickCbs)e(l)}setMarksExpanded(e,t="hover"){if(this.scene.marksExpandedStack!==e){if(null===e&&this.markPopover?.key){let e=this.chrome.markGlyphByKey(this.markPopover.key);if(e&&e.stack===this.scene.marksExpandedStack)return}this.scene.marksExpandedStack=e,this.marksExpandedBy=t,this.scheduler?.invalidate(2)}}handleMarkClick(e,t){let i=this.chrome.markGlyphAt(e,t);if(!i)return null!==this.scene.marksExpandedStack&&null===this.chrome.markStackAt(e,t)&&this.setMarksExpanded(null),!1;if(i.decked)return this.setMarksExpanded(i.stack,"tap"),!0;let o=i.cluster.marks,r=o[0],l={id:r.id,ids:o.map(e=>e.id),time:r.time,...void 0!==i.cluster.group?{group:i.cluster.group}:{}};for(let e of this.markClickCbs)e(l);return o.some(e=>void 0!==e.content)?this.markPopover?.open(i.cluster,{x:i.x,y:i.y,size:i.size}):(this.scene.marksFlash={key:i.cluster.key,until:nu()+220},this.syncMarkPulse()),!0}trackMarkPopover(){let e=this.markPopover?.key;if(!e)return;let t=this.chrome.markGlyphByKey(e);this.markPopover.track(t&&!(t.decked&&0!==t.depth)?{x:t.x,y:t.y,size:t.size}:null)}setMarkHover(e){this.scene.marksHoverKey!==e&&(this.scene.marksHoverKey=e,this.scene.marksHoverSince=nu(),this.scheduler?.invalidate(2),this.syncMarkPulse())}syncMarkPulse(){if(null!==this.markPulseRaf||"function"!=typeof requestAnimationFrame)return;let e=()=>{this.markPulseRaf=null;let t=nu();this.scene.marksFlash&&this.scene.marksFlash.until<=t&&(this.scene.marksFlash=null),this.scheduler?.invalidate(2),(null!==this.scene.marksHoverKey&&t-this.scene.marksHoverSince<360||null!==this.scene.marksFlash)&&(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,i=1/0;for(let o of this.scene.panes.values()){let r=e<o.bounds.top?o.bounds.top-e:e-(o.bounds.top+o.bounds.height);r<i&&(i=r,t=o)}return t}resolveScaleHolder(e,t){let i=this.paneNodeAtY(t);if(!i)return null;let o=this.coords.width,r=this.scene.ownScaleIndicatorsForPane(i.id);if(e>=o+64&&r.length>0){let t=r[Math.floor((e-o-64)/56)];if(t)return{holder:this.scene.ensureIndicatorScale(t.id,i.scaleTarget),height:i.bounds.height}}return{holder:i,height:i.bounds.height}}beginPriceScale(e,t){let i=this.resolveScaleHolder(e,t);i&&(this.scaleDragHolder=i.holder,this.scaleDragHeight=i.height,this.scaleDragStart={...i.holder.scale},i.holder.manualScale={...i.holder.scale},this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4))}priceScaleBy(e){let t=this.scaleDragHolder,i=this.scaleDragStart;t&&i&&this.setManualScale(t,function(e,t){if(e.log&&e.min>0&&e.max>e.min){let i=Math.log(e.min),o=Math.log(e.max),r=(i+o)/2,l=(o-i)/2*t;return{min:Math.exp(r-l),max:Math.exp(r+l),log:!0}}let i=(e.min+e.max)/2,o=(e.max-e.min)/2*t;return{min:i-o,max:i+o,log:e.log}}(i,Math.exp(.004*e)))}applyFreePan(e){!0===e?(this.freePanTrigger="drag",this.freePanOn=!0):"drag"===e||"alt"===e||"shift"===e||"mod"===e||"function"==typeof e?(this.freePanTrigger=e,this.freePanOn=!0):this.freePanOn=!!e,this.input&&(this.input.freePan=!!this.freePanOn&&this.freePanTrigger)}beginPricePan(e,t=!1){let i=this.paneNodeAtY(e);if(!i)return!1;if(!i.manualScale){if(!t)return!1;i.manualScale={...i.scale},this.axisScaleButtons?.reposition(),this.scheduler?.invalidate(4)}return this.scaleDragHolder=i,this.scaleDragHeight=i.bounds.height,this.scaleDragStart={...i.scale},!0}pricePanBy(e){let t=this.scaleDragHolder,i=this.scaleDragStart;t&&i&&this.setManualScale(t,function(e,t,i){if(i<=0)return{...e};if(e.log&&e.min>0&&e.max>e.min){let o=Math.log(e.min),r=Math.log(e.max),l=(r-o)*t/i;return{min:Math.exp(o+l),max:Math.exp(r+l),log:!0}}let o=(e.max-e.min)*t/i;return{min:e.min+o,max:e.max+o,log:e.log}}(i,e,this.scaleDragHeight))}resetPriceScale(e,t){let i=this.resolveScaleHolder(e,t);i&&(i.holder.manualScale=null,this.axisScaleButtons?.reposition(),this.scheduler.invalidate(4))}dataDblClick(e,t){let i=this.paneNodeAtY(t)??this.nearestPaneToY(t);if(!i)return;let o=this.maximizedPaneId!==i.id;this.maximizedPaneId=o?i.id:null,this.afterPaneLayoutChange(),this.emitPaneAction({type:"maximize",paneId:i.id,maximized:o})}resetView(){this.fitContent(),this.scheduler.invalidate(4),this.emitViewportChange()}setManualScale(e,t){e.manualScale=t,e.scale={...t},e.scaleTarget={...t},e.initialized=!0,this.scheduler.invalidate(4)}afterPaneLayoutChange(){this.layoutPanes(),this.paneControls?.refresh(),this.scheduler.invalidate(4)}paneControlViews(){let e=this.scene.orderedPanes();return e.map((t,i)=>({id:t.id,kind:t.kind,collapsed:t.collapsed,maximized:this.maximizedPaneId===t.id,top:t.bounds.top,height:t.bounds.height,index:i,count:e.length}))}movePaneLocal(e,t){let i=this.scene.orderedPanes(),o=i.findIndex(t=>t.id===e);if(o<0)return;let r="up"===t?o-1:o+1;if(r<1||r>=i.length)return;let l=i.map(e=>e.id),n=l[o];l[o]=l[r],l[r]=n,this.scene.orderPanes(l),this.afterPaneLayoutChange(),this.emitPaneAction({type:"move",paneId:e,dir:t})}paneSeparatorAt(e){return null!==this.separatorPaneIndexAt(e)}separatorHoverY(e){if(!this.paneResizeEnabled)return null;let t=this.separatorPaneIndexAt(e);return null===t?null:this.scene.orderedPanes()[t].bounds.top}separatorPaneIndexAt(e){let t=this.scene.orderedPanes();for(let i=1;i<t.length;i++)if(4>=Math.abs(e-t[i].bounds.top))return i;return null}beginPaneResize(e){let t=this.separatorPaneIndexAt(e);if(null===t)return;let i=this.scene.orderedPanes(),o=i[t-1],r=i[t];this.resizeAbove=o,this.resizeBelow=r,this.resizeStartAboveWeight=o.heightWeight,this.resizeSplitStart={combinedTop:o.bounds.top,combinedHeight:o.bounds.height+r.bounds.height,combinedWeight:o.heightWeight+r.heightWeight,startBoundaryY:r.bounds.top}}paneResizeBy(e){let t=this.resizeAbove,i=this.resizeBelow,o=this.resizeSplitStart;if(!t||!i||!o)return;let r=function(e,t,i=24){let{combinedTop:o,combinedHeight:r,combinedWeight:l,startBoundaryY:n}=e,a=Math.min(i,r/2),s=Math.max(o+a,Math.min(o+r-a,n+t)),h=r>0?(s-o)/r*l:l/2;return{above:h,below:l-h}}(o,e);t.heightWeight=r.above,i.heightWeight=r.below,this.layoutPanes(),this.scheduler.invalidate(4)}endPaneResize(){let e=this.resizeAbove,t=this.resizeBelow,i=this.resizeStartAboveWeight;this.resizeAbove=null,this.resizeBelow=null,this.resizeSplitStart=null,e&&t&&e.heightWeight!==i&&this.emitPaneAction({type:"resize",paneIds:[e.id,t.id]})}resetPaneSize(e){let t=this.separatorPaneIndexAt(e);if(null===t)return;let i=this.scene.orderedPanes(),o=i[t-1],r=i[t],l=(o.heightWeight+r.heightWeight)/2;o.heightWeight=l,r.heightWeight=l,this.layoutPanes(),this.scheduler.invalidate(4),this.emitPaneAction({type:"resize",paneIds:[o.id,r.id]})}setKeyboardEnabled(e){this.keyboardEnabled=e,this.dataCanvas&&this.keyboard&&(e?(this.dataCanvas.tabIndex=0,this.dataCanvas.setAttribute("role","application"),this.dataCanvas.setAttribute("aria-label",this.t(ng.keyboardHelp)),!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=iZ(this.coords.getViewport().barSpacing*Math.exp(.2*e));this.zoomTo(t,this.coords.rightEdgeLogical,this.coords.width)}stepCrosshair(e){let t=this.coords.barCount;if(0===t)return;let i=this.hoverLogical??Math.min(t-1,Math.round(this.coords.xToLogical(this.coords.width)));this.focusBar(i+e)}focusBar(e){let t=this.coords.barCount;if(0===t)return;let i=Math.max(0,Math.min(t-1,e)),o=this.coords.getViewport(),r=this.coords.xToLogical(0),l=this.coords.xToLogical(this.coords.width),n=o.rightOffset;i<r+2?n-=r+2-i:i>l-2&&(n+=i-(l-2)),n!==o.rightOffset&&this.applyViewport({barSpacing:o.barSpacing,rightOffset:n});let a=this.scene.orderedPanes().find(e=>"price"===e.kind)??this.scene.orderedPanes()[0]??null,s=this.scene.crosshair?.y??(a?a.bounds.top+a.bounds.height/2:this.coords.height/2);this.handlePointerMove(this.coords.logicalToX(i),s),this.announceBar(i)}announceBar(e){if(!this.liveRegion)return;let t=this.bars[e],i=this.dataWindowPricePane(),o=this.dataWindowOHLC(t,i),r=[];for(let l of(t&&r.push(function(e,t){let{date:i,time:o}=nb(e,t);return`${i} ${o}`}(t.time,oF(this.scene.timezone,this.coords.barInterval))),o&&r.push(this.t(ng.barSummary,{open:o.o,high:o.h,low:o.l,close:o.c})),this.dataWindowGroups(e,i)))for(let e of l.rows)r.push(this.t(ng.valueSummary,{name:e.label,value:e.value}));this.liveRegion.textContent=r.join(". ")}getDataWindowReadout(){let e=this.bars.length;if(0===e)return{date:"",time:"",ohlc:null,groups:[]};let t=null!=this.hoverLogical?this.hoverLogical:e-1,i=this.bars[t],o=this.dataWindowPricePane(),r=i?nb(i.time,oF(this.scene.timezone,this.coords.barInterval)):{date:"",time:""};return{date:r.date,time:r.time,ohlc:this.dataWindowOHLC(i,o),groups:this.dataWindowGroups(t,o)}}dataWindowPricePane(){return this.scene.orderedPanes().find(e=>"price"===e.kind)??null}dataWindowFmt(e,t,i="dataWindow"){return t?oU(t.scale,t.bounds.height,e,this.scene.priceMintick,this.scene.format,i):String(e)}formatVolume(e,t){return(this.scene.format??n.$S).compact(e,{decimals:2,trimZeros:!1,surface:t})}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:null!=e.volume?this.formatVolume(e.volume,"dataWindow"):void 0,up:e.close>=e.open}:null}dataWindowGroups(e,t){let i=[];for(let o of this.scene.indicators.values()){let r=this.readoutRowsFor(o,e,t,"dataWindow");r.length&&i.push({name:this.modelTitle(o),rows:r})}return i}readoutRowsFor(e,t,i,r){if(e.native?.type==="volume")return this.volumeReadoutRows(e,t,"legend"===r?"legend":"dataWindow");let l=(e.paneId?this.scene.panes.get(e.paneId):null)??i,n=this.scene.offsetOf(e.id),a=[];for(let i of e.series){let s,h,d;if(!(0,o.oBL)(i,r))continue;if("candle"===i.kind||"bar"===i.kind)s=i.bars[t-n]?.close,h=i.style?.up??this.theme.upColor;else{if(!(0,o.xcs)(i))continue;s=i.points[t-n]?.value,h=i.points[t-n]?.color??i.style.color}if(null==s||!Number.isFinite(s))continue;let c="legend"===r?"legend":"dataWindow";if(l&&"own"===e.percentBaseline){let t=this.scene.scaleFor(e,l),i=od(this.scene,l,e);d=i?oq(t,l.bounds.height,s,i,void 0,l.axisFormat,this.scene.format,c):oU(t,l.bounds.height,s,void 0,this.scene.format,c)}else d=this.dataWindowFmt(s,l,c);a.push({label:this.seriesTitle(i,e),value:d,color:h})}return a}volumeReadoutRows(e,t,i){if(this.volumeHidden)return[];let o=this.bars[t],r=o?.volume;if(null==o||null==r||!Number.isFinite(r))return[];let l=this.scene.volumeLayer,n=o.close>=o.open?l?.upColor??this.theme.upColor:l?.downColor??this.theme.downColor;return[{label:this.modelTitle(e),value:this.formatVolume(r,i),color:n}]}updateLegendValues(){if(!this.inputsUI)return;let e=this.bars.length,t=new Map;if(e>0){let i=null!=this.hoverLogical?this.hoverLogical:e-1,o=this.dataWindowPricePane();for(let e of this.scene.indicators.values())t.set(e.id,this.readoutRowsFor(e,i,o,"legend").map(e=>({value:e.value,color:e.color})))}this.inputsUI.setPlotValues(t)}renderFrame(e){this.animator.active||(e>=3?(this.computeScales(),this.paintData()):e>=2&&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.renderCrosshairLayer(),!(e>=3)&&this.paintedData&&this.repaintCursorLayers(),this.updateLegendValues())}renderCrosshairLayer(){this.crosshairLayer.render(this.scene,this.coords,this.theme,this.hoverSeparatorY,this.externalCrossPx()),this.syncShadeRight()}syncShadeRight(){let e=this.shadeRightEl;if(!e)return;let t=this.crosshairLayer.shadeRightArea,i=t?`${t.x},${t.width},${t.height}`:"";if(i!==this.shadeRightSig){if(this.shadeRightSig=i,!t){e.hidden=!0,e.style.display="none";return}Object.assign(e.style,{left:`${t.x}px`,width:`${t.width}px`,height:`${t.height}px`,display:""}),e.hidden=!1}}repaintCursorLayers(){let e=this.scene.panes.get(np);if(!e)return;let t="undefined"!=typeof performance?performance.now():Date.now();for(let i of this.extLayers){if(!i.def.repaintOnCursor)continue;let o=this.layerPane(i)??e;!(o.collapsed||this.layerHiddenWithCandles(i))&&(i.instance.render(this.extLayerArgs(i,o.scale,o.bounds,t)),this.animZoom.on&&i.instance.animating?.()&&this.animator.start())}}clearLayerCanvas(e){0!==e.width&&0!==e.height&&e.getContext("2d")?.clearRect(0,0,e.width,e.height)}extLayerArgs(e,t,i,o){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:i,theme:this.theme,priceStyle:this.scene.priceStyle,nowMs:o,cursor:this.lastPointer,i18n:this.i18n??(0,n.Db)()}}paintData(){this.syncLayerCanvasOrder(),this.syncLegendOrder(),this.stampScaleInvert(),this.backend.modelAlpha=this.modelAlpha,this.backend.candleBodyAlpha=this.candleBodyAlpha,this.backend.candleStructureAlpha=this.candleStructureAlpha;let e=1;this.backend.candleBodyScale=1;let t=this.scene.panes.get(np);if(t){let i=this.nativeLayerPane("volume")??t;this.volumeRenderer.render({bars:this.scene.bars,data:this.scene.volumeLayer,visible:this.volumeActive&&!this.volumeHidden&&!i.collapsed,coords:this.coords,bounds:i.bounds,fillPane:"price"!==i.kind}),this.vpvrRenderer.render({bars:this.scene.bars,data:this.scene.vpvrLayer,visible:this.vpvrActive&&!this.vpvrHidden,coords:this.coords,scale:t.scale,bounds:t.bounds,theme:this.theme});let r="undefined"!=typeof performance?performance.now():Date.now(),l=null;for(let e of this.extLayers){let i=this.layerPane(e)??t;if(i.collapsed||this.layerHiddenWithCandles(e)){this.clearLayerCanvas(e.canvas);continue}let n=this.extLayerArgs(e,i.scale,i.bounds,r);e.instance.render(n),i===t&&(l=(0,o.lKO)(l,e.instance.modulateBase?.(n)??null)),this.animZoom.on&&e.instance.animating?.()&&this.animator.start()}l&&(null!=l.candleBodyScale&&(this.backend.candleBodyScale=nf(l.candleBodyScale)||.01),null!=l.candleBodyAlpha&&(this.backend.candleBodyAlpha=nf(l.candleBodyAlpha)*this.candleBodyAlpha),null!=l.gridAlpha&&(e=nf(l.gridAlpha)))}let i=this.bars.length-1,r=i>=0?this.bars[i]:void 0,l=!!r&&this.liveEaseTime===r.time&&(r.high!==this.liveEaseHigh||r.low!==this.liveEaseLow||r.close!==this.liveEaseClose);l&&r&&(this.bars[i]={...r,high:this.liveEaseHigh,low:this.liveEaseLow,close:this.liveEaseClose}),this.scene.drawingSlices=function(e,t){let i=new Map;for(let[t,o]of e)i.set(t,[...o]);for(let[e,o]of t)i.set(e,[...i.get(e)??[],...o]);for(let e of i.values())e.sort((e,t)=>e.beforeZ-t.beforeZ);return i}(this.indicatorSlices.prepare(this.scene,this.coords,this.theme,this.dataCanvas),this.userDrawings?.prepareSlices(this.scene.orderedPanes().map(e=>e.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(),l&&r&&(this.bars[i]=r),this.paintedData=!0}drawingProjector(){var e,t,i,o;return e=this.coords,t=e=>{let t=this.scene.panes.get(e);return t?{scale:t.scale,bounds:t.bounds,collapsed:t.collapsed}:null},i=e=>this.paneNodeAtY(e)?.id??null,o=(e,t)=>this.barsInTimeRange(e,t),{xOf:t=>e.timeToX(t),yOf:(i,o)=>{let r=t(o);return r?e.priceToY(i,r.scale,r.bounds):null},pxToPoint:(i,o,r)=>{let l=t(r);return{time:e.logicalToTime(e.xToLogical(i)),price:l?e.yToPrice(o,l.scale,l.bounds):0}},paneIdAtY:i,paneRect:e=>{let i=t(e);return i?{top:i.bounds.top,height:i.collapsed?0:i.bounds.height}:null},barsBetween:(t,i)=>Math.abs(e.timeToLogical(i)-e.timeToLogical(t)),barsInRange:o?(e,t)=>o(e,t):void 0,seriesInRange:this.userDrawings?.seriesGateway?(e,t,i)=>this.userDrawings.seriesGateway.seriesInRange(e,t,i):void 0,priceDecimals:e=>e===np&&this.scene.priceMintick?(0,n.a4)(this.scene.priceMintick)||2:void 0,width:e.width,height:e.height}}barsInTimeRange(e,t){let i=Math.min(e,t),o=Math.max(e,t),r=[];for(let e of this.bars)if(!(e.time<i)){if(e.time>o)break;r.push(e)}return r}get userDrawingsPort(){return this.userDrawings??void 0}focus(){this.dataCanvas?.focus({preventScroll:!0})}setExternalCrosshair(e,t=null){let i=null==e?null:{time:e,price:t},o=this.externalCross;(i||o)&&(i&&o&&o.time===i.time&&o.price===i.price||(this.externalCross=i,this.scheduler.invalidate(1)))}externalCrossPx(){let e=this.externalCross;if(!e||0===this.coords.barCount)return null;let t=Math.floor(this.coords.timeToLogical(e.time));if(!(t<this.coords.barCount))return null;let i=this.coords.logicalToX(Math.max(t,-1));if(!Number.isFinite(i))return null;let o=t>=0&&i>=0&&i<=this.coords.width,r=null;if(null!=e.price){let t=this.scene.orderedPanes().find(e=>"price"===e.kind);t&&(!Number.isFinite(r=this.coords.priceToY(e.price,t.scale,t.bounds))||r<t.bounds.top||r>t.bounds.top+t.bounds.height)&&(r=null)}return{x:i,y:r,time:this.coords.logicalToTime(Math.max(t,0)),price:null!=r?e.price:null,line:o}}setSnapMode(e){this.snapMode=e}snapToCandle(e,t,i="strong",o){let r;if("off"===i)return e;let l=this.bars.length;if(0===l)return e;let n=Math.max(0,Math.min(l-1,Math.round(this.coords.timeToLogical(e.time)))),a=this.bars[n];if(!a)return e;if(t!==np)r={time:a.time,price:e.price};else{let t=a.open;for(let i of[a.high,a.low,a.close])Math.abs(i-e.price)<Math.abs(t-e.price)&&(t=i);r={time:a.time,price:t}}if("weak"===i&&o){let i=this.drawingProjector(),l=i.yOf(r.price,t);if(Math.hypot(i.xOf(r.time)-o.x,(l??o.y)-o.y)>8)return e}return r}computeScales(){let e=this.coords.barCount;if(0===e)return;let t=this.coords.visibleLogicalRange(),i=Math.max(0,Math.floor(t.from)),o=Math.min(e-1,Math.ceil(t.to));if(o<i)return;let r=Math.max(o,Math.ceil(t.to));this.scene.percentBaseline=this.bars[i]?.close??0,this.scene.modelPercentBaselines.clear();let l=this.scene.orderedPanes(),n=l.find(e=>"price"===e.kind)??null;this.chrome.prepare(this.scene,this.coords,this.theme);let a=this.animator.active,s=this.scene.style.margins;for(let e of l){let l=this.scene.indicatorsForPane(e.id).filter(e=>!0!==e.ownScale);for(let t of(e.percentBaseline="price"===e.kind?this.bars[i]?.close??0:this.firstVisibleValue(l,i,o),l)){if("own"!==t.percentBaseline)continue;let e=this.firstVisibleValue([t],i,o);0!==e&&Number.isFinite(e)&&this.scene.modelPercentBaselines.set(t.id,e)}if(e.manualScale){e.scaleTarget=e.manualScale,e.scale={...e.manualScale},e.initialized=!0;continue}let h=this.chrome.paneDrawingsRange(l,this.scene,e===n,t);if(e===n){let e=function(e,t,i,o=()=>0){let r=1/0,l=-1/0,n=e=>{null!=e&&Number.isFinite(e)&&(e<r&&(r=e),e>l&&(l=e))};for(let r of e){let e=o(r.id);for(let o of r.series)!0===o.overlay&&l5(o,t,i,e,n)}return r===1/0?null:{min:r,max:l}}(this.scene.indicators.values(),i,r,e=>this.scene.offsetOf(e));e&&(h=h?{min:Math.min(h.min,e.min),max:Math.max(h.max,e.max)}:e)}let d="price"===e.kind&&(!this.scene.candlesHidden||this.priceLayersAnchoredToBars(l)||!this.paneHasMeasurableContent(l,h)),c=e===n&&this.scene.scalePriceOnly&&d,p=oh(this.scene,e),u=new Set(l.filter(e=>"own"===e.percentBaseline).map(e=>e.id)),g=e=>{if(!p||!u.has(e))return 1;let t=this.scene.modelPercentBaselines.get(e);return null!=t&&0!==t?p.baseline/t:0};if(e.scaleTarget=c?l2([],this.bars,!0,i,r,null,oa(this.scene,e),e=>this.scene.offsetOf(e),s):l2(l,this.bars,d,i,r,h,oa(this.scene,e),e=>this.scene.offsetOf(e),s,g),e.axisFormat=void 0,e.axisBands=void 0,this.volumeOwnsPane(e,l)){let t=this.maxVisibleVolume(i,o);t>0&&(e.scaleTarget={min:0,max:t/.96},e.axisFormat="volume")}else if(this.layerNativesOwnPane(e,l)&&(e.scaleTarget=l2([],this.bars,!0,i,o,h,oa(this.scene,e),e=>this.scene.offsetOf(e),s),e.percentBaseline=this.bars[i]?.close??0,l.every(e=>null!=e.paneAxis))){e.axisFormat="none";let t=l.find(e=>"object"==typeof e.paneAxis);e.axisBands=t?t.paneAxis.bands:void 0}if(e===n&&this.scene.tradeMarkers.visible&&e.bounds.height>0){let i=this.tradesScaleHints(t);if(i){let t=e.scaleTarget;e.scaleTarget=function(e,t,i,o){if(i<=0&&o<=0)return e;let r=t-i-o;if(!(r>=8))return e;if(e.log&&e.min>0&&e.max>e.min){let t=Math.log(e.min),l=Math.log(e.max),n=(l-t)/r;return{...e,min:Math.exp(t-o*n),max:Math.exp(l+i*n)}}if(e.max<=e.min)return e;let l=(e.max-e.min)/r;return{...e,min:e.min-o*l,max:e.max+i*l}}({...t,min:Math.min(t.min,i.min),max:Math.max(t.max,i.max)},e.bounds.height,i.abovePx,i.belowPx)}}for(let o of(a&&e.initialized||(e.scale={...e.scaleTarget},e.initialized=!0),this.scene.ownScaleIndicatorsForPane(e.id))){let l=this.scene.ensureIndicatorScale(o.id,e.scaleTarget);if(l.manualScale){l.scaleTarget=l.manualScale,l.scale={...l.manualScale},l.initialized=!0;continue}let n=this.chrome.paneDrawingsRange([o],this.scene,!1,t);l.scaleTarget=l2([o],this.bars,!1,i,r,n,!1,e=>this.scene.offsetOf(e),s),a&&l.initialized||(l.scale={...l.scaleTarget},l.initialized=!0)}}}tradesScaleHints(e){let t=null,i={timeToLogical:e=>this.coords.timeToLogical(e),barAt:e=>{let t=this.bars[Math.round(e)];return t?{high:t.high,low:t.low}:null}};for(let o of this.scene.indicators.values()){if(!o.trades?.length)continue;let r=function(e,t,i,o,r,l){if(0===e.length)return null;let n=1/0,a=-1/0,s=0,h=0;for(let d of i7(e,t,i,Math.floor(o),Math.ceil(r),l+4)){let e=i.barAt(d.logical);e&&(e.low<n&&(n=e.low),e.high>a&&(a=e.high),h=Math.max(h,i9(d.buys)),s=Math.max(s,i9(d.sells)))}return Number.isFinite(n)&&Number.isFinite(a)?{min:n,max:a,abovePx:s,belowPx:h}:null}(o.trades,this.scene.tradeMarkers,i,e.from,e.to,this.scene.style.fontSize);r&&(t=t?{min:Math.min(t.min,r.min),max:Math.max(t.max,r.max),abovePx:Math.max(t.abovePx,r.abovePx),belowPx:Math.max(t.belowPx,r.belowPx)}:r)}return t}fitContent(){let e=this.coords.barCount,t=this.coords.width;if(e<=0||t<=0)return;for(let e of(this.animator?.stop(),this.panVelocity=0,this.scene.panes.values()))e.manualScale=null;for(let e of this.scene.indicatorScales.values())e.manualScale=null;let i=Math.min(e,200),o=this.scene.style.margins.right,r=this.clampViewport(t/((i+o)*this.coords.spacingScale),o);this.coords.setViewport(r),this.targetBarSpacing=r.barSpacing}reframeKeepZoom(){for(let e of(this.animator?.stop(),this.panVelocity=0,this.scene.panes.values()))e.manualScale=null;for(let e of this.scene.indicatorScales.values())e.manualScale=null;let e={barSpacing:iZ(this.coords.getViewport().barSpacing),rightOffset:this.scene.style.margins.right};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),i=t.find(e=>!0!==e.ownScale)??t[0];return i&&this.modelTitle(i)||null}overlayStack(){var e=this.scene.orderedIndicatorsForPane(np).filter(e=>!1!==e.legend).map(e=>({id:e.id,z:this.scene.zOf(e.id)})),t=this.scene.candleZ;let i=[...e],o=i.findIndex(e=>e.z>=t);return i.splice(o<0?i.length:o,0,{id:null,z:t}),i}syncLegendOrder(){this.inputsUI?.orderRows(this.scene.indicatorZOrder().map(e=>e.id))}restackOverlay(e,t){for(let e of function(e){let t=[];for(let i=0;i<e.length;){let o=i+1;for(;o<e.length&&e[o].z===e[i].z;)o+=1;let r=o-i;if(r>1){let l=e[i].z,n=((e[o]?.z??l+1)-l)/r;for(let o=1;o<r;o+=1){let r=e[i+o].id;null!==r&&t.push({id:r,z:l+o*n})}}i=o}return t}(this.overlayStack()))this.scene.setIndicatorZ(e.id,e.z);let i=t(this.overlayStack(),e);if(null!==i)for(let t of(this.scene.setIndicatorZ(e,i),this.syncLegendOrder(),this.scheduler.invalidate(4),this.configChangedCbs))t()}nativeLayerPane(e){for(let t of this.scene.indicators.values())if(t.native?.type===e)return this.scene.panes.get(t.paneId??np)??null;return null}createPlotCanvas(e={}){let t=document.createElement("canvas");return Object.assign(t.style,{position:"absolute",inset:"0",width:"100%",height:"100%"}),e.pointerEvents||(t.style.pointerEvents="none"),t.dir="ltr",t}ensureInstanceLayer(e){let t=e.native?.channel;if(!t||!this.plot||this.extLayers.some(t=>t.owner===e.id))return;let i=this.extLayers.find(t=>null===t.owner&&t.def.id===e.native.type);if(!i)return;let o=this.createPlotCanvas();o.width=this.dataCanvas.width,o.height=this.dataCanvas.height,o.style.width=this.dataCanvas.style.width||"100%",o.style.height=this.dataCanvas.style.height||"100%";let r={def:i.def,instance:i.def.create(),canvas:o,channel:t,owner:e.id};this.extLayers.push(r),this.plot.insertBefore(o,this.chromeCanvas),r.instance.mount(o)}dropInstanceLayer(e){let t=this.extLayers.findIndex(t=>t.owner===e);if(t<0)return;let[i]=this.extLayers.splice(t,1);i.instance.destroy?.(),i.canvas.remove()}layerOwner(e){if(null!==e.owner)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),i=t?t.paneId??np:np;return this.scene.panes.get(i)??null}orderedLayerCanvases(){let e=new Map(this.extLayers.map(e=>[e.channel,e.canvas])),{below:t,above:i}=function(e,t){let i=e.map(e=>({id:e.id,key:e.ownerZ??("below-data"===e.placement?-1/0:t)}));i.sort((e,t)=>e.key-t.key);let o=[],r=[];for(let e of i)(e.key<t?o:r).push(e.id);return{below:o,above:r}}(this.extLayers.map(e=>{let t=this.layerOwner(e);return{id:e.channel,placement:"below-data"===e.def.placement?"below-data":"above-data",ownerZ:t?this.scene.zOf(t.id):null}}),this.scene.candleZ);return{below:t.map(t=>e.get(t)),above:i.map(t=>e.get(t))}}canvasPile(){let{below:e,above:t}=this.orderedLayerCanvases();return[this.backdropCanvas,...e,this.dataCanvas,this.volumeCanvas,this.vpvrCanvas,...t]}syncLayerCanvasOrder(){if(0===this.extLayers.length||!this.plot)return;let{below:e,above:t}=this.orderedLayerCanvases(),i=[...e.map(e=>this.extLayers.find(t=>t.canvas===e).channel),"|",...t.map(e=>this.extLayers.find(t=>t.canvas===e).channel)].join(",");if(i!==this.layerOrderSig){for(let t of(this.layerOrderSig=i,e))this.plot.insertBefore(t,this.dataCanvas);for(let e of t)this.plot.insertBefore(e,this.chromeCanvas)}}volumeOwnsPane(e,t){return"price"!==e.kind&&!!this.volumeActive&&!this.volumeHidden&&!!this.scene.volumeLayer&&this.nativeLayerPane("volume")===e&&t.every(e=>e.native?.type==="volume")}layerNativesOwnPane(e,t){return"price"!==e.kind&&0!==t.length&&t.every(e=>0===e.series.length&&!!e.native&&this.extLayers.some(t=>t.def.id===e.native.type))}layerHiddenWithCandles(e){return this.scene.candlesHidden&&null===e.owner&&e.def.id===this.scene.priceStyle}priceLayersAnchoredToBars(e){return e.some(e=>0===e.series.length&&!!e.native&&this.extLayers.some(t=>t.def.id===e.native.type))}paneHasMeasurableContent(e,t){return!!t||e.some(e=>e.priceLines.length>0||e.series.some(e=>!0!==e.overlay))}paneScaleInfos(){return this.scene.orderedPanes().map(e=>({id:e.id,kind:e.kind,top:e.bounds.top,height:e.bounds.height,mode:on(this.scene,e),log:oa(this.scene,e),invert:os(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:null==e.manualScale,log:oa(this.scene,e),percent:"percent"===on(this.scene,e)}))}togglePaneAuto(e){let t=this.scene.panes.get(e);t&&(t.manualScale=null==t.manualScale?{...t.scale}:null,this.scheduler?.invalidate(4))}setPaneScaleMode(e,t){if(e===np)this.scene.scaleMode=t;else{let i=this.scene.panes.get(e);if(!i)return;i.scaleMode=t}this.scheduler?.invalidate(4)}setPaneLog(e,t){let i=e===np?this.scene.orderedPanes().find(e=>"price"===e.kind):this.scene.panes.get(e);if(e===np)this.scene.logScale=t;else{if(!i)return;i.logScale=t}i?.manualScale&&(i.manualScale.log=t),this.scheduler?.invalidate(4)}setPaneInvert(e,t){if(e===np)this.scene.invertScale=t;else{let i=this.scene.panes.get(e);if(!i)return;i.invert=t}this.scheduler?.invalidate(4)}stampScaleInvert(){for(let e of this.scene.panes.values()){let t=os(this.scene,e);for(let i of(e.scale.invert=t,e.scaleTarget.invert=t,e.manualScale&&(e.manualScale.invert=t),this.scene.ownScaleIndicatorsForPane(e.id))){let e=this.scene.indicatorScales.get(i.id);e&&(e.scale.invert=t,e.scaleTarget.invert=t,e.manualScale&&(e.manualScale.invert=t))}}}firstVisibleValue(e,t,i=t){for(let r of e){let e=this.scene.offsetOf(r.id);for(let l of r.series)if(!0!==l.overlay){if((0,o.xcs)(l))for(let o=t;o<=i;o+=1){let t=l.points[o-e]?.value;if(null!=t&&Number.isFinite(t)&&0!==t)return t}else if("candle"===l.kind||"bar"===l.kind)for(let o=t;o<=i;o+=1){let t=l.bars[o-e];if(t&&Number.isFinite(t.close)&&0!==t.close)return t.close}}}return 0}maxVisibleVolume(e,t){let i=0;for(let o=e;o<=t;o+=1){let e=this.bars[o]?.volume;null!=e&&e>i&&(i=e)}return i}layoutPanes(){let e=this.scene.orderedPanes(),t=this.coords.height;this.inputsUI?.setCollapsedPanes(this.collapsedMasterMap());let i=this.maximizedPaneId?this.scene.panes.get(this.maximizedPaneId):null;if(i){for(let o of e)o===i?o.bounds={top:0,height:t}:o.bounds={top:t,height:0},o.bounds.height;this.inputsUI?.reposition(),this.paneControls?.reposition(),this.axisScaleButtons?.reposition(),this.repositionScrollButton(),this.positionAttribution(),this.publishPricePaneBounds();return}let o=e.filter(e=>e.collapsed),r=e.filter(e=>!e.collapsed),l=Math.max(0,t-26*o.length),n=r.reduce((e,t)=>e+(t.heightWeight||1),0)||1,a=0;for(let t of e){let e=t.collapsed?26:l*(t.heightWeight||1)/n;t.bounds={top:a,height:e},a+=e}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,i=t?[t]:this.scene.orderedPanes().filter(e=>!e.collapsed),o=i.length?Math.max(...i.map(e=>e.bounds.top+e.bounds.height)):e;this.scrollBtnBottomPx=36+Math.max(0,e-o),this.mountContainer?.style.setProperty("--vela-bottom-gutter",`${22+Math.max(0,e-o)}px`),this.scrollBtnRightPx=this.rightAxisW+12,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 i=this.scene.orderedIndicatorsForPane(t.id).filter(e=>!1!==e.legend),o=new Set(this.scene.ownScaleIndicatorsForPane(t.id).map(e=>e.id)),r=i.find(e=>!o.has(e.id))??i[0];e.set(t.id,r?.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+22,t=this.scene.panes.get(np),i=t?t.bounds.top:0,o=Math.max(0,e-(i+(t?t.bounds.height:this.coords.height)));this.mountContainer.style.setProperty("--vela-price-pane-top",`${i}px`),this.mountContainer.style.setProperty("--vela-price-pane-bottom",`${o}px`)}buildAttributionEl(){return null!==this.attributionHtml?function(e,t,i){let o=e.createElement("div");return o.className="vela-attribution-custom",Object.assign(o.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",display:"flex",alignItems:"center",lineHeight:"1"}),o.style.color=no(i),o.innerHTML=t,o.dataset.velaScreenshot="1",o}(document,this.attributionHtml,this.theme.background):function(e,t,i){let o;(o=e.getElementById(nt))||((o=e.createElement("style")).id=nt,e.head.appendChild(o)),o.textContent=ni;let r=e.createElement("a");r.className="vela-attribution",r.href="https://velacharts.dev/?utm_source=vela&utm_medium=attribution",r.target="_blank",r.rel="noopener";let l=(0,n.b6)(i,nl);r.title=l,r.setAttribute("aria-label",l),Object.assign(r.style,{position:"absolute",zIndex:"6",pointerEvents:"auto",cursor:"pointer"}),nr(r,t),r.dataset.velaScreenshot="1";let a=e.createElement("span");a.className="vela-attr-symbol",a.setAttribute("aria-hidden","true"),a.innerHTML='<svg viewBox="0 -142 161.66 148" aria-hidden="true"><g fill="currentColor"><path d="M0 -140L32.91 -140L77.52 -62.73L61.06 -34.24Z"/><path d="M161.66 -140L128.75 -140L84.14 -62.73L100.59 -34.24Z"/><path d="M80.83 -52.04L95.85 -26.02L80.83 0L65.81 -26.02Z"/></g></svg>';let s=e.createElement("span");return s.className="vela-attr-wordmark",s.innerHTML='<svg viewBox="161.66 -142 310.57 148" aria-hidden="true"><g fill="currentColor"><path d="M226.3 1.17Q200.81 1.17 186.12 -12.99Q171.42 -27.15 171.42 -51.17Q171.42 -75.2 185.87 -89.6Q200.33 -104 224.25 -104Q247.4 -104 261.7 -90.58Q276.01 -77.15 276.3 -54.59Q276.3 -49.9 275.42 -45.02H200.81V-43.55Q201.2 -32.62 207.75 -26.42Q214.29 -20.21 225.03 -20.21Q233.72 -20.21 239.34 -23.93Q244.95 -27.64 246.81 -34.77H274.64Q272.1 -19.14 259.16 -8.98Q246.22 1.17 226.3 1.17ZM201.5 -63.38H247.88Q246.42 -72.75 240.27 -77.88Q234.12 -83.01 224.45 -83.01Q215.17 -83.01 208.92 -77.73Q202.67 -72.46 201.5 -63.38ZM287.54 0V-140.04H315.76V0ZM429.34 -23.83H432.56V0H418.11Q407.76 0 403.36 -4.44Q398.97 -8.89 399.16 -16.8Q387.83 1.17 365.57 1.17Q348.48 1.17 337.88 -6.74Q327.29 -14.65 327.29 -29Q327.29 -45.41 339.45 -54.3Q351.6 -63.18 374.55 -63.18H394.96V-68.16Q394.96 -75.2 390.08 -79.3Q385.2 -83.4 376.51 -83.4Q368.3 -83.4 363.03 -79.98Q357.76 -76.56 356.88 -70.8H329.73Q331.19 -85.84 344.08 -94.92Q356.97 -104 377.29 -104Q399.06 -104 410.88 -94.43Q422.7 -84.86 422.7 -66.6V-30.18Q422.7 -26.37 424.26 -25.1Q425.82 -23.83 429.34 -23.83ZM394.96 -42.38V-44.43H374.36Q365.47 -44.43 360.59 -40.92Q355.7 -37.4 355.7 -30.96Q355.7 -25.59 359.81 -22.41Q363.91 -19.24 370.94 -19.24Q381.97 -19.24 388.37 -25.54Q394.77 -31.84 394.96 -42.38Z"/><path fill-opacity="0.55" d="M437.44 -124.28H441.96V-113.41H445.34V-124.28H449.87V-127.4H437.44ZM451.43 -113.41H454.7V-123.29L458.97 -113.41H461.62L465.99 -123.29V-113.41H469.21V-127.4H464.53L460.42 -117.68L456.16 -127.4H451.43Z"/></g></svg>',r.append(a,s),r}(document,this.theme.background,this.i18n)}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,i=t?[t]:this.scene.orderedPanes().filter(e=>!e.collapsed),o=e>0&&i.length?Math.max(...i.map(e=>e.bounds.top+e.bounds.height)):e;Object.assign(this.attributionEl.style,{left:`${(this.toolbarGutter||0)+12}px`,bottom:`${32+Math.max(0,e-o)}px`})}refreshAttributionColor(){this.attributionEl&&(null!==this.attributionHtml?this.attributionEl.style.color=no(this.theme.background):nr(this.attributionEl,this.theme.background))}syncSize(){let e=this.wrapper.clientWidth,t=this.wrapper.clientHeight;if(e<=0||t<=0)return;let i=window.devicePixelRatio||1;this.plot.style.left=`${this.toolbarGutter}px`;let o=this.plot.getBoundingClientRect(),r=Math.max(1,Math.round(o.width*i)),l=Math.max(1,Math.round(o.height*i)),n=this.plotDeviceSize;n&&1>=Math.abs(n.width-o.width*i)&&1>=Math.abs(n.height-o.height*i)&&(r=Math.max(1,n.width),l=Math.max(1,n.height));let a=r/i,s=l/i,h=e=>{e.width=r,e.height=l,e.style.width=`${a}px`,e.style.height=`${s}px`};for(let e of(h(this.dataCanvas),h(this.backdropCanvas),h(this.volumeCanvas),this.extLayers))h(e.canvas);h(this.vpvrCanvas),h(this.chromeCanvas),h(this.drawingsCanvas),h(this.cursorCanvas),this.coords.setSize(Math.max(1,a-this.rightAxisW),Math.max(1,s-22),i),this.scene.crosshair=null,this.layoutPanes(),this.userDrawings?.onResize(),!this.didInitialFit&&this.coords.barCount>0&&(this.fitContent(),this.didInitialFit=!0),this.animator.active?(this.computeScales(),this.paintData(),this.renderCrosshairLayer()):this.scheduler.flushNow(4)}applyBackground(){this.wrapper.style.background=this.theme.background}};function nb(e,t){let i=new Date(e+oO(e,t)),o=e=>e<10?`0${e}`:String(e);return{date:`${i.getUTCFullYear()}-${o(i.getUTCMonth()+1)}-${o(i.getUTCDate())}`,time:`${o(i.getUTCHours())}:${o(i.getUTCMinutes())}`}}function nf(e){return Math.max(0,Math.min(1,e))}function nv(e){return"percent"===e||"indexed"===e?e:"price"}var ny=class{constructor(){this.records=new Map,this.counter=0}nextId(e="ind",t=()=>!1){let i;do this.counter+=1,i=`${e}-${this.counter}`;while(this.records.has(i)||t(i));return i}add(e){this.records.set(e.id,e)}get(e){return this.records.get(e)}remove(e){let t=this.records.get(e);return this.records.delete(e),t}all(){return[...this.records.values()]}},nw=class{constructor(e,t,i){this.feed=e,this.market=t,this.onBar=i,this.unsubscribe=null}start(){this.unsubscribe||(this.unsubscribe=this.feed.subscribe(this.market,this.onBar))}stop(){this.unsubscribe?.(),this.unsubscribe=null}},nC=class{constructor(e,t,i,o,r,l){this.controller=i,this.schema=[],this.propsSchema=[],this.visibleState=!0,this.bus=new E,this.id=e,this.title=t,void 0!==o&&(this.source=o),void 0!==r&&(this.nativeType=r),void 0!==l&&(this.language=l)}get inputs(){return this.schema}get props(){return this.propsSchema}get visible(){return this.visibleState}inputValues(){return this.controller.inputValuesOf(this.id)}propValues(){return this.controller.propValuesOf(this.id)}setInput(e,t){this.controller.applyInputs(this.id,{[e]:t})}setInputs(e){this.controller.applyInputs(this.id,e)}setProp(e,t){this.controller.applyProps(this.id,{[e]:t})}setProps(e){this.controller.applyProps(this.id,e)}updateCode(e){return this.controller.updateCode(this.id,e)}setVisible(e){this.controller.setVisible(this.id,e)}moveTo(e){this.controller.moveIndicator(this.id,e)}on(e,t){return this.bus.on(e,t)}context(e){return this.controller.getIndicatorContext(this.id,e)}remove(){this.controller.removeIndicator(this.id)}setSchema(e){this.schema=e}setPropsSchema(e){this.propsSchema=e}setSource(e){this.source=e}setVisibleState(e){this.visibleState=e}emit(e,t){this.bus.emit(e,t)}};function nx(e){let t={};for(let i of e.series)t[i.kind]=(t[i.kind]??0)+1;let i=e=>e?.filter(e=>!0===e.overlay).length??0,o=i(e.series)+i(e.fills)+i(e.backgrounds)+i(e.lines)+i(e.boxes)+i(e.labels)+i(e.polylines)+i(e.linefills)+i(e.tables);return{id:e.id,title:e.title,overlay:e.overlay,paneId:e.paneId,native:!!e.native,nativeType:e.native?.type,series:t,fills:e.fills.length,backgrounds:e.backgrounds.length,priceLines:e.priceLines.length,lines:e.lines?.length??0,boxes:e.boxes?.length??0,labels:e.labels?.length??0,polylines:e.polylines?.length??0,linefills:e.linefills?.length??0,tables:e.tables?.length??0,barColors:e.barColors?.length??0,trades:e.trades?.length??0,inputs:e.inputs.length,forcedOverlay:o}}var nk={"1D":864e5,"1W":6048e5,"1M":2592e6,"3M":7776e6,"6M":15552e6,"1Y":31536e6,"5Y":15768e7},nS=class{constructor(e,t){this.renderer=e,this.marks=new Map,this.groups=new Map,this.subs=[],this.enabled=!!e.capabilities.timelineMarks&&"function"==typeof e.setTimelineMarks,this.enabled&&e.onMarkClick&&this.subs.push(e.onMarkClick(e=>t.emit("mark:click",e)))}get supported(){return this.enabled}add(e){this.marks.set(e.id,nT(e)),this.sync()}set(e){for(let t of(this.marks.clear(),e))this.marks.set(t.id,nT(t));this.sync()}remove(e){let t=this.marks.delete(e);return t&&this.sync(),t}clear(){0!==this.marks.size&&(this.marks.clear(),this.sync())}all(){return[...this.marks.values()].map(e=>({...e,glyph:{...e.glyph}}))}defineGroup(e){if(!e||"string"!=typeof e.id||0===e.id.length)throw Error("[vela] marks.defineGroup: `id` must be a non-empty string");if("string"!=typeof e.label)throw Error(`[vela] marks.defineGroup: group "${e.id}" needs a string \`label\``);if(void 0!==e.parent&&("string"!=typeof e.parent||0===e.parent.length))throw Error(`[vela] marks.defineGroup: group "${e.id}" has a \`parent\` that is not a group id`);this.groups.set(e.id,{...e}),this.sync()}groupDefinitions(){return[...this.groups.values()].map(e=>({...e}))}setGroupVisible(e,t){if(!this.renderer.features.includes("marks"))return void console.warn(`[vela] renderer "${this.renderer.name}" does not paint timeline marks — setGroupVisible ignored.`);this.renderer.applyFeature("marks",{groups:{[e]:t}})}isGroupVisible(e){let t=this.renderer.readFeature("marks"),i={};for(let[e,o]of Object.entries(t?.groups??{}))"boolean"==typeof o&&(i[e]=o);return or(i,e,[...this.groups.values()])}destroy(){for(let e of this.subs)e();this.subs.length=0}sync(){this.enabled&&this.renderer.setTimelineMarks([...this.marks.values()],[...this.groups.values()])}};function nT(e){if(!e||"object"!=typeof e)throw Error("[vela] marks: a mark must be an object");if("string"!=typeof e.id||0===e.id.length)throw Error("[vela] marks: `id` must be a non-empty string");if("number"!=typeof e.time||!Number.isFinite(e.time))throw Error(`[vela] marks: mark "${e.id}" needs a finite epoch-ms \`time\``);if(!e.glyph||"object"!=typeof e.glyph||"string"!=typeof e.glyph.color)throw Error(`[vela] marks: mark "${e.id}" needs a glyph with a \`color\``);return{...e,glyph:{...e.glyph}}}var nM=["240","60","30","15","5","1"],nL=class{constructor(e){this.deps=e,this.cache=new Map,this.listeners=new Set}seriesInRange(e,t,i){if(!this.deps.canFetch())return{state:"unavailable",reason:"no-source"};let r=this.resolveTimeframe(e);if("string"!=typeof r)return{state:"unavailable",reason:r.reason};let l=(0,o.cle)(r),n=Math.min(t,i),a=Math.max(t,i);if(!(a>n)||!(l>0))return{state:"unavailable",reason:"not-lower"};if((a-n)/l>5e3)return{state:"unavailable",reason:"too-wide"};let s=`${this.deps.marketKey()}|${r}`,h=this.cache.get(s)??[],d=h.find(e=>e.from<=n&&e.to>=a);if(d){if(d.pending)return this.loading(h,r,l,n,a);if(!(d.failedAt>0))return this.maybeRefresh(s,d,r,l,a),{state:"ready",bars:this.slice(d.bars,n,a),timeframe:r,barMs:l};if(Date.now()-d.failedAt<15e3)return this.loading(h,r,l,n,a);h.splice(h.indexOf(d),1)}return this.fetchWindow(s,h,r,n,a),this.loading(h,r,l,n,a)}onUpdate(e){return this.listeners.add(e),()=>this.listeners.delete(e)}resolveTimeframe(e){if((0,o.jJY)(this.deps.chartTimeframe()))return{reason:"none-lower"};let t=(0,o.cle)(this.deps.chartTimeframe()),i=nM[nM.length-1];if((0,o.cle)(i)>=t)return{reason:"none-lower"};let r=e.trim()||"auto";if("auto"===r){for(let e of nM)if((0,o.cle)(e)<=t/4)return e;return i}return(0,o.cle)(r)<t?r:{reason:"not-lower"}}loading(e,t,i,o,r){let l=new Map;for(let t of e)if(!t.pending&&!(t.failedAt>0)&&!(t.to<o)&&!(t.from>r))for(let e of this.slice(t.bars,o,r))l.set(e.time,e);return 0===l.size?{state:"loading",timeframe:t,barMs:i}:{state:"loading",timeframe:t,barMs:i,bars:[...l.values()].sort((e,t)=>e.time-t.time)}}fetchWindow(e,t,i,o,r){if(t.some(e=>e.pending&&e.to>=o&&e.from<=r))return;let l=(r-o)*.25,n={from:o-l,to:r+l,bars:[],fetchedAt:0,pending:!0,failedAt:0};t.push(n),this.cache.set(e,t),this.evict(),this.deps.fetchBars(i,{from:n.from,to:n.to}).then(t=>{n.bars=t,n.fetchedAt=Date.now(),n.pending=!1,this.absorbOverlaps(e,n),this.fire()}).catch(()=>{n.pending=!1,n.failedAt=Date.now(),this.fire()})}maybeRefresh(e,t,i,o,r){t.pending||r<(t.bars.length>0?t.bars[t.bars.length-1].time:t.from)||Date.now()-t.fetchedAt<o||(t.pending=!0,this.deps.fetchBars(i,{from:t.from,to:t.to}).then(e=>{t.bars=e,t.fetchedAt=Date.now(),t.pending=!1,this.fire()}).catch(()=>{t.pending=!1,t.fetchedAt=Date.now()}))}absorbOverlaps(e,t){let i=this.cache.get(e);if(i)for(let e=i.length-1;e>=0;e-=1){let o=i[e];if(o===t||o.pending||o.failedAt>0||o.to<t.from||o.from>t.to)continue;let r=new Map;for(let e of o.bars)r.set(e.time,e);for(let e of t.bars)r.set(e.time,e);t.bars=[...r.values()].sort((e,t)=>e.time-t.time),t.from=Math.min(t.from,o.from),t.to=Math.max(t.to,o.to),t.fetchedAt=Math.min(t.fetchedAt,o.fetchedAt||t.fetchedAt),i.splice(e,1)}}evict(){let e=0;for(let t of this.cache.values())e+=t.length;for(;e>16;){let t=null,i=-1,o=1/0;for(let[e,r]of this.cache)for(let l=0;l<r.length;l+=1){let n=r[l];if(n.pending)continue;let a=n.fetchedAt||n.failedAt;a<o&&(t=e,i=l,o=a)}if(null==t)return;let r=this.cache.get(t);r.splice(i,1),0===r.length&&this.cache.delete(t),e-=1}}slice(e,t,i){let o=[];for(let r of e)if(!(r.time<t)){if(r.time>i)break;o.push(r)}return o}fire(){for(let e of[...this.listeners])e()}};function nA(e){return null!=e&&"string"!=typeof e?e:void 0}function nP(e,t={}){let{title:i,tooltip:o,display:r,...l}=e,a={...r},s=nA(i);s&&!a.title&&(a.title=s);let h=nA(o);h&&!a.tooltip&&(a.tooltip=h);let d=null!=l.group?t.groups?.[l.group]:void 0;if(d&&!a.group&&(a.group=d),l.options&&t.options&&!a.options){let e={},i=!1;for(let o of l.options){let r=t.options[o];r&&(e[o]=r,i=!0)}i&&(a.options=e)}let c={...l,title:(0,n.rI)(i)};return null!=o&&(c.tooltip=(0,n.rI)(o)),Object.keys(a).length>0&&(c.display=a),c}var nI=class e{constructor(e,t,i,r,l,a){for(let e of(this.renderer=t,this.feed=i,this.config=l,this.dataControl=a,this.events=new E,this.registry=new ny,this.paneOrder=["price"],this.collapsedPanes=new Set,this.maximizedPaneId=null,this.paneActionUnsub=null,this.i18n=(0,n.Db)(),this.handles=new Map,this.engines=new Map,this.live=null,this.bars=[],this.rawBars=[],this.barTransform=null,this.typeEngines=new Map,this.suspendedEngines=new WeakSet,this.typeSettings=new Map,this.activeEngineStyle=null,this.priceStyle="candles",this.priceStyleWillChangeUnsub=null,this.unresolvedUnsub=null,this.visibleRange=null,this.viewportUnsub=null,this.viewportTimer=null,this.healing=!1,this.healBuffer=[],this.lastHealAt=0,this.onVisible=null,this.replayQueue=null,this.replayTimer=null,this.replayPlaying=!1,this.replayIntervalMs=1e3,this.replayDepth=null,this.replayLoading=null,this.replayCarrying=null,this.replayTickSource=null,this.replayForming=null,this.replayTickFetches=new Map,this.replayTickAbort=null,this.barCause="tick",this.historyState="complete",this.generation=0,this.progressiveAbort=null,this.supersedeWaiters=[],this.historyCompleted=!1,this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e}),this.switchingMarket=!1,this.loadingUp=!1,this.unavailableGen=-1,this.volumeOptedOut=!1,this.volumeFactsWait=null,this.facts=null,this.factsProbe=0,this.contextEmitAt=new Map,this.runEmitAt=new Map,r))this.registerEngine(e.language,e);this.defaultLanguage=l.defaultLanguage,this.renderer.mount(e,l.theme),this.renderer.onInputChange(e=>"prop"===e.kind?this.applyProps(e.indicatorId,{[e.key]:e.value}):this.applyInputs(e.indicatorId,{[e.key]:e.value})),this.renderer.onRemoveIndicator(e=>this.removeIndicator(e)),this.renderer.onToggleIndicatorVisible?.((e,t)=>this.setVisible(e,t)),this.paneActionUnsub=this.renderer.onPaneAction?.(e=>this.handlePaneAction(e))??null,this.renderer.onChartTypeSettingsChange?.((e,t)=>{this.typeSettings.set(e,t),this.typeEngines.get(e)?.onSettings?.(t)}),this.renderer.onMoveIndicator?.((e,t)=>this.moveIndicator(e,t)),this.renderer.onThemeSelect?.(e=>this.setTheme(K(e))),this.viewportUnsub=this.renderer.onViewportChange(e=>this.onViewportChange(e)),this.renderer.onPriceStyleChange?.(e=>this.syncPriceStyle(e)),this.priceStyleWillChangeUnsub=this.renderer.onPriceStyleWillChange?.((e,t)=>this.events.emit("priceStyle:change",{from:e,to:t}))??null;let s=this.renderer.readFeature("priceStyle");"string"==typeof s&&(this.priceStyle=s),this.barTransform=rT(s);let h=new nL({fetchBars:(e,t)=>this.fetchSeries(this.config.market.symbol??"",e,t),canFetch:()=>!!this.feed.loadRange&&!this.config.market.data?.length&&!!this.config.market.symbol,chartTimeframe:()=>this.config.market.timeframe??"60",marketKey:()=>`${this.config.market.symbol??""}|${this.config.market.session??""}`});this.drawings=new eD(this.renderer,this.events,l.drawings,h,()=>this.i18n),this.marks=new nS(this.renderer,this.events),this.unresolvedUnsub=this.feed.onUnresolved?.(e=>{this.endLoad(),this.events.emit("data:unresolved",e)})??null,this.readyPromise=this.init(),(0,o.V$N)(s)?.dataEngine&&this.syncChartTypeEngine(s)}currentVisibleRange(){if(this.visibleRange)return this.visibleRange;let e=this.renderer.getVisibleRange();return e?{left:e.from,right:e.to}:void 0}engineFor(e){let t=e??this.defaultLanguage,i=this.engines.get(t);if(!i)throw Error(`[vela] no scripting engine registered for language "${t}". Vela ships none — install one (Pine Script: @luxalgo/vela-pinets) and register it before addIndicator, e.g. chart.registerEngine('pine', new PineEngine()).`);return i}market(){return{symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",symbolInfo:this.feed.symbolInfo?.(this.config.market),chartStyle:this.priceStyle,session:this.config.market.session}}async fetchSeries(e,t,i){let o,r=rM(e),l="regular"===(o=i.session)||"extended"===o?o:void 0,n={symbol:r.symbol,timeframe:t,...l?{session:l}:{}},a=await (this.feed.loadRange?this.feed.loadRange(n,i):this.feed.load({...n,bars:i.limit}));return r.transform?r.transform.full(a):a}onViewportChange(e){this.visibleRange={left:e.from,right:e.to},this.events.emit("viewport:changed",{from:e.from,to:e.to}),null!=this.viewportTimer&&clearTimeout(this.viewportTimer),this.viewportTimer=setTimeout(()=>{if(this.viewportTimer=null,this.switchingMarket)return;let e=this.visibleRange;if(e){for(let t of this.registry.all())t.renderHandle&&!t.hidden&&(t.session&&t.prepared?.reactsToViewport?(t.pendingCause="viewport",t.session.setVisibleRange(e)):t.native?.descriptor.reactsToViewport&&t.native.instance.onViewport({from:e.left,to:e.right}));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onViewport?.({from:e.left,to:e.right})}},150)}async init(){let e=this.bumpGeneration();this.beginLoad(!0),await this.loadMarket(e,{firstLoad:!0}),this.generation===e&&(this.startLive(),this.events.emit("ready",void 0))}bumpGeneration(){let e=++this.generation;for(let e of(this.progressiveAbort?.abort(),this.progressiveAbort=null,this.supersedeWaiters.splice(0)))e();return e}marketUnavailable(e,t){if(this.generation!==e||this.unavailableGen===e)return;this.unavailableGen=e,console.warn(`[vela] ${t.message}`),this.stopLive(),this.completeHistory("aborted"),this.endLoad();let i=this.config.market;this.events.emit("data:unavailable",{symbol:i.symbol??"TEST",timeframe:i.timeframe??"60",reason:t.reason,...void 0!==t.finest?{finest:t.finest}:{},...void 0!==t.default?{default:t.default}:{}})}beginLoad(e){if(this.loadingUp)return;this.loadingUp=!0,this.renderer.setLoading?.(!0);let t=this.config.market;this.events.emit("load:start",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",firstLoad:e})}endLoad(){if(!this.loadingUp)return;this.loadingUp=!1,this.renderer.setLoading?.(!1);let e=this.config.market;this.events.emit("load:end",{symbol:e.symbol??"TEST",timeframe:e.timeframe??"60",bars:this.bars.length})}async loadMarket(e,t){try{await this.loadMarketInner(e,t)}catch(t){if(!(0,o.DhR)(t))throw t;this.marketUnavailable(e,t)}finally{this.generation===e&&this.endLoad()}}async loadMarketInner(e,t){let i=this.config.market;this.syncSymbolFacts();let r=i.bars??500,l=i.visibleRange,n=!i.data?.length&&null==l&&r>5e3,a=!1;if(!i.data?.length&&null==l&&this.feed.loadProgressive){let l=!1,n=(i,o)=>{if(this.generation!==e||!o&&0===i.length||!l&&!o&&i.length<Math.min(r,20))return;if(l&&this.replayQueue)return void this.mergeHistoryIntoReplay(i);let n=l;this.setBarSeries(i,n?{preserveView:!0}:void 0),!l&&i.length>0&&(l=!0,t.firstLoad&&this.activateBarLayers(),o||(this.historyState="backfill")),n&&!o&&this.notifySessionsBars("backfill")},s=new AbortController;this.progressiveAbort=s,a=await new Promise(t=>{let a=!1,h=e=>{a||(a=!0,t(e))};s.signal.addEventListener("abort",()=>h(!0),{once:!0}),this.feed.loadProgressive(i,e=>{n(e,!1),l&&h(!0)},{signal:s.signal}).then(t=>(this.progressiveAbort===s&&(this.progressiveAbort=null),null==t)?h(!1):this.generation!==e?h(!0):void(n(t,!0),this.completeHistory(t.length>=r?"depth":"genesis"),h(!0))).catch(t=>{this.progressiveAbort===s&&(this.progressiveAbort=null),(0,o.DhR)(t)?this.marketUnavailable(e,t):this.generation===e&&this.completeHistory("aborted"),h(!0)})})}if(a);else if(n&&this.feed.loadRange){let o=await this.feed.load({...i,bars:Math.min(r,1e4)});if(this.generation!==e)return;this.setBarSeries(o),t.firstLoad&&this.activateBarLayers(),o.length>0&&r>o.length?(this.historyState="backfill",this.backfillHistory(e,r)):this.completeHistory("depth")}else if(n){let o=await this.feed.load({...i,bars:300});if(this.generation!==e)return;this.setBarSeries(o),t.firstLoad&&this.activateBarLayers();let r=await this.feed.load(i);if(this.generation!==e)return;this.setBarSeries(r,{preserveView:!0}),this.completeHistory("depth")}else{let o=await this.feed.load(i);if(this.generation!==e)return;this.setBarSeries(o),t.firstLoad&&this.activateBarLayers(),this.completeHistory("depth")}null!=l&&("string"==typeof l?this.setVisibleRangePreset(l):this.renderer.setVisibleRange(l)),this.syncSymbolFacts({refresh:!0})}startLive(){this.config.live&&this.unavailableGen!==this.generation&&(this.live=new nw(this.feed,this.config.market,e=>this.onBar(e)),this.live.start(),"undefined"!=typeof document&&(this.onVisible=()=>{if("visible"!==document.visibilityState)return;let e=this.bars[this.bars.length-1];!e||this.healing||!this.canHeal()||Date.now()-this.lastHealAt<=5e3||this.healGap(e.time)},document.addEventListener("visibilitychange",this.onVisible)))}stopLive(){this.live?.stop(),this.live=null,this.onVisible&&"undefined"!=typeof document&&document.removeEventListener("visibilitychange",this.onVisible),this.onVisible=null,this.healing=!1,this.healBuffer=[],this.lastHealAt=0}resetHistoryTracking(){this.resolveHistoryComplete(),this.historyCompleted=!1,this.historyState="complete",this.historyCompletePromise=new Promise(e=>{this.resolveHistoryComplete=e})}marketSnapshot(){let e=this.config.market;return{symbol:e.symbol,provider:ei(e.symbol??"").provider??void 0,timeframe:e.timeframe,bars:e.bars,session:e.session,offline:void 0!==e.data}}async setMarket(e){let t=this.config.market,i=!0===e.force||void 0!==e.symbol&&e.symbol!==t.symbol||void 0!==e.timeframe&&e.timeframe!==t.timeframe||void 0!==e.session&&e.session!==t.session||void 0!==e.data,o=void 0!==e.bars&&e.bars!==t.bars,r=i&&void 0===e.data&&(void 0===e.symbol||e.symbol===t.symbol)&&(void 0!==e.timeframe||void 0!==e.session),l=i?this.replayCarrying:null;l&&(this.replayCarrying=null,r||(l.cancelled=!0,this.events.emit("replay:end",{reason:"market"})));let n=this.replayQueue&&r&&this.rawBars.length>0?{revealedEnd:this.rawBars[this.rawBars.length-1].time+this.barIntervalMs(),playing:this.replayPlaying,cancelled:!1}:l&&r?{revealedEnd:l.revealedEnd,playing:l.playing,cancelled:!1}:null;if(l&&(l.cancelled=!0),n&&(this.replayCarrying=n),n&&this.replayQueue){this.endReplay(null,{restore:!1,resume:!1});let i=this.replayDepth;this.replayDepth=null,i&&void 0===e.bars&&(void 0===i.bars?delete t.bars:t.bars=i.bars)}if(this.replayQueue&&(i||o)&&this.endReplay("market",{restore:!i,resume:!1}),this.replayLoading&&(i||o)){let i=this.replayDepth;this.abandonReplayLoad("market"),i&&void 0===e.bars&&(void 0===i.bars?delete t.bars:t.bars=i.bars)}let a=o&&!i&&this.rawBars.length>0&&!t.data?.length&&((e.bars??0)<=this.rawBars.length||"function"==typeof this.feed.loadRange);if(!i&&!o)return void("string"==typeof e.visibleRange?this.setVisibleRangePreset(e.visibleRange):e.visibleRange&&this.renderer.setVisibleRange(e.visibleRange));let s={symbol:t.symbol??"TEST",timeframe:t.timeframe??"60"};void 0!==e.symbol&&e.symbol!==t.symbol&&this.drawings.onSymbolChange();let h=i&&void 0!==e.session&&void 0===e.data&&(void 0===e.symbol||e.symbol===t.symbol)&&(void 0===e.timeframe||e.timeframe===t.timeframe)&&void 0===e.visibleRange?this.currentVisibleRange():void 0,d=h?this.rawBars.filter(e=>e.time>=h.left&&e.time<=h.right).length:0,c=this.bumpGeneration();this.switchingMarket=!0;try{if(this.stopLive(),null!=this.viewportTimer&&(clearTimeout(this.viewportTimer),this.viewportTimer=null),this.visibleRange=null,this.resetHistoryTracking(),void 0!==e.symbol&&(t.symbol=e.symbol),void 0!==e.timeframe&&(t.timeframe=e.timeframe),void 0!==e.bars&&(t.bars=e.bars),void 0!==e.session&&(t.session=e.session),h){let e=Math.min(Math.ceil((Date.now()-h.left)/this.barIntervalMs())+50,5e3);e>(t.bars??500)&&(t.bars=e)}if(void 0!==e.data?t.data=e.data:void 0!==e.symbol&&delete t.data,t.visibleRange=e.visibleRange??(h?{from:h.left,to:h.right}:void 0),i)for(let e of(this.beginLoad(!1),this.setBarSeries([],{clearing:!0}),this.blankIndicatorVisuals(),this.activeEngineStyle&&(this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.renderer.setNativeData?.(this.activeEngineStyle,void 0),this.renderer.setNativeData?.(`${this.activeEngineStyle}-pending`,[])),this.registry.all()))e.native?.started&&(this.stopNativeInstance(e.native),this.renderer.setNativeData?.(this.nativeChannel(e),void 0));if(a?this.extendDepth(c,t.bars??500):await Promise.race([this.loadMarket(c,{firstLoad:!1}),new Promise(e=>this.supersedeWaiters.push(e))]),this.generation!==c)return}finally{this.generation===c&&(this.switchingMarket=!1)}if(h&&d>=2&&this.rawBars.length>0){let e=this.rawBars,t=e.length-1;for(;t>0&&e[t].time>h.right;)t-=1;let i=e[Math.max(0,t-(d-1))].time;this.renderer.setVisibleRange({from:i,to:Math.max(h.right,e[t].time+1)})}let p=n&&!n.cancelled?n:null,u=p?p.revealedEnd-this.barIntervalMs():0,g=null!=p&&this.rawBars.length>0&&u>=this.rawBars[0].time,m=g&&this.resumeCarriedReplay(this.replayStart({from:u}),p);a||m||(this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators()),a&&this.releaseHeldNatives(),m||this.startLive(),i&&this.events.emit("market:changed",{symbol:t.symbol??"TEST",timeframe:t.timeframe??"60",prev:s}),p&&!g&&this.resumeCarriedReplay(this.replayStart({from:u}),p)}restartNativeIndicators(){for(let e of this.registry.all())if(e.native)if(this.stopNativeInstance(e.native),e.native.instance=e.native.descriptor.create(),e.pendingStructural=!0,e.hidden)e.native.stale=!0;else{let t=this.handles.get(e.id);t&&this.startNativeIndicator(e.id,t)}}restartChartTypeEngine(){for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle&&this.startChartTypeEngine(this.activeEngineStyle)}suspendTypeEngine(e){e&&(e.suspend(),this.suspendedEngines.add(e))}stopNativeInstance(e){e.started&&e.instance.stop(),e.started=!1,e.revokeContext?.(),e.revokeContext=void 0}activateBarLayers(){this.maybeAutoAddVolume()}extendDepth(e,t){if(this.rawBars.length>t){this.setBarSeries(this.rawBars.slice(this.rawBars.length-t),{preserveView:!0}),this.completeHistory("depth");return}if(this.rawBars.length===t)return void this.completeHistory("depth");this.historyState="backfill",this.backfillHistory(e,t)}async backfillHistory(e,t){try{for(;this.generation===e&&this.rawBars.length<t&&this.rawBars.length>0;){let i=t-this.rawBars.length,r=await this.feed.loadRange(this.config.market,{to:this.rawBars[0].time,limit:Math.min(1e4,i)+1});if(this.generation!==e)return;let l=this.rawBars[0].time,n=r.filter(e=>e.time<l);if(0===n.length)return void this.completeHistory("genesis");for(let e=1;e<n.length;e+=1)if(!(0,o.vQt)(n[e],n[e-1])){console.warn("[vela] non-monotonic history chunk — stopping the backfill"),this.completeHistory("aborted");return}this.setBarSeries([...n,...this.rawBars],{preserveView:!0}),this.notifySessionsBars("backfill"),this.events.emit("history:progress",{loaded:this.rawBars.length,target:t})}this.generation===e&&this.completeHistory("depth")}catch(t){if((0,o.DhR)(t))return this.marketUnavailable(e,t);console.warn(`[vela] history backfill failed — keeping ${this.rawBars.length} bars (${t instanceof Error?t.message:String(t)})`),this.generation===e&&this.completeHistory("aborted")}}completeHistory(e){this.historyCompleted||(this.historyCompleted=!0,this.historyState="complete",this.notifySessionsBars("complete"),this.events.emit("history:complete",{reason:e,oldestTime:this.rawBars[0]?.time??0,barsLoaded:this.rawBars.length}),this.resolveHistoryComplete())}historyComplete(){return this.historyCompletePromise}async replayStart(e){if(0===this.rawBars.length)return void console.warn("[vela] chart.replay.start() ignored — the chart has no bars yet");let t=this.generation;if(e.from<this.rawBars[0].time&&(await this.historyCompletePromise,this.generation!==t||0===this.rawBars.length))return;let i=this.rawBars[0].time;if(e.from<i&&this.canHeal()&&"function"==typeof this.feed.loadRange){let o=this.rawBars.length+(this.replayQueue?.length??0)+Math.ceil((i-e.from)/this.barIntervalMs())+1,r=null!==this.replayQueue;r&&this.endReplay(null,{restore:!0,resume:!1}),this.replayDepth??(this.replayDepth={bars:this.config.market.bars});let l=this.setMarket({bars:o});if(this.replayLoading={seek:r},await l,t=this.generation,await this.historyCompletePromise,!this.replayLoading||this.generation!==t||0===this.rawBars.length)return;this.replayLoading=null}this.settleFormingBar(),this.dropTickFetches();let o=this.replayQueue?[...this.rawBars,...this.replayQueue]:this.rawBars,r=0;for(;r<o.length&&o[r].time<=e.from;)r+=1;if((r=Math.max(1,r))>=o.length)return void console.warn("[vela] chart.replay.start() ignored — no bar opens after the requested time");let l=this.replayPlaying;this.clearReplayTimer(),this.replayQueue||this.stopLive(),this.replayQueue=o.slice(r),this.setBarSeries(o.slice(0,r)),this.restartBarConsumers({blank:!0}),l&&this.events.emit("replay:pause",void 0),this.events.emit("replay:start",{cursorTime:o[r-1].time,remaining:this.replayQueue.length}),this.prefetchTicks()}replayStep(){if(this.replayForming)return this.finishFormingBar(),!0;let e=this.replayQueue,t=e?.shift();return!!e&&!!t&&(this.replayTickFetches.delete(t.time),this.applyBar(t),this.completeReveal(t),this.prefetchTicks(),!0)}resumeCarriedReplay(e,t){return this.replayQueue&&this.replayCarrying===t&&(this.replayCarrying=null),e.then(()=>{this.replayCarrying===t&&(this.replayCarrying=null),!t.cancelled&&(this.replayQueue?t.playing&&this.replayPlay():this.events.emit("replay:end",{reason:"market"}))}),null!==this.replayQueue}replayStepUpdate(){if(!this.replayQueue)return!1;if(this.replayForming)return this.applyReplayTicks(1),!0;let e=this.replayQueue[0];if(!e)return!1;let t=this.replayTickSource?this.requestTicks(e):null;if(t&&!t.ticks){let i=this.replayTickAbort;return t.done.then(()=>{this.replayPlaying||this.replayForming||this.replayTickAbort!==i||this.replayQueue?.[0]!==e||this.replayStepUpdate()}),!0}return t?.ticks?.length?(this.openFormingBar(t.ticks,1),!0):this.replayStep()}replaySetTicks(e){this.finishFormingBar(),this.dropTickFetches(),this.replayTickSource=e,this.prefetchTicks()}replayPlay(e){if(this.replayQueue){if(void 0!==e){if(!(Number.isFinite(e)&&e>0))return void console.warn(`[vela] chart.replay.play(${e}) ignored — the interval must be a positive number of ms`);this.replayIntervalMs=e}this.clearReplayTimer(),this.replayPlaying=!0,this.replayForming&&this.paceFormingBar(this.replayForming),this.scheduleReplayStep(this.replayForming?.delayMs),this.events.emit("replay:play",{intervalMs:this.replayIntervalMs})}}replayPause(){this.replayPlaying&&(this.clearReplayTimer(),this.events.emit("replay:pause",void 0))}replayStop(){let e=this.replayCarrying;if(e&&(e.cancelled=!0,this.replayCarrying=null,this.events.emit("replay:end",{reason:"stopped"})),this.replayLoading){let e=this.replayDepth;this.abandonReplayLoad("stopped"),this.setMarket({bars:e?.bars??500});return}this.endReplay("stopped",{restore:!0,resume:!0})}abandonReplayLoad(e){let t=this.replayLoading;t&&(this.replayLoading=null,this.replayDepth=null,t.seek&&this.events.emit("replay:end",{reason:e}))}replayState(){let e=null!==this.replayQueue;return{active:e||null!==this.replayCarrying,playing:this.replayCarrying?.playing??this.replayPlaying,cursorTime:e?this.rawBars[this.rawBars.length-1]?.time??null:null,remaining:this.replayQueue?.length??0,nextTime:this.replayForming?.bar.time??this.replayQueue?.[0]?.time??null,intervalMs:this.replayIntervalMs}}replayBounds(){let e=this.rawBars[0],t=this.replayQueue?.[this.replayQueue.length-1]??this.rawBars[this.rawBars.length-1];return e&&t?{first:e.time,last:t.time}:null}scheduleReplayStep(e=this.replayIntervalMs){this.replayTimer=setTimeout(()=>{this.replayTimer=null,this.replayAdvance()},e)}replayAdvance(){if(!this.replayPlaying||!this.replayQueue)return;let e=this.replayForming;if(e){let t=Math.floor((nE()-e.origin)/this.replayIntervalMs)+1;this.applyReplayTicks(Math.max(e.batch,t-e.next)),this.replayPlaying&&this.scheduleReplayStep(e.delayMs);return}let t=this.replayQueue[0];if(!t)return;let i=this.replayTickSource?this.requestTicks(t):null;if(i&&!i.ticks){let e=this.replayTickAbort;i.done.then(()=>{this.replayPlaying&&null==this.replayTimer&&this.replayTickAbort===e&&this.replayQueue?.[0]===t&&this.replayAdvance()});return}if(!i?.ticks?.length){this.replayStep()&&this.replayPlaying&&this.scheduleReplayStep();return}this.openFormingBar(i.ticks),this.replayPlaying&&this.scheduleReplayStep(this.replayForming?.delayMs)}openFormingBar(e,t){let i=this.replayQueue.shift(),o=e.every(e=>void 0===e.volume)?(i.volume??0)/e.length:null,r={bar:i,ticks:e,next:0,candle:null,volumeEach:o,batch:1,delayMs:this.replayIntervalMs,origin:0};this.paceFormingBar(r),this.replayForming=r,this.applyReplayTicks(t??r.batch),this.prefetchTicks()}paceFormingBar(e){e.batch=Math.max(1,Math.ceil(16/this.replayIntervalMs)),e.delayMs=this.replayIntervalMs*e.batch,e.origin=nE()-Math.max(0,e.next-1)*this.replayIntervalMs}applyReplayTicks(e){let t=this.replayForming;if(!t)return;let i=t.candle,o=Math.min(t.ticks.length,t.next+e);for(;t.next<o;t.next+=1){let e=t.ticks[t.next],o=t.volumeEach??e.volume??0,r=Math.max(e.high??e.price,e.price),l=Math.min(e.low??e.price,e.price);if(i)i={...i,high:Math.max(i.high,r),low:Math.min(i.low,l),close:e.price,volume:(i.volume??0)+o};else{let n=e.open??e.price;i={time:t.bar.time,open:n,high:Math.max(n,r),low:Math.min(n,l),close:e.price,volume:o}}}if(t.candle=i,t.next>=t.ticks.length)return void this.finishFormingBar();this.applyBar(i),this.events.emit("replay:tick",{cursorTime:t.bar.time,index:t.next-1,count:t.ticks.length})}finishFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.replayTickFetches.delete(e.bar.time),this.applyBar(e.bar),this.events.emit("replay:tick",{cursorTime:e.bar.time,index:e.ticks.length-1,count:e.ticks.length}),this.completeReveal(e.bar))}settleFormingBar(){let e=this.replayForming;e&&(this.replayForming=null,this.applyBar(e.bar))}mergeHistoryIntoReplay(e){let t=this.replayQueue,i=this.rawBars[0];if(!t||!i)return;let o=t[t.length-1]??this.rawBars[this.rawBars.length-1],r=0;for(;r<e.length&&e[r].time<i.time;)r+=1;let l=e.length;for(;l>r&&e[l-1].time>o.time;)l-=1;l<e.length&&t.push(...e.slice(l)),r>0&&(this.setBarSeries([...e.slice(0,r),...this.rawBars],{preserveView:!0}),this.notifySessionsBars("backfill"))}completeReveal(e){let t=this.replayQueue;t&&(this.events.emit("replay:step",{cursorTime:e.time,remaining:t.length}),0===t.length&&this.endReplay("finished",{restore:!0,resume:!0}))}prefetchTicks(){let e=this.replayQueue?.[0];e&&this.replayTickSource&&this.requestTicks(e)}requestTicks(e){let t=this.replayTickFetches.get(e.time);if(t)return t;let i=this.replayTickSource;this.replayTickAbort??(this.replayTickAbort=new AbortController);let o=this.replayTickAbort.signal,r=this.replayQueue??[],l=r[r.indexOf(e)+1]?.time??e.time+this.barIntervalMs(),n={ticks:null,done:Promise.resolve()},a=e=>{n.ticks=function(e){if(!Array.isArray(e))return[];let t=e=>void 0===e||Number.isFinite(e);return e.filter(e=>null!=e&&Number.isFinite(e.price)&&t(e.volume)&&t(e.high)&&t(e.low)&&t(e.open))}(e)},s=e=>{o.aborted||console.warn(`[vela] replay tick source failed — revealing the bar whole (${e instanceof Error?e.message:String(e)})`),a([])};try{let t=i(e,{end:l,signal:o});Array.isArray(t)?a(t):n.done=Promise.resolve(t).then(a,s)}catch(e){s(e)}return this.replayTickFetches.set(e.time,n),n}dropTickFetches(){this.replayTickAbort?.abort(),this.replayTickAbort=null,this.replayTickFetches.clear()}clearReplayTimer(){null!=this.replayTimer&&clearTimeout(this.replayTimer),this.replayTimer=null,this.replayPlaying=!1}endReplay(e,t){let i=this.replayQueue;if(!i)return;this.clearReplayTimer(),t.restore?this.settleFormingBar():this.replayForming=null,this.dropTickFetches(),this.replayQueue=null;let o=e?this.replayDepth:null;if(e&&(this.replayDepth=null),o&&(void 0===o.bars?delete this.config.market.bars:this.config.market.bars=o.bars),t.restore){let e=o?o.bars??500:1/0;if(i.length>0||this.rawBars.length>e){let t=[...this.rawBars,...i];this.setBarSeries(t.length>e?t.slice(t.length-e):t),this.restartBarConsumers({blank:!1})}else this.config.live&&(this.restartNativeIndicators(),this.restartChartTypeEngine())}if(t.resume&&this.config.live){this.startLive();let e=this.rawBars[this.rawBars.length-1];e&&this.canHeal()&&this.healGap(e.time)}e&&this.events.emit("replay:end",{reason:e})}restartBarConsumers(e){e.blank&&this.blankIndicatorVisuals(),this.restartNativeIndicators(),this.restartChartTypeEngine(),this.reexecuteIndicators()}qualifiedSymbol(){let e=this.config.market;return e.symbol?e.symbol:null}maybeAutoAddVolume(){if(!this.config.volume||this.volumeOptedOut||!this.renderer.setNativeData||!(0,o.fPj)("volume"))return;let e=this.feed.symbolInfo?.(this.config.market),t=this.qualifiedSymbol();if(void 0===e&&t&&this.symbolFactsComing(t)){let e={symbol:t};this.volumeFactsWait=e,this.dataControl.symbolInfo(t).catch(()=>void 0).then(i=>{this.volumeFactsWait===e&&(this.volumeFactsWait=null,this.qualifiedSymbol()!==t||this.volumeOptedOut||i?.volume!==!1&&this.addNativeIndicator("volume"))});return}e?.volume!==!1&&this.addNativeIndicator("volume")}symbolFactsComing(e){if(this.config.market.data?.length)return!1;let t=this.dataControl.resolve(e);return!!t&&"function"==typeof this.dataControl.providerInstance(t.provider)?.getSymbolInfo}symbolFacts(){return this.facts?{...this.facts}:null}syncSymbolFacts({refresh:e=!1}={}){let t=++this.factsProbe,i=this.qualifiedSymbol();this.renderer.setSymbolName?.(i?ei(i).ticker:void 0);let o=this.feed.symbolInfo?.(this.config.market);this.applySymbolFacts(nF(o)),!(!i||this.config.market.data?.length)&&(void 0===o||e)&&this.dataControl.symbolInfo(i).catch(()=>void 0).then(e=>{this.factsProbe===t&&this.qualifiedSymbol()===i&&void 0!==e&&this.applySymbolFacts(nF(e))})}applySymbolFacts(e){let t=this.facts,i=t?.mintick!==e?.mintick;t===e||t&&e&&t.ohlc===e.ohlc&&t.volume===e.volume&&!i||(this.facts=e,i&&this.renderer.setPricePrecision?.(e?.mintick),this.renderer.setSymbolFacts?.(e),this.events.emit("symbol:facts",{symbol:this.config.market.symbol??"TEST",facts:this.symbolFacts()}))}pendingNativeIndicators(){let e=this.volumeFactsWait;return!e||e.symbol!==this.qualifiedSymbol()||this.volumeOptedOut||this.presentNativeIndicators().includes("volume")?[]:["volume"]}syncPriceStyle(e){"string"==typeof e&&(this.priceStyle=e),this.syncBarTransform(e),this.syncChartTypeEngine(e)}syncChartTypeEngine(e){let t="string"==typeof e?e:null,i=(0,o.V$N)(t),r=i?.dataEngine?t:null;r!==this.activeEngineStyle&&(this.activeEngineStyle&&this.suspendTypeEngine(this.typeEngines.get(this.activeEngineStyle)),this.activeEngineStyle=r,r&&this.startChartTypeEngine(r))}async startChartTypeEngine(e){if(!this.renderer.setNativeData||(await this.readyPromise,this.activeEngineStyle!==e))return;let t=this.typeEngines.get(e);if(t){this.suspendedEngines.delete(t),t.resume();return}let i=(0,o.V$N)(e);if(!i?.dataEngine)return;let r=i.dataEngine();this.typeEngines.set(e,r);let l=this.typeSettings.get(e);l&&r.onSettings?.(l);let n=()=>this.typeEngines.get(e)===r&&!this.suspendedEngines.has(r);r.start({symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:(this.config.live??!1)&&null===this.replayQueue,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,pushData:t=>{n()&&this.renderer.setNativeData?.(e,t)},pushPending:t=>{n()&&this.renderer.setNativeData?.(`${e}-pending`,t)}})}syncBarTransform(e){let t=rT(e);if(t!==this.barTransform){if((this.barTransform=t,0!==this.rawBars.length)&&(this.bars=t?t.full(this.rawBars):this.rawBars,this.renderer.setBars(this.bars,{preserveView:!0}),this.reexecuteIndicators(),!this.switchingMarket))for(let e of this.registry.all())e.native?.started&&e.renderHandle&&!e.hidden&&this.pokeNative(e)}}blankIndicatorVisuals(){for(let e of this.registry.all())!e.hidden&&e.renderHandle&&e.model&&(e.model=function(e){let{anchorTime:t,...i}=e;return{...i,series:e.series.map(e=>"candle"===e.kind||"bar"===e.kind?{...e,bars:[]}:"markers"===e.kind?{...e,markers:[]}:{...e,points:[]}),fills:[],backgrounds:[],priceLines:[],lines:[],boxes:[],labels:[],polylines:[],linefills:[],tables:[],barColors:[],trades:[]}}(e.model),e.renderHandle=this.renderer.mountIndicator(e.model),e.pendingStructural=!0,this.setLoading(e,!0))}reexecuteIndicators(){for(let e of this.registry.all()){if(e.hidden||!e.session)continue;e.session.stop(),e.session=void 0,e.pendingStructural=!0,e.pendingCause="market",this.setLoading(e,!0);let t=this.handles.get(e.id);t&&this.executeIndicator(e.id,t)}}onBar(e){if(this.healing)return void this.healBuffer.push(e);let t=this.rawBars[this.rawBars.length-1];if(t&&this.canHeal()&&e.time>t.time+1.5*this.barIntervalMs()&&Date.now()-this.lastHealAt>5e3){this.healBuffer.push(e),this.healGap(t.time);return}this.applyBar(e)}setBarSeries(e,t){this.rawBars=e,this.bars=this.barTransform?this.barTransform.full(e):e,this.renderer.setBars(this.bars,{preserveView:t?.preserveView,variableDuration:(0,o.jJY)(this.config.market.timeframe??"")}),!t?.clearing&&this.bars.length>0&&this.endLoad()}applyBar(e,t=!0){let i=this.rawBars[this.rawBars.length-1],r=e;if(i&&(0,o.SyC)(i,e))this.rawBars[this.rawBars.length-1]=e,this.barCause="tick",this.barTransform&&(r=this.barTransform.next(e,this.bars[this.bars.length-2]),this.bars[this.bars.length-1]=r);else{if(!(!i||(0,o.vQt)(e,i)))return;this.rawBars.push(e),this.barCause="bar",this.barTransform&&(r=this.barTransform.next(e,this.bars[this.bars.length-1]),this.bars.push(r))}this.renderer.updateBar(r),this.events.emit("bar",e),t&&this.notifySessionsBars("backfill"===this.historyState?"backfill":void 0)}notifySessionsBars(e){if(this.switchingMarket)return;let t=e?"history":this.barCause;for(let i of this.registry.all())i.renderHandle&&!i.hidden&&(i.session?(i.pendingCause=t,i.session.notifyBars(e)):i.native&&this.pokeNative(i));this.activeEngineStyle&&this.typeEngines.get(this.activeEngineStyle)?.onBars?.()}pokeNative(e){let t=e.native;if(!t.descriptor.waitsForHistory)return void t.instance.onBars();if("backfill"!==this.historyState){if(t.heldForHistory){t.heldForHistory=!1;let i=this.handles.get(e.id);i&&this.startNativeIndicator(e.id,i);return}t.started&&t.instance.onBars()}}releaseHeldNatives(){if("backfill"!==this.historyState)for(let e of this.registry.all())e.native?.heldForHistory&&!e.hidden&&this.pokeNative(e)}canHeal(){return!!this.feed.loadRange&&!this.config.market.data?.length&&!(0,o.jJY)(this.config.market.timeframe??"")}barIntervalMs(){return(0,o.cle)(this.config.market.timeframe??"60")}async healGap(e){let t=this.generation;this.healing=!0,this.lastHealAt=Date.now();try{let i=await this.feed.loadRange(this.config.market,{from:e});if(this.generation!==t||this.replayQueue)return;for(let e of i)this.applyBar(e,!1)}catch(e){(0,o.DhR)(e)&&this.marketUnavailable(t,e)}finally{if(this.generation===t&&!this.replayQueue){this.healing=!1;let e=this.healBuffer;for(let t of(this.healBuffer=[],e))this.applyBar(t,!1);this.notifySessionsBars("backfill"===this.historyState?"backfill":void 0)}}}registerEngine(e,t){let i=this.engines.get(e);i&&i!==t&&console.warn(`[vela] re-registering scripting engine for language "${e}"; replacing ${i.constructor.name} with ${t.constructor.name}.`),this.engines.set(e,t)}addIndicator(e,t={}){let i=this.claimIndicatorId(t.id),o=t.title??"Indicator",r=new nC(i,o,this,e,void 0,t.language??this.defaultLanguage);return this.handles.set(i,r),this.registry.add({id:i,title:o,source:e,options:t,inputValues:{...t.inputs??{}},propValues:{...t.props??{}}}),this.startIndicator(i,e,t,r),r}addNativeIndicator(e,t={}){let i=(0,o.fPj)(e);if(!i?.multiInstance){let t=this.registry.all().find(t=>t.native?.type===e);if(t)return this.handles.get(t.id)??new nC(t.id,t.title,this,void 0,e)}let r=this.registry.nextId("native",e=>this.handles.has(e)),l=i?(0,n.b6)(this.i18n,i.title):e,a=new nC(r,l,this,void 0,e);if(this.handles.set(r,a),!i)return console.warn(`[vela] addNativeIndicator("${e}") — no native indicator registered for this type.`),a;let s={...i.defaultInputs(),...t.inputs??{}};return this.registry.add({id:r,title:l,source:e,inputValues:s,propValues:{},native:{type:e,instance:i.create(),descriptor:i}}),a.setSchema(i.inputsSchema()),this.startNativeIndicator(r,a),a}presentNativeIndicators(){return this.registry.all().map(e=>e.native?.type).filter(e=>!!e)}async availableNativeIndicators(){let e=this.qualifiedSymbol(),t=new Set(this.presentNativeIndicators());return Promise.all((0,o.DZ3)().filter(e=>!1!==e.catalog).map(async i=>({type:i.type,title:(0,n.b6)(this.i18n,i.title),supported:await this.isNativeSupported(i,e),present:t.has(i.type),beta:i.beta,...i.multiInstance?{multiInstance:!0}:{}})))}async isNativeSupported(e,t){if(!e.isSupported)return!0;if(!t)return!1;try{return await e.isSupported(t,this.dataControl)}catch{return!1}}applyInputs(e,t){let i=this.registry.get(e);i&&(i.session||i.native)&&(i.inputValues={...i.inputValues,...t},i.renderHandle&&this.renderer.setIndicatorInputs(i.renderHandle,i.inputValues),i.pendingStructural=!0,i.hidden||i.native||this.setLoading(i,!0),i.pendingCause="inputs",i.session?i.session.update(i.inputValues):i.native&&!i.hidden&&i.native.instance.setInputs(i.inputValues),this.events.emit("indicator:inputs",{id:e}))}inputValuesOf(e){return{...this.registry.get(e)?.inputValues}}propValuesOf(e){return{...this.registry.get(e)?.propValues}}applyProps(e,t){let i=this.registry.get(e);i?.session&&(i.propValues={...i.propValues,...t},i.renderHandle&&this.renderer.setIndicatorInputs(i.renderHandle,i.inputValues,i.propValues),i.pendingStructural=!0,i.hidden||this.setLoading(i,!0),i.pendingCause="inputs",i.session.update(i.inputValues,i.propValues),this.events.emit("indicator:inputs",{id:e}))}updateCode(e,t){let i=this.registry.get(e),o=this.handles.get(e);return i&&o?i.native?(console.warn(`[vela] updateCode("${e}") — a native indicator has no script to update.`),Promise.resolve({ok:!1,error:Error(`[vela] updateCode("${e}") — a native indicator has no script to update.`)})):void 0===i.pendingSource&&void 0===i.codeTrial&&t===i.source?Promise.resolve({ok:!0,error:null}):new Promise(r=>{(i.codeWaiters??(i.codeWaiters=[])).push(r),i.pendingSource===t||void 0===i.pendingSource&&i.codeTrial&&i.source===t||(i.pendingSource=t,this.swapSource(e,t,o))}):Promise.resolve({ok:!1,error:Error(`[vela] updateCode("${e}") — the indicator is no longer on the chart.`)})}async swapSource(e,t,i){let o,r=this.registry.get(e)?.engine??this.engineFor(this.registry.get(e)?.options?.language);try{o=await r.prepare(t,e)}catch(r){let o=this.registry.get(e);o?.pendingSource===t&&(o.pendingSource=void 0,this.rejectCode(e,o,i,r));return}let l=this.registry.get(e);if(!l||l.pendingSource!==t)return;l.pendingSource=void 0;let n=l.codeTrial?.previous??{source:l.source,engine:l.engine,prepared:l.prepared,inputValues:l.inputValues,propValues:l.propValues,inputs:[...i.inputs],props:[...i.props]};if(l.inputValues=nB(o.inputs,l.inputValues,l.prepared?.inputs),l.propValues=nB(o.props??[],l.propValues,l.prepared?.props),l.source=t,l.engine=r,l.prepared=o,i.setSource(t),i.setSchema(o.inputs),i.setPropsSchema(o.props??[]),l.session?.stop(),l.session=void 0,l.pendingStructural=!0,l.pendingCause="code",l.hidden){l.codeTrial=void 0,l.renderHandle&&this.renderer.setIndicatorInputs(l.renderHandle,l.inputValues,l.propValues),this.settleCode(l,{ok:!0,error:null});return}l.codeTrial={previous:n},l.renderHandle?(this.renderer.setIndicatorInputs(l.renderHandle,l.inputValues,l.propValues),this.setLoading(l,!0)):this.mountLoadingPlaceholder(e,l),this.executeIndicator(e,i),0===this.bars.length&&l.codeTrial&&(l.codeTrial=void 0,this.settleCode(l,{ok:!0,error:null}))}settleCode(e,t){let i=e.codeWaiters;if(e.codeWaiters=void 0,i)for(let e of i)e(t)}rejectCode(e,t,i,o){let r=t.codeTrial;if(t.codeTrial=void 0,this.fail(e,i,o),r){let o=r.previous;t.session?.stop(),t.session=void 0,t.source=o.source,t.engine=o.engine,t.prepared=o.prepared,t.inputValues=o.inputValues,t.propValues=o.propValues,i.setSource(o.source),i.setSchema(o.inputs),i.setPropsSchema(o.props),t.pendingStructural=!0,t.pendingCause=void 0,t.renderHandle&&this.renderer.setIndicatorInputs(t.renderHandle,t.inputValues,t.propValues),t.hidden||this.executeIndicator(e,i)}let l=o instanceof Error?o:Error(String(o));this.settleCode(t,{ok:!1,error:l})}listIndicators(){return[...this.handles.values()]}getIndicatorContext(e,t){let i=this.registry.get(e)?.session;return i?.getContext?.(t)??Promise.resolve(null)}removeIndicator(e){let t=this.registry.remove(e);t?.native?.type==="volume"&&(this.volumeOptedOut=!0),t&&this.settleCode(t,{ok:!1,error:Error(`[vela] updateCode("${e}") — the indicator was removed.`)}),t?.session?.stop(),t?.native&&this.stopNativeInstance(t.native),this.handles.delete(e),t?.renderHandle&&this.renderer.removeIndicator(t.renderHandle);let i=t?.model?.paneId;i&&"price"!==i&&!this.paneStillUsed(i)&&(this.renderer.removePane(i),this.forgetPane(i),this.events.emit("pane:changed",void 0)),this.events.emit("indicator:removed",{id:e})}setVisible(e,t){let i=this.registry.get(e);if(i&&!t!==i.hidden){if(i.hidden=!t,this.handles.get(e)?.setVisibleState(t),t)if(i.renderHandle&&this.renderer.setIndicatorVisible?.(i.renderHandle,!0),i.pendingStructural=!0,i.native)if(i.native.stale||!i.native.started){i.native.stale=!1;let t=this.handles.get(e);t&&this.startNativeIndicator(e,t)}else i.native.instance.resume();else{this.setLoading(i,!0);let t=this.handles.get(e);t&&this.executeIndicator(e,t)}else i.session?.stop(),i.session=void 0,i.codeTrial&&(i.codeTrial=void 0,this.settleCode(i,{ok:!0,error:null})),i.native?.started&&i.native.instance.suspend(),i.renderHandle?this.renderer.setIndicatorVisible?.(i.renderHandle,!1):i.native&&this.mountHiddenNativeRow(e,i);this.events.emit("indicator:visibility",{id:e,visible:t})}}ready(){return this.readyPromise}inspect(){let e=[...this.registry.all()].filter(e=>!e.loading).sort((e,t)=>!!t.native-!!e.native).map(e=>e.model).filter(e=>null!=e).map(nx),t=t=>e.reduce((e,i)=>e+t(i),0);return{indicators:e,totals:{panes:new Set(e.map(e=>e.paneId??"price")).size,series:t(e=>Object.values(e.series).reduce((e,t)=>e+t,0)),fills:t(e=>e.fills),backgrounds:t(e=>e.backgrounds),priceLines:t(e=>e.priceLines),lines:t(e=>e.lines),boxes:t(e=>e.boxes),labels:t(e=>e.labels),polylines:t(e=>e.polylines),linefills:t(e=>e.linefills),tables:t(e=>e.tables),barColors:t(e=>e.barColors),trades:t(e=>e.trades),forcedOverlay:t(e=>e.forcedOverlay)}}}resize(){this.renderer.resize()}setTheme(e){let t=this.config.theme;[...new Set([...Object.keys(e),...Object.keys(t)])].every(i=>e[i]===t[i])||(this.config.theme=e,this.renderer.setTheme(e),this.events.emit("theme:changed",e))}getVisibleRange(){return this.renderer.getVisibleRange()}setVisibleRange(e){this.renderer.setVisibleRange(e)}panBy(e){if(this.renderer.panBy)return void this.renderer.panBy(e);let t=this.renderer.getVisibleRange();if(!t)return;let i=(t.to-t.from)*e;this.renderer.setVisibleRange({from:t.from+i,to:t.to+i})}setVisibleRangePreset(e){let t=function(e,t){if(0===t.length)return null;let i=t[0].time,o=t[t.length-1].time;return"ALL"===e?{from:i,to:o}:{from:Math.max(i,"YTD"===e?Date.UTC(new Date(o).getUTCFullYear(),0,1):o-nk[e]),to:o}}(e,this.bars);t&&this.renderer.setVisibleRange(t,{rightMargin:!0})}destroy(){for(let e of(this.bumpGeneration(),this.volumeFactsWait=null,this.factsProbe+=1,this.resolveHistoryComplete(),this.clearReplayTimer(),this.replayQueue=null,this.replayForming=null,this.replayCarrying=null,this.dropTickFetches(),this.replayDepth=null,this.replayLoading=null,this.stopLive(),null!=this.viewportTimer&&clearTimeout(this.viewportTimer),this.viewportUnsub?.(),this.paneActionUnsub?.(),this.priceStyleWillChangeUnsub?.(),this.priceStyleWillChangeUnsub=null,this.registry.all()))this.settleCode(e,{ok:!1,error:Error("[vela] updateCode — the chart was destroyed.")}),e.session?.stop(),e.native&&this.stopNativeInstance(e.native);for(let e of this.typeEngines.values())e.stop();this.typeEngines.clear(),this.activeEngineStyle=null,this.unresolvedUnsub?.(),this.unresolvedUnsub=null,this.feed.destroy?.(),this.drawings.destroy(),this.marks.destroy(),this.renderer.destroy(),this.events.clear()}claimIndicatorId(e){if(void 0===e)return this.registry.nextId("ind",e=>this.handles.has(e));if("string"!=typeof e||0===e.length)throw TypeError("[vela] addIndicator: `id` must be a non-empty string");if(this.handles.has(e)||this.registry.get(e))throw Error(`[vela] addIndicator: indicator id "${e}" is already live on this chart`);return e}async startIndicator(e,t,i,o){try{if(await this.readyPromise,!this.registry.get(e))return;await ("function"==typeof requestAnimationFrame?new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e()))):new Promise(e=>setTimeout(e,0)));let r=this.registry.get(e);if(!r)return;let l=this.engineFor(i.language);r.engine=l;let n=await l.prepare(t,e);if(r.source!==t)return;r.prepared=n;let a={};for(let e of n.inputs)a[e.key]=e.defval;r.inputValues={...a,...r.inputValues},o.setSchema(n.inputs);let s={};for(let e of n.props??[])s[e.key]=e.defval;r.propValues={...s,...r.propValues},o.setPropsSchema(n.props??[]),this.mountLoadingPlaceholder(e,r),this.executeIndicator(e,o)}catch(t){this.fail(e,o,t)}}executeIndicator(e,t){let i=this.registry.get(e);if(!i||!i.engine||!i.prepared||i.hidden)return;let o=this.config.live&&!i.prepared.reactsToViewport&&i.engine.capabilities.streaming?"live":"static",r=i.prepared,l=i.engine.execute({prepared:i.prepared,market:this.market(),bars:this.bars,getBars:()=>this.bars,fetchSeries:(e,t,i)=>this.fetchSeries(e,t,i),inputs:i.inputValues,props:i.propValues,visibleRange:this.currentVisibleRange(),mode:o,historyState:this.historyState},{onModel:t=>{let o=!i.announced,r=i.pendingCause??"history";this.applyModel(e,t)&&(i.pendingCause=void 0,i.codeTrial&&(i.codeTrial=void 0,this.settleCode(i,{ok:!0,error:null})),this.emitContextChanged(e),this.emitScriptRun(e,r,o))},onAlert:e=>{if(this.replayQueue||this.replayCarrying)return;let o=i.options?.title??i.prepared?.meta.title??i.title;this.events.emit("alert",{...e,indicator:o}),t.emit("alert",{id:e.id,message:e.message,title:e.title,time:e.time})},onWarning:e=>this.events.emit("warning",e),onError:o=>{i.codeTrial?this.rejectCode(e,i,t,o):this.fail(e,t,o)}});if(i.prepared!==r)return void l.stop();i.session=l,this.emitContextChanged(e)}async startNativeIndicator(e,t){try{await this.readyPromise;let t=this.registry.get(e);if(!t?.native||t.hidden)return;let i=t.native;if(i.started)return;if(i.descriptor.waitsForHistory&&"backfill"===this.historyState){i.heldForHistory=!0,this.mountNativePlaceholder(e,t);return}i.heldForHistory=!1;let o=this.nativeChannel(t),r=!0,l=[];i.revokeContext=()=>{for(let e of(r=!1,l.splice(0)))e()};let n={id:e,symbol:this.config.market.symbol??"TEST",timeframe:this.config.market.timeframe??"60",live:this.config.live&&null===this.replayQueue,session:this.config.market.session,bars:()=>this.bars,data:this.dataControl,fetchSeries:(e,t,i)=>this.fetchSeries(e,t,{...this.config.market.session?{session:this.config.market.session}:{},...i}),subscribeSeries:(e,t,i)=>{if(!r||!this.config.live||null!==this.replayQueue)return()=>{};let o={symbol:rM(e).symbol,timeframe:t,...this.config.market.session?{session:this.config.market.session}:{}},n=this.feed.subscribe(o,e=>{r&&i(e)}),a=()=>{let e=l.indexOf(a);e>=0&&l.splice(e,1),n()};return l.push(a),a},emit:i=>{r&&this.applyModel(e,this.buildNativeModel(t,i,this.bars[0]?.time))},pushData:e=>{r&&this.renderer.setNativeData?.(o,e)},setStatus:e=>{r&&t.renderHandle&&!t.hidden&&this.renderer.setIndicatorStatus?.(t.renderHandle,e)}};i.instance.start(n,t.inputValues),i.started=!0}catch(i){this.fail(e,t,i)}}nativeChannel(e){let{type:t,descriptor:i}=e.native;return i.multiInstance?(0,o.ktk)(t,e.id):t}buildNativeModel(e,t,i){let o=e.native.descriptor,r=e.native.type,l=this.nativeChannel(e),a=t.title??o.title,s=void 0!==t.shortTitle?t.shortTitle:void 0!==t.title?void 0:o.shortTitle,h=void 0!==t.title?(0,n.b6)(this.i18n,t.title):e.title;if(void 0!==t.title){e.title=h;let t=this.handles.get(e.id);t&&(t.title=h)}let d=nA(a),c=nA(s),p=t.paneHint??o.paneHint,u=void 0!==t.paneHint?"price"===t.paneHint:o.overlay;return{id:e.id,title:h,...void 0!==s?{shorttitle:(0,n.b6)(this.i18n,s)}:{},...d?{displayTitle:d}:{},...c?{displayShorttitle:c}:{},overlay:u,paneHint:p,...t.ownScale?{ownScale:!0}:{},...void 0!==t.percentBaseline?{percentBaseline:t.percentBaseline}:{},...t.priceAxisLabel?{priceAxisLabel:!0}:{},native:{type:r,...l!==r?{channel:l}:{}},...null!=i?{anchorTime:i}:{},...!1===o.legend?{legend:!1}:{},...null!=t.paneAxis?{paneAxis:t.paneAxis}:{},series:t.series??[],fills:t.fills??[],backgrounds:t.backgrounds??[],priceLines:t.priceLines??[],...t.lines?{lines:t.lines}:{},...t.boxes?{boxes:t.boxes}:{},...t.labels?{labels:t.labels}:{},...t.polylines?{polylines:t.polylines}:{},...t.linefills?{linefills:t.linefills}:{},...t.tables?{tables:t.tables}:{},inputs:o.inputsSchema(),inputValues:e.inputValues}}mountLoadingPlaceholder(e,t){if(t.renderHandle||!t.prepared)return;let i=t.prepared.meta,o={id:e,title:t.options?.title??i.title,overlay:i.overlay,paneHint:i.overlay?"price":"new",series:[],fills:[],backgrounds:[],priceLines:[],inputs:t.prepared.inputs,inputValues:t.inputValues,...t.prepared.props?{props:t.prepared.props,propValues:t.propValues}:{}},r=this.routePane(e,o,t.options??{});this.placeModel(o,e,r),t.model=o;let l=this.ensurePaneFor(r);if(t.renderHandle=this.renderer.mountIndicator(o),l&&this.events.emit("pane:changed",void 0),t.pendingStructural=!0,t.hidden){this.renderer.setIndicatorVisible?.(t.renderHandle,!1),this.announce(t,this.handles.get(e));return}this.setLoading(t,!0)}mountHiddenNativeRow(e,t){if(t.renderHandle||!t.native)return;let i=this.buildNativeModel(t,{}),o=this.routePane(e,i,t.options??{});this.placeModel(i,e,o),t.model=i;let r=this.ensurePaneFor(o);t.renderHandle=this.renderer.mountIndicator(i),r&&this.events.emit("pane:changed",void 0),t.pendingStructural=!0,this.renderer.setIndicatorVisible?.(t.renderHandle,!1),this.announce(t,this.handles.get(e))}mountNativePlaceholder(e,t){if(t.pendingStructural=!0,!t.renderHandle){let i=this.buildNativeModel(t,{}),o=this.routePane(e,i,t.options??{});this.placeModel(i,e,o),t.model=i;let r=this.ensurePaneFor(o);t.renderHandle=this.renderer.mountIndicator(i),r&&this.events.emit("pane:changed",void 0)}this.setLoading(t,!0)}setLoading(e,t){e.loading=t,e.renderHandle&&!e.hidden&&this.renderer.setIndicatorStatus?.(e.renderHandle,t?"loading":"idle")}ensurePaneFor(e){let t=!this.paneOrder.includes(e);return t&&this.paneOrder.push(e),this.renderer.ensurePane({id:e,kind:"price"===e?"price":"study",order:this.paneOrder.indexOf(e)}),t}paneStillUsed(e){for(let t of this.registry.all())if(t.model?.paneId===e)return!0;return!1}forgetPane(e){let t=this.paneOrder.indexOf(e);t>0&&this.paneOrder.splice(t,1),this.collapsedPanes.delete(e),this.maximizedPaneId===e&&(this.maximizedPaneId=null)}setTranslator(e){this.i18n=e,this.drawings.relocalize()}relocalize(){for(let e of(this.drawings.relocalize(),this.registry.all())){let t=e.native?.descriptor;if(!t)continue;let i=e.model?e.model.displayTitle:t.title;if(void 0!==i){e.title=(0,n.b6)(this.i18n,i);let t=this.handles.get(e.id);t&&(t.title=e.title),e.model&&(e.model.title=e.title)}if(e.model){let t=e.model.displayShorttitle;void 0!==t&&(e.model.shorttitle=(0,n.b6)(this.i18n,t))}}}paneManagementSupported(){return!0===this.renderer.capabilities.paneManagement&&"function"==typeof this.renderer.setIndicatorPane}listPanes(){let e=new Map;for(let t of this.registry.all()){let i=t.model;if(!i||!1===i.legend)continue;let o=i.paneId??"price";e.has(o)||e.set(o,[]),e.get(o).push({id:t.id,title:i.title||t.title,...i.shorttitle?{shorttitle:i.shorttitle}:{},ownScale:!0===i.ownScale})}let t=[];for(let i of this.paneOrder){if("price"!==i&&!e.has(i))continue;let o=this.renderer.paneHeightWeight?.(i)??null;t.push({id:i,kind:"price"===i?"price":"study",order:t.length,collapsed:this.collapsedPanes.has(i),maximized:this.maximizedPaneId===i,...null!==o?{heightWeight:o}:{},indicators:e.get(i)??[]})}return t}movePane(e,t){if("price"===e)return;let i=this.existingPaneIds(),o=i.indexOf(e);if(o<0)return;let r="up"===t?o-1:o+1;r<=0||r>=i.length||([i[o],i[r]]=[i[r],i[o]],this.reorderPanes(i),this.events.emit("pane:moved",{paneId:e,dir:t}))}removePaneAndIndicators(e){if("price"!==e)for(let t of[...this.registry.all()])t.model?.paneId===e&&this.removeIndicator(t.id)}collapsePane(e,t){t?this.collapsedPanes.add(e):this.collapsedPanes.delete(e),this.renderer.setPaneCollapsed?.(e,t),this.events.emit("pane:changed",void 0)}maximizePane(e){this.maximizedPaneId=e,this.renderer.setPaneMaximized?.(e),this.events.emit("pane:changed",void 0)}setPaneHeightWeight(e,t){return this.renderer.setPaneHeightWeight?"number"!=typeof t||!Number.isFinite(t)||t<=0?void console.warn(`[vela] chart.panes.setHeightWeight: weight must be a positive number (got ${String(t)}).`):this.existingPaneIds().includes(e)?void(this.renderer.setPaneHeightWeight(e,t),this.events.emit("pane:changed",void 0)):void console.warn(`[vela] chart.panes.setHeightWeight: no pane "${e}".`):void console.warn("[vela] the active renderer does not support pane sizing — chart.panes.setHeightWeight ignored.")}moveIndicator(e,t){if(!this.paneManagementSupported()||!this.renderer.setIndicatorPane)return void console.warn("[vela] the active renderer does not support moving indicators between panes.");let i=this.registry.get(e);if(!i?.renderHandle||!i.model)return;let o=i.model,r=o.paneId??"price",l=this.resolveMoveTarget(e,o,t);if(!l)return;let{paneId:n,ownScale:a,insert:s}=l;(n!==r||!0===o.ownScale!==a)&&(s?this.insertPaneOrder(n,s):this.paneOrder.includes(n)||this.paneOrder.push(n),o.ownScale=a,i.paneLocked=!0,this.placeModel(o,e,n),this.ensurePaneFor(n),this.renderer.setIndicatorPane(i.renderHandle,n,{ownScale:a}),"price"===r||r===n||this.paneStillUsed(r)||(this.renderer.removePane(r),this.forgetPane(r)),this.reorderPanes(this.existingPaneIds()),this.events.emit("indicator:moved",{id:e,paneId:n}),this.events.emit("pane:changed",void 0))}resolveMoveTarget(e,t,i){if("price"===i||"object"==typeof i&&"pane"in i&&"price"===i.pane)return{paneId:"price",ownScale:!t.overlay};if("pane"in i)return this.existingPaneIds().includes(i.pane)?{paneId:i.pane,ownScale:!0}:null;let o=!0===i.newPane?{}:i.newPane;return{paneId:this.freshPaneId(e,t.paneId??"price"),ownScale:!1,insert:o}}freshPaneId(e,t){let i=new Set(this.existingPaneIds()),o=`pane-${e}`;for(let r=2;o===t||i.has(o);r+=1)o=`pane-${e}-${r}`;return o}insertPaneOrder(e,t){let i=this.paneOrder.indexOf(e);i>0&&this.paneOrder.splice(i,1);let o=this.paneOrder.length;t.before&&this.paneOrder.includes(t.before)?o=this.paneOrder.indexOf(t.before):t.after&&this.paneOrder.includes(t.after)&&(o=this.paneOrder.indexOf(t.after)+1),o<1&&(o=1),this.paneOrder.splice(o,0,e)}existingPaneIds(){return this.paneOrder.filter(e=>"price"===e||this.paneStillUsed(e))}reorderPanes(e){this.paneOrder.length=0,this.paneOrder.push(...e),this.renderer.orderPanes?.(e),this.events.emit("pane:changed",void 0)}handlePaneAction(e){switch(e.type){case"remove":this.removePaneAndIndicators(e.paneId);break;case"move":{let t=this.existingPaneIds(),i=t.indexOf(e.paneId),o="up"===e.dir?i-1:i+1;i>0&&o>0&&o<t.length&&([t[i],t[o]]=[t[o],t[i]],this.paneOrder.length=0,this.paneOrder.push(...t),this.events.emit("pane:changed",void 0),this.events.emit("pane:moved",{paneId:e.paneId,dir:e.dir}));break}case"collapse":e.collapsed?this.collapsedPanes.add(e.paneId):this.collapsedPanes.delete(e.paneId),this.events.emit("pane:changed",void 0);break;case"maximize":this.maximizedPaneId=e.maximized?e.paneId:null,this.events.emit("pane:changed",void 0);break;case"resize":this.events.emit("pane:changed",void 0)}}announce(e,t){e.announced||(e.announced=!0,this.events.emit("indicator:added",{id:e.id}),this.emitContextChanged(e.id),t?.emit("ready",void 0))}applyModel(t,i){let r=this.registry.get(t);if(!r||r.hidden)return!0;if(this.switchingMarket||r.loading&&0===this.bars.length&&!e.modelHasOutput(i))return!1;let l=this.handles.get(t);if(!r.renderHandle){let e=this.routePane(t,i,r.options??{});this.placeModel(i,t,e),r.model=i;let o=this.ensurePaneFor(e);return r.renderHandle=this.renderer.mountIndicator(i),r.pendingStructural=!1,o&&this.events.emit("pane:changed",void 0),this.announce(r,l),!0}let n=r.model?.paneId??"price",a=r.model,s=a?.ownScale===!0,h=!1;if(!r.paneLocked&&(r.loading||r.native)){let e=this.routePane(t,i,r.options??{});e!==n&&("price"===n||this.registry.all().some(e=>e.id!==t&&e.model?.paneId===n)||(this.renderer.removePane(n),this.forgetPane(n)),this.ensurePaneFor(e),r.pendingStructural=!0,n=e,h=!0)}return this.placeModel(i,t,n),r.paneLocked&&(i.ownScale=s),a&&(i.title!==a.title||i.shorttitle!==a.shorttitle||!0===i.ownScale!==s||i.percentBaseline!==a.percentBaseline||i.priceAxisLabel!==a.priceAxisLabel)&&(r.pendingStructural=!0),r.model=i,r.pendingStructural?(r.renderHandle=this.renderer.mountIndicator(i),this.renderer.setIndicatorInputs(r.renderHandle,r.inputValues,r.propValues),r.pendingStructural=!1):this.renderer.updateIndicator(r.renderHandle,function(e){let t=[],i=1/0,r=0;for(let l of e.series)if("candle"===l.kind||"bar"===l.kind)for(let e of(t.push({seriesId:l.id,kind:"bars",bars:l.bars,barColors:l.barColors??[]}),l.bars))e&&(e.time<i&&(i=e.time),e.time>r&&(r=e.time));else if((0,o.xcs)(l))for(let e of(t.push({seriesId:l.id,kind:"points",points:l.points}),l.points))e&&(e.time<i&&(i=e.time),e.time>r&&(r=e.time));return{kind:"value",indicatorId:e.id,dirty:{from:Number.isFinite(i)?i:0,to:r},anchorTime:e.anchorTime??null,series:t,lines:e.lines??[],boxes:e.boxes??[],labels:e.labels??[],polylines:e.polylines??[],linefills:e.linefills??[],tables:e.tables??[],trades:e.trades??[],fills:e.fills,backgrounds:e.backgrounds,priceLines:e.priceLines,barColors:e.barColors??[]}}(i)),h&&this.events.emit("pane:changed",void 0),r.loading&&this.setLoading(r,!1),this.announce(r,l),!0}static modelHasOutput(e){return e.series.length>0||e.fills.length>0||e.backgrounds.length>0||e.priceLines.length>0||(e.lines?.length??0)>0||(e.boxes?.length??0)>0||(e.labels?.length??0)>0||(e.polylines?.length??0)>0||(e.linefills?.length??0)>0||(e.tables?.length??0)>0||(e.barColors?.length??0)>0||(e.trades?.length??0)>0}routePane(e,t,i){return"new"===i.pane?`pane-${e}`:"price"===i.pane||(i.overlay??t.overlay)?"price":`pane-${e}`}static plotsAtLastBar(e,t){let i={};for(let r of e.series){if(!(0,o.xcs)(r))continue;let e=r.points.length-1;if(void 0!==t)for(;e>=0&&r.points[e].time>t;)e-=1;i[r.title]=r.points[e]?.value??null}return i}placeModel(e,t,i){e.id=t,e.paneId=i;let o=e=>!0===e.overlay?"price":i;for(let t of e.series)t.paneId=o(t);for(let t of e.fills)t.paneId=o(t);for(let t of e.backgrounds)t.paneId=o(t);for(let t of e.priceLines)t.paneId=i;if(e.lines)for(let t of e.lines)t.paneId=o(t);if(e.boxes)for(let t of e.boxes)t.paneId=o(t);if(e.labels)for(let t of e.labels)t.paneId=o(t);if(e.polylines)for(let t of e.polylines)t.paneId=o(t);if(e.linefills)for(let t of e.linefills)t.paneId=o(t);if(e.tables)for(let t of e.tables)t.paneId=o(t)}emitContextChanged(e){if(!this.registry.get(e)?.session?.getContext)return;let t=Date.now();t-(this.contextEmitAt.get(e)??0)<1e3||(this.contextEmitAt.set(e,t),this.events.emit("context:changed",{id:e}))}emitScriptRun(e,t,i){let o=this.registry.get(e);if(!o||o.native||!this.events.hasListeners("script:run"))return;let r=Date.now();"tick"===t&&r-(this.runEmitAt.get(e)??0)<1e3||(this.runEmitAt.set(e,r),Promise.resolve().then(()=>this.buildScriptRun(o,t,i)).then(t=>{t&&this.registry.get(e)&&this.events.emit("script:run",t)}))}async buildScriptRun(t,i,o){let r=t.model;if(!r)return null;let l=await this.pullContext(t,["variables","strategy","warnings"]),n=this.bars[this.bars.length-1];return{id:t.id,title:r.title,kind:l?.strategy||(r.trades?.length??0)>0?"strategy":"indicator",cause:i,first:o,bar:Math.max(0,this.bars.length-1),time:n?.time??0,forming:this.config.live&&this.bars.length>0,complete:"backfill"!==this.historyState,plots:e.plotsAtLastBar(r,n?.time),vars:l?.variables??{},...l?.strategy?{strategy:l.strategy}:{},warnings:l?.warnings??[],trades:async()=>(await this.pullContext(t,["trades"]))?.trades??[],series:async e=>((await this.pullContext(t,["plots"]))?.plots?.[e]??[]).map(e=>({time:e.time,value:"number"==typeof e.value?e.value:null}))}}async pullContext(e,t){try{return await e.session?.getContext?.(t)??null}catch{return null}}fail(e,t,i){let o=this.registry.get(e);o?.loading&&this.setLoading(o,!1);let r=i instanceof Error?i:Error(String(i));console.error(`[vela] indicator "${e}" failed:`,r.message),this.events.emit("indicator:error",{id:e,error:r}),t?.emit("error",{error:r})}};function nE(){return"undefined"!=typeof performance?performance.now():Date.now()}function nB(e,t,i=[]){let o={},r=new Set;for(let t of e)o[t.key]=t.defval,r.add(t.key),r.add(t.title);let l=new Map;for(let e of i)l.set(e.key,e.defval),l.has(e.title)||l.set(e.title,e.defval);for(let[e,i]of Object.entries(t))if(r.has(e)){var n,a;l.has(e)&&(n=l.get(e),n===(a=i)||"object"==typeof n&&null!==n&&"object"==typeof a&&null!==a&&JSON.stringify(n)===JSON.stringify(a))||(o[e]=i)}return o}function nF(e){if(!e)return null;let t={},{mintick:i}=e;return"number"==typeof i&&Number.isFinite(i)&&i>0&&(t.mintick=i),"boolean"==typeof e.ohlc&&(t.ohlc=e.ohlc),"boolean"==typeof e.volume&&(t.volume=e.volume),t}var nO=class{constructor(e){this.controller=e}get supported(){return this.controller.paneManagementSupported()}list(){return this.controller.listPanes()}move(e,t){return this.guard()&&this.controller.movePane(e,t),this}remove(e){return this.guard()&&this.controller.removePaneAndIndicators(e),this}collapse(e,t=!0){return this.guard()&&this.controller.collapsePane(e,t),this}maximize(e){return this.guard()&&this.controller.maximizePane(e),this}setHeightWeight(e,t){return this.guard()&&this.controller.setPaneHeightWeight(e,t),this}moveIndicator(e,t){return this.guard()&&this.controller.moveIndicator(e,t),this}guard(){return!!this.controller.paneManagementSupported()||(console.warn("[vela] the active renderer does not support pane management — chart.panes mutation ignored."),!1)}};function nR(e,t){let i=(e.open+e.high+e.low+e.close)/4,o=t?(t.open+t.close)/2:(e.open+e.close)/2;return{time:e.time,open:o,high:Math.max(e.high,o,i),low:Math.min(e.low,o,i),close:i,...null!=e.volume?{volume:e.volume}:{}}}var nN={full:function(e){let t,i=Array(e.length);for(let o=0;o<e.length;o+=1)t=nR(e[o],t),i[o]=t;return i},next:nR},nz=r.cr,nV=r.TV;function nD(e,t){return"string"==typeof e&&""!==e?e:t}function n$(e){var t;return{upColor:nD(e.upColor,nz),downColor:nD(e.downColor,nV),heightFrac:Math.min(.5,Math.max(.05,("number"==typeof(t=e.heightPct)&&Number.isFinite(t)?t:20)/100))}}var nH=class{constructor(){this.ctx=null,this.inputs={}}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(n$(t))}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(n$(e))}suspend(){}resume(){this.ctx?.pushData(n$(this.inputs))}stop(){}},nW={type:"volume",title:(0,n.ab)("indicator.volume.title","Volume"),paneHint:"price",overlay:!0,inputsSchema:()=>[nP({key:"upColor",title:(0,n.ab)("indicator.volume.upColor","Up color"),type:"color",defval:nz}),nP({key:"downColor",title:(0,n.ab)("indicator.volume.downColor","Down color"),type:"color",defval:nV}),nP({key:"heightPct",title:(0,n.ab)("indicator.volume.heightPct","Height %"),type:"int",defval:20,min:5,max:50,step:1,tooltip:(0,n.ab)("indicator.volume.heightPct.tooltip","Panel height the tallest visible bar occupies.")})],defaultInputs:()=>({upColor:nz,downColor:nV,heightPct:20}),create:()=>new nH},nq=r.bg,nU=r.TV;function nj(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function nG(e,t){return"string"==typeof e&&""!==e?e:t}function nK(e){return{rows:Math.round(Math.min(400,Math.max(2,nj(e.rows,24)))),widthFrac:Math.min(.9,Math.max(.05,nj(e.widthPct,30)/100)),upColor:nG(e.upColor,nq),downColor:nG(e.downColor,nU),showPoc:!1!==e.showPoc,valueAreaFrac:Math.min(1,Math.max(0,nj(e.valueAreaPct,70)/100))}}var nY=class{constructor(){this.ctx=null,this.inputs={}}start(e,t){this.ctx=e,this.inputs=t,e.emit({}),e.pushData(nK(t))}onBars(){}onViewport(){}setInputs(e){this.inputs=e,this.ctx?.pushData(nK(e))}suspend(){}resume(){this.ctx?.pushData(nK(this.inputs))}stop(){}},nZ={type:"vpvr",title:(0,n.ab)("indicator.vpvr.title","Visible Range Volume Profile"),shortTitle:(0,n.ab)("indicator.vpvr.shortTitle","VRVP"),paneHint:"price",overlay:!0,inputsSchema:()=>[nP({key:"rows",title:(0,n.ab)("indicator.vpvr.rows","Rows"),type:"int",defval:24,min:2,max:400,step:1}),nP({key:"widthPct",title:(0,n.ab)("indicator.vpvr.widthPct","Width %"),type:"int",defval:30,min:5,max:90,step:1,tooltip:(0,n.ab)("indicator.vpvr.widthPct.tooltip","Panel width the largest row occupies.")}),nP({key:"upColor",title:(0,n.ab)("indicator.vpvr.upColor","Up color"),type:"color",defval:nq}),nP({key:"downColor",title:(0,n.ab)("indicator.vpvr.downColor","Down color"),type:"color",defval:nU}),nP({key:"showPoc",title:(0,n.ab)("indicator.vpvr.showPoc","Point of control"),type:"bool",defval:!0}),nP({key:"valueAreaPct",title:(0,n.ab)("indicator.vpvr.valueAreaPct","Value area %"),type:"int",defval:70,min:0,max:100,step:1})],defaultInputs:()=>({rows:24,widthPct:30,upColor:nq,downColor:nU,showPoc:!0,valueAreaPct:70}),create:()=>new nY},nX={groups:{Settings:(0,n.ab)("indicator.group.settings","Settings"),Style:(0,n.ab)("indicator.group.style","Style"),"Trend Regime":(0,n.ab)("indicator.group.trendRegime","Trend Regime"),Thresholds:(0,n.ab)("indicator.group.thresholds","Thresholds"),"Squeeze & Bulge":(0,n.ab)("indicator.group.squeezeBulge","Squeeze & Bulge"),"Alligator Lines":(0,n.ab)("indicator.group.alligatorLines","Alligator Lines"),"Trigger Levels":(0,n.ab)("indicator.group.triggerLevels","Trigger Levels"),Oscillator:(0,n.ab)("indicator.group.oscillator","Oscillator")},options:{Close:(0,n.ab)("indicator.option.close","Close"),Open:(0,n.ab)("indicator.option.open","Open"),High:(0,n.ab)("indicator.option.high","High"),Low:(0,n.ab)("indicator.option.low","Low"),"Momentum (|CMO|)":(0,n.ab)("indicator.option.momentumCmo","Momentum (|CMO|)"),"Volatility (StDev Ratio)":(0,n.ab)("indicator.option.volatilityStdevRatio","Volatility (StDev Ratio)"),Indicator:(0,n.ab)("indicator.option.indicator","Indicator"),Oscillator:(0,n.ab)("indicator.option.oscillator","Oscillator"),Momentum:(0,n.ab)("indicator.option.momentum","Momentum"),Session:(0,n.ab)("indicator.option.session","Session"),Week:(0,n.ab)("indicator.option.week","Week"),Month:(0,n.ab)("indicator.option.month","Month"),Quarter:(0,n.ab)("indicator.option.quarter","Quarter"),Year:(0,n.ab)("indicator.option.year","Year"),"Standard Deviation":(0,n.ab)("indicator.option.standardDeviation","Standard Deviation"),Percentage:(0,n.ab)("indicator.option.percentage","Percentage"),Traditional:(0,n.ab)("indicator.option.traditional","Traditional"),Fibonacci:(0,n.ab)("indicator.option.fibonacci","Fibonacci"),Camarilla:(0,n.ab)("indicator.option.camarilla","Camarilla"),Woodie:(0,n.ab)("indicator.option.woodie","Woodie"),"ROC %":(0,n.ab)("indicator.option.rocPercent","ROC %"),McGinley:(0,n.ab)("indicator.option.mcGinley","McGinley"),Hamming:(0,n.ab)("indicator.option.hamming","Hamming"),"SMMA (Wilder)":(0,n.ab)("indicator.option.smmaWilder","SMMA (Wilder)"),"Wilder (RMA)":(0,n.ab)("indicator.option.wilderRma","Wilder (RMA)"),Auto:(0,n.ab)("indicator.option.auto","Auto"),Daily:(0,n.ab)("indicator.option.daily","Daily"),Weekly:(0,n.ab)("indicator.option.weekly","Weekly"),Monthly:(0,n.ab)("indicator.option.monthly","Monthly"),Yearly:(0,n.ab)("indicator.option.yearly","Yearly"),"Position vs Average":(0,n.ab)("indicator.option.positionVsAverage","Position vs Average"),"Single Color":(0,n.ab)("indicator.option.singleColor","Single Color"),"Normalized Oscillator (II%)":(0,n.ab)("indicator.option.normalizedOscillator","Normalized Oscillator (II%)"),"Cumulative Line":(0,n.ab)("indicator.option.cumulativeLine","Cumulative Line")}};function n_(e,t,i){let o=e[t];return"number"==typeof o&&Number.isFinite(o)?o:i}function nQ(e,t,i){let o=e[t];return"string"==typeof o&&""!==o?o:i}function nJ(e,t,i){let o=e[t];return"boolean"==typeof o?o:i}function n0(e,t){if(e.length>=2){let t=[];for(let i=1;i<e.length;i++){let o=e[i].time-e[i-1].time;o>0&&t.push(o)}if(t.length>0)return t.sort((e,t)=>e-t),t[Math.floor(t.length/2)]}return(0,o.cle)(t)||6e4}function n1(e,t){let i=Math.trunc(t);if(0===i)return[...e];if(i>0)return[...Array(i).fill(null),...e];let o=-i,r=Array(e.length).fill(null);for(let t=0;t+o<e.length;t++)r[t]=e[t+o];return r}var n2=class{constructor(e){this.spec=e,this.ctx=null,this.inputs={},this.extBars=new Map,this.extFetchedFrom=new Map,this.extSubs=new Map,this.fetchSeq=0,this.suspended=!1}start(e,t){this.ctx=e,this.inputs=t,this.suspended=!1,this.syncAndCompute()}onBars(){this.ctx&&!this.suspended&&this.syncAndCompute()}onViewport(){}setInputs(e){this.inputs=e,this.ctx&&!this.suspended&&this.syncAndCompute()}suspend(){this.suspended=!0,this.fetchSeq++,this.clearSubs()}resume(){this.suspended=!1,this.ctx&&this.syncAndCompute()}stop(){this.suspended=!0,this.fetchSeq++,this.clearSubs(),this.extBars.clear(),this.extFetchedFrom.clear(),this.ctx=null}clearSubs(){for(let e of this.extSubs.values())e();this.extSubs.clear()}wantedExternalSymbols(){let e=this.spec.externalSymbols?.(this.inputs);if(!e||0===e.length)return[];let t=[],i=new Set;for(let o of e){let e=o.trim();!e||i.has(e)||(i.add(e),t.push(e))}return t}isOwnSymbol(e){if(!this.ctx)return!1;let t=e=>(this.ctx.data.canonicalSymbol?.(e)??e).trim().toUpperCase();return t(e)===t(this.ctx.symbol)}buildExternalMap(e,t){if(0===t.length)return;let i=new Map;for(let o of t)i.set(o,this.isOwnSymbol(o)?e:this.extBars.get(o)??[]);return i}ensureSubscriptions(e){let t=this.ctx;if(t&&t.live&&t.subscribeSeries&&!this.suspended)for(let i of e){if(this.extSubs.has(i))continue;let e=t.subscribeSeries(i,t.timeframe,e=>{if(!this.ctx||this.suspended)return;let t=this.extBars.get(i);t||(t=[],this.extBars.set(i,t));var o=t;let r=o[o.length-1];r&&r.time===e.time?o[o.length-1]=e:(!r||e.time>r.time)&&o.push(e),this.emitCompute(this.ctx.bars(),this.wantedExternalSymbols())});this.extSubs.set(i,e)}}syncAndCompute(){let e=this.ctx;if(!e)return;let t=e.bars(),i=this.wantedExternalSymbols(),o=new Set(i);for(let e of[...this.extSubs.keys()])(!o.has(e)||this.isOwnSymbol(e))&&(this.extSubs.get(e)?.(),this.extSubs.delete(e));for(let e of[...this.extBars.keys()])(!o.has(e)||this.isOwnSymbol(e))&&(this.extBars.delete(e),this.extFetchedFrom.delete(e));let r=i.filter(e=>!this.isOwnSymbol(e));if(0===r.length){this.fetchSeq++,this.emitCompute(t,i),e.setStatus("idle");return}if(this.emitCompute(t,i),!e.fetchSeries||0===t.length)return void e.setStatus("idle");let l=t[0].time,n=r.filter(e=>!this.extBars.has(e)||l<(this.extFetchedFrom.get(e)??1/0));if(0===n.length){this.ensureSubscriptions(r),e.setStatus("idle");return}let a=++this.fetchSeq;e.setStatus("loading");let s=n0(t,e.timeframe),h={from:l,to:t[t.length-1].time+s,limit:t.length+64};Promise.all(n.map(async t=>{try{let i=await e.fetchSeries(t,e.timeframe,h);return[t,i]}catch{return[t,[]]}})).then(e=>{if(a===this.fetchSeq&&this.ctx&&!this.suspended){for(let[t,i]of e)this.extBars.set(t,[...i]),this.extFetchedFrom.set(t,l);this.ensureSubscriptions(r),this.emitCompute(this.ctx.bars(),this.wantedExternalSymbols()),this.ctx.setStatus("idle")}})}emitCompute(e,t){if(!this.ctx)return;let i=this.buildExternalMap(e,t),r=this.spec.compute(e,this.inputs,i),l=n0(e,this.ctx.timeframe),a=this.spec.type,s=[],h=new Map,d=new Map;if(r.plots.forEach((t,i)=>{let r=t.kind??"line",c=(0,n.rI)(t.title),p=(0,o.uZt)({instanceId:a,kind:r,title:c,ordinal:i}),u=Math.trunc(t.offset??0);h.set(t.key,p),d.set(t.key,u);let g=t.displayTitle??nA(t.title);s.push({id:p,title:c,...g?{displayTitle:g}:{},paneId:"",kind:r,points:function(e,t,i,o=0,r=6e4){let l=Math.trunc(o);if(0===l){let o=Array(e.length);for(let r=0;r<e.length;r++){let l=t[r],n={time:e[r].time,value:null!=l&&Number.isFinite(l)?l:null},a=i?.[r];null!=a&&(n.color=a),o[r]=n}return o}if(0===e.length)return[];if(l<0){let o=-l,r=Array(e.length);for(let l=0;l<e.length;l++){let n=l+o,a=n<t.length?t[n]:void 0,s={time:e[l].time,value:null!=a&&Number.isFinite(a)?a:null},h=n<t.length?i?.[n]:void 0;null!=h&&(s.color=h),r[l]=s}return r}let n=e.length+l,a=e[e.length-1].time,s=Array(n);for(let o=0;o<n;o++){let n=o<e.length?e[o].time:a+(o-(e.length-1))*r,h=o-l,d=h>=0&&h<t.length?t[h]:void 0,c={time:n,value:null!=d&&Number.isFinite(d)?d:null},p=h>=0&&h<t.length?i?.[h]:void 0;null!=p&&(c.color=p),s[o]=c}return s}(e,t.values,t.colors,u,l),style:{color:t.color,width:t.width??1,lineStyle:t.lineStyle??"solid",...null!=t.base?{base:t.base}:{}},...t.overlay?{overlay:!0}:{},...t.display?{display:t.display}:{}})}),r.markers&&r.markers.length>0){let e=this.spec.shortTitle??this.spec.title,t=nA(e);s.push({id:(0,o.uZt)({instanceId:a,kind:"markers",title:"markers",ordinal:0}),title:(0,n.rI)(e),...t?{displayTitle:t}:{},paneId:"",kind:"markers",markers:r.markers})}let c=(r.bands??[]).flatMap((e,t)=>{let i=h.get(e.from),r=h.get(e.to);if(!i||!r)return[];let l=d.get(e.from)??0,n=l===(d.get(e.to)??0)?l:0;return[{id:(0,o.uZt)({instanceId:a,kind:"fill",title:e.key,ordinal:t}),paneId:"",fromSeriesId:i,toSeriesId:r,color:e.color,...e.colors?{colors:n1(e.colors,n)}:{},...e.gradient?{gradient:n1(e.gradient,n)}:{}}]}),p=(r.levels??[]).map((e,t)=>({id:(0,o.uZt)({instanceId:a,kind:"hline",title:e.key,ordinal:t}),paneId:"",price:e.price,...null!=e.color?{color:e.color}:{},lineStyle:e.lineStyle??"dashed",width:1,...null!=e.title?{title:(0,n.rI)(e.title)}:{},...nA(e.title)?{displayTitle:e.title}:{}})),u=(r.polylines??[]).map((e,t)=>{let{key:i,...r}=e;return{id:(0,o.uZt)({instanceId:a,kind:"polyline",title:i,ordinal:t}),paneId:"",...r}});this.ctx.emit({series:s,fills:c,priceLines:p,polylines:u})}},n5=["Close","Open","High","Low","HL2","HLC3","OHLC4","HLCC4"];function n3(e,t){let i=Array(e.length);for(let o=0;o<e.length;o++){let r=e[o];switch(t){case"Open":i[o]=r.open;break;case"High":i[o]=r.high;break;case"Low":i[o]=r.low;break;case"HL2":i[o]=(r.high+r.low)/2;break;case"HLC3":i[o]=(r.high+r.low+r.close)/3;break;case"OHLC4":i[o]=(r.open+r.high+r.low+r.close)/4;break;case"HLCC4":i[o]=(r.high+r.low+r.close+r.close)/4;break;default:i[o]=r.close}}return i}function n4(e){return e.map(e=>null!=e.volume&&Number.isFinite(e.volume)?e.volume:NaN)}function n6(e){return e.map(e=>e.high)}function n8(e){return e.map(e=>e.low)}function n7(e){return e.map(e=>e.close)}function n9(e,t,i){let o=Array(e.length);for(let r=0;r<e.length;r++){let l=e[r],n=t[r];o[r]=Number.isFinite(l)&&Number.isFinite(n)?i(l,n):NaN}return o}function ae(e,t){let i=Array(e.length);for(let o=0;o<e.length;o++){let r=e[o];i[o]=Number.isFinite(r)?t(r):NaN}return i}function at(e,t){return n9(e,t,(e,t)=>e-t)}function ai(e,t,i){let o=Array(e.length).fill(NaN);if(t<=0)return o;let r=0;for(let l=0;l<e.length;l++)(r=Number.isFinite(e[l])?r+1:0)>=t&&(o[l]=i(e,l-t+1,l));return o}function ao(e,t){return ai(e,t,(e,t,i)=>{let o=0;for(let r=t;r<=i;r++)o+=e[r];return o})}function ar(e,t){return ai(e,t,(e,i,o)=>{let r=0;for(let t=i;t<=o;t++)r+=e[t];return r/t})}function al(e,t){let i=t*(t+1)/2;return ai(e,t,(e,t,o)=>{let r=0;for(let i=t;i<=o;i++)r+=e[i]*(i-t+1);return r/i})}function an(e,t){return ai(e,t,(e,i,o)=>{let r=0;for(let t=i;t<=o;t++)r+=e[t];let l=r/t,n=0;for(let t=i;t<=o;t++){let i=e[t]-l;n+=i*i}return Math.sqrt(n/t)})}function aa(e,t){return ai(e,t,(e,t,i)=>{let o=-1/0;for(let r=t;r<=i;r++)e[r]>o&&(o=e[r]);return o})}function as(e,t){return ai(e,t,(e,t,i)=>{let o=1/0;for(let r=t;r<=i;r++)e[r]<o&&(o=e[r]);return o})}function ah(e,t,i){let o=Array(e.length).fill(NaN),r=0,l=NaN;for(let n=0;n<e.length;n++){let a=e[n];if(!Number.isFinite(a)){r=0,l=NaN;continue}if(r+=1,Number.isFinite(l))l=i*a+(1-i)*l,o[n]=l;else if(r>=t){let i=0;for(let o=n-t+1;o<=n;o++)i+=e[o];l=i/t,o[n]=l}}return o}function ad(e,t){return ah(e,t,2/(t+1))}function ac(e,t){return ah(e,t,1/t)}function ap(e,t=1){let i=Array(e.length).fill(NaN);for(let o=t;o<e.length;o++){let r=e[o],l=e[o-t];Number.isFinite(r)&&Number.isFinite(l)&&(i[o]=r-l)}return i}function au(e,t){let i=Array(e.length).fill(NaN);for(let o=t;o<e.length;o++){let r=e[o],l=e[o-t];Number.isFinite(r)&&Number.isFinite(l)&&0!==l&&(i[o]=100*(r-l)/l)}return i}function ag(e,t){let i=Array(e.length).fill(NaN);for(let o=0;o<e.length;o++){let r=o-t;r>=0&&r<e.length&&(i[o]=e[r])}return i}function am(e){let t=Array(e.length).fill(NaN);for(let i=0;i<e.length;i++){let o=e[i];if(0===i){t[i]=o.high-o.low;continue}let r=e[i-1].close;t[i]=Math.max(o.high-o.low,Math.abs(o.high-r),Math.abs(o.low-r))}return t}function ab(e,t){return ac(am(e),t)}function af(e,t){let i=ap(e),o=ae(i,e=>Math.max(e,0)),r=ae(i,e=>Math.max(-e,0));return n9(ac(o,t),ac(r,t),(e,t)=>0===t?100:100-100/(1+e/t))}function av(e,t,i,o){let r=aa(t,o),l=as(i,o),n=Array(e.length).fill(NaN);for(let t=0;t<e.length;t++){let i=e[t],o=r[t],a=l[t];Number.isFinite(i)&&Number.isFinite(o)&&Number.isFinite(a)&&(n[t]=o===a?50:100*(i-a)/(o-a))}return n}function ay(e,t,i=0){let o=(t-1)*t/2,r=(t-1)*t*(2*t-1)/6,l=t*r-o*o;return ai(e,t,(e,r,n)=>{let a=0,s=0;for(let t=r;t<=n;t++){let i=t-r;a+=e[t],s+=i*e[t]}let h=0===l?0:(t*s-o*a)/l;return(a-h*o)/t+h*(t-1-i)})}function aw(e,t){if(t<3)return aT(e.length,NaN);let i=(t-1)*t/2,o=(t-1)*t*(2*t-1)/6,r=t*o-i*i;return ai(e,t,(e,o,l)=>{let n=0,a=0;for(let t=o;t<=l;t++)n+=e[t],a+=(t-o)*e[t];let s=(t*a-i*n)/r,h=(n-s*i)/t,d=0;for(let t=o;t<=l;t++){let i=e[t]-(h+s*(t-o));d+=i*i}return Math.sqrt(d/(t-2))})}function aC(e,t,i){let o=Array(e.length).fill(NaN);for(let r=i-1;r<e.length;r++){let l=0,n=0,a=!0;for(let o=r-i+1;o<=r;o++){let i=e[o],r=t[o];if(!Number.isFinite(i)||!Number.isFinite(r)){a=!1;break}l+=i,n+=r}if(!a)continue;let s=l/i,h=n/i,d=0,c=0,p=0;for(let o=r-i+1;o<=r;o++){let i=e[o]-s,r=t[o]-h;d+=i*r,c+=i*i,p+=r*r}let u=Math.sqrt(c*p);o[r]=0===u?0:d/u}return o}function ax(e){let t=Array(e.length).fill(NaN);for(let i=1;i<e.length;i++){let o=(e[i].time-e[i-1].time)/864e5;o>0&&(t[i]=o)}return t}function ak(e){let t=Array(e.length).fill(NaN);for(let i=3;i<e.length;i++){let o=e[i-3],r=e[i-2],l=e[i-1],n=e[i];Number.isFinite(o)&&Number.isFinite(r)&&Number.isFinite(l)&&Number.isFinite(n)&&(t[i]=(o+2*r+2*l+n)/6)}return t}function aS(e){let t=Array(e.length).fill(NaN),i=0,o=!1;for(let r=0;r<e.length;r++){let l=e[r];Number.isFinite(l)&&(i+=l,o=!0),o&&(t[r]=i)}return t}function aT(e,t){return Array(e).fill(t)}function aM(e){let t=Array(e.length).fill(NaN);for(let i=1;i<e.length;i++){let o=e[i],r=e[i-1];Number.isFinite(o)&&Number.isFinite(r)&&o>0&&r>0&&(t[i]=Math.log(o/r))}return t}function aL(e,t){let i=e.length,o=Array(i).fill(null);if(0===t.length)return o;let r=-1;for(let l=0;l<i;l++){let i=e[l].time;for(;r+1<t.length&&t[r+1].time<=i;)r++;r>=0&&(o[l]=t[r])}return o}var aA="Settings",aP="Style";function aI(e,t="length",i=(0,n.ab)("indicator.common.length","Length"),o=5e3,r){return{key:t,title:i,type:"int",defval:e,min:1,max:o,step:1,group:aA,...null!=r?{tooltip:r}:{}}}function aE(e,t,i,o=1,r=5e3,l){return{key:e,title:t,type:"int",defval:i,min:o,max:r,step:1,group:aA,...null!=l?{tooltip:l}:{}}}function aB(e,t,i,o=0,r=1e3,l=.1,n){return{key:e,title:t,type:"float",defval:i,min:o,max:r,step:l,group:aA,...null!=n?{tooltip:n}:{}}}function aF(e,t,i,o=aA,r){return{key:e,title:t,type:"bool",defval:i,group:o,...null!=r?{tooltip:r}:{}}}function aO(e,t,i,o,r){return{key:e,title:t,type:"string",defval:i,options:o,group:aA,...null!=r?{tooltip:r}:{}}}function aR(e="Close",t="source",i=(0,n.ab)("indicator.common.source","Source"),o){return{key:t,title:i,type:"string",defval:e,options:n5,group:aA,...null!=o?{tooltip:o}:{}}}function aN(e,t,i="",o){return{key:e,title:t,type:"symbol",defval:i,group:aA,...o?.confirm?{confirm:!0}:{},...o?.tooltip!=null?{tooltip:o.tooltip}:{}}}function az(e=r.rD,t=(0,n.ab)("indicator.common.color","Color"),i="color",o){return{key:i,title:t,type:"color",defval:e,group:aP,...null!=o?{tooltip:o}:{}}}function aV(e=2,t="lineWidth",i=(0,n.ab)("indicator.common.lineWidth","Line Width")){return{key:t,title:i,type:"int",defval:e,min:1,max:5,step:1,group:aP,tooltip:(0,n.ab)("indicator.common.lineWidth.tooltip","Width of the plotted line, in pixels.")}}function aD(e,t){return function(e,t=.08){let i=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!i)return e;let o=Math.round(255*Math.max(0,Math.min(1,t))).toString(16).padStart(2,"0");return`#${i[1]}${o}`}(e,(100-t)/100)}function a$(e=(0,n.ab)("indicator.common.basisColor","Basis")){return[az(r.cr,(0,n.ab)("indicator.common.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.channel.bullColor.tooltip","Color of the lower band and of the basis while price holds above it.")),az(r.TV,(0,n.ab)("indicator.common.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.channel.bearColor.tooltip","Color of the upper band and of the basis while price sits below it.")),az(r.qm,e,"basisColor",(0,n.ab)("indicator.channel.basisColor.tooltip","Color of the basis line while price sits exactly on it."))]}function aH(e,t,i,o,l,a){let s=t.map((t,i)=>{if(!Number.isFinite(t))return null;let o=e[i].close;return o>t?l.bull:o<t?l.bear:l.neutral}),h=i.map((e,t)=>{let i=o[t];return Number.isFinite(e)&&Number.isFinite(i)?{topValue:e,bottomValue:i,topColor:aD(l.bear,90),bottomColor:aD(l.bull,90)}:null});return{plots:[{key:"basis",title:(0,n.ab)("indicator.channel.plot.basis","Basis"),values:[...t],color:l.neutral,colors:s},{key:"upper",title:(0,n.ab)("indicator.channel.plot.upper","Upper"),values:[...i],color:aD(l.bear,30)},{key:"lower",title:(0,n.ab)("indicator.channel.plot.lower","Lower"),values:[...o],color:aD(l.bull,30)}],bands:[{key:a,from:"upper",to:"lower",color:aD(r.qm,90),gradient:h}]}}function aW(e,t,i,o){return{key:e,title:t,values:Array(i).fill(o),color:aD(r.qm,100),display:{pane:!1,legend:!1,dataWindow:!1}}}function aq(e,t,i,o=92){return{plots:[aW("obAnchor","Overbought Anchor",e,t.overbought),aW("osAnchor","Oversold Anchor",e,t.oversold),aW("topAnchor","Top Anchor",e,t.top),aW("bottomAnchor","Bottom Anchor",e,t.bottom)],bands:[{key:"obZone",from:"obAnchor",to:"topAnchor",color:aD(i.overbought,o)},{key:"osZone",from:"osAnchor",to:"bottomAnchor",color:aD(i.oversold,o)}]}}function aU(e,t,i,o=50,r=100){return e.map((e,l)=>{if(!Number.isFinite(e))return null;let n=i(e,l),a=e>t;return{topValue:Math.max(e,t),bottomValue:Math.min(e,t),topColor:aD(n,a?o:r),bottomColor:aD(n,a?r:o)}})}function aj(e){var t,i,o;let l=(e.overbought+e.oversold)/2,a=(t=e.values,i={low:e.oversold,mid:l,high:e.overbought},o=e.ink,t.map(e=>Number.isFinite(e)?e<=i.mid?aY(e,i.low,i.mid,o.low,o.mid):aY(e,i.mid,i.high,o.mid,o.high):null)),s=aq(e.values.length,{overbought:e.overbought,oversold:e.oversold,top:e.scale.top,bottom:e.scale.bottom},{overbought:e.ink.high,oversold:e.ink.low},e.zoneTransparency),h=[{key:e.key,title:e.title,values:e.values,color:e.ink.mid,width:e.width??1,colors:a},...s.plots],d=[...s.bands];null!=e.bandFill&&d.push({key:"band",from:"obAnchor",to:"osAnchor",color:e.bandFill}),e.midpointWash&&(h.push(aW("midAnchor","Midpoint Anchor",e.values.length,l)),d.push({key:"wash",from:e.key,to:"midAnchor",color:aD(r.qm,100),gradient:aU(e.values,l,(t,i)=>a[i]??e.ink.mid)}));let c=[{key:"overbought",price:e.overbought,color:e.levelInk,lineStyle:"dashed",title:e.levelTitles?.overbought??(0,n.ab)("indicator.common.level.overbought","Overbought")},{key:"oversold",price:e.oversold,color:e.levelInk,lineStyle:"dashed",title:e.levelTitles?.oversold??(0,n.ab)("indicator.common.level.oversold","Oversold")}];return null!=e.midline&&c.splice(1,0,{key:"midline",price:e.midline,color:e.levelInk,lineStyle:"dotted",title:(0,n.ab)("indicator.common.level.midline","Midline")}),{plots:h,bands:d,levels:c}}function aG(e){let t=e.baseline??0,i=i=>i>t?e.ink.bull:i<t?e.ink.bear:e.ink.neutral,o=[{key:e.key,title:e.title,values:e.values,color:e.ink.neutral,width:e.width??1,colors:e.values.map(e=>Number.isFinite(e)?i(e):null)},...e.extraPlots??[]],l=[];return!1!==e.fill&&(o.push(aW("baseline","Baseline Anchor",e.values.length,t)),l.push({key:"wash",from:e.key,to:"baseline",color:aD(r.qm,100),gradient:aU(e.values,t,i,e.valueTransparency)})),{plots:o,bands:l,levels:[{key:"zero",price:t,color:e.zeroInk,lineStyle:e.zeroLineStyle??"dashed",title:e.zeroTitle??(0,n.ab)("indicator.common.level.zero","Zero Line")},...e.extraLevels??[]]}}function aK(e){let t=/^#([0-9a-f]{6})/i.exec(e.trim());if(!t)return null;let i=parseInt(t[1],16);return[i>>16&255,i>>8&255,255&i]}function aY(e,t,i,o,r){let l=aK(o),n=aK(r);if(!l||!n||!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(i))return o;let a=i-t,s=0===a?0:Math.max(0,Math.min(1,(e-t)/a)),h=e=>Math.round(l[e]+(n[e]-l[e])*s).toString(16).padStart(2,"0");return`#${h(0)}${h(1)}${h(2)}`}var aZ=["SMA","EMA","WMA","RMA (SMMA)","HMA","ALMA","VWMA","DEMA","TEMA","KAMA","LSMA","McGinley","Hamming"];function aX(e,t,i,o,r={}){switch(e){case"EMA":return ad(t,o);case"WMA":return al(t,o);case"RMA":case"RMA (SMMA)":return ac(t,o);case"HMA":let l=Math.max(2,Math.trunc(o)),n=at(ae(al(t,Math.max(1,Math.trunc(l/2))),e=>2*e),al(t,l));return al(n,Math.max(1,Math.round(Math.sqrt(l))));case"ALMA":return function(e,t,i,o){let r=i*(t-1),l=t/Math.max(o,1e-9),n=Array(t),a=0;for(let e=0;e<t;e++){let t=e-r,i=Math.exp(-(t*t)/(2*l*l));n[e]=i,a+=i}return ai(e,t,(e,t,i)=>{let o=0;for(let r=t;r<=i;r++)o+=e[r]*n[r-t];return 0===a?NaN:o/a})}(t,o,r.almaOffset??.85,r.almaSigma??6);case"VWMA":var a=n4(i);let s=n9(t,a,(e,t)=>e*t);return n9(ao(s,o),ao(a,o),(e,t)=>t>0?e/t:NaN);case"DEMA":let h=ad(t,o);return at(ae(h,e=>2*e),ad(h,o));case"TEMA":let d=ad(t,o),c=ad(d,o),p=ad(c,o);return n9(n9(ae(d,e=>3*e),ae(c,e=>3*e),(e,t)=>e-t),p,(e,t)=>e+t);case"KAMA":return function(e,t,i=2/3,o=2/31){let r=ae(ap(e,t),Math.abs),l=ao(ae(ap(e),Math.abs),t),n=Array(e.length).fill(NaN),a=NaN;for(let t=0;t<e.length;t++){let s=e[t];if(!Number.isFinite(s))continue;let h=r[t],d=l[t];if(!Number.isFinite(h)||!Number.isFinite(d)){a=Number.isFinite(a)?a:s,n[t]=a;continue}let c=((0===d?0:h/d)*(i-o)+o)**2;a=Number.isFinite(a)?a+c*(s-a):s,n[t]=a}return n}(t,o);case"LSMA":return ay(t,o,r.lsmaOffset??0);case"McGinley":return function(e,t){let i=Array(e.length).fill(NaN),o=NaN;for(let r=0;r<e.length;r++){let l=e[r];if(Number.isFinite(l)){if(Number.isFinite(o)){let e=t*(0===o?0:l/o)**4;o+=0===e?0:(l-o)/e}else o=l;i[r]=o}}return i}(t,o);case"Hamming":return function(e,t,i=.54,o=.46){if(t<=1)return e.map(e=>Number.isFinite(e)?e:NaN);let r=Array(t),l=0;for(let e=0;e<t;e++){let n=i-o*Math.cos(2*Math.PI*e/(t-1));r[e]=n,l+=n}return ai(e,t,(e,t,i)=>{let o=0;for(let l=t;l<=i;l++)o+=e[l]*r[i-l];return 0===l?NaN:o/l})}(t,o);default:return ar(t,o)}}function a_(){return[aF("trendColor",(0,n.ab)("indicator.slope.trendColor","Slope Trend Coloring"),!0,aP,(0,n.ab)("indicator.slope.trendColor.tooltip","Colors the line by its slope — bullish while it rises, bearish while it falls. Disable to draw it in the neutral color.")),az(r.cr,(0,n.ab)("indicator.common.bullColor","Bullish"),"bullColor"),az(r.TV,(0,n.ab)("indicator.common.bearColor","Bearish"),"bearColor"),az(r.qm,(0,n.ab)("indicator.common.neutralColor","Neutral"),"neutralColor"),aV()]}function aQ(e,t,i,o){var l,n;let a=nQ(o,"neutralColor",r.qm),s=nJ(o,"trendColor",!0);return{key:e,title:t,values:i,color:a,width:n_(o,"lineWidth",2),...s?{colors:(l=nQ(o,"bullColor",r.cr),n=nQ(o,"bearColor",r.TV),i.map((e,t)=>{if(!Number.isFinite(e))return null;let o=t>0?i[t-1]:NaN;return Number.isFinite(o)?e>o?l:e<o?n:a:a}))}:{}}}var aJ={key:"offset",title:(0,n.ab)("indicator.common.offset","Offset"),type:"int",defval:0,min:-500,max:500,step:1,group:aA,tooltip:(0,n.ab)("indicator.common.offset.tooltip","Bars the plotted line is displaced by. Positive values push it to the right.")};function a0(e,t,i,o){return{type:e,title:t.title,shortTitle:t.shortTitle,overlay:!0,inputs:[aI(20,"length",(0,n.ab)("indicator.common.length","Length"),5e3,t.lengthTooltip),aR("Close","source",(0,n.ab)("indicator.common.source","Source"),t.sourceTooltip),aJ,az()],compute:(e,l)=>{let n=n_(l,"length",20),a=o(n3(e,nQ(l,"source","Close")),n),s=Math.trunc(n_(l,"offset",0));return 0!==s&&(a=ag(a,s)),{plots:[{key:i.toLowerCase(),title:t.shortTitle,values:a,color:nQ(l,"color",r.rD),width:2}]}}}}var a1=a0("sma",{title:(0,n.ab)("indicator.sma.title","Simple Moving Average"),shortTitle:(0,n.ab)("indicator.sma.shortTitle","SMA"),lengthTooltip:(0,n.ab)("indicator.sma.length.tooltip","Number of bars used in the SMA calculation."),sourceTooltip:(0,n.ab)("indicator.sma.source.tooltip","Price series the SMA is calculated on.")},"SMA",ar),a2=a0("ema",{title:(0,n.ab)("indicator.ema.title","Exponential Moving Average"),shortTitle:(0,n.ab)("indicator.ema.shortTitle","EMA"),lengthTooltip:(0,n.ab)("indicator.ema.length.tooltip","Number of bars used in the EMA calculation."),sourceTooltip:(0,n.ab)("indicator.ema.source.tooltip","Price series the EMA is calculated on.")},"EMA",ad),a5={type:"moving-average",title:(0,n.ab)("indicator.movingAverage.title","Moving Average"),shortTitle:(0,n.ab)("indicator.movingAverage.shortTitle","MA"),overlay:!0,inputs:[aO("maType",(0,n.ab)("indicator.movingAverage.maType","MA 1 Type"),"SMA",aZ,(0,n.ab)("indicator.movingAverage.maType.tooltip","Moving average calculation used for MA 1.")),aI(20,"length",(0,n.ab)("indicator.movingAverage.length","MA 1 Length"),5e3,(0,n.ab)("indicator.movingAverage.length.tooltip","Number of bars used in the MA 1 calculation.")),aR("Close","source",(0,n.ab)("indicator.movingAverage.source","MA 1 Source"),(0,n.ab)("indicator.movingAverage.source.tooltip","Price series MA 1 is calculated on.")),aF("showMa2",(0,n.ab)("indicator.movingAverage.showMa2","Show MA 2"),!1,aA,(0,n.ab)("indicator.movingAverage.showMa2.tooltip","Displays the optional second moving average.")),aO("ma2Type",(0,n.ab)("indicator.movingAverage.ma2Type","MA 2 Type"),"SMA",aZ,(0,n.ab)("indicator.movingAverage.ma2Type.tooltip","Moving average calculation used for MA 2.")),aI(50,"ma2Length",(0,n.ab)("indicator.movingAverage.ma2Length","MA 2 Length"),5e3,(0,n.ab)("indicator.movingAverage.ma2Length.tooltip","Number of bars used in the MA 2 calculation.")),aR("Close","ma2Source",(0,n.ab)("indicator.movingAverage.ma2Source","MA 2 Source"),(0,n.ab)("indicator.movingAverage.ma2Source.tooltip","Price series MA 2 is calculated on.")),aB("almaOffset",(0,n.ab)("indicator.movingAverage.almaOffset","ALMA Offset"),.85,0,1,.05,(0,n.ab)("indicator.movingAverage.almaOffset.tooltip","ALMA type only. Values near 1 make the average more responsive, values near 0 make it smoother.")),aB("almaSigma",(0,n.ab)("indicator.movingAverage.almaSigma","ALMA Sigma"),6,.1,100,.5,(0,n.ab)("indicator.movingAverage.almaSigma.tooltip","ALMA type only. Larger values widen the Gaussian window for a smoother average.")),aE("lsmaOffset",(0,n.ab)("indicator.movingAverage.lsmaOffset","LSMA Offset"),0,0,500,(0,n.ab)("indicator.movingAverage.lsmaOffset.tooltip","LSMA type only. Bar offset applied to the linear regression value.")),aJ,az(r.rD,(0,n.ab)("indicator.movingAverage.color","MA 1"),"color",(0,n.ab)("indicator.movingAverage.color.tooltip","MA 1 line color.")),az(r.Nz,(0,n.ab)("indicator.movingAverage.ma2Color","MA 2"),"ma2Color",(0,n.ab)("indicator.movingAverage.ma2Color.tooltip","MA 2 line color."))],compute:(e,t)=>{let i={almaOffset:n_(t,"almaOffset",.85),almaSigma:n_(t,"almaSigma",6),lsmaOffset:Math.trunc(n_(t,"lsmaOffset",0))},o=Math.trunc(n_(t,"offset",0)),l=e=>0===o?e:ag(e,o),n=nQ(t,"maType","SMA"),a=l(aX(n,n3(e,nQ(t,"source","Close")),e,n_(t,"length",20),i)),s=[{key:"ma",title:n,values:a,color:nQ(t,"color",r.rD),width:2}];if(nJ(t,"showMa2",!1)){let o=nQ(t,"ma2Type","SMA"),n=l(aX(o,n3(e,nQ(t,"ma2Source","Close")),e,n_(t,"ma2Length",50),i));s.push({key:"ma2",title:`${o} 2`,values:n,color:nQ(t,"ma2Color",r.Nz),width:2})}return{plots:s}}},a3={type:"rma",title:(0,n.ab)("indicator.rma.title","Smoothed Moving Average"),shortTitle:(0,n.ab)("indicator.rma.shortTitle","RMA"),overlay:!0,inputs:[aR("Close","source",(0,n.ab)("indicator.rma.source","Source"),(0,n.ab)("indicator.rma.source.tooltip","Price series the average smooths. Wilder computed his 1978 indicators on the close, but the recursion accepts any source.")),aI(14,"length",(0,n.ab)("indicator.rma.length","RMA Length"),5e3,(0,n.ab)("indicator.rma.length.tooltip","Number of bars N in Wilder's smoothing: the line keeps (N − 1)/N of its previous value and blends in 1/N of the new price. That alpha is smaller than an EMA's, so an N-period RMA responds like a (2N − 1)-period EMA.")),...a_()],compute:(e,t)=>({plots:[aQ("rma",(0,n.ab)("indicator.rma.plot.rma","RMA"),ac(n3(e,nQ(t,"source","Close")),n_(t,"length",14)),t)]})},a4={type:"zlema",title:(0,n.ab)("indicator.zlema.title","Zero-Lag Exponential Moving Average"),shortTitle:(0,n.ab)("indicator.zlema.shortTitle","ZLEMA"),overlay:!0,inputs:[aR("Close","source",(0,n.ab)("indicator.zlema.source","Source"),(0,n.ab)("indicator.zlema.source.tooltip","Price series the average de-lags and then smooths.")),aI(21,"length",(0,n.ab)("indicator.zlema.length","ZLEMA Length"),5e3,(0,n.ab)("indicator.zlema.length.tooltip","EMA length N. It sets both the smoothing (alpha = 2 / (N + 1)) and the correction: an EMA of length N lags by about (N − 1)/2 bars, and the de-lagging step is sized to cancel exactly that.")),...a_()],compute:(e,t)=>{let i=n_(t,"length",21),o=n3(e,nQ(t,"source","Close")),r=n9(o,ag(o,Math.round((i-1)/2)),(e,t)=>2*e-t);return{plots:[aQ("zlema",(0,n.ab)("indicator.zlema.plot.zlema","ZLEMA"),ad(r,i),t)]}}},a6="Momentum (|CMO|)",a8="Volatility (StDev Ratio)",a7="Trend Regime",a9={type:"vidya",title:(0,n.ab)("indicator.vidya.title","Variable Index Dynamic Average"),shortTitle:(0,n.ab)("indicator.vidya.shortTitle","VIDYA"),overlay:!0,inputs:[aR("Close","source",(0,n.ab)("indicator.vidya.source","Source"),(0,n.ab)("indicator.vidya.source.tooltip","Price series the average smooths. VIDYA is classically computed on the close.")),aI(12,"length",(0,n.ab)("indicator.vidya.length","VIDYA Length"),5e3,(0,n.ab)("indicator.vidya.length.tooltip","EMA-equivalent length N of the base smoothing constant, alpha = 2 / (N + 1). The adaptive scaler rescales this base speed bar by bar.")),aO("scaler",(0,n.ab)("indicator.vidya.scaler","Adaptive Scaler"),a6,[a6,a8],(0,n.ab)("indicator.vidya.scaler.tooltip","Bar-by-bar measure that rescales the smoothing constant. Momentum divides the absolute Chande Momentum Oscillator by 100; Volatility is Chande's original short-term over reference standard deviation.")),aE("scalerLength",(0,n.ab)("indicator.vidya.scalerLength","Scaler Lookback"),9,1,5e3,(0,n.ab)("indicator.vidya.scalerLength.tooltip","Lookback of the adaptive scaler — the CMO period in momentum mode, or the short-term standard deviation window in volatility mode.")),aE("refLength",(0,n.ab)("indicator.vidya.refLength","Reference StDev Length"),30,2,5e3,(0,n.ab)("indicator.vidya.refLength.tooltip","Volatility mode only — window of the reference standard deviation the short-term reading is divided by.")),{...aB("flatThreshold",(0,n.ab)("indicator.vidya.flatThreshold","Flat Threshold"),.05,0,10,.01,(0,n.ab)("indicator.vidya.flatThreshold.tooltip","One-bar change of VIDYA, as a fraction of ATR, below which the line reads as flat.")),group:a7},{...aE("atrLength",(0,n.ab)("indicator.vidya.atrLength","ATR Normalization Length"),14,1,5e3,(0,n.ab)("indicator.vidya.atrLength.tooltip","ATR window used to normalize VIDYA's one-bar slope, so the flat threshold behaves consistently across symbols and timeframes.")),group:a7},aF("trendColor",(0,n.ab)("indicator.vidya.trendColor","Trend Regime Coloring"),!0,aP,(0,n.ab)("indicator.vidya.trendColor.tooltip","Colors VIDYA by its regime read — bullish while sloping up beyond the flat threshold, bearish while sloping down, flat inside congestion.")),aF("adaptiveGradient",(0,n.ab)("indicator.vidya.adaptiveGradient","Adaptive Gradient"),!0,aP,(0,n.ab)("indicator.vidya.adaptiveGradient.tooltip","Blends the trend color toward the flat color according to the adaptive scaler, so the line pales as momentum dies.")),az(r.cr,(0,n.ab)("indicator.vidya.bullColor","Bullish"),"bullColor"),az(r.TV,(0,n.ab)("indicator.vidya.bearColor","Bearish"),"bearColor"),az(r.qm,(0,n.ab)("indicator.vidya.flatColor","Flat"),"flatColor"),az(r.qm,(0,n.ab)("indicator.vidya.neutralColor","Neutral"),"neutralColor"),aV()],compute:(e,t)=>{let i=n_(t,"length",12),o=n3(e,nQ(t,"source","Close")),l=n_(t,"scalerLength",9),a=ae(function(e,t){let i=ap(e);return n9(ao(ae(i,e=>Math.max(e,0)),t),ao(ae(i,e=>Math.max(-e,0)),t),(e,t)=>e+t===0?0:100*(e-t)/(e+t))}(o,l),e=>Math.abs(e)/100),s=n9(an(o,l),an(o,n_(t,"refLength",30)),(e,t)=>t>0?e/t:0),h=nQ(t,"scaler",a6)===a8?s:a,d=2/(i+1),c=Array(o.length).fill(NaN),p=NaN;for(let e=0;e<o.length;e++){let t=o[e];if(!Number.isFinite(t))continue;let i=h[e];if(Number.isFinite(p)&&Number.isFinite(i)){let e=Math.min(d*i,1);p=e*t+(1-e)*p}else p=t;c[e]=p}let u=nQ(t,"neutralColor",r.qm);if(!nJ(t,"trendColor",!0))return{plots:[{key:"vidya",title:(0,n.ab)("indicator.vidya.plot.vidya","VIDYA"),values:c,color:u,width:n_(t,"lineWidth",2)}]};let g=nQ(t,"bullColor",r.cr),m=nQ(t,"bearColor",r.TV),b=nQ(t,"flatColor",r.qm),f=n_(t,"flatThreshold",.05),v=ab(e,n_(t,"atrLength",14)),y=nJ(t,"adaptiveGradient",!0),w=c.map((e,t)=>{if(!Number.isFinite(e))return null;let i=v[t],o=t>0&&Number.isFinite(c[t-1])?e-c[t-1]:0,r=Number.isFinite(i)&&0!==i?o/i:0,l=r>f?g:r<-f?m:null;return null==l?b:y?aY(Math.min(h[t]??0,1),0,1,b,l):l});return{plots:[{key:"vidya",title:(0,n.ab)("indicator.vidya.plot.vidya","VIDYA"),values:c,color:b,width:n_(t,"lineWidth",2),colors:w}]}}},se={type:"ma-envelope",title:(0,n.ab)("indicator.maEnvelope.title","Moving Average Envelope"),shortTitle:(0,n.ab)("indicator.maEnvelope.shortTitle","MA Env"),overlay:!0,inputs:[aO("maType",(0,n.ab)("indicator.maEnvelope.maType","MA Type"),"SMA",["SMA","EMA","WMA","RMA (SMMA)","HMA","VWMA"],(0,n.ab)("indicator.maEnvelope.maType.tooltip","Moving average type used as the envelope basis.")),{...aI(20,"length",(0,n.ab)("indicator.maEnvelope.length","Length"),5e3,(0,n.ab)("indicator.maEnvelope.length.tooltip","Number of bars in the basis moving average.")),min:2},aR("Close","source",(0,n.ab)("indicator.maEnvelope.source","Source"),(0,n.ab)("indicator.maEnvelope.source.tooltip","Price series the basis moving average is calculated on.")),aB("percent",(0,n.ab)("indicator.maEnvelope.percent","Percent"),2.5,0,50,.1,(0,n.ab)("indicator.maEnvelope.percent.tooltip","Envelope offset as a percentage of the basis. Upper = basis \xd7 (1 + percent / 100), lower = basis \xd7 (1 − percent / 100).")),...a$()],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=aX(nQ(t,"maType","SMA"),i,e,n_(t,"length",20)),l=n_(t,"percent",2.5)/100,n={bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"basisColor",r.qm)};return aH(e,o,ae(o,e=>e*(1+l)),ae(o,e=>e*(1-l)),n,"envelope")}},st={type:"lsma",title:(0,n.ab)("indicator.lsma.title","Least Squares Moving Average"),shortTitle:(0,n.ab)("indicator.lsma.shortTitle","LSMA"),overlay:!0,inputs:[aR("Close","source",(0,n.ab)("indicator.lsma.source","Source"),(0,n.ab)("indicator.lsma.source.tooltip","Price series the regression line is fitted to.")),{...aI(25,"length",(0,n.ab)("indicator.lsma.length","LSMA Length"),5e3,(0,n.ab)("indicator.lsma.length.tooltip","Number of bars N in each least-squares fit. Every bar fits a straight line to its last N values and plots where that line ends, so the average leads turns that a same-length SMA trails, at the cost of overshooting after sharp moves.")),min:2},aE("offset",(0,n.ab)("indicator.lsma.offset","Regression Offset"),0,0,500,(0,n.ab)("indicator.lsma.offset.tooltip","Bars to step back along each bar's fitted line. 0 plots the line's endpoint at the current bar; larger values read the fit further back, trading lead for smoothness.")),...a_()],compute:(e,t)=>{let i=ay(n3(e,nQ(t,"source","Close")),n_(t,"length",25),Math.trunc(n_(t,"offset",0)));return{plots:[aQ("lsma",(0,n.ab)("indicator.lsma.plot.lsma","LSMA"),i,t)]}}},si={type:"linear-regression-slope",title:(0,n.ab)("indicator.linearRegressionSlope.title","Linear Regression Slope"),shortTitle:(0,n.ab)("indicator.linearRegressionSlope.shortTitle","LRS"),overlay:!1,inputs:[{...aI(100,"length",(0,n.ab)("indicator.linearRegressionSlope.length","Length"),5e3,(0,n.ab)("indicator.linearRegressionSlope.length.tooltip","Number of bars used to fit the linear regression.")),min:2},aR("Close","source",(0,n.ab)("indicator.linearRegressionSlope.source","Source"),(0,n.ab)("indicator.linearRegressionSlope.source.tooltip","Price series the regression is fitted to.")),az(r.cr,(0,n.ab)("indicator.linearRegressionSlope.bullColor","Rising"),"bullColor",(0,n.ab)("indicator.linearRegressionSlope.bullColor.tooltip","Color of the slope line while the fit slopes upward.")),az(r.TV,(0,n.ab)("indicator.linearRegressionSlope.bearColor","Falling"),"bearColor",(0,n.ab)("indicator.linearRegressionSlope.bearColor.tooltip","Color of the slope line while the fit slopes downward.")),az(r.qm,(0,n.ab)("indicator.linearRegressionSlope.lineColor","Slope Line"),"lineColor",(0,n.ab)("indicator.linearRegressionSlope.lineColor.tooltip","Color of the slope line while the fit is flat."))],compute:(e,t)=>{let i=n_(t,"length",100),o=n3(e,nQ(t,"source","Close")),l=n9(ay(o,i,0),ay(o,i,1),(e,t)=>e-t),a=nQ(t,"bullColor",r.cr),s=nQ(t,"bearColor",r.TV),h=nQ(t,"lineColor",r.qm),d=l.map(e=>Number.isFinite(e)?e>0?a:e<0?s:h:null);return{plots:[{key:"slope",title:(0,n.ab)("indicator.linearRegressionSlope.plot.slope","Slope"),values:l,color:h,width:2,colors:d}],levels:[{key:"zero",price:0,color:aD(r.qm,50),lineStyle:"dashed"}]}}},so=["SMA","EMA","WMA"];function sr(e,t,i,o,l){let a=(0,n.ab)("indicator.maCross.length.tooltip","Number of bars this average covers.");return{type:e,title:t,shortTitle:i,overlay:!0,inputs:[aI(o.length,`${o.key}Length`,o.lengthTitle,5e3,a),aI(l.length,`${l.key}Length`,l.lengthTitle,5e3,a),aR("Close","source",(0,n.ab)("indicator.common.source","Source"),(0,n.ab)("indicator.maCross.source.tooltip","Price series both averages are calculated on.")),az(r.rD,o.title,`${o.key}Color`),az(r.Nz,l.title,`${l.key}Color`),az(r.cr,(0,n.ab)("indicator.maCross.bullColor","Bullish Cross"),"bullColor",(0,n.ab)("indicator.maCross.bullColor.tooltip","Color of the marker where the first average crosses above the second.")),az(r.TV,(0,n.ab)("indicator.maCross.bearColor","Bearish Cross"),"bearColor",(0,n.ab)("indicator.maCross.bearColor.tooltip","Color of the marker where the first average crosses below the second."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),a=o.smooth(i,n_(t,`${o.key}Length`,o.length)),s=l.smooth(i,n_(t,`${l.key}Length`,l.length)),h=a.map((e,t)=>{if(0===t)return 0;let i=e-s[t],o=a[t-1]-s[t-1];return i>0&&o<0?1:i<0&&o>0?-1:0}),d=nQ(t,"bullColor",r.cr),c=nQ(t,"bearColor",r.TV);return{plots:[{key:o.key,title:o.title,values:a,color:nQ(t,`${o.key}Color`,r.rD),width:2},{key:l.key,title:l.title,values:s,color:nQ(t,`${l.key}Color`,r.Nz),width:2},{key:"crosses",title:(0,n.ab)("indicator.maCross.plot.crosses","Crosses"),values:h.map((e,t)=>0===e?NaN:a[t]),kind:"circles",color:d,colors:h.map(e=>0===e?null:e>0?d:c),width:4}]}}}}var sl={key:"short",title:(0,n.ab)("indicator.maCross.plot.short","Short"),lengthTitle:(0,n.ab)("indicator.maCross.shortLength","Short Length"),length:9},sn={key:"long",title:(0,n.ab)("indicator.maCross.plot.long","Long"),lengthTitle:(0,n.ab)("indicator.maCross.longLength","Long Length"),length:26},sa=sr("ma-cross",(0,n.ab)("indicator.maCross.title","MA Cross"),(0,n.ab)("indicator.maCross.shortTitle","MA Cross"),{...sl,smooth:ar},{...sn,smooth:ar}),ss=sr("ema-cross",(0,n.ab)("indicator.emaCross.title","EMA Cross"),(0,n.ab)("indicator.emaCross.shortTitle","EMA Cross"),{...sl,smooth:ad},{...sn,smooth:ad}),sh=sr("ma-with-ema-cross",(0,n.ab)("indicator.maWithEmaCross.title","MA with EMA Cross"),(0,n.ab)("indicator.maWithEmaCross.shortTitle","MA/EMA Cross"),{key:"ma",title:(0,n.ab)("indicator.maWithEmaCross.plot.ma","MA"),lengthTitle:(0,n.ab)("indicator.maWithEmaCross.maLength","MA Length"),length:10,smooth:ar},{key:"ema",title:(0,n.ab)("indicator.maWithEmaCross.plot.ema","EMA"),lengthTitle:(0,n.ab)("indicator.maWithEmaCross.emaLength","EMA Length"),length:10,smooth:ad}),sd=[{length:(0,n.ab)("indicator.multiAverage.length1","MA 1 Length"),color:(0,n.ab)("indicator.multiAverage.color1","MA 1")},{length:(0,n.ab)("indicator.multiAverage.length2","MA 2 Length"),color:(0,n.ab)("indicator.multiAverage.color2","MA 2")},{length:(0,n.ab)("indicator.multiAverage.length3","MA 3 Length"),color:(0,n.ab)("indicator.multiAverage.color3","MA 3")},{length:(0,n.ab)("indicator.multiAverage.length4","MA 4 Length"),color:(0,n.ab)("indicator.multiAverage.color4","MA 4")},{length:(0,n.ab)("indicator.multiAverage.length5","MA 5 Length"),color:(0,n.ab)("indicator.multiAverage.color5","MA 5")},{length:(0,n.ab)("indicator.multiAverage.length6","MA 6 Length"),color:(0,n.ab)("indicator.multiAverage.color6","MA 6")}];function sc(e,t,i,o){let l=o.map((e,t)=>({length:e,plotKey:`ma${t+1}`,lengthKey:`length${t+1}`,colorKey:`color${t+1}`,ink:aY(t,0,o.length-1,r.rD,r.Nz),text:sd[t]}));return{type:e,title:t,shortTitle:i,overlay:!0,inputs:[aO("maType",(0,n.ab)("indicator.multiAverage.maType","MA Type"),"SMA",so,(0,n.ab)("indicator.multiAverage.maType.tooltip","Moving average calculation every line uses.")),aR("Close","source",(0,n.ab)("indicator.common.source","Source"),(0,n.ab)("indicator.multiAverage.source.tooltip","Price series every line is calculated on.")),...l.map(e=>aI(e.length,e.lengthKey,e.text.length,5e3,(0,n.ab)("indicator.multiAverage.length.tooltip","Number of bars this line averages."))),...l.map(e=>az(e.ink,e.text.color,e.colorKey))],compute:(e,t)=>{let i=nQ(t,"maType","SMA"),o=n3(e,nQ(t,"source","Close"));return{plots:l.map(r=>{let l=n_(t,r.lengthKey,r.length);return{key:r.plotKey,title:`${i} ${l}`,values:aX(i,o,e,l),color:nQ(t,r.colorKey,r.ink),width:2}})}}}}var sp=sc("moving-average-double",(0,n.ab)("indicator.maDouble.title","Moving Average Double"),(0,n.ab)("indicator.maDouble.shortTitle","MA Double"),[14,21]),su=sc("moving-average-triple",(0,n.ab)("indicator.maTriple.title","Moving Average Triple"),(0,n.ab)("indicator.maTriple.shortTitle","MA Triple"),[14,21,35]),sg=sc("moving-average-multiple",(0,n.ab)("indicator.maMultiple.title","Moving Average Multiple"),(0,n.ab)("indicator.maMultiple.shortTitle","MA Multiple"),[14,21,35,50,100,200]),sm=[{key:"trader1",length:3,title:(0,n.ab)("indicator.guppy.trader1","Trader EMA 1 Length"),trader:!0},{key:"trader2",length:5,title:(0,n.ab)("indicator.guppy.trader2","Trader EMA 2 Length"),trader:!0},{key:"trader3",length:8,title:(0,n.ab)("indicator.guppy.trader3","Trader EMA 3 Length"),trader:!0},{key:"trader4",length:10,title:(0,n.ab)("indicator.guppy.trader4","Trader EMA 4 Length"),trader:!0},{key:"trader5",length:12,title:(0,n.ab)("indicator.guppy.trader5","Trader EMA 5 Length"),trader:!0},{key:"trader6",length:15,title:(0,n.ab)("indicator.guppy.trader6","Trader EMA 6 Length"),trader:!0},{key:"investor1",length:30,title:(0,n.ab)("indicator.guppy.investor1","Investor EMA 1 Length"),trader:!1},{key:"investor2",length:35,title:(0,n.ab)("indicator.guppy.investor2","Investor EMA 2 Length"),trader:!1},{key:"investor3",length:40,title:(0,n.ab)("indicator.guppy.investor3","Investor EMA 3 Length"),trader:!1},{key:"investor4",length:45,title:(0,n.ab)("indicator.guppy.investor4","Investor EMA 4 Length"),trader:!1},{key:"investor5",length:50,title:(0,n.ab)("indicator.guppy.investor5","Investor EMA 5 Length"),trader:!1},{key:"investor6",length:60,title:(0,n.ab)("indicator.guppy.investor6","Investor EMA 6 Length"),trader:!1}],sb={type:"guppy-multiple-moving-average",title:(0,n.ab)("indicator.guppy.title","Guppy Multiple Moving Average"),shortTitle:(0,n.ab)("indicator.guppy.shortTitle","GMMA"),overlay:!0,inputs:[aR("Close","source",(0,n.ab)("indicator.common.source","Source"),(0,n.ab)("indicator.guppy.source.tooltip","Price series the twelve averages are calculated on.")),...sm.map(e=>aI(e.length,e.key,e.title,5e3,(0,n.ab)("indicator.guppy.length.tooltip","Number of bars this exponential average covers."))),az(r.rD,(0,n.ab)("indicator.guppy.traderColor","Traders"),"traderColor",(0,n.ab)("indicator.guppy.traderColor.tooltip","Color of the six short averages.")),az(r.Nz,(0,n.ab)("indicator.guppy.investorColor","Investors"),"investorColor",(0,n.ab)("indicator.guppy.investorColor.tooltip","Color of the six long averages."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=nQ(t,"traderColor",r.rD),l=nQ(t,"investorColor",r.Nz);return{plots:sm.map(e=>{let r=n_(t,e.key,e.length);return{key:e.key,title:`EMA ${r}`,values:ad(i,r),color:e.trader?o:l,width:1}})}}},sf="#ab47bc",sv=r.Nz,sy="#ffd700";function sw(e,t){let i=n_(t,"length",20),o=n_(t,"mult",2),r=n3(e,nQ(t,"source","Close")),l=ar(r,i),n=ae(an(r,i),e=>e*o);return{src:r,basis:l,upper:n9(l,n,(e,t)=>e+t),lower:n9(l,n,(e,t)=>e-t)}}function sC(e,t){return[{...aI(20,"length",(0,n.ab)("indicator.common.length","Length"),5e3,(0,n.ab)("indicator.bollinger.length.tooltip","Number of bars used for the Bollinger Bands basis (a simple moving average) and for the standard deviation.")),min:2},aR("Close","source",(0,n.ab)("indicator.common.source","Source"),(0,n.ab)("indicator.bollinger.source.tooltip","Price series the bands are computed from.")),aB("mult",(0,n.ab)("indicator.bollinger.mult","Multiplier"),2,e,50,t,(0,n.ab)("indicator.bollinger.mult.tooltip","Standard deviation multiplier for the upper and lower bands."))]}var sx={type:"bollinger-bands",title:(0,n.ab)("indicator.bollingerBands.title","Bollinger Bands"),shortTitle:(0,n.ab)("indicator.bollingerBands.shortTitle","BB"),overlay:!0,inputs:[aI(20,"length",(0,n.ab)("indicator.bollingerBands.length","Length"),5e3,(0,n.ab)("indicator.bollingerBands.length.tooltip","Number of bars used to calculate the basis SMA and the standard deviation.")),aR("Close","source",(0,n.ab)("indicator.bollingerBands.source","Source"),(0,n.ab)("indicator.bollingerBands.source.tooltip","Price series the bands are calculated on.")),aB("mult",(0,n.ab)("indicator.bollingerBands.mult","Multiplier"),2,0,50,.1,(0,n.ab)("indicator.bollingerBands.mult.tooltip","Number of standard deviations added above and below the basis to form the bands.")),az(r.Nz,(0,n.ab)("indicator.bollingerBands.basisColor","Basis"),"basisColor",(0,n.ab)("indicator.bollingerBands.basisColor.tooltip","Color of the basis (middle band) moving average.")),az(r.rD,(0,n.ab)("indicator.bollingerBands.color","Bands"),"color",(0,n.ab)("indicator.bollingerBands.color.tooltip","Color of the upper and lower bands.")),az(aD(r.rD,92),(0,n.ab)("indicator.bollingerBands.fillColor","Fill"),"fillColor",(0,n.ab)("indicator.bollingerBands.fillColor.tooltip","Fill color of the area between the upper and lower bands."))],compute:(e,t)=>{let{basis:i,upper:o,lower:l}=sw(e,t),a=nQ(t,"color",r.rD);return{plots:[{key:"basis",title:(0,n.ab)("indicator.bollingerBands.plot.basis","Basis"),values:i,color:nQ(t,"basisColor",r.Nz)},{key:"upper",title:(0,n.ab)("indicator.bollingerBands.plot.upper","Upper"),values:o,color:a},{key:"lower",title:(0,n.ab)("indicator.bollingerBands.plot.lower","Lower"),values:l,color:a}],bands:[{key:"bb",from:"upper",to:"lower",color:nQ(t,"fillColor",aD(r.rD,92))}]}}},sk="Thresholds",sS={type:"percent-b",title:(0,n.ab)("indicator.percentB.title","Bollinger Bands %B"),shortTitle:(0,n.ab)("indicator.percentB.shortTitle","%B"),overlay:!1,inputs:[...sC(.001,.25),{...aB("overbought",(0,n.ab)("indicator.percentB.overbought","Overbought"),1,-10,10,.05,(0,n.ab)("indicator.percentB.overbought.tooltip","Level treated as overbought. 1 is the upper band itself, so readings above the default mean price sits outside the bands.")),group:sk},{...aB("oversold",(0,n.ab)("indicator.percentB.oversold","Oversold"),0,-10,10,.05,(0,n.ab)("indicator.percentB.oversold.tooltip","Level treated as oversold. 0 is the lower band itself, so readings below the default mean price sits outside the bands.")),group:sk},az(r.cr,(0,n.ab)("indicator.percentB.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.percentB.bullColor.tooltip","Color of %B above the 0.5 midline, where price trades in the upper half of the bands.")),az(r.TV,(0,n.ab)("indicator.percentB.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.percentB.bearColor.tooltip","Color of %B below the 0.5 midline, where price trades in the lower half of the bands.")),aF("gradientFill",(0,n.ab)("indicator.percentB.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.percentB.gradientFill.tooltip","Vertical gradient between %B and the 0.5 midline, fully transparent at the midline and more opaque at the oscillator value.")),az(r.qm,(0,n.ab)("indicator.percentB.levelsColor","Levels Color"),"levelsColor",(0,n.ab)("indicator.percentB.levelsColor.tooltip","Color of the dashed overbought/oversold levels and of the dotted midline."))],compute:(e,t)=>{let{src:i,upper:o,lower:l}=sw(e,t),a=i.map((e,t)=>{let i=o[t],r=l[t];return Number.isFinite(i)&&Number.isFinite(r)&&i!==r?(e-r)/(i-r):NaN}),s=nQ(t,"bullColor",r.cr),h=nQ(t,"bearColor",r.TV),d=nQ(t,"levelsColor",r.qm),c=a.map(e=>Number.isFinite(e)?e>.5?s:h:null);return{plots:[{key:"pb",title:(0,n.ab)("indicator.percentB.plot.pb","%B"),values:a,color:h,colors:c},{key:"mid",title:(0,n.ab)("indicator.percentB.plot.mid","Midline"),values:a.map(e=>Number.isFinite(e)?.5:NaN),color:d,display:{pane:!1,legend:!1,dataWindow:!1}}],bands:nJ(t,"gradientFill",!0)?[{key:"pbFill",from:"pb",to:"mid",color:aD(r.qm,100),gradient:a.map(e=>{if(!Number.isFinite(e))return null;let t=e>.5,i=t?s:h;return{topValue:Math.max(e,.5),bottomValue:Math.min(e,.5),topColor:t?aD(i,50):aD(i,100),bottomColor:t?aD(i,100):aD(i,50)}})}]:[],levels:[{key:"overbought",price:n_(t,"overbought",1),color:d,lineStyle:"dashed",title:(0,n.ab)("indicator.percentB.level.overbought","Overbought")},{key:"oversold",price:n_(t,"oversold",0),color:d,lineStyle:"dashed",title:(0,n.ab)("indicator.percentB.level.oversold","Oversold")},{key:"midline",price:.5,color:aD(d,50),lineStyle:"dotted",title:(0,n.ab)("indicator.percentB.level.midline","Midline")}]}}},sT="Squeeze & Bulge",sM={type:"bandwidth",title:(0,n.ab)("indicator.bandwidth.title","Bollinger Bands Width"),shortTitle:(0,n.ab)("indicator.bandwidth.shortTitle","BandWidth"),overlay:!1,inputs:[...sC(.001,.25),{...aE("lookback",(0,n.ab)("indicator.bandwidth.lookback","Reference Lookback"),125,2,5e3,(0,n.ab)("indicator.bandwidth.lookback.tooltip","Window used to locate the lowest (Squeeze) and highest (Bulge) BandWidth references.")),group:sT},aF("showSqueeze",(0,n.ab)("indicator.bandwidth.showSqueeze","Show Squeeze Level"),!0,sT,(0,n.ab)("indicator.bandwidth.showSqueeze.tooltip","Plots the lowest BandWidth of the reference lookback — unusually compressed volatility, a condition rather than a directional signal.")),aF("showBulge",(0,n.ab)("indicator.bandwidth.showBulge","Show Bulge Level"),!0,sT,(0,n.ab)("indicator.bandwidth.showBulge.tooltip","Plots the highest BandWidth of the reference lookback — extreme width that is unlikely to be sustained.")),az(r.qm,(0,n.ab)("indicator.bandwidth.color","BandWidth"),"color",(0,n.ab)("indicator.bandwidth.color.tooltip","Color of the BandWidth line. At its Squeeze reference the line takes the Squeeze color, at its Bulge reference the Bulge color.")),aF("gradientFill",(0,n.ab)("indicator.bandwidth.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.bandwidth.gradientFill.tooltip","Fills the area between zero and BandWidth with a vertical gradient, fully transparent at zero.")),az(r.Nz,(0,n.ab)("indicator.bandwidth.squeezeColor","Squeeze Level"),"squeezeColor",(0,n.ab)("indicator.bandwidth.squeezeColor.tooltip","Color of the lowest-BandWidth reference line.")),az(r.TV,(0,n.ab)("indicator.bandwidth.bulgeColor","Bulge Level"),"bulgeColor",(0,n.ab)("indicator.bandwidth.bulgeColor.tooltip","Color of the highest-BandWidth reference line."))],compute:(e,t)=>{let{basis:i,upper:o,lower:l}=sw(e,t),a=i.map((e,t)=>{let i=o[t],r=l[t];return Number.isFinite(e)&&0!==e&&Number.isFinite(i)&&Number.isFinite(r)?(i-r)/e:NaN}),s=n_(t,"lookback",125),h=as(a,s),d=aa(a,s),c=nQ(t,"color",r.qm),p=nQ(t,"squeezeColor",r.Nz),u=nQ(t,"bulgeColor",r.TV),g=a.map((e,t)=>Number.isFinite(e)?e<=h[t]?p:e>=d[t]?u:c:null),m=[{key:"bbw",title:(0,n.ab)("indicator.bandwidth.plot.bbw","BandWidth"),values:a,color:c,colors:g},{key:"zero",title:(0,n.ab)("indicator.bandwidth.plot.zero","Zero Line"),values:a.map(e=>Number.isFinite(e)?0:NaN),color:aD(r.qm,90)}];return nJ(t,"showSqueeze",!0)&&m.push({key:"squeeze",title:(0,n.ab)("indicator.bandwidth.plot.squeeze","Squeeze Level"),values:h,color:p}),nJ(t,"showBulge",!0)&&m.push({key:"bulge",title:(0,n.ab)("indicator.bandwidth.plot.bulge","Bulge Level"),values:d,color:u}),{plots:m,bands:nJ(t,"gradientFill",!0)?[{key:"bbwFill",from:"bbw",to:"zero",color:aD(r.qm,100),gradient:a.map((e,t)=>{if(!Number.isFinite(e))return null;let i=g[t]??c;return{topValue:e,bottomValue:0,topColor:aD(i,50),bottomColor:aD(i,100)}})}]:[]}}},sL={type:"keltner-channels",title:(0,n.ab)("indicator.keltnerChannels.title","Keltner Channels"),shortTitle:(0,n.ab)("indicator.keltnerChannels.shortTitle","KC"),overlay:!0,inputs:[aI(20,"length",(0,n.ab)("indicator.keltnerChannels.length","EMA Length"),5e3,(0,n.ab)("indicator.keltnerChannels.length.tooltip","Number of bars used to compute the exponential moving average basis line.")),aE("atrLength",(0,n.ab)("indicator.keltnerChannels.atrLength","ATR Length"),10,1,5e3,(0,n.ab)("indicator.keltnerChannels.atrLength.tooltip","Number of bars used to compute the Average True Range (Wilder smoothing).")),aB("mult",(0,n.ab)("indicator.keltnerChannels.mult","Multiplier"),2,0,50,.1,(0,n.ab)("indicator.keltnerChannels.mult.tooltip","ATR multiple used to offset the upper and lower bands from the basis line.")),aR("Close","source",(0,n.ab)("indicator.keltnerChannels.source","Source"),(0,n.ab)("indicator.keltnerChannels.source.tooltip","Price series used to compute the basis line.")),...a$("Basis Color")],compute:(e,t)=>{let i=ad(n3(e,nQ(t,"source","Close")),n_(t,"length",20)),o=ae(ab(e,n_(t,"atrLength",10)),e=>e*n_(t,"mult",2)),l={bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"basisColor",r.qm)};return aH(e,i,n9(i,o,(e,t)=>e+t),n9(i,o,(e,t)=>e-t),l,"kc")}},sA={type:"donchian-channels",title:(0,n.ab)("indicator.donchianChannels.title","Donchian Channels"),shortTitle:(0,n.ab)("indicator.donchianChannels.shortTitle","DC"),overlay:!0,inputs:[aI(20,"length",(0,n.ab)("indicator.donchianChannels.length","Length"),5e3,(0,n.ab)("indicator.donchianChannels.length.tooltip","Lookback length. The upper and lower channels are the highest high and lowest low over this many bars.")),az(r.TV,(0,n.ab)("indicator.donchianChannels.upperColor","Upper"),"upperColor",(0,n.ab)("indicator.donchianChannels.upperColor.tooltip","Color of the upper channel line.")),az(r.qm,(0,n.ab)("indicator.donchianChannels.middleColor","Middle"),"middleColor",(0,n.ab)("indicator.donchianChannels.middleColor.tooltip","Color of the channel midline.")),az(r.cr,(0,n.ab)("indicator.donchianChannels.lowerColor","Lower"),"lowerColor",(0,n.ab)("indicator.donchianChannels.lowerColor.tooltip","Color of the lower channel line.")),az(aD(r.qm,92),(0,n.ab)("indicator.donchianChannels.fillColor","Fill"),"fillColor",(0,n.ab)("indicator.donchianChannels.fillColor.tooltip","Color of the channel interior fill."))],compute:(e,t)=>{let i=n_(t,"length",20),o=aa(n6(e),i),l=as(n8(e),i);return{plots:[{key:"upper",title:(0,n.ab)("indicator.donchianChannels.plot.upper","Upper"),values:o,color:nQ(t,"upperColor",r.TV)},{key:"middle",title:(0,n.ab)("indicator.donchianChannels.plot.middle","Middle"),kind:"circles",values:n9(o,l,(e,t)=>(e+t)/2),color:nQ(t,"middleColor",r.qm)},{key:"lower",title:(0,n.ab)("indicator.donchianChannels.plot.lower","Lower"),values:l,color:nQ(t,"lowerColor",r.cr)}],bands:[{key:"dc",from:"upper",to:"lower",color:nQ(t,"fillColor",aD(r.qm,92))}]}}},sP={type:"moving-average-channel",title:(0,n.ab)("indicator.movingAverageChannel.title","Moving Average Channel"),shortTitle:(0,n.ab)("indicator.movingAverageChannel.shortTitle","MAC"),overlay:!0,inputs:[aI(20,"upperLength",(0,n.ab)("indicator.movingAverageChannel.upperLength","Upper Length"),5e3,(0,n.ab)("indicator.movingAverageChannel.upperLength.tooltip","Number of bars in the simple moving average of the highs.")),aI(20,"lowerLength",(0,n.ab)("indicator.movingAverageChannel.lowerLength","Lower Length"),5e3,(0,n.ab)("indicator.movingAverageChannel.lowerLength.tooltip","Number of bars in the simple moving average of the lows.")),aE("upperOffset",(0,n.ab)("indicator.movingAverageChannel.upperOffset","Upper Offset"),0,-500,500,(0,n.ab)("indicator.movingAverageChannel.upperOffset.tooltip","Bars the upper line is displaced by. Positive values push it to the right.")),aE("lowerOffset",(0,n.ab)("indicator.movingAverageChannel.lowerOffset","Lower Offset"),0,-500,500,(0,n.ab)("indicator.movingAverageChannel.lowerOffset.tooltip","Bars the lower line is displaced by. Positive values push it to the right.")),az(r.TV,(0,n.ab)("indicator.movingAverageChannel.upperColor","Upper"),"upperColor",(0,n.ab)("indicator.movingAverageChannel.upperColor.tooltip","Color of the upper channel line.")),az(r.cr,(0,n.ab)("indicator.movingAverageChannel.lowerColor","Lower"),"lowerColor",(0,n.ab)("indicator.movingAverageChannel.lowerColor.tooltip","Color of the lower channel line.")),az(aD(r.qm,92),(0,n.ab)("indicator.movingAverageChannel.fillColor","Fill"),"fillColor",(0,n.ab)("indicator.movingAverageChannel.fillColor.tooltip","Color of the channel interior fill."))],compute:(e,t)=>({plots:[{key:"upper",title:(0,n.ab)("indicator.movingAverageChannel.plot.upper","Upper"),values:ag(ar(n6(e),n_(t,"upperLength",20)),Math.trunc(n_(t,"upperOffset",0))),color:nQ(t,"upperColor",r.TV)},{key:"lower",title:(0,n.ab)("indicator.movingAverageChannel.plot.lower","Lower"),values:ag(ar(n8(e),n_(t,"lowerLength",20)),Math.trunc(n_(t,"lowerOffset",0))),color:nQ(t,"lowerColor",r.cr)}],bands:[{key:"mac",from:"upper",to:"lower",color:nQ(t,"fillColor",aD(r.qm,92))}]})},sI={type:"standard-error-bands",title:(0,n.ab)("indicator.standardErrorBands.title","Standard Error Bands"),shortTitle:(0,n.ab)("indicator.standardErrorBands.shortTitle","SEB"),overlay:!0,inputs:[{...aI(21,"length",(0,n.ab)("indicator.standardErrorBands.length","Length"),5e3,(0,n.ab)("indicator.standardErrorBands.length.tooltip","Number of bars used to fit the linear regression and compute its standard error.")),min:3},aB("mult",(0,n.ab)("indicator.standardErrorBands.mult","SE Multiplier"),2,0,50,.1,(0,n.ab)("indicator.standardErrorBands.mult.tooltip","Multiple of the regression standard error used to offset the bands from the regression line.")),aI(3,"smoothing",(0,n.ab)("indicator.standardErrorBands.smoothing","Smoothing"),500,(0,n.ab)("indicator.standardErrorBands.smoothing.tooltip","Moving average length applied to the regression line and to its standard error. 1 leaves both unsmoothed.")),aO("smoothingType",(0,n.ab)("indicator.standardErrorBands.smoothingType","Smoothing Type"),"SMA",["SMA","EMA","WMA"],(0,n.ab)("indicator.standardErrorBands.smoothingType.tooltip","Moving average used for that smoothing.")),aR("Close","source",(0,n.ab)("indicator.standardErrorBands.source","Source"),(0,n.ab)("indicator.standardErrorBands.source.tooltip","Price series the regression is fitted to.")),az(r.qm,(0,n.ab)("indicator.standardErrorBands.basisColor","Regression Line"),"basisColor",(0,n.ab)("indicator.standardErrorBands.basisColor.tooltip","Color of the smoothed linear regression midline.")),az(r.TV,(0,n.ab)("indicator.standardErrorBands.upperColor","Upper Band"),"upperColor",(0,n.ab)("indicator.standardErrorBands.upperColor.tooltip","Color of the upper band and of the fill between it and the regression line.")),az(r.cr,(0,n.ab)("indicator.standardErrorBands.lowerColor","Lower Band"),"lowerColor",(0,n.ab)("indicator.standardErrorBands.lowerColor.tooltip","Color of the lower band and of the fill between it and the regression line."))],compute:(e,t)=>{let i=n_(t,"length",21),o=n3(e,nQ(t,"source","Close")),l=nQ(t,"smoothingType","SMA"),a=n_(t,"smoothing",3),s=e=>"EMA"===l?ad(e,a):"WMA"===l?al(e,a):ar(e,a),h=s(ay(o,i)),d=ae(s(aw(o,i)),e=>e*n_(t,"mult",2)),c=nQ(t,"upperColor",r.TV),p=nQ(t,"lowerColor",r.cr);return{plots:[{key:"basis",title:(0,n.ab)("indicator.standardErrorBands.plot.basis","Basis"),values:h,color:nQ(t,"basisColor",r.qm)},{key:"upper",title:(0,n.ab)("indicator.standardErrorBands.plot.upper","Upper Band"),values:n9(h,d,(e,t)=>e+t),color:c},{key:"lower",title:(0,n.ab)("indicator.standardErrorBands.plot.lower","Lower Band"),values:n9(h,d,(e,t)=>e-t),color:p}],bands:[{key:"sebUpper",from:"upper",to:"basis",color:aD(c,90)},{key:"sebLower",from:"basis",to:"lower",color:aD(p,90)}]}}},sE={type:"volatility-index",title:(0,n.ab)("indicator.volatilityIndex.title","Volatility Index"),shortTitle:(0,n.ab)("indicator.volatilityIndex.shortTitle","Vol Index"),overlay:!0,inputs:[aI(10,"length",(0,n.ab)("indicator.volatilityIndex.length","Length"),5e3,(0,n.ab)("indicator.volatilityIndex.length.tooltip","Number of bars in the average true range.")),aB("mult",(0,n.ab)("indicator.volatilityIndex.mult","ATR Multiplier"),3,0,50,.1,(0,n.ab)("indicator.volatilityIndex.mult.tooltip","Multiple of the average true range the stop keeps from the most favorable close.")),aO("smoothing",(0,n.ab)("indicator.volatilityIndex.smoothing","Smoothing"),"RMA",["RMA","EMA"],(0,n.ab)("indicator.volatilityIndex.smoothing.tooltip","Average applied to the true range. RMA is Wilder's own smoothing; EMA reacts faster.")),az(r.cr,(0,n.ab)("indicator.volatilityIndex.longColor","Long Stop"),"longColor",(0,n.ab)("indicator.volatilityIndex.longColor.tooltip","Color of the stop while it trails below price.")),az(r.TV,(0,n.ab)("indicator.volatilityIndex.shortColor","Short Stop"),"shortColor",(0,n.ab)("indicator.volatilityIndex.shortColor.tooltip","Color of the stop while it sits above price."))],compute:(e,t)=>{let i=n_(t,"length",10),o=n_(t,"mult",3),l="EMA"===nQ(t,"smoothing","RMA")?2/(i+1):1/i,a=am(e),s=e.length,h=Array(s).fill(NaN),d=Array(s).fill(NaN),c=!0,p=NaN,u=NaN,g=0,m=0;for(let t=0;t<s;t++){let r=e[t].close;if(t>0&&r===e[t-1].close){h[t]=h[t-1],d[t]=d[t-1];continue}let n=c?p-o*u:p+o*u;Number.isFinite(n)&&((c?h:d)[t]=n),Number.isFinite(u)?u+=l*(a[t]-u):(g+=a[t],(m+=1)>=i&&(u=g/i)),Number.isFinite(n)&&(c?r<n:r>n)?(c=!c,p=r):p=Number.isFinite(p)?c?Math.max(p,r):Math.min(p,r):r}return{plots:[{key:"long",title:(0,n.ab)("indicator.volatilityIndex.plot.long","Long Stop"),values:h,color:nQ(t,"longColor",r.cr)},{key:"short",title:(0,n.ab)("indicator.volatilityIndex.plot.short","Short Stop"),values:d,color:nQ(t,"shortColor",r.TV)}]}}},sB={type:"chandelier-exit",title:(0,n.ab)("indicator.chandelierExit.title","Chandelier Exit"),shortTitle:(0,n.ab)("indicator.chandelierExit.shortTitle","CE"),overlay:!0,inputs:[aI(22,"length",(0,n.ab)("indicator.chandelierExit.length","Length"),5e3,(0,n.ab)("indicator.chandelierExit.length.tooltip","Lookback used for both the highest high / lowest low extremes and the ATR.")),aB("mult",(0,n.ab)("indicator.chandelierExit.mult","ATR Multiplier"),3,0,50,.1,(0,n.ab)("indicator.chandelierExit.mult.tooltip","Multiple of ATR subtracted from the highest high (long stop) and added to the lowest low (short stop).")),aF("ratchet",(0,n.ab)("indicator.chandelierExit.ratchet","Ratchet Stops"),!1,void 0,(0,n.ab)("indicator.chandelierExit.ratchet.tooltip","Prevents the long stop from falling and the short stop from rising, resetting once close crosses through the stop.")),az(r.cr,(0,n.ab)("indicator.chandelierExit.longColor","Long Stop"),"longColor",(0,n.ab)("indicator.chandelierExit.longColor.tooltip","Color of the long trailing stop line.")),az(r.TV,(0,n.ab)("indicator.chandelierExit.shortColor","Short Stop"),"shortColor",(0,n.ab)("indicator.chandelierExit.shortColor.tooltip","Color of the short trailing stop line."))],compute:(e,t)=>{let i=n_(t,"length",22),o=ae(ab(e,i),e=>e*n_(t,"mult",3)),l=n9(aa(n6(e),i),o,(e,t)=>e-t),a=n9(as(n8(e),i),o,(e,t)=>e+t),s=l,h=a;if(nJ(t,"ratchet",!1)){s=Array(e.length).fill(NaN),h=Array(e.length).fill(NaN);for(let t=0;t<e.length;t++){let i=l[t],o=a[t],r=t>0?e[t-1].close:e[t].close,n=t>0&&Number.isFinite(s[t-1])?s[t-1]:i,d=t>0&&Number.isFinite(h[t-1])?h[t-1]:o;s[t]=Number.isFinite(i)?r>n?Math.max(i,n):i:NaN,h[t]=Number.isFinite(o)?r<d?Math.min(o,d):o:NaN}}return{plots:[{key:"long",title:(0,n.ab)("indicator.chandelierExit.plot.long","Long Stop"),values:s,color:nQ(t,"longColor",r.cr)},{key:"short",title:(0,n.ab)("indicator.chandelierExit.plot.short","Short Stop"),values:h,color:nQ(t,"shortColor",r.TV)}]}}},sF={type:"chande-kroll-stop",title:(0,n.ab)("indicator.chandeKrollStop.title","Chande Kroll Stop"),shortTitle:(0,n.ab)("indicator.chandeKrollStop.shortTitle","CKS"),overlay:!0,inputs:[aE("p",(0,n.ab)("indicator.chandeKrollStop.p","ATR Length (P)"),10,1,5e3,(0,n.ab)("indicator.chandeKrollStop.p.tooltip","Lookback used for both the ATR and the highest high / lowest low price extremes.")),aB("x",(0,n.ab)("indicator.chandeKrollStop.x","ATR Multiplier (X)"),1,0,50,.1,(0,n.ab)("indicator.chandeKrollStop.x.tooltip","Multiplier applied to the ATR to offset the preliminary stops from the price extremes.")),aE("q",(0,n.ab)("indicator.chandeKrollStop.q","Stop Length (Q)"),9,1,5e3,(0,n.ab)("indicator.chandeKrollStop.q.tooltip","Lookback over which the preliminary stops are extended into the final stop levels.")),az(r.TV,(0,n.ab)("indicator.chandeKrollStop.shortColor","Short Stop"),"shortColor",(0,n.ab)("indicator.chandeKrollStop.shortColor.tooltip","Color of the protective stop line for short positions.")),az(r.cr,(0,n.ab)("indicator.chandeKrollStop.longColor","Long Stop"),"longColor",(0,n.ab)("indicator.chandeKrollStop.longColor.tooltip","Color of the protective stop line for long positions."))],compute:(e,t)=>{let i=n_(t,"p",10),o=n_(t,"q",9),l=ae(ab(e,i),e=>e*n_(t,"x",1)),a=n9(aa(n6(e),i),l,(e,t)=>e-t),s=n9(as(n8(e),i),l,(e,t)=>e+t);return{plots:[{key:"stopShort",title:"Stop Short",displayTitle:(0,n.ab)("indicator.chandeKrollStop.plot.stopShort","Short Stop"),values:aa(a,o),color:nQ(t,"shortColor",r.TV)},{key:"stopLong",title:"Stop Long",displayTitle:(0,n.ab)("indicator.chandeKrollStop.plot.stopLong","Long Stop"),values:as(s,o),color:nQ(t,"longColor",r.cr)}]}}},sO={type:"supertrend",title:(0,n.ab)("indicator.supertrend.title","SuperTrend"),shortTitle:(0,n.ab)("indicator.supertrend.shortTitle","SuperTrend"),overlay:!0,inputs:[aE("atrLength",(0,n.ab)("indicator.supertrend.atrLength","ATR Length"),10,1,5e3,(0,n.ab)("indicator.supertrend.atrLength.tooltip","Number of bars used to compute the Wilder ATR.")),aB("mult",(0,n.ab)("indicator.supertrend.mult","Factor"),3,0,50,.1,(0,n.ab)("indicator.supertrend.mult.tooltip","ATR multiplier setting how far the trailing stop sits from the bar midpoint.")),az(r.cr,(0,n.ab)("indicator.supertrend.upColor","Uptrend Color"),"upColor",(0,n.ab)("indicator.supertrend.upColor.tooltip","Line color while the trend is up.")),az(r.TV,(0,n.ab)("indicator.supertrend.downColor","Downtrend Color"),"downColor",(0,n.ab)("indicator.supertrend.downColor.tooltip","Line color while the trend is down."))],compute:(e,t)=>{let i=n_(t,"mult",3),o=ab(e,n_(t,"atrLength",10)),l=e.length,a=Array(l).fill(NaN),s=Array(l).fill(NaN),h=NaN,d=NaN,c=-1;for(let t=0;t<l;t++){let r=o[t];if(!Number.isFinite(r))continue;let l=e[t],n=(l.high+l.low)/2,p=n+i*r,u=n-i*r,g=Number.isFinite(h)?h:p,m=Number.isFinite(d)?d:u,b=t>0?e[t-1].close:l.close;h=b<=g?Math.min(p,g):p,d=b>=m?Math.max(u,m):u,1===(c=l.close>h?1:l.close<d?-1:c)?a[t]=d:s[t]=h}return{plots:[{key:"up",title:(0,n.ab)("indicator.supertrend.plot.up","Uptrend"),values:a,color:nQ(t,"upColor",r.cr)},{key:"down",title:(0,n.ab)("indicator.supertrend.plot.down","Downtrend"),values:s,color:nQ(t,"downColor",r.TV)}]}}},sR={type:"williams-alligator",title:(0,n.ab)("indicator.williamsAlligator.title","Williams Alligator"),shortTitle:(0,n.ab)("indicator.williamsAlligator.shortTitle","Alligator"),overlay:!0,inputs:[aE("jawLength",(0,n.ab)("indicator.williamsAlligator.jawLength","Jaw Length"),13,1,5e3,(0,n.ab)("indicator.williamsAlligator.jawLength.tooltip","Smoothing length of the Jaw SMMA of median price (hl2), 13 in the classic setup.")),aE("teethLength",(0,n.ab)("indicator.williamsAlligator.teethLength","Teeth Length"),8,1,5e3,(0,n.ab)("indicator.williamsAlligator.teethLength.tooltip","Smoothing length of the Teeth SMMA of median price (hl2), 8 in the classic setup.")),aE("lipsLength",(0,n.ab)("indicator.williamsAlligator.lipsLength","Lips Length"),5,1,5e3,(0,n.ab)("indicator.williamsAlligator.lipsLength.tooltip","Smoothing length of the Lips SMMA of median price (hl2), 5 in the classic setup.")),aE("jawOffset",(0,n.ab)("indicator.williamsAlligator.jawOffset","Jaw Offset"),8,0,100,(0,n.ab)("indicator.williamsAlligator.jawOffset.tooltip","Number of bars the Jaw plot is shifted into the future, 8 in the classic setup.")),aE("teethOffset",(0,n.ab)("indicator.williamsAlligator.teethOffset","Teeth Offset"),5,0,100,(0,n.ab)("indicator.williamsAlligator.teethOffset.tooltip","Number of bars the Teeth plot is shifted into the future, 5 in the classic setup.")),aE("lipsOffset",(0,n.ab)("indicator.williamsAlligator.lipsOffset","Lips Offset"),3,0,100,(0,n.ab)("indicator.williamsAlligator.lipsOffset.tooltip","Number of bars the Lips plot is shifted into the future, 3 in the classic setup.")),az(sf,(0,n.ab)("indicator.williamsAlligator.jawColor","Jaw"),"jawColor",(0,n.ab)("indicator.williamsAlligator.jawColor.tooltip","Color of the Jaw line.")),az(sv,(0,n.ab)("indicator.williamsAlligator.teethColor","Teeth"),"teethColor",(0,n.ab)("indicator.williamsAlligator.teethColor.tooltip","Color of the Teeth line.")),az(sy,(0,n.ab)("indicator.williamsAlligator.lipsColor","Lips"),"lipsColor",(0,n.ab)("indicator.williamsAlligator.lipsColor.tooltip","Color of the Lips line."))],compute:(e,t)=>{let i=n3(e,"HL2"),o=ag(ac(i,n_(t,"jawLength",13)),n_(t,"jawOffset",8)),r=ag(ac(i,n_(t,"teethLength",8)),n_(t,"teethOffset",5)),l=ag(ac(i,n_(t,"lipsLength",5)),n_(t,"lipsOffset",3));return{plots:[{key:"jaw",title:(0,n.ab)("indicator.williamsAlligator.plot.jaw","Jaw"),values:o,color:nQ(t,"jawColor",sf)},{key:"teeth",title:(0,n.ab)("indicator.williamsAlligator.plot.teeth","Teeth"),values:r,color:nQ(t,"teethColor",sv)},{key:"lips",title:(0,n.ab)("indicator.williamsAlligator.plot.lips","Lips"),values:l,color:nQ(t,"lipsColor",sy)}]}}},sN="Alligator Lines",sz="SMMA (Wilder)",sV={type:"gator-oscillator",title:(0,n.ab)("indicator.gatorOscillator.title","Gator Oscillator"),shortTitle:(0,n.ab)("indicator.gatorOscillator.shortTitle","Gator Oscillator"),overlay:!1,inputs:[{...aR("HL2","source",(0,n.ab)("indicator.gatorOscillator.source","Source"),(0,n.ab)("indicator.gatorOscillator.source.tooltip","Price series fed to the three Alligator averages. Bill Williams' original recipe uses the median price (high + low) / 2.")),group:sN},{...aO("maType",(0,n.ab)("indicator.gatorOscillator.maType","Smoothing"),sz,[sz,"SMA","EMA"],(0,n.ab)("indicator.gatorOscillator.maType.tooltip","Moving average applied to the source for the jaw, teeth and lips. The original uses the smoothed (Wilder-style) moving average.")),group:sN},{...aE("jawLength",(0,n.ab)("indicator.gatorOscillator.jawLength","Jaw Length"),13,1,500,(0,n.ab)("indicator.gatorOscillator.jawLength.tooltip","Averaging length of the jaw line.")),group:sN},{...aE("jawOffset",(0,n.ab)("indicator.gatorOscillator.jawOffset","Jaw Offset"),8,0,100,(0,n.ab)("indicator.gatorOscillator.jawOffset.tooltip","Bars the jaw is displaced forward, 8 in the original recipe. The upper histogram measures the absolute spread between the displaced jaw and teeth.")),group:sN},{...aE("teethLength",(0,n.ab)("indicator.gatorOscillator.teethLength","Teeth Length"),8,1,500,(0,n.ab)("indicator.gatorOscillator.teethLength.tooltip","Averaging length of the teeth line.")),group:sN},{...aE("teethOffset",(0,n.ab)("indicator.gatorOscillator.teethOffset","Teeth Offset"),5,0,100,(0,n.ab)("indicator.gatorOscillator.teethOffset.tooltip","Bars the teeth are displaced forward, 5 in the original recipe. The teeth line enters both spreads.")),group:sN},{...aE("lipsLength",(0,n.ab)("indicator.gatorOscillator.lipsLength","Lips Length"),5,1,500,(0,n.ab)("indicator.gatorOscillator.lipsLength.tooltip","Averaging length of the lips line.")),group:sN},{...aE("lipsOffset",(0,n.ab)("indicator.gatorOscillator.lipsOffset","Lips Offset"),3,0,100,(0,n.ab)("indicator.gatorOscillator.lipsOffset.tooltip","Bars the lips are displaced forward, 3 in the original recipe. The lower histogram measures the negative absolute spread between the displaced teeth and lips.")),group:sN},az(r.cr,(0,n.ab)("indicator.gatorOscillator.growColor","Expanding"),"growColor",(0,n.ab)("indicator.gatorOscillator.growColor.tooltip","Column color while a spread grew against its own previous bar — the averages are spreading apart.")),az(r.TV,(0,n.ab)("indicator.gatorOscillator.shrinkColor","Contracting"),"shrinkColor",(0,n.ab)("indicator.gatorOscillator.shrinkColor.tooltip","Column color while a spread shrank — the averages are converging. Color encodes expansion, not trade direction.")),az(r.qm,(0,n.ab)("indicator.gatorOscillator.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.gatorOscillator.zeroColor.tooltip","Color of the zero line separating the two histograms."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","HL2")),o=nQ(t,"maType",sz),l=e=>"SMA"===o?ar(i,e):"EMA"===o?ad(i,e):ac(i,e),a=ag(l(n_(t,"jawLength",13)),n_(t,"jawOffset",8)),s=ag(l(n_(t,"teethLength",8)),n_(t,"teethOffset",5)),h=ag(l(n_(t,"lipsLength",5)),n_(t,"lipsOffset",3)),d=ae(at(a,s),Math.abs),c=ae(at(s,h),Math.abs),p=nQ(t,"growColor",r.cr),u=nQ(t,"shrinkColor",r.TV),g=e=>{let t=!1;return e.map((i,o)=>{if(!Number.isFinite(i))return null;let r=o>0?e[o-1]:NaN;return Number.isFinite(r)&&(t=i>r||!(i<r)&&t),t?p:u})};return{plots:[{key:"upper",title:"Upper Histogram (Jaw - Teeth)",displayTitle:(0,n.ab)("indicator.gatorOscillator.plot.upper","Upper Histogram (Jaw − Teeth)"),values:d,kind:"columns",color:p,colors:g(d),base:0},{key:"lower",title:"Lower Histogram (Teeth - Lips)",displayTitle:(0,n.ab)("indicator.gatorOscillator.plot.lower","Lower Histogram (Teeth − Lips)"),values:ae(c,e=>-e),kind:"columns",color:u,colors:g(c),base:0}],levels:[{key:"zero",price:0,color:nQ(t,"zeroColor",r.qm),lineStyle:"solid",title:(0,n.ab)("indicator.gatorOscillator.level.zero","Zero Line")}]}}};function sD(e,t,i=0,o=100,r=(0,n.ab)("indicator.threshold.overbought","Overbought Level"),l=(0,n.ab)("indicator.threshold.oversold","Oversold Level"),a=1){return[aB("overbought",r,e,i,o,a,(0,n.ab)("indicator.threshold.overbought.tooltip","Level above which the oscillator is considered overbought.")),aB("oversold",l,t,i,o,a,(0,n.ab)("indicator.threshold.oversold.tooltip","Level below which the oscillator is considered oversold."))]}function s$(e,t,i){return e.map((o,r)=>{if(!Number.isFinite(o))return null;let l=r>0?e[r-1]:NaN;return Number.isFinite(l)&&o>l?t:i})}var sH={type:"rsi",title:(0,n.ab)("indicator.rsi.title","Relative Strength Index"),shortTitle:(0,n.ab)("indicator.rsi.shortTitle","RSI"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.rsi.length","Length"),5e3,(0,n.ab)("indicator.rsi.length.tooltip","Number of bars used in the Wilder smoothing of average gains and losses.")),aR("Close","source",(0,n.ab)("indicator.rsi.source","Source"),(0,n.ab)("indicator.rsi.source.tooltip","Price series the RSI is calculated on.")),...sD(70,30,0,100,(0,n.ab)("indicator.rsi.overbought","Overbought"),(0,n.ab)("indicator.rsi.oversold","Oversold")),az(r.qm,(0,n.ab)("indicator.rsi.color","RSI"),"color",(0,n.ab)("indicator.rsi.color.tooltip","Color of the RSI line at the midline. Toward either threshold it blends into that threshold’s color.")),az(r.cr,(0,n.ab)("indicator.rsi.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.rsi.oversoldColor.tooltip","Color of the line and zone shading at and below the oversold level.")),az(r.TV,(0,n.ab)("indicator.rsi.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.rsi.overboughtColor.tooltip","Color of the line and zone shading at and above the overbought level.")),az(r.qm,(0,n.ab)("indicator.rsi.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.rsi.levelsColor.tooltip","Color of the overbought, midline and oversold levels.")),az(aD(r.qm,90),(0,n.ab)("indicator.rsi.fillColor","Band Fill"),"fillColor",(0,n.ab)("indicator.rsi.fillColor.tooltip","Color of the fill between the overbought and oversold levels."))],compute:(e,t)=>aj({key:"rsi",title:(0,n.ab)("indicator.rsi.plot.rsi","RSI"),values:af(n3(e,nQ(t,"source","Close")),n_(t,"length",14)),scale:{top:100,bottom:0},overbought:n_(t,"overbought",70),oversold:n_(t,"oversold",30),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:nQ(t,"levelsColor",r.qm),width:2,midline:50,bandFill:nQ(t,"fillColor",aD(r.qm,90))})};function sW(e,t,i){let o=n_(i,"overbought",80),l=n_(i,"oversold",20);return{plots:[{key:"k",title:(0,n.ab)("indicator.stochastic.plot.k","%K"),values:e,color:nQ(i,"kColor",r.rD)},{key:"d",title:(0,n.ab)("indicator.stochastic.plot.d","%D"),values:t,color:nQ(i,"dColor",r.Nz)},aW("obAnchor","Overbought Anchor",e.length,o),aW("osAnchor","Oversold Anchor",e.length,l)],bands:[{key:"band",from:"obAnchor",to:"osAnchor",color:nQ(i,"fillColor",aD(r.rD,90))}],levels:[{key:"overbought",price:o,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.common.level.overbought","Overbought")},{key:"oversold",price:l,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.common.level.oversold","Oversold")}]}}var sq={type:"stochastic",title:(0,n.ab)("indicator.stochastic.title","Stochastic"),shortTitle:(0,n.ab)("indicator.stochastic.shortTitle","Stoch"),overlay:!1,inputs:[aI(14,"kLength",(0,n.ab)("indicator.stochastic.kLength","%K Length"),5e3,(0,n.ab)("indicator.stochastic.kLength.tooltip","Number of bars used for the highest high / lowest low range of the raw %K.")),aI(3,"kSmoothing",(0,n.ab)("indicator.stochastic.kSmoothing","%K Smoothing"),500,(0,n.ab)("indicator.stochastic.kSmoothing.tooltip","Simple moving average length applied to the raw %K. 1 gives the fast stochastic, 3 the classic slow stochastic.")),aI(3,"dLength",(0,n.ab)("indicator.stochastic.dLength","%D Smoothing"),500,(0,n.ab)("indicator.stochastic.dLength.tooltip","Simple moving average length of the %D signal line, applied to the smoothed %K.")),...sD(80,20),az(r.rD,(0,n.ab)("indicator.stochastic.kColor","%K"),"kColor",(0,n.ab)("indicator.stochastic.kColor.tooltip","Color of the %K line.")),az(r.Nz,(0,n.ab)("indicator.stochastic.dColor","%D"),"dColor",(0,n.ab)("indicator.stochastic.dColor.tooltip","Color of the %D signal line.")),az(aD(r.rD,90),(0,n.ab)("indicator.stochastic.fillColor","Band Fill"),"fillColor",(0,n.ab)("indicator.stochastic.fillColor.tooltip","Fill color of the area between the overbought and oversold levels."))],compute:(e,t)=>{let i=ar(av(n7(e),n6(e),n8(e),n_(t,"kLength",14)),n_(t,"kSmoothing",3));return sW(i,ar(i,n_(t,"dLength",3)),t)}},sU={type:"stochastic-rsi",title:(0,n.ab)("indicator.stochasticRsi.title","Stochastic RSI"),shortTitle:(0,n.ab)("indicator.stochasticRsi.shortTitle","Stoch RSI"),overlay:!1,inputs:[aR("Close","source",(0,n.ab)("indicator.stochasticRsi.source","RSI Source"),(0,n.ab)("indicator.stochasticRsi.source.tooltip","Price series the RSI is computed on.")),aI(14,"rsiLength",(0,n.ab)("indicator.stochasticRsi.rsiLength","RSI Length"),5e3,(0,n.ab)("indicator.stochasticRsi.rsiLength.tooltip","Lookback length of the Wilder RSI.")),aI(14,"stochLength",(0,n.ab)("indicator.stochasticRsi.stochLength","Stochastic Length"),5e3,(0,n.ab)("indicator.stochasticRsi.stochLength.tooltip","Lookback over which the highest and lowest RSI values are taken.")),aI(3,"kSmoothing",(0,n.ab)("indicator.stochasticRsi.kSmoothing","%K Smoothing"),500,(0,n.ab)("indicator.stochasticRsi.kSmoothing.tooltip","Simple moving average length applied to the stochastic of RSI to form %K.")),aI(3,"dLength",(0,n.ab)("indicator.stochasticRsi.dLength","%D Smoothing"),500,(0,n.ab)("indicator.stochasticRsi.dLength.tooltip","Simple moving average length applied to %K to form the %D signal line.")),...sD(80,20),az(r.rD,(0,n.ab)("indicator.stochasticRsi.kColor","%K Color"),"kColor",(0,n.ab)("indicator.stochasticRsi.kColor.tooltip","Color of the %K line.")),az(r.Nz,(0,n.ab)("indicator.stochasticRsi.dColor","%D Color"),"dColor",(0,n.ab)("indicator.stochasticRsi.dColor.tooltip","Color of the %D signal line.")),az(aD(r.rD,90),(0,n.ab)("indicator.stochasticRsi.fillColor","Zone Fill"),"fillColor",(0,n.ab)("indicator.stochasticRsi.fillColor.tooltip","Fill color of the area between the overbought and oversold levels."))],compute:(e,t)=>{let i=af(n3(e,nQ(t,"source","Close")),n_(t,"rsiLength",14)),o=ar(av(i,i,i,n_(t,"stochLength",14)),n_(t,"kSmoothing",3));return sW(o,ar(o,n_(t,"dLength",3)),t)}},sj={type:"macd",title:(0,n.ab)("indicator.macd.title","MACD"),overlay:!1,inputs:[aI(12,"fastLength",(0,n.ab)("indicator.macd.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.macd.fastLength.tooltip","Length of the fast EMA.")),aI(26,"slowLength",(0,n.ab)("indicator.macd.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.macd.slowLength.tooltip","Length of the slow EMA.")),aI(9,"signalLength",(0,n.ab)("indicator.macd.signalLength","Signal Smoothing"),500,(0,n.ab)("indicator.macd.signalLength.tooltip","Length of the EMA applied to the MACD line to obtain the signal line.")),aR("Close","source",(0,n.ab)("indicator.macd.source","Source"),(0,n.ab)("indicator.macd.source.tooltip","Price series used to compute the fast and slow EMAs.")),az(r.rD,(0,n.ab)("indicator.macd.color","MACD Line"),"color",(0,n.ab)("indicator.macd.color.tooltip","Color of the MACD line.")),az(r.Nz,(0,n.ab)("indicator.macd.signalColor","Signal Line"),"signalColor",(0,n.ab)("indicator.macd.signalColor.tooltip","Color of the signal line.")),az(r.cr,(0,n.ab)("indicator.macd.growAboveColor","Grow Above"),"growAboveColor",(0,n.ab)("indicator.macd.growAboveColor.tooltip","Histogram color when above zero and rising.")),az(aD(r.cr,50),(0,n.ab)("indicator.macd.fallAboveColor","Fall Above"),"fallAboveColor",(0,n.ab)("indicator.macd.fallAboveColor.tooltip","Histogram color when above zero and falling.")),az(aD(r.TV,50),(0,n.ab)("indicator.macd.growBelowColor","Grow Below"),"growBelowColor",(0,n.ab)("indicator.macd.growBelowColor.tooltip","Histogram color when below zero and rising.")),az(r.TV,(0,n.ab)("indicator.macd.fallBelowColor","Fall Below"),"fallBelowColor",(0,n.ab)("indicator.macd.fallBelowColor.tooltip","Histogram color when below zero and falling."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=at(ad(i,n_(t,"fastLength",12)),ad(i,n_(t,"slowLength",26))),l=ad(o,n_(t,"signalLength",9)),a=at(o,l),s=function(e,t){return e.map((i,o)=>{if(!Number.isFinite(i))return null;let r=o>0&&Number.isFinite(e[o-1])?e[o-1]:i,l=i>r;return i>=0?l?t.growAbove:t.fallAbove:l?t.growBelow:t.fallBelow})}(a,{growAbove:nQ(t,"growAboveColor",r.cr),fallAbove:nQ(t,"fallAboveColor",aD(r.cr,50)),growBelow:nQ(t,"growBelowColor",aD(r.TV,50)),fallBelow:nQ(t,"fallBelowColor",r.TV)});return{plots:[{key:"hist",title:(0,n.ab)("indicator.macd.plot.hist","Histogram"),values:a,kind:"columns",color:r.cr,colors:s,base:0},{key:"macd",title:(0,n.ab)("indicator.macd.plot.macd","MACD"),values:o,color:nQ(t,"color",r.rD)},{key:"signal",title:(0,n.ab)("indicator.macd.plot.signal","Signal"),values:l,color:nQ(t,"signalColor",r.Nz)}],levels:[{key:"zero",price:0,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.macd.level.zero","Zero Line")}]}}},sG={type:"ppo",title:(0,n.ab)("indicator.ppo.title","Percentage Price Oscillator"),shortTitle:(0,n.ab)("indicator.ppo.shortTitle","PPO"),overlay:!1,inputs:[aR("Close","source",(0,n.ab)("indicator.ppo.source","Source"),(0,n.ab)("indicator.ppo.source.tooltip","Price series fed into the fast and slow averages.")),aI(12,"fastLength",(0,n.ab)("indicator.ppo.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.ppo.fastLength.tooltip","Length of the fast moving average.")),aI(26,"slowLength",(0,n.ab)("indicator.ppo.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.ppo.slowLength.tooltip","Length of the slow moving average. The spread is divided by it and scaled to a percentage of price.")),aO("maType",(0,n.ab)("indicator.ppo.maType","Average Type"),"EMA",["EMA","SMA"],(0,n.ab)("indicator.ppo.maType.tooltip","Moving average type used for the fast and slow averages.")),aI(9,"signalLength",(0,n.ab)("indicator.ppo.signalLength","Signal Smoothing"),500,(0,n.ab)("indicator.ppo.signalLength.tooltip","Length of the signal line that smooths the PPO line.")),aO("signalType",(0,n.ab)("indicator.ppo.signalType","Signal Type"),"EMA",["EMA","SMA"],(0,n.ab)("indicator.ppo.signalType.tooltip","Moving average type used for the signal line.")),az(r.cr,(0,n.ab)("indicator.ppo.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.ppo.bullColor.tooltip","Color of the PPO line, gradient fill and histogram above the zero line.")),az(r.TV,(0,n.ab)("indicator.ppo.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.ppo.bearColor.tooltip","Color of the PPO line, gradient fill and histogram below the zero line.")),az(r.Nz,(0,n.ab)("indicator.ppo.signalColor","Signal Line"),"signalColor",(0,n.ab)("indicator.ppo.signalColor.tooltip","Color of the signal line.")),aF("showHistogram",(0,n.ab)("indicator.ppo.showHistogram","Show Histogram"),!0,aP,(0,n.ab)("indicator.ppo.showHistogram.tooltip","Displays the histogram (PPO minus signal line) as columns. Bright columns mark a spread still widening, faded ones a spread narrowing back.")),aF("gradientFill",(0,n.ab)("indicator.ppo.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.ppo.gradientFill.tooltip","Fills the area between the zero line and the PPO line with a vertical gradient."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=(e,t,i)=>"SMA"===e?ar(t,i):ad(t,i),l=nQ(t,"maType","EMA"),a=n9(o(l,i,n_(t,"fastLength",12)),o(l,i,n_(t,"slowLength",26)),(e,t)=>0===t?NaN:(e-t)/t*100),s=o(nQ(t,"signalType","EMA"),a,n_(t,"signalLength",9)),h=at(a,s),d=nQ(t,"bullColor",r.cr),c=nQ(t,"bearColor",r.TV),p=aG({key:"ppo",title:(0,n.ab)("indicator.ppo.plot.ppo","PPO Line"),values:a,ink:{bull:d,bear:c,neutral:c},zeroInk:aD(r.qm,90),fill:nJ(t,"gradientFill",!0),extraPlots:[{key:"signal",title:(0,n.ab)("indicator.ppo.plot.signal","Signal Line"),values:s,color:nQ(t,"signalColor",r.Nz)}]});if(nJ(t,"showHistogram",!0)){let e=h.map((e,t)=>{if(!Number.isFinite(e))return null;let i=t>0&&Number.isFinite(h[t-1])?h[t-1]:e;return aD(e>=0?d:c,(e>=0?e>i:e<i)?40:70)});p.plots.unshift({key:"hist",title:(0,n.ab)("indicator.ppo.plot.hist","Histogram"),values:h,kind:"columns",color:d,colors:e,base:0})}return p}};function sK(e){let t=n3(e,"HL2");return at(ar(t,5),ar(t,34))}var sY={type:"awesome-oscillator",title:(0,n.ab)("indicator.awesomeOscillator.title","Awesome Oscillator"),shortTitle:(0,n.ab)("indicator.awesomeOscillator.shortTitle","AO"),overlay:!1,inputs:[az(r.cr,(0,n.ab)("indicator.awesomeOscillator.risingColor","Rising"),"risingColor",(0,n.ab)("indicator.awesomeOscillator.risingColor.tooltip","Histogram color when the oscillator is higher than on the previous bar.")),az(r.TV,(0,n.ab)("indicator.awesomeOscillator.fallingColor","Falling"),"fallingColor",(0,n.ab)("indicator.awesomeOscillator.fallingColor.tooltip","Histogram color when the oscillator is lower than or equal to the previous bar.")),az(r.qm,(0,n.ab)("indicator.awesomeOscillator.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.awesomeOscillator.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=sK(e),o=nQ(t,"risingColor",r.cr);return{plots:[{key:"ao",title:(0,n.ab)("indicator.awesomeOscillator.plot.ao","AO"),values:i,kind:"columns",color:o,colors:s$(i,o,nQ(t,"fallingColor",r.TV)),base:0}],levels:[{key:"zero",price:0,color:nQ(t,"zeroColor",r.qm),lineStyle:"dashed",title:(0,n.ab)("indicator.awesomeOscillator.level.zero","Zero Line")}]}}},sZ={type:"accelerator-oscillator",title:(0,n.ab)("indicator.acceleratorOscillator.title","Accelerator Oscillator"),shortTitle:(0,n.ab)("indicator.acceleratorOscillator.shortTitle","AC"),overlay:!1,inputs:[az(r.cr,(0,n.ab)("indicator.acceleratorOscillator.risingColor","Rising"),"risingColor",(0,n.ab)("indicator.acceleratorOscillator.risingColor.tooltip","Histogram color when the oscillator is higher than on the previous bar.")),az(r.TV,(0,n.ab)("indicator.acceleratorOscillator.fallingColor","Falling"),"fallingColor",(0,n.ab)("indicator.acceleratorOscillator.fallingColor.tooltip","Histogram color when the oscillator is lower than or equal to the previous bar.")),az(r.qm,(0,n.ab)("indicator.acceleratorOscillator.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.acceleratorOscillator.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=sK(e),o=at(i,ar(i,5)),l=nQ(t,"risingColor",r.cr);return{plots:[{key:"ac",title:(0,n.ab)("indicator.acceleratorOscillator.plot.ac","AC"),values:o,kind:"columns",color:l,colors:s$(o,l,nQ(t,"fallingColor",r.TV)),base:0}],levels:[{key:"zero",price:0,color:nQ(t,"zeroColor",r.qm),lineStyle:"dashed",title:(0,n.ab)("indicator.common.level.zero","Zero Line")}]}}},sX={type:"commodity-channel-index",title:(0,n.ab)("indicator.commodityChannelIndex.title","Commodity Channel Index"),shortTitle:(0,n.ab)("indicator.commodityChannelIndex.shortTitle","CCI"),overlay:!1,inputs:[aI(20,"length",(0,n.ab)("indicator.commodityChannelIndex.length","Length"),5e3,(0,n.ab)("indicator.commodityChannelIndex.length.tooltip","Number of bars used for the moving average and the mean absolute deviation of the source.")),aR("HLC3","source",(0,n.ab)("indicator.commodityChannelIndex.source","Source"),(0,n.ab)("indicator.commodityChannelIndex.source.tooltip","Price series measured by the CCI; the typical price hlc3 is the classic choice.")),aB("upper",(0,n.ab)("indicator.commodityChannelIndex.upper","Upper Level"),100,-1e3,1e3,10,(0,n.ab)("indicator.commodityChannelIndex.upper.tooltip","Overbought reference level, +100 classically.")),aB("lower",(0,n.ab)("indicator.commodityChannelIndex.lower","Lower Level"),-100,-1e3,1e3,10,(0,n.ab)("indicator.commodityChannelIndex.lower.tooltip","Oversold reference level, −100 classically.")),az(r.qm,(0,n.ab)("indicator.commodityChannelIndex.color","CCI Line"),"color",(0,n.ab)("indicator.commodityChannelIndex.color.tooltip","Color of the CCI line.")),az(r.cr,(0,n.ab)("indicator.commodityChannelIndex.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.commodityChannelIndex.bullColor.tooltip","Line and fill color while the CCI reads above zero.")),az(r.TV,(0,n.ab)("indicator.commodityChannelIndex.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.commodityChannelIndex.bearColor.tooltip","Line and fill color while the CCI reads below zero.")),az(r.qm,(0,n.ab)("indicator.commodityChannelIndex.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.commodityChannelIndex.levelsColor.tooltip","Color of the upper, lower and zero reference lines."))],compute:(e,t)=>{let i=n_(t,"length",20),o=n3(e,nQ(t,"source","HLC3")),l=ar(o,i),a=function(e,t){return ai(e,t,(e,i,o)=>{let r=0;for(let t=i;t<=o;t++)r+=e[t];let l=r/t,n=0;for(let t=i;t<=o;t++)n+=Math.abs(e[t]-l);return n/t})}(o,i),s=o.map((e,t)=>{let i=l[t],o=a[t];return Number.isFinite(i)&&Number.isFinite(o)?0===o?0:(e-i)/(.015*o):NaN}),h=nQ(t,"levelsColor",r.qm);return aG({key:"cci",title:(0,n.ab)("indicator.commodityChannelIndex.plot.cci","CCI"),values:s,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:h,zeroLineStyle:"dotted",extraLevels:[{key:"upper",price:n_(t,"upper",100),color:h,lineStyle:"dashed",title:(0,n.ab)("indicator.commodityChannelIndex.level.upper","Upper Level")},{key:"lower",price:n_(t,"lower",-100),color:h,lineStyle:"dashed",title:(0,n.ab)("indicator.commodityChannelIndex.level.lower","Lower Level")}]})}},s_={type:"williams-percent-r",title:(0,n.ab)("indicator.williamsPercentR.title","Williams %R"),shortTitle:(0,n.ab)("indicator.williamsPercentR.shortTitle","%R"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.williamsPercentR.length","Length"),5e3,(0,n.ab)("indicator.williamsPercentR.length.tooltip","Lookback length of the highest high / lowest low range. 14 is the classic setting.")),aR("Close","source",(0,n.ab)("indicator.williamsPercentR.source","Source"),(0,n.ab)("indicator.williamsPercentR.source.tooltip","Series located within the lookback range. Close is the classic choice.")),...sD(-20,-80,-100,0),az(r.qm,(0,n.ab)("indicator.williamsPercentR.color","%R Line"),"color",(0,n.ab)("indicator.williamsPercentR.color.tooltip","Color of the %R line between the levels. Toward either level it blends into that level’s color.")),az(r.TV,(0,n.ab)("indicator.williamsPercentR.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.williamsPercentR.overboughtColor.tooltip","Color of the line and zone shading at and above the overbought level.")),az(r.cr,(0,n.ab)("indicator.williamsPercentR.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.williamsPercentR.oversoldColor.tooltip","Color of the line and zone shading at and below the oversold level."))],compute:(e,t)=>{let i=n_(t,"length",14),o=n3(e,nQ(t,"source","Close")),l=aa(n6(e),i),a=as(n8(e),i),s=o.map((e,t)=>{let i=l[t],o=a[t];return Number.isFinite(i)&&Number.isFinite(o)&&i>o?-100*(i-e)/(i-o):NaN});return aj({key:"wr",title:(0,n.ab)("indicator.williamsPercentR.plot.wr","%R"),values:s,scale:{top:0,bottom:-100},overbought:n_(t,"overbought",-20),oversold:n_(t,"oversold",-80),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:r.qm})}},sQ={type:"chande-momentum-oscillator",title:(0,n.ab)("indicator.chandeMomentumOscillator.title","Chande Momentum Oscillator"),shortTitle:(0,n.ab)("indicator.chandeMomentumOscillator.shortTitle","CMO"),overlay:!1,inputs:[aI(9,"length",(0,n.ab)("indicator.chandeMomentumOscillator.length","Length"),5e3,(0,n.ab)("indicator.chandeMomentumOscillator.length.tooltip","Number of bars over which up moves and down moves are summed.")),aR("Close","source",(0,n.ab)("indicator.chandeMomentumOscillator.source","Source"),(0,n.ab)("indicator.chandeMomentumOscillator.source.tooltip","Price series used to measure bar-to-bar changes.")),aB("overbought",(0,n.ab)("indicator.chandeMomentumOscillator.overbought","Overbought Level"),50,0,100,1,(0,n.ab)("indicator.chandeMomentumOscillator.overbought.tooltip","Level above which the oscillator is considered overbought.")),aB("oversold",(0,n.ab)("indicator.chandeMomentumOscillator.oversold","Oversold Level"),-50,-100,0,1,(0,n.ab)("indicator.chandeMomentumOscillator.oversold.tooltip","Level below which the oscillator is considered oversold.")),az(r.qm,(0,n.ab)("indicator.chandeMomentumOscillator.color","CMO Line"),"color",(0,n.ab)("indicator.chandeMomentumOscillator.color.tooltip","Color of the CMO line.")),az(r.cr,(0,n.ab)("indicator.chandeMomentumOscillator.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.chandeMomentumOscillator.bullColor.tooltip","Line and fill color while momentum is positive, and shading of the oversold zone.")),az(r.TV,(0,n.ab)("indicator.chandeMomentumOscillator.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.chandeMomentumOscillator.bearColor.tooltip","Line and fill color while momentum is negative, and shading of the overbought zone.")),az(r.qm,(0,n.ab)("indicator.chandeMomentumOscillator.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.chandeMomentumOscillator.levelsColor.tooltip","Color of the overbought, oversold, and zero lines."))],compute:(e,t)=>{let i=n_(t,"length",9),o=ap(n3(e,nQ(t,"source","Close"))),l=n9(ao(ae(o,e=>Math.max(e,0)),i),ao(ae(o,e=>Math.max(-e,0)),i),(e,t)=>e+t===0?0:100*(e-t)/(e+t)),a=nQ(t,"bullColor",r.cr),s=nQ(t,"bearColor",r.TV),h=nQ(t,"levelsColor",r.qm),d=n_(t,"overbought",50),c=n_(t,"oversold",-50),p=aG({key:"cmo",title:(0,n.ab)("indicator.chandeMomentumOscillator.plot.cmo","CMO"),values:l,ink:{bull:a,bear:s,neutral:nQ(t,"color",r.qm)},zeroInk:h,zeroLineStyle:"dotted",extraLevels:[{key:"overbought",price:d,color:h,lineStyle:"dashed",title:(0,n.ab)("indicator.chandeMomentumOscillator.level.overbought","Overbought")},{key:"oversold",price:c,color:h,lineStyle:"dashed",title:(0,n.ab)("indicator.chandeMomentumOscillator.level.oversold","Oversold")}]}),u=aq(l.length,{overbought:d,oversold:c,top:100,bottom:-100},{overbought:s,oversold:a});return p.plots.push(...u.plots),p.bands=[...p.bands??[],...u.bands],p}},sJ={type:"connors-rsi",title:(0,n.ab)("indicator.connorsRsi.title","Connors RSI"),shortTitle:(0,n.ab)("indicator.connorsRsi.shortTitle","CRSI"),overlay:!1,inputs:[aI(3,"rsiLength",(0,n.ab)("indicator.connorsRsi.rsiLength","RSI Length"),5e3,(0,n.ab)("indicator.connorsRsi.rsiLength.tooltip","Length of the Wilder RSI applied to the closing price.")),aI(2,"streakLength",(0,n.ab)("indicator.connorsRsi.streakLength","Streak RSI Length"),5e3,(0,n.ab)("indicator.connorsRsi.streakLength.tooltip","Length of the Wilder RSI applied to the up/down close streak.")),aI(100,"rankLength",(0,n.ab)("indicator.connorsRsi.rankLength","Percent Rank Length"),5e3,(0,n.ab)("indicator.connorsRsi.rankLength.tooltip","Lookback of the percent rank applied to the 1-bar rate of change of the closing price.")),...sD(90,10),az(r.qm,(0,n.ab)("indicator.connorsRsi.color","CRSI Line"),"color",(0,n.ab)("indicator.connorsRsi.color.tooltip","Color of the Connors RSI line.")),az(r.cr,(0,n.ab)("indicator.connorsRsi.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.connorsRsi.oversoldColor.tooltip","Line, fill and zone color toward and below the oversold level.")),az(r.TV,(0,n.ab)("indicator.connorsRsi.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.connorsRsi.overboughtColor.tooltip","Line, fill and zone color toward and above the overbought level.")),az(r.qm,(0,n.ab)("indicator.connorsRsi.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.connorsRsi.levelsColor.tooltip","Color of the overbought and oversold levels."))],compute:(e,t)=>{let i=n7(e),o=Array(i.length).fill(0);for(let e=1;e<i.length;e++){let t=i[e]-i[e-1];o[e]=t>0?Math.max(o[e-1],0)+1:t<0?Math.min(o[e-1],0)-1:0}let l=af(i,n_(t,"rsiLength",3)),a=af(o,n_(t,"streakLength",2)),s=function(e,t){let i=Array(e.length).fill(NaN);for(let o=t;o<e.length;o++){let r=e[o];if(!Number.isFinite(r))continue;let l=0,n=0;for(let i=o-t;i<o;i++){let t=e[i];if(!Number.isFinite(t)){n=-1;break}n+=1,t<=r&&(l+=1)}n===t&&(i[o]=100*l/t)}return i}(au(i,1),n_(t,"rankLength",100)),h=i.map((e,t)=>{let i=l[t],o=a[t],r=s[t];return Number.isFinite(i)&&Number.isFinite(o)&&Number.isFinite(r)?(i+o+r)/3:NaN});return aj({key:"crsi",title:(0,n.ab)("indicator.connorsRsi.plot.crsi","Connors RSI"),values:h,scale:{top:100,bottom:0},overbought:n_(t,"overbought",90),oversold:n_(t,"oversold",10),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:nQ(t,"levelsColor",r.qm),midpointWash:!0})}},s0={type:"fisher-transform",title:(0,n.ab)("indicator.fisherTransform.title","Fisher Transform"),shortTitle:(0,n.ab)("indicator.fisherTransform.shortTitle","Fisher"),overlay:!1,inputs:[aI(9,"length",(0,n.ab)("indicator.fisherTransform.length","Length"),5e3,(0,n.ab)("indicator.fisherTransform.length.tooltip","Lookback period used to locate the median price hl2 within its highest-lowest range. Ehlers' original length is 10; 9 is the common platform default.")),az(r.qm,(0,n.ab)("indicator.fisherTransform.color","Fisher Line"),"color",(0,n.ab)("indicator.fisherTransform.color.tooltip","Color of the Fisher line when it sits exactly on its trigger.")),az(r.qm,(0,n.ab)("indicator.fisherTransform.triggerColor","Trigger Line"),"triggerColor",(0,n.ab)("indicator.fisherTransform.triggerColor.tooltip","Color of the trigger line, the Fisher value delayed one bar.")),az(r.cr,(0,n.ab)("indicator.fisherTransform.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.fisherTransform.bullColor.tooltip","Color of the Fisher line and fill while it is above the trigger.")),az(r.TV,(0,n.ab)("indicator.fisherTransform.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.fisherTransform.bearColor.tooltip","Color of the Fisher line and fill while it is below the trigger."))],compute:(e,t)=>{let i=n_(t,"length",9),o=n3(e,"HL2"),l=aa(o,i),a=as(o,i),s=e.length,h=Array(s).fill(NaN),d=0,c=0;for(let e=0;e<s;e++){let t=l[e],i=a[e];Number.isFinite(t)&&Number.isFinite(i)&&(c=.5*Math.log((1+(d=(d=.66*(t>i?(o[e]-i)/(t-i)-.5:0)+.67*d)>.99?.999:d<-.99?-.999:d))/(1-d))+.5*c,h[e]=c)}let p=ag(h,1),u=nQ(t,"color",r.qm),g=nQ(t,"bullColor",r.cr),m=nQ(t,"bearColor",r.TV),b=e=>{let t=h[e],i=p[e];return Number.isFinite(i)?t>i?g:t<i?m:u:u};return{plots:[{key:"fisher",title:(0,n.ab)("indicator.fisherTransform.plot.fisher","Fisher"),values:h,color:u,width:2,colors:h.map((e,t)=>Number.isFinite(e)?b(t):null)},{key:"trigger",title:(0,n.ab)("indicator.fisherTransform.plot.trigger","Trigger"),values:p,color:nQ(t,"triggerColor",r.qm)}],bands:[{key:"spread",from:"fisher",to:"trigger",color:aD(u,80),colors:h.map((e,t)=>Number.isFinite(e)?aD(b(t),80):null)}],levels:[{key:"upper",price:1.5,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.fisherTransform.level.upper","Upper Level")},{key:"lower",price:-1.5,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.fisherTransform.level.lower","Lower Level")},{key:"zero",price:0,color:r.qm,lineStyle:"dotted",title:(0,n.ab)("indicator.fisherTransform.level.zero","Zero Line")}]}}},s1={type:"trix",title:(0,n.ab)("indicator.trix.title","TRIX"),overlay:!1,inputs:[aI(18,"length",(0,n.ab)("indicator.trix.length","Length"),5e3,(0,n.ab)("indicator.trix.length.tooltip","Length of each of the three EMA smoothing passes applied to the close price.")),aI(9,"signalLength",(0,n.ab)("indicator.trix.signalLength","Signal Length"),500,(0,n.ab)("indicator.trix.signalLength.tooltip","Length of the EMA applied to TRIX to form the signal line.")),az(r.qm,(0,n.ab)("indicator.trix.color","TRIX Color"),"color",(0,n.ab)("indicator.trix.color.tooltip","Color of the TRIX line.")),az(r.Nz,(0,n.ab)("indicator.trix.signalColor","Signal Color"),"signalColor",(0,n.ab)("indicator.trix.signalColor.tooltip","Color of the signal line.")),az(r.cr,(0,n.ab)("indicator.trix.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.trix.bullColor.tooltip","Color of the TRIX line and its gradient fill while TRIX holds above zero.")),az(r.TV,(0,n.ab)("indicator.trix.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.trix.bearColor.tooltip","Color of the TRIX line and its gradient fill while TRIX holds below zero."))],compute:(e,t)=>{let i=n_(t,"length",18),o=au(ad(ad(ad(n7(e),i),i),i),1);return aG({key:"trix",title:(0,n.ab)("indicator.trix.plot.trix","TRIX"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,extraPlots:[{key:"signal",title:(0,n.ab)("indicator.trix.plot.signal","Signal"),values:ad(o,n_(t,"signalLength",9)),color:nQ(t,"signalColor",r.Nz)}]})}};function s2(e,t,i){let o=ap(e);return n9(ad(ad(o,t),i),ad(ad(ae(o,Math.abs),t),i),(e,t)=>0===t?0:e/t)}var s5={type:"true-strength-index",title:(0,n.ab)("indicator.trueStrengthIndex.title","True Strength Index"),shortTitle:(0,n.ab)("indicator.trueStrengthIndex.shortTitle","TSI"),overlay:!1,inputs:[aI(25,"longLength",(0,n.ab)("indicator.trueStrengthIndex.longLength","Long Length"),5e3,(0,n.ab)("indicator.trueStrengthIndex.longLength.tooltip","Length of the first (long) EMA applied to the 1-bar price change.")),aI(13,"shortLength",(0,n.ab)("indicator.trueStrengthIndex.shortLength","Short Length"),5e3,(0,n.ab)("indicator.trueStrengthIndex.shortLength.tooltip","Length of the second (short) EMA applied to the long-smoothed price change.")),aI(13,"signalLength",(0,n.ab)("indicator.trueStrengthIndex.signalLength","Signal Length"),500,(0,n.ab)("indicator.trueStrengthIndex.signalLength.tooltip","Length of the EMA of TSI used as the signal line.")),az(r.qm,(0,n.ab)("indicator.trueStrengthIndex.color","TSI"),"color",(0,n.ab)("indicator.trueStrengthIndex.color.tooltip","Color of the TSI line.")),az(r.Nz,(0,n.ab)("indicator.trueStrengthIndex.signalColor","Signal"),"signalColor",(0,n.ab)("indicator.trueStrengthIndex.signalColor.tooltip","Color of the signal line.")),az(r.cr,(0,n.ab)("indicator.trueStrengthIndex.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.trueStrengthIndex.bullColor.tooltip","Color of the TSI line and its gradient fill while TSI holds above zero.")),az(r.TV,(0,n.ab)("indicator.trueStrengthIndex.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.trueStrengthIndex.bearColor.tooltip","Color of the TSI line and its gradient fill while TSI holds below zero."))],compute:(e,t)=>{let i=ae(s2(n7(e),n_(t,"longLength",25),n_(t,"shortLength",13)),e=>100*e);return aG({key:"tsi",title:(0,n.ab)("indicator.trueStrengthIndex.plot.tsi","TSI"),values:i,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,extraPlots:[{key:"signal",title:(0,n.ab)("indicator.trueStrengthIndex.plot.signal","Signal"),values:ad(i,n_(t,"signalLength",13)),color:nQ(t,"signalColor",r.Nz)}]})}},s3="Indicator",s4="Oscillator",s6={type:"smi-ergodic",title:(0,n.ab)("indicator.smiErgodic.title","SMI Ergodic Oscillator"),shortTitle:(0,n.ab)("indicator.smiErgodic.shortTitle","SMIE"),overlay:!1,inputs:[aI(20,"longLength",(0,n.ab)("indicator.smiErgodic.longLength","Long Length"),5e3,(0,n.ab)("indicator.smiErgodic.longLength.tooltip","Length of the first EMA smoothing applied to the momentum of the closing price.")),aI(5,"shortLength",(0,n.ab)("indicator.smiErgodic.shortLength","Short Length"),5e3,(0,n.ab)("indicator.smiErgodic.shortLength.tooltip","Length of the second EMA smoothing applied to the momentum of the closing price.")),aI(5,"signalLength",(0,n.ab)("indicator.smiErgodic.signalLength","Signal Length"),500,(0,n.ab)("indicator.smiErgodic.signalLength.tooltip","Length of the EMA of the SMI that forms the signal line.")),aO("display",(0,n.ab)("indicator.smiErgodic.display","Display"),s3,[s3,s4],(0,n.ab)("indicator.smiErgodic.display.tooltip","Indicator plots the SMI and its signal line. Oscillator plots the difference between them as a histogram.")),az(r.qm,(0,n.ab)("indicator.smiErgodic.color","SMI"),"color",(0,n.ab)("indicator.smiErgodic.color.tooltip","Color of the SMI line while it sits exactly on its signal line.")),az(r.Nz,(0,n.ab)("indicator.smiErgodic.signalColor","Signal"),"signalColor",(0,n.ab)("indicator.smiErgodic.signalColor.tooltip","Color of the signal line.")),az(r.cr,(0,n.ab)("indicator.smiErgodic.growColor","Oscillator Grow"),"growColor",(0,n.ab)("indicator.smiErgodic.growColor.tooltip","Color of the rising oscillator histogram, and of the SMI line while it leads its signal.")),az(r.TV,(0,n.ab)("indicator.smiErgodic.fallColor","Oscillator Fall"),"fallColor",(0,n.ab)("indicator.smiErgodic.fallColor.tooltip","Color of the falling oscillator histogram, and of the SMI line while it lags its signal."))],compute:(e,t)=>{let i=s2(n7(e),n_(t,"longLength",20),n_(t,"shortLength",5)),o=ad(i,n_(t,"signalLength",5)),l=nQ(t,"growColor",r.cr),a=nQ(t,"fallColor",r.TV),s=[{key:"zero",price:0,color:aD(r.qm,50),lineStyle:"dashed",title:(0,n.ab)("indicator.smiErgodic.level.zero","Zero Line")}];if(nQ(t,"display",s3)===s4){let e=at(i,o),t=e.map((t,i)=>{if(!Number.isFinite(t))return null;let o=i>0&&Number.isFinite(e[i-1])?e[i-1]:t;return t>o?l:a});return{plots:[{key:"osc",title:(0,n.ab)("indicator.smiErgodic.plot.osc","Oscillator"),values:e,kind:"columns",color:l,colors:t,base:0}],levels:s}}let h=nQ(t,"color",r.qm),d=e=>{let t=i[e],r=o[e];return Number.isFinite(r)?t>r?l:t<r?a:h:h};return{plots:[{key:"smi",title:(0,n.ab)("indicator.smiErgodic.plot.smi","SMI"),values:i,color:h,colors:i.map((e,t)=>Number.isFinite(e)?d(t):null)},{key:"signal",title:(0,n.ab)("indicator.smiErgodic.plot.signal","Signal"),values:o,color:nQ(t,"signalColor",r.Nz)}],bands:[{key:"spread",from:"smi",to:"signal",color:aD(h,75),colors:i.map((e,t)=>Number.isFinite(e)?aD(d(t),75):null)}],levels:s}}},s8="Trigger Levels",s7={type:"schaff-trend-cycle",title:(0,n.ab)("indicator.schaffTrendCycle.title","Schaff Trend Cycle"),shortTitle:(0,n.ab)("indicator.schaffTrendCycle.shortTitle","Schaff Trend Cycle"),overlay:!1,inputs:[aR("Close","source",(0,n.ab)("indicator.schaffTrendCycle.source","Source"),(0,n.ab)("indicator.schaffTrendCycle.source.tooltip","Price series used to build the MACD that the trend cycle is measured on.")),aI(23,"fastLength",(0,n.ab)("indicator.schaffTrendCycle.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.schaffTrendCycle.fastLength.tooltip","Fast EMA length of the underlying MACD.")),aI(50,"slowLength",(0,n.ab)("indicator.schaffTrendCycle.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.schaffTrendCycle.slowLength.tooltip","Slow EMA length of the underlying MACD.")),{...aI(10,"cycleLength",(0,n.ab)("indicator.schaffTrendCycle.cycleLength","Cycle Length"),5e3,(0,n.ab)("indicator.schaffTrendCycle.cycleLength.tooltip","Window of the two stochastic passes. Each pass measures where its input sits inside the range of its own values over this many bars.")),min:2},aB("factor",(0,n.ab)("indicator.schaffTrendCycle.factor","Smoothing Factor"),.5,.01,1,.05,(0,n.ab)("indicator.schaffTrendCycle.factor.tooltip","%D style recursive smoothing applied after each stochastic pass. 0.5 is the published default.")),{...aB("upper",(0,n.ab)("indicator.schaffTrendCycle.upper","Upper Trigger"),75,0,100,1,(0,n.ab)("indicator.schaffTrendCycle.upper.tooltip","Upper trigger line. A cross down through it flags an emerging downtrend.")),group:s8},{...aB("lower",(0,n.ab)("indicator.schaffTrendCycle.lower","Lower Trigger"),25,0,100,1,(0,n.ab)("indicator.schaffTrendCycle.lower.tooltip","Lower trigger line. A cross up through it flags an emerging uptrend.")),group:s8},az(r.cr,(0,n.ab)("indicator.schaffTrendCycle.bullColor","Bullish Color"),"bullColor",(0,n.ab)("indicator.schaffTrendCycle.bullColor.tooltip","Color of the trend cycle line and gradient while the cycle holds the upper half of its 0-100 scale.")),az(r.TV,(0,n.ab)("indicator.schaffTrendCycle.bearColor","Bearish Color"),"bearColor",(0,n.ab)("indicator.schaffTrendCycle.bearColor.tooltip","Color of the trend cycle line and gradient while the cycle holds the lower half of its 0-100 scale.")),az(r.qm,(0,n.ab)("indicator.schaffTrendCycle.levelsColor","Levels Color"),"levelsColor",(0,n.ab)("indicator.schaffTrendCycle.levelsColor.tooltip","Color of the dashed trigger lines and the dotted midline.")),aF("gradientFill",(0,n.ab)("indicator.schaffTrendCycle.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.schaffTrendCycle.gradientFill.tooltip","Vertical gradient between the midline and the trend cycle, fading out toward the midline."))],compute:(e,t)=>{let i=n_(t,"cycleLength",10),o=n_(t,"factor",.5),l=n3(e,nQ(t,"source","Close")),a=at(ad(l,n_(t,"fastLength",23)),ad(l,n_(t,"slowLength",50))),s=e=>{let t=as(e,i),o=aa(e,i),r=Array(e.length).fill(NaN),l=NaN;for(let i=0;i<e.length;i++){let n=e[i],a=t[i],s=o[i];Number.isFinite(n)&&Number.isFinite(a)&&Number.isFinite(s)&&(s>a&&(l=100*(n-a)/(s-a)),r[i]=l)}return r},h=e=>{let t=Array(e.length).fill(NaN),i=NaN;for(let r=0;r<e.length;r++){let l=e[r];Number.isFinite(l)&&(i=Number.isFinite(i)?i+o*(l-i):l,t[r]=i)}return t},d=h(s(h(s(a)))),c=nQ(t,"levelsColor",r.qm),p=nQ(t,"bullColor",r.cr),u=nQ(t,"bearColor",r.TV),g=[{key:"stc",title:(0,n.ab)("indicator.schaffTrendCycle.plot.stc","Schaff Trend Cycle"),values:d,color:u,width:2,colors:d.map(e=>Number.isFinite(e)?e>50?p:u:null)}],m=[];return nJ(t,"gradientFill",!0)&&(g.push(aW("midAnchor","Midline Anchor",d.length,50)),m.push({key:"wash",from:"stc",to:"midAnchor",color:aD(r.qm,100),gradient:aU(d,50,e=>e>50?p:u)})),{plots:g,bands:m,levels:[{key:"upper",price:n_(t,"upper",75),color:aD(c,25),lineStyle:"dashed",title:(0,n.ab)("indicator.schaffTrendCycle.level.upper","Upper Trigger")},{key:"lower",price:n_(t,"lower",25),color:aD(c,25),lineStyle:"dashed",title:(0,n.ab)("indicator.schaffTrendCycle.level.lower","Lower Trigger")},{key:"midline",price:50,color:aD(c,60),lineStyle:"dotted",title:(0,n.ab)("indicator.schaffTrendCycle.level.midline","Midline")}]}}},s9={type:"know-sure-thing",title:(0,n.ab)("indicator.knowSureThing.title","Know Sure Thing"),shortTitle:(0,n.ab)("indicator.knowSureThing.shortTitle","KST"),overlay:!1,inputs:[aI(10,"rocLength1",(0,n.ab)("indicator.knowSureThing.rocLength1","ROC Length #1"),5e3,(0,n.ab)("indicator.knowSureThing.rocLength1.tooltip","Lookback of the first (shortest) rate of change.")),aI(15,"rocLength2",(0,n.ab)("indicator.knowSureThing.rocLength2","ROC Length #2"),5e3,(0,n.ab)("indicator.knowSureThing.rocLength2.tooltip","Lookback of the second rate of change.")),aI(20,"rocLength3",(0,n.ab)("indicator.knowSureThing.rocLength3","ROC Length #3"),5e3,(0,n.ab)("indicator.knowSureThing.rocLength3.tooltip","Lookback of the third rate of change.")),aI(30,"rocLength4",(0,n.ab)("indicator.knowSureThing.rocLength4","ROC Length #4"),5e3,(0,n.ab)("indicator.knowSureThing.rocLength4.tooltip","Lookback of the fourth (longest) rate of change.")),aI(10,"smaLength1",(0,n.ab)("indicator.knowSureThing.smaLength1","SMA Length #1"),5e3,(0,n.ab)("indicator.knowSureThing.smaLength1.tooltip","Smoothing length applied to the first rate of change (RCMA #1).")),aI(10,"smaLength2",(0,n.ab)("indicator.knowSureThing.smaLength2","SMA Length #2"),5e3,(0,n.ab)("indicator.knowSureThing.smaLength2.tooltip","Smoothing length applied to the second rate of change (RCMA #2).")),aI(10,"smaLength3",(0,n.ab)("indicator.knowSureThing.smaLength3","SMA Length #3"),5e3,(0,n.ab)("indicator.knowSureThing.smaLength3.tooltip","Smoothing length applied to the third rate of change (RCMA #3).")),aI(15,"smaLength4",(0,n.ab)("indicator.knowSureThing.smaLength4","SMA Length #4"),5e3,(0,n.ab)("indicator.knowSureThing.smaLength4.tooltip","Smoothing length applied to the fourth rate of change (RCMA #4).")),aI(9,"signalLength",(0,n.ab)("indicator.knowSureThing.signalLength","Signal Length"),500,(0,n.ab)("indicator.knowSureThing.signalLength.tooltip","Simple moving average length of the signal line.")),az(r.cr,(0,n.ab)("indicator.knowSureThing.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.knowSureThing.bullColor.tooltip","Color of the KST line while above zero.")),az(r.TV,(0,n.ab)("indicator.knowSureThing.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.knowSureThing.bearColor.tooltip","Color of the KST line while below zero.")),az(r.Nz,(0,n.ab)("indicator.knowSureThing.signalColor","Signal"),"signalColor",(0,n.ab)("indicator.knowSureThing.signalColor.tooltip","Color of the signal line."))],compute:(e,t)=>{let i=n7(e),o=(e,o,r,l)=>ar(au(i,n_(t,e,o)),n_(t,r,l)),l=[o("rocLength1",10,"smaLength1",10),o("rocLength2",15,"smaLength2",10),o("rocLength3",20,"smaLength3",10),o("rocLength4",30,"smaLength4",15)].reduce((e,t,i)=>n9(e,t,(e,t)=>e+t*(i+1)),Array(i.length).fill(0)),a=nQ(t,"bullColor",r.cr);return aG({key:"kst",title:(0,n.ab)("indicator.knowSureThing.plot.kst","KST"),values:l,ink:{bull:a,bear:nQ(t,"bearColor",r.TV),neutral:a},zeroInk:r.qm,valueTransparency:60,extraPlots:[{key:"signal",title:(0,n.ab)("indicator.knowSureThing.plot.signal","Signal"),values:ar(l,n_(t,"signalLength",9)),color:nQ(t,"signalColor",r.Nz)}]})}},he={type:"coppock-curve",title:(0,n.ab)("indicator.coppockCurve.title","Coppock Curve"),shortTitle:(0,n.ab)("indicator.coppockCurve.shortTitle","Coppock"),overlay:!1,inputs:[aI(10,"wmaLength",(0,n.ab)("indicator.coppockCurve.wmaLength","WMA Length"),5e3,(0,n.ab)("indicator.coppockCurve.wmaLength.tooltip","Length of the weighted moving average applied to the sum of the two rates of change.")),aI(14,"longRoc",(0,n.ab)("indicator.coppockCurve.longRoc","Long ROC Length"),5e3,(0,n.ab)("indicator.coppockCurve.longRoc.tooltip","Lookback of the long rate of change, in bars. The original definition uses 14 monthly closes.")),aI(11,"shortRoc",(0,n.ab)("indicator.coppockCurve.shortRoc","Short ROC Length"),5e3,(0,n.ab)("indicator.coppockCurve.shortRoc.tooltip","Lookback of the short rate of change, in bars. The original definition uses 11 monthly closes.")),aR("Close","source",(0,n.ab)("indicator.coppockCurve.source","Source"),(0,n.ab)("indicator.coppockCurve.source.tooltip","Price series used for the rate of change calculations.")),az(r.qm,(0,n.ab)("indicator.coppockCurve.color","Coppock Curve"),"color",(0,n.ab)("indicator.coppockCurve.color.tooltip","Color of the Coppock Curve line.")),az(r.cr,(0,n.ab)("indicator.coppockCurve.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.coppockCurve.bullColor.tooltip","Line and fill color while the curve reads above zero.")),az(r.TV,(0,n.ab)("indicator.coppockCurve.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.coppockCurve.bearColor.tooltip","Line and fill color while the curve reads below zero.")),az(r.qm,(0,n.ab)("indicator.coppockCurve.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.coppockCurve.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=al(n9(au(i,n_(t,"longRoc",14)),au(i,n_(t,"shortRoc",11)),(e,t)=>e+t),n_(t,"wmaLength",10));return aG({key:"coppock",title:(0,n.ab)("indicator.coppockCurve.plot.coppock","Coppock Curve"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:nQ(t,"zeroColor",r.qm)})}},ht={type:"detrended-price-oscillator",title:(0,n.ab)("indicator.detrendedPriceOscillator.title","Detrended Price Oscillator"),shortTitle:(0,n.ab)("indicator.detrendedPriceOscillator.shortTitle","DPO"),overlay:!1,inputs:[aI(21,"length",(0,n.ab)("indicator.detrendedPriceOscillator.length","Length"),5e3,(0,n.ab)("indicator.detrendedPriceOscillator.length.tooltip","Lookback of the simple moving average that price is detrended against. The comparison is displaced by Length / 2 + 1 bars.")),aR("Close","source",(0,n.ab)("indicator.detrendedPriceOscillator.source","Source"),(0,n.ab)("indicator.detrendedPriceOscillator.source.tooltip","Price series used in the detrending calculation.")),aF("centered",(0,n.ab)("indicator.detrendedPriceOscillator.centered","Centered"),!1,void 0,(0,n.ab)("indicator.detrendedPriceOscillator.centered.tooltip","Shifts the oscillator back by Length / 2 + 1 bars so it is centered on the prices it detrends. The most recent bars then show no value.")),az(r.qm,(0,n.ab)("indicator.detrendedPriceOscillator.color","DPO"),"color",(0,n.ab)("indicator.detrendedPriceOscillator.color.tooltip","Color of the line when it sits exactly at zero.")),az(r.cr,(0,n.ab)("indicator.detrendedPriceOscillator.bullColor","Above Zero"),"bullColor",(0,n.ab)("indicator.detrendedPriceOscillator.bullColor.tooltip","Color of the line and fill while the oscillator is above zero.")),az(r.TV,(0,n.ab)("indicator.detrendedPriceOscillator.bearColor","Below Zero"),"bearColor",(0,n.ab)("indicator.detrendedPriceOscillator.bearColor.tooltip","Color of the line and fill while the oscillator is below zero.")),az(r.qm,(0,n.ab)("indicator.detrendedPriceOscillator.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.detrendedPriceOscillator.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=n_(t,"length",21),o=Math.trunc(i/2)+1,l=n3(e,nQ(t,"source","Close")),a=ar(l,i),s=nJ(t,"centered",!1)?ag(at(ag(l,o),a),-o):at(l,ag(a,o));return aG({key:"dpo",title:(0,n.ab)("indicator.detrendedPriceOscillator.plot.dpo","DPO"),values:s,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:nQ(t,"zeroColor",r.qm)})}},hi="ROC %",ho="Momentum",hr={type:"rate-of-change",title:(0,n.ab)("indicator.rateOfChange.title","Rate of Change"),shortTitle:(0,n.ab)("indicator.rateOfChange.shortTitle","ROC"),overlay:!1,inputs:[aI(9,"length",(0,n.ab)("indicator.rateOfChange.length","Length"),5e3,(0,n.ab)("indicator.rateOfChange.length.tooltip","Lookback period; the source is compared with its value this many bars ago.")),aR("Close","source",(0,n.ab)("indicator.rateOfChange.source","Source"),(0,n.ab)("indicator.rateOfChange.source.tooltip","Series used as input for the calculation.")),aO("mode",(0,n.ab)("indicator.rateOfChange.mode","Mode"),hi,[hi,ho],(0,n.ab)("indicator.rateOfChange.mode.tooltip","ROC % plots the change as a percentage of the source value from the lookback; Momentum plots the raw difference.")),az(r.qm,(0,n.ab)("indicator.rateOfChange.color","Line"),"color",(0,n.ab)("indicator.rateOfChange.color.tooltip","Color of the line when the reading sits exactly at zero.")),az(r.cr,(0,n.ab)("indicator.rateOfChange.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.rateOfChange.bullColor.tooltip","Color of the line and fill while the reading is above zero.")),az(r.TV,(0,n.ab)("indicator.rateOfChange.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.rateOfChange.bearColor.tooltip","Color of the line and fill while the reading is below zero.")),aF("gradientFill",(0,n.ab)("indicator.rateOfChange.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.rateOfChange.gradientFill.tooltip","Fills the area between the line and zero, following the line color."))],compute:(e,t)=>{let i=n_(t,"length",9),o=n3(e,nQ(t,"source","Close")),l=nQ(t,"mode",hi)===ho?ap(o,i):au(o,i);return aG({key:"roc",title:(0,n.ab)("indicator.rateOfChange.plot.roc","ROC"),values:l,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,fill:nJ(t,"gradientFill",!0)})}},hl={type:"ultimate-oscillator",title:(0,n.ab)("indicator.ultimateOscillator.title","Ultimate Oscillator"),shortTitle:(0,n.ab)("indicator.ultimateOscillator.shortTitle","UO"),overlay:!1,inputs:[aI(7,"fastLength",(0,n.ab)("indicator.ultimateOscillator.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.ultimateOscillator.fastLength.tooltip","Bars in the fastest averaging window. Weighted 4 in the final blend, so it dominates the oscillator.")),aI(14,"middleLength",(0,n.ab)("indicator.ultimateOscillator.middleLength","Middle Length"),5e3,(0,n.ab)("indicator.ultimateOscillator.middleLength.tooltip","Bars in the intermediate averaging window. Weighted 2 in the final blend.")),aI(28,"slowLength",(0,n.ab)("indicator.ultimateOscillator.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.ultimateOscillator.slowLength.tooltip","Bars in the slowest averaging window. Weighted 1 in the final blend.")),...sD(70,30,0,100,(0,n.ab)("indicator.ultimateOscillator.overbought","Overbought"),(0,n.ab)("indicator.ultimateOscillator.oversold","Oversold")),az(r.qm,(0,n.ab)("indicator.ultimateOscillator.color","Oscillator"),"color",(0,n.ab)("indicator.ultimateOscillator.color.tooltip","Color of the line midway between the levels. Toward either level it blends into that level’s color.")),az(r.qm,(0,n.ab)("indicator.ultimateOscillator.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.ultimateOscillator.levelsColor.tooltip","Color of the overbought and oversold levels.")),az(r.cr,(0,n.ab)("indicator.ultimateOscillator.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.ultimateOscillator.oversoldColor.tooltip","Color of the line at the oversold level and of the oversold zone shading.")),az(r.TV,(0,n.ab)("indicator.ultimateOscillator.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.ultimateOscillator.overboughtColor.tooltip","Color of the line at the overbought level and of the overbought zone shading."))],compute:(e,t)=>{let i=e.length,o=Array(i).fill(NaN),l=Array(i).fill(NaN);for(let t=0;t<i;t++){let i=e[t],r=t>0?e[t-1].close:i.close,n=Math.min(i.low,r);o[t]=i.close-n,l[t]=Math.max(i.high,r)-n}let a=e=>n9(ao(o,e),ao(l,e),(e,t)=>0===t?NaN:e/t),s=a(n_(t,"fastLength",7)),h=a(n_(t,"middleLength",14)),d=a(n_(t,"slowLength",28)),c=s.map((e,t)=>{let i=h[t],o=d[t];return Number.isFinite(e)&&Number.isFinite(i)&&Number.isFinite(o)?100*(4*e+2*i+o)/7:NaN});return aj({key:"uo",title:(0,n.ab)("indicator.ultimateOscillator.plot.uo","UO"),values:c,scale:{top:100,bottom:0},overbought:n_(t,"overbought",70),oversold:n_(t,"oversold",30),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:nQ(t,"levelsColor",r.qm),zoneTransparency:91})}},hn={type:"relative-vigor-index",title:(0,n.ab)("indicator.relativeVigorIndex.title","Relative Vigor Index"),shortTitle:(0,n.ab)("indicator.relativeVigorIndex.shortTitle","RVGI"),overlay:!1,inputs:[aI(10,"length",(0,n.ab)("indicator.relativeVigorIndex.length","Length"),5e3,(0,n.ab)("indicator.relativeVigorIndex.length.tooltip","Number of bars summed for the smoothed numerator (close − open) and denominator (high − low).")),az(r.cr,(0,n.ab)("indicator.relativeVigorIndex.color","RVGI"),"color",(0,n.ab)("indicator.relativeVigorIndex.color.tooltip","Color of the RVGI line.")),az(r.TV,(0,n.ab)("indicator.relativeVigorIndex.signalColor","Signal"),"signalColor",(0,n.ab)("indicator.relativeVigorIndex.signalColor.tooltip","Color of the signal line."))],compute:(e,t)=>{let i=n_(t,"length",10),o=ak(at(n7(e),e.map(e=>e.open))),l=ak(at(n6(e),n8(e))),a=n9(ao(o,i),ao(l,i),(e,t)=>0===t?0:e/t);return{plots:[{key:"rvgi",title:(0,n.ab)("indicator.relativeVigorIndex.plot.rvgi","RVGI"),values:a,color:nQ(t,"color",r.cr)},{key:"signal",title:(0,n.ab)("indicator.relativeVigorIndex.plot.signal","Signal"),values:ak(a),color:nQ(t,"signalColor",r.TV)}],levels:[{key:"zero",price:0,color:aD(r.qm,50),lineStyle:"dashed",title:(0,n.ab)("indicator.relativeVigorIndex.level.zero","Zero Line")}]}}},ha="Wilder (RMA)",hs={type:"relative-volatility-index",title:(0,n.ab)("indicator.relativeVolatilityIndex.title","Relative Volatility Index"),shortTitle:(0,n.ab)("indicator.relativeVolatilityIndex.shortTitle","RVI"),overlay:!1,inputs:[aI(10,"stdevLength",(0,n.ab)("indicator.relativeVolatilityIndex.stdevLength","Stdev Length"),5e3,(0,n.ab)("indicator.relativeVolatilityIndex.stdevLength.tooltip","Number of bars used for the standard deviation of closing prices that serves as each bar's volatility reading.")),aI(14,"smoothLength",(0,n.ab)("indicator.relativeVolatilityIndex.smoothLength","Smoothing Length"),5e3,(0,n.ab)("indicator.relativeVolatilityIndex.smoothLength.tooltip","Number of bars used to smooth the up and down volatility streams.")),aO("smoothType",(0,n.ab)("indicator.relativeVolatilityIndex.smoothType","Smoothing Type"),"EMA",["EMA",ha],(0,n.ab)("indicator.relativeVolatilityIndex.smoothType.tooltip","Moving average applied to the volatility streams. EMA is Dorsey's classic calculation; Wilder (RMA) matches platforms that use Wilder smoothing.")),...sD(80,20),az(r.qm,(0,n.ab)("indicator.relativeVolatilityIndex.color","RVI Line"),"color",(0,n.ab)("indicator.relativeVolatilityIndex.color.tooltip","Color of the RVI line at the midline. Toward either threshold it blends into that threshold’s color.")),az(r.cr,(0,n.ab)("indicator.relativeVolatilityIndex.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.relativeVolatilityIndex.overboughtColor.tooltip","Color of the line and zone shading at and above the overbought level.")),az(r.TV,(0,n.ab)("indicator.relativeVolatilityIndex.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.relativeVolatilityIndex.oversoldColor.tooltip","Color of the line and zone shading at and below the oversold level."))],compute:(e,t)=>{let i=n7(e),o=an(i,n_(t,"stdevLength",10)),l=ap(i),a=n9(o,l,(e,t)=>t>0?e:0),s=n9(o,l,(e,t)=>t<0?e:0),h=n_(t,"smoothLength",14),d=nQ(t,"smoothType","EMA")===ha?ac:ad,c=n9(d(a,h),d(s,h),(e,t)=>e+t===0?0:100*e/(e+t));return aj({key:"rvi",title:(0,n.ab)("indicator.relativeVolatilityIndex.plot.rvi","RVI"),values:c,scale:{top:100,bottom:0},overbought:n_(t,"overbought",80),oversold:n_(t,"oversold",20),ink:{low:nQ(t,"oversoldColor",r.TV),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.cr)},levelInk:r.qm,width:2})}},hh={type:"balance-of-power",title:(0,n.ab)("indicator.balanceOfPower.title","Balance of Power"),shortTitle:(0,n.ab)("indicator.balanceOfPower.shortTitle","BOP"),overlay:!1,inputs:[aF("smoothing",(0,n.ab)("indicator.balanceOfPower.smoothing","Smoothing"),!1,void 0,(0,n.ab)("indicator.balanceOfPower.smoothing.tooltip","Smooth the raw Balance of Power with a simple moving average instead of plotting the single-bar value.")),aI(14,"smoothLength",(0,n.ab)("indicator.balanceOfPower.smoothLength","Length"),5e3,(0,n.ab)("indicator.balanceOfPower.smoothLength.tooltip","Simple moving average length applied when smoothing is enabled.")),az(r.qm,(0,n.ab)("indicator.balanceOfPower.color","BOP Color"),"color",(0,n.ab)("indicator.balanceOfPower.color.tooltip","Color of the line at exactly zero.")),az(r.cr,(0,n.ab)("indicator.balanceOfPower.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.balanceOfPower.bullColor.tooltip","Line and fill color while the Balance of Power is above zero — buyers in control of the bar.")),az(r.TV,(0,n.ab)("indicator.balanceOfPower.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.balanceOfPower.bearColor.tooltip","Line and fill color while the Balance of Power is below zero — sellers in control of the bar."))],compute:(e,t)=>{let i=e.map(e=>e.high===e.low?0:(e.close-e.open)/(e.high-e.low)),o=nJ(t,"smoothing",!1)?ar(i,n_(t,"smoothLength",14)):i;return aG({key:"bop",title:(0,n.ab)("indicator.balanceOfPower.plot.bop","BOP"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,valueTransparency:60})}},hd={type:"elder-ray",title:(0,n.ab)("indicator.elderRay.title","Elder Ray"),overlay:!1,inputs:[aI(13,"length",(0,n.ab)("indicator.elderRay.length","EMA Length"),5e3,(0,n.ab)("indicator.elderRay.length.tooltip","Number of bars in the exponential moving average of closing prices used as the reference level for Bull Power and Bear Power. Alexander Elder's classic setting is 13.")),az(r.cr,(0,n.ab)("indicator.elderRay.bullColor","Bull Power"),"bullColor",(0,n.ab)("indicator.elderRay.bullColor.tooltip","Color of the Bull Power columns.")),az(r.TV,(0,n.ab)("indicator.elderRay.bearColor","Bear Power"),"bearColor",(0,n.ab)("indicator.elderRay.bearColor.tooltip","Color of the Bear Power columns."))],compute:(e,t)=>{let i=ad(n7(e),n_(t,"length",13));return{plots:[{key:"bull",title:(0,n.ab)("indicator.elderRay.plot.bull","Bull Power"),values:at(n6(e),i),kind:"columns",color:nQ(t,"bullColor",r.cr),base:0},{key:"bear",title:(0,n.ab)("indicator.elderRay.plot.bear","Bear Power"),values:at(n8(e),i),kind:"columns",color:nQ(t,"bearColor",r.TV),base:0}],levels:[{key:"zero",price:0,color:aD(r.qm,30),lineStyle:"dashed",title:(0,n.ab)("indicator.elderRay.level.zero","Zero Line")}]}}},hc={type:"ttm-squeeze",title:(0,n.ab)("indicator.ttmSqueeze.title","TTM Squeeze"),overlay:!1,inputs:[{...aI(20,"length",(0,n.ab)("indicator.ttmSqueeze.length","Length"),5e3,(0,n.ab)("indicator.ttmSqueeze.length.tooltip","Shared lookback for the Bollinger Bands, the Keltner Channels, and the momentum regression. John Carter's original setting is 20.")),min:2},aR("Close","source",(0,n.ab)("indicator.ttmSqueeze.source","Source"),(0,n.ab)("indicator.ttmSqueeze.source.tooltip","Price series used for the shared moving average basis, the standard deviation, and the momentum displacement.")),aB("bbMult",(0,n.ab)("indicator.ttmSqueeze.bbMult","Bollinger Bands Multiplier"),2,.1,50,.1,(0,n.ab)("indicator.ttmSqueeze.bbMult.tooltip","Standard deviation multiplier for the Bollinger Bands.")),aB("kcMult",(0,n.ab)("indicator.ttmSqueeze.kcMult","Keltner Channels Multiplier"),1.5,.1,50,.1,(0,n.ab)("indicator.ttmSqueeze.kcMult.tooltip","ATR multiplier for the Keltner Channels. A smaller multiplier demands a tighter compression before the squeeze turns on.")),az(r.cr,(0,n.ab)("indicator.ttmSqueeze.bullColor","Momentum Up"),"bullColor",(0,n.ab)("indicator.ttmSqueeze.bullColor.tooltip","Histogram color while momentum is positive. Bars building away from zero print solid, bars fading back print dimmed.")),az(r.TV,(0,n.ab)("indicator.ttmSqueeze.bearColor","Momentum Down"),"bearColor",(0,n.ab)("indicator.ttmSqueeze.bearColor.tooltip","Histogram color while momentum is negative. Bars building away from zero print solid, bars fading back print dimmed.")),az(r.Nz,(0,n.ab)("indicator.ttmSqueeze.squeezeOnColor","Squeeze On"),"squeezeOnColor",(0,n.ab)("indicator.ttmSqueeze.squeezeOnColor.tooltip","Zero-line dot color while both Bollinger Bands sit fully inside the Keltner Channels.")),az(r.qm,(0,n.ab)("indicator.ttmSqueeze.squeezeOffColor","Squeeze Off"),"squeezeOffColor",(0,n.ab)("indicator.ttmSqueeze.squeezeOffColor.tooltip","Zero-line dot color while the Bollinger Bands trade outside the Keltner Channels.")),aF("markFires",(0,n.ab)("indicator.ttmSqueeze.markFires","Mark Squeeze Fires"),!0,aP,(0,n.ab)("indicator.ttmSqueeze.markFires.tooltip","Draws a cross on the zero line on the first bar where the bands re-emerge outside the channels, colored by the side of the momentum histogram."))],compute:(e,t)=>{let i=n_(t,"length",20),o=n3(e,nQ(t,"source","Close")),l=ar(o,i),a=ae(an(o,i),e=>e*n_(t,"bbMult",2)),s=ae(ab(e,i),e=>e*n_(t,"kcMult",1.5)),h=n9(aa(n6(e),i),as(n8(e),i),(e,t)=>(e+t)/2),d=ay(at(o,n9(h,l,(e,t)=>(e+t)/2)),i,0),c=l.map((e,t)=>{let i=a[t],o=s[t];return Number.isFinite(e)&&Number.isFinite(i)&&Number.isFinite(o)?i<o:null}),p=nQ(t,"bullColor",r.cr),u=nQ(t,"bearColor",r.TV),g=nQ(t,"squeezeOnColor",r.Nz),m=nQ(t,"squeezeOffColor",r.qm),b=d.map((e,t)=>{if(!Number.isFinite(e))return null;let i=t>0&&Number.isFinite(d[t-1])?d[t-1]:e,o=e>i;return e>=0?o?p:aD(p,60):o?aD(u,60):u}),f=[{key:"mom",title:(0,n.ab)("indicator.ttmSqueeze.plot.mom","Momentum"),values:d,kind:"columns",color:p,colors:b,base:0},{key:"state",title:(0,n.ab)("indicator.ttmSqueeze.plot.state","Squeeze State"),values:c.map(e=>null==e?NaN:0),kind:"circles",color:m,width:2,colors:c.map(e=>null==e?null:e?g:m)}];if(nJ(t,"markFires",!0)){let e=c.map((e,t)=>!1===e&&!0===c[t-1]?0:NaN);f.push({key:"fire",title:(0,n.ab)("indicator.ttmSqueeze.plot.fire","Squeeze Fire"),values:e,kind:"cross",color:m,width:3,colors:e.map((e,t)=>Number.isFinite(e)?Number.isFinite(d[t])?d[t]>=0?p:u:m:null)})}return{plots:f}}},hp={type:"momentum",title:(0,n.ab)("indicator.momentum.title","Momentum"),shortTitle:(0,n.ab)("indicator.momentum.shortTitle","Mom"),overlay:!1,inputs:[aI(10,"length",(0,n.ab)("indicator.momentum.length","Length"),5e3,(0,n.ab)("indicator.momentum.length.tooltip","Lookback period; the source is compared with its value this many bars ago.")),aR("Close","source",(0,n.ab)("indicator.momentum.source","Source"),(0,n.ab)("indicator.momentum.source.tooltip","Series the difference is measured on.")),az(r.qm,(0,n.ab)("indicator.momentum.color","Line"),"color",(0,n.ab)("indicator.momentum.color.tooltip","Color of the line when the reading sits exactly at zero.")),az(r.cr,(0,n.ab)("indicator.momentum.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.momentum.bullColor.tooltip","Color of the line and fill while the reading is above zero.")),az(r.TV,(0,n.ab)("indicator.momentum.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.momentum.bearColor.tooltip","Color of the line and fill while the reading is below zero.")),aF("gradientFill",(0,n.ab)("indicator.momentum.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.momentum.gradientFill.tooltip","Fills the area between the line and zero, following the line color."))],compute:(e,t)=>aG({key:"mom",title:(0,n.ab)("indicator.momentum.plot.mom","Momentum"),values:ap(n3(e,nQ(t,"source","Close")),n_(t,"length",10)),ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,fill:nJ(t,"gradientFill",!0)})},hu={type:"accumulative-swing-index",title:(0,n.ab)("indicator.accumulativeSwingIndex.title","Accumulative Swing Index"),overlay:!1,inputs:[aB("limitMove",(0,n.ab)("indicator.accumulativeSwingIndex.limitMove","Limit Move"),10,.1,1e5,.1,(0,n.ab)("indicator.accumulativeSwingIndex.limitMove.tooltip","Largest price change allowed in one direction in a session. Every swing is divided by it, so a larger value flattens the whole line.")),aI(10,"swingLength",(0,n.ab)("indicator.accumulativeSwingIndex.swingLength","Swing Length"),200,(0,n.ab)("indicator.accumulativeSwingIndex.swingLength.tooltip","Bars on each side required to confirm a swing high or low of the line. The line is colored against its most recent confirmed swing points.")),az(r.qm,(0,n.ab)("indicator.accumulativeSwingIndex.color","ASI Line"),"color",(0,n.ab)("indicator.accumulativeSwingIndex.color.tooltip","Color of the line while it sits between its prior swing high and swing low.")),az(r.cr,(0,n.ab)("indicator.accumulativeSwingIndex.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.accumulativeSwingIndex.bullColor.tooltip","Color of the line while it reads above its prior swing high, which Wilder took as confirming an upside breakout in price.")),az(r.TV,(0,n.ab)("indicator.accumulativeSwingIndex.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.accumulativeSwingIndex.bearColor.tooltip","Color of the line while it reads below its prior swing low, which Wilder took as confirming a downside breakout in price."))],compute:(e,t)=>{let i=Math.max(n_(t,"limitMove",10),.1),o=Array(e.length).fill(NaN);for(let t=1;t<e.length;t++){let r=e[t],l=e[t-1],n=Math.abs(r.high-l.close),a=Math.abs(r.low-l.close),s=r.high-r.low,h=Math.abs(l.close-l.open),d=n>=a&&n>=s?n-.5*a+.25*h:a>=n&&a>=s?a-.5*n+.25*h:s+.25*h,c=r.close-l.close+.5*(r.close-r.open)+.25*(l.close-l.open);o[t]=0===d?0:50*c*(Math.max(n,a)/i)/d}let l=aS(o),a={bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)};return{plots:[{key:"asi",title:(0,n.ab)("indicator.accumulativeSwingIndex.plot.asi","ASI"),values:l,color:a.neutral,colors:function(e,t,i){let o=NaN,r=NaN;return e.map((l,n)=>{let a=n-t;if(a-t>=0){let i=e[a],l=Number.isFinite(i),s=l;for(let o=a-t;o<=n&&(l||s);o++){if(o===a)continue;let t=e[o];(!Number.isFinite(t)||(o<a?t>i:t>=i))&&(l=!1),(!Number.isFinite(t)||(o<a?t<i:t<=i))&&(s=!1)}l&&(o=i),s&&(r=i)}return Number.isFinite(l)?l>o?i.bull:l<r?i.bear:i.neutral:null})}(l,Math.trunc(n_(t,"swingLength",10)),a)}]}}},hg={type:"rank-correlation-index",title:(0,n.ab)("indicator.rankCorrelationIndex.title","Rank Correlation Index"),shortTitle:(0,n.ab)("indicator.rankCorrelationIndex.shortTitle","RCI"),overlay:!1,inputs:[{...aI(12,"length",(0,n.ab)("indicator.rankCorrelationIndex.length","Length"),1e3,(0,n.ab)("indicator.rankCorrelationIndex.length.tooltip","Number of bars whose order in time is compared with their order by price.")),min:2},aR("Close","source",(0,n.ab)("indicator.rankCorrelationIndex.source","Source"),(0,n.ab)("indicator.rankCorrelationIndex.source.tooltip","Price series the bars are ranked by.")),...sD(.8,-.8,-1,1,void 0,void 0,.05),az(r.qm,(0,n.ab)("indicator.rankCorrelationIndex.color","RCI Line"),"color",(0,n.ab)("indicator.rankCorrelationIndex.color.tooltip","Color of the RCI line between the levels. Toward either level it blends into that level’s color.")),az(r.TV,(0,n.ab)("indicator.rankCorrelationIndex.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.rankCorrelationIndex.overboughtColor.tooltip","Color of the line and zone shading at and above the overbought level.")),az(r.cr,(0,n.ab)("indicator.rankCorrelationIndex.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.rankCorrelationIndex.oversoldColor.tooltip","Color of the line and zone shading at and below the oversold level."))],compute:(e,t)=>aj({key:"rci",title:(0,n.ab)("indicator.rankCorrelationIndex.plot.rci","RCI"),values:function(e,t){if(t<2)return aT(e.length,NaN);let i=Array(t),o=Array(t),r=6/(t*(t*t-1));return ai(e,t,(e,l)=>{for(let e=0;e<t;e++)i[e]=e;i.sort((t,i)=>e[l+i]-e[l+t]);for(let r=0;r<t;){let n=r;for(;n+1<t&&e[l+i[n+1]]===e[l+i[r]];)n++;let a=(r+n)/2+1;for(let e=r;e<=n;e++)o[i[e]]=a;r=n+1}let n=0;for(let e=0;e<t;e++){let i=t-e-o[e];n+=i*i}return 1-r*n})}(n3(e,nQ(t,"source","Close")),n_(t,"length",12)),scale:{top:1,bottom:-1},overbought:n_(t,"overbought",.8),oversold:n_(t,"oversold",-.8),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:r.qm,midline:0})},hm={type:"majority-rule",title:(0,n.ab)("indicator.majorityRule.title","Majority Rule"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.majorityRule.length","Rolling Period"),5e3,(0,n.ab)("indicator.majorityRule.length.tooltip","Number of bars counted. The reading is the percentage of them that closed above the bar before.")),az(r.qm,(0,n.ab)("indicator.majorityRule.color","Line"),"color",(0,n.ab)("indicator.majorityRule.color.tooltip","Color of the line when exactly half the bars closed higher.")),az(r.cr,(0,n.ab)("indicator.majorityRule.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.majorityRule.bullColor.tooltip","Color of the line and fill while more than half the bars closed higher.")),az(r.TV,(0,n.ab)("indicator.majorityRule.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.majorityRule.bearColor.tooltip","Color of the line and fill while fewer than half the bars closed higher.")),aF("gradientFill",(0,n.ab)("indicator.majorityRule.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.majorityRule.gradientFill.tooltip","Fills the area between the line and the midline, following the line color."))],compute:(e,t)=>{let i=n_(t,"length",14),o=ae(ap(n7(e)),e=>+(e>0));return aG({key:"majority",title:(0,n.ab)("indicator.majorityRule.plot.majority","Majority Rule"),values:ae(ao(o,i),e=>100*e/i),baseline:50,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,zeroTitle:(0,n.ab)("indicator.common.level.midline","Midline"),fill:nJ(t,"gradientFill",!0)})}},hb={type:"advance-decline",title:(0,n.ab)("indicator.advanceDecline.title","Advance/Decline"),overlay:!1,inputs:[aI(10,"length",(0,n.ab)("indicator.advanceDecline.length","Length"),5e3,(0,n.ab)("indicator.advanceDecline.length.tooltip","Number of bars counted. The reading divides how many closed above their open by how many closed below it.")),az(r.qm,(0,n.ab)("indicator.advanceDecline.color","Line"),"color",(0,n.ab)("indicator.advanceDecline.color.tooltip","Color of the line when up bars and down bars are level.")),az(r.cr,(0,n.ab)("indicator.advanceDecline.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.advanceDecline.bullColor.tooltip","Color of the line and fill while up bars outnumber down bars.")),az(r.TV,(0,n.ab)("indicator.advanceDecline.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.advanceDecline.bearColor.tooltip","Color of the line and fill while down bars outnumber up bars.")),aF("gradientFill",(0,n.ab)("indicator.advanceDecline.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.advanceDecline.gradientFill.tooltip","Fills the area between the line and 1, following the line color."))],compute:(e,t)=>{let i=n_(t,"length",10),o=ao(e.map(e=>+(e.close>e.open)),i),l=ao(e.map(e=>+(e.close<e.open)),i);return aG({key:"ratio",title:(0,n.ab)("indicator.advanceDecline.plot.ratio","Advance/Decline"),values:n9(o,l,(e,t)=>0===t?e:e/t),baseline:1,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,zeroTitle:(0,n.ab)("indicator.advanceDecline.level.even","Even"),fill:nJ(t,"gradientFill",!0)})}},hf={type:"aroon",title:(0,n.ab)("indicator.aroon.title","Aroon"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.aroon.length","Length"),5e3,(0,n.ab)("indicator.aroon.length.tooltip","Lookback length used to locate the highest high and lowest low.")),az(r.cr,(0,n.ab)("indicator.aroon.upColor","Aroon Up"),"upColor",(0,n.ab)("indicator.aroon.upColor.tooltip","Color of the Aroon Up line.")),az(r.TV,(0,n.ab)("indicator.aroon.downColor","Aroon Down"),"downColor",(0,n.ab)("indicator.aroon.downColor.tooltip","Color of the Aroon Down line."))],compute:(e,t)=>{let i=n_(t,"length",14),o=ae(ai(n6(e),i,(e,t,i)=>{let o=-1/0,r=i;for(let l=t;l<=i;l++)e[l]>=o&&(o=e[l],r=l);return i-r}),e=>100*(i-e)/i),l=ae(ai(n8(e),i,(e,t,i)=>{let o=1/0,r=i;for(let l=t;l<=i;l++)e[l]<=o&&(o=e[l],r=l);return i-r}),e=>100*(i-e)/i);return{plots:[{key:"up",title:(0,n.ab)("indicator.aroon.plot.up","Aroon Up"),values:o,color:nQ(t,"upColor",r.cr)},{key:"down",title:(0,n.ab)("indicator.aroon.plot.down","Aroon Down"),values:l,color:nQ(t,"downColor",r.TV)}]}}},hv={type:"average-directional-index",title:(0,n.ab)("indicator.averageDirectionalIndex.title","Average Directional Index"),shortTitle:(0,n.ab)("indicator.averageDirectionalIndex.shortTitle","ADX"),overlay:!1,inputs:[aI(14,"diLength",(0,n.ab)("indicator.averageDirectionalIndex.diLength","DI Length"),5e3,(0,n.ab)("indicator.averageDirectionalIndex.diLength.tooltip","Wilder RMA smoothing length applied to directional movement and true range when computing +DI and −DI.")),aI(14,"adxLength",(0,n.ab)("indicator.averageDirectionalIndex.adxLength","ADX Smoothing"),5e3,(0,n.ab)("indicator.averageDirectionalIndex.adxLength.tooltip","Wilder RMA smoothing length applied to DX to obtain the ADX line.")),aB("keyLevel",(0,n.ab)("indicator.averageDirectionalIndex.keyLevel","Key Level"),25,0,100,1,(0,n.ab)("indicator.averageDirectionalIndex.keyLevel.tooltip","Trend strength reference level; ADX above it is commonly read as a trending market.")),az(r.cr,(0,n.ab)("indicator.averageDirectionalIndex.plusDiColor","+DI Color"),"plusDiColor",(0,n.ab)("indicator.averageDirectionalIndex.plusDiColor.tooltip","Color of the plus directional indicator, and of the ADX line above the key level while +DI leads.")),az(r.TV,(0,n.ab)("indicator.averageDirectionalIndex.minusDiColor","−DI Color"),"minusDiColor",(0,n.ab)("indicator.averageDirectionalIndex.minusDiColor.tooltip","Color of the minus directional indicator, and of the ADX line above the key level while −DI leads.")),az(r.qm,(0,n.ab)("indicator.averageDirectionalIndex.adxColor","ADX Color"),"adxColor",(0,n.ab)("indicator.averageDirectionalIndex.adxColor.tooltip","Color of the ADX line while it sits below the key level — no trend strong enough to trade."))],compute:(e,t)=>{let i=n_(t,"diLength",14),o=e.length,l=Array(o).fill(NaN),a=Array(o).fill(NaN);for(let t=1;t<o;t++){let i=e[t].high-e[t-1].high,o=e[t-1].low-e[t].low;l[t]=i>o&&i>0?i:0,a[t]=o>i&&o>0?o:0}let s=ac(am(e),i),h=n9(ac(l,i),s,(e,t)=>0===t?0:100*e/t),d=n9(ac(a,i),s,(e,t)=>0===t?0:100*e/t),c=ac(n9(h,d,(e,t)=>e+t===0?0:100*Math.abs(e-t)/(e+t)),n_(t,"adxLength",14)),p=nQ(t,"plusDiColor",r.cr),u=nQ(t,"minusDiColor",r.TV),g=nQ(t,"adxColor",r.qm),m=n_(t,"keyLevel",25),b=c.map((e,t)=>Number.isFinite(e)?e<=m?g:(h[t]??0)>(d[t]??0)?p:u:null);return{plots:[{key:"plusDi",title:(0,n.ab)("indicator.averageDirectionalIndex.plot.plusDi","+DI"),values:h,color:aD(p,30)},{key:"minusDi",title:"-DI",displayTitle:(0,n.ab)("indicator.averageDirectionalIndex.plot.minusDi","−DI"),values:d,color:aD(u,30)},{key:"adx",title:(0,n.ab)("indicator.averageDirectionalIndex.plot.adx","ADX"),values:c,color:g,width:2,colors:b}],levels:[{key:"keyLevel",price:m,color:r.qm,lineStyle:"dashed",title:(0,n.ab)("indicator.averageDirectionalIndex.level.keyLevel","Key Level")}]}}},hy={type:"vortex-indicator",title:(0,n.ab)("indicator.vortexIndicator.title","Vortex Indicator"),shortTitle:(0,n.ab)("indicator.vortexIndicator.shortTitle","VI"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.vortexIndicator.length","Length"),5e3,(0,n.ab)("indicator.vortexIndicator.length.tooltip","Number of bars used to sum the vortex movements (VM+ and VM−) and the true range.")),az(r.cr,(0,n.ab)("indicator.vortexIndicator.plusColor","VI+"),"plusColor",(0,n.ab)("indicator.vortexIndicator.plusColor.tooltip","Color of the positive vortex line (VI+).")),az(r.TV,(0,n.ab)("indicator.vortexIndicator.minusColor","VI−"),"minusColor",(0,n.ab)("indicator.vortexIndicator.minusColor.tooltip","Color of the negative vortex line (VI−).")),az(r.qm,(0,n.ab)("indicator.vortexIndicator.baselineColor","Baseline"),"baselineColor",(0,n.ab)("indicator.vortexIndicator.baselineColor.tooltip","Color of the dotted baseline drawn at 1."))],compute:(e,t)=>{let i=n_(t,"length",14),o=e.length,l=Array(o).fill(NaN),a=Array(o).fill(NaN);for(let t=1;t<o;t++)l[t]=Math.abs(e[t].high-e[t-1].low),a[t]=Math.abs(e[t].low-e[t-1].high);let s=ao(am(e),i);return{plots:[{key:"viPlus",title:(0,n.ab)("indicator.vortexIndicator.plot.viPlus","VI+"),values:n9(ao(l,i),s,(e,t)=>0===t?NaN:e/t),color:nQ(t,"plusColor",r.cr)},{key:"viMinus",title:"VI-",displayTitle:(0,n.ab)("indicator.vortexIndicator.plot.viMinus","VI−"),values:n9(ao(a,i),s,(e,t)=>0===t?NaN:e/t),color:nQ(t,"minusColor",r.TV)}],levels:[{key:"baseline",price:1,color:nQ(t,"baselineColor",r.qm),lineStyle:"dotted",title:(0,n.ab)("indicator.vortexIndicator.level.baseline","Baseline")}]}}},hw={type:"trend-strength-index",title:(0,n.ab)("indicator.trendStrengthIndex.title","Trend Strength Index"),overlay:!1,inputs:[{...aI(14,"length",(0,n.ab)("indicator.trendStrengthIndex.length","Length"),5e3,(0,n.ab)("indicator.trendStrengthIndex.length.tooltip","Number of bars over which the source is correlated with time.")),min:2},aR("Close","source",(0,n.ab)("indicator.trendStrengthIndex.source","Source"),(0,n.ab)("indicator.trendStrengthIndex.source.tooltip","Price series correlated with time.")),az(r.qm,(0,n.ab)("indicator.trendStrengthIndex.color","Line"),"color",(0,n.ab)("indicator.trendStrengthIndex.color.tooltip","Color of the line when the reading sits exactly at zero.")),az(r.cr,(0,n.ab)("indicator.trendStrengthIndex.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.trendStrengthIndex.bullColor.tooltip","Color of the line and fill while the reading is above zero: price has been rising in step with time.")),az(r.TV,(0,n.ab)("indicator.trendStrengthIndex.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.trendStrengthIndex.bearColor.tooltip","Color of the line and fill while the reading is below zero: price has been falling in step with time.")),aF("gradientFill",(0,n.ab)("indicator.trendStrengthIndex.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.trendStrengthIndex.gradientFill.tooltip","Fills the area between the line and zero, following the line color."))],compute:(e,t)=>aG({key:"tsi",title:(0,n.ab)("indicator.trendStrengthIndex.plot.tsi","Trend Strength"),values:aC(n3(e,nQ(t,"source","Close")),function(e){let t=Array(e);for(let i=0;i<e;i++)t[i]=i;return t}(e.length),n_(t,"length",14)),ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm,fill:nJ(t,"gradientFill",!0)})},hC=[.71,2.14,3.57,5],hx={type:"chop-zone",title:(0,n.ab)("indicator.chopZone.title","Chop Zone"),overlay:!1,inputs:[az(r.cr,(0,n.ab)("indicator.chopZone.bullColor","Rising"),"bullColor",(0,n.ab)("indicator.chopZone.bullColor.tooltip","Color of the steepest rising zone. The three gentler rising zones blend from the flat color toward it.")),az(r.TV,(0,n.ab)("indicator.chopZone.bearColor","Falling"),"bearColor",(0,n.ab)("indicator.chopZone.bearColor.tooltip","Color of the steepest falling zone. The three gentler falling zones blend from the flat color toward it.")),az(r.Nz,(0,n.ab)("indicator.chopZone.flatColor","Flat"),"flatColor",(0,n.ab)("indicator.chopZone.flatColor.tooltip","Color of the bars where the trend line is flat: a choppy market."))],compute:(e,t)=>{let i=ad(n7(e),34),o=aa(n6(e),30),l=as(n6(e),30),a=nQ(t,"bullColor",r.cr),s=nQ(t,"bearColor",r.TV),h=nQ(t,"flatColor",r.Nz),d=hC.length,c=Array(e.length).fill(NaN),p=Array(e.length).fill(null);for(let t=1;t<e.length;t++){let r=i[t],n=i[t-1],u=o[t],g=l[t];if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(u)||!Number.isFinite(g))continue;let m=e[t],b=(m.high+m.low+m.close)/3,f=u-g,v=f>0&&0!==b?(r-n)/b*(25/f*g):0,y=Math.round(180*Math.atan(Math.abs(v))/Math.PI),w=function(e){let t=Math.abs(e),i=0;for(let e of hC)t>=e&&(i+=1);return e<0?-i:i}(v<0?-y:y);c[t]=1,p[t]=0===w?h:aY(Math.abs(w),0,d,h,w>0?a:s)}return{plots:[{key:"zone",title:(0,n.ab)("indicator.chopZone.plot.zone","Chop Zone"),values:c,kind:"columns",color:h,colors:p,base:0}]}}};function hk(e,t,i){return e.map((o,r)=>{if(!Number.isFinite(o))return null;let l=r>0&&Number.isFinite(e[r-1])?e[r-1]:o;return o>l?i:t})}function hS(e,t,i,o,l,n,a=1){return{plots:[{key:e,title:t,values:i,color:l,width:a,colors:o},aW("zeroAnchor","Zero Anchor",i.length,0)],bands:[{key:"wash",from:e,to:"zeroAnchor",color:aD(r.qm,100),gradient:aU(i,0,(e,t)=>o[t]??l,n)}]}}function hT(e,t,i,o){let l=as(i,100),n=aa(i,100),a=i.map((e,t)=>Number.isFinite(e)?aY(e,l[t],n[t],r.qm,o):null);return hS(e,t,i,a,o,75,2)}var hM={type:"average-true-range",title:(0,n.ab)("indicator.averageTrueRange.title","Average True Range"),shortTitle:(0,n.ab)("indicator.averageTrueRange.shortTitle","ATR"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.averageTrueRange.length","Length"),5e3,(0,n.ab)("indicator.averageTrueRange.length.tooltip","Number of bars used to average the true range.")),aO("smoothing",(0,n.ab)("indicator.averageTrueRange.smoothing","Smoothing"),"RMA",["RMA","SMA","EMA","WMA"],(0,n.ab)("indicator.averageTrueRange.smoothing.tooltip","Moving average applied to the true range. RMA is Wilder's original smoothing used by the classic ATR.")),az(r.qm,(0,n.ab)("indicator.averageTrueRange.color","ATR Line"),"color",(0,n.ab)("indicator.averageTrueRange.color.tooltip","Color of the ATR line while volatility contracts or holds flat.")),az(r.Nz,(0,n.ab)("indicator.averageTrueRange.expandColor","Expanding"),"expandColor",(0,n.ab)("indicator.averageTrueRange.expandColor.tooltip","Color of the ATR line while it rises — volatility expanding bar to bar."))],compute:(e,t)=>{let i=n_(t,"length",14),o=am(e),l=nQ(t,"smoothing","RMA"),a="SMA"===l?ar(o,i):"EMA"===l?ad(o,i):"WMA"===l?al(o,i):ac(o,i),s=nQ(t,"color",r.qm);return hS("atr",(0,n.ab)("indicator.averageTrueRange.plot.atr","ATR"),a,hk(a,s,nQ(t,"expandColor",r.Nz)),s,75)}},hL={type:"historical-volatility",title:(0,n.ab)("indicator.historicalVolatility.title","Historical Volatility"),shortTitle:(0,n.ab)("indicator.historicalVolatility.shortTitle","HV"),overlay:!1,inputs:[{...aI(10,"length",(0,n.ab)("indicator.historicalVolatility.length","Length"),5e3,(0,n.ab)("indicator.historicalVolatility.length.tooltip","Lookback window in bars for the standard deviation of close-to-close log returns.")),min:2},aF("annualize",(0,n.ab)("indicator.historicalVolatility.annualize","Annualize"),!0,void 0,(0,n.ab)("indicator.historicalVolatility.annualize.tooltip","Scale the per-bar volatility to an annual figure by multiplying by the square root of the periods per year.")),aE("periodsPerYear",(0,n.ab)("indicator.historicalVolatility.periodsPerYear","Periods Per Year"),252,1,1e5,(0,n.ab)("indicator.historicalVolatility.periodsPerYear.tooltip","Number of periods in a year used for annualization: 252 for daily bars, 52 for weekly, 12 for monthly.")),az(r.Nz,(0,n.ab)("indicator.historicalVolatility.color","Volatility Line"),"color",(0,n.ab)("indicator.historicalVolatility.color.tooltip","Color of the line at its recent highs; it fades toward grey as volatility contracts."))],compute:(e,t)=>{let i=n_(t,"length",10),o=at(ae(n7(e),Math.log),ag(ae(n7(e),Math.log),1)),l=ae(ao(o,i),e=>e/i),a=ao(ae(o,e=>e*e),i),s=nJ(t,"annualize",!0)?Math.sqrt(n_(t,"periodsPerYear",252)):1,h=n9(a,l,(e,t)=>Math.sqrt(Math.max(e-i*t*t,0)/(i-1))*s*100);return hT("hv",(0,n.ab)("indicator.historicalVolatility.plot.hv","Historical Volatility"),h,nQ(t,"color",r.Nz))}},hA=2*Math.LN2-1,hP={type:"volatility-ohlc",title:(0,n.ab)("indicator.volatilityOhlc.title","Volatility O-H-L-C"),shortTitle:(0,n.ab)("indicator.volatilityOhlc.shortTitle","Vol OHLC"),overlay:!1,inputs:[aI(10,"length",(0,n.ab)("indicator.volatilityOhlc.length","Length"),5e3,(0,n.ab)("indicator.volatilityOhlc.length.tooltip","Number of bars whose daily variance estimates are averaged.")),aB("marketClosed",(0,n.ab)("indicator.volatilityOhlc.marketClosed","Market Closed Fraction"),0,0,.999,.01,(0,n.ab)("indicator.volatilityOhlc.marketClosed.tooltip","Share of the day the market spends closed, from 0 to 0.999. At 0 only each bar’s own range counts; above 0 the gap from the previous close is weighed in.")),aE("daysPerYear",(0,n.ab)("indicator.volatilityOhlc.daysPerYear","Days Per Year"),252,1,366,(0,n.ab)("indicator.volatilityOhlc.daysPerYear.tooltip","Trading days in a year, used to annualize the daily variance.")),az(r.Nz,(0,n.ab)("indicator.volatilityOhlc.color","Volatility Line"),"color",(0,n.ab)("indicator.volatilityOhlc.color.tooltip","Color of the line at its recent highs; it fades toward grey as volatility contracts."))],compute:(e,t)=>{let i=ax(e),o=Math.min(Math.max(n_(t,"marketClosed",0),0),.999),l=e.map((t,r)=>{let l=i[r];if(!Number.isFinite(l)||!(t.low>0)||!(t.open>0))return NaN;let n=Math.log(t.high/t.low),a=Math.log(t.close/t.open),s=.5*n*n-hA*a*a;if(0===o)return s/l;let h=Math.log(t.open/e[r-1].close);return(.12*h*h/o+.88*s/(1-o))/l}),a=n_(t,"daysPerYear",252),s=ae(ar(l,n_(t,"length",10)),e=>100*Math.sqrt(e*a));return hT("vol",(0,n.ab)("indicator.volatilityOhlc.plot.vol","Volatility"),s,nQ(t,"color",r.Nz))}},hI={type:"volatility-close-to-close",title:(0,n.ab)("indicator.volatilityCloseToClose.title","Volatility Close-to-Close"),shortTitle:(0,n.ab)("indicator.volatilityCloseToClose.shortTitle","Vol Close-to-Close"),overlay:!1,inputs:[{...aI(10,"length",(0,n.ab)("indicator.volatilityCloseToClose.length","Length"),5e3,(0,n.ab)("indicator.volatilityCloseToClose.length.tooltip","Number of bar-to-bar close log returns used for the sample variance.")),min:2},aE("daysPerYear",(0,n.ab)("indicator.volatilityCloseToClose.daysPerYear","Days Per Year"),252,1,366,(0,n.ab)("indicator.volatilityCloseToClose.daysPerYear.tooltip","Trading days in a year, used to annualize the variance.")),az(r.Nz,(0,n.ab)("indicator.volatilityCloseToClose.color","Volatility Line"),"color",(0,n.ab)("indicator.volatilityCloseToClose.color.tooltip","Color of the line at its recent highs; it fades toward grey as volatility contracts."))],compute:(e,t)=>{let i=function(e,t){return t<2?aT(e.length,NaN):ai(e,t,(e,i,o)=>{let r=0;for(let t=i;t<=o;t++)r+=e[t];let l=r/t,n=0;for(let t=i;t<=o;t++){let i=e[t]-l;n+=i*i}return n/(t-1)})}(aM(n7(e)),n_(t,"length",10)),o=n_(t,"daysPerYear",252),l=ae(i,e=>100*Math.sqrt(Math.max(e,0)*o));return hT("vol",(0,n.ab)("indicator.volatilityCloseToClose.plot.vol","Volatility"),l,nQ(t,"color",r.Nz))}},hE={type:"volatility-zero-trend",title:(0,n.ab)("indicator.volatilityZeroTrend.title","Volatility Zero Trend Close-to-Close"),shortTitle:(0,n.ab)("indicator.volatilityZeroTrend.shortTitle","Vol Zero Trend"),overlay:!1,inputs:[aI(10,"length",(0,n.ab)("indicator.volatilityZeroTrend.length","Length"),5e3,(0,n.ab)("indicator.volatilityZeroTrend.length.tooltip","Number of close-to-close returns averaged.")),aE("daysPerYear",(0,n.ab)("indicator.volatilityZeroTrend.daysPerYear","Days Per Year"),252,1,366,(0,n.ab)("indicator.volatilityZeroTrend.daysPerYear.tooltip","Trading days in a year, used to annualize the daily variance.")),az(r.Nz,(0,n.ab)("indicator.volatilityZeroTrend.color","Volatility Line"),"color",(0,n.ab)("indicator.volatilityZeroTrend.color.tooltip","Color of the line at its recent highs; it fades toward grey as volatility contracts."))],compute:(e,t)=>{let i=ae(n7(e),Math.log),o=n9(at(i,ag(i,1)),ax(e),(e,t)=>e*e/t),l=n_(t,"daysPerYear",252),a=ae(ar(o,n_(t,"length",10)),e=>100*Math.sqrt(e*l));return hT("vol",(0,n.ab)("indicator.volatilityZeroTrend.plot.vol","Volatility"),a,nQ(t,"color",r.Nz))}},hB={type:"chaikin-volatility",title:(0,n.ab)("indicator.chaikinVolatility.title","Chaikin Volatility"),shortTitle:(0,n.ab)("indicator.chaikinVolatility.shortTitle","CHV"),overlay:!1,inputs:[aI(10,"emaLength",(0,n.ab)("indicator.chaikinVolatility.emaLength","EMA Length"),5e3,(0,n.ab)("indicator.chaikinVolatility.emaLength.tooltip","Length of the exponential moving average applied to the bar high-low range.")),aI(10,"rocLength",(0,n.ab)("indicator.chaikinVolatility.rocLength","ROC Length"),5e3,(0,n.ab)("indicator.chaikinVolatility.rocLength.tooltip","Number of bars used for the rate of change of the smoothed high-low range.")),az(r.qm,(0,n.ab)("indicator.chaikinVolatility.color","CHV Color"),"color",(0,n.ab)("indicator.chaikinVolatility.color.tooltip","Color of the Chaikin Volatility line.")),az(r.Nz,(0,n.ab)("indicator.chaikinVolatility.expansionColor","Expansion"),"expansionColor",(0,n.ab)("indicator.chaikinVolatility.expansionColor.tooltip","Line and fill color while the reading is above zero, when the smoothed range is wider than it was at the start of the ROC Length lookback."))],compute:(e,t)=>{let i=ad(at(n6(e),n8(e)),n_(t,"emaLength",10)),o=ag(i,n_(t,"rocLength",10)),l=n9(i,o,(e,t)=>0===t?NaN:100*(e-t)/t),a=nQ(t,"color",r.qm),s=nQ(t,"expansionColor",r.Nz);return aG({key:"chv",title:(0,n.ab)("indicator.chaikinVolatility.plot.chv","Chaikin Volatility"),values:l,ink:{bull:s,bear:a,neutral:a},zeroInk:r.qm})}},hF={type:"mass-index",title:(0,n.ab)("indicator.massIndex.title","Mass Index"),shortTitle:(0,n.ab)("indicator.massIndex.shortTitle","MI"),overlay:!1,inputs:[aI(25,"length",(0,n.ab)("indicator.massIndex.length","Sum Length"),5e3,(0,n.ab)("indicator.massIndex.length.tooltip","Number of bars over which the single/double EMA ratio is summed.")),aI(9,"emaLength",(0,n.ab)("indicator.massIndex.emaLength","EMA Length"),5e3,(0,n.ab)("indicator.massIndex.emaLength.tooltip","Length of the single EMA of the high-low range and of its double smoothing.")),aB("setupLevel",(0,n.ab)("indicator.massIndex.setupLevel","Setup Level"),27,0,1e3,.1,(0,n.ab)("indicator.massIndex.setupLevel.tooltip","Reversal bulge setup level; a rise above it arms the pattern.")),aB("triggerLevel",(0,n.ab)("indicator.massIndex.triggerLevel","Trigger Level"),26.5,0,1e3,.1,(0,n.ab)("indicator.massIndex.triggerLevel.tooltip","Reversal bulge trigger level; a decline below it after a setup completes the pattern.")),az(r.qm,(0,n.ab)("indicator.massIndex.color","Mass Index"),"color",(0,n.ab)("indicator.massIndex.color.tooltip","Line color while no reversal bulge is armed.")),az(r.Nz,(0,n.ab)("indicator.massIndex.armedColor","Armed"),"armedColor",(0,n.ab)("indicator.massIndex.armedColor.tooltip","Line color from the rise above the setup level until the decline below the trigger level.")),az(r.qm,(0,n.ab)("indicator.massIndex.levelsColor","Levels"),"levelsColor",(0,n.ab)("indicator.massIndex.levelsColor.tooltip","Reversal bulge levels color."))],compute:(e,t)=>{let i=n_(t,"emaLength",9),o=ad(at(n6(e),n8(e)),i),l=ao(n9(o,ad(o,i),(e,t)=>0===t?1:e/t),n_(t,"length",25)),a=n_(t,"setupLevel",27),s=n_(t,"triggerLevel",26.5),h=nQ(t,"color",r.qm),d=nQ(t,"armedColor",r.Nz),c=nQ(t,"levelsColor",r.qm),p=!1,u=l.map(e=>Number.isFinite(e)?(p=e>a||!(e<s)&&p)?d:h:null);return{plots:[{key:"mi",title:(0,n.ab)("indicator.massIndex.plot.mi","Mass Index"),values:l,color:h,colors:u},aW("setupAnchor","Setup Anchor",l.length,a),aW("triggerAnchor","Trigger Anchor",l.length,s)],bands:[{key:"bulge",from:"setupAnchor",to:"triggerAnchor",color:aD(d,90)}],levels:[{key:"setup",price:a,color:c,lineStyle:"dashed",title:(0,n.ab)("indicator.massIndex.level.setup","Setup Level")},{key:"trigger",price:s,color:c,lineStyle:"dashed",title:(0,n.ab)("indicator.massIndex.level.trigger","Trigger Level")}]}}},hO={type:"standard-deviation",title:(0,n.ab)("indicator.standardDeviation.title","Standard Deviation"),shortTitle:(0,n.ab)("indicator.standardDeviation.shortTitle","StdDev"),overlay:!1,inputs:[aI(20,"length",(0,n.ab)("indicator.standardDeviation.length","Length"),5e3,(0,n.ab)("indicator.standardDeviation.length.tooltip","Number of bars used to compute the standard deviation.")),aR("Close","source",(0,n.ab)("indicator.standardDeviation.source","Source"),(0,n.ab)("indicator.standardDeviation.source.tooltip","Price series the standard deviation is calculated on.")),az(r.qm,(0,n.ab)("indicator.standardDeviation.color","Standard Deviation"),"color",(0,n.ab)("indicator.standardDeviation.color.tooltip","Line color while volatility contracts or holds flat.")),az(r.Nz,(0,n.ab)("indicator.standardDeviation.expandColor","Expanding"),"expandColor",(0,n.ab)("indicator.standardDeviation.expandColor.tooltip","Line and fill color while volatility expands bar to bar."))],compute:(e,t)=>{let i=an(n3(e,nQ(t,"source","Close")),n_(t,"length",20)),o=nQ(t,"color",r.qm);return hS("stdev",(0,n.ab)("indicator.standardDeviation.plot.stdev","Standard Deviation"),i,hk(i,o,nQ(t,"expandColor",r.Nz)),o,80)}},hR={type:"standard-error",title:(0,n.ab)("indicator.standardError.title","Standard Error"),shortTitle:(0,n.ab)("indicator.standardError.shortTitle","StdErr"),overlay:!1,inputs:[{...aI(14,"length",(0,n.ab)("indicator.standardError.length","Length"),5e3,(0,n.ab)("indicator.standardError.length.tooltip","Number of bars the regression line is fitted over.")),min:3},aR("Close","source",(0,n.ab)("indicator.standardError.source","Source"),(0,n.ab)("indicator.standardError.source.tooltip","Price series the regression line is fitted to.")),az(r.qm,(0,n.ab)("indicator.standardError.color","Standard Error"),"color",(0,n.ab)("indicator.standardError.color.tooltip","Line color while the reading contracts or holds flat.")),az(r.Nz,(0,n.ab)("indicator.standardError.expandColor","Expanding"),"expandColor",(0,n.ab)("indicator.standardError.expandColor.tooltip","Line and fill color while the reading expands bar to bar."))],compute:(e,t)=>{let i=aw(n3(e,nQ(t,"source","Close")),n_(t,"length",14)),o=nQ(t,"color",r.qm);return hS("se",(0,n.ab)("indicator.standardError.plot.se","Standard Error"),i,hk(i,o,nQ(t,"expandColor",r.Nz)),o,80)}},hN={type:"ulcer-index",title:(0,n.ab)("indicator.ulcerIndex.title","Ulcer Index"),overlay:!1,inputs:[{...aI(14,"length",(0,n.ab)("indicator.ulcerIndex.length","Length"),500,(0,n.ab)("indicator.ulcerIndex.length.tooltip","Lookback window. At each bar the percentage drawdown from the window's running maximum is squared; the squares are averaged and the root taken.")),min:2},aR("Close","source",(0,n.ab)("indicator.ulcerIndex.source","Source"),(0,n.ab)("indicator.ulcerIndex.source.tooltip","Price series the Ulcer Index is computed on. Close is the standard choice.")),aB("threshold",(0,n.ab)("indicator.ulcerIndex.threshold","Stress Threshold"),5,0,1e3,.25,(0,n.ab)("indicator.ulcerIndex.threshold.tooltip","Reference level drawn as a dashed line. The index scales with the instrument's volatility and the window length, so set it relative to its own history.")),az(r.qm,(0,n.ab)("indicator.ulcerIndex.color","Ulcer Index"),"color",(0,n.ab)("indicator.ulcerIndex.color.tooltip","Color of the index near zero; it blends toward the stress color as the reading approaches the threshold.")),az(r.TV,(0,n.ab)("indicator.ulcerIndex.stressColor","Stress"),"stressColor",(0,n.ab)("indicator.ulcerIndex.stressColor.tooltip","Color of the index at and beyond the stress threshold.")),aF("gradientFill",(0,n.ab)("indicator.ulcerIndex.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.ulcerIndex.gradientFill.tooltip","Vertical gradient between zero and the Ulcer Index, fully transparent at zero.")),aF("showDrawdown",(0,n.ab)("indicator.ulcerIndex.showDrawdown","Drawdown %"),!1,aP,(0,n.ab)("indicator.ulcerIndex.showDrawdown.tooltip","Plot the current percentage drawdown from the window high as columns below zero — the raw ingredient the index averages.")),az(aD(r.TV,50),(0,n.ab)("indicator.ulcerIndex.drawdownColor","Drawdown Color"),"drawdownColor",(0,n.ab)("indicator.ulcerIndex.drawdownColor.tooltip","Color of the drawdown columns.")),az(r.qm,(0,n.ab)("indicator.ulcerIndex.thresholdColor","Threshold"),"thresholdColor",(0,n.ab)("indicator.ulcerIndex.thresholdColor.tooltip","Color of the stress threshold line."))],compute:(e,t)=>{let i=n_(t,"length",14),o=n3(e,nQ(t,"source","Close")),l=o.length,a=Array(l).fill(NaN),s=Array(l).fill(NaN);for(let e=i-1;e<l;e++){let t=NaN,r=0,l=!0,n=NaN;for(let a=e-i+1;a<=e;a++){let e=o[a];if(!Number.isFinite(e)||(t=Number.isFinite(t)?Math.max(t,e):e)<=0){l=!1;break}r+=(n=100*(e-t)/t)*n}l&&(a[e]=Math.sqrt(r/i),s[e]=n)}let h=nQ(t,"color",r.qm),d=nQ(t,"stressColor",r.TV),c=n_(t,"threshold",5),p=a.map(e=>Number.isFinite(e)?c>0?aY(e,0,c,h,d):d:null),u=[{key:"ui",title:(0,n.ab)("indicator.ulcerIndex.plot.ui","Ulcer Index"),values:a,color:h,colors:p}],g=[];return nJ(t,"gradientFill",!0)&&(u.push(aW("zeroAnchor","Zero Base",l,0)),g.push({key:"wash",from:"ui",to:"zeroAnchor",color:aD(r.qm,100),gradient:aU(a,0,(e,t)=>p[t]??h)})),nJ(t,"showDrawdown",!1)&&u.push({key:"dd",title:(0,n.ab)("indicator.ulcerIndex.plot.dd","Drawdown %"),values:s,kind:"columns",color:nQ(t,"drawdownColor",aD(r.TV,50)),base:0}),{plots:u,bands:g,levels:[{key:"zero",price:0,color:aD(r.qm,50),lineStyle:"dotted",title:(0,n.ab)("indicator.ulcerIndex.level.zero","Zero Line")},{key:"threshold",price:c,color:nQ(t,"thresholdColor",r.qm),lineStyle:"dashed",title:(0,n.ab)("indicator.ulcerIndex.level.threshold","Stress Threshold")}]}}},hz={type:"choppiness-index",title:(0,n.ab)("indicator.choppinessIndex.title","Choppiness Index"),shortTitle:(0,n.ab)("indicator.choppinessIndex.shortTitle","CHOP"),overlay:!1,inputs:[{...aI(14,"length",(0,n.ab)("indicator.choppinessIndex.length","Length"),5e3,(0,n.ab)("indicator.choppinessIndex.length.tooltip","Number of bars used to sum true ranges and to measure the highest high − lowest low range.")),min:2},aB("upperBand",(0,n.ab)("indicator.choppinessIndex.upperBand","Upper Band"),61.8,0,100,.1,(0,n.ab)("indicator.choppinessIndex.upperBand.tooltip","Readings above this level indicate a choppy, range-bound market.")),aB("lowerBand",(0,n.ab)("indicator.choppinessIndex.lowerBand","Lower Band"),38.2,0,100,.1,(0,n.ab)("indicator.choppinessIndex.lowerBand.tooltip","Readings below this level indicate a strong trend.")),az(r.qm,(0,n.ab)("indicator.choppinessIndex.color","CHOP Line"),"color",(0,n.ab)("indicator.choppinessIndex.color.tooltip","Color of the Choppiness Index line.")),az(r.cr,(0,n.ab)("indicator.choppinessIndex.trendingColor","Trending"),"trendingColor",(0,n.ab)("indicator.choppinessIndex.trendingColor.tooltip","Line, fill and zone color toward and below the lower band — a trending market.")),az(r.TV,(0,n.ab)("indicator.choppinessIndex.choppyColor","Choppy"),"choppyColor",(0,n.ab)("indicator.choppinessIndex.choppyColor.tooltip","Line, fill and zone color toward and above the upper band — a choppy, range-bound market.")),az(aD(r.qm,90),(0,n.ab)("indicator.choppinessIndex.fillColor","Band Fill"),"fillColor",(0,n.ab)("indicator.choppinessIndex.fillColor.tooltip","Fill color of the zone between the upper and lower bands."))],compute:(e,t)=>{let i=n_(t,"length",14),o=ao(am(e),i),l=n9(aa(n6(e),i),as(n8(e),i),(e,t)=>e-t),a=n9(o,l,(e,t)=>t>0&&e>0?100*Math.log10(e/t)/Math.log10(i):NaN);return aj({key:"chop",title:(0,n.ab)("indicator.choppinessIndex.plot.chop","CHOP"),values:a,scale:{top:100,bottom:0},overbought:n_(t,"upperBand",61.8),oversold:n_(t,"lowerBand",38.2),ink:{low:nQ(t,"trendingColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"choppyColor",r.TV)},levelInk:r.qm,bandFill:nQ(t,"fillColor",aD(r.qm,90)),midpointWash:!0,levelTitles:{overbought:(0,n.ab)("indicator.choppinessIndex.level.upperBand","Upper Band"),oversold:(0,n.ab)("indicator.choppinessIndex.level.lowerBand","Lower Band")}})}};function hV(e){return e.map(e=>null!=e.volume&&Number.isFinite(e.volume)?e.high===e.low?0:(2*e.close-e.high-e.low)/(e.high-e.low)*e.volume:NaN)}function hD(e,t,i,o){return e.map((r,l)=>{if(!Number.isFinite(r))return null;let n=l>0?e[l-1]:NaN;return Number.isFinite(n)?r>n?t:r<n?i:o:o})}function h$(e,t,i,o){let r=Array(e.length).fill(NaN),l=i;for(let i=0;i<e.length;i++){let n=e[i].volume,a=i>0?e[i-1].volume:null,s=i>0?t[i-1]:NaN;null!=n&&null!=a&&Number.isFinite(n)&&Number.isFinite(a)&&o(n,a)&&Number.isFinite(s)&&0!==s&&(l*=1+(t[i]-s)/s),r[i]=l}return r}function hH(e,t,i,o,l,a,s,h=!1){return{plots:[{key:"signal",title:(0,n.ab)("indicator.regime.plot.signal","Signal EMA"),values:o,color:l.signal,...a?{}:{display:{pane:!1}}},{key:e,title:t,values:i,color:l.neutral,width:2,colors:i.map((e,t)=>Number.isFinite(e)?(e=>{let t=o[e],r=i[e];return h||!Number.isFinite(t)?l.neutral:r>t?l.bull:r<t?l.bear:l.neutral})(t):null)}],bands:s?[{key:"regime",from:e,to:"signal",color:aD(r.qm,100),gradient:i.map((e,t)=>{let i=o[t];if(!Number.isFinite(e)||!Number.isFinite(i))return null;let r=e>i,n=r?l.bull:l.bear;return{topValue:Math.max(e,i),bottomValue:Math.min(e,i),topColor:aD(n,r?50:100),bottomColor:aD(n,r?100:50)}})}]:[]}}var hW={type:"on-balance-volume",title:(0,n.ab)("indicator.onBalanceVolume.title","On Balance Volume"),shortTitle:(0,n.ab)("indicator.onBalanceVolume.shortTitle","OBV"),overlay:!1,inputs:[aF("smoothing",(0,n.ab)("indicator.onBalanceVolume.smoothing","Smoothing MA"),!1,aA,(0,n.ab)("indicator.onBalanceVolume.smoothing.tooltip","Display a moving average of OBV to act as a smoothing/signal line.")),aO("maType",(0,n.ab)("indicator.onBalanceVolume.maType","MA Type"),"SMA",["SMA","EMA","WMA","RMA (SMMA)"],(0,n.ab)("indicator.onBalanceVolume.maType.tooltip","Moving average type used for the smoothing MA.")),aI(20,"maLength",(0,n.ab)("indicator.onBalanceVolume.maLength","MA Length"),5e3,(0,n.ab)("indicator.onBalanceVolume.maLength.tooltip","Number of bars used for the smoothing MA.")),az(r.rD,(0,n.ab)("indicator.onBalanceVolume.color","OBV"),"color",(0,n.ab)("indicator.onBalanceVolume.color.tooltip","Color of the OBV line.")),az(r.Nz,(0,n.ab)("indicator.onBalanceVolume.maColor","Smoothing MA"),"maColor",(0,n.ab)("indicator.onBalanceVolume.maColor.tooltip","Color of the smoothing MA line."))],compute:(e,t)=>{let i=aS(n9(n4(e),ap(n7(e)),(e,t)=>t>0?e:t<0?-e:0)),o=[{key:"obv",title:(0,n.ab)("indicator.onBalanceVolume.plot.obv","OBV"),values:i,color:nQ(t,"color",r.rD)}];if(nJ(t,"smoothing",!1)){let e=n_(t,"maLength",20),l=nQ(t,"maType","SMA"),a="EMA"===l?ad(i,e):"WMA"===l?al(i,e):"RMA (SMMA)"===l?ac(i,e):ar(i,e);o.push({key:"ma",title:(0,n.ab)("indicator.onBalanceVolume.plot.ma","Smoothing MA"),values:a,color:nQ(t,"maColor",r.Nz)})}return{plots:o}}},hq={type:"net-volume",title:(0,n.ab)("indicator.netVolume.title","Net Volume"),overlay:!1,inputs:[az(r.cr,(0,n.ab)("indicator.netVolume.upColor","Up"),"upColor",(0,n.ab)("indicator.netVolume.upColor.tooltip","Color of the columns on bars that close above the previous close.")),az(r.TV,(0,n.ab)("indicator.netVolume.downColor","Down"),"downColor",(0,n.ab)("indicator.netVolume.downColor.tooltip","Color of the columns on bars that close below the previous close.")),az(r.qm,(0,n.ab)("indicator.netVolume.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.netVolume.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=n9(n4(e),ap(n7(e)),(e,t)=>t>0?e:t<0?-e:0),o=nQ(t,"upColor",r.cr),l=nQ(t,"downColor",r.TV);return{plots:[{key:"net",title:(0,n.ab)("indicator.netVolume.plot.net","Net Volume"),values:i,kind:"columns",color:o,colors:i.map(e=>Number.isFinite(e)?e<0?l:o:null),base:0}],levels:[{key:"zero",price:0,color:nQ(t,"zeroColor",r.qm),lineStyle:"dashed",title:(0,n.ab)("indicator.common.level.zero","Zero Line")}]}}},hU={type:"accumulation-distribution",title:(0,n.ab)("indicator.accumulationDistribution.title","Accumulation / Distribution"),shortTitle:(0,n.ab)("indicator.accumulationDistribution.shortTitle","A/D"),overlay:!1,inputs:[aF("slopeColoring",(0,n.ab)("indicator.accumulationDistribution.slopeColoring","Slope Coloring"),!0,aP,(0,n.ab)("indicator.accumulationDistribution.slopeColoring.tooltip","Color the line by its slope — bullish while rising (accumulation), bearish while falling (distribution).")),az(r.qm,(0,n.ab)("indicator.accumulationDistribution.color","A/D Line"),"color",(0,n.ab)("indicator.accumulationDistribution.color.tooltip","Color of the line when slope coloring is disabled or the line is flat.")),az(r.cr,(0,n.ab)("indicator.accumulationDistribution.bullColor","Rising"),"bullColor",(0,n.ab)("indicator.accumulationDistribution.bullColor.tooltip","Line color while the A/D Line rises.")),az(r.TV,(0,n.ab)("indicator.accumulationDistribution.bearColor","Falling"),"bearColor",(0,n.ab)("indicator.accumulationDistribution.bearColor.tooltip","Line color while the A/D Line falls."))],compute:(e,t)=>{let i=aS(hV(e)),o=nQ(t,"color",r.qm);return{plots:[{key:"ad",title:(0,n.ab)("indicator.accumulationDistribution.plot.ad","A/D"),values:i,color:o,...nJ(t,"slopeColoring",!0)?{colors:hD(i,nQ(t,"bullColor",r.cr),nQ(t,"bearColor",r.TV),o)}:{}}]}}},hj={type:"chaikin-money-flow",title:(0,n.ab)("indicator.chaikinMoneyFlow.title","Chaikin Money Flow"),shortTitle:(0,n.ab)("indicator.chaikinMoneyFlow.shortTitle","CMF"),overlay:!1,inputs:[aI(20,"length",(0,n.ab)("indicator.chaikinMoneyFlow.length","Length"),5e3,(0,n.ab)("indicator.chaikinMoneyFlow.length.tooltip","Lookback length over which money flow volume and volume are summed.")),az(r.qm,(0,n.ab)("indicator.chaikinMoneyFlow.color","CMF Line"),"color",(0,n.ab)("indicator.chaikinMoneyFlow.color.tooltip","Color of the Chaikin Money Flow line.")),az(r.cr,(0,n.ab)("indicator.chaikinMoneyFlow.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.chaikinMoneyFlow.bullColor.tooltip","Line and fill color while the CMF reads above zero (net money flowing in).")),az(r.TV,(0,n.ab)("indicator.chaikinMoneyFlow.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.chaikinMoneyFlow.bearColor.tooltip","Line and fill color while the CMF reads below zero (net money flowing out).")),az(r.qm,(0,n.ab)("indicator.chaikinMoneyFlow.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.chaikinMoneyFlow.zeroColor.tooltip","Color of the zero reference line."))],compute:(e,t)=>{let i=n_(t,"length",20),o=n9(ao(hV(e),i),ao(n4(e),i),(e,t)=>0===t?0:e/t);return aG({key:"cmf",title:(0,n.ab)("indicator.chaikinMoneyFlow.plot.cmf","CMF"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:nQ(t,"zeroColor",r.qm)})}},hG={type:"chaikin-oscillator",title:(0,n.ab)("indicator.chaikinOscillator.title","Chaikin Oscillator"),shortTitle:(0,n.ab)("indicator.chaikinOscillator.shortTitle","Chaikin Osc"),overlay:!1,inputs:[aI(3,"fastLength",(0,n.ab)("indicator.chaikinOscillator.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.chaikinOscillator.fastLength.tooltip","Length of the fast EMA applied to the accumulation/distribution line.")),aI(10,"slowLength",(0,n.ab)("indicator.chaikinOscillator.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.chaikinOscillator.slowLength.tooltip","Length of the slow EMA applied to the accumulation/distribution line.")),az(r.qm,(0,n.ab)("indicator.chaikinOscillator.color","Oscillator"),"color",(0,n.ab)("indicator.chaikinOscillator.color.tooltip","Color of the Chaikin Oscillator line.")),az(r.cr,(0,n.ab)("indicator.chaikinOscillator.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.chaikinOscillator.bullColor.tooltip","Line and fill color while the oscillator reads above zero (accumulation).")),az(r.TV,(0,n.ab)("indicator.chaikinOscillator.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.chaikinOscillator.bearColor.tooltip","Line and fill color while the oscillator reads below zero (distribution)."))],compute:(e,t)=>{let i=aS(hV(e)),o=at(ad(i,n_(t,"fastLength",3)),ad(i,n_(t,"slowLength",10)));return aG({key:"co",title:(0,n.ab)("indicator.chaikinOscillator.plot.co","Chaikin Oscillator"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm})}},hK={type:"ease-of-movement",title:(0,n.ab)("indicator.easeOfMovement.title","Ease of Movement"),shortTitle:(0,n.ab)("indicator.easeOfMovement.shortTitle","EOM"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.easeOfMovement.length","Length"),5e3,(0,n.ab)("indicator.easeOfMovement.length.tooltip","Number of bars in the simple moving average smoothing the 1-bar Ease of Movement values.")),aE("divisor",(0,n.ab)("indicator.easeOfMovement.divisor","Divisor"),1e4,1,1e9,(0,n.ab)("indicator.easeOfMovement.divisor.tooltip","Volume scaling constant of the box ratio; larger values scale the oscillator up. 10000 is the conventional default.")),az(r.qm,(0,n.ab)("indicator.easeOfMovement.color","EOM Line"),"color",(0,n.ab)("indicator.easeOfMovement.color.tooltip","Color of the line when it sits exactly at zero.")),az(r.cr,(0,n.ab)("indicator.easeOfMovement.bullColor","Above Zero"),"bullColor",(0,n.ab)("indicator.easeOfMovement.bullColor.tooltip","Color of the line and fill while Ease of Movement is positive.")),az(r.TV,(0,n.ab)("indicator.easeOfMovement.bearColor","Below Zero"),"bearColor",(0,n.ab)("indicator.easeOfMovement.bearColor.tooltip","Color of the line and fill while Ease of Movement is negative."))],compute:(e,t)=>{let i=n_(t,"divisor",1e4),o=ap(n3(e,"HL2")),l=e.map((e,t)=>{let r=o[t];return null!=e.volume&&Number.isFinite(e.volume)&&Number.isFinite(r)?0===e.volume?0:i*r*(e.high-e.low)/e.volume:NaN});return aG({key:"eom",title:(0,n.ab)("indicator.easeOfMovement.plot.eom","EOM"),values:ar(l,n_(t,"length",14)),ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"color",r.qm)},zeroInk:r.qm})}},hY={type:"force-index",title:(0,n.ab)("indicator.forceIndex.title","Force Index"),shortTitle:(0,n.ab)("indicator.forceIndex.shortTitle","FI"),overlay:!1,inputs:[aI(13,"length",(0,n.ab)("indicator.forceIndex.length","Length"),5e3,(0,n.ab)("indicator.forceIndex.length.tooltip","EMA length applied to the raw 1-bar force index, (close − close[1]) \xd7 volume. Elder used 13 for the intermediate trend and 2 for short-term timing.")),az(r.cr,(0,n.ab)("indicator.forceIndex.color","Bullish"),"color",(0,n.ab)("indicator.forceIndex.color.tooltip","Color of the line while above zero (buying pressure).")),az(r.TV,(0,n.ab)("indicator.forceIndex.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.forceIndex.bearColor.tooltip","Color of the line while below zero (selling pressure)."))],compute:(e,t)=>{let i=n9(ap(n7(e)),n4(e),(e,t)=>e*t),o=nQ(t,"color",r.cr);return aG({key:"force",title:(0,n.ab)("indicator.forceIndex.plot.force","Force Index"),values:ad(i,n_(t,"length",13)),ink:{bull:o,bear:nQ(t,"bearColor",r.TV),neutral:o},zeroInk:r.qm,width:2,valueTransparency:60})}},hZ={type:"klinger-oscillator",title:(0,n.ab)("indicator.klingerOscillator.title","Klinger Oscillator"),shortTitle:(0,n.ab)("indicator.klingerOscillator.shortTitle","KVO"),overlay:!1,inputs:[aI(34,"fastLength",(0,n.ab)("indicator.klingerOscillator.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.klingerOscillator.fastLength.tooltip","Length of the fast EMA applied to the volume force.")),aI(55,"slowLength",(0,n.ab)("indicator.klingerOscillator.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.klingerOscillator.slowLength.tooltip","Length of the slow EMA applied to the volume force.")),aI(13,"signalLength",(0,n.ab)("indicator.klingerOscillator.signalLength","Signal Length"),500,(0,n.ab)("indicator.klingerOscillator.signalLength.tooltip","Length of the EMA applied to the oscillator to obtain the signal line.")),az(r.cr,(0,n.ab)("indicator.klingerOscillator.color","Bullish"),"color",(0,n.ab)("indicator.klingerOscillator.color.tooltip","Color of the Klinger oscillator while above zero.")),az(r.TV,(0,n.ab)("indicator.klingerOscillator.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.klingerOscillator.bearColor.tooltip","Color of the Klinger oscillator while below zero.")),az(r.Nz,(0,n.ab)("indicator.klingerOscillator.signalColor","Signal"),"signalColor",(0,n.ab)("indicator.klingerOscillator.signalColor.tooltip","Color of the signal line."))],compute:(e,t)=>{let i=e.length,o=Array(i).fill(NaN),l=1,a=1,s=0,h=0;for(let t=0;t<i;t++){let i=e[t],r=i.high+i.low+i.close,n=t>0?e[t-1].high+e[t-1].low+e[t-1].close:r;l=r>n?1:-1;let d=i.high-i.low;s=t>0&&l===a?s+d:h+d;let c=i.volume;o[t]=null!=c&&Number.isFinite(c)?0===s?0:c*Math.abs(d/s*2-1)*l*100:NaN,a=l,h=d}let d=at(ad(o,n_(t,"fastLength",34)),ad(o,n_(t,"slowLength",55))),c=nQ(t,"color",r.cr);return aG({key:"kvo",title:(0,n.ab)("indicator.klingerOscillator.plot.kvo","KVO"),values:d,ink:{bull:c,bear:nQ(t,"bearColor",r.TV),neutral:c},zeroInk:aD(r.qm,50),valueTransparency:60,extraPlots:[{key:"signal",title:(0,n.ab)("indicator.klingerOscillator.plot.signal","Signal"),values:ad(d,n_(t,"signalLength",13)),color:nQ(t,"signalColor",r.Nz)}]})}},hX={type:"money-flow-index",title:(0,n.ab)("indicator.moneyFlowIndex.title","Money Flow Index"),shortTitle:(0,n.ab)("indicator.moneyFlowIndex.shortTitle","MFI"),overlay:!1,inputs:[aI(14,"length",(0,n.ab)("indicator.moneyFlowIndex.length","Length"),5e3,(0,n.ab)("indicator.moneyFlowIndex.length.tooltip","Number of bars used to sum positive and negative money flow.")),aB("overbought",(0,n.ab)("indicator.moneyFlowIndex.overbought","Overbought Level"),80,0,100,1,(0,n.ab)("indicator.moneyFlowIndex.overbought.tooltip","Level above which the MFI is considered overbought.")),aB("oversold",(0,n.ab)("indicator.moneyFlowIndex.oversold","Oversold Level"),20,0,100,1,(0,n.ab)("indicator.moneyFlowIndex.oversold.tooltip","Level below which the MFI is considered oversold.")),az(r.qm,(0,n.ab)("indicator.moneyFlowIndex.color","MFI"),"color",(0,n.ab)("indicator.moneyFlowIndex.color.tooltip","Color of the MFI line between the levels. Toward either level it blends into that level’s color.")),az(r.TV,(0,n.ab)("indicator.moneyFlowIndex.overboughtColor","Overbought"),"overboughtColor",(0,n.ab)("indicator.moneyFlowIndex.overboughtColor.tooltip","Color of the line and zone shading at and above the overbought level.")),az(r.cr,(0,n.ab)("indicator.moneyFlowIndex.oversoldColor","Oversold"),"oversoldColor",(0,n.ab)("indicator.moneyFlowIndex.oversoldColor.tooltip","Color of the line and zone shading at and below the oversold level.")),az(aD(r.qm,94),(0,n.ab)("indicator.moneyFlowIndex.fillColor","OB/OS Zone Fill"),"fillColor",(0,n.ab)("indicator.moneyFlowIndex.fillColor.tooltip","Fill color of the area between the overbought and oversold levels."))],compute:(e,t)=>{let i=n_(t,"length",14),o=n3(e,"HLC3"),l=n9(o,n4(e),(e,t)=>e*t),a=ap(o),s=ao(n9(l,a,(e,t)=>t>0?e:0),i),h=ao(n9(l,a,(e,t)=>t<0?e:0),i),d=n9(s,h,(e,t)=>e+t>0?100*e/(e+t):NaN);return aj({key:"mfi",title:(0,n.ab)("indicator.moneyFlowIndex.plot.mfi","MFI"),values:d,scale:{top:100,bottom:0},overbought:n_(t,"overbought",80),oversold:n_(t,"oversold",20),ink:{low:nQ(t,"oversoldColor",r.cr),mid:nQ(t,"color",r.qm),high:nQ(t,"overboughtColor",r.TV)},levelInk:r.qm,zoneTransparency:91,bandFill:nQ(t,"fillColor",aD(r.qm,94))})}};function h_(e){return[az(r.cr,(0,n.ab)("indicator.common.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.regime.bullColor.tooltip","Color of the line and gradient fill while it holds above its signal EMA.")),az(r.TV,(0,n.ab)("indicator.common.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.regime.bearColor.tooltip","Color of the line and gradient fill while it holds below its signal EMA.")),az(r.qm,(0,n.ab)("indicator.common.neutralColor","Neutral"),"neutralColor",(0,n.ab)("indicator.regime.neutralColor.tooltip","Color used while the signal EMA is still forming, or the line sits exactly on it.")),az(r.qm,e,"signalColor",(0,n.ab)("indicator.regime.signalColor.tooltip","Color of the signal EMA overlay.")),aF("gradientFill",(0,n.ab)("indicator.regime.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.regime.gradientFill.tooltip","Fills the gap between the line and its signal EMA with a vertical gradient — transparent at the average, strongest at the line."))]}var hQ="Position vs Average",hJ="Single Color",h0={type:"negative-volume-index",title:(0,n.ab)("indicator.negativeVolumeIndex.title","Negative Volume Index"),shortTitle:(0,n.ab)("indicator.negativeVolumeIndex.shortTitle","Negative Volume Index"),overlay:!1,inputs:[aB("base",(0,n.ab)("indicator.negativeVolumeIndex.base","Starting Value"),1e3,.01,1e6,1,(0,n.ab)("indicator.negativeVolumeIndex.base.tooltip","Arbitrary seed of the cumulative line, conventionally 1000. The absolute level carries no information — the line is read by slope and by position against the signal EMA.")),aF("showSignal",(0,n.ab)("indicator.negativeVolumeIndex.showSignal","Signal EMA"),!0,aA,(0,n.ab)("indicator.negativeVolumeIndex.showSignal.tooltip","Displays the conventional signal overlay. Hiding it only removes the plotted average; the regime coloring and fill still use it.")),aI(255,"signalLength",(0,n.ab)("indicator.negativeVolumeIndex.signalLength","Signal Length"),5e3,(0,n.ab)("indicator.negativeVolumeIndex.signalLength.tooltip","Length of the signal EMA. The convention is 255 sessions on daily charts, about one trading year.")),aO("colorMode",(0,n.ab)("indicator.negativeVolumeIndex.colorMode","Line Coloring"),hQ,[hQ,hJ],(0,n.ab)("indicator.negativeVolumeIndex.colorMode.tooltip","Position vs Average colors the line by the classic regime read; Single Color draws the whole line in the neutral color.")),...h_((0,n.ab)("indicator.negativeVolumeIndex.signalColor","Signal EMA"))],compute:(e,t)=>{let i=h$(e,n7(e),n_(t,"base",1e3),(e,t)=>e<t),o=ad(i,n_(t,"signalLength",255));return hH("nvi","NVI",i,o,{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"neutralColor",r.qm),signal:nQ(t,"signalColor",r.qm)},nJ(t,"showSignal",!0),nJ(t,"gradientFill",!0),nQ(t,"colorMode",hQ)===hJ)}},h1={type:"positive-volume-index",title:(0,n.ab)("indicator.positiveVolumeIndex.title","Positive Volume Index"),shortTitle:(0,n.ab)("indicator.positiveVolumeIndex.shortTitle","Positive Volume Index"),overlay:!1,inputs:[aR("Close","source",(0,n.ab)("indicator.positiveVolumeIndex.source","Source"),(0,n.ab)("indicator.positiveVolumeIndex.source.tooltip","Price series whose one-bar percentage change moves PVI on its active sessions.")),aB("base",(0,n.ab)("indicator.positiveVolumeIndex.base","Starting Value"),1e3,1,1e6,1,(0,n.ab)("indicator.positiveVolumeIndex.base.tooltip","Seed of the cumulative line. The absolute level carries no information, so the reads are the slope and the position against the signal EMA.")),aF("showSignal",(0,n.ab)("indicator.positiveVolumeIndex.showSignal","Signal EMA"),!0,aA,(0,n.ab)("indicator.positiveVolumeIndex.showSignal.tooltip","Plots the long EMA of PVI that anchors the classic regime read. Hiding it keeps the regime coloring and fill, which are always measured against it.")),aI(255,"signalLength",(0,n.ab)("indicator.positiveVolumeIndex.signalLength","Signal Length"),5e3,(0,n.ab)("indicator.positiveVolumeIndex.signalLength.tooltip","Length of the signal EMA. The classic reference is 255 trading days on daily charts, about one year.")),...h_((0,n.ab)("indicator.positiveVolumeIndex.signalColor","Signal Line"))],compute:(e,t)=>{let i=n3(e,nQ(t,"source","Close")),o=h$(e,i,n_(t,"base",1e3),(e,t)=>e>t),l=ad(o,n_(t,"signalLength",255));return hH("pvi","PVI",o,l,{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"neutralColor",r.qm),signal:nQ(t,"signalColor",r.qm)},nJ(t,"showSignal",!0),nJ(t,"gradientFill",!0))}},h2={type:"price-volume-trend",title:(0,n.ab)("indicator.priceVolumeTrend.title","Price Volume Trend"),shortTitle:(0,n.ab)("indicator.priceVolumeTrend.shortTitle","PVT"),overlay:!1,inputs:[aF("showSignal",(0,n.ab)("indicator.priceVolumeTrend.showSignal","Signal Line"),!1,aA,(0,n.ab)("indicator.priceVolumeTrend.showSignal.tooltip","Display a moving average of PVT acting as a signal line.")),aO("signalType",(0,n.ab)("indicator.priceVolumeTrend.signalType","Signal Type"),"SMA",["SMA","EMA"],(0,n.ab)("indicator.priceVolumeTrend.signalType.tooltip","Moving average type used for the signal line.")),aI(21,"signalLength",(0,n.ab)("indicator.priceVolumeTrend.signalLength","Signal Length"),5e3,(0,n.ab)("indicator.priceVolumeTrend.signalLength.tooltip","Number of bars used to compute the signal line.")),az(r.qm,(0,n.ab)("indicator.priceVolumeTrend.color","PVT Color"),"color",(0,n.ab)("indicator.priceVolumeTrend.color.tooltip","Color of the PVT line while it is flat.")),az(r.cr,(0,n.ab)("indicator.priceVolumeTrend.bullColor","Rising"),"bullColor",(0,n.ab)("indicator.priceVolumeTrend.bullColor.tooltip","Color of the PVT line while it rises bar to bar.")),az(r.TV,(0,n.ab)("indicator.priceVolumeTrend.bearColor","Falling"),"bearColor",(0,n.ab)("indicator.priceVolumeTrend.bearColor.tooltip","Color of the PVT line while it falls bar to bar.")),az(r.Nz,(0,n.ab)("indicator.priceVolumeTrend.signalColor","Signal Color"),"signalColor",(0,n.ab)("indicator.priceVolumeTrend.signalColor.tooltip","Color of the signal line."))],compute:(e,t)=>{let i=n7(e),o=aS(e.map((e,t)=>{if(0===t||null==e.volume||!Number.isFinite(e.volume))return NaN;let o=i[t-1];return 0===o?0:(i[t]-o)/o*e.volume})),l=nQ(t,"color",r.qm),a=[{key:"pvt",title:(0,n.ab)("indicator.priceVolumeTrend.plot.pvt","PVT"),values:o,color:l,width:2,colors:hD(o,nQ(t,"bullColor",r.cr),nQ(t,"bearColor",r.TV),l)}];if(nJ(t,"showSignal",!1)){let e=n_(t,"signalLength",21),i="EMA"===nQ(t,"signalType","SMA")?ad(o,e):ar(o,e);a.push({key:"signal",title:(0,n.ab)("indicator.priceVolumeTrend.plot.signal","Signal"),values:i,color:nQ(t,"signalColor",r.Nz)})}return{plots:a}}},h5={type:"volume-oscillator",title:(0,n.ab)("indicator.volumeOscillator.title","Volume Oscillator"),shortTitle:(0,n.ab)("indicator.volumeOscillator.shortTitle","Vol Osc"),overlay:!1,inputs:[aI(5,"fastLength",(0,n.ab)("indicator.volumeOscillator.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.volumeOscillator.fastLength.tooltip","Length of the fast EMA of volume.")),aI(10,"slowLength",(0,n.ab)("indicator.volumeOscillator.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.volumeOscillator.slowLength.tooltip","Length of the slow EMA of volume.")),az(r.cr,(0,n.ab)("indicator.volumeOscillator.color","Above Zero"),"color",(0,n.ab)("indicator.volumeOscillator.color.tooltip","Color of the line and fill while it holds above zero — volume expanding.")),az(r.TV,(0,n.ab)("indicator.volumeOscillator.bearColor","Below Zero"),"bearColor",(0,n.ab)("indicator.volumeOscillator.bearColor.tooltip","Color of the line and fill while it holds below zero — volume contracting."))],compute:(e,t)=>{let i=n4(e),o=n9(ad(i,n_(t,"fastLength",5)),ad(i,n_(t,"slowLength",10)),(e,t)=>0===t?0:100*(e-t)/t),l=nQ(t,"color",r.cr);return aG({key:"vo",title:(0,n.ab)("indicator.volumeOscillator.plot.vo","Volume Oscillator"),values:o,ink:{bull:l,bear:nQ(t,"bearColor",r.TV),neutral:l},zeroInk:r.qm,valueTransparency:60})}},h3="Oscillator",h4={type:"pvo",title:(0,n.ab)("indicator.pvo.title","Percentage Volume Oscillator"),shortTitle:(0,n.ab)("indicator.pvo.shortTitle","PVO"),overlay:!1,inputs:[{...aI(12,"fastLength",(0,n.ab)("indicator.pvo.fastLength","Fast Length"),5e3,(0,n.ab)("indicator.pvo.fastLength.tooltip","Period of the fast EMA of volume. The conventional setting is 12.")),group:h3},{...aI(26,"slowLength",(0,n.ab)("indicator.pvo.slowLength","Slow Length"),5e3,(0,n.ab)("indicator.pvo.slowLength.tooltip","Period of the slow EMA of volume. The PVO expresses the fast/slow spread as a percentage of this slow average.")),group:h3},{...aI(9,"signalLength",(0,n.ab)("indicator.pvo.signalLength","Signal Length"),500,(0,n.ab)("indicator.pvo.signalLength.tooltip","Period of the EMA applied to the PVO to form the signal line.")),group:h3},az(r.cr,(0,n.ab)("indicator.pvo.color","Expansion Color"),"color",(0,n.ab)("indicator.pvo.color.tooltip","Color of the oscillator and fill while participation expands.")),az(r.TV,(0,n.ab)("indicator.pvo.bearColor","Contraction Color"),"bearColor",(0,n.ab)("indicator.pvo.bearColor.tooltip","Color of the oscillator and fill while participation contracts.")),az(r.Nz,(0,n.ab)("indicator.pvo.signalColor","Signal Line"),"signalColor",(0,n.ab)("indicator.pvo.signalColor.tooltip","Color of the signal line.")),az(aD(r.qm,50),(0,n.ab)("indicator.pvo.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.pvo.zeroColor.tooltip","Color of the zero reference line.")),aF("showSignal",(0,n.ab)("indicator.pvo.showSignal","Show Signal Line"),!0,aP,(0,n.ab)("indicator.pvo.showSignal.tooltip","Plot the signal line, an EMA of the PVO.")),aF("showHistogram",(0,n.ab)("indicator.pvo.showHistogram","Show Histogram"),!0,aP,(0,n.ab)("indicator.pvo.showHistogram.tooltip","Plot the difference between the PVO and its signal line as columns behind the oscillator."))],compute:(e,t)=>{let i=n4(e),o=n9(ad(i,n_(t,"fastLength",12)),ad(i,n_(t,"slowLength",26)),(e,t)=>t>0?100*(e-t)/t:NaN),l=ad(o,n_(t,"signalLength",9)),a=nQ(t,"color",r.cr),s=nQ(t,"bearColor",r.TV),h=[];if(nJ(t,"showHistogram",!0)){let e=at(o,l);h.push({key:"hist",title:(0,n.ab)("indicator.pvo.plot.hist","Histogram"),values:e,kind:"columns",color:aD(a,60),colors:e.map(e=>Number.isFinite(e)?aD(e>0?a:s,60):null),base:0})}return nJ(t,"showSignal",!0)&&h.push({key:"signal",title:(0,n.ab)("indicator.pvo.plot.signal","Signal"),values:l,color:nQ(t,"signalColor",r.Nz)}),aG({key:"pvo",title:(0,n.ab)("indicator.pvo.plot.pvo","PVO"),values:o,ink:{bull:a,bear:s,neutral:s},zeroInk:nQ(t,"zeroColor",aD(r.qm,50)),extraPlots:h})}},h6={type:"volume-flow-indicator",title:(0,n.ab)("indicator.volumeFlowIndicator.title","Volume Flow Indicator"),shortTitle:(0,n.ab)("indicator.volumeFlowIndicator.shortTitle","Volume Flow Indicator"),overlay:!1,inputs:[{...aI(130,"length",(0,n.ab)("indicator.volumeFlowIndicator.length","Length"),5e3,(0,n.ab)("indicator.volumeFlowIndicator.length.tooltip","Rolling summation window, also used for the average volume that scales the result. The published default of 130 bars targets position-horizon work on daily charts.")),min:2},aB("coef",(0,n.ab)("indicator.volumeFlowIndicator.coef","Cutoff Coefficient"),.2,0,10,.05,(0,n.ab)("indicator.volumeFlowIndicator.coef.tooltip","Scales the volatility-based minimum change in typical price. Moves smaller than the cutoff count as noise and contribute no volume.")),aB("volCoef",(0,n.ab)("indicator.volumeFlowIndicator.volCoef","Volume Cap Multiplier"),2.5,.1,50,.1,(0,n.ab)("indicator.volumeFlowIndicator.volCoef.tooltip","Caps each bar's volume contribution at this multiple of the average volume, so a single climactic print stays bounded.")),{...aI(30,"volLength",(0,n.ab)("indicator.volumeFlowIndicator.volLength","Volatility Length"),5e3,(0,n.ab)("indicator.volumeFlowIndicator.volLength.tooltip","Window of the standard deviation of the log change in typical price used to build the adaptive cutoff.")),min:2},aF("smooth",(0,n.ab)("indicator.volumeFlowIndicator.smooth","Smooth VFI"),!0,aA,(0,n.ab)("indicator.volumeFlowIndicator.smooth.tooltip","Applies the published light smoothing — an EMA of the summed line — before plotting.")),aI(3,"smoothLength",(0,n.ab)("indicator.volumeFlowIndicator.smoothLength","Smoothing Length"),500,(0,n.ab)("indicator.volumeFlowIndicator.smoothLength.tooltip","Length of the smoothing EMA. The published version uses 3 bars.")),aF("showSignal",(0,n.ab)("indicator.volumeFlowIndicator.showSignal","Signal Line"),!0,aA,(0,n.ab)("indicator.volumeFlowIndicator.showSignal.tooltip","Plots an EMA of VFI as a signal line.")),aI(5,"signalLength",(0,n.ab)("indicator.volumeFlowIndicator.signalLength","Signal Length"),500,(0,n.ab)("indicator.volumeFlowIndicator.signalLength.tooltip","Length of the signal-line EMA.")),az(r.cr,(0,n.ab)("indicator.volumeFlowIndicator.color","Bullish"),"color",(0,n.ab)("indicator.volumeFlowIndicator.color.tooltip","Color of the VFI line and gradient fill above the zero line — the net accumulation regime.")),az(r.TV,(0,n.ab)("indicator.volumeFlowIndicator.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.volumeFlowIndicator.bearColor.tooltip","Color of the VFI line and gradient fill below the zero line — the net distribution regime.")),az(r.Nz,(0,n.ab)("indicator.volumeFlowIndicator.signalColor","Signal Line"),"signalColor",(0,n.ab)("indicator.volumeFlowIndicator.signalColor.tooltip","Color of the signal line.")),aF("gradientFill",(0,n.ab)("indicator.volumeFlowIndicator.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.volumeFlowIndicator.gradientFill.tooltip","Fills the area between the zero line and the VFI line with a vertical gradient."))],compute:(e,t)=>{let i=n_(t,"length",130),o=n3(e,"HLC3"),l=an(at(ae(o,Math.log),ag(ae(o,Math.log),1)),n_(t,"volLength",30)),a=n_(t,"coef",.2),s=n_(t,"volCoef",2.5),h=n4(e),d=ag(ar(h,i),1),c=ap(o),p=n9(ao(e.map((e,t)=>{let i=l[t],o=c[t],r=h[t];if(!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(r))return NaN;let n=a*i*e.close,p=d[t],u=Number.isFinite(p)?Math.min(r,p*s):r;return o>n?u:o<-n?-u:0}),i),d,(e,t)=>t>0?e/t:NaN),u=nJ(t,"smooth",!0)?ad(p,n_(t,"smoothLength",3)):p,g=nQ(t,"color",r.cr),m=nJ(t,"showSignal",!0)?[{key:"signal",title:(0,n.ab)("indicator.volumeFlowIndicator.plot.signal","Signal Line"),values:ad(u,n_(t,"signalLength",5)),color:nQ(t,"signalColor",r.Nz)}]:[];return aG({key:"vfi",title:(0,n.ab)("indicator.volumeFlowIndicator.plot.vfi","VFI"),values:u,ink:{bull:g,bear:nQ(t,"bearColor",r.TV),neutral:nQ(t,"bearColor",r.TV)},zeroInk:aD(r.qm,90),fill:nJ(t,"gradientFill",!0),extraPlots:m})}},h8="Normalized Oscillator (II%)",h7="Cumulative Line",h9={type:"intraday-intensity",title:(0,n.ab)("indicator.intradayIntensity.title","Intraday Intensity"),shortTitle:(0,n.ab)("indicator.intradayIntensity.shortTitle","Intraday Intensity"),overlay:!1,inputs:[aO("mode",(0,n.ab)("indicator.intradayIntensity.mode","Display"),h8,[h8,h7],(0,n.ab)("indicator.intradayIntensity.mode.tooltip","The two published forms. The cumulative line is open-ended and read by slope against price; the normalized oscillator divides a rolling sum of intensity by the rolling sum of volume and oscillates around zero.")),aI(21,"length",(0,n.ab)("indicator.intradayIntensity.length","Oscillator Length"),5e3,(0,n.ab)("indicator.intradayIntensity.length.tooltip","Window of the rolling sums in the normalized form. The common setting is 21 bars. It has no effect on the cumulative line.")),az(r.cr,(0,n.ab)("indicator.intradayIntensity.color","Bullish"),"color",(0,n.ab)("indicator.intradayIntensity.color.tooltip","Color of positive readings, the rising cumulative line and the fill above zero — the accumulation side.")),az(r.TV,(0,n.ab)("indicator.intradayIntensity.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.intradayIntensity.bearColor.tooltip","Color of negative readings, the falling cumulative line and the fill below zero — the distribution side.")),aF("gradientFill",(0,n.ab)("indicator.intradayIntensity.gradientFill","Gradient Fill"),!0,aP,(0,n.ab)("indicator.intradayIntensity.gradientFill.tooltip","Fills the area between the zero line and the oscillator with a vertical gradient. Applies to the normalized oscillator only."))],compute:(e,t)=>{let i=hV(e),o=nQ(t,"color",r.cr),l=nQ(t,"bearColor",r.TV);if(nQ(t,"mode",h8)===h7){let e=aS(i);return{plots:[{key:"ii",title:(0,n.ab)("indicator.intradayIntensity.plot.ii","Intraday Intensity"),values:e,color:o,colors:hD(e,o,l,o)}]}}let a=n_(t,"length",21),s=n9(ao(i,a),ao(n4(e),a),(e,t)=>t>0?100*e/t:NaN);return aG({key:"ii",title:(0,n.ab)("indicator.intradayIntensity.plot.ii","Intraday Intensity"),values:s,ink:{bull:o,bear:l,neutral:l},zeroInk:aD(r.qm,90),fill:nJ(t,"gradientFill",!0)})}};function de(e,t){if("Week"===e)return Math.floor((Math.floor(t/864e5)+3)/7);if("Month"===e||"Quarter"===e||"Year"===e){let i=new Date(t);return"Year"===e?i.getUTCFullYear():"Quarter"===e?4*i.getUTCFullYear()+Math.floor(i.getUTCMonth()/3):12*i.getUTCFullYear()+i.getUTCMonth()}return Math.floor(t/864e5)}function dt(e){if(e.length<2)return 0;let t=[];for(let i=1;i<e.length;i++)t.push(e[i].time-e[i-1].time);return t.sort((e,t)=>e-t),t[Math.floor(t.length/2)]??0}var di={type:"parabolic-sar",title:(0,n.ab)("indicator.parabolicSar.title","Parabolic SAR"),shortTitle:(0,n.ab)("indicator.parabolicSar.shortTitle","SAR"),overlay:!0,inputs:[aB("start",(0,n.ab)("indicator.parabolicSar.start","Start"),.02,0,1,.01,(0,n.ab)("indicator.parabolicSar.start.tooltip","Initial acceleration factor applied when a new trend begins.")),aB("increment",(0,n.ab)("indicator.parabolicSar.increment","Increment"),.02,0,1,.01,(0,n.ab)("indicator.parabolicSar.increment.tooltip","Amount added to the acceleration factor each time the trend makes a new extreme point.")),aB("maximum",(0,n.ab)("indicator.parabolicSar.maximum","Maximum"),.2,.01,1,.01,(0,n.ab)("indicator.parabolicSar.maximum.tooltip","Upper cap on the acceleration factor.")),az(r.cr,(0,n.ab)("indicator.parabolicSar.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.parabolicSar.bullColor.tooltip","Color of the SAR crosses while they trail below price — uptrend, the stop sits under the market.")),az(r.TV,(0,n.ab)("indicator.parabolicSar.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.parabolicSar.bearColor.tooltip","Color of the SAR crosses while they sit above price — downtrend, the stop sits over the market."))],compute:(e,t)=>{let i=n_(t,"start",.02),o=n_(t,"increment",.02),l=n_(t,"maximum",.2),a=e.length,s=Array(a).fill(NaN);if(a>=2){let t=e[1].close>=e[0].close,r=t?e[0].low:e[0].high,n=t?e[0].high:e[0].low,h=i;for(let d=1;d<a;d++){let a=e[d];r+=h*(n-r),r=t?Math.min(r,e[d-1].low,d>=2?e[d-2].low:e[d-1].low):Math.max(r,e[d-1].high,d>=2?e[d-2].high:e[d-1].high);let c=t?a.low<r:a.high>r;c?(t=!t,r=n,n=t?a.high:a.low,h=i):t&&a.high>n?(n=a.high,h=Math.min(l,h+o)):!t&&a.low<n&&(n=a.low,h=Math.min(l,h+o)),s[d]=r}}let h=nQ(t,"bullColor",r.cr),d=nQ(t,"bearColor",r.TV),c=s.map((t,i)=>Number.isFinite(t)?t<e[i].close?h:d:null);return{plots:[{key:"sar",title:(0,n.ab)("indicator.parabolicSar.plot.sar","SAR"),values:s,kind:"cross",color:h,colors:c}]}}},dr="Standard Deviation",dl="Percentage",dn=[{show:"band1",mult:"band1Mult",defMult:1,defOn:!0},{show:"band2",mult:"band2Mult",defMult:2,defOn:!1},{show:"band3",mult:"band3Mult",defMult:3,defOn:!1}],da={show:(0,n.ab)("indicator.vwap.band","Band #{n}"),showTooltips:[(0,n.ab)("indicator.vwap.band1.tooltip","Show the first band pair."),(0,n.ab)("indicator.vwap.band2.tooltip","Show the second band pair."),(0,n.ab)("indicator.vwap.band3.tooltip","Show the third band pair.")],mult:(0,n.ab)("indicator.vwap.bandMult","Band #{n} Multiplier"),multTooltip:(0,n.ab)("indicator.vwap.bandMult.tooltip","Multiplier for this band pair, in standard deviations or percent depending on the bands mode."),upper:(0,n.ab)("indicator.vwap.plot.upperBand","Upper Band #{n}"),lower:(0,n.ab)("indicator.vwap.plot.lowerBand","Lower Band #{n}")},ds={type:"vwap",title:(0,n.ab)("indicator.vwap.title","Volume Weighted Average Price"),shortTitle:(0,n.ab)("indicator.vwap.shortTitle","VWAP"),overlay:!0,inputs:[aO("anchor",(0,n.ab)("indicator.vwap.anchor","Anchor Period"),"Session",["Session","Week","Month","Quarter","Year"],(0,n.ab)("indicator.vwap.anchor.tooltip","Period anchoring the average. VWAP and its bands reset on the first bar of each new session, week, month, quarter or year (UTC).")),aR("HLC3","source",(0,n.ab)("indicator.vwap.source","Source"),(0,n.ab)("indicator.vwap.source.tooltip","Price used in the volume weighted average. Typical price (HLC3) is the classic choice.")),aO("bandsMode",(0,n.ab)("indicator.vwap.bandsMode","Bands Mode"),dr,[dr,dl],(0,n.ab)("indicator.vwap.bandsMode.tooltip","Bands offset method: multiples of the volume weighted standard deviation of price around VWAP, or a percentage of the VWAP value.")),...dn.flatMap((e,t)=>[aF(e.show,(0,n.tV)(da.show,{n:t+1}),e.defOn,aA,da.showTooltips[t]),aB(e.mult,(0,n.tV)(da.mult,{n:t+1}),e.defMult,0,50,.5,da.multTooltip)]),aF("hideDwm",(0,n.ab)("indicator.vwap.hideDwm","Hide VWAP on 1D or Above"),!0,aA,(0,n.ab)("indicator.vwap.hideDwm.tooltip","Hide the VWAP and its bands on daily and higher timeframes, where an intraday anchored VWAP is not meaningful.")),az(r.cr,(0,n.ab)("indicator.vwap.bullColor","Bullish"),"bullColor",(0,n.ab)("indicator.vwap.bullColor.tooltip","VWAP line color while price closes above it, and the color of the lower (support) bands.")),az(r.TV,(0,n.ab)("indicator.vwap.bearColor","Bearish"),"bearColor",(0,n.ab)("indicator.vwap.bearColor.tooltip","VWAP line color while price closes below it, and the color of the upper (resistance) bands.")),az(r.qm,(0,n.ab)("indicator.vwap.bandsColor","Bands"),"bandsColor",(0,n.ab)("indicator.vwap.bandsColor.tooltip","Deviation bands fill color.")),aF("fill",(0,n.ab)("indicator.vwap.fill","Bands Fill"),!0,aP,(0,n.ab)("indicator.vwap.fill.tooltip","Fill the area between each visible band pair."))],compute:(e,t)=>{let i=nQ(t,"anchor","Session"),o=n3(e,nQ(t,"source","HLC3")),l=e.length,a=nJ(t,"hideDwm",!0)&&dt(e)>=864e5,s=Array(l).fill(NaN),h=dn.filter(e=>nJ(t,e.show,e.defOn)).map(e=>({mult:Math.max(0,n_(t,e.mult,e.defMult)),up:Array(l).fill(NaN),down:Array(l).fill(NaN)})),d=nQ(t,"bandsMode",dr)===dl,c=NaN,p=0,u=0,g=0;for(let t=0;t<l&&!a;t++){let r=e[t],l=de(i,r.time);l!==c&&(c=l,p=0,u=0,g=0);let n=r.volume;if(null!=n&&Number.isFinite(n)&&n>0){let e=o[t];p+=e*n,u+=e*e*n,g+=n}if(g<=0)continue;let a=p/g,m=d?a/100:Math.sqrt(Math.max(0,u/g-a*a));for(let e of(s[t]=a,h))e.up[t]=a+e.mult*m,e.down[t]=a-e.mult*m}let m=nQ(t,"bullColor",r.cr),b=nQ(t,"bearColor",r.TV),f=aD(nQ(t,"bandsColor",r.qm),95),v=[{key:"vwap",title:(0,n.ab)("indicator.vwap.plot.vwap","VWAP"),values:s,color:m,colors:s.map((t,i)=>Number.isFinite(t)?e[i].close>=t?m:b:null)}],y=[];return h.forEach((e,i)=>{v.push({key:`up${i}`,title:(0,n.tV)(da.upper,{n:i+1}),values:e.up,color:aD(b,40)},{key:`down${i}`,title:(0,n.tV)(da.lower,{n:i+1}),values:e.down,color:aD(m,40)}),nJ(t,"fill",!0)&&y.push({key:`band${i}`,from:`up${i}`,to:`down${i}`,color:f})}),{plots:v,bands:y}}},dh="Traditional",dd="Fibonacci",dc="Camarilla",dp="Woodie",du="Auto",dg={type:"pivot-points",title:(0,n.ab)("indicator.pivotPoints.title","Pivot Points Standard"),shortTitle:(0,n.ab)("indicator.pivotPoints.shortTitle","Pivots"),overlay:!0,inputs:[aO("kind",(0,n.ab)("indicator.pivotPoints.kind","Type"),dh,[dh,dd,dc,dp],(0,n.tV)((0,n.ab)("indicator.pivotPoints.kind.tooltip","Formula used to calculate the levels. Traditional is the classic floor-trader method; Fibonacci projects {level1, number}/{level2, number}/{level3, number}% of the prior range around the pivot; Camarilla scales the prior range around the prior close; Woodie gives extra weight to the period open."),{level1:38.2,level2:61.8,level3:100})),aO("anchor",(0,n.ab)("indicator.pivotPoints.anchor","Pivots Timeframe"),du,[du,"Daily","Weekly","Monthly","Yearly"],(0,n.ab)("indicator.pivotPoints.anchor.tooltip","Period the pivots are anchored to. Auto follows the chart's timeframe: daily pivots up to 15-minute bars, weekly on other intraday bars, monthly on daily bars, yearly above.")),az(r.Nz,(0,n.ab)("indicator.pivotPoints.pivotColor","Pivot"),"pivotColor",(0,n.ab)("indicator.pivotPoints.pivotColor.tooltip","Color of the central pivot (P) level.")),az(r.TV,(0,n.ab)("indicator.pivotPoints.resistanceColor","Resistances"),"resistanceColor",(0,n.ab)("indicator.pivotPoints.resistanceColor.tooltip","Color of the resistance (R) levels.")),az(r.cr,(0,n.ab)("indicator.pivotPoints.supportColor","Supports"),"supportColor",(0,n.ab)("indicator.pivotPoints.supportColor.tooltip","Color of the support (S) levels."))],compute:(e,t)=>{let i=dt(e),o=nQ(t,"anchor",du),l="Daily"===o?"Session":"Weekly"===o?"Week":"Monthly"===o?"Month":"Yearly"===o?"Year":i<=9e5?"Session":i<864e5?"Week":i<=864e5?"Month":"Year",n=nQ(t,"kind",dh),a=new Map;for(let t of e){let e=de(l,t.time),i=a.get(e);i?(i.high=Math.max(i.high,t.high),i.low=Math.min(i.low,t.low),i.close=t.close):a.set(e,{open:t.open,high:t.high,low:t.low,close:t.close})}let s=e.length,h=()=>Array(s).fill(NaN),d={p:h(),r1:h(),s1:h(),r2:h(),s2:h(),r3:h(),s3:h(),r4:h(),s4:h()},c=NaN;for(let t=0;t<s;t++){let i=de(l,e[t].time),o=i!==c;if(c=i,o)continue;let r=a.get(i-1),s=a.get(i);if(!r||!s)continue;let h=r.high-r.low,p=(r.high+r.low+r.close)/3,u=n===dp?(r.high+r.low+2*s.open)/4:p;if(d.p[t]=u,n===dd)d.r1[t]=p+.382*h,d.s1[t]=p-.382*h,d.r2[t]=p+.618*h,d.s2[t]=p-.618*h,d.r3[t]=p+h,d.s3[t]=p-h;else if(n===dc){let e=1.1*h;d.r1[t]=r.close+e/12,d.s1[t]=r.close-e/12,d.r2[t]=r.close+e/6,d.s2[t]=r.close-e/6,d.r3[t]=r.close+e/4,d.s3[t]=r.close-e/4,d.r4[t]=r.close+e/2,d.s4[t]=r.close-e/2}else d.r1[t]=2*u-r.low,d.s1[t]=2*u-r.high,d.r2[t]=u+h,d.s2[t]=u-h,n!==dp&&(d.r3[t]=r.high+2*(u-r.low),d.s3[t]=r.low-2*(r.high-u))}let p=nQ(t,"resistanceColor",r.TV),u=nQ(t,"supportColor",r.cr),g=(e,t,i)=>({key:e,title:t,values:d[e],color:i}),m=[g("p","P",nQ(t,"pivotColor",r.Nz)),g("r1","R1",p),g("s1","S1",u),g("r2","R2",p),g("s2","S2",u)];return n!==dp&&m.push(g("r3","R3",p),g("s3","S3",u)),n===dc&&m.push(g("r4","R4",p),g("s4","S4",u)),{plots:m}}},dm={type:"52-week-high-low",title:(0,n.ab)("indicator.n52WeekHighLow.title","52-Week High/Low"),shortTitle:(0,n.ab)("indicator.n52WeekHighLow.shortTitle","52W H/L"),overlay:!0,inputs:[aE("weeks",(0,n.ab)("indicator.n52WeekHighLow.weeks","Weeks"),52,1,520,(0,n.ab)("indicator.n52WeekHighLow.weeks.tooltip","Length of the rolling window, in weeks.")),aF("showAllTime",(0,n.ab)("indicator.n52WeekHighLow.showAllTime","Show All-Time High/Low"),!1,aA,(0,n.ab)("indicator.n52WeekHighLow.showAllTime.tooltip","Additionally display the all-time high and low, tracked over the symbol's full loaded history.")),az(r.cr,(0,n.ab)("indicator.n52WeekHighLow.highColor","52-Week High"),"highColor",(0,n.ab)("indicator.n52WeekHighLow.highColor.tooltip","Color of the 52-week high level.")),az(r.TV,(0,n.ab)("indicator.n52WeekHighLow.lowColor","52-Week Low"),"lowColor",(0,n.ab)("indicator.n52WeekHighLow.lowColor.tooltip","Color of the 52-week low level.")),az(r.qm,(0,n.ab)("indicator.n52WeekHighLow.allTimeColor","All-Time High/Low"),"allTimeColor",(0,n.ab)("indicator.n52WeekHighLow.allTimeColor.tooltip","Color of the all-time high and all-time low levels."))],compute:(e,t)=>{let i=7*n_(t,"weeks",52)*864e5,o=e.length,l=Array(o).fill(NaN),a=Array(o).fill(NaN),s=Array(o).fill(NaN),h=Array(o).fill(NaN),d=[],c=[],p=0,u=-1/0,g=1/0;for(let t=0;t<o;t++){let o=e[t];for(;d.length>0&&e[d[d.length-1]].high<=o.high;)d.pop();for(d.push(t);c.length>0&&e[c[c.length-1]].low>=o.low;)c.pop();for(c.push(t);e[p].time<o.time-i;)p+=1;for(;d[0]<p;)d.shift();for(;c[0]<p;)c.shift();l[t]=e[d[0]].high,a[t]=e[c[0]].low,u=Math.max(u,o.high),g=Math.min(g,o.low),s[t]=u,h[t]=g}let m=[{key:"high",title:"52 Week High",displayTitle:(0,n.ab)("indicator.n52WeekHighLow.plot.high","52-Week High"),values:l,kind:"step",color:nQ(t,"highColor",r.cr),width:2},{key:"low",title:"52 Week Low",displayTitle:(0,n.ab)("indicator.n52WeekHighLow.plot.low","52-Week Low"),values:a,kind:"step",color:nQ(t,"lowColor",r.TV),width:2}];if(nJ(t,"showAllTime",!1)){let e=nQ(t,"allTimeColor",r.qm);m.push({key:"ath",title:(0,n.ab)("indicator.n52WeekHighLow.plot.ath","All-Time High"),values:s,kind:"step",color:e},{key:"atl",title:(0,n.ab)("indicator.n52WeekHighLow.plot.atl","All-Time Low"),values:h,kind:"step",color:e})}return{plots:m}}},db={type:"zigzag",title:(0,n.ab)("indicator.zigzag.title","ZigZag"),overlay:!0,inputs:[aB("deviation",(0,n.ab)("indicator.zigzag.deviation","Deviation (%)"),5,.01,100,.1,(0,n.ab)("indicator.zigzag.deviation.tooltip","Minimum reversal from the leg extreme, as a percentage of that extreme, required to confirm a new pivot.")),{...aE("depth",(0,n.ab)("indicator.zigzag.depth","Depth"),10,2,500,(0,n.ab)("indicator.zigzag.depth.tooltip","Minimum number of bars required between two consecutive pivots."))},az(r.cr,(0,n.ab)("indicator.zigzag.bullColor","Up Leg"),"bullColor",(0,n.ab)("indicator.zigzag.bullColor.tooltip","Color of rising zigzag segments.")),az(r.TV,(0,n.ab)("indicator.zigzag.bearColor","Down Leg"),"bearColor",(0,n.ab)("indicator.zigzag.bearColor.tooltip","Color of falling zigzag segments.")),{key:"lineWidth",title:(0,n.ab)("indicator.zigzag.lineWidth","Width"),type:"int",defval:2,min:1,max:10,step:1,group:aP,tooltip:(0,n.ab)("indicator.zigzag.lineWidth.tooltip","Width of the zigzag segments.")}],compute:(e,t)=>{let i=n_(t,"deviation",5)/100,o=n_(t,"depth",10),l=[];if(e.length>1){let t=e[1].close>=e[0].close,r=t?{i:0,price:e[0].high}:{i:0,price:e[0].low};for(let n=1;n<e.length;n++){let a=e[n];t?a.high>=r.price?r={i:n,price:a.high}:a.low<=r.price*(1-i)&&r.i-(l[l.length-1]?.i??-o)>=o&&(l.push(r),t=!1,r={i:n,price:a.low}):a.low<=r.price?r={i:n,price:a.low}:a.high>=r.price*(1+i)&&r.i-(l[l.length-1]?.i??-o)>=o&&(l.push(r),t=!0,r={i:n,price:a.high})}l.push(r)}let n=nQ(t,"bullColor",r.cr),a=nQ(t,"bearColor",r.TV),s=n_(t,"lineWidth",2),h=[];for(let t=1;t<l.length;t++){let i=l[t-1],o=l[t];h.push({key:`leg${t}`,points:[{xloc:"bar_time",x:e[i.i].time,price:i.price},{xloc:"bar_time",x:e[o.i].time,price:o.price}],curved:!1,closed:!1,lineColor:o.price>=i.price?n:a,lineWidth:s,lineStyle:"solid",arrowLeft:!1,arrowRight:!1})}return{plots:[],polylines:h}}},df={type:"williams-fractal",title:(0,n.ab)("indicator.williamsFractal.title","Williams Fractal"),shortTitle:(0,n.ab)("indicator.williamsFractal.shortTitle","Fractals"),overlay:!0,inputs:[aE("periods",(0,n.ab)("indicator.williamsFractal.periods","Periods"),2,2,50,(0,n.ab)("indicator.williamsFractal.periods.tooltip","Bars required on each side of the candidate bar. 2 is Bill Williams' classic 5-bar fractal; a fractal is confirmed only once this many later bars have closed.")),az(r.TV,(0,n.ab)("indicator.williamsFractal.upColor","Up Fractal"),"upColor",(0,n.ab)("indicator.williamsFractal.upColor.tooltip","Color of the up fractal marker (swing high), drawn above the fractal bar.")),az(r.cr,(0,n.ab)("indicator.williamsFractal.downColor","Down Fractal"),"downColor",(0,n.ab)("indicator.williamsFractal.downColor.tooltip","Color of the down fractal marker (swing low), drawn below the fractal bar."))],compute:(e,t)=>{let i=n_(t,"periods",2),o=[],l=nQ(t,"upColor",r.TV),n=nQ(t,"downColor",r.cr),a=(t,o,r)=>{let l=o(e[t]);for(let n=t-i;n<=t+i;n++)if(n!==t&&!r(l,o(e[n])))return!1;return!0};for(let t=i;t<e.length-i;t++)a(t,e=>e.high,(e,t)=>e>t)&&o.push({time:e[t].time,position:"aboveBar",shape:"triangleup",color:l}),a(t,e=>e.low,(e,t)=>e<t)&&o.push({time:e[t].time,position:"belowBar",shape:"triangledown",color:n});return{plots:[],markers:o}}};function dv(e,t,i){return{type:e,title:i.title,overlay:!0,inputs:[az(r.rD,void 0,"color",i.colorTooltip)],compute:(e,o)=>({plots:[{key:"price",title:i.plot,values:n3(e,t),color:nQ(o,"color",r.rD)}]})}}var dy=dv("median-price","HL2",{title:(0,n.ab)("indicator.medianPrice.title","Median Price"),plot:(0,n.ab)("indicator.medianPrice.plot.price","Median Price"),colorTooltip:(0,n.ab)("indicator.medianPrice.color.tooltip","Color of the line through the midpoint of each bar: the average of its high and low.")}),dw=dv("typical-price","HLC3",{title:(0,n.ab)("indicator.typicalPrice.title","Typical Price"),plot:(0,n.ab)("indicator.typicalPrice.plot.price","Typical Price"),colorTooltip:(0,n.ab)("indicator.typicalPrice.color.tooltip","Color of the line through the average of each bar’s high, low and close.")}),dC=dv("average-price","OHLC4",{title:(0,n.ab)("indicator.averagePrice.title","Average Price"),plot:(0,n.ab)("indicator.averagePrice.plot.price","Average Price"),colorTooltip:(0,n.ab)("indicator.averagePrice.color.tooltip","Color of the line through the average of each bar’s open, high, low and close.")}),dx=[a1,a2,a5,a3,a4,a9,se,st,si,sa,ss,sh,sp,su,sg,sb,sx,sS,sM,sL,sA,sP,sI,sE,sB,sF,sO,sR,sV,sH,sq,sU,sj,sG,sY,sZ,sX,s_,sQ,sJ,s0,s1,s5,s6,s7,s9,he,ht,hr,hp,hl,hn,hs,hh,hd,hc,hu,hg,hm,hb,hf,hv,hy,hw,hx,hM,hL,hI,hP,hE,hB,hF,hO,hR,hN,hz,hW,hq,hU,hj,hG,hK,hY,hZ,hX,h0,h1,h2,h5,h4,h6,h9,{type:"ichimoku-cloud",title:(0,n.ab)("indicator.ichimokuCloud.title","Ichimoku Cloud"),shortTitle:(0,n.ab)("indicator.ichimokuCloud.shortTitle","Ichimoku"),overlay:!0,inputs:[aN("symbol",(0,n.ab)("indicator.ichimokuCloud.symbol","Another Symbol"),"",{tooltip:(0,n.ab)("indicator.ichimokuCloud.symbol.tooltip","Optional secondary symbol to compute the cloud on. Leave empty to use the chart symbol.")}),aI(9,"conversionLength",(0,n.ab)("indicator.ichimokuCloud.conversionLength","Conversion Line Length"),5e3,(0,n.ab)("indicator.ichimokuCloud.conversionLength.tooltip","Lookback period for the Conversion Line (Tenkan-sen) high-low midpoint.")),aI(26,"baseLength",(0,n.ab)("indicator.ichimokuCloud.baseLength","Base Line Length"),5e3,(0,n.ab)("indicator.ichimokuCloud.baseLength.tooltip","Lookback period for the Base Line (Kijun-sen) high-low midpoint.")),aI(52,"spanBLength",(0,n.ab)("indicator.ichimokuCloud.spanBLength","Leading Span B Length"),5e3,(0,n.ab)("indicator.ichimokuCloud.spanBLength.tooltip","Lookback period for Leading Span B (Senkou Span B) high-low midpoint.")),aI(26,"laggingLength",(0,n.ab)("indicator.ichimokuCloud.laggingLength","Lagging Span"),5e3,(0,n.ab)("indicator.ichimokuCloud.laggingLength.tooltip","Backward shift period for the Lagging Span (Chikou Span); plots close shifted back by period − 1 bars.")),aI(26,"displacement",(0,n.ab)("indicator.ichimokuCloud.displacement","Displacement"),5e3,(0,n.ab)("indicator.ichimokuCloud.displacement.tooltip","Forward shift period for Leading Span A and B; projects the cloud ahead by displacement − 1 bars.")),az(r.rD,(0,n.ab)("indicator.ichimokuCloud.conversionColor","Conversion Line"),"conversionColor",(0,n.ab)("indicator.ichimokuCloud.conversionColor.tooltip","Color of the Conversion Line.")),az(r.TV,(0,n.ab)("indicator.ichimokuCloud.baseColor","Base Line"),"baseColor",(0,n.ab)("indicator.ichimokuCloud.baseColor.tooltip","Color of the Base Line.")),az(r.cr,(0,n.ab)("indicator.ichimokuCloud.laggingColor","Lagging Span"),"laggingColor",(0,n.ab)("indicator.ichimokuCloud.laggingColor.tooltip","Color of the Lagging Span.")),az(r.cr,(0,n.ab)("indicator.ichimokuCloud.spanAColor","Leading Span A"),"spanAColor",(0,n.ab)("indicator.ichimokuCloud.spanAColor.tooltip","Color of Leading Span A.")),az(r.TV,(0,n.ab)("indicator.ichimokuCloud.spanBColor","Leading Span B"),"spanBColor",(0,n.ab)("indicator.ichimokuCloud.spanBColor.tooltip","Color of Leading Span B.")),az(aD(r.cr,90),(0,n.ab)("indicator.ichimokuCloud.bullCloudColor","Bullish Cloud"),"bullCloudColor",(0,n.ab)("indicator.ichimokuCloud.bullCloudColor.tooltip","Cloud fill color while Leading Span A sits at or above Leading Span B.")),az(aD(r.TV,90),(0,n.ab)("indicator.ichimokuCloud.bearCloudColor","Bearish Cloud"),"bearCloudColor",(0,n.ab)("indicator.ichimokuCloud.bearCloudColor.tooltip","Cloud fill color while Leading Span A sits below Leading Span B."))],externalSymbols:e=>{let t=nQ(e,"symbol","").trim();return t?[t]:[]},compute:(e,t,i)=>{let o,l,a,s=nQ(t,"symbol","").trim();if(s){let t=aL(e,i?.get(s)??[]);o=t.map(e=>e?e.high:NaN),l=t.map(e=>e?e.low:NaN),a=t.map(e=>e?e.close:NaN)}else o=n6(e),l=n8(e),a=n7(e);let h=e=>n9(aa(o,e),as(l,e),(e,t)=>(e+t)/2),d=h(n_(t,"conversionLength",9)),c=h(n_(t,"baseLength",26)),p=n9(d,c,(e,t)=>(e+t)/2),u=h(n_(t,"spanBLength",52)),g=-(Math.max(1,Math.trunc(n_(t,"laggingLength",26)))-1),m=Math.max(1,Math.trunc(n_(t,"displacement",26)))-1,b=nQ(t,"bullCloudColor",aD(r.cr,90)),f=nQ(t,"bearCloudColor",aD(r.TV,90)),v=p.map((e,t)=>{let i=u[t];return Number.isFinite(e)&&Number.isFinite(i)?e>=i?b:f:null});return{plots:[{key:"conversion",title:(0,n.ab)("indicator.ichimokuCloud.plot.conversion","Conversion Line"),values:d,color:nQ(t,"conversionColor",r.rD)},{key:"base",title:(0,n.ab)("indicator.ichimokuCloud.plot.base","Base Line"),values:c,color:nQ(t,"baseColor",r.TV)},{key:"lagging",title:(0,n.ab)("indicator.ichimokuCloud.plot.lagging","Lagging Span"),values:a,color:nQ(t,"laggingColor",r.cr),offset:g},{key:"spanA",title:(0,n.ab)("indicator.ichimokuCloud.plot.spanA","Leading Span A"),values:p,color:nQ(t,"spanAColor",r.cr),offset:m},{key:"spanB",title:(0,n.ab)("indicator.ichimokuCloud.plot.spanB","Leading Span B"),values:u,color:nQ(t,"spanBColor",r.TV),offset:m}],bands:[{key:"cloud",from:"spanA",to:"spanB",color:b,colors:v}]}}},di,ds,dg,dm,db,df,dy,dw,dC,{type:"correlation-coefficient",title:(0,n.ab)("indicator.correlationCoefficient.title","Correlation Coefficient"),shortTitle:(0,n.ab)("indicator.correlationCoefficient.shortTitle","CC"),overlay:!1,inputs:[aN("symbol",(0,n.ab)("indicator.correlationCoefficient.symbol","Symbol"),"",{confirm:!0,tooltip:(0,n.ab)("indicator.correlationCoefficient.symbol.tooltip","Secondary symbol whose closing prices are correlated with the chart symbol.")}),aI(20,"length",(0,n.ab)("indicator.correlationCoefficient.length","Length"),2e3,(0,n.ab)("indicator.correlationCoefficient.length.tooltip","Number of bars over which the Pearson correlation coefficient is computed.")),az(r.cr,(0,n.ab)("indicator.correlationCoefficient.bullColor","Positive"),"bullColor",(0,n.ab)("indicator.correlationCoefficient.bullColor.tooltip","Line and area color while correlation is above zero.")),az(r.TV,(0,n.ab)("indicator.correlationCoefficient.bearColor","Negative"),"bearColor",(0,n.ab)("indicator.correlationCoefficient.bearColor.tooltip","Line and area color while correlation is below zero.")),az(r.qm,(0,n.ab)("indicator.correlationCoefficient.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.correlationCoefficient.zeroColor.tooltip","Color of the zero reference line."))],externalSymbols:e=>{let t=nQ(e,"symbol","").trim();return t?[t]:[]},compute:(e,t,i)=>{let o,l=nQ(t,"symbol","").trim();if(l){let r=aL(e,i?.get(l)??[]).map(e=>e?e.close:NaN);o=aC(n7(e),r,n_(t,"length",20))}else o=aT(e.length,NaN);let a=nQ(t,"bullColor",r.cr),s=nQ(t,"bearColor",r.TV),h=nQ(t,"zeroColor",r.qm),d=e=>e>0?a:e<0?s:r.qm;return{plots:[{key:"cc",title:(0,n.ab)("indicator.correlationCoefficient.plot.cc","Correlation"),values:o,color:r.qm,width:1,colors:o.map(e=>Number.isFinite(e)?d(e):null)},aW("baseline","Baseline Anchor",o.length,0)],bands:[{key:"area",from:"cc",to:"baseline",color:aD(r.qm,100),colors:o.map(e=>Number.isFinite(e)?aD(d(e),80):null)}],levels:[{key:"zero",price:0,color:h,lineStyle:"dashed",title:(0,n.ab)("indicator.common.level.zero","Zero Line")}]}}},{type:"correlation-log",title:(0,n.ab)("indicator.correlationLog.title","Correlation - Log"),shortTitle:(0,n.ab)("indicator.correlationLog.shortTitle","Correlation - Log"),overlay:!1,inputs:[aN("instrument",(0,n.ab)("indicator.correlationLog.instrument","Instrument 1"),"",{confirm:!0,tooltip:(0,n.ab)("indicator.correlationLog.instrument.tooltip","First symbol whose log returns enter the correlation.")}),aN("instrument2",(0,n.ab)("indicator.correlationLog.instrument2","Instrument 2"),"",{confirm:!0,tooltip:(0,n.ab)("indicator.correlationLog.instrument2.tooltip","Second symbol whose log returns enter the correlation.")}),{...aI(25,"length",(0,n.ab)("indicator.correlationLog.length","Length"),5e3,(0,n.ab)("indicator.correlationLog.length.tooltip","Number of bar-to-bar log returns used to compute the Pearson correlation.")),min:2},az(r.cr,(0,n.ab)("indicator.correlationLog.bullColor","Positive"),"bullColor",(0,n.ab)("indicator.correlationLog.bullColor.tooltip","Line and wash color while correlation is above zero.")),az(r.TV,(0,n.ab)("indicator.correlationLog.bearColor","Negative"),"bearColor",(0,n.ab)("indicator.correlationLog.bearColor.tooltip","Line and wash color while correlation is below zero.")),az(r.qm,(0,n.ab)("indicator.correlationLog.zeroColor","Zero Line"),"zeroColor",(0,n.ab)("indicator.correlationLog.zeroColor.tooltip","Color of the zero reference line."))],externalSymbols:e=>[nQ(e,"instrument","").trim(),nQ(e,"instrument2","").trim()].filter(Boolean),compute:(e,t,i)=>{let o,l=nQ(t,"instrument","").trim(),a=nQ(t,"instrument2","").trim();if(l&&a){let r=aL(e,i?.get(l)??[]).map(e=>e?e.close:NaN),n=aL(e,i?.get(a)??[]).map(e=>e?e.close:NaN);o=aC(aM(r),aM(n),n_(t,"length",25))}else o=aT(e.length,NaN);return aG({key:"corr",title:(0,n.ab)("indicator.correlationLog.plot.corr","Correlation"),values:o,ink:{bull:nQ(t,"bullColor",r.cr),bear:nQ(t,"bearColor",r.TV),neutral:r.qm},zeroInk:nQ(t,"zeroColor",r.qm)})}}],dk="Settings",dS="Style",dT={groups:nX.groups,options:{...nX.options,same:(0,n.ab)("indicator.compare.scale.same","Same % scale"),"new-scale":(0,n.ab)("indicator.compare.scale.newScale","New price scale"),"new-pane":(0,n.ab)("indicator.compare.scale.newPane","New pane"),solid:(0,n.ab)("indicator.compare.lineStyle.solid","Solid"),dashed:(0,n.ab)("indicator.compare.lineStyle.dashed","Dashed"),dotted:(0,n.ab)("indicator.compare.lineStyle.dotted","Dotted")}},dM=[nP({key:"symbol",title:(0,n.ab)("indicator.compare.symbol","Symbol"),type:"symbol",defval:"",group:dk,tooltip:(0,n.ab)("indicator.compare.symbol.tooltip","Secondary symbol overlaid for comparison.")},dT),nP({key:"scale",title:(0,n.ab)("indicator.compare.scale","Scale"),type:"string",defval:"same",options:["same","new-scale","new-pane"],group:dk,tooltip:(0,n.ab)("indicator.compare.scale.tooltip","Share the main percentage scale, use an independent price scale, or plot in a new pane.")},dT),nP({key:"source",title:(0,n.ab)("indicator.common.source","Source"),type:"string",defval:"Close",options:n5,group:dk,tooltip:(0,n.ab)("indicator.compare.source.tooltip","Price value taken from each bar.")},dT),nP({key:"color",title:(0,n.ab)("indicator.common.color","Color"),type:"color",defval:r.tv[0],group:dS,tooltip:(0,n.ab)("indicator.compare.color.tooltip","Color of the compared symbol line and price-axis badge.")},dT),nP({key:"lineWidth",title:(0,n.ab)("indicator.common.lineWidth","Line Width"),type:"int",defval:2,min:1,max:5,step:1,group:dS,tooltip:(0,n.ab)("indicator.common.lineWidth.tooltip","Width of the plotted line, in pixels.")},dT),nP({key:"lineStyle",title:(0,n.ab)("indicator.compare.lineStyle","Style"),type:"string",defval:"solid",options:["solid","dashed","dotted"],group:dS,tooltip:(0,n.ab)("indicator.compare.lineStyle.tooltip","Stroke pattern of the compared symbol line.")},dT)];function dL(){let e={};for(let t of dM)e[t.key]=t.defval;return e}var dA=class{constructor(){this.ctx=null,this.inputs=dL(),this.suspended=!1,this.extBars=[],this.fetchedSymbol="",this.fetchedFrom=1/0,this.inFlightFrom=null,this.needsCatchup=!1,this.fetchSeq=0,this.unsub=null,this.subSymbol=""}start(e,t){this.ctx=e,this.inputs={...dL(),...t},this.suspended=!1,this.needsCatchup=!1,this.syncAndCompute()}onBars(){this.ctx&&!this.suspended&&this.syncAndCompute()}onViewport(){}setInputs(e){this.inputs={...dL(),...e},this.ctx&&!this.suspended&&this.syncAndCompute()}suspend(){this.suspended=!0,this.fetchSeq+=1,this.inFlightFrom=null,this.needsCatchup=!0,this.clearSub()}resume(){this.suspended=!1,this.ctx&&this.syncAndCompute()}stop(){this.suspended=!0,this.fetchSeq+=1,this.clearSub(),this.extBars=[],this.fetchedSymbol="",this.fetchedFrom=1/0,this.inFlightFrom=null,this.needsCatchup=!1,this.ctx=null}clearSub(){this.unsub?.(),this.unsub=null,this.subSymbol=""}targetSymbol(){return"string"==typeof this.inputs.symbol?this.inputs.symbol.trim():""}isOwnSymbol(e){if(!this.ctx)return!1;let t=e=>(this.ctx.data.canonicalSymbol?.(e)??e).trim().toUpperCase();return t(e)===t(this.ctx.symbol)}ensureSubscription(e){let t=this.ctx;t&&t.live&&t.subscribeSeries&&!this.suspended&&(this.subSymbol===e&&this.unsub||(this.clearSub(),this.subSymbol=e,this.unsub=t.subscribeSeries(e,t.timeframe,t=>{if(this.ctx&&!this.suspended&&this.targetSymbol()===e){var i=this.extBars;let o=i[i.length-1];!o||t.time>o.time?i.push(t):t.time===o.time&&(i[i.length-1]=t),this.emit(this.ctx.bars(),e,this.extBars)}})))}syncAndCompute(){let e=this.ctx;if(!e)return;let t=e.bars(),i=this.targetSymbol();if(!i){this.fetchSeq+=1,this.clearSub(),this.extBars=[],this.fetchedSymbol="",this.fetchedFrom=1/0,this.inFlightFrom=null,this.needsCatchup=!1,this.emit(t,"",[]),e.setStatus("idle");return}if(this.isOwnSymbol(i)){this.fetchSeq+=1,this.clearSub(),this.extBars=[],this.fetchedSymbol="",this.fetchedFrom=1/0,this.inFlightFrom=null,this.needsCatchup=!1,this.emit(t,i,t),e.setStatus("idle");return}if(this.fetchedSymbol!==i&&(this.clearSub(),this.extBars=[],this.fetchedSymbol=i,this.fetchedFrom=1/0,this.inFlightFrom=null,this.needsCatchup=!1),this.emit(t,i,this.extBars),!e.fetchSeries||0===t.length)return void e.setStatus("idle");let r=t[0].time;if(!this.needsCatchup&&r>=this.fetchedFrom&&this.fetchedFrom<1/0){this.ensureSubscription(i),e.setStatus("idle");return}if(!this.needsCatchup&&null!==this.inFlightFrom&&r>=this.inFlightFrom)return;let l=++this.fetchSeq;this.inFlightFrom=r,this.needsCatchup=!1,e.setStatus("loading");let n=function(e,t){if(e.length>=2){let t=e[e.length-1].time-e[e.length-2].time;if(t>0)return t}return(0,o.cle)(t)??6e4}(t,e.timeframe),a={from:r,to:t[t.length-1].time+n,limit:t.length+64};e.fetchSeries(i,e.timeframe,a).then(e=>({ok:!0,fetched:e}),()=>({ok:!1,fetched:[]})).then(({ok:e,fetched:t})=>{l===this.fetchSeq&&this.ctx&&!this.suspended&&this.targetSymbol()===i&&(this.inFlightFrom=null,e&&(this.extBars=function(e,t){if(0===t.length)return[...e];if(0===e.length)return[...t];let i=[...e],o=i[i.length-1].time;for(let e of t)e.time>o?i.push(e):e.time===o&&(i[i.length-1]=e);return i}(t,this.extBars),this.fetchedFrom=Math.min(this.fetchedFrom,r),this.ensureSubscription(i),this.emit(this.ctx.bars(),i,this.extBars)),this.ctx.setStatus("idle"))})}emit(e,t,i){var l,n;let a=this.ctx;if(!a)return;let s="new-scale"===(l=this.inputs.scale)||"new-pane"===l?l:"same",h="string"==typeof this.inputs.source?this.inputs.source:"Close",d="string"==typeof this.inputs.color&&this.inputs.color?this.inputs.color:r.tv[0],c=function(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.min(5,Math.round(t))):2}(this.inputs.lineWidth),p="dashed"===(n=this.inputs.lineStyle)||"dotted"===n?n:"solid",u=t?ei(t):null,g=u?.ticker||t,m=t?a.data.displayPrefix(t)??u?.provider??void 0:void 0,b=m?m.toUpperCase():void 0,f=g?b?`${g} \xb7 ${b}`:g:void 0,v=t?aL(e,i):[],y=Array(e.length);if(t&&v.length===e.length){let t=[],i=[];for(let e=0;e<v.length;e+=1){let o=v[e];o&&(t.push(o),i.push(e))}let o=n3(t,h);for(let t=0;t<e.length;t+=1)y[t]={time:e[t].time,value:null};for(let t=0;t<i.length;t+=1){let r=o[t],l=i[t];y[l]={time:e[l].time,value:Number.isFinite(r)?r:null}}}else for(let t=0;t<e.length;t+=1)y[t]={time:e[t].time,value:null};let w=(0,o.uZt)({instanceId:"compare",kind:"line",title:"compare",ordinal:0});a.emit({...f?{title:f}:{},paneHint:"new-pane"===s?"new":"price",ownScale:"new-scale"===s,percentBaseline:"own",priceAxisLabel:!0,series:[{id:w,title:g||"Compare",paneId:"",kind:"line",points:y,style:{color:d,width:c,lineStyle:p}}]})}},dP={type:"compare",title:(0,n.ab)("indicator.compare.title","Compare symbol"),paneHint:"price",overlay:!0,multiInstance:!0,catalog:!1,inputsSchema:()=>dM.map(e=>({...e})),defaultInputs:()=>dL(),create:()=>new dA},dI=e=>e instanceof Error?e:Error(String(e)),dE=class{constructor(e,t={},i={}){for(let e of((0,o.w$2)({id:"heikinashi",label:(0,n.ab)("chart.priceStyle.heikinashi","Heikin Ashi"),barTransform:nN,supports:e=>!1!==e.ohlc}),(0,o.WG7)(nW),(0,o.WG7)(nZ),dx))(0,o.WG7)(function(e){let t=null;return{type:e.type,title:e.title,...null!=e.shortTitle?{shortTitle:e.shortTitle}:{},paneHint:e.overlay?"price":"new",overlay:e.overlay,multiInstance:!0,waitsForHistory:!0,inputsSchema:()=>t??(t=e.inputs.map(e=>nP(e,nX))),defaultInputs:()=>Object.fromEntries(e.inputs.map(e=>[e.key,e.defval])),create:()=>new n2(e)}}(e));(0,o.WG7)(dP);let r=function(e){if("string"!=typeof e)return e;let t=document.querySelector(e);if(!t)throw Error(`[vela] container not found for selector "${e}"`);return t}(e),l=K(t.theme),a={currentPriceLine:t.currentPriceLine??!0,logScale:t.logScale??!1,nativeBackend:t.nativeBackend??"auto",...function(e){if(!1===e)return{animZoom:0,animPan:0,animScroll:0,animAutoscale:0,animLiveBar:0,animIntro:{style:!1,duration:0}};let t=!0===e||null==e?{}:e,i=e7(t.pan??!0,110);return{animZoom:e7(t.zoom??!0,70),animPan:i,animScroll:void 0===t.scroll?130*(i>0):e7(t.scroll,130),animAutoscale:e7(t.autoscale??!0,80),animLiveBar:e9(t.liveBar),animIntro:te(t.intro??!0)}}(t.animations),glow:t.glow??0,upColor:t.upColor??l.upColor,downColor:t.downColor??l.downColor,priceStyle:t.priceStyle??"candles",priceAxisTicks:t.priceAxis?.ticks??null,freePan:t.freePan??!1},s=t.renderer??nm;if("function"!=typeof s)throw 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 h=i.renderer??new s(a);this.rendererPort=h,this.localeState=new n.O4((0,n.VY)(t));let d=i.engines??[],c=i.dataFeed??new es,p={market:{symbol:t.symbol,timeframe:t.timeframe,bars:t.bars,session:t.session,visibleRange:t.visibleRange,data:t.data},live:t.live??!1,theme:l,defaultLanguage:t.defaultLanguage??d[0]?.language??"pine",drawings:t.drawings,volume:t.volume??!0};this.rendererControl=new Z(h),t.settings&&this.rendererControl.setSettingsVisibility(t.settings),this.dataControl=new ef(c),this.orchestrator=new nI(r,h,c,d,p,this.dataControl);let u=(0,o.gNA)();Object.keys(u).length>0&&this.rendererControl.set(u),this.panesControl=new nO(this.orchestrator),this.drawingsControl=new ev(this.orchestrator.drawings),this.marksControl=new ey(this.orchestrator.marks),this.replayControl=new ew(this.orchestrator),this.orchestrator.setTranslator(this.localeState),this.pushLocalization()}get i18n(){return this.localeState}setLocale(e){return this.localeState.update("string"==typeof e?{locale:e}:(0,n.VY)(e)),this.orchestrator.relocalize(),this.pushLocalization(),this.orchestrator.events.emit("locale:changed",{locale:this.localeState.locale,direction:this.localeState.direction}),this}pushLocalization(){let e=this.localeState;this.rendererPort.setLocalization?.(e,{lang:e.localeExplicit?e.locale:null,dir:e.directionExplicit?e.direction:null})}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()}pendingNativeIndicators(){return this.orchestrator.pendingNativeIndicators()}symbolFacts(){return this.orchestrator.symbolFacts()}indicators(){return this.orchestrator.listIndicators()}runScript(e,t){let i;try{i=this.addIndicator(e,t)}catch(e){return Promise.resolve({ok:!1,run:null,error:dI(e),onUpdate:()=>()=>void 0,remove:()=>void 0})}let o=new Set,r=()=>{try{i.remove()}catch{}};return new Promise(e=>{let t=!1,l=this.on("script:run",a=>{if(a.id===i.id){if(t){for(let e of o)e(a);return}t=!0,n(),e({ok:!0,run:a,error:null,onUpdate:e=>(o.add(e),()=>o.delete(e)),remove:()=>{l(),o.clear(),r()}})}}),n=i.on("error",({error:i})=>{t||(t=!0,l(),n(),r(),e({ok:!1,run:null,error:i,onUpdate:()=>()=>void 0,remove:()=>void 0}))})})}runIndicator(e,t){let i;try{i=this.addIndicator(e,t)}catch(e){return Promise.resolve({ok:!1,handle:null,error:dI(e),context:null})}return new Promise(e=>{let t=i.on("ready",()=>{t(),o(),e({ok:!0,handle:i,error:null,context:null})}),o=i.on("error",({error:r})=>{t(),o(),i.context().catch(()=>null).then(t=>{try{i.remove()}catch{}e({ok:!1,handle:null,error:r,context:t})})})})}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}get replay(){return this.replayControl}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(K(e)),this}destroy(){this.orchestrator.destroy()}}}}]);