openalgo-charts 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +43 -7
- package/dist/indicators/index.d.ts +11 -1
- package/dist/openalgo-charts.indicators.mjs +1 -1
- package/dist/openalgo-charts.indicators.mjs.map +1 -1
- package/dist/openalgo-charts.mjs +1 -1
- package/dist/openalgo-charts.mjs.map +1 -1
- package/dist/openalgo-charts.standalone.js +1 -1
- package/dist/openalgo-charts.standalone.js.map +1 -1
- package/dist/profile/index.d.ts +6 -0
- package/dist/transform/index.d.ts +6 -0
- package/package.json +1 -1
package/dist/openalgo-charts.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e="1.0.21";function t(){return e}const i={None:0,Cursor:1,Light:2,Full:3};class s{constructor(e=i.None){Object.defineProperty(this,"_globalLevel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_panes",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_timeScaleOps",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._globalLevel=e}get globalLevel(){return this._globalLevel}invalidateGlobal(e){e>this._globalLevel&&(this._globalLevel=e)}invalidatePane(e,t){var i,s;this._panes.set(e,(i=this._panes.get(e),s=t,void 0===i?{...s}:{level:Math.max(i.level,s.level),autoScale:i.autoScale||s.autoScale}))}paneInvalidation(e){return this._panes.get(e)}panes(){return this._panes}addTimeScaleOp(e){this._timeScaleOps.push(e)}timeScaleOps(){return this._timeScaleOps}isEmpty(){return this._globalLevel===i.None&&0===this._panes.size&&0===this._timeScaleOps.length}merge(e){this.invalidateGlobal(e._globalLevel);for(const[t,i]of e._panes)this.invalidatePane(t,i);e._timeScaleOps.length>0&&(this._timeScaleOps=this._timeScaleOps.concat(e._timeScaleOps))}}const r=()=>{};class n{constructor(e,t,i){if(Object.defineProperty(this,"_onFrame",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_schedule",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cancel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_handle",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._onFrame=e,t)this._schedule=t,this._cancel=i??r;else{const e="function"==typeof requestAnimationFrame?{schedule:e=>requestAnimationFrame(e),cancel:e=>cancelAnimationFrame(e)}:{schedule:e=>setTimeout(e,16),cancel:e=>clearTimeout(e)};this._schedule=e.schedule,this._cancel=e.cancel}}get scheduled(){return null!==this._handle}requestFrame(){if(null!==this._handle)return;this._handle=-1;const e=this._schedule(()=>{this._handle=null,this._onFrame()});null!==this._handle&&(this._handle=e)}stop(){null!==this._handle&&(this._cancel(this._handle),this._handle=null)}}function o(e,t,i){return{width:Math.round(e*i),height:Math.round(t*i)}}function a(e,t){return Math.round(e*t)/t}class l{constructor(e,t){Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mediaWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_mediaHeight",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dpr",{enumerable:!0,configurable:!0,writable:!0,value:1}),this.element=e.createElement("canvas");const i=this.element.getContext("2d");if(null===i)throw new Error("openalgo-charts: 2D canvas context is not available");this.ctx=i;const s=this.element.style;s.position="absolute",s.top="0",s.left="0",s.width="100%",s.height="100%",s.zIndex=String(t)}get mediaWidth(){return this._mediaWidth}get mediaHeight(){return this._mediaHeight}get pixelRatio(){return this._dpr}resize(e,t,i){if(e===this._mediaWidth&&t===this._mediaHeight&&i===this._dpr)return;this._mediaWidth=e,this._mediaHeight=t,this._dpr=i;const s=o(e,t,i);this.element.width=s.width,this.element.height=s.height,this.element.style.width=`${e}px`,this.element.style.height=`${t}px`}clearBitmap(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.element.width,this.element.height)}}function h(e,t,i){return e<t?t:e>i?i:e}function c(e,t,i){return e+(t-e)*i}function d(e,t){return t<=0?e:Math.round(e/t)*t}function u(e){const t=Math.floor(Math.log10(e)),i=e/Math.pow(10,t);for(const e of[1,2,2.5,5])if(e>i*(1+1e-9))return e*Math.pow(10,t);return 10*Math.pow(10,t)}function p(e,t,i){const s=Math.ceil(e/i)*i,r=Math.floor(t/i)*i;return Math.round((r-s)/i)+1}function _(e,t,i=6){if(!isFinite(e)||!isFinite(t)||t<=e)return[Number.isFinite(e)?e:0];let s=function(e){if(e<=0)return 0;const t=Math.floor(Math.log10(e)),i=e/Math.pow(10,t);let s;return s=i<1.5?1:i<3?2:i<7?5:10,s*Math.pow(10,t)}((t-e)/Math.max(1,i-1));if(!(s>0))return[e];for(let r=0;r<20&&p(e,t,s)>i;r++)s=u(s);const r=Math.ceil(e/s)*s,n=Math.floor(t/s)*s,o=[],a=Math.round((n-r)/s)+1;for(let e=0;e<a&&e<1e3;e++){const t=r+e*s;o.push(Math.abs(t)<s/1e6?0:t)}return o}function f(e){return e<=0||!isFinite(e)?2:e>=1?0:Math.min(8,Math.ceil(-Math.log10(e)))}const b={marginTop:.1,marginBottom:.1,minMove:0,mode:"linear",inverted:!1};function m(e,t,i,s){if(!isFinite(e)||!isFinite(t))return{min:0,max:1};if(t<=e){const i=Math.abs(t)>0?.05*Math.abs(t):.5;return{min:e-i,max:t+i}}const r=t-e;return{min:e-r*s,max:t+r*i}}class g{constructor(e={}){Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_min",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_max",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_autoScale",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_scaled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_priceFormatter",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._options={...b,...e}}get options(){return this._options}setOptions(e){this._options={...this._options,...e}}setHeight(e){this._height=e}get height(){return this._height}setPriceRange(e){this._min=e.min,this._max=e.max,this._scaled=!0}get scaled(){return this._scaled}priceRange(){return{min:this._min,max:this._max}}get autoScale(){return this._autoScale}setAutoScale(e){this._autoScale=e}scaleAroundCenter(e){const t=(this._min+this._max)/2,i=(this._max-this._min)/2*e;this._min=t-i,this._max=t+i,this._autoScale=!1}panByPixels(e){if(this._height<=0||0===e)return;const t=this._t(this._min),i=this._t(this._max),s=i-t;if(!(s>0))return;const r=s*((this._options.inverted?-e:e)/this._height);this._min=this._tInv(t+r),this._max=this._tInv(i+r),this._autoScale=!1}autoscale(e,t){this.setPriceRange(m(e,t,this._options.marginTop,this._options.marginBottom))}_t(e){return"logarithmic"===this._options.mode?Math.log10(Math.max(1e-10,e)):e}_tInv(e){return"logarithmic"===this._options.mode?Math.pow(10,e):e}priceToY(e){const t=this._t(this._min),i=this._t(this._max)-t;if(i<=0)return this._height/2;const s=(this._t(e)-t)/i;return this._options.inverted?this._height*s:this._height*(1-s)}yToPrice(e){const t=this._t(this._min),i=this._t(this._max)-t,s=this._options.inverted?e/this._height:1-e/this._height;return this._tInv(t+s*i)}precision(){return this._options.minMove>0?f(this._options.minMove):f((this._max-this._min)/100)}snapToTick(e){const t=this._options.minMove;return t<=0?e:Math.round(e/t)*t}setPriceFormatter(e){this._priceFormatter=e}format(e){return null!==this._priceFormatter?this._priceFormatter(e):e.toFixed(this.precision())}clampY(e){return h(e,0,this._height)}}const v={barSpacing:8,minBarSpacing:1,maxBarSpacing:80,rightOffset:4};class y{constructor(e={}){Object.defineProperty(this,"_barSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rightOffset",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_minBarSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maxBarSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_baseIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:null});const t={...v,...e};this._barSpacing=t.barSpacing,this._rightOffset=t.rightOffset,this._minBarSpacing=t.minBarSpacing,this._maxBarSpacing=t.maxBarSpacing}setWidth(e){this._width=e}get width(){return this._width}get barSpacing(){return this._barSpacing}setBarSpacing(e){this._barSpacing=h(e,this._minBarSpacing,this._maxBarSpacing)}get rightOffset(){return this._rightOffset}setRightOffset(e){this._rightOffset=e}setBaseIndex(e){this._baseIndex=e}_rightEdgeIndex(){return this._baseIndex+this._rightOffset}indexToX(e){return this._width-(this._rightEdgeIndex()-e)*this._barSpacing}xToIndex(e){return this._rightEdgeIndex()-(this._width-e)/this._barSpacing}visibleRange(){const e=this._rightEdgeIndex();return{from:e-this._width/this._barSpacing,to:e}}getVisibleLogicalRange(){return this.visibleRange()}setVisibleLogicalRange(e){if(this._width<=0)return;const t=e.to-e.from;t>0&&(this.setBarSpacing(this._width/t),this._rightOffset=e.to-this._baseIndex,this._onChange?.())}setChangeHandler(e){this._onChange=e}scrollByPixels(e){this._rightOffset-=e/this._barSpacing}zoomAtX(e,t){const i=this.xToIndex(e),s=this._barSpacing;if(this.setBarSpacing(s*t),this._barSpacing===s)return;const r=i+(this._width-e)/this._barSpacing;this._rightOffset=r-this._baseIndex}fitContent(e){if(e<=0||this._width<=0)return;this._baseIndex=e-1,this._rightOffset=v.rightOffset;const t=this._width/(e+this._rightOffset);this.setBarSpacing(t)}}const w=[];class x{constructor(){Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_sortedTimes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_indexByTime",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_nextId",{enumerable:!0,configurable:!0,writable:!0,value:1})}createSeries(){const e=this._nextId++;return this._series.set(e,{bars:[]}),e}removeSeries(e){this._series.delete(e),this._rebuild()}setSeriesData(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);i.bars=function(e){const t=e.slice().sort((e,t)=>e.time-t.time);let i=0;for(let e=0;e<t.length;e++)i>0&&t[e].time===t[i-1].time?t[i-1]=t[e]:t[i++]=t[e];return t.length=i,t}(t),this._rebuild()}addBars(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);if(0===t.length)return;const s=new Map;for(const e of i.bars)s.set(e.time,e);for(const e of t)s.set(e.time,e);i.bars=Array.from(s.values()).sort((e,t)=>e.time-t.time),this._rebuild()}update(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);const s=i.bars,r=s[s.length-1];if(void 0===r||t.time>r.time){s.push(t);const e=this._sortedTimes.length,i=e>0?this._sortedTimes[e-1]:void 0;return void 0===i||t.time>i?(this._appendTime(t.time),"append"):this._indexByTime.has(t.time)?"replace":(this._rebuild(),"insert")}if(t.time===r.time)return s[s.length-1]=t,"replace";const n=s.findIndex(e=>e.time===t.time);return n>=0?(s[n]=t,"replace"):(this.addBars(e,[t]),"insert")}_appendTime(e){this._indexByTime.has(e)||(this._indexByTime.set(e,this._sortedTimes.length),this._sortedTimes.push(e))}get length(){return this._sortedTimes.length}get baseIndex(){return this._sortedTimes.length-1}indexToTime(e){return this._sortedTimes[e]}timeToIndex(e){return this._indexByTime.get(e)}indexToTimeFloat(e){const t=this._sortedTimes,i=t.length;if(0===i)return NaN;if(1===i)return t[0];if(e<=0)return t[0]+e*(t[1]-t[0]);if(e>=i-1)return t[i-1]+(e-(i-1))*(t[i-1]-t[i-2]);const s=Math.floor(e);return t[s]+(e-s)*(t[s+1]-t[s])}timeToIndexFloat(e){const t=this._sortedTimes,i=t.length;if(0===i)return NaN;if(1===i)return 0;if(e<=t[0]){const i=t[1]-t[0];return i>0?(e-t[0])/i:0}if(e>=t[i-1]){const s=t[i-1]-t[i-2];return s>0?i-1+(e-t[i-1])/s:i-1}let s=0,r=i-1;for(;s<r;){const i=s+r+1>>1;t[i]<=e?s=i:r=i-1}const n=t[s+1]-t[s];return n>0?s+(e-t[s])/n:s}seriesBars(e){return this._series.get(e)?.bars??w}indexedBars(e){const t=this._series.get(e);if(void 0===t)return[];const i=[];for(const e of t.bars){const t=this._indexByTime.get(e.time);void 0!==t&&i.push({index:t,bar:e})}return i}visibleBars(e,t,i){const s=this._series.get(e);if(void 0===s)return[];const r=s.bars,n=Math.max(0,Math.floor(t)),o=Math.min(this.baseIndex,Math.ceil(i));if(o<n||0===r.length)return[];const a=this._sortedTimes[n],l=this._sortedTimes[o];if(void 0===a||void 0===l)return[];let h=0,c=r.length;for(;h<c;){const e=h+c>>1;r[e].time<a?h=e+1:c=e}const d=[];for(let e=h;e<r.length;e++){const t=r[e].time;if(t>l)break;const i=this._indexByTime.get(t);void 0!==i&&d.push({index:i,bar:r[e]})}return d}lastIndexedBar(e){const t=this._series.get(e);if(void 0===t||0===t.bars.length)return null;const i=t.bars[t.bars.length-1],s=this._indexByTime.get(i.time);return void 0===s?null:{index:s,bar:i}}_rebuild(){const e=new Set;for(const t of this._series.values())for(const i of t.bars)e.add(i.time);this._sortedTimes=Array.from(e).sort((e,t)=>e-t),this._indexByTime.clear();for(let e=0;e<this._sortedTimes.length;e++)this._indexByTime.set(this._sortedTimes[e],e)}}const P={upColor:"#26a69a",downColor:"#ef5350",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350",borderVisible:!0,wickVisible:!0};function S(e,t){const i=Math.floor(e*t*.8);let s=Math.max(1,i);if(s>=2){s%2!=Math.max(1,Math.floor(t))%2&&(s-=1)}return Math.max(1,s)}function O(e,t,i,s,r,n=P){const o=S(s,r),a=Math.max(1,Math.floor(r));for(const{x:s,bar:l}of t){const t=l.close>=l.open,h=Math.round(s*r),c=Math.round(i(l.open)*r),d=Math.round(i(l.close)*r),u=Math.round(i(l.high)*r),p=Math.round(i(l.low)*r),_=n.widthScale?Math.max(.05,Math.min(1,n.widthScale(l))):1,f=1===_?o:Math.max(1,Math.round(o*_)),b=Math.floor(f/2);n.wickVisible&&(e.fillStyle=t?n.wickUpColor:n.wickDownColor,e.fillRect(h-Math.floor(a/2),u,a,Math.max(1,p-u)));const m=Math.min(c,d),g=Math.max(1,Math.abs(d-c)),v=t?n.upColor:n.downColor;n.hollow&&t?(e.strokeStyle=v,e.lineWidth=Math.max(1,a),e.strokeRect(h-b+.5,m+.5,f-1,g-1)):(e.fillStyle=v,e.fillRect(h-b,m,f,g),n.borderVisible&&f>=3&&!n.hollow&&(e.strokeStyle=t?n.borderUpColor:n.borderDownColor,e.lineWidth=1,e.strokeRect(h-b+.5,m+.5,f-1,g-1)))}}function T(e,t,i){const s=e.bar;return{cx:Math.round(e.x*i),yOpen:Math.round(t(s.open)*i),yClose:Math.round(t(s.close)*i),yHigh:Math.round(t(s.high)*i),yLow:Math.round(t(s.low)*i),up:s.close>=s.open}}function M(e,t,i,s,r,n,o=!1){const a=Math.max(1,Math.floor(S(s,r)/2)),l=Math.max(1,Math.floor(r));e.save();for(const s of t){const t=T(s,i,r);e.fillStyle=t.up?n.upColor??"#26a69a":n.downColor??"#ef5350",e.fillRect(t.cx-Math.floor(l/2),t.yHigh,l,Math.max(1,t.yLow-t.yHigh)),o||(e.fillRect(t.cx-a,t.yOpen,a,l),e.fillRect(t.cx,t.yClose,a,l))}e.restore()}const C=new WeakMap;function I(e,t,i,s){let r=C.get(e);void 0===r&&(r=new Map,C.set(e,r));const n=`${Math.round(t)}|${i}|${s}`;let o=r.get(n);return void 0===o&&(o=e.createLinearGradient(0,0,0,t),o.addColorStop(0,i),o.addColorStop(1,s),r.set(n,o)),o}function j(e,t,i=e=>e.close){return e.map(e=>({x:e.x,y:t(i(e.bar))}))}function L(e,t,i,s,r){const n=j(t,i),o=r.step?function(e){if(0===e.length)return[];const t=[{...e[0]}];for(let i=1;i<e.length;i++)t.push({x:e[i].x,y:e[i-1].y}),t.push({x:e[i].x,y:e[i].y});return t}(n):n;e.save(),e.strokeStyle=r.color??"#4f8cff",e.lineWidth=Math.max(1,(r.lineWidth??1.5)*s),e.lineJoin="round",e.lineCap="round";const a="dashed"===r.lineStyle?[6*s,4*s]:"dotted"===r.lineStyle?[1*s,3*s]:[];if(e.setLineDash(a),r.markersOnly||function(e,t,i){if(0===t.length)return;e.beginPath();let s=!1;for(const r of t)Number.isFinite(r.x)&&Number.isFinite(r.y)?s?e.lineTo(r.x*i,r.y*i):(e.moveTo(r.x*i,r.y*i),s=!0):s=!1;e.stroke()}(e,o,s),e.setLineDash([]),r.markers||r.markersOnly){const t=(r.markerRadius??2)*s;e.fillStyle=r.color??"#4f8cff";for(const i of n)Number.isFinite(i.x)&&Number.isFinite(i.y)&&(e.beginPath(),e.arc(i.x*s,i.y*s,t,0,2*Math.PI),e.fill())}e.restore()}const k={color:"#3a4666",base:0};function A(e,t,i={}){return{...P,upColor:e.upColor??t.upColor,downColor:e.downColor??t.downColor,borderUpColor:e.borderUpColor??t.upColor,borderDownColor:e.borderDownColor??t.downColor,wickUpColor:e.wickUpColor??t.wickUpColor,wickDownColor:e.wickDownColor??t.wickDownColor,borderVisible:e.borderVisible??P.borderVisible,wickVisible:e.wickVisible??P.wickVisible,...i}}const F=e=>({min:e.low,max:e.high}),R=e=>({min:e.close,max:e.close}),B=(e,t)=>{const i=t.base??0;return{min:Math.min(i,e.close),max:Math.max(i,e.close)}},N=new Map,W=new Set(["point-figure","kagi"]);function D(e,t){N.set(e,t)}function z(e){const t=N.get(e);if(void 0===t){if(W.has(e))throw new Error(`openalgo-charts: series type "${e}" needs the transform tier — import 'openalgo-charts/transform' first`);throw new Error(`openalgo-charts: unknown series type "${e}"`)}return t}function $(){return Array.from(N.keys())}const H=(e,t)=>({...e,upColor:e.upColor??t.upColor,downColor:e.downColor??t.downColor});function q(e,t,i=.5,s=1){const r=e*t;if(r<=0)return 1;const n=i*Math.max(1,s);return r>=n?1:Math.max(1,Math.ceil(n/r))}function E(e){const t=e[0];let i=t.high,s=t.low,r=t.volume??0,n=void 0!==t.volume;for(let t=1;t<e.length;t++){const o=e[t];o.high>i&&(i=o.high),o.low<s&&(s=o.low),void 0!==o.volume&&(r+=o.volume,n=!0)}const o={time:t.time,open:t.open,high:i,low:s,close:e[e.length-1].close};return n&&(o.volume=r),o}function U(e,t){if(t<=1)return e.slice();const i=[];for(let s=0;s<e.length;s+=t)i.push(E(e.slice(s,s+t)));return i}function V(e,t){if(t<=1)return e.map(e=>({x:e.x,bar:e.bar}));const i=[];for(let s=0;s<e.length;s+=t){const r=e.slice(s,s+t),n=r.reduce((e,t)=>e+t.x,0)/r.length;i.push({x:n,bar:E(r.map(e=>e.bar))})}return i}D("candlestick",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>O(e,t,i,s,r,A(n,o.theme)),extents:F}),D("hollow-candle",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>O(e,t,i,s,r,A(n,o.theme,{hollow:!0})),extents:F}),D("volume-candle",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>{const a=o.maxVolume;O(e,t,i,s,r,A(n,o.theme,{widthScale:e=>a>0?(e.volume??0)/a:1}))},extents:F}),D("bar",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>M(e,t,i,s,r,H(n,o.theme)),extents:F}),D("high-low",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>M(e,t,i,s,r,H(n,o.theme),!0),extents:F}),D("line",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>L(e,t,i,r,{...n,color:n.color??o.theme.lineColor}),extents:R}),D("line-markers",{defaultStyle:{lineWidth:1.5,markers:!0},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>L(e,t,i,r,{...n,color:n.color??o.theme.lineColor,markers:!0}),extents:R}),D("step",{defaultStyle:{lineWidth:1.5,step:!0},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>L(e,t,i,r,{...n,color:n.color??o.theme.lineColor,step:!0}),extents:R}),D("area",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>function(e,t,i,s,r,n){const o=j(t,i);if(0===o.length)return;const a=r*s;e.save(),e.beginPath(),e.moveTo(o[0].x*s,a);for(const t of o)e.lineTo(t.x*s,t.y*s);e.lineTo(o[o.length-1].x*s,a),e.closePath(),e.fillStyle=I(e,a,n.areaTopColor??"rgba(79,140,255,0.40)",n.areaBottomColor??"rgba(79,140,255,0.00)"),e.fill(),e.restore(),L(e,t,i,s,{color:n.color??"#4f8cff",lineWidth:n.lineWidth??1.5})}(e,t,i,r,o.plotHeight,{...n,color:n.color??o.theme.lineColor,areaTopColor:n.areaTopColor??o.theme.areaTopColor,areaBottomColor:n.areaBottomColor??o.theme.areaBottomColor}),extents:R}),D("hlc-area",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>function(e,t,i,s,r){if(0===t.length)return;const n=j(t,i,e=>e.high),o=j(t,i,e=>e.low);e.save(),e.beginPath(),e.moveTo(n[0].x*s,n[0].y*s);for(const t of n)e.lineTo(t.x*s,t.y*s);for(let t=o.length-1;t>=0;t--)e.lineTo(o[t].x*s,o[t].y*s);e.closePath(),e.fillStyle=r.areaTopColor??"rgba(79,140,255,0.15)",e.fill(),e.restore(),L(e,t,i,s,{color:r.closeColor??"#4f8cff",lineWidth:r.lineWidth??1.5})}(e,t,i,r,{...n,closeColor:n.closeColor??o.theme.lineColor}),extents:F}),D("baseline",{defaultStyle:{baseValue:0,lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,n,o)=>function(e,t,i,s,r){const n=i(r.baseValue??0)*s,o=j(t,i);if(0===o.length)return;const a=o[0].x*s,l=o[o.length-1].x*s,h=()=>{e.beginPath(),e.moveTo(a,n);for(const t of o)e.lineTo(t.x*s,t.y*s);e.lineTo(l,n),e.closePath()},c=r.areaTopColor??"rgba(38,166,154,0.20)",d=r.areaBottomColor??"rgba(239,83,80,0.20)",u=1e5;e.save(),e.beginPath(),e.rect(a,n-u,l-a,u),e.clip(),h(),e.fillStyle=I(e,n,c,"rgba(0,0,0,0)"),e.fill(),e.restore(),e.save(),e.beginPath(),e.rect(a,n,l-a,u),e.clip(),h(),e.fillStyle=d,e.fill(),e.restore(),e.save();for(let t=1;t<o.length;t++){const i=o[t-1],a=o[t],l=(i.y+a.y)/2<=n/s;e.strokeStyle=l?r.topColor??"#26a69a":r.bottomColor??"#ef5350",e.lineWidth=Math.max(1,Math.round((r.lineWidth??1.5)*s)),e.beginPath(),e.moveTo(i.x*s,i.y*s),e.lineTo(a.x*s,a.y*s),e.stroke()}e.restore()}(e,t,i,r,{...n,topColor:n.topColor??o.theme.baselineTopLine,bottomColor:n.bottomColor??o.theme.baselineBottomLine,areaTopColor:n.areaTopColor??o.theme.baselineTopFill,areaBottomColor:n.areaBottomColor??o.theme.baselineBottomFill}),extents:(e,t)=>{const i=t.baseValue??0;return{min:Math.min(i,e.close),max:Math.max(i,e.close)}}}),D("column",{defaultStyle:{base:0},isPriceSeries:!1,draw:(e,t,i,s,r,n,o)=>function(e,t,i,s,r,n){const o=S(s,r),a=Math.floor(o/2),l=Math.round(i(n.base??0)*r);e.save();for(const s of t){const t=T(s,i,r);e.fillStyle=t.up?n.upColor??"#26a69a":n.downColor??"#ef5350";const h=Math.min(l,t.yClose);e.fillRect(t.cx-a,h,o,Math.max(1,Math.abs(l-t.yClose)))}e.restore()}(e,t,i,s,r,H(n,o.theme)),extents:B}),D("histogram",{defaultStyle:{base:0,color:"#3a4666"},isPriceSeries:!1,draw:(e,t,i,s,r,n)=>{!function(e,t,i,s,r,n=k){const o=S(s,r),a=Math.floor(o/2),l=Math.round(i(n.base)*r);e.fillStyle=n.color;for(const{x:s,bar:n}of t){const t=Math.round(s*r),h=Math.round(i(n.close)*r),c=Math.min(l,h),d=Math.max(1,Math.abs(l-h));e.fillRect(t-a,c,o,d)}}(e,t,i,s,r,{color:n.color??"#3a4666",base:n.base??0})},extents:B});const Y=19800;function G(e){return Math.floor(e/1e3)}function K(e){const t=e.trim(),i=/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/.exec(t);if(null===i)throw new Error(`openalgo-charts: unparseable IST time string "${e}"`);const s=Number(i[1]),r=Number(i[2]),n=Number(i[3]),o=void 0!==i[4]?Number(i[4]):0,a=void 0!==i[5]?Number(i[5]):0,l=void 0!==i[6]?Number(i[6]):0,h=Date.UTC(s,r-1,n,o,a,l);return Math.floor(h/1e3)-Y}function X(e){const t=new Date(1e3*(e+Y));return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds(),weekday:t.getUTCDay()}}const J=e=>e<10?`0${e}`:String(e);function Q(e){const t=X(e);return`${J(t.hour)}:${J(t.minute)}`}function Z(e){const t=X(e);return`${J(t.hour)}:${J(t.minute)}:${J(t.second)}`}function ee(e){const t=X(e);return`${t.year}-${J(t.month)}-${J(t.day)}`}const te=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function ie(e){const t=X(e);return`${J(t.day)} ${te[t.month-1]}`}const se=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function re(e,t){const i=X(e),s=X(t);return i.year!==s.year||i.month!==s.month||i.day!==s.day}const ne={textColor:"#8b91a7",lineColor:"#2a3046",font:"11px system-ui, sans-serif"};function oe(e,t){return e.replace(/(\d+(?:\.\d+)?)px/,(e,i)=>Number(i)*t+"px")}function ae(e,t,i,s,r,n,o,a){e.save(),e.font=11*r+"px system-ui, sans-serif";const l=6*r,h=16*r,c=e.measureText(t).width;if(e.fillStyle=n,e.textBaseline="middle","right"===a)e.fillRect(i+1,s-h/2,c+2*l,h),e.fillStyle=o,e.textAlign="left",e.fillText(t,i+1+l,s);else{const r=c+2*l;e.fillRect(i-r/2,s,r,h),e.fillStyle=o,e.textAlign="center",e.fillText(t,i,s+h/2)}e.restore()}function le(e){const t={top:2,normal:1,bottom:0};let i=null;for(const s of e)null!==s&&(null===i||s.distance<i.distance||s.distance===i.distance&&t[s.zOrder]>t[i.zOrder])&&(i=s);return i}class he{constructor(e){Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"base",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"priceScale",{enumerable:!0,configurable:!0,writable:!0,value:new g}),Object.defineProperty(this,"_leftScale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_overlayScale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"weight",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_primitives",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),this.element=e.createElement("div"),this.element.style.position="relative",this.element.style.width="100%",this.element.style.flex="1 1 auto",this.element.style.overflow="hidden",this.base=new l(e,0),this.top=new l(e,1),this.element.appendChild(this.base.element),this.element.appendChild(this.top.element)}addSeries(e){this._scaleFor(e.scaleId),this._series.push(e)}_scaleFor(e){return"left"===e?this._leftScale??(this._leftScale=new g):""===e?this._overlayScale??(this._overlayScale=new g):this.priceScale}scaleOf(e){return this._scaleFor(e.scaleId)}hasLeftScale(){return null!==this._leftScale&&this._series.some(e=>"left"===e.scaleId)}removeSeries(e){const t=this._series.indexOf(e);return!(t<0)&&(this._series.splice(t,1),!0)}series(){return this._series}primitives(){return this._primitives}addPrimitive(e,t){this._primitives.push(e),e.attached?.(t)}removePrimitive(e){const t=this._primitives.indexOf(e);return!(t<0)&&(this._primitives.splice(t,1),e.detached?.(),!0)}destroy(){for(const e of this._primitives)e.detached?.();this._primitives.length=0,this.element.remove()}_primitiveContext(e){const t=this._layout(e);return{timeScale:e.timeScale,priceScale:this.priceScale,dataLayer:e.dataLayer,plotWidth:t.plotWidth,plotHeight:t.plotHeight,priceAxisWidth:e.priceAxisWidth,dpr:e.dpr,theme:e.theme,hoverId:e.hoverId??null,dragId:e.dragId??null,bars:()=>{for(const t of this._series)if(z(t.type).isPriceSeries)return e.dataLayer.seriesBars(t.dataId);return[]}}}hitTestPrimitives(e,t,i){const s=this._primitiveContext(i);return le(this._primitives.map(i=>i.hitTest?i.hitTest(e,t,s):null))}resize(e,t,i){this._width=e,this._height=t,this.base.resize(e,t,i),this.top.resize(e,t,i)}setScaleHeights(e){this.priceScale.setHeight(e),this._leftScale?.setHeight(e),this._overlayScale?.setHeight(e)}_layout(e){const t=e.leftAxisWidth??0;return{plotWidth:Math.max(0,this._width-e.priceAxisWidth-t),plotHeight:Math.max(0,this._height-(e.showTimeAxis?e.timeAxisHeight:0)),priceAxisWidth:e.priceAxisWidth,timeAxisHeight:e.showTimeAxis?e.timeAxisHeight:0,plotLeft:t}}autoscale(e){const t=this._layout(e),i=e.timeScale.visibleRange();this._autoscaleScale(this.priceScale,e=>"right"===e.scaleId,!0,e,t.plotHeight,i),this._leftScale&&this._autoscaleScale(this._leftScale,e=>"left"===e.scaleId,!1,e,t.plotHeight,i),this._overlayScale&&this._autoscaleScale(this._overlayScale,e=>""===e.scaleId,!1,e,t.plotHeight,i)}_autoscaleScale(e,t,i,s,r,n){if(e.setHeight(r),!e.autoScale)return;let o=1/0,a=-1/0;for(const e of this._series){if(!1===e.style.visible||!t(e))continue;const i=z(e.type);for(const t of s.dataLayer.visibleBars(e.dataId,n.from,n.to)){const s=i.extents(t.bar,e.style);s.min<o&&(o=s.min),s.max>a&&(a=s.max)}}if(i)for(const e of this._primitives){const t=e.autoscaleInfo?.();t&&(t.min<o&&(o=t.min),t.max>a&&(a=t.max))}o<=a&&e.autoscale(o,a)}paintBase(e){const t=this._layout(e),i=e.dpr,s=this.base.ctx;this.base.clearBitmap();const r={textColor:e.theme.axisText,lineColor:e.theme.axisLine,font:`${e.theme.axisFontSize??11}px system-ui, sans-serif`};if("transparent"!==e.theme.background&&(s.fillStyle=e.theme.background,s.fillRect(0,0,Math.round(this._width*i),Math.round(this._height*i))),this._leftScale&&t.plotLeft>0&&function(e,t,i,s,r,n=ne){const o=t.priceRange(),a=_(o.min,o.max,6),l=Math.round(i*r);e.save(),e.strokeStyle=n.lineColor,e.fillStyle=n.textColor,e.font=oe(n.font,r),e.textAlign="right",e.textBaseline="middle",e.lineWidth=1,e.beginPath(),e.moveTo(l-.5,0),e.lineTo(l-.5,Math.round(s*r)),e.stroke();for(const i of a){const n=Math.round(t.priceToY(i)*r);n<0||n>s*r||e.fillText(t.format(i),l-6*r,n)}e.restore()}(s,this._leftScale,t.plotLeft,t.plotHeight,i,r),s.save(),t.plotLeft>0&&s.translate(Math.round(t.plotLeft*i),0),e.showVertGrid||e.showHorzGrid){const r=function(e,t,i){const s=Math.max(1,i.spacing),r=[];for(let t=s;t<e;t+=s)r.push(t);const n=[];for(let e=s;e<t;e+=s)n.push(e);return{verticals:r,horizontals:n}}(t.plotWidth,t.plotHeight,{spacing:60}),n="dashed"===e.theme.gridStyle?[4*i,4*i]:"dotted"===e.theme.gridStyle?[1*i,3*i]:void 0;!function(e,t,i,s,r,n){e.save(),e.strokeStyle=n.color,e.lineWidth=Math.max(1,Math.round(n.lineWidth*r)),n.dash&&e.setLineDash(n.dash),e.beginPath();const o=Math.round(i*r),l=Math.round(s*r);for(const i of t.verticals){const t=Math.round(a(i,r)*r)+0;e.moveTo(t,0),e.lineTo(t,l)}for(const i of t.horizontals){const t=Math.round(a(i,r)*r)+0;e.moveTo(0,t),e.lineTo(o,t)}e.stroke(),e.restore()}(s,{verticals:e.showVertGrid?r.verticals:[],horizontals:e.showHorzGrid?r.horizontals:[]},t.plotWidth,t.plotHeight,i,{color:e.theme.grid,lineWidth:1,dash:n})}const n=this._primitiveContext(e);for(const e of this._primitives)"bottom"===e.zOrder()&&e.draw(s,n);const o=e.timeScale.visibleRange();let l=null;const h=e.conflate?q(e.timeScale.barSpacing,i,.5,e.conflationFactor):1;for(const r of this._series){if(!1===r.style.visible)continue;const n=this._scaleFor(r.scaleId),a=e=>n.priceToY(e),c=z(r.type);let d=e.dataLayer.visibleBars(r.dataId,o.from,o.to).map(t=>({x:e.timeScale.indexToX(t.index),bar:t.bar}));h>1&&(d=V(d,h));let u=0;for(const e of d)(e.bar.volume??0)>u&&(u=e.bar.volume??0);const p={plotHeight:t.plotHeight,maxVolume:u,theme:e.theme};if(c.draw(s,d,a,e.timeScale.barSpacing,i,r.style,p),c.isPriceSeries&&null===l&&n===this.priceScale){const t=e.dataLayer.lastIndexedBar(r.dataId);null!==t&&(l={close:t.bar.close,up:t.bar.close>=t.bar.open,showLine:!1!==r.style.priceLineVisible,showTag:!1!==r.style.lastValueVisible})}}!function(e,t,i,s,r=ne){const n=t.priceRange(),o=_(n.min,n.max,6),a=Math.round(i.plotWidth*s);e.save(),e.strokeStyle=r.lineColor,e.fillStyle=r.textColor,e.font=oe(r.font,s),e.textAlign="left",e.textBaseline="middle",e.lineWidth=1,e.beginPath(),e.moveTo(a+.5,0),e.lineTo(a+.5,Math.round(i.plotHeight*s)),e.stroke();for(const r of o){const n=Math.round(t.priceToY(r)*s);n<0||n>i.plotHeight*s||e.fillText(t.format(r),a+6*s,n)}e.restore()}(s,this.priceScale,t,i,r),null!==l&&function(e,t,i,s,r,n,o=ne,a={up:"#26a69a",down:"#ef5350",text:"#0d0e12"},l=!0,h=!0){if(!l&&!h)return;const c=Math.round(t.priceToY(i)*n);if(c<0||c>r.plotHeight*n)return;const d=s?a.up:a.down,u=Math.round(r.plotWidth*n);if(e.save(),l&&(e.strokeStyle=d,e.lineWidth=Math.max(1,Math.round(n)),e.setLineDash([3*n,3*n]),e.beginPath(),e.moveTo(0,c+.5),e.lineTo(u,c+.5),e.stroke(),e.setLineDash([])),h){const s=t.format(i);e.font=oe(o.font,n);const r=6*n,l=16*n,h=e.measureText(s).width;e.fillStyle=d,e.fillRect(u+1,c-l/2,h+2*r,l),e.fillStyle=a.text,e.textAlign="left",e.textBaseline="middle",e.fillText(s,u+1+r,c)}e.restore()}(s,this.priceScale,l.close,l.up,t,i,r,{up:e.theme.lastPriceUp,down:e.theme.lastPriceDown,text:e.theme.lastPriceText},l.showLine,l.showTag);for(const e of this._primitives)"normal"===e.zOrder()&&e.draw(s,n);e.showTimeAxis&&function(e,t,i,s,r,n=ne,o){const a=t.visibleRange(),l=Math.max(0,Math.floor(a.from)),h=Math.min(i.baseIndex,Math.ceil(a.to));if(h<l)return;const c=Math.max(1,Math.round(80/Math.max(1,t.barSpacing))),d=Math.round(s.plotHeight*r);let u=Number.POSITIVE_INFINITY;{let e=i.indexToTime(l);for(let t=l+1;t<=h;t++){const s=i.indexToTime(t);if(void 0!==s&&void 0!==e){const t=s-e;t>0&&t<u&&(u=t)}void 0!==s&&(e=s)}}const p=u*c,_=Number.isFinite(p)&&p<60;let f;e.save(),e.fillStyle=n.textColor,e.strokeStyle=n.lineColor,e.font=oe(n.font,r),e.textAlign="center",e.textBaseline="top",e.lineWidth=1,e.beginPath(),e.moveTo(0,d+.5),e.lineTo(Math.round(s.plotWidth*r),d+.5),e.stroke();for(let n=l;n<=h;n+=c){const a=i.indexToTime(n);if(void 0===a)continue;const l=Math.round(t.indexToX(n)*r);if(l<0||l>s.plotWidth*r){f=a;continue}let h;if(o){let e;if(void 0===f)e="day";else{const t=X(f),i=X(a);e=t.year!==i.year?"year":t.month!==i.month?"month":t.day!==i.day?"day":_?"timeWithSeconds":"time"}h=o(a,e)}else h=void 0===f||re(f,a)?ie(a):_?Z(a):Q(a);e.fillText(h,l,d+4*r),f=a}e.restore()}(s,e.timeScale,e.dataLayer,t,i,r,e.timeFormatter),s.restore()}paintTop(e,t){this.top.clearBitmap();const i=this._layout(t),s=this.top.ctx,r=t.dpr;s.save(),i.plotLeft>0&&s.translate(Math.round(i.plotLeft*r),0);const n=this._primitiveContext(t);for(const e of this._primitives)"top"===e.zOrder()&&e.draw(s,n);if(null!==e){const n="solid"===t.theme.crosshairStyle?[]:"dotted"===t.theme.crosshairStyle?[1*r,3*r]:[4*r,4*r];!function(e,t,i,s,r,n,o,a=1,l=[4*n,4*n]){if(e.save(),e.strokeStyle=o,e.lineWidth=Math.max(1,a),e.setLineDash(l),t>=0&&t<=s){const i=Math.round(t*n)+.5;e.beginPath(),e.moveTo(i,0),e.lineTo(i,Math.round(r*n)),e.stroke()}if(null!==i&&i>=0&&i<=r){const t=Math.round(i*n)+.5;e.beginPath(),e.moveTo(0,t),e.lineTo(Math.round(s*n),t),e.stroke()}e.setLineDash([]),e.restore()}(s,e.x,e.yLocal,i.plotWidth,i.plotHeight,r,t.theme.crosshair,t.theme.crosshairWidth??1,n);const o=t.theme.crosshairLabelBackground??t.theme.crosshair,a=!1!==t.theme.crosshairLabelVisible;if(a&&null!==e.yLocal){const n=this.priceScale.yToPrice(e.yLocal);ae(s,this.priceScale.format(n),i.plotWidth*r,e.yLocal*r,r,o,t.theme.lastPriceText,"right")}if(a&&e.showTimeTag&&e.x>=0&&e.x<=i.plotWidth){const n=Math.round(t.timeScale.xToIndex(e.x)),a=t.dataLayer.indexToTime(n);void 0!==a&&ae(s,t.timeFormatter?t.timeFormatter(a):function(e){const t=X(e);let i=`${se[t.weekday]} ${J(t.day)} ${te[t.month-1]} '${String(t.year).slice(-2)}`;return 0===t.hour&&0===t.minute&&0===t.second||(i+=` ${J(t.hour)}:${J(t.minute)}`,0!==t.second&&(i+=`:${J(t.second)}`)),i}(a),e.x*r,i.plotHeight*r,r,o,t.theme.lastPriceText,"bottom")}}s.restore()}yToPrice(e){return this.priceScale.yToPrice(e)}}const ce={background:"#0d0e12",grid:"#161a26",axisText:"#8b91a7",axisLine:"#2a3046",crosshair:"#6b7280",upColor:"#26a69a",downColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350",lineColor:"#4f8cff",areaTopColor:"rgba(79,140,255,0.40)",areaBottomColor:"rgba(79,140,255,0.00)",baselineTopLine:"#26a69a",baselineTopFill:"rgba(38,166,154,0.20)",baselineBottomLine:"#ef5350",baselineBottomFill:"rgba(239,83,80,0.20)",lastPriceUp:"#26a69a",lastPriceDown:"#ef5350",lastPriceText:"#0d0e12",buy:"#26a69a",sell:"#ef5350",profit:"#26a69a",loss:"#ef5350"},de={background:"#ffffff",grid:"#eef1f6",axisText:"#5b6472",axisLine:"#d4dae3",crosshair:"#9aa3b2",upColor:"#089981",downColor:"#e0473e",wickUpColor:"#089981",wickDownColor:"#e0473e",lineColor:"#2962ff",areaTopColor:"rgba(41,98,255,0.30)",areaBottomColor:"rgba(41,98,255,0.00)",baselineTopLine:"#089981",baselineTopFill:"rgba(8,153,129,0.18)",baselineBottomLine:"#e0473e",baselineBottomFill:"rgba(224,71,62,0.18)",lastPriceUp:"#089981",lastPriceDown:"#e0473e",lastPriceText:"#ffffff",buy:"#089981",sell:"#e0473e",profit:"#089981",loss:"#e0473e"},ue=de;const pe=[{label:"Solid",value:"solid"},{label:"Dashed",value:"dashed"},{label:"Dotted",value:"dotted"}];function _e(e){return{color:e.colorKey??`${e.key}:color`,width:`${e.key}:width`,lineStyle:`${e.key}:lineStyle`,opacity:`${e.key}:opacity`,type:`${e.key}:type`}}function fe(e){const t=[];for(const i of e.plots){const s=_e(i),r=e.inputs.find(e=>e.key===i.colorKey),n="string"==typeof r?.default?r.default:i.style?.color??"#4f8cff";t.push({key:s.color,type:"color",label:i.title,default:n,group:i.title}),t.push({key:s.opacity,type:"number",label:"Opacity",default:100,min:0,max:100,step:1,group:i.title}),t.push({key:s.width,type:"number",label:"Thickness",default:i.style?.lineWidth??1.5,min:.5,max:8,step:.5,group:i.title}),t.push({key:s.lineStyle,type:"select",label:"Line style",default:i.style?.lineStyle??"solid",options:pe,group:i.title}),t.push({key:s.type,type:"select",label:"Plot style",default:i.type,options:be,group:i.title})}return t}const be=[{label:"Line",value:"line"},{label:"Line with markers",value:"line-markers"},{label:"Step line",value:"step"},{label:"Area",value:"area"},{label:"Histogram",value:"histogram"},{label:"Columns",value:"column"}],me=[{label:"Close",value:"close"},{label:"Open",value:"open"},{label:"High",value:"high"},{label:"Low",value:"low"},{label:"HL2",value:"hl2"},{label:"HLC3",value:"hlc3"},{label:"OHLC4",value:"ohlc4"}],ge=new Map;function ve(e){ge.set(e.id,e)}function ye(e){const t=ge.get(e);if(void 0===t)throw new Error(`openalgo-charts: unknown indicator "${e}" — did you import 'openalgo-charts/indicators'?`);return t}function we(e){return ge.has(e)}function xe(){return Array.from(ge.values())}function Pe(e){const t={};for(const i of e.inputs)t[i.key]=i.default;return t}function Se(e,t){switch(t){case"open":return e.open;case"high":return e.high;case"low":return e.low;case"hl2":return(e.high+e.low)/2;case"hlc3":return(e.high+e.low+e.close)/3;case"ohlc4":return(e.open+e.high+e.low+e.close)/4;case"volume":return e.volume??0;default:return e.close}}function Oe(e,t){const i=new Array(e.length);for(let s=0;s<e.length;s++)i[s]=Se(e[s],t);return i}class Te{constructor(e){Object.defineProperty(this,"_points",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this._opts={opacity:.12,...e}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"bottom"}autoscaleInfo(){return null}setPoints(e){this._points=e.slice(),this._host?.requestUpdate()}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}setVisible(e){this._visible=e,this._host?.requestUpdate()}draw(e,t){if(!this._visible||this._points.length<2)return;const i=t.dpr,s=e=>t.timeScale.indexToX(e)*i,r=e=>t.priceScale.priceToY(e)*i;e.save(),e.globalAlpha=this._opts.opacity??.12;let n=null;const o=()=>{if(null!==n&&n.xs.length>=2){e.beginPath(),e.moveTo(n.xs[0],n.top[0]);for(let t=1;t<n.xs.length;t++)e.lineTo(n.xs[t],n.top[t]);for(let t=n.xs.length-1;t>=0;t--)e.lineTo(n.xs[t],n.bot[t]);e.closePath(),e.fillStyle=n.up?this._opts.colorUp:this._opts.colorDown,e.fill()}n=null};for(let e=0;e<this._points.length;e++){const t=this._points[e];if(null===t.a||null===t.b||!Number.isFinite(t.a)||!Number.isFinite(t.b)){o();continue}const i=t.a>=t.b,a=s(t.index),l=r(t.a),h=r(t.b);if(null!==n&&n.up!==i){const a=this._points[e-1];if(void 0!==a&&null!==a.a&&null!==a.b){const e=a.a-a.b,l=t.a-t.b,h=e===l?0:e/(e-l),c=s(a.index+(t.index-a.index)*h),d=r(a.a+(t.a-a.a)*h);n.xs.push(c),n.top.push(d),n.bot.push(d),o(),n={up:i,xs:[c],top:[d],bot:[d]}}else o()}null===n&&(n={up:i,xs:[],top:[],bot:[]}),n.xs.push(a),n.top.push(l),n.bot.push(h)}o(),e.restore()}}function Me(e){const t=e.trim();if(t.startsWith("#")){const e=t.slice(1);if(3===e.length||4===e.length){const[t,i,s,r]=[...e].map(e=>parseInt(e+e,16));return[t,i,s].some(Number.isNaN)?null:{r:t,g:i,b:s,a:4===e.length?r/255:1}}if(6===e.length||8===e.length){const t=parseInt(e.slice(0,6),16);if(Number.isNaN(t))return null;const i=8===e.length?parseInt(e.slice(6,8),16)/255:1;return{r:t>>16&255,g:t>>8&255,b:255&t,a:Number.isNaN(i)?1:i}}return null}const i=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(t);return null===i?null:{r:Number(i[1]),g:Number(i[2]),b:Number(i[3]),a:void 0===i[4]?1:Number(i[4])}}function Ce(e){return function(e){const t=Me(e);if(null===t)return.5;const i=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};return.2126*i(t.r)+.7152*i(t.g)+.0722*i(t.b)}(e)>.45?"#10131a":"#ffffff"}function Ie(e,t){const i=Me(e);return null===i?e:`rgba(${i.r},${i.g},${i.b},${t})`}function je(e,t){const i=Me(e);if(null===i)return e;const s=t>=0?255:0,r=Math.min(1,Math.abs(t)),n=e=>Math.round(e+(s-e)*r);return`rgba(${n(i.r)},${n(i.g)},${n(i.b)},${i.a})`}function Le(e,t,i,s,r,n){const o=e.roundRect;"function"==typeof o?o.call(e,t,i,s,r,Math.max(0,Math.min(n,s/2,r/2))):e.rect(t,i,s,r)}function ke(e){const t={};for(const i of fe(e))t[i.key]=i.default;return t}function Ae(e){const t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(2)}B`:t>=1e6?`${(e/1e6).toFixed(2)}M`:t>=1e3?e.toFixed(0):t>=1?e.toFixed(2):e.toPrecision(3)}let Fe=1;class Re{constructor(e,t,i={},s){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"indicatorId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"paneIndex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_d",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ownPane",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_settings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_plotTypes",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_fills",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_levels",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_values",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_barCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_removed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_detach",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_legend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this._host=e,this._d=t,this.indicatorId=t.id,this.name=t.name,this.id=`${t.id}-${Fe++}`,this._settings={...Pe(t),...ke(t),...i},void 0!==s?(this.paneIndex=s,this._ownPane=!1):"onchart"===t.placement?(this.paneIndex=0,this._ownPane=!1):(this.paneIndex=e.nextPaneIndex(),this._ownPane=!0);for(const i of t.plots){const t=this._plotType(i);this._plotTypes.set(i.key,t),this._series.set(i.key,e.addIndicatorSeries(t,this.paneIndex,this._plotStyle(i),i.priceScaleId))}for(const i of t.fills??[]){const t=new Te({colorUp:this._fillColor(i,!0),colorDown:this._fillColor(i,!1),opacity:i.opacity??.12});this._fills.push(t),e.addIndicatorFill(t,this.paneIndex)}this._legend=e.addIndicatorLegend({id:`indicator:${this.id}`,title:t.name,params:this._paramSummary(),color:this._legendColor(),row:e.legendRowsOn(this.paneIndex),paneIndex:this.paneIndex}),this._applyLevels(),this._applyRange(),this.recompute(),this._attach()}_paramSummary(){const e=[];for(const t of this._d.inputs){if("color"===t.type)continue;const i=this._settings[t.key];null!=i&&""!==i&&e.push(String(i))}return e.join(" ")}_legendColor(){for(const e of this._d.plots){const t=e.colorKey;if(void 0!==t&&"string"==typeof this._settings[t])return this._settings[t];if("string"==typeof e.style?.color)return e.style.color}}visible(){return this._visible}setVisible(e){if(e!==this._visible){this._visible=e;for(const t of this._series.values())t.applyOptions({visible:e});for(const t of this._fills)t.setVisible(e);this._legend?.setOptions({hidden:!e})}}shiftPane(e){this.paneIndex+=e}legend(){return this._legend}updateLegendValues(e){if(null===this._legend)return;const t=this._barCount,i=void 0===e||e<0||e>=t?t-1:e;if(i<0)return void this._legend.setValues([]);const s=[];for(const e of this._d.plots){const t=this._values[e.key]?.[i];null!=t&&Number.isFinite(t)&&s.push({text:Ae(t),color:this._plotColor(e)})}this._legend.setValues(s)}_fillColor(e,t){const i=t?e.colorUpKey:e.colorDownKey,s=void 0!==i?this._settings[i]:void 0;if("string"==typeof s)return s;return(t?e.colorUp:e.colorDown)??(t?"#26a69a":"#ef5350")}_syncFills(){const e=this._d.fills??[];for(let t=0;t<e.length;t++){const i=this._fills[t];if(void 0===i)continue;const s=e[t],r=this._values[s.between[0]],n=this._values[s.between[1]];if(i.setOptions({colorUp:this._fillColor(s,!0),colorDown:this._fillColor(s,!1),opacity:s.opacity??.12}),void 0===r||void 0===n){i.setPoints([]);continue}const o=[];for(let e=0;e<this._barCount;e++)o.push({index:e,a:r[e]??null,b:n[e]??null});i.setPoints(o)}}_plotType(e){const t=this._settings[_e(e).type];return"string"==typeof t&&""!==t?t:e.type}_plotColor(e){const t=this._settings[_e(e).color];return"string"==typeof t?t:"string"==typeof e.style?.color?e.style.color:void 0}_plotStyle(e){const t=_e(e),i={...e.style??{},title:e.title},s=this._plotColor(e),r=(n=this._settings[t.opacity],o=100,"number"==typeof n&&Number.isFinite(n)?n:o);var n,o;void 0!==s&&(i.color=r>=100?s:Ie(s,r/100));const a=this._settings[t.width];"number"==typeof a&&a>0&&(i.lineWidth=a);const l=this._settings[t.lineStyle];return"string"==typeof l&&(i.lineStyle=l),i}_attach(){const e=this._d.attach?.({settings:()=>this._settings,bars:()=>this._host.sourceBars(),requestRecompute:()=>{this._removed||(this._barCount=0,this.recompute())},store:this._store});this._detach="function"==typeof e?e:null}settings(){return{...this._settings}}series(e){return this._series.get(e)}values(){return this._values}setSettings(e){if(!this._removed){this._settings={...this._settings,...e};for(const e of this._d.plots){const t=this._plotType(e);t===this._plotTypes.get(e.key)?this._series.get(e.key)?.applyOptions(this._plotStyle(e)):(this._series.get(e.key)?.remove(),this._series.set(e.key,this._host.addIndicatorSeries(t,this.paneIndex,this._plotStyle(e),e.priceScaleId)),this._plotTypes.set(e.key,t))}this._legend?.setOptions({params:this._paramSummary(),color:this._legendColor()}),this._applyLevels(),this._applyRange(),this._values={},this._barCount=0,this.recompute(),this._detach?.(),this._attach()}}recompute(){if(this._removed)return;const e=this._host.sourceBars(),t=e.length;let i=null;if(t>0&&this._barCount>0&&(t===this._barCount||t===this._barCount+1)&&void 0!==this._d.calcTail){const s=this._barCount-1,r=this._d.calcTail(e,this._settings,s,this._values,this._store);null!==r&&(i=function(e,t,i,s){const r={};for(const n of Object.keys(t)){const o=e[n],a=t[n];if(void 0===o||void 0===a)return null;if(a.length!==s-i)return null;const l=new Array(s);for(let e=0;e<i;e++)l[e]=o[e]??null;for(let e=i;e<s;e++)l[e]=a[e-i]??null;r[n]=l}return r}(this._values,r,s,t))}null===i&&(i=this._d.calc(e,this._settings,this._store)),this._values=i,this._barCount=t;for(const s of this._d.plots){const r=this._series.get(s.key);if(void 0===r)continue;const n=i[s.key];if(void 0===n){r.setData([]);continue}const o=new Array(t);for(let i=0;i<t;i++){const t=n[i];o[i]={time:e[i].time,value:null==t?NaN:t}}r.setData(o)}this._syncFills(),this.updateLegendValues()}_applyLevels(){for(const e of this._levels)this._host.removeIndicatorLevel(e);this._levels=[];const e=this._d.levels?.(this._settings)??[];let t=0;for(const i of e)this._levels.push(this._host.addIndicatorLevel(i.price,i.color??"#8892a6",i.dashed??!0,i.title??"",`${this.id}:level:${t++}`,this.paneIndex))}_applyRange(){this._ownPane&&this._host.setPaneRange(this.paneIndex,this._d.range?.(this._settings)??null)}remove(){if(!this._removed){this._removed=!0,this._detach?.(),this._detach=null,null!==this._legend&&(this._host.removeIndicatorLegend(this._legend),this._legend=null);for(const e of this._levels)this._host.removeIndicatorLevel(e);this._levels=[];for(const e of this._series.values())e.remove();this._series.clear();for(const e of this._fills)this._host.removeIndicatorFill(e);this._fills.length=0,this._ownPane&&this._host.setPaneRange(this.paneIndex,null)}}}const Be=1;function Ne(e){return!("open"in e)&&!("value"in e)}function We(e){if("open"in e)return e;if("value"in e){const t=e.value;return{time:e.time,open:t,high:t,low:t,close:t}}return{time:e.time,open:NaN,high:NaN,low:NaN,close:NaN}}const De={friction:.0055,minSpeed:.02,triggerSpeed:.08};class ze{constructor(e,t={}){Object.defineProperty(this,"_v0",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_k",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_minSpeed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_duration",{enumerable:!0,configurable:!0,writable:!0,value:void 0});const i={...De,...t};this._v0=e,this._k=i.friction,this._minSpeed=i.minSpeed;const s=Math.abs(this._v0)>0?this._minSpeed/Math.abs(this._v0):1;this._duration=s>=1?0:-Math.log(s)/this._k}static shouldAnimate(e,t={}){const i=t.triggerSpeed??De.triggerSpeed;return Math.abs(e)>=i}distanceAt(e){const t=Math.min(Math.max(0,e),this._duration);return this._v0/this._k*(1-Math.exp(-this._k*t))}get durationMs(){return this._duration}finished(e){return e>=this._duration}}const $e=["Mod","Ctrl","Meta","Alt","Shift"],He=new Set($e),qe=new Set(["Shift","Control","Alt","Meta","OS","ShiftLeft","ShiftRight","ControlLeft","ControlRight","AltLeft","AltRight","MetaLeft","MetaRight","OSLeft","OSRight"]);function Ee(){return"undefined"!=typeof navigator&&/mac|iphone|ipad/i.test(navigator.platform||navigator.userAgent||"")}function Ue(e){const t=e.split("+").map(e=>e.trim()).filter(e=>e.length>0);if(0===t.length)return null;const i=t[t.length-1];if(!/^[A-Za-z0-9]+$/.test(i)||He.has(i))return null;const s=[];for(const e of t.slice(0,-1)){if(!He.has(e))return null;s.includes(e)||s.push(e)}return s.sort((e,t)=>$e.indexOf(e)-$e.indexOf(t)),{mods:s,key:i}}function Ve(e){const t=Ue(e);return null===t?"":[...t.mods,t.key].join("+")}function Ye(e){return""!==Ve(e)}const Ge={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",Equal:"=",Minus:"-",NumpadAdd:"+",NumpadSubtract:"-",Escape:"Esc",Space:"Space"};function Ke(e,t=Ee()){const i=Ue(e);if(null===i)return"";const s=t?{Mod:"⌘",Ctrl:"⌃",Meta:"⌘",Alt:"⌥",Shift:"⇧"}:{Mod:"Ctrl",Ctrl:"Ctrl",Meta:"Win",Alt:"Alt",Shift:"Shift"};var r;return[...i.mods.map(e=>s[e]),(r=i.key,void 0!==Ge[r]?Ge[r]:/^Key[A-Z]$/.test(r)?r.slice(3):/^Digit[0-9]$/.test(r)?r.slice(5):r)].join(t?" ":" + ")}function Xe(e,t=Ee()){const i=e.code??e.key??"";if(""===i||qe.has(i))return"";const s=[];return(t?e.metaKey:e.ctrlKey)&&s.push("Mod"),t&&e.ctrlKey&&s.push("Ctrl"),!t&&e.metaKey&&s.push("Meta"),e.altKey&&s.push("Alt"),e.shiftKey&&s.push("Shift"),Ve([...s,i].join("+"))}const Je=new Set(["Mod+KeyW","Mod+KeyT","Mod+KeyN","Mod+KeyQ","Mod+KeyR","Mod+KeyL","Mod+Shift+KeyT","Mod+Shift+KeyN","Mod+Shift+KeyW"]);function Qe(e){return Je.has(Ve(e))}const Ze=[{command:"panLeft",label:"Pan left",combos:["ArrowLeft"]},{command:"panRight",label:"Pan right",combos:["ArrowRight"]},{command:"panLeftFast",label:"Pan left (fast)",combos:["Mod+ArrowLeft"]},{command:"panRightFast",label:"Pan right (fast)",combos:["Mod+ArrowRight"]},{command:"panUp",label:"Pan up",combos:["ArrowUp"]},{command:"panDown",label:"Pan down",combos:["ArrowDown"]},{command:"zoomIn",label:"Zoom in",combos:["Equal","Shift+Equal","NumpadAdd"]},{command:"zoomOut",label:"Zoom out",combos:["Minus","NumpadSubtract"]},{command:"resetScale",label:"Reset scale",combos:["Home","Digit0"]},{command:"fitContent",label:"Fit content",combos:["Alt+KeyF"]},{command:"screenshot",label:"Screenshot (PNG)",combos:["Alt+Shift+KeyS"]},{command:"toggleGridVert",label:"Toggle vertical grid",combos:["Alt+KeyV"]},{command:"toggleGridHorz",label:"Toggle horizontal grid",combos:["Alt+KeyH"]},{command:"toggleCrosshairMagnet",label:"Toggle crosshair magnet",combos:["Alt+KeyM"]}],et={panLeftFast:["Alt+ArrowLeft"],panRightFast:["Alt+ArrowRight"],screenshot:["Mod+Shift+KeyS"]},tt=new Set(Ze.map(e=>e.command)),it=e=>Array.isArray(e)?e:[e];class st{constructor(e={}){Object.defineProperty(this,"scope",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_isMac",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_persist",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_preset",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_overrides",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_custom",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_entries",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_reverse",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),this.scope=e.scope??"hover",this._isMac=e.isMac??Ee(),this._persist=e.persist??!1,this._storageKey=e.storageKey??"openalgo-charts:shortcuts",this._preset=e.preset??"default";const t=e=>{for(const[t,i]of Object.entries(e??{})){if(null===i){this._disabled.add(t);continue}const e=it(i).map(Ve).filter(e=>""!==e&&!Qe(e));this._overrides[t]=e}};t(e.overrides);for(const t of e.disabledCommands??[])this._disabled.add(t);for(const t of e.customShortcuts??[])this._custom.set(t.command,t);const i=this._load();if(null!==i){void 0!==i.preset&&(this._preset=i.preset),t(i.overrides);for(const e of i.disabled??[])this._disabled.add(e)}this._rebuild()}_presetCombos(e){return"alt"===this._preset?et[e]:void 0}_effectiveCombos(e,t){return this._disabled.has(e)?[]:void 0!==this._overrides[e]?this._overrides[e]:this._presetCombos(e)??t}_rebuild(){this._entries=new Map;for(const e of Ze)this._entries.set(e.command,{command:e.command,label:e.label,combos:this._effectiveCombos(e.command,e.combos)});for(const e of this._custom.values())this._entries.set(e.command,{command:e.command,label:e.label??e.command,combos:this._effectiveCombos(e.command,it(e.combos).map(Ve).filter(e=>""!==e))});this._reverse=new Map;for(const e of this._entries.values())for(const t of e.combos)this._reverse.has(t)||this._reverse.set(t,e.command)}resolve(e){const t=Xe(e,this._isMac);return""===t?null:this._reverse.get(t)??null}handleKey(e){return this._reverse.get(Ve(e))??null}runCustom(e){const t=this._custom.get(e);return void 0!==t&&(t.onTrigger(),this.emitTrigger(e),!0)}emitTrigger(e,t=""){const i={command:e,combo:t,isCustom:this._custom.has(e)};for(const e of this._listeners)e(i)}on(e){return this._listeners.add(e),()=>this._listeners.delete(e)}setBinding(e,t){const i=it(t).map(Ve).filter(e=>""!==e&&!Qe(e));return 0!==i.length&&(this._overrides[e]=i,this._disabled.delete(e),this._after(),!0)}disable(e){this._disabled.add(e),delete this._overrides[e],this._after()}resetBinding(e){delete this._overrides[e],this._disabled.delete(e),this._after()}resetAll(){this._overrides={},this._disabled.clear(),this._after()}setPreset(e){this._preset=e,this._after()}addCustom(e){this._custom.set(e.command,e),this._after()}list(){return[...this._entries.values()].map(e=>({command:e.command,label:e.label,combos:e.combos,isCustom:this._custom.has(e.command),isDisabled:this._disabled.has(e.command)}))}state(){return{preset:this._preset,overrides:this._overrides,disabled:[...this._disabled]}}_after(){this._rebuild(),this._save()}_save(){if(this._persist&&"undefined"!=typeof localStorage)try{localStorage.setItem(this._storageKey,JSON.stringify(this.state()))}catch{}}_load(){if(!this._persist||"undefined"==typeof localStorage)return null;try{const e=localStorage.getItem(this._storageKey);return null===e?null:JSON.parse(e)}catch{return null}}static shouldIgnore(e){const t=e;if(null==t)return!1;if(!0===t.isContentEditable)return!0;const i=(t.tagName??"").toUpperCase();return"INPUT"===i||"TEXTAREA"===i||"SELECT"===i}}class rt{constructor(e){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ghostPrice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_group",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._opts=e}attached(e){this._host=e}detached(){this._host=null}get price(){return this._opts.price}setPrice(e){this._opts.price=e,this._host?.requestUpdate()}setLeftLabel(e){this._opts.leftLabel=e,this._host?.requestUpdate()}setDragGhost(e){this._ghostPrice=e,this._host?.requestUpdate()}options(){return this._opts}zOrder(){return"normal"}autoscaleInfo(){return{min:this._opts.price,max:this._opts.price}}draw(e,t){this._group=null;const i=Math.round(t.priceScale.priceToY(this._opts.price)*t.dpr)+.5;if(i<0||i>t.plotHeight*t.dpr)return;const s=t.dpr,r=Math.round(t.plotWidth*s),n=Math.max(0,Math.min(1,this._opts.extentFromRight??1)),o=Math.round(t.plotWidth*(1-n)*s),a=this._opts.color,l=void 0!==this._opts.cursor||!0===this._opts.closeButton,h=t.dragId===this._opts.id,c=l&&!h&&(t.hoverId===this._opts.id||t.hoverId===`${this._opts.id}::close`),d=t.hoverId===`${this._opts.id}::close`;if(e.save(),null!==this._ghostPrice&&h){const i=Math.round(t.priceScale.priceToY(this._ghostPrice)*s)+.5;i>=0&&i<=t.plotHeight*s&&(e.strokeStyle=Ie(a,.35),e.lineWidth=Math.max(1,Math.round(s)),e.setLineDash([2*s,3*s]),e.beginPath(),e.moveTo(o,i),e.lineTo(r,i),e.stroke(),e.setLineDash([]))}h&&(e.strokeStyle=Ie(a,.18),e.lineWidth=Math.max(5*s,Math.round(this._opts.lineWidth*s)+4*s),e.beginPath(),e.moveTo(o,i),e.lineTo(r,i),e.stroke()),e.strokeStyle=c||h?je(a,.1):a;const u=Math.max(1,Math.round(this._opts.lineWidth*s));e.lineWidth=c||h?u+Math.round(s):u,this._opts.dashed&&e.setLineDash([4*s,4*s]),e.beginPath(),e.moveTo(o,i),e.lineTo(r,i),e.stroke(),e.setLineDash([]),e.font=`500 ${11*s}px system-ui, sans-serif`,e.textBaseline="middle",e.textAlign="left";const p=18*s,_=6*s,f=3*s,b=h||c?je(a,.12):a,m=this._opts.label??t.priceScale.format(this._opts.price);e.fillStyle=b,e.fillRect(r+1,i-p/2,e.measureText(m).width+2*_,p),e.fillStyle=Ce(a),e.fillText(m,r+1+_,i);if(void 0!==this._opts.badge||void 0!==this._opts.qty||void 0!==this._opts.leftLabel&&""!==this._opts.leftLabel||!0===this._opts.closeButton){const r="transparent"===t.theme.background,l=r?Ie(a,.14):t.theme.background,u=r?t.theme.axisText:Ce(t.theme.background),b=Ie(t.theme.axisText,c||h?.75:.5),m=[];void 0!==this._opts.badge&&m.push({text:this._opts.badge,fill:h?je(a,.2):c?je(a,.12):a,textColor:Ce(a),border:je(a,-.25)}),void 0!==this._opts.qty&&m.push({text:String(this._opts.qty),fill:l,textColor:u,border:b}),void 0!==this._opts.leftLabel&&""!==this._opts.leftLabel&&m.push({text:this._opts.leftLabel,fill:l,textColor:u,border:b}),!0===this._opts.closeButton&&m.push({close:!0,fill:d?a:l,textColor:d?Ce(a):u,border:d?a:b}),this._group=function(e,t,i,s,r){const{height:n,padX:o,radius:a,gap:l,dpr:h}=r,c=s.map(t=>!0===t.close?20*h:e.measureText(t.text??"").width+2*o),d=c.reduce((e,t)=>e+t,0)+l*Math.max(0,s.length-1);void 0!==r.backplate&&(e.beginPath(),Le(e,t,i-n/2,d,n,a),e.fillStyle=r.backplate,e.fill());let u=Number.POSITIVE_INFINITY,p=t;for(let t=0;t<s.length;t++){const r=s[t],d=c[t];if(e.beginPath(),Le(e,p,i-n/2,d,n,a),e.fillStyle=r.fill,e.fill(),void 0!==r.border&&(e.strokeStyle=r.border,e.lineWidth=Math.max(1,Math.round(h)),e.stroke()),!0===r.close){u=p,e.strokeStyle=r.textColor,e.lineWidth=Math.max(1,Math.round(1.4*h));const t=p+d/2,s=3.5*h;e.beginPath(),e.moveTo(t-s,i-s),e.lineTo(t+s,i+s),e.moveTo(t+s,i-s),e.lineTo(t-s,i+s),e.stroke()}else e.fillStyle=r.textColor,e.textAlign="left",e.textBaseline="middle",e.fillText(r.text??"",p+o,i);p+=d+l}return{x0:t/h,x1:(p-l)/h,closeX0:u/h}}(e,o+(1===n?6*s:0),i,m,{height:p,padX:_,radius:f,gap:2*s,backplate:r?void 0:t.theme.background,dpr:s})}e.restore()}hitTest(e,t,i){if(e<0||e>i.plotWidth)return null;const s=i.priceScale.priceToY(this._opts.price),r=Math.abs(t-s),n=this._group;return null!==n&&r<=10&&e>=n.x0&&e<=n.x1?this._opts.closeButton&&e>=n.closeX0?{externalId:`${this._opts.id}::close`,zOrder:"normal",distance:r,cursor:"pointer"}:{externalId:this._opts.id,zOrder:"normal",distance:r,cursor:this._opts.cursor}:r>4?null:{externalId:this._opts.id,zOrder:"normal",distance:r,cursor:this._opts.cursor}}}const nt={long:"#2f6df6",short:"#ef5350",order:"#3b82f6",tp:"#26a69a",sl:"#ef5350",buy:"#26a69a",sell:"#ef5350"},ot="::close";function at(e,t){const i=e.length;if(0===i)return;let s=0,r=i-1;for(;s<r;){const i=s+r+1>>1,n=e.indexToTime(i);void 0!==n&&n<=t?s=i:r=i-1}const n=e.indexToTime(s);if(void 0!==n){if(s+1<i){const i=e.indexToTime(s+1);if(void 0!==i&&Math.abs(i-t)<Math.abs(n-t))return s+1}return s}}function lt(e,t,i,s,r,n){const o=5*n;e.fillStyle=r,e.beginPath(),"buy"===s?(e.moveTo(t,i-1.5*o),e.lineTo(t-o,i),e.lineTo(t+o,i)):(e.moveTo(t,i+1.5*o),e.lineTo(t-o,i),e.lineTo(t+o,i)),e.closePath(),e.fill()}function ht(e,t,i,s,r,n){const o=9*n;e.fillStyle=s,e.beginPath(),e.arc(t,i,o,0,2*Math.PI),e.fill(),""!==r&&(e.fillStyle=Ce(s),e.font=`500 ${9*n}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,t,i+.5*n))}function ct(e,t,i,s,r,n){const o=String(s);e.font=`500 ${9*n}px system-ui, sans-serif`;const a=e.measureText(o).width+10*n,l=15*n;e.fillStyle=r,e.beginPath(),Le(e,Math.round(t-a/2),Math.round(i-l/2),Math.round(a),Math.round(l),3*n),e.fill(),e.fillStyle=Ce(r),e.textAlign="center",e.textBaseline="middle",e.fillText(o,t,i+.5*n)}class dt{constructor(e){Object.defineProperty(this,"_trades",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_colors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._colors=e}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setTrades(e){this._trades=e,this._host?.requestUpdate()}setColors(e){this._colors=e,this._host?.requestUpdate()}draw(e,t){if(0===this._trades.length)return;const i=t.dpr,s=new Map;e.save();for(const r of this._trades){const n=at(t.dataLayer,Math.floor(r.timestamp/1e3));if(void 0===n)continue;const o=Math.round(t.timeScale.indexToX(n)*i),a=r.color??("buy"===r.side?this._colors.buy:this._colors.sell),l=r.variant??"chevron";if("count"===l){const e=`${n}:${r.side}`;let t=s.get(e);void 0===t&&(t={index:n,sumPS:0,sumS:0,n:0,color:a},s.set(e,t)),t.sumPS+=r.price*r.size,t.sumS+=r.size,t.n+=1;continue}const h=Math.round(t.priceScale.priceToY(r.price)*i);"bubble"===l?ht(e,o,h,a,r.label??("buy"===r.side?"B":"S"),i):lt(e,o,h,r.side,a,i)}for(const r of s.values()){const s=r.sumS>0?r.sumPS/r.sumS:0;ct(e,Math.round(t.timeScale.indexToX(r.index)*i),Math.round(t.priceScale.priceToY(s)*i),r.n,r.color,i)}e.restore()}}class ut{constructor(e){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_positions",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_orders",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_trades",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_dragPrev",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_colors",{enumerable:!0,configurable:!0,writable:!0,value:{...nt}}),Object.defineProperty(this,"_markers",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._host=e,e.subscribeClick(e=>this._onClick(e)),e.subscribeDrag((e,t)=>this._onDrag(e,t),(e,t)=>this._onDragEnd(e,t))}on(e,t){let i=this._listeners.get(e);return void 0===i&&(i=new Set,this._listeners.set(e,i)),i.add(t),()=>{this._listeners.get(e)?.delete(t)}}off(e,t){this._listeners.get(e)?.delete(t)}_emit(e,t){const i=this._listeners.get(e);if(void 0!==i)for(const e of i)e(t);this._host.emit?.(e,t)}setSettings(e){void 0!==e.longColor&&(this._colors.long=e.longColor),void 0!==e.shortColor&&(this._colors.short=e.shortColor),void 0!==e.orderColor&&(this._colors.order=e.orderColor),void 0!==e.tpColor&&(this._colors.tp=e.tpColor),void 0!==e.slColor&&(this._colors.sl=e.slColor),void 0!==e.buyColor&&(this._colors.buy=e.buyColor),void 0!==e.sellColor&&(this._colors.sell=e.sellColor),this.setPositions(this.getPositions()),this.setOrders(this.getOrders()),this._markers?.setColors(this._colors)}getSettings(){return{...this._colors}}setPositions(e){this._sync(this._positions,e,"pos")}setOrders(e){this._sync(this._orders,e,"ord")}setTrades(e){this._trades.clear();for(const t of e)this._trades.set(t.id,t);this._renderTrades()}addTrade(e){this._trades.set(e.id,e),this._renderTrades()}upsertOrder(e){const t=this.getOrders().filter(t=>t.id!==e.id);t.push(e),this.setOrders(t)}removeOrder(e){const t=this.getOrders().filter(t=>t.id!==e&&t.parentId!==e);this.setOrders(t)}syncState(e){void 0!==e.positions&&this.setPositions(e.positions),void 0!==e.orders&&this.setOrders(e.orders),void 0!==e.trades&&this.setTrades(e.trades)}updatePositionPnl(e,t,i,s){const r=this._positions.get(e);void 0!==r&&(void 0!==i&&(r.entity.pnlText=i),void 0!==s&&(r.entity.pnlPercent=s),r.line.setLeftLabel(this._positionPill(r.entity)))}getPositions(){return[...this._positions.values()].map(e=>e.entity)}getOrders(){return[...this._orders.values()].map(e=>e.entity)}getTrades(){return[...this._trades.values()]}clear(){for(const e of this._positions.values())this._host.removePrimitive(e.line);for(const e of this._orders.values())this._host.removePrimitive(e.line);this._positions.clear(),this._orders.clear(),this._trades.clear(),null!==this._markers&&(this._host.removePrimitive(this._markers),this._markers=null)}_renderTrades(){null===this._markers&&(this._markers=new dt(this._colors),this._host.addPrimitive(this._markers)),this._markers.setTrades(this.getTrades())}_sync(e,t,i){const s=new Set;for(const r of t){s.add(r.id);const t="pos"===i?this._positionOpts(r):this._orderOpts(r),n=this._sig(t),o=e.get(r.id);if(void 0!==o&&o.sig===n)o.entity=r,o.line.setPrice(t.price),void 0!==t.leftLabel&&o.line.setLeftLabel(t.leftLabel);else{void 0!==o&&this._host.removePrimitive(o.line);const i=new rt(t);this._host.addPrimitive(i),e.set(r.id,{entity:r,line:i,sig:n})}}for(const[t,i]of e)s.has(t)||(this._host.removePrimitive(i.line),e.delete(t))}_sig(e){return`${e.color}|${e.dashed}|${!0===e.closeButton}|${e.cursor??""}|${void 0!==e.leftLabel}|${e.badge??""}|${e.qty??""}`}_positionPill(e){return void 0===e.pnlText?"":`${e.pnlText}${void 0!==e.pnlPercent?` (${e.pnlPercent})`:""}`}_positionOpts(e){const t="line-only"===e.variant;return{price:e.entryPrice,color:e.color??("long"===e.side?this._colors.long:this._colors.short),lineWidth:2,dashed:!1,id:`pos:${e.id}`,badge:t?void 0:e.side.toUpperCase(),qty:t?void 0:e.size,leftLabel:t?void 0:this._positionPill(e),closeButton:!t&&!0!==e.readOnly,extentFromRight:.3}}_orderOpts(e){const t="line-only"===e.variant,i=!t&&(e.draggable??!0!==e.readOnly),s=e.color??("tp"===e.bracketRole?this._colors.tp:"sl"===e.bracketRole?this._colors.sl:this._colors.order);return{price:e.price,color:s,lineWidth:e.lineWidth??1,dashed:"solid"!==(e.lineStyle??"solid"),id:`ord:${e.id}`,badge:t?void 0:(e.bracketRole??e.side).toUpperCase(),qty:t?void 0:e.size,leftLabel:t||void 0!==e.bracketRole?void 0:e.type.replace("_"," ").toUpperCase(),closeButton:!t&&!0!==e.readOnly,extentFromRight:.3,cursor:i?"ns-resize":void 0}}_onClick(e){if(e.endsWith(ot)){const t=e.slice(0,-7);if(t.startsWith("ord:")){const e=t.slice(4);this._orders.has(e)&&this._emit("trading:order_cancel",{orderId:e})}else if(t.startsWith("pos:")){const e=t.slice(4);this._positions.has(e)&&this._emit("trading:position_close",{positionId:e})}return}if(e.startsWith("ord:")){const t=this._orders.get(e.slice(4));void 0!==t&&this._emit("trading:order_click",{order:t.entity})}else if(e.startsWith("pos:")){const t=this._positions.get(e.slice(4));void 0!==t&&this._emit("trading:position_click",{position:t.entity})}}_onDrag(e,t){if(!e.startsWith("ord:"))return;const i=this._orders.get(e.slice(4));if(void 0===i)return;const s=e.slice(4);this._dragPrev.has(s)||(this._dragPrev.set(s,i.entity.price),i.line.setDragGhost(i.entity.price)),i.line.setPrice(t)}_onDragEnd(e,t){if(!e.startsWith("ord:"))return;const i=e.slice(4),s=this._orders.get(i);if(void 0===s)return;const r=this._dragPrev.get(i)??s.entity.price;this._dragPrev.delete(i),s.line.setDragGhost(null),s.entity.price=t,s.line.setPrice(t),void 0!==s.entity.bracketRole?this._emit("trading:bracket_modify",{parentId:s.entity.parentId,bracketRole:s.entity.bracketRole,newPrice:t}):this._emit("trading:order_modify",{orderId:i,newPrice:t,previousPrice:r})}}function pt(e,t){return{dist:Math.hypot(e.x-t.x,e.y-t.y),cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}const _t={tiny:6,small:9,medium:12,big:16};function ft(e){return _t[e]}function bt(e,t){return Math.max(4,Math.min(_t[e],Math.floor(t)))}function mt(e,t,i,s,r,n){const o=r/2;switch(e.fillStyle=n,e.strokeStyle=n,e.beginPath(),t){case"arrowUp":case"triangleUp":e.moveTo(i,s-o),e.lineTo(i+o,s+o),e.lineTo(i-o,s+o),e.closePath(),e.fill();break;case"arrowDown":case"triangleDown":e.moveTo(i,s+o),e.lineTo(i+o,s-o),e.lineTo(i-o,s-o),e.closePath(),e.fill();break;case"circle":e.arc(i,s,o,0,2*Math.PI),e.fill();break;case"square":e.fillRect(i-o,s-o,r,r);break;case"diamond":e.moveTo(i,s-o),e.lineTo(i+o,s),e.lineTo(i,s+o),e.lineTo(i-o,s),e.closePath(),e.fill();break;case"flag":e.fillRect(i-1,s-o,Math.max(1,r/8),r),e.fillRect(i,s-o,o,.8*o)}}class gt{constructor(e){Object.defineProperty(this,"_seriesId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_markers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_lastPositions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._seriesId=e}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"normal"}setMarkers(e){this._markers=e.slice().sort((e,t)=>e.time-t.time),this._host?.requestUpdate()}draw(e,t){if(this._lastPositions=[],0===this._markers.length)return;const i=new Map;for(const e of t.dataLayer.indexedBars(this._seriesId))i.set(e.bar.time,e.bar);const s=t.timeScale.visibleRange(),r=new Map;e.save();for(const n of this._markers){const o=t.dataLayer.timeToIndex(n.time);if(void 0===o||o<s.from-1||o>s.to+1)continue;const a=i.get(n.time),l=bt(n.size,t.timeScale.barSpacing)*t.dpr,h=t.timeScale.indexToX(o)*t.dpr,c=r.get(n.time)??0,d=(l+4*t.dpr)*c;let u;if("atPrice"===n.position&&void 0!==n.price)u=t.priceScale.priceToY(n.price)*t.dpr;else if(void 0!==a&&"aboveBar"===n.position)u=t.priceScale.priceToY(a.high)*t.dpr-l-d;else if(void 0!==a&&"belowBar"===n.position)u=t.priceScale.priceToY(a.low)*t.dpr+l+d;else{if(void 0===a)continue;u=t.priceScale.priceToY((a.open+a.close)/2)*t.dpr}if(r.set(n.time,c+1),mt(e,n.shape,h,u,l,n.color),void 0!==n.text){e.fillStyle=n.color,e.font=Math.max(9,ft(n.size))*t.dpr+"px system-ui, sans-serif",e.textAlign="center",e.textBaseline="belowBar"===n.position?"top":"bottom";const i="belowBar"===n.position?u+l:u-l;e.fillText(n.text,h,i)}void 0!==n.id&&this._lastPositions.push({id:n.id,x:h/t.dpr,y:u/t.dpr})}e.restore()}hitTest(e,t){let i=null;for(const s of this._lastPositions){const r=Math.hypot(s.x-e,s.y-t);r<=8&&(null===i||r<i.distance)&&(i={externalId:s.id,zOrder:"normal",distance:r,cursor:"pointer"})}return i}}const vt={earnings:"#f0a020",dividend:"#26a69a",split:"#4f8cff",news:"#9aa0b4"};class yt{constructor(){Object.defineProperty(this,"_events",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_positions",{enumerable:!0,configurable:!0,writable:!0,value:[]})}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"normal"}setEvents(e){this._events=e.slice().sort((e,t)=>e.time-t.time),this._host?.requestUpdate()}draw(e,t){if(this._positions=[],0===this._events.length)return;const i=t.timeScale.visibleRange(),s=8*t.dpr,r=t.plotHeight*t.dpr-s-4*t.dpr;e.save(),e.textAlign="center",e.textBaseline="middle",e.font=10*t.dpr+"px system-ui, sans-serif";for(const n of this._events){const o=t.dataLayer.timeToIndex(n.time);if(void 0===o||o<i.from-1||o>i.to+1)continue;const a=t.timeScale.indexToX(o)*t.dpr,l=n.color??vt[n.type]??"#9aa0b4";e.fillStyle=l,e.beginPath(),e.arc(a,r,s,0,2*Math.PI),e.fill(),e.fillStyle="#0d0e12",e.fillText(n.label.slice(0,2),a,r),void 0!==n.id&&this._positions.push({id:n.id,x:a/t.dpr,y:r/t.dpr,r:s/t.dpr})}e.restore()}hitTest(e,t){let i=null;for(const s of this._positions){const r=Math.hypot(s.x-e,s.y-t);r<=s.r&&(null===i||r<i.distance)&&(i={externalId:s.id,zOrder:"normal",distance:r,cursor:"pointer"})}return i}}const wt=18,xt=16,Pt=["hide","settings","close"];function St(e,t,i,s,r,n,o){const a=.42*r,l=Math.max(1,Math.round(1.4*n));switch(e.save(),e.strokeStyle=e.fillStyle,e.lineWidth=l,e.lineCap="round",e.lineJoin="round",e.beginPath(),t){case"up":e.moveTo(i,s+a),e.lineTo(i,s-a),e.moveTo(i-.62*a,s-.35*a),e.lineTo(i,s-a),e.lineTo(i+.62*a,s-.35*a);break;case"down":e.moveTo(i,s-a),e.lineTo(i,s+a),e.moveTo(i-.62*a,s+.35*a),e.lineTo(i,s+a),e.lineTo(i+.62*a,s+.35*a);break;case"hide":e.moveTo(i-a,s),e.quadraticCurveTo(i,s-1.15*a,i+a,s),e.quadraticCurveTo(i,s+1.15*a,i-a,s),e.stroke(),e.beginPath(),e.arc(i,s,.34*a,0,2*Math.PI),!0===o.hidden&&(e.moveTo(i-a,s+.85*a),e.lineTo(i+a,s-.85*a));break;case"maximize":!0===o.maximized?(e.moveTo(i-a,s-.25*a),e.lineTo(i-.25*a,s-.25*a),e.lineTo(i-.25*a,s-a),e.moveTo(i+a,s+.25*a),e.lineTo(i+.25*a,s+.25*a),e.lineTo(i+.25*a,s+a)):(e.moveTo(i-a,s-.4*a),e.lineTo(i-a,s-a),e.lineTo(i-.4*a,s-a),e.moveTo(i+.4*a,s-a),e.lineTo(i+a,s-a),e.lineTo(i+a,s-.4*a),e.moveTo(i+a,s+.4*a),e.lineTo(i+a,s+a),e.lineTo(i+.4*a,s+a),e.moveTo(i-.4*a,s+a),e.lineTo(i-a,s+a),e.lineTo(i-a,s+.4*a));break;case"settings":e.arc(i,s,.46*a,0,2*Math.PI);for(let t=0;t<8;t++){const r=t*Math.PI/4,n=Math.cos(r),o=Math.sin(r);e.moveTo(i+n*a*.68,s+o*a*.68),e.lineTo(i+n*a,s+o*a)}break;case"close":e.moveTo(i-.8*a,s-.55*a),e.lineTo(i+.8*a,s-.55*a),e.moveTo(i-.3*a,s-.55*a),e.lineTo(i-.3*a,s-.85*a),e.lineTo(i+.3*a,s-.85*a),e.lineTo(i+.3*a,s-.55*a),e.moveTo(i-.6*a,s-.55*a),e.lineTo(i-.45*a,s+.85*a),e.lineTo(i+.45*a,s+.85*a),e.lineTo(i+.6*a,s-.55*a)}e.stroke(),e.restore()}class Ot{constructor(e){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_values",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_buttons",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),this._opts={font:11,left:8,top:6,row:0,...e}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setValue(e,t){this.setValues(""===e?[]:[{text:e,color:t}])}setValues(e){e.length===this._values.length&&e.every((e,t)=>e.text===this._values[t].text&&e.label===this._values[t].label&&e.color===this._values[t].color)||(this._values=e.map(e=>({...e})),this._host?.requestUpdate())}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}options(){return this._opts}draw(e,t){const i=this._opts,s=t.dpr,r=(i.font??11)*s,n=((i.top??6)+(i.row??0)*wt)*s,o=n+wt*s/2;let a=(i.left??8)*s;const l=!0===i.hidden;e.save(),e.textBaseline="middle",e.textAlign="left",e.globalAlpha=l?.45:1,void 0!==i.color&&(e.fillStyle=i.color,e.beginPath(),e.arc(a+3*s,o,3*s,0,2*Math.PI),e.fill(),a+=11*s),e.font=`600 ${r}px ui-sans-serif, system-ui, sans-serif`,e.fillStyle=t.theme.axisText,e.fillText(i.title,a,o),a+=e.measureText(i.title).width+6*s,e.font=`${r}px ui-sans-serif, system-ui, sans-serif`,void 0!==i.params&&""!==i.params&&(e.fillStyle=Ie(t.theme.axisText,.55),e.fillText(i.params,a,o),a+=e.measureText(i.params).width+6*s);for(const r of this._values)void 0!==r.label&&""!==r.label&&(e.fillStyle=Ie(t.theme.axisText,.55),e.fillText(r.label,a,o),a+=e.measureText(r.label).width+3*s),e.fillStyle=r.color??i.valueColor??i.color??t.theme.axisText,e.fillText(r.text,a,o),a+=e.measureText(r.text).width+6*s;this._buttons=[];const h="string"==typeof t.hoverId&&t.hoverId.startsWith(`${i.id}::`),c=i.actions??Pt;if(h&&c.length>0){const h=(18*c.length+6)*s;e.globalAlpha=1,e.fillStyle=Ie(t.theme.background,.82),e.beginPath(),e.roundRect(a-3*s,o-9*s,h,wt*s,5*s),e.fill(),a+=2*s;for(const h of c){const c=`${i.id}::${h}`,d=a;this._buttons.push({id:c,x:d/s,y:n/s});const u=t.hoverId===c;u&&(e.fillStyle=Ie(t.theme.axisText,.16),e.beginPath(),e.roundRect(d,o-8*s,xt*s,xt*s,4*s),e.fill()),e.globalAlpha=l?.5:u?1:.75,e.fillStyle="close"===h&&u?"#ff6b6b":t.theme.axisText,St(e,h,d+8*s,o,r,s,i),e.globalAlpha=1,a+=18*s}}this._width=a/s,e.restore()}hitTest(e,t){const i=this._opts,s=(i.top??6)+(i.row??0)*wt;if(t<s||t>s+wt)return null;for(const t of this._buttons)if(e>=t.x&&e<=t.x+xt)return{externalId:t.id,zOrder:"top",distance:0,cursor:"pointer"};const r=Math.max(this._width,(i.left??8)+40)+130;return e>=(i.left??8)-4&&e<=r?{externalId:`${i.id}::row`,zOrder:"top",distance:0,cursor:"default"}:null}}const Tt={id:"timenav",buttons:["zoomOut","zoomIn",null,"panLeftBar","panRightBar"],size:26,gap:4,groupGap:16,bottomMargin:10,revealHeight:64,fadeSeconds:.12,labels:{zoomOut:"Zoom out",zoomIn:"Zoom in",panLeftBar:"Move left",panRightBar:"Move right"},hints:{},showTooltip:!0,font:11,radius:6,zOrder:"top"};class Mt{constructor(e={},t){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_boxes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_pointer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_opacity",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastFrameMs",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_revealTop",{enumerable:!0,configurable:!0,writable:!0,value:1/0}),this._opts={...Tt,...e},this._now=t??(()=>"undefined"!=typeof performance?performance.now():0)}attached(e){this._host=e}detached(){this._host=null}zOrder(){return this._opts.zOrder??"top"}options(){return this._opts}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}setPointer(e){const t=this._pointer;this._pointer=e,(null===t!=(null===e)||this._opacity>0||this._targetOpacity()>0)&&this._host?.requestUpdate()}_revealed(){return null!==this._pointer&&this._pointer.y>=this._revealTop}_targetOpacity(){return this._revealed()?1:0}animating(){return Math.abs(this._targetOpacity()-this._opacity)>.001}draw(e,t){const i=this._opts,s=t.dpr;this._revealTop=Math.max(0,t.plotHeight-i.revealHeight);const r=this._targetOpacity(),n=this._now(),o=null===this._lastFrameMs?0:Math.max(0,(n-this._lastFrameMs)/1e3);if(this._lastFrameMs=n,i.fadeSeconds<=0||o<=0)i.fadeSeconds<=0&&(this._opacity=r);else{const e=o/i.fadeSeconds;this._opacity+=Math.sign(r-this._opacity)*Math.min(e,Math.abs(r-this._opacity))}if(this._opacity<=.001)return this._boxes=[],void(this._opacity=0);const a=i.size;let l=0;for(let e=0;e<i.buttons.length;e++){null!==i.buttons[e]?(l+=a,e<i.buttons.length-1&&null!==i.buttons[e+1]&&(l+=i.gap)):l+=i.groupGap}const h=(t.plotWidth-l)/2,c=t.plotHeight-i.bottomMargin-a;this._boxes=[];let d=h;for(let e=0;e<i.buttons.length;e++){const t=i.buttons[e];null!==t?(this._boxes.push({action:t,x:d,y:c,w:a,h:a}),d+=a,e<i.buttons.length-1&&null!==i.buttons[e+1]&&(d+=i.gap)):d+=i.groupGap}const u=this._hoveredAction();e.save(),e.globalAlpha=this._opacity;for(const i of this._boxes)this._button(e,i,i.action===u,t,s);i.showTooltip&&null!==u&&this._tooltip(e,u,t,s),e.restore()}_hoveredAction(){const e=this._pointer;if(null===e)return null;for(const t of this._boxes)if(e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h)return t.action;return null}_button(e,t,i,s,r){const n=this._opts,o=t.x*r,a=t.y*r,l=t.w*r,h=t.h*r,c=Math.min(n.radius*r,l/2,h/2);e.beginPath(),e.roundRect(o,a,l,h,c),e.fillStyle=Ct(s.theme.background,s.theme.axisText,i?.28:.12),e.fill(),e.strokeStyle=jt(s.theme.axisLine,i?1:.8),e.lineWidth=Math.max(1,Math.round(r)),e.stroke(),e.strokeStyle=s.theme.axisText,e.fillStyle=s.theme.axisText,e.lineWidth=Math.max(1,Math.round(1.5*r)),e.lineCap="round",e.lineJoin="round";const d=o+l/2,u=a+h/2,p=.22*Math.min(l,h);switch(e.beginPath(),t.action){case"zoomOut":e.moveTo(d-p,u),e.lineTo(d+p,u);break;case"zoomIn":e.moveTo(d-p,u),e.lineTo(d+p,u),e.moveTo(d,u-p),e.lineTo(d,u+p);break;case"panLeftBar":e.moveTo(d+.55*p,u-p),e.lineTo(d-.5*p,u),e.lineTo(d+.55*p,u+p);break;case"panRightBar":e.moveTo(d-.55*p,u-p),e.lineTo(d+.5*p,u),e.lineTo(d-.55*p,u+p)}e.stroke()}_tooltip(e,t,i,s){const r=this._opts,n=this._boxes.find(e=>e.action===t);if(void 0===n)return;const o=r.labels[t],a=r.hints[t];e.font=r.font*s+"px ui-sans-serif, system-ui, sans-serif",e.textBaseline="middle",e.textAlign="left";const l=7*s,h=8*s,c=e.measureText(o).width,d=2*l+c+(void 0===a?0:e.measureText(a).width+h+8*s),u=22*s;let p=(n.x+n.w/2)*s-d/2;p=Math.max(2*s,Math.min(p,i.plotWidth*s-d-2*s));const _=n.y*s-u-6*s;if(e.beginPath(),e.roundRect(p,_,d,u,5*s),e.fillStyle=Ct(i.theme.background,i.theme.axisText,.22),e.fill(),e.strokeStyle=jt(i.theme.axisLine,.9),e.lineWidth=Math.max(1,Math.round(s)),e.stroke(),e.fillStyle=i.theme.axisText,e.fillText(o,p+l,_+u/2),void 0!==a){const t=p+l+c+h,r=e.measureText(a).width+8*s;e.beginPath(),e.roundRect(t-4*s,_+4*s,r,u-8*s,3*s),e.fillStyle=Ct(i.theme.background,i.theme.axisText,.42),e.fill(),e.fillStyle=i.theme.axisText,e.fillText(a,t,_+u/2)}}hitTest(e,t){if(this._opacity<.5)return null;for(const i of this._boxes)if(e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h)return{externalId:`${this._opts.id}::${i.action}`,zOrder:"top",distance:0,cursor:"pointer"};return null}}function Ct(e,t,i){const s=It(e),r=It(t);if(null===s||null===r)return e;const n=i<0?0:i>1?1:i;return`rgb(${Math.round(s[0]+(r[0]-s[0])*n)},${Math.round(s[1]+(r[1]-s[1])*n)},${Math.round(s[2]+(r[2]-s[2])*n)})`}function It(e){if(e.startsWith("#")){const t=e.slice(1),i=3===t.length?t.split("").map(e=>e+e).join(""):t,s=parseInt(i.slice(0,6),16);return Number.isNaN(s)?null:[s>>16&255,s>>8&255,255&s]}const t=/^rgba?\(([^)]+)\)$/.exec(e);if(null===t)return null;const i=t[1].split(",").map(e=>parseFloat(e));return[i[0],i[1],i[2]]}function jt(e,t){if(e.startsWith("#")){const i=e.slice(1),s=3===i.length?i.split("").map(e=>e+e).join(""):i,r=parseInt(s.slice(0,6),16);return Number.isNaN(r)?e:`rgba(${r>>16&255},${r>>8&255},${255&r},${t})`}const i=/^rgba?\(([^)]+)\)$/.exec(e);if(null===i)return e;const s=i[1].split(",").map(e=>e.trim());return`rgba(${s[0]},${s[1]},${s[2]},${t})`}const Lt=["#f5a623","#26a69a","#ab47bc","#ef5350","#26c6da","#8bc34a","#ff7043","#5c6bc0"];function kt(e){const t=Math.abs(e);return t>=1e9?(e/1e9).toFixed(2)+"B":t>=1e6?(e/1e6).toFixed(2)+"M":t>=1e3?(e/1e3).toFixed(2)+"K":String(Math.round(e))}function At(){return"undefined"!=typeof window&&window.devicePixelRatio?window.devicePixelRatio:1}class Ft{constructor(e,t={}){Object.defineProperty(this,"_container",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pixelRatio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_theme",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_panes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_loop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_dataLayer",{enumerable:!0,configurable:!0,writable:!0,value:new x}),Object.defineProperty(this,"_timeScale",{enumerable:!0,configurable:!0,writable:!0,value:new y}),Object.defineProperty(this,"_priceAxisWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_timeAxisHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resizeObserver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_hasFitContent",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_crosshairMode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_shortcuts",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_trading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pointerInside",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_keyTarget",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_conflate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_conflationFactor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_gridVert",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_gridHorz",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_cursorPane",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_cursor",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragStartX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragStartY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_pointers",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_pinch",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pinchPane",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_liveRegion",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragStartOffset",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragT",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragVelocity",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_kineticHandle",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_firstDataId",{enumerable:!0,configurable:!0,writable:!0,value:{value:null}}),Object.defineProperty(this,"_indicators",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_recomputing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drawingState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maximizedPane",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_savedWeights",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_legends",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_firstPaneIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_historyLoader",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadingHistory",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_clickCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_crosshairCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pointerMoved",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_placementMode",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_legendOffset",{enumerable:!0,configurable:!0,writable:!0,value:{top:6,left:8,paneIndex:0}}),Object.defineProperty(this,"_downPane",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_downX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_downLocalY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_hoverId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_overlayFrozen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragEndCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_axisDrag",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragMoved",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragFrom",{enumerable:!0,configurable:!0,writable:!0,value:{time:0,price:0}}),Object.defineProperty(this,"_paneResize",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_axisStartCoord",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartMin",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartMax",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartSpacing",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_priceFormatter",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_priceScaleOptions",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_timeFormatter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_leftAxisWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_timeNav",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_timeNavPane",{enumerable:!0,configurable:!0,writable:!0,value:-1}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_onPointerEnter",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._pointerInside=!0}}),Object.defineProperty(this,"_onContextMenu",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(e.defaultPrevented)return;const t=this._panes[this._localPoint(e).pane];if(void 0!==t){this._cursor=null,this._cursorPane=null;try{const e=t.top.ctx;e.save(),e.globalCompositeOperation="destination-over",e.drawImage(t.base.element,0,0),e.restore(),this._overlayFrozen=!0}catch{}}}}),Object.defineProperty(this,"_onPointerDown",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(this._unfreezeOverlay(),"mouse"===e.pointerType&&0!==e.button)return;this._stopKinetic();const t=this._localPoint(e);this._pointers.set(e.pointerId,{x:t.x,y:t.y,pane:t.pane});try{this._container.setPointerCapture?.(e.pointerId)}catch{}if(this._pointers.size>=2)return void this._beginPinch();this._downPane=t.pane,this._downX=t.x,this._downLocalY=t.localY;const s=this._dividerAt(t.y);if(null!==s){const e=this._paneLayout();return this._paneResize={index:s,startY:t.y,aWeight:this._panes[s].weight,bWeight:this._panes[s+1].weight,aHeight:e[s].height,bHeight:e[s+1].height},void(this._dragging=!1)}const r=Math.max(0,this._width-this._priceAxisWidth),n=t.x>=r,o=t.pane===this._panes.length-1&&t.localY>=t.paneHeight-this._timeAxisHeight;if(n){this._axisDrag="price",this._axisStartCoord=t.localY;const e=this._panes[t.pane].priceScale.priceRange();return this._axisStartMin=e.min,this._axisStartMax=e.max,void(this._dragging=!1)}if(o)return this._axisDrag="time",this._axisStartCoord=t.x,this._axisStartSpacing=this._timeScale.barSpacing,void(this._dragging=!1);if(this._placementMode)return this._dragging=!1,void(this._pointerMoved=!1);const a=this._panes[t.pane]?.hitTestPrimitives(t.x-this._leftAxisWidth,t.localY,this._renderContext(t.pane===this._panes.length-1));if(a&&(!0===a.draggable||"ns-resize"===a.cursor&&null!==this._dragCb))return this._dragId=a.externalId,this._dragMoved=!1,this._ensureScaled(t.pane),this._dragFrom={time:this._xToTime(t.x),price:this._panes[t.pane].priceScale.yToPrice(t.localY)},this._setHover(a),this._cursor=null,this._cursorPane=null,this.invalidate(e=>e.invalidateGlobal(i.Cursor)),this._dragging=!1,void(this._pointerMoved=!1);this._dragging=!0,this._pointerMoved=!1,this._dragStartX=t.x,this._dragStartY=t.y,this._lastDragY=t.y,this._dragStartOffset=this._timeScale.rightOffset,this._lastDragX=t.x,this._lastDragT=this._now(),this._dragVelocity=0}}),Object.defineProperty(this,"_onPointerMove",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(this._unfreezeOverlay(),"mouse"===e.pointerType&&!(1&e.buttons)&&(this._dragging||null!==this._dragId||null!==this._axisDrag))return void this._onPointerUp(e);const t=this._localPoint(e);if(this._pointers.has(e.pointerId)&&this._pointers.set(e.pointerId,{x:t.x,y:t.y,pane:t.pane}),null===this._pinch){if("price"===this._axisDrag){const e=t.localY-this._axisStartCoord,s=Math.exp(.005*e),r=(this._axisStartMin+this._axisStartMax)/2,n=(this._axisStartMax-this._axisStartMin)/2*s,o=this._panes[this._downPane].priceScale;return o.setPriceRange({min:r-n,max:r+n}),o.setAutoScale(!1),void this.invalidate(e=>e.invalidatePane(this._downPane,{level:i.Light,autoScale:!1}))}if(null!==this._paneResize){const e=this._paneResize,s=e.aHeight+e.bHeight,r=e.aWeight+e.bWeight,n=Math.min(24,s/4),o=Math.max(n,Math.min(s-n,e.aHeight+(t.y-e.startY)));return this._panes[e.index].weight=o/s*r,this._panes[e.index+1].weight=r-this._panes[e.index].weight,this._relayout(),void this.invalidate(e=>e.invalidateGlobal(i.Full))}if("time"===this._axisDrag){const e=t.x-this._axisStartCoord;return this._timeScale.setBarSpacing(this._axisStartSpacing*Math.exp(.005*e)),void this.invalidate(e=>e.invalidateGlobal(i.Full))}if(this._placementMode&&this._pointers.size>0&&(Math.abs(t.x-this._downX)>3||Math.abs(t.localY-this._downLocalY)>3)&&(this._pointerMoved=!0),null!==this._dragId){(Math.abs(t.x-this._downX)>3||Math.abs(t.localY-this._downLocalY)>3)&&(this._dragMoved=!0);const e=this._panes[this._downPane].priceScale.yToPrice(t.localY),i=this._xToTime(t.x);return this._dragCb?.(this._dragId,e,i),void this.emit("drag",{id:this._dragId,price:e,time:i,paneIndex:this._downPane,fromPrice:this._dragFrom.price,fromTime:this._dragFrom.time})}if(this._dragging){const e=t.x-this._dragStartX;(Math.abs(e)>3||Math.abs(t.y-this._dragStartY)>3)&&(this._pointerMoved=!0),this._timeScale.setRightOffset(this._dragStartOffset-e/this._timeScale.barSpacing),this._panes[this._downPane]?.priceScale.panByPixels(t.y-this._lastDragY),this._lastDragY=t.y;const s=this._now(),r=s-this._lastDragT;return r>0&&(this._dragVelocity=(t.x-this._lastDragX)/r),this._lastDragX=t.x,this._lastDragT=s,this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),void this._emitViewport("pan")}this._updateCursor(t.pane,t.x,t.localY,t.y)}else this._updatePinch()}}),Object.defineProperty(this,"_onPointerUp",{enumerable:!0,configurable:!0,writable:!0,value:e=>{try{this._container.releasePointerCapture?.(e.pointerId)}catch{}if(this._pointers.delete(e.pointerId),null===this._pinch){if(null!==this._paneResize)return this._paneResize=null,void this.emit("paneResized",{paneIndex:this._downPane});if(null===this._axisDrag){if(null!==this._dragId){const t=this._localPoint(e),s=this._panes[this._downPane].priceScale.yToPrice(t.localY),r=this._xToTime(t.x);if(this._dragEndCb?.(this._dragId,s,r),this.emit("drag:end",{id:this._dragId,price:s,time:r,paneIndex:this._downPane}),!this._dragMoved){const e=this._dragId;this._clickCb?.(e),this.emit("click",{id:e,price:s,time:r,paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}})}this._dragId=null;const n="touch"===e.pointerType?null:this._panes[t.pane]?.hitTestPrimitives(t.x-this._leftAxisWidth,t.localY,this._renderContext(t.pane===this._panes.length-1))??null;return this._setHover(n),void this.invalidate(e=>e.invalidateGlobal(i.Light))}if(this._dragging=!1,this._placementMode&&this._pointerMoved){const t=this._localPoint(e);return this._ensureScaled(this._downPane),this.emit("click",{id:null,price:this._panes[this._downPane]?.priceScale.yToPrice(this._downLocalY)??null,time:this._xToTime(this._downX),paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}}),void this.emit("click",{id:null,price:this._panes[this._downPane]?.priceScale.yToPrice(t.localY)??null,time:this._xToTime(t.x),paneIndex:this._downPane,point:{x:t.x,y:t.localY},viaDrag:!0})}if(!this._pointerMoved){const e=this._downPane===this._panes.length-1,t=this._panes[this._downPane]?.hitTestPrimitives(this._downX-this._leftAxisWidth,this._downLocalY,this._renderContext(e));if(t&&this._handleLegendAction(t.externalId))return;return t&&this._clickCb?.(t.externalId),this._ensureScaled(this._downPane),void this.emit("click",{id:t?.externalId??null,price:this._panes[this._downPane]?.priceScale.yToPrice(this._downLocalY)??null,time:this._xToTime(this._downX),paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}})}ze.shouldAnimate(this._dragVelocity)&&this._startKinetic(this._dragVelocity)}else this._axisDrag=null}else this._pointers.size<2&&(this._pinch=null,this._dragging=!1)}}),Object.defineProperty(this,"_onPointerUpNative",{enumerable:!0,configurable:!0,writable:!0,value:e=>{"mouse"===e.pointerType&&0!==e.button||this._onPointerUp(e)}}),Object.defineProperty(this,"_onPointerLeave",{enumerable:!0,configurable:!0,writable:!0,value:()=>{if(this._pointerInside=!1,this._feedTimeNav(null),null===this._dragId&&this._setHover(null),null!==this._cursor){this._cursor=null,this._cursorPane=null,this.invalidate(e=>e.invalidateGlobal(i.Cursor));for(const e of this._indicators)e.updateLegendValues();const e={time:null,index:null,price:null,bar:null,point:null,paneIndex:null};this._crosshairCb?.(e),this.emit("crosshair:move",e)}}}),Object.defineProperty(this,"_onWheel",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._unfreezeOverlay(),e.preventDefault();const t=this._localPoint(e),s=e.deltaY<0?1.1:1/1.1;this._timeScale.zoomAtX(t.x,s),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._emitViewport("zoom")}}),Object.defineProperty(this,"_onDblClick",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.emit("dblclick",{}),this._placementMode||this.resetScale()}}),Object.defineProperty(this,"_onKeyDown",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._unfreezeOverlay();const t=this._shortcuts;if(null===t||st.shouldIgnore(e.target)||!this._shortcutsActive())return;const s=t.resolve(e);if(null===s)return;let r=this._runShortcut(s);r||(r=t.runCustom(s)),r&&(e.preventDefault(),t.emitTrigger(s),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary())}}),this._container=e,this._doc=t.document??e.ownerDocument,this._pixelRatio=t.pixelRatio??At,this._theme=t.theme??ue,this._priceAxisWidth=t.priceAxisWidth??56,void 0!==t.legendOffset?.top&&(this._legendOffset.top=t.legendOffset.top),void 0!==t.legendOffset?.left&&(this._legendOffset.left=t.legendOffset.left),void 0!==t.legendOffset?.paneIndex&&(this._legendOffset.paneIndex=t.legendOffset.paneIndex),this._timeAxisHeight=t.timeAxisHeight??22,this._crosshairMode=t.crosshairMode??"normal";const s=t.shortcuts;this._shortcuts=!1===s?null:s instanceof st?s:new st(s??{}),this._now=t.now??(()=>"undefined"!=typeof performance?performance.now():0),this._conflate=t.conflate??!1,this._conflationFactor=t.conflationFactor??1,this._priceFormatter=t.priceFormatter??null,this._priceScaleOptions=t.priceScale??null,this._timeFormatter=t.timeFormatter,this._gridVert=t.grid?.vertLines??!0,this._gridHorz=t.grid?.horzLines??!0;const r=t.timeNavigator??!0;!1!==r&&(this._timeNav=new Mt({...!0===r?{}:r,hints:this._navHints(!0===r?void 0:r)},this._now));const o="function"==typeof getComputedStyle?getComputedStyle(e).position:e.style.position;o&&"static"!==o||(e.style.position="relative"),e.style.display="flex",e.style.flexDirection="column",e.style.background=this._theme.background,e.style.touchAction="none",e.getAttribute("role")||e.setAttribute("role","application"),e.setAttribute("aria-label",t.ariaLabel??"Interactive financial chart"),e.hasAttribute("tabindex")||(e.tabIndex=0);const a=this._doc.createElement("div");a.setAttribute("aria-live","polite");const l=a.style;l.position="absolute",l.width="1px",l.height="1px",l.overflow="hidden",l.clip="rect(0 0 0 0)",l.whiteSpace="nowrap",l.border="0",l.padding="0",l.margin="-1px",e.appendChild(a),this._liveRegion=a,this._loop=t.raf?new n(()=>this._onFrame(),t.raf.schedule,t.raf.cancel):new n(()=>this._onFrame()),this._addPane(),this._observeSize(),this._attachInput(),this._timeScale.setChangeHandler(()=>this.invalidate(e=>e.invalidateGlobal(i.Full))),this.applySize(e.clientWidth,e.clientHeight),"function"==typeof queueMicrotask&&queueMicrotask(()=>this.emit("ready",{}))}setHistoryLoader(e){this._historyLoader=e}historyLoadComplete(){this._loadingHistory=!1}get dataLayer(){return this._dataLayer}get timeScale(){return this._timeScale}setVisibleLogicalRange(e){this._timeScale.setVisibleLogicalRange(e)}getVisibleLogicalRange(){return this._timeScale.visibleRange()}fitContent(){this._dataLayer.length<=0||(this._timeScale.fitContent(this._dataLayer.length),this.invalidate(e=>e.invalidateGlobal(i.Full)))}get shortcuts(){return this._shortcuts}get trading(){return null===this._trading&&(this._trading=new ut(this)),this._trading}addSeries(e,t={}){return this._createSeries(e,t,!0)}_createSeries(e,t,s){const r=this._dataLayer.createSeries(),n=t.paneIndex??0;this._ensurePane(n),s&&null===this._firstDataId.value&&z(e).isPriceSeries&&(this._firstDataId.value=r,this._firstPaneIndex=n);const o=function(e,t,i,s="right"){return{dataId:e,type:t,style:{...z(t).defaultStyle,...i},scaleId:s}}(r,e,t.style,t.priceScaleId??"right");if(this._panes[n].addSeries(o),this._recomputeLeftAxis(),t.priceFormat){const e=this._panes[n].scaleOf(o),i=t.priceFormat;if("custom"===i.type)e.setPriceFormatter(i.formatter);else if("volume"===i.type)e.setPriceFormatter(kt);else{const t=i.minMove??(void 0!==i.precision?Math.pow(10,-i.precision):void 0);void 0!==t&&e.setOptions({minMove:t})}}return{setData:e=>this._setData(r,e.map(We)),prependData:e=>this._prependData(r,e.map(We)),update:e=>this._updateBar(r,We(e)),getData:()=>this._dataLayer.indexedBars(r).map(e=>e.bar),applyOptions:e=>{Object.assign(o.style,e),this.invalidate(e=>e.invalidateGlobal(i.Full))},remove:()=>{this._panes[n].removeSeries(o),this._dataLayer.removeSeries(r),this._firstDataId.value===r&&(this._firstDataId.value=null),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),this._recomputeLeftAxis(),this.invalidate(e=>e.invalidateGlobal(i.Full))},priceScale:()=>this._panes[n].scaleOf(o),createMarkers:()=>{const e=new gt(r);return this._addPrimitive(n,e),e}}}addPriceLine(e,t=0){const i=new rt(e);return this._addPrimitive(t,i),i}addEventMarkers(e=0){const t=new yt;return this._addPrimitive(e,t),t}addIndicator(e,t={},i={}){const s=ye(e),r=new Re(this._indicatorHost(),s,this._distinctColors(s,t),i.paneIndex);return this._indicators.push(r),r}_distinctColors(e,t){const i=this._indicators.filter(t=>t.indicatorId===e.id).length;if(0===i)return t;const s={...t},r=e.plots;for(let e=0;e<r.length;e++){const t=_e(r[e]).color;void 0===s[t]&&(s[t]=Lt[(i*r.length+e)%Lt.length])}return s}indicators(){return this._indicators}removeIndicator(e){const t=this._indicators.findIndex(t=>t.id===e);if(t<0)return!1;const{indicatorId:i,paneIndex:s}=this._indicators[t];return this._indicators[t].remove(),this._indicators.splice(t,1),this.emit("indicatorRemoved",{instanceId:e,indicatorId:i,paneIndex:s}),s>0&&0===this._panes[s]?.series().length&&this.removePane(s),!0}_indicatorHost(){return{addIndicatorLegend:e=>{const t=0===e.row&&e.paneIndex>0?["hide","settings","up","down","maximize","close"]:["hide","settings","close"],i=e.paneIndex===this._legendOffset.paneIndex?{top:this._legendOffset.top,left:this._legendOffset.left}:{},s=new Ot({...i,...e,actions:t});return this._addPrimitive(e.paneIndex,s),s},removeIndicatorLegend:e=>{this.removePrimitive(e),this._restackLegends()},legendRowsOn:e=>this._legends.filter(t=>t.paneIndex===e).length,addIndicatorSeries:(e,t,i,s)=>this._createSeries(e,{paneIndex:t,style:i,priceScaleId:s},!1),addIndicatorLevel:(e,t,i,s,r,n)=>this.addPriceLine({price:e,color:t,lineWidth:1,dashed:i,leftLabel:s,id:r},n),removeIndicatorLevel:e=>this.removePrimitive(e),addIndicatorFill:(e,t)=>this._addPrimitive(t,e),removeIndicatorFill:e=>this.removePrimitive(e),sourceBars:()=>null===this._firstDataId.value?[]:this._dataLayer.seriesBars(this._firstDataId.value),nextPaneIndex:()=>this._panes.length,setPaneRange:(e,t)=>{const i=this._panes[e];void 0!==i&&(null===t?i.priceScale.setAutoScale(!0):(i.priceScale.setAutoScale(!1),i.priceScale.setPriceRange(t)))}}}_recomputeIndicators(){if(!this._recomputing&&0!==this._indicators.length){this._recomputing=!0;try{for(const e of this._indicators)e.recompute()}finally{this._recomputing=!1}}}subscribeClick(e){this._clickCb=e}subscribeCrosshairMove(e){this._crosshairCb=e}subscribeDrag(e,t){this._dragCb=e,this._dragEndCb=t??null}_ensureScaled(e){const t=this._panes[e];void 0===t||t.priceScale.scaled||t.autoscale(this._renderContext(e===this._panes.length-1))}_xToTime(e){return this._dataLayer.indexToTimeFloat(this._timeScale.xToIndex(e-this._leftAxisWidth))}timeToCoordinate(e){return this._timeScale.indexToX(this._dataLayer.timeToIndexFloat(e))+this._leftAxisWidth}coordinateToTime(e){return this._xToTime(e)}on(e,t){let i=this._listeners.get(e);return void 0===i&&(i=new Set,this._listeners.set(e,i)),i.add(t),()=>this.off(e,t)}once(e,t){const i=s=>{this.off(e,i),t(s)};return this.on(e,i)}off(e,t){void 0!==t?this._listeners.get(e)?.delete(t):this._listeners.delete(e)}emit(e,t){const i=this._listeners.get(e);if(void 0!==i)for(const e of[...i])try{e(t)}catch{}}_emitViewport(e){if(void 0===this._listeners.get(e))return;const t=this._timeScale.visibleRange();this.emit(e,{from:this._dataLayer.indexToTime(Math.round(t.from))??null,to:this._dataLayer.indexToTime(Math.round(t.to))??null,logicalFrom:t.from,logicalTo:t.to})}addPrimitive(e,t=0){this._addPrimitive(t,e)}priceToCoordinate(e,t=0){this._ensureScaled(t);const i=this._panes[t];if(void 0===i)return null;return(this._paneLayout()[t]?.top??0)+i.priceScale.priceToY(e)}coordinateToPrice(e,t=0){this._ensureScaled(t);const i=this._panes[t];if(void 0===i)return null;const s=this._paneLayout()[t]?.top??0;return i.priceScale.yToPrice(e-s)}setGridOptions(e){void 0!==e.vertLines&&(this._gridVert=e.vertLines),void 0!==e.horzLines&&(this._gridHorz=e.horzLines),this.invalidate(e=>e.invalidateGlobal(i.Full))}gridOptions(){return{vertLines:this._gridVert,horzLines:this._gridHorz}}takeScreenshot(){const e=this._pixelRatio(),t=this._doc.createElement("canvas");t.width=Math.max(1,Math.round(this._width*e)),t.height=Math.max(1,Math.round(this._height*e));const i=t.getContext("2d");if(null===i)return t;i.fillStyle=this._theme.background,i.fillRect(0,0,t.width,t.height);const s=this._paneLayout();for(let t=0;t<this._panes.length;t++){const r=Math.round((s[t]?.top??0)*e);i.drawImage(this._panes[t].base.element,0,r),i.drawImage(this._panes[t].top.element,0,r)}return t}_addPrimitive(e,t){this._ensurePane(e);const s={requestUpdate:()=>this.invalidate(t=>t.invalidatePane(e,{level:i.Light,autoScale:!1}))};this._panes[e].addPrimitive(t,s),t instanceof Ot&&(this._legends.push({legend:t,paneIndex:e}),this._restackLegends()),this.invalidate(t=>t.invalidatePane(e,{level:i.Light,autoScale:!1}))}removePrimitive(e){const t=this._legends.findIndex(t=>t.legend===e);t>=0&&this._legends.splice(t,1);for(let s=0;s<this._panes.length;s++)if(this._panes[s].removePrimitive(e))return t>=0&&this._restackLegends(),void this.invalidate(e=>e.invalidatePane(s,{level:i.Light,autoScale:!1}))}_restackLegends(){const e=new Map;for(const t of this._legends){const i=e.get(t.paneIndex)??0;t.legend.setOptions({row:i}),e.set(t.paneIndex,i+1)}}tradeHost(e=0){return{addPrimitive:t=>this._addPrimitive(e,t),removePrimitive:e=>this.removePrimitive(e)}}_updateBar(e,t){const s=this._timeScale.rightOffset>=0,r=this._dataLayer.update(e,t);this._timeScale.setBaseIndex(this._dataLayer.baseIndex),"append"!==r||s||this._timeScale.setRightOffset(this._timeScale.rightOffset-1),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_ensurePane(e){let t=!1;for(;this._panes.length<=e;)this._addPane(0===this._panes.length?1:.32),t=!0;t&&this._relayout()}_setData(e,t){this._dataLayer.setSeriesData(e,t),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),!this._hasFitContent&&this._dataLayer.length>0&&(this._timeScale.setWidth(Math.max(0,this._width-this._priceAxisWidth-this._leftAxisWidth)),this._timeScale.fitContent(this._dataLayer.length),this._hasFitContent=!0),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_prependData(e,t){this._dataLayer.addBars(e,t),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_addPane(e=1){const t=new he(this._doc);return t.weight=e,t.priceScale.setPriceFormatter(this._priceFormatter),this._priceScaleOptions&&t.priceScale.setOptions(this._priceScaleOptions),this._panes.push(t),this._container.appendChild(t.element),t}setPriceFormatter(e){this._priceFormatter=e;for(const t of this._panes)t.priceScale.setPriceFormatter(e);this.invalidate(e=>e.invalidateGlobal(i.Full))}setTimeFormatter(e){this._timeFormatter=e,this.invalidate(e=>e.invalidateGlobal(i.Full))}setPlacementMode(e){this._placementMode=e}setTheme(e){this._theme=e,this._container.style.background=e.background,this.invalidate(e=>e.invalidateGlobal(i.Full))}applyOptions(e){e.theme&&this.setTheme(e.theme),e.grid&&this.setGridOptions(e.grid),void 0!==e.priceFormatter&&this.setPriceFormatter(e.priceFormatter),"timeFormatter"in e&&this.setTimeFormatter(e.timeFormatter),e.crosshairMode&&(this._crosshairMode=e.crosshairMode)}panes(){return this._panes}getState(){const e=this._panes.map(e=>{const t=e.priceScale,i=t.options,s={weight:e.weight,priceScale:{marginTop:i.marginTop,marginBottom:i.marginBottom,minMove:i.minMove,mode:i.mode,inverted:i.inverted,autoScale:t.autoScale}};return t.autoScale||(s.priceScale.range={...t.priceRange()}),s}),t=[];this._panes.forEach((e,i)=>{for(const s of e.series())t.push({type:s.type,style:{...s.style},paneIndex:i,priceScaleId:s.scaleId})});const i={version:1,viewport:{...this.getVisibleLogicalRange()},barSpacing:this._timeScale.barSpacing,grid:this.gridOptions(),crosshairMode:this._crosshairMode,panes:e,series:t,indicators:this._indicators.map(e=>({indicatorId:e.indicatorId,settings:e.settings(),paneIndex:e.paneIndex}))};return void 0!==this._drawingState&&(i.drawings=this._drawingState),i}restoreState(e){const t=e;if(null===t||"object"!=typeof t||"number"!=typeof t.version)return{applied:!1,series:[],indicators:0,reason:"not a chart state object"};if(t.version>1)return{applied:!1,series:[],indicators:0,reason:`state version ${t.version} is newer than 1`};t.grid&&this.setGridOptions(t.grid),t.crosshairMode&&(this._crosshairMode=t.crosshairMode),t.panes&&(t.panes.forEach((e,t)=>{this._ensurePane(t);const i=this._panes[t];i.weight=e.weight;const s=i.priceScale;s.setOptions({marginTop:e.priceScale.marginTop,marginBottom:e.priceScale.marginBottom,minMove:e.priceScale.minMove,mode:e.priceScale.mode,inverted:e.priceScale.inverted}),s.setAutoScale(e.priceScale.autoScale),!e.priceScale.autoScale&&e.priceScale.range&&s.setPriceRange(e.priceScale.range)}),this._relayout());let s=0;if(t.indicators){for(const e of this._indicators)e.remove();this._indicators.length=0;for(const e of t.indicators)we(e.indicatorId)&&(this._indicators.push(new Re(this._indicatorHost(),ye(e.indicatorId),e.settings,e.paneIndex)),s+=1)}for(let e=this._panes.length-1;e>0;e--)0===this._panes[e].series().length&&this.removePane(e);return this._drawingState=t.drawings,void 0!==t.barSpacing&&this._timeScale.setBarSpacing(t.barSpacing),t.viewport&&this._dataLayer.length>0&&this.setVisibleLogicalRange(t.viewport),this.invalidate(e=>e.invalidateGlobal(i.Full)),{applied:!0,series:t.series??[],indicators:s}}drawingState(){return this._drawingState}setDrawingState(e){this._drawingState=e}invalidate(e){null===this._pending&&(this._pending=new s),e(this._pending),this._loop.requestFrame()}applySize(e,t){e===this._width&&t===this._height||(this._width=e,this._height=t,this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("resize",{width:e,height:t}))}_relayout(){this._syncTimeNavPane();const e=this._pixelRatio(),t=this._weightTotal();for(const i of this._panes){const s=this._height*i.weight/t;i.element.style.flex=`0 0 ${s}px`,i.resize(this._width,s,e);const r=i===this._panes[this._panes.length-1];i.setScaleHeights(Math.max(0,s-(r?this._timeAxisHeight:0)))}this._timeScale.setWidth(Math.max(0,this._width-this._priceAxisWidth-this._leftAxisWidth))}_recomputeLeftAxis(){const e=this._panes.some(e=>e.hasLeftScale())?this._priceAxisWidth:0;e!==this._leftAxisWidth&&(this._leftAxisWidth=e,this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)))}_weightTotal(){let e=0;for(const t of this._panes)e+=t.weight;return e<=0?1:e}_dividerAt(e){const t=this._paneLayout();for(let i=0;i<t.length-1;i++){const s=t[i].top+t[i].height;if(Math.abs(e-s)<=Ft.DIVIDER_GRAB)return i}return null}setPaneWeight(e,t){const s=this._panes[e];void 0!==s&&(s.weight=Math.max(.05,t),this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)))}paneWeight(e){return this._panes[e]?.weight??0}removePane(e){if(e<=0||e>=this._panes.length)return!1;for(let t=this._indicators.length-1;t>=0;t--)this._indicators[t].paneIndex===e&&(this._indicators[t].remove(),this._indicators.splice(t,1));const t=this._panes[e];for(const e of[...t.series()])t.removeSeries(e),this._dataLayer.removeSeries(e.dataId),this._firstDataId.value===e.dataId&&(this._firstDataId.value=null);t.destroy(),this._panes.splice(e,1),null!==this._savedWeights&&(this._savedWeights.splice(e,1),this._savedWeights.length<=1&&(this._savedWeights=null));for(const t of this._indicators)t.paneIndex>e&&t.shiftPane(-1);return this._timeScale.setBaseIndex(this._dataLayer.baseIndex),this._recomputeLeftAxis(),this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneRemoved",{paneIndex:e}),!0}movePane(e,t){const s=e+t;if(e<=0||s<=0||e>=this._panes.length||s>=this._panes.length)return!1;const r=this._panes;[r[e],r[s]]=[r[s],r[e]];for(const i of this._indicators)i.paneIndex===e?i.shiftPane(t):i.paneIndex===s&&i.shiftPane(-t);for(const e of r)this._container.appendChild(e.element);return this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneMoved",{from:e,to:s}),!0}maximizePane(e){if(e<0||e>=this._panes.length)return!1;if(this._maximizedPane===e){const e=this._savedWeights;null!==e&&this._panes.forEach((t,i)=>{t.weight=e[i]??t.weight}),this._maximizedPane=null,this._savedWeights=null}else null===this._savedWeights&&(this._savedWeights=this._panes.map(e=>e.weight)),this._panes.forEach((t,i)=>{t.weight=i===e?1:.001}),this._maximizedPane=e;return this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneMaximized",{paneIndex:this._maximizedPane}),!0}maximizedPane(){return this._maximizedPane}_handleLegendAction(e){const t=e.lastIndexOf("::");if(t<0)return!1;const s=e.slice(t+2);if(null!==this._timeNav&&e.startsWith(`${this._timeNav.options().id}::`))return this._runShortcut(s)&&this.invalidate(e=>e.invalidateGlobal(i.Full)),!0;if("row"===s&&!e.startsWith("indicator:"))return!0;if(!e.startsWith("indicator:"))return!1;const r=e.slice(10,t);if("row"===s)return!0;const n=this._indicators.find(e=>e.id===r);if(void 0===n)return!1;const o=n.paneIndex;switch(s){case"close":return this.removeIndicator(r),!0;case"hide":return n.setVisible(!n.visible()),!0;case"up":return this.movePane(o,-1),!0;case"down":return this.movePane(o,1),!0;case"maximize":return this.maximizePane(o),!0;case"settings":return this.emit("indicatorSettings",{instanceId:r,indicatorId:n.indicatorId,paneIndex:o}),!0;default:return!1}}_paneLayout(){const e=this._weightTotal(),t=[];let i=0;for(const s of this._panes){const r=this._height*s.weight/e;t.push({top:i,height:r}),i+=r}return t}_navHints(e){if(void 0!==e?.hints)return e.hints;if(null===this._shortcuts)return{};const t={};for(const e of this._shortcuts.list()){if("zoomIn"!==e.command&&"zoomOut"!==e.command)continue;const i=e.combos[0];void 0!==i&&(t[e.command]=Bt(i))}return t}_syncTimeNavPane(){if(null===this._timeNav)return;const e=this._panes.length-1;e===this._timeNavPane||e<0||(this._timeNavPane>=0&&this._panes[this._timeNavPane]?.removePrimitive(this._timeNav),this._addPrimitive(e,this._timeNav),this._timeNavPane=e)}_feedTimeNav(e){const t=this._timeNav;null!==t&&(t.setPointer(e),t.animating()&&this.invalidate(e=>e.invalidateGlobal(i.Light)))}_renderContext(e){return{timeScale:this._timeScale,dataLayer:this._dataLayer,dpr:this._pixelRatio(),priceAxisWidth:this._priceAxisWidth,timeAxisHeight:this._timeAxisHeight,showTimeAxis:e,conflate:this._conflate,conflationFactor:this._conflationFactor,theme:this._theme,showVertGrid:this._gridVert,showHorzGrid:this._gridHorz,timeFormatter:this._timeFormatter,leftAxisWidth:this._leftAxisWidth,hoverId:this._hoverId,dragId:this._dragId}}_observeSize(){"undefined"!=typeof ResizeObserver&&(this._resizeObserver=new ResizeObserver(e=>{const t=e[0];t&&this.applySize(t.contentRect.width,t.contentRect.height)}),this._resizeObserver.observe(this._container))}_onFrame(){const e=this._pending;if(this._pending=null,null===e||e.isEmpty())return;const t=e.globalLevel;for(let s=0;s<this._panes.length;s++){const r=this._panes[s],n=e.paneInvalidation(s),o=Math.max(t,n?.level??i.None),a=s===this._panes.length-1,l=this._renderContext(a);if((o>=i.Full||n?.autoScale)&&r.autoscale(l),o>=i.Light&&r.paintBase(l),o>=i.Cursor&&!this._overlayFrozen){const e=null===this._cursor?null:{x:this._cursor.x,yLocal:s===this._cursorPane?this._cursor.y:null,showTimeTag:a};r.paintTop(e,l)}}}_attachInput(){if("undefined"==typeof window)return;const e=this._container;e.addEventListener("pointerdown",this._onPointerDown),e.addEventListener("pointermove",this._onPointerMove),e.addEventListener("pointerup",this._onPointerUpNative),e.addEventListener("pointercancel",this._onPointerUp),e.addEventListener("pointerleave",this._onPointerLeave),e.addEventListener("wheel",this._onWheel,{passive:!1}),e.addEventListener("dblclick",this._onDblClick),e.addEventListener("pointerenter",this._onPointerEnter),e.addEventListener("contextmenu",this._onContextMenu);const t="function"==typeof this._doc.addEventListener?this._doc:e;t.addEventListener("keydown",this._onKeyDown),this._keyTarget=t}_unfreezeOverlay(){this._overlayFrozen&&(this._overlayFrozen=!1,this.invalidate(e=>e.invalidateGlobal(i.Cursor)))}_localPoint(e){const t=this._container.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top,r=this._paneLayout();let n=0;for(let e=0;e<r.length;e++)s>=r[e].top&&(n=e);const o=r[n]??{top:0,height:this._height};return{x:i,y:s,pane:n,localY:s-o.top,paneHeight:o.height}}resetScale(){this._dataLayer.length>0&&this._timeScale.fitContent(this._dataLayer.length);for(const e of this._panes)e.priceScale.setAutoScale(!0);this.invalidate(e=>e.invalidateGlobal(i.Full))}_beginPinch(){const e=[...this._pointers.values()];this._pinch=pt(e[0],e[1]),this._pinchPane=e[0].pane,this._dragging=!1,this._axisDrag=null,this._dragId=null,this._pointerMoved=!0}_updatePinch(){const e=[...this._pointers.values()];if(e.length<2||null===this._pinch)return;const t=pt(e[0],e[1]),s=function(e,t){return{factor:e.dist>0?t.dist/e.dist:1,dx:t.cx-e.cx,dy:t.cy-e.cy}}(this._pinch,t);1!==s.factor&&this._timeScale.zoomAtX(t.cx,s.factor),this._timeScale.setRightOffset(this._timeScale.rightOffset-s.dx/this._timeScale.barSpacing),this._panes[this._pinchPane]?.priceScale.panByPixels(s.dy),this._pinch=t,this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._emitViewport(1!==s.factor?"zoom":"pan")}_shortcutsActive(){if(null===this._shortcuts)return!1;if("global"===this._shortcuts.scope||this._pointerInside)return!0;const e=this._doc.activeElement;return null!==e&&(e===this._container||!0===this._container.contains?.(e))}_runShortcut(e){const t=this._timeScale;switch(e){case"panLeftBar":return t.setRightOffset(t.rightOffset-1),!0;case"panRightBar":return t.setRightOffset(t.rightOffset+1),!0;case"panLeft":return t.setRightOffset(t.rightOffset-2),!0;case"panRight":return t.setRightOffset(t.rightOffset+2),!0;case"panLeftFast":return t.setRightOffset(t.rightOffset-10),!0;case"panRightFast":return t.setRightOffset(t.rightOffset+10),!0;case"panUp":return this._panes[0]?.priceScale.panByPixels(20),!0;case"panDown":return this._panes[0]?.priceScale.panByPixels(-20),!0;case"zoomIn":return t.zoomAtX(this._width/2,1.1),!0;case"zoomOut":return t.zoomAtX(this._width/2,1/1.1),!0;case"resetScale":return this.resetScale(),!0;case"fitContent":return this._dataLayer.length>0&&t.fitContent(this._dataLayer.length),!0;case"screenshot":return this.downloadScreenshot(),!0;case"toggleGridVert":return this.setGridOptions({vertLines:!this._gridVert}),!0;case"toggleGridHorz":return this.setGridOptions({horzLines:!this._gridHorz}),!0;case"toggleCrosshairMagnet":return this._crosshairMode="magnet"===this._crosshairMode?"normal":"magnet",!0;default:return!1}}downloadScreenshot(e="chart.png"){try{const t=this.takeScreenshot(),i=this._doc.createElement("a");i.href=t.toDataURL("image/png"),i.download=e,i.click()}catch{}}_updateAccessibleSummary(){if(null===this._liveRegion)return;const e=this._dataLayer.length;let t=`${e} bar${1===e?"":"s"}`;if(null!==this._firstDataId.value&&void 0!==this._panes[0]){const e=this._dataLayer.lastIndexedBar(this._firstDataId.value);null!==e&&(t+=`, latest price ${this._panes[0].priceScale.format(e.bar.close)}`)}this._liveRegion.textContent=`Financial chart, ${t}`}_setHover(e){const t=e?.externalId??null;this._container.style.cursor=e?.cursor??"",t!==this._hoverId&&(this._hoverId=t,this.invalidate(e=>e.invalidateGlobal(i.Light)),this.emit("hover",{id:t}))}_updateCursor(e,t,s,r=s){const n=this._width-this._priceAxisWidth,o=t-this._leftAxisWidth,a=Math.max(0,n-this._leftAxisWidth);if(o<0||o>a)return void this._onPointerLeave();const l=this._panes[e],h=l.hitTestPrimitives(o,s,this._renderContext(e===this._panes.length-1))??null;if(null===h&&null!==this._dividerAt(r))return this._setHover(null),void(this._container.style.cursor="row-resize");this._setHover(h),this._feedTimeNav(e===this._panes.length-1?{x:o,y:s}:null);let c=s;const d=Math.round(this._timeScale.xToIndex(o));let u=null;if(null!==this._firstDataId.value){const t=this._dataLayer.visibleBars(this._firstDataId.value,d,d);if(t.length>0&&(u=t[0].bar,"magnet"===this._crosshairMode&&e===this._firstPaneIndex)){const e=function(e,t){const i=[t.open,t.high,t.low,t.close];let s=i[0],r=Math.abs(e-s);for(let t=1;t<i.length;t++){const n=Math.abs(e-i[t]);n<r&&(r=n,s=i[t])}return s}(l.yToPrice(s),u);c=l.priceScale.priceToY(e)}}this._cursorPane=e,this._cursor={x:o,y:c};for(const e of this._indicators)e.updateLegendValues(d);if(this.invalidate(e=>e.invalidateGlobal(i.Cursor)),null!==this._crosshairCb||void 0!==this._listeners.get("crosshair:move")){const i={time:this._dataLayer.indexToTime(d)??null,index:d,price:l.yToPrice(s),bar:u,point:{x:t,y:r},paneIndex:e,pressed:this._pointers.size>0};this._crosshairCb?.(i),this.emit("crosshair:move",i)}}_maybeLoadHistory(){if(null===this._historyLoader||this._loadingHistory)return;const e=this._timeScale.visibleRange();e.from<10&&(this._loadingHistory=!0,this.emit("lazy-load",{from:this._dataLayer.indexToTime(Math.round(e.from))??null,to:this._dataLayer.indexToTime(Math.round(e.to))??null,direction:"backward"}),this._historyLoader())}_startKinetic(e){const t=new ze(e);if(t.durationMs<=0)return;const s=this._now();let r=0;const n=()=>{const e=this._now()-s,o=t.distanceAt(e),a=o-r;r=o,this._timeScale.setRightOffset(this._timeScale.rightOffset-a/this._timeScale.barSpacing),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),t.finished(e)?this._kineticHandle=null:this._kineticHandle=requestAnimationFrame(n)};this._kineticHandle=requestAnimationFrame(n)}_stopKinetic(){null!==this._kineticHandle&&(cancelAnimationFrame(this._kineticHandle),this._kineticHandle=null)}destroy(){this._loop.stop(),this._stopKinetic();for(const e of this._indicators)e.remove();if(this._indicators.length=0,this._resizeObserver?.disconnect(),this._resizeObserver=null,"undefined"!=typeof window){const e=this._container;e.removeEventListener("pointerdown",this._onPointerDown),e.removeEventListener("pointermove",this._onPointerMove),e.removeEventListener("pointerup",this._onPointerUpNative),e.removeEventListener("pointercancel",this._onPointerUp),e.removeEventListener("pointerleave",this._onPointerLeave),e.removeEventListener("wheel",this._onWheel),e.removeEventListener("dblclick",this._onDblClick),e.removeEventListener("pointerenter",this._onPointerEnter),e.removeEventListener("contextmenu",this._onContextMenu),this._keyTarget?.removeEventListener("keydown",this._onKeyDown),this._keyTarget=null}this._liveRegion?.remove(),this._liveRegion=null,this._container.style.cursor="",this._pointers.clear();for(const e of this._panes)e.destroy();this._panes.length=0}}function Rt(e,t={}){return new Ft(e,t)}function Bt(e){const t={Equal:"+",Minus:"-",NumpadAdd:"+",NumpadSubtract:"-",ArrowLeft:"<",ArrowRight:">",ArrowUp:"^",ArrowDown:"v"};return e.split("+").map(e=>e.trim()).map(e=>"Mod"===e?"Ctrl":t[e]??e.replace(/^(Key|Digit)/,"")).join(" + ")}Object.defineProperty(Ft,"DIVIDER_GRAB",{enumerable:!0,configurable:!0,writable:!0,value:4});const Nt={intervalSec:60,volumeMode:"ltq-sum",lateTickPolicy:"foldIntoBar",sessionAnchorSec:0};class Wt{constructor(e={}){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_current",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_cumAtBarStart",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastCum",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_hasCum",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._opts={...Nt,...e}}seed(e,t){this._current={...e},void 0!==t&&(this._lastCum=t,this._cumAtBarStart=t-(e.volume??0),this._hasCum=!0)}current(){return null===this._current?null:{...this._current}}bucketStart(e){const t=this._opts.sessionAnchorSec,i=this._opts.intervalSec;return t+Math.floor((e-t)/i)*i}onTick(e){const t=this.bucketStart(e.time);if(null!==this._current&&t<this._current.time)return"dropOlderThanPrevBar"===this._opts.lateTickPolicy?null:(this._foldInto(this._current,e),{bar:{...this._current},isNew:!1});if(null===this._current||t>this._current.time){const i=this._volumeForNewBar(e),s={time:t,open:e.price,high:e.price,low:e.price,close:e.price,volume:i};return this._current=s,{bar:{...s},isNew:!0}}return this._foldInto(this._current,e),{bar:{...this._current},isNew:!1}}_foldInto(e,t){t.price>e.high&&(e.high=t.price),t.price<e.low&&(e.low=t.price),e.close=t.price,e.volume=this._volumeForSameBar(e,t)}_volumeForNewBar(e){if("ltq-sum"===this._opts.volumeMode)return e.ltq??0;const t=e.cumDayVolume??0;return this._hasCum?t<this._lastCum?this._cumAtBarStart=0:this._cumAtBarStart=this._lastCum:this._cumAtBarStart=t,this._lastCum=t,this._hasCum=!0,Math.max(0,t-this._cumAtBarStart)}_volumeForSameBar(e,t){if("ltq-sum"===this._opts.volumeMode)return(e.volume??0)+(t.ltq??0);const i=t.cumDayVolume??0;return this._lastCum=i,Math.max(0,i-this._cumAtBarStart)}}function Dt(e,t,i,s,r,n){const o=r-t-i,a=n-t-s;switch(e){case"top-left":return{x:t,y:t,w:i,h:s};case"top-right":return{x:o,y:t,w:i,h:s};case"bottom-left":return{x:t,y:a,w:i,h:s};case"center":return{x:(r-i)/2,y:(n-s)/2,w:i,h:s};default:return{x:o,y:a,w:i,h:s}}}class zt{constructor(e={}){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_img",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_tintCanvas",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_tintKey",{enumerable:!0,configurable:!0,writable:!0,value:""}),this._opts={position:e.position??"bottom-right",margin:e.margin??12,height:e.height??28,opacity:e.opacity??.7,zOrder:e.zOrder??"top",src:e.src,image:e.image,tint:e.tint},e.image&&(this._img=e.image,this._ready=!0)}attached(e){if(this._host=e,!this._ready&&this._opts.src&&"undefined"!=typeof Image){const e=new Image;e.onload=()=>{this._img=e,this._ready=!0,this._host?.requestUpdate()},e.decoding="async",e.src=this._opts.src}}detached(){this._host=null}zOrder(){return this._opts.zOrder}autoscaleInfo(){return null}setOptions(e){this._opts={...this._opts,...e},this._tintCanvas=null,e.image?(this._img=e.image,this._ready=!0):void 0!==e.src&&(this._ready=!1,this._img=null,this.attached(this._host)),this._host?.requestUpdate()}draw(e,t){if(!this._ready||null===this._img)return;const i=this._opts,s=this._img.naturalWidth??this._img.width,r=this._img.naturalHeight??this._img.height;if(!s||!r)return;const n=i.height,o=n*(s/r),a=Dt(i.position,i.margin,o,n,t.plotWidth,t.plotHeight),l=t.dpr,h=Math.round(a.x*l),c=Math.round(a.y*l),d=Math.round(o*l),u=Math.round(n*l);e.save(),e.globalAlpha=Math.max(0,Math.min(1,i.opacity));const p=i.tint?this._tinted(e,d,u,i.tint):this._img;i.tint&&p?e.drawImage(p,h,c):e.drawImage(this._img,h,c,d,u),e.restore()}_tinted(e,t,i,s){const r=`${t}x${i}:${s}`;if(this._tintCanvas&&this._tintKey===r)return this._tintCanvas;const n=e.canvas.ownerDocument;let o=null;if(n&&"function"==typeof n.createElement&&(o=n.createElement("canvas")),!o)return null;o.width=t,o.height=i;const a=o.getContext("2d");return a&&null!==this._img?(a.clearRect(0,0,t,i),a.drawImage(this._img,0,0,t,i),a.globalCompositeOperation="source-in",a.fillStyle=s,a.fillRect(0,0,t,i),this._tintCanvas=o,this._tintKey=r,o):null}}class $t{constructor(e={}){Object.defineProperty(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_position",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_my",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_scale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_btnW",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_qtyW",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_h",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_buyLabel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sellLabel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_showPrices",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_qty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_buyColor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sellColor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bid",{enumerable:!0,configurable:!0,writable:!0,value:NaN}),Object.defineProperty(this,"_ask",{enumerable:!0,configurable:!0,writable:!0,value:NaN}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_sellRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_buyRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_qtyRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._id=e.id??"trade",this._position=e.position??"top-left";const t=e.margin??12;this._mx="number"==typeof t?t:t.x,this._my="number"==typeof t?t:t.y,this._buyLabel=e.buyLabel??"BUY",this._sellLabel=e.sellLabel??"SELL",this._showPrices=e.showPrices??!0,this._scale=Math.max(.6,Math.min(1.5,e.scale??1)),this._btnW=74*this._scale,this._qtyW=40*this._scale,this._h=42*this._scale,this._qty=void 0!==e.qty?String(e.qty):"",this._buyColor=e.buyColor,this._sellColor=e.sellColor}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setPrices(e,t){this._bid=e,this._ask=t,this._host?.requestUpdate()}setMark(e){this.setPrices(e,e)}setQty(e){this._qty=String(e),this._host?.requestUpdate()}setColors(e,t){this._buyColor=e,this._sellColor=t,this._host?.requestUpdate()}_origin(e,t){const i=2*this._btnW+this._qtyW+2,s=this._mx,r=e-this._mx-i,n=this._my,o=t-this._my-this._h;switch(this._position){case"top-right":return{x:r,y:n,w:i};case"bottom-left":return{x:s,y:o,w:i};case"bottom-right":return{x:r,y:o,w:i};case"center":return{x:(e-i)/2,y:(t-this._h)/2,w:i};default:return{x:s,y:n,w:i}}}draw(e,t){this._sellRect=this._buyRect=this._qtyRect=null;const i=t.dpr,s=this._origin(t.plotWidth,t.plotHeight),r=this._sellColor??t.theme.sell,n=this._buyColor??t.theme.buy;this._sellRect={x:s.x,y:s.y,w:this._btnW,h:this._h},this._qtyRect={x:s.x+this._btnW+1,y:s.y,w:this._qtyW,h:this._h},this._buyRect={x:s.x+this._btnW+this._qtyW+2,y:s.y,w:this._btnW,h:this._h},e.save(),e.shadowColor="rgba(0,0,0,0.35)",e.shadowBlur=8*i,e.shadowOffsetY=2*i;const o=(e,i)=>null!==e&&t.hoverId===`${this._id}:${i}`;this._drawButton(e,this._sellRect,i,o(this._sellRect,"sell")?je(r,.12):r,this._sellLabel,this._showPrices?this._fmt(t,this._bid):"","left");const a="transparent"===t.theme.background?je(r,-.6):t.theme.grid;this._drawChip(e,this._qtyRect,i,a,this._qty||"—",t.theme.axisText),this._drawButton(e,this._buyRect,i,o(this._buyRect,"buy")?je(n,.12):n,this._buyLabel,this._showPrices?this._fmt(t,this._ask):"","right"),e.restore()}_fmt(e,t){return Number.isNaN(t)?"":e.priceScale.format(t)}_drawButton(e,t,i,s,r,n,o){const a=7*this._scale*i;e.beginPath(),this._roundedSide(e,t.x*i,t.y*i,t.w*i,t.h*i,a,o),e.fillStyle=s,e.fill();const l=Ce(s);e.textAlign="center";const h=(t.x+t.w/2)*i;""!==n?(e.fillStyle=l,e.font=10*this._scale*i+"px system-ui, sans-serif",e.textBaseline="alphabetic",e.fillText(n,h,(t.y+t.h*(18/42))*i),e.font=`700 ${12*this._scale*i}px system-ui, sans-serif`,e.fillText(r,h,(t.y+t.h*(33/42))*i)):(e.fillStyle=l,e.font=`700 ${13*this._scale*i}px system-ui, sans-serif`,e.textBaseline="middle",e.fillText(r,h,(t.y+t.h/2)*i))}_drawChip(e,t,i,s,r,n){e.beginPath(),e.rect(t.x*i,t.y*i,t.w*i,t.h*i),e.fillStyle=s,e.fill(),e.fillStyle=n,e.font=`600 ${13*this._scale*i}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,(t.x+t.w/2)*i,(t.y+t.h/2)*i)}_roundedSide(e,t,i,s,r,n,o){const a=e;if("function"==typeof a.roundRect){const e="left"===o?[n,0,0,n]:[0,n,n,0];a.roundRect(t,i,s,r,e)}else Le(e,t,i,s,r,n)}hitTest(e,t,i){const s=i=>null!==i&&e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h;return s(this._buyRect)?{externalId:`${this._id}:buy`,zOrder:"top",distance:0,cursor:"pointer"}:s(this._sellRect)?{externalId:`${this._id}:sell`,zOrder:"top",distance:0,cursor:"pointer"}:s(this._qtyRect)?{externalId:`${this._id}:qty`,zOrder:"top",distance:0,cursor:"pointer"}:null}}function Ht(e,t){if(t<=0)throw new Error("openalgo-charts: EMA period must be > 0");const i=[];if(0===e.length)return i;const s=2/(t+1);let r=e[0];i.push(r);for(let t=1;t<e.length;t++)r=e[t]*s+r*(1-s),i.push(r);return i}function qt(e,t){const i=Ht(e.map(e=>e.close),t);return e.map((e,t)=>({time:e.time,open:i[t],high:i[t],low:i[t],close:i[t]}))}function Et(e,t=14){if(t<=0)throw new Error("openalgo-charts: RSI period must be > 0");const i=e.length,s=new Array(i).fill(NaN);if(i<=t)return s;let r=0,n=0;for(let i=1;i<=t;i++){const t=e[i]-e[i-1];t>=0?r+=t:n-=t}let o=r/t,a=n/t;s[t]=0===a?100:100-100/(1+o/a);for(let r=t+1;r<i;r++){const i=e[r]-e[r-1];o=(o*(t-1)+(i>0?i:0))/t,a=(a*(t-1)+(i<0?-i:0))/t,s[r]=0===a?100:100-100/(1+o/a)}return s}function Ut(e,t=14){const i=Et(e.map(e=>e.close),t);return e.map((e,t)=>({time:e.time,open:i[t],high:i[t],low:i[t],close:i[t]}))}function Vt(e,t,i){const s=e.length,r=new Array(s);if(0===s)return r;r[0]=e[0]-t[0];for(let n=1;n<s;n++){const s=e[n]-t[n],o=Math.abs(e[n]-i[n-1]),a=Math.abs(t[n]-i[n-1]);r[n]=Math.max(s,o,a)}return r}function Yt(e,t,i,s=14){if(s<=0)throw new Error("openalgo-charts: ATR period must be > 0");const r=Vt(e,t,i),n=r.length,o=new Array(n).fill(NaN);if(n<s)return o;let a=0;for(let e=0;e<s;e++)a+=r[e];let l=a/s;o[s-1]=l;for(let e=s;e<n;e++)l=(l*(s-1)+r[e])/s,o[e]=l;return o}function Gt(e,t=10,i=3){const s=e.length,r=e.map(()=>({value:NaN,direction:1})),n=e.map(e=>e.high),o=e.map(e=>e.low),a=e.map(e=>e.close),l=Yt(n,o,a,t);let h=NaN,c=NaN,d=NaN,u=!1;for(let e=0;e<s;e++){if(!Number.isFinite(l[e]))continue;const t=(n[e]+o[e])/2,s=t+i*l[e],p=t-i*l[e],_=u?s<h||a[e-1]>h?s:h:s,f=u?p>c||a[e-1]<c?p:c:p;let b,m;u&&d!==h?a[e]>=f?(b=f,m=-1):(b=_,m=1):a[e]<=_?(b=_,m=1):(b=f,m=-1),r[e]={value:b,direction:m},h=_,c=f,d=b,u=!0}return r}function Kt(e,t=10,i=3){const s=Gt(e,t,i),r=(e,t)=>({time:e,open:t,high:t,low:t,close:t}),n=[],o=[];for(let t=0;t<e.length;t++){const i=s[t],a=Number.isFinite(i.value);n.push(r(e[t].time,a&&-1===i.direction?i.value:NaN)),o.push(r(e[t].time,a&&1===i.direction?i.value:NaN))}return{up:n,down:o}}function Xt(e){if("number"==typeof e)return e>1e12?G(e):Math.floor(e);const t=Number(e);return""===e.trim()||Number.isNaN(t)||/[-T :]/.test(e.trim())?K(e):t>1e12?G(t):Math.floor(t)}function Jt(e){const t=e.data??[],i=[];for(const e of t){const t=e.timestamp??e.time;void 0!==t&&i.push({time:Xt(t),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})}return i.sort((e,t)=>e.time-t.time)}class Qt{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fetch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._config=e;const t=e.fetchImpl??("undefined"!=typeof fetch?fetch.bind(globalThis):void 0);if(void 0===t)throw new Error("openalgo-charts: no fetch available; pass config.fetchImpl");this._fetch=t}async getBars(e){if(void 0===e.from||void 0===e.to)throw new Error("openalgo-charts: getBars requires `from` and `to` (UTC seconds) — OpenAlgo history needs a date range");const t=await this._fetch(`${this._config.baseUrl}/api/v1/history`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this._config.apiKey,symbol:e.symbol,exchange:e.exchange,interval:e.interval,start_date:ee(e.from),end_date:ee(e.to)})});if(!t.ok)throw new Error(`openalgo-charts: history request failed (${t.status})`);return Jt(await t.json())}}const Zt={LTP:1,Quote:2,Depth:3};function ei(){return JSON.stringify({action:"subscribe_orders"})}function ti(e,t,i,s){const r={action:"subscribe",symbol:t,exchange:i,mode:Zt[e]};return"Depth"===e&&void 0!==s&&(r.depth_level=s),JSON.stringify(r)}function ii(e,t,i){return JSON.stringify({action:"unsubscribe",symbol:t,exchange:i,mode:Zt[e]})}function si(e){if("number"==typeof e)return e>1e12?G(e):Math.floor(e);if("string"==typeof e&&""!==e.trim()){const t=Date.parse(e);if(!Number.isNaN(t))return Math.floor(t/1e3)}return 0}function ri(e){if("object"!=typeof e||null===e)return null;const t=e,i=t.data??t,s=i.symbol??"",r=i.exchange??"";if(i.depth&&(i.depth.buy||i.depth.sell)){const e=(i.depth.buy??[]).map(e=>({price:e.price,qty:e.quantity}));return{kind:"depth",symbol:s,exchange:r,depth:{bids:e,asks:(i.depth.sell??[]).map(e=>({price:e.price,qty:e.quantity})),ltp:i.ltp??i.last_price??e[0]?.price??0}}}const n=i.ltp??i.last_price;return"number"==typeof n?{kind:"ltp",event:{symbol:s,exchange:r,ltp:n,ltq:i.last_trade_quantity??i.ltq,volume:i.volume,timeSec:si(i.timestamp)}}:null}class ni{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_factory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sock",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_open",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_queue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_ltpCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_depthCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_stateCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_controlCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_orderCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_ordersSubscribed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_subs",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_userClosed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_attempts",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_reconnectTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resubscribeOnOpen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_rc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._config=e;const t=e.socketFactory??(e=>new WebSocket(e));this._factory=t;const i=e.reconnect??{};this._rc={enabled:i.enabled??!0,baseDelayMs:i.baseDelayMs??1e3,maxDelayMs:i.maxDelayMs??3e4,maxAttempts:i.maxAttempts??1/0}}connect(){if(null!==this._sock)return;this._emitState("connecting");const e=this._factory(this._config.url);e.onmessage=e=>this._dispatch(e.data),e.onopen=()=>this._onOpen(),e.onclose=()=>this._onClose(),e.onerror=()=>this._emitState("error"),this._sock=e,1===e.readyState&&this._onOpen()}onState(e){return this._stateCbs.add(e),()=>this._stateCbs.delete(e)}onControl(e){return this._controlCbs.add(e),()=>this._controlCbs.delete(e)}_emitState(e){for(const t of this._stateCbs)t(e)}_onOpen(){var e;if(!this._open&&(this._open=!0,this._attempts=0,this._emitState("open"),this._sock?.send((e=this._config.apiKey,JSON.stringify({action:"authenticate",api_key:e}))),this._flush(),this._resubscribeOnOpen)){this._resubscribeOnOpen=!1;for(const e of this._subs.values())this._sock?.send(ti(e.mode,e.symbol,e.exchange,e.depthLevel));this._ordersSubscribed&&this._sock?.send(ei())}}_onClose(){this._open=!1,this._emitState("closed"),this._maybeReconnect()}_maybeReconnect(){if(this._userClosed||!this._rc.enabled||this._attempts>=this._rc.maxAttempts)return;const e=this._attempts++,t=Math.min(this._rc.maxDelayMs,this._rc.baseDelayMs*2**e);this._emitState("reconnecting"),this._reconnectTimer=setTimeout(()=>{this._reconnectTimer=null,this._sock=null,this._open=!1,this._resubscribeOnOpen=this._subs.size>0||this._ordersSubscribed,this.connect()},t)}_send(e){null!==this._sock&&this._open?this._sock.send(e):this._queue.push(e)}_flush(){if(null!==this._sock){for(const e of this._queue)this._sock.send(e);this._queue.length=0}}onLtp(e){return this._ltpCbs.add(e),()=>this._ltpCbs.delete(e)}onDepth(e){return this._depthCbs.add(e),()=>this._depthCbs.delete(e)}subscribe(e,t,i,s){this._subs.set(`${e}:${t}:${i}`,{mode:e,symbol:t,exchange:i,depthLevel:s}),this._send(ti(e,t,i,s))}unsubscribe(e,t,i){this._subs.delete(`${e}:${t}:${i}`),this._send(ii(e,t,i))}onOrderUpdate(e){return this._orderCbs.add(e),()=>this._orderCbs.delete(e)}subscribeOrders(){this._ordersSubscribed=!0,this._send(ei())}unsubscribeOrders(){this._ordersSubscribed=!1,this._send(JSON.stringify({action:"unsubscribe_orders"}))}close(){this._userClosed=!0,null!==this._reconnectTimer&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=null),this._sock?.close(),this._sock=null,this._open=!1,this._queue.length=0}_dispatch(e){let t;try{t=JSON.parse(e)}catch{t=e}if(function(e){return"ping"===e||"object"==typeof e&&null!==e&&"ping"===e.type}(t))return void this._sock?.send(JSON.stringify({action:"pong"}));const i=function(e){if("object"!=typeof e||null===e)return null;const t=e;if("order_update"!==t.type)return null;const i=e=>{if("number"==typeof e)return e;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isNaN(t)?0:t}return 0},s=e=>"string"==typeof e?e:"",r=i(t.trigger_price);return{orderId:s(t.orderid),symbol:s(t.symbol),exchange:s(t.exchange),action:"SELL"===t.action?"SELL":"BUY",quantity:i(t.quantity),price:i(t.price),triggerPrice:r>0?r:void 0,pricetype:""===s(t.pricetype)?"LIMIT":s(t.pricetype),product:s(t.product),status:s(t.order_status).toLowerCase(),filledQuantity:i(t.filled_quantity),pendingQuantity:i(t.pending_quantity),averagePrice:i(t.average_price),rejectionReason:s(t.rejection_reason),mode:s(t.mode)}}(t);if(null!==i){for(const e of this._orderCbs)e(i);return}const s=ri(t);if(null!==s)if("ltp"===s.kind)for(const e of this._ltpCbs)e(s.event);else for(const e of this._depthCbs)e(s.symbol,s.exchange,s.depth);else if("object"==typeof t&&null!==t)for(const e of this._controlCbs)e(t)}}class oi{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fetch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_strategy",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_defaultProduct",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this._config=e,this._strategy=e.strategy??"openalgo-charts",this._defaultProduct=e.defaultProduct??"MIS";const t=e.fetchImpl??("undefined"!=typeof fetch?fetch.bind(globalThis):void 0);if(void 0===t)throw new Error("openalgo-charts: no fetch available; pass config.fetchImpl");this._fetch=t}async _post(e,t){const i=await this._fetch(`${this._config.baseUrl}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this._config.apiKey,...t})});if(!i.ok){let t="";try{const e=await i.json();"string"==typeof e.message&&""!==e.message&&(t=`: ${e.message}`)}catch{}throw new Error(`openalgo-charts: ${e} failed (${i.status})${t}`)}return i.json()}async place(e){const t={symbol:e.symbol,exchange:e.exchange??"NSE",action:e.side,pricetype:e.type,product:e.product??this._defaultProduct,quantity:e.qty},i=await this._post("/api/v1/placeorder",{strategy:this._strategy,symbol:t.symbol,action:t.action,exchange:t.exchange,pricetype:t.pricetype,product:t.product,quantity:e.qty,price:e.price??0,trigger_price:e.triggerPrice??0,disclosed_quantity:0}),s=i.orderid??i.order_id;if(void 0===s)throw new Error("openalgo-charts: placeorder returned no orderid");return this._ctx.set(s,t),{orderId:s}}async modify(e,t){const i=this._ctx.get(e);if(void 0===i)throw new Error(`openalgo-charts: cannot modify ${e} — unknown order context (place it or load the order book first)`);void 0!==t.qty&&(i.quantity=t.qty),await this._post("/api/v1/modifyorder",{orderid:e,strategy:this._strategy,symbol:i.symbol,action:i.action,exchange:i.exchange,pricetype:i.pricetype,product:i.product,quantity:i.quantity,price:t.price??0,trigger_price:t.triggerPrice??0,disclosed_quantity:0})}async cancel(e){await this._post("/api/v1/cancelorder",{orderid:e,strategy:this._strategy})}async getOrders(){const e=await this._post("/api/v1/orderbook",{}),t=Array.isArray(e.data)?e.data:e.data?.orders??[],i=t.map(hi);for(const e of t)e.orderid&&this._ctx.set(e.orderid,{symbol:e.symbol??"",exchange:e.exchange??"NSE",action:e.action??"BUY",pricetype:e.pricetype??"LIMIT",product:e.product??this._defaultProduct,quantity:ai(e.quantity)});return i}async getPositions(){return((await this._post("/api/v1/positionbook",{})).data??[]).map(ci)}}function ai(e){if("number"==typeof e)return e;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isNaN(t)?0:t}return 0}const li={open:"working",pending:"pending",trigger_pending:"working","trigger pending":"working",complete:"filled",cancelled:"cancelled",rejected:"rejected"};function hi(e){return{id:e.orderid??"",symbol:e.symbol??"",side:"SELL"===e.action?"SELL":"BUY",type:e.pricetype??"LIMIT",qty:ai(e.quantity),filledQty:ai(e.filled_quantity),price:ai(e.price),triggerPrice:void 0!==e.trigger_price&&ai(e.trigger_price)>0?ai(e.trigger_price):void 0,status:li[(e.order_status??"").toLowerCase()]??"working"}}function ci(e){return{symbol:e.symbol??"",netQty:ai(e.quantity),avgPrice:ai(e.average_price)}}function di(e){const t=/^(\d*)\s*([smhdw])$/i.exec(e.trim());if(null===t)return 60;const i=""===t[1]?1:Number(t[1]),s=t[2].toLowerCase();return i*("s"===s?1:"m"===s?60:"h"===s?3600:"d"===s?86400:604800)}class ui{constructor(e){Object.defineProperty(this,"_rest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ws",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_volumeMode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._rest=new Qt(e),this._ws=new ni({url:e.wsUrl,apiKey:e.apiKey,socketFactory:e.socketFactory}),this._volumeMode=e.volumeMode??"ltq-sum",this._ws.connect()}getBars(e){return this._rest.getBars(e)}subscribeBars(e,t,i){const s=new Wt({intervalSec:di(e.interval),volumeMode:this._volumeMode});i?.seedFrom&&s.seed(i.seedFrom,i.cumDayVolumeSoFar);const r=this._ws.onLtp(i=>{if(i.symbol!==e.symbol)return;if(i.exchange&&e.exchange&&i.exchange!==e.exchange)return;const r=i.timeSec&&i.timeSec>0?i.timeSec:Math.floor(Date.now()/1e3),n=s.onTick({time:r,price:i.ltp,ltq:i.ltq,cumDayVolume:i.volume});null!==n&&t(n.bar)});return this._ws.subscribe("LTP",e.symbol,e.exchange),()=>{r(),this._ws.unsubscribe("LTP",e.symbol,e.exchange)}}subscribeDepth(e,t){const i=this._ws.onDepth((i,s,r)=>{i===e.symbol&&(s&&e.exchange&&s!==e.exchange||t(r))});return this._ws.subscribe("Depth",e.symbol,e.exchange),()=>{i(),this._ws.unsubscribe("Depth",e.symbol,e.exchange)}}close(){this._ws.close()}}const pi=(e,t)=>{const i=setInterval(e,t);return()=>clearInterval(i)};class _i{constructor(e=60,t=pi){Object.defineProperty(this,"intervalSec",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_schedule",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.intervalSec=e,this._schedule=t}async getBars(e){return fi(e.from??17e8,500,this.intervalSec)}subscribeBars(e,t,i){let s=e.from??17e8,r=100,n=19088743;const o=()=>(n^=n<<13,n>>>=0,n^=n>>17,n^=n<<5,n>>>=0,n/4294967295);return this._schedule(()=>{s+=this.intervalSec;const e=r,i=Math.max(1,e+2*(o()-.5)),n=Math.max(e,i)+o(),a=Math.max(.01,Math.min(e,i)-o());t({time:s,open:e,high:n,low:a,close:i,volume:Math.round(1e3+9e3*o())}),r=i},i?.tickMs??1e3)}}function fi(e,t,i){const s=[];let r=100,n=2654435769;const o=()=>(n^=n<<13,n>>>=0,n^=n>>17,n^=n<<5,n>>>=0,n/4294967295);for(let n=0;n<t;n++){const t=2*(o()-.5),a=r,l=Math.max(1,a+t),h=Math.max(a,l)+o(),c=Math.min(a,l)-o();s.push({time:e+n*i,open:a,high:h,low:c,close:l,volume:Math.round(1e3+9e3*o())}),r=l}return s}function bi(e,t){if("interval"===e.mode){const i=e.anchorSec??0;return i+Math.floor((t-i)/e.seconds)*e.seconds}return 0}class mi{constructor(e){Object.defineProperty(this,"_tf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cur",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_count",{enumerable:!0,configurable:!0,writable:!0,value:0}),this._tf=e}current(){return null===this._cur?null:{...this._cur}}onTick(e){const t=null===this._cur;let i=t;if(t||null===this._cur||(i="interval"===this._tf.mode?bi(this._tf,e.time)!==this._cur.time:"ticks"===this._tf.mode?this._count>=this._tf.count:(this._cur.volume??0)>=this._tf.perBar),i){const t="interval"===this._tf.mode?bi(this._tf,e.time):e.time;return this._cur={time:t,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.qty},this._count=1,{bar:{...this._cur},isNew:!0}}const s=this._cur;return e.price>s.high&&(s.high=e.price),e.price<s.low&&(s.low=e.price),s.close=e.price,s.volume=(s.volume??0)+e.qty,this._count+=1,{bar:{...s},isNew:!1}}}export{et as ALT_PRESET,tt as BUILTIN_COMMANDS,$t as BuySellButtons,Be as CHART_STATE_VERSION,Wt as CandleBuilder,Ft as Chart,Nt as DEFAULT_CANDLE_BUILDER_OPTIONS,P as DEFAULT_CANDLE_STYLE,k as DEFAULT_HISTOGRAM_STYLE,Ze as DEFAULT_KEYMAP,b as DEFAULT_PRICE_SCALE_OPTIONS,ue as DEFAULT_THEME,Tt as DEFAULT_TIME_NAVIGATOR_OPTIONS,v as DEFAULT_TIME_SCALE_OPTIONS,nt as DEFAULT_TRADING_COLORS,yt as EventMarkers,_i as FakeDataFeed,pe as INDICATOR_LINE_STYLES,me as INDICATOR_SOURCES,Y as IST_OFFSET_SECONDS,Te as IndicatorFill,i as InvalidationLevel,zt as LogoWatermark,Qt as OpenAlgoDataFeed,ui as OpenAlgoLiveDataFeed,oi as OpenAlgoTradeFeed,ni as OpenAlgoWsFeed,he as Pane,Ot as PaneLegend,rt as PriceLine,g as PriceScale,gt as SeriesMarkers,st as ShortcutManager,mi as TickBarAggregator,Mt as TimeNavigator,y as TimeScale,dt as TradeMarkersPrimitive,ut as TradingController,e as VERSION,Yt as atr,m as autoscaleRange,le as bestHit,o as bitmapSize,h as clamp,kt as compactVolume,U as conflateBars,V as conflateItems,q as conflationGroupSize,Rt as createChart,ce as darkTheme,mt as drawShape,bt as effectiveMarkerPx,Ht as ema,qt as emaSeries,G as epochMsToUtcSeconds,Xe as eventToCombo,Ke as formatCombo,ie as formatIstDate,Q as formatIstTime,Z as formatIstTimeSeconds,ti as formatSubscribe,ii as formatUnsubscribe,fi as generateBars,z as getChartType,ye as getIndicator,we as hasIndicator,Pe as indicatorDefaults,fe as indicatorStyleInputs,di as intervalToSeconds,re as isNewIstDay,Qe as isReservedCombo,Ye as isValidCombo,Ne as isWhitespace,K as istStringToUtcSeconds,c as lerp,de as lightTheme,Jt as mapHistoryResponse,hi as mapOrder,ci as mapPosition,ft as markerSizePx,E as mergeBars,_ as niceTicks,Ve as normalizeCombo,S as optimalBarWidth,Ue as parseCombo,ri as parseMessage,_e as plotStyleKeys,f as precisionForStep,D as registerChartType,ve as registerIndicator,$ as registeredChartTypes,xe as registeredIndicators,d as roundToTick,Xt as rowTimeToUtcSeconds,Et as rsi,Ut as rsiSeries,a as snapToDevicePixel,Se as sourceValue,Oe as sourceValues,Gt as supertrend,Kt as supertrendSeries,We as toBar,Vt as trueRange,ee as utcSecondsToIstDateString,X as utcSecondsToIstParts,t as version,I as verticalGradient,Dt as watermarkRect};
|
|
1
|
+
const e="1.0.23";function t(){return e}const i={None:0,Cursor:1,Light:2,Full:3};class s{constructor(e=i.None){Object.defineProperty(this,"_globalLevel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_panes",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_timeScaleOps",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._globalLevel=e}get globalLevel(){return this._globalLevel}invalidateGlobal(e){e>this._globalLevel&&(this._globalLevel=e)}invalidatePane(e,t){var i,s;this._panes.set(e,(i=this._panes.get(e),s=t,void 0===i?{...s}:{level:Math.max(i.level,s.level),autoScale:i.autoScale||s.autoScale}))}paneInvalidation(e){return this._panes.get(e)}panes(){return this._panes}addTimeScaleOp(e){this._timeScaleOps.push(e)}timeScaleOps(){return this._timeScaleOps}isEmpty(){return this._globalLevel===i.None&&0===this._panes.size&&0===this._timeScaleOps.length}merge(e){this.invalidateGlobal(e._globalLevel);for(const[t,i]of e._panes)this.invalidatePane(t,i);e._timeScaleOps.length>0&&(this._timeScaleOps=this._timeScaleOps.concat(e._timeScaleOps))}}const r=()=>{};class o{constructor(e,t,i){if(Object.defineProperty(this,"_onFrame",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_schedule",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cancel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_handle",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._onFrame=e,t)this._schedule=t,this._cancel=i??r;else{const e="function"==typeof requestAnimationFrame?{schedule:e=>requestAnimationFrame(e),cancel:e=>cancelAnimationFrame(e)}:{schedule:e=>setTimeout(e,16),cancel:e=>clearTimeout(e)};this._schedule=e.schedule,this._cancel=e.cancel}}get scheduled(){return null!==this._handle}requestFrame(){if(null!==this._handle)return;this._handle=-1;const e=this._schedule(()=>{this._handle=null,this._onFrame()});null!==this._handle&&(this._handle=e)}stop(){null!==this._handle&&(this._cancel(this._handle),this._handle=null)}}function n(e,t,i){return{width:Math.round(e*i),height:Math.round(t*i)}}function a(e,t){return Math.round(e*t)/t}class l{constructor(e,t){Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mediaWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_mediaHeight",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dpr",{enumerable:!0,configurable:!0,writable:!0,value:1}),this.element=e.createElement("canvas");const i=this.element.getContext("2d");if(null===i)throw new Error("openalgo-charts: 2D canvas context is not available");this.ctx=i;const s=this.element.style;s.position="absolute",s.top="0",s.left="0",s.width="100%",s.height="100%",s.zIndex=String(t)}get mediaWidth(){return this._mediaWidth}get mediaHeight(){return this._mediaHeight}get pixelRatio(){return this._dpr}resize(e,t,i){if(e===this._mediaWidth&&t===this._mediaHeight&&i===this._dpr)return;this._mediaWidth=e,this._mediaHeight=t,this._dpr=i;const s=n(e,t,i);this.element.width=s.width,this.element.height=s.height,this.element.style.width=`${e}px`,this.element.style.height=`${t}px`}clearBitmap(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.element.width,this.element.height)}}function h(e,t,i){return e<t?t:e>i?i:e}function c(e,t,i){return e+(t-e)*i}function d(e,t){return t<=0?e:Math.round(e/t)*t}function u(e){const t=Math.floor(Math.log10(e)),i=e/Math.pow(10,t);for(const e of[1,2,2.5,5])if(e>i*(1+1e-9))return e*Math.pow(10,t);return 10*Math.pow(10,t)}function p(e,t,i){const s=Math.ceil(e/i)*i,r=Math.floor(t/i)*i;return Math.round((r-s)/i)+1}function _(e,t,i=6){if(!isFinite(e)||!isFinite(t)||t<=e)return[Number.isFinite(e)?e:0];let s=function(e){if(e<=0)return 0;const t=Math.floor(Math.log10(e)),i=e/Math.pow(10,t);let s;return s=i<1.5?1:i<3?2:i<7?5:10,s*Math.pow(10,t)}((t-e)/Math.max(1,i-1));if(!(s>0))return[e];for(let r=0;r<20&&p(e,t,s)>i;r++)s=u(s);const r=Math.ceil(e/s)*s,o=Math.floor(t/s)*s,n=[],a=Math.round((o-r)/s)+1;for(let e=0;e<a&&e<1e3;e++){const t=r+e*s;n.push(Math.abs(t)<s/1e6?0:t)}return n}function f(e){return e<=0||!isFinite(e)?2:e>=1?0:Math.min(8,Math.ceil(-Math.log10(e)))}const b={marginTop:.1,marginBottom:.1,minMove:0,mode:"linear",inverted:!1};function m(e,t,i,s){if(!isFinite(e)||!isFinite(t))return{min:0,max:1};if(t<=e){const i=Math.abs(t)>0?.05*Math.abs(t):.5;return{min:e-i,max:t+i}}const r=t-e;return{min:e-r*s,max:t+r*i}}class g{constructor(e={}){Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_min",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_max",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_autoScale",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_scaled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_priceFormatter",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._options={...b,...e}}get options(){return this._options}setOptions(e){this._options={...this._options,...e}}setHeight(e){this._height=e}get height(){return this._height}setPriceRange(e){this._min=e.min,this._max=e.max,this._scaled=!0}get scaled(){return this._scaled}priceRange(){return{min:this._min,max:this._max}}get autoScale(){return this._autoScale}setAutoScale(e){this._autoScale=e}scaleAroundCenter(e){const t=(this._min+this._max)/2,i=(this._max-this._min)/2*e;this._min=t-i,this._max=t+i,this._autoScale=!1}panByPixels(e){if(this._height<=0||0===e)return;const t=this._t(this._min),i=this._t(this._max),s=i-t;if(!(s>0))return;const r=s*((this._options.inverted?-e:e)/this._height);this._min=this._tInv(t+r),this._max=this._tInv(i+r),this._autoScale=!1}autoscale(e,t){this.setPriceRange(m(e,t,this._options.marginTop,this._options.marginBottom))}_t(e){return"logarithmic"===this._options.mode?Math.log10(Math.max(1e-10,e)):e}_tInv(e){return"logarithmic"===this._options.mode?Math.pow(10,e):e}priceToY(e){const t=this._t(this._min),i=this._t(this._max)-t;if(i<=0)return this._height/2;const s=(this._t(e)-t)/i;return this._options.inverted?this._height*s:this._height*(1-s)}yToPrice(e){const t=this._t(this._min),i=this._t(this._max)-t,s=this._options.inverted?e/this._height:1-e/this._height;return this._tInv(t+s*i)}precision(){return this._options.minMove>0?f(this._options.minMove):f((this._max-this._min)/100)}snapToTick(e){const t=this._options.minMove;return t<=0?e:Math.round(e/t)*t}setPriceFormatter(e){this._priceFormatter=e}format(e){return null!==this._priceFormatter?this._priceFormatter(e):e.toFixed(this.precision())}clampY(e){return h(e,0,this._height)}}const v={barSpacing:8,minBarSpacing:1,maxBarSpacing:80,rightOffset:4};class y{constructor(e={}){Object.defineProperty(this,"_barSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rightOffset",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_minBarSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maxBarSpacing",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_baseIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:null});const t={...v,...e};this._barSpacing=t.barSpacing,this._rightOffset=t.rightOffset,this._minBarSpacing=t.minBarSpacing,this._maxBarSpacing=t.maxBarSpacing}setWidth(e){this._width=e}get width(){return this._width}get barSpacing(){return this._barSpacing}setBarSpacing(e){this._barSpacing=h(e,this._minBarSpacing,this._maxBarSpacing)}get rightOffset(){return this._rightOffset}setRightOffset(e){this._rightOffset=e}setBaseIndex(e){this._baseIndex=e}_rightEdgeIndex(){return this._baseIndex+this._rightOffset}indexToX(e){return this._width-(this._rightEdgeIndex()-e)*this._barSpacing}xToIndex(e){return this._rightEdgeIndex()-(this._width-e)/this._barSpacing}visibleRange(){const e=this._rightEdgeIndex();return{from:e-this._width/this._barSpacing,to:e}}getVisibleLogicalRange(){return this.visibleRange()}setVisibleLogicalRange(e){if(this._width<=0)return;const t=e.to-e.from;t>0&&(this.setBarSpacing(this._width/t),this._rightOffset=e.to-this._baseIndex,this._onChange?.())}setChangeHandler(e){this._onChange=e}scrollByPixels(e){this._rightOffset-=e/this._barSpacing}zoomAtX(e,t){const i=this.xToIndex(e),s=this._barSpacing;if(this.setBarSpacing(s*t),this._barSpacing===s)return;const r=i+(this._width-e)/this._barSpacing;this._rightOffset=r-this._baseIndex}fitContent(e){if(e<=0||this._width<=0)return;this._baseIndex=e-1,this._rightOffset=v.rightOffset;const t=this._width/(e+this._rightOffset);this.setBarSpacing(t)}}const w=[];class x{constructor(){Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_sortedTimes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_indexByTime",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_nextId",{enumerable:!0,configurable:!0,writable:!0,value:1})}createSeries(){const e=this._nextId++;return this._series.set(e,{bars:[]}),e}removeSeries(e){this._series.delete(e),this._rebuild()}setSeriesData(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);i.bars=function(e){const t=e.slice().sort((e,t)=>e.time-t.time);let i=0;for(let e=0;e<t.length;e++)i>0&&t[e].time===t[i-1].time?t[i-1]=t[e]:t[i++]=t[e];return t.length=i,t}(t),this._rebuild()}addBars(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);if(0===t.length)return;const s=new Map;for(const e of i.bars)s.set(e.time,e);for(const e of t)s.set(e.time,e);i.bars=Array.from(s.values()).sort((e,t)=>e.time-t.time),this._rebuild()}update(e,t){const i=this._series.get(e);if(void 0===i)throw new Error(`openalgo-charts: unknown series ${e}`);const s=i.bars,r=s[s.length-1];if(void 0===r||t.time>r.time){s.push(t);const e=this._sortedTimes.length,i=e>0?this._sortedTimes[e-1]:void 0;return void 0===i||t.time>i?(this._appendTime(t.time),"append"):this._indexByTime.has(t.time)?"replace":(this._rebuild(),"insert")}if(t.time===r.time)return s[s.length-1]=t,"replace";const o=s.findIndex(e=>e.time===t.time);return o>=0?(s[o]=t,"replace"):(this.addBars(e,[t]),"insert")}_appendTime(e){this._indexByTime.has(e)||(this._indexByTime.set(e,this._sortedTimes.length),this._sortedTimes.push(e))}get length(){return this._sortedTimes.length}get baseIndex(){return this._sortedTimes.length-1}indexToTime(e){return this._sortedTimes[e]}timeToIndex(e){return this._indexByTime.get(e)}indexToTimeFloat(e){const t=this._sortedTimes,i=t.length;if(0===i)return NaN;if(1===i)return t[0];if(e<=0)return t[0]+e*(t[1]-t[0]);if(e>=i-1)return t[i-1]+(e-(i-1))*(t[i-1]-t[i-2]);const s=Math.floor(e);return t[s]+(e-s)*(t[s+1]-t[s])}timeToIndexFloat(e){const t=this._sortedTimes,i=t.length;if(0===i)return NaN;if(1===i)return 0;if(e<=t[0]){const i=t[1]-t[0];return i>0?(e-t[0])/i:0}if(e>=t[i-1]){const s=t[i-1]-t[i-2];return s>0?i-1+(e-t[i-1])/s:i-1}let s=0,r=i-1;for(;s<r;){const i=s+r+1>>1;t[i]<=e?s=i:r=i-1}const o=t[s+1]-t[s];return o>0?s+(e-t[s])/o:s}seriesBars(e){return this._series.get(e)?.bars??w}indexedBars(e){const t=this._series.get(e);if(void 0===t)return[];const i=[];for(const e of t.bars){const t=this._indexByTime.get(e.time);void 0!==t&&i.push({index:t,bar:e})}return i}visibleBars(e,t,i){const s=this._series.get(e);if(void 0===s)return[];const r=s.bars,o=Math.max(0,Math.floor(t)),n=Math.min(this.baseIndex,Math.ceil(i));if(n<o||0===r.length)return[];const a=this._sortedTimes[o],l=this._sortedTimes[n];if(void 0===a||void 0===l)return[];let h=0,c=r.length;for(;h<c;){const e=h+c>>1;r[e].time<a?h=e+1:c=e}const d=[];for(let e=h;e<r.length;e++){const t=r[e].time;if(t>l)break;const i=this._indexByTime.get(t);void 0!==i&&d.push({index:i,bar:r[e]})}return d}lastIndexedBar(e){const t=this._series.get(e);if(void 0===t||0===t.bars.length)return null;const i=t.bars[t.bars.length-1],s=this._indexByTime.get(i.time);return void 0===s?null:{index:s,bar:i}}_rebuild(){const e=new Set;for(const t of this._series.values())for(const i of t.bars)e.add(i.time);this._sortedTimes=Array.from(e).sort((e,t)=>e-t),this._indexByTime.clear();for(let e=0;e<this._sortedTimes.length;e++)this._indexByTime.set(this._sortedTimes[e],e)}}const P={upColor:"#26a69a",downColor:"#ef5350",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350",borderVisible:!0,wickVisible:!0};function S(e,t){const i=Math.floor(e*t*.8);let s=Math.max(1,i);if(s>=2){s%2!=Math.max(1,Math.floor(t))%2&&(s-=1)}return Math.max(1,s)}function O(e,t,i,s,r,o=P){const n=S(s,r),a=Math.max(1,Math.floor(r));for(const{x:s,bar:l}of t){const t=l.close>=l.open,h=Math.round(s*r),c=Math.round(i(l.open)*r),d=Math.round(i(l.close)*r),u=Math.round(i(l.high)*r),p=Math.round(i(l.low)*r),_=o.widthScale?Math.max(.05,Math.min(1,o.widthScale(l))):1,f=1===_?n:Math.max(1,Math.round(n*_)),b=Math.floor(f/2);o.wickVisible&&(e.fillStyle=t?o.wickUpColor:o.wickDownColor,e.fillRect(h-Math.floor(a/2),u,a,Math.max(1,p-u)));const m=Math.min(c,d),g=Math.max(1,Math.abs(d-c)),v=t?o.upColor:o.downColor;o.hollow&&t?(e.strokeStyle=v,e.lineWidth=Math.max(1,a),e.strokeRect(h-b+.5,m+.5,f-1,g-1)):(e.fillStyle=v,e.fillRect(h-b,m,f,g),o.borderVisible&&f>=3&&!o.hollow&&(e.strokeStyle=t?o.borderUpColor:o.borderDownColor,e.lineWidth=1,e.strokeRect(h-b+.5,m+.5,f-1,g-1)))}}function T(e,t,i){const s=e.bar;return{cx:Math.round(e.x*i),yOpen:Math.round(t(s.open)*i),yClose:Math.round(t(s.close)*i),yHigh:Math.round(t(s.high)*i),yLow:Math.round(t(s.low)*i),up:s.close>=s.open}}function M(e,t,i,s,r,o,n=!1){const a=Math.max(1,Math.floor(S(s,r)/2)),l=Math.max(1,Math.floor(r));e.save();for(const s of t){const t=T(s,i,r);e.fillStyle=t.up?o.upColor??"#26a69a":o.downColor??"#ef5350",e.fillRect(t.cx-Math.floor(l/2),t.yHigh,l,Math.max(1,t.yLow-t.yHigh)),n||(e.fillRect(t.cx-a,t.yOpen,a,l),e.fillRect(t.cx,t.yClose,a,l))}e.restore()}const C=new WeakMap;function I(e,t,i,s){let r=C.get(e);void 0===r&&(r=new Map,C.set(e,r));const o=`${Math.round(t)}|${i}|${s}`;let n=r.get(o);return void 0===n&&(n=e.createLinearGradient(0,0,0,t),n.addColorStop(0,i),n.addColorStop(1,s),r.set(o,n)),n}function L(e,t,i=e=>e.close){return e.map(e=>({x:e.x,y:t(i(e.bar))}))}function j(e,t,i,s,r){const o=L(t,i),n=r.step?function(e){if(0===e.length)return[];const t=[{...e[0]}];for(let i=1;i<e.length;i++)t.push({x:e[i].x,y:e[i-1].y}),t.push({x:e[i].x,y:e[i].y});return t}(o):o;e.save(),e.strokeStyle=r.color??"#4f8cff",e.lineWidth=Math.max(1,(r.lineWidth??1.5)*s),e.lineJoin="round",e.lineCap="round";const a="dashed"===r.lineStyle?[6*s,4*s]:"dotted"===r.lineStyle?[1*s,3*s]:[];if(e.setLineDash(a),r.markersOnly||function(e,t,i){if(0===t.length)return;e.beginPath();let s=!1;for(const r of t)Number.isFinite(r.x)&&Number.isFinite(r.y)?s?e.lineTo(r.x*i,r.y*i):(e.moveTo(r.x*i,r.y*i),s=!0):s=!1;e.stroke()}(e,n,s),e.setLineDash([]),r.markers||r.markersOnly){const t=(r.markerRadius??2)*s;e.fillStyle=r.color??"#4f8cff";for(const i of o)Number.isFinite(i.x)&&Number.isFinite(i.y)&&(e.beginPath(),e.arc(i.x*s,i.y*s,t,0,2*Math.PI),e.fill())}e.restore()}const k={color:"#3a4666",base:0};function A(e,t,i={}){return{...P,upColor:e.upColor??t.upColor,downColor:e.downColor??t.downColor,borderUpColor:e.borderUpColor??t.upColor,borderDownColor:e.borderDownColor??t.downColor,wickUpColor:e.wickUpColor??t.wickUpColor,wickDownColor:e.wickDownColor??t.wickDownColor,borderVisible:e.borderVisible??P.borderVisible,wickVisible:e.wickVisible??P.wickVisible,...i}}const F=e=>({min:e.low,max:e.high}),R=e=>({min:e.close,max:e.close}),B=(e,t)=>{const i=t.base??0;return{min:Math.min(i,e.close),max:Math.max(i,e.close)}},N=new Map,W=new Set(["point-figure","kagi"]);function D(e,t){N.set(e,t)}function z(e){const t=N.get(e);if(void 0===t){if(W.has(e))throw new Error(`openalgo-charts: series type "${e}" needs the transform tier — import 'openalgo-charts/transform' first`);throw new Error(`openalgo-charts: unknown series type "${e}"`)}return t}function $(){return Array.from(N.keys())}const H=(e,t)=>({...e,upColor:e.upColor??t.upColor,downColor:e.downColor??t.downColor});function q(e,t,i=.5,s=1){const r=e*t;if(r<=0)return 1;const o=i*Math.max(1,s);return r>=o?1:Math.max(1,Math.ceil(o/r))}function E(e){const t=e[0];let i=t.high,s=t.low,r=t.volume??0,o=void 0!==t.volume;for(let t=1;t<e.length;t++){const n=e[t];n.high>i&&(i=n.high),n.low<s&&(s=n.low),void 0!==n.volume&&(r+=n.volume,o=!0)}const n={time:t.time,open:t.open,high:i,low:s,close:e[e.length-1].close};return o&&(n.volume=r),n}function U(e,t){if(t<=1)return e.slice();const i=[];for(let s=0;s<e.length;s+=t)i.push(E(e.slice(s,s+t)));return i}function V(e,t){if(t<=1)return e.map(e=>({x:e.x,bar:e.bar}));const i=[];for(let s=0;s<e.length;s+=t){const r=e.slice(s,s+t),o=r.reduce((e,t)=>e+t.x,0)/r.length;i.push({x:o,bar:E(r.map(e=>e.bar))})}return i}D("candlestick",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>O(e,t,i,s,r,A(o,n.theme)),extents:F}),D("hollow-candle",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>O(e,t,i,s,r,A(o,n.theme,{hollow:!0})),extents:F}),D("volume-candle",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>{const a=n.maxVolume;O(e,t,i,s,r,A(o,n.theme,{widthScale:e=>a>0?(e.volume??0)/a:1}))},extents:F}),D("bar",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>M(e,t,i,s,r,H(o,n.theme)),extents:F}),D("high-low",{defaultStyle:{},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>M(e,t,i,s,r,H(o,n.theme),!0),extents:F}),D("line",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>j(e,t,i,r,{...o,color:o.color??n.theme.lineColor}),extents:R}),D("line-markers",{defaultStyle:{lineWidth:1.5,markers:!0},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>j(e,t,i,r,{...o,color:o.color??n.theme.lineColor,markers:!0}),extents:R}),D("step",{defaultStyle:{lineWidth:1.5,step:!0},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>j(e,t,i,r,{...o,color:o.color??n.theme.lineColor,step:!0}),extents:R}),D("area",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>function(e,t,i,s,r,o){const n=L(t,i);if(0===n.length)return;const a=r*s;e.save(),e.beginPath(),e.moveTo(n[0].x*s,a);for(const t of n)e.lineTo(t.x*s,t.y*s);e.lineTo(n[n.length-1].x*s,a),e.closePath(),e.fillStyle=I(e,a,o.areaTopColor??"rgba(79,140,255,0.40)",o.areaBottomColor??"rgba(79,140,255,0.00)"),e.fill(),e.restore(),j(e,t,i,s,{color:o.color??"#4f8cff",lineWidth:o.lineWidth??1.5})}(e,t,i,r,n.plotHeight,{...o,color:o.color??n.theme.lineColor,areaTopColor:o.areaTopColor??n.theme.areaTopColor,areaBottomColor:o.areaBottomColor??n.theme.areaBottomColor}),extents:R}),D("hlc-area",{defaultStyle:{lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>function(e,t,i,s,r){if(0===t.length)return;const o=L(t,i,e=>e.high),n=L(t,i,e=>e.low);e.save(),e.beginPath(),e.moveTo(o[0].x*s,o[0].y*s);for(const t of o)e.lineTo(t.x*s,t.y*s);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x*s,n[t].y*s);e.closePath(),e.fillStyle=r.areaTopColor??"rgba(79,140,255,0.15)",e.fill(),e.restore(),j(e,t,i,s,{color:r.closeColor??"#4f8cff",lineWidth:r.lineWidth??1.5})}(e,t,i,r,{...o,closeColor:o.closeColor??n.theme.lineColor}),extents:F}),D("baseline",{defaultStyle:{baseValue:0,lineWidth:1.5},isPriceSeries:!0,draw:(e,t,i,s,r,o,n)=>function(e,t,i,s,r){const o=i(r.baseValue??0)*s,n=L(t,i);if(0===n.length)return;const a=n[0].x*s,l=n[n.length-1].x*s,h=()=>{e.beginPath(),e.moveTo(a,o);for(const t of n)e.lineTo(t.x*s,t.y*s);e.lineTo(l,o),e.closePath()},c=r.areaTopColor??"rgba(38,166,154,0.20)",d=r.areaBottomColor??"rgba(239,83,80,0.20)",u=1e5;e.save(),e.beginPath(),e.rect(a,o-u,l-a,u),e.clip(),h(),e.fillStyle=I(e,o,c,"rgba(0,0,0,0)"),e.fill(),e.restore(),e.save(),e.beginPath(),e.rect(a,o,l-a,u),e.clip(),h(),e.fillStyle=d,e.fill(),e.restore(),e.save();for(let t=1;t<n.length;t++){const i=n[t-1],a=n[t],l=(i.y+a.y)/2<=o/s;e.strokeStyle=l?r.topColor??"#26a69a":r.bottomColor??"#ef5350",e.lineWidth=Math.max(1,Math.round((r.lineWidth??1.5)*s)),e.beginPath(),e.moveTo(i.x*s,i.y*s),e.lineTo(a.x*s,a.y*s),e.stroke()}e.restore()}(e,t,i,r,{...o,topColor:o.topColor??n.theme.baselineTopLine,bottomColor:o.bottomColor??n.theme.baselineBottomLine,areaTopColor:o.areaTopColor??n.theme.baselineTopFill,areaBottomColor:o.areaBottomColor??n.theme.baselineBottomFill}),extents:(e,t)=>{const i=t.baseValue??0;return{min:Math.min(i,e.close),max:Math.max(i,e.close)}}}),D("column",{defaultStyle:{base:0},isPriceSeries:!1,draw:(e,t,i,s,r,o,n)=>function(e,t,i,s,r,o){const n=S(s,r),a=Math.floor(n/2),l=Math.round(i(o.base??0)*r);e.save();for(const s of t){const t=T(s,i,r);e.fillStyle=t.up?o.upColor??"#26a69a":o.downColor??"#ef5350";const h=Math.min(l,t.yClose);e.fillRect(t.cx-a,h,n,Math.max(1,Math.abs(l-t.yClose)))}e.restore()}(e,t,i,s,r,H(o,n.theme)),extents:B}),D("histogram",{defaultStyle:{base:0,color:"#3a4666"},isPriceSeries:!1,draw:(e,t,i,s,r,o)=>{!function(e,t,i,s,r,o=k){const n=S(s,r),a=Math.floor(n/2),l=Math.round(i(o.base)*r);let h="";for(const{x:s,bar:c}of t){const t=c.color??o.color;t!==h&&(e.fillStyle=t,h=t);const d=Math.round(s*r),u=Math.round(i(c.close)*r),p=Math.min(l,u),_=Math.max(1,Math.abs(l-u));e.fillRect(d-a,p,n,_)}}(e,t,i,s,r,{color:o.color??"#3a4666",base:o.base??0})},extents:B});const Y=19800;function G(e){return Math.floor(e/1e3)}function K(e){const t=e.trim(),i=/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/.exec(t);if(null===i)throw new Error(`openalgo-charts: unparseable IST time string "${e}"`);const s=Number(i[1]),r=Number(i[2]),o=Number(i[3]),n=void 0!==i[4]?Number(i[4]):0,a=void 0!==i[5]?Number(i[5]):0,l=void 0!==i[6]?Number(i[6]):0,h=Date.UTC(s,r-1,o,n,a,l);return Math.floor(h/1e3)-Y}function X(e){const t=new Date(1e3*(e+Y));return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds(),weekday:t.getUTCDay()}}const J=e=>e<10?`0${e}`:String(e);function Q(e){const t=X(e);return`${J(t.hour)}:${J(t.minute)}`}function Z(e){const t=X(e);return`${J(t.hour)}:${J(t.minute)}:${J(t.second)}`}function ee(e){const t=X(e);return`${t.year}-${J(t.month)}-${J(t.day)}`}const te=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function ie(e){const t=X(e);return`${J(t.day)} ${te[t.month-1]}`}const se=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function re(e,t){const i=X(e),s=X(t);return i.year!==s.year||i.month!==s.month||i.day!==s.day}const oe={textColor:"#8b91a7",lineColor:"#2a3046",font:"11px system-ui, sans-serif"};function ne(e,t){return e.replace(/(\d+(?:\.\d+)?)px/,(e,i)=>Number(i)*t+"px")}function ae(e,t,i,s,r,o,n,a){e.save(),e.font=11*r+"px system-ui, sans-serif";const l=6*r,h=16*r,c=e.measureText(t).width;if(e.fillStyle=o,e.textBaseline="middle","right"===a)e.fillRect(i+1,s-h/2,c+2*l,h),e.fillStyle=n,e.textAlign="left",e.fillText(t,i+1+l,s);else{const r=c+2*l;e.fillRect(i-r/2,s,r,h),e.fillStyle=n,e.textAlign="center",e.fillText(t,i,s+h/2)}e.restore()}function le(e){const t={top:2,normal:1,bottom:0};let i=null;for(const s of e)null!==s&&(null===i||s.distance<i.distance||s.distance===i.distance&&t[s.zOrder]>t[i.zOrder])&&(i=s);return i}class he{constructor(e){Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"base",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"priceScale",{enumerable:!0,configurable:!0,writable:!0,value:new g}),Object.defineProperty(this,"_leftScale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_overlayScale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"weight",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_primitives",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),this.element=e.createElement("div"),this.element.style.position="relative",this.element.style.width="100%",this.element.style.flex="1 1 auto",this.element.style.overflow="hidden",this.element.style.borderTopStyle="solid",this.element.style.borderTopWidth="0px",this.element.style.boxSizing="border-box",this.base=new l(e,0),this.top=new l(e,1),this.element.appendChild(this.base.element),this.element.appendChild(this.top.element)}addSeries(e){this._scaleFor(e.scaleId),this._series.push(e)}_scaleFor(e){return"left"===e?this._leftScale??(this._leftScale=new g):""===e?this._overlayScale??(this._overlayScale=new g):this.priceScale}scaleOf(e){return this._scaleFor(e.scaleId)}hasLeftScale(){return null!==this._leftScale&&this._series.some(e=>"left"===e.scaleId)}removeSeries(e){const t=this._series.indexOf(e);return!(t<0)&&(this._series.splice(t,1),!0)}series(){return this._series}primitives(){return this._primitives}addPrimitive(e,t){this._primitives.push(e),e.attached?.(t)}removePrimitive(e){const t=this._primitives.indexOf(e);return!(t<0)&&(this._primitives.splice(t,1),e.detached?.(),!0)}destroy(){for(const e of this._primitives)e.detached?.();this._primitives.length=0,this.element.remove()}_primitiveContext(e){const t=this._layout(e);return{timeScale:e.timeScale,priceScale:this.priceScale,dataLayer:e.dataLayer,plotWidth:t.plotWidth,plotHeight:t.plotHeight,priceAxisWidth:e.priceAxisWidth,dpr:e.dpr,theme:e.theme,hoverId:e.hoverId??null,dragId:e.dragId??null,bars:()=>{for(const t of this._series)if(z(t.type).isPriceSeries)return e.dataLayer.seriesBars(t.dataId);return[]}}}hitTestPrimitives(e,t,i){const s=this._primitiveContext(i);return le(this._primitives.map(i=>i.hitTest?i.hitTest(e,t,s):null))}resize(e,t,i){this._width=e,this._height=t,this.base.resize(e,t,i),this.top.resize(e,t,i)}setScaleHeights(e){this.priceScale.setHeight(e),this._leftScale?.setHeight(e),this._overlayScale?.setHeight(e)}_layout(e){const t=e.leftAxisWidth??0;return{plotWidth:Math.max(0,this._width-e.priceAxisWidth-t),plotHeight:Math.max(0,this._height-(e.showTimeAxis?e.timeAxisHeight:0)),priceAxisWidth:e.priceAxisWidth,timeAxisHeight:e.showTimeAxis?e.timeAxisHeight:0,plotLeft:t}}autoscale(e){const t=this._layout(e),i=e.timeScale.visibleRange();this._autoscaleScale(this.priceScale,e=>"right"===e.scaleId,!0,e,t.plotHeight,i),this._leftScale&&this._autoscaleScale(this._leftScale,e=>"left"===e.scaleId,!1,e,t.plotHeight,i),this._overlayScale&&this._autoscaleScale(this._overlayScale,e=>""===e.scaleId,!1,e,t.plotHeight,i)}_autoscaleScale(e,t,i,s,r,o){if(e.setHeight(r),!e.autoScale)return;let n=1/0,a=-1/0;for(const e of this._series){if(!1===e.style.visible||!t(e))continue;const i=z(e.type);for(const t of s.dataLayer.visibleBars(e.dataId,o.from,o.to)){const s=i.extents(t.bar,e.style);s.min<n&&(n=s.min),s.max>a&&(a=s.max)}}if(i)for(const e of this._primitives){const t=e.autoscaleInfo?.();t&&(t.min<n&&(n=t.min),t.max>a&&(a=t.max))}n<=a&&e.autoscale(n,a)}paintBase(e){const t=this._layout(e),i=e.dpr,s=this.base.ctx;this.base.clearBitmap();const r={textColor:e.theme.axisText,lineColor:e.theme.axisLine,font:`${e.theme.axisFontSize??11}px system-ui, sans-serif`};if("transparent"!==e.theme.background&&(s.fillStyle=e.theme.background,s.fillRect(0,0,Math.round(this._width*i),Math.round(this._height*i))),this._leftScale&&t.plotLeft>0&&function(e,t,i,s,r,o=oe){const n=t.priceRange(),a=_(n.min,n.max,6),l=Math.round(i*r);e.save(),e.strokeStyle=o.lineColor,e.fillStyle=o.textColor,e.font=ne(o.font,r),e.textAlign="right",e.textBaseline="middle",e.lineWidth=1,e.beginPath(),e.moveTo(l-.5,0),e.lineTo(l-.5,Math.round(s*r)),e.stroke();for(const i of a){const o=Math.round(t.priceToY(i)*r);o<0||o>s*r||e.fillText(t.format(i),l-6*r,o)}e.restore()}(s,this._leftScale,t.plotLeft,t.plotHeight,i,r),s.save(),t.plotLeft>0&&s.translate(Math.round(t.plotLeft*i),0),e.showVertGrid||e.showHorzGrid){const r=function(e,t,i){const s=Math.max(1,i.spacing),r=[];for(let t=s;t<e;t+=s)r.push(t);const o=[];for(let e=s;e<t;e+=s)o.push(e);return{verticals:r,horizontals:o}}(t.plotWidth,t.plotHeight,{spacing:60}),o="dashed"===e.theme.gridStyle?[4*i,4*i]:"dotted"===e.theme.gridStyle?[1*i,3*i]:void 0;!function(e,t,i,s,r,o){e.save(),e.strokeStyle=o.color,e.lineWidth=Math.max(1,Math.round(o.lineWidth*r)),o.dash&&e.setLineDash(o.dash),e.beginPath();const n=Math.round(i*r),l=Math.round(s*r);for(const i of t.verticals){const t=Math.round(a(i,r)*r)+0;e.moveTo(t,0),e.lineTo(t,l)}for(const i of t.horizontals){const t=Math.round(a(i,r)*r)+0;e.moveTo(0,t),e.lineTo(n,t)}e.stroke(),e.restore()}(s,{verticals:e.showVertGrid?r.verticals:[],horizontals:e.showHorzGrid?r.horizontals:[]},t.plotWidth,t.plotHeight,i,{color:e.theme.grid,lineWidth:1,dash:o})}const o=this._primitiveContext(e);for(const e of this._primitives)"bottom"===e.zOrder()&&e.draw(s,o);const n=e.timeScale.visibleRange();let l=null;const h=e.conflate?q(e.timeScale.barSpacing,i,.5,e.conflationFactor):1;for(const r of this._series){if(!1===r.style.visible)continue;const o=this._scaleFor(r.scaleId),a=e=>o.priceToY(e),c=z(r.type);let d=e.dataLayer.visibleBars(r.dataId,n.from,n.to).map(t=>({x:e.timeScale.indexToX(t.index),bar:t.bar}));h>1&&(d=V(d,h));let u=0;for(const e of d)(e.bar.volume??0)>u&&(u=e.bar.volume??0);const p={plotHeight:t.plotHeight,maxVolume:u,theme:e.theme};if(c.draw(s,d,a,e.timeScale.barSpacing,i,r.style,p),c.isPriceSeries&&null===l&&o===this.priceScale){const t=e.dataLayer.lastIndexedBar(r.dataId);null!==t&&(l={close:t.bar.close,up:t.bar.close>=t.bar.open,showLine:!1!==r.style.priceLineVisible,showTag:!1!==r.style.lastValueVisible})}}!function(e,t,i,s,r=oe){const o=t.priceRange(),n=_(o.min,o.max,6),a=Math.round(i.plotWidth*s);e.save(),e.strokeStyle=r.lineColor,e.fillStyle=r.textColor,e.font=ne(r.font,s),e.textAlign="left",e.textBaseline="middle",e.lineWidth=1,e.beginPath(),e.moveTo(a+.5,0),e.lineTo(a+.5,Math.round(i.plotHeight*s)),e.stroke();for(const r of n){const o=Math.round(t.priceToY(r)*s);o<0||o>i.plotHeight*s||e.fillText(t.format(r),a+6*s,o)}e.restore()}(s,this.priceScale,t,i,r),null!==l&&function(e,t,i,s,r,o,n=oe,a={up:"#26a69a",down:"#ef5350",text:"#0d0e12"},l=!0,h=!0){if(!l&&!h)return;const c=Math.round(t.priceToY(i)*o);if(c<0||c>r.plotHeight*o)return;const d=s?a.up:a.down,u=Math.round(r.plotWidth*o);if(e.save(),l&&(e.strokeStyle=d,e.lineWidth=Math.max(1,Math.round(o)),e.setLineDash([3*o,3*o]),e.beginPath(),e.moveTo(0,c+.5),e.lineTo(u,c+.5),e.stroke(),e.setLineDash([])),h){const s=t.format(i);e.font=ne(n.font,o);const r=6*o,l=16*o,h=e.measureText(s).width;e.fillStyle=d,e.fillRect(u+1,c-l/2,h+2*r,l),e.fillStyle=a.text,e.textAlign="left",e.textBaseline="middle",e.fillText(s,u+1+r,c)}e.restore()}(s,this.priceScale,l.close,l.up,t,i,r,{up:e.theme.lastPriceUp,down:e.theme.lastPriceDown,text:e.theme.lastPriceText},l.showLine,l.showTag);for(const e of this._primitives)"normal"===e.zOrder()&&e.draw(s,o);e.showTimeAxis&&function(e,t,i,s,r,o=oe,n){const a=t.visibleRange(),l=Math.max(0,Math.floor(a.from)),h=Math.min(i.baseIndex,Math.ceil(a.to));if(h<l)return;const c=Math.max(1,Math.round(80/Math.max(1,t.barSpacing))),d=Math.round(s.plotHeight*r);let u=Number.POSITIVE_INFINITY;{let e=i.indexToTime(l);for(let t=l+1;t<=h;t++){const s=i.indexToTime(t);if(void 0!==s&&void 0!==e){const t=s-e;t>0&&t<u&&(u=t)}void 0!==s&&(e=s)}}const p=u*c,_=Number.isFinite(p)&&p<60;let f;e.save(),e.fillStyle=o.textColor,e.strokeStyle=o.lineColor,e.font=ne(o.font,r),e.textAlign="center",e.textBaseline="top",e.lineWidth=1,e.beginPath(),e.moveTo(0,d+.5),e.lineTo(Math.round(s.plotWidth*r),d+.5),e.stroke();for(let o=l;o<=h;o+=c){const a=i.indexToTime(o);if(void 0===a)continue;const l=Math.round(t.indexToX(o)*r);if(l<0||l>s.plotWidth*r){f=a;continue}let h;if(n){let e;if(void 0===f)e="day";else{const t=X(f),i=X(a);e=t.year!==i.year?"year":t.month!==i.month?"month":t.day!==i.day?"day":_?"timeWithSeconds":"time"}h=n(a,e)}else h=void 0===f||re(f,a)?ie(a):_?Z(a):Q(a);e.fillText(h,l,d+4*r),f=a}e.restore()}(s,e.timeScale,e.dataLayer,t,i,r,e.timeFormatter),s.restore()}paintTop(e,t){this.top.clearBitmap();const i=this._layout(t),s=this.top.ctx,r=t.dpr;s.save(),i.plotLeft>0&&s.translate(Math.round(i.plotLeft*r),0);const o=this._primitiveContext(t);for(const e of this._primitives)"top"===e.zOrder()&&e.draw(s,o);if(null!==e){const o="solid"===t.theme.crosshairStyle?[]:"dotted"===t.theme.crosshairStyle?[1*r,3*r]:[4*r,4*r];!function(e,t,i,s,r,o,n,a=1,l=[4*o,4*o]){if(e.save(),e.strokeStyle=n,e.lineWidth=Math.max(1,a),e.setLineDash(l),t>=0&&t<=s){const i=Math.round(t*o)+.5;e.beginPath(),e.moveTo(i,0),e.lineTo(i,Math.round(r*o)),e.stroke()}if(null!==i&&i>=0&&i<=r){const t=Math.round(i*o)+.5;e.beginPath(),e.moveTo(0,t),e.lineTo(Math.round(s*o),t),e.stroke()}e.setLineDash([]),e.restore()}(s,e.x,e.yLocal,i.plotWidth,i.plotHeight,r,t.theme.crosshair,t.theme.crosshairWidth??1,o);const n=t.theme.crosshairLabelBackground??t.theme.crosshair,a=!1!==t.theme.crosshairLabelVisible;if(a&&null!==e.yLocal){const o=this.priceScale.yToPrice(e.yLocal);ae(s,this.priceScale.format(o),i.plotWidth*r,e.yLocal*r,r,n,t.theme.lastPriceText,"right")}if(a&&e.showTimeTag&&e.x>=0&&e.x<=i.plotWidth){const o=Math.round(t.timeScale.xToIndex(e.x)),a=t.dataLayer.indexToTime(o);void 0!==a&&ae(s,t.timeFormatter?t.timeFormatter(a):function(e){const t=X(e);let i=`${se[t.weekday]} ${J(t.day)} ${te[t.month-1]} '${String(t.year).slice(-2)}`;return 0===t.hour&&0===t.minute&&0===t.second||(i+=` ${J(t.hour)}:${J(t.minute)}`,0!==t.second&&(i+=`:${J(t.second)}`)),i}(a),e.x*r,i.plotHeight*r,r,n,t.theme.lastPriceText,"bottom")}}s.restore()}yToPrice(e){return this.priceScale.yToPrice(e)}}const ce={background:"#0d0e12",grid:"#161a26",axisText:"#8b91a7",axisLine:"#2a3046",paneSeparator:"#1e2334",crosshair:"#6b7280",upColor:"#26a69a",downColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350",lineColor:"#4f8cff",areaTopColor:"rgba(79,140,255,0.40)",areaBottomColor:"rgba(79,140,255,0.00)",baselineTopLine:"#26a69a",baselineTopFill:"rgba(38,166,154,0.20)",baselineBottomLine:"#ef5350",baselineBottomFill:"rgba(239,83,80,0.20)",lastPriceUp:"#26a69a",lastPriceDown:"#ef5350",lastPriceText:"#0d0e12",buy:"#26a69a",sell:"#ef5350",profit:"#26a69a",loss:"#ef5350"},de={background:"#ffffff",grid:"#eef1f6",axisText:"#5b6472",axisLine:"#d4dae3",paneSeparator:"#e6eaf0",crosshair:"#9aa3b2",upColor:"#089981",downColor:"#e0473e",wickUpColor:"#089981",wickDownColor:"#e0473e",lineColor:"#2962ff",areaTopColor:"rgba(41,98,255,0.30)",areaBottomColor:"rgba(41,98,255,0.00)",baselineTopLine:"#089981",baselineTopFill:"rgba(8,153,129,0.18)",baselineBottomLine:"#e0473e",baselineBottomFill:"rgba(224,71,62,0.18)",lastPriceUp:"#089981",lastPriceDown:"#e0473e",lastPriceText:"#ffffff",buy:"#089981",sell:"#e0473e",profit:"#089981",loss:"#e0473e"},ue=de;const pe=[{label:"Solid",value:"solid"},{label:"Dashed",value:"dashed"},{label:"Dotted",value:"dotted"}];function _e(e){return{color:e.colorKey??`${e.key}:color`,width:`${e.key}:width`,lineStyle:`${e.key}:lineStyle`,opacity:`${e.key}:opacity`,type:`${e.key}:type`}}function fe(e){const t=[];for(const i of e.plots){const s=_e(i),r=e.inputs.find(e=>e.key===i.colorKey),o="string"==typeof r?.default?r.default:i.style?.color??"#4f8cff";t.push({key:s.color,type:"color",label:i.title,default:o,group:i.title}),t.push({key:s.opacity,type:"number",label:"Opacity",default:100,min:0,max:100,step:1,group:i.title}),t.push({key:s.width,type:"number",label:"Thickness",default:i.style?.lineWidth??1.5,min:.5,max:8,step:.5,group:i.title}),t.push({key:s.lineStyle,type:"select",label:"Line style",default:i.style?.lineStyle??"solid",options:pe,group:i.title}),t.push({key:s.type,type:"select",label:"Plot style",default:i.type,options:be,group:i.title})}return t}const be=[{label:"Line",value:"line"},{label:"Line with markers",value:"line-markers"},{label:"Step line",value:"step"},{label:"Area",value:"area"},{label:"Histogram",value:"histogram"},{label:"Columns",value:"column"}],me=[{label:"Close",value:"close"},{label:"Open",value:"open"},{label:"High",value:"high"},{label:"Low",value:"low"},{label:"HL2",value:"hl2"},{label:"HLC3",value:"hlc3"},{label:"OHLC4",value:"ohlc4"}],ge=new Map;function ve(e){ge.set(e.id,e)}function ye(e){const t=ge.get(e);if(void 0===t)throw new Error(`openalgo-charts: unknown indicator "${e}" — did you import 'openalgo-charts/indicators'?`);return t}function we(e){return ge.has(e)}function xe(){return Array.from(ge.values())}function Pe(e){const t={};for(const i of e.inputs)t[i.key]=i.default;return t}function Se(e,t){switch(t){case"open":return e.open;case"high":return e.high;case"low":return e.low;case"hl2":return(e.high+e.low)/2;case"hlc3":return(e.high+e.low+e.close)/3;case"ohlc4":return(e.open+e.high+e.low+e.close)/4;case"volume":return e.volume??0;default:return e.close}}function Oe(e,t){const i=new Array(e.length);for(let s=0;s<e.length;s++)i[s]=Se(e[s],t);return i}class Te{constructor(e){Object.defineProperty(this,"_points",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this._opts={opacity:.12,...e}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"bottom"}autoscaleInfo(){return null}setPoints(e){this._points=e.slice(),this._host?.requestUpdate()}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}setVisible(e){this._visible=e,this._host?.requestUpdate()}draw(e,t){if(!this._visible||this._points.length<2)return;const i=t.dpr,s=e=>t.timeScale.indexToX(e)*i,r=e=>t.priceScale.priceToY(e)*i;e.save(),e.globalAlpha=this._opts.opacity??.12;let o=null;const n=()=>{if(null!==o&&o.xs.length>=2){e.beginPath(),e.moveTo(o.xs[0],o.top[0]);for(let t=1;t<o.xs.length;t++)e.lineTo(o.xs[t],o.top[t]);for(let t=o.xs.length-1;t>=0;t--)e.lineTo(o.xs[t],o.bot[t]);e.closePath(),e.fillStyle=o.up?this._opts.colorUp:this._opts.colorDown,e.fill()}o=null};for(let e=0;e<this._points.length;e++){const t=this._points[e];if(null===t.a||null===t.b||!Number.isFinite(t.a)||!Number.isFinite(t.b)){n();continue}const i=t.a>=t.b,a=s(t.index),l=r(t.a),h=r(t.b);if(null!==o&&o.up!==i){const a=this._points[e-1];if(void 0!==a&&null!==a.a&&null!==a.b){const e=a.a-a.b,l=t.a-t.b,h=e===l?0:e/(e-l),c=s(a.index+(t.index-a.index)*h),d=r(a.a+(t.a-a.a)*h);o.xs.push(c),o.top.push(d),o.bot.push(d),n(),o={up:i,xs:[c],top:[d],bot:[d]}}else n()}null===o&&(o={up:i,xs:[],top:[],bot:[]}),o.xs.push(a),o.top.push(l),o.bot.push(h)}n(),e.restore()}}function Me(e){const t=e.trim();if(t.startsWith("#")){const e=t.slice(1);if(3===e.length||4===e.length){const[t,i,s,r]=[...e].map(e=>parseInt(e+e,16));return[t,i,s].some(Number.isNaN)?null:{r:t,g:i,b:s,a:4===e.length?r/255:1}}if(6===e.length||8===e.length){const t=parseInt(e.slice(0,6),16);if(Number.isNaN(t))return null;const i=8===e.length?parseInt(e.slice(6,8),16)/255:1;return{r:t>>16&255,g:t>>8&255,b:255&t,a:Number.isNaN(i)?1:i}}return null}const i=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(t);return null===i?null:{r:Number(i[1]),g:Number(i[2]),b:Number(i[3]),a:void 0===i[4]?1:Number(i[4])}}function Ce(e){return function(e){const t=Me(e);if(null===t)return.5;const i=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};return.2126*i(t.r)+.7152*i(t.g)+.0722*i(t.b)}(e)>.45?"#10131a":"#ffffff"}function Ie(e,t){const i=Me(e);return null===i?e:`rgba(${i.r},${i.g},${i.b},${t})`}function Le(e,t){const i=Me(e);if(null===i)return e;const s=t>=0?255:0,r=Math.min(1,Math.abs(t)),o=e=>Math.round(e+(s-e)*r);return`rgba(${o(i.r)},${o(i.g)},${o(i.b)},${i.a})`}function je(e,t,i,s,r,o){const n=e.roundRect;"function"==typeof n?n.call(e,t,i,s,r,Math.max(0,Math.min(o,s/2,r/2))):e.rect(t,i,s,r)}function ke(e){const t={};for(const i of fe(e))t[i.key]=i.default;return t}function Ae(e){const t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(2)}B`:t>=1e6?`${(e/1e6).toFixed(2)}M`:t>=1e3?e.toFixed(0):t>=1?e.toFixed(2):e.toPrecision(3)}let Fe=1;class Re{constructor(e,t,i={},s){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"indicatorId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"paneIndex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_d",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ownPane",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_settings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_plotTypes",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_fills",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_levels",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_values",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_barCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_removed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_detach",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_legend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:!0}),this._host=e,this._d=t,this.indicatorId=t.id,this.name=t.name,this.id=`${t.id}-${Fe++}`,this._settings={...Pe(t),...ke(t),...i},void 0!==s?(this.paneIndex=s,this._ownPane=!1):"onchart"===t.placement?(this.paneIndex=0,this._ownPane=!1):(this.paneIndex=e.nextPaneIndex(),this._ownPane=!0);for(const i of t.plots){const t=this._plotType(i);this._plotTypes.set(i.key,t),this._series.set(i.key,e.addIndicatorSeries(t,this.paneIndex,this._plotStyle(i),i.priceScaleId))}for(const i of t.fills??[]){const t=new Te({colorUp:this._fillColor(i,!0),colorDown:this._fillColor(i,!1),opacity:i.opacity??.12});this._fills.push(t),e.addIndicatorFill(t,this.paneIndex)}this._legend=e.addIndicatorLegend({id:`indicator:${this.id}`,title:t.name,params:this._paramSummary(),color:this._legendColor(),row:e.legendRowsOn(this.paneIndex),paneIndex:this.paneIndex}),this._applyLevels(),this._applyRange(),this.recompute(),this._attach()}_paramSummary(){const e=[];for(const t of this._d.inputs){if("color"===t.type)continue;const i=this._settings[t.key];null!=i&&""!==i&&e.push(String(i))}return e.join(" ")}_legendColor(){for(const e of this._d.plots){const t=e.colorKey;if(void 0!==t&&"string"==typeof this._settings[t])return this._settings[t];if("string"==typeof e.style?.color)return e.style.color}}visible(){return this._visible}setVisible(e){if(e!==this._visible){this._visible=e;for(const t of this._series.values())t.applyOptions({visible:e});for(const t of this._fills)t.setVisible(e);this._legend?.setOptions({hidden:!e})}}shiftPane(e){this.paneIndex+=e}legend(){return this._legend}updateLegendValues(e){if(null===this._legend)return;const t=this._barCount,i=void 0===e||e<0||e>=t?t-1:e;if(i<0)return void this._legend.setValues([]);const s=[];for(const e of this._d.plots){const t=this._values[e.key]?.[i];null!=t&&Number.isFinite(t)&&s.push({text:Ae(t),color:this._plotColor(e)})}this._legend.setValues(s)}_fillColor(e,t){const i=t?e.colorUpKey:e.colorDownKey,s=void 0!==i?this._settings[i]:void 0;if("string"==typeof s)return s;return(t?e.colorUp:e.colorDown)??(t?"#26a69a":"#ef5350")}_syncFills(){const e=this._d.fills??[];for(let t=0;t<e.length;t++){const i=this._fills[t];if(void 0===i)continue;const s=e[t],r=this._values[s.between[0]],o=this._values[s.between[1]];if(i.setOptions({colorUp:this._fillColor(s,!0),colorDown:this._fillColor(s,!1),opacity:s.opacity??.12}),void 0===r||void 0===o){i.setPoints([]);continue}const n=[];for(let e=0;e<this._barCount;e++)n.push({index:e,a:r[e]??null,b:o[e]??null});i.setPoints(n)}}_plotType(e){const t=this._settings[_e(e).type];return"string"==typeof t&&""!==t?t:e.type}_plotColor(e){const t=this._settings[_e(e).color];return"string"==typeof t?t:"string"==typeof e.style?.color?e.style.color:void 0}_plotStyle(e){const t=_e(e),i={...e.style??{},title:e.title},s=this._plotColor(e),r=(o=this._settings[t.opacity],n=100,"number"==typeof o&&Number.isFinite(o)?o:n);var o,n;void 0!==s&&(i.color=r>=100?s:Ie(s,r/100));const a=this._settings[t.width];"number"==typeof a&&a>0&&(i.lineWidth=a);const l=this._settings[t.lineStyle];return"string"==typeof l&&(i.lineStyle=l),i}_attach(){const e=this._d.attach?.({settings:()=>this._settings,bars:()=>this._host.sourceBars(),requestRecompute:()=>{this._removed||(this._barCount=0,this.recompute())},store:this._store});this._detach="function"==typeof e?e:null}settings(){return{...this._settings}}series(e){return this._series.get(e)}values(){return this._values}setSettings(e){if(!this._removed){this._settings={...this._settings,...e};for(const e of this._d.plots){const t=this._plotType(e);t===this._plotTypes.get(e.key)?this._series.get(e.key)?.applyOptions(this._plotStyle(e)):(this._series.get(e.key)?.remove(),this._series.set(e.key,this._host.addIndicatorSeries(t,this.paneIndex,this._plotStyle(e),e.priceScaleId)),this._plotTypes.set(e.key,t))}this._legend?.setOptions({params:this._paramSummary(),color:this._legendColor()}),this._applyLevels(),this._applyRange(),this._values={},this._barCount=0,this.recompute(),this._detach?.(),this._attach()}}recompute(){if(this._removed)return;const e=this._host.sourceBars(),t=e.length;let i=null;if(t>0&&this._barCount>0&&(t===this._barCount||t===this._barCount+1)&&void 0!==this._d.calcTail){const s=this._barCount-1,r=this._d.calcTail(e,this._settings,s,this._values,this._store);null!==r&&(i=function(e,t,i,s){const r={};for(const o of Object.keys(t)){const n=e[o],a=t[o];if(void 0===n||void 0===a)return null;if(a.length!==s-i)return null;const l=new Array(s);for(let e=0;e<i;e++)l[e]=n[e]??null;for(let e=i;e<s;e++)l[e]=a[e-i]??null;r[o]=l}return r}(this._values,r,s,t))}null===i&&(i=this._d.calc(e,this._settings,this._store)),this._values=i,this._barCount=t;for(const s of this._d.plots){const r=this._series.get(s.key);if(void 0===r)continue;const o=i[s.key];if(void 0===o){r.setData([]);continue}const n=new Array(t),a=s.colorBy;for(let s=0;s<t;s++){const t=o[s],r=null==t?NaN:t,l={time:e[s].time,value:r};if(void 0!==a&&Number.isFinite(r)){const e=a({value:r,index:s,values:i,settings:this._settings});void 0!==e&&(l.color=e)}n[s]=l}r.setData(n)}this._syncFills(),this.updateLegendValues()}_applyLevels(){for(const e of this._levels)this._host.removeIndicatorLevel(e);this._levels=[];const e=this._d.levels?.(this._settings)??[];let t=0;for(const i of e)this._levels.push(this._host.addIndicatorLevel(i.price,i.color??"#8892a6",i.dashed??!0,i.title??"",`${this.id}:level:${t++}`,this.paneIndex))}_applyRange(){this._ownPane&&this._host.setPaneRange(this.paneIndex,this._d.range?.(this._settings)??null)}remove(){if(!this._removed){this._removed=!0,this._detach?.(),this._detach=null,null!==this._legend&&(this._host.removeIndicatorLegend(this._legend),this._legend=null);for(const e of this._levels)this._host.removeIndicatorLevel(e);this._levels=[];for(const e of this._series.values())e.remove();this._series.clear();for(const e of this._fills)this._host.removeIndicatorFill(e);this._fills.length=0,this._ownPane&&this._host.setPaneRange(this.paneIndex,null)}}}const Be=1;function Ne(e){return!("open"in e)&&!("value"in e)}function We(e){if("open"in e)return e;if("value"in e){const t=e.value,i={time:e.time,open:t,high:t,low:t,close:t};return void 0!==e.color&&(i.color=e.color),i}return{time:e.time,open:NaN,high:NaN,low:NaN,close:NaN}}const De={friction:.0055,minSpeed:.02,triggerSpeed:.08};class ze{constructor(e,t={}){Object.defineProperty(this,"_v0",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_k",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_minSpeed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_duration",{enumerable:!0,configurable:!0,writable:!0,value:void 0});const i={...De,...t};this._v0=e,this._k=i.friction,this._minSpeed=i.minSpeed;const s=Math.abs(this._v0)>0?this._minSpeed/Math.abs(this._v0):1;this._duration=s>=1?0:-Math.log(s)/this._k}static shouldAnimate(e,t={}){const i=t.triggerSpeed??De.triggerSpeed;return Math.abs(e)>=i}distanceAt(e){const t=Math.min(Math.max(0,e),this._duration);return this._v0/this._k*(1-Math.exp(-this._k*t))}get durationMs(){return this._duration}finished(e){return e>=this._duration}}const $e=["Mod","Ctrl","Meta","Alt","Shift"],He=new Set($e),qe=new Set(["Shift","Control","Alt","Meta","OS","ShiftLeft","ShiftRight","ControlLeft","ControlRight","AltLeft","AltRight","MetaLeft","MetaRight","OSLeft","OSRight"]);function Ee(){return"undefined"!=typeof navigator&&/mac|iphone|ipad/i.test(navigator.platform||navigator.userAgent||"")}function Ue(e){const t=e.split("+").map(e=>e.trim()).filter(e=>e.length>0);if(0===t.length)return null;const i=t[t.length-1];if(!/^[A-Za-z0-9]+$/.test(i)||He.has(i))return null;const s=[];for(const e of t.slice(0,-1)){if(!He.has(e))return null;s.includes(e)||s.push(e)}return s.sort((e,t)=>$e.indexOf(e)-$e.indexOf(t)),{mods:s,key:i}}function Ve(e){const t=Ue(e);return null===t?"":[...t.mods,t.key].join("+")}function Ye(e){return""!==Ve(e)}const Ge={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",Equal:"=",Minus:"-",NumpadAdd:"+",NumpadSubtract:"-",Escape:"Esc",Space:"Space"};function Ke(e,t=Ee()){const i=Ue(e);if(null===i)return"";const s=t?{Mod:"⌘",Ctrl:"⌃",Meta:"⌘",Alt:"⌥",Shift:"⇧"}:{Mod:"Ctrl",Ctrl:"Ctrl",Meta:"Win",Alt:"Alt",Shift:"Shift"};var r;return[...i.mods.map(e=>s[e]),(r=i.key,void 0!==Ge[r]?Ge[r]:/^Key[A-Z]$/.test(r)?r.slice(3):/^Digit[0-9]$/.test(r)?r.slice(5):r)].join(t?" ":" + ")}function Xe(e,t=Ee()){const i=e.code??e.key??"";if(""===i||qe.has(i))return"";const s=[];return(t?e.metaKey:e.ctrlKey)&&s.push("Mod"),t&&e.ctrlKey&&s.push("Ctrl"),!t&&e.metaKey&&s.push("Meta"),e.altKey&&s.push("Alt"),e.shiftKey&&s.push("Shift"),Ve([...s,i].join("+"))}const Je=new Set(["Mod+KeyW","Mod+KeyT","Mod+KeyN","Mod+KeyQ","Mod+KeyR","Mod+KeyL","Mod+Shift+KeyT","Mod+Shift+KeyN","Mod+Shift+KeyW"]);function Qe(e){return Je.has(Ve(e))}const Ze=[{command:"panLeft",label:"Pan left",combos:["ArrowLeft"]},{command:"panRight",label:"Pan right",combos:["ArrowRight"]},{command:"panLeftFast",label:"Pan left (fast)",combos:["Mod+ArrowLeft"]},{command:"panRightFast",label:"Pan right (fast)",combos:["Mod+ArrowRight"]},{command:"panUp",label:"Pan up",combos:["ArrowUp"]},{command:"panDown",label:"Pan down",combos:["ArrowDown"]},{command:"zoomIn",label:"Zoom in",combos:["Equal","Shift+Equal","NumpadAdd"]},{command:"zoomOut",label:"Zoom out",combos:["Minus","NumpadSubtract"]},{command:"resetScale",label:"Reset scale",combos:["Home","Digit0"]},{command:"fitContent",label:"Fit content",combos:["Alt+KeyF"]},{command:"screenshot",label:"Screenshot (PNG)",combos:["Alt+Shift+KeyS"]},{command:"toggleGridVert",label:"Toggle vertical grid",combos:["Alt+KeyV"]},{command:"toggleGridHorz",label:"Toggle horizontal grid",combos:["Alt+KeyH"]},{command:"toggleCrosshairMagnet",label:"Toggle crosshair magnet",combos:["Alt+KeyM"]}],et={panLeftFast:["Alt+ArrowLeft"],panRightFast:["Alt+ArrowRight"],screenshot:["Mod+Shift+KeyS"]},tt=new Set(Ze.map(e=>e.command)),it=e=>Array.isArray(e)?e:[e];class st{constructor(e={}){Object.defineProperty(this,"scope",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_isMac",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_persist",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_preset",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_overrides",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_custom",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_entries",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_reverse",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),this.scope=e.scope??"hover",this._isMac=e.isMac??Ee(),this._persist=e.persist??!1,this._storageKey=e.storageKey??"openalgo-charts:shortcuts",this._preset=e.preset??"default";const t=e=>{for(const[t,i]of Object.entries(e??{})){if(null===i){this._disabled.add(t);continue}const e=it(i).map(Ve).filter(e=>""!==e&&!Qe(e));this._overrides[t]=e}};t(e.overrides);for(const t of e.disabledCommands??[])this._disabled.add(t);for(const t of e.customShortcuts??[])this._custom.set(t.command,t);const i=this._load();if(null!==i){void 0!==i.preset&&(this._preset=i.preset),t(i.overrides);for(const e of i.disabled??[])this._disabled.add(e)}this._rebuild()}_presetCombos(e){return"alt"===this._preset?et[e]:void 0}_effectiveCombos(e,t){return this._disabled.has(e)?[]:void 0!==this._overrides[e]?this._overrides[e]:this._presetCombos(e)??t}_rebuild(){this._entries=new Map;for(const e of Ze)this._entries.set(e.command,{command:e.command,label:e.label,combos:this._effectiveCombos(e.command,e.combos)});for(const e of this._custom.values())this._entries.set(e.command,{command:e.command,label:e.label??e.command,combos:this._effectiveCombos(e.command,it(e.combos).map(Ve).filter(e=>""!==e))});this._reverse=new Map;for(const e of this._entries.values())for(const t of e.combos)this._reverse.has(t)||this._reverse.set(t,e.command)}resolve(e){const t=Xe(e,this._isMac);return""===t?null:this._reverse.get(t)??null}handleKey(e){return this._reverse.get(Ve(e))??null}runCustom(e){const t=this._custom.get(e);return void 0!==t&&(t.onTrigger(),this.emitTrigger(e),!0)}emitTrigger(e,t=""){const i={command:e,combo:t,isCustom:this._custom.has(e)};for(const e of this._listeners)e(i)}on(e){return this._listeners.add(e),()=>this._listeners.delete(e)}setBinding(e,t){const i=it(t).map(Ve).filter(e=>""!==e&&!Qe(e));return 0!==i.length&&(this._overrides[e]=i,this._disabled.delete(e),this._after(),!0)}disable(e){this._disabled.add(e),delete this._overrides[e],this._after()}resetBinding(e){delete this._overrides[e],this._disabled.delete(e),this._after()}resetAll(){this._overrides={},this._disabled.clear(),this._after()}setPreset(e){this._preset=e,this._after()}addCustom(e){this._custom.set(e.command,e),this._after()}list(){return[...this._entries.values()].map(e=>({command:e.command,label:e.label,combos:e.combos,isCustom:this._custom.has(e.command),isDisabled:this._disabled.has(e.command)}))}state(){return{preset:this._preset,overrides:this._overrides,disabled:[...this._disabled]}}_after(){this._rebuild(),this._save()}_save(){if(this._persist&&"undefined"!=typeof localStorage)try{localStorage.setItem(this._storageKey,JSON.stringify(this.state()))}catch{}}_load(){if(!this._persist||"undefined"==typeof localStorage)return null;try{const e=localStorage.getItem(this._storageKey);return null===e?null:JSON.parse(e)}catch{return null}}static shouldIgnore(e){const t=e;if(null==t)return!1;if(!0===t.isContentEditable)return!0;const i=(t.tagName??"").toUpperCase();return"INPUT"===i||"TEXTAREA"===i||"SELECT"===i}}class rt{constructor(e){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ghostPrice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_group",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._opts=e}attached(e){this._host=e}detached(){this._host=null}get price(){return this._opts.price}setPrice(e){this._opts.price=e,this._host?.requestUpdate()}setLeftLabel(e){this._opts.leftLabel=e,this._host?.requestUpdate()}setDragGhost(e){this._ghostPrice=e,this._host?.requestUpdate()}options(){return this._opts}zOrder(){return"normal"}autoscaleInfo(){return{min:this._opts.price,max:this._opts.price}}draw(e,t){this._group=null;const i=Math.round(t.priceScale.priceToY(this._opts.price)*t.dpr)+.5;if(i<0||i>t.plotHeight*t.dpr)return;const s=t.dpr,r=Math.round(t.plotWidth*s),o=Math.max(0,Math.min(1,this._opts.extentFromRight??1)),n=Math.round(t.plotWidth*(1-o)*s),a=this._opts.color,l=void 0!==this._opts.cursor||!0===this._opts.closeButton,h=t.dragId===this._opts.id,c=l&&!h&&(t.hoverId===this._opts.id||t.hoverId===`${this._opts.id}::close`),d=t.hoverId===`${this._opts.id}::close`;if(e.save(),null!==this._ghostPrice&&h){const i=Math.round(t.priceScale.priceToY(this._ghostPrice)*s)+.5;i>=0&&i<=t.plotHeight*s&&(e.strokeStyle=Ie(a,.35),e.lineWidth=Math.max(1,Math.round(s)),e.setLineDash([2*s,3*s]),e.beginPath(),e.moveTo(n,i),e.lineTo(r,i),e.stroke(),e.setLineDash([]))}h&&(e.strokeStyle=Ie(a,.18),e.lineWidth=Math.max(5*s,Math.round(this._opts.lineWidth*s)+4*s),e.beginPath(),e.moveTo(n,i),e.lineTo(r,i),e.stroke()),e.strokeStyle=c||h?Le(a,.1):a;const u=Math.max(1,Math.round(this._opts.lineWidth*s));e.lineWidth=c||h?u+Math.round(s):u,this._opts.dashed&&e.setLineDash([4*s,4*s]),e.beginPath(),e.moveTo(n,i),e.lineTo(r,i),e.stroke(),e.setLineDash([]),e.font=`500 ${11*s}px system-ui, sans-serif`,e.textBaseline="middle",e.textAlign="left";const p=18*s,_=6*s,f=3*s,b=h||c?Le(a,.12):a,m=this._opts.label??t.priceScale.format(this._opts.price);e.fillStyle=b,e.fillRect(r+1,i-p/2,e.measureText(m).width+2*_,p),e.fillStyle=Ce(a),e.fillText(m,r+1+_,i);if(void 0!==this._opts.badge||void 0!==this._opts.qty||void 0!==this._opts.leftLabel&&""!==this._opts.leftLabel||!0===this._opts.closeButton){const r="transparent"===t.theme.background,l=r?Ie(a,.14):t.theme.background,u=r?t.theme.axisText:Ce(t.theme.background),b=Ie(t.theme.axisText,c||h?.75:.5),m=[];void 0!==this._opts.badge&&m.push({text:this._opts.badge,fill:h?Le(a,.2):c?Le(a,.12):a,textColor:Ce(a),border:Le(a,-.25)}),void 0!==this._opts.qty&&m.push({text:String(this._opts.qty),fill:l,textColor:u,border:b}),void 0!==this._opts.leftLabel&&""!==this._opts.leftLabel&&m.push({text:this._opts.leftLabel,fill:l,textColor:u,border:b}),!0===this._opts.closeButton&&m.push({close:!0,fill:d?a:l,textColor:d?Ce(a):u,border:d?a:b}),this._group=function(e,t,i,s,r){const{height:o,padX:n,radius:a,gap:l,dpr:h}=r,c=s.map(t=>!0===t.close?20*h:e.measureText(t.text??"").width+2*n),d=c.reduce((e,t)=>e+t,0)+l*Math.max(0,s.length-1);void 0!==r.backplate&&(e.beginPath(),je(e,t,i-o/2,d,o,a),e.fillStyle=r.backplate,e.fill());let u=Number.POSITIVE_INFINITY,p=t;for(let t=0;t<s.length;t++){const r=s[t],d=c[t];if(e.beginPath(),je(e,p,i-o/2,d,o,a),e.fillStyle=r.fill,e.fill(),void 0!==r.border&&(e.strokeStyle=r.border,e.lineWidth=Math.max(1,Math.round(h)),e.stroke()),!0===r.close){u=p,e.strokeStyle=r.textColor,e.lineWidth=Math.max(1,Math.round(1.4*h));const t=p+d/2,s=3.5*h;e.beginPath(),e.moveTo(t-s,i-s),e.lineTo(t+s,i+s),e.moveTo(t+s,i-s),e.lineTo(t-s,i+s),e.stroke()}else e.fillStyle=r.textColor,e.textAlign="left",e.textBaseline="middle",e.fillText(r.text??"",p+n,i);p+=d+l}return{x0:t/h,x1:(p-l)/h,closeX0:u/h}}(e,n+(1===o?6*s:0),i,m,{height:p,padX:_,radius:f,gap:2*s,backplate:r?void 0:t.theme.background,dpr:s})}e.restore()}hitTest(e,t,i){if(e<0||e>i.plotWidth)return null;const s=i.priceScale.priceToY(this._opts.price),r=Math.abs(t-s),o=this._group;return null!==o&&r<=10&&e>=o.x0&&e<=o.x1?this._opts.closeButton&&e>=o.closeX0?{externalId:`${this._opts.id}::close`,zOrder:"normal",distance:r,cursor:"pointer"}:{externalId:this._opts.id,zOrder:"normal",distance:r,cursor:this._opts.cursor}:r>4?null:{externalId:this._opts.id,zOrder:"normal",distance:r,cursor:this._opts.cursor}}}const ot={long:"#2f6df6",short:"#ef5350",order:"#3b82f6",tp:"#26a69a",sl:"#ef5350",buy:"#26a69a",sell:"#ef5350"},nt="::close";function at(e,t){const i=e.length;if(0===i)return;let s=0,r=i-1;for(;s<r;){const i=s+r+1>>1,o=e.indexToTime(i);void 0!==o&&o<=t?s=i:r=i-1}const o=e.indexToTime(s);if(void 0!==o){if(s+1<i){const i=e.indexToTime(s+1);if(void 0!==i&&Math.abs(i-t)<Math.abs(o-t))return s+1}return s}}function lt(e,t,i,s,r,o){const n=5*o;e.fillStyle=r,e.beginPath(),"buy"===s?(e.moveTo(t,i-1.5*n),e.lineTo(t-n,i),e.lineTo(t+n,i)):(e.moveTo(t,i+1.5*n),e.lineTo(t-n,i),e.lineTo(t+n,i)),e.closePath(),e.fill()}function ht(e,t,i,s,r,o){const n=9*o;e.fillStyle=s,e.beginPath(),e.arc(t,i,n,0,2*Math.PI),e.fill(),""!==r&&(e.fillStyle=Ce(s),e.font=`500 ${9*o}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,t,i+.5*o))}function ct(e,t,i,s,r,o){const n=String(s);e.font=`500 ${9*o}px system-ui, sans-serif`;const a=e.measureText(n).width+10*o,l=15*o;e.fillStyle=r,e.beginPath(),je(e,Math.round(t-a/2),Math.round(i-l/2),Math.round(a),Math.round(l),3*o),e.fill(),e.fillStyle=Ce(r),e.textAlign="center",e.textBaseline="middle",e.fillText(n,t,i+.5*o)}class dt{constructor(e){Object.defineProperty(this,"_trades",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_colors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._colors=e}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setTrades(e){this._trades=e,this._host?.requestUpdate()}setColors(e){this._colors=e,this._host?.requestUpdate()}draw(e,t){if(0===this._trades.length)return;const i=t.dpr,s=new Map;e.save();for(const r of this._trades){const o=at(t.dataLayer,Math.floor(r.timestamp/1e3));if(void 0===o)continue;const n=Math.round(t.timeScale.indexToX(o)*i),a=r.color??("buy"===r.side?this._colors.buy:this._colors.sell),l=r.variant??"chevron";if("count"===l){const e=`${o}:${r.side}`;let t=s.get(e);void 0===t&&(t={index:o,sumPS:0,sumS:0,n:0,color:a},s.set(e,t)),t.sumPS+=r.price*r.size,t.sumS+=r.size,t.n+=1;continue}const h=Math.round(t.priceScale.priceToY(r.price)*i);"bubble"===l?ht(e,n,h,a,r.label??("buy"===r.side?"B":"S"),i):lt(e,n,h,r.side,a,i)}for(const r of s.values()){const s=r.sumS>0?r.sumPS/r.sumS:0;ct(e,Math.round(t.timeScale.indexToX(r.index)*i),Math.round(t.priceScale.priceToY(s)*i),r.n,r.color,i)}e.restore()}}class ut{constructor(e){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_positions",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_orders",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_trades",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_dragPrev",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_colors",{enumerable:!0,configurable:!0,writable:!0,value:{...ot}}),Object.defineProperty(this,"_markers",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._host=e,e.subscribeClick(e=>this._onClick(e)),e.subscribeDrag((e,t)=>this._onDrag(e,t),(e,t)=>this._onDragEnd(e,t))}on(e,t){let i=this._listeners.get(e);return void 0===i&&(i=new Set,this._listeners.set(e,i)),i.add(t),()=>{this._listeners.get(e)?.delete(t)}}off(e,t){this._listeners.get(e)?.delete(t)}_emit(e,t){const i=this._listeners.get(e);if(void 0!==i)for(const e of i)e(t);this._host.emit?.(e,t)}setSettings(e){void 0!==e.longColor&&(this._colors.long=e.longColor),void 0!==e.shortColor&&(this._colors.short=e.shortColor),void 0!==e.orderColor&&(this._colors.order=e.orderColor),void 0!==e.tpColor&&(this._colors.tp=e.tpColor),void 0!==e.slColor&&(this._colors.sl=e.slColor),void 0!==e.buyColor&&(this._colors.buy=e.buyColor),void 0!==e.sellColor&&(this._colors.sell=e.sellColor),this.setPositions(this.getPositions()),this.setOrders(this.getOrders()),this._markers?.setColors(this._colors)}getSettings(){return{...this._colors}}setPositions(e){this._sync(this._positions,e,"pos")}setOrders(e){this._sync(this._orders,e,"ord")}setTrades(e){this._trades.clear();for(const t of e)this._trades.set(t.id,t);this._renderTrades()}addTrade(e){this._trades.set(e.id,e),this._renderTrades()}upsertOrder(e){const t=this.getOrders().filter(t=>t.id!==e.id);t.push(e),this.setOrders(t)}removeOrder(e){const t=this.getOrders().filter(t=>t.id!==e&&t.parentId!==e);this.setOrders(t)}syncState(e){void 0!==e.positions&&this.setPositions(e.positions),void 0!==e.orders&&this.setOrders(e.orders),void 0!==e.trades&&this.setTrades(e.trades)}updatePositionPnl(e,t,i,s){const r=this._positions.get(e);void 0!==r&&(void 0!==i&&(r.entity.pnlText=i),void 0!==s&&(r.entity.pnlPercent=s),r.line.setLeftLabel(this._positionPill(r.entity)))}getPositions(){return[...this._positions.values()].map(e=>e.entity)}getOrders(){return[...this._orders.values()].map(e=>e.entity)}getTrades(){return[...this._trades.values()]}clear(){for(const e of this._positions.values())this._host.removePrimitive(e.line);for(const e of this._orders.values())this._host.removePrimitive(e.line);this._positions.clear(),this._orders.clear(),this._trades.clear(),null!==this._markers&&(this._host.removePrimitive(this._markers),this._markers=null)}_renderTrades(){null===this._markers&&(this._markers=new dt(this._colors),this._host.addPrimitive(this._markers)),this._markers.setTrades(this.getTrades())}_sync(e,t,i){const s=new Set;for(const r of t){s.add(r.id);const t="pos"===i?this._positionOpts(r):this._orderOpts(r),o=this._sig(t),n=e.get(r.id);if(void 0!==n&&n.sig===o)n.entity=r,n.line.setPrice(t.price),void 0!==t.leftLabel&&n.line.setLeftLabel(t.leftLabel);else{void 0!==n&&this._host.removePrimitive(n.line);const i=new rt(t);this._host.addPrimitive(i),e.set(r.id,{entity:r,line:i,sig:o})}}for(const[t,i]of e)s.has(t)||(this._host.removePrimitive(i.line),e.delete(t))}_sig(e){return`${e.color}|${e.dashed}|${!0===e.closeButton}|${e.cursor??""}|${void 0!==e.leftLabel}|${e.badge??""}|${e.qty??""}`}_positionPill(e){return void 0===e.pnlText?"":`${e.pnlText}${void 0!==e.pnlPercent?` (${e.pnlPercent})`:""}`}_positionOpts(e){const t="line-only"===e.variant;return{price:e.entryPrice,color:e.color??("long"===e.side?this._colors.long:this._colors.short),lineWidth:2,dashed:!1,id:`pos:${e.id}`,badge:t?void 0:e.side.toUpperCase(),qty:t?void 0:e.size,leftLabel:t?void 0:this._positionPill(e),closeButton:!t&&!0!==e.readOnly,extentFromRight:.3}}_orderOpts(e){const t="line-only"===e.variant,i=!t&&(e.draggable??!0!==e.readOnly),s=e.color??("tp"===e.bracketRole?this._colors.tp:"sl"===e.bracketRole?this._colors.sl:this._colors.order);return{price:e.price,color:s,lineWidth:e.lineWidth??1,dashed:"solid"!==(e.lineStyle??"solid"),id:`ord:${e.id}`,badge:t?void 0:(e.bracketRole??e.side).toUpperCase(),qty:t?void 0:e.size,leftLabel:t||void 0!==e.bracketRole?void 0:e.type.replace("_"," ").toUpperCase(),closeButton:!t&&!0!==e.readOnly,extentFromRight:.3,cursor:i?"ns-resize":void 0}}_onClick(e){if(e.endsWith(nt)){const t=e.slice(0,-7);if(t.startsWith("ord:")){const e=t.slice(4);this._orders.has(e)&&this._emit("trading:order_cancel",{orderId:e})}else if(t.startsWith("pos:")){const e=t.slice(4);this._positions.has(e)&&this._emit("trading:position_close",{positionId:e})}return}if(e.startsWith("ord:")){const t=this._orders.get(e.slice(4));void 0!==t&&this._emit("trading:order_click",{order:t.entity})}else if(e.startsWith("pos:")){const t=this._positions.get(e.slice(4));void 0!==t&&this._emit("trading:position_click",{position:t.entity})}}_onDrag(e,t){if(!e.startsWith("ord:"))return;const i=this._orders.get(e.slice(4));if(void 0===i)return;const s=e.slice(4);this._dragPrev.has(s)||(this._dragPrev.set(s,i.entity.price),i.line.setDragGhost(i.entity.price)),i.line.setPrice(t)}_onDragEnd(e,t){if(!e.startsWith("ord:"))return;const i=e.slice(4),s=this._orders.get(i);if(void 0===s)return;const r=this._dragPrev.get(i)??s.entity.price;this._dragPrev.delete(i),s.line.setDragGhost(null),s.entity.price=t,s.line.setPrice(t),void 0!==s.entity.bracketRole?this._emit("trading:bracket_modify",{parentId:s.entity.parentId,bracketRole:s.entity.bracketRole,newPrice:t}):this._emit("trading:order_modify",{orderId:i,newPrice:t,previousPrice:r})}}function pt(e,t){return{dist:Math.hypot(e.x-t.x,e.y-t.y),cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}const _t={tiny:6,small:9,medium:12,big:16};function ft(e){return _t[e]}function bt(e,t){return Math.max(4,Math.min(_t[e],Math.floor(t)))}function mt(e,t,i,s,r,o){const n=r/2;switch(e.fillStyle=o,e.strokeStyle=o,e.beginPath(),t){case"arrowUp":case"triangleUp":e.moveTo(i,s-n),e.lineTo(i+n,s+n),e.lineTo(i-n,s+n),e.closePath(),e.fill();break;case"arrowDown":case"triangleDown":e.moveTo(i,s+n),e.lineTo(i+n,s-n),e.lineTo(i-n,s-n),e.closePath(),e.fill();break;case"circle":e.arc(i,s,n,0,2*Math.PI),e.fill();break;case"square":e.fillRect(i-n,s-n,r,r);break;case"diamond":e.moveTo(i,s-n),e.lineTo(i+n,s),e.lineTo(i,s+n),e.lineTo(i-n,s),e.closePath(),e.fill();break;case"flag":e.fillRect(i-1,s-n,Math.max(1,r/8),r),e.fillRect(i,s-n,n,.8*n)}}class gt{constructor(e){Object.defineProperty(this,"_seriesId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_markers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_lastPositions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._seriesId=e}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"normal"}setMarkers(e){this._markers=e.slice().sort((e,t)=>e.time-t.time),this._host?.requestUpdate()}draw(e,t){if(this._lastPositions=[],0===this._markers.length)return;const i=new Map;for(const e of t.dataLayer.indexedBars(this._seriesId))i.set(e.bar.time,e.bar);const s=t.timeScale.visibleRange(),r=new Map;e.save();for(const o of this._markers){const n=t.dataLayer.timeToIndex(o.time);if(void 0===n||n<s.from-1||n>s.to+1)continue;const a=i.get(o.time),l=bt(o.size,t.timeScale.barSpacing)*t.dpr,h=t.timeScale.indexToX(n)*t.dpr,c=r.get(o.time)??0,d=(l+4*t.dpr)*c;let u;if("atPrice"===o.position&&void 0!==o.price)u=t.priceScale.priceToY(o.price)*t.dpr;else if(void 0!==a&&"aboveBar"===o.position)u=t.priceScale.priceToY(a.high)*t.dpr-l-d;else if(void 0!==a&&"belowBar"===o.position)u=t.priceScale.priceToY(a.low)*t.dpr+l+d;else{if(void 0===a)continue;u=t.priceScale.priceToY((a.open+a.close)/2)*t.dpr}if(r.set(o.time,c+1),mt(e,o.shape,h,u,l,o.color),void 0!==o.text){e.fillStyle=o.color,e.font=Math.max(9,ft(o.size))*t.dpr+"px system-ui, sans-serif",e.textAlign="center",e.textBaseline="belowBar"===o.position?"top":"bottom";const i="belowBar"===o.position?u+l:u-l;e.fillText(o.text,h,i)}void 0!==o.id&&this._lastPositions.push({id:o.id,x:h/t.dpr,y:u/t.dpr})}e.restore()}hitTest(e,t){let i=null;for(const s of this._lastPositions){const r=Math.hypot(s.x-e,s.y-t);r<=8&&(null===i||r<i.distance)&&(i={externalId:s.id,zOrder:"normal",distance:r,cursor:"pointer"})}return i}}const vt={earnings:"#f0a020",dividend:"#26a69a",split:"#4f8cff",news:"#9aa0b4"};class yt{constructor(){Object.defineProperty(this,"_events",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_positions",{enumerable:!0,configurable:!0,writable:!0,value:[]})}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"normal"}setEvents(e){this._events=e.slice().sort((e,t)=>e.time-t.time),this._host?.requestUpdate()}draw(e,t){if(this._positions=[],0===this._events.length)return;const i=t.timeScale.visibleRange(),s=8*t.dpr,r=t.plotHeight*t.dpr-s-4*t.dpr;e.save(),e.textAlign="center",e.textBaseline="middle",e.font=10*t.dpr+"px system-ui, sans-serif";for(const o of this._events){const n=t.dataLayer.timeToIndex(o.time);if(void 0===n||n<i.from-1||n>i.to+1)continue;const a=t.timeScale.indexToX(n)*t.dpr,l=o.color??vt[o.type]??"#9aa0b4";e.fillStyle=l,e.beginPath(),e.arc(a,r,s,0,2*Math.PI),e.fill(),e.fillStyle="#0d0e12",e.fillText(o.label.slice(0,2),a,r),void 0!==o.id&&this._positions.push({id:o.id,x:a/t.dpr,y:r/t.dpr,r:s/t.dpr})}e.restore()}hitTest(e,t){let i=null;for(const s of this._positions){const r=Math.hypot(s.x-e,s.y-t);r<=s.r&&(null===i||r<i.distance)&&(i={externalId:s.id,zOrder:"normal",distance:r,cursor:"pointer"})}return i}}const wt=18,xt=16,Pt=["hide","settings","close"];function St(e,t,i,s,r,o,n){const a=.42*r,l=Math.max(1,Math.round(1.4*o));switch(e.save(),e.strokeStyle=e.fillStyle,e.lineWidth=l,e.lineCap="round",e.lineJoin="round",e.beginPath(),t){case"up":e.moveTo(i,s+a),e.lineTo(i,s-a),e.moveTo(i-.62*a,s-.35*a),e.lineTo(i,s-a),e.lineTo(i+.62*a,s-.35*a);break;case"down":e.moveTo(i,s-a),e.lineTo(i,s+a),e.moveTo(i-.62*a,s+.35*a),e.lineTo(i,s+a),e.lineTo(i+.62*a,s+.35*a);break;case"hide":e.moveTo(i-a,s),e.quadraticCurveTo(i,s-1.15*a,i+a,s),e.quadraticCurveTo(i,s+1.15*a,i-a,s),e.stroke(),e.beginPath(),e.arc(i,s,.34*a,0,2*Math.PI),!0===n.hidden&&(e.moveTo(i-a,s+.85*a),e.lineTo(i+a,s-.85*a));break;case"maximize":!0===n.maximized?(e.moveTo(i-a,s-.25*a),e.lineTo(i-.25*a,s-.25*a),e.lineTo(i-.25*a,s-a),e.moveTo(i+a,s+.25*a),e.lineTo(i+.25*a,s+.25*a),e.lineTo(i+.25*a,s+a)):(e.moveTo(i-a,s-.4*a),e.lineTo(i-a,s-a),e.lineTo(i-.4*a,s-a),e.moveTo(i+.4*a,s-a),e.lineTo(i+a,s-a),e.lineTo(i+a,s-.4*a),e.moveTo(i+a,s+.4*a),e.lineTo(i+a,s+a),e.lineTo(i+.4*a,s+a),e.moveTo(i-.4*a,s+a),e.lineTo(i-a,s+a),e.lineTo(i-a,s+.4*a));break;case"settings":e.arc(i,s,.46*a,0,2*Math.PI);for(let t=0;t<8;t++){const r=t*Math.PI/4,o=Math.cos(r),n=Math.sin(r);e.moveTo(i+o*a*.68,s+n*a*.68),e.lineTo(i+o*a,s+n*a)}break;case"close":e.moveTo(i-.8*a,s-.55*a),e.lineTo(i+.8*a,s-.55*a),e.moveTo(i-.3*a,s-.55*a),e.lineTo(i-.3*a,s-.85*a),e.lineTo(i+.3*a,s-.85*a),e.lineTo(i+.3*a,s-.55*a),e.moveTo(i-.6*a,s-.55*a),e.lineTo(i-.45*a,s+.85*a),e.lineTo(i+.45*a,s+.85*a),e.lineTo(i+.6*a,s-.55*a)}e.stroke(),e.restore()}class Ot{constructor(e){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_values",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_buttons",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),this._opts={font:11,left:8,top:6,row:0,...e}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setValue(e,t){this.setValues(""===e?[]:[{text:e,color:t}])}setValues(e){e.length===this._values.length&&e.every((e,t)=>e.text===this._values[t].text&&e.label===this._values[t].label&&e.color===this._values[t].color)||(this._values=e.map(e=>({...e})),this._host?.requestUpdate())}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}options(){return this._opts}draw(e,t){const i=this._opts,s=t.dpr,r=(i.font??11)*s,o=((i.top??6)+(i.row??0)*wt)*s,n=o+wt*s/2;let a=(i.left??8)*s;const l=!0===i.hidden;e.save(),e.textBaseline="middle",e.textAlign="left",e.globalAlpha=l?.45:1,void 0!==i.color&&(e.fillStyle=i.color,e.beginPath(),e.arc(a+3*s,n,3*s,0,2*Math.PI),e.fill(),a+=11*s),e.font=`600 ${r}px ui-sans-serif, system-ui, sans-serif`,e.fillStyle=t.theme.axisText,e.fillText(i.title,a,n),a+=e.measureText(i.title).width+6*s,e.font=`${r}px ui-sans-serif, system-ui, sans-serif`,void 0!==i.params&&""!==i.params&&(e.fillStyle=Ie(t.theme.axisText,.55),e.fillText(i.params,a,n),a+=e.measureText(i.params).width+6*s);for(const r of this._values)void 0!==r.label&&""!==r.label&&(e.fillStyle=Ie(t.theme.axisText,.55),e.fillText(r.label,a,n),a+=e.measureText(r.label).width+3*s),e.fillStyle=r.color??i.valueColor??i.color??t.theme.axisText,e.fillText(r.text,a,n),a+=e.measureText(r.text).width+6*s;this._buttons=[];const h="string"==typeof t.hoverId&&t.hoverId.startsWith(`${i.id}::`),c=i.actions??Pt;if(h&&c.length>0){const h=(18*c.length+6)*s;e.globalAlpha=1,e.fillStyle=Ie(t.theme.background,.82),e.beginPath(),e.roundRect(a-3*s,n-9*s,h,wt*s,5*s),e.fill(),a+=2*s;for(const h of c){const c=`${i.id}::${h}`,d=a;this._buttons.push({id:c,x:d/s,y:o/s});const u=t.hoverId===c;u&&(e.fillStyle=Ie(t.theme.axisText,.16),e.beginPath(),e.roundRect(d,n-8*s,xt*s,xt*s,4*s),e.fill()),e.globalAlpha=l?.5:u?1:.75,e.fillStyle="close"===h&&u?"#ff6b6b":t.theme.axisText,St(e,h,d+8*s,n,r,s,i),e.globalAlpha=1,a+=18*s}}this._width=a/s,e.restore()}hitTest(e,t){const i=this._opts,s=(i.top??6)+(i.row??0)*wt;if(t<s||t>s+wt)return null;for(const t of this._buttons)if(e>=t.x&&e<=t.x+xt)return{externalId:t.id,zOrder:"top",distance:0,cursor:"pointer"};const r=Math.max(this._width,(i.left??8)+40)+130;return e>=(i.left??8)-4&&e<=r?{externalId:`${i.id}::row`,zOrder:"top",distance:0,cursor:"default"}:null}}const Tt={id:"timenav",buttons:["zoomOut","zoomIn",null,"panLeftBar","panRightBar"],size:26,gap:4,groupGap:16,bottomMargin:10,revealHeight:64,fadeSeconds:.12,labels:{zoomOut:"Zoom out",zoomIn:"Zoom in",panLeftBar:"Move left",panRightBar:"Move right"},hints:{},showTooltip:!0,font:11,radius:6,zOrder:"top"};class Mt{constructor(e={},t){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_boxes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_pointer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_opacity",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastFrameMs",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_revealTop",{enumerable:!0,configurable:!0,writable:!0,value:1/0}),this._opts={...Tt,...e},this._now=t??(()=>"undefined"!=typeof performance?performance.now():0)}attached(e){this._host=e}detached(){this._host=null}zOrder(){return this._opts.zOrder??"top"}options(){return this._opts}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}setPointer(e){const t=this._pointer;this._pointer=e,(null===t!=(null===e)||this._opacity>0||this._targetOpacity()>0)&&this._host?.requestUpdate()}_revealed(){return null!==this._pointer&&this._pointer.y>=this._revealTop}_targetOpacity(){return this._revealed()?1:0}animating(){return Math.abs(this._targetOpacity()-this._opacity)>.001}draw(e,t){const i=this._opts,s=t.dpr;this._revealTop=Math.max(0,t.plotHeight-i.revealHeight);const r=this._targetOpacity(),o=this._now(),n=null===this._lastFrameMs?0:Math.max(0,(o-this._lastFrameMs)/1e3);if(this._lastFrameMs=o,i.fadeSeconds<=0||n<=0)i.fadeSeconds<=0&&(this._opacity=r);else{const e=n/i.fadeSeconds;this._opacity+=Math.sign(r-this._opacity)*Math.min(e,Math.abs(r-this._opacity))}if(this._opacity<=.001)return this._boxes=[],void(this._opacity=0);const a=i.size;let l=0;for(let e=0;e<i.buttons.length;e++){null!==i.buttons[e]?(l+=a,e<i.buttons.length-1&&null!==i.buttons[e+1]&&(l+=i.gap)):l+=i.groupGap}const h=(t.plotWidth-l)/2,c=t.plotHeight-i.bottomMargin-a;this._boxes=[];let d=h;for(let e=0;e<i.buttons.length;e++){const t=i.buttons[e];null!==t?(this._boxes.push({action:t,x:d,y:c,w:a,h:a}),d+=a,e<i.buttons.length-1&&null!==i.buttons[e+1]&&(d+=i.gap)):d+=i.groupGap}const u=this._hoveredAction();e.save(),e.globalAlpha=this._opacity;for(const i of this._boxes)this._button(e,i,i.action===u,t,s);i.showTooltip&&null!==u&&this._tooltip(e,u,t,s),e.restore()}_hoveredAction(){const e=this._pointer;if(null===e)return null;for(const t of this._boxes)if(e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h)return t.action;return null}_button(e,t,i,s,r){const o=this._opts,n=t.x*r,a=t.y*r,l=t.w*r,h=t.h*r,c=Math.min(o.radius*r,l/2,h/2);e.beginPath(),e.roundRect(n,a,l,h,c),e.fillStyle=Ct(s.theme.background,s.theme.axisText,i?.28:.12),e.fill(),e.strokeStyle=Lt(s.theme.axisLine,i?1:.8),e.lineWidth=Math.max(1,Math.round(r)),e.stroke(),e.strokeStyle=s.theme.axisText,e.fillStyle=s.theme.axisText,e.lineWidth=Math.max(1,Math.round(1.5*r)),e.lineCap="round",e.lineJoin="round";const d=n+l/2,u=a+h/2,p=.22*Math.min(l,h);switch(e.beginPath(),t.action){case"zoomOut":e.moveTo(d-p,u),e.lineTo(d+p,u);break;case"zoomIn":e.moveTo(d-p,u),e.lineTo(d+p,u),e.moveTo(d,u-p),e.lineTo(d,u+p);break;case"panLeftBar":e.moveTo(d+.55*p,u-p),e.lineTo(d-.5*p,u),e.lineTo(d+.55*p,u+p);break;case"panRightBar":e.moveTo(d-.55*p,u-p),e.lineTo(d+.5*p,u),e.lineTo(d-.55*p,u+p)}e.stroke()}_tooltip(e,t,i,s){const r=this._opts,o=this._boxes.find(e=>e.action===t);if(void 0===o)return;const n=r.labels[t],a=r.hints[t];e.font=r.font*s+"px ui-sans-serif, system-ui, sans-serif",e.textBaseline="middle",e.textAlign="left";const l=7*s,h=8*s,c=e.measureText(n).width,d=2*l+c+(void 0===a?0:e.measureText(a).width+h+8*s),u=22*s;let p=(o.x+o.w/2)*s-d/2;p=Math.max(2*s,Math.min(p,i.plotWidth*s-d-2*s));const _=o.y*s-u-6*s;if(e.beginPath(),e.roundRect(p,_,d,u,5*s),e.fillStyle=Ct(i.theme.background,i.theme.axisText,.22),e.fill(),e.strokeStyle=Lt(i.theme.axisLine,.9),e.lineWidth=Math.max(1,Math.round(s)),e.stroke(),e.fillStyle=i.theme.axisText,e.fillText(n,p+l,_+u/2),void 0!==a){const t=p+l+c+h,r=e.measureText(a).width+8*s;e.beginPath(),e.roundRect(t-4*s,_+4*s,r,u-8*s,3*s),e.fillStyle=Ct(i.theme.background,i.theme.axisText,.42),e.fill(),e.fillStyle=i.theme.axisText,e.fillText(a,t,_+u/2)}}hitTest(e,t){if(this._opacity<.5)return null;for(const i of this._boxes)if(e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h)return{externalId:`${this._opts.id}::${i.action}`,zOrder:"top",distance:0,cursor:"pointer"};return null}}function Ct(e,t,i){const s=It(e),r=It(t);if(null===s||null===r)return e;const o=i<0?0:i>1?1:i;return`rgb(${Math.round(s[0]+(r[0]-s[0])*o)},${Math.round(s[1]+(r[1]-s[1])*o)},${Math.round(s[2]+(r[2]-s[2])*o)})`}function It(e){if(e.startsWith("#")){const t=e.slice(1),i=3===t.length?t.split("").map(e=>e+e).join(""):t,s=parseInt(i.slice(0,6),16);return Number.isNaN(s)?null:[s>>16&255,s>>8&255,255&s]}const t=/^rgba?\(([^)]+)\)$/.exec(e);if(null===t)return null;const i=t[1].split(",").map(e=>parseFloat(e));return[i[0],i[1],i[2]]}function Lt(e,t){if(e.startsWith("#")){const i=e.slice(1),s=3===i.length?i.split("").map(e=>e+e).join(""):i,r=parseInt(s.slice(0,6),16);return Number.isNaN(r)?e:`rgba(${r>>16&255},${r>>8&255},${255&r},${t})`}const i=/^rgba?\(([^)]+)\)$/.exec(e);if(null===i)return e;const s=i[1].split(",").map(e=>e.trim());return`rgba(${s[0]},${s[1]},${s[2]},${t})`}const jt=["#f5a623","#26a69a","#ab47bc","#ef5350","#26c6da","#8bc34a","#ff7043","#5c6bc0"];function kt(e){const t=Math.abs(e);return t>=1e9?(e/1e9).toFixed(2)+"B":t>=1e6?(e/1e6).toFixed(2)+"M":t>=1e3?(e/1e3).toFixed(2)+"K":String(Math.round(e))}function At(){return"undefined"!=typeof window&&window.devicePixelRatio?window.devicePixelRatio:1}class Ft{constructor(e,t={}){Object.defineProperty(this,"_container",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pixelRatio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_theme",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_panes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_loop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_dataLayer",{enumerable:!0,configurable:!0,writable:!0,value:new x}),Object.defineProperty(this,"_timeScale",{enumerable:!0,configurable:!0,writable:!0,value:new y}),Object.defineProperty(this,"_priceAxisWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_timeAxisHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resizeObserver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_height",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_hasFitContent",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_crosshairMode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_shortcuts",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_trading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pointerInside",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_keyTarget",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_conflate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_conflationFactor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_gridVert",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_gridHorz",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_cursorPane",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_cursor",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragStartX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragStartY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_pointers",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_pinch",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pinchPane",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_liveRegion",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragStartOffset",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastDragT",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragVelocity",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_kineticHandle",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_firstDataId",{enumerable:!0,configurable:!0,writable:!0,value:{value:null}}),Object.defineProperty(this,"_indicators",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_recomputing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drawingState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maximizedPane",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_savedWeights",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_legends",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_firstPaneIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_historyLoader",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadingHistory",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_clickCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_crosshairCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_pointerMoved",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_placementMode",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_legendOffset",{enumerable:!0,configurable:!0,writable:!0,value:{top:6,left:8}}),Object.defineProperty(this,"_downPane",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_downX",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_downLocalY",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_dragId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_hoverId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_overlayFrozen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragEndCb",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_axisDrag",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragMoved",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dragFrom",{enumerable:!0,configurable:!0,writable:!0,value:{time:0,price:0}}),Object.defineProperty(this,"_paneResize",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_axisStartCoord",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartMin",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartMax",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_axisStartSpacing",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_priceFormatter",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_priceScaleOptions",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_timeFormatter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_leftAxisWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_timeNav",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_timeNavPane",{enumerable:!0,configurable:!0,writable:!0,value:-1}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_onPointerEnter",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._pointerInside=!0}}),Object.defineProperty(this,"_onContextMenu",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(e.defaultPrevented)return;const t=this._panes[this._localPoint(e).pane];if(void 0!==t){this._cursor=null,this._cursorPane=null;try{const e=t.top.ctx;e.save(),e.globalCompositeOperation="destination-over",e.drawImage(t.base.element,0,0),e.restore(),this._overlayFrozen=!0}catch{}}}}),Object.defineProperty(this,"_onPointerDown",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(this._unfreezeOverlay(),"mouse"===e.pointerType&&0!==e.button)return;this._stopKinetic();const t=this._localPoint(e);this._pointers.set(e.pointerId,{x:t.x,y:t.y,pane:t.pane});try{this._container.setPointerCapture?.(e.pointerId)}catch{}if(this._pointers.size>=2)return void this._beginPinch();this._downPane=t.pane,this._downX=t.x,this._downLocalY=t.localY;const s=this._dividerAt(t.y);if(null!==s){const e=this._paneLayout();return this._paneResize={index:s,startY:t.y,aWeight:this._panes[s].weight,bWeight:this._panes[s+1].weight,aHeight:e[s].height,bHeight:e[s+1].height},void(this._dragging=!1)}const r=Math.max(0,this._width-this._priceAxisWidth),o=t.x>=r,n=t.pane===this._panes.length-1&&t.localY>=t.paneHeight-this._timeAxisHeight;if(o){this._axisDrag="price",this._axisStartCoord=t.localY;const e=this._panes[t.pane].priceScale.priceRange();return this._axisStartMin=e.min,this._axisStartMax=e.max,void(this._dragging=!1)}if(n)return this._axisDrag="time",this._axisStartCoord=t.x,this._axisStartSpacing=this._timeScale.barSpacing,void(this._dragging=!1);if(this._placementMode)return this._dragging=!1,void(this._pointerMoved=!1);const a=this._panes[t.pane]?.hitTestPrimitives(t.x-this._leftAxisWidth,t.localY,this._renderContext(t.pane===this._panes.length-1));if(a&&(!0===a.draggable||"ns-resize"===a.cursor&&null!==this._dragCb))return this._dragId=a.externalId,this._dragMoved=!1,this._ensureScaled(t.pane),this._dragFrom={time:this._xToTime(t.x),price:this._panes[t.pane].priceScale.yToPrice(t.localY)},this._setHover(a),this._cursor=null,this._cursorPane=null,this.invalidate(e=>e.invalidateGlobal(i.Cursor)),this._dragging=!1,void(this._pointerMoved=!1);this._dragging=!0,this._pointerMoved=!1,this._dragStartX=t.x,this._dragStartY=t.y,this._lastDragY=t.y,this._dragStartOffset=this._timeScale.rightOffset,this._lastDragX=t.x,this._lastDragT=this._now(),this._dragVelocity=0}}),Object.defineProperty(this,"_onPointerMove",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(this._unfreezeOverlay(),"mouse"===e.pointerType&&!(1&e.buttons)&&(this._dragging||null!==this._dragId||null!==this._axisDrag))return void this._onPointerUp(e);const t=this._localPoint(e);if(this._pointers.has(e.pointerId)&&this._pointers.set(e.pointerId,{x:t.x,y:t.y,pane:t.pane}),null===this._pinch){if("price"===this._axisDrag){const e=t.localY-this._axisStartCoord,s=Math.exp(.005*e),r=(this._axisStartMin+this._axisStartMax)/2,o=(this._axisStartMax-this._axisStartMin)/2*s,n=this._panes[this._downPane].priceScale;return n.setPriceRange({min:r-o,max:r+o}),n.setAutoScale(!1),void this.invalidate(e=>e.invalidatePane(this._downPane,{level:i.Light,autoScale:!1}))}if(null!==this._paneResize){const e=this._paneResize,s=e.aHeight+e.bHeight,r=e.aWeight+e.bWeight,o=Math.min(24,s/4),n=Math.max(o,Math.min(s-o,e.aHeight+(t.y-e.startY)));return this._panes[e.index].weight=n/s*r,this._panes[e.index+1].weight=r-this._panes[e.index].weight,this._relayout(),void this.invalidate(e=>e.invalidateGlobal(i.Full))}if("time"===this._axisDrag){const e=t.x-this._axisStartCoord;return this._timeScale.setBarSpacing(this._axisStartSpacing*Math.exp(.005*e)),void this.invalidate(e=>e.invalidateGlobal(i.Full))}if(this._placementMode&&this._pointers.size>0&&(Math.abs(t.x-this._downX)>3||Math.abs(t.localY-this._downLocalY)>3)&&(this._pointerMoved=!0),null!==this._dragId){(Math.abs(t.x-this._downX)>3||Math.abs(t.localY-this._downLocalY)>3)&&(this._dragMoved=!0);const e=this._panes[this._downPane].priceScale.yToPrice(t.localY),i=this._xToTime(t.x);return this._dragCb?.(this._dragId,e,i),void this.emit("drag",{id:this._dragId,price:e,time:i,paneIndex:this._downPane,fromPrice:this._dragFrom.price,fromTime:this._dragFrom.time})}if(this._dragging){const e=t.x-this._dragStartX;(Math.abs(e)>3||Math.abs(t.y-this._dragStartY)>3)&&(this._pointerMoved=!0),this._timeScale.setRightOffset(this._dragStartOffset-e/this._timeScale.barSpacing),this._panes[this._downPane]?.priceScale.panByPixels(t.y-this._lastDragY),this._lastDragY=t.y;const s=this._now(),r=s-this._lastDragT;return r>0&&(this._dragVelocity=(t.x-this._lastDragX)/r),this._lastDragX=t.x,this._lastDragT=s,this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),void this._emitViewport("pan")}this._updateCursor(t.pane,t.x,t.localY,t.y)}else this._updatePinch()}}),Object.defineProperty(this,"_onPointerUp",{enumerable:!0,configurable:!0,writable:!0,value:e=>{try{this._container.releasePointerCapture?.(e.pointerId)}catch{}if(this._pointers.delete(e.pointerId),null===this._pinch){if(null!==this._paneResize)return this._paneResize=null,void this.emit("paneResized",{paneIndex:this._downPane});if(null===this._axisDrag){if(null!==this._dragId){const t=this._localPoint(e),s=this._panes[this._downPane].priceScale.yToPrice(t.localY),r=this._xToTime(t.x);if(this._dragEndCb?.(this._dragId,s,r),this.emit("drag:end",{id:this._dragId,price:s,time:r,paneIndex:this._downPane}),!this._dragMoved){const e=this._dragId;this._clickCb?.(e),this.emit("click",{id:e,price:s,time:r,paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}})}this._dragId=null;const o="touch"===e.pointerType?null:this._panes[t.pane]?.hitTestPrimitives(t.x-this._leftAxisWidth,t.localY,this._renderContext(t.pane===this._panes.length-1))??null;return this._setHover(o),void this.invalidate(e=>e.invalidateGlobal(i.Light))}if(this._dragging=!1,this._placementMode&&this._pointerMoved){const t=this._localPoint(e);return this._ensureScaled(this._downPane),this.emit("click",{id:null,price:this._panes[this._downPane]?.priceScale.yToPrice(this._downLocalY)??null,time:this._xToTime(this._downX),paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}}),void this.emit("click",{id:null,price:this._panes[this._downPane]?.priceScale.yToPrice(t.localY)??null,time:this._xToTime(t.x),paneIndex:this._downPane,point:{x:t.x,y:t.localY},viaDrag:!0})}if(!this._pointerMoved){const e=this._downPane===this._panes.length-1,t=this._panes[this._downPane]?.hitTestPrimitives(this._downX-this._leftAxisWidth,this._downLocalY,this._renderContext(e));if(t&&this._handleLegendAction(t.externalId))return;return t&&this._clickCb?.(t.externalId),this._ensureScaled(this._downPane),void this.emit("click",{id:t?.externalId??null,price:this._panes[this._downPane]?.priceScale.yToPrice(this._downLocalY)??null,time:this._xToTime(this._downX),paneIndex:this._downPane,point:{x:this._downX,y:this._downLocalY}})}ze.shouldAnimate(this._dragVelocity)&&this._startKinetic(this._dragVelocity)}else this._axisDrag=null}else this._pointers.size<2&&(this._pinch=null,this._dragging=!1)}}),Object.defineProperty(this,"_onPointerUpNative",{enumerable:!0,configurable:!0,writable:!0,value:e=>{"mouse"===e.pointerType&&0!==e.button||this._onPointerUp(e)}}),Object.defineProperty(this,"_onPointerLeave",{enumerable:!0,configurable:!0,writable:!0,value:()=>{if(this._pointerInside=!1,this._feedTimeNav(null),null===this._dragId&&this._setHover(null),null!==this._cursor){this._cursor=null,this._cursorPane=null,this.invalidate(e=>e.invalidateGlobal(i.Cursor));for(const e of this._indicators)e.updateLegendValues();const e={time:null,index:null,price:null,bar:null,point:null,paneIndex:null};this._crosshairCb?.(e),this.emit("crosshair:move",e)}}}),Object.defineProperty(this,"_onWheel",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._unfreezeOverlay(),e.preventDefault();const t=this._localPoint(e),s=e.deltaY<0?1.1:1/1.1;this._timeScale.zoomAtX(t.x,s),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._emitViewport("zoom")}}),Object.defineProperty(this,"_onDblClick",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.emit("dblclick",{}),this._placementMode||this.resetScale()}}),Object.defineProperty(this,"_onKeyDown",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._unfreezeOverlay();const t=this._shortcuts;if(null===t||st.shouldIgnore(e.target)||!this._shortcutsActive())return;const s=t.resolve(e);if(null===s)return;let r=this._runShortcut(s);r||(r=t.runCustom(s)),r&&(e.preventDefault(),t.emitTrigger(s),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary())}}),this._container=e,this._doc=t.document??e.ownerDocument,this._pixelRatio=t.pixelRatio??At,this._theme=t.theme??ue,this._priceAxisWidth=t.priceAxisWidth??56,void 0!==t.legendOffset?.top&&(this._legendOffset.top=t.legendOffset.top),void 0!==t.legendOffset?.left&&(this._legendOffset.left=t.legendOffset.left),this._timeAxisHeight=t.timeAxisHeight??22,this._crosshairMode=t.crosshairMode??"normal";const s=t.shortcuts;this._shortcuts=!1===s?null:s instanceof st?s:new st(s??{}),this._now=t.now??(()=>"undefined"!=typeof performance?performance.now():0),this._conflate=t.conflate??!1,this._conflationFactor=t.conflationFactor??1,this._priceFormatter=t.priceFormatter??null,this._priceScaleOptions=t.priceScale??null,this._timeFormatter=t.timeFormatter,this._gridVert=t.grid?.vertLines??!0,this._gridHorz=t.grid?.horzLines??!0;const r=t.timeNavigator??!0;!1!==r&&(this._timeNav=new Mt({...!0===r?{}:r,hints:this._navHints(!0===r?void 0:r)},this._now));const n="function"==typeof getComputedStyle?getComputedStyle(e).position:e.style.position;n&&"static"!==n||(e.style.position="relative"),e.style.display="flex",e.style.flexDirection="column",e.style.background=this._theme.background,e.style.touchAction="none",e.getAttribute("role")||e.setAttribute("role","application"),e.setAttribute("aria-label",t.ariaLabel??"Interactive financial chart"),e.hasAttribute("tabindex")||(e.tabIndex=0);const a=this._doc.createElement("div");a.setAttribute("aria-live","polite");const l=a.style;l.position="absolute",l.width="1px",l.height="1px",l.overflow="hidden",l.clip="rect(0 0 0 0)",l.whiteSpace="nowrap",l.border="0",l.padding="0",l.margin="-1px",e.appendChild(a),this._liveRegion=a,this._loop=t.raf?new o(()=>this._onFrame(),t.raf.schedule,t.raf.cancel):new o(()=>this._onFrame()),this._addPane(),this._observeSize(),this._attachInput(),this._timeScale.setChangeHandler(()=>this.invalidate(e=>e.invalidateGlobal(i.Full))),this.applySize(e.clientWidth,e.clientHeight),"function"==typeof queueMicrotask&&queueMicrotask(()=>this.emit("ready",{}))}setHistoryLoader(e){this._historyLoader=e}historyLoadComplete(){this._loadingHistory=!1}get dataLayer(){return this._dataLayer}get timeScale(){return this._timeScale}setVisibleLogicalRange(e){this._timeScale.setVisibleLogicalRange(e)}getVisibleLogicalRange(){return this._timeScale.visibleRange()}fitContent(){this._dataLayer.length<=0||(this._timeScale.fitContent(this._dataLayer.length),this.invalidate(e=>e.invalidateGlobal(i.Full)))}get shortcuts(){return this._shortcuts}get trading(){return null===this._trading&&(this._trading=new ut(this)),this._trading}addSeries(e,t={}){return this._createSeries(e,t,!0)}_createSeries(e,t,s){const r=this._dataLayer.createSeries(),o=t.paneIndex??0;this._ensurePane(o),s&&null===this._firstDataId.value&&z(e).isPriceSeries&&(this._firstDataId.value=r,this._firstPaneIndex=o);const n=function(e,t,i,s="right"){return{dataId:e,type:t,style:{...z(t).defaultStyle,...i},scaleId:s}}(r,e,t.style,t.priceScaleId??"right");if(this._panes[o].addSeries(n),this._recomputeLeftAxis(),t.priceFormat){const e=this._panes[o].scaleOf(n),i=t.priceFormat;if("custom"===i.type)e.setPriceFormatter(i.formatter);else if("volume"===i.type)e.setPriceFormatter(kt);else{const t=i.minMove??(void 0!==i.precision?Math.pow(10,-i.precision):void 0);void 0!==t&&e.setOptions({minMove:t})}}return{setData:e=>this._setData(r,e.map(We)),prependData:e=>this._prependData(r,e.map(We)),update:e=>this._updateBar(r,We(e)),getData:()=>this._dataLayer.indexedBars(r).map(e=>e.bar),applyOptions:e=>{Object.assign(n.style,e),this.invalidate(e=>e.invalidateGlobal(i.Full))},remove:()=>{this._panes[o].removeSeries(n),this._dataLayer.removeSeries(r),this._firstDataId.value===r&&(this._firstDataId.value=null),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),this._recomputeLeftAxis(),this.invalidate(e=>e.invalidateGlobal(i.Full))},priceScale:()=>this._panes[o].scaleOf(n),createMarkers:()=>{const e=new gt(r);return this._addPrimitive(o,e),e}}}addPriceLine(e,t=0){const i=new rt(e);return this._addPrimitive(t,i),i}addEventMarkers(e=0){const t=new yt;return this._addPrimitive(e,t),t}addIndicator(e,t={},i={}){const s=ye(e),r=new Re(this._indicatorHost(),s,this._distinctColors(s,t),i.paneIndex);return this._indicators.push(r),r}_distinctColors(e,t){const i=this._indicators.filter(t=>t.indicatorId===e.id).length;if(0===i)return t;const s={...t},r=e.plots;for(let e=0;e<r.length;e++){const t=_e(r[e]).color;void 0===s[t]&&(s[t]=jt[(i*r.length+e)%jt.length])}return s}indicators(){return this._indicators}removeIndicator(e){const t=this._indicators.findIndex(t=>t.id===e);if(t<0)return!1;const{indicatorId:i,paneIndex:s}=this._indicators[t];return this._indicators[t].remove(),this._indicators.splice(t,1),this.emit("indicatorRemoved",{instanceId:e,indicatorId:i,paneIndex:s}),s>0&&0===this._panes[s]?.series().length&&this.removePane(s),!0}_indicatorHost(){return{addIndicatorLegend:e=>{const t=0===e.row&&e.paneIndex>0?["hide","settings","up","down","maximize","close"]:["hide","settings","close"],i=new Ot({...e,actions:t});return this._addPrimitive(e.paneIndex,i),i},removeIndicatorLegend:e=>{this.removePrimitive(e),this._restackLegends()},legendRowsOn:e=>this._legends.filter(t=>t.paneIndex===e).length,addIndicatorSeries:(e,t,i,s)=>this._createSeries(e,{paneIndex:t,style:i,priceScaleId:s},!1),addIndicatorLevel:(e,t,i,s,r,o)=>this.addPriceLine({price:e,color:t,lineWidth:1,dashed:i,leftLabel:s,id:r},o),removeIndicatorLevel:e=>this.removePrimitive(e),addIndicatorFill:(e,t)=>this._addPrimitive(t,e),removeIndicatorFill:e=>this.removePrimitive(e),sourceBars:()=>null===this._firstDataId.value?[]:this._dataLayer.seriesBars(this._firstDataId.value),nextPaneIndex:()=>this._panes.length,setPaneRange:(e,t)=>{const i=this._panes[e];void 0!==i&&(null===t?i.priceScale.setAutoScale(!0):(i.priceScale.setAutoScale(!1),i.priceScale.setPriceRange(t)))}}}_recomputeIndicators(){if(!this._recomputing&&0!==this._indicators.length){this._recomputing=!0;try{for(const e of this._indicators)e.recompute()}finally{this._recomputing=!1}}}subscribeClick(e){this._clickCb=e}subscribeCrosshairMove(e){this._crosshairCb=e}subscribeDrag(e,t){this._dragCb=e,this._dragEndCb=t??null}_ensureScaled(e){const t=this._panes[e];void 0===t||t.priceScale.scaled||t.autoscale(this._renderContext(e===this._panes.length-1))}_xToTime(e){return this._dataLayer.indexToTimeFloat(this._timeScale.xToIndex(e-this._leftAxisWidth))}timeToCoordinate(e){return this._timeScale.indexToX(this._dataLayer.timeToIndexFloat(e))+this._leftAxisWidth}coordinateToTime(e){return this._xToTime(e)}on(e,t){let i=this._listeners.get(e);return void 0===i&&(i=new Set,this._listeners.set(e,i)),i.add(t),()=>this.off(e,t)}once(e,t){const i=s=>{this.off(e,i),t(s)};return this.on(e,i)}off(e,t){void 0!==t?this._listeners.get(e)?.delete(t):this._listeners.delete(e)}emit(e,t){const i=this._listeners.get(e);if(void 0!==i)for(const e of[...i])try{e(t)}catch{}}_emitViewport(e){if(void 0===this._listeners.get(e))return;const t=this._timeScale.visibleRange();this.emit(e,{from:this._dataLayer.indexToTime(Math.round(t.from))??null,to:this._dataLayer.indexToTime(Math.round(t.to))??null,logicalFrom:t.from,logicalTo:t.to})}addPrimitive(e,t=0){this._addPrimitive(t,e)}priceToCoordinate(e,t=0){this._ensureScaled(t);const i=this._panes[t];if(void 0===i)return null;return(this._paneLayout()[t]?.top??0)+i.priceScale.priceToY(e)}coordinateToPrice(e,t=0){this._ensureScaled(t);const i=this._panes[t];if(void 0===i)return null;const s=this._paneLayout()[t]?.top??0;return i.priceScale.yToPrice(e-s)}setGridOptions(e){void 0!==e.vertLines&&(this._gridVert=e.vertLines),void 0!==e.horzLines&&(this._gridHorz=e.horzLines),this.invalidate(e=>e.invalidateGlobal(i.Full))}gridOptions(){return{vertLines:this._gridVert,horzLines:this._gridHorz}}takeScreenshot(){const e=this._pixelRatio(),t=this._doc.createElement("canvas");t.width=Math.max(1,Math.round(this._width*e)),t.height=Math.max(1,Math.round(this._height*e));const i=t.getContext("2d");if(null===i)return t;i.fillStyle=this._theme.background,i.fillRect(0,0,t.width,t.height);const s=this._paneLayout();for(let t=0;t<this._panes.length;t++){const r=Math.round((s[t]?.top??0)*e);i.drawImage(this._panes[t].base.element,0,r),i.drawImage(this._panes[t].top.element,0,r)}return t}_addPrimitive(e,t){this._ensurePane(e);const s={requestUpdate:()=>this.invalidate(t=>t.invalidatePane(e,{level:i.Light,autoScale:!1}))};this._panes[e].addPrimitive(t,s),t instanceof Ot&&(this._legends.push({legend:t,paneIndex:e}),this._restackLegends()),this.invalidate(t=>t.invalidatePane(e,{level:i.Light,autoScale:!1}))}removePrimitive(e){const t=this._legends.findIndex(t=>t.legend===e);t>=0&&this._legends.splice(t,1);for(let s=0;s<this._panes.length;s++)if(this._panes[s].removePrimitive(e))return t>=0&&this._restackLegends(),void this.invalidate(e=>e.invalidatePane(s,{level:i.Light,autoScale:!1}))}_restackLegends(){const e=new Map;for(const t of this._legends){const i=e.get(t.paneIndex)??0;t.legend.setOptions({row:i}),e.set(t.paneIndex,i+1)}this._syncLegendOffsets()}_syncLegendOffsets(){const e=this._paneLayout();for(const t of this._legends){if(!t.legend.options().id.startsWith("indicator:"))continue;const i=(e[t.paneIndex]?.top??Number.POSITIVE_INFINITY)<=12;t.legend.setOptions(i?{top:this._legendOffset.top,left:this._legendOffset.left}:{top:6,left:8})}}tradeHost(e=0){return{addPrimitive:t=>this._addPrimitive(e,t),removePrimitive:e=>this.removePrimitive(e)}}_updateBar(e,t){const s=this._timeScale.rightOffset>=0,r=this._dataLayer.update(e,t);this._timeScale.setBaseIndex(this._dataLayer.baseIndex),"append"!==r||s||this._timeScale.setRightOffset(this._timeScale.rightOffset-1),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_ensurePane(e){let t=!1;for(;this._panes.length<=e;)this._addPane(0===this._panes.length?1:.32),t=!0;t&&this._relayout()}_setData(e,t){this._dataLayer.setSeriesData(e,t),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),!this._hasFitContent&&this._dataLayer.length>0&&(this._timeScale.setWidth(Math.max(0,this._width-this._priceAxisWidth-this._leftAxisWidth)),this._timeScale.fitContent(this._dataLayer.length),this._hasFitContent=!0),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_prependData(e,t){this._dataLayer.addBars(e,t),this._timeScale.setBaseIndex(this._dataLayer.baseIndex),e===this._firstDataId.value&&this._recomputeIndicators(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._updateAccessibleSummary()}_addPane(e=1){const t=new he(this._doc);return t.weight=e,t.priceScale.setPriceFormatter(this._priceFormatter),this._priceScaleOptions&&t.priceScale.setOptions(this._priceScaleOptions),this._panes.push(t),this._container.appendChild(t.element),t}setPriceFormatter(e){this._priceFormatter=e;for(const t of this._panes)t.priceScale.setPriceFormatter(e);this.invalidate(e=>e.invalidateGlobal(i.Full))}setTimeFormatter(e){this._timeFormatter=e,this.invalidate(e=>e.invalidateGlobal(i.Full))}setPlacementMode(e){this._placementMode=e}setTheme(e){this._theme=e,this._container.style.background=e.background,this.invalidate(e=>e.invalidateGlobal(i.Full))}applyOptions(e){e.theme&&this.setTheme(e.theme),e.grid&&this.setGridOptions(e.grid),void 0!==e.priceFormatter&&this.setPriceFormatter(e.priceFormatter),"timeFormatter"in e&&this.setTimeFormatter(e.timeFormatter),e.crosshairMode&&(this._crosshairMode=e.crosshairMode)}panes(){return this._panes}getState(){const e=this._panes.map(e=>{const t=e.priceScale,i=t.options,s={weight:e.weight,priceScale:{marginTop:i.marginTop,marginBottom:i.marginBottom,minMove:i.minMove,mode:i.mode,inverted:i.inverted,autoScale:t.autoScale}};return t.autoScale||(s.priceScale.range={...t.priceRange()}),s}),t=[];this._panes.forEach((e,i)=>{for(const s of e.series())t.push({type:s.type,style:{...s.style},paneIndex:i,priceScaleId:s.scaleId})});const i={version:1,viewport:{...this.getVisibleLogicalRange()},barSpacing:this._timeScale.barSpacing,grid:this.gridOptions(),crosshairMode:this._crosshairMode,panes:e,series:t,indicators:this._indicators.map(e=>({indicatorId:e.indicatorId,settings:e.settings(),paneIndex:e.paneIndex}))};return void 0!==this._drawingState&&(i.drawings=this._drawingState),i}restoreState(e){const t=e;if(null===t||"object"!=typeof t||"number"!=typeof t.version)return{applied:!1,series:[],indicators:0,reason:"not a chart state object"};if(t.version>1)return{applied:!1,series:[],indicators:0,reason:`state version ${t.version} is newer than 1`};t.grid&&this.setGridOptions(t.grid),t.crosshairMode&&(this._crosshairMode=t.crosshairMode),t.panes&&(t.panes.forEach((e,t)=>{this._ensurePane(t);const i=this._panes[t];i.weight=e.weight;const s=i.priceScale;s.setOptions({marginTop:e.priceScale.marginTop,marginBottom:e.priceScale.marginBottom,minMove:e.priceScale.minMove,mode:e.priceScale.mode,inverted:e.priceScale.inverted}),s.setAutoScale(e.priceScale.autoScale),!e.priceScale.autoScale&&e.priceScale.range&&s.setPriceRange(e.priceScale.range)}),this._relayout());let s=0;if(t.indicators){for(const e of this._indicators)e.remove();this._indicators.length=0;for(const e of t.indicators)we(e.indicatorId)&&(this._indicators.push(new Re(this._indicatorHost(),ye(e.indicatorId),e.settings,e.paneIndex)),s+=1)}for(let e=this._panes.length-1;e>0;e--)0===this._panes[e].series().length&&this.removePane(e);return this._drawingState=t.drawings,void 0!==t.barSpacing&&this._timeScale.setBarSpacing(t.barSpacing),t.viewport&&this._dataLayer.length>0&&this.setVisibleLogicalRange(t.viewport),this.invalidate(e=>e.invalidateGlobal(i.Full)),{applied:!0,series:t.series??[],indicators:s}}drawingState(){return this._drawingState}setDrawingState(e){this._drawingState=e}invalidate(e){null===this._pending&&(this._pending=new s),e(this._pending),this._loop.requestFrame()}applySize(e,t){e===this._width&&t===this._height||(this._width=e,this._height=t,this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("resize",{width:e,height:t}))}_relayout(){this._syncTimeNavPane(),this._syncLegendOffsets();const e=this._pixelRatio(),t=this._weightTotal();for(const i of this._panes){const s=this._height*i.weight/t;i.element.style.flex=`0 0 ${s}px`;const r=i===this._panes[0];i.element.style.borderTopWidth=r?"0px":"1px",i.element.style.borderTopColor=r?"transparent":this._theme.paneSeparator,i.resize(this._width,s,e);const o=i===this._panes[this._panes.length-1];i.setScaleHeights(Math.max(0,s-(o?this._timeAxisHeight:0)))}this._timeScale.setWidth(Math.max(0,this._width-this._priceAxisWidth-this._leftAxisWidth))}_recomputeLeftAxis(){const e=this._panes.some(e=>e.hasLeftScale())?this._priceAxisWidth:0;e!==this._leftAxisWidth&&(this._leftAxisWidth=e,this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)))}_weightTotal(){let e=0;for(const t of this._panes)e+=t.weight;return e<=0?1:e}_dividerAt(e){const t=this._paneLayout();for(let i=0;i<t.length-1;i++){const s=t[i].top+t[i].height;if(Math.abs(e-s)<=Ft.DIVIDER_GRAB)return i}return null}setPaneWeight(e,t){const s=this._panes[e];void 0!==s&&(s.weight=Math.max(.05,t),this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)))}paneWeight(e){return this._panes[e]?.weight??0}removePane(e){if(e<=0||e>=this._panes.length)return!1;for(let t=this._indicators.length-1;t>=0;t--)this._indicators[t].paneIndex===e&&(this._indicators[t].remove(),this._indicators.splice(t,1));const t=this._panes[e];for(const e of[...t.series()])t.removeSeries(e),this._dataLayer.removeSeries(e.dataId),this._firstDataId.value===e.dataId&&(this._firstDataId.value=null);t.destroy(),this._panes.splice(e,1),null!==this._savedWeights&&(this._savedWeights.splice(e,1),this._savedWeights.length<=1&&(this._savedWeights=null));for(const t of this._indicators)t.paneIndex>e&&t.shiftPane(-1);return this._timeScale.setBaseIndex(this._dataLayer.baseIndex),this._recomputeLeftAxis(),this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneRemoved",{paneIndex:e}),!0}movePane(e,t){const s=e+t;if(e<=0||s<=0||e>=this._panes.length||s>=this._panes.length)return!1;const r=this._panes;[r[e],r[s]]=[r[s],r[e]];for(const i of this._indicators)i.paneIndex===e?i.shiftPane(t):i.paneIndex===s&&i.shiftPane(-t);for(const e of r)this._container.appendChild(e.element);return this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneMoved",{from:e,to:s}),!0}maximizePane(e){if(e<0||e>=this._panes.length)return!1;if(this._maximizedPane===e){const e=this._savedWeights;null!==e&&this._panes.forEach((t,i)=>{t.weight=e[i]??t.weight}),this._maximizedPane=null,this._savedWeights=null}else null===this._savedWeights&&(this._savedWeights=this._panes.map(e=>e.weight)),this._panes.forEach((t,i)=>{t.weight=i===e?1:.001}),this._maximizedPane=e;return this._relayout(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this.emit("paneMaximized",{paneIndex:this._maximizedPane}),!0}maximizedPane(){return this._maximizedPane}_handleLegendAction(e){const t=e.lastIndexOf("::");if(t<0)return!1;const s=e.slice(t+2);if(null!==this._timeNav&&e.startsWith(`${this._timeNav.options().id}::`))return this._runShortcut(s)&&this.invalidate(e=>e.invalidateGlobal(i.Full)),!0;if("row"===s&&!e.startsWith("indicator:"))return!0;if(!e.startsWith("indicator:"))return!1;const r=e.slice(10,t);if("row"===s)return!0;const o=this._indicators.find(e=>e.id===r);if(void 0===o)return!1;const n=o.paneIndex;switch(s){case"close":return this.removeIndicator(r),!0;case"hide":return o.setVisible(!o.visible()),!0;case"up":return this.movePane(n,-1),!0;case"down":return this.movePane(n,1),!0;case"maximize":return this.maximizePane(n),!0;case"settings":return this.emit("indicatorSettings",{instanceId:r,indicatorId:o.indicatorId,paneIndex:n}),!0;default:return!1}}_paneLayout(){const e=this._weightTotal(),t=[];let i=0;for(const s of this._panes){const r=this._height*s.weight/e;t.push({top:i,height:r}),i+=r}return t}_navHints(e){if(void 0!==e?.hints)return e.hints;if(null===this._shortcuts)return{};const t={};for(const e of this._shortcuts.list()){if("zoomIn"!==e.command&&"zoomOut"!==e.command)continue;const i=e.combos[0];void 0!==i&&(t[e.command]=Bt(i))}return t}_syncTimeNavPane(){if(null===this._timeNav)return;const e=this._panes.length-1;e===this._timeNavPane||e<0||(this._timeNavPane>=0&&this._panes[this._timeNavPane]?.removePrimitive(this._timeNav),this._addPrimitive(e,this._timeNav),this._timeNavPane=e)}_feedTimeNav(e){const t=this._timeNav;null!==t&&(t.setPointer(e),t.animating()&&this.invalidate(e=>e.invalidateGlobal(i.Light)))}_renderContext(e){return{timeScale:this._timeScale,dataLayer:this._dataLayer,dpr:this._pixelRatio(),priceAxisWidth:this._priceAxisWidth,timeAxisHeight:this._timeAxisHeight,showTimeAxis:e,conflate:this._conflate,conflationFactor:this._conflationFactor,theme:this._theme,showVertGrid:this._gridVert,showHorzGrid:this._gridHorz,timeFormatter:this._timeFormatter,leftAxisWidth:this._leftAxisWidth,hoverId:this._hoverId,dragId:this._dragId}}_observeSize(){"undefined"!=typeof ResizeObserver&&(this._resizeObserver=new ResizeObserver(e=>{const t=e[0];t&&this.applySize(t.contentRect.width,t.contentRect.height)}),this._resizeObserver.observe(this._container))}_onFrame(){const e=this._pending;if(this._pending=null,null===e||e.isEmpty())return;const t=e.globalLevel;for(let s=0;s<this._panes.length;s++){const r=this._panes[s],o=e.paneInvalidation(s),n=Math.max(t,o?.level??i.None),a=s===this._panes.length-1,l=this._renderContext(a);if((n>=i.Full||o?.autoScale)&&r.autoscale(l),n>=i.Light&&r.paintBase(l),n>=i.Cursor&&!this._overlayFrozen){const e=null===this._cursor?null:{x:this._cursor.x,yLocal:s===this._cursorPane?this._cursor.y:null,showTimeTag:a};r.paintTop(e,l)}}}_attachInput(){if("undefined"==typeof window)return;const e=this._container;e.addEventListener("pointerdown",this._onPointerDown),e.addEventListener("pointermove",this._onPointerMove),e.addEventListener("pointerup",this._onPointerUpNative),e.addEventListener("pointercancel",this._onPointerUp),e.addEventListener("pointerleave",this._onPointerLeave),e.addEventListener("wheel",this._onWheel,{passive:!1}),e.addEventListener("dblclick",this._onDblClick),e.addEventListener("pointerenter",this._onPointerEnter),e.addEventListener("contextmenu",this._onContextMenu);const t="function"==typeof this._doc.addEventListener?this._doc:e;t.addEventListener("keydown",this._onKeyDown),this._keyTarget=t}_unfreezeOverlay(){this._overlayFrozen&&(this._overlayFrozen=!1,this.invalidate(e=>e.invalidateGlobal(i.Cursor)))}_localPoint(e){const t=this._container.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top,r=this._paneLayout();let o=0;for(let e=0;e<r.length;e++)s>=r[e].top&&(o=e);const n=r[o]??{top:0,height:this._height};return{x:i,y:s,pane:o,localY:s-n.top,paneHeight:n.height}}resetScale(){this._dataLayer.length>0&&this._timeScale.fitContent(this._dataLayer.length);for(const e of this._panes)e.priceScale.setAutoScale(!0);this.invalidate(e=>e.invalidateGlobal(i.Full))}_beginPinch(){const e=[...this._pointers.values()];this._pinch=pt(e[0],e[1]),this._pinchPane=e[0].pane,this._dragging=!1,this._axisDrag=null,this._dragId=null,this._pointerMoved=!0}_updatePinch(){const e=[...this._pointers.values()];if(e.length<2||null===this._pinch)return;const t=pt(e[0],e[1]),s=function(e,t){return{factor:e.dist>0?t.dist/e.dist:1,dx:t.cx-e.cx,dy:t.cy-e.cy}}(this._pinch,t);1!==s.factor&&this._timeScale.zoomAtX(t.cx,s.factor),this._timeScale.setRightOffset(this._timeScale.rightOffset-s.dx/this._timeScale.barSpacing),this._panes[this._pinchPane]?.priceScale.panByPixels(s.dy),this._pinch=t,this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),this._emitViewport(1!==s.factor?"zoom":"pan")}_shortcutsActive(){if(null===this._shortcuts)return!1;if("global"===this._shortcuts.scope||this._pointerInside)return!0;const e=this._doc.activeElement;return null!==e&&(e===this._container||!0===this._container.contains?.(e))}_runShortcut(e){const t=this._timeScale;switch(e){case"panLeftBar":return t.setRightOffset(t.rightOffset-1),!0;case"panRightBar":return t.setRightOffset(t.rightOffset+1),!0;case"panLeft":return t.setRightOffset(t.rightOffset-2),!0;case"panRight":return t.setRightOffset(t.rightOffset+2),!0;case"panLeftFast":return t.setRightOffset(t.rightOffset-10),!0;case"panRightFast":return t.setRightOffset(t.rightOffset+10),!0;case"panUp":return this._panes[0]?.priceScale.panByPixels(20),!0;case"panDown":return this._panes[0]?.priceScale.panByPixels(-20),!0;case"zoomIn":return t.zoomAtX(this._width/2,1.1),!0;case"zoomOut":return t.zoomAtX(this._width/2,1/1.1),!0;case"resetScale":return this.resetScale(),!0;case"fitContent":return this._dataLayer.length>0&&t.fitContent(this._dataLayer.length),!0;case"screenshot":return this.downloadScreenshot(),!0;case"toggleGridVert":return this.setGridOptions({vertLines:!this._gridVert}),!0;case"toggleGridHorz":return this.setGridOptions({horzLines:!this._gridHorz}),!0;case"toggleCrosshairMagnet":return this._crosshairMode="magnet"===this._crosshairMode?"normal":"magnet",!0;default:return!1}}downloadScreenshot(e="chart.png"){try{const t=this.takeScreenshot(),i=this._doc.createElement("a");i.href=t.toDataURL("image/png"),i.download=e,i.click()}catch{}}_updateAccessibleSummary(){if(null===this._liveRegion)return;const e=this._dataLayer.length;let t=`${e} bar${1===e?"":"s"}`;if(null!==this._firstDataId.value&&void 0!==this._panes[0]){const e=this._dataLayer.lastIndexedBar(this._firstDataId.value);null!==e&&(t+=`, latest price ${this._panes[0].priceScale.format(e.bar.close)}`)}this._liveRegion.textContent=`Financial chart, ${t}`}_setHover(e){const t=e?.externalId??null;this._container.style.cursor=e?.cursor??"",t!==this._hoverId&&(this._hoverId=t,this.invalidate(e=>e.invalidateGlobal(i.Light)),this.emit("hover",{id:t}))}_updateCursor(e,t,s,r=s){const o=this._width-this._priceAxisWidth,n=t-this._leftAxisWidth,a=Math.max(0,o-this._leftAxisWidth);if(n<0||n>a)return void this._onPointerLeave();const l=this._panes[e],h=l.hitTestPrimitives(n,s,this._renderContext(e===this._panes.length-1))??null;if(null===h&&null!==this._dividerAt(r))return this._setHover(null),void(this._container.style.cursor="row-resize");this._setHover(h),this._feedTimeNav(e===this._panes.length-1?{x:n,y:s}:null);let c=s;const d=Math.round(this._timeScale.xToIndex(n));let u=null;if(null!==this._firstDataId.value){const t=this._dataLayer.visibleBars(this._firstDataId.value,d,d);if(t.length>0&&(u=t[0].bar,"magnet"===this._crosshairMode&&e===this._firstPaneIndex)){const e=function(e,t){const i=[t.open,t.high,t.low,t.close];let s=i[0],r=Math.abs(e-s);for(let t=1;t<i.length;t++){const o=Math.abs(e-i[t]);o<r&&(r=o,s=i[t])}return s}(l.yToPrice(s),u);c=l.priceScale.priceToY(e)}}this._cursorPane=e,this._cursor={x:n,y:c};for(const e of this._indicators)e.updateLegendValues(d);if(this.invalidate(e=>e.invalidateGlobal(i.Cursor)),null!==this._crosshairCb||void 0!==this._listeners.get("crosshair:move")){const i={time:this._dataLayer.indexToTime(d)??null,index:d,price:l.yToPrice(s),bar:u,point:{x:t,y:r},paneIndex:e,pressed:this._pointers.size>0};this._crosshairCb?.(i),this.emit("crosshair:move",i)}}_maybeLoadHistory(){if(null===this._historyLoader||this._loadingHistory)return;const e=this._timeScale.visibleRange();e.from<10&&(this._loadingHistory=!0,this.emit("lazy-load",{from:this._dataLayer.indexToTime(Math.round(e.from))??null,to:this._dataLayer.indexToTime(Math.round(e.to))??null,direction:"backward"}),this._historyLoader())}_startKinetic(e){const t=new ze(e);if(t.durationMs<=0)return;const s=this._now();let r=0;const o=()=>{const e=this._now()-s,n=t.distanceAt(e),a=n-r;r=n,this._timeScale.setRightOffset(this._timeScale.rightOffset-a/this._timeScale.barSpacing),this._maybeLoadHistory(),this.invalidate(e=>e.invalidateGlobal(i.Full)),t.finished(e)?this._kineticHandle=null:this._kineticHandle=requestAnimationFrame(o)};this._kineticHandle=requestAnimationFrame(o)}_stopKinetic(){null!==this._kineticHandle&&(cancelAnimationFrame(this._kineticHandle),this._kineticHandle=null)}destroy(){this._loop.stop(),this._stopKinetic();for(const e of this._indicators)e.remove();if(this._indicators.length=0,this._resizeObserver?.disconnect(),this._resizeObserver=null,"undefined"!=typeof window){const e=this._container;e.removeEventListener("pointerdown",this._onPointerDown),e.removeEventListener("pointermove",this._onPointerMove),e.removeEventListener("pointerup",this._onPointerUpNative),e.removeEventListener("pointercancel",this._onPointerUp),e.removeEventListener("pointerleave",this._onPointerLeave),e.removeEventListener("wheel",this._onWheel),e.removeEventListener("dblclick",this._onDblClick),e.removeEventListener("pointerenter",this._onPointerEnter),e.removeEventListener("contextmenu",this._onContextMenu),this._keyTarget?.removeEventListener("keydown",this._onKeyDown),this._keyTarget=null}this._liveRegion?.remove(),this._liveRegion=null,this._container.style.cursor="",this._pointers.clear();for(const e of this._panes)e.destroy();this._panes.length=0}}function Rt(e,t={}){return new Ft(e,t)}function Bt(e){const t={Equal:"+",Minus:"-",NumpadAdd:"+",NumpadSubtract:"-",ArrowLeft:"<",ArrowRight:">",ArrowUp:"^",ArrowDown:"v"};return e.split("+").map(e=>e.trim()).map(e=>"Mod"===e?"Ctrl":t[e]??e.replace(/^(Key|Digit)/,"")).join(" + ")}Object.defineProperty(Ft,"DIVIDER_GRAB",{enumerable:!0,configurable:!0,writable:!0,value:4});const Nt={intervalSec:60,volumeMode:"ltq-sum",lateTickPolicy:"foldIntoBar",sessionAnchorSec:0};class Wt{constructor(e={}){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_current",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_cumAtBarStart",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_lastCum",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_hasCum",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._opts={...Nt,...e}}seed(e,t){this._current={...e},void 0!==t&&(this._lastCum=t,this._cumAtBarStart=t-(e.volume??0),this._hasCum=!0)}current(){return null===this._current?null:{...this._current}}bucketStart(e){const t=this._opts.sessionAnchorSec,i=this._opts.intervalSec;return t+Math.floor((e-t)/i)*i}onTick(e){const t=this.bucketStart(e.time);if(null!==this._current&&t<this._current.time)return"dropOlderThanPrevBar"===this._opts.lateTickPolicy?null:(this._foldInto(this._current,e),{bar:{...this._current},isNew:!1});if(null===this._current||t>this._current.time){const i=this._volumeForNewBar(e),s={time:t,open:e.price,high:e.price,low:e.price,close:e.price,volume:i};return this._current=s,{bar:{...s},isNew:!0}}return this._foldInto(this._current,e),{bar:{...this._current},isNew:!1}}_foldInto(e,t){t.price>e.high&&(e.high=t.price),t.price<e.low&&(e.low=t.price),e.close=t.price,e.volume=this._volumeForSameBar(e,t)}_volumeForNewBar(e){if("ltq-sum"===this._opts.volumeMode)return e.ltq??0;const t=e.cumDayVolume??0;return this._hasCum?t<this._lastCum?this._cumAtBarStart=0:this._cumAtBarStart=this._lastCum:this._cumAtBarStart=t,this._lastCum=t,this._hasCum=!0,Math.max(0,t-this._cumAtBarStart)}_volumeForSameBar(e,t){if("ltq-sum"===this._opts.volumeMode)return(e.volume??0)+(t.ltq??0);const i=t.cumDayVolume??0;return this._lastCum=i,Math.max(0,i-this._cumAtBarStart)}}function Dt(e,t,i,s,r,o){const n=r-t-i,a=o-t-s;switch(e){case"top-left":return{x:t,y:t,w:i,h:s};case"top-right":return{x:n,y:t,w:i,h:s};case"bottom-left":return{x:t,y:a,w:i,h:s};case"center":return{x:(r-i)/2,y:(o-s)/2,w:i,h:s};default:return{x:n,y:a,w:i,h:s}}}class zt{constructor(e={}){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_img",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_tintCanvas",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_tintKey",{enumerable:!0,configurable:!0,writable:!0,value:""}),this._opts={position:e.position??"bottom-right",margin:e.margin??12,height:e.height??28,opacity:e.opacity??.7,zOrder:e.zOrder??"top",src:e.src,image:e.image,tint:e.tint},e.image&&(this._img=e.image,this._ready=!0)}attached(e){if(this._host=e,!this._ready&&this._opts.src&&"undefined"!=typeof Image){const e=new Image;e.onload=()=>{this._img=e,this._ready=!0,this._host?.requestUpdate()},e.decoding="async",e.src=this._opts.src}}detached(){this._host=null}zOrder(){return this._opts.zOrder}autoscaleInfo(){return null}setOptions(e){this._opts={...this._opts,...e},this._tintCanvas=null,e.image?(this._img=e.image,this._ready=!0):void 0!==e.src&&(this._ready=!1,this._img=null,this.attached(this._host)),this._host?.requestUpdate()}draw(e,t){if(!this._ready||null===this._img)return;const i=this._opts,s=this._img.naturalWidth??this._img.width,r=this._img.naturalHeight??this._img.height;if(!s||!r)return;const o=i.height,n=o*(s/r),a=Dt(i.position,i.margin,n,o,t.plotWidth,t.plotHeight),l=t.dpr,h=Math.round(a.x*l),c=Math.round(a.y*l),d=Math.round(n*l),u=Math.round(o*l);e.save(),e.globalAlpha=Math.max(0,Math.min(1,i.opacity));const p=i.tint?this._tinted(e,d,u,i.tint):this._img;i.tint&&p?e.drawImage(p,h,c):e.drawImage(this._img,h,c,d,u),e.restore()}_tinted(e,t,i,s){const r=`${t}x${i}:${s}`;if(this._tintCanvas&&this._tintKey===r)return this._tintCanvas;const o=e.canvas.ownerDocument;let n=null;if(o&&"function"==typeof o.createElement&&(n=o.createElement("canvas")),!n)return null;n.width=t,n.height=i;const a=n.getContext("2d");return a&&null!==this._img?(a.clearRect(0,0,t,i),a.drawImage(this._img,0,0,t,i),a.globalCompositeOperation="source-in",a.fillStyle=s,a.fillRect(0,0,t,i),this._tintCanvas=n,this._tintKey=r,n):null}}class $t{constructor(e={}){Object.defineProperty(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_position",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_my",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_scale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_btnW",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_qtyW",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_h",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_buyLabel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sellLabel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_showPrices",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_qty",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_buyColor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sellColor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bid",{enumerable:!0,configurable:!0,writable:!0,value:NaN}),Object.defineProperty(this,"_ask",{enumerable:!0,configurable:!0,writable:!0,value:NaN}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_sellRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_buyRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_qtyRect",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._id=e.id??"trade",this._position=e.position??"top-left";const t=e.margin??12;this._mx="number"==typeof t?t:t.x,this._my="number"==typeof t?t:t.y,this._buyLabel=e.buyLabel??"BUY",this._sellLabel=e.sellLabel??"SELL",this._showPrices=e.showPrices??!0,this._scale=Math.max(.6,Math.min(1.5,e.scale??1)),this._btnW=74*this._scale,this._qtyW=40*this._scale,this._h=42*this._scale,this._qty=void 0!==e.qty?String(e.qty):"",this._buyColor=e.buyColor,this._sellColor=e.sellColor}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"top"}autoscaleInfo(){return null}setPrices(e,t){this._bid=e,this._ask=t,this._host?.requestUpdate()}setMark(e){this.setPrices(e,e)}setQty(e){this._qty=String(e),this._host?.requestUpdate()}setColors(e,t){this._buyColor=e,this._sellColor=t,this._host?.requestUpdate()}_origin(e,t){const i=2*this._btnW+this._qtyW+2,s=this._mx,r=e-this._mx-i,o=this._my,n=t-this._my-this._h;switch(this._position){case"top-right":return{x:r,y:o,w:i};case"bottom-left":return{x:s,y:n,w:i};case"bottom-right":return{x:r,y:n,w:i};case"center":return{x:(e-i)/2,y:(t-this._h)/2,w:i};default:return{x:s,y:o,w:i}}}draw(e,t){this._sellRect=this._buyRect=this._qtyRect=null;const i=t.dpr,s=this._origin(t.plotWidth,t.plotHeight),r=this._sellColor??t.theme.sell,o=this._buyColor??t.theme.buy;this._sellRect={x:s.x,y:s.y,w:this._btnW,h:this._h},this._qtyRect={x:s.x+this._btnW+1,y:s.y,w:this._qtyW,h:this._h},this._buyRect={x:s.x+this._btnW+this._qtyW+2,y:s.y,w:this._btnW,h:this._h},e.save(),e.shadowColor="rgba(0,0,0,0.35)",e.shadowBlur=8*i,e.shadowOffsetY=2*i;const n=(e,i)=>null!==e&&t.hoverId===`${this._id}:${i}`;this._drawButton(e,this._sellRect,i,n(this._sellRect,"sell")?Le(r,.12):r,this._sellLabel,this._showPrices?this._fmt(t,this._bid):"","left");const a="transparent"===t.theme.background?Le(r,-.6):t.theme.grid;this._drawChip(e,this._qtyRect,i,a,this._qty||"—",t.theme.axisText),this._drawButton(e,this._buyRect,i,n(this._buyRect,"buy")?Le(o,.12):o,this._buyLabel,this._showPrices?this._fmt(t,this._ask):"","right"),e.restore()}_fmt(e,t){return Number.isNaN(t)?"":e.priceScale.format(t)}_drawButton(e,t,i,s,r,o,n){const a=7*this._scale*i;e.beginPath(),this._roundedSide(e,t.x*i,t.y*i,t.w*i,t.h*i,a,n),e.fillStyle=s,e.fill();const l=Ce(s);e.textAlign="center";const h=(t.x+t.w/2)*i;""!==o?(e.fillStyle=l,e.font=10*this._scale*i+"px system-ui, sans-serif",e.textBaseline="alphabetic",e.fillText(o,h,(t.y+t.h*(18/42))*i),e.font=`700 ${12*this._scale*i}px system-ui, sans-serif`,e.fillText(r,h,(t.y+t.h*(33/42))*i)):(e.fillStyle=l,e.font=`700 ${13*this._scale*i}px system-ui, sans-serif`,e.textBaseline="middle",e.fillText(r,h,(t.y+t.h/2)*i))}_drawChip(e,t,i,s,r,o){e.beginPath(),e.rect(t.x*i,t.y*i,t.w*i,t.h*i),e.fillStyle=s,e.fill(),e.fillStyle=o,e.font=`600 ${13*this._scale*i}px system-ui, sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,(t.x+t.w/2)*i,(t.y+t.h/2)*i)}_roundedSide(e,t,i,s,r,o,n){const a=e;if("function"==typeof a.roundRect){const e="left"===n?[o,0,0,o]:[0,o,o,0];a.roundRect(t,i,s,r,e)}else je(e,t,i,s,r,o)}hitTest(e,t,i){const s=i=>null!==i&&e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h;return s(this._buyRect)?{externalId:`${this._id}:buy`,zOrder:"top",distance:0,cursor:"pointer"}:s(this._sellRect)?{externalId:`${this._id}:sell`,zOrder:"top",distance:0,cursor:"pointer"}:s(this._qtyRect)?{externalId:`${this._id}:qty`,zOrder:"top",distance:0,cursor:"pointer"}:null}}function Ht(e,t){if(t<=0)throw new Error("openalgo-charts: EMA period must be > 0");const i=[];if(0===e.length)return i;const s=2/(t+1);let r=e[0];i.push(r);for(let t=1;t<e.length;t++)r=e[t]*s+r*(1-s),i.push(r);return i}function qt(e,t){const i=Ht(e.map(e=>e.close),t);return e.map((e,t)=>({time:e.time,open:i[t],high:i[t],low:i[t],close:i[t]}))}function Et(e,t=14){if(t<=0)throw new Error("openalgo-charts: RSI period must be > 0");const i=e.length,s=new Array(i).fill(NaN);if(i<=t)return s;let r=0,o=0;for(let i=1;i<=t;i++){const t=e[i]-e[i-1];t>=0?r+=t:o-=t}let n=r/t,a=o/t;s[t]=0===a?100:100-100/(1+n/a);for(let r=t+1;r<i;r++){const i=e[r]-e[r-1];n=(n*(t-1)+(i>0?i:0))/t,a=(a*(t-1)+(i<0?-i:0))/t,s[r]=0===a?100:100-100/(1+n/a)}return s}function Ut(e,t=14){const i=Et(e.map(e=>e.close),t);return e.map((e,t)=>({time:e.time,open:i[t],high:i[t],low:i[t],close:i[t]}))}function Vt(e,t,i){const s=e.length,r=new Array(s);if(0===s)return r;r[0]=e[0]-t[0];for(let o=1;o<s;o++){const s=e[o]-t[o],n=Math.abs(e[o]-i[o-1]),a=Math.abs(t[o]-i[o-1]);r[o]=Math.max(s,n,a)}return r}function Yt(e,t,i,s=14){if(s<=0)throw new Error("openalgo-charts: ATR period must be > 0");const r=Vt(e,t,i),o=r.length,n=new Array(o).fill(NaN);if(o<s)return n;let a=0;for(let e=0;e<s;e++)a+=r[e];let l=a/s;n[s-1]=l;for(let e=s;e<o;e++)l=(l*(s-1)+r[e])/s,n[e]=l;return n}function Gt(e,t=10,i=3){const s=e.length,r=e.map(()=>({value:NaN,direction:1})),o=e.map(e=>e.high),n=e.map(e=>e.low),a=e.map(e=>e.close),l=Yt(o,n,a,t);let h=NaN,c=NaN,d=NaN,u=!1;for(let e=0;e<s;e++){if(!Number.isFinite(l[e]))continue;const t=(o[e]+n[e])/2,s=t+i*l[e],p=t-i*l[e],_=u?s<h||a[e-1]>h?s:h:s,f=u?p>c||a[e-1]<c?p:c:p;let b,m;u&&d!==h?a[e]>=f?(b=f,m=-1):(b=_,m=1):a[e]<=_?(b=_,m=1):(b=f,m=-1),r[e]={value:b,direction:m},h=_,c=f,d=b,u=!0}return r}function Kt(e,t=10,i=3){const s=Gt(e,t,i),r=(e,t)=>({time:e,open:t,high:t,low:t,close:t}),o=[],n=[];for(let t=0;t<e.length;t++){const i=s[t],a=Number.isFinite(i.value);o.push(r(e[t].time,a&&-1===i.direction?i.value:NaN)),n.push(r(e[t].time,a&&1===i.direction?i.value:NaN))}return{up:o,down:n}}function Xt(e){if("number"==typeof e)return e>1e12?G(e):Math.floor(e);const t=Number(e);return""===e.trim()||Number.isNaN(t)||/[-T :]/.test(e.trim())?K(e):t>1e12?G(t):Math.floor(t)}function Jt(e){const t=e.data??[],i=[];for(const e of t){const t=e.timestamp??e.time;void 0!==t&&i.push({time:Xt(t),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})}return i.sort((e,t)=>e.time-t.time)}class Qt{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fetch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._config=e;const t=e.fetchImpl??("undefined"!=typeof fetch?fetch.bind(globalThis):void 0);if(void 0===t)throw new Error("openalgo-charts: no fetch available; pass config.fetchImpl");this._fetch=t}async getBars(e){if(void 0===e.from||void 0===e.to)throw new Error("openalgo-charts: getBars requires `from` and `to` (UTC seconds) — OpenAlgo history needs a date range");const t=await this._fetch(`${this._config.baseUrl}/api/v1/history`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this._config.apiKey,symbol:e.symbol,exchange:e.exchange,interval:e.interval,start_date:ee(e.from),end_date:ee(e.to)})});if(!t.ok)throw new Error(`openalgo-charts: history request failed (${t.status})`);return Jt(await t.json())}}const Zt={LTP:1,Quote:2,Depth:3};function ei(){return JSON.stringify({action:"subscribe_orders"})}function ti(e,t,i,s){const r={action:"subscribe",symbol:t,exchange:i,mode:Zt[e]};return"Depth"===e&&void 0!==s&&(r.depth_level=s),JSON.stringify(r)}function ii(e,t,i){return JSON.stringify({action:"unsubscribe",symbol:t,exchange:i,mode:Zt[e]})}function si(e){if("number"==typeof e)return e>1e12?G(e):Math.floor(e);if("string"==typeof e&&""!==e.trim()){const t=Date.parse(e);if(!Number.isNaN(t))return Math.floor(t/1e3)}return 0}function ri(e){if("object"!=typeof e||null===e)return null;const t=e,i=t.data??t,s=i.symbol??"",r=i.exchange??"";if(i.depth&&(i.depth.buy||i.depth.sell)){const e=(i.depth.buy??[]).map(e=>({price:e.price,qty:e.quantity}));return{kind:"depth",symbol:s,exchange:r,depth:{bids:e,asks:(i.depth.sell??[]).map(e=>({price:e.price,qty:e.quantity})),ltp:i.ltp??i.last_price??e[0]?.price??0}}}const o=i.ltp??i.last_price;return"number"==typeof o?{kind:"ltp",event:{symbol:s,exchange:r,ltp:o,ltq:i.last_trade_quantity??i.ltq,volume:i.volume,timeSec:si(i.timestamp)}}:null}class oi{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_factory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_sock",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_open",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_queue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_ltpCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_depthCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_stateCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_controlCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_orderCbs",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_ordersSubscribed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_subs",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_userClosed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_attempts",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_reconnectTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resubscribeOnOpen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_rc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._config=e;const t=e.socketFactory??(e=>new WebSocket(e));this._factory=t;const i=e.reconnect??{};this._rc={enabled:i.enabled??!0,baseDelayMs:i.baseDelayMs??1e3,maxDelayMs:i.maxDelayMs??3e4,maxAttempts:i.maxAttempts??1/0}}connect(){if(null!==this._sock)return;this._emitState("connecting");const e=this._factory(this._config.url);e.onmessage=e=>this._dispatch(e.data),e.onopen=()=>this._onOpen(),e.onclose=()=>this._onClose(),e.onerror=()=>this._emitState("error"),this._sock=e,1===e.readyState&&this._onOpen()}onState(e){return this._stateCbs.add(e),()=>this._stateCbs.delete(e)}onControl(e){return this._controlCbs.add(e),()=>this._controlCbs.delete(e)}_emitState(e){for(const t of this._stateCbs)t(e)}_onOpen(){var e;if(!this._open&&(this._open=!0,this._attempts=0,this._emitState("open"),this._sock?.send((e=this._config.apiKey,JSON.stringify({action:"authenticate",api_key:e}))),this._flush(),this._resubscribeOnOpen)){this._resubscribeOnOpen=!1;for(const e of this._subs.values())this._sock?.send(ti(e.mode,e.symbol,e.exchange,e.depthLevel));this._ordersSubscribed&&this._sock?.send(ei())}}_onClose(){this._open=!1,this._emitState("closed"),this._maybeReconnect()}_maybeReconnect(){if(this._userClosed||!this._rc.enabled||this._attempts>=this._rc.maxAttempts)return;const e=this._attempts++,t=Math.min(this._rc.maxDelayMs,this._rc.baseDelayMs*2**e);this._emitState("reconnecting"),this._reconnectTimer=setTimeout(()=>{this._reconnectTimer=null,this._sock=null,this._open=!1,this._resubscribeOnOpen=this._subs.size>0||this._ordersSubscribed,this.connect()},t)}_send(e){null!==this._sock&&this._open?this._sock.send(e):this._queue.push(e)}_flush(){if(null!==this._sock){for(const e of this._queue)this._sock.send(e);this._queue.length=0}}onLtp(e){return this._ltpCbs.add(e),()=>this._ltpCbs.delete(e)}onDepth(e){return this._depthCbs.add(e),()=>this._depthCbs.delete(e)}subscribe(e,t,i,s){this._subs.set(`${e}:${t}:${i}`,{mode:e,symbol:t,exchange:i,depthLevel:s}),this._send(ti(e,t,i,s))}unsubscribe(e,t,i){this._subs.delete(`${e}:${t}:${i}`),this._send(ii(e,t,i))}onOrderUpdate(e){return this._orderCbs.add(e),()=>this._orderCbs.delete(e)}subscribeOrders(){this._ordersSubscribed=!0,this._send(ei())}unsubscribeOrders(){this._ordersSubscribed=!1,this._send(JSON.stringify({action:"unsubscribe_orders"}))}close(){this._userClosed=!0,null!==this._reconnectTimer&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=null),this._sock?.close(),this._sock=null,this._open=!1,this._queue.length=0}_dispatch(e){let t;try{t=JSON.parse(e)}catch{t=e}if(function(e){return"ping"===e||"object"==typeof e&&null!==e&&"ping"===e.type}(t))return void this._sock?.send(JSON.stringify({action:"pong"}));const i=function(e){if("object"!=typeof e||null===e)return null;const t=e;if("order_update"!==t.type)return null;const i=e=>{if("number"==typeof e)return e;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isNaN(t)?0:t}return 0},s=e=>"string"==typeof e?e:"",r=i(t.trigger_price);return{orderId:s(t.orderid),symbol:s(t.symbol),exchange:s(t.exchange),action:"SELL"===t.action?"SELL":"BUY",quantity:i(t.quantity),price:i(t.price),triggerPrice:r>0?r:void 0,pricetype:""===s(t.pricetype)?"LIMIT":s(t.pricetype),product:s(t.product),status:s(t.order_status).toLowerCase(),filledQuantity:i(t.filled_quantity),pendingQuantity:i(t.pending_quantity),averagePrice:i(t.average_price),rejectionReason:s(t.rejection_reason),mode:s(t.mode)}}(t);if(null!==i){for(const e of this._orderCbs)e(i);return}const s=ri(t);if(null!==s)if("ltp"===s.kind)for(const e of this._ltpCbs)e(s.event);else for(const e of this._depthCbs)e(s.symbol,s.exchange,s.depth);else if("object"==typeof t&&null!==t)for(const e of this._controlCbs)e(t)}}class ni{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fetch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_strategy",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_defaultProduct",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this._config=e,this._strategy=e.strategy??"openalgo-charts",this._defaultProduct=e.defaultProduct??"MIS";const t=e.fetchImpl??("undefined"!=typeof fetch?fetch.bind(globalThis):void 0);if(void 0===t)throw new Error("openalgo-charts: no fetch available; pass config.fetchImpl");this._fetch=t}async _post(e,t){const i=await this._fetch(`${this._config.baseUrl}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apikey:this._config.apiKey,...t})});if(!i.ok){let t="";try{const e=await i.json();"string"==typeof e.message&&""!==e.message&&(t=`: ${e.message}`)}catch{}throw new Error(`openalgo-charts: ${e} failed (${i.status})${t}`)}return i.json()}async place(e){const t={symbol:e.symbol,exchange:e.exchange??"NSE",action:e.side,pricetype:e.type,product:e.product??this._defaultProduct,quantity:e.qty},i=await this._post("/api/v1/placeorder",{strategy:this._strategy,symbol:t.symbol,action:t.action,exchange:t.exchange,pricetype:t.pricetype,product:t.product,quantity:e.qty,price:e.price??0,trigger_price:e.triggerPrice??0,disclosed_quantity:0}),s=i.orderid??i.order_id;if(void 0===s)throw new Error("openalgo-charts: placeorder returned no orderid");return this._ctx.set(s,t),{orderId:s}}async modify(e,t){const i=this._ctx.get(e);if(void 0===i)throw new Error(`openalgo-charts: cannot modify ${e} — unknown order context (place it or load the order book first)`);void 0!==t.qty&&(i.quantity=t.qty),await this._post("/api/v1/modifyorder",{orderid:e,strategy:this._strategy,symbol:i.symbol,action:i.action,exchange:i.exchange,pricetype:i.pricetype,product:i.product,quantity:i.quantity,price:t.price??0,trigger_price:t.triggerPrice??0,disclosed_quantity:0})}async cancel(e){await this._post("/api/v1/cancelorder",{orderid:e,strategy:this._strategy})}async getOrders(){const e=await this._post("/api/v1/orderbook",{}),t=Array.isArray(e.data)?e.data:e.data?.orders??[],i=t.map(hi);for(const e of t)e.orderid&&this._ctx.set(e.orderid,{symbol:e.symbol??"",exchange:e.exchange??"NSE",action:e.action??"BUY",pricetype:e.pricetype??"LIMIT",product:e.product??this._defaultProduct,quantity:ai(e.quantity)});return i}async getPositions(){return((await this._post("/api/v1/positionbook",{})).data??[]).map(ci)}}function ai(e){if("number"==typeof e)return e;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isNaN(t)?0:t}return 0}const li={open:"working",pending:"pending",trigger_pending:"working","trigger pending":"working",complete:"filled",cancelled:"cancelled",rejected:"rejected"};function hi(e){return{id:e.orderid??"",symbol:e.symbol??"",side:"SELL"===e.action?"SELL":"BUY",type:e.pricetype??"LIMIT",qty:ai(e.quantity),filledQty:ai(e.filled_quantity),price:ai(e.price),triggerPrice:void 0!==e.trigger_price&&ai(e.trigger_price)>0?ai(e.trigger_price):void 0,status:li[(e.order_status??"").toLowerCase()]??"working"}}function ci(e){return{symbol:e.symbol??"",netQty:ai(e.quantity),avgPrice:ai(e.average_price)}}function di(e){const t=/^(\d*)\s*([smhdw])$/i.exec(e.trim());if(null===t)return 60;const i=""===t[1]?1:Number(t[1]),s=t[2].toLowerCase();return i*("s"===s?1:"m"===s?60:"h"===s?3600:"d"===s?86400:604800)}class ui{constructor(e){Object.defineProperty(this,"_rest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ws",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_volumeMode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._rest=new Qt(e),this._ws=new oi({url:e.wsUrl,apiKey:e.apiKey,socketFactory:e.socketFactory}),this._volumeMode=e.volumeMode??"ltq-sum",this._ws.connect()}getBars(e){return this._rest.getBars(e)}subscribeBars(e,t,i){const s=new Wt({intervalSec:di(e.interval),volumeMode:this._volumeMode});i?.seedFrom&&s.seed(i.seedFrom,i.cumDayVolumeSoFar);const r=this._ws.onLtp(i=>{if(i.symbol!==e.symbol)return;if(i.exchange&&e.exchange&&i.exchange!==e.exchange)return;const r=i.timeSec&&i.timeSec>0?i.timeSec:Math.floor(Date.now()/1e3),o=s.onTick({time:r,price:i.ltp,ltq:i.ltq,cumDayVolume:i.volume});null!==o&&t(o.bar)});return this._ws.subscribe("LTP",e.symbol,e.exchange),()=>{r(),this._ws.unsubscribe("LTP",e.symbol,e.exchange)}}subscribeDepth(e,t){const i=this._ws.onDepth((i,s,r)=>{i===e.symbol&&(s&&e.exchange&&s!==e.exchange||t(r))});return this._ws.subscribe("Depth",e.symbol,e.exchange),()=>{i(),this._ws.unsubscribe("Depth",e.symbol,e.exchange)}}close(){this._ws.close()}}const pi=(e,t)=>{const i=setInterval(e,t);return()=>clearInterval(i)};class _i{constructor(e=60,t=pi){Object.defineProperty(this,"intervalSec",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_schedule",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.intervalSec=e,this._schedule=t}async getBars(e){return fi(e.from??17e8,500,this.intervalSec)}subscribeBars(e,t,i){let s=e.from??17e8,r=100,o=19088743;const n=()=>(o^=o<<13,o>>>=0,o^=o>>17,o^=o<<5,o>>>=0,o/4294967295);return this._schedule(()=>{s+=this.intervalSec;const e=r,i=Math.max(1,e+2*(n()-.5)),o=Math.max(e,i)+n(),a=Math.max(.01,Math.min(e,i)-n());t({time:s,open:e,high:o,low:a,close:i,volume:Math.round(1e3+9e3*n())}),r=i},i?.tickMs??1e3)}}function fi(e,t,i){const s=[];let r=100,o=2654435769;const n=()=>(o^=o<<13,o>>>=0,o^=o>>17,o^=o<<5,o>>>=0,o/4294967295);for(let o=0;o<t;o++){const t=2*(n()-.5),a=r,l=Math.max(1,a+t),h=Math.max(a,l)+n(),c=Math.min(a,l)-n();s.push({time:e+o*i,open:a,high:h,low:c,close:l,volume:Math.round(1e3+9e3*n())}),r=l}return s}function bi(e,t){if("interval"===e.mode){const i=e.anchorSec??0;return i+Math.floor((t-i)/e.seconds)*e.seconds}return 0}class mi{constructor(e){Object.defineProperty(this,"_tf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cur",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_count",{enumerable:!0,configurable:!0,writable:!0,value:0}),this._tf=e}current(){return null===this._cur?null:{...this._cur}}onTick(e){const t=null===this._cur;let i=t;if(t||null===this._cur||(i="interval"===this._tf.mode?bi(this._tf,e.time)!==this._cur.time:"ticks"===this._tf.mode?this._count>=this._tf.count:(this._cur.volume??0)>=this._tf.perBar),i){const t="interval"===this._tf.mode?bi(this._tf,e.time):e.time;return this._cur={time:t,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.qty},this._count=1,{bar:{...this._cur},isNew:!0}}const s=this._cur;return e.price>s.high&&(s.high=e.price),e.price<s.low&&(s.low=e.price),s.close=e.price,s.volume=(s.volume??0)+e.qty,this._count+=1,{bar:{...s},isNew:!1}}}export{et as ALT_PRESET,tt as BUILTIN_COMMANDS,$t as BuySellButtons,Be as CHART_STATE_VERSION,Wt as CandleBuilder,Ft as Chart,Nt as DEFAULT_CANDLE_BUILDER_OPTIONS,P as DEFAULT_CANDLE_STYLE,k as DEFAULT_HISTOGRAM_STYLE,Ze as DEFAULT_KEYMAP,b as DEFAULT_PRICE_SCALE_OPTIONS,ue as DEFAULT_THEME,Tt as DEFAULT_TIME_NAVIGATOR_OPTIONS,v as DEFAULT_TIME_SCALE_OPTIONS,ot as DEFAULT_TRADING_COLORS,yt as EventMarkers,_i as FakeDataFeed,pe as INDICATOR_LINE_STYLES,me as INDICATOR_SOURCES,Y as IST_OFFSET_SECONDS,Te as IndicatorFill,i as InvalidationLevel,zt as LogoWatermark,Qt as OpenAlgoDataFeed,ui as OpenAlgoLiveDataFeed,ni as OpenAlgoTradeFeed,oi as OpenAlgoWsFeed,he as Pane,Ot as PaneLegend,rt as PriceLine,g as PriceScale,gt as SeriesMarkers,st as ShortcutManager,mi as TickBarAggregator,Mt as TimeNavigator,y as TimeScale,dt as TradeMarkersPrimitive,ut as TradingController,e as VERSION,Yt as atr,m as autoscaleRange,le as bestHit,n as bitmapSize,h as clamp,kt as compactVolume,U as conflateBars,V as conflateItems,q as conflationGroupSize,Rt as createChart,ce as darkTheme,mt as drawShape,bt as effectiveMarkerPx,Ht as ema,qt as emaSeries,G as epochMsToUtcSeconds,Xe as eventToCombo,Ke as formatCombo,ie as formatIstDate,Q as formatIstTime,Z as formatIstTimeSeconds,ti as formatSubscribe,ii as formatUnsubscribe,fi as generateBars,z as getChartType,ye as getIndicator,we as hasIndicator,Pe as indicatorDefaults,fe as indicatorStyleInputs,di as intervalToSeconds,re as isNewIstDay,Qe as isReservedCombo,Ye as isValidCombo,Ne as isWhitespace,K as istStringToUtcSeconds,c as lerp,de as lightTheme,Jt as mapHistoryResponse,hi as mapOrder,ci as mapPosition,ft as markerSizePx,E as mergeBars,_ as niceTicks,Ve as normalizeCombo,S as optimalBarWidth,Ue as parseCombo,ri as parseMessage,_e as plotStyleKeys,f as precisionForStep,D as registerChartType,ve as registerIndicator,$ as registeredChartTypes,xe as registeredIndicators,d as roundToTick,Xt as rowTimeToUtcSeconds,Et as rsi,Ut as rsiSeries,a as snapToDevicePixel,Se as sourceValue,Oe as sourceValues,Gt as supertrend,Kt as supertrendSeries,We as toBar,Vt as trueRange,ee as utcSecondsToIstDateString,X as utcSecondsToIstParts,t as version,I as verticalGradient,Dt as watermarkRect};
|
|
2
2
|
//# sourceMappingURL=openalgo-charts.mjs.map
|