@kumo-charts/core 1.0.0-beta.6 → 1.0.0-beta.7
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/LICENSE +201 -201
- package/NOTICE +11 -11
- package/README.md +23 -23
- package/dist/{aggregator-CsTcgTRK.js → aggregator-DFCDVoFt.js} +3 -3
- package/dist/{alert-book-DNP68WX7.js → alert-book-KgUNJ1Pm.js} +5 -4
- package/dist/alert-engine.d.ts +5 -5
- package/dist/alert-engine.js +10 -10
- package/dist/{alerts-Bv5u4-99.js → alerts-sN1NVz-X.js} +19 -7
- package/dist/alerts.d.ts +1 -1
- package/dist/alerts.js +1 -1
- package/dist/all.d.ts +9 -9
- package/dist/all.js +9 -9
- package/dist/{api-BxS-GfYB.d.ts → api-BWC_Cce5.d.ts} +15 -1
- package/dist/{api-BlJUtij_.d.ts → api-DgviKlaI.d.ts} +1 -1
- package/dist/{bar-store-B_NkvUnA.js → bar-store-B4HFH1h6.js} +21 -3
- package/dist/{calendar-BkI9B9A5.js → calendar-xZYfA5bX.js} +4 -4
- package/dist/{chart-types-pzeZDEp9.js → chart-types-DtRsOwjT.js} +3 -3
- package/dist/chart-types.d.ts +1 -1
- package/dist/chart-types.js +1 -1
- package/dist/collection-RZyV3hnM.js +71 -0
- package/dist/{color-1Osbv2TE.js → color-AsBx5M66.js} +1 -1
- package/dist/{data-B75gRyuP.d.ts → data-RRHroFqK.d.ts} +34 -2
- package/dist/{drawings-DMRwbLsg.js → drawings-C-jyagJI.js} +137 -125
- package/dist/drawings.d.ts +3 -3
- package/dist/drawings.js +1 -1
- package/dist/{frame-Bt85Ejw7.js → frame-790ompHn.js} +5 -6
- package/dist/{index-Bfi0g81h.d.ts → index-B5nL4-fG.d.ts} +4 -2
- package/dist/{index-D12U6YKZ.d.ts → index-BMRUiN6F.d.ts} +2 -2
- package/dist/{index-SSXLg0b-.d.ts → index-Bgl-FJT3.d.ts} +3 -3
- package/dist/{index-BoRy0gWB.d.ts → index-Bp1gL2SV.d.ts} +1 -1
- package/dist/{index-DTrnOP7Q.d.ts → index-CsFnU-ko.d.ts} +1 -1
- package/dist/{index-BpyqTH6i.d.ts → index-D5fdjNJv.d.ts} +14 -2
- package/dist/{index-DvbA0QtQ.d.ts → index-cuDsywlB.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +280 -107
- package/dist/{indicator-store-CSNYNv-H.js → indicator-store-Cj8FkdLe.js} +11 -5
- package/dist/{indicators-7G1DqNSH.js → indicators-KKeZmC6g.js} +30 -9
- package/dist/indicators.d.ts +2 -2
- package/dist/indicators.js +2 -2
- package/dist/kumo-charts.iife.js +7 -7
- package/dist/{module-DxdViSuj.d.ts → module-ma1-rklb.d.ts} +2 -2
- package/dist/{modules-RlaXjRWe.js → modules-D_E0wmaT.js} +1 -1
- package/dist/{price-line-BPw9VyW3.js → price-line-Ctf8YIXI.js} +77 -89
- package/dist/{price-line-CdM5YNlZ.d.ts → price-line-exqgokHI.d.ts} +3 -1
- package/dist/{price-lines-CaLOO6qa.js → price-lines-C9xony-Z.js} +1 -1
- package/dist/{registry-f-A949ov.js → registry-DpycnxXe.js} +8 -4
- package/dist/{replay-_1IoxPdh.js → replay-BglWO-Se.js} +3 -3
- package/dist/replay.d.ts +1 -1
- package/dist/replay.js +1 -1
- package/dist/{series-store-Brd46VuC.js → series-store-DwvvS42F.js} +3 -3
- package/dist/{time-BN0L-hLy.js → time-QUqwrKFO.js} +1 -1
- package/dist/{trading-CjKK5irF.js → trading-BY4NVox9.js} +38 -17
- package/dist/trading.d.ts +1 -1
- package/dist/trading.js +1 -1
- package/dist/{transforms-CtdsqwVk.js → transforms-D07qL7UT.js} +3 -3
- package/dist/{types-Bgjeo6w6.js → types-CEVVGcR9.js} +6 -2
- package/dist/{types-uoxTaiGv.js → types-CgerhCJ3.js} +3 -1
- package/dist/{types-xV6t4aad.d.ts → types-CrxgaGh5.d.ts} +14 -2
- package/dist/{validate-YdhjgZ6g.js → validate-B_z8rO0I.js} +4 -1
- package/dist/{value-format-BieuAeNK.js → value-format-DwSqOZkc.js} +6 -6
- package/dist/{values-Cw8XKIVE.js → values-CIb5EJ5-.js} +18 -10
- package/dist/{values-CtBpceAo.js → values-Hk0_RbLE.js} +5 -5
- package/dist/{volume-profile-ZWM9N-I-.js → volume-profile-Ci-AGdvp.js} +5 -8
- package/dist/volume-profile.d.ts +1 -1
- package/dist/volume-profile.js +1 -1
- package/dist/{watermark-qCkQw950.js → watermark--TmdUE3C.js} +3 -3
- package/dist/watermark.d.ts +1 -1
- package/dist/watermark.js +1 -1
- package/package.json +1 -1
package/dist/kumo-charts.iife.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var KumoChart=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class extends Error{name=`ChartError`;constructor(e){super(`[kumochart] ${e}`)}};function n(e){throw new t(e)}function r(e){let t=null;for(let n of e)try{n()}catch(e){t??={error:e}}if(t)throw t.error}function i(e){return typeof e==`string`?JSON.stringify(e):typeof e==`number`||typeof e==`boolean`||e===null?String(e):e===void 0?`undefined`:Array.isArray(e)?`an array`:typeof e==`object`?`an object`:typeof e}function a(e,t=`time`){let r;if(typeof e==`number`)r=e;else if(typeof e==`string`)r=Date.parse(e);else if(e instanceof Date)r=e.getTime();else return n(`${t} must be a number, string or Date, received ${i(e)}.`);return Number.isFinite(r)||n(`${t} ${i(e)} is not a valid point in time.`),r}function o(e){let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toISOString()}function s(e,t,n){let r=e.map(()=>!1),i=(e,t)=>!e.stretch&&!r[t];for(;;){let a=t-r.filter(Boolean).length*n,o=e.reduce((e,t,n)=>i(t,n)?e+t.height:e,0),s=o>a?a/o:1,c=e.flatMap((e,t)=>i(e,t)&&e.height*s<n?[t]:[]);if(c.length===0)return e.map((e,t)=>e.stretch?0:r[t]?n:e.height*s);c.forEach(e=>{r[e]=!0})}}function c(e,t,n){if(t.length===0)return[];let r=Math.min(n,e/t.length),i=t.filter(e=>e.stretch).length,a=s(t,e-i*r,r),o=a.reduce((e,t)=>e+t,0),c=Math.max(0,e-o);if(i===0){let e=a.length-1;return a[e]=(a[e]??0)+c,a}return t.map((e,t)=>e.stretch?c/i:a[t]??0)}function l(e){let t=Math.max(0,e.width),n=Math.max(0,e.height),r=Math.min(e.axisWidth,t),i=Math.min(e.leftAxisWidth,t-r),a=Math.max(0,t-r-i),o=Math.min(e.timeAxisHeight,n),s=Math.max(0,e.panes.length-1)*e.separatorHeight,l=c(Math.max(0,n-o-s),e.panes,e.minPaneHeight),u=[],d=[],f=0;return e.panes.forEach((t,n)=>{let o=l[n]??0;u.push({id:t.id,plot:{x:0,y:f,width:a,height:o},axis:{x:a,y:f,width:r,height:o},leftAxis:i>0?{x:-i,y:f,width:i,height:o}:null}),f+=o;let s=e.panes[n+1];s&&(d.push({above:t.id,below:s.id,y:f,height:e.separatorHeight}),f+=e.separatorHeight)}),{width:t,height:n,plotWidth:a,axisWidth:r,leftAxisWidth:i,panes:u,separators:d,timeAxis:o>0?{x:-i,y:f,width:t,height:o}:null}}function u(e){let t=e.leftAxisWidth,n=e=>({...e,x:e.x+t});return{...e,panes:e.panes.map(e=>({id:e.id,plot:n(e.plot),axis:n(e.axis),leftAxis:e.leftAxis?n(e.leftAxis):null})),separators:e.separators.map(e=>({...e})),timeAxis:e.timeAxis?n(e.timeAxis):null}}function d(e,t,r={}){return typeof t!=`number`||!Number.isFinite(t)?n(`${e} must be a finite number, received ${i(t)}.`):(r.integer&&!Number.isInteger(t)&&n(`${e} must be an integer, received ${t}.`),r.min!==void 0&&(r.exclusiveMin?t<=r.min:t<r.min)&&n(`${e} must be ${r.exclusiveMin?`greater than`:`at least`} ${r.min}, received ${t}.`),r.max!==void 0&&t>r.max&&n(`${e} must be at most ${r.max}, received ${t}.`),t)}function f(e,t){return typeof t==`boolean`?t:n(`${e} must be a boolean, received ${i(t)}.`)}function p(e,t){return typeof t!=`string`||t.length===0?n(`${e} must be a non-empty string, received ${i(t)}.`):t}function m(e,t,r){return typeof t!=`string`||!r.includes(t)?n(`${e} must be one of ${r.map(e=>`"${e}"`).join(`, `)}, received ${i(t)}.`):t}function h(e,t){(typeof t!=`object`||!t||Array.isArray(t))&&n(`${e} must be an object, received ${i(t)}.`)}function g(e){return Object.keys(e)}function _(e,t,r){h(e,t);let i=Object.keys(t).find(e=>!r.includes(e));i!==void 0&&n(`${e} has no field "${i}"; its fields are ${r.join(`, `)}.`)}function v(e,t){Array.isArray(t)||n(`${e} must be an array, received ${i(t)}.`)}function ee(e,t){t!==null&&typeof t!=`function`&&n(`${e} must be a function or null, received ${i(t)}.`)}function te(e,t){let r=p(e,t);try{new Intl.DateTimeFormat(`en-US`,{timeZone:r})}catch{n(`${e} ${JSON.stringify(r)} is not a valid IANA time zone.`)}return r}let ne=g({top:!0,bottom:!0}),re=.9;function ie(e,t){return _(e,t,ne),d(`${e}.top`,t.top,{min:0,max:re}),d(`${e}.bottom`,t.bottom,{min:0,max:re}),t.top+t.bottom>re&&n(`${e}.top and ${e}.bottom must leave a tenth of the pane for the data.`),{top:t.top,bottom:t.bottom}}function ae(){return{min:1/0,max:-1/0,minPositive:1/0}}function y(e,t){Number.isFinite(t)&&(t<e.min&&(e.min=t),t>e.max&&(e.max=t),t>0&&t<e.minPositive&&(e.minPositive=t))}let oe={mode:`normal`};function se(e,t){let n=e.max-e.min;if(!Number.isFinite(n)||!(n>0))return!1;if(t===`log`)return e.min>-30&&e.max<30&&n>1e-6;let r=Math.max(1,Math.abs(e.min),Math.abs(e.max));return n>r*1e-9&&n<r*1e9}function ce(e,t,n){switch(e){case`normal`:return oe;case`log`:return Number.isFinite(n.minPositive)?{mode:e}:oe;case`percent`:return t!==null&&t!==0?{mode:e,base:t}:oe;case`indexed`:return t!==null&&t>0?{mode:e,base:t}:oe}}var le=class{height=0;settings;transform=oe;manual=null;range=null;leader=null;constructor(e){this.settings=e}get mode(){return this.transform.mode}get autoScale(){return this.manual===null}get lead(){return this.leader??this}get inverted(){return this.lead.settings.invert}get plotHeight(){return this.height}configure(e){e.mode!==this.settings.mode&&(this.manual=null),this.settings=e}setHeight(e){this.height=Math.max(0,e)}relativeMode(e){let{mode:t}=ce(this.settings.mode,e,ae());return t===`percent`||t===`indexed`?t:null}fit(e,t){let n=ce(this.settings.mode,t,e);if(this.leader=null,this.transform=n,this.manual?.mode===n.mode){this.range=this.manual.range;return}let r=this.toScale(n.mode===`log`?e.minPositive:e.min),i=this.toScale(e.max);if(r===null||i===null||i<r){this.range=null;return}let a=i===r,o=a?i===0?1:Math.max(Math.abs(i)*.01,1e-6):i-r,{top:s,bottom:c}=this.settings.margins,l=o/(1-s-c),u=a?o/2:0;this.range={min:r-u-c*l,max:i+u+s*l}}follow(e){this.leader=e,this.height=e.height,this.transform=e.transform,this.range=e.range}scaleRange(){return this.range}valueRange(){return this.range?{min:this.fromScale(this.range.min),max:this.fromScale(this.range.max)}:null}toScale(e){if(!Number.isFinite(e))return null;let t=this.transform;switch(t.mode){case`normal`:return e;case`log`:return e>0?Math.log10(e):null;case`percent`:return(e-t.base)/Math.abs(t.base)*100;case`indexed`:return e/t.base*100}}fromScale(e){let t=this.transform;switch(t.mode){case`normal`:return e;case`log`:return 10**e;case`percent`:return t.base+e/100*Math.abs(t.base);case`indexed`:return e/100*t.base}}displayValue(e){return this.transform.mode===`percent`||this.transform.mode===`indexed`?this.toScale(e)??NaN:e}valueToY(e){let t=this.toScale(e);return t===null?NaN:this.scaleToY(t)}scaleToY(e){let t=this.range;if(!t)return NaN;let n=(e-t.min)/(t.max-t.min);return this.inverted?n*this.height:(1-n)*this.height}yToScale(e){let t=this.range;if(!t||this.height===0)return NaN;let n=this.inverted?e/this.height:1-e/this.height;return t.min+n*(t.max-t.min)}yToValue(e){return this.fromScale(this.yToScale(e))}setValueRange(e){let t=this.toScale(e.min),n=this.toScale(e.max);return t===null||n===null?!1:this.setManual({min:t,max:n})}zoom(e,t){let n=this.range;if(!n||!(e>0))return;let r=this.yToScale(t);this.setManual({min:r-(r-n.min)/e,max:r+(n.max-r)/e})}pan(e){let t=this.range;if(!t||this.height===0)return;let n=(t.max-t.min)*e/this.height,r=this.settings.invert?-n:n;this.setManual({min:t.min+r,max:t.max+r})}resetAutoScale(){this.manual=null}manualRange(){return this.manual?.mode===this.settings.mode?this.manual.range:null}restoreManualRange(e){this.manual=e&&se(e,this.settings.mode)?{range:e,mode:this.settings.mode}:null}setManual(e){return se(e,this.transform.mode)?(this.manual={range:e,mode:this.transform.mode},this.range=e,!0):!1}};let ue=/^(.+)-(\d+)$/;var de=class{taken;counts;constructor(e,t){this.taken=e,this.counts=new Map(t?.counts)}next(e){let t=this.counts.get(e)??1;for(;this.taken(`${e}-${t}`);)t+=1;return`${e}-${t}`}note(e){let t=ue.exec(e);if(!t)return;let[,n=``,r=``]=t,i=Number(r)+1;Number.isSafeInteger(i)&&i>(this.counts.get(n)??1)&&this.counts.set(n,i)}reserve(e){e.forEach(e=>{let t=typeof e==`object`&&e?e.id:void 0;typeof t==`string`&&this.note(t)})}};let b=`main`,fe=`right`,pe=`left`,me=[`normal`,`log`,`percent`,`indexed`],he=g({id:!0,title:!0,height:!0}),ge=g({title:!0,height:!0});function _e(e,t){t.title!==void 0&&typeof t.title!=`string`&&n(`${e}.title must be a string.`),t.height!==void 0&&d(`${e}.height`,t.height,{min:1})}var ve=class{defaultHeight;entries=[];ids=new de(e=>this.get(e)!==void 0);margins;constructor(e,t){this.defaultHeight=e,this.margins=t,this.entries.push(this.createEntry(b,{title:``},!1))}list(){return this.entries}get(e){return this.entries.find(t=>t.id===e)}require(e){return this.get(e)??n(`Unknown pane "${e}".`)}info(e){return{id:e.id,title:e.title,height:e.height,auto:e.auto}}configure(e,t){this.defaultHeight=e,this.margins=t,this.entries.forEach(e=>{e.scales.forEach(e=>{this.syncScale(e)})})}add(e,t){_(`pane`,e,he),_e(`pane`,e);let r=e.id===void 0?this.ids.next(`pane`):p(`pane.id`,e.id);this.get(r)&&n(`A pane with id "${r}" already exists.`);let i=this.createEntry(r,e,t);return this.entries.push(i),this.ids.note(r),i}update(e,t){_(`pane patch`,t,ge);let n=this.require(e);_e(`pane`,t),t.title!==void 0&&(n.title=t.title),t.height!==void 0&&(n.height=t.height)}remove(e){e===`main`&&n(`The main pane cannot be removed.`);let t=this.entries.findIndex(t=>t.id===e);t<0&&n(`Unknown pane "${e}".`),this.entries.splice(t,1)}move(e,t){e===`main`&&n(`The main pane always stays first.`),d(`index`,t,{min:1,max:this.entries.length-1,integer:!0});let r=this.entries.findIndex(t=>t.id===e);r<0&&n(`Unknown pane "${e}".`);let[i]=this.entries.splice(r,1);i&&this.entries.splice(t,0,i)}adopt(e){this.entries.splice(0,this.entries.length,...e.entries),this.entries.forEach(e=>{this.ids.note(e.id),e.scales.forEach(e=>{this.syncScale(e)})})}findScale(e,t){return this.require(e).scales.get(t)??null}ensureScale(e,t){let n=this.require(e),r=n.scales.get(t);return r||(p(`scale id`,t),r=this.createScale(t),n.scales.set(t,r)),r}manualScales(e){let t=/* @__PURE__ */ new Set;for(let{scale:n}of this.require(e).scales.values())n.lead.autoScale||t.add(n.lead);return[...t]}setScaleMode(e,t,n){let r=this.ensureScale(e,t);r.mode=m(`mode`,n,me),this.syncScale(r)}setScaleInverted(e,t,n){let r=this.ensureScale(e,t);r.invert=f(`inverted`,n),this.syncScale(r)}setScaleMargins(e,t,n){let r=n===null?null:ie(`margins`,n),i=this.ensureScale(e,t);i.margins=r,this.syncScale(i)}createScale(e){return{id:e,mode:`normal`,invert:!1,margins:null,scale:new le({mode:`normal`,invert:!1,margins:this.margins})}}createEntry(e,t,n){let r=this.createScale(fe);return{id:e,title:t.title??``,height:t.height??this.defaultHeight,auto:n,right:r,scale:r.scale,scales:/* @__PURE__ */ new Map([[fe,r]])}}syncScale(e){e.scale.configure({mode:e.mode,invert:e.invert,margins:e.margins??this.margins})}};function ye(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}let be=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`]);function xe(e){return Array.isArray(e)?[...e]:e}function Se(e,t){if(t===void 0)return e;if(!ye(e)||!ye(t))return xe(t);let n={...e};for(let[e,r]of Object.entries(t)){if(r===void 0||be.has(e))continue;let t=n[e];n[e]=ye(t)&&ye(r)?Se(t,r):xe(r)}return n}function Ce(e){return(ye(e)||Array.isArray(e))&&(Object.values(e).forEach(e=>{Ce(e)}),Object.freeze(e)),e}function we(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=e,r=t,i=Object.keys(n);return i.length===Object.keys(r).length&&i.every(e=>Object.hasOwn(r,e)&&we(n[e],r[e]))}let Te=g({interval:!0});function Ee(e){return{set:(t,n={})=>{_(`data.set() options`,n,Te),e.run(()=>{e.setData(t,n.interval)})},update:t=>{e.run(()=>{e.updateData(Array.isArray(t)?t:[t])})},addTrades:t=>e.run(()=>e.addTrades(Array.isArray(t)?t:[t])),prepend:t=>e.run(()=>e.prependData(t)),clear:()=>{e.run(()=>{e.clearData()})},sourceInterval:()=>e.market.sourceInterval(),calendar:()=>e.market.tradingCalendar(),timeframe:()=>e.market.timeframe(),setTimeframe:t=>{e.run(()=>{e.setTimeframe(t)})},get length(){return e.bars.length},bars:e.market.displayed,source:e.market.revealed,at:t=>e.bars.bar(t),last:()=>e.bars.bar(e.bars.length-1),indexOf:t=>e.bars.indexOf(a(t)),toArray:()=>e.bars.toArray()}}function De(e,t,r){let i=()=>e.panes.findScale(t,r),a=()=>e.panes.ensureScale(t,r),o=()=>e.frame().panes.find(e=>e.id===t)?.plot.y??n(`Unknown pane "${t}".`),s=t=>{e.run(()=>{e.frame(),t(),e.invalidate()})};return{range:()=>(e.frame(),i()?.scale.valueRange()??null),setRange:e=>{d(`range.min`,e.min),d(`range.max`,e.max),e.max>e.min||n(`range.max (${e.max}) must be greater than range.min (${e.min}).`),s(()=>{a().scale.lead.setValueRange(e)||n(`The range ${e.min}..${e.max} cannot be shown in ${a().scale.mode} mode.`)})},autoScale:()=>{s(()=>{i()?.scale.lead.resetAutoScale()})},isAutoScale:()=>i()?.scale.lead.autoScale??!0,mode:()=>i()?.mode??`normal`,setMode:n=>{s(()=>{e.panes.setScaleMode(t,r,n)})},isInverted:()=>i()?.invert??!1,setInverted:n=>{s(()=>{e.panes.setScaleInverted(t,r,n)})},margins:()=>({...i()?.margins??e.options.priceScale.margins}),setMargins:n=>{s(()=>{e.panes.setScaleMargins(t,r,n)})},priceToY:e=>{d(`price`,e);let t=o(),n=i()?.scale.valueToY(e)??NaN;return Number.isFinite(n)?t+n:null},yToPrice:e=>{d(`y`,e);let t=o(),n=i()?.scale.yToValue(e-t)??NaN;return Number.isFinite(n)?n:null}}}function Oe(e){return{list:()=>e.panes.list().map(t=>e.panes.info(t)),get:t=>{let n=e.panes.get(t);return n?e.panes.info(n):null},add:t=>e.run(()=>{let{id:n}=e.panes.add(t,!1);return e.invalidate(),n}),update:(t,n)=>{e.run(()=>{e.panes.update(t,n),e.invalidate()})},remove:t=>{e.run(()=>{t===`main`&&n(`The main pane cannot be removed.`);let r=e.occupantsOf(t);r.length>0&&n(`Pane "${t}" still contains ${r.map(e=>`"${e}"`).join(`, `)}.`),e.removePane(t),e.invalidate()})},move:(t,n)=>{e.run(()=>{e.panes.move(t,n),e.invalidate()})}}}let ke=/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,Ae=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/i,je;function Me(e){let t=e.length<=4?e.split(``).map(e=>e+e).join(``):e,n=e=>Number.parseInt(t.slice(e,e+2),16);return{r:n(0),g:n(2),b:n(4),a:t.length===8?n(6)/255:1}}function Ne(e){let t=e[4];return{r:Number(e[1]),g:Number(e[2]),b:Number(e[3]),a:t===void 0?1:t.endsWith(`%`)?Number(t.slice(0,-1))/100:Number(t)}}function Pe(e){if(je??=typeof document>`u`?null:document.createElement(`canvas`).getContext(`2d`),!je)return;je.fillStyle=`#000000`,je.fillStyle=e;let t=je.fillStyle;return(t!==`#000000`||/^(black|#0{3,8})$/i.test(e))&&(ke.test(t)||Ae.test(t))?t:null}function Fe(e){let t=e.trim(),r=ke.exec(t);if(r?.[1])return Me(r[1]);let i=Ae.exec(t);if(i)return Ne(i);let a=Pe(t);return a?Fe(a):n(`Unsupported color ${JSON.stringify(e)}.`)}function x(e,t){let r=p(e,t).trim();return!ke.test(r)&&!Ae.test(r)&&Pe(r)===null&&n(`${e} must be a CSS color, not ${JSON.stringify(t)}.`),t}function Ie(e,t){for(let[n,r]of Object.entries(t))(n===`color`||n.endsWith(`Color`))&&r!=null&&x(`${e}.${n}`,r)}let Le=/* @__PURE__ */ new Map;function Re(e){let t=Le.get(e);return t||(Le.size>=256&&Le.clear(),t={rgba:Fe(e),made:/* @__PURE__ */ new Map},Le.set(e,t)),t}function ze(e,t,n){let r=e.made.get(t);return r===void 0&&(e.made.size>=32&&e.made.clear(),r=n(),e.made.set(t,r)),r}function Be(e,t,n){let r=Re(e);return ze(r,`${n} over ${t}`,()=>{let e=r.rgba,i=Re(t).rgba,a=e.a*n,o=(e,t)=>Math.round(e*a+t*(1-a));return`rgb(${o(e.r,i.r)}, ${o(e.g,i.g)}, ${o(e.b,i.b)})`})}function S(e,t){let n=Re(e);return ze(n,String(t),()=>{let{r:e,g:r,b:i,a}=n.rgba;return`rgba(${e}, ${r}, ${i}, ${Math.round(a*t*1e3)/1e3})`})}var Ve=class{current=0;resetAt=0;tails=[];get revision(){return this.current}reset(){this.current+=1,this.resetAt=this.current,this.tails=[]}tail(e){this.current+=1,this.tails.push({revision:this.current,from:e}),this.tails.length>256&&this.tails.shift()}since(e){if(e===this.current)return null;let t=this.tails[0];if(e<this.resetAt||e>this.current||!t||t.revision>e+1)return{kind:`reset`};let n=1/0;for(let t of this.tails)t.revision>e&&(n=Math.min(n,t.from));return{kind:`tail`,from:n}}};let He=Float64Array.BYTES_PER_ELEMENT;function Ue(e){return e.byteOffset/He}function We(e,t,n,r){let i=new Float64Array(new ArrayBuffer((n+r)*He),n*He,r);return i.set(e.subarray(0,t)),i}function Ge(e,t,n){return n<=e.length?e:We(e,t,Ue(e),Math.max(16,e.length*2,n))}function Ke(e,t,n){let r=Ue(e)>=n?e:We(e,t,n+(t+n>>1),Math.max(16,e.length));return new Float64Array(r.buffer,r.byteOffset-n*He,r.length+n)}function qe(e,t){for(let r=1;r<e.length;r+=1){let i=e[r-1],a=e[r];i&&a&&a.time<=i.time&&n(`${t} must be sorted by strictly ascending time: ${t}[${r}] (${a.time}) is not after ${t}[${r-1}] (${i.time}).`)}}function Je(e,t,r,i,a){let o=t>0?r:-1/0;e.forEach((e,t)=>{e.time<o&&n(`${i}[${t}] (time ${e.time}) is older than the last ${a} (time ${o}). update() only replaces the last ${a} or appends newer ones; use set() or prepend() to change history.`),o=e.time});let s=e[0],c=t>0&&s?.time===r?t-1:t,l=[];for(let t of e)l.length>0&&l[l.length-1]?.time===t.time?l[l.length-1]=t:l.push(t);return{from:c,tail:l}}function Ye(e){if(e.length<2)return null;let t=Math.max(1,e.length-64),n=[];for(let r=t;r<e.length;r+=1)n.push(e.time(r)-e.time(r-1));return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]??null}function Xe(e,t,n){if(t===null)return e.length===1&&n===e.time(0)?0:NaN;if(n<=e.time(0))return(n-e.time(0))/t;let r=e.lowerBound(n),i=r<e.length&&e.time(r)===n?r:r-1,a=e.length-1;if(i>=a)return a+(n-e.time(a))/t;let o=e.time(i);return i+(n-o)/(e.time(i+1)-o)}function Ze(e,t,n){if(t===null)return e.length===1&&n===0?e.time(0):NaN;let r=e.length-1;if(n<=0)return e.time(0)+n*t;if(n>=r)return e.time(r)+(n-r)*t;let i=Math.floor(n),a=e.time(i);return a+(n-i)*(e.time(i+1)-a)}function Qe(e){return typeof e==`number`&&Number.isFinite(e)}function $e(e,t){return t===void 0?e:`${e}[${t}]`}function et(e,t=`bar`,r){let o=e;(typeof o!=`object`||!o||Array.isArray(o))&&h($e(t,r),o);let s=Qe(e.time)?e.time:a(e.time,`${$e(t,r)}.time`),{open:c,high:l,low:u,close:d}=e,f=e.volume??0;if(!Qe(c)||!Qe(l)||!Qe(u)||!Qe(d)||!Qe(f)){let[e,a]=Object.entries({open:c,high:l,low:u,close:d,volume:f}).find(([,e])=>!Qe(e));n(`${$e(t,r)}.${e} must be a finite number, received ${i(a)}.`)}return(l<Math.max(c,d)||u>Math.min(c,d))&&n(`${$e(t,r)} is inconsistent: high (${l}) and low (${u}) must enclose open (${c}) and close (${d}).`),f<0&&n(`${$e(t,r)}.volume must not be negative, received ${f}.`),{time:s,open:c,high:l,low:u,close:d,volume:f}}function tt(e,t=`bars`){return e.map((e,n)=>et(e,t,n))}var nt=class{times=/* @__PURE__ */ new Float64Array;opens=/* @__PURE__ */ new Float64Array;highs=/* @__PURE__ */ new Float64Array;lows=/* @__PURE__ */ new Float64Array;closes=/* @__PURE__ */ new Float64Array;volumes=/* @__PURE__ */ new Float64Array;count=0;changes=new Ve;cachedInterval=null;get length(){return this.count}get revision(){return this.changes.revision}time(e){return this.times[e]??NaN}open(e){return this.opens[e]??NaN}high(e){return this.highs[e]??NaN}low(e){return this.lows[e]??NaN}close(e){return this.closes[e]??NaN}volume(e){return this.volumes[e]??NaN}price(e,t){switch(t){case`open`:return this.open(e);case`high`:return this.high(e);case`low`:return this.low(e);case`close`:return this.close(e);case`hl2`:return(this.high(e)+this.low(e))/2;case`hlc3`:return(this.high(e)+this.low(e)+this.close(e))/3;case`ohlc4`:return(this.open(e)+this.high(e)+this.low(e)+this.close(e))/4}}bar(e){return Number.isInteger(e)&&e>=0&&e<this.count?this.read(e):null}read(e){return{time:this.time(e),open:this.open(e),high:this.high(e),low:this.low(e),close:this.close(e),volume:this.volume(e)}}toArray(){return Array.from({length:this.count},(e,t)=>this.read(t))}lowerBound(e){let t=0,n=this.count;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}indexOf(e){let t=this.lowerBound(e);return t<this.count&&this.time(t)===e?t:-1}indexAt(e){let t=this.lowerBound(e);return t<this.count&&this.time(t)===e?t:t-1}logicalIndexOf(e){return Xe(this,this.interval(),e)}timeOfLogicalIndex(e){return Ze(this,this.interval(),e)}interval(){return this.cachedInterval!==null||this.count<2||(this.cachedInterval=Ye(this)),this.cachedInterval}changesSince(e){return this.changes.since(e)}set(e){let t=tt(e);qe(t,`bars`),this.assign(t)}clear(){this.count=0,this.markReset()}assign(e){this.allocate(e.length),e.forEach((e,t)=>{this.write(t,e)}),this.count=e.length,this.markReset()}replaceFrom(e,t){let n=e+t.length,r=n!==this.count;this.ensureCapacity(n),t.forEach((t,n)=>{r||=this.time(e+n)!==t.time,this.write(e+n,t)}),this.count=n,r&&(this.cachedInterval=null),this.changes.tail(e)}insertBefore(e){e.length&&this.replaceFirst(0,e)}replaceFirst(e,t){let n=t.length-e,r=this.count,i=e=>Ke(e,r,n);this.times=i(this.times),this.opens=i(this.opens),this.highs=i(this.highs),this.lows=i(this.lows),this.closes=i(this.closes),this.volumes=i(this.volumes),t.forEach((e,t)=>{this.write(t,e)}),this.count=r+n,this.markReset()}write(e,t){this.times[e]=t.time,this.opens[e]=t.open,this.highs[e]=t.high,this.lows[e]=t.low,this.closes[e]=t.close,this.volumes[e]=t.volume}allocate(e){let t=Math.max(16,e);this.times=new Float64Array(t),this.opens=new Float64Array(t),this.highs=new Float64Array(t),this.lows=new Float64Array(t),this.closes=new Float64Array(t),this.volumes=new Float64Array(t)}ensureCapacity(e){let t=this.count,n=n=>Ge(n,t,e);this.times=n(this.times),this.opens=n(this.opens),this.highs=n(this.highs),this.lows=n(this.lows),this.closes=n(this.closes),this.volumes=n(this.volumes)}markReset(){this.changes.reset(),this.cachedInterval=null}},rt=class{store;count;moves;countedAt=-1;counted=0;constructor(e,t=()=>e.length,n=()=>0){this.store=e,this.count=t,this.moves=n}get length(){let e=this.revision;return e!==this.countedAt&&(this.countedAt=e,this.counted=this.count()),this.counted}get revision(){return this.store.revision+this.moves()}time(e){return this.store.time(e)}open(e){return this.store.open(e)}high(e){return this.store.high(e)}low(e){return this.store.low(e)}close(e){return this.store.close(e)}volume(e){return this.store.volume(e)}bar(e){return e<this.length?this.store.bar(e):null}lowerBound(e){return Math.min(this.store.lowerBound(e),this.length)}};function it(e,t=`points`){return e.map((e,r)=>{h(`${t}[${r}]`,e);let o=a(e.time,`${t}[${r}].time`);return e.value!==null&&(typeof e.value!=`number`||!Number.isFinite(e.value))&&n(`${t}[${r}].value must be a finite number or null, received ${i(e.value)}.`),{time:o,value:e.value??NaN}})}var at=class{times=/* @__PURE__ */ new Float64Array;values=/* @__PURE__ */ new Float64Array;count=0;get length(){return this.count}time(e){return this.times[e]??NaN}value(e){return this.values[e]??NaN}lowerBound(e){let t=0,n=this.count;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}clear(){this.count=0}assign(e){this.times=Float64Array.from(e,e=>e.time),this.values=Float64Array.from(e,e=>e.value),this.count=e.length}replaceFrom(e,t){let n=e+t.length;this.grow(n),t.forEach((t,n)=>{this.times[e+n]=t.time,this.values[e+n]=t.value}),this.count=n}insertBefore(e){this.replaceFirst(0,e)}replaceFirst(e,t){let n=t.length-e;this.times=Ke(this.times,this.count,n),this.values=Ke(this.values,this.count,n),t.forEach((e,t)=>{this.times[t]=e.time,this.values[t]=e.value}),this.count+=n}grow(e){this.times=Ge(this.times,this.count,e),this.values=Ge(this.values,this.count,e)}};let ot=e=>e;function st(){}var ct=class{values=/* @__PURE__ */ new Float64Array;count=0;at(e){return this.values[e]??NaN}assign(e){this.values=e,this.count=e.length}clear(){this.count=0}writeFrom(e,t){let n=e+t.length;this.values=Ge(this.values,e,n),this.values.set(t,e),this.count=n}prepend(e){this.values=Ke(this.values,this.count,e.length),this.values.set(e),this.count+=e.length}lastBefore(e){for(let t=e-1;t>=0;--t){let e=this.at(t);if(!Number.isNaN(e))return e}return-1/0}first(){for(let e=0;e<this.count;e+=1){let t=this.at(e);if(!Number.isNaN(t))return t}return 1/0}runStart(e,t){let n=e;for(;n>0;){let e=this.at(n-1);if(!Number.isNaN(e)&&e!==t)break;--n}return n}};function lt(e,t,r,i){let a=new Float64Array(e),s=i;for(let i=0;i<e;i+=1){let e=t(i),c=r(i,e);c===null?a[i]=NaN:(c<s&&n(`The calendar puts ${o(e)} into the bucket ${o(c)}, before the bucket ${o(s)} of an earlier time; buckets must not decrease with time.`),a[i]=c,s=c)}return a}var ut=class{source;target;kind;bucketer;buckets=new ct;cutoff=1/0;moves=0;constructor(e,t,n,r){this.source=e,this.target=t,this.kind=n,this.bucketer=r}get display(){return this.target}setDisplay(e){this.target.clear(),this.target=e,this.rebuild()}planSet(e,t){let n=this.kind.parse(e,this.kind.label);qe(n,this.kind.label);let r=lt(n.length,e=>n[e]?.time??NaN,(e,n)=>t(n),-1/0);return()=>{this.source.assign(n),this.buckets.assign(r),this.bucketer=t,this.rebuild()}}planUpdate(e){let{label:t,noun:n}=this.kind,r=this.source.length,{from:i,tail:a}=Je(this.kind.parse(e,t),r,this.source.time(r-1),t,n);if(a.length===0)return st;let o=i<r?this.buckets.at(i):NaN,s=lt(a.length,e=>a[e]?.time??NaN,(e,t)=>e===0&&i<r?Number.isNaN(o)?null:o:this.bucketer(t),this.buckets.lastBefore(i));return()=>{this.source.replaceFrom(i,a),this.buckets.writeFrom(i,s),this.refresh(i,this.limit())}}planPrepend(e){let t=this.kind.parse(e,this.kind.label);qe(t,this.kind.label);let r=this.source.length?this.source.time(0):1/0,i=t.filter(e=>e.time<r);if(i.length===0)return{inserted:0,commit:st};let a=lt(i.length,e=>i[e]?.time??NaN,(e,t)=>this.bucketer(t),-1/0),s=a.reduce((e,t)=>Number.isNaN(t)?e:t,-1/0),c=this.buckets.first();return s>c&&n(`The calendar puts older points into the bucket ${o(s)}, after the bucket ${o(c)} of a later time; buckets must not decrease with time.`),{inserted:i.length,commit:()=>{this.source.insertBefore(i),this.buckets.prepend(a),this.showOlder(i.length)}}}planRebucket(e){let t=lt(this.source.length,e=>this.source.time(e),(t,n)=>e(n),-1/0);return()=>{this.buckets.assign(t),this.bucketer=e,this.rebuild()}}follow(e){if(e.kind===`reset`){this.planRebucket(this.bucketer)();return}let{from:t}=e,n=lt(this.source.length-t,e=>this.source.time(t+e),(e,t)=>this.bucketer(t),this.buckets.lastBefore(t));this.buckets.writeFrom(t,n),this.refresh(t,this.limit())}cutoffTime(){return this.cutoff}setCutoff(e){let t=this.limit();this.cutoff=e;let n=this.limit();return n!==t&&(this.moves+=1,this.refresh(Math.min(t,n),Math.max(t,n)))}nextCutoff(e,t){let n=this.source.length,r=this.countUpTo(e);if(r>=n)return null;if(t){for(;r<n-1&&Number.isNaN(this.buckets.at(r));)r+=1;let e=this.buckets.at(r);for(;r<n-1;){let t=this.buckets.at(r+1);if(!Number.isNaN(t)&&t!==e)break;r+=1}}return this.source.time(r)}revealed(){return this.limit()}cutoffMoves(){return this.moves}firstTime(){return this.source.length>0?this.source.time(0):null}clear(){this.source.clear(),this.buckets.clear(),this.display.clear()}limit(){return this.countUpTo(this.cutoff)}countUpTo(e){if(e===1/0)return this.source.length;let t=0,n=this.source.length;for(;t<n;){let r=t+n>>>1;this.source.time(r)<=e?t=r+1:n=r}return t}rebuild(){this.display.assign(this.kind.aggregate(this.source,this.buckets,0,this.limit()))}showOlder(e){let t=this.display;if(t.length===0){this.rebuild();return}let n=t.time(0),r=this.limit(),i=e;for(;i<r;){let e=this.buckets.at(i);if(!Number.isNaN(e)&&e!==n)break;i+=1}t.replaceFirst(1,this.kind.aggregate(this.source,this.buckets,0,i))}refresh(e,t){let n=e;for(;n<t&&Number.isNaN(this.buckets.at(n));)n+=1;if(n>=t)return!1;let r=this.buckets.at(n),i=this.display.lowerBound(r),a=this.kind.aggregate(this.source,this.buckets,this.buckets.runStart(n,r),this.limit()),o=this.display.length;return i>=o-1&&i+a.length>=o?this.display.replaceFrom(i,a):this.rebuild(),!0}};function dt(e,t,n,r){let i=[],a=NaN,o=0,s=0,c=0,l=0,u=0;for(let d=n;d<r;d+=1){let n=t.at(d);Number.isNaN(n)||(n===a?(s=Math.max(s,e.high(d)),c=Math.min(c,e.low(d)),l=e.close(d),u+=e.volume(d)):(Number.isNaN(a)||i.push({time:a,open:o,high:s,low:c,close:l,volume:u}),a=n,o=e.open(d),s=e.high(d),c=e.low(d),l=e.close(d),u=e.volume(d)))}return Number.isNaN(a)||i.push({time:a,open:o,high:s,low:c,close:l,volume:u}),i}function ft(e,t,n,r){let i=[],a=NaN,o=NaN;for(let s=n;s<r;s+=1){let n=t.at(s);if(Number.isNaN(n))continue;n!==a&&(Number.isNaN(a)||i.push({time:a,value:o}),a=n,o=NaN);let r=e.value(s);Number.isNaN(r)||(o=r)}return Number.isNaN(a)||i.push({time:a,value:o}),i}let pt={label:`bars`,noun:`bar`,parse:tt,aggregate:dt},mt={label:`points`,noun:`point`,parse:it,aggregate:ft};function ht(e,t=new nt){return new ut(new nt,t,pt,e)}function gt(e,t){return new ut(e,new nt,pt,t)}function _t(e){return new ut(new at,new at,mt,e)}let vt=g({id:!0,type:!0,pane:!0,scale:!0,title:!0,visible:!0,precision:!0,lastValueLabel:!0,style:!0,data:!0}),yt=g({title:!0,visible:!0,precision:!0,lastValueLabel:!0,style:!0,scale:!0});function bt(e){_(`series`,e,vt)}function xt(e){return e===null?null:d(`series.precision`,e,{min:0,max:12,integer:!0})}var St=class e{registry;theme;entries=/* @__PURE__ */ new Map;ids;bucketer=ot;cutoff=1/0;constructor(e,t,n){this.registry=e,this.theme=t,this.ids=new de(e=>this.entries.has(e),n)}staging(t){let n=new e(this.registry,this.theme,this.ids);return n.bucketer=this.bucketer,n.cutoff=this.cutoff,n.ids.reserve(t),n}list(){return[...this.entries.values()]}get(e){return this.entries.get(e)}require(e){return this.entries.get(e)??n(`Unknown series "${e}".`)}info(e){return{id:e.id,type:e.type,pane:e.pane,scale:e.scale,title:e.title,visible:e.visible,precision:e.precision,lastValueLabel:e.lastValueLabel,style:{...e.style}}}add(e,t){let r=e.id??this.ids.next(e.type);p(`series.id`,r),p(`series.type`,e.type),this.entries.has(r)&&n(`A series with id "${r}" already exists.`);let i=this.registry.require(e.type),a=i.input===`ohlc`?{input:`ohlc`,feed:ht(this.bucketer)}:{input:`value`,feed:_t(this.bucketer)};a.feed.setCutoff(this.cutoff);let o={id:r,type:e.type,definition:i,pane:t,scale:e.scale===void 0?`right`:p(`series.scale`,e.scale),title:e.title===void 0?r:p(`series.title`,e.title),visible:e.visible===void 0||f(`series.visible`,e.visible),precision:e.precision===void 0?null:xt(e.precision),lastValueLabel:e.lastValueLabel!==void 0&&f(`series.lastValueLabel`,e.lastValueLabel),style:e.style===void 0?{}:this.checkStyle(i,e.style),bars:a.input===`ohlc`?a.feed.display:null,values:a.input===`value`?a.feed.display:null,source:a,latestTrade:-1/0};return e.data&&this.write(o,`set`,e.data),this.entries.set(r,o),this.ids.note(r),o}update(e,t){_(`series patch`,t,yt);let n=this.require(e),r=t.title===void 0?n.title:p(`series.title`,t.title),i=t.scale===void 0?n.scale:p(`series.scale`,t.scale),a=t.visible===void 0?n.visible:f(`series.visible`,t.visible),o=t.precision===void 0?n.precision:xt(t.precision),s=t.lastValueLabel===void 0?n.lastValueLabel:f(`series.lastValueLabel`,t.lastValueLabel),c=t.style===void 0?n.style:{...n.style,...this.checkStyle(n.definition,t.style)};n.title=r,n.scale=i,n.visible=a,n.precision=o,n.lastValueLabel=s,n.style=c}checkStyle(e,t){let n=this.theme();return _(`series.style`,t,Object.keys(e.defaultStyle(n,n.text))),Ie(`series.style`,t),{...t}}move(e,t){this.require(e).pane=t}remove(e){let t=this.require(e);return this.entries.delete(e),t}adopt(e){this.entries.clear(),e.entries.forEach((e,t)=>{this.entries.set(t,e),this.ids.note(t)})}write(e,t,r){let{source:i}=e;if(i.input===`ohlc`)Ct(i.feed,t,r,this.bucketer)();else{let a=r.map((t,r)=>((typeof t!=`object`||!t||!(`value`in t))&&n(`Series "${e.id}" of type "${e.type}" needs { time, value } points (points[${r}]).`),t));Ct(i.feed,t,a,this.bucketer)()}t===`set`&&(e.latestTrade=-1/0)}planRebucket(e){let t=this.list().map(t=>t.source.feed.planRebucket(e));return()=>{t.forEach(e=>{e()}),this.bucketer=e}}setCutoff(e){this.cutoff=e;for(let t of this.entries.values())t.source.feed.setCutoff(e)}};function Ct(e,t,n,r){return t===`set`?e.planSet(n,r):t===`update`?e.planUpdate(n):e.planPrepend(n).commit}function wt(e){h(`series type definition`,e),p(`series type definition type`,e.type),m(`definition.input`,e.input,[`ohlc`,`value`]),(typeof e.defaultStyle!=`function`||typeof e.paint!=`function`)&&n(`A series type definition needs defaultStyle() and paint() functions.`)}function Tt(e,t,n){bt(n);let r=n.pane??`main`;r!==`new`&&e.panes.require(r);let i=r===`new`;return{entry:t.add(n,i?b:r),own:i}}function Et(e){let t=t=>{e.run(()=>{v(`series`,t);let r=e.series.staging(t),i=t.flatMap(t=>{let n=Tt(e,r,t);return n.own?[n.entry.id]:[]});e.values.verify((e,t)=>{e.kind===`series`&&!r.get(e.id)&&n(`${t}: unknown series "${e.id}".`)});let a=e.series.list().map(e=>e.pane);e.series.adopt(r),a.forEach(t=>{e.releasePane(t)}),i.forEach(t=>{e.series.move(t,e.createAutoPane(t))}),e.values.reset(),e.invalidate()})},r=(t,n,r)=>{e.run(()=>{e.series.write(e.series.require(t),n,r),n!==`update`&&e.values.reset(),e.invalidate()})};return{set:t,add:t=>e.run(()=>{let{entry:n,own:r}=Tt(e,e.series,t);return r&&e.series.move(n.id,e.createAutoPane(n.id)),e.invalidate(),n.id}),update:(t,n)=>{e.run(()=>{e.series.update(t,n),e.invalidate()})},remove:t=>{e.run(()=>{e.values.assertUnused(`series`,t);let n=e.series.remove(t);e.releasePane(n.pane),e.invalidate()})},clear:()=>{t([])},get:t=>{let n=e.series.get(t);return n?e.series.info(n):null},list:()=>e.series.list().map(t=>e.series.info(t)),setData:(e,t)=>{r(e,`set`,t)},updateData:(e,t)=>{r(e,`update`,Array.isArray(t)?t:[t])},prependData:(e,t)=>{r(e,`prepend`,t)},addTrades:(t,n)=>e.run(()=>{let r=e.market.addSeriesTrades(e.series.require(t),Array.isArray(n)?n:[n]);return e.invalidate(),r}),register:t=>{e.run(()=>{wt(t),e.seriesTypes.register(t),e.bus.emit(`typesChange`,{kind:`series`,type:t.type,registered:!0})})},unregister:t=>{e.run(()=>{e.seriesTypes.require(t),e.options.mainSeries.type===t&&n(`The main series is of type "${t}"; change it first.`);let r=e.series.list().filter(e=>e.type===t);r.length>0&&n(`The series ${r.map(e=>`"${e.id}"`).join(`, `)} are of type "${t}"; remove them first.`),e.seriesTypes.unregister(t),e.bus.emit(`typesChange`,{kind:`series`,type:t,registered:!1})})},types:()=>e.seriesTypes.types(),definition:t=>e.seriesTypes.get(t)??null}}let Dt=[`left`,`center`,`right`],Ot=1.25;function kt(e){return Number.isFinite(e)?e:null}function At(e){let t=e.timeScale,n=t=>{e.run(()=>{e.frame(),t(),e.invalidate()})};return{visibleRange:()=>{e.frame();let n=t.visibleBars();return n?{from:e.bars.time(n.from),to:e.bars.time(n.to)}:null},setVisibleRange:({from:r,to:i})=>{let o=e.bars.logicalIndexOf(a(r,`range.from`)),s=e.bars.logicalIndexOf(a(i,`range.to`));Number.isFinite(o)&&Number.isFinite(s)&&n(()=>{t.setLogicalRange({from:Math.min(o,s)-.5,to:Math.max(o,s)+.5})})},visibleLogicalRange:()=>(e.frame(),e.bars.length>0?t.logicalRange():null),setVisibleLogicalRange:e=>{d(`range.from`,e.from),d(`range.to`,e.to),n(()=>{t.setLogicalRange(e)})},scrollToTime:(r,i=`center`)=>{let o=e.bars.logicalIndexOf(a(r));m(`align`,i,Dt),Number.isFinite(o)&&n(()=>{t.scrollToIndex(o,i)})},scrollToIndex:(e,r=`center`)=>{d(`index`,e),m(`align`,r,Dt),n(()=>{t.scrollToIndex(e,r)})},scrollToRealTime:()=>{n(()=>{t.scrollToRealTime()})},isFollowing:()=>t.isFollowing(),fitContent:()=>{n(()=>{t.fitContent()})},zoomIn:()=>{n(()=>{t.zoom(Ot,t.zoomAnchor(null))})},zoomOut:()=>{n(()=>{t.zoom(1/Ot,t.zoomAnchor(null))})},barSpacing:()=>t.barSpacing,setBarSpacing:e=>{d(`spacing`,e,{min:0,exclusiveMin:!0}),n(()=>{t.setBarSpacing(e)})},reset:()=>{n(()=>{t.reset(e.options.timeScale.barSpacing)})},timeToX:n=>{let r=e.frame().layout.leftAxisWidth;return kt(t.indexToX(e.bars.logicalIndexOf(a(n)))+r)},xToTime:n=>{d(`x`,n);let r=e.frame().layout.leftAxisWidth;return kt(e.bars.timeOfLogicalIndex(t.xToIndex(n-r)))},indexToX:n=>{d(`index`,n);let r=e.frame().layout.leftAxisWidth;return e.bars.length>0?t.indexToX(n)+r:null},xToIndex:n=>{d(`x`,n);let r=e.frame().layout.leftAxisWidth;return e.bars.length>0?t.xToIndex(n-r):null}}}function jt(e){h(`transform definition`,e),p(`transform definition type`,e.type),p(`transform definition name`,e.name),f(`transform definition keepsTime`,e.keepsTime),typeof e.create!=`function`&&n(`A transform definition needs a create() function.`)}function Mt(e){let{transforms:t}=e.market;return{set:t=>{e.run(()=>{e.setTransform(t)})},get:()=>e.market.transform(),register:n=>{e.run(()=>{jt(n),t.register(n),e.bus.emit(`typesChange`,{kind:`transform`,type:n.type,registered:!0})})},unregister:r=>{e.run(()=>{t.require(r),e.market.transform()?.type===r&&n(`The "${r}" transform builds the displayed bars; set another one first.`),t.unregister(r),e.bus.emit(`typesChange`,{kind:`transform`,type:r,registered:!1})})},types:()=>t.types(),definition:e=>t.get(e)??null}}var Nt=class{listeners=/* @__PURE__ */ new Map;queue=[];depth=0;flushing=!1;on(e,t){let n=this.listeners.get(e);return n||(n=/* @__PURE__ */ new Set,this.listeners.set(e,n)),n.add(t),()=>{let n=this.listeners.get(e);n?.delete(t),n?.size===0&&this.listeners.delete(e)}}has(e){return this.listeners.has(e)}emit(e,t){this.listeners.has(e)&&(this.queue.push({type:e,event:t}),this.depth===0&&this.flush())}defer(e){this.depth+=1;try{return e()}finally{--this.depth,this.depth===0&&this.flush()}}clear(){this.listeners.clear(),this.queue.length=0}flush(){if(this.flushing)return;this.flushing=!0;let e=[];try{for(let t=this.queue.shift();t;t=this.queue.shift()){let n=this.listeners.get(t.type);if(n)for(let r of[...n])try{r(t.event)}catch(t){e.push(t)}}}finally{this.flushing=!1}if(e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,`Multiple chart event listeners threw.`)}};let Pt=36e5,Ft=9e5,It=4096;function Lt(e,t){let n=e.find(e=>e.type===t);return n?Number(n.value):0}var Rt=class{timeZone;hours=new Float64Array(It).fill(NaN);offsets=new Float64Array(It);zoneFormat;constructor(e){this.timeZone=e,this.zoneFormat=e===null?null:new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})}offset(e){let t=this.zoneFormat;if(!t)return-new Date(e).getTimezoneOffset()*6e4;let n=Math.floor(e/Pt),r=n&4095;if(this.hours[r]===n)return this.offsets[r]??0;let i=n*Pt,a=this.lookUp(t,i);return this.lookUp(t,i+Pt-Ft)===a?(this.hours[r]=n,this.offsets[r]=a,a):this.lookUp(t,Math.floor(e/Ft)*Ft)}lookUp(e,t){let n=e.formatToParts(t);return Date.UTC(Lt(n,`year`),Lt(n,`month`)-1,Lt(n,`day`),Lt(n,`hour`),Lt(n,`minute`),Lt(n,`second`))-t}instant(e){let t=e-this.offset(e);return e-this.offset(t)}fields(e){if(!this.zoneFormat){let t=new Date(e);return{year:t.getFullYear(),month:t.getMonth(),day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds()}}let t=new Date(e+this.offset(e));return{year:t.getUTCFullYear(),month:t.getUTCMonth(),day:t.getUTCDate(),hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}},zt=class{clock;numberFormats=/* @__PURE__ */ new Map;compactFormat;smallFormat;tinyFormat;timeFormats;dayFormat;minuteFormat;secondFormat;locale;timeZone;given;constructor(e,t){this.given=e??void 0,this.clock=new Rt(t),this.compactFormat=new Intl.NumberFormat(this.given,{notation:`compact`,maximumFractionDigits:2}),this.smallFormat=new Intl.NumberFormat(this.given,{maximumSignificantDigits:3}),this.tinyFormat=new Intl.NumberFormat(this.given,{notation:`scientific`,maximumSignificantDigits:3});let n=e=>new Intl.DateTimeFormat(this.given,{timeZone:t??void 0,...e}),r=n({}).resolvedOptions();this.locale=this.compactFormat.resolvedOptions().locale,this.timeZone=r.timeZone;let i={hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`};this.timeFormats={year:n({year:`numeric`}),month:n({month:`short`}),day:n({day:`numeric`}),hour:n(i),minute:n(i),second:n({...i,second:`2-digit`})},this.dayFormat=n({year:`numeric`,month:`short`,day:`numeric`,weekday:`short`}),this.minuteFormat=n({year:`numeric`,month:`short`,day:`numeric`,...i}),this.secondFormat=n({year:`numeric`,month:`short`,day:`numeric`,...i,second:`2-digit`})}number(e,t){let n=this.numberFormats.get(t);return n||(n=new Intl.NumberFormat(this.given,{minimumFractionDigits:t,maximumFractionDigits:t}),this.numberFormats.set(t,n)),n.format(e)}compact(e){let t=Math.abs(e);return t===0||t>=1?this.compactFormat.format(e):(t<1e-4?this.tinyFormat:this.smallFormat).format(e)}timeTick(e,t){return this.timeFormats[t].format(e)}timeCrosshair(e,t){return t!==null&&t>=864e5?this.dayFormat.format(e):t!==null&&t<6e4?this.secondFormat.format(e):this.minuteFormat.format(e)}duration(e,t){let n=Math.max(0,Math.ceil(e/1e3)),r=Math.floor(n/86400),i=Math.floor(n%86400/3600),a=Math.floor(n%3600/60),o=n%60,s=e=>String(e).padStart(2,`0`);return r>0?`${t(r)} ${s(i)}:${s(a)}:${s(o)}`:i>0?`${i}:${s(a)}:${s(o)}`:`${s(a)}:${s(o)}`}};function Bt(e,t=0,n=8){let r=t;if(!Number.isFinite(e))return r;for(;r<n;){let t=e*10**r;if(Math.abs(t-Math.round(t))<Math.max(1e-9,Math.abs(t)*1e-12))break;r+=1}return r}let Vt={legendOpen:`O`,legendHigh:`H`,legendLow:`L`,legendClose:`C`,legendVolume:`V`,days:e=>`${e}d`};function Ht(e){return Object.fromEntries(Object.keys(e).map(e=>[e,null]))}function Ut(e,t,r){h(e,t);for(let[i,a]of Object.entries(t)){Object.hasOwn(r,i)||n(`${e} has no entry "${i}".`);let t=typeof r[i];a!==null&&typeof a!==t&&n(`${e}.${i} must be ${t===`function`?`a function`:`a string`} or null.`)}}function Wt(e,t){let n=Object.entries(t).filter(([,e])=>e!==null);return{...e,...Object.fromEntries(n)}}function Gt(e){return Wt(Vt,e.texts)}let Kt=Ce({background:`#0e0e0e`,text:`#d8d8d8`,textMuted:`#9b9b9b`,grid:`rgba(140, 140, 140, 0.085)`,border:`rgba(140, 140, 140, 0.17)`,crosshair:`rgba(216, 216, 216, 0.45)`,crosshairLabelBackground:`#2a2a2a`,crosshairLabelText:`#f2f2f2`,up:`#2fb57e`,down:`#ef5d5d`,volumeUp:`rgba(47, 181, 126, 0.4)`,volumeDown:`rgba(239, 93, 93, 0.4)`,accent:`#3a74dc`,palette:[`#e8b04a`,`#5b9cf0`,`#b48cf0`,`#3cc4b0`,`#ef7d8e`,`#9fcf4a`,`#ee8a3c`,`#d77fd8`],buy:`#2fb57e`,sell:`#ef5d5d`,alert:`#e3a33b`}),qt=Ce({background:`#ffffff`,text:`#1c2433`,textMuted:`#6b7485`,grid:`rgba(28, 36, 51, 0.06)`,border:`rgba(28, 36, 51, 0.12)`,crosshair:`rgba(28, 36, 51, 0.42)`,crosshairLabelBackground:`#1c2433`,crosshairLabelText:`#ffffff`,up:`#14a37f`,down:`#e5484d`,volumeUp:`rgba(20, 163, 127, 0.32)`,volumeDown:`rgba(229, 72, 77, 0.32)`,accent:`#4f46e5`,palette:[`#f59e0b`,`#4f46e5`,`#0891b2`,`#db2777`,`#65a30d`,`#9333ea`,`#ea580c`,`#0d9488`],buy:`#14a37f`,sell:`#e5484d`,alert:`#f59e0b`});function Jt(e=[]){return{...Object.fromEntries(e.map(e=>[e.key,e.defaults()])),autoSize:!0,locale:null,timeZone:null,theme:qt,font:{family:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif`,size:12},grid:{vertical:!0,horizontal:!0,style:`solid`},crosshair:{mode:`free`,vertical:!0,horizontal:!0,labels:!0,style:`dashed`,snapToBars:!0},mainSeries:{type:`candles`,source:`close`,styles:{},barColor:null},timeScale:{visible:!0,height:28,barSpacing:8,minBarSpacing:.5,maxBarSpacing:60,rightOffset:60,loadMoreThreshold:20,formatter:null},priceScale:{visible:!0,margins:{top:.1,bottom:.08},precision:`auto`,formatter:null,minWidth:48},latestPrice:{line:!0,label:!0,countdown:!1,style:`dotted`,color:null},legend:{visible:!0,rows:null,buttons:null,hideValuesOnHover:!0,top:0},texts:Ht(Vt),interaction:{pan:!0,wheelZoom:!0,pinchZoom:!0,axisScale:!0,kineticScroll:!0,keyboard:!0,longPressMs:300,touchMagnifier:!0,hitTolerance:6},panes:{defaultHeight:120,minHeight:40,separatorHeight:5,separatorWidth:2,separatorColor:null,separatorHoverColor:null},calendar:{timeZone:`UTC`,sessions:[],dayStart:`00:00`,weekdays:[0,1,2,3,4,5,6],weekStart:1,bucket:null},performance:{maxPixelRatio:3,maxTrades:1e5}}}let Yt=[`open`,`high`,`low`,`close`,`hl2`,`hlc3`,`ohlc4`],Xt=/^([01]\d|2[0-3]):([0-5]\d)$/;function Zt(e,t){let r=typeof t==`string`?Xt.exec(t):null;return r?Number(r[1])*60+Number(r[2]):n(`${e} must be a time of day such as "09:30", received ${i(t)}.`)}function Qt(e,t){let r=p(e,t),[i,a,o]=r.split(`-`);(i===void 0||a===void 0||o!==void 0)&&n(`${e} must be a session such as "09:30-11:30", received ${JSON.stringify(r)}.`);let s={start:Zt(e,i),end:Zt(e,a)};return s.start===s.end&&n(`${e} ${JSON.stringify(r)} has no length.`),s}function $t(e){return e.start<e.end?[[e.start,e.end]]:[[e.start,1440],[0,e.end]]}function en(e,t){return e.start<e.end?t>e.start&&t<e.end:t>e.start||t<e.end}function tn(e,t,r){e.forEach((i,a)=>{for(let o=0;o<a;o+=1){let s=e[o];s!==void 0&&$t(i).some(([e,t])=>$t(s).some(([n,r])=>e<r&&n<t))&&n(`${r}.sessions[${a}] ${JSON.stringify(t[a])} overlaps ${r}.sessions[${o}] ${JSON.stringify(t[o])}.`)}})}function nn(e,t){v(`${t}.sessions`,e.sessions);let r=e.sessions.map((e,n)=>p(`${t}.sessions[${n}]`,e)),i=r.map((e,n)=>Qt(`${t}.sessions[${n}]`,e));tn(i,r,t);let a=Zt(`${t}.dayStart`,e.dayStart);i.forEach((i,o)=>{en(i,a)&&n(`${t}.sessions[${o}] ${JSON.stringify(r[o])} spans the start of the trading day (${e.dayStart}); set ${t}.dayStart to the time the trading day begins.`)}),v(`${t}.weekdays`,e.weekdays),e.weekdays.length===0&&n(`${t}.weekdays must contain at least one weekday.`);let o=Array.from({length:7},()=>!1);e.weekdays.forEach((e,r)=>{let i=d(`${t}.weekdays[${r}]`,e,{min:0,max:6,integer:!0});o[i]&&n(`${t}.weekdays contains ${i} twice.`),o[i]=!0});let s=d(`${t}.weekStart`,e.weekStart,{min:0,max:6,integer:!0});return ee(`${t}.bucket`,e.bucket),{sessions:i,dayStart:a,weekdays:o,weekStart:s,bucket:e.bucket}}function rn(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function an(e,t){return e===t||e.timeZone===t.timeZone&&e.dayStart===t.dayStart&&e.weekStart===t.weekStart&&e.bucket===t.bucket&&rn(e.sessions,t.sessions)&&rn(e.weekdays,t.weekdays)}let on={font:g({family:!0,size:!0}),grid:g({vertical:!0,horizontal:!0,style:!0}),crosshair:g({mode:!0,vertical:!0,horizontal:!0,labels:!0,style:!0,snapToBars:!0}),mainSeries:g({type:!0,source:!0,styles:!0,barColor:!0}),timeScale:g({visible:!0,height:!0,barSpacing:!0,minBarSpacing:!0,maxBarSpacing:!0,rightOffset:!0,loadMoreThreshold:!0,formatter:!0}),priceScale:g({visible:!0,margins:!0,precision:!0,formatter:!0,minWidth:!0}),latestPrice:g({line:!0,label:!0,countdown:!0,style:!0,color:!0}),legend:g({visible:!0,rows:!0,buttons:!0,hideValuesOnHover:!0,top:!0}),interaction:g({pan:!0,wheelZoom:!0,pinchZoom:!0,axisScale:!0,kineticScroll:!0,keyboard:!0,longPressMs:!0,touchMagnifier:!0,hitTolerance:!0}),panes:g({defaultHeight:!0,minHeight:!0,separatorHeight:!0,separatorWidth:!0,separatorColor:!0,separatorHoverColor:!0}),calendar:g({timeZone:!0,sessions:!0,dayStart:!0,weekdays:!0,weekStart:!0,bucket:!0}),performance:g({maxPixelRatio:!0,maxTrades:!0})};function sn(e){for(let[t,n]of Object.entries(on))_(`options.${t}`,e[t],n)}let cn=[`solid`,`dashed`,`dotted`],ln=[`background`,`text`,`textMuted`,`grid`,`border`,`crosshair`,`crosshairLabelBackground`,`crosshairLabelText`,`up`,`down`,`volumeUp`,`volumeDown`,`accent`,`buy`,`sell`,`alert`];function un(e){if(e!==null)try{new Intl.NumberFormat(e)}catch{n(`options.locale ${JSON.stringify(e)} is not a valid BCP 47 language tag.`)}}function dn(e){_(`options.theme`,e,[...ln,`palette`]),ln.forEach(t=>{x(`options.theme.${t}`,e[t])}),(!Array.isArray(e.palette)||e.palette.length===0)&&n(`options.theme.palette must contain at least one color.`),e.palette.forEach((e,t)=>{x(`options.theme.palette[${t}]`,e)})}function fn(e){sn(e),f(`options.autoSize`,e.autoSize),un(e.locale),e.timeZone!==null&&te(`options.timeZone`,e.timeZone),dn(e.theme),p(`options.font.family`,e.font.family),d(`options.font.size`,e.font.size,{min:6,max:48}),f(`options.grid.vertical`,e.grid.vertical),f(`options.grid.horizontal`,e.grid.horizontal),m(`options.grid.style`,e.grid.style,cn),m(`options.crosshair.mode`,e.crosshair.mode,[`magnet`,`free`]),f(`options.crosshair.vertical`,e.crosshair.vertical),f(`options.crosshair.horizontal`,e.crosshair.horizontal),f(`options.crosshair.labels`,e.crosshair.labels),m(`options.crosshair.style`,e.crosshair.style,cn),f(`options.crosshair.snapToBars`,e.crosshair.snapToBars),p(`options.mainSeries.type`,e.mainSeries.type),m(`options.mainSeries.source`,e.mainSeries.source,Yt),ee(`options.mainSeries.barColor`,e.mainSeries.barColor),h(`options.mainSeries.styles`,e.mainSeries.styles);for(let[t,n]of Object.entries(e.mainSeries.styles))n!==null&&(h(`options.mainSeries.styles.${t}`,n),Ie(`options.mainSeries.styles.${t}`,n));let t=e.timeScale;f(`options.timeScale.visible`,t.visible),d(`options.timeScale.height`,t.height,{min:0}),d(`options.timeScale.minBarSpacing`,t.minBarSpacing,{min:.1}),d(`options.timeScale.maxBarSpacing`,t.maxBarSpacing,{min:t.minBarSpacing}),d(`options.timeScale.barSpacing`,t.barSpacing,{min:t.minBarSpacing,max:t.maxBarSpacing}),d(`options.timeScale.rightOffset`,t.rightOffset,{min:0}),d(`options.timeScale.loadMoreThreshold`,t.loadMoreThreshold,{min:0,integer:!0}),ee(`options.timeScale.formatter`,t.formatter);let n=e.priceScale;f(`options.priceScale.visible`,n.visible),ie(`options.priceScale.margins`,n.margins),n.precision!==`auto`&&d(`options.priceScale.precision`,n.precision,{min:0,max:12,integer:!0}),ee(`options.priceScale.formatter`,n.formatter),d(`options.priceScale.minWidth`,n.minWidth,{min:0}),f(`options.latestPrice.line`,e.latestPrice.line),f(`options.latestPrice.label`,e.latestPrice.label),f(`options.latestPrice.countdown`,e.latestPrice.countdown),m(`options.latestPrice.style`,e.latestPrice.style,cn),e.latestPrice.color!==null&&x(`options.latestPrice.color`,e.latestPrice.color),f(`options.legend.visible`,e.legend.visible),f(`options.legend.hideValuesOnHover`,e.legend.hideValuesOnHover),d(`options.legend.top`,e.legend.top,{min:0});let r=e.interaction;f(`options.interaction.pan`,r.pan),f(`options.interaction.wheelZoom`,r.wheelZoom),f(`options.interaction.pinchZoom`,r.pinchZoom),f(`options.interaction.axisScale`,r.axisScale),f(`options.interaction.kineticScroll`,r.kineticScroll),f(`options.interaction.keyboard`,r.keyboard),d(`options.interaction.longPressMs`,r.longPressMs,{min:0}),f(`options.interaction.touchMagnifier`,r.touchMagnifier),d(`options.interaction.hitTolerance`,r.hitTolerance,{min:1}),d(`options.panes.defaultHeight`,e.panes.defaultHeight,{min:1}),d(`options.panes.minHeight`,e.panes.minHeight,{min:1}),d(`options.panes.separatorHeight`,e.panes.separatorHeight,{min:0}),ee(`options.legend.rows`,e.legend.rows),ee(`options.legend.buttons`,e.legend.buttons),d(`options.panes.separatorWidth`,e.panes.separatorWidth,{min:0});for(let t of[`separatorColor`,`separatorHoverColor`])e.panes[t]!==null&&x(`options.panes.${t}`,e.panes[t]);te(`options.calendar.timeZone`,e.calendar.timeZone),nn(e.calendar,`options.calendar`),d(`options.performance.maxPixelRatio`,e.performance.maxPixelRatio,{min:1}),d(`options.performance.maxTrades`,e.performance.maxTrades,{min:0,max:1e7,integer:!0}),Ut(`options.texts`,e.texts,Vt)}function pn(e,t,r){if(t!==void 0){h(`options`,t);for(let r of Object.keys(t))Object.hasOwn(e,r)||n(`The chart has no option "${r}"; a module the chart lacks may add it.`)}let i=Se(e,t);return fn(i),r.forEach(e=>{let t=`options.${e.key}`,n=i[e.key];h(t,n),e.validate(n,t)}),Ce(i)}function mn(e,t){switch(e){case`solid`:return[];case`dashed`:return[4*t+2,3*t+1];case`dotted`:return[t,2*t+1]}}function C(e,t,n,r=`solid`){e.strokeStyle=t,e.lineWidth=n,e.setLineDash(mn(r,n))}function w(e,t,n){let r=Math.max(1,Math.round(t*n)),i=Math.round(e*n);return(r%2==1?i+.5:i)/n}function T(e,t){return Math.round(e*t)/t}function hn(e,t){e.save();try{t()}finally{e.restore()}}function E(e,t,n=`normal`){return`${n} ${e}px ${t}`}function gn(e,t,n,r,i){let a=e.measureText(t).width+i.paddingX*2,o=i.align===`left`?n:i.align===`right`?n-a:n-a/2,s=r-i.height/2;return e.fillStyle=i.background,e.beginPath(),e.roundRect(o,s,a,i.height,i.radius??2),e.fill(),e.fillStyle=i.color,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(t,o+a/2,r+.5),a}var _n=class{count=0;xs=/* @__PURE__ */ new Float64Array(64);opens=/* @__PURE__ */ new Float64Array(64);highs=/* @__PURE__ */ new Float64Array(64);lows=/* @__PURE__ */ new Float64Array(64);closes=/* @__PURE__ */ new Float64Array(64);volumes=/* @__PURE__ */ new Float64Array(64);values=/* @__PURE__ */ new Float64Array(64);ups=/* @__PURE__ */ new Uint8Array(64);colors=[];reset(e){if(this.count=0,this.colors.length=0,this.xs.length>=e)return;let t=Math.max(e,this.xs.length*2);this.xs=new Float64Array(t),this.opens=new Float64Array(t),this.highs=new Float64Array(t),this.lows=new Float64Array(t),this.closes=new Float64Array(t),this.volumes=new Float64Array(t),this.values=new Float64Array(t),this.ups=new Uint8Array(t)}pushOhlc(e,t,n,r,i,a,o,s=null){let c=this.count;this.colors[c]=s,this.xs[c]=e,this.opens[c]=t,this.highs[c]=n,this.lows[c]=r,this.closes[c]=i,this.volumes[c]=a,this.ups[c]=+!!o,this.count=c+1}pushValue(e,t,n){let r=this.count;this.colors[r]=null,this.xs[r]=e,this.volumes[r]=NaN,this.values[r]=t,this.ups[r]=+!!n,this.count=r+1}x(e){return this.xs[e]??NaN}open(e){return this.opens[e]??NaN}high(e){return this.highs[e]??NaN}low(e){return this.lows[e]??NaN}close(e){return this.closes[e]??NaN}volume(e){return this.volumes[e]??NaN}value(e){return this.values[e]??NaN}isUp(e){return this.ups[e]===1}color(e){return this.colors[e]??null}};let vn=/* @__PURE__ */ new WeakMap;function yn(e,t,n,r,i){let{theme:a}=n.options,o=vn.get(e);if(o?.definition===t&&o.theme===a&&o.color===r&&o.overrides===i)return o.style;let s=Se(t.defaultStyle(a,r),i);return vn.set(e,{definition:t,theme:a,color:r,overrides:i,style:s}),s}function bn(e,t){return e.precision===null?t:{kind:`decimal`,precision:e.precision}}var xn=class{sources;entry;range;format;color;pool;pane;scale;placed=e=>e;constructor(e,t,n,r,i,a){this.sources=e,this.entry=t,this.range=n,this.format=r,this.color=i,this.pool=a,this.pane=t.pane,this.scale=t.scale}window(){let{bars:e,timeScale:t}=this.sources,n=t.logicalRange(),r=this.entry.bars??this.entry.values,i=r?.length??0,a=e.length===1,o=e.timeOfLogicalIndex(a?0:Math.floor(n.from)-1),s=e.timeOfLogicalIndex(a?0:Math.ceil(n.to)+1);return!r||Number.isNaN(o)||Number.isNaN(s)?{from:0,to:-1}:{from:r.lowerBound(o),to:Math.min(i,r.lowerBound(s)+1)-1}}include(e){let{from:t,to:n}=this.window(),{bars:r,values:i}=this.entry,a=this.placed;for(let o=t;o<=n;o+=1)r?(y(e,a(r.low(o))),y(e,a(r.high(o)))):i&&y(e,a(i.value(o)));let o=yn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style);this.entry.definition.extraExtents?.(o).forEach(t=>{y(e,a(t))})}firstValue(){let{bars:e,values:t}=this.entry,{to:n}=this.window(),r=this.sources.bars.time(this.range.from);for(let i=(e??t)?.lowerBound(r)??0;i<=n;i+=1){let n=e?e.close(i):t?.value(i)??NaN;if(Number.isFinite(n))return n}return null}rebase(e,t){let n=this.firstValue();n!==null&&n!==t&&(this.placed=e===`percent`?n===0?()=>NaN:e=>t+(e-n)/Math.abs(n)*Math.abs(t):n>0?e=>e/n*t:()=>NaN)}latest(){let{bars:e,values:t,lastValueLabel:n}=this.entry,r=((e??t)?.length??0)-1,i=e?e.close(r):t?.value(r)??NaN;if(!n||!Number.isFinite(i))return null;let{theme:a}=this.sources.options,o=yn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style),s=!e||i>=e.open(r);return{value:this.placed(i),color:o.color??(s?o.upColor??a.up:o.downColor??a.down)}}emit(e,t){let{from:n,to:r}=this.window(),{bars:i,values:a}=this.entry,{bars:o,timeScale:s}=this.sources,c=this.pool.take(`series:${this.entry.id}`),l=this.placed,u=t=>e.valueToY(l(t));c.reset(Math.max(0,r-n+1));for(let e=n;e<=r;e+=1)if(i){let t=s.indexToX(o.logicalIndexOf(i.time(e))),n=i.open(e),r=i.close(e);c.pushOhlc(t,u(n),u(i.high(e)),u(i.low(e)),u(r),i.volume(e),r>=n)}else if(a){let t=s.indexToX(o.logicalIndexOf(a.time(e))),n=a.value(e),r=e>0?a.value(e-1):n;c.pushValue(t,u(n),!(n<r))}t.push({kind:`series`,definition:this.entry.definition,style:yn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style),points:c,valueToY:u,bars:i,first:n,transform:null})}};function Sn(e,t){return e[t%e.length]}var Cn=class{buffers=/* @__PURE__ */ new Map;used=/* @__PURE__ */ new Set;take(e){this.used.add(e);let t=this.buffers.get(e);return t||(t=new _n,this.buffers.set(e,t)),t}sweep(){for(let e of this.buffers.keys())this.used.has(e)||this.buffers.delete(e);this.used=/* @__PURE__ */ new Set}};function wn(e){let t=e.options.mainSeries.barColor;if(!t)return null;let{bars:r,values:a}=e;return e=>{let o=r.bar(e)??n(`There is no bar ${e}.`),s=t({index:e,bar:o,indicator:(t,n)=>{let r={kind:`indicator`,id:t,...n===void 0?{}:{key:n}};return a.check(r,`mainSeries.barColor`),a.read(r,e)}});return s!==null&&typeof s!=`string`&&n(`mainSeries.barColor must return a color string or null, received ${i(s)}.`),s}}var Tn=class{sources;range;format;pool;pane=b;scale=fe;constructor(e,t,n,r){this.sources=e,this.range=t,this.format=n,this.pool=r}get definition(){return this.sources.seriesTypes.require(this.sources.options.mainSeries.type)}include(e){let{bars:t,options:n}=this.sources,r=this.definition.input===`ohlc`;for(let i=this.range.from;i<=this.range.to;i+=1)r?(y(e,t.low(i)),y(e,t.high(i))):y(e,t.price(i,n.mainSeries.source))}firstValue(){let{bars:e,options:t}=this.sources;return e.price(this.range.from,this.definition.input===`ohlc`?`close`:t.mainSeries.source)}emit(e,t){let{bars:n,timeScale:r,options:i}=this.sources,a=this.definition,o=this.pool.take(`main`),s=Math.max(0,this.range.from-1),c=Math.min(n.length-1,this.range.to+1);o.reset(c-s+1);let l=wn(this.sources);for(let t=s;t<=c;t+=1){let s=r.indexToX(t);if(a.input===`ohlc`){let r=n.open(t),i=n.close(t);o.pushOhlc(s,e.valueToY(r),e.valueToY(n.high(t)),e.valueToY(n.low(t)),e.valueToY(i),n.volume(t),i>=r,l?.(t)??null)}else{let r=n.price(t,i.mainSeries.source),a=t>0?n.price(t-1,i.mainSeries.source):r;o.pushValue(s,e.valueToY(r),r>=a)}}t.push({kind:`series`,definition:a,style:yn(i.mainSeries,a,this.sources,Sn(i.theme.palette,0),i.mainSeries.styles[i.mainSeries.type]??void 0),points:o,valueToY:t=>e.valueToY(t),bars:a.input===`ohlc`?n:null,first:s,transform:this.sources.transform})}};function En(e,t,n,r){let{options:i}=e,a=i.theme.palette,o=[new Tn(e,t,n,r)];return e.series.list().forEach((i,s)=>{if(i.visible){let c=Sn(a,s+1);o.push(new xn(e,i,t,bn(i,n),c,r))}}),e.contributors.forEach(i=>{o.push(...i(e,t,n,r))}),o}function D(e,t,n){return Number.isFinite(t)?n.kind===`compact`?e.compact(t):e.number(t,n.precision):`—`}function Dn(e,t){return e?e.kind===`decimal`&&t.kind===`decimal`?e.precision>=t.precision?e:t:e.kind===`decimal`?e:t:t}function On(e,t,n){return Math.min(Math.max(e,t),n)}function kn(e){if(!(e>0)||!Number.isFinite(e))return 1;let t=Math.floor(Math.log10(e)),n=e=>t<0?e/10**-t:e*10**t,r=t<0?e*10**-t:e/10**t;return n(r<=1?1:r<=2?2:r<=2.5?2.5:r<=5?5:10)}function An(e,t,n){if(!(n>0)||!Number.isFinite(e)||!Number.isFinite(t)||t<e)return[];let r=[],i=Math.ceil(e/n),a=Math.floor(t/n),o=Math.max(0,-Math.floor(Math.log10(n))+1);for(let e=i;e<=a;e+=1)r.push(Number((e*n).toFixed(o)));return r}let jn=[1,2,5];function Mn(e,t){let n=e.scaleRange();if(!n)return[];let r=[];for(let e=Math.floor(n.min);e<=Math.ceil(n.max);e+=1)for(let t of jn){let i=t*10**e,a=Math.log10(i);a>=n.min&&a<=n.max&&r.push(i)}let i=[],a=NaN;for(let n of r){let r=e.valueToY(n);(Number.isNaN(a)||Math.abs(r-a)>=t)&&(i.push(n),a=r)}return i}function Nn(e,t){let n=e.scaleRange(),r=e.plotHeight;if(!n||r<=0)return[];let i=n.max-n.min,a;if(e.mode===`log`&&i>=1)a=Mn(e,t);else if(e.mode===`log`){let i=e.fromScale(n.min),o=e.fromScale(n.max);a=An(i,o,kn((o-i)*t/r))}else{let o=kn(i*t/r);a=An(n.min,n.max,o).map(t=>e.fromScale(t))}return a.map(t=>({value:t,y:e.valueToY(t)})).filter(e=>e.y>=0&&e.y<=r)}function Pn(e,t){return!e||t.year!==e.year?90:t.month===e.month?t.day===e.day?t.hour===e.hour?t.minute===e.minute?t.second===e.second?1:30:t.minute%30==0?52:t.minute%15==0?51:t.minute%5==0?50:40:t.hour%6==0?62:60:70:80}function Fn(e){return e>=90?`year`:e>=80?`month`:e>=70?`day`:e>=60?`hour`:e>=40?`minute`:`second`}var In=class{store;clock;weights=/* @__PURE__ */ new Uint8Array;revision=-1;constructor(e,t){this.store=e,this.clock=t}weight(e){this.sync();let t=this.weights[e]??0;if(t!==0)return t;let n=this.clock.fields(this.store.time(e)),r=Pn(e>0?this.clock.fields(this.store.time(e-1)):null,n);return this.weights[e]=r,r}sync(){let e=this.store.changesSince(this.revision);if(e){if(e.kind===`reset`||this.weights.length<this.store.length){let t=new Uint8Array(Math.max(16,this.store.length*2));e.kind===`tail`&&t.set(this.weights.subarray(0,e.from)),this.weights=t}else this.weights.fill(0,e.from);this.revision=this.store.revision}}};function Ln(e,t,n,r){let i=e.visibleBars();if(!i)return[];let a=/* @__PURE__ */ new Map;for(let e=i.from;e<=i.to;e+=1){let t=n.weight(e),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[],s=[],c=[...a.keys()].filter(e=>e>1).sort((e,t)=>t-e);for(let t of c)for(let n of a.get(t)??[]){let i=e.indexToX(n),a=0,c=o.length;for(;a<c;){let e=a+c>>>1;(o[e]??0)<i?a=e+1:c=e}let l=o[a-1],u=o[a];(l===void 0||i-l>=r)&&(u===void 0||u-i>=r)&&(o.splice(a,0,i),s.push({index:n,weight:t}))}return s.sort((e,t)=>e.index-t.index).map(({index:n,weight:r})=>({index:n,x:e.indexToX(n),time:t.time(n),unit:Fn(r)}))}function Rn(e,t,n){let{scale:r}=t,i=r.displayValue(n),a=r.mode,o=e.options.priceScale.formatter,s=t.format.kind===`decimal`?t.format.precision:0;return o?o(i,{paneId:t.id,mode:a,precision:s,locale:e.formatter.locale}):a===`percent`?`${D(e.formatter,i,{kind:`decimal`,precision:2})}%`:a===`indexed`?D(e.formatter,i,{kind:`decimal`,precision:2}):D(e.formatter,i,t.format)}function zn(e,t){let n=t.reduce((t,n)=>Math.max(t,e.measureText(n)),0);return Math.min(160,Math.max(e.options.priceScale.minWidth,Math.ceil(n+20)))}function Bn(e,t,n){if(!e.options.priceScale.visible)return{right:0,left:0};let r=e=>t.flatMap(t=>t.marks.flatMap(t=>t.side===e?[t.text]:[])),i=[...t.flatMap(e=>e.ticks.map(e=>e.text)),...r(`right`)],a=t.flatMap(e=>e.left?[e.left]:[]),o=n?[n.text,...n.countdown===null?[]:[n.countdown],...n.live?[n.live.text]:[]]:[];return{right:zn(e,[...i,...o]),left:a.length>0?zn(e,[...a.flatMap(e=>e.ticks.map(e=>e.text)),...r(`left`)]):0}}function Vn(e,t,n,r){let{options:i,panes:a}=e;return l({width:t,height:n,axisWidth:i.priceScale.visible?r.right:0,leftAxisWidth:i.priceScale.visible?r.left:0,timeAxisHeight:i.timeScale.visible?i.timeScale.height:0,separatorHeight:i.panes.separatorHeight,minPaneHeight:i.panes.minHeight,panes:a.list().map(e=>({id:e.id,height:e.height,stretch:e.id===b}))})}function Hn(e,t){return e<=t&&e>t-12}function Un(e,t,n,r){let i={kind:`decimal`,precision:e.pricePrecision},a=n,o=Jn(e,t,a,i,r);for(let n=0;n<2;n+=1){let n=Bn(e,o.panes,o.latest);if(Hn(n.right,a.right)&&Hn(n.left,a.left))break;a={right:Hn(n.right,a.right)?a.right:n.right,left:Hn(n.left,a.left)&&n.left>0?a.left:n.left},o=Jn(e,t,a,i,r)}return e.timeScale.settle(),r.sweep(),o}function Wn(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.scale);e?e.push(n):t.set(n.scale,[n])}return t}function Gn(e,t){let n=t[0]?.firstValue()??null,r=e.relativeMode(n);r&&n!==null&&t.forEach(e=>{e.rebase?.(r,n)}),e.fit(Kn(t),n)}function Kn(e){let t=ae();return e.forEach(e=>{e.include(t,!1)}),t.min>t.max&&e.forEach(e=>{e.include(t,!0)}),t}function qn(e,t){return e.reduce((e,t)=>Dn(e,t.format),null)??t}function Jn(e,t,r,i,a){let{options:o,timeScale:s,bars:c,formatter:l}=e,u=Vn(e,t.width,t.height,r);s.setWidth(u.plotWidth);let d=s.visibleBars(),f=d?En(e,d,i,a):[],p=[],m=o.font.size*2.6;for(let t of u.panes){let n=e.panes.require(t.id),r=f.filter(e=>e.pane===n.id),a=Wn(r),o=/* @__PURE__ */ new Map;for(let[r,i]of a){let a=e.panes.ensureScale(n.id,r).scale;a.setHeight(t.plot.height),Gn(a,i),o.set(r,a)}let s=a.get(`right`)??a.get(`left`)??[],c=o.get(pe);a.has(`right`)||(n.scale.setHeight(t.plot.height),c?n.scale.follow(c):n.scale.fit(ae(),null));let l=[],u=[];r.forEach(t=>{let r=o.get(t.scale)??n.scale;t.emit(r,l);let i=t.scale===`right`?`right`:t.scale===`left`?`left`:null,a=i?t.latest?.():null;if(i&&a){let o={id:n.id,scale:r,format:t.format};u.push({side:i,y:r.valueToY(a.value),text:Rn(e,o,a.value),color:a.color})}});let d=(t,r)=>{let i={id:n.id,scale:t,format:r};return Nn(t,m).map(t=>({y:t.y,text:Rn(e,i,t.value)}))},h=qn(s,i),g=a.get(pe),_=g?qn(g,i):i;p.push({id:n.id,entry:n,plot:t.plot,axis:t.axis,scale:n.scale,format:h,ticks:d(n.scale,h),left:c?{axis:t.leftAxis??{...t.plot,x:0,width:0},scale:c,format:_,ticks:d(c,_)}:null,marks:u,jobs:l})}let h=p[0]??n(`The layout has no main pane.`);return{layout:u,visible:d,timeTicks:o.timeScale.visible?Ln(s,c,e.marks,e.measureText(`00:00`)+24).map(t=>{let n=o.timeScale.formatter?o.timeScale.formatter(t.time,{kind:`axis`,unit:t.unit,locale:l.locale,timeZone:l.timeZone}):l.timeTick(t.time,t.unit);return{x:t.x,unit:t.unit,text:n,width:e.measureText(n)}}).filter(e=>e.x-e.width/2>=0&&e.x+e.width/2<=u.plotWidth):[],panes:p,main:h,priceFormat:i,latest:Yn(e,h)}}function Yn(e,t){let{bars:n,options:r}=e;if(n.length===0)return null;let i=n.length-1,a=e.seriesTypes.require(r.mainSeries.type).input===`ohlc`?n.close(i):n.price(i,r.mainSeries.source),o=t.scale.valueToY(a),s=n.close(i)>=n.open(i),c=r.mainSeries.styles[r.mainSeries.type],l=c&&`upColor`in c?c:void 0,{theme:u}=r,d=e=>r.latestPrice.color??(e?l?.upColor??u.up:l?.downColor??u.down),f=e.live;return{value:a,y:o,up:s,color:d(s),text:Rn(e,t,a),countdown:e.countdown,live:f===null||f===a?null:{value:f,y:t.scale.valueToY(f),color:Be(d(f>=a),u.background,.4),text:Rn(e,t,f)}}}let Xn={price:[],time:null};function Zn(e,t,n){return Math.min(Math.max(t,n/2),Math.max(n/2,e.layout.plotWidth-n/2))}function Qn(e,t,n,r){if(!n||!t.crosshair.labels)return Xn;let i=[],{y:a}=n;if(a!==null&&t.priceScale.visible){let r=(t.font.size+8)/2;for(let t of e.panes){let e=a-r-t.axis.y,o=a+r-t.axis.y;o>0&&e<t.axis.height&&(n.priceText!==null&&i.push({axis:t.axis,top:e,bottom:o}),n.leftPriceText!==null&&t.left&&i.push({axis:t.left.axis,top:e,bottom:o}))}}let o=null;if(n.timeText!==null&&e.layout.timeAxis){let t=r(n.timeText)+12,i=Zn(e,n.x,t);o={left:i-t/2,right:i+t/2}}return{price:i,time:o}}function $n(e,t,n,r){return e.some(e=>e.axis===t&&n+r>e.top&&n-r<e.bottom)}function er(e,t){let n=e.time;return n!==null&&t.x+t.width/2>n.left&&t.x-t.width/2<n.right}function tr(e,t,n){let r=t.font.size/2,i=[];return e.panes.forEach((e,t)=>{e.ticks.forEach((a,o)=>{$n(n.price,e.axis,a.y,r)&&i.push(`${t}:${o}`)}),e.left?.ticks.forEach((a,o)=>{$n(n.price,e.left?.axis??e.axis,a.y,r)&&i.push(`${t}<${o}`)})}),e.timeTicks.forEach((e,t)=>{er(n,e)&&i.push(`t${t}`)}),i.join(`,`)}function nr(e,t,n,r,i,a){let o=-r.leftAxisWidth,s={x:Math.min(Math.max(n.x,o+56),o+r.width-56),y:n.y-48-56>=56?n.y-48-56:n.y+48+56},c=r.width*i,l=r.height*i,u=(n.x-o-28)*i,d=(n.y-28)*i,f=56*i,p=Math.max(0,u),m=Math.max(0,d),h=Math.min(c,u+f)-p,g=Math.min(l,d+f)-m,_=112/f;if(e.save(),e.beginPath(),e.arc(s.x,s.y,56,0,Math.PI*2),e.clip(),e.fillStyle=a.background,e.fillRect(s.x-56,s.y-56,112,112),h>0&&g>0){let n=s.x-56+(p-u)*_,r=s.y-56+(m-d)*_;for(let i of t)e.drawImage(i,p,m,h,g,n,r,h*_,g*_)}e.beginPath(),e.moveTo(s.x-7,s.y),e.lineTo(s.x+7,s.y),e.moveTo(s.x,s.y-7),e.lineTo(s.x,s.y+7),C(e,a.crosshair,1.5),e.stroke(),e.restore(),e.beginPath(),e.arc(s.x,s.y,56,0,Math.PI*2),C(e,a.border,2),e.stroke()}function rr(e,t){return(e.font.size+8-6)*t+6}function ir(e,t,n){let r=[...e],i=e.map((e,t)=>t).sort((t,n)=>(e[t]??0)-(e[n]??0)),a=n?(n.top+n.bottom)/2:-1/0,o=n?.top??1/0;for(let n of i.filter(t=>(e[t]??0)<=a).reverse())r[n]=Math.min(e[n]??0,o-t/2),o=(r[n]??0)-t/2;o=n?.bottom??-1/0;for(let n of i.filter(t=>(e[t]??0)>a))r[n]=Math.max(e[n]??0,o+t/2),o=(r[n]??0)+t/2;return r}function ar(e,t,n){if(!t.priceScale.visible)return[];let r=t.latestPrice.label?e.latest:null,i=n?2:1,a=rr(t,1),o=r?.live??null,s=[];for(let n of e.panes)for(let c of[`right`,`left`]){let l=c===`right`?n.axis:n.left?.axis,u=n===e.main&&c===`right`,d=[...n.marks.filter(e=>e.side===c),...u&&o&&Number.isFinite(o.y)?[o]:[]],f=r?r.y-a/2:0,p=r&&u&&Number.isFinite(r.y)?{top:f,bottom:f+rr(t,i)}:null,m=ir(d.map(e=>e.y),a,p);l&&d.forEach((e,t)=>{s.push({axis:l,y:m[t]??e.y,lines:1,mark:e})})}return r&&s.push({axis:e.main.axis,y:r.y,lines:i,mark:null}),s}let or=[`arrow-up`,`arrow-down`,`triangle-up`,`triangle-down`,`circle`,`square`];function sr(e){return e===`arrow-up`||e===`triangle-up`?1:e===`arrow-down`||e===`triangle-down`?-1:0}function cr(e,t,n,r,i){switch(t){case`circle`:e.arc(n,r,i,0,Math.PI*2);return;case`square`:e.rect(n-i,r-i,i*2,i*2);return;case`triangle-up`:e.moveTo(n,r-i),e.lineTo(n+i,r+i),e.lineTo(n-i,r+i),e.closePath();return;case`triangle-down`:e.moveTo(n,r+i),e.lineTo(n+i,r-i),e.lineTo(n-i,r-i),e.closePath();return;case`arrow-up`:e.moveTo(n,r-i),e.lineTo(n+i,r),e.lineTo(n+i*.4,r),e.lineTo(n+i*.4,r+i),e.lineTo(n-i*.4,r+i),e.lineTo(n-i*.4,r),e.lineTo(n-i,r),e.closePath();return;case`arrow-down`:e.moveTo(n,r+i),e.lineTo(n+i,r),e.lineTo(n+i*.4,r),e.lineTo(n+i*.4,r-i),e.lineTo(n-i*.4,r-i),e.lineTo(n-i*.4,r),e.lineTo(n-i,r),e.closePath();return}}function lr(e,t,n,r,i){switch(t.kind){case`series`:hn(e,()=>{t.definition.paint({ctx:e,pixelRatio:r,width:n.plot.width,height:n.plot.height,barSpacing:i,style:t.style,points:t.points,valueToY:t.valueToY,bars:t.bars,first:t.first,transform:t.transform})});return;case`fill`:{let n=t.steps?fr:dr;t.above===t.below?n(e,t.from,t.to,null,t.above,i):(n(e,t.from,t.to,!0,t.above,i),n(e,t.from,t.to,!1,t.below,i));return}case`segments`:pr(e,t,r,i);return;case`boxes`:e.beginPath();for(let n of t.boxes)e.rect(w(n.x,1,r),w(n.y,1,r),Math.round(n.width*r)/r,Math.round(n.height*r)/r);e.fillStyle=S(t.color,.1),e.fill(),C(e,S(t.color,.6),1,`solid`),e.stroke();return;case`reference`:{let i=w(t.y,1,r);e.beginPath(),e.moveTo(0,i),e.lineTo(n.plot.width,i),C(e,t.color,1,`dashed`),e.stroke();return}case`columns`:mr(e,t,r,i);return;case`markers`:hr(e,t);return;case`labels`:ur(e,t,n.plot.width);return}}function ur(e,t,n){e.font=t.font,e.textAlign=`center`;for(let{x:r,y:i,text:a,above:o,color:s}of t.labels){if(r<0||r>n)continue;let c=a.split(`
|
|
2
|
-
`),l=Math.max(...c.map(t=>e.measureText(t).width))/2,u=Math.min(Math.max(r,l),n-l);e.fillStyle=s,e.textBaseline=o?`bottom`:`top`,c.forEach((n,r)=>{let a=o?-4-(c.length-1-r)*t.lineHeight:4+r*t.lineHeight;e.fillText(n,u,i+a)})}}function dr(e,t,n,r,i){let a=e=>t.value(e)<=n.value(e),o=-1,s=NaN,c=NaN,l=(i,l,u)=>{if(r===null||a(i)===r){Number.isNaN(s)?e.moveTo(t.x(o),t.value(o)):e.moveTo(s,c);for(let n=o;n<=i;n+=1)e.lineTo(t.x(n),t.value(n));Number.isNaN(l)||e.lineTo(l,u);for(let t=i;t>=o;--t)e.lineTo(n.x(t),n.value(t));e.closePath()}};e.beginPath();for(let e=0;e<t.count;e+=1)if(Number.isNaN(t.value(e))||Number.isNaN(n.value(e)))o>=0&&l(e-1,NaN,NaN),o=-1;else if(o<0)o=e,s=NaN,c=NaN;else if(a(e)!==a(e-1)){let r=t.value(e-1)-n.value(e-1),i=r/(r-(t.value(e)-n.value(e))),a=t.x(e-1)+i*(t.x(e)-t.x(e-1)),u=t.value(e-1)+i*(t.value(e)-t.value(e-1));l(e-1,a,u),o=e,s=a,c=u}o>=0&&l(t.count-1,NaN,NaN),e.fillStyle=i,e.fill()}function fr(e,t,n,r,i,a){e.beginPath();for(let i=0;i<t.count;i+=1){let o=t.value(i),s=n.value(i);Number.isNaN(o)||Number.isNaN(s)||r!==null&&o<=s!==r||e.rect(t.x(i)-a/2,Math.min(o,s),a,Math.abs(s-o))}e.fillStyle=i,e.fill()}function pr(e,t,n,r){let{points:i}=t;e.beginPath();for(let a=0;a<i.count;a+=1){let o=i.value(a);if(Number.isNaN(o)||o===i.value(a-1))continue;let s=a;for(;s+1<i.count&&i.value(s+1)===o;)s+=1;let c=w(o,t.lineWidth,n);e.moveTo(i.x(a)-r/2,c),e.lineTo(i.x(s)+r/2,c)}C(e,t.color,t.lineWidth,t.lineStyle),e.stroke()}function mr(e,t,n,r){let{points:i,from:a}=t,o=Math.max(1/n,Math.round(r*t.width*n)/n),s=1/n;e.fillStyle=t.color,e.beginPath();for(let r=0;r<i.count;r+=1){let c=i.value(r),l=a.value(r);if(Number.isNaN(c)||Number.isNaN(l))continue;let u=Math.round((i.x(r)-o/2)*n)/n,d=Math.min(l,c),f=Math.max(s,Math.abs(c-l));t.hollow?e.rect(u+s/2,d+s/2,o-s,f-s):e.fillRect(u,d,o,f)}t.hollow&&(C(e,t.color,s,`solid`),e.stroke())}function hr(e,t){let{points:n,shape:r,text:i,size:a}=t,o=r?sr(r):0,s=o*a;if(e.fillStyle=t.color,r){e.beginPath();for(let t=0;t<n.count;t+=1){let i=n.value(t);if(!Number.isNaN(i)){let o=n.x(t);e.moveTo(o+a,i+s),cr(e,r,o,i+s,a)}}e.fill()}if(i.length===0)return;e.font=t.font,e.textAlign=`center`,e.textBaseline=r?o>0?`top`:`bottom`:`middle`;let c=r?o>0?s+a+2:s-a-2:0;for(let t=0;t<n.count;t+=1){let r=n.value(t),a=typeof i==`string`?i:i[t]??``;!Number.isNaN(r)&&a!==``&&e.fillText(a,n.x(t),r+c)}}function gr(e,t,n,r){let{grid:i,theme:a}=n;if(i.vertical||i.horizontal){e.beginPath();for(let n of t.panes){let{plot:a}=n;if(i.vertical)for(let n of t.timeTicks){let t=w(n.x,1,r);e.moveTo(t,a.y),e.lineTo(t,a.y+a.height)}if(i.horizontal)for(let t of n.ticks){let n=w(a.y+t.y,1,r);e.moveTo(a.x,n),e.lineTo(a.x+a.width,n)}}C(e,a.grid,1,i.style),e.stroke()}}function _r(e,t,n,r,i){if(!n.priceScale.visible)return;let{theme:a}=n;e.font=E(n.font.size,n.font.family),e.fillStyle=a.textMuted,e.textBaseline=`middle`;let o=n.font.size/2,s=[...ar(t,n,(t.latest?.countdown??null)!==null).map(e=>{let t=e.y-(n.font.size+8)/2;return{axis:e.axis,top:t,bottom:t+rr(n,e.lines)}}),...i.price],c=(t,n,r)=>{for(let i of n)i.y>=o&&i.y<=t.height-o&&!$n(s,t,i.y,o)&&e.fillText(i.text,r,t.y+i.y)};for(let n of t.panes)e.textAlign=`left`,c(n.axis,n.ticks,n.axis.x+8),n.left&&(e.textAlign=`right`,c(n.left.axis,n.left.ticks,-8));let l=t.layout.leftAxisWidth>0?[t.layout.plotWidth,0]:[t.layout.plotWidth];e.beginPath();for(let n of l){let i=w(n,1,r);e.moveTo(i,0),e.lineTo(i,t.layout.height)}C(e,a.border,1),e.stroke()}function vr(e,t,n,r,i){let a=t.layout.timeAxis;if(!a)return;let{theme:o}=n,s=w(a.y,1,r);e.beginPath(),e.moveTo(a.x,s),e.lineTo(a.x+a.width,s),C(e,o.border,1),e.stroke(),e.save(),e.beginPath(),e.rect(0,a.y,t.layout.plotWidth,a.height),e.clip(),e.font=E(n.font.size,n.font.family),e.textAlign=`center`,e.textBaseline=`middle`;for(let n of t.timeTicks)er(i,n)||(e.fillStyle=n.unit===`year`||n.unit===`month`||n.unit===`day`?o.text:o.textMuted,e.fillText(n.text,n.x,a.y+a.height/2));e.restore()}function yr(e,t,n,r,i){let{separatorWidth:a,separatorColor:o,separatorHoverColor:s}=n.panes;if(a<=0)return;let c=-t.layout.leftAxisWidth;for(let l of t.layout.separators){let u=w(l.y+l.height/2,a,r);e.beginPath(),e.moveTo(c,u),e.lineTo(c+t.layout.width,u),C(e,l.above===i?s??n.theme.crosshair:o??n.theme.border,a),e.stroke()}}function br(e,t,n,r){let i=t.latest;if(!i||!n.latestPrice.line||!Number.isFinite(i.y))return;let{plot:a}=t.main;if(i.y<0||i.y>a.height)return;let o=w(a.y+i.y,1,r);e.beginPath(),e.moveTo(a.x,o),e.lineTo(a.x+a.width,o),C(e,i.color,1,n.latestPrice.style),e.stroke()}function xr(e,t,n,r,i,a,o,s){e.fillStyle=n.theme.background,e.fillRect(-t.layout.leftAxisWidth,0,t.layout.width,t.layout.height),gr(e,t,n,r);for(let n of t.panes){let{plot:t}=n;hn(e,()=>{e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),e.translate(t.x,t.y),a(e,n,`below`);for(let t of n.jobs)lr(e,t,n,r,i);a(e,n,`above`)})}br(e,t,n,r),yr(e,t,n,r,o),_r(e,t,n,r,s),vr(e,t,n,r,s)}function Sr(e,t,n,r,i,a){let{timeAxis:o}=t.layout,s=t.panes.flatMap(e=>e.left?[e.axis,e.left.axis]:[e.axis]);hn(e,()=>{e.beginPath();for(let t of o?[...s,o]:s)e.rect(t.x,t.y,t.width,t.height);e.clip(),e.fillStyle=n.theme.background,e.fillRect(-t.layout.leftAxisWidth,0,t.layout.width,t.layout.height),yr(e,t,n,r,i),_r(e,t,n,r,a),vr(e,t,n,r,a)})}var Cr=class{view;run;handle=0;pending=/* @__PURE__ */ new Set;tasks=[];running=!1;constructor(e,t){this.view=e,this.run=t}request(...e){e.forEach(e=>this.pending.add(e)),this.pending.size>0&&this.schedule()}beforePaint(e){this.tasks.push(e),this.schedule()}flush(){this.handle!==0&&(this.view.cancelAnimationFrame(this.handle),this.handle=0);let e=this.tasks;this.tasks=[],this.running=!0;try{r(e)}finally{this.running=!1,this.tasks.length>0&&this.schedule(),this.paint()}}schedule(){this.handle===0&&!this.running&&(this.handle=this.view.requestAnimationFrame(()=>{this.handle=0,this.flush()}))}paint(){if(this.pending.size===0)return;let e=this.pending;this.pending=/* @__PURE__ */ new Set,this.run(e)}destroy(){this.handle!==0&&(this.view.cancelAnimationFrame(this.handle),this.handle=0),this.pending.clear(),this.tasks=[]}};let wr=[`scene`,`objects`,`cursor`];var Tr=class{view;container;maxPixelRatio;onChange;root;layers;cssWidth=0;cssHeight=0;ratio=1;resizeObserver=null;pixelRatioQuery=null;constructor(e,t,r,i){this.view=e,this.container=t,this.maxPixelRatio=r,this.onChange=i;let a=t.ownerDocument;this.root=a.createElement(`div`),this.root.tabIndex=0,this.root.setAttribute(`role`,`img`),this.root.setAttribute(`aria-label`,`Trading chart`),Object.assign(this.root.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,outline:`none`,touchAction:`none`,userSelect:`none`,webkitUserSelect:`none`,webkitTapHighlightColor:`transparent`});let o=wr.map(e=>{let t=a.createElement(`canvas`);t.dataset.layer=e,Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,pointerEvents:`none`});let r=t.getContext(`2d`)??n(`The browser does not provide a 2D canvas context.`);return this.root.appendChild(t),[e,{canvas:t,ctx:r}]});this.layers=Object.fromEntries(o),t.appendChild(this.root)}get width(){return this.cssWidth}get height(){return this.cssHeight}get pixelRatio(){return this.ratio}context(e){return this.layers[e].ctx}canvas(e){return this.layers[e].canvas}setMaxPixelRatio(e){return this.maxPixelRatio=e,this.resize(this.cssWidth,this.cssHeight)}measureContainer(){return{width:this.container.clientWidth,height:this.container.clientHeight}}setAutoSize(e){if(this.resizeObserver?.disconnect(),this.resizeObserver=null,e){let e=new ResizeObserver(e=>{let t=e.at(-1)?.contentRect;t&&this.resize(t.width,t.height)&&this.onChange()});e.observe(this.container),this.resizeObserver=e}}watchPixelRatio(){this.pixelRatioQuery?.removeEventListener(`change`,this.handlePixelRatioChange),this.pixelRatioQuery=this.view.matchMedia(`(resolution: ${this.view.devicePixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.handlePixelRatioChange)}handlePixelRatioChange=()=>{this.watchPixelRatio(),this.resize(this.cssWidth,this.cssHeight)&&this.onChange()};resize(e,t){let n=Math.min(this.maxPixelRatio,Math.max(1,this.view.devicePixelRatio)),r=Math.round(Math.max(0,e)*n),i=Math.round(Math.max(0,t)*n),a=r/n,o=i/n;if(a===this.cssWidth&&o===this.cssHeight&&n===this.ratio)return!1;this.cssWidth=a,this.cssHeight=o,this.ratio=n;for(let e of wr){let{canvas:t}=this.layers[e];t.width=r,t.height=i,t.style.width=`${a}px`,t.style.height=`${o}px`}return!0}begin(e,t=0){let{canvas:n,ctx:r}=this.layers[e];return r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,n.width,n.height),this.over(e,t)}over(e,t=0){let{ctx:n}=this.layers[e];return n.setTransform(this.ratio,0,0,this.ratio,this.ratio*t,0),n}composite(){let e=this.container.ownerDocument.createElement(`canvas`);e.width=this.layers.scene.canvas.width,e.height=this.layers.scene.canvas.height;let t=e.getContext(`2d`)??n(`The browser does not provide a 2D canvas context.`);for(let e of wr)t.drawImage(this.layers[e].canvas,0,0);return e}destroy(){this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.handlePixelRatioChange),this.root.remove()}},Er=class{settings;width=0;count=0;spacing;offset;following=!0;pending=null;constructor(e,t){this.settings=e,this.spacing=On(t,e.minBarSpacing,e.maxBarSpacing),this.offset=this.realTimeOffset()}get barSpacing(){return this.spacing}get plotWidth(){return this.width}configure(e){let t=this.isRealTime();this.settings=e,this.spacing=On(this.spacing,e.minBarSpacing,e.maxBarSpacing),t&&(this.offset=this.realTimeOffset()),this.constrain()}setWidth(e){this.width=Math.max(0,e),this.constrain(),this.width>0&&this.pending?.()}settle(){this.width>0&&(this.pending=null)}rightEdge(){return this.count-1+this.offset}indexToX(e){return this.width-(this.rightEdge()-e)*this.spacing}xToIndex(e){return this.rightEdge()-(this.width-e)/this.spacing}logicalRange(){let e=this.rightEdge();return{from:e-this.width/this.spacing,to:e}}visibleBars(){if(this.count===0||this.width===0)return null;let e=this.logicalRange(),t=Math.max(0,Math.floor(e.from+.5)),n=Math.min(this.count-1,Math.ceil(e.to-.5));return t<=n?{from:t,to:n}:null}isFollowing(){return this.following}isRealTime(){return Math.abs(this.offset-this.realTimeOffset())<1e-6}setBarCount(e,t){let n=this.count;this.count=e,t===`reset`||t===`replace`&&n===0?(this.offset=this.realTimeOffset(),this.following=!0):t===`tail`&&e>n&&!this.following&&n>0&&(this.offset-=e-n),this.constrain()}scrollBy(e){this.pending=null,this.offset-=e/this.spacing,this.viewChanged()}scrollToRealTime(){this.pending=null,this.offset=this.realTimeOffset(),this.constrain(),this.following=!0}placeRightEdge(e){this.pending=null,this.placeIndexAt(e,this.width)}scrollToIndex(e,t){this.sized(()=>{let n=t===`left`?this.spacing/2:t===`right`?this.width-this.spacing/2:this.width/2;this.placeIndexAt(e,n)})}zoomAnchor(e){return this.following&&this.count>0?Math.min(this.indexToX(this.count-1),this.width):e??this.width/2}zoom(e,t){this.pending=null;let n=On(this.spacing*e,this.settings.minBarSpacing,this.settings.maxBarSpacing);if(n!==this.spacing){let e=this.xToIndex(t);this.spacing=n,this.placeIndexAt(e,t)}}setBarSpacing(e){this.pending=null;let t=this.isRealTime(),n=this.width,r=this.xToIndex(n);this.spacing=On(e,this.settings.minBarSpacing,this.settings.maxBarSpacing),t?(this.offset=this.realTimeOffset(),this.constrain(),this.following=!0):this.placeIndexAt(r,n)}reset(e){this.setBarSpacing(e),this.scrollToRealTime()}setLogicalRange(e){let t=e.to-e.from;t>0&&this.sized(()=>{this.spacing=On(this.width/t,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=(e.from+e.to)/2+this.width/this.spacing/2-(this.count-1),this.viewChanged()})}fitContent(){this.sized(()=>{if(this.count===0)return;let e=Math.max(1,this.width-this.settings.rightOffset);this.spacing=On(e/this.count,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=this.realTimeOffset(),this.constrain(),this.following=!0})}state(){return{barSpacing:this.spacing,offset:this.offset}}restore(e){this.pending=null,this.spacing=On(e.barSpacing,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=e.offset,this.viewChanged()}sized(e){this.pending=null,this.width>0?e():this.pending=e}placeIndexAt(e,t){this.offset=e+(this.width-t)/this.spacing-(this.count-1),this.viewChanged()}viewChanged(){if(this.constrain(),this.width>0&&this.count>0){let e=this.visibleBars();this.following=e!==null&&e.to===this.count-1}}realTimeOffset(){return .5+this.settings.rightOffset/this.spacing}constrain(){if(this.count===0||this.width===0)return;let e=Math.min(2,this.count),t=this.width/this.spacing,n=e-.5-(this.count-1),r=Math.max(n,t+.5-e);this.offset=On(this.offset,n,r)}},Dr=class{kind;hint;definitions=/* @__PURE__ */ new Map;fixed;constructor(e,t=[],n=``){this.kind=e,this.hint=n,t.forEach(e=>{this.register(e)}),this.fixed=new Set(t.map(e=>e.type))}register(e){h(`${this.kind} definition`,e);let t=p(`${this.kind} definition type`,e.type);this.definitions.has(t)&&n(`A ${this.kind} "${t}" is already registered.`),this.definitions.set(t,e)}unregister(e){p(this.kind,e),this.fixed.has(e)&&n(`"${e}" is a ${this.kind} of every chart and cannot be unregistered.`),this.require(e),this.definitions.delete(e)}get(e){return this.definitions.get(e)}require(e){return this.definitions.get(e)??n(`Unknown ${this.kind} "${e}".${this.hint?` ${this.hint}`:``}`)}types(){return[...this.definitions.keys()]}};function Or(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Map;for(let a=0;a<e.count;a+=1){let o=e.isUp(a),s=e.color(a);if(s===null){(o?t:n).push(a);continue}let c=i.get(s);c||(c={},i.set(s,c));let l=o?c.rising:c.falling;l||(l=[],c[o?`rising`:`falling`]=l,r.push({up:o,color:s,indices:l})),l.push(a)}return[{up:!0,color:null,indices:t},{up:!1,color:null,indices:n},...r]}function kr(e,t){let{ctx:n,points:r,style:i,pixelRatio:a,barSpacing:o}=e,s=Math.max(1/a,T(o*i.bodyRatio,a)),c=s*a<3,l=1/a;n.setLineDash([]);for(let e of Or(r)){let{up:o,color:u}=e,d=u??(o?i.upColor:i.downColor),f=!(t&&o);if(i.wick||c){n.beginPath();for(let t of e.indices){let e=w(r.x(t),1,a);n.moveTo(e,r.high(t)),n.lineTo(e,r.low(t))}n.strokeStyle=c||u!==null?d:o?i.upWickColor:i.downWickColor,n.lineWidth=l,n.stroke()}if(!c){n.beginPath();for(let t of e.indices){let e=r.open(t),i=r.close(t);n.rect(T(r.x(t)-s/2,a),T(Math.min(e,i),a),s,Math.max(l,T(Math.abs(i-e),a)))}f&&(n.fillStyle=d,n.fill()),(i.border||!f)&&(n.save(),n.clip(),n.strokeStyle=f&&u===null?o?i.upBorderColor:i.downBorderColor:d,n.lineWidth=2*Math.max(l,T(1,a)),n.stroke(),n.restore())}}}function Ar(e,t){return{upColor:e,downColor:t,upWickColor:e,downWickColor:t,upBorderColor:e,downBorderColor:t,wick:!0,border:!1,bodyRatio:.72}}let jr={type:`candles`,input:`ohlc`,defaultStyle:e=>Ar(e.up,e.down),paint:e=>{kr(e,!1)}},Mr={type:`hollow-candles`,input:`ohlc`,defaultStyle:e=>Ar(e.up,e.down),paint:e=>{kr(e,!0)}},Nr={type:`ohlc`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:1,ticks:!0}),paint:({ctx:e,points:t,style:n,pixelRatio:r,barSpacing:i})=>{let a=Math.max(1,Math.min(i*.4,8)),o=n.ticks&&i>=3;e.lineWidth=n.lineWidth,e.setLineDash([]);for(let i of Or(t)){e.beginPath();for(let s of i.indices){let i=w(t.x(s),n.lineWidth,r);if(e.moveTo(i,t.high(s)),e.lineTo(i,t.low(s)),o){let o=w(t.open(s),n.lineWidth,r),c=w(t.close(s),n.lineWidth,r);e.moveTo(i-a,o),e.lineTo(i,o),e.moveTo(i,c),e.lineTo(i+a,c)}}e.strokeStyle=i.color??(i.up?n.upColor:n.downColor),e.stroke()}}},Pr={type:`high-low`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:2}),paint:({ctx:e,points:t,style:n,pixelRatio:r})=>{e.lineWidth=n.lineWidth,e.lineCap=`butt`,e.setLineDash([]);for(let i of Or(t)){e.beginPath();for(let a of i.indices){let i=w(t.x(a),n.lineWidth,r);e.moveTo(i,t.high(a)),e.lineTo(i,t.low(a))}e.strokeStyle=i.color??(i.up?n.upColor:n.downColor),e.stroke()}}};function Fr(e,t,n,r=!1){if(r){Ir(e,t,n);return}let i=!1,a=NaN,o=0,s=0,c=0,l=0,u=0,d=0,f=0,p=()=>{f>1&&(s<l?(e.lineTo(s,o),e.lineTo(l,c)):(e.lineTo(l,c),e.lineTo(s,o)),e.lineTo(u,d)),f=0};for(let r=0;r<t.count;r+=1){let m=n(r);if(Number.isNaN(m)){p(),i=!1;continue}let h=t.x(r),g=Math.floor(h);i&&g===a?(m<o&&(o=m,s=h),m>c&&(c=m,l=h),u=h,d=m,f+=1):(p(),i?e.lineTo(h,m):(e.moveTo(h,m),i=!0),a=g,o=m,s=h,c=m,l=h,u=h,d=m,f=1)}p()}function Ir(e,t,n){let r=!1,i=0;for(let a=0;a<t.count;a+=1){let o=n(a);if(Number.isNaN(o)){r=!1;continue}let s=t.x(a);r?(e.lineTo(s,i),e.lineTo(s,o)):(e.moveTo(s,o),r=!0),i=o}}function Lr(e,t,n,r){let i=-1,a=n=>{i<0||(e.lineTo(t.x(n),r),e.lineTo(t.x(i),r),e.closePath(),i=-1)};for(let r=0;r<t.count;r+=1){let o=n(r);Number.isNaN(o)?a(r-1):i<0?(i=r,e.moveTo(t.x(r),o)):e.lineTo(t.x(r),o)}a(t.count-1)}function Rr(e){return{color:e,lineWidth:2,lineStyle:`solid`}}function zr(e,t,n,r){e.beginPath(),Fr(e,t,e=>t.value(e),r),C(e,n.color,n.lineWidth,n.lineStyle),e.lineJoin=`round`,e.lineCap=`round`,e.stroke()}let Br={type:`line`,input:`value`,defaultStyle:(e,t)=>Rr(t),paint:({ctx:e,points:t,style:n})=>{zr(e,t,n,!1)}},Vr={type:`step-line`,input:`value`,defaultStyle:(e,t)=>Rr(t),paint:({ctx:e,points:t,style:n})=>{zr(e,t,n,!0)}},Hr={type:`line-markers`,input:`value`,defaultStyle:(e,t)=>({...Rr(t),markerRadius:3}),paint:({ctx:e,points:t,style:n})=>{zr(e,t,n,!1),e.beginPath();for(let r=0;r<t.count;r+=1){let i=t.value(r);Number.isNaN(i)||(e.moveTo(t.x(r)+n.markerRadius,i),e.arc(t.x(r),i,n.markerRadius,0,Math.PI*2))}e.fillStyle=n.color,e.fill()}},Ur={type:`area`,input:`value`,defaultStyle:(e,t)=>({lineColor:t,lineWidth:2,topColor:S(t,.4),bottomColor:S(t,0)}),paint:({ctx:e,points:t,style:n,height:r})=>{let i=e.createLinearGradient(0,0,0,r);i.addColorStop(0,n.topColor),i.addColorStop(1,n.bottomColor),e.beginPath(),Lr(e,t,e=>t.value(e),r),e.fillStyle=i,e.fill(),zr(e,t,{color:n.lineColor,lineWidth:n.lineWidth,lineStyle:`solid`},!1)}},Wr={type:`baseline`,input:`value`,defaultStyle:e=>({baseValue:null,lineWidth:2,topLineColor:e.up,topFillColor:S(e.up,.22),bottomLineColor:e.down,bottomFillColor:S(e.down,.22)}),paint:({ctx:e,points:t,style:n,width:r,height:i,valueToY:a})=>{let o=n.baseValue===null?NaN:a(n.baseValue);for(let e=0;Number.isNaN(o)&&e<t.count;e+=1)o=t.value(e);if(Number.isNaN(o))return;let s=[{top:0,bottom:o,line:n.topLineColor,fill:n.topFillColor},{top:o,bottom:i,line:n.bottomLineColor,fill:n.bottomFillColor}];for(let i of s)e.save(),e.beginPath(),e.rect(0,i.top,r,i.bottom-i.top),e.clip(),e.beginPath(),Lr(e,t,e=>t.value(e),o),e.fillStyle=i.fill,e.fill(),zr(e,t,{color:i.line,lineWidth:n.lineWidth,lineStyle:`solid`},!1),e.restore()}},Gr=`#00bcd4`,Kr=`#e91e63`,qr={type:`hlc-area`,input:`ohlc`,defaultStyle:(e,t)=>({highColor:Gr,lowColor:Kr,closeColor:t,highFillColor:S(Gr,.25),lowFillColor:S(Kr,.25),lineWidth:1.5}),paint:({ctx:e,points:t,style:n})=>{let r=[{color:n.highFillColor,edge:e=>t.high(e)},{color:n.lowFillColor,edge:e=>t.low(e)}];for(let n of r){e.beginPath(),Fr(e,t,n.edge);for(let n=t.count-1;n>=0;--n)e.lineTo(t.x(n),t.close(n));e.closePath(),e.fillStyle=n.color,e.fill()}let i=[{color:n.highColor,read:e=>t.high(e)},{color:n.lowColor,read:e=>t.low(e)},{color:n.closeColor,read:e=>t.close(e)}];for(let r of i)e.beginPath(),Fr(e,t,r.read),C(e,r.color,n.lineWidth),e.stroke()}},Jr={type:`columns`,input:`value`,defaultStyle:e=>({upColor:e.volumeUp,downColor:e.volumeDown,base:0,widthRatio:.72}),extraExtents:e=>e.base===null?[]:[e.base],paint:({ctx:e,points:t,style:n,pixelRatio:r,barSpacing:i,height:a,valueToY:o})=>{let s=n.base===null?NaN:o(n.base),c=Number.isFinite(s)?s:a,l=Math.max(1/r,Math.round(i*n.widthRatio*r)/r);for(let i of[!0,!1]){e.fillStyle=i?n.upColor:n.downColor;for(let n=0;n<t.count;n+=1){let a=t.value(n);if(t.isUp(n)===i&&!Number.isNaN(a)){let i=Math.round((t.x(n)-l/2)*r)/r;e.fillRect(i,Math.min(a,c),l,Math.max(1/r,Math.abs(c-a)))}}}}};function Yr(){return new Dr(`series type`,[jr,Mr,Nr,Pr,Br,Vr,Hr,Ur,Wr,qr,Jr],`Register it with chart.series.register().`)}let Xr={kind:`idle`};var Zr=class{view;scroll;velocity=0;time=0;frame=0;constructor(e,t){this.view=e,this.scroll=t}start(e,t){let n=e[0],r=e[e.length-1];if(!n||!r||t-r.time>80)return;let i=r.time-n.time,a=i>0?(r.x-n.x)/i:0;if(Math.abs(a)<.15)return;this.velocity=a,this.time=performance.now();let o=e=>{let t=Math.max(0,e-this.time);this.time=e,this.velocity*=Math.exp(-t/325),this.frame=Math.abs(this.velocity)<.02?0:this.scroll(this.velocity*t)?this.view.requestAnimationFrame(o):0};this.frame=this.view.requestAnimationFrame(o)}stop(){this.frame!==0&&(this.view.cancelAnimationFrame(this.frame),this.frame=0)}};let Qr=1.15;function $r(e,t,n,r){let i=(e.metaKey||e.ctrlKey)&&!e.altKey,a=e.key,o=a.toLowerCase(),s=t.plotWidth();if(a===`Escape`)return n?(r(),!0):t.command(`escape`);if(n)return!1;if(i&&o===`z`)return t.command(e.shiftKey?`redo`:`undo`);if(i&&!e.shiftKey&&o===`y`)return t.command(`redo`);if(i&&(o===`c`||o===`v`))return t.command(o===`c`?`copy`:`paste`);if(e.metaKey||e.ctrlKey||e.altKey)return!1;if(a===`Delete`||a===`Backspace`)return t.command(`delete`);if(a===`Enter`)return t.command(`enter`);if(a===`ArrowLeft`||a===`ArrowRight`)t.scrollTime((e.shiftKey?s/2:s/20)*(a===`ArrowLeft`?1:-1));else if(a===`ArrowUp`||a===`+`||a===`=`)t.zoomTime(Qr,null);else if(a===`ArrowDown`||a===`-`)t.zoomTime(1/Qr,null);else if(a===`End`)t.scrollToRealTime();else return!1;return!0}function ei(e,t){let n=Math.abs(e.x-t.x);return n>=40?n:null}var ti=class{span;center;constructor(e,t){this.span=ei(e,t),this.center=(e.x+t.x)/2}move(e,t,n){let r=ei(e,t),i=(e.x+t.x)/2;n.scrollTime(i-this.center),r!==null&&this.span!==null&&n.zoomTime(r/this.span,i),this.span=r,this.center=i}};let ni={shift:!1,alt:!1,command:!1},ri=.0018,ii=.006,ai=/* @__PURE__ */ new Set([`Shift`,`Alt`,`Control`,`Meta`]);function oi(e){return{shift:e.shiftKey,alt:e.altKey,command:e.ctrlKey||e.metaKey}}function si(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function ci(e,t){let n=e.deltaMode===1?16:e.deltaMode===2?t:1;return{x:e.deltaX*n,y:e.deltaY*n}}var li=class{host;view;gesture=Xr;touches=/* @__PURE__ */ new Map;hoverPoint=null;hoverPending=!1;wheel={x:0,y:0,pinch:0,point:{x:0,y:0},pending:!1};kinetic;longPressTimer=0;modifiers=ni;lastPoint=null;root;constructor(e,t){this.host=e,this.view=t,this.root=e.root,this.kinetic=new Zr(t,t=>e.scrollTime(t)),this.root.addEventListener(`pointerdown`,this.onPointerDown),this.root.addEventListener(`pointermove`,this.onPointerMove),this.root.addEventListener(`pointerup`,this.onPointerUp),this.root.addEventListener(`pointercancel`,this.onPointerCancel),this.root.addEventListener(`lostpointercapture`,this.onPointerCancel),this.root.addEventListener(`pointerleave`,this.onPointerLeave),this.root.addEventListener(`wheel`,this.onWheel,{passive:!1}),this.root.addEventListener(`dblclick`,this.onDoubleClick),this.root.addEventListener(`contextmenu`,this.onContextMenu),this.root.addEventListener(`keydown`,this.onKeyDown),this.root.addEventListener(`keyup`,this.onKeyUp),this.view.addEventListener(`blur`,this.onWindowBlur)}destroy(){try{this.cancelGesture()}finally{this.stopListening()}}stopListening(){this.kinetic.stop(),this.root.removeEventListener(`pointerdown`,this.onPointerDown),this.root.removeEventListener(`pointermove`,this.onPointerMove),this.root.removeEventListener(`pointerup`,this.onPointerUp),this.root.removeEventListener(`pointercancel`,this.onPointerCancel),this.root.removeEventListener(`lostpointercapture`,this.onPointerCancel),this.root.removeEventListener(`pointerleave`,this.onPointerLeave),this.root.removeEventListener(`wheel`,this.onWheel),this.root.removeEventListener(`dblclick`,this.onDoubleClick),this.root.removeEventListener(`contextmenu`,this.onContextMenu),this.root.removeEventListener(`keydown`,this.onKeyDown),this.root.removeEventListener(`keyup`,this.onKeyUp),this.view.removeEventListener(`blur`,this.onWindowBlur)}cancelGesture(){let e=this.gesture;this.clearLongPress(),this.gesture=Xr,e.kind===`drag`||e.kind===`separator`?e.session.cancel():e.kind===`touch-crosshair`?this.host.setPointer(null):e.kind===`tool`&&this.host.activeTool()?.cancelPress(),this.host.magnify(null),this.host.hoverSeparator(null),this.updateCursor(null,null)}local(e){let t=this.root.getBoundingClientRect();return{x:e.clientX-t.left-this.host.originX(),y:e.clientY-t.top}}onPointerDown=e=>{if(e.pointerType===`mouse`&&e.button!==0)return;this.kinetic.stop(),this.root.focus({preventScroll:!0});let t=this.local(e);this.track(e,t);let n=e.pointerType===`touch`;if(n){if(this.touches.set(e.pointerId,t),this.touches.size===2){this.startPinch();return}if(this.touches.size>2)return}if(this.gesture.kind!==`idle`)return;e.isTrusted&&this.root.setPointerCapture(e.pointerId);let r=this.host.activeTool(),i=this.host.regionAt(t);r&&i.kind===`plot`?(this.gesture={kind:`tool`,pointerId:e.pointerId,touch:n},r.pointerDown(t,this.modifiers,n),n&&this.host.magnify(t)):this.startPress(e.pointerId,n,t,i)};startPress(e,t,n,r){if(r.kind===`separator`){this.host.setPointer(null),this.host.hoverSeparator(r.above),this.gesture={kind:`separator`,pointerId:e,startY:n.y,session:this.host.beginPaneResize(r.above,r.below)};return}if(r.kind===`time-axis`&&this.host.enabled(`axisScale`)){this.gesture={kind:`time-axis`,pointerId:e,startX:n.x,lastX:n.x};return}if(r.kind===`price-axis`&&this.host.enabled(`axisScale`)){this.gesture={kind:`price-axis`,pointerId:e,paneId:r.paneId,scale:r.scale,anchorY:n.y,lastY:n.y};return}let i=r.kind===`plot`?this.host.legendAt(n):null;if(i?.button){this.gesture={kind:`legend`,pointerId:e,hit:i};return}let a=r.kind===`plot`?this.host.hitTest(n):null;this.gesture={kind:`pressed`,pointerId:e,touch:t,start:n,region:r,target:a},t&&!a&&(this.longPressTimer=this.view.setTimeout(()=>{this.longPressTimer=0,this.gesture.kind===`pressed`&&this.gesture.pointerId===e&&(this.gesture={kind:`touch-crosshair`,pointerId:e},this.host.setPointer(n))},this.host.longPressMs()))}onPointerMove=e=>{let t=this.local(e);this.track(e,t);let n=this.gesture;if(e.pointerType===`touch`&&this.touches.has(e.pointerId)&&(this.touches.set(e.pointerId,t),n.kind===`pinch`))this.movePinch();else switch(n.kind){case`idle`:e.pointerType!==`touch`&&this.scheduleHover(t),this.host.activeTool()?.pointerMove(t,this.modifiers);return;case`tool`:e.pointerId===n.pointerId&&(this.host.activeTool()?.pointerMove(t,this.modifiers),this.host.setPointer(t),n.touch&&this.host.magnify(t));return;case`pressed`:e.pointerId===n.pointerId&&this.movePressed(n,t);return;case`pan`:e.pointerId===n.pointerId&&this.movePan(n,t,e.timeStamp);return;case`drag`:e.pointerId===n.pointerId&&(n.session.move(t,this.modifiers),n.touch?this.host.magnify(t):this.host.setPointer(t));return;case`time-axis`:e.pointerId===n.pointerId&&(this.host.zoomTime(Math.exp((t.x-n.lastX)*ii),n.startX),n.lastX=t.x);return;case`price-axis`:e.pointerId===n.pointerId&&(this.host.zoomPrice(n.paneId,n.scale,Math.exp((n.lastY-t.y)*ii),n.anchorY),n.lastY=t.y);return;case`separator`:e.pointerId===n.pointerId&&n.session.move(t.y-n.startY);return;case`touch-crosshair`:e.pointerId===n.pointerId&&this.host.setPointer(t);return;case`pinch`:case`legend`:return}};movePressed(e,t){if(si(t,e.start)<(e.touch?8:3))return;this.clearLongPress();let n=e.target;if(n?.draggable){let r=this.host.beginDrag(n,e.start,this.modifiers);if(r){this.gesture={kind:`drag`,pointerId:e.pointerId,touch:e.touch,session:r},r.move(t,this.modifiers),this.updateCursor(n,null),e.touch&&this.host.magnify(t);return}}if(e.region.kind!==`plot`||!this.host.enabled(`pan`)){this.gesture=Xr;return}let r={kind:`pan`,pointerId:e.pointerId,touch:e.touch,paneId:e.region.paneId,last:e.start,samples:[]};this.gesture=r,this.root.style.cursor=`grabbing`,this.movePan(r,t,performance.now())}movePan(e,t,n){let r=t.x-e.last.x,i=t.y-e.last.y;for(e.last=t,this.host.scrollTime(r),e.paneId!==null&&!this.host.isAutoScale(e.paneId)&&this.host.panPrice(e.paneId,i),e.samples.push({x:t.x,time:n});e.samples.length>2&&n-(e.samples[0]?.time??n)>80;)e.samples.shift();e.touch||this.host.setPointer(t)}onPointerUp=e=>{let t=this.local(e);this.track(e,t),this.touches.delete(e.pointerId);let n=this.gesture;if(n.kind===`pinch`)this.endPinch();else if(!(`pointerId`in n&&n.pointerId!==e.pointerId)){switch(this.clearLongPress(),this.gesture=Xr,n.kind){case`pressed`:this.host.click(t,n.target);break;case`tool`:this.host.activeTool()?.pointerUp(t,this.modifiers,n.touch);break;case`pan`:this.host.enabled(`kineticScroll`)&&this.kinetic.start(n.samples,e.timeStamp);break;case`drag`:n.session.end();break;case`legend`:{let e=this.host.legendAt(t);e?.button===n.hit.button&&e.item.id===n.hit.item.id&&this.host.clickLegend(e);break}case`separator`:{n.session.end();let e=this.host.regionAt(t);this.host.hoverSeparator(e.kind===`separator`?e.above:null);break}}e.pointerType===`touch`&&(this.host.setPointer(null),this.host.magnify(null)),this.updateCursor(null,e.pointerType===`touch`?null:t)}};onPointerCancel=e=>{this.touches.delete(e.pointerId),`pointerId`in this.gesture&&this.gesture.pointerId===e.pointerId?this.cancelGesture():this.gesture.kind===`pinch`&&this.endPinch()};onPointerLeave=e=>{e.pointerType!==`touch`&&this.gesture.kind===`idle`&&(this.hoverPoint=null,this.host.hover(null),this.host.hoverSeparator(null),this.host.hoverLegend(null),this.host.setPointer(null))};onWindowBlur=()=>{this.cancelGesture()};scheduleHover(e){let t=this.host.regionAt(e);this.host.setPointer(t.kind===`separator`?null:e),this.hoverPoint=e,this.hoverPending||(this.hoverPending=!0,this.host.beforePaint(()=>{this.hoverPending=!1;let e=this.hoverPoint;if(e&&this.gesture.kind===`idle`){let t=this.host.regionAt(e);this.host.hoverSeparator(t.kind===`separator`?t.above:null);let n=t.kind===`plot`&&!this.host.activeTool()?this.host.hitTest(e):null;this.host.hover(n);let r=t.kind===`plot`?this.host.legendAt(e):null;this.host.hoverLegend(r),this.updateCursor(n,e),r?.button&&(this.root.style.cursor=`pointer`)}}))}updateCursor(e,t){if(e){this.root.style.cursor=e.cursor;return}if(!t){this.root.style.cursor=``;return}let n=this.host.regionAt(t),r=this.host.enabled(`axisScale`);this.root.style.cursor=n.kind===`separator`?`row-resize`:n.kind===`price-axis`&&r?`ns-resize`:n.kind===`time-axis`&&r?`ew-resize`:n.kind===`plot`?`crosshair`:``}fingers(){let[e,t]=[...this.touches.values()];return e&&t?[e,t]:null}startPinch(){this.cancelGesture();let e=this.fingers();e&&this.host.enabled(`pinchZoom`)&&(this.gesture={kind:`pinch`,pinch:new ti(...e)})}movePinch(){let e=this.gesture,t=this.fingers();e.kind===`pinch`&&t&&e.pinch.move(...t,this.host)}endPinch(){let e=this.fingers();if(e){this.gesture={kind:`pinch`,pinch:new ti(...e)};return}let[t]=[...this.touches.entries()];this.gesture=t&&this.host.enabled(`pan`)?{kind:`pan`,pointerId:t[0],touch:!0,paneId:null,last:t[1],samples:[]}:Xr}clearLongPress(){this.longPressTimer!==0&&(this.view.clearTimeout(this.longPressTimer),this.longPressTimer=0)}onWheel=e=>{if(!this.host.enabled(`wheelZoom`))return;e.preventDefault(),this.kinetic.stop();let t=ci(e,this.root.clientHeight);e.ctrlKey?this.wheel.pinch+=t.y:(this.wheel.x+=t.x,this.wheel.y+=e.shiftKey?0:t.y,this.wheel.x+=e.shiftKey?t.y:0),this.wheel.point=this.local(e),this.wheel.pending||(this.wheel.pending=!0,this.host.beforePaint(()=>{this.wheel.pending=!1,this.applyWheel()}))};applyWheel(){let{x:e,y:t,pinch:n,point:r}=this.wheel;this.wheel.x=0,this.wheel.y=0,this.wheel.pinch=0;let i=this.host.regionAt(r);i.kind===`price-axis`?(this.host.zoomPrice(i.paneId,i.scale,Math.exp(-(t+n)*ri),r.y),this.followPointer()):(n!==0&&this.host.zoomTime(Math.exp(-n*.012),r.x),Math.abs(e)>Math.abs(t)?this.host.scrollTime(-e):t!==0&&this.host.zoomTime(Math.exp(-t*ri),r.x),this.lastPoint||this.host.setPointer(r),this.followPointer())}onDoubleClick=e=>{let t=this.local(e),n=this.host.activeTool();if(n){n.doubleClick(t);return}let r=this.host.regionAt(t),i=r.kind===`plot`?this.host.hitTest(t):null;(!i||!this.host.editObject(i))&&this.host.doubleClick(t,r)};onContextMenu=e=>{let t=this.local(e),n=this.host.regionAt(t).kind===`plot`?this.host.hitTest(t):null;this.host.contextMenu(t,n,e)&&e.preventDefault()};track(e,t){this.modifiers=oi(e),this.lastPoint=t}onKeyUp=e=>{this.refreshModifiers(e)};refreshModifiers(e){ai.has(e.key)&&this.lastPoint&&(this.modifiers=oi(e),this.followPointer())}followPointer(){let e=this.gesture;this.lastPoint&&(e.kind===`drag`?e.session.move(this.lastPoint,this.modifiers):(e.kind===`tool`||e.kind===`idle`)&&this.host.activeTool()?.pointerMove(this.lastPoint,this.modifiers))}onKeyDown=e=>{this.refreshModifiers(e),this.host.enabled(`keyboard`)&&$r(e,this.host,this.gesture.kind!==`idle`,()=>{let e=this.gesture.kind===`tool`;this.cancelGesture(),e&&this.host.command(`escape`)})&&e.preventDefault()}};function ui(e,t){return e===t||e!==null&&t!==null&&e.kind===t.kind&&e.id===t.id&&e.part===t.part}var di=class{selected=null;hoveredTarget=null;domains=[];add(e,t){this.domains=[...this.domains,{domain:e,z:t}].sort((e,t)=>e.z-t.z)}kinds(){return this.domains.map(({domain:e})=>e.kind)}get selection(){return this.selected}get hovered(){return this.hoveredTarget}setHovered(e){return!ui(e,this.hoveredTarget)&&(this.hoveredTarget=e,!0)}select(e){let t=this.selected;return t===e||t&&e&&t.kind===e.kind&&t.id===e.id?!1:(this.selected=e,!0)}exists(e){return this.domain(e.kind)?.has(e.id)??!1}prune(){let e=!1;return this.selected&&!this.domain(this.selected.kind)?.has(this.selected.id)&&(this.selected=null,e=!0),this.hoveredTarget&&!this.domain(this.hoveredTarget.kind)?.has(this.hoveredTarget.id)&&(this.hoveredTarget=null,e=!0),e}hitTest(e,t){let n=null;for(let{domain:r}of this.domains){let i=r.hitTest(e,t);i&&(!n||this.beats(i,n))&&(n=i)}return n?.target??null}beginDrag(e,t,n,r){return this.domain(t.kind)?.beginDrag(e,t,n,r)??null}edit(e){return this.domain(e.kind)?.edit?.(e.id)??!1}paint(e){for(let{domain:t}of this.domains)t.paint(e)}domain(e){return this.domains.find(t=>t.domain.kind===e)?.domain}beats(e,t){if(e.priority!==t.priority)return e.priority>t.priority;let n=this.isSelected(e.target);return n===this.isSelected(t.target)?e.distance<t.distance:n}isSelected(e){return this.selected?.kind===e.kind&&this.selected.id===e.id}},fi=class{host;timer=0;constructor(e){this.host=e}text(e){let t=this.end();return t!==null&&t>e?this.host.formatter.duration(t-e,Gt(this.host.options).days):null}sync(){let e=this.end(),t=e!==null&&e>Date.now();t&&this.timer===0?this.timer=this.host.view.setInterval(()=>{this.text(Date.now())===null?this.host.invalidate():this.host.invalidateLayers(`cursor`)},1e3):t||this.stop()}stop(){this.host.view.clearInterval(this.timer),this.timer=0}end(){let{bars:e,options:t}=this.host;if(!t.latestPrice.countdown||this.host.replaying||!this.host.timeBased||e.length===0)return null;let n=e.time(e.length-1),r=this.host.barDuration??e.interval();return this.host.barEnd(n)??(r===null?null:n+r)}};function pi(e,t){return e.panes.find(e=>t>=e.plot.y&&t<e.plot.y+e.plot.height)??null}function mi(e,t,n,r,i=!0){let{bars:a,timeScale:o,options:s}=e;if(a.length===0||n<0||n>t.layout.plotWidth)return null;let c=Math.round(o.xToIndex(n)),l=a.timeOfLogicalIndex(c),u=a.bar(c),d=pi(t,r),f=null,p=r;return d&&(f=d.scale.yToValue(r-d.plot.y),s.crosshair.mode===`magnet`&&d.id===`main`&&u&&(f=u.close,p=d.plot.y+d.scale.valueToY(f))),{x:i?o.indexToX(c):n,y:p,paneId:d?.id??null,index:c,time:Number.isNaN(l)?null:l,price:f!==null&&Number.isFinite(f)?f:null,bar:u}}function hi(e,t,n){let{bars:r,options:i,formatter:a}=e,o=r.bar(n);if(!o)return[];let{theme:s}=i,c=n>0?r.close(n-1):o.open,l=o.close-c,u=l>=0?s.up:s.down,d=e=>D(a,e,t.priceFormat),f=c===0?0:l/c*100,p=l>=0?`+`:``,m=Gt(i);return[{text:`${m.legendOpen} ${d(o.open)}`,color:u},{text:`${m.legendHigh} ${d(o.high)}`,color:u},{text:`${m.legendLow} ${d(o.low)}`,color:u},{text:`${m.legendClose} ${d(o.close)}`,color:u},{text:`${p}${d(l)} (${p}${a.number(f,2)}%)`,color:u},{text:`${m.legendVolume} ${a.compact(o.volume)}`,color:s.textMuted}]}function gi(e,t,n){let r=t.left,i=r?.scale.yToValue(n-t.plot.y)??NaN;return r&&Number.isFinite(i)?Rn(e,{id:t.id,scale:r.scale,format:r.format},i):null}function _i(e,t,n,r){let{options:i,series:a,formatter:o}=e,{theme:s}=i,c=i.legend.rows??(e=>e.visible),l=[],u=(e,t)=>{let n=r?.kind===e.kind&&r.id===e.id;l.push({item:e,segments:t,buttons:n?i.legend.buttons?.(e)??[]:[],hoveredButton:n?r.button:null})};u({kind:`main`,id:`main`,type:null,paneId:b,visible:!0},hi(e,t,n));for(let r of e.legendRows)for(let e of r(t,n))c(e.item)&&u(e.item,e.segments());let d=e.bars.time(n);return a.list().forEach((e,n)=>{let r={kind:`series`,id:e.id,type:null,paneId:e.pane,visible:e.visible};if(!c(r))return;let i=[{text:e.title,color:s.textMuted}],a=vi(e,d);a!==null&&i.push({text:D(o,a.value,bn(e,t.priceFormat)),color:a.up===null?yi(e,s,n):a.up?s.up:s.down}),u(r,i)}),l}function vi(e,t){let n=e.values??e.bars,r=n?n.lowerBound(t+1)-1:-1;if(r<0)return null;if(e.values){let t=e.values.value(r);return Number.isNaN(t)?null:{value:t,up:null}}let i=e.bars;return i?{value:i.close(r),up:i.close(r)>=i.open(r)}:null}function yi(e,t,n){let r=e.style.color;return typeof r==`string`?r:Sn(t.palette,n+1)}function bi(e,t,n,r,i,a=null){let{bars:o,options:s}=e,c=n?.bar&&n.index<o.length?n.index:o.length-1;return{crosshair:r,legends:s.legend.visible&&o.length>0?_i(e,t,c,a):[],countdown:e.countdown.text(i)}}function xi(e,t,n){if(!n)return null;let{bars:r,formatter:i,options:a}=e,o=e.timeBased?e.barDuration??r.interval():null,s=n.paneId?t.panes.find(e=>e.id===n.paneId):void 0,c=n.time===null?null:a.timeScale.formatter?a.timeScale.formatter(n.time,{kind:`crosshair`,unit:`minute`,locale:i.locale,timeZone:i.timeZone}):i.timeCrosshair(n.time,o);return{x:n.x,y:s?n.y:null,timeText:c,priceText:s&&n.price!==null?Rn(e,s,n.price):null,leftPriceText:s?.left?gi(e,s,n.y):null}}function Si(e,t){let n=e.indexAt(t);if(n>=0&&n<e.length-1)return n;let r=e.logicalIndexOf(t);return Number.isFinite(r)?Math.floor(r+1e-9):n>=0?n:null}function Ci(e,t){if(e===null||t===null)return e===t;let n=e.bar,r=t.bar;return e.x===t.x&&e.y===t.y&&e.paneId===t.paneId&&e.index===t.index&&e.time===t.time&&e.price===t.price&&(n===null||r===null?n===r:n.time===r.time&&n.open===r.open&&n.high===r.high&&n.low===r.low&&n.close===r.close&&n.volume===r.volume)}var wi=class{core;changed;pointer=null;external=null;dirty=!1;fromPointer=!1;frame=null;current=null;moving=!1;motionTimer=0;restingAt=null;constructor(e,t){this.core=e,this.changed=t}get value(){return this.current}setPointer(e){this.moving?this.restingAt=e:(e?.x!==this.restingAt?.x||e?.y!==this.restingAt?.y)&&(this.restingAt=null),this.pointer=e,this.external=null,this.dirty=!0,this.fromPointer=!0,this.changed()}noteMotion(){let{view:e}=this.core;this.moving=!0,this.restingAt=this.pointer,e.clearTimeout(this.motionTimer),this.motionTimer=e.setTimeout(()=>{this.motionTimer=0,this.moving=!1},150)}destroy(){this.core.view.clearTimeout(this.motionTimer)}setExternal(e){this.pointer=null,this.external=e,this.dirty=!0,this.fromPointer=!1,this.changed()}sync(e){if(!this.dirty&&e===this.frame)return;let t=this.current,n=this.locate(e);if(this.current=n,this.frame=e,this.dirty=!1,this.fromPointer&&!Ci(t,n)){let t=(n?.x??0)+e.layout.leftAxisWidth;this.core.bus.emit(`crosshairMove`,n?{visible:!0,...n,x:t}:{visible:!1})}}locate(e){let{core:t}=this;if(this.pointer){let n=!t.options.crosshair.snapToBars||this.moving||this.restingAt!==null;return mi(t,e,this.pointer.x,this.pointer.y,!n)}if(!this.external)return null;let{time:n,price:r,paneId:i}=this.external,a=Si(t.bars,n),o=e.panes.find(e=>e.id===i);if(a===null||!o)return null;let s=r===null?o.plot.y+o.plot.height/2:o.plot.y+o.scale.valueToY(r);return mi(t,e,t.timeScale.indexToX(a),s)}},Ti=class{capacity;entries=/* @__PURE__ */ new Map;constructor(e){this.capacity=e}get(e){let t=this.entries.get(e);return t!==void 0&&(this.entries.delete(e),this.entries.set(e,t)),t}set(e,t){if(this.entries.delete(e),this.entries.set(e,t),this.entries.size>this.capacity){let e=this.entries.keys().next();e.done||this.entries.delete(e.value)}}getOrCreate(e,t){let n=this.get(e);if(n!==void 0)return n;let r=t();return this.set(e,r),r}clear(){this.entries.clear()}get size(){return this.entries.size}},Ei=class{paths=new Ti(64);get(e){return this.paths.getOrCreate(e,()=>new Path2D(e))}};let Di={rows:[],buttons:[]};function Oi(e,t,n,r,i,a,o=`#ffffff`){if(!(r>=0&&r<=n.height)||n.width===0)return;let s=t.font.size+8,c=n.y+r-s/2;e.font=E(t.font.size,t.font.family),e.fillStyle=i,e.beginPath(),e.roundRect(n.x+1,c,n.width-2,(s-6)*a.length+6,2),e.fill(),e.fillStyle=o,e.textAlign=`left`,e.textBaseline=`middle`,a.forEach((t,r)=>{e.fillText(t,n.x+6+2,c+s/2+.5+(s-6)*r)})}function ki(e,t,n,r){let{latest:i}=t;for(let a of ar(t,n,r!==null))if(a.mark){let t=a.mark===i?.live?n.theme.text:void 0;Oi(e,n,a.axis,a.y,a.mark.color,[a.mark.text],t)}else if(i){let t=r===null?[i.text]:[i.text,r];Oi(e,n,a.axis,a.y,i.color,t)}}function Ai(e,t,n,r,i){let{theme:a}=n,o=n.crosshair,s=t.layout.timeAxis?.y??t.layout.height;if(e.beginPath(),o.vertical){let t=w(i.x,1,r);e.moveTo(t,0),e.lineTo(t,s)}if(o.horizontal&&i.y!==null){let n=w(i.y,1,r);e.moveTo(0,n),e.lineTo(t.layout.plotWidth,n)}if(C(e,a.crosshair,1,o.style),e.stroke(),!o.labels)return;e.font=E(n.font.size,n.font.family);let c=n.font.size+8,l={background:a.crosshairLabelBackground,color:a.crosshairLabelText,paddingX:6,height:c};i.priceText!==null&&i.y!==null&&n.priceScale.visible&&gn(e,i.priceText,t.layout.plotWidth+1,i.y,{...l,align:`left`}),i.leftPriceText!==null&&i.y!==null&&n.priceScale.visible&&gn(e,i.leftPriceText,-1,i.y,{...l,align:`right`});let u=t.layout.timeAxis;if(i.timeText!==null&&u){let n=e.measureText(i.timeText).width+12,r=Zn(t,i.x,n);gn(e,i.timeText,r,u.y+u.height/2,{...l,align:`center`})}}function ji(e,t,n,r,i,a){let{theme:o}=t;a&&(e.fillStyle=S(o.text,.12),e.beginPath(),e.roundRect(i.x,i.y,i.width,i.height,2),e.fill());let s=i.height-4;e.save(),e.translate(i.x+2,i.y+2),e.scale(s/24,s/24),e.strokeStyle=a?o.text:o.textMuted,e.lineWidth=2,e.lineCap=`round`,e.lineJoin=`round`,e.setLineDash([]),e.stroke(n.get(r.icon)),e.restore()}function Mi(e,t,n,r,i){e.font=E(n.font.size,n.font.family),e.textAlign=`left`,e.textBaseline=`top`;let a=n.font.size+6,o=n.font.size+5,s=/* @__PURE__ */ new Map,c=[],l=[];for(let u of r){let{item:r}=u,d=t.panes.find(e=>e.id===r.paneId);if(!d)continue;let f=d.plot.x+8,p=d.plot.x+d.plot.width-8,m=d.plot.y+d.plot.height,h=d.plot.y+6+(d.id===`main`?n.legend.top:0),g=s.get(r.paneId)??0,_=g,v=f,ee=h+_*a,te=f,ne=e=>(v>f&&v+e>p&&(_+=1,v=f,ee+=a),ee+a<=m),re=()=>{e.globalAlpha=1;for(let t of u.buttons){if(!ne(o))break;let a={x:v,y:ee-2,width:o,height:o};ji(e,n,i,t,a,u.hoveredButton===t.id),l.push({item:r,id:t.id,rect:a}),v+=o+2,te=Math.max(te,v)}v+=6},ie=u.buttons.length===0?-1:r.kind===`main`?0:1,ae=ie>=0&&n.legend.hideValuesOnHover?ie:1/0;for(let[t,n]of u.segments.entries()){t===ie&&re();let i=e.measureText(n.text).width;if(!ne(i))break;t<ae&&(e.globalAlpha=r.visible?1:.45,e.fillStyle=n.color,e.fillText(n.text,v,ee)),v+=i+8,te=Math.max(te,v-8)}ie>=u.segments.length&&re(),e.globalAlpha=1;let y=h+g*a-2;c.push({item:r,rect:{x:f,y,width:te-f,height:(_-g+1)*a}}),s.set(r.paneId,_+1)}return{rows:c,buttons:l}}function Ni(e,t,n,r,i,a){let o=n.legend.visible?Mi(e,t,n,i.legends,a):Di;return ki(e,t,n,i.countdown),i.crosshair&&Ai(e,t,n,r,i.crosshair),o}let Pi=(e,t)=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height;var Fi=class{icons=new Ei;layout={rows:[],buttons:[]};hovered=null;get hover(){return this.hovered}paint(e,t,n,r,i,a){let o=bi(t,n,r,i,Date.now(),this.hovered);this.layout=Ni(e,n,t.options,a,o,this.icons)}at(e){let t=this.layout.buttons.find(t=>Pi(t.rect,e));if(t)return{item:t.item,button:t.id};let n=this.layout.rows.find(t=>Pi(t.rect,e));return n?{item:n.item,button:null}:null}setHover(e){let t=e?{kind:e.item.kind,id:e.item.id,button:e.button}:null,n=this.hovered;return n?.kind===t?.kind&&n?.id===t?.id&&n?.button===t?.button?!1:(this.hovered=t,!0)}};let Ii={kind:`outside`};function O(e,t,n){return e.isDestroyed?n:e.run(t)}function Li(e,t){return e.runCommand(t)?!0:t===`escape`&&e.objects.selection?(e.selectByUser(null),!0):!1}function Ri(e,t){let{layout:n}=e;for(let e of n.separators)if(t.y>=e.y-3&&t.y<=e.y+e.height+3)return{kind:`separator`,above:e.above,below:e.below};for(let r of e.panes)if(t.y>=r.plot.y&&t.y<r.plot.y+r.plot.height)return t.x<0?{kind:`price-axis`,paneId:r.id,scale:pe}:t.x<n.plotWidth?{kind:`plot`,paneId:r.id}:{kind:`price-axis`,paneId:r.id,scale:fe};let r=n.timeAxis;return r&&t.y>=r.y&&t.y<r.y+r.height&&t.x>=0&&t.x<n.plotWidth?{kind:`time-axis`}:{kind:`outside`}}function zi(e,t,n){let r=e.frame(),i=Ri(r,t),a={x:t.x+r.layout.leftAxisWidth,y:t.y,target:n?{kind:n.kind,id:n.id,part:n.part}:null},o=i.kind===`price-axis`?r.panes.find(e=>e.id===i.paneId):null;if(i.kind===`price-axis`&&o){let n=(e.panes.findScale(i.paneId,i.scale)?.scale)?.yToValue(t.y-o.plot.y)??NaN;return{...a,area:i.kind,paneId:i.paneId,scaleId:i.scale,index:null,time:null,price:Number.isFinite(n)?n:null}}let s=mi(e,r,t.x,t.y);return{...a,area:i.kind,paneId:s?.paneId??null,scaleId:null,index:s?.index??null,time:s?.time??null,price:s?.price??null}}function Bi(e,t,n){let r=new Map(e.frame().panes.map(e=>[e.id,e.plot.height])),i=new Map(e.panes.list().map(e=>[e.id,e.height])),a=r.get(t)??0,o=a+(r.get(n)??0),s=Math.min(e.options.panes.minHeight,o/2),c=!1,l=t=>{O(e,()=>{for(let n of e.panes.list())n.id!==`main`&&e.panes.update(n.id,{height:t.get(n.id)??n.height});e.invalidate()})};return{move:e=>{let i=On(a+e,s,o-s);l(new Map([...r,[t,i],[n,o-i]])),c=!0},cancel:()=>{c&&l(i)},end:()=>{c&&O(e,()=>{for(let t of e.panes.list())t.id!==`main`&&t.height!==i.get(t.id)&&e.bus.emit(`paneResize`,{paneId:t.id,height:t.height})})}}}function Vi(e,t){return{move:(n,r)=>{O(e,()=>{t.move(n,r)})},end:()=>{O(e,()=>{t.end()})},cancel:()=>{O(e,()=>{t.cancel()})}}}function Hi(e,t){return{pointerDown:(n,r,i)=>{O(e,()=>{t.pointerDown(n,r,i)})},pointerMove:(n,r)=>{O(e,()=>{t.pointerMove(n,r)})},pointerUp:(n,r,i)=>{O(e,()=>{t.pointerUp(n,r,i)})},doubleClick:n=>{O(e,()=>{t.doubleClick(n)})},cancelPress:()=>{O(e,()=>{t.cancelPress()})}}}function Ui(e){let t=()=>e.options.interaction,n=t=>{O(e,()=>{e.shownFrame(),t(),e.invalidate()})},r=t=>O(e,()=>{e.shownFrame();let n=e.timeScale.state();t();let r=e.timeScale.state(),i=r.barSpacing!==n.barSpacing||r.offset!==n.offset;return i&&(e.noteMotion(),e.invalidate()),i},!1);return{root:e.surface.root,enabled:e=>t()[e],longPressMs:()=>t().longPressMs,beforePaint:t=>{e.beforePaint(()=>{O(e,t)})},plotWidth:()=>O(e,()=>e.shownFrame().layout.plotWidth,0),originX:()=>O(e,()=>e.shownFrame().layout.leftAxisWidth,0),regionAt:t=>O(e,()=>Ri(e.shownFrame(),t),Ii),setPointer:t=>{O(e,()=>{e.setPointer(t)})},magnify:t=>{O(e,()=>{e.magnify(t)})},hitTest:t=>O(e,()=>e.hitTest(t),null),hover:t=>{O(e,()=>{e.setHovered(t)})},hoverSeparator:t=>{O(e,()=>{e.setHoveredSeparator(t)})},legendAt:t=>e.options.legend.visible?e.legend.at(t):null,hoverLegend:t=>{O(e,()=>{e.setLegendHover(t)})},clickLegend:t=>{O(e,()=>{t.button!==null&&e.bus.emit(`legendButtonClick`,{item:t.item,buttonId:t.button})})},beginDrag:(t,n,r)=>{let i=O(e,()=>e.beginDrag(t,n,r),null);return i?Vi(e,i):null},activeTool:()=>{let t=e.activeTool();return t?Hi(e,t):null},click:(t,n)=>{O(e,()=>{n?.part.startsWith(`button:`)?e.bus.emit(`buttonClick`,{kind:n.kind,id:n.id,buttonId:n.part.slice(7)}):(e.selectByUser(n?{kind:n.kind,id:n.id}:null),e.bus.has(`click`)&&e.bus.emit(`click`,zi(e,t,n)))})},doubleClick:(n,r)=>{O(e,()=>{r.kind===`price-axis`&&t().axisScale?(e.panes.findScale(r.paneId,r.scale)?.scale.lead.resetAutoScale(),e.invalidate()):r.kind===`time-axis`&&t().axisScale&&(e.timeScale.reset(e.options.timeScale.barSpacing),e.invalidate()),e.bus.has(`doubleClick`)&&e.bus.emit(`doubleClick`,zi(e,n,e.hitTest(n)))})},contextMenu:(t,n)=>O(e,()=>e.activeTool()?(Li(e,`escape`),!0):e.bus.has(`contextMenu`)?(e.bus.emit(`contextMenu`,zi(e,t,n)),!0):!1,!1),scrollTime:t=>r(()=>{e.timeScale.scrollBy(t)}),zoomTime:(t,n)=>r(()=>{e.timeScale.zoom(t,e.timeScale.zoomAnchor(n))}),isAutoScale:t=>e.panes.manualScales(t).length===0,panPrice:(t,r)=>{n(()=>{e.panes.manualScales(t).forEach(e=>{e.pan(r)})})},zoomPrice:(t,r,i,a)=>{n(()=>{let n=e.shownFrame().panes.find(e=>e.id===t);n&&e.panes.findScale(t,r)?.scale.lead.zoom(i,a-n.plot.y)})},beginPaneResize:(t,n)=>Bi(e,t,n),command:t=>O(e,()=>Li(e,t),!1),editObject:t=>O(e,()=>e.objects.edit(t),!1),scrollToRealTime:()=>{r(()=>{e.timeScale.scrollToRealTime()})}}}let Wi={buy:1,sell:-1};function Gi(e,t=`trades`){return e.map((e,r)=>{let o=`${t}[${r}]`;h(o,e);let s=a(e.time,`${o}.time`),c=e.size??0;(typeof e.price!=`number`||!Number.isFinite(e.price))&&n(`${o}.price must be a finite number, received ${i(e.price)}.`),(typeof c!=`number`||!Number.isFinite(c)||c<0)&&n(`${o}.size must be a finite number of at least 0, received ${i(c)}.`);let l=e.side===void 0?null:m(`${o}.side`,e.side,[`buy`,`sell`]);return{time:s,price:e.price,size:c,side:l}})}function Ki(e,t){return{time:e.time,open:e.open,high:Math.max(e.high,t.price),low:Math.min(e.low,t.price),close:t.price,volume:e.volume+t.size}}function qi(e,t,n,r,i){let a=t,o=(a&&i(a.time))??-1/0,s=n,c=[],l=[],u=[];return e.forEach(e=>{let t=r(e.time);if(t===null||e.time<s||t<o)return;let n=a&&t===o?Ki(a,e):Ji(t,e);c.length>0&&c[c.length-1]?.time===n.time?c[c.length-1]=n:c.push(n),a=n,o=t,s=e.time,l.push(e),u.push(t)}),{bars:c,kept:l,barTimes:u,latest:s}}function Ji(e,t){return{time:e,open:t.price,high:t.price,low:t.price,close:t.price,volume:t.size}}var Yi=class{capacity;times=/* @__PURE__ */ new Float64Array;prices=/* @__PURE__ */ new Float64Array;sizes=/* @__PURE__ */ new Float64Array;sides=/* @__PURE__ */ new Int8Array;barTimes=/* @__PURE__ */ new Float64Array;oldest=0;total=0;revealed=0;cutoff=1/0;changes=new Ve;constructor(e){this.capacity=e}get revision(){return this.changes.revision}get first(){return this.oldest}get end(){return this.revealed}time(e){return this.times[e%this.capacity]??NaN}price(e){return this.prices[e%this.capacity]??NaN}size(e){return this.sizes[e%this.capacity]??NaN}side(e){let t=this.sides[e%this.capacity];return t===1?`buy`:t===-1?`sell`:null}bar(e){let t=this.price(e);return{time:this.time(e),open:t,high:t,low:t,close:t,volume:this.size(e)}}append(e,t){this.capacity!==0&&(this.reserve(this.total+e.length),e.forEach((e,n)=>{let r=this.total%this.capacity;this.times[r]=e.time,this.prices[r]=e.price,this.sizes[r]=e.size,this.sides[r]=e.side===null?0:Wi[e.side],this.barTimes[r]=t[n]??NaN,this.total+=1}),this.oldest=Math.max(this.oldest,this.total-this.capacity),this.reveal())}setCutoff(e){this.cutoff=e,this.reveal()}setCapacity(e){if(e===this.capacity)return;let t=Math.max(this.oldest,this.total-e),n=Array.from({length:this.total-t},(e,n)=>t+n).map(e=>{let t=e%this.capacity;return[this.times[t]??NaN,this.prices[t]??NaN,this.sizes[t]??NaN,this.sides[t]??0,this.barTimes[t]??NaN]});this.capacity=e,this.oldest=t,this.times=/* @__PURE__ */ new Float64Array,this.prices=/* @__PURE__ */ new Float64Array,this.sizes=/* @__PURE__ */ new Float64Array,this.sides=/* @__PURE__ */ new Int8Array,this.barTimes=/* @__PURE__ */ new Float64Array,this.reserve(this.total),n.forEach(([n,r,i,a,o],s)=>{let c=(t+s)%e;this.times[c]=n,this.prices[c]=r,this.sizes[c]=i,this.sides[c]=a,this.barTimes[c]=o}),this.revealed=Math.max(this.revealed,t)}clear(){this.oldest=0,this.total=0,this.revealed=0,this.changes.reset()}changesSince(e){return this.changes.since(e)}view(){return new Xi(this)}reveal(){let e=this.oldest,t=this.total;for(;e<t;){let n=e+t>>>1;(this.barTimes[n%this.capacity]??NaN)<=this.cutoff?e=n+1:t=n}let n=this.revealed;this.revealed=e,e>n?this.changes.tail(n):e<n&&this.changes.reset()}reserve(e){let t=Math.min(this.capacity,e);if(t<=this.times.length)return;let n=Math.min(this.capacity,Math.max(16,this.times.length*2,t)),r=e=>{let t=new Float64Array(n);return t.set(e),t};this.times=r(this.times),this.prices=r(this.prices),this.sizes=r(this.sizes);let i=new Int8Array(n);i.set(this.sides),this.sides=i,this.barTimes=r(this.barTimes)}},Xi=class{log;constructor(e){this.log=e}get length(){return this.log.end-this.log.first}get revision(){return this.log.revision}time(e){return this.log.time(this.log.first+e)}open(e){return this.log.price(this.log.first+e)}high(e){return this.log.price(this.log.first+e)}low(e){return this.log.price(this.log.first+e)}close(e){return this.log.price(this.log.first+e)}volume(e){return this.log.size(this.log.first+e)}bar(e){return e>=0&&e<this.length?this.log.bar(this.log.first+e):null}lowerBound(e){let t=0,n=this.length;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}};let k=864e5,Zi=[`second`,`minute`,`hour`,`day`,`week`,`month`],Qi={second:1e3,minute:6e4,hour:36e5},$i={day:1,week:7,month:30},ea={s:`second`,m:`minute`,h:`hour`,H:`hour`,d:`day`,D:`day`,w:`week`,W:`week`,M:`month`},ta={second:`s`,minute:`m`,hour:`h`,day:`D`,week:`W`,month:`M`},na=/^(\d*)([smhHdDwWM])$/;function ra(e,t,r,a){return(!Number.isSafeInteger(t)||t<1)&&n(`${r} needs a positive integer count, received ${i(a)}.`),Object.freeze({unit:e,count:t})}function ia(e,t=`interval`){let r=e;if(typeof r==`string`){let e=na.exec(r),i=e?ea[e[2]??``]:void 0;return!e||!i?n(`${t} ${JSON.stringify(r)} is not an interval; use a count and a unit such as "15s", "5m", "4h", "1D", "1W" or "3M".`):ra(i,e[1]?Number(e[1]):1,t,r)}if(typeof r!=`object`||!r||Array.isArray(r))return n(`${t} must be a string such as "5m" or an object { unit, count }, received ${i(r)}.`);let{unit:a,count:o}=r;return Zi.includes(a)||n(`${t}.unit must be one of ${Zi.map(e=>`"${e}"`).join(`, `)}, received ${i(a)}.`),ra(a,o,t,o)}function A(e){let{unit:t,count:n}=ia(e);return`${n}${ta[t]}`}function aa(e){let t=Qi[e.unit];return t===void 0?null:t*e.count}function oa(e){return aa(e)??($i[e.unit]??0)*864e5*e.count}function sa(e){return aa(ia(e))}function ca(e,t){return e===t||e?.unit===t?.unit&&e?.count===t?.count}function la(e,t){let n=aa(e),r=aa(t),i=`it is finer than the source`;return r===null?n===null?e.unit===t.unit?e.count<t.count?i:e.count%t.count===0?null:`${A(e)} is not a multiple of ${A(t)}`:t.unit===`day`?t.count===1?null:`weeks and months are built from 1D bars`:e.unit===`day`?i:`weeks and months do not divide each other`:i:n===null?864e5%r==0?null:`${A(t)} does not divide a day`:n<r?i:n%r===0?null:`${A(e)} is not a multiple of ${A(t)}`}function ua(e,t){let r=ia(e,`timeframe`),i=ia(t),a=la(r,i);a!==null&&n(`The timeframe ${A(r)} cannot be built from ${A(i)} source bars: ${a}.`)}function da(e,t){return la(ia(e,`timeframe`),ia(t))===null}let fa=6e4,pa=108e5;function ma(e){return((e+4)%7+7)%7}var ha=class{spec;timeZone;path;clock;dateOffset;recent=null;latest=null;latestDay=null;tradingWeek;constructor(e,t,n){this.spec=e,this.timeZone=t,this.path=n,this.clock=new Rt(t),this.dateOffset=e.dayStart===0?0:e.dayStart*fa-k,this.tradingWeek=[0,1,2,3,4,5,6].filter(t=>e.weekdays[ma(t)])}bucket(e,t){return this.cached(t).bucketer(a(e))}range(e,t){let n=a(e),{run:r,bucketer:i}=this.cached(t),o=i(n);return o===null?null:this.spec.bucket?{bucket:o,start:n,end:n+1}:{...r}}cached(e){if(this.recent?.input!==e){let t={bucket:0,start:0,end:0};this.recent={input:e,run:t,bucketer:this.bucketer(ia(e),t)}}return this.recent}bucketer(e,t={bucket:0,start:0,end:0},r=!1){let a=r&&aa(e)===null,s=n=>n>=t.start&&n<t.end||this.locate(n,e,t,a)?t.bucket:null,c=this.spec.bucket;return c?t=>{let r=c(t,e,s);return r!==null&&(typeof r!=`number`||!Number.isFinite(r))&&n(`${this.path}.bucket must return a time or null, received ${i(r)} for ${o(t)}.`),r}:s}locate(e,t,n,r){let i=r?this.day(e):this.segment(e);if(i===null)return!1;let a=aa(t),{start:o,end:s}=i;if(a!==null){let{origin:t}=i;n.bucket=t+Math.floor((e-t)/a)*a,o=Number.isNaN(o)?o:n.bucket,s=Math.min(n.bucket+a,s)}else{let e=this.trading(i.date,1),{count:r}=t,a,c;switch(t.unit){case`day`:{let t=Math.floor(this.tradingDates(e)/r)*r;a=this.tradingDate(t),c=this.tradingDate(t+r);break}case`week`:{let t=e-(ma(e)-this.spec.weekStart+7)%7,n=-((4-this.spec.weekStart+7)%7);a=n+Math.floor((t-n)/7/r)*r*7,c=a+r*7;break}default:{let t=/* @__PURE__ */ new Date(e*k),n=Math.floor((t.getUTCFullYear()*12+t.getUTCMonth())/r)*r;a=Date.UTC(Math.floor(n/12),n%12,1)/k,c=Date.UTC(Math.floor(n/12),n%12+r,1)/k}}n.bucket=this.clock.instant(a*k),this.spec.sessions.length===0&&(o=this.movingInto(a),s=this.movingInto(c))}let c=!Number.isNaN(o+s);return n.start=c?o:e,n.end=c?s:e+1,!0}day(e){let t=this.latestDay;if(t!==null&&e>=t.start&&e<t.end)return t;let n=e+this.clock.offset(e),r=Math.floor((n-this.dateOffset)/k),i=r*k+this.dateOffset;return this.latestDay={origin:this.clock.instant(i),start:this.steady(i),end:this.steady(i+k),date:r},this.latestDay}segment(e){let t=this.latest;if(t!==null&&e>=t.start&&e<t.end)return t;let n=e+this.clock.offset(e),r=Math.floor((n-this.dateOffset)/k),i=r*k+this.dateOffset,a=i+k;if(this.spec.sessions.length>0){let e=this.session(n);if(e===null)return null;[i,a]=e}return this.latest={origin:this.clock.instant(i),start:this.steady(i),end:this.steady(a),date:r},this.latest}session(e){let t=Math.floor(e/k)*k;for(let{start:n,end:r}of this.spec.sessions){let i=(n-(n>r&&e-t<r*fa?1440:0))*fa,a=i+(r-n+1440)%1440*fa;if(e>=t+i&&e<t+a)return[t+i,t+a]}return null}movingInto(e){return this.steady((this.trading(e-1,-1)+1)*k+this.dateOffset)}tradingDates(e){let t=Math.floor(e/7),n=e-t*7;return t*this.tradingWeek.length+this.tradingWeek.filter(e=>e<n).length}tradingDate(e){let t=Math.floor(e/this.tradingWeek.length);return t*7+(this.tradingWeek[e-t*this.tradingWeek.length]??NaN)}trading(e,t){let n=e;for(;!this.spec.weekdays[ma(n)];)n+=t;return n}steady(e){let t=this.clock.instant(e),n=this.clock.offset(t);return t+n===e&&this.clock.offset(t-pa)===n&&this.clock.offset(t+pa)===n?t:NaN}};let ga=g({timeZone:!0,sessions:!0,dayStart:!0,weekdays:!0,weekStart:!0,bucket:!0});function _a(e={}){_(`calendar`,e,ga);let t=Se(Jt().calendar,e),n=te(`calendar.timeZone`,t.timeZone),r=new ha(nn(t,`calendar`),n,`calendar`);return{bucket:(e,t)=>r.bucket(e,t),range:(e,t)=>r.range(e,t)}}var va=class{store;first=0;constructor(e){this.store=e}get revision(){return this.store.revision}get end(){return this.store.length}changesSince(e){return this.store.changesSince(e)}bar(e){return this.store.read(e)}side(){return null}view(){return this.store}};function ya(e,t,r){let i=[],a=t,s=-1/0;for(let t of e)Number.isFinite(t.time)&&Number.isFinite(t.open)&&Number.isFinite(t.high)&&Number.isFinite(t.low)&&Number.isFinite(t.close)&&Number.isFinite(t.volume)||n(`The "${r}" transform produced a bar with a value that is not a finite number.`),t.time<s&&n(`The "${r}" transform produced a bar at ${o(t.time)} after a bar at ${o(s)}; times must not decrease.`),s=t.time,a=Math.max(t.time,a+1),i.push(a===t.time?t:{...t,time:a});return i}var ba=class{input;from;output;type;definition;params;stream=null;latest=null;fed=0;completed=0;seen=-1;constructor(e,t,n,r,i,a){this.input=e,this.from=t,this.output=n,this.type=r,this.definition=i,this.params=a}get settled(){return this.completed}lastClose(){let{first:e,end:t}=this.input;return t>e?this.input.bar(t-1).close:null}resolved(){return this.latest?.resolved?.()??null}sync(){let e=this.input.changesSince(this.seen);e&&(e.kind===`tail`&&this.stream&&e.from>=this.fed&&this.fed>=this.input.first?this.extend(this.stream):this.rebuild(),this.seen=this.input.revision)}rebuild(){let e=this.definition.create(this.params,this.input.view(),this.from),t=this.feed(e,this.input.first),n=ya(t.bars,-1/0,this.type);this.commit(e,t,0),this.output.assign(n)}extend(e){let t=this.fed<this.input.end-1?e.clone():e,n=this.completed,r=this.feed(t,this.fed),i=n>0?this.output.time(n-1):-1/0,a=ya(r.bars,i,this.type);this.commit(t,r,n),this.output.replaceFrom(n,a)}commit(e,t,n){this.stream=e,this.fed=t.fed,this.completed=n+t.completed,this.latest=t.latest}feed(e,t){let n=this.input.end,r=[],i=t;for(;i<n-1;i+=1)for(let t of e.next(this.input.bar(i),this.input.side(i)))r.push(t);let a=r.length,o=e;if(n>t){let t=e.clone();r.push(...t.next(this.input.bar(n-1),this.input.side(n-1)));let i=t.current();o=t,i&&r.push(i)}return{bars:r,fed:i,completed:a,latest:o}}};function xa(){return new Dr(`bar transform`,[],`Give it to the chartTypes module, or register it with chart.transforms.register().`)}let Sa=g({type:!0,params:!0,input:!0});function Ca(e){return new ha(nn(e.calendar,`options.calendar`),e.calendar.timeZone,`options.calendar`)}function wa(e){return aa(e)===null}function Ta(e,t){if(wa(t))return e.bucketer(t,void 0,!0);let r=e.bucketer(t);return i=>{let a=r(i);return a!==null&&a!==i&&n(`The ${A(t)} bar at ${o(i)} does not start a bar of the trading calendar, which starts it at ${o(a)}: set options.calendar as the data times its bars, such as its timeZone (now ${JSON.stringify(e.timeZone)}).`),a}}function Ea(e,t,n){let r=Ta(e,t);if(!n)return r;let i=e.bucketer(n,void 0,wa(t));return e=>r(e)===null?null:i(e)}function Da(e,t,n){return e.bucketer(n??t,void 0,wa(t))}let Oa=[`bars`,`trades`];function ka(e){e.forEach(e=>{e()})}var Aa=class{bars;series;options;feed;transforms=xa();displayed;revealed;timeBars=new nt;trades;stage=null;latestTrade=-1/0;source=null;frame=null;calendar;constructor(e,t,n){this.bars=e,this.series=t,this.options=n,this.feed=ht(ot,e),this.displayed=new rt(e),this.revealed=new rt(this.feed.source,()=>this.feed.revealed(),()=>this.feed.cutoffMoves()),this.calendar=Ca(n),this.trades=new Yi(n.performance.maxTrades)}sourceInterval(){return this.source}tradingCalendar(){return this.calendar}timeframe(){return this.frame}transform(){if(!this.stage)return null;let e=this.stage.resolved();return{type:this.stage.type,params:structuredClone(this.stage.params),input:this.stage.from,resolved:e&&structuredClone(e)}}transformResolved(){return this.stage?.resolved()??null}setTransform(e){if(e===null){this.stage&&(this.stage=null,this.feed.setDisplay(this.bars));return}let{type:t,definition:n,params:r,from:i}=this.startTransform(e),a=i===`trades`?this.trades:new va(this.timeBars),o=this.stage;o||this.feed.setDisplay(this.timeBars);let s=new ba(a,i,this.bars,t,n,r);try{s.sync()}catch(e){throw o||this.feed.setDisplay(this.bars),e}this.stage=s}checkTransform(e){let{type:t,definition:n,params:r,from:i}=this.startTransform(e);new ba(i===`trades`?this.trades:new va(this.stage?this.timeBars:this.bars),i,new nt,t,n,r).sync()}startTransform(e){_(`transform`,e,Sa);let t=p(`transform.type`,e.type),n=this.transforms.require(t);e.params!==void 0&&h(`transform.params`,e.params);let r=e.input===void 0?`bars`:m(`transform.input`,e.input,Oa),i={...e.params};return n.create(i,r===`trades`?this.trades.view():this.feed.display,r),{type:t,definition:n,params:i,from:r}}livePrice(){return this.stage&&!this.stage.definition.keepsTime?this.stage.lastClose():null}settled(){return this.stage?this.stage.settled:Math.max(0,this.bars.length-1)}timeBased(){return this.stage?.definition.keepsTime??!0}resolution(){return this.timeBased()?this.frame??this.source:`untimed`}barDuration(){if(!this.timeBased())return null;let e=this.frame??this.source;return e?aa(e):null}barEnd(e){let t=this.timeBased()?this.frame??this.source:null,n=t?this.calendar.range(e,t):null;return n&&n.end>e+1?n.end:null}firstSourceTime(){return this.feed.firstTime()}configure(e){let t=this.options,n=!an(t.calendar,e.calendar),r=n?Ca(e):this.calendar,i=n?this.source:null,a=i?this.planBuckets(r,i,this.frame):[];return this.options=e,this.trades.setCapacity(e.performance.maxTrades),ka(a),this.calendar=r,i&&this.stage?.sync(),i!==null}set(e,t){let n=t===void 0?null:ia(t,`interval`),r=n&&this.frame&&da(this.frame,n)?this.frame:null,i=n&&r&&!ca(r,n)?r:null,a=n?Da(this.calendar,n,i):ot,o=n?Ea(this.calendar,n,i):ot;ka([this.feed.planSet(e,o),this.series.planRebucket(a)]),this.source=n,this.frame=i,this.trades.clear(),this.latestTrade=-1/0,this.stage?.sync()}update(e){this.feed.planUpdate(e)(),this.stage?.sync()}prepend(e){let{inserted:t,commit:n}=this.feed.planPrepend(e);return n(),this.stage?.sync(),t}addTrades(e){let t=this.source??n(`addTrades() needs the source interval: pass it with data.set(bars, { interval }).`),r=this.feed.source,{bars:i,kept:a,barTimes:o,latest:s}=qi(Gi(e),r.bar(r.length-1),this.latestTrade,this.calendar.bucketer(t),Ta(this.calendar,t));return this.latestTrade=s,this.trades.append(a,o),this.update(i),a.length}addSeriesTrades(e,t){let r=this.source??n(`series.addTrades() needs the source interval: pass it with data.set(bars, { interval }).`),i=Gi(t),a=this.calendar.bucketer(r),o=Ta(this.calendar,r);if(e.source.input===`ohlc`){let{feed:t}=e.source,n=qi(i,t.source.bar(t.source.length-1),e.latestTrade,a,o);return t.planUpdate(n.bars)(),e.latestTrade=n.latest,n.kept.length}let{feed:s}=e.source,c=s.source.length,l=s.source.value(c-1),u=qi(i,c===0?null:{time:s.source.time(c-1),open:l,high:l,low:l,close:l,volume:0},e.latestTrade,a,o);return s.planUpdate(u.bars.map(e=>({time:e.time,value:e.close})))(),e.latestTrade=u.latest,u.kept.length}clear(){this.feed.clear(),this.trades.clear(),this.latestTrade=-1/0,this.setCutoff(1/0)}setTimeframe(e){let t=this.source??n(`setTimeframe() needs the source interval: pass it with data.set(bars, { interval }).`),r=e===null?null:ia(e,`timeframe`);r&&ua(r,t);let i=r&&ca(r,t)?null:r;ka(this.planBuckets(this.calendar,t,i)),this.frame=i,this.stage?.sync()}bucketerOf(e,t){return Ea(this.calendar,e,t)}setCutoff(e){this.series.setCutoff(e),this.trades.setCutoff(e);let t=this.feed.setCutoff(e);return this.stage?.sync(),t}planBuckets(e,t,n){return[this.feed.planRebucket(Ea(e,t,n)),this.series.planRebucket(Da(e,t,n))]}},ja=class{bars;revision=-1;value=2;constructor(e){this.bars=e}get(e){if(e!==`auto`)return e;let t=this.bars;if(this.revision!==t.revision){let e=2;for(let n=Math.max(0,t.length-500);n<t.length;n+=1)e=Bt(t.open(n),e),e=Bt(t.high(n),e),e=Bt(t.low(n),e),e=Bt(t.close(n),e);this.revision=t.revision,this.value=e}return this.value}invalidate(){this.revision=-1}},Ma=class{environment;plugins=/* @__PURE__ */ new Map;constructor(e){this.environment=e}add(e){h(`plugin`,e);let t=p(`plugin.name`,e.name);for(let t of[`attach`,`detach`,`paint`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`plugin.${t} must be a function.`);this.plugins.has(t)&&n(`A plugin named "${t}" is already added.`);let{environment:r}=this;e.attach?.({chart:r.chart(),bars:r.displayed,source:r.source,repaint:()=>{r.repaint()}}),this.plugins.set(t,e),r.repaint()}remove(e){let t=this.plugins.get(e)??n(`There is no plugin named "${e}".`);this.plugins.delete(e),this.environment.repaint(),t.detach?.()}get(e){return this.plugins.get(e)??null}list(){return[...this.plugins.values()]}paint(e,t,n,r,i){let a=[...this.plugins.values()].filter(e=>e.paint!==void 0);if(a.length===0)return;let{environment:o}=this,{bars:s,timeScale:c}=o,l=o.options(),u={ctx:e,pixelRatio:i,layer:r,pane:{id:n.id,width:n.plot.width,height:n.plot.height,valueToY:e=>n.scale.valueToY(e),yToValue:e=>n.scale.yToValue(e),formatValue:e=>o.formatValue(n,e)},bars:o.displayed,source:o.source,cutoff:o.cutoff(),visible:t.visible,barSpacing:c.barSpacing,indexToX:e=>c.indexToX(e),xToIndex:e=>c.xToIndex(e),timeToX:e=>c.indexToX(s.logicalIndexOf(e)),theme:l.theme,font:{family:l.font.family,size:l.font.size}};for(let t of a)hn(e,()=>{t.paint?.(u)})}detachAll(){let e=[...this.plugins.values()];this.plugins.clear(),r(e.map(e=>()=>e.detach?.()))}},Na=class{readers=/* @__PURE__ */ new Map;users=[];constructor(e,t){this.provide(`price`,{check:()=>void 0,read:(t,n)=>e.price(n,t.field??`close`),paneOf:()=>b}),this.provide(`series`,{check:e=>{t.require(e.id)},read:(n,r)=>{let i=t.require(n.id),a=i.values??i.bars,o=a?a.lowerBound(e.time(r)+1)-1:-1;return o<0?NaN:i.values?i.values.value(o):i.bars?.close(o)??NaN},paneOf:e=>t.require(e.id).pane,scaleOf:e=>t.require(e.id).scale})}provide(e,t){this.readers.set(e,t)}use(e){this.users.push(e)}reader(e,t){return this.readers.get(e.kind)??n(`${t}: the chart has no ${e.kind} values; load the module of its ${e.kind}s.`)}check(e,t){this.reader(e,t).check(e,t)}read(e,t){return this.reader(e,`source`).read(e,t)}paneOf(e){return this.reader(e,`source`).paneOf(e)}scaleOf(e){return this.reader(e,`source`).scaleOf?.(e)??`right`}movable(e){return this.readers.get(e.kind)?.movable===!0}uses(e,t){return this.users.flatMap(n=>n.uses(e,t).map(e=>({...e,noun:n.noun})))}assertUnused(e,t){let r=/* @__PURE__ */ new Map;for(let n of this.uses(e,t))r.set(n.noun,(r.get(n.noun)??/* @__PURE__ */ new Set).add(n.user));if(r.size===0)return;let i=[...r].map(([e,t])=>{let n=[...t].map(e=>`"${e}"`).join(`, `);return t.size>1?`the ${e}s ${n}`:`${e} ${n}`}),a=i.length>1||[...r.values()].some(e=>e.size>1);n(`"${t}" is read by ${i.join(` and `)}; remove ${a?`them`:`it`} first.`)}reset(){this.users.forEach(e=>{e.reset()})}verify(e){this.users.forEach(t=>{t.verify(e)})}},Pa=class{host;lastVisibleKey=``;loadMoreArmed=!0;loadMoreFirstTime=NaN;constructor(e){this.host=e}check(){let{bars:e,timeScale:t,bus:n}=this.host,r=t.visibleBars(),i=r?`${e.time(r.from)}:${e.time(r.to)}`:``;if(i!==this.lastVisibleKey){this.lastVisibleKey=i;let a=t.logicalRange();n.emit(`visibleRangeChange`,{range:r?{from:e.time(r.from),to:e.time(r.to)}:null,logicalRange:r?a:null})}this.checkLoadMore()}checkLoadMore(){let{bars:e,timeScale:t,bus:n,market:r,surface:i,options:a}=this.host;if(e.length===0||i.width===0)return;let o=a.timeScale.loadMoreThreshold-t.logicalRange().from;if(!(o>0)){this.loadMoreArmed=!0;return}let s=r.firstSourceTime()??e.time(0);(this.loadMoreArmed||s!==this.loadMoreFirstTime)&&(this.loadMoreArmed=!1,this.loadMoreFirstTime=s,n.emit(`loadMore`,{before:s,bars:Math.ceil(o)}))}};function Fa(e){return{minBarSpacing:e.timeScale.minBarSpacing,maxBarSpacing:e.timeScale.maxBarSpacing,rightOffset:e.timeScale.rightOffset}}var Ia=class{view;bus=new Nt;bars=new nt;seriesTypes=Yr();series=new St(this.seriesTypes,()=>this.currentOptions.theme);values=new Na(this.bars,this.series);surface;timeScale;panes;objects=new di;market;plugins;contributors=[];legendRows=[];scenePainters=[];commands=[];paneOccupants=[];stateParts=[];tool=null;hooks={barsChanged:[],dataCleared:[],destroyed:[]};moduleApis;input;currentOptions;formatterValue;marks;scheduler;pool=new Cn;frameValue=null;geometryDirty=!0;axisWidths={right:0,left:0};precision;magnified=null;tracker=new wi(this,()=>{this.invalidateLayers(`cursor`)});viewport=new Pa(this);countdown=new fi(this);hoveredSeparator=null;coveredTicks=``;legend=new Fi;cutoffTime=1/0;optionSections;destroyed=!1;constructor(e,t,n,r,i){this.view=e,this.optionSections=r.flatMap(e=>e.options?[e.options]:[]),this.currentOptions=pn(Jt(this.optionSections),n,this.optionSections),this.market=new Aa(this.bars,this.series,this.currentOptions),this.precision=new ja(this.market.feed.source),this.formatterValue=new zt(this.currentOptions.locale,this.currentOptions.timeZone),this.marks=new In(this.bars,this.formatterValue.clock),this.timeScale=new Er(Fa(this.currentOptions),this.currentOptions.timeScale.barSpacing),this.panes=new ve(this.currentOptions.panes.defaultHeight,this.currentOptions.priceScale.margins),this.surface=new Tr(e,t,this.currentOptions.performance.maxPixelRatio,()=>{this.run(()=>{this.invalidate()}),this.scheduler.flush()}),this.scheduler=new Cr(e,e=>{this.paint(e)}),this.plugins=new Ma({bars:this.bars,displayed:this.market.displayed,source:this.market.revealed,timeScale:this.timeScale,cutoff:()=>this.cutoffTime,options:()=>this.currentOptions,formatValue:(e,t)=>Rn(this,e,t),repaint:()=>{this.invalidateLayers(`scene`)},chart:i}),this.input=new li(Ui(this),e),this.moduleApis=this.install(r),this.axisWidths={right:this.currentOptions.priceScale.minWidth,left:0};let a=this.surface.measureContainer();this.surface.resize(a.width,a.height),this.surface.setAutoSize(this.currentOptions.autoSize),this.surface.watchPixelRatio(),this.invalidate()}install(e){let t={};try{for(let r of e)for(let[e,i]of Object.entries(r.install?.(this)??{}))Object.hasOwn(t,e)&&n(`Two modules add chart.${e}.`),t[e]=i}catch(e){throw this.destroy(),e}return t}get options(){return this.currentOptions}get formatter(){return this.formatterValue}get barDuration(){return this.market.barDuration()}barEnd(e){return this.market.barEnd(e)}get timeBased(){return this.market.timeBased()}get cutoff(){return this.cutoffTime}get isDestroyed(){return this.destroyed}get replaying(){return this.cutoffTime!==1/0}events(){return this.bus}get crosshair(){return this.tracker.sync(this.frame()),this.tracker.value}run(e){return this.destroyed&&n(`The chart has been destroyed.`),this.bus.defer(e)}applyOptions(e){let t=this.currentOptions,n=pn(t,e,this.optionSections);this.seriesTypes.require(n.mainSeries.type);let r=this.market.tradingCalendar(),i=this.rightEdgeTime(),a=this.market.configure(n);this.currentOptions=n,(n.locale!==t.locale||n.timeZone!==t.timeZone)&&(this.formatterValue=new zt(n.locale,n.timeZone),this.marks=new In(this.bars,this.formatterValue.clock)),this.timeScale.configure(Fa(n)),n.timeScale.barSpacing!==t.timeScale.barSpacing&&this.timeScale.setBarSpacing(n.timeScale.barSpacing),this.panes.configure(n.panes.defaultHeight,n.priceScale.margins),a?(this.timeScale.setBarCount(this.bars.length,`replace`),this.placeRightEdge(i),this.onBarsChanged({kind:`reset`})):this.market.tradingCalendar()!==r&&this.values.reset(),n.performance.maxPixelRatio!==t.performance.maxPixelRatio&&this.surface.setMaxPixelRatio(n.performance.maxPixelRatio),n.autoSize!==t.autoSize&&this.surface.setAutoSize(n.autoSize),this.precision.invalidate(),this.invalidate(),this.bus.emit(`optionsChange`,{options:n,previous:t})}resize(e,t){this.surface.resize(e,t)&&this.invalidate()}setData(e,t){this.changeData(`replace`,()=>{this.market.set(e,t)})}updateData(e){this.changeData(`tail`,()=>{this.market.update(e)})}addTrades(e){return this.changeData(`tail`,()=>this.market.addTrades(e))}prependData(e){return this.changeData(`prepend`,()=>this.market.prepend(e))}clearData(){this.cutoffTime=1/0,this.hooks.dataCleared.forEach(e=>{e()}),this.changeData(`reset`,()=>{this.market.clear()})}setTimeframe(e){this.changeData(`replace`,()=>{this.market.setTimeframe(e)})}setTransform(e){this.changeData(`replace`,()=>{this.market.setTransform(e)})}reveal(e,t){this.cutoffTime=e,this.changeData(t?`reset`:`tail`,()=>{this.market.setCutoff(e)})}changeData(e,t){let n=this.bars.revision,r=e===`replace`?this.rightEdgeTime():null,i=t(),a=this.bars.changesSince(n);return a?(this.timeScale.setBarCount(this.bars.length,e),this.placeRightEdge(r),this.onBarsChanged(e===`prepend`?{kind:`reset`}:a)):this.invalidate(),i}placeRightEdge(e){let t=e===null?NaN:this.bars.logicalIndexOf(e);Number.isFinite(t)&&this.timeScale.placeRightEdge(t)}rightEdgeTime(){if(this.timeScale.isFollowing()||this.bars.length===0||this.timeScale.plotWidth===0)return null;let e=this.bars.timeOfLogicalIndex(this.timeScale.rightEdge());return Number.isFinite(e)?e:null}createAutoPane(e){let t=e;for(let n=2;this.panes.get(t);n+=1)t=`${e}-${n}`;return this.panes.add({id:t},!0),t}occupantsOf(e){return[...this.paneOccupants.flatMap(t=>t.occupants(e)),...this.series.list().filter(t=>t.pane===e).map(e=>e.id)]}removePane(e){this.panes.remove(e),this.paneOccupants.forEach(t=>{t.removed(e)}),this.objects.prune()}releasePane(e){this.panes.get(e)?.auto&&this.occupantsOf(e).length===0&&this.removePane(e)}noteMotion(){this.tracker.noteMotion()}setLegendHover(e){this.legend.setHover(e)&&this.invalidateLayers(`cursor`)}setHoveredSeparator(e){this.hoveredSeparator!==e&&(this.hoveredSeparator=e,this.invalidateLayers(`scene`))}setPointer(e){this.tracker.setPointer(e)}setExternalCrosshair(e){this.tracker.setExternal(e)}magnify(e){this.magnified=this.currentOptions.interaction.touchMagnifier?e:null,this.invalidateLayers(`cursor`)}objectContext(e=this.frame()){return{frame:e,bars:this.bars,displayed:this.market.displayed,source:this.market.revealed,timeScale:this.timeScale,resolution:this.market.resolution(),options:this.currentOptions,formatter:this.formatterValue,selection:this.objects.selection,hovered:this.objects.hovered,cutoff:this.cutoffTime,scaleOf:(e,t)=>this.panes.findScale(e,t)?.scale??null,measureText:(e,t)=>this.measureText(e,t)}}measureText(e,t){let n=this.surface.context(`cursor`);return n.font=t,n.measureText(e).width}hitTest(e){return this.objects.hitTest(this.objectContext(),e)}setHovered(e){this.objects.setHovered(e)&&this.invalidateLayers(`objects`)}beginDrag(e,t,n){return this.objects.beginDrag(this.objectContext(),e,t,n)}select(e){this.objects.select(e)&&this.invalidateLayers(`objects`)}selectByUser(e){this.objects.select(e)&&(this.invalidateLayers(`objects`),this.bus.emit(`selectionChange`,{selection:e}))}activeTool(){return this.tool?.()??null}runCommand(e){return this.commands.some(t=>t(e))}invalidate(){this.geometryDirty=!0,this.scheduler.request(`scene`,`objects`,`cursor`)}invalidateLayers(...e){this.scheduler.request(...e)}beforePaint(e){this.scheduler.beforePaint(e)}frame(){if(this.geometryDirty||!this.frameValue){this.frameValue=this.buildFrame(),this.geometryDirty=!1;let{axisWidth:e,leftAxisWidth:t}=this.frameValue.layout;this.axisWidths={right:e,left:t},this.countdown.sync(),this.viewport.check()}return this.frameValue}shownFrame(){return this.frameValue??this.frame()}flush(){this.scheduler.flush()}buildFrame(){let e=this.surface.context(`cursor`);return e.font=E(this.currentOptions.font.size,this.currentOptions.font.family),Un({options:this.currentOptions,formatter:this.formatterValue,bars:this.bars,timeScale:this.timeScale,marks:this.marks,panes:this.panes,series:this.series,contributors:this.contributors,values:this.values,seriesTypes:this.seriesTypes,transform:this.market.transformResolved(),live:this.market.livePrice(),countdown:this.countdown.text(Date.now()),pricePrecision:this.precision.get(this.currentOptions.priceScale.precision),measureText:t=>e.measureText(t).width},{width:this.surface.width,height:this.surface.height},this.axisWidths,this.pool)}paint(e){this.bus.defer(()=>{let t=this.frame(),n=this.surface.pixelRatio,r=t.layout.leftAxisWidth,i=this.currentOptions,a=[],o=e=>{try{e()}catch(e){a.push(e)}},s=null;o(()=>{this.tracker.sync(t),s=xi(this,t,this.tracker.value)});let c=E(i.font.size,i.font.family),l=Qn(t,i,s,e=>this.measureText(e,c)),u=tr(t,i,l);if(e.has(`scene`)?o(()=>{this.coveredTicks=u,xr(this.surface.begin(`scene`,r),t,i,n,this.timeScale.barSpacing,(e,r,i)=>{this.plugins.paint(e,t,r,i,n),this.scenePainters.forEach(a=>{a(e,t,r,i,n)})},this.hoveredSeparator,l)}):u!==this.coveredTicks&&o(()=>{this.coveredTicks=u,Sr(this.surface.over(`scene`,r),t,i,n,this.hoveredSeparator,l)}),e.has(`objects`)&&o(()=>{this.objects.paint({...this.objectContext(t),ctx:this.surface.begin(`objects`,r),pixelRatio:n})}),e.has(`cursor`)&&o(()=>{let e=this.surface.begin(`cursor`,r);this.legend.paint(e,this,t,this.tracker.value,s,n),this.magnified&&nr(e,[this.surface.canvas(`scene`),this.surface.canvas(`objects`)],this.magnified,t.layout,n,i.theme)}),a.length>0)throw a[0]})}onBarsChanged(e){this.hooks.barsChanged.forEach(t=>{t(e)}),this.invalidate(),this.bus.emit(`barsChange`,{change:e})}destroy(){this.destroyed||r([()=>{this.plugins.detachAll()},()=>{this.bus.clear()},()=>{this.input.destroy()},()=>{this.destroyed=!0,this.scheduler.destroy(),this.countdown.stop(),this.tracker.destroy()},...this.hooks.destroyed,()=>{this.surface.destroy()}])}};function La(e){(typeof HTMLElement>`u`||!(e instanceof HTMLElement))&&n(`createChart() needs an HTMLElement container.`);let r=e.ownerDocument.defaultView??n(`The container is not attached to a window.`),i=[[`ResizeObserver`,typeof globalThis.ResizeObserver==`function`],[`PointerEvent`,typeof globalThis.PointerEvent==`function`],[`Path2D`,typeof globalThis.Path2D==`function`],[`matchMedia`,typeof r.matchMedia==`function`],[`requestAnimationFrame`,typeof r.requestAnimationFrame==`function`],[`Intl.DateTimeFormat`,typeof globalThis.Intl.DateTimeFormat==`function`]].filter(([,e])=>!e).map(([e])=>e);if(i.length>0)throw new t(`This browser lacks required APIs: ${i.join(`, `)}.`);return r}let Ra=[`version`,`mainSeries`,`transform`,`view`,`panes`];function za(e){let t=Object.fromEntries(e.stateParts.map(e=>[e.key,e.save()]));return structuredClone({version:1,mainSeries:{type:e.options.mainSeries.type,source:e.options.mainSeries.source},transform:Va(e.market.transform()),view:e.timeScale.state(),panes:e.panes.list().map(e=>{let{right:t}=e;return{id:e.id,title:e.title,height:e.height,auto:e.auto,mode:t.mode,inverted:t.invert,range:t.scale.manualRange(),margins:t.margins,scales:[...e.scales.values()].filter(e=>e.id!==fe).map(e=>({id:e.id,mode:e.mode,inverted:e.invert,margins:e.margins,range:e.scale.manualRange()}))}}),...t})}function Ba(e,t){h(`state`,t),t.version!==1&&n(`Unsupported chart state: expected version 1, received ${i(t.version)}.`);for(let r of Object.keys(t))!Ra.includes(r)&&!e.stateParts.some(e=>e.key===r)&&n(`The state has "${r}", which no module of the chart keeps.`);h(`state.mainSeries`,t.mainSeries),v(`state.panes`,t.panes),h(`state.view`,t.view),e.seriesTypes.require(t.mainSeries.type),t.transform!==void 0&&t.transform!==null&&e.market.checkTransform(t.transform);let r=e.options,a=new ve(r.panes.defaultHeight,r.priceScale.margins);t.panes[0]?.id!==`main`&&n(`The first pane of a chart state must be the main pane.`),t.panes.forEach((e,t)=>{h(`state.panes[${t}]`,e);let n=t===0?a.require(b):a.add({id:p(`panes[${t}].id`,e.id),title:e.title,height:e.height},e.auto);a.update(n.id,{title:e.title,height:d(`panes[${t}].height`,e.height,{min:1})}),e.scales!==void 0&&v(`panes[${t}].scales`,e.scales),[{id:fe,mode:e.mode,inverted:e.inverted,margins:e.margins??null,range:e.range},...e.scales??[]].forEach((e,r)=>{let i=`panes[${t}].scales[${r}]`;a.setScaleMode(n.id,e.id,e.mode),a.setScaleInverted(n.id,e.id,e.inverted),a.setScaleMargins(n.id,e.id,e.margins),e.range!==null&&(h(`${i}.range`,e.range),d(`${i}.range.min`,e.range.min),d(`${i}.range.max`,e.range.max))})});let o=e.stateParts.map(e=>e.prepare(t[e.key],a));for(let t of e.series.list())a.get(t.pane)||n(`The state has no pane "${t.pane}", which series "${t.id}" is drawn in.`);e.values.verify((e,t)=>{o.find(t=>t.values?.kind===e.kind)?.values?.check(e,t)}),d(`view.barSpacing`,t.view.barSpacing,{min:0,exclusiveMin:!0}),d(`view.offset`,t.view.offset),e.applyOptions({mainSeries:{type:t.mainSeries.type,source:t.mainSeries.source}}),t.transform!==void 0&&e.setTransform(t.transform),e.panes.adopt(a),t.panes.forEach(t=>{e.panes.require(t.id).scale.restoreManualRange(t.range),t.scales?.forEach(n=>{e.panes.ensureScale(t.id,n.id).scale.restoreManualRange(n.range)})}),o.forEach(e=>{e.apply()}),e.timeScale.restore(t.view),e.values.reset(),e.objects.prune(),e.invalidate()}function Va(e){return e&&{type:e.type,params:e.params,input:e.input}}let Ha=/* @__PURE__ */ new WeakMap;function Ua(e){let t=Object.freeze({name:e.name});return Ha.set(t,e),t}function Wa(e){h(`module definition`,e);let{name:t,options:r}=e;return(typeof t!=`string`||t===``)&&n(`createModule() needs the name of the module.`),typeof e.install!=`function`&&n(`The module "${t}" needs an install() function.`),r!==void 0&&(_(`The options of the module "${t}"`,r,[`key`,`defaults`,`validate`]),p(`The options key of the module "${t}"`,r.key),(typeof r.defaults!=`function`||typeof r.validate!=`function`)&&n(`The options of the module "${t}" need defaults() and validate().`)),Ua({name:t,...r===void 0?{}:{options:r},extend:(t,n)=>e.install(t,n)??{}})}function Ga(e){let t=e;Array.isArray(t)||n(`options.modules must be an array of modules, such as [indicators(allIndicators)].`);let r=/* @__PURE__ */ new Set;return e.map((e,t)=>{let i=Ha.get(e)??n(`options.modules[${t}] is not a module, such as indicators(allIndicators).`);return r.has(i.name)&&n(`The ${i.name} module is given twice.`),r.add(i.name),i})}let Ka=g({time:!0,price:!0,pane:!0});function qa(e,t,n,r=[]){for(let[i,a]of Object.entries(Object.getOwnPropertyDescriptors(t))){let o=a.get?.bind(t),s=a.value;if(!r.includes(i)){if(o)Object.defineProperty(t,i,{...a,get:()=>e.run(o)});else if(typeof s==`function`){let n=s;Object.defineProperty(t,i,{...a,value:(...r)=>e.run(()=>n.apply(t,r))})}else n&&ye(s)&&qa(e,s,!1)}}return t}function Ja(e,t){let r=t.options,i=e.events();return{options:()=>r?e.options[r.key]:n(`The ${t.name} module has no options.`),emit:(e,t)=>{i.emit(e,t)},keepState:r=>{_(`The state part of the ${t.name} module`,r,[`key`,`save`,`read`,`load`]);let{key:i}=r;p(`The state key of the ${t.name} module`,i),(Ra.includes(i)||e.stateParts.some(e=>e.key===i))&&n(`The ${t.name} module keeps "${i}" of the state, which the chart keeps already.`),e.stateParts.push({key:i,save:()=>r.save(),prepare:e=>{let t=e===void 0?null:r.read(e,`state.${i}`);return{apply:()=>{r.load(t)}}}})}}}function Ya(e,t){let r=La(e),{modules:i=[],...o}=t??{},s=Ga(i),c=new Ia(r,e,o,s,()=>f),l=/* @__PURE__ */ new Map,f={element:c.surface.root,options:()=>c.options,applyOptions:e=>{c.run(()=>{c.applyOptions(e)})},layout:()=>u(c.frame().layout),resize:(e,t)=>{d(`width`,e,{min:0}),d(`height`,t,{min:0}),c.run(()=>{c.resize(e,t)})},batch:e=>{c.run(e)},on:(e,t)=>c.bus.on(e,t),data:Ee(c),transforms:Mt(c),timeScale:At(c),priceScale:(e=b,t=fe)=>{c.panes.require(e),p(`scale id`,t);let n=`${e}\u0000${t}`,r=l.get(n);return r||(r=qa(c,De(c,e,t),!1),l.set(n,r)),r},panes:Oe(c),series:Et(c),crosshair:{get:()=>{let e=c.crosshair;return e&&{...e,x:e.x+c.frame().layout.leftAxisWidth}},set:e=>{c.run(()=>{if(e===null){c.setExternalCrosshair(null);return}_(`crosshair position`,e,Ka);let{time:t,price:n,pane:r=b}=e;c.panes.require(r),c.setExternalCrosshair({time:a(t),price:n===void 0?null:d(`price`,n),paneId:r})})}},modules:()=>s.map(e=>e.name),select:e=>{c.run(()=>{e!==null&&(m(`selection.kind`,e.kind,c.objects.kinds()),p(`selection.id`,e.id),c.objects.exists(e)||n(`There is no ${e.kind} with id "${e.id}".`)),c.select(e)})},selection:()=>c.objects.selection,saveState:()=>za(c),loadState:e=>{c.run(()=>{Ba(c,e)})},screenshot:()=>c.run(()=>(c.flush(),c.surface.composite())),plugins:{add:e=>{c.run(()=>{c.plugins.add(e)})},remove:e=>{c.run(()=>{c.plugins.remove(e)})},get:e=>c.plugins.get(e),list:()=>c.plugins.list()},destroy:()=>{c.destroy()}};Object.assign(f,c.moduleApis),qa(c,f,!0,[`destroy`]);try{for(let e of s)for(let[t,r]of Object.entries(e.extend?.(f,Ja(c,e))??{}))Object.hasOwn(f,t)&&n(`The ${e.name} module adds chart.${t}, which the chart has already.`),Object.assign(f,{[t]:r});c.seriesTypes.require(c.options.mainSeries.type)}catch(e){throw c.destroy(),e}return f}function Xa(e,t,r,i,a){v(e,t);let o=t.map((t,n)=>({input:t,settings:a(t,`${e}[${n}]`)})),s=/* @__PURE__ */ new Set;o.forEach(({input:t},r)=>{if(t.id!==void 0){let i=p(`${e}[${r}].id`,t.id);s.has(i)&&n(`${e} contains the id "${i}" twice.`),s.add(i)}}),s.forEach(e=>{r.note(e)});let c=/* @__PURE__ */ new Map;return o.forEach(({input:e,settings:t})=>{let n=e.id??r.next(i);r.note(n),c.set(n,{id:n,...t})}),c}function Za(e,t){let n=t=>e.run(()=>{let n=t();return e.objects.prune(),e.invalidateLayers(`objects`),n});return{set:e=>{n(()=>{t.set(e)})},add:e=>n(()=>t.add(e)),update:(e,r)=>{n(()=>{t.update(e,r)})},remove:e=>{n(()=>{t.remove(e)})},clear:()=>{n(()=>{t.set([])})},get:e=>t.get(e),list:()=>t.list()}}function Qa(e,t){return{context:()=>e.objectContext(),repaint:()=>{e.invalidateLayers(`objects`)},formatValue:(t,n)=>Rn(e,t,n),dragged:t}}let $a={button:50,handle:40,label:30,line:20,body:10};function eo(e,t){return e.timeScale.indexToX(e.bars.logicalIndexOf(t))}function j(e,t){return e.panes.find(e=>e.id===t)}function to(e,t,n){let r=e.yToValue(n);if(t.kind===`decimal`){let e=10**t.precision;return Math.round(r*e)/e}let i=Math.abs(e.yToValue(n+1)-r);if(!Number.isFinite(i)||i===0)return r;let a=Math.floor(Math.log10(i));if(a<0){let e=10**-a;return Math.round(r*e)/e}let o=10**a;return Math.round(r/o)*o}let no=g({id:!0,text:!0,icon:!0,width:!0}),ro=/^\s*[Mm][\d\s,.eE+\-MmLlHhVvCcSsQqTtAaZz]*$/;function io(e,t){if(e===void 0)return[];v(t,e);let r=/* @__PURE__ */ new Set;return e.map((e,i)=>{let a=`${t}[${i}]`;return _(a,e,no),p(`${a}.id`,e.id),r.has(e.id)&&n(`${t} contains the button id "${e.id}" twice.`),r.add(e.id),e.text===void 0&&e.icon===void 0&&n(`${a} needs a text or an icon.`),e.text!==void 0&&typeof e.text!=`string`&&n(`${a}.text must be a string.`),e.icon!==void 0&&(typeof e.icon!=`string`||!ro.test(e.icon))&&n(`${a}.icon must be SVG path data starting with a move command, e.g. "M6 6L18 18".`),e.width!==void 0&&d(`${a}.width`,e.width,{min:8,max:200}),{...e}})}function ao(e,t,n){let r=n/2,i=e.map(e=>({view:e,center:e.y})),a=-1/0;for(let e of i)e.center=Math.max(e.view.y,a+2+r),a=e.center+r;let o=t+2;for(let e of[...i].reverse())e.view.y<=t&&(e.center=Math.min(e.center,o-2-r),o=e.center-r);return i.map(e=>e.center)}function oo(e,t,n,r,i){let a=r+8,o=[...e].filter(e=>Number.isFinite(e.y)).sort((e,t)=>e.y-t.y),s=ao(o,n,a);return o.map((e,n)=>{let o=e.text?i(e.text,r)+12:0,c=e.buttons.map(e=>e.width??(e.icon?a:i(e.text??``,r)+12)),l=o+c.reduce((e,t)=>e+t,0),u=s[n]??e.y,d=t-8-l,f=u-a/2,p=d+o,m=e.buttons.map((e,t)=>{let n=c[t]??a,r={x:p,y:f,width:n,height:a};return p+=n,{button:e,rect:r}});return{view:e,labelY:u,label:{x:d,y:f,width:l,height:a},textWidth:o,buttons:m}})}function so(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function co(e,t,n){for(let n of e)for(let{button:e,rect:r}of n.buttons)if(so(r,t))return{id:n.view.id,part:`button:${e.id}`,priority:$a.button,distance:0};for(let n of e)if(so(n.label,t))return{id:n.view.id,part:`label`,priority:$a.label,distance:0};let r=null;for(let i of e){let e=Math.abs(t.y-i.view.y);e<=n&&(!r||e<r.distance)&&(r={id:i.view.id,part:`line`,priority:$a.line,distance:e})}return r}function lo(e,t,n,r,i,a){e.font=E(i.fontSize,i.fontFamily),e.textBaseline=`middle`;for(let o of t){let{view:t,label:s}=o,c=w(n.y+t.y,1,i.pixelRatio),l=t.emphasized?2:1;e.beginPath(),e.moveTo(n.x,c),e.lineTo(n.x+n.width,c),C(e,t.color,l,t.lineStyle),e.stroke();let u=n.y+s.y,d=n.x+s.x;o.labelY!==t.y&&(e.beginPath(),e.moveTo(d+s.width/2,c),e.lineTo(d+s.width/2,u),C(e,t.color,1),e.stroke()),e.fillStyle=t.color,e.beginPath(),e.roundRect(d,u,s.width,s.height,3),e.fill(),t.text&&(e.fillStyle=i.textColor,e.textAlign=`center`,e.fillText(t.text,d+o.textWidth/2,u+s.height/2+.5));for(let{button:t,rect:r}of o.buttons){let o=n.x+r.x;if(e.fillStyle=S(`#000000`,.18),e.fillRect(o,u,r.width,r.height),e.fillStyle=S(i.textColor,.35),e.fillRect(o,u+3,1,r.height-6),t.icon){let n=r.height-8;e.save(),e.translate(o+(r.width-n)/2,u+4),e.scale(n/24,n/24),e.strokeStyle=i.textColor,e.lineWidth=2.2,e.lineCap=`round`,e.lineJoin=`round`,e.setLineDash([]),e.stroke(a.get(t.icon)),e.restore()}else t.text&&(e.fillStyle=i.textColor,e.textAlign=`center`,e.fillText(t.text,o+r.width/2,u+r.height/2+.5))}if(i.showAxis&&t.y>=0&&t.y<=n.height){let a=i.fontSize+8;e.fillStyle=t.color,e.beginPath(),e.roundRect(r.x+1,n.y+t.y-a/2,r.width-2,a,2),e.fill(),e.fillStyle=i.textColor,e.textAlign=`left`,e.fillText(t.axisText,r.x+8,n.y+t.y+.5)}}}let uo=[`cross`,`cross-up`,`cross-down`,`above`,`below`,`enter-channel`,`exit-channel`,`inside-channel`,`outside-channel`],fo=[`once`,`once-per-bar`,`once-per-bar-close`,`every-time`],po={kind:`price`,field:`close`},mo=g({id:!0,source:!0,trigger:!0,value:!0,frequency:!0,enabled:!0,label:!0,color:!0,lineStyle:!0,draggable:!0,visible:!0,buttons:!0}),ho={price:g({kind:!0,field:!0}),indicator:g({kind:!0,id:!0,key:!0}),series:g({kind:!0,id:!0}),drawing:g({kind:!0,id:!0,level:!0})};function go(e,t,r){switch(h(t,e),Object.hasOwn(ho,e.kind)&&_(t,e,ho[e.kind]),e.kind){case`price`:return{kind:`price`,field:e.field===void 0?`close`:m(`${t}.field`,e.field,Yt)};case`indicator`:return p(`${t}.id`,e.id),e.key!==void 0&&p(`${t}.key`,e.key),r.check(e,t),{kind:`indicator`,id:e.id,...e.key===void 0?{}:{key:e.key}};case`series`:return p(`${t}.id`,e.id),r.check(e,t),{kind:`series`,id:e.id};case`drawing`:return p(`${t}.id`,e.id),e.level!==void 0&&p(`${t}.level`,e.level),r.check(e,t),{kind:`drawing`,id:e.id,...e.level===void 0?{}:{level:e.level}};default:return n(`${t}.kind must be "price", "indicator", "series" or "drawing".`)}}function _o(e){return Array.isArray(e)?e:[e]}function vo(e,t,n){return typeof e==`number`?d(t,e):go(e,t,n)}function yo(e,t,r,i){let a=t.endsWith(`-channel`);return(Array.isArray(e)!==a||a&&e.length!==2)&&n(`${i} of a "${t}" alert must be ${a?`a channel's two bounds`:`one value`}.`),a?e.map((e,t)=>vo(e,`${i}[${t}]`,r)):vo(e,i,r)}function bo(e,t,n=`alert`){_(n,e,mo),e.label!==void 0&&p(`${n}.label`,e.label);let r=m(`${n}.trigger`,e.trigger,uo);return{source:go(e.source??po,`${n}.source`,t),trigger:r,value:yo(e.value,r,t,`${n}.value`),frequency:e.frequency===void 0?`once`:m(`${n}.frequency`,e.frequency,fo),enabled:e.enabled===void 0||f(`${n}.enabled`,e.enabled),label:e.label??null,color:e.color===void 0?null:x(`${n}.color`,e.color),lineStyle:e.lineStyle===void 0?`solid`:m(`${n}.lineStyle`,e.lineStyle,cn),draggable:e.draggable===void 0||f(`${n}.draggable`,e.draggable),visible:e.visible===void 0||f(`${n}.visible`,e.visible),buttons:io(e.buttons,`${n}.buttons`)}}function xo(e){return{source:e.source,trigger:e.trigger,value:e.value,frequency:e.frequency,enabled:e.enabled,lineStyle:e.lineStyle,draggable:e.draggable,visible:e.visible,buttons:e.buttons.map(e=>({...e})),...e.label===null?{}:{label:e.label},...e.color===null?{}:{color:e.color}}}let So=[`above`,`below`,`inside-channel`,`outside-channel`];function Co(e,t){let n=e=>JSON.stringify([e.source,e.trigger,e.value,e.frequency,e.enabled]);return n(e)===n(t)}function wo(e){return e.status===`active`}function To(e){return[Math.min(...e),Math.max(...e)]}function Eo(e,t,n,r){return e<=t&&n>r}function Do(e,t,n,r){return e>=t&&n<r}function Oo(e,[t,n]){return e>t&&e<n}function ko(e,[t,n]){return e<t||e>n}function Ao(e,t,n,r,i){let[a,o]=n,[s,c]=i;switch(e){case`above`:return r>c;case`below`:return r<s;case`cross-up`:return Eo(t,o,r,c);case`cross-down`:return Do(t,a,r,s);case`cross`:return Eo(t,o,r,c)||Do(t,a,r,s);case`enter-channel`:return Oo(r,i)&&!Oo(t,n);case`exit-channel`:return ko(r,i)&&!ko(t,n);case`inside-channel`:return Oo(r,i);case`outside-channel`:return ko(r,i)}}function jo(e,t,n,r,[i,a]){return e===`enter-channel`?t<=n?i:a:e===`inside-channel`?r-i<=a-r?i:a:r<i?i:a}var Mo=class{host;states=/* @__PURE__ */ new Map;ids=new de(e=>this.states.has(e));constructor(e){this.host=e}all(){return this.states.values()}config(e){return this.states.get(e)?.config}setLevel(e,t,n){let r=this.require(e),i=r.config.value;r.config={...r.config,value:t===null||!Array.isArray(i)?n:_o(i).map((e,r)=>r===t?n:e)},this.baseline(r)}settle(e){this.baseline(this.require(e))}has(e){return this.states.has(e)}list(){return[...this.states.values()].map(e=>this.info(e))}get(e){let t=this.states.get(e);return t?this.info(t):null}uses(e,t){return[...this.states.values()].flatMap(({config:n})=>[n.source,..._o(n.value)].flatMap(r=>typeof r!=`number`&&r.kind===e&&`id`in r&&r.id===t?[{user:n.id,source:r}]:[]))}verify(e){this.states.forEach(({config:t})=>{[t.source,..._o(t.value)].forEach(n=>{typeof n!=`number`&&e(n,`alert "${t.id}"`)})})}rebaseline(){this.states.forEach(e=>{this.baseline(e)})}set(e){let t=Xa(`alerts`,e,this.ids,`alert`,(e,t)=>bo(e,this.host.reader,t)),n=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let r=this.states.get(t);r&&Co(r.config,e)?(r.config=e,n.set(t,r)):n.set(t,this.createState(e))}),this.states=n}add(e){let t=bo(e,this.host.reader),r=e.id===void 0?this.ids.next(`alert`):p(`alert.id`,e.id);return this.states.has(r)&&n(`An alert with id "${r}" already exists.`),this.states.set(r,this.createState({id:r,...t})),this.ids.note(r),r}update(e,t){let n=this.require(e),r={id:e,...bo({...xo(n.config),...t},this.host.reader)},i=!Co(n.config,r);n.config=r,r.enabled?(i||n.status===`disabled`)&&(n.status=`active`):n.status=`disabled`,this.baseline(n)}remove(e){this.require(e),this.states.delete(e)}rearm(e){let t=this.require(e);t.config.enabled&&(t.status=`active`,t.triggeredAt=null,this.baseline(t))}require(e){return this.states.get(e)??n(`Unknown alert "${e}".`)}info(e){return{...e.config,status:e.status,triggeredAt:e.triggeredAt}}createState(e){let t={config:e,status:e.enabled?`active`:`disabled`,triggeredAt:null,last:NaN,lastThresholds:[],lastIndex:-1,closedIndex:-1};return this.baseline(t),t}thresholds(e,t){return _o(e.value).map(e=>typeof e==`number`?e:this.host.reader.read(e,t))}baseline(e){let{config:t}=e,n=this.host.bars.length-1,r=this.host.settled()-1,i=t.frequency===`once-per-bar-close`?r:n;e.closedIndex=r,e.lastIndex=i,e.last=i>=0?this.host.reader.read(t.source,i):NaN,e.lastThresholds=i>=0?this.thresholds(t,i):[]}evaluate(e){for(let t of this.states.values()){if(e.kind===`reset`||t.status!==`active`){this.baseline(t);continue}let n=this.host.bars.length-1;if(t.config.frequency===`once-per-bar-close`){let e=this.host.settled();for(let n=t.closedIndex+1;n<e&&wo(t);n+=1)this.step(t,n),t.closedIndex=n}else if(n>=0){let r=Math.min(Math.max(e.from,t.lastIndex),n);for(let e=r;e<=n&&wo(t);e+=1)this.step(t,e)}}}step(e,t){let{config:n}=e,r=this.host.reader.read(n.source,t),i=this.thresholds(n,t),a=this.host.bars.time(t),o=(t,n)=>typeof t!=`number`&&this.host.reader.movable(t)&&e.lastIndex>=0?this.host.reader.read(t,e.lastIndex):n,s=o(n.source,e.last),c=_o(n.value).map((t,n)=>o(t,e.lastThresholds[n]??NaN)),l=So.includes(n.trigger)?[r,...i]:[r,...i,s,...c],u=To(i),d=To(c),f=l.every(Number.isFinite)&&Ao(n.trigger,s,d,r,u)&&(n.frequency!==`once-per-bar`||e.triggeredAt!==a);e.last=r,e.lastThresholds=i,e.lastIndex=t,f&&(e.triggeredAt=a,n.frequency===`once`&&(e.status=`triggered`),this.host.triggered({id:n.id,time:a,value:r,threshold:jo(n.trigger,s,d[0],r,u),trigger:n.trigger}))}};function No(e){let{id:t,value:n}=e;return typeof n==`number`?[{id:t,bound:null,value:n}]:Array.isArray(n)?_o(n).flatMap((e,n)=>typeof e==`number`?[{id:t,bound:n,value:e}]:[]):[]}function Po(e,t){return t.bound===null||e.startsWith(`button:`)?e:`${e}:${t.bound}`}function Fo(e){let t=/^(?:line|label):(\d)$/.exec(e)?.[1];return t===void 0?null:Number(t)}var Io=class{host;kind=`alert`;book;icons=new Ei;constructor(e,t){this.host=t,this.book=new Mo({bars:e,reader:t.reader,settled:()=>t.settled(),triggered:e=>{t.triggered(e)}})}has(e){return this.book.has(e)}list(){return this.book.list()}get(e){return this.book.get(e)}uses(e,t){return this.book.uses(e,t)}verify(e){this.book.verify(e)}rebaseline(){this.book.rebaseline()}set(e){this.book.set(e)}add(e){return this.book.add(e)}update(e,t){this.book.update(e,t)}remove(e){this.book.remove(e)}rearm(e){this.book.rearm(e)}evaluate(e){this.book.evaluate(e)}layouts(e){let t=/* @__PURE__ */ new Map,n=[],{theme:r}=e.options;for(let{config:i,status:a}of this.book.all()){let o=i.visible?No(i):[],s=o.length>0?this.host.reader.paneOf(i.source):null,c=s===null?null:j(e.frame,s),l=s===null?null:e.scaleOf(s,this.host.reader.scaleOf(i.source));if(s===null||!c||!l)continue;let u=i.color??r.alert,d=t.get(s)??[];for(let t of o)d.push({id:String(n.length),y:l.valueToY(t.value),color:a===`active`?u:S(u,.45),text:i.label??``,axisText:this.host.formatValue({...c,scale:l},t.value),buttons:i.buttons,lineStyle:i.lineStyle,emphasized:e.selection?.kind===`alert`&&e.selection.id===i.id||e.hovered?.kind===`alert`&&e.hovered.id===i.id}),n.push(t);t.set(s,d)}return{panes:[...t.entries()].flatMap(([t,n])=>{let r=j(e.frame,t);return r?[{pane:r,layouts:oo(n,r.plot.width,r.plot.height,e.options.font.size,(t,n)=>e.measureText(t,E(n,e.options.font.family)))}]:[]}),lines:n}}hitTest(e,t){let{panes:n,lines:r}=this.layouts(e);for(let{pane:i,layouts:a}of n){if(t.y<i.plot.y||t.y>=i.plot.y+i.plot.height)continue;let n=co(a,{x:t.x,y:t.y-i.plot.y},e.options.interaction.hitTolerance),o=n?r[Number(n.id)]:void 0,s=o?this.book.config(o.id):void 0;if(n&&o&&s){let e=s.draggable&&!n.part.startsWith(`button:`);return{target:{kind:`alert`,id:o.id,part:Po(n.part,o),cursor:e?`ns-resize`:`pointer`,draggable:e},priority:n.priority,distance:n.distance}}}return null}beginDrag(e,t){let n=this.book.config(t.id),r=Fo(t.part),i=n?No(n).find(e=>e.bound===r):void 0;if(!n||!i||!n.draggable)return null;let{id:a}=n,o=this.host.reader.paneOf(n.source),s=this.host.reader.scaleOf(n.source);if(!j(e.frame,o)||!e.scaleOf(o,s))return null;let c=i.value,l=c,u=(e,t)=>{this.host.dragged({id:a,phase:e,price:t,initialPrice:c,bound:r})},d=e=>{this.book.has(a)&&this.book.setLevel(a,r,e),this.host.repaint()};return u(`start`,l),{move:e=>{let t=j(this.host.context().frame,o);if(!t||!this.book.has(a))return;let n=this.host.context().scaleOf(o,s),r=n?to(n,t.format,e.y-t.plot.y):NaN;Number.isFinite(r)&&r!==l&&(l=r,d(l),u(`move`,l))},end:()=>{this.book.has(a)&&this.book.settle(a),u(`end`,l)},cancel:()=>{d(c),u(`cancel`,c)}}}paint(e){let{ctx:t}=e;for(let{pane:n,layouts:r}of this.layouts(e).panes)t.save(),t.beginPath(),t.rect(0,n.plot.y,e.frame.layout.width,n.plot.height),t.clip(),lo(t,r,n.plot,n.axis,{fontSize:e.options.font.size,fontFamily:e.options.font.family,pixelRatio:e.pixelRatio,textColor:`#ffffff`,showAxis:e.options.priceScale.visible},this.icons),t.restore()}};function Lo(){return Ua({name:`alerts`,install:e=>{let t=e.events(),n=new Io(e.bars,{...Qa(e,e=>{t.emit(`alertDrag`,e)}),reader:e.values,settled:()=>e.market.settled(),triggered:n=>{e.invalidateLayers(`objects`),t.emit(`alertTrigger`,{...n,replay:e.replaying})}});return e.objects.add(n,30),e.values.use({noun:`alert`,uses:(e,t)=>n.uses(e,t),reset:()=>{n.rebaseline()},verify:e=>{n.verify(e)}}),e.hooks.barsChanged.push(e=>{n.evaluate(e)}),{alerts:{...Za(e,n),rearm:t=>{e.run(()=>{n.rearm(t),e.invalidateLayers(`objects`)})}}}}})}function Ro(e,t){return`Trades have no true range to size the "${e}" transform by: give ${t}.`}function zo(e,t,r,i){let a=[t,`percentage`,`atrLength`].filter(e=>r[e]!==void 0);return a.length>1&&n(`The "${e}" transform takes one of params.${t}, params.percentage and params.atrLength, received ${a.map(e=>`params.${e}`).join(` and `)}.`),r[t]===void 0?r.percentage===void 0?(i===`trades`&&n(Ro(e,`params.${t} or params.percentage`)),{kind:`atr`,length:r.atrLength===void 0?14:d(`params.atrLength`,r.atrLength,{min:1,max:1e3,integer:!0})}):{kind:`percentage`,percentage:d(`params.percentage`,r.percentage,{min:0,exclusiveMin:!0,max:100})}:{kind:`fixed`,size:d(`params.${t}`,r[t],{min:0,exclusiveMin:!0})}}function Bo(e){let t=10**Math.floor(Math.log10(e));return Number((Math.round(2*e/t)*t/2).toPrecision(12))}function Vo(e,t,n){return Number.isNaN(n)?e-t:Math.max(e,n)-Math.min(t,n)}function Ho(e,t,n,r){return t<r?(e*t+n)/(t+1):(e*(r-1)+n)/r}function Uo(e,t,n=e.length){let r=0;for(let i=0;i<n;i+=1){let n=i>0?e.close(i-1):NaN,a=Vo(e.high(i),e.low(i),n);r=Ho(r,i,a,t)}return n>0?r:NaN}function Wo(e,t){let n=Math.abs(t)*e/100;return n>0?Bo(n):NaN}function Go(e,t){switch(e.kind){case`fixed`:return e.size;case`percentage`:return t.length>1?Wo(e.percentage,t.close(t.length-2)):NaN;case`atr`:{let n=t.length-1,r=n>=e.length?Uo(t,e.length,n):0;return r>0?Bo(r):NaN}}}var Ko=class e{rule;build;stream;waiting;average;close;constructor(e,t,n=null,r=[],i=0,a=NaN){this.rule=e,this.build=t,this.stream=n,this.waiting=r,this.average=i,this.close=a}next(e){if(this.stream)return this.stream.next(e,null);let{rule:t,waiting:n}=this,r=n.length,i=t.kind===`percentage`?Wo(t.percentage,this.close):r>=t.length&&this.average>0?Bo(this.average):NaN;if(t.kind===`atr`){let n=Vo(e.high,e.low,this.close);this.average=Ho(this.average,r,n,t.length)}if(this.close=e.close,n.push(e),Number.isNaN(i))return[];let a=this.build(i);return this.stream=a,n.splice(0).flatMap(e=>a.next(e,null))}current(){return this.stream?.current()??null}clone(){return new e(this.rule,this.build,this.stream?.clone()??null,[...this.waiting],this.average,this.close)}resolved(){return this.stream?.resolved?.()??null}};function qo(e,t,n){let r=Go(e,t);return e.kind===`fixed`||!Number.isNaN(r)?n(r):new Ko(e,n)}let Jo=1e4;function Yo(e,t,r){r/t>Jo&&n(`The "${e}" size ${t} is too small for these prices: one bar would make more than ${Jo} bars.`)}function Xo(e,t,r){for(let i of Object.keys(t))r.includes(i)||n(`The "${e}" transform has no parameter "${i}".`)}var Zo=class e{previous;forming;constructor(e=null,t=null){this.previous=e,this.forming=t}next(e){let t=this.forming;this.previous=t??this.previous;let n=(e.open+e.high+e.low+e.close)/4,r=this.previous?(this.previous.open+this.previous.close)/2:(e.open+e.close)/2;return this.forming={time:e.time,open:r,high:Math.max(e.high,r,n),low:Math.min(e.low,r,n),close:n,volume:e.volume},t?[t]:[]}current(){return this.forming}clone(){return new e(this.previous,this.forming)}};let Qo={type:`heikin-ashi`,name:`Heikin-Ashi`,keepsTime:!0,create:e=>(Xo(`heikin-ashi`,e,[]),new Zo)};var $o=class e{range;state;constructor(e,t){this.range=e,this.state=t}next(e){let t=this.state,n=this.range,r=[],i=e.close>=e.open?[e.open,e.low,e.high,e.close]:[e.open,e.high,e.low,e.close],a=t=>({time:e.time,open:t,high:t,low:t,close:t,volume:0}),o=t.forming?.open??e.open;Yo(`range`,n,Math.max(e.high-o,o-e.low));for(let e of i){let i=t.forming??a(e);for(;e-i.low>n;){let e=i.low+n;r.push({...i,high:e,close:e}),i=a(e)}for(;i.high-e>n;){let e=i.high-n;r.push({...i,low:e,close:e}),i=a(e)}i.high=Math.max(i.high,e),i.low=Math.min(i.low,e),i.close=e,t.forming=i}return t.forming&&(t.forming.volume+=e.volume),r}current(){return this.state.forming?{...this.state.forming}:null}clone(){return new e(this.range,{forming:this.state.forming?{...this.state.forming}:null})}resolved(){return{range:this.range}}};let es={type:`range`,name:`Range`,keepsTime:!1,create:(e,t,r)=>(Xo(`range`,e,[`range`]),e.range===void 0&&r===`trades`&&n(Ro(`range`,`params.range`)),qo(e.range===void 0?{kind:`atr`,length:14}:{kind:`fixed`,size:d(`params.range`,e.range,{min:Number.MIN_VALUE})},t,e=>new $o(e,{forming:null})))};var ts=class e{count;state;constructor(e,t){this.count=e,this.state=t}next(e){let t=this.state;if(Number.isNaN(t.time)&&(t.time=e.time),t.volume+=e.volume,Number.isNaN(t.reference))return t.reference=e.close,[];let n=t.lines.map(e=>Math.max(e.open,e.close)),r=t.lines.map(e=>Math.min(e.open,e.close)),i=t.lines.length>0?Math.max(...n):t.reference,a=t.lines.length>0?Math.min(...r):t.reference,o=t.lines.length-1,s;if(e.close>i)s=n[o]??t.reference;else if(e.close<a)s=r[o]??t.reference;else return[];let c={time:t.time,open:s,high:Math.max(s,e.close),low:Math.min(s,e.close),close:e.close,volume:t.volume};return t.lines.push({open:s,close:e.close}),t.lines.length>this.count&&t.lines.shift(),t.time=NaN,t.volume=0,[c]}current(){return null}clone(){return new e(this.count,{...this.state,lines:[...this.state.lines]})}};let ns={type:`line-break`,name:`Line break`,keepsTime:!1,create:e=>(Xo(`line-break`,e,[`lines`]),new ts(e.lines===void 0?3:d(`params.lines`,e.lines,{min:1,max:100,integer:!0}),{lines:[],reference:NaN,time:NaN,volume:0}))};function rs(e,t,r,i){return Xo(e,r,[t]),r[t]===void 0&&n(`The "${e}" transform needs params.${t}, the ${i} of each bar.`),d(`params.${t}`,r[t],{min:0,exclusiveMin:!0})}var is=class e{measure;size;forming;amount;constructor(e,t,n=null,r=0){this.measure=e,this.size=t,this.forming=n,this.amount=r}next(e){let t=this.forming,n=t?{time:t.time,open:t.open,high:Math.max(t.high,e.high),low:Math.min(t.low,e.low),close:e.close,volume:t.volume+e.volume}:e,r=this.amount+this.measure(e);return r>=this.size*(1-1e-9)?(this.forming=null,this.amount=0,[n]):(this.forming=n,this.amount=r,[])}current(){return this.forming}clone(){return new e(this.measure,this.size,this.forming,this.amount)}};let as={type:`tick`,name:`Tick`,keepsTime:!1,create:e=>(Xo(`tick`,e,[`count`]),e.count===void 0&&n(`The "tick" transform needs params.count, the trades of each bar.`),new is(()=>1,d(`params.count`,e.count,{min:1,integer:!0})))},os={type:`volume`,name:`Volume`,keepsTime:!1,create:e=>new is(e=>e.volume,rs(`volume`,`volume`,e,`volume`))},ss={type:`turnover`,name:`Turnover`,keepsTime:!1,create:e=>new is(e=>(e.high+e.low+e.close)/3*e.volume,rs(`turnover`,`turnover`,e,`turnover`))},cs=e=>({time:e.time,open:e.open,high:Math.max(e.open,e.close),low:Math.min(e.open,e.close),close:e.close,volume:e.volume});var ls=class e{reversal;state;constructor(e,t){this.reversal=e,this.state=t}next(e){let t=this.state;if(Number.isNaN(t.start))return t.start=e.close,t.startTime=e.time,t.pending=e.volume,[];let n=this.reversal*(1-1e-9),r=t.line;if(!r)return t.pending+=e.volume,Math.abs(e.close-t.start)>=n&&(t.line={time:t.startTime,open:t.start,close:e.close,volume:t.pending},t.pending=0),[];let i=r.close>r.open;return(i?e.close>r.close:e.close<r.close)?(r.close=e.close,r.volume+=t.pending+e.volume,t.pending=0,[]):(i?r.close-e.close:e.close-r.close)>=n?(t.line={time:e.time,open:r.close,close:e.close,volume:t.pending+e.volume},t.pending=0,[cs(r)]):(t.pending+=e.volume,[])}current(){return this.state.line?cs(this.state.line):null}clone(){let t=this.state.line;return new e(this.reversal,{...this.state,line:t?{...t}:null})}resolved(){return{reversal:this.reversal}}};let us={type:`kagi`,name:`Kagi`,keepsTime:!1,create:(e,t,n)=>(Xo(`kagi`,e,[`reversal`,`percentage`,`atrLength`]),qo(zo(`kagi`,`reversal`,e,n),t,e=>new ls(e,{start:NaN,startTime:NaN,line:null,pending:0})))};function ds(e,t){if(t<2)return null;let n=e.close(t),r=e.close(t-2);return n>e.open(t)?n>r||null:n<r?!1:null}function fs(e,t){for(let n=t-1;n>=2;--n){let t=ds(e,n);if(t!==null)return t}return e.close(0)>e.open(0)}function ps(e){let{ctx:t,points:r,style:i,pixelRatio:a,valueToY:o,first:s}=e,c=e.bars??n(`Kagi lines are OHLC bars.`),l=[],u=null,d=null,f=(e,t,n)=>{let r=n?i.upWidth:i.downWidth;return[w(e,r,a),w(t,r,a)]},p=(e,t,n)=>{if(u?.yang===n)u.points.push(...f(e,t,n));else{let r=d??[e,t];u={yang:n,points:[...f(r[0],r[1],n),...f(e,t,n)]},l.push(u)}d=[e,t]},m=fs(c,s);for(let e=0;e<r.count;e+=1){let t=s+e,n=r.x(e),i=ds(c,t);p(n,r.open(e),m),i!==null&&i!==m&&(p(n,o(c.close(t-2)),m),m=i),p(n,r.close(e),m)}t.lineJoin=`miter`,t.lineCap=`butt`,t.setLineDash([]);for(let e of[!0,!1]){t.beginPath();for(let n of l)if(n.yang===e){t.moveTo(n.points[0]??0,n.points[1]??0);for(let e=2;e<n.points.length;e+=2)t.lineTo(n.points[e]??0,n.points[e+1]??0)}t.strokeStyle=e?i.upColor:i.downColor,t.lineWidth=e?i.upWidth:i.downWidth,t.stroke()}}let ms={type:`kagi`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,upWidth:2,downWidth:1}),paint:ps},hs=[`close`,`hl`],gs=1e-9;var _s=class e{settings;state;constructor(e,t){this.settings=e,this.state=t}next(e){let t=this.state,{box:n,reversal:r,source:i}=this.settings;Number.isNaN(t.start)&&(t.start=e.open,t.startTime=e.time);let a=Math.floor((i===`hl`?e.high:e.close)/n+gs),o=Math.ceil((i===`hl`?e.low:e.close)/n-gs),s=t.column;if(!s){t.pending+=e.volume;let i=t.start/n;return a>=Math.floor(i+gs)+r?t.column=this.open(t.startTime,!0,Math.floor(i+gs),a):o<=Math.ceil(i-gs)-r&&(t.column=this.open(t.startTime,!1,Math.ceil(i-gs),o)),[]}let c=s.rising?a>=s.last+1:o<=s.last-1,l=s.rising?o<=s.last-r:a>=s.last+r;if(c)return s.last=s.rising?a:o,s.volume+=t.pending+e.volume,t.pending=0,[];if(t.pending+=e.volume,!l)return[];let u=s.rising?o:a;if(this.settings.oneStepBack&&s.first===s.last)return s.rising=!s.rising,s.last=u,s.volume+=t.pending,t.pending=0,[];let d=s.rising?s.last-1:s.last+1;return t.column=this.open(e.time,!s.rising,d,u),[this.bar(s)]}current(){return this.state.column?this.bar(this.state.column):null}clone(){let t=this.state.column;return new e(this.settings,{...this.state,column:t?{...t}:null})}resolved(){let{box:e,reversal:t,source:n,oneStepBack:r}=this.settings;return{box:e,reversal:t,source:n,oneStepBack:r}}open(e,t,n,r){let i=this.state.pending;return this.state.pending=0,{time:e,rising:t,first:n,last:r,volume:i}}bar(e){let t=e=>Number((e*this.settings.box).toPrecision(12)),n=t(e.first),r=t(e.last);return{time:e.time,open:n,high:Math.max(n,r),low:Math.min(n,r),close:r,volume:e.volume}}};let vs={type:`point-figure`,name:`Point & figure`,keepsTime:!1,create:(e,t,n)=>{Xo(`point-figure`,e,[`box`,`percentage`,`atrLength`,`reversal`,`source`,`oneStepBack`]);let r=zo(`point-figure`,`box`,e,n),i={reversal:e.reversal===void 0?3:d(`params.reversal`,e.reversal,{min:1,max:100,integer:!0}),source:e.source===void 0?`close`:m(`params.source`,e.source,hs),oneStepBack:e.oneStepBack!==void 0&&f(`params.oneStepBack`,e.oneStepBack)};return qo(r,t,e=>new _s({...i,box:e},{start:NaN,startTime:NaN,column:null,pending:0}))}},ys=.12;function bs(e){let{ctx:t,points:r,style:i,pixelRatio:a,barSpacing:o,valueToY:s,first:c,transform:l}=e,u=e.bars??n(`Point & figure columns are OHLC bars.`),d=l?.box,f=i.box??(typeof d==`number`?d:NaN);if(!(f>0))return;let p=Math.max(1/a,o*i.widthRatio),m=[],h=[],g=[];for(let e=0;e<r.count;e+=1){let t=c+e,n=u.open(t),i=u.close(t),a=i>n,o=t>0?n>u.close(t-1):a,l=a?f:-f,d=Math.round(Math.abs(i-n)/f)+1,_=r.x(e);if(Math.abs(s(n+f/2)-s(n-f/2))<4||p<4)g.push({rising:a,x:_,top:s(Math.max(n,i)+f/2),bottom:s(Math.min(n,i)-f/2)});else for(let e=0;e<d;e+=1){let t=n+e*l,r=s(t+f/2),i=s(t-f/2);if(!Number.isFinite(r)||!Number.isFinite(i))continue;let c=p*ys,u=Math.abs(i-r)*ys;((e===0?o:a)?m:h).push(_-p/2+c,Math.min(r,i)+u,_+p/2-c,Math.max(r,i)-u)}}t.setLineDash([]),t.lineWidth=i.lineWidth,t.lineCap=`round`,t.beginPath();for(let e=0;e<m.length;e+=4){let[n=0,r=0,i=0,a=0]=m.slice(e,e+4);t.moveTo(n,r),t.lineTo(i,a),t.moveTo(n,a),t.lineTo(i,r)}t.strokeStyle=i.upColor,t.stroke(),t.beginPath();for(let e=0;e<h.length;e+=4){let[n=0,r=0,i=0,a=0]=h.slice(e,e+4),o=(i-n)/2;t.moveTo(i,(r+a)/2),t.ellipse(n+o,(r+a)/2,o,(a-r)/2,0,0,Math.PI*2)}t.strokeStyle=i.downColor,t.stroke();for(let e of g){let n=T(e.x-p/2,a);t.fillStyle=e.rising?i.upColor:i.downColor,t.fillRect(n,Math.min(e.top,e.bottom),Math.max(1/a,T(p,a)),Math.abs(e.bottom-e.top))}}let xs={type:`point-figure`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:1.5,widthRatio:.85,box:null}),paint:bs},Ss=[`close`,`ohlc`],Cs=1e-9;var ws=class e{settings;state;constructor(e,t){this.settings=e,this.state=t}next(e){let t=this.state,n=this.settings.source===`close`?[e.close]:e.close>=e.open?[e.open,e.low,e.high,e.close]:[e.open,e.high,e.low,e.close],r=[];for(let i of n)t.volume+=e.volume/n.length,t.high=Math.max(t.high,i),t.low=Math.min(t.low,i),this.reach(i,e.time,r);return r}current(){return null}clone(){return new e(this.settings,{...this.state})}resolved(){let{box:e,source:t,wicks:n}=this.settings;return{box:e,source:t,wicks:n}}reach(e,t,n){let r=this.state,i=this.settings.box,a=e/i;Number.isNaN(r.bottom)&&(r.bottom=Math.floor(a+Cs),r.top=r.bottom+1),Yo(`renko`,i,Math.max(e-r.top*i,r.bottom*i-e));let o=[];for(;a>=r.top+1-Cs;)o.push([r.top,r.top+1]),r.bottom=r.top,r.top+=1;for(;a<=r.bottom-1+Cs;)o.push([r.bottom,r.bottom-1]),r.top=r.bottom,--r.bottom;if(o.length===0)return;let s=e=>Number((e*i).toPrecision(12)),c=r.volume/o.length;o.forEach(([e,a],o)=>{let l=s(e),u=s(a),d=this.settings.wicks&&o===0,f=a>e;n.push({time:t,open:l,high:d&&!f&&r.high/i>e+1+Cs?r.high:Math.max(l,u),low:d&&f&&r.low/i<e-1-Cs?r.low:Math.min(l,u),close:u,volume:c})}),r.volume=0,r.high=-1/0,r.low=1/0}};let Ts={type:`renko`,name:`Renko`,keepsTime:!1,create:(e,t,n)=>{Xo(`renko`,e,[`box`,`percentage`,`atrLength`,`source`,`wicks`]);let r=zo(`renko`,`box`,e,n),i=e.source===void 0?`close`:m(`params.source`,e.source,Ss),a=e.wicks===void 0||f(`params.wicks`,e.wicks);return qo(r,t,e=>new ws({box:e,source:i,wicks:a},{bottom:NaN,top:NaN,volume:0,high:-1/0,low:1/0}))}};function Es(e){let{ctx:t,points:n,style:r,pixelRatio:i,barSpacing:a}=e,o=1/i,s=0;for(let e=0;e<n.count;e+=1)s=Math.max(s,n.volume(e)||0);let c=e=>Math.max(o,T(a*r.bodyRatio*(n.volume(e)||0)/(s||1),i));t.setLineDash([]);for(let e of Or(n)){let{up:a,color:s}=e,l=s??(a?r.upColor:r.downColor);if(r.wick){t.beginPath();for(let r of e.indices){let e=w(n.x(r),1,i);t.moveTo(e,n.high(r)),t.lineTo(e,n.low(r))}t.strokeStyle=s??(a?r.upWickColor:r.downWickColor),t.lineWidth=o,t.stroke()}t.beginPath();for(let r of e.indices){let e=c(r),a=n.open(r),s=n.close(r);t.rect(T(n.x(r)-e/2,i),T(Math.min(a,s),i),e,Math.max(o,T(Math.abs(s-a),i)))}t.fillStyle=l,t.fill(),r.border&&(t.save(),t.clip(),t.strokeStyle=s??(a?r.upBorderColor:r.downBorderColor),t.lineWidth=2*Math.max(o,T(1,i)),t.stroke(),t.restore())}}let Ds={type:`volume-candles`,input:`ohlc`,defaultStyle:e=>Ar(e.up,e.down),paint:Es};function Os(e=[]){v(`chartTypes()`,e);let t={transform:/* @__PURE__ */ new Set,"series type":/* @__PURE__ */ new Set},r=(e,r)=>{t[e].has(r)&&n(`chartTypes() is given the ${e} "${r}" twice.`),t[e].add(r)};return e.forEach((e,t)=>{h(`chartTypes()[${t}]`,e),!e.transform&&!e.series&&n(`chartTypes()[${t}] has neither a transform nor a series type.`),e.transform&&(jt(e.transform),r(`transform`,e.transform.type)),e.series&&(wt(e.series),r(`series type`,e.series.type))}),Ua({name:`chartTypes`,install:t=>{for(let{transform:n,series:r}of e)n&&t.market.transforms.register(n),r&&t.seriesTypes.register(r);return{}}})}let ks=[{transform:Qo},{transform:Ts},{transform:es},{transform:ns},{transform:us,series:ms},{transform:vs,series:xs},{transform:as},{transform:os},{transform:ss},{series:Ds}],As=[`left`,`center`,`right`],js=[`top`,`middle`,`bottom`],Ms=[`supermillennium`,`millennium`,`submillennium`,`grand-supercycle`,`supercycle`,`cycle`,`primary`,`intermediate`,`minor`,`minute`,`minuette`,`subminuette`,`micro`,`submicro`,`miniscule`],Ns=[`fill`,`bold`,`italic`,`extendLeft`,`extendRight`,`startArrow`,`endArrow`],Ps=[`color`,`lineWidth`,`lineStyle`],Fs=g({value:!0,color:!0,visible:!0});function Is(e,t){return _(e,t,Fs),{value:d(`${e}.value`,t.value),...t.color===void 0?{}:{color:x(`${e}.color`,t.color)},...t.visible===void 0?{}:{visible:f(`${e}.visible`,t.visible)}}}function Ls(e,t){return v(`style.${e}`,t),t.length>32&&n(`style.${e} can have at most 32 levels, received ${t.length}.`),t.map((t,n)=>Is(`style.${e}[${n}]`,t))}let Rs=g({color:!0,lineWidth:!0,lineStyle:!0,fill:!0,fillColor:!0,textColor:!0,fontSize:!0,bold:!0,italic:!0,textAlign:!0,textPosition:!0,extendLeft:!0,extendRight:!0,startArrow:!0,endArrow:!0,levels:!0,timeLevels:!0,source:!0,degree:!0});function zs(e){_(`style`,e,Rs);let t={};for(let n of[`color`,`fillColor`,`textColor`])e[n]!==void 0&&(t[n]=x(`style.${n}`,e[n]));for(let n of Ns)e[n]!==void 0&&(t[n]=f(`style.${n}`,e[n]));e.lineWidth!==void 0&&(t.lineWidth=d(`style.lineWidth`,e.lineWidth,{min:.5,max:20})),e.fontSize!==void 0&&(t.fontSize=d(`style.fontSize`,e.fontSize,{min:6,max:72})),e.lineStyle!==void 0&&(t.lineStyle=m(`style.lineStyle`,e.lineStyle,cn)),e.textAlign!==void 0&&(t.textAlign=m(`style.textAlign`,e.textAlign,As)),e.textPosition!==void 0&&(t.textPosition=m(`style.textPosition`,e.textPosition,js));for(let n of[`levels`,`timeLevels`])e[n]!==void 0&&(t[n]=Ls(n,e[n]));return e.source!==void 0&&(t.source=m(`style.source`,e.source,Yt)),e.degree!==void 0&&(t.degree=m(`style.degree`,e.degree,Ms)),t}function Bs(e){let{theme:t}=e;return{color:t.accent,lineWidth:1.5,lineStyle:`solid`,fill:!0,fillColor:t.grid,textColor:t.text,fontSize:e.font.size+1,bold:!1,italic:!1,textAlign:`left`,textPosition:`top`,extendLeft:!1,extendRight:!1,startArrow:!1,endArrow:!1,levels:[],timeLevels:[],source:`close`,degree:`intermediate`}}let Vs=/* @__PURE__ */ new WeakMap;function Hs(e,t){let n=Vs.get(e);n||(n=/* @__PURE__ */ new WeakMap,Vs.set(e,n));let r=n.get(t);return r||(r=Ce(Se(Bs(e),t.defaultStyle?.(e.theme))),n.set(t,r)),r}let Us=/* @__PURE__ */ new WeakMap;function Ws(e,t,n){let r=Us.get(n);if(r?.options===e&&r.definition===t)return r.style;let i=Ce(Se(Hs(e,t),n));return Us.set(n,{options:e,definition:t,style:i}),i}function Gs(e,t){return`${e.italic?`italic `:``}${E(e.fontSize,t,e.bold?600:`normal`)}`}let Ks=[`second`,`minute`,`hour`,`day`,`week`,`month`];function qs(e,t){h(e,t);let n=d(`${e}.from`,t.from,{min:1,integer:!0});return{from:n,to:d(`${e}.to`,t.to,{min:n,integer:!0})}}function Js(e){h(`drawing.timeframes`,e);let t=Object.keys(e).find(e=>e!==`untimed`&&!Ks.includes(e));t!==void 0&&n(`drawing.timeframes.${t} is not a unit; the units are ${Ks.join(`, `)} and untimed.`);let r={};for(let t of Ks){let n=e[t];n!==void 0&&(r[t]=qs(`drawing.timeframes.${t}`,n))}return e.untimed!==void 0&&(r.untimed=f(`drawing.timeframes.untimed`,e.untimed)),r}function Ys(e,t){if(!e||t===null)return!0;if(t===`untimed`)return e.untimed===!0;let{unit:n,count:r}=Xs(t),i=e[n];return i!==void 0&&r>=i.from&&r<=i.to}function Xs(e){let{unit:t,count:n}=e;return t===`second`&&n%60==0&&(t=`minute`,n/=60),t===`minute`&&n%60==0&&(t=`hour`,n/=60),{unit:t,count:n}}let Zs=g({id:!0,type:!0,pane:!0,points:!0,style:!0,text:!0,locked:!0,visible:!0,timeframes:!0}),Qs=Zs.filter(e=>e!==`id`&&e!==`type`),$s=g({time:!0,price:!0});function ec(e,t){return v(t,e),e.forEach((e,n)=>{_(`${t}[${n}]`,e,$s)}),e.map((e,n)=>({time:a(e.time,`${t}[${n}].time`),price:d(`${t}[${n}].price`,e.price)}))}function tc(e){return e===null?null:Js(e)}function nc(e,t,r,i){i(t)||n(`Unknown pane "${t}".`),e.mainPane&&t!==`main`&&n(`A "${r}" drawing is computed from the bars of the main pane; it goes on the main pane, not "${t}".`)}function rc(e,t,r){(e.points===0?t.length>=2:t.length===e.points)||n(`A "${r}" drawing needs ${e.points===0?`at least 2`:String(e.points)} points, received ${t.length}.`)}var ic=class e{registry;entries=[];ids;copies=/* @__PURE__ */ new WeakMap;constructor(e,t){this.registry=e,this.ids=new de(e=>this.get(e)!==void 0,t)}staging(t){let n=new e(this.registry,this.ids);return n.ids.reserve(t),n}list(){return this.entries}get(e){return this.entries.find(t=>t.id===e)}require(e){return this.get(e)??n(`Unknown drawing "${e}".`)}info(e){return{id:e.id,type:e.type,pane:e.pane,points:e.points.map(e=>({...e})),style:structuredClone(e.style),text:e.text,locked:e.locked,visible:e.visible,timeframes:structuredClone(e.timeframes)}}create(e,t){_(`drawing`,e,Zs),p(`drawing.type`,e.type);let r=this.registry.require(e.type),i=e.id??this.ids.next(e.type);p(`drawing.id`,i),this.get(i)&&n(`A drawing with id "${i}" already exists.`);let a=e.pane??`main`;nc(r,a,e.type,t);let o=ec(e.points,`drawing.points`);return rc(r,o,e.type),{id:i,type:e.type,definition:r,pane:a,points:o,style:zs(e.style??{}),text:e.text===void 0?``:ac(e.text),locked:e.locked!==void 0&&f(`drawing.locked`,e.locked),visible:e.visible===void 0||f(`drawing.visible`,e.visible),timeframes:tc(e.timeframes??null)}}add(e){this.entries.push(e),this.ids.note(e.id)}update(e,t,n){_(`drawing patch`,t,Qs);let r=this.require(e),i=t.points===void 0?r.points:ec(t.points,`drawing.points`);rc(r.definition,i,r.type),t.pane!==void 0&&nc(r.definition,t.pane,r.type,n);let a=t.style===void 0?r.style:{...r.style,...zs(t.style)},o=t.text===void 0?r.text:ac(t.text),s=t.locked===void 0?r.locked:f(`drawing.locked`,t.locked),c=t.visible===void 0?r.visible:f(`drawing.visible`,t.visible),l=t.timeframes===void 0?r.timeframes:tc(t.timeframes);this.copies.delete(r),r.points=i,r.pane=t.pane??r.pane,r.style=a,r.text=o,r.locked=s,r.visible=c,r.timeframes=l}setPoints(e,t){let n=this.require(e);this.copies.delete(n),n.points=t}remove(e){let t=this.require(e);return this.entries=this.entries.filter(e=>e!==t),t}removePane(e){this.entries=this.entries.filter(t=>t.pane!==e)}hasType(e){return this.entries.some(t=>t.type===e)}snapshot(){return this.entries.map(e=>{let t=this.copies.get(e);return t||(t={...e},this.copies.set(e,t)),t})}restore(e){this.entries=e.map(e=>{let t={...e};return this.copies.set(t,e),this.ids.note(t.id),t})}};function ac(e){return typeof e==`string`?e:n(`drawing.text must be a string.`)}var oc=class{keeps;undoStack=[];redoStack=[];merging=null;constructor(e){this.keeps=e}get canUndo(){return this.keeps()&&this.undoStack.length>0}get canRedo(){return this.keeps()&&this.redoStack.length>0}record(e,t=null){this.keeps()?(t===null||t!==this.merging)&&(this.merging=t,this.undoStack.push(e),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack=[]):this.clear()}undo(e){if(!this.keeps())return null;this.merging=null;let t=this.undoStack.pop();return t?(this.redoStack.push(e),t):null}redo(e){if(!this.keeps())return null;this.merging=null;let t=this.redoStack.pop();return t?(this.undoStack.push(e),t):null}clear(){this.merging=null,this.undoStack=[],this.redoStack=[]}forgetPane(e){this.forget(t=>t.pane===e)}forgetType(e){this.forget(t=>t.type===e)}forget(e){let t=t=>t.filter(t=>!e(t));this.undoStack=this.undoStack.map(t),this.redoStack=this.redoStack.map(t)}};let sc=NaN,cc={toScale:e=>e,fromScale:e=>e},lc={toScale:e=>e>0?Math.log10(e):NaN,fromScale:e=>10**e};function uc(e,t){return{bars:e,barIndex:e=>t.logicalIndexOf(e),timeAt:e=>t.timeOfLogicalIndex(e)}}function dc(e,t,n,r){if(e.valueAt)return e.valueAt(t);let i=e.extend??`none`,a=n.logicalIndexOf(e.from.time),o=n.logicalIndexOf(e.to.time),s=n.logicalIndexOf(t);if([a,o,s].some(Number.isNaN))return sc;if(a===o)return e.from.price===e.to.price&&(i===`both`||(i===`end`?s>=a:s===a))?e.from.price:sc;let c=(s-a)/(o-a);if(!(i===`both`||c>=0&&(i===`end`||c<=1)))return sc;let l=r.toScale(e.from.price),u=r.toScale(e.to.price);return r.fromScale(l+c*(u-l))}let fc=g({merge:!0});function pc(e){h(`drawing type definition`,e),p(`drawing type definition type`,e.type),d(`definition.points`,e.points,{min:0,max:20,integer:!0}),(typeof e.paint!=`function`||typeof e.hitTest!=`function`)&&n(`A drawing type definition needs paint() and hitTest() functions.`),e.mainPane!==void 0&&f(`definition.mainPane`,e.mainPane),e.freehand&&e.points!==0&&n(`A drawing type drawn by hand (definition.freehand) needs points: 0.`),e.textAnchor!==void 0&&d(`definition.textAnchor`,e.textAnchor,{min:0,max:Math.max(0,e.points-1),integer:!0}),e.place!==void 0&&(d(`definition.place`,e.place,{min:1,max:Math.max(1,e.points-1),integer:!0}),(e.points===0||typeof e.complete!=`function`)&&n(`A drawing type with definition.place needs a fixed number of points and complete().`)),e.fields!==void 0&&!Array.isArray(e.fields)&&n(`definition.fields must be an array of style fields when given.`);for(let t of[`paintBelow`,`defaultStyle`,`handles`,`moveHandle`,`axisMarks`,`bounds`,`complete`,`levels`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`definition.${t} must be a function when given.`)}function mc(e,t){let r=t.store,i=t=>e.panes.get(t)!==void 0,a=(n,r)=>{e.run(()=>{t.change(n,r===void 0?{}:{merge:r})})};return{set:n=>{e.run(()=>{v(`drawings`,n);let e=r.staging(n);n.forEach(t=>{e.add(e.create(t,i))}),t.replace(e.snapshot())})},add:t=>e.run(()=>{let e=r.create(t,i);return a(()=>{r.add(e)}),e.id}),update:(t,n,o={})=>{e.run(()=>{r.require(t),_(`options`,o,fc);let e=o.merge===void 0?void 0:JSON.stringify([t,p(`options.merge`,o.merge)]);a(()=>{r.update(t,n,i)},e)})},remove:n=>{e.run(()=>{t.remove(n,!1)})},clear:()=>{a(()=>{r.restore([])})},get:e=>{let t=r.get(e);return t?r.info(t):null},list:()=>r.list().map(e=>r.info(e)),validate:e=>{new ic(r.registry).create(e,i)},duplicate:n=>e.run(()=>t.duplicate(n)),bounds:e=>t.bounds(e),levels:t=>{let i=r.get(t)??n(`Unknown drawing "${t}".`),a=Ws(e.options,i.definition,i.style);return(i.definition.levels?.(i.points,cc,a,uc(e.bars,e.bars))??[]).map(e=>e.key)},editText:n=>e.run(()=>t.editText(n)),startTool:(n,r={})=>{e.run(()=>{t.startTool(n,r)})},cancelTool:()=>{e.run(()=>{t.cancelTool()})},activeTool:()=>t.activeToolType(),toolStyle:e=>t.toolStyle(e),setToolStyle:(n,r)=>{e.run(()=>{t.setToolStyle(n,r)})},undo:()=>e.run(()=>t.restore(`undo`,!1)),redo:()=>e.run(()=>t.restore(`redo`,!1)),canUndo:()=>t.history.canUndo,canRedo:()=>t.history.canRedo,register:t=>{e.run(()=>{pc(t),r.registry.register(t),e.bus.emit(`typesChange`,{kind:`drawing`,type:t.type,registered:!0})})},unregister:i=>{e.run(()=>{r.registry.require(i),r.hasType(i)&&n(`Drawings of type "${i}" are on the chart; remove them first.`),t.activeToolType()===i&&n(`The "${i}" tool is active; cancel it first.`),r.registry.unregister(i),t.forgetType(i),e.bus.emit(`typesChange`,{kind:`drawing`,type:i,registered:!1})})},types:()=>r.registry.types(),definition:e=>r.registry.get(e)??null,fields:e=>[...r.registry.require(e).fields??Ps],defaultStyle:t=>structuredClone(Hs(e.options,r.registry.require(t)))}}let hc=Math.PI/4;function gc(e,t){return t.command?e===`off`?`strong`:`off`:e}function _c(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.round(Math.atan2(r,n)/hc)*hc,a=Math.round(Math.cos(i)*1e9)/1e9,o=Math.round(Math.sin(i)*1e9)/1e9,s=n*a+r*o;return{x:e.x+s*a,y:e.y+s*o}}function vc(e){return Number.isFinite(e.time)&&Number.isFinite(e.price)}function yc(e,t,n){return{x:eo(e,n.time),y:t.scale.valueToY(n.price)}}function bc(e,t,n){return{time:e.bars.timeOfLogicalIndex(e.timeScale.xToIndex(n.x)),price:t.scale.yToValue(n.y)}}function xc(e,t,n,r){let{bars:i,timeScale:a}=e,o=r.pivot?_c(yc(e,t,r.pivot),n):n,s=Math.round(a.xToIndex(o.x)),c=i.timeOfLogicalIndex(s),l=t.scale.yToValue(o.y),u=i.bar(s);if(r.pivot||r.magnet===`off`||!u||t.id!==`main`)return{time:c,price:l};let d=[u.open,u.high,u.low,u.close].reduce((e,n)=>Math.abs(t.scale.valueToY(n)-o.y)<Math.abs(t.scale.valueToY(e)-o.y)?n:e),f=Math.abs(t.scale.valueToY(d)-o.y);return{time:c,price:r.magnet===`strong`||f<=16?d:l}}function Sc(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Cc(e,t,n){let r=Math.max(Math.abs(e.x),Math.abs(e.x-t)),i=Math.max(Math.abs(e.y),Math.abs(e.y-n));return Math.hypot(r,i)+t+n}function wc(e,t,n,r,i){if(i===`segment`||e.x===t.x&&e.y===t.y)return[e,t];let a=Cc(e,n,r),o=Math.hypot(t.x-e.x,t.y-e.y),s=(t.x-e.x)/o,c=(t.y-e.y)/o,l={x:e.x+s*a,y:e.y+c*a};return[i===`line`?{x:e.x-s*a,y:e.y-c*a}:e,l]}function Tc(e,t){return e.x<t.x||e.x===t.x&&e.y>t.y}function Ec(e,t,n,r,i,a){let o=Math.hypot(t.x-e.x,t.y-e.y);if(o===0||!i&&!a)return[e,t];let s=(t.x-e.x)/o,c=(t.y-e.y)/o,l=Tc(e,t),u=l?i:a,d=l?a:i,f=Cc(e,n,r),p=Cc(t,n,r);return[u?{x:e.x-s*f,y:e.y-c*f}:e,d?{x:t.x+s*p,y:t.y+c*p}:t]}function Dc(e,t,n,r=0){return e.x>=Math.min(t.x,n.x)-r&&e.x<=Math.max(t.x,n.x)+r&&e.y>=Math.min(t.y,n.y)-r&&e.y<=Math.max(t.y,n.y)+r}function Oc(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r,r+=1){let a=t[r],o=t[i];a&&o&&a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function M(e,t){let n=[],r=t?e.at(-1):void 0;for(let t of e)r&&n.push([r,t]),r=t;return n}function kc(e){return Math.round(e*1.4)}function N(e,t=0){if(e.length===0)return null;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let{x:t,y:o}of e)n=Math.min(n,t),r=Math.min(r,o),i=Math.max(i,t),a=Math.max(a,o);return{x:n-t,y:r-t,width:i-n+t*2,height:a-r+t*2}}function Ac(e){return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]}function jc(e){return e.startsWith(`handle:`)?e.slice(7):null}function Mc(e,t){let n=Number(e.id);return Number.isInteger(n)&&n>=0&&n<t&&String(n)===e.id}function Nc(e,t){if(!e.handles)return t.points.map((e,t)=>({id:String(t),x:e.x,y:e.y}));let r=e.handles(t),i=e.moveHandle?void 0:r.find(e=>!Mc(e,t.anchors.length));return i&&n(`The handle "${i.id}" of a "${e.type}" drawing is no anchor; define moveHandle() to move it.`),r}function Pc(e,t,n,r,i,a){return e.moveHandle?e.moveHandle(t,n,r,i,a):t.map((e,t)=>String(t)===n?r:e)}function Fc(e,t,n){if(e.handles||t.length<2)return null;let r=Number(n);return t[r-1]??t[r+1]??null}function Ic(e,t,n,r){let i=null;for(let r of e){let e=Math.hypot(r.x-t.x,r.y-t.y);r.marker!==!1&&e<=n&&(!i||e<i.distance)&&(i={handle:r,distance:e})}if(i)return i;for(let n of e){let e=n.line?Sc(t,n.line[0],n.line[1]):1/0;e<=r&&(!i||e<i.distance)&&(i={handle:n,distance:e})}return i}function Lc(e,t,n,r){for(let i of n){if(i.marker===!1)continue;let n=t.x+i.x,a=t.y+i.y,o=i.id===r.hovered;o&&(e.beginPath(),e.arc(n,a,r.radius+5,0,Math.PI*2),e.fillStyle=S(r.color,.18),e.fill()),e.beginPath(),e.arc(n,a,o?r.radius+1:r.radius,0,Math.PI*2),e.fillStyle=o?r.color:r.background,e.fill(),C(e,o?r.background:r.color,1.5),e.stroke()}}let Rc=[{ms:864e5,en:`d`,zh:`天`,ja:`日`,ko:`일`},{ms:36e5,en:`h`,zh:`小时`,ja:`時間`,ko:`시간`},{ms:6e4,en:`m`,zh:`分钟`,ja:`分`,ko:`분`},{ms:1e3,en:`s`,zh:`秒`,ja:`秒`,ko:`초`}],zc={en:` `,zh:``,ja:``,ko:` `};function Bc(e,t){let n=Math.round(Math.abs(e)/1e3)*1e3,r=[];for(let e of Rc){let i=Math.floor(n/e.ms);if(i>0&&r.length<2)r.push(`${i}${e[t]}`),n-=i*e.ms;else if(r.length>0)break}let i=`0${Rc[3][t]}`;return r.length===0?i:r.join(zc[t])}let Vc={text:`Text`,bars:e=>e===1?`1 bar`:`${e} bars`,duration:e=>Bc(e,`en`),target:`Target`,stop:`Stop`,riskReward:`R:R`,open:`Open`,targetHit:`Target hit`,stopped:`Stopped`,leftShoulder:`Left Shoulder`,head:`Head`,rightShoulder:`Right Shoulder`},Hc={text:`文字`,bars:e=>`${e} 根 K 线`,duration:e=>Bc(e,`zh`),target:`止盈`,stop:`止损`,riskReward:`盈亏比`,open:`持仓中`,targetHit:`已止盈`,stopped:`已止损`,leftShoulder:`左肩`,head:`头部`,rightShoulder:`右肩`},Uc={text:`テキスト`,bars:e=>`${e}本`,duration:e=>Bc(e,`ja`),target:`利確`,stop:`損切り`,riskReward:`RR比`,open:`保有中`,targetHit:`利確済み`,stopped:`損切り済み`,leftShoulder:`左肩`,head:`頭`,rightShoulder:`右肩`},Wc={text:`텍스트`,bars:e=>`캔들 ${e}개`,duration:e=>Bc(e,`ko`),target:`익절`,stop:`손절`,riskReward:`손익비`,open:`보유 중`,targetHit:`익절 완료`,stopped:`손절 완료`,leftShoulder:`왼쪽 어깨`,head:`머리`,rightShoulder:`오른쪽 어깨`};function Gc(e){let t=new Intl.NumberFormat(e??void 0).resolvedOptions().locale.split(`-`)[0];return t===`zh`?Hc:t===`ja`?Uc:t===`ko`?Wc:Vc}let Kc=g({magnet:!0,handleRadius:!0,visible:!0,history:!0,texts:!0}),qc={key:`drawings`,defaults:()=>({magnet:`off`,handleRadius:5,visible:!0,history:!0,texts:Ht(Vc)}),validate:(e,t)=>{_(t,e,Kc),m(`${t}.magnet`,e.magnet,[`off`,`weak`,`strong`]),d(`${t}.handleRadius`,e.handleRadius,{min:1}),f(`${t}.visible`,e.visible),f(`${t}.history`,e.history),Ut(`${t}.texts`,e.texts,Vc)}};function Jc(e){return e.drawings}let Yc=/* @__PURE__ */ new WeakMap;function Xc(e){let t=Yc.get(e);return t||(t=Wt(Gc(e.locale),Jc(e).texts),Yc.set(e,t)),t}let Zc=`#ffffff`;function Qc(e){return{prices:e.map(e=>e.price),times:e.map(e=>e.time)}}function $c(e,t,n){return e.axisMarks?.(t,n)??Qc(t)}function el(e,t,n,r,i,a){let{ctx:o,frame:s,options:c}=e,l=c.font.size+8,u=l/2;o.font=E(c.font.size,c.font.family);let d=t.plot.y+u,f=t.plot.y+t.plot.height-u,p=n.prices.map(e=>t.plot.y+t.scale.valueToY(e)),m=p.filter(e=>Number.isFinite(e));if(c.priceScale.visible&&m.length>0){let e=t.axis;if(!a&&m.length>1){let n=Math.max(t.plot.y,Math.min(...m)),i=Math.min(t.plot.y+t.plot.height,Math.max(...m));o.fillStyle=S(r,.14),o.fillRect(e.x,n,e.width,Math.max(0,i-n))}n.prices.forEach((t,n)=>{let a=p[n];a!==void 0&&a>=d-u&&a<=f+u&&gn(o,i(t),e.x+1,Math.min(Math.max(a,d),f),{background:r,color:Zc,paddingX:6,height:l,align:`left`})})}let h=s.layout.timeAxis,g=n.times.map(t=>eo(e,t)),_=g.filter(e=>Number.isFinite(e));if(!h||_.length===0)return;if(!a&&_.length>1){let e=Math.max(0,Math.min(..._)),t=Math.min(s.layout.plotWidth,Math.max(..._));o.fillStyle=S(r,.14),o.fillRect(e,h.y,Math.max(0,t-e),h.height)}let v=e.bars.interval();n.times.forEach((t,n)=>{let i=g[n];if(i===void 0||!Number.isFinite(i)||i<0||i>s.layout.plotWidth)return;let a=c.timeScale.formatter,u=a?a(t,{kind:`crosshair`,unit:`minute`,locale:e.formatter.locale,timeZone:e.formatter.timeZone}):e.formatter.timeCrosshair(t,v),d=o.measureText(u).width+12,f=Math.min(Math.max(i,d/2),s.layout.plotWidth-d/2);gn(o,u,f,h.y+h.height/2,{background:r,color:Zc,paddingX:6,height:l,align:`center`})})}function tl(e){return e.place??e.points}function nl(e,t){if(!e.complete)return t;let{type:r}=e,i=e.complete(t);return v(`complete() of "${r}"`,i),i.length!==e.points&&n(`complete() of "${r}" gives ${i.length} anchors; a "${r}" drawing has ${e.points}.`),i}function rl(e,t){return e.frame.panes.find(e=>t.y>=e.plot.y&&t.y<e.plot.y+e.plot.height&&t.x>=0&&t.x<e.plot.width)}function il(e,t){return{x:t.x-e.plot.x,y:t.y-e.plot.y}}var al=class{type;options;host;points=[];paneId=null;downAt=null;pressPlaced=!1;strokeAt=null;hover=null;constructor(e,t,n){this.type=e,this.options=t,this.host=n}get definition(){return this.host.definition(this.type)}placedPane(e){return this.paneId===null?void 0:j(e.frame,this.paneId)}paneAt(e,t){if(this.paneId!==null)return this.placedPane(e);let n=rl(e,t);return this.definition.mainPane&&n?.id!==`main`?void 0:n}pane(e){return this.hover?this.paneAt(e,this.hover.point):this.placedPane(e)}forgetPane(e){this.paneId===e&&(this.points=[],this.paneId=null,this.downAt=null,this.strokeAt=null)}pointerDown(e,t,n){this.pressPlaced=!1,n&&!this.definition.freehand?this.pointerMove(e,t):this.placeAt(e,t)&&(this.pressPlaced=!0,this.downAt=e,this.strokeAt=e)}pointerMove(e,t){this.hover={point:e,modifiers:t};let n=this.strokeAt;this.definition.freehand&&this.downAt&&n&&Math.hypot(e.x-n.x,e.y-n.y)>=3&&(this.strokeAt=e,this.placeNext(e,t)),this.host.repaint()}preview(e){let t=this.hover,n=t&&this.paneAt(e,t.point),r=t&&n?this.anchor(e,n,t.point,t.modifiers):null;return r&&vc(r)?r:null}pointerUp(e,t,n){this.downAt=null,this.pressPlaced=!1,this.definition.freehand?this.endStroke(e,t):n&&(this.hover=null,this.placeAt(e,t))}doubleClick(){this.finish()}cancelPress(){this.downAt=null,this.strokeAt=null,this.hover=null,this.pressPlaced&&(this.points=this.definition.freehand?[]:this.points.slice(0,-1),this.paneId=this.points.length>0?this.paneId:null),this.pressPlaced=!1,this.host.repaint()}endStroke(e,t){let n=this.strokeAt;this.strokeAt=null,n&&(e.x!==n.x||e.y!==n.y)&&this.placeNext(e,t),this.points.length>=2?this.host.complete(this):(this.points=[],this.paneId=null),this.host.repaint()}finish(){return this.definition.points!==0||this.definition.freehand||this.points.length<2?!1:(this.host.complete(this),!0)}place(e,t,n,r){let i=this.anchor(e,t,n,r),a=this.points.at(-1),o=[...this.points,i],s=tl(this.definition);return!vc(i)||a?.time===i.time&&a.price===i.price||o.length===s&&!this.host.draws(this,nl(this.definition,o),t)?!1:(this.points=o,!0)}placeAt(e,t){let n=this.host.context(),r=this.paneAt(n,e);return!r||!this.place(n,r,e,t)?!1:(this.paneId=r.id,this.hover=null,this.completeWhenReady(),this.host.repaint(),!0)}placeNext(e,t){let n=this.host.context(),r=this.placedPane(n);r&&this.place(n,r,e,t)}anchor(e,t,n,r){if(this.definition.freehand)return bc(e,t,il(t,n));let i={magnet:gc(Jc(e.options).magnet,r),pivot:r.shift?this.points.at(-1)??null:null};return xc(e,t,il(t,n),i)}completeWhenReady(){let e=tl(this.definition);e>0&&this.points.length>=e&&this.host.complete(this)}};function ol(e,t){return Ws(e.options,t.definition,t.style)}function sl(e,t){return Jc(e.options).visible&&t.visible&&Ys(t.timeframes,e.resolution)?e.frame.panes.find(e=>e.id===t.pane):void 0}function cl(e,t,n,r,i){let a=ol(e,n),o=Gs(a,e.options.font.family);return{points:r.map(t=>yc(e,i,t)),anchors:r,width:i.plot.width,height:i.plot.height,style:a,text:n.text,theme:e.options.theme,fontFamily:e.options.font.family,textFont:o,valueToY:e=>i.scale.valueToY(e),yToValue:e=>i.scale.yToValue(e),timeToX:t=>eo(e,t),barIndex:t=>e.bars.logicalIndexOf(t),bars:e.displayed,source:e.source,formatValue:e=>t.formatValue(i,e),measureText:t=>e.measureText(t,o),texts:Xc(e.options)}}function ll(e,t){return e.bounds?e.bounds(t):N(Nc(e,t))}function ul(e,t,n){if(!e.bounds)return!0;let r=e.bounds(t);return r!==null&&r.x<=n.x+n.width&&r.x+r.width>=n.x&&r.y<=n.y+n.height&&r.y+r.height>=n.y}function dl(e){return{x:-16,y:-16,width:e.width+32,height:e.height+32}}function fl(e,t,n,r,i){let{ctx:a,pixelRatio:o}=e;hn(a,()=>{a.beginPath(),a.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),a.clip(),a.translate(t.plot.x,t.plot.y);let e={ctx:a,pixelRatio:o,geometry:r,hovered:i.hovered,selected:i.selected,editing:i.editing};i.below&&n.paintBelow?.(e),n.paint(e)}),i.handles&&!i.editing&&(a.save(),a.beginPath(),a.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),a.clip(),Lc(a,{x:t.plot.x,y:t.plot.y},Nc(n,r),{color:r.style.color,background:e.options.theme.background,radius:Jc(e.options).handleRadius,hovered:i.hoveredHandle}),a.restore())}function pl(e,t,n){let{ctx:r,pixelRatio:i}=e;hn(r,()=>{t.paintBelow?.({ctx:r,pixelRatio:i,geometry:n,hovered:!1,selected:!1,editing:!1})})}function ml(e,t,n,r,i,a=!0){let o=ol(e,r);el(e,n,a?$c(r.definition,i,o):Qc(i),o.color,e=>t.formatValue(n,e),!1)}function hl(e,t,n,r){let i=n.pane(e);if(!i)return;let a=n.preview(e),o=a?[...n.points,a]:n.points,s=n.definition,c={definition:s,style:r,text:n.options.text??``},l=tl(s)||2,u=o.length>=l?nl(s,o):o;if(o.length>=l&&!s.editableText)fl(e,i,s,cl(e,t,c,u,i),{hovered:!1,selected:!0,editing:!1,handles:!0,hoveredHandle:null,below:!0});else{let t=ol(e,c),n=u.map((t,n)=>({id:String(n),...yc(e,i,t)}));if(n.length>1&&!s.editableText){let{ctx:r}=e;r.save(),r.beginPath(),r.rect(i.plot.x,i.plot.y,i.plot.width,i.plot.height),r.clip(),r.beginPath(),n.forEach(({x:e,y:t},n)=>{n===0?r.moveTo(i.plot.x+e,i.plot.y+t):r.lineTo(i.plot.x+e,i.plot.y+t)}),C(r,t.color,t.lineWidth,t.lineStyle),r.stroke(),r.restore()}Lc(e.ctx,{x:i.plot.x,y:i.plot.y},n,{color:t.color,background:e.options.theme.background,radius:Jc(e.options).handleRadius,hovered:null})}ml(e,t,i,c,u,o.length>=l)}function gl(e,t,n,r){let i=e.selection?.kind===`drawing`&&!r.placing?e.selection.id:null,a=e.hovered?.kind===`drawing`?e.hovered:null,o=null;for(let s of n){let n=sl(e,s);if(!n)continue;let c=s.id===i,l=a?.id===s.id,u=cl(e,t,s,s.points,n);c&&(o={entry:s,pane:n}),ul(s.definition,u,dl(u))&&fl(e,n,s.definition,u,{hovered:l,selected:c,editing:r.editing===s.id,handles:c||l,hoveredHandle:l?jc(a.part):null,below:!1})}for(let r of n){let n=sl(e,r),a=ol(e,r),o=n?$c(r.definition,r.points,a):null;n&&o?.always&&r.id!==i&&el(e,n,o,a.color,e=>t.formatValue(n,e),!0)}o&&ml(e,t,o.pane,o.entry,o.entry.points),r.placing&&hl(e,t,r.placing.tool,r.placing.style)}function _l(e,t,n,r){for(let i of n)if(i.definition.paintBelow&&sl(e,i)?.id===r.id){let n=cl(e,t,i,i.points,r);ul(i.definition,n,dl(n))&&pl(e,i.definition,n)}}function vl({bars:e,timeScale:t},n){let r=Math.abs(n.scale.yToScale(0)-n.scale.yToScale(1));return{...n.scale.mode===`log`?lc:cc,barIndex:t=>e.logicalIndexOf(t),timeAt:t=>e.timeOfLogicalIndex(t),unitHeight:r>0?1/r/t.barSpacing:1}}function yl(e,t,n,r,i){let{timeScale:a,bars:o}=e,s=Math.round(a.xToIndex(i.x)-r.index),c=t.scale.yToScale(i.y)-r.value;return n.map(e=>({time:o.timeOfLogicalIndex(o.logicalIndexOf(e.time)+s),price:t.scale.fromScale((t.scale.toScale(e.price)??NaN)+c)}))}function bl(e,t,n,r,i){let{store:a}=e,o=a.get(n.id);if(!o||o.locked||!j(t.frame,o.pane))return null;e.keepText();let s=jc(n.part),c=o;i.alt&&s===null&&(c=e.copyOf(o),a.add(c));let l=c!==o,u=c.definition.paintBelow!==void 0,d=c.points.map(e=>({...e})),f=j(t.frame,c.pane),p=f?il(f,r):r,m={index:t.timeScale.xToIndex(p.x),value:f?f.scale.yToScale(p.y):NaN},h=!1;e.select(c.id);let g=()=>a.get(c.id)===c,_=()=>{let e=a.snapshot();return l?e.filter(e=>e.id!==c.id):e.map(e=>e.id===c.id?{...e,points:d}:e)};return{move:(t,n)=>{let r=e.context(),i=j(r.frame,c.pane);if(!i||!g())return;let o=il(i,t),l=s===null?yl(r,i,d,m,o):Pc(c.definition,d,s,xc(r,i,o,{magnet:gc(Jc(r.options).magnet,n),pivot:n.shift?Fc(c.definition,d,s):null}),vl(r,i),ol(r,c));l.every(vc)&&(a.setPoints(c.id,l),h=!0,e.repaint(u))},end:()=>{(h||l)&&g()&&e.dropped(_(),c.id,l)},cancel:()=>{g()&&(a.restore(_()),e.select(o.id),e.cancelled())}}}function xl(e,t){return t.y>=e.plot.y&&t.y<e.plot.y+e.plot.height}function Sl(e,t,n,r){let i=/* @__PURE__ */ new Set;n.selection?.kind===`drawing`&&i.add(n.selection.id),n.hovered?.kind===`drawing`&&i.add(n.hovered.id);let a=null;for(let o of i){let i=e.find(e=>e.id===o),s=i?sl(n,i):void 0;if(!i||!s||!xl(s,r))continue;let c=cl(n,t,i,i.points,s),l=Jc(n.options).handleRadius+4,u=Ic(Nc(i.definition,c),il(s,r),l,n.options.interaction.hitTolerance);u&&(!a||u.distance<a.distance)&&(a={target:{kind:`drawing`,id:i.id,part:`handle:${u.handle.id}`,cursor:i.locked?`pointer`:u.handle.cursor??`move`,draggable:!i.locked},priority:$a.handle,distance:u.distance})}return a}function Cl(e,t){return e.part===t.part?e.distance<t.distance:e.part===`line`}function wl(e,t,n,r){let i=Sl(e,t,n,r);if(i)return i;let a=n.options.interaction.hitTolerance,o=null;for(let i of[...e].reverse()){let e=sl(n,i);if(!e||!xl(e,r))continue;let s=cl(n,t,i,i.points,e),c=il(e,r),l=ul(i.definition,s,{x:c.x-a,y:c.y-a,width:a*2,height:a*2})?i.definition.hitTest(s,c,a):null;l&&(!o||Cl(l,o.hit))&&(o={entry:i,hit:l})}return o&&{target:{kind:`drawing`,id:o.entry.id,part:o.hit.part,cursor:`pointer`,draggable:!o.entry.locked},priority:o.hit.part===`line`?$a.line:$a.body,distance:o.hit.distance}}var Tl=class{options;area;done=!1;focused=!1;focusTimer=0;constructor(e){this.options=e;let t=e.root.ownerDocument.createElement(`textarea`);this.area=t,t.value=e.text,t.spellcheck=!1,t.setAttribute(`aria-label`,e.label),Object.assign(t.style,{position:`absolute`,zIndex:`2`,left:`${e.x-3-1}px`,top:`${e.y-e.lineHeight/2-2-1}px`,margin:`0`,padding:`2px 3px`,border:`1px solid ${e.border}`,borderRadius:`3px`,outline:`none`,resize:`none`,overflow:`hidden`,whiteSpace:`pre`,background:e.background,color:e.color,font:e.font,textAlign:e.align,lineHeight:`${e.lineHeight}px`,boxShadow:`0 2px 10px rgba(0, 0, 0, 0.12)`}),t.addEventListener(`keydown`,this.onKey),t.addEventListener(`input`,this.fit),t.addEventListener(`blur`,this.onBlur),t.addEventListener(`focus`,this.onFocus);for(let e of[`pointerdown`,`pointermove`,`pointerup`,`dblclick`,`wheel`,`keyup`])t.addEventListener(e,El);e.root.appendChild(t),this.fit();let n=e.root.ownerDocument.defaultView;this.focusTimer=n?.setTimeout(()=>{t.focus(),t.select()},0)??0}commit(){this.finish(()=>{this.options.commit(this.area.value)})}cancel(){this.finish(()=>{this.options.cancel()})}finish(e){this.done||(this.done=!0,this.area.ownerDocument.defaultView?.clearTimeout(this.focusTimer),this.area.removeEventListener(`blur`,this.onBlur),this.area.remove(),e())}onKey=e=>{e.stopPropagation(),e.key===`Escape`?(e.preventDefault(),this.cancel()):e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.commit())};onFocus=()=>{this.focused=!0};onBlur=()=>{this.focused&&this.commit()};fit=()=>{let e=this.area,t=Math.max(1,e.value.split(`
|
|
3
|
-
`).length);e.style.height=`${t*this.options.lineHeight+4+2}px`,e.style.width=`0`,e.style.width=`${Math.max(40,e.scrollWidth+2)}px`}};function El(e){e.stopPropagation()}var Dl=class{host;current=null;constructor(e){this.host=e}get edited(){return this.current?.edited??null}open(e,t){let{host:n}=this,r=n.context(),i=j(r.frame,e.pane??`main`),a=n.definition(e.type),o=e.points[a.textAnchor??0];if(!i||!o)return;let s={definition:a,style:e.style??{},text:e.text??``},c=ol(r,s),l=yc(r,i,{time:Number(o.time),price:o.price}),u=()=>{this.current=null,n.repaint()},d=new Tl({root:n.root,x:r.frame.layout.leftAxisWidth+i.plot.x+l.x,y:i.plot.y+l.y,text:s.text,label:Xc(r.options).text,font:Gs(c,r.options.font.family),align:c.textAlign,fontSize:c.fontSize,lineHeight:kc(c.fontSize),color:c.textColor,border:c.color,background:r.options.theme.background,commit:e=>{u(),n.keep(t,e)},cancel:()=>{u(),n.drop(t)}});this.current={editor:d,edited:t},n.repaint()}commit(){this.current?.editor.commit()}cancel(){this.current?.editor.cancel()}};let Ol=g({style:!0,text:!0,continuous:!0});function kl(e){return{type:e.type,pane:e.pane,points:e.points,style:e.style,text:e.text,locked:e.locked,visible:e.visible,timeframes:e.timeframes}}var Al=class{store;host;kind=`drawing`;history=new oc(()=>Jc(this.host.context().options).history);tool=null;clipboard=null;text;quietly=!1;toolStyles=/* @__PURE__ */ new Map;paneExists=e=>this.host.paneExists(e);constructor(e,t){this.store=e,this.host=t,this.text=new Dl({root:t.root,context:()=>t.context(),repaint:()=>{t.repaint(!1)},definition:t=>e.registry.require(t),keep:(e,t)=>{this.keepText(e,t)},drop:e=>{this.dropText(e)}})}edit(e){return this.editText(e)}has(e){return this.store.get(e)!==void 0}shown(e){let t=this.store.get(e);return t!==void 0&&sl(this.host.context(),t)!==void 0}activeTool(){return this.placing(this.host.context())}placing(e){return Jc(e.options).visible?this.tool:null}activeToolType(){return this.tool?.type??null}startTool(e,t){this.store.registry.require(e),_(`tool options`,t,Ol);let n={...t.style===void 0?{}:{style:zs(t.style)},...t.text===void 0?{}:{text:ac(t.text)},...t.continuous!==void 0&&f(`tool options.continuous`,t.continuous)?{continuous:!0}:{}};this.closeTextQuietly(!0),this.tool=this.newTool(e,n),this.host.repaint(!1)}cancelTool(){this.text.edited?.id===null&&this.closeTextQuietly(!1),this.tool&&(this.tool=null,this.host.repaint(!1))}toolStyle(e){return this.store.registry.require(e),{...this.toolStyles.get(e)}}setToolStyle(e,t){this.store.registry.require(e),t===null?this.toolStyles.delete(e):this.toolStyles.set(e,zs(t)),this.host.repaint(!1)}forgetPane(e){let t=this.text.edited;t&&this.paneOfText(t)===e&&this.closeTextQuietly(!1),this.store.removePane(e),this.history.forgetPane(e),this.tool?.forgetPane(e),this.clipboard?.pane===e&&(this.clipboard=null)}paneOfText(e){return e.id===null?e.input.pane:this.store.get(e.id)?.pane}forgetType(e){let t=this.text.edited;t?.id===null&&t.input.type===e&&this.closeTextQuietly(!1),this.toolStyles.delete(e),this.history.forgetType(e),this.clipboard?.type===e&&(this.clipboard=null)}placingStyle(e){return{...this.toolStyles.get(e.type),...e.options.style}}finishTool(){return this.placing(this.host.context())?.finish()??!1}newTool(e,t){return new al(e,t,{context:()=>this.host.context(),definition:e=>this.store.registry.require(e),repaint:()=>{this.host.repaint(!1)},draws:(e,t,n)=>{let r={definition:e.definition,style:this.placingStyle(e),text:e.options.text??``},i=cl(this.host.context(),this.host,r,t,n);return ll(e.definition,i)!==null},complete:e=>{this.placed(e)}})}placed(e){let t=e.paneId;if(t===null)return;this.tool=e.options.continuous?this.newTool(e.type,e.options):null;let n=this.tool===null,r=this.placingStyle(e),i={type:e.type,pane:t,points:nl(e.definition,e.points),...Object.keys(r).length>0?{style:r}:{},...e.options.text===void 0?{}:{text:e.options.text}};e.definition.editableText&&e.options.text===void 0?(this.text.open(i,{id:null,input:i,endsTool:n}),this.host.repaint(!1)):(this.create(i),n&&this.host.toolEnded(e.type,!0))}create(e){let t=this.store.create(e,this.paneExists);this.change(()=>{this.store.add(t)},{user:{reason:`create`,ids:[t.id]},select:t.id})}change(e,t={}){let n=this.store.snapshot();e(),this.changed(n,t)}changed(e,t){we(e,this.store.snapshot())||this.history.record(e,t.merge??null),t.select!==void 0&&this.host.selected(t.select),this.settle(t.user!==void 0),t.user&&this.host.changed(t.user.reason,t.user.ids)}settle(e){let t=this.text.edited;t&&t.id!==null&&!this.has(t.id)&&this.closeTextQuietly(!1),this.host.prune(e),this.host.repaint(!0)}remove(e,t){this.store.require(e),this.change(()=>{this.store.remove(e)},t?{user:{reason:`remove`,ids:[e]}}:{})}replace(e){this.closeTextQuietly(!1),this.store.restore(e),this.history.clear(),this.clipboard&&!this.host.paneExists(this.clipboard.pane)&&(this.clipboard=null),this.settle(!1)}restore(e,t){if(!(e===`undo`?this.history.canUndo:this.history.canRedo))return!1;this.closeTextQuietly(!0);let n=this.store.snapshot(),r=e===`undo`?this.history.undo(n):this.history.redo(n);return r?(this.store.restore(r),this.settle(t),t&&this.host.changed(e,[]),!0):!1}shifted(e){let{bars:t}=this.host.context(),n=e.points.map(e=>({time:t.timeOfLogicalIndex(t.logicalIndexOf(Number(e.time))+5),price:e.price}));return n.every(vc)?{...e,points:n}:null}copy(e){let t=e===null?void 0:this.store.get(e);return t?(this.clipboard=kl(this.store.info(t)),!0):!1}paste(){let e=this.clipboard&&this.shifted(this.clipboard);return e?(this.clipboard=e,this.create(e),!0):!1}duplicate(e){let t=this.shifted(kl(this.store.info(this.store.require(e))))??n(`duplicate() needs two bars or more, to place the copy bars to the right.`),r=this.store.create(t,this.paneExists);return this.change(()=>{this.store.add(r)}),r.id}editText(e){let t=this.store.require(e);return!t.definition.editableText||t.locked?!1:(this.closeTextQuietly(!0),this.text.open(this.store.info(t),{id:e}),!0)}commitText(){this.text.commit()}closeTextQuietly(e){this.quietly=!0;try{e?this.text.commit():this.text.cancel()}finally{this.quietly=!1}}keepText(e,t){let{id:n}=e;if(n===null){let n=t.trim()!==``;n&&this.create({...e.input,text:t}),e.endsTool&&!this.quietly&&this.host.toolEnded(e.input.type,n)}else this.has(n)&&t!==this.store.require(n).text&&this.change(()=>{this.store.update(n,{text:t},this.paneExists)},{user:{reason:`edit`,ids:[n]}})}dropText(e){e.id===null&&e.endsTool&&!this.quietly&&this.host.toolEnded(e.input.type,!1)}bounds(e){let t=this.host.context(),n=this.store.require(e),r=sl(t,n);if(!r)return null;let i=ll(n.definition,cl(t,this.host,n,n.points,r));if(!i)return null;let a=Math.max(0,i.x),o=Math.max(0,i.y),s=Math.min(r.plot.width,i.x+i.width),c=Math.min(r.plot.height,i.y+i.height);return s>=a&&c>=o?{x:t.frame.layout.leftAxisWidth+r.plot.x+a,y:r.plot.y+o,width:s-a,height:c-o}:null}hitTest(e,t){return wl(this.store.list(),this.host,e,t)}beginDrag(e,t,n,r){return bl({store:this.store,context:()=>this.host.context(),keepText:()=>{this.commitText()},copyOf:e=>this.store.create(kl(this.store.info(e)),this.paneExists),select:e=>{this.host.selected(e)},repaint:e=>{this.host.repaint(e)},dropped:(e,t,n)=>{this.changed(e,{user:{reason:n?`create`:`edit`,ids:[t]}})},cancelled:()=>{this.settle(!0)}},e,t,n,r)}paintBelow(e,t){_l(e,this.host,this.store.list(),t)}paint(e){let t=this.placing(e);gl(e,this.host,this.store.list(),{placing:t&&{tool:t,style:this.placingStyle(t)},editing:this.text.edited?.id??null})}};function jl(e,t){let{bars:r,scaleOf:i}=e,a=uc(r,r),o=t=>t.definition.levels?.(t.points,i(t.pane),Ws(e.options(),t.definition,t.style),a)??[],s=(e,t)=>{let n=o(e);return(t===void 0?n[0]:n.find(e=>e.key===t))??null};return{movable:!0,check:(e,r)=>{let i=t.get(e.id)??n(`${r}: unknown drawing "${e.id}".`),a=o(i).map(e=>e.key);a.length===0&&n(`${r}: a "${i.type}" drawing has no lines to watch.`),e.level!==void 0&&!a.includes(e.level)&&n(`${r}: a "${i.type}" drawing has no line "${e.level}"; it has ${a.map(e=>`"${e}"`).join(`, `)}.`)},read:(e,n)=>{let a=t.get(e.id),o=a?s(a,e.level):null;return a&&o?dc(o,r.time(n),r,i(a.pane)):NaN},paneOf:e=>t.get(e.id)?.pane??`main`}}function Ml(e,t){let n=e.events(),r=()=>{let n=e.objects.selection;return n?.kind===`drawing`&&!t.activeTool()&&t.shown(n.id)?n.id:null};return e=>{switch(e){case`escape`:{let e=t.activeToolType();return e!==null&&(t.cancelTool(),n.emit(`toolEnd`,{type:e,completed:!1}),!0)}case`delete`:{let e=r();return e!==null&&(t.remove(e,!0),!0)}case`undo`:case`redo`:return t.restore(e,!0);case`enter`:return t.finishTool();case`copy`:return t.copy(r());case`paste`:return t.paste()}}}function Nl(e){let{store:t}=e;return{key:`drawings`,save:()=>t.list().map(e=>t.info(e)),prepare:(n,r)=>{let i=n??[];v(`state.drawings`,i);let a=t.staging(i);return i.forEach(e=>{a.add(a.create(e,e=>r.get(e)!==void 0))}),{apply:()=>{e.replace(a.snapshot()),e.cancelTool()}}}}}function Pl(e=[]){let t=/* @__PURE__ */ new Set;return e.forEach(e=>{pc(e);let{type:r}=e;t.has(r)&&n(`drawings() is given the drawing type "${r}" twice.`),t.add(r)}),Ua({name:`drawings`,options:qc,install:t=>{let n=new Dr(`drawing type`,[],`Give it to the drawings module, or register it with chart.drawings.register().`);e.forEach(e=>{n.register(e)});let r=t.events(),i=new Al(new ic(n),{context:()=>t.objectContext(),root:t.surface.root,repaint:e=>{e?t.invalidateLayers(`scene`,`objects`):t.invalidateLayers(`objects`)},paneExists:e=>t.panes.get(e)!==void 0,prune:e=>{t.objects.prune()&&e&&t.bus.emit(`selectionChange`,{selection:t.objects.selection})},formatValue:(e,n)=>Rn(t,e,n),changed:(e,t)=>{r.emit(`drawingsChange`,{reason:e,ids:t})},toolEnded:(e,t)=>{r.emit(`toolEnd`,{type:e,completed:t})},selected:e=>{t.selectByUser(e===null?null:{kind:`drawing`,id:e})}});return t.objects.add(i,20),t.hooks.destroyed.push(()=>{i.closeTextQuietly(!1)}),t.scenePainters.push((e,n,r,a,o)=>{a===`below`&&i.paintBelow({...t.objectContext(n),ctx:e,pixelRatio:o},r)}),t.tool=()=>i.activeTool(),t.commands.push(Ml(t,i)),t.values.provide(`drawing`,jl({bars:t.bars,options:()=>t.options,scaleOf:e=>t.panes.get(e)?.scales.get(`right`)?.mode===`log`?lc:cc},i.store)),t.paneOccupants.push({occupants:()=>[],removed:e=>{i.forgetPane(e)}}),t.stateParts.push(Nl(i)),{drawings:mc(t,i)}}})}let P={part:`body`,distance:0};function F(e,t,n={}){let{ctx:r,geometry:i}=e;r.beginPath(),t(r),C(r,n.color??i.style.color,n.lineWidth??i.style.lineWidth,n.lineStyle??i.style.lineStyle),r.lineCap=`round`,r.lineJoin=`round`,r.stroke()}function Fl(e){return e.reduce((e,t)=>t)}function I(e,t,n){t.forEach((t,n)=>{n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)}),n&&e.closePath()}function L(e,t,n){e.beginPath(),I(e,t,!0),e.fillStyle=n,e.fill()}function Il(e,t,n,r){let i=Sc(e,t,n);return i<=r?{part:`line`,distance:i}:null}function R(e,t,n){let r=t.reduce((t,[n,r])=>Math.min(t,Sc(e,n,r)),1/0);return r<=n?{part:`line`,distance:r}:null}function Ll(e,t,n,r,i){return R(e,t,r)??(i&&Oc(e,n)?P:null)}function z(e,t,n=null){let r=0;return e.flatMap(({value:e,color:i,visible:a})=>{let o=e===0||e===1,s=o||!n?t.color:Sn(n,r);return r+=+!o,a===!1?[]:[{value:e,color:i??s}]})}function B(e){return String(Math.round(e*1e3)/1e3)}function Rl(e){let t=/* @__PURE__ */ new WeakMap;return(n,r,i)=>{let a=t.get(n);return a?.revision!==n.revision&&(a={revision:n.revision,values:new Ti(e)},t.set(n,a)),a.values.getOrCreate(r,i)}}function zl(e,t,n){switch(n){case`open`:return e.open(t);case`high`:return e.high(t);case`low`:return e.low(t);case`close`:return e.close(t);case`hl2`:return(e.high(t)+e.low(t))/2;case`hlc3`:return(e.high(t)+e.low(t)+e.close(t))/3;case`ohlc4`:return(e.open(t)+e.high(t)+e.low(t)+e.close(t))/4}}let Bl={left:0,center:.5,right:1,top:0,middle:.5,bottom:1},Vl=Math.PI/8;function Hl(e){return 9+e.lineWidth*2.5}function Ul(e,t){return Math.min(t/2,Hl(e)*.6)}function Wl(e,t,n,r,i=r.color){let a=Hl(r);e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.x-a*Math.cos(n-Vl),t.y-a*Math.sin(n-Vl)),e.lineTo(t.x-a*Math.cos(n+Vl),t.y-a*Math.sin(n+Vl)),e.closePath(),e.fillStyle=i,e.fill()}function Gl(e,t,n,r){let i=Math.hypot(n.x-t.x,n.y-t.y);if(i===0)return;let{style:a}=e.geometry,o=Math.atan2(n.y-t.y,n.x-t.x),s=Ul(a,i);F(e,e=>{e.moveTo(t.x,t.y),e.lineTo(n.x-s*Math.cos(o),n.y-s*Math.sin(o))},{color:r,lineStyle:`solid`}),Wl(e.ctx,n,o,a,r)}function Kl(e){return e.text===``?[]:e.text.split(`
|
|
4
|
-
`)}function
|
|
5
|
-
`)}function
|
|
6
|
-
`),n=kc(r.style.fontSize);Jl({...e,geometry:{...r,style:{...r.style,textAlign:`center`}}},t,a.x,a.y-(t.length-1)*n/2,0,r.style.textColor)}}function od(e,t,n,r){let{center:i,radiusX:a,radiusY:o,rotation:s}=e;if(a<=0||o<=0)return null;let c=t.x-i.x,l=t.y-i.y,u=(c*Math.cos(s)+l*Math.sin(s))/a,d=(-c*Math.sin(s)+l*Math.cos(s))/o,f=Math.hypot(u,d),p=Math.abs(f-1)*Math.min(a,o);return p<=n?{part:`line`,distance:p}:r&&f<1?P:null}function sd({center:e,radiusX:t,radiusY:n,rotation:r}){let i=Math.cos(r),a=Math.sin(r),o=Math.hypot(t*i,n*a),s=Math.hypot(t*a,n*i);return{x:e.x-o,y:e.y-s,width:o*2,height:s*2}}function cd(e){let[t,n]=e.points,r=Math.hypot(n.x-t.x,n.y-t.y);return{center:t,radiusX:r,radiusY:r,rotation:0}}let ld={type:`circle`,points:2,fields:id,defaultStyle:e=>({fillColor:S(e.accent,.12)}),paint:e=>{ad(e,cd(e.geometry))},hitTest:(e,t,n)=>od(cd(e),t,n,e.style.fill),bounds:e=>sd(cd(e)),axisMarks:([e])=>({prices:[e.price],times:[e.time]})};function ud(e){let[t,n,r]=e.points,i=Math.hypot(n.x-t.x,n.y-t.y);if(i===0)return null;let a={x:(t.x+n.x)/2,y:(t.y+n.y)/2},o={x:-(n.y-t.y)/i,y:(n.x-t.x)/i},s=(r.x-a.x)*o.x+(r.y-a.y)*o.y;return{center:a,radiusX:i/2,radiusY:Math.abs(s),rotation:Math.atan2(n.y-t.y,n.x-t.x),normal:s<0?{x:-o.x,y:-o.y}:o}}let dd={type:`ellipse`,points:3,fields:id,defaultStyle:e=>({fillColor:S(e.accent,.12)}),paint:e=>{let t=ud(e.geometry);t&&ad(e,t)},hitTest:(e,t,n)=>{let r=ud(e);return r?od(r,t,n,e.style.fill):null},handles:e=>{let[t,n]=e.points,r=ud(e);return r?[{id:`0`,...t},{id:`1`,...n},{id:`2`,x:r.center.x+r.normal.x*r.radiusY,y:r.center.y+r.normal.y*r.radiusY}]:e.points.map((e,t)=>({id:String(t),...e}))},bounds:e=>{let t=ud(e);return t&&sd(t)},axisMarks:([e,t])=>({prices:[e.price,t.price],times:[e.time,t.time]})},fd={type:`triangle`,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:S(e.accent,.12)}),paint:e=>{let{points:t}=e.geometry;e.geometry.style.fill&&L(e.ctx,t,e.geometry.style.fillColor),F(e,e=>{I(e,t,!0)})},hitTest:(e,t,n)=>Ll(t,M(e.points,!0),e.points,n,e.style.fill),bounds:e=>N(e.points)};function pd(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?Math.hypot(n.x-e.x,n.y-e.y):Math.abs((t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x))/r}function md(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?e:{x:e.x-(t.y-e.y)/r*n,y:e.y+(t.x-e.x)/r*n}}function hd([e,t,n]){let r=pd(e,t,n);return[md(e,t,r),md(t,e,-r),md(t,e,r),md(e,t,-r)]}let gd={type:`rotated-rectangle`,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:S(e.accent,.12)}),paint:e=>{let t=hd(e.geometry.points);e.geometry.style.fill&&L(e.ctx,t,e.geometry.style.fillColor),F(e,e=>{I(e,t,!0)})},hitTest:(e,t,n)=>{let r=hd(e.points);return Ll(t,M(r,!0),r,n,e.style.fill)},bounds:e=>N(hd(e.points)),handles:e=>{let[t,n]=e.points;return[{id:`0`,...t},{id:`1`,...n},...hd(e.points).map((e,t)=>({id:`corner-${String(t)}`,...e}))]},moveHandle:([e,t,n],r,i,a)=>{if(r.startsWith(`corner-`))return[e,t,i];let o=e=>({x:a.barIndex(e.time),y:a.toScale(e.price)*a.unitHeight}),[s,c]=r===`0`?[i,t]:[e,i],l=md(o(s),o(c),pd(o(e),o(t),o(n))),u={time:a.timeAt(l.x),price:a.fromScale(l.y/a.unitHeight)};return Number.isFinite(u.time)&&Number.isFinite(u.price)?[s,c,u]:[s,c,n]},axisMarks:([e,t])=>({prices:[e.price,t.price],times:[e.time,t.time]})};function _d(e){let[t,n]=e.points,r=Math.min(t.x,n.x),i=Math.abs(n.x-t.x),a=t=>[{x:t,y:0},{x:t,y:e.height}];if(i<2)return[a(r)];let o=[];for(let t=r+Math.max(0,Math.ceil(-r/i))*i;t<=e.width;t+=i)o.push(a(t));return o}let vd={type:`cyclic-lines`,points:2,fields:[`color`,`lineWidth`,`lineStyle`],paint:e=>{F(e,t=>{for(let n of _d(e.geometry))I(t,n,!1)})},hitTest:(e,t,n)=>{let[r,i]=e.points;return R(t,_d(e),n)??([r,i].some(e=>Dc(t,e,e,n))?{part:`line`,distance:0}:null)},bounds:e=>{let[t,n]=e.points,r=Math.min(t.x,n.x);return{x:r,y:0,width:Math.max(0,e.width-r),height:e.height}},axisMarks:([e,t])=>({prices:[],times:[e.time,t.time]})},yd=[0,.25,.382,.5,.618,.75,1],bd=.08,xd=()=>({levels:yd.map(e=>({value:e})),timeLevels:yd.map(e=>({value:e}))});function Sd(e,t,n,r){return z(e,t.style,t.theme.palette).map(({value:e,color:t})=>({ratio:e,at:n+(r-n)*e,color:t})).sort((e,t)=>e.ratio-t.ratio)}function Cd(e,t,n){F(e,e=>{I(e,t,!1)},n)}function wd(e,t){e.font=E(t.style.fontSize-1,t.fontFamily)}function Td(e,t){return{left:Math.min(e.x,t.x),right:Math.max(e.x,t.x),top:Math.min(e.y,t.y),bottom:Math.max(e.y,t.y)}}function Ed(e,t,n){let r=4+Math.max(0,...n.map(({ratio:t})=>e.measureText(B(t)))),i=4+e.style.fontSize;return{x:t.left-r,y:t.top-i,width:t.right-t.left+r*2,height:t.bottom-t.top+i*2}}function Dd(e,t,n,r,i){wd(e,t),e.textBaseline=`middle`;for(let{ratio:t,at:i,color:a}of r)e.fillStyle=a,e.textAlign=`right`,e.fillText(B(t),n.left-4,i),e.textAlign=`left`,e.fillText(B(t),n.right+4,i);e.textAlign=`center`;for(let{ratio:t,at:r,color:a}of i)e.fillStyle=a,e.textBaseline=`bottom`,e.fillText(B(t),r,n.top-4),e.textBaseline=`top`,e.fillText(B(t),r,n.bottom+4)}function Od(e){let[t,n]=e.points;return{first:t,second:n,prices:Sd(e.style.levels,e,t.y,n.y),times:Sd(e.style.timeLevels,e,t.x,n.x)}}function kd({first:e,second:t,prices:n,times:r}){return[...n.map(({at:n,color:r})=>({line:[{x:e.x,y:n},{x:t.x,y:n}],color:r})),...r.map(({at:n,color:r})=>({line:[{x:n,y:e.y},{x:n,y:t.y}],color:r}))]}let Ad={type:`gann-box`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`timeLevels`,`fill`],defaultStyle:xd,paint:e=>{let{ctx:t,geometry:n}=e,r=Od(n),{first:i,second:a,prices:o,times:s}=r;n.style.fill&&(o.forEach(({at:e,color:n},r)=>{let s=o[r+1];s&&L(t,yu({x:i.x,y:e},{x:a.x,y:s.at}),S(n,bd))}),s.forEach(({at:e,color:n},r)=>{let o=s[r+1];o&&L(t,yu({x:e,y:i.y},{x:o.at,y:a.y}),S(n,bd))}));for(let{line:t,color:n}of kd(r))Cd(e,t,{color:n});Dd(t,n,Td(i,a),o,s)},hitTest:(e,t,n)=>{let r=Od(e);return Ll(t,kd(r).map(({line:e})=>e),yu(r.first,r.second),n,e.style.fill)},bounds:e=>{let t=Od(e);return Ed(e,Td(t.first,t.second),[...t.prices,...t.times])},handles:Su,moveHandle:Cu,levels:([e,t],n,r)=>{let i=n.toScale(e.price),a=n.toScale(t.price),o=Math.min(e.time,t.time),s=Math.max(e.time,t.time);return z(r.levels,r).map(({value:e})=>{let t=n.fromScale(i+(a-i)*e);return{key:B(e),from:{time:o,price:t},to:{time:s,price:t}}})}};function jd(e){let[t,n]=e.points,r=Sd(e.style.levels,e,n.y,t.y),i=Sd(e.style.timeLevels,e,n.x,t.x),a=n=>wc(t,n,e.width,e.height,`ray`);return{origin:t,corner:n,prices:r.map(e=>({...e,ray:a({x:n.x,y:e.at})})),times:i.map(e=>({...e,ray:a({x:e.at,y:n.y})}))}}function Md({prices:e,times:t}){return[...e,...t].map(({ray:e})=>e)}function Nd({origin:e,corner:t,prices:n,times:r}){return[...n.map(({at:n})=>[{x:e.x,y:n},{x:t.x,y:n}]),...r.map(({at:n})=>[{x:n,y:e.y},{x:n,y:t.y}])]}function Pd(e,t){return t.flatMap(({ray:n,color:r},i)=>{let a=t[i+1];return a?[{area:[e,n[1],a.ray[1]],color:r}]:[]})}let Fd={type:`fib-speed-fan`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`timeLevels`,`fill`],defaultStyle:xd,paint:e=>{let{ctx:t,geometry:n}=e,r=jd(n),{origin:i,corner:a,prices:o,times:s}=r;if(n.style.fill)for(let{area:e,color:n}of[...Pd(i,o),...Pd(i,s)])L(t,e,S(n,bd));for(let t of Nd(r))Cd(e,t,{color:S(n.style.color,.5),lineWidth:1});for(let{ray:t,color:n}of[...o,...s])Cd(e,t,{color:n});Dd(t,n,Td(i,a),o,s)},hitTest:(e,t,n)=>{let r=jd(e),i=[...Pd(r.origin,r.prices),...Pd(r.origin,r.times)];return R(t,[...Md(r),...Nd(r)],n)??(e.style.fill&&i.some(({area:e})=>Oc(t,e))?P:null)},bounds:e=>{let t=jd(e),n=Ed(e,Td(t.origin,t.corner),[...t.prices,...t.times]);return N([...Md(t).flat(),...Ac(n)])},levels:([e,t],n,r,{barIndex:i,timeAt:a})=>{let o=n.toScale(t.price),s=n.toScale(e.price),c=e=>z(e,r).map(e=>e.value),l=(t,n)=>({key:t,from:e,to:n,extend:`end`}),u=i(t.time),d=i(e.time)-u;return[...c(r.levels).map(e=>l(B(e),{time:t.time,price:n.fromScale(o+(s-o)*e)})),...c(r.timeLevels).filter(n=>n!==1&&e.time!==t.time).map(e=>l(`time-${B(e)}`,{time:a(u+d*e),price:t.price}))]}},Id=[8,4,3,2,1,1/2,1/3,1/4,1/8];function Ld(e){return e>=1?`${B(e)}×1`:`1×${B(Math.round(100/e)/100)}`}function Rd(e){let[t,n]=e.points,r=n.x-t.x,i=n.y-t.y;return r===0&&i===0?[]:z(e.style.levels,e.style,e.theme.palette).filter(({value:e})=>e>0).sort((e,t)=>t.value-e.value).map(({value:a,color:o})=>{let s=a<=1?{x:n.x,y:t.y+i*a}:{x:t.x+r/a,y:n.y};return{ratio:a,color:o,ray:wc(t,s,e.width,e.height,`ray`)}})}function zd(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=i>0?(n-e.x)/i:i<0?-e.x/i:1/0,s=a>0?(r-e.y)/a:a<0?-e.y/a:1/0,c=Math.min(o,s),l={x:e.x+i*c,y:e.y+a*c};return c>0&&Dc(l,{x:0,y:0},{x:n,y:r},.5)?l:null}function Bd(e,t,[n,r],i){let{width:a,height:o}=t,s=zd(n,r,a,o);if(!s)return;let c=s.y<n.y;if(s.x<=.5||s.x>=a-.5){let t=s.x>=a-.5;e.textAlign=t?`right`:`left`,e.textBaseline=c?`bottom`:`top`,e.fillText(i,s.x+(t?-4:4),s.y+(c?-1:1)*4);return}let l=s.y<=o/2,u=t.measureText(i)+4,d=s.x>=n.x?s.x+u<=a:s.x-u<0;e.textAlign=d?`left`:`right`,e.textBaseline=l?`top`:`bottom`,e.fillText(i,s.x+(d?4:-4),s.y+(l?1:-1)*4)}let Vd={type:`gann-fan`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`],defaultStyle:()=>({levels:Id.map(e=>({value:e}))}),paint:e=>{let{ctx:t,geometry:n}=e,r=Rd(n),[i]=n.points;n.style.fill&&r.forEach(({ray:e,color:n},a)=>{let o=r[a+1];o&&L(t,[i,e[1],o.ray[1]],S(n,bd))});for(let{ray:t,color:n}of r)Cd(e,t,{color:n});wd(t,n);for(let{ratio:e,color:i,ray:a}of r)t.fillStyle=i,Bd(t,n,a,Ld(e))},hitTest:(e,t,n)=>{let r=Rd(e),[i]=e.points,a=r.flatMap(({ray:e},t)=>{let n=r[t+1];return n?[[i,e[1],n.ray[1]]]:[]});return R(t,r.map(({ray:e})=>e),n)??(e.style.fill&&a.some(e=>Oc(t,e))?P:null)},bounds:e=>N([...e.points,...Rd(e).flatMap(({ray:e})=>e)]),levels:([e,t],n,r,{barIndex:i,timeAt:a})=>{let o=n.toScale(e.price),s=n.toScale(t.price),c=i(e.time),l=i(t.time)-c;return e.time===t.time?[]:z(r.levels,r).filter(({value:e})=>e>0).map(({value:r})=>({key:Ld(r),from:e,to:r<=1?{time:t.time,price:n.fromScale(o+(s-o)*r)}:{time:a(c+l/r),price:t.price},extend:`end`}))}};function Hd(e,t,n){let r=n.price-t.price,i=r>0?`+`:``;return`${`${i}${e.formatValue(r)}`}${t.price===0?``:` (${i}${(r/Math.abs(t.price)*100).toFixed(2)}%)`}`}function Ud(e,t,n){return`${Hd(e,t,n)} · ${e.texts.bars(Gd(e,t,n))}`}function Wd(e,t,n){return e.texts.duration(n.time-t.time)}function Gd(e,t,n){return Math.round(Math.abs(e.barIndex(n.time)-e.barIndex(t.time)))}function Kd(e,t,n,r,i,a){let o=e.style.fontSize+10,s=e.measureText(t)+16,c=Math.min(n.y,r.y)-6-o/2,l=Math.max(n.y,r.y)+6+o/2,u=((a?c-o/2>=0:l+o/2<=e.height)?a:!a)?c:l;return{text:t,x:i-s/2,y:Math.min(Math.max(u,o/2),e.height-o/2)-o/2,width:s,height:o}}function qd(e,t,n){let{ctx:r,geometry:i}=e;r.font=i.textFont,gn(r,t.text,t.x+t.width/2,t.y+t.height/2,{background:n,color:`#ffffff`,paddingX:8,height:t.height,align:`center`,radius:4})}function Jd(e,t,n){return n.price>=t.price?e.theme.up:e.theme.down}function Yd(e,t){let[n,r]=e.points,[i,a]=e.anchors;return{start:n,end:r,color:t.color(e,i,a),arrows:t.arrows(n,r),label:Kd(e,t.label(e,i,a),n,r,(n.x+r.x)/2,t.above(n,r))}}function Xd(e){return{type:e.type,points:2,fields:e.fields,...e.defaultStyle?{defaultStyle:e.defaultStyle}:{},paint:t=>{let{ctx:n,geometry:r}=t,i=Yd(r,e);r.style.fill&&L(n,yu(i.start,i.end),e.fill(r,i.color));for(let[e,n]of i.arrows)Gl(t,e,n,i.color);qd(t,i.label,i.color)},hitTest:(t,n,r)=>{let i=Yd(t,e),{label:a}=i,o=Dc(n,a,{x:a.x+a.width,y:a.y+a.height})||t.style.fill&&Dc(n,i.start,i.end);return R(n,i.arrows,r)??(o?P:null)},bounds:t=>{let{start:n,end:r,label:i}=Yd(t,e);return N([n,r,...Ac(i)])},...e.levels?{levels:e=>_u(e,null)}:{}}}let Zd=(e,t)=>{let n=(e.x+t.x)/2;return[[{x:n,y:e.y},{x:n,y:t.y}]]},Qd=(e,t)=>{let n=(e.y+t.y)/2;return[[{x:e.x,y:n},{x:t.x,y:n}]]},$d=/* @__PURE__ */ Xd({type:`price-range`,fields:[`lineWidth`,`fill`,`fontSize`],color:Jd,fill:(e,t)=>S(t,.14),arrows:Zd,label:Ud,above:(e,t)=>t.y<=e.y,levels:!0}),ef=/* @__PURE__ */ Xd({type:`date-range`,fields:[`color`,`lineWidth`,`fill`,`fillColor`,`fontSize`],defaultStyle:e=>({fillColor:S(e.accent,.12)}),color:e=>e.style.color,fill:e=>e.style.fillColor,arrows:Qd,label:(e,t,n)=>`${e.texts.bars(Gd(e,t,n))} · ${Wd(e,t,n)}`,above:()=>!1,levels:!1}),tf=/* @__PURE__ */ Xd({type:`date-price-range`,fields:[`lineWidth`,`fill`,`fontSize`],color:Jd,fill:(e,t)=>S(t,.14),arrows:(e,t)=>[...Zd(e,t),...Qd(e,t)],label:(e,t,n)=>`${Ud(e,t,n)} · ${Wd(e,t,n)}`,above:()=>!1,levels:!0});function nf(e){let[t,n]=e.points,[r,i]=e.anchors,{style:a,texts:o}=e,s=[Hd(e,r,i),`${o.bars(Gd(e,r,i))} · ${o.duration(i.time-r.time)}`,`${mu(t,n).toFixed(2)}°`],c=a.fontSize+4,l=Math.max(...s.map(t=>e.measureText(t)))+12,u=s.length*c-4+12,d=Math.hypot(n.x-t.x,n.y-t.y),[f,p]=d===0?[0,1]:[(t.y-n.y)/d,(n.x-t.x)/d],[m,h]=p<0||p===0&&f>0?[-f,-p]:[f,p],g=(Math.abs(m)*l+Math.abs(h)*u)/2+8,_=(t.x+n.x)/2+m*g-l/2,v=(t.y+n.y)/2+h*g-u/2;return{line:Ec(t,n,e.width,e.height,a.extendLeft,a.extendRight),box:{x:Math.min(Math.max(_,0),Math.max(0,e.width-l)),y:Math.min(Math.max(v,0),Math.max(0,e.height-u)),width:l,height:u,lines:s,lineHeight:c}}}let rf={type:`info-line`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`extendLeft`,`extendRight`,`fontSize`],paint:e=>{let{ctx:t,geometry:n}=e,{line:r,box:i}=nf(n);F(e,e=>{I(e,r,!1)}),t.beginPath(),t.roundRect(i.x,i.y,i.width,i.height,4),t.fillStyle=S(n.style.color,.9),t.fill(),t.font=n.textFont,t.fillStyle=`#ffffff`,t.textAlign=`left`,t.textBaseline=`top`,i.lines.forEach((e,n)=>{t.fillText(e,i.x+6,i.y+6+n*i.lineHeight)})},hitTest:(e,t,n)=>{let{line:r,box:i}=nf(e);return Il(t,r[0],r[1],n)??(Dc(t,i,{x:i.x+i.width,y:i.y+i.height},n)?P:null)},bounds:e=>{let{line:t,box:n}=nf(e);return N([...t,n,{x:n.x+n.width,y:n.y+n.height}])},levels:([e,t],n,r)=>[tu(`line`,e,t,r)]};function af(e){let[t]=e.points,[n]=e.anchors,{style:r}=e,i=e.formatValue(n.price),a=r.fontSize+10,o=e.measureText(i)+16,s=t.x+10,c=t.y-10;return{anchor:t,box:{x:s,y:c-a,width:o,height:a},tail:[t,{x:s,y:c-a/2},{x:s+a/2,y:c}],text:i,font:e.textFont}}let of={type:`price-label`,points:1,fields:[`color`,`textColor`,`fontSize`],defaultStyle:()=>({textColor:`#ffffff`,bold:!0}),paint:e=>{let{ctx:t,geometry:n}=e,r=af(n),{box:i,tail:a}=r;t.beginPath(),t.roundRect(i.x,i.y,i.width,i.height,4),I(t,a,!0),t.fillStyle=n.style.color,t.fill(),t.font=r.font,t.fillStyle=n.style.textColor,t.textAlign=`center`,t.textBaseline=`middle`,t.fillText(r.text,i.x+i.width/2,i.y+i.height/2+.5)},hitTest:(e,t,n)=>{let r=af(e),{box:i}=r;return Dc(t,{x:i.x,y:i.y},{x:i.x+i.width,y:i.y+i.height},n)||Oc(t,r.tail)?P:null},bounds:e=>{let{box:t,anchor:n}=af(e);return{x:n.x,y:t.y,width:t.x+t.width-n.x,height:n.y-t.y}}};function sf(e){let[t]=e.points,n=t.y-22,r=t.x+16;return{pole:{x:t.x,y:n},outline:[{x:t.x,y:n},{x:r,y:n},{x:r-4,y:n+5},{x:r,y:n+10},{x:t.x,y:n+10}]}}let cf={type:`flag-mark`,points:1,fields:[`color`],paint:e=>{let{ctx:t,geometry:n}=e,[r]=n.points,i=sf(n);F(e,e=>{e.moveTo(r.x,r.y),e.lineTo(i.pole.x,i.pole.y)},{lineWidth:1.5,lineStyle:`solid`}),L(t,i.outline,n.style.color)},hitTest:(e,t,n)=>{let[r]=e.points;return Dc(t,{x:r.x,y:r.y-22},{x:r.x+16,y:r.y},n)?P:null},bounds:({points:[e]})=>({x:e.x,y:e.y-22,width:16,height:22})};function lf(e,t){let[n]=e.points,r=t?1:-1,i=(e,t)=>({x:n.x+e,y:n.y+r*t});return{outline:[n,i(8,10),i(3,10),i(3,22),i(-3,22),i(-3,10),i(-8,10)],textAt:i(0,26)}}function uf(e,t,n){if(e.text===``)return null;let r=e.measureText(e.text),i=e.style.fontSize;return{x:t.textAt.x-r/2,y:n?t.textAt.y:t.textAt.y-i,width:r,height:i}}function df(e,t){return{type:e,points:1,fields:[`color`,`text`,`textColor`,`fontSize`,`bold`,`italic`],defaultStyle:e=>({color:t?e.up:e.down}),paint:e=>{let{ctx:n,geometry:r}=e,i=lf(r,t);L(n,i.outline,r.style.color),r.text!==``&&!e.editing&&(n.font=r.textFont,n.fillStyle=r.style.textColor,n.textAlign=`center`,n.textBaseline=t?`top`:`bottom`,n.fillText(r.text,i.textAt.x,i.textAt.y))},hitTest:(e,n,r)=>{let i=lf(e,t),a=uf(e,i,t),o=a!==null&&Dc(n,{x:a.x,y:a.y},{x:a.x+a.width,y:a.y+a.height},r),[s]=e.points;return Dc(n,{x:s.x-8,y:t?s.y:s.y-22},{x:s.x+8,y:t?s.y+22:s.y},r)||o||Oc(n,i.outline)?P:null},bounds:e=>{let n=lf(e,t),r=uf(e,n,t);return N([...n.outline,...r?[{x:r.x,y:r.y},{x:r.x+r.width,y:r.y+r.height}]:[]])}}}let ff=/* @__PURE__ */ df(`arrow-mark-up`,!0),pf=/* @__PURE__ */ df(`arrow-mark-down`,!1),mf=[`color`,`lineWidth`,`fill`,`fillColor`,`textColor`,`fontSize`,`bold`,`italic`];function hf(e,t,n){return[t,n].every(t=>!t||e.y<=t.y)}function gf(e,t,n,r){let{ctx:i,geometry:a}=e,o=a.style.fontSize+8;i.font=a.textFont,gn(i,t,n.x,n.y+(r?-1:1)*(6+o/2),{background:a.style.color,color:a.style.textColor,paddingX:6,height:o,align:`center`,radius:3})}function _f(e,t,n){let{fontSize:r}=e.style,i=Math.max(r+8,r*1.5),a=Math.max(0,...n.map(t=>e.measureText(t)+12));return N(t,Math.max(6+i,a/2))}function vf(e,t,n,r){let{ctx:i,geometry:a}=e,o=a.style.fontSize+6;i.font=E(a.style.fontSize-1,a.fontFamily),gn(i,B(t),(n.x+r.x)/2,(n.y+r.y)/2,{background:a.style.color,color:a.style.textColor,paddingX:5,height:o,align:`center`,radius:3})}function yf(e,t){F(e,e=>{I(e,t,!1)},{lineWidth:1,lineStyle:`dotted`})}function bf(e,t){return Math.abs(t.price-e.price)}let xf=[`X`,`A`,`B`,`C`,`D`];function Sf([e,t,n,r,i]){return{xb:bf(t,n)/bf(e,t),ac:bf(n,r)/bf(t,n),bd:bf(r,i)/bf(n,r),xd:bf(t,i)/bf(e,t)}}let Cf={type:`xabcd-pattern`,points:5,fields:mf,defaultStyle:e=>({fillColor:S(e.accent,.12),textColor:`#ffffff`}),paint:e=>{let{ctx:t,geometry:n}=e,{points:r}=n,[i,a,o,s,c]=r;n.style.fill&&(L(t,[i,a,o],n.style.fillColor),L(t,[o,s,c],n.style.fillColor));let l=Sf(n.anchors),u=[[l.xb,i,o],[l.ac,a,s],[l.bd,o,c],[l.xd,i,c]];for(let[,t,n]of u)yf(e,[t,n]);F(e,e=>{I(e,r,!1)},{lineStyle:`solid`});for(let[t,n,r]of u)Number.isFinite(t)&&vf(e,t,n,r);let d=[[`X`,i,void 0,a],[`A`,a,i,o],[`B`,o,a,s],[`C`,s,o,c],[`D`,c,s,void 0]];for(let[t,n,r,i]of d)gf(e,t,n,hf(n,r,i))},hitTest:(e,t,n)=>{let[r,i,a,o,s]=e.points;return R(t,M(e.points,!1),n)??(e.style.fill&&(Oc(t,[r,i,a])||Oc(t,[a,o,s]))?P:null)},bounds:e=>_f(e,e.points,xf)};function wf([e,t,n,r]){return{ac:bf(t,n)/bf(e,t),bd:bf(n,r)/bf(t,n)}}let Tf={type:`abcd-pattern`,points:4,fields:[`color`,`lineWidth`,`textColor`,`fontSize`,`bold`,`italic`],defaultStyle:()=>({textColor:`#ffffff`}),paint:e=>{let{points:t}=e.geometry,[n,r,i,a]=t,o=wf(e.geometry.anchors),s=[[o.ac,n,i],[o.bd,r,a]];for(let[,t,n]of s)yf(e,[t,n]);F(e,e=>{I(e,t,!1)},{lineStyle:`solid`});for(let[t,n,r]of s)Number.isFinite(t)&&vf(e,t,n,r);let c=[[`A`,n,void 0,r],[`B`,r,n,i],[`C`,i,r,a],[`D`,a,i,void 0]];for(let[t,n,r,i]of c)gf(e,t,n,hf(n,r,i))},hitTest:(e,t,n)=>R(t,M(e.points,!1),n),bounds:e=>_f(e,e.points,[`A`,`B`,`C`,`D`])};function Ef(e,t,n,r){let i={x:t.x-e.x,y:t.y-e.y},a={x:r.x-n.x,y:r.y-n.y},o=i.x*a.y-i.y*a.x;if(o===0)return null;let s=(i.y*(n.x-e.x)-i.x*(n.y-e.y))/o;return s>=0&&s<=1?{x:n.x+a.x*s,y:n.y+a.y*s}:null}function Df(e,t,n){return{x:n.x,y:e.x===t.x?e.y:e.y+(t.y-e.y)*(n.x-e.x)/(t.x-e.x)}}function Of(e){let{points:t}=e,[n,r,i,a,o,s,c]=t,l=Ef(i,o,n,r)??Df(i,o,n),u=Ef(i,o,s,c)??Df(i,o,c);return{points:t,neckline:[l,u],areas:[[l,r,i],[i,a,o],[o,s,u]]}}let kf={type:`head-and-shoulders`,points:7,fields:mf,defaultStyle:e=>({fillColor:S(e.accent,.12),textColor:`#ffffff`}),paint:e=>{let{ctx:t,geometry:n}=e,r=Of(n);if(n.style.fill)for(let e of r.areas)L(t,e,n.style.fillColor);yf(e,r.neckline),F(e,e=>{I(e,r.points,!1)},{lineStyle:`solid`});let{texts:i}=n,[,a,o,s,c,l,u]=r.points,d=[[i.leftShoulder,a,r.points[0],o],[i.head,s,o,c],[i.rightShoulder,l,c,u]];for(let[t,n,r,i]of d)gf(e,t,n,hf(n,r,i))},hitTest:(e,t,n)=>{let r=Of(e);return R(t,[...M(r.points,!1),r.neckline],n)??(e.style.fill&&r.areas.some(e=>Oc(t,e))?P:null)},bounds:e=>{let t=Of(e),{texts:n}=e;return _f(e,[...t.points,...t.neckline],[n.leftShoulder,n.head,n.rightShoulder])},levels:([,,e,,t])=>[{key:`neckline`,from:e,to:t,extend:`end`}]},Af=[`I`,`II`,`III`,`IV`,`V`],jf=[`arabic`,`roman`,`arabic`,`small`,`arabic`],Mf=[`circle`,`parentheses`,`plain`];function Nf(e,t,n,r){let i=Ms.indexOf(e),a=jf[Math.floor(i/3)]??`arabic`,o=Mf[i%3]??`plain`,s=r?.[t-1]??String.fromCharCode(65+t-1),c=n?a===`arabic`?s:s.toLowerCase():a===`arabic`?String(t):a===`roman`?Af[t-1]??``:(Af[t-1]??``).toLowerCase();return{text:o===`parentheses`?`(${c})`:c,circled:o===`circle`}}function Pf(e,t,n,r){let{ctx:i,geometry:a}=e,{style:o}=a;i.font=a.textFont;let s=Math.max(o.fontSize*.75,(a.measureText(t.text)+6)/2),c=n.y+(r?-1:1)*(6+s);t.circled&&F(e,e=>{e.arc(n.x,c,s,0,Math.PI*2)},{lineWidth:1,lineStyle:`solid`}),i.fillStyle=o.color,i.textAlign=`center`,i.textBaseline=`middle`,i.fillText(t.text,n.x,c+.5)}function Ff(e,t,n,r){return{type:e,points:t+1,fields:[`color`,`lineWidth`,`degree`,`fontSize`],paint:e=>{let{points:t,style:i}=e.geometry;F(e,e=>{I(e,t,!1)},{lineStyle:`solid`}),M(t,!1).forEach(([a,o],s)=>{Pf(e,Nf(i.degree,s+1,n,r),o,hf(o,a,t[s+2]))})},hitTest:(e,t,n)=>R(t,M(e.points,!1),n),bounds:e=>_f(e,e.points,Array.from({length:t},(t,i)=>Nf(e.style.degree,i+1,n,r).text))}}let If=/* @__PURE__ */ Ff(`elliott-impulse`,5,!1),Lf=/* @__PURE__ */ Ff(`elliott-correction`,3,!0),Rf=/* @__PURE__ */ Ff(`elliott-triangle`,5,!0),zf=/* @__PURE__ */ Ff(`elliott-double-combo`,3,!0,`WXY`),Bf=/* @__PURE__ */ Ff(`elliott-triple-combo`,5,!0,`WXYXZ`);function Vf(e,t){let[n,r,i]=e.points,a=t===`pivot`?n:{x:t===`schiff`?n.x:(n.x+r.x)/2,y:(n.y+r.y)/2},o={x:(r.x+i.x)/2,y:(r.y+i.y)/2},s={x:o.x-a.x,y:o.y-a.y};if(Math.hypot(s.x,s.y)<1)return null;let{width:c,height:l}=e,u=e=>wc(e,{x:e.x+s.x,y:e.y+s.y},c,l,`ray`),d=u(a),f=u(r),p=u(i);return{handle:a===n?null:[n,a],median:d,upper:f,lower:p,base:[r,i],area:[r,f[1],p[1],i]}}function Hf(e,t){let n=e=>[e.median,e.upper,e.lower,e.base,...e.handle?[e.handle]:[]];return{type:e,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:S(e.accent,.08)}),paint:e=>{let r=Vf(e.geometry,t);r&&(e.geometry.style.fill&&L(e.ctx,r.area,e.geometry.style.fillColor),F(e,e=>{for(let t of n(r))I(e,t,!1)}))},hitTest:(e,r,i)=>{let a=Vf(e,t);return a?R(r,n(a),i)??(e.style.fill&&Oc(r,a.area)?P:null):null},bounds:e=>{let r=Vf(e,t);return r&&N(n(r).flat())}}}let Uf=/* @__PURE__ */ Hf(`pitchfork`,`pivot`),Wf=/* @__PURE__ */ Hf(`schiff-pitchfork`,`schiff`),Gf=/* @__PURE__ */ Hf(`modified-schiff-pitchfork`,`modified-schiff`);function Kf([e,t,n]){return{start:e.time,end:t.time,entry:e.price,target:t.price,stop:n.price}}function qf(e,t){let n=t?1:-1,r=Math.max(e.end,e.start),i=n*e.target>=n*e.entry?e.target:e.entry,a=n*e.stop<=n*e.entry?e.stop:e.entry;return[{time:e.start,price:e.entry},{time:r,price:i},{time:r,price:a}]}function Jf(e,t,n){let r=e.lowerBound(t.start),i=Math.min(e.lowerBound(t.end+1),e.length),a=null,o={kind:`pending`,entered:a,time:t.start,price:t.entry};for(let s=r;s<i;s+=1){let r=e.time(s);if(a===null){e.low(s)<=t.entry&&e.high(s)>=t.entry&&(a=r,o={kind:`open`,entered:a,time:r,price:e.close(s)});continue}let i=n?e.low(s)<=t.stop:e.high(s)>=t.stop,c=n?e.high(s)>=t.target:e.low(s)<=t.target;if(i&&t.stop!==t.entry)return{kind:`stop`,entered:a,time:r,price:t.stop};if(c&&t.target!==t.entry)return{kind:`target`,entered:a,time:r,price:t.target};o={kind:`open`,entered:a,time:r,price:e.close(s)}}return o}function Yf(e,t,n){let r=e===0?0:(n?1:-1)*(t-e)/Math.abs(e)*100;return`${r>0?`+`:``}${r.toFixed(2)}%`}function Xf(e){let[t,n,r]=e.points;return[t.x,n.x].some(e=>Number.isNaN(e))?null:{left:t.x,right:n.x,entry:t.y,target:n.y,stop:r.y}}function Zf(e,t,n,r){return[{x:e,y:n},{x:t,y:n},{x:t,y:r},{x:e,y:r}]}function Qf(e,t,n,r,i){let{ctx:a,geometry:o}=e,s=o.style.fontSize+8;a.font=E(o.style.fontSize,o.fontFamily),gn(a,t,n,Math.min(Math.max(r,s/2),o.height-s/2),{background:i,color:`#ffffff`,paddingX:6,height:s,align:`center`,radius:3})}let $f=/* @__PURE__ */ Rl(64);function ep(e,t,n){let{bars:r,source:i}=e,a=r.lowerBound(t.end+1),o=a<r.length?r.time(a)-1:1/0,{start:s,entry:c,target:l,stop:u}=t;return $f(i,`${s}:${o}:${c}:${l}:${u}:${n}`,()=>Jf(i,{...t,end:o},n))}function tp(e,t,n,r){let i=ep(e,n,r);if(i.entered===null)return null;let a=n=>Math.min(Math.max(t.left,ip(e,n)),t.right);return{outcome:i,from:a(i.entered),to:a(i.time),y:e.valueToY(i.price),gain:(r?1:-1)*(i.price-n.entry)}}function np(e,t){let{ctx:n,geometry:r}=e,i=Xf(r),a=Kf(r.anchors);if(!i)return;let{theme:o}=r;L(n,Zf(i.left,i.right,i.entry,i.target),S(o.up,.16)),L(n,Zf(i.left,i.right,i.entry,i.stop),S(o.down,.16));let s=tp(r,i,a,t);s&&L(n,Zf(s.from,s.to,i.entry,s.y),S(s.gain>=0?o.up:o.down,.22))}function rp(e,t){let{geometry:n}=e,r=Xf(n),i=Kf(n.anchors);if(!r)return;let{theme:a,style:o}=n,s=tp(n,r,i,t);s&&F(e,e=>{e.moveTo(s.from,r.entry),e.lineTo(s.to,s.y)},{color:a.textMuted,lineStyle:`dashed`}),F(e,e=>{e.moveTo(r.left,r.entry),e.lineTo(r.right,r.entry)});let c=(r.left+r.right)/2,l=o.fontSize,u=Math.abs(i.target-i.entry),d=Math.abs(i.entry-i.stop),f=d===0?`—`:(u/d).toFixed(2),{texts:p}=n,m=s?` · ${s.outcome.kind===`open`?p.open:s.outcome.kind===`target`?p.targetHit:p.stopped} ${Yf(i.entry,s.outcome.price,t)}`:``,h=s?s.gain>=0?a.up:a.down:o.color;if(Qf(e,`${p.riskReward} ${f}${m}`,c,r.entry,h),e.hovered||e.selected){let o=l/2+4+4,s=(e,t)=>e<=t?e-o:e+o;Qf(e,`${p.target} ${n.formatValue(i.target)} (${Yf(i.entry,i.target,t)})`,c,s(r.target,r.entry),a.up),Qf(e,`${p.stop} ${n.formatValue(i.stop)} (${Yf(i.entry,i.stop,t)})`,c,s(r.stop,r.entry),a.down)}}function ip(e,t){let[n,r]=e.points,[i,a]=e.anchors,o=e.barIndex(a.time)-e.barIndex(i.time);if(o===0)return n.x;let s=(e.barIndex(t)-e.barIndex(i.time))/o;return n.x+s*(r.x-n.x)}function ap(e){let t=Xf(e);if(!t)return[];let n=(t.left+t.right)/2,r=e=>[{x:t.left,y:e},{x:t.right,y:e}];return[{id:`start`,x:t.left,y:t.entry,cursor:`ew-resize`},{id:`end`,x:t.right,y:t.entry,cursor:`ew-resize`},{id:`target`,x:n,y:t.target,cursor:`ns-resize`,line:r(t.target)},{id:`stop`,x:n,y:t.stop,cursor:`ns-resize`,line:r(t.stop)},{id:`entry`,x:n,y:t.entry,cursor:`ns-resize`,line:r(t.entry),marker:!1}]}function op(e,t,n,r){let i=Kf(e);switch(t){case`start`:return qf({...i,start:Math.min(n.time,i.end)},r);case`entry`:{let e=Math.min(i.target,i.stop),t=Math.max(i.target,i.stop);return qf({...i,entry:Math.min(Math.max(n.price,e),t)},r)}case`target`:return qf({...i,target:n.price},r);case`stop`:return qf({...i,stop:n.price},r);case`end`:return qf({...i,end:n.time},r);default:return e}}function sp(e,t){return{type:e,points:3,place:2,mainPane:!0,fields:[`fontSize`],complete:([e,n])=>{let r=(t?1:-1)*Math.abs(n.price-e.price);return qf({start:Math.min(e.time,n.time),end:Math.max(e.time,n.time),entry:e.price,target:e.price+r,stop:e.price-r},t)},paintBelow:e=>{np(e,t)},paint:e=>{rp(e,t)},hitTest:(e,t,n)=>{let r=Xf(e);if(!r)return null;let i=Zf(r.left,r.right,r.target,r.stop);return Ll(t,M(i,!0),i,n,!0)},bounds:e=>{let t=Xf(e);if(!t)return null;let n=e.style.fontSize+8+4,r=Math.min(t.target,t.stop)-n,i=Math.max(t.target,t.stop)+n;return{x:t.left,y:r,width:t.right-t.left,height:i-r}},handles:ap,moveHandle:(e,n,r)=>op(e,n,r,t),axisMarks:e=>{let t=Kf(e);return{prices:[t.target,t.entry,t.stop],times:[t.start,t.end]}}}}let cp=/* @__PURE__ */ sp(`long-position`,!0),lp=/* @__PURE__ */ sp(`short-position`,!1);function up(e,t,n,r){let i=e.lowerBound(Math.min(t,n)),a=e.lowerBound(Math.max(t,n)+1)-1,o=a-i+1;if(o<2)return null;let s=t=>zl(e,t,r),c=0;for(let e=i;e<=a;e+=1)c+=s(e);c/=o;let l=(o-1)/2,u=0,d=0;for(let e=i;e<=a;e+=1){let t=e-i-l;u+=t*(s(e)-c),d+=t*t}let f=u/d,p=c-f*l,m=0,h=0;for(let e=i;e<=a;e+=1){let t=s(e);m+=(t-p-f*(e-i))**2,h+=(t-c)**2}let g=f*f*d,_=h===0||g===0?0:Math.abs(u*f)/Math.sqrt(h*g);return{first:i,last:a,start:p,slope:f,deviation:Math.sqrt(m/(o-1)),pearson:_}}let dp=/* @__PURE__ */ Rl(64);function fp(e,t,n,r){return dp(e,`${t}:${n}:${r}`,()=>up(e,t,n,r))}function pp(e){return z(e.levels,e).sort((e,t)=>t.value-e.value)}function mp(e){let[t,n]=e.anchors,{bars:r,style:i}=e,a=fp(r,t.time,n.time,i.source);if(!a)return null;let o=e.timeToX(r.time(a.first)),s=e.timeToX(r.time(a.last)),c=(t,n)=>({x:n===a.first?o:s,y:e.valueToY(a.start+a.slope*(n-a.first)+t*a.deviation)});return{fit:a,lines:pp(i).map(t=>{let n=c(t.value,a.first),r=c(t.value,a.last);return{level:t,line:i.extendRight?wc(n,r,e.width,e.height,`ray`):[n,r]}}),ends:t.time<=n.time?[c(0,a.first),c(0,a.last)]:[c(0,a.last),c(0,a.first)]}}function hp(e){let t=e.lines[0]?.line,n=e.lines.at(-1)?.line;return t&&n?[t[0],t[1],n[1],n[0]]:[]}let gp={type:`regression-trend`,points:2,mainPane:!0,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`extendRight`,`source`],defaultStyle:()=>({levels:[{value:2},{value:0},{value:-2}]}),paint:e=>{let{ctx:t,geometry:n}=e,r=mp(n);if(!r)return;let{style:i}=n;i.fill&&r.lines.forEach(({level:e,line:n},i)=>{let a=r.lines[i+1];a&&L(t,[n[0],n[1],a.line[1],a.line[0]],S(e.color,.1))});for(let{level:t,line:n}of r.lines)F(e,e=>{I(e,n,!1)},{color:t.color,...t.value===0?{lineStyle:`dashed`}:{}});let a=r.lines.at(-1)?.line;a&&(t.font=E(i.fontSize-1,n.fontFamily),t.fillStyle=i.color,t.textAlign=`left`,t.textBaseline=`top`,t.fillText(B(r.fit.pearson),a[0].x,a[0].y+4))},hitTest:(e,t,n)=>{let r=mp(e);return r?Ll(t,r.lines.map(({line:e})=>e),hp(r),n,e.style.fill):null},handles:e=>(mp(e)?.ends??[]).map((e,t)=>({id:String(t),x:e.x,y:e.y,cursor:`ew-resize`})),moveHandle:(e,t,n)=>e.map((e,r)=>String(r)===t?{...e,time:n.time}:e),axisMarks:([e,t])=>({prices:[],times:[e.time,t.time]}),bounds:e=>{let t=mp(e),n=t?.lines.at(-1)?.line;return t&&n?N([...t.lines.flatMap(({line:e})=>e),{x:n[0].x+e.measureText(B(t.fit.pearson)),y:n[0].y+4+e.style.fontSize}]):null},levels:([e,t],n,r,{bars:i})=>{let a=fp(i,e.time,t.time,r.source),[o,...s]=pp(r);return[o,s.pop(),...s].filter(e=>e!==void 0).map(n=>{let o=B(n.value);if(!a)return{key:o,from:e,to:t,valueAt:()=>NaN};let s=e=>({time:i.time(e),price:a.start+a.slope*(e-a.first)+n.value*a.deviation});return{key:o,from:s(a.first),to:s(a.last),extend:r.extendRight?`end`:`none`}})}};function _p(e,t,n){let r=e.lowerBound(t),i=Math.max(0,e.length-r),a=new Float64Array(i),o=new Float64Array(i),s=0,c=0,l=0;for(let t=0;t<i;t+=1){let i=r+t,u=zl(e,i,n),d=e.volume(i);s+=d,c+=u*d,l+=u*u*d;let f=c/s;a[t]=f,o[t]=Math.sqrt(Math.max(0,l/s-f*f))}return{first:r,vwap:a,deviation:o}}let vp=/* @__PURE__ */ Rl(64);function yp(e,t,n){return vp(e,`${t}:${n}`,()=>_p(e,t,n))}function bp(e){return z(e.levels,e).filter(e=>e.value>0)}function xp(e){let[t]=e.anchors,{bars:n,style:r}=e,i=yp(n,t.time,r.source);if(i.vwap.length===0)return null;let a=e.timeToX(n.time(i.first)),o=i.vwap.length>1?e.timeToX(n.time(i.first+1))-a:1,s=Math.max(0,Math.floor(-a/o)-1),c=Math.min(i.vwap.length-1,Math.ceil((e.width-a)/o)+1),l=t=>{let n=[];for(let r=s;r<=c;r+=1){let i=e.valueToY(t(r));Number.isFinite(i)&&n.push({x:a+r*o,y:i})}return n},u=e=>i.vwap[e]??NaN,d=e=>i.deviation[e]??NaN;return{vwap:l(u),bands:bp(r).map(e=>({color:e.color,upper:l(t=>u(t)+e.value*d(t)),lower:l(t=>u(t)-e.value*d(t))}))}}function Sp(e){return[...e.upper,...[...e.lower].reverse()]}let Cp=[ru,iu,au,ou,cu,lu,du,wu,ku,Uu,Mu,Nu,$d,cp,lp,Uf,Wu,ef,tf,rd,$u,pu,gu,gp,qu,Yu,Fd,Ad,ld,dd,fd,of,cf,Cf,kf,If,Lf,{type:`anchored-vwap`,points:1,mainPane:!0,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`source`],defaultStyle:e=>({source:`hlc3`,levels:[{value:1,color:e.up},{value:2,color:e.up,visible:!1},{value:3,color:e.up,visible:!1}]}),paint:e=>{let{ctx:t,geometry:n}=e,r=xp(n);if(r){if(n.style.fill)for(let e of r.bands)L(t,Sp(e),S(e.color,.06));for(let t of r.bands)F(e,e=>{I(e,t.upper,!1),I(e,t.lower,!1)},{color:t.color});F(e,e=>{I(e,r.vwap,!1)})}},hitTest:(e,t,n)=>{let r=xp(e);if(!r)return null;let i=[r.vwap,...r.bands.flatMap(e=>[e.upper,e.lower])],a=e.style.fill&&r.bands.some(e=>Oc(t,Sp(e)));return R(t,i.flatMap(e=>M(e,!1)),n)??(a?P:null)},handles:e=>{let[t]=e.anchors,n=yp(e.bars,t.time,e.style.source),r=n.vwap[0];return r===void 0?[]:[{id:`0`,x:e.timeToX(e.bars.time(n.first)),y:e.valueToY(r),cursor:`ew-resize`}]},moveHandle:([e],t,n)=>[{...e,time:n.time}],axisMarks:([e])=>({prices:[],times:[e.time]}),bounds:e=>{let t=xp(e);return t&&N([...t.vwap,...t.bands.flatMap(e=>[...e.upper,...e.lower])])},levels:([e],t,n,{bars:r})=>{let i=(t,i)=>{let a=yp(r,e.time,n.source),o=r.lowerBound(t),s=o-a.first;return o<r.length&&r.time(o)===t&&s>=0&&s<a.vwap.length?i(a,s):NaN},a=(t,n)=>({key:t,from:e,to:e,valueAt:e=>i(e,n)}),o=(e,t)=>e.vwap[t]??NaN,s=(e,t)=>e.deviation[t]??NaN;return[a(`vwap`,o),...bp(n).flatMap(e=>[a(B(e.value),(t,n)=>o(t,n)+e.value*s(t,n)),a(B(-e.value),(t,n)=>o(t,n)-e.value*s(t,n))])]}},rf,Wf,Gf,Vd,Tf,Rf,zf,Bf,vd,ed,gd,ff,pf],wp=/* @__PURE__ */ new WeakMap;function Tp(e,t){let n=[],r=e.shift(t.high),i=e.shift(t.low);for(let a=0;a<e.length;a+=1){let o=e.value(t.high,a),s=e.value(t.low,a);Number.isNaN(o)||n.push({column:t.high,at:a,bar:a+r,price:o,high:!0}),Number.isNaN(s)||n.push({column:t.low,at:a,bar:a+i,price:s,high:!1})}return r===i?n:n.sort((e,t)=>e.bar-t.bar||Number(t.high)-Number(e.high))}function Ep(e,t,n){let{bars:r}=e,i=0;for(let e=Math.max(0,t+1);e<=Math.min(n,r.length-1);e+=1)i+=r.volume(e);return i}function Dp(e,t,n){let r=n?.price??t.price;return{...t,change:t.price-r,previous:r,volume:Ep(e,n?.bar??-1,t.bar)}}function Op(e,t){let n=wp.get(e);if(n?.version===e.version&&n.columns.high===t.high&&n.columns.low===t.low)return n.pivots;let r=[];for(let n of Tp(e,t))r.at(-1)?.high===n.high?r[r.length-1]=n:r.push(n);let i=[];for(let t of r)i.push(Dp(e,t,i.at(-1)));return wp.set(e,{version:e.version,columns:t,pivots:i}),i}function kp(e,t,n){let r=e.length-1,i=e.value(t.own,r);if(!n||Number.isNaN(i))return null;let a=r+e.shift(t.own);return Dp(e,{column:t.own,at:r,bar:a,price:i,high:!n.high},n)}function Ap(e,t,n){let r=0,i=t.length;for(;r<i;){let a=Math.floor((r+i)/2),o=t[a];e.indexOf(o.column,o.at)<n?r=a+1:i=a}return r}var jp=class{plot;from;to;points;indices;constructor(e,t,n,r,i){this.plot=t,this.from=r,this.to=i;let a=Op(e,n),o=Math.max(0,Ap(e,a,r)-1),s=Math.min(a.length,Ap(e,a,i+1)+1),c=t.extend&&s===a.length?kp(e,n,a.at(-1)):null;this.points=[...a.slice(o,s),...c?[c]:[]],this.indices=this.points.map(t=>e.indexOf(t.column,t.at))}include(e){this.points.forEach((t,n)=>{this.inView(n)&&y(e,t.price)})}emit(e,t,n,r,i,a,o){let{timeScale:s,seriesTypes:c,options:l}=t,u=r.take(e);u.reset(this.points.length),this.points.forEach((e,t)=>{u.pushValue(s.indexToX(this.indices[t]??NaN),n.valueToY(e.price),e.high)}),o.push({kind:`series`,definition:c.require(`line`),style:i,points:u,valueToY:e=>n.valueToY(e),bars:null,first:this.from,transform:null});let d=this.labels(t,n,a);if(d.length>0){let e=l.font.size-1;o.push({kind:`labels`,labels:d,font:E(e,l.font.family),lineHeight:Math.round(e*1.3)})}}inView(e){let t=this.indices[e]??NaN;return t>=this.from&&t<=this.to}labels(e,t,n){let r=this.plot.labels??{};if(!r.price&&!r.change&&!r.volume)return[];let{theme:i}=e.options;return this.points.flatMap((a,o)=>this.inView(o)?[{x:e.timeScale.indexToX(this.indices[o]??NaN),y:t.valueToY(a.price),text:Mp(a,r,e,n),above:a.high,color:a.high?i.up:i.down}]:[])}};function Mp(e,t,{formatter:n},r){let i=[];if(t.price&&i.push(D(n,e.price,r)),t.change){let a=t.change===`percent`?`${D(n,e.change*100/e.previous,{kind:`decimal`,precision:2})}%`:D(n,e.change,r);i.push(`(${e.change>0?`+`:``}${a})`)}let a=[i.join(` `)];return t.volume&&a.push(D(n,e.volume,{kind:`compact`})),a.filter(e=>e!==``).join(`
|
|
7
|
-
`)}function Np(e,t,n,r,i){let a=n=>!Number.isNaN(e(n))&&!Number.isNaN(t(n)),o=e=>a(e)&&a(e+1)&&(!n||n(e)===n(e+1)),s=[];for(let n=r;n<=i;n+=1){if(!a(n))continue;let r=n,i=n;for(;o(r-1);)--r;for(;o(i);)i+=1;let c=-1/0,l=1/0;for(let n=r;n<=i;n+=1)c=Math.max(c,e(n)),l=Math.min(l,t(n));s.push({start:r,end:i,high:c,low:l}),n=i}return s}function Pp(e,t){return e.find(({key:e,plot:n})=>n.kind===`candles`&&(e===t.key||n.open===t.key||n.high===t.key||n.low===t.key))||null}function Fp(e,t){return e.series.reader(e.outputs.findIndex(e=>e.key===t))}function Ip(e,t,n){let r=t.plot;return!(Fp(e,t.key)(n)<Fp(e,r.open)(n))}var Lp=class{sources;entry;range;format;colors;pool;pane;scale;constructor(e,t,n,r,i,a){this.sources=e,this.entry=t,this.range=n,this.format=r,this.colors=i,this.pool=a,this.pane=t.pane,this.scale=t.scale}reader(e){return this.entry.series.reader(e)}startOf(e){return typeof e==`number`?()=>e:this.reader(this.entry.outputs.findIndex(t=>t.key===e))}valueTexts(e,t,n,r){let i=this.reader(e),a=Wp(t,this.format),o=t.plot.kind===`marker`?t.plot.text:void 0,s=[];for(let e=n;e<=r;e+=1){let t=i(e);s.push(Number.isNaN(t)?``:[o,D(this.sources.formatter,t,a)].filter(Boolean).join(` `))}return s}zigzag(e,t,n,r){let i=e=>this.entry.outputs.findIndex(t=>t.key===e),a={own:e,high:i(t.high),low:i(t.low)};return new jp(this.entry.series,t,a,n,r)}lineStyle(e){let{plot:t}=e,n=t.kind===`line`||t.kind===`zigzag`?t:null;return{color:this.colors.get(e.key)??this.sources.options.theme.text,lineWidth:this.entry.styles[e.key]?.lineWidth??n?.width??1.25,lineStyle:this.entry.styles[e.key]?.lineStyle??n?.style??`solid`}}boxRuns(e,t,n,r){let i=t.group===void 0?null:this.startOf(t.group);return Np(this.reader(e),this.startOf(t.from),i,n,r)}window(e){let{series:t,outputs:n}=this.entry,r=this.sources.timeScale.logicalRange(),i=n.map((e,n)=>t.reach(n));return{from:Math.max(Math.floor(r.from+.5)-e,-Math.max(0,...i.map(e=>e.before))),to:Math.min(Math.ceil(r.to-.5)+e,this.sources.bars.length-1+Math.max(0,...i.map(e=>e.after)))}}include(e,t){let{outputs:n,definition:r,styles:i}=this.entry,{from:a,to:o}=this.window(0);n.forEach((n,r)=>{let{plot:s}=n;if(!Hp(this.entry,n)||!t&&(i[n.key]?.autoscale??n.autoscale)===!1)return;if(s.kind===`zigzag`){this.zigzag(r,s,a,o).include(e);return}let c=this.reader(r),l=s.kind===`columns`?this.startOf(s.from):null,u=s.kind===`candles`?[s.open,s.high,s.low].map(e=>Fp(this.entry,e)):[];for(let t=a;t<=o;t+=1){let n=c(t);y(e,n),l&&!Number.isNaN(n)&&y(e,l(t)),Number.isNaN(n)||u.forEach(n=>{y(e,n(t))})}if(n.plot.kind===`histogram`)y(e,0);else if(n.plot.kind===`box`)for(let t of this.boxRuns(r,n.plot,a,o))y(e,t.high),y(e,t.low)}),r.range&&(y(e,r.range.min),y(e,r.range.max))}firstValue(){let e=this.reader(0),{to:t}=this.window(0);for(let n=this.range.from;n<=t;n+=1){let t=e(n);if(Number.isFinite(t))return t}return null}candles(e,t,n,r,i,a){let{timeScale:o}=this.sources,s=this.reader(t),[c,l,u]=[n.open,n.high,n.low].map(e=>Fp(this.entry,e));for(let t=i;t<=a;t+=1){let n=[c(t),l(t),u(t),s(t)];if(n.every(e=>!Number.isNaN(e))){let[i,a,s,c]=n;e.pushOhlc(o.indexToX(t),r.valueToY(i),r.valueToY(a),r.valueToY(s),r.valueToY(c),NaN,c>=i)}}}emit(e,t){let{outputs:n,fills:r,definition:i,params:a,id:o,series:s}=this.entry,{timeScale:c,options:l,seriesTypes:u}=this.sources,d=l.theme,{from:f,to:p}=this.window(1),m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Map,g=new Set(r.flatMap(e=>[e.from,e.to]));n.forEach((t,n)=>{let{plot:r}=t,i=r.kind===`hidden`&&g.has(t.key)&&this.entry.styles[t.key]?.visible!==!1;if(!Hp(this.entry,t)&&!i||r.kind===`zigzag`)return;let a=this.pool.take(`indicator:${o}:${t.key}`);if(a.reset(p-f+1),r.kind===`candles`){this.candles(a,n,r,e,f,p),m.set(t.key,a);return}if(r.kind===`columns`){let n=this.startOf(r.from),i=this.pool.take(`indicator:${o}:${t.key}:from`);i.reset(p-f+1);for(let t=f;t<=p;t+=1)i.pushValue(c.indexToX(t),e.valueToY(n(t)),!0);h.set(t.key,i)}let l=this.reader(n),u=s.reader(n,1),d=e=>s.rises(e),_=r.kind===`marker`;for(let t=f;t<=p;t+=1){let n=_&&!s.opens(t)?NaN:l(t),i=r.kind===`histogram`?Bp(r.colorBy,l,u,d,t):!(n<l(t-1));a.pushValue(c.indexToX(t),e.valueToY(n),i)}m.set(t.key,a)}),r.forEach(r=>{let i=m.get(r.from),a=m.get(r.to);if(i&&a){let o=r.colorBy===`higher`?.14:.08,s=e=>S(this.colors.get(e)??d.textMuted,o),c=s(r.from),l=r.colorBy===`higher`?s(r.to):c,u=e=>n.find(t=>t.key===e)?.plot.kind===`segments`;t.push({kind:`fill`,above:e.inverted?l:c,below:e.inverted?c:l,from:i,to:a,steps:u(r.from)&&u(r.to)})}}),(this.entry.levels??i.levels?.(a)??[]).forEach(n=>{let r=e.valueToY(n);Number.isFinite(r)&&t.push({kind:`reference`,y:r,color:S(d.textMuted,.6)})}),n.forEach((n,r)=>{let{plot:i}=n;if(i.kind===`zigzag`&&Hp(this.entry,n)){this.zigzag(r,i,f,p).emit(`indicator:${o}:${n.key}`,this.sources,e,this.pool,this.lineStyle(n),Wp(n,this.format),t);return}let a=m.get(n.key);if(a){if(n.plot.kind===`box`){let i=c.barSpacing;t.push({kind:`boxes`,boxes:this.boxRuns(r,n.plot,f,p).map(t=>{let n=e.valueToY(t.high),r=e.valueToY(t.low);return{x:c.indexToX(t.start)-i/2,y:Math.min(n,r),width:(t.end-t.start+1)*i,height:Math.abs(r-n)}}),color:this.colors.get(n.key)??d.text})}else if(n.plot.kind===`candles`){let r=this.colors.get(n.key);t.push({kind:`series`,definition:u.require(`candles`),style:Ar(r??d.up,r??d.down),points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null})}else if(n.plot.kind===`histogram`){let r=this.colors.get(n.key),[i,o]=r?[r,r]:Rp(n.plot.colorBy,d);t.push({kind:`series`,definition:u.require(`columns`),style:{upColor:i,downColor:o,base:0,widthRatio:.6},points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null})}else n.plot.kind===`line`?t.push({kind:`series`,definition:u.require(`line`),style:this.lineStyle(n),points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null}):n.plot.kind===`segments`?t.push({kind:`segments`,points:a,color:this.colors.get(n.key)??d.text,lineWidth:this.entry.styles[n.key]?.lineWidth??n.plot.width??1.25,lineStyle:this.entry.styles[n.key]?.lineStyle??n.plot.style??`solid`}):n.plot.kind===`columns`?t.push({kind:`columns`,points:a,from:h.get(n.key)??a,color:this.colors.get(n.key)??d.text,width:n.plot.width??.6,hollow:n.plot.hollow??!1}):n.plot.kind===`marker`&&t.push({kind:`markers`,points:a,color:this.colors.get(n.key)??zp(n.plot,d),shape:n.plot.shape??null,text:n.plot.value?this.valueTexts(r,n,f,p):n.plot.text??``,size:n.plot.size??5,font:E(l.font.size-1,l.font.family)})}})}};function Rp(e,t){return e===`bar`?[t.volumeUp,t.volumeDown]:[t.up,t.down]}function zp(e,t){let n=e.kind===`marker`&&e.shape?sr(e.shape):0;return n>0?t.buy:n<0?t.sell:t.text}function Bp(e,t,n,r,i){switch(e){case`bar`:return r(i);case`sign`:return t(i)>=0;case`change`:return!(t(i)<=n(i))}}function Vp(e,t,n,r,i,a){let{plot:o}=t,s=Pp(e.outputs,t);if(s)return i.get(s.key)??(Ip(e,s,r)?a.up:a.down);let c=i.get(t.key);if(c)return c;if(o.kind===`histogram`){let{series:t}=e,[i,s]=Rp(o.colorBy,a);return Bp(o.colorBy,t.reader(n),t.reader(n,1),e=>t.rises(e),r)?i:s}return zp(o,a)}function Hp(e,t){return t.plot.kind!==`hidden`&&e.styles[t.key]?.visible!==!1}function Up(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=0;for(let{key:t,plot:n}of e.outputs)n.kind===`box`?r.set(n.from,t):n.kind===`candles`&&[n.open,n.high,n.low].forEach(e=>{r.set(e,t)});for(let a of e.outputs){let o=a.color??(a.themeColor&&t[a.themeColor]),{plot:s}=a,c=s.kind===`hidden`&&a.legend===!1,l=s.kind===`marker`&&s.shape&&sr(s.shape)!==0,u=s.kind===`histogram`||s.kind===`candles`,d=!o&&!u&&!c&&!l&&!r.has(a.key)?Sn(t.palette,i++):void 0,f=e.colors[a.key]??o??d;f&&n.set(a.key,f)}return r.forEach((e,t)=>{let r=n.get(e);r&&!n.has(t)&&n.set(t,r)}),n}function Wp(e,t){return e.precision===void 0?t:{kind:`decimal`,precision:e.precision}}function Gp(e,t){let n=e.definition.precision;return n===`price`?e.upstream?Gp(e.upstream,t):t:n===`volume`?{kind:`compact`}:{kind:`decimal`,precision:n}}function Kp(e){return(t,n,r,i)=>e.list().flatMap(e=>e.visible?(e.series.sync(),[new Lp(t,e,n,Gp(e,r),Up(e,t.options.theme),i)]):[])}let qp=[`line`,`segments`,`box`,`histogram`,`columns`,`candles`,`marker`,`zigzag`,`hidden`];function Jp(e,t){typeof e[t]!=`function`&&n(`definition.${t} must be a function.`)}function Yp(e){h(`indicator definition`,e),p(`definition.type`,e.type);let t=`create`in e,r=`compute`in e&&`lookback`in e;!t&&!r&&n(`An indicator definition needs create(), or lookback() and compute().`),(t?[`create`]:[`lookback`,`compute`]).forEach(t=>{Jp(e,t)}),p(`definition.name`,e.name),m(`definition.pane`,e.pane,[`main`,`new`]),h(`definition.params`,e.params);for(let[t,n]of Object.entries(e.params))n.legend!==void 0&&f(`definition.params.${t}.legend`,n.legend);typeof e.precision==`string`?m(`definition.precision`,e.precision,[`price`,`volume`]):d(`definition.precision`,e.precision,{min:0,max:12,integer:!0}),typeof e.outputs!=`function`&&n(`An indicator definition needs an outputs() function.`),e.source!==void 0&&m(`definition.source`,e.source,Yt);for(let t of[`levels`,`fills`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`definition.${t} must be a function of the parameters.`);e.range!==void 0&&(h(`definition.range`,e.range),d(`definition.range.min`,e.range.min),d(`definition.range.max`,e.range.max))}function Xp(e,t,r){v(`definition.fills of "${r}"`,e);let i=new Set(t.map(e=>e.key));e.forEach((e,t)=>{let a=`definition.fills[${t}]`;h(a,e),(!i.has(e.from)||!i.has(e.to))&&n(`${a} of "${r}" shades from "${e.from}" to "${e.to}", which is no output.`),e.colorBy!==void 0&&m(`${a}.colorBy`,e.colorBy,[`from`,`higher`])})}function Zp(e,t,r){for(let i of[`high`,`low`])r.has(e[i])||n(`The zigzag of ${t} takes its ${i}s from "${e[i]}", which is no output.`);e.extend!==void 0&&f(`${t}: extend`,e.extend),e.labels!==void 0&&(_(`${t}: labels`,e.labels,[`price`,`change`,`volume`]),e.labels.price!==void 0&&f(`${t}: labels.price`,e.labels.price),e.labels.change!==void 0&&e.labels.change!==null&&m(`${t}: labels.change`,e.labels.change,[`absolute`,`percent`]),e.labels.volume!==void 0&&f(`${t}: labels.volume`,e.labels.volume))}function Qp(e,t){v(`outputs of "${t}"`,e);let r=/* @__PURE__ */ new Set;e.forEach((e,i)=>{h(`outputs of "${t}"[${i}]`,e),p(`outputs of "${t}": key`,e.key),r.has(e.key)&&n(`Indicator "${t}" produces the output key "${e.key}" twice; use distinct parameter values.`),r.add(e.key)});for(let{key:i,plot:a,offset:o,themeColor:s,precision:c,autoscale:l}of e){let e=`output "${i}" of "${t}"`;h(`${e}: plot`,a),m(`${e}: kind`,a.kind,qp),l!==void 0&&f(`${e}: autoscale`,l),o!==void 0&&d(`${e}: offset`,o,{integer:!0}),c!==void 0&&d(`${e}: precision`,c,{min:0,max:12,integer:!0}),s!==void 0&&m(`${e}: themeColor`,s,[`up`,`down`]);let u=a.kind===`line`||a.kind===`segments`||a.kind===`zigzag`;if(u&&a.style!==void 0&&m(`${e}: style`,a.style,cn),u&&a.width!==void 0&&d(`${e}: width`,a.width,{min:.5,max:10}),a.kind===`zigzag`&&Zp(a,e,r),a.kind===`histogram`&&m(`${e}: colorBy`,a.colorBy,[`sign`,`change`,`bar`]),a.kind===`box`&&!r.has(a.from)&&n(`The boxes of ${e} reach down to "${a.from}", which is no output.`),a.kind===`box`&&a.group!==void 0&&!r.has(a.group)&&n(`The boxes of ${e} are told apart by "${a.group}", which is no output.`),a.kind===`candles`)for(let t of[`open`,`high`,`low`])r.has(a[t])||n(`The candles of ${e} take their ${t} from "${a[t]}", which is no output.`);a.kind===`columns`?(typeof a.from==`number`?d(`${e}: from`,a.from):r.has(a.from)||n(`The columns of ${e} start at "${a.from}", which is no output.`),a.width!==void 0&&d(`${e}: width`,a.width,{min:0,max:1,exclusiveMin:!0})):a.kind===`marker`&&(a.value!==void 0&&f(`${e}: value`,a.value),a.shape===void 0&&a.text===void 0&&a.value!==!0&&n(`The marker of ${e} needs a shape, a text or the value.`),a.shape!==void 0&&m(`${e}: shape`,a.shape,or),a.size!==void 0&&d(`${e}: size`,a.size,{min:1,max:40}))}}function $p(e,t,r){let{store:i}=t;return{set:n=>{e.run(()=>{t.set(n)})},add:n=>e.run(()=>t.add(n)),update:(n,r)=>{e.run(()=>{t.update(n,r)})},remove:n=>{e.run(()=>{t.remove(n)})},clear:()=>{e.run(()=>{t.set([])})},get:e=>{let t=i.get(e);return t?i.info(t):null},list:()=>i.list().map(e=>i.info(e)),valuesAt:(t,n=e.bars.length-1)=>{let a=i.require(t);a.series.sync();let o=e.frame(),s=Up(a,e.options.theme),c=Gp(a,o.priceFormat);return a.outputs.map((t,i)=>{let o=a.series.drawn(i,n);return{key:t.key,label:r().label(t.label),color:Vp(a,t,i,n,s,e.options.theme),value:Number.isNaN(o)?null:o,text:D(e.formatter,o,Wp(t,c))}})},refresh:(t,n)=>{e.run(()=>{let r=i.require(t),a=n===void 0?-1/0:d(`refresh() from`,n);r.series.refresh(a)&&e.values.reset(),e.invalidate()})},register:t=>{e.run(()=>{Yp(t),i.registry.register(t),e.bus.emit(`typesChange`,{kind:`indicator`,type:t.type,registered:!0})})},unregister:t=>{e.run(()=>{i.registry.require(t);let r=i.list().filter(e=>e.type===t);r.length>0&&n(`The indicators ${r.map(e=>`"${e.id}"`).join(`, `)} are of type "${t}"; remove them first.`),i.registry.unregister(t),e.bus.emit(`typesChange`,{kind:`indicator`,type:t,registered:!1})})},types:()=>i.registry.types(),definition:e=>i.registry.get(e)??null,title:e=>r().title(e),label:e=>r().label(e)}}var em=class{bars;context;constructor(e,t){this.bars=e,this.context=t}barAt(e){return e}indexOf(e){return e}reach(e){return{before:Math.max(0,-e),after:Math.max(0,e)}}},tm=class{market;displayed;frame;feed;decision=null;bucketed=null;sourceRevision=-1;started=/* @__PURE__ */ new Int32Array;matched=/* @__PURE__ */ new Float64Array;matchedCount=0;displayedRevision=-1;barsRevision=-1;constructor(e,t,n){this.market=e,this.displayed=t,this.frame=n,this.feed=gt(e.feed.source,ot)}get bars(){return this.feed.display}context(){return{calendar:this.market.tradingCalendar(),interval:this.frame}}update(){let e=this.source();return e!==null&&(this.follow(e),this.match(),!0)}barAt(e){let t=this.displayed.length-1;return e>=t?this.bars.length-1+Math.ceil((e-t)/this.ratio()):e>=0?(this.started[e]??0)-2:this.barAt(0)-Math.ceil(-e/this.ratio())}indexOf(e){let t=-1,n=Math.max(1,this.displayed.length);for(;this.barAt(t)>=e;)t*=2;for(;this.barAt(n)<e;)n*=2;for(;n-t>1;){let r=Math.floor((t+n)/2);this.barAt(r)<e?t=r:n=r}return n}reach(e){let t=this.ratio();return{before:Math.max(0,(this.barAt(0)-e)*t),after:Math.max(0,e*t)}}ratio(){return Math.max(1,Math.round(this.displayed.length/Math.max(1,this.bars.length)))}source(){let{market:e,frame:t}=this,n=e.sourceInterval(),r=e.timeframe()??n,i=e.timeBased(),a=this.decision;return(a?.source!==n||a.shown!==r||a.timed!==i)&&(this.decision={source:n,shown:r,timed:i,applies:n!==null&&r!==null&&i&&oa(r)<oa(t)&&da(t,n)}),this.decision?.applies?n:null}follow(e){let{market:t,feed:n}=this,r=t.tradingCalendar(),i=t.feed.source;if(this.bucketed?.calendar!==r||!ca(this.bucketed.source,e))n.planRebucket(t.bucketerOf(e,this.frame))(),this.bucketed={calendar:r,source:e};else{let e=i.changesSince(this.sourceRevision);e&&n.follow(e)}this.sourceRevision=i.revision,n.setCutoff(t.feed.cutoffTime())}match(){let{displayed:e,bars:t}=this,n=e.changesSince(this.displayedRevision),r=t.changesSince(this.barsRevision),i=e.length;if(n&&(i=n.kind===`reset`?0:Math.max(0,n.from-1)),r){let t=r.kind===`reset`?0:r.from,n=r.kind===`reset`?-1/0:this.firstMove(t);this.keepTimes(t),n!==1/0&&(i=Math.min(i,Math.max(0,e.lowerBound(n)-1)))}this.displayedRevision=e.revision,this.barsRevision=t.revision,this.count(i)}firstMove(e){let{bars:t,matched:n,matchedCount:r}=this,i=Math.max(t.length,r);for(let a=e;a<i;a+=1){let e=a<r?n[a]??NaN:1/0,i=a<t.length?t.time(a):1/0;if(e!==i)return Math.min(e,i)}return 1/0}keepTimes(e){let{bars:t}=this;if(this.matched.length<t.length){let n=new Float64Array(Math.max(64,t.length,this.matched.length*2));n.set(this.matched.subarray(0,Math.min(e,this.matchedCount))),this.matched=n}for(let n=e;n<t.length;n+=1)this.matched[n]=t.time(n);this.matchedCount=t.length}count(e){let{displayed:t,bars:n}=this,r=t.length-1;if(this.started.length<r){let t=new Int32Array(Math.max(64,r,this.started.length*2));t.set(this.started.subarray(0,e)),this.started=t}let i=e>0?this.started[e-1]??0:0;for(let a=e;a<r;a+=1){let e=t.time(a+1);for(;i<n.length&&n.time(i)<=e;)i+=1;this.started[a]=i}}},nm=class{market;displayed;timeframes=/* @__PURE__ */ new Map;constructor(e,t){this.market=e,this.displayed=new em(t,()=>({calendar:e.tradingCalendar(),interval:e.timeframe()??e.sourceInterval()}))}of(e){if(e===null)return()=>this.displayed;let t=A(e),n=this.timeframes.get(t)??new tm(this.market,this.displayed.bars,e);return this.timeframes.set(t,n),()=>n.update()?n:this.displayed}keep(e){let t=new Set(e.flatMap(e=>e?[A(e)]:[]));for(let e of[...this.timeframes.keys()])t.has(e)||this.timeframes.delete(e)}};function rm(e,t){return t===void 0?0:e.outputs.findIndex(e=>e.key===t)}function im(e,t,r){rm(e.get(t.id)??n(`${r}: unknown indicator "${t.id}".`),t.key)<0&&n(`${r}: indicator "${t.id}" has no output "${String(t.key)}".`)}function am(e){return{check:(t,n)=>{im(e,t,n)},read:(t,n)=>{let r=e.require(t.id);return r.series.sync(),r.series.drawn(rm(r,t.key),n)},paneOf:t=>e.require(t.id).pane,scaleOf:t=>e.require(t.id).scale}}let om={time:0,open:0,high:0,low:0,close:0,volume:0};var sm=class e{capacity;compute;columns;start=0;size=0;empty;constructor(e,t,n,r=Array.from({length:7},()=>new Float64Array(e))){this.capacity=e,this.compute=n,this.columns=r,this.empty=new Float64Array(t).fill(NaN)}get length(){return this.size}bar(e){let t=(this.start+e)%this.capacity,n=e=>this.columns[e]?.[t]??NaN;return{time:n(0),open:n(1),high:n(2),low:n(3),close:n(4),volume:n(5)}}price(e){return this.columns[6]?.[(this.start+e)%this.capacity]??NaN}next(e,t){let n=this.size<this.capacity?(this.start+this.size)%this.capacity:this.start,r=[e.time,e.open,e.high,e.low,e.close,e.volume,t];return this.columns.forEach((e,t)=>{e[n]=r[t]??NaN}),this.size<this.capacity?this.size+=1:this.start=(this.start+1)%this.capacity,this.size===this.capacity?this.compute(this):this.empty}clone(){let t=new e(this.capacity,this.empty.length,this.compute,this.columns.map(e=>e.slice()));return t.start=this.start,t.size=this.size,t}};function cm(e,t,n,r){return`create`in e?e.create(t,r):new sm(e.lookback(t),n,n=>e.compute(n,t,r))}function lm(e,t,r){let i={};t!==void 0&&h(`params`,t);for(let i of Object.keys(t??{}))Object.hasOwn(e.params,i)||n(`Indicator "${r}" has no parameter "${i}".`);for(let[a,o]of Object.entries(e.params)){let e=t?.[a]===void 0?o.default:t[a],s={...o.min===void 0?{}:{min:o.min},...o.max===void 0?{}:{max:o.max},...o.integer?{integer:!0}:{}},c=(e,t)=>{let r=d(e,t,s);return o.options&&!o.options.some(e=>e.value===r)&&n(`${e} must be one of ${o.options.map(e=>`${e.value} (${e.label})`).join(`, `)}, received ${r}.`),r};if(Array.isArray(o.default)){let t=o.default.length===0?0:1;(!Array.isArray(e)||e.length<t||e.length>8)&&n(`Parameter "${a}" of indicator "${r}" must be a list of ${String(t)} to 8 numbers.`),e.forEach((e,t)=>{c(`params.${a}[${t}]`,e)}),i[a]=[...e]}else i[a]=c(`params.${a}`,e)}return i}function um(e,t){return t!==null&&e.calendar===t.calendar&&ca(e.interval,t.interval)}var dm=class{definition;params;outputs;source;basis;columns;stream=null;checkpoint=null;computedCount=0;revision=-1;scratch={...om};rebuilds=0;changes=0;resumes=0;upstreamSeen=null;refreshFrom=null;contextSeen=null;current;constructor(e,t,n,r,i){this.definition=e,this.params=t,this.outputs=n,this.source=r,this.basis=i,this.columns=n.map(()=>/* @__PURE__ */ new Float64Array),this.current=typeof r==`function`?r().series.current:i()}sync(){let e=typeof this.source==`function`?this.source():null;e?.series.sync();let t=e?e.series.current:this.basis(),n=t.context(),r=t!==this.current||!um(n,this.contextSeen)||e!==null&&(e.series!==this.upstreamSeen?.series||e.series.rebuilds!==this.upstreamSeen.rebuilds),i=t.bars,a=r?{kind:`reset`}:this.refreshed(i,e,i.changesSince(this.revision));if(this.current=t,this.contextSeen=n,this.refreshFrom=null,e&&(this.upstreamSeen={series:e.series,rebuilds:e.series.rebuilds,resumes:e.series.resumes}),!a)return;let o=i.length;this.ensureCapacity(o),a.kind===`reset`||!this.checkpoint||a.from<this.computedCount-1?(this.stream=cm(this.definition,this.params,this.outputs.length,n),this.rebuilds+=1,this.run(i,0,o,e)):(this.stream=this.checkpoint.clone(),this.resumes+=1,this.run(i,this.computedCount-1,o,e)),this.computedCount=o,this.revision=i.revision,this.changes+=1}get version(){return this.changes}get length(){return this.computedCount}get bars(){return this.current.bars}indexOf(e,t){return this.current.indexOf(t+this.shift(e))}refresh(e){this.refreshFrom=Math.min(this.refreshFrom??1/0,e);let{bars:t}=this.current;return t.lowerBound(e+1)-1<this.computedCount-1}refreshed(e,t,n){let r=[];return this.refreshFrom!==null&&r.push(Math.max(0,e.lowerBound(this.refreshFrom+1)-1)),t&&t.series.resumes!==this.upstreamSeen?.resumes&&r.push(Math.max(0,this.computedCount-1)),r.length===0||n?.kind===`reset`?n:{kind:`tail`,from:Math.min(n?.from??1/0,...r)}}value(e,t){return t<this.computedCount?this.columns[e]?.[t]??NaN:NaN}shift(e){let t=typeof this.source==`function`?this.source():null,n=this.outputs[e]?.offset??0;return t?n+t.series.shift(t.column):n}reader(e,t=0){let n=this.shift(e)+t,r=this.current;return t=>this.value(e,r.barAt(t)-n)}drawn(e,t){return this.reader(e)(t)}reach(e){return this.current.reach(this.shift(e))}opens(e){return this.current.barAt(e)!==this.current.barAt(e-1)}rises(e){let{bars:t}=this.current,n=this.current.barAt(e);return n>=0&&n<t.length&&t.close(n)>=t.open(n)}run(e,t,n,r){let i=this.stream;if(i){for(let a=t;a<n;a+=1){a===n-1&&(this.checkpoint=i.clone());let t=this.readBar(e,a),o;if(r){if(o=r.series.value(r.column,a),Number.isNaN(o)){this.columns.forEach(e=>{e[a]=NaN});continue}t.open=o,t.high=o,t.low=o,t.close=o}else o=e.price(a,this.source);let s=i.next(t,o);for(let e=0;e<this.columns.length;e+=1){let t=this.columns[e];t&&(t[a]=s[e]??NaN)}}t>=n&&(this.checkpoint=null)}}readBar(e,t){let n=this.scratch;return n.time=e.time(t),n.open=e.open(t),n.high=e.high(t),n.low=e.low(t),n.close=e.close(t),n.volume=e.volume(t),n}ensureCapacity(e){let t=this.columns[0]?.length??0;if(t>=e)return;let n=Math.max(64,e,t*2);this.columns=this.columns.map(t=>{let r=new Float64Array(n).fill(NaN);return r.set(t.subarray(0,Math.min(t.length,e))),r})}};let fm=g({id:!0,type:!0,params:!0,pane:!0,scale:!0,source:!0,timeframe:!0,visible:!0,colors:!0,styles:!0,levels:!0}),pm=g({params:!0,pane:!0,source:!0,timeframe:!0,visible:!0,scale:!0,colors:!0,styles:!0,levels:!0}),mm=g({visible:!0,lineWidth:!0,lineStyle:!0,autoscale:!0}),hm=g({kind:!0,id:!0,key:!0});function gm(e){_(`indicator`,e,fm)}function _m(e){_(`patch`,e,pm)}function vm(e,t){_(e,t,mm);let{visible:n,lineWidth:r,lineStyle:i,autoscale:a}=t;return{...n===void 0?{}:{visible:f(`${e}.visible`,n)},...a===void 0?{}:{autoscale:f(`${e}.autoscale`,a)},...r===void 0?{}:{lineWidth:d(`${e}.lineWidth`,r,{min:.5,max:10})},...i===void 0?{}:{lineStyle:m(`${e}.lineStyle`,i,cn)}}}function ym(e,t,r,i,a,o){let s=new Set(i.map(e=>e.key)),c=new Map(Object.entries(t).filter(([e])=>s.has(e)));r!==void 0&&h(`indicator.${a}`,r);for(let[t,i]of Object.entries(r??{}))s.has(t)||n(`Indicator "${e}" has no output "${t}" for ${a}.`),i===null?c.delete(t):c.set(t,o(`${a}.${t}`,i));return Object.fromEntries(c)}function bm(e){return v(`indicator.levels`,e),e.map((e,t)=>d(`indicator.levels[${String(t)}]`,e))}function xm(e){return typeof e==`string`?m(`indicator.source`,e,Yt):(_(`indicator.source`,e,hm),m(`indicator.source.kind`,e.kind,[`indicator`]),p(`indicator.source.id`,e.id),e.key!==void 0&&p(`indicator.source.key`,e.key),e)}function Sm(e){return e===null?null:ia(e,`indicator.timeframe`)}function Cm(e,t,n){let r=lm(e,t,n),i=e.outputs(r);Qp(i,n);let a=e.fills?.(r)??[];return Xp(a,i,n),e.lookback&&d(`lookback() of "${n}"`,e.lookback(r),{min:1,integer:!0}),{params:r,outputs:i,fills:a}}function wm(e,t){let{params:n,outputs:r,fills:i}=Cm(e,t.params,t.type);return{params:n,outputs:r,fills:i,visible:t.visible===void 0||f(`indicator.visible`,t.visible),colors:ym(t.type,{},t.colors,r,`colors`,x),styles:ym(t.type,{},t.styles,r,`styles`,vm),levels:t.levels===void 0?null:bm(t.levels)}}function Tm(e){let t=[],n=e=>{t.includes(e)||(e.upstream&&n(e.upstream),t.push(e))};return e.forEach(n),t}var Em=class{core;store;constructor(e,t){this.core=e,this.store=t}add(e){let{core:t,store:n}=this,{entry:r,own:i}=this.place(n,e);return i&&n.move(r.id,t.createAutoPane(r.id)),t.invalidate(),r.id}set(e){let{core:t,store:n}=this;v(`indicators`,e);let r=n.staging(e),i=e.flatMap(e=>{let t=this.place(r,e);return t.own?[t.entry.id]:[]});t.values.verify((e,t)=>{e.kind===`indicator`&&im(r,e,t)});let a=n.list().map(e=>e.pane);n.adopt(r),a.forEach(e=>{t.releasePane(e)}),i.forEach(e=>{n.move(e,t.createAutoPane(e))}),t.values.reset(),t.invalidate()}place(e,t){gm(t);let n=t.pane??e.defaultPane(t.type,t.source);n!==`new`&&this.core.panes.require(n);let r=n===`new`;return{entry:r?e.add(t.scale===void 0?{...t,scale:fe}:t,b):e.add(t,n),own:r}}remove(e){this.core.values.assertUnused(`indicator`,e);let t=this.store.remove(e);this.core.releasePane(t.pane),this.core.invalidate()}update(e,t){let{core:r,store:i}=this;_m(t);let a=i.require(e).pane,o=t.pane===void 0?a:p(`patch.pane`,t.pane);o!==`new`&&r.panes.require(o);let s=o===`new`&&t.scale===void 0?{...t,scale:fe}:t;i.update(e,s,t=>{let i=r.values.uses(`indicator`,e).flatMap(({user:e,noun:n,source:r})=>r.kind===`indicator`&&r.key!==void 0&&!t.includes(r.key)?[`"${r.key}" (read by ${n} "${e}")`]:[]);i.length>0&&n(`Indicator "${e}" would no longer produce ${i.join(`, `)}.`)}),o!==a&&(i.move(e,o===`new`?r.createAutoPane(e):o),r.releasePane(a)),(t.params!==void 0||t.source!==void 0||t.timeframe!==void 0)&&r.values.reset(),r.invalidate()}values(){return am(this.store)}state(){let{store:e}=this;return{key:`indicators`,save:()=>Tm(e.list()).map(t=>{let n=e.info(t);return{id:n.id,type:n.type,params:n.params,pane:n.pane,scale:n.scale,source:n.source,...n.timeframe===null?{}:{timeframe:n.timeframe},visible:n.visible,colors:n.colors,styles:n.styles,...n.levels===null?{}:{levels:n.levels}}}),prepare:(e,t)=>this.prepare(e,t)}}prepare(e,t){let n=e??[];v(`state.indicators`,n);let r=this.store.staging(n);return n.forEach((e,n)=>{h(`state.indicators[${n}]`,e),t.require(e.pane),r.add({id:e.id,type:e.type,params:e.params,source:e.source,...e.timeframe===void 0?{}:{timeframe:e.timeframe},...e.scale===void 0?{}:{scale:e.scale},visible:e.visible,colors:{...e.colors},...e.styles===void 0?{}:{styles:structuredClone(e.styles)},...e.levels===void 0?{}:{levels:[...e.levels]}},e.pane)}),{values:{kind:`indicator`,check:(e,t)=>{im(r,e,t)}},apply:()=>{this.store.adopt(r)}}}};function Dm(e){return e.upstream?Dm(e.upstream):e.timeframe}function Om(e){return e?JSON.stringify(A(e)):`null`}function km(e,t){return()=>({series:e.series,column:t===void 0?0:e.outputs.findIndex(e=>e.key===t)})}var Am=class e{bases;registry;entries=/* @__PURE__ */ new Map;ids;constructor(e,t,n){this.bases=e,this.registry=t,this.ids=new de(e=>this.entries.has(e),n)}staging(t){let n=new e(this.bases,this.registry,this.ids);return n.ids.reserve(t),n}list(){return[...this.entries.values()]}get(e){return this.entries.get(e)}require(e){return this.entries.get(e)??n(`Unknown indicator "${e}".`)}info(e){let t=Dm(e);return{id:e.id,type:e.type,params:structuredClone(e.params),pane:e.pane,scale:e.scale,source:typeof e.source==`string`?e.source:{...e.source},timeframe:t?A(t):null,visible:e.visible,colors:{...e.colors},styles:structuredClone(e.styles),levels:e.levels===null?null:[...e.levels]}}defaultPane(e,t){let n=this.registry.require(e).pane;return(typeof t==`object`&&n===`main`?this.entries.get(t.id):void 0)?.pane??n}parseSource(e,t){if(e===void 0)return{source:`close`,upstream:null};let r=xm(e);if(typeof r==`string`)return{source:r,upstream:null};let{id:i,key:a}=r,o=this.entries.get(i)??n(`indicator.source: unknown indicator "${i}".`);a!==void 0&&!o.outputs.some(e=>e.key===a)&&n(`indicator.source: indicator "${i}" has no output "${a}".`);for(let e=o;e;e=e.upstream)e.id===t&&n(`indicator.source: "${i}" reads "${t}", so "${t}" cannot read it.`);return{source:{kind:`indicator`,id:o.id,...a===void 0?{}:{key:a}},upstream:o}}parseTimeframe(e,t,r){let i=e===void 0?void 0:Sm(e);if(!t)return i===void 0?r:i;let a=Dm(t);return i!==void 0&&!ca(i,a)&&n(`indicator.timeframe must be ${Om(a)}, the timeframe of the indicator "${t.id}" it reads, received ${Om(i)}.`),null}release(){this.bases.keep(this.list().map(e=>e.timeframe))}dependents(e){return this.list().filter(t=>t.upstream?.id===e).map(e=>e.id)}series(e,t,n,r,i,a){return new dm(e,t,n,i&&typeof r!=`string`?km(i,r.key):r,this.bases.of(a))}add(e,t){p(`indicator.type`,e.type);let r=this.registry.require(e.type);e.id!==void 0&&this.entries.has(p(`indicator.id`,e.id))&&n(`An indicator with id "${e.id}" already exists.`);let i=wm(r,e),{params:a,outputs:o}=i,{source:s,upstream:c}=this.parseSource(e.source??r.source,null),l=this.parseTimeframe(e.timeframe,c,null),u=e.scale===void 0?c&&c.pane===t?c.scale:`right`:p(`indicator.scale`,e.scale),d=e.id??this.ids.next(e.type.toLowerCase()),f={id:d,type:e.type,definition:r,pane:t,scale:u,source:s,upstream:c,timeframe:l,...i,series:this.series(r,a,o,s,c,l)};return this.entries.set(d,f),this.ids.note(d),f}update(e,t,r){let i=this.require(e);t.params!==void 0&&h(`params`,t.params);let{params:a,outputs:o,fills:s}=t.params===void 0?i:Cm(i.definition,{...i.params,...t.params},i.type),{source:c,upstream:l}=t.source===void 0?{source:i.source,upstream:i.upstream}:this.parseSource(t.source,e),u=this.parseTimeframe(t.timeframe,l,Dm(i)),d=o.map(e=>e.key);for(let t of this.list())t.upstream===i&&typeof t.source!=`string`&&t.source.key!==void 0&&!d.includes(t.source.key)&&n(`Indicator "${e}" would no longer produce "${t.source.key}", which indicator "${t.id}" reads.`);r(d);let m=ym(i.type,i.colors,t.colors,o,`colors`,x),g=ym(i.type,i.styles,t.styles,o,`styles`,vm),_=t.levels===void 0?i.levels:t.levels===null?null:bm(t.levels),v=t.visible===void 0?i.visible:f(`indicator.visible`,t.visible),ee=t.scale===void 0?i.scale:p(`indicator.scale`,t.scale);(t.params!==void 0||t.source!==void 0||t.timeframe!==void 0)&&(i.series=this.series(i.definition,a,o,c,l,u)),i.params=a,i.source=c,i.upstream=l,i.timeframe=u,i.outputs=o,i.fills=s,i.colors=m,i.styles=g,i.levels=_,i.visible=v,i.scale=ee,this.release()}move(e,t){this.require(e).pane=t}remove(e){let t=this.require(e),r=this.dependents(e);return r.length>0&&n(`Indicator "${e}" is read by the indicators ${r.map(e=>`"${e}"`).join(`, `)}; remove them first.`),this.entries.delete(e),this.release(),t}adopt(e){this.entries.clear(),e.entries.forEach((e,t)=>{this.entries.set(t,e),this.ids.note(t)}),this.release()}};function jm({definition:e,params:t},n){return Object.entries(t).flatMap(([t,r])=>{let i=e.params[t];return i?.legend===!1?[]:(typeof r==`number`?[r]:[...r]).map(e=>{let t=i?.options?.find(t=>t.value===e);return t?n.label(t.label):e})}).join(` `)}function Mm(e,t){let n=e.upstream;if(!n||typeof e.source==`string`)return``;let r=e.source.key===void 0?``:` ${e.source.key}`;return` · ${t.label(n.definition.name)}${r}`}function Nm(e,t,n,r){return(i,a)=>e.list().map(e=>({item:{kind:`indicator`,id:e.id,type:e.type,paneId:e.pane,visible:e.visible},segments:()=>{let{theme:o}=t();e.series.sync();let s=Up(e,o),c=Gp(e,i.priceFormat),l=r(),u=l.label(e.definition.name),d=Dm(e),f=[{text:`${[u,jm(e,l),d?A(d):``].filter(e=>e!==``).join(` `)}${Mm(e,l)}`,color:o.textMuted}],p=e.outputs.filter(e=>e.legend!==!1).length>1;return e.outputs.forEach((t,r)=>{if(t.legend===!1||e.styles[t.key]?.visible===!1)return;let i=e.series.drawn(r,a),u=D(n(),i,Wp(t,c));f.push({text:p?`${l.label(t.label)} ${u}`:u,color:Vp(e,t,r,a,s,o)})}),f}}))}let Pm=[`names`,`labels`];function Fm(e,t){if(t!==void 0){h(e,t);for(let[n,r]of Object.entries(t))p(`${e}.${JSON.stringify(n)}`,r)}}function Im(e,t){v(e,t),t.forEach((t,n)=>{h(`${e}[${n}]`,t);let r=Object.entries(t);for(let[t,i]of r){let r=`${e}[${n}].${t}`;_(r,i,Pm),Fm(`${r}.names`,i.names),Fm(`${r}.labels`,i.labels)}})}function Lm(e,t,n){return new Map(e.flatMap(e=>Object.entries(e[t]?.[n]??{})))}function Rm(e,t){let n=new Intl.NumberFormat(t??void 0).resolvedOptions().locale.split(`-`)[0],r=Lm(e,n??`en`,`labels`),i=Lm(e,n??`en`,`names`),a=Lm(e,`en`,`names`);return{label:e=>{let t=r.get(e);if(t!==void 0)return t;let n=/\d+$/.exec(e)?.[0],i=n===void 0?void 0:r.get(`${e.slice(0,-n.length)}{n}`);return i===void 0||n===void 0?e:i.replace(`{n}`,n)},title:e=>i.get(e)??a.get(e)??null}}function zm(e=[],t={}){v(`indicators()`,e);let r=/* @__PURE__ */ new Set;e.forEach(e=>{Yp(e),r.has(e.type)&&n(`indicators() is given the indicator type "${e.type}" twice.`),r.add(e.type)}),_(`indicators() options`,t,[`texts`]);let i=t.texts??[];return Im(`indicators() texts`,i),Ua({name:`indicators`,install:t=>{let n=new Dr(`indicator type`,[],`Give it to the indicators module, or register it with chart.indicators.register().`);e.forEach(e=>{n.register(e)});let r=new Am(new nm(t.market,t.bars),n),a=new Em(t,r),o=null,s=()=>{let{locale:e}=t.options;return o?.locale!==e&&(o={locale:e,words:Rm(i,e)}),o.words};return t.contributors.push(Kp(r)),t.legendRows.push(Nm(r,()=>t.options,()=>t.formatter,s)),t.values.provide(`indicator`,a.values()),t.paneOccupants.push({occupants:e=>r.list().filter(t=>t.pane===e).map(e=>e.id),removed:()=>void 0}),t.stateParts.push(a.state()),{indicators:$p(t,a,s)}}})}var V=class e{capacity;values;start=0;size=0;constructor(e){this.capacity=e,this.values=new Float64Array(d(`capacity`,e,{min:1,integer:!0}))}get length(){return this.size}get full(){return this.size===this.capacity}push(e){if(this.size<this.capacity)return this.values[(this.start+this.size)%this.capacity]=e,this.size+=1,NaN;let t=this.values[this.start]??NaN;return this.values[this.start]=e,this.start=(this.start+1)%this.capacity,t}at(e){return this.values[(this.start+e)%this.capacity]??NaN}fromEnd(e){return e<this.size?this.at(this.size-1-e):NaN}max(){let e=-1/0;for(let t=0;t<this.size;t+=1)e=Math.max(e,this.at(t));return e}min(){let e=1/0;for(let t=0;t<this.size;t+=1)e=Math.min(e,this.at(t));return e}sum(){let e=0;for(let t=0;t<this.size;t+=1)e+=this.at(t);return e}clone(){let t=new e(this.capacity);return t.values.set(this.values),t.start=this.start,t.size=this.size,t}},Bm=class e{period;sum;constructor(e,t=new W(e)){this.period=e,this.sum=t}next(e){return this.sum.next(e)/this.period}clone(){return new e(this.period,this.sum.clone())}},H=class e{period;window;sum;value;constructor(e,t=new V(e),n=0,r=NaN){this.period=e,this.window=t,this.sum=n,this.value=r}next(e){if(Number.isNaN(e))return this.value;let t=this.window.push(e);return this.sum+=e-(Number.isNaN(t)?0:t),this.value=this.window.full?this.sum/this.period:NaN,this.value}clone(){return new e(this.period,this.window.clone(),this.sum,this.value)}},Vm=class e{period;window;value=NaN;constructor(e){this.period=e,this.window=new V(d(`period`,e,{min:1,integer:!0}))}next(e){if(Number.isNaN(e))return this.value;if(this.window.push(e),!this.window.full)return NaN;let t=this.window.sum()/this.period,n=0;for(let e=0;e<this.period;e+=1)n+=(this.window.at(e)-t)**2;return this.value=Math.sqrt(n/this.period),this.value}clone(){let t=new e(this.period);return t.window=this.window.clone(),t.value=this.value,t}},Hm=class e{period;weight;value;constructor(e,t,n=NaN){this.period=e,this.weight=t,this.value=n}next(e){return Number.isNaN(e)||(this.value=Number.isNaN(this.value)?e:(this.weight*e+(this.period-this.weight)*this.value)/this.period),this.value}clone(){return new e(this.period,this.weight,this.value)}},U=class e{period;alpha;count;value;constructor(e,t,n=0,r=0){this.period=e,this.alpha=t,this.count=n,this.value=r}static ema(t){return new e(t,2/(t+1))}static rma(t){return new e(t,1/t)}next(e){return Number.isNaN(e)?this.count===this.period?this.value:NaN:this.count===this.period?(this.value=this.alpha*e+(1-this.alpha)*this.value,this.value):(this.count+=1,this.value+=e,this.count<this.period?NaN:(this.value/=this.period,this.value))}clone(){return new e(this.period,this.alpha,this.count,this.value)}},Um=class e{period;window;sum;weighted;constructor(e,t=new V(e),n=0,r=0){this.period=e,this.window=t,this.sum=n,this.weighted=r}next(e){if(Number.isNaN(e))return this.window.full?this.average():NaN;let t=this.window.length,n=this.window.push(e);return t<this.period?(this.weighted+=(t+1)*e,this.sum+=e):(this.weighted+=this.period*e-this.sum,this.sum+=e-n),this.window.full?this.average():NaN}average(){return this.weighted/(this.period*(this.period+1)/2)}clone(){return new e(this.period,this.window.clone(),this.sum,this.weighted)}},W=class e{window;sum;constructor(e,t=new V(e),n=0){this.window=t,this.sum=n}next(e){let t=this.window.push(e);return this.sum=Number.isNaN(this.sum)?this.window.sum():this.sum+(e-(Number.isNaN(t)?0:t)),this.window.full?this.sum:NaN}clone(){return new e(this.window.capacity,this.window.clone(),this.sum)}},G=class e{highs;lows;constructor(e){this.highs=new V(d(`period`,e,{min:1,integer:!0})),this.lows=new V(e)}push(e,t){this.highs.push(e),this.lows.push(t)}highest(){return this.highs.full?this.highs.max():NaN}lowest(){return this.lows.full?this.lows.min():NaN}clone(){let t=new e(this.highs.capacity);return t.highs=this.highs.clone(),t.lows=this.lows.clone(),t}},K=class e{last=NaN;next(e){let t=this.last;return this.last=e,t}clone(){let t=new e;return t.last=this.last,t}};let Wm={next:e=>e,clone:()=>Wm};var q=class e{steps;input;out;constructor(e,t){this.steps=e,this.input=t,this.out=new Float64Array(e.length)}next(e,t){let n=this.input(e,t);return this.steps.forEach((t,r)=>{this.out[r]=t.next(n,e)}),this.out}clone(){return new e(this.steps.map(e=>e.clone()),this.input)}},Gm=class e{step;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t){this.step=e,this.average=t}next(e,t){let n=this.step.next(t);return this.out[0]=n,this.out[1]=this.average.next(n),this.out}clone(){return new e(this.step.clone(),this.average.clone())}};function J(e){return{key:e.toLowerCase(),label:e,plot:{kind:`line`}}}function Y(e,t){return{key:e,label:t,plot:{kind:`line`}}}function Km(e,t){return t.map(t=>J(`${e}${t}`))}function X(e,t=`Period`){return{default:e,min:1,max:2e3,integer:!0,label:t}}function qm(e,t=`Periods`){return{default:e,min:1,max:2e3,integer:!0,label:t}}function Jm(e){return e.map((e,t)=>({value:t,label:e}))}function Z(e,t,n,r=!0){return{default:t,label:n,options:Jm(e),...r?{}:{legend:!1}}}function Q(e,t,r){return(!Number.isInteger(t)||t<0||t>=e.length)&&n(`There is no ${r} ${String(t)}.`),e[t]}function Ym(e,t,n=!0){return Z([`Off`,`On`],+!!e,t,n)}function $(e,t){return t===0?NaN:e/t}let Xm=[`sma`,`ema`,`rma`,`wma`,`vwma`];var Zm=class e{average;constructor(e){this.average=e}next(e){return this.average.next(e)}clone(){return new e(this.average.clone())}},Qm=class e{flow;volume;value;constructor(e,t,n=NaN){this.flow=e,this.volume=t,this.value=n}static of(t){return new e(new W(t),new W(t))}next(e,t){return Number.isNaN(e)||(this.value=$(this.flow.next(e*t.volume),this.volume.next(t.volume))),this.value}clone(){return new e(this.flow.clone(),this.volume.clone(),this.value)}};function $m(e,t){switch(m(`kind`,e,Xm),d(`period`,t,{min:1,integer:!0}),e){case`sma`:return new Zm(new H(t));case`ema`:return new Zm(U.ema(t));case`rma`:return new Zm(U.rma(t));case`wma`:return new Zm(new Um(t));case`vwma`:return Qm.of(t)}}let eh=[null,`sma`,`sma`,`ema`,`rma`,`wma`,`vwma`];function th(e){return{maType:Z([`None`,`SMA`,`SMA + Bollinger Bands`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],+!!e,`Type`,!1),maLength:{...X(14,`Length`),legend:!1},bbMult:{default:2,min:.001,max:50,label:`BB StdDev`,legend:!1}}}function nh(e,t,{maType:n}){if(Q(eh,n,`smoothing type`)===null)return[];let r=Y(`${e}BasedMa`,`${t}-based MA`);return n===2?[r,Y(`upperBollingerBand`,`Upper Bollinger Band`),Y(`lowerBollingerBand`,`Lower Bollinger Band`)]:[r]}function rh({maType:e}){return e===2?[{from:`upperBollingerBand`,to:`lowerBollingerBand`}]:[]}var ih=class e{value;average;deviation;multiplier;out;constructor(e,t,n,r){this.value=e,this.average=t,this.deviation=n,this.multiplier=r,this.out=new Float64Array(1+ +!!t+(n?2:0))}static of(t,{maType:n,maLength:r,bbMult:i}){let a=Q(eh,n,`smoothing type`);return new e(t,a&&$m(a,r),n===2?new Vm(r):null,i)}next(e,t){let n=this.value.next(t,e);if(this.out[0]=n,this.average){let t=this.average.next(n,e);if(this.out[1]=t,this.deviation){let e=this.deviation.next(n)*this.multiplier;this.out[2]=t+e,this.out[3]=t-e}}return this.out}clone(){return new e(this.value.clone(),this.average?.clone()??null,this.deviation?.clone()??null,this.multiplier)}};let ah={type:`MA`,name:`MA`,pane:`main`,precision:`price`,params:{periods:qm([9],`Length`)},outputs:({periods:e})=>Km(`MA`,e),create:({periods:e})=>new q(e.map(e=>new H(e)),(e,t)=>t)},oh={type:`EMA`,name:`EMA`,pane:`main`,precision:`price`,params:{periods:qm([9],`Length`)},outputs:({periods:e})=>Km(`EMA`,e),create:({periods:e})=>new q(e.map(e=>U.ema(e)),(e,t)=>t)},sh={type:`SMMA`,name:`SMMA`,pane:`main`,precision:`price`,params:{periods:qm([7],`Length`)},outputs:({periods:e})=>Km(`SMMA`,e),create:({periods:e})=>new q(e.map(e=>U.rma(e)),(e,t)=>t)},ch={type:`WMA`,name:`WMA`,pane:`main`,precision:`price`,params:{periods:qm([9],`Length`)},outputs:({periods:e})=>Km(`WMA`,e),create:({periods:e})=>new q(e.map(e=>new Um(e)),(e,t)=>t)};var lh=class e{period;half;full;root;constructor(e,t=new Um(Math.floor(e/2)),n=new Um(e),r=new Um(Math.floor(Math.sqrt(e)))){this.period=e,this.half=t,this.full=n,this.root=r}next(e){let t=2*this.half.next(e)-this.full.next(e);return Number.isNaN(t)?t:this.root.next(t)}clone(){return new e(this.period,this.half.clone(),this.full.clone(),this.root.clone())}};let uh={type:`HMA`,name:`HMA`,pane:`main`,precision:`price`,params:{periods:{default:[9],min:2,max:2e3,integer:!0,label:`Length`}},outputs:({periods:e})=>Km(`HMA`,e),create:({periods:e})=>new q(e.map(e=>new lh(e)),(e,t)=>t)};var dh=class e{period;fast;slow;previous;history;moves;value;fastest;slowest;constructor(e,t,n,r=new K,i=new V(e),a=new W(e),o=NaN){this.period=e,this.fast=t,this.slow=n,this.previous=r,this.history=i,this.moves=a,this.value=o,this.fastest=2/(t+1),this.slowest=2/(n+1)}next(e){let t=this.previous.next(e),n=this.history.push(e),r=this.moves.next(Math.abs(e-t));if(Number.isNaN(r))return NaN;let i=((r===0?0:Math.abs(e-n)/r)*(this.fastest-this.slowest)+this.slowest)**2,a=Number.isNaN(this.value)?e:this.value;return this.value=a+i*(e-a),this.value}clone(){return new e(this.period,this.fast,this.slow,this.previous.clone(),this.history.clone(),this.moves.clone(),this.value)}};let fh={type:`KAMA`,name:`KAMA`,pane:`main`,precision:`price`,params:{period:X(10,`ER length`),fast:X(2,`Fast length`),slow:X(30,`Slow length`)},outputs:()=>[J(`KAMA`)],create:({period:e,fast:t,slow:n})=>new q([new dh(e,t,n)],(e,t)=>t)};var ph=class e{weights;norm;window;constructor(e,t,n=new V(e.length)){this.weights=e,this.norm=t,this.window=n}next(e){if(this.window.push(e),!this.window.full)return NaN;let t=0;for(let e=0;e<this.weights.length;e+=1)t+=this.window.at(e)*(this.weights[e]??0);return t/this.norm}clone(){return new e(this.weights,this.norm,this.window.clone())}};function mh(e,t,n){let r=t*(e-1),i=e/n,a=Float64Array.from({length:e},(e,t)=>Math.exp(-((t-r)**2)/(2*i*i)));return new ph(a,a.reduce((e,t)=>e+t,0))}let hh={type:`ALMA`,name:`ALMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`),offset:{default:.85,min:0,max:1,label:`Offset`},sigma:{default:6,min:.1,max:100,label:`Sigma`}},outputs:()=>[J(`ALMA`)],create:({period:e,offset:t,sigma:n})=>new q([mh(e,t,n)],(e,t)=>t)},gh={type:`VWMA`,name:`VWMA`,pane:`main`,precision:`price`,params:{periods:qm([20],`Length`)},outputs:({periods:e})=>Km(`VWMA`,e),create:({periods:e})=>new q(e.map(e=>Qm.of(e)),(e,t)=>t)};var _h=class e{averages;constructor(e){this.averages=e}next(e){let t=0;for(let n of this.averages)t+=n.next(e);return t/this.averages.length}clone(){return new e(this.averages.map(e=>e.clone()))}};let vh={type:`BBI`,name:`BBI`,pane:`main`,precision:`price`,params:{n1:X(3,`N1`),n2:X(6,`N2`),n3:X(12,`N3`),n4:X(24,`N4`)},outputs:()=>[J(`BBI`)],create:({n1:e,n2:t,n3:n,n4:r})=>new q([new _h([e,t,n,r].map(e=>new Bm(e)))],(e,t)=>t)};function yh(e,t){return Math.max(e.high-e.low,Math.abs(e.high-t),Math.abs(e.low-t))}var bh=class e{closes;constructor(e=new K){this.closes=e}next(e){let t=this.closes.next(e.close);return Number.isNaN(t)?e.high-e.low:yh(e,t)}clone(){return new e(this.closes.clone())}},xh=class e{ranges;average;constructor(e,t){this.ranges=e,this.average=t}static of(t){return new e(new bh,U.rma(t))}next(e){return this.average.next(this.ranges.next(e))}clone(){return new e(this.ranges.clone(),this.average.clone())}},Sh=class e{ranges;average;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.ranges=e,this.average=t}next(e){return this.out[0]=this.average.next(this.ranges.next(e),e),this.out}clone(){return new e(this.ranges.clone(),this.average.clone())}};let Ch=[`rma`,`sma`,`ema`,`wma`],wh={type:`ATR`,name:`ATR`,pane:`new`,precision:`price`,params:{period:X(14,`Length`),smoothing:Z([`RMA`,`SMA`,`EMA`,`WMA`],0,`Smoothing`)},outputs:()=>[J(`ATR`)],create:({period:e,smoothing:t})=>new Sh(new bh,$m(Q(Ch,t,`smoothing`),e))},Th={type:`STD`,name:`STD`,pane:`new`,precision:`price`,params:{period:{default:20,min:2,max:2e3,integer:!0,label:`Period`}},outputs:()=>[J(`STD`)],create:({period:e})=>new q([new Vm(e)],(e,t)=>t)};var Eh=class e{period;ranges;sums;extremes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new bh,n=new W(e),r=new G(e)){this.period=e,this.ranges=t,this.sums=n,this.extremes=r}next(e){let t=this.sums.next(this.ranges.next(e));this.extremes.push(e.high,e.low);let n=this.extremes.highest()-this.extremes.lowest();return this.out[0]=100*Math.log10($(t,n))/Math.log10(this.period),this.out}clone(){return new e(this.period,this.ranges.clone(),this.sums.clone(),this.extremes.clone())}};let Dh={type:`CHOP`,name:`CHOP`,pane:`new`,precision:2,params:{period:{default:14,min:2,max:2e3,integer:!0,label:`Length`}},outputs:()=>[J(`CHOP`)],levels:()=>[61.8,50,38.2],create:({period:e})=>new Eh(e)},Oh=()=>[{from:`upper`,to:`lower`}],kh=[`sma`,`ema`,`rma`,`wma`,`vwma`];var Ah=class e{multiplier;mean;deviation;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.multiplier=e,this.mean=t,this.deviation=n}next(e,t){let n=this.mean.next(t,e),r=this.deviation.next(t)*this.multiplier;return this.out[0]=n,this.out[1]=n+r,this.out[2]=n-r,this.out}clone(){return new e(this.multiplier,this.mean.clone(),this.deviation.clone())}};let jh={type:`BOLL`,name:`BOLL`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),maType:Z([`SMA`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],0,`Basis MA Type`),multiplier:{default:2,min:.001,max:50,label:`StdDev`}},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:Oh,create:({period:e,maType:t,multiplier:n})=>new Ah(n,$m(Q(kh,t,`basis average`),e),new Vm(e))},Mh=[`Average True Range`,`True Range`,`Range`];var Nh=class e{average;constructor(e){this.average=e}next(e){return this.average.next(e.high-e.low)}clone(){return new e(this.average.clone())}},Ph=class e{multiplier;mean;width;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.multiplier=e,this.mean=t,this.width=n}next(e,t){let n=this.mean.next(t,e),r=this.width.next(e)*this.multiplier;return this.out[0]=n+r,this.out[1]=n,this.out[2]=n-r,this.out}clone(){return new e(this.multiplier,this.mean.clone(),this.width.clone())}};let Fh={type:`KC`,name:`KC`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),multiplier:{default:2,min:.1,max:10,label:`Multiplier`},exponential:Ym(!0,`Use Exponential MA`,!1),bandStyle:Z(Mh,0,`Bands Style`,!1),atrPeriod:{...X(10,`ATR Length`),legend:!1}},outputs:()=>[Y(`upper`,`Upper`),Y(`basis`,`Basis`),Y(`lower`,`Lower`)],fills:Oh,create:({period:e,multiplier:t,exponential:n,bandStyle:r,atrPeriod:i})=>{Q(Mh,r,`band style`);let a=r===0?xh.of(i):r===1?new bh:new Nh(U.rma(e));return new Ph(t,$m(n===1?`ema`:`sma`,e),a)}};var Ih=class e{extremes;out=/* @__PURE__ */ new Float64Array(3);constructor(e){this.extremes=e}next(e){this.extremes.push(e.high,e.low);let t=this.extremes.highest(),n=this.extremes.lowest();return this.out[0]=(t+n)/2,this.out[1]=t,this.out[2]=n,this.out}clone(){return new e(this.extremes.clone())}};let Lh={type:`DC`,name:`DC`,pane:`main`,precision:`price`,params:{period:X(20,`Length`)},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:Oh,create:({period:e})=>new Ih(new G(e))};function Rh(e){let t=e===null||aa(e)!==null||e.unit===`day`&&e.count===1;return Math.sqrt(365/(t?1:7))}var zh=class e{scale;deviation;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t,n=new K){this.scale=e,this.deviation=t,this.closes=n}next(e){let t=$(e.close,this.closes.next(e.close));return this.out[0]=100*this.deviation.next(Math.log(t))*this.scale,this.out}clone(){return new e(this.scale,this.deviation.clone(),this.closes.clone())}};let Bh={type:`HV`,name:`HV`,pane:`new`,precision:2,params:{period:X(10,`Length`)},outputs:()=>[J(`HV`)],create:({period:e},{interval:t})=>new zh(Rh(t),new Vm(e))};var Vh=class e{sum;single;double;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=U.ema(9),n=U.ema(9)){this.sum=e,this.single=t,this.double=n}next(e){let t=this.single.next(e.high-e.low);return this.out[0]=this.sum.next($(t,this.double.next(t))),this.out}clone(){return new e(this.sum.clone(),this.single.clone(),this.double.clone())}};let Hh={type:`MASS`,name:`Mass Index`,pane:`new`,precision:2,params:{period:X(10,`Length`)},outputs:()=>[Y(`massIndex`,`Mass Index`)],create:({period:e})=>new Vh(new W(e))},Uh={period:X(20,`Length`),multiplier:{default:2,min:.001,max:50,label:`StdDev`}};var Wh=class e{multiplier;mean;deviation;basis=NaN;spread=NaN;constructor(e,t,n){this.multiplier=e,this.mean=t,this.deviation=n}static of({period:t,multiplier:n}){return new e(n,new H(t),new Vm(t))}next(e){this.basis=this.mean.next(e),this.spread=this.deviation.next(e)*this.multiplier}clone(){let t=new e(this.multiplier,this.mean.clone(),this.deviation.clone());return t.basis=this.basis,t.spread=this.spread,t}},Gh=class e{bands;expansions;contractions;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.bands=e,this.expansions=t,this.contractions=n}next(e,t){this.bands.next(t);let n=$(2*this.bands.spread,this.bands.basis)*100;return this.expansions.push(n),this.contractions.push(n),this.out[0]=n,this.out[1]=this.expansions.full?this.expansions.max():NaN,this.out[2]=this.contractions.full?this.contractions.min():NaN,this.out}clone(){return new e(this.bands.clone(),this.expansions.clone(),this.contractions.clone())}};let Kh={type:`BBW`,name:`BBW`,pane:`new`,precision:2,params:{...Uh,expansion:X(125,`Highest Expansion Length`),contraction:X(125,`Lowest Contraction Length`)},outputs:()=>[Y(`bollingerBandWidth`,`Bollinger BandWidth`),Y(`highestExpansion`,`Highest Expansion`),Y(`lowestContraction`,`Lowest Contraction`)],create:e=>new Gh(Wh.of(e),new V(e.expansion),new V(e.contraction))};var qh=class e{bands;out=/* @__PURE__ */ new Float64Array(1);constructor(e){this.bands=e}next(e,t){this.bands.next(t);let{basis:n,spread:r}=this.bands;return this.out[0]=$(t-(n-r),2*r),this.out}clone(){return new e(this.bands.clone())}};let Jh={type:`BBP`,name:`BB %B`,pane:`new`,precision:2,params:Uh,outputs:()=>[Y(`bollingerBandsB`,`Bollinger Bands %b`)],levels:()=>[1,.5,0],create:e=>new qh(Wh.of(e))},Yh=[`ema`,`sma`];var Xh=class e{fast;slow;signal;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.fast=e,this.slow=t,this.signal=n}next(e,t){let n=this.fast.next(t,e)-this.slow.next(t,e),r=this.signal.next(n,e);return this.out[0]=n-r,this.out[1]=n,this.out[2]=r,this.out}clone(){return new e(this.fast.clone(),this.slow.clone(),this.signal.clone())}};let Zh={type:`MACD`,name:`MACD`,pane:`new`,precision:`price`,params:{fast:{default:12,min:1,max:500,integer:!0,label:`Fast length`},slow:{default:26,min:1,max:500,integer:!0,label:`Slow length`},signal:{default:9,min:1,max:500,integer:!0,label:`Signal length`},oscillatorType:Z([`EMA`,`SMA`],0,`Oscillator MA type`,!1),signalType:Z([`EMA`,`SMA`],0,`Signal MA type`,!1)},outputs:()=>[{key:`histogram`,label:`Histogram`,plot:{kind:`histogram`,colorBy:`sign`}},Y(`macd`,`MACD`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:({fast:e,slow:t,signal:n,oscillatorType:r,signalType:i})=>{let a=Q(Yh,r,`oscillator average`);return new Xh($m(a,e),$m(a,t),$m(Q(Yh,i,`signal average`),n))}};var Qh=class e{period;previous;gains;losses;constructor(e,t=new K,n=U.rma(e),r=U.rma(e)){this.period=e,this.previous=t,this.gains=n,this.losses=r}next(e){let t=this.previous.next(e);if(Number.isNaN(t))return NaN;let n=this.gains.next(Math.max(e-t,0)),r=this.losses.next(Math.max(t-e,0));return r===0?100:n===0?0:100-100/(1+n/r)}clone(){return new e(this.period,this.previous.clone(),this.gains.clone(),this.losses.clone())}};let $h={type:`RSI`,name:`RSI`,pane:`new`,precision:2,params:{period:X(14,`RSI Length`),...th(!0)},outputs:e=>[Y(`rsi`,`RSI`),...nh(`rsi`,`RSI`,e)],fills:rh,levels:()=>[70,50,30],range:{min:0,max:100},create:e=>ih.of(new Qh(e.period),e)};var eg=class e{range;k;d;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.range=e,this.k=t,this.d=n}next(e){this.range.push(e.high,e.low);let t=this.range.lowest(),n=this.range.highest()-t;if(Number.isNaN(n))return this.out.fill(NaN),this.out;let r=n===0?50:(e.close-t)/n*100,i=this.k.next(r),a=this.d.next(i);return this.out[0]=i,this.out[1]=a,this.out[2]=3*i-2*a,this.out}clone(){return new e(this.range.clone(),this.k.clone(),this.d.clone())}};let tg={type:`KDJ`,name:`KDJ`,pane:`new`,precision:2,params:{period:X(9),k:X(3,`K`),d:X(3,`D`)},outputs:()=>[`K`,`D`,`J`].map(J),levels:()=>[20,80],create:({period:e,k:t,d:n})=>new eg(new G(e),new Hm(t,1),new Hm(n,1))};var ng=class e{ranges;out;constructor(e){this.ranges=e,this.out=new Float64Array(e.length)}next(e,t){return this.ranges.forEach((n,r)=>{n.push(e.high,e.low);let i=n.highest();this.out[r]=$(t-i,i-n.lowest())*100}),this.out}clone(){return new e(this.ranges.map(e=>e.clone()))}};let rg={type:`WR`,name:`WR`,pane:`new`,precision:2,params:{periods:qm([14],`Length`)},outputs:({periods:e})=>e.map(e=>Y(`wr${String(e)}`,`%R${String(e)}`)),levels:()=>[-20,-50,-80],range:{min:-100,max:0},create:({periods:e})=>new ng(e.map(e=>new G(e)))};var ig=class e{window;constructor(e){this.window=e}next(e){return this.window.push(e),this.window.full?this.cci(e):NaN}clone(){return new e(this.window.clone())}cci(e){let t=this.window.length,n=0;for(let r=0;r<t;r+=1)n+=e-this.window.at(r);n/=t;let r=0;for(let i=0;i<t;i+=1)r+=Math.abs(e-this.window.at(i)-n);return $(n,.015*r/t)}};let ag={type:`CCI`,name:`CCI`,pane:`new`,source:`hlc3`,precision:2,params:{period:X(20,`Length`),...th(!0)},outputs:e=>[Y(`cci`,`CCI`),...nh(`cci`,`CCI`,e)],fills:rh,levels:()=>[100,0,-100],create:e=>ih.of(new ig(new V(e.period)),e)};var og=class e{history;constructor(e,t=new V(e)){this.history=t}next(e){let t=this.history.push(e);return $(e-t,t)*100}clone(){return new e(this.history.capacity,this.history.clone())}};let sg={type:`ROC`,name:`ROC`,pane:`new`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[J(`ROC`)],levels:()=>[0],create:({period:e})=>new q([new og(e)],(e,t)=>t)};var cg=class e{period;average;constructor(e,t=new Bm(e)){this.period=e,this.average=t}next(e){let t=this.average.next(e);return $(e-t,t)*100}clone(){return new e(this.period,this.average.clone())}};let lg={type:`BIAS`,name:`BIAS`,pane:`new`,precision:2,params:{periods:qm([6,12,24])},outputs:({periods:e})=>Km(`BIAS`,e),create:({periods:e})=>new q(e.map(e=>new cg(e)),(e,t)=>t)};var ug=class e{range;k;d;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.range=e,this.k=t,this.d=n}next(e){this.range.push(e.high,e.low);let t=this.range.lowest(),n=this.k.next($(e.close-t,this.range.highest()-t)*100);return this.out[0]=n,this.out[1]=this.d.next(n),this.out}clone(){return new e(this.range.clone(),this.k.clone(),this.d.clone())}};let dg={type:`STOCH`,name:`Stoch`,pane:`new`,precision:2,params:{period:X(14,`%K Length`),smoothK:X(1,`%K Smoothing`),smoothD:X(3,`%D Smoothing`)},outputs:()=>[Y(`k`,`%K`),Y(`d`,`%D`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({period:e,smoothK:t,smoothD:n})=>new ug(new G(e),new H(t),new H(n))};var fg=class e{rsi;range;k;d;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.rsi=e,this.range=t,this.k=n,this.d=r}next(e,t){let n=this.rsi.next(t);this.range.push(n,n);let r=this.range.lowest(),i=this.k.next($(n-r,this.range.highest()-r)*100);return this.out[0]=i,this.out[1]=this.d.next(i),this.out}clone(){return new e(this.rsi.clone(),this.range.clone(),this.k.clone(),this.d.clone())}};let pg={type:`STOCHRSI`,name:`Stoch RSI`,pane:`new`,precision:2,params:{smoothK:X(3,`K`),smoothD:X(3,`D`),rsiPeriod:X(14,`RSI Length`),period:X(14,`Stochastic Length`)},outputs:()=>[Y(`k`,`K`),Y(`d`,`D`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({rsiPeriod:e,period:t,smoothK:n,smoothD:r})=>new fg(new Qh(e),new G(t),new H(n),new H(r))};var mg=class e{range;out=/* @__PURE__ */ new Float64Array(2);state={value:NaN,fisher:NaN};constructor(e){this.range=e}next(e,t){let n=this.state;this.range.push(t,t);let r=this.range.lowest(),i=.66*($(t-r,this.range.highest()-r)-.5)+.67*(Number.isNaN(n.value)?0:n.value),a=i>.99?.999:i<-.99?-.999:i,o=.5*Math.log((1+a)/(1-a))+.5*(Number.isNaN(n.fisher)?0:n.fisher);return this.out[0]=o,this.out[1]=n.fisher,this.state={value:a,fisher:o},this.out}clone(){let t=new e(this.range.clone());return t.state=this.state,t}};let hg={type:`FISHER`,name:`Fisher`,pane:`new`,source:`hl2`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[J(`Fisher`),J(`Trigger`)],levels:()=>[1.5,.75,0,-.75,-1.5],create:({period:e})=>new mg(new G(e))};var gg=class e{history;constructor(e){this.history=e}next(e){return e-this.history.push(e)}clone(){return new e(this.history.clone())}};let _g={type:`MTM`,name:`MTM`,pane:`new`,precision:`price`,params:{period:X(10,`Length`)},outputs:()=>[Y(`mom`,`MOM`)],create:({period:e})=>new q([new gg(new V(e))],(e,t)=>t)};var vg=class e{centered;mean;prices;means;constructor(e,t,n,r){this.centered=e,this.mean=t,this.prices=n,this.means=r}next(e){let t=this.mean.next(e),n=this.prices.push(e),r=this.means.push(t);return this.centered?n-t:e-r}clone(){return new e(this.centered,this.mean.clone(),this.prices.clone(),this.means.clone())}};function yg(e){return Math.floor(e/2)+1}let bg={type:`DPO`,name:`DPO`,pane:`new`,precision:2,params:{period:X(21,`Length`),centered:Ym(!1,`Centered`)},outputs:({period:e,centered:t})=>[{...Y(`dpo`,`DPO`),...t===1?{offset:-yg(e)}:{}}],levels:()=>[0],create:({period:e,centered:t})=>new q([new vg(t===1,new H(e),new V(yg(e)),new V(yg(e)))],(e,t)=>t)};var xg=class e{period;previous;rises;constructor(e,t=new K,n=new W(e)){this.period=e,this.previous=t,this.rises=n}next(e){let t=this.previous.next(e),n=Number.isNaN(t)?NaN:+(e>t);return this.rises.next(n)/this.period*100}clone(){return new e(this.period,this.previous.clone(),this.rises.clone())}};let Sg={type:`PSY`,name:`PSY`,pane:`new`,precision:2,params:{period:X(12),signal:X(6,`Signal`)},outputs:()=>[J(`PSY`),J(`PSYMA`)],range:{min:0,max:100},create:({period:e,signal:t})=>new Gm(new xg(e),new Bm(t))};var Cg=class e{period;closes;bullish;bearish;above;below;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new K,n=new W(e),r=new W(e),i=new W(e),a=new W(e)){this.period=e,this.closes=t,this.bullish=n,this.bearish=r,this.above=i,this.below=a}next(e){let t=this.closes.next(e.close),n=this.bullish.next(Math.max(0,e.high-t)),r=this.bearish.next(Math.max(0,t-e.low));return this.out[0]=$(n,r)*100,this.out[1]=$(this.above.next(e.high-e.open),this.below.next(e.open-e.low))*100,this.out}clone(){return new e(this.period,this.closes.clone(),this.bullish.clone(),this.bearish.clone(),this.above.clone(),this.below.clone())}};let wg={type:`BRAR`,name:`BRAR`,pane:`new`,precision:2,params:{period:X(26)},outputs:()=>[J(`BR`),J(`AR`)],create:({period:e})=>new Cg(e)};var Tg=class e{fast;slow;constructor(e,t){this.fast=e,this.slow=t}next(e){return this.fast.next(e)-this.slow.next(e)}clone(){return new e(this.fast.clone(),this.slow.clone())}};let Eg={type:`AO`,name:`AO`,pane:`new`,source:`hl2`,precision:`price`,params:{fast:X(5,`Fast length`),slow:X(34,`Slow length`)},outputs:()=>[{key:`ao`,label:`AO`,plot:{kind:`histogram`,colorBy:`change`}}],create:({fast:e,slow:t})=>new q([new Tg(new H(e),new H(t))],(e,t)=>t)};var Dg=class e{short;long;constructor(e,t){this.short=e,this.long=t}next(e,t){let n=this.long.next(e,t);return $(this.short.next(e,t)-n,n)*100}clone(){return new e(this.short.clone(),this.long.clone())}};let Og={type:`PPO`,name:`PPO`,pane:`new`,precision:2,params:{short:X(10,`Short Length`),long:X(21,`Long Length`),exponential:Ym(!1,`Use Exponential MA`,!1)},outputs:()=>[Y(`ppo`,`PPO`)],levels:()=>[0],create:({short:e,long:t,exponential:n})=>{let r=n===1?`ema`:`sma`;return new q([new Dg($m(r,e),$m(r,t))],(e,t)=>t)}};var kg=class e{period;previous;gains;losses;constructor(e,t=new K,n=new W(e),r=new W(e)){this.period=e,this.previous=t,this.gains=n,this.losses=r}next(e){let t=e-this.previous.next(e),n=this.gains.next(Math.max(t,0)),r=this.losses.next(Math.max(-t,0));return $(100*(n-r),n+r)}clone(){return new e(this.period,this.previous.clone(),this.gains.clone(),this.losses.clone())}};let Ag={type:`CMO`,name:`CMO`,pane:`new`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[Y(`chandeMo`,`Chande MO`)],levels:()=>[0],create:({period:e})=>new q([new kg(e)],(e,t)=>t)};var jg=class e{pressure;range;constructor(e,t){this.pressure=e,this.range=t}static of(t){return new e(new W(t),new W(t))}next(e,t){return $(this.pressure.next(e),this.range.next(t))}clone(){return new e(this.pressure.clone(),this.range.clone())}},Mg=class e{sums;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K){this.sums=e,this.closes=t}next(e){let t=this.closes.next(e.close),n=Math.min(e.low,t),r=e.close-n,i=Math.max(e.high,t)-n,[a,o,s]=this.sums;return this.out[0]=100*(4*a.next(r,i)+2*o.next(r,i)+s.next(r,i))/7,this.out}clone(){let[t,n,r]=this.sums;return new e([t.clone(),n.clone(),r.clone()],this.closes.clone())}};let Ng={type:`UO`,name:`UO`,pane:`new`,precision:2,params:{fast:X(7,`Fast length`),middle:X(14,`Middle length`),slow:X(28,`Slow length`)},outputs:()=>[Y(`uo`,`UO`)],create:({fast:e,middle:t,slow:n})=>new Mg([jg.of(e),jg.of(t),jg.of(n)])};var Pg=class e{roc;average;constructor(e,t){this.roc=e,this.average=t}static of(t,n){return new e(new og(t),new H(n))}next(e){return this.average.next(this.roc.next(e))}clone(){return new e(this.roc.clone(),this.average.clone())}},Fg=class e{rocs;constructor(e){this.rocs=e}next(e){return this.rocs.reduce((t,n,r)=>t+(r+1)*n.next(e),0)}clone(){return new e(this.rocs.map(e=>e.clone()))}};let Ig={type:`KST`,name:`KST`,pane:`new`,precision:4,params:{roc1:X(10,`ROC Length #1`),roc2:X(15,`ROC Length #2`),roc3:X(20,`ROC Length #3`),roc4:X(30,`ROC Length #4`),sma1:X(10,`SMA Length #1`),sma2:X(10,`SMA Length #2`),sma3:X(10,`SMA Length #3`),sma4:X(15,`SMA Length #4`),signal:X(9,`Signal length`)},outputs:()=>[Y(`kst`,`KST`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:e=>new Gm(new Fg([Pg.of(e.roc1,e.sma1),Pg.of(e.roc2,e.sma2),Pg.of(e.roc3,e.sma3),Pg.of(e.roc4,e.sma4)]),new H(e.signal))};var Lg=class e{long;short;average;constructor(e,t,n){this.long=e,this.short=t,this.average=n}next(e){return this.average.next(this.long.next(e)+this.short.next(e))}clone(){return new e(this.long.clone(),this.short.clone(),this.average.clone())}};let Rg={type:`COPPOCK`,name:`Coppock`,pane:`new`,precision:2,params:{wmaLength:X(10,`WMA Length`),longRoc:X(14,`Long RoC Length`),shortRoc:X(11,`Short RoC Length`)},outputs:()=>[Y(`coppockCurve`,`Coppock Curve`)],levels:()=>[0],create:({wmaLength:e,longRoc:t,shortRoc:n})=>new q([new Lg(new og(t),new og(n),new Um(e))],(e,t)=>t)};var zg=class e{first;second;constructor(e,t){this.first=e,this.second=t}static of(t,n){return new e(U.ema(t),U.ema(n))}next(e){return this.second.next(this.first.next(e))}clone(){return new e(this.first.clone(),this.second.clone())}},Bg=class e{change;size;previous;constructor(e,t,n=new K){this.change=e,this.size=t,this.previous=n}next(e){let t=e-this.previous.next(e);return 100*$(this.change.next(t),this.size.next(Math.abs(t)))}clone(){return new e(this.change.clone(),this.size.clone(),this.previous.clone())}};let Vg={type:`TSI`,name:`TSI`,pane:`new`,precision:4,params:{long:X(25,`Long Length`),short:X(13,`Short Length`),signal:X(13,`Signal length`)},outputs:()=>[Y(`trueStrengthIndex`,`True Strength Index`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:({long:e,short:t,signal:n})=>new Gm(new Bg(zg.of(e,t),zg.of(e,t)),U.ema(n))};var Hg=class e{range;distance;width;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.range=e,this.distance=t,this.width=n,this.average=r}next(e){this.range.push(e.high,e.low);let t=this.range.highest(),n=this.range.lowest(),r=200*$(this.distance.next(e.close-(t+n)/2),this.width.next(t-n));return this.out[0]=r,this.out[1]=this.average.next(r),this.out}clone(){return new e(this.range.clone(),this.distance.clone(),this.width.clone(),this.average.clone())}};let Ug={type:`SMI`,name:`SMI`,pane:`new`,precision:2,params:{kLength:X(10,`%K Length`),dLength:X(3,`%D Length`),emaLength:X(3,`EMA Length`)},outputs:()=>[Y(`smi`,`SMI`),Y(`smiBasedEma`,`SMI-based EMA`)],levels:()=>[40,-40],create:({kLength:e,dLength:t,emaLength:n})=>new Hg(new G(e),zg.of(t,t),zg.of(t,t),U.ema(n))};var Wg=class e{window;constructor(e=new V(4)){this.window=e}next(e){this.window.push(e);let{window:t}=this;return t.full?(t.at(0)+2*t.at(1)+2*t.at(2)+t.at(3))/6:NaN}clone(){return new e(this.window.clone())}},Gg=class e{body;span;bodies;spans;signal;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r,i){this.body=e,this.span=t,this.bodies=n,this.spans=r,this.signal=i}next(e){let t=$(this.bodies.next(this.body.next(e.close-e.open)),this.spans.next(this.span.next(e.high-e.low)));return this.out[0]=t,this.out[1]=this.signal.next(t),this.out}clone(){return new e(this.body.clone(),this.span.clone(),this.bodies.clone(),this.spans.clone(),this.signal.clone())}};let Kg={type:`RVGI`,name:`RVGI`,pane:`new`,precision:4,params:{period:X(10,`Length`)},outputs:()=>[Y(`rvgi`,`RVGI`),Y(`signalLine`,`Signal line`)],create:({period:e})=>new Gg(new Wg,new Wg,new W(e),new W(e),new Wg)},qg={type:`BOP`,name:`BOP`,pane:`new`,precision:2,params:{},outputs:()=>[Y(`bop`,`BOP`)],create:()=>new q([Wm],e=>$(e.close-e.open,e.high-e.low))};var Jg=class e{previous;streak;constructor(e=new K,t=0){this.previous=e,this.streak=t}next(e){let t=this.previous.next(e),{streak:n}=this;return this.streak=e===t?0:e>t?Math.max(n,0)+1:Math.min(n,0)-1,this.streak}clone(){return new e(this.previous.clone(),this.streak)}},Yg=class e{window;constructor(e){this.window=e}next(e){if(Number.isNaN(e))return NaN;let{window:t}=this,n=0;for(let r=0;r<t.length;r+=1)n+=+(t.at(r)<=e);let r=t.full?100*n/t.capacity:NaN;return t.push(e),r}clone(){return new e(this.window.clone())}},Xg=class e{rsi;streak;streakRsi;change;rank;constructor(e,t,n,r,i){this.rsi=e,this.streak=t,this.streakRsi=n,this.change=r,this.rank=i}next(e){return(this.rsi.next(e)+this.streakRsi.next(this.streak.next(e))+this.rank.next(this.change.next(e)))/3}clone(){return new e(this.rsi.clone(),this.streak.clone(),this.streakRsi.clone(),this.change.clone(),this.rank.clone())}};let Zg={type:`CRSI`,name:`CRSI`,pane:`new`,precision:2,params:{rsiLength:X(3,`RSI Length`),streakLength:X(2,`UpDown Length`),rocLength:X(100,`ROC Length`)},outputs:()=>[Y(`crsi`,`CRSI`)],levels:()=>[70,50,30],range:{min:0,max:100},create:({rsiLength:e,streakLength:t,rocLength:n})=>new q([new Xg(new Qh(e),new Jg,new Qh(t),new og(1),new Yg(new V(n)))],(e,t)=>t)},Qg=[`1D`,`1W`,`1M`,`3M`,`12M`];function $g(e){return Q(Qg,e,`period`)}var e_=class e{calendar;interval;years;current=null;previous=null;start=NaN;constructor(e,t,n=1){this.calendar=e,this.interval=t,this.years=n}push(e){let t=this.calendar.bucket(e.time,this.interval);return t!==null&&t!==this.start&&(this.years===1||new Date(t+1728e5).getUTCFullYear()%this.years===0)?(this.start=t,this.previous=this.current,this.current={open:e.open,high:e.high,low:e.low,close:e.close},!0):(this.current&&(this.current.high=Math.max(this.current.high,e.high),this.current.low=Math.min(this.current.low,e.low),this.current.close=e.close),!1)}clone(){let t=new e(this.calendar,this.interval,this.years);return t.start=this.start,t.current=this.current&&{...this.current},t.previous=this.previous&&{...this.previous},t}};let t_=[{label:`Traditional`,depth:5,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3;return[r,r*2-t,r*2-e,r+(e-t),r-(e-t),r*2+(e-2*t),r*2-(2*e-t),r*3+(e-3*t),r*3-(3*e-t),r*4+(e-4*t),r*4-(4*e-t)]}},{label:`Fibonacci`,depth:3,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3,i=e-t;return[r,r+.382*i,r-.382*i,r+.618*i,r-.618*i,r+i,r-i]}},{label:`Woodie`,depth:4,levels:({high:e,low:t},n)=>{let r=(e+t+2*n)/4,i=e+2*(r-t),a=t-2*(e-r);return[r,2*r-t,2*r-e,r+(e-t),r-(e-t),i,a,i+(e-t),a-(e-t)]}},{label:`Classic`,depth:4,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3,i=e-t;return[r,2*r-t,2*r-e,r+i,r-i,r+2*i,r-2*i,r+3*i,r-3*i]}},{label:`DM`,depth:1,levels:({open:e,high:t,low:n,close:r})=>{let i=r===e?t+n+2*r:r>e?2*t+n+r:2*n+t+r;return[i/4,i/2-n,i/2-t]}},{label:`Camarilla`,depth:5,levels:({high:e,low:t,close:n})=>{let r=1.1*(e-t),i=e/t*n;return[(e+t+n)/3,n+r/12,n-r/12,n+r/6,n-r/6,n+r/4,n-r/4,n+r/2,n-r/2,i,n-(i-n)]}}];function n_(e){return t_[e]??n(`There are no pivot points of kind ${e}.`)}let r_=[[`1D`,1],[`1W`,1],[`1M`,1],[`3M`,1],[`12M`,1],[`12M`,2],[`12M`,3],[`12M`,5],[`12M`,10]];function i_(e){if(e===null)return`1D`;let t=aa(e);return t===null?e.unit===`day`&&e.count<7?`1M`:`12M`:t<=9e5?`1D`:`1W`}var a_=class e{kind;periods;levels;constructor(e,t,n=new Float64Array(1+e.depth*2).fill(NaN)){this.kind=e,this.periods=t,this.levels=n}next(e){if(this.periods.push(e)){let{previous:e,current:t}=this.periods;e&&t&&(this.levels=Float64Array.from(this.kind.levels(e,t.open)))}return this.levels}clone(){return new e(this.kind,this.periods.clone(),this.levels)}};let o_={type:`PIVOTS`,name:`Pivots`,pane:`main`,precision:`price`,params:{kind:{default:0,label:`Type`,options:/* @__PURE__ */ t_.map(({label:e},t)=>({value:t,label:e}))},period:Z([`Auto`,`Daily`,`Weekly`,`Monthly`,`Quarterly`,`Yearly`,`Biyearly`,`Triyearly`,`Quinquennially`,`Decennially`],0,`Pivots timeframe`)},outputs:({kind:e})=>{let t=[{key:`p`,label:`P`,plot:{kind:`segments`},autoscale:!1}];for(let n=1;n<=n_(e).depth;n+=1)t.push({key:`r${n}`,label:`R${n}`,plot:{kind:`segments`},themeColor:`down`,autoscale:!1},{key:`s${n}`,label:`S${n}`,plot:{kind:`segments`},themeColor:`up`,autoscale:!1});return t},create:({kind:e,period:t},{calendar:n,interval:r})=>{let[i,a]=t===0?[i_(r),1]:Q(r_,t-1,`pivot timeframe`);return new a_(n_(e),new e_(n,i,a))}};var s_=class e{periods;out=/* @__PURE__ */ new Float64Array(3);constructor(e){this.periods=e}next(e){this.periods.push(e);let t=this.periods.previous;return this.out[0]=t?.high??NaN,this.out[1]=t?.low??NaN,this.out[2]=t?.close??NaN,this.out}clone(){return new e(this.periods.clone())}};let c_={type:`PREVHLC`,name:`Prev HLC`,pane:`main`,precision:`price`,params:{period:Z([`Day`,`Week`,`Month`,`Quarter`,`Year`],0,`Period`)},outputs:()=>[{key:`high`,label:`PH`,plot:{kind:`segments`},themeColor:`up`,autoscale:!1},{key:`low`,label:`PL`,plot:{kind:`segments`},themeColor:`down`,autoscale:!1},{key:`close`,label:`PC`,plot:{kind:`segments`,style:`dashed`},autoscale:!1}],create:({period:e},{calendar:t})=>new s_(new e_(t,$g(e)))},l_={type:`ADR`,name:`ADR`,pane:`new`,precision:`price`,params:{period:X(14,`Length`)},outputs:()=>[J(`ADR`)],create:({period:e})=>new q([new H(e)],e=>e.high-e.low)},u_=[`1D`,`1W`,`1M`,`3M`,`12M`];function d_(e,t){let{offsets:n,volumes:r}=e,i=0,a=n.length;for(;i<a;){let e=i+a>>>1;(n[e]??NaN)<=t?i=e+1:a=e}return i===0?NaN:r[i-1]??NaN}var f_=class e{start;offsets;volumes;count;total;constructor(e=NaN,t=/* @__PURE__ */ new Float64Array(64),n=/* @__PURE__ */ new Float64Array(64),r=0,i=0){this.start=e,this.offsets=t,this.volumes=n,this.count=r,this.total=i}add(e,t){if(this.count===this.offsets.length){let e=new Float64Array(this.count*2),t=new Float64Array(this.count*2);e.set(this.offsets),t.set(this.volumes),this.offsets=e,this.volumes=t}this.offsets[this.count]=e,this.volumes[this.count]=t,this.count+=1}ended(){return{offsets:this.offsets.slice(0,this.count),volumes:this.volumes.slice(0,this.count)}}clone(){return new e(this.start,this.offsets.slice(),this.volumes.slice(),this.count,this.total)}},p_=class e{calendar;anchor;length;cumulative;current;past;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n,r,i=new f_,a=[]){this.calendar=e,this.anchor=t,this.length=n,this.cumulative=r,this.current=i,this.past=a}next(e){let t=this.calendar.bucket(e.time,this.anchor);if(t!==null&&t!==this.current.start&&(Number.isNaN(this.current.start)||(this.past=[...this.past,this.current.ended()].slice(-this.length)),this.current=new f_(t)),Number.isNaN(this.current.start))return this.out.fill(NaN),this.out;let n=e.time-this.current.start;this.current.total+=e.volume;let r=this.cumulative?this.current.total:e.volume;this.current.add(n,r);let i=this.past.length<this.length?NaN:this.average(n);return this.out[0]=$(r,i),this.out[1]=r,this.out[2]=i,this.out}average(e){let t=0,n=0;for(let r of this.past){let i=d_(r,e);Number.isNaN(i)||(t+=i,n+=1)}return n===0?NaN:t/n}clone(){return new e(this.calendar,this.anchor,this.length,this.cumulative,this.current.clone(),this.past)}};let m_={type:`RVOL`,name:`RelVol`,pane:`new`,precision:`volume`,params:{anchor:Z([`Day`,`Week`,`Month`,`Quarter`,`Year`],0,`Anchor Timeframe`),period:X(5,`Length`),mode:Z([`Cumulative`,`Regular`],0,`Calculation Mode`)},outputs:()=>[{key:`relativeVolumeRatio`,label:`Relative Volume Ratio`,plot:{kind:`columns`,from:0},precision:2},{key:`currentVolume`,label:`Current Volume`,plot:{kind:`hidden`}},{key:`pastVolume`,label:`Past Volume`,plot:{kind:`hidden`}}],levels:()=>[1],create:({anchor:e,period:t,mode:n},{calendar:r})=>new p_(r,Q(u_,e,`anchor`),t,Q([!0,!1],n,`calculation mode`))},h_=[{key:`tokyo`,label:`Tokyo`,session:`09:00-15:00`,timeZone:`Asia/Tokyo`},{key:`london`,label:`London`,session:`08:30-16:30`,timeZone:`Europe/London`},{key:`newYork`,label:`New York`,session:`09:30-16:00`,timeZone:`America/New_York`}],g_=/^[a-zA-Z][a-zA-Z0-9]*$/;function __(e,t){h(t,e),g_.test(p(`${t}.key`,e.key))||n(`${t}.key must be letters and digits, starting with a letter, received "${e.key}".`),p(`${t}.label`,e.label);let r=p(`${t}.session`,e.session);return _a({timeZone:p(`${t}.timeZone`,e.timeZone),sessions:[r],dayStart:r.split(`-`)[0]??``})}var v_=class e{calendars;state;out;constructor(e,t=new Float64Array(e.length*3).fill(NaN)){this.calendars=e,this.state=t,this.out=new Float64Array(e.length*3)}next(e){let{state:t,out:n}=this;return this.calendars.forEach((r,i)=>{let a=r.bucket(e.time,`1D`),o=i*3;a===null?(t[o]=NaN,n.fill(NaN,o,o+3)):(a!==t[o]&&(t[o]=a,t[o+1]=e.high,t[o+2]=e.low),t[o+1]=Math.max(t[o+1]??NaN,e.high),t[o+2]=Math.min(t[o+2]??NaN,e.low),n[o]=t[o+1]??NaN,n[o+1]=t[o+2]??NaN,n[o+2]=a)}),n}clone(){return new e(this.calendars,this.state.slice())}};function y_(e,t=`SESSIONS`){v(`sessions`,e),e.length===0&&n(`sessions must contain at least one session.`);let r=e.map((e,t)=>__(e,`sessions[${t}]`)),i=e.flatMap(({key:e,label:t})=>[{key:`${e}High`,label:`${t} H`,plot:{kind:`box`,from:`${e}Low`,group:`${e}Day`},autoscale:!1},{key:`${e}Low`,label:`${t} L`,plot:{kind:`hidden`}},{key:`${e}Day`,label:`${t} day`,plot:{kind:`hidden`},legend:!1,precision:0}]);return{type:t,name:`Sessions`,pane:`main`,precision:`price`,params:{},outputs:()=>i,create:()=>new v_(r)}}let b_=/* @__PURE__ */ y_(h_);var x_=class e{opens;lows;closes;constructor(e=new K,t=new K,n=new K){this.opens=e,this.lows=t,this.closes=n}next(e){let t=this.opens.next(e.open),n=this.lows.next(e.low),r=this.closes.next(e.close),i=Math.abs(e.high-r),a=Math.abs(e.low-r),o=Math.abs(e.high-n),s=Math.abs(r-t),c=i>a&&i>o?i+a/2+s/4:a>o&&a>i?a+i/2+s/4:o+s/4,l=e.close-r+(e.close-e.open)/2+r-t;return c===0?0:16*l/c*Math.max(i,a)}clone(){return new e(this.opens.clone(),this.lows.clone(),this.closes.clone())}},S_=class e{swing;sum;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.swing=e,this.sum=t,this.average=n}next(e){let t=this.sum.next(this.swing.next(e));return this.out[0]=t,this.out[1]=this.average.next(t),this.out}clone(){return new e(this.swing.clone(),this.sum.clone(),this.average.clone())}};let C_={type:`ASI`,name:`ASI`,pane:`new`,precision:`price`,params:{period:X(26),signal:X(10,`Signal`)},outputs:()=>[J(`ASI`),J(`ASIT`)],create:({period:e,signal:t})=>new S_(new x_,new W(e),new Bm(t))};function w_(e){return Math.floor(e/2.5+1)}var T_=class e{average;history;constructor(e,t){this.average=e,this.history=t}static of(t){return new e(new Bm(t),new V(w_(t)))}next(e){return this.history.push(this.average.next(e))}clone(){return new e(this.average.clone(),this.history.clone())}},E_=class e{averages;middles;above;below;out;constructor(e,t,n,r){this.averages=e,this.middles=t,this.above=n,this.below=r,this.out=new Float64Array(1+e.length)}next(e){let t=this.middles.next((e.high+e.low)/2),n=$(this.above.next(Math.max(0,e.high-t)),this.below.next(Math.max(0,t-e.low)))*100;return this.out[0]=n,this.averages.forEach((e,t)=>{this.out[t+1]=e.next(n)}),this.out}clone(){return new e(this.averages.map(e=>e.clone()),this.middles.clone(),this.above.clone(),this.below.clone())}};let D_={type:`CR`,name:`CR`,pane:`new`,precision:2,params:{period:X(26),periods:qm([10,20,40,62],`MA Length`)},outputs:({periods:e})=>[J(`CR`),...Km(`MA`,e)],create:({period:e,periods:t})=>new E_(t.map(e=>T_.of(e)),new K,new W(e),new W(e))};function O_(e){return(e.highest()+e.lowest())/2}var k_=class e{conversion;base;spanB;out=/* @__PURE__ */ new Float64Array(7);constructor(e,t,n){this.conversion=e,this.base=t,this.spanB=n}next(e){this.conversion.push(e.high,e.low),this.base.push(e.high,e.low),this.spanB.push(e.high,e.low);let t=O_(this.conversion),n=O_(this.base),r=(t+n)/2,i=O_(this.spanB);return this.out[0]=t,this.out[1]=n,this.out[2]=e.close,this.out[3]=r,this.out[4]=i,this.out[5]=Math.max(r,i),this.out[6]=Math.min(r,i),this.out}clone(){return new e(this.conversion.clone(),this.base.clone(),this.spanB.clone())}};let A_={type:`ICHIMOKU`,name:`Ichimoku`,pane:`main`,precision:`price`,params:{conversion:X(9,`Conversion Line Length`),base:X(26,`Base Line Length`),spanB:X(52,`Leading Span B Length`),displacement:X(26,`Displacement`)},outputs:({displacement:e})=>{let t=e-1,n=(e,n)=>({key:e,label:n,plot:{kind:`hidden`},offset:t,legend:!1});return[Y(`conversionLine`,`Conversion Line`),Y(`baseLine`,`Base Line`),{...Y(`laggingSpan`,`Lagging Span`),offset:-t},{...Y(`leadingSpanA`,`Leading Span A`),themeColor:`up`,offset:t},{...Y(`leadingSpanB`,`Leading Span B`),themeColor:`down`,offset:t},n(`kumoCloudUpperLine`,`Kumo Cloud Upper Line`),n(`kumoCloudLowerLine`,`Kumo Cloud Lower Line`)]},fills:()=>[{from:`leadingSpanA`,to:`leadingSpanB`,colorBy:`higher`}],create:({conversion:e,base:t,spanB:n})=>new k_(new G(e),new G(t),new G(n))};var j_=class e{start;increment;maximum;out=/* @__PURE__ */ new Float64Array(1);state={index:0,sar:NaN,extreme:NaN,acceleration:NaN,rising:!1,close:NaN,high:NaN,low:NaN,high2:NaN,low2:NaN};constructor(e,t,n){this.start=e,this.increment=t,this.maximum=n}next(e){let t=this.state,n=t.index===1;return n&&(t.rising=e.close>t.close,t.extreme=t.rising?e.high:e.low,t.sar=t.rising?t.low:t.high,t.acceleration=this.start),t.sar+=t.acceleration*(t.extreme-t.sar),(t.rising?t.sar>e.low:t.sar<e.high)&&(n=!0,t.sar=t.rising?Math.max(e.high,t.extreme):Math.min(e.low,t.extreme),t.rising=!t.rising,t.extreme=t.rising?e.high:e.low,t.acceleration=this.start),!n&&(t.rising?e.high>t.extreme:e.low<t.extreme)&&(t.extreme=t.rising?e.high:e.low,t.acceleration=Math.min(t.acceleration+this.increment,this.maximum)),t.sar=t.rising?Math.min(t.sar,t.low,t.index>1?t.low2:t.low):Math.max(t.sar,t.high,t.index>1?t.high2:t.high),this.out[0]=t.sar,t.index+=1,t.close=e.close,t.high2=t.high,t.low2=t.low,t.high=e.high,t.low=e.low,this.out}clone(){let t=new e(this.start,this.increment,this.maximum);return t.state={...this.state},t}};let M_={type:`SAR`,name:`SAR`,pane:`main`,precision:`price`,params:{start:{default:.02,min:.001,max:1,label:`Start`},increment:{default:.02,min:.001,max:1,label:`Increment`},maximum:{default:.2,min:.001,max:1,label:`Max value`}},outputs:()=>[{key:`parabolicSar`,label:`ParabolicSAR`,plot:{kind:`marker`,shape:`circle`,size:2}}],create:({start:e,increment:t,maximum:n})=>new j_(e,t,n)};var N_=class e{multiplier;range;out=/* @__PURE__ */ new Float64Array(3);state={close:NaN,atr:NaN,upper:NaN,lower:NaN,trend:NaN};constructor(e,t){this.multiplier=e,this.range=t}next(e){let t=this.state,n=this.range.next(e),r=(e.high+e.low)/2,i=Number.isNaN(t.upper)?0:t.upper,a=Number.isNaN(t.lower)?0:t.lower,o=r+this.multiplier*n,s=r-this.multiplier*n;s>a||t.close<a||(s=a),o<i||t.close>i||(o=i);let c=Number.isNaN(t.atr)||(t.trend===i?e.close<=o:e.close<s),l=c?o:s,u=Number.isNaN(t.close);return this.out[0]=u||c?NaN:l,this.out[1]=u||!c?NaN:l,this.out[2]=u?NaN:(e.open+e.close)/2,this.state={close:e.close,atr:n,upper:o,lower:s,trend:l},this.out}clone(){let t=new e(this.multiplier,this.range.clone());return t.state=this.state,t}};let P_={type:`SUPERTREND`,name:`SuperTrend`,pane:`main`,precision:`price`,params:{period:X(10,`ATR Length`),multiplier:{default:3,min:.01,max:10,label:`Factor`}},outputs:()=>[{...Y(`upTrend`,`Up Trend`),themeColor:`up`},{...Y(`downTrend`,`Down Trend`),themeColor:`down`},{key:`bodyMiddle`,label:`Body Middle`,plot:{kind:`hidden`},legend:!1}],fills:()=>[{from:`upTrend`,to:`bodyMiddle`},{from:`downTrend`,to:`bodyMiddle`}],create:({period:e,multiplier:t})=>new N_(t,xh.of(e))};function F_(e,t){return Number.isNaN(e)?t:e}var I_=class e{highs;lows;closes;range;plusMoves;minusMoves;adx;plus;minus;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n,r,i,a,o,s=NaN,c=NaN){this.highs=e,this.lows=t,this.closes=n,this.range=r,this.plusMoves=i,this.minusMoves=a,this.adx=o,this.plus=s,this.minus=c}static of(t,n){return new e(new K,new K,new K,U.rma(t),U.rma(t),U.rma(t),U.rma(n))}next(e){let t=e.high-this.highs.next(e.high),n=this.lows.next(e.low)-e.low,r=this.range.next(yh(e,this.closes.next(e.close))),i=Number.isNaN(t)?NaN:t>n&&t>0?t:0,a=Number.isNaN(n)?NaN:n>t&&n>0?n:0;this.plus=F_($(100*this.plusMoves.next(i),r),this.plus),this.minus=F_($(100*this.minusMoves.next(a),r),this.minus);let o=this.plus+this.minus;return this.out[0]=100*this.adx.next(Math.abs(this.plus-this.minus)/(o===0?1:o)),this.out[1]=this.plus,this.out[2]=this.minus,this.out}clone(){return new e(this.highs.clone(),this.lows.clone(),this.closes.clone(),this.range.clone(),this.plusMoves.clone(),this.minusMoves.clone(),this.adx.clone(),this.plus,this.minus)}};let L_={type:`DMI`,name:`DMI`,pane:`new`,precision:4,params:{adxSmoothing:X(14,`ADX Smoothing`),diLength:X(14,`DI Length`)},outputs:()=>[Y(`adx`,`ADX`),Y(`plus`,`+DI`),Y(`minus`,`-DI`)],create:({adxSmoothing:e,diLength:t})=>I_.of(t,e)};var R_=class e{fast;slow;constructor(e,t){this.fast=e,this.slow=t}next(e){return this.fast.next(e)-this.slow.next(e)}clone(){return new e(this.fast.clone(),this.slow.clone())}};let z_={type:`DMA`,name:`DMA`,pane:`new`,precision:`price`,params:{fast:X(10,`Fast`),slow:X(50,`Slow`),signal:X(10,`Signal`)},outputs:()=>[J(`DIF`),J(`DIFMA`)],create:({fast:e,slow:t,signal:n})=>new Gm(new R_(new Bm(e),new Bm(t)),new Bm(n))};var B_=class e{averages;previous;constructor(e,t=new K){this.averages=e,this.previous=t}next(e){let t=this.averages.reduce((e,t)=>t.next(e),Math.log(e));return 1e4*(t-this.previous.next(t))}clone(){return new e(this.averages.map(e=>e.clone()),this.previous.clone())}};let V_={type:`TRIX`,name:`TRIX`,pane:`new`,precision:2,params:{period:X(18,`Length`)},outputs:()=>[J(`TRIX`)],levels:()=>[0],create:({period:e})=>new q([new B_([U.ema(e),U.ema(e),U.ema(e)])],(e,t)=>t)};function H_(e,t){let n=0;for(let r=1;r<e.length;r+=1)t*e.at(r)>=t*e.at(n)&&(n=r);return e.length-1-n}var U_=class e{period;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new V(e+1),n=new V(e+1)){this.period=e,this.highs=t,this.lows=n}next(e){return this.highs.push(e.high),this.lows.push(e.low),this.highs.full?(this.out[0]=100*(this.period-H_(this.highs,1))/this.period,this.out[1]=100*(this.period-H_(this.lows,-1))/this.period,this.out):(this.out.fill(NaN),this.out)}clone(){return new e(this.period,this.highs.clone(),this.lows.clone())}};let W_={type:`AROON`,name:`Aroon`,pane:`new`,precision:2,params:{period:X(14,`Length`)},outputs:()=>[{...Y(`aroonUp`,`Aroon Up`),themeColor:`up`},{...Y(`aroonDown`,`Aroon Down`),themeColor:`down`}],range:{min:0,max:100},create:({period:e})=>new U_(e)};var G_=class e{multiplier;extremes;range;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.multiplier=e,this.extremes=t,this.range=n}next(e){let t=this.multiplier*this.range.next(e);return this.extremes.push(e.high,e.low),this.out[0]=this.extremes.highest()-t,this.out[1]=this.extremes.lowest()+t,this.out}clone(){return new e(this.multiplier,this.extremes.clone(),this.range.clone())}};let K_={type:`CHANDELIER`,name:`Chandelier`,pane:`main`,precision:`price`,params:{period:X(22,`Length`),atrPeriod:X(22,`ATR length`),multiplier:{default:3,min:0,max:100,label:`ATR multiplier`}},outputs:()=>[{...Y(`longExit`,`Long exit`),themeColor:`up`},{...Y(`shortExit`,`Short exit`),themeColor:`down`}],create:({period:e,atrPeriod:t,multiplier:n})=>new G_(n,new G(e),xh.of(t))},q_={type:`VOL`,name:`VOL`,pane:`new`,precision:`volume`,params:{periods:{default:[],min:1,max:2e3,integer:!0,label:`MA Length`}},outputs:({periods:e})=>[{key:`volume`,label:`Volume`,plot:{kind:`histogram`,colorBy:`bar`}},...e.map(e=>Y(`ma${String(e)}`,`MA${String(e)}`))],create:({periods:e})=>new q([Wm,...e.map(e=>new H(e))],e=>e.volume)};var J_=class e{closes;total;constructor(e=new K,t=0){this.closes=e,this.total=t}next(e,t){let n=t.close-this.closes.next(t.close);return Number.isNaN(n)||(this.total+=Math.sign(n)*t.volume),this.total}clone(){return new e(this.closes.clone(),this.total)}};let Y_={type:`OBV`,name:`OBV`,pane:`new`,precision:`volume`,params:th(!1),outputs:e=>[Y(`onBalanceVolume`,`OnBalanceVolume`),...nh(`obv`,`OBV`,e)],fills:rh,create:e=>ih.of(new J_,e)};var X_=class e{period;average;closes;up;down;flat;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n=new K,r=new W(e),i=new W(e),a=new W(e)){this.period=e,this.average=t,this.closes=n,this.up=r,this.down=i,this.flat=a}next(e){let t=e.close-this.closes.next(e.close);if(Number.isNaN(t))return this.out.fill(NaN),this.out;let n=this.up.next(t>0?e.volume:0),r=this.down.next(t<0?e.volume:0),i=this.flat.next(t===0?e.volume:0),a=$(2*n+i,2*r+i)*100;return this.out[0]=a,this.out[1]=this.average.next(a),this.out}clone(){return new e(this.period,this.average.clone(),this.closes.clone(),this.up.clone(),this.down.clone(),this.flat.clone())}};let Z_={type:`VR`,name:`VR`,pane:`new`,precision:2,params:{period:X(26),signal:X(6,`Signal`)},outputs:()=>[J(`VR`),J(`MAVR`)],create:({period:e,signal:t})=>new X_(e,new Bm(t))};var Q_=class e{divisor;medians;constructor(e,t=new K){this.divisor=e,this.medians=t}next(e,t){let n=(t.high+t.low)/2,r=n-this.medians.next(n);return $(this.divisor*r*(t.high-t.low),t.volume)}clone(){return new e(this.divisor,this.medians.clone())}},$_=class e{ease;average;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.ease=e,this.average=t}next(e,t){return this.out[0]=this.average.next(this.ease.next(t,e)),this.out}clone(){return new e(this.ease.clone(),this.average.clone())}};let ev={type:`EMV`,name:`EMV`,pane:`new`,precision:`volume`,params:{period:X(14,`Length`),divisor:{default:1e4,min:1,max:0xe8d4a51000,integer:!0,label:`Divisor`}},outputs:()=>[Y(`eom`,`EOM`)],create:({period:e,divisor:t})=>new $_(new Q_(t),new H(e))};var tv=class e{period;typicals;positive;negative;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K,n=new W(e),r=new W(e)){this.period=e,this.typicals=t,this.positive=n,this.negative=r}next(e){let t=(e.high+e.low+e.close)/3,n=t-this.typicals.next(t),r=t*e.volume,i=this.positive.next(n<=0?0:r),a=this.negative.next(n>=0?0:r);return this.out[0]=100-100/(1+$(i,a)),this.out}clone(){return new e(this.period,this.typicals.clone(),this.positive.clone(),this.negative.clone())}};let nv={type:`MFI`,name:`MFI`,pane:`new`,precision:2,params:{period:X(14,`Length`)},outputs:()=>[Y(`mf`,`MF`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({period:e})=>new tv(e)};var rv=class e{period;flows;volumes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new W(e),n=new W(e)){this.period=e,this.flows=t,this.volumes=n}next(e){let t=e.high-e.low,n=t===0?0:(2*e.close-e.low-e.high)/t*e.volume;return this.out[0]=$(this.flows.next(n),this.volumes.next(e.volume)),this.out}clone(){return new e(this.period,this.flows.clone(),this.volumes.clone())}};let iv={type:`CMF`,name:`CMF`,pane:`new`,precision:2,params:{period:X(20,`Length`)},outputs:()=>[J(`CMF`)],levels:()=>[0],create:({period:e})=>new rv(e)},av=[`1D`,`1W`,`1M`,`3M`,`12M`];var ov=class e{calendar;anchor;percent;bands;period;volume;sum;squares;out;constructor(e,t,n,r,i=NaN,a=0,o=0,s=0){this.calendar=e,this.anchor=t,this.percent=n,this.bands=r,this.period=i,this.volume=a,this.sum=o,this.squares=s,this.out=new Float64Array(1+r.length*2)}next(e,t){let n=this.calendar.bucket(e.time,this.anchor);n!==null&&n!==this.period&&(this.period=n,this.volume=0,this.sum=0,this.squares=0),this.volume+=e.volume,this.sum+=t*e.volume,this.squares+=t*t*e.volume;let r=this.sum/this.volume,i=this.percent?r*.01:Math.sqrt(Math.max(0,this.squares/this.volume-r*r));return this.out[0]=r,this.bands.forEach((e,t)=>{this.out[1+t*2]=r+i*e,this.out[2+t*2]=r-i*e}),this.out}clone(){return new e(this.calendar,this.anchor,this.percent,this.bands,this.period,this.volume,this.sum,this.squares)}};function sv({band1:e,band2:t,band3:n}){return[e,t,n]}function cv(e,t){return{default:t,min:0,max:10,label:`Bands Multiplier #${String(e)}`,legend:!1}}let lv={type:`VWAP`,name:`VWAP`,pane:`main`,source:`hlc3`,precision:`price`,params:{anchor:Z([`Session`,`Week`,`Month`,`Quarter`,`Year`],0,`Anchor Period`),bandMode:Z([`Standard Deviation`,`Percentage`],0,`Bands Calculation Mode`,!1),band1:cv(1,1),band2:cv(2,0),band3:cv(3,0)},outputs:e=>[Y(`vwap`,`VWAP`),...sv(e).flatMap((e,t)=>e>0?[Y(`upperBand${String(t+1)}`,`Upper Band #${String(t+1)}`),Y(`lowerBand${String(t+1)}`,`Lower Band #${String(t+1)}`)]:[])],fills:e=>sv(e).flatMap((e,t)=>e>0?[{from:`upperBand${String(t+1)}`,to:`lowerBand${String(t+1)}`}]:[]),create:(e,{calendar:t})=>new ov(t,Q(av,e.anchor,`VWAP anchor`),Q([!1,!0],e.bandMode,`VWAP band mode`),sv(e).filter(e=>e>0))};function uv(e){let t=e.high-e.low;return t===0?0:(2*e.close-e.low-e.high)/t*e.volume}var dv=class e{total;constructor(e=0){this.total=e}next(e,t){return this.total+=uv(t),this.total}clone(){return new e(this.total)}};let fv={type:`AD`,name:`Accum/Dist`,pane:`new`,precision:`volume`,params:{},outputs:()=>[Y(`accumulationDistribution`,`Accumulation/Distribution`)],create:()=>new q([new dv],(e,t)=>t)};var pv=class e{line;fast;slow;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t,n){this.line=e,this.fast=t,this.slow=n}next(e,t){let n=this.line.next(t,e);return this.out[0]=this.fast.next(n)-this.slow.next(n),this.out}clone(){return new e(this.line.clone(),this.fast.clone(),this.slow.clone())}};let mv={type:`CHAIKINOSC`,name:`Chaikin Osc`,pane:`new`,precision:`volume`,params:{fast:X(3,`Fast length`),slow:X(10,`Slow length`)},outputs:()=>[Y(`chaikinOscillator`,`Chaikin Oscillator`)],levels:()=>[0],create:({fast:e,slow:t})=>new pv(new dv,U.ema(e),U.ema(t))};var hv=class e{short;long;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.short=e,this.long=t}next(e){let t=this.short.next(e.volume),n=this.long.next(e.volume);return this.out[0]=$(t-n,n)*100,this.out}clone(){return new e(this.short.clone(),this.long.clone())}};let gv={type:`VO`,name:`Volume Osc`,pane:`new`,precision:2,params:{short:X(5,`Short Length`),long:X(10,`Long Length`)},outputs:()=>[Y(`volumeOsc`,`Volume Osc`)],levels:()=>[0],create:({short:e,long:t})=>new hv(U.ema(e),U.ema(t))};var _v=class e{average;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K){this.average=e,this.closes=t}next(e){let t=e.close-this.closes.next(e.close);return this.out[0]=this.average.next(t*e.volume),this.out}clone(){return new e(this.average.clone(),this.closes.clone())}};let vv={type:`EFI`,name:`EFI`,pane:`new`,precision:`volume`,params:{period:X(13,`Length`)},outputs:()=>[Y(`elderForceIndex`,`Elder Force Index`)],levels:()=>[0],create:({period:e})=>new _v(U.ema(e))};var yv=class e{fast;slow;signal;typicals;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r=new K){this.fast=e,this.slow=t,this.signal=n,this.typicals=r}next(e){let t=(e.high+e.low+e.close)/3,n=t-this.typicals.next(t)>=0?e.volume:-e.volume,r=this.fast.next(n)-this.slow.next(n);return this.out[0]=r,this.out[1]=this.signal.next(r),this.out}clone(){return new e(this.fast.clone(),this.slow.clone(),this.signal.clone(),this.typicals.clone())}};let bv={type:`KVO`,name:`KVO`,pane:`new`,precision:`volume`,params:{fast:X(34,`Fast length`),slow:X(55,`Slow length`),signal:X(13,`Signal length`)},outputs:()=>[Y(`klingerOscillator`,`Klinger Oscillator`),Y(`signalLine`,`Signal line`)],create:({fast:e,slow:t,signal:n})=>new yv(U.ema(e),U.ema(t),U.ema(n))};var xv=class e{closes;total;constructor(e=new K,t=0){this.closes=e,this.total=t}next(e,t){let n=this.closes.next(t.close),r=$(t.close-n,n)*t.volume;return Number.isNaN(r)||(this.total+=r),this.total}clone(){return new e(this.closes.clone(),this.total)}};let Sv={type:`PVT`,name:`PVT`,pane:`new`,precision:`volume`,params:{},outputs:()=>[J(`PVT`)],create:()=>new q([new xv],(e,t)=>t)};var Cv=class e{sum;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t){this.sum=e,this.average=t}next(e){let t=e.high-e.low,n=t===0?0:(e.close-e.open)/t*e.volume,r=this.sum.next(n)/1e4;return this.out[0]=r,this.out[1]=this.average.next(r),this.out}clone(){return new e(this.sum.clone(),this.average.clone())}};let wv={type:`WVAD`,name:`WVAD`,pane:`new`,precision:`volume`,params:{period:X(24),signal:X(6,`Signal`)},outputs:()=>[J(`WVAD`),J(`MAWVAD`)],create:({period:e,signal:t})=>new Cv(new W(e),new Bm(t))};function Tv(e,t){return{default:e,min:0,max:500,integer:!0,label:t}}let Ev={type:`ALLIGATOR`,name:`Alligator`,pane:`main`,source:`hl2`,precision:`price`,params:{jaw:X(13,`Jaw Length`),teeth:X(8,`Teeth Length`),lips:X(5,`Lips Length`),jawShift:Tv(8,`Jaw Offset`),teethShift:Tv(5,`Teeth Offset`),lipsShift:Tv(3,`Lips Offset`)},outputs:({jawShift:e,teethShift:t,lipsShift:n})=>[{...Y(`jaw`,`Jaw`),offset:e},{...Y(`teeth`,`Teeth`),offset:t},{...Y(`lips`,`Lips`),offset:n}],create:({jaw:e,teeth:t,lips:n})=>new q([e,t,n].map(e=>U.rma(e)),(e,t)=>t)};function Dv(e,t,n){let r=n*e.fromEnd(t);for(let i=0;i<t;i+=1)if(!(n*e.fromEnd(i)<r))return!1;for(let i=0;i<=4;i+=1){let a=!0;for(let o=1;o<=i+t&&a;o+=1){let s=n*e.fromEnd(t+o);a=o<=i?s<=r:s<r}if(a)return!0}return!1}var Ov=class e{period;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new V(2*e+4+1),n=new V(2*e+4+1)){this.period=e,this.highs=t,this.lows=n}next(e){this.highs.push(e.high),this.lows.push(e.low);let{period:t}=this;return this.out[0]=Dv(this.lows,t,-1)?this.lows.fromEnd(t):NaN,this.out[1]=Dv(this.highs,t,1)?this.highs.fromEnd(t):NaN,this.out}clone(){return new e(this.period,this.highs.clone(),this.lows.clone())}};let kv={type:`FRACTALS`,name:`Fractals`,pane:`main`,precision:`price`,params:{period:{default:2,min:2,max:50,integer:!0,label:`Periods`}},outputs:({period:e})=>[{key:`downFractal`,label:`Down fractal`,plot:{kind:`marker`,shape:`triangle-up`,size:4},themeColor:`down`,offset:-e},{key:`upFractal`,label:`Up fractal`,plot:{kind:`marker`,shape:`triangle-down`,size:4},themeColor:`up`,offset:-e}],create:({period:e})=>new Ov(e)};var Av=class e{share;mean;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t){this.share=e,this.mean=t}next(e,t){let n=this.mean.next(t,e);return this.out[0]=n,this.out[1]=n*(1+this.share),this.out[2]=n*(1-this.share),this.out}clone(){return new e(this.share,this.mean.clone())}};let jv={type:`ENVELOPE`,name:`Env`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),percent:{default:10,min:0,max:100,label:`Percent`},exponential:Ym(!1,`Exponential`,!1)},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:()=>[{from:`upper`,to:`lower`}],create:({period:e,percent:t,exponential:n})=>new Av(t/100,$m(n===1?`ema`:`sma`,e))};function Mv(){return new Hm(4,2)}var Nv=class e{typical;previous;extremes;high;low;lines;out=/* @__PURE__ */ new Float64Array(6);constructor(e,t,n,r,i,a){this.typical=e,this.previous=t,this.extremes=n,this.high=r,this.low=i,this.lines=a}static of(t){return new e(new Bm(t),new K,new G(t),Mv(),Mv(),Array.from({length:6},Mv))}next(e){let t=this.previous.next(this.typical.next((e.high+e.low+e.close)/3));this.extremes.push(e.high,e.low);let n=this.high.next(this.extremes.highest()),r=this.low.next(this.extremes.lowest()),i=[2*n-r,t+n-r,t*2-r,t*2-n,t-n+r,2*r-n];return this.lines.forEach((e,t)=>{this.out[t]=e.next(i[t]??NaN)}),this.out}clone(){return new e(this.typical.clone(),this.previous.clone(),this.extremes.clone(),this.high.clone(),this.low.clone(),this.lines.map(e=>e.clone()))}};let Pv={type:`MIKE`,name:`MIKE`,pane:`main`,precision:`price`,params:{period:X(10)},outputs:()=>[`STOR`,`MIDR`,`WEKR`,`WEKS`,`MIDS`,`STOS`].map(J),create:({period:e})=>Nv.of(e)};var Fv=class e{weights;averages;constructor(e,t){this.weights=e,this.averages=t}static of(t,n){return new e(n,n.map(()=>U.ema(t)))}next(e){let t=e,n=0;return this.averages.forEach((e,r)=>{t=e.next(t),n+=(this.weights[r]??0)*t}),n}clone(){return new e(this.weights,this.averages.map(e=>e.clone()))}};let Iv={type:`DEMA`,name:`DEMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`)},outputs:()=>[J(`DEMA`)],create:({period:e})=>new q([Fv.of(e,[2,-1])],(e,t)=>t)},Lv={type:`TEMA`,name:`TEMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`)},outputs:()=>[J(`TEMA`)],create:({period:e})=>new q([Fv.of(e,[3,-3,1])],(e,t)=>t)};var Rv=class e{offset;window;spread;constructor(e,t){this.offset=e,this.window=t;let n=t.capacity;this.spread=n*(n*n-1)/12}next(e){if(this.window.push(e),!this.window.full)return NaN;let t=this.window.capacity,n=(t-1)/2,r=this.window.sum()/t,i=0;for(let e=0;e<t;e+=1)i+=(e-n)*(this.window.at(e)-r);return r+i/this.spread*(t-1-this.offset-n)}clone(){return new e(this.offset,this.window.clone())}};let zv={type:`LSMA`,name:`LSMA`,pane:`main`,precision:`price`,params:{period:{default:25,min:2,max:2e3,integer:!0,label:`Length`},offset:{default:0,min:-2e3,max:2e3,integer:!0,label:`Offset`}},outputs:()=>[J(`LSMA`)],create:({period:e,offset:t})=>new q([new Rv(t,new V(e))],(e,t)=>t)};var Bv=class e{period;seed;value;constructor(e,t,n=NaN){this.period=e,this.seed=t,this.value=n}next(e){return this.value=Number.isNaN(this.value)?this.seed.next(e):this.value+(e-this.value)/(this.period*(e/this.value)**4),this.value}clone(){return new e(this.period,this.seed.clone(),this.value)}};let Vv={type:`MCGINLEY`,name:`McGinley Dynamic`,pane:`main`,precision:`price`,params:{period:X(14,`Length`)},outputs:()=>[J(`McGinley`)],create:({period:e})=>new q([new Bv(e,U.ema(e))],(e,t)=>t)},Hv=[`sma`,`ema`,`rma`,`wma`,`vwma`],Uv=[20,50,100,200];function Wv(e){return[[e.maType1,e.period1],[e.maType2,e.period2],[e.maType3,e.period3],[e.maType4,e.period4]]}function Gv(){let e=e=>Z([`SMA`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],0,`Type #${String(e)}`),t=e=>X(Uv[e-1]??0,`Length #${String(e)}`);return{maType1:e(1),period1:t(1),maType2:e(2),period2:t(2),maType3:e(3),period3:t(3),maType4:e(4),period4:t(4)}}let Kv={type:`RIBBON`,name:`MA Ribbon`,pane:`main`,precision:`price`,params:Gv(),outputs:()=>[1,2,3,4].map(e=>Y(`ma${String(e)}`,`MA №${String(e)}`)),create:e=>new q(Wv(e).map(([e,t])=>$m(Q(Hv,e,`ribbon average`),t)),(e,t)=>t)};var qv=class e{multiplier;range;closes;out=/* @__PURE__ */ new Float64Array(2);state={max:NaN,min:NaN,up:!0,stop:NaN};constructor(e,t,n=new K){this.multiplier=e,this.range=t,this.closes=n}next(e,t){let n=this.state,r=this.closes.next(e.close),i=this.range.next(e),a=Number.isNaN(i)?yh(e,r):i*this.multiplier,o=Number.isNaN(n.max)?t:Math.max(n.max,t),s=Number.isNaN(n.min)?t:Math.min(n.min,t),c=n.up?Math.max(n.stop,o-a):Math.min(n.stop,s+a);c=Number.isNaN(c)?t:c;let l=t-c>=0;return l!==n.up&&(o=t,s=t,c=l?o-a:s+a),this.out[0]=l?c:NaN,this.out[1]=l?NaN:c,this.state={max:o,min:s,up:l,stop:c},this.out}clone(){let t=new e(this.multiplier,this.range.clone(),this.closes.clone());return t.state=this.state,t}};function Jv(e,t,n){return{key:e,label:t,plot:{kind:`marker`,shape:`circle`,size:2},themeColor:n}}let Yv={type:`VSTOP`,name:`VStop`,pane:`main`,precision:`price`,params:{period:{default:20,min:2,max:2e3,integer:!0,label:`Length`},multiplier:{default:2,min:.25,max:100,label:`Multiplier`}},outputs:()=>[Jv(`upTrend`,`Up Trend`,`up`),Jv(`downTrend`,`Down Trend`,`down`)],create:({period:e,multiplier:t})=>new qv(t,xh.of(e))};var Xv=class e{multiplier;extremes;range;stops;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.multiplier=e,this.extremes=t,this.range=n,this.stops=r}next(e){let t=this.multiplier*this.range.next(e);return this.extremes.push(e.high,e.low),this.stops.push(this.extremes.highest()-t,this.extremes.lowest()+t),this.out[0]=this.stops.lowest(),this.out[1]=this.stops.highest(),this.out}clone(){return new e(this.multiplier,this.extremes.clone(),this.range.clone(),this.stops.clone())}};let Zv={type:`CKSTOP`,name:`Chande Kroll Stop`,pane:`main`,precision:`price`,params:{period:X(10,`ATR Length`),multiplier:{default:1,min:0,max:100,label:`ATR Coefficient`},stopPeriod:X(9,`Stop Length`)},outputs:()=>[{...Y(`stopLong`,`Stop Long`),themeColor:`up`},{...Y(`stopShort`,`Stop Short`),themeColor:`down`}],create:({period:e,multiplier:t,stopPeriod:n})=>new Xv(t,new G(e),xh.of(e),new G(n))};function Qv(e){return{default:10,min:1,max:500,integer:!0,label:e}}function $v(e,t,n){if(!e.full)return NaN;let r=e.fromEnd(t);for(let i=0;i<e.length;i+=1){let a=n*e.fromEnd(i);if(i<t?a>=n*r:i>t&&a>n*r)return NaN}return r}var ey=class e{highRight;lowRight;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.highRight=e,this.lowRight=t,this.highs=n,this.lows=r}next(e){return this.highs.push(e.high),this.lows.push(e.low),this.out[0]=$v(this.highs,this.highRight,1),this.out[1]=$v(this.lows,this.lowRight,-1),this.out}clone(){return new e(this.highRight,this.lowRight,this.highs.clone(),this.lows.clone())}};let ty={type:`PIVOTHL`,name:`Pivots HL`,pane:`main`,precision:`price`,params:{highLeft:Qv(`Pivot High Left`),highRight:Qv(`Pivot High Right`),lowLeft:Qv(`Pivot Low Left`),lowRight:Qv(`Pivot Low Right`)},outputs:({highRight:e,lowRight:t})=>[{key:`pivotHigh`,label:`Pivot High`,plot:{kind:`marker`,shape:`triangle-down`,size:4,value:!0},themeColor:`up`,offset:-e},{key:`pivotLow`,label:`Pivot Low`,plot:{kind:`marker`,shape:`triangle-up`,size:4,value:!0},themeColor:`down`,offset:-t}],create:({highLeft:e,highRight:t,lowLeft:n,lowRight:r})=>new ey(t,r,new V(e+t+1),new V(n+r+1))};function ny(e,t,n){if(!e.full)return NaN;let r=e.fromEnd(t);for(let i=0;i<e.length;i+=1){let a=n*e.fromEnd(i);if(i<t?a>n*r:i>t&&a>=n*r)return NaN}return r}function ry(e){return Math.max(2,Math.floor(e/2))}var iy=class e{deviation;half;highs;lows;out=/* @__PURE__ */ new Float64Array(3);state={high:!1,price:NaN};constructor(e,t,n,r){this.deviation=e,this.half=t,this.highs=n,this.lows=r}next(e){this.highs.push(e.high),this.lows.push(e.low);let t=ny(this.highs,this.half,1),n=ny(this.lows,this.half,-1);this.out[1]=this.takes(!0,t)?t:NaN,this.out[2]=this.takes(!1,n)?n:NaN;let{high:r,price:i}=this.state;return this.out[0]=Number.isNaN(i)?NaN:r?e.low:e.high,this.out}takes(e,t){if(Number.isNaN(t))return!1;let n=this.state,r=100*(t-n.price)/Math.abs(n.price),i=Number.isNaN(n.price)?!0:n.high===e?(e?t-n.price:n.price-t)>0:(e?r:-r)>=this.deviation;return i&&(this.state={high:e,price:t}),i}clone(){let t=new e(this.deviation,this.half,this.highs.clone(),this.lows.clone());return t.state=this.state,t}};let ay={type:`ZIGZAG`,name:`Zig Zag`,pane:`main`,precision:`price`,params:{deviation:{default:5,min:.01,max:100,label:`Price deviation for reversals (%)`},depth:{default:10,min:2,max:1e3,integer:!0,label:`Pivot legs`},extend:Ym(!0,`Extend to last bar`,!1),showPrice:Ym(!0,`Display reversal price`,!1),showVolume:Ym(!0,`Display cumulative volume`,!1),showChange:Ym(!0,`Display reversal price change`,!1),changeMode:Z([`Absolute`,`Percent`],0,`Price change`,!1)},outputs:({depth:e,extend:t,showPrice:n,showVolume:r,showChange:i,changeMode:a})=>{let o=-ry(e);return[{key:`zigZag`,label:`Zig Zag`,plot:{kind:`zigzag`,high:`high`,low:`low`,extend:t===1,labels:{price:n===1,change:i===1?a===1?`percent`:`absolute`:null,volume:r===1}},legend:!1},{key:`high`,label:`Pivot High`,plot:{kind:`hidden`},offset:o,legend:!1},{key:`low`,label:`Pivot Low`,plot:{kind:`hidden`},offset:o,legend:!1}]},create:({deviation:e,depth:t})=>{let n=ry(t);return new iy(e,n,new V(2*n+1),new V(2*n+1))}};var oy=class e{highs;lows;ranges;upward;downward;range;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r,i,a){this.highs=e,this.lows=t,this.ranges=n,this.upward=r,this.downward=i,this.range=a}static of(t){return new e(new K,new K,new bh,new W(t),new W(t),new W(t))}next(e){let t=this.upward.next(Math.abs(e.high-this.lows.next(e.low))),n=this.downward.next(Math.abs(e.low-this.highs.next(e.high))),r=this.range.next(this.ranges.next(e));return this.out[0]=$(t,r),this.out[1]=$(n,r),this.out}clone(){return new e(this.highs.clone(),this.lows.clone(),this.ranges.clone(),this.upward.clone(),this.downward.clone(),this.range.clone())}};let sy=[ah,oh,sh,jh,A_,q_,Zh,$h,tg,rg,ag,sg,lg,Y_,Z_,ev,nv,wh,Th,L_,lv,M_,P_,Fh,Lh,ch,uh,fh,hh,gh,vh,z_,V_,W_,K_,dg,pg,hg,_g,bg,Sg,wg,iv,Dh,Ev,kv,o_,c_,l_,b_,fv,gv,m_,mv,vv,bv,Sv,wv,Bh,Hh,Kh,Jh,Eg,Og,Ag,Ng,Ig,Rg,Vg,Ug,Kg,qg,Zg,C_,D_,Iv,Lv,zv,Vv,Kv,jv,Yv,Zv,{type:`VORTEX`,name:`VI`,pane:`new`,precision:4,params:{period:{default:14,min:2,max:2e3,integer:!0,label:`Length`}},outputs:()=>[Y(`viPlus`,`VI +`),Y(`viMinus`,`VI -`)],create:({period:e})=>oy.of(e)},ty,Pv,ay];function cy(e,t){return{start:(n,r)=>{e.run(()=>{t.start(n,r)})},stop:()=>{e.run(()=>{t.stop()})},play:()=>{e.run(()=>{t.play()})},pause:()=>{e.run(()=>{t.pause()})},step:n=>e.run(()=>t.step(n)),seek:n=>{e.run(()=>{t.seek(n)})},configure:n=>{e.run(()=>{t.configure(n)})},state:()=>t.state()}}let ly={speed:1,step:`bar`},uy=g({speed:!0,step:!0});function dy(e,t){_(`replay settings`,t,uy);let n={...e,...t};return d(`replay.speed`,n.speed,{min:0,exclusiveMin:!0,max:1e3}),m(`replay.step`,n.step,[`bar`,`source`]),n}var fy=class{host;cursor=null;settings=ly;timer=0;constructor(e){this.host=e}get active(){return this.cursor!==null}state(){return this.cursor===null?null:{...this.settings,time:this.cursor,playing:this.timer!==0,ended:this.host.market.feed.nextCutoff(this.cursor,!1)===null}}start(e,t={}){let r=a(e,`replay start`),o=dy(this.settings,t),s=this.host.market.firstSourceTime();s===null&&n(`Replay needs data: set bars before starting it.`),r<s&&n(`replay start ${i(e)} is before the first bar; start at or after the first bar.`),this.pause(),this.settings=o,this.cursor=r,this.host.reveal(r,!0)}stop(){this.cursor!==null&&(this.pause(),this.cursor=null,this.host.reveal(1/0,!0))}play(){this.require(`play()`),this.timer===0&&this.schedule()}pause(){this.timer!==0&&(this.host.view.clearTimeout(this.timer),this.timer=0)}step(e=1){let t=this.require(`step()`);d(`replay step count`,e,{min:1,integer:!0});let n=t,r=0;for(;r<e;r+=1){let e=this.host.market.feed.nextCutoff(n,this.settings.step===`bar`);if(e===null)break;n=e}return r>0&&(this.cursor=n,this.host.reveal(n,!1)),r}seek(e){this.require(`seek()`);let t=a(e,`replay time`),r=this.host.market.firstSourceTime();r!==null&&t<r&&n(`replay time ${i(e)} is before the first bar.`),this.cursor=t,this.host.reveal(t,!0)}configure(e){this.settings=dy(this.settings,e),this.timer!==0&&(this.pause(),this.schedule())}reset(){this.pause(),this.cursor=null}require(e){return this.cursor??n(`replay.${e} needs a running replay: call replay.start() first.`)}schedule(){this.timer=this.host.view.setTimeout(()=>{this.timer=0,this.host.played(()=>this.tick())},1e3/this.settings.speed)}tick(){let e=this.cursor!==null&&this.step()>0,t=this.state();return t?!e||t.ended?{state:t,reason:`end`}:(this.schedule(),{state:{...t,playing:!0},reason:`step`}):n(`Replay stopped during a step.`)}};function py(){return Ua({name:`replay`,install:e=>{let t=e.events(),n=new fy({view:e.view,market:e.market,reveal:(t,n)=>{e.reveal(t,n)},played:n=>{e.run(()=>{t.emit(`replay`,n())})}});return e.hooks.dataCleared.push(()=>{n.reset()}),e.hooks.destroyed.push(()=>{n.reset()}),{replay:cy(e,n)}}})}let my=[`above`,`below`,`price`],hy=g({id:!0,time:!0,position:!0,price:!0,shape:!0,color:!0,text:!0,size:!0,outline:!0,link:!0});function gy(e,t=`marker`){_(t,e,hy);let r=m(`${t}.position`,e.position,my);return r===`price`&&e.price===void 0&&n(`${t}.price is required with position "price".`),e.text!==void 0&&typeof e.text!=`string`&&n(`${t}.text must be a string.`),{time:a(e.time,`${t}.time`),position:r,price:e.price===void 0?null:d(`${t}.price`,e.price),shape:m(`${t}.shape`,e.shape,or),color:e.color===void 0?null:x(`${t}.color`,e.color),text:e.text??``,size:e.size===void 0?8:d(`${t}.size`,e.size,{min:2,max:40}),outline:e.outline===void 0?null:x(`${t}.outline`,e.outline),link:e.link===void 0?null:p(`${t}.link`,e.link)}}function _y(e){return{time:e.time,position:e.position,shape:e.shape,text:e.text,size:e.size,...e.price===null?{}:{price:e.price},...e.color===null?{}:{color:e.color},...e.outline===null?{}:{outline:e.outline},...e.link===null?{}:{link:e.link}}}function vy(e,t){let n=sr(t.shape),{theme:r}=e.options;return t.color??(n>0?r.buy:n<0?r.sell:r.text)}function yy(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;(e[i]?.time??NaN)<t?n=i+1:r=i}return n}var by=class{kind=`marker`;markers=/* @__PURE__ */ new Map;ids=new de(e=>this.markers.has(e));sorted=null;has(e){return this.markers.has(e)}list(){return[...this.markers.values()]}get(e){return this.markers.get(e)??null}set(e){this.markers=Xa(`markers`,e,this.ids,`marker`,gy),this.sorted=null}add(e){let t=gy(e),r=e.id===void 0?this.ids.next(`marker`):p(`marker.id`,e.id);return this.markers.has(r)&&n(`A marker with id "${r}" already exists.`),this.markers.set(r,{id:r,...t}),this.ids.note(r),this.sorted=null,r}update(e,t){let r=this.markers.get(e)??n(`Unknown marker "${e}".`);this.markers.set(e,{id:e,...gy({..._y(r),...t})}),this.sorted=null}remove(e){this.markers.delete(e)||n(`Unknown marker "${e}".`),this.sorted=null}between(e,t,n){let{bars:r}=e,i=r.length-1,a=e.resolution===`untimed`?null:r.interval(),o=n<i?r.time(n+1):a===null?1/0:r.time(i)+a;return this.sorted??=[...this.markers.values()].sort((e,t)=>e.time-t.time),this.sorted.slice(yy(this.sorted,r.time(t)),yy(this.sorted,o))}place(e){let t=j(e.frame,b),n=e.frame.visible;if(!t||!n||this.markers.size===0)return[];let{bars:r,timeScale:i}=e,a=Math.max(0,n.from-1),o=Math.min(r.length-1,n.to+1),s=/* @__PURE__ */ new Map,c=[];for(let n of this.between(e,a,o)){if(n.time>e.cutoff)break;let a=r.indexAt(n.time),o=i.indexToX(a),l=`${a}:${n.position}`,u=s.get(l)??0;s.set(l,u+n.size*2+4);let d;d=n.position===`above`?t.scale.valueToY(r.high(a))-4-n.size-u:n.position===`below`?t.scale.valueToY(r.low(a))+4+n.size+u:t.scale.valueToY(n.price??NaN),c.push({marker:n,x:o,y:d,color:vy(e,n)})}return c}links(e,t){let n=j(e.frame,b),{bars:r,timeScale:i}=e;if(!n||r.length===0)return[];let a=new Map(t.map(e=>[e.marker.id,e])),o=t=>{let o=a.get(t.id);if(o)return{x:o.x,y:o.y};let s=r.indexAt(t.time);if(s<0||t.time>e.cutoff)return null;let c=t.position===`above`?n.scale.valueToY(r.high(s))-4-t.size:t.position===`below`?n.scale.valueToY(r.low(s))+4+t.size:n.scale.valueToY(t.price??NaN);return{x:i.indexToX(s),y:c}},s=[];for(let t of this.markers.values()){let n=t.link===null?void 0:this.markers.get(t.link),r=n&&o(n),i=n&&o(t);n&&r&&i&&s.push({from:r,to:i,color:a.get(n.id)?.color??vy(e,n),outline:n.outline})}return s}hitTest(e,t){let n=j(e.frame,b);if(!n)return null;let r={x:t.x-n.plot.x,y:t.y-n.plot.y},i=null;for(let t of this.place(e)){let e=Math.hypot(r.x-t.x,r.y-t.y);e<=t.marker.size+3&&(i===null||e<i.distance)&&(i={target:{kind:`marker`,id:t.marker.id,part:`body`,cursor:`pointer`,draggable:!1},priority:$a.body,distance:e})}return i}beginDrag(){return null}paint(e){let t=j(e.frame,b);if(!t)return;let{ctx:n,options:r}=e;n.save(),n.beginPath(),n.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),n.clip(),n.translate(t.plot.x,t.plot.y),n.font=E(r.font.size-1,r.font.family),n.textAlign=`center`;let i=this.place(e);for(let{from:t,to:r,color:a,outline:o}of this.links(e,i))n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(r.x,r.y),o!==null&&(C(n,o,3),n.setLineDash(mn(`dashed`,1)),n.stroke()),C(n,a,1,`dashed`),n.stroke();for(let{marker:t,x:r,y:a,color:o}of i){let i=e.selection?.kind===`marker`&&e.selection.id===t.id||e.hovered?.kind===`marker`&&e.hovered.id===t.id,s=t.size*(i?1.25:1);if(n.fillStyle=o,n.beginPath(),cr(n,t.shape,r,a,s),n.fill(),t.outline!==null&&(C(n,t.outline,1),n.stroke()),t.text){let e=t.position===`below`;n.textBaseline=e?`top`:`bottom`,n.fillText(t.text,r,e?a+s+2:a-s-2)}}n.restore()}};let xy=g({id:!0,price:!0,side:!0,label:!0,quantity:!0,draggable:!0,pull:!0,visible:!0,color:!0,lineStyle:!0,buttons:!0});function Sy(e,t=`order`){return _(t,e,xy),e.label!==void 0&&p(`${t}.label`,e.label),e.quantity!==void 0&&typeof e.quantity!=`string`&&d(`${t}.quantity`,e.quantity),{price:d(`${t}.price`,e.price),side:m(`${t}.side`,e.side,[`buy`,`sell`]),label:e.label??null,quantity:e.quantity??null,draggable:e.draggable===void 0||f(`${t}.draggable`,e.draggable),pull:e.pull!==void 0&&f(`${t}.pull`,e.pull),visible:e.visible===void 0||f(`${t}.visible`,e.visible),color:e.color===void 0?null:x(`${t}.color`,e.color),lineStyle:e.lineStyle===void 0?`dashed`:m(`${t}.lineStyle`,e.lineStyle,cn),buttons:io(e.buttons,`${t}.buttons`)}}function Cy(e){return{price:e.price,side:e.side,draggable:e.draggable,pull:e.pull,visible:e.visible,lineStyle:e.lineStyle,buttons:e.buttons.map(e=>({...e})),...e.label===null?{}:{label:e.label},...e.quantity===null?{}:{quantity:e.quantity},...e.color===null?{}:{color:e.color}}}var wy=class{host;kind=`order`;orders=/* @__PURE__ */ new Map;ids=new de(e=>this.orders.has(e));icons=new Ei;constructor(e){this.host=e}has(e){return this.orders.has(e)}list(){return[...this.orders.values()]}get(e){return this.orders.get(e)??null}require(e){return this.orders.get(e)??n(`Unknown order "${e}".`)}set(e){this.orders=Xa(`orders`,e,this.ids,`order`,Sy)}add(e){let t=Sy(e),r=e.id===void 0?this.ids.next(`order`):p(`order.id`,e.id);return this.orders.has(r)&&n(`An order with id "${r}" already exists.`),this.orders.set(r,{id:r,...t}),this.ids.note(r),r}update(e,t){let n=this.require(e);this.orders.set(e,{id:e,...Sy({...Cy(n),...t})})}remove(e){this.require(e),this.orders.delete(e)}layouts(e,t){let{theme:n,font:r}=e.options,i=[];for(let r of this.orders.values()){if(!r.visible)continue;let a=r.label??(r.side===`buy`?`BUY`:`SELL`),o=e.selection?.kind===`order`&&e.selection.id===r.id||e.hovered?.kind===`order`&&e.hovered.id===r.id;i.push({id:r.id,y:t.scale.valueToY(r.price),color:r.color??(r.side===`buy`?n.buy:n.sell),text:r.quantity===null?a:`${a} ${String(r.quantity)}`,axisText:this.host.formatValue(t,r.price),buttons:r.buttons,lineStyle:r.lineStyle,emphasized:o})}return oo(i,t.plot.width,t.plot.height,r.size,(t,n)=>e.measureText(t,E(n,r.family)))}hitTest(e,t){let n=j(e.frame,b);if(!n||t.y<n.plot.y||t.y>=n.plot.y+n.plot.height)return null;let r=co(this.layouts(e,n),{x:t.x,y:t.y-n.plot.y},e.options.interaction.hitTolerance),i=r?this.orders.get(r.id):void 0;if(!r||!i)return null;let a=r.part.startsWith(`button:`),o=i.draggable&&!a;return{target:{kind:`order`,id:i.id,part:r.part,cursor:o?`ns-resize`:`pointer`,draggable:o},priority:r.priority,distance:r.distance}}beginDrag(e,t){let n=this.orders.get(t.id),r=j(e.frame,b);if(!n?.draggable||!r)return null;let i=n.price,a=i;this.host.dragged({id:n.id,phase:`start`,price:a,initialPrice:i});let o=e=>{let t=this.orders.get(n.id);t&&!t.pull&&(this.orders.set(n.id,{...t,price:e}),this.host.repaint())};return{move:e=>{let t=j(this.host.context().frame,b);if(!t||!this.orders.has(n.id))return;let r=e.y-t.plot.y,s=to(t.scale,t.format,r);Number.isFinite(s)&&s!==a&&(a=s,o(a),this.host.dragged({id:n.id,phase:`move`,price:a,initialPrice:i}))},end:()=>{this.host.dragged({id:n.id,phase:`end`,price:a,initialPrice:i})},cancel:()=>{o(i),this.host.dragged({id:n.id,phase:`cancel`,price:i,initialPrice:i})}}}paint(e){let t=j(e.frame,b);if(!t||this.orders.size===0)return;let{ctx:n}=e;n.save(),n.beginPath(),n.rect(0,t.plot.y,e.frame.layout.width,t.plot.height),n.clip(),lo(n,this.layouts(e,t),t.plot,t.axis,{fontSize:e.options.font.size,fontFamily:e.options.font.family,pixelRatio:e.pixelRatio,textColor:`#ffffff`,showAxis:e.options.priceScale.visible},this.icons),n.restore()}};function Ty(){return Ua({name:`orders`,install:e=>{let t=e.events(),n=new wy(Qa(e,e=>{t.emit(`orderDrag`,e)}));return e.objects.add(n,40),{orders:Za(e,n)}}})}function Ey(){return Ua({name:`markers`,install:e=>{let t=new by;return e.objects.add(t,10),{markers:Za(e,t)}}})}function Dy(e,t){return{up:e.upColor??t.up,down:e.downColor??t.down,poc:e.pocColor??t.palette[0]}}function Oy(e,t,n,r,i){let a=t.rows.reduce((e,t)=>Math.max(e,t.up+t.down),0);t.rows.forEach((o,s)=>{let c=n(o.high),l=n(o.low),u=Math.abs(l-c),d=+(u>3),f=Math.min(c,l)+d/2,p=s>=t.valueArea.low&&s<=t.valueArea.high?.5:.22,m=o.up/a*r.length,h=o.down/a*r.length,g=r.x+m;e.fillStyle=S(i.up,p),e.fillRect(Math.min(r.x,g),f,Math.abs(m),u-d),e.fillStyle=S(i.down,p),e.fillRect(Math.min(g,g+h),f,Math.abs(h),u-d)});let o=t.rows[t.poc];if(o){let t=Math.round(n((o.low+o.high)/2))+.5;e.beginPath(),e.moveTo(r.x,t),e.lineTo(r.pocTo,t),e.strokeStyle=i.poc,e.lineWidth=1,e.stroke()}}let ky=.7;g({rows:!0,valueArea:!0});function Ay(e,t){return d(e,t,{min:1,max:1e3,integer:!0})}function jy(e,t){return d(e,t,{min:0,exclusiveMin:!0,max:1})}function My(e,t){return{rows:e.rows===void 0?24:Ay(`${t}.rows`,e.rows),valueArea:e.valueArea===void 0?ky:jy(`${t}.valueArea`,e.valueArea)}}function Ny(e){e.length===0&&n(`pointOfControl() needs the volume of one row at least.`);let t=(e.length-1)/2,r=0;for(let n=1;n<e.length;n+=1){let i=e[n]??0,a=e[r]??0;(i>a||i===a&&Math.abs(n-t)<=Math.abs(r-t))&&(r=n)}return r}function Py(e,t,n=ky){d(`poc`,t,{min:0,max:e.length-1,integer:!0}),jy(`share`,n);let r=0;for(let t=0;t<e.length;t+=1)r+=e[t]??0;let i=r*n,a=e[t]??0,o=t,s=t;for(;o>0||s<e.length-1;){let n=s<e.length-1?e[s+1]??0:-1,c=o>0?e[o-1]??0:-1,l=n>c||n===c&&s+1-t<=t-(o-1),u=l?n:c;if(a+u>i+r*1e-9)break;a+=u,l?s+=1:--o}return{low:o,high:s}}function Fy(e,t,n){let r=t>e?t-e:Math.max(Math.abs(t)*.001,1e-9);return{bottom:t>e?e:e-r/2,step:r/n,count:n}}function Iy(e,t,n,r,i){let a=Math.max(0,t),o=Math.min(e.length,n),s=1/0,c=-1/0;for(let t=a;t<o;t+=1)s=Math.min(s,e.low(t)),c=Math.max(c,e.high(t));if(!(c>=s))return null;let{bottom:l,step:u}=Fy(s,c,r),d=new Float64Array(r),f=new Float64Array(r);for(let t=a;t<o;t+=1){let n=e.volume(t);if(!(n>0))continue;let i=e.close(t)>=e.open(t)?d:f,a=e.low(t),o=e.high(t),s=Math.min(r-1,Math.max(0,Math.floor((a-l)/u))),c=Math.min(r-1,Math.max(0,Math.floor((o-l)/u)));if(s===c||o===a)i[s]=(i[s]??0)+n;else for(let e=s;e<=c;e+=1){let t=l+e*u,r=Math.min(o,t+u)-Math.max(a,t);r>0&&(i[e]=(i[e]??0)+n*r/(o-a))}}let p=new Float64Array(r),m=0;for(let e=0;e<r;e+=1)p[e]=(d[e]??0)+(f[e]??0),m+=p[e]??0;if(!(m>0))return null;let h=Ny(p);return{rows:Array.from({length:r},(e,t)=>({low:l+t*u,high:l+(t+1)*u,up:d[t]??0,down:f[t]??0})),total:m,poc:h,valueArea:Py(p,h,i)}}function Ly(e,t,n,r){return{start:t.lowerBound(e.time(n)),end:r+1<e.length?t.lowerBound(e.time(r+1)):t.length}}function Ry(e,t){return Math.max(0,e.lowerBound(t+1)-1)}function zy(e,t,n){return e.range(t.time(n),`1D`)}function By(e,t,n){let r=n,i=zy(e,t,r);for(;!i&&r>0;)--r,i=zy(e,t,r);if(!i)return null;let{bucket:a}=i,o=t.lowerBound(i.start),s=t.lowerBound(i.end);for(let n=o-1;n>=0;--n){let r=zy(e,t,n);if(r?.bucket===a)o=t.lowerBound(r.start),n=o;else if(r)break}for(;s<t.length;){let n=zy(e,t,s);if(!n)s+=1;else if(n.bucket===a)s=t.lowerBound(n.end);else break}return{start:o,end:s}}function Vy(e,t,n){let r=n;for(;r<t.length&&!zy(e,t,r);)r+=1;return r}var Hy=class{settings;revision=-1;length=0;calendar=null;range=``;visible=null;days=/* @__PURE__ */ new Map;constructor(e){this.settings=e}profile(e,t,n){return this.follow(e),(this.visible?.start!==t||this.visible.end!==n)&&(this.visible={start:t,end:n,profile:this.compute(e.source,t,n)}),this.visible.profile}sessions(e,t,n,r){let{source:i}=e;this.follow(e),t!==this.calendar&&(this.calendar=t,this.days.clear(),this.range=``);let a=`${n}:${r}`;if(a!==this.range){let e=/* @__PURE__ */ new Map;for(let a=n;a<r;){let n=By(t,i,a);if(!n){a=Vy(t,i,a);continue}let r=this.days.get(n.start);e.set(n.start,r?.end===n.end?r:{...n,profile:this.compute(i,n.start,n.end)}),a=n.end}this.days=e,this.range=a}return this.days.values()}compute(e,t,n){return Iy(e,t,n,this.settings.rows,this.settings.valueArea)}follow({source:e,changes:t}){let n=t.changesSince(this.revision),r=e.length===this.length?1/0:Math.min(e.length,this.length);if(n&&(r=n.kind===`reset`?0:Math.min(r,n.from)),this.revision=t.revision,this.length=e.length,r!==1/0){this.visible&&this.visible.end>r&&(this.visible=null);for(let[e,t]of this.days)t.end>=r&&this.days.delete(e);this.range=``}}};function Uy(e,t,n,r){let{bars:i,source:a,visible:o}=t;if(!o)return;let{start:s,end:c}=Ly(i,a,o.from,o.to),l=Dy(n,t.theme);if(n.mode===`visible`){let i=r.profile(t,s,c);if(!i)return;let a=n.placement===`right`,o=(n.width??.25)*t.width;Oy(e,i,t.valueToY,{x:a?t.width:0,length:a?-o:o,pocTo:a?0:t.width},l);return}let u=t.barSpacing/2;for(let o of r.sessions(t,t.calendar,s,c)){if(!o.profile)continue;let r=t.indexToX(Ry(i,a.time(o.start)))-u,s=t.indexToX(Ry(i,a.time(o.end-1)))+u;Oy(e,o.profile,t.valueToY,{x:r,length:(n.width??.7)*(s-r),pocTo:s},l)}}let Wy=[`visible`,`session`],Gy=[`left`,`right`],Ky=g({id:!0,mode:!0,rows:!0,valueArea:!0,width:!0,placement:!0,upColor:!0,downColor:!0,pocColor:!0,visible:!0}),qy=Ky.filter(e=>e!==`id`);function Jy(e,t){return t===void 0?null:x(e,t)}function Yy(e,t){_(t,e,Ky);let{rows:n,valueArea:r}=My(e,t);return{mode:m(`${t}.mode`,e.mode,Wy),rows:n,valueArea:r,width:e.width===void 0?null:jy(`${t}.width`,e.width),placement:e.placement===void 0?`right`:m(`${t}.placement`,e.placement,Gy),upColor:Jy(`${t}.upColor`,e.upColor),downColor:Jy(`${t}.downColor`,e.downColor),pocColor:Jy(`${t}.pocColor`,e.pocColor),visible:e.visible===void 0||f(`${t}.visible`,e.visible)}}function Xy(e){let{width:t,upColor:n,downColor:r,pocColor:i}=e;return{id:e.id,mode:e.mode,rows:e.rows,valueArea:e.valueArea,placement:e.placement,visible:e.visible,...t===null?{}:{width:t},...n===null?{}:{upColor:n},...r===null?{}:{downColor:r},...i===null?{}:{pocColor:i}}}function Zy(e){return{profile:e,cache:new Hy(e)}}var Qy=class e{entries=/* @__PURE__ */ new Map;ids;constructor(e){this.ids=new de(e=>this.entries.has(e),e)}staging(t){let n=new e(this.ids);return n.ids.reserve(t),n}list(){return[...this.entries.values()].map(e=>({...e.profile}))}get(e){let t=this.entries.get(e);return t?{...t.profile}:null}inputs(){return[...this.entries.values()].map(e=>Xy(e.profile))}add(e,t=`volumeProfile`){let r=Yy(e,t),i=e.id===void 0?this.ids.next(`volume-profile`):p(`${t}.id`,e.id);return this.entries.has(i)&&n(`A volume profile with id "${i}" already exists.`),this.entries.set(i,Zy({id:i,...r})),this.ids.note(i),i}update(e,t){let r=this.entries.get(e)??n(`Unknown volume profile "${e}".`);_(`volumeProfile patch`,t,qy);let i=Yy({...Xy(r.profile),...t},`volumeProfile`);this.entries.set(e,Zy({id:e,...i}))}remove(e){this.entries.delete(e)||n(`Unknown volume profile "${e}".`)}adopt(e){this.entries=e.entries,this.entries.forEach((e,t)=>{this.ids.note(t)})}paint(e,t){this.entries.forEach(({profile:n,cache:r})=>{n.visible&&Uy(e,t,n,r)})}};function $y(e,t,n){v(n,t);let r=e.staging(t);return t.forEach((e,t)=>{r.add(e,`${n}[${t}]`)}),r}function eb(e){return{key:`volumeProfiles`,save:()=>e.inputs(),prepare:t=>{let n=$y(e,t??[],`state.volumeProfiles`);return{apply:()=>{e.adopt(n)}}}}}function tb(e,t){let n=t=>e.run(()=>{let n=t();return e.invalidateLayers(`scene`),n});return{set:e=>{n(()=>{t.adopt($y(t,e,`volumeProfiles`))})},add:e=>n(()=>t.add(e)),update:(e,r)=>{n(()=>{t.update(e,r)})},remove:e=>{n(()=>{t.remove(e)})},clear:()=>{n(()=>{t.adopt(t.staging([]))})},get:e=>t.get(e),list:()=>t.list()}}function nb(){return Ua({name:`volumeProfiles`,install:e=>{let t=new Qy;return e.scenePainters.push((n,r,i,a)=>{if(a!==`below`||i.id!==`main`)return;let{timeScale:o}=e;n.save(),t.paint(n,{bars:e.market.displayed,source:e.market.revealed,changes:e.market.feed.source,visible:r.visible,calendar:e.market.tradingCalendar(),theme:e.options.theme,width:i.plot.width,barSpacing:o.barSpacing,indexToX:e=>o.indexToX(e),valueToY:e=>i.scale.valueToY(e)}),n.restore()}),e.stateParts.push(eb(t)),{volumeProfiles:tb(e,t)}}})}let rb=g({rows:!0,valueArea:!0,width:!0,upColor:!0,downColor:!0,pocColor:!0});function ib(e={}){let t=`fixedRangeVolumeProfile() options`;_(t,e,rb);let{rows:n,valueArea:r}=My(e,t),i=e.width===void 0?.6:jy(`${t}.width`,e.width);for(let n of[`upColor`,`downColor`,`pocColor`])e[n]!==void 0&&p(`${t}.${n}`,e[n]);let a=/* @__PURE__ */ new WeakMap,o=(e,t,i)=>{let o=a.get(e);return o?.revision!==e.revision&&(o={revision:e.revision,profiles:new Ti(64)},a.set(e,o)),o.profiles.getOrCreate(`${t}:${i}`,()=>Iy(e,t,i,n,r))},s=e=>{let[t,n]=e.anchors,[r,i]=e.points,{bars:a,source:s}=e,c=a.lowerBound(Math.max(t.time,n.time)+1),l=o(s,s.lowerBound(Math.min(t.time,n.time)),c<a.length?s.lowerBound(a.time(c)):s.length),u=l?.rows[0]?.low??Math.min(t.price,n.price),d=l?.rows.at(-1)?.high??Math.max(t.price,n.price),f=[e.valueToY(u),e.valueToY(d)];return{profile:l,left:Math.min(r.x,i.x),right:Math.max(r.x,i.x),top:Math.min(...f),bottom:Math.max(...f)}};return{type:`fixed-range-volume-profile`,points:2,mainPane:!0,fields:[`color`],paintBelow:({ctx:t,geometry:n})=>{let{left:r,right:a,top:o,bottom:c,profile:l}=s(n);t.fillStyle=S(n.style.color,.04),t.fillRect(r,o,a-r,c-o),l&&Oy(t,l,n.valueToY,{x:r,length:i*(a-r),pocTo:a},Dy(e,n.theme))},paint:({ctx:e,geometry:t,hovered:n,selected:r})=>{let{left:i,right:a,top:o,bottom:c}=s(t),{color:l}=t.style;e.strokeStyle=n||r?l:S(l,.5),e.lineWidth=1,e.strokeRect(Math.round(i)+.5,Math.round(o)+.5,a-i,c-o)},hitTest:(e,t,n)=>{let{left:r,right:i,top:a,bottom:o}=s(e);if(!(t.x>=r-n&&t.x<=i+n&&t.y>=a-n&&t.y<=o+n))return null;let c=Math.min(Math.abs(t.x-r),Math.abs(t.x-i),Math.abs(t.y-a),Math.abs(t.y-o));return c<=n?{part:`line`,distance:c}:{part:`body`,distance:0}},handles:e=>{let t=s(e),n=(t.top+t.bottom)/2;return e.points.map((e,t)=>({id:String(t),x:e.x,y:n,cursor:`ew-resize`}))},axisMarks:e=>({prices:[],times:e.map(e=>e.time)}),bounds:e=>{let t=s(e);return{x:t.left,y:t.top,width:t.right-t.left,height:t.bottom-t.top}}}}let ab=g({lines:!0,color:!0}),ob=g({text:!0,size:!0}),sb={key:`watermark`,defaults:()=>({lines:[],color:null}),validate:(e,t)=>{_(t,e,ab),v(`${t}.lines`,e.lines),e.lines.forEach((e,n)=>{let r=`${t}.lines[${n}]`;_(r,e,ob),p(`${r}.text`,e.text),e.size!==void 0&&d(`${r}.size`,e.size,{min:6,max:200})}),e.color!==null&&x(`${t}.color`,e.color)}};function cb(e){return e.watermark}function lb(){return Ua({name:`watermark`,options:sb,install:e=>(e.scenePainters.push((t,n,r,i)=>{let{lines:a,color:o}=cb(e.options);if(i!==`below`||r.id!==`main`||a.length===0)return;let{theme:s,font:c}=e.options,l=a.map(e=>(e.size??40)*1.25),u=(r.plot.height-l.reduce((e,t)=>e+t,0))/2;t.fillStyle=o??S(s.text,.1),t.textAlign=`center`,t.textBaseline=`middle`,a.forEach((e,n)=>{let i=l[n]??0;t.font=E(e.size??40,c.family,600),t.fillText(e.text,r.plot.width/2,u+i/2),u+=i})}),{})})}function ub(e={}){return _(`allModules() options`,e,[`indicators`]),[zm(sy,e.indicators),Pl([...Cp,ib()]),Os(ks),Lo(),Ty(),Ey(),py(),nb(),lb()]}return e.ChartError=t,e.LINE_STYLES=cn,e.PRICE_SOURCES=Yt,e.alerts=Lo,e.allChartTypes=ks,e.allDrawings=Cp,e.allIndicators=sy,e.allModules=ub,e.canBuildTimeframe=da,e.chartTypes=Os,e.checkColor=x,e.checkTimeframe=ua,e.createCalendar=_a,e.createChart=Ya,e.createModule=Wa,e.darkTheme=Kt,e.drawings=Pl,e.fixedRangeVolumeProfile=ib,e.formatInterval=A,e.indicators=zm,e.intervalDuration=sa,e.lightTheme=qt,e.markers=Ey,e.orders=Ty,e.parseBar=et,e.parseInterval=ia,e.replay=py,e.volumeProfiles=nb,e.watermark=lb,e.withAlpha=S,e})({});
|
|
1
|
+
var KumoChart=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class extends Error{name=`ChartError`;constructor(e){super(`[kumochart] ${e}`)}};function n(e){throw new t(e)}function r(e){let t=null;for(let n of e)try{n()}catch(e){t??={error:e}}if(t)throw t.error}function i(e){return typeof e==`string`?JSON.stringify(e):typeof e==`number`||typeof e==`boolean`||e===null?String(e):e===void 0?`undefined`:Array.isArray(e)?`an array`:typeof e==`object`?`an object`:typeof e}function a(e,t=`time`){let r;if(typeof e==`number`)r=e;else if(typeof e==`string`)r=Date.parse(e);else if(e instanceof Date)r=e.getTime();else return n(`${t} must be a number, string or Date, received ${i(e)}.`);return Number.isFinite(r)||n(`${t} ${i(e)} is not a valid point in time.`),r}function o(e){let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toISOString()}function s(e,t,n){let r=e.map(()=>!1),i=(e,t)=>!e.stretch&&!r[t];for(;;){let a=t-r.filter(Boolean).length*n,o=e.reduce((e,t,n)=>i(t,n)?e+t.height:e,0),s=o>a?a/o:1,c=e.flatMap((e,t)=>i(e,t)&&e.height*s<n?[t]:[]);if(c.length===0)return e.map((e,t)=>e.stretch?0:r[t]?n:e.height*s);c.forEach(e=>{r[e]=!0})}}function c(e,t,n){if(t.length===0)return[];let r=Math.min(n,e/t.length),i=t.filter(e=>e.stretch).length,a=s(t,e-i*r,r),o=a.reduce((e,t)=>e+t,0),c=Math.max(0,e-o);if(i===0){let e=a.length-1;return a[e]=(a[e]??0)+c,a}return t.map((e,t)=>e.stretch?c/i:a[t]??0)}function l(e){let t=Math.max(0,e.width),n=Math.max(0,e.height),r=Math.min(e.axisWidth,t),i=Math.min(e.leftAxisWidth,t-r),a=Math.max(0,t-r-i),o=Math.min(e.timeAxisHeight,n),s=Math.max(0,e.panes.length-1)*e.separatorHeight,l=c(Math.max(0,n-o-s),e.panes,e.minPaneHeight),u=[],d=[],f=0;return e.panes.forEach((t,n)=>{let o=l[n]??0;u.push({id:t.id,plot:{x:0,y:f,width:a,height:o},axis:{x:a,y:f,width:r,height:o},leftAxis:i>0?{x:-i,y:f,width:i,height:o}:null}),f+=o;let s=e.panes[n+1];s&&(d.push({above:t.id,below:s.id,y:f,height:e.separatorHeight}),f+=e.separatorHeight)}),{width:t,height:n,plotWidth:a,axisWidth:r,leftAxisWidth:i,panes:u,separators:d,timeAxis:o>0?{x:-i,y:f,width:t,height:o}:null}}function u(e){let t=e.leftAxisWidth,n=e=>({...e,x:e.x+t});return{...e,panes:e.panes.map(e=>({id:e.id,plot:n(e.plot),axis:n(e.axis),leftAxis:e.leftAxis?n(e.leftAxis):null})),separators:e.separators.map(e=>({...e})),timeAxis:e.timeAxis?n(e.timeAxis):null}}function d(e,t,r={}){return typeof t!=`number`||!Number.isFinite(t)?n(`${e} must be a finite number, received ${i(t)}.`):(r.integer&&!Number.isInteger(t)&&n(`${e} must be an integer, received ${t}.`),r.min!==void 0&&(r.exclusiveMin?t<=r.min:t<r.min)&&n(`${e} must be ${r.exclusiveMin?`greater than`:`at least`} ${r.min}, received ${t}.`),r.max!==void 0&&t>r.max&&n(`${e} must be at most ${r.max}, received ${t}.`),t)}function f(e,t){return typeof t==`boolean`?t:n(`${e} must be a boolean, received ${i(t)}.`)}function p(e,t){return typeof t!=`string`||t.length===0?n(`${e} must be a non-empty string, received ${i(t)}.`):t}function m(e,t,r){return typeof t!=`string`||!r.includes(t)?n(`${e} must be one of ${r.map(e=>`"${e}"`).join(`, `)}, received ${i(t)}.`):t}function h(e,t){(typeof t!=`object`||!t||Array.isArray(t))&&n(`${e} must be an object, received ${i(t)}.`)}function g(e){return Object.keys(e)}function _(e,t,r){h(e,t);let i=Object.keys(t).find(e=>!r.includes(e));i!==void 0&&n(`${e} has no field "${i}"; its fields are ${r.join(`, `)}.`)}function v(e,t){Array.isArray(t)||n(`${e} must be an array, received ${i(t)}.`)}function ee(e,t){typeof t!=`function`&&n(`${e} must be a function, received ${i(t)}.`)}function y(e,t){t!==null&&typeof t!=`function`&&n(`${e} must be a function or null, received ${i(t)}.`)}function te(e,t){let r=p(e,t);try{new Intl.DateTimeFormat(`en-US`,{timeZone:r})}catch{n(`${e} ${JSON.stringify(r)} is not a valid IANA time zone.`)}return r}let ne=g({top:!0,bottom:!0}),re=.9;function ie(e,t){return _(e,t,ne),d(`${e}.top`,t.top,{min:0,max:re}),d(`${e}.bottom`,t.bottom,{min:0,max:re}),t.top+t.bottom>re&&n(`${e}.top and ${e}.bottom must leave a tenth of the pane for the data.`),{top:t.top,bottom:t.bottom}}function ae(){return{min:1/0,max:-1/0,minPositive:1/0}}function b(e,t){Number.isFinite(t)&&(t<e.min&&(e.min=t),t>e.max&&(e.max=t),t>0&&t<e.minPositive&&(e.minPositive=t))}let oe={mode:`normal`};function se(e,t){let n=e.max-e.min;if(!Number.isFinite(n)||!(n>0))return!1;if(t===`log`)return e.min>-30&&e.max<30&&n>1e-6;let r=Math.max(1,Math.abs(e.min),Math.abs(e.max));return n>r*1e-9&&n<r*1e9}function ce(e,t,n){switch(e){case`normal`:return oe;case`log`:return Number.isFinite(n.minPositive)?{mode:e}:oe;case`percent`:return t!==null&&t!==0?{mode:e,base:t}:oe;case`indexed`:return t!==null&&t>0?{mode:e,base:t}:oe}}var le=class{height=0;settings;transform=oe;manual=null;range=null;leader=null;constructor(e){this.settings=e}get mode(){return this.transform.mode}get autoScale(){return this.manual===null}get lead(){return this.leader??this}get inverted(){return this.lead.settings.invert}get plotHeight(){return this.height}configure(e){e.mode!==this.settings.mode&&(this.manual=null),this.settings=e}setHeight(e){this.height=Math.max(0,e)}relativeMode(e){let{mode:t}=ce(this.settings.mode,e,ae());return t===`percent`||t===`indexed`?t:null}fit(e,t){let n=ce(this.settings.mode,t,e);if(this.leader=null,this.transform=n,this.manual?.mode===n.mode){this.range=this.manual.range;return}let r=this.toScale(n.mode===`log`?e.minPositive:e.min),i=this.toScale(e.max);if(r===null||i===null||i<r){this.range=null;return}let a=i===r,o=a?i===0?1:Math.max(Math.abs(i)*.01,1e-6):i-r,{top:s,bottom:c}=this.settings.margins,l=o/(1-s-c),u=a?o/2:0;this.range={min:r-u-c*l,max:i+u+s*l}}follow(e){this.leader=e,this.height=e.height,this.transform=e.transform,this.range=e.range}scaleRange(){return this.range}valueRange(){return this.range?{min:this.fromScale(this.range.min),max:this.fromScale(this.range.max)}:null}toScale(e){if(!Number.isFinite(e))return null;let t=this.transform;switch(t.mode){case`normal`:return e;case`log`:return e>0?Math.log10(e):null;case`percent`:return(e-t.base)/Math.abs(t.base)*100;case`indexed`:return e/t.base*100}}fromScale(e){let t=this.transform;switch(t.mode){case`normal`:return e;case`log`:return 10**e;case`percent`:return t.base+e/100*Math.abs(t.base);case`indexed`:return e/100*t.base}}displayValue(e){return this.transform.mode===`percent`||this.transform.mode===`indexed`?this.toScale(e)??NaN:e}valueToY(e){let t=this.toScale(e);return t===null?NaN:this.scaleToY(t)}scaleToY(e){let t=this.range;if(!t)return NaN;let n=(e-t.min)/(t.max-t.min);return this.inverted?n*this.height:(1-n)*this.height}yToScale(e){let t=this.range;if(!t||this.height===0)return NaN;let n=this.inverted?e/this.height:1-e/this.height;return t.min+n*(t.max-t.min)}yToValue(e){return this.fromScale(this.yToScale(e))}setValueRange(e){let t=this.toScale(e.min),n=this.toScale(e.max);return t===null||n===null?!1:this.setManual({min:t,max:n})}zoom(e,t){let n=this.range;if(!n||!(e>0))return;let r=this.yToScale(t);this.setManual({min:r-(r-n.min)/e,max:r+(n.max-r)/e})}pan(e){let t=this.range;if(!t||this.height===0)return;let n=(t.max-t.min)*e/this.height,r=this.settings.invert?-n:n;this.setManual({min:t.min+r,max:t.max+r})}resetAutoScale(){this.manual=null}manualRange(){return this.manual?.mode===this.settings.mode?this.manual.range:null}restoreManualRange(e){this.manual=e&&se(e,this.settings.mode)?{range:e,mode:this.settings.mode}:null}setManual(e){return se(e,this.transform.mode)?(this.manual={range:e,mode:this.transform.mode},this.range=e,!0):!1}};let ue=/^(.+)-(\d+)$/;var de=class{taken;counts;constructor(e,t){this.taken=e,this.counts=new Map(t?.counts)}next(e){let t=this.counts.get(e)??1;for(;this.taken(`${e}-${t}`);)t+=1;return`${e}-${t}`}note(e){let t=ue.exec(e);if(!t)return;let[,n=``,r=``]=t,i=Number(r)+1;Number.isSafeInteger(i)&&i>(this.counts.get(n)??1)&&this.counts.set(n,i)}reserve(e){e.forEach(e=>{let t=typeof e==`object`&&e?e.id:void 0;typeof t==`string`&&this.note(t)})}};let x=`main`,fe=`right`,pe=`left`,me=[`normal`,`log`,`percent`,`indexed`],he=g({id:!0,title:!0,height:!0}),ge=g({title:!0,height:!0});function _e(e,t){t.title!==void 0&&typeof t.title!=`string`&&n(`${e}.title must be a string.`),t.height!==void 0&&d(`${e}.height`,t.height,{min:1})}var ve=class{defaultHeight;entries=[];ids=new de(e=>this.get(e)!==void 0);margins;constructor(e,t){this.defaultHeight=e,this.margins=t,this.entries.push(this.createEntry(x,{title:``},!1))}list(){return this.entries}get(e){return this.entries.find(t=>t.id===e)}require(e){return this.get(e)??n(`Unknown pane "${e}".`)}info(e){return{id:e.id,title:e.title,height:e.height,auto:e.auto}}configure(e,t){this.defaultHeight=e,this.margins=t,this.entries.forEach(e=>{e.scales.forEach(e=>{this.syncScale(e)})})}add(e,t){_(`pane`,e,he),_e(`pane`,e);let r=e.id===void 0?this.ids.next(`pane`):p(`pane.id`,e.id);this.get(r)&&n(`A pane with id "${r}" already exists.`);let i=this.createEntry(r,e,t);return this.entries.push(i),this.ids.note(r),i}update(e,t){_(`pane patch`,t,ge);let n=this.require(e);_e(`pane`,t),t.title!==void 0&&(n.title=t.title),t.height!==void 0&&(n.height=t.height)}remove(e){e===`main`&&n(`The main pane cannot be removed.`);let t=this.entries.findIndex(t=>t.id===e);t<0&&n(`Unknown pane "${e}".`),this.entries.splice(t,1)}move(e,t){e===`main`&&n(`The main pane always stays first.`),d(`index`,t,{min:1,max:this.entries.length-1,integer:!0});let r=this.entries.findIndex(t=>t.id===e);r<0&&n(`Unknown pane "${e}".`);let[i]=this.entries.splice(r,1);i&&this.entries.splice(t,0,i)}adopt(e){this.entries.splice(0,this.entries.length,...e.entries),this.entries.forEach(e=>{this.ids.note(e.id),e.scales.forEach(e=>{this.syncScale(e)})})}findScale(e,t){return this.require(e).scales.get(t)??null}ensureScale(e,t){let n=this.require(e),r=n.scales.get(t);return r||(p(`scale id`,t),r=this.createScale(t),n.scales.set(t,r)),r}manualScales(e){let t=/* @__PURE__ */ new Set;for(let{scale:n}of this.require(e).scales.values())n.lead.autoScale||t.add(n.lead);return[...t]}setScaleMode(e,t,n){let r=this.ensureScale(e,t);r.mode=m(`mode`,n,me),this.syncScale(r)}setScaleInverted(e,t,n){let r=this.ensureScale(e,t);r.invert=f(`inverted`,n),this.syncScale(r)}setScaleMargins(e,t,n){let r=n===null?null:ie(`margins`,n),i=this.ensureScale(e,t);i.margins=r,this.syncScale(i)}createScale(e){return{id:e,mode:`normal`,invert:!1,margins:null,scale:new le({mode:`normal`,invert:!1,margins:this.margins})}}createEntry(e,t,n){let r=this.createScale(fe);return{id:e,title:t.title??``,height:t.height??this.defaultHeight,auto:n,right:r,scale:r.scale,scales:/* @__PURE__ */ new Map([[fe,r]])}}syncScale(e){e.scale.configure({mode:e.mode,invert:e.invert,margins:e.margins??this.margins})}};function ye(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}let be=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`]);function xe(e){return Array.isArray(e)?[...e]:e}function Se(e,t){if(t===void 0)return e;if(!ye(e)||!ye(t))return xe(t);let n={...e};for(let[e,r]of Object.entries(t)){if(r===void 0||be.has(e))continue;let t=n[e];n[e]=ye(t)&&ye(r)?Se(t,r):xe(r)}return n}function Ce(e){return(ye(e)||Array.isArray(e))&&(Object.values(e).forEach(e=>{Ce(e)}),Object.freeze(e)),e}function we(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;let n=e,r=t,i=Object.keys(n);return i.length===Object.keys(r).length&&i.every(e=>Object.hasOwn(r,e)&&we(n[e],r[e]))}let Te=g({interval:!0});function Ee(e){return{set:(t,n={})=>{v(`bars`,t),_(`data.set() options`,n,Te),e.run(()=>{e.setData(t,n.interval)})},update:t=>{e.run(()=>{e.updateData(Array.isArray(t)?t:[t])})},addTrades:t=>e.run(()=>e.addTrades(Array.isArray(t)?t:[t])),prepend:t=>(v(`bars`,t),e.run(()=>e.prependData(t))),clear:()=>{e.run(()=>{e.clearData()})},sourceInterval:()=>e.market.sourceInterval(),calendar:()=>e.market.tradingCalendar(),timeframe:()=>e.market.timeframe(),setTimeframe:t=>{e.run(()=>{e.setTimeframe(t)})},get length(){return e.bars.length},bars:e.market.displayed,source:e.market.revealed,at:t=>e.bars.bar(t),last:()=>e.bars.bar(e.bars.length-1),indexOf:t=>e.bars.indexOf(a(t)),toArray:()=>e.bars.toArray()}}function De(e,t,r){let i=()=>e.panes.findScale(t,r),a=()=>e.panes.ensureScale(t,r),o=()=>e.frame().panes.find(e=>e.id===t)?.plot.y??n(`Unknown pane "${t}".`),s=t=>{e.run(()=>{e.frame(),t(),e.invalidate()})};return{range:()=>(e.frame(),i()?.scale.valueRange()??null),setRange:e=>{d(`range.min`,e.min),d(`range.max`,e.max),e.max>e.min||n(`range.max (${e.max}) must be greater than range.min (${e.min}).`),s(()=>{a().scale.lead.setValueRange(e)||n(`The range ${e.min}..${e.max} cannot be shown in ${a().scale.mode} mode.`)})},autoScale:()=>{s(()=>{i()?.scale.lead.resetAutoScale()})},isAutoScale:()=>i()?.scale.lead.autoScale??!0,mode:()=>i()?.mode??`normal`,setMode:n=>{s(()=>{e.panes.setScaleMode(t,r,n)})},isInverted:()=>i()?.invert??!1,setInverted:n=>{s(()=>{e.panes.setScaleInverted(t,r,n)})},margins:()=>({...i()?.margins??e.options.priceScale.margins}),setMargins:n=>{s(()=>{e.panes.setScaleMargins(t,r,n)})},priceToY:e=>{d(`price`,e);let t=o(),n=i()?.scale.valueToY(e)??NaN;return Number.isFinite(n)?t+n:null},yToPrice:e=>{d(`y`,e);let t=o(),n=i()?.scale.yToValue(e-t)??NaN;return Number.isFinite(n)?n:null}}}function Oe(e){return{list:()=>e.panes.list().map(t=>e.panes.info(t)),get:t=>{let n=e.panes.get(t);return n?e.panes.info(n):null},add:t=>e.run(()=>{let{id:n}=e.panes.add(t,!1);return e.invalidate(),n}),update:(t,n)=>{e.run(()=>{e.panes.update(t,n),e.invalidate()})},remove:t=>{e.run(()=>{t===`main`&&n(`The main pane cannot be removed.`);let r=e.occupantsOf(t);r.length>0&&n(`Pane "${t}" still contains ${r.map(e=>`"${e}"`).join(`, `)}.`),e.removePane(t),e.invalidate()})},move:(t,n)=>{e.run(()=>{e.panes.move(t,n),e.invalidate()})}}}let ke=/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,Ae=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/i,je;function Me(e){let t=e.length<=4?e.split(``).map(e=>e+e).join(``):e,n=e=>Number.parseInt(t.slice(e,e+2),16);return{r:n(0),g:n(2),b:n(4),a:t.length===8?n(6)/255:1}}function Ne(e){let t=e[4];return{r:Number(e[1]),g:Number(e[2]),b:Number(e[3]),a:t===void 0?1:t.endsWith(`%`)?Number(t.slice(0,-1))/100:Number(t)}}function Pe(e){if(je??=typeof document>`u`?null:document.createElement(`canvas`).getContext(`2d`),!je)return;je.fillStyle=`#000000`,je.fillStyle=e;let t=je.fillStyle;return(t!==`#000000`||/^(black|#0{3,8})$/i.test(e))&&(ke.test(t)||Ae.test(t))?t:null}function Fe(e){let t=e.trim(),r=ke.exec(t);if(r?.[1])return Me(r[1]);let i=Ae.exec(t);if(i)return Ne(i);let a=Pe(t);return a?Fe(a):n(`Unsupported color ${JSON.stringify(e)}.`)}function S(e,t){let r=p(e,t).trim();return!ke.test(r)&&!Ae.test(r)&&Pe(r)===null&&n(`${e} must be a CSS color, not ${JSON.stringify(t)}.`),t}function Ie(e,t){for(let[n,r]of Object.entries(t))(n===`color`||n.endsWith(`Color`))&&r!=null&&S(`${e}.${n}`,r)}let Le=/* @__PURE__ */ new Map;function Re(e){let t=Le.get(e);return t||(Le.size>=256&&Le.clear(),t={rgba:Fe(e),made:/* @__PURE__ */ new Map},Le.set(e,t)),t}function ze(e,t,n){let r=e.made.get(t);return r===void 0&&(e.made.size>=32&&e.made.clear(),r=n(),e.made.set(t,r)),r}function Be(e,t,n){let r=Re(e);return ze(r,`${n} over ${t}`,()=>{let e=r.rgba,i=Re(t).rgba,a=e.a*n,o=(e,t)=>Math.round(e*a+t*(1-a));return`rgb(${o(e.r,i.r)}, ${o(e.g,i.g)}, ${o(e.b,i.b)})`})}function C(e,t){let n=Re(e);return ze(n,String(t),()=>{let{r:e,g:r,b:i,a}=n.rgba;return`rgba(${e}, ${r}, ${i}, ${Math.round(a*t*1e3)/1e3})`})}var Ve=class{current=0;resetAt=0;tails=[];get revision(){return this.current}reset(){this.current+=1,this.resetAt=this.current,this.tails=[]}tail(e){this.current+=1,this.tails.push({revision:this.current,from:e}),this.tails.length>256&&this.tails.shift()}since(e){if(e===this.current)return null;let t=this.tails[0];if(e<this.resetAt||e>this.current||!t||t.revision>e+1)return{kind:`reset`};let n=1/0;for(let t of this.tails)t.revision>e&&(n=Math.min(n,t.from));return{kind:`tail`,from:n}}};let He=Float64Array.BYTES_PER_ELEMENT;function Ue(e){return e.byteOffset/He}function We(e,t,n,r){let i=new Float64Array(new ArrayBuffer((n+r)*He),n*He,r);return i.set(e.subarray(0,t)),i}function Ge(e,t,n){return n<=e.length?e:We(e,t,Ue(e),Math.max(16,e.length*2,n))}function Ke(e,t,n){let r=Ue(e)>=n?e:We(e,t,n+(t+n>>1),Math.max(16,e.length));return new Float64Array(r.buffer,r.byteOffset-n*He,r.length+n)}function qe(e,t){for(let r=1;r<e.length;r+=1){let i=e[r-1],a=e[r];i&&a&&a.time<=i.time&&n(`${t} must be sorted by strictly ascending time: ${t}[${r}] (${a.time}) is not after ${t}[${r-1}] (${i.time}).`)}}function Je(e,t,r,i,a){let o=t>0?r:-1/0;e.forEach((e,t)=>{e.time<o&&n(`${i}[${t}] (time ${e.time}) is older than the last ${a} (time ${o}). update() only replaces the last ${a} or appends newer ones; use set() or prepend() to change history.`),o=e.time});let s=e[0],c=t>0&&s?.time===r?t-1:t,l=[];for(let t of e)l.length>0&&l[l.length-1]?.time===t.time?l[l.length-1]=t:l.push(t);return{from:c,tail:l}}function Ye(e){if(e.length<2)return null;let t=Math.max(1,e.length-64),n=[];for(let r=t;r<e.length;r+=1)n.push(e.time(r)-e.time(r-1));return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]??null}function Xe(e,t,n){if(t===null)return e.length===1&&n===e.time(0)?0:NaN;if(n<=e.time(0))return(n-e.time(0))/t;let r=e.lowerBound(n),i=r<e.length&&e.time(r)===n?r:r-1,a=e.length-1;if(i>=a)return a+(n-e.time(a))/t;let o=e.time(i);return i+(n-o)/(e.time(i+1)-o)}function Ze(e,t,n){if(t===null)return e.length===1&&n===e.time(0)?0:NaN;let r=e.length-1;if(n<e.time(0))return Math.floor((n-e.time(0))/t);let i=e.lowerBound(n),a=i<e.length&&e.time(i)===n?i:i-1;return a>=r?r+Math.floor((n-e.time(r))/t):a}function Qe(e,t,n){if(t===null)return e.length===1&&n===0?e.time(0):NaN;let r=e.length-1;if(n<=0)return e.time(0)+n*t;if(n>=r)return e.time(r)+(n-r)*t;let i=Math.floor(n),a=e.time(i);return a+(n-i)*(e.time(i+1)-a)}function $e(e){return typeof e==`number`&&Number.isFinite(e)}function et(e,t){return t===void 0?e:`${e}[${t}]`}function tt(e,t=`bar`,r){let o=e;(typeof o!=`object`||!o||Array.isArray(o))&&h(et(t,r),o);let s=$e(e.time)?e.time:a(e.time,`${et(t,r)}.time`),{open:c,high:l,low:u,close:d}=e,f=e.volume??0;if(!$e(c)||!$e(l)||!$e(u)||!$e(d)||!$e(f)){let[e,a]=Object.entries({open:c,high:l,low:u,close:d,volume:f}).find(([,e])=>!$e(e));n(`${et(t,r)}.${e} must be a finite number, received ${i(a)}.`)}return(l<Math.max(c,d)||u>Math.min(c,d))&&n(`${et(t,r)} is inconsistent: high (${l}) and low (${u}) must enclose open (${c}) and close (${d}).`),f<0&&n(`${et(t,r)}.volume must not be negative, received ${f}.`),{time:s,open:c,high:l,low:u,close:d,volume:f}}function nt(e,t=`bars`){return e.map((e,n)=>tt(e,t,n))}var rt=class{times=/* @__PURE__ */ new Float64Array;opens=/* @__PURE__ */ new Float64Array;highs=/* @__PURE__ */ new Float64Array;lows=/* @__PURE__ */ new Float64Array;closes=/* @__PURE__ */ new Float64Array;volumes=/* @__PURE__ */ new Float64Array;count=0;changes=new Ve;cachedInterval=null;get length(){return this.count}get revision(){return this.changes.revision}time(e){return this.times[e]??NaN}open(e){return this.opens[e]??NaN}high(e){return this.highs[e]??NaN}low(e){return this.lows[e]??NaN}close(e){return this.closes[e]??NaN}volume(e){return this.volumes[e]??NaN}price(e,t){switch(t){case`open`:return this.open(e);case`high`:return this.high(e);case`low`:return this.low(e);case`close`:return this.close(e);case`hl2`:return(this.high(e)+this.low(e))/2;case`hlc3`:return(this.high(e)+this.low(e)+this.close(e))/3;case`ohlc4`:return(this.open(e)+this.high(e)+this.low(e)+this.close(e))/4}}bar(e){return Number.isInteger(e)&&e>=0&&e<this.count?this.read(e):null}read(e){return{time:this.time(e),open:this.open(e),high:this.high(e),low:this.low(e),close:this.close(e),volume:this.volume(e)}}toArray(){return Array.from({length:this.count},(e,t)=>this.read(t))}lowerBound(e){let t=0,n=this.count;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}indexOf(e){let t=this.lowerBound(e);return t<this.count&&this.time(t)===e?t:-1}indexAt(e){let t=this.lowerBound(e);return t<this.count&&this.time(t)===e?t:t-1}logicalIndexOf(e){return Xe(this,this.interval(),e)}barIndexOf(e){return Ze(this,this.interval(),e)}timeOfLogicalIndex(e){return Qe(this,this.interval(),e)}interval(){return this.cachedInterval!==null||this.count<2||(this.cachedInterval=Ye(this)),this.cachedInterval}changesSince(e){return this.changes.since(e)}set(e){let t=nt(e);qe(t,`bars`),this.assign(t)}clear(){this.count=0,this.markReset()}assign(e){this.allocate(e.length),e.forEach((e,t)=>{this.write(t,e)}),this.count=e.length,this.markReset()}replaceFrom(e,t){let n=e+t.length,r=n!==this.count;this.ensureCapacity(n),t.forEach((t,n)=>{r||=this.time(e+n)!==t.time,this.write(e+n,t)}),this.count=n,r&&(this.cachedInterval=null),this.changes.tail(e)}insertBefore(e){e.length&&this.replaceFirst(0,e)}replaceFirst(e,t){let n=t.length-e,r=this.count,i=e=>Ke(e,r,n);this.times=i(this.times),this.opens=i(this.opens),this.highs=i(this.highs),this.lows=i(this.lows),this.closes=i(this.closes),this.volumes=i(this.volumes),t.forEach((e,t)=>{this.write(t,e)}),this.count=r+n,this.markReset()}write(e,t){this.times[e]=t.time,this.opens[e]=t.open,this.highs[e]=t.high,this.lows[e]=t.low,this.closes[e]=t.close,this.volumes[e]=t.volume}allocate(e){let t=Math.max(16,e);this.times=new Float64Array(t),this.opens=new Float64Array(t),this.highs=new Float64Array(t),this.lows=new Float64Array(t),this.closes=new Float64Array(t),this.volumes=new Float64Array(t)}ensureCapacity(e){let t=this.count,n=n=>Ge(n,t,e);this.times=n(this.times),this.opens=n(this.opens),this.highs=n(this.highs),this.lows=n(this.lows),this.closes=n(this.closes),this.volumes=n(this.volumes)}markReset(){this.changes.reset(),this.cachedInterval=null}},it=class{store;count;moves;countedAt=-1;counted=0;constructor(e,t=()=>e.length,n=()=>0){this.store=e,this.count=t,this.moves=n}get length(){let e=this.revision;return e!==this.countedAt&&(this.countedAt=e,this.counted=this.count()),this.counted}get revision(){return this.store.revision+this.moves()}time(e){return this.store.time(e)}open(e){return this.store.open(e)}high(e){return this.store.high(e)}low(e){return this.store.low(e)}close(e){return this.store.close(e)}volume(e){return this.store.volume(e)}bar(e){return e<this.length?this.store.bar(e):null}lowerBound(e){return Math.min(this.store.lowerBound(e),this.length)}};function at(e,t=`points`){return e.map((e,r)=>{h(`${t}[${r}]`,e);let o=a(e.time,`${t}[${r}].time`);return e.value!==null&&(typeof e.value!=`number`||!Number.isFinite(e.value))&&n(`${t}[${r}].value must be a finite number or null, received ${i(e.value)}.`),{time:o,value:e.value??NaN}})}var ot=class{times=/* @__PURE__ */ new Float64Array;values=/* @__PURE__ */ new Float64Array;count=0;get length(){return this.count}time(e){return this.times[e]??NaN}value(e){return this.values[e]??NaN}lowerBound(e){let t=0,n=this.count;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}clear(){this.count=0}assign(e){this.times=Float64Array.from(e,e=>e.time),this.values=Float64Array.from(e,e=>e.value),this.count=e.length}replaceFrom(e,t){let n=e+t.length;this.grow(n),t.forEach((t,n)=>{this.times[e+n]=t.time,this.values[e+n]=t.value}),this.count=n}insertBefore(e){this.replaceFirst(0,e)}replaceFirst(e,t){let n=t.length-e;this.times=Ke(this.times,this.count,n),this.values=Ke(this.values,this.count,n),t.forEach((e,t)=>{this.times[t]=e.time,this.values[t]=e.value}),this.count+=n}grow(e){this.times=Ge(this.times,this.count,e),this.values=Ge(this.values,this.count,e)}};let st=e=>e;function ct(){}var lt=class{values=/* @__PURE__ */ new Float64Array;count=0;at(e){return this.values[e]??NaN}assign(e){this.values=e,this.count=e.length}clear(){this.count=0}writeFrom(e,t){let n=e+t.length;this.values=Ge(this.values,e,n),this.values.set(t,e),this.count=n}prepend(e){this.values=Ke(this.values,this.count,e.length),this.values.set(e),this.count+=e.length}lastBefore(e){for(let t=e-1;t>=0;--t){let e=this.at(t);if(!Number.isNaN(e))return e}return-1/0}first(){for(let e=0;e<this.count;e+=1){let t=this.at(e);if(!Number.isNaN(t))return t}return 1/0}runStart(e,t){let n=e;for(;n>0;){let e=this.at(n-1);if(!Number.isNaN(e)&&e!==t)break;--n}return n}};function ut(e,t,r,i){let a=new Float64Array(e),s=i;for(let i=0;i<e;i+=1){let e=t(i),c=r(i,e);c===null?a[i]=NaN:(c<s&&n(`The calendar puts ${o(e)} into the bucket ${o(c)}, before the bucket ${o(s)} of an earlier time; buckets must not decrease with time.`),a[i]=c,s=c)}return a}var dt=class{source;target;kind;bucketer;buckets=new lt;cutoff=1/0;moves=0;constructor(e,t,n,r){this.source=e,this.target=t,this.kind=n,this.bucketer=r}get display(){return this.target}setDisplay(e){this.target.clear(),this.target=e,this.rebuild()}planSet(e,t){let n=this.kind.parse(e,this.kind.label);qe(n,this.kind.label);let r=ut(n.length,e=>n[e]?.time??NaN,(e,n)=>t(n),-1/0);return()=>{this.source.assign(n),this.buckets.assign(r),this.bucketer=t,this.rebuild()}}planUpdate(e){let{label:t,noun:n}=this.kind,r=this.source.length,{from:i,tail:a}=Je(this.kind.parse(e,t),r,this.source.time(r-1),t,n);if(a.length===0)return ct;let o=i<r?this.buckets.at(i):NaN,s=ut(a.length,e=>a[e]?.time??NaN,(e,t)=>e===0&&i<r?Number.isNaN(o)?null:o:this.bucketer(t),this.buckets.lastBefore(i));return()=>{this.source.replaceFrom(i,a),this.buckets.writeFrom(i,s),this.refresh(i,this.limit())}}planPrepend(e){let t=this.kind.parse(e,this.kind.label);qe(t,this.kind.label);let r=this.source.length?this.source.time(0):1/0,i=t.filter(e=>e.time<r);if(i.length===0)return{inserted:0,commit:ct};let a=ut(i.length,e=>i[e]?.time??NaN,(e,t)=>this.bucketer(t),-1/0),s=a.reduce((e,t)=>Number.isNaN(t)?e:t,-1/0),c=this.buckets.first();return s>c&&n(`The calendar puts older points into the bucket ${o(s)}, after the bucket ${o(c)} of a later time; buckets must not decrease with time.`),{inserted:i.length,commit:()=>{this.source.insertBefore(i),this.buckets.prepend(a),this.showOlder(i.length)}}}planRebucket(e){let t=ut(this.source.length,e=>this.source.time(e),(t,n)=>e(n),-1/0);return()=>{this.buckets.assign(t),this.bucketer=e,this.rebuild()}}follow(e){if(e.kind===`reset`){this.planRebucket(this.bucketer)();return}let{from:t}=e,n=ut(this.source.length-t,e=>this.source.time(t+e),(e,t)=>this.bucketer(t),this.buckets.lastBefore(t));this.buckets.writeFrom(t,n),this.refresh(t,this.limit())}cutoffTime(){return this.cutoff}setCutoff(e){let t=this.limit();this.cutoff=e;let n=this.limit();return n!==t&&(this.moves+=1,this.refresh(Math.min(t,n),Math.max(t,n)))}nextCutoff(e,t){let n=this.source.length,r=this.countUpTo(e);if(r>=n)return null;if(t){for(;r<n-1&&Number.isNaN(this.buckets.at(r));)r+=1;let e=this.buckets.at(r);for(;r<n-1;){let t=this.buckets.at(r+1);if(!Number.isNaN(t)&&t!==e)break;r+=1}}return this.source.time(r)}revealed(){return this.limit()}cutoffMoves(){return this.moves}firstTime(){return this.source.length>0?this.source.time(0):null}clear(){this.source.clear(),this.buckets.clear(),this.display.clear()}limit(){return this.countUpTo(this.cutoff)}countUpTo(e){if(e===1/0)return this.source.length;let t=0,n=this.source.length;for(;t<n;){let r=t+n>>>1;this.source.time(r)<=e?t=r+1:n=r}return t}rebuild(){this.display.assign(this.kind.aggregate(this.source,this.buckets,0,this.limit()))}showOlder(e){let t=this.display;if(t.length===0){this.rebuild();return}let n=t.time(0),r=this.limit(),i=e;for(;i<r;){let e=this.buckets.at(i);if(!Number.isNaN(e)&&e!==n)break;i+=1}t.replaceFirst(1,this.kind.aggregate(this.source,this.buckets,0,i))}refresh(e,t){let n=e;for(;n<t&&Number.isNaN(this.buckets.at(n));)n+=1;if(n>=t)return!1;let r=this.buckets.at(n),i=this.display.lowerBound(r),a=this.kind.aggregate(this.source,this.buckets,this.buckets.runStart(n,r),this.limit()),o=this.display.length;return i>=o-1&&i+a.length>=o?this.display.replaceFrom(i,a):this.rebuild(),!0}};function ft(e,t,n,r){let i=[],a=NaN,o=0,s=0,c=0,l=0,u=0;for(let d=n;d<r;d+=1){let n=t.at(d);Number.isNaN(n)||(n===a?(s=Math.max(s,e.high(d)),c=Math.min(c,e.low(d)),l=e.close(d),u+=e.volume(d)):(Number.isNaN(a)||i.push({time:a,open:o,high:s,low:c,close:l,volume:u}),a=n,o=e.open(d),s=e.high(d),c=e.low(d),l=e.close(d),u=e.volume(d)))}return Number.isNaN(a)||i.push({time:a,open:o,high:s,low:c,close:l,volume:u}),i}function pt(e,t,n,r){let i=[],a=NaN,o=NaN;for(let s=n;s<r;s+=1){let n=t.at(s);if(Number.isNaN(n))continue;n!==a&&(Number.isNaN(a)||i.push({time:a,value:o}),a=n,o=NaN);let r=e.value(s);Number.isNaN(r)||(o=r)}return Number.isNaN(a)||i.push({time:a,value:o}),i}let mt={label:`bars`,noun:`bar`,parse:nt,aggregate:ft},ht={label:`points`,noun:`point`,parse:at,aggregate:pt};function gt(e,t=new rt){return new dt(new rt,t,mt,e)}function _t(e,t){return new dt(e,new rt,mt,t)}function vt(e){return new dt(new ot,new ot,ht,e)}let yt=g({id:!0,type:!0,pane:!0,scale:!0,title:!0,visible:!0,precision:!0,lastValueLabel:!0,style:!0,data:!0}),bt=g({title:!0,visible:!0,precision:!0,lastValueLabel:!0,style:!0,scale:!0});function xt(e){_(`series`,e,yt)}function St(e){return e===null?null:d(`series.precision`,e,{min:0,max:12,integer:!0})}var Ct=class e{registry;theme;entries=/* @__PURE__ */ new Map;ids;bucketer=st;cutoff=1/0;constructor(e,t,n){this.registry=e,this.theme=t,this.ids=new de(e=>this.entries.has(e),n)}staging(t){let n=new e(this.registry,this.theme,this.ids);return n.bucketer=this.bucketer,n.cutoff=this.cutoff,n.ids.reserve(t),n}list(){return[...this.entries.values()]}get(e){return this.entries.get(e)}require(e){return this.entries.get(e)??n(`Unknown series "${e}".`)}info(e){return{id:e.id,type:e.type,pane:e.pane,scale:e.scale,title:e.title,visible:e.visible,precision:e.precision,lastValueLabel:e.lastValueLabel,style:{...e.style}}}add(e,t){let r=e.id??this.ids.next(e.type);p(`series.id`,r),p(`series.type`,e.type),this.entries.has(r)&&n(`A series with id "${r}" already exists.`);let i=this.registry.require(e.type),a=i.input===`ohlc`?{input:`ohlc`,feed:gt(this.bucketer)}:{input:`value`,feed:vt(this.bucketer)};a.feed.setCutoff(this.cutoff);let o={id:r,type:e.type,definition:i,pane:t,scale:e.scale===void 0?`right`:p(`series.scale`,e.scale),title:e.title===void 0?r:p(`series.title`,e.title),visible:e.visible===void 0||f(`series.visible`,e.visible),precision:e.precision===void 0?null:St(e.precision),lastValueLabel:e.lastValueLabel!==void 0&&f(`series.lastValueLabel`,e.lastValueLabel),style:e.style===void 0?{}:this.checkStyle(i,e.style),bars:a.input===`ohlc`?a.feed.display:null,values:a.input===`value`?a.feed.display:null,source:a,latestTrade:-1/0};return e.data&&this.write(o,`set`,e.data),this.entries.set(r,o),this.ids.note(r),o}update(e,t){_(`series patch`,t,bt);let n=this.require(e),r=t.title===void 0?n.title:p(`series.title`,t.title),i=t.scale===void 0?n.scale:p(`series.scale`,t.scale),a=t.visible===void 0?n.visible:f(`series.visible`,t.visible),o=t.precision===void 0?n.precision:St(t.precision),s=t.lastValueLabel===void 0?n.lastValueLabel:f(`series.lastValueLabel`,t.lastValueLabel),c=t.style===void 0?n.style:{...n.style,...this.checkStyle(n.definition,t.style)};n.title=r,n.scale=i,n.visible=a,n.precision=o,n.lastValueLabel=s,n.style=c}checkStyle(e,t){let n=this.theme();return _(`series.style`,t,Object.keys(e.defaultStyle(n,n.text))),Ie(`series.style`,t),{...t}}move(e,t){this.require(e).pane=t}remove(e){let t=this.require(e);return this.entries.delete(e),t}adopt(e){this.entries.clear(),e.entries.forEach((e,t)=>{this.entries.set(t,e),this.ids.note(t)})}write(e,t,r){let{source:i}=e;if(i.input===`ohlc`)wt(i.feed,t,r,this.bucketer)();else{let a=r.map((t,r)=>((typeof t!=`object`||!t||!(`value`in t))&&n(`Series "${e.id}" of type "${e.type}" needs { time, value } points (points[${r}]).`),t));wt(i.feed,t,a,this.bucketer)()}t===`set`&&(e.latestTrade=-1/0)}planRebucket(e){let t=this.list().map(t=>t.source.feed.planRebucket(e));return()=>{t.forEach(e=>{e()}),this.bucketer=e}}setCutoff(e){this.cutoff=e;for(let t of this.entries.values())t.source.feed.setCutoff(e)}};function wt(e,t,n,r){return t===`set`?e.planSet(n,r):t===`update`?e.planUpdate(n):e.planPrepend(n).commit}function Tt(e){h(`series type definition`,e),p(`series type definition type`,e.type),m(`definition.input`,e.input,[`ohlc`,`value`]),(typeof e.defaultStyle!=`function`||typeof e.paint!=`function`)&&n(`A series type definition needs defaultStyle() and paint() functions.`)}function Et(e,t,n){xt(n);let r=n.pane??`main`;r!==`new`&&e.panes.require(r);let i=r===`new`;return{entry:t.add(n,i?x:r),own:i}}function Dt(e){let t=t=>{e.run(()=>{v(`series`,t);let r=e.series.staging(t),i=t.flatMap(t=>{let n=Et(e,r,t);return n.own?[n.entry.id]:[]});e.values.verify((e,t)=>{e.kind===`series`&&!r.get(e.id)&&n(`${t}: unknown series "${e.id}".`)});let a=e.series.list().map(e=>e.pane);e.series.adopt(r),a.forEach(t=>{e.releasePane(t)}),i.forEach(t=>{e.series.move(t,e.createAutoPane(t))}),e.values.reset(),e.invalidate()})},r=(t,n,r)=>{e.run(()=>{e.series.write(e.series.require(t),n,r),n!==`update`&&e.values.reset(),e.invalidate()})};return{set:t,add:t=>e.run(()=>{let{entry:n,own:r}=Et(e,e.series,t);return r&&e.series.move(n.id,e.createAutoPane(n.id)),e.invalidate(),n.id}),update:(t,n)=>{e.run(()=>{e.series.update(t,n),e.invalidate()})},remove:t=>{e.run(()=>{e.values.assertUnused(`series`,t);let n=e.series.remove(t);e.releasePane(n.pane),e.invalidate()})},clear:()=>{t([])},get:t=>{let n=e.series.get(t);return n?e.series.info(n):null},list:()=>e.series.list().map(t=>e.series.info(t)),setData:(e,t)=>{r(e,`set`,t)},updateData:(e,t)=>{r(e,`update`,Array.isArray(t)?t:[t])},prependData:(e,t)=>{r(e,`prepend`,t)},addTrades:(t,n)=>e.run(()=>{let r=e.market.addSeriesTrades(e.series.require(t),Array.isArray(n)?n:[n]);return e.invalidate(),r}),register:t=>{e.run(()=>{Tt(t),e.seriesTypes.register(t),e.bus.emit(`typesChange`,{kind:`series`,type:t.type,registered:!0})})},unregister:t=>{e.run(()=>{e.seriesTypes.require(t),e.options.mainSeries.type===t&&n(`The main series is of type "${t}"; change it first.`);let r=e.series.list().filter(e=>e.type===t);r.length>0&&n(`The series ${r.map(e=>`"${e.id}"`).join(`, `)} are of type "${t}"; remove them first.`),e.seriesTypes.unregister(t),e.bus.emit(`typesChange`,{kind:`series`,type:t,registered:!1})})},types:()=>e.seriesTypes.types(),definition:t=>e.seriesTypes.get(t)??null}}let Ot=[`left`,`center`,`right`],kt=1.25;function At(e){return Number.isFinite(e)?e:null}function jt(e){let t=e.timeScale,n=t=>{e.run(()=>{e.frame(),t(),e.invalidate()})};return{visibleRange:()=>{e.frame();let n=t.visibleBars();return n?{from:e.bars.time(n.from),to:e.bars.time(n.to)}:null},setVisibleRange:r=>{h(`range`,r);let{from:i,to:o}=r,s=e.bars.logicalIndexOf(a(i,`range.from`)),c=e.bars.logicalIndexOf(a(o,`range.to`));Number.isFinite(s)&&Number.isFinite(c)&&n(()=>{t.setLogicalRange({from:Math.min(s,c)-.5,to:Math.max(s,c)+.5})})},visibleLogicalRange:()=>(e.frame(),e.bars.length>0?t.logicalRange():null),setVisibleLogicalRange:e=>{h(`range`,e),d(`range.from`,e.from),d(`range.to`,e.to),n(()=>{t.setLogicalRange(e)})},scrollToTime:(r,i=`center`)=>{let o=e.bars.logicalIndexOf(a(r));m(`align`,i,Ot),Number.isFinite(o)&&n(()=>{t.scrollToIndex(o,i)})},scrollToIndex:(e,r=`center`)=>{d(`index`,e),m(`align`,r,Ot),n(()=>{t.scrollToIndex(e,r)})},scrollToRealTime:()=>{n(()=>{t.scrollToRealTime()})},isFollowing:()=>t.isFollowing(),fitContent:()=>{n(()=>{t.fitContent()})},zoomIn:()=>{n(()=>{t.zoom(kt,t.zoomAnchor(null))})},zoomOut:()=>{n(()=>{t.zoom(1/kt,t.zoomAnchor(null))})},barSpacing:()=>t.barSpacing,setBarSpacing:e=>{d(`spacing`,e,{min:0,exclusiveMin:!0}),n(()=>{t.setBarSpacing(e)})},reset:()=>{n(()=>{t.reset(e.options.timeScale.barSpacing)})},timeToX:n=>{let r=e.frame().layout.leftAxisWidth;return At(t.indexToX(e.bars.logicalIndexOf(a(n)))+r)},xToTime:n=>{d(`x`,n);let r=e.frame().layout.leftAxisWidth;return At(e.bars.timeOfLogicalIndex(t.xToIndex(n-r)))},indexToX:n=>{d(`index`,n);let r=e.frame().layout.leftAxisWidth;return e.bars.length>0?t.indexToX(n)+r:null},xToIndex:n=>{d(`x`,n);let r=e.frame().layout.leftAxisWidth;return e.bars.length>0?t.xToIndex(n-r):null}}}function Mt(e){h(`transform definition`,e),p(`transform definition type`,e.type),p(`transform definition name`,e.name),f(`transform definition keepsTime`,e.keepsTime),typeof e.create!=`function`&&n(`A transform definition needs a create() function.`)}function Nt(e){let{transforms:t}=e.market;return{set:t=>{e.run(()=>{e.setTransform(t)})},get:()=>e.market.transform(),register:n=>{e.run(()=>{Mt(n),t.register(n),e.bus.emit(`typesChange`,{kind:`transform`,type:n.type,registered:!0})})},unregister:r=>{e.run(()=>{t.require(r),e.market.transform()?.type===r&&n(`The "${r}" transform builds the displayed bars; set another one first.`),t.unregister(r),e.bus.emit(`typesChange`,{kind:`transform`,type:r,registered:!1})})},types:()=>t.types(),definition:e=>t.get(e)??null}}var Pt=class{listeners=/* @__PURE__ */ new Map;queue=[];depth=0;flushing=!1;on(e,t){let n=this.listeners.get(e);return n||(n=/* @__PURE__ */ new Set,this.listeners.set(e,n)),n.add(t),()=>{let n=this.listeners.get(e);n?.delete(t),n?.size===0&&this.listeners.delete(e)}}has(e){return this.listeners.has(e)}emit(e,t){this.listeners.has(e)&&(this.queue.push({type:e,event:t}),this.depth===0&&this.flush())}defer(e){this.depth+=1;try{return e()}finally{--this.depth,this.depth===0&&this.flush()}}clear(){this.listeners.clear(),this.queue.length=0}flush(){if(this.flushing)return;this.flushing=!0;let e=[];try{for(let t=this.queue.shift();t;t=this.queue.shift()){let n=this.listeners.get(t.type);if(n)for(let r of[...n])try{r(t.event)}catch(t){e.push(t)}}}finally{this.flushing=!1}if(e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,`Multiple chart event listeners threw.`)}};let Ft=36e5,It=9e5,Lt=4096;function Rt(e,t){let n=e.find(e=>e.type===t);return n?Number(n.value):0}var zt=class{timeZone;hours=new Float64Array(Lt).fill(NaN);offsets=new Float64Array(Lt);zoneFormat;constructor(e){this.timeZone=e,this.zoneFormat=e===null?null:new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})}offset(e){let t=this.zoneFormat;if(!t)return-new Date(e).getTimezoneOffset()*6e4;let n=Math.floor(e/Ft),r=n&4095;if(this.hours[r]===n)return this.offsets[r]??0;let i=n*Ft,a=this.lookUp(t,i);return this.lookUp(t,i+Ft-It)===a?(this.hours[r]=n,this.offsets[r]=a,a):this.lookUp(t,Math.floor(e/It)*It)}lookUp(e,t){let n=e.formatToParts(t);return Date.UTC(Rt(n,`year`),Rt(n,`month`)-1,Rt(n,`day`),Rt(n,`hour`),Rt(n,`minute`),Rt(n,`second`))-t}instant(e){let t=e-this.offset(e);return e-this.offset(t)}fields(e){if(!this.zoneFormat){let t=new Date(e);return{year:t.getFullYear(),month:t.getMonth(),day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds()}}let t=new Date(e+this.offset(e));return{year:t.getUTCFullYear(),month:t.getUTCMonth(),day:t.getUTCDate(),hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds()}}},Bt=class{clock;numberFormats=/* @__PURE__ */ new Map;compactFormat;smallFormat;tinyFormat;timeFormats;dayFormat;minuteFormat;secondFormat;locale;timeZone;given;constructor(e,t){this.given=e??void 0,this.clock=new zt(t),this.compactFormat=new Intl.NumberFormat(this.given,{notation:`compact`,maximumFractionDigits:2}),this.smallFormat=new Intl.NumberFormat(this.given,{maximumSignificantDigits:3}),this.tinyFormat=new Intl.NumberFormat(this.given,{notation:`scientific`,maximumSignificantDigits:3});let n=e=>new Intl.DateTimeFormat(this.given,{timeZone:t??void 0,...e}),r=n({}).resolvedOptions();this.locale=this.compactFormat.resolvedOptions().locale,this.timeZone=r.timeZone;let i={hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`};this.timeFormats={year:n({year:`numeric`}),month:n({month:`short`}),day:n({day:`numeric`}),hour:n(i),minute:n(i),second:n({...i,second:`2-digit`})},this.dayFormat=n({year:`numeric`,month:`short`,day:`numeric`,weekday:`short`}),this.minuteFormat=n({year:`numeric`,month:`short`,day:`numeric`,...i}),this.secondFormat=n({year:`numeric`,month:`short`,day:`numeric`,...i,second:`2-digit`})}number(e,t){let n=this.numberFormats.get(t);return n||(n=new Intl.NumberFormat(this.given,{minimumFractionDigits:t,maximumFractionDigits:t}),this.numberFormats.set(t,n)),n.format(e)}compact(e){let t=Math.abs(e);return t===0||t>=1?this.compactFormat.format(e):(t<1e-4?this.tinyFormat:this.smallFormat).format(e)}timeTick(e,t){return this.timeFormats[t].format(e)}timeCrosshair(e,t){return t!==null&&t>=864e5?this.dayFormat.format(e):t!==null&&t<6e4?this.secondFormat.format(e):this.minuteFormat.format(e)}duration(e,t){let n=Math.max(0,Math.ceil(e/1e3)),r=Math.floor(n/86400),i=Math.floor(n%86400/3600),a=Math.floor(n%3600/60),o=n%60,s=e=>String(e).padStart(2,`0`);return r>0?`${t(r)} ${s(i)}:${s(a)}:${s(o)}`:i>0?`${i}:${s(a)}:${s(o)}`:`${s(a)}:${s(o)}`}};function Vt(e,t=0,n=8){let r=t;if(!Number.isFinite(e))return r;for(;r<n;){let t=e*10**r;if(Math.abs(t-Math.round(t))<Math.max(1e-9,Math.abs(t)*1e-12))break;r+=1}return r}let Ht={legendOpen:`O`,legendHigh:`H`,legendLow:`L`,legendClose:`C`,legendVolume:`V`,days:e=>`${e}d`};function Ut(e){return Object.fromEntries(Object.keys(e).map(e=>[e,null]))}function Wt(e,t,r){h(e,t);for(let[i,a]of Object.entries(t)){Object.hasOwn(r,i)||n(`${e} has no entry "${i}".`);let t=typeof r[i];a!==null&&typeof a!==t&&n(`${e}.${i} must be ${t===`function`?`a function`:`a string`} or null.`)}}function Gt(e,t){let n=Object.entries(t).filter(([,e])=>e!==null);return{...e,...Object.fromEntries(n)}}function Kt(e){return Gt(Ht,e.texts)}let qt=Ce({background:`#0e0e0e`,text:`#d8d8d8`,textMuted:`#9b9b9b`,grid:`rgba(140, 140, 140, 0.085)`,border:`rgba(140, 140, 140, 0.17)`,crosshair:`rgba(216, 216, 216, 0.45)`,crosshairLabelBackground:`#2a2a2a`,crosshairLabelText:`#f2f2f2`,up:`#2fb57e`,down:`#ef5d5d`,volumeUp:`rgba(47, 181, 126, 0.4)`,volumeDown:`rgba(239, 93, 93, 0.4)`,accent:`#3a74dc`,palette:[`#e8b04a`,`#5b9cf0`,`#b48cf0`,`#3cc4b0`,`#ef7d8e`,`#9fcf4a`,`#ee8a3c`,`#d77fd8`],buy:`#2fb57e`,sell:`#ef5d5d`,alert:`#e3a33b`}),Jt=Ce({background:`#ffffff`,text:`#1c2433`,textMuted:`#6b7485`,grid:`rgba(28, 36, 51, 0.06)`,border:`rgba(28, 36, 51, 0.12)`,crosshair:`rgba(28, 36, 51, 0.42)`,crosshairLabelBackground:`#1c2433`,crosshairLabelText:`#ffffff`,up:`#14a37f`,down:`#e5484d`,volumeUp:`rgba(20, 163, 127, 0.32)`,volumeDown:`rgba(229, 72, 77, 0.32)`,accent:`#4f46e5`,palette:[`#f59e0b`,`#4f46e5`,`#0891b2`,`#db2777`,`#65a30d`,`#9333ea`,`#ea580c`,`#0d9488`],buy:`#14a37f`,sell:`#e5484d`,alert:`#f59e0b`});function Yt(e=[]){return{...Object.fromEntries(e.map(e=>[e.key,e.defaults()])),autoSize:!0,locale:null,timeZone:null,theme:Jt,font:{family:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif`,size:12},grid:{vertical:!0,horizontal:!0,style:`solid`},crosshair:{mode:`free`,vertical:!0,horizontal:!0,labels:!0,style:`dashed`,snapToBars:!0,priceLines:null,avoidLabels:!1},mainSeries:{type:`candles`,source:`close`,styles:{},barColor:null},timeScale:{visible:!0,height:28,barSpacing:8,minBarSpacing:.5,maxBarSpacing:60,rightOffset:60,loadMoreThreshold:20,formatter:null},priceScale:{visible:!0,margins:{top:.1,bottom:.08},precision:`auto`,formatter:null,minWidth:48,pinLabels:!0,labelAnchor:`middle`},latestPrice:{line:!0,label:!0,countdown:!1,style:`dotted`,color:null},legend:{visible:!0,rows:null,buttons:null,hideValuesOnHover:!0,top:0},texts:Ut(Ht),interaction:{pan:!0,wheelZoom:!0,pinchZoom:!0,axisScale:!0,kineticScroll:!0,keyboard:!0,longPressMs:300,touchMagnifier:!0,hitTolerance:6},panes:{defaultHeight:120,minHeight:40,separatorHeight:5,separatorWidth:2,separatorColor:null,separatorHoverColor:null},calendar:{timeZone:`UTC`,sessions:[],dayStart:`00:00`,weekdays:[0,1,2,3,4,5,6],weekStart:1,bucket:null},performance:{maxPixelRatio:3,maxTrades:1e5}}}let Xt=[`open`,`high`,`low`,`close`,`hl2`,`hlc3`,`ohlc4`],Zt=/^([01]\d|2[0-3]):([0-5]\d)$/;function Qt(e,t){let r=typeof t==`string`?Zt.exec(t):null;return r?Number(r[1])*60+Number(r[2]):n(`${e} must be a time of day such as "09:30", received ${i(t)}.`)}function $t(e,t){let r=p(e,t),[i,a,o]=r.split(`-`);(i===void 0||a===void 0||o!==void 0)&&n(`${e} must be a session such as "09:30-11:30", received ${JSON.stringify(r)}.`);let s={start:Qt(e,i),end:Qt(e,a)};return s.start===s.end&&n(`${e} ${JSON.stringify(r)} has no length.`),s}function en(e){return e.start<e.end?[[e.start,e.end]]:[[e.start,1440],[0,e.end]]}function tn(e,t){return e.start<e.end?t>e.start&&t<e.end:t>e.start||t<e.end}function nn(e,t,r){e.forEach((i,a)=>{for(let o=0;o<a;o+=1){let s=e[o];s!==void 0&&en(i).some(([e,t])=>en(s).some(([n,r])=>e<r&&n<t))&&n(`${r}.sessions[${a}] ${JSON.stringify(t[a])} overlaps ${r}.sessions[${o}] ${JSON.stringify(t[o])}.`)}})}function rn(e,t){v(`${t}.sessions`,e.sessions);let r=e.sessions.map((e,n)=>p(`${t}.sessions[${n}]`,e)),i=r.map((e,n)=>$t(`${t}.sessions[${n}]`,e));nn(i,r,t);let a=Qt(`${t}.dayStart`,e.dayStart);i.forEach((i,o)=>{tn(i,a)&&n(`${t}.sessions[${o}] ${JSON.stringify(r[o])} spans the start of the trading day (${e.dayStart}); set ${t}.dayStart to the time the trading day begins.`)}),v(`${t}.weekdays`,e.weekdays),e.weekdays.length===0&&n(`${t}.weekdays must contain at least one weekday.`);let o=Array.from({length:7},()=>!1);e.weekdays.forEach((e,r)=>{let i=d(`${t}.weekdays[${r}]`,e,{min:0,max:6,integer:!0});o[i]&&n(`${t}.weekdays contains ${i} twice.`),o[i]=!0});let s=d(`${t}.weekStart`,e.weekStart,{min:0,max:6,integer:!0});return y(`${t}.bucket`,e.bucket),{sessions:i,dayStart:a,weekdays:o,weekStart:s,bucket:e.bucket}}function an(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function on(e,t){return e===t||e.timeZone===t.timeZone&&e.dayStart===t.dayStart&&e.weekStart===t.weekStart&&e.bucket===t.bucket&&an(e.sessions,t.sessions)&&an(e.weekdays,t.weekdays)}let sn={font:g({family:!0,size:!0}),grid:g({vertical:!0,horizontal:!0,style:!0}),crosshair:g({mode:!0,vertical:!0,horizontal:!0,labels:!0,style:!0,snapToBars:!0,priceLines:!0,avoidLabels:!0}),mainSeries:g({type:!0,source:!0,styles:!0,barColor:!0}),timeScale:g({visible:!0,height:!0,barSpacing:!0,minBarSpacing:!0,maxBarSpacing:!0,rightOffset:!0,loadMoreThreshold:!0,formatter:!0}),priceScale:g({visible:!0,margins:!0,precision:!0,formatter:!0,minWidth:!0,pinLabels:!0,labelAnchor:!0}),latestPrice:g({line:!0,label:!0,countdown:!0,style:!0,color:!0}),legend:g({visible:!0,rows:!0,buttons:!0,hideValuesOnHover:!0,top:!0}),interaction:g({pan:!0,wheelZoom:!0,pinchZoom:!0,axisScale:!0,kineticScroll:!0,keyboard:!0,longPressMs:!0,touchMagnifier:!0,hitTolerance:!0}),panes:g({defaultHeight:!0,minHeight:!0,separatorHeight:!0,separatorWidth:!0,separatorColor:!0,separatorHoverColor:!0}),calendar:g({timeZone:!0,sessions:!0,dayStart:!0,weekdays:!0,weekStart:!0,bucket:!0}),performance:g({maxPixelRatio:!0,maxTrades:!0})};function cn(e){for(let[t,n]of Object.entries(sn))_(`options.${t}`,e[t],n)}let ln=[`solid`,`dashed`,`dotted`],un=[`middle`,`firstLine`],dn=[`background`,`text`,`textMuted`,`grid`,`border`,`crosshair`,`crosshairLabelBackground`,`crosshairLabelText`,`up`,`down`,`volumeUp`,`volumeDown`,`accent`,`buy`,`sell`,`alert`];function fn(e){if(e!==null)try{new Intl.NumberFormat(e)}catch{n(`options.locale ${JSON.stringify(e)} is not a valid BCP 47 language tag.`)}}function pn(e){_(`options.theme`,e,[...dn,`palette`]),dn.forEach(t=>{S(`options.theme.${t}`,e[t])}),(!Array.isArray(e.palette)||e.palette.length===0)&&n(`options.theme.palette must contain at least one color.`),e.palette.forEach((e,t)=>{S(`options.theme.palette[${t}]`,e)})}function mn(e){cn(e),f(`options.autoSize`,e.autoSize),fn(e.locale),e.timeZone!==null&&te(`options.timeZone`,e.timeZone),pn(e.theme),p(`options.font.family`,e.font.family),d(`options.font.size`,e.font.size,{min:6,max:48}),f(`options.grid.vertical`,e.grid.vertical),f(`options.grid.horizontal`,e.grid.horizontal),m(`options.grid.style`,e.grid.style,ln),m(`options.crosshair.mode`,e.crosshair.mode,[`magnet`,`free`]),f(`options.crosshair.vertical`,e.crosshair.vertical),f(`options.crosshair.horizontal`,e.crosshair.horizontal),f(`options.crosshair.labels`,e.crosshair.labels),m(`options.crosshair.style`,e.crosshair.style,ln),f(`options.crosshair.snapToBars`,e.crosshair.snapToBars),y(`options.crosshair.priceLines`,e.crosshair.priceLines),f(`options.crosshair.avoidLabels`,e.crosshair.avoidLabels),p(`options.mainSeries.type`,e.mainSeries.type),m(`options.mainSeries.source`,e.mainSeries.source,Xt),y(`options.mainSeries.barColor`,e.mainSeries.barColor),h(`options.mainSeries.styles`,e.mainSeries.styles);for(let[t,n]of Object.entries(e.mainSeries.styles))n!==null&&(h(`options.mainSeries.styles.${t}`,n),Ie(`options.mainSeries.styles.${t}`,n));let t=e.timeScale;f(`options.timeScale.visible`,t.visible),d(`options.timeScale.height`,t.height,{min:0}),d(`options.timeScale.minBarSpacing`,t.minBarSpacing,{min:.1}),d(`options.timeScale.maxBarSpacing`,t.maxBarSpacing,{min:t.minBarSpacing}),d(`options.timeScale.barSpacing`,t.barSpacing,{min:t.minBarSpacing,max:t.maxBarSpacing}),d(`options.timeScale.rightOffset`,t.rightOffset,{min:0}),d(`options.timeScale.loadMoreThreshold`,t.loadMoreThreshold,{min:0,integer:!0}),y(`options.timeScale.formatter`,t.formatter);let n=e.priceScale;f(`options.priceScale.visible`,n.visible),ie(`options.priceScale.margins`,n.margins),n.precision!==`auto`&&d(`options.priceScale.precision`,n.precision,{min:0,max:12,integer:!0}),y(`options.priceScale.formatter`,n.formatter),d(`options.priceScale.minWidth`,n.minWidth,{min:0}),f(`options.priceScale.pinLabels`,n.pinLabels),m(`options.priceScale.labelAnchor`,n.labelAnchor,un),f(`options.latestPrice.line`,e.latestPrice.line),f(`options.latestPrice.label`,e.latestPrice.label),f(`options.latestPrice.countdown`,e.latestPrice.countdown),m(`options.latestPrice.style`,e.latestPrice.style,ln),e.latestPrice.color!==null&&S(`options.latestPrice.color`,e.latestPrice.color),f(`options.legend.visible`,e.legend.visible),f(`options.legend.hideValuesOnHover`,e.legend.hideValuesOnHover),d(`options.legend.top`,e.legend.top,{min:0});let r=e.interaction;f(`options.interaction.pan`,r.pan),f(`options.interaction.wheelZoom`,r.wheelZoom),f(`options.interaction.pinchZoom`,r.pinchZoom),f(`options.interaction.axisScale`,r.axisScale),f(`options.interaction.kineticScroll`,r.kineticScroll),f(`options.interaction.keyboard`,r.keyboard),d(`options.interaction.longPressMs`,r.longPressMs,{min:0}),f(`options.interaction.touchMagnifier`,r.touchMagnifier),d(`options.interaction.hitTolerance`,r.hitTolerance,{min:1}),d(`options.panes.defaultHeight`,e.panes.defaultHeight,{min:1}),d(`options.panes.minHeight`,e.panes.minHeight,{min:1}),d(`options.panes.separatorHeight`,e.panes.separatorHeight,{min:0}),y(`options.legend.rows`,e.legend.rows),y(`options.legend.buttons`,e.legend.buttons),d(`options.panes.separatorWidth`,e.panes.separatorWidth,{min:0});for(let t of[`separatorColor`,`separatorHoverColor`])e.panes[t]!==null&&S(`options.panes.${t}`,e.panes[t]);te(`options.calendar.timeZone`,e.calendar.timeZone),rn(e.calendar,`options.calendar`),d(`options.performance.maxPixelRatio`,e.performance.maxPixelRatio,{min:1}),d(`options.performance.maxTrades`,e.performance.maxTrades,{min:0,max:1e7,integer:!0}),Wt(`options.texts`,e.texts,Ht)}function hn(e,t,r){if(t!==void 0){h(`options`,t);for(let r of Object.keys(t))Object.hasOwn(e,r)||n(`The chart has no option "${r}"; a module the chart lacks may add it.`)}let i=Se(e,t);return mn(i),r.forEach(e=>{let t=`options.${e.key}`,n=i[e.key];h(t,n),e.validate(n,t)}),Ce(i)}function gn(e,t){switch(e){case`solid`:return[];case`dashed`:return[4*t+2,3*t+1];case`dotted`:return[t,2*t+1]}}function w(e,t,n,r=`solid`){e.strokeStyle=t,e.lineWidth=n,e.setLineDash(gn(r,n))}function T(e,t,n){let r=Math.max(1,Math.round(t*n)),i=Math.round(e*n);return(r%2==1?i+.5:i)/n}function _n(e,t){return Math.round(e*t)/t}function vn(e,t){e.save();try{t()}finally{e.restore()}}function E(e,t,n=`normal`){return`${n} ${e}px ${t}`}function yn(e,t,n,r,i){let a=e.measureText(t).width+i.paddingX*2,o=i.align===`left`?n:i.align===`right`?n-a:n-a/2,s=r-i.height/2;return e.fillStyle=i.background,e.beginPath(),e.roundRect(o,s,a,i.height,i.radius??2),e.fill(),e.fillStyle=i.color,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(t,o+a/2,r+.5),a}var bn=class{count=0;xs=/* @__PURE__ */ new Float64Array(64);opens=/* @__PURE__ */ new Float64Array(64);highs=/* @__PURE__ */ new Float64Array(64);lows=/* @__PURE__ */ new Float64Array(64);closes=/* @__PURE__ */ new Float64Array(64);volumes=/* @__PURE__ */ new Float64Array(64);values=/* @__PURE__ */ new Float64Array(64);ups=/* @__PURE__ */ new Uint8Array(64);colors=[];reset(e){if(this.count=0,this.colors.length=0,this.xs.length>=e)return;let t=Math.max(e,this.xs.length*2);this.xs=new Float64Array(t),this.opens=new Float64Array(t),this.highs=new Float64Array(t),this.lows=new Float64Array(t),this.closes=new Float64Array(t),this.volumes=new Float64Array(t),this.values=new Float64Array(t),this.ups=new Uint8Array(t)}pushOhlc(e,t,n,r,i,a,o,s=null){let c=this.count;this.colors[c]=s,this.xs[c]=e,this.opens[c]=t,this.highs[c]=n,this.lows[c]=r,this.closes[c]=i,this.volumes[c]=a,this.ups[c]=+!!o,this.count=c+1}pushValue(e,t,n){let r=this.count;this.colors[r]=null,this.xs[r]=e,this.volumes[r]=NaN,this.values[r]=t,this.ups[r]=+!!n,this.count=r+1}x(e){return this.xs[e]??NaN}open(e){return this.opens[e]??NaN}high(e){return this.highs[e]??NaN}low(e){return this.lows[e]??NaN}close(e){return this.closes[e]??NaN}volume(e){return this.volumes[e]??NaN}value(e){return this.values[e]??NaN}isUp(e){return this.ups[e]===1}color(e){return this.colors[e]??null}};let xn=/* @__PURE__ */ new WeakMap;function Sn(e,t,n,r,i){let{theme:a}=n.options,o=xn.get(e);if(o?.definition===t&&o.theme===a&&o.color===r&&o.overrides===i)return o.style;let s=Se(t.defaultStyle(a,r),i);return xn.set(e,{definition:t,theme:a,color:r,overrides:i,style:s}),s}function Cn(e,t){return e.precision===null?t:{kind:`decimal`,precision:e.precision}}var wn=class{sources;entry;range;format;color;pool;pane;scale;placed=e=>e;constructor(e,t,n,r,i,a){this.sources=e,this.entry=t,this.range=n,this.format=r,this.color=i,this.pool=a,this.pane=t.pane,this.scale=t.scale}window(){let{bars:e,timeScale:t}=this.sources,n=t.logicalRange(),r=this.entry.bars??this.entry.values,i=r?.length??0,a=e.length===1,o=e.timeOfLogicalIndex(a?0:Math.floor(n.from)-1),s=e.timeOfLogicalIndex(a?0:Math.ceil(n.to)+1);return!r||Number.isNaN(o)||Number.isNaN(s)?{from:0,to:-1}:{from:r.lowerBound(o),to:Math.min(i,r.lowerBound(s)+1)-1}}include(e){let{from:t,to:n}=this.window(),{bars:r,values:i}=this.entry,a=this.placed;for(let o=t;o<=n;o+=1)r?(b(e,a(r.low(o))),b(e,a(r.high(o)))):i&&b(e,a(i.value(o)));let o=Sn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style);this.entry.definition.extraExtents?.(o).forEach(t=>{b(e,a(t))})}firstValue(){let{bars:e,values:t}=this.entry,{to:n}=this.window(),r=this.sources.bars.time(this.range.from);for(let i=(e??t)?.lowerBound(r)??0;i<=n;i+=1){let n=e?e.close(i):t?.value(i)??NaN;if(Number.isFinite(n))return n}return null}rebase(e,t){let n=this.firstValue();n!==null&&n!==t&&(this.placed=e===`percent`?n===0?()=>NaN:e=>t+(e-n)/Math.abs(n)*Math.abs(t):n>0?e=>e/n*t:()=>NaN)}latest(){let{bars:e,values:t,lastValueLabel:n}=this.entry,r=((e??t)?.length??0)-1,i=e?e.close(r):t?.value(r)??NaN;if(!n||!Number.isFinite(i))return[];let{theme:a}=this.sources.options,o=Sn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style),s=!e||i>=e.open(r);return[{value:this.placed(i),color:o.color??(s?o.upColor??a.up:o.downColor??a.down)}]}emit(e,t){let{from:n,to:r}=this.window(),{bars:i,values:a}=this.entry,{bars:o,timeScale:s}=this.sources,c=this.pool.take(`series:${this.entry.id}`),l=this.placed,u=t=>e.valueToY(l(t));c.reset(Math.max(0,r-n+1));for(let e=n;e<=r;e+=1)if(i){let t=s.indexToX(o.logicalIndexOf(i.time(e))),n=i.open(e),r=i.close(e);c.pushOhlc(t,u(n),u(i.high(e)),u(i.low(e)),u(r),i.volume(e),r>=n)}else if(a){let t=s.indexToX(o.logicalIndexOf(a.time(e))),n=a.value(e),r=e>0?a.value(e-1):n;c.pushValue(t,u(n),!(n<r))}t.push({kind:`series`,definition:this.entry.definition,style:Sn(this.entry,this.entry.definition,this.sources,this.color,this.entry.style),points:c,valueToY:u,bars:i,first:n,transform:null})}};function Tn(e,t){return e[t%e.length]}var En=class{buffers=/* @__PURE__ */ new Map;used=/* @__PURE__ */ new Set;take(e){this.used.add(e);let t=this.buffers.get(e);return t||(t=new bn,this.buffers.set(e,t)),t}sweep(){for(let e of this.buffers.keys())this.used.has(e)||this.buffers.delete(e);this.used=/* @__PURE__ */ new Set}};function Dn(e){let t=e.options.mainSeries.barColor;if(!t)return null;let{bars:r,values:a}=e;return e=>{let o=r.bar(e)??n(`There is no bar ${e}.`),s=t({index:e,bar:o,indicator:(t,n)=>{let r={kind:`indicator`,id:t,...n===void 0?{}:{key:n}};return a.check(r,`mainSeries.barColor`),a.read(r,e)}});return s!==null&&typeof s!=`string`&&n(`mainSeries.barColor must return a color string or null, received ${i(s)}.`),s}}var On=class{sources;range;format;pool;pane=x;scale=fe;constructor(e,t,n,r){this.sources=e,this.range=t,this.format=n,this.pool=r}get definition(){return this.sources.seriesTypes.require(this.sources.options.mainSeries.type)}include(e){let{bars:t,options:n}=this.sources,r=this.definition.input===`ohlc`;for(let i=this.range.from;i<=this.range.to;i+=1)r?(b(e,t.low(i)),b(e,t.high(i))):b(e,t.price(i,n.mainSeries.source))}firstValue(){let{bars:e,options:t}=this.sources;return e.price(this.range.from,this.definition.input===`ohlc`?`close`:t.mainSeries.source)}emit(e,t){let{bars:n,timeScale:r,options:i}=this.sources,a=this.definition,o=this.pool.take(`main`),s=Math.max(0,this.range.from-1),c=Math.min(n.length-1,this.range.to+1);o.reset(c-s+1);let l=Dn(this.sources);for(let t=s;t<=c;t+=1){let s=r.indexToX(t);if(a.input===`ohlc`){let r=n.open(t),i=n.close(t);o.pushOhlc(s,e.valueToY(r),e.valueToY(n.high(t)),e.valueToY(n.low(t)),e.valueToY(i),n.volume(t),i>=r,l?.(t)??null)}else{let r=n.price(t,i.mainSeries.source),a=t>0?n.price(t-1,i.mainSeries.source):r;o.pushValue(s,e.valueToY(r),r>=a)}}t.push({kind:`series`,definition:a,style:Sn(i.mainSeries,a,this.sources,Tn(i.theme.palette,0),i.mainSeries.styles[i.mainSeries.type]??void 0),points:o,valueToY:t=>e.valueToY(t),bars:a.input===`ohlc`?n:null,first:s,transform:this.sources.transform})}};function kn(e,t,n,r){let{options:i}=e,a=i.theme.palette,o=[new On(e,t,n,r)];return e.series.list().forEach((i,s)=>{if(i.visible){let c=Tn(a,s+1);o.push(new wn(e,i,t,Cn(i,n),c,r))}}),e.contributors.forEach(i=>{o.push(...i(e,t,n,r))}),o}function D(e,t,n){return Number.isFinite(t)?n.kind===`compact`?e.compact(t):e.number(t,n.precision):`—`}function An(e,t){return e?e.kind===`decimal`&&t.kind===`decimal`?e.precision>=t.precision?e:t:e.kind===`decimal`?e:t:t}function jn(e,t,n){return Math.min(Math.max(e,t),n)}function Mn(e){if(!(e>0)||!Number.isFinite(e))return 1;let t=Math.floor(Math.log10(e)),n=e=>t<0?e/10**-t:e*10**t,r=t<0?e*10**-t:e/10**t;return n(r<=1?1:r<=2?2:r<=2.5?2.5:r<=5?5:10)}function Nn(e,t,n){if(!(n>0)||!Number.isFinite(e)||!Number.isFinite(t)||t<e)return[];let r=[],i=Math.ceil(e/n),a=Math.floor(t/n),o=Math.max(0,-Math.floor(Math.log10(n))+1);for(let e=i;e<=a;e+=1)r.push(Number((e*n).toFixed(o)));return r}let Pn=[1,2,5];function Fn(e,t){let n=e.scaleRange();if(!n)return[];let r=[];for(let e=Math.floor(n.min);e<=Math.ceil(n.max);e+=1)for(let t of Pn){let i=t*10**e,a=Math.log10(i);a>=n.min&&a<=n.max&&r.push(i)}let i=[],a=NaN;for(let n of r){let r=e.valueToY(n);(Number.isNaN(a)||Math.abs(r-a)>=t)&&(i.push(n),a=r)}return i}function In(e,t){let n=e.scaleRange(),r=e.plotHeight;if(!n||r<=0)return[];let i=n.max-n.min,a;if(e.mode===`log`&&i>=1)a=Fn(e,t);else if(e.mode===`log`){let i=e.fromScale(n.min),o=e.fromScale(n.max);a=Nn(i,o,Mn((o-i)*t/r))}else{let o=Mn(i*t/r);a=Nn(n.min,n.max,o).map(t=>e.fromScale(t))}return a.map(t=>({value:t,y:e.valueToY(t)})).filter(e=>e.y>=0&&e.y<=r)}function Ln(e,t){return!e||t.year!==e.year?90:t.month===e.month?t.day===e.day?t.hour===e.hour?t.minute===e.minute?t.second===e.second?1:30:t.minute%30==0?52:t.minute%15==0?51:t.minute%5==0?50:40:t.hour%6==0?62:60:70:80}function Rn(e){return e>=90?`year`:e>=80?`month`:e>=70?`day`:e>=60?`hour`:e>=40?`minute`:`second`}var zn=class{store;clock;weights=/* @__PURE__ */ new Uint8Array;revision=-1;constructor(e,t){this.store=e,this.clock=t}weight(e){this.sync();let t=this.weights[e]??0;if(t!==0)return t;let n=this.clock.fields(this.store.time(e)),r=Ln(e>0?this.clock.fields(this.store.time(e-1)):null,n);return this.weights[e]=r,r}sync(){let e=this.store.changesSince(this.revision);if(e){if(e.kind===`reset`||this.weights.length<this.store.length){let t=new Uint8Array(Math.max(16,this.store.length*2));e.kind===`tail`&&t.set(this.weights.subarray(0,e.from)),this.weights=t}else this.weights.fill(0,e.from);this.revision=this.store.revision}}};function Bn(e,t,n,r){let i=e.visibleBars();if(!i)return[];let a=/* @__PURE__ */ new Map;for(let e=i.from;e<=i.to;e+=1){let t=n.weight(e),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[],s=[],c=[...a.keys()].filter(e=>e>1).sort((e,t)=>t-e);for(let t of c)for(let n of a.get(t)??[]){let i=e.indexToX(n),a=0,c=o.length;for(;a<c;){let e=a+c>>>1;(o[e]??0)<i?a=e+1:c=e}let l=o[a-1],u=o[a];(l===void 0||i-l>=r)&&(u===void 0||u-i>=r)&&(o.splice(a,0,i),s.push({index:n,weight:t}))}return s.sort((e,t)=>e.index-t.index).map(({index:n,weight:r})=>({index:n,x:e.indexToX(n),time:t.time(n),unit:Rn(r)}))}function Vn(e,t,n){let{scale:r}=t,i=r.displayValue(n),a=r.mode,o=e.options.priceScale.formatter,s=t.format.kind===`decimal`?t.format.precision:0;return o?o(i,{paneId:t.id,mode:a,precision:s,locale:e.formatter.locale}):a===`percent`?`${D(e.formatter,i,{kind:`decimal`,precision:2})}%`:a===`indexed`?D(e.formatter,i,{kind:`decimal`,precision:2}):D(e.formatter,i,t.format)}function Hn(e,t){let n=t.reduce((t,n)=>Math.max(t,e.measureText(n)),0);return Math.min(160,Math.max(e.options.priceScale.minWidth,Math.ceil(n+20)))}function Un(e,t,n){if(!e.options.priceScale.visible)return{right:0,left:0};let r=e=>t.flatMap(t=>t.marks.flatMap(t=>t.side===e?[t.text]:[])),i=[...t.flatMap(e=>e.ticks.map(e=>e.text)),...r(`right`)],a=t.flatMap(e=>e.left?[e.left]:[]),o=n?[n.text,...n.countdown===null?[]:[n.countdown],...n.live?[n.live.text]:[]]:[];return{right:Hn(e,[...i,...o]),left:a.length>0?Hn(e,[...a.flatMap(e=>e.ticks.map(e=>e.text)),...r(`left`)]):0}}function Wn(e,t,n,r){let{options:i,panes:a}=e;return l({width:t,height:n,axisWidth:i.priceScale.visible?r.right:0,leftAxisWidth:i.priceScale.visible?r.left:0,timeAxisHeight:i.timeScale.visible?i.timeScale.height:0,separatorHeight:i.panes.separatorHeight,minPaneHeight:i.panes.minHeight,panes:a.list().map(e=>({id:e.id,height:e.height,stretch:e.id===x}))})}function Gn(e,t){return e<=t&&e>t-12}function Kn(e,t,n,r){let i={kind:`decimal`,precision:e.pricePrecision},a=n,o=Zn(e,t,a,i,r);for(let n=0;n<2;n+=1){let n=Un(e,o.panes,o.latest);if(Gn(n.right,a.right)&&Gn(n.left,a.left))break;a={right:Gn(n.right,a.right)?a.right:n.right,left:Gn(n.left,a.left)&&n.left>0?a.left:n.left},o=Zn(e,t,a,i,r)}return e.timeScale.settle(),r.sweep(),o}function qn(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.scale);e?e.push(n):t.set(n.scale,[n])}return t}function Jn(e,t){let n=t[0]?.firstValue()??null,r=e.relativeMode(n);r&&n!==null&&t.forEach(e=>{e.rebase?.(r,n)}),e.fit(Yn(t),n)}function Yn(e){let t=ae();return e.forEach(e=>{e.include(t,!1)}),t.min>t.max&&e.forEach(e=>{e.include(t,!0)}),t}function Xn(e,t){return e.reduce((e,t)=>An(e,t.format),null)??t}function Zn(e,t,r,i,a){let{options:o,timeScale:s,bars:c,formatter:l}=e,u=Wn(e,t.width,t.height,r);s.setWidth(u.plotWidth);let d=s.visibleBars(),f=d?kn(e,d,i,a):[],p=[],m=o.font.size*2.6;for(let t of u.panes){let n=e.panes.require(t.id),r=f.filter(e=>e.pane===n.id),a=qn(r),o=/* @__PURE__ */ new Map;for(let[r,i]of a){let a=e.panes.ensureScale(n.id,r).scale;a.setHeight(t.plot.height),Jn(a,i),o.set(r,a)}let s=a.get(`right`)??a.get(`left`)??[],c=o.get(pe);a.has(`right`)||(n.scale.setHeight(t.plot.height),c?n.scale.follow(c):n.scale.fit(ae(),null));let l=[],u=[];r.forEach(t=>{let r=o.get(t.scale)??n.scale;t.emit(r,l);let i=t.scale===`right`?`right`:t.scale===`left`?`left`:null;if(i){let a={id:n.id,scale:r,format:t.format};for(let n of t.latest?.()??[])u.push({side:i,y:r.valueToY(n.value),text:Vn(e,a,n.value),color:n.color})}});let d=(t,r)=>{let i={id:n.id,scale:t,format:r};return In(t,m).map(t=>({y:t.y,text:Vn(e,i,t.value)}))},h=Xn(s,i),g=a.get(pe),_=g?Xn(g,i):i;p.push({id:n.id,entry:n,plot:t.plot,axis:t.axis,scale:n.scale,format:h,ticks:d(n.scale,h),left:c?{axis:t.leftAxis??{...t.plot,x:0,width:0},scale:c,format:_,ticks:d(c,_)}:null,marks:u,jobs:l})}let h=p[0]??n(`The layout has no main pane.`);return{layout:u,visible:d,timeTicks:o.timeScale.visible?Bn(s,c,e.marks,e.measureText(`00:00`)+24).map(t=>{let n=o.timeScale.formatter?o.timeScale.formatter(t.time,{kind:`axis`,unit:t.unit,locale:l.locale,timeZone:l.timeZone}):l.timeTick(t.time,t.unit);return{x:t.x,unit:t.unit,text:n,width:e.measureText(n)}}).filter(e=>e.x-e.width/2>=0&&e.x+e.width/2<=u.plotWidth):[],panes:p,main:h,priceFormat:i,latest:Qn(e,h)}}function Qn(e,t){let{bars:n,options:r}=e;if(n.length===0)return null;let i=n.length-1,a=e.seriesTypes.require(r.mainSeries.type).input===`ohlc`?n.close(i):n.price(i,r.mainSeries.source),o=t.scale.valueToY(a),s=n.close(i)>=n.open(i),c=r.mainSeries.styles[r.mainSeries.type],l=c&&`upColor`in c?c:void 0,{theme:u}=r,d=e=>r.latestPrice.color??(e?l?.upColor??u.up:l?.downColor??u.down),f=e.live;return{value:a,y:o,up:s,color:d(s),text:Vn(e,t,a),countdown:e.countdown,live:f===null||f===a?null:{value:f,y:t.scale.valueToY(f),color:Be(d(f>=a),u.background,.4),text:Vn(e,t,f)}}}function $n(e,t){return(e.font.size+8-6)*t+6}function er(e,t,n){return e.priceScale.labelAnchor===`middle`?t-($n(e,n)-$n(e,1))/2:t}function tr(e,t,n){let r=[...e],i=e.map((e,t)=>t).sort((t,n)=>(e[t]??0)-(e[n]??0)),a=n?(n.top+n.bottom)/2:-1/0,o=n?.top??1/0;for(let n of i.filter(t=>(e[t]??0)<=a).reverse())r[n]=Math.min(e[n]??0,o-t/2),o=(r[n]??0)-t/2;o=n?.bottom??-1/0;for(let n of i.filter(t=>(e[t]??0)>a))r[n]=Math.max(e[n]??0,o+t/2),o=(r[n]??0)+t/2;return r}function nr(e,t,n){if(!t.priceScale.visible)return[];let r=t.latestPrice.label?e.latest:null,i=n?2:1,a=$n(t,1),o=r?.live??null,s=r?er(t,r.y,i):0,c=[];for(let n of e.panes)for(let l of[`right`,`left`]){let u=l===`right`?n.axis:n.left?.axis,d=n===e.main&&l===`right`,f=[...n.marks.filter(e=>e.side===l),...d&&o&&Number.isFinite(o.y)?[o]:[]],p=s-a/2,m=r&&d&&Number.isFinite(r.y)?{top:p,bottom:p+$n(t,i)}:null,h=tr(f.map(e=>e.y),a,m);u&&f.forEach((e,t)=>{c.push({axis:u,y:h[t]??e.y,lines:1,mark:e})})}return r&&c.push({axis:e.main.axis,y:s,lines:i,mark:null}),c}let rr={price:[],time:null},ir=e=>e.font.size+8,ar=e=>e.font.size+2;function or(e,t,n,r){let i=sr(e,t,n,r);return t.crosshair.avoidLabels?ur(e,i,n,lr(e,t)):i}function sr(e,t,n,r){if(r===0){let e=ir(t)/2;return{top:n-e,bottom:n+e,priceY:n,lineY:()=>n}}let i=ar(t),a=i/2+3,o=e.layout.timeAxis?.y??e.layout.height;if(t.priceScale.labelAnchor===`middle`){let e=2*a+r*i,t=Math.max(0,Math.min(n-e/2,o-e));return cr({top:0,bottom:e,priceY:a,lineY:e=>a+i*(e+1)},t)}return n+a+r*i<=o?{top:n-a,bottom:n+a+r*i,priceY:n,lineY:e=>n+i*(e+1)}:{top:n-a-r*i,bottom:n+a,priceY:n,lineY:e=>n-i*(r-e)}}function cr(e,t){return{top:e.top+t,bottom:e.bottom+t,priceY:e.priceY+t,lineY:n=>e.lineY(n)+t}}function lr(e,t){let n=new Set(e.panes.map(e=>e.axis)),r=$n(t,1)/2;return nr(e,t,(e.latest?.countdown??null)!==null).filter(e=>n.has(e.axis)).map(e=>{let n=e.axis.y+e.y-r;return{top:n,bottom:n+$n(t,e.lines)}})}function ur(e,t,n,r){let i=t.bottom-t.top,a=[];for(let e of[...r].sort((e,t)=>e.top-t.top)){let t=a[a.length-1];t&&e.top<t.bottom+i?t.bottom=Math.max(t.bottom,e.bottom):a.push({...e})}let o=a.find(e=>t.top<e.bottom&&t.bottom>e.top);if(!o)return t;let s=e.layout.timeAxis?.y??e.layout.height,c=o.top-i>=0,l=o.bottom+i<=s;return cr(t,n<(o.top+o.bottom)/2&&c||!l?o.top-t.bottom:o.bottom-t.top)}function dr(e,t,n){return Math.min(Math.max(t,n/2),Math.max(n/2,e.layout.plotWidth-n/2))}function fr(e,t,n,r){if(!n||!t.crosshair.labels)return rr;let i=[],{y:a}=n;if(a!==null&&t.priceScale.visible){let r=ir(t)/2,o=or(e,t,a,n.priceLines.length);for(let t of e.panes){let e=o.top-t.axis.y,s=o.bottom-t.axis.y;n.priceText!==null&&s>0&&e<t.axis.height&&i.push({axis:t.axis,top:e,bottom:s});let c=a-r-t.axis.y,l=a+r-t.axis.y;n.leftPriceText!==null&&t.left&&l>0&&c<t.axis.height&&i.push({axis:t.left.axis,top:c,bottom:l})}}let o=null;if(n.timeText!==null&&e.layout.timeAxis){let t=r(n.timeText)+12,i=dr(e,n.x,t);o={left:i-t/2,right:i+t/2}}return{price:i,time:o}}function pr(e,t,n,r){return e.some(e=>e.axis===t&&n+r>e.top&&n-r<e.bottom)}function mr(e,t){let n=e.time;return n!==null&&t.x+t.width/2>n.left&&t.x-t.width/2<n.right}function hr(e,t,n){let r=t.font.size/2,i=[];return e.panes.forEach((e,t)=>{e.ticks.forEach((a,o)=>{pr(n.price,e.axis,a.y,r)&&i.push(`${t}:${o}`)}),e.left?.ticks.forEach((a,o)=>{pr(n.price,e.left?.axis??e.axis,a.y,r)&&i.push(`${t}<${o}`)})}),e.timeTicks.forEach((e,t)=>{mr(n,e)&&i.push(`t${t}`)}),i.join(`,`)}function gr(e,t,n,r,i,a){let o=-r.leftAxisWidth,s={x:Math.min(Math.max(n.x,o+56),o+r.width-56),y:n.y-48-56>=56?n.y-48-56:n.y+48+56},c=r.width*i,l=r.height*i,u=(n.x-o-28)*i,d=(n.y-28)*i,f=56*i,p=Math.max(0,u),m=Math.max(0,d),h=Math.min(c,u+f)-p,g=Math.min(l,d+f)-m,_=112/f;if(e.save(),e.beginPath(),e.arc(s.x,s.y,56,0,Math.PI*2),e.clip(),e.fillStyle=a.background,e.fillRect(s.x-56,s.y-56,112,112),h>0&&g>0){let n=s.x-56+(p-u)*_,r=s.y-56+(m-d)*_;for(let i of t)e.drawImage(i,p,m,h,g,n,r,h*_,g*_)}e.beginPath(),e.moveTo(s.x-7,s.y),e.lineTo(s.x+7,s.y),e.moveTo(s.x,s.y-7),e.lineTo(s.x,s.y+7),w(e,a.crosshair,1.5),e.stroke(),e.restore(),e.beginPath(),e.arc(s.x,s.y,56,0,Math.PI*2),w(e,a.border,2),e.stroke()}let _r=[`arrow-up`,`arrow-down`,`triangle-up`,`triangle-down`,`circle`,`square`];function vr(e){return e===`arrow-up`||e===`triangle-up`?1:e===`arrow-down`||e===`triangle-down`?-1:0}function yr(e,t,n,r,i){switch(t){case`circle`:e.arc(n,r,i,0,Math.PI*2);return;case`square`:e.rect(n-i,r-i,i*2,i*2);return;case`triangle-up`:e.moveTo(n,r-i),e.lineTo(n+i,r+i),e.lineTo(n-i,r+i),e.closePath();return;case`triangle-down`:e.moveTo(n,r+i),e.lineTo(n+i,r-i),e.lineTo(n-i,r-i),e.closePath();return;case`arrow-up`:e.moveTo(n,r-i),e.lineTo(n+i,r),e.lineTo(n+i*.4,r),e.lineTo(n+i*.4,r+i),e.lineTo(n-i*.4,r+i),e.lineTo(n-i*.4,r),e.lineTo(n-i,r),e.closePath();return;case`arrow-down`:e.moveTo(n,r+i),e.lineTo(n+i,r),e.lineTo(n+i*.4,r),e.lineTo(n+i*.4,r-i),e.lineTo(n-i*.4,r-i),e.lineTo(n-i*.4,r),e.lineTo(n-i,r),e.closePath();return}}function br(e,t,n,r,i){switch(t.kind){case`series`:vn(e,()=>{t.definition.paint({ctx:e,pixelRatio:r,width:n.plot.width,height:n.plot.height,barSpacing:i,style:t.style,points:t.points,valueToY:t.valueToY,bars:t.bars,first:t.first,transform:t.transform})});return;case`fill`:{let n=t.steps?Cr:Sr;t.above===t.below?n(e,t.from,t.to,null,t.above,i):(n(e,t.from,t.to,!0,t.above,i),n(e,t.from,t.to,!1,t.below,i));return}case`segments`:wr(e,t,r,i);return;case`boxes`:e.beginPath();for(let n of t.boxes)e.rect(T(n.x,1,r),T(n.y,1,r),Math.round(n.width*r)/r,Math.round(n.height*r)/r);e.fillStyle=C(t.color,.1),e.fill(),w(e,C(t.color,.6),1,`solid`),e.stroke();return;case`reference`:{let i=T(t.y,1,r);e.beginPath(),e.moveTo(0,i),e.lineTo(n.plot.width,i),w(e,t.color,1,`dashed`),e.stroke();return}case`columns`:Tr(e,t,r,i);return;case`markers`:Er(e,t);return;case`labels`:xr(e,t,n.plot.width);return}}function xr(e,t,n){e.font=t.font,e.textAlign=`center`;for(let{x:r,y:i,text:a,above:o,color:s}of t.labels){if(r<0||r>n)continue;let c=a.split(`
|
|
2
|
+
`),l=Math.max(...c.map(t=>e.measureText(t).width))/2,u=Math.min(Math.max(r,l),n-l);e.fillStyle=s,e.textBaseline=o?`bottom`:`top`,c.forEach((n,r)=>{let a=o?-4-(c.length-1-r)*t.lineHeight:4+r*t.lineHeight;e.fillText(n,u,i+a)})}}function Sr(e,t,n,r,i){let a=e=>t.value(e)<=n.value(e),o=-1,s=NaN,c=NaN,l=(i,l,u)=>{if(r===null||a(i)===r){Number.isNaN(s)?e.moveTo(t.x(o),t.value(o)):e.moveTo(s,c);for(let n=o;n<=i;n+=1)e.lineTo(t.x(n),t.value(n));Number.isNaN(l)||e.lineTo(l,u);for(let t=i;t>=o;--t)e.lineTo(n.x(t),n.value(t));e.closePath()}};e.beginPath();for(let e=0;e<t.count;e+=1)if(Number.isNaN(t.value(e))||Number.isNaN(n.value(e)))o>=0&&l(e-1,NaN,NaN),o=-1;else if(o<0)o=e,s=NaN,c=NaN;else if(a(e)!==a(e-1)){let r=t.value(e-1)-n.value(e-1),i=r/(r-(t.value(e)-n.value(e))),a=t.x(e-1)+i*(t.x(e)-t.x(e-1)),u=t.value(e-1)+i*(t.value(e)-t.value(e-1));l(e-1,a,u),o=e,s=a,c=u}o>=0&&l(t.count-1,NaN,NaN),e.fillStyle=i,e.fill()}function Cr(e,t,n,r,i,a){e.beginPath();for(let i=0;i<t.count;i+=1){let o=t.value(i),s=n.value(i);Number.isNaN(o)||Number.isNaN(s)||r!==null&&o<=s!==r||e.rect(t.x(i)-a/2,Math.min(o,s),a,Math.abs(s-o))}e.fillStyle=i,e.fill()}function wr(e,t,n,r){let{points:i}=t;e.beginPath();for(let a=0;a<i.count;a+=1){let o=i.value(a);if(Number.isNaN(o)||o===i.value(a-1))continue;let s=a;for(;s+1<i.count&&i.value(s+1)===o;)s+=1;let c=T(o,t.lineWidth,n);e.moveTo(i.x(a)-r/2,c),e.lineTo(i.x(s)+r/2,c)}w(e,t.color,t.lineWidth,t.lineStyle),e.stroke()}function Tr(e,t,n,r){let{points:i,from:a}=t,o=Math.max(1/n,Math.round(r*t.width*n)/n),s=1/n;e.fillStyle=t.color,e.beginPath();for(let r=0;r<i.count;r+=1){let c=i.value(r),l=a.value(r);if(Number.isNaN(c)||Number.isNaN(l))continue;let u=Math.round((i.x(r)-o/2)*n)/n,d=Math.min(l,c),f=Math.max(s,Math.abs(c-l));t.hollow?e.rect(u+s/2,d+s/2,o-s,f-s):e.fillRect(u,d,o,f)}t.hollow&&(w(e,t.color,s,`solid`),e.stroke())}function Er(e,t){let{points:n,shape:r,text:i,size:a}=t,o=r?vr(r):0,s=o*a;if(e.fillStyle=t.color,r){e.beginPath();for(let t=0;t<n.count;t+=1){let i=n.value(t);if(!Number.isNaN(i)){let o=n.x(t);e.moveTo(o+a,i+s),yr(e,r,o,i+s,a)}}e.fill()}if(i.length===0)return;e.font=t.font,e.textAlign=`center`,e.textBaseline=r?o>0?`top`:`bottom`:`middle`;let c=r?o>0?s+a+2:s-a-2:0;for(let t=0;t<n.count;t+=1){let r=n.value(t),a=typeof i==`string`?i:i[t]??``;!Number.isNaN(r)&&a!==``&&e.fillText(a,n.x(t),r+c)}}function Dr(e,t,n,r){let{grid:i,theme:a}=n;if(i.vertical||i.horizontal){e.beginPath();for(let n of t.panes){let{plot:a}=n;if(i.vertical)for(let n of t.timeTicks){let t=T(n.x,1,r);e.moveTo(t,a.y),e.lineTo(t,a.y+a.height)}if(i.horizontal)for(let t of n.ticks){let n=T(a.y+t.y,1,r);e.moveTo(a.x,n),e.lineTo(a.x+a.width,n)}}w(e,a.grid,1,i.style),e.stroke()}}function Or(e,t,n,r,i){if(!n.priceScale.visible)return;let{theme:a}=n;e.font=E(n.font.size,n.font.family),e.fillStyle=a.textMuted,e.textBaseline=`middle`;let o=n.font.size/2,s=[...nr(t,n,(t.latest?.countdown??null)!==null).map(e=>{let t=e.y-(n.font.size+8)/2;return{axis:e.axis,top:t,bottom:t+$n(n,e.lines)}}),...i.price],c=(t,n,r)=>{for(let i of n)i.y>=o&&i.y<=t.height-o&&!pr(s,t,i.y,o)&&e.fillText(i.text,r,t.y+i.y)};for(let n of t.panes)e.textAlign=`left`,c(n.axis,n.ticks,n.axis.x+8),n.left&&(e.textAlign=`right`,c(n.left.axis,n.left.ticks,-8));let l=t.layout.leftAxisWidth>0?[t.layout.plotWidth,0]:[t.layout.plotWidth];e.beginPath();for(let n of l){let i=T(n,1,r);e.moveTo(i,0),e.lineTo(i,t.layout.height)}w(e,a.border,1),e.stroke()}function kr(e,t,n,r,i){let a=t.layout.timeAxis;if(!a)return;let{theme:o}=n,s=T(a.y,1,r);e.beginPath(),e.moveTo(a.x,s),e.lineTo(a.x+a.width,s),w(e,o.border,1),e.stroke(),e.save(),e.beginPath(),e.rect(0,a.y,t.layout.plotWidth,a.height),e.clip(),e.font=E(n.font.size,n.font.family),e.textAlign=`center`,e.textBaseline=`middle`;for(let n of t.timeTicks)mr(i,n)||(e.fillStyle=n.unit===`year`||n.unit===`month`||n.unit===`day`?o.text:o.textMuted,e.fillText(n.text,n.x,a.y+a.height/2));e.restore()}function Ar(e,t,n,r,i){let{separatorWidth:a,separatorColor:o,separatorHoverColor:s}=n.panes;if(a<=0)return;let c=-t.layout.leftAxisWidth;for(let l of t.layout.separators){let u=T(l.y+l.height/2,a,r);e.beginPath(),e.moveTo(c,u),e.lineTo(c+t.layout.width,u),w(e,l.above===i?s??n.theme.crosshair:o??n.theme.border,a),e.stroke()}}function jr(e,t,n,r){let i=t.latest;if(!i||!n.latestPrice.line||!Number.isFinite(i.y))return;let{plot:a}=t.main;if(i.y<0||i.y>a.height)return;let o=T(a.y+i.y,1,r);e.beginPath(),e.moveTo(a.x,o),e.lineTo(a.x+a.width,o),w(e,i.color,1,n.latestPrice.style),e.stroke()}function Mr(e,t,n,r,i,a,o,s){e.fillStyle=n.theme.background,e.fillRect(-t.layout.leftAxisWidth,0,t.layout.width,t.layout.height),Dr(e,t,n,r);for(let n of t.panes){let{plot:t}=n;vn(e,()=>{e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip(),e.translate(t.x,t.y),a(e,n,`below`);for(let t of n.jobs)br(e,t,n,r,i);a(e,n,`above`)})}jr(e,t,n,r),Ar(e,t,n,r,o),Or(e,t,n,r,s),kr(e,t,n,r,s)}function Nr(e,t,n,r,i,a){let{timeAxis:o}=t.layout,s=t.panes.flatMap(e=>e.left?[e.axis,e.left.axis]:[e.axis]);vn(e,()=>{e.beginPath();for(let t of o?[...s,o]:s)e.rect(t.x,t.y,t.width,t.height);e.clip(),e.fillStyle=n.theme.background,e.fillRect(-t.layout.leftAxisWidth,0,t.layout.width,t.layout.height),Ar(e,t,n,r,i),Or(e,t,n,r,a),kr(e,t,n,r,a)})}var Pr=class{view;run;handle=0;pending=/* @__PURE__ */ new Set;tasks=[];running=!1;constructor(e,t){this.view=e,this.run=t}request(...e){e.forEach(e=>this.pending.add(e)),this.pending.size>0&&this.schedule()}beforePaint(e){this.tasks.push(e),this.schedule()}flush(){this.handle!==0&&(this.view.cancelAnimationFrame(this.handle),this.handle=0);let e=this.tasks;this.tasks=[],this.running=!0;try{r(e)}finally{this.running=!1,this.tasks.length>0&&this.schedule(),this.paint()}}schedule(){this.handle===0&&!this.running&&(this.handle=this.view.requestAnimationFrame(()=>{this.handle=0,this.flush()}))}paint(){if(this.pending.size===0)return;let e=this.pending;this.pending=/* @__PURE__ */ new Set,this.run(e)}destroy(){this.handle!==0&&(this.view.cancelAnimationFrame(this.handle),this.handle=0),this.pending.clear(),this.tasks=[]}};let Fr=[`scene`,`objects`,`cursor`];var Ir=class{view;container;maxPixelRatio;onChange;root;layers;cssWidth=0;cssHeight=0;ratio=1;resizeObserver=null;pixelRatioQuery=null;constructor(e,t,r,i){this.view=e,this.container=t,this.maxPixelRatio=r,this.onChange=i;let a=t.ownerDocument;this.root=a.createElement(`div`),this.root.tabIndex=0,this.root.setAttribute(`role`,`img`),this.root.setAttribute(`aria-label`,`Trading chart`),Object.assign(this.root.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,outline:`none`,touchAction:`none`,userSelect:`none`,webkitUserSelect:`none`,webkitTapHighlightColor:`transparent`});let o=Fr.map(e=>{let t=a.createElement(`canvas`);t.dataset.layer=e,Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,pointerEvents:`none`});let r=t.getContext(`2d`)??n(`The browser does not provide a 2D canvas context.`);return this.root.appendChild(t),[e,{canvas:t,ctx:r}]});this.layers=Object.fromEntries(o),t.appendChild(this.root)}get width(){return this.cssWidth}get height(){return this.cssHeight}get pixelRatio(){return this.ratio}context(e){return this.layers[e].ctx}canvas(e){return this.layers[e].canvas}setMaxPixelRatio(e){return this.maxPixelRatio=e,this.resize(this.cssWidth,this.cssHeight)}measureContainer(){return{width:this.container.clientWidth,height:this.container.clientHeight}}setAutoSize(e){if(this.resizeObserver?.disconnect(),this.resizeObserver=null,e){let e=new this.view.ResizeObserver(e=>{let t=e.at(-1)?.contentRect;t&&this.resize(t.width,t.height)&&this.onChange()});e.observe(this.container),this.resizeObserver=e}}watchPixelRatio(){this.pixelRatioQuery?.removeEventListener(`change`,this.handlePixelRatioChange),this.pixelRatioQuery=this.view.matchMedia(`(resolution: ${this.view.devicePixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.handlePixelRatioChange)}handlePixelRatioChange=()=>{this.watchPixelRatio(),this.resize(this.cssWidth,this.cssHeight)&&this.onChange()};resize(e,t){let n=Math.min(this.maxPixelRatio,Math.max(1,this.view.devicePixelRatio)),r=Math.round(Math.max(0,e)*n),i=Math.round(Math.max(0,t)*n),a=r/n,o=i/n;if(a===this.cssWidth&&o===this.cssHeight&&n===this.ratio)return!1;this.cssWidth=a,this.cssHeight=o,this.ratio=n;for(let e of Fr){let{canvas:t}=this.layers[e];t.width=r,t.height=i,t.style.width=`${a}px`,t.style.height=`${o}px`}return!0}begin(e,t=0){let{canvas:n,ctx:r}=this.layers[e];return r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,n.width,n.height),this.over(e,t)}over(e,t=0){let{ctx:n}=this.layers[e];return n.setTransform(this.ratio,0,0,this.ratio,this.ratio*t,0),n}composite(){let e=this.container.ownerDocument.createElement(`canvas`);if(e.width=this.layers.scene.canvas.width,e.height=this.layers.scene.canvas.height,e.width===0||e.height===0)return e;let t=e.getContext(`2d`)??n(`The browser does not provide a 2D canvas context.`);for(let e of Fr)t.drawImage(this.layers[e].canvas,0,0);return e}destroy(){this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.handlePixelRatioChange),this.root.remove()}},Lr=class{settings;width=0;count=0;spacing;offset;following=!0;pending=null;constructor(e,t){this.settings=e,this.spacing=jn(t,e.minBarSpacing,e.maxBarSpacing),this.offset=this.realTimeOffset()}get barSpacing(){return this.spacing}get plotWidth(){return this.width}configure(e){let t=this.isRealTime();this.settings=e,this.spacing=jn(this.spacing,e.minBarSpacing,e.maxBarSpacing),t&&(this.offset=this.realTimeOffset()),this.constrain()}setWidth(e){this.width=Math.max(0,e),this.constrain(),this.width>0&&this.pending?.()}settle(){this.width>0&&(this.pending=null)}rightEdge(){return this.count-1+this.offset}indexToX(e){return this.width-(this.rightEdge()-e)*this.spacing}xToIndex(e){return this.rightEdge()-(this.width-e)/this.spacing}logicalRange(){let e=this.rightEdge();return{from:e-this.width/this.spacing,to:e}}visibleBars(){if(this.count===0||this.width===0)return null;let e=this.logicalRange(),t=Math.max(0,Math.floor(e.from+.5)),n=Math.min(this.count-1,Math.ceil(e.to-.5));return t<=n?{from:t,to:n}:null}isFollowing(){return this.following}isRealTime(){return Math.abs(this.offset-this.realTimeOffset())<1e-6}setBarCount(e,t){let n=this.count;this.count=e,t===`reset`||t===`replace`&&n===0?(this.offset=this.realTimeOffset(),this.following=!0):t===`tail`&&e>n&&!this.following&&n>0&&(this.offset-=e-n),this.constrain()}scrollBy(e){this.pending=null,this.offset-=e/this.spacing,this.viewChanged()}scrollToRealTime(){this.pending=null,this.offset=this.realTimeOffset(),this.constrain(),this.following=!0}placeRightEdge(e){this.pending=null,this.placeIndexAt(e,this.width)}scrollToIndex(e,t){this.sized(()=>{let n=t===`left`?this.spacing/2:t===`right`?this.width-this.spacing/2:this.width/2;this.placeIndexAt(e,n)})}zoomAnchor(e){return this.following&&this.count>0?Math.min(this.indexToX(this.count-1),this.width):e??this.width/2}zoom(e,t){this.pending=null;let n=jn(this.spacing*e,this.settings.minBarSpacing,this.settings.maxBarSpacing);if(n!==this.spacing){let e=this.xToIndex(t);this.spacing=n,this.placeIndexAt(e,t)}}setBarSpacing(e){this.pending=null;let t=this.isRealTime(),n=this.width,r=this.xToIndex(n);this.spacing=jn(e,this.settings.minBarSpacing,this.settings.maxBarSpacing),t?(this.offset=this.realTimeOffset(),this.constrain(),this.following=!0):this.placeIndexAt(r,n)}reset(e){this.setBarSpacing(e),this.scrollToRealTime()}setLogicalRange(e){let t=e.to-e.from;t>0&&this.sized(()=>{this.spacing=jn(this.width/t,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=(e.from+e.to)/2+this.width/this.spacing/2-(this.count-1),this.viewChanged()})}fitContent(){this.sized(()=>{if(this.count===0)return;let e=Math.max(1,this.width-this.settings.rightOffset);this.spacing=jn(e/this.count,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=this.realTimeOffset(),this.constrain(),this.following=!0})}state(){return{barSpacing:this.spacing,offset:this.offset}}restore(e){this.pending=null,this.spacing=jn(e.barSpacing,this.settings.minBarSpacing,this.settings.maxBarSpacing),this.offset=e.offset,this.viewChanged()}sized(e){this.pending=null,this.width>0?e():this.pending=e}placeIndexAt(e,t){this.offset=e+(this.width-t)/this.spacing-(this.count-1),this.viewChanged()}viewChanged(){if(this.constrain(),this.width>0&&this.count>0){let e=this.visibleBars();this.following=e!==null&&e.to===this.count-1}}realTimeOffset(){return .5+this.settings.rightOffset/this.spacing}constrain(){if(this.count===0||this.width===0)return;let e=Math.min(2,this.count),t=this.width/this.spacing,n=e-.5-(this.count-1),r=Math.max(n,t+.5-e);this.offset=jn(this.offset,n,r)}},Rr=class{kind;hint;definitions=/* @__PURE__ */ new Map;fixed;constructor(e,t=[],n=``){this.kind=e,this.hint=n,t.forEach(e=>{this.register(e)}),this.fixed=new Set(t.map(e=>e.type))}register(e){h(`${this.kind} definition`,e);let t=p(`${this.kind} definition type`,e.type);this.definitions.has(t)&&n(`A ${this.kind} "${t}" is already registered.`),this.definitions.set(t,e)}unregister(e){p(this.kind,e),this.fixed.has(e)&&n(`"${e}" is a ${this.kind} of every chart and cannot be unregistered.`),this.require(e),this.definitions.delete(e)}get(e){return this.definitions.get(e)}require(e){return this.definitions.get(e)??n(`Unknown ${this.kind} "${e}".${this.hint?` ${this.hint}`:``}`)}types(){return[...this.definitions.keys()]}};function zr(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Map;for(let a=0;a<e.count;a+=1){let o=e.isUp(a),s=e.color(a);if(s===null){(o?t:n).push(a);continue}let c=i.get(s);c||(c={},i.set(s,c));let l=o?c.rising:c.falling;l||(l=[],c[o?`rising`:`falling`]=l,r.push({up:o,color:s,indices:l})),l.push(a)}return[{up:!0,color:null,indices:t},{up:!1,color:null,indices:n},...r]}function Br(e,t){let{ctx:n,points:r,style:i,pixelRatio:a,barSpacing:o}=e,s=Math.max(1/a,_n(o*i.bodyRatio,a)),c=s*a<3,l=1/a;n.setLineDash([]);for(let e of zr(r)){let{up:o,color:u}=e,d=u??(o?i.upColor:i.downColor),f=!(t&&o);if(i.wick||c){n.beginPath();for(let t of e.indices){let e=T(r.x(t),1,a);n.moveTo(e,r.high(t)),n.lineTo(e,r.low(t))}n.strokeStyle=c||u!==null?d:o?i.upWickColor:i.downWickColor,n.lineWidth=l,n.stroke()}if(!c){n.beginPath();for(let t of e.indices){let e=r.open(t),i=r.close(t);n.rect(_n(r.x(t)-s/2,a),_n(Math.min(e,i),a),s,Math.max(l,_n(Math.abs(i-e),a)))}f&&(n.fillStyle=d,n.fill()),(i.border||!f)&&(n.save(),n.clip(),n.strokeStyle=f&&u===null?o?i.upBorderColor:i.downBorderColor:d,n.lineWidth=2*Math.max(l,_n(1,a)),n.stroke(),n.restore())}}}function Vr(e,t){return{upColor:e,downColor:t,upWickColor:e,downWickColor:t,upBorderColor:e,downBorderColor:t,wick:!0,border:!1,bodyRatio:.72}}let Hr={type:`candles`,input:`ohlc`,defaultStyle:e=>Vr(e.up,e.down),paint:e=>{Br(e,!1)}},Ur={type:`hollow-candles`,input:`ohlc`,defaultStyle:e=>Vr(e.up,e.down),paint:e=>{Br(e,!0)}},Wr={type:`ohlc`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:1,ticks:!0}),paint:({ctx:e,points:t,style:n,pixelRatio:r,barSpacing:i})=>{let a=Math.max(1,Math.min(i*.4,8)),o=n.ticks&&i>=3;e.lineWidth=n.lineWidth,e.setLineDash([]);for(let i of zr(t)){e.beginPath();for(let s of i.indices){let i=T(t.x(s),n.lineWidth,r);if(e.moveTo(i,t.high(s)),e.lineTo(i,t.low(s)),o){let o=T(t.open(s),n.lineWidth,r),c=T(t.close(s),n.lineWidth,r);e.moveTo(i-a,o),e.lineTo(i,o),e.moveTo(i,c),e.lineTo(i+a,c)}}e.strokeStyle=i.color??(i.up?n.upColor:n.downColor),e.stroke()}}},Gr={type:`high-low`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:2}),paint:({ctx:e,points:t,style:n,pixelRatio:r})=>{e.lineWidth=n.lineWidth,e.lineCap=`butt`,e.setLineDash([]);for(let i of zr(t)){e.beginPath();for(let a of i.indices){let i=T(t.x(a),n.lineWidth,r);e.moveTo(i,t.high(a)),e.lineTo(i,t.low(a))}e.strokeStyle=i.color??(i.up?n.upColor:n.downColor),e.stroke()}}};function Kr(e,t,n,r=!1){if(r){qr(e,t,n);return}let i=!1,a=NaN,o=0,s=0,c=0,l=0,u=0,d=0,f=0,p=()=>{f>1&&(s<l?(e.lineTo(s,o),e.lineTo(l,c)):(e.lineTo(l,c),e.lineTo(s,o)),e.lineTo(u,d)),f=0};for(let r=0;r<t.count;r+=1){let m=n(r);if(Number.isNaN(m)){p(),i=!1;continue}let h=t.x(r),g=Math.floor(h);i&&g===a?(m<o&&(o=m,s=h),m>c&&(c=m,l=h),u=h,d=m,f+=1):(p(),i?e.lineTo(h,m):(e.moveTo(h,m),i=!0),a=g,o=m,s=h,c=m,l=h,u=h,d=m,f=1)}p()}function qr(e,t,n){let r=!1,i=0;for(let a=0;a<t.count;a+=1){let o=n(a);if(Number.isNaN(o)){r=!1;continue}let s=t.x(a);r?(e.lineTo(s,i),e.lineTo(s,o)):(e.moveTo(s,o),r=!0),i=o}}function Jr(e,t,n,r){let i=-1,a=n=>{i<0||(e.lineTo(t.x(n),r),e.lineTo(t.x(i),r),e.closePath(),i=-1)};for(let r=0;r<t.count;r+=1){let o=n(r);Number.isNaN(o)?a(r-1):i<0?(i=r,e.moveTo(t.x(r),o)):e.lineTo(t.x(r),o)}a(t.count-1)}function Yr(e){return{color:e,lineWidth:2,lineStyle:`solid`}}function Xr(e,t,n,r){e.beginPath(),Kr(e,t,e=>t.value(e),r),w(e,n.color,n.lineWidth,n.lineStyle),e.lineJoin=`round`,e.lineCap=`round`,e.stroke()}let Zr={type:`line`,input:`value`,defaultStyle:(e,t)=>Yr(t),paint:({ctx:e,points:t,style:n})=>{Xr(e,t,n,!1)}},Qr={type:`step-line`,input:`value`,defaultStyle:(e,t)=>Yr(t),paint:({ctx:e,points:t,style:n})=>{Xr(e,t,n,!0)}},$r={type:`line-markers`,input:`value`,defaultStyle:(e,t)=>({...Yr(t),markerRadius:3}),paint:({ctx:e,points:t,style:n})=>{Xr(e,t,n,!1),e.beginPath();for(let r=0;r<t.count;r+=1){let i=t.value(r);Number.isNaN(i)||(e.moveTo(t.x(r)+n.markerRadius,i),e.arc(t.x(r),i,n.markerRadius,0,Math.PI*2))}e.fillStyle=n.color,e.fill()}},ei={type:`area`,input:`value`,defaultStyle:(e,t)=>({lineColor:t,lineWidth:2,topColor:C(t,.4),bottomColor:C(t,0)}),paint:({ctx:e,points:t,style:n,height:r})=>{let i=e.createLinearGradient(0,0,0,r);i.addColorStop(0,n.topColor),i.addColorStop(1,n.bottomColor),e.beginPath(),Jr(e,t,e=>t.value(e),r),e.fillStyle=i,e.fill(),Xr(e,t,{color:n.lineColor,lineWidth:n.lineWidth,lineStyle:`solid`},!1)}},ti={type:`baseline`,input:`value`,defaultStyle:e=>({baseValue:null,lineWidth:2,topLineColor:e.up,topFillColor:C(e.up,.22),bottomLineColor:e.down,bottomFillColor:C(e.down,.22)}),paint:({ctx:e,points:t,style:n,width:r,height:i,valueToY:a})=>{let o=n.baseValue===null?NaN:a(n.baseValue);for(let e=0;Number.isNaN(o)&&e<t.count;e+=1)o=t.value(e);if(Number.isNaN(o))return;let s=[{top:0,bottom:o,line:n.topLineColor,fill:n.topFillColor},{top:o,bottom:i,line:n.bottomLineColor,fill:n.bottomFillColor}];for(let i of s)e.save(),e.beginPath(),e.rect(0,i.top,r,i.bottom-i.top),e.clip(),e.beginPath(),Jr(e,t,e=>t.value(e),o),e.fillStyle=i.fill,e.fill(),Xr(e,t,{color:i.line,lineWidth:n.lineWidth,lineStyle:`solid`},!1),e.restore()}},ni=`#00bcd4`,ri=`#e91e63`,ii={type:`hlc-area`,input:`ohlc`,defaultStyle:(e,t)=>({highColor:ni,lowColor:ri,closeColor:t,highFillColor:C(ni,.25),lowFillColor:C(ri,.25),lineWidth:1.5}),paint:({ctx:e,points:t,style:n})=>{let r=[{color:n.highFillColor,edge:e=>t.high(e)},{color:n.lowFillColor,edge:e=>t.low(e)}];for(let n of r){e.beginPath(),Kr(e,t,n.edge);for(let n=t.count-1;n>=0;--n)e.lineTo(t.x(n),t.close(n));e.closePath(),e.fillStyle=n.color,e.fill()}let i=[{color:n.highColor,read:e=>t.high(e)},{color:n.lowColor,read:e=>t.low(e)},{color:n.closeColor,read:e=>t.close(e)}];for(let r of i)e.beginPath(),Kr(e,t,r.read),w(e,r.color,n.lineWidth),e.stroke()}},ai={type:`columns`,input:`value`,defaultStyle:e=>({upColor:e.volumeUp,downColor:e.volumeDown,base:0,widthRatio:.72}),extraExtents:e=>e.base===null?[]:[e.base],paint:({ctx:e,points:t,style:n,pixelRatio:r,barSpacing:i,height:a,valueToY:o})=>{let s=n.base===null?NaN:o(n.base),c=Number.isFinite(s)?s:a,l=Math.max(1/r,Math.round(i*n.widthRatio*r)/r);for(let i of[!0,!1]){e.fillStyle=i?n.upColor:n.downColor;for(let n=0;n<t.count;n+=1){let a=t.value(n);if(t.isUp(n)===i&&!Number.isNaN(a)){let i=Math.round((t.x(n)-l/2)*r)/r;e.fillRect(i,Math.min(a,c),l,Math.max(1/r,Math.abs(c-a)))}}}}};function oi(){return new Rr(`series type`,[Hr,Ur,Wr,Gr,Zr,Qr,$r,ei,ti,ii,ai],`Register it with chart.series.register().`)}let si={kind:`idle`};var ci=class{view;scroll;velocity=0;time=0;frame=0;constructor(e,t){this.view=e,this.scroll=t}start(e,t){let n=e[0],r=e[e.length-1];if(!n||!r||t-r.time>80)return;let i=r.time-n.time,a=i>0?(r.x-n.x)/i:0;if(Math.abs(a)<.15)return;this.velocity=a,this.time=performance.now();let o=e=>{let t=Math.max(0,e-this.time);this.time=e,this.velocity*=Math.exp(-t/325),this.frame=Math.abs(this.velocity)<.02?0:this.scroll(this.velocity*t)?this.view.requestAnimationFrame(o):0};this.frame=this.view.requestAnimationFrame(o)}stop(){this.frame!==0&&(this.view.cancelAnimationFrame(this.frame),this.frame=0)}};let li=1.15;function ui(e,t,n,r){let i=(e.metaKey||e.ctrlKey)&&!e.altKey,a=e.key,o=a.toLowerCase(),s=t.plotWidth();if(a===`Escape`)return n?(r(),!0):t.command(`escape`);if(n)return!1;if(i&&o===`z`)return t.command(e.shiftKey?`redo`:`undo`);if(i&&!e.shiftKey&&o===`y`)return t.command(`redo`);if(i&&(o===`c`||o===`v`))return t.command(o===`c`?`copy`:`paste`);if(e.metaKey||e.ctrlKey||e.altKey)return!1;if(a===`Delete`||a===`Backspace`)return t.command(`delete`);if(a===`Enter`)return t.command(`enter`);if(a===`ArrowLeft`||a===`ArrowRight`)t.scrollTime((e.shiftKey?s/2:s/20)*(a===`ArrowLeft`?1:-1));else if(a===`ArrowUp`||a===`+`||a===`=`)t.zoomTime(li,null);else if(a===`ArrowDown`||a===`-`)t.zoomTime(1/li,null);else if(a===`End`)t.scrollToRealTime();else return!1;return!0}function di(e,t){let n=Math.abs(e.x-t.x);return n>=40?n:null}var fi=class{span;center;constructor(e,t){this.span=di(e,t),this.center=(e.x+t.x)/2}move(e,t,n){let r=di(e,t),i=(e.x+t.x)/2;n.scrollTime(i-this.center),r!==null&&this.span!==null&&n.zoomTime(r/this.span,i),this.span=r,this.center=i}};let pi={shift:!1,alt:!1,command:!1},mi=.0018,hi=.006,gi=/* @__PURE__ */ new Set([`Shift`,`Alt`,`Control`,`Meta`]);function _i(e){return{shift:e.shiftKey,alt:e.altKey,command:e.ctrlKey||e.metaKey}}function vi(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function yi(e,t){let n=e.deltaMode===1?16:e.deltaMode===2?t:1;return{x:e.deltaX*n,y:e.deltaY*n}}var bi=class{host;view;gesture=si;touches=/* @__PURE__ */ new Map;hoverPoint=null;hoverPending=!1;wheel={x:0,y:0,pinch:0,point:{x:0,y:0},pending:!1};kinetic;longPressTimer=0;modifiers=pi;lastPoint=null;root;constructor(e,t){this.host=e,this.view=t,this.root=e.root,this.kinetic=new ci(t,t=>e.scrollTime(t)),this.root.addEventListener(`pointerdown`,this.onPointerDown),this.root.addEventListener(`pointermove`,this.onPointerMove),this.root.addEventListener(`pointerup`,this.onPointerUp),this.root.addEventListener(`pointercancel`,this.onPointerCancel),this.root.addEventListener(`lostpointercapture`,this.onPointerCancel),this.root.addEventListener(`pointerleave`,this.onPointerLeave),this.root.addEventListener(`wheel`,this.onWheel,{passive:!1}),this.root.addEventListener(`dblclick`,this.onDoubleClick),this.root.addEventListener(`contextmenu`,this.onContextMenu),this.root.addEventListener(`keydown`,this.onKeyDown),this.root.addEventListener(`keyup`,this.onKeyUp),this.view.addEventListener(`blur`,this.onWindowBlur)}destroy(){try{this.cancelGesture()}finally{this.stopListening()}}stopListening(){this.kinetic.stop(),this.root.removeEventListener(`pointerdown`,this.onPointerDown),this.root.removeEventListener(`pointermove`,this.onPointerMove),this.root.removeEventListener(`pointerup`,this.onPointerUp),this.root.removeEventListener(`pointercancel`,this.onPointerCancel),this.root.removeEventListener(`lostpointercapture`,this.onPointerCancel),this.root.removeEventListener(`pointerleave`,this.onPointerLeave),this.root.removeEventListener(`wheel`,this.onWheel),this.root.removeEventListener(`dblclick`,this.onDoubleClick),this.root.removeEventListener(`contextmenu`,this.onContextMenu),this.root.removeEventListener(`keydown`,this.onKeyDown),this.root.removeEventListener(`keyup`,this.onKeyUp),this.view.removeEventListener(`blur`,this.onWindowBlur)}cancelGesture(){let e=this.gesture;this.clearLongPress(),this.gesture=si,e.kind===`drag`||e.kind===`separator`?e.session.cancel():e.kind===`touch-crosshair`?this.host.setPointer(null):e.kind===`tool`&&this.host.activeTool()?.cancelPress(),this.host.magnify(null),this.host.hoverSeparator(null),this.updateCursor(null,null)}local(e){let t=this.root.getBoundingClientRect();return{x:e.clientX-t.left-this.host.originX(),y:e.clientY-t.top}}onPointerDown=e=>{if(e.pointerType===`mouse`&&e.button!==0)return;this.kinetic.stop(),this.root.focus({preventScroll:!0});let t=this.local(e);this.track(e,t);let n=e.pointerType===`touch`;if(n){if(this.touches.set(e.pointerId,t),this.touches.size===2){this.startPinch();return}if(this.touches.size>2)return}if(this.gesture.kind!==`idle`)return;e.isTrusted&&this.root.setPointerCapture(e.pointerId);let r=this.host.activeTool(),i=this.host.regionAt(t);r&&i.kind===`plot`?(this.gesture={kind:`tool`,pointerId:e.pointerId,touch:n},r.pointerDown(t,this.modifiers,n),n&&this.host.magnify(t)):this.startPress(e.pointerId,n,t,i)};startPress(e,t,n,r){if(r.kind===`separator`){this.host.setPointer(null),this.host.hoverSeparator(r.above),this.gesture={kind:`separator`,pointerId:e,startY:n.y,session:this.host.beginPaneResize(r.above,r.below)};return}if(r.kind===`time-axis`&&this.host.enabled(`axisScale`)){this.gesture={kind:`time-axis`,pointerId:e,startX:n.x,lastX:n.x};return}if(r.kind===`price-axis`&&this.host.enabled(`axisScale`)){if(!this.host.scalesPrice(r.paneId,r.scale))return;this.gesture={kind:`price-axis`,pointerId:e,paneId:r.paneId,scale:r.scale,anchorY:n.y,lastY:n.y};return}let i=r.kind===`plot`?this.host.legendAt(n):null;if(i?.button){this.gesture={kind:`legend`,pointerId:e,hit:i};return}let a=r.kind===`plot`?this.host.hitTest(n):null;this.gesture={kind:`pressed`,pointerId:e,touch:t,start:n,region:r,target:a},t&&!a&&(this.longPressTimer=this.view.setTimeout(()=>{this.longPressTimer=0,this.gesture.kind===`pressed`&&this.gesture.pointerId===e&&(this.gesture={kind:`touch-crosshair`,pointerId:e},this.host.setPointer(n))},this.host.longPressMs()))}onPointerMove=e=>{let t=this.local(e);this.track(e,t);let n=this.gesture;if(e.pointerType===`touch`&&this.touches.has(e.pointerId)&&(this.touches.set(e.pointerId,t),n.kind===`pinch`))this.movePinch();else switch(n.kind){case`idle`:e.pointerType!==`touch`&&this.scheduleHover(t),this.host.activeTool()?.pointerMove(t,this.modifiers);return;case`tool`:e.pointerId===n.pointerId&&(this.host.activeTool()?.pointerMove(t,this.modifiers),this.host.setPointer(t),n.touch&&this.host.magnify(t));return;case`pressed`:e.pointerId===n.pointerId&&this.movePressed(n,t);return;case`pan`:e.pointerId===n.pointerId&&this.movePan(n,t,e.timeStamp);return;case`drag`:e.pointerId===n.pointerId&&(n.session.move(t,this.modifiers),n.touch?this.host.magnify(t):this.host.setPointer(t));return;case`time-axis`:e.pointerId===n.pointerId&&(this.host.zoomTime(Math.exp((t.x-n.lastX)*hi),n.startX),n.lastX=t.x);return;case`price-axis`:e.pointerId===n.pointerId&&(this.host.zoomPrice(n.paneId,n.scale,Math.exp((n.lastY-t.y)*hi),n.anchorY),n.lastY=t.y);return;case`separator`:e.pointerId===n.pointerId&&n.session.move(t.y-n.startY);return;case`touch-crosshair`:e.pointerId===n.pointerId&&this.host.setPointer(t);return;case`pinch`:case`legend`:return}};movePressed(e,t){if(vi(t,e.start)<(e.touch?8:3))return;this.clearLongPress();let n=e.target;if(n?.draggable){let r=this.host.beginDrag(n,e.start,this.modifiers);if(r){this.gesture={kind:`drag`,pointerId:e.pointerId,touch:e.touch,session:r},r.move(t,this.modifiers),this.updateCursor(n,null),e.touch&&this.host.magnify(t);return}}if(e.region.kind!==`plot`||!this.host.enabled(`pan`)){this.gesture=si;return}let r={kind:`pan`,pointerId:e.pointerId,touch:e.touch,paneId:e.region.paneId,last:e.start,samples:[]};this.gesture=r,this.root.style.cursor=`grabbing`,this.showTooltip(null),this.movePan(r,t,performance.now())}movePan(e,t,n){let r=t.x-e.last.x,i=t.y-e.last.y;for(e.last=t,this.host.scrollTime(r),e.paneId!==null&&!this.host.isAutoScale(e.paneId)&&this.host.panPrice(e.paneId,i),e.samples.push({x:t.x,time:n});e.samples.length>2&&n-(e.samples[0]?.time??n)>80;)e.samples.shift();e.touch||this.host.setPointer(t)}onPointerUp=e=>{let t=this.local(e);this.track(e,t),this.touches.delete(e.pointerId);let n=this.gesture;if(n.kind===`pinch`)this.endPinch();else if(!(`pointerId`in n&&n.pointerId!==e.pointerId)){switch(this.clearLongPress(),this.gesture=si,n.kind){case`pressed`:this.host.click(t,n.target);break;case`tool`:this.host.activeTool()?.pointerUp(t,this.modifiers,n.touch);break;case`pan`:this.host.enabled(`kineticScroll`)&&this.kinetic.start(n.samples,e.timeStamp);break;case`drag`:n.session.end();break;case`legend`:{let e=this.host.legendAt(t);e?.button===n.hit.button&&e.item.id===n.hit.item.id&&this.host.clickLegend(e);break}case`separator`:{n.session.end();let e=this.host.regionAt(t);this.host.hoverSeparator(e.kind===`separator`?e.above:null);break}}e.pointerType===`touch`&&(this.host.setPointer(null),this.host.magnify(null)),this.updateCursor(null,e.pointerType===`touch`?null:t)}};onPointerCancel=e=>{this.touches.delete(e.pointerId),`pointerId`in this.gesture&&this.gesture.pointerId===e.pointerId?this.cancelGesture():this.gesture.kind===`pinch`&&this.endPinch()};onPointerLeave=e=>{e.pointerType!==`touch`&&this.gesture.kind===`idle`&&(this.hoverPoint=null,this.host.hover(null),this.host.hoverSeparator(null),this.host.hoverLegend(null),this.host.setPointer(null))};onWindowBlur=()=>{this.cancelGesture()};scheduleHover(e){let t=this.host.regionAt(e);this.host.setPointer(t.kind===`separator`?null:e),this.hoverPoint=e,this.hoverPending||(this.hoverPending=!0,this.host.beforePaint(()=>{this.hoverPending=!1;let e=this.hoverPoint;if(e&&this.gesture.kind===`idle`){let t=this.host.regionAt(e);this.host.hoverSeparator(t.kind===`separator`?t.above:null);let n=t.kind===`plot`&&!this.host.activeTool()?this.host.hitTest(e):null;this.host.hover(n);let r=t.kind===`plot`?this.host.legendAt(e):null;this.host.hoverLegend(r),this.updateCursor(n,e),r?.button&&(this.root.style.cursor=`pointer`)}}))}showTooltip(e){e===null?this.root.removeAttribute(`title`):this.root.getAttribute(`title`)!==e&&this.root.setAttribute(`title`,e)}updateCursor(e,t){if(this.showTooltip(this.gesture.kind===`idle`?e?.tooltip??null:null),e){this.root.style.cursor=e.cursor;return}if(!t){this.root.style.cursor=``;return}let n=this.host.regionAt(t),r=this.host.enabled(`axisScale`);this.root.style.cursor=n.kind===`separator`?`row-resize`:n.kind===`price-axis`&&r&&this.host.scalesPrice(n.paneId,n.scale)?`ns-resize`:n.kind===`time-axis`&&r?`ew-resize`:n.kind===`plot`?`crosshair`:``}fingers(){let[e,t]=[...this.touches.values()];return e&&t?[e,t]:null}startPinch(){this.cancelGesture();let e=this.fingers();e&&this.host.enabled(`pinchZoom`)&&(this.gesture={kind:`pinch`,pinch:new fi(...e)})}movePinch(){let e=this.gesture,t=this.fingers();e.kind===`pinch`&&t&&e.pinch.move(...t,this.host)}endPinch(){let e=this.fingers();if(e){this.gesture={kind:`pinch`,pinch:new fi(...e)};return}let[t]=[...this.touches.entries()];this.gesture=t&&this.host.enabled(`pan`)?{kind:`pan`,pointerId:t[0],touch:!0,paneId:null,last:t[1],samples:[]}:si}clearLongPress(){this.longPressTimer!==0&&(this.view.clearTimeout(this.longPressTimer),this.longPressTimer=0)}onWheel=e=>{if(!this.host.enabled(`wheelZoom`))return;e.preventDefault(),this.kinetic.stop();let t=yi(e,this.root.clientHeight);e.ctrlKey?this.wheel.pinch+=t.y:(this.wheel.x+=t.x,this.wheel.y+=e.shiftKey?0:t.y,this.wheel.x+=e.shiftKey?t.y:0),this.wheel.point=this.local(e),this.wheel.pending||(this.wheel.pending=!0,this.host.beforePaint(()=>{this.wheel.pending=!1,this.applyWheel()}))};applyWheel(){let{x:e,y:t,pinch:n,point:r}=this.wheel;this.wheel.x=0,this.wheel.y=0,this.wheel.pinch=0;let i=this.host.regionAt(r);if(i.kind===`price-axis`){if(!this.host.scalesPrice(i.paneId,i.scale))return;this.host.zoomPrice(i.paneId,i.scale,Math.exp(-(t+n)*mi),r.y),this.followPointer()}else n!==0&&this.host.zoomTime(Math.exp(-n*.012),r.x),Math.abs(e)>Math.abs(t)?this.host.scrollTime(-e):t!==0&&this.host.zoomTime(Math.exp(-t*mi),r.x),this.lastPoint||this.host.setPointer(r),this.followPointer()}onDoubleClick=e=>{let t=this.local(e),n=this.host.activeTool();if(n){n.doubleClick(t);return}let r=this.host.regionAt(t),i=r.kind===`plot`?this.host.hitTest(t):null;(!i||!this.host.editObject(i))&&this.host.doubleClick(t,r)};onContextMenu=e=>{let t=this.local(e),n=this.host.regionAt(t).kind===`plot`?this.host.hitTest(t):null;this.host.contextMenu(t,n,e)&&e.preventDefault()};track(e,t){this.modifiers=_i(e),this.lastPoint=t}onKeyUp=e=>{this.refreshModifiers(e)};refreshModifiers(e){gi.has(e.key)&&this.lastPoint&&(this.modifiers=_i(e),this.followPointer())}followPointer(){let e=this.gesture;this.lastPoint&&(e.kind===`drag`?e.session.move(this.lastPoint,this.modifiers):(e.kind===`tool`||e.kind===`idle`)&&this.host.activeTool()?.pointerMove(this.lastPoint,this.modifiers))}onKeyDown=e=>{this.refreshModifiers(e),this.host.enabled(`keyboard`)&&ui(e,this.host,this.gesture.kind!==`idle`,()=>{let e=this.gesture.kind===`tool`;this.cancelGesture(),e&&this.host.command(`escape`)})&&e.preventDefault()}};function xi(e,t){return e===t||e!==null&&t!==null&&e.kind===t.kind&&e.id===t.id&&e.part===t.part}var Si=class{selected=null;hoveredTarget=null;domains=[];add(e,t){this.domains=[...this.domains,{domain:e,z:t}].sort((e,t)=>e.z-t.z)}kinds(){return this.domains.map(({domain:e})=>e.kind)}get selection(){return this.selected}get hovered(){return this.hoveredTarget}setHovered(e){return!xi(e,this.hoveredTarget)&&(this.hoveredTarget=e,!0)}select(e){let t=this.selected;return t===e||t&&e&&t.kind===e.kind&&t.id===e.id?!1:(this.selected=e,!0)}exists(e){return this.domain(e.kind)?.has(e.id)??!1}prune(){let e=!1;return this.selected&&!this.domain(this.selected.kind)?.has(this.selected.id)&&(this.selected=null,e=!0),this.hoveredTarget&&!this.domain(this.hoveredTarget.kind)?.has(this.hoveredTarget.id)&&(this.hoveredTarget=null,e=!0),e}hitTest(e,t){let n=null;for(let{domain:r}of this.domains){let i=r.hitTest(e,t);i&&(!n||this.beats(i,n))&&(n=i)}return n?.target??null}beginDrag(e,t,n,r){return this.domain(t.kind)?.beginDrag(e,t,n,r)??null}edit(e){return this.domain(e.kind)?.edit?.(e.id)??!1}reveal(e,t){return this.domain(t.kind)?.reveal?.(e,t)??null}paint(e){for(let{domain:t}of this.domains)t.paint(e)}domain(e){return this.domains.find(t=>t.domain.kind===e)?.domain}beats(e,t){if(e.priority!==t.priority)return e.priority>t.priority;let n=this.isSelected(e.target);return n===this.isSelected(t.target)?e.distance<t.distance:n}isSelected(e){return this.selected?.kind===e.kind&&this.selected.id===e.id}},Ci=class{host;timer=0;constructor(e){this.host=e}text(e){let t=this.end();return t!==null&&t>e?this.host.formatter.duration(t-e,Kt(this.host.options).days):null}sync(){let e=this.end(),t=e!==null&&e>Date.now();t&&this.timer===0?this.timer=this.host.view.setInterval(()=>{this.text(Date.now())===null?this.host.invalidate():this.host.invalidateLayers(`cursor`)},1e3):t||this.stop()}stop(){this.host.view.clearInterval(this.timer),this.timer=0}end(){let{bars:e,options:t}=this.host;if(!t.latestPrice.countdown||this.host.replaying||!this.host.timeBased||e.length===0)return null;let n=e.time(e.length-1),r=this.host.barDuration??e.interval();return this.host.barEnd(n)??(r===null?null:n+r)}};function wi(e,t){return e.panes.find(e=>t>=e.plot.y&&t<e.plot.y+e.plot.height)??null}function Ti(e,t,n,r,i=!0){let{bars:a,timeScale:o,options:s}=e;if(a.length===0||n<0||n>t.layout.plotWidth)return null;let c=Math.round(o.xToIndex(n)),l=a.timeOfLogicalIndex(c),u=a.bar(c),d=wi(t,r),f=null,p=r;return d&&(f=d.scale.yToValue(r-d.plot.y),s.crosshair.mode===`magnet`&&d.id===`main`&&u&&(f=u.close,p=d.plot.y+d.scale.valueToY(f))),{x:i?o.indexToX(c):n,y:p,paneId:d?.id??null,index:c,time:Number.isNaN(l)?null:l,price:f!==null&&Number.isFinite(f)?f:null,bar:u}}function Ei(e,t,n){let{bars:r,options:i,formatter:a}=e,o=r.bar(n);if(!o)return[];let{theme:s}=i,c=n>0?r.close(n-1):o.open,l=o.close-c,u=l>=0?s.up:s.down,d=e=>D(a,e,t.priceFormat),f=c===0?0:l/c*100,p=l>=0?`+`:``,m=Kt(i);return[{text:`${m.legendOpen} ${d(o.open)}`,color:u},{text:`${m.legendHigh} ${d(o.high)}`,color:u},{text:`${m.legendLow} ${d(o.low)}`,color:u},{text:`${m.legendClose} ${d(o.close)}`,color:u},{text:`${p}${d(l)} (${p}${a.number(f,2)}%)`,color:u},{text:`${m.legendVolume} ${a.compact(o.volume)}`,color:s.textMuted}]}function Di(e,t,n){let r=t.left,i=r?.scale.yToValue(n-t.plot.y)??NaN;return r&&Number.isFinite(i)?Vn(e,{id:t.id,scale:r.scale,format:r.format},i):null}function Oi(e,t,n,r){let{options:i,series:a,formatter:o}=e,{theme:s}=i,c=i.legend.rows??(e=>e.visible),l=[],u=(e,t)=>{let n=r?.kind===e.kind&&r.id===e.id;l.push({item:e,segments:t,buttons:n?i.legend.buttons?.(e)??[]:[],hoveredButton:n?r.button:null})};u({kind:`main`,id:`main`,type:null,paneId:x,visible:!0},Ei(e,t,n));for(let r of e.legendRows)for(let e of r(t,n))c(e.item)&&u(e.item,e.segments());let d=e.bars.time(n);return a.list().forEach((e,n)=>{let r={kind:`series`,id:e.id,type:null,paneId:e.pane,visible:e.visible};if(!c(r))return;let i=[{text:e.title,color:s.textMuted}],a=ki(e,d);a!==null&&i.push({text:D(o,a.value,Cn(e,t.priceFormat)),color:a.up===null?Ai(e,s,n):a.up?s.up:s.down}),u(r,i)}),l}function ki(e,t){let n=e.values??e.bars,r=n?n.lowerBound(t+1)-1:-1;if(r<0)return null;if(e.values){let t=e.values.value(r);return Number.isNaN(t)?null:{value:t,up:null}}let i=e.bars;return i?{value:i.close(r),up:i.close(r)>=i.open(r)}:null}function Ai(e,t,n){let r=e.style.color;return typeof r==`string`?r:Tn(t.palette,n+1)}function ji(e,t,n,r,i,a=null){let{bars:o,options:s}=e,c=n?.bar&&n.index<o.length?n.index:o.length-1;return{crosshair:r,legends:s.legend.visible&&o.length>0?Oi(e,t,c,a):[],countdown:e.countdown.text(i)}}function Mi(e,t,n){if(!n)return null;let{bars:r,formatter:i,options:a}=e,o=e.timeBased?e.barDuration??r.interval():null,s=n.paneId?t.panes.find(e=>e.id===n.paneId):void 0,c=n.time===null?null:a.timeScale.formatter?a.timeScale.formatter(n.time,{kind:`crosshair`,unit:`minute`,locale:i.locale,timeZone:i.timeZone}):i.timeCrosshair(n.time,o);return{x:n.x,y:s?n.y:null,timeText:c,priceText:s&&n.price!==null?Vn(e,s,n.price):null,priceLines:s&&n.price!==null&&a.crosshair.priceLines?a.crosshair.priceLines(n.price,s.id).filter(e=>typeof e==`string`&&e!==``):[],leftPriceText:s?.left?Di(e,s,n.y):null}}function Ni(e,t){let n=e.indexAt(t);if(n>=0&&n<e.length-1)return n;let r=e.logicalIndexOf(t);return Number.isFinite(r)?Math.floor(r+1e-9):n>=0?n:null}function Pi(e,t){if(e===null||t===null)return e===t;let n=e.bar,r=t.bar;return e.x===t.x&&e.y===t.y&&e.paneId===t.paneId&&e.index===t.index&&e.time===t.time&&e.price===t.price&&(n===null||r===null?n===r:n.time===r.time&&n.open===r.open&&n.high===r.high&&n.low===r.low&&n.close===r.close&&n.volume===r.volume)}var Fi=class{core;changed;pointer=null;external=null;dirty=!1;fromPointer=!1;frame=null;current=null;moving=!1;motionTimer=0;restingAt=null;constructor(e,t){this.core=e,this.changed=t}get value(){return this.current}setPointer(e){this.moving?this.restingAt=e:(e?.x!==this.restingAt?.x||e?.y!==this.restingAt?.y)&&(this.restingAt=null),this.pointer=e,this.external=null,this.dirty=!0,this.fromPointer=!0,this.changed()}noteMotion(){let{view:e}=this.core;this.moving=!0,this.restingAt=this.pointer,e.clearTimeout(this.motionTimer),this.motionTimer=e.setTimeout(()=>{this.motionTimer=0,this.moving=!1},150)}destroy(){this.core.view.clearTimeout(this.motionTimer)}setExternal(e){this.pointer=null,this.external=e,this.dirty=!0,this.fromPointer=!1,this.changed()}sync(e){if(!this.dirty&&e===this.frame)return;let t=this.current,n=this.locate(e);if(this.current=n,this.frame=e,this.dirty=!1,this.fromPointer&&!Pi(t,n)){let t=(n?.x??0)+e.layout.leftAxisWidth;this.core.bus.emit(`crosshairMove`,n?{visible:!0,...n,x:t}:{visible:!1})}}locate(e){let{core:t}=this;if(this.pointer){let n=!t.options.crosshair.snapToBars||this.moving||this.restingAt!==null;return Ti(t,e,this.pointer.x,this.pointer.y,!n)}if(!this.external)return null;let{time:n,price:r,paneId:i}=this.external,a=Ni(t.bars,n),o=e.panes.find(e=>e.id===i);if(a===null||!o)return null;let s=r===null?o.plot.y+o.plot.height/2:o.plot.y+o.scale.valueToY(r);return Ti(t,e,t.timeScale.indexToX(a),s)}},Ii=class{capacity;entries=/* @__PURE__ */ new Map;constructor(e){this.capacity=e}get(e){let t=this.entries.get(e);return t!==void 0&&(this.entries.delete(e),this.entries.set(e,t)),t}set(e,t){if(this.entries.delete(e),this.entries.set(e,t),this.entries.size>this.capacity){let e=this.entries.keys().next();e.done||this.entries.delete(e.value)}}getOrCreate(e,t){let n=this.get(e);if(n!==void 0)return n;let r=t();return this.set(e,r),r}clear(){this.entries.clear()}get size(){return this.entries.size}},Li=class{paths=new Ii(64);get(e){return this.paths.getOrCreate(e,()=>new Path2D(e))}};let Ri={rows:[],buttons:[]};function zi(e,t,n,r,i,a,o=`#ffffff`){if(!(r>=0&&r<=n.height)||n.width===0)return;let s=t.font.size+8,c=n.y+r-s/2;e.font=E(t.font.size,t.font.family),e.fillStyle=i,e.beginPath(),e.roundRect(n.x+1,c,n.width-2,(s-6)*a.length+6,2),e.fill(),e.fillStyle=o,e.textAlign=`left`,e.textBaseline=`middle`,a.forEach((t,r)=>{e.fillText(t,n.x+6+2,c+s/2+.5+(s-6)*r)})}function Bi(e,t,n,r){let{latest:i}=t;for(let a of nr(t,n,r!==null))if(a.mark){let t=a.mark===i?.live?n.theme.text:void 0;zi(e,n,a.axis,a.y,a.mark.color,[a.mark.text],t)}else if(i){let t=r===null?[i.text]:[i.text,r];zi(e,n,a.axis,a.y,i.color,t)}}function Vi(e,t,n,r,i){let{theme:a}=n,o=n.crosshair,s=t.layout.timeAxis?.y??t.layout.height;if(e.beginPath(),o.vertical){let t=T(i.x,1,r);e.moveTo(t,0),e.lineTo(t,s)}if(o.horizontal&&i.y!==null){let n=T(i.y,1,r);e.moveTo(0,n),e.lineTo(t.layout.plotWidth,n)}if(w(e,a.crosshair,1,o.style),e.stroke(),!o.labels)return;e.font=E(n.font.size,n.font.family);let c=n.font.size+8,l={background:a.crosshairLabelBackground,color:a.crosshairLabelText,paddingX:6,height:c};if(i.priceText!==null&&i.y!==null&&n.priceScale.visible){let r=or(t,n,i.y,i.priceLines.length);i.priceLines.length===0?yn(e,i.priceText,t.layout.plotWidth+1,r.priceY,{...l,align:`left`}):Hi(e,t,n,i.priceText,i.priceLines,r)}i.leftPriceText!==null&&i.y!==null&&n.priceScale.visible&&yn(e,i.leftPriceText,-1,i.y,{...l,align:`right`});let u=t.layout.timeAxis;if(i.timeText!==null&&u){let n=e.measureText(i.timeText).width+12,r=dr(t,i.x,n);yn(e,i.timeText,r,u.y+u.height/2,{...l,align:`center`})}}function Hi(e,t,n,r,i,a){let{theme:o}=n,s=Math.max(...[r,...i].map(t=>e.measureText(t).width))+12,c=t.layout.plotWidth+1;e.fillStyle=o.crosshairLabelBackground,e.beginPath(),e.roundRect(c,a.top,s,a.bottom-a.top,2),e.fill(),e.fillStyle=o.crosshairLabelText,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(r,c+s/2,a.priceY+.5),i.forEach((t,n)=>{e.fillText(t,c+s/2,a.lineY(n)+.5)})}function Ui(e,t,n,r,i,a){let{theme:o}=t;a&&(e.fillStyle=C(o.text,.12),e.beginPath(),e.roundRect(i.x,i.y,i.width,i.height,2),e.fill());let s=i.height-4;e.save(),e.translate(i.x+2,i.y+2),e.scale(s/24,s/24),e.strokeStyle=a?o.text:o.textMuted,e.lineWidth=2,e.lineCap=`round`,e.lineJoin=`round`,e.setLineDash([]),e.stroke(n.get(r.icon)),e.restore()}function Wi(e,t,n,r,i){e.font=E(n.font.size,n.font.family),e.textAlign=`left`,e.textBaseline=`top`;let a=n.font.size+6,o=n.font.size+5,s=/* @__PURE__ */ new Map,c=[],l=[];for(let u of r){let{item:r}=u,d=t.panes.find(e=>e.id===r.paneId);if(!d)continue;let f=d.plot.x+8,p=d.plot.x+d.plot.width-8,m=d.plot.y+d.plot.height,h=d.plot.y+6+(d.id===`main`?n.legend.top:0),g=s.get(r.paneId)??0,_=g,v=f,ee=h+_*a,y=f,te=e=>(v>f&&v+e>p&&(_+=1,v=f,ee+=a),ee+a<=m),ne=()=>{e.globalAlpha=1;for(let t of u.buttons){if(!te(o))break;let a={x:v,y:ee-2,width:o,height:o};Ui(e,n,i,t,a,u.hoveredButton===t.id),l.push({item:r,id:t.id,rect:a}),v+=o+2,y=Math.max(y,v)}v+=6},re=u.buttons.length===0?-1:r.kind===`main`?0:1,ie=re>=0&&n.legend.hideValuesOnHover?re:1/0;for(let[t,n]of u.segments.entries()){t===re&&ne();let i=e.measureText(n.text).width;if(!te(i))break;t<ie&&(e.globalAlpha=r.visible?1:.45,e.fillStyle=n.color,e.fillText(n.text,v,ee)),v+=i+8,y=Math.max(y,v-8)}re>=u.segments.length&&ne(),e.globalAlpha=1;let ae=h+g*a-2;c.push({item:r,rect:{x:f,y:ae,width:y-f,height:(_-g+1)*a}}),s.set(r.paneId,_+1)}return{rows:c,buttons:l}}function Gi(e,t,n,r,i,a){let o=n.legend.visible?Wi(e,t,n,i.legends,a):Ri;return Bi(e,t,n,i.countdown),i.crosshair&&Vi(e,t,n,r,i.crosshair),o}let Ki=(e,t)=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height;var qi=class{icons=new Li;layout={rows:[],buttons:[]};hovered=null;get hover(){return this.hovered}paint(e,t,n,r,i,a){let o=ji(t,n,r,i,Date.now(),this.hovered);this.layout=Gi(e,n,t.options,a,o,this.icons)}at(e){let t=this.layout.buttons.find(t=>Ki(t.rect,e));if(t)return{item:t.item,button:t.id};let n=this.layout.rows.find(t=>Ki(t.rect,e));return n?{item:n.item,button:null}:null}setHover(e){let t=e?{kind:e.item.kind,id:e.item.id,button:e.button}:null,n=this.hovered;return n?.kind===t?.kind&&n?.id===t?.id&&n?.button===t?.button?!1:(this.hovered=t,!0)}};let Ji={button:50,handle:40,label:30,line:20,body:10};function Yi(e,t){return e.timeScale.indexToX(e.bars.barIndexOf(t))}function Xi(e,t){return e.timeScale.indexToX(e.bars.logicalIndexOf(t))}function O(e,t){return e.panes.find(e=>e.id===t)}function Zi(e,t,n){let r=e.yToValue(n);if(t.kind===`decimal`){let e=10**t.precision;return Math.round(r*e)/e}let i=Math.abs(e.yToValue(n+1)-r);if(!Number.isFinite(i)||i===0)return r;let a=Math.floor(Math.log10(i));if(a<0){let e=10**-a;return Math.round(r*e)/e}let o=10**a;return Math.round(r/o)*o}let Qi=g({id:!0,text:!0,icon:!0,width:!0}),$i=/^\s*[Mm][\d\s,.eE+\-MmLlHhVvCcSsQqTtAaZz]*$/;function ea(e,t){if(e===void 0)return[];v(t,e);let r=/* @__PURE__ */ new Set;return e.map((e,i)=>{let a=`${t}[${i}]`;return _(a,e,Qi),p(`${a}.id`,e.id),r.has(e.id)&&n(`${t} contains the button id "${e.id}" twice.`),r.add(e.id),e.text===void 0&&e.icon===void 0&&n(`${a} needs a text or an icon.`),e.text!==void 0&&typeof e.text!=`string`&&n(`${a}.text must be a string.`),e.icon!==void 0&&(typeof e.icon!=`string`||!$i.test(e.icon))&&n(`${a}.icon must be SVG path data starting with a move command, e.g. "M6 6L18 18".`),e.width!==void 0&&d(`${a}.width`,e.width,{min:8,max:200}),{...e}})}let ta=[`left`,`center`,`right`];function na(e){return e===`pinned`||e.startsWith(`pinned:`)}function ra(e,t,n){let r=n/2,i=e.map(e=>({view:e,center:e.y})),a=-1/0;for(let e of i)e.center=Math.max(e.view.y,a+2+r),a=e.center+r;let o=t+2;for(let e of[...i].reverse())e.view.y<=t&&(e.center=Math.min(e.center,o-2-r),o=e.center-r);return i.map(e=>e.center)}function ia(e,t,n,r,i,a=!1){let o=r+8,s=o/2,c=e.filter(e=>Number.isFinite(e.y)).map(e=>{let t=a?e.y<0?`top`:e.y>n?`bottom`:null:null,r=t===`top`?s:t===`bottom`?n-s:e.y;return{view:e,pinned:t,at:a&&!t?Math.max(e.y,s):r}}).sort((e,t)=>e.at-t.at||e.view.y-t.view.y),l=[];for(let e of ta){let t=c.flatMap(({view:t},n)=>(t.align??`right`)===e?[n]:[]),r=ra(t.map(e=>{let{view:t,at:n}=c[e];return{...t,y:n}}),n,o);t.forEach((e,t)=>{l[e]=r[t]??0})}return c.map(({view:e,pinned:n},a)=>{let s=n?16:0,c=(e.text?i(e.text,r)+12:0)+s,u=e.buttons.map(e=>e.width??(e.icon?o:i(e.text??``,r)+12)),d=c+u.reduce((e,t)=>e+t,0),f=l[a]??e.y,p=e.align??`right`,m=p===`left`?8:p===`center`?(t-d)/2:t-8-d,h=f-o/2,g=m+c,_=e.buttons.map((e,t)=>{let n=u[t]??o,r={x:g,y:h,width:n,height:o};return g+=n,{button:e,rect:r}});return{view:e,labelY:f,label:{x:m,y:h,width:d,height:o},pinned:n,arrow:s,textWidth:c,buttons:_}})}function aa(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function oa(e,t,n){for(let n of e)for(let{button:e,rect:r}of n.buttons)if(aa(r,t))return{id:n.view.id,part:`button:${e.id}`,priority:Ji.button,distance:0};for(let n of e)if(aa(n.label,t)){let e=n.pinned?`pinned`:`label`;return{id:n.view.id,part:e,priority:Ji.label,distance:0}}let r=null;for(let i of e){let e=Math.abs(t.y-i.view.y);e<=n&&(!r||e<r.distance)&&(r={id:i.view.id,part:`line`,priority:Ji.line,distance:e})}return r}function sa(e,t,n,r,i,a){e.font=E(i.fontSize,i.fontFamily),e.textBaseline=`middle`;for(let o of t){let{view:t,label:s}=o,c=T(n.y+t.y,1,i.pixelRatio),l=t.emphasized?2:1;e.beginPath(),e.moveTo(n.x,c),e.lineTo(n.x+n.width,c),w(e,t.color,l,t.lineStyle),e.stroke();let u=n.y+s.y,d=n.x+s.x;if(o.labelY!==t.y&&!o.pinned&&(e.beginPath(),e.moveTo(d+s.width/2,c),e.lineTo(d+s.width/2,u),w(e,t.color,1),e.stroke()),e.fillStyle=t.color,e.beginPath(),e.roundRect(d,u,s.width,s.height,3),e.fill(),o.pinned){let t=d+o.arrow/2+1,n=u+s.height/2,r=o.pinned===`top`?-1:1;e.fillStyle=i.textColor,e.beginPath(),e.moveTo(t,n+r*4),e.lineTo(t-4,n-r*3),e.lineTo(t+4,n-r*3),e.closePath(),e.fill()}t.text&&(e.fillStyle=i.textColor,e.textAlign=`center`,e.fillText(t.text,d+o.arrow+(o.textWidth-o.arrow)/2,u+s.height/2+.5));for(let{button:t,rect:r}of o.buttons){let o=n.x+r.x;if(e.fillStyle=C(`#000000`,.18),e.fillRect(o,u,r.width,r.height),e.fillStyle=C(i.textColor,.35),e.fillRect(o,u+3,1,r.height-6),t.icon){let n=r.height-8;e.save(),e.translate(o+(r.width-n)/2,u+4),e.scale(n/24,n/24),e.strokeStyle=i.textColor,e.lineWidth=2.2,e.lineCap=`round`,e.lineJoin=`round`,e.setLineDash([]),e.stroke(a.get(t.icon)),e.restore()}else t.text&&(e.fillStyle=i.textColor,e.textAlign=`center`,e.fillText(t.text,o+r.width/2,u+r.height/2+.5))}if(i.showAxis&&t.axisText!==null&&t.y>=0&&t.y<=n.height){let a=i.fontSize+8;e.fillStyle=t.color,e.beginPath(),e.roundRect(r.x+1,n.y+t.y-a/2,r.width-2,a,2),e.fill(),e.fillStyle=i.textColor,e.textAlign=`left`,e.fillText(t.axisText,r.x+8,n.y+t.y+.5)}}}let ca={kind:`outside`};function k(e,t,n){return e.isDestroyed?n:e.run(t)}function la(e,t){return e.runCommand(t)?!0:t===`escape`&&e.objects.selection?(e.selectByUser(null),!0):!1}function ua(e,t){let n=e.objects.reveal(e.objectContext(),t),r=n&&e.shownFrame().panes.find(e=>e.id===n.pane),i=n&&e.panes.findScale(n.pane,n.scale)?.scale;if(!n||!r||!i)return;let a=i.valueToY(n.value);Number.isFinite(a)&&(i.lead.pan(r.plot.height/2-a),e.invalidate())}function da(e,t){let{layout:n}=e;for(let e of n.separators)if(t.y>=e.y-3&&t.y<=e.y+e.height+3)return{kind:`separator`,above:e.above,below:e.below};for(let r of e.panes)if(t.y>=r.plot.y&&t.y<r.plot.y+r.plot.height)return t.x<0?{kind:`price-axis`,paneId:r.id,scale:pe}:t.x<n.plotWidth?{kind:`plot`,paneId:r.id}:{kind:`price-axis`,paneId:r.id,scale:fe};let r=n.timeAxis;return r&&t.y>=r.y&&t.y<r.y+r.height&&t.x>=0&&t.x<n.plotWidth?{kind:`time-axis`}:{kind:`outside`}}function fa(e,t,n){let r=e.frame(),i=da(r,t),a={x:t.x+r.layout.leftAxisWidth,y:t.y,target:n?{kind:n.kind,id:n.id,part:n.part}:null},o=i.kind===`price-axis`?r.panes.find(e=>e.id===i.paneId):null;if(i.kind===`price-axis`&&o){let n=(e.panes.findScale(i.paneId,i.scale)?.scale)?.yToValue(t.y-o.plot.y)??NaN;return{...a,area:i.kind,paneId:i.paneId,scaleId:i.scale,index:null,time:null,price:Number.isFinite(n)?n:null}}let s=Ti(e,r,t.x,t.y);return{...a,area:i.kind,paneId:s?.paneId??null,scaleId:null,index:s?.index??null,time:s?.time??null,price:s?.price??null}}function pa(e,t,n){let r=new Map(e.frame().panes.map(e=>[e.id,e.plot.height])),i=new Map(e.panes.list().map(e=>[e.id,e.height])),a=r.get(t)??0,o=a+(r.get(n)??0),s=Math.min(e.options.panes.minHeight,o/2),c=!1,l=t=>{k(e,()=>{for(let n of e.panes.list())n.id!==`main`&&e.panes.update(n.id,{height:t.get(n.id)??n.height});e.invalidate()})};return{move:e=>{let i=jn(a+e,s,o-s);l(new Map([...r,[t,i],[n,o-i]])),c=!0},cancel:()=>{c&&l(i)},end:()=>{c&&k(e,()=>{for(let t of e.panes.list())t.id!==`main`&&t.height!==i.get(t.id)&&e.bus.emit(`paneResize`,{paneId:t.id,height:t.height})})}}}function ma(e,t){return{move:(n,r)=>{k(e,()=>{t.move(n,r)})},end:()=>{k(e,()=>{t.end()})},cancel:()=>{k(e,()=>{t.cancel()})}}}function ha(e,t){return{pointerDown:(n,r,i)=>{k(e,()=>{t.pointerDown(n,r,i)})},pointerMove:(n,r)=>{k(e,()=>{t.pointerMove(n,r)})},pointerUp:(n,r,i)=>{k(e,()=>{t.pointerUp(n,r,i)})},doubleClick:n=>{k(e,()=>{t.doubleClick(n)})},cancelPress:()=>{k(e,()=>{t.cancelPress()})}}}function ga(e){let t=()=>e.options.interaction,n=t=>{k(e,()=>{e.shownFrame(),t(),e.invalidate()})},r=t=>k(e,()=>{e.shownFrame();let n=e.timeScale.state();t();let r=e.timeScale.state(),i=r.barSpacing!==n.barSpacing||r.offset!==n.offset;return i&&(e.noteMotion(),e.invalidate()),i},!1);return{root:e.surface.root,enabled:e=>t()[e],longPressMs:()=>t().longPressMs,beforePaint:t=>{e.beforePaint(()=>{k(e,t)})},plotWidth:()=>k(e,()=>e.shownFrame().layout.plotWidth,0),originX:()=>k(e,()=>e.shownFrame().layout.leftAxisWidth,0),regionAt:t=>k(e,()=>da(e.shownFrame(),t),ca),setPointer:t=>{k(e,()=>{e.setPointer(t)})},magnify:t=>{k(e,()=>{e.magnify(t)})},hitTest:t=>k(e,()=>e.hitTest(t),null),hover:t=>{k(e,()=>{e.setHovered(t)})},hoverSeparator:t=>{k(e,()=>{e.setHoveredSeparator(t)})},legendAt:t=>e.options.legend.visible?e.legend.at(t):null,hoverLegend:t=>{k(e,()=>{e.setLegendHover(t)})},clickLegend:t=>{k(e,()=>{t.button!==null&&e.bus.emit(`legendButtonClick`,{item:t.item,buttonId:t.button})})},beginDrag:(t,n,r)=>{let i=k(e,()=>e.beginDrag(t,n,r),null);return i?ma(e,i):null},activeTool:()=>{let t=e.activeTool();return t?ha(e,t):null},click:(t,n)=>{k(e,()=>{n?.part.startsWith(`button:`)?e.bus.emit(`buttonClick`,{kind:n.kind,id:n.id,buttonId:n.part.slice(7)}):(n&&na(n.part)&&ua(e,n),e.selectByUser(n?{kind:n.kind,id:n.id}:null),e.bus.has(`click`)&&e.bus.emit(`click`,fa(e,t,n)))})},doubleClick:(n,r)=>{k(e,()=>{if(r.kind===`price-axis`&&t().axisScale?(e.panes.findScale(r.paneId,r.scale)?.scale.lead.resetAutoScale(),e.invalidate()):r.kind===`time-axis`&&t().axisScale&&(e.timeScale.reset(e.options.timeScale.barSpacing),e.invalidate()),e.bus.has(`doubleClick`)){let t=r.kind===`plot`?e.hitTest(n):null;e.bus.emit(`doubleClick`,fa(e,n,t))}})},contextMenu:(t,n)=>k(e,()=>e.activeTool()?(la(e,`escape`),!0):e.bus.has(`contextMenu`)?(e.bus.emit(`contextMenu`,fa(e,t,n)),!0):!1,!1),scrollTime:t=>r(()=>{e.timeScale.scrollBy(t)}),zoomTime:(t,n)=>r(()=>{e.timeScale.zoom(t,e.timeScale.zoomAnchor(n))}),isAutoScale:t=>e.panes.manualScales(t).length===0,panPrice:(t,r)=>{n(()=>{e.panes.manualScales(t).forEach(e=>{e.pan(r)})})},zoomPrice:(t,r,i,a)=>{n(()=>{let n=e.shownFrame().panes.find(e=>e.id===t);n&&e.panes.findScale(t,r)?.scale.lead.zoom(i,a-n.plot.y)})},scalesPrice:(t,n)=>{let r=e.isDestroyed?null:e.panes.findScale(t,n)?.scale.lead.mode;return r!==`percent`&&r!==`indexed`},beginPaneResize:(t,n)=>pa(e,t,n),command:t=>k(e,()=>la(e,t),!1),editObject:t=>k(e,()=>e.objects.edit(t),!1),scrollToRealTime:()=>{r(()=>{e.timeScale.scrollToRealTime()})}}}let _a={buy:1,sell:-1};function va(e,t=`trades`){return e.map((e,r)=>{let o=`${t}[${r}]`;h(o,e);let s=a(e.time,`${o}.time`),c=e.size??0;(typeof e.price!=`number`||!Number.isFinite(e.price))&&n(`${o}.price must be a finite number, received ${i(e.price)}.`),(typeof c!=`number`||!Number.isFinite(c)||c<0)&&n(`${o}.size must be a finite number of at least 0, received ${i(c)}.`);let l=e.side===void 0?null:m(`${o}.side`,e.side,[`buy`,`sell`]);return{time:s,price:e.price,size:c,side:l}})}function ya(e,t){return{time:e.time,open:e.open,high:Math.max(e.high,t.price),low:Math.min(e.low,t.price),close:t.price,volume:e.volume+t.size}}function ba(e,t,n,r,i){let a=t,o=(a&&i(a.time))??-1/0,s=n,c=[],l=[],u=[];return e.forEach(e=>{let t=r(e.time);if(t===null||e.time<s||t<o)return;let n=a&&t===o?ya(a,e):xa(t,e);c.length>0&&c[c.length-1]?.time===n.time?c[c.length-1]=n:c.push(n),a=n,o=t,s=e.time,l.push(e),u.push(t)}),{bars:c,kept:l,barTimes:u,latest:s}}function xa(e,t){return{time:e,open:t.price,high:t.price,low:t.price,close:t.price,volume:t.size}}var Sa=class{capacity;times=/* @__PURE__ */ new Float64Array;prices=/* @__PURE__ */ new Float64Array;sizes=/* @__PURE__ */ new Float64Array;sides=/* @__PURE__ */ new Int8Array;barTimes=/* @__PURE__ */ new Float64Array;oldest=0;total=0;revealed=0;cutoff=1/0;changes=new Ve;constructor(e){this.capacity=e}get revision(){return this.changes.revision}get first(){return this.oldest}get end(){return this.revealed}time(e){return this.times[e%this.capacity]??NaN}price(e){return this.prices[e%this.capacity]??NaN}size(e){return this.sizes[e%this.capacity]??NaN}side(e){let t=this.sides[e%this.capacity];return t===1?`buy`:t===-1?`sell`:null}bar(e){let t=this.price(e);return{time:this.time(e),open:t,high:t,low:t,close:t,volume:this.size(e)}}append(e,t){this.capacity!==0&&(this.reserve(this.total+e.length),e.forEach((e,n)=>{let r=this.total%this.capacity;this.times[r]=e.time,this.prices[r]=e.price,this.sizes[r]=e.size,this.sides[r]=e.side===null?0:_a[e.side],this.barTimes[r]=t[n]??NaN,this.total+=1}),this.oldest=Math.max(this.oldest,this.total-this.capacity),this.reveal())}setCutoff(e){this.cutoff=e,this.reveal()}setCapacity(e){if(e===this.capacity)return;let t=Math.max(this.oldest,this.total-e),n=Array.from({length:this.total-t},(e,n)=>t+n).map(e=>{let t=e%this.capacity;return[this.times[t]??NaN,this.prices[t]??NaN,this.sizes[t]??NaN,this.sides[t]??0,this.barTimes[t]??NaN]});this.capacity=e,this.oldest=t,this.times=/* @__PURE__ */ new Float64Array,this.prices=/* @__PURE__ */ new Float64Array,this.sizes=/* @__PURE__ */ new Float64Array,this.sides=/* @__PURE__ */ new Int8Array,this.barTimes=/* @__PURE__ */ new Float64Array,this.reserve(this.total),n.forEach(([n,r,i,a,o],s)=>{let c=(t+s)%e;this.times[c]=n,this.prices[c]=r,this.sizes[c]=i,this.sides[c]=a,this.barTimes[c]=o}),this.revealed=Math.max(this.revealed,t)}clear(){this.oldest=0,this.total=0,this.revealed=0,this.changes.reset()}changesSince(e){return this.changes.since(e)}view(){return new Ca(this)}reveal(){let e=this.oldest,t=this.total;for(;e<t;){let n=e+t>>>1;(this.barTimes[n%this.capacity]??NaN)<=this.cutoff?e=n+1:t=n}let n=this.revealed;this.revealed=e,e>n?this.changes.tail(n):e<n&&this.changes.reset()}reserve(e){let t=Math.min(this.capacity,e);if(t<=this.times.length)return;let n=Math.min(this.capacity,Math.max(16,this.times.length*2,t)),r=e=>{let t=new Float64Array(n);return t.set(e),t};this.times=r(this.times),this.prices=r(this.prices),this.sizes=r(this.sizes);let i=new Int8Array(n);i.set(this.sides),this.sides=i,this.barTimes=r(this.barTimes)}},Ca=class{log;constructor(e){this.log=e}get length(){return this.log.end-this.log.first}get revision(){return this.log.revision}time(e){return this.log.time(this.log.first+e)}open(e){return this.log.price(this.log.first+e)}high(e){return this.log.price(this.log.first+e)}low(e){return this.log.price(this.log.first+e)}close(e){return this.log.price(this.log.first+e)}volume(e){return this.log.size(this.log.first+e)}bar(e){return e>=0&&e<this.length?this.log.bar(this.log.first+e):null}lowerBound(e){let t=0,n=this.length;for(;t<n;){let r=t+n>>>1;this.time(r)<e?t=r+1:n=r}return t}};let A=864e5,wa=[`second`,`minute`,`hour`,`day`,`week`,`month`],Ta={second:1e3,minute:6e4,hour:36e5},Ea={day:1,week:7,month:30},Da={s:`second`,m:`minute`,h:`hour`,H:`hour`,d:`day`,D:`day`,w:`week`,W:`week`,M:`month`},Oa={second:`s`,minute:`m`,hour:`h`,day:`D`,week:`W`,month:`M`},ka=/^(\d*)([smhHdDwWM])$/;function Aa(e,t,r,a){return(!Number.isSafeInteger(t)||t<1)&&n(`${r} needs a positive integer count, received ${i(a)}.`),Object.freeze({unit:e,count:t})}function ja(e,t=`interval`){let r=e;if(typeof r==`string`){let e=ka.exec(r),i=e?Da[e[2]??``]:void 0;return!e||!i?n(`${t} ${JSON.stringify(r)} is not an interval; use a count and a unit such as "15s", "5m", "4h", "1D", "1W" or "3M".`):Aa(i,e[1]?Number(e[1]):1,t,r)}if(typeof r!=`object`||!r||Array.isArray(r))return n(`${t} must be a string such as "5m" or an object { unit, count }, received ${i(r)}.`);let{unit:a,count:o}=r;return wa.includes(a)||n(`${t}.unit must be one of ${wa.map(e=>`"${e}"`).join(`, `)}, received ${i(a)}.`),Aa(a,o,t,o)}function j(e){let{unit:t,count:n}=ja(e);return`${n}${Oa[t]}`}function Ma(e){let t=Ta[e.unit];return t===void 0?null:t*e.count}function Na(e){return Ma(e)??(Ea[e.unit]??0)*864e5*e.count}function Pa(e){return Ma(ja(e))}function Fa(e,t){return e===t||e?.unit===t?.unit&&e?.count===t?.count}function Ia(e,t){let n=Ma(e),r=Ma(t),i=`it is finer than the source`;return r===null?n===null?e.unit===t.unit?e.count<t.count?i:e.count%t.count===0?null:`${j(e)} is not a multiple of ${j(t)}`:t.unit===`day`?t.count===1?null:`weeks and months are built from 1D bars`:e.unit===`day`?i:`weeks and months do not divide each other`:i:n===null?864e5%r==0?null:`${j(t)} does not divide a day`:n<r?i:n%r===0?null:`${j(e)} is not a multiple of ${j(t)}`}function La(e,t){let r=ja(e,`timeframe`),i=ja(t),a=Ia(r,i);a!==null&&n(`The timeframe ${j(r)} cannot be built from ${j(i)} source bars: ${a}.`)}function Ra(e,t){return Ia(ja(e,`timeframe`),ja(t))===null}let za=6e4,Ba=108e5;function Va(e){return((e+4)%7+7)%7}var Ha=class{spec;timeZone;path;clock;dateOffset;recent=null;latest=null;latestDay=null;tradingWeek;constructor(e,t,n){this.spec=e,this.timeZone=t,this.path=n,this.clock=new zt(t),this.dateOffset=e.dayStart===0?0:e.dayStart*za-A,this.tradingWeek=[0,1,2,3,4,5,6].filter(t=>e.weekdays[Va(t)])}bucket(e,t){return this.cached(t).bucketer(a(e))}range(e,t){let n=a(e),{run:r,bucketer:i}=this.cached(t),o=i(n);return o===null?null:this.spec.bucket?{bucket:o,start:n,end:n+1}:{...r}}cached(e){if(this.recent?.input!==e){let t={bucket:0,start:0,end:0};this.recent={input:e,run:t,bucketer:this.bucketer(ja(e),t)}}return this.recent}bucketer(e,t={bucket:0,start:0,end:0},r=!1){let a=r&&Ma(e)===null,s=n=>n>=t.start&&n<t.end||this.locate(n,e,t,a)?t.bucket:null,c=this.spec.bucket;return c?t=>{let r=c(t,e,s);return r!==null&&(typeof r!=`number`||!Number.isFinite(r))&&n(`${this.path}.bucket must return a time or null, received ${i(r)} for ${o(t)}.`),r}:s}locate(e,t,n,r){let i=r?this.day(e):this.segment(e);if(i===null)return!1;let a=Ma(t),{start:o,end:s}=i;if(a!==null){let{origin:t}=i;n.bucket=t+Math.floor((e-t)/a)*a,o=Number.isNaN(o)?o:n.bucket,s=Math.min(n.bucket+a,s)}else{let e=this.trading(i.date,1),{count:r}=t,a,c;switch(t.unit){case`day`:{let t=Math.floor(this.tradingDates(e)/r)*r;a=this.tradingDate(t),c=this.tradingDate(t+r);break}case`week`:{let t=e-(Va(e)-this.spec.weekStart+7)%7,n=-((4-this.spec.weekStart+7)%7);a=n+Math.floor((t-n)/7/r)*r*7,c=a+r*7;break}default:{let t=/* @__PURE__ */ new Date(e*A),n=Math.floor((t.getUTCFullYear()*12+t.getUTCMonth())/r)*r;a=Date.UTC(Math.floor(n/12),n%12,1)/A,c=Date.UTC(Math.floor(n/12),n%12+r,1)/A}}n.bucket=this.clock.instant(a*A),this.spec.sessions.length===0&&(o=this.movingInto(a),s=this.movingInto(c))}let c=!Number.isNaN(o+s);return n.start=c?o:e,n.end=c?s:e+1,!0}day(e){let t=this.latestDay;if(t!==null&&e>=t.start&&e<t.end)return t;let n=e+this.clock.offset(e),r=Math.floor((n-this.dateOffset)/A),i=r*A+this.dateOffset;return this.latestDay={origin:this.clock.instant(i),start:this.steady(i),end:this.steady(i+A),date:r},this.latestDay}segment(e){let t=this.latest;if(t!==null&&e>=t.start&&e<t.end)return t;let n=e+this.clock.offset(e),r=Math.floor((n-this.dateOffset)/A),i=r*A+this.dateOffset,a=i+A;if(this.spec.sessions.length>0){let e=this.session(n);if(e===null)return null;[i,a]=e}return this.latest={origin:this.clock.instant(i),start:this.steady(i),end:this.steady(a),date:r},this.latest}session(e){let t=Math.floor(e/A)*A;for(let{start:n,end:r}of this.spec.sessions){let i=(n-(n>r&&e-t<r*za?1440:0))*za,a=i+(r-n+1440)%1440*za;if(e>=t+i&&e<t+a)return[t+i,t+a]}return null}movingInto(e){return this.steady((this.trading(e-1,-1)+1)*A+this.dateOffset)}tradingDates(e){let t=Math.floor(e/7),n=e-t*7;return t*this.tradingWeek.length+this.tradingWeek.filter(e=>e<n).length}tradingDate(e){let t=Math.floor(e/this.tradingWeek.length);return t*7+(this.tradingWeek[e-t*this.tradingWeek.length]??NaN)}trading(e,t){let n=e;for(;!this.spec.weekdays[Va(n)];)n+=t;return n}steady(e){let t=this.clock.instant(e),n=this.clock.offset(t);return t+n===e&&this.clock.offset(t-Ba)===n&&this.clock.offset(t+Ba)===n?t:NaN}};let Ua=g({timeZone:!0,sessions:!0,dayStart:!0,weekdays:!0,weekStart:!0,bucket:!0});function Wa(e={}){_(`calendar`,e,Ua);let t=Se(Yt().calendar,e),n=te(`calendar.timeZone`,t.timeZone),r=new Ha(rn(t,`calendar`),n,`calendar`);return{bucket:(e,t)=>r.bucket(e,t),range:(e,t)=>r.range(e,t)}}var Ga=class{store;first=0;constructor(e){this.store=e}get revision(){return this.store.revision}get end(){return this.store.length}changesSince(e){return this.store.changesSince(e)}bar(e){return this.store.read(e)}side(){return null}view(){return this.store}};function Ka(e,t,r){let i=[],a=t,s=-1/0;for(let t of e)Number.isFinite(t.time)&&Number.isFinite(t.open)&&Number.isFinite(t.high)&&Number.isFinite(t.low)&&Number.isFinite(t.close)&&Number.isFinite(t.volume)||n(`The "${r}" transform produced a bar with a value that is not a finite number.`),t.time<s&&n(`The "${r}" transform produced a bar at ${o(t.time)} after a bar at ${o(s)}; times must not decrease.`),s=t.time,a=Math.max(t.time,a+1),i.push(a===t.time?t:{...t,time:a});return i}var qa=class{input;from;output;type;definition;params;stream=null;latest=null;fed=0;completed=0;seen=-1;constructor(e,t,n,r,i,a){this.input=e,this.from=t,this.output=n,this.type=r,this.definition=i,this.params=a}get settled(){return this.completed}lastClose(){let{first:e,end:t}=this.input;return t>e?this.input.bar(t-1).close:null}resolved(){return this.latest?.resolved?.()??null}sync(){let e=this.input.changesSince(this.seen);e&&(e.kind===`tail`&&this.stream&&e.from>=this.fed&&this.fed>=this.input.first?this.extend(this.stream):this.rebuild(),this.seen=this.input.revision)}rebuild(){let e=this.definition.create(this.params,this.input.view(),this.from),t=this.feed(e,this.input.first),n=Ka(t.bars,-1/0,this.type);this.commit(e,t,0),this.output.assign(n)}extend(e){let t=this.fed<this.input.end-1?e.clone():e,n=this.completed,r=this.feed(t,this.fed),i=n>0?this.output.time(n-1):-1/0,a=Ka(r.bars,i,this.type);this.commit(t,r,n),this.output.replaceFrom(n,a)}commit(e,t,n){this.stream=e,this.fed=t.fed,this.completed=n+t.completed,this.latest=t.latest}feed(e,t){let n=this.input.end,r=[],i=t;for(;i<n-1;i+=1)for(let t of e.next(this.input.bar(i),this.input.side(i)))r.push(t);let a=r.length,o=e;if(n>t){let t=e.clone();r.push(...t.next(this.input.bar(n-1),this.input.side(n-1)));let i=t.current();o=t,i&&r.push(i)}return{bars:r,fed:i,completed:a,latest:o}}};function Ja(){return new Rr(`bar transform`,[],`Give it to the chartTypes module, or register it with chart.transforms.register().`)}let Ya=g({type:!0,params:!0,input:!0});function Xa(e){return new Ha(rn(e.calendar,`options.calendar`),e.calendar.timeZone,`options.calendar`)}function Za(e){return Ma(e)===null}function Qa(e,t){if(Za(t))return e.bucketer(t,void 0,!0);let r=e.bucketer(t);return i=>{let a=r(i);return a!==null&&a!==i&&n(`The ${j(t)} bar at ${o(i)} does not start a bar of the trading calendar, which starts it at ${o(a)}: set options.calendar as the data times its bars, such as its timeZone (now ${JSON.stringify(e.timeZone)}).`),a}}function $a(e,t,n){let r=Qa(e,t);if(!n)return r;let i=e.bucketer(n,void 0,Za(t));return e=>r(e)===null?null:i(e)}function eo(e,t,n){return e.bucketer(n??t,void 0,Za(t))}let to=[`bars`,`trades`];function no(e){e.forEach(e=>{e()})}var ro=class{bars;series;options;feed;transforms=Ja();displayed;revealed;timeBars=new rt;trades;stage=null;latestTrade=-1/0;source=null;frame=null;calendar;constructor(e,t,n){this.bars=e,this.series=t,this.options=n,this.feed=gt(st,e),this.displayed=new it(e),this.revealed=new it(this.feed.source,()=>this.feed.revealed(),()=>this.feed.cutoffMoves()),this.calendar=Xa(n),this.trades=new Sa(n.performance.maxTrades)}sourceInterval(){return this.source}tradingCalendar(){return this.calendar}timeframe(){return this.frame}transform(){if(!this.stage)return null;let e=this.stage.resolved();return{type:this.stage.type,params:structuredClone(this.stage.params),input:this.stage.from,resolved:e&&structuredClone(e)}}transformResolved(){return this.stage?.resolved()??null}setTransform(e){if(e===null){this.stage&&(this.stage=null,this.feed.setDisplay(this.bars));return}let{type:t,definition:n,params:r,from:i}=this.startTransform(e),a=i===`trades`?this.trades:new Ga(this.timeBars),o=this.stage;o||this.feed.setDisplay(this.timeBars);let s=new qa(a,i,this.bars,t,n,r);try{s.sync()}catch(e){throw o||this.feed.setDisplay(this.bars),e}this.stage=s}checkTransform(e){let{type:t,definition:n,params:r,from:i}=this.startTransform(e);new qa(i===`trades`?this.trades:new Ga(this.stage?this.timeBars:this.bars),i,new rt,t,n,r).sync()}startTransform(e){_(`transform`,e,Ya);let t=p(`transform.type`,e.type),n=this.transforms.require(t);e.params!==void 0&&h(`transform.params`,e.params);let r=e.input===void 0?`bars`:m(`transform.input`,e.input,to),i={...e.params};return n.create(i,r===`trades`?this.trades.view():this.feed.display,r),{type:t,definition:n,params:i,from:r}}livePrice(){return this.stage&&!this.stage.definition.keepsTime?this.stage.lastClose():null}settled(){return this.stage?this.stage.settled:Math.max(0,this.bars.length-1)}timeBased(){return this.stage?.definition.keepsTime??!0}resolution(){return this.timeBased()?this.frame??this.source:`untimed`}barDuration(){if(!this.timeBased())return null;let e=this.frame??this.source;return e?Ma(e):null}barEnd(e){let t=this.timeBased()?this.frame??this.source:null,n=t?this.calendar.range(e,t):null;return n&&n.end>e+1?n.end:null}firstSourceTime(){return this.feed.firstTime()}configure(e){let t=this.options,n=!on(t.calendar,e.calendar),r=n?Xa(e):this.calendar,i=n?this.source:null,a=i?this.planBuckets(r,i,this.frame):[];return this.options=e,this.trades.setCapacity(e.performance.maxTrades),no(a),this.calendar=r,i&&this.stage?.sync(),i!==null}set(e,t){let n=t===void 0?null:ja(t,`interval`),r=n&&this.frame&&Ra(this.frame,n)?this.frame:null,i=n&&r&&!Fa(r,n)?r:null,a=n?eo(this.calendar,n,i):st,o=n?$a(this.calendar,n,i):st;no([this.feed.planSet(e,o),this.series.planRebucket(a)]),this.source=n,this.frame=i,this.trades.clear(),this.latestTrade=-1/0,this.stage?.sync()}update(e){this.feed.planUpdate(e)(),this.stage?.sync()}prepend(e){let{inserted:t,commit:n}=this.feed.planPrepend(e);return n(),this.stage?.sync(),t}addTrades(e){let t=this.source??n(`addTrades() needs the source interval: pass it with data.set(bars, { interval }).`),r=this.feed.source,{bars:i,kept:a,barTimes:o,latest:s}=ba(va(e),r.bar(r.length-1),this.latestTrade,this.calendar.bucketer(t),Qa(this.calendar,t));return this.latestTrade=s,this.trades.append(a,o),this.update(i),a.length}addSeriesTrades(e,t){let r=this.source??n(`series.addTrades() needs the source interval: pass it with data.set(bars, { interval }).`),i=va(t),a=this.calendar.bucketer(r),o=Qa(this.calendar,r);if(e.source.input===`ohlc`){let{feed:t}=e.source,n=ba(i,t.source.bar(t.source.length-1),e.latestTrade,a,o);return t.planUpdate(n.bars)(),e.latestTrade=n.latest,n.kept.length}let{feed:s}=e.source,c=s.source.length,l=s.source.value(c-1),u=ba(i,c===0?null:{time:s.source.time(c-1),open:l,high:l,low:l,close:l,volume:0},e.latestTrade,a,o);return s.planUpdate(u.bars.map(e=>({time:e.time,value:e.close})))(),e.latestTrade=u.latest,u.kept.length}clear(){this.feed.clear(),this.trades.clear(),this.latestTrade=-1/0,this.setCutoff(1/0)}setTimeframe(e){let t=this.source??n(`setTimeframe() needs the source interval: pass it with data.set(bars, { interval }).`),r=e===null?null:ja(e,`timeframe`);r&&La(r,t);let i=r&&Fa(r,t)?null:r;no(this.planBuckets(this.calendar,t,i)),this.frame=i,this.stage?.sync()}bucketerOf(e,t){return $a(this.calendar,e,t)}setCutoff(e){this.series.setCutoff(e),this.trades.setCutoff(e);let t=this.feed.setCutoff(e);return this.stage?.sync(),t}planBuckets(e,t,n){return[this.feed.planRebucket($a(e,t,n)),this.series.planRebucket(eo(e,t,n))]}},io=class{bars;revision=-1;value=2;constructor(e){this.bars=e}get(e){if(e!==`auto`)return e;let t=this.bars;if(this.revision!==t.revision){let e=2;for(let n=Math.max(0,t.length-500);n<t.length;n+=1)e=Vt(t.open(n),e),e=Vt(t.high(n),e),e=Vt(t.low(n),e),e=Vt(t.close(n),e);this.revision=t.revision,this.value=e}return this.value}invalidate(){this.revision=-1}},ao=class{environment;plugins=/* @__PURE__ */ new Map;constructor(e){this.environment=e}add(e){h(`plugin`,e);let t=p(`plugin.name`,e.name);for(let t of[`attach`,`detach`,`paint`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`plugin.${t} must be a function.`);this.plugins.has(t)&&n(`A plugin named "${t}" is already added.`);let{environment:r}=this;e.attach?.({chart:r.chart(),bars:r.displayed,source:r.source,repaint:()=>{r.repaint()}}),this.plugins.set(t,e),r.repaint()}remove(e){let t=this.plugins.get(e)??n(`There is no plugin named "${e}".`);this.plugins.delete(e),this.environment.repaint(),t.detach?.()}get(e){return this.plugins.get(e)??null}list(){return[...this.plugins.values()]}paint(e,t,n,r,i){let a=[...this.plugins.values()].filter(e=>e.paint!==void 0);if(a.length===0)return;let{environment:o}=this,{bars:s,timeScale:c}=o,l=o.options(),u={ctx:e,pixelRatio:i,layer:r,pane:{id:n.id,width:n.plot.width,height:n.plot.height,valueToY:e=>n.scale.valueToY(e),yToValue:e=>n.scale.yToValue(e),formatValue:e=>o.formatValue(n,e)},bars:o.displayed,source:o.source,cutoff:o.cutoff(),visible:t.visible,barSpacing:c.barSpacing,indexToX:e=>c.indexToX(e),xToIndex:e=>c.xToIndex(e),timeToX:e=>c.indexToX(s.logicalIndexOf(e)),theme:l.theme,font:{family:l.font.family,size:l.font.size}};for(let t of a)vn(e,()=>{t.paint?.(u)})}detachAll(){let e=[...this.plugins.values()];this.plugins.clear(),r(e.map(e=>()=>e.detach?.()))}},oo=class{readers=/* @__PURE__ */ new Map;users=[];constructor(e,t){this.provide(`price`,{check:()=>void 0,read:(t,n)=>e.price(n,t.field??`close`),paneOf:()=>x}),this.provide(`series`,{check:e=>{t.require(e.id)},read:(n,r)=>{let i=t.require(n.id),a=i.values??i.bars,o=a?a.lowerBound(e.time(r)+1)-1:-1;return o<0?NaN:i.values?i.values.value(o):i.bars?.close(o)??NaN},paneOf:e=>t.require(e.id).pane,scaleOf:e=>t.require(e.id).scale})}provide(e,t){this.readers.set(e,t)}use(e){this.users.push(e)}reader(e,t){return this.readers.get(e.kind)??n(`${t}: the chart has no ${e.kind} values; load the module of its ${e.kind}s.`)}check(e,t){this.reader(e,t).check(e,t)}read(e,t){return this.reader(e,`source`).read(e,t)}paneOf(e){return this.reader(e,`source`).paneOf(e)}scaleOf(e){return this.reader(e,`source`).scaleOf?.(e)??`right`}movable(e){return this.readers.get(e.kind)?.movable===!0}uses(e,t){return this.users.flatMap(n=>n.uses(e,t).map(e=>({...e,noun:n.noun})))}assertUnused(e,t){let r=/* @__PURE__ */ new Map;for(let n of this.uses(e,t))r.set(n.noun,(r.get(n.noun)??/* @__PURE__ */ new Set).add(n.user));if(r.size===0)return;let i=[...r].map(([e,t])=>{let n=[...t].map(e=>`"${e}"`).join(`, `);return t.size>1?`the ${e}s ${n}`:`${e} ${n}`}),a=i.length>1||[...r.values()].some(e=>e.size>1);n(`"${t}" is read by ${i.join(` and `)}; remove ${a?`them`:`it`} first.`)}reset(){this.users.forEach(e=>{e.reset()})}verify(e){this.users.forEach(t=>{t.verify(e)})}},so=class{host;lastVisibleKey=``;loadMoreArmed=!0;loadMoreFirstTime=NaN;constructor(e){this.host=e}check(){let{bars:e,timeScale:t,bus:n}=this.host,r=t.visibleBars(),i=r?`${e.time(r.from)}:${e.time(r.to)}`:``;if(i!==this.lastVisibleKey){this.lastVisibleKey=i;let a=t.logicalRange();n.emit(`visibleRangeChange`,{range:r?{from:e.time(r.from),to:e.time(r.to)}:null,logicalRange:r?a:null})}this.checkLoadMore()}checkLoadMore(){let{bars:e,timeScale:t,bus:n,market:r,surface:i,options:a}=this.host;if(e.length===0||i.width===0)return;let o=a.timeScale.loadMoreThreshold-t.logicalRange().from;if(!(o>0)){this.loadMoreArmed=!0;return}let s=r.firstSourceTime()??e.time(0);(this.loadMoreArmed||s!==this.loadMoreFirstTime)&&(this.loadMoreArmed=!1,this.loadMoreFirstTime=s,n.emit(`loadMore`,{before:s,bars:Math.ceil(o)}))}};function co(e){return{minBarSpacing:e.timeScale.minBarSpacing,maxBarSpacing:e.timeScale.maxBarSpacing,rightOffset:e.timeScale.rightOffset}}var lo=class{view;bus=new Pt;bars=new rt;seriesTypes=oi();series=new Ct(this.seriesTypes,()=>this.currentOptions.theme);values=new oo(this.bars,this.series);surface;timeScale;panes;objects=new Si;market;plugins;contributors=[];legendRows=[];scenePainters=[];commands=[];paneOccupants=[];stateParts=[];tool=null;hooks={barsChanged:[],dataCleared:[],destroyed:[]};moduleApis;input;currentOptions;formatterValue;marks;scheduler;pool=new En;frameValue=null;geometryDirty=!0;axisWidths={right:0,left:0};precision;magnified=null;tracker=new Fi(this,()=>{this.invalidateLayers(`cursor`)});viewport=new so(this);countdown=new Ci(this);hoveredSeparator=null;coveredTicks=``;legend=new qi;cutoffTime=1/0;optionSections;destroyed=!1;constructor(e,t,n,r,i){this.view=e,this.optionSections=r.flatMap(e=>e.options?[e.options]:[]),this.currentOptions=hn(Yt(this.optionSections),n,this.optionSections),this.market=new ro(this.bars,this.series,this.currentOptions),this.precision=new io(this.market.feed.source),this.formatterValue=new Bt(this.currentOptions.locale,this.currentOptions.timeZone),this.marks=new zn(this.bars,this.formatterValue.clock),this.timeScale=new Lr(co(this.currentOptions),this.currentOptions.timeScale.barSpacing),this.panes=new ve(this.currentOptions.panes.defaultHeight,this.currentOptions.priceScale.margins),this.surface=new Ir(e,t,this.currentOptions.performance.maxPixelRatio,()=>{this.run(()=>{this.invalidate()}),this.scheduler.flush()}),this.scheduler=new Pr(e,e=>{this.paint(e)}),this.plugins=new ao({bars:this.bars,displayed:this.market.displayed,source:this.market.revealed,timeScale:this.timeScale,cutoff:()=>this.cutoffTime,options:()=>this.currentOptions,formatValue:(e,t)=>Vn(this,e,t),repaint:()=>{this.invalidateLayers(`scene`)},chart:i}),this.input=new bi(ga(this),e),this.moduleApis=this.install(r),this.axisWidths={right:this.currentOptions.priceScale.minWidth,left:0};let a=this.surface.measureContainer();this.surface.resize(a.width,a.height),this.surface.setAutoSize(this.currentOptions.autoSize),this.surface.watchPixelRatio(),this.invalidate()}install(e){let t={};try{for(let r of e)for(let[e,i]of Object.entries(r.install?.(this)??{}))Object.hasOwn(t,e)&&n(`Two modules add chart.${e}.`),t[e]=i}catch(e){throw this.destroy(),e}return t}get options(){return this.currentOptions}get formatter(){return this.formatterValue}get barDuration(){return this.market.barDuration()}barEnd(e){return this.market.barEnd(e)}get timeBased(){return this.market.timeBased()}get cutoff(){return this.cutoffTime}get isDestroyed(){return this.destroyed}get replaying(){return this.cutoffTime!==1/0}events(){return this.bus}get crosshair(){return this.tracker.sync(this.frame()),this.tracker.value}run(e){return this.destroyed&&n(`The chart has been destroyed.`),this.bus.defer(e)}applyOptions(e){let t=this.currentOptions,n=hn(t,e,this.optionSections);this.seriesTypes.require(n.mainSeries.type);let r=this.market.tradingCalendar(),i=this.rightEdgeTime(),a=this.market.configure(n);this.currentOptions=n,(n.locale!==t.locale||n.timeZone!==t.timeZone)&&(this.formatterValue=new Bt(n.locale,n.timeZone),this.marks=new zn(this.bars,this.formatterValue.clock)),this.timeScale.configure(co(n)),n.timeScale.barSpacing!==t.timeScale.barSpacing&&this.timeScale.setBarSpacing(n.timeScale.barSpacing),this.panes.configure(n.panes.defaultHeight,n.priceScale.margins),a?(this.timeScale.setBarCount(this.bars.length,`replace`),this.placeRightEdge(i),this.onBarsChanged({kind:`reset`})):this.market.tradingCalendar()!==r&&this.values.reset(),n.performance.maxPixelRatio!==t.performance.maxPixelRatio&&this.surface.setMaxPixelRatio(n.performance.maxPixelRatio),n.autoSize!==t.autoSize&&this.surface.setAutoSize(n.autoSize),this.precision.invalidate(),this.invalidate(),this.bus.emit(`optionsChange`,{options:n,previous:t})}resize(e,t){this.surface.resize(e,t)&&this.invalidate()}setData(e,t){this.changeData(`replace`,()=>{this.market.set(e,t)})}updateData(e){this.changeData(`tail`,()=>{this.market.update(e)})}addTrades(e){return this.changeData(`tail`,()=>this.market.addTrades(e))}prependData(e){return this.changeData(`prepend`,()=>this.market.prepend(e))}clearData(){this.cutoffTime=1/0,this.hooks.dataCleared.forEach(e=>{e()}),this.changeData(`reset`,()=>{this.market.clear()})}setTimeframe(e){this.changeData(`replace`,()=>{this.market.setTimeframe(e)})}setTransform(e){this.changeData(`replace`,()=>{this.market.setTransform(e)})}reveal(e,t){this.cutoffTime=e,this.changeData(t?`reset`:`tail`,()=>{this.market.setCutoff(e)})}changeData(e,t){let n=this.bars.revision,r=e===`replace`?this.rightEdgeTime():null,i=t(),a=this.bars.changesSince(n);return a?(this.timeScale.setBarCount(this.bars.length,e),this.placeRightEdge(r),this.onBarsChanged(e===`prepend`?{kind:`reset`}:a)):this.invalidate(),i}placeRightEdge(e){let t=e===null?NaN:this.bars.logicalIndexOf(e);Number.isFinite(t)&&this.timeScale.placeRightEdge(t)}rightEdgeTime(){if(this.timeScale.isFollowing()||this.bars.length===0||this.timeScale.plotWidth===0)return null;let e=this.bars.timeOfLogicalIndex(this.timeScale.rightEdge());return Number.isFinite(e)?e:null}createAutoPane(e){let t=e;for(let n=2;this.panes.get(t);n+=1)t=`${e}-${n}`;return this.panes.add({id:t},!0),t}occupantsOf(e){return[...this.paneOccupants.flatMap(t=>t.occupants(e)),...this.series.list().filter(t=>t.pane===e).map(e=>e.id)]}removePane(e){this.panes.remove(e),this.paneOccupants.forEach(t=>{t.removed(e)}),this.objects.prune()}releasePane(e){this.panes.get(e)?.auto&&this.occupantsOf(e).length===0&&this.removePane(e)}noteMotion(){this.tracker.noteMotion()}setLegendHover(e){this.legend.setHover(e)&&this.invalidateLayers(`cursor`)}setHoveredSeparator(e){this.hoveredSeparator!==e&&(this.hoveredSeparator=e,this.invalidateLayers(`scene`))}setPointer(e){this.tracker.setPointer(e)}setExternalCrosshair(e){this.tracker.setExternal(e)}magnify(e){this.magnified=this.currentOptions.interaction.touchMagnifier?e:null,this.invalidateLayers(`cursor`)}objectContext(e=this.frame()){return{frame:e,bars:this.bars,displayed:this.market.displayed,source:this.market.revealed,timeScale:this.timeScale,resolution:this.market.resolution(),options:this.currentOptions,formatter:this.formatterValue,selection:this.objects.selection,hovered:this.objects.hovered,cutoff:this.cutoffTime,scaleOf:(e,t)=>this.panes.findScale(e,t)?.scale??null,measureText:(e,t)=>this.measureText(e,t)}}measureText(e,t){let n=this.surface.context(`cursor`);return n.font=t,n.measureText(e).width}hitTest(e){return this.objects.hitTest(this.objectContext(),e)}setHovered(e){this.objects.setHovered(e)&&this.invalidateLayers(`objects`)}beginDrag(e,t,n){return this.objects.beginDrag(this.objectContext(),e,t,n)}select(e){this.objects.select(e)&&this.invalidateLayers(`objects`)}selectByUser(e){this.objects.select(e)&&(this.invalidateLayers(`objects`),this.bus.emit(`selectionChange`,{selection:e}))}activeTool(){return this.tool?.()??null}runCommand(e){return this.commands.some(t=>t(e))}invalidate(){this.geometryDirty=!0,this.scheduler.request(`scene`,`objects`,`cursor`)}invalidateLayers(...e){this.scheduler.request(...e)}beforePaint(e){this.scheduler.beforePaint(e)}frame(){if(this.geometryDirty||!this.frameValue){this.frameValue=this.buildFrame(),this.geometryDirty=!1;let{axisWidth:e,leftAxisWidth:t}=this.frameValue.layout;this.axisWidths={right:e,left:t},this.countdown.sync(),this.viewport.check()}return this.frameValue}shownFrame(){return this.frameValue??this.frame()}flush(){this.scheduler.flush()}buildFrame(){let e=this.surface.context(`cursor`);return e.font=E(this.currentOptions.font.size,this.currentOptions.font.family),Kn({options:this.currentOptions,formatter:this.formatterValue,bars:this.bars,timeScale:this.timeScale,marks:this.marks,panes:this.panes,series:this.series,contributors:this.contributors,values:this.values,seriesTypes:this.seriesTypes,transform:this.market.transformResolved(),live:this.market.livePrice(),countdown:this.countdown.text(Date.now()),pricePrecision:this.precision.get(this.currentOptions.priceScale.precision),measureText:t=>e.measureText(t).width},{width:this.surface.width,height:this.surface.height},this.axisWidths,this.pool)}paint(e){this.bus.defer(()=>{let t=this.frame(),n=this.surface.pixelRatio,r=t.layout.leftAxisWidth,i=this.currentOptions,a=[],o=e=>{try{e()}catch(e){a.push(e)}},s=null;o(()=>{this.tracker.sync(t),s=this.objects.hovered?.kind===`order`?null:Mi(this,t,this.tracker.value)});let c=E(i.font.size,i.font.family),l=fr(t,i,s,e=>this.measureText(e,c)),u=hr(t,i,l);if(e.has(`scene`)?o(()=>{this.coveredTicks=u,Mr(this.surface.begin(`scene`,r),t,i,n,this.timeScale.barSpacing,(e,r,i)=>{this.plugins.paint(e,t,r,i,n),this.scenePainters.forEach(a=>{a(e,t,r,i,n)})},this.hoveredSeparator,l)}):u!==this.coveredTicks&&o(()=>{this.coveredTicks=u,Nr(this.surface.over(`scene`,r),t,i,n,this.hoveredSeparator,l)}),e.has(`objects`)&&o(()=>{this.objects.paint({...this.objectContext(t),ctx:this.surface.begin(`objects`,r),pixelRatio:n})}),e.has(`cursor`)&&o(()=>{let e=this.surface.begin(`cursor`,r);this.legend.paint(e,this,t,this.tracker.value,s,n),this.magnified&&gr(e,[this.surface.canvas(`scene`),this.surface.canvas(`objects`)],this.magnified,t.layout,n,i.theme)}),a.length>0)throw a[0]})}onBarsChanged(e){this.hooks.barsChanged.forEach(t=>{t(e)}),this.invalidate(),this.bus.emit(`barsChange`,{change:e})}destroy(){this.destroyed||r([()=>{this.plugins.detachAll()},()=>{this.bus.clear()},()=>{this.input.destroy()},()=>{this.destroyed=!0,this.scheduler.destroy(),this.countdown.stop(),this.tracker.destroy()},...this.hooks.destroyed,()=>{this.surface.destroy()}])}};function uo(e){(typeof HTMLElement>`u`||!(e instanceof HTMLElement))&&n(`createChart() needs an HTMLElement container.`);let r=e.ownerDocument.defaultView??n(`The container is not attached to a window.`),i=[[`ResizeObserver`,typeof r.ResizeObserver==`function`],[`PointerEvent`,typeof globalThis.PointerEvent==`function`],[`Path2D`,typeof globalThis.Path2D==`function`],[`matchMedia`,typeof r.matchMedia==`function`],[`requestAnimationFrame`,typeof r.requestAnimationFrame==`function`],[`Intl.DateTimeFormat`,typeof globalThis.Intl.DateTimeFormat==`function`]].filter(([,e])=>!e).map(([e])=>e);if(i.length>0)throw new t(`This browser lacks required APIs: ${i.join(`, `)}.`);return r}let fo=[`version`,`mainSeries`,`transform`,`view`,`panes`];function po(e){let t=Object.fromEntries(e.stateParts.map(e=>[e.key,e.save()]));return structuredClone({version:1,mainSeries:{type:e.options.mainSeries.type,source:e.options.mainSeries.source},transform:ho(e.market.transform()),view:e.timeScale.state(),panes:e.panes.list().map(e=>{let{right:t}=e;return{id:e.id,title:e.title,height:e.height,auto:e.auto,mode:t.mode,inverted:t.invert,range:t.scale.manualRange(),margins:t.margins,scales:[...e.scales.values()].filter(e=>e.id!==fe).map(e=>({id:e.id,mode:e.mode,inverted:e.invert,margins:e.margins,range:e.scale.manualRange()}))}}),...t})}function mo(e,t){h(`state`,t),t.version!==1&&n(`Unsupported chart state: expected version 1, received ${i(t.version)}.`);for(let r of Object.keys(t))!fo.includes(r)&&!e.stateParts.some(e=>e.key===r)&&n(`The state has "${r}", which no module of the chart keeps.`);h(`state.mainSeries`,t.mainSeries),v(`state.panes`,t.panes),h(`state.view`,t.view),e.seriesTypes.require(t.mainSeries.type),t.transform!==void 0&&t.transform!==null&&e.market.checkTransform(t.transform);let r=e.options,a=new ve(r.panes.defaultHeight,r.priceScale.margins);t.panes[0]?.id!==`main`&&n(`The first pane of a chart state must be the main pane.`),t.panes.forEach((e,t)=>{h(`state.panes[${t}]`,e);let n=t===0?a.require(x):a.add({id:p(`panes[${t}].id`,e.id),title:e.title,height:e.height},e.auto);a.update(n.id,{title:e.title,height:d(`panes[${t}].height`,e.height,{min:1})}),e.scales!==void 0&&v(`panes[${t}].scales`,e.scales),[{id:fe,mode:e.mode,inverted:e.inverted,margins:e.margins??null,range:e.range},...e.scales??[]].forEach((e,r)=>{let i=`panes[${t}].scales[${r}]`;a.setScaleMode(n.id,e.id,e.mode),a.setScaleInverted(n.id,e.id,e.inverted),a.setScaleMargins(n.id,e.id,e.margins),e.range!==null&&(h(`${i}.range`,e.range),d(`${i}.range.min`,e.range.min),d(`${i}.range.max`,e.range.max))})});let o=e.stateParts.map(e=>e.prepare(t[e.key],a));for(let t of e.series.list())a.get(t.pane)||n(`The state has no pane "${t.pane}", which series "${t.id}" is drawn in.`);e.values.verify((e,t)=>{o.find(t=>t.values?.kind===e.kind)?.values?.check(e,t)}),d(`view.barSpacing`,t.view.barSpacing,{min:0,exclusiveMin:!0}),d(`view.offset`,t.view.offset),e.applyOptions({mainSeries:{type:t.mainSeries.type,source:t.mainSeries.source}}),t.transform!==void 0&&e.setTransform(t.transform),e.panes.adopt(a),t.panes.forEach(t=>{e.panes.require(t.id).scale.restoreManualRange(t.range),t.scales?.forEach(n=>{e.panes.ensureScale(t.id,n.id).scale.restoreManualRange(n.range)})}),o.forEach(e=>{e.apply()}),e.timeScale.restore(t.view),e.values.reset(),e.objects.prune(),e.invalidate()}function ho(e){return e&&{type:e.type,params:e.params,input:e.input}}let go=/* @__PURE__ */ new WeakMap;function _o(e){let t=Object.freeze({name:e.name});return go.set(t,e),t}function vo(e){h(`module definition`,e);let{name:t,options:r}=e;return(typeof t!=`string`||t===``)&&n(`createModule() needs the name of the module.`),typeof e.install!=`function`&&n(`The module "${t}" needs an install() function.`),r!==void 0&&(_(`The options of the module "${t}"`,r,[`key`,`defaults`,`validate`]),p(`The options key of the module "${t}"`,r.key),(typeof r.defaults!=`function`||typeof r.validate!=`function`)&&n(`The options of the module "${t}" need defaults() and validate().`)),_o({name:t,...r===void 0?{}:{options:r},extend:(t,n)=>e.install(t,n)??{}})}function yo(e){let t=e;Array.isArray(t)||n(`options.modules must be an array of modules, such as [indicators(allIndicators)].`);let r=/* @__PURE__ */ new Set;return e.map((e,t)=>{let i=go.get(e)??n(`options.modules[${t}] is not a module, such as indicators(allIndicators).`);return r.has(i.name)&&n(`The ${i.name} module is given twice.`),r.add(i.name),i})}let bo=g({time:!0,price:!0,pane:!0});function xo(e,t,n,r=[]){for(let[i,a]of Object.entries(Object.getOwnPropertyDescriptors(t))){let o=a.get?.bind(t),s=a.value;if(!r.includes(i)){if(o)Object.defineProperty(t,i,{...a,get:()=>e.run(o)});else if(typeof s==`function`){let n=s;Object.defineProperty(t,i,{...a,value:(...r)=>e.run(()=>n.apply(t,r))})}else n&&ye(s)&&xo(e,s,!1)}}return t}function So(e,t){let r=t.options,i=e.events();return{options:()=>r?e.options[r.key]:n(`The ${t.name} module has no options.`),emit:(e,t)=>{i.emit(e,t)},keepState:r=>{_(`The state part of the ${t.name} module`,r,[`key`,`save`,`read`,`load`]);let{key:i}=r;p(`The state key of the ${t.name} module`,i),(fo.includes(i)||e.stateParts.some(e=>e.key===i))&&n(`The ${t.name} module keeps "${i}" of the state, which the chart keeps already.`),e.stateParts.push({key:i,save:()=>r.save(),prepare:e=>{let t=e===void 0?null:r.read(e,`state.${i}`);return{apply:()=>{r.load(t)}}}})}}}function Co(e,t){let r=uo(e),{modules:i=[],...o}=t??{},s=yo(i),c=new lo(r,e,o,s,()=>f),l=/* @__PURE__ */ new Map,f={element:c.surface.root,options:()=>c.options,applyOptions:e=>{c.run(()=>{c.applyOptions(e)})},layout:()=>u(c.frame().layout),resize:(e,t)=>{d(`width`,e,{min:0}),d(`height`,t,{min:0}),c.run(()=>{c.resize(e,t)})},batch:e=>{ee(`operation`,e),c.run(e)},on:(e,t)=>c.bus.on(e,t),data:Ee(c),transforms:Nt(c),timeScale:jt(c),priceScale:(e=x,t=fe)=>{c.panes.require(e),p(`scale id`,t);let n=`${e}\u0000${t}`,r=l.get(n);return r||(r=xo(c,De(c,e,t),!1),l.set(n,r)),r},panes:Oe(c),series:Dt(c),crosshair:{get:()=>{let e=c.crosshair;return e&&{...e,x:e.x+c.frame().layout.leftAxisWidth}},set:e=>{c.run(()=>{if(e===null){c.setExternalCrosshair(null);return}_(`crosshair position`,e,bo);let{time:t,price:n,pane:r=x}=e;c.panes.require(r),c.setExternalCrosshair({time:a(t),price:n===void 0?null:d(`price`,n),paneId:r})})}},modules:()=>s.map(e=>e.name),select:e=>{c.run(()=>{e!==null&&(h(`selection`,e),m(`selection.kind`,e.kind,c.objects.kinds()),p(`selection.id`,e.id),c.objects.exists(e)||n(`There is no ${e.kind} with id "${e.id}".`)),c.select(e)})},selection:()=>c.objects.selection,saveState:()=>po(c),loadState:e=>{c.run(()=>{mo(c,e)})},screenshot:()=>c.run(()=>(c.flush(),c.surface.composite())),plugins:{add:e=>{c.run(()=>{c.plugins.add(e)})},remove:e=>{c.run(()=>{c.plugins.remove(e)})},get:e=>c.plugins.get(e),list:()=>c.plugins.list()},destroy:()=>{c.destroy()}};Object.assign(f,c.moduleApis),xo(c,f,!0,[`destroy`]);try{for(let e of s)for(let[t,r]of Object.entries(e.extend?.(f,So(c,e))??{}))Object.hasOwn(f,t)&&n(`The ${e.name} module adds chart.${t}, which the chart has already.`),Object.assign(f,{[t]:r});c.seriesTypes.require(c.options.mainSeries.type)}catch(e){throw c.destroy(),e}return f}function wo(e,t,r,i,a){v(e,t);let o=t.map((t,n)=>({input:t,settings:a(t,`${e}[${n}]`)})),s=/* @__PURE__ */ new Set;o.forEach(({input:t},r)=>{if(t.id!==void 0){let i=p(`${e}[${r}].id`,t.id);s.has(i)&&n(`${e} contains the id "${i}" twice.`),s.add(i)}}),s.forEach(e=>{r.note(e)});let c=/* @__PURE__ */ new Map;return o.forEach(({input:e,settings:t})=>{let n=e.id??r.next(i);r.note(n),c.set(n,{id:n,...t})}),c}function To(e,t){let n=t=>e.run(()=>{let n=t();return e.objects.prune(),e.invalidateLayers(`objects`),n});return{set:e=>{n(()=>{t.set(e)})},add:e=>n(()=>t.add(e)),update:(e,r)=>{n(()=>{t.update(e,r)})},remove:e=>{n(()=>{t.remove(e)})},clear:()=>{n(()=>{t.set([])})},get:e=>t.get(e),list:()=>t.list()}}function Eo(e,t){return{context:()=>e.objectContext(),repaint:()=>{e.invalidateLayers(`objects`)},formatValue:(t,n)=>Vn(e,t,n),dragged:t}}let Do=[`cross`,`cross-up`,`cross-down`,`above`,`below`,`enter-channel`,`exit-channel`,`inside-channel`,`outside-channel`],Oo=[`once`,`once-per-bar`,`once-per-bar-close`,`every-time`],ko={kind:`price`,field:`close`},Ao=g({id:!0,source:!0,trigger:!0,value:!0,frequency:!0,enabled:!0,label:!0,color:!0,lineStyle:!0,draggable:!0,visible:!0,buttons:!0}),jo={price:g({kind:!0,field:!0}),indicator:g({kind:!0,id:!0,key:!0}),series:g({kind:!0,id:!0}),drawing:g({kind:!0,id:!0,level:!0})};function Mo(e,t,r){switch(h(t,e),Object.hasOwn(jo,e.kind)&&_(t,e,jo[e.kind]),e.kind){case`price`:return{kind:`price`,field:e.field===void 0?`close`:m(`${t}.field`,e.field,Xt)};case`indicator`:return p(`${t}.id`,e.id),e.key!==void 0&&p(`${t}.key`,e.key),r.check(e,t),{kind:`indicator`,id:e.id,...e.key===void 0?{}:{key:e.key}};case`series`:return p(`${t}.id`,e.id),r.check(e,t),{kind:`series`,id:e.id};case`drawing`:return p(`${t}.id`,e.id),e.level!==void 0&&p(`${t}.level`,e.level),r.check(e,t),{kind:`drawing`,id:e.id,...e.level===void 0?{}:{level:e.level}};default:return n(`${t}.kind must be "price", "indicator", "series" or "drawing".`)}}function No(e){return Array.isArray(e)?e:[e]}function Po(e,t,n){return typeof e==`number`?d(t,e):Mo(e,t,n)}function Fo(e,t,r,i){let a=t.endsWith(`-channel`);return(Array.isArray(e)!==a||a&&e.length!==2)&&n(`${i} of a "${t}" alert must be ${a?`a channel's two bounds`:`one value`}.`),a?e.map((e,t)=>Po(e,`${i}[${t}]`,r)):Po(e,i,r)}function Io(e,t,n=`alert`){_(n,e,Ao),e.label!==void 0&&p(`${n}.label`,e.label);let r=m(`${n}.trigger`,e.trigger,Do);return{source:Mo(e.source??ko,`${n}.source`,t),trigger:r,value:Fo(e.value,r,t,`${n}.value`),frequency:e.frequency===void 0?`once`:m(`${n}.frequency`,e.frequency,Oo),enabled:e.enabled===void 0||f(`${n}.enabled`,e.enabled),label:e.label??null,color:e.color===void 0?null:S(`${n}.color`,e.color),lineStyle:e.lineStyle===void 0?`solid`:m(`${n}.lineStyle`,e.lineStyle,ln),draggable:e.draggable===void 0||f(`${n}.draggable`,e.draggable),visible:e.visible===void 0||f(`${n}.visible`,e.visible),buttons:ea(e.buttons,`${n}.buttons`)}}function Lo(e){return{source:e.source,trigger:e.trigger,value:e.value,frequency:e.frequency,enabled:e.enabled,lineStyle:e.lineStyle,draggable:e.draggable,visible:e.visible,buttons:e.buttons.map(e=>({...e})),...e.label===null?{}:{label:e.label},...e.color===null?{}:{color:e.color}}}let Ro=[`above`,`below`,`inside-channel`,`outside-channel`];function zo(e,t){let n=e=>JSON.stringify([e.source,e.trigger,e.value,e.frequency,e.enabled]);return n(e)===n(t)}function Bo(e){return e.status===`active`}function Vo(e){return[Math.min(...e),Math.max(...e)]}function Ho(e,t,n,r){return e<=t&&n>r}function Uo(e,t,n,r){return e>=t&&n<r}function Wo(e,[t,n]){return e>t&&e<n}function Go(e,[t,n]){return e<t||e>n}function Ko(e,t,n,r,i){let[a,o]=n,[s,c]=i;switch(e){case`above`:return r>c;case`below`:return r<s;case`cross-up`:return Ho(t,o,r,c);case`cross-down`:return Uo(t,a,r,s);case`cross`:return Ho(t,o,r,c)||Uo(t,a,r,s);case`enter-channel`:return Wo(r,i)&&!Wo(t,n);case`exit-channel`:return Go(r,i)&&!Go(t,n);case`inside-channel`:return Wo(r,i);case`outside-channel`:return Go(r,i)}}function qo(e,t,n,r,[i,a]){return e===`enter-channel`?t<=n?i:a:e===`inside-channel`?r-i<=a-r?i:a:r<i?i:a}var Jo=class{host;states=/* @__PURE__ */ new Map;ids=new de(e=>this.states.has(e));constructor(e){this.host=e}all(){return this.states.values()}config(e){return this.states.get(e)?.config}setLevel(e,t,n){let r=this.require(e),i=r.config.value;r.config={...r.config,value:t===null||!Array.isArray(i)?n:No(i).map((e,r)=>r===t?n:e)},this.baseline(r)}settle(e){this.baseline(this.require(e))}has(e){return this.states.has(e)}list(){return[...this.states.values()].map(e=>this.info(e))}get(e){let t=this.states.get(e);return t?this.info(t):null}uses(e,t){return[...this.states.values()].flatMap(({config:n})=>[n.source,...No(n.value)].flatMap(r=>typeof r!=`number`&&r.kind===e&&`id`in r&&r.id===t?[{user:n.id,source:r}]:[]))}verify(e){this.states.forEach(({config:t})=>{[t.source,...No(t.value)].forEach(n=>{typeof n!=`number`&&e(n,`alert "${t.id}"`)})})}rebaseline(){this.states.forEach(e=>{this.baseline(e)})}set(e){let t=wo(`alerts`,e,this.ids,`alert`,(e,t)=>Io(e,this.host.reader,t)),n=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let r=this.states.get(t);r&&zo(r.config,e)?(r.config=e,n.set(t,r)):n.set(t,this.createState(e))}),this.states=n}add(e){let t=Io(e,this.host.reader),r=e.id===void 0?this.ids.next(`alert`):p(`alert.id`,e.id);return this.states.has(r)&&n(`An alert with id "${r}" already exists.`),this.states.set(r,this.createState({id:r,...t})),this.ids.note(r),r}update(e,t){let n=this.require(e),r={id:e,...Io({...Lo(n.config),...t},this.host.reader)},i=!zo(n.config,r);n.config=r,r.enabled?(i||n.status===`disabled`)&&(n.status=`active`):n.status=`disabled`,this.baseline(n)}remove(e){this.require(e),this.states.delete(e)}rearm(e){let t=this.require(e);t.config.enabled&&(t.status=`active`,t.triggeredAt=null,this.baseline(t))}require(e){return this.states.get(e)??n(`Unknown alert "${e}".`)}info(e){return{...e.config,status:e.status,triggeredAt:e.triggeredAt}}createState(e){let t={config:e,status:e.enabled?`active`:`disabled`,triggeredAt:null,last:NaN,lastThresholds:[],lastIndex:-1,closedIndex:-1};return this.baseline(t),t}thresholds(e,t){return No(e.value).map(e=>typeof e==`number`?e:this.host.reader.read(e,t))}baseline(e){let{config:t}=e,n=this.host.bars.length-1,r=this.host.settled()-1,i=t.frequency===`once-per-bar-close`?r:n;e.closedIndex=r,e.lastIndex=i,e.last=i>=0?this.host.reader.read(t.source,i):NaN,e.lastThresholds=i>=0?this.thresholds(t,i):[]}evaluate(e){for(let t of this.states.values()){if(e.kind===`reset`||t.status!==`active`){this.baseline(t);continue}let n=this.host.bars.length-1;if(t.config.frequency===`once-per-bar-close`){let e=this.host.settled();for(let n=t.closedIndex+1;n<e&&Bo(t);n+=1)this.step(t,n),t.closedIndex=n}else if(n>=0){let r=Math.min(Math.max(e.from,t.lastIndex),n);for(let e=r;e<=n&&Bo(t);e+=1)this.step(t,e)}}}step(e,t){let{config:n}=e,r=this.host.reader.read(n.source,t),i=this.thresholds(n,t),a=this.host.bars.time(t),o=(t,n)=>typeof t!=`number`&&this.host.reader.movable(t)&&e.lastIndex>=0?this.host.reader.read(t,e.lastIndex):n,s=o(n.source,e.last),c=No(n.value).map((t,n)=>o(t,e.lastThresholds[n]??NaN)),l=Ro.includes(n.trigger)?[r,...i]:[r,...i,s,...c],u=Vo(i),d=Vo(c),f=l.every(Number.isFinite)&&Ko(n.trigger,s,d,r,u)&&(n.frequency!==`once-per-bar`||e.triggeredAt!==a);e.last=r,e.lastThresholds=i,e.lastIndex=t,f&&(e.triggeredAt=a,n.frequency===`once`&&(e.status=`triggered`),this.host.triggered({id:n.id,time:a,value:r,threshold:qo(n.trigger,s,d[0],r,u),trigger:n.trigger}))}};function Yo(e){let{id:t,value:n}=e;return typeof n==`number`?[{id:t,bound:null,value:n}]:Array.isArray(n)?No(n).flatMap((e,n)=>typeof e==`number`?[{id:t,bound:n,value:e}]:[]):[]}function Xo(e,t){return t.bound===null||e.startsWith(`button:`)?e:`${e}:${t.bound}`}function Zo(e){let t=/^(?:line|label):(\d)$/.exec(e)?.[1];return t===void 0?null:Number(t)}var Qo=class{host;kind=`alert`;book;icons=new Li;constructor(e,t){this.host=t,this.book=new Jo({bars:e,reader:t.reader,settled:()=>t.settled(),triggered:e=>{t.triggered(e)}})}has(e){return this.book.has(e)}list(){return this.book.list()}get(e){return this.book.get(e)}uses(e,t){return this.book.uses(e,t)}verify(e){this.book.verify(e)}rebaseline(){this.book.rebaseline()}set(e){this.book.set(e)}add(e){return this.book.add(e)}update(e,t){this.book.update(e,t)}remove(e){this.book.remove(e)}rearm(e){this.book.rearm(e)}evaluate(e){this.book.evaluate(e)}layouts(e){let t=/* @__PURE__ */ new Map,n=[],{theme:r}=e.options;for(let{config:i,status:a}of this.book.all()){let o=i.visible?Yo(i):[],s=o.length>0?this.host.reader.paneOf(i.source):null,c=s===null?null:O(e.frame,s),l=s===null?null:e.scaleOf(s,this.host.reader.scaleOf(i.source));if(s===null||!c||!l)continue;let u=i.color??r.alert,d=t.get(s)??[];for(let t of o)d.push({id:String(n.length),y:l.valueToY(t.value),color:a===`active`?u:C(u,.45),text:i.label??``,axisText:this.host.formatValue({...c,scale:l},t.value),buttons:i.buttons,lineStyle:i.lineStyle,emphasized:e.selection?.kind===`alert`&&e.selection.id===i.id||e.hovered?.kind===`alert`&&e.hovered.id===i.id}),n.push(t);t.set(s,d)}return{panes:[...t.entries()].flatMap(([t,n])=>{let r=O(e.frame,t);return r?[{pane:r,layouts:ia(n,r.plot.width,r.plot.height,e.options.font.size,(t,n)=>e.measureText(t,E(n,e.options.font.family)),e.options.priceScale.pinLabels)}]:[]}),lines:n}}hitTest(e,t){let{panes:n,lines:r}=this.layouts(e);for(let{pane:i,layouts:a}of n){if(t.y<i.plot.y||t.y>=i.plot.y+i.plot.height)continue;let n=oa(a,{x:t.x,y:t.y-i.plot.y},e.options.interaction.hitTolerance),o=n?r[Number(n.id)]:void 0,s=o?this.book.config(o.id):void 0;if(n&&o&&s){let e=s.draggable&&!n.part.startsWith(`button:`);return{target:{kind:`alert`,id:o.id,part:Xo(n.part,o),cursor:e?`ns-resize`:`pointer`,draggable:e},priority:n.priority,distance:n.distance}}}return null}reveal(e,t){let n=this.book.config(t.id),r=/:(\d)$/.exec(t.part)?.[1],i=n?Yo(n).find(e=>e.bound===(r===void 0?null:Number(r))):void 0;return!n||!i?null:{pane:this.host.reader.paneOf(n.source),scale:this.host.reader.scaleOf(n.source),value:i.value}}beginDrag(e,t){let n=this.book.config(t.id),r=Zo(t.part),i=n?Yo(n).find(e=>e.bound===r):void 0;if(!n||!i||!n.draggable)return null;let{id:a}=n,o=this.host.reader.paneOf(n.source),s=this.host.reader.scaleOf(n.source);if(!O(e.frame,o)||!e.scaleOf(o,s))return null;let c=i.value,l=c,u=(e,t)=>{this.host.dragged({id:a,phase:e,price:t,initialPrice:c,bound:r})},d=e=>{this.book.has(a)&&this.book.setLevel(a,r,e),this.host.repaint()};return u(`start`,l),{move:e=>{let t=O(this.host.context().frame,o);if(!t||!this.book.has(a))return;let n=this.host.context().scaleOf(o,s),r=n?Zi(n,t.format,e.y-t.plot.y):NaN;Number.isFinite(r)&&r!==l&&(l=r,d(l),u(`move`,l))},end:()=>{this.book.has(a)&&this.book.settle(a),u(`end`,l)},cancel:()=>{d(c),u(`cancel`,c)}}}paint(e){let{ctx:t}=e;for(let{pane:n,layouts:r}of this.layouts(e).panes)t.save(),t.beginPath(),t.rect(0,n.plot.y,e.frame.layout.width,n.plot.height),t.clip(),sa(t,r,n.plot,n.axis,{fontSize:e.options.font.size,fontFamily:e.options.font.family,pixelRatio:e.pixelRatio,textColor:`#ffffff`,showAxis:e.options.priceScale.visible},this.icons),t.restore()}};function $o(){return _o({name:`alerts`,install:e=>{let t=e.events(),n=new Qo(e.bars,{...Eo(e,e=>{t.emit(`alertDrag`,e)}),reader:e.values,settled:()=>e.market.settled(),triggered:n=>{e.invalidateLayers(`objects`),t.emit(`alertTrigger`,{...n,replay:e.replaying})}});return e.objects.add(n,30),e.values.use({noun:`alert`,uses:(e,t)=>n.uses(e,t),reset:()=>{n.rebaseline()},verify:e=>{n.verify(e)}}),e.hooks.barsChanged.push(e=>{n.evaluate(e)}),{alerts:{...To(e,n),rearm:t=>{e.run(()=>{n.rearm(t),e.invalidateLayers(`objects`)})}}}}})}function es(e,t){return`Trades have no true range to size the "${e}" transform by: give ${t}.`}function ts(e,t,r,i){let a=[t,`percentage`,`atrLength`].filter(e=>r[e]!==void 0);return a.length>1&&n(`The "${e}" transform takes one of params.${t}, params.percentage and params.atrLength, received ${a.map(e=>`params.${e}`).join(` and `)}.`),r[t]===void 0?r.percentage===void 0?(i===`trades`&&n(es(e,`params.${t} or params.percentage`)),{kind:`atr`,length:r.atrLength===void 0?14:d(`params.atrLength`,r.atrLength,{min:1,max:1e3,integer:!0})}):{kind:`percentage`,percentage:d(`params.percentage`,r.percentage,{min:0,exclusiveMin:!0,max:100})}:{kind:`fixed`,size:d(`params.${t}`,r[t],{min:0,exclusiveMin:!0})}}function ns(e){let t=10**Math.floor(Math.log10(e));return Number((Math.round(2*e/t)*t/2).toPrecision(12))}function rs(e,t,n){return Number.isNaN(n)?e-t:Math.max(e,n)-Math.min(t,n)}function is(e,t,n,r){return t<r?(e*t+n)/(t+1):(e*(r-1)+n)/r}function as(e,t,n=e.length){let r=0;for(let i=0;i<n;i+=1){let n=i>0?e.close(i-1):NaN,a=rs(e.high(i),e.low(i),n);r=is(r,i,a,t)}return n>0?r:NaN}function os(e,t){let n=Math.abs(t)*e/100;return n>0?ns(n):NaN}function ss(e,t){switch(e.kind){case`fixed`:return e.size;case`percentage`:return t.length>1?os(e.percentage,t.close(t.length-2)):NaN;case`atr`:{let n=t.length-1,r=n>=e.length?as(t,e.length,n):0;return r>0?ns(r):NaN}}}var cs=class e{rule;build;stream;waiting;average;close;constructor(e,t,n=null,r=[],i=0,a=NaN){this.rule=e,this.build=t,this.stream=n,this.waiting=r,this.average=i,this.close=a}next(e){if(this.stream)return this.stream.next(e,null);let{rule:t,waiting:n}=this,r=n.length,i=t.kind===`percentage`?os(t.percentage,this.close):r>=t.length&&this.average>0?ns(this.average):NaN;if(t.kind===`atr`){let n=rs(e.high,e.low,this.close);this.average=is(this.average,r,n,t.length)}if(this.close=e.close,n.push(e),Number.isNaN(i))return[];let a=this.build(i);return this.stream=a,n.splice(0).flatMap(e=>a.next(e,null))}current(){return this.stream?.current()??null}clone(){return new e(this.rule,this.build,this.stream?.clone()??null,[...this.waiting],this.average,this.close)}resolved(){return this.stream?.resolved?.()??null}};function ls(e,t,n){let r=ss(e,t);return e.kind===`fixed`||!Number.isNaN(r)?n(r):new cs(e,n)}let us=1e4;function ds(e,t,r){r/t>us&&n(`The "${e}" size ${t} is too small for these prices: one bar would make more than ${us} bars.`)}function fs(e,t,r){for(let i of Object.keys(t))r.includes(i)||n(`The "${e}" transform has no parameter "${i}".`)}var ps=class e{previous;forming;constructor(e=null,t=null){this.previous=e,this.forming=t}next(e){let t=this.forming;this.previous=t??this.previous;let n=(e.open+e.high+e.low+e.close)/4,r=this.previous?(this.previous.open+this.previous.close)/2:(e.open+e.close)/2;return this.forming={time:e.time,open:r,high:Math.max(e.high,r,n),low:Math.min(e.low,r,n),close:n,volume:e.volume},t?[t]:[]}current(){return this.forming}clone(){return new e(this.previous,this.forming)}};let ms={type:`heikin-ashi`,name:`Heikin-Ashi`,keepsTime:!0,create:e=>(fs(`heikin-ashi`,e,[]),new ps)};var hs=class e{range;state;constructor(e,t){this.range=e,this.state=t}next(e){let t=this.state,n=this.range,r=[],i=e.close>=e.open?[e.open,e.low,e.high,e.close]:[e.open,e.high,e.low,e.close],a=t=>({time:e.time,open:t,high:t,low:t,close:t,volume:0}),o=t.forming?.open??e.open;ds(`range`,n,Math.max(e.high-o,o-e.low));for(let e of i){let i=t.forming??a(e);for(;e-i.low>n;){let e=i.low+n;r.push({...i,high:e,close:e}),i=a(e)}for(;i.high-e>n;){let e=i.high-n;r.push({...i,low:e,close:e}),i=a(e)}i.high=Math.max(i.high,e),i.low=Math.min(i.low,e),i.close=e,t.forming=i}return t.forming&&(t.forming.volume+=e.volume),r}current(){return this.state.forming?{...this.state.forming}:null}clone(){return new e(this.range,{forming:this.state.forming?{...this.state.forming}:null})}resolved(){return{range:this.range}}};let gs={type:`range`,name:`Range`,keepsTime:!1,create:(e,t,r)=>(fs(`range`,e,[`range`]),e.range===void 0&&r===`trades`&&n(es(`range`,`params.range`)),ls(e.range===void 0?{kind:`atr`,length:14}:{kind:`fixed`,size:d(`params.range`,e.range,{min:Number.MIN_VALUE})},t,e=>new hs(e,{forming:null})))};var _s=class e{count;state;constructor(e,t){this.count=e,this.state=t}next(e){let t=this.state;if(Number.isNaN(t.time)&&(t.time=e.time),t.volume+=e.volume,Number.isNaN(t.reference))return t.reference=e.close,[];let n=t.lines.map(e=>Math.max(e.open,e.close)),r=t.lines.map(e=>Math.min(e.open,e.close)),i=t.lines.length>0?Math.max(...n):t.reference,a=t.lines.length>0?Math.min(...r):t.reference,o=t.lines.length-1,s;if(e.close>i)s=n[o]??t.reference;else if(e.close<a)s=r[o]??t.reference;else return[];let c={time:t.time,open:s,high:Math.max(s,e.close),low:Math.min(s,e.close),close:e.close,volume:t.volume};return t.lines.push({open:s,close:e.close}),t.lines.length>this.count&&t.lines.shift(),t.time=NaN,t.volume=0,[c]}current(){return null}clone(){return new e(this.count,{...this.state,lines:[...this.state.lines]})}};let vs={type:`line-break`,name:`Line break`,keepsTime:!1,create:e=>(fs(`line-break`,e,[`lines`]),new _s(e.lines===void 0?3:d(`params.lines`,e.lines,{min:1,max:100,integer:!0}),{lines:[],reference:NaN,time:NaN,volume:0}))};function ys(e,t,r,i){return fs(e,r,[t]),r[t]===void 0&&n(`The "${e}" transform needs params.${t}, the ${i} of each bar.`),d(`params.${t}`,r[t],{min:0,exclusiveMin:!0})}var bs=class e{measure;size;forming;amount;constructor(e,t,n=null,r=0){this.measure=e,this.size=t,this.forming=n,this.amount=r}next(e){let t=this.forming,n=t?{time:t.time,open:t.open,high:Math.max(t.high,e.high),low:Math.min(t.low,e.low),close:e.close,volume:t.volume+e.volume}:e,r=this.amount+this.measure(e);return r>=this.size*(1-1e-9)?(this.forming=null,this.amount=0,[n]):(this.forming=n,this.amount=r,[])}current(){return this.forming}clone(){return new e(this.measure,this.size,this.forming,this.amount)}};let xs={type:`tick`,name:`Tick`,keepsTime:!1,create:e=>(fs(`tick`,e,[`count`]),e.count===void 0&&n(`The "tick" transform needs params.count, the trades of each bar.`),new bs(()=>1,d(`params.count`,e.count,{min:1,integer:!0})))},Ss={type:`volume`,name:`Volume`,keepsTime:!1,create:e=>new bs(e=>e.volume,ys(`volume`,`volume`,e,`volume`))},Cs={type:`turnover`,name:`Turnover`,keepsTime:!1,create:e=>new bs(e=>(e.high+e.low+e.close)/3*e.volume,ys(`turnover`,`turnover`,e,`turnover`))},ws=e=>({time:e.time,open:e.open,high:Math.max(e.open,e.close),low:Math.min(e.open,e.close),close:e.close,volume:e.volume});var Ts=class e{reversal;state;constructor(e,t){this.reversal=e,this.state=t}next(e){let t=this.state;if(Number.isNaN(t.start))return t.start=e.close,t.startTime=e.time,t.pending=e.volume,[];let n=this.reversal*(1-1e-9),r=t.line;if(!r)return t.pending+=e.volume,Math.abs(e.close-t.start)>=n&&(t.line={time:t.startTime,open:t.start,close:e.close,volume:t.pending},t.pending=0),[];let i=r.close>r.open;return(i?e.close>r.close:e.close<r.close)?(r.close=e.close,r.volume+=t.pending+e.volume,t.pending=0,[]):(i?r.close-e.close:e.close-r.close)>=n?(t.line={time:e.time,open:r.close,close:e.close,volume:t.pending+e.volume},t.pending=0,[ws(r)]):(t.pending+=e.volume,[])}current(){return this.state.line?ws(this.state.line):null}clone(){let t=this.state.line;return new e(this.reversal,{...this.state,line:t?{...t}:null})}resolved(){return{reversal:this.reversal}}};let Es={type:`kagi`,name:`Kagi`,keepsTime:!1,create:(e,t,n)=>(fs(`kagi`,e,[`reversal`,`percentage`,`atrLength`]),ls(ts(`kagi`,`reversal`,e,n),t,e=>new Ts(e,{start:NaN,startTime:NaN,line:null,pending:0})))};function Ds(e,t){if(t<2)return null;let n=e.close(t),r=e.close(t-2);return n>e.open(t)?n>r||null:n<r?!1:null}function Os(e,t){for(let n=t-1;n>=2;--n){let t=Ds(e,n);if(t!==null)return t}return e.close(0)>e.open(0)}function ks(e){let{ctx:t,points:r,style:i,pixelRatio:a,valueToY:o,first:s}=e,c=e.bars??n(`Kagi lines are OHLC bars.`),l=[],u=null,d=null,f=(e,t,n)=>{let r=n?i.upWidth:i.downWidth;return[T(e,r,a),T(t,r,a)]},p=(e,t,n)=>{if(u?.yang===n)u.points.push(...f(e,t,n));else{let r=d??[e,t];u={yang:n,points:[...f(r[0],r[1],n),...f(e,t,n)]},l.push(u)}d=[e,t]},m=Os(c,s);for(let e=0;e<r.count;e+=1){let t=s+e,n=r.x(e),i=Ds(c,t);p(n,r.open(e),m),i!==null&&i!==m&&(p(n,o(c.close(t-2)),m),m=i),p(n,r.close(e),m)}t.lineJoin=`miter`,t.lineCap=`butt`,t.setLineDash([]);for(let e of[!0,!1]){t.beginPath();for(let n of l)if(n.yang===e){t.moveTo(n.points[0]??0,n.points[1]??0);for(let e=2;e<n.points.length;e+=2)t.lineTo(n.points[e]??0,n.points[e+1]??0)}t.strokeStyle=e?i.upColor:i.downColor,t.lineWidth=e?i.upWidth:i.downWidth,t.stroke()}}let As={type:`kagi`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,upWidth:2,downWidth:1}),paint:ks},js=[`close`,`hl`],Ms=1e-9;var Ns=class e{settings;state;constructor(e,t){this.settings=e,this.state=t}next(e){let t=this.state,{box:n,reversal:r,source:i}=this.settings;Number.isNaN(t.start)&&(t.start=e.open,t.startTime=e.time);let a=Math.floor((i===`hl`?e.high:e.close)/n+Ms),o=Math.ceil((i===`hl`?e.low:e.close)/n-Ms),s=t.column;if(!s){t.pending+=e.volume;let i=t.start/n;return a>=Math.floor(i+Ms)+r?t.column=this.open(t.startTime,!0,Math.floor(i+Ms),a):o<=Math.ceil(i-Ms)-r&&(t.column=this.open(t.startTime,!1,Math.ceil(i-Ms),o)),[]}let c=s.rising?a>=s.last+1:o<=s.last-1,l=s.rising?o<=s.last-r:a>=s.last+r;if(c)return s.last=s.rising?a:o,s.volume+=t.pending+e.volume,t.pending=0,[];if(t.pending+=e.volume,!l)return[];let u=s.rising?o:a;if(this.settings.oneStepBack&&s.first===s.last)return s.rising=!s.rising,s.last=u,s.volume+=t.pending,t.pending=0,[];let d=s.rising?s.last-1:s.last+1;return t.column=this.open(e.time,!s.rising,d,u),[this.bar(s)]}current(){return this.state.column?this.bar(this.state.column):null}clone(){let t=this.state.column;return new e(this.settings,{...this.state,column:t?{...t}:null})}resolved(){let{box:e,reversal:t,source:n,oneStepBack:r}=this.settings;return{box:e,reversal:t,source:n,oneStepBack:r}}open(e,t,n,r){let i=this.state.pending;return this.state.pending=0,{time:e,rising:t,first:n,last:r,volume:i}}bar(e){let t=e=>Number((e*this.settings.box).toPrecision(12)),n=t(e.first),r=t(e.last);return{time:e.time,open:n,high:Math.max(n,r),low:Math.min(n,r),close:r,volume:e.volume}}};let Ps={type:`point-figure`,name:`Point & figure`,keepsTime:!1,create:(e,t,n)=>{fs(`point-figure`,e,[`box`,`percentage`,`atrLength`,`reversal`,`source`,`oneStepBack`]);let r=ts(`point-figure`,`box`,e,n),i={reversal:e.reversal===void 0?3:d(`params.reversal`,e.reversal,{min:1,max:100,integer:!0}),source:e.source===void 0?`close`:m(`params.source`,e.source,js),oneStepBack:e.oneStepBack!==void 0&&f(`params.oneStepBack`,e.oneStepBack)};return ls(r,t,e=>new Ns({...i,box:e},{start:NaN,startTime:NaN,column:null,pending:0}))}},Fs=.12;function Is(e){let{ctx:t,points:r,style:i,pixelRatio:a,barSpacing:o,valueToY:s,first:c,transform:l}=e,u=e.bars??n(`Point & figure columns are OHLC bars.`),d=l?.box,f=i.box??(typeof d==`number`?d:NaN);if(!(f>0))return;let p=Math.max(1/a,o*i.widthRatio),m=[],h=[],g=[];for(let e=0;e<r.count;e+=1){let t=c+e,n=u.open(t),i=u.close(t),a=i>n,o=t>0?n>u.close(t-1):a,l=a?f:-f,d=Math.round(Math.abs(i-n)/f)+1,_=r.x(e);if(Math.abs(s(n+f/2)-s(n-f/2))<4||p<4)g.push({rising:a,x:_,top:s(Math.max(n,i)+f/2),bottom:s(Math.min(n,i)-f/2)});else for(let e=0;e<d;e+=1){let t=n+e*l,r=s(t+f/2),i=s(t-f/2);if(!Number.isFinite(r)||!Number.isFinite(i))continue;let c=p*Fs,u=Math.abs(i-r)*Fs;((e===0?o:a)?m:h).push(_-p/2+c,Math.min(r,i)+u,_+p/2-c,Math.max(r,i)-u)}}t.setLineDash([]),t.lineWidth=i.lineWidth,t.lineCap=`round`,t.beginPath();for(let e=0;e<m.length;e+=4){let[n=0,r=0,i=0,a=0]=m.slice(e,e+4);t.moveTo(n,r),t.lineTo(i,a),t.moveTo(n,a),t.lineTo(i,r)}t.strokeStyle=i.upColor,t.stroke(),t.beginPath();for(let e=0;e<h.length;e+=4){let[n=0,r=0,i=0,a=0]=h.slice(e,e+4),o=(i-n)/2;t.moveTo(i,(r+a)/2),t.ellipse(n+o,(r+a)/2,o,(a-r)/2,0,0,Math.PI*2)}t.strokeStyle=i.downColor,t.stroke();for(let e of g){let n=_n(e.x-p/2,a);t.fillStyle=e.rising?i.upColor:i.downColor,t.fillRect(n,Math.min(e.top,e.bottom),Math.max(1/a,_n(p,a)),Math.abs(e.bottom-e.top))}}let Ls={type:`point-figure`,input:`ohlc`,defaultStyle:e=>({upColor:e.up,downColor:e.down,lineWidth:1.5,widthRatio:.85,box:null}),paint:Is},Rs=[`close`,`ohlc`],zs=1e-9;var Bs=class e{settings;state;constructor(e,t){this.settings=e,this.state=t}next(e){let t=this.state,n=this.settings.source===`close`?[e.close]:e.close>=e.open?[e.open,e.low,e.high,e.close]:[e.open,e.high,e.low,e.close],r=[];for(let i of n)t.volume+=e.volume/n.length,t.high=Math.max(t.high,i),t.low=Math.min(t.low,i),this.reach(i,e.time,r);return r}current(){return null}clone(){return new e(this.settings,{...this.state})}resolved(){let{box:e,source:t,wicks:n}=this.settings;return{box:e,source:t,wicks:n}}reach(e,t,n){let r=this.state,i=this.settings.box,a=e/i;Number.isNaN(r.bottom)&&(r.bottom=Math.floor(a+zs),r.top=r.bottom+1),ds(`renko`,i,Math.max(e-r.top*i,r.bottom*i-e));let o=[];for(;a>=r.top+1-zs;)o.push([r.top,r.top+1]),r.bottom=r.top,r.top+=1;for(;a<=r.bottom-1+zs;)o.push([r.bottom,r.bottom-1]),r.top=r.bottom,--r.bottom;if(o.length===0)return;let s=e=>Number((e*i).toPrecision(12)),c=r.volume/o.length;o.forEach(([e,a],o)=>{let l=s(e),u=s(a),d=this.settings.wicks&&o===0,f=a>e;n.push({time:t,open:l,high:d&&!f&&r.high/i>e+1+zs?r.high:Math.max(l,u),low:d&&f&&r.low/i<e-1-zs?r.low:Math.min(l,u),close:u,volume:c})}),r.volume=0,r.high=-1/0,r.low=1/0}};let Vs={type:`renko`,name:`Renko`,keepsTime:!1,create:(e,t,n)=>{fs(`renko`,e,[`box`,`percentage`,`atrLength`,`source`,`wicks`]);let r=ts(`renko`,`box`,e,n),i=e.source===void 0?`close`:m(`params.source`,e.source,Rs),a=e.wicks===void 0||f(`params.wicks`,e.wicks);return ls(r,t,e=>new Bs({box:e,source:i,wicks:a},{bottom:NaN,top:NaN,volume:0,high:-1/0,low:1/0}))}};function Hs(e){let{ctx:t,points:n,style:r,pixelRatio:i,barSpacing:a}=e,o=1/i,s=0;for(let e=0;e<n.count;e+=1)s=Math.max(s,n.volume(e)||0);let c=e=>Math.max(o,_n(a*r.bodyRatio*(n.volume(e)||0)/(s||1),i));t.setLineDash([]);for(let e of zr(n)){let{up:a,color:s}=e,l=s??(a?r.upColor:r.downColor);if(r.wick){t.beginPath();for(let r of e.indices){let e=T(n.x(r),1,i);t.moveTo(e,n.high(r)),t.lineTo(e,n.low(r))}t.strokeStyle=s??(a?r.upWickColor:r.downWickColor),t.lineWidth=o,t.stroke()}t.beginPath();for(let r of e.indices){let e=c(r),a=n.open(r),s=n.close(r);t.rect(_n(n.x(r)-e/2,i),_n(Math.min(a,s),i),e,Math.max(o,_n(Math.abs(s-a),i)))}t.fillStyle=l,t.fill(),r.border&&(t.save(),t.clip(),t.strokeStyle=s??(a?r.upBorderColor:r.downBorderColor),t.lineWidth=2*Math.max(o,_n(1,i)),t.stroke(),t.restore())}}let Us={type:`volume-candles`,input:`ohlc`,defaultStyle:e=>Vr(e.up,e.down),paint:Hs};function Ws(e=[]){v(`chartTypes()`,e);let t={transform:/* @__PURE__ */ new Set,"series type":/* @__PURE__ */ new Set},r=(e,r)=>{t[e].has(r)&&n(`chartTypes() is given the ${e} "${r}" twice.`),t[e].add(r)};return e.forEach((e,t)=>{h(`chartTypes()[${t}]`,e),!e.transform&&!e.series&&n(`chartTypes()[${t}] has neither a transform nor a series type.`),e.transform&&(Mt(e.transform),r(`transform`,e.transform.type)),e.series&&(Tt(e.series),r(`series type`,e.series.type))}),_o({name:`chartTypes`,install:t=>{for(let{transform:n,series:r}of e)n&&t.market.transforms.register(n),r&&t.seriesTypes.register(r);return{}}})}let Gs=[{transform:ms},{transform:Vs},{transform:gs},{transform:vs},{transform:Es,series:As},{transform:Ps,series:Ls},{transform:xs},{transform:Ss},{transform:Cs},{series:Us}],Ks=[`left`,`center`,`right`],qs=[`top`,`middle`,`bottom`],Js=[`supermillennium`,`millennium`,`submillennium`,`grand-supercycle`,`supercycle`,`cycle`,`primary`,`intermediate`,`minor`,`minute`,`minuette`,`subminuette`,`micro`,`submicro`,`miniscule`],Ys=[`fill`,`bold`,`italic`,`extendLeft`,`extendRight`,`startArrow`,`endArrow`],Xs=[`color`,`lineWidth`,`lineStyle`],Zs=g({value:!0,color:!0,visible:!0});function Qs(e,t){return _(e,t,Zs),{value:d(`${e}.value`,t.value),...t.color===void 0?{}:{color:S(`${e}.color`,t.color)},...t.visible===void 0?{}:{visible:f(`${e}.visible`,t.visible)}}}function $s(e,t){return v(`style.${e}`,t),t.length>32&&n(`style.${e} can have at most 32 levels, received ${t.length}.`),t.map((t,n)=>Qs(`style.${e}[${n}]`,t))}let ec=g({color:!0,lineWidth:!0,lineStyle:!0,fill:!0,fillColor:!0,textColor:!0,fontSize:!0,bold:!0,italic:!0,textAlign:!0,textPosition:!0,extendLeft:!0,extendRight:!0,startArrow:!0,endArrow:!0,levels:!0,timeLevels:!0,source:!0,degree:!0});function tc(e){_(`style`,e,ec);let t={};for(let n of[`color`,`fillColor`,`textColor`])e[n]!==void 0&&(t[n]=S(`style.${n}`,e[n]));for(let n of Ys)e[n]!==void 0&&(t[n]=f(`style.${n}`,e[n]));e.lineWidth!==void 0&&(t.lineWidth=d(`style.lineWidth`,e.lineWidth,{min:.5,max:20})),e.fontSize!==void 0&&(t.fontSize=d(`style.fontSize`,e.fontSize,{min:6,max:72})),e.lineStyle!==void 0&&(t.lineStyle=m(`style.lineStyle`,e.lineStyle,ln)),e.textAlign!==void 0&&(t.textAlign=m(`style.textAlign`,e.textAlign,Ks)),e.textPosition!==void 0&&(t.textPosition=m(`style.textPosition`,e.textPosition,qs));for(let n of[`levels`,`timeLevels`])e[n]!==void 0&&(t[n]=$s(n,e[n]));return e.source!==void 0&&(t.source=m(`style.source`,e.source,Xt)),e.degree!==void 0&&(t.degree=m(`style.degree`,e.degree,Js)),t}function nc(e){let{theme:t}=e;return{color:t.accent,lineWidth:1.5,lineStyle:`solid`,fill:!0,fillColor:t.grid,textColor:t.text,fontSize:e.font.size+1,bold:!1,italic:!1,textAlign:`left`,textPosition:`top`,extendLeft:!1,extendRight:!1,startArrow:!1,endArrow:!1,levels:[],timeLevels:[],source:`close`,degree:`intermediate`}}let rc=/* @__PURE__ */ new WeakMap;function ic(e,t){let n=rc.get(e);n||(n=/* @__PURE__ */ new WeakMap,rc.set(e,n));let r=n.get(t);return r||(r=Ce(Se(nc(e),t.defaultStyle?.(e.theme))),n.set(t,r)),r}let ac=/* @__PURE__ */ new WeakMap;function oc(e,t,n){let r=ac.get(n);if(r?.options===e&&r.definition===t)return r.style;let i=Ce(Se(ic(e,t),n));return ac.set(n,{options:e,definition:t,style:i}),i}function sc(e,t){return`${e.italic?`italic `:``}${E(e.fontSize,t,e.bold?600:`normal`)}`}let cc=[`second`,`minute`,`hour`,`day`,`week`,`month`];function lc(e,t){h(e,t);let n=d(`${e}.from`,t.from,{min:1,integer:!0});return{from:n,to:d(`${e}.to`,t.to,{min:n,integer:!0})}}function uc(e){h(`drawing.timeframes`,e);let t=Object.keys(e).find(e=>e!==`untimed`&&!cc.includes(e));t!==void 0&&n(`drawing.timeframes.${t} is not a unit; the units are ${cc.join(`, `)} and untimed.`);let r={};for(let t of cc){let n=e[t];n!==void 0&&(r[t]=lc(`drawing.timeframes.${t}`,n))}return e.untimed!==void 0&&(r.untimed=f(`drawing.timeframes.untimed`,e.untimed)),r}function dc(e,t){if(!e||t===null)return!0;if(t===`untimed`)return e.untimed===!0;let{unit:n,count:r}=fc(t),i=e[n];return i!==void 0&&r>=i.from&&r<=i.to}function fc(e){let{unit:t,count:n}=e;return t===`second`&&n%60==0&&(t=`minute`,n/=60),t===`minute`&&n%60==0&&(t=`hour`,n/=60),{unit:t,count:n}}let pc=g({id:!0,type:!0,pane:!0,points:!0,style:!0,text:!0,locked:!0,visible:!0,timeframes:!0}),mc=pc.filter(e=>e!==`id`&&e!==`type`),hc=g({time:!0,price:!0});function gc(e,t){return v(t,e),e.forEach((e,n)=>{_(`${t}[${n}]`,e,hc)}),e.map((e,n)=>({time:a(e.time,`${t}[${n}].time`),price:d(`${t}[${n}].price`,e.price)}))}function _c(e){return e===null?null:uc(e)}function vc(e,t,r,i){i(t)||n(`Unknown pane "${t}".`),e.mainPane&&t!==`main`&&n(`A "${r}" drawing is computed from the bars of the main pane; it goes on the main pane, not "${t}".`)}function yc(e,t,r){(e.points===0?t.length>=2:t.length===e.points)||n(`A "${r}" drawing needs ${e.points===0?`at least 2`:String(e.points)} points, received ${t.length}.`)}var bc=class e{registry;entries=[];ids;copies=/* @__PURE__ */ new WeakMap;constructor(e,t){this.registry=e,this.ids=new de(e=>this.get(e)!==void 0,t)}staging(t){let n=new e(this.registry,this.ids);return n.ids.reserve(t),n}list(){return this.entries}get(e){return this.entries.find(t=>t.id===e)}require(e){return this.get(e)??n(`Unknown drawing "${e}".`)}info(e){return{id:e.id,type:e.type,pane:e.pane,points:e.points.map(e=>({...e})),style:structuredClone(e.style),text:e.text,locked:e.locked,visible:e.visible,timeframes:structuredClone(e.timeframes)}}create(e,t){_(`drawing`,e,pc),p(`drawing.type`,e.type);let r=this.registry.require(e.type),i=e.id??this.ids.next(e.type);p(`drawing.id`,i),this.get(i)&&n(`A drawing with id "${i}" already exists.`);let a=e.pane??`main`;vc(r,a,e.type,t);let o=gc(e.points,`drawing.points`);return yc(r,o,e.type),{id:i,type:e.type,definition:r,pane:a,points:o,style:tc(e.style??{}),text:e.text===void 0?``:xc(e.text),locked:e.locked!==void 0&&f(`drawing.locked`,e.locked),visible:e.visible===void 0||f(`drawing.visible`,e.visible),timeframes:_c(e.timeframes??null)}}add(e){this.entries.push(e),this.ids.note(e.id)}update(e,t,n){_(`drawing patch`,t,mc);let r=this.require(e),i=t.points===void 0?r.points:gc(t.points,`drawing.points`);yc(r.definition,i,r.type),t.pane!==void 0&&vc(r.definition,t.pane,r.type,n);let a=t.style===void 0?r.style:{...r.style,...tc(t.style)},o=t.text===void 0?r.text:xc(t.text),s=t.locked===void 0?r.locked:f(`drawing.locked`,t.locked),c=t.visible===void 0?r.visible:f(`drawing.visible`,t.visible),l=t.timeframes===void 0?r.timeframes:_c(t.timeframes);this.copies.delete(r),r.points=i,r.pane=t.pane??r.pane,r.style=a,r.text=o,r.locked=s,r.visible=c,r.timeframes=l}setPoints(e,t){let n=this.require(e);this.copies.delete(n),n.points=t}remove(e){let t=this.require(e);return this.entries=this.entries.filter(e=>e!==t),t}removePane(e){this.entries=this.entries.filter(t=>t.pane!==e)}hasType(e){return this.entries.some(t=>t.type===e)}snapshot(){return this.entries.map(e=>{let t=this.copies.get(e);return t||(t={...e},this.copies.set(e,t)),t})}restore(e){this.entries=e.map(e=>{let t={...e};return this.copies.set(t,e),this.ids.note(t.id),t})}};function xc(e){return typeof e==`string`?e:n(`drawing.text must be a string.`)}var Sc=class{keeps;undoStack=[];redoStack=[];merging=null;constructor(e){this.keeps=e}get canUndo(){return this.keeps()&&this.undoStack.length>0}get canRedo(){return this.keeps()&&this.redoStack.length>0}record(e,t=null){this.keeps()?(t===null||t!==this.merging)&&(this.merging=t,this.undoStack.push(e),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack=[]):this.clear()}undo(e){if(!this.keeps())return null;this.merging=null;let t=this.undoStack.pop();return t?(this.redoStack.push(e),t):null}redo(e){if(!this.keeps())return null;this.merging=null;let t=this.redoStack.pop();return t?(this.undoStack.push(e),t):null}clear(){this.merging=null,this.undoStack=[],this.redoStack=[]}forgetPane(e){this.forget(t=>t.pane===e)}forgetType(e){this.forget(t=>t.type===e)}forget(e){let t=t=>t.filter(t=>!e(t));this.undoStack=this.undoStack.map(t),this.redoStack=this.redoStack.map(t)}};let Cc=NaN,wc={toScale:e=>e,fromScale:e=>e},Tc={toScale:e=>e>0?Math.log10(e):NaN,fromScale:e=>10**e};function Ec(e,t){return{bars:e,barIndex:e=>t.logicalIndexOf(e),timeAt:e=>t.timeOfLogicalIndex(e)}}function Dc(e,t,n,r){if(e.valueAt)return e.valueAt(t);let i=e.extend??`none`,a=n.logicalIndexOf(e.from.time),o=n.logicalIndexOf(e.to.time),s=n.logicalIndexOf(t);if([a,o,s].some(Number.isNaN))return Cc;if(a===o)return e.from.price===e.to.price&&(i===`both`||(i===`end`?s>=a:s===a))?e.from.price:Cc;let c=(s-a)/(o-a);if(!(i===`both`||c>=0&&(i===`end`||c<=1)))return Cc;let l=r.toScale(e.from.price),u=r.toScale(e.to.price);return r.fromScale(l+c*(u-l))}let Oc=g({merge:!0});function kc(e){h(`drawing type definition`,e),p(`drawing type definition type`,e.type),d(`definition.points`,e.points,{min:0,max:20,integer:!0}),(typeof e.paint!=`function`||typeof e.hitTest!=`function`)&&n(`A drawing type definition needs paint() and hitTest() functions.`),e.mainPane!==void 0&&f(`definition.mainPane`,e.mainPane),e.freehand&&e.points!==0&&n(`A drawing type drawn by hand (definition.freehand) needs points: 0.`),e.textAnchor!==void 0&&d(`definition.textAnchor`,e.textAnchor,{min:0,max:Math.max(0,e.points-1),integer:!0}),e.place!==void 0&&(d(`definition.place`,e.place,{min:1,max:Math.max(1,e.points-1),integer:!0}),(e.points===0||typeof e.complete!=`function`)&&n(`A drawing type with definition.place needs a fixed number of points and complete().`)),e.fields!==void 0&&!Array.isArray(e.fields)&&n(`definition.fields must be an array of style fields when given.`);for(let t of[`paintBelow`,`defaultStyle`,`handles`,`moveHandle`,`axisMarks`,`bounds`,`complete`,`levels`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`definition.${t} must be a function when given.`)}function Ac(e,t){let r=t.store,i=t=>e.panes.get(t)!==void 0,a=(n,r)=>{e.run(()=>{t.change(n,r===void 0?{}:{merge:r})})};return{set:n=>{e.run(()=>{v(`drawings`,n);let e=r.staging(n);n.forEach(t=>{e.add(e.create(t,i))}),t.replace(e.snapshot())})},add:t=>e.run(()=>{let e=r.create(t,i);return a(()=>{r.add(e)}),e.id}),update:(t,n,o={})=>{e.run(()=>{r.require(t),_(`options`,o,Oc);let e=o.merge===void 0?void 0:JSON.stringify([t,p(`options.merge`,o.merge)]);a(()=>{r.update(t,n,i)},e)})},remove:n=>{e.run(()=>{t.remove(n,!1)})},clear:()=>{a(()=>{r.restore([])})},get:e=>{let t=r.get(e);return t?r.info(t):null},list:()=>r.list().map(e=>r.info(e)),validate:e=>{new bc(r.registry).create(e,i)},duplicate:n=>e.run(()=>t.duplicate(n)),bounds:e=>t.bounds(e),levels:t=>{let i=r.get(t)??n(`Unknown drawing "${t}".`),a=oc(e.options,i.definition,i.style);return(i.definition.levels?.(i.points,wc,a,Ec(e.bars,e.bars))??[]).map(e=>e.key)},editText:n=>e.run(()=>t.editText(n)),startTool:(n,r={})=>{e.run(()=>{t.startTool(n,r)})},cancelTool:()=>{e.run(()=>{t.cancelTool()})},activeTool:()=>t.activeToolType(),toolStyle:e=>t.toolStyle(e),setToolStyle:(n,r)=>{e.run(()=>{t.setToolStyle(n,r)})},undo:()=>e.run(()=>t.restore(`undo`,!1)),redo:()=>e.run(()=>t.restore(`redo`,!1)),canUndo:()=>t.history.canUndo,canRedo:()=>t.history.canRedo,register:t=>{e.run(()=>{kc(t),r.registry.register(t),e.bus.emit(`typesChange`,{kind:`drawing`,type:t.type,registered:!0})})},unregister:i=>{e.run(()=>{r.registry.require(i),r.hasType(i)&&n(`Drawings of type "${i}" are on the chart; remove them first.`),t.activeToolType()===i&&n(`The "${i}" tool is active; cancel it first.`),r.registry.unregister(i),t.forgetType(i),e.bus.emit(`typesChange`,{kind:`drawing`,type:i,registered:!1})})},types:()=>r.registry.types(),definition:e=>r.registry.get(e)??null,fields:e=>[...r.registry.require(e).fields??Xs],defaultStyle:t=>structuredClone(ic(e.options,r.registry.require(t)))}}let jc=Math.PI/4;function Mc(e,t){return t.command?e===`off`?`strong`:`off`:e}function Nc(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.round(Math.atan2(r,n)/jc)*jc,a=Math.round(Math.cos(i)*1e9)/1e9,o=Math.round(Math.sin(i)*1e9)/1e9,s=n*a+r*o;return{x:e.x+s*a,y:e.y+s*o}}function Pc(e){return Number.isFinite(e.time)&&Number.isFinite(e.price)}function Fc(e,t,n,r=!1){return{x:r?Xi(e,n.time):Yi(e,n.time),y:t.scale.valueToY(n.price)}}function Ic(e,t){let n=e.timeOfLogicalIndex(e.barIndexOf(t.time));return Number.isFinite(n)?{time:n,price:t.price}:t}function Lc(e,t,n){return{time:e.bars.timeOfLogicalIndex(e.timeScale.xToIndex(n.x)),price:t.scale.yToValue(n.y)}}function Rc(e,t,n,r){let{bars:i,timeScale:a}=e,o=r.pivot?Nc(Fc(e,t,r.pivot),n):n,s=Math.round(a.xToIndex(o.x)),c=i.timeOfLogicalIndex(s),l=t.scale.yToValue(o.y),u=i.bar(s);if(r.pivot||r.magnet===`off`||!u||t.id!==`main`)return{time:c,price:l};let d=[u.open,u.high,u.low,u.close].reduce((e,n)=>Math.abs(t.scale.valueToY(n)-o.y)<Math.abs(t.scale.valueToY(e)-o.y)?n:e),f=Math.abs(t.scale.valueToY(d)-o.y);return{time:c,price:r.magnet===`strong`||f<=16?d:l}}function zc(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Bc(e,t,n){let r=Math.max(Math.abs(e.x),Math.abs(e.x-t)),i=Math.max(Math.abs(e.y),Math.abs(e.y-n));return Math.hypot(r,i)+t+n}function Vc(e,t,n,r,i){if(i===`segment`||e.x===t.x&&e.y===t.y)return[e,t];let a=Bc(e,n,r),o=Math.hypot(t.x-e.x,t.y-e.y),s=(t.x-e.x)/o,c=(t.y-e.y)/o,l={x:e.x+s*a,y:e.y+c*a};return[i===`line`?{x:e.x-s*a,y:e.y-c*a}:e,l]}function Hc(e,t){return e.x<t.x||e.x===t.x&&e.y>t.y}function Uc(e,t,n,r,i,a){let o=Math.hypot(t.x-e.x,t.y-e.y);if(o===0||!i&&!a)return[e,t];let s=(t.x-e.x)/o,c=(t.y-e.y)/o,l=Hc(e,t),u=l?i:a,d=l?a:i,f=Bc(e,n,r),p=Bc(t,n,r);return[u?{x:e.x-s*f,y:e.y-c*f}:e,d?{x:t.x+s*p,y:t.y+c*p}:t]}function Wc(e,t,n,r=0){return e.x>=Math.min(t.x,n.x)-r&&e.x<=Math.max(t.x,n.x)+r&&e.y>=Math.min(t.y,n.y)-r&&e.y<=Math.max(t.y,n.y)+r}function Gc(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r,r+=1){let a=t[r],o=t[i];a&&o&&a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function M(e,t){let n=[],r=t?e.at(-1):void 0;for(let t of e)r&&n.push([r,t]),r=t;return n}function Kc(e){return Math.round(e*1.4)}function N(e,t=0){if(e.length===0)return null;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let{x:t,y:o}of e)n=Math.min(n,t),r=Math.min(r,o),i=Math.max(i,t),a=Math.max(a,o);return{x:n-t,y:r-t,width:i-n+t*2,height:a-r+t*2}}function qc(e){return[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}]}function Jc(e){return e.startsWith(`handle:`)?e.slice(7):null}function Yc(e,t){let n=Number(e.id);return Number.isInteger(n)&&n>=0&&n<t&&String(n)===e.id}function Xc(e,t){if(!e.handles)return t.points.map((e,t)=>({id:String(t),x:e.x,y:e.y}));let r=e.handles(t),i=e.moveHandle?void 0:r.find(e=>!Yc(e,t.anchors.length));return i&&n(`The handle "${i.id}" of a "${e.type}" drawing is no anchor; define moveHandle() to move it.`),r}function Zc(e,t,n,r,i,a){return e.moveHandle?e.moveHandle(t,n,r,i,a):t.map((e,t)=>String(t)===n?r:e)}function Qc(e,t,n,r,i){let a=/^\d+$/.test(n)?Number(n):-1;return a<0||a>=t.length?e.pivotOf?.(t,n,r,i)??null:t.length<2?null:t[a-1]??t[a+1]??null}function $c(e,t,n,r){let i=null;for(let r of e){let e=Math.hypot(r.x-t.x,r.y-t.y);r.marker!==!1&&e<=n&&(!i||e<i.distance)&&(i={handle:r,distance:e})}if(i)return i;for(let n of e){let e=n.line?zc(t,n.line[0],n.line[1]):1/0;e<=r&&(!i||e<i.distance)&&(i={handle:n,distance:e})}return i}function el(e,t,n,r){for(let i of n){if(i.marker===!1)continue;let n=t.x+i.x,a=t.y+i.y,o=i.id===r.hovered;o&&(e.beginPath(),e.arc(n,a,r.radius+5,0,Math.PI*2),e.fillStyle=C(r.color,.18),e.fill()),e.beginPath(),e.arc(n,a,o?r.radius+1:r.radius,0,Math.PI*2),e.fillStyle=o?r.color:r.background,e.fill(),w(e,o?r.background:r.color,1.5),e.stroke()}}let tl=[{ms:864e5,en:`d`,zh:`天`,ja:`日`,ko:`일`},{ms:36e5,en:`h`,zh:`小时`,ja:`時間`,ko:`시간`},{ms:6e4,en:`m`,zh:`分钟`,ja:`分`,ko:`분`},{ms:1e3,en:`s`,zh:`秒`,ja:`秒`,ko:`초`}],nl={en:` `,zh:``,ja:``,ko:` `};function rl(e,t){let n=Math.round(Math.abs(e)/1e3)*1e3,r=[];for(let e of tl){let i=Math.floor(n/e.ms);if(i>0&&r.length<2)r.push(`${i}${e[t]}`),n-=i*e.ms;else if(r.length>0)break}let i=`0${tl[3][t]}`;return r.length===0?i:r.join(nl[t])}let il={text:`Text`,bars:e=>e===1?`1 bar`:`${e} bars`,duration:e=>rl(e,`en`),target:`Target`,stop:`Stop`,riskReward:`R:R`,open:`Open`,targetHit:`Target hit`,stopped:`Stopped`,leftShoulder:`Left Shoulder`,head:`Head`,rightShoulder:`Right Shoulder`},al={text:`文字`,bars:e=>`${e} 根 K 线`,duration:e=>rl(e,`zh`),target:`止盈`,stop:`止损`,riskReward:`盈亏比`,open:`持仓中`,targetHit:`已止盈`,stopped:`已止损`,leftShoulder:`左肩`,head:`头部`,rightShoulder:`右肩`},ol={text:`テキスト`,bars:e=>`${e}本`,duration:e=>rl(e,`ja`),target:`利確`,stop:`損切り`,riskReward:`RR比`,open:`保有中`,targetHit:`利確済み`,stopped:`損切り済み`,leftShoulder:`左肩`,head:`頭`,rightShoulder:`右肩`},sl={text:`텍스트`,bars:e=>`캔들 ${e}개`,duration:e=>rl(e,`ko`),target:`익절`,stop:`손절`,riskReward:`손익비`,open:`보유 중`,targetHit:`익절 완료`,stopped:`손절 완료`,leftShoulder:`왼쪽 어깨`,head:`머리`,rightShoulder:`오른쪽 어깨`};function cl(e){let t=new Intl.NumberFormat(e??void 0).resolvedOptions().locale.split(`-`)[0];return t===`zh`?al:t===`ja`?ol:t===`ko`?sl:il}let ll=g({magnet:!0,handleRadius:!0,visible:!0,history:!0,texts:!0}),ul={key:`drawings`,defaults:()=>({magnet:`off`,handleRadius:5,visible:!0,history:!0,texts:Ut(il)}),validate:(e,t)=>{_(t,e,ll),m(`${t}.magnet`,e.magnet,[`off`,`weak`,`strong`]),d(`${t}.handleRadius`,e.handleRadius,{min:1}),f(`${t}.visible`,e.visible),f(`${t}.history`,e.history),Wt(`${t}.texts`,e.texts,il)}};function dl(e){return e.drawings}let fl=/* @__PURE__ */ new WeakMap;function pl(e){let t=fl.get(e);return t||(t=Gt(cl(e.locale),dl(e).texts),fl.set(e,t)),t}let ml=`#ffffff`;function hl(e){return{prices:e.map(e=>e.price),times:e.map(e=>e.time)}}function gl(e,t,n){return e.axisMarks?.(t,n)??hl(t)}function _l(e,t,n,r,i,a){let{ctx:o,frame:s,options:c}=e,l=c.font.size+8,u=l/2;o.font=E(c.font.size,c.font.family);let d=t.plot.y+u,f=t.plot.y+t.plot.height-u,p=n.prices.map(e=>t.plot.y+t.scale.valueToY(e)),m=p.filter(e=>Number.isFinite(e));if(c.priceScale.visible&&m.length>0){let e=t.axis;if(!a&&m.length>1){let n=Math.max(t.plot.y,Math.min(...m)),i=Math.min(t.plot.y+t.plot.height,Math.max(...m));o.fillStyle=C(r,.14),o.fillRect(e.x,n,e.width,Math.max(0,i-n))}n.prices.forEach((t,n)=>{let a=p[n];a!==void 0&&a>=d-u&&a<=f+u&&yn(o,i(t),e.x+1,Math.min(Math.max(a,d),f),{background:r,color:ml,paddingX:6,height:l,align:`left`})})}let h=s.layout.timeAxis,g=n.times.map(t=>Xi(e,t)),_=g.filter(e=>Number.isFinite(e));if(!h||_.length===0)return;if(!a&&_.length>1){let e=Math.max(0,Math.min(..._)),t=Math.min(s.layout.plotWidth,Math.max(..._));o.fillStyle=C(r,.14),o.fillRect(e,h.y,Math.max(0,t-e),h.height)}let v=e.bars.interval();n.times.forEach((t,n)=>{let i=g[n];if(i===void 0||!Number.isFinite(i)||i<0||i>s.layout.plotWidth)return;let a=c.timeScale.formatter,u=a?a(t,{kind:`crosshair`,unit:`minute`,locale:e.formatter.locale,timeZone:e.formatter.timeZone}):e.formatter.timeCrosshair(t,v),d=o.measureText(u).width+12,f=Math.min(Math.max(i,d/2),s.layout.plotWidth-d/2);yn(o,u,f,h.y+h.height/2,{background:r,color:ml,paddingX:6,height:l,align:`center`})})}function vl(e){return e.place??e.points}function yl(e,t){if(!e.complete)return t;let{type:r}=e,i=e.complete(t);return v(`complete() of "${r}"`,i),i.length!==e.points&&n(`complete() of "${r}" gives ${i.length} anchors; a "${r}" drawing has ${e.points}.`),i}function bl(e,t){return e.frame.panes.find(e=>t.y>=e.plot.y&&t.y<e.plot.y+e.plot.height&&t.x>=0&&t.x<e.plot.width)}function xl(e,t){return{x:t.x-e.plot.x,y:t.y-e.plot.y}}var Sl=class{type;options;host;points=[];paneId=null;downAt=null;pressPlaced=!1;strokeAt=null;hover=null;constructor(e,t,n){this.type=e,this.options=t,this.host=n}get definition(){return this.host.definition(this.type)}placedPane(e){return this.paneId===null?void 0:O(e.frame,this.paneId)}paneAt(e,t){if(this.paneId!==null)return this.placedPane(e);let n=bl(e,t);return this.definition.mainPane&&n?.id!==`main`?void 0:n}pane(e){return this.hover?this.paneAt(e,this.hover.point):this.placedPane(e)}forgetPane(e){this.paneId===e&&(this.points=[],this.paneId=null,this.downAt=null,this.strokeAt=null)}pointerDown(e,t,n){this.pressPlaced=!1,n&&!this.definition.freehand?this.pointerMove(e,t):this.placeAt(e,t)&&(this.pressPlaced=!0,this.downAt=e,this.strokeAt=e)}pointerMove(e,t){this.hover={point:e,modifiers:t};let n=this.strokeAt;this.definition.freehand&&this.downAt&&n&&Math.hypot(e.x-n.x,e.y-n.y)>=3&&(this.strokeAt=e,this.placeNext(e,t)),this.host.repaint()}preview(e){let t=this.hover,n=t&&this.paneAt(e,t.point),r=t&&n?this.anchor(e,n,t.point,t.modifiers):null;return r&&Pc(r)?r:null}pointerUp(e,t,n){this.downAt=null,this.pressPlaced=!1,this.definition.freehand?this.endStroke(e,t):n&&(this.hover=null,this.placeAt(e,t))}doubleClick(){this.finish()}cancelPress(){this.downAt=null,this.strokeAt=null,this.hover=null,this.pressPlaced&&(this.points=this.definition.freehand?[]:this.points.slice(0,-1),this.paneId=this.points.length>0?this.paneId:null),this.pressPlaced=!1,this.host.repaint()}endStroke(e,t){let n=this.strokeAt;this.strokeAt=null,n&&(e.x!==n.x||e.y!==n.y)&&this.placeNext(e,t),this.points.length>=2?this.host.complete(this):(this.points=[],this.paneId=null),this.host.repaint()}finish(){return this.definition.points!==0||this.definition.freehand||this.points.length<2?!1:(this.host.complete(this),!0)}place(e,t,n,r){let i=this.anchor(e,t,n,r),a=this.points.at(-1),o=[...this.points,i],s=vl(this.definition);return!Pc(i)||a?.time===i.time&&a.price===i.price||o.length===s&&!this.host.draws(this,yl(this.definition,o),t)?!1:(this.points=o,!0)}placeAt(e,t){let n=this.host.context(),r=this.paneAt(n,e);return!r||!this.place(n,r,e,t)?!1:(this.paneId=r.id,this.hover=null,this.completeWhenReady(),this.host.repaint(),!0)}placeNext(e,t){let n=this.host.context(),r=this.placedPane(n);r&&this.place(n,r,e,t)}anchor(e,t,n,r){if(this.definition.freehand)return Lc(e,t,xl(t,n));let i={magnet:Mc(dl(e.options).magnet,r),pivot:r.shift?this.points.at(-1)??null:null};return Rc(e,t,xl(t,n),i)}completeWhenReady(){let e=vl(this.definition);e>0&&this.points.length>=e&&this.host.complete(this)}};function Cl(e,t){return oc(e.options,t.definition,t.style)}function wl(e,t){return dl(e.options).visible&&t.visible&&dc(t.timeframes,e.resolution)?e.frame.panes.find(e=>e.id===t.pane):void 0}function Tl(e,t,n,r,i){let a=Cl(e,n),o=sc(a,e.options.font.family),s=n.definition.freehand===!0,c=s?r:r.map(t=>Ic(e.bars,t));return{points:c.map(t=>Fc(e,i,t,s)),anchors:c,width:i.plot.width,height:i.plot.height,style:a,text:n.text,theme:e.options.theme,fontFamily:e.options.font.family,textFont:o,valueToY:e=>i.scale.valueToY(e),yToValue:e=>i.scale.yToValue(e),timeToX:t=>Xi(e,t),barIndex:t=>e.bars.logicalIndexOf(t),bars:e.displayed,source:e.source,formatValue:e=>t.formatValue(i,e),measureText:t=>e.measureText(t,o),texts:pl(e.options)}}function El(e,t){return e.bounds?e.bounds(t):N(Xc(e,t))}function Dl(e,t,n){if(!e.bounds)return!0;let r=e.bounds(t);return r!==null&&r.x<=n.x+n.width&&r.x+r.width>=n.x&&r.y<=n.y+n.height&&r.y+r.height>=n.y}function Ol(e){return{x:-16,y:-16,width:e.width+32,height:e.height+32}}function kl(e,t,n,r,i){let{ctx:a,pixelRatio:o}=e;vn(a,()=>{a.beginPath(),a.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),a.clip(),a.translate(t.plot.x,t.plot.y);let e={ctx:a,pixelRatio:o,geometry:r,hovered:i.hovered,selected:i.selected,editing:i.editing};i.below&&n.paintBelow?.(e),n.paint(e)}),i.handles&&!i.editing&&(a.save(),a.beginPath(),a.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),a.clip(),el(a,{x:t.plot.x,y:t.plot.y},Xc(n,r),{color:r.style.color,background:e.options.theme.background,radius:dl(e.options).handleRadius,hovered:i.hoveredHandle}),a.restore())}function Al(e,t,n){let{ctx:r,pixelRatio:i}=e;vn(r,()=>{t.paintBelow?.({ctx:r,pixelRatio:i,geometry:n,hovered:!1,selected:!1,editing:!1})})}function jl(e,t,n,r,i,a=!0){let o=Cl(e,r);_l(e,n,a?gl(r.definition,i,o):hl(i),o.color,e=>t.formatValue(n,e),!1)}function Ml(e,t,n,r){let i=n.pane(e);if(!i)return;let a=n.preview(e),o=a?[...n.points,a]:n.points,s=n.definition,c={definition:s,style:r,text:n.options.text??``},l=vl(s)||2,u=o.length>=l?yl(s,o):o;if(o.length>=l&&!s.editableText)kl(e,i,s,Tl(e,t,c,u,i),{hovered:!1,selected:!0,editing:!1,handles:!0,hoveredHandle:null,below:!0});else{let t=Cl(e,c),n=u.map((t,n)=>({id:String(n),...Fc(e,i,t)}));if(n.length>1&&!s.editableText){let{ctx:r}=e;r.save(),r.beginPath(),r.rect(i.plot.x,i.plot.y,i.plot.width,i.plot.height),r.clip(),r.beginPath(),n.forEach(({x:e,y:t},n)=>{n===0?r.moveTo(i.plot.x+e,i.plot.y+t):r.lineTo(i.plot.x+e,i.plot.y+t)}),w(r,t.color,t.lineWidth,t.lineStyle),r.stroke(),r.restore()}el(e.ctx,{x:i.plot.x,y:i.plot.y},n,{color:t.color,background:e.options.theme.background,radius:dl(e.options).handleRadius,hovered:null})}jl(e,t,i,c,u,o.length>=l)}function Nl(e,t,n,r){let i=e.selection?.kind===`drawing`&&!r.placing?e.selection.id:null,a=e.hovered?.kind===`drawing`?e.hovered:null,o=null;for(let s of n){let n=wl(e,s);if(!n)continue;let c=s.id===i,l=a?.id===s.id,u=Tl(e,t,s,s.points,n);c&&(o={entry:s,pane:n}),Dl(s.definition,u,Ol(u))&&kl(e,n,s.definition,u,{hovered:l,selected:c,editing:r.editing===s.id,handles:c||l,hoveredHandle:l?Jc(a.part):null,below:!1})}for(let r of n){let n=wl(e,r),a=Cl(e,r),o=n?gl(r.definition,r.points,a):null;n&&o?.always&&r.id!==i&&_l(e,n,o,a.color,e=>t.formatValue(n,e),!0)}o&&jl(e,t,o.pane,o.entry,o.entry.points),r.placing&&Ml(e,t,r.placing.tool,r.placing.style)}function Pl(e,t,n,r){for(let i of n)if(i.definition.paintBelow&&wl(e,i)?.id===r.id){let n=Tl(e,t,i,i.points,r);Dl(i.definition,n,Ol(n))&&Al(e,i.definition,n)}}function Fl({bars:e,timeScale:t},n){let r=Math.abs(n.scale.yToScale(0)-n.scale.yToScale(1));return{...n.scale.mode===`log`?Tc:wc,barIndex:t=>e.logicalIndexOf(t),timeAt:t=>e.timeOfLogicalIndex(t),unitHeight:r>0?1/r/t.barSpacing:1}}function Il(e,t,n,r,i,a){let{timeScale:o,bars:s}=e,c=Math.round(o.xToIndex(i.x)-r.index),l=t.scale.yToScale(i.y)-r.value;return n.map(e=>({time:s.timeOfLogicalIndex((a?s.logicalIndexOf(e.time):s.barIndexOf(e.time))+c),price:t.scale.fromScale((t.scale.toScale(e.price)??NaN)+l)}))}function Ll(e,t,n,r,i){let{store:a}=e,o=a.get(n.id);if(!o||o.locked||!O(t.frame,o.pane))return null;e.keepText();let s=Jc(n.part),c=o;i.alt&&s===null&&(c=e.copyOf(o),a.add(c));let l=c!==o,u=c.definition.paintBelow!==void 0,d=c.points.map(e=>({...e})),f=O(t.frame,c.pane),p=f?xl(f,r):r,m={index:t.timeScale.xToIndex(p.x),value:f?f.scale.yToScale(p.y):NaN},h=!1;e.select(c.id);let g=()=>a.get(c.id)===c,_=()=>{let e=a.snapshot();return l?e.filter(e=>e.id!==c.id):e.map(e=>e.id===c.id?{...e,points:d}:e)};return{move:(t,n)=>{let r=e.context(),i=O(r.frame,c.pane);if(!i||!g())return;let o=xl(i,t),l=Fl(r,i),f=Cl(r,c),p=s===null?Il(r,i,d,m,o,c.definition.freehand===!0):Zc(c.definition,d,s,Rc(r,i,o,{magnet:Mc(dl(r.options).magnet,n),pivot:n.shift?Qc(c.definition,d,s,l,f):null}),l,f);p.every(Pc)&&(a.setPoints(c.id,p),h=!0,e.repaint(u))},end:()=>{(h||l)&&g()&&e.dropped(_(),c.id,l)},cancel:()=>{g()&&(a.restore(_()),e.select(o.id),e.cancelled())}}}function Rl(e,t){return t.y>=e.plot.y&&t.y<e.plot.y+e.plot.height}function zl(e,t,n,r){let i=/* @__PURE__ */ new Set;n.selection?.kind===`drawing`&&i.add(n.selection.id),n.hovered?.kind===`drawing`&&i.add(n.hovered.id);let a=null;for(let o of i){let i=e.find(e=>e.id===o),s=i?wl(n,i):void 0;if(!i||!s||!Rl(s,r))continue;let c=Tl(n,t,i,i.points,s),l=dl(n.options).handleRadius+4,u=$c(Xc(i.definition,c),xl(s,r),l,n.options.interaction.hitTolerance);u&&(!a||u.distance<a.distance)&&(a={target:{kind:`drawing`,id:i.id,part:`handle:${u.handle.id}`,cursor:i.locked?`pointer`:u.handle.cursor??`move`,draggable:!i.locked},priority:Ji.handle,distance:u.distance})}return a}function Bl(e,t){return e.part===t.part?e.distance<t.distance:e.part===`line`}function Vl(e,t,n,r){let i=zl(e,t,n,r);if(i)return i;let a=n.options.interaction.hitTolerance,o=null;for(let i of[...e].reverse()){let e=wl(n,i);if(!e||!Rl(e,r))continue;let s=Tl(n,t,i,i.points,e),c=xl(e,r),l=Dl(i.definition,s,{x:c.x-a,y:c.y-a,width:a*2,height:a*2})?i.definition.hitTest(s,c,a):null;l&&(!o||Bl(l,o.hit))&&(o={entry:i,hit:l})}return o&&{target:{kind:`drawing`,id:o.entry.id,part:o.hit.part,cursor:`pointer`,draggable:!o.entry.locked},priority:o.hit.part===`line`?Ji.line:Ji.body,distance:o.hit.distance}}var Hl=class{options;area;done=!1;focused=!1;focusTimer=0;constructor(e){this.options=e;let t=e.root.ownerDocument.createElement(`textarea`);this.area=t,t.value=e.text,t.spellcheck=!1,t.setAttribute(`aria-label`,e.label),Object.assign(t.style,{position:`absolute`,zIndex:`2`,left:`${e.x-3-1}px`,top:`${e.y-e.lineHeight/2-2-1}px`,margin:`0`,padding:`2px 3px`,border:`1px solid ${e.border}`,borderRadius:`3px`,outline:`none`,resize:`none`,overflow:`hidden`,whiteSpace:`pre`,background:e.background,color:e.color,font:e.font,textAlign:e.align,lineHeight:`${e.lineHeight}px`,boxShadow:`0 2px 10px rgba(0, 0, 0, 0.12)`}),t.addEventListener(`keydown`,this.onKey),t.addEventListener(`input`,this.fit),t.addEventListener(`blur`,this.onBlur),t.addEventListener(`focus`,this.onFocus);for(let e of[`pointerdown`,`pointermove`,`pointerup`,`dblclick`,`wheel`,`keyup`])t.addEventListener(e,Ul);e.root.appendChild(t),this.fit();let n=e.root.ownerDocument.defaultView;this.focusTimer=n?.setTimeout(()=>{t.focus(),t.select()},0)??0}commit(){this.finish(()=>{this.options.commit(this.area.value)})}cancel(){this.finish(()=>{this.options.cancel()})}finish(e){this.done||(this.done=!0,this.area.ownerDocument.defaultView?.clearTimeout(this.focusTimer),this.area.removeEventListener(`blur`,this.onBlur),this.area.remove(),e())}onKey=e=>{e.stopPropagation(),e.key===`Escape`?(e.preventDefault(),this.cancel()):e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.commit())};onFocus=()=>{this.focused=!0};onBlur=()=>{this.focused&&this.commit()};fit=()=>{let e=this.area,t=Math.max(1,e.value.split(`
|
|
3
|
+
`).length);e.style.height=`${t*this.options.lineHeight+4+2}px`,e.style.width=`0`,e.style.width=`${Math.max(40,e.scrollWidth+2)}px`}};function Ul(e){e.stopPropagation()}var Wl=class{host;current=null;constructor(e){this.host=e}get edited(){return this.current?.edited??null}open(e,t){let{host:n}=this,r=n.context(),i=O(r.frame,e.pane??`main`),a=n.definition(e.type),o=e.points[a.textAnchor??0];if(!i||!o)return;let s={definition:a,style:e.style??{},text:e.text??``},c=Cl(r,s),l=Fc(r,i,{time:Number(o.time),price:o.price}),u=()=>{this.current=null,n.repaint()},d=new Hl({root:n.root,x:r.frame.layout.leftAxisWidth+i.plot.x+l.x,y:i.plot.y+l.y,text:s.text,label:pl(r.options).text,font:sc(c,r.options.font.family),align:c.textAlign,fontSize:c.fontSize,lineHeight:Kc(c.fontSize),color:c.textColor,border:c.color,background:r.options.theme.background,commit:e=>{u(),n.keep(t,e)},cancel:()=>{u(),n.drop(t)}});this.current={editor:d,edited:t},n.repaint()}commit(){this.current?.editor.commit()}cancel(){this.current?.editor.cancel()}};let Gl=g({style:!0,text:!0,continuous:!0});function Kl(e){return{type:e.type,pane:e.pane,points:e.points,style:e.style,text:e.text,locked:e.locked,visible:e.visible,timeframes:e.timeframes}}var ql=class{store;host;kind=`drawing`;history=new Sc(()=>dl(this.host.context().options).history);tool=null;clipboard=null;text;quietly=!1;toolStyles=/* @__PURE__ */ new Map;paneExists=e=>this.host.paneExists(e);constructor(e,t){this.store=e,this.host=t,this.text=new Wl({root:t.root,context:()=>t.context(),repaint:()=>{t.repaint(!1)},definition:t=>e.registry.require(t),keep:(e,t)=>{this.keepText(e,t)},drop:e=>{this.dropText(e)}})}edit(e){return this.editText(e)}has(e){return this.store.get(e)!==void 0}shown(e){let t=this.store.get(e);return t!==void 0&&wl(this.host.context(),t)!==void 0}activeTool(){return this.placing(this.host.context())}placing(e){return dl(e.options).visible?this.tool:null}activeToolType(){return this.tool?.type??null}startTool(e,t){this.store.registry.require(e),_(`tool options`,t,Gl);let n={...t.style===void 0?{}:{style:tc(t.style)},...t.text===void 0?{}:{text:xc(t.text)},...t.continuous!==void 0&&f(`tool options.continuous`,t.continuous)?{continuous:!0}:{}};this.closeTextQuietly(!0),this.tool=this.newTool(e,n),this.host.repaint(!1)}cancelTool(){this.text.edited?.id===null&&this.closeTextQuietly(!1),this.tool&&(this.tool=null,this.host.repaint(!1))}toolStyle(e){return this.store.registry.require(e),{...this.toolStyles.get(e)}}setToolStyle(e,t){this.store.registry.require(e),t===null?this.toolStyles.delete(e):this.toolStyles.set(e,tc(t)),this.host.repaint(!1)}forgetPane(e){let t=this.text.edited;t&&this.paneOfText(t)===e&&this.closeTextQuietly(!1),this.store.removePane(e),this.history.forgetPane(e),this.tool?.forgetPane(e),this.clipboard?.pane===e&&(this.clipboard=null)}paneOfText(e){return e.id===null?e.input.pane:this.store.get(e.id)?.pane}forgetType(e){let t=this.text.edited;t?.id===null&&t.input.type===e&&this.closeTextQuietly(!1),this.toolStyles.delete(e),this.history.forgetType(e),this.clipboard?.type===e&&(this.clipboard=null)}placingStyle(e){return{...this.toolStyles.get(e.type),...e.options.style}}finishTool(){return this.placing(this.host.context())?.finish()??!1}newTool(e,t){return new Sl(e,t,{context:()=>this.host.context(),definition:e=>this.store.registry.require(e),repaint:()=>{this.host.repaint(!1)},draws:(e,t,n)=>{let r={definition:e.definition,style:this.placingStyle(e),text:e.options.text??``},i=Tl(this.host.context(),this.host,r,t,n);return El(e.definition,i)!==null},complete:e=>{this.placed(e)}})}placed(e){let t=e.paneId;if(t===null)return;this.tool=e.options.continuous?this.newTool(e.type,e.options):null;let n=this.tool===null,r=this.placingStyle(e),i={type:e.type,pane:t,points:yl(e.definition,e.points),...Object.keys(r).length>0?{style:r}:{},...e.options.text===void 0?{}:{text:e.options.text}};e.definition.editableText&&e.options.text===void 0?(this.text.open(i,{id:null,input:i,endsTool:n}),this.host.repaint(!1)):(this.create(i),n&&this.host.toolEnded(e.type,!0))}create(e){let t=this.store.create(e,this.paneExists);this.change(()=>{this.store.add(t)},{user:{reason:`create`,ids:[t.id]},select:t.id})}change(e,t={}){let n=this.store.snapshot();e(),this.changed(n,t)}changed(e,t){we(e,this.store.snapshot())||this.history.record(e,t.merge??null),t.select!==void 0&&this.host.selected(t.select),this.settle(t.user!==void 0),t.user&&this.host.changed(t.user.reason,t.user.ids)}settle(e){let t=this.text.edited;t&&t.id!==null&&!this.has(t.id)&&this.closeTextQuietly(!1),this.host.prune(e),this.host.repaint(!0)}remove(e,t){this.store.require(e),this.change(()=>{this.store.remove(e)},t?{user:{reason:`remove`,ids:[e]}}:{})}replace(e){this.closeTextQuietly(!1),this.store.restore(e),this.history.clear(),this.clipboard&&!this.host.paneExists(this.clipboard.pane)&&(this.clipboard=null),this.settle(!1)}restore(e,t){if(!(e===`undo`?this.history.canUndo:this.history.canRedo))return!1;this.closeTextQuietly(!0);let n=this.store.snapshot(),r=e===`undo`?this.history.undo(n):this.history.redo(n);return r?(this.store.restore(r),this.settle(t),t&&this.host.changed(e,[]),!0):!1}shifted(e){let{bars:t}=this.host.context(),n=e.points.map(e=>({time:t.timeOfLogicalIndex(t.logicalIndexOf(Number(e.time))+5),price:e.price}));return n.every(Pc)?{...e,points:n}:null}copy(e){let t=e===null?void 0:this.store.get(e);return t?(this.clipboard=Kl(this.store.info(t)),!0):!1}paste(){let e=this.clipboard&&this.shifted(this.clipboard);return e?(this.clipboard=e,this.create(e),!0):!1}duplicate(e){let t=this.shifted(Kl(this.store.info(this.store.require(e))))??n(`duplicate() needs two bars or more, to place the copy bars to the right.`),r=this.store.create(t,this.paneExists);return this.change(()=>{this.store.add(r)}),r.id}editText(e){let t=this.store.require(e);return!t.definition.editableText||t.locked?!1:(this.closeTextQuietly(!0),this.text.open(this.store.info(t),{id:e}),!0)}commitText(){this.text.commit()}closeTextQuietly(e){this.quietly=!0;try{e?this.text.commit():this.text.cancel()}finally{this.quietly=!1}}keepText(e,t){let{id:n}=e;if(n===null){let n=t.trim()!==``;n&&this.create({...e.input,text:t}),e.endsTool&&!this.quietly&&this.host.toolEnded(e.input.type,n)}else this.has(n)&&t!==this.store.require(n).text&&this.change(()=>{this.store.update(n,{text:t},this.paneExists)},{user:{reason:`edit`,ids:[n]}})}dropText(e){e.id===null&&e.endsTool&&!this.quietly&&this.host.toolEnded(e.input.type,!1)}bounds(e){let t=this.host.context(),n=this.store.require(e),r=wl(t,n);if(!r)return null;let i=El(n.definition,Tl(t,this.host,n,n.points,r));if(!i)return null;let a=Math.max(0,i.x),o=Math.max(0,i.y),s=Math.min(r.plot.width,i.x+i.width),c=Math.min(r.plot.height,i.y+i.height);return s>=a&&c>=o?{x:t.frame.layout.leftAxisWidth+r.plot.x+a,y:r.plot.y+o,width:s-a,height:c-o}:null}hitTest(e,t){return Vl(this.store.list(),this.host,e,t)}beginDrag(e,t,n,r){return Ll({store:this.store,context:()=>this.host.context(),keepText:()=>{this.commitText()},copyOf:e=>this.store.create(Kl(this.store.info(e)),this.paneExists),select:e=>{this.host.selected(e)},repaint:e=>{this.host.repaint(e)},dropped:(e,t,n)=>{this.changed(e,{user:{reason:n?`create`:`edit`,ids:[t]}})},cancelled:()=>{this.settle(!0)}},e,t,n,r)}paintBelow(e,t){Pl(e,this.host,this.store.list(),t)}paint(e){let t=this.placing(e);Nl(e,this.host,this.store.list(),{placing:t&&{tool:t,style:this.placingStyle(t)},editing:this.text.edited?.id??null})}};function Jl(e,t){let{bars:r,scaleOf:i}=e,a=Ec(r,r),o=t=>t.definition.levels?.(t.points,i(t.pane),oc(e.options(),t.definition,t.style),a)??[],s=(e,t)=>{let n=o(e);return(t===void 0?n[0]:n.find(e=>e.key===t))??null};return{movable:!0,check:(e,r)=>{let i=t.get(e.id)??n(`${r}: unknown drawing "${e.id}".`),a=o(i).map(e=>e.key);a.length===0&&n(`${r}: a "${i.type}" drawing has no lines to watch.`),e.level!==void 0&&!a.includes(e.level)&&n(`${r}: a "${i.type}" drawing has no line "${e.level}"; it has ${a.map(e=>`"${e}"`).join(`, `)}.`)},read:(e,n)=>{let a=t.get(e.id),o=a?s(a,e.level):null;return a&&o?Dc(o,r.time(n),r,i(a.pane)):NaN},paneOf:e=>t.get(e.id)?.pane??`main`}}function Yl(e,t){let n=e.events(),r=()=>{let n=e.objects.selection;return n?.kind===`drawing`&&!t.activeTool()&&t.shown(n.id)?n.id:null};return e=>{switch(e){case`escape`:{let e=t.activeToolType();return e!==null&&(t.cancelTool(),n.emit(`toolEnd`,{type:e,completed:!1}),!0)}case`delete`:{let e=r();return e!==null&&(t.remove(e,!0),!0)}case`undo`:case`redo`:return t.restore(e,!0);case`enter`:return t.finishTool();case`copy`:return t.copy(r());case`paste`:return t.paste()}}}function Xl(e){let{store:t}=e;return{key:`drawings`,save:()=>t.list().map(e=>t.info(e)),prepare:(n,r)=>{let i=n??[];v(`state.drawings`,i);let a=t.staging(i);return i.forEach(e=>{a.add(a.create(e,e=>r.get(e)!==void 0))}),{apply:()=>{e.replace(a.snapshot()),e.cancelTool()}}}}}function Zl(e=[]){let t=/* @__PURE__ */ new Set;return e.forEach(e=>{kc(e);let{type:r}=e;t.has(r)&&n(`drawings() is given the drawing type "${r}" twice.`),t.add(r)}),_o({name:`drawings`,options:ul,install:t=>{let n=new Rr(`drawing type`,[],`Give it to the drawings module, or register it with chart.drawings.register().`);e.forEach(e=>{n.register(e)});let r=t.events(),i=new ql(new bc(n),{context:()=>t.objectContext(),root:t.surface.root,repaint:e=>{e?t.invalidateLayers(`scene`,`objects`):t.invalidateLayers(`objects`)},paneExists:e=>t.panes.get(e)!==void 0,prune:e=>{t.objects.prune()&&e&&t.bus.emit(`selectionChange`,{selection:t.objects.selection})},formatValue:(e,n)=>Vn(t,e,n),changed:(e,t)=>{r.emit(`drawingsChange`,{reason:e,ids:t})},toolEnded:(e,t)=>{r.emit(`toolEnd`,{type:e,completed:t})},selected:e=>{t.selectByUser(e===null?null:{kind:`drawing`,id:e})}});return t.objects.add(i,20),t.hooks.destroyed.push(()=>{i.closeTextQuietly(!1)}),t.scenePainters.push((e,n,r,a,o)=>{a===`below`&&i.paintBelow({...t.objectContext(n),ctx:e,pixelRatio:o},r)}),t.tool=()=>i.activeTool(),t.commands.push(Yl(t,i)),t.values.provide(`drawing`,Jl({bars:t.bars,options:()=>t.options,scaleOf:e=>t.panes.get(e)?.scales.get(`right`)?.mode===`log`?Tc:wc},i.store)),t.paneOccupants.push({occupants:()=>[],removed:e=>{i.forgetPane(e)}}),t.stateParts.push(Xl(i)),{drawings:Ac(t,i)}}})}let Ql={part:`body`,distance:0};function P(e,t,n={}){let{ctx:r,geometry:i}=e;r.beginPath(),t(r),w(r,n.color??i.style.color,n.lineWidth??i.style.lineWidth,n.lineStyle??i.style.lineStyle),r.lineCap=`round`,r.lineJoin=`round`,r.stroke()}function $l(e){return e.reduce((e,t)=>t)}function F(e,t,n){t.forEach((t,n)=>{n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)}),n&&e.closePath()}function I(e,t,n){e.beginPath(),F(e,t,!0),e.fillStyle=n,e.fill()}function eu(e,t,n,r){let i=zc(e,t,n);return i<=r?{part:`line`,distance:i}:null}function L(e,t,n){let r=t.reduce((t,[n,r])=>Math.min(t,zc(e,n,r)),1/0);return r<=n?{part:`line`,distance:r}:null}function R(e,t,n=null){let r=0;return e.flatMap(({value:e,color:i,visible:a})=>{let o=e===0||e===1,s=o||!n?t.color:Tn(n,r);return r+=+!o,a===!1?[]:[{value:e,color:i??s}]})}function z(e){return String(Math.round(e*1e3)/1e3)}function tu(e){let t=/* @__PURE__ */ new WeakMap;return(n,r,i)=>{let a=t.get(n);return a?.revision!==n.revision&&(a={revision:n.revision,values:new Ii(e)},t.set(n,a)),a.values.getOrCreate(r,i)}}function nu(e,t,n){switch(n){case`open`:return e.open(t);case`high`:return e.high(t);case`low`:return e.low(t);case`close`:return e.close(t);case`hl2`:return(e.high(t)+e.low(t))/2;case`hlc3`:return(e.high(t)+e.low(t)+e.close(t))/3;case`ohlc4`:return(e.open(t)+e.high(t)+e.low(t)+e.close(t))/4}}let ru={left:0,center:.5,right:1,top:0,middle:.5,bottom:1},iu=Math.PI/8;function au(e){return 9+e.lineWidth*2.5}function ou(e,t){return Math.min(t/2,au(e)*.6)}function su(e,t,n,r,i=r.color){let a=au(r);e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.x-a*Math.cos(n-iu),t.y-a*Math.sin(n-iu)),e.lineTo(t.x-a*Math.cos(n+iu),t.y-a*Math.sin(n+iu)),e.closePath(),e.fillStyle=i,e.fill()}function cu(e,t,n,r){let i=Math.hypot(n.x-t.x,n.y-t.y);if(i===0)return;let{style:a}=e.geometry,o=Math.atan2(n.y-t.y,n.x-t.x),s=ou(a,i);P(e,e=>{e.moveTo(t.x,t.y),e.lineTo(n.x-s*Math.cos(o),n.y-s*Math.sin(o))},{color:r,lineStyle:`solid`}),su(e.ctx,n,o,a,r)}function lu(e){return e.text===``?[]:e.text.split(`
|
|
4
|
+
`)}function uu(e){let t=lu(e);return t.length===0?0:4+t.length*Kc(e.style.fontSize)}function du(e,t,n,r,i,a){let{ctx:o,geometry:s}=e,{style:c}=s,l=Kc(c.fontSize);o.font=s.textFont,o.fillStyle=a,o.textAlign=c.textAlign,o.textBaseline=`middle`,t.forEach((e,t)=>{o.fillText(e,n+i*ru[c.textAlign],r+t*l)})}function fu(e,t,n){let r=lu(e.geometry);if(r.length===0)return;let{ctx:i,geometry:a}=e,{style:o}=a,[s,c]=Hc(t,n)?[t,n]:[n,t],l=Math.hypot(c.x-s.x,c.y-s.y)-8,u=Kc(o.fontSize),d=r.length*u,f=o.textPosition===`top`?-4-d:o.textPosition===`bottom`?4:-d/2;if(i.save(),i.translate(s.x,s.y),i.rotate(Math.atan2(c.y-s.y,c.x-s.x)),o.textPosition===`middle`){let e=Math.max(...r.map(e=>a.measureText(e)));i.fillStyle=a.theme.background,i.fillRect((l-e)*ru[o.textAlign],f,e+8,d)}du(e,r,4,f+u/2,l,o.textColor),i.restore()}function pu(e,t,n){let r=lu(e.geometry);if(r.length===0)return;let{style:i}=e.geometry,a=Kc(i.fontSize),o=Math.abs(n.y-t.y)-8-r.length*a;du(e,r,Math.min(t.x,n.x)+4,Math.min(t.y,n.y)+4+o*ru[i.textPosition]+a/2,Math.abs(n.x-t.x)-8,i.textColor)}let mu=[`text`,`textColor`,`fontSize`,`bold`,`italic`,`textAlign`,`textPosition`],hu=[`color`,`lineWidth`,`lineStyle`],gu=[`startArrow`,`endArrow`],_u=[`extendLeft`,`extendRight`];function vu(e,t,n,r){let[i,a]=t.time<=n.time?[t,n]:[n,t];return r.extendLeft&&r.extendRight?{key:e,from:i,to:a,extend:`both`}:r.extendRight?{key:e,from:i,to:a,extend:`end`}:r.extendLeft?{key:e,from:a,to:i,extend:`end`}:{key:e,from:t,to:n,extend:`none`}}function yu(e,t,n=!1){let r=({points:[e,n],width:r,height:i,style:a})=>t===`segment`?Uc(e,n,r,i,a.extendLeft,a.extendRight):Vc(e,n,r,i,t);return{type:e,points:2,fields:t===`segment`?[...hu,..._u,...gu,...mu]:[...hu,...mu],defaultStyle:()=>({textAlign:`center`,...n?{endArrow:!0}:{}}),paint:e=>{let{ctx:t,geometry:n}=e,[i,a]=n.points,o=r(n),{style:s}=n,c=Math.atan2(a.y-i.y,a.x-i.x),l=Math.hypot(a.x-i.x,a.y-i.y),u=s.startArrow&&o[0]===i&&l>0,d=s.endArrow&&o[1]===a&&l>0,f=ou(s,l),p=u?{x:i.x+f*Math.cos(c),y:i.y+f*Math.sin(c)}:o[0],m=d?{x:a.x-f*Math.cos(c),y:a.y-f*Math.sin(c)}:o[1];P(e,e=>{e.moveTo(p.x,p.y),e.lineTo(m.x,m.y)}),u&&su(t,i,c+Math.PI,s),d&&su(t,a,c,s),fu(e,i,a)},hitTest:(e,t,n)=>{let[i,a]=r(e);return eu(t,i,a,n)},bounds:e=>N(r(e),uu(e)),levels:([e,n],r,i)=>t===`segment`?[vu(`line`,e,n,i)]:[{key:`line`,from:e,to:n,extend:t===`ray`?`end`:`both`}]}}let bu=/* @__PURE__ */ yu(`trend-line`,`segment`),xu=/* @__PURE__ */ yu(`ray`,`ray`),Su=/* @__PURE__ */ yu(`extended-line`,`line`),Cu=/* @__PURE__ */ yu(`arrow`,`segment`,!0);function wu(e,t){let n=({points:[e],width:n})=>[{x:t?e.x:0,y:e.y},{x:n,y:e.y}];return{type:e,points:1,fields:[...hu,...mu],defaultStyle:()=>({textAlign:t?`left`:`right`}),paint:e=>{let[t,r]=n(e.geometry);P(e,e=>{e.moveTo(t.x,t.y),e.lineTo(r.x,r.y)}),fu(e,t,r)},hitTest:(e,t,r)=>{let[i,a]=n(e);return eu(t,i,a,r)},bounds:e=>N(n(e),uu(e)),axisMarks:([e])=>({prices:[e.price],times:[],always:!0}),levels:([e])=>[{key:`line`,from:e,to:e,extend:t?`end`:`both`}]}}let Tu=/* @__PURE__ */ wu(`horizontal-line`,!1),Eu=/* @__PURE__ */ wu(`horizontal-ray`,!0);function Du({points:[e],height:t}){return[{x:e.x,y:0},{x:e.x,y:t}]}let Ou={type:`vertical-line`,points:1,fields:[`color`,`lineWidth`,`lineStyle`,`text`,`textColor`,`fontSize`,`bold`,`italic`,`textAlign`,`textPosition`],defaultStyle:()=>({textAlign:`center`}),paint:e=>{let[t,n]=Du(e.geometry);P(e,e=>{e.moveTo(t.x,t.y),e.lineTo(n.x,n.y)}),fu(e,n,t)},hitTest:(e,t,n)=>{let[r,i]=Du(e);return eu(t,r,i,n)},bounds:e=>N(Du(e),uu(e)),axisMarks:([e])=>({prices:[],times:[e.time],always:!0})};function ku(e){let[t]=e.points;return[[{x:0,y:t.y},{x:e.width,y:t.y}],Du(e)]}let Au={type:`cross-line`,points:1,fields:hu,paint:e=>{P(e,t=>{for(let n of ku(e.geometry))F(t,n,!1)})},hitTest:(e,t,n)=>L(t,ku(e),n),bounds:e=>N(ku(e).flat()),axisMarks:([e])=>({prices:[e.price],times:[e.time],always:!0}),levels:([e])=>[{key:`line`,from:e,to:e,extend:`both`}]};function ju(e,t){return Math.atan2(e.y-t.y,t.x-e.x)*180/Math.PI}function Mu(e){let[t,n]=e.points,{style:r,width:i,height:a}=e,o=ju(t,n),s=Math.min(50,Math.hypot(n.x-t.x,n.y-t.y));return{start:t,line:Uc(t,n,i,a,r.extendLeft,r.extendRight),angle:o,radius:s,label:{text:`${o.toFixed(2)}°`,x:t.x+s+6,y:t.y+(o>=0?2:-2)}}}let Nu={type:`trend-angle`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`extendLeft`,`extendRight`,`fontSize`],paint:e=>{let{ctx:t,geometry:n}=e,{start:r,line:i,angle:a,radius:o,label:s}=Mu(n),{style:c}=n;P(e,e=>{F(e,i,!1)});let l=-a*Math.PI/180;P(e,e=>{e.moveTo(r.x,r.y),e.lineTo(r.x+o,r.y),e.arc(r.x,r.y,o,0,l,l<0)},{lineWidth:1,lineStyle:`dotted`}),t.font=E(c.fontSize,n.fontFamily),t.fillStyle=c.color,t.textAlign=`left`,t.textBaseline=a>=0?`top`:`bottom`,t.fillText(s.text,s.x,s.y)},hitTest:(e,t,n)=>{let[r,i]=Mu(e).line;return eu(t,r,i,n)},bounds:e=>{let{start:t,radius:n,label:r,angle:i,line:a}=Mu(e),{fontSize:o}=e.style;return N([...a,{x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y+n},{x:r.x+e.measureText(r.text),y:r.y+(i>=0?o:-o)}])},levels:([e,t],n,r)=>[vu(`line`,e,t,r)]};function Pu([e,t],n){let r=Math.min(e.time,t.time),i=Math.max(e.time,t.time),a=(e,t)=>{let a={time:r,price:t},o={time:i,price:t};return n?vu(e,a,o,n):{key:e,from:a,to:o}};return[a(`top`,Math.max(e.price,t.price)),a(`bottom`,Math.min(e.price,t.price))]}let Fu=[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`,`extendLeft`,`extendRight`];function Iu(e,t){return[e,{x:t.x,y:e.y},t,{x:e.x,y:t.y}]}function Lu(e){let[t,n]=e.points,{extendLeft:r,extendRight:i}=e.style,a=t.x<=n.x,o=(t,n)=>({x:n?r?Math.min(0,t.x):t.x:i?Math.max(e.width,t.x):t.x,y:t.y}),s=Iu(o(t,a),o(n,!a)),c=[a?r:i,!1,a?i:r,!1];return{area:s,border:M(s,!0).filter((e,t)=>!c[t])}}function Ru(e,t){return(e.x-t.x)*(e.y-t.y)>0?`nwse-resize`:`nesw-resize`}function zu(e){let[t,n]=e.points,r={x:(t.x+n.x)/2,y:(t.y+n.y)/2},i={x:t.x,y:n.y},a={x:n.x,y:t.y};return[{id:`0`,...t,cursor:Ru(t,n)},{id:`1`,...n,cursor:Ru(n,t)},{id:`ab`,...i,cursor:Ru(i,a)},{id:`ba`,...a,cursor:Ru(a,i)},{id:`price-0`,x:r.x,y:t.y,cursor:`ns-resize`},{id:`price-1`,x:r.x,y:n.y,cursor:`ns-resize`},{id:`time-0`,x:t.x,y:r.y,cursor:`ew-resize`},{id:`time-1`,x:n.x,y:r.y,cursor:`ew-resize`}]}function Bu([e,t],n){switch(n){case`ab`:return{time:t.time,price:e.price};case`ba`:return{time:e.time,price:t.price};default:return null}}function Vu([e,t],n,r){switch(n){case`0`:return[r,t];case`1`:return[e,r];case`ab`:return[{time:r.time,price:e.price},{time:t.time,price:r.price}];case`ba`:return[{time:e.time,price:r.price},{time:r.time,price:t.price}];case`price-0`:return[{...e,price:r.price},t];case`price-1`:return[e,{...t,price:r.price}];case`time-0`:return[{...e,time:r.time},t];default:return[e,{...t,time:r.time}]}}let Hu={type:`rectangle`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`,`extendLeft`,`extendRight`,`text`,`textColor`,`fontSize`,`bold`,`italic`,`textAlign`,`textPosition`],defaultStyle:e=>({fillColor:C(e.accent,.12),textAlign:`center`,textPosition:`middle`}),paint:e=>{let[t,n]=e.geometry.points,r=Lu(e.geometry);e.geometry.style.fill&&I(e.ctx,r.area,e.geometry.style.fillColor),P(e,e=>{r.border.length===4?F(e,r.area,!0):r.border.forEach(t=>{F(e,t,!1)})}),pu(e,t,n)},hitTest:(e,t,n)=>L(t,Lu(e).border,n),bounds:e=>N(Lu(e).area),handles:zu,moveHandle:Vu,pivotOf:Bu,levels:(e,t,n)=>Pu(e,n)};function Uu(e,t,n){if(e.x===t.x)return{x:n.x-e.x,y:0};let r=e.y+(n.x-e.x)/(t.x-e.x)*(t.y-e.y);return{x:0,y:n.y-r}}function Wu(e,t){let[n,r,i]=e.points,{width:a,height:o,style:s}=e,c=Uu(n,r,i),l=(e,t)=>({x:e.x+c.x*t,y:e.y+c.y*t}),[u,d]=t?Uc(n,r,a,o,s.extendLeft,s.extendRight):[n,r],f=[u,d],p=[l(u,1),l(d,1)];return{base:f,parallel:p,lines:[f,p],middle:[l(u,.5),l(d,.5)],area:[u,d,p[1],p[0]]}}function Gu(e){let{base:t,parallel:n}=Wu(e,!1),r=([e,t])=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});return[{id:`0`,...t[0]},{id:`1`,...t[1]},{id:`p0`,...n[0]},{id:`p1`,...n[1]},{id:`m0`,...r(t),cursor:`ns-resize`},{id:`m1`,...r(n),cursor:`ns-resize`}]}function Ku([e,t,n],r){let i=e=>r.barIndex(e.time),a=e=>r.toScale(e.price),o=n=>i(e)===i(t)?a(e):a(e)+(n-i(e))/(i(t)-i(e))*(a(t)-a(e));return{base:o,height:a(n)-o(i(n)),raised:(e,t)=>({time:e.time,price:r.fromScale(a(e)+t)})}}function qu(e,t,n,r){let[i,a]=e,{base:o,height:s,raised:c}=Ku(e,r),l=e=>r.barIndex(e.time),u=e=>r.toScale(e.price),d=(e,t,n)=>[e,t,c(e,n)],f=c(n,-s);switch(t){case`0`:return d(n,a,s);case`1`:return d(i,n,s);case`p0`:return d(f,a,s);case`p1`:return d(i,f,s);case`m0`:{let e=u(n)-o(l(n));return d(c(i,e),c(a,e),s-e)}default:return d(i,a,u(n)-o(l(n)))}}function Ju(e,t,n){if(t!==`p0`&&t!==`p1`)return null;let[r,i]=e,{height:a,raised:o}=Ku(e,n);return o(t===`p0`?i:r,a)}let Yu={type:`parallel-channel`,points:3,fields:Fu,defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{let t=Wu(e.geometry,!0);e.geometry.style.fill&&I(e.ctx,t.area,e.geometry.style.fillColor),P(e,e=>{t.lines.forEach(t=>{F(e,t,!1)})}),P(e,e=>{F(e,t.middle,!1)},{lineStyle:`dashed`})},hitTest:(e,t,n)=>L(t,Wu(e,!0).lines,n),bounds:e=>N(Wu(e,!0).area),handles:Gu,moveHandle:qu,pivotOf:Ju,levels:([e,t,n],r,i,{barIndex:a})=>{let o=n.time===e.time?0:(a(n.time)-a(e.time))/(a(t.time)-a(e.time)),s=r.toScale(e.price),c=s+o*(r.toScale(t.price)-s),l=r.toScale(n.price)-c,u=(e,t)=>({time:e.time,price:r.fromScale(r.toScale(e.price)+l*t)});return[vu(`base`,e,t,i),vu(`parallel`,u(e,1),u(t,1),i),vu(`middle`,u(e,.5),u(t,.5),i)]},axisMarks:([e,t])=>({prices:[e.price,t.price],times:[e.time,t.time]})};function Xu(e){return(e.text===``?e.texts.text:e.text).split(`
|
|
5
|
+
`)}function Zu(e){let[t]=e.points,n=Xu(e),r=Kc(e.style.fontSize),i=Math.max(...n.map(t=>e.measureText(t)));return{x:t.x-4,y:t.y-r/2-4,width:i+8,height:n.length*r+8}}let Qu={type:`text`,points:1,editableText:!0,fields:[`text`,`textColor`,`fontSize`,`bold`,`italic`,`textAlign`,`fill`,`fillColor`],defaultStyle:e=>({fill:!1,fillColor:C(e.accent,.12)}),paint:e=>{let{ctx:t,geometry:n,hovered:r,selected:i,editing:a}=e,[o]=n.points,s=Zu(n);if(a)return;n.style.fill&&(t.fillStyle=n.style.fillColor,t.fillRect(s.x,s.y,s.width,s.height)),(r||i)&&(t.fillStyle=C(n.style.color,.08),t.fillRect(s.x,s.y,s.width,s.height),w(t,C(n.style.color,i?.9:.5),1),t.strokeRect(s.x+.5,s.y+.5,s.width-1,s.height-1));let{textColor:c}=n.style;du(e,Xu(n),o.x,o.y,s.width-8,n.text===``?C(c,.5):c)},hitTest:(e,t,n)=>{let r=Zu(e);return Wc(t,{x:r.x,y:r.y},{x:r.x+r.width,y:r.y+r.height},n)?Ql:null},handles:()=>[],axisMarks:()=>({prices:[],times:[]}),bounds:Zu},$u={type:`path`,points:0,fields:[`color`,`lineWidth`,`lineStyle`,`startArrow`,`endArrow`],paint:e=>{let{ctx:t,geometry:n}=e,{points:r,style:i}=n,[a,o]=r,[s,c]=r.slice(2).reduce(([,e],t)=>[e,t],[a,o]),l=(e,t)=>{let n=Math.hypot(e.x-t.x,e.y-t.y),r=n===0?0:ou(i,n)/n;return{x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r}},u=[...r];i.startArrow&&(u[0]=l(a,o)),i.endArrow&&(u[u.length-1]=l(c,s)),P(e,e=>{F(e,u,!1)}),i.startArrow&&su(t,a,Math.atan2(a.y-o.y,a.x-o.x),i),i.endArrow&&su(t,c,Math.atan2(c.y-s.y,c.x-s.x),i)},hitTest:(e,t,n)=>L(t,M(e.points,!1),n),bounds:e=>N(e.points)},ed=[{value:0},{value:.236},{value:.382},{value:.5},{value:.618},{value:.786},{value:1},{value:1.618},{value:2.618},{value:3.618},{value:4.236},{value:1.272,visible:!1},{value:1.414,visible:!1},{value:2.272,visible:!1},{value:2.414,visible:!1},{value:2,visible:!1},{value:3,visible:!1},{value:3.272,visible:!1},{value:3.414,visible:!1},{value:4,visible:!1},{value:4.272,visible:!1},{value:4.414,visible:!1},{value:4.618,visible:!1},{value:4.764,visible:!1}],td=[{value:0},{value:.382},{value:.618},{value:1},{value:1.272},{value:1.618},{value:2},{value:2.618}],nd=[0,.236,.382,.5,.618,.786,1,1.618,2.618,3.618,4.236],rd=[0,1,2,3,5,8,13,21,34,55,89];function id(e,t){let{points:n,anchors:r,style:i}=e,a=n.map(e=>e.x),o=R(i.levels,i,e.theme.palette).map(({value:n,color:i})=>{let a=t.price(r,n);return{level:n,price:a,y:e.valueToY(a),color:i}}),s=Math.min(...a),c=Math.max(...a);return{guide:n,left:i.extendLeft?Math.min(0,s):s,right:i.extendRight?Math.max(e.width,c):c,labels:i.extendLeft?0:s,levels:o.sort((e,t)=>e.level-t.level)}}function ad(e,t,n){return`${z(t)} ${e.formatValue(n)}`}function od(e,t){let n=e.style.fontSize+4;return N([...t.guide,...sd(t).flat(),...t.levels.map(({level:r,price:i,y:a})=>({x:t.labels+4+e.measureText(ad(e,r,i)),y:a-n}))])}function sd({left:e,right:t,levels:n}){return n.map(({y:n})=>[{x:e,y:n},{x:t,y:n}])}function cd(e,t){return{type:e,points:t.points,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`extendLeft`,`extendRight`],defaultStyle:()=>({levels:t.levels}),levels:(e,n,r)=>{let i=e.map(e=>e.time);return R(r.levels,r).map(({value:n})=>{let a=t.price(e,n);return vu(z(n),{time:Math.min(...i),price:a},{time:Math.max(...i),price:a},r)})},paint:e=>{let{ctx:n,geometry:r}=e,i=id(r,t),{left:a,right:o,levels:s}=i;r.style.fill&&s.forEach(({y:e,color:t},r)=>{let i=s[r+1];i&&(n.fillStyle=C(t,.1),n.fillRect(a,e,o-a,i.y-e))}),s.forEach(({y:t,color:n})=>{P(e,e=>{e.moveTo(a,t),e.lineTo(o,t)},{color:n})}),P(e,e=>{F(e,i.guide,!1)},{lineStyle:`dashed`}),n.font=E(r.style.fontSize-1,r.fontFamily),n.textAlign=`left`,n.textBaseline=`bottom`,s.forEach(({level:e,price:t,y:a,color:o})=>{n.fillStyle=o,n.fillText(ad(r,e,t),i.labels+4,a-3)})},hitTest:(e,n,r)=>L(n,sd(id(e,t)),r),bounds:e=>od(e,id(e,t))}}let ld=/* @__PURE__ */ cd(`fib-retracement`,{points:2,levels:ed,price:([e,t],n)=>t.price+(e.price-t.price)*n}),ud=/* @__PURE__ */ cd(`fib-extension`,{points:3,levels:td,price:([e,t,n],r)=>n.price+(t.price-e.price)*r});function dd(e){let[t,n,r]=e.points,{style:i,width:a,height:o}=e,s=(e,n)=>({x:e.x+(r.x-t.x)*n,y:e.y+(r.y-t.y)*n});return R(i.levels,i,e.theme.palette).map(({value:e,color:r})=>({level:e,color:r,line:Uc(s(t,e),s(n,e),a,o,i.extendLeft,i.extendRight)})).sort((e,t)=>e.level-t.level)}function fd([e,t]){let[n,r]=e.x<=t.x?[e,t]:[t,e];return n.x>=0||r.x===n.x?n:{x:0,y:n.y+(r.y-n.y)*-n.x/(r.x-n.x)}}let pd={type:`fib-channel`,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`extendLeft`,`extendRight`],defaultStyle:()=>({levels:nd.map(e=>({value:e}))}),paint:e=>{let{ctx:t,geometry:n}=e,r=dd(n);n.style.fill&&r.forEach(({line:e,color:n},i)=>{let a=r[i+1];a&&(t.beginPath(),F(t,[e[0],e[1],a.line[1],a.line[0]],!0),t.fillStyle=C(n,.1),t.fill())});for(let{line:t,color:n}of r)P(e,e=>{F(e,t,!1)},{color:n});t.font=E(n.style.fontSize-1,n.fontFamily),t.textAlign=`left`,t.textBaseline=`bottom`;for(let{level:e,line:i,color:a}of r){let r=fd(i);t.fillStyle=a,t.fillText(ad(n,e,n.yToValue(r.y)),r.x+4,r.y-3)}},bounds:e=>{let t=e.style.fontSize+4;return N(dd(e).flatMap(({level:n,line:r})=>{let i=fd(r),a=ad(e,n,e.yToValue(i.y));return[...r,{x:i.x+4+e.measureText(a),y:i.y-t}]}))},hitTest:(e,t,n)=>L(t,dd(e).map(({line:e})=>e),n),levels:([e,t,n],r,i,{barIndex:a,timeAt:o})=>{let s=a(n.time)-a(e.time),c=r.toScale(n.price)-r.toScale(e.price),l=(e,t)=>({time:o(a(e.time)+s*t),price:r.fromScale(r.toScale(e.price)+c*t)});return R(i.levels,i).map(({value:n})=>vu(z(n),l(e,n),l(t,n),i))}};function md(e){let[t,n]=e.points,{style:r}=e;return R(r.levels,r).map(({value:e,color:r})=>({count:e,x:t.x+(n.x-t.x)*e,color:r})).sort((e,t)=>e.count-t.count)}let hd={type:`fib-time-zone`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`],defaultStyle:()=>({fill:!1,levels:rd.map(e=>({value:e}))}),paint:e=>{let{ctx:t,geometry:n}=e,r=md(n),{height:i,style:a}=n;a.fill&&r.forEach(({x:e,color:n},a)=>{let o=r[a+1];o&&(t.fillStyle=C(n,.1),t.fillRect(e,0,o.x-e,i))});for(let{x:t,color:n}of r)P(e,e=>{e.moveTo(t,0),e.lineTo(t,i)},{color:n});P(e,e=>{F(e,n.points,!1)},{lineStyle:`dashed`}),t.font=E(a.fontSize-1,n.fontFamily),t.textAlign=`left`,t.textBaseline=`bottom`;for(let{count:e,x:n,color:a}of r)t.fillStyle=a,t.fillText(z(e),n+4,i-4)},hitTest:(e,t,n)=>{let r=md(e),[i,a]=e.points;return L(t,[[i,a],...r.map(({x:t})=>[{x:t,y:0},{x:t,y:e.height}])],n)},bounds:e=>N([...e.points,...md(e).flatMap(({count:t,x:n})=>[{x:n,y:0},{x:n+4+e.measureText(z(t)),y:e.height}])]),axisMarks:([e,t])=>({prices:[],times:[e.time,t.time]})};function gd(e,t){let[n]=t,r=$l(t);e.moveTo(n.x,n.y);for(let[n,r]of M(t.slice(1),!1))e.quadraticCurveTo(n.x,n.y,(n.x+r.x)/2,(n.y+r.y)/2);e.lineTo(r.x,r.y)}function _d(e,t,n){let r=t?$l(e):e[0],i=e=>Math.hypot(e.x-r.x,e.y-r.y)>=n,a=(t?e.findLast(i):e.find(i))??(t?e[0]:$l(e));return Math.atan2(r.y-a.y,r.x-a.x)}function vd(e){let t=e.map(e=>e.price),n=e.map(e=>e.time);return{prices:[Math.max(...t),Math.min(...t)],times:[Math.min(...n),Math.max(...n)]}}let yd={type:`brush`,points:0,freehand:!0,fields:[`color`,`lineWidth`,`fill`,`fillColor`,`startArrow`,`endArrow`],defaultStyle:()=>({fill:!1,lineWidth:2}),paint:e=>{let{ctx:t,geometry:n}=e,{points:r,style:i}=n;i.fill&&(t.beginPath(),gd(t,r),t.closePath(),t.fillStyle=i.fillColor,t.fill()),P(e,e=>{gd(e,r)},{lineStyle:`solid`});let a=au(i);i.startArrow&&su(t,r[0],_d(r,!1,a),i),i.endArrow&&su(t,$l(r),_d(r,!0,a),i)},hitTest:(e,t,n)=>L(t,M(e.points,!1),n),handles:()=>[],bounds:e=>N(e.points),axisMarks:vd},bd={type:`highlighter`,points:0,freehand:!0,fields:[`color`,`lineWidth`],defaultStyle:()=>({color:`rgba(255, 196, 0, 0.35)`,lineWidth:12}),paint:e=>{P(e,t=>{gd(t,e.geometry.points)},{lineStyle:`solid`})},hitTest:(e,t,n)=>L(t,M(e.points,!1),n+e.style.lineWidth/2),handles:()=>[],bounds:e=>N(e.points,e.style.lineWidth/2),axisMarks:vd};function xd(e){let[,t]=e.points,n=Xu(e),r=Kc(e.style.fontSize),i=Math.max(...n.map(t=>e.measureText(t)));return{x:t.x-6,y:t.y-r/2-6,width:i+12,height:n.length*r+12}}function Sd(e,t){return{x:Math.min(Math.max(e.x,t.x),t.x+t.width),y:Math.min(Math.max(e.y,t.y),t.y+t.height)}}let Cd={type:`callout`,points:2,editableText:!0,textAnchor:1,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`,`text`,`textColor`,`fontSize`,`bold`,`italic`,`textAlign`],defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{let{ctx:t,geometry:n,editing:r}=e,[i,a]=n.points,o=xd(n),{style:s}=n,c=Sd(i,o);P(e,e=>{e.moveTo(i.x,i.y),e.lineTo(c.x,c.y)}),t.beginPath(),t.arc(i.x,i.y,3,0,Math.PI*2),t.fillStyle=s.color,t.fill();let l=e=>{e.roundRect(o.x,o.y,o.width,o.height,4)};s.fill&&(t.beginPath(),l(t),t.fillStyle=s.fillColor,t.fill()),P(e,l,{lineStyle:`solid`}),!r&&du(e,Xu(n),a.x,a.y,o.width-12,n.text===``?C(s.textColor,.5):s.textColor)},hitTest:(e,t,n)=>{let[r]=e.points,i=xd(e);if(t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height)return Ql;let a=zc(t,r,Sd(r,i));return a<=n?{part:`line`,distance:a}:null},bounds:e=>{let[t]=e.points,n=xd(e),r=Math.min(n.x,t.x),i=Math.min(n.y,t.y);return{x:r,y:i,width:Math.max(n.x+n.width,t.x)-r,height:Math.max(n.y+n.height,t.y)-i}}},wd=[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`,`text`,`textColor`,`fontSize`,`bold`,`italic`];function Td(e,t){let{ctx:n,geometry:r,editing:i}=e,{center:a,radiusX:o,radiusY:s,rotation:c}=t,l=e=>{e.ellipse(a.x,a.y,o,s,c,0,Math.PI*2)};if(r.style.fill&&(n.beginPath(),l(n),n.fillStyle=r.style.fillColor,n.fill()),P(e,l),!i&&r.text!==``){let t=r.text.split(`
|
|
6
|
+
`),n=Kc(r.style.fontSize);du({...e,geometry:{...r,style:{...r.style,textAlign:`center`}}},t,a.x,a.y-(t.length-1)*n/2,0,r.style.textColor)}}function Ed(e,t,n){let{center:r,radiusX:i,radiusY:a,rotation:o}=e;if(i<=0||a<=0)return null;let s=t.x-r.x,c=t.y-r.y,l=(s*Math.cos(o)+c*Math.sin(o))/i,u=(-s*Math.sin(o)+c*Math.cos(o))/a,d=Math.abs(Math.hypot(l,u)-1)*Math.min(i,a);return d<=n?{part:`line`,distance:d}:null}function Dd({center:e,radiusX:t,radiusY:n,rotation:r}){let i=Math.cos(r),a=Math.sin(r),o=Math.hypot(t*i,n*a),s=Math.hypot(t*a,n*i);return{x:e.x-o,y:e.y-s,width:o*2,height:s*2}}function Od(e){let[t,n]=e.points,r=Math.hypot(n.x-t.x,n.y-t.y);return{center:t,radiusX:r,radiusY:r,rotation:0}}let kd={type:`circle`,points:2,fields:wd,defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{Td(e,Od(e.geometry))},hitTest:(e,t,n)=>Ed(Od(e),t,n),bounds:e=>Dd(Od(e)),axisMarks:([e])=>({prices:[e.price],times:[e.time]})};function Ad(e){let[t,n,r]=e.points,i=Math.hypot(n.x-t.x,n.y-t.y);if(i===0)return null;let a={x:(t.x+n.x)/2,y:(t.y+n.y)/2},o={x:-(n.y-t.y)/i,y:(n.x-t.x)/i},s=(r.x-a.x)*o.x+(r.y-a.y)*o.y;return{center:a,radiusX:i/2,radiusY:Math.abs(s),rotation:Math.atan2(n.y-t.y,n.x-t.x),normal:s<0?{x:-o.x,y:-o.y}:o}}let jd={type:`ellipse`,points:3,fields:wd,defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{let t=Ad(e.geometry);t&&Td(e,t)},hitTest:(e,t,n)=>{let r=Ad(e);return r?Ed(r,t,n):null},handles:e=>{let[t,n]=e.points,r=Ad(e);return r?[{id:`0`,...t},{id:`1`,...n},{id:`2`,x:r.center.x+r.normal.x*r.radiusY,y:r.center.y+r.normal.y*r.radiusY}]:e.points.map((e,t)=>({id:String(t),...e}))},bounds:e=>{let t=Ad(e);return t&&Dd(t)},axisMarks:([e,t])=>({prices:[e.price,t.price],times:[e.time,t.time]})},Md={type:`triangle`,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{let{points:t}=e.geometry;e.geometry.style.fill&&I(e.ctx,t,e.geometry.style.fillColor),P(e,e=>{F(e,t,!0)})},hitTest:(e,t,n)=>L(t,M(e.points,!0),n),bounds:e=>N(e.points)};function Nd(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?Math.hypot(n.x-e.x,n.y-e.y):Math.abs((t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x))/r}function Pd(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?e:{x:e.x-(t.y-e.y)/r*n,y:e.y+(t.x-e.x)/r*n}}function Fd([e,t,n]){let r=Nd(e,t,n);return[Pd(e,t,r),Pd(t,e,-r),Pd(t,e,r),Pd(e,t,-r)]}let Id={type:`rotated-rectangle`,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:C(e.accent,.12)}),paint:e=>{let t=Fd(e.geometry.points);e.geometry.style.fill&&I(e.ctx,t,e.geometry.style.fillColor),P(e,e=>{F(e,t,!0)})},hitTest:(e,t,n)=>L(t,M(Fd(e.points),!0),n),bounds:e=>N(Fd(e.points)),handles:e=>{let[t,n]=e.points;return[{id:`0`,...t},{id:`1`,...n},...Fd(e.points).map((e,t)=>({id:`corner-${String(t)}`,...e}))]},moveHandle:([e,t,n],r,i,a)=>{if(r.startsWith(`corner-`))return[e,t,i];let o=e=>({x:a.barIndex(e.time),y:a.toScale(e.price)*a.unitHeight}),[s,c]=r===`0`?[i,t]:[e,i],l=Pd(o(s),o(c),Nd(o(e),o(t),o(n))),u={time:a.timeAt(l.x),price:a.fromScale(l.y/a.unitHeight)};return Number.isFinite(u.time)&&Number.isFinite(u.price)?[s,c,u]:[s,c,n]},pivotOf:([,e],t)=>t.startsWith(`corner-`)?e:null,axisMarks:([e,t])=>({prices:[e.price,t.price],times:[e.time,t.time]})};function Ld(e){let[t,n]=e.points,r=Math.min(t.x,n.x),i=Math.abs(n.x-t.x),a=t=>[{x:t,y:0},{x:t,y:e.height}];if(i<2)return[a(r)];let o=[];for(let t=r+Math.max(0,Math.ceil(-r/i))*i;t<=e.width;t+=i)o.push(a(t));return o}let Rd={type:`cyclic-lines`,points:2,fields:[`color`,`lineWidth`,`lineStyle`],paint:e=>{P(e,t=>{for(let n of Ld(e.geometry))F(t,n,!1)})},hitTest:(e,t,n)=>{let[r,i]=e.points;return L(t,Ld(e),n)??([r,i].some(e=>Wc(t,e,e,n))?{part:`line`,distance:0}:null)},bounds:e=>{let[t,n]=e.points,r=Math.min(t.x,n.x);return{x:r,y:0,width:Math.max(0,e.width-r),height:e.height}},axisMarks:([e,t])=>({prices:[],times:[e.time,t.time]})},zd=[0,.25,.382,.5,.618,.75,1],Bd=.08,Vd=()=>({levels:zd.map(e=>({value:e})),timeLevels:zd.map(e=>({value:e}))});function Hd(e,t,n,r){return R(e,t.style,t.theme.palette).map(({value:e,color:t})=>({ratio:e,at:n+(r-n)*e,color:t})).sort((e,t)=>e.ratio-t.ratio)}function Ud(e,t,n){P(e,e=>{F(e,t,!1)},n)}function Wd(e,t){e.font=E(t.style.fontSize-1,t.fontFamily)}function Gd(e,t){return{left:Math.min(e.x,t.x),right:Math.max(e.x,t.x),top:Math.min(e.y,t.y),bottom:Math.max(e.y,t.y)}}function Kd(e,t,n){let r=4+Math.max(0,...n.map(({ratio:t})=>e.measureText(z(t)))),i=4+e.style.fontSize;return{x:t.left-r,y:t.top-i,width:t.right-t.left+r*2,height:t.bottom-t.top+i*2}}function qd(e,t,n,r,i){Wd(e,t),e.textBaseline=`middle`;for(let{ratio:t,at:i,color:a}of r)e.fillStyle=a,e.textAlign=`right`,e.fillText(z(t),n.left-4,i),e.textAlign=`left`,e.fillText(z(t),n.right+4,i);e.textAlign=`center`;for(let{ratio:t,at:r,color:a}of i)e.fillStyle=a,e.textBaseline=`bottom`,e.fillText(z(t),r,n.top-4),e.textBaseline=`top`,e.fillText(z(t),r,n.bottom+4)}function Jd(e){let[t,n]=e.points;return{first:t,second:n,prices:Hd(e.style.levels,e,t.y,n.y),times:Hd(e.style.timeLevels,e,t.x,n.x)}}function Yd({first:e,second:t,prices:n,times:r}){return[...n.map(({at:n,color:r})=>({line:[{x:e.x,y:n},{x:t.x,y:n}],color:r})),...r.map(({at:n,color:r})=>({line:[{x:n,y:e.y},{x:n,y:t.y}],color:r}))]}let Xd={type:`gann-box`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`timeLevels`,`fill`],defaultStyle:Vd,paint:e=>{let{ctx:t,geometry:n}=e,r=Jd(n),{first:i,second:a,prices:o,times:s}=r;n.style.fill&&(o.forEach(({at:e,color:n},r)=>{let s=o[r+1];s&&I(t,Iu({x:i.x,y:e},{x:a.x,y:s.at}),C(n,Bd))}),s.forEach(({at:e,color:n},r)=>{let o=s[r+1];o&&I(t,Iu({x:e,y:i.y},{x:o.at,y:a.y}),C(n,Bd))}));for(let{line:t,color:n}of Yd(r))Ud(e,t,{color:n});qd(t,n,Gd(i,a),o,s)},hitTest:(e,t,n)=>L(t,Yd(Jd(e)).map(({line:e})=>e),n),bounds:e=>{let t=Jd(e);return Kd(e,Gd(t.first,t.second),[...t.prices,...t.times])},handles:zu,moveHandle:Vu,pivotOf:Bu,levels:([e,t],n,r)=>{let i=n.toScale(e.price),a=n.toScale(t.price),o=Math.min(e.time,t.time),s=Math.max(e.time,t.time);return R(r.levels,r).map(({value:e})=>{let t=n.fromScale(i+(a-i)*e);return{key:z(e),from:{time:o,price:t},to:{time:s,price:t}}})}};function Zd(e){let[t,n]=e.points,r=Hd(e.style.levels,e,n.y,t.y),i=Hd(e.style.timeLevels,e,n.x,t.x),a=n=>Vc(t,n,e.width,e.height,`ray`);return{origin:t,corner:n,prices:r.map(e=>({...e,ray:a({x:n.x,y:e.at})})),times:i.map(e=>({...e,ray:a({x:e.at,y:n.y})}))}}function Qd({prices:e,times:t}){return[...e,...t].map(({ray:e})=>e)}function $d({origin:e,corner:t,prices:n,times:r}){return[...n.map(({at:n})=>[{x:e.x,y:n},{x:t.x,y:n}]),...r.map(({at:n})=>[{x:n,y:e.y},{x:n,y:t.y}])]}function ef(e,t){return t.flatMap(({ray:n,color:r},i)=>{let a=t[i+1];return a?[{area:[e,n[1],a.ray[1]],color:r}]:[]})}let tf={type:`fib-speed-fan`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`timeLevels`,`fill`],defaultStyle:Vd,paint:e=>{let{ctx:t,geometry:n}=e,r=Zd(n),{origin:i,corner:a,prices:o,times:s}=r;if(n.style.fill)for(let{area:e,color:n}of[...ef(i,o),...ef(i,s)])I(t,e,C(n,Bd));for(let t of $d(r))Ud(e,t,{color:C(n.style.color,.5),lineWidth:1});for(let{ray:t,color:n}of[...o,...s])Ud(e,t,{color:n});qd(t,n,Gd(i,a),o,s)},hitTest:(e,t,n)=>{let r=Zd(e);return L(t,[...Qd(r),...$d(r)],n)},bounds:e=>{let t=Zd(e),n=Kd(e,Gd(t.origin,t.corner),[...t.prices,...t.times]);return N([...Qd(t).flat(),...qc(n)])},levels:([e,t],n,r,{barIndex:i,timeAt:a})=>{let o=n.toScale(t.price),s=n.toScale(e.price),c=e=>R(e,r).map(e=>e.value),l=(t,n)=>({key:t,from:e,to:n,extend:`end`}),u=i(t.time),d=i(e.time)-u;return[...c(r.levels).map(e=>l(z(e),{time:t.time,price:n.fromScale(o+(s-o)*e)})),...c(r.timeLevels).filter(n=>n!==1&&e.time!==t.time).map(e=>l(`time-${z(e)}`,{time:a(u+d*e),price:t.price}))]}},nf=[8,4,3,2,1,1/2,1/3,1/4,1/8];function rf(e){return e>=1?`${z(e)}×1`:`1×${z(Math.round(100/e)/100)}`}function af(e){let[t,n]=e.points,r=n.x-t.x,i=n.y-t.y;return r===0&&i===0?[]:R(e.style.levels,e.style,e.theme.palette).filter(({value:e})=>e>0).sort((e,t)=>t.value-e.value).map(({value:a,color:o})=>{let s=a<=1?{x:n.x,y:t.y+i*a}:{x:t.x+r/a,y:n.y};return{ratio:a,color:o,ray:Vc(t,s,e.width,e.height,`ray`)}})}function of(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=i>0?(n-e.x)/i:i<0?-e.x/i:1/0,s=a>0?(r-e.y)/a:a<0?-e.y/a:1/0,c=Math.min(o,s),l={x:e.x+i*c,y:e.y+a*c};return c>0&&Wc(l,{x:0,y:0},{x:n,y:r},.5)?l:null}function sf(e,t,[n,r],i){let{width:a,height:o}=t,s=of(n,r,a,o);if(!s)return;let c=s.y<n.y;if(s.x<=.5||s.x>=a-.5){let t=s.x>=a-.5;e.textAlign=t?`right`:`left`,e.textBaseline=c?`bottom`:`top`,e.fillText(i,s.x+(t?-4:4),s.y+(c?-1:1)*4);return}let l=s.y<=o/2,u=t.measureText(i)+4,d=s.x>=n.x?s.x+u<=a:s.x-u<0;e.textAlign=d?`left`:`right`,e.textBaseline=l?`top`:`bottom`,e.fillText(i,s.x+(d?4:-4),s.y+(l?1:-1)*4)}let cf={type:`gann-fan`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`],defaultStyle:()=>({levels:nf.map(e=>({value:e}))}),paint:e=>{let{ctx:t,geometry:n}=e,r=af(n),[i]=n.points;n.style.fill&&r.forEach(({ray:e,color:n},a)=>{let o=r[a+1];o&&I(t,[i,e[1],o.ray[1]],C(n,Bd))});for(let{ray:t,color:n}of r)Ud(e,t,{color:n});Wd(t,n);for(let{ratio:e,color:i,ray:a}of r)t.fillStyle=i,sf(t,n,a,rf(e))},hitTest:(e,t,n)=>L(t,af(e).map(({ray:e})=>e),n),bounds:e=>N([...e.points,...af(e).flatMap(({ray:e})=>e)]),levels:([e,t],n,r,{barIndex:i,timeAt:a})=>{let o=n.toScale(e.price),s=n.toScale(t.price),c=i(e.time),l=i(t.time)-c;return e.time===t.time?[]:R(r.levels,r).filter(({value:e})=>e>0).map(({value:r})=>({key:rf(r),from:e,to:r<=1?{time:t.time,price:n.fromScale(o+(s-o)*r)}:{time:a(c+l/r),price:t.price},extend:`end`}))}};function lf(e,t,n){let r=n.price-t.price,i=r>0?`+`:``;return`${`${i}${e.formatValue(r)}`}${t.price===0?``:` (${i}${(r/Math.abs(t.price)*100).toFixed(2)}%)`}`}function uf(e,t,n){return`${lf(e,t,n)} · ${e.texts.bars(ff(e,t,n))}`}function df(e,t,n){return e.texts.duration(n.time-t.time)}function ff(e,t,n){return Math.round(Math.abs(e.barIndex(n.time)-e.barIndex(t.time)))}function pf(e,t,n,r,i,a){let o=e.style.fontSize+10,s=e.measureText(t)+16,c=Math.min(n.y,r.y)-6-o/2,l=Math.max(n.y,r.y)+6+o/2,u=((a?c-o/2>=0:l+o/2<=e.height)?a:!a)?c:l;return{text:t,x:i-s/2,y:Math.min(Math.max(u,o/2),e.height-o/2)-o/2,width:s,height:o}}function mf(e,t,n){let{ctx:r,geometry:i}=e;r.font=i.textFont,yn(r,t.text,t.x+t.width/2,t.y+t.height/2,{background:n,color:`#ffffff`,paddingX:8,height:t.height,align:`center`,radius:4})}function hf(e,t,n){return n.price>=t.price?e.theme.up:e.theme.down}function gf(e,t){let[n,r]=e.points,[i,a]=e.anchors;return{start:n,end:r,color:t.color(e,i,a),arrows:t.arrows(n,r),label:pf(e,t.label(e,i,a),n,r,(n.x+r.x)/2,t.above(n,r))}}function _f(e){return{type:e.type,points:2,fields:e.fields,...e.defaultStyle?{defaultStyle:e.defaultStyle}:{},paint:t=>{let{ctx:n,geometry:r}=t,i=gf(r,e);r.style.fill&&I(n,Iu(i.start,i.end),e.fill(r,i.color));for(let[e,n]of i.arrows)cu(t,e,n,i.color);mf(t,i.label,i.color)},hitTest:(t,n,r)=>{let i=gf(t,e),{label:a}=i,o=Wc(n,a,{x:a.x+a.width,y:a.y+a.height});return L(n,i.arrows,r)??(o?Ql:null)},bounds:t=>{let{start:n,end:r,label:i}=gf(t,e);return N([n,r,...qc(i)])},...e.levels?{levels:e=>Pu(e,null)}:{}}}let vf=(e,t)=>{let n=(e.x+t.x)/2;return[[{x:n,y:e.y},{x:n,y:t.y}]]},yf=(e,t)=>{let n=(e.y+t.y)/2;return[[{x:e.x,y:n},{x:t.x,y:n}]]},bf=/* @__PURE__ */ _f({type:`price-range`,fields:[`lineWidth`,`fill`,`fontSize`],color:hf,fill:(e,t)=>C(t,.14),arrows:vf,label:uf,above:(e,t)=>t.y<=e.y,levels:!0}),xf=/* @__PURE__ */ _f({type:`date-range`,fields:[`color`,`lineWidth`,`fill`,`fillColor`,`fontSize`],defaultStyle:e=>({fillColor:C(e.accent,.12)}),color:e=>e.style.color,fill:e=>e.style.fillColor,arrows:yf,label:(e,t,n)=>`${e.texts.bars(ff(e,t,n))} · ${df(e,t,n)}`,above:()=>!1,levels:!1}),Sf=/* @__PURE__ */ _f({type:`date-price-range`,fields:[`lineWidth`,`fill`,`fontSize`],color:hf,fill:(e,t)=>C(t,.14),arrows:(e,t)=>[...vf(e,t),...yf(e,t)],label:(e,t,n)=>`${uf(e,t,n)} · ${df(e,t,n)}`,above:()=>!1,levels:!0});function Cf(e){let[t,n]=e.points,[r,i]=e.anchors,{style:a,texts:o}=e,s=[lf(e,r,i),`${o.bars(ff(e,r,i))} · ${o.duration(i.time-r.time)}`,`${ju(t,n).toFixed(2)}°`],c=a.fontSize+4,l=Math.max(...s.map(t=>e.measureText(t)))+12,u=s.length*c-4+12,d=Math.hypot(n.x-t.x,n.y-t.y),[f,p]=d===0?[0,1]:[(t.y-n.y)/d,(n.x-t.x)/d],[m,h]=p<0||p===0&&f>0?[-f,-p]:[f,p],g=(Math.abs(m)*l+Math.abs(h)*u)/2+8,_=(t.x+n.x)/2+m*g-l/2,v=(t.y+n.y)/2+h*g-u/2;return{line:Uc(t,n,e.width,e.height,a.extendLeft,a.extendRight),box:{x:Math.min(Math.max(_,0),Math.max(0,e.width-l)),y:Math.min(Math.max(v,0),Math.max(0,e.height-u)),width:l,height:u,lines:s,lineHeight:c}}}let wf={type:`info-line`,points:2,fields:[`color`,`lineWidth`,`lineStyle`,`extendLeft`,`extendRight`,`fontSize`],paint:e=>{let{ctx:t,geometry:n}=e,{line:r,box:i}=Cf(n);P(e,e=>{F(e,r,!1)}),t.beginPath(),t.roundRect(i.x,i.y,i.width,i.height,4),t.fillStyle=C(n.style.color,.9),t.fill(),t.font=n.textFont,t.fillStyle=`#ffffff`,t.textAlign=`left`,t.textBaseline=`top`,i.lines.forEach((e,n)=>{t.fillText(e,i.x+6,i.y+6+n*i.lineHeight)})},hitTest:(e,t,n)=>{let{line:r,box:i}=Cf(e);return eu(t,r[0],r[1],n)??(Wc(t,i,{x:i.x+i.width,y:i.y+i.height},n)?Ql:null)},bounds:e=>{let{line:t,box:n}=Cf(e);return N([...t,n,{x:n.x+n.width,y:n.y+n.height}])},levels:([e,t],n,r)=>[vu(`line`,e,t,r)]};function Tf(e){let[t]=e.points,[n]=e.anchors,{style:r}=e,i=e.formatValue(n.price),a=r.fontSize+10,o=e.measureText(i)+16,s=t.x+10,c=t.y-10;return{anchor:t,box:{x:s,y:c-a,width:o,height:a},tail:[t,{x:s,y:c-a/2},{x:s+a/2,y:c}],text:i,font:e.textFont}}let Ef={type:`price-label`,points:1,fields:[`color`,`textColor`,`fontSize`],defaultStyle:()=>({textColor:`#ffffff`,bold:!0}),paint:e=>{let{ctx:t,geometry:n}=e,r=Tf(n),{box:i,tail:a}=r;t.beginPath(),t.roundRect(i.x,i.y,i.width,i.height,4),F(t,a,!0),t.fillStyle=n.style.color,t.fill(),t.font=r.font,t.fillStyle=n.style.textColor,t.textAlign=`center`,t.textBaseline=`middle`,t.fillText(r.text,i.x+i.width/2,i.y+i.height/2+.5)},hitTest:(e,t,n)=>{let r=Tf(e),{box:i}=r;return Wc(t,{x:i.x,y:i.y},{x:i.x+i.width,y:i.y+i.height},n)||Gc(t,r.tail)?Ql:null},bounds:e=>{let{box:t,anchor:n}=Tf(e);return{x:n.x,y:t.y,width:t.x+t.width-n.x,height:n.y-t.y}}};function Df(e){let[t]=e.points,n=t.y-22,r=t.x+16;return{pole:{x:t.x,y:n},outline:[{x:t.x,y:n},{x:r,y:n},{x:r-4,y:n+5},{x:r,y:n+10},{x:t.x,y:n+10}]}}let Of={type:`flag-mark`,points:1,fields:[`color`],paint:e=>{let{ctx:t,geometry:n}=e,[r]=n.points,i=Df(n);P(e,e=>{e.moveTo(r.x,r.y),e.lineTo(i.pole.x,i.pole.y)},{lineWidth:1.5,lineStyle:`solid`}),I(t,i.outline,n.style.color)},hitTest:(e,t,n)=>{let[r]=e.points;return Wc(t,{x:r.x,y:r.y-22},{x:r.x+16,y:r.y},n)?Ql:null},bounds:({points:[e]})=>({x:e.x,y:e.y-22,width:16,height:22})};function kf(e,t){let[n]=e.points,r=t?1:-1,i=(e,t)=>({x:n.x+e,y:n.y+r*t});return{outline:[n,i(8,10),i(3,10),i(3,22),i(-3,22),i(-3,10),i(-8,10)],textAt:i(0,26)}}function Af(e,t,n){if(e.text===``)return null;let r=e.measureText(e.text),i=e.style.fontSize;return{x:t.textAt.x-r/2,y:n?t.textAt.y:t.textAt.y-i,width:r,height:i}}function jf(e,t){return{type:e,points:1,fields:[`color`,`text`,`textColor`,`fontSize`,`bold`,`italic`],defaultStyle:e=>({color:t?e.up:e.down}),paint:e=>{let{ctx:n,geometry:r}=e,i=kf(r,t);I(n,i.outline,r.style.color),r.text!==``&&!e.editing&&(n.font=r.textFont,n.fillStyle=r.style.textColor,n.textAlign=`center`,n.textBaseline=t?`top`:`bottom`,n.fillText(r.text,i.textAt.x,i.textAt.y))},hitTest:(e,n,r)=>{let i=kf(e,t),a=Af(e,i,t),o=a!==null&&Wc(n,{x:a.x,y:a.y},{x:a.x+a.width,y:a.y+a.height},r),[s]=e.points;return Wc(n,{x:s.x-8,y:t?s.y:s.y-22},{x:s.x+8,y:t?s.y+22:s.y},r)||o||Gc(n,i.outline)?Ql:null},bounds:e=>{let n=kf(e,t),r=Af(e,n,t);return N([...n.outline,...r?[{x:r.x,y:r.y},{x:r.x+r.width,y:r.y+r.height}]:[]])}}}let Mf=/* @__PURE__ */ jf(`arrow-mark-up`,!0),Nf=/* @__PURE__ */ jf(`arrow-mark-down`,!1),Pf=[`color`,`lineWidth`,`fill`,`fillColor`,`textColor`,`fontSize`,`bold`,`italic`];function Ff(e,t,n){return[t,n].every(t=>!t||e.y<=t.y)}function If(e,t,n,r){let{ctx:i,geometry:a}=e,o=a.style.fontSize+8;i.font=a.textFont,yn(i,t,n.x,n.y+(r?-1:1)*(6+o/2),{background:a.style.color,color:a.style.textColor,paddingX:6,height:o,align:`center`,radius:3})}function Lf(e,t,n){let{fontSize:r}=e.style,i=Math.max(r+8,r*1.5),a=Math.max(0,...n.map(t=>e.measureText(t)+12));return N(t,Math.max(6+i,a/2))}function Rf(e,t,n,r){let{ctx:i,geometry:a}=e,o=a.style.fontSize+6;i.font=E(a.style.fontSize-1,a.fontFamily),yn(i,z(t),(n.x+r.x)/2,(n.y+r.y)/2,{background:a.style.color,color:a.style.textColor,paddingX:5,height:o,align:`center`,radius:3})}function zf(e,t){P(e,e=>{F(e,t,!1)},{lineWidth:1,lineStyle:`dotted`})}function B(e,t){return Math.abs(t.price-e.price)}let Bf=[`X`,`A`,`B`,`C`,`D`];function Vf([e,t,n,r,i]){return{xb:B(t,n)/B(e,t),ac:B(n,r)/B(t,n),bd:B(r,i)/B(n,r),xd:B(t,i)/B(e,t)}}let Hf={type:`xabcd-pattern`,points:5,fields:Pf,defaultStyle:e=>({fillColor:C(e.accent,.12),textColor:`#ffffff`}),paint:e=>{let{ctx:t,geometry:n}=e,{points:r}=n,[i,a,o,s,c]=r;n.style.fill&&(I(t,[i,a,o],n.style.fillColor),I(t,[o,s,c],n.style.fillColor));let l=Vf(n.anchors),u=[[l.xb,i,o],[l.ac,a,s],[l.bd,o,c],[l.xd,i,c]];for(let[,t,n]of u)zf(e,[t,n]);P(e,e=>{F(e,r,!1)},{lineStyle:`solid`});for(let[t,n,r]of u)Number.isFinite(t)&&Rf(e,t,n,r);let d=[[`X`,i,void 0,a],[`A`,a,i,o],[`B`,o,a,s],[`C`,s,o,c],[`D`,c,s,void 0]];for(let[t,n,r,i]of d)If(e,t,n,Ff(n,r,i))},hitTest:(e,t,n)=>L(t,M(e.points,!1),n),bounds:e=>Lf(e,e.points,Bf)};function Uf([e,t,n,r]){return{ac:B(t,n)/B(e,t),bd:B(n,r)/B(t,n)}}let Wf={type:`abcd-pattern`,points:4,fields:[`color`,`lineWidth`,`textColor`,`fontSize`,`bold`,`italic`],defaultStyle:()=>({textColor:`#ffffff`}),paint:e=>{let{points:t}=e.geometry,[n,r,i,a]=t,o=Uf(e.geometry.anchors),s=[[o.ac,n,i],[o.bd,r,a]];for(let[,t,n]of s)zf(e,[t,n]);P(e,e=>{F(e,t,!1)},{lineStyle:`solid`});for(let[t,n,r]of s)Number.isFinite(t)&&Rf(e,t,n,r);let c=[[`A`,n,void 0,r],[`B`,r,n,i],[`C`,i,r,a],[`D`,a,i,void 0]];for(let[t,n,r,i]of c)If(e,t,n,Ff(n,r,i))},hitTest:(e,t,n)=>L(t,M(e.points,!1),n),bounds:e=>Lf(e,e.points,[`A`,`B`,`C`,`D`])};function Gf(e,t,n,r){let i={x:t.x-e.x,y:t.y-e.y},a={x:r.x-n.x,y:r.y-n.y},o=i.x*a.y-i.y*a.x;if(o===0)return null;let s=(i.y*(n.x-e.x)-i.x*(n.y-e.y))/o;return s>=0&&s<=1?{x:n.x+a.x*s,y:n.y+a.y*s}:null}function Kf(e,t,n){return{x:n.x,y:e.x===t.x?e.y:e.y+(t.y-e.y)*(n.x-e.x)/(t.x-e.x)}}function qf(e){let{points:t}=e,[n,r,i,a,o,s,c]=t,l=Gf(i,o,n,r)??Kf(i,o,n),u=Gf(i,o,s,c)??Kf(i,o,c);return{points:t,neckline:[l,u],areas:[[l,r,i],[i,a,o],[o,s,u]]}}let Jf={type:`head-and-shoulders`,points:7,fields:Pf,defaultStyle:e=>({fillColor:C(e.accent,.12),textColor:`#ffffff`}),paint:e=>{let{ctx:t,geometry:n}=e,r=qf(n);if(n.style.fill)for(let e of r.areas)I(t,e,n.style.fillColor);zf(e,r.neckline),P(e,e=>{F(e,r.points,!1)},{lineStyle:`solid`});let{texts:i}=n,[,a,o,s,c,l,u]=r.points,d=[[i.leftShoulder,a,r.points[0],o],[i.head,s,o,c],[i.rightShoulder,l,c,u]];for(let[t,n,r,i]of d)If(e,t,n,Ff(n,r,i))},hitTest:(e,t,n)=>{let r=qf(e);return L(t,[...M(r.points,!1),r.neckline],n)},bounds:e=>{let t=qf(e),{texts:n}=e;return Lf(e,[...t.points,...t.neckline],[n.leftShoulder,n.head,n.rightShoulder])},levels:([,,e,,t])=>[{key:`neckline`,from:e,to:t,extend:`end`}]},Yf=[`I`,`II`,`III`,`IV`,`V`],Xf=[`arabic`,`roman`,`arabic`,`small`,`arabic`],Zf=[`circle`,`parentheses`,`plain`];function Qf(e,t,n,r){let i=Js.indexOf(e),a=Xf[Math.floor(i/3)]??`arabic`,o=Zf[i%3]??`plain`,s=r?.[t-1]??String.fromCharCode(65+t-1),c=n?a===`arabic`?s:s.toLowerCase():a===`arabic`?String(t):a===`roman`?Yf[t-1]??``:(Yf[t-1]??``).toLowerCase();return{text:o===`parentheses`?`(${c})`:c,circled:o===`circle`}}function $f(e,t,n,r){let{ctx:i,geometry:a}=e,{style:o}=a;i.font=a.textFont;let s=Math.max(o.fontSize*.75,(a.measureText(t.text)+6)/2),c=n.y+(r?-1:1)*(6+s);t.circled&&P(e,e=>{e.arc(n.x,c,s,0,Math.PI*2)},{lineWidth:1,lineStyle:`solid`}),i.fillStyle=o.color,i.textAlign=`center`,i.textBaseline=`middle`,i.fillText(t.text,n.x,c+.5)}function ep(e,t,n,r){return{type:e,points:t+1,fields:[`color`,`lineWidth`,`degree`,`fontSize`],paint:e=>{let{points:t,style:i}=e.geometry;P(e,e=>{F(e,t,!1)},{lineStyle:`solid`}),M(t,!1).forEach(([a,o],s)=>{$f(e,Qf(i.degree,s+1,n,r),o,Ff(o,a,t[s+2]))})},hitTest:(e,t,n)=>L(t,M(e.points,!1),n),bounds:e=>Lf(e,e.points,Array.from({length:t},(t,i)=>Qf(e.style.degree,i+1,n,r).text))}}let tp=/* @__PURE__ */ ep(`elliott-impulse`,5,!1),np=/* @__PURE__ */ ep(`elliott-correction`,3,!0),rp=/* @__PURE__ */ ep(`elliott-triangle`,5,!0),ip=/* @__PURE__ */ ep(`elliott-double-combo`,3,!0,`WXY`),ap=/* @__PURE__ */ ep(`elliott-triple-combo`,5,!0,`WXYXZ`);function op(e,t){let[n,r,i]=e.points,a=t===`pivot`?n:{x:t===`schiff`?n.x:(n.x+r.x)/2,y:(n.y+r.y)/2},o={x:(r.x+i.x)/2,y:(r.y+i.y)/2},s={x:o.x-a.x,y:o.y-a.y};if(Math.hypot(s.x,s.y)<1)return null;let{width:c,height:l}=e,u=e=>Vc(e,{x:e.x+s.x,y:e.y+s.y},c,l,`ray`),d=u(a),f=u(r),p=u(i);return{handle:a===n?null:[n,a],median:d,upper:f,lower:p,base:[r,i],area:[r,f[1],p[1],i]}}function sp(e,t){let n=e=>[e.median,e.upper,e.lower,e.base,...e.handle?[e.handle]:[]];return{type:e,points:3,fields:[`color`,`lineWidth`,`lineStyle`,`fill`,`fillColor`],defaultStyle:e=>({fillColor:C(e.accent,.08)}),paint:e=>{let r=op(e.geometry,t);r&&(e.geometry.style.fill&&I(e.ctx,r.area,e.geometry.style.fillColor),P(e,e=>{for(let t of n(r))F(e,t,!1)}))},hitTest:(e,r,i)=>{let a=op(e,t);return a?L(r,n(a),i):null},bounds:e=>{let r=op(e,t);return r&&N(n(r).flat())}}}let cp=/* @__PURE__ */ sp(`pitchfork`,`pivot`),lp=/* @__PURE__ */ sp(`schiff-pitchfork`,`schiff`),up=/* @__PURE__ */ sp(`modified-schiff-pitchfork`,`modified-schiff`);function dp([e,t,n]){return{start:e.time,end:t.time,entry:e.price,target:t.price,stop:n.price}}function fp(e,t){let n=t?1:-1,r=Math.max(e.end,e.start),i=n*e.target>=n*e.entry?e.target:e.entry,a=n*e.stop<=n*e.entry?e.stop:e.entry;return[{time:e.start,price:e.entry},{time:r,price:i},{time:r,price:a}]}function pp(e,t,n){let r=e.lowerBound(t.start),i=Math.min(e.lowerBound(t.end+1),e.length),a=null,o={kind:`pending`,entered:a,time:t.start,price:t.entry};for(let s=r;s<i;s+=1){let r=e.time(s);if(a===null){e.low(s)<=t.entry&&e.high(s)>=t.entry&&(a=r,o={kind:`open`,entered:a,time:r,price:e.close(s)});continue}let i=n?e.low(s)<=t.stop:e.high(s)>=t.stop,c=n?e.high(s)>=t.target:e.low(s)<=t.target;if(i&&t.stop!==t.entry)return{kind:`stop`,entered:a,time:r,price:t.stop};if(c&&t.target!==t.entry)return{kind:`target`,entered:a,time:r,price:t.target};o={kind:`open`,entered:a,time:r,price:e.close(s)}}return o}function mp(e,t,n){let r=e===0?0:(n?1:-1)*(t-e)/Math.abs(e)*100;return`${r>0?`+`:``}${r.toFixed(2)}%`}function hp(e){let[t,n,r]=e.points;return[t.x,n.x].some(e=>Number.isNaN(e))?null:{left:t.x,right:n.x,entry:t.y,target:n.y,stop:r.y}}function gp(e,t,n,r){return[{x:e,y:n},{x:t,y:n},{x:t,y:r},{x:e,y:r}]}function _p(e,t,n,r,i){let{ctx:a,geometry:o}=e,s=o.style.fontSize+8;a.font=E(o.style.fontSize,o.fontFamily),yn(a,t,n,Math.min(Math.max(r,s/2),o.height-s/2),{background:i,color:`#ffffff`,paddingX:6,height:s,align:`center`,radius:3})}let vp=/* @__PURE__ */ tu(64);function yp(e,t,n){let{bars:r,source:i}=e,a=r.lowerBound(t.end+1),o=a<r.length?r.time(a)-1:1/0,{start:s,entry:c,target:l,stop:u}=t;return vp(i,`${s}:${o}:${c}:${l}:${u}:${n}`,()=>pp(i,{...t,end:o},n))}function bp(e,t,n,r){let i=yp(e,n,r);if(i.entered===null)return null;let a=n=>Math.min(Math.max(t.left,Cp(e,n)),t.right);return{outcome:i,from:a(i.entered),to:a(i.time),y:e.valueToY(i.price),gain:(r?1:-1)*(i.price-n.entry)}}function xp(e,t){let{ctx:n,geometry:r}=e,i=hp(r),a=dp(r.anchors);if(!i)return;let{theme:o}=r;I(n,gp(i.left,i.right,i.entry,i.target),C(o.up,.16)),I(n,gp(i.left,i.right,i.entry,i.stop),C(o.down,.16));let s=bp(r,i,a,t);s&&I(n,gp(s.from,s.to,i.entry,s.y),C(s.gain>=0?o.up:o.down,.22))}function Sp(e,t){let{geometry:n}=e,r=hp(n),i=dp(n.anchors);if(!r)return;let{theme:a,style:o}=n,s=bp(n,r,i,t);s&&P(e,e=>{e.moveTo(s.from,r.entry),e.lineTo(s.to,s.y)},{color:a.textMuted,lineStyle:`dashed`}),P(e,e=>{e.moveTo(r.left,r.entry),e.lineTo(r.right,r.entry)});let c=(r.left+r.right)/2,l=o.fontSize,u=Math.abs(i.target-i.entry),d=Math.abs(i.entry-i.stop),f=d===0?`—`:(u/d).toFixed(2),{texts:p}=n,m=s?` · ${s.outcome.kind===`open`?p.open:s.outcome.kind===`target`?p.targetHit:p.stopped} ${mp(i.entry,s.outcome.price,t)}`:``,h=s?s.gain>=0?a.up:a.down:o.color;if(_p(e,`${p.riskReward} ${f}${m}`,c,r.entry,h),e.hovered||e.selected){let o=l/2+4+4,s=(e,t)=>e<=t?e-o:e+o;_p(e,`${p.target} ${n.formatValue(i.target)} (${mp(i.entry,i.target,t)})`,c,s(r.target,r.entry),a.up),_p(e,`${p.stop} ${n.formatValue(i.stop)} (${mp(i.entry,i.stop,t)})`,c,s(r.stop,r.entry),a.down)}}function Cp(e,t){let[n,r]=e.points,[i,a]=e.anchors,o=e.barIndex(a.time)-e.barIndex(i.time);if(o===0)return n.x;let s=(e.barIndex(t)-e.barIndex(i.time))/o;return n.x+s*(r.x-n.x)}function wp(e){let t=hp(e);if(!t)return[];let n=(t.left+t.right)/2,r=e=>[{x:t.left,y:e},{x:t.right,y:e}];return[{id:`start`,x:t.left,y:t.entry,cursor:`ew-resize`},{id:`end`,x:t.right,y:t.entry,cursor:`ew-resize`},{id:`target`,x:n,y:t.target,cursor:`ns-resize`,line:r(t.target)},{id:`stop`,x:n,y:t.stop,cursor:`ns-resize`,line:r(t.stop)},{id:`entry`,x:n,y:t.entry,cursor:`ns-resize`,line:r(t.entry),marker:!1}]}function Tp(e,t,n,r){let i=dp(e);switch(t){case`start`:return fp({...i,start:Math.min(n.time,i.end)},r);case`entry`:{let e=Math.min(i.target,i.stop),t=Math.max(i.target,i.stop);return fp({...i,entry:Math.min(Math.max(n.price,e),t)},r)}case`target`:return fp({...i,target:n.price},r);case`stop`:return fp({...i,stop:n.price},r);case`end`:return fp({...i,end:n.time},r);default:return e}}function Ep(e,t){return{type:e,points:3,place:2,mainPane:!0,fields:[`fontSize`],complete:([e,n])=>{let r=(t?1:-1)*Math.abs(n.price-e.price);return fp({start:Math.min(e.time,n.time),end:Math.max(e.time,n.time),entry:e.price,target:e.price+r,stop:e.price-r},t)},paintBelow:e=>{xp(e,t)},paint:e=>{Sp(e,t)},hitTest:(e,t,n)=>{let r=hp(e);if(!r)return null;let i=[{x:r.left,y:r.entry},{x:r.right,y:r.entry}];return L(t,[...M(gp(r.left,r.right,r.target,r.stop),!0),i],n)},bounds:e=>{let t=hp(e);if(!t)return null;let n=e.style.fontSize+8+4,r=Math.min(t.target,t.stop)-n,i=Math.max(t.target,t.stop)+n;return{x:t.left,y:r,width:t.right-t.left,height:i-r}},handles:wp,moveHandle:(e,n,r)=>Tp(e,n,r,t),axisMarks:e=>{let t=dp(e);return{prices:[t.target,t.entry,t.stop],times:[t.start,t.end]}}}}let Dp=/* @__PURE__ */ Ep(`long-position`,!0),Op=/* @__PURE__ */ Ep(`short-position`,!1);function kp(e,t,n,r){let i=e.lowerBound(Math.min(t,n)),a=e.lowerBound(Math.max(t,n)+1)-1,o=a-i+1;if(o<2)return null;let s=t=>nu(e,t,r),c=0;for(let e=i;e<=a;e+=1)c+=s(e);c/=o;let l=(o-1)/2,u=0,d=0;for(let e=i;e<=a;e+=1){let t=e-i-l;u+=t*(s(e)-c),d+=t*t}let f=u/d,p=c-f*l,m=0,h=0;for(let e=i;e<=a;e+=1){let t=s(e);m+=(t-p-f*(e-i))**2,h+=(t-c)**2}let g=f*f*d,_=h===0||g===0?0:Math.abs(u*f)/Math.sqrt(h*g);return{first:i,last:a,start:p,slope:f,deviation:Math.sqrt(m/(o-1)),pearson:_}}let Ap=/* @__PURE__ */ tu(64);function jp(e,t,n,r){return Ap(e,`${t}:${n}:${r}`,()=>kp(e,t,n,r))}function Mp(e){return R(e.levels,e).sort((e,t)=>t.value-e.value)}function Np(e){let[t,n]=e.anchors,{bars:r,style:i}=e,a=jp(r,t.time,n.time,i.source);if(!a)return null;let o=e.timeToX(r.time(a.first)),s=e.timeToX(r.time(a.last)),c=(t,n)=>({x:n===a.first?o:s,y:e.valueToY(a.start+a.slope*(n-a.first)+t*a.deviation)});return{fit:a,lines:Mp(i).map(t=>{let n=c(t.value,a.first),r=c(t.value,a.last);return{level:t,line:i.extendRight?Vc(n,r,e.width,e.height,`ray`):[n,r]}}),ends:t.time<=n.time?[c(0,a.first),c(0,a.last)]:[c(0,a.last),c(0,a.first)]}}let Pp={type:`regression-trend`,points:2,mainPane:!0,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`extendRight`,`source`],defaultStyle:()=>({levels:[{value:2},{value:0},{value:-2}]}),paint:e=>{let{ctx:t,geometry:n}=e,r=Np(n);if(!r)return;let{style:i}=n;i.fill&&r.lines.forEach(({level:e,line:n},i)=>{let a=r.lines[i+1];a&&I(t,[n[0],n[1],a.line[1],a.line[0]],C(e.color,.1))});for(let{level:t,line:n}of r.lines)P(e,e=>{F(e,n,!1)},{color:t.color,...t.value===0?{lineStyle:`dashed`}:{}});let a=r.lines.at(-1)?.line;a&&(t.font=E(i.fontSize-1,n.fontFamily),t.fillStyle=i.color,t.textAlign=`left`,t.textBaseline=`top`,t.fillText(z(r.fit.pearson),a[0].x,a[0].y+4))},hitTest:(e,t,n)=>{let r=Np(e);return r?L(t,r.lines.map(({line:e})=>e),n):null},handles:e=>(Np(e)?.ends??[]).map((e,t)=>({id:String(t),x:e.x,y:e.y,cursor:`ew-resize`})),moveHandle:(e,t,n)=>e.map((e,r)=>String(r)===t?{...e,time:n.time}:e),axisMarks:([e,t])=>({prices:[],times:[e.time,t.time]}),bounds:e=>{let t=Np(e),n=t?.lines.at(-1)?.line;return t&&n?N([...t.lines.flatMap(({line:e})=>e),{x:n[0].x+e.measureText(z(t.fit.pearson)),y:n[0].y+4+e.style.fontSize}]):null},levels:([e,t],n,r,{bars:i})=>{let a=jp(i,e.time,t.time,r.source),[o,...s]=Mp(r);return[o,s.pop(),...s].filter(e=>e!==void 0).map(n=>{let o=z(n.value);if(!a)return{key:o,from:e,to:t,valueAt:()=>NaN};let s=e=>({time:i.time(e),price:a.start+a.slope*(e-a.first)+n.value*a.deviation});return{key:o,from:s(a.first),to:s(a.last),extend:r.extendRight?`end`:`none`}})}};function Fp(e,t,n){let r=e.lowerBound(t),i=Math.max(0,e.length-r),a=new Float64Array(i),o=new Float64Array(i),s=0,c=0,l=0;for(let t=0;t<i;t+=1){let i=r+t,u=nu(e,i,n),d=e.volume(i);s+=d,c+=u*d,l+=u*u*d;let f=c/s;a[t]=f,o[t]=Math.sqrt(Math.max(0,l/s-f*f))}return{first:r,vwap:a,deviation:o}}let Ip=/* @__PURE__ */ tu(64);function Lp(e,t,n){return Ip(e,`${t}:${n}`,()=>Fp(e,t,n))}function Rp(e){return R(e.levels,e).filter(e=>e.value>0)}function zp(e){let[t]=e.anchors,{bars:n,style:r}=e,i=Lp(n,t.time,r.source);if(i.vwap.length===0)return null;let a=e.timeToX(n.time(i.first)),o=i.vwap.length>1?e.timeToX(n.time(i.first+1))-a:1,s=Math.max(0,Math.floor(-a/o)-1),c=Math.min(i.vwap.length-1,Math.ceil((e.width-a)/o)+1),l=t=>{let n=[];for(let r=s;r<=c;r+=1){let i=e.valueToY(t(r));Number.isFinite(i)&&n.push({x:a+r*o,y:i})}return n},u=e=>i.vwap[e]??NaN,d=e=>i.deviation[e]??NaN;return{vwap:l(u),bands:Rp(r).map(e=>({color:e.color,upper:l(t=>u(t)+e.value*d(t)),lower:l(t=>u(t)-e.value*d(t))}))}}function Bp(e){return[...e.upper,...[...e.lower].reverse()]}let Vp=[bu,xu,Su,Cu,Tu,Eu,Ou,Hu,Yu,ld,Qu,$u,bf,Dp,Op,cp,ud,xf,Sf,Cd,yd,Au,Nu,Pp,pd,hd,tf,Xd,kd,jd,Md,Ef,Of,Hf,Jf,tp,np,{type:`anchored-vwap`,points:1,mainPane:!0,fields:[`color`,`lineWidth`,`lineStyle`,`levels`,`fill`,`source`],defaultStyle:e=>({source:`hlc3`,levels:[{value:1,color:e.up},{value:2,color:e.up,visible:!1},{value:3,color:e.up,visible:!1}]}),paint:e=>{let{ctx:t,geometry:n}=e,r=zp(n);if(r){if(n.style.fill)for(let e of r.bands)I(t,Bp(e),C(e.color,.06));for(let t of r.bands)P(e,e=>{F(e,t.upper,!1),F(e,t.lower,!1)},{color:t.color});P(e,e=>{F(e,r.vwap,!1)})}},hitTest:(e,t,n)=>{let r=zp(e);return r?L(t,[r.vwap,...r.bands.flatMap(e=>[e.upper,e.lower])].flatMap(e=>M(e,!1)),n):null},handles:e=>{let[t]=e.anchors,n=Lp(e.bars,t.time,e.style.source),r=n.vwap[0];return r===void 0?[]:[{id:`0`,x:e.timeToX(e.bars.time(n.first)),y:e.valueToY(r),cursor:`ew-resize`}]},moveHandle:([e],t,n)=>[{...e,time:n.time}],axisMarks:([e])=>({prices:[],times:[e.time]}),bounds:e=>{let t=zp(e);return t&&N([...t.vwap,...t.bands.flatMap(e=>[...e.upper,...e.lower])])},levels:([e],t,n,{bars:r})=>{let i=(t,i)=>{let a=Lp(r,e.time,n.source),o=r.lowerBound(t),s=o-a.first;return o<r.length&&r.time(o)===t&&s>=0&&s<a.vwap.length?i(a,s):NaN},a=(t,n)=>({key:t,from:e,to:e,valueAt:e=>i(e,n)}),o=(e,t)=>e.vwap[t]??NaN,s=(e,t)=>e.deviation[t]??NaN;return[a(`vwap`,o),...Rp(n).flatMap(e=>[a(z(e.value),(t,n)=>o(t,n)+e.value*s(t,n)),a(z(-e.value),(t,n)=>o(t,n)-e.value*s(t,n))])]}},wf,lp,up,cf,Wf,rp,ip,ap,Rd,bd,Id,Mf,Nf],Hp=/* @__PURE__ */ new WeakMap;function Up(e,t){let n=[],r=e.shift(t.high),i=e.shift(t.low);for(let a=0;a<e.length;a+=1){let o=e.value(t.high,a),s=e.value(t.low,a);Number.isNaN(o)||n.push({column:t.high,at:a,bar:a+r,price:o,high:!0}),Number.isNaN(s)||n.push({column:t.low,at:a,bar:a+i,price:s,high:!1})}return r===i?n:n.sort((e,t)=>e.bar-t.bar||Number(t.high)-Number(e.high))}function Wp(e,t,n){let{bars:r}=e,i=0;for(let e=Math.max(0,t+1);e<=Math.min(n,r.length-1);e+=1)i+=r.volume(e);return i}function Gp(e,t,n){let r=n?.price??t.price;return{...t,change:t.price-r,previous:r,volume:Wp(e,n?.bar??-1,t.bar)}}function Kp(e,t){let n=Hp.get(e);if(n?.version===e.version&&n.columns.high===t.high&&n.columns.low===t.low)return n.pivots;let r=[];for(let n of Up(e,t))r.at(-1)?.high===n.high?r[r.length-1]=n:r.push(n);let i=[];for(let t of r)i.push(Gp(e,t,i.at(-1)));return Hp.set(e,{version:e.version,columns:t,pivots:i}),i}function qp(e,t,n){let r=e.length-1,i=e.value(t.own,r);if(!n||Number.isNaN(i))return null;let a=r+e.shift(t.own);return Gp(e,{column:t.own,at:r,bar:a,price:i,high:!n.high},n)}function Jp(e,t,n){let r=0,i=t.length;for(;r<i;){let a=Math.floor((r+i)/2),o=t[a];e.indexOf(o.column,o.at)<n?r=a+1:i=a}return r}var Yp=class{plot;from;to;points;indices;constructor(e,t,n,r,i){this.plot=t,this.from=r,this.to=i;let a=Kp(e,n),o=Math.max(0,Jp(e,a,r)-1),s=Math.min(a.length,Jp(e,a,i+1)+1),c=t.extend&&s===a.length?qp(e,n,a.at(-1)):null;this.points=[...a.slice(o,s),...c?[c]:[]],this.indices=this.points.map(t=>e.indexOf(t.column,t.at))}include(e){this.points.forEach((t,n)=>{this.inView(n)&&b(e,t.price)})}emit(e,t,n,r,i,a,o){let{timeScale:s,seriesTypes:c,options:l}=t,u=r.take(e);u.reset(this.points.length),this.points.forEach((e,t)=>{u.pushValue(s.indexToX(this.indices[t]??NaN),n.valueToY(e.price),e.high)}),o.push({kind:`series`,definition:c.require(`line`),style:i,points:u,valueToY:e=>n.valueToY(e),bars:null,first:this.from,transform:null});let d=this.labels(t,n,a);if(d.length>0){let e=l.font.size-1;o.push({kind:`labels`,labels:d,font:E(e,l.font.family),lineHeight:Math.round(e*1.3)})}}inView(e){let t=this.indices[e]??NaN;return t>=this.from&&t<=this.to}labels(e,t,n){let r=this.plot.labels??{};if(!r.price&&!r.change&&!r.volume)return[];let{theme:i}=e.options;return this.points.flatMap((a,o)=>this.inView(o)?[{x:e.timeScale.indexToX(this.indices[o]??NaN),y:t.valueToY(a.price),text:Xp(a,r,e,n),above:a.high,color:a.high?i.up:i.down}]:[])}};function Xp(e,t,{formatter:n},r){let i=[];if(t.price&&i.push(D(n,e.price,r)),t.change){let a=t.change===`percent`?`${D(n,e.change*100/e.previous,{kind:`decimal`,precision:2})}%`:D(n,e.change,r);i.push(`(${e.change>0?`+`:``}${a})`)}let a=[i.join(` `)];return t.volume&&a.push(D(n,e.volume,{kind:`compact`})),a.filter(e=>e!==``).join(`
|
|
7
|
+
`)}function Zp(e,t,n,r,i){let a=n=>!Number.isNaN(e(n))&&!Number.isNaN(t(n)),o=e=>a(e)&&a(e+1)&&(!n||n(e)===n(e+1)),s=[];for(let n=r;n<=i;n+=1){if(!a(n))continue;let r=n,i=n;for(;o(r-1);)--r;for(;o(i);)i+=1;let c=-1/0,l=1/0;for(let n=r;n<=i;n+=1)c=Math.max(c,e(n)),l=Math.min(l,t(n));s.push({start:r,end:i,high:c,low:l}),n=i}return s}function Qp(e,t){return e.find(({key:e,plot:n})=>n.kind===`candles`&&(e===t.key||n.open===t.key||n.high===t.key||n.low===t.key))||null}function $p(e,t){return e.series.reader(e.outputs.findIndex(e=>e.key===t))}function em(e,t,n){let r=t.plot;return!($p(e,t.key)(n)<$p(e,r.open)(n))}var tm=class{sources;entry;range;format;colors;pool;pane;scale;constructor(e,t,n,r,i,a){this.sources=e,this.entry=t,this.range=n,this.format=r,this.colors=i,this.pool=a,this.pane=t.pane,this.scale=t.scale}reader(e){return this.entry.series.reader(e)}startOf(e){return typeof e==`number`?()=>e:this.reader(this.entry.outputs.findIndex(t=>t.key===e))}valueTexts(e,t,n,r){let i=this.reader(e),a=cm(t,this.format),o=t.plot.kind===`marker`?t.plot.text:void 0,s=[];for(let e=n;e<=r;e+=1){let t=i(e);s.push(Number.isNaN(t)?``:[o,D(this.sources.formatter,t,a)].filter(Boolean).join(` `))}return s}zigzag(e,t,n,r){let i=e=>this.entry.outputs.findIndex(t=>t.key===e),a={own:e,high:i(t.high),low:i(t.low)};return new Yp(this.entry.series,t,a,n,r)}lineStyle(e){let{plot:t}=e,n=t.kind===`line`||t.kind===`zigzag`?t:null;return{color:this.colors.get(e.key)??this.sources.options.theme.text,lineWidth:this.entry.styles[e.key]?.lineWidth??n?.width??1.25,lineStyle:this.entry.styles[e.key]?.lineStyle??n?.style??`solid`}}boxRuns(e,t,n,r){let i=t.group===void 0?null:this.startOf(t.group);return Zp(this.reader(e),this.startOf(t.from),i,n,r)}window(e){let{series:t,outputs:n}=this.entry,r=this.sources.timeScale.logicalRange(),i=n.map((e,n)=>t.reach(n));return{from:Math.max(Math.floor(r.from+.5)-e,-Math.max(0,...i.map(e=>e.before))),to:Math.min(Math.ceil(r.to-.5)+e,this.sources.bars.length-1+Math.max(0,...i.map(e=>e.after)))}}include(e,t){let{outputs:n,definition:r,styles:i}=this.entry,{from:a,to:o}=this.window(0);n.forEach((n,r)=>{let{plot:s}=n;if(!om(this.entry,n)||!t&&(i[n.key]?.autoscale??n.autoscale)===!1)return;if(s.kind===`zigzag`){this.zigzag(r,s,a,o).include(e);return}let c=this.reader(r),l=s.kind===`columns`?this.startOf(s.from):null,u=s.kind===`candles`?[s.open,s.high,s.low].map(e=>$p(this.entry,e)):[];for(let t=a;t<=o;t+=1){let n=c(t);b(e,n),l&&!Number.isNaN(n)&&b(e,l(t)),Number.isNaN(n)||u.forEach(n=>{b(e,n(t))})}if(n.plot.kind===`histogram`)b(e,0);else if(n.plot.kind===`box`)for(let t of this.boxRuns(r,n.plot,a,o))b(e,t.high),b(e,t.low)}),r.range&&(b(e,r.range.min),b(e,r.range.max))}firstValue(){let e=this.reader(0),{to:t}=this.window(0);for(let n=this.range.from;n<=t;n+=1){let t=e(n);if(Number.isFinite(t))return t}return null}candles(e,t,n,r,i,a){let{timeScale:o}=this.sources,s=this.reader(t),[c,l,u]=[n.open,n.high,n.low].map(e=>$p(this.entry,e));for(let t=i;t<=a;t+=1){let n=[c(t),l(t),u(t),s(t)];if(n.every(e=>!Number.isNaN(e))){let[i,a,s,c]=n;e.pushOhlc(o.indexToX(t),r.valueToY(i),r.valueToY(a),r.valueToY(s),r.valueToY(c),NaN,c>=i)}}}latest(){let{entry:e}=this;if(!e.lastValueLabel)return[];let t=this.sources.bars.length-1,{theme:n}=this.sources.options;return e.outputs.flatMap((r,i)=>{let{kind:a}=r.plot,o=e.series.drawn(i,t);return!om(e,r)||a!==`line`&&a!==`segments`&&a!==`histogram`||!Number.isFinite(o)?[]:[{value:o,color:am(e,r,i,t,this.colors,n)}]})}emit(e,t){let{outputs:n,fills:r,definition:i,params:a,id:o,series:s}=this.entry,{timeScale:c,options:l,seriesTypes:u}=this.sources,d=l.theme,{from:f,to:p}=this.window(1),m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Map,g=new Set(r.flatMap(e=>[e.from,e.to]));n.forEach((t,n)=>{let{plot:r}=t,i=r.kind===`hidden`&&g.has(t.key)&&this.entry.styles[t.key]?.visible!==!1;if(!om(this.entry,t)&&!i||r.kind===`zigzag`)return;let a=this.pool.take(`indicator:${o}:${t.key}`);if(a.reset(p-f+1),r.kind===`candles`){this.candles(a,n,r,e,f,p),m.set(t.key,a);return}if(r.kind===`columns`){let n=this.startOf(r.from),i=this.pool.take(`indicator:${o}:${t.key}:from`);i.reset(p-f+1);for(let t=f;t<=p;t+=1)i.pushValue(c.indexToX(t),e.valueToY(n(t)),!0);h.set(t.key,i)}let l=this.reader(n),u=s.reader(n,1),d=e=>s.rises(e),_=r.kind===`marker`;for(let t=f;t<=p;t+=1){let n=_&&!s.opens(t)?NaN:l(t),i=r.kind===`histogram`?im(r.colorBy,l,u,d,t):!(n<l(t-1));a.pushValue(c.indexToX(t),e.valueToY(n),i)}m.set(t.key,a)}),r.forEach(r=>{let i=m.get(r.from),a=m.get(r.to);if(i&&a){let o=r.colorBy===`higher`?.14:.08,s=e=>C(this.colors.get(e)??d.textMuted,o),c=s(r.from),l=r.colorBy===`higher`?s(r.to):c,u=e=>n.find(t=>t.key===e)?.plot.kind===`segments`;t.push({kind:`fill`,above:e.inverted?l:c,below:e.inverted?c:l,from:i,to:a,steps:u(r.from)&&u(r.to)})}}),(this.entry.levels??i.levels?.(a)??[]).forEach(n=>{let r=e.valueToY(n);Number.isFinite(r)&&t.push({kind:`reference`,y:r,color:C(d.textMuted,.6)})}),n.forEach((n,r)=>{let{plot:i}=n;if(i.kind===`zigzag`&&om(this.entry,n)){this.zigzag(r,i,f,p).emit(`indicator:${o}:${n.key}`,this.sources,e,this.pool,this.lineStyle(n),cm(n,this.format),t);return}let a=m.get(n.key);if(a){if(n.plot.kind===`box`){let i=c.barSpacing;t.push({kind:`boxes`,boxes:this.boxRuns(r,n.plot,f,p).map(t=>{let n=e.valueToY(t.high),r=e.valueToY(t.low);return{x:c.indexToX(t.start)-i/2,y:Math.min(n,r),width:(t.end-t.start+1)*i,height:Math.abs(r-n)}}),color:this.colors.get(n.key)??d.text})}else if(n.plot.kind===`candles`){let r=this.colors.get(n.key);t.push({kind:`series`,definition:u.require(`candles`),style:Vr(r??d.up,r??d.down),points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null})}else if(n.plot.kind===`histogram`){let r=this.colors.get(n.key),[i,o]=r?[r,r]:nm(n.plot.colorBy,d);t.push({kind:`series`,definition:u.require(`columns`),style:{upColor:i,downColor:o,base:0,widthRatio:.6},points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null})}else n.plot.kind===`line`?t.push({kind:`series`,definition:u.require(`line`),style:this.lineStyle(n),points:a,valueToY:t=>e.valueToY(t),bars:null,first:f,transform:null}):n.plot.kind===`segments`?t.push({kind:`segments`,points:a,color:this.colors.get(n.key)??d.text,lineWidth:this.entry.styles[n.key]?.lineWidth??n.plot.width??1.25,lineStyle:this.entry.styles[n.key]?.lineStyle??n.plot.style??`solid`}):n.plot.kind===`columns`?t.push({kind:`columns`,points:a,from:h.get(n.key)??a,color:this.colors.get(n.key)??d.text,width:n.plot.width??.6,hollow:n.plot.hollow??!1}):n.plot.kind===`marker`&&t.push({kind:`markers`,points:a,color:this.colors.get(n.key)??rm(n.plot,d),shape:n.plot.shape??null,text:n.plot.value?this.valueTexts(r,n,f,p):n.plot.text??``,size:n.plot.size??5,font:E(l.font.size-1,l.font.family)})}})}};function nm(e,t){return e===`bar`?[t.volumeUp,t.volumeDown]:[t.up,t.down]}function rm(e,t){let n=e.kind===`marker`&&e.shape?vr(e.shape):0;return n>0?t.buy:n<0?t.sell:t.text}function im(e,t,n,r,i){switch(e){case`bar`:return r(i);case`sign`:return t(i)>=0;case`change`:return!(t(i)<=n(i))}}function am(e,t,n,r,i,a){let{plot:o}=t,s=Qp(e.outputs,t);if(s)return i.get(s.key)??(em(e,s,r)?a.up:a.down);let c=i.get(t.key);if(c)return c;if(o.kind===`histogram`){let{series:t}=e,[i,s]=nm(o.colorBy,a);return im(o.colorBy,t.reader(n),t.reader(n,1),e=>t.rises(e),r)?i:s}return rm(o,a)}function om(e,t){return t.plot.kind!==`hidden`&&e.styles[t.key]?.visible!==!1}function sm(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=0;for(let{key:t,plot:n}of e.outputs)n.kind===`box`?r.set(n.from,t):n.kind===`candles`&&[n.open,n.high,n.low].forEach(e=>{r.set(e,t)});for(let a of e.outputs){let o=a.color??(a.themeColor&&t[a.themeColor]),{plot:s}=a,c=s.kind===`hidden`&&a.legend===!1,l=s.kind===`marker`&&s.shape&&vr(s.shape)!==0,u=s.kind===`histogram`||s.kind===`candles`,d=!o&&!u&&!c&&!l&&!r.has(a.key)?Tn(t.palette,i++):void 0,f=e.colors[a.key]??o??d;f&&n.set(a.key,f)}return r.forEach((e,t)=>{let r=n.get(e);r&&!n.has(t)&&n.set(t,r)}),n}function cm(e,t){return e.precision===void 0?t:{kind:`decimal`,precision:e.precision}}function lm(e,t){let n=e.definition.precision;return n===`price`?e.upstream?lm(e.upstream,t):t:n===`volume`?{kind:`compact`}:{kind:`decimal`,precision:n}}function um(e){return(t,n,r,i)=>e.list().flatMap(e=>e.visible?(e.series.sync(),[new tm(t,e,n,lm(e,r),sm(e,t.options.theme),i)]):[])}let dm=[`line`,`segments`,`box`,`histogram`,`columns`,`candles`,`marker`,`zigzag`,`hidden`];function fm(e,t){typeof e[t]!=`function`&&n(`definition.${t} must be a function.`)}function pm(e){h(`indicator definition`,e),p(`definition.type`,e.type);let t=`create`in e,r=`compute`in e&&`lookback`in e;!t&&!r&&n(`An indicator definition needs create(), or lookback() and compute().`),(t?[`create`]:[`lookback`,`compute`]).forEach(t=>{fm(e,t)}),p(`definition.name`,e.name),m(`definition.pane`,e.pane,[`main`,`new`]),h(`definition.params`,e.params);for(let[t,n]of Object.entries(e.params))n.legend!==void 0&&f(`definition.params.${t}.legend`,n.legend);typeof e.precision==`string`?m(`definition.precision`,e.precision,[`price`,`volume`]):d(`definition.precision`,e.precision,{min:0,max:12,integer:!0}),typeof e.outputs!=`function`&&n(`An indicator definition needs an outputs() function.`),e.source!==void 0&&m(`definition.source`,e.source,Xt);for(let t of[`levels`,`fills`])e[t]!==void 0&&typeof e[t]!=`function`&&n(`definition.${t} must be a function of the parameters.`);e.range!==void 0&&(h(`definition.range`,e.range),d(`definition.range.min`,e.range.min),d(`definition.range.max`,e.range.max))}function mm(e,t,r){v(`definition.fills of "${r}"`,e);let i=new Set(t.map(e=>e.key));e.forEach((e,t)=>{let a=`definition.fills[${t}]`;h(a,e),(!i.has(e.from)||!i.has(e.to))&&n(`${a} of "${r}" shades from "${e.from}" to "${e.to}", which is no output.`),e.colorBy!==void 0&&m(`${a}.colorBy`,e.colorBy,[`from`,`higher`])})}function hm(e,t,r){for(let i of[`high`,`low`])r.has(e[i])||n(`The zigzag of ${t} takes its ${i}s from "${e[i]}", which is no output.`);e.extend!==void 0&&f(`${t}: extend`,e.extend),e.labels!==void 0&&(_(`${t}: labels`,e.labels,[`price`,`change`,`volume`]),e.labels.price!==void 0&&f(`${t}: labels.price`,e.labels.price),e.labels.change!==void 0&&e.labels.change!==null&&m(`${t}: labels.change`,e.labels.change,[`absolute`,`percent`]),e.labels.volume!==void 0&&f(`${t}: labels.volume`,e.labels.volume))}function gm(e,t){v(`outputs of "${t}"`,e);let r=/* @__PURE__ */ new Set;e.forEach((e,i)=>{h(`outputs of "${t}"[${i}]`,e),p(`outputs of "${t}": key`,e.key),r.has(e.key)&&n(`Indicator "${t}" produces the output key "${e.key}" twice; use distinct parameter values.`),r.add(e.key)});for(let{key:i,plot:a,offset:o,themeColor:s,precision:c,autoscale:l}of e){let e=`output "${i}" of "${t}"`;h(`${e}: plot`,a),m(`${e}: kind`,a.kind,dm),l!==void 0&&f(`${e}: autoscale`,l),o!==void 0&&d(`${e}: offset`,o,{integer:!0}),c!==void 0&&d(`${e}: precision`,c,{min:0,max:12,integer:!0}),s!==void 0&&m(`${e}: themeColor`,s,[`up`,`down`]);let u=a.kind===`line`||a.kind===`segments`||a.kind===`zigzag`;if(u&&a.style!==void 0&&m(`${e}: style`,a.style,ln),u&&a.width!==void 0&&d(`${e}: width`,a.width,{min:.5,max:10}),a.kind===`zigzag`&&hm(a,e,r),a.kind===`histogram`&&m(`${e}: colorBy`,a.colorBy,[`sign`,`change`,`bar`]),a.kind===`box`&&!r.has(a.from)&&n(`The boxes of ${e} reach down to "${a.from}", which is no output.`),a.kind===`box`&&a.group!==void 0&&!r.has(a.group)&&n(`The boxes of ${e} are told apart by "${a.group}", which is no output.`),a.kind===`candles`)for(let t of[`open`,`high`,`low`])r.has(a[t])||n(`The candles of ${e} take their ${t} from "${a[t]}", which is no output.`);a.kind===`columns`?(typeof a.from==`number`?d(`${e}: from`,a.from):r.has(a.from)||n(`The columns of ${e} start at "${a.from}", which is no output.`),a.width!==void 0&&d(`${e}: width`,a.width,{min:0,max:1,exclusiveMin:!0})):a.kind===`marker`&&(a.value!==void 0&&f(`${e}: value`,a.value),a.shape===void 0&&a.text===void 0&&a.value!==!0&&n(`The marker of ${e} needs a shape, a text or the value.`),a.shape!==void 0&&m(`${e}: shape`,a.shape,_r),a.size!==void 0&&d(`${e}: size`,a.size,{min:1,max:40}))}}function _m(e,t,r){let{store:i}=t;return{set:n=>{e.run(()=>{t.set(n)})},add:n=>e.run(()=>t.add(n)),update:(n,r)=>{e.run(()=>{t.update(n,r)})},remove:n=>{e.run(()=>{t.remove(n)})},clear:()=>{e.run(()=>{t.set([])})},get:e=>{let t=i.get(e);return t?i.info(t):null},list:()=>i.list().map(e=>i.info(e)),valuesAt:(t,n=e.bars.length-1)=>{let a=i.require(t);a.series.sync();let o=e.frame(),s=sm(a,e.options.theme),c=lm(a,o.priceFormat);return a.outputs.map((t,i)=>{let o=a.series.drawn(i,n);return{key:t.key,label:r().label(t.label),color:am(a,t,i,n,s,e.options.theme),value:Number.isNaN(o)?null:o,text:D(e.formatter,o,cm(t,c))}})},refresh:(t,n)=>{e.run(()=>{let r=i.require(t),a=n===void 0?-1/0:d(`refresh() from`,n);r.series.refresh(a)&&e.values.reset(),e.invalidate()})},register:t=>{e.run(()=>{pm(t),i.registry.register(t),e.bus.emit(`typesChange`,{kind:`indicator`,type:t.type,registered:!0})})},unregister:t=>{e.run(()=>{i.registry.require(t);let r=i.list().filter(e=>e.type===t);r.length>0&&n(`The indicators ${r.map(e=>`"${e.id}"`).join(`, `)} are of type "${t}"; remove them first.`),i.registry.unregister(t),e.bus.emit(`typesChange`,{kind:`indicator`,type:t,registered:!1})})},types:()=>i.registry.types(),definition:e=>i.registry.get(e)??null,title:e=>r().title(e),label:e=>r().label(p(`text`,e))}}var vm=class{bars;context;constructor(e,t){this.bars=e,this.context=t}barAt(e){return e}indexOf(e){return e}reach(e){return{before:Math.max(0,-e),after:Math.max(0,e)}}},ym=class{market;displayed;frame;feed;decision=null;bucketed=null;sourceRevision=-1;started=/* @__PURE__ */ new Int32Array;matched=/* @__PURE__ */ new Float64Array;matchedCount=0;displayedRevision=-1;barsRevision=-1;constructor(e,t,n){this.market=e,this.displayed=t,this.frame=n,this.feed=_t(e.feed.source,st)}get bars(){return this.feed.display}context(){return{calendar:this.market.tradingCalendar(),interval:this.frame}}update(){let e=this.source();return e!==null&&(this.follow(e),this.match(),!0)}barAt(e){let t=this.displayed.length-1;return e>=t?this.bars.length-1+Math.ceil((e-t)/this.ratio()):e>=0?(this.started[e]??0)-2:this.barAt(0)-Math.ceil(-e/this.ratio())}indexOf(e){let t=-1,n=Math.max(1,this.displayed.length);for(;this.barAt(t)>=e;)t*=2;for(;this.barAt(n)<e;)n*=2;for(;n-t>1;){let r=Math.floor((t+n)/2);this.barAt(r)<e?t=r:n=r}return n}reach(e){let t=this.ratio();return{before:Math.max(0,(this.barAt(0)-e)*t),after:Math.max(0,e*t)}}ratio(){return Math.max(1,Math.round(this.displayed.length/Math.max(1,this.bars.length)))}source(){let{market:e,frame:t}=this,n=e.sourceInterval(),r=e.timeframe()??n,i=e.timeBased(),a=this.decision;return(a?.source!==n||a.shown!==r||a.timed!==i)&&(this.decision={source:n,shown:r,timed:i,applies:n!==null&&r!==null&&i&&Na(r)<Na(t)&&Ra(t,n)}),this.decision?.applies?n:null}follow(e){let{market:t,feed:n}=this,r=t.tradingCalendar(),i=t.feed.source;if(this.bucketed?.calendar!==r||!Fa(this.bucketed.source,e))n.planRebucket(t.bucketerOf(e,this.frame))(),this.bucketed={calendar:r,source:e};else{let e=i.changesSince(this.sourceRevision);e&&n.follow(e)}this.sourceRevision=i.revision,n.setCutoff(t.feed.cutoffTime())}match(){let{displayed:e,bars:t}=this,n=e.changesSince(this.displayedRevision),r=t.changesSince(this.barsRevision),i=e.length;if(n&&(i=n.kind===`reset`?0:Math.max(0,n.from-1)),r){let t=r.kind===`reset`?0:r.from,n=r.kind===`reset`?-1/0:this.firstMove(t);this.keepTimes(t),n!==1/0&&(i=Math.min(i,Math.max(0,e.lowerBound(n)-1)))}this.displayedRevision=e.revision,this.barsRevision=t.revision,this.count(i)}firstMove(e){let{bars:t,matched:n,matchedCount:r}=this,i=Math.max(t.length,r);for(let a=e;a<i;a+=1){let e=a<r?n[a]??NaN:1/0,i=a<t.length?t.time(a):1/0;if(e!==i)return Math.min(e,i)}return 1/0}keepTimes(e){let{bars:t}=this;if(this.matched.length<t.length){let n=new Float64Array(Math.max(64,t.length,this.matched.length*2));n.set(this.matched.subarray(0,Math.min(e,this.matchedCount))),this.matched=n}for(let n=e;n<t.length;n+=1)this.matched[n]=t.time(n);this.matchedCount=t.length}count(e){let{displayed:t,bars:n}=this,r=t.length-1;if(this.started.length<r){let t=new Int32Array(Math.max(64,r,this.started.length*2));t.set(this.started.subarray(0,e)),this.started=t}let i=e>0?this.started[e-1]??0:0;for(let a=e;a<r;a+=1){let e=t.time(a+1);for(;i<n.length&&n.time(i)<=e;)i+=1;this.started[a]=i}}},bm=class{market;displayed;timeframes=/* @__PURE__ */ new Map;constructor(e,t){this.market=e,this.displayed=new vm(t,()=>({calendar:e.tradingCalendar(),interval:e.timeframe()??e.sourceInterval()}))}of(e){if(e===null)return()=>this.displayed;let t=j(e),n=this.timeframes.get(t)??new ym(this.market,this.displayed.bars,e);return this.timeframes.set(t,n),()=>n.update()?n:this.displayed}keep(e){let t=new Set(e.flatMap(e=>e?[j(e)]:[]));for(let e of[...this.timeframes.keys()])t.has(e)||this.timeframes.delete(e)}};function xm(e,t){return t===void 0?0:e.outputs.findIndex(e=>e.key===t)}function Sm(e,t,r){xm(e.get(t.id)??n(`${r}: unknown indicator "${t.id}".`),t.key)<0&&n(`${r}: indicator "${t.id}" has no output "${String(t.key)}".`)}function Cm(e){return{check:(t,n)=>{Sm(e,t,n)},read:(t,n)=>{let r=e.require(t.id);return r.series.sync(),r.series.drawn(xm(r,t.key),n)},paneOf:t=>e.require(t.id).pane,scaleOf:t=>e.require(t.id).scale}}let wm={time:0,open:0,high:0,low:0,close:0,volume:0};var Tm=class e{capacity;compute;columns;start=0;size=0;empty;constructor(e,t,n,r=Array.from({length:7},()=>new Float64Array(e))){this.capacity=e,this.compute=n,this.columns=r,this.empty=new Float64Array(t).fill(NaN)}get length(){return this.size}bar(e){let t=(this.start+e)%this.capacity,n=e=>this.columns[e]?.[t]??NaN;return{time:n(0),open:n(1),high:n(2),low:n(3),close:n(4),volume:n(5)}}price(e){return this.columns[6]?.[(this.start+e)%this.capacity]??NaN}next(e,t){let n=this.size<this.capacity?(this.start+this.size)%this.capacity:this.start,r=[e.time,e.open,e.high,e.low,e.close,e.volume,t];return this.columns.forEach((e,t)=>{e[n]=r[t]??NaN}),this.size<this.capacity?this.size+=1:this.start=(this.start+1)%this.capacity,this.size===this.capacity?this.compute(this):this.empty}clone(){let t=new e(this.capacity,this.empty.length,this.compute,this.columns.map(e=>e.slice()));return t.start=this.start,t.size=this.size,t}};function Em(e,t,n,r){return`create`in e?e.create(t,r):new Tm(e.lookback(t),n,n=>e.compute(n,t,r))}function Dm(e,t,r){let i={};t!==void 0&&h(`params`,t);for(let i of Object.keys(t??{}))Object.hasOwn(e.params,i)||n(`Indicator "${r}" has no parameter "${i}".`);for(let[a,o]of Object.entries(e.params)){let e=t?.[a]===void 0?o.default:t[a],s={...o.min===void 0?{}:{min:o.min},...o.max===void 0?{}:{max:o.max},...o.integer?{integer:!0}:{}},c=(e,t)=>{let r=d(e,t,s);return o.options&&!o.options.some(e=>e.value===r)&&n(`${e} must be one of ${o.options.map(e=>`${e.value} (${e.label})`).join(`, `)}, received ${r}.`),r};if(Array.isArray(o.default)){let t=o.default.length===0?0:1;(!Array.isArray(e)||e.length<t||e.length>8)&&n(`Parameter "${a}" of indicator "${r}" must be a list of ${String(t)} to 8 numbers.`),e.forEach((e,t)=>{c(`params.${a}[${t}]`,e)}),i[a]=[...e]}else i[a]=c(`params.${a}`,e)}return i}function Om(e,t){return t!==null&&e.calendar===t.calendar&&Fa(e.interval,t.interval)}var km=class{definition;params;outputs;source;basis;columns;stream=null;checkpoint=null;computedCount=0;revision=-1;scratch={...wm};rebuilds=0;changes=0;resumes=0;upstreamSeen=null;refreshFrom=null;contextSeen=null;current;constructor(e,t,n,r,i){this.definition=e,this.params=t,this.outputs=n,this.source=r,this.basis=i,this.columns=n.map(()=>/* @__PURE__ */ new Float64Array),this.current=typeof r==`function`?r().series.current:i()}sync(){let e=typeof this.source==`function`?this.source():null;e?.series.sync();let t=e?e.series.current:this.basis(),n=t.context(),r=t!==this.current||!Om(n,this.contextSeen)||e!==null&&(e.series!==this.upstreamSeen?.series||e.series.rebuilds!==this.upstreamSeen.rebuilds),i=t.bars,a=r?{kind:`reset`}:this.refreshed(i,e,i.changesSince(this.revision));if(this.current=t,this.contextSeen=n,this.refreshFrom=null,e&&(this.upstreamSeen={series:e.series,rebuilds:e.series.rebuilds,resumes:e.series.resumes}),!a)return;let o=i.length;this.ensureCapacity(o),a.kind===`reset`||!this.checkpoint||a.from<this.computedCount-1?(this.stream=Em(this.definition,this.params,this.outputs.length,n),this.rebuilds+=1,this.run(i,0,o,e)):(this.stream=this.checkpoint.clone(),this.resumes+=1,this.run(i,this.computedCount-1,o,e)),this.computedCount=o,this.revision=i.revision,this.changes+=1}get version(){return this.changes}get length(){return this.computedCount}get bars(){return this.current.bars}indexOf(e,t){return this.current.indexOf(t+this.shift(e))}refresh(e){this.refreshFrom=Math.min(this.refreshFrom??1/0,e);let{bars:t}=this.current;return t.lowerBound(e+1)-1<this.computedCount-1}refreshed(e,t,n){let r=[];return this.refreshFrom!==null&&r.push(Math.max(0,e.lowerBound(this.refreshFrom+1)-1)),t&&t.series.resumes!==this.upstreamSeen?.resumes&&r.push(Math.max(0,this.computedCount-1)),r.length===0||n?.kind===`reset`?n:{kind:`tail`,from:Math.min(n?.from??1/0,...r)}}value(e,t){return t<this.computedCount?this.columns[e]?.[t]??NaN:NaN}shift(e){let t=typeof this.source==`function`?this.source():null,n=this.outputs[e]?.offset??0;return t?n+t.series.shift(t.column):n}reader(e,t=0){let n=this.shift(e)+t,r=this.current;return t=>this.value(e,r.barAt(t)-n)}drawn(e,t){return this.reader(e)(t)}reach(e){return this.current.reach(this.shift(e))}opens(e){return this.current.barAt(e)!==this.current.barAt(e-1)}rises(e){let{bars:t}=this.current,n=this.current.barAt(e);return n>=0&&n<t.length&&t.close(n)>=t.open(n)}run(e,t,n,r){let i=this.stream;if(i){for(let a=t;a<n;a+=1){a===n-1&&(this.checkpoint=i.clone());let t=this.readBar(e,a),o;if(r){if(o=r.series.value(r.column,a),Number.isNaN(o)){this.columns.forEach(e=>{e[a]=NaN});continue}t.open=o,t.high=o,t.low=o,t.close=o}else o=e.price(a,this.source);let s=i.next(t,o);for(let e=0;e<this.columns.length;e+=1){let t=this.columns[e];t&&(t[a]=s[e]??NaN)}}t>=n&&(this.checkpoint=null)}}readBar(e,t){let n=this.scratch;return n.time=e.time(t),n.open=e.open(t),n.high=e.high(t),n.low=e.low(t),n.close=e.close(t),n.volume=e.volume(t),n}ensureCapacity(e){let t=this.columns[0]?.length??0;if(t>=e)return;let n=Math.max(64,e,t*2);this.columns=this.columns.map(t=>{let r=new Float64Array(n).fill(NaN);return r.set(t.subarray(0,Math.min(t.length,e))),r})}};let Am=g({id:!0,type:!0,params:!0,pane:!0,scale:!0,source:!0,timeframe:!0,visible:!0,lastValueLabel:!0,colors:!0,styles:!0,levels:!0}),jm=g({params:!0,pane:!0,source:!0,timeframe:!0,visible:!0,lastValueLabel:!0,scale:!0,colors:!0,styles:!0,levels:!0}),Mm=g({visible:!0,lineWidth:!0,lineStyle:!0,autoscale:!0}),Nm=g({kind:!0,id:!0,key:!0});function Pm(e){_(`indicator`,e,Am)}function Fm(e){_(`patch`,e,jm)}function Im(e,t){_(e,t,Mm);let{visible:n,lineWidth:r,lineStyle:i,autoscale:a}=t;return{...n===void 0?{}:{visible:f(`${e}.visible`,n)},...a===void 0?{}:{autoscale:f(`${e}.autoscale`,a)},...r===void 0?{}:{lineWidth:d(`${e}.lineWidth`,r,{min:.5,max:10})},...i===void 0?{}:{lineStyle:m(`${e}.lineStyle`,i,ln)}}}function Lm(e,t,r,i,a,o){let s=new Set(i.map(e=>e.key)),c=new Map(Object.entries(t).filter(([e])=>s.has(e)));r!==void 0&&h(`indicator.${a}`,r);for(let[t,i]of Object.entries(r??{}))s.has(t)||n(`Indicator "${e}" has no output "${t}" for ${a}.`),i===null?c.delete(t):c.set(t,o(`${a}.${t}`,i));return Object.fromEntries(c)}function Rm(e){return v(`indicator.levels`,e),e.map((e,t)=>d(`indicator.levels[${String(t)}]`,e))}function zm(e){return typeof e==`string`?m(`indicator.source`,e,Xt):(_(`indicator.source`,e,Nm),m(`indicator.source.kind`,e.kind,[`indicator`]),p(`indicator.source.id`,e.id),e.key!==void 0&&p(`indicator.source.key`,e.key),e)}function Bm(e){return e===null?null:ja(e,`indicator.timeframe`)}function Vm(e,t,n){let r=Dm(e,t,n),i=e.outputs(r);gm(i,n);let a=e.fills?.(r)??[];return mm(a,i,n),e.lookback&&d(`lookback() of "${n}"`,e.lookback(r),{min:1,integer:!0}),{params:r,outputs:i,fills:a}}function Hm(e,t){let{params:n,outputs:r,fills:i}=Vm(e,t.params,t.type);return{params:n,outputs:r,fills:i,visible:t.visible===void 0||f(`indicator.visible`,t.visible),lastValueLabel:t.lastValueLabel!==void 0&&f(`indicator.lastValueLabel`,t.lastValueLabel),colors:Lm(t.type,{},t.colors,r,`colors`,S),styles:Lm(t.type,{},t.styles,r,`styles`,Im),levels:t.levels===void 0?null:Rm(t.levels)}}function Um(e){let t=[],n=e=>{t.includes(e)||(e.upstream&&n(e.upstream),t.push(e))};return e.forEach(n),t}var Wm=class{core;store;constructor(e,t){this.core=e,this.store=t}add(e){let{core:t,store:n}=this,{entry:r,own:i}=this.place(n,e);return i&&n.move(r.id,t.createAutoPane(r.id)),t.invalidate(),r.id}set(e){let{core:t,store:n}=this;v(`indicators`,e);let r=n.staging(e),i=e.flatMap(e=>{let t=this.place(r,e);return t.own?[t.entry.id]:[]});t.values.verify((e,t)=>{e.kind===`indicator`&&Sm(r,e,t)});let a=n.list().map(e=>e.pane);n.adopt(r),a.forEach(e=>{t.releasePane(e)}),i.forEach(e=>{n.move(e,t.createAutoPane(e))}),t.values.reset(),t.invalidate()}place(e,t){Pm(t);let n=t.pane??e.defaultPane(t.type,t.source);n!==`new`&&this.core.panes.require(n);let r=n===`new`;return{entry:r?e.add(t.scale===void 0?{...t,scale:fe}:t,x):e.add(t,n),own:r}}remove(e){this.core.values.assertUnused(`indicator`,e);let t=this.store.remove(e);this.core.releasePane(t.pane),this.core.invalidate()}update(e,t){let{core:r,store:i}=this;Fm(t);let a=i.require(e).pane,o=t.pane===void 0?a:p(`patch.pane`,t.pane);o!==`new`&&r.panes.require(o);let s=o===`new`&&t.scale===void 0?{...t,scale:fe}:t;i.update(e,s,t=>{let i=r.values.uses(`indicator`,e).flatMap(({user:e,noun:n,source:r})=>r.kind===`indicator`&&r.key!==void 0&&!t.includes(r.key)?[`"${r.key}" (read by ${n} "${e}")`]:[]);i.length>0&&n(`Indicator "${e}" would no longer produce ${i.join(`, `)}.`)}),o!==a&&(i.move(e,o===`new`?r.createAutoPane(e):o),r.releasePane(a)),(t.params!==void 0||t.source!==void 0||t.timeframe!==void 0)&&r.values.reset(),r.invalidate()}values(){return Cm(this.store)}state(){let{store:e}=this;return{key:`indicators`,save:()=>Um(e.list()).map(t=>{let n=e.info(t);return{id:n.id,type:n.type,params:n.params,pane:n.pane,scale:n.scale,source:n.source,...n.timeframe===null?{}:{timeframe:n.timeframe},visible:n.visible,...n.lastValueLabel?{lastValueLabel:!0}:{},colors:n.colors,styles:n.styles,...n.levels===null?{}:{levels:n.levels}}}),prepare:(e,t)=>this.prepare(e,t)}}prepare(e,t){let n=e??[];v(`state.indicators`,n);let r=this.store.staging(n);return n.forEach((e,n)=>{h(`state.indicators[${n}]`,e),t.require(e.pane),r.add({id:e.id,type:e.type,params:e.params,source:e.source,...e.timeframe===void 0?{}:{timeframe:e.timeframe},...e.scale===void 0?{}:{scale:e.scale},visible:e.visible,...e.lastValueLabel===void 0?{}:{lastValueLabel:e.lastValueLabel},colors:{...e.colors},...e.styles===void 0?{}:{styles:structuredClone(e.styles)},...e.levels===void 0?{}:{levels:[...e.levels]}},e.pane)}),{values:{kind:`indicator`,check:(e,t)=>{Sm(r,e,t)}},apply:()=>{this.store.adopt(r)}}}};function Gm(e){return e.upstream?Gm(e.upstream):e.timeframe}function Km(e){return e?JSON.stringify(j(e)):`null`}function qm(e,t){return()=>({series:e.series,column:t===void 0?0:e.outputs.findIndex(e=>e.key===t)})}var Jm=class e{bases;registry;entries=/* @__PURE__ */ new Map;ids;constructor(e,t,n){this.bases=e,this.registry=t,this.ids=new de(e=>this.entries.has(e),n)}staging(t){let n=new e(this.bases,this.registry,this.ids);return n.ids.reserve(t),n}list(){return[...this.entries.values()]}get(e){return this.entries.get(e)}require(e){return this.entries.get(e)??n(`Unknown indicator "${e}".`)}info(e){let t=Gm(e);return{id:e.id,type:e.type,params:structuredClone(e.params),pane:e.pane,scale:e.scale,source:typeof e.source==`string`?e.source:{...e.source},timeframe:t?j(t):null,visible:e.visible,lastValueLabel:e.lastValueLabel,colors:{...e.colors},styles:structuredClone(e.styles),levels:e.levels===null?null:[...e.levels]}}defaultPane(e,t){let n=this.registry.require(e).pane;return(typeof t==`object`&&n===`main`?this.entries.get(t.id):void 0)?.pane??n}parseSource(e,t){if(e===void 0)return{source:`close`,upstream:null};let r=zm(e);if(typeof r==`string`)return{source:r,upstream:null};let{id:i,key:a}=r,o=this.entries.get(i)??n(`indicator.source: unknown indicator "${i}".`);a!==void 0&&!o.outputs.some(e=>e.key===a)&&n(`indicator.source: indicator "${i}" has no output "${a}".`);for(let e=o;e;e=e.upstream)e.id===t&&n(`indicator.source: "${i}" reads "${t}", so "${t}" cannot read it.`);return{source:{kind:`indicator`,id:o.id,...a===void 0?{}:{key:a}},upstream:o}}parseTimeframe(e,t,r){let i=e===void 0?void 0:Bm(e);if(!t)return i===void 0?r:i;let a=Gm(t);return i!==void 0&&!Fa(i,a)&&n(`indicator.timeframe must be ${Km(a)}, the timeframe of the indicator "${t.id}" it reads, received ${Km(i)}.`),null}release(){this.bases.keep(this.list().map(e=>e.timeframe))}dependents(e){return this.list().filter(t=>t.upstream?.id===e).map(e=>e.id)}series(e,t,n,r,i,a){return new km(e,t,n,i&&typeof r!=`string`?qm(i,r.key):r,this.bases.of(a))}add(e,t){p(`indicator.type`,e.type);let r=this.registry.require(e.type);e.id!==void 0&&this.entries.has(p(`indicator.id`,e.id))&&n(`An indicator with id "${e.id}" already exists.`);let i=Hm(r,e),{params:a,outputs:o}=i,{source:s,upstream:c}=this.parseSource(e.source??r.source,null),l=this.parseTimeframe(e.timeframe,c,null),u=e.scale===void 0?c&&c.pane===t?c.scale:`right`:p(`indicator.scale`,e.scale),d=e.id??this.ids.next(e.type.toLowerCase()),f={id:d,type:e.type,definition:r,pane:t,scale:u,source:s,upstream:c,timeframe:l,...i,series:this.series(r,a,o,s,c,l)};return this.entries.set(d,f),this.ids.note(d),f}update(e,t,r){let i=this.require(e);t.params!==void 0&&h(`params`,t.params);let{params:a,outputs:o,fills:s}=t.params===void 0?i:Vm(i.definition,{...i.params,...t.params},i.type),{source:c,upstream:l}=t.source===void 0?{source:i.source,upstream:i.upstream}:this.parseSource(t.source,e),u=this.parseTimeframe(t.timeframe,l,Gm(i)),d=o.map(e=>e.key);for(let t of this.list())t.upstream===i&&typeof t.source!=`string`&&t.source.key!==void 0&&!d.includes(t.source.key)&&n(`Indicator "${e}" would no longer produce "${t.source.key}", which indicator "${t.id}" reads.`);r(d);let m=Lm(i.type,i.colors,t.colors,o,`colors`,S),g=Lm(i.type,i.styles,t.styles,o,`styles`,Im),_=t.levels===void 0?i.levels:t.levels===null?null:Rm(t.levels),v=t.visible===void 0?i.visible:f(`indicator.visible`,t.visible),ee=t.lastValueLabel===void 0?i.lastValueLabel:f(`indicator.lastValueLabel`,t.lastValueLabel),y=t.scale===void 0?i.scale:p(`indicator.scale`,t.scale);(t.params!==void 0||t.source!==void 0||t.timeframe!==void 0)&&(i.series=this.series(i.definition,a,o,c,l,u)),i.params=a,i.source=c,i.upstream=l,i.timeframe=u,i.outputs=o,i.fills=s,i.colors=m,i.styles=g,i.levels=_,i.visible=v,i.lastValueLabel=ee,i.scale=y,this.release()}move(e,t){this.require(e).pane=t}remove(e){let t=this.require(e),r=this.dependents(e);return r.length>0&&n(`Indicator "${e}" is read by the indicators ${r.map(e=>`"${e}"`).join(`, `)}; remove them first.`),this.entries.delete(e),this.release(),t}adopt(e){this.entries.clear(),e.entries.forEach((e,t)=>{this.entries.set(t,e),this.ids.note(t)}),this.release()}};function Ym({definition:e,params:t},n){return Object.entries(t).flatMap(([t,r])=>{let i=e.params[t];return i?.legend===!1?[]:(typeof r==`number`?[r]:[...r]).map(e=>{let t=i?.options?.find(t=>t.value===e);return t?n.label(t.label):e})}).join(` `)}function Xm(e,t){let n=e.upstream;if(!n||typeof e.source==`string`)return``;let r=e.source.key===void 0?``:` ${e.source.key}`;return` · ${t.label(n.definition.name)}${r}`}function Zm(e,t,n,r){return(i,a)=>e.list().map(e=>({item:{kind:`indicator`,id:e.id,type:e.type,paneId:e.pane,visible:e.visible},segments:()=>{let{theme:o}=t();e.series.sync();let s=sm(e,o),c=lm(e,i.priceFormat),l=r(),u=l.label(e.definition.name),d=Gm(e),f=[{text:`${[u,Ym(e,l),d?j(d):``].filter(e=>e!==``).join(` `)}${Xm(e,l)}`,color:o.textMuted}],p=e.outputs.filter(e=>e.legend!==!1).length>1;return e.outputs.forEach((t,r)=>{if(t.legend===!1||e.styles[t.key]?.visible===!1)return;let i=e.series.drawn(r,a),u=D(n(),i,cm(t,c));f.push({text:p?`${l.label(t.label)} ${u}`:u,color:am(e,t,r,a,s,o)})}),f}}))}let Qm=[`names`,`labels`];function $m(e,t){if(t!==void 0){h(e,t);for(let[n,r]of Object.entries(t))p(`${e}.${JSON.stringify(n)}`,r)}}function eh(e,t){v(e,t),t.forEach((t,n)=>{h(`${e}[${n}]`,t);let r=Object.entries(t);for(let[t,i]of r){let r=`${e}[${n}].${t}`;_(r,i,Qm),$m(`${r}.names`,i.names),$m(`${r}.labels`,i.labels)}})}function th(e,t,n){return new Map(e.flatMap(e=>Object.entries(e[t]?.[n]??{})))}function nh(e,t){let n=new Intl.NumberFormat(t??void 0).resolvedOptions().locale.split(`-`)[0],r=th(e,n??`en`,`labels`),i=th(e,n??`en`,`names`),a=th(e,`en`,`names`);return{label:e=>{let t=r.get(e);if(t!==void 0)return t;let n=/\d+$/.exec(e)?.[0],i=n===void 0?void 0:r.get(`${e.slice(0,-n.length)}{n}`);return i===void 0||n===void 0?e:i.replace(`{n}`,n)},title:e=>i.get(e)??a.get(e)??null}}function rh(e=[],t={}){v(`indicators()`,e);let r=/* @__PURE__ */ new Set;e.forEach(e=>{pm(e),r.has(e.type)&&n(`indicators() is given the indicator type "${e.type}" twice.`),r.add(e.type)}),_(`indicators() options`,t,[`texts`]);let i=t.texts??[];return eh(`indicators() texts`,i),_o({name:`indicators`,install:t=>{let n=new Rr(`indicator type`,[],`Give it to the indicators module, or register it with chart.indicators.register().`);e.forEach(e=>{n.register(e)});let r=new Jm(new bm(t.market,t.bars),n),a=new Wm(t,r),o=null,s=()=>{let{locale:e}=t.options;return o?.locale!==e&&(o={locale:e,words:nh(i,e)}),o.words};return t.contributors.push(um(r)),t.legendRows.push(Zm(r,()=>t.options,()=>t.formatter,s)),t.values.provide(`indicator`,a.values()),t.paneOccupants.push({occupants:e=>r.list().filter(t=>t.pane===e).map(e=>e.id),removed:()=>void 0}),t.stateParts.push(a.state()),{indicators:_m(t,a,s)}}})}var V=class e{capacity;values;start=0;size=0;constructor(e){this.capacity=e,this.values=new Float64Array(d(`capacity`,e,{min:1,integer:!0}))}get length(){return this.size}get full(){return this.size===this.capacity}push(e){if(this.size<this.capacity)return this.values[(this.start+this.size)%this.capacity]=e,this.size+=1,NaN;let t=this.values[this.start]??NaN;return this.values[this.start]=e,this.start=(this.start+1)%this.capacity,t}at(e){return this.values[(this.start+e)%this.capacity]??NaN}fromEnd(e){return e<this.size?this.at(this.size-1-e):NaN}max(){let e=-1/0;for(let t=0;t<this.size;t+=1)e=Math.max(e,this.at(t));return e}min(){let e=1/0;for(let t=0;t<this.size;t+=1)e=Math.min(e,this.at(t));return e}sum(){let e=0;for(let t=0;t<this.size;t+=1)e+=this.at(t);return e}clone(){let t=new e(this.capacity);return t.values.set(this.values),t.start=this.start,t.size=this.size,t}},ih=class e{period;sum;constructor(e,t=new W(e)){this.period=e,this.sum=t}next(e){return this.sum.next(e)/this.period}clone(){return new e(this.period,this.sum.clone())}},H=class e{period;window;sum;value;constructor(e,t=new V(e),n=0,r=NaN){this.period=e,this.window=t,this.sum=n,this.value=r}next(e){if(Number.isNaN(e))return this.value;let t=this.window.push(e);return this.sum+=e-(Number.isNaN(t)?0:t),this.value=this.window.full?this.sum/this.period:NaN,this.value}clone(){return new e(this.period,this.window.clone(),this.sum,this.value)}},ah=class e{period;window;value=NaN;constructor(e){this.period=e,this.window=new V(d(`period`,e,{min:1,integer:!0}))}next(e){if(Number.isNaN(e))return this.value;if(this.window.push(e),!this.window.full)return NaN;let t=this.window.sum()/this.period,n=0;for(let e=0;e<this.period;e+=1)n+=(this.window.at(e)-t)**2;return this.value=Math.sqrt(n/this.period),this.value}clone(){let t=new e(this.period);return t.window=this.window.clone(),t.value=this.value,t}},oh=class e{period;weight;value;constructor(e,t,n=NaN){this.period=e,this.weight=t,this.value=n}next(e){return Number.isNaN(e)||(this.value=Number.isNaN(this.value)?e:(this.weight*e+(this.period-this.weight)*this.value)/this.period),this.value}clone(){return new e(this.period,this.weight,this.value)}},U=class e{period;alpha;count;value;constructor(e,t,n=0,r=0){this.period=e,this.alpha=t,this.count=n,this.value=r}static ema(t){return new e(t,2/(t+1))}static rma(t){return new e(t,1/t)}next(e){return Number.isNaN(e)?this.count===this.period?this.value:NaN:this.count===this.period?(this.value=this.alpha*e+(1-this.alpha)*this.value,this.value):(this.count+=1,this.value+=e,this.count<this.period?NaN:(this.value/=this.period,this.value))}clone(){return new e(this.period,this.alpha,this.count,this.value)}},sh=class e{period;window;sum;weighted;constructor(e,t=new V(e),n=0,r=0){this.period=e,this.window=t,this.sum=n,this.weighted=r}next(e){if(Number.isNaN(e))return this.window.full?this.average():NaN;let t=this.window.length,n=this.window.push(e);return t<this.period?(this.weighted+=(t+1)*e,this.sum+=e):(this.weighted+=this.period*e-this.sum,this.sum+=e-n),this.window.full?this.average():NaN}average(){return this.weighted/(this.period*(this.period+1)/2)}clone(){return new e(this.period,this.window.clone(),this.sum,this.weighted)}},W=class e{window;sum;constructor(e,t=new V(e),n=0){this.window=t,this.sum=n}next(e){let t=this.window.push(e);return this.sum=Number.isNaN(this.sum)?this.window.sum():this.sum+(e-(Number.isNaN(t)?0:t)),this.window.full?this.sum:NaN}clone(){return new e(this.window.capacity,this.window.clone(),this.sum)}},G=class e{highs;lows;constructor(e){this.highs=new V(d(`period`,e,{min:1,integer:!0})),this.lows=new V(e)}push(e,t){this.highs.push(e),this.lows.push(t)}highest(){return this.highs.full?this.highs.max():NaN}lowest(){return this.lows.full?this.lows.min():NaN}clone(){let t=new e(this.highs.capacity);return t.highs=this.highs.clone(),t.lows=this.lows.clone(),t}},K=class e{last=NaN;next(e){let t=this.last;return this.last=e,t}clone(){let t=new e;return t.last=this.last,t}};let ch={next:e=>e,clone:()=>ch};var q=class e{steps;input;out;constructor(e,t){this.steps=e,this.input=t,this.out=new Float64Array(e.length)}next(e,t){let n=this.input(e,t);return this.steps.forEach((t,r)=>{this.out[r]=t.next(n,e)}),this.out}clone(){return new e(this.steps.map(e=>e.clone()),this.input)}},lh=class e{step;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t){this.step=e,this.average=t}next(e,t){let n=this.step.next(t);return this.out[0]=n,this.out[1]=this.average.next(n),this.out}clone(){return new e(this.step.clone(),this.average.clone())}};function J(e){return{key:e.toLowerCase(),label:e,plot:{kind:`line`}}}function Y(e,t){return{key:e,label:t,plot:{kind:`line`}}}function uh(e,t){return t.map(t=>J(`${e}${t}`))}function X(e,t=`Period`){return{default:e,min:1,max:2e3,integer:!0,label:t}}function dh(e,t=`Periods`){return{default:e,min:1,max:2e3,integer:!0,label:t}}function fh(e){return e.map((e,t)=>({value:t,label:e}))}function Z(e,t,n,r=!0){return{default:t,label:n,options:fh(e),...r?{}:{legend:!1}}}function Q(e,t,r){return(!Number.isInteger(t)||t<0||t>=e.length)&&n(`There is no ${r} ${String(t)}.`),e[t]}function ph(e,t,n=!0){return Z([`Off`,`On`],+!!e,t,n)}function $(e,t){return t===0?NaN:e/t}let mh=[`sma`,`ema`,`rma`,`wma`,`vwma`];var hh=class e{average;constructor(e){this.average=e}next(e){return this.average.next(e)}clone(){return new e(this.average.clone())}},gh=class e{flow;volume;value;constructor(e,t,n=NaN){this.flow=e,this.volume=t,this.value=n}static of(t){return new e(new W(t),new W(t))}next(e,t){return Number.isNaN(e)||(this.value=$(this.flow.next(e*t.volume),this.volume.next(t.volume))),this.value}clone(){return new e(this.flow.clone(),this.volume.clone(),this.value)}};function _h(e,t){switch(m(`kind`,e,mh),d(`period`,t,{min:1,integer:!0}),e){case`sma`:return new hh(new H(t));case`ema`:return new hh(U.ema(t));case`rma`:return new hh(U.rma(t));case`wma`:return new hh(new sh(t));case`vwma`:return gh.of(t)}}let vh=[null,`sma`,`sma`,`ema`,`rma`,`wma`,`vwma`];function yh(e){return{maType:Z([`None`,`SMA`,`SMA + Bollinger Bands`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],+!!e,`Type`,!1),maLength:{...X(14,`Length`),legend:!1},bbMult:{default:2,min:.001,max:50,label:`BB StdDev`,legend:!1}}}function bh(e,t,{maType:n}){if(Q(vh,n,`smoothing type`)===null)return[];let r=Y(`${e}BasedMa`,`${t}-based MA`);return n===2?[r,Y(`upperBollingerBand`,`Upper Bollinger Band`),Y(`lowerBollingerBand`,`Lower Bollinger Band`)]:[r]}function xh({maType:e}){return e===2?[{from:`upperBollingerBand`,to:`lowerBollingerBand`}]:[]}var Sh=class e{value;average;deviation;multiplier;out;constructor(e,t,n,r){this.value=e,this.average=t,this.deviation=n,this.multiplier=r,this.out=new Float64Array(1+ +!!t+(n?2:0))}static of(t,{maType:n,maLength:r,bbMult:i}){let a=Q(vh,n,`smoothing type`);return new e(t,a&&_h(a,r),n===2?new ah(r):null,i)}next(e,t){let n=this.value.next(t,e);if(this.out[0]=n,this.average){let t=this.average.next(n,e);if(this.out[1]=t,this.deviation){let e=this.deviation.next(n)*this.multiplier;this.out[2]=t+e,this.out[3]=t-e}}return this.out}clone(){return new e(this.value.clone(),this.average?.clone()??null,this.deviation?.clone()??null,this.multiplier)}};let Ch={type:`MA`,name:`MA`,pane:`main`,precision:`price`,params:{periods:dh([9],`Length`)},outputs:({periods:e})=>uh(`MA`,e),create:({periods:e})=>new q(e.map(e=>new H(e)),(e,t)=>t)},wh={type:`EMA`,name:`EMA`,pane:`main`,precision:`price`,params:{periods:dh([9],`Length`)},outputs:({periods:e})=>uh(`EMA`,e),create:({periods:e})=>new q(e.map(e=>U.ema(e)),(e,t)=>t)},Th={type:`SMMA`,name:`SMMA`,pane:`main`,precision:`price`,params:{periods:dh([7],`Length`)},outputs:({periods:e})=>uh(`SMMA`,e),create:({periods:e})=>new q(e.map(e=>U.rma(e)),(e,t)=>t)},Eh={type:`WMA`,name:`WMA`,pane:`main`,precision:`price`,params:{periods:dh([9],`Length`)},outputs:({periods:e})=>uh(`WMA`,e),create:({periods:e})=>new q(e.map(e=>new sh(e)),(e,t)=>t)};var Dh=class e{period;half;full;root;constructor(e,t=new sh(Math.floor(e/2)),n=new sh(e),r=new sh(Math.floor(Math.sqrt(e)))){this.period=e,this.half=t,this.full=n,this.root=r}next(e){let t=2*this.half.next(e)-this.full.next(e);return Number.isNaN(t)?t:this.root.next(t)}clone(){return new e(this.period,this.half.clone(),this.full.clone(),this.root.clone())}};let Oh={type:`HMA`,name:`HMA`,pane:`main`,precision:`price`,params:{periods:{default:[9],min:2,max:2e3,integer:!0,label:`Length`}},outputs:({periods:e})=>uh(`HMA`,e),create:({periods:e})=>new q(e.map(e=>new Dh(e)),(e,t)=>t)};var kh=class e{period;fast;slow;previous;history;moves;value;fastest;slowest;constructor(e,t,n,r=new K,i=new V(e),a=new W(e),o=NaN){this.period=e,this.fast=t,this.slow=n,this.previous=r,this.history=i,this.moves=a,this.value=o,this.fastest=2/(t+1),this.slowest=2/(n+1)}next(e){let t=this.previous.next(e),n=this.history.push(e),r=this.moves.next(Math.abs(e-t));if(Number.isNaN(r))return NaN;let i=((r===0?0:Math.abs(e-n)/r)*(this.fastest-this.slowest)+this.slowest)**2,a=Number.isNaN(this.value)?e:this.value;return this.value=a+i*(e-a),this.value}clone(){return new e(this.period,this.fast,this.slow,this.previous.clone(),this.history.clone(),this.moves.clone(),this.value)}};let Ah={type:`KAMA`,name:`KAMA`,pane:`main`,precision:`price`,params:{period:X(10,`ER length`),fast:X(2,`Fast length`),slow:X(30,`Slow length`)},outputs:()=>[J(`KAMA`)],create:({period:e,fast:t,slow:n})=>new q([new kh(e,t,n)],(e,t)=>t)};var jh=class e{weights;norm;window;constructor(e,t,n=new V(e.length)){this.weights=e,this.norm=t,this.window=n}next(e){if(this.window.push(e),!this.window.full)return NaN;let t=0;for(let e=0;e<this.weights.length;e+=1)t+=this.window.at(e)*(this.weights[e]??0);return t/this.norm}clone(){return new e(this.weights,this.norm,this.window.clone())}};function Mh(e,t,n){let r=t*(e-1),i=e/n,a=Float64Array.from({length:e},(e,t)=>Math.exp(-((t-r)**2)/(2*i*i)));return new jh(a,a.reduce((e,t)=>e+t,0))}let Nh={type:`ALMA`,name:`ALMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`),offset:{default:.85,min:0,max:1,label:`Offset`},sigma:{default:6,min:.1,max:100,label:`Sigma`}},outputs:()=>[J(`ALMA`)],create:({period:e,offset:t,sigma:n})=>new q([Mh(e,t,n)],(e,t)=>t)},Ph={type:`VWMA`,name:`VWMA`,pane:`main`,precision:`price`,params:{periods:dh([20],`Length`)},outputs:({periods:e})=>uh(`VWMA`,e),create:({periods:e})=>new q(e.map(e=>gh.of(e)),(e,t)=>t)};var Fh=class e{averages;constructor(e){this.averages=e}next(e){let t=0;for(let n of this.averages)t+=n.next(e);return t/this.averages.length}clone(){return new e(this.averages.map(e=>e.clone()))}};let Ih={type:`BBI`,name:`BBI`,pane:`main`,precision:`price`,params:{n1:X(3,`N1`),n2:X(6,`N2`),n3:X(12,`N3`),n4:X(24,`N4`)},outputs:()=>[J(`BBI`)],create:({n1:e,n2:t,n3:n,n4:r})=>new q([new Fh([e,t,n,r].map(e=>new ih(e)))],(e,t)=>t)};function Lh(e,t){return Math.max(e.high-e.low,Math.abs(e.high-t),Math.abs(e.low-t))}var Rh=class e{closes;constructor(e=new K){this.closes=e}next(e){let t=this.closes.next(e.close);return Number.isNaN(t)?e.high-e.low:Lh(e,t)}clone(){return new e(this.closes.clone())}},zh=class e{ranges;average;constructor(e,t){this.ranges=e,this.average=t}static of(t){return new e(new Rh,U.rma(t))}next(e){return this.average.next(this.ranges.next(e))}clone(){return new e(this.ranges.clone(),this.average.clone())}},Bh=class e{ranges;average;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.ranges=e,this.average=t}next(e){return this.out[0]=this.average.next(this.ranges.next(e),e),this.out}clone(){return new e(this.ranges.clone(),this.average.clone())}};let Vh=[`rma`,`sma`,`ema`,`wma`],Hh={type:`ATR`,name:`ATR`,pane:`new`,precision:`price`,params:{period:X(14,`Length`),smoothing:Z([`RMA`,`SMA`,`EMA`,`WMA`],0,`Smoothing`)},outputs:()=>[J(`ATR`)],create:({period:e,smoothing:t})=>new Bh(new Rh,_h(Q(Vh,t,`smoothing`),e))},Uh={type:`STD`,name:`STD`,pane:`new`,precision:`price`,params:{period:{default:20,min:2,max:2e3,integer:!0,label:`Period`}},outputs:()=>[J(`STD`)],create:({period:e})=>new q([new ah(e)],(e,t)=>t)};var Wh=class e{period;ranges;sums;extremes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new Rh,n=new W(e),r=new G(e)){this.period=e,this.ranges=t,this.sums=n,this.extremes=r}next(e){let t=this.sums.next(this.ranges.next(e));this.extremes.push(e.high,e.low);let n=this.extremes.highest()-this.extremes.lowest();return this.out[0]=100*Math.log10($(t,n))/Math.log10(this.period),this.out}clone(){return new e(this.period,this.ranges.clone(),this.sums.clone(),this.extremes.clone())}};let Gh={type:`CHOP`,name:`CHOP`,pane:`new`,precision:2,params:{period:{default:14,min:2,max:2e3,integer:!0,label:`Length`}},outputs:()=>[J(`CHOP`)],levels:()=>[61.8,50,38.2],create:({period:e})=>new Wh(e)},Kh=()=>[{from:`upper`,to:`lower`}],qh=[`sma`,`ema`,`rma`,`wma`,`vwma`];var Jh=class e{multiplier;mean;deviation;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.multiplier=e,this.mean=t,this.deviation=n}next(e,t){let n=this.mean.next(t,e),r=this.deviation.next(t)*this.multiplier;return this.out[0]=n,this.out[1]=n+r,this.out[2]=n-r,this.out}clone(){return new e(this.multiplier,this.mean.clone(),this.deviation.clone())}};let Yh={type:`BOLL`,name:`BOLL`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),maType:Z([`SMA`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],0,`Basis MA Type`),multiplier:{default:2,min:.001,max:50,label:`StdDev`}},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:Kh,create:({period:e,maType:t,multiplier:n})=>new Jh(n,_h(Q(qh,t,`basis average`),e),new ah(e))},Xh=[`Average True Range`,`True Range`,`Range`];var Zh=class e{average;constructor(e){this.average=e}next(e){return this.average.next(e.high-e.low)}clone(){return new e(this.average.clone())}},Qh=class e{multiplier;mean;width;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.multiplier=e,this.mean=t,this.width=n}next(e,t){let n=this.mean.next(t,e),r=this.width.next(e)*this.multiplier;return this.out[0]=n+r,this.out[1]=n,this.out[2]=n-r,this.out}clone(){return new e(this.multiplier,this.mean.clone(),this.width.clone())}};let $h={type:`KC`,name:`KC`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),multiplier:{default:2,min:.1,max:10,label:`Multiplier`},exponential:ph(!0,`Use Exponential MA`,!1),bandStyle:Z(Xh,0,`Bands Style`,!1),atrPeriod:{...X(10,`ATR Length`),legend:!1}},outputs:()=>[Y(`upper`,`Upper`),Y(`basis`,`Basis`),Y(`lower`,`Lower`)],fills:Kh,create:({period:e,multiplier:t,exponential:n,bandStyle:r,atrPeriod:i})=>{Q(Xh,r,`band style`);let a=r===0?zh.of(i):r===1?new Rh:new Zh(U.rma(e));return new Qh(t,_h(n===1?`ema`:`sma`,e),a)}};var eg=class e{extremes;out=/* @__PURE__ */ new Float64Array(3);constructor(e){this.extremes=e}next(e){this.extremes.push(e.high,e.low);let t=this.extremes.highest(),n=this.extremes.lowest();return this.out[0]=(t+n)/2,this.out[1]=t,this.out[2]=n,this.out}clone(){return new e(this.extremes.clone())}};let tg={type:`DC`,name:`DC`,pane:`main`,precision:`price`,params:{period:X(20,`Length`)},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:Kh,create:({period:e})=>new eg(new G(e))};function ng(e){let t=e===null||Ma(e)!==null||e.unit===`day`&&e.count===1;return Math.sqrt(365/(t?1:7))}var rg=class e{scale;deviation;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t,n=new K){this.scale=e,this.deviation=t,this.closes=n}next(e){let t=$(e.close,this.closes.next(e.close));return this.out[0]=100*this.deviation.next(Math.log(t))*this.scale,this.out}clone(){return new e(this.scale,this.deviation.clone(),this.closes.clone())}};let ig={type:`HV`,name:`HV`,pane:`new`,precision:2,params:{period:X(10,`Length`)},outputs:()=>[J(`HV`)],create:({period:e},{interval:t})=>new rg(ng(t),new ah(e))};var ag=class e{sum;single;double;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=U.ema(9),n=U.ema(9)){this.sum=e,this.single=t,this.double=n}next(e){let t=this.single.next(e.high-e.low);return this.out[0]=this.sum.next($(t,this.double.next(t))),this.out}clone(){return new e(this.sum.clone(),this.single.clone(),this.double.clone())}};let og={type:`MASS`,name:`Mass Index`,pane:`new`,precision:2,params:{period:X(10,`Length`)},outputs:()=>[Y(`massIndex`,`Mass Index`)],create:({period:e})=>new ag(new W(e))},sg={period:X(20,`Length`),multiplier:{default:2,min:.001,max:50,label:`StdDev`}};var cg=class e{multiplier;mean;deviation;basis=NaN;spread=NaN;constructor(e,t,n){this.multiplier=e,this.mean=t,this.deviation=n}static of({period:t,multiplier:n}){return new e(n,new H(t),new ah(t))}next(e){this.basis=this.mean.next(e),this.spread=this.deviation.next(e)*this.multiplier}clone(){let t=new e(this.multiplier,this.mean.clone(),this.deviation.clone());return t.basis=this.basis,t.spread=this.spread,t}},lg=class e{bands;expansions;contractions;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.bands=e,this.expansions=t,this.contractions=n}next(e,t){this.bands.next(t);let n=$(2*this.bands.spread,this.bands.basis)*100;return this.expansions.push(n),this.contractions.push(n),this.out[0]=n,this.out[1]=this.expansions.full?this.expansions.max():NaN,this.out[2]=this.contractions.full?this.contractions.min():NaN,this.out}clone(){return new e(this.bands.clone(),this.expansions.clone(),this.contractions.clone())}};let ug={type:`BBW`,name:`BBW`,pane:`new`,precision:2,params:{...sg,expansion:X(125,`Highest Expansion Length`),contraction:X(125,`Lowest Contraction Length`)},outputs:()=>[Y(`bollingerBandWidth`,`Bollinger BandWidth`),Y(`highestExpansion`,`Highest Expansion`),Y(`lowestContraction`,`Lowest Contraction`)],create:e=>new lg(cg.of(e),new V(e.expansion),new V(e.contraction))};var dg=class e{bands;out=/* @__PURE__ */ new Float64Array(1);constructor(e){this.bands=e}next(e,t){this.bands.next(t);let{basis:n,spread:r}=this.bands;return this.out[0]=$(t-(n-r),2*r),this.out}clone(){return new e(this.bands.clone())}};let fg={type:`BBP`,name:`BB %B`,pane:`new`,precision:2,params:sg,outputs:()=>[Y(`bollingerBandsB`,`Bollinger Bands %b`)],levels:()=>[1,.5,0],create:e=>new dg(cg.of(e))},pg=[`ema`,`sma`];var mg=class e{fast;slow;signal;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.fast=e,this.slow=t,this.signal=n}next(e,t){let n=this.fast.next(t,e)-this.slow.next(t,e),r=this.signal.next(n,e);return this.out[0]=n-r,this.out[1]=n,this.out[2]=r,this.out}clone(){return new e(this.fast.clone(),this.slow.clone(),this.signal.clone())}};let hg={type:`MACD`,name:`MACD`,pane:`new`,precision:`price`,params:{fast:{default:12,min:1,max:500,integer:!0,label:`Fast length`},slow:{default:26,min:1,max:500,integer:!0,label:`Slow length`},signal:{default:9,min:1,max:500,integer:!0,label:`Signal length`},oscillatorType:Z([`EMA`,`SMA`],0,`Oscillator MA type`,!1),signalType:Z([`EMA`,`SMA`],0,`Signal MA type`,!1)},outputs:()=>[{key:`histogram`,label:`Histogram`,plot:{kind:`histogram`,colorBy:`sign`}},Y(`macd`,`MACD`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:({fast:e,slow:t,signal:n,oscillatorType:r,signalType:i})=>{let a=Q(pg,r,`oscillator average`);return new mg(_h(a,e),_h(a,t),_h(Q(pg,i,`signal average`),n))}};var gg=class e{period;previous;gains;losses;constructor(e,t=new K,n=U.rma(e),r=U.rma(e)){this.period=e,this.previous=t,this.gains=n,this.losses=r}next(e){let t=this.previous.next(e);if(Number.isNaN(t))return NaN;let n=this.gains.next(Math.max(e-t,0)),r=this.losses.next(Math.max(t-e,0));return r===0?100:n===0?0:100-100/(1+n/r)}clone(){return new e(this.period,this.previous.clone(),this.gains.clone(),this.losses.clone())}};let _g={type:`RSI`,name:`RSI`,pane:`new`,precision:2,params:{period:X(14,`RSI Length`),...yh(!0)},outputs:e=>[Y(`rsi`,`RSI`),...bh(`rsi`,`RSI`,e)],fills:xh,levels:()=>[70,50,30],range:{min:0,max:100},create:e=>Sh.of(new gg(e.period),e)};var vg=class e{range;k;d;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n){this.range=e,this.k=t,this.d=n}next(e){this.range.push(e.high,e.low);let t=this.range.lowest(),n=this.range.highest()-t;if(Number.isNaN(n))return this.out.fill(NaN),this.out;let r=n===0?50:(e.close-t)/n*100,i=this.k.next(r),a=this.d.next(i);return this.out[0]=i,this.out[1]=a,this.out[2]=3*i-2*a,this.out}clone(){return new e(this.range.clone(),this.k.clone(),this.d.clone())}};let yg={type:`KDJ`,name:`KDJ`,pane:`new`,precision:2,params:{period:X(9),k:X(3,`K`),d:X(3,`D`)},outputs:()=>[`K`,`D`,`J`].map(J),levels:()=>[20,80],create:({period:e,k:t,d:n})=>new vg(new G(e),new oh(t,1),new oh(n,1))};var bg=class e{ranges;out;constructor(e){this.ranges=e,this.out=new Float64Array(e.length)}next(e,t){return this.ranges.forEach((n,r)=>{n.push(e.high,e.low);let i=n.highest();this.out[r]=$(t-i,i-n.lowest())*100}),this.out}clone(){return new e(this.ranges.map(e=>e.clone()))}};let xg={type:`WR`,name:`WR`,pane:`new`,precision:2,params:{periods:dh([14],`Length`)},outputs:({periods:e})=>e.map(e=>Y(`wr${String(e)}`,`%R${String(e)}`)),levels:()=>[-20,-50,-80],range:{min:-100,max:0},create:({periods:e})=>new bg(e.map(e=>new G(e)))};var Sg=class e{window;constructor(e){this.window=e}next(e){return this.window.push(e),this.window.full?this.cci(e):NaN}clone(){return new e(this.window.clone())}cci(e){let t=this.window.length,n=0;for(let r=0;r<t;r+=1)n+=e-this.window.at(r);n/=t;let r=0;for(let i=0;i<t;i+=1)r+=Math.abs(e-this.window.at(i)-n);return $(n,.015*r/t)}};let Cg={type:`CCI`,name:`CCI`,pane:`new`,source:`hlc3`,precision:2,params:{period:X(20,`Length`),...yh(!0)},outputs:e=>[Y(`cci`,`CCI`),...bh(`cci`,`CCI`,e)],fills:xh,levels:()=>[100,0,-100],create:e=>Sh.of(new Sg(new V(e.period)),e)};var wg=class e{history;constructor(e,t=new V(e)){this.history=t}next(e){let t=this.history.push(e);return $(e-t,t)*100}clone(){return new e(this.history.capacity,this.history.clone())}};let Tg={type:`ROC`,name:`ROC`,pane:`new`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[J(`ROC`)],levels:()=>[0],create:({period:e})=>new q([new wg(e)],(e,t)=>t)};var Eg=class e{period;average;constructor(e,t=new ih(e)){this.period=e,this.average=t}next(e){let t=this.average.next(e);return $(e-t,t)*100}clone(){return new e(this.period,this.average.clone())}};let Dg={type:`BIAS`,name:`BIAS`,pane:`new`,precision:2,params:{periods:dh([6,12,24])},outputs:({periods:e})=>uh(`BIAS`,e),create:({periods:e})=>new q(e.map(e=>new Eg(e)),(e,t)=>t)};var Og=class e{range;k;d;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.range=e,this.k=t,this.d=n}next(e){this.range.push(e.high,e.low);let t=this.range.lowest(),n=this.k.next($(e.close-t,this.range.highest()-t)*100);return this.out[0]=n,this.out[1]=this.d.next(n),this.out}clone(){return new e(this.range.clone(),this.k.clone(),this.d.clone())}};let kg={type:`STOCH`,name:`Stoch`,pane:`new`,precision:2,params:{period:X(14,`%K Length`),smoothK:X(1,`%K Smoothing`),smoothD:X(3,`%D Smoothing`)},outputs:()=>[Y(`k`,`%K`),Y(`d`,`%D`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({period:e,smoothK:t,smoothD:n})=>new Og(new G(e),new H(t),new H(n))};var Ag=class e{rsi;range;k;d;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.rsi=e,this.range=t,this.k=n,this.d=r}next(e,t){let n=this.rsi.next(t);this.range.push(n,n);let r=this.range.lowest(),i=this.k.next($(n-r,this.range.highest()-r)*100);return this.out[0]=i,this.out[1]=this.d.next(i),this.out}clone(){return new e(this.rsi.clone(),this.range.clone(),this.k.clone(),this.d.clone())}};let jg={type:`STOCHRSI`,name:`Stoch RSI`,pane:`new`,precision:2,params:{smoothK:X(3,`K`),smoothD:X(3,`D`),rsiPeriod:X(14,`RSI Length`),period:X(14,`Stochastic Length`)},outputs:()=>[Y(`k`,`K`),Y(`d`,`D`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({rsiPeriod:e,period:t,smoothK:n,smoothD:r})=>new Ag(new gg(e),new G(t),new H(n),new H(r))};var Mg=class e{range;out=/* @__PURE__ */ new Float64Array(2);state={value:NaN,fisher:NaN};constructor(e){this.range=e}next(e,t){let n=this.state;this.range.push(t,t);let r=this.range.lowest(),i=.66*($(t-r,this.range.highest()-r)-.5)+.67*(Number.isNaN(n.value)?0:n.value),a=i>.99?.999:i<-.99?-.999:i,o=.5*Math.log((1+a)/(1-a))+.5*(Number.isNaN(n.fisher)?0:n.fisher);return this.out[0]=o,this.out[1]=n.fisher,this.state={value:a,fisher:o},this.out}clone(){let t=new e(this.range.clone());return t.state=this.state,t}};let Ng={type:`FISHER`,name:`Fisher`,pane:`new`,source:`hl2`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[J(`Fisher`),J(`Trigger`)],levels:()=>[1.5,.75,0,-.75,-1.5],create:({period:e})=>new Mg(new G(e))};var Pg=class e{history;constructor(e){this.history=e}next(e){return e-this.history.push(e)}clone(){return new e(this.history.clone())}};let Fg={type:`MTM`,name:`MTM`,pane:`new`,precision:`price`,params:{period:X(10,`Length`)},outputs:()=>[Y(`mom`,`MOM`)],create:({period:e})=>new q([new Pg(new V(e))],(e,t)=>t)};var Ig=class e{centered;mean;prices;means;constructor(e,t,n,r){this.centered=e,this.mean=t,this.prices=n,this.means=r}next(e){let t=this.mean.next(e),n=this.prices.push(e),r=this.means.push(t);return this.centered?n-t:e-r}clone(){return new e(this.centered,this.mean.clone(),this.prices.clone(),this.means.clone())}};function Lg(e){return Math.floor(e/2)+1}let Rg={type:`DPO`,name:`DPO`,pane:`new`,precision:2,params:{period:X(21,`Length`),centered:ph(!1,`Centered`)},outputs:({period:e,centered:t})=>[{...Y(`dpo`,`DPO`),...t===1?{offset:-Lg(e)}:{}}],levels:()=>[0],create:({period:e,centered:t})=>new q([new Ig(t===1,new H(e),new V(Lg(e)),new V(Lg(e)))],(e,t)=>t)};var zg=class e{period;previous;rises;constructor(e,t=new K,n=new W(e)){this.period=e,this.previous=t,this.rises=n}next(e){let t=this.previous.next(e),n=Number.isNaN(t)?NaN:+(e>t);return this.rises.next(n)/this.period*100}clone(){return new e(this.period,this.previous.clone(),this.rises.clone())}};let Bg={type:`PSY`,name:`PSY`,pane:`new`,precision:2,params:{period:X(12),signal:X(6,`Signal`)},outputs:()=>[J(`PSY`),J(`PSYMA`)],range:{min:0,max:100},create:({period:e,signal:t})=>new lh(new zg(e),new ih(t))};var Vg=class e{period;closes;bullish;bearish;above;below;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new K,n=new W(e),r=new W(e),i=new W(e),a=new W(e)){this.period=e,this.closes=t,this.bullish=n,this.bearish=r,this.above=i,this.below=a}next(e){let t=this.closes.next(e.close),n=this.bullish.next(Math.max(0,e.high-t)),r=this.bearish.next(Math.max(0,t-e.low));return this.out[0]=$(n,r)*100,this.out[1]=$(this.above.next(e.high-e.open),this.below.next(e.open-e.low))*100,this.out}clone(){return new e(this.period,this.closes.clone(),this.bullish.clone(),this.bearish.clone(),this.above.clone(),this.below.clone())}};let Hg={type:`BRAR`,name:`BRAR`,pane:`new`,precision:2,params:{period:X(26)},outputs:()=>[J(`BR`),J(`AR`)],create:({period:e})=>new Vg(e)};var Ug=class e{fast;slow;constructor(e,t){this.fast=e,this.slow=t}next(e){return this.fast.next(e)-this.slow.next(e)}clone(){return new e(this.fast.clone(),this.slow.clone())}};let Wg={type:`AO`,name:`AO`,pane:`new`,source:`hl2`,precision:`price`,params:{fast:X(5,`Fast length`),slow:X(34,`Slow length`)},outputs:()=>[{key:`ao`,label:`AO`,plot:{kind:`histogram`,colorBy:`change`}}],create:({fast:e,slow:t})=>new q([new Ug(new H(e),new H(t))],(e,t)=>t)};var Gg=class e{short;long;constructor(e,t){this.short=e,this.long=t}next(e,t){let n=this.long.next(e,t);return $(this.short.next(e,t)-n,n)*100}clone(){return new e(this.short.clone(),this.long.clone())}};let Kg={type:`PPO`,name:`PPO`,pane:`new`,precision:2,params:{short:X(10,`Short Length`),long:X(21,`Long Length`),exponential:ph(!1,`Use Exponential MA`,!1)},outputs:()=>[Y(`ppo`,`PPO`)],levels:()=>[0],create:({short:e,long:t,exponential:n})=>{let r=n===1?`ema`:`sma`;return new q([new Gg(_h(r,e),_h(r,t))],(e,t)=>t)}};var qg=class e{period;previous;gains;losses;constructor(e,t=new K,n=new W(e),r=new W(e)){this.period=e,this.previous=t,this.gains=n,this.losses=r}next(e){let t=e-this.previous.next(e),n=this.gains.next(Math.max(t,0)),r=this.losses.next(Math.max(-t,0));return $(100*(n-r),n+r)}clone(){return new e(this.period,this.previous.clone(),this.gains.clone(),this.losses.clone())}};let Jg={type:`CMO`,name:`CMO`,pane:`new`,precision:2,params:{period:X(9,`Length`)},outputs:()=>[Y(`chandeMo`,`Chande MO`)],levels:()=>[0],create:({period:e})=>new q([new qg(e)],(e,t)=>t)};var Yg=class e{pressure;range;constructor(e,t){this.pressure=e,this.range=t}static of(t){return new e(new W(t),new W(t))}next(e,t){return $(this.pressure.next(e),this.range.next(t))}clone(){return new e(this.pressure.clone(),this.range.clone())}},Xg=class e{sums;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K){this.sums=e,this.closes=t}next(e){let t=this.closes.next(e.close),n=Math.min(e.low,t),r=e.close-n,i=Math.max(e.high,t)-n,[a,o,s]=this.sums;return this.out[0]=100*(4*a.next(r,i)+2*o.next(r,i)+s.next(r,i))/7,this.out}clone(){let[t,n,r]=this.sums;return new e([t.clone(),n.clone(),r.clone()],this.closes.clone())}};let Zg={type:`UO`,name:`UO`,pane:`new`,precision:2,params:{fast:X(7,`Fast length`),middle:X(14,`Middle length`),slow:X(28,`Slow length`)},outputs:()=>[Y(`uo`,`UO`)],create:({fast:e,middle:t,slow:n})=>new Xg([Yg.of(e),Yg.of(t),Yg.of(n)])};var Qg=class e{roc;average;constructor(e,t){this.roc=e,this.average=t}static of(t,n){return new e(new wg(t),new H(n))}next(e){return this.average.next(this.roc.next(e))}clone(){return new e(this.roc.clone(),this.average.clone())}},$g=class e{rocs;constructor(e){this.rocs=e}next(e){return this.rocs.reduce((t,n,r)=>t+(r+1)*n.next(e),0)}clone(){return new e(this.rocs.map(e=>e.clone()))}};let e_={type:`KST`,name:`KST`,pane:`new`,precision:4,params:{roc1:X(10,`ROC Length #1`),roc2:X(15,`ROC Length #2`),roc3:X(20,`ROC Length #3`),roc4:X(30,`ROC Length #4`),sma1:X(10,`SMA Length #1`),sma2:X(10,`SMA Length #2`),sma3:X(10,`SMA Length #3`),sma4:X(15,`SMA Length #4`),signal:X(9,`Signal length`)},outputs:()=>[Y(`kst`,`KST`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:e=>new lh(new $g([Qg.of(e.roc1,e.sma1),Qg.of(e.roc2,e.sma2),Qg.of(e.roc3,e.sma3),Qg.of(e.roc4,e.sma4)]),new H(e.signal))};var t_=class e{long;short;average;constructor(e,t,n){this.long=e,this.short=t,this.average=n}next(e){return this.average.next(this.long.next(e)+this.short.next(e))}clone(){return new e(this.long.clone(),this.short.clone(),this.average.clone())}};let n_={type:`COPPOCK`,name:`Coppock`,pane:`new`,precision:2,params:{wmaLength:X(10,`WMA Length`),longRoc:X(14,`Long RoC Length`),shortRoc:X(11,`Short RoC Length`)},outputs:()=>[Y(`coppockCurve`,`Coppock Curve`)],levels:()=>[0],create:({wmaLength:e,longRoc:t,shortRoc:n})=>new q([new t_(new wg(t),new wg(n),new sh(e))],(e,t)=>t)};var r_=class e{first;second;constructor(e,t){this.first=e,this.second=t}static of(t,n){return new e(U.ema(t),U.ema(n))}next(e){return this.second.next(this.first.next(e))}clone(){return new e(this.first.clone(),this.second.clone())}},i_=class e{change;size;previous;constructor(e,t,n=new K){this.change=e,this.size=t,this.previous=n}next(e){let t=e-this.previous.next(e);return 100*$(this.change.next(t),this.size.next(Math.abs(t)))}clone(){return new e(this.change.clone(),this.size.clone(),this.previous.clone())}};let a_={type:`TSI`,name:`TSI`,pane:`new`,precision:4,params:{long:X(25,`Long Length`),short:X(13,`Short Length`),signal:X(13,`Signal length`)},outputs:()=>[Y(`trueStrengthIndex`,`True Strength Index`),Y(`signalLine`,`Signal line`)],levels:()=>[0],create:({long:e,short:t,signal:n})=>new lh(new i_(r_.of(e,t),r_.of(e,t)),U.ema(n))};var o_=class e{range;distance;width;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.range=e,this.distance=t,this.width=n,this.average=r}next(e){this.range.push(e.high,e.low);let t=this.range.highest(),n=this.range.lowest(),r=200*$(this.distance.next(e.close-(t+n)/2),this.width.next(t-n));return this.out[0]=r,this.out[1]=this.average.next(r),this.out}clone(){return new e(this.range.clone(),this.distance.clone(),this.width.clone(),this.average.clone())}};let s_={type:`SMI`,name:`SMI`,pane:`new`,precision:2,params:{kLength:X(10,`%K Length`),dLength:X(3,`%D Length`),emaLength:X(3,`EMA Length`)},outputs:()=>[Y(`smi`,`SMI`),Y(`smiBasedEma`,`SMI-based EMA`)],levels:()=>[40,-40],create:({kLength:e,dLength:t,emaLength:n})=>new o_(new G(e),r_.of(t,t),r_.of(t,t),U.ema(n))};var c_=class e{window;constructor(e=new V(4)){this.window=e}next(e){this.window.push(e);let{window:t}=this;return t.full?(t.at(0)+2*t.at(1)+2*t.at(2)+t.at(3))/6:NaN}clone(){return new e(this.window.clone())}},l_=class e{body;span;bodies;spans;signal;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r,i){this.body=e,this.span=t,this.bodies=n,this.spans=r,this.signal=i}next(e){let t=$(this.bodies.next(this.body.next(e.close-e.open)),this.spans.next(this.span.next(e.high-e.low)));return this.out[0]=t,this.out[1]=this.signal.next(t),this.out}clone(){return new e(this.body.clone(),this.span.clone(),this.bodies.clone(),this.spans.clone(),this.signal.clone())}};let u_={type:`RVGI`,name:`RVGI`,pane:`new`,precision:4,params:{period:X(10,`Length`)},outputs:()=>[Y(`rvgi`,`RVGI`),Y(`signalLine`,`Signal line`)],create:({period:e})=>new l_(new c_,new c_,new W(e),new W(e),new c_)},d_={type:`BOP`,name:`BOP`,pane:`new`,precision:2,params:{},outputs:()=>[Y(`bop`,`BOP`)],create:()=>new q([ch],e=>$(e.close-e.open,e.high-e.low))};var f_=class e{previous;streak;constructor(e=new K,t=0){this.previous=e,this.streak=t}next(e){let t=this.previous.next(e),{streak:n}=this;return this.streak=e===t?0:e>t?Math.max(n,0)+1:Math.min(n,0)-1,this.streak}clone(){return new e(this.previous.clone(),this.streak)}},p_=class e{window;constructor(e){this.window=e}next(e){if(Number.isNaN(e))return NaN;let{window:t}=this,n=0;for(let r=0;r<t.length;r+=1)n+=+(t.at(r)<=e);let r=t.full?100*n/t.capacity:NaN;return t.push(e),r}clone(){return new e(this.window.clone())}},m_=class e{rsi;streak;streakRsi;change;rank;constructor(e,t,n,r,i){this.rsi=e,this.streak=t,this.streakRsi=n,this.change=r,this.rank=i}next(e){return(this.rsi.next(e)+this.streakRsi.next(this.streak.next(e))+this.rank.next(this.change.next(e)))/3}clone(){return new e(this.rsi.clone(),this.streak.clone(),this.streakRsi.clone(),this.change.clone(),this.rank.clone())}};let h_={type:`CRSI`,name:`CRSI`,pane:`new`,precision:2,params:{rsiLength:X(3,`RSI Length`),streakLength:X(2,`UpDown Length`),rocLength:X(100,`ROC Length`)},outputs:()=>[Y(`crsi`,`CRSI`)],levels:()=>[70,50,30],range:{min:0,max:100},create:({rsiLength:e,streakLength:t,rocLength:n})=>new q([new m_(new gg(e),new f_,new gg(t),new wg(1),new p_(new V(n)))],(e,t)=>t)},g_=[`1D`,`1W`,`1M`,`3M`,`12M`];function __(e){return Q(g_,e,`period`)}var v_=class e{calendar;interval;years;current=null;previous=null;start=NaN;constructor(e,t,n=1){this.calendar=e,this.interval=t,this.years=n}push(e){let t=this.calendar.bucket(e.time,this.interval);return t!==null&&t!==this.start&&(this.years===1||new Date(t+1728e5).getUTCFullYear()%this.years===0)?(this.start=t,this.previous=this.current,this.current={open:e.open,high:e.high,low:e.low,close:e.close},!0):(this.current&&(this.current.high=Math.max(this.current.high,e.high),this.current.low=Math.min(this.current.low,e.low),this.current.close=e.close),!1)}clone(){let t=new e(this.calendar,this.interval,this.years);return t.start=this.start,t.current=this.current&&{...this.current},t.previous=this.previous&&{...this.previous},t}};let y_=[{label:`Traditional`,depth:5,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3;return[r,r*2-t,r*2-e,r+(e-t),r-(e-t),r*2+(e-2*t),r*2-(2*e-t),r*3+(e-3*t),r*3-(3*e-t),r*4+(e-4*t),r*4-(4*e-t)]}},{label:`Fibonacci`,depth:3,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3,i=e-t;return[r,r+.382*i,r-.382*i,r+.618*i,r-.618*i,r+i,r-i]}},{label:`Woodie`,depth:4,levels:({high:e,low:t},n)=>{let r=(e+t+2*n)/4,i=e+2*(r-t),a=t-2*(e-r);return[r,2*r-t,2*r-e,r+(e-t),r-(e-t),i,a,i+(e-t),a-(e-t)]}},{label:`Classic`,depth:4,levels:({high:e,low:t,close:n})=>{let r=(e+t+n)/3,i=e-t;return[r,2*r-t,2*r-e,r+i,r-i,r+2*i,r-2*i,r+3*i,r-3*i]}},{label:`DM`,depth:1,levels:({open:e,high:t,low:n,close:r})=>{let i=r===e?t+n+2*r:r>e?2*t+n+r:2*n+t+r;return[i/4,i/2-n,i/2-t]}},{label:`Camarilla`,depth:5,levels:({high:e,low:t,close:n})=>{let r=1.1*(e-t),i=e/t*n;return[(e+t+n)/3,n+r/12,n-r/12,n+r/6,n-r/6,n+r/4,n-r/4,n+r/2,n-r/2,i,n-(i-n)]}}];function b_(e){return y_[e]??n(`There are no pivot points of kind ${e}.`)}let x_=[[`1D`,1],[`1W`,1],[`1M`,1],[`3M`,1],[`12M`,1],[`12M`,2],[`12M`,3],[`12M`,5],[`12M`,10]];function S_(e){if(e===null)return`1D`;let t=Ma(e);return t===null?e.unit===`day`&&e.count<7?`1M`:`12M`:t<=9e5?`1D`:`1W`}var C_=class e{kind;periods;levels;constructor(e,t,n=new Float64Array(1+e.depth*2).fill(NaN)){this.kind=e,this.periods=t,this.levels=n}next(e){if(this.periods.push(e)){let{previous:e,current:t}=this.periods;e&&t&&(this.levels=Float64Array.from(this.kind.levels(e,t.open)))}return this.levels}clone(){return new e(this.kind,this.periods.clone(),this.levels)}};let w_={type:`PIVOTS`,name:`Pivots`,pane:`main`,precision:`price`,params:{kind:{default:0,label:`Type`,options:/* @__PURE__ */ y_.map(({label:e},t)=>({value:t,label:e}))},period:Z([`Auto`,`Daily`,`Weekly`,`Monthly`,`Quarterly`,`Yearly`,`Biyearly`,`Triyearly`,`Quinquennially`,`Decennially`],0,`Pivots timeframe`)},outputs:({kind:e})=>{let t=[{key:`p`,label:`P`,plot:{kind:`segments`},autoscale:!1}];for(let n=1;n<=b_(e).depth;n+=1)t.push({key:`r${n}`,label:`R${n}`,plot:{kind:`segments`},themeColor:`down`,autoscale:!1},{key:`s${n}`,label:`S${n}`,plot:{kind:`segments`},themeColor:`up`,autoscale:!1});return t},create:({kind:e,period:t},{calendar:n,interval:r})=>{let[i,a]=t===0?[S_(r),1]:Q(x_,t-1,`pivot timeframe`);return new C_(b_(e),new v_(n,i,a))}};var T_=class e{periods;out=/* @__PURE__ */ new Float64Array(3);constructor(e){this.periods=e}next(e){this.periods.push(e);let t=this.periods.previous;return this.out[0]=t?.high??NaN,this.out[1]=t?.low??NaN,this.out[2]=t?.close??NaN,this.out}clone(){return new e(this.periods.clone())}};let E_={type:`PREVHLC`,name:`Prev HLC`,pane:`main`,precision:`price`,params:{period:Z([`Day`,`Week`,`Month`,`Quarter`,`Year`],0,`Period`)},outputs:()=>[{key:`high`,label:`PH`,plot:{kind:`segments`},themeColor:`up`,autoscale:!1},{key:`low`,label:`PL`,plot:{kind:`segments`},themeColor:`down`,autoscale:!1},{key:`close`,label:`PC`,plot:{kind:`segments`,style:`dashed`},autoscale:!1}],create:({period:e},{calendar:t})=>new T_(new v_(t,__(e)))},D_={type:`ADR`,name:`ADR`,pane:`new`,precision:`price`,params:{period:X(14,`Length`)},outputs:()=>[J(`ADR`)],create:({period:e})=>new q([new H(e)],e=>e.high-e.low)},O_=[`1D`,`1W`,`1M`,`3M`,`12M`];function k_(e,t){let{offsets:n,volumes:r}=e,i=0,a=n.length;for(;i<a;){let e=i+a>>>1;(n[e]??NaN)<=t?i=e+1:a=e}return i===0?NaN:r[i-1]??NaN}var A_=class e{start;offsets;volumes;count;total;constructor(e=NaN,t=/* @__PURE__ */ new Float64Array(64),n=/* @__PURE__ */ new Float64Array(64),r=0,i=0){this.start=e,this.offsets=t,this.volumes=n,this.count=r,this.total=i}add(e,t){if(this.count===this.offsets.length){let e=new Float64Array(this.count*2),t=new Float64Array(this.count*2);e.set(this.offsets),t.set(this.volumes),this.offsets=e,this.volumes=t}this.offsets[this.count]=e,this.volumes[this.count]=t,this.count+=1}ended(){return{offsets:this.offsets.slice(0,this.count),volumes:this.volumes.slice(0,this.count)}}clone(){return new e(this.start,this.offsets.slice(),this.volumes.slice(),this.count,this.total)}},j_=class e{calendar;anchor;length;cumulative;current;past;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n,r,i=new A_,a=[]){this.calendar=e,this.anchor=t,this.length=n,this.cumulative=r,this.current=i,this.past=a}next(e){let t=this.calendar.bucket(e.time,this.anchor);if(t!==null&&t!==this.current.start&&(Number.isNaN(this.current.start)||(this.past=[...this.past,this.current.ended()].slice(-this.length)),this.current=new A_(t)),Number.isNaN(this.current.start))return this.out.fill(NaN),this.out;let n=e.time-this.current.start;this.current.total+=e.volume;let r=this.cumulative?this.current.total:e.volume;this.current.add(n,r);let i=this.past.length<this.length?NaN:this.average(n);return this.out[0]=$(r,i),this.out[1]=r,this.out[2]=i,this.out}average(e){let t=0,n=0;for(let r of this.past){let i=k_(r,e);Number.isNaN(i)||(t+=i,n+=1)}return n===0?NaN:t/n}clone(){return new e(this.calendar,this.anchor,this.length,this.cumulative,this.current.clone(),this.past)}};let M_={type:`RVOL`,name:`RelVol`,pane:`new`,precision:`volume`,params:{anchor:Z([`Day`,`Week`,`Month`,`Quarter`,`Year`],0,`Anchor Timeframe`),period:X(5,`Length`),mode:Z([`Cumulative`,`Regular`],0,`Calculation Mode`)},outputs:()=>[{key:`relativeVolumeRatio`,label:`Relative Volume Ratio`,plot:{kind:`columns`,from:0},precision:2},{key:`currentVolume`,label:`Current Volume`,plot:{kind:`hidden`}},{key:`pastVolume`,label:`Past Volume`,plot:{kind:`hidden`}}],levels:()=>[1],create:({anchor:e,period:t,mode:n},{calendar:r})=>new j_(r,Q(O_,e,`anchor`),t,Q([!0,!1],n,`calculation mode`))},N_=[{key:`tokyo`,label:`Tokyo`,session:`09:00-15:00`,timeZone:`Asia/Tokyo`},{key:`london`,label:`London`,session:`08:30-16:30`,timeZone:`Europe/London`},{key:`newYork`,label:`New York`,session:`09:30-16:00`,timeZone:`America/New_York`}],P_=/^[a-zA-Z][a-zA-Z0-9]*$/;function F_(e,t){h(t,e),P_.test(p(`${t}.key`,e.key))||n(`${t}.key must be letters and digits, starting with a letter, received "${e.key}".`),p(`${t}.label`,e.label);let r=p(`${t}.session`,e.session);return Wa({timeZone:p(`${t}.timeZone`,e.timeZone),sessions:[r],dayStart:r.split(`-`)[0]??``})}var I_=class e{calendars;state;out;constructor(e,t=new Float64Array(e.length*3).fill(NaN)){this.calendars=e,this.state=t,this.out=new Float64Array(e.length*3)}next(e){let{state:t,out:n}=this;return this.calendars.forEach((r,i)=>{let a=r.bucket(e.time,`1D`),o=i*3;a===null?(t[o]=NaN,n.fill(NaN,o,o+3)):(a!==t[o]&&(t[o]=a,t[o+1]=e.high,t[o+2]=e.low),t[o+1]=Math.max(t[o+1]??NaN,e.high),t[o+2]=Math.min(t[o+2]??NaN,e.low),n[o]=t[o+1]??NaN,n[o+1]=t[o+2]??NaN,n[o+2]=a)}),n}clone(){return new e(this.calendars,this.state.slice())}};function L_(e,t=`SESSIONS`){v(`sessions`,e),e.length===0&&n(`sessions must contain at least one session.`);let r=e.map((e,t)=>F_(e,`sessions[${t}]`)),i=e.flatMap(({key:e,label:t})=>[{key:`${e}High`,label:`${t} H`,plot:{kind:`box`,from:`${e}Low`,group:`${e}Day`},autoscale:!1},{key:`${e}Low`,label:`${t} L`,plot:{kind:`hidden`}},{key:`${e}Day`,label:`${t} day`,plot:{kind:`hidden`},legend:!1,precision:0}]);return{type:t,name:`Sessions`,pane:`main`,precision:`price`,params:{},outputs:()=>i,create:()=>new I_(r)}}let R_=/* @__PURE__ */ L_(N_);var z_=class e{opens;lows;closes;constructor(e=new K,t=new K,n=new K){this.opens=e,this.lows=t,this.closes=n}next(e){let t=this.opens.next(e.open),n=this.lows.next(e.low),r=this.closes.next(e.close),i=Math.abs(e.high-r),a=Math.abs(e.low-r),o=Math.abs(e.high-n),s=Math.abs(r-t),c=i>a&&i>o?i+a/2+s/4:a>o&&a>i?a+i/2+s/4:o+s/4,l=e.close-r+(e.close-e.open)/2+r-t;return c===0?0:16*l/c*Math.max(i,a)}clone(){return new e(this.opens.clone(),this.lows.clone(),this.closes.clone())}},B_=class e{swing;sum;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.swing=e,this.sum=t,this.average=n}next(e){let t=this.sum.next(this.swing.next(e));return this.out[0]=t,this.out[1]=this.average.next(t),this.out}clone(){return new e(this.swing.clone(),this.sum.clone(),this.average.clone())}};let V_={type:`ASI`,name:`ASI`,pane:`new`,precision:`price`,params:{period:X(26),signal:X(10,`Signal`)},outputs:()=>[J(`ASI`),J(`ASIT`)],create:({period:e,signal:t})=>new B_(new z_,new W(e),new ih(t))};function H_(e){return Math.floor(e/2.5+1)}var U_=class e{average;history;constructor(e,t){this.average=e,this.history=t}static of(t){return new e(new ih(t),new V(H_(t)))}next(e){return this.history.push(this.average.next(e))}clone(){return new e(this.average.clone(),this.history.clone())}},W_=class e{averages;middles;above;below;out;constructor(e,t,n,r){this.averages=e,this.middles=t,this.above=n,this.below=r,this.out=new Float64Array(1+e.length)}next(e){let t=this.middles.next((e.high+e.low)/2),n=$(this.above.next(Math.max(0,e.high-t)),this.below.next(Math.max(0,t-e.low)))*100;return this.out[0]=n,this.averages.forEach((e,t)=>{this.out[t+1]=e.next(n)}),this.out}clone(){return new e(this.averages.map(e=>e.clone()),this.middles.clone(),this.above.clone(),this.below.clone())}};let G_={type:`CR`,name:`CR`,pane:`new`,precision:2,params:{period:X(26),periods:dh([10,20,40,62],`MA Length`)},outputs:({periods:e})=>[J(`CR`),...uh(`MA`,e)],create:({period:e,periods:t})=>new W_(t.map(e=>U_.of(e)),new K,new W(e),new W(e))};function K_(e){return(e.highest()+e.lowest())/2}var q_=class e{conversion;base;spanB;out=/* @__PURE__ */ new Float64Array(7);constructor(e,t,n){this.conversion=e,this.base=t,this.spanB=n}next(e){this.conversion.push(e.high,e.low),this.base.push(e.high,e.low),this.spanB.push(e.high,e.low);let t=K_(this.conversion),n=K_(this.base),r=(t+n)/2,i=K_(this.spanB);return this.out[0]=t,this.out[1]=n,this.out[2]=e.close,this.out[3]=r,this.out[4]=i,this.out[5]=Math.max(r,i),this.out[6]=Math.min(r,i),this.out}clone(){return new e(this.conversion.clone(),this.base.clone(),this.spanB.clone())}};let J_={type:`ICHIMOKU`,name:`Ichimoku`,pane:`main`,precision:`price`,params:{conversion:X(9,`Conversion Line Length`),base:X(26,`Base Line Length`),spanB:X(52,`Leading Span B Length`),displacement:X(26,`Displacement`)},outputs:({displacement:e})=>{let t=e-1,n=(e,n)=>({key:e,label:n,plot:{kind:`hidden`},offset:t,legend:!1});return[Y(`conversionLine`,`Conversion Line`),Y(`baseLine`,`Base Line`),{...Y(`laggingSpan`,`Lagging Span`),offset:-t},{...Y(`leadingSpanA`,`Leading Span A`),themeColor:`up`,offset:t},{...Y(`leadingSpanB`,`Leading Span B`),themeColor:`down`,offset:t},n(`kumoCloudUpperLine`,`Kumo Cloud Upper Line`),n(`kumoCloudLowerLine`,`Kumo Cloud Lower Line`)]},fills:()=>[{from:`leadingSpanA`,to:`leadingSpanB`,colorBy:`higher`}],create:({conversion:e,base:t,spanB:n})=>new q_(new G(e),new G(t),new G(n))};var Y_=class e{start;increment;maximum;out=/* @__PURE__ */ new Float64Array(1);state={index:0,sar:NaN,extreme:NaN,acceleration:NaN,rising:!1,close:NaN,high:NaN,low:NaN,high2:NaN,low2:NaN};constructor(e,t,n){this.start=e,this.increment=t,this.maximum=n}next(e){let t=this.state,n=t.index===1;return n&&(t.rising=e.close>t.close,t.extreme=t.rising?e.high:e.low,t.sar=t.rising?t.low:t.high,t.acceleration=this.start),t.sar+=t.acceleration*(t.extreme-t.sar),(t.rising?t.sar>e.low:t.sar<e.high)&&(n=!0,t.sar=t.rising?Math.max(e.high,t.extreme):Math.min(e.low,t.extreme),t.rising=!t.rising,t.extreme=t.rising?e.high:e.low,t.acceleration=this.start),!n&&(t.rising?e.high>t.extreme:e.low<t.extreme)&&(t.extreme=t.rising?e.high:e.low,t.acceleration=Math.min(t.acceleration+this.increment,this.maximum)),t.sar=t.rising?Math.min(t.sar,t.low,t.index>1?t.low2:t.low):Math.max(t.sar,t.high,t.index>1?t.high2:t.high),this.out[0]=t.sar,t.index+=1,t.close=e.close,t.high2=t.high,t.low2=t.low,t.high=e.high,t.low=e.low,this.out}clone(){let t=new e(this.start,this.increment,this.maximum);return t.state={...this.state},t}};let X_={type:`SAR`,name:`SAR`,pane:`main`,precision:`price`,params:{start:{default:.02,min:.001,max:1,label:`Start`},increment:{default:.02,min:.001,max:1,label:`Increment`},maximum:{default:.2,min:.001,max:1,label:`Max value`}},outputs:()=>[{key:`parabolicSar`,label:`ParabolicSAR`,plot:{kind:`marker`,shape:`circle`,size:2}}],create:({start:e,increment:t,maximum:n})=>new Y_(e,t,n)};var Z_=class e{multiplier;range;out=/* @__PURE__ */ new Float64Array(3);state={close:NaN,atr:NaN,upper:NaN,lower:NaN,trend:NaN};constructor(e,t){this.multiplier=e,this.range=t}next(e){let t=this.state,n=this.range.next(e),r=(e.high+e.low)/2,i=Number.isNaN(t.upper)?0:t.upper,a=Number.isNaN(t.lower)?0:t.lower,o=r+this.multiplier*n,s=r-this.multiplier*n;s>a||t.close<a||(s=a),o<i||t.close>i||(o=i);let c=Number.isNaN(t.atr)||(t.trend===i?e.close<=o:e.close<s),l=c?o:s,u=Number.isNaN(t.close);return this.out[0]=u||c?NaN:l,this.out[1]=u||!c?NaN:l,this.out[2]=u?NaN:(e.open+e.close)/2,this.state={close:e.close,atr:n,upper:o,lower:s,trend:l},this.out}clone(){let t=new e(this.multiplier,this.range.clone());return t.state=this.state,t}};let Q_={type:`SUPERTREND`,name:`SuperTrend`,pane:`main`,precision:`price`,params:{period:X(10,`ATR Length`),multiplier:{default:3,min:.01,max:10,label:`Factor`}},outputs:()=>[{...Y(`upTrend`,`Up Trend`),themeColor:`up`},{...Y(`downTrend`,`Down Trend`),themeColor:`down`},{key:`bodyMiddle`,label:`Body Middle`,plot:{kind:`hidden`},legend:!1}],fills:()=>[{from:`upTrend`,to:`bodyMiddle`},{from:`downTrend`,to:`bodyMiddle`}],create:({period:e,multiplier:t})=>new Z_(t,zh.of(e))};function $_(e,t){return Number.isNaN(e)?t:e}var ev=class e{highs;lows;closes;range;plusMoves;minusMoves;adx;plus;minus;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t,n,r,i,a,o,s=NaN,c=NaN){this.highs=e,this.lows=t,this.closes=n,this.range=r,this.plusMoves=i,this.minusMoves=a,this.adx=o,this.plus=s,this.minus=c}static of(t,n){return new e(new K,new K,new K,U.rma(t),U.rma(t),U.rma(t),U.rma(n))}next(e){let t=e.high-this.highs.next(e.high),n=this.lows.next(e.low)-e.low,r=this.range.next(Lh(e,this.closes.next(e.close))),i=Number.isNaN(t)?NaN:t>n&&t>0?t:0,a=Number.isNaN(n)?NaN:n>t&&n>0?n:0;this.plus=$_($(100*this.plusMoves.next(i),r),this.plus),this.minus=$_($(100*this.minusMoves.next(a),r),this.minus);let o=this.plus+this.minus;return this.out[0]=100*this.adx.next(Math.abs(this.plus-this.minus)/(o===0?1:o)),this.out[1]=this.plus,this.out[2]=this.minus,this.out}clone(){return new e(this.highs.clone(),this.lows.clone(),this.closes.clone(),this.range.clone(),this.plusMoves.clone(),this.minusMoves.clone(),this.adx.clone(),this.plus,this.minus)}};let tv={type:`DMI`,name:`DMI`,pane:`new`,precision:4,params:{adxSmoothing:X(14,`ADX Smoothing`),diLength:X(14,`DI Length`)},outputs:()=>[Y(`adx`,`ADX`),Y(`plus`,`+DI`),Y(`minus`,`-DI`)],create:({adxSmoothing:e,diLength:t})=>ev.of(t,e)};var nv=class e{fast;slow;constructor(e,t){this.fast=e,this.slow=t}next(e){return this.fast.next(e)-this.slow.next(e)}clone(){return new e(this.fast.clone(),this.slow.clone())}};let rv={type:`DMA`,name:`DMA`,pane:`new`,precision:`price`,params:{fast:X(10,`Fast`),slow:X(50,`Slow`),signal:X(10,`Signal`)},outputs:()=>[J(`DIF`),J(`DIFMA`)],create:({fast:e,slow:t,signal:n})=>new lh(new nv(new ih(e),new ih(t)),new ih(n))};var iv=class e{averages;previous;constructor(e,t=new K){this.averages=e,this.previous=t}next(e){let t=this.averages.reduce((e,t)=>t.next(e),Math.log(e));return 1e4*(t-this.previous.next(t))}clone(){return new e(this.averages.map(e=>e.clone()),this.previous.clone())}};let av={type:`TRIX`,name:`TRIX`,pane:`new`,precision:2,params:{period:X(18,`Length`)},outputs:()=>[J(`TRIX`)],levels:()=>[0],create:({period:e})=>new q([new iv([U.ema(e),U.ema(e),U.ema(e)])],(e,t)=>t)};function ov(e,t){let n=0;for(let r=1;r<e.length;r+=1)t*e.at(r)>=t*e.at(n)&&(n=r);return e.length-1-n}var sv=class e{period;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new V(e+1),n=new V(e+1)){this.period=e,this.highs=t,this.lows=n}next(e){return this.highs.push(e.high),this.lows.push(e.low),this.highs.full?(this.out[0]=100*(this.period-ov(this.highs,1))/this.period,this.out[1]=100*(this.period-ov(this.lows,-1))/this.period,this.out):(this.out.fill(NaN),this.out)}clone(){return new e(this.period,this.highs.clone(),this.lows.clone())}};let cv={type:`AROON`,name:`Aroon`,pane:`new`,precision:2,params:{period:X(14,`Length`)},outputs:()=>[{...Y(`aroonUp`,`Aroon Up`),themeColor:`up`},{...Y(`aroonDown`,`Aroon Down`),themeColor:`down`}],range:{min:0,max:100},create:({period:e})=>new sv(e)};var lv=class e{multiplier;extremes;range;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n){this.multiplier=e,this.extremes=t,this.range=n}next(e){let t=this.multiplier*this.range.next(e);return this.extremes.push(e.high,e.low),this.out[0]=this.extremes.highest()-t,this.out[1]=this.extremes.lowest()+t,this.out}clone(){return new e(this.multiplier,this.extremes.clone(),this.range.clone())}};let uv={type:`CHANDELIER`,name:`Chandelier`,pane:`main`,precision:`price`,params:{period:X(22,`Length`),atrPeriod:X(22,`ATR length`),multiplier:{default:3,min:0,max:100,label:`ATR multiplier`}},outputs:()=>[{...Y(`longExit`,`Long exit`),themeColor:`up`},{...Y(`shortExit`,`Short exit`),themeColor:`down`}],create:({period:e,atrPeriod:t,multiplier:n})=>new lv(n,new G(e),zh.of(t))},dv={type:`VOL`,name:`VOL`,pane:`new`,precision:`volume`,params:{periods:{default:[],min:1,max:2e3,integer:!0,label:`MA Length`}},outputs:({periods:e})=>[{key:`volume`,label:`Volume`,plot:{kind:`histogram`,colorBy:`bar`}},...e.map(e=>Y(`ma${String(e)}`,`MA${String(e)}`))],create:({periods:e})=>new q([ch,...e.map(e=>new H(e))],e=>e.volume)};var fv=class e{closes;total;constructor(e=new K,t=0){this.closes=e,this.total=t}next(e,t){let n=t.close-this.closes.next(t.close);return Number.isNaN(n)||(this.total+=Math.sign(n)*t.volume),this.total}clone(){return new e(this.closes.clone(),this.total)}};let pv={type:`OBV`,name:`OBV`,pane:`new`,precision:`volume`,params:yh(!1),outputs:e=>[Y(`onBalanceVolume`,`OnBalanceVolume`),...bh(`obv`,`OBV`,e)],fills:xh,create:e=>Sh.of(new fv,e)};var mv=class e{period;average;closes;up;down;flat;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n=new K,r=new W(e),i=new W(e),a=new W(e)){this.period=e,this.average=t,this.closes=n,this.up=r,this.down=i,this.flat=a}next(e){let t=e.close-this.closes.next(e.close);if(Number.isNaN(t))return this.out.fill(NaN),this.out;let n=this.up.next(t>0?e.volume:0),r=this.down.next(t<0?e.volume:0),i=this.flat.next(t===0?e.volume:0),a=$(2*n+i,2*r+i)*100;return this.out[0]=a,this.out[1]=this.average.next(a),this.out}clone(){return new e(this.period,this.average.clone(),this.closes.clone(),this.up.clone(),this.down.clone(),this.flat.clone())}};let hv={type:`VR`,name:`VR`,pane:`new`,precision:2,params:{period:X(26),signal:X(6,`Signal`)},outputs:()=>[J(`VR`),J(`MAVR`)],create:({period:e,signal:t})=>new mv(e,new ih(t))};var gv=class e{divisor;medians;constructor(e,t=new K){this.divisor=e,this.medians=t}next(e,t){let n=(t.high+t.low)/2,r=n-this.medians.next(n);return $(this.divisor*r*(t.high-t.low),t.volume)}clone(){return new e(this.divisor,this.medians.clone())}},_v=class e{ease;average;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.ease=e,this.average=t}next(e,t){return this.out[0]=this.average.next(this.ease.next(t,e)),this.out}clone(){return new e(this.ease.clone(),this.average.clone())}};let vv={type:`EMV`,name:`EMV`,pane:`new`,precision:`volume`,params:{period:X(14,`Length`),divisor:{default:1e4,min:1,max:0xe8d4a51000,integer:!0,label:`Divisor`}},outputs:()=>[Y(`eom`,`EOM`)],create:({period:e,divisor:t})=>new _v(new gv(t),new H(e))};var yv=class e{period;typicals;positive;negative;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K,n=new W(e),r=new W(e)){this.period=e,this.typicals=t,this.positive=n,this.negative=r}next(e){let t=(e.high+e.low+e.close)/3,n=t-this.typicals.next(t),r=t*e.volume,i=this.positive.next(n<=0?0:r),a=this.negative.next(n>=0?0:r);return this.out[0]=100-100/(1+$(i,a)),this.out}clone(){return new e(this.period,this.typicals.clone(),this.positive.clone(),this.negative.clone())}};let bv={type:`MFI`,name:`MFI`,pane:`new`,precision:2,params:{period:X(14,`Length`)},outputs:()=>[Y(`mf`,`MF`)],levels:()=>[80,50,20],range:{min:0,max:100},create:({period:e})=>new yv(e)};var xv=class e{period;flows;volumes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new W(e),n=new W(e)){this.period=e,this.flows=t,this.volumes=n}next(e){let t=e.high-e.low,n=t===0?0:(2*e.close-e.low-e.high)/t*e.volume;return this.out[0]=$(this.flows.next(n),this.volumes.next(e.volume)),this.out}clone(){return new e(this.period,this.flows.clone(),this.volumes.clone())}};let Sv={type:`CMF`,name:`CMF`,pane:`new`,precision:2,params:{period:X(20,`Length`)},outputs:()=>[J(`CMF`)],levels:()=>[0],create:({period:e})=>new xv(e)},Cv=[`1D`,`1W`,`1M`,`3M`,`12M`];var wv=class e{calendar;anchor;percent;bands;period;volume;sum;squares;out;constructor(e,t,n,r,i=NaN,a=0,o=0,s=0){this.calendar=e,this.anchor=t,this.percent=n,this.bands=r,this.period=i,this.volume=a,this.sum=o,this.squares=s,this.out=new Float64Array(1+r.length*2)}next(e,t){let n=this.calendar.bucket(e.time,this.anchor);n!==null&&n!==this.period&&(this.period=n,this.volume=0,this.sum=0,this.squares=0),this.volume+=e.volume,this.sum+=t*e.volume,this.squares+=t*t*e.volume;let r=this.sum/this.volume,i=this.percent?r*.01:Math.sqrt(Math.max(0,this.squares/this.volume-r*r));return this.out[0]=r,this.bands.forEach((e,t)=>{this.out[1+t*2]=r+i*e,this.out[2+t*2]=r-i*e}),this.out}clone(){return new e(this.calendar,this.anchor,this.percent,this.bands,this.period,this.volume,this.sum,this.squares)}};function Tv({band1:e,band2:t,band3:n}){return[e,t,n]}function Ev(e,t){return{default:t,min:0,max:10,label:`Bands Multiplier #${String(e)}`,legend:!1}}let Dv={type:`VWAP`,name:`VWAP`,pane:`main`,source:`hlc3`,precision:`price`,params:{anchor:Z([`Session`,`Week`,`Month`,`Quarter`,`Year`],0,`Anchor Period`),bandMode:Z([`Standard Deviation`,`Percentage`],0,`Bands Calculation Mode`,!1),band1:Ev(1,1),band2:Ev(2,0),band3:Ev(3,0)},outputs:e=>[Y(`vwap`,`VWAP`),...Tv(e).flatMap((e,t)=>e>0?[Y(`upperBand${String(t+1)}`,`Upper Band #${String(t+1)}`),Y(`lowerBand${String(t+1)}`,`Lower Band #${String(t+1)}`)]:[])],fills:e=>Tv(e).flatMap((e,t)=>e>0?[{from:`upperBand${String(t+1)}`,to:`lowerBand${String(t+1)}`}]:[]),create:(e,{calendar:t})=>new wv(t,Q(Cv,e.anchor,`VWAP anchor`),Q([!1,!0],e.bandMode,`VWAP band mode`),Tv(e).filter(e=>e>0))};function Ov(e){let t=e.high-e.low;return t===0?0:(2*e.close-e.low-e.high)/t*e.volume}var kv=class e{total;constructor(e=0){this.total=e}next(e,t){return this.total+=Ov(t),this.total}clone(){return new e(this.total)}};let Av={type:`AD`,name:`Accum/Dist`,pane:`new`,precision:`volume`,params:{},outputs:()=>[Y(`accumulationDistribution`,`Accumulation/Distribution`)],create:()=>new q([new kv],(e,t)=>t)};var jv=class e{line;fast;slow;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t,n){this.line=e,this.fast=t,this.slow=n}next(e,t){let n=this.line.next(t,e);return this.out[0]=this.fast.next(n)-this.slow.next(n),this.out}clone(){return new e(this.line.clone(),this.fast.clone(),this.slow.clone())}};let Mv={type:`CHAIKINOSC`,name:`Chaikin Osc`,pane:`new`,precision:`volume`,params:{fast:X(3,`Fast length`),slow:X(10,`Slow length`)},outputs:()=>[Y(`chaikinOscillator`,`Chaikin Oscillator`)],levels:()=>[0],create:({fast:e,slow:t})=>new jv(new kv,U.ema(e),U.ema(t))};var Nv=class e{short;long;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t){this.short=e,this.long=t}next(e){let t=this.short.next(e.volume),n=this.long.next(e.volume);return this.out[0]=$(t-n,n)*100,this.out}clone(){return new e(this.short.clone(),this.long.clone())}};let Pv={type:`VO`,name:`Volume Osc`,pane:`new`,precision:2,params:{short:X(5,`Short Length`),long:X(10,`Long Length`)},outputs:()=>[Y(`volumeOsc`,`Volume Osc`)],levels:()=>[0],create:({short:e,long:t})=>new Nv(U.ema(e),U.ema(t))};var Fv=class e{average;closes;out=/* @__PURE__ */ new Float64Array(1);constructor(e,t=new K){this.average=e,this.closes=t}next(e){let t=e.close-this.closes.next(e.close);return this.out[0]=this.average.next(t*e.volume),this.out}clone(){return new e(this.average.clone(),this.closes.clone())}};let Iv={type:`EFI`,name:`EFI`,pane:`new`,precision:`volume`,params:{period:X(13,`Length`)},outputs:()=>[Y(`elderForceIndex`,`Elder Force Index`)],levels:()=>[0],create:({period:e})=>new Fv(U.ema(e))};var Lv=class e{fast;slow;signal;typicals;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r=new K){this.fast=e,this.slow=t,this.signal=n,this.typicals=r}next(e){let t=(e.high+e.low+e.close)/3,n=t-this.typicals.next(t)>=0?e.volume:-e.volume,r=this.fast.next(n)-this.slow.next(n);return this.out[0]=r,this.out[1]=this.signal.next(r),this.out}clone(){return new e(this.fast.clone(),this.slow.clone(),this.signal.clone(),this.typicals.clone())}};let Rv={type:`KVO`,name:`KVO`,pane:`new`,precision:`volume`,params:{fast:X(34,`Fast length`),slow:X(55,`Slow length`),signal:X(13,`Signal length`)},outputs:()=>[Y(`klingerOscillator`,`Klinger Oscillator`),Y(`signalLine`,`Signal line`)],create:({fast:e,slow:t,signal:n})=>new Lv(U.ema(e),U.ema(t),U.ema(n))};var zv=class e{closes;total;constructor(e=new K,t=0){this.closes=e,this.total=t}next(e,t){let n=this.closes.next(t.close),r=$(t.close-n,n)*t.volume;return Number.isNaN(r)||(this.total+=r),this.total}clone(){return new e(this.closes.clone(),this.total)}};let Bv={type:`PVT`,name:`PVT`,pane:`new`,precision:`volume`,params:{},outputs:()=>[J(`PVT`)],create:()=>new q([new zv],(e,t)=>t)};var Vv=class e{sum;average;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t){this.sum=e,this.average=t}next(e){let t=e.high-e.low,n=t===0?0:(e.close-e.open)/t*e.volume,r=this.sum.next(n)/1e4;return this.out[0]=r,this.out[1]=this.average.next(r),this.out}clone(){return new e(this.sum.clone(),this.average.clone())}};let Hv={type:`WVAD`,name:`WVAD`,pane:`new`,precision:`volume`,params:{period:X(24),signal:X(6,`Signal`)},outputs:()=>[J(`WVAD`),J(`MAWVAD`)],create:({period:e,signal:t})=>new Vv(new W(e),new ih(t))};function Uv(e,t){return{default:e,min:0,max:500,integer:!0,label:t}}let Wv={type:`ALLIGATOR`,name:`Alligator`,pane:`main`,source:`hl2`,precision:`price`,params:{jaw:X(13,`Jaw Length`),teeth:X(8,`Teeth Length`),lips:X(5,`Lips Length`),jawShift:Uv(8,`Jaw Offset`),teethShift:Uv(5,`Teeth Offset`),lipsShift:Uv(3,`Lips Offset`)},outputs:({jawShift:e,teethShift:t,lipsShift:n})=>[{...Y(`jaw`,`Jaw`),offset:e},{...Y(`teeth`,`Teeth`),offset:t},{...Y(`lips`,`Lips`),offset:n}],create:({jaw:e,teeth:t,lips:n})=>new q([e,t,n].map(e=>U.rma(e)),(e,t)=>t)};function Gv(e,t,n){let r=n*e.fromEnd(t);for(let i=0;i<t;i+=1)if(!(n*e.fromEnd(i)<r))return!1;for(let i=0;i<=4;i+=1){let a=!0;for(let o=1;o<=i+t&&a;o+=1){let s=n*e.fromEnd(t+o);a=o<=i?s<=r:s<r}if(a)return!0}return!1}var Kv=class e{period;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t=new V(2*e+4+1),n=new V(2*e+4+1)){this.period=e,this.highs=t,this.lows=n}next(e){this.highs.push(e.high),this.lows.push(e.low);let{period:t}=this;return this.out[0]=Gv(this.lows,t,-1)?this.lows.fromEnd(t):NaN,this.out[1]=Gv(this.highs,t,1)?this.highs.fromEnd(t):NaN,this.out}clone(){return new e(this.period,this.highs.clone(),this.lows.clone())}};let qv={type:`FRACTALS`,name:`Fractals`,pane:`main`,precision:`price`,params:{period:{default:2,min:2,max:50,integer:!0,label:`Periods`}},outputs:({period:e})=>[{key:`downFractal`,label:`Down fractal`,plot:{kind:`marker`,shape:`triangle-up`,size:4},themeColor:`down`,offset:-e},{key:`upFractal`,label:`Up fractal`,plot:{kind:`marker`,shape:`triangle-down`,size:4},themeColor:`up`,offset:-e}],create:({period:e})=>new Kv(e)};var Jv=class e{share;mean;out=/* @__PURE__ */ new Float64Array(3);constructor(e,t){this.share=e,this.mean=t}next(e,t){let n=this.mean.next(t,e);return this.out[0]=n,this.out[1]=n*(1+this.share),this.out[2]=n*(1-this.share),this.out}clone(){return new e(this.share,this.mean.clone())}};let Yv={type:`ENVELOPE`,name:`Env`,pane:`main`,precision:`price`,params:{period:X(20,`Length`),percent:{default:10,min:0,max:100,label:`Percent`},exponential:ph(!1,`Exponential`,!1)},outputs:()=>[Y(`basis`,`Basis`),Y(`upper`,`Upper`),Y(`lower`,`Lower`)],fills:()=>[{from:`upper`,to:`lower`}],create:({period:e,percent:t,exponential:n})=>new Jv(t/100,_h(n===1?`ema`:`sma`,e))};function Xv(){return new oh(4,2)}var Zv=class e{typical;previous;extremes;high;low;lines;out=/* @__PURE__ */ new Float64Array(6);constructor(e,t,n,r,i,a){this.typical=e,this.previous=t,this.extremes=n,this.high=r,this.low=i,this.lines=a}static of(t){return new e(new ih(t),new K,new G(t),Xv(),Xv(),Array.from({length:6},Xv))}next(e){let t=this.previous.next(this.typical.next((e.high+e.low+e.close)/3));this.extremes.push(e.high,e.low);let n=this.high.next(this.extremes.highest()),r=this.low.next(this.extremes.lowest()),i=[2*n-r,t+n-r,t*2-r,t*2-n,t-n+r,2*r-n];return this.lines.forEach((e,t)=>{this.out[t]=e.next(i[t]??NaN)}),this.out}clone(){return new e(this.typical.clone(),this.previous.clone(),this.extremes.clone(),this.high.clone(),this.low.clone(),this.lines.map(e=>e.clone()))}};let Qv={type:`MIKE`,name:`MIKE`,pane:`main`,precision:`price`,params:{period:X(10)},outputs:()=>[`STOR`,`MIDR`,`WEKR`,`WEKS`,`MIDS`,`STOS`].map(J),create:({period:e})=>Zv.of(e)};var $v=class e{weights;averages;constructor(e,t){this.weights=e,this.averages=t}static of(t,n){return new e(n,n.map(()=>U.ema(t)))}next(e){let t=e,n=0;return this.averages.forEach((e,r)=>{t=e.next(t),n+=(this.weights[r]??0)*t}),n}clone(){return new e(this.weights,this.averages.map(e=>e.clone()))}};let ey={type:`DEMA`,name:`DEMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`)},outputs:()=>[J(`DEMA`)],create:({period:e})=>new q([$v.of(e,[2,-1])],(e,t)=>t)},ty={type:`TEMA`,name:`TEMA`,pane:`main`,precision:`price`,params:{period:X(9,`Length`)},outputs:()=>[J(`TEMA`)],create:({period:e})=>new q([$v.of(e,[3,-3,1])],(e,t)=>t)};var ny=class e{offset;window;spread;constructor(e,t){this.offset=e,this.window=t;let n=t.capacity;this.spread=n*(n*n-1)/12}next(e){if(this.window.push(e),!this.window.full)return NaN;let t=this.window.capacity,n=(t-1)/2,r=this.window.sum()/t,i=0;for(let e=0;e<t;e+=1)i+=(e-n)*(this.window.at(e)-r);return r+i/this.spread*(t-1-this.offset-n)}clone(){return new e(this.offset,this.window.clone())}};let ry={type:`LSMA`,name:`LSMA`,pane:`main`,precision:`price`,params:{period:{default:25,min:2,max:2e3,integer:!0,label:`Length`},offset:{default:0,min:-2e3,max:2e3,integer:!0,label:`Offset`}},outputs:()=>[J(`LSMA`)],create:({period:e,offset:t})=>new q([new ny(t,new V(e))],(e,t)=>t)};var iy=class e{period;seed;value;constructor(e,t,n=NaN){this.period=e,this.seed=t,this.value=n}next(e){return this.value=Number.isNaN(this.value)?this.seed.next(e):this.value+(e-this.value)/(this.period*(e/this.value)**4),this.value}clone(){return new e(this.period,this.seed.clone(),this.value)}};let ay={type:`MCGINLEY`,name:`McGinley Dynamic`,pane:`main`,precision:`price`,params:{period:X(14,`Length`)},outputs:()=>[J(`McGinley`)],create:({period:e})=>new q([new iy(e,U.ema(e))],(e,t)=>t)},oy=[`sma`,`ema`,`rma`,`wma`,`vwma`],sy=[20,50,100,200];function cy(e){return[[e.maType1,e.period1],[e.maType2,e.period2],[e.maType3,e.period3],[e.maType4,e.period4]]}function ly(){let e=e=>Z([`SMA`,`EMA`,`SMMA (RMA)`,`WMA`,`VWMA`],0,`Type #${String(e)}`),t=e=>X(sy[e-1]??0,`Length #${String(e)}`);return{maType1:e(1),period1:t(1),maType2:e(2),period2:t(2),maType3:e(3),period3:t(3),maType4:e(4),period4:t(4)}}let uy={type:`RIBBON`,name:`MA Ribbon`,pane:`main`,precision:`price`,params:ly(),outputs:()=>[1,2,3,4].map(e=>Y(`ma${String(e)}`,`MA №${String(e)}`)),create:e=>new q(cy(e).map(([e,t])=>_h(Q(oy,e,`ribbon average`),t)),(e,t)=>t)};var dy=class e{multiplier;range;closes;out=/* @__PURE__ */ new Float64Array(2);state={max:NaN,min:NaN,up:!0,stop:NaN};constructor(e,t,n=new K){this.multiplier=e,this.range=t,this.closes=n}next(e,t){let n=this.state,r=this.closes.next(e.close),i=this.range.next(e),a=Number.isNaN(i)?Lh(e,r):i*this.multiplier,o=Number.isNaN(n.max)?t:Math.max(n.max,t),s=Number.isNaN(n.min)?t:Math.min(n.min,t),c=n.up?Math.max(n.stop,o-a):Math.min(n.stop,s+a);c=Number.isNaN(c)?t:c;let l=t-c>=0;return l!==n.up&&(o=t,s=t,c=l?o-a:s+a),this.out[0]=l?c:NaN,this.out[1]=l?NaN:c,this.state={max:o,min:s,up:l,stop:c},this.out}clone(){let t=new e(this.multiplier,this.range.clone(),this.closes.clone());return t.state=this.state,t}};function fy(e,t,n){return{key:e,label:t,plot:{kind:`marker`,shape:`circle`,size:2},themeColor:n}}let py={type:`VSTOP`,name:`VStop`,pane:`main`,precision:`price`,params:{period:{default:20,min:2,max:2e3,integer:!0,label:`Length`},multiplier:{default:2,min:.25,max:100,label:`Multiplier`}},outputs:()=>[fy(`upTrend`,`Up Trend`,`up`),fy(`downTrend`,`Down Trend`,`down`)],create:({period:e,multiplier:t})=>new dy(t,zh.of(e))};var my=class e{multiplier;extremes;range;stops;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.multiplier=e,this.extremes=t,this.range=n,this.stops=r}next(e){let t=this.multiplier*this.range.next(e);return this.extremes.push(e.high,e.low),this.stops.push(this.extremes.highest()-t,this.extremes.lowest()+t),this.out[0]=this.stops.lowest(),this.out[1]=this.stops.highest(),this.out}clone(){return new e(this.multiplier,this.extremes.clone(),this.range.clone(),this.stops.clone())}};let hy={type:`CKSTOP`,name:`Chande Kroll Stop`,pane:`main`,precision:`price`,params:{period:X(10,`ATR Length`),multiplier:{default:1,min:0,max:100,label:`ATR Coefficient`},stopPeriod:X(9,`Stop Length`)},outputs:()=>[{...Y(`stopLong`,`Stop Long`),themeColor:`up`},{...Y(`stopShort`,`Stop Short`),themeColor:`down`}],create:({period:e,multiplier:t,stopPeriod:n})=>new my(t,new G(e),zh.of(e),new G(n))};function gy(e){return{default:10,min:1,max:500,integer:!0,label:e}}function _y(e,t,n){if(!e.full)return NaN;let r=e.fromEnd(t);for(let i=0;i<e.length;i+=1){let a=n*e.fromEnd(i);if(i<t?a>=n*r:i>t&&a>n*r)return NaN}return r}var vy=class e{highRight;lowRight;highs;lows;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r){this.highRight=e,this.lowRight=t,this.highs=n,this.lows=r}next(e){return this.highs.push(e.high),this.lows.push(e.low),this.out[0]=_y(this.highs,this.highRight,1),this.out[1]=_y(this.lows,this.lowRight,-1),this.out}clone(){return new e(this.highRight,this.lowRight,this.highs.clone(),this.lows.clone())}};let yy={type:`PIVOTHL`,name:`Pivots HL`,pane:`main`,precision:`price`,params:{highLeft:gy(`Pivot High Left`),highRight:gy(`Pivot High Right`),lowLeft:gy(`Pivot Low Left`),lowRight:gy(`Pivot Low Right`)},outputs:({highRight:e,lowRight:t})=>[{key:`pivotHigh`,label:`Pivot High`,plot:{kind:`marker`,shape:`triangle-down`,size:4,value:!0},themeColor:`up`,offset:-e},{key:`pivotLow`,label:`Pivot Low`,plot:{kind:`marker`,shape:`triangle-up`,size:4,value:!0},themeColor:`down`,offset:-t}],create:({highLeft:e,highRight:t,lowLeft:n,lowRight:r})=>new vy(t,r,new V(e+t+1),new V(n+r+1))};function by(e,t,n){if(!e.full)return NaN;let r=e.fromEnd(t);for(let i=0;i<e.length;i+=1){let a=n*e.fromEnd(i);if(i<t?a>n*r:i>t&&a>=n*r)return NaN}return r}function xy(e){return Math.max(2,Math.floor(e/2))}var Sy=class e{deviation;half;highs;lows;out=/* @__PURE__ */ new Float64Array(3);state={high:!1,price:NaN};constructor(e,t,n,r){this.deviation=e,this.half=t,this.highs=n,this.lows=r}next(e){this.highs.push(e.high),this.lows.push(e.low);let t=by(this.highs,this.half,1),n=by(this.lows,this.half,-1);this.out[1]=this.takes(!0,t)?t:NaN,this.out[2]=this.takes(!1,n)?n:NaN;let{high:r,price:i}=this.state;return this.out[0]=Number.isNaN(i)?NaN:r?e.low:e.high,this.out}takes(e,t){if(Number.isNaN(t))return!1;let n=this.state,r=100*(t-n.price)/Math.abs(n.price),i=Number.isNaN(n.price)?!0:n.high===e?(e?t-n.price:n.price-t)>0:(e?r:-r)>=this.deviation;return i&&(this.state={high:e,price:t}),i}clone(){let t=new e(this.deviation,this.half,this.highs.clone(),this.lows.clone());return t.state=this.state,t}};let Cy={type:`ZIGZAG`,name:`Zig Zag`,pane:`main`,precision:`price`,params:{deviation:{default:5,min:.01,max:100,label:`Price deviation for reversals (%)`},depth:{default:10,min:2,max:1e3,integer:!0,label:`Pivot legs`},extend:ph(!0,`Extend to last bar`,!1),showPrice:ph(!0,`Display reversal price`,!1),showVolume:ph(!0,`Display cumulative volume`,!1),showChange:ph(!0,`Display reversal price change`,!1),changeMode:Z([`Absolute`,`Percent`],0,`Price change`,!1)},outputs:({depth:e,extend:t,showPrice:n,showVolume:r,showChange:i,changeMode:a})=>{let o=-xy(e);return[{key:`zigZag`,label:`Zig Zag`,plot:{kind:`zigzag`,high:`high`,low:`low`,extend:t===1,labels:{price:n===1,change:i===1?a===1?`percent`:`absolute`:null,volume:r===1}},legend:!1},{key:`high`,label:`Pivot High`,plot:{kind:`hidden`},offset:o,legend:!1},{key:`low`,label:`Pivot Low`,plot:{kind:`hidden`},offset:o,legend:!1}]},create:({deviation:e,depth:t})=>{let n=xy(t);return new Sy(e,n,new V(2*n+1),new V(2*n+1))}};var wy=class e{highs;lows;ranges;upward;downward;range;out=/* @__PURE__ */ new Float64Array(2);constructor(e,t,n,r,i,a){this.highs=e,this.lows=t,this.ranges=n,this.upward=r,this.downward=i,this.range=a}static of(t){return new e(new K,new K,new Rh,new W(t),new W(t),new W(t))}next(e){let t=this.upward.next(Math.abs(e.high-this.lows.next(e.low))),n=this.downward.next(Math.abs(e.low-this.highs.next(e.high))),r=this.range.next(this.ranges.next(e));return this.out[0]=$(t,r),this.out[1]=$(n,r),this.out}clone(){return new e(this.highs.clone(),this.lows.clone(),this.ranges.clone(),this.upward.clone(),this.downward.clone(),this.range.clone())}};let Ty=[Ch,wh,Th,Yh,J_,dv,hg,_g,yg,xg,Cg,Tg,Dg,pv,hv,vv,bv,Hh,Uh,tv,Dv,X_,Q_,$h,tg,Eh,Oh,Ah,Nh,Ph,Ih,rv,av,cv,uv,kg,jg,Ng,Fg,Rg,Bg,Hg,Sv,Gh,Wv,qv,w_,E_,D_,R_,Av,Pv,M_,Mv,Iv,Rv,Bv,Hv,ig,og,ug,fg,Wg,Kg,Jg,Zg,e_,n_,a_,s_,u_,d_,h_,V_,G_,ey,ty,ry,ay,uy,Yv,py,hy,{type:`VORTEX`,name:`VI`,pane:`new`,precision:4,params:{period:{default:14,min:2,max:2e3,integer:!0,label:`Length`}},outputs:()=>[Y(`viPlus`,`VI +`),Y(`viMinus`,`VI -`)],create:({period:e})=>wy.of(e)},yy,Qv,Cy];function Ey(e,t){return{start:(n,r)=>{e.run(()=>{t.start(n,r)})},stop:()=>{e.run(()=>{t.stop()})},play:()=>{e.run(()=>{t.play()})},pause:()=>{e.run(()=>{t.pause()})},step:n=>e.run(()=>t.step(n)),seek:n=>{e.run(()=>{t.seek(n)})},configure:n=>{e.run(()=>{t.configure(n)})},state:()=>t.state()}}let Dy={speed:1,step:`bar`},Oy=g({speed:!0,step:!0});function ky(e,t){_(`replay settings`,t,Oy);let n={...e,...t};return d(`replay.speed`,n.speed,{min:0,exclusiveMin:!0,max:1e3}),m(`replay.step`,n.step,[`bar`,`source`]),n}var Ay=class{host;cursor=null;settings=Dy;timer=0;constructor(e){this.host=e}get active(){return this.cursor!==null}state(){return this.cursor===null?null:{...this.settings,time:this.cursor,playing:this.timer!==0,ended:this.host.market.feed.nextCutoff(this.cursor,!1)===null}}start(e,t={}){let r=a(e,`replay start`),o=ky(this.settings,t),s=this.host.market.firstSourceTime();s===null&&n(`Replay needs data: set bars before starting it.`),r<s&&n(`replay start ${i(e)} is before the first bar; start at or after the first bar.`),this.pause(),this.settings=o,this.cursor=r,this.host.reveal(r,!0)}stop(){this.cursor!==null&&(this.pause(),this.cursor=null,this.host.reveal(1/0,!0))}play(){this.require(`play()`),this.timer===0&&this.schedule()}pause(){this.timer!==0&&(this.host.view.clearTimeout(this.timer),this.timer=0)}step(e=1){let t=this.require(`step()`);d(`replay step count`,e,{min:1,integer:!0});let n=t,r=0;for(;r<e;r+=1){let e=this.host.market.feed.nextCutoff(n,this.settings.step===`bar`);if(e===null)break;n=e}return r>0&&(this.cursor=n,this.host.reveal(n,!1)),r}seek(e){this.require(`seek()`);let t=a(e,`replay time`),r=this.host.market.firstSourceTime();r!==null&&t<r&&n(`replay time ${i(e)} is before the first bar.`),this.cursor=t,this.host.reveal(t,!0)}configure(e){this.settings=ky(this.settings,e),this.timer!==0&&(this.pause(),this.schedule())}reset(){this.pause(),this.cursor=null}require(e){return this.cursor??n(`replay.${e} needs a running replay: call replay.start() first.`)}schedule(){this.timer=this.host.view.setTimeout(()=>{this.timer=0,this.host.played(()=>this.tick())},1e3/this.settings.speed)}tick(){let e=this.cursor!==null&&this.step()>0,t=this.state();return t?!e||t.ended?{state:t,reason:`end`}:(this.schedule(),{state:{...t,playing:!0},reason:`step`}):n(`Replay stopped during a step.`)}};function jy(){return _o({name:`replay`,install:e=>{let t=e.events(),n=new Ay({view:e.view,market:e.market,reveal:(t,n)=>{e.reveal(t,n)},played:n=>{e.run(()=>{t.emit(`replay`,n())})}});return e.hooks.dataCleared.push(()=>{n.reset()}),e.hooks.destroyed.push(()=>{n.reset()}),{replay:Ey(e,n)}}})}let My=[`above`,`below`,`price`],Ny=g({id:!0,time:!0,position:!0,price:!0,shape:!0,color:!0,text:!0,size:!0,outline:!0,link:!0});function Py(e,t=`marker`){_(t,e,Ny);let r=m(`${t}.position`,e.position,My);return r===`price`&&e.price===void 0&&n(`${t}.price is required with position "price".`),e.text!==void 0&&typeof e.text!=`string`&&n(`${t}.text must be a string.`),{time:a(e.time,`${t}.time`),position:r,price:e.price===void 0?null:d(`${t}.price`,e.price),shape:m(`${t}.shape`,e.shape,_r),color:e.color===void 0?null:S(`${t}.color`,e.color),text:e.text??``,size:e.size===void 0?8:d(`${t}.size`,e.size,{min:2,max:40}),outline:e.outline===void 0?null:S(`${t}.outline`,e.outline),link:e.link===void 0?null:p(`${t}.link`,e.link)}}function Fy(e){return{time:e.time,position:e.position,shape:e.shape,text:e.text,size:e.size,...e.price===null?{}:{price:e.price},...e.color===null?{}:{color:e.color},...e.outline===null?{}:{outline:e.outline},...e.link===null?{}:{link:e.link}}}function Iy(e,t){let n=vr(t.shape),{theme:r}=e.options;return t.color??(n>0?r.buy:n<0?r.sell:r.text)}function Ly(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;(e[i]?.time??NaN)<t?n=i+1:r=i}return n}var Ry=class{kind=`marker`;markers=/* @__PURE__ */ new Map;ids=new de(e=>this.markers.has(e));sorted=null;has(e){return this.markers.has(e)}list(){return[...this.markers.values()]}get(e){return this.markers.get(e)??null}set(e){this.markers=wo(`markers`,e,this.ids,`marker`,Py),this.sorted=null}add(e){let t=Py(e),r=e.id===void 0?this.ids.next(`marker`):p(`marker.id`,e.id);return this.markers.has(r)&&n(`A marker with id "${r}" already exists.`),this.markers.set(r,{id:r,...t}),this.ids.note(r),this.sorted=null,r}update(e,t){let r=this.markers.get(e)??n(`Unknown marker "${e}".`);this.markers.set(e,{id:e,...Py({...Fy(r),...t})}),this.sorted=null}remove(e){this.markers.delete(e)||n(`Unknown marker "${e}".`),this.sorted=null}between(e,t,n){let{bars:r}=e,i=r.length-1,a=e.resolution===`untimed`?null:r.interval(),o=n<i?r.time(n+1):a===null?1/0:r.time(i)+a;return this.sorted??=[...this.markers.values()].sort((e,t)=>e.time-t.time),this.sorted.slice(Ly(this.sorted,r.time(t)),Ly(this.sorted,o))}place(e){let t=O(e.frame,x),n=e.frame.visible;if(!t||!n||this.markers.size===0)return[];let{bars:r,timeScale:i}=e,a=Math.max(0,n.from-1),o=Math.min(r.length-1,n.to+1),s=/* @__PURE__ */ new Map,c=[];for(let n of this.between(e,a,o)){if(n.time>e.cutoff)break;let a=r.indexAt(n.time),o=i.indexToX(a),l=`${a}:${n.position}`,u=s.get(l)??0;s.set(l,u+n.size*2+4);let d;d=n.position===`above`?t.scale.valueToY(r.high(a))-4-n.size-u:n.position===`below`?t.scale.valueToY(r.low(a))+4+n.size+u:t.scale.valueToY(n.price??NaN),c.push({marker:n,x:o,y:d,color:Iy(e,n)})}return c}links(e,t){let n=O(e.frame,x),{bars:r,timeScale:i}=e;if(!n||r.length===0)return[];let a=new Map(t.map(e=>[e.marker.id,e])),o=t=>{let o=a.get(t.id);if(o)return{x:o.x,y:o.y};let s=r.indexAt(t.time);if(s<0||t.time>e.cutoff)return null;let c=t.position===`above`?n.scale.valueToY(r.high(s))-4-t.size:t.position===`below`?n.scale.valueToY(r.low(s))+4+t.size:n.scale.valueToY(t.price??NaN);return{x:i.indexToX(s),y:c}},s=[];for(let t of this.markers.values()){let n=t.link===null?void 0:this.markers.get(t.link),r=n&&o(n),i=n&&o(t);n&&r&&i&&s.push({from:r,to:i,color:a.get(n.id)?.color??Iy(e,n),outline:n.outline})}return s}hitTest(e,t){let n=O(e.frame,x);if(!n)return null;let r={x:t.x-n.plot.x,y:t.y-n.plot.y},i=null;for(let t of this.place(e)){let e=Math.hypot(r.x-t.x,r.y-t.y);e<=t.marker.size+3&&(i===null||e<i.distance)&&(i={target:{kind:`marker`,id:t.marker.id,part:`body`,cursor:`pointer`,draggable:!1},priority:Ji.body,distance:e})}return i}beginDrag(){return null}paint(e){let t=O(e.frame,x);if(!t)return;let{ctx:n,options:r}=e;n.save(),n.beginPath(),n.rect(t.plot.x,t.plot.y,t.plot.width,t.plot.height),n.clip(),n.translate(t.plot.x,t.plot.y),n.font=E(r.font.size-1,r.font.family),n.textAlign=`center`;let i=this.place(e);for(let{from:t,to:r,color:a,outline:o}of this.links(e,i))n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(r.x,r.y),o!==null&&(w(n,o,3),n.setLineDash(gn(`dashed`,1)),n.stroke()),w(n,a,1,`dashed`),n.stroke();for(let{marker:t,x:r,y:a,color:o}of i){let i=e.selection?.kind===`marker`&&e.selection.id===t.id||e.hovered?.kind===`marker`&&e.hovered.id===t.id,s=t.size*(i?1.25:1);if(n.fillStyle=o,n.beginPath(),yr(n,t.shape,r,a,s),n.fill(),t.outline!==null&&(w(n,t.outline,1),n.stroke()),t.text){let e=t.position===`below`;n.textBaseline=e?`top`:`bottom`,n.fillText(t.text,r,e?a+s+2:a-s-2)}}n.restore()}};let zy=g({id:!0,price:!0,side:!0,label:!0,quantity:!0,draggable:!0,pull:!0,visible:!0,color:!0,lineStyle:!0,buttons:!0,labelAlign:!0,axisLabel:!0,tooltip:!0});function By(e,t=`order`){return _(t,e,zy),e.label!==void 0&&p(`${t}.label`,e.label),e.quantity!==void 0&&typeof e.quantity!=`string`&&d(`${t}.quantity`,e.quantity),e.tooltip!==void 0&&p(`${t}.tooltip`,e.tooltip),{price:d(`${t}.price`,e.price),side:m(`${t}.side`,e.side,[`buy`,`sell`]),label:e.label??null,quantity:e.quantity??null,draggable:e.draggable===void 0||f(`${t}.draggable`,e.draggable),pull:e.pull!==void 0&&f(`${t}.pull`,e.pull),visible:e.visible===void 0||f(`${t}.visible`,e.visible),color:e.color===void 0?null:S(`${t}.color`,e.color),lineStyle:e.lineStyle===void 0?`dashed`:m(`${t}.lineStyle`,e.lineStyle,ln),buttons:ea(e.buttons,`${t}.buttons`),labelAlign:e.labelAlign===void 0?`right`:m(`${t}.labelAlign`,e.labelAlign,ta),axisLabel:e.axisLabel===void 0||f(`${t}.axisLabel`,e.axisLabel),tooltip:e.tooltip===void 0||e.tooltip===``?null:e.tooltip}}function Vy(e){return{price:e.price,side:e.side,draggable:e.draggable,pull:e.pull,visible:e.visible,lineStyle:e.lineStyle,buttons:e.buttons.map(e=>({...e})),labelAlign:e.labelAlign,axisLabel:e.axisLabel,...e.label===null?{}:{label:e.label},...e.quantity===null?{}:{quantity:e.quantity},...e.color===null?{}:{color:e.color},...e.tooltip===null?{}:{tooltip:e.tooltip}}}var Hy=class{host;kind=`order`;orders=/* @__PURE__ */ new Map;ids=new de(e=>this.orders.has(e));icons=new Li;constructor(e){this.host=e}has(e){return this.orders.has(e)}list(){return[...this.orders.values()]}get(e){return this.orders.get(e)??null}require(e){return this.orders.get(e)??n(`Unknown order "${e}".`)}set(e){this.orders=wo(`orders`,e,this.ids,`order`,By)}add(e){let t=By(e),r=e.id===void 0?this.ids.next(`order`):p(`order.id`,e.id);return this.orders.has(r)&&n(`An order with id "${r}" already exists.`),this.orders.set(r,{id:r,...t}),this.ids.note(r),r}update(e,t){let n=this.require(e);this.orders.set(e,{id:e,...By({...Vy(n),...t})})}remove(e){this.require(e),this.orders.delete(e)}layouts(e,t){let{theme:n,font:r}=e.options,i=[];for(let r of this.orders.values()){if(!r.visible)continue;let a=r.label??(r.side===`buy`?`BUY`:`SELL`),o=e.selection?.kind===`order`&&e.selection.id===r.id;i.push({id:r.id,y:t.scale.valueToY(r.price),color:r.color??(r.side===`buy`?n.buy:n.sell),text:r.quantity===null?a:`${a} ${String(r.quantity)}`,axisText:r.axisLabel?this.host.formatValue(t,r.price):null,buttons:r.buttons,lineStyle:r.lineStyle,emphasized:o,align:r.labelAlign})}return ia(i,t.plot.width,t.plot.height,r.size,(t,n)=>e.measureText(t,E(n,r.family)),e.options.priceScale.pinLabels)}hitTest(e,t){let n=O(e.frame,x);if(!n||t.y<n.plot.y||t.y>=n.plot.y+n.plot.height)return null;let r=oa(this.layouts(e,n),{x:t.x,y:t.y-n.plot.y},e.options.interaction.hitTolerance),i=r?this.orders.get(r.id):void 0;if(!r||!i)return null;let a=r.part.startsWith(`button:`),o=i.draggable&&!a;return{target:{kind:`order`,id:i.id,part:r.part,cursor:o&&r.part===`line`?`ns-resize`:`pointer`,draggable:o,...i.tooltip===null||a?{}:{tooltip:i.tooltip}},priority:r.priority,distance:r.distance}}reveal(e,t){let n=this.orders.get(t.id);return n?{pane:x,scale:fe,value:n.price}:null}beginDrag(e,t){let n=this.orders.get(t.id),r=O(e.frame,x);if(!n?.draggable||!r)return null;let i=n.price,a=i;this.host.dragged({id:n.id,phase:`start`,price:a,initialPrice:i});let o=e=>{let t=this.orders.get(n.id);t&&!t.pull&&(this.orders.set(n.id,{...t,price:e}),this.host.repaint())};return{move:e=>{let t=O(this.host.context().frame,x);if(!t||!this.orders.has(n.id))return;let r=e.y-t.plot.y,s=Zi(t.scale,t.format,r);Number.isFinite(s)&&s!==a&&(a=s,o(a),this.host.dragged({id:n.id,phase:`move`,price:a,initialPrice:i}))},end:()=>{this.host.dragged({id:n.id,phase:`end`,price:a,initialPrice:i})},cancel:()=>{o(i),this.host.dragged({id:n.id,phase:`cancel`,price:i,initialPrice:i})}}}paint(e){let t=O(e.frame,x);if(!t||this.orders.size===0)return;let{ctx:n}=e;n.save(),n.beginPath(),n.rect(0,t.plot.y,e.frame.layout.width,t.plot.height),n.clip(),sa(n,this.layouts(e,t),t.plot,t.axis,{fontSize:e.options.font.size,fontFamily:e.options.font.family,pixelRatio:e.pixelRatio,textColor:`#ffffff`,showAxis:e.options.priceScale.visible},this.icons),n.restore()}};function Uy(){return _o({name:`orders`,install:e=>{let t=e.events(),n=new Hy(Eo(e,e=>{t.emit(`orderDrag`,e)}));return e.objects.add(n,40),{orders:To(e,n)}}})}function Wy(){return _o({name:`markers`,install:e=>{let t=new Ry;return e.objects.add(t,10),{markers:To(e,t)}}})}function Gy(e,t){return{up:e.upColor??t.up,down:e.downColor??t.down,poc:e.pocColor??t.palette[0]}}function Ky(e,t,n,r,i){let a=t.rows.reduce((e,t)=>Math.max(e,t.up+t.down),0);t.rows.forEach((o,s)=>{let c=n(o.high),l=n(o.low),u=Math.abs(l-c),d=+(u>3),f=Math.min(c,l)+d/2,p=s>=t.valueArea.low&&s<=t.valueArea.high?.5:.22,m=o.up/a*r.length,h=o.down/a*r.length,g=r.x+m;e.fillStyle=C(i.up,p),e.fillRect(Math.min(r.x,g),f,Math.abs(m),u-d),e.fillStyle=C(i.down,p),e.fillRect(Math.min(g,g+h),f,Math.abs(h),u-d)});let o=t.rows[t.poc];if(o){let t=Math.round(n((o.low+o.high)/2))+.5;e.beginPath(),e.moveTo(r.x,t),e.lineTo(r.pocTo,t),e.strokeStyle=i.poc,e.lineWidth=1,e.stroke()}}let qy=.7;g({rows:!0,valueArea:!0});function Jy(e,t){return d(e,t,{min:1,max:1e3,integer:!0})}function Yy(e,t){return d(e,t,{min:0,exclusiveMin:!0,max:1})}function Xy(e,t){return{rows:e.rows===void 0?24:Jy(`${t}.rows`,e.rows),valueArea:e.valueArea===void 0?qy:Yy(`${t}.valueArea`,e.valueArea)}}function Zy(e){e.length===0&&n(`pointOfControl() needs the volume of one row at least.`);let t=(e.length-1)/2,r=0;for(let n=1;n<e.length;n+=1){let i=e[n]??0,a=e[r]??0;(i>a||i===a&&Math.abs(n-t)<=Math.abs(r-t))&&(r=n)}return r}function Qy(e,t,n=qy){d(`poc`,t,{min:0,max:e.length-1,integer:!0}),Yy(`share`,n);let r=0;for(let t=0;t<e.length;t+=1)r+=e[t]??0;let i=r*n,a=e[t]??0,o=t,s=t;for(;o>0||s<e.length-1;){let n=s<e.length-1?e[s+1]??0:-1,c=o>0?e[o-1]??0:-1,l=n>c||n===c&&s+1-t<=t-(o-1),u=l?n:c;if(a+u>i+r*1e-9)break;a+=u,l?s+=1:--o}return{low:o,high:s}}function $y(e,t,n){let r=t>e?t-e:Math.max(Math.abs(t)*.001,1e-9);return{bottom:t>e?e:e-r/2,step:r/n,count:n}}function eb(e,t,n,r,i){let a=Math.max(0,t),o=Math.min(e.length,n),s=1/0,c=-1/0;for(let t=a;t<o;t+=1)s=Math.min(s,e.low(t)),c=Math.max(c,e.high(t));if(!(c>=s))return null;let{bottom:l,step:u}=$y(s,c,r),d=new Float64Array(r),f=new Float64Array(r);for(let t=a;t<o;t+=1){let n=e.volume(t);if(!(n>0))continue;let i=e.close(t)>=e.open(t)?d:f,a=e.low(t),o=e.high(t),s=Math.min(r-1,Math.max(0,Math.floor((a-l)/u))),c=Math.min(r-1,Math.max(0,Math.floor((o-l)/u)));if(s===c||o===a)i[s]=(i[s]??0)+n;else for(let e=s;e<=c;e+=1){let t=l+e*u,r=Math.min(o,t+u)-Math.max(a,t);r>0&&(i[e]=(i[e]??0)+n*r/(o-a))}}let p=new Float64Array(r),m=0;for(let e=0;e<r;e+=1)p[e]=(d[e]??0)+(f[e]??0),m+=p[e]??0;if(!(m>0))return null;let h=Zy(p);return{rows:Array.from({length:r},(e,t)=>({low:l+t*u,high:l+(t+1)*u,up:d[t]??0,down:f[t]??0})),total:m,poc:h,valueArea:Qy(p,h,i)}}function tb(e,t,n,r){return{start:t.lowerBound(e.time(n)),end:r+1<e.length?t.lowerBound(e.time(r+1)):t.length}}function nb(e,t){return Math.max(0,e.lowerBound(t+1)-1)}function rb(e,t,n){return e.range(t.time(n),`1D`)}function ib(e,t,n){let r=n,i=rb(e,t,r);for(;!i&&r>0;)--r,i=rb(e,t,r);if(!i)return null;let{bucket:a}=i,o=t.lowerBound(i.start),s=t.lowerBound(i.end);for(let n=o-1;n>=0;--n){let r=rb(e,t,n);if(r?.bucket===a)o=t.lowerBound(r.start),n=o;else if(r)break}for(;s<t.length;){let n=rb(e,t,s);if(!n)s+=1;else if(n.bucket===a)s=t.lowerBound(n.end);else break}return{start:o,end:s}}function ab(e,t,n){let r=n;for(;r<t.length&&!rb(e,t,r);)r+=1;return r}var ob=class{settings;revision=-1;length=0;calendar=null;range=``;visible=null;days=/* @__PURE__ */ new Map;constructor(e){this.settings=e}profile(e,t,n){return this.follow(e),(this.visible?.start!==t||this.visible.end!==n)&&(this.visible={start:t,end:n,profile:this.compute(e.source,t,n)}),this.visible.profile}sessions(e,t,n,r){let{source:i}=e;this.follow(e),t!==this.calendar&&(this.calendar=t,this.days.clear(),this.range=``);let a=`${n}:${r}`;if(a!==this.range){let e=/* @__PURE__ */ new Map;for(let a=n;a<r;){let n=ib(t,i,a);if(!n){a=ab(t,i,a);continue}let r=this.days.get(n.start);e.set(n.start,r?.end===n.end?r:{...n,profile:this.compute(i,n.start,n.end)}),a=n.end}this.days=e,this.range=a}return this.days.values()}compute(e,t,n){return eb(e,t,n,this.settings.rows,this.settings.valueArea)}follow({source:e,changes:t}){let n=t.changesSince(this.revision),r=e.length===this.length?1/0:Math.min(e.length,this.length);if(n&&(r=n.kind===`reset`?0:Math.min(r,n.from)),this.revision=t.revision,this.length=e.length,r!==1/0){this.visible&&this.visible.end>r&&(this.visible=null);for(let[e,t]of this.days)t.end>=r&&this.days.delete(e);this.range=``}}};function sb(e,t,n,r){let{bars:i,source:a,visible:o}=t;if(!o)return;let{start:s,end:c}=tb(i,a,o.from,o.to),l=Gy(n,t.theme);if(n.mode===`visible`){let i=r.profile(t,s,c);if(!i)return;let a=n.placement===`right`,o=(n.width??.25)*t.width;Ky(e,i,t.valueToY,{x:a?t.width:0,length:a?-o:o,pocTo:a?0:t.width},l);return}let u=t.barSpacing/2;for(let o of r.sessions(t,t.calendar,s,c)){if(!o.profile)continue;let r=t.indexToX(nb(i,a.time(o.start)))-u,s=t.indexToX(nb(i,a.time(o.end-1)))+u;Ky(e,o.profile,t.valueToY,{x:r,length:(n.width??.7)*(s-r),pocTo:s},l)}}let cb=[`visible`,`session`],lb=[`left`,`right`],ub=g({id:!0,mode:!0,rows:!0,valueArea:!0,width:!0,placement:!0,upColor:!0,downColor:!0,pocColor:!0,visible:!0}),db=ub.filter(e=>e!==`id`);function fb(e,t){return t===void 0?null:S(e,t)}function pb(e,t){_(t,e,ub);let{rows:n,valueArea:r}=Xy(e,t);return{mode:m(`${t}.mode`,e.mode,cb),rows:n,valueArea:r,width:e.width===void 0?null:Yy(`${t}.width`,e.width),placement:e.placement===void 0?`right`:m(`${t}.placement`,e.placement,lb),upColor:fb(`${t}.upColor`,e.upColor),downColor:fb(`${t}.downColor`,e.downColor),pocColor:fb(`${t}.pocColor`,e.pocColor),visible:e.visible===void 0||f(`${t}.visible`,e.visible)}}function mb(e){let{width:t,upColor:n,downColor:r,pocColor:i}=e;return{id:e.id,mode:e.mode,rows:e.rows,valueArea:e.valueArea,placement:e.placement,visible:e.visible,...t===null?{}:{width:t},...n===null?{}:{upColor:n},...r===null?{}:{downColor:r},...i===null?{}:{pocColor:i}}}function hb(e){return{profile:e,cache:new ob(e)}}var gb=class e{entries=/* @__PURE__ */ new Map;ids;constructor(e){this.ids=new de(e=>this.entries.has(e),e)}staging(t){let n=new e(this.ids);return n.ids.reserve(t),n}list(){return[...this.entries.values()].map(e=>({...e.profile}))}get(e){let t=this.entries.get(e);return t?{...t.profile}:null}inputs(){return[...this.entries.values()].map(e=>mb(e.profile))}add(e,t=`volumeProfile`){let r=pb(e,t),i=e.id===void 0?this.ids.next(`volume-profile`):p(`${t}.id`,e.id);return this.entries.has(i)&&n(`A volume profile with id "${i}" already exists.`),this.entries.set(i,hb({id:i,...r})),this.ids.note(i),i}update(e,t){let r=this.entries.get(e)??n(`Unknown volume profile "${e}".`);_(`volumeProfile patch`,t,db);let i=pb({...mb(r.profile),...t},`volumeProfile`);this.entries.set(e,hb({id:e,...i}))}remove(e){this.entries.delete(e)||n(`Unknown volume profile "${e}".`)}adopt(e){this.entries=e.entries,this.entries.forEach((e,t)=>{this.ids.note(t)})}paint(e,t){this.entries.forEach(({profile:n,cache:r})=>{n.visible&&sb(e,t,n,r)})}};function _b(e,t,n){v(n,t);let r=e.staging(t);return t.forEach((e,t)=>{r.add(e,`${n}[${t}]`)}),r}function vb(e){return{key:`volumeProfiles`,save:()=>e.inputs(),prepare:t=>{let n=_b(e,t??[],`state.volumeProfiles`);return{apply:()=>{e.adopt(n)}}}}}function yb(e,t){let n=t=>e.run(()=>{let n=t();return e.invalidateLayers(`scene`),n});return{set:e=>{n(()=>{t.adopt(_b(t,e,`volumeProfiles`))})},add:e=>n(()=>t.add(e)),update:(e,r)=>{n(()=>{t.update(e,r)})},remove:e=>{n(()=>{t.remove(e)})},clear:()=>{n(()=>{t.adopt(t.staging([]))})},get:e=>t.get(e),list:()=>t.list()}}function bb(){return _o({name:`volumeProfiles`,install:e=>{let t=new gb;return e.scenePainters.push((n,r,i,a)=>{if(a!==`below`||i.id!==`main`)return;let{timeScale:o}=e;n.save(),t.paint(n,{bars:e.market.displayed,source:e.market.revealed,changes:e.market.feed.source,visible:r.visible,calendar:e.market.tradingCalendar(),theme:e.options.theme,width:i.plot.width,barSpacing:o.barSpacing,indexToX:e=>o.indexToX(e),valueToY:e=>i.scale.valueToY(e)}),n.restore()}),e.stateParts.push(vb(t)),{volumeProfiles:yb(e,t)}}})}let xb=g({rows:!0,valueArea:!0,width:!0,upColor:!0,downColor:!0,pocColor:!0});function Sb(e={}){let t=`fixedRangeVolumeProfile() options`;_(t,e,xb);let{rows:n,valueArea:r}=Xy(e,t),i=e.width===void 0?.6:Yy(`${t}.width`,e.width);for(let n of[`upColor`,`downColor`,`pocColor`])e[n]!==void 0&&p(`${t}.${n}`,e[n]);let a=/* @__PURE__ */ new WeakMap,o=(e,t,i)=>{let o=a.get(e);return o?.revision!==e.revision&&(o={revision:e.revision,profiles:new Ii(64)},a.set(e,o)),o.profiles.getOrCreate(`${t}:${i}`,()=>eb(e,t,i,n,r))},s=e=>{let[t,n]=e.anchors,[r,i]=e.points,{bars:a,source:s}=e,c=a.lowerBound(Math.max(t.time,n.time)+1),l=o(s,s.lowerBound(Math.min(t.time,n.time)),c<a.length?s.lowerBound(a.time(c)):s.length),u=l?.rows[0]?.low??Math.min(t.price,n.price),d=l?.rows.at(-1)?.high??Math.max(t.price,n.price),f=[e.valueToY(u),e.valueToY(d)];return{profile:l,left:Math.min(r.x,i.x),right:Math.max(r.x,i.x),top:Math.min(...f),bottom:Math.max(...f)}};return{type:`fixed-range-volume-profile`,points:2,mainPane:!0,fields:[`color`],paintBelow:({ctx:t,geometry:n})=>{let{left:r,right:a,top:o,bottom:c,profile:l}=s(n);t.fillStyle=C(n.style.color,.04),t.fillRect(r,o,a-r,c-o),l&&Ky(t,l,n.valueToY,{x:r,length:i*(a-r),pocTo:a},Gy(e,n.theme))},paint:({ctx:e,geometry:t,hovered:n,selected:r})=>{let{left:i,right:a,top:o,bottom:c}=s(t),{color:l}=t.style;e.strokeStyle=n||r?l:C(l,.5),e.lineWidth=1,e.strokeRect(Math.round(i)+.5,Math.round(o)+.5,a-i,c-o)},hitTest:(e,t,n)=>{let{left:r,right:i,top:a,bottom:o}=s(e);if(!(t.x>=r-n&&t.x<=i+n&&t.y>=a-n&&t.y<=o+n))return null;let c=Math.min(Math.abs(t.x-r),Math.abs(t.x-i),Math.abs(t.y-a),Math.abs(t.y-o));return c<=n?{part:`line`,distance:c}:null},handles:e=>{let t=s(e),n=(t.top+t.bottom)/2;return e.points.map((e,t)=>({id:String(t),x:e.x,y:n,cursor:`ew-resize`}))},axisMarks:e=>({prices:[],times:e.map(e=>e.time)}),bounds:e=>{let t=s(e);return{x:t.left,y:t.top,width:t.right-t.left,height:t.bottom-t.top}}}}let Cb=g({lines:!0,color:!0}),wb=g({text:!0,size:!0}),Tb={key:`watermark`,defaults:()=>({lines:[],color:null}),validate:(e,t)=>{_(t,e,Cb),v(`${t}.lines`,e.lines),e.lines.forEach((e,n)=>{let r=`${t}.lines[${n}]`;_(r,e,wb),p(`${r}.text`,e.text),e.size!==void 0&&d(`${r}.size`,e.size,{min:6,max:200})}),e.color!==null&&S(`${t}.color`,e.color)}};function Eb(e){return e.watermark}function Db(){return _o({name:`watermark`,options:Tb,install:e=>(e.scenePainters.push((t,n,r,i)=>{let{lines:a,color:o}=Eb(e.options);if(i!==`below`||r.id!==`main`||a.length===0)return;let{theme:s,font:c}=e.options,l=a.map(e=>(e.size??40)*1.25),u=(r.plot.height-l.reduce((e,t)=>e+t,0))/2;t.fillStyle=o??C(s.text,.1),t.textAlign=`center`,t.textBaseline=`middle`,a.forEach((e,n)=>{let i=l[n]??0;t.font=E(e.size??40,c.family,600),t.fillText(e.text,r.plot.width/2,u+i/2),u+=i})}),{})})}function Ob(e={}){return _(`allModules() options`,e,[`indicators`]),[rh(Ty,e.indicators),Zl([...Vp,Sb()]),Ws(Gs),$o(),Uy(),Wy(),jy(),bb(),Db()]}return e.ChartError=t,e.LABEL_ANCHORS=un,e.LINE_STYLES=ln,e.PRICE_SOURCES=Xt,e.alerts=$o,e.allChartTypes=Gs,e.allDrawings=Vp,e.allIndicators=Ty,e.allModules=Ob,e.canBuildTimeframe=Ra,e.chartTypes=Ws,e.checkColor=S,e.checkTimeframe=La,e.createCalendar=Wa,e.createChart=Co,e.createModule=vo,e.darkTheme=qt,e.drawings=Zl,e.fixedRangeVolumeProfile=Sb,e.formatInterval=j,e.indicators=rh,e.intervalDuration=Pa,e.lightTheme=Jt,e.markers=Wy,e.orders=Uy,e.parseBar=tt,e.parseInterval=ja,e.replay=jy,e.volumeProfiles=bb,e.watermark=Db,e.withAlpha=C,e})({});
|