openalgo-charts
Version:
From-scratch, dependency-free canvas charting engine for OpenAlgo: professional-grade interactive rendering, advanced on-chart trading, and a one-call widget tier that adds the toolbar, drawing rail, dialogs and shortcuts.
3 lines • 72.2 kB
JavaScript
function e(e){let t=1/0,o=-1/0;for(const i of e)0!==i.levels.length&&(o=Math.max(o,i.levels[0].price),t=Math.min(t,i.levels[i.levels.length-1].price));return Number.isFinite(t)?{min:t,max:o}:null}function t(e,t){return Math.round(Math.round(e/t)*t*1e8)/1e8}function o(e,o,i){if(!(i>0)||i===1/0)return[];const r=t(e,i),n=t(o,i),s=Math.round((n-r)/i)+1;if(!Number.isFinite(s)||r+i===r||n+i===n)return[];const l=[];for(let e=0,o=r;e<s;e++,o+=i)l.push(t(o,i));return l}function i(e,t){let o=0;for(let t=1;t<e.length;t++)e[t]>e[o]&&(o=t);let i=o,r=o,n=e[o]??0;for(;n<t&&(i>0||r<e.length-1);){n+=(i>0?e[i-1]:-1)>=(r<e.length-1?e[r+1]:-1)?e[--i]:e[++r]}return{poc:o,upper:i,lower:r}}function r(e,t,r=.7){const n=new Map;for(const i of e){const e=o(i.low,i.high,t),r=(i.volume??0)/e.length;for(const t of e)n.set(t,(n.get(t)??0)+r)}const s=Array.from(n.entries()).map(([e,t])=>({price:e,volume:t})).sort((e,t)=>t.price-e.price);if(0===s.length)return{buckets:s,poc:0,vah:0,val:0,totalVolume:0};const l=s.reduce((e,t)=>e+t.volume,0),a=i(s.map(e=>e.volume),l*r);return{buckets:s,poc:s[a.poc].price,vah:s[a.upper].price,val:s[a.lower].price,totalVolume:l}}const n=19800;const s="Asia/Kolkata",l=new Map,a={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};function c(e,t){const o=function(e){let t=l.get(e);if(void 0===t){let o;try{o=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",weekday:"short"})}catch{throw new Error(`openalgo-charts: unknown IANA time zone "${e}"`)}t={format:o,parts:new Map,lastSecond:Number.NaN,lastParts:null},l.set(e,t)}return t}(t);if(e===o.lastSecond&&null!==o.lastParts)return o.lastParts;let i=o.parts.get(e);return void 0===i&&(i=function(e,t){let o=1970,i=1,r=1,n=0,s=0,l=0,c=4;for(const h of e.formatToParts(new Date(1e3*t)))switch(h.type){case"year":o=Number(h.value);break;case"month":i=Number(h.value);break;case"day":r=Number(h.value);break;case"hour":n=Number(h.value)%24;break;case"minute":s=Number(h.value);break;case"second":l=Number(h.value);break;case"weekday":c=a[h.value]??0}return{year:o,month:i,day:r,hour:n,minute:s,second:l,weekday:c,dayIndex:Math.floor(Date.UTC(o,i-1,r)/864e5)}}(o.format,e),o.parts.size>=4096&&o.parts.clear(),o.parts.set(e,i)),o.lastSecond=e,o.lastParts=i,i}function h(e,t=s){const o=c(e,t);return{year:o.year,month:o.month,day:o.day,hour:o.hour,minute:o.minute,second:o.second,weekday:o.weekday}}function u(e,t=s){const o=c(e,t);return Math.floor(Date.UTC(o.year,o.month-1,o.day,o.hour,o.minute,o.second)/1e3)-e}const d=86400;function p(e,t){return t===s?function(e){const t=new Date(1e3*(e+n));return{year:t.getUTCFullYear(),month:t.getUTCMonth()+1,day:t.getUTCDate(),hour:t.getUTCHours(),minute:t.getUTCMinutes(),second:t.getUTCSeconds(),weekday:t.getUTCDay()}}(e):h(e,t)}function m(e,t){if(t===s){const t=((e+n)%d+d)%d;return Math.floor(t/60)}const o=h(e,t);return 60*o.hour+o.minute}function f(e,t){return t===s?Math.floor((e+n)/d):function(e,t=s){return c(e,t).dayIndex}(e,t)}function b(e,t,o,i){if("composite"===t)return 0;if("month"===t){const t=p(e,o);return 12*t.year+(t.month-1)}let r=f(e,o);return void 0!==i&&i.startMinute>i.endMinute&&m(e,o)<i.endMinute&&(r-=1),"day"===t?r:Math.floor((r+3)/7)}const g={tickSize:.05,session:"composite",valueAreaPercent:.7,deltaFromBarDirection:!0,timezone:s};function w(e,t={}){const r={...g,...t},n=r.tickSize>0?r.tickSize:g.tickSize,l=Math.min(1,Math.max(0,r.valueAreaPercent)),a=r.timezone??s,c=new Map,h=[];for(const t of e){const e=b(t.time,r.session,a);let o=c.get(e);void 0===o&&(o=[],c.set(e,o),h.push(e)),o.push(t)}const u=[];for(const e of h){const t=c.get(e);if(0===t.length)continue;const s=new Map;let a=0,h=0,d=0;for(const e of t){const t=e.volume??0;a+=t;const i=e.close>=e.open,l=r.deltaFromBarDirection&&i?t:0,c=r.deltaFromBarDirection?i?0:t:0;h+=l,d+=c;const u=o(e.low,e.high,n),p=Math.max(1,u.length),m=t/p,f=l/p,b=c/p;for(const e of u){let t=s.get(e);void 0===t&&(t={volume:0,buy:0,sell:0},s.set(e,t)),t.volume+=m,t.buy+=f,t.sell+=b}}const p=Array.from(s.entries()).map(([e,t])=>({price:e,volume:t.volume,buyVolume:t.buy,sellVolume:t.sell,delta:t.buy-t.sell})).sort((e,t)=>t.price-e.price);if(0===p.length)continue;const m=i(p.map(e=>e.volume),a*l);u.push({startTime:t[0].time,endTime:t[t.length-1].time,levels:p,poc:p[m.poc].price,vah:p[m.upper].price,val:p[m.lower].price,totalVolume:a,buyVolume:h,sellVolume:d,delta:h-d})}return{sessions:u,options:{...r,timezone:a}}}const v={displayMode:"total",side:"right",width:90,opacity:.85,barColor:"#3b5168",buyColor:"#26a69a",sellColor:"#ef5350",showPoc:!0,pocColor:"#f0a020",showPocLabel:!0,showValueArea:!0,vahColor:"#8892a6",valColor:"#8892a6",showValueAreaLabels:!0,highlightValueArea:!0,valueAreaFillColor:"#4a6fa5",valueAreaFillOpacity:.08,valueAreaOpacityDim:.4,labelSide:"right",zOrder:"bottom"};class M{constructor(e=null,t={}){Object.defineProperty(this,"_result",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._result=e,this._opts={...v,...t}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return this._opts.zOrder}autoscaleInfo(){return null===this._result?null:e(this._result.sessions)}setData(e){this._result=e,this._host?.requestUpdate()}setOptions(e){this._opts={...this._opts,...e},this._host?.requestUpdate()}draw(e,t){if(null===this._result||0===this._result.sessions.length)return;const o=this._result.options.tickSize;for(const i of this._result.sessions)this._drawSession(e,t,i,o)}_segments(e,t,o){const i=this._opts;if("delta"===i.displayMode){const r=Math.abs(e.delta)/t*o;return[{color:e.delta>=0?i.buyColor:i.sellColor,len:r}]}const r=e.volume/t*o;if("buySell"===i.displayMode&&e.volume>0){const t=r*(e.buyVolume/e.volume);return[{color:i.buyColor,len:t},{color:i.sellColor,len:r-t}]}return[{color:i.barColor,len:r}]}_drawSession(e,t,o,i){const r=this._opts,n=t.dpr,s=t.dataLayer.timeToIndex(o.startTime),l=t.dataLayer.timeToIndex(o.endTime);if(void 0===s||void 0===l)return;const a=Math.round(t.timeScale.indexToX(s)*n),c=Math.max(a+1,Math.round(t.timeScale.indexToX(l)*n)),h=e=>t.priceScale.priceToY(e)*n,u=Math.max(1,Math.abs(t.priceScale.priceToY(o.poc)-t.priceScale.priceToY(o.poc+i))*n),d=r.width*n,p="right"===r.side?c:a;let m=0;for(const e of o.levels){const t="delta"===r.displayMode?Math.abs(e.delta):e.volume;t>m&&(m=t)}if(m<=0&&(m=1),e.save(),r.highlightValueArea){const t=h(o.vah)-u/2,i=h(o.val)+u/2,n="right"===r.side?c-d:a;e.globalAlpha=r.valueAreaFillOpacity,e.fillStyle=r.valueAreaFillColor,e.fillRect(n,t,d,i-t),e.globalAlpha=1}for(const t of o.levels){const i=t.price<=o.vah&&t.price>=o.val,n=r.opacity*(i?1:r.valueAreaOpacityDim),s=h(t.price)-u/2,l=Math.max(1,u-1);let a=p;e.globalAlpha=n;for(const o of this._segments(t,m,d)){if(o.len<=0)continue;const t="right"===r.side?a-o.len:a;e.fillStyle=o.color,e.fillRect(t,s,o.len,l),a="right"===r.side?a-o.len:a+o.len}}e.globalAlpha=1;const f=(t,o,i)=>{const s=Math.round(h(t))+.5;e.strokeStyle=o,e.lineWidth=Math.max(1,Math.round(n)),e.beginPath(),e.moveTo(a,s),e.lineTo(c,s),e.stroke(),""!==i&&(e.font=9*n+"px ui-sans-serif, system-ui, sans-serif",e.textBaseline="middle",e.fillStyle=o,"right"===r.labelSide?(e.textAlign="left",e.fillText(i,c+3*n,s)):(e.textAlign="right",e.fillText(i,a-3*n,s)))};r.showValueArea&&(f(o.vah,r.vahColor,r.showValueAreaLabels?`VAH ${t.priceScale.format(o.vah)}`:""),f(o.val,r.valColor,r.showValueAreaLabels?`VAL ${t.priceScale.format(o.val)}`:"")),r.showPoc&&f(o.poc,r.pocColor,r.showPocLabel?`POC ${t.priceScale.format(o.poc)}`:""),e.restore()}}function _(e,t,r,n=.7,s=2){const l=Math.max(1,t),a=new Map;let c=-1/0,h=1/0;const u=Math.ceil(e.length/l);for(let t=0;t<u;t++){const i=e.slice(t*l,(t+1)*l);if(0===i.length)continue;let n=-1/0,u=1/0;for(const e of i)n=Math.max(n,e.high),u=Math.min(u,e.low);t<s&&(c=Math.max(c,n),h=Math.min(h,u));for(const e of o(u,n,r))a.set(e,(a.get(e)??0)+1)}const d=Array.from(a.entries()).map(([e,t])=>({price:e,count:t})).sort((e,t)=>t.price-e.price);if(0===d.length)return{buckets:d,poc:0,vah:0,val:0,ib:{high:0,low:0}};const p=d.reduce((e,t)=>e+t.count,0),m=i(d.map(e=>e.count),p*n);return{buckets:d,poc:d[m.poc].price,vah:d[m.upper].price,val:d[m.lower].price,ib:{high:c,low:h}}}const x={"all-hours":{startMinute:0,endMinute:0,name:"All Hours"},india:{startMinute:555,endMinute:930,zone:"Asia/Kolkata",name:"India"},asia:{startMinute:540,endMinute:900,zone:"Asia/Tokyo",name:"Asia"},london:{startMinute:420,endMinute:780,zone:"Europe/London",name:"London"},"new-york":{startMinute:480,endMinute:930,zone:"America/New_York",name:"New York"},"us-regular":{startMinute:570,endMinute:960,zone:"America/New_York",name:"US Regular"}},y={tickSize:.05,rowTicks:1,session:"day",blockMinutes:30,valueAreaPercent:.7,initialBalancePeriods:2,compositeSessions:1,tailEdges:0,timezone:s};function k(e,t){return e>0&&t>0?Math.max(1,Math.round(e/t)):1}function S(e){const t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(t-26+97)}function T(e,t){return e?.zone??t}function F(e,t,o=s){if(t.startMinute===t.endMinute)return!0;const i=m(e,T(t,o));return t.startMinute<t.endMinute?i>=t.startMinute&&i<t.endMinute:i>=t.startMinute||i<t.endMinute}function C(e,t,o,i){const r=p(e,o),n=new Date(Date.UTC(r.year,r.month-1,r.day+i));return function(e,t,o,i=0,r=0,n=0,l=s){const a=Math.floor(Date.UTC(e,t-1,o,i,r,n)/1e3),c=a-u(a,l);return a-u(c,l)}(n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),Math.floor(t.startMinute/60),t.startMinute%60,0,o)}function A(e,t,o=s){const i=T(t,o),r=C(e,t,i,0);return r<=e?r:C(e,t,i,-1)}function P(e,t){const o=e.map(e=>e.count),r=i(o,o.reduce((e,t)=>e+t,0)*t);return{poc:e[r.poc].price,vah:e[r.upper].price,val:e[r.lower].price}}function V(e,t,o){let i=0;for(let r=t;r>=0&&r<e.length&&1===e[r].count;r+=o)i++;return i}function D(e,t,o,i,r,n){const s=e.high-e.low,l=t-o;if(l<=0||s<=0)return"normal";if(i.up>0&&i.down>0)return"neutral";const a=r.findIndex(e=>e.price===n);if(a>=0&&r.length>=5){const e=r[a].count;let t=1/0,o=0;for(let e=0;e<r.length;e++){const i=Math.abs(e-a);i>1&&(o=Math.max(o,r[e].count)),i>0&&i<=Math.max(2,Math.floor(r.length/4))&&(t=Math.min(t,r[e].count))}if(o>=.7*e&&t<=.35*e)return"double-distribution"}const c=l/s;return c>=2.5?"trend":c>=1.4?"normal-variation":"normal"}function R(e,t,o,i,r){if(void 0===t)return"auction";const n=i-r;if(n<=0)return"auction";const s=t.high-t.low,l=(e-r)/n;if((l>.7||l<.3)&&s<=.35*n)return"drive";if(void 0!==o){const i=t.low<e-.25*s,r=t.high>e+.25*s;if(i&&o.high>t.high||r&&o.low<t.low)return"test-drive";if(r&&o.low<e||i&&o.high>e)return"rejection-reverse"}return"auction"}function z(e,t={}){const o={...y,...t},i=o.tickSize>0?o.tickSize:y.tickSize,r=Math.max(1,Math.floor(o.rowTicks)),n=o.timezone??s,l={row:i*r,blockSec:Math.max(1,Math.round(60*o.blockMinutes)),vaPct:Math.min(1,Math.max(0,o.valueAreaPercent)),ibPeriods:Math.max(1,Math.floor(o.initialBalancePeriods)),tailEdges:o.tailEdges,win:o.window,cal:T(o.window,n)},a=[];for(const t of function(e,t,o,i){const r=t.window,n=Math.max(1,Math.floor(t.compositeSessions)),s=new Map,l=[];for(const n of e){if(void 0!==r&&!F(n.time,r,o))continue;const e=b(n.time,t.session,i,r);let a=s.get(e);void 0===a&&(a=[],s.set(e,a),l.push(e)),a.push(n)}const a=[];if(n>1&&"composite"!==t.session)for(let e=0;e<l.length;e+=n){const t=[];for(let o=e;o<Math.min(e+n,l.length);o++)t.push(...s.get(l[o]));a.push(t)}else for(const e of l)a.push(s.get(e));return a}(e,o,n,l.cal)){const e=E(t,l);null!==e&&a.push(e)}return{sessions:a,options:{...o,rowTicks:r,timezone:n}}}function E(e,t){if(0===e.length)return null;const i=e[0].time;let r=i;const n=t.win;void 0!==n&&n.startMinute!==n.endMinute&&(r=A(i,n,t.cal));const s=new Map,l=new Map;let a=0,c=-1/0,h=1/0,u=0,d=-1/0,p=1/0;for(const i of e){const e=Math.max(0,Math.floor((i.time-r)/t.blockSec));e>a&&(a=e),e<t.ibPeriods&&(c=Math.max(c,i.high),h=Math.min(h,i.low)),d=Math.max(d,i.high),p=Math.min(p,i.low);const n=i.volume??0;u+=n;let m=l.get(e);void 0===m&&(m={index:e,letter:S(e),startTime:i.time,endTime:i.time,high:i.high,low:i.low,volume:0},l.set(e,m)),m.endTime=i.time,m.high=Math.max(m.high,i.high),m.low=Math.min(m.low,i.low),m.volume+=n;const f=o(i.low,i.high,t.row),b=n/Math.max(1,f.length);for(const t of f){let o=s.get(t);void 0===o&&(o={periods:new Set,volume:0},s.set(t,o)),o.periods.add(e),o.volume+=b}}const m=Array.from(l.values()).sort((e,t)=>e.index-t.index),f=Array.from(s.entries()).map(([e,t])=>{const o=Array.from(t.periods).sort((e,t)=>e-t);return{price:e,count:o.length,periods:o,volume:t.volume,letters:o.map(S).join("")}}).sort((e,t)=>t.price-e.price);if(0===f.length)return null;const b=P(f,t.vaPct),g=[];for(let e=1;e<f.length-1;e++)1===f[e].count&&g.push(f[e].price);const w={high:Number.isFinite(c)?c:f[0].price,low:Number.isFinite(h)?h:f[f.length-1].price},v={up:Math.max(0,d-w.high),down:Math.max(0,w.low-p)};let M=f[0].price,_=-1;for(const e of f)e.volume>_&&(_=e.volume,M=e.price);return{startTime:i,endTime:e[e.length-1].time,label:n?.name,levels:f,poc:b.poc,vah:b.vah,val:b.val,high:d,low:p,open:e[0].open,close:e[e.length-1].close,periods:a+1,periodDetail:m,initialBalance:w,rangeExtension:v,singlePrints:g,...O(f,t.tailEdges),poorHigh:f[0].count>1,poorLow:f[f.length-1].count>1,developing:B(f,m,t.vaPct),dayType:D(w,d,p,v,f,b.poc),openType:R(e[0].open,m[0],m[1],d,p),volumePoc:M,totalVolume:u}}function B(e,t,o){const i=[];for(const r of t){const t=[];for(const o of e){let e=0;for(const t of o.periods)t<=r.index&&e++;e>0&&t.push({price:o.price,count:e})}0!==t.length&&i.push({periodIndex:r.index,time:r.endTime,...P(t,o)})}return i}function O(e,t){let o=null,i=null;if(t>0){const r=V(e,0,1);r>=t&&(i={high:e[0].price,low:e[r-1].price});const n=V(e,e.length-1,-1);n>=t&&(o={high:e[e.length-n].price,low:e[e.length-1].price})}return{buyingTail:o,sellingTail:i}}function N(e){const t=[],o=e.sessions,i=["poc","vah","val"];for(let e=0;e<o.length;e++)for(const r of i){const i=o[e][r];let n=!1;for(let t=e+1;t<o.length&&!n;t++)i<=o[t].high&&i>=o[t].low&&(n=!0);n||t.push({time:o[e].startTime,price:i,kind:r})}return t}function L(e,o){return t(e,o.tickSize*Math.max(1,Math.floor(o.rowTicks)))}const j=["25755","65656","34443","65556","74747","74744","34553","55755","72227","11152","55655","44447","57755","57555","25552","65644","25573","65655","34216","72222","55557","55552","55775","55255","55222","71247","03137","44656","03443","11353","02743","32722","03531","44655","20223","10152","44565","62223","07755","06555","02552","06564","03511","03444","03216","27223","05553","05552","05577","05225","05531","07127","75557","26227","61247","61216","55711","74616","34752","71222","25252","25716","57575"],I=new Map(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#",(e,t)=>{const o=[];for(let e=0;e<5;e++){const i=Number(j[t][e]);for(let t=0;t<3;t++){if(!(i&4>>t))continue;const r=t;for(;t+1<3&&i&4>>t+1;)t++;o.push([r,e,t-r+1])}}return[e,o]}));function W(e,t,o,i,r,n,s="center"){if(0===t.length||!Number.isFinite(r)||!Number.isFinite(n))return!1;const l=4*t.length-1,a=Math.floor(Math.min(r/5,n/l)+1e-7);if(a<1)return!1;const c=l*a,h=Math.round(o-("center"===s?c/2:"right"===s?c:0)),u=Math.round(i-5*a/2);for(let o=0;o<t.length;o++){const i=I.get(t[o]);if(void 0!==i)for(const[t,r,n]of i)e.fillRect(h+(4*o+t)*a,u+r*a,n*a,a)}return!0}const H=["#e05555","#e08a3c","#d9c341","#8cc44a","#3fb96b","#38b2a3","#3b9fd1","#5a7fe0","#8a68d9","#c05fc4","#d1508f","#9b7b5a"],$={blockDisplay:"auto",minLetterHeight:7,letterFade:4,letterWidth:8,font:10,colorMode:"period",periodColors:H,color:"#5a6b8c",vaColor:"#4a8f7a",opacity:.92,outsideVaOpacity:.45,zOrder:"top",split:!1,showSessionOpen:!1,sessionOpenColor:"#5ca8ff",showLastPrice:!1,lastPriceColor:"#ff6b5e",profileSpacing:4,showPoc:!0,pocColor:"#f0a020",pocThickness:2,showPocLabel:!0,showValueArea:!0,vahColor:"#8892a6",valColor:"#8892a6",showValueAreaLabels:!0,fillValueArea:!0,valueAreaFillColor:"#4a8f7a",valueAreaFillOpacity:.07,showInitialBalance:!0,ibColor:"#c8853a",showSinglePrints:!0,singlePrintColor:"#e0556b",showTails:!0,buyTailColor:"#3fb96b",sellTailColor:"#e05555",showPoorHighLow:!1,poorColor:"#ffd966",showNakedLevels:!1,nakedColor:"#b0b0b0",showDevelopingPoc:!1,developingPocColor:"#ffffff",showDevelopingVa:!1,developingVaColor:"#888888",showTpoCounts:!1,countColor:"#8892a6",showSessionLabel:!0,showDayType:!1,showOpenType:!1,labelColor:"#cccccc",showVolumeProfile:!1,volumeProfileWidth:60,volumeProfileSide:"right",volumeColor:"#3b5168",showVolumeValues:!1},U={normal:"Normal","normal-variation":"Normal Var",trend:"Trend","double-distribution":"Double Dist",neutral:"Neutral"},Y={drive:"Open-Drive","test-drive":"Open-Test-Drive","rejection-reverse":"Open-Rej-Rev",auction:"Open-Auction"};class q{constructor(e=null,t={}){Object.defineProperty(this,"_result",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_boxes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_rowH",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_rc",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_sessionSplits",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this._result=e,this._opts={...$,...t}}attached(e){this._host=e}detached(){this._host=null}zOrder(){return this._opts.zOrder}options(){return this._opts}autoscaleInfo(){return null===this._result?null:e(this._result.sessions)}setData(e){this._result=e,this._boxes=[],this._host?.requestUpdate()}setOptions(e){this._opts={...this._opts,...e},void 0!==e.split&&this._sessionSplits.clear(),this._host?.requestUpdate()}isSessionSplit(e){const t=this._sessionKey(e);return null!==t&&(this._sessionSplits.get(t)??this._opts.split)}setSessionSplit(e,t){const o=this._sessionKey(e);return null!==o&&(null===t?this._sessionSplits.delete(o):this._sessionSplits.set(o,t),this._host?.requestUpdate(),!0)}_sessionKey(e){if(!Number.isInteger(e)||e<0||null===this._result)return null;const t=this._result.sessions[e];return void 0===t?null:function(e,t){const o=T(t.window,t.timezone??s);return[t.session,t.compositeSessions,o,t.window?.startMinute??"",t.window?.endMinute??"",b(e,t.session,o,t.window)].join("|")}(t.startTime,this._result.options)}hitTest(e,t){const o=this._boxes.find(t=>e>=t.x0&&e<=t.x1);return void 0===o?null:{externalId:`mp:${o.index}`,zOrder:"normal",distance:0,cursor:"crosshair"}}hoverAt(e,t,o){const i=o??this._rc;if(null===i||null===this._result)return null;const r=this._boxes.find(t=>e>=t.x0&&e<=t.x1);if(void 0===r)return null;const n=this._result.sessions[r.index];if(void 0===n)return null;let s=null,l=1/0;for(const e of n.levels){const o=Math.abs(i.priceScale.priceToY(e.price)-t);o<l&&o<=Math.max(4,this._rowH)&&(l=o,s=e)}return null===s?null:{sessionIndex:r.index,price:s.price,level:s,session:n,isPoc:s.price===n.poc,inValueArea:s.price<=n.vah&&s.price>=n.val,isSinglePrint:n.singlePrints.includes(s.price)}}draw(e,t){if(this._rc=t,this._boxes=[],null===this._result||0===this._result.sessions.length)return;const o=this._result.options,i=o.tickSize*Math.max(1,Math.floor(o.rowTicks)),r="compact"===this._opts.blockDisplay;r&&(e.save(),e.beginPath(),e.rect(0,0,Math.floor(t.plotWidth*t.dpr),Math.floor(t.plotHeight*t.dpr)),e.clip());for(let o=0;o<this._result.sessions.length;o++)this._drawSession(e,t,this._result.sessions[o],i,o);this._opts.showNakedLevels&&this._drawNaked(e,t),r&&e.restore()}_letterAlpha(e){const t=this._opts;if("compact"===t.blockDisplay||"letters"===t.blockDisplay||"blocks+letters"===t.blockDisplay)return 1;if("blocks"===t.blockDisplay)return 0;const o=Math.max(1,t.letterFade);return Math.max(0,Math.min(1,(e-t.minLetterHeight)/o))}_blockColor(e,t,o){const i=this._opts;return"period"===i.colorMode?i.periodColors[t%i.periodColors.length]??i.color:"valueArea"===i.colorMode&&e.price<=o.vah&&e.price>=o.val?i.vaColor:i.color}_drawSession(e,t,o,i,r){const n=this._opts,s=t.dpr,l="compact"===n.blockDisplay,a=this.isSessionSplit(r),c=t.dataLayer.timeToIndex(o.startTime),h=t.dataLayer.timeToIndex(o.endTime);if(void 0===c||void 0===h)return;const u=n.profileSpacing*s;let d=Math.round(t.timeScale.indexToX(c)*s)+u/2;const p=Math.max(d+1,Math.round(t.timeScale.indexToX(h)*s)-u/2),m=d<=t.plotWidth*s&&p>=0;this._boxes.push({index:r,x0:d/s,x1:p/s});const f=e=>t.priceScale.priceToY(e)*s,b=Math.max(1,Math.abs(t.priceScale.priceToY(o.poc)-t.priceScale.priceToY(o.poc+i))*s);this._rowH=b/s;const g=l&&b<12*s,w=Math.floor(Math.min(b,n.font*s)+1e-7),v=g?Math.max(1,Math.min(Math.round(n.letterWidth*s),4*Math.max(1,Math.floor(w/5)))):n.letterWidth*s;n.showSessionOpen&&(d+=v+3*s);const M=n.showLastPrice&&r===this._result.sessions.length-1,_=this._letterAlpha(b/s),x=!l&&("letters"!==n.blockDisplay||_<1);if(e.save(),n.fillValueArea&&p>d){const t=f(o.vah)-b/2,i=f(o.val)+b/2;e.globalAlpha=n.valueAreaFillOpacity,e.fillStyle=n.valueAreaFillColor,e.fillRect(d,t,p-d,i-t),e.globalAlpha=1}let y=1,k=0;for(const e of o.levels)e.count>y&&(y=e.count),e.volume>k&&(k=e.volume);n.showVolumeProfile&&k>0&&this._drawVolume(e,t,o,d,p,b,k);const S=Math.min(n.font*s,.95*b);_>0&&(e.font=`${S}px ui-monospace, SFMono-Regular, Menlo, monospace`,e.textBaseline="middle",e.textAlign="center");const T=Math.max(1,b-Math.min(1.5*s,.15*b)),F="count"===n.colorMode||"volume"===n.colorMode;for(const i of o.levels){const r=f(i.price);if(l&&(r+b/2<0||r-b/2>t.plotHeight*s))continue;const c=i.price<=o.vah&&i.price>=o.val?1:n.outsideVaOpacity,h="count"===n.colorMode?i.count/y:"volume"===n.colorMode&&k>0?i.volume/k:1,u=n.opacity*c*(F?.3+.7*h:1);for(let c=0;c<i.periods.length;c++){const m=a?i.periods[c]:c,f=d+m*v;if(f>p)break;if(l&&(f+v>p||f+v<0||f>t.plotWidth*s))continue;const b=this._blockColor(i,i.periods[c],o);x&&(e.globalAlpha=u,e.fillStyle=b,e.fillRect(f,r-T/2,Math.max(1,v-Math.min(1,.12*v)),T)),_>0&&(e.globalAlpha=l?n.opacity*(F?.3+.7*h:1):_*(x?.95:u),e.fillStyle=x?"#12151c":b,g?W(e,i.letters[c]??"",f+v/2,r,w,v-1)||e.fillRect(Math.round(f),Math.round(r),Math.max(1,Math.floor(v-1)),1):e.fillText(i.letters[c]??"",l?Math.round(f+v/2):f+v/2,l?Math.round(r):r))}}if(e.globalAlpha=1,n.showTpoCounts){e.font=`${Math.min((n.font-1)*s,b)}px ui-monospace, monospace`,e.textAlign="left",e.textBaseline="middle",e.fillStyle=n.countColor;const i=d+((a?o.periods:y)+(M?1:0))*v+3*s;for(const r of o.levels){const o=f(r.price);if(g){if(o+b/2<0||o-b/2>t.plotHeight*s)continue;W(e,String(r.count),i,o,w,Math.max(0,p-i),"left")}else e.fillText(String(r.count),i,o)}}if(n.showSinglePrints&&o.singlePrints.length>0){e.strokeStyle=n.singlePrintColor,e.lineWidth=Math.max(1,Math.round(s));for(const t of o.singlePrints){const o=Math.round(f(t))+.5;e.beginPath(),e.moveTo(d,o),e.lineTo(d+6*s,o),e.stroke()}}if(n.showTails){const t=(t,o)=>{if(null===t)return;e.fillStyle=o,e.globalAlpha=.75;const i=f(t.high)-b/2,r=f(t.low)+b/2;e.fillRect(d-4*s,i,3*s,r-i),e.globalAlpha=1};t(o.sellingTail,n.sellTailColor),t(o.buyingTail,n.buyTailColor)}if(n.showInitialBalance&&Number.isFinite(o.initialBalance.high)){const t=f(o.initialBalance.high),i=f(o.initialBalance.low),r=d-2*s;e.strokeStyle=n.ibColor,e.lineWidth=Math.max(1,Math.round(1.5*s)),e.beginPath(),e.moveTo(r,t),e.lineTo(r,i),e.moveTo(r,t),e.lineTo(r+5*s,t),e.moveTo(r,i),e.lineTo(r+5*s,i),e.stroke()}const C=(t,o,i,r=1)=>{const l=Math.round(f(t))+.5;e.strokeStyle=o,e.lineWidth=Math.max(1,Math.round(r*s)),e.beginPath(),e.moveTo(d,l),e.lineTo(p,l),e.stroke(),""!==i&&(e.font=(n.font-1)*s+"px ui-sans-serif, system-ui, sans-serif",e.textBaseline="middle",e.textAlign="left",e.fillStyle=o,e.fillText(i,p+3*s,l))};n.showValueArea&&(C(o.vah,n.vahColor,n.showValueAreaLabels?`VAH ${t.priceScale.format(o.vah)}`:""),C(o.val,n.valColor,n.showValueAreaLabels?`VAL ${t.priceScale.format(o.val)}`:"")),n.showPoc&&C(o.poc,n.pocColor,n.showPocLabel?`POC ${t.priceScale.format(o.poc)}`:"",n.pocThickness),n.showPoorHighLow&&(o.poorHigh&&C(o.high,n.poorColor,"Poor High"),o.poorLow&&C(o.low,n.poorColor,"Poor Low")),n.showDevelopingPoc&&this._drawDeveloping(e,t,o,"poc",n.developingPocColor),n.showDevelopingVa&&(this._drawDeveloping(e,t,o,"vah",n.developingVaColor),this._drawDeveloping(e,t,o,"val",n.developingVaColor));const A=this._result;if(n.showSessionOpen&&this._drawPriceMarker(e,t,"o",d-v/2-3*s,f(L(o.open,A.options)),b,n.sessionOpenColor),M&&m){const i=L(o.close,A.options),r=o.levels.find(e=>e.price===i);if(void 0!==r){const o=a?(r.periods[r.periods.length-1]??0)+1:r.count,l=Math.max(2,v/2),c=Math.max(l,Math.min(d+(o+.5)*v,t.plotWidth*s-l));this._drawPriceMarker(e,t,"#",c,f(i),b,n.lastPriceColor)}}const P=[];n.showSessionLabel&&void 0!==o.label&&P.push(o.label),n.showDayType&&P.push(U[o.dayType]??o.dayType),n.showOpenType&&P.push(Y[o.openType]??o.openType),P.length>0&&(e.font=(n.font-1)*s+"px ui-sans-serif, system-ui, sans-serif",e.textAlign="left",e.textBaseline="bottom",e.fillStyle=n.labelColor,e.fillText(P.join(" · "),d,f(o.high)-b)),e.restore()}_drawPriceMarker(e,t,o,i,r,n,s){const l=Math.max(5,Math.min(n,this._opts.font*t.dpr));e.save(),e.globalAlpha=this._opts.opacity,e.fillStyle=s,n<12*t.dpr?W(e,o,i,r,l,Math.max(3,l)):(e.font=`${l}px ui-monospace, SFMono-Regular, Menlo, monospace`,e.textAlign="center",e.textBaseline="middle",e.fillText(o,Math.round(i),r)),e.restore()}_drawVolume(e,t,o,i,r,n,s){const l=this._opts,a=t.dpr,c=l.volumeProfileWidth*a,h="right"===l.volumeProfileSide,u="compact"===l.blockDisplay,d=e=>!u||e+n/2>=0&&e-n/2<=t.plotHeight*a;e.globalAlpha=.55,e.fillStyle=l.volumeColor;for(const l of o.levels){if(!d(t.priceScale.priceToY(l.price)*a))continue;const o=c*(l.volume/s),u=t.priceScale.priceToY(l.price)*a-n/2;e.fillRect(h?r-o:i,u,o,Math.max(1,n-1))}if(e.globalAlpha=1,l.showVolumeValues&&n>=(u?5-1e-7:7*a)){e.font=`${Math.min(9*a,.9*n)}px ui-monospace, monospace`,e.textBaseline="middle",e.textAlign=h?"right":"left",e.fillStyle=l.countColor;for(const s of o.levels){const o=t.priceScale.priceToY(s.price)*a;if(!d(o))continue;const l=Math.round(s.volume).toString(),p=h?r-2*a:i+2*a;u&&n<12*a?W(e,l,p,o,Math.min(n,9*a),Math.max(0,c-4*a),h?"right":"left"):e.fillText(l,p,o)}}}_drawDeveloping(e,t,o,i,r){if(0===o.developing.length)return;const n=t.dpr;e.save(),e.strokeStyle=r,e.lineWidth=Math.max(1,Math.round(n)),e.beginPath();let s=!1;for(const r of o.developing){const o=t.dataLayer.timeToIndex(r.time);if(void 0===o)continue;const l=t.timeScale.indexToX(o)*n,a=Math.round(t.priceScale.priceToY(r[i])*n)+.5;s?e.lineTo(l,a):(e.moveTo(l,a),s=!0)}s&&e.stroke(),e.restore()}_drawNaked(e,t){const o=this._opts,i=t.dpr,r=N(this._result);if(0===r.length)return;e.save(),e.strokeStyle=o.nakedColor,e.lineWidth=Math.max(1,Math.round(i)),e.setLineDash([4*i,3*i]);const n=t.plotWidth*i;for(const o of r){const r=t.dataLayer.timeToIndex(o.time);if(void 0===r)continue;const s=Math.round(t.priceScale.priceToY(o.price)*i)+.5;e.beginPath(),e.moveTo(t.timeScale.indexToX(r)*i,s),e.lineTo(n,s),e.stroke()}e.setLineDash([]),e.restore()}}function K(e,o,i){return t(function(e,t,o){const i=e/t,r=Math.sign(i)*Math.round(Math.abs(i)),n=Math.floor(r/o),s=2*(r-n*o);return s>o||s===o&&n%2!=0?n+1:n}(e,o,i)*i*o,o*i)}function X(e){const t=e?.minTradeSize??0;if(!Number.isFinite(t)||t<0)throw new RangeError("Footprint minTradeSize must be nonnegative and finite");return t}function Z(e,t,o,i=1,r){const n=Q(o,i),s=X(r);if(!Number.isFinite(e))throw new RangeError("Footprint time must be finite");for(const e of t)ee(e);const l=new Map,a=new Map;let c=0,h=0,u=0,d=0;for(const e of t){const t=K(e.price,o,i);let r=l.get(t);void 0===r&&(r={price:t,bidVol:0,askVol:0},l.set(t,r)),G(a,e,o),e.qty<s||(d++,"bid"===e.side?(r.bidVol+=e.qty,c-=e.qty):(r.askVol+=e.qty,c+=e.qty),h=Math.min(h,c),u=Math.max(u,c))}const p={time:e,cells:Array.from(l.values()).sort((e,t)=>t.price-e.price),delta:c,minDelta:h,maxDelta:u,rowSize:n,tradeCount:d};if(t.length>0){p.open=t[0].price,p.close=t[t.length-1].price,p.high=p.low=t[0].price;for(const e of t)p.high=Math.max(p.high,e.price),p.low=Math.min(p.low,e.price);p.auction=J(a,p.high,p.low,o)}return p}function G(e,t,o){const i=Math.round(t.price/o);let r=e.get(i);void 0===r&&(r=[0,0],e.set(i,r)),r["bid"===t.side?0:1]+=t.qty}function J(e,t,o,i){const r=e.get(Math.round(t/i))??[0,0],n=e.get(Math.round(o/i))??[0,0];return{highBid:r[0],highAsk:r[1],lowBid:n[0],lowAsk:n[1]}}function Q(e,t){if(!Number.isFinite(e)||e<=0)throw new RangeError("Footprint tickSize must be positive and finite");if(!Number.isSafeInteger(t)||t<1)throw new RangeError("Footprint rowTicks must be a positive integer");const o=e*t;if(!Number.isFinite(o))throw new RangeError("Footprint tickSize * rowTicks must be finite");return o}function ee(e){if(!Number.isFinite(e.price))throw new RangeError("Footprint trade price must be finite");if(!Number.isFinite(e.qty)||e.qty<0)throw new RangeError("Footprint trade qty must be nonnegative and finite");if("bid"!==e.side&&"ask"!==e.side)throw new TypeError("Footprint trade side must be bid or ask")}function te(e){let t=1/0;for(let o=1;o<e.length;o++){const i=e[o-1].price-e[o].price;i>0&&(t=Math.min(t,i))}return t}function oe(e,t,o){return Math.max(1e-7*o,Math.max(Math.abs(e),Math.abs(t))*Number.EPSILON*8)}function ie(e,t,o){return Number.isFinite(o)&&e>t&&Math.abs(e-t-o)<=oe(e,t,o)}function re(e,t,o,i){if(ie(e,t,o))return i;const r=e-t;return Number.isFinite(o)&&r>o+oe(e,t,o)&&Math.round(r/o)-1<=1e3?0:void 0}function ne(e,t=3,o,i=0){if(!Number.isFinite(t)||t<=0)throw new RangeError("Imbalance ratio must be positive and finite");if(void 0!==o&&(!Number.isFinite(o)||o<=0))throw new RangeError("Imbalance rowSize must be positive and finite");if(!Number.isFinite(i)||i<0)throw new RangeError("Imbalance threshold must be nonnegative and finite");const r=[...e].sort((e,t)=>t.price-e.price),n=o??te(r),s=(e,o)=>e>0&&e>=i&&e>=t*o,l=[];for(let e=0;e<r.length;e++){const t=r[e],o=r[e+1],i=r[e-1],a=o&&re(t.price,o.price,n,o.bidVol),c=i&&re(i.price,t.price,n,i.askVol);void 0!==a&&s(t.askVol,a)&&l.push({price:t.price,side:"buy"}),void 0!==c&&s(t.bidVol,c)&&l.push({price:t.price,side:"sell"})}return l}function se(e){const t=[];let o=0;for(const i of e)o+=i.delta,t.push(o);return t}function le(e,t=3,o=3,i,r=0){if(!Number.isSafeInteger(o)||o<1)throw new RangeError("Imbalance minStack must be a positive integer");const n=[...e].sort((e,t)=>t.price-e.price),s=ne(n,t,i,r),l=i??te(n),a=[];for(const e of["buy","sell"]){const t=new Set(s.filter(t=>t.side===e).map(e=>e.price));let i;const r=()=>{i&&i.count>=o&&a.push(i),i=void 0};for(const o of n)t.has(o.price)?(i&&!ie(i.endPrice,o.price,l)&&r(),i?(i.endPrice=o.price,i.count++):i={startPrice:o.price,endPrice:o.price,side:e,count:1}):r();r()}return a.sort((e,t)=>t.startPrice-e.startPrice)}function ae(e="tickRule"){if("tickRule"!==e&&"quote"!==e)throw new TypeError("Trade classification must be tickRule or quote");let t=0,o="ask";return i=>{if(!Number.isFinite(i.price))throw new RangeError("Trade print price must be finite");const{price:r,bid:n,ask:s}=i,l="quote"===e&&void 0!==n&&void 0!==s&&n>0&&s>=n;let a;return a=l&&r>=s?"ask":l&&r<=n?"bid":r>t?"ask":r<t?"bid":o,t=r,o=a,a}}const ce={imbalanceRatio:3,imbalanceThreshold:0,stackedImbalances:3,multipleNodeBars:2,bigOrderMultiple:3,absorptionMultiple:2,signalLookback:10,nearExtremeRows:3,flipBars:2,flipMinDeltaPct:8,zoneEnd:"closeInside",zoneActiveAfter:1,zoneLookback:0,formingLastBar:!0};function he(e){const t=[...e.cells].sort((e,t)=>e.price-t.price);let o=e.rowSize??1/0;for(let e=1;e<t.length;e++)o=Math.min(o,t[e].price-t[e-1].price);let r=0,n=0,s=0,l=0,a=0;for(const e of t)r+=e.bidVol+e.askVol,e.bidVol>0&&(n+=e.bidVol,s++),e.askVol>0&&(l+=e.askVol,a++);const c=e.high??t[t.length-1]?.price??0,h=e.low??t[0]?.price??0,u=[...t].reverse(),d=r>0?u[i(u.map(e=>e.bidVol+e.askVol),0).poc].price:null;return{bar:e,rows:t,row:Number.isFinite(o)?o:0,high:c,low:h,volume:r,poc:d,sumBid:n,bidCells:s,sumAsk:l,askCells:a}}function ue(e,t={}){const o={...ce,...t};!function(e){for(const t of[e.imbalanceRatio,e.signalLookback,e.nearExtremeRows])if(!Number.isFinite(t)||t<=0)throw new RangeError("Footprint signal ratio and lookbacks must be positive and finite");for(const t of[e.imbalanceThreshold,e.bigOrderMultiple,e.absorptionMultiple,e.flipMinDeltaPct])if(!Number.isFinite(t)||t<0)throw new RangeError("Footprint signal thresholds must be nonnegative and finite");for(const t of[e.stackedImbalances,e.multipleNodeBars,e.flipBars,e.zoneActiveAfter,e.zoneLookback])if(!Number.isSafeInteger(t)||t<0)throw new RangeError("Footprint signal counts must be nonnegative integers");if(1===e.multipleNodeBars)throw new RangeError("Footprint multipleNodeBars must be 0 or at least 2");if("closeInside"!==e.zoneEnd&&"traverse"!==e.zoneEnd&&"touch"!==e.zoneEnd)throw new TypeError("Unknown footprint zone end rule")}(o);const i=e.map(he),r=i.map((e,t)=>({time:e.bar.time,node:!1,flip:0,divergence:void 0!==e.bar.open&&void 0!==e.bar.close&&(e.bar.close>e.bar.open&&e.bar.delta<0||e.bar.close<e.bar.open&&e.bar.delta>0),...de(i,t,o)}));for(let e=0;e<i.length;e++)r[e].flip=me(i,e,o);const n=[],s=o.zoneLookback>0?i.length-o.zoneLookback:0,l=(e,t,r,l)=>{if(t<s)return;const a=i[t].row/2;n.push(function(e,t,o,i){let r=0;for(let n=o+1;n<t.length;n++){const o=t[n],s=o.bar.close,l=!(i.formingLastBar&&n===t.length-1),a=o.high>=e.low&&o.low<=e.high,c=o.high>=e.high&&o.low<=e.low,h=l&&void 0!==s&&s>=e.low&&s<=e.high;if(null!==e.activeTime&&null===e.touchTime&&a&&(e.touchTime=o.bar.time),"touch"===i.zoneEnd?a:"traverse"===i.zoneEnd?c:h||c)return e.endTime=o.bar.time,e;null===e.activeTime&&(o.low>e.high||o.high<e.low)&&++r>=i.zoneActiveAfter&&(e.activeTime=o.bar.time)}return e}({kind:e,time:i[t].bar.time,low:r-a,high:l+a,endTime:null,activeTime:null,touchTime:null},i,t,o))};for(let e=0;e<i.length;e++){const t=i[e];if(o.stackedImbalances>0)for(const i of le(t.bar.cells,o.imbalanceRatio,o.stackedImbalances,t.row||void 0,o.imbalanceThreshold))l("buy"===i.side?"stackedBuy":"stackedSell",e,Math.min(i.startPrice,i.endPrice),Math.max(i.startPrice,i.endPrice));for(const t of r[e].absorption)l("absorption",e,t.low,t.high)}return function(e,t,o,i){if(0===o.multipleNodeBars)return;let r=0;for(let n=1;n<=e.length;n++){const s=e[n-1],l=e[n];if(!(void 0!==l&&null!==s.poc&&null!==l.poc&&Math.abs(s.poc-l.poc)<=1e-6*Math.max(s.row,l.row))){if(n-r>=o.multipleNodeBars&&null!==e[r].poc){for(let e=r;e<n;e++)t[e].node=!0;i(n-1)}r=n}}}(i,r,o,e=>l("node",e,i[e].poc,i[e].poc)),n.sort((e,t)=>e.time-t.time),{bars:r,zones:n,auctions:fe(i,o)}}function de(e,t,o){const i=e[t],r=i.rows.length,n=o.nearExtremeRows;let s=0,l=0,a=0,c=0;for(let i=Math.max(0,t-o.signalLookback+1);i<=t;i++){const t=e[i];s+=t.sumBid,l+=t.bidCells,a+=t.sumAsk,c+=t.askCells}const h=l?s/l:0,u=c?a/c:0,d=l+c?(s+a)/(l+c):0,p={bigBid:null,bigAsk:null,absorption:[]};if(0===r)return p;let m=0,f=0;for(let e=1;e<r;e++)i.rows[e].bidVol>i.rows[m].bidVol&&(m=e),i.rows[e].askVol>i.rows[f].askVol&&(f=e);if(o.bigOrderMultiple>0&&d>0&&(i.bar.delta<0&&m<n&&i.rows[m].bidVol>=o.bigOrderMultiple*d&&(p.bigBid=i.rows[m].price),i.bar.delta>0&&f>=r-n&&i.rows[f].askVol>=o.bigOrderMultiple*d&&(p.bigAsk=i.rows[f].price)),o.absorptionMultiple>0&&h>0&&u>0){let e=-1;for(let t=0;t<=r;t++){const s=i.rows[t],l=void 0!==s&&(t<n||t>=r-n)&&s.bidVol>=o.absorptionMultiple*h&&s.askVol>=o.absorptionMultiple*u,a=l&&e>=0&&pe(i.rows[t-1].price,s.price,i.row);l&&(e<0||a)?e<0&&(e=t):(e>=0&&p.absorption.push({low:i.rows[e].price,high:i.rows[t-1].price}),e=l?t:-1)}}return p}function pe(e,t,o){return o>0&&Math.abs(t-e-o)<=1e-6*o}function me(e,t,o){const i=e[t],r=i.bar.delta;if(0===o.flipBars||0===r||t<o.flipBars||i.volume<=0)return 0;const n=r>0?1:-1;for(let i=t-o.flipBars;i<t;i++)if(Math.sign(e[i].bar.delta)!==-n)return 0;if(Math.abs(r)/i.volume*100<o.flipMinDeltaPct)return 0;const s=[];for(let o=Math.max(0,t-20);o<t;o++)s.push(Math.abs(e[o].bar.delta));if(s.sort((e,t)=>e-t),s.length&&Math.abs(r)<1.5*s[s.length>>1])return 0;let l=n>0?1/0:-1/0,a=l;for(let i=Math.max(0,t-10);i<=t;i++){const r=n>0?e[i].low:e[i].high;a=n>0?Math.min(a,r):Math.max(a,r),i>=t-o.flipBars&&(l=n>0?Math.min(l,r):Math.max(l,r))}return l===a?n:0}function fe(e,t){const o=[],i=t.formingLastBar?e.length-1:e.length;for(let t=0;t<i;t++){const i=e[t],r=i.bar.auction;if(void 0!==r)for(const n of["high","low"]){if(!("high"===n?r.highBid>0&&r.highAsk>0:r.lowBid>0&&r.lowAsk>0))continue;const s="high"===n?i.high:i.low,l=1e-9*Math.max(1,Math.abs(s));let a=null;for(let o=t+1;o<e.length&&null===a;o++)("high"===n?e[o].high>s+l:e[o].low<s-l)&&(a=e[o].bar.time);o.push({time:i.bar.time,side:n,price:s,endTime:a})}}return o}class be{constructor(e){Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),this._opts=e}attached(e){this._host=e}detached(){this._host=null}zOrder(){return"bottom"}autoscaleInfo(){return null}setData(e){this._opts=e,this._host?.requestUpdate()}draw(e,t){const o=this._opts;if(0===o.buckets.length)return;const i=t.dpr,r=o.buckets.reduce((e,t)=>Math.max(e,t.value),0)||1,n=o.width*i,s="left"===o.side?0:t.plotWidth*i,l=Math.max(2*i,t.plotHeight*i/Math.max(1,o.buckets.length)-i);e.save();for(const a of o.buckets){const c=t.priceScale.priceToY(a.price)*i,h=n*(a.value/r),u=a.price<=o.vah&&a.price>=o.val;e.fillStyle=a.price===o.poc?"#f0a020":u?o.vaColor:o.barColor;const d="left"===o.side?s:s-h;e.fillRect(d,c-l/2,h,l)}for(const[r,n]of[[o.poc,"#f0a020"],[o.vah,"#5a6b8c"],[o.val,"#5a6b8c"]]){const o=Math.round(t.priceScale.priceToY(r)*i)+.5;e.strokeStyle=n,e.lineWidth=Math.max(1,Math.round(i)),e.beginPath(),e.moveTo(0,o),e.lineTo(t.plotWidth*i,o),e.stroke()}e.restore()}}function ge(e){const t=e.trim();if(t.startsWith("#")){const e=t.slice(1);if(3===e.length||4===e.length){const[t,o,i,r]=[...e].map(e=>parseInt(e+e,16));return[t,o,i].some(Number.isNaN)?null:{r:t,g:o,b:i,a:4===e.length?r/255:1}}if(6===e.length||8===e.length){const t=parseInt(e.slice(0,6),16);if(Number.isNaN(t))return null;const o=8===e.length?parseInt(e.slice(6,8),16)/255:1;return{r:t>>16&255,g:t>>8&255,b:255&t,a:Number.isNaN(o)?1:o}}return null}const o=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i.exec(t);return null===o?null:{r:Number(o[1]),g:Number(o[2]),b:Number(o[3]),a:void 0===o[4]?1:Number(o[4])}}const we=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};function ve(e,t){const o=ge(e);return null===o?e:`rgba(${o.r},${o.g},${o.b},${t})`}function Me(e,t,o){return e<t?t:e>o?o:e}function _e(e){return`rgb(${Math.round(e.r)},${Math.round(e.g)},${Math.round(e.b)})`}function xe(e,t,o){return{r:e.r+(t.r-e.r)*o,g:e.g+(t.g-e.g)*o,b:e.b+(t.b-e.b)*o,a:1}}function ye(e){return function(e){return.2126*we(e.r)+.7152*we(e.g)+.0722*we(e.b)}({r:Me(e.r,0,255),g:Me(e.g,0,255),b:Me(e.b,0,255),a:e.a})}function ke(e,t){const o=ge(t);if(!o)return e;const i=ye(o),r=e=>{const t=ye(e);return(Math.max(t,i)+.05)/(Math.min(t,i)+.05)},n=(i+.05)/.05>=1.05/(i+.05)?0:255,s={r:n,g:n,b:n},l=ge(e);if(!l)return _e(s);const a=xe(o,l,Math.max(0,Math.min(1,l.a)));if(r(a)>=4.5)return e;let c=0,h=1,u=s;for(let e=0;e<10;e++){const e=(c+h)/2,t=xe(a,s,e),o={r:Math.round(t.r),g:Math.round(t.g),b:Math.round(t.b),a:1};r(o)>=4.5?(h=e,u=o):c=e}return _e(u)}function Se(e,t,o){const i=e.dataLayer.timeToIndex(t);return void 0===i?null:e.timeScale.indexToX(i)+o*e.timeScale.barSpacing/2}function Te(e,t,o,i,r,n,s){const l=t.dpr,a=n?i+r:i-r;e.fillStyle=s,e.beginPath(),e.moveTo(o*l,i*l),e.lineTo((o+r/2)*l,a*l),e.lineTo((o-r/2)*l,a*l),e.closePath(),e.fill()}const Fe={widthFactor:.9,font:10,minTextHeight:11,textFade:4,displayMode:"bidask",volumeDivisor:1,compactNumbers:!0,cellStyle:"heatmap",intensityScope:"bar",textColorMode:"contrast",imbalanceRatio:3,imbalanceThreshold:0,stackedImbalances:3,statsRows:[],tableRows:[],tableLabelWidth:150,statsRowHeight:15,statsPosition:"bottom",cvdOffset:0,cvdReset:"none",tpoMinutes:30,showCandle:!0,showPoc:!0,pocStyle:"marker",pocColor:"#f0a020",showValueArea:!1,valueAreaPercent:.7,radius:2,multipleNodeBars:0,nodeColor:"#e8c547",bigOrderMultiple:0,bigOrderColor:"#2ea8ff",absorptionMultiple:0,absorptionColor:"#a98bf0",signalLookback:10,nearExtremeRows:3,flipBars:0,flipMinDeltaPct:8,showZones:!1,zoneKinds:["stacked","node","absorption"],zoneEnd:"closeInside",zoneActiveAfter:1,zoneLookback:0,showUnfinishedAuctions:!1,showDeltaLabels:!1,markDivergence:!1,divergenceColor:"#f2a33a",showVisibleProfile:!1,profileWidth:100,showEmptyRows:!0,formingLastBar:!0};function Ce(e){if(!Number.isFinite(e))return"-";const t=Number(e.toPrecision(3)),o=Math.abs(t),[i,r]=o>=1e9?["B",1e9]:o>=1e6?["M",1e6]:o>=1e3?["K",1e3]:["",1];return String(Number((t/r).toPrecision(3)))+i}function Ae(e,t,o){const i=ge(e),r=ge(t);if(null===i||null===r)return t;const n=Math.max(0,Math.min(1,o));return`rgb(${Math.round(i.r+(r.r-i.r)*n)},${Math.round(i.g+(r.g-i.g)*n)},${Math.round(i.b+(r.b-i.b)*n)})`}function Pe(e){return{...e,statsRows:[...e.statsRows],tableRows:[...e.tableRows],zoneKinds:[...e.zoneKinds]}}const Ve={startMinute:0},De=new Set(["bidask","imbalance"]),Re={stackedBuy:"stacked",stackedSell:"stacked",node:"node",absorption:"absorption"};const ze={volume:"Volume",bidVolume:"Bid Volume",askVolume:"Ask Volume",delta:"Delta",minDelta:"Min Delta",maxDelta:"Max Delta",deltaPct:"Delta %",cvd:"CVD",trades:"Trades",cumVolume:"Cum Volume",cvdRatio:"CVD / Volume",session:"Session"},Ee={...ze,volume:"Total Volume",bidVolume:"Total Bid Volume",askVolume:"Total Ask Volume",cvd:"Cumulative Delta",cumVolume:"Cumulative Volume",cvdRatio:"Cum. Delta / Volume",session:"Session Letter"};class Be{constructor(e={}){Object.defineProperty(this,"_bars",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_stats",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_signals",{enumerable:!0,configurable:!0,writable:!0,value:{bars:[],zones:[],auctions:[]}}),Object.defineProperty(this,"_cols",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_rc",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inferredStep",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_primed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_liveFrom",{enumerable:!0,configurable:!0,writable:!0,value:-1/0}),Object.defineProperty(this,"_alertHandlers",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_alerted",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),this._opts=Pe({...Fe,...e}),this._validateOptions(this._opts)}attached(e){this._host=e}detached(){this._host=null,this._rc=null,this._cols=[]}zOrder(){return"normal"}_validateOptions(e){for(const t of[e.widthFactor,e.font,e.statsRowHeight,e.tableLabelWidth,e.imbalanceRatio,e.volumeDivisor,e.tpoMinutes,e.profileWidth])if(!Number.isFinite(t)||t<=0)throw new RangeError("Footprint dimensions and ratio must be positive and finite");for(const t of[e.radius,e.minTextHeight,e.textFade,e.imbalanceThreshold])if(!Number.isFinite(t)||t<0)throw new RangeError("Footprint thresholds and radius must be nonnegative and finite");for(const t of[e.cellWidth,e.tickSize])if(void 0!==t&&(!Number.isFinite(t)||t<=0))throw new RangeError("Footprint width and row step must be positive and finite");if(!Number.isSafeInteger(e.stackedImbalances)||e.stackedImbalances<0)throw new RangeError("Footprint stack length must be a nonnegative integer");if(!Number.isFinite(e.cvdOffset))throw new RangeError("Footprint CVD offset must be finite");if(!Number.isFinite(e.valueAreaPercent)||e.valueAreaPercent<=0||e.valueAreaPercent>1)throw new RangeError("Footprint value area must be in (0, 1]");for(const t of[e.statsRows,e.tableRows])if(t.some(e=>!Object.prototype.hasOwnProperty.call(ze,e))||new Set(t).size!==t.length)throw new RangeError("Footprint statistics rows must be known and unique");if(e.zoneKinds.some(e=>"stacked"!==e&&"node"!==e&&"absorption"!==e)||new Set(e.zoneKinds).size!==e.zoneKinds.length)throw new RangeError("Footprint zone kinds must be stacked, node or absorption, each once");ue([],this._signalOptions(e))}_signalOptions(e){return{imbalanceRatio:e.imbalanceRatio,imbalanceThreshold:e.imbalanceThreshold,stackedImbalances:e.stackedImbalances,multipleNodeBars:e.multipleNodeBars,bigOrderMultiple:e.bigOrderMultiple,absorptionMultiple:e.absorptionMultiple,signalLookback:e.signalLookback,nearExtremeRows:e.nearExtremeRows,flipBars:e.flipBars,flipMinDeltaPct:e.flipMinDeltaPct,zoneEnd:e.zoneEnd,zoneActiveAfter:e.zoneActiveAfter,zoneLookback:e.zoneLookback,formingLastBar:e.formingLastBar}}setBars(e){this._bars=e.map(e=>({...e,cells:e.cells.map(e=>({...e})).sort((e,t)=>t.price-e.price)}));let t=1/0;for(const e of this._bars){void 0!==e.rowSize&&e.rowSize>0&&(t=Math.min(t,e.rowSize));for(let o=1;o<e.cells.length;o++){const i=e.cells[o-1].price-e.cells[o].price;i>0&&(t=Math.min(t,i))}}this._inferredStep=Number.isFinite(t)?t:0,this._cols=[],this._recomputeStats(),this._reportTouches(!0),this._host?.requestUpdate()}setOptions(e){const t={...this._opts,...e};this._validateOptions(t),this._opts=Pe(t),this._cols=[],this._recomputeStats(),this._reportTouches(!1),this._host?.requestUpdate()}options(){return Pe(this._opts)}onZoneAlert(e){return this._alertHandlers.add(e),()=>{this._alertHandlers.delete(e)}}_reportTouches(e){const t=this._opts,o=this._bars[this._bars.length-1]?.time;if((void 0===o||o<this._liveFrom)&&(this._primed=!1,this._alerted.clear(),this._liveFrom=-1/0),void 0===o)return;const i=e&&this._primed,r=this._liveFrom;if(e&&(this._primed=!0,this._liveFrom=o),t.showZones)for(const e of this._signals.zones){if(null===e.touchTime||!t.zoneKinds.includes(Re[e.kind]))continue;const o=`${e.kind}|${e.time}|${e.low}`;if(!this._alerted.has(o)&&(this._alerted.add(o),i&&!(e.touchTime<r)))for(const t of[...this._alertHandlers])try{t({zone:{...e},time:e.touchTime})}catch(e){queueMicrotask(()=>{throw e})}}}stats(){return this._stats}signals(){return this._signals}_step(e){return this._opts.tickSize??e.rowSize??this._inferredStep}autoscaleInfo(){let e=1/0,t=-1/0;for(const o of this._bars){const i=this._step(o)/2;for(const r of o.cells)e=Math.min(e,r.price-i),t=Math.max(t,r.price+i);this._opts.showCandle&&(void 0!==o.low&&(e=Math.min(e,o.low)),void 0!==o.high&&(t=Math.max(t,o.high)))}return Number.isFinite(e)?{min:e,max:t}:null}_recomputeStats(){const e=this._opts,t=e.sessionWindow??Ve,o=e.timezone??s,r="session"===e.cvdReset||e.statsRows.includes("session")||e.tableRows.includes("session");let n=e.cvdOffset,l=0,a=NaN;this._stats=this._bars.map(s=>{const c=s.cells.map(e=>e.bidVol+e.askVol),h=c.reduce((e,t)=>e+t,0),u=s.cells.reduce((e,t)=>e+t.bidVol,0),d=s.cells.reduce((e,t)=>e+t.askVol,0),p=i(c,h*e.valueAreaPercent),m=r?A(s.time,t,o):0;return"session"!==e.cvdReset||m===a||Number.isNaN(a)||(n=0,l=0),a=m,n+=s.delta,l+=h,{time:s.time,volume:h,bidVolume:u,askVolume:d,delta:s.delta,minDelta:s.minDelta??null,maxDelta:s.maxDelta??null,deltaPct:h>0?s.delta/h*100:0,cvd:n,cumVolume:l,cvdRatio:l>0?n/l:0,session:r?S(Math.floor((s.time-m)/(60*e.tpoMinutes))):"-",trades:s.tradeCount??null,poc:s.cells[p.poc]?.price??0,vah:s.cells[p.upper]?.price??0,val:s.cells[p.lower]?.price??0}}),this._signals=ue(this._bars,this._signalOptions(e))}_bounds(e,t,o){const i=o.priceScale.priceToY(e);if(!(t>0))return{top:i-8,bottom:i+8};const r=o.priceScale.priceToY(e-t/2),n=o.priceScale.priceToY(e+t/2);return{top:Math.min(r,n),bottom:Math.max(r,n)}}_format(e){return this._opts.compactNumbers||!Number.isFinite(e)?Ce(e):(Math.sign(e)*Math.round(Math.abs(e))).toLocaleString("en-US")}_cellMeasure(e){const t=this._opts.displayMode,o=e.bidVol+e.askVol,i=e.askVol-e.bidVol;return"volume"===t?o:"deltaPct"===t?o>0?Math.abs(i)/o:0:"delta"===t||"volumeDelta"===t||"deltaShadedVolume"===t?Math.abs(i):Math.max(e.bidVol,e.askVol)}_peak(e){if("deltaPct"===this._opts.displayMode)return 1;let t=0;for(const o of e.cells)t=Math.max(t,this._cellMeasure(o));return t}draw(e,t){if(this._rc=t,this._cols=[],0===this._bars.length||t.plotHeight<=0||t.plotWidth<=0)return;const o=this._opts,r=t.dpr,n=o.buyColor??t.theme.upColor,s=o.sellColor??t.theme.downColor,l={buy:n,sell:s,bg:t.theme.background,imbBuy:o.imbalanceBuyColor??n,imbSell:o.imbalanceSellColor??s},a=t.timeScale.barSpacing,c=Math.max(.1,Math.min(o.cellWidth??a*o.widthFactor,.96*a)),h=o.showCandle&&c>=20?Math.min(9,.15*c):0,u=Math.max(.1,c-h),d=o.tableRows.length?o.tableRows:"bottom"===o.statsPosition?o.statsRows:[],p=Math.min(t.plotHeight,d.length*o.statsRowHeight),m=t.plotHeight-p,f=t.timeScale.visibleRange();for(let e=0;e<this._bars.length;e++){const o=this._bars[e];if(!o.cells.length)continue;const i=t.dataLayer.timeToIndex(o.time);if(void 0===i||i<f.from-1||i>f.to+1)continue;const r=t.timeScale.indexToX(i)-c/2+h;r+u<0||r>t.plotWidth||this._cols.push({bar:o,stats:this._stats[e],index:e,x:r+u/2,x0:r,width:u,rowSize:this._step(o),rows:[]})}let b=0;if("visible"===o.intensityScope)for(const e of this._cols)b=Math.max(b,this._peak(e.bar));e.save(),e.beginPath(),e.rect(0,0,t.plotWidth*r,t.plotHeight*r),e.clip(),e.textBaseline="middle",e.save(),e.beginPath(),e.rect(0,0,t.plotWidth*r,m*r),e.clip(),this._drawAcross(e,t,l,m);for(const o of this._cols)this._drawColumn(e,t,o,h,l,m,b);for(const o of this._cols)this._drawUnder(e,t,o,l,m);if(o.showVisibleProfile&&function(e,t,o,r,n,s,l,a,c,h,u,d,p){const m=new Map;for(const e of o)for(const t of e.cells){const e=m.get(t.price)??[0,0];e[0]+=t.bidVol,e[1]+=t.askVol,m.set(t.price,e)}const f=[...m.keys()].sort((e,t)=>t-e),b=f.map(e=>m.get(e)[0]+m.get(e)[1]),g=Math.max(0,...b);if(g<=0||!(r>0))return;const w=i(b,0).poc,v=t.dpr,M=5*p;e.save(),e.beginPath(),e.rect(0,0,(M+n+2)*v,s*v),e.clip(),e.font=p*v+"px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="right",e.textBaseline="middle",f.forEach((o,i)=>{const[f,_]=m.get(o),x=t.priceScale.priceToY(o+r/2),y=t.priceScale.priceToY(o-r/2),k=Math.min(x,y),S=Math.max(1,Math.abs(y-x)-1);if(k>=s||k+S<=0)return;const T=ve(h,.08+.4*b[i]/g);e.fillStyle=c,e.fillRect(0,k*v,M*v,S*v),e.fillStyle=T,e.fillRect(0,k*v,M*v,S*v),i===w&&(e.strokeStyle=u,e.lineWidth=v,e.strokeRect(v/2,k*v+v/2,M*v-v,S*v-v)),S>=.8*p&&(e.fillStyle=ke(h,c),e.fillText(d(b[i]),(M-3)*v,(k+S/2)*v));const F=n*_/g,C=n*f/g;e.fillStyle=ve(l,.8),e.fillRect((M+1)*v,k*v,F*v,S*v),e.fillStyle=ve(a,.8),e.fillRect((M+1+F)*v,k*v,C*v,S*v)}),e.restore()}(e,t,this._cols.map(e=>e.bar),this._cols[0]?.rowSize??0,o.profileWidth,m,o.profileAskColor??l.buy,o.profileBidColor??l.sell,l.bg,o.textColor??t.theme.axisText,o.pocColor,e=>this._format(e/o.volumeDivisor),Math.max(8,o.font-1)),e.restore(),o.statsRows.length&&"bar"===o.statsPosition)for(const o of this._cols)this._drawCard(e,t,o,l,m);d.length&&this._drawFooter(e,t,l,p,d),e.restore()}_drawAcross(e,t,o,i){const r=this._opts,n={stackedBuy:o.imbBuy,stackedSell:o.imbSell,node:r.nodeColor,absorption:r.absorptionColor,auctionHigh:r.auctionHighColor??o.buy,auctionLow:r.auctionLowColor??o.sell};if(r.showZones&&function(e,t,o,i,r){const n=t.dpr;for(const s of o){const o=Se(t,s.time,1),l=null===s.endTime?t.plotWidth:Se(t,s.endTime,-1);if(null===o||null===l||l<=Math.max(0,o)||o>=t.plotWidth)continue;const a=t.priceScale.priceToY(s.high),c=t.priceScale.priceToY(s.low);Math.min(a,c)>=r||(e.fillStyle=ve(i[s.kind],.22),e.fillRect(o*n,Math.min(a,c)*n,(l-o)*n,Math.abs(c-a)*n))}}(e,t,this._signals.zones.filter(e=>r.zoneKinds.includes(Re[e.kind])),n,i),!r.showUnfinishedAuctions)return;const s=new Map(this._bars.map(e=>[e.time,e]));!function(e,t,o,i,r){const n=t.dpr;e.save(),e.lineWidth=n,e.setLineDash([6*n,3*n,n,3*n]);for(const s of o){const o=Se(t,s.time,1),l=null===s.endTime?t.plotWidth:Se(t,s.endTime,-1);if(null===o||null===l||l<=Math.max(0,o)||o>=t.plotWidth)continue;const a=Math.round(r(s)*n)+.5;e.strokeStyle="high"===s.side?i.auctionHigh:i.auctionLow,e.beginPath(),e.moveTo(o*n,a),e.lineTo(l*n,a),e.stroke()}e.restore()}(e,t,this._signals.auctions,n,e=>{const o=s.get(e.time),i=this._step(o),r="high"===e.side?o.cells[0]:o.cells[o.cells.length-1],n=this._bounds(r?.price??e.price,i,t);return"high"===e.side?n.top:n.bottom})}_imbalanceStrength(e,t){if(t<=0)return 1;const o=e/t,i=this._opts.imbalanceRatio;return o>=3*i?1:o>=2*i?.8:.6}_drawColumn(e,o,i,r,n,s,l){const a=this._opts,c=o.dpr,{bar:h,stats:u}=i,{buy:d,sell:p,bg:m,imbBuy:f,imbSell:b}=n,g=i.width*c,w=g/2,v=i.x0*c,M=i.x*c,_=a.showEmptyRows?function(e,o){if(!(o>0)||e.length<2)return e;const i=[];for(let r=0;r<e.length;r++){const n=e[r],s=e[r+1];if(i.push(n),void 0===s)break;const l=Math.round((n.price-s.price)/o)-1;if(!(l>1e3))for(let e=1;e<=l;e++)i.push({price:t(n.price-e*o,o),bidVol:0,askVol:0})}return i}(h.cells,i.rowSize):h.cells,x=ne(h.cells,a.imbalanceRatio,i.rowSize||void 0,a.imbalanceThreshold),y=new Map(i.rowSize>0?h.cells.map(e=>[t(e.price,i.rowSize),e]):[]),k=new Set(x.filter(e=>"buy"===e.side).map(e=>e.price)),S=new Set(x.filter(e=>"sell"===e.side).map(e=>e.price)),T=De.has(a.displayMode),F="visible"===a.intensityScope?l:this._peak(h);let C=0;for(const e of h.cells)C=Math.max(C,T?Math.max(e.bidVol,e.askVol):e.bidVol+e.askVol);const A=this._signals.bars[i.index],P=this._bodyRows(h,_,i.rowSize),V=void 0!==h.open&&void 0!==h.close&&h.close<h.open?a.candleDownColor??p:a.candleUpColor??d,D=void 0!==a.lastPriceColor&&i.index===this._bars.length-1&&void 0!==h.close?this._rowOf(h,h.close,i.rowSize):null;r>0&&this._drawCandle(e,o,i,r,a.candleUpColor??d,a.candleDownColor??p);const R=(e,o)=>{const r=y.get(t(e+(o?-i.rowSize:i.rowSize),i.rowSize));return void 0===r?0:o?r.bidVol:r.askVol};_.forEach(t=>{const r=this._bounds(t.price,i.rowSize,o);if(r.bottom<=0||r.top>=s)return;i.rows.push({cell:t,top:Math.max(0,r.top),bottom:Math.min(s,r.bottom)});const n=r.top*c,l=(r.bottom-r.top)*c,h=Math.max(0,l-Math.min(c,.1*l)),_=Math.max(0,Math.min(1,(r.bottom-r.top-a.minTextHeight)/Math.max(1,a.textFade)+1));if(e.font=a.font*c+"px ui-monospace, SFMono-Regular, Menlo, monospace",T){const i=Math.min(c,.08*w),r=w-i;let s,l;if("imbalance"===a.displayMode){const e=P.has(t.price)?Ae(m,V,.18):m;s=S.has(t.price)?Ae(m,b,this._imbalanceStrength(t.bidVol,R(t.price,!1))):e,l=k.has(t.price)?Ae(m,f,this._imbalanceStrength(t.askVol,R(t.price,!0))):e}const u=S.has(t.price),g=k.has(t.price);this._cell(e,o,t,v,n,r,h,t.bidVol,F,C,u?b:p,d,p,m,u,_,"bid",s),this._cell(e,o,t,M+i,n,r,h,t.askVol,F,C,g?f:d,d,p,m,g,_,"ask",l)}else{const i=t.askVol-t.bidVol,r=t.bidVol+t.askVol,s=this._cellMeasure(t)*("volume"===a.displayMode?1:Math.sign(i)||1),l="deltaPct"===a.displayMode?`${r>0?Math.round(i/r*100):0}%`:"volumeDelta"===a.displayMode?`${this._format(r/a.volumeDivisor)} x ${this._format(i/a.volumeDivisor)}`:this._format(("delta"===a.displayMode?i:r)/a.volumeDivisor),c=i>0?k.has(t.price):i<0&&S.has(t.price),u=c?i>0?f:b:"volume"===a.displayMode&&void 0!==a.volumeColor?a.volumeColor:i>0?d:i<0?p:Ae(d,p,.5);this._cell(e,o,t,v,n,g,h,s,F,C,u,d,p,m,c,_,"single",void 0,l)}if(A?.node&&t.price===u.poc&&(e.fillStyle=ve(a.nodeColor,.35),e.fillRect(v,n,g,h)),D===t.price&&(e.fillStyle=ve(a.lastPriceColor,.45),e.fillRect(v,n,g,h)),a.showPoc&&t.price===u.poc&&("outline"===a.pocStyle?(e.strokeStyle=a.pocColor,e.lineWidth=Math.max(1,c),e.strokeRect(v,n+c/2,g,Math.max(0,h-c))):(e.fillStyle=a.pocColor,e.fillRect(v-2*c,n,2*c,h))),T&&(A?.bigBid===t.price||A?.bigAsk===t.price)){e.strokeStyle=a.bigOrderColor,e.lineWidth=2*c;const o=A.bigBid===t.price?v:M;e.strokeRect(o+c,n+c,w-2*c,Math.max(0,h-2*c))}}),"imbalance"===a.displayMode&&P.size>0&&this._outlineBody(e,o,i,P,V);for(const t of A?.absorption??[]){const r=this._bounds(t.high,i.rowSize,o),n=this._bounds(t.low,i.rowSize,o),s=Math.min(r.top,n.top)*c,l=Math.max(r.bottom,n.bottom)*c-s;e.fillStyle=ve(a.absorptionColor,.3),e.fillRect(v,s,g,l),e.strokeStyle=a.absorptionColor,e.lineWidth=c,e.strokeRect(v,s,g,l)}this._drawValueArea(e,o,i,v,g),this._drawBrackets(e,o,i,f,b)}_bodyRows(e,t,o){const i=new Set;if(void 0===e.open||void 0===e.close||!e.cells.length)return i;const r=this._rowOf(e,Math.max(e.open,e.close),o),n=this._rowOf(e,Math.min(e.open,e.close),o);for(const e of t)e.price<=r&&e.price>=n&&i.add(e.price);return i}_rowOf(e,t,o){let i=e.cells[0].price;for(const o of e.cells)Math.abs(o.price-t)<Math.abs(i-t)&&(i=o.price);return o>0?i:t}_outlineBody(e,t,o,i,r){const n=t.dpr,s=[...i],l=this._bounds(Math.max(...s),o.rowSize,t),a=this._bounds(Math.min(...s),o.rowSize,t),c=Math.min(l.top,a.top),h=Math.max(l.bottom,a.bottom);e.strokeStyle=r,e.lineWidth=1.5*n,e.strokeRect(o.x0*n,c*n,o.width*n,(h-c)*n)}_drawValueArea(e,t,o,i,r){const n=this._opts,s=o.stats;if(!n.showValueArea||s.volume<=0)return;const l=this._bounds(s.vah,o.rowSize,t),a=this._bounds(s.val,o.rowSize,t);e.strokeStyle=n.valueAreaColor??t.theme.axisText,e.lineWidth=t.dpr,e.beginPath();for(const o of[Math.min(l.top,a.top),Math.max(l.bottom,a.bottom)])e.moveTo(i,o*t.dpr),e.lineTo(i+r,o*t.dpr);e.stroke()}_drawBrackets(e,t,o,i,r){const n=this._opts,s=t.dpr;if(n.stackedImbalances<=0||o.width<16)return;const l=le(o.bar.cells,n.imbalanceRatio,n.stackedImbalances,o.rowSize||void 0,n.imbalanceThreshold);for(const n of l){const l=this._bounds(n.startPrice,o.rowSize,t),a=this._bounds(n.endPrice,o.rowSize,t),c=Math.min(l.top,a.top)*s,h=Math.max(l.bottom,a.bottom)*s,u=("buy"===n.side?o.x0+o.width-1:o.x0+1)*s,d=("buy"===n.side?-3:3)*s;e.strokeStyle="buy"===n.side?i:r,e.lineWidth=s,e.beginPath(),e.moveTo(u+d,c),e.lineTo(u,c),e.lineTo(u,h),e.lineTo(u+d,h),e.stroke()}}_columnBottom(e,t){let o=-1/0;for(const i of t.bar.cells)o=Math.max(o,this._bounds(i.price,t.rowSize,e).bottom);if(this._opts.showCandle)for(const i of[t.bar.high,t.bar.low])void 0!==i&&(o=Math.max(o,e.priceScale.priceToY(i)));return o}_drawUnder(e,t,o,i,r){const n=this._opts,s=t.dpr,l=this._signals.bars[o.index];let a=this._columnBottom(t,o)+3;if(n.showDeltaLabels&&o.width>=24){const c=o.bar.delta,h=n.font+5;a+h<=r&&(e.font=`bold ${n.font*s}px ui-monospace, SFMono-Regular, Menlo, monospace`,e.textAlign="center",e.fillStyle=ke(c>0?i.buy:c<0?i.sell:t.theme.axisText,i.bg),e.fillText((c>0?"+":"")+this._format(c/n.volumeDivisor),o.x*s,(a+h/2)*s),n.markDivergence&&l?.divergence&&(e.strokeStyle=n.divergenceColor,e.lineWidth=1.5*s,e.strokeRect((o.x0+1)*s,a*s,(o.width-2)*s,h*s))),a+=h+2}if(!l?.flip)return;const c=Math.min(12,Math.max(6,o.width/5));if(l.flip>0)Te(e,t,o.x,a+1,c,!0,i.buy);else{let r=1/0;for(const e of o.bar.cells)r=Math.min(r,this._bounds(e.price,o.rowSize,t).top);this._opts.showCandle&&void 0!==o.bar.high&&(r=Math.min(r,t.priceScale.priceToY(o.bar.high))),Te(e,t,o.x,r-3,c,!1,i.sell)}}_drawCandle(e,t,o,i,r,n){const s=o.bar,l=t.dpr,a=(o.x0-i/2)*l,c=Math.min(4,.45*i)*l,h=s.high??s.cells[0].price,u=s.low??s.cells[s.cells.length-1].price,d=t.priceScale.priceToY(h)*l,p=t.priceScale.priceToY(u)*l,m=void 0!==s.open&&void 0!==s.close,f=m?s.close>=s.open?r:n:t.theme.axisText;if(e.fillStyle=f,e.fillRect(a,Math.min(d,p),l,Math.max(l,Math.abs(p-d))),m){const o=t.priceScale.priceToY(s.open)*l,i=t.priceScale.priceToY(s.close)*l;e.fillRect(a-c/2,Math.min(o,i),c,Math.max(l,Math.abs(i-o)))}}_cell(e,t,o,i,r,n,s,l,a,c,h,u,d,p,m,f,b,g,w){if(n<=0||s<=0)return;const v=this._opts,M=t.dpr,_="profile"===v.cellStyle&&void 0===g,x=Math.max(0,Math.min(1,a>0?Math.abs(l)/a:0)),y=g??(m?h:Ae(p,h,"ladder"===v.cellStyle?.18+.82*Math.sqrt(x):.08+.62*Math.sqrt(x))),k=_?n*x:n,S=_&&"bid"===b?i+n-k:i;if(k>0&&(e.fillStyle=y,e.beginPath(),e.roundRect(S,r,k,s,"ladder"===v.cellStyle||_?0:Math.min(v.radius*M,s/2,k/2)),e.fill()),f<=0||s<v.font*M*.6)return;const T=w??this._format(l/v.volumeDivisor),F=e.measureText(T).width;if(F+4*M>n)return;e.textAlign=_&&"single"!==b?"bid"===b?"right":"left":"center";const C=_&&"single"!==b?"bid"===b?i+n-2*M:i+2*M:i+n/2,A="right"===e.textAlign?C-F:"left"===e.textAlign?C:C-F/2,P=A+F;let V=y;_&&(0===k||P<=S||A>=S+k?V=p:(A<S||P>S+k)&&(V=p,e.fillStyle=p,e.fillRect(A-M,r,F+2*M,s)));const D=v.textColor??ke(t.theme.axisText,p),R=function(e){const{mode:t,side:o,bidVol:i,askVol:r,neutral:n,buy:s,sell:l}=e,a=r>i?s:i>r?l:n,c="ask"===o?s:"bid"===o?l:a;let h=n;switch(t){case"contrast":break;case"side":h=c;break;case"delta":h=a;break;case"dominant":("single"===o||"ask"===o&&r>i||"bid"===o&&i>r)&&(h=a);break;case"imbalance":e.hot&&(h=c);break;case"volume":{const t="ask"===o?r:"bid"===o?i:r+i,s=e.peak>0?Math.max(0,Math.min(1,t/e.peak)):0;if(s>=1)h=c;else if(s>0&&c!==n){const e=ge(n),t=ge(c);e&&t&&(h=_e(xe(e,t,s)))}break}}return ke(ge(h)?h:n,e.background)}({mode:v.textColorMode,side:b,bidVol:o.bidVol,askVol:o.askVol,peak:c,hot:m,neutral:D,buy:v.buyTextColor??u,sell:v.sellTextColor??d,background:V});e.fillStyle=ve(R,f),e.fillText(T,C,r+s/2)}_drawCard(e,t,o,i,r){const n=this._opts,s=t.dpr;if(o.width<68||0===o.rows.length)return;const l=n.showDeltaLabels&&o.width>=24?n.font+7:0,a=1===this._signals.bars[o.index]?.flip?Math.min(12,Math.max(6,o.width/5))+2:0,c=this._columnBottom(t,o)+8+l+a,h=n.statsRows.length*n.statsRowHeight+8;if(c<0||c+h>r)return;o.card={top:c,bottom:c+h};const u=Ae(i.bg,t.theme.axisText,.13);e.fillStyle=u,e.beginPath(),e.roundRect(o.x0*s,c*s,o.width*s,h*s,2*s),e.fill(),e.font=Math.max(8,n.font-1)*s+"px ui-monospace, SFMono-Regular, Menlo, monospace",n.statsRows.forEach((r,l)=>{const a=this._metric(o.stats,r),h=this._statText(o.stats,r),d=(c+4+(l+.5)*n.statsRowHeight)*s,p=ze[r];if(e.measureText(p).width+e.measureText(h).width+12*s>o.width*s)return;e.textAlign="left",e.fillStyle=ke(n.textColor??t.theme.axisText,u),e.fillText(p,(o.x0+4)*s,d),e.textAlign="right";const m="session"===r?n.sessionColor??n.textColor??t.theme.axisText:n.textColor??t.theme.axisText;e.fillStyle=ke(this._statColor(r,a,m,n.buyTextColor??i.buy,n.sellTextColor??i.sell),u),e.fillText(h,(o.x0+o.width-4)*s,d)})}_drawFooter(e,t,o,i,r){const n=this._opts,s=t.dpr,l=t.plotHeight-i,{buy:a,sell:c}=o,h=n.tableBackground??o.bg,u=Math.min(n.tableLabelWidth,t.plotWidth);e.fillStyle=h,e.fillRect(0,l*s,t.plotWidth*s,i*s),e.font=Math.max(8,n.font-.5)*s+"px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="center";const d=t.timeScale.barSpacing;for(const e of this._cols){const o=t.timeScale.indexToX(t.dataLayer.timeToIndex(e.bar.time)),i=Math.max(u,o-d/2),r=Math.min(t.plotWidth,o+d/2);i<r&&(e.table={left:i,right:r,top:l,bottom:t.plotHeight})}e.save(),e.beginPath(),e.rect(u*s,l*s,(t.plotWidth-u)*s,i*s),e.clip(),r.forEach((o,i)=>{let r="cvdRatio"===o?0:1;for(const e of this._cols)e.table&&(r=Math.max(r,Math.abs(this._metric(e.stats,o)??0)));for(const u of this._cols){if(!u.table)continue;const p=this._metric(u.stats,o),m=p??0,f="session"===o?u.stats.session.charCodeAt(0)%2?.3:.15:.1+.4*(r>0?Math.abs(m)/r:0),b=Ae(h,this._statColor(o,p,t.theme.axisText,a,c),f),g=t.timeScale.indexToX(t.dataLayer.timeToIndex(u.bar.time)),w=(l+i*n.statsRowHeight)*s;e.fillStyle=b,e.fillRect((g-d/2)*s,w+s,Math.max(0,d*s-s),Math.max(0,n.statsRowHeight*s-s));const v=this._statText(u.stats,o),M=e.measureText(v).width/(2*s)+2;g-M<u.table.left||g+M>u.table.right||(e.fillStyle=ke("session"===o?n.sessionColor??n.textColor??t.theme.axisText:n.textColor??t.theme.axisText,b),e.fillText(v,g*s,w+n.statsRowHeight*s/2))}}),e.restore(),e.save(),e.beginPath(),e.rect(0,l*s,u*s,i*s),e.clip();const p=Ae(h,t.theme.axisText,.09);e.fillStyle=p,e.fillRect(0,l*s,u*s,i*s),e.fillStyle=ke(n.textColor??t.theme.axisText,p),e.textAlign="left",r.forEach((t,o)=>e.fillText(Ee[t],6*s,(l+(o+.5)*n.statsRowHeight)*s)),e.restore(),e.strokeStyle=Ae(h,t.theme.axisText,.25),e.lineWidth=s,e.beginPath();for(let o=0;o<=r.length;o++){const i=(l+o*n.statsRowHeight)*s;e.moveTo(0,i),e.lineTo(t.plotWidth*s,i)}e.moveTo(u*s,l*s),e.lineTo(u*s,t.plotHeight*s),e.stroke()}_statColor(e,t,o,i,r){return"session"===e||null===t||0===t||"volume"===e||"trades"===e||"cumVolume"===e?o:"askVolume"===e?i:"bidVolume"===e?r:t>0?i:r}_metric(e,t){return"session"===t?null:e[t]}_statText(e,t){if("session"===t)return e.session;const o=this._metric(e,t);if(null===o)return"-";if("deltaPct"===t)return`${o>=0?"+":""}${o.toFixed(1)}%`;if("cvdRatio"===t)return`${o>=0?"+":""}${o.toFixed(3)}`;const i="trades"===t?o:o/this._opts.volumeDivisor,r="trades"===t?Ce(i):this._format(i);return(e=>"volume"===e||"trades"===e||"bidVolume"===e||"askVolume"===e||"cumVolume"===e)(t)||i<0?r:"+"+r}hitTest(e,t){const o=this.hoverAt(e,t);return o?{externalId:`footprint:${o.time}`,zOrder:"normal",distance:0,cursor:"crosshair"}:null}hoverAt(e,t,o){const i=o??this._rc;if(!i||e<0||e>i.plotWidth||t<0||t>i.plotHeight)return null;const r=this._cols.find(o=>o.table&&e>=o.table.left&&e<o.table.right&&t>=o.table.top&&t<=o.table.bottom);if(r)return{time:r.bar.time,price:null,cell:null,stats:r.stats};const n=this._cols.find(t=>e>=t.x0&&e<=t.x0+t.width);if(!n)return null;const s=n.rows.find(e=>t>=e.top&&t<e.bottom);return s?{time:n.bar.time,price:s.cell.price,cell:s.cell,stats:n.stats}:n.card&&t>=n.card.top&&t<=n.card.bottom?{time:n.bar.time,price:null,cell:null,stats:n.stats}:null}}const Oe=["buyColor","sellColor","volumeColor","candleUpColor","candleDownColor","textColor","imbalanceBuyColor","imbalanceSellColor","lastPriceColor","pocColor","nodeColor","divergenceColor","bigOrderColor","absorptionColor","auctionHighColor","auctionLowColor","profileAskColor","profileBidColor","sessionColor","tableBackground"],Ne=e=>Object.freeze(Object.fromEntries(e.split(" ").map((e,t)=>[Oe[t],`#${e}`]))),Le=Object.freeze({ocean:Ne("1E88E5 E53935 90A4AE 26C6DA FF7043 ECEFF1 00ACC1 F4511E 4DD0E1 FFFFFF FFD54F FFB300 40C4FF B39DDB 26C6DA FF7043 0097A7 E53935 00796B 0D1B2A"),ember:Ne("FF8F00 C62828 BCAAA4 FFB300 D84315 FFF8E1 FFC107 E53935 FFEB3B FFFFFF FFF176 FF6E40 FFD180 CE93D8 FFCA28 EF5350 FB8C00 B71C1C 8D6E63 1E1410"),forest:Ne("2E7D32 AD1457 A5D6A7 66BB6A EC407A F1F8E9 43A047 D81B60 C6FF00 FFFFFF FFEE58 FFA726 80DEEA CE93D8 66BB6A F06292 388E3C C2185B 558B2F 102017"),neon:Ne("00B8D4 FF1744 B388FF 00E676 FF3D00 FFFFFF 00E676 FF1744 FFEA00 FFFFFF FFEA00 FF9100 18FFFF D500F9 76FF03 FF4081 00B8D4 F50057 651FFF 0A0A14"),monochrome:Ne("B0BEC5 546E7A CFD8DC ECEFF1 78909C FFFFFF E0E0E0 616161 90A4AE FFFFFF BDBDBD FFFFFF FFFFFF 9E9E9E E0E0E0 757575 90A4AE 455A64 607D8B 121212"),daylight:Ne("1976D2 D32F2F 546E7A 2E7D32 C62828 1A1A1A 43A047 E53935 4DD0E1 000000 FBC02D F57C00 0288D1 7E57C2 2E7D32 C62828 4A9AA5 E57373 C27A3A ECEFF1")});class je{constructor(e,t,o=1,i){if(Object.defineProperty(this,"_tf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_tickSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rowTicks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rowSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_minSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_time",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_cells",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_ticks",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_delta",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_minDelta",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_maxDelta",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_count",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prints",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_open",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_lastTickTime",{enumerable:!0,configurable:!0,writable:!0,value:-1/0}),Object.defineProperty(this,"_openPrice",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_high",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_low",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_close",{enumerable:!0,configurable:!0,writable:!0,value:0}),this._rowSize=Q(t,o),this._tickSize=t,this._rowTicks=o,this._minSize=X(i),"interval"===e.mode){if(!Number.isFinite(e.seconds)||e.seconds<=0)throw new RangeError("Footprint interval seconds must be positive and finite");if(void 0!==e.anchorSec&&!Number.isFinite(e.anchorSec))throw new RangeError("Footprint anchorSec must be finite")}else if("ticks"===e.mode){if(!Number.isSafeInteger(e.count)||e.count<1)throw new RangeError("Footprint tick count must be a positive integer")}else{if("volume"!==e.mode)throw new TypeError("Unknown footprint timeframe mode");if(!Number.isFinite(e.perBar)||e.perBar<=0)throw new RangeError("Footprint volume perBar must be positive and finite")}this._tf={...e}}_snapshot(){const e=Array.from(this._cells.values(),e=>({...e})).sort((e,t)=>t.price-e.price);return{time:this._time,cells:e,delta:this._delta,minDelta:this._minDelta,maxDelta:this._maxDelta,rowSize:this._rowSize,open:this._openPrice,high:this._high,low:this._low,close:this._close,tradeCount:this._count,auction:J(this._ticks,this._high,this._low,this._tickSize)}}current(){return this._open?this._snapshot():null}_intervalKey(e){if("interval"!==this._tf.mode)return 0;const t=this._tf.anchorSec??0;return t+Math.floor((e-t)/this._tf.seconds)*this._tf.seconds}onTick(e){if(ee(e),!Number.isFinite(e.time))throw new RangeError("Footprint tick time must be finite");if(e.time<this._lastTickTime)throw new RangeError("Footprint tick timestamp is out of order");let t=!this._open;this._open&&(t="interval"===this._tf.mode?this._intervalKey(e.time)!==this._time:"ticks"===this._tf.mode?this._prints>=this._tf.count&&e.time>this._time:this._volume>=this._tf.perBar&&e.time>this._time),t&&(this._cells=new Map,this._ticks=new Map,this._delta=0,this._minDelta=0,this._maxDelta=0,this._count=0,this._prints=0,this._volume=0,this._open=!0,this._openPrice=this._high=this._low=e.price,this._time="interval"===this._tf.mode?this._intervalKey(e.time):e.time);const o=K(e.price,this._tickSize,this._rowTicks);let i=this._cells.get(o);return void 0===i&&(i={price:o,bidVol:0,askVol:0},this._cells.set(o,i)),G(this._ticks,e,this._tickSize),e.qty>=this._minSize&&("bid"===e.side?(i.bidVol+=e.qty,this._delta-=e.qty):(i.askVol+=e.qty,this._delta+=e.qty),this._minDelta=Math.min(this._minDelta,this._delta),this._maxDelta=Math.max(this._maxDelta,this._delta),this._count+=1),this._prints+=1,this._volume+=e.qty,this._high=Math.max(this._high,e.price),this._low=Math.min(this._low,e.price),this._close=e.price,this._lastTickTime=e.time,{bar:this._snapshot(),isNew:t}}}const Ie="profile";export{Fe as DEFAULT_FOOTPRINT_OPTIONS,ce as DEFAULT_FOOTPRINT_SIGNAL_OPTIONS,y as DEFAULT_MARKET_PROFILE_OPTIONS,$ as DEFAULT_MARKET_PROFILE_PRIMITIVE_OPTIONS,g as DEFAULT_VOLUME_PROFILE_FAMILY_OPTIONS,v as DEFAULT_VOLUME_PROFILE_PRIMITIVE_OPTIONS,Le as FOOTPRINT_THEMES,Be as Footprint,je as FootprintAggregator,be as HorizontalProfile,q as MarketProfile,Ie as PROFILE_TIER,H as TPO_PERIOD_COLORS,x as TRADING_HOURS,M as VolumeProfile,t as bucketPrice,Ce as compactVol,Z as computeFootprint,z as computeMarketProfile,_ as computeTpo,r as computeVolumeProfile,w as computeVolumeProfileSessions,ae as createTradeClassifier,se as cumulativeDelta,ne as diagonalImbalances,ue as footprintSignals,F as inWindow,N as nakedLevels,o as priceBuckets,L as rowOf,k as rowTicksFor,le as stackedImbalances,S as tpoLetter};
//# sourceMappingURL=openalgo-charts.profile.mjs.map