charts-core 1.1.21 → 1.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- (function(O,z){typeof exports=="object"&&typeof module<"u"?z(exports,require("d3")):typeof define=="function"&&define.amd?define(["exports","d3"],z):(O=typeof globalThis<"u"?globalThis:O||self,z(O.ChartsCore={},O.d3))})(this,function(O,z){"use strict";var vr=Object.defineProperty;var br=(O,z,ae)=>z in O?vr(O,z,{enumerable:!0,configurable:!0,writable:!0,value:ae}):O[z]=ae;var f=(O,z,ae)=>br(O,typeof z!="symbol"?z+"":z,ae);function ae(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const k=ae(z),ci=i=>{const{svg:e,config:t,y:s,width:n}=i,{margin:a,yAxis:r}=t,{customTicks:o,tickFormat:c,tickValues:h,ticks:u,isShow:g}=r;if(!g)return null;e.append("g").attr("transform",`translate(${n-a.right},0)`).call(_=>{let p=k.axisRight(s);o&&c?p=p.tickFormat(c):p=p.tickFormat(v=>{const b=Number(v),w=C=>C.toString().replace(/\.0+$/,"");return Math.abs(b)>=1e12?w(b/1e12)+"T":Math.abs(b)>=1e9?w(b/1e9)+"B":Math.abs(b)>=1e6?w(b/1e6)+"M":Math.abs(b)>=1e3?w(b/1e3)+"K":w(b)}),o&&u&&(p=Array.isArray(u)?p.ticks(...u):p.ticks(u)),o&&h&&(p=p.tickValues(h)),_.call(p)}).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),i.yTicks=p}).call(_=>_.select(".domain").remove()).call(_=>_.selectAll(".tick line").remove()).call(_=>{const p=_.selectAll(".tick text");p.classed("sc-charts__y-axis-tick",!0).attr("text-anchor","start");const v=p.nodes().map(w=>w.getBBox().width),b=Math.max(...v);_.selectAll(".tick").each(function(w,C){var $;const y=k.select(this),x=y.select("text"),A=v[C],H=b-A,R=y.append("g").attr("transform","translate(10, 0)");x.attr("x",H),x.remove(),($=R.node())==null||$.appendChild(x.node())})}).attr("font-family","inherit")},hi=i=>{const{svg:e,config:t,x:s,height:n}=i,{margin:a,xAxis:r}=t,{isShow:o,tickValues:c,tickFormat:h,customTicks:u,ticks:g}=r;if(!o)return null;e.append("g").attr("transform",`translate(0,${n-a.bottom})`).call(_=>{let p=k.axisBottom(s);u?(h&&(p=p.tickFormat(h)),g&&(p=Array.isArray(g)?p.ticks(...g):p.ticks(g)),c&&(p=p.tickValues(c))):p.ticks(5),_.call(p)}).call(_=>_.select(".domain").remove()).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),i.xTicks=p}).call(_=>_.selectAll(".tick line").remove()).call(_=>_.selectAll(".tick text").classed("sc-charts__x-axis-tick",!0)).attr("font-family","inherit")},di=i=>{const{svg:e,config:t,y:s,width:n}=i,{margin:a,grid:{horizontalStyle:r}}=t;if(r!=="none"){if(r.startsWith("zero-line")){const o=e.append("line").attr("x1",0+a.left).attr("x2",n-a.right).attr("y1",s(0)).attr("y2",s(0)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);r==="zero-line-dashed"&&o.attr("stroke-dasharray","4 4")}r.startsWith("every-line")&&(i.yTicks||s.ticks()).forEach(c=>{const h=e.append("line").attr("x1",0+a.left).attr("x2",n-a.right).attr("y1",s(c)).attr("y2",s(c)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);r==="every-line-dashed"&&h.attr("stroke-dasharray","4 4")})}},ui=i=>{const e=Array.from(i.childNodes);for(let t=0;t<e.length;t++)i.removeChild(e[t])},fi=i=>{const e="http://www.w3.org/2000/svg",t=document.createElement("div");t.className="sc-charts__hovered-circles-tooltip-container",t.style.display="none";const s=document.createElement("div");s.className="sc-charts__hovered-circles-tooltip";const n=document.createElement("div");n.className="sc-charts__hovered-circles-tooltip-arrow";const a=document.createElementNS(e,"svg");a.setAttribute("width","12"),a.setAttribute("height","4"),a.setAttribute("viewBox","0 0 12 4"),a.setAttribute("fill","none"),a.setAttribute("xmlns",e);const r=document.createElementNS(e,"path");return r.setAttribute("d","M6 4L0 0H12L6 4Z"),a.appendChild(r),n.appendChild(a),t.append(n),t.append(s),i.append(t),{tooltipContainer:t,tooltip:s,tooltipArrow:n}},gi=(i,e,{x:t,y:s,r:n=3.5,hr:a=0})=>{if(e)return i.append("image").attr("x",t-6).attr("y",s-6).attr("width",12).attr("height",12).attr("href","data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAxMyAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzE0NTJfNTAwOSkiPgo8cGF0aCBkPSJNNi41MzY0NiAxMS41Njg4QzkuMjA1ODYgMTEuNTY4OCAxMS4zNjk4IDkuNDA0ODMgMTEuMzY5OCA2LjczNTQzQzExLjM2OTggNC4wNjYwNiA5LjIwNTg2IDEuOTAyMSA2LjUzNjQ2IDEuOTAyMUMzLjg2NzA4IDEuOTAyMSAxLjcwMzEyIDQuMDY2MDYgMS43MDMxMiA2LjczNTQzQzEuNzAzMTIgOS40MDQ4MyAzLjg2NzA4IDExLjU2ODggNi41MzY0NiAxMS41Njg4WiIgZmlsbD0iI0ZDRUJFOSIvPgo8cGF0aCBkPSJNMy4xMTcxOSAxMC4xNTM1TDkuOTQ3MTkgMy4zMjM0OSIgc3Ryb2tlPSIjRjE4MTY5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHBhdGggZD0iTTYuNTM2NDYgMTEuNTY4OEM5LjIwNTg2IDExLjU2ODggMTEuMzY5OCA5LjQwNDgzIDExLjM2OTggNi43MzU0M0MxMS4zNjk4IDQuMDY2MDYgOS4yMDU4NiAxLjkwMjEgNi41MzY0NiAxLjkwMjFDMy44NjcwOSAxLjkwMjEgMS43MDMxMiA0LjA2NjA2IDEuNzAzMTIgNi43MzU0M0MxLjcwMzEyIDkuNDA0ODMgMy44NjcwOSAxMS41Njg4IDYuNTM2NDYgMTEuNTY4OFoiIHN0cm9rZT0iI0YxODE2OSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDBfMTQ1Ml81MDA5Ij4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC41MzUxNTYgMC43MzUzNTIpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==");{const r=i.append("g");return r.append("circle").attr("cx",t).attr("cy",s).attr("r",n).classed("sc-charts__hovered-circles",!0),r.append("circle").attr("cx",t).attr("cy",s).attr("r",n+a).classed("sc-charts__hovered-circles_add",!0),r}};function mi(i,e,t,s){if(!i)return null;const n=i.width/2,a=e-n,r=e+n;return a<t?t:r>s?s-i.width:e-n}const dt=(i,{x1:e,x2:t,y1:s,y2:n})=>i.append("line").attr("x1",e).attr("x2",t).attr("y1",s).attr("y2",n).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1),_i=i=>{const{svg:e,config:t,x:s,y:n,height:a,data:r,wrapperNode:o}=i,{margin:c,grid:{verticalStyle:h,tooltipNode:u,hoverCirclesRadius:g,hoverCirclesAdditionalArea:_}}=t;if(h!=="none"&&(h.startsWith("every-line")&&(i.xTicks||s.ticks()).forEach(v=>{const b=e.append("line").attr("x1",s(v)).attr("x2",s(v)).attr("y1",c.top).attr("y2",a-c.bottom).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);h==="every-line-dashed"&&b.attr("stroke-dasharray","4 4")}),h==="hovered-circles")){const p=n.range()[0],v=s(r[0].date),b=s(r[r.length-1].date);dt(e,{x1:v,x2:b,y1:p,y2:p});const{tooltipContainer:w,tooltip:C,tooltipArrow:y}=fi(o);r.forEach((x,A)=>{const H=s(x.date),R=n(x.value),$=r[A-1],P=A>0&&$&&x.value===$.value;P||dt(e,{x1:H,x2:H,y1:R,y2:p});const W=gi(e,P,{x:H,y:p,r:g,hr:_});u&&W.on("mouseover",function(){ui(C),w.style.display="block",C.append(u({date:x.date,value:P?null:x.value}));const K=C.getBoundingClientRect(),Qe=mi(K,s(x.date),i.config.margin.left-i.config.grid.tooltipArrowSize,i.width-i.config.margin.right+i.config.grid.tooltipArrowSize);C.style.left=Qe+"px",y.style.left=s(x.date)+"px"}).on("mouseout",function(){w.style.display="none"})})}},pi=i=>{di(i),_i(i)},vi=i=>{const{svg:e,config:t,width:s,height:n}=i,{margin:a,logo:r}=t;hi(i),ci(i),r&&e.append("image").attr("xlink:href",t.theme==="dark"?r.picDarkTheme:r.picLightTheme).attr("width",r.width).attr("height",r.height).attr("x",r.x??(s-a.left-a.right)/2-r.width/2+a.left).attr("y",r.y??(n-a.top-a.bottom)/2-r.height/2+a.top),pi(i)},ce=(i,e,t)=>{let s=i.select(`#${e}`);return s.empty()&&(s=i.append("linearGradient").attr("gradientUnits","userSpaceOnUse").attr("id",e)),s.attr("x1",t.x1).attr("y1",t.x2).attr("x2",t.y1).attr("y2",t.y2),t.stops.forEach(({offset:n,stopColor:a})=>{s.append("stop").attr("offset",n).attr("stop-color",a)}),s},re=i=>{const e=k.select(i).select("defs");return e.empty()?k.select(i).append("defs"):e},ut=i=>{const{y:e,config:{margin:t}}=i,s=e.range()[0]-e(0),n=e.range()[0]-s>=0?e.range()[0]-s:0,a=s+t.bottom>=0?s+t.bottom:0;return{x:0,y:n,width:"100%",height:a}},ft=(i,e)=>({...i,...e,margin:{...i.margin,...e==null?void 0:e.margin},logo:i.logo&&(e!=null&&e.logo)?{width:e.logo.width??i.logo.width,height:e.logo.height??i.logo.height,picLightTheme:e.logo.picLightTheme??i.logo.picLightTheme,picDarkTheme:e.logo.picDarkTheme??i.logo.picDarkTheme,x:e.logo.x??i.logo.x,y:e.logo.y??i.logo.y}:i.logo,xAxis:{...i.xAxis,...e==null?void 0:e.xAxis},yAxis:{...i.yAxis,...e==null?void 0:e.yAxis},grid:{...i.grid,...e==null?void 0:e.grid},hover:{...i.hover,...e==null?void 0:e.hover},selection:{...i.selection,...e==null?void 0:e.selection}}),gt=(i,e={})=>{const t=i.node(),s=re(t),n=(o,c)=>ce(s,o,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"20%",stopColor:c},{offset:"60%",stopColor:c},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});n("gradient-range-borders-up","var(--sc-color-selection-up)"),n("gradient-range-borders-down","var(--sc-color-selection-down)");const a="sc-charts__border-range-line",r=i.append("line").classed(a,!0).style("display",e.hidden?"none":"block");return{className(o,c){o==="remove"?r.classed(`${a}${c}`,!1):r.classed(`${a}${c}`,!0)},update({x1:o,x2:c,y1:h,y2:u,hidden:g}){o!==void 0&&r.attr("x1",o),c!==void 0&&r.attr("x2",c),h!==void 0&&r.attr("y1",h),u!==void 0&&r.attr("y2",u),g!==void 0&&r.style("display",g?"none":"block")},destroy(){r.remove()}}},Re=(i,e={})=>{const t=i.append("circle").attr("r",e.radius||4).style("display",e.hidden?"none":"block"),s=e.className||"";return s&&t.classed(s,!0),{className(n,a){n==="remove"?t.classed(`${s}${a}`,!1):t.classed(`${s}${a}`,!0)},update({cx:n,cy:a,hidden:r,fill:o}){n!==void 0&&t.attr("cx",n),a!==void 0&&t.attr("cy",a),o!==void 0&&t.attr("fill",o),r!==void 0&&t.style("display",r?"none":"block")},destroy(){t.remove()}}},bi=(i,e={})=>{const t="sc-charts__hover-line",s=i.append("line").style("display",e.hidden?"none":"block").classed(t,!0),n=i.node(),a=re(n);return((o,c)=>ce(a,o,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"15%",stopColor:c},{offset:"75%",stopColor:c},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]}))("hover-line-gradient","var(--sc-color-hover-line)"),{className(o,c){o==="remove"?s.classed(`${t}${c}`,!1):s.classed(`${t}${c}`,!0)},update({x1:o,x2:c,y1:h,y2:u,hidden:g}){o!==void 0&&s.attr("x1",o),c!==void 0&&s.attr("x2",c),h!==void 0&&s.attr("y1",h),u!==void 0&&s.attr("y2",u),g!==void 0&&s.style("display",g?"none":"block")},destroy(){s.remove()}}},te="sc-charts__range-tooltip",mt=k.timeFormat("%b %e, %I:%M %p"),yi=i=>{const e=k.format(",.2f");return`${i<0?"-":""}$${e(Math.abs(i))}`};function wi(i){const e="http://www.w3.org/2000/svg",t=document.createElement("div");t.className=te,t.style.position="absolute",t.style.top="0",t.style.pointerEvents="none",t.style.display="none",i.append(t);const s=document.createElement("div");s.className=`${te}-container`,t.append(s);const n=document.createElement("div");n.className=`${te}-sum`,s.append(n);const a=document.createElement("div");a.className=`${te}-sum-icon`;const r=document.createElementNS(e,"svg");r.setAttribute("width","14"),r.setAttribute("height","14"),r.setAttribute("viewBox","0 0 14 14"),r.setAttribute("fill","none"),r.setAttribute("xmlns",e);const o=document.createElementNS(e,"path");o.setAttribute("d","M7 0.5C5.71442 0.5 4.45772 0.881218 3.3888 1.59545C2.31988 2.30968 1.48676 3.32484 0.994786 4.51256C0.502816 5.70028 0.374095 7.00721 0.624899 8.26809C0.875703 9.52896 1.49477 10.6872 2.40381 11.5962C3.31285 12.5052 4.47104 13.1243 5.73192 13.3751C6.99279 13.6259 8.29973 13.4972 9.48744 13.0052C10.6752 12.5132 11.6903 11.6801 12.4046 10.6112C13.1188 9.54229 13.5 8.28558 13.5 7C13.4982 5.27665 12.8128 3.62441 11.5942 2.40582C10.3756 1.18722 8.72335 0.50182 7 0.5ZM9.35375 6.85375C9.30732 6.90024 9.25217 6.93712 9.19147 6.96228C9.13077 6.98744 9.06571 7.00039 9 7.00039C8.93429 7.00039 8.86923 6.98744 8.80853 6.96228C8.74783 6.93712 8.69269 6.90024 8.64625 6.85375L7.5 5.70687V9.5C7.5 9.63261 7.44732 9.75979 7.35356 9.85355C7.25979 9.94732 7.13261 10 7 10C6.86739 10 6.74022 9.94732 6.64645 9.85355C6.55268 9.75979 6.5 9.63261 6.5 9.5V5.70687L5.35375 6.85375C5.25993 6.94757 5.13268 7.00028 5 7.00028C4.86732 7.00028 4.74007 6.94757 4.64625 6.85375C4.55243 6.75993 4.49972 6.63268 4.49972 6.5C4.49972 6.36732 4.55243 6.24007 4.64625 6.14625L6.64625 4.14625C6.69269 4.09976 6.74783 4.06288 6.80853 4.03772C6.86923 4.01256 6.9343 3.99961 7 3.99961C7.06571 3.99961 7.13077 4.01256 7.19147 4.03772C7.25217 4.06288 7.30732 4.09976 7.35375 4.14625L9.35375 6.14625C9.40024 6.19269 9.43712 6.24783 9.46228 6.30853C9.48744 6.36923 9.5004 6.43429 9.5004 6.5C9.5004 6.56571 9.48744 6.63077 9.46228 6.69147C9.43712 6.75217 9.40024 6.80731 9.35375 6.85375Z"),o.setAttribute("fill","currentColor"),r.appendChild(o),a.appendChild(r),n.append(a);const c=document.createElement("div");n.append(c);const h=document.createElement("div");return h.className=`${te}-time`,s.append(h),{wrapper:t,sumNode:c,timeNode:h}}const xi=i=>{const{wrapper:e,sumNode:t,timeNode:s}=wi(i.wrapperNode);return{className(n,a){n==="remove"?e.classList.remove(`${te}${a}`):e.classList.add(`${te}${a}`)},update({leftPoint:n,rightPoint:a,x:r,y:o,hidden:c,closest:h}){if(n&&a&&h&&r!==void 0){const u=a.value-n.value,{sumFormatter:g,timeFormatter:_}=i.config.selection,p=(i.x(a.date)+i.x(n.date))/2,v=i.x(h.date)<p?"left":"right";let b="",w="";if(g)b=g({left:n.value,right:a.value,direction:v});else{const C=(u/Math.abs(n.value)*100).toFixed(2);b=`${yi(u)} (${C}%)`}_?w=_({left:n.date,right:a.date,direction:v}):w=`${mt(n.date)} to ${mt(a.date)}`,t.textContent=b,s.textContent=w,requestAnimationFrame(()=>{const C=e.getBoundingClientRect(),y=i.wrapperNode.getBoundingClientRect(),x=i.x(n.date),A=i.x(a.date);let R=(x+A)/2-C.width/2;const $=0,P=y.width-C.width;R<$&&(R=$),R>P&&(R=P),e.style.left=`${R}px`,e.style.top=`${o}px`})}c!==void 0&&(e.style.display=c?"none":"block")},destroy(){e.remove()}}},he="sc-charts__hover-tooltip",$e=16,Ci=k.timeFormat("%a, %b %d, %-I:%M %p"),Mi=i=>{const e=k.format(",.2f");return`${i<0?"-":""}$${e(Math.abs(i))}`};function Ti(i){const e=document.createElement("div");e.className=`${he}-container`,e.style.position="absolute",e.style.top="0",e.style.pointerEvents="none",e.style.display="none",i.appendChild(e);const t=document.createElement("div");t.className=`${he}-sum`,e.appendChild(t);const s=document.createElement("div");return s.className=`${he}-time`,e.appendChild(s),{wrapper:e,sumNode:t,timeNode:s}}function Ai(i,e,t){return i?e+$e+i.width<t?e+$e:e-$e-i.width:null}const Si=i=>{const{wrapper:e,sumNode:t,timeNode:s}=Ti(i.wrapperNode);return{className(n,a){n==="remove"?e.classList.remove(`${he}${a}`):e.classList.add(`${he}${a}`)},update({hidden:n,dataItem:a}){if(a){const{sumFormatter:r,timeFormatter:o}=i.config.hover;t.textContent=r?r(a.value):Mi(a.value),s.textContent=o?o(a.date):Ci(a.date),requestAnimationFrame(()=>{const c=e.getBoundingClientRect(),h=Ai(c,i.x(a.date),i.width-i.config.margin.right);h&&(e.style.left=h+"px")})}n!==void 0&&(e.style.display=n?"none":"block")},destroy(){e.remove()}}},ki={margin:{top:10,right:30,bottom:20,left:10},theme:"light",logo:{width:406,height:113,x:null,y:null,picDarkTheme:null,picLightTheme:null},extremePointFormatter:null,hasExtremePoint:!1,hasMainLineArea:!1,hover:{enable:!0,range:"1m",transitionDuration:150,transitionName:"default",sumFormatter:null,timeFormatter:null},selection:{enable:!0,sumFormatter:null,timeFormatter:null},xAxis:{customTicks:!1,tickFormat:null,ticks:null,tickValues:null,isShow:!1},yAxis:{customTicks:!1,tickFormat:null,ticks:null,tickValues:null,isShow:!0},grid:{horizontalStyle:"zero-line-dashed",verticalStyle:"none",tooltipNode:null,tooltipArrowSize:12,hoverCirclesRadius:3.5,hoverCirclesAdditionalArea:2},enableBelowZeroLine:!1,curveTension:1},we=i=>k.curveCardinal.tension(i.config.curveTension),Di=i=>{const{svg:e,data:t,x:s,y:n,config:a}=i,r=e.node(),o=re(r);ce(o,"main-line-area-gradient",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-main-line)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});const h=k.area().x(_=>s(_.date)).y0(n.range()[0]).y1(_=>n(_.value)).curve(we(i)),u="sc-charts__main-line-area",g=e.append("path").datum(t).attr("d",h).attr("class",u).classed(`${u}_hidden`,!a.hasMainLineArea);return{className(_,p){_==="remove"?g.classed(`${u}${p}`,!1):g.classed(`${u}${p}`,!0)},update({data:_,hidden:p}){if(_!==void 0&&g.datum(_).attr("d",h),p!==void 0){if(!a.hasMainLineArea)return null;g.classed(`${u}_hidden`,p)}},destroy(){g.remove()}}},Li=(i,e={})=>{const t="sc-charts__range-line-area",{svg:s,x:n,y:a,config:r,data:o,chartId:c}=i,{clip:h}=e,u=s.node(),g=re(u),_="range-line-area-gradient";ce(g,_+"_up",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-selection-up)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]}),ce(g,_+"_down",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-selection-down)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});const p=k.area().x(y=>n(y.date)).y0(a.range()[0]).y1(y=>a(y.value)).curve(we(i)),v=`${c}-clip-${t}`,w=g.append("clipPath").attr("id",v).append("rect").attr("x",(h==null?void 0:h.x)||0).attr("y",(h==null?void 0:h.y)||0).attr("width",(h==null?void 0:h.width)||"100%").attr("height",(h==null?void 0:h.height)||"100%"),C=s.append("path").datum(o).attr("d",p).attr("class",t).classed(`${t}_hidden`,!r.hasMainLineArea).attr("clip-path",`url(#${v})`);return{className(y,x){y==="remove"?C.classed(`${t}${x}`,!1):C.classed(`${t}${x}`,!0)},update({data:y,hidden:x,clip:A}){y!==void 0&&C.datum(y).attr("d",p),x!==void 0&&C.classed(`${t}_hidden`,x),A!==void 0&&w.attr("x",A.x).attr("y",A.y).attr("width",A.width).attr("height",A.height)},destroy(){C.remove()}}},Oe=(i,e)=>{const{svg:t,data:s,x:n,y:a,chartId:r}=i,{baseClassName:o,id:c,clip:h}=e,u=t.node(),g=re(u),_=k.line().x(C=>n(C.date)).y(C=>a(C.value)).curve(we(i)),p=`${r}-clip-${o}`,b=g.append("clipPath").attr("id",p).append("rect").attr("x",(h==null?void 0:h.x)||0).attr("y",(h==null?void 0:h.y)||0).attr("width",(h==null?void 0:h.width)||"100%").attr("height",(h==null?void 0:h.height)||"100%"),w=t.append("path").classed(o,!0).datum(s).attr("d",_).attr("id",c).attr("clip-path",`url(#${p})`);return{className(C,y){C==="remove"?w.classed(`${o}${y}`,!1):w.classed(`${o}${y}`,!0)},update({data:C,clip:y,hidden:x}){C!==void 0&&w.datum(C).attr("d",_),x!==void 0&&w.classed(`${o}_hidden`,x),y!==void 0&&b.attr("x",y.x).attr("y",y.y).attr("width",y.width).attr("height",y.height)},destroy(){w.remove()}}},Ei=(i,e)=>{const{svg:t,data:s,x:n,y:a,chartId:r,config:o}=i,{baseClassName:c,id:h,clip:u}=e,g=t.node(),_=re(g),p=k.line().x(y=>n(y.date)).y(y=>a(y.value)).curve(we(i)),v=`${r}-clip-${c}`,w=_.append("clipPath").attr("id",v).append("rect").attr("x",(u==null?void 0:u.x)||0).attr("y",(u==null?void 0:u.y)||0).attr("width",(u==null?void 0:u.width)||"100%").attr("height",(u==null?void 0:u.height)||"100%"),C=t.append("path").classed(c,!0).datum(s).attr("d",p).attr("id",h).attr("clip-path",`url(#${v})`);return{className(y,x){y==="remove"?C.classed(`${c}${x}`,!1):C.classed(`${c}${x}`,!0)},update({data:y,clip:x,hidden:A}){y!==void 0&&C.datum(y).attr("d",p),A!==void 0&&C.classed(`${c}_hidden`,A),x!==void 0&&(o.hover.transitionName==="default"?w.transition().duration(o.hover.transitionDuration).attr("x",x.x).attr("y",x.y).attr("width",x.width).attr("height",x.height).ease(k.easeLinear):w.attr("x",x.x).attr("y",x.y).attr("width",x.width).attr("height",x.height))},destroy(){C.remove()}}},Ni=i=>{const e=Math.abs(i);let t;return e>=1e9?t=(i/1e9).toFixed(1)+"B":e>=1e6?t=(i/1e6).toFixed(1)+"M":e>=1e3?t=(i/1e3).toFixed(1)+"K":t=i.toFixed(1),t},Fi=(i,e)=>{const{svg:t,data:s,x:n,y:a}=i,{baseClassName:r}=e,o=t.append("g").classed(r,!0),c=o.append("circle").attr("r",5).classed(`${r}-circle`,!0),h=o.append("text").attr("text-anchor","middle").attr("dy","-9px").classed(`${r}-label`,!0);return(g=>{if(!g||g.length===0)return;const _=g[g.length-1],p=n(_.date),v=a(_.value);c.attr("cx",p).attr("cy",v);const b=i.config.extremePointFormatter||Ni;h.attr("x",p).attr("y",v).text(b(_.value))})(s),{className(g,_){g==="remove"?o.classed(`${r}${_}`,!1):o.classed(`${r}${_}`,!0)},update({hidden:g}){g!==void 0&&o.classed(`${r}_hidden`,g)},destroy(){o.remove()}}},Hi=i=>{const e=Oe(i,{baseClassName:"sc-charts__main-line",id:`${i.chartId}-sc-charts__main-line`}),t=Di(i);let s=null;i.config.hasExtremePoint&&(s=Fi(i,{baseClassName:"sc-charts__extreme-point"}));const n=bi(i.svg),a=Ei(i,{baseClassName:"sc-charts__highlight-line",id:`${i.chartId}-sc-charts__highlight-line`,clip:{x:0,y:0,width:"0",height:"0"}});let r=null;i.config.enableBelowZeroLine&&(r=Oe(i,{baseClassName:"sc-charts__below-zero-line",id:`${i.chartId}-sc-charts__below-zero-line`,clip:ut(i)}));const o=Re(i.svg,{className:"sc-charts__hover-circle",hidden:!0}),c=gt(i.svg),h=gt(i.svg),u=Oe(i,{baseClassName:"sc-charts__range-line",id:`${i.chartId}-sc-charts__range-line`,clip:{x:0,y:0,width:"0",height:"0"}}),g=Re(i.svg,{className:"sc-charts__range-circle-left",hidden:!0}),_=Re(i.svg,{className:"sc-charts__range-circle-right",hidden:!0}),p=xi(i),v=Si(i),b=Li(i);return{hoverLine:n,hoverCircle:o,rangeBorderLeft:c,rangeBorderRight:h,rangeLine:u,rangeLineArea:b,rangeCircleLeft:g,rangeCircleRight:_,mainLine:e,rangeTooltip:p,highlightLine:a,hoverTooltip:v,mainLineArea:t,belowZeroLine:r,extremePoint:s}},Bi=(i,e,t)=>{const s=i.match(/^(\d+)([dMhmw])$/);if(!s)return console.warn("Invalid hoverRange:",i),{x:0,y:0,width:"100%",height:"100%"};const[,n,a]=s,r=parseInt(n,10),[o,c]=t.domain();let h=new Date(o);for(;h<c;){let u=new Date(h);switch(a){case"M":u.setMinutes(u.getMinutes()+r);break;case"h":u.setHours(u.getHours()+r);break;case"d":u.setDate(u.getDate()+r);break;case"w":u.setDate(u.getDate()+r*7);break;case"m":u=new Date(h.getFullYear(),h.getMonth()+r,1);break;default:return{x:0,y:0,width:"100%",height:"100%"}}if(e>=h&&e<u){const g=t(h),_=t(u);return{x:g,y:0,width:_-g,height:"100%"}}h=new Date(u)}if(e.getTime()===c.getTime()){let u=new Date(c);switch(a){case"M":u.setMinutes(u.getMinutes()-r);break;case"h":u.setHours(u.getHours()-r);break;case"d":u.setDate(u.getDate()-r);break;case"w":u.setDate(u.getDate()-r*7);break;case"m":u=new Date(c.getFullYear(),c.getMonth()-r,1);break}const g=t(u),_=t(c);return{x:g,y:0,width:_-g,height:"100%"}}return{x:0,y:0,width:"100%",height:"100%"}},_t=(i,e)=>{var h;const{x:t,y:s,elements:n,config:{margin:a},height:r}=i;n.hoverLine.update({x1:t(e.date),x2:t(e.date),y1:a.top,y2:r-a.bottom,hidden:!1}),n.hoverCircle.update({cx:t(e.date),cy:s(e.value),hidden:!1}),n.hoverTooltip.update({dataItem:e,hidden:!1});const o=Bi(i.config.hover.range,e.date,t);n.highlightLine.update({clip:o,hidden:!1});const c=s.range()[0]-s(0)+a.bottom;c>=0&&((h=n.belowZeroLine)==null||h.update({clip:{...o,y:s(0),height:c}})),n.mainLine.className("add","_muted")},pt=i=>{var t;const{elements:e}=i;e.hoverLine.update({hidden:!0}),e.hoverCircle.update({hidden:!0}),e.highlightLine.update({hidden:!0}),e.mainLine.className("remove","_muted"),e.hoverTooltip.update({hidden:!0}),i.action!=="selection"&&((t=e.belowZeroLine)==null||t.update({clip:ut(i)}))},Ii=(i,e)=>{["rangeBorderLeft","rangeBorderRight","rangeCircleLeft","rangeCircleRight","rangeLine","rangeLineArea","rangeTooltip"].forEach(s=>{e?(i[s].className("remove","_down"),i[s].className("add","_up")):(i[s].className("remove","_up"),i[s].className("add","_down"))})},Ri=(i,e,t)=>{var v;const{x:s,y:n,config:{margin:a},height:r,elements:o}=i,c=s(e.date)<s(t.date)?e:t,h=s(e.date)>=s(t.date)?e:t,u=h.value-c.value>=0,g=s(c.date),_=s(h.date),p=_-g;o.rangeBorderLeft.update({x1:g,x2:g,y1:a.top,y2:r-a.bottom,hidden:!1}),o.rangeBorderRight.update({x1:_,x2:_,y1:a.top,y2:r-a.bottom,hidden:!1}),o.rangeCircleLeft.update({cx:g,cy:n(c.value),hidden:!1}),o.rangeCircleRight.update({cx:_,cy:n(h.value),hidden:!1}),o.rangeLine.update({clip:{x:g,y:0,width:p,height:n.range()[0]},hidden:!1}),o.rangeLineArea.update({clip:{x:g,y:0,width:p,height:n.range()[0]},hidden:!1}),o.rangeTooltip.update({rightPoint:h,leftPoint:c,closest:t,x:g+p/2,y:0,hidden:!1}),(v=o.belowZeroLine)==null||v.update({hidden:!0}),o.mainLineArea.update({hidden:!0}),Ii(o,u),o.mainLine.className("add","_selected-muted")},vt=i=>{var t;const{elements:e}=i;e.rangeLine.update({hidden:!0}),e.rangeLineArea.update({hidden:!0}),e.rangeBorderLeft.update({hidden:!0}),e.rangeBorderRight.update({hidden:!0}),e.rangeCircleLeft.update({hidden:!0}),e.rangeCircleRight.update({hidden:!0}),e.rangeTooltip.update({hidden:!0}),e.mainLine.className("remove","_selected-muted"),e.mainLineArea.update({hidden:!1}),(t=e.belowZeroLine)==null||t.update({hidden:!1})},$i=i=>{const{svg:e,data:t,x:s,config:n,width:a,height:r}=i,{margin:o,hover:c,selection:h}=n;let u=null,g=!1;const _=v=>t.reduce((b,w)=>Math.abs(s(b.date)-v)<Math.abs(s(w.date)-v)?b:w);e.append("rect").attr("width",a-o.left-o.right).attr("height",r-o.top-o.bottom).attr("x",o.left).attr("y",o.top).attr("fill","transparent").on("mousemove",function(v){const[b]=k.pointer(v,this),w=_(b);!g&&c.enable?(i.action="hover",_t(i,w)):(i.action=g?"selection":"none",pt(i)),u&&h.enable&&(i.action="selection",Ri(i,u,w))}).on("mouseleave",()=>{i.action="none",g=!1,u=null,pt(i),vt(i)}).on("mousedown",function(v){if(h.enable){g=!0,i.action="selection";const[b]=k.pointer(v,this);u=_(b)}}).on("mouseup",function(v){const[b]=k.pointer(v,this),w=_(b);g=!1,u=null,i.action="hover",h.enable&&vt(i),c.enable&&_t(i,w)})},Oi=(i,e,t)=>{const{margin:s}=e,n=k.scaleTime(),a=k.extent(i,r=>new Date(r.date));return a[0]==null||a[1]==null?n:n.domain([a[0],a[1]]).range([s.left,t-s.right])},Pi=(i,e,t)=>{const{margin:s}=e,n=k.max(i,r=>r.value)??0,a=k.min(i,r=>r.value)??0;return k.scaleLinear().domain([a,n]).range([t-s.bottom,s.top])},zi=(i,e)=>{const t=k.select(i);if(t.empty())return console.error(`Element with selector ${i} not found!`),null;if(!e.chartId||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(e.chartId))return console.error(`chartId is required and must be a valid id
2
- (only letters, numbers or underscores. The first character must be a letter)`),null;const s=t.append("div"),n=s.append("svg"),a=t.node();let r=a.getBoundingClientRect(),o=r.width,c=r.height,h=ft({...ki},e.config),u=e.data;const g=()=>{r=a.getBoundingClientRect(),o=r.width,c=r.height,_({data:u,config:h})};window.addEventListener("resize",g);const _=(p,v=!1)=>{v&&p.config&&(h=ft(h,p.config)),v&&p.data&&(u=p.data);const b=u.map(A=>({date:new Date(A.date),value:A.value})).sort((A,H)=>A.date.getTime()-H.date.getTime()),w=Oi(b,h,o),C=Pi(b,h,c);s.attr("class",`sc-charts sc-charts__${h.theme}`),n.attr("preserveAspectRatio","xMinYMin meet").attr("viewBox",`0 0 ${o} ${c}`).style("width","100%").style("height","100%").selectAll("*").remove();const y={chartId:e.chartId,svg:n,wrapperNode:s.node(),data:b,x:w,y:C,config:h,action:"none",width:o,height:c};vi(y);const x={...y,elements:Hi(y)};$i(x)};return _(e),{update:p=>_(p,!0),destroy:()=>{window.removeEventListener("resize",g),n.remove()}}};var xe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Vi(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var de={exports:{}};de.exports;var bt;function ji(){return bt||(bt=1,function(i,e){var t=200,s="__lodash_hash_undefined__",n=800,a=16,r=9007199254740991,o="[object Arguments]",c="[object Array]",h="[object AsyncFunction]",u="[object Boolean]",g="[object Date]",_="[object Error]",p="[object Function]",v="[object GeneratorFunction]",b="[object Map]",w="[object Number]",C="[object Null]",y="[object Object]",x="[object Proxy]",A="[object RegExp]",H="[object Set]",R="[object String]",$="[object Undefined]",P="[object WeakMap]",W="[object ArrayBuffer]",K="[object DataView]",Qe="[object Float32Array]",Un="[object Float64Array]",Gn="[object Int8Array]",Zn="[object Int16Array]",qn="[object Int32Array]",Jn="[object Uint8Array]",Qn="[object Uint8ClampedArray]",Kn="[object Uint16Array]",ea="[object Uint32Array]",ta=/[\\^$.*+?()[\]{}|]/g,ia=/^\[object .+?Constructor\]$/,sa=/^(?:0|[1-9]\d*)$/,N={};N[Qe]=N[Un]=N[Gn]=N[Zn]=N[qn]=N[Jn]=N[Qn]=N[Kn]=N[ea]=!0,N[o]=N[c]=N[W]=N[u]=N[K]=N[g]=N[_]=N[p]=N[b]=N[w]=N[y]=N[A]=N[H]=N[R]=N[P]=!1;var Pt=typeof xe=="object"&&xe&&xe.Object===Object&&xe,na=typeof self=="object"&&self&&self.Object===Object&&self,_e=Pt||na||Function("return this")(),zt=e&&!e.nodeType&&e,pe=zt&&!0&&i&&!i.nodeType&&i,Vt=pe&&pe.exports===zt,Ke=Vt&&Pt.process,jt=function(){try{var l=pe&&pe.require&&pe.require("util").types;return l||Ke&&Ke.binding&&Ke.binding("util")}catch{}}(),Yt=jt&&jt.isTypedArray;function aa(l,d,m){switch(m.length){case 0:return l.call(d);case 1:return l.call(d,m[0]);case 2:return l.call(d,m[0],m[1]);case 3:return l.call(d,m[0],m[1],m[2])}return l.apply(d,m)}function ra(l,d){for(var m=-1,M=Array(l);++m<l;)M[m]=d(m);return M}function oa(l){return function(d){return l(d)}}function la(l,d){return l==null?void 0:l[d]}function ca(l,d){return function(m){return l(d(m))}}var ha=Array.prototype,da=Function.prototype,De=Object.prototype,et=_e["__core-js_shared__"],Le=da.toString,ee=De.hasOwnProperty,Wt=function(){var l=/[^.]+$/.exec(et&&et.keys&&et.keys.IE_PROTO||"");return l?"Symbol(src)_1."+l:""}(),Xt=De.toString,ua=Le.call(Object),fa=RegExp("^"+Le.call(ee).replace(ta,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ee=Vt?_e.Buffer:void 0,Ut=_e.Symbol,Gt=_e.Uint8Array;Ee&&Ee.allocUnsafe;var Zt=ca(Object.getPrototypeOf,Object),qt=Object.create,ga=De.propertyIsEnumerable,ma=ha.splice,ie=Ut?Ut.toStringTag:void 0,Ne=function(){try{var l=st(Object,"defineProperty");return l({},"",{}),l}catch{}}(),_a=Ee?Ee.isBuffer:void 0,Jt=Math.max,pa=Date.now,Qt=st(_e,"Map"),ve=st(Object,"create"),va=function(){function l(){}return function(d){if(!ne(d))return{};if(qt)return qt(d);l.prototype=d;var m=new l;return l.prototype=void 0,m}}();function se(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var M=l[d];this.set(M[0],M[1])}}function ba(){this.__data__=ve?ve(null):{},this.size=0}function ya(l){var d=this.has(l)&&delete this.__data__[l];return this.size-=d?1:0,d}function wa(l){var d=this.__data__;if(ve){var m=d[l];return m===s?void 0:m}return ee.call(d,l)?d[l]:void 0}function xa(l){var d=this.__data__;return ve?d[l]!==void 0:ee.call(d,l)}function Ca(l,d){var m=this.__data__;return this.size+=this.has(l)?0:1,m[l]=ve&&d===void 0?s:d,this}se.prototype.clear=ba,se.prototype.delete=ya,se.prototype.get=wa,se.prototype.has=xa,se.prototype.set=Ca;function J(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var M=l[d];this.set(M[0],M[1])}}function Ma(){this.__data__=[],this.size=0}function Ta(l){var d=this.__data__,m=Fe(d,l);if(m<0)return!1;var M=d.length-1;return m==M?d.pop():ma.call(d,m,1),--this.size,!0}function Aa(l){var d=this.__data__,m=Fe(d,l);return m<0?void 0:d[m][1]}function Sa(l){return Fe(this.__data__,l)>-1}function ka(l,d){var m=this.__data__,M=Fe(m,l);return M<0?(++this.size,m.push([l,d])):m[M][1]=d,this}J.prototype.clear=Ma,J.prototype.delete=Ta,J.prototype.get=Aa,J.prototype.has=Sa,J.prototype.set=ka;function oe(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var M=l[d];this.set(M[0],M[1])}}function Da(){this.size=0,this.__data__={hash:new se,map:new(Qt||J),string:new se}}function La(l){var d=Be(this,l).delete(l);return this.size-=d?1:0,d}function Ea(l){return Be(this,l).get(l)}function Na(l){return Be(this,l).has(l)}function Fa(l,d){var m=Be(this,l),M=m.size;return m.set(l,d),this.size+=m.size==M?0:1,this}oe.prototype.clear=Da,oe.prototype.delete=La,oe.prototype.get=Ea,oe.prototype.has=Na,oe.prototype.set=Fa;function le(l){var d=this.__data__=new J(l);this.size=d.size}function Ha(){this.__data__=new J,this.size=0}function Ba(l){var d=this.__data__,m=d.delete(l);return this.size=d.size,m}function Ia(l){return this.__data__.get(l)}function Ra(l){return this.__data__.has(l)}function $a(l,d){var m=this.__data__;if(m instanceof J){var M=m.__data__;if(!Qt||M.length<t-1)return M.push([l,d]),this.size=++m.size,this;m=this.__data__=new oe(M)}return m.set(l,d),this.size=m.size,this}le.prototype.clear=Ha,le.prototype.delete=Ba,le.prototype.get=Ia,le.prototype.has=Ra,le.prototype.set=$a;function Oa(l,d){var m=rt(l),M=!m&&at(l),S=!m&&!M&&si(l),E=!m&&!M&&!S&&ai(l),B=m||M||S||E,L=B?ra(l.length,String):[],I=L.length;for(var G in l)B&&(G=="length"||S&&(G=="offset"||G=="parent")||E&&(G=="buffer"||G=="byteLength"||G=="byteOffset")||ti(G,I))||L.push(G);return L}function tt(l,d,m){(m!==void 0&&!Ie(l[d],m)||m===void 0&&!(d in l))&&it(l,d,m)}function Pa(l,d,m){var M=l[d];(!(ee.call(l,d)&&Ie(M,m))||m===void 0&&!(d in l))&&it(l,d,m)}function Fe(l,d){for(var m=l.length;m--;)if(Ie(l[m][0],d))return m;return-1}function it(l,d,m){d=="__proto__"&&Ne?Ne(l,d,{configurable:!0,enumerable:!0,value:m,writable:!0}):l[d]=m}var za=er();function He(l){return l==null?l===void 0?$:C:ie&&ie in Object(l)?tr(l):or(l)}function Kt(l){return be(l)&&He(l)==o}function Va(l){if(!ne(l)||ar(l))return!1;var d=lt(l)?fa:ia;return d.test(dr(l))}function ja(l){return be(l)&&ni(l.length)&&!!N[He(l)]}function Ya(l){if(!ne(l))return rr(l);var d=ii(l),m=[];for(var M in l)M=="constructor"&&(d||!ee.call(l,M))||m.push(M);return m}function ei(l,d,m,M,S){l!==d&&za(d,function(E,B){if(S||(S=new le),ne(E))Wa(l,d,B,m,ei,M,S);else{var L=M?M(nt(l,B),E,B+"",l,d,S):void 0;L===void 0&&(L=E),tt(l,B,L)}},ri)}function Wa(l,d,m,M,S,E,B){var L=nt(l,m),I=nt(d,m),G=B.get(I);if(G){tt(l,m,G);return}var Y=E?E(L,I,m+"",l,d,B):void 0,ye=Y===void 0;if(ye){var ct=rt(I),ht=!ct&&si(I),li=!ct&&!ht&&ai(I);Y=I,ct||ht||li?rt(L)?Y=L:ur(L)?Y=Ja(L):ht?(ye=!1,Y=Ga(I)):li?(ye=!1,Y=qa(I)):Y=[]:fr(I)||at(I)?(Y=L,at(L)?Y=gr(L):(!ne(L)||lt(L))&&(Y=ir(I))):ye=!1}ye&&(B.set(I,Y),S(Y,I,M,E,B),B.delete(I)),tt(l,m,Y)}function Xa(l,d){return cr(lr(l,d,oi),l+"")}var Ua=Ne?function(l,d){return Ne(l,"toString",{configurable:!0,enumerable:!1,value:_r(d),writable:!0})}:oi;function Ga(l,d){return l.slice()}function Za(l){var d=new l.constructor(l.byteLength);return new Gt(d).set(new Gt(l)),d}function qa(l,d){var m=Za(l.buffer);return new l.constructor(m,l.byteOffset,l.length)}function Ja(l,d){var m=-1,M=l.length;for(d||(d=Array(M));++m<M;)d[m]=l[m];return d}function Qa(l,d,m,M){var S=!m;m||(m={});for(var E=-1,B=d.length;++E<B;){var L=d[E],I=void 0;I===void 0&&(I=l[L]),S?it(m,L,I):Pa(m,L,I)}return m}function Ka(l){return Xa(function(d,m){var M=-1,S=m.length,E=S>1?m[S-1]:void 0,B=S>2?m[2]:void 0;for(E=l.length>3&&typeof E=="function"?(S--,E):void 0,B&&sr(m[0],m[1],B)&&(E=S<3?void 0:E,S=1),d=Object(d);++M<S;){var L=m[M];L&&l(d,L,M,E)}return d})}function er(l){return function(d,m,M){for(var S=-1,E=Object(d),B=M(d),L=B.length;L--;){var I=B[++S];if(m(E[I],I,E)===!1)break}return d}}function Be(l,d){var m=l.__data__;return nr(d)?m[typeof d=="string"?"string":"hash"]:m.map}function st(l,d){var m=la(l,d);return Va(m)?m:void 0}function tr(l){var d=ee.call(l,ie),m=l[ie];try{l[ie]=void 0;var M=!0}catch{}var S=Xt.call(l);return M&&(d?l[ie]=m:delete l[ie]),S}function ir(l){return typeof l.constructor=="function"&&!ii(l)?va(Zt(l)):{}}function ti(l,d){var m=typeof l;return d=d??r,!!d&&(m=="number"||m!="symbol"&&sa.test(l))&&l>-1&&l%1==0&&l<d}function sr(l,d,m){if(!ne(m))return!1;var M=typeof d;return(M=="number"?ot(m)&&ti(d,m.length):M=="string"&&d in m)?Ie(m[d],l):!1}function nr(l){var d=typeof l;return d=="string"||d=="number"||d=="symbol"||d=="boolean"?l!=="__proto__":l===null}function ar(l){return!!Wt&&Wt in l}function ii(l){var d=l&&l.constructor,m=typeof d=="function"&&d.prototype||De;return l===m}function rr(l){var d=[];if(l!=null)for(var m in Object(l))d.push(m);return d}function or(l){return Xt.call(l)}function lr(l,d,m){return d=Jt(d===void 0?l.length-1:d,0),function(){for(var M=arguments,S=-1,E=Jt(M.length-d,0),B=Array(E);++S<E;)B[S]=M[d+S];S=-1;for(var L=Array(d+1);++S<d;)L[S]=M[S];return L[d]=m(B),aa(l,this,L)}}function nt(l,d){if(!(d==="constructor"&&typeof l[d]=="function")&&d!="__proto__")return l[d]}var cr=hr(Ua);function hr(l){var d=0,m=0;return function(){var M=pa(),S=a-(M-m);if(m=M,S>0){if(++d>=n)return arguments[0]}else d=0;return l.apply(void 0,arguments)}}function dr(l){if(l!=null){try{return Le.call(l)}catch{}try{return l+""}catch{}}return""}function Ie(l,d){return l===d||l!==l&&d!==d}var at=Kt(function(){return arguments}())?Kt:function(l){return be(l)&&ee.call(l,"callee")&&!ga.call(l,"callee")},rt=Array.isArray;function ot(l){return l!=null&&ni(l.length)&&!lt(l)}function ur(l){return be(l)&&ot(l)}var si=_a||pr;function lt(l){if(!ne(l))return!1;var d=He(l);return d==p||d==v||d==h||d==x}function ni(l){return typeof l=="number"&&l>-1&&l%1==0&&l<=r}function ne(l){var d=typeof l;return l!=null&&(d=="object"||d=="function")}function be(l){return l!=null&&typeof l=="object"}function fr(l){if(!be(l)||He(l)!=y)return!1;var d=Zt(l);if(d===null)return!0;var m=ee.call(d,"constructor")&&d.constructor;return typeof m=="function"&&m instanceof m&&Le.call(m)==ua}var ai=Yt?oa(Yt):ja;function gr(l){return Qa(l,ri(l))}function ri(l){return ot(l)?Oa(l):Ya(l)}var mr=Ka(function(l,d,m){ei(l,d,m)});function _r(l){return function(){return l}}function oi(l){return l}function pr(){return!1}i.exports=mr}(de,de.exports)),de.exports}var Yi=ji();const Ce=Vi(Yi),yt=12,Wi={candles:{direction:"right",offset:`${Math.round(yt/2)}px`,style:"filled",strokeWidth:1,baseWidth:yt,bodyRatio:.7,zoomOnWheel:"both",scaleSensitivity:.002,limiterOffset:{left:0,right:0},hideMissingData:!1},xAxis:{isShow:!0,position:"bottom",height:20,text:{font:"sans-serif",fontSize:"12px"}},yAxis:{isShow:!0,position:"right",width:50,text:{font:"sans-serif",fontSize:"10px"}},guides:{isShowX:!0,isShowY:!0,formatterX:null,formatterY:null},markers:[],trade:{showHoldTime:!1,holdTimeContent:null,holdTimeDates:null,holdTimePrice:null,showConnectionLine:!0,showLabelButtons:!0}};class Xi{constructor(e){f(this,"_candles");f(this,"_xAxis");f(this,"_yAxis");f(this,"_guides");f(this,"_trade");const t=Ce({},Wi,e);this._candles=t.candles,this._xAxis=t.xAxis,this._yAxis=t.yAxis,this._guides=t.guides,this._trade=t.trade}update(e){const t=Ce({},{candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,trade:this._trade},e);this._candles=t.candles,this._xAxis=t.xAxis,this._yAxis=t.yAxis,this._guides=t.guides,this._trade=t.trade}get candles(){return this._candles}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get guides(){return this._guides}get trade(){return this._trade}}class V{constructor(e){f(this,"x");f(this,"y");f(this,"width");f(this,"height");let t;if(!e)t={x:0,y:0,width:0,height:0};else if(e instanceof HTMLElement||e instanceof Element){const{x:s,y:n,width:a,height:r}=e.getBoundingClientRect();t={x:s,y:n,width:a,height:r}}else t=e;this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}static empty(){return{x:0,y:0,width:0,height:0,left:0,right:0,bottom:0,top:0}}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}}class Ui{constructor(e,t){f(this,"_chart",new V);f(this,"_area",new V);f(this,"_xAxis",new V);f(this,"_yAxis",new V);f(this,"_axisIntersection",new V);const{xAxis:s,yAxis:n}=t;this._chart=new V(e),this._calc(s,n)}_calc(e,t){const s=e.isShow?e.height:0,n=t.isShow?t.width:0,a=this._chart.height-s,r=this._chart.width-n;this._area=new V({x:t.position==="left"?n:0,y:e.position==="top"?s:0,width:r,height:a}),this._xAxis=new V({y:e.position==="top"?0:a,x:t.position==="left"?n:0,height:s,width:r}),this._yAxis=new V({y:e.position==="top"?s:0,x:t.position==="left"?0:r,width:n,height:a}),this._axisIntersection=new V({y:e.position==="top"?0:a,x:t.position==="left"?0:r,width:n,height:s})}updateConfig(e){const{xAxis:t,yAxis:s}=e;this._calc(t,s)}update(e){const{xAxis:t,yAxis:s}=e.config;this._chart=new V(e.container),this._calc(t,s)}get area(){return this._area}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get axisIntersection(){return this._axisIntersection}get chart(){return this._chart}}const Gi=i=>i?new Date(i.close_time).getTime()-new Date(i.open_time).getTime():0;function Zi(i,e){if(i.length<2)return[];const t=[];for(let s=0;s<i.length-1;s++){const n=i[s].close_time.getTime(),a=i[s].open_time.getTime(),o=new Date(i[s+1].open_time).getTime()-n;if(o>=e){const c=Math.floor(o/e),h=[];for(let u=1;u<=c;u++)h.push(a+u*e);h.length>0&&t.push(h)}}return t}function wt(i,e){const t=Gi(i[0]),s=Zi(i,t),n=[];return s.forEach(a=>{if(a.length===0)return;const r=i.find(g=>g.close_time.getTime()===a[0]),o=i.find(g=>g.open_time.getTime()===a[a.length-1]+t);if(!r||!o)throw new Error("[CS_Data] error while creating missing data");const c=r.close,h=o.open;let u=c;a.forEach((g,_)=>{const p=(h-u)/a.length;let v=u+p*_,b=v+p;const w=Math.abs(v-b);let C=Math.max(v,b)+w/2,y=Math.min(v,b)-w/2;if(e.trade){const A=[...e.trade.entries,...e.trade.exits].find(H=>{const R=H.time.getTime();return R>=g&&R<g+t});A&&(A.type==="buy"?(y=A.price,b=Math.max(y,b),v=b+w,C=Math.max(v,b)+w/2,u=v):A.type==="sell"&&(C=A.price,b=Math.min(C,b),v=b-w,y=Math.min(v,b)-w/2,u=v))}const x={open_time:new Date(g),close_time:new Date(g+t),open:v,close:b,high:C,low:y};n.push(x)})}),n}class Pe{constructor(e,t){f(this,"_initialData",[]);f(this,"_preparedData",[]);f(this,"_missingData",[]);f(this,"_count",0);f(this,"_model");f(this,"_interval",0);this._model=t,this.update(e)}_prepare(e){return e.map(t=>({...t,open_time:new Date(t.open_time),close_time:new Date(t.close_time)})).sort((t,s)=>t.open_time.getTime()-s.open_time.getTime())}update(e){this._initialData=e,this._preparedData=this._prepare(e),this._missingData=wt(this._preparedData,this._model),this._count=this._preparedData.length+this._missingData.length,this._interval=new Date(e[0].close_time).getTime()-new Date(e[0].open_time).getTime()}updateMissingCandles(){this._missingData=wt(this._preparedData,this._model)}get initialData(){return this._initialData}get preparedData(){return this._preparedData}get missingData(){return this._missingData}get allData(){return[...this._preparedData,...this._missingData]}get count(){return this._count}get interval(){return this._interval}static findByDate(e,t){return t.find(s=>s.open_time<=e&&s.close_time>e)}}class qi{constructor(){f(this,"listeners",{})}subscribe(e,t){return this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){var s;this.listeners[e]=((s=this.listeners[e])==null?void 0:s.filter(n=>n!==t))||[]}emit(e,...t){var n;const s=t[0];(n=this.listeners[e])==null||n.forEach(a=>{a(s)})}}class xt{constructor(){f(this,"_scale")}domain(){const e=this._scale.domain();if(e.length!==2)throw new Error("Domain length is not 2");return e}setDomain(e){this._scale.domain(e)}range(){const e=this._scale.range();if(e.length!==2)throw new Error("Range length is not 2");return e}setRange(e){this._scale.range(e)}invert(e){return this._scale.invert(e)}ticks(e){return this._scale.ticks(e)}tickFormat(e,t){return this._scale.tickFormat(e,t)}raw(){return this._scale}convert(e){return this._scale(e)}}class Ct extends xt{constructor(){super(),this._scale=k.scaleTime()}}class Ji extends xt{constructor(){super(),this._scale=k.scaleLinear()}}const Mt={x:.2,y:.2},Tt=.001,Qi={s:1e3,M:1e3*60,h:1e3*60*60,d:1e3*60*60*24,w:1e3*60*60*24*7},Ki=i=>{const e=i.match(/^(\d+)([a-zA-Z]+)$/);if(!e)throw new Error(`Invalid offset format: "${i}"`);return[parseInt(e[1]),e[2]]},es=(i,e)=>{const[t,s]=e.domain().map(o=>o.getTime()),n=i.filter(o=>{const c=o.open_time.getTime();return c>=t&&c<=s}),a=k.min(n,o=>o.low),r=k.max(n,o=>o.high);if(a==null||r==null)throw new Error("Invalid Y data");return[a,r]};class ts{constructor(e){this.model=e}initX(e){const t=this.model.candles.preparedData,s=k.extent(t,n=>new Date(n.open_time));if(!s[0]||!s[1])throw new Error("Invalid x data");e.setDomain(s),this.setRange(e,this.model.layout.xAxis),this.setDefaultXDomain(e),this.applyOffset(e)}initY(e,t){const s=es(this.model.candles.preparedData,t);e.setDomain(s),this.setRange(e,this.model.layout.yAxis)}init(e){this.initX(e.x),this.initY(e.y,e.x)}setRange(e,{x:t,y:s,width:n,height:a}){e instanceof Ct?e.setRange([t,t+n]):e.setRange([s+a,s])}setDefaultXDomain(e){const{candles:{count:t},layout:{area:s},config:{candles:{baseWidth:n,bodyRatio:a,direction:r}}}=this.model,[o,c]=e.domain().map(p=>p.getTime()),h=c-o,u=n/a*t,g=h*(s.width/u),_=r==="left"?[new Date(o),new Date(o+g)]:[new Date(c-g),new Date(c)];e.setDomain(_)}applyOffset(e){const{config:{candles:{offset:t,direction:s}},layout:{xAxis:n}}=this.model,[a,r]=Ki(t),o=r==="px"?e.invert(n.x+a).getTime()-e.invert(n.x).getTime():Qi[r]*a,c=s==="left"?-o:o,[h,u]=e.domain();e.setDomain([new Date(h.getTime()+c),new Date(u.getTime()+c)])}}class is{constructor(e){f(this,"_model");f(this,"_scaleX");f(this,"_scaleY");f(this,"_initializer");f(this,"_baseDomain",{x:[new Date,new Date],y:[0,0]});f(this,"scaleFactor",{x:1,y:1});f(this,"panOffset",{x:0,y:0});this._model=e,this._scaleX=new Ct,this._scaleY=new Ji,this._initializer=new ts(e),this._initializer.init({x:this._scaleX,y:this._scaleY}),this._baseDomain={x:this._scaleX.domain(),y:this._scaleY.domain()}}reinit(){this._initializer.init({x:this._scaleX,y:this._scaleY}),this.scaleFactor={x:1,y:1},this.panOffset={x:0,y:0},this._baseDomain={x:this._scaleX.domain(),y:this._scaleY.domain()}}get x(){return this._scaleX}get y(){return this._scaleY}get factorX(){return this.scaleFactor.x}get factorY(){return this.scaleFactor.y}get panOffsetX(){return this.panOffset.x}get panOffsetY(){return this.panOffset.y}fitYToVisibleCandles(){const e=this._model.candles.allData,[t,s]=this._scaleX.domain(),n=e.filter(g=>g.open_time>=t&&g.open_time<=s);if(!n.length)return;const a=Math.min(...n.map(g=>g.low)),r=Math.max(...n.map(g=>g.high)),o=r-a;if(o===0)return;const c=this._baseDomain.y;this.scale("y",(c[1]-c[0])/o,"absolute");const h=this._scaleY.convert((a+r)/2),u=this._scaleY.convert((c[0]+c[1])/2);this.pan("y",u-h,"absolute")}scale(e,t,s="delta"){if(s==="absolute"){const n=Math.max(Mt[e],t);if(Math.abs(n-this.scaleFactor[e])<Tt)return;this.scaleFactor[e]=n}else{const n=this.scaleFactor[e],a=n+t*this._model.config.candles.scaleSensitivity;if(a<Mt[e]||Math.abs(a-n)<Tt)return;this.scaleFactor[e]=a}this._updateDomain(e)}pan(e,t,s="delta"){s==="absolute"?this.panOffset[e]=t:this.panOffset[e]+=t,this._updateDomain(e)}_updateDomain(e){const t=this._baseDomain[e],s=this.scaleFactor[e],n=this.panOffset[e];if(e==="x"){const[a,r]=t,o=r.getTime()-a.getTime(),c=o/s,h=a.getTime()+o/2,u=this._scaleX.invert(0-n).getTime()-this._scaleX.invert(0).getTime();this._scaleX.setDomain([new Date(h-c/2+u),new Date(h+c/2+u)])}else{const[a,r]=t,o=r-a,c=o/s,h=a+o/2,u=this._scaleY.invert(0-n)-this._scaleY.invert(0);this._scaleY.setDomain([h-c/2+u,h+c/2+u])}this._model.eventBus.emit("scale_event")}}class ss{constructor(e,{entry:t=[],exit:s=[]}){f(this,"_model");f(this,"_rawEntry");f(this,"_rawExit");f(this,"_mapped",[]);f(this,"_entries",[]);f(this,"_exits",[]);f(this,"_activeTradeTime",null);f(this,"_hoveredTradeTime",null);this._model=e,this._rawEntry=t,this._rawExit=s,this.recalculate()}_findTradeCandle(e){return t=>e>=t.open_time&&e<t.close_time}recalculate(){const e=this._rawEntry.map(n=>({...n,kind:"entry",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),t=this._rawExit.map(n=>({...n,kind:"exit",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),s=[...e,...t];this._mapped=this._model.candles.allData.map(n=>{const a=s.filter(r=>r.time>=n.open_time&&r.time<n.close_time);return{candle:n,trades:a}}).filter(n=>n.trades.length>0),this._entries=e.sort((n,a)=>n.time.getTime()-a.time.getTime()),this._exits=t.sort((n,a)=>n.time.getTime()-a.time.getTime())}updateTrade({entry:e,exit:t}){this._rawEntry=e,this._rawExit=t,this.recalculate()}setActiveTrade(e,t){this._activeTradeTime=t||null,this._mapped=this._mapped.map(s=>({...s,isActive:e===null?void 0:[e,s.candle.open_time.getTime()===t]}))}setHoveredTrade(e,t){this._hoveredTradeTime=t||null,this._mapped=this._mapped.map(s=>({...s,isHovered:e===null?void 0:[e,s.candle.open_time.getTime()===t]}))}get hasActiveTrade(){return this._activeTradeTime!==null}get hasHoveredTrade(){return this._hoveredTradeTime!==null}get tradedCandles(){return this._mapped}get entries(){return this._entries}get exits(){return this._exits}get entryMinTime(){var e;return((e=this._entries.at(0))==null?void 0:e.time.getTime())??0}get exitMaxTime(){var e;return((e=this._exits.at(-1))==null?void 0:e.time.getTime())??0}get timeRange(){const{allData:e,interval:t}=this._model.candles,s=e.map(r=>r.open_time.getTime());let n=0,a=s.length-1;for(let r=0;r<s.length;r++){const o=s[r],c=o<=this.entryMinTime&&o+t>=this.entryMinTime,h=o<=this.exitMaxTime&&o+t>=this.exitMaxTime;if(n===0&&c&&(n=r),a===s.length-1&&h&&(a=r),n!==0&&a!==s.length-1)break}return s.slice(n,a+1)}get hasTrade(){return this._rawEntry.length>0&&this._rawExit.length>0}get holdTime(){return Math.abs(this.entryMinTime-this.exitMaxTime)}}class ns{constructor(e,t){f(this,"_rawMarkers");f(this,"_markers",[]);f(this,"_model");f(this,"_defaults",{mainColor:"#000000",textColor:"#ffffff",lineColor:"#000000",formatter:{horizontal:e=>e.toString(),vertical:e=>e.toLocaleString()}});this._rawMarkers=t,this._model=e,this.rebuild()}rebuild(){const{layout:{area:e},scales:{y:t},colorScheme:{userMarkers:{default:s}}}=this._model;this._markers=this._rawMarkers.map(n=>{var h;const a={mainColor:n.mainColor??s.main,textColor:n.textColor??s.text,lineColor:n.lineColor??s.line},r=t.convert(n.value),c=(n.formatter??((h=this._defaults.formatter)==null?void 0:h.horizontal)??(u=>u.toString()))(n.value);return{value:n.value,text:c,x:e.x,y:r,startDate:n.startDate?n.startDate instanceof Date?n.startDate:new Date(n.startDate):null,...a}})}updateMarkers(e){this._rawMarkers=e,this.rebuild()}get data(){return this._markers}}const as={bg:"#FFFFFF",axisIntersection:"#FFFFFF",xAxis:{bg:"#FFFFFF",text:"#7F7F83"},yAxis:{bg:"#FFFFFF",text:"#7F7F83"},candles:{risingFill:"#56B683",risingStroke:"#000000",fallingFill:"#F18169",fallingStroke:"#000000",noDataFill:["#d9d9da","#ededed"],noDataStroke:"#000000"},guides:{horizontalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"},verticalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"}},trade:{buyLabel:{main:"#56B683",text:"#ffffff"},sellLabel:{main:"#F18169",text:"#ffffff"},connectionLine:"#D9D9DA",tradeBorders:"#EDEDED",activeLabel:"#007AFF",hold:{main:"#A1BBFF",text:"#ffffff"}},userMarkers:{default:{main:"#EDEDED",text:"#000000",line:"#EDEDED"}},comments:{scaleAnchor:{bgActive:"#007AFF",bgInactive:"#A1BBFF",iconActive:"#FFFFFF",iconInactive:"#004DA1"}}};class rs{constructor(e){f(this,"_scheme");this._scheme=Ce({},as,e),Object.keys(this._scheme).forEach(t=>{Object.defineProperty(this,t,{get:()=>this._scheme[t],enumerable:!0})})}update(e){this._scheme=Ce({},this._scheme,e)}}class os{constructor(e,t){f(this,"_data");f(this,"_callbacks",{onAdd:()=>{},onUpdate:()=>{},onDelete:()=>{}});f(this,"_model");f(this,"_grouped",{});this._data=(e==null?void 0:e.data)||[],this._model=t,this._updateGroups(),e!=null&&e.onAdd&&(this._callbacks.onAdd=e.onAdd),e!=null&&e.onUpdate&&(this._callbacks.onUpdate=e.onUpdate),e!=null&&e.onDelete&&(this._callbacks.onDelete=e.onDelete)}_updateGroups(){this._grouped={};for(const e of this._data){const t=Pe.findByDate(new Date(e.date),this._model.candles.allData);if(!t)continue;const s=t.open_time.getTime();this._grouped[s]||(this._grouped[s]=[]),this._grouped[s].push({...e,candle:t})}}get data(){return this._data}set data(e){this._data=e,this._updateGroups()}get grouped(){return this._grouped}add(e){this._data.push(e),this._updateGroups(),this._callbacks.onAdd(e)}remove(e){this._data=this._data.filter(t=>t.id!==e),this._updateGroups(),this._callbacks.onDelete(e)}update(e,t){this._updateGroups(),this._callbacks.onUpdate(e,t)}}class ls{constructor({chartId:e,container:t,candles:s,config:n,trade:a={entry:[],exit:[]},userMarkers:r=[],colorScheme:o,comments:c}){f(this,"chartId");f(this,"container");f(this,"eventBus",new qi);f(this,"candles");f(this,"config");f(this,"colorScheme");f(this,"layout");f(this,"scales");f(this,"trade");f(this,"userMarkers");f(this,"comments");this.chartId=e,this.container=t,this.candles=new Pe(s,this),this.config=new Xi(n),this.colorScheme=new rs(o),this.layout=new Ui(t,this.config),this.scales=new is(this),this.trade=new ss(this,a),this.candles.updateMissingCandles(),this.trade.recalculate(),this.userMarkers=new ns(this,r),this.comments=new os(c,this)}init(){this.eventBus.emit("init_model")}subscribe(e,t){return this.eventBus.subscribe(e,t)}unsubscribe(e,t){this.eventBus.unsubscribe(e,t)}updateConfig(e){this.eventBus.emit("update_config",e)}updateCandles(e){this.eventBus.emit("update_candles",e)}updateTrade(e){this.eventBus.emit("update_trade",e)}updateUserMarkers(e){this.eventBus.emit("update_user_markers",e)}updateColorScheme(e){this.eventBus.emit("update_color_scheme",e)}updateComments(e){this.eventBus.emit("update_comments",e)}}const Me=window.devicePixelRatio||2;class D{constructor({tag:e,className:t,id:s,textContent:n}){f(this,"_tag");f(this,"_className");f(this,"_id");f(this,"_textContent");f(this,"_node");f(this,"_absolutePosition",new DOMRect);this._tag=e||"div",this._className=t||"",this._id=s||"",this._textContent=n||"";const a=document.createElement(this._tag);this._className&&(a.className=this._className),this._id&&(a.id=this._id),this._textContent&&(a.textContent=this._textContent),this._node=a}get node(){return this._node}position(e,t){const s=typeof e=="number"?e:e.x,n=typeof e=="number"?t:e.y;this.node.style.top=n+"px",this.node.style.left=s+"px"}append(...e){this._node.append(...e)}prepend(...e){this._node.prepend(...e)}remove(){this._node.remove(),this._tag="",this._className="",this._id="",this._textContent=""}get absolutePosition(){return this._absolutePosition}updateAbsolutePosition(){this._absolutePosition=this._node.getBoundingClientRect()}setVisible(e){this.node.style.opacity=e?"1":"0",this.node.style.visibility=e?"visible":"hidden"}}class ue extends D{constructor({className:t,id:s,width:n,height:a,isMain:r}){super({tag:"canvas",className:`${t} sc-charts-cs__canvas ${r?"":"sc-charts-cs__canvas-additional"}`,id:s});f(this,"_ctx");f(this,"_width");f(this,"_height");f(this,"background",null);this._width=n,this._height=a,this.updateSize({width:n,height:a});const o=this._node.getContext("2d");if(!o)throw new Error("Failed to get 2D context");o.scale(Me,Me),this._ctx=o}updateSize({width:t,height:s}){t&&(this._node.width=t*Me,this._node.style.width=`${t}px`,this._width=t),s&&(this._node.height=s*Me,this._node.style.height=`${s}px`,this._height=s)}clear(){this.background?(this._ctx.save(),this._ctx.fillStyle=this.background,this._ctx.fillRect(0,0,this._width,this._height),this._ctx.restore()):this._ctx.clearRect(0,0,this._width,this._height)}get ctx(){return this._ctx}get width(){return this._width}get height(){return this._height}}const cs=10;function hs(i,e){const{layout:{xAxis:t},colorScheme:{xAxis:s},config:{xAxis:n},scales:a}=e,r=a.x.ticks(cs),o=u=>u.getHours()===0&&u.getMinutes()===0,c=k.timeFormat("%d %b"),h=k.timeFormat("%H:%M");i.save(),i.fillStyle=s.bg,i.fillRect(t.x,t.y,t.width,t.height),i.restore(),i.fillStyle=s.text,i.font=`${n.text.fontSize} ${n.text.font}`,i.textAlign="center",i.textBaseline="middle",r.forEach(u=>{const g=a.x.convert(u),_=o(u)?c(u):h(u);i.fillText(_,g,t.y+t.height/2)})}function ds(i,e){const{layout:{yAxis:t},colorScheme:{yAxis:s},config:{yAxis:n},scales:a}=e,r=a.y.ticks(6),o=a.y.tickFormat(6);i.save(),i.fillStyle=s.bg,i.fillRect(t.x,t.y,t.width,t.height),i.restore(),i.fillStyle=s.text,i.font=`${n.text.fontSize} ${n.text.font}`,i.textAlign="center",i.textBaseline="middle",r.forEach(c=>{const h=a.y.convert(c),u=o(c);i.fillText(u,t.x+t.width/2,h)})}const us=(i,e)=>{const{layout:{axisIntersection:t},colorScheme:s}=e;i.save(),i.fillStyle=s.axisIntersection,i.fillRect(t.x,t.y,t.width,t.height),i.restore()};class ze{static xAxis(e,t){hs(e,t)}static yAxis(e,t){ds(e,t)}static intersection(e,t){us(e,t)}}class fs{constructor(e){f(this,"_target");this._target=e}mousemove(e){this._target.addEventListener("mousemove",e)}mouseleave(e){this._target.addEventListener("mouseleave",e)}mousedown(e){this._target.addEventListener("mousedown",e)}mouseup(e){this._target.addEventListener("mouseup",e)}wheel(e){this._target.addEventListener("wheel",e)}dblclick(e){this._target.addEventListener("dblclick",e)}contextmenu(e){this._target.addEventListener("contextmenu",e)}}function Te(i){return i*.1875}const gs=(i,{mainColor:e,textColor:t,symbol:s,x:n,y:a,size:r,fontSize:o})=>{const g=r/16,_=16*g,p=n-_/2,v=a;i.save(),i.translate(p,v),i.scale(g,g),i.beginPath(),i.moveTo(7.85696,.288512),i.lineTo(4.53377,3.11938),i.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),i.lineTo(11.2275,4),i.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),i.lineTo(8.52156,.302869),i.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),i.closePath(),i.fillStyle=e,i.fill(),i.beginPath(),i.moveTo(0,7),i.bezierCurveTo(0,4.79086,1.79086,3,4,3),i.lineTo(12,3),i.bezierCurveTo(14.2091,3,16,4.79086,16,7),i.lineTo(16,15),i.bezierCurveTo(16,17.2091,14.2091,19,12,19),i.lineTo(4,19),i.bezierCurveTo(1.79086,19,0,17.2091,0,15),i.lineTo(0,7),i.closePath(),i.fillStyle=e,i.fill(),i.restore(),i.save(),i.font=`bold ${o}px sans-serif`,i.textAlign="center",i.textBaseline="top",i.textAlign="center",i.textBaseline="middle";const b=a+g*3+.5,w=g*16,C=b+w/2;i.fillStyle=t,i.fillText(s,n,C),i.restore()},ms=(i,{mainColor:e,textColor:t,symbol:s,x:n,y:a,size:r,fontSize:o})=>{const g=r/16,_=16*g,p=n-_/2,v=a;i.save(),i.translate(p,v),i.scale(g,-g),i.beginPath(),i.moveTo(7.85696,.288512),i.lineTo(4.53377,3.11938),i.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),i.lineTo(11.2275,4),i.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),i.lineTo(8.52156,.302869),i.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),i.closePath(),i.fillStyle=e,i.fill(),i.beginPath(),i.moveTo(0,7),i.bezierCurveTo(0,4.79086,1.79086,3,4,3),i.lineTo(12,3),i.bezierCurveTo(14.2091,3,16,4.79086,16,7),i.lineTo(16,15),i.bezierCurveTo(16,17.2091,14.2091,19,12,19),i.lineTo(4,19),i.bezierCurveTo(1.79086,19,0,17.2091,0,15),i.lineTo(0,7),i.closePath(),i.fillStyle=e,i.fill(),i.restore(),i.save(),i.font=`bold ${o}px sans-serif`,i.textAlign="center",i.textBaseline="middle";const b=g*16,w=a-g*19+b/2;i.fillStyle=t,i.fillText(s,n,w),i.restore()};function Ae(i){"@babel/helpers - typeof";return Ae=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ae(i)}var _s=/^\s+/,ps=/\s+$/;function T(i,e){if(i=i||"",e=e||{},i instanceof T)return i;if(!(this instanceof T))return new T(i,e);var t=vs(i);this._originalInput=i,this._r=t.r,this._g=t.g,this._b=t.b,this._a=t.a,this._roundA=Math.round(100*this._a)/100,this._format=e.format||t.format,this._gradientType=e.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=t.ok}T.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var e=this.toRgb();return(e.r*299+e.g*587+e.b*114)/1e3},getLuminance:function(){var e=this.toRgb(),t,s,n,a,r,o;return t=e.r/255,s=e.g/255,n=e.b/255,t<=.03928?a=t/12.92:a=Math.pow((t+.055)/1.055,2.4),s<=.03928?r=s/12.92:r=Math.pow((s+.055)/1.055,2.4),n<=.03928?o=n/12.92:o=Math.pow((n+.055)/1.055,2.4),.2126*a+.7152*r+.0722*o},setAlpha:function(e){return this._a=Et(e),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var e=St(this._r,this._g,this._b);return{h:e.h*360,s:e.s,v:e.v,a:this._a}},toHsvString:function(){var e=St(this._r,this._g,this._b),t=Math.round(e.h*360),s=Math.round(e.s*100),n=Math.round(e.v*100);return this._a==1?"hsv("+t+", "+s+"%, "+n+"%)":"hsva("+t+", "+s+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var e=At(this._r,this._g,this._b);return{h:e.h*360,s:e.s,l:e.l,a:this._a}},toHslString:function(){var e=At(this._r,this._g,this._b),t=Math.round(e.h*360),s=Math.round(e.s*100),n=Math.round(e.l*100);return this._a==1?"hsl("+t+", "+s+"%, "+n+"%)":"hsla("+t+", "+s+"%, "+n+"%, "+this._roundA+")"},toHex:function(e){return kt(this._r,this._g,this._b,e)},toHexString:function(e){return"#"+this.toHex(e)},toHex8:function(e){return xs(this._r,this._g,this._b,this._a,e)},toHex8String:function(e){return"#"+this.toHex8(e)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return this._a==1?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(F(this._r,255)*100)+"%",g:Math.round(F(this._g,255)*100)+"%",b:Math.round(F(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(F(this._r,255)*100)+"%, "+Math.round(F(this._g,255)*100)+"%, "+Math.round(F(this._b,255)*100)+"%)":"rgba("+Math.round(F(this._r,255)*100)+"%, "+Math.round(F(this._g,255)*100)+"%, "+Math.round(F(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:Hs[kt(this._r,this._g,this._b,!0)]||!1},toFilter:function(e){var t="#"+Dt(this._r,this._g,this._b,this._a),s=t,n=this._gradientType?"GradientType = 1, ":"";if(e){var a=T(e);s="#"+Dt(a._r,a._g,a._b,a._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+t+",endColorstr="+s+")"},toString:function(e){var t=!!e;e=e||this._format;var s=!1,n=this._a<1&&this._a>=0,a=!t&&n&&(e==="hex"||e==="hex6"||e==="hex3"||e==="hex4"||e==="hex8"||e==="name");return a?e==="name"&&this._a===0?this.toName():this.toRgbString():(e==="rgb"&&(s=this.toRgbString()),e==="prgb"&&(s=this.toPercentageRgbString()),(e==="hex"||e==="hex6")&&(s=this.toHexString()),e==="hex3"&&(s=this.toHexString(!0)),e==="hex4"&&(s=this.toHex8String(!0)),e==="hex8"&&(s=this.toHex8String()),e==="name"&&(s=this.toName()),e==="hsl"&&(s=this.toHslString()),e==="hsv"&&(s=this.toHsvString()),s||this.toHexString())},clone:function(){return T(this.toString())},_applyModification:function(e,t){var s=e.apply(null,[this].concat([].slice.call(t)));return this._r=s._r,this._g=s._g,this._b=s._b,this.setAlpha(s._a),this},lighten:function(){return this._applyModification(As,arguments)},brighten:function(){return this._applyModification(Ss,arguments)},darken:function(){return this._applyModification(ks,arguments)},desaturate:function(){return this._applyModification(Cs,arguments)},saturate:function(){return this._applyModification(Ms,arguments)},greyscale:function(){return this._applyModification(Ts,arguments)},spin:function(){return this._applyModification(Ds,arguments)},_applyCombination:function(e,t){return e.apply(null,[this].concat([].slice.call(t)))},analogous:function(){return this._applyCombination(Ns,arguments)},complement:function(){return this._applyCombination(Ls,arguments)},monochromatic:function(){return this._applyCombination(Fs,arguments)},splitcomplement:function(){return this._applyCombination(Es,arguments)},triad:function(){return this._applyCombination(Lt,[3])},tetrad:function(){return this._applyCombination(Lt,[4])}},T.fromRatio=function(i,e){if(Ae(i)=="object"){var t={};for(var s in i)i.hasOwnProperty(s)&&(s==="a"?t[s]=i[s]:t[s]=fe(i[s]));i=t}return T(i,e)};function vs(i){var e={r:0,g:0,b:0},t=1,s=null,n=null,a=null,r=!1,o=!1;return typeof i=="string"&&(i=$s(i)),Ae(i)=="object"&&(Z(i.r)&&Z(i.g)&&Z(i.b)?(e=bs(i.r,i.g,i.b),r=!0,o=String(i.r).substr(-1)==="%"?"prgb":"rgb"):Z(i.h)&&Z(i.s)&&Z(i.v)?(s=fe(i.s),n=fe(i.v),e=ws(i.h,s,n),r=!0,o="hsv"):Z(i.h)&&Z(i.s)&&Z(i.l)&&(s=fe(i.s),a=fe(i.l),e=ys(i.h,s,a),r=!0,o="hsl"),i.hasOwnProperty("a")&&(t=i.a)),t=Et(t),{ok:r,format:i.format||o,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:t}}function bs(i,e,t){return{r:F(i,255)*255,g:F(e,255)*255,b:F(t,255)*255}}function At(i,e,t){i=F(i,255),e=F(e,255),t=F(t,255);var s=Math.max(i,e,t),n=Math.min(i,e,t),a,r,o=(s+n)/2;if(s==n)a=r=0;else{var c=s-n;switch(r=o>.5?c/(2-s-n):c/(s+n),s){case i:a=(e-t)/c+(e<t?6:0);break;case e:a=(t-i)/c+2;break;case t:a=(i-e)/c+4;break}a/=6}return{h:a,s:r,l:o}}function ys(i,e,t){var s,n,a;i=F(i,360),e=F(e,100),t=F(t,100);function r(h,u,g){return g<0&&(g+=1),g>1&&(g-=1),g<1/6?h+(u-h)*6*g:g<1/2?u:g<2/3?h+(u-h)*(2/3-g)*6:h}if(e===0)s=n=a=t;else{var o=t<.5?t*(1+e):t+e-t*e,c=2*t-o;s=r(c,o,i+1/3),n=r(c,o,i),a=r(c,o,i-1/3)}return{r:s*255,g:n*255,b:a*255}}function St(i,e,t){i=F(i,255),e=F(e,255),t=F(t,255);var s=Math.max(i,e,t),n=Math.min(i,e,t),a,r,o=s,c=s-n;if(r=s===0?0:c/s,s==n)a=0;else{switch(s){case i:a=(e-t)/c+(e<t?6:0);break;case e:a=(t-i)/c+2;break;case t:a=(i-e)/c+4;break}a/=6}return{h:a,s:r,v:o}}function ws(i,e,t){i=F(i,360)*6,e=F(e,100),t=F(t,100);var s=Math.floor(i),n=i-s,a=t*(1-e),r=t*(1-n*e),o=t*(1-(1-n)*e),c=s%6,h=[t,r,a,a,o,t][c],u=[o,t,t,r,a,a][c],g=[a,a,o,t,t,r][c];return{r:h*255,g:u*255,b:g*255}}function kt(i,e,t,s){var n=[X(Math.round(i).toString(16)),X(Math.round(e).toString(16)),X(Math.round(t).toString(16))];return s&&n[0].charAt(0)==n[0].charAt(1)&&n[1].charAt(0)==n[1].charAt(1)&&n[2].charAt(0)==n[2].charAt(1)?n[0].charAt(0)+n[1].charAt(0)+n[2].charAt(0):n.join("")}function xs(i,e,t,s,n){var a=[X(Math.round(i).toString(16)),X(Math.round(e).toString(16)),X(Math.round(t).toString(16)),X(Nt(s))];return n&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function Dt(i,e,t,s){var n=[X(Nt(s)),X(Math.round(i).toString(16)),X(Math.round(e).toString(16)),X(Math.round(t).toString(16))];return n.join("")}T.equals=function(i,e){return!i||!e?!1:T(i).toRgbString()==T(e).toRgbString()},T.random=function(){return T.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})};function Cs(i,e){e=e===0?0:e||10;var t=T(i).toHsl();return t.s-=e/100,t.s=Se(t.s),T(t)}function Ms(i,e){e=e===0?0:e||10;var t=T(i).toHsl();return t.s+=e/100,t.s=Se(t.s),T(t)}function Ts(i){return T(i).desaturate(100)}function As(i,e){e=e===0?0:e||10;var t=T(i).toHsl();return t.l+=e/100,t.l=Se(t.l),T(t)}function Ss(i,e){e=e===0?0:e||10;var t=T(i).toRgb();return t.r=Math.max(0,Math.min(255,t.r-Math.round(255*-(e/100)))),t.g=Math.max(0,Math.min(255,t.g-Math.round(255*-(e/100)))),t.b=Math.max(0,Math.min(255,t.b-Math.round(255*-(e/100)))),T(t)}function ks(i,e){e=e===0?0:e||10;var t=T(i).toHsl();return t.l-=e/100,t.l=Se(t.l),T(t)}function Ds(i,e){var t=T(i).toHsl(),s=(t.h+e)%360;return t.h=s<0?360+s:s,T(t)}function Ls(i){var e=T(i).toHsl();return e.h=(e.h+180)%360,T(e)}function Lt(i,e){if(isNaN(e)||e<=0)throw new Error("Argument to polyad must be a positive number");for(var t=T(i).toHsl(),s=[T(i)],n=360/e,a=1;a<e;a++)s.push(T({h:(t.h+a*n)%360,s:t.s,l:t.l}));return s}function Es(i){var e=T(i).toHsl(),t=e.h;return[T(i),T({h:(t+72)%360,s:e.s,l:e.l}),T({h:(t+216)%360,s:e.s,l:e.l})]}function Ns(i,e,t){e=e||6,t=t||30;var s=T(i).toHsl(),n=360/t,a=[T(i)];for(s.h=(s.h-(n*e>>1)+720)%360;--e;)s.h=(s.h+n)%360,a.push(T(s));return a}function Fs(i,e){e=e||6;for(var t=T(i).toHsv(),s=t.h,n=t.s,a=t.v,r=[],o=1/e;e--;)r.push(T({h:s,s:n,v:a})),a=(a+o)%1;return r}T.mix=function(i,e,t){t=t===0?0:t||50;var s=T(i).toRgb(),n=T(e).toRgb(),a=t/100,r={r:(n.r-s.r)*a+s.r,g:(n.g-s.g)*a+s.g,b:(n.b-s.b)*a+s.b,a:(n.a-s.a)*a+s.a};return T(r)},T.readability=function(i,e){var t=T(i),s=T(e);return(Math.max(t.getLuminance(),s.getLuminance())+.05)/(Math.min(t.getLuminance(),s.getLuminance())+.05)},T.isReadable=function(i,e,t){var s=T.readability(i,e),n,a;switch(a=!1,n=Os(t),n.level+n.size){case"AAsmall":case"AAAlarge":a=s>=4.5;break;case"AAlarge":a=s>=3;break;case"AAAsmall":a=s>=7;break}return a},T.mostReadable=function(i,e,t){var s=null,n=0,a,r,o,c;t=t||{},r=t.includeFallbackColors,o=t.level,c=t.size;for(var h=0;h<e.length;h++)a=T.readability(i,e[h]),a>n&&(n=a,s=T(e[h]));return T.isReadable(i,s,{level:o,size:c})||!r?s:(t.includeFallbackColors=!1,T.mostReadable(i,["#fff","#000"],t))};var Ve=T.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},Hs=T.hexNames=Bs(Ve);function Bs(i){var e={};for(var t in i)i.hasOwnProperty(t)&&(e[i[t]]=t);return e}function Et(i){return i=parseFloat(i),(isNaN(i)||i<0||i>1)&&(i=1),i}function F(i,e){Is(i)&&(i="100%");var t=Rs(i);return i=Math.min(e,Math.max(0,parseFloat(i))),t&&(i=parseInt(i*e,10)/100),Math.abs(i-e)<1e-6?1:i%e/parseFloat(e)}function Se(i){return Math.min(1,Math.max(0,i))}function j(i){return parseInt(i,16)}function Is(i){return typeof i=="string"&&i.indexOf(".")!=-1&&parseFloat(i)===1}function Rs(i){return typeof i=="string"&&i.indexOf("%")!=-1}function X(i){return i.length==1?"0"+i:""+i}function fe(i){return i<=1&&(i=i*100+"%"),i}function Nt(i){return Math.round(parseFloat(i)*255).toString(16)}function Ft(i){return j(i)/255}var U=function(){var i="[-\\+]?\\d+%?",e="[-\\+]?\\d*\\.\\d+%?",t="(?:"+e+")|(?:"+i+")",s="[\\s|\\(]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")\\s*\\)?",n="[\\s|\\(]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")\\s*\\)?";return{CSS_UNIT:new RegExp(t),rgb:new RegExp("rgb"+s),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+s),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+s),hsva:new RegExp("hsva"+n),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();function Z(i){return!!U.CSS_UNIT.exec(i)}function $s(i){i=i.replace(_s,"").replace(ps,"").toLowerCase();var e=!1;if(Ve[i])i=Ve[i],e=!0;else if(i=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var t;return(t=U.rgb.exec(i))?{r:t[1],g:t[2],b:t[3]}:(t=U.rgba.exec(i))?{r:t[1],g:t[2],b:t[3],a:t[4]}:(t=U.hsl.exec(i))?{h:t[1],s:t[2],l:t[3]}:(t=U.hsla.exec(i))?{h:t[1],s:t[2],l:t[3],a:t[4]}:(t=U.hsv.exec(i))?{h:t[1],s:t[2],v:t[3]}:(t=U.hsva.exec(i))?{h:t[1],s:t[2],v:t[3],a:t[4]}:(t=U.hex8.exec(i))?{r:j(t[1]),g:j(t[2]),b:j(t[3]),a:Ft(t[4]),format:e?"name":"hex8"}:(t=U.hex6.exec(i))?{r:j(t[1]),g:j(t[2]),b:j(t[3]),format:e?"name":"hex"}:(t=U.hex4.exec(i))?{r:j(t[1]+""+t[1]),g:j(t[2]+""+t[2]),b:j(t[3]+""+t[3]),a:Ft(t[4]+""+t[4]),format:e?"name":"hex8"}:(t=U.hex3.exec(i))?{r:j(t[1]+""+t[1]),g:j(t[2]+""+t[2]),b:j(t[3]+""+t[3]),format:e?"name":"hex"}:!1}function Os(i){var e,t;return i=i||{level:"AA",size:"small"},e=(i.level||"AA").toUpperCase(),t=(i.size||"small").toLowerCase(),e!=="AA"&&e!=="AAA"&&(e="AA"),t!=="small"&&t!=="large"&&(t="small"),{level:e,size:t}}function Ps(i,e){const{trade:{tradedCandles:t},scales:{x:s,y:n},colorScheme:a,config:{trade:{showLabelButtons:r}}}=e;if(!r)return;const{trade:o}=a,c=4;t.forEach(({isHovered:h,isActive:u,candle:g,trades:_})=>{const p=s.convert(g.open_time);_.forEach(v=>{const b=v.type==="buy",w=b?o.buyLabel.text:o.sellLabel.text,C=b?"B":"S",y=b?n.convert(g.low)+c:n.convert(g.high)-c,x=b?gs:ms;let A=b?o.buyLabel.main:o.sellLabel.main;h&&h[1]&&h[0]===v.type&&(A=T.mix(A,a.bg,20).toString()),u&&u[1]&&u[0]===v.type&&(A=o.activeLabel),x(i,{x:p,y,symbol:C,mainColor:A,textColor:w,size:16,fontSize:12})})})}function zs(i,e){const{scales:{x:t,factorX:s},layout:{area:n},trade:{tradedCandles:a,exits:r,entries:o},config:{candles:c},colorScheme:{trade:h}}=e;if(a.length===0)return;const u=a.map(_=>_.candle).sort((_,p)=>_.open_time.getTime()-p.open_time.getTime()),g=c.baseWidth/2*s+c.strokeWidth/2;if(i.save(),i.lineWidth=1,i.strokeStyle=h.tradeBorders,o.length){const _=t.convert(u[0].open_time)-g;i.beginPath(),i.moveTo(_,n.y),i.lineTo(_,n.y+n.height),i.stroke()}if(r.length){const _=t.convert(u[u.length-1].open_time)+g;i.beginPath(),i.moveTo(_,n.y),i.lineTo(_,n.y+n.height),i.stroke()}i.restore()}const Vs=(i,e)=>{const{scales:{x:t,y:s},trade:{tradedCandles:n,entries:a,exits:r},colorScheme:{trade:o},config:{trade:{showConnectionLine:c}}}=e;if(i.save(),!c)return;const h=g=>{var _;return(_=n.find(p=>g.getTime()>=p.candle.open_time.getTime()&&g.getTime()<p.candle.close_time.getTime()))==null?void 0:_.candle},u=(g,_)=>{const p=h(g.time),v=h(_.time);if(!p||!v)return;const b=t.convert(p.open_time),w=t.convert(v.open_time);let C,y;g.type==="buy"?(C=s.convert(p.low),y=s.convert(v.high)):(C=s.convert(p.high),y=s.convert(v.low)),i.beginPath(),i.setLineDash([4,4]),i.strokeStyle=o.connectionLine,i.moveTo(b,C),i.lineTo(w,y),i.stroke(),i.setLineDash([])};if(a.length===1&&r.length>1)r.forEach(g=>u(a[0],g));else if(r.length===1&&a.length>1)a.forEach(g=>u(g,r[0]));else if(a.length===1&&r.length===1)u(a[0],r[0]);else if(a.length>0&&r.length>0){const g=a.reduce((p,v)=>p.time<v.time?p:v),_=r.reduce((p,v)=>p.time>v.time?p:v);u(g,_)}i.restore()},Ht=(i,e)=>{const{radius:t,coords:{x:s,y:n},fillColor:a,width:r,height:o}=e;i.beginPath(),i.fillStyle=a,i.lineWidth=1,i.moveTo(s+t,n),i.lineTo(s+r-t,n),i.quadraticCurveTo(s+r,n,s+r,n+t),i.lineTo(s+r,n+o-t),i.quadraticCurveTo(s+r,n+o,s+r-t,n+o),i.lineTo(s+t,n+o),i.quadraticCurveTo(s,n+o,s,n+o-t),i.lineTo(s,n+t),i.quadraticCurveTo(s,n,s+t,n),i.closePath(),i.fill()},js=i=>{const e=Math.floor((Date.now()-+i)/1e3),t=[[60,1,"s"],[3600,60,"m"],[86400,3600,"h"],[604800,86400,"d"],[2629746,604800,"w"],[31556952,2629746,"mo"],[1/0,31556952,"y"]],[,s,n]=t.find(([r])=>e<r);return`${Math.floor(e/s)}${n} ago`};function Ys(i){const e=Math.floor(i/1e3),t=[{label:"d",value:86400},{label:"h",value:3600},{label:"m",value:60},{label:"s",value:1}],s=[];let n=e;for(const{label:a,value:r}of t)if(n>=r){const o=Math.floor(n/r);if(s.push(`${o}${a}`),n%=r,s.length===2)break}return s.length?s.join(" "):"0s"}const Ws=10,Xs=6,Us=4,Gs=12,Zs=(i,e)=>{var W;const{scales:{x:t,y:s},trade:{entries:n,exits:a,holdTime:r},colorScheme:{trade:{hold:o}},config:{trade:{showHoldTime:c,holdTimeContent:h,holdTimeDates:u,holdTimePrice:g}}}=e;if(!c)return;const _=n.at(0),p=a.at(-1);if(!_||!p)return;const v=K=>K?K instanceof Date?K:new Date(K):null,b=t.convert(v(u==null?void 0:u[0])||_.candle.open_time),w=t.convert(v(u==null?void 0:u[1])||p.candle.open_time),C=s.convert(g||(((W=n.at(0))==null?void 0:W.price)??0));i.beginPath(),i.setLineDash([4,4]),i.strokeStyle=o.main,i.moveTo(b,C),i.lineTo(w,C),i.stroke(),i.setLineDash([]);const y=(b+w)/2,x=h||`Hold: ${Ys(r)}`,H=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();i.font=`600 ${Ws}px ${H}`;const $=i.measureText(x).width+Xs*2,P=Gs+Us*2;Ht(i,{radius:4,coords:{x:y-$/2,y:C-P/2},width:$,height:P,fillColor:o.main}),i.fillStyle=o.text,i.textBaseline="middle",i.textAlign="center",i.fillText(x,y,C),i.restore()};class ge{constructor(e,t,{CanvasClass:s=ue,noCanvas:n=!1,noDOM:a=!1}={}){f(this,"canvas",null);f(this,"dom",null);f(this,"prefix");const{width:r,height:o,canvasesContainer:c,domElements:h}=t;n||(this.canvas=new s({className:`sc-charts-cs__canvas-${e}`,width:r,height:o}),c.append(this.canvas.node)),a||(this.dom=new D({className:`sc-charts-cs__dom-${e}`}),h.append(this.dom.node)),this.prefix=`sc-charts-cs__${e}`}cx(...e){return e.map(t=>`${this.prefix}-${t}`).join(" ")}cxFabric(...e){return t=>e.map(s=>`${this.prefix}-${s}-${t}`).join(" ")}}const qs={"right-bottom":{dx:1,dy:1},"left-top":{dx:-1,dy:-1},"right-top":{dx:1,dy:-1},"left-bottom":{dx:-1,dy:1}},je=({size:i,parent:e,coords:t,prioritySide:s="right-bottom",offset:n=8})=>{const{width:a,height:r}=i,o=e.right-e.left,c=e.bottom-e.top,h=y=>{const{dx:x,dy:A}=qs[y],H=t.x+(x===1?n:-a-n),R=t.y+(A===1?n:-r-n);return{x:H,y:R,side:y}},u=({x:y,y:x})=>y>=0&&x>=0&&y+a<=o&&x+r<=c,g=()=>{const y=t.y<0,x=t.y+r>c,A=t.x<0,H=t.x+a>o;return A&&y?"right-bottom":A&&x?"right-top":H&&y?"left-bottom":H&&x?"left-top":A?"right-bottom":H?"left-bottom":y?"right-bottom":x?"right-top":s},p=[s,"right-bottom","right-top","left-bottom","left-top"].filter((y,x,A)=>A.indexOf(y)===x),v=g();let b=null;for(const y of[v,...p]){const x=h(y);if(u(x)){b=x;break}}b||(b=h(v));const w=Math.min(Math.max(b.x,n),o-a-n),C=Math.min(Math.max(b.y,n),c-r-n);return{x:w,y:C,side:b.side}};class q extends D{constructor(t){super(t);f(this,"_state",{});f(this,"_updateScheduled",!1)}get state(){return this._state}set state(t){this._state=new Proxy(t,{set:(s,n,a)=>{if(typeof n!="string")return!0;const r=n;return s[r]===a||(s[r]=a,this._scheduleUpdate()),!0}})}setState(t){Object.assign(this.state,t)}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,requestAnimationFrame(()=>{this._updateScheduled=!1,this.render()}))}render(){}destroy(){this._updateScheduled=!1,this.remove()}forceUpdate(){this._scheduleUpdate()}}class Js extends q{constructor(t){const s="label-tooltip";super({className:t.cx(s)});f(this,"title");f(this,"manyBox");f(this,"oneBox");f(this,"clsx");this.clsx=t.cxFabric(s),this.title=new D({tag:"div",className:this.clsx("title")}),this.manyBox=new D({tag:"div",className:this.clsx("box_many")}),this.oneBox=new D({tag:"div",className:this.clsx("box_one")}),t.dom.append(this.title.node,this.oneBox.node,this.manyBox.node),this.state={isShow:!1,x:0,y:0,parent:V.empty()}}_createLineNodes(t,s){const n=[];for(const a of Object.keys(s))if(a in t){const r=new D({tag:"div",className:this.clsx("line")});let o=t[a].toString();a==="kind"&&(o=this._formatDate(t.time));const c=new D({tag:"strong",textContent:s[a]}),h=new D({tag:"span",textContent:o});r.append(c.node,h.node),n.push(r.node)}return n}_formatDate(t){const s=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short",year:"numeric",hour12:!1}).format(t),[n,a,r]=s.split(", ");return`${n}, ${a} ${r}`}updateContent(t){if(t.length){if(this.title.node.style.display="none",this.oneBox.node.style.display="none",this.oneBox.node.replaceChildren(),this.manyBox.node.style.display="none",this.manyBox.node.replaceChildren(),t.length===1){this.title.node.style.display="flex",this.oneBox.node.style.display="flex",this.title.node.textContent=this._formatDate(t[0].time);const s=this._createLineNodes(t[0],{price:"Price:",profit:"Realized P&L:",volume:"Volume:",percentage:"% of position:"});this.oneBox.append(...s),this.node.append(this.title.node,this.oneBox.node)}else if(t.length>1){this.manyBox.node.style.display="flex";const s=t.map(n=>{const a=new D({tag:"div"}),r=this._createLineNodes(n,{kind:n.kind==="entry"?"Entry:":"Exit:",price:"Price:"});return a.append(...r),a.node});this.manyBox.append(...s),this.node.append(this.manyBox.node)}}}render(){const{isShow:t,x:s,y:n,parent:a}=this.state;this.setVisible(t),t&&this.updateAbsolutePosition();const r=je({size:this.absolutePosition,parent:a,coords:{x:s,y:n}});this.position(r.x,r.y)}}class Qs extends ge{constructor(t){super("trade",t);f(this,"labelTooltip");if(!this.dom)throw new Error("[CS_V_Trade] this.dom must be defined");if(!this.canvas)throw new Error("[CS_V_Trade] this.canvas must be defined");this.labelTooltip=new Js(this),this.dom.append(this.labelTooltip.node)}renderAll(t){this.canvas.clear(),zs(this.canvas.ctx,t),Ps(this.canvas.ctx,t),Vs(this.canvas.ctx,t),Zs(this.canvas.ctx,t)}}function Ks(i,{color:e="#000000",lineWidth:t=1,dashed:s,coords:n}){i.strokeStyle=e,i.lineWidth=t,s&&i.setLineDash(s),i.beginPath(),i.moveTo(n.x1,n.y1),i.lineTo(n.x2,n.y2),i.stroke()}const en={text:"#FFFFFF",bg:"#000000"},tn=(i,e)=>{const{coords:t,text:s,fontSize:n=14,fontWeight:a=600,textHeight:r,padding:o={x:0,y:0},borderRadius:c=0,colors:h,align:u={x:"left",y:"top"}}=e,g={...en,...h},p=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();i.font=`${a} ${n}px ${p}`;const b=i.measureText(s).width+o.x*2,w=r+o.y*2;let C=t.x,y=t.y;u.x==="middle"?C-=b/2:u.x==="right"&&(C-=b),u.y==="middle"?y-=w/2:u.y==="bottom"&&(y-=w),Ht(i,{radius:c,coords:{x:C,y},width:b,height:w,fillColor:g.bg}),i.fillStyle=g.text,i.textBaseline="middle",i.textAlign="center",i.fillText(s,C+b/2,y+w/2)},Bt={line:"#000000",text:"#ffffff",main:"#000000"},It=(i,{text:e,startLineCoords:t,side:s,colors:n=Bt,dir:a="h",endMarkerCoords:r})=>{if(a==="h"&&(s==="bottom"||s==="top"))throw new Error("[drawMarker util]: Incorrect side or dir for this marker");const o={...Bt,...n};i.save(),Ks(i,{color:o.line,lineWidth:1,dashed:[4,4],coords:{x1:t.x,y1:t.y,x2:r.x,y2:r.y}}),tn(i,{text:e,coords:r,padding:{x:6,y:4},borderRadius:4,fontSize:10,textHeight:12,align:{x:a==="v"?"middle":s,y:a==="h"?"middle":s},colors:{text:o.text,bg:o.main}}),i.restore()};class sn extends ue{constructor(e){super(e)}drawMarker(e){It(this.ctx,e)}}class nn extends ge{constructor(e){if(super("user-markers",e,{CanvasClass:sn,noDOM:!0}),!this.canvas)throw new Error("[CS_V_UserMarkers] this.canvas must be defined")}render(e){this.canvas.clear();for(const t of e.userMarkers.data)this.canvas.drawMarker({text:t.text,side:e.config.yAxis.position,dir:"h",startLineCoords:{x:t.startDate?e.scales.x.convert(t.startDate):0,y:e.scales.y.convert(t.value)},endMarkerCoords:{x:e.layout.yAxis.right,y:e.scales.y.convert(t.value)},colors:{line:t.lineColor,main:t.mainColor,text:t.textColor}})}clear(){this.canvas.clear()}}const an="sc-charts-cs";class Q{constructor(e){f(this,"block");this.block=e}gen(e){return`${an}__${this.block}${e?"-"+e:""}`}}const Ye=new Q("comment-actions");class rn extends D{constructor({onDelete:e,onUpdate:t}){super({className:Ye.gen()});const s=new D({tag:"button",className:Ye.gen("edit"),textContent:"Edit"}),n=new D({tag:"button",className:Ye.gen("delete"),textContent:"Delete"});n.node.addEventListener("click",a=>{a.stopPropagation(),e()}),s.node.addEventListener("click",a=>{a.stopPropagation(),t()}),this.append(s.node,n.node)}}function We(i,e){var n;const t=a=>{if(!document.contains(i.node))return;const r=a.target;if(i.node.contains(r))return;const o=document.elementFromPoint(a.clientX,a.clientY);if(o&&i.node.contains(o))return;const c=i.node.getBoundingClientRect();a.clientX>=c.left&&a.clientX<=c.right&&a.clientY>=c.top&&a.clientY<=c.bottom&&getComputedStyle(i.node).pointerEvents!=="none"||e(a)};document.addEventListener("mousedown",t);const s=(n=i.destroy)==null?void 0:n.bind(i);return i.destroy=()=>{document.removeEventListener("mousedown",t),s==null||s()},i}class on{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","18"),t.setAttribute("height","4"),t.setAttribute("viewBox","0 0 18 4"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=[{d:"M9 2.83366C9.46024 2.83366 9.83333 2.46056 9.83333 2.00033C9.83333 1.54009 9.46024 1.16699 9 1.16699C8.53976 1.16699 8.16667 1.54009 8.16667 2.00033C8.16667 2.46056 8.53976 2.83366 9 2.83366Z",fill:"currentColor"},{d:"M15.6667 2.83366C16.1269 2.83366 16.5 2.46056 16.5 2.00033C16.5 1.54009 16.1269 1.16699 15.6667 1.16699C15.2064 1.16699 14.8333 1.54009 14.8333 2.00033C14.8333 2.46056 15.2064 2.83366 15.6667 2.83366Z",fill:"currentColor"},{d:"M2.33333 2.83366C2.79357 2.83366 3.16667 2.46056 3.16667 2.00033C3.16667 1.54009 2.79357 1.16699 2.33333 1.16699C1.8731 1.16699 1.5 1.54009 1.5 2.00033C1.5 2.46056 1.8731 2.83366 2.33333 2.83366Z",fill:"currentColor"},{d:"M9 2.83366C9.46024 2.83366 9.83333 2.46056 9.83333 2.00033C9.83333 1.54009 9.46024 1.16699 9 1.16699C8.53976 1.16699 8.16667 1.54009 8.16667 2.00033C8.16667 2.46056 8.53976 2.83366 9 2.83366Z",stroke:"currentColor"},{d:"M15.6667 2.83366C16.1269 2.83366 16.5 2.46056 16.5 2.00033C16.5 1.54009 16.1269 1.16699 15.6667 1.16699C15.2064 1.16699 14.8333 1.54009 14.8333 2.00033C14.8333 2.46056 15.2064 2.83366 15.6667 2.83366Z",stroke:"currentColor"},{d:"M2.33333 2.83366C2.79357 2.83366 3.16667 2.46056 3.16667 2.00033C3.16667 1.54009 2.79357 1.16699 2.33333 1.16699C1.8731 1.16699 1.5 1.54009 1.5 2.00033C1.5 2.46056 1.8731 2.83366 2.33333 2.83366Z",stroke:"currentColor"}];for(const n of s){const a=document.createElementNS(e,"path");a.setAttribute("d",n.d),n.fill&&a.setAttribute("fill",n.fill),n.stroke&&(a.setAttribute("stroke",n.stroke),a.setAttribute("stroke-width","2"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round")),t.appendChild(a)}this.node=t}}const me=new Q("comment-list");class ln extends D{constructor({onDelete:t,onOpenEditor:s,comment:n,layout:a}){super({className:me.gen("item")});f(this,"actionTooltip");f(this,"actionsTrigger");const r=new D({className:me.gen("text"),textContent:n.text}),o=new D({className:me.gen("created-at"),textContent:js(new Date(n.createdAt))});this.actionsTrigger=new D({tag:"button",className:me.gen("action-trigger")});const c=new rn({onDelete:t,onUpdate:s});this.actionTooltip=We(c,()=>{this.actionTooltip.setVisible(!1)}),this.actionsTrigger.node.addEventListener("click",()=>{this.actionsTrigger.updateAbsolutePosition(),this.actionTooltip.updateAbsolutePosition(),this.actionTooltip.node.style.top=this.actionsTrigger.absolutePosition.top-a.chart.top+20+"px",this.actionTooltip.node.style.left=this.actionsTrigger.absolutePosition.left-a.chart.left-this.actionTooltip.absolutePosition.width+10+"px",this.actionTooltip.setVisible(!0)});const h=new D({className:me.gen("text-wrap")});this.actionTooltip.node.setAttribute("id",`ac-${n.id}`),h.append(r.node,this.actionsTrigger.node),this.actionsTrigger.append(new on().node),this.append(h.node,o.node)}}class cn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","14"),t.setAttribute("height","12"),t.setAttribute("viewBox","0 0 14 12"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M12.4139 0.531408C12.6727 0.208181 13.1453 0.155616 13.4686 0.414221C13.792 0.672923 13.8444 1.14547 13.5858 1.46891L5.58582 11.4689C5.45257 11.6355 5.25388 11.7374 5.0409 11.7492C4.82806 11.7608 4.62035 11.6812 4.46961 11.5304L0.469611 7.53043C0.176835 7.23753 0.176757 6.76274 0.469611 6.46988C0.744191 6.19548 1.179 6.17796 1.47352 6.41813L1.53016 6.46988L4.93738 9.87711L12.4139 0.531408Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class hn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","10"),t.setAttribute("height","10"),t.setAttribute("viewBox","0 0 10 10"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("fill-rule","evenodd"),s.setAttribute("clip-rule","evenodd"),s.setAttribute("d","M9.05951 2.10202C9.38042 1.78111 9.38042 1.26081 9.05951 0.939901C8.73861 0.618991 8.21831 0.618991 7.8974 0.939901L5.0002 3.8371L2.10299 0.939901C1.78208 0.618992 1.26179 0.618992 0.940877 0.939901C0.619968 1.26081 0.619968 1.78111 0.940877 2.10202L3.83808 4.99922L0.940877 7.89642C0.619968 8.21733 0.619968 8.73763 0.940877 9.05854C1.26179 9.37945 1.78208 9.37945 2.10299 9.05854L5.0002 6.16133L7.8974 9.05854C8.21831 9.37945 8.73861 9.37945 9.05951 9.05854C9.38042 8.73763 9.38042 8.21733 9.05951 7.89642L6.16231 4.99922L9.05951 2.10202Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class dn extends q{constructor(t){super({className:"sc-charts-cs__comments-edit"});f(this,"input");f(this,"saveBtn");f(this,"cancelBtn");f(this,"_onSave");f(this,"_onCancel");this._onSave=t.onSave,this._onCancel=t.onCancel,this.input=new D({tag:"textarea",className:"sc-charts-cs__comments-edit-input"}),this.saveBtn=new D({tag:"button",className:"sc-charts-cs__comments-edit-save-btn"}),this.saveBtn.append(new cn().node),this.cancelBtn=new D({tag:"button",className:"sc-charts-cs__comments-edit-cancel-btn"}),this.cancelBtn.append(new hn().node);const s=new D({className:"sc-charts-cs__comments-edit-btn-container"});s.append(this.cancelBtn.node,this.saveBtn.node),this.append(this.input.node,s.node),this.state={inputValue:t.initialValue||"",hasInitFocused:!1},this._setupListeners(),this.render()}_setupListeners(){this.saveBtn.node.addEventListener("click",()=>{this._onSave(this.state.inputValue)}),this.input.node.addEventListener("input",t=>{const s=t.target;this.setState({inputValue:s.value})}),this.cancelBtn.node.addEventListener("click",this._onCancel)}render(){this.input.node.value=this.state.inputValue,this.saveBtn.node.disabled=!this.state.inputValue.trim(),this.state.hasInitFocused||(requestAnimationFrame(()=>this.input.node.focus()),this.setState({hasInitFocused:!0}))}}const un=new Q("comment-list");class fn extends q{constructor(t,s,n,a={}){super({tag:"ul",className:un.gen(),...a});f(this,"_elements",{});f(this,"_model");f(this,"_view");this._model=s,this._view=n,this.state={items:t,editId:null},this.render()}render(){this.node.replaceChildren(),this._elements={},this.state.items.forEach((t,s)=>{this._elements[t.id]={order:s+1,element:this._createItem(t)}}),this.append(...this._sortedNodes())}_createItem(t){if(this.state.editId===t.id)return new dn({onSave:a=>{this._model.comments.update(t.id,a),this.setState({editId:null})},onCancel:()=>{this.setState({editId:null})},initialValue:t.text});const s=new ln({onDelete:()=>{this._model.comments.remove(t.id),s.actionTooltip.setVisible(!1)},onOpenEditor:()=>{this.setState({editId:t.id}),s.actionTooltip.setVisible(!1)},comment:t,layout:this._model.layout}),n=document.querySelector(`#ac-${t.id}`);return n?n.replaceWith(s.actionTooltip.node):this._view.domElements.append(s.actionTooltip.node),s}_sortedNodes(){return Object.values(this._elements).sort((t,s)=>t.order-s.order).map(t=>t.element.node)}}class gn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","14"),t.setAttribute("height","14"),t.setAttribute("viewBox","0 0 14 14"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M3.00035 7.00005H5.33369M3.00035 7.00005L0.957995 1.45651C0.853586 1.17312 1.14972 0.908067 1.41985 1.04313L12.7374 6.70191C12.9831 6.82475 12.9831 7.17535 12.7374 7.29819L1.41985 12.957C1.14971 13.092 0.853586 12.827 0.957995 12.5436L3.00035 7.00005Z"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),t.appendChild(s),this.node=t}}const ke=new Q(""),Xe=new Q("add-field");class Rt extends q{constructor({onAdd:t,blockName:s}){ke.block=s;super({className:ke.gen()+" "+Xe.gen()});f(this,"btn");f(this,"input");f(this,"_onAdd");this._onAdd=t,this.state={inputValue:""},this.input=new D({tag:"input",className:ke.gen("input")+" "+Xe.gen("input")}),this.input.node.setAttribute("placeholder","Add comment..."),this.btn=new D({tag:"button",className:ke.gen("btn")+" "+Xe.gen("btn")}),this.btn.append(new gn().node),this.append(this.input.node,this.btn.node),this._setupListeners(),this.render()}_addComment(){this._onAdd(this.input.node.value),this.setState({inputValue:""}),this.input.node.value="",this.input.node.blur()}_setupListeners(){this.btn.node.addEventListener("click",()=>{this.btn.node.disabled||this._addComment()}),this.input.node.addEventListener("keydown",t=>{t.key==="Enter"&&!this.btn.node.disabled&&this._addComment()}),this.input.node.addEventListener("input",t=>{const s=t.target;this.setState({inputValue:s.value})})}render(){this.btn.node.disabled=!this.state.inputValue.trim()}}const mn=new Q("list-tooltip"),Ue=8;class _n extends q{constructor(t,s,n){super({className:mn.gen()});f(this,"_list");f(this,"_addField");f(this,"_size",null);f(this,"_model");f(this,"_prevIsShow",!1);this._model=s,this.state={isShow:!1,comments:t},this._list=new fn(t,s,n),this._addField=new Rt({blockName:"list-tooltip-add",onAdd:a=>{const r=t[0].date,o=t[0].price,c={id:crypto.randomUUID(),text:a,date:r,price:o,createdAt:new Date().toISOString()};s.comments.add(c)}}),this.node.append(this._list.node,this._addField.node)}render(){const{isShow:t,comments:s}=this.state,{width:n,height:a}=this._model.layout.area;this._prevIsShow!==t&&(this._list.forceUpdate(),this._prevIsShow=t),this.node.style.maxHeight=a/2-Ue+"px",this.setVisible(t),t&&!this._size&&(this.updateAbsolutePosition(),this._size=this.absolutePosition,this.position(n/2-this._size.width-Ue,a/2+Ue)),this._list.setState({items:s}),requestAnimationFrame(()=>{this._list.node.scrollTop=this._list.node.scrollHeight})}get list(){return this._list}}class pn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","16"),t.setAttribute("height","16"),t.setAttribute("viewBox","0 0 16 16"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M7.99978 0.890625C4.07889 0.890625 0.888672 4.08085 0.888672 8.00174C0.888672 9.24262 1.21845 10.4693 1.83267 11.5315C2.04423 11.928 1.74823 13.3111 1.08423 13.9751C0.89845 14.1608 0.838894 14.4391 0.933116 14.6844C1.02734 14.9297 1.25756 15.0977 1.51978 15.112C1.59001 15.1155 1.66201 15.1173 1.73401 15.1173C2.75178 15.1173 3.98734 14.7555 4.79178 14.3431C5.39178 14.648 6.02734 14.8648 6.686 14.9902C7.11623 15.072 7.55889 15.1128 7.99978 15.1128C11.9207 15.1128 15.1109 11.9226 15.1109 8.00174C15.1109 4.08085 11.9207 0.890625 7.99978 0.890625ZM9.11089 10.224H5.11089C4.74289 10.224 4.44423 9.92529 4.44423 9.55729C4.44423 9.18929 4.74289 8.89062 5.11089 8.89062H9.11089C9.47889 8.89062 9.77756 9.18929 9.77756 9.55729C9.77756 9.92529 9.47889 10.224 9.11089 10.224ZM10.8887 7.11285H5.11089C4.74289 7.11285 4.44423 6.81418 4.44423 6.44618C4.44423 6.07818 4.74289 5.77951 5.11089 5.77951H10.8887C11.2567 5.77951 11.5553 6.07818 11.5553 6.44618C11.5553 6.81418 11.2567 7.11285 10.8887 7.11285Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class vn extends q{constructor({x:t,...s},n){super(s);f(this,"_colors");this._colors=n.colorScheme.comments.scaleAnchor,this.state={x:t,y:n.layout.xAxis.top,isActive:!1},this.node.append(new pn().node),this.render()}render(){const{x:t,y:s,isActive:n}=this.state;this.position({x:t,y:s});const a=n?"Active":"Inactive";this.node.style.backgroundColor=this._colors[`bg${a}`],this.node.style.color=this._colors[`icon${a}`]}}const $t=new Q("comment-box");class bn extends q{constructor({boxId:t,model:s,view:n,comments:a,coords:r,onBoxActivate:o,onBoxDeactivate:c}){super({className:$t.gen()});f(this,"pointer",new D({className:"sc-charts-cs__comments-pointer"}));f(this,"tooltip");f(this,"anchor");f(this,"_onBoxActivate");f(this,"_onBoxDeactivate");f(this,"_boxId");this._boxId=t,this._onBoxActivate=o,this._onBoxDeactivate=c,this.state={isActive:!1,comments:a,coords:r},this.pointer.position(r),this.anchor=new vn({x:r.x,className:$t.gen("anchor")},s),this.anchor.node.addEventListener("click",()=>{const h=!this.state.isActive;h?this._onBoxActivate(this._boxId):this._onBoxDeactivate(this._boxId),this.setState({isActive:h})}),this.tooltip=We(new _n(a,s,n),h=>{this.state.isActive&&(this.anchor.node.contains(h.target)||(this._onBoxDeactivate(this._boxId),this.setState({isActive:!1})))}),this.append(this.pointer.node,this.anchor.node,this.tooltip.node),this.render()}render(){const{isActive:t,comments:s,coords:n}=this.state;this.pointer.position(n),this.pointer.setVisible(t),this.anchor.setState({x:n.x,isActive:t}),this.tooltip.setState({comments:s,isShow:t})}}class yn{static animateTo(e,t,s,n){const a=e.scales.panOffsetX+(e.layout.area.width/2-t),r=e.scales.panOffsetY+(e.layout.area.height/2-s),o=300,c=performance.now(),h=e.scales.panOffsetX,u=e.scales.panOffsetY,g=_=>{const p=_-c,v=Math.min(p/o,1),b=v*v*(3-2*v),w=h+(a-h)*b,C=u+(r-u)*b;e.scales.pan("x",w,"absolute"),e.scales.pan("y",C,"absolute"),v<1?requestAnimationFrame(g):n==null||n()};requestAnimationFrame(g)}static animateToDataCoords(e,t,s,n){const a=typeof t=="number"?e.scales.x.convert(new Date(t)):e.scales.x.convert(t),r=e.scales.y.convert(s);this.animateTo(e,a,r,n)}}const Ge=new Q("comments-context");class wn extends q{constructor(){super({className:Ge.gen()});f(this,"pointer");f(this,"addField");f(this,"menu");f(this,"_size",null);f(this,"_model",null);f(this,"_candle",null);this.state={candle:null,isShow:!1,model:null},this.pointer=new D({className:Ge.gen("pointer")}),this.menu=new D({className:Ge.gen("menu")}),We(this.menu,()=>{this.setState({isShow:!1})}),this.addField=new Rt({blockName:"context-add",onAdd:t=>{!this._model||!this._candle||(this._model.comments.add({id:crypto.randomUUID(),text:t,date:this._candle.open_time.toISOString(),price:this._model.scales.y.invert((this._candle.open+this._candle.close)/2),createdAt:new Date().toISOString()}),this.setState({isShow:!1}))}}),this.menu.append(this.addField.node),this.append(this.pointer.node,this.menu.node)}_changeInputCorner(t){this.addField.input.node.style.borderTopLeftRadius=t==="right-bottom"?"0px":"12px",this.addField.input.node.style.borderBottomRightRadius=t==="left-top"?"0px":"12px",this.addField.input.node.style.borderBottomLeftRadius=t==="right-top"?"0px":"12px",this.addField.input.node.style.borderTopRightRadius=t==="left-bottom"?"0px":"12px"}render(){const{candle:t,isShow:s,model:n}=this.state;if(this.setVisible(s),!n||!t)return;this._model=n,this._candle=t;const a={x:n==null?void 0:n.scales.x.convert(t.open_time),y:n==null?void 0:n.scales.y.convert((t.open+t.close)/2)};this.pointer.position(a),this._size||(this.menu.position(a),this.menu.updateAbsolutePosition());const r=je({size:this.menu.absolutePosition,parent:n.layout.area,offset:9,coords:a});this._changeInputCorner(r.side),this.menu.position(r.x,r.y)}}class xn extends ge{constructor(t){super("comments",t,{noCanvas:!0});f(this,"boxes",{});f(this,"contextMenu");f(this,"_view");if(!this.dom)throw new Error("[CS_V_Comments] this.dom must be defined");this.contextMenu=new wn,this._view=t,t.domElements.append(this.contextMenu.node)}_getCandleCoords(t,s){return{x:t.scales.x.convert(s.open_time),y:t.scales.y.convert((s.open+s.close)/2)}}createBox({boxId:t,coords:s,model:n,comments:a}){const r=new bn({boxId:t,model:n,comments:a,coords:s,view:this._view,onBoxActivate:o=>{const c=a[0].candle;yn.animateToDataCoords(n,c.open_time,(c.open+c.close)/2),this.boxes[o].setState({isActive:!0})},onBoxDeactivate:o=>this.boxes[o].setState({isActive:!1})});this.boxes[t]=r,this.dom.append(r.node)}render(t){this.contextMenu.setState({model:t}),this.contextMenu.forceUpdate();const s=t.comments.grouped,n=new Set(Object.keys(s));Object.entries(s).forEach(([a,r])=>{const o=this._getCandleCoords(t,r[0].candle),c={boxId:a,coords:o,comments:r};this.boxes[a]?this.boxes[a].setState({comments:r,coords:o}):this.createBox({...c,model:t})}),Object.keys(this.boxes).forEach(a=>{n.has(a)||(this.boxes[a].node.remove(),delete this.boxes[a])})}}class Cn extends ue{constructor(e){super(e)}drawMarker({text:e,startLineCoords:t,endMarkerCoords:s,colors:n,type:a,side:r}){It(this.ctx,{text:e,colors:n,startLineCoords:t,endMarkerCoords:s,dir:a,side:r})}}class Mn extends ge{constructor(e){if(super("guides",e,{CanvasClass:Cn,noDOM:!0}),!this.canvas)throw new Error("[CS_V_Guides] Canvas must be defined")}render(e,{x:t,y:s}){if(this.canvas.clear(),e.config.guides.isShowY){const n=e.config.yAxis.position;this.canvas.drawMarker({text:e.scales.y.invert(s).toFixed(2),startLineCoords:{x:0,y:s},endMarkerCoords:{x:e.layout.yAxis[n],y:s},side:n,colors:e.colorScheme.guides.horizontalMarker,type:"h"})}if(e.config.guides.isShowX){const n=e.config.xAxis.position;this.canvas.drawMarker({text:k.timeFormat("%a %d, %b %y %H:%M")(e.scales.x.invert(t)),startLineCoords:{x:t,y:0},endMarkerCoords:{x:t,y:e.layout.xAxis[n]},side:n,colors:e.colorScheme.guides.verticalMarker,type:"v"})}}}class Tn extends q{constructor(t){super({className:t});f(this,"_isFirstShow",!1);const s=new D({tag:"p"});s.node.textContent="No data from broker",this.append(s.node),this.state={isShow:!1,x:0,y:0,parent:V.empty()},this.render()}render(){const{isShow:t,x:s,y:n,parent:a}=this.state;t&&!this._isFirstShow&&(this.updateAbsolutePosition(),this._isFirstShow=!0),this.setVisible(t);const r=je({size:this.absolutePosition,parent:a,coords:{x:s,y:n}});this.position(r.x,r.y)}}class An extends ue{constructor(t){super(t);f(this,"domain",null);f(this,"_getVisible",t=>{if(!this.domain)return[];const[s,n]=this.domain;return t.filter(a=>a.open_time>=s&&a.open_time<=n)})}drawSingleCandle({x:t,y:s,strokeWidth:n,width:a,colors:r,isDim:o}){this.ctx.fillStyle=this._mix(r.fill,r.bg,o),this.ctx.strokeStyle=this._mix(r.stroke,r.bg,o),this.ctx.lineWidth=n,this.ctx.beginPath(),this.ctx.moveTo(t,s.high),this.ctx.lineTo(t,s.low),this.ctx.stroke();const c=Math.min(s.open,s.close),h=Math.abs(s.close-s.open),u=t-a/2;this.ctx.fillRect(u,c,a,h),this.ctx.strokeRect(u,c,a,h)}drawCandles(t){const{colorScheme:{candles:s,bg:n},trade:{timeRange:a},candles:{missingData:r,preparedData:o},config:{candles:{hideMissingData:c}}}=t,h=t.config.candles.style==="filled";this.domain=t.scales.x.domain(),c||this._getVisible(r).forEach((u,g)=>{const _=s.noDataFill[g%s.noDataFill.length],p=h?_:s.noDataStroke;this.drawSingleCandle({...this._getBasicCandleProps(t,u),colors:{fill:_,stroke:p,bg:n}})}),this._getVisible(o).forEach(u=>{const g=u.close>=u.open?"rising":"falling",_=s[`${g}Fill`],p=s[`${g}${h?"Fill":"Stroke"}`];this.drawSingleCandle({...this._getBasicCandleProps(t,u),colors:{fill:_,stroke:p,bg:n},isDim:!!(a.length&&!a.includes(u.open_time.getTime()))})})}_mix(t,s,n){return n?T.mix(t,s).toString():t}_getBasicCandleProps(t,s){return{x:t.scales.x.convert(s.open_time),y:{open:t.scales.y.convert(s.open),close:t.scales.y.convert(s.close),high:t.scales.y.convert(s.high),low:t.scales.y.convert(s.low)},width:t.config.candles.baseWidth*t.scales.factorX,strokeWidth:t.config.candles.strokeWidth}}}class Sn extends ge{constructor(t){super("candles",t,{CanvasClass:An});f(this,"_noDataTooltip",null);f(this,"limiter");if(!this.dom)throw new Error("[CS_V_Candles] this.dom must be defined");if(!this.canvas)throw new Error("[CS_V_Candles] this.canvas must be defined");this._noDataTooltip=new Tn(this.cx("no-data")),this.limiter=new D({className:this.cx("limiter")}),this.limiter.setVisible(!1),this.dom.append(this._noDataTooltip.node,this.limiter.node)}get noDataTooltip(){return this._noDataTooltip}removeNoDataTooltip(){var t;(t=this._noDataTooltip)==null||t.remove(),this._noDataTooltip=null}render(t){this.canvas.clear(),this.canvas.drawCandles(t);const s=t.candles.allData[0];if(s){const{baseWidth:n,limiterOffset:a}=t.config.candles,r=t.scales.x.convert(s.open_time)-n/2-a.left-a.right,o=t.layout.area.height/2;this.limiter.node.style.height=t.layout.area.height+"px",this.limiter.setVisible(!0),this.limiter.position(r,o)}}}class kn{constructor(e){f(this,"container");f(this,"width");f(this,"height");f(this,"wrapper");f(this,"domElements");f(this,"canvasesContainer");f(this,"mainCanvas");f(this,"binding");f(this,"userMarkers");f(this,"guideMarkers");f(this,"trade");f(this,"comments");f(this,"candles");this.container=e,this.wrapper=new D({tag:"div",className:"sc-charts-cs"}),e.append(this.wrapper.node);const{width:t,height:s}=e.getBoundingClientRect();this.width=t,this.height=s,this.mainCanvas=new ue({className:"sc-charts-cs__canvas-main",width:t,height:s,isMain:!0}),this.domElements=new D({tag:"div",className:"sc-charts-cs__dom-elements"}),this.canvasesContainer=new D({tag:"div",className:"sc-charts-cs__canvases"}),this.canvasesContainer.append(this.mainCanvas.node),this.wrapper.append(this.canvasesContainer.node,this.domElements.node),this.mainCanvas.updateAbsolutePosition(),this.binding=new fs(this.mainCanvas.node),this.comments=new xn(this),this.candles=new Sn(this),this.trade=new Qs(this),this.guideMarkers=new Mn(this),this.userMarkers=new nn(this)}renderAll(e){this.mainCanvas.clear(),this.candles.render(e),ze.xAxis(this.mainCanvas.ctx,e),ze.yAxis(this.mainCanvas.ctx,e),ze.intersection(this.mainCanvas.ctx,e),this.trade.renderAll(e),this.userMarkers.render(e),this.comments.render(e)}}class Dn{constructor(e){f(this,"logColors",{init_model:"color: green",scale_event:"color: orange",update_config:"color: blue",update_candles:"color: purple",update_trade:"color: red",update_user_markers:"color: brown",update_color_scheme:"color: teal"});f(this,"ignoredLogEvents",[]);e&&(this.ignoredLogEvents=e)}log(e,t){if(this.ignoredLogEvents.includes(e))return;const s=this.logColors[e]||"color: gray";let n;try{n=JSON.parse(JSON.stringify(t))}catch{n=t}console.log(`%c[SUBSCRIBE] ${e}`,s,n)}}class Ln{constructor(e,t){f(this,"_model");f(this,"_view");f(this,"_enableLogging");f(this,"_logger");this._model=e,this._view=t,this._enableLogging=!1,this._logger=new Dn(["scale_event"])}subscribeWithLogging(e,t){const s=n=>{this._enableLogging&&this._logger.log(e,n),t(n)};this._model.subscribe(e,s)}init(){this.subscribeWithLogging("init_model",()=>{this._model.config.candles.hideMissingData&&this._view.candles.removeNoDataTooltip(),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("scale_event",()=>{this._model.userMarkers.rebuild(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_config",e=>{this._model.config.update(e),this._model.layout.updateConfig(this._model.config),this._model.userMarkers.rebuild(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_candles",e=>{this._model.candles.update(e),this._model.scales.reinit(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_trade",e=>{this._model.trade.updateTrade(e),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_user_markers",e=>{this._model.userMarkers.updateMarkers(e),this._view.userMarkers.render(this._model)}),this.subscribeWithLogging("update_color_scheme",e=>{this._model.colorScheme.update(e),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("open_trade_label_tooltip",({trade:e,x:t,y:s})=>{this._model.trade.setActiveTrade(e.tradeType,e.candle.open_time.getTime()),this._view.trade.renderAll(this._model),this._model.config.trade.showLabelButtons&&(this._view.trade.labelTooltip.updateContent(e.trades),this._view.trade.labelTooltip.setState({isShow:!0,x:t,y:s,parent:this._model.layout.area}))}),this.subscribeWithLogging("close_trade_label_tooltip",()=>{this._model.trade.setActiveTrade(null),this._view.trade.renderAll(this._model),this._view.trade.labelTooltip.setState({isShow:!1})}),this.subscribeWithLogging("hover_nodata_candle",({x:e,y:t})=>{var s;(s=this._view.candles.noDataTooltip)==null||s.setState({isShow:!0,x:e,y:t,parent:this._model.layout.area})}),this.subscribeWithLogging("leave_nodata_candle",()=>{var e;(e=this._view.candles.noDataTooltip)==null||e.setState({isShow:!1})}),this.subscribeWithLogging("mouseover_trade_label_tooltip",e=>{this._model.trade.setHoveredTrade(e.tradeType,e.candle.open_time.getTime()),this._view.trade.renderAll(this._model)}),this.subscribeWithLogging("mouseleave_trade_label_tooltip",()=>{this._model.trade.setHoveredTrade(null),this._view.trade.renderAll(this._model)}),this.subscribeWithLogging("update_comments",e=>{this._model.comments.data=e,this._view.renderAll(this._model)})}}class Ot{constructor(){f(this,"_map",new Map)}add(e,t,s){let n=this._map.get(e);n||(n={},this._map.set(e,n)),n[t]||(n[t]=new Set),n[t].add(s)}remove(e,t,s){var a;const n=this._map.get(e);(a=n==null?void 0:n[t])==null||a.delete(s)}removeAll(e){this._map.delete(e)}emit(e,t){const s=this._map.get(e),n=s==null?void 0:s[t.type];if(!n)return!1;let a=!1;const r={...t,stopPropagation:()=>{a=!0}};for(const o of n)if(o(r),a)break;return a}}class En{constructor(){f(this,"_elements",[]);f(this,"_listeners",new Ot);f(this,"_lastHovered",new Set);f(this,"_dragContext",null)}get isDragging(){return this._dragContext!==null}register(...e){this._elements.push(...e)}unregister(e){this._elements=this._elements.filter(t=>t!==e),this._listeners.removeAll(e),this._lastHovered.delete(e)}clear(){this._elements=[],this._listeners=new Ot,this._lastHovered.clear()}on(e,t,s){this._listeners.add(e,t,s)}off(e,t,s){this._listeners.remove(e,t,s)}dispatchMouseMove(e,t){if(this._dragContext){this._emitSingle(this._dragContext.target,{type:"drag",target:this._dragContext.target,x:e,y:t,prevX:this._dragContext.lastX,prevY:this._dragContext.lastY}),this._dragContext.lastX=e,this._dragContext.lastY=t;return}const s=this._getHitsAt(e,t),n=new Set(s.map(a=>a.target));for(const a of s)if(!this._lastHovered.has(a.target)&&this._emitSingle(a.target,{type:"mouseover",target:a.target,x:a.x,y:a.y})||this._emitSingle(a.target,{type:"mousemove",target:a.target,x:a.x,y:a.y}))break;for(const a of this._lastHovered)n.has(a)||this._emitSingle(a,{type:"mouseleave",target:a,x:e,y:t});this._lastHovered=n}dispatchMouseDown(e,t){const s=this._getHitsAt(e,t);if(s.length===0){this._dragContext=null;return}this._dragContext=null;for(const n of s)if(this._emitSingle(n.target,{type:"mousedown",target:n.target,x:n.x,y:n.y})){this._dragContext={target:n.target,lastX:e,lastY:t};break}!this._dragContext&&s.length>0&&(this._dragContext={target:s[s.length-1].target,lastX:e,lastY:t})}dispatchMouseUp(e,t){this._dragContext&&this._emitSingle(this._dragContext.target,{type:"mouseup",target:this._dragContext.target,x:e,y:t}),this._dragContext=null}dispatchClick(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"click",target:n.target,x:n.x,y:n.y}))break}dispatchDblClick(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"dblclick",target:n.target,x:n.x,y:n.y}))break}dispatchContextMenu(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"contextmenu",target:n.target,x:n.x,y:n.y}))break}dispatchWheel(e,t,s,n,a){const r=this._getHitsAt(e,t);for(const o of r)if(this._emitSingle(o.target,{type:"wheel",target:o.target,x:o.x,y:o.y,deltaX:s,deltaY:n,deltaZ:a}))break}hitTestAll(e,t){return this._getHitsAt(e,t)}_getHitsAt(e,t){return this._elements.map(s=>s.hitTest(e,t)).filter(s=>s!==null)}_emitSingle(e,t){let s=!1;const n={...t,stopPropagation(){s=!0}};return this._listeners.emit(e,n),s}}class Nn{constructor(e){this.model=e}hitTest(e,t){const{candles:{missingData:s},scales:{x:n,y:a},config:{candles:{baseWidth:r}}}=this.model;for(const o of s){const c=n.convert(o.open_time),h=a.convert(o.high),u=a.convert(o.low),g=c-r/2,_=c+r/2,p=Math.min(h,u),v=Math.max(h,u);if(e>=g&&e<=_&&t>=p&&t<=v)return{target:this,x:e,y:t,type:"candle",candle:o}}return null}}class Fn{constructor(e,t){f(this,"_model");f(this,"_hitManager");f(this,"_hit");this._model=e,this._hitManager=t,this._hit=new Nn(e),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mouseover",e=>{const t=this._hit.hitTest(e.x,e.y);if(!t)return;const s=this._model.scales.x.convert(t.candle.open_time),n=this._model.scales.y.convert(t.candle.high)-4;this._model.eventBus.emit("hover_nodata_candle",{x:s,y:n})}),this._hitManager.on(this._hit,"mouseleave",()=>{this._model.eventBus.emit("leave_nodata_candle")})}}class Hn{constructor(e){this.model=e}hitTest(e,t){const{tradedCandles:s}=this.model.trade,{x:n,y:a}=this.model.scales,r=16,o=4;for(const{candle:c,trades:h}of s){const g=n.convert(c.open_time)+this.model.config.candles.baseWidth/2,_=r,p=r;for(const v of["buy","sell"]){const b=h.filter(x=>x.type===v);if(!b.length)continue;const w=v==="buy"?a.convert(c.low)+o+Te(r):a.convert(c.high)-o-r-Te(r),C=e>=g-_/2&&e<=g+_/2,y=t>=w&&t<=w+p;if(C&&y)return{target:this,type:"trade-label",tradeType:v,x:e,y:t,candle:c,trades:b}}}return null}}class Bn{constructor(e,t){f(this,"_model");f(this,"_hitManager");f(this,"_tradeLabelHit");this._model=e,this._hitManager=t,this._tradeLabelHit=new Hn(e),this._hitManager.register(this._tradeLabelHit)}register(){this._hitManager.on(this._tradeLabelHit,"click",e=>{const t=this._tradeLabelHit.hitTest(e.x,e.y);if(!t)return;const s=this._model.scales.x.convert(t.candle.open_time),n=this._model.scales.y.convert(t.trades[0].type==="buy"?t.candle.low:t.candle.high),a=t.trades[0].type==="buy"?n+4+Te(16)+8:n-4-16-Te(16)+8;this._model.eventBus.emit("open_trade_label_tooltip",{trade:{candle:t.candle,trades:t.trades,tradeType:t.tradeType},x:s,y:a})}),this._hitManager.on(this._tradeLabelHit,"mouseover",e=>{const t=this._tradeLabelHit.hitTest(e.x,e.y);t&&this._model.eventBus.emit("mouseover_trade_label_tooltip",{candle:t.candle,trades:t.trades,tradeType:t.tradeType})}),this._hitManager.on(this._tradeLabelHit,"mouseleave",()=>{this._model.eventBus.emit("mouseleave_trade_label_tooltip")})}}class In{constructor(e){this.model=e}hitTest(e,t){const{xAxis:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"x-axis"}:null}}class Rn{constructor(e){this.model=e}hitTest(e,t){const{area:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"area"}:null}}class $n{constructor(e){this.model=e}hitTest(e,t){const{yAxis:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"y-axis"}:null}}function On(i,e){let t={x:0,y:0},s=null;return n=>{Math.abs(n.x-t.x)<i&&Math.abs(n.y-t.y)<i||(t={x:n.x,y:n.y},s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{e(n),s=null}))}}function Pn(i,e){let t=null;return s=>{const n=s.x-(s.prevX??s.x),a=s.y-(s.prevY??s.y);Math.abs(n)<i&&Math.abs(a)<i||(t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{e(s),t=null}))}}function Ze(i,e){const{width:t}=e.candles.limiter.absolutePosition,s=i.config.candles.baseWidth,n=i.config.candles.limiterOffset.left+i.config.candles.limiterOffset.right,r=i.scales.x.convert(i.candles.allData[0].open_time)-t-s/2-n;r>0&&i.scales.pan("x",-r)}function qe(i){return i.candles.limiter.absolutePosition.width>0}class Je{constructor(e,t,s){f(this,"_model");f(this,"_hitManager");f(this,"_hit");this._model=e,this._hitManager=t,this._hit=s,t.register(s)}}class zn extends Je{constructor(t,s,n){super(t,s,new In(t));f(this,"_view");this._view=n}register(){this._hitManager.on(this._hit,"drag",t=>{const s=t.x-(t.prevX??t.x);this._model.scales.scale("x",-s),this._view&&qe(this._view)&&Ze(this._model,this._view)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.scale("x",1,"absolute"),this._model.scales.pan("x",0,"absolute")})}}class Vn extends Je{constructor(e,t){super(e,t,new $n(e))}register(){this._hitManager.on(this._hit,"drag",e=>{const t=e.y-(e.prevY??e.y);this._model.scales.scale("y",-t)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.fitYToVisibleCandles()})}}class jn extends Je{constructor(t,s,n){super(t,n,new Rn(t));f(this,"_view");this._view=s}register(){this._hitManager.on(this._hit,"mousemove",On(1,t=>{this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"mouseleave",()=>{this._view.guideMarkers.canvas.clear()}),this._hitManager.on(this._hit,"drag",Pn(1,t=>{this._model.scales.pan("x",t.x-(t.prevX??t.x)),qe(this._view)&&Ze(this._model,this._view),this._model.scales.pan("y",t.y-(t.prevY??t.y)),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"contextmenu",({x:t})=>{const s=this._model.scales.x.invert(t),n=Pe.findByDate(s,this._model.candles.allData);n&&(this._view.comments.contextMenu.setState({isShow:!0,candle:n}),this._view.comments.render(this._model))}),this._hitManager.on(this._hit,"wheel",t=>{var a,r;if(!t.deltaY)return;const s=-t.deltaY,n=(r=(a=this._model.config)==null?void 0:a.candles)==null?void 0:r.zoomOnWheel;["x","both"].includes(n)&&(this._model.scales.scale("x",s),qe(this._view)&&Ze(this._model,this._view)),["y","both"].includes(n)&&this._model.scales.scale("y",s)})}}class Yn{constructor(e,t,s){f(this,"_hitManager");f(this,"_candlesHandler");f(this,"_tradeLabelsHandler");f(this,"_xAxisHandler");f(this,"_yAxisHandler");f(this,"_areaHandler");this._hitManager=s,this._candlesHandler=new Fn(e,this._hitManager),this._tradeLabelsHandler=new Bn(e,this._hitManager),this._xAxisHandler=new zn(e,this._hitManager,t),this._yAxisHandler=new Vn(e,this._hitManager),this._areaHandler=new jn(e,t,this._hitManager)}register(){this._candlesHandler.register(),this._tradeLabelsHandler.register(),this._xAxisHandler.register(),this._yAxisHandler.register(),this._areaHandler.register()}}class Wn{constructor(e,t){f(this,"_model");f(this,"_view");f(this,"_subscriptionsManager");f(this,"_hitManager",new En);f(this,"_boundMouseMove",this.onDocumentMouseMove.bind(this));f(this,"_boundMouseUp",this.onDocumentMouseUp.bind(this));this._model=e,this._view=t,this._subscriptionsManager=new Ln(e,t)}init(){this._subscriptionsManager.init(),this._model.init(),this._view.binding.mousemove(this.onMouseMove.bind(this)),this._view.binding.mousedown(this.onMouseDown.bind(this)),this._view.binding.mouseup(this.onMouseUp.bind(this)),this._view.binding.wheel(this.onWheel.bind(this)),this._view.binding.mouseleave(this.onMouseLeave.bind(this)),this._view.binding.dblclick(this.onDoubleClick.bind(this)),this._view.binding.contextmenu(this.onContextMenu.bind(this)),window.addEventListener("scroll",this.onWindowScroll.bind(this),{passive:!0}),document.addEventListener("click",this.onDocumentClick.bind(this)),new Yn(this._model,this._view,this._hitManager).register()}onContextMenu(e){e.preventDefault();const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchContextMenu(t,s)}onWindowScroll(){this._view.mainCanvas.updateAbsolutePosition()}onMouseLeave(){this._hitManager.isDragging||(this._hitManager.dispatchMouseMove(-1/0,-1/0),document.removeEventListener("mousemove",this._boundMouseMove),document.removeEventListener("mouseup",this._boundMouseUp))}onDoubleClick(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchDblClick(t,s)}onDocumentClick(e){const t=this.getMouseRelative(e);this._hitManager.dispatchClick(t.x,t.y),!this._hitManager.hitTestAll(t.x,t.y).find(n=>n.type==="trade-label")&&this._model.trade.hasActiveTrade&&this._model.eventBus.emit("close_trade_label_tooltip")}getMouseRelative(e){return{x:e.clientX-this._view.mainCanvas.absolutePosition.left,y:e.clientY-this._view.mainCanvas.absolutePosition.top}}onDocumentMouseMove(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseMove(t,s)}onMouseDown(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseDown(t,s),e.preventDefault(),document.addEventListener("mouseup",this._boundMouseUp),this._hitManager.isDragging&&document.addEventListener("mousemove",this._boundMouseMove)}onMouseUp(e){const t=this.getMouseRelative(e);this._hitManager.dispatchMouseUp(t.x,t.y),document.removeEventListener("mouseup",this._boundMouseUp)}onDocumentMouseUp(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseUp(t,s),document.removeEventListener("mouseup",this._boundMouseUp),document.removeEventListener("mousemove",this._boundMouseMove)}onMouseMove(e){var a;if(!this._hitManager.isDragging){const{x:r,y:o}=this.getMouseRelative(e);this._hitManager.dispatchMouseMove(r,o)}const{x:t,y:s}=this.getMouseRelative(e),n=this._hitManager.hitTestAll(t,s);(a=n[0])!=null&&a.type&&(n[0].type==="area"?this._view.mainCanvas.node.style.cursor="crosshair":n[0].type==="trade-label"?this._model.config.trade.showLabelButtons&&(this._view.mainCanvas.node.style.cursor="pointer"):n[0].type==="x-axis"?this._view.mainCanvas.node.style.cursor="ew-resize":n[0].type==="y-axis"?this._view.mainCanvas.node.style.cursor="ns-resize":this._view.mainCanvas.node.style.cursor="default")}onWheel(e){e.preventDefault(),this._hitManager.dispatchWheel(e.offsetX,e.offsetY,e.deltaX,e.deltaY,e.deltaZ)}}class Xn{constructor(e,{chartId:t,candles:s,config:n,trade:a,userMarkers:r,colorScheme:o,comments:c,renderLimiter:h}){f(this,"_model");f(this,"_view");f(this,"_controller");f(this,"_candlesLimiterClean");const u=document.querySelector(e);if(!u)throw new Error(`Element with selector "${e}" not found!`);if(!t||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t))throw new Error("chartId is required and must be a valid id (only letters, numbers or underscores. The first character must be a letter)");if(this._model=new ls({chartId:t,candles:s,config:n,container:u,trade:a,userMarkers:r,colorScheme:o,comments:c}),this._view=new kn(u),this._controller=new Wn(this._model,this._view),h){const g=h(this._view.candles.limiter.node);this._view.candles.limiter.updateAbsolutePosition(),typeof g=="function"&&(this._candlesLimiterClean=g)}this._controller.init()}destroy(){var e;(e=this._candlesLimiterClean)==null||e.call(this)}updateConfig(e){this._model.updateConfig(e)}updateTrade(e){this._model.updateTrade(e)}updateUserMarkers(e){this._model.updateUserMarkers(e)}updateColorScheme(e){this._model.updateColorScheme(e)}updateCandles(e){this._model.updateCandles(e)}updateComments(e){this._model.updateComments(e)}async _drawHeader(e,t,s){const n=48*s,a=12*s,r=20*s,o=103*s;e.fillStyle="#FFFFFF",e.fillRect(0,0,t,n),e.strokeStyle="#EDEDED",e.lineWidth=1*s,e.beginPath(),e.moveTo(0,n),e.lineTo(t,n),e.stroke();const c=`<svg width="103" height="20" viewBox="0 0 103 20" fill="none" xmlns="http://www.w3.org/2000/svg">
3
- <path d="M92.6267 1.50666H93.0475C93.3792 1.50666 93.6025 1.31028 93.6025 1.02537C93.6025 0.740457 93.4034 0.561783 93.0426 0.561783C92.706 0.561783 92.4827 0.759773 92.4633 1.06239H91.795C91.8209 0.423351 92.3225 0.00805664 93.075 0.00805664C93.8274 0.00805664 94.2886 0.376671 94.2886 0.928788C94.2886 1.35213 93.9973 1.65797 93.5717 1.73523V1.74972C94.0895 1.79318 94.4229 2.10385 94.4229 2.58192C94.4229 3.20164 93.8581 3.61372 93.0572 3.61372C92.2562 3.61372 91.761 3.18555 91.7271 2.54973H92.4212C92.4423 2.84108 92.6834 3.03263 93.0652 3.03263C93.4471 3.03263 93.6834 2.82981 93.6834 2.53685C93.6834 2.22135 93.4455 2.0298 93.0539 2.0298H92.6251V1.50827L92.6267 1.50666Z" fill="#1C2026"/>
4
- <path d="M95.1182 2.97623C94.9256 2.68488 94.8269 2.29373 94.8269 1.83498C94.8269 0.692113 95.3852 0.00317383 96.2816 0.00317383C96.9434 0.00317383 97.4596 0.392714 97.5567 0.957708H96.8431C96.7735 0.727525 96.5502 0.574607 96.2784 0.574607C95.7945 0.574607 95.5017 1.03658 95.5178 1.81566H95.5324C95.6716 1.47763 96.013 1.25389 96.4564 1.25389C97.1149 1.25389 97.6036 1.73679 97.6036 2.39192C97.6036 3.10179 97.0486 3.61205 96.2719 3.61205C95.7735 3.61205 95.3625 3.3867 95.1198 2.97623H95.1182ZM96.8949 2.41446C96.8949 2.05872 96.6279 1.79796 96.2654 1.79796C95.903 1.79796 95.6311 2.05872 95.6311 2.40802C95.6311 2.75732 95.9078 3.0374 96.2638 3.0374C96.6198 3.0374 96.8965 2.76215 96.8965 2.41607L96.8949 2.41446Z" fill="#1C2026"/>
5
- <path d="M97.998 1.79961C97.998 0.68411 98.5336 0 99.4026 0C100.272 0 100.804 0.6825 100.804 1.79639C100.804 2.91028 100.275 3.60727 99.4026 3.60727C98.5304 3.60727 97.998 2.91672 97.998 1.798V1.79961ZM100.066 1.79961C100.066 1.01892 99.8136 0.579481 99.4026 0.579481C98.9916 0.579481 98.7359 1.02214 98.7359 1.79961C98.7359 2.57708 98.9883 3.0294 99.4026 3.0294C99.8168 3.0294 100.066 2.58674 100.066 1.79961Z" fill="#1C2026"/>
6
- <path d="M101.137 0.809958C101.137 0.381786 101.469 0.048584 101.901 0.048584C102.333 0.048584 102.666 0.381786 102.666 0.809958C102.666 1.23813 102.331 1.57294 101.901 1.57294C101.47 1.57294 101.137 1.23974 101.137 0.809958ZM102.249 0.809958C102.249 0.616798 102.097 0.46066 101.902 0.46066C101.708 0.46066 101.556 0.616798 101.556 0.809958C101.556 1.00312 101.715 1.16087 101.902 1.16087C102.1 1.16087 102.249 0.998289 102.249 0.809958Z" fill="#1C2026"/>
7
- <path d="M42.5486 0.0388184C37.204 0.0388184 33.5098 3.06983 33.5098 7.50447C33.5098 11.9391 37.204 15.02 42.5486 15.02C47.8933 15.02 51.5018 11.9375 51.5018 7.49803C51.5018 3.05856 47.8642 0.0388184 42.5486 0.0388184ZM42.5486 12.2836C39.0227 12.2836 36.5519 10.3327 36.5519 7.4771C36.5519 4.62155 39.0179 2.78331 42.5486 2.78331C46.0794 2.78331 48.4613 4.67789 48.4613 7.4771C48.4613 10.2763 45.9872 12.2787 42.5486 12.2787V12.2852V12.2836Z" fill="#1C2026"/>
8
- <path d="M10.4321 6.17332H5.62948C2.78642 6.17332 2.01943 2.78013 7.93208 2.78013C10.4337 2.78013 12.3949 3.85539 13.2476 4.41878L14.7833 2.10085C13.3318 0.827603 10.7751 0.0356445 7.90457 0.0356445C-1.589 0.0356445 -1.70389 8.85825 5.65861 8.85825H10.4903C13.6166 8.85825 14.1279 12.2804 7.93208 12.2804C4.83336 12.2804 2.38836 10.6402 1.53561 10.0172L0 12.3367C1.45146 13.6084 4.51944 15.0217 7.95797 15.0217C17.9062 15.0152 18.0211 6.17171 10.4321 6.17171V6.17332Z" fill="#1C2026"/>
9
- <path d="M26.0314 12.2771C22.3939 12.2771 20.0346 10.3262 20.0346 7.527C20.0346 4.72779 22.3648 2.7817 26.0023 2.7817C28.0784 2.7817 30.0104 3.85696 31.1755 4.93061L32.9166 2.52737C31.2677 1.22836 28.737 0.0388184 26.0088 0.0388184C20.5508 0.0388184 16.999 3.09397 16.999 7.53344C16.999 11.9729 20.6042 15.02 26.0654 15.02C28.8502 15.02 31.381 13.7757 33.0282 12.4751L31.2386 10.1266C30.0687 11.2067 28.135 12.2771 26.0314 12.2771Z" fill="#1C2026"/>
10
- <path d="M80.9771 0.0372542C75.8605 0.0372542 72.3071 3.09241 72.3071 7.53188C72.3071 11.9714 76.3719 15.0185 81.9156 15.0185C84.8428 15.0185 87.2829 14.0575 88.8218 12.7569L87.0289 10.4148C85.9771 11.5464 84.2732 12.3657 81.8849 12.3657C78.558 12.3657 76.1874 10.9814 75.5013 8.85986H89.592V7.5013C89.5872 3.06182 86.092 0.0356445 80.9755 0.0356445L80.9771 0.0372542ZM80.948 2.69482C83.8768 2.69482 85.88 4.06787 86.4075 6.25702H75.4447C75.9884 4.08718 77.9722 2.69482 80.948 2.69482Z" fill="#1C2026"/>
11
- <path d="M62.7358 0.0372542C60.1921 0.0372542 58.1743 0.925792 56.7875 2.29562C56.4283 1.16563 55.4364 0.462207 54.0917 0.462207H52.2471V3.14875H53.951V20.0004H56.9364V12.8792C58.3151 14.1782 60.273 15.0233 62.739 15.0233C67.485 15.0233 70.7536 11.9408 70.7536 7.5013C70.7536 3.06182 67.4802 0.0356445 62.7342 0.0356445L62.7358 0.0372542ZM62.3652 12.2756C59.1241 12.2756 56.9364 10.3247 56.9364 7.4691C56.9364 4.61355 59.1241 2.7753 62.3652 2.7753C65.6064 2.7753 67.7099 4.66989 67.7099 7.4691C67.7067 10.3311 65.464 12.2756 62.3652 12.2756Z" fill="#1C2026"/>
12
- </svg>`;try{const h=await this._loadSvgAsImage(c);h&&e.drawImage(h,a,(n-r)/2,o,r)}catch(h){console.warn("Failed to load logo SVG:",h)}}_drawHeaderSecondLine(e,t,s,n,a,r){const o=20*r,c=12*r,h=8*r;e.fillStyle="#FFFFFF",e.fillRect(0,a,n,o),e.strokeStyle="#EDEDED",e.lineWidth=1*r,e.beginPath(),e.moveTo(0,a+o),e.lineTo(n,a+o),e.stroke(),e.fillStyle="#1C2026",e.font=`500 ${h}px Geist, Arial, sans-serif`,e.textBaseline="middle",e.textAlign="left";const u=t?`${t} created with Scope360, ${s}`:`Scope360, ${s}`;e.fillText(u,c,a+o/2)}_loadSvgAsImage(e){return new Promise((t,s)=>{const n=new Image,a=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(a);n.onload=()=>{URL.revokeObjectURL(r),t(n)},n.onerror=()=>{URL.revokeObjectURL(r),s(new Error("Failed to load SVG"))},n.src=r})}_drawFooter(e,t,s,n,a,r){const o=32*r,c=12*r,h=12*r,u=4*r,g=n+a;e.fillStyle="#FFFFFF",e.fillRect(0,g,s,o),e.strokeStyle="#EDEDED",e.lineWidth=1*r,e.beginPath(),e.moveTo(0,g),e.lineTo(s,g),e.stroke(),e.textBaseline="middle",e.textAlign="left";const _=[];if(t.pair&&_.push({label:"",value:t.pair}),t.net_pnl!==void 0){const w=t.net_pnl.startsWith("+");_.push({label:"Net P&L",value:t.net_pnl,valueColor:w?"#56B683":"#F18169"})}t.type&&_.push({label:"Type",value:t.type}),t.entry_price&&_.push({label:"Entry",value:t.entry_price}),t.exit_price&&_.push({label:"Exit",value:t.exit_price}),t.open_date&&_.push({label:"Open date",value:t.open_date}),t.close_date&&_.push({label:"Close date",value:t.close_date}),t.holdtime&&_.push({label:"Holdtime",value:t.holdtime}),t.rr&&_.push({label:"RR",value:t.rr}),t.volume&&_.push({label:"Volume",value:t.volume});const p=g+o/2,v=24*r;if(_.length===0)return;e.font=`500 ${h}px Geist, Arial, sans-serif`;let b=c;_.forEach(w=>{const C=e.measureText(w.label).width,y=e.measureText(w.value).width,x=C+u+y;e.fillStyle="#8E8E93",e.font=`500 ${h}px Geist, Arial, sans-serif`,e.fillText(w.label,b,p);const A=b+C+u;e.fillStyle=w.valueColor||"#1C2026",e.font=`500 ${h}px Geist, Arial, sans-serif`,e.fillText(w.value,A,p),b+=x+v})}async captureScreenshot(e={}){const t=typeof e=="string"?e:e.filename||"candlestick-chart.png",n=new Date().toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",timeZoneName:"short"}),a=typeof e=="object"?e:{},r=a.createdBy,o=a.createdAt||n,c=a.trade,{width:h,height:u,canvasesContainer:g}=this._view,_=Array.from(g.node.querySelectorAll("canvas"));if(_.length===0){console.warn("No canvas elements found for screenshot");return}const p=window.devicePixelRatio||1,v=48*p,b=20*p,w=c?32*p:0,C=u*p,y=C+v+b+w,x=document.createElement("canvas");x.width=h*p,x.height=y;const A=x.getContext("2d");if(!A){console.error("Failed to get 2D context for merged canvas");return}A.fillStyle="#ffffff",A.fillRect(0,0,x.width,x.height);let H=v+b;await this._drawHeader(A,x.width,p),this._drawHeaderSecondLine(A,r,o,x.width,v,p);const R=this._view.mainCanvas;R.background&&(A.fillStyle=R.background,A.fillRect(0,H,x.width,C)),_.forEach($=>{A.drawImage($,0,0,$.width,$.height,0,H,x.width,C)}),c&&this._drawFooter(A,c,x.width,H,C,p),x.toBlob($=>{if(!$){console.error("Failed to create blob from canvas");return}const P=URL.createObjectURL($),W=document.createElement("a");W.href=P,W.download=t,document.body.appendChild(W),W.click(),document.body.removeChild(W),URL.revokeObjectURL(P)},"image/png",1)}}O.CandlestickChart=Xn,O.createLineChart=zi,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(V,j){typeof exports=="object"&&typeof module<"u"?j(exports,require("d3")):typeof define=="function"&&define.amd?define(["exports","d3"],j):(V=typeof globalThis<"u"?globalThis:V||self,j(V.ChartsCore={},V.d3))})(this,function(V,j){"use strict";var vr=Object.defineProperty;var br=(V,j,me)=>j in V?vr(V,j,{enumerable:!0,configurable:!0,writable:!0,value:me}):V[j]=me;var f=(V,j,me)=>br(V,typeof j!="symbol"?j+"":j,me);function me(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const k=me(j),Ai=i=>{const{svg:e,config:t,y:s,width:n}=i,{margin:a,yAxis:r}=t,{customTicks:o,tickFormat:c,tickValues:h,ticks:u,isShow:g}=r;if(!g)return null;e.append("g").attr("transform",`translate(${n-a.right},0)`).call(_=>{let p=k.axisRight(s);o&&c?p=p.tickFormat(c):p=p.tickFormat(v=>{const b=Number(v),x=C=>C.toString().replace(/\.0+$/,"");return Math.abs(b)>=1e12?x(b/1e12)+"T":Math.abs(b)>=1e9?x(b/1e9)+"B":Math.abs(b)>=1e6?x(b/1e6)+"M":Math.abs(b)>=1e3?x(b/1e3)+"K":x(b)}),o&&u&&(p=Array.isArray(u)?p.ticks(...u):p.ticks(u)),o&&h&&(p=p.tickValues(h)),_.call(p)}).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),i.yTicks=p}).call(_=>_.select(".domain").remove()).call(_=>_.selectAll(".tick line").remove()).call(_=>{const p=_.selectAll(".tick text");p.classed("sc-charts__y-axis-tick",!0).attr("text-anchor","start");const v=p.nodes().map(x=>x.getBBox().width),b=Math.max(...v);_.selectAll(".tick").each(function(x,C){var $;const y=k.select(this),w=y.select("text"),M=v[C],L=b-M,R=y.append("g").attr("transform","translate(10, 0)");w.attr("x",L),w.remove(),($=R.node())==null||$.appendChild(w.node())})}).attr("font-family","inherit")},Mi=i=>{const{svg:e,config:t,x:s,height:n}=i,{margin:a,xAxis:r}=t,{isShow:o,tickValues:c,tickFormat:h,customTicks:u,ticks:g}=r;if(!o)return null;e.append("g").attr("transform",`translate(0,${n-a.bottom})`).call(_=>{let p=k.axisBottom(s);u?(h&&(p=p.tickFormat(h)),g&&(p=Array.isArray(g)?p.ticks(...g):p.ticks(g)),c&&(p=p.tickValues(c))):p.ticks(5),_.call(p)}).call(_=>_.select(".domain").remove()).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),i.xTicks=p}).call(_=>_.selectAll(".tick line").remove()).call(_=>_.selectAll(".tick text").classed("sc-charts__x-axis-tick",!0)).attr("font-family","inherit")},Ti=i=>{const{svg:e,config:t,y:s,width:n}=i,{margin:a,grid:{horizontalStyle:r}}=t;if(r!=="none"){if(r.startsWith("zero-line")){const o=e.append("line").attr("x1",0+a.left).attr("x2",n-a.right).attr("y1",s(0)).attr("y2",s(0)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);r==="zero-line-dashed"&&o.attr("stroke-dasharray","4 4")}r.startsWith("every-line")&&(i.yTicks||s.ticks()).forEach(c=>{const h=e.append("line").attr("x1",0+a.left).attr("x2",n-a.right).attr("y1",s(c)).attr("y2",s(c)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);r==="every-line-dashed"&&h.attr("stroke-dasharray","4 4")})}},ki=i=>{const e=Array.from(i.childNodes);for(let t=0;t<e.length;t++)i.removeChild(e[t])},Di=i=>{const e="http://www.w3.org/2000/svg",t=document.createElement("div");t.className="sc-charts__hovered-circles-tooltip-container",t.style.display="none";const s=document.createElement("div");s.className="sc-charts__hovered-circles-tooltip";const n=document.createElement("div");n.className="sc-charts__hovered-circles-tooltip-arrow";const a=document.createElementNS(e,"svg");a.setAttribute("width","12"),a.setAttribute("height","4"),a.setAttribute("viewBox","0 0 12 4"),a.setAttribute("fill","none"),a.setAttribute("xmlns",e);const r=document.createElementNS(e,"path");return r.setAttribute("d","M6 4L0 0H12L6 4Z"),a.appendChild(r),n.appendChild(a),t.append(n),t.append(s),i.append(t),{tooltipContainer:t,tooltip:s,tooltipArrow:n}},Ei=(i,e,{x:t,y:s,r:n=3.5,hr:a=0})=>{if(e)return i.append("image").attr("x",t-6).attr("y",s-6).attr("width",12).attr("height",12).attr("href","data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAxMyAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzE0NTJfNTAwOSkiPgo8cGF0aCBkPSJNNi41MzY0NiAxMS41Njg4QzkuMjA1ODYgMTEuNTY4OCAxMS4zNjk4IDkuNDA0ODMgMTEuMzY5OCA2LjczNTQzQzExLjM2OTggNC4wNjYwNiA5LjIwNTg2IDEuOTAyMSA2LjUzNjQ2IDEuOTAyMUMzLjg2NzA4IDEuOTAyMSAxLjcwMzEyIDQuMDY2MDYgMS43MDMxMiA2LjczNTQzQzEuNzAzMTIgOS40MDQ4MyAzLjg2NzA4IDExLjU2ODggNi41MzY0NiAxMS41Njg4WiIgZmlsbD0iI0ZDRUJFOSIvPgo8cGF0aCBkPSJNMy4xMTcxOSAxMC4xNTM1TDkuOTQ3MTkgMy4zMjM0OSIgc3Ryb2tlPSIjRjE4MTY5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHBhdGggZD0iTTYuNTM2NDYgMTEuNTY4OEM5LjIwNTg2IDExLjU2ODggMTEuMzY5OCA5LjQwNDgzIDExLjM2OTggNi43MzU0M0MxMS4zNjk4IDQuMDY2MDYgOS4yMDU4NiAxLjkwMjEgNi41MzY0NiAxLjkwMjFDMy44NjcwOSAxLjkwMjEgMS43MDMxMiA0LjA2NjA2IDEuNzAzMTIgNi43MzU0M0MxLjcwMzEyIDkuNDA0ODMgMy44NjcwOSAxMS41Njg4IDYuNTM2NDYgMTEuNTY4OFoiIHN0cm9rZT0iI0YxODE2OSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDBfMTQ1Ml81MDA5Ij4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC41MzUxNTYgMC43MzUzNTIpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==");{const r=i.append("g");return r.append("circle").attr("cx",t).attr("cy",s).attr("r",n).classed("sc-charts__hovered-circles",!0),r.append("circle").attr("cx",t).attr("cy",s).attr("r",n+a).classed("sc-charts__hovered-circles_add",!0),r}};function Li(i,e,t,s){if(!i)return null;const n=i.width/2,a=e-n,r=e+n;return a<t?t:r>s?s-i.width:e-n}const Nt=(i,{x1:e,x2:t,y1:s,y2:n})=>i.append("line").attr("x1",e).attr("x2",t).attr("y1",s).attr("y2",n).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1),Ni=i=>{const{svg:e,config:t,x:s,y:n,height:a,data:r,wrapperNode:o}=i,{margin:c,grid:{verticalStyle:h,tooltipNode:u,hoverCirclesRadius:g,hoverCirclesAdditionalArea:_}}=t;if(h!=="none"&&(h.startsWith("every-line")&&(i.xTicks||s.ticks()).forEach(v=>{const b=e.append("line").attr("x1",s(v)).attr("x2",s(v)).attr("y1",c.top).attr("y2",a-c.bottom).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);h==="every-line-dashed"&&b.attr("stroke-dasharray","4 4")}),h==="hovered-circles")){const p=n.range()[0],v=s(r[0].date),b=s(r[r.length-1].date);Nt(e,{x1:v,x2:b,y1:p,y2:p});const{tooltipContainer:x,tooltip:C,tooltipArrow:y}=Di(o);r.forEach((w,M)=>{const L=s(w.date),R=n(w.value),$=r[M-1],O=M>0&&$&&w.value===$.value;O||Nt(e,{x1:L,x2:L,y1:R,y2:p});const se=Ei(e,O,{x:L,y:p,r:g,hr:_});u&&se.on("mouseover",function(){ki(C),x.style.display="block",C.append(u({date:w.date,value:O?null:w.value}));const U=C.getBoundingClientRect(),P=Li(U,s(w.date),i.config.margin.left-i.config.grid.tooltipArrowSize,i.width-i.config.margin.right+i.config.grid.tooltipArrowSize);C.style.left=P+"px",y.style.left=s(w.date)+"px"}).on("mouseout",function(){x.style.display="none"})})}},Fi=i=>{Ti(i),Ni(i)},Hi=i=>{const{svg:e,config:t,width:s,height:n}=i,{margin:a,logo:r}=t;Mi(i),Ai(i),r&&e.append("image").attr("xlink:href",t.theme==="dark"?r.picDarkTheme:r.picLightTheme).attr("width",r.width).attr("height",r.height).attr("x",r.x??(s-a.left-a.right)/2-r.width/2+a.left).attr("y",r.y??(n-a.top-a.bottom)/2-r.height/2+a.top),Fi(i)},we=(i,e,t)=>{let s=i.select(`#${e}`);return s.empty()&&(s=i.append("linearGradient").attr("gradientUnits","userSpaceOnUse").attr("id",e)),s.attr("x1",t.x1).attr("y1",t.x2).attr("x2",t.y1).attr("y2",t.y2),t.stops.forEach(({offset:n,stopColor:a})=>{s.append("stop").attr("offset",n).attr("stop-color",a)}),s},pe=i=>{const e=k.select(i).select("defs");return e.empty()?k.select(i).append("defs"):e},Ft=i=>{const{y:e,config:{margin:t}}=i,s=e.range()[0]-e(0),n=e.range()[0]-s>=0?e.range()[0]-s:0,a=s+t.bottom>=0?s+t.bottom:0;return{x:0,y:n,width:"100%",height:a}},Ht=(i,e)=>({...i,...e,margin:{...i.margin,...e==null?void 0:e.margin},logo:i.logo&&(e!=null&&e.logo)?{width:e.logo.width??i.logo.width,height:e.logo.height??i.logo.height,picLightTheme:e.logo.picLightTheme??i.logo.picLightTheme,picDarkTheme:e.logo.picDarkTheme??i.logo.picDarkTheme,x:e.logo.x??i.logo.x,y:e.logo.y??i.logo.y}:i.logo,xAxis:{...i.xAxis,...e==null?void 0:e.xAxis},yAxis:{...i.yAxis,...e==null?void 0:e.yAxis},grid:{...i.grid,...e==null?void 0:e.grid},hover:{...i.hover,...e==null?void 0:e.hover},selection:{...i.selection,...e==null?void 0:e.selection}}),Bt=(i,e={})=>{const t=i.node(),s=pe(t),n=(o,c)=>we(s,o,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"20%",stopColor:c},{offset:"60%",stopColor:c},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});n("gradient-range-borders-up","var(--sc-color-selection-up)"),n("gradient-range-borders-down","var(--sc-color-selection-down)");const a="sc-charts__border-range-line",r=i.append("line").classed(a,!0).style("display",e.hidden?"none":"block");return{className(o,c){o==="remove"?r.classed(`${a}${c}`,!1):r.classed(`${a}${c}`,!0)},update({x1:o,x2:c,y1:h,y2:u,hidden:g}){o!==void 0&&r.attr("x1",o),c!==void 0&&r.attr("x2",c),h!==void 0&&r.attr("y1",h),u!==void 0&&r.attr("y2",u),g!==void 0&&r.style("display",g?"none":"block")},destroy(){r.remove()}}},st=(i,e={})=>{const t=i.append("circle").attr("r",e.radius||4).style("display",e.hidden?"none":"block"),s=e.className||"";return s&&t.classed(s,!0),{className(n,a){n==="remove"?t.classed(`${s}${a}`,!1):t.classed(`${s}${a}`,!0)},update({cx:n,cy:a,hidden:r,fill:o}){n!==void 0&&t.attr("cx",n),a!==void 0&&t.attr("cy",a),o!==void 0&&t.attr("fill",o),r!==void 0&&t.style("display",r?"none":"block")},destroy(){t.remove()}}},Bi=(i,e={})=>{const t="sc-charts__hover-line",s=i.append("line").style("display",e.hidden?"none":"block").classed(t,!0),n=i.node(),a=pe(n);return((o,c)=>we(a,o,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"15%",stopColor:c},{offset:"75%",stopColor:c},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]}))("hover-line-gradient","var(--sc-color-hover-line)"),{className(o,c){o==="remove"?s.classed(`${t}${c}`,!1):s.classed(`${t}${c}`,!0)},update({x1:o,x2:c,y1:h,y2:u,hidden:g}){o!==void 0&&s.attr("x1",o),c!==void 0&&s.attr("x2",c),h!==void 0&&s.attr("y1",h),u!==void 0&&s.attr("y2",u),g!==void 0&&s.style("display",g?"none":"block")},destroy(){s.remove()}}},le="sc-charts__range-tooltip",It=k.timeFormat("%b %e, %I:%M %p"),Ii=i=>{const e=k.format(",.2f");return`${i<0?"-":""}$${e(Math.abs(i))}`};function Ri(i){const e="http://www.w3.org/2000/svg",t=document.createElement("div");t.className=le,t.style.position="absolute",t.style.top="0",t.style.pointerEvents="none",t.style.display="none",i.append(t);const s=document.createElement("div");s.className=`${le}-container`,t.append(s);const n=document.createElement("div");n.className=`${le}-sum`,s.append(n);const a=document.createElement("div");a.className=`${le}-sum-icon`;const r=document.createElementNS(e,"svg");r.setAttribute("width","14"),r.setAttribute("height","14"),r.setAttribute("viewBox","0 0 14 14"),r.setAttribute("fill","none"),r.setAttribute("xmlns",e);const o=document.createElementNS(e,"path");o.setAttribute("d","M7 0.5C5.71442 0.5 4.45772 0.881218 3.3888 1.59545C2.31988 2.30968 1.48676 3.32484 0.994786 4.51256C0.502816 5.70028 0.374095 7.00721 0.624899 8.26809C0.875703 9.52896 1.49477 10.6872 2.40381 11.5962C3.31285 12.5052 4.47104 13.1243 5.73192 13.3751C6.99279 13.6259 8.29973 13.4972 9.48744 13.0052C10.6752 12.5132 11.6903 11.6801 12.4046 10.6112C13.1188 9.54229 13.5 8.28558 13.5 7C13.4982 5.27665 12.8128 3.62441 11.5942 2.40582C10.3756 1.18722 8.72335 0.50182 7 0.5ZM9.35375 6.85375C9.30732 6.90024 9.25217 6.93712 9.19147 6.96228C9.13077 6.98744 9.06571 7.00039 9 7.00039C8.93429 7.00039 8.86923 6.98744 8.80853 6.96228C8.74783 6.93712 8.69269 6.90024 8.64625 6.85375L7.5 5.70687V9.5C7.5 9.63261 7.44732 9.75979 7.35356 9.85355C7.25979 9.94732 7.13261 10 7 10C6.86739 10 6.74022 9.94732 6.64645 9.85355C6.55268 9.75979 6.5 9.63261 6.5 9.5V5.70687L5.35375 6.85375C5.25993 6.94757 5.13268 7.00028 5 7.00028C4.86732 7.00028 4.74007 6.94757 4.64625 6.85375C4.55243 6.75993 4.49972 6.63268 4.49972 6.5C4.49972 6.36732 4.55243 6.24007 4.64625 6.14625L6.64625 4.14625C6.69269 4.09976 6.74783 4.06288 6.80853 4.03772C6.86923 4.01256 6.9343 3.99961 7 3.99961C7.06571 3.99961 7.13077 4.01256 7.19147 4.03772C7.25217 4.06288 7.30732 4.09976 7.35375 4.14625L9.35375 6.14625C9.40024 6.19269 9.43712 6.24783 9.46228 6.30853C9.48744 6.36923 9.5004 6.43429 9.5004 6.5C9.5004 6.56571 9.48744 6.63077 9.46228 6.69147C9.43712 6.75217 9.40024 6.80731 9.35375 6.85375Z"),o.setAttribute("fill","currentColor"),r.appendChild(o),a.appendChild(r),n.append(a);const c=document.createElement("div");n.append(c);const h=document.createElement("div");return h.className=`${le}-time`,s.append(h),{wrapper:t,sumNode:c,timeNode:h}}const $i=i=>{const{wrapper:e,sumNode:t,timeNode:s}=Ri(i.wrapperNode);return{className(n,a){n==="remove"?e.classList.remove(`${le}${a}`):e.classList.add(`${le}${a}`)},update({leftPoint:n,rightPoint:a,x:r,y:o,hidden:c,closest:h}){if(n&&a&&h&&r!==void 0){const u=a.value-n.value,{sumFormatter:g,timeFormatter:_}=i.config.selection,p=(i.x(a.date)+i.x(n.date))/2,v=i.x(h.date)<p?"left":"right";let b="",x="";if(g)b=g({left:n.value,right:a.value,direction:v});else{const C=(u/Math.abs(n.value)*100).toFixed(2);b=`${Ii(u)} (${C}%)`}_?x=_({left:n.date,right:a.date,direction:v}):x=`${It(n.date)} to ${It(a.date)}`,t.textContent=b,s.textContent=x,requestAnimationFrame(()=>{const C=e.getBoundingClientRect(),y=i.wrapperNode.getBoundingClientRect(),w=i.x(n.date),M=i.x(a.date);let R=(w+M)/2-C.width/2;const $=0,O=y.width-C.width;R<$&&(R=$),R>O&&(R=O),e.style.left=`${R}px`,e.style.top=`${o}px`})}c!==void 0&&(e.style.display=c?"none":"block")},destroy(){e.remove()}}},xe="sc-charts__hover-tooltip",nt=16,Oi=k.timeFormat("%a, %b %d, %-I:%M %p"),Pi=i=>{const e=k.format(",.2f");return`${i<0?"-":""}$${e(Math.abs(i))}`};function zi(i){const e=document.createElement("div");e.className=`${xe}-container`,e.style.position="absolute",e.style.top="0",e.style.pointerEvents="none",e.style.display="none",i.appendChild(e);const t=document.createElement("div");t.className=`${xe}-sum`,e.appendChild(t);const s=document.createElement("div");return s.className=`${xe}-time`,e.appendChild(s),{wrapper:e,sumNode:t,timeNode:s}}function Vi(i,e,t){return i?e+nt+i.width<t?e+nt:e-nt-i.width:null}const ji=i=>{const{wrapper:e,sumNode:t,timeNode:s}=zi(i.wrapperNode);return{className(n,a){n==="remove"?e.classList.remove(`${xe}${a}`):e.classList.add(`${xe}${a}`)},update({hidden:n,dataItem:a}){if(a){const{sumFormatter:r,timeFormatter:o}=i.config.hover;t.textContent=r?r(a.value):Pi(a.value),s.textContent=o?o(a.date):Oi(a.date),requestAnimationFrame(()=>{const c=e.getBoundingClientRect(),h=Vi(c,i.x(a.date),i.width-i.config.margin.right);h&&(e.style.left=h+"px")})}n!==void 0&&(e.style.display=n?"none":"block")},destroy(){e.remove()}}},Yi={margin:{top:10,right:30,bottom:20,left:10},theme:"light",logo:{width:406,height:113,x:null,y:null,picDarkTheme:null,picLightTheme:null},extremePointFormatter:null,hasExtremePoint:!1,hasMainLineArea:!1,hover:{enable:!0,range:"1m",transitionDuration:150,transitionName:"default",sumFormatter:null,timeFormatter:null},selection:{enable:!0,sumFormatter:null,timeFormatter:null},xAxis:{customTicks:!1,tickFormat:null,ticks:null,tickValues:null,isShow:!1},yAxis:{customTicks:!1,tickFormat:null,ticks:null,tickValues:null,isShow:!0},grid:{horizontalStyle:"zero-line-dashed",verticalStyle:"none",tooltipNode:null,tooltipArrowSize:12,hoverCirclesRadius:3.5,hoverCirclesAdditionalArea:2},enableBelowZeroLine:!1,curveTension:1},Re=i=>k.curveCardinal.tension(i.config.curveTension),Wi=i=>{const{svg:e,data:t,x:s,y:n,config:a}=i,r=e.node(),o=pe(r);we(o,"main-line-area-gradient",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-main-line)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});const h=k.area().x(_=>s(_.date)).y0(n.range()[0]).y1(_=>n(_.value)).curve(Re(i)),u="sc-charts__main-line-area",g=e.append("path").datum(t).attr("d",h).attr("class",u).classed(`${u}_hidden`,!a.hasMainLineArea);return{className(_,p){_==="remove"?g.classed(`${u}${p}`,!1):g.classed(`${u}${p}`,!0)},update({data:_,hidden:p}){if(_!==void 0&&g.datum(_).attr("d",h),p!==void 0){if(!a.hasMainLineArea)return null;g.classed(`${u}_hidden`,p)}},destroy(){g.remove()}}},Xi=(i,e={})=>{const t="sc-charts__range-line-area",{svg:s,x:n,y:a,config:r,data:o,chartId:c}=i,{clip:h}=e,u=s.node(),g=pe(u),_="range-line-area-gradient";we(g,_+"_up",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-selection-up)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]}),we(g,_+"_down",{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"var(--sc-color-selection-down)"},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]});const p=k.area().x(y=>n(y.date)).y0(a.range()[0]).y1(y=>a(y.value)).curve(Re(i)),v=`${c}-clip-${t}`,x=g.append("clipPath").attr("id",v).append("rect").attr("x",(h==null?void 0:h.x)||0).attr("y",(h==null?void 0:h.y)||0).attr("width",(h==null?void 0:h.width)||"100%").attr("height",(h==null?void 0:h.height)||"100%"),C=s.append("path").datum(o).attr("d",p).attr("class",t).classed(`${t}_hidden`,!r.hasMainLineArea).attr("clip-path",`url(#${v})`);return{className(y,w){y==="remove"?C.classed(`${t}${w}`,!1):C.classed(`${t}${w}`,!0)},update({data:y,hidden:w,clip:M}){y!==void 0&&C.datum(y).attr("d",p),w!==void 0&&C.classed(`${t}_hidden`,w),M!==void 0&&x.attr("x",M.x).attr("y",M.y).attr("width",M.width).attr("height",M.height)},destroy(){C.remove()}}},at=(i,e)=>{const{svg:t,data:s,x:n,y:a,chartId:r}=i,{baseClassName:o,id:c,clip:h}=e,u=t.node(),g=pe(u),_=k.line().x(C=>n(C.date)).y(C=>a(C.value)).curve(Re(i)),p=`${r}-clip-${o}`,b=g.append("clipPath").attr("id",p).append("rect").attr("x",(h==null?void 0:h.x)||0).attr("y",(h==null?void 0:h.y)||0).attr("width",(h==null?void 0:h.width)||"100%").attr("height",(h==null?void 0:h.height)||"100%"),x=t.append("path").classed(o,!0).datum(s).attr("d",_).attr("id",c).attr("clip-path",`url(#${p})`);return{className(C,y){C==="remove"?x.classed(`${o}${y}`,!1):x.classed(`${o}${y}`,!0)},update({data:C,clip:y,hidden:w}){C!==void 0&&x.datum(C).attr("d",_),w!==void 0&&x.classed(`${o}_hidden`,w),y!==void 0&&b.attr("x",y.x).attr("y",y.y).attr("width",y.width).attr("height",y.height)},destroy(){x.remove()}}},Ui=(i,e)=>{const{svg:t,data:s,x:n,y:a,chartId:r,config:o}=i,{baseClassName:c,id:h,clip:u}=e,g=t.node(),_=pe(g),p=k.line().x(y=>n(y.date)).y(y=>a(y.value)).curve(Re(i)),v=`${r}-clip-${c}`,x=_.append("clipPath").attr("id",v).append("rect").attr("x",(u==null?void 0:u.x)||0).attr("y",(u==null?void 0:u.y)||0).attr("width",(u==null?void 0:u.width)||"100%").attr("height",(u==null?void 0:u.height)||"100%"),C=t.append("path").classed(c,!0).datum(s).attr("d",p).attr("id",h).attr("clip-path",`url(#${v})`);return{className(y,w){y==="remove"?C.classed(`${c}${w}`,!1):C.classed(`${c}${w}`,!0)},update({data:y,clip:w,hidden:M}){y!==void 0&&C.datum(y).attr("d",p),M!==void 0&&C.classed(`${c}_hidden`,M),w!==void 0&&(o.hover.transitionName==="default"?x.transition().duration(o.hover.transitionDuration).attr("x",w.x).attr("y",w.y).attr("width",w.width).attr("height",w.height).ease(k.easeLinear):x.attr("x",w.x).attr("y",w.y).attr("width",w.width).attr("height",w.height))},destroy(){C.remove()}}},Gi=i=>{const e=Math.abs(i);let t;return e>=1e9?t=(i/1e9).toFixed(1)+"B":e>=1e6?t=(i/1e6).toFixed(1)+"M":e>=1e3?t=(i/1e3).toFixed(1)+"K":t=i.toFixed(1),t},Zi=(i,e)=>{const{svg:t,data:s,x:n,y:a}=i,{baseClassName:r}=e,o=t.append("g").classed(r,!0),c=o.append("circle").attr("r",5).classed(`${r}-circle`,!0),h=o.append("text").attr("text-anchor","middle").attr("dy","-9px").classed(`${r}-label`,!0);return(g=>{if(!g||g.length===0)return;const _=g[g.length-1],p=n(_.date),v=a(_.value);c.attr("cx",p).attr("cy",v);const b=i.config.extremePointFormatter||Gi;h.attr("x",p).attr("y",v).text(b(_.value))})(s),{className(g,_){g==="remove"?o.classed(`${r}${_}`,!1):o.classed(`${r}${_}`,!0)},update({hidden:g}){g!==void 0&&o.classed(`${r}_hidden`,g)},destroy(){o.remove()}}},qi=i=>{const e=at(i,{baseClassName:"sc-charts__main-line",id:`${i.chartId}-sc-charts__main-line`}),t=Wi(i);let s=null;i.config.hasExtremePoint&&(s=Zi(i,{baseClassName:"sc-charts__extreme-point"}));const n=Bi(i.svg),a=Ui(i,{baseClassName:"sc-charts__highlight-line",id:`${i.chartId}-sc-charts__highlight-line`,clip:{x:0,y:0,width:"0",height:"0"}});let r=null;i.config.enableBelowZeroLine&&(r=at(i,{baseClassName:"sc-charts__below-zero-line",id:`${i.chartId}-sc-charts__below-zero-line`,clip:Ft(i)}));const o=st(i.svg,{className:"sc-charts__hover-circle",hidden:!0}),c=Bt(i.svg),h=Bt(i.svg),u=at(i,{baseClassName:"sc-charts__range-line",id:`${i.chartId}-sc-charts__range-line`,clip:{x:0,y:0,width:"0",height:"0"}}),g=st(i.svg,{className:"sc-charts__range-circle-left",hidden:!0}),_=st(i.svg,{className:"sc-charts__range-circle-right",hidden:!0}),p=$i(i),v=ji(i),b=Xi(i);return{hoverLine:n,hoverCircle:o,rangeBorderLeft:c,rangeBorderRight:h,rangeLine:u,rangeLineArea:b,rangeCircleLeft:g,rangeCircleRight:_,mainLine:e,rangeTooltip:p,highlightLine:a,hoverTooltip:v,mainLineArea:t,belowZeroLine:r,extremePoint:s}},Ji=(i,e,t)=>{const s=i.match(/^(\d+)([dMhmw])$/);if(!s)return console.warn("Invalid hoverRange:",i),{x:0,y:0,width:"100%",height:"100%"};const[,n,a]=s,r=parseInt(n,10),[o,c]=t.domain();let h=new Date(o);for(;h<c;){let u=new Date(h);switch(a){case"M":u.setMinutes(u.getMinutes()+r);break;case"h":u.setHours(u.getHours()+r);break;case"d":u.setDate(u.getDate()+r);break;case"w":u.setDate(u.getDate()+r*7);break;case"m":u=new Date(h.getFullYear(),h.getMonth()+r,1);break;default:return{x:0,y:0,width:"100%",height:"100%"}}if(e>=h&&e<u){const g=t(h),_=t(u);return{x:g,y:0,width:_-g,height:"100%"}}h=new Date(u)}if(e.getTime()===c.getTime()){let u=new Date(c);switch(a){case"M":u.setMinutes(u.getMinutes()-r);break;case"h":u.setHours(u.getHours()-r);break;case"d":u.setDate(u.getDate()-r);break;case"w":u.setDate(u.getDate()-r*7);break;case"m":u=new Date(c.getFullYear(),c.getMonth()-r,1);break}const g=t(u),_=t(c);return{x:g,y:0,width:_-g,height:"100%"}}return{x:0,y:0,width:"100%",height:"100%"}},Rt=(i,e)=>{var h;const{x:t,y:s,elements:n,config:{margin:a},height:r}=i;n.hoverLine.update({x1:t(e.date),x2:t(e.date),y1:a.top,y2:r-a.bottom,hidden:!1}),n.hoverCircle.update({cx:t(e.date),cy:s(e.value),hidden:!1}),n.hoverTooltip.update({dataItem:e,hidden:!1});const o=Ji(i.config.hover.range,e.date,t);n.highlightLine.update({clip:o,hidden:!1});const c=s.range()[0]-s(0)+a.bottom;c>=0&&((h=n.belowZeroLine)==null||h.update({clip:{...o,y:s(0),height:c}})),n.mainLine.className("add","_muted")},$t=i=>{var t;const{elements:e}=i;e.hoverLine.update({hidden:!0}),e.hoverCircle.update({hidden:!0}),e.highlightLine.update({hidden:!0}),e.mainLine.className("remove","_muted"),e.hoverTooltip.update({hidden:!0}),i.action!=="selection"&&((t=e.belowZeroLine)==null||t.update({clip:Ft(i)}))},Qi=(i,e)=>{["rangeBorderLeft","rangeBorderRight","rangeCircleLeft","rangeCircleRight","rangeLine","rangeLineArea","rangeTooltip"].forEach(s=>{e?(i[s].className("remove","_down"),i[s].className("add","_up")):(i[s].className("remove","_up"),i[s].className("add","_down"))})},Ki=(i,e,t)=>{var v;const{x:s,y:n,config:{margin:a},height:r,elements:o}=i,c=s(e.date)<s(t.date)?e:t,h=s(e.date)>=s(t.date)?e:t,u=h.value-c.value>=0,g=s(c.date),_=s(h.date),p=_-g;o.rangeBorderLeft.update({x1:g,x2:g,y1:a.top,y2:r-a.bottom,hidden:!1}),o.rangeBorderRight.update({x1:_,x2:_,y1:a.top,y2:r-a.bottom,hidden:!1}),o.rangeCircleLeft.update({cx:g,cy:n(c.value),hidden:!1}),o.rangeCircleRight.update({cx:_,cy:n(h.value),hidden:!1}),o.rangeLine.update({clip:{x:g,y:0,width:p,height:n.range()[0]},hidden:!1}),o.rangeLineArea.update({clip:{x:g,y:0,width:p,height:n.range()[0]},hidden:!1}),o.rangeTooltip.update({rightPoint:h,leftPoint:c,closest:t,x:g+p/2,y:0,hidden:!1}),(v=o.belowZeroLine)==null||v.update({hidden:!0}),o.mainLineArea.update({hidden:!0}),Qi(o,u),o.mainLine.className("add","_selected-muted")},Ot=i=>{var t;const{elements:e}=i;e.rangeLine.update({hidden:!0}),e.rangeLineArea.update({hidden:!0}),e.rangeBorderLeft.update({hidden:!0}),e.rangeBorderRight.update({hidden:!0}),e.rangeCircleLeft.update({hidden:!0}),e.rangeCircleRight.update({hidden:!0}),e.rangeTooltip.update({hidden:!0}),e.mainLine.className("remove","_selected-muted"),e.mainLineArea.update({hidden:!1}),(t=e.belowZeroLine)==null||t.update({hidden:!1})},es=i=>{const{svg:e,data:t,x:s,config:n,width:a,height:r}=i,{margin:o,hover:c,selection:h}=n;let u=null,g=!1;const _=v=>t.reduce((b,x)=>Math.abs(s(b.date)-v)<Math.abs(s(x.date)-v)?b:x);e.append("rect").attr("width",a-o.left-o.right).attr("height",r-o.top-o.bottom).attr("x",o.left).attr("y",o.top).attr("fill","transparent").on("mousemove",function(v){const[b]=k.pointer(v,this),x=_(b);!g&&c.enable?(i.action="hover",Rt(i,x)):(i.action=g?"selection":"none",$t(i)),u&&h.enable&&(i.action="selection",Ki(i,u,x))}).on("mouseleave",()=>{i.action="none",g=!1,u=null,$t(i),Ot(i)}).on("mousedown",function(v){if(h.enable){g=!0,i.action="selection";const[b]=k.pointer(v,this);u=_(b)}}).on("mouseup",function(v){const[b]=k.pointer(v,this),x=_(b);g=!1,u=null,i.action="hover",h.enable&&Ot(i),c.enable&&Rt(i,x)})},ts=(i,e,t)=>{const{margin:s}=e,n=k.scaleTime(),a=k.extent(i,r=>new Date(r.date));return a[0]==null||a[1]==null?n:n.domain([a[0],a[1]]).range([s.left,t-s.right])},is=(i,e,t)=>{const{margin:s}=e,n=k.max(i,r=>r.value)??0,a=k.min(i,r=>r.value)??0;return k.scaleLinear().domain([a,n]).range([t-s.bottom,s.top])},ss=(i,e)=>{const t=k.select(i);if(t.empty())return console.error(`Element with selector ${i} not found!`),null;if(!e.chartId||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(e.chartId))return console.error(`chartId is required and must be a valid id
2
+ (only letters, numbers or underscores. The first character must be a letter)`),null;const s=t.append("div"),n=s.append("svg"),a=t.node();let r=a.getBoundingClientRect(),o=r.width,c=r.height,h=Ht({...Yi},e.config),u=e.data;const g=()=>{r=a.getBoundingClientRect(),o=r.width,c=r.height,_({data:u,config:h})};window.addEventListener("resize",g);const _=(p,v=!1)=>{v&&p.config&&(h=Ht(h,p.config)),v&&p.data&&(u=p.data);const b=u.map(M=>({date:new Date(M.date),value:M.value})).sort((M,L)=>M.date.getTime()-L.date.getTime()),x=ts(b,h,o),C=is(b,h,c);s.attr("class",`sc-charts sc-charts__${h.theme}`),n.attr("preserveAspectRatio","xMinYMin meet").attr("viewBox",`0 0 ${o} ${c}`).style("width","100%").style("height","100%").selectAll("*").remove();const y={chartId:e.chartId,svg:n,wrapperNode:s.node(),data:b,x,y:C,config:h,action:"none",width:o,height:c};Hi(y);const w={...y,elements:qi(y)};es(w)};return _(e),{update:p=>_(p,!0),destroy:()=>{window.removeEventListener("resize",g),n.remove()}}};var $e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ns(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Ce={exports:{}};Ce.exports;var Pt;function as(){return Pt||(Pt=1,function(i,e){var t=200,s="__lodash_hash_undefined__",n=800,a=16,r=9007199254740991,o="[object Arguments]",c="[object Array]",h="[object AsyncFunction]",u="[object Boolean]",g="[object Date]",_="[object Error]",p="[object Function]",v="[object GeneratorFunction]",b="[object Map]",x="[object Number]",C="[object Null]",y="[object Object]",w="[object Proxy]",M="[object RegExp]",L="[object Set]",R="[object String]",$="[object Undefined]",O="[object WeakMap]",se="[object ArrayBuffer]",U="[object DataView]",P="[object Float32Array]",G="[object Float64Array]",J="[object Int8Array]",We="[object Int16Array]",vt="[object Int32Array]",ce="[object Uint8Array]",ke="[object Uint8ClampedArray]",De="[object Uint16Array]",Xe="[object Uint32Array]",Ue=/[\\^$.*+?()[\]{}|]/g,Ge=/^\[object .+?Constructor\]$/,bt=/^(?:0|[1-9]\d*)$/,N={};N[P]=N[G]=N[J]=N[We]=N[vt]=N[ce]=N[ke]=N[De]=N[Xe]=!0,N[o]=N[c]=N[se]=N[u]=N[U]=N[g]=N[_]=N[p]=N[b]=N[x]=N[y]=N[M]=N[L]=N[R]=N[O]=!1;var z=typeof $e=="object"&&$e&&$e.Object===Object&&$e,_e=typeof self=="object"&&self&&self.Object===Object&&self,Q=z||_e||Function("return this")(),K=e&&!e.nodeType&&e,re=K&&!0&&i&&!i.nodeType&&i,Ee=re&&re.exports===K,ve=Ee&&z.process,Le=function(){try{var l=re&&re.require&&re.require("util").types;return l||ve&&ve.binding&&ve.binding("util")}catch{}}(),Ne=Le&&Le.isTypedArray;function he(l,d,m){switch(m.length){case 0:return l.call(d);case 1:return l.call(d,m[0]);case 2:return l.call(d,m[0],m[1]);case 3:return l.call(d,m[0],m[1],m[2])}return l.apply(d,m)}function de(l,d){for(var m=-1,S=Array(l);++m<l;)S[m]=d(m);return S}function yt(l){return function(d){return l(d)}}function Fe(l,d){return l==null?void 0:l[d]}function ca(l,d){return function(m){return l(d(m))}}var ha=Array.prototype,da=Function.prototype,Ze=Object.prototype,wt=Q["__core-js_shared__"],qe=da.toString,oe=Ze.hasOwnProperty,oi=function(){var l=/[^.]+$/.exec(wt&&wt.keys&&wt.keys.IE_PROTO||"");return l?"Symbol(src)_1."+l:""}(),li=Ze.toString,ua=qe.call(Object),fa=RegExp("^"+qe.call(oe).replace(Ue,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Je=Ee?Q.Buffer:void 0,ci=Q.Symbol,hi=Q.Uint8Array;Je&&Je.allocUnsafe;var di=ca(Object.getPrototypeOf,Object),ui=Object.create,ga=Ze.propertyIsEnumerable,ma=ha.splice,ue=ci?ci.toStringTag:void 0,Qe=function(){try{var l=St(Object,"defineProperty");return l({},"",{}),l}catch{}}(),pa=Je?Je.isBuffer:void 0,fi=Math.max,_a=Date.now,gi=St(Q,"Map"),He=St(Object,"create"),va=function(){function l(){}return function(d){if(!ge(d))return{};if(ui)return ui(d);l.prototype=d;var m=new l;return l.prototype=void 0,m}}();function fe(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var S=l[d];this.set(S[0],S[1])}}function ba(){this.__data__=He?He(null):{},this.size=0}function ya(l){var d=this.has(l)&&delete this.__data__[l];return this.size-=d?1:0,d}function wa(l){var d=this.__data__;if(He){var m=d[l];return m===s?void 0:m}return oe.call(d,l)?d[l]:void 0}function xa(l){var d=this.__data__;return He?d[l]!==void 0:oe.call(d,l)}function Ca(l,d){var m=this.__data__;return this.size+=this.has(l)?0:1,m[l]=He&&d===void 0?s:d,this}fe.prototype.clear=ba,fe.prototype.delete=ya,fe.prototype.get=wa,fe.prototype.has=xa,fe.prototype.set=Ca;function ne(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var S=l[d];this.set(S[0],S[1])}}function Sa(){this.__data__=[],this.size=0}function Aa(l){var d=this.__data__,m=Ke(d,l);if(m<0)return!1;var S=d.length-1;return m==S?d.pop():ma.call(d,m,1),--this.size,!0}function Ma(l){var d=this.__data__,m=Ke(d,l);return m<0?void 0:d[m][1]}function Ta(l){return Ke(this.__data__,l)>-1}function ka(l,d){var m=this.__data__,S=Ke(m,l);return S<0?(++this.size,m.push([l,d])):m[S][1]=d,this}ne.prototype.clear=Sa,ne.prototype.delete=Aa,ne.prototype.get=Ma,ne.prototype.has=Ta,ne.prototype.set=ka;function be(l){var d=-1,m=l==null?0:l.length;for(this.clear();++d<m;){var S=l[d];this.set(S[0],S[1])}}function Da(){this.size=0,this.__data__={hash:new fe,map:new(gi||ne),string:new fe}}function Ea(l){var d=tt(this,l).delete(l);return this.size-=d?1:0,d}function La(l){return tt(this,l).get(l)}function Na(l){return tt(this,l).has(l)}function Fa(l,d){var m=tt(this,l),S=m.size;return m.set(l,d),this.size+=m.size==S?0:1,this}be.prototype.clear=Da,be.prototype.delete=Ea,be.prototype.get=La,be.prototype.has=Na,be.prototype.set=Fa;function ye(l){var d=this.__data__=new ne(l);this.size=d.size}function Ha(){this.__data__=new ne,this.size=0}function Ba(l){var d=this.__data__,m=d.delete(l);return this.size=d.size,m}function Ia(l){return this.__data__.get(l)}function Ra(l){return this.__data__.has(l)}function $a(l,d){var m=this.__data__;if(m instanceof ne){var S=m.__data__;if(!gi||S.length<t-1)return S.push([l,d]),this.size=++m.size,this;m=this.__data__=new be(S)}return m.set(l,d),this.size=m.size,this}ye.prototype.clear=Ha,ye.prototype.delete=Ba,ye.prototype.get=Ia,ye.prototype.has=Ra,ye.prototype.set=$a;function Oa(l,d){var m=Tt(l),S=!m&&Mt(l),T=!m&&!S&&bi(l),F=!m&&!S&&!T&&wi(l),B=m||S||T||F,E=B?de(l.length,String):[],I=E.length;for(var ee in l)B&&(ee=="length"||T&&(ee=="offset"||ee=="parent")||F&&(ee=="buffer"||ee=="byteLength"||ee=="byteOffset")||_i(ee,I))||E.push(ee);return E}function xt(l,d,m){(m!==void 0&&!it(l[d],m)||m===void 0&&!(d in l))&&Ct(l,d,m)}function Pa(l,d,m){var S=l[d];(!(oe.call(l,d)&&it(S,m))||m===void 0&&!(d in l))&&Ct(l,d,m)}function Ke(l,d){for(var m=l.length;m--;)if(it(l[m][0],d))return m;return-1}function Ct(l,d,m){d=="__proto__"&&Qe?Qe(l,d,{configurable:!0,enumerable:!0,value:m,writable:!0}):l[d]=m}var za=er();function et(l){return l==null?l===void 0?$:C:ue&&ue in Object(l)?tr(l):or(l)}function mi(l){return Be(l)&&et(l)==o}function Va(l){if(!ge(l)||ar(l))return!1;var d=Dt(l)?fa:Ge;return d.test(dr(l))}function ja(l){return Be(l)&&yi(l.length)&&!!N[et(l)]}function Ya(l){if(!ge(l))return rr(l);var d=vi(l),m=[];for(var S in l)S=="constructor"&&(d||!oe.call(l,S))||m.push(S);return m}function pi(l,d,m,S,T){l!==d&&za(d,function(F,B){if(T||(T=new ye),ge(F))Wa(l,d,B,m,pi,S,T);else{var E=S?S(At(l,B),F,B+"",l,d,T):void 0;E===void 0&&(E=F),xt(l,B,E)}},xi)}function Wa(l,d,m,S,T,F,B){var E=At(l,m),I=At(d,m),ee=B.get(I);if(ee){xt(l,m,ee);return}var X=F?F(E,I,m+"",l,d,B):void 0,Ie=X===void 0;if(Ie){var Et=Tt(I),Lt=!Et&&bi(I),Si=!Et&&!Lt&&wi(I);X=I,Et||Lt||Si?Tt(E)?X=E:ur(E)?X=Ja(E):Lt?(Ie=!1,X=Ga(I)):Si?(Ie=!1,X=qa(I)):X=[]:fr(I)||Mt(I)?(X=E,Mt(E)?X=gr(E):(!ge(E)||Dt(E))&&(X=ir(I))):Ie=!1}Ie&&(B.set(I,X),T(X,I,S,F,B),B.delete(I)),xt(l,m,X)}function Xa(l,d){return cr(lr(l,d,Ci),l+"")}var Ua=Qe?function(l,d){return Qe(l,"toString",{configurable:!0,enumerable:!1,value:pr(d),writable:!0})}:Ci;function Ga(l,d){return l.slice()}function Za(l){var d=new l.constructor(l.byteLength);return new hi(d).set(new hi(l)),d}function qa(l,d){var m=Za(l.buffer);return new l.constructor(m,l.byteOffset,l.length)}function Ja(l,d){var m=-1,S=l.length;for(d||(d=Array(S));++m<S;)d[m]=l[m];return d}function Qa(l,d,m,S){var T=!m;m||(m={});for(var F=-1,B=d.length;++F<B;){var E=d[F],I=void 0;I===void 0&&(I=l[E]),T?Ct(m,E,I):Pa(m,E,I)}return m}function Ka(l){return Xa(function(d,m){var S=-1,T=m.length,F=T>1?m[T-1]:void 0,B=T>2?m[2]:void 0;for(F=l.length>3&&typeof F=="function"?(T--,F):void 0,B&&sr(m[0],m[1],B)&&(F=T<3?void 0:F,T=1),d=Object(d);++S<T;){var E=m[S];E&&l(d,E,S,F)}return d})}function er(l){return function(d,m,S){for(var T=-1,F=Object(d),B=S(d),E=B.length;E--;){var I=B[++T];if(m(F[I],I,F)===!1)break}return d}}function tt(l,d){var m=l.__data__;return nr(d)?m[typeof d=="string"?"string":"hash"]:m.map}function St(l,d){var m=Fe(l,d);return Va(m)?m:void 0}function tr(l){var d=oe.call(l,ue),m=l[ue];try{l[ue]=void 0;var S=!0}catch{}var T=li.call(l);return S&&(d?l[ue]=m:delete l[ue]),T}function ir(l){return typeof l.constructor=="function"&&!vi(l)?va(di(l)):{}}function _i(l,d){var m=typeof l;return d=d??r,!!d&&(m=="number"||m!="symbol"&&bt.test(l))&&l>-1&&l%1==0&&l<d}function sr(l,d,m){if(!ge(m))return!1;var S=typeof d;return(S=="number"?kt(m)&&_i(d,m.length):S=="string"&&d in m)?it(m[d],l):!1}function nr(l){var d=typeof l;return d=="string"||d=="number"||d=="symbol"||d=="boolean"?l!=="__proto__":l===null}function ar(l){return!!oi&&oi in l}function vi(l){var d=l&&l.constructor,m=typeof d=="function"&&d.prototype||Ze;return l===m}function rr(l){var d=[];if(l!=null)for(var m in Object(l))d.push(m);return d}function or(l){return li.call(l)}function lr(l,d,m){return d=fi(d===void 0?l.length-1:d,0),function(){for(var S=arguments,T=-1,F=fi(S.length-d,0),B=Array(F);++T<F;)B[T]=S[d+T];T=-1;for(var E=Array(d+1);++T<d;)E[T]=S[T];return E[d]=m(B),he(l,this,E)}}function At(l,d){if(!(d==="constructor"&&typeof l[d]=="function")&&d!="__proto__")return l[d]}var cr=hr(Ua);function hr(l){var d=0,m=0;return function(){var S=_a(),T=a-(S-m);if(m=S,T>0){if(++d>=n)return arguments[0]}else d=0;return l.apply(void 0,arguments)}}function dr(l){if(l!=null){try{return qe.call(l)}catch{}try{return l+""}catch{}}return""}function it(l,d){return l===d||l!==l&&d!==d}var Mt=mi(function(){return arguments}())?mi:function(l){return Be(l)&&oe.call(l,"callee")&&!ga.call(l,"callee")},Tt=Array.isArray;function kt(l){return l!=null&&yi(l.length)&&!Dt(l)}function ur(l){return Be(l)&&kt(l)}var bi=pa||_r;function Dt(l){if(!ge(l))return!1;var d=et(l);return d==p||d==v||d==h||d==w}function yi(l){return typeof l=="number"&&l>-1&&l%1==0&&l<=r}function ge(l){var d=typeof l;return l!=null&&(d=="object"||d=="function")}function Be(l){return l!=null&&typeof l=="object"}function fr(l){if(!Be(l)||et(l)!=y)return!1;var d=di(l);if(d===null)return!0;var m=oe.call(d,"constructor")&&d.constructor;return typeof m=="function"&&m instanceof m&&qe.call(m)==ua}var wi=Ne?yt(Ne):ja;function gr(l){return Qa(l,xi(l))}function xi(l){return kt(l)?Oa(l):Ya(l)}var mr=Ka(function(l,d,m){pi(l,d,m)});function pr(l){return function(){return l}}function Ci(l){return l}function _r(){return!1}i.exports=mr}(Ce,Ce.exports)),Ce.exports}var rs=as();const Oe=ns(rs),zt=12,os={candles:{direction:"right",offset:`${Math.round(zt/2)}px`,style:"filled",strokeWidth:1,baseWidth:zt,bodyRatio:.7,zoomOnWheel:"both",scaleSensitivity:.002,limiterOffset:{left:0,right:0},hideMissingData:!1},xAxis:{isShow:!0,position:"bottom",height:20,text:{font:"sans-serif",fontSize:"12px"}},yAxis:{isShow:!0,position:"right",width:50,text:{font:"sans-serif",fontSize:"10px"}},guides:{isShowX:!0,isShowY:!0,formatterX:null,formatterY:null},markers:[],trade:{showHoldTime:!1,holdTimeContent:null,holdTimeDates:null,holdTimePrice:null,showConnectionLine:!0,showLabelButtons:!0}};class ls{constructor(e){f(this,"_candles");f(this,"_xAxis");f(this,"_yAxis");f(this,"_guides");f(this,"_trade");const t=Oe({},os,e);this._candles=t.candles,this._xAxis=t.xAxis,this._yAxis=t.yAxis,this._guides=t.guides,this._trade=t.trade}update(e){const t=Oe({},{candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,trade:this._trade},e);this._candles=t.candles,this._xAxis=t.xAxis,this._yAxis=t.yAxis,this._guides=t.guides,this._trade=t.trade}get candles(){return this._candles}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get guides(){return this._guides}get trade(){return this._trade}}class Y{constructor(e){f(this,"x");f(this,"y");f(this,"width");f(this,"height");let t;if(!e)t={x:0,y:0,width:0,height:0};else if(e instanceof HTMLElement||e instanceof Element){const{x:s,y:n,width:a,height:r}=e.getBoundingClientRect();t={x:s,y:n,width:a,height:r}}else t=e;this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}static empty(){return{x:0,y:0,width:0,height:0,left:0,right:0,bottom:0,top:0}}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}}class cs{constructor(e,t){f(this,"_chart",new Y);f(this,"_area",new Y);f(this,"_xAxis",new Y);f(this,"_yAxis",new Y);f(this,"_axisIntersection",new Y);const{xAxis:s,yAxis:n}=t;this._chart=new Y(e),this._calc(s,n)}_calc(e,t){const s=e.isShow?e.height:0,n=t.isShow?t.width:0,a=this._chart.height-s,r=this._chart.width-n;this._area=new Y({x:t.position==="left"?n:0,y:e.position==="top"?s:0,width:r,height:a}),this._xAxis=new Y({y:e.position==="top"?0:a,x:t.position==="left"?n:0,height:s,width:r}),this._yAxis=new Y({y:e.position==="top"?s:0,x:t.position==="left"?0:r,width:n,height:a}),this._axisIntersection=new Y({y:e.position==="top"?0:a,x:t.position==="left"?0:r,width:n,height:s})}updateConfig(e){const{xAxis:t,yAxis:s}=e;this._calc(t,s)}update(e){const{xAxis:t,yAxis:s}=e.config;this._chart=new Y(e.container),this._calc(t,s)}get area(){return this._area}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get axisIntersection(){return this._axisIntersection}get chart(){return this._chart}}const hs=i=>i?new Date(i.close_time).getTime()-new Date(i.open_time).getTime():0;function ds(i,e){if(i.length<2)return[];const t=[];for(let s=0;s<i.length-1;s++){const n=i[s].close_time.getTime(),a=i[s].open_time.getTime(),o=new Date(i[s+1].open_time).getTime()-n;if(o>=e){const c=Math.floor(o/e),h=[];for(let u=1;u<=c;u++)h.push(a+u*e);h.length>0&&t.push(h)}}return t}function Vt(i,e){const t=hs(i[0]),s=ds(i,t),n=[];return s.forEach(a=>{if(a.length===0)return;const r=i.find(g=>g.close_time.getTime()===a[0]),o=i.find(g=>g.open_time.getTime()===a[a.length-1]+t);if(!r||!o)throw new Error("[CS_Data] error while creating missing data");const c=r.close,h=o.open;let u=c;a.forEach((g,_)=>{const p=(h-u)/a.length;let v=u+p*_,b=v+p;const x=Math.abs(v-b);let C=Math.max(v,b)+x/2,y=Math.min(v,b)-x/2;if(e.trade){const M=[...e.trade.entries,...e.trade.exits].find(L=>{const R=L.time.getTime();return R>=g&&R<g+t});M&&(M.type==="buy"?(y=M.price,b=Math.max(y,b),v=b+x,C=Math.max(v,b)+x/2,u=v):M.type==="sell"&&(C=M.price,b=Math.min(C,b),v=b-x,y=Math.min(v,b)-x/2,u=v))}const w={open_time:new Date(g),close_time:new Date(g+t),open:v,close:b,high:C,low:y};n.push(w)})}),n}class rt{constructor(e,t){f(this,"_initialData",[]);f(this,"_preparedData",[]);f(this,"_missingData",[]);f(this,"_count",0);f(this,"_model");f(this,"_interval",0);this._model=t,this.update(e)}_prepare(e){return e.map(t=>({...t,open_time:new Date(t.open_time),close_time:new Date(t.close_time)})).sort((t,s)=>t.open_time.getTime()-s.open_time.getTime())}update(e){this._initialData=e,this._preparedData=this._prepare(e),this._missingData=Vt(this._preparedData,this._model),this._count=this._preparedData.length+this._missingData.length,this._interval=new Date(e[0].close_time).getTime()-new Date(e[0].open_time).getTime()}updateMissingCandles(){this._missingData=Vt(this._preparedData,this._model)}get initialData(){return this._initialData}get preparedData(){return this._preparedData}get missingData(){return this._missingData}get allData(){return[...this._preparedData,...this._missingData]}get count(){return this._count}get interval(){return this._interval}static findByDate(e,t){return t.find(s=>s.open_time<=e&&s.close_time>e)}}class us{constructor(){f(this,"listeners",{})}subscribe(e,t){return this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t),()=>this.unsubscribe(e,t)}unsubscribe(e,t){var s;this.listeners[e]=((s=this.listeners[e])==null?void 0:s.filter(n=>n!==t))||[]}emit(e,...t){var n;const s=t[0];(n=this.listeners[e])==null||n.forEach(a=>{a(s)})}}class jt{constructor(){f(this,"_scale")}domain(){const e=this._scale.domain();if(e.length!==2)throw new Error("Domain length is not 2");return e}setDomain(e){this._scale.domain(e)}range(){const e=this._scale.range();if(e.length!==2)throw new Error("Range length is not 2");return e}setRange(e){this._scale.range(e)}invert(e){return this._scale.invert(e)}ticks(e){return this._scale.ticks(e)}tickFormat(e,t){return this._scale.tickFormat(e,t)}raw(){return this._scale}convert(e){return this._scale(e)}}class Yt extends jt{constructor(){super(),this._scale=k.scaleTime()}}class fs extends jt{constructor(){super(),this._scale=k.scaleLinear()}}const Wt={x:.2,y:.2},Xt=.001,gs={s:1e3,M:1e3*60,h:1e3*60*60,d:1e3*60*60*24,w:1e3*60*60*24*7},ms=i=>{const e=i.match(/^(\d+)([a-zA-Z]+)$/);if(!e)throw new Error(`Invalid offset format: "${i}"`);return[parseInt(e[1]),e[2]]},ps=(i,e)=>{const[t,s]=e.domain().map(o=>o.getTime()),n=i.filter(o=>{const c=o.open_time.getTime();return c>=t&&c<=s}),a=k.min(n,o=>o.low),r=k.max(n,o=>o.high);if(a==null||r==null)throw new Error("Invalid Y data");return[a,r]};class _s{constructor(e){this.model=e}initX(e){const t=this.model.candles.preparedData,s=k.extent(t,n=>new Date(n.open_time));if(!s[0]||!s[1])throw new Error("Invalid x data");e.setDomain(s),this.setRange(e,this.model.layout.xAxis),this.setDefaultXDomain(e),this.applyOffset(e)}initY(e,t){const s=ps(this.model.candles.preparedData,t);e.setDomain(s),this.setRange(e,this.model.layout.yAxis)}init(e){this.initX(e.x),this.initY(e.y,e.x)}setRange(e,{x:t,y:s,width:n,height:a}){e instanceof Yt?e.setRange([t,t+n]):e.setRange([s+a,s])}setDefaultXDomain(e){const{candles:{count:t},layout:{area:s},config:{candles:{baseWidth:n,bodyRatio:a,direction:r}}}=this.model,[o,c]=e.domain().map(p=>p.getTime()),h=c-o,u=n/a*t,g=h*(s.width/u),_=r==="left"?[new Date(o),new Date(o+g)]:[new Date(c-g),new Date(c)];e.setDomain(_)}applyOffset(e){const{config:{candles:{offset:t,direction:s}},layout:{xAxis:n}}=this.model,[a,r]=ms(t),o=r==="px"?e.invert(n.x+a).getTime()-e.invert(n.x).getTime():gs[r]*a,c=s==="left"?-o:o,[h,u]=e.domain();e.setDomain([new Date(h.getTime()+c),new Date(u.getTime()+c)])}}class vs{constructor(e){f(this,"_model");f(this,"_scaleX");f(this,"_scaleY");f(this,"_initializer");f(this,"_baseDomain",{x:[new Date,new Date],y:[0,0]});f(this,"scaleFactor",{x:1,y:1});f(this,"panOffset",{x:0,y:0});this._model=e,this._scaleX=new Yt,this._scaleY=new fs,this._initializer=new _s(e),this._initializer.init({x:this._scaleX,y:this._scaleY}),this._baseDomain={x:this._scaleX.domain(),y:this._scaleY.domain()}}reinit(){this._initializer.init({x:this._scaleX,y:this._scaleY}),this.scaleFactor={x:1,y:1},this.panOffset={x:0,y:0},this._baseDomain={x:this._scaleX.domain(),y:this._scaleY.domain()}}get x(){return this._scaleX}get y(){return this._scaleY}get factorX(){return this.scaleFactor.x}get factorY(){return this.scaleFactor.y}get panOffsetX(){return this.panOffset.x}get panOffsetY(){return this.panOffset.y}fitYToVisibleCandles(){const e=this._model.candles.allData,[t,s]=this._scaleX.domain(),n=e.filter(g=>g.open_time>=t&&g.open_time<=s);if(!n.length)return;const a=Math.min(...n.map(g=>g.low)),r=Math.max(...n.map(g=>g.high)),o=r-a;if(o===0)return;const c=this._baseDomain.y;this.scale("y",(c[1]-c[0])/o,"absolute");const h=this._scaleY.convert((a+r)/2),u=this._scaleY.convert((c[0]+c[1])/2);this.pan("y",u-h,"absolute")}scale(e,t,s="delta"){if(s==="absolute"){const n=Math.max(Wt[e],t);if(Math.abs(n-this.scaleFactor[e])<Xt)return;this.scaleFactor[e]=n}else{const n=this.scaleFactor[e],a=n+t*this._model.config.candles.scaleSensitivity;if(a<Wt[e]||Math.abs(a-n)<Xt)return;this.scaleFactor[e]=a}this._updateDomain(e)}pan(e,t,s="delta"){s==="absolute"?this.panOffset[e]=t:this.panOffset[e]+=t,this._updateDomain(e)}_updateDomain(e){const t=this._baseDomain[e],s=this.scaleFactor[e],n=this.panOffset[e];if(e==="x"){const[a,r]=t,o=r.getTime()-a.getTime(),c=o/s,h=a.getTime()+o/2,u=this._scaleX.invert(0-n).getTime()-this._scaleX.invert(0).getTime();this._scaleX.setDomain([new Date(h-c/2+u),new Date(h+c/2+u)])}else{const[a,r]=t,o=r-a,c=o/s,h=a+o/2,u=this._scaleY.invert(0-n)-this._scaleY.invert(0);this._scaleY.setDomain([h-c/2+u,h+c/2+u])}this._model.eventBus.emit("scale_event")}}class bs{constructor(e,{entry:t=[],exit:s=[]}){f(this,"_model");f(this,"_rawEntry");f(this,"_rawExit");f(this,"_mapped",[]);f(this,"_entries",[]);f(this,"_exits",[]);f(this,"_activeTradeTime",null);f(this,"_hoveredTradeTime",null);this._model=e,this._rawEntry=t,this._rawExit=s,this.recalculate()}_findTradeCandle(e){return t=>e>=t.open_time&&e<t.close_time}recalculate(){const e=this._rawEntry.map(n=>({...n,kind:"entry",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),t=this._rawExit.map(n=>({...n,kind:"exit",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),s=[...e,...t];this._mapped=this._model.candles.allData.map(n=>{const a=s.filter(r=>r.time>=n.open_time&&r.time<n.close_time);return{candle:n,trades:a}}).filter(n=>n.trades.length>0),this._entries=e.sort((n,a)=>n.time.getTime()-a.time.getTime()),this._exits=t.sort((n,a)=>n.time.getTime()-a.time.getTime())}updateTrade({entry:e,exit:t}){this._rawEntry=e,this._rawExit=t,this.recalculate()}setActiveTrade(e,t){this._activeTradeTime=t||null,this._mapped=this._mapped.map(s=>({...s,isActive:e===null?void 0:[e,s.candle.open_time.getTime()===t]}))}setHoveredTrade(e,t){this._hoveredTradeTime=t||null,this._mapped=this._mapped.map(s=>({...s,isHovered:e===null?void 0:[e,s.candle.open_time.getTime()===t]}))}get hasActiveTrade(){return this._activeTradeTime!==null}get hasHoveredTrade(){return this._hoveredTradeTime!==null}get tradedCandles(){return this._mapped}get entries(){return this._entries}get exits(){return this._exits}get entryMinTime(){var e;return((e=this._entries.at(0))==null?void 0:e.time.getTime())??0}get exitMaxTime(){var e;return((e=this._exits.at(-1))==null?void 0:e.time.getTime())??0}get timeRange(){const{allData:e,interval:t}=this._model.candles,s=e.map(r=>r.open_time.getTime());let n=0,a=s.length-1;for(let r=0;r<s.length;r++){const o=s[r],c=o<=this.entryMinTime&&o+t>=this.entryMinTime,h=o<=this.exitMaxTime&&o+t>=this.exitMaxTime;if(n===0&&c&&(n=r),a===s.length-1&&h&&(a=r),n!==0&&a!==s.length-1)break}return s.slice(n,a+1)}get hasTrade(){return this._rawEntry.length>0&&this._rawExit.length>0}get holdTime(){return Math.abs(this.entryMinTime-this.exitMaxTime)}}class ys{constructor(e,t){f(this,"_rawMarkers");f(this,"_markers",[]);f(this,"_model");f(this,"_defaults",{mainColor:"#000000",textColor:"#ffffff",lineColor:"#000000",formatter:{horizontal:e=>e.toString(),vertical:e=>e.toLocaleString()}});this._rawMarkers=t,this._model=e,this.rebuild()}rebuild(){const{layout:{area:e},scales:{y:t},colorScheme:{userMarkers:{default:s}}}=this._model;this._markers=this._rawMarkers.map(n=>{var h;const a={mainColor:n.mainColor??s.main,textColor:n.textColor??s.text,lineColor:n.lineColor??s.line},r=t.convert(n.value),c=(n.formatter??((h=this._defaults.formatter)==null?void 0:h.horizontal)??(u=>u.toString()))(n.value);return{value:n.value,text:c,x:e.x,y:r,startDate:n.startDate?n.startDate instanceof Date?n.startDate:new Date(n.startDate):null,...a}})}updateMarkers(e){this._rawMarkers=e,this.rebuild()}get data(){return this._markers}}const ws={bg:"#FFFFFF",axisIntersection:"#FFFFFF",xAxis:{bg:"#FFFFFF",text:"#7F7F83"},yAxis:{bg:"#FFFFFF",text:"#7F7F83"},candles:{risingFill:"#56B683",risingStroke:"#000000",fallingFill:"#F18169",fallingStroke:"#000000",noDataFill:["#d9d9da","#ededed"],noDataStroke:"#000000"},guides:{horizontalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"},verticalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"}},trade:{buyLabel:{main:"#56B683",text:"#ffffff"},sellLabel:{main:"#F18169",text:"#ffffff"},connectionLine:"#D9D9DA",tradeBorders:"#EDEDED",activeLabel:"#007AFF",hold:{main:"#A1BBFF",text:"#ffffff"}},userMarkers:{default:{main:"#EDEDED",text:"#000000",line:"#EDEDED"}},comments:{scaleAnchor:{bgActive:"#007AFF",bgInactive:"#A1BBFF",iconActive:"#FFFFFF",iconInactive:"#004DA1"}}};class xs{constructor(e){f(this,"_scheme");this._scheme=Oe({},ws,e),Object.keys(this._scheme).forEach(t=>{Object.defineProperty(this,t,{get:()=>this._scheme[t],enumerable:!0})})}update(e){this._scheme=Oe({},this._scheme,e)}}class Cs{constructor(e,t){f(this,"_data");f(this,"_callbacks",{onAdd:()=>{},onUpdate:()=>{},onDelete:()=>{}});f(this,"_model");f(this,"_grouped",{});this._data=(e==null?void 0:e.data)||[],this._model=t,this._updateGroups(),e!=null&&e.onAdd&&(this._callbacks.onAdd=e.onAdd),e!=null&&e.onUpdate&&(this._callbacks.onUpdate=e.onUpdate),e!=null&&e.onDelete&&(this._callbacks.onDelete=e.onDelete)}_updateGroups(){this._grouped={};for(const e of this._data){const t=rt.findByDate(new Date(e.date),this._model.candles.allData);if(!t)continue;const s=t.open_time.getTime();this._grouped[s]||(this._grouped[s]=[]),this._grouped[s].push({...e,candle:t})}}get data(){return this._data}set data(e){this._data=e,this._updateGroups()}get grouped(){return this._grouped}add(e){this._data.push(e),this._updateGroups(),this._callbacks.onAdd(e)}remove(e){this._data=this._data.filter(t=>t.id!==e),this._updateGroups(),this._callbacks.onDelete(e)}update(e,t){this._updateGroups(),this._callbacks.onUpdate(e,t)}}class Ss{constructor({chartId:e,container:t,candles:s,config:n,trade:a={entry:[],exit:[]},userMarkers:r=[],colorScheme:o,comments:c}){f(this,"chartId");f(this,"container");f(this,"eventBus",new us);f(this,"candles");f(this,"config");f(this,"colorScheme");f(this,"layout");f(this,"scales");f(this,"trade");f(this,"userMarkers");f(this,"comments");this.chartId=e,this.container=t,this.candles=new rt(s,this),this.config=new ls(n),this.colorScheme=new xs(o),this.layout=new cs(t,this.config),this.scales=new vs(this),this.trade=new bs(this,a),this.candles.updateMissingCandles(),this.trade.recalculate(),this.userMarkers=new ys(this,r),this.comments=new Cs(c,this)}init(){this.eventBus.emit("init_model")}subscribe(e,t){return this.eventBus.subscribe(e,t)}unsubscribe(e,t){this.eventBus.unsubscribe(e,t)}updateConfig(e){this.eventBus.emit("update_config",e)}updateCandles(e){this.eventBus.emit("update_candles",e)}updateTrade(e){this.eventBus.emit("update_trade",e)}updateUserMarkers(e){this.eventBus.emit("update_user_markers",e)}updateColorScheme(e){this.eventBus.emit("update_color_scheme",e)}updateComments(e){this.eventBus.emit("update_comments",e)}}const Pe=window.devicePixelRatio||2;class D{constructor({tag:e,className:t,id:s,textContent:n}){f(this,"_tag");f(this,"_className");f(this,"_id");f(this,"_textContent");f(this,"_node");f(this,"_absolutePosition",new DOMRect);this._tag=e||"div",this._className=t||"",this._id=s||"",this._textContent=n||"";const a=document.createElement(this._tag);this._className&&(a.className=this._className),this._id&&(a.id=this._id),this._textContent&&(a.textContent=this._textContent),this._node=a}get node(){return this._node}position(e,t){const s=typeof e=="number"?e:e.x,n=typeof e=="number"?t:e.y;this.node.style.top=n+"px",this.node.style.left=s+"px"}append(...e){this._node.append(...e)}prepend(...e){this._node.prepend(...e)}remove(){this._node.remove(),this._tag="",this._className="",this._id="",this._textContent=""}get absolutePosition(){return this._absolutePosition}updateAbsolutePosition(){this._absolutePosition=this._node.getBoundingClientRect()}setVisible(e){this.node.style.opacity=e?"1":"0",this.node.style.visibility=e?"visible":"hidden"}}class Se extends D{constructor({className:t,id:s,width:n,height:a,isMain:r}){super({tag:"canvas",className:`${t} sc-charts-cs__canvas ${r?"":"sc-charts-cs__canvas-additional"}`,id:s});f(this,"_ctx");f(this,"_width");f(this,"_height");f(this,"background",null);this._width=n,this._height=a,this.updateSize({width:n,height:a});const o=this._node.getContext("2d");if(!o)throw new Error("Failed to get 2D context");o.scale(Pe,Pe),this._ctx=o}updateSize({width:t,height:s}){t&&(this._node.width=t*Pe,this._node.style.width=`${t}px`,this._width=t),s&&(this._node.height=s*Pe,this._node.style.height=`${s}px`,this._height=s)}clear(){this.background?(this._ctx.save(),this._ctx.fillStyle=this.background,this._ctx.fillRect(0,0,this._width,this._height),this._ctx.restore()):this._ctx.clearRect(0,0,this._width,this._height)}get ctx(){return this._ctx}get width(){return this._width}get height(){return this._height}}const As=10;function Ms(i,e){const{layout:{xAxis:t},colorScheme:{xAxis:s},config:{xAxis:n},scales:a}=e,r=a.x.ticks(As),o=u=>u.getHours()===0&&u.getMinutes()===0,c=k.timeFormat("%d %b"),h=k.timeFormat("%H:%M");i.save(),i.fillStyle=s.bg,i.fillRect(t.x,t.y,t.width,t.height),i.restore(),i.fillStyle=s.text,i.font=`${n.text.fontSize} ${n.text.font}`,i.textAlign="center",i.textBaseline="middle",r.forEach(u=>{const g=a.x.convert(u),_=o(u)?c(u):h(u);i.fillText(_,g,t.y+t.height/2)})}function Ts(i,e){const{layout:{yAxis:t},colorScheme:{yAxis:s},config:{yAxis:n},scales:a}=e,r=a.y.ticks(6),o=a.y.tickFormat(6);i.save(),i.fillStyle=s.bg,i.fillRect(t.x,t.y,t.width,t.height),i.restore(),i.fillStyle=s.text,i.font=`${n.text.fontSize} ${n.text.font}`,i.textAlign="center",i.textBaseline="middle",r.forEach(c=>{const h=a.y.convert(c),u=o(c);i.fillText(u,t.x+t.width/2,h)})}const ks=(i,e)=>{const{layout:{axisIntersection:t},colorScheme:s}=e;i.save(),i.fillStyle=s.axisIntersection,i.fillRect(t.x,t.y,t.width,t.height),i.restore()};class ot{static xAxis(e,t){Ms(e,t)}static yAxis(e,t){Ts(e,t)}static intersection(e,t){ks(e,t)}}class Ds{constructor(e){f(this,"_target");this._target=e}mousemove(e){this._target.addEventListener("mousemove",e)}mouseleave(e){this._target.addEventListener("mouseleave",e)}mousedown(e){this._target.addEventListener("mousedown",e)}mouseup(e){this._target.addEventListener("mouseup",e)}wheel(e){this._target.addEventListener("wheel",e)}dblclick(e){this._target.addEventListener("dblclick",e)}contextmenu(e){this._target.addEventListener("contextmenu",e)}}function ze(i){return i*.1875}const Es=(i,{mainColor:e,textColor:t,symbol:s,x:n,y:a,size:r,fontSize:o})=>{const g=r/16,_=16*g,p=n-_/2,v=a;i.save(),i.translate(p,v),i.scale(g,g),i.beginPath(),i.moveTo(7.85696,.288512),i.lineTo(4.53377,3.11938),i.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),i.lineTo(11.2275,4),i.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),i.lineTo(8.52156,.302869),i.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),i.closePath(),i.fillStyle=e,i.fill(),i.beginPath(),i.moveTo(0,7),i.bezierCurveTo(0,4.79086,1.79086,3,4,3),i.lineTo(12,3),i.bezierCurveTo(14.2091,3,16,4.79086,16,7),i.lineTo(16,15),i.bezierCurveTo(16,17.2091,14.2091,19,12,19),i.lineTo(4,19),i.bezierCurveTo(1.79086,19,0,17.2091,0,15),i.lineTo(0,7),i.closePath(),i.fillStyle=e,i.fill(),i.restore(),i.save(),i.font=`bold ${o}px sans-serif`,i.textAlign="center",i.textBaseline="top",i.textAlign="center",i.textBaseline="middle";const b=a+g*3+.5,x=g*16,C=b+x/2;i.fillStyle=t,i.fillText(s,n,C),i.restore()},Ls=(i,{mainColor:e,textColor:t,symbol:s,x:n,y:a,size:r,fontSize:o})=>{const g=r/16,_=16*g,p=n-_/2,v=a;i.save(),i.translate(p,v),i.scale(g,-g),i.beginPath(),i.moveTo(7.85696,.288512),i.lineTo(4.53377,3.11938),i.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),i.lineTo(11.2275,4),i.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),i.lineTo(8.52156,.302869),i.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),i.closePath(),i.fillStyle=e,i.fill(),i.beginPath(),i.moveTo(0,7),i.bezierCurveTo(0,4.79086,1.79086,3,4,3),i.lineTo(12,3),i.bezierCurveTo(14.2091,3,16,4.79086,16,7),i.lineTo(16,15),i.bezierCurveTo(16,17.2091,14.2091,19,12,19),i.lineTo(4,19),i.bezierCurveTo(1.79086,19,0,17.2091,0,15),i.lineTo(0,7),i.closePath(),i.fillStyle=e,i.fill(),i.restore(),i.save(),i.font=`bold ${o}px sans-serif`,i.textAlign="center",i.textBaseline="middle";const b=g*16,x=a-g*19+b/2;i.fillStyle=t,i.fillText(s,n,x),i.restore()};function Ve(i){"@babel/helpers - typeof";return Ve=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ve(i)}var Ns=/^\s+/,Fs=/\s+$/;function A(i,e){if(i=i||"",e=e||{},i instanceof A)return i;if(!(this instanceof A))return new A(i,e);var t=Hs(i);this._originalInput=i,this._r=t.r,this._g=t.g,this._b=t.b,this._a=t.a,this._roundA=Math.round(100*this._a)/100,this._format=e.format||t.format,this._gradientType=e.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=t.ok}A.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var e=this.toRgb();return(e.r*299+e.g*587+e.b*114)/1e3},getLuminance:function(){var e=this.toRgb(),t,s,n,a,r,o;return t=e.r/255,s=e.g/255,n=e.b/255,t<=.03928?a=t/12.92:a=Math.pow((t+.055)/1.055,2.4),s<=.03928?r=s/12.92:r=Math.pow((s+.055)/1.055,2.4),n<=.03928?o=n/12.92:o=Math.pow((n+.055)/1.055,2.4),.2126*a+.7152*r+.0722*o},setAlpha:function(e){return this._a=Qt(e),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var e=Gt(this._r,this._g,this._b);return{h:e.h*360,s:e.s,v:e.v,a:this._a}},toHsvString:function(){var e=Gt(this._r,this._g,this._b),t=Math.round(e.h*360),s=Math.round(e.s*100),n=Math.round(e.v*100);return this._a==1?"hsv("+t+", "+s+"%, "+n+"%)":"hsva("+t+", "+s+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var e=Ut(this._r,this._g,this._b);return{h:e.h*360,s:e.s,l:e.l,a:this._a}},toHslString:function(){var e=Ut(this._r,this._g,this._b),t=Math.round(e.h*360),s=Math.round(e.s*100),n=Math.round(e.l*100);return this._a==1?"hsl("+t+", "+s+"%, "+n+"%)":"hsla("+t+", "+s+"%, "+n+"%, "+this._roundA+")"},toHex:function(e){return Zt(this._r,this._g,this._b,e)},toHexString:function(e){return"#"+this.toHex(e)},toHex8:function(e){return $s(this._r,this._g,this._b,this._a,e)},toHex8String:function(e){return"#"+this.toHex8(e)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return this._a==1?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(H(this._r,255)*100)+"%",g:Math.round(H(this._g,255)*100)+"%",b:Math.round(H(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(H(this._r,255)*100)+"%, "+Math.round(H(this._g,255)*100)+"%, "+Math.round(H(this._b,255)*100)+"%)":"rgba("+Math.round(H(this._r,255)*100)+"%, "+Math.round(H(this._g,255)*100)+"%, "+Math.round(H(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:qs[Zt(this._r,this._g,this._b,!0)]||!1},toFilter:function(e){var t="#"+qt(this._r,this._g,this._b,this._a),s=t,n=this._gradientType?"GradientType = 1, ":"";if(e){var a=A(e);s="#"+qt(a._r,a._g,a._b,a._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+t+",endColorstr="+s+")"},toString:function(e){var t=!!e;e=e||this._format;var s=!1,n=this._a<1&&this._a>=0,a=!t&&n&&(e==="hex"||e==="hex6"||e==="hex3"||e==="hex4"||e==="hex8"||e==="name");return a?e==="name"&&this._a===0?this.toName():this.toRgbString():(e==="rgb"&&(s=this.toRgbString()),e==="prgb"&&(s=this.toPercentageRgbString()),(e==="hex"||e==="hex6")&&(s=this.toHexString()),e==="hex3"&&(s=this.toHexString(!0)),e==="hex4"&&(s=this.toHex8String(!0)),e==="hex8"&&(s=this.toHex8String()),e==="name"&&(s=this.toName()),e==="hsl"&&(s=this.toHslString()),e==="hsv"&&(s=this.toHsvString()),s||this.toHexString())},clone:function(){return A(this.toString())},_applyModification:function(e,t){var s=e.apply(null,[this].concat([].slice.call(t)));return this._r=s._r,this._g=s._g,this._b=s._b,this.setAlpha(s._a),this},lighten:function(){return this._applyModification(Vs,arguments)},brighten:function(){return this._applyModification(js,arguments)},darken:function(){return this._applyModification(Ys,arguments)},desaturate:function(){return this._applyModification(Os,arguments)},saturate:function(){return this._applyModification(Ps,arguments)},greyscale:function(){return this._applyModification(zs,arguments)},spin:function(){return this._applyModification(Ws,arguments)},_applyCombination:function(e,t){return e.apply(null,[this].concat([].slice.call(t)))},analogous:function(){return this._applyCombination(Gs,arguments)},complement:function(){return this._applyCombination(Xs,arguments)},monochromatic:function(){return this._applyCombination(Zs,arguments)},splitcomplement:function(){return this._applyCombination(Us,arguments)},triad:function(){return this._applyCombination(Jt,[3])},tetrad:function(){return this._applyCombination(Jt,[4])}},A.fromRatio=function(i,e){if(Ve(i)=="object"){var t={};for(var s in i)i.hasOwnProperty(s)&&(s==="a"?t[s]=i[s]:t[s]=Ae(i[s]));i=t}return A(i,e)};function Hs(i){var e={r:0,g:0,b:0},t=1,s=null,n=null,a=null,r=!1,o=!1;return typeof i=="string"&&(i=en(i)),Ve(i)=="object"&&(te(i.r)&&te(i.g)&&te(i.b)?(e=Bs(i.r,i.g,i.b),r=!0,o=String(i.r).substr(-1)==="%"?"prgb":"rgb"):te(i.h)&&te(i.s)&&te(i.v)?(s=Ae(i.s),n=Ae(i.v),e=Rs(i.h,s,n),r=!0,o="hsv"):te(i.h)&&te(i.s)&&te(i.l)&&(s=Ae(i.s),a=Ae(i.l),e=Is(i.h,s,a),r=!0,o="hsl"),i.hasOwnProperty("a")&&(t=i.a)),t=Qt(t),{ok:r,format:i.format||o,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:t}}function Bs(i,e,t){return{r:H(i,255)*255,g:H(e,255)*255,b:H(t,255)*255}}function Ut(i,e,t){i=H(i,255),e=H(e,255),t=H(t,255);var s=Math.max(i,e,t),n=Math.min(i,e,t),a,r,o=(s+n)/2;if(s==n)a=r=0;else{var c=s-n;switch(r=o>.5?c/(2-s-n):c/(s+n),s){case i:a=(e-t)/c+(e<t?6:0);break;case e:a=(t-i)/c+2;break;case t:a=(i-e)/c+4;break}a/=6}return{h:a,s:r,l:o}}function Is(i,e,t){var s,n,a;i=H(i,360),e=H(e,100),t=H(t,100);function r(h,u,g){return g<0&&(g+=1),g>1&&(g-=1),g<1/6?h+(u-h)*6*g:g<1/2?u:g<2/3?h+(u-h)*(2/3-g)*6:h}if(e===0)s=n=a=t;else{var o=t<.5?t*(1+e):t+e-t*e,c=2*t-o;s=r(c,o,i+1/3),n=r(c,o,i),a=r(c,o,i-1/3)}return{r:s*255,g:n*255,b:a*255}}function Gt(i,e,t){i=H(i,255),e=H(e,255),t=H(t,255);var s=Math.max(i,e,t),n=Math.min(i,e,t),a,r,o=s,c=s-n;if(r=s===0?0:c/s,s==n)a=0;else{switch(s){case i:a=(e-t)/c+(e<t?6:0);break;case e:a=(t-i)/c+2;break;case t:a=(i-e)/c+4;break}a/=6}return{h:a,s:r,v:o}}function Rs(i,e,t){i=H(i,360)*6,e=H(e,100),t=H(t,100);var s=Math.floor(i),n=i-s,a=t*(1-e),r=t*(1-n*e),o=t*(1-(1-n)*e),c=s%6,h=[t,r,a,a,o,t][c],u=[o,t,t,r,a,a][c],g=[a,a,o,t,t,r][c];return{r:h*255,g:u*255,b:g*255}}function Zt(i,e,t,s){var n=[Z(Math.round(i).toString(16)),Z(Math.round(e).toString(16)),Z(Math.round(t).toString(16))];return s&&n[0].charAt(0)==n[0].charAt(1)&&n[1].charAt(0)==n[1].charAt(1)&&n[2].charAt(0)==n[2].charAt(1)?n[0].charAt(0)+n[1].charAt(0)+n[2].charAt(0):n.join("")}function $s(i,e,t,s,n){var a=[Z(Math.round(i).toString(16)),Z(Math.round(e).toString(16)),Z(Math.round(t).toString(16)),Z(Kt(s))];return n&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function qt(i,e,t,s){var n=[Z(Kt(s)),Z(Math.round(i).toString(16)),Z(Math.round(e).toString(16)),Z(Math.round(t).toString(16))];return n.join("")}A.equals=function(i,e){return!i||!e?!1:A(i).toRgbString()==A(e).toRgbString()},A.random=function(){return A.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})};function Os(i,e){e=e===0?0:e||10;var t=A(i).toHsl();return t.s-=e/100,t.s=je(t.s),A(t)}function Ps(i,e){e=e===0?0:e||10;var t=A(i).toHsl();return t.s+=e/100,t.s=je(t.s),A(t)}function zs(i){return A(i).desaturate(100)}function Vs(i,e){e=e===0?0:e||10;var t=A(i).toHsl();return t.l+=e/100,t.l=je(t.l),A(t)}function js(i,e){e=e===0?0:e||10;var t=A(i).toRgb();return t.r=Math.max(0,Math.min(255,t.r-Math.round(255*-(e/100)))),t.g=Math.max(0,Math.min(255,t.g-Math.round(255*-(e/100)))),t.b=Math.max(0,Math.min(255,t.b-Math.round(255*-(e/100)))),A(t)}function Ys(i,e){e=e===0?0:e||10;var t=A(i).toHsl();return t.l-=e/100,t.l=je(t.l),A(t)}function Ws(i,e){var t=A(i).toHsl(),s=(t.h+e)%360;return t.h=s<0?360+s:s,A(t)}function Xs(i){var e=A(i).toHsl();return e.h=(e.h+180)%360,A(e)}function Jt(i,e){if(isNaN(e)||e<=0)throw new Error("Argument to polyad must be a positive number");for(var t=A(i).toHsl(),s=[A(i)],n=360/e,a=1;a<e;a++)s.push(A({h:(t.h+a*n)%360,s:t.s,l:t.l}));return s}function Us(i){var e=A(i).toHsl(),t=e.h;return[A(i),A({h:(t+72)%360,s:e.s,l:e.l}),A({h:(t+216)%360,s:e.s,l:e.l})]}function Gs(i,e,t){e=e||6,t=t||30;var s=A(i).toHsl(),n=360/t,a=[A(i)];for(s.h=(s.h-(n*e>>1)+720)%360;--e;)s.h=(s.h+n)%360,a.push(A(s));return a}function Zs(i,e){e=e||6;for(var t=A(i).toHsv(),s=t.h,n=t.s,a=t.v,r=[],o=1/e;e--;)r.push(A({h:s,s:n,v:a})),a=(a+o)%1;return r}A.mix=function(i,e,t){t=t===0?0:t||50;var s=A(i).toRgb(),n=A(e).toRgb(),a=t/100,r={r:(n.r-s.r)*a+s.r,g:(n.g-s.g)*a+s.g,b:(n.b-s.b)*a+s.b,a:(n.a-s.a)*a+s.a};return A(r)},A.readability=function(i,e){var t=A(i),s=A(e);return(Math.max(t.getLuminance(),s.getLuminance())+.05)/(Math.min(t.getLuminance(),s.getLuminance())+.05)},A.isReadable=function(i,e,t){var s=A.readability(i,e),n,a;switch(a=!1,n=tn(t),n.level+n.size){case"AAsmall":case"AAAlarge":a=s>=4.5;break;case"AAlarge":a=s>=3;break;case"AAAsmall":a=s>=7;break}return a},A.mostReadable=function(i,e,t){var s=null,n=0,a,r,o,c;t=t||{},r=t.includeFallbackColors,o=t.level,c=t.size;for(var h=0;h<e.length;h++)a=A.readability(i,e[h]),a>n&&(n=a,s=A(e[h]));return A.isReadable(i,s,{level:o,size:c})||!r?s:(t.includeFallbackColors=!1,A.mostReadable(i,["#fff","#000"],t))};var lt=A.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},qs=A.hexNames=Js(lt);function Js(i){var e={};for(var t in i)i.hasOwnProperty(t)&&(e[i[t]]=t);return e}function Qt(i){return i=parseFloat(i),(isNaN(i)||i<0||i>1)&&(i=1),i}function H(i,e){Qs(i)&&(i="100%");var t=Ks(i);return i=Math.min(e,Math.max(0,parseFloat(i))),t&&(i=parseInt(i*e,10)/100),Math.abs(i-e)<1e-6?1:i%e/parseFloat(e)}function je(i){return Math.min(1,Math.max(0,i))}function W(i){return parseInt(i,16)}function Qs(i){return typeof i=="string"&&i.indexOf(".")!=-1&&parseFloat(i)===1}function Ks(i){return typeof i=="string"&&i.indexOf("%")!=-1}function Z(i){return i.length==1?"0"+i:""+i}function Ae(i){return i<=1&&(i=i*100+"%"),i}function Kt(i){return Math.round(parseFloat(i)*255).toString(16)}function ei(i){return W(i)/255}var q=function(){var i="[-\\+]?\\d+%?",e="[-\\+]?\\d*\\.\\d+%?",t="(?:"+e+")|(?:"+i+")",s="[\\s|\\(]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")\\s*\\)?",n="[\\s|\\(]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")[,|\\s]+("+t+")\\s*\\)?";return{CSS_UNIT:new RegExp(t),rgb:new RegExp("rgb"+s),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+s),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+s),hsva:new RegExp("hsva"+n),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();function te(i){return!!q.CSS_UNIT.exec(i)}function en(i){i=i.replace(Ns,"").replace(Fs,"").toLowerCase();var e=!1;if(lt[i])i=lt[i],e=!0;else if(i=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var t;return(t=q.rgb.exec(i))?{r:t[1],g:t[2],b:t[3]}:(t=q.rgba.exec(i))?{r:t[1],g:t[2],b:t[3],a:t[4]}:(t=q.hsl.exec(i))?{h:t[1],s:t[2],l:t[3]}:(t=q.hsla.exec(i))?{h:t[1],s:t[2],l:t[3],a:t[4]}:(t=q.hsv.exec(i))?{h:t[1],s:t[2],v:t[3]}:(t=q.hsva.exec(i))?{h:t[1],s:t[2],v:t[3],a:t[4]}:(t=q.hex8.exec(i))?{r:W(t[1]),g:W(t[2]),b:W(t[3]),a:ei(t[4]),format:e?"name":"hex8"}:(t=q.hex6.exec(i))?{r:W(t[1]),g:W(t[2]),b:W(t[3]),format:e?"name":"hex"}:(t=q.hex4.exec(i))?{r:W(t[1]+""+t[1]),g:W(t[2]+""+t[2]),b:W(t[3]+""+t[3]),a:ei(t[4]+""+t[4]),format:e?"name":"hex8"}:(t=q.hex3.exec(i))?{r:W(t[1]+""+t[1]),g:W(t[2]+""+t[2]),b:W(t[3]+""+t[3]),format:e?"name":"hex"}:!1}function tn(i){var e,t;return i=i||{level:"AA",size:"small"},e=(i.level||"AA").toUpperCase(),t=(i.size||"small").toLowerCase(),e!=="AA"&&e!=="AAA"&&(e="AA"),t!=="small"&&t!=="large"&&(t="small"),{level:e,size:t}}function sn(i,e){const{trade:{tradedCandles:t},scales:{x:s,y:n},colorScheme:a,config:{trade:{showLabelButtons:r}}}=e;if(!r)return;const{trade:o}=a,c=4;t.forEach(({isHovered:h,isActive:u,candle:g,trades:_})=>{const p=s.convert(g.open_time);_.forEach(v=>{const b=v.type==="buy",x=b?o.buyLabel.text:o.sellLabel.text,C=b?"B":"S",y=b?n.convert(g.low)+c:n.convert(g.high)-c,w=b?Es:Ls;let M=b?o.buyLabel.main:o.sellLabel.main;h&&h[1]&&h[0]===v.type&&(M=A.mix(M,a.bg,20).toString()),u&&u[1]&&u[0]===v.type&&(M=o.activeLabel),w(i,{x:p,y,symbol:C,mainColor:M,textColor:x,size:16,fontSize:12})})})}function nn(i,e){const{scales:{x:t,factorX:s},layout:{area:n},trade:{tradedCandles:a,exits:r,entries:o},config:{candles:c},colorScheme:{trade:h}}=e;if(a.length===0)return;const u=a.map(_=>_.candle).sort((_,p)=>_.open_time.getTime()-p.open_time.getTime()),g=c.baseWidth/2*s+c.strokeWidth/2;if(i.save(),i.lineWidth=1,i.strokeStyle=h.tradeBorders,o.length){const _=t.convert(u[0].open_time)-g;i.beginPath(),i.moveTo(_,n.y),i.lineTo(_,n.y+n.height),i.stroke()}if(r.length){const _=t.convert(u[u.length-1].open_time)+g;i.beginPath(),i.moveTo(_,n.y),i.lineTo(_,n.y+n.height),i.stroke()}i.restore()}const an=(i,e)=>{const{scales:{x:t,y:s},trade:{tradedCandles:n,entries:a,exits:r},colorScheme:{trade:o},config:{trade:{showConnectionLine:c}}}=e;if(i.save(),!c)return;const h=g=>{var _;return(_=n.find(p=>g.getTime()>=p.candle.open_time.getTime()&&g.getTime()<p.candle.close_time.getTime()))==null?void 0:_.candle},u=(g,_)=>{const p=h(g.time),v=h(_.time);if(!p||!v)return;const b=t.convert(p.open_time),x=t.convert(v.open_time);let C,y;g.type==="buy"?(C=s.convert(p.low),y=s.convert(v.high)):(C=s.convert(p.high),y=s.convert(v.low)),i.beginPath(),i.setLineDash([4,4]),i.strokeStyle=o.connectionLine,i.moveTo(b,C),i.lineTo(x,y),i.stroke(),i.setLineDash([])};if(a.length===1&&r.length>1)r.forEach(g=>u(a[0],g));else if(r.length===1&&a.length>1)a.forEach(g=>u(g,r[0]));else if(a.length===1&&r.length===1)u(a[0],r[0]);else if(a.length>0&&r.length>0){const g=a.reduce((p,v)=>p.time<v.time?p:v),_=r.reduce((p,v)=>p.time>v.time?p:v);u(g,_)}i.restore()},ti=(i,e)=>{const{radius:t,coords:{x:s,y:n},fillColor:a,width:r,height:o}=e;i.beginPath(),i.fillStyle=a,i.lineWidth=1,i.moveTo(s+t,n),i.lineTo(s+r-t,n),i.quadraticCurveTo(s+r,n,s+r,n+t),i.lineTo(s+r,n+o-t),i.quadraticCurveTo(s+r,n+o,s+r-t,n+o),i.lineTo(s+t,n+o),i.quadraticCurveTo(s,n+o,s,n+o-t),i.lineTo(s,n+t),i.quadraticCurveTo(s,n,s+t,n),i.closePath(),i.fill()},rn=i=>{const e=Math.floor((Date.now()-+i)/1e3),t=[[60,1,"s"],[3600,60,"m"],[86400,3600,"h"],[604800,86400,"d"],[2629746,604800,"w"],[31556952,2629746,"mo"],[1/0,31556952,"y"]],[,s,n]=t.find(([r])=>e<r);return`${Math.floor(e/s)}${n} ago`};function on(i){const e=Math.floor(i/1e3),t=[{label:"d",value:86400},{label:"h",value:3600},{label:"m",value:60},{label:"s",value:1}],s=[];let n=e;for(const{label:a,value:r}of t)if(n>=r){const o=Math.floor(n/r);if(s.push(`${o}${a}`),n%=r,s.length===2)break}return s.length?s.join(" "):"0s"}const ln=10,cn=6,hn=4,dn=12,un=(i,e)=>{var se;const{scales:{x:t,y:s},trade:{entries:n,exits:a,holdTime:r},colorScheme:{trade:{hold:o}},config:{trade:{showHoldTime:c,holdTimeContent:h,holdTimeDates:u,holdTimePrice:g}}}=e;if(!c)return;const _=n.at(0),p=a.at(-1);if(!_||!p)return;const v=U=>U?U instanceof Date?U:new Date(U):null,b=t.convert(v(u==null?void 0:u[0])||_.candle.open_time),x=t.convert(v(u==null?void 0:u[1])||p.candle.open_time),C=s.convert(g||(((se=n.at(0))==null?void 0:se.price)??0));i.beginPath(),i.setLineDash([4,4]),i.strokeStyle=o.main,i.moveTo(b,C),i.lineTo(x,C),i.stroke(),i.setLineDash([]);const y=(b+x)/2,w=h||`Hold: ${on(r)}`,L=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();i.font=`600 ${ln}px ${L}`;const $=i.measureText(w).width+cn*2,O=dn+hn*2;ti(i,{radius:4,coords:{x:y-$/2,y:C-O/2},width:$,height:O,fillColor:o.main}),i.fillStyle=o.text,i.textBaseline="middle",i.textAlign="center",i.fillText(w,y,C),i.restore()};class Me{constructor(e,t,{CanvasClass:s=Se,noCanvas:n=!1,noDOM:a=!1}={}){f(this,"canvas",null);f(this,"dom",null);f(this,"prefix");const{width:r,height:o,canvasesContainer:c,domElements:h}=t;n||(this.canvas=new s({className:`sc-charts-cs__canvas-${e}`,width:r,height:o}),c.append(this.canvas.node)),a||(this.dom=new D({className:`sc-charts-cs__dom-${e}`}),h.append(this.dom.node)),this.prefix=`sc-charts-cs__${e}`}cx(...e){return e.map(t=>`${this.prefix}-${t}`).join(" ")}cxFabric(...e){return t=>e.map(s=>`${this.prefix}-${s}-${t}`).join(" ")}}const fn={"right-bottom":{dx:1,dy:1},"left-top":{dx:-1,dy:-1},"right-top":{dx:1,dy:-1},"left-bottom":{dx:-1,dy:1}},ct=({size:i,parent:e,coords:t,prioritySide:s="right-bottom",offset:n=8})=>{const{width:a,height:r}=i,o=e.right-e.left,c=e.bottom-e.top,h=y=>{const{dx:w,dy:M}=fn[y],L=t.x+(w===1?n:-a-n),R=t.y+(M===1?n:-r-n);return{x:L,y:R,side:y}},u=({x:y,y:w})=>y>=0&&w>=0&&y+a<=o&&w+r<=c,g=()=>{const y=t.y<0,w=t.y+r>c,M=t.x<0,L=t.x+a>o;return M&&y?"right-bottom":M&&w?"right-top":L&&y?"left-bottom":L&&w?"left-top":M?"right-bottom":L?"left-bottom":y?"right-bottom":w?"right-top":s},p=[s,"right-bottom","right-top","left-bottom","left-top"].filter((y,w,M)=>M.indexOf(y)===w),v=g();let b=null;for(const y of[v,...p]){const w=h(y);if(u(w)){b=w;break}}b||(b=h(v));const x=Math.min(Math.max(b.x,n),o-a-n),C=Math.min(Math.max(b.y,n),c-r-n);return{x,y:C,side:b.side}};class ie extends D{constructor(t){super(t);f(this,"_state",{});f(this,"_updateScheduled",!1)}get state(){return this._state}set state(t){this._state=new Proxy(t,{set:(s,n,a)=>{if(typeof n!="string")return!0;const r=n;return s[r]===a||(s[r]=a,this._scheduleUpdate()),!0}})}setState(t){Object.assign(this.state,t)}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,requestAnimationFrame(()=>{this._updateScheduled=!1,this.render()}))}render(){}destroy(){this._updateScheduled=!1,this.remove()}forceUpdate(){this._scheduleUpdate()}}class gn extends ie{constructor(t){const s="label-tooltip";super({className:t.cx(s)});f(this,"title");f(this,"manyBox");f(this,"oneBox");f(this,"clsx");this.clsx=t.cxFabric(s),this.title=new D({tag:"div",className:this.clsx("title")}),this.manyBox=new D({tag:"div",className:this.clsx("box_many")}),this.oneBox=new D({tag:"div",className:this.clsx("box_one")}),t.dom.append(this.title.node,this.oneBox.node,this.manyBox.node),this.state={isShow:!1,x:0,y:0,parent:Y.empty()}}_createLineNodes(t,s){const n=[];for(const a of Object.keys(s))if(a in t){const r=new D({tag:"div",className:this.clsx("line")});let o=t[a].toString();a==="kind"&&(o=this._formatDate(t.time));const c=new D({tag:"strong",textContent:s[a]}),h=new D({tag:"span",textContent:o});r.append(c.node,h.node),n.push(r.node)}return n}_formatDate(t){const s=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short",year:"numeric",hour12:!1}).format(t),[n,a,r]=s.split(", ");return`${n}, ${a} ${r}`}updateContent(t){if(t.length){if(this.title.node.style.display="none",this.oneBox.node.style.display="none",this.oneBox.node.replaceChildren(),this.manyBox.node.style.display="none",this.manyBox.node.replaceChildren(),t.length===1){this.title.node.style.display="flex",this.oneBox.node.style.display="flex",this.title.node.textContent=this._formatDate(t[0].time);const s=this._createLineNodes(t[0],{price:"Price:",profit:"Realized P&L:",volume:"Volume:",percentage:"% of position:"});this.oneBox.append(...s),this.node.append(this.title.node,this.oneBox.node)}else if(t.length>1){this.manyBox.node.style.display="flex";const s=t.map(n=>{const a=new D({tag:"div"}),r=this._createLineNodes(n,{kind:n.kind==="entry"?"Entry:":"Exit:",price:"Price:"});return a.append(...r),a.node});this.manyBox.append(...s),this.node.append(this.manyBox.node)}}}render(){const{isShow:t,x:s,y:n,parent:a}=this.state;this.setVisible(t),t&&this.updateAbsolutePosition();const r=ct({size:this.absolutePosition,parent:a,coords:{x:s,y:n}});this.position(r.x,r.y)}}class mn extends Me{constructor(t){super("trade",t);f(this,"labelTooltip");if(!this.dom)throw new Error("[CS_V_Trade] this.dom must be defined");if(!this.canvas)throw new Error("[CS_V_Trade] this.canvas must be defined");this.labelTooltip=new gn(this),this.dom.append(this.labelTooltip.node)}renderAll(t){this.canvas.clear(),nn(this.canvas.ctx,t),sn(this.canvas.ctx,t),an(this.canvas.ctx,t),un(this.canvas.ctx,t)}}function pn(i,{color:e="#000000",lineWidth:t=1,dashed:s,coords:n}){i.strokeStyle=e,i.lineWidth=t,s&&i.setLineDash(s),i.beginPath(),i.moveTo(n.x1,n.y1),i.lineTo(n.x2,n.y2),i.stroke()}const _n={text:"#FFFFFF",bg:"#000000"},vn=(i,e)=>{const{coords:t,text:s,fontSize:n=14,fontWeight:a=600,textHeight:r,padding:o={x:0,y:0},borderRadius:c=0,colors:h,align:u={x:"left",y:"top"}}=e,g={..._n,...h},p=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();i.font=`${a} ${n}px ${p}`;const b=i.measureText(s).width+o.x*2,x=r+o.y*2;let C=t.x,y=t.y;u.x==="middle"?C-=b/2:u.x==="right"&&(C-=b),u.y==="middle"?y-=x/2:u.y==="bottom"&&(y-=x),ti(i,{radius:c,coords:{x:C,y},width:b,height:x,fillColor:g.bg}),i.fillStyle=g.text,i.textBaseline="middle",i.textAlign="center",i.fillText(s,C+b/2,y+x/2)},ii={line:"#000000",text:"#ffffff",main:"#000000"},si=(i,{text:e,startLineCoords:t,side:s,colors:n=ii,dir:a="h",endMarkerCoords:r})=>{if(a==="h"&&(s==="bottom"||s==="top"))throw new Error("[drawMarker util]: Incorrect side or dir for this marker");const o={...ii,...n};i.save(),pn(i,{color:o.line,lineWidth:1,dashed:[4,4],coords:{x1:t.x,y1:t.y,x2:r.x,y2:r.y}}),vn(i,{text:e,coords:r,padding:{x:6,y:4},borderRadius:4,fontSize:10,textHeight:12,align:{x:a==="v"?"middle":s,y:a==="h"?"middle":s},colors:{text:o.text,bg:o.main}}),i.restore()};class bn extends Se{constructor(e){super(e)}drawMarker(e){si(this.ctx,e)}}class yn extends Me{constructor(e){if(super("user-markers",e,{CanvasClass:bn,noDOM:!0}),!this.canvas)throw new Error("[CS_V_UserMarkers] this.canvas must be defined")}render(e){this.canvas.clear();for(const t of e.userMarkers.data)this.canvas.drawMarker({text:t.text,side:e.config.yAxis.position,dir:"h",startLineCoords:{x:t.startDate?e.scales.x.convert(t.startDate):0,y:e.scales.y.convert(t.value)},endMarkerCoords:{x:e.layout.yAxis.right,y:e.scales.y.convert(t.value)},colors:{line:t.lineColor,main:t.mainColor,text:t.textColor}})}clear(){this.canvas.clear()}}const wn="sc-charts-cs";class ae{constructor(e){f(this,"block");this.block=e}gen(e){return`${wn}__${this.block}${e?"-"+e:""}`}}const ht=new ae("comment-actions");class xn extends D{constructor({onDelete:e,onUpdate:t}){super({className:ht.gen()});const s=new D({tag:"button",className:ht.gen("edit"),textContent:"Edit"}),n=new D({tag:"button",className:ht.gen("delete"),textContent:"Delete"});n.node.addEventListener("click",a=>{a.stopPropagation(),e()}),s.node.addEventListener("click",a=>{a.stopPropagation(),t()}),this.append(s.node,n.node)}}function dt(i,e){var n;const t=a=>{if(!document.contains(i.node))return;const r=a.target;if(i.node.contains(r))return;const o=document.elementFromPoint(a.clientX,a.clientY);if(o&&i.node.contains(o))return;const c=i.node.getBoundingClientRect();a.clientX>=c.left&&a.clientX<=c.right&&a.clientY>=c.top&&a.clientY<=c.bottom&&getComputedStyle(i.node).pointerEvents!=="none"||e(a)};document.addEventListener("mousedown",t);const s=(n=i.destroy)==null?void 0:n.bind(i);return i.destroy=()=>{document.removeEventListener("mousedown",t),s==null||s()},i}class Cn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","18"),t.setAttribute("height","4"),t.setAttribute("viewBox","0 0 18 4"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=[{d:"M9 2.83366C9.46024 2.83366 9.83333 2.46056 9.83333 2.00033C9.83333 1.54009 9.46024 1.16699 9 1.16699C8.53976 1.16699 8.16667 1.54009 8.16667 2.00033C8.16667 2.46056 8.53976 2.83366 9 2.83366Z",fill:"currentColor"},{d:"M15.6667 2.83366C16.1269 2.83366 16.5 2.46056 16.5 2.00033C16.5 1.54009 16.1269 1.16699 15.6667 1.16699C15.2064 1.16699 14.8333 1.54009 14.8333 2.00033C14.8333 2.46056 15.2064 2.83366 15.6667 2.83366Z",fill:"currentColor"},{d:"M2.33333 2.83366C2.79357 2.83366 3.16667 2.46056 3.16667 2.00033C3.16667 1.54009 2.79357 1.16699 2.33333 1.16699C1.8731 1.16699 1.5 1.54009 1.5 2.00033C1.5 2.46056 1.8731 2.83366 2.33333 2.83366Z",fill:"currentColor"},{d:"M9 2.83366C9.46024 2.83366 9.83333 2.46056 9.83333 2.00033C9.83333 1.54009 9.46024 1.16699 9 1.16699C8.53976 1.16699 8.16667 1.54009 8.16667 2.00033C8.16667 2.46056 8.53976 2.83366 9 2.83366Z",stroke:"currentColor"},{d:"M15.6667 2.83366C16.1269 2.83366 16.5 2.46056 16.5 2.00033C16.5 1.54009 16.1269 1.16699 15.6667 1.16699C15.2064 1.16699 14.8333 1.54009 14.8333 2.00033C14.8333 2.46056 15.2064 2.83366 15.6667 2.83366Z",stroke:"currentColor"},{d:"M2.33333 2.83366C2.79357 2.83366 3.16667 2.46056 3.16667 2.00033C3.16667 1.54009 2.79357 1.16699 2.33333 1.16699C1.8731 1.16699 1.5 1.54009 1.5 2.00033C1.5 2.46056 1.8731 2.83366 2.33333 2.83366Z",stroke:"currentColor"}];for(const n of s){const a=document.createElementNS(e,"path");a.setAttribute("d",n.d),n.fill&&a.setAttribute("fill",n.fill),n.stroke&&(a.setAttribute("stroke",n.stroke),a.setAttribute("stroke-width","2"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round")),t.appendChild(a)}this.node=t}}const Te=new ae("comment-list");class Sn extends D{constructor({onDelete:t,onOpenEditor:s,comment:n,layout:a}){super({className:Te.gen("item")});f(this,"actionTooltip");f(this,"actionsTrigger");const r=new D({className:Te.gen("text"),textContent:n.text}),o=new D({className:Te.gen("created-at"),textContent:rn(new Date(n.createdAt))});this.actionsTrigger=new D({tag:"button",className:Te.gen("action-trigger")});const c=new xn({onDelete:t,onUpdate:s});this.actionTooltip=dt(c,()=>{this.actionTooltip.setVisible(!1)}),this.actionsTrigger.node.addEventListener("click",()=>{this.actionsTrigger.updateAbsolutePosition(),this.actionTooltip.updateAbsolutePosition(),this.actionTooltip.node.style.top=this.actionsTrigger.absolutePosition.top-a.chart.top+20+"px",this.actionTooltip.node.style.left=this.actionsTrigger.absolutePosition.left-a.chart.left-this.actionTooltip.absolutePosition.width+10+"px",this.actionTooltip.setVisible(!0)});const h=new D({className:Te.gen("text-wrap")});this.actionTooltip.node.setAttribute("id",`ac-${n.id}`),h.append(r.node,this.actionsTrigger.node),this.actionsTrigger.append(new Cn().node),this.append(h.node,o.node)}}class An{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","14"),t.setAttribute("height","12"),t.setAttribute("viewBox","0 0 14 12"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M12.4139 0.531408C12.6727 0.208181 13.1453 0.155616 13.4686 0.414221C13.792 0.672923 13.8444 1.14547 13.5858 1.46891L5.58582 11.4689C5.45257 11.6355 5.25388 11.7374 5.0409 11.7492C4.82806 11.7608 4.62035 11.6812 4.46961 11.5304L0.469611 7.53043C0.176835 7.23753 0.176757 6.76274 0.469611 6.46988C0.744191 6.19548 1.179 6.17796 1.47352 6.41813L1.53016 6.46988L4.93738 9.87711L12.4139 0.531408Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class Mn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","10"),t.setAttribute("height","10"),t.setAttribute("viewBox","0 0 10 10"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("fill-rule","evenodd"),s.setAttribute("clip-rule","evenodd"),s.setAttribute("d","M9.05951 2.10202C9.38042 1.78111 9.38042 1.26081 9.05951 0.939901C8.73861 0.618991 8.21831 0.618991 7.8974 0.939901L5.0002 3.8371L2.10299 0.939901C1.78208 0.618992 1.26179 0.618992 0.940877 0.939901C0.619968 1.26081 0.619968 1.78111 0.940877 2.10202L3.83808 4.99922L0.940877 7.89642C0.619968 8.21733 0.619968 8.73763 0.940877 9.05854C1.26179 9.37945 1.78208 9.37945 2.10299 9.05854L5.0002 6.16133L7.8974 9.05854C8.21831 9.37945 8.73861 9.37945 9.05951 9.05854C9.38042 8.73763 9.38042 8.21733 9.05951 7.89642L6.16231 4.99922L9.05951 2.10202Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class Tn extends ie{constructor(t){super({className:"sc-charts-cs__comments-edit"});f(this,"input");f(this,"saveBtn");f(this,"cancelBtn");f(this,"_onSave");f(this,"_onCancel");this._onSave=t.onSave,this._onCancel=t.onCancel,this.input=new D({tag:"textarea",className:"sc-charts-cs__comments-edit-input"}),this.saveBtn=new D({tag:"button",className:"sc-charts-cs__comments-edit-save-btn"}),this.saveBtn.append(new An().node),this.cancelBtn=new D({tag:"button",className:"sc-charts-cs__comments-edit-cancel-btn"}),this.cancelBtn.append(new Mn().node);const s=new D({className:"sc-charts-cs__comments-edit-btn-container"});s.append(this.cancelBtn.node,this.saveBtn.node),this.append(this.input.node,s.node),this.state={inputValue:t.initialValue||"",hasInitFocused:!1},this._setupListeners(),this.render()}_setupListeners(){this.saveBtn.node.addEventListener("click",()=>{this._onSave(this.state.inputValue)}),this.input.node.addEventListener("input",t=>{const s=t.target;this.setState({inputValue:s.value})}),this.cancelBtn.node.addEventListener("click",this._onCancel)}render(){this.input.node.value=this.state.inputValue,this.saveBtn.node.disabled=!this.state.inputValue.trim(),this.state.hasInitFocused||(requestAnimationFrame(()=>this.input.node.focus()),this.setState({hasInitFocused:!0}))}}const kn=new ae("comment-list");class Dn extends ie{constructor(t,s,n,a={}){super({tag:"ul",className:kn.gen(),...a});f(this,"_elements",{});f(this,"_model");f(this,"_view");this._model=s,this._view=n,this.state={items:t,editId:null},this.render()}render(){this.node.replaceChildren(),this._elements={},this.state.items.forEach((t,s)=>{this._elements[t.id]={order:s+1,element:this._createItem(t)}}),this.append(...this._sortedNodes())}_createItem(t){if(this.state.editId===t.id)return new Tn({onSave:a=>{this._model.comments.update(t.id,a),this.setState({editId:null})},onCancel:()=>{this.setState({editId:null})},initialValue:t.text});const s=new Sn({onDelete:()=>{this._model.comments.remove(t.id),s.actionTooltip.setVisible(!1)},onOpenEditor:()=>{this.setState({editId:t.id}),s.actionTooltip.setVisible(!1)},comment:t,layout:this._model.layout}),n=document.querySelector(`#ac-${t.id}`);return n?n.replaceWith(s.actionTooltip.node):this._view.domElements.append(s.actionTooltip.node),s}_sortedNodes(){return Object.values(this._elements).sort((t,s)=>t.order-s.order).map(t=>t.element.node)}}class En{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","14"),t.setAttribute("height","14"),t.setAttribute("viewBox","0 0 14 14"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M3.00035 7.00005H5.33369M3.00035 7.00005L0.957995 1.45651C0.853586 1.17312 1.14972 0.908067 1.41985 1.04313L12.7374 6.70191C12.9831 6.82475 12.9831 7.17535 12.7374 7.29819L1.41985 12.957C1.14971 13.092 0.853586 12.827 0.957995 12.5436L3.00035 7.00005Z"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),t.appendChild(s),this.node=t}}const Ye=new ae(""),ut=new ae("add-field");class ni extends ie{constructor({onAdd:t,blockName:s}){Ye.block=s;super({className:Ye.gen()+" "+ut.gen()});f(this,"btn");f(this,"input");f(this,"_onAdd");this._onAdd=t,this.state={inputValue:""},this.input=new D({tag:"input",className:Ye.gen("input")+" "+ut.gen("input")}),this.input.node.setAttribute("placeholder","Add comment..."),this.btn=new D({tag:"button",className:Ye.gen("btn")+" "+ut.gen("btn")}),this.btn.append(new En().node),this.append(this.input.node,this.btn.node),this._setupListeners(),this.render()}_addComment(){this._onAdd(this.input.node.value),this.setState({inputValue:""}),this.input.node.value="",this.input.node.blur()}_setupListeners(){this.btn.node.addEventListener("click",()=>{this.btn.node.disabled||this._addComment()}),this.input.node.addEventListener("keydown",t=>{t.key==="Enter"&&!this.btn.node.disabled&&this._addComment()}),this.input.node.addEventListener("input",t=>{const s=t.target;this.setState({inputValue:s.value})})}render(){this.btn.node.disabled=!this.state.inputValue.trim()}}const Ln=new ae("list-tooltip"),ft=8;class Nn extends ie{constructor(t,s,n){super({className:Ln.gen()});f(this,"_list");f(this,"_addField");f(this,"_size",null);f(this,"_model");f(this,"_prevIsShow",!1);this._model=s,this.state={isShow:!1,comments:t},this._list=new Dn(t,s,n),this._addField=new ni({blockName:"list-tooltip-add",onAdd:a=>{const r=t[0].date,o=t[0].price,c={id:crypto.randomUUID(),text:a,date:r,price:o,createdAt:new Date().toISOString()};s.comments.add(c)}}),this.node.append(this._list.node,this._addField.node)}render(){const{isShow:t,comments:s}=this.state,{width:n,height:a}=this._model.layout.area;this._prevIsShow!==t&&(this._list.forceUpdate(),this._prevIsShow=t),this.node.style.maxHeight=a/2-ft+"px",this.setVisible(t),t&&!this._size&&(this.updateAbsolutePosition(),this._size=this.absolutePosition,this.position(n/2-this._size.width-ft,a/2+ft)),this._list.setState({items:s}),requestAnimationFrame(()=>{this._list.node.scrollTop=this._list.node.scrollHeight})}get list(){return this._list}}class Fn{constructor(){f(this,"node");const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","16"),t.setAttribute("height","16"),t.setAttribute("viewBox","0 0 16 16"),t.setAttribute("fill","none"),t.setAttribute("xmlns",e);const s=document.createElementNS(e,"path");s.setAttribute("d","M7.99978 0.890625C4.07889 0.890625 0.888672 4.08085 0.888672 8.00174C0.888672 9.24262 1.21845 10.4693 1.83267 11.5315C2.04423 11.928 1.74823 13.3111 1.08423 13.9751C0.89845 14.1608 0.838894 14.4391 0.933116 14.6844C1.02734 14.9297 1.25756 15.0977 1.51978 15.112C1.59001 15.1155 1.66201 15.1173 1.73401 15.1173C2.75178 15.1173 3.98734 14.7555 4.79178 14.3431C5.39178 14.648 6.02734 14.8648 6.686 14.9902C7.11623 15.072 7.55889 15.1128 7.99978 15.1128C11.9207 15.1128 15.1109 11.9226 15.1109 8.00174C15.1109 4.08085 11.9207 0.890625 7.99978 0.890625ZM9.11089 10.224H5.11089C4.74289 10.224 4.44423 9.92529 4.44423 9.55729C4.44423 9.18929 4.74289 8.89062 5.11089 8.89062H9.11089C9.47889 8.89062 9.77756 9.18929 9.77756 9.55729C9.77756 9.92529 9.47889 10.224 9.11089 10.224ZM10.8887 7.11285H5.11089C4.74289 7.11285 4.44423 6.81418 4.44423 6.44618C4.44423 6.07818 4.74289 5.77951 5.11089 5.77951H10.8887C11.2567 5.77951 11.5553 6.07818 11.5553 6.44618C11.5553 6.81418 11.2567 7.11285 10.8887 7.11285Z"),s.setAttribute("fill","currentColor"),t.appendChild(s),this.node=t}}class Hn extends ie{constructor({x:t,...s},n){super(s);f(this,"_colors");this._colors=n.colorScheme.comments.scaleAnchor,this.state={x:t,y:n.layout.xAxis.top,isActive:!1},this.node.append(new Fn().node),this.render()}render(){const{x:t,y:s,isActive:n}=this.state;this.position({x:t,y:s});const a=n?"Active":"Inactive";this.node.style.backgroundColor=this._colors[`bg${a}`],this.node.style.color=this._colors[`icon${a}`]}}const ai=new ae("comment-box");class Bn extends ie{constructor({boxId:t,model:s,view:n,comments:a,coords:r,onBoxActivate:o,onBoxDeactivate:c}){super({className:ai.gen()});f(this,"pointer",new D({className:"sc-charts-cs__comments-pointer"}));f(this,"tooltip");f(this,"anchor");f(this,"_onBoxActivate");f(this,"_onBoxDeactivate");f(this,"_boxId");this._boxId=t,this._onBoxActivate=o,this._onBoxDeactivate=c,this.state={isActive:!1,comments:a,coords:r},this.pointer.position(r),this.anchor=new Hn({x:r.x,className:ai.gen("anchor")},s),this.anchor.node.addEventListener("click",()=>{const h=!this.state.isActive;h?this._onBoxActivate(this._boxId):this._onBoxDeactivate(this._boxId),this.setState({isActive:h})}),this.tooltip=dt(new Nn(a,s,n),h=>{this.state.isActive&&(this.anchor.node.contains(h.target)||(this._onBoxDeactivate(this._boxId),this.setState({isActive:!1})))}),this.append(this.pointer.node,this.anchor.node,this.tooltip.node),this.render()}render(){const{isActive:t,comments:s,coords:n}=this.state;this.pointer.position(n),this.pointer.setVisible(t),this.anchor.setState({x:n.x,isActive:t}),this.tooltip.setState({comments:s,isShow:t})}}class In{static animateTo(e,t,s,n){const a=e.scales.panOffsetX+(e.layout.area.width/2-t),r=e.scales.panOffsetY+(e.layout.area.height/2-s),o=300,c=performance.now(),h=e.scales.panOffsetX,u=e.scales.panOffsetY,g=_=>{const p=_-c,v=Math.min(p/o,1),b=v*v*(3-2*v),x=h+(a-h)*b,C=u+(r-u)*b;e.scales.pan("x",x,"absolute"),e.scales.pan("y",C,"absolute"),v<1?requestAnimationFrame(g):n==null||n()};requestAnimationFrame(g)}static animateToDataCoords(e,t,s,n){const a=typeof t=="number"?e.scales.x.convert(new Date(t)):e.scales.x.convert(t),r=e.scales.y.convert(s);this.animateTo(e,a,r,n)}}const gt=new ae("comments-context");class Rn extends ie{constructor(){super({className:gt.gen()});f(this,"pointer");f(this,"addField");f(this,"menu");f(this,"_size",null);f(this,"_model",null);f(this,"_candle",null);this.state={candle:null,isShow:!1,model:null},this.pointer=new D({className:gt.gen("pointer")}),this.menu=new D({className:gt.gen("menu")}),dt(this.menu,()=>{this.setState({isShow:!1})}),this.addField=new ni({blockName:"context-add",onAdd:t=>{!this._model||!this._candle||(this._model.comments.add({id:crypto.randomUUID(),text:t,date:this._candle.open_time.toISOString(),price:this._model.scales.y.invert((this._candle.open+this._candle.close)/2),createdAt:new Date().toISOString()}),this.setState({isShow:!1}))}}),this.menu.append(this.addField.node),this.append(this.pointer.node,this.menu.node)}_changeInputCorner(t){this.addField.input.node.style.borderTopLeftRadius=t==="right-bottom"?"0px":"12px",this.addField.input.node.style.borderBottomRightRadius=t==="left-top"?"0px":"12px",this.addField.input.node.style.borderBottomLeftRadius=t==="right-top"?"0px":"12px",this.addField.input.node.style.borderTopRightRadius=t==="left-bottom"?"0px":"12px"}render(){const{candle:t,isShow:s,model:n}=this.state;if(this.setVisible(s),!n||!t)return;this._model=n,this._candle=t;const a={x:n==null?void 0:n.scales.x.convert(t.open_time),y:n==null?void 0:n.scales.y.convert((t.open+t.close)/2)};this.pointer.position(a),this._size||(this.menu.position(a),this.menu.updateAbsolutePosition());const r=ct({size:this.menu.absolutePosition,parent:n.layout.area,offset:9,coords:a});this._changeInputCorner(r.side),this.menu.position(r.x,r.y)}}class $n extends Me{constructor(t){super("comments",t,{noCanvas:!0});f(this,"boxes",{});f(this,"contextMenu");f(this,"_view");if(!this.dom)throw new Error("[CS_V_Comments] this.dom must be defined");this.contextMenu=new Rn,this._view=t,t.domElements.append(this.contextMenu.node)}_getCandleCoords(t,s){return{x:t.scales.x.convert(s.open_time),y:t.scales.y.convert((s.open+s.close)/2)}}createBox({boxId:t,coords:s,model:n,comments:a}){const r=new Bn({boxId:t,model:n,comments:a,coords:s,view:this._view,onBoxActivate:o=>{const c=a[0].candle;In.animateToDataCoords(n,c.open_time,(c.open+c.close)/2),this.boxes[o].setState({isActive:!0})},onBoxDeactivate:o=>this.boxes[o].setState({isActive:!1})});this.boxes[t]=r,this.dom.append(r.node)}render(t){this.contextMenu.setState({model:t}),this.contextMenu.forceUpdate();const s=t.comments.grouped,n=new Set(Object.keys(s));Object.entries(s).forEach(([a,r])=>{const o=this._getCandleCoords(t,r[0].candle),c={boxId:a,coords:o,comments:r};this.boxes[a]?this.boxes[a].setState({comments:r,coords:o}):this.createBox({...c,model:t})}),Object.keys(this.boxes).forEach(a=>{n.has(a)||(this.boxes[a].node.remove(),delete this.boxes[a])})}}class On extends Se{constructor(e){super(e)}drawMarker({text:e,startLineCoords:t,endMarkerCoords:s,colors:n,type:a,side:r}){si(this.ctx,{text:e,colors:n,startLineCoords:t,endMarkerCoords:s,dir:a,side:r})}}class Pn extends Me{constructor(e){if(super("guides",e,{CanvasClass:On,noDOM:!0}),!this.canvas)throw new Error("[CS_V_Guides] Canvas must be defined")}render(e,{x:t,y:s}){if(this.canvas.clear(),e.config.guides.isShowY){const n=e.config.yAxis.position;this.canvas.drawMarker({text:e.scales.y.invert(s).toFixed(2),startLineCoords:{x:0,y:s},endMarkerCoords:{x:e.layout.yAxis[n],y:s},side:n,colors:e.colorScheme.guides.horizontalMarker,type:"h"})}if(e.config.guides.isShowX){const n=e.config.xAxis.position;this.canvas.drawMarker({text:k.timeFormat("%a %d, %b %y %H:%M")(e.scales.x.invert(t)),startLineCoords:{x:t,y:0},endMarkerCoords:{x:t,y:e.layout.xAxis[n]},side:n,colors:e.colorScheme.guides.verticalMarker,type:"v"})}}}class zn extends ie{constructor(t){super({className:t});f(this,"_isFirstShow",!1);const s=new D({tag:"p"});s.node.textContent="No data from broker",this.append(s.node),this.state={isShow:!1,x:0,y:0,parent:Y.empty()},this.render()}render(){const{isShow:t,x:s,y:n,parent:a}=this.state;t&&!this._isFirstShow&&(this.updateAbsolutePosition(),this._isFirstShow=!0),this.setVisible(t);const r=ct({size:this.absolutePosition,parent:a,coords:{x:s,y:n}});this.position(r.x,r.y)}}class Vn extends Se{constructor(t){super(t);f(this,"domain",null);f(this,"_getVisible",t=>{if(!this.domain)return[];const[s,n]=this.domain;return t.filter(a=>a.open_time>=s&&a.open_time<=n)})}drawSingleCandle({x:t,y:s,strokeWidth:n,width:a,colors:r,isDim:o}){this.ctx.fillStyle=this._mix(r.fill,r.bg,o),this.ctx.strokeStyle=this._mix(r.stroke,r.bg,o),this.ctx.lineWidth=n,this.ctx.beginPath(),this.ctx.moveTo(t,s.high),this.ctx.lineTo(t,s.low),this.ctx.stroke();const c=Math.min(s.open,s.close),h=Math.abs(s.close-s.open),u=t-a/2;this.ctx.fillRect(u,c,a,h),this.ctx.strokeRect(u,c,a,h)}drawCandles(t){const{colorScheme:{candles:s,bg:n},trade:{timeRange:a},candles:{missingData:r,preparedData:o},config:{candles:{hideMissingData:c}}}=t,h=t.config.candles.style==="filled";this.domain=t.scales.x.domain(),c||this._getVisible(r).forEach((u,g)=>{const _=s.noDataFill[g%s.noDataFill.length],p=h?_:s.noDataStroke;this.drawSingleCandle({...this._getBasicCandleProps(t,u),colors:{fill:_,stroke:p,bg:n}})}),this._getVisible(o).forEach(u=>{const g=u.close>=u.open?"rising":"falling",_=s[`${g}Fill`],p=s[`${g}${h?"Fill":"Stroke"}`];this.drawSingleCandle({...this._getBasicCandleProps(t,u),colors:{fill:_,stroke:p,bg:n},isDim:!!(a.length&&!a.includes(u.open_time.getTime()))})})}_mix(t,s,n){return n?A.mix(t,s).toString():t}_getBasicCandleProps(t,s){return{x:t.scales.x.convert(s.open_time),y:{open:t.scales.y.convert(s.open),close:t.scales.y.convert(s.close),high:t.scales.y.convert(s.high),low:t.scales.y.convert(s.low)},width:t.config.candles.baseWidth*t.scales.factorX,strokeWidth:t.config.candles.strokeWidth}}}class jn extends Me{constructor(t){super("candles",t,{CanvasClass:Vn});f(this,"_noDataTooltip",null);f(this,"limiter");if(!this.dom)throw new Error("[CS_V_Candles] this.dom must be defined");if(!this.canvas)throw new Error("[CS_V_Candles] this.canvas must be defined");this._noDataTooltip=new zn(this.cx("no-data")),this.limiter=new D({className:this.cx("limiter")}),this.limiter.setVisible(!1),this.dom.append(this._noDataTooltip.node,this.limiter.node)}get noDataTooltip(){return this._noDataTooltip}removeNoDataTooltip(){var t;(t=this._noDataTooltip)==null||t.remove(),this._noDataTooltip=null}render(t){this.canvas.clear(),this.canvas.drawCandles(t);const s=t.candles.allData[0];if(s){const{baseWidth:n,limiterOffset:a}=t.config.candles,r=t.scales.x.convert(s.open_time)-n/2-a.left-a.right,o=t.layout.area.height/2;this.limiter.node.style.height=t.layout.area.height+"px",this.limiter.setVisible(!0),this.limiter.position(r,o)}}}class Yn{constructor(e){f(this,"container");f(this,"width");f(this,"height");f(this,"wrapper");f(this,"domElements");f(this,"canvasesContainer");f(this,"mainCanvas");f(this,"binding");f(this,"userMarkers");f(this,"guideMarkers");f(this,"trade");f(this,"comments");f(this,"candles");this.container=e,this.wrapper=new D({tag:"div",className:"sc-charts-cs"}),e.append(this.wrapper.node);const{width:t,height:s}=e.getBoundingClientRect();this.width=t,this.height=s,this.mainCanvas=new Se({className:"sc-charts-cs__canvas-main",width:t,height:s,isMain:!0}),this.domElements=new D({tag:"div",className:"sc-charts-cs__dom-elements"}),this.canvasesContainer=new D({tag:"div",className:"sc-charts-cs__canvases"}),this.canvasesContainer.append(this.mainCanvas.node),this.wrapper.append(this.canvasesContainer.node,this.domElements.node),this.mainCanvas.updateAbsolutePosition(),this.binding=new Ds(this.mainCanvas.node),this.comments=new $n(this),this.candles=new jn(this),this.trade=new mn(this),this.guideMarkers=new Pn(this),this.userMarkers=new yn(this)}renderAll(e){this.mainCanvas.clear(),this.candles.render(e),ot.xAxis(this.mainCanvas.ctx,e),ot.yAxis(this.mainCanvas.ctx,e),ot.intersection(this.mainCanvas.ctx,e),this.trade.renderAll(e),this.userMarkers.render(e),this.comments.render(e)}}class Wn{constructor(e){f(this,"logColors",{init_model:"color: green",scale_event:"color: orange",update_config:"color: blue",update_candles:"color: purple",update_trade:"color: red",update_user_markers:"color: brown",update_color_scheme:"color: teal"});f(this,"ignoredLogEvents",[]);e&&(this.ignoredLogEvents=e)}log(e,t){if(this.ignoredLogEvents.includes(e))return;const s=this.logColors[e]||"color: gray";let n;try{n=JSON.parse(JSON.stringify(t))}catch{n=t}console.log(`%c[SUBSCRIBE] ${e}`,s,n)}}class Xn{constructor(e,t){f(this,"_model");f(this,"_view");f(this,"_enableLogging");f(this,"_logger");this._model=e,this._view=t,this._enableLogging=!1,this._logger=new Wn(["scale_event"])}subscribeWithLogging(e,t){const s=n=>{this._enableLogging&&this._logger.log(e,n),t(n)};this._model.subscribe(e,s)}init(){this.subscribeWithLogging("init_model",()=>{this._model.config.candles.hideMissingData&&this._view.candles.removeNoDataTooltip(),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("scale_event",()=>{this._model.userMarkers.rebuild(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_config",e=>{this._model.config.update(e),this._model.layout.updateConfig(this._model.config),this._model.userMarkers.rebuild(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_candles",e=>{this._model.candles.update(e),this._model.scales.reinit(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_trade",e=>{this._model.trade.updateTrade(e),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_user_markers",e=>{this._model.userMarkers.updateMarkers(e),this._view.userMarkers.render(this._model)}),this.subscribeWithLogging("update_color_scheme",e=>{this._model.colorScheme.update(e),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("open_trade_label_tooltip",({trade:e,x:t,y:s})=>{this._model.trade.setActiveTrade(e.tradeType,e.candle.open_time.getTime()),this._view.trade.renderAll(this._model),this._model.config.trade.showLabelButtons&&(this._view.trade.labelTooltip.updateContent(e.trades),this._view.trade.labelTooltip.setState({isShow:!0,x:t,y:s,parent:this._model.layout.area}))}),this.subscribeWithLogging("close_trade_label_tooltip",()=>{this._model.trade.setActiveTrade(null),this._view.trade.renderAll(this._model),this._view.trade.labelTooltip.setState({isShow:!1})}),this.subscribeWithLogging("hover_nodata_candle",({x:e,y:t})=>{var s;(s=this._view.candles.noDataTooltip)==null||s.setState({isShow:!0,x:e,y:t,parent:this._model.layout.area})}),this.subscribeWithLogging("leave_nodata_candle",()=>{var e;(e=this._view.candles.noDataTooltip)==null||e.setState({isShow:!1})}),this.subscribeWithLogging("mouseover_trade_label_tooltip",e=>{this._model.trade.setHoveredTrade(e.tradeType,e.candle.open_time.getTime()),this._view.trade.renderAll(this._model)}),this.subscribeWithLogging("mouseleave_trade_label_tooltip",()=>{this._model.trade.setHoveredTrade(null),this._view.trade.renderAll(this._model)}),this.subscribeWithLogging("update_comments",e=>{this._model.comments.data=e,this._view.renderAll(this._model)})}}class ri{constructor(){f(this,"_map",new Map)}add(e,t,s){let n=this._map.get(e);n||(n={},this._map.set(e,n)),n[t]||(n[t]=new Set),n[t].add(s)}remove(e,t,s){var a;const n=this._map.get(e);(a=n==null?void 0:n[t])==null||a.delete(s)}removeAll(e){this._map.delete(e)}emit(e,t){const s=this._map.get(e),n=s==null?void 0:s[t.type];if(!n)return!1;let a=!1;const r={...t,stopPropagation:()=>{a=!0}};for(const o of n)if(o(r),a)break;return a}}class Un{constructor(){f(this,"_elements",[]);f(this,"_listeners",new ri);f(this,"_lastHovered",new Set);f(this,"_dragContext",null)}get isDragging(){return this._dragContext!==null}register(...e){this._elements.push(...e)}unregister(e){this._elements=this._elements.filter(t=>t!==e),this._listeners.removeAll(e),this._lastHovered.delete(e)}clear(){this._elements=[],this._listeners=new ri,this._lastHovered.clear()}on(e,t,s){this._listeners.add(e,t,s)}off(e,t,s){this._listeners.remove(e,t,s)}dispatchMouseMove(e,t){if(this._dragContext){this._emitSingle(this._dragContext.target,{type:"drag",target:this._dragContext.target,x:e,y:t,prevX:this._dragContext.lastX,prevY:this._dragContext.lastY}),this._dragContext.lastX=e,this._dragContext.lastY=t;return}const s=this._getHitsAt(e,t),n=new Set(s.map(a=>a.target));for(const a of s)if(!this._lastHovered.has(a.target)&&this._emitSingle(a.target,{type:"mouseover",target:a.target,x:a.x,y:a.y})||this._emitSingle(a.target,{type:"mousemove",target:a.target,x:a.x,y:a.y}))break;for(const a of this._lastHovered)n.has(a)||this._emitSingle(a,{type:"mouseleave",target:a,x:e,y:t});this._lastHovered=n}dispatchMouseDown(e,t){const s=this._getHitsAt(e,t);if(s.length===0){this._dragContext=null;return}this._dragContext=null;for(const n of s)if(this._emitSingle(n.target,{type:"mousedown",target:n.target,x:n.x,y:n.y})){this._dragContext={target:n.target,lastX:e,lastY:t};break}!this._dragContext&&s.length>0&&(this._dragContext={target:s[s.length-1].target,lastX:e,lastY:t})}dispatchMouseUp(e,t){this._dragContext&&this._emitSingle(this._dragContext.target,{type:"mouseup",target:this._dragContext.target,x:e,y:t}),this._dragContext=null}dispatchClick(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"click",target:n.target,x:n.x,y:n.y}))break}dispatchDblClick(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"dblclick",target:n.target,x:n.x,y:n.y}))break}dispatchContextMenu(e,t){const s=this._getHitsAt(e,t);for(const n of s)if(this._emitSingle(n.target,{type:"contextmenu",target:n.target,x:n.x,y:n.y}))break}dispatchWheel(e,t,s,n,a){const r=this._getHitsAt(e,t);for(const o of r)if(this._emitSingle(o.target,{type:"wheel",target:o.target,x:o.x,y:o.y,deltaX:s,deltaY:n,deltaZ:a}))break}hitTestAll(e,t){return this._getHitsAt(e,t)}_getHitsAt(e,t){return this._elements.map(s=>s.hitTest(e,t)).filter(s=>s!==null)}_emitSingle(e,t){let s=!1;const n={...t,stopPropagation(){s=!0}};return this._listeners.emit(e,n),s}}class Gn{constructor(e){this.model=e}hitTest(e,t){const{candles:{missingData:s},scales:{x:n,y:a},config:{candles:{baseWidth:r}}}=this.model;for(const o of s){const c=n.convert(o.open_time),h=a.convert(o.high),u=a.convert(o.low),g=c-r/2,_=c+r/2,p=Math.min(h,u),v=Math.max(h,u);if(e>=g&&e<=_&&t>=p&&t<=v)return{target:this,x:e,y:t,type:"candle",candle:o}}return null}}class Zn{constructor(e,t){f(this,"_model");f(this,"_hitManager");f(this,"_hit");this._model=e,this._hitManager=t,this._hit=new Gn(e),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mouseover",e=>{const t=this._hit.hitTest(e.x,e.y);if(!t)return;const s=this._model.scales.x.convert(t.candle.open_time),n=this._model.scales.y.convert(t.candle.high)-4;this._model.eventBus.emit("hover_nodata_candle",{x:s,y:n})}),this._hitManager.on(this._hit,"mouseleave",()=>{this._model.eventBus.emit("leave_nodata_candle")})}}class qn{constructor(e){this.model=e}hitTest(e,t){const{tradedCandles:s}=this.model.trade,{x:n,y:a}=this.model.scales,r=16,o=4;for(const{candle:c,trades:h}of s){const g=n.convert(c.open_time)+this.model.config.candles.baseWidth/2,_=r,p=r;for(const v of["buy","sell"]){const b=h.filter(w=>w.type===v);if(!b.length)continue;const x=v==="buy"?a.convert(c.low)+o+ze(r):a.convert(c.high)-o-r-ze(r),C=e>=g-_/2&&e<=g+_/2,y=t>=x&&t<=x+p;if(C&&y)return{target:this,type:"trade-label",tradeType:v,x:e,y:t,candle:c,trades:b}}}return null}}class Jn{constructor(e,t){f(this,"_model");f(this,"_hitManager");f(this,"_tradeLabelHit");this._model=e,this._hitManager=t,this._tradeLabelHit=new qn(e),this._hitManager.register(this._tradeLabelHit)}register(){this._hitManager.on(this._tradeLabelHit,"click",e=>{const t=this._tradeLabelHit.hitTest(e.x,e.y);if(!t)return;const s=this._model.scales.x.convert(t.candle.open_time),n=this._model.scales.y.convert(t.trades[0].type==="buy"?t.candle.low:t.candle.high),a=t.trades[0].type==="buy"?n+4+ze(16)+8:n-4-16-ze(16)+8;this._model.eventBus.emit("open_trade_label_tooltip",{trade:{candle:t.candle,trades:t.trades,tradeType:t.tradeType},x:s,y:a})}),this._hitManager.on(this._tradeLabelHit,"mouseover",e=>{const t=this._tradeLabelHit.hitTest(e.x,e.y);t&&this._model.eventBus.emit("mouseover_trade_label_tooltip",{candle:t.candle,trades:t.trades,tradeType:t.tradeType})}),this._hitManager.on(this._tradeLabelHit,"mouseleave",()=>{this._model.eventBus.emit("mouseleave_trade_label_tooltip")})}}class Qn{constructor(e){this.model=e}hitTest(e,t){const{xAxis:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"x-axis"}:null}}class Kn{constructor(e){this.model=e}hitTest(e,t){const{area:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"area"}:null}}class ea{constructor(e){this.model=e}hitTest(e,t){const{yAxis:s}=this.model.layout;return e>=s.x&&e<=s.x+s.width&&t>=s.y&&t<=s.y+s.height?{target:this,x:e,y:t,type:"y-axis"}:null}}function ta(i,e){let t={x:0,y:0},s=null;return n=>{Math.abs(n.x-t.x)<i&&Math.abs(n.y-t.y)<i||(t={x:n.x,y:n.y},s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{e(n),s=null}))}}function ia(i,e){let t=null;return s=>{const n=s.x-(s.prevX??s.x),a=s.y-(s.prevY??s.y);Math.abs(n)<i&&Math.abs(a)<i||(t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{e(s),t=null}))}}function mt(i,e){const{width:t}=e.candles.limiter.absolutePosition,s=i.config.candles.baseWidth,n=i.config.candles.limiterOffset.left+i.config.candles.limiterOffset.right,r=i.scales.x.convert(i.candles.allData[0].open_time)-t-s/2-n;r>0&&i.scales.pan("x",-r)}function pt(i){return i.candles.limiter.absolutePosition.width>0}class _t{constructor(e,t,s){f(this,"_model");f(this,"_hitManager");f(this,"_hit");this._model=e,this._hitManager=t,this._hit=s,t.register(s)}}class sa extends _t{constructor(t,s,n){super(t,s,new Qn(t));f(this,"_view");this._view=n}register(){this._hitManager.on(this._hit,"drag",t=>{const s=t.x-(t.prevX??t.x);this._model.scales.scale("x",-s),this._view&&pt(this._view)&&mt(this._model,this._view)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.scale("x",1,"absolute"),this._model.scales.pan("x",0,"absolute")})}}class na extends _t{constructor(e,t){super(e,t,new ea(e))}register(){this._hitManager.on(this._hit,"drag",e=>{const t=e.y-(e.prevY??e.y);this._model.scales.scale("y",-t)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.fitYToVisibleCandles()})}}class aa extends _t{constructor(t,s,n){super(t,n,new Kn(t));f(this,"_view");this._view=s}register(){this._hitManager.on(this._hit,"mousemove",ta(1,t=>{this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"mouseleave",()=>{this._view.guideMarkers.canvas.clear()}),this._hitManager.on(this._hit,"drag",ia(1,t=>{this._model.scales.pan("x",t.x-(t.prevX??t.x)),pt(this._view)&&mt(this._model,this._view),this._model.scales.pan("y",t.y-(t.prevY??t.y)),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"contextmenu",({x:t})=>{const s=this._model.scales.x.invert(t),n=rt.findByDate(s,this._model.candles.allData);n&&(this._view.comments.contextMenu.setState({isShow:!0,candle:n}),this._view.comments.render(this._model))}),this._hitManager.on(this._hit,"wheel",t=>{var a,r;if(!t.deltaY)return;const s=-t.deltaY,n=(r=(a=this._model.config)==null?void 0:a.candles)==null?void 0:r.zoomOnWheel;["x","both"].includes(n)&&(this._model.scales.scale("x",s),pt(this._view)&&mt(this._model,this._view)),["y","both"].includes(n)&&this._model.scales.scale("y",s)})}}class ra{constructor(e,t,s){f(this,"_hitManager");f(this,"_candlesHandler");f(this,"_tradeLabelsHandler");f(this,"_xAxisHandler");f(this,"_yAxisHandler");f(this,"_areaHandler");this._hitManager=s,this._candlesHandler=new Zn(e,this._hitManager),this._tradeLabelsHandler=new Jn(e,this._hitManager),this._xAxisHandler=new sa(e,this._hitManager,t),this._yAxisHandler=new na(e,this._hitManager),this._areaHandler=new aa(e,t,this._hitManager)}register(){this._candlesHandler.register(),this._tradeLabelsHandler.register(),this._xAxisHandler.register(),this._yAxisHandler.register(),this._areaHandler.register()}}class oa{constructor(e,t){f(this,"_model");f(this,"_view");f(this,"_subscriptionsManager");f(this,"_hitManager",new Un);f(this,"_boundMouseMove",this.onDocumentMouseMove.bind(this));f(this,"_boundMouseUp",this.onDocumentMouseUp.bind(this));this._model=e,this._view=t,this._subscriptionsManager=new Xn(e,t)}init(){this._subscriptionsManager.init(),this._model.init(),this._view.binding.mousemove(this.onMouseMove.bind(this)),this._view.binding.mousedown(this.onMouseDown.bind(this)),this._view.binding.mouseup(this.onMouseUp.bind(this)),this._view.binding.wheel(this.onWheel.bind(this)),this._view.binding.mouseleave(this.onMouseLeave.bind(this)),this._view.binding.dblclick(this.onDoubleClick.bind(this)),this._view.binding.contextmenu(this.onContextMenu.bind(this)),window.addEventListener("scroll",this.onWindowScroll.bind(this),{passive:!0}),document.addEventListener("click",this.onDocumentClick.bind(this)),new ra(this._model,this._view,this._hitManager).register()}onContextMenu(e){e.preventDefault();const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchContextMenu(t,s)}onWindowScroll(){this._view.mainCanvas.updateAbsolutePosition()}onMouseLeave(){this._hitManager.isDragging||(this._hitManager.dispatchMouseMove(-1/0,-1/0),document.removeEventListener("mousemove",this._boundMouseMove),document.removeEventListener("mouseup",this._boundMouseUp))}onDoubleClick(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchDblClick(t,s)}onDocumentClick(e){const t=this.getMouseRelative(e);this._hitManager.dispatchClick(t.x,t.y),!this._hitManager.hitTestAll(t.x,t.y).find(n=>n.type==="trade-label")&&this._model.trade.hasActiveTrade&&this._model.eventBus.emit("close_trade_label_tooltip")}getMouseRelative(e){return{x:e.clientX-this._view.mainCanvas.absolutePosition.left,y:e.clientY-this._view.mainCanvas.absolutePosition.top}}onDocumentMouseMove(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseMove(t,s)}onMouseDown(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseDown(t,s),e.preventDefault(),document.addEventListener("mouseup",this._boundMouseUp),this._hitManager.isDragging&&document.addEventListener("mousemove",this._boundMouseMove)}onMouseUp(e){const t=this.getMouseRelative(e);this._hitManager.dispatchMouseUp(t.x,t.y),document.removeEventListener("mouseup",this._boundMouseUp)}onDocumentMouseUp(e){const{x:t,y:s}=this.getMouseRelative(e);this._hitManager.dispatchMouseUp(t,s),document.removeEventListener("mouseup",this._boundMouseUp),document.removeEventListener("mousemove",this._boundMouseMove)}onMouseMove(e){var a;if(!this._hitManager.isDragging){const{x:r,y:o}=this.getMouseRelative(e);this._hitManager.dispatchMouseMove(r,o)}const{x:t,y:s}=this.getMouseRelative(e),n=this._hitManager.hitTestAll(t,s);(a=n[0])!=null&&a.type&&(n[0].type==="area"?this._view.mainCanvas.node.style.cursor="crosshair":n[0].type==="trade-label"?this._model.config.trade.showLabelButtons&&(this._view.mainCanvas.node.style.cursor="pointer"):n[0].type==="x-axis"?this._view.mainCanvas.node.style.cursor="ew-resize":n[0].type==="y-axis"?this._view.mainCanvas.node.style.cursor="ns-resize":this._view.mainCanvas.node.style.cursor="default")}onWheel(e){e.preventDefault(),this._hitManager.dispatchWheel(e.offsetX,e.offsetY,e.deltaX,e.deltaY,e.deltaZ)}}class la{constructor(e,{chartId:t,candles:s,config:n,trade:a,userMarkers:r,colorScheme:o,comments:c,renderLimiter:h}){f(this,"_model");f(this,"_view");f(this,"_controller");f(this,"_candlesLimiterClean");const u=document.querySelector(e);if(!u)throw new Error(`Element with selector "${e}" not found!`);if(!t||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t))throw new Error("chartId is required and must be a valid id (only letters, numbers or underscores. The first character must be a letter)");if(this._model=new Ss({chartId:t,candles:s,config:n,container:u,trade:a,userMarkers:r,colorScheme:o,comments:c}),this._view=new Yn(u),this._controller=new oa(this._model,this._view),h){const g=h(this._view.candles.limiter.node);this._view.candles.limiter.updateAbsolutePosition(),typeof g=="function"&&(this._candlesLimiterClean=g)}this._controller.init()}destroy(){var e;(e=this._candlesLimiterClean)==null||e.call(this)}updateConfig(e){this._model.updateConfig(e)}updateTrade(e){this._model.updateTrade(e)}updateUserMarkers(e){this._model.updateUserMarkers(e)}updateColorScheme(e){this._model.updateColorScheme(e)}updateCandles(e){this._model.updateCandles(e)}updateComments(e){this._model.updateComments(e)}async _drawHeader(e,t,s,n=!1){const a=48*s,r=12*s,o=20*s,c=103*s;e.fillStyle=n?"#101011":"#FFFFFF",e.fillRect(0,0,t,a),e.strokeStyle=n?"#3E3E3E":"#EDEDED",e.lineWidth=1*s,e.beginPath(),e.moveTo(0,a),e.lineTo(t,a),e.stroke();const h=n?"#FFFFFF":"#1C2026",u=`<svg width="103" height="20" viewBox="0 0 103 20" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M92.6267 1.50666H93.0475C93.3792 1.50666 93.6025 1.31028 93.6025 1.02537C93.6025 0.740457 93.4034 0.561783 93.0426 0.561783C92.706 0.561783 92.4827 0.759773 92.4633 1.06239H91.795C91.8209 0.423351 92.3225 0.00805664 93.075 0.00805664C93.8274 0.00805664 94.2886 0.376671 94.2886 0.928788C94.2886 1.35213 93.9973 1.65797 93.5717 1.73523V1.74972C94.0895 1.79318 94.4229 2.10385 94.4229 2.58192C94.4229 3.20164 93.8581 3.61372 93.0572 3.61372C92.2562 3.61372 91.761 3.18555 91.7271 2.54973H92.4212C92.4423 2.84108 92.6834 3.03263 93.0652 3.03263C93.4471 3.03263 93.6834 2.82981 93.6834 2.53685C93.6834 2.22135 93.4455 2.0298 93.0539 2.0298H92.6251V1.50827L92.6267 1.50666Z" fill="${h}"/>
4
+ <path d="M95.1182 2.97623C94.9256 2.68488 94.8269 2.29373 94.8269 1.83498C94.8269 0.692113 95.3852 0.00317383 96.2816 0.00317383C96.9434 0.00317383 97.4596 0.392714 97.5567 0.957708H96.8431C96.7735 0.727525 96.5502 0.574607 96.2784 0.574607C95.7945 0.574607 95.5017 1.03658 95.5178 1.81566H95.5324C95.6716 1.47763 96.013 1.25389 96.4564 1.25389C97.1149 1.25389 97.6036 1.73679 97.6036 2.39192C97.6036 3.10179 97.0486 3.61205 96.2719 3.61205C95.7735 3.61205 95.3625 3.3867 95.1198 2.97623H95.1182ZM96.8949 2.41446C96.8949 2.05872 96.6279 1.79796 96.2654 1.79796C95.903 1.79796 95.6311 2.05872 95.6311 2.40802C95.6311 2.75732 95.9078 3.0374 96.2638 3.0374C96.6198 3.0374 96.8965 2.76215 96.8965 2.41607L96.8949 2.41446Z" fill="${h}"/>
5
+ <path d="M97.998 1.79961C97.998 0.68411 98.5336 0 99.4026 0C100.272 0 100.804 0.6825 100.804 1.79639C100.804 2.91028 100.275 3.60727 99.4026 3.60727C98.5304 3.60727 97.998 2.91672 97.998 1.798V1.79961ZM100.066 1.79961C100.066 1.01892 99.8136 0.579481 99.4026 0.579481C98.9916 0.579481 98.7359 1.02214 98.7359 1.79961C98.7359 2.57708 98.9883 3.0294 99.4026 3.0294C99.8168 3.0294 100.066 2.58674 100.066 1.79961Z" fill="${h}"/>
6
+ <path d="M101.137 0.809958C101.137 0.381786 101.469 0.048584 101.901 0.048584C102.333 0.048584 102.666 0.381786 102.666 0.809958C102.666 1.23813 102.331 1.57294 101.901 1.57294C101.47 1.57294 101.137 1.23974 101.137 0.809958ZM102.249 0.809958C102.249 0.616798 102.097 0.46066 101.902 0.46066C101.708 0.46066 101.556 0.616798 101.556 0.809958C101.556 1.00312 101.715 1.16087 101.902 1.16087C102.1 1.16087 102.249 0.998289 102.249 0.809958Z" fill="${h}"/>
7
+ <path d="M42.5486 0.0388184C37.204 0.0388184 33.5098 3.06983 33.5098 7.50447C33.5098 11.9391 37.204 15.02 42.5486 15.02C47.8933 15.02 51.5018 11.9375 51.5018 7.49803C51.5018 3.05856 47.8642 0.0388184 42.5486 0.0388184ZM42.5486 12.2836C39.0227 12.2836 36.5519 10.3327 36.5519 7.4771C36.5519 4.62155 39.0179 2.78331 42.5486 2.78331C46.0794 2.78331 48.4613 4.67789 48.4613 7.4771C48.4613 10.2763 45.9872 12.2787 42.5486 12.2787V12.2852V12.2836Z" fill="${h}"/>
8
+ <path d="M10.4321 6.17332H5.62948C2.78642 6.17332 2.01943 2.78013 7.93208 2.78013C10.4337 2.78013 12.3949 3.85539 13.2476 4.41878L14.7833 2.10085C13.3318 0.827603 10.7751 0.0356445 7.90457 0.0356445C-1.589 0.0356445 -1.70389 8.85825 5.65861 8.85825H10.4903C13.6166 8.85825 14.1279 12.2804 7.93208 12.2804C4.83336 12.2804 2.38836 10.6402 1.53561 10.0172L0 12.3367C1.45146 13.6084 4.51944 15.0217 7.95797 15.0217C17.9062 15.0152 18.0211 6.17171 10.4321 6.17171V6.17332Z" fill="${h}"/>
9
+ <path d="M26.0314 12.2771C22.3939 12.2771 20.0346 10.3262 20.0346 7.527C20.0346 4.72779 22.3648 2.7817 26.0023 2.7817C28.0784 2.7817 30.0104 3.85696 31.1755 4.93061L32.9166 2.52737C31.2677 1.22836 28.737 0.0388184 26.0088 0.0388184C20.5508 0.0388184 16.999 3.09397 16.999 7.53344C16.999 11.9729 20.6042 15.02 26.0654 15.02C28.8502 15.02 31.381 13.7757 33.0282 12.4751L31.2386 10.1266C30.0687 11.2067 28.135 12.2771 26.0314 12.2771Z" fill="${h}"/>
10
+ <path d="M80.9771 0.0372542C75.8605 0.0372542 72.3071 3.09241 72.3071 7.53188C72.3071 11.9714 76.3719 15.0185 81.9156 15.0185C84.8428 15.0185 87.2829 14.0575 88.8218 12.7569L87.0289 10.4148C85.9771 11.5464 84.2732 12.3657 81.8849 12.3657C78.558 12.3657 76.1874 10.9814 75.5013 8.85986H89.592V7.5013C89.5872 3.06182 86.092 0.0356445 80.9755 0.0356445L80.9771 0.0372542ZM80.948 2.69482C83.8768 2.69482 85.88 4.06787 86.4075 6.25702H75.4447C75.9884 4.08718 77.9722 2.69482 80.948 2.69482Z" fill="${h}"/>
11
+ <path d="M62.7358 0.0372542C60.1921 0.0372542 58.1743 0.925792 56.7875 2.29562C56.4283 1.16563 55.4364 0.462207 54.0917 0.462207H52.2471V3.14875H53.951V20.0004H56.9364V12.8792C58.3151 14.1782 60.273 15.0233 62.739 15.0233C67.485 15.0233 70.7536 11.9408 70.7536 7.5013C70.7536 3.06182 67.4802 0.0356445 62.7342 0.0356445L62.7358 0.0372542ZM62.3652 12.2756C59.1241 12.2756 56.9364 10.3247 56.9364 7.4691C56.9364 4.61355 59.1241 2.7753 62.3652 2.7753C65.6064 2.7753 67.7099 4.66989 67.7099 7.4691C67.7067 10.3311 65.464 12.2756 62.3652 12.2756Z" fill="${h}"/>
12
+ </svg>`;try{const g=await this._loadSvgAsImage(u);g&&e.drawImage(g,r,(a-o)/2,c,o)}catch(g){console.warn("Failed to load logo SVG:",g)}}_drawHeaderSecondLine(e,t,s,n,a,r,o=!1){const c=20*r,h=12*r,u=8*r;e.fillStyle=o?"#292929":"#FFFFFF",e.fillRect(0,a,n,c),e.strokeStyle=o?"#3E3E3E":"#EDEDED",e.lineWidth=1*r,e.beginPath(),e.moveTo(0,a+c),e.lineTo(n,a+c),e.stroke(),e.fillStyle=o?"#C3C3C5":"#1C2026",e.font=`500 ${u}px Geist, Arial, sans-serif`,e.textBaseline="middle",e.textAlign="left";const g=t?`${t} created with Scope360, ${s}`:`Scope360, ${s}`;e.fillText(g,h,a+c/2)}_loadSvgAsImage(e){return new Promise((t,s)=>{const n=new Image,a=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(a);n.onload=()=>{URL.revokeObjectURL(r),t(n)},n.onerror=()=>{URL.revokeObjectURL(r),s(new Error("Failed to load SVG"))},n.src=r})}_drawFooter(e,t,s,n,a,r,o=!1){const c=32*r,h=12*r,u=12*r,g=4*r,_=n+a;e.fillStyle=o?"#292929":"#FFFFFF",e.fillRect(0,_,s,c),e.strokeStyle=o?"#3E3E3E":"#EDEDED",e.lineWidth=1*r,e.beginPath(),e.moveTo(0,_),e.lineTo(s,_),e.stroke(),e.textBaseline="middle",e.textAlign="left";const p=[];if(t.pair&&p.push({label:"",value:t.pair}),t.net_pnl!==void 0){const w=t.net_pnl.startsWith("+");p.push({label:"Net P&L",value:t.net_pnl,valueColor:w?"#56B683":"#F18169"})}t.type&&p.push({label:"Type",value:t.type}),t.entry_price&&p.push({label:"Entry",value:t.entry_price}),t.exit_price&&p.push({label:"Exit",value:t.exit_price}),t.open_date&&p.push({label:"Open date",value:t.open_date}),t.close_date&&p.push({label:"Close date",value:t.close_date}),t.holdtime&&p.push({label:"Holdtime",value:t.holdtime}),t.rr&&p.push({label:"RR",value:t.rr}),t.volume&&p.push({label:"Volume",value:t.volume});const v=_+c/2,b=24*r;if(p.length===0)return;e.font=`500 ${u}px Geist, Arial, sans-serif`;const x=o?"#878788":"#8E8E93",C=o?"#FAFAFA":"#1C2026";let y=h;p.forEach(w=>{const M=e.measureText(w.label).width,L=e.measureText(w.value).width,R=M+g+L;e.fillStyle=x,e.font=`500 ${u}px Geist, Arial, sans-serif`,e.fillText(w.label,y,v);const $=y+M+g;e.fillStyle=w.valueColor||C,e.font=`500 ${u}px Geist, Arial, sans-serif`,e.fillText(w.value,$,v),y+=R+b})}async captureScreenshot(e={}){const t=typeof e=="string"?e:e.filename||"candlestick-chart.png",n=new Date().toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",timeZoneName:"short"}),a=typeof e=="object"?e:{},r=a.createdBy,o=a.createdAt||n,c=a.trade,h=a.isDark||!1,{canvasesContainer:u,width:g,height:_}=this._view,p=Array.from(u.node.querySelectorAll("canvas"));if(p.length===0){console.warn("No canvas elements found for screenshot");return}const v=1440,b=900,x=48,C=20,y=c?32:0,w=b-x-C-y,M=v,L=g/_,R=M/w;let $,O,se=0,U=0;L>R?(O=w,$=O*L,se=0,U=0):($=M,O=$/L,U=(w-O)/2);const P=window.devicePixelRatio||1,G=document.createElement("canvas");G.width=v*P,G.height=b*P;const J=G.getContext("2d");if(!J){console.error("Failed to get 2D context for merged canvas");return}J.fillStyle=h?"#101011":"#ffffff",J.fillRect(0,0,G.width,G.height);const We=x*P,vt=C*P,ce=w*P,ke=M*P,De=We+vt;await this._drawHeader(J,G.width,P,h),this._drawHeaderSecondLine(J,r,o,G.width,We,P,h);const Xe=this._view.mainCanvas;Xe.background&&(J.fillStyle=Xe.background,J.fillRect(0,De,G.width,ce));const Ue=$*P,Ge=O*P,bt=se*P,N=U*P;p.forEach(z=>{let _e=0,Q=0,K=z.width,re=z.height,Ee=Ue,ve=Ge,Le=bt,Ne=N;if(L>R){const he=Ge/z.height,de=z.width*he;de>ke&&(_e=(de-ke)/he,K=z.width-_e,Ee=ke,Le=0)}else{const he=Ue/z.width,de=z.height*he;if(de>ce){const Fe=(de-ce)/he;Q=Fe/2,re=z.height-Fe,ve=ce,Ne=0}}J.drawImage(z,_e,Q,K,re,Le,De+Ne,Ee,ve)}),c&&this._drawFooter(J,c,G.width,De,ce,P,h),G.toBlob(async z=>{if(!z){console.error("Failed to create blob from canvas");return}try{await navigator.clipboard.write([new ClipboardItem({"image/png":z})])}catch{const Q=URL.createObjectURL(z),K=document.createElement("a");K.href=Q,K.download=t,document.body.appendChild(K),K.click(),document.body.removeChild(K),URL.revokeObjectURL(Q)}},"image/png",1)}}V.CandlestickChart=la,V.createLineChart=ss,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
13
13
  //# sourceMappingURL=charts-core.umd.cjs.map