charts-core 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts-core.css +1 -1
- package/dist/charts-core.js +1833 -1842
- package/dist/charts-core.js.map +1 -1
- package/dist/charts-core.umd.cjs +2 -3
- package/dist/charts-core.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/charts-core.umd.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
(function($,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("d3")):typeof define=="function"&&define.amd?define(["exports","d3"],O):($=typeof globalThis<"u"?globalThis:$||self,O($.ChartsCore={},$.d3))})(this,function($,O){"use strict";var ca=Object.defineProperty;var ha=($,O,nt)=>O in $?ca($,O,{enumerable:!0,configurable:!0,writable:!0,value:nt}):$[O]=nt;var c=($,O,nt)=>ha($,typeof O!="symbol"?O+"":O,nt);function nt(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const D=nt(O),ns=s=>{const{svg:t,config:e,y:i,width:n}=s,{margin:r,yAxis:a}=e,{customTicks:l,tickFormat:h,tickValues:d,ticks:g,isShow:_}=a;if(!_)return null;t.append("g").attr("transform",`translate(${n-r.right},0)`).call(m=>{let p=D.axisRight(i);l&&h?p=p.tickFormat(h):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)}),l&&g&&(p=Array.isArray(g)?p.ticks(...g):p.ticks(g)),l&&d&&(p=p.tickValues(d)),m.call(p)}).call(m=>{let p=[];m.selectAll(".tick").each(v=>p.push(v)),s.yTicks=p}).call(m=>m.select(".domain").remove()).call(m=>m.selectAll(".tick line").remove()).call(m=>{const p=m.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);m.selectAll(".tick").each(function(x,C){var z;const w=D.select(this),y=w.select("text"),T=v[C],E=b-T,N=w.append("g").attr("transform","translate(10, 0)");y.attr("x",E),y.remove(),(z=N.node())==null||z.appendChild(y.node())})}).attr("font-family","inherit")},rs=s=>{const{svg:t,config:e,x:i,height:n}=s,{margin:r,xAxis:a}=e,{isShow:l,tickValues:h,tickFormat:d,customTicks:g,ticks:_}=a;if(!l)return null;t.append("g").attr("transform",`translate(0,${n-r.bottom})`).call(m=>{let p=D.axisBottom(i);g?(d&&(p=p.tickFormat(d)),_&&(p=Array.isArray(_)?p.ticks(..._):p.ticks(_)),h&&(p=p.tickValues(h))):p.ticks(5),m.call(p)}).call(m=>m.select(".domain").remove()).call(m=>{let p=[];m.selectAll(".tick").each(v=>p.push(v)),s.xTicks=p}).call(m=>m.selectAll(".tick line").remove()).call(m=>m.selectAll(".tick text").classed("sc-charts__x-axis-tick",!0)).attr("font-family","inherit")},as=s=>{const{svg:t,config:e,y:i,width:n}=s,{margin:r,grid:{horizontalStyle:a}}=e;if(a!=="none"){if(a.startsWith("zero-line")){const l=t.append("line").attr("x1",0+r.left).attr("x2",n-r.right).attr("y1",i(0)).attr("y2",i(0)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);a==="zero-line-dashed"&&l.attr("stroke-dasharray","4 4")}a.startsWith("every-line")&&(s.yTicks||i.ticks()).forEach(h=>{const d=t.append("line").attr("x1",0+r.left).attr("x2",n-r.right).attr("y1",i(h)).attr("y2",i(h)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);a==="every-line-dashed"&&d.attr("stroke-dasharray","4 4")})}},os=s=>{const t=Array.from(s.childNodes);for(let e=0;e<t.length;e++)s.removeChild(t[e])},ls=s=>{const t="http://www.w3.org/2000/svg",e=document.createElement("div");e.className="sc-charts__hovered-circles-tooltip-container",e.style.display="none";const i=document.createElement("div");i.className="sc-charts__hovered-circles-tooltip";const n=document.createElement("div");n.className="sc-charts__hovered-circles-tooltip-arrow";const r=document.createElementNS(t,"svg");r.setAttribute("width","12"),r.setAttribute("height","4"),r.setAttribute("viewBox","0 0 12 4"),r.setAttribute("fill","none"),r.setAttribute("xmlns",t);const a=document.createElementNS(t,"path");return a.setAttribute("d","M6 4L0 0H12L6 4Z"),r.appendChild(a),n.appendChild(r),e.append(n),e.append(i),s.append(e),{tooltipContainer:e,tooltip:i,tooltipArrow:n}},cs=(s,t,{x:e,y:i,r:n=3.5,hr:r=0})=>{if(t)return s.append("image").attr("x",e-6).attr("y",i-6).attr("width",12).attr("height",12).attr("href","data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAxMyAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzE0NTJfNTAwOSkiPgo8cGF0aCBkPSJNNi41MzY0NiAxMS41Njg4QzkuMjA1ODYgMTEuNTY4OCAxMS4zNjk4IDkuNDA0ODMgMTEuMzY5OCA2LjczNTQzQzExLjM2OTggNC4wNjYwNiA5LjIwNTg2IDEuOTAyMSA2LjUzNjQ2IDEuOTAyMUMzLjg2NzA4IDEuOTAyMSAxLjcwMzEyIDQuMDY2MDYgMS43MDMxMiA2LjczNTQzQzEuNzAzMTIgOS40MDQ4MyAzLjg2NzA4IDExLjU2ODggNi41MzY0NiAxMS41Njg4WiIgZmlsbD0iI0ZDRUJFOSIvPgo8cGF0aCBkPSJNMy4xMTcxOSAxMC4xNTM1TDkuOTQ3MTkgMy4zMjM0OSIgc3Ryb2tlPSIjRjE4MTY5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHBhdGggZD0iTTYuNTM2NDYgMTEuNTY4OEM5LjIwNTg2IDExLjU2ODggMTEuMzY5OCA5LjQwNDgzIDExLjM2OTggNi43MzU0M0MxMS4zNjk4IDQuMDY2MDYgOS4yMDU4NiAxLjkwMjEgNi41MzY0NiAxLjkwMjFDMy44NjcwOSAxLjkwMjEgMS43MDMxMiA0LjA2NjA2IDEuNzAzMTIgNi43MzU0M0MxLjcwMzEyIDkuNDA0ODMgMy44NjcwOSAxMS41Njg4IDYuNTM2NDYgMTEuNTY4OFoiIHN0cm9rZT0iI0YxODE2OSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDBfMTQ1Ml81MDA5Ij4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC41MzUxNTYgMC43MzUzNTIpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==");{const a=s.append("g");return a.append("circle").attr("cx",e).attr("cy",i).attr("r",n).classed("sc-charts__hovered-circles",!0),a.append("circle").attr("cx",e).attr("cy",i).attr("r",n+r).classed("sc-charts__hovered-circles_add",!0),a}};function hs(s,t,e,i){if(!s)return null;const n=s.width/2,r=t-n,a=t+n;return r<e?e:a>i?i-s.width:t-n}const oe=(s,{x1:t,x2:e,y1:i,y2:n})=>s.append("line").attr("x1",t).attr("x2",e).attr("y1",i).attr("y2",n).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1),ds=s=>{const{svg:t,config:e,x:i,y:n,height:r,data:a,wrapperNode:l}=s,{margin:h,grid:{verticalStyle:d,tooltipNode:g,hoverCirclesRadius:_,hoverCirclesAdditionalArea:m}}=e;if(d!=="none"&&(d.startsWith("every-line")&&(s.xTicks||i.ticks()).forEach(v=>{const b=t.append("line").attr("x1",i(v)).attr("x2",i(v)).attr("y1",h.top).attr("y2",r-h.bottom).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);d==="every-line-dashed"&&b.attr("stroke-dasharray","4 4")}),d==="hovered-circles")){const p=n.range()[0],v=i(a[0].date),b=i(a[a.length-1].date);oe(t,{x1:v,x2:b,y1:p,y2:p});const{tooltipContainer:x,tooltip:C,tooltipArrow:w}=ls(l);a.forEach((y,T)=>{const E=i(y.date),N=n(y.value),z=a[T-1],G=T>0&&z&&y.value===z.value;G||oe(t,{x1:E,x2:E,y1:N,y2:p});const Vt=cs(t,G,{x:E,y:p,r:_,hr:m});g&&Vt.on("mouseover",function(){os(C),x.style.display="block",C.append(g({date:y.date,value:G?null:y.value}));const Gt=C.getBoundingClientRect(),Ut=hs(Gt,i(y.date),s.config.margin.left-s.config.grid.tooltipArrowSize,s.width-s.config.margin.right+s.config.grid.tooltipArrowSize);C.style.left=Ut+"px",w.style.left=i(y.date)+"px"}).on("mouseout",function(){x.style.display="none"})})}},us=s=>{as(s),ds(s)},gs=s=>{const{svg:t,config:e,width:i,height:n}=s,{margin:r,logo:a}=e;rs(s),ns(s),a&&t.append("image").attr("xlink:href",e.theme==="dark"?a.picDarkTheme:a.picLightTheme).attr("width",a.width).attr("height",a.height).attr("x",a.x??(i-r.left-r.right)/2-a.width/2+r.left).attr("y",a.y??(n-r.top-r.bottom)/2-a.height/2+r.top),us(s)},lt=(s,t,e)=>{let i=s.select(`#${t}`);return i.empty()&&(i=s.append("linearGradient").attr("gradientUnits","userSpaceOnUse").attr("id",t)),i.attr("x1",e.x1).attr("y1",e.x2).attr("x2",e.y1).attr("y2",e.y2),e.stops.forEach(({offset:n,stopColor:r})=>{i.append("stop").attr("offset",n).attr("stop-color",r)}),i},rt=s=>{const t=D.select(s).select("defs");return t.empty()?D.select(s).append("defs"):t},le=s=>{const{y:t,config:{margin:e}}=s,i=t.range()[0]-t(0),n=t.range()[0]-i>=0?t.range()[0]-i:0,r=i+e.bottom>=0?i+e.bottom:0;return{x:0,y:n,width:"100%",height:r}},ce=(s,t)=>({...s,...t,margin:{...s.margin,...t==null?void 0:t.margin},logo:s.logo&&(t!=null&&t.logo)?{width:t.logo.width??s.logo.width,height:t.logo.height??s.logo.height,picLightTheme:t.logo.picLightTheme??s.logo.picLightTheme,picDarkTheme:t.logo.picDarkTheme??s.logo.picDarkTheme,x:t.logo.x??s.logo.x,y:t.logo.y??s.logo.y}:s.logo,xAxis:{...s.xAxis,...t==null?void 0:t.xAxis},yAxis:{...s.yAxis,...t==null?void 0:t.yAxis},grid:{...s.grid,...t==null?void 0:t.grid},hover:{...s.hover,...t==null?void 0:t.hover},selection:{...s.selection,...t==null?void 0:t.selection}}),he=(s,t={})=>{const e=s.node(),i=rt(e),n=(l,h)=>lt(i,l,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"20%",stopColor:h},{offset:"60%",stopColor:h},{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 r="sc-charts__border-range-line",a=s.append("line").classed(r,!0).style("display",t.hidden?"none":"block");return{className(l,h){l==="remove"?a.classed(`${r}${h}`,!1):a.classed(`${r}${h}`,!0)},update({x1:l,x2:h,y1:d,y2:g,hidden:_}){l!==void 0&&a.attr("x1",l),h!==void 0&&a.attr("x2",h),d!==void 0&&a.attr("y1",d),g!==void 0&&a.attr("y2",g),_!==void 0&&a.style("display",_?"none":"block")},destroy(){a.remove()}}},Bt=(s,t={})=>{const e=s.append("circle").attr("r",t.radius||4).style("display",t.hidden?"none":"block"),i=t.className||"";return i&&e.classed(i,!0),{className(n,r){n==="remove"?e.classed(`${i}${r}`,!1):e.classed(`${i}${r}`,!0)},update({cx:n,cy:r,hidden:a,fill:l}){n!==void 0&&e.attr("cx",n),r!==void 0&&e.attr("cy",r),l!==void 0&&e.attr("fill",l),a!==void 0&&e.style("display",a?"none":"block")},destroy(){e.remove()}}},_s=(s,t={})=>{const e="sc-charts__hover-line",i=s.append("line").style("display",t.hidden?"none":"block").classed(e,!0),n=s.node(),r=rt(n);return((l,h)=>lt(r,l,{x1:"0%",y1:"0%",x2:"0%",y2:"100%",stops:[{offset:"0%",stopColor:"rgba(255, 255, 255, 0)"},{offset:"15%",stopColor:h},{offset:"75%",stopColor:h},{offset:"100%",stopColor:"rgba(255, 255, 255, 0)"}]}))("hover-line-gradient","var(--sc-color-hover-line)"),{className(l,h){l==="remove"?i.classed(`${e}${h}`,!1):i.classed(`${e}${h}`,!0)},update({x1:l,x2:h,y1:d,y2:g,hidden:_}){l!==void 0&&i.attr("x1",l),h!==void 0&&i.attr("x2",h),d!==void 0&&i.attr("y1",d),g!==void 0&&i.attr("y2",g),_!==void 0&&i.style("display",_?"none":"block")},destroy(){i.remove()}}},K="sc-charts__range-tooltip",de=D.timeFormat("%b %e, %I:%M %p"),fs=s=>{const t=D.format(",.2f");return`${s<0?"-":""}$${t(Math.abs(s))}`};function ms(s){const t="http://www.w3.org/2000/svg",e=document.createElement("div");e.className=K,e.style.position="absolute",e.style.top="0",e.style.pointerEvents="none",e.style.display="none",s.append(e);const i=document.createElement("div");i.className=`${K}-container`,e.append(i);const n=document.createElement("div");n.className=`${K}-sum`,i.append(n);const r=document.createElement("div");r.className=`${K}-sum-icon`;const a=document.createElementNS(t,"svg");a.setAttribute("width","14"),a.setAttribute("height","14"),a.setAttribute("viewBox","0 0 14 14"),a.setAttribute("fill","none"),a.setAttribute("xmlns",t);const l=document.createElementNS(t,"path");l.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"),l.setAttribute("fill","currentColor"),a.appendChild(l),r.appendChild(a),n.append(r);const h=document.createElement("div");n.append(h);const d=document.createElement("div");return d.className=`${K}-time`,i.append(d),{wrapper:e,sumNode:h,timeNode:d}}const ps=s=>{const{wrapper:t,sumNode:e,timeNode:i}=ms(s.wrapperNode);return{className(n,r){n==="remove"?t.classList.remove(`${K}${r}`):t.classList.add(`${K}${r}`)},update({leftPoint:n,rightPoint:r,x:a,y:l,hidden:h,closest:d}){if(n&&r&&d&&a!==void 0){const g=r.value-n.value,{sumFormatter:_,timeFormatter:m}=s.config.selection,p=(s.x(r.date)+s.x(n.date))/2,v=s.x(d.date)<p?"left":"right";let b="",x="";if(_)b=_({left:n.value,right:r.value,direction:v});else{const C=(g/Math.abs(n.value)*100).toFixed(2);b=`${fs(g)} (${C}%)`}m?x=m({left:n.date,right:r.date,direction:v}):x=`${de(n.date)} to ${de(r.date)}`,e.textContent=b,i.textContent=x,requestAnimationFrame(()=>{const C=t.getBoundingClientRect(),w=s.wrapperNode.getBoundingClientRect(),y=s.x(n.date),T=s.x(r.date);let N=(y+T)/2-C.width/2;const z=0,G=w.width-C.width;N<z&&(N=z),N>G&&(N=G),t.style.left=`${N}px`,t.style.top=`${l}px`})}h!==void 0&&(t.style.display=h?"none":"block")},destroy(){t.remove()}}},ct="sc-charts__hover-tooltip",Ht=16,vs=D.timeFormat("%a, %b %d, %-I:%M %p"),bs=s=>{const t=D.format(",.2f");return`${s<0?"-":""}$${t(Math.abs(s))}`};function ys(s){const t=document.createElement("div");t.className=`${ct}-container`,t.style.position="absolute",t.style.top="0",t.style.pointerEvents="none",t.style.display="none",s.appendChild(t);const e=document.createElement("div");e.className=`${ct}-sum`,t.appendChild(e);const i=document.createElement("div");return i.className=`${ct}-time`,t.appendChild(i),{wrapper:t,sumNode:e,timeNode:i}}function xs(s,t,e){return s?t+Ht+s.width<e?t+Ht:t-Ht-s.width:null}const ws=s=>{const{wrapper:t,sumNode:e,timeNode:i}=ys(s.wrapperNode);return{className(n,r){n==="remove"?t.classList.remove(`${ct}${r}`):t.classList.add(`${ct}${r}`)},update({hidden:n,dataItem:r}){if(r){const{sumFormatter:a,timeFormatter:l}=s.config.hover;e.textContent=a?a(r.value):bs(r.value),i.textContent=l?l(r.date):vs(r.date),requestAnimationFrame(()=>{const h=t.getBoundingClientRect(),d=xs(h,s.x(r.date),s.width-s.config.margin.right);d&&(t.style.left=d+"px")})}n!==void 0&&(t.style.display=n?"none":"block")},destroy(){t.remove()}}},Cs={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},vt=s=>D.curveCardinal.tension(s.config.curveTension),Ms=s=>{const{svg:t,data:e,x:i,y:n,config:r}=s,a=t.node(),l=rt(a);lt(l,"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 d=D.area().x(m=>i(m.date)).y0(n.range()[0]).y1(m=>n(m.value)).curve(vt(s)),g="sc-charts__main-line-area",_=t.append("path").datum(e).attr("d",d).attr("class",g).classed(`${g}_hidden`,!r.hasMainLineArea);return{className(m,p){m==="remove"?_.classed(`${g}${p}`,!1):_.classed(`${g}${p}`,!0)},update({data:m,hidden:p}){if(m!==void 0&&_.datum(m).attr("d",d),p!==void 0){if(!r.hasMainLineArea)return null;_.classed(`${g}_hidden`,p)}},destroy(){_.remove()}}},As=(s,t={})=>{const e="sc-charts__range-line-area",{svg:i,x:n,y:r,config:a,data:l,chartId:h}=s,{clip:d}=t,g=i.node(),_=rt(g),m="range-line-area-gradient";lt(_,m+"_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)"}]}),lt(_,m+"_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=D.area().x(w=>n(w.date)).y0(r.range()[0]).y1(w=>r(w.value)).curve(vt(s)),v=`${h}-clip-${e}`,x=_.append("clipPath").attr("id",v).append("rect").attr("x",(d==null?void 0:d.x)||0).attr("y",(d==null?void 0:d.y)||0).attr("width",(d==null?void 0:d.width)||"100%").attr("height",(d==null?void 0:d.height)||"100%"),C=i.append("path").datum(l).attr("d",p).attr("class",e).classed(`${e}_hidden`,!a.hasMainLineArea).attr("clip-path",`url(#${v})`);return{className(w,y){w==="remove"?C.classed(`${e}${y}`,!1):C.classed(`${e}${y}`,!0)},update({data:w,hidden:y,clip:T}){w!==void 0&&C.datum(w).attr("d",p),y!==void 0&&C.classed(`${e}_hidden`,y),T!==void 0&&x.attr("x",T.x).attr("y",T.y).attr("width",T.width).attr("height",T.height)},destroy(){C.remove()}}},Rt=(s,t)=>{const{svg:e,data:i,x:n,y:r,chartId:a}=s,{baseClassName:l,id:h,clip:d}=t,g=e.node(),_=rt(g),m=D.line().x(C=>n(C.date)).y(C=>r(C.value)).curve(vt(s)),p=`${a}-clip-${l}`,b=_.append("clipPath").attr("id",p).append("rect").attr("x",(d==null?void 0:d.x)||0).attr("y",(d==null?void 0:d.y)||0).attr("width",(d==null?void 0:d.width)||"100%").attr("height",(d==null?void 0:d.height)||"100%"),x=e.append("path").classed(l,!0).datum(i).attr("d",m).attr("id",h).attr("clip-path",`url(#${p})`);return{className(C,w){C==="remove"?x.classed(`${l}${w}`,!1):x.classed(`${l}${w}`,!0)},update({data:C,clip:w,hidden:y}){C!==void 0&&x.datum(C).attr("d",m),y!==void 0&&x.classed(`${l}_hidden`,y),w!==void 0&&b.attr("x",w.x).attr("y",w.y).attr("width",w.width).attr("height",w.height)},destroy(){x.remove()}}},Ts=(s,t)=>{const{svg:e,data:i,x:n,y:r,chartId:a,config:l}=s,{baseClassName:h,id:d,clip:g}=t,_=e.node(),m=rt(_),p=D.line().x(w=>n(w.date)).y(w=>r(w.value)).curve(vt(s)),v=`${a}-clip-${h}`,x=m.append("clipPath").attr("id",v).append("rect").attr("x",(g==null?void 0:g.x)||0).attr("y",(g==null?void 0:g.y)||0).attr("width",(g==null?void 0:g.width)||"100%").attr("height",(g==null?void 0:g.height)||"100%"),C=e.append("path").classed(h,!0).datum(i).attr("d",p).attr("id",d).attr("clip-path",`url(#${v})`);return{className(w,y){w==="remove"?C.classed(`${h}${y}`,!1):C.classed(`${h}${y}`,!0)},update({data:w,clip:y,hidden:T}){w!==void 0&&C.datum(w).attr("d",p),T!==void 0&&C.classed(`${h}_hidden`,T),y!==void 0&&(l.hover.transitionName==="default"?x.transition().duration(l.hover.transitionDuration).attr("x",y.x).attr("y",y.y).attr("width",y.width).attr("height",y.height).ease(D.easeLinear):x.attr("x",y.x).attr("y",y.y).attr("width",y.width).attr("height",y.height))},destroy(){C.remove()}}},Ss=s=>{const t=Math.abs(s);let e;return t>=1e9?e=(s/1e9).toFixed(1)+"B":t>=1e6?e=(s/1e6).toFixed(1)+"M":t>=1e3?e=(s/1e3).toFixed(1)+"K":e=s.toFixed(1),e},ks=(s,t)=>{const{svg:e,data:i,x:n,y:r}=s,{baseClassName:a}=t,l=e.append("g").classed(a,!0),h=l.append("circle").attr("r",5).classed(`${a}-circle`,!0),d=l.append("text").attr("text-anchor","middle").attr("dy","-9px").classed(`${a}-label`,!0);return(_=>{if(!_||_.length===0)return;const m=_[_.length-1],p=n(m.date),v=r(m.value);h.attr("cx",p).attr("cy",v);const b=s.config.extremePointFormatter||Ss;d.attr("x",p).attr("y",v).text(b(m.value))})(i),{className(_,m){_==="remove"?l.classed(`${a}${m}`,!1):l.classed(`${a}${m}`,!0)},update({hidden:_}){_!==void 0&&l.classed(`${a}_hidden`,_)},destroy(){l.remove()}}},Ds=s=>{const t=Rt(s,{baseClassName:"sc-charts__main-line",id:`${s.chartId}-sc-charts__main-line`}),e=Ms(s);let i=null;s.config.hasExtremePoint&&(i=ks(s,{baseClassName:"sc-charts__extreme-point"}));const n=_s(s.svg),r=Ts(s,{baseClassName:"sc-charts__highlight-line",id:`${s.chartId}-sc-charts__highlight-line`,clip:{x:0,y:0,width:"0",height:"0"}});let a=null;s.config.enableBelowZeroLine&&(a=Rt(s,{baseClassName:"sc-charts__below-zero-line",id:`${s.chartId}-sc-charts__below-zero-line`,clip:le(s)}));const l=Bt(s.svg,{className:"sc-charts__hover-circle",hidden:!0}),h=he(s.svg),d=he(s.svg),g=Rt(s,{baseClassName:"sc-charts__range-line",id:`${s.chartId}-sc-charts__range-line`,clip:{x:0,y:0,width:"0",height:"0"}}),_=Bt(s.svg,{className:"sc-charts__range-circle-left",hidden:!0}),m=Bt(s.svg,{className:"sc-charts__range-circle-right",hidden:!0}),p=ps(s),v=ws(s),b=As(s);return{hoverLine:n,hoverCircle:l,rangeBorderLeft:h,rangeBorderRight:d,rangeLine:g,rangeLineArea:b,rangeCircleLeft:_,rangeCircleRight:m,mainLine:t,rangeTooltip:p,highlightLine:r,hoverTooltip:v,mainLineArea:e,belowZeroLine:a,extremePoint:i}},Es=(s,t,e)=>{const i=s.match(/^(\d+)([dMhmw])$/);if(!i)return console.warn("Invalid hoverRange:",s),{x:0,y:0,width:"100%",height:"100%"};const[,n,r]=i,a=parseInt(n,10),[l,h]=e.domain();let d=new Date(l);for(;d<h;){let g=new Date(d);switch(r){case"M":g.setMinutes(g.getMinutes()+a);break;case"h":g.setHours(g.getHours()+a);break;case"d":g.setDate(g.getDate()+a);break;case"w":g.setDate(g.getDate()+a*7);break;case"m":g=new Date(d.getFullYear(),d.getMonth()+a,1);break;default:return{x:0,y:0,width:"100%",height:"100%"}}if(t>=d&&t<g){const _=e(d),m=e(g);return{x:_,y:0,width:m-_,height:"100%"}}d=new Date(g)}if(t.getTime()===h.getTime()){let g=new Date(h);switch(r){case"M":g.setMinutes(g.getMinutes()-a);break;case"h":g.setHours(g.getHours()-a);break;case"d":g.setDate(g.getDate()-a);break;case"w":g.setDate(g.getDate()-a*7);break;case"m":g=new Date(h.getFullYear(),h.getMonth()-a,1);break}const _=e(g),m=e(h);return{x:_,y:0,width:m-_,height:"100%"}}return{x:0,y:0,width:"100%",height:"100%"}},ue=(s,t)=>{var d;const{x:e,y:i,elements:n,config:{margin:r},height:a}=s;n.hoverLine.update({x1:e(t.date),x2:e(t.date),y1:r.top,y2:a-r.bottom,hidden:!1}),n.hoverCircle.update({cx:e(t.date),cy:i(t.value),hidden:!1}),n.hoverTooltip.update({dataItem:t,hidden:!1});const l=Es(s.config.hover.range,t.date,e);n.highlightLine.update({clip:l,hidden:!1});const h=i.range()[0]-i(0)+r.bottom;h>=0&&((d=n.belowZeroLine)==null||d.update({clip:{...l,y:i(0),height:h}})),n.mainLine.className("add","_muted")},ge=s=>{var e;const{elements:t}=s;t.hoverLine.update({hidden:!0}),t.hoverCircle.update({hidden:!0}),t.highlightLine.update({hidden:!0}),t.mainLine.className("remove","_muted"),t.hoverTooltip.update({hidden:!0}),s.action!=="selection"&&((e=t.belowZeroLine)==null||e.update({clip:le(s)}))},Ls=(s,t)=>{["rangeBorderLeft","rangeBorderRight","rangeCircleLeft","rangeCircleRight","rangeLine","rangeLineArea","rangeTooltip"].forEach(i=>{t?(s[i].className("remove","_down"),s[i].className("add","_up")):(s[i].className("remove","_up"),s[i].className("add","_down"))})},Ns=(s,t,e)=>{var v;const{x:i,y:n,config:{margin:r},height:a,elements:l}=s,h=i(t.date)<i(e.date)?t:e,d=i(t.date)>=i(e.date)?t:e,g=d.value-h.value>=0,_=i(h.date),m=i(d.date),p=m-_;l.rangeBorderLeft.update({x1:_,x2:_,y1:r.top,y2:a-r.bottom,hidden:!1}),l.rangeBorderRight.update({x1:m,x2:m,y1:r.top,y2:a-r.bottom,hidden:!1}),l.rangeCircleLeft.update({cx:_,cy:n(h.value),hidden:!1}),l.rangeCircleRight.update({cx:m,cy:n(d.value),hidden:!1}),l.rangeLine.update({clip:{x:_,y:0,width:p,height:n.range()[0]},hidden:!1}),l.rangeLineArea.update({clip:{x:_,y:0,width:p,height:n.range()[0]},hidden:!1}),l.rangeTooltip.update({rightPoint:d,leftPoint:h,closest:e,x:_+p/2,y:0,hidden:!1}),(v=l.belowZeroLine)==null||v.update({hidden:!0}),l.mainLineArea.update({hidden:!0}),Ls(l,g),l.mainLine.className("add","_selected-muted")},_e=s=>{var e;const{elements:t}=s;t.rangeLine.update({hidden:!0}),t.rangeLineArea.update({hidden:!0}),t.rangeBorderLeft.update({hidden:!0}),t.rangeBorderRight.update({hidden:!0}),t.rangeCircleLeft.update({hidden:!0}),t.rangeCircleRight.update({hidden:!0}),t.rangeTooltip.update({hidden:!0}),t.mainLine.className("remove","_selected-muted"),t.mainLineArea.update({hidden:!1}),(e=t.belowZeroLine)==null||e.update({hidden:!1})},Is=s=>{const{svg:t,data:e,x:i,config:n,width:r,height:a}=s,{margin:l,hover:h,selection:d}=n;let g=null,_=!1;const m=v=>e.reduce((b,x)=>Math.abs(i(b.date)-v)<Math.abs(i(x.date)-v)?b:x);t.append("rect").attr("width",r-l.left-l.right).attr("height",a-l.top-l.bottom).attr("x",l.left).attr("y",l.top).attr("fill","transparent").on("mousemove",function(v){const[b]=D.pointer(v,this),x=m(b);!_&&h.enable?(s.action="hover",ue(s,x)):(s.action=_?"selection":"none",ge(s)),g&&d.enable&&(s.action="selection",Ns(s,g,x))}).on("mouseleave",()=>{s.action="none",_=!1,g=null,ge(s),_e(s)}).on("mousedown",function(v){if(d.enable){_=!0,s.action="selection";const[b]=D.pointer(v,this);g=m(b)}}).on("mouseup",function(v){const[b]=D.pointer(v,this),x=m(b);_=!1,g=null,s.action="hover",d.enable&&_e(s),h.enable&&ue(s,x)})},Fs=(s,t,e)=>{const{margin:i}=t,n=D.scaleTime(),r=D.extent(s,a=>new Date(a.date));return r[0]==null||r[1]==null?n:n.domain([r[0],r[1]]).range([i.left,e-i.right])},Bs=(s,t,e)=>{const{margin:i}=t,n=D.max(s,a=>a.value)??0,r=D.min(s,a=>a.value)??0;return D.scaleLinear().domain([r,n]).range([e-i.bottom,i.top])},Hs=(s,t)=>{const e=D.select(s);if(e.empty())return console.error(`Element with selector ${s} not found!`),null;if(!t.chartId||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.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 i=e.append("div"),n=i.append("svg"),r=e.node();let a=r.getBoundingClientRect(),l=a.width,h=a.height,d=ce({...Cs},t.config),g=t.data;const _=()=>{a=r.getBoundingClientRect(),l=a.width,h=a.height,m({data:g,config:d})};window.addEventListener("resize",_);const m=(p,v=!1)=>{v&&p.config&&(d=ce(d,p.config)),v&&p.data&&(g=p.data);const b=g.map(T=>({date:new Date(T.date),value:T.value})).sort((T,E)=>T.date.getTime()-E.date.getTime()),x=Fs(b,d,l),C=Bs(b,d,h);i.attr("class",`sc-charts sc-charts__${d.theme}`),n.attr("preserveAspectRatio","xMinYMin meet").attr("viewBox",`0 0 ${l} ${h}`).style("width","100%").style("height","100%").selectAll("*").remove();const w={chartId:t.chartId,svg:n,wrapperNode:i.node(),data:b,x,y:C,config:d,action:"none",width:l,height:h};gs(w);const y={...w,elements:Ds(w)};Is(y)};return m(t),{update:p=>m(p,!0),destroy:()=>{window.removeEventListener("resize",_),n.remove()}}};var bt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Rs(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var ht={exports:{}};ht.exports;var fe;function zs(){return fe||(fe=1,function(s,t){var e=200,i="__lodash_hash_undefined__",n=800,r=16,a=9007199254740991,l="[object Arguments]",h="[object Array]",d="[object AsyncFunction]",g="[object Boolean]",_="[object Date]",m="[object Error]",p="[object Function]",v="[object GeneratorFunction]",b="[object Map]",x="[object Number]",C="[object Null]",w="[object Object]",y="[object Proxy]",T="[object RegExp]",E="[object Set]",N="[object String]",z="[object Undefined]",G="[object WeakMap]",Vt="[object ArrayBuffer]",Gt="[object DataView]",Ut="[object Float32Array]",zn="[object Float64Array]",$n="[object Int8Array]",On="[object Int16Array]",Pn="[object Int32Array]",Yn="[object Uint8Array]",jn="[object Uint8ClampedArray]",Xn="[object Uint16Array]",Wn="[object Uint32Array]",Vn=/[\\^$.*+?()[\]{}|]/g,Gn=/^\[object .+?Constructor\]$/,Un=/^(?:0|[1-9]\d*)$/,F={};F[Ut]=F[zn]=F[$n]=F[On]=F[Pn]=F[Yn]=F[jn]=F[Xn]=F[Wn]=!0,F[l]=F[h]=F[Vt]=F[g]=F[Gt]=F[_]=F[m]=F[p]=F[b]=F[x]=F[w]=F[T]=F[E]=F[N]=F[G]=!1;var Be=typeof bt=="object"&&bt&&bt.Object===Object&&bt,Zn=typeof self=="object"&&self&&self.Object===Object&&self,gt=Be||Zn||Function("return this")(),He=t&&!t.nodeType&&t,_t=He&&!0&&s&&!s.nodeType&&s,Re=_t&&_t.exports===He,Zt=Re&&Be.process,ze=function(){try{var o=_t&&_t.require&&_t.require("util").types;return o||Zt&&Zt.binding&&Zt.binding("util")}catch{}}(),$e=ze&&ze.isTypedArray;function qn(o,u,f){switch(f.length){case 0:return o.call(u);case 1:return o.call(u,f[0]);case 2:return o.call(u,f[0],f[1]);case 3:return o.call(u,f[0],f[1],f[2])}return o.apply(u,f)}function Jn(o,u){for(var f=-1,M=Array(o);++f<o;)M[f]=u(f);return M}function Qn(o){return function(u){return o(u)}}function Kn(o,u){return o==null?void 0:o[u]}function tr(o,u){return function(f){return o(u(f))}}var er=Array.prototype,sr=Function.prototype,St=Object.prototype,qt=gt["__core-js_shared__"],kt=sr.toString,Q=St.hasOwnProperty,Oe=function(){var o=/[^.]+$/.exec(qt&&qt.keys&&qt.keys.IE_PROTO||"");return o?"Symbol(src)_1."+o:""}(),Pe=St.toString,ir=kt.call(Object),nr=RegExp("^"+kt.call(Q).replace(Vn,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Dt=Re?gt.Buffer:void 0,Ye=gt.Symbol,je=gt.Uint8Array;Dt&&Dt.allocUnsafe;var Xe=tr(Object.getPrototypeOf,Object),We=Object.create,rr=St.propertyIsEnumerable,ar=er.splice,et=Ye?Ye.toStringTag:void 0,Et=function(){try{var o=Kt(Object,"defineProperty");return o({},"",{}),o}catch{}}(),or=Dt?Dt.isBuffer:void 0,Ve=Math.max,lr=Date.now,Ge=Kt(gt,"Map"),ft=Kt(Object,"create"),cr=function(){function o(){}return function(u){if(!it(u))return{};if(We)return We(u);o.prototype=u;var f=new o;return o.prototype=void 0,f}}();function st(o){var u=-1,f=o==null?0:o.length;for(this.clear();++u<f;){var M=o[u];this.set(M[0],M[1])}}function hr(){this.__data__=ft?ft(null):{},this.size=0}function dr(o){var u=this.has(o)&&delete this.__data__[o];return this.size-=u?1:0,u}function ur(o){var u=this.__data__;if(ft){var f=u[o];return f===i?void 0:f}return Q.call(u,o)?u[o]:void 0}function gr(o){var u=this.__data__;return ft?u[o]!==void 0:Q.call(u,o)}function _r(o,u){var f=this.__data__;return this.size+=this.has(o)?0:1,f[o]=ft&&u===void 0?i:u,this}st.prototype.clear=hr,st.prototype.delete=dr,st.prototype.get=ur,st.prototype.has=gr,st.prototype.set=_r;function q(o){var u=-1,f=o==null?0:o.length;for(this.clear();++u<f;){var M=o[u];this.set(M[0],M[1])}}function fr(){this.__data__=[],this.size=0}function mr(o){var u=this.__data__,f=Lt(u,o);if(f<0)return!1;var M=u.length-1;return f==M?u.pop():ar.call(u,f,1),--this.size,!0}function pr(o){var u=this.__data__,f=Lt(u,o);return f<0?void 0:u[f][1]}function vr(o){return Lt(this.__data__,o)>-1}function br(o,u){var f=this.__data__,M=Lt(f,o);return M<0?(++this.size,f.push([o,u])):f[M][1]=u,this}q.prototype.clear=fr,q.prototype.delete=mr,q.prototype.get=pr,q.prototype.has=vr,q.prototype.set=br;function at(o){var u=-1,f=o==null?0:o.length;for(this.clear();++u<f;){var M=o[u];this.set(M[0],M[1])}}function yr(){this.size=0,this.__data__={hash:new st,map:new(Ge||q),string:new st}}function xr(o){var u=It(this,o).delete(o);return this.size-=u?1:0,u}function wr(o){return It(this,o).get(o)}function Cr(o){return It(this,o).has(o)}function Mr(o,u){var f=It(this,o),M=f.size;return f.set(o,u),this.size+=f.size==M?0:1,this}at.prototype.clear=yr,at.prototype.delete=xr,at.prototype.get=wr,at.prototype.has=Cr,at.prototype.set=Mr;function ot(o){var u=this.__data__=new q(o);this.size=u.size}function Ar(){this.__data__=new q,this.size=0}function Tr(o){var u=this.__data__,f=u.delete(o);return this.size=u.size,f}function Sr(o){return this.__data__.get(o)}function kr(o){return this.__data__.has(o)}function Dr(o,u){var f=this.__data__;if(f instanceof q){var M=f.__data__;if(!Ge||M.length<e-1)return M.push([o,u]),this.size=++f.size,this;f=this.__data__=new at(M)}return f.set(o,u),this.size=f.size,this}ot.prototype.clear=Ar,ot.prototype.delete=Tr,ot.prototype.get=Sr,ot.prototype.has=kr,ot.prototype.set=Dr;function Er(o,u){var f=se(o),M=!f&&ee(o),k=!f&&!M&&Qe(o),I=!f&&!M&&!k&&ts(o),H=f||M||k||I,L=H?Jn(o.length,String):[],R=L.length;for(var U in o)H&&(U=="length"||k&&(U=="offset"||U=="parent")||I&&(U=="buffer"||U=="byteLength"||U=="byteOffset")||qe(U,R))||L.push(U);return L}function Jt(o,u,f){(f!==void 0&&!Ft(o[u],f)||f===void 0&&!(u in o))&&Qt(o,u,f)}function Lr(o,u,f){var M=o[u];(!(Q.call(o,u)&&Ft(M,f))||f===void 0&&!(u in o))&&Qt(o,u,f)}function Lt(o,u){for(var f=o.length;f--;)if(Ft(o[f][0],u))return f;return-1}function Qt(o,u,f){u=="__proto__"&&Et?Et(o,u,{configurable:!0,enumerable:!0,value:f,writable:!0}):o[u]=f}var Nr=Wr();function Nt(o){return o==null?o===void 0?z:C:et&&et in Object(o)?Vr(o):Qr(o)}function Ue(o){return mt(o)&&Nt(o)==l}function Ir(o){if(!it(o)||qr(o))return!1;var u=ne(o)?nr:Gn;return u.test(sa(o))}function Fr(o){return mt(o)&&Ke(o.length)&&!!F[Nt(o)]}function Br(o){if(!it(o))return Jr(o);var u=Je(o),f=[];for(var M in o)M=="constructor"&&(u||!Q.call(o,M))||f.push(M);return f}function Ze(o,u,f,M,k){o!==u&&Nr(u,function(I,H){if(k||(k=new ot),it(I))Hr(o,u,H,f,Ze,M,k);else{var L=M?M(te(o,H),I,H+"",o,u,k):void 0;L===void 0&&(L=I),Jt(o,H,L)}},es)}function Hr(o,u,f,M,k,I,H){var L=te(o,f),R=te(u,f),U=H.get(R);if(U){Jt(o,f,U);return}var Y=I?I(L,R,f+"",o,u,H):void 0,pt=Y===void 0;if(pt){var re=se(R),ae=!re&&Qe(R),is=!re&&!ae&&ts(R);Y=R,re||ae||is?se(L)?Y=L:ia(L)?Y=Yr(L):ae?(pt=!1,Y=$r(R)):is?(pt=!1,Y=Pr(R)):Y=[]:na(R)||ee(R)?(Y=L,ee(L)?Y=ra(L):(!it(L)||ne(L))&&(Y=Gr(R))):pt=!1}pt&&(H.set(R,Y),k(Y,R,M,I,H),H.delete(R)),Jt(o,f,Y)}function Rr(o,u){return ta(Kr(o,u,ss),o+"")}var zr=Et?function(o,u){return Et(o,"toString",{configurable:!0,enumerable:!1,value:oa(u),writable:!0})}:ss;function $r(o,u){return o.slice()}function Or(o){var u=new o.constructor(o.byteLength);return new je(u).set(new je(o)),u}function Pr(o,u){var f=Or(o.buffer);return new o.constructor(f,o.byteOffset,o.length)}function Yr(o,u){var f=-1,M=o.length;for(u||(u=Array(M));++f<M;)u[f]=o[f];return u}function jr(o,u,f,M){var k=!f;f||(f={});for(var I=-1,H=u.length;++I<H;){var L=u[I],R=void 0;R===void 0&&(R=o[L]),k?Qt(f,L,R):Lr(f,L,R)}return f}function Xr(o){return Rr(function(u,f){var M=-1,k=f.length,I=k>1?f[k-1]:void 0,H=k>2?f[2]:void 0;for(I=o.length>3&&typeof I=="function"?(k--,I):void 0,H&&Ur(f[0],f[1],H)&&(I=k<3?void 0:I,k=1),u=Object(u);++M<k;){var L=f[M];L&&o(u,L,M,I)}return u})}function Wr(o){return function(u,f,M){for(var k=-1,I=Object(u),H=M(u),L=H.length;L--;){var R=H[++k];if(f(I[R],R,I)===!1)break}return u}}function It(o,u){var f=o.__data__;return Zr(u)?f[typeof u=="string"?"string":"hash"]:f.map}function Kt(o,u){var f=Kn(o,u);return Ir(f)?f:void 0}function Vr(o){var u=Q.call(o,et),f=o[et];try{o[et]=void 0;var M=!0}catch{}var k=Pe.call(o);return M&&(u?o[et]=f:delete o[et]),k}function Gr(o){return typeof o.constructor=="function"&&!Je(o)?cr(Xe(o)):{}}function qe(o,u){var f=typeof o;return u=u??a,!!u&&(f=="number"||f!="symbol"&&Un.test(o))&&o>-1&&o%1==0&&o<u}function Ur(o,u,f){if(!it(f))return!1;var M=typeof u;return(M=="number"?ie(f)&&qe(u,f.length):M=="string"&&u in f)?Ft(f[u],o):!1}function Zr(o){var u=typeof o;return u=="string"||u=="number"||u=="symbol"||u=="boolean"?o!=="__proto__":o===null}function qr(o){return!!Oe&&Oe in o}function Je(o){var u=o&&o.constructor,f=typeof u=="function"&&u.prototype||St;return o===f}function Jr(o){var u=[];if(o!=null)for(var f in Object(o))u.push(f);return u}function Qr(o){return Pe.call(o)}function Kr(o,u,f){return u=Ve(u===void 0?o.length-1:u,0),function(){for(var M=arguments,k=-1,I=Ve(M.length-u,0),H=Array(I);++k<I;)H[k]=M[u+k];k=-1;for(var L=Array(u+1);++k<u;)L[k]=M[k];return L[u]=f(H),qn(o,this,L)}}function te(o,u){if(!(u==="constructor"&&typeof o[u]=="function")&&u!="__proto__")return o[u]}var ta=ea(zr);function ea(o){var u=0,f=0;return function(){var M=lr(),k=r-(M-f);if(f=M,k>0){if(++u>=n)return arguments[0]}else u=0;return o.apply(void 0,arguments)}}function sa(o){if(o!=null){try{return kt.call(o)}catch{}try{return o+""}catch{}}return""}function Ft(o,u){return o===u||o!==o&&u!==u}var ee=Ue(function(){return arguments}())?Ue:function(o){return mt(o)&&Q.call(o,"callee")&&!rr.call(o,"callee")},se=Array.isArray;function ie(o){return o!=null&&Ke(o.length)&&!ne(o)}function ia(o){return mt(o)&&ie(o)}var Qe=or||la;function ne(o){if(!it(o))return!1;var u=Nt(o);return u==p||u==v||u==d||u==y}function Ke(o){return typeof o=="number"&&o>-1&&o%1==0&&o<=a}function it(o){var u=typeof o;return o!=null&&(u=="object"||u=="function")}function mt(o){return o!=null&&typeof o=="object"}function na(o){if(!mt(o)||Nt(o)!=w)return!1;var u=Xe(o);if(u===null)return!0;var f=Q.call(u,"constructor")&&u.constructor;return typeof f=="function"&&f instanceof f&&kt.call(f)==ir}var ts=$e?Qn($e):Fr;function ra(o){return jr(o,es(o))}function es(o){return ie(o)?Er(o):Br(o)}var aa=Xr(function(o,u,f){Ze(o,u,f)});function oa(o){return function(){return o}}function ss(o){return o}function la(){return!1}s.exports=aa}(ht,ht.exports)),ht.exports}var $s=zs();const yt=Rs($s),me=12,Os={candles:{direction:"right",offset:`${Math.round(me/2)}px`,style:"filled",strokeWidth:1,baseWidth:me,bodyRatio:.7,zoomOnWheel:"both",scaleSensitivity:.002},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}};class Ps{constructor(t){c(this,"_candles");c(this,"_xAxis");c(this,"_yAxis");c(this,"_guides");c(this,"_trade");const e=yt({},Os,t);this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._trade=e.trade}update(t){const e=yt({},{candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,trade:this._trade},t);this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._trade=e.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 j{constructor(t){c(this,"_x");c(this,"_y");c(this,"_width");c(this,"_height");let e;if(!t)e={x:0,y:0,width:0,height:0};else if(t instanceof HTMLElement||t instanceof Element){const{x:i,y:n,width:r,height:a}=t.getBoundingClientRect();e={x:i,y:n,width:r,height:a}}else e=t;this._x=e.x,this._y=e.y,this._width=e.width,this._height=e.height}get x(){return this._x}get y(){return this._y}get width(){return this._width}get height(){return this._height}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 Ys{constructor(t,e){c(this,"_chart",new j);c(this,"_area",new j);c(this,"_xAxis",new j);c(this,"_yAxis",new j);c(this,"_axisIntersection",new j);const{xAxis:i,yAxis:n}=e;this._chart=new j(t),this._calc(i,n)}_calc(t,e){const i=t.isShow?t.height:0,n=e.isShow?e.width:0,r=this._chart.height-i,a=this._chart.width-n;this._area=new j({x:e.position==="left"?n:0,y:t.position==="top"?i:0,width:a,height:r}),this._xAxis=new j({y:t.position==="top"?0:r,x:e.position==="left"?n:0,height:i,width:a}),this._yAxis=new j({y:t.position==="top"?i:0,x:e.position==="left"?0:a,width:n,height:r}),this._axisIntersection=new j({y:t.position==="top"?0:r,x:e.position==="left"?0:a,width:n,height:i})}updateConfig(t){const{xAxis:e,yAxis:i}=t;this._calc(e,i)}update(t){const{xAxis:e,yAxis:i}=t.config;this._chart=new j(t.container),this._calc(e,i)}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 js=s=>s?new Date(s.close_time).getTime()-new Date(s.open_time).getTime():0;function Xs(s,t){if(s.length<2)return[];const e=[];for(let i=0;i<s.length-1;i++){const n=s[i].close_time.getTime(),r=s[i].open_time.getTime(),l=new Date(s[i+1].open_time).getTime()-n;if(l>=t){const h=Math.floor(l/t),d=[];for(let g=1;g<=h;g++)d.push(r+g*t);d.length>0&&e.push(d)}}return e}function pe(s,t){const e=js(s[0]),i=Xs(s,e),n=[];return i.forEach(r=>{if(r.length===0)return;const a=s.find(_=>_.close_time.getTime()===r[0]),l=s.find(_=>_.open_time.getTime()===r[r.length-1]+e);if(!a||!l)throw new Error("[CS_Data] error while creating missing data");const h=a.close,d=l.open;let g=h;r.forEach((_,m)=>{const p=(d-g)/r.length;let v=g+p*m,b=v+p;const x=Math.abs(v-b);let C=Math.max(v,b)+x/2,w=Math.min(v,b)-x/2;if(t.trade){const T=[...t.trade.entries,...t.trade.exits].find(E=>{const N=E.time.getTime();return N>=_&&N<_+e});T&&(T.type==="buy"?(w=T.price,b=Math.max(w,b),v=b+x,C=Math.max(v,b)+x/2,g=v):T.type==="sell"&&(C=T.price,b=Math.min(C,b),v=b-x,w=Math.min(v,b)-x/2,g=v))}const y={open_time:new Date(_),close_time:new Date(_+e),open:v,close:b,high:C,low:w};n.push(y)})}),n}class zt{constructor(t,e){c(this,"_initialData",[]);c(this,"_preparedData",[]);c(this,"_missingData",[]);c(this,"_count",0);c(this,"_model");c(this,"_interval",0);this._model=e,this.update(t)}_prepare(t){return t.map(e=>({...e,open_time:new Date(e.open_time),close_time:new Date(e.close_time)})).sort((e,i)=>e.open_time.getTime()-i.open_time.getTime())}update(t){this._initialData=t,this._preparedData=this._prepare(t),this._missingData=pe(this._preparedData,this._model),this._count=this._preparedData.length+this._missingData.length,this._interval=new Date(t[0].close_time).getTime()-new Date(t[0].open_time).getTime()}updateMissingCandles(){this._missingData=pe(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(t,e){return e.find(i=>i.open_time<=t&&i.close_time>t)}}class Ws{constructor(){c(this,"listeners",{})}subscribe(t,e){return this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e),()=>this.unsubscribe(t,e)}unsubscribe(t,e){var i;this.listeners[t]=((i=this.listeners[t])==null?void 0:i.filter(n=>n!==e))||[]}emit(t,...e){var n;const i=e[0];(n=this.listeners[t])==null||n.forEach(r=>{r(i)})}}class ve{constructor(){c(this,"_scale")}domain(){const t=this._scale.domain();if(t.length!==2)throw new Error("Domain length is not 2");return t}setDomain(t){this._scale.domain(t)}range(){const t=this._scale.range();if(t.length!==2)throw new Error("Range length is not 2");return t}setRange(t){this._scale.range(t)}invert(t){return this._scale.invert(t)}ticks(t){return this._scale.ticks(t)}tickFormat(t,e){return this._scale.tickFormat(t,e)}raw(){return this._scale}convert(t){return this._scale(t)}}class be extends ve{constructor(){super(),this._scale=D.scaleTime()}}class Vs extends ve{constructor(){super(),this._scale=D.scaleLinear()}}const ye={x:.2,y:.2},xe=.001,Gs={s:1e3,M:1e3*60,h:1e3*60*60,d:1e3*60*60*24,w:1e3*60*60*24*7},Us=s=>{const t=s.match(/^(\d+)([a-zA-Z]+)$/);if(!t)throw new Error(`Invalid offset format: "${s}"`);return[parseInt(t[1]),t[2]]},Zs=(s,t)=>{const[e,i]=t.domain().map(l=>l.getTime()),n=s.filter(l=>{const h=l.open_time.getTime();return h>=e&&h<=i}),r=D.min(n,l=>l.low),a=D.max(n,l=>l.high);if(r==null||a==null)throw new Error("Invalid Y data");return[r,a]};class qs{constructor(t){this.model=t}initX(t){const e=this.model.candles.preparedData,i=D.extent(e,n=>new Date(n.open_time));if(!i[0]||!i[1])throw new Error("Invalid x data");t.setDomain(i),this.setRange(t,this.model.layout.xAxis),this.setDefaultXDomain(t),this.applyOffset(t)}initY(t,e){const i=Zs(this.model.candles.preparedData,e);t.setDomain(i),this.setRange(t,this.model.layout.yAxis)}init(t){this.initX(t.x),this.initY(t.y,t.x)}setRange(t,{x:e,y:i,width:n,height:r}){t instanceof be?t.setRange([e,e+n]):t.setRange([i+r,i])}setDefaultXDomain(t){const{candles:{count:e},layout:{area:i},config:{candles:{baseWidth:n,bodyRatio:r,direction:a}}}=this.model,[l,h]=t.domain().map(p=>p.getTime()),d=h-l,g=n/r*e,_=d*(i.width/g),m=a==="left"?[new Date(l),new Date(l+_)]:[new Date(h-_),new Date(h)];t.setDomain(m)}applyOffset(t){const{config:{candles:{offset:e,direction:i}},layout:{xAxis:n}}=this.model,[r,a]=Us(e),l=a==="px"?t.invert(n.x+r).getTime()-t.invert(n.x).getTime():Gs[a]*r,h=i==="left"?-l:l,[d,g]=t.domain();t.setDomain([new Date(d.getTime()+h),new Date(g.getTime()+h)])}}class Js{constructor(t){c(this,"_model");c(this,"_scaleX");c(this,"_scaleY");c(this,"_initializer");c(this,"_baseDomain",{x:[new Date,new Date],y:[0,0]});c(this,"scaleFactor",{x:1,y:1});c(this,"panOffset",{x:0,y:0});this._model=t,this._scaleX=new be,this._scaleY=new Vs,this._initializer=new qs(t),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 t=this._model.candles.allData,[e,i]=this._scaleX.domain(),n=t.filter(_=>_.open_time>=e&&_.open_time<=i);if(!n.length)return;const r=Math.min(...n.map(_=>_.low)),a=Math.max(...n.map(_=>_.high)),l=a-r;if(l===0)return;const h=this._baseDomain.y;this.scale("y",(h[1]-h[0])/l,"absolute");const d=this._scaleY.convert((r+a)/2),g=this._scaleY.convert((h[0]+h[1])/2);this.pan("y",g-d,"absolute")}scale(t,e,i="delta"){if(i==="absolute"){const n=Math.max(ye[t],e);if(Math.abs(n-this.scaleFactor[t])<xe)return;this.scaleFactor[t]=n}else{const n=this.scaleFactor[t],r=n+e*this._model.config.candles.scaleSensitivity;if(r<ye[t]||Math.abs(r-n)<xe)return;this.scaleFactor[t]=r}this._updateDomain(t)}pan(t,e,i="delta"){i==="absolute"?this.panOffset[t]=e:this.panOffset[t]+=e,this._updateDomain(t)}_updateDomain(t){const e=this._baseDomain[t],i=this.scaleFactor[t],n=this.panOffset[t];if(t==="x"){const[r,a]=e,l=a.getTime()-r.getTime(),h=l/i,d=r.getTime()+l/2,g=this._scaleX.invert(0-n).getTime()-this._scaleX.invert(0).getTime();this._scaleX.setDomain([new Date(d-h/2+g),new Date(d+h/2+g)])}else{const[r,a]=e,l=a-r,h=l/i,d=r+l/2,g=this._scaleY.invert(0-n)-this._scaleY.invert(0);this._scaleY.setDomain([d-h/2+g,d+h/2+g])}this._model.eventBus.emit("scale_event")}}class Qs{constructor(t,{entry:e=[],exit:i=[]}){c(this,"_model");c(this,"_rawEntry");c(this,"_rawExit");c(this,"_mapped",[]);c(this,"_entries",[]);c(this,"_exits",[]);c(this,"_activeTradeTime",null);c(this,"_hoveredTradeTime",null);this._model=t,this._rawEntry=e,this._rawExit=i,this.recalculate()}_findTradeCandle(t){return e=>t>=e.open_time&&t<e.close_time}recalculate(){const t=this._rawEntry.map(n=>({...n,kind:"entry",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),e=this._rawExit.map(n=>({...n,kind:"exit",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),i=[...t,...e];this._mapped=this._model.candles.allData.map(n=>{const r=i.filter(a=>a.time>=n.open_time&&a.time<n.close_time);return{candle:n,trades:r}}).filter(n=>n.trades.length>0),this._entries=t.sort((n,r)=>n.time.getTime()-r.time.getTime()),this._exits=e.sort((n,r)=>n.time.getTime()-r.time.getTime())}updateTrade({entry:t,exit:e}){this._rawEntry=t,this._rawExit=e,this.recalculate()}setActiveTrade(t,e){this._activeTradeTime=e||null,this._mapped=this._mapped.map(i=>({...i,isActive:t===null?void 0:[t,i.candle.open_time.getTime()===e]}))}setHoveredTrade(t,e){this._hoveredTradeTime=e||null,this._mapped=this._mapped.map(i=>({...i,isHovered:t===null?void 0:[t,i.candle.open_time.getTime()===e]}))}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 t;return((t=this._entries.at(0))==null?void 0:t.time.getTime())??0}get exitMaxTime(){var t;return((t=this._exits.at(-1))==null?void 0:t.time.getTime())??0}get timeRange(){const{allData:t,interval:e}=this._model.candles,i=t.map(a=>a.open_time.getTime());let n=0,r=i.length-1;for(let a=0;a<i.length;a++){const l=i[a],h=l<=this.entryMinTime&&l+e>=this.entryMinTime,d=l<=this.exitMaxTime&&l+e>=this.exitMaxTime;if(n===0&&h&&(n=a),r===i.length-1&&d&&(r=a),n!==0&&r!==i.length-1)break}return i.slice(n,r+1)}get hasTrade(){return this._rawEntry.length>0&&this._rawExit.length>0}get holdTime(){return Math.abs(this.entryMinTime-this.exitMaxTime)}}class Ks{constructor(t,e){c(this,"_rawMarkers");c(this,"_markers",[]);c(this,"_model");c(this,"_defaults",{mainColor:"#000000",textColor:"#ffffff",lineColor:"#000000",formatter:{horizontal:t=>t.toString(),vertical:t=>t.toLocaleString()}});this._rawMarkers=e,this._model=t,this.rebuild()}rebuild(){const{layout:{area:t,chart:e},config:i,scales:{x:n,y:r},colorScheme:{userMarkers:{default:a}}}=this._model;this._markers=this._rawMarkers.map(l=>{var g,_;const h={mainColor:l.mainColor??a.main,textColor:l.textColor??a.text,lineColor:l.lineColor??a.line};if((l.type??"horizontal")==="horizontal"){const m=l,p=r.convert(m.value),b=(m.formatter??((g=this._defaults.formatter)==null?void 0:g.horizontal)??(x=>x.toString()))(m.value);return{value:m.value,type:"horizontal",text:b,x:t.x,y:p,lineLength:e.width,position:i.yAxis.position,...h}}else{const m=l,p=m.value instanceof Date?m.value:new Date(m.value),v=n.convert(p),x=(m.formatter??((_=this._defaults.formatter)==null?void 0:_.vertical)??(C=>C.toLocaleString()))(p);return{value:p,type:"vertical",text:x,x:v,y:t.y,lineLength:e.height,position:i.xAxis.position,...h}}})}updateMarkers(t){this._rawMarkers=t,this.rebuild()}get data(){return this._markers}}class ti{constructor(){c(this,"bg","#FFFFFF");c(this,"axisIntersection","#FFFFFF");c(this,"xAxis",{bg:"#FFFFFF",text:"#7F7F83"});c(this,"yAxis",{bg:"#FFFFFF",text:"#7F7F83"});c(this,"candles",{risingFill:"#56B683",risingStroke:"#000000",fallingFill:"#F18169",fallingStroke:"#000000",noDataFill:["#d9d9da","#ededed"],noDataStroke:"#000000"});c(this,"guides",{horizontalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"},verticalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"}});c(this,"trade");c(this,"userMarkers");c(this,"comments",{scaleAnchor:{bgActive:"#007AFF",bgInactive:"#A1BBFF",iconActive:"#FFFFFF",iconInactive:"#004DA1"}});this.trade={buyLabel:{main:this.candles.risingFill,text:"#ffffff"},sellLabel:{main:this.candles.fallingFill,text:"#ffffff"},connectionLine:"#D9D9DA",tradeBorders:"#EDEDED",activeLabel:"#007AFF",hold:{main:"#A1BBFF",text:"#ffffff"}},this.userMarkers={default:{main:"#EDEDED",text:"#000000",line:"#EDEDED"}}}toObject(){return{bg:this.bg,axisIntersection:this.axisIntersection,xAxis:this.xAxis,yAxis:this.yAxis,candles:this.candles,guides:this.guides,trade:this.trade,userMarkers:this.userMarkers,comments:this.comments}}}const ei=new ti().toObject();class si{constructor(t){c(this,"_bg");c(this,"_candles");c(this,"_xAxis");c(this,"_yAxis");c(this,"_guides");c(this,"_axisIntersection");c(this,"_trade");c(this,"_userMarkers");c(this,"_comments");const e=yt({},ei,t);this._candles=e.candles,this._bg=e.bg,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._axisIntersection=e.axisIntersection,this._trade=e.trade,this._userMarkers=e.userMarkers,this._comments=e.comments}update(t){const e=yt({},{bg:this._bg,candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,axisIntersection:this._axisIntersection,trade:this._trade,userMarkers:this._userMarkers,comments:this._comments},t);this._bg=e.bg,this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._axisIntersection=e.axisIntersection,this._trade=e.trade,this._userMarkers=e.userMarkers,this._comments=e.comments}get bg(){return this._bg}get candles(){return this._candles}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get guides(){return this._guides}get axisIntersection(){return this._axisIntersection}get trade(){return this._trade}get userMarkers(){return this._userMarkers}get comments(){return this._comments}}class ii{constructor(t,e){c(this,"_data");c(this,"_callbacks",{onAdd:()=>{},onUpdate:()=>{},onDelete:()=>{}});c(this,"_model");c(this,"_grouped",{});this._data=(t==null?void 0:t.data)||[],this._model=e,this._updateGroups(),t!=null&&t.onAdd&&(this._callbacks.onAdd=t.onAdd),t!=null&&t.onUpdate&&(this._callbacks.onUpdate=t.onUpdate),t!=null&&t.onDelete&&(this._callbacks.onDelete=t.onDelete)}_updateGroups(){this._grouped={};for(const t of this._data){const e=zt.findByDate(new Date(t.date),this._model.candles.allData);if(!e)continue;const i=e.open_time.getTime();this._grouped[i]||(this._grouped[i]=[]),this._grouped[i].push({...t,candle:e})}}get data(){return this._data}set data(t){this._data=t,this._updateGroups()}get grouped(){return this._grouped}add(t){this._data.push(t),this._updateGroups(),this._callbacks.onAdd(t)}remove(t){this._data=this._data.filter(e=>e.id!==t),this._updateGroups(),this._callbacks.onDelete(t)}update(t,e){this._updateGroups(),this._callbacks.onUpdate(t,e)}}class ni{constructor({chartId:t,container:e,candles:i,config:n,trade:r={entry:[],exit:[]},userMarkers:a=[],colorScheme:l,comments:h}){c(this,"_chartId");c(this,"_container");c(this,"_eventBus",new Ws);c(this,"_candles");c(this,"_config");c(this,"_colorScheme");c(this,"_layout");c(this,"_scaleManager");c(this,"_trade");c(this,"_userMarkers");c(this,"_comments");this._chartId=t,this._container=e,this._candles=new zt(i,this),this._config=new Ps(n),this._colorScheme=new si(l),this._layout=new Ys(e,this._config),this._scaleManager=new Js(this),this._trade=new Qs(this,r),this._candles.updateMissingCandles(),this._trade.recalculate(),this._userMarkers=new Ks(this,a),this._comments=new ii(h,this)}init(){this._eventBus.emit("init_model")}subscribe(t,e){return this._eventBus.subscribe(t,e)}unsubscribe(t,e){this._eventBus.unsubscribe(t,e)}updateConfig(t){this._eventBus.emit("update_config",t)}updateCandles(t){this._eventBus.emit("update_candles",t)}updateTrade(t){this._eventBus.emit("update_trade",t)}updateUserMarkers(t){this._eventBus.emit("update_user_markers",t)}updateColorScheme(t){this._eventBus.emit("update_color_scheme",t)}updateComments(t){this._eventBus.emit("update_comments",t)}get chartId(){return this._chartId}get container(){return this._container}get config(){return this._config}get layout(){return this._layout}get candles(){return this._candles}get eventBus(){return this._eventBus}get scales(){return this._scaleManager}get trade(){return this._trade}get userMarkers(){return this._userMarkers}get colorScheme(){return this._colorScheme}get comments(){return this._comments}}const xt=window.devicePixelRatio||2;class S{constructor({tag:t,className:e,id:i,textContent:n}){c(this,"_tag");c(this,"_className");c(this,"_id");c(this,"_textContent");c(this,"_node");c(this,"_absolutePosition",new DOMRect);this._tag=t||"div",this._className=e||"",this._id=i||"",this._textContent=n||"";const r=document.createElement(this._tag);this._className&&(r.className=this._className),this._id&&(r.id=this._id),this._textContent&&(r.textContent=this._textContent),this._node=r}get node(){return this._node}position(t,e){const i=typeof t=="number"?t:t.x,n=typeof t=="number"?e:t.y;this.node.style.top=n+"px",this.node.style.left=i+"px"}append(...t){this._node.append(...t)}prepend(...t){this._node.prepend(...t)}remove(){this._node.remove(),this._tag="",this._className="",this._id="",this._textContent=""}get absolutePosition(){return this._absolutePosition}updateAbsolutePosition(){this._absolutePosition=this._node.getBoundingClientRect()}setVisible(t){this.node.style.opacity=t?"1":"0",this.node.style.visibility=t?"visible":"hidden"}}class wt extends S{constructor({className:e,id:i,width:n,height:r,isMain:a}){super({tag:"canvas",className:`${e} sc-charts-cs__canvas ${a?"":"sc-charts-cs__canvas-additional"}`,id:i});c(this,"_ctx");c(this,"_width");c(this,"_height");c(this,"background",null);this._width=n,this._height=r,this.updateSize({width:n,height:r});const l=this._node.getContext("2d");if(!l)throw new Error("Failed to get 2D context");l.scale(xt,xt),this._ctx=l}updateSize({width:e,height:i}){e&&(this._node.width=e*xt,this._node.style.width=`${e}px`,this._width=e),i&&(this._node.height=i*xt,this._node.style.height=`${i}px`,this._height=i)}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}}function Ct(s){"@babel/helpers - typeof";return Ct=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ct(s)}var ri=/^\s+/,ai=/\s+$/;function A(s,t){if(s=s||"",t=t||{},s instanceof A)return s;if(!(this instanceof A))return new A(s,t);var e=oi(s);this._originalInput=s,this._r=e.r,this._g=e.g,this._b=e.b,this._a=e.a,this._roundA=Math.round(100*this._a)/100,this._format=t.format||e.format,this._gradientType=t.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=e.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 t=this.toRgb();return(t.r*299+t.g*587+t.b*114)/1e3},getLuminance:function(){var t=this.toRgb(),e,i,n,r,a,l;return e=t.r/255,i=t.g/255,n=t.b/255,e<=.03928?r=e/12.92:r=Math.pow((e+.055)/1.055,2.4),i<=.03928?a=i/12.92:a=Math.pow((i+.055)/1.055,2.4),n<=.03928?l=n/12.92:l=Math.pow((n+.055)/1.055,2.4),.2126*r+.7152*a+.0722*l},setAlpha:function(t){return this._a=Se(t),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var t=Ce(this._r,this._g,this._b);return{h:t.h*360,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=Ce(this._r,this._g,this._b),e=Math.round(t.h*360),i=Math.round(t.s*100),n=Math.round(t.v*100);return this._a==1?"hsv("+e+", "+i+"%, "+n+"%)":"hsva("+e+", "+i+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var t=we(this._r,this._g,this._b);return{h:t.h*360,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=we(this._r,this._g,this._b),e=Math.round(t.h*360),i=Math.round(t.s*100),n=Math.round(t.l*100);return this._a==1?"hsl("+e+", "+i+"%, "+n+"%)":"hsla("+e+", "+i+"%, "+n+"%, "+this._roundA+")"},toHex:function(t){return Me(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return di(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},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(B(this._r,255)*100)+"%",g:Math.round(B(this._g,255)*100)+"%",b:Math.round(B(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(B(this._r,255)*100)+"%, "+Math.round(B(this._g,255)*100)+"%, "+Math.round(B(this._b,255)*100)+"%)":"rgba("+Math.round(B(this._r,255)*100)+"%, "+Math.round(B(this._g,255)*100)+"%, "+Math.round(B(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:Ci[Me(this._r,this._g,this._b,!0)]||!1},toFilter:function(t){var e="#"+Ae(this._r,this._g,this._b,this._a),i=e,n=this._gradientType?"GradientType = 1, ":"";if(t){var r=A(t);i="#"+Ae(r._r,r._g,r._b,r._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+e+",endColorstr="+i+")"},toString:function(t){var e=!!t;t=t||this._format;var i=!1,n=this._a<1&&this._a>=0,r=!e&&n&&(t==="hex"||t==="hex6"||t==="hex3"||t==="hex4"||t==="hex8"||t==="name");return r?t==="name"&&this._a===0?this.toName():this.toRgbString():(t==="rgb"&&(i=this.toRgbString()),t==="prgb"&&(i=this.toPercentageRgbString()),(t==="hex"||t==="hex6")&&(i=this.toHexString()),t==="hex3"&&(i=this.toHexString(!0)),t==="hex4"&&(i=this.toHex8String(!0)),t==="hex8"&&(i=this.toHex8String()),t==="name"&&(i=this.toName()),t==="hsl"&&(i=this.toHslString()),t==="hsv"&&(i=this.toHsvString()),i||this.toHexString())},clone:function(){return A(this.toString())},_applyModification:function(t,e){var i=t.apply(null,[this].concat([].slice.call(e)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(fi,arguments)},brighten:function(){return this._applyModification(mi,arguments)},darken:function(){return this._applyModification(pi,arguments)},desaturate:function(){return this._applyModification(ui,arguments)},saturate:function(){return this._applyModification(gi,arguments)},greyscale:function(){return this._applyModification(_i,arguments)},spin:function(){return this._applyModification(vi,arguments)},_applyCombination:function(t,e){return t.apply(null,[this].concat([].slice.call(e)))},analogous:function(){return this._applyCombination(xi,arguments)},complement:function(){return this._applyCombination(bi,arguments)},monochromatic:function(){return this._applyCombination(wi,arguments)},splitcomplement:function(){return this._applyCombination(yi,arguments)},triad:function(){return this._applyCombination(Te,[3])},tetrad:function(){return this._applyCombination(Te,[4])}},A.fromRatio=function(s,t){if(Ct(s)=="object"){var e={};for(var i in s)s.hasOwnProperty(i)&&(i==="a"?e[i]=s[i]:e[i]=dt(s[i]));s=e}return A(s,t)};function oi(s){var t={r:0,g:0,b:0},e=1,i=null,n=null,r=null,a=!1,l=!1;return typeof s=="string"&&(s=Si(s)),Ct(s)=="object"&&(Z(s.r)&&Z(s.g)&&Z(s.b)?(t=li(s.r,s.g,s.b),a=!0,l=String(s.r).substr(-1)==="%"?"prgb":"rgb"):Z(s.h)&&Z(s.s)&&Z(s.v)?(i=dt(s.s),n=dt(s.v),t=hi(s.h,i,n),a=!0,l="hsv"):Z(s.h)&&Z(s.s)&&Z(s.l)&&(i=dt(s.s),r=dt(s.l),t=ci(s.h,i,r),a=!0,l="hsl"),s.hasOwnProperty("a")&&(e=s.a)),e=Se(e),{ok:a,format:s.format||l,r:Math.min(255,Math.max(t.r,0)),g:Math.min(255,Math.max(t.g,0)),b:Math.min(255,Math.max(t.b,0)),a:e}}function li(s,t,e){return{r:B(s,255)*255,g:B(t,255)*255,b:B(e,255)*255}}function we(s,t,e){s=B(s,255),t=B(t,255),e=B(e,255);var i=Math.max(s,t,e),n=Math.min(s,t,e),r,a,l=(i+n)/2;if(i==n)r=a=0;else{var h=i-n;switch(a=l>.5?h/(2-i-n):h/(i+n),i){case s:r=(t-e)/h+(t<e?6:0);break;case t:r=(e-s)/h+2;break;case e:r=(s-t)/h+4;break}r/=6}return{h:r,s:a,l}}function ci(s,t,e){var i,n,r;s=B(s,360),t=B(t,100),e=B(e,100);function a(d,g,_){return _<0&&(_+=1),_>1&&(_-=1),_<1/6?d+(g-d)*6*_:_<1/2?g:_<2/3?d+(g-d)*(2/3-_)*6:d}if(t===0)i=n=r=e;else{var l=e<.5?e*(1+t):e+t-e*t,h=2*e-l;i=a(h,l,s+1/3),n=a(h,l,s),r=a(h,l,s-1/3)}return{r:i*255,g:n*255,b:r*255}}function Ce(s,t,e){s=B(s,255),t=B(t,255),e=B(e,255);var i=Math.max(s,t,e),n=Math.min(s,t,e),r,a,l=i,h=i-n;if(a=i===0?0:h/i,i==n)r=0;else{switch(i){case s:r=(t-e)/h+(t<e?6:0);break;case t:r=(e-s)/h+2;break;case e:r=(s-t)/h+4;break}r/=6}return{h:r,s:a,v:l}}function hi(s,t,e){s=B(s,360)*6,t=B(t,100),e=B(e,100);var i=Math.floor(s),n=s-i,r=e*(1-t),a=e*(1-n*t),l=e*(1-(1-n)*t),h=i%6,d=[e,a,r,r,l,e][h],g=[l,e,e,a,r,r][h],_=[r,r,l,e,e,a][h];return{r:d*255,g:g*255,b:_*255}}function Me(s,t,e,i){var n=[X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16))];return i&&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 di(s,t,e,i,n){var r=[X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16)),X(ke(i))];return n&&r[0].charAt(0)==r[0].charAt(1)&&r[1].charAt(0)==r[1].charAt(1)&&r[2].charAt(0)==r[2].charAt(1)&&r[3].charAt(0)==r[3].charAt(1)?r[0].charAt(0)+r[1].charAt(0)+r[2].charAt(0)+r[3].charAt(0):r.join("")}function Ae(s,t,e,i){var n=[X(ke(i)),X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16))];return n.join("")}A.equals=function(s,t){return!s||!t?!1:A(s).toRgbString()==A(t).toRgbString()},A.random=function(){return A.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})};function ui(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.s-=t/100,e.s=Mt(e.s),A(e)}function gi(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.s+=t/100,e.s=Mt(e.s),A(e)}function _i(s){return A(s).desaturate(100)}function fi(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.l+=t/100,e.l=Mt(e.l),A(e)}function mi(s,t){t=t===0?0:t||10;var e=A(s).toRgb();return e.r=Math.max(0,Math.min(255,e.r-Math.round(255*-(t/100)))),e.g=Math.max(0,Math.min(255,e.g-Math.round(255*-(t/100)))),e.b=Math.max(0,Math.min(255,e.b-Math.round(255*-(t/100)))),A(e)}function pi(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.l-=t/100,e.l=Mt(e.l),A(e)}function vi(s,t){var e=A(s).toHsl(),i=(e.h+t)%360;return e.h=i<0?360+i:i,A(e)}function bi(s){var t=A(s).toHsl();return t.h=(t.h+180)%360,A(t)}function Te(s,t){if(isNaN(t)||t<=0)throw new Error("Argument to polyad must be a positive number");for(var e=A(s).toHsl(),i=[A(s)],n=360/t,r=1;r<t;r++)i.push(A({h:(e.h+r*n)%360,s:e.s,l:e.l}));return i}function yi(s){var t=A(s).toHsl(),e=t.h;return[A(s),A({h:(e+72)%360,s:t.s,l:t.l}),A({h:(e+216)%360,s:t.s,l:t.l})]}function xi(s,t,e){t=t||6,e=e||30;var i=A(s).toHsl(),n=360/e,r=[A(s)];for(i.h=(i.h-(n*t>>1)+720)%360;--t;)i.h=(i.h+n)%360,r.push(A(i));return r}function wi(s,t){t=t||6;for(var e=A(s).toHsv(),i=e.h,n=e.s,r=e.v,a=[],l=1/t;t--;)a.push(A({h:i,s:n,v:r})),r=(r+l)%1;return a}A.mix=function(s,t,e){e=e===0?0:e||50;var i=A(s).toRgb(),n=A(t).toRgb(),r=e/100,a={r:(n.r-i.r)*r+i.r,g:(n.g-i.g)*r+i.g,b:(n.b-i.b)*r+i.b,a:(n.a-i.a)*r+i.a};return A(a)},A.readability=function(s,t){var e=A(s),i=A(t);return(Math.max(e.getLuminance(),i.getLuminance())+.05)/(Math.min(e.getLuminance(),i.getLuminance())+.05)},A.isReadable=function(s,t,e){var i=A.readability(s,t),n,r;switch(r=!1,n=ki(e),n.level+n.size){case"AAsmall":case"AAAlarge":r=i>=4.5;break;case"AAlarge":r=i>=3;break;case"AAAsmall":r=i>=7;break}return r},A.mostReadable=function(s,t,e){var i=null,n=0,r,a,l,h;e=e||{},a=e.includeFallbackColors,l=e.level,h=e.size;for(var d=0;d<t.length;d++)r=A.readability(s,t[d]),r>n&&(n=r,i=A(t[d]));return A.isReadable(s,i,{level:l,size:h})||!a?i:(e.includeFallbackColors=!1,A.mostReadable(s,["#fff","#000"],e))};var $t=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"},Ci=A.hexNames=Mi($t);function Mi(s){var t={};for(var e in s)s.hasOwnProperty(e)&&(t[s[e]]=e);return t}function Se(s){return s=parseFloat(s),(isNaN(s)||s<0||s>1)&&(s=1),s}function B(s,t){Ai(s)&&(s="100%");var e=Ti(s);return s=Math.min(t,Math.max(0,parseFloat(s))),e&&(s=parseInt(s*t,10)/100),Math.abs(s-t)<1e-6?1:s%t/parseFloat(t)}function Mt(s){return Math.min(1,Math.max(0,s))}function P(s){return parseInt(s,16)}function Ai(s){return typeof s=="string"&&s.indexOf(".")!=-1&&parseFloat(s)===1}function Ti(s){return typeof s=="string"&&s.indexOf("%")!=-1}function X(s){return s.length==1?"0"+s:""+s}function dt(s){return s<=1&&(s=s*100+"%"),s}function ke(s){return Math.round(parseFloat(s)*255).toString(16)}function De(s){return P(s)/255}var W=function(){var s="[-\\+]?\\d+%?",t="[-\\+]?\\d*\\.\\d+%?",e="(?:"+t+")|(?:"+s+")",i="[\\s|\\(]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")\\s*\\)?",n="[\\s|\\(]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")\\s*\\)?";return{CSS_UNIT:new RegExp(e),rgb:new RegExp("rgb"+i),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+i),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+i),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(s){return!!W.CSS_UNIT.exec(s)}function Si(s){s=s.replace(ri,"").replace(ai,"").toLowerCase();var t=!1;if($t[s])s=$t[s],t=!0;else if(s=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var e;return(e=W.rgb.exec(s))?{r:e[1],g:e[2],b:e[3]}:(e=W.rgba.exec(s))?{r:e[1],g:e[2],b:e[3],a:e[4]}:(e=W.hsl.exec(s))?{h:e[1],s:e[2],l:e[3]}:(e=W.hsla.exec(s))?{h:e[1],s:e[2],l:e[3],a:e[4]}:(e=W.hsv.exec(s))?{h:e[1],s:e[2],v:e[3]}:(e=W.hsva.exec(s))?{h:e[1],s:e[2],v:e[3],a:e[4]}:(e=W.hex8.exec(s))?{r:P(e[1]),g:P(e[2]),b:P(e[3]),a:De(e[4]),format:t?"name":"hex8"}:(e=W.hex6.exec(s))?{r:P(e[1]),g:P(e[2]),b:P(e[3]),format:t?"name":"hex"}:(e=W.hex4.exec(s))?{r:P(e[1]+""+e[1]),g:P(e[2]+""+e[2]),b:P(e[3]+""+e[3]),a:De(e[4]+""+e[4]),format:t?"name":"hex8"}:(e=W.hex3.exec(s))?{r:P(e[1]+""+e[1]),g:P(e[2]+""+e[2]),b:P(e[3]+""+e[3]),format:t?"name":"hex"}:!1}function ki(s){var t,e;return s=s||{level:"AA",size:"small"},t=(s.level||"AA").toUpperCase(),e=(s.size||"small").toLowerCase(),t!=="AA"&&t!=="AAA"&&(t="AA"),e!=="small"&&e!=="large"&&(e="small"),{level:t,size:e}}function Ee(s,t,e,{fillColor:i,strokeColor:n,candleWidth:r,strokeWidth:a},l){const h=y=>e.scales.x.convert(y),d=y=>e.scales.y.convert(y),g=h(t.open_time),_=d(t.open),m=d(t.close),p=e.trade.timeRange.includes(t.open_time.getTime()),v=e.trade.timeRange.length&&!p,b=y=>v?A.mix(y,l).toString():y;s.fillStyle=b(i),s.strokeStyle=b(n),s.lineWidth=a,s.beginPath(),s.moveTo(g,d(t.high)),s.lineTo(g,d(t.low)),s.stroke();const x=Math.min(_,m),C=Math.abs(m-_),w=g-r/2;s.fillRect(w,x,r,C),s.strokeRect(w,x,r,C)}function Di(s,t){const{strokeWidth:e,style:i}=t.config.candles,{candles:n,bg:r}=t.colorScheme,a=t.config.candles.baseWidth*t.scales.factorX;t.candles.missingData.forEach((l,h)=>{const d=n.noDataFill[h%n.noDataFill.length],g=i==="filled"?d:n.noDataStroke;Ee(s,l,t,{fillColor:d,strokeColor:g,candleWidth:a,strokeWidth:e},r)})}function Ei(s,t){const{strokeWidth:e,style:i}=t.config.candles,n=t.config.candles.baseWidth*t.scales.factorX,{candles:r,bg:a}=t.colorScheme,[l,h]=t.scales.x.domain();t.candles.preparedData.filter(_=>_.open_time>=l&&_.open_time<=h).forEach(_=>{const m=_.close>=_.open?"up":"down",p=m==="up"?r.risingFill:r.fallingFill,v=m==="up"?r.risingStroke:r.fallingStroke;Ee(s,_,t,{fillColor:p,strokeColor:i==="filled"?p:v,candleWidth:n,strokeWidth:e},a)})}class Li{static renderAll(t,e){Di(t,e),Ei(t,e)}}const Ni=10;function Ii(s,t){const{layout:{xAxis:e},colorScheme:{xAxis:i},config:{xAxis:n},scales:r}=t,a=r.x.ticks(Ni),l=g=>g.getHours()===0&&g.getMinutes()===0,h=D.timeFormat("%d %b"),d=D.timeFormat("%H:%M");s.save(),s.fillStyle=i.bg,s.fillRect(e.x,e.y,e.width,e.height),s.restore(),s.fillStyle=i.text,s.font=`${n.text.fontSize} ${n.text.font}`,s.textAlign="center",s.textBaseline="middle",a.forEach(g=>{const _=r.x.convert(g),m=l(g)?h(g):d(g);s.fillText(m,_,e.y+e.height/2)})}function Fi(s,t){const{layout:{yAxis:e},colorScheme:{yAxis:i},config:{yAxis:n},scales:r}=t,a=r.y.ticks(6),l=r.y.tickFormat(6);s.save(),s.fillStyle=i.bg,s.fillRect(e.x,e.y,e.width,e.height),s.restore(),s.fillStyle=i.text,s.font=`${n.text.fontSize} ${n.text.font}`,s.textAlign="center",s.textBaseline="middle",a.forEach(h=>{const d=r.y.convert(h),g=l(h);s.fillText(g,e.x+e.width/2,d)})}const Bi=(s,t)=>{const{layout:{axisIntersection:e},colorScheme:i}=t;s.save(),s.fillStyle=i.axisIntersection,s.fillRect(e.x,e.y,e.width,e.height),s.restore()};class Ot{static xAxis(t,e){Ii(t,e)}static yAxis(t,e){Fi(t,e)}static intersection(t,e){Bi(t,e)}}class Hi{constructor(t){c(this,"_target");this._target=t}mousemove(t){this._target.addEventListener("mousemove",t)}mouseleave(t){this._target.addEventListener("mouseleave",t)}mousedown(t){this._target.addEventListener("mousedown",t)}mouseup(t){this._target.addEventListener("mouseup",t)}wheel(t){this._target.addEventListener("wheel",t)}dblclick(t){this._target.addEventListener("dblclick",t)}contextmenu(t){this._target.addEventListener("contextmenu",t)}}class V{static line(t,{lineColor:e,type:i,x:n,y:r,lineLength:a}){t.save(),t.strokeStyle=e||"#777777",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(n,r),t.lineTo(n+(i==="h"?a:0),r+(i==="v"?a:0)),t.stroke(),t.restore()}static _basicLabel(t,{text:e,mainColor:i,textColor:n,position:r}){t.textContent=e,t.style.backgroundColor=i??"#777777",t.style.color=n??"#ffffff",t.style[r]="0px"}static label_h(t,{text:e,y:i,mainColor:n,textColor:r,position:a}){V._basicLabel(t,{text:e,mainColor:n,textColor:r,position:a}),t.style.top=i+"px",t.style.transform="translateY(-50%)"}static label_v(t,{text:e,x:i,mainColor:n,textColor:r,position:a}){V._basicLabel(t,{text:e,mainColor:n,textColor:r,position:a}),t.style.left=i+"px",t.style.transform="translateX(-50%)"}static horizontalMarker({node:t,ctx:e,x:i,y:n,lineLength:r,text:a,textColor:l,mainColor:h,lineColor:d,position:g}){V.line(e,{type:"h",x:i,y:n,lineLength:r,lineColor:d}),V.label_h(t,{text:a,y:n,textColor:l,mainColor:h,position:g})}static verticalMarker({node:t,ctx:e,x:i,y:n,lineLength:r,text:a,textColor:l,mainColor:h,lineColor:d,position:g}){V.line(e,{type:"v",x:i,y:n,lineLength:r,lineColor:d}),V.label_v(t,{text:a,x:i,textColor:l,mainColor:h,position:g})}}class Ri{constructor(t,e){c(this,"_canvas");c(this,"_parent");c(this,"_horizontalMarker");c(this,"_verticalMarker");this._canvas=e;const i=new S({tag:"div",className:"sc-charts-cs__guide-markers"});this._parent=i;const n=new S({tag:"div",className:"sc-charts-cs__guide-marker sc-charts-cs__guide-marker-h"}),r=new S({tag:"div",className:"sc-charts-cs__guide-marker sc-charts-cs__guide-marker-v"});this._horizontalMarker=n,this._verticalMarker=r,i.append(n.node),i.append(r.node),t.append(i.node),this.hide()}update(t){this._verticalMarker.node.style.display=t.isShowX?"flex":"none",this._horizontalMarker.node.style.display=t.isShowY?"flex":"none"}hide(){this._verticalMarker.node.style.display="none",this._horizontalMarker.node.style.display="none",this._canvas.clear()}show(){this._verticalMarker.node.style.display="flex",this._horizontalMarker.node.style.display="flex"}render(t,{x:e,y:i}){this._canvas.clear();const{layout:{area:n,chart:r},config:{guides:a,yAxis:l,xAxis:h},colorScheme:{guides:{horizontalMarker:d,verticalMarker:g}}}=t;a.isShowY&&V.horizontalMarker({ctx:this._canvas.ctx,node:this._horizontalMarker.node,x:n.left,y:i,lineLength:r.width,text:t.scales.y.invert(i).toFixed(2),position:l.position,mainColor:d.main,lineColor:d.line,textColor:d.text}),a.isShowX&&V.verticalMarker({ctx:this._canvas.ctx,node:this._verticalMarker.node,text:D.timeFormat("%a %d, %b %y %H:%M")(t.scales.x.invert(e)),position:h.position,x:e,y:n.top,lineLength:r.height,mainColor:g.main,lineColor:g.line,textColor:g.text})}clear(){this._canvas.clear(),this._parent.remove()}}function At(s){return s*.1875}const zi=(s,{mainColor:t,textColor:e,symbol:i,x:n,y:r,size:a,fontSize:l})=>{const _=a/16,m=16*_,p=n-m/2,v=r;s.save(),s.translate(p,v),s.scale(_,_),s.beginPath(),s.moveTo(7.85696,.288512),s.lineTo(4.53377,3.11938),s.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),s.lineTo(11.2275,4),s.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),s.lineTo(8.52156,.302869),s.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),s.closePath(),s.fillStyle=t,s.fill(),s.beginPath(),s.moveTo(0,7),s.bezierCurveTo(0,4.79086,1.79086,3,4,3),s.lineTo(12,3),s.bezierCurveTo(14.2091,3,16,4.79086,16,7),s.lineTo(16,15),s.bezierCurveTo(16,17.2091,14.2091,19,12,19),s.lineTo(4,19),s.bezierCurveTo(1.79086,19,0,17.2091,0,15),s.lineTo(0,7),s.closePath(),s.fillStyle=t,s.fill(),s.restore(),s.save(),s.font=`bold ${l}px sans-serif`,s.textAlign="center",s.textBaseline="top",s.textAlign="center",s.textBaseline="middle";const b=r+_*3+.5,x=_*16,C=b+x/2;s.fillStyle=e,s.fillText(i,n,C),s.restore()},$i=(s,{mainColor:t,textColor:e,symbol:i,x:n,y:r,size:a,fontSize:l})=>{const _=a/16,m=16*_,p=n-m/2,v=r;s.save(),s.translate(p,v),s.scale(_,-_),s.beginPath(),s.moveTo(7.85696,.288512),s.lineTo(4.53377,3.11938),s.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),s.lineTo(11.2275,4),s.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),s.lineTo(8.52156,.302869),s.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),s.closePath(),s.fillStyle=t,s.fill(),s.beginPath(),s.moveTo(0,7),s.bezierCurveTo(0,4.79086,1.79086,3,4,3),s.lineTo(12,3),s.bezierCurveTo(14.2091,3,16,4.79086,16,7),s.lineTo(16,15),s.bezierCurveTo(16,17.2091,14.2091,19,12,19),s.lineTo(4,19),s.bezierCurveTo(1.79086,19,0,17.2091,0,15),s.lineTo(0,7),s.closePath(),s.fillStyle=t,s.fill(),s.restore(),s.save(),s.font=`bold ${l}px sans-serif`,s.textAlign="center",s.textBaseline="middle";const b=_*16,x=r-_*19+b/2;s.fillStyle=e,s.fillText(i,n,x),s.restore()};function Oi(s,t){const{trade:{tradedCandles:e},scales:{x:i,y:n},colorScheme:r}=t,{trade:a}=r,l=4;e.forEach(({isHovered:h,isActive:d,candle:g,trades:_})=>{const m=i.convert(g.open_time);_.forEach(p=>{const v=p.type==="buy",b=v?a.buyLabel.text:a.sellLabel.text,x=v?"B":"S",C=v?n.convert(g.low)+l:n.convert(g.high)-l,w=v?zi:$i;let y=v?a.buyLabel.main:a.sellLabel.main;h&&h[1]&&h[0]===p.type&&(y=A.mix(y,r.bg,20).toString()),d&&d[1]&&d[0]===p.type&&(y=a.activeLabel),w(s,{x:m,y:C,symbol:x,mainColor:y,textColor:b,size:16,fontSize:12})})})}function Pi(s,t){const{scales:{x:e,factorX:i},layout:{area:n},trade:{tradedCandles:r,exits:a,entries:l},config:{candles:h},colorScheme:{trade:d}}=t;if(r.length===0)return;const g=r.map(m=>m.candle).sort((m,p)=>m.open_time.getTime()-p.open_time.getTime()),_=h.baseWidth/2*i+h.strokeWidth/2;if(s.save(),s.lineWidth=1,s.strokeStyle=d.tradeBorders,l.length){const m=e.convert(g[0].open_time)-_;s.beginPath(),s.moveTo(m,n.y),s.lineTo(m,n.y+n.height),s.stroke()}if(a.length){const m=e.convert(g[g.length-1].open_time)+_;s.beginPath(),s.moveTo(m,n.y),s.lineTo(m,n.y+n.height),s.stroke()}s.restore()}const Yi=(s,t)=>{const{scales:{x:e,y:i},trade:{tradedCandles:n,entries:r,exits:a},colorScheme:{trade:l}}=t;s.save();const h=g=>{var _;return(_=n.find(m=>g.getTime()>=m.candle.open_time.getTime()&&g.getTime()<m.candle.close_time.getTime()))==null?void 0:_.candle},d=(g,_)=>{const m=h(g.time),p=h(_.time);if(!m||!p)return;const v=e.convert(m.open_time),b=e.convert(p.open_time);let x,C;g.type==="buy"?(x=i.convert(m.low),C=i.convert(p.high)):(x=i.convert(m.high),C=i.convert(p.low)),s.beginPath(),s.setLineDash([4,4]),s.strokeStyle=l.connectionLine,s.moveTo(v,x),s.lineTo(b,C),s.stroke(),s.setLineDash([])};if(r.length===1&&a.length>1)a.forEach(g=>d(r[0],g));else if(a.length===1&&r.length>1)r.forEach(g=>d(g,a[0]));else if(r.length===1&&a.length===1)d(r[0],a[0]);else if(r.length>0&&a.length>0){const g=r.reduce((m,p)=>m.time<p.time?m:p),_=a.reduce((m,p)=>m.time>p.time?m:p);d(g,_)}s.restore()};class Le extends S{constructor({className:e,isAdaptPosition:i}={}){super({tag:"div",className:e});c(this,"_isAdaptPosition");this._isAdaptPosition=!!i}show({x:e,y:i,parent:n,offset:r=8}){let a=e+r,l=i+r;if(this._isAdaptPosition){this.updateAbsolutePosition();const h=this.absolutePosition,d={top:0,left:0,bottom:n.bottom-n.top,right:n.right-n.left};a+h.width>d.right&&(a=e-h.width-r,a<d.left+r&&(a=d.left+r)),l+h.height>d.bottom&&(l=i-h.height-r,l<d.top+r&&(l=d.top+r))}this.node.style.opacity="1",this.node.style.visibility="visible",this.node.style.left=`${a}px`,this.node.style.top=`${l}px`}hide(){this.node.style.opacity="0",this.node.style.visibility="hidden"}}class ji extends Le{constructor(){super({className:"sc-charts-cs__trade-label-tooltip",isAdaptPosition:!0});c(this,"_title");c(this,"_manyBox");c(this,"_oneBox");this._title=new S({tag:"div",className:"sc-charts-cs__trade-label-tooltip-title"}),this._manyBox=new S({tag:"div",className:"sc-charts-cs__trade-label-tooltip-box_many"}),this._oneBox=new S({tag:"div",className:"sc-charts-cs__trade-label-tooltip-box_one"}),this.node.append(this._title.node,this._oneBox.node,this._manyBox.node)}_createLineNodes(e,i){const n=[];for(const r of Object.keys(i))if(r in e){const a=new S({tag:"div",className:`sc-charts-cs__trade-label-tooltip-line
|
|
3
|
-
sc-charts-cs__trade-label-tooltip-line-key-${r}`});let l=e[r].toString();r==="kind"&&(l=this._formatDate(e.time));const h=new S({tag:"strong",textContent:i[r]}),d=new S({tag:"span",textContent:l});a.append(h.node,d.node),n.push(a.node)}return n}_formatDate(e){const i=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short",year:"numeric",hour12:!1}).format(e),[n,r,a]=i.split(", ");return`${n}, ${r} ${a}`}_clearTooltip(){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()}updateContent(e){if(e.length){if(this._clearTooltip(),e.length===1){this._title.node.style.display="flex",this._oneBox.node.style.display="flex",this._title.node.textContent=this._formatDate(e[0].time);const i=this._createLineNodes(e[0],{price:"Price:",profit:"Realized P&L:",volume:"Volume:",percentage:"% of position:"});this._oneBox.append(...i),this.node.append(this._title.node,this._oneBox.node)}else if(e.length>1){this._manyBox.node.style.display="flex";const i=e.map(n=>{const r=new S({tag:"div"}),a=this._createLineNodes(n,{kind:n.kind==="entry"?"Entry:":"Exit:",price:"Price:"});return r.append(...a),r.node});this._manyBox.append(...i),this.node.append(this._manyBox.node)}}}}const Xi=s=>{const t=Math.floor((Date.now()-+s)/1e3),e=[[60,1,"s"],[3600,60,"m"],[86400,3600,"h"],[604800,86400,"d"],[2629746,604800,"w"],[31556952,2629746,"mo"],[1/0,31556952,"y"]],[,i,n]=e.find(([a])=>t<a);return`${Math.floor(t/i)}${n} ago`};function Wi(s){const t=Math.floor(s/1e3),e=[{label:"d",value:86400},{label:"h",value:3600},{label:"m",value:60},{label:"s",value:1}],i=[];let n=t;for(const{label:r,value:a}of e)if(n>=a){const l=Math.floor(n/a);if(i.push(`${l}${r}`),n%=a,i.length===2)break}return i.length?i.join(" "):"0s"}const Vi=10,Gi=6,Ui=4,Zi=12,qi=(s,t)=>{var G;const{scales:{x:e,y:i},trade:{entries:n,exits:r,holdTime:a},colorScheme:{trade:{hold:l}},config:{trade:{showHoldTime:h}}}=t;if(!h)return;const d=n.at(0),g=r.at(-1);if(!d||!g)return;const _=e.convert(d.candle.open_time),m=e.convert(g.candle.open_time),p=i.convert(((G=n.at(0))==null?void 0:G.price)??0);s.beginPath(),s.setLineDash([4,4]),s.strokeStyle=l.main,s.moveTo(_,p),s.lineTo(m,p),s.stroke(),s.setLineDash([]);const v=(_+m)/2,b=`Hold: ${Wi(a)}`,C=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();s.font=`600 ${Vi}px ${C}`;const y=s.measureText(b).width+Gi*2,T=Zi+Ui*2,E=v-y/2,N=p-T/2,z=4;s.beginPath(),s.fillStyle=l.main,s.lineWidth=1,s.moveTo(E+z,N),s.lineTo(E+y-z,N),s.quadraticCurveTo(E+y,N,E+y,N+z),s.lineTo(E+y,N+T-z),s.quadraticCurveTo(E+y,N+T,E+y-z,N+T),s.lineTo(E+z,N+T),s.quadraticCurveTo(E,N+T,E,N+T-z),s.lineTo(E,N+z),s.quadraticCurveTo(E,N,E+z,N),s.closePath(),s.fill(),s.fillStyle=l.text,s.textBaseline="middle",s.textAlign="center",s.fillText(b,v,p),s.restore()};class Ji{constructor({domParent:t,canvasParent:e,width:i,height:n}){c(this,"_canvas");c(this,"_labelTooltip");this._canvas=new wt({className:"sc-charts-cs__canvas-trade",width:i,height:n}),this._labelTooltip=new ji,e.append(this._canvas.node),t.append(this._labelTooltip.node)}get canvas(){return this._canvas}get labelTooltip(){return this._labelTooltip}renderAll(t){this._canvas.clear(),Pi(this._canvas.ctx,t),Oi(this._canvas.ctx,t),Yi(this._canvas.ctx,t),qi(this._canvas.ctx,t)}}class Qi{constructor(t,e){c(this,"canvas");c(this,"parent");c(this,"items",{});c(this,"className");this.className=e,this.canvas=new wt({width:t.width,height:t.height,className:`${e}-canvas`}),t.canvasesContainer.append(this.canvas.node),this.parent=new S({tag:"div",className:e}),t.domElements.append(this.parent.node)}render(t){const e=new Set(t.map(this.getIdFromMarker));this.canvas.clear(),this.removeObsoleteItems(e);for(const i of t){const n=this.getIdFromMarker(i),r=this.items[n]??this.createMarkerElement(n);this.renderMarker(i,r.node)}}clear(){this.canvas.clear(),this.parent.remove()}getIdFromMarker(t){const e=t.type==="horizontal"?"h":"v",i=t.value instanceof Date?t.value.getTime().toString():t.value.toString().replace(".","d");return`${e}_${i}`}removeObsoleteItems(t){for(const e in this.items)t.has(e)||(this.items[e].remove(),delete this.items[e])}createMarkerElement(t){const e=new S({tag:"div",className:`${this.className}-item`});return this.parent.append(e.node),this.items[t]=e,e}renderMarker(t,e){t.type==="horizontal"?V.horizontalMarker({ctx:this.canvas.ctx,node:e,...t}):V.verticalMarker({ctx:this.canvas.ctx,node:e,...t})}}class Ki extends Le{constructor(){super({className:"sc-charts-cs__candle-tooltip_nodata",isAdaptPosition:!0});const t=new S({tag:"p"});t.node.textContent="No data from broker",this.append(t.node)}}class tt extends S{constructor(e){super(e);c(this,"_state",{});c(this,"_updateScheduled",!1)}get state(){return this._state}set state(e){this._state=new Proxy(e,{set:(i,n,r)=>{if(typeof n!="string")return!0;const a=n;return i[a]===r||(i[a]=r,this._scheduleUpdate()),!0}})}setState(e){Object.assign(this.state,e)}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,requestAnimationFrame(()=>{this._updateScheduled=!1,this.render()}))}render(){}destroy(){this._updateScheduled=!1,this.remove()}forceUpdate(){this._scheduleUpdate()}}const tn="sc-charts-cs";class J{constructor(t){c(this,"block");this.block=t}gen(t){return`${tn}__${this.block}${t?"-"+t:""}`}}const Pt=new J("comment-actions");class en extends S{constructor({onDelete:t,onUpdate:e}){super({className:Pt.gen()});const i=new S({tag:"button",className:Pt.gen("edit"),textContent:"Edit"}),n=new S({tag:"button",className:Pt.gen("delete"),textContent:"Delete"});n.node.addEventListener("click",r=>{r.stopPropagation(),t()}),i.node.addEventListener("click",r=>{r.stopPropagation(),e()}),this.append(i.node,n.node)}}function Yt(s,t){var n;const e=r=>{if(!document.contains(s.node))return;const a=r.target;if(s.node.contains(a))return;const l=document.elementFromPoint(r.clientX,r.clientY);if(l&&s.node.contains(l))return;const h=s.node.getBoundingClientRect();r.clientX>=h.left&&r.clientX<=h.right&&r.clientY>=h.top&&r.clientY<=h.bottom&&getComputedStyle(s.node).pointerEvents!=="none"||t(r)};document.addEventListener("mousedown",e);const i=(n=s.destroy)==null?void 0:n.bind(s);return s.destroy=()=>{document.removeEventListener("mousedown",e),i==null||i()},s}class sn{constructor(){c(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","18"),e.setAttribute("height","4"),e.setAttribute("viewBox","0 0 18 4"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=[{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 i){const r=document.createElementNS(t,"path");r.setAttribute("d",n.d),n.fill&&r.setAttribute("fill",n.fill),n.stroke&&(r.setAttribute("stroke",n.stroke),r.setAttribute("stroke-width","2"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round")),e.appendChild(r)}this.node=e}}const ut=new J("comment-list");class nn extends S{constructor({onDelete:e,onOpenEditor:i,comment:n,layout:r}){super({className:ut.gen("item")});c(this,"actionTooltip");c(this,"actionsTrigger");const a=new S({className:ut.gen("text"),textContent:n.text}),l=new S({className:ut.gen("created-at"),textContent:Xi(new Date(n.createdAt))});this.actionsTrigger=new S({tag:"button",className:ut.gen("action-trigger")});const h=new en({onDelete:e,onUpdate:i});this.actionTooltip=Yt(h,()=>{this.actionTooltip.setVisible(!1)}),this.actionsTrigger.node.addEventListener("click",()=>{this.actionsTrigger.updateAbsolutePosition(),this.actionTooltip.updateAbsolutePosition(),this.actionTooltip.node.style.top=this.actionsTrigger.absolutePosition.top-r.chart.top+20+"px",this.actionTooltip.node.style.left=this.actionsTrigger.absolutePosition.left-r.chart.left-this.actionTooltip.absolutePosition.width+10+"px",this.actionTooltip.setVisible(!0)});const d=new S({className:ut.gen("text-wrap")});this.actionTooltip.node.setAttribute("id",`ac-${n.id}`),d.append(a.node,this.actionsTrigger.node),this.actionsTrigger.append(new sn().node),this.append(d.node,l.node)}}class rn{constructor(){c(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","14"),e.setAttribute("height","12"),e.setAttribute("viewBox","0 0 14 12"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class an{constructor(){c(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","10"),e.setAttribute("height","10"),e.setAttribute("viewBox","0 0 10 10"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.setAttribute("fill-rule","evenodd"),i.setAttribute("clip-rule","evenodd"),i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class on extends tt{constructor(e){super({className:"sc-charts-cs__comments-edit"});c(this,"input");c(this,"saveBtn");c(this,"cancelBtn");c(this,"_onSave");c(this,"_onCancel");this._onSave=e.onSave,this._onCancel=e.onCancel,this.input=new S({tag:"textarea",className:"sc-charts-cs__comments-edit-input"}),this.saveBtn=new S({tag:"button",className:"sc-charts-cs__comments-edit-save-btn"}),this.saveBtn.append(new rn().node),this.cancelBtn=new S({tag:"button",className:"sc-charts-cs__comments-edit-cancel-btn"}),this.cancelBtn.append(new an().node);const i=new S({className:"sc-charts-cs__comments-edit-btn-container"});i.append(this.cancelBtn.node,this.saveBtn.node),this.append(this.input.node,i.node),this.state={inputValue:e.initialValue||"",hasInitFocused:!1},this._setupListeners(),this.render()}_setupListeners(){this.saveBtn.node.addEventListener("click",()=>{this._onSave(this.state.inputValue)}),this.input.node.addEventListener("input",e=>{const i=e.target;this.setState({inputValue:i.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 ln=new J("comment-list");class cn extends tt{constructor(e,i,n,r={}){super({tag:"ul",className:ln.gen(),...r});c(this,"_elements",{});c(this,"_model");c(this,"_view");this._model=i,this._view=n,this.state={items:e,editId:null},this.render()}render(){this.node.replaceChildren(),this._elements={},this.state.items.forEach((e,i)=>{this._elements[e.id]={order:i+1,element:this._createItem(e)}}),this.append(...this._sortedNodes())}_createItem(e){if(this.state.editId===e.id)return new on({onSave:r=>{this._model.comments.update(e.id,r),this.setState({editId:null})},onCancel:()=>{this.setState({editId:null})},initialValue:e.text});const i=new nn({onDelete:()=>{this._model.comments.remove(e.id),i.actionTooltip.setVisible(!1)},onOpenEditor:()=>{this.setState({editId:e.id}),i.actionTooltip.setVisible(!1)},comment:e,layout:this._model.layout}),n=document.querySelector(`#ac-${e.id}`);return n?n.replaceWith(i.actionTooltip.node):this._view.domElements.append(i.actionTooltip.node),i}_sortedNodes(){return Object.values(this._elements).sort((e,i)=>e.order-i.order).map(e=>e.element.node)}}class hn{constructor(){c(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","14"),e.setAttribute("height","14"),e.setAttribute("viewBox","0 0 14 14"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),e.appendChild(i),this.node=e}}const Tt=new J(""),jt=new J("add-field");class Ne extends tt{constructor({onAdd:e,blockName:i}){Tt.block=i;super({className:Tt.gen()+" "+jt.gen()});c(this,"btn");c(this,"input");c(this,"_onAdd");this._onAdd=e,this.state={inputValue:""},this.input=new S({tag:"input",className:Tt.gen("input")+" "+jt.gen("input")}),this.input.node.setAttribute("placeholder","Add comment..."),this.btn=new S({tag:"button",className:Tt.gen("btn")+" "+jt.gen("btn")}),this.btn.append(new hn().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",e=>{e.key==="Enter"&&!this.btn.node.disabled&&this._addComment()}),this.input.node.addEventListener("input",e=>{const i=e.target;this.setState({inputValue:i.value})})}render(){this.btn.node.disabled=!this.state.inputValue.trim()}}const dn=new J("list-tooltip"),Xt=8;class un extends tt{constructor(e,i,n){super({className:dn.gen()});c(this,"_list");c(this,"_addField");c(this,"_size",null);c(this,"_model");c(this,"_prevIsShow",!1);this._model=i,this.state={isShow:!1,comments:e},this._list=new cn(e,i,n),this._addField=new Ne({blockName:"list-tooltip-add",onAdd:r=>{const a=e[0].date,l=e[0].price,h={id:crypto.randomUUID(),text:r,date:a,price:l,createdAt:new Date().toISOString()};i.comments.add(h)}}),this.node.append(this._list.node,this._addField.node)}render(){const{isShow:e,comments:i}=this.state,{width:n,height:r}=this._model.layout.area;this._prevIsShow!==e&&(this._list.forceUpdate(),this._prevIsShow=e),this.node.style.maxHeight=r/2-Xt+"px",this.setVisible(e),e&&!this._size&&(this.updateAbsolutePosition(),this._size=this.absolutePosition,this.position(n/2-this._size.width-Xt,r/2+Xt)),this._list.setState({items:i}),requestAnimationFrame(()=>{this._list.node.scrollTop=this._list.node.scrollHeight})}get list(){return this._list}}class gn{constructor(){c(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class _n extends tt{constructor({x:e,...i},n){super(i);c(this,"_colors");this._colors=n.colorScheme.comments.scaleAnchor,this.state={x:e,y:n.layout.xAxis.top,isActive:!1},this.node.append(new gn().node),this.render()}render(){const{x:e,y:i,isActive:n}=this.state;this.position({x:e,y:i});const r=n?"Active":"Inactive";this.node.style.backgroundColor=this._colors[`bg${r}`],this.node.style.color=this._colors[`icon${r}`]}}const Ie=new J("comment-box");class fn extends tt{constructor({boxId:e,model:i,view:n,comments:r,coords:a,onBoxActivate:l,onBoxDeactivate:h}){super({className:Ie.gen()});c(this,"pointer",new S({className:"sc-charts-cs__comments-pointer"}));c(this,"tooltip");c(this,"anchor");c(this,"_onBoxActivate");c(this,"_onBoxDeactivate");c(this,"_boxId");this._boxId=e,this._onBoxActivate=l,this._onBoxDeactivate=h,this.state={isActive:!1,comments:r,coords:a},this.pointer.position(a),this.anchor=new _n({x:a.x,className:Ie.gen("anchor")},i),this.anchor.node.addEventListener("click",()=>{const d=!this.state.isActive;d?this._onBoxActivate(this._boxId):this._onBoxDeactivate(this._boxId),this.setState({isActive:d})}),this.tooltip=Yt(new un(r,i,n),d=>{this.state.isActive&&(this.anchor.node.contains(d.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:e,comments:i,coords:n}=this.state;this.pointer.position(n),this.pointer.setVisible(e),this.anchor.setState({x:n.x,isActive:e}),this.tooltip.setState({comments:i,isShow:e})}}class mn{static animateTo(t,e,i,n){const r=t.scales.panOffsetX+(t.layout.area.width/2-e),a=t.scales.panOffsetY+(t.layout.area.height/2-i),l=300,h=performance.now(),d=t.scales.panOffsetX,g=t.scales.panOffsetY,_=m=>{const p=m-h,v=Math.min(p/l,1),b=v*v*(3-2*v),x=d+(r-d)*b,C=g+(a-g)*b;t.scales.pan("x",x,"absolute"),t.scales.pan("y",C,"absolute"),v<1?requestAnimationFrame(_):n==null||n()};requestAnimationFrame(_)}static animateToDataCoords(t,e,i,n){const r=typeof e=="number"?t.scales.x.convert(new Date(e)):t.scales.x.convert(e),a=t.scales.y.convert(i);this.animateTo(t,r,a,n)}}const pn={"right-bottom":{dx:1,dy:1},"left-top":{dx:-1,dy:-1},"right-top":{dx:1,dy:-1},"left-bottom":{dx:-1,dy:1}},vn=({size:s,parent:t,coords:e,prioritySide:i="right-bottom",offset:n=8})=>{const{width:r,height:a}=s,l=t.right-t.left,h=t.bottom-t.top,d=w=>{const{dx:y,dy:T}=pn[w],E=e.x+(y===1?n:-r-n),N=e.y+(T===1?n:-a-n);return{x:E,y:N,side:w}},g=({x:w,y})=>w>=0&&y>=0&&w+r<=l&&y+a<=h,_=()=>{const w=e.y<0,y=e.y+a>h,T=e.x<0,E=e.x+r>l;return T&&w?"right-bottom":T&&y?"right-top":E&&w?"left-bottom":E&&y?"left-top":T?"right-bottom":E?"left-bottom":w?"right-bottom":y?"right-top":i},p=[i,"right-bottom","right-top","left-bottom","left-top"].filter((w,y,T)=>T.indexOf(w)===y),v=_();let b=null;for(const w of[v,...p]){const y=d(w);if(g(y)){b=y;break}}b||(b=d(v));const x=Math.min(Math.max(b.x,n),l-r-n),C=Math.min(Math.max(b.y,n),h-a-n);return{x,y:C,side:b.side}},Wt=new J("comments-context");class bn extends tt{constructor(){super({className:Wt.gen()});c(this,"pointer");c(this,"addField");c(this,"menu");c(this,"_size",null);c(this,"_model",null);c(this,"_candle",null);this.state={candle:null,isShow:!1,model:null},this.pointer=new S({className:Wt.gen("pointer")}),this.menu=new S({className:Wt.gen("menu")}),Yt(this.menu,()=>{this.setState({isShow:!1})}),this.addField=new Ne({blockName:"context-add",onAdd:e=>{!this._model||!this._candle||(this._model.comments.add({id:crypto.randomUUID(),text:e,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(e){this.addField.input.node.style.borderTopLeftRadius=e==="right-bottom"?"0px":"12px",this.addField.input.node.style.borderBottomRightRadius=e==="left-top"?"0px":"12px",this.addField.input.node.style.borderBottomLeftRadius=e==="right-top"?"0px":"12px",this.addField.input.node.style.borderTopRightRadius=e==="left-bottom"?"0px":"12px"}render(){const{candle:e,isShow:i,model:n}=this.state;if(this.setVisible(i),!n||!e)return;this._model=n,this._candle=e;const r={x:n==null?void 0:n.scales.x.convert(e.open_time),y:n==null?void 0:n.scales.y.convert((e.open+e.close)/2)};this.pointer.position(r),this._size||(this.menu.position(r),this.menu.updateAbsolutePosition());const a=vn({size:this.menu.absolutePosition,parent:n.layout.area,offset:9,coords:r});this._changeInputCorner(a.side),this.menu.position(a.x,a.y)}}class yn{constructor(t,e){c(this,"_container");c(this,"_boxes",{});c(this,"_contextMenu");c(this,"_view");this._container=new S({className:e}),this._contextMenu=new bn,this._view=t,t.domElements.append(this._container.node,this._contextMenu.node)}_getCandleCoords(t,e){return{x:t.scales.x.convert(e.open_time),y:t.scales.y.convert((e.open+e.close)/2)}}createBox({boxId:t,coords:e,model:i,comments:n}){const r=new fn({boxId:t,model:i,comments:n,coords:e,view:this._view,onBoxActivate:a=>{const l=n[0].candle;mn.animateToDataCoords(i,l.open_time,(l.open+l.close)/2),this._boxes[a].setState({isActive:!0})},onBoxDeactivate:a=>this._boxes[a].setState({isActive:!1})});this._boxes[t]=r,this._container.append(r.node)}render(t){this._contextMenu.setState({model:t}),this._contextMenu.forceUpdate();const e=t.comments.grouped,i=new Set(Object.keys(e));Object.entries(e).forEach(([n,r])=>{const a=this._getCandleCoords(t,r[0].candle),l={boxId:n,coords:a,comments:r};this._boxes[n]?this._boxes[n].setState({comments:r,coords:a}):this.createBox({...l,model:t})}),Object.keys(this._boxes).forEach(n=>{i.has(n)||(this._boxes[n].node.remove(),delete this._boxes[n])})}get contextMenu(){return this._contextMenu}get items(){return this._boxes}}class xn{constructor(t){c(this,"_container");c(this,"_width");c(this,"_height");c(this,"_wrapper");c(this,"_domElements");c(this,"_canvasesContainer");c(this,"_mainCanvas");c(this,"_guidesCanvas");c(this,"_bindingManager");c(this,"_userMarkers");c(this,"_guideMarkers");c(this,"_trade");c(this,"_noDataTooltip");c(this,"_comments");this._container=t,this._wrapper=new S({tag:"div",className:"sc-charts-cs"}),t.append(this._wrapper.node);const{width:e,height:i}=t.getBoundingClientRect();this._width=e,this._height=i,this._mainCanvas=new wt({className:"sc-charts-cs__canvas-main",width:e,height:i,isMain:!0}),this._guidesCanvas=new wt({className:"sc-charts-cs__canvas-guides",width:e,height:i}),this._domElements=new S({tag:"div",className:"sc-charts-cs__dom-elements"}),this._canvasesContainer=new S({tag:"div",className:"sc-charts-cs__canvases"}),this._noDataTooltip=new Ki,this._canvasesContainer.append(this._mainCanvas.node),this._wrapper.append(this._canvasesContainer.node,this._domElements.node),this._mainCanvas.updateAbsolutePosition(),this._bindingManager=new Hi(this._mainCanvas.node),this._userMarkers=new Qi(this,"sc-charts-cs__user-markers"),this._comments=new yn(this,"sc-charts-cs__comments"),this._trade=new Ji({width:e,height:i,canvasParent:this._canvasesContainer,domParent:this._domElements}),this._guideMarkers=new Ri(this._domElements,this._guidesCanvas),this._domElements.append(this._noDataTooltip.node),this._canvasesContainer.append(this._guidesCanvas.node)}get container(){return this._container}get width(){return this._width}get height(){return this._height}get wrapper(){return this._wrapper}get domElements(){return this._domElements}get canvasesContainer(){return this._canvasesContainer}get mainCanvas(){return this._mainCanvas}get guidesCanvas(){return this._guidesCanvas}get binding(){return this._bindingManager}get userMarkers(){return this._userMarkers}get guideMarkers(){return this._guideMarkers}get trade(){return this._trade}get noDataTooltip(){return this._noDataTooltip}get comments(){return this._comments}renderAll(t){this._mainCanvas.clear(),Li.renderAll(this._mainCanvas.ctx,t),Ot.xAxis(this._mainCanvas.ctx,t),Ot.yAxis(this._mainCanvas.ctx,t),Ot.intersection(this._mainCanvas.ctx,t),this._trade.renderAll(t),this._userMarkers.render(t.userMarkers.data),this._comments.render(t)}}class wn{constructor(t){c(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"});c(this,"ignoredLogEvents",[]);t&&(this.ignoredLogEvents=t)}log(t,e){if(this.ignoredLogEvents.includes(t))return;const i=this.logColors[t]||"color: gray";let n;try{n=JSON.parse(JSON.stringify(e))}catch{n=e}console.log(`%c[SUBSCRIBE] ${t}`,i,n)}}class Cn{constructor(t,e){c(this,"_model");c(this,"_view");c(this,"_enableLogging");c(this,"_logger");this._model=t,this._view=e,this._enableLogging=!1,this._logger=new wn(["scale_event"])}subscribeWithLogging(t,e){const i=n=>{this._enableLogging&&this._logger.log(t,n),e(n)};this._model.subscribe(t,i)}init(){this.subscribeWithLogging("init_model",()=>{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",t=>{this._model.config.update(t),this._model.layout.updateConfig(this._model.config),this._model.userMarkers.rebuild(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_candles",t=>{this._model.candles.update(t),this._model.scales.reinit(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_trade",t=>{this._model.trade.updateTrade(t),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_user_markers",t=>{this._model.userMarkers.updateMarkers(t),this._view.userMarkers.render(this._model.userMarkers.data)}),this.subscribeWithLogging("update_color_scheme",t=>{this._model.colorScheme.update(t),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("open_trade_label_tooltip",({trade:t,x:e,y:i})=>{this._model.trade.setActiveTrade(t.tradeType,t.candle.open_time.getTime()),this._view.trade.renderAll(this._model),this._view.trade.labelTooltip.updateContent(t.trades),this._view.trade.labelTooltip.show({x:e,y:i,parent:this._model.layout.chart})}),this.subscribeWithLogging("close_trade_label_tooltip",()=>{this._model.trade.setActiveTrade(null),this._view.trade.renderAll(this._model),this._view.trade.labelTooltip.hide()}),this.subscribeWithLogging("hover_nodata_candle",({x:t,y:e})=>{this._view.noDataTooltip.show({x:t,y:e,parent:this._model.layout.area})}),this.subscribeWithLogging("leave_nodata_candle",()=>{this._view.noDataTooltip.hide()}),this.subscribeWithLogging("mouseover_trade_label_tooltip",t=>{this._model.trade.setHoveredTrade(t.tradeType,t.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",t=>{this._model.comments.data=t,this._view.renderAll(this._model)})}}class Fe{constructor(){c(this,"_map",new Map)}add(t,e,i){let n=this._map.get(t);n||(n={},this._map.set(t,n)),n[e]||(n[e]=new Set),n[e].add(i)}remove(t,e,i){var r;const n=this._map.get(t);(r=n==null?void 0:n[e])==null||r.delete(i)}removeAll(t){this._map.delete(t)}emit(t,e){const i=this._map.get(t),n=i==null?void 0:i[e.type];if(!n)return!1;let r=!1;const a={...e,stopPropagation:()=>{r=!0}};for(const l of n)if(l(a),r)break;return r}}class Mn{constructor(){c(this,"_elements",[]);c(this,"_listeners",new Fe);c(this,"_lastHovered",new Set);c(this,"_dragContext",null)}get isDragging(){return this._dragContext!==null}register(...t){this._elements.push(...t)}unregister(t){this._elements=this._elements.filter(e=>e!==t),this._listeners.removeAll(t),this._lastHovered.delete(t)}clear(){this._elements=[],this._listeners=new Fe,this._lastHovered.clear()}on(t,e,i){this._listeners.add(t,e,i)}off(t,e,i){this._listeners.remove(t,e,i)}dispatchMouseMove(t,e){if(this._dragContext){this._emitSingle(this._dragContext.target,{type:"drag",target:this._dragContext.target,x:t,y:e,prevX:this._dragContext.lastX,prevY:this._dragContext.lastY}),this._dragContext.lastX=t,this._dragContext.lastY=e;return}const i=this._getHitsAt(t,e),n=new Set(i.map(r=>r.target));for(const r of i)if(!this._lastHovered.has(r.target)&&this._emitSingle(r.target,{type:"mouseover",target:r.target,x:r.x,y:r.y})||this._emitSingle(r.target,{type:"mousemove",target:r.target,x:r.x,y:r.y}))break;for(const r of this._lastHovered)n.has(r)||this._emitSingle(r,{type:"mouseleave",target:r,x:t,y:e});this._lastHovered=n}dispatchMouseDown(t,e){const i=this._getHitsAt(t,e);if(i.length===0){this._dragContext=null;return}this._dragContext=null;for(const n of i)if(this._emitSingle(n.target,{type:"mousedown",target:n.target,x:n.x,y:n.y})){this._dragContext={target:n.target,lastX:t,lastY:e};break}!this._dragContext&&i.length>0&&(this._dragContext={target:i[i.length-1].target,lastX:t,lastY:e})}dispatchMouseUp(t,e){this._dragContext&&this._emitSingle(this._dragContext.target,{type:"mouseup",target:this._dragContext.target,x:t,y:e}),this._dragContext=null}dispatchClick(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"click",target:n.target,x:n.x,y:n.y}))break}dispatchDblClick(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"dblclick",target:n.target,x:n.x,y:n.y}))break}dispatchContextMenu(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"contextmenu",target:n.target,x:n.x,y:n.y}))break}dispatchWheel(t,e,i,n,r){const a=this._getHitsAt(t,e);for(const l of a)if(this._emitSingle(l.target,{type:"wheel",target:l.target,x:l.x,y:l.y,deltaX:i,deltaY:n,deltaZ:r}))break}hitTestAll(t,e){return this._getHitsAt(t,e)}_getHitsAt(t,e){return this._elements.map(i=>i.hitTest(t,e)).filter(i=>i!==null)}_emitSingle(t,e){let i=!1;const n={...e,stopPropagation(){i=!0}};return this._listeners.emit(t,n),i}}class An{constructor(t){this.model=t}hitTest(t,e){const{candles:{missingData:i},scales:{x:n,y:r},config:{candles:{baseWidth:a}}}=this.model;for(const l of i){const h=n.convert(l.open_time),d=r.convert(l.high),g=r.convert(l.low),_=h-a/2,m=h+a/2,p=Math.min(d,g),v=Math.max(d,g);if(t>=_&&t<=m&&e>=p&&e<=v)return{target:this,x:t,y:e,type:"candle",candle:l}}return null}}class Tn{constructor(t,e){c(this,"_model");c(this,"_hitManager");c(this,"_hit");this._model=t,this._hitManager=e,this._hit=new An(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mouseover",t=>{const e=this._hit.hitTest(t.x,t.y);if(!e)return;const i=this._model.scales.x.convert(e.candle.open_time),n=this._model.scales.y.convert(e.candle.high)-4;this._model.eventBus.emit("hover_nodata_candle",{x:i,y:n})}),this._hitManager.on(this._hit,"mouseleave",()=>{this._model.eventBus.emit("leave_nodata_candle")})}}class Sn{constructor(t){this.model=t}hitTest(t,e){const{tradedCandles:i}=this.model.trade,{x:n,y:r}=this.model.scales,a=16,l=4;for(const{candle:h,trades:d}of i){const _=n.convert(h.open_time)+this.model.config.candles.baseWidth/2,m=a,p=a;for(const v of["buy","sell"]){const b=d.filter(y=>y.type===v);if(!b.length)continue;const x=v==="buy"?r.convert(h.low)+l+At(a):r.convert(h.high)-l-a-At(a),C=t>=_-m/2&&t<=_+m/2,w=e>=x&&e<=x+p;if(C&&w)return{target:this,type:"trade-label",tradeType:v,x:t,y:e,candle:h,trades:b}}}return null}}class kn{constructor(t,e){c(this,"_model");c(this,"_hitManager");c(this,"_tradeLabelHit");this._model=t,this._hitManager=e,this._tradeLabelHit=new Sn(t),this._hitManager.register(this._tradeLabelHit)}register(){this._hitManager.on(this._tradeLabelHit,"click",t=>{const e=this._tradeLabelHit.hitTest(t.x,t.y);if(!e)return;const i=this._model.scales.x.convert(e.candle.open_time),n=this._model.scales.y.convert(e.trades[0].type==="buy"?e.candle.low:e.candle.high),r=e.trades[0].type==="buy"?n+4+At(16)+8:n-4-16-At(16)+8;this._model.eventBus.emit("open_trade_label_tooltip",{trade:{candle:e.candle,trades:e.trades,tradeType:e.tradeType},x:i,y:r})}),this._hitManager.on(this._tradeLabelHit,"mouseover",t=>{const e=this._tradeLabelHit.hitTest(t.x,t.y);e&&this._model.eventBus.emit("mouseover_trade_label_tooltip",{candle:e.candle,trades:e.trades,tradeType:e.tradeType})}),this._hitManager.on(this._tradeLabelHit,"mouseleave",()=>{this._model.eventBus.emit("mouseleave_trade_label_tooltip")})}}class Dn{constructor(t){this.model=t}hitTest(t,e){const{xAxis:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"x-axis"}:null}}class En{constructor(t){this.model=t}hitTest(t,e){const{area:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"area"}:null}}class Ln{constructor(t){this.model=t}hitTest(t,e){const{yAxis:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"y-axis"}:null}}class Nn{constructor(t,e){c(this,"_model");c(this,"_hitManager");c(this,"_hit");this._model=t,this._hitManager=e,this._hit=new Dn(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"drag",t=>{const e=t.x-(t.prevX??t.x);this._model.scales.scale("x",-e)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.scale("x",1,"absolute"),this._model.scales.pan("x",0,"absolute")})}}class In{constructor(t,e){c(this,"_model");c(this,"_hitManager");c(this,"_hit");this._model=t,this._hitManager=e,this._hit=new Ln(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"drag",t=>{const e=t.y-(t.prevY??t.y);this._model.scales.scale("y",-e)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.fitYToVisibleCandles()})}}class Fn{constructor(t,e,i){c(this,"_model");c(this,"_view");c(this,"_hitManager");c(this,"_hit");this._model=t,this._view=e,this._hitManager=i,this._hit=new En(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mousemove",t=>{this._view.guideMarkers.show(),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})}),this._hitManager.on(this._hit,"mouseleave",()=>{this._view.guideMarkers.hide()}),this._hitManager.on(this._hit,"drag",t=>{const e=t.x-(t.prevX??t.x),i=t.y-(t.prevY??t.y);this._model.scales.pan("x",e),this._model.scales.pan("y",i),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})}),this._hitManager.on(this._hit,"contextmenu",({x:t})=>{const e=this._model.scales.x.invert(t),i=zt.findByDate(e,this._model.candles.allData);i&&(this._view.comments.contextMenu.setState({isShow:!0,candle:i}),this._view.comments.render(this._model))}),this._hitManager.on(this._hit,"wheel",t=>{var n,r;if(!t.deltaY)return;const e=-t.deltaY,i=(r=(n=this._model.config)==null?void 0:n.candles)==null?void 0:r.zoomOnWheel;["x","both"].includes(i)&&this._model.scales.scale("x",e),["y","both"].includes(i)&&this._model.scales.scale("y",e)})}}class Bn{constructor(t,e,i){c(this,"_hitManager");c(this,"_candlesHandler");c(this,"_tradeLabelsHandler");c(this,"_xAxisHandler");c(this,"_yAxisHandler");c(this,"_areaHandler");this._hitManager=i,this._candlesHandler=new Tn(t,this._hitManager),this._tradeLabelsHandler=new kn(t,this._hitManager),this._xAxisHandler=new Nn(t,this._hitManager),this._yAxisHandler=new In(t,this._hitManager),this._areaHandler=new Fn(t,e,this._hitManager)}register(){this._candlesHandler.register(),this._tradeLabelsHandler.register(),this._xAxisHandler.register(),this._yAxisHandler.register(),this._areaHandler.register()}}class Hn{constructor(t,e){c(this,"_model");c(this,"_view");c(this,"_subscriptionsManager");c(this,"_hitManager",new Mn);c(this,"_boundMouseMove",this.onDocumentMouseMove.bind(this));c(this,"_boundMouseUp",this.onDocumentMouseUp.bind(this));this._model=t,this._view=e,this._subscriptionsManager=new Cn(t,e)}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 Bn(this._model,this._view,this._hitManager).register()}onContextMenu(t){t.preventDefault();const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchContextMenu(e,i)}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(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchDblClick(e,i)}onDocumentClick(t){const e=this.getMouseRelative(t);this._hitManager.dispatchClick(e.x,e.y),!this._hitManager.hitTestAll(e.x,e.y).find(n=>n.type==="trade-label")&&this._model.trade.hasActiveTrade&&this._model.eventBus.emit("close_trade_label_tooltip")}getMouseRelative(t){return{x:t.clientX-this._view.mainCanvas.absolutePosition.left,y:t.clientY-this._view.mainCanvas.absolutePosition.top}}onDocumentMouseMove(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseMove(e,i)}onMouseDown(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseDown(e,i),t.preventDefault(),document.addEventListener("mouseup",this._boundMouseUp),this._hitManager.isDragging&&document.addEventListener("mousemove",this._boundMouseMove)}onMouseUp(t){const e=this.getMouseRelative(t);this._hitManager.dispatchMouseUp(e.x,e.y),document.removeEventListener("mouseup",this._boundMouseUp)}onDocumentMouseUp(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseUp(e,i),document.removeEventListener("mouseup",this._boundMouseUp),document.removeEventListener("mousemove",this._boundMouseMove)}onMouseMove(t){var r;if(!this._hitManager.isDragging){const{x:a,y:l}=this.getMouseRelative(t);this._hitManager.dispatchMouseMove(a,l)}const{x:e,y:i}=this.getMouseRelative(t),n=this._hitManager.hitTestAll(e,i);(r=n[0])!=null&&r.type&&(n[0].type==="area"?this._view.mainCanvas.node.style.cursor="crosshair":n[0].type==="trade-label"?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(t){t.preventDefault(),this._hitManager.dispatchWheel(t.offsetX,t.offsetY,t.deltaX,t.deltaY,t.deltaZ)}}class Rn{constructor(t,{chartId:e,candles:i,config:n,trade:r,userMarkers:a,colorScheme:l,comments:h}){c(this,"_model");c(this,"_view");c(this,"_controller");const d=document.querySelector(t);if(!d)throw new Error(`Element with selector "${t}" not found!`);if(!e||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(e))throw new Error("chartId is required and must be a valid id (only letters, numbers or underscores. The first character must be a letter)");this._model=new ni({chartId:e,candles:i,config:n,container:d,trade:r,userMarkers:a,colorScheme:l,comments:h}),this._view=new xn(d),this._controller=new Hn(this._model,this._view),this._controller.init()}updateConfig(t){this._model.updateConfig(t)}updateTrade(t){this._model.updateTrade(t)}updateUserMarkers(t){this._model.updateUserMarkers(t)}updateColorScheme(t){this._model.updateColorScheme(t)}updateCandles(t){this._model.updateCandles(t)}updateComments(t){this._model.updateComments(t)}}$.CandlestickChart=Rn,$.createLineChart=Hs,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function($,z){typeof exports=="object"&&typeof module<"u"?z(exports,require("d3")):typeof define=="function"&&define.amd?define(["exports","d3"],z):($=typeof globalThis<"u"?globalThis:$||self,z($.ChartsCore={},$.d3))})(this,function($,z){"use strict";var ga=Object.defineProperty;var fa=($,z,rt)=>z in $?ga($,z,{enumerable:!0,configurable:!0,writable:!0,value:rt}):$[z]=rt;var h=($,z,rt)=>fa($,typeof z!="symbol"?z+"":z,rt);function rt(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const D=rt(z),rs=s=>{const{svg:t,config:e,y:i,width:n}=s,{margin:r,yAxis:a}=e,{customTicks:l,tickFormat:c,tickValues:d,ticks:g,isShow:f}=a;if(!f)return null;t.append("g").attr("transform",`translate(${n-r.right},0)`).call(_=>{let p=D.axisRight(i);l&&c?p=p.tickFormat(c):p=p.tickFormat(v=>{const b=Number(v),y=C=>C.toString().replace(/\.0+$/,"");return Math.abs(b)>=1e12?y(b/1e12)+"T":Math.abs(b)>=1e9?y(b/1e9)+"B":Math.abs(b)>=1e6?y(b/1e6)+"M":Math.abs(b)>=1e3?y(b/1e3)+"K":y(b)}),l&&g&&(p=Array.isArray(g)?p.ticks(...g):p.ticks(g)),l&&d&&(p=p.tickValues(d)),_.call(p)}).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),s.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(y=>y.getBBox().width),b=Math.max(...v);_.selectAll(".tick").each(function(y,C){var O;const w=D.select(this),x=w.select("text"),T=v[C],H=b-T,R=w.append("g").attr("transform","translate(10, 0)");x.attr("x",H),x.remove(),(O=R.node())==null||O.appendChild(x.node())})}).attr("font-family","inherit")},as=s=>{const{svg:t,config:e,x:i,height:n}=s,{margin:r,xAxis:a}=e,{isShow:l,tickValues:c,tickFormat:d,customTicks:g,ticks:f}=a;if(!l)return null;t.append("g").attr("transform",`translate(0,${n-r.bottom})`).call(_=>{let p=D.axisBottom(i);g?(d&&(p=p.tickFormat(d)),f&&(p=Array.isArray(f)?p.ticks(...f):p.ticks(f)),c&&(p=p.tickValues(c))):p.ticks(5),_.call(p)}).call(_=>_.select(".domain").remove()).call(_=>{let p=[];_.selectAll(".tick").each(v=>p.push(v)),s.xTicks=p}).call(_=>_.selectAll(".tick line").remove()).call(_=>_.selectAll(".tick text").classed("sc-charts__x-axis-tick",!0)).attr("font-family","inherit")},os=s=>{const{svg:t,config:e,y:i,width:n}=s,{margin:r,grid:{horizontalStyle:a}}=e;if(a!=="none"){if(a.startsWith("zero-line")){const l=t.append("line").attr("x1",0+r.left).attr("x2",n-r.right).attr("y1",i(0)).attr("y2",i(0)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);a==="zero-line-dashed"&&l.attr("stroke-dasharray","4 4")}a.startsWith("every-line")&&(s.yTicks||i.ticks()).forEach(c=>{const d=t.append("line").attr("x1",0+r.left).attr("x2",n-r.right).attr("y1",i(c)).attr("y2",i(c)).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);a==="every-line-dashed"&&d.attr("stroke-dasharray","4 4")})}},ls=s=>{const t=Array.from(s.childNodes);for(let e=0;e<t.length;e++)s.removeChild(t[e])},cs=s=>{const t="http://www.w3.org/2000/svg",e=document.createElement("div");e.className="sc-charts__hovered-circles-tooltip-container",e.style.display="none";const i=document.createElement("div");i.className="sc-charts__hovered-circles-tooltip";const n=document.createElement("div");n.className="sc-charts__hovered-circles-tooltip-arrow";const r=document.createElementNS(t,"svg");r.setAttribute("width","12"),r.setAttribute("height","4"),r.setAttribute("viewBox","0 0 12 4"),r.setAttribute("fill","none"),r.setAttribute("xmlns",t);const a=document.createElementNS(t,"path");return a.setAttribute("d","M6 4L0 0H12L6 4Z"),r.appendChild(a),n.appendChild(r),e.append(n),e.append(i),s.append(e),{tooltipContainer:e,tooltip:i,tooltipArrow:n}},hs=(s,t,{x:e,y:i,r:n=3.5,hr:r=0})=>{if(t)return s.append("image").attr("x",e-6).attr("y",i-6).attr("width",12).attr("height",12).attr("href","data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAxMyAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzE0NTJfNTAwOSkiPgo8cGF0aCBkPSJNNi41MzY0NiAxMS41Njg4QzkuMjA1ODYgMTEuNTY4OCAxMS4zNjk4IDkuNDA0ODMgMTEuMzY5OCA2LjczNTQzQzExLjM2OTggNC4wNjYwNiA5LjIwNTg2IDEuOTAyMSA2LjUzNjQ2IDEuOTAyMUMzLjg2NzA4IDEuOTAyMSAxLjcwMzEyIDQuMDY2MDYgMS43MDMxMiA2LjczNTQzQzEuNzAzMTIgOS40MDQ4MyAzLjg2NzA4IDExLjU2ODggNi41MzY0NiAxMS41Njg4WiIgZmlsbD0iI0ZDRUJFOSIvPgo8cGF0aCBkPSJNMy4xMTcxOSAxMC4xNTM1TDkuOTQ3MTkgMy4zMjM0OSIgc3Ryb2tlPSIjRjE4MTY5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPHBhdGggZD0iTTYuNTM2NDYgMTEuNTY4OEM5LjIwNTg2IDExLjU2ODggMTEuMzY5OCA5LjQwNDgzIDExLjM2OTggNi43MzU0M0MxMS4zNjk4IDQuMDY2MDYgOS4yMDU4NiAxLjkwMjEgNi41MzY0NiAxLjkwMjFDMy44NjcwOSAxLjkwMjEgMS43MDMxMiA0LjA2NjA2IDEuNzAzMTIgNi43MzU0M0MxLjcwMzEyIDkuNDA0ODMgMy44NjcwOSAxMS41Njg4IDYuNTM2NDYgMTEuNTY4OFoiIHN0cm9rZT0iI0YxODE2OSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+CjwvZz4KPGRlZnM+CjxjbGlwUGF0aCBpZD0iY2xpcDBfMTQ1Ml81MDA5Ij4KPHJlY3Qgd2lkdGg9IjEyIiBoZWlnaHQ9IjEyIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC41MzUxNTYgMC43MzUzNTIpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==");{const a=s.append("g");return a.append("circle").attr("cx",e).attr("cy",i).attr("r",n).classed("sc-charts__hovered-circles",!0),a.append("circle").attr("cx",e).attr("cy",i).attr("r",n+r).classed("sc-charts__hovered-circles_add",!0),a}};function ds(s,t,e,i){if(!s)return null;const n=s.width/2,r=t-n,a=t+n;return r<e?e:a>i?i-s.width:t-n}const oe=(s,{x1:t,x2:e,y1:i,y2:n})=>s.append("line").attr("x1",t).attr("x2",e).attr("y1",i).attr("y2",n).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1),us=s=>{const{svg:t,config:e,x:i,y:n,height:r,data:a,wrapperNode:l}=s,{margin:c,grid:{verticalStyle:d,tooltipNode:g,hoverCirclesRadius:f,hoverCirclesAdditionalArea:_}}=e;if(d!=="none"&&(d.startsWith("every-line")&&(s.xTicks||i.ticks()).forEach(v=>{const b=t.append("line").attr("x1",i(v)).attr("x2",i(v)).attr("y1",c.top).attr("y2",r-c.bottom).attr("stroke","var(--sc-color-axis-zero-line)").attr("stroke-width",1);d==="every-line-dashed"&&b.attr("stroke-dasharray","4 4")}),d==="hovered-circles")){const p=n.range()[0],v=i(a[0].date),b=i(a[a.length-1].date);oe(t,{x1:v,x2:b,y1:p,y2:p});const{tooltipContainer:y,tooltip:C,tooltipArrow:w}=cs(l);a.forEach((x,T)=>{const H=i(x.date),R=n(x.value),O=a[T-1],G=T>0&&O&&x.value===O.value;G||oe(t,{x1:H,x2:H,y1:R,y2:p});const ot=hs(t,G,{x:H,y:p,r:f,hr:_});g&&ot.on("mouseover",function(){ls(C),y.style.display="block",C.append(g({date:x.date,value:G?null:x.value}));const K=C.getBoundingClientRect(),Ut=ds(K,i(x.date),s.config.margin.left-s.config.grid.tooltipArrowSize,s.width-s.config.margin.right+s.config.grid.tooltipArrowSize);C.style.left=Ut+"px",w.style.left=i(x.date)+"px"}).on("mouseout",function(){y.style.display="none"})})}},gs=s=>{os(s),us(s)},fs=s=>{const{svg:t,config:e,width:i,height:n}=s,{margin:r,logo:a}=e;as(s),rs(s),a&&t.append("image").attr("xlink:href",e.theme==="dark"?a.picDarkTheme:a.picLightTheme).attr("width",a.width).attr("height",a.height).attr("x",a.x??(i-r.left-r.right)/2-a.width/2+r.left).attr("y",a.y??(n-r.top-r.bottom)/2-a.height/2+r.top),gs(s)},ht=(s,t,e)=>{let i=s.select(`#${t}`);return i.empty()&&(i=s.append("linearGradient").attr("gradientUnits","userSpaceOnUse").attr("id",t)),i.attr("x1",e.x1).attr("y1",e.x2).attr("x2",e.y1).attr("y2",e.y2),e.stops.forEach(({offset:n,stopColor:r})=>{i.append("stop").attr("offset",n).attr("stop-color",r)}),i},at=s=>{const t=D.select(s).select("defs");return t.empty()?D.select(s).append("defs"):t},le=s=>{const{y:t,config:{margin:e}}=s,i=t.range()[0]-t(0),n=t.range()[0]-i>=0?t.range()[0]-i:0,r=i+e.bottom>=0?i+e.bottom:0;return{x:0,y:n,width:"100%",height:r}},ce=(s,t)=>({...s,...t,margin:{...s.margin,...t==null?void 0:t.margin},logo:s.logo&&(t!=null&&t.logo)?{width:t.logo.width??s.logo.width,height:t.logo.height??s.logo.height,picLightTheme:t.logo.picLightTheme??s.logo.picLightTheme,picDarkTheme:t.logo.picDarkTheme??s.logo.picDarkTheme,x:t.logo.x??s.logo.x,y:t.logo.y??s.logo.y}:s.logo,xAxis:{...s.xAxis,...t==null?void 0:t.xAxis},yAxis:{...s.yAxis,...t==null?void 0:t.yAxis},grid:{...s.grid,...t==null?void 0:t.grid},hover:{...s.hover,...t==null?void 0:t.hover},selection:{...s.selection,...t==null?void 0:t.selection}}),he=(s,t={})=>{const e=s.node(),i=at(e),n=(l,c)=>ht(i,l,{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 r="sc-charts__border-range-line",a=s.append("line").classed(r,!0).style("display",t.hidden?"none":"block");return{className(l,c){l==="remove"?a.classed(`${r}${c}`,!1):a.classed(`${r}${c}`,!0)},update({x1:l,x2:c,y1:d,y2:g,hidden:f}){l!==void 0&&a.attr("x1",l),c!==void 0&&a.attr("x2",c),d!==void 0&&a.attr("y1",d),g!==void 0&&a.attr("y2",g),f!==void 0&&a.style("display",f?"none":"block")},destroy(){a.remove()}}},Rt=(s,t={})=>{const e=s.append("circle").attr("r",t.radius||4).style("display",t.hidden?"none":"block"),i=t.className||"";return i&&e.classed(i,!0),{className(n,r){n==="remove"?e.classed(`${i}${r}`,!1):e.classed(`${i}${r}`,!0)},update({cx:n,cy:r,hidden:a,fill:l}){n!==void 0&&e.attr("cx",n),r!==void 0&&e.attr("cy",r),l!==void 0&&e.attr("fill",l),a!==void 0&&e.style("display",a?"none":"block")},destroy(){e.remove()}}},ms=(s,t={})=>{const e="sc-charts__hover-line",i=s.append("line").style("display",t.hidden?"none":"block").classed(e,!0),n=s.node(),r=at(n);return((l,c)=>ht(r,l,{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(l,c){l==="remove"?i.classed(`${e}${c}`,!1):i.classed(`${e}${c}`,!0)},update({x1:l,x2:c,y1:d,y2:g,hidden:f}){l!==void 0&&i.attr("x1",l),c!==void 0&&i.attr("x2",c),d!==void 0&&i.attr("y1",d),g!==void 0&&i.attr("y2",g),f!==void 0&&i.style("display",f?"none":"block")},destroy(){i.remove()}}},et="sc-charts__range-tooltip",de=D.timeFormat("%b %e, %I:%M %p"),_s=s=>{const t=D.format(",.2f");return`${s<0?"-":""}$${t(Math.abs(s))}`};function ps(s){const t="http://www.w3.org/2000/svg",e=document.createElement("div");e.className=et,e.style.position="absolute",e.style.top="0",e.style.pointerEvents="none",e.style.display="none",s.append(e);const i=document.createElement("div");i.className=`${et}-container`,e.append(i);const n=document.createElement("div");n.className=`${et}-sum`,i.append(n);const r=document.createElement("div");r.className=`${et}-sum-icon`;const a=document.createElementNS(t,"svg");a.setAttribute("width","14"),a.setAttribute("height","14"),a.setAttribute("viewBox","0 0 14 14"),a.setAttribute("fill","none"),a.setAttribute("xmlns",t);const l=document.createElementNS(t,"path");l.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"),l.setAttribute("fill","currentColor"),a.appendChild(l),r.appendChild(a),n.append(r);const c=document.createElement("div");n.append(c);const d=document.createElement("div");return d.className=`${et}-time`,i.append(d),{wrapper:e,sumNode:c,timeNode:d}}const vs=s=>{const{wrapper:t,sumNode:e,timeNode:i}=ps(s.wrapperNode);return{className(n,r){n==="remove"?t.classList.remove(`${et}${r}`):t.classList.add(`${et}${r}`)},update({leftPoint:n,rightPoint:r,x:a,y:l,hidden:c,closest:d}){if(n&&r&&d&&a!==void 0){const g=r.value-n.value,{sumFormatter:f,timeFormatter:_}=s.config.selection,p=(s.x(r.date)+s.x(n.date))/2,v=s.x(d.date)<p?"left":"right";let b="",y="";if(f)b=f({left:n.value,right:r.value,direction:v});else{const C=(g/Math.abs(n.value)*100).toFixed(2);b=`${_s(g)} (${C}%)`}_?y=_({left:n.date,right:r.date,direction:v}):y=`${de(n.date)} to ${de(r.date)}`,e.textContent=b,i.textContent=y,requestAnimationFrame(()=>{const C=t.getBoundingClientRect(),w=s.wrapperNode.getBoundingClientRect(),x=s.x(n.date),T=s.x(r.date);let R=(x+T)/2-C.width/2;const O=0,G=w.width-C.width;R<O&&(R=O),R>G&&(R=G),t.style.left=`${R}px`,t.style.top=`${l}px`})}c!==void 0&&(t.style.display=c?"none":"block")},destroy(){t.remove()}}},dt="sc-charts__hover-tooltip",$t=16,bs=D.timeFormat("%a, %b %d, %-I:%M %p"),ys=s=>{const t=D.format(",.2f");return`${s<0?"-":""}$${t(Math.abs(s))}`};function xs(s){const t=document.createElement("div");t.className=`${dt}-container`,t.style.position="absolute",t.style.top="0",t.style.pointerEvents="none",t.style.display="none",s.appendChild(t);const e=document.createElement("div");e.className=`${dt}-sum`,t.appendChild(e);const i=document.createElement("div");return i.className=`${dt}-time`,t.appendChild(i),{wrapper:t,sumNode:e,timeNode:i}}function ws(s,t,e){return s?t+$t+s.width<e?t+$t:t-$t-s.width:null}const Cs=s=>{const{wrapper:t,sumNode:e,timeNode:i}=xs(s.wrapperNode);return{className(n,r){n==="remove"?t.classList.remove(`${dt}${r}`):t.classList.add(`${dt}${r}`)},update({hidden:n,dataItem:r}){if(r){const{sumFormatter:a,timeFormatter:l}=s.config.hover;e.textContent=a?a(r.value):ys(r.value),i.textContent=l?l(r.date):bs(r.date),requestAnimationFrame(()=>{const c=t.getBoundingClientRect(),d=ws(c,s.x(r.date),s.width-s.config.margin.right);d&&(t.style.left=d+"px")})}n!==void 0&&(t.style.display=n?"none":"block")},destroy(){t.remove()}}},Ms={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},xt=s=>D.curveCardinal.tension(s.config.curveTension),As=s=>{const{svg:t,data:e,x:i,y:n,config:r}=s,a=t.node(),l=at(a);ht(l,"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 d=D.area().x(_=>i(_.date)).y0(n.range()[0]).y1(_=>n(_.value)).curve(xt(s)),g="sc-charts__main-line-area",f=t.append("path").datum(e).attr("d",d).attr("class",g).classed(`${g}_hidden`,!r.hasMainLineArea);return{className(_,p){_==="remove"?f.classed(`${g}${p}`,!1):f.classed(`${g}${p}`,!0)},update({data:_,hidden:p}){if(_!==void 0&&f.datum(_).attr("d",d),p!==void 0){if(!r.hasMainLineArea)return null;f.classed(`${g}_hidden`,p)}},destroy(){f.remove()}}},Ts=(s,t={})=>{const e="sc-charts__range-line-area",{svg:i,x:n,y:r,config:a,data:l,chartId:c}=s,{clip:d}=t,g=i.node(),f=at(g),_="range-line-area-gradient";ht(f,_+"_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)"}]}),ht(f,_+"_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=D.area().x(w=>n(w.date)).y0(r.range()[0]).y1(w=>r(w.value)).curve(xt(s)),v=`${c}-clip-${e}`,y=f.append("clipPath").attr("id",v).append("rect").attr("x",(d==null?void 0:d.x)||0).attr("y",(d==null?void 0:d.y)||0).attr("width",(d==null?void 0:d.width)||"100%").attr("height",(d==null?void 0:d.height)||"100%"),C=i.append("path").datum(l).attr("d",p).attr("class",e).classed(`${e}_hidden`,!a.hasMainLineArea).attr("clip-path",`url(#${v})`);return{className(w,x){w==="remove"?C.classed(`${e}${x}`,!1):C.classed(`${e}${x}`,!0)},update({data:w,hidden:x,clip:T}){w!==void 0&&C.datum(w).attr("d",p),x!==void 0&&C.classed(`${e}_hidden`,x),T!==void 0&&y.attr("x",T.x).attr("y",T.y).attr("width",T.width).attr("height",T.height)},destroy(){C.remove()}}},zt=(s,t)=>{const{svg:e,data:i,x:n,y:r,chartId:a}=s,{baseClassName:l,id:c,clip:d}=t,g=e.node(),f=at(g),_=D.line().x(C=>n(C.date)).y(C=>r(C.value)).curve(xt(s)),p=`${a}-clip-${l}`,b=f.append("clipPath").attr("id",p).append("rect").attr("x",(d==null?void 0:d.x)||0).attr("y",(d==null?void 0:d.y)||0).attr("width",(d==null?void 0:d.width)||"100%").attr("height",(d==null?void 0:d.height)||"100%"),y=e.append("path").classed(l,!0).datum(i).attr("d",_).attr("id",c).attr("clip-path",`url(#${p})`);return{className(C,w){C==="remove"?y.classed(`${l}${w}`,!1):y.classed(`${l}${w}`,!0)},update({data:C,clip:w,hidden:x}){C!==void 0&&y.datum(C).attr("d",_),x!==void 0&&y.classed(`${l}_hidden`,x),w!==void 0&&b.attr("x",w.x).attr("y",w.y).attr("width",w.width).attr("height",w.height)},destroy(){y.remove()}}},Ss=(s,t)=>{const{svg:e,data:i,x:n,y:r,chartId:a,config:l}=s,{baseClassName:c,id:d,clip:g}=t,f=e.node(),_=at(f),p=D.line().x(w=>n(w.date)).y(w=>r(w.value)).curve(xt(s)),v=`${a}-clip-${c}`,y=_.append("clipPath").attr("id",v).append("rect").attr("x",(g==null?void 0:g.x)||0).attr("y",(g==null?void 0:g.y)||0).attr("width",(g==null?void 0:g.width)||"100%").attr("height",(g==null?void 0:g.height)||"100%"),C=e.append("path").classed(c,!0).datum(i).attr("d",p).attr("id",d).attr("clip-path",`url(#${v})`);return{className(w,x){w==="remove"?C.classed(`${c}${x}`,!1):C.classed(`${c}${x}`,!0)},update({data:w,clip:x,hidden:T}){w!==void 0&&C.datum(w).attr("d",p),T!==void 0&&C.classed(`${c}_hidden`,T),x!==void 0&&(l.hover.transitionName==="default"?y.transition().duration(l.hover.transitionDuration).attr("x",x.x).attr("y",x.y).attr("width",x.width).attr("height",x.height).ease(D.easeLinear):y.attr("x",x.x).attr("y",x.y).attr("width",x.width).attr("height",x.height))},destroy(){C.remove()}}},ks=s=>{const t=Math.abs(s);let e;return t>=1e9?e=(s/1e9).toFixed(1)+"B":t>=1e6?e=(s/1e6).toFixed(1)+"M":t>=1e3?e=(s/1e3).toFixed(1)+"K":e=s.toFixed(1),e},Ds=(s,t)=>{const{svg:e,data:i,x:n,y:r}=s,{baseClassName:a}=t,l=e.append("g").classed(a,!0),c=l.append("circle").attr("r",5).classed(`${a}-circle`,!0),d=l.append("text").attr("text-anchor","middle").attr("dy","-9px").classed(`${a}-label`,!0);return(f=>{if(!f||f.length===0)return;const _=f[f.length-1],p=n(_.date),v=r(_.value);c.attr("cx",p).attr("cy",v);const b=s.config.extremePointFormatter||ks;d.attr("x",p).attr("y",v).text(b(_.value))})(i),{className(f,_){f==="remove"?l.classed(`${a}${_}`,!1):l.classed(`${a}${_}`,!0)},update({hidden:f}){f!==void 0&&l.classed(`${a}_hidden`,f)},destroy(){l.remove()}}},Ls=s=>{const t=zt(s,{baseClassName:"sc-charts__main-line",id:`${s.chartId}-sc-charts__main-line`}),e=As(s);let i=null;s.config.hasExtremePoint&&(i=Ds(s,{baseClassName:"sc-charts__extreme-point"}));const n=ms(s.svg),r=Ss(s,{baseClassName:"sc-charts__highlight-line",id:`${s.chartId}-sc-charts__highlight-line`,clip:{x:0,y:0,width:"0",height:"0"}});let a=null;s.config.enableBelowZeroLine&&(a=zt(s,{baseClassName:"sc-charts__below-zero-line",id:`${s.chartId}-sc-charts__below-zero-line`,clip:le(s)}));const l=Rt(s.svg,{className:"sc-charts__hover-circle",hidden:!0}),c=he(s.svg),d=he(s.svg),g=zt(s,{baseClassName:"sc-charts__range-line",id:`${s.chartId}-sc-charts__range-line`,clip:{x:0,y:0,width:"0",height:"0"}}),f=Rt(s.svg,{className:"sc-charts__range-circle-left",hidden:!0}),_=Rt(s.svg,{className:"sc-charts__range-circle-right",hidden:!0}),p=vs(s),v=Cs(s),b=Ts(s);return{hoverLine:n,hoverCircle:l,rangeBorderLeft:c,rangeBorderRight:d,rangeLine:g,rangeLineArea:b,rangeCircleLeft:f,rangeCircleRight:_,mainLine:t,rangeTooltip:p,highlightLine:r,hoverTooltip:v,mainLineArea:e,belowZeroLine:a,extremePoint:i}},Es=(s,t,e)=>{const i=s.match(/^(\d+)([dMhmw])$/);if(!i)return console.warn("Invalid hoverRange:",s),{x:0,y:0,width:"100%",height:"100%"};const[,n,r]=i,a=parseInt(n,10),[l,c]=e.domain();let d=new Date(l);for(;d<c;){let g=new Date(d);switch(r){case"M":g.setMinutes(g.getMinutes()+a);break;case"h":g.setHours(g.getHours()+a);break;case"d":g.setDate(g.getDate()+a);break;case"w":g.setDate(g.getDate()+a*7);break;case"m":g=new Date(d.getFullYear(),d.getMonth()+a,1);break;default:return{x:0,y:0,width:"100%",height:"100%"}}if(t>=d&&t<g){const f=e(d),_=e(g);return{x:f,y:0,width:_-f,height:"100%"}}d=new Date(g)}if(t.getTime()===c.getTime()){let g=new Date(c);switch(r){case"M":g.setMinutes(g.getMinutes()-a);break;case"h":g.setHours(g.getHours()-a);break;case"d":g.setDate(g.getDate()-a);break;case"w":g.setDate(g.getDate()-a*7);break;case"m":g=new Date(c.getFullYear(),c.getMonth()-a,1);break}const f=e(g),_=e(c);return{x:f,y:0,width:_-f,height:"100%"}}return{x:0,y:0,width:"100%",height:"100%"}},ue=(s,t)=>{var d;const{x:e,y:i,elements:n,config:{margin:r},height:a}=s;n.hoverLine.update({x1:e(t.date),x2:e(t.date),y1:r.top,y2:a-r.bottom,hidden:!1}),n.hoverCircle.update({cx:e(t.date),cy:i(t.value),hidden:!1}),n.hoverTooltip.update({dataItem:t,hidden:!1});const l=Es(s.config.hover.range,t.date,e);n.highlightLine.update({clip:l,hidden:!1});const c=i.range()[0]-i(0)+r.bottom;c>=0&&((d=n.belowZeroLine)==null||d.update({clip:{...l,y:i(0),height:c}})),n.mainLine.className("add","_muted")},ge=s=>{var e;const{elements:t}=s;t.hoverLine.update({hidden:!0}),t.hoverCircle.update({hidden:!0}),t.highlightLine.update({hidden:!0}),t.mainLine.className("remove","_muted"),t.hoverTooltip.update({hidden:!0}),s.action!=="selection"&&((e=t.belowZeroLine)==null||e.update({clip:le(s)}))},Ns=(s,t)=>{["rangeBorderLeft","rangeBorderRight","rangeCircleLeft","rangeCircleRight","rangeLine","rangeLineArea","rangeTooltip"].forEach(i=>{t?(s[i].className("remove","_down"),s[i].className("add","_up")):(s[i].className("remove","_up"),s[i].className("add","_down"))})},Is=(s,t,e)=>{var v;const{x:i,y:n,config:{margin:r},height:a,elements:l}=s,c=i(t.date)<i(e.date)?t:e,d=i(t.date)>=i(e.date)?t:e,g=d.value-c.value>=0,f=i(c.date),_=i(d.date),p=_-f;l.rangeBorderLeft.update({x1:f,x2:f,y1:r.top,y2:a-r.bottom,hidden:!1}),l.rangeBorderRight.update({x1:_,x2:_,y1:r.top,y2:a-r.bottom,hidden:!1}),l.rangeCircleLeft.update({cx:f,cy:n(c.value),hidden:!1}),l.rangeCircleRight.update({cx:_,cy:n(d.value),hidden:!1}),l.rangeLine.update({clip:{x:f,y:0,width:p,height:n.range()[0]},hidden:!1}),l.rangeLineArea.update({clip:{x:f,y:0,width:p,height:n.range()[0]},hidden:!1}),l.rangeTooltip.update({rightPoint:d,leftPoint:c,closest:e,x:f+p/2,y:0,hidden:!1}),(v=l.belowZeroLine)==null||v.update({hidden:!0}),l.mainLineArea.update({hidden:!0}),Ns(l,g),l.mainLine.className("add","_selected-muted")},fe=s=>{var e;const{elements:t}=s;t.rangeLine.update({hidden:!0}),t.rangeLineArea.update({hidden:!0}),t.rangeBorderLeft.update({hidden:!0}),t.rangeBorderRight.update({hidden:!0}),t.rangeCircleLeft.update({hidden:!0}),t.rangeCircleRight.update({hidden:!0}),t.rangeTooltip.update({hidden:!0}),t.mainLine.className("remove","_selected-muted"),t.mainLineArea.update({hidden:!1}),(e=t.belowZeroLine)==null||e.update({hidden:!1})},Fs=s=>{const{svg:t,data:e,x:i,config:n,width:r,height:a}=s,{margin:l,hover:c,selection:d}=n;let g=null,f=!1;const _=v=>e.reduce((b,y)=>Math.abs(i(b.date)-v)<Math.abs(i(y.date)-v)?b:y);t.append("rect").attr("width",r-l.left-l.right).attr("height",a-l.top-l.bottom).attr("x",l.left).attr("y",l.top).attr("fill","transparent").on("mousemove",function(v){const[b]=D.pointer(v,this),y=_(b);!f&&c.enable?(s.action="hover",ue(s,y)):(s.action=f?"selection":"none",ge(s)),g&&d.enable&&(s.action="selection",Is(s,g,y))}).on("mouseleave",()=>{s.action="none",f=!1,g=null,ge(s),fe(s)}).on("mousedown",function(v){if(d.enable){f=!0,s.action="selection";const[b]=D.pointer(v,this);g=_(b)}}).on("mouseup",function(v){const[b]=D.pointer(v,this),y=_(b);f=!1,g=null,s.action="hover",d.enable&&fe(s),c.enable&&ue(s,y)})},Bs=(s,t,e)=>{const{margin:i}=t,n=D.scaleTime(),r=D.extent(s,a=>new Date(a.date));return r[0]==null||r[1]==null?n:n.domain([r[0],r[1]]).range([i.left,e-i.right])},Hs=(s,t,e)=>{const{margin:i}=t,n=D.max(s,a=>a.value)??0,r=D.min(s,a=>a.value)??0;return D.scaleLinear().domain([r,n]).range([e-i.bottom,i.top])},Rs=(s,t)=>{const e=D.select(s);if(e.empty())return console.error(`Element with selector ${s} not found!`),null;if(!t.chartId||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.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 i=e.append("div"),n=i.append("svg"),r=e.node();let a=r.getBoundingClientRect(),l=a.width,c=a.height,d=ce({...Ms},t.config),g=t.data;const f=()=>{a=r.getBoundingClientRect(),l=a.width,c=a.height,_({data:g,config:d})};window.addEventListener("resize",f);const _=(p,v=!1)=>{v&&p.config&&(d=ce(d,p.config)),v&&p.data&&(g=p.data);const b=g.map(T=>({date:new Date(T.date),value:T.value})).sort((T,H)=>T.date.getTime()-H.date.getTime()),y=Bs(b,d,l),C=Hs(b,d,c);i.attr("class",`sc-charts sc-charts__${d.theme}`),n.attr("preserveAspectRatio","xMinYMin meet").attr("viewBox",`0 0 ${l} ${c}`).style("width","100%").style("height","100%").selectAll("*").remove();const w={chartId:t.chartId,svg:n,wrapperNode:i.node(),data:b,x:y,y:C,config:d,action:"none",width:l,height:c};fs(w);const x={...w,elements:Ls(w)};Fs(x)};return _(t),{update:p=>_(p,!0),destroy:()=>{window.removeEventListener("resize",f),n.remove()}}};var wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $s(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var ut={exports:{}};ut.exports;var me;function zs(){return me||(me=1,function(s,t){var e=200,i="__lodash_hash_undefined__",n=800,r=16,a=9007199254740991,l="[object Arguments]",c="[object Array]",d="[object AsyncFunction]",g="[object Boolean]",f="[object Date]",_="[object Error]",p="[object Function]",v="[object GeneratorFunction]",b="[object Map]",y="[object Number]",C="[object Null]",w="[object Object]",x="[object Proxy]",T="[object RegExp]",H="[object Set]",R="[object String]",O="[object Undefined]",G="[object WeakMap]",ot="[object ArrayBuffer]",K="[object DataView]",Ut="[object Float32Array]",Yn="[object Float64Array]",jn="[object Int8Array]",Xn="[object Int16Array]",Vn="[object Int32Array]",Wn="[object Uint8Array]",Gn="[object Uint8ClampedArray]",Un="[object Uint16Array]",Zn="[object Uint32Array]",qn=/[\\^$.*+?()[\]{}|]/g,Jn=/^\[object .+?Constructor\]$/,Qn=/^(?:0|[1-9]\d*)$/,N={};N[Ut]=N[Yn]=N[jn]=N[Xn]=N[Vn]=N[Wn]=N[Gn]=N[Un]=N[Zn]=!0,N[l]=N[c]=N[ot]=N[g]=N[K]=N[f]=N[_]=N[p]=N[b]=N[y]=N[w]=N[T]=N[H]=N[R]=N[G]=!1;var He=typeof wt=="object"&&wt&&wt.Object===Object&&wt,Kn=typeof self=="object"&&self&&self.Object===Object&&self,_t=He||Kn||Function("return this")(),Re=t&&!t.nodeType&&t,pt=Re&&!0&&s&&!s.nodeType&&s,$e=pt&&pt.exports===Re,Zt=$e&&He.process,ze=function(){try{var o=pt&&pt.require&&pt.require("util").types;return o||Zt&&Zt.binding&&Zt.binding("util")}catch{}}(),Pe=ze&&ze.isTypedArray;function tr(o,u,m){switch(m.length){case 0:return o.call(u);case 1:return o.call(u,m[0]);case 2:return o.call(u,m[0],m[1]);case 3:return o.call(u,m[0],m[1],m[2])}return o.apply(u,m)}function er(o,u){for(var m=-1,M=Array(o);++m<o;)M[m]=u(m);return M}function sr(o){return function(u){return o(u)}}function ir(o,u){return o==null?void 0:o[u]}function nr(o,u){return function(m){return o(u(m))}}var rr=Array.prototype,ar=Function.prototype,Dt=Object.prototype,qt=_t["__core-js_shared__"],Lt=ar.toString,tt=Dt.hasOwnProperty,Oe=function(){var o=/[^.]+$/.exec(qt&&qt.keys&&qt.keys.IE_PROTO||"");return o?"Symbol(src)_1."+o:""}(),Ye=Dt.toString,or=Lt.call(Object),lr=RegExp("^"+Lt.call(tt).replace(qn,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Et=$e?_t.Buffer:void 0,je=_t.Symbol,Xe=_t.Uint8Array;Et&&Et.allocUnsafe;var Ve=nr(Object.getPrototypeOf,Object),We=Object.create,cr=Dt.propertyIsEnumerable,hr=rr.splice,st=je?je.toStringTag:void 0,Nt=function(){try{var o=Kt(Object,"defineProperty");return o({},"",{}),o}catch{}}(),dr=Et?Et.isBuffer:void 0,Ge=Math.max,ur=Date.now,Ue=Kt(_t,"Map"),vt=Kt(Object,"create"),gr=function(){function o(){}return function(u){if(!nt(u))return{};if(We)return We(u);o.prototype=u;var m=new o;return o.prototype=void 0,m}}();function it(o){var u=-1,m=o==null?0:o.length;for(this.clear();++u<m;){var M=o[u];this.set(M[0],M[1])}}function fr(){this.__data__=vt?vt(null):{},this.size=0}function mr(o){var u=this.has(o)&&delete this.__data__[o];return this.size-=u?1:0,u}function _r(o){var u=this.__data__;if(vt){var m=u[o];return m===i?void 0:m}return tt.call(u,o)?u[o]:void 0}function pr(o){var u=this.__data__;return vt?u[o]!==void 0:tt.call(u,o)}function vr(o,u){var m=this.__data__;return this.size+=this.has(o)?0:1,m[o]=vt&&u===void 0?i:u,this}it.prototype.clear=fr,it.prototype.delete=mr,it.prototype.get=_r,it.prototype.has=pr,it.prototype.set=vr;function q(o){var u=-1,m=o==null?0:o.length;for(this.clear();++u<m;){var M=o[u];this.set(M[0],M[1])}}function br(){this.__data__=[],this.size=0}function yr(o){var u=this.__data__,m=It(u,o);if(m<0)return!1;var M=u.length-1;return m==M?u.pop():hr.call(u,m,1),--this.size,!0}function xr(o){var u=this.__data__,m=It(u,o);return m<0?void 0:u[m][1]}function wr(o){return It(this.__data__,o)>-1}function Cr(o,u){var m=this.__data__,M=It(m,o);return M<0?(++this.size,m.push([o,u])):m[M][1]=u,this}q.prototype.clear=br,q.prototype.delete=yr,q.prototype.get=xr,q.prototype.has=wr,q.prototype.set=Cr;function lt(o){var u=-1,m=o==null?0:o.length;for(this.clear();++u<m;){var M=o[u];this.set(M[0],M[1])}}function Mr(){this.size=0,this.__data__={hash:new it,map:new(Ue||q),string:new it}}function Ar(o){var u=Bt(this,o).delete(o);return this.size-=u?1:0,u}function Tr(o){return Bt(this,o).get(o)}function Sr(o){return Bt(this,o).has(o)}function kr(o,u){var m=Bt(this,o),M=m.size;return m.set(o,u),this.size+=m.size==M?0:1,this}lt.prototype.clear=Mr,lt.prototype.delete=Ar,lt.prototype.get=Tr,lt.prototype.has=Sr,lt.prototype.set=kr;function ct(o){var u=this.__data__=new q(o);this.size=u.size}function Dr(){this.__data__=new q,this.size=0}function Lr(o){var u=this.__data__,m=u.delete(o);return this.size=u.size,m}function Er(o){return this.__data__.get(o)}function Nr(o){return this.__data__.has(o)}function Ir(o,u){var m=this.__data__;if(m instanceof q){var M=m.__data__;if(!Ue||M.length<e-1)return M.push([o,u]),this.size=++m.size,this;m=this.__data__=new lt(M)}return m.set(o,u),this.size=m.size,this}ct.prototype.clear=Dr,ct.prototype.delete=Lr,ct.prototype.get=Er,ct.prototype.has=Nr,ct.prototype.set=Ir;function Fr(o,u){var m=se(o),M=!m&&ee(o),k=!m&&!M&&Ke(o),E=!m&&!M&&!k&&es(o),F=m||M||k||E,L=F?er(o.length,String):[],B=L.length;for(var U in o)F&&(U=="length"||k&&(U=="offset"||U=="parent")||E&&(U=="buffer"||U=="byteLength"||U=="byteOffset")||Je(U,B))||L.push(U);return L}function Jt(o,u,m){(m!==void 0&&!Ht(o[u],m)||m===void 0&&!(u in o))&&Qt(o,u,m)}function Br(o,u,m){var M=o[u];(!(tt.call(o,u)&&Ht(M,m))||m===void 0&&!(u in o))&&Qt(o,u,m)}function It(o,u){for(var m=o.length;m--;)if(Ht(o[m][0],u))return m;return-1}function Qt(o,u,m){u=="__proto__"&&Nt?Nt(o,u,{configurable:!0,enumerable:!0,value:m,writable:!0}):o[u]=m}var Hr=Zr();function Ft(o){return o==null?o===void 0?O:C:st&&st in Object(o)?qr(o):sa(o)}function Ze(o){return bt(o)&&Ft(o)==l}function Rr(o){if(!nt(o)||ta(o))return!1;var u=ne(o)?lr:Jn;return u.test(aa(o))}function $r(o){return bt(o)&&ts(o.length)&&!!N[Ft(o)]}function zr(o){if(!nt(o))return ea(o);var u=Qe(o),m=[];for(var M in o)M=="constructor"&&(u||!tt.call(o,M))||m.push(M);return m}function qe(o,u,m,M,k){o!==u&&Hr(u,function(E,F){if(k||(k=new ct),nt(E))Pr(o,u,F,m,qe,M,k);else{var L=M?M(te(o,F),E,F+"",o,u,k):void 0;L===void 0&&(L=E),Jt(o,F,L)}},ss)}function Pr(o,u,m,M,k,E,F){var L=te(o,m),B=te(u,m),U=F.get(B);if(U){Jt(o,m,U);return}var Y=E?E(L,B,m+"",o,u,F):void 0,yt=Y===void 0;if(yt){var re=se(B),ae=!re&&Ke(B),ns=!re&&!ae&&es(B);Y=B,re||ae||ns?se(L)?Y=L:oa(L)?Y=Wr(L):ae?(yt=!1,Y=jr(B)):ns?(yt=!1,Y=Vr(B)):Y=[]:la(B)||ee(B)?(Y=L,ee(L)?Y=ca(L):(!nt(L)||ne(L))&&(Y=Jr(B))):yt=!1}yt&&(F.set(B,Y),k(Y,B,M,E,F),F.delete(B)),Jt(o,m,Y)}function Or(o,u){return na(ia(o,u,is),o+"")}var Yr=Nt?function(o,u){return Nt(o,"toString",{configurable:!0,enumerable:!1,value:da(u),writable:!0})}:is;function jr(o,u){return o.slice()}function Xr(o){var u=new o.constructor(o.byteLength);return new Xe(u).set(new Xe(o)),u}function Vr(o,u){var m=Xr(o.buffer);return new o.constructor(m,o.byteOffset,o.length)}function Wr(o,u){var m=-1,M=o.length;for(u||(u=Array(M));++m<M;)u[m]=o[m];return u}function Gr(o,u,m,M){var k=!m;m||(m={});for(var E=-1,F=u.length;++E<F;){var L=u[E],B=void 0;B===void 0&&(B=o[L]),k?Qt(m,L,B):Br(m,L,B)}return m}function Ur(o){return Or(function(u,m){var M=-1,k=m.length,E=k>1?m[k-1]:void 0,F=k>2?m[2]:void 0;for(E=o.length>3&&typeof E=="function"?(k--,E):void 0,F&&Qr(m[0],m[1],F)&&(E=k<3?void 0:E,k=1),u=Object(u);++M<k;){var L=m[M];L&&o(u,L,M,E)}return u})}function Zr(o){return function(u,m,M){for(var k=-1,E=Object(u),F=M(u),L=F.length;L--;){var B=F[++k];if(m(E[B],B,E)===!1)break}return u}}function Bt(o,u){var m=o.__data__;return Kr(u)?m[typeof u=="string"?"string":"hash"]:m.map}function Kt(o,u){var m=ir(o,u);return Rr(m)?m:void 0}function qr(o){var u=tt.call(o,st),m=o[st];try{o[st]=void 0;var M=!0}catch{}var k=Ye.call(o);return M&&(u?o[st]=m:delete o[st]),k}function Jr(o){return typeof o.constructor=="function"&&!Qe(o)?gr(Ve(o)):{}}function Je(o,u){var m=typeof o;return u=u??a,!!u&&(m=="number"||m!="symbol"&&Qn.test(o))&&o>-1&&o%1==0&&o<u}function Qr(o,u,m){if(!nt(m))return!1;var M=typeof u;return(M=="number"?ie(m)&&Je(u,m.length):M=="string"&&u in m)?Ht(m[u],o):!1}function Kr(o){var u=typeof o;return u=="string"||u=="number"||u=="symbol"||u=="boolean"?o!=="__proto__":o===null}function ta(o){return!!Oe&&Oe in o}function Qe(o){var u=o&&o.constructor,m=typeof u=="function"&&u.prototype||Dt;return o===m}function ea(o){var u=[];if(o!=null)for(var m in Object(o))u.push(m);return u}function sa(o){return Ye.call(o)}function ia(o,u,m){return u=Ge(u===void 0?o.length-1:u,0),function(){for(var M=arguments,k=-1,E=Ge(M.length-u,0),F=Array(E);++k<E;)F[k]=M[u+k];k=-1;for(var L=Array(u+1);++k<u;)L[k]=M[k];return L[u]=m(F),tr(o,this,L)}}function te(o,u){if(!(u==="constructor"&&typeof o[u]=="function")&&u!="__proto__")return o[u]}var na=ra(Yr);function ra(o){var u=0,m=0;return function(){var M=ur(),k=r-(M-m);if(m=M,k>0){if(++u>=n)return arguments[0]}else u=0;return o.apply(void 0,arguments)}}function aa(o){if(o!=null){try{return Lt.call(o)}catch{}try{return o+""}catch{}}return""}function Ht(o,u){return o===u||o!==o&&u!==u}var ee=Ze(function(){return arguments}())?Ze:function(o){return bt(o)&&tt.call(o,"callee")&&!cr.call(o,"callee")},se=Array.isArray;function ie(o){return o!=null&&ts(o.length)&&!ne(o)}function oa(o){return bt(o)&&ie(o)}var Ke=dr||ua;function ne(o){if(!nt(o))return!1;var u=Ft(o);return u==p||u==v||u==d||u==x}function ts(o){return typeof o=="number"&&o>-1&&o%1==0&&o<=a}function nt(o){var u=typeof o;return o!=null&&(u=="object"||u=="function")}function bt(o){return o!=null&&typeof o=="object"}function la(o){if(!bt(o)||Ft(o)!=w)return!1;var u=Ve(o);if(u===null)return!0;var m=tt.call(u,"constructor")&&u.constructor;return typeof m=="function"&&m instanceof m&&Lt.call(m)==or}var es=Pe?sr(Pe):$r;function ca(o){return Gr(o,ss(o))}function ss(o){return ie(o)?Fr(o):zr(o)}var ha=Ur(function(o,u,m){qe(o,u,m)});function da(o){return function(){return o}}function is(o){return o}function ua(){return!1}s.exports=ha}(ut,ut.exports)),ut.exports}var Ps=zs();const Ct=$s(Ps),_e=12,Os={candles:{direction:"right",offset:`${Math.round(_e/2)}px`,style:"filled",strokeWidth:1,baseWidth:_e,bodyRatio:.7,zoomOnWheel:"both",scaleSensitivity:.002},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}};class Ys{constructor(t){h(this,"_candles");h(this,"_xAxis");h(this,"_yAxis");h(this,"_guides");h(this,"_trade");const e=Ct({},Os,t);this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._trade=e.trade}update(t){const e=Ct({},{candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,trade:this._trade},t);this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._trade=e.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 j{constructor(t){h(this,"x");h(this,"y");h(this,"width");h(this,"height");let e;if(!t)e={x:0,y:0,width:0,height:0};else if(t instanceof HTMLElement||t instanceof Element){const{x:i,y:n,width:r,height:a}=t.getBoundingClientRect();e={x:i,y:n,width:r,height:a}}else e=t;this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.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 js{constructor(t,e){h(this,"_chart",new j);h(this,"_area",new j);h(this,"_xAxis",new j);h(this,"_yAxis",new j);h(this,"_axisIntersection",new j);const{xAxis:i,yAxis:n}=e;this._chart=new j(t),this._calc(i,n)}_calc(t,e){const i=t.isShow?t.height:0,n=e.isShow?e.width:0,r=this._chart.height-i,a=this._chart.width-n;this._area=new j({x:e.position==="left"?n:0,y:t.position==="top"?i:0,width:a,height:r}),this._xAxis=new j({y:t.position==="top"?0:r,x:e.position==="left"?n:0,height:i,width:a}),this._yAxis=new j({y:t.position==="top"?i:0,x:e.position==="left"?0:a,width:n,height:r}),this._axisIntersection=new j({y:t.position==="top"?0:r,x:e.position==="left"?0:a,width:n,height:i})}updateConfig(t){const{xAxis:e,yAxis:i}=t;this._calc(e,i)}update(t){const{xAxis:e,yAxis:i}=t.config;this._chart=new j(t.container),this._calc(e,i)}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 Xs=s=>s?new Date(s.close_time).getTime()-new Date(s.open_time).getTime():0;function Vs(s,t){if(s.length<2)return[];const e=[];for(let i=0;i<s.length-1;i++){const n=s[i].close_time.getTime(),r=s[i].open_time.getTime(),l=new Date(s[i+1].open_time).getTime()-n;if(l>=t){const c=Math.floor(l/t),d=[];for(let g=1;g<=c;g++)d.push(r+g*t);d.length>0&&e.push(d)}}return e}function pe(s,t){const e=Xs(s[0]),i=Vs(s,e),n=[];return i.forEach(r=>{if(r.length===0)return;const a=s.find(f=>f.close_time.getTime()===r[0]),l=s.find(f=>f.open_time.getTime()===r[r.length-1]+e);if(!a||!l)throw new Error("[CS_Data] error while creating missing data");const c=a.close,d=l.open;let g=c;r.forEach((f,_)=>{const p=(d-g)/r.length;let v=g+p*_,b=v+p;const y=Math.abs(v-b);let C=Math.max(v,b)+y/2,w=Math.min(v,b)-y/2;if(t.trade){const T=[...t.trade.entries,...t.trade.exits].find(H=>{const R=H.time.getTime();return R>=f&&R<f+e});T&&(T.type==="buy"?(w=T.price,b=Math.max(w,b),v=b+y,C=Math.max(v,b)+y/2,g=v):T.type==="sell"&&(C=T.price,b=Math.min(C,b),v=b-y,w=Math.min(v,b)-y/2,g=v))}const x={open_time:new Date(f),close_time:new Date(f+e),open:v,close:b,high:C,low:w};n.push(x)})}),n}class Pt{constructor(t,e){h(this,"_initialData",[]);h(this,"_preparedData",[]);h(this,"_missingData",[]);h(this,"_count",0);h(this,"_model");h(this,"_interval",0);this._model=e,this.update(t)}_prepare(t){return t.map(e=>({...e,open_time:new Date(e.open_time),close_time:new Date(e.close_time)})).sort((e,i)=>e.open_time.getTime()-i.open_time.getTime())}update(t){this._initialData=t,this._preparedData=this._prepare(t),this._missingData=pe(this._preparedData,this._model),this._count=this._preparedData.length+this._missingData.length,this._interval=new Date(t[0].close_time).getTime()-new Date(t[0].open_time).getTime()}updateMissingCandles(){this._missingData=pe(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(t,e){return e.find(i=>i.open_time<=t&&i.close_time>t)}}class Ws{constructor(){h(this,"listeners",{})}subscribe(t,e){return this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e),()=>this.unsubscribe(t,e)}unsubscribe(t,e){var i;this.listeners[t]=((i=this.listeners[t])==null?void 0:i.filter(n=>n!==e))||[]}emit(t,...e){var n;const i=e[0];(n=this.listeners[t])==null||n.forEach(r=>{r(i)})}}class ve{constructor(){h(this,"_scale")}domain(){const t=this._scale.domain();if(t.length!==2)throw new Error("Domain length is not 2");return t}setDomain(t){this._scale.domain(t)}range(){const t=this._scale.range();if(t.length!==2)throw new Error("Range length is not 2");return t}setRange(t){this._scale.range(t)}invert(t){return this._scale.invert(t)}ticks(t){return this._scale.ticks(t)}tickFormat(t,e){return this._scale.tickFormat(t,e)}raw(){return this._scale}convert(t){return this._scale(t)}}class be extends ve{constructor(){super(),this._scale=D.scaleTime()}}class Gs extends ve{constructor(){super(),this._scale=D.scaleLinear()}}const ye={x:.2,y:.2},xe=.001,Us={s:1e3,M:1e3*60,h:1e3*60*60,d:1e3*60*60*24,w:1e3*60*60*24*7},Zs=s=>{const t=s.match(/^(\d+)([a-zA-Z]+)$/);if(!t)throw new Error(`Invalid offset format: "${s}"`);return[parseInt(t[1]),t[2]]},qs=(s,t)=>{const[e,i]=t.domain().map(l=>l.getTime()),n=s.filter(l=>{const c=l.open_time.getTime();return c>=e&&c<=i}),r=D.min(n,l=>l.low),a=D.max(n,l=>l.high);if(r==null||a==null)throw new Error("Invalid Y data");return[r,a]};class Js{constructor(t){this.model=t}initX(t){const e=this.model.candles.preparedData,i=D.extent(e,n=>new Date(n.open_time));if(!i[0]||!i[1])throw new Error("Invalid x data");t.setDomain(i),this.setRange(t,this.model.layout.xAxis),this.setDefaultXDomain(t),this.applyOffset(t)}initY(t,e){const i=qs(this.model.candles.preparedData,e);t.setDomain(i),this.setRange(t,this.model.layout.yAxis)}init(t){this.initX(t.x),this.initY(t.y,t.x)}setRange(t,{x:e,y:i,width:n,height:r}){t instanceof be?t.setRange([e,e+n]):t.setRange([i+r,i])}setDefaultXDomain(t){const{candles:{count:e},layout:{area:i},config:{candles:{baseWidth:n,bodyRatio:r,direction:a}}}=this.model,[l,c]=t.domain().map(p=>p.getTime()),d=c-l,g=n/r*e,f=d*(i.width/g),_=a==="left"?[new Date(l),new Date(l+f)]:[new Date(c-f),new Date(c)];t.setDomain(_)}applyOffset(t){const{config:{candles:{offset:e,direction:i}},layout:{xAxis:n}}=this.model,[r,a]=Zs(e),l=a==="px"?t.invert(n.x+r).getTime()-t.invert(n.x).getTime():Us[a]*r,c=i==="left"?-l:l,[d,g]=t.domain();t.setDomain([new Date(d.getTime()+c),new Date(g.getTime()+c)])}}class Qs{constructor(t){h(this,"_model");h(this,"_scaleX");h(this,"_scaleY");h(this,"_initializer");h(this,"_baseDomain",{x:[new Date,new Date],y:[0,0]});h(this,"scaleFactor",{x:1,y:1});h(this,"panOffset",{x:0,y:0});this._model=t,this._scaleX=new be,this._scaleY=new Gs,this._initializer=new Js(t),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 t=this._model.candles.allData,[e,i]=this._scaleX.domain(),n=t.filter(f=>f.open_time>=e&&f.open_time<=i);if(!n.length)return;const r=Math.min(...n.map(f=>f.low)),a=Math.max(...n.map(f=>f.high)),l=a-r;if(l===0)return;const c=this._baseDomain.y;this.scale("y",(c[1]-c[0])/l,"absolute");const d=this._scaleY.convert((r+a)/2),g=this._scaleY.convert((c[0]+c[1])/2);this.pan("y",g-d,"absolute")}scale(t,e,i="delta"){if(i==="absolute"){const n=Math.max(ye[t],e);if(Math.abs(n-this.scaleFactor[t])<xe)return;this.scaleFactor[t]=n}else{const n=this.scaleFactor[t],r=n+e*this._model.config.candles.scaleSensitivity;if(r<ye[t]||Math.abs(r-n)<xe)return;this.scaleFactor[t]=r}this._updateDomain(t)}pan(t,e,i="delta"){i==="absolute"?this.panOffset[t]=e:this.panOffset[t]+=e,this._updateDomain(t)}_updateDomain(t){const e=this._baseDomain[t],i=this.scaleFactor[t],n=this.panOffset[t];if(t==="x"){const[r,a]=e,l=a.getTime()-r.getTime(),c=l/i,d=r.getTime()+l/2,g=this._scaleX.invert(0-n).getTime()-this._scaleX.invert(0).getTime();this._scaleX.setDomain([new Date(d-c/2+g),new Date(d+c/2+g)])}else{const[r,a]=e,l=a-r,c=l/i,d=r+l/2,g=this._scaleY.invert(0-n)-this._scaleY.invert(0);this._scaleY.setDomain([d-c/2+g,d+c/2+g])}this._model.eventBus.emit("scale_event")}}class Ks{constructor(t,{entry:e=[],exit:i=[]}){h(this,"_model");h(this,"_rawEntry");h(this,"_rawExit");h(this,"_mapped",[]);h(this,"_entries",[]);h(this,"_exits",[]);h(this,"_activeTradeTime",null);h(this,"_hoveredTradeTime",null);this._model=t,this._rawEntry=e,this._rawExit=i,this.recalculate()}_findTradeCandle(t){return e=>t>=e.open_time&&t<e.close_time}recalculate(){const t=this._rawEntry.map(n=>({...n,kind:"entry",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),e=this._rawExit.map(n=>({...n,kind:"exit",time:new Date(n.time),candle:this._model.candles.allData.find(this._findTradeCandle(new Date(n.time)))})),i=[...t,...e];this._mapped=this._model.candles.allData.map(n=>{const r=i.filter(a=>a.time>=n.open_time&&a.time<n.close_time);return{candle:n,trades:r}}).filter(n=>n.trades.length>0),this._entries=t.sort((n,r)=>n.time.getTime()-r.time.getTime()),this._exits=e.sort((n,r)=>n.time.getTime()-r.time.getTime())}updateTrade({entry:t,exit:e}){this._rawEntry=t,this._rawExit=e,this.recalculate()}setActiveTrade(t,e){this._activeTradeTime=e||null,this._mapped=this._mapped.map(i=>({...i,isActive:t===null?void 0:[t,i.candle.open_time.getTime()===e]}))}setHoveredTrade(t,e){this._hoveredTradeTime=e||null,this._mapped=this._mapped.map(i=>({...i,isHovered:t===null?void 0:[t,i.candle.open_time.getTime()===e]}))}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 t;return((t=this._entries.at(0))==null?void 0:t.time.getTime())??0}get exitMaxTime(){var t;return((t=this._exits.at(-1))==null?void 0:t.time.getTime())??0}get timeRange(){const{allData:t,interval:e}=this._model.candles,i=t.map(a=>a.open_time.getTime());let n=0,r=i.length-1;for(let a=0;a<i.length;a++){const l=i[a],c=l<=this.entryMinTime&&l+e>=this.entryMinTime,d=l<=this.exitMaxTime&&l+e>=this.exitMaxTime;if(n===0&&c&&(n=a),r===i.length-1&&d&&(r=a),n!==0&&r!==i.length-1)break}return i.slice(n,r+1)}get hasTrade(){return this._rawEntry.length>0&&this._rawExit.length>0}get holdTime(){return Math.abs(this.entryMinTime-this.exitMaxTime)}}class ti{constructor(t,e){h(this,"_rawMarkers");h(this,"_markers",[]);h(this,"_model");h(this,"_defaults",{mainColor:"#000000",textColor:"#ffffff",lineColor:"#000000",formatter:{horizontal:t=>t.toString(),vertical:t=>t.toLocaleString()}});this._rawMarkers=e,this._model=t,this.rebuild()}rebuild(){const{layout:{area:t,chart:e},config:i,scales:{x:n,y:r},colorScheme:{userMarkers:{default:a}}}=this._model;this._markers=this._rawMarkers.map(l=>{var g,f;const c={mainColor:l.mainColor??a.main,textColor:l.textColor??a.text,lineColor:l.lineColor??a.line};if((l.type??"horizontal")==="horizontal"){const _=l,p=r.convert(_.value),b=(_.formatter??((g=this._defaults.formatter)==null?void 0:g.horizontal)??(y=>y.toString()))(_.value);return{value:_.value,type:"horizontal",text:b,x:t.x,y:p,lineLength:e.width,position:i.yAxis.position,...c}}else{const _=l,p=_.value instanceof Date?_.value:new Date(_.value),v=n.convert(p),y=(_.formatter??((f=this._defaults.formatter)==null?void 0:f.vertical)??(C=>C.toLocaleString()))(p);return{value:p,type:"vertical",text:y,x:v,y:t.y,lineLength:e.height,position:i.xAxis.position,...c}}})}updateMarkers(t){this._rawMarkers=t,this.rebuild()}get data(){return this._markers}}class ei{constructor(){h(this,"bg","#FFFFFF");h(this,"axisIntersection","#FFFFFF");h(this,"xAxis",{bg:"#FFFFFF",text:"#7F7F83"});h(this,"yAxis",{bg:"#FFFFFF",text:"#7F7F83"});h(this,"candles",{risingFill:"#56B683",risingStroke:"#000000",fallingFill:"#F18169",fallingStroke:"#000000",noDataFill:["#d9d9da","#ededed"],noDataStroke:"#000000"});h(this,"guides",{horizontalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"},verticalMarker:{main:"#1C2026",text:"#ffffff",line:"#1C2026"}});h(this,"trade");h(this,"userMarkers");h(this,"comments",{scaleAnchor:{bgActive:"#007AFF",bgInactive:"#A1BBFF",iconActive:"#FFFFFF",iconInactive:"#004DA1"}});this.trade={buyLabel:{main:this.candles.risingFill,text:"#ffffff"},sellLabel:{main:this.candles.fallingFill,text:"#ffffff"},connectionLine:"#D9D9DA",tradeBorders:"#EDEDED",activeLabel:"#007AFF",hold:{main:"#A1BBFF",text:"#ffffff"}},this.userMarkers={default:{main:"#EDEDED",text:"#000000",line:"#EDEDED"}}}toObject(){return{bg:this.bg,axisIntersection:this.axisIntersection,xAxis:this.xAxis,yAxis:this.yAxis,candles:this.candles,guides:this.guides,trade:this.trade,userMarkers:this.userMarkers,comments:this.comments}}}const si=new ei().toObject();class ii{constructor(t){h(this,"_bg");h(this,"_candles");h(this,"_xAxis");h(this,"_yAxis");h(this,"_guides");h(this,"_axisIntersection");h(this,"_trade");h(this,"_userMarkers");h(this,"_comments");const e=Ct({},si,t);this._candles=e.candles,this._bg=e.bg,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._axisIntersection=e.axisIntersection,this._trade=e.trade,this._userMarkers=e.userMarkers,this._comments=e.comments}update(t){const e=Ct({},{bg:this._bg,candles:this._candles,xAxis:this._xAxis,yAxis:this._yAxis,guides:this._guides,axisIntersection:this._axisIntersection,trade:this._trade,userMarkers:this._userMarkers,comments:this._comments},t);this._bg=e.bg,this._candles=e.candles,this._xAxis=e.xAxis,this._yAxis=e.yAxis,this._guides=e.guides,this._axisIntersection=e.axisIntersection,this._trade=e.trade,this._userMarkers=e.userMarkers,this._comments=e.comments}get bg(){return this._bg}get candles(){return this._candles}get xAxis(){return this._xAxis}get yAxis(){return this._yAxis}get guides(){return this._guides}get axisIntersection(){return this._axisIntersection}get trade(){return this._trade}get userMarkers(){return this._userMarkers}get comments(){return this._comments}}class ni{constructor(t,e){h(this,"_data");h(this,"_callbacks",{onAdd:()=>{},onUpdate:()=>{},onDelete:()=>{}});h(this,"_model");h(this,"_grouped",{});this._data=(t==null?void 0:t.data)||[],this._model=e,this._updateGroups(),t!=null&&t.onAdd&&(this._callbacks.onAdd=t.onAdd),t!=null&&t.onUpdate&&(this._callbacks.onUpdate=t.onUpdate),t!=null&&t.onDelete&&(this._callbacks.onDelete=t.onDelete)}_updateGroups(){this._grouped={};for(const t of this._data){const e=Pt.findByDate(new Date(t.date),this._model.candles.allData);if(!e)continue;const i=e.open_time.getTime();this._grouped[i]||(this._grouped[i]=[]),this._grouped[i].push({...t,candle:e})}}get data(){return this._data}set data(t){this._data=t,this._updateGroups()}get grouped(){return this._grouped}add(t){this._data.push(t),this._updateGroups(),this._callbacks.onAdd(t)}remove(t){this._data=this._data.filter(e=>e.id!==t),this._updateGroups(),this._callbacks.onDelete(t)}update(t,e){this._updateGroups(),this._callbacks.onUpdate(t,e)}}class ri{constructor({chartId:t,container:e,candles:i,config:n,trade:r={entry:[],exit:[]},userMarkers:a=[],colorScheme:l,comments:c}){h(this,"_chartId");h(this,"_container");h(this,"_eventBus",new Ws);h(this,"_candles");h(this,"_config");h(this,"_colorScheme");h(this,"_layout");h(this,"_scaleManager");h(this,"_trade");h(this,"_userMarkers");h(this,"_comments");this._chartId=t,this._container=e,this._candles=new Pt(i,this),this._config=new Ys(n),this._colorScheme=new ii(l),this._layout=new js(e,this._config),this._scaleManager=new Qs(this),this._trade=new Ks(this,r),this._candles.updateMissingCandles(),this._trade.recalculate(),this._userMarkers=new ti(this,a),this._comments=new ni(c,this)}init(){this._eventBus.emit("init_model")}subscribe(t,e){return this._eventBus.subscribe(t,e)}unsubscribe(t,e){this._eventBus.unsubscribe(t,e)}updateConfig(t){this._eventBus.emit("update_config",t)}updateCandles(t){this._eventBus.emit("update_candles",t)}updateTrade(t){this._eventBus.emit("update_trade",t)}updateUserMarkers(t){this._eventBus.emit("update_user_markers",t)}updateColorScheme(t){this._eventBus.emit("update_color_scheme",t)}updateComments(t){this._eventBus.emit("update_comments",t)}get chartId(){return this._chartId}get container(){return this._container}get config(){return this._config}get layout(){return this._layout}get candles(){return this._candles}get eventBus(){return this._eventBus}get scales(){return this._scaleManager}get trade(){return this._trade}get userMarkers(){return this._userMarkers}get colorScheme(){return this._colorScheme}get comments(){return this._comments}}const Mt=window.devicePixelRatio||2;class S{constructor({tag:t,className:e,id:i,textContent:n}){h(this,"_tag");h(this,"_className");h(this,"_id");h(this,"_textContent");h(this,"_node");h(this,"_absolutePosition",new DOMRect);this._tag=t||"div",this._className=e||"",this._id=i||"",this._textContent=n||"";const r=document.createElement(this._tag);this._className&&(r.className=this._className),this._id&&(r.id=this._id),this._textContent&&(r.textContent=this._textContent),this._node=r}get node(){return this._node}position(t,e){const i=typeof t=="number"?t:t.x,n=typeof t=="number"?e:t.y;this.node.style.top=n+"px",this.node.style.left=i+"px"}append(...t){this._node.append(...t)}prepend(...t){this._node.prepend(...t)}remove(){this._node.remove(),this._tag="",this._className="",this._id="",this._textContent=""}get absolutePosition(){return this._absolutePosition}updateAbsolutePosition(){this._absolutePosition=this._node.getBoundingClientRect()}setVisible(t){this.node.style.opacity=t?"1":"0",this.node.style.visibility=t?"visible":"hidden"}}class we extends S{constructor({className:e,id:i,width:n,height:r,isMain:a}){super({tag:"canvas",className:`${e} sc-charts-cs__canvas ${a?"":"sc-charts-cs__canvas-additional"}`,id:i});h(this,"_ctx");h(this,"_width");h(this,"_height");h(this,"background",null);this._width=n,this._height=r,this.updateSize({width:n,height:r});const l=this._node.getContext("2d");if(!l)throw new Error("Failed to get 2D context");l.scale(Mt,Mt),this._ctx=l}updateSize({width:e,height:i}){e&&(this._node.width=e*Mt,this._node.style.width=`${e}px`,this._width=e),i&&(this._node.height=i*Mt,this._node.style.height=`${i}px`,this._height=i)}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 ai=10;function oi(s,t){const{layout:{xAxis:e},colorScheme:{xAxis:i},config:{xAxis:n},scales:r}=t,a=r.x.ticks(ai),l=g=>g.getHours()===0&&g.getMinutes()===0,c=D.timeFormat("%d %b"),d=D.timeFormat("%H:%M");s.save(),s.fillStyle=i.bg,s.fillRect(e.x,e.y,e.width,e.height),s.restore(),s.fillStyle=i.text,s.font=`${n.text.fontSize} ${n.text.font}`,s.textAlign="center",s.textBaseline="middle",a.forEach(g=>{const f=r.x.convert(g),_=l(g)?c(g):d(g);s.fillText(_,f,e.y+e.height/2)})}function li(s,t){const{layout:{yAxis:e},colorScheme:{yAxis:i},config:{yAxis:n},scales:r}=t,a=r.y.ticks(6),l=r.y.tickFormat(6);s.save(),s.fillStyle=i.bg,s.fillRect(e.x,e.y,e.width,e.height),s.restore(),s.fillStyle=i.text,s.font=`${n.text.fontSize} ${n.text.font}`,s.textAlign="center",s.textBaseline="middle",a.forEach(c=>{const d=r.y.convert(c),g=l(c);s.fillText(g,e.x+e.width/2,d)})}const ci=(s,t)=>{const{layout:{axisIntersection:e},colorScheme:i}=t;s.save(),s.fillStyle=i.axisIntersection,s.fillRect(e.x,e.y,e.width,e.height),s.restore()};class Ot{static xAxis(t,e){oi(t,e)}static yAxis(t,e){li(t,e)}static intersection(t,e){ci(t,e)}}class hi{constructor(t){h(this,"_target");this._target=t}mousemove(t){this._target.addEventListener("mousemove",t)}mouseleave(t){this._target.addEventListener("mouseleave",t)}mousedown(t){this._target.addEventListener("mousedown",t)}mouseup(t){this._target.addEventListener("mouseup",t)}wheel(t){this._target.addEventListener("wheel",t)}dblclick(t){this._target.addEventListener("dblclick",t)}contextmenu(t){this._target.addEventListener("contextmenu",t)}}function At(s){return s*.1875}const di=(s,{mainColor:t,textColor:e,symbol:i,x:n,y:r,size:a,fontSize:l})=>{const f=a/16,_=16*f,p=n-_/2,v=r;s.save(),s.translate(p,v),s.scale(f,f),s.beginPath(),s.moveTo(7.85696,.288512),s.lineTo(4.53377,3.11938),s.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),s.lineTo(11.2275,4),s.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),s.lineTo(8.52156,.302869),s.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),s.closePath(),s.fillStyle=t,s.fill(),s.beginPath(),s.moveTo(0,7),s.bezierCurveTo(0,4.79086,1.79086,3,4,3),s.lineTo(12,3),s.bezierCurveTo(14.2091,3,16,4.79086,16,7),s.lineTo(16,15),s.bezierCurveTo(16,17.2091,14.2091,19,12,19),s.lineTo(4,19),s.bezierCurveTo(1.79086,19,0,17.2091,0,15),s.lineTo(0,7),s.closePath(),s.fillStyle=t,s.fill(),s.restore(),s.save(),s.font=`bold ${l}px sans-serif`,s.textAlign="center",s.textBaseline="top",s.textAlign="center",s.textBaseline="middle";const b=r+f*3+.5,y=f*16,C=b+y/2;s.fillStyle=e,s.fillText(i,n,C),s.restore()},ui=(s,{mainColor:t,textColor:e,symbol:i,x:n,y:r,size:a,fontSize:l})=>{const f=a/16,_=16*f,p=n-_/2,v=r;s.save(),s.translate(p,v),s.scale(f,-f),s.beginPath(),s.moveTo(7.85696,.288512),s.lineTo(4.53377,3.11938),s.bezierCurveTo(4.17982,3.42089,4.39305,4,4.85801,4),s.lineTo(11.2275,4),s.bezierCurveTo(11.6818,4,11.9006,3.44302,11.5678,3.13374),s.lineTo(8.52156,.302869),s.bezierCurveTo(8.33575,.130189,8.05007,.124018,7.85696,.288512),s.closePath(),s.fillStyle=t,s.fill(),s.beginPath(),s.moveTo(0,7),s.bezierCurveTo(0,4.79086,1.79086,3,4,3),s.lineTo(12,3),s.bezierCurveTo(14.2091,3,16,4.79086,16,7),s.lineTo(16,15),s.bezierCurveTo(16,17.2091,14.2091,19,12,19),s.lineTo(4,19),s.bezierCurveTo(1.79086,19,0,17.2091,0,15),s.lineTo(0,7),s.closePath(),s.fillStyle=t,s.fill(),s.restore(),s.save(),s.font=`bold ${l}px sans-serif`,s.textAlign="center",s.textBaseline="middle";const b=f*16,y=r-f*19+b/2;s.fillStyle=e,s.fillText(i,n,y),s.restore()};function Tt(s){"@babel/helpers - typeof";return Tt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Tt(s)}var gi=/^\s+/,fi=/\s+$/;function A(s,t){if(s=s||"",t=t||{},s instanceof A)return s;if(!(this instanceof A))return new A(s,t);var e=mi(s);this._originalInput=s,this._r=e.r,this._g=e.g,this._b=e.b,this._a=e.a,this._roundA=Math.round(100*this._a)/100,this._format=t.format||e.format,this._gradientType=t.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=e.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 t=this.toRgb();return(t.r*299+t.g*587+t.b*114)/1e3},getLuminance:function(){var t=this.toRgb(),e,i,n,r,a,l;return e=t.r/255,i=t.g/255,n=t.b/255,e<=.03928?r=e/12.92:r=Math.pow((e+.055)/1.055,2.4),i<=.03928?a=i/12.92:a=Math.pow((i+.055)/1.055,2.4),n<=.03928?l=n/12.92:l=Math.pow((n+.055)/1.055,2.4),.2126*r+.7152*a+.0722*l},setAlpha:function(t){return this._a=ke(t),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var t=Me(this._r,this._g,this._b);return{h:t.h*360,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=Me(this._r,this._g,this._b),e=Math.round(t.h*360),i=Math.round(t.s*100),n=Math.round(t.v*100);return this._a==1?"hsv("+e+", "+i+"%, "+n+"%)":"hsva("+e+", "+i+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var t=Ce(this._r,this._g,this._b);return{h:t.h*360,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=Ce(this._r,this._g,this._b),e=Math.round(t.h*360),i=Math.round(t.s*100),n=Math.round(t.l*100);return this._a==1?"hsl("+e+", "+i+"%, "+n+"%)":"hsla("+e+", "+i+"%, "+n+"%, "+this._roundA+")"},toHex:function(t){return Ae(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return bi(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},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(I(this._r,255)*100)+"%",g:Math.round(I(this._g,255)*100)+"%",b:Math.round(I(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(I(this._r,255)*100)+"%, "+Math.round(I(this._g,255)*100)+"%, "+Math.round(I(this._b,255)*100)+"%)":"rgba("+Math.round(I(this._r,255)*100)+"%, "+Math.round(I(this._g,255)*100)+"%, "+Math.round(I(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:Ei[Ae(this._r,this._g,this._b,!0)]||!1},toFilter:function(t){var e="#"+Te(this._r,this._g,this._b,this._a),i=e,n=this._gradientType?"GradientType = 1, ":"";if(t){var r=A(t);i="#"+Te(r._r,r._g,r._b,r._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+e+",endColorstr="+i+")"},toString:function(t){var e=!!t;t=t||this._format;var i=!1,n=this._a<1&&this._a>=0,r=!e&&n&&(t==="hex"||t==="hex6"||t==="hex3"||t==="hex4"||t==="hex8"||t==="name");return r?t==="name"&&this._a===0?this.toName():this.toRgbString():(t==="rgb"&&(i=this.toRgbString()),t==="prgb"&&(i=this.toPercentageRgbString()),(t==="hex"||t==="hex6")&&(i=this.toHexString()),t==="hex3"&&(i=this.toHexString(!0)),t==="hex4"&&(i=this.toHex8String(!0)),t==="hex8"&&(i=this.toHex8String()),t==="name"&&(i=this.toName()),t==="hsl"&&(i=this.toHslString()),t==="hsv"&&(i=this.toHsvString()),i||this.toHexString())},clone:function(){return A(this.toString())},_applyModification:function(t,e){var i=t.apply(null,[this].concat([].slice.call(e)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(Ci,arguments)},brighten:function(){return this._applyModification(Mi,arguments)},darken:function(){return this._applyModification(Ai,arguments)},desaturate:function(){return this._applyModification(yi,arguments)},saturate:function(){return this._applyModification(xi,arguments)},greyscale:function(){return this._applyModification(wi,arguments)},spin:function(){return this._applyModification(Ti,arguments)},_applyCombination:function(t,e){return t.apply(null,[this].concat([].slice.call(e)))},analogous:function(){return this._applyCombination(Di,arguments)},complement:function(){return this._applyCombination(Si,arguments)},monochromatic:function(){return this._applyCombination(Li,arguments)},splitcomplement:function(){return this._applyCombination(ki,arguments)},triad:function(){return this._applyCombination(Se,[3])},tetrad:function(){return this._applyCombination(Se,[4])}},A.fromRatio=function(s,t){if(Tt(s)=="object"){var e={};for(var i in s)s.hasOwnProperty(i)&&(i==="a"?e[i]=s[i]:e[i]=gt(s[i]));s=e}return A(s,t)};function mi(s){var t={r:0,g:0,b:0},e=1,i=null,n=null,r=null,a=!1,l=!1;return typeof s=="string"&&(s=Bi(s)),Tt(s)=="object"&&(Z(s.r)&&Z(s.g)&&Z(s.b)?(t=_i(s.r,s.g,s.b),a=!0,l=String(s.r).substr(-1)==="%"?"prgb":"rgb"):Z(s.h)&&Z(s.s)&&Z(s.v)?(i=gt(s.s),n=gt(s.v),t=vi(s.h,i,n),a=!0,l="hsv"):Z(s.h)&&Z(s.s)&&Z(s.l)&&(i=gt(s.s),r=gt(s.l),t=pi(s.h,i,r),a=!0,l="hsl"),s.hasOwnProperty("a")&&(e=s.a)),e=ke(e),{ok:a,format:s.format||l,r:Math.min(255,Math.max(t.r,0)),g:Math.min(255,Math.max(t.g,0)),b:Math.min(255,Math.max(t.b,0)),a:e}}function _i(s,t,e){return{r:I(s,255)*255,g:I(t,255)*255,b:I(e,255)*255}}function Ce(s,t,e){s=I(s,255),t=I(t,255),e=I(e,255);var i=Math.max(s,t,e),n=Math.min(s,t,e),r,a,l=(i+n)/2;if(i==n)r=a=0;else{var c=i-n;switch(a=l>.5?c/(2-i-n):c/(i+n),i){case s:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-s)/c+2;break;case e:r=(s-t)/c+4;break}r/=6}return{h:r,s:a,l}}function pi(s,t,e){var i,n,r;s=I(s,360),t=I(t,100),e=I(e,100);function a(d,g,f){return f<0&&(f+=1),f>1&&(f-=1),f<1/6?d+(g-d)*6*f:f<1/2?g:f<2/3?d+(g-d)*(2/3-f)*6:d}if(t===0)i=n=r=e;else{var l=e<.5?e*(1+t):e+t-e*t,c=2*e-l;i=a(c,l,s+1/3),n=a(c,l,s),r=a(c,l,s-1/3)}return{r:i*255,g:n*255,b:r*255}}function Me(s,t,e){s=I(s,255),t=I(t,255),e=I(e,255);var i=Math.max(s,t,e),n=Math.min(s,t,e),r,a,l=i,c=i-n;if(a=i===0?0:c/i,i==n)r=0;else{switch(i){case s:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-s)/c+2;break;case e:r=(s-t)/c+4;break}r/=6}return{h:r,s:a,v:l}}function vi(s,t,e){s=I(s,360)*6,t=I(t,100),e=I(e,100);var i=Math.floor(s),n=s-i,r=e*(1-t),a=e*(1-n*t),l=e*(1-(1-n)*t),c=i%6,d=[e,a,r,r,l,e][c],g=[l,e,e,a,r,r][c],f=[r,r,l,e,e,a][c];return{r:d*255,g:g*255,b:f*255}}function Ae(s,t,e,i){var n=[X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16))];return i&&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 bi(s,t,e,i,n){var r=[X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16)),X(De(i))];return n&&r[0].charAt(0)==r[0].charAt(1)&&r[1].charAt(0)==r[1].charAt(1)&&r[2].charAt(0)==r[2].charAt(1)&&r[3].charAt(0)==r[3].charAt(1)?r[0].charAt(0)+r[1].charAt(0)+r[2].charAt(0)+r[3].charAt(0):r.join("")}function Te(s,t,e,i){var n=[X(De(i)),X(Math.round(s).toString(16)),X(Math.round(t).toString(16)),X(Math.round(e).toString(16))];return n.join("")}A.equals=function(s,t){return!s||!t?!1:A(s).toRgbString()==A(t).toRgbString()},A.random=function(){return A.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})};function yi(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.s-=t/100,e.s=St(e.s),A(e)}function xi(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.s+=t/100,e.s=St(e.s),A(e)}function wi(s){return A(s).desaturate(100)}function Ci(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.l+=t/100,e.l=St(e.l),A(e)}function Mi(s,t){t=t===0?0:t||10;var e=A(s).toRgb();return e.r=Math.max(0,Math.min(255,e.r-Math.round(255*-(t/100)))),e.g=Math.max(0,Math.min(255,e.g-Math.round(255*-(t/100)))),e.b=Math.max(0,Math.min(255,e.b-Math.round(255*-(t/100)))),A(e)}function Ai(s,t){t=t===0?0:t||10;var e=A(s).toHsl();return e.l-=t/100,e.l=St(e.l),A(e)}function Ti(s,t){var e=A(s).toHsl(),i=(e.h+t)%360;return e.h=i<0?360+i:i,A(e)}function Si(s){var t=A(s).toHsl();return t.h=(t.h+180)%360,A(t)}function Se(s,t){if(isNaN(t)||t<=0)throw new Error("Argument to polyad must be a positive number");for(var e=A(s).toHsl(),i=[A(s)],n=360/t,r=1;r<t;r++)i.push(A({h:(e.h+r*n)%360,s:e.s,l:e.l}));return i}function ki(s){var t=A(s).toHsl(),e=t.h;return[A(s),A({h:(e+72)%360,s:t.s,l:t.l}),A({h:(e+216)%360,s:t.s,l:t.l})]}function Di(s,t,e){t=t||6,e=e||30;var i=A(s).toHsl(),n=360/e,r=[A(s)];for(i.h=(i.h-(n*t>>1)+720)%360;--t;)i.h=(i.h+n)%360,r.push(A(i));return r}function Li(s,t){t=t||6;for(var e=A(s).toHsv(),i=e.h,n=e.s,r=e.v,a=[],l=1/t;t--;)a.push(A({h:i,s:n,v:r})),r=(r+l)%1;return a}A.mix=function(s,t,e){e=e===0?0:e||50;var i=A(s).toRgb(),n=A(t).toRgb(),r=e/100,a={r:(n.r-i.r)*r+i.r,g:(n.g-i.g)*r+i.g,b:(n.b-i.b)*r+i.b,a:(n.a-i.a)*r+i.a};return A(a)},A.readability=function(s,t){var e=A(s),i=A(t);return(Math.max(e.getLuminance(),i.getLuminance())+.05)/(Math.min(e.getLuminance(),i.getLuminance())+.05)},A.isReadable=function(s,t,e){var i=A.readability(s,t),n,r;switch(r=!1,n=Hi(e),n.level+n.size){case"AAsmall":case"AAAlarge":r=i>=4.5;break;case"AAlarge":r=i>=3;break;case"AAAsmall":r=i>=7;break}return r},A.mostReadable=function(s,t,e){var i=null,n=0,r,a,l,c;e=e||{},a=e.includeFallbackColors,l=e.level,c=e.size;for(var d=0;d<t.length;d++)r=A.readability(s,t[d]),r>n&&(n=r,i=A(t[d]));return A.isReadable(s,i,{level:l,size:c})||!a?i:(e.includeFallbackColors=!1,A.mostReadable(s,["#fff","#000"],e))};var Yt=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"},Ei=A.hexNames=Ni(Yt);function Ni(s){var t={};for(var e in s)s.hasOwnProperty(e)&&(t[s[e]]=e);return t}function ke(s){return s=parseFloat(s),(isNaN(s)||s<0||s>1)&&(s=1),s}function I(s,t){Ii(s)&&(s="100%");var e=Fi(s);return s=Math.min(t,Math.max(0,parseFloat(s))),e&&(s=parseInt(s*t,10)/100),Math.abs(s-t)<1e-6?1:s%t/parseFloat(t)}function St(s){return Math.min(1,Math.max(0,s))}function P(s){return parseInt(s,16)}function Ii(s){return typeof s=="string"&&s.indexOf(".")!=-1&&parseFloat(s)===1}function Fi(s){return typeof s=="string"&&s.indexOf("%")!=-1}function X(s){return s.length==1?"0"+s:""+s}function gt(s){return s<=1&&(s=s*100+"%"),s}function De(s){return Math.round(parseFloat(s)*255).toString(16)}function Le(s){return P(s)/255}var V=function(){var s="[-\\+]?\\d+%?",t="[-\\+]?\\d*\\.\\d+%?",e="(?:"+t+")|(?:"+s+")",i="[\\s|\\(]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")\\s*\\)?",n="[\\s|\\(]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")[,|\\s]+("+e+")\\s*\\)?";return{CSS_UNIT:new RegExp(e),rgb:new RegExp("rgb"+i),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+i),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+i),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(s){return!!V.CSS_UNIT.exec(s)}function Bi(s){s=s.replace(gi,"").replace(fi,"").toLowerCase();var t=!1;if(Yt[s])s=Yt[s],t=!0;else if(s=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var e;return(e=V.rgb.exec(s))?{r:e[1],g:e[2],b:e[3]}:(e=V.rgba.exec(s))?{r:e[1],g:e[2],b:e[3],a:e[4]}:(e=V.hsl.exec(s))?{h:e[1],s:e[2],l:e[3]}:(e=V.hsla.exec(s))?{h:e[1],s:e[2],l:e[3],a:e[4]}:(e=V.hsv.exec(s))?{h:e[1],s:e[2],v:e[3]}:(e=V.hsva.exec(s))?{h:e[1],s:e[2],v:e[3],a:e[4]}:(e=V.hex8.exec(s))?{r:P(e[1]),g:P(e[2]),b:P(e[3]),a:Le(e[4]),format:t?"name":"hex8"}:(e=V.hex6.exec(s))?{r:P(e[1]),g:P(e[2]),b:P(e[3]),format:t?"name":"hex"}:(e=V.hex4.exec(s))?{r:P(e[1]+""+e[1]),g:P(e[2]+""+e[2]),b:P(e[3]+""+e[3]),a:Le(e[4]+""+e[4]),format:t?"name":"hex8"}:(e=V.hex3.exec(s))?{r:P(e[1]+""+e[1]),g:P(e[2]+""+e[2]),b:P(e[3]+""+e[3]),format:t?"name":"hex"}:!1}function Hi(s){var t,e;return s=s||{level:"AA",size:"small"},t=(s.level||"AA").toUpperCase(),e=(s.size||"small").toLowerCase(),t!=="AA"&&t!=="AAA"&&(t="AA"),e!=="small"&&e!=="large"&&(e="small"),{level:t,size:e}}function Ri(s,t){const{trade:{tradedCandles:e},scales:{x:i,y:n},colorScheme:r}=t,{trade:a}=r,l=4;e.forEach(({isHovered:c,isActive:d,candle:g,trades:f})=>{const _=i.convert(g.open_time);f.forEach(p=>{const v=p.type==="buy",b=v?a.buyLabel.text:a.sellLabel.text,y=v?"B":"S",C=v?n.convert(g.low)+l:n.convert(g.high)-l,w=v?di:ui;let x=v?a.buyLabel.main:a.sellLabel.main;c&&c[1]&&c[0]===p.type&&(x=A.mix(x,r.bg,20).toString()),d&&d[1]&&d[0]===p.type&&(x=a.activeLabel),w(s,{x:_,y:C,symbol:y,mainColor:x,textColor:b,size:16,fontSize:12})})})}function $i(s,t){const{scales:{x:e,factorX:i},layout:{area:n},trade:{tradedCandles:r,exits:a,entries:l},config:{candles:c},colorScheme:{trade:d}}=t;if(r.length===0)return;const g=r.map(_=>_.candle).sort((_,p)=>_.open_time.getTime()-p.open_time.getTime()),f=c.baseWidth/2*i+c.strokeWidth/2;if(s.save(),s.lineWidth=1,s.strokeStyle=d.tradeBorders,l.length){const _=e.convert(g[0].open_time)-f;s.beginPath(),s.moveTo(_,n.y),s.lineTo(_,n.y+n.height),s.stroke()}if(a.length){const _=e.convert(g[g.length-1].open_time)+f;s.beginPath(),s.moveTo(_,n.y),s.lineTo(_,n.y+n.height),s.stroke()}s.restore()}const zi=(s,t)=>{const{scales:{x:e,y:i},trade:{tradedCandles:n,entries:r,exits:a},colorScheme:{trade:l}}=t;s.save();const c=g=>{var f;return(f=n.find(_=>g.getTime()>=_.candle.open_time.getTime()&&g.getTime()<_.candle.close_time.getTime()))==null?void 0:f.candle},d=(g,f)=>{const _=c(g.time),p=c(f.time);if(!_||!p)return;const v=e.convert(_.open_time),b=e.convert(p.open_time);let y,C;g.type==="buy"?(y=i.convert(_.low),C=i.convert(p.high)):(y=i.convert(_.high),C=i.convert(p.low)),s.beginPath(),s.setLineDash([4,4]),s.strokeStyle=l.connectionLine,s.moveTo(v,y),s.lineTo(b,C),s.stroke(),s.setLineDash([])};if(r.length===1&&a.length>1)a.forEach(g=>d(r[0],g));else if(a.length===1&&r.length>1)r.forEach(g=>d(g,a[0]));else if(r.length===1&&a.length===1)d(r[0],a[0]);else if(r.length>0&&a.length>0){const g=r.reduce((_,p)=>_.time<p.time?_:p),f=a.reduce((_,p)=>_.time>p.time?_:p);d(g,f)}s.restore()},Pi=({ctx:s,radius:t,x:e,y:i,fillColor:n,width:r,height:a})=>{s.beginPath(),s.fillStyle=n,s.lineWidth=1,s.moveTo(e+t,i),s.lineTo(e+r-t,i),s.quadraticCurveTo(e+r,i,e+r,i+t),s.lineTo(e+r,i+a-t),s.quadraticCurveTo(e+r,i+a,e+r-t,i+a),s.lineTo(e+t,i+a),s.quadraticCurveTo(e,i+a,e,i+a-t),s.lineTo(e,i+t),s.quadraticCurveTo(e,i,e+t,i),s.closePath(),s.fill()},Oi=s=>{const t=Math.floor((Date.now()-+s)/1e3),e=[[60,1,"s"],[3600,60,"m"],[86400,3600,"h"],[604800,86400,"d"],[2629746,604800,"w"],[31556952,2629746,"mo"],[1/0,31556952,"y"]],[,i,n]=e.find(([a])=>t<a);return`${Math.floor(t/i)}${n} ago`};function Yi(s){const t=Math.floor(s/1e3),e=[{label:"d",value:86400},{label:"h",value:3600},{label:"m",value:60},{label:"s",value:1}],i=[];let n=t;for(const{label:r,value:a}of e)if(n>=a){const l=Math.floor(n/a);if(i.push(`${l}${r}`),n%=a,i.length===2)break}return i.length?i.join(" "):"0s"}const ji=10,Xi=6,Vi=4,Wi=12,Gi=(s,t)=>{var ot;const{scales:{x:e,y:i},trade:{entries:n,exits:r,holdTime:a},colorScheme:{trade:{hold:l}},config:{trade:{showHoldTime:c,holdTimeContent:d,holdTimeDates:g,holdTimePrice:f}}}=t;if(!c)return;const _=n.at(0),p=r.at(-1);if(!_||!p)return;const v=K=>K?K instanceof Date?K:new Date(K):null,b=e.convert(v(g==null?void 0:g[0])||_.candle.open_time),y=e.convert(v(g==null?void 0:g[1])||p.candle.open_time),C=i.convert(f||(((ot=n.at(0))==null?void 0:ot.price)??0));s.beginPath(),s.setLineDash([4,4]),s.strokeStyle=l.main,s.moveTo(b,C),s.lineTo(y,C),s.stroke(),s.setLineDash([]);const w=(b+y)/2,x=d||`Hold: ${Yi(a)}`,H=getComputedStyle(document.querySelector(".sc-charts-cs")||document.body).font.replace(/^\s*\S+/,"").trim();s.font=`600 ${ji}px ${H}`;const O=s.measureText(x).width+Xi*2,G=Wi+Vi*2;Pi({ctx:s,radius:4,x:w-O/2,y:C-G/2,width:O,height:G,fillColor:l.main}),s.fillStyle=l.text,s.textBaseline="middle",s.textAlign="center",s.fillText(x,w,C),s.restore()};class ft{constructor(t,e){h(this,"canvas");h(this,"dom");h(this,"prefix");const{width:i,height:n,canvasesContainer:r,domElements:a}=e;this.canvas=new we({className:`sc-charts-cs__canvas-${t}`,width:i,height:n}),this.dom=new S({className:`sc-charts-cs__dom-${t}`}),this.prefix=`sc-charts-cs__${t}`,r.append(this.canvas.node),a.append(this.dom.node)}cx(...t){return t.map(e=>`${this.prefix}-${e}`).join(" ")}cxFabric(...t){return e=>t.map(i=>`${this.prefix}-${i}-${e}`).join(" ")}}const Ui={"right-bottom":{dx:1,dy:1},"left-top":{dx:-1,dy:-1},"right-top":{dx:1,dy:-1},"left-bottom":{dx:-1,dy:1}},Ee=({size:s,parent:t,coords:e,prioritySide:i="right-bottom",offset:n=8})=>{const{width:r,height:a}=s,l=t.right-t.left,c=t.bottom-t.top,d=w=>{const{dx:x,dy:T}=Ui[w],H=e.x+(x===1?n:-r-n),R=e.y+(T===1?n:-a-n);return{x:H,y:R,side:w}},g=({x:w,y:x})=>w>=0&&x>=0&&w+r<=l&&x+a<=c,f=()=>{const w=e.y<0,x=e.y+a>c,T=e.x<0,H=e.x+r>l;return T&&w?"right-bottom":T&&x?"right-top":H&&w?"left-bottom":H&&x?"left-top":T?"right-bottom":H?"left-bottom":w?"right-bottom":x?"right-top":i},p=[i,"right-bottom","right-top","left-bottom","left-top"].filter((w,x,T)=>T.indexOf(w)===x),v=f();let b=null;for(const w of[v,...p]){const x=d(w);if(g(x)){b=x;break}}b||(b=d(v));const y=Math.min(Math.max(b.x,n),l-r-n),C=Math.min(Math.max(b.y,n),c-a-n);return{x:y,y:C,side:b.side}};class J extends S{constructor(e){super(e);h(this,"_state",{});h(this,"_updateScheduled",!1)}get state(){return this._state}set state(e){this._state=new Proxy(e,{set:(i,n,r)=>{if(typeof n!="string")return!0;const a=n;return i[a]===r||(i[a]=r,this._scheduleUpdate()),!0}})}setState(e){Object.assign(this.state,e)}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,requestAnimationFrame(()=>{this._updateScheduled=!1,this.render()}))}render(){}destroy(){this._updateScheduled=!1,this.remove()}forceUpdate(){this._scheduleUpdate()}}class Zi extends J{constructor(e){const i="label-tooltip";super({className:e.cx(i)});h(this,"title");h(this,"manyBox");h(this,"oneBox");h(this,"clsx");this.clsx=e.cxFabric(i),this.title=new S({tag:"div",className:this.clsx("title")}),this.manyBox=new S({tag:"div",className:this.clsx("box_many")}),this.oneBox=new S({tag:"div",className:this.clsx("box_one")}),e.dom.append(this.title.node,this.oneBox.node,this.manyBox.node),this.state={isShow:!1,x:0,y:0,parent:j.empty()}}_createLineNodes(e,i){const n=[];for(const r of Object.keys(i))if(r in e){const a=new S({tag:"div",className:this.clsx("line")});let l=e[r].toString();r==="kind"&&(l=this._formatDate(e.time));const c=new S({tag:"strong",textContent:i[r]}),d=new S({tag:"span",textContent:l});a.append(c.node,d.node),n.push(a.node)}return n}_formatDate(e){const i=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short",year:"numeric",hour12:!1}).format(e),[n,r,a]=i.split(", ");return`${n}, ${r} ${a}`}updateContent(e){if(e.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(),e.length===1){this.title.node.style.display="flex",this.oneBox.node.style.display="flex",this.title.node.textContent=this._formatDate(e[0].time);const i=this._createLineNodes(e[0],{price:"Price:",profit:"Realized P&L:",volume:"Volume:",percentage:"% of position:"});this.oneBox.append(...i),this.node.append(this.title.node,this.oneBox.node)}else if(e.length>1){this.manyBox.node.style.display="flex";const i=e.map(n=>{const r=new S({tag:"div"}),a=this._createLineNodes(n,{kind:n.kind==="entry"?"Entry:":"Exit:",price:"Price:"});return r.append(...a),r.node});this.manyBox.append(...i),this.node.append(this.manyBox.node)}}}render(){const{isShow:e,x:i,y:n,parent:r}=this.state;this.setVisible(e),e&&this.updateAbsolutePosition();const a=Ee({size:this.absolutePosition,parent:r,coords:{x:i,y:n}});this.position(a.x,a.y)}}class qi extends ft{constructor(e){super("trade",e);h(this,"labelTooltip");this.labelTooltip=new Zi(this),this.dom.append(this.labelTooltip.node)}renderAll(e){this.canvas.clear(),$i(this.canvas.ctx,e),Ri(this.canvas.ctx,e),zi(this.canvas.ctx,e),Gi(this.canvas.ctx,e)}}class W{static line(t,{lineColor:e,type:i,x:n,y:r,lineLength:a}){t.save(),t.strokeStyle=e||"#777777",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(n,r),t.lineTo(n+(i==="h"?a:0),r+(i==="v"?a:0)),t.stroke(),t.restore()}static _basicLabel(t,{text:e,mainColor:i,textColor:n,position:r}){t.textContent=e,t.style.backgroundColor=i??"#777777",t.style.color=n??"#ffffff",t.style[r]="0px"}static label_h(t,{text:e,y:i,mainColor:n,textColor:r,position:a}){W._basicLabel(t,{text:e,mainColor:n,textColor:r,position:a}),t.style.top=i+"px",t.style.transform="translateY(-50%)"}static label_v(t,{text:e,x:i,mainColor:n,textColor:r,position:a}){W._basicLabel(t,{text:e,mainColor:n,textColor:r,position:a}),t.style.left=i+"px",t.style.transform="translateX(-50%)"}static horizontalMarker({node:t,ctx:e,x:i,y:n,lineLength:r,text:a,textColor:l,mainColor:c,lineColor:d,position:g}){W.line(e,{type:"h",x:i,y:n,lineLength:r,lineColor:d}),W.label_h(t,{text:a,y:n,textColor:l,mainColor:c,position:g})}static verticalMarker({node:t,ctx:e,x:i,y:n,lineLength:r,text:a,textColor:l,mainColor:c,lineColor:d,position:g}){W.line(e,{type:"v",x:i,y:n,lineLength:r,lineColor:d}),W.label_v(t,{text:a,x:i,textColor:l,mainColor:c,position:g})}}class Ji extends ft{constructor(e){super("user-markers",e);h(this,"items",{})}render(e){const i=new Set(e.map(this.getIdFromMarker));this.canvas.clear(),this.removeObsoleteItems(i);for(const n of e){const r=this.getIdFromMarker(n),a=this.items[r]??this.createMarkerElement(r);this.renderMarker(n,a.node)}}clear(){this.canvas.clear(),this.dom.remove()}getIdFromMarker(e){const i=e.type==="horizontal"?"h":"v",n=e.value instanceof Date?e.value.getTime().toString():e.value.toString().replace(".","d");return`${i}_${n}`}removeObsoleteItems(e){for(const i in this.items)e.has(i)||(this.items[i].remove(),delete this.items[i])}createMarkerElement(e){const i=new S({tag:"div",className:this.cx("item")});return this.dom.append(i.node),this.items[e]=i,i}renderMarker(e,i){e.type==="horizontal"?W.horizontalMarker({ctx:this.canvas.ctx,node:i,...e}):W.verticalMarker({ctx:this.canvas.ctx,node:i,...e})}}const Qi="sc-charts-cs";class Q{constructor(t){h(this,"block");this.block=t}gen(t){return`${Qi}__${this.block}${t?"-"+t:""}`}}const jt=new Q("comment-actions");class Ki extends S{constructor({onDelete:t,onUpdate:e}){super({className:jt.gen()});const i=new S({tag:"button",className:jt.gen("edit"),textContent:"Edit"}),n=new S({tag:"button",className:jt.gen("delete"),textContent:"Delete"});n.node.addEventListener("click",r=>{r.stopPropagation(),t()}),i.node.addEventListener("click",r=>{r.stopPropagation(),e()}),this.append(i.node,n.node)}}function Xt(s,t){var n;const e=r=>{if(!document.contains(s.node))return;const a=r.target;if(s.node.contains(a))return;const l=document.elementFromPoint(r.clientX,r.clientY);if(l&&s.node.contains(l))return;const c=s.node.getBoundingClientRect();r.clientX>=c.left&&r.clientX<=c.right&&r.clientY>=c.top&&r.clientY<=c.bottom&&getComputedStyle(s.node).pointerEvents!=="none"||t(r)};document.addEventListener("mousedown",e);const i=(n=s.destroy)==null?void 0:n.bind(s);return s.destroy=()=>{document.removeEventListener("mousedown",e),i==null||i()},s}class tn{constructor(){h(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","18"),e.setAttribute("height","4"),e.setAttribute("viewBox","0 0 18 4"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=[{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 i){const r=document.createElementNS(t,"path");r.setAttribute("d",n.d),n.fill&&r.setAttribute("fill",n.fill),n.stroke&&(r.setAttribute("stroke",n.stroke),r.setAttribute("stroke-width","2"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round")),e.appendChild(r)}this.node=e}}const mt=new Q("comment-list");class en extends S{constructor({onDelete:e,onOpenEditor:i,comment:n,layout:r}){super({className:mt.gen("item")});h(this,"actionTooltip");h(this,"actionsTrigger");const a=new S({className:mt.gen("text"),textContent:n.text}),l=new S({className:mt.gen("created-at"),textContent:Oi(new Date(n.createdAt))});this.actionsTrigger=new S({tag:"button",className:mt.gen("action-trigger")});const c=new Ki({onDelete:e,onUpdate:i});this.actionTooltip=Xt(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-r.chart.top+20+"px",this.actionTooltip.node.style.left=this.actionsTrigger.absolutePosition.left-r.chart.left-this.actionTooltip.absolutePosition.width+10+"px",this.actionTooltip.setVisible(!0)});const d=new S({className:mt.gen("text-wrap")});this.actionTooltip.node.setAttribute("id",`ac-${n.id}`),d.append(a.node,this.actionsTrigger.node),this.actionsTrigger.append(new tn().node),this.append(d.node,l.node)}}class sn{constructor(){h(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","14"),e.setAttribute("height","12"),e.setAttribute("viewBox","0 0 14 12"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class nn{constructor(){h(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","10"),e.setAttribute("height","10"),e.setAttribute("viewBox","0 0 10 10"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.setAttribute("fill-rule","evenodd"),i.setAttribute("clip-rule","evenodd"),i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class rn extends J{constructor(e){super({className:"sc-charts-cs__comments-edit"});h(this,"input");h(this,"saveBtn");h(this,"cancelBtn");h(this,"_onSave");h(this,"_onCancel");this._onSave=e.onSave,this._onCancel=e.onCancel,this.input=new S({tag:"textarea",className:"sc-charts-cs__comments-edit-input"}),this.saveBtn=new S({tag:"button",className:"sc-charts-cs__comments-edit-save-btn"}),this.saveBtn.append(new sn().node),this.cancelBtn=new S({tag:"button",className:"sc-charts-cs__comments-edit-cancel-btn"}),this.cancelBtn.append(new nn().node);const i=new S({className:"sc-charts-cs__comments-edit-btn-container"});i.append(this.cancelBtn.node,this.saveBtn.node),this.append(this.input.node,i.node),this.state={inputValue:e.initialValue||"",hasInitFocused:!1},this._setupListeners(),this.render()}_setupListeners(){this.saveBtn.node.addEventListener("click",()=>{this._onSave(this.state.inputValue)}),this.input.node.addEventListener("input",e=>{const i=e.target;this.setState({inputValue:i.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 an=new Q("comment-list");class on extends J{constructor(e,i,n,r={}){super({tag:"ul",className:an.gen(),...r});h(this,"_elements",{});h(this,"_model");h(this,"_view");this._model=i,this._view=n,this.state={items:e,editId:null},this.render()}render(){this.node.replaceChildren(),this._elements={},this.state.items.forEach((e,i)=>{this._elements[e.id]={order:i+1,element:this._createItem(e)}}),this.append(...this._sortedNodes())}_createItem(e){if(this.state.editId===e.id)return new rn({onSave:r=>{this._model.comments.update(e.id,r),this.setState({editId:null})},onCancel:()=>{this.setState({editId:null})},initialValue:e.text});const i=new en({onDelete:()=>{this._model.comments.remove(e.id),i.actionTooltip.setVisible(!1)},onOpenEditor:()=>{this.setState({editId:e.id}),i.actionTooltip.setVisible(!1)},comment:e,layout:this._model.layout}),n=document.querySelector(`#ac-${e.id}`);return n?n.replaceWith(i.actionTooltip.node):this._view.domElements.append(i.actionTooltip.node),i}_sortedNodes(){return Object.values(this._elements).sort((e,i)=>e.order-i.order).map(e=>e.element.node)}}class ln{constructor(){h(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","14"),e.setAttribute("height","14"),e.setAttribute("viewBox","0 0 14 14"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),e.appendChild(i),this.node=e}}const kt=new Q(""),Vt=new Q("add-field");class Ne extends J{constructor({onAdd:e,blockName:i}){kt.block=i;super({className:kt.gen()+" "+Vt.gen()});h(this,"btn");h(this,"input");h(this,"_onAdd");this._onAdd=e,this.state={inputValue:""},this.input=new S({tag:"input",className:kt.gen("input")+" "+Vt.gen("input")}),this.input.node.setAttribute("placeholder","Add comment..."),this.btn=new S({tag:"button",className:kt.gen("btn")+" "+Vt.gen("btn")}),this.btn.append(new ln().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",e=>{e.key==="Enter"&&!this.btn.node.disabled&&this._addComment()}),this.input.node.addEventListener("input",e=>{const i=e.target;this.setState({inputValue:i.value})})}render(){this.btn.node.disabled=!this.state.inputValue.trim()}}const cn=new Q("list-tooltip"),Wt=8;class hn extends J{constructor(e,i,n){super({className:cn.gen()});h(this,"_list");h(this,"_addField");h(this,"_size",null);h(this,"_model");h(this,"_prevIsShow",!1);this._model=i,this.state={isShow:!1,comments:e},this._list=new on(e,i,n),this._addField=new Ne({blockName:"list-tooltip-add",onAdd:r=>{const a=e[0].date,l=e[0].price,c={id:crypto.randomUUID(),text:r,date:a,price:l,createdAt:new Date().toISOString()};i.comments.add(c)}}),this.node.append(this._list.node,this._addField.node)}render(){const{isShow:e,comments:i}=this.state,{width:n,height:r}=this._model.layout.area;this._prevIsShow!==e&&(this._list.forceUpdate(),this._prevIsShow=e),this.node.style.maxHeight=r/2-Wt+"px",this.setVisible(e),e&&!this._size&&(this.updateAbsolutePosition(),this._size=this.absolutePosition,this.position(n/2-this._size.width-Wt,r/2+Wt)),this._list.setState({items:i}),requestAnimationFrame(()=>{this._list.node.scrollTop=this._list.node.scrollHeight})}get list(){return this._list}}class dn{constructor(){h(this,"node");const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("fill","none"),e.setAttribute("xmlns",t);const i=document.createElementNS(t,"path");i.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"),i.setAttribute("fill","currentColor"),e.appendChild(i),this.node=e}}class un extends J{constructor({x:e,...i},n){super(i);h(this,"_colors");this._colors=n.colorScheme.comments.scaleAnchor,this.state={x:e,y:n.layout.xAxis.top,isActive:!1},this.node.append(new dn().node),this.render()}render(){const{x:e,y:i,isActive:n}=this.state;this.position({x:e,y:i});const r=n?"Active":"Inactive";this.node.style.backgroundColor=this._colors[`bg${r}`],this.node.style.color=this._colors[`icon${r}`]}}const Ie=new Q("comment-box");class gn extends J{constructor({boxId:e,model:i,view:n,comments:r,coords:a,onBoxActivate:l,onBoxDeactivate:c}){super({className:Ie.gen()});h(this,"pointer",new S({className:"sc-charts-cs__comments-pointer"}));h(this,"tooltip");h(this,"anchor");h(this,"_onBoxActivate");h(this,"_onBoxDeactivate");h(this,"_boxId");this._boxId=e,this._onBoxActivate=l,this._onBoxDeactivate=c,this.state={isActive:!1,comments:r,coords:a},this.pointer.position(a),this.anchor=new un({x:a.x,className:Ie.gen("anchor")},i),this.anchor.node.addEventListener("click",()=>{const d=!this.state.isActive;d?this._onBoxActivate(this._boxId):this._onBoxDeactivate(this._boxId),this.setState({isActive:d})}),this.tooltip=Xt(new hn(r,i,n),d=>{this.state.isActive&&(this.anchor.node.contains(d.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:e,comments:i,coords:n}=this.state;this.pointer.position(n),this.pointer.setVisible(e),this.anchor.setState({x:n.x,isActive:e}),this.tooltip.setState({comments:i,isShow:e})}}class fn{static animateTo(t,e,i,n){const r=t.scales.panOffsetX+(t.layout.area.width/2-e),a=t.scales.panOffsetY+(t.layout.area.height/2-i),l=300,c=performance.now(),d=t.scales.panOffsetX,g=t.scales.panOffsetY,f=_=>{const p=_-c,v=Math.min(p/l,1),b=v*v*(3-2*v),y=d+(r-d)*b,C=g+(a-g)*b;t.scales.pan("x",y,"absolute"),t.scales.pan("y",C,"absolute"),v<1?requestAnimationFrame(f):n==null||n()};requestAnimationFrame(f)}static animateToDataCoords(t,e,i,n){const r=typeof e=="number"?t.scales.x.convert(new Date(e)):t.scales.x.convert(e),a=t.scales.y.convert(i);this.animateTo(t,r,a,n)}}const Gt=new Q("comments-context");class mn extends J{constructor(){super({className:Gt.gen()});h(this,"pointer");h(this,"addField");h(this,"menu");h(this,"_size",null);h(this,"_model",null);h(this,"_candle",null);this.state={candle:null,isShow:!1,model:null},this.pointer=new S({className:Gt.gen("pointer")}),this.menu=new S({className:Gt.gen("menu")}),Xt(this.menu,()=>{this.setState({isShow:!1})}),this.addField=new Ne({blockName:"context-add",onAdd:e=>{!this._model||!this._candle||(this._model.comments.add({id:crypto.randomUUID(),text:e,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(e){this.addField.input.node.style.borderTopLeftRadius=e==="right-bottom"?"0px":"12px",this.addField.input.node.style.borderBottomRightRadius=e==="left-top"?"0px":"12px",this.addField.input.node.style.borderBottomLeftRadius=e==="right-top"?"0px":"12px",this.addField.input.node.style.borderTopRightRadius=e==="left-bottom"?"0px":"12px"}render(){const{candle:e,isShow:i,model:n}=this.state;if(this.setVisible(i),!n||!e)return;this._model=n,this._candle=e;const r={x:n==null?void 0:n.scales.x.convert(e.open_time),y:n==null?void 0:n.scales.y.convert((e.open+e.close)/2)};this.pointer.position(r),this._size||(this.menu.position(r),this.menu.updateAbsolutePosition());const a=Ee({size:this.menu.absolutePosition,parent:n.layout.area,offset:9,coords:r});this._changeInputCorner(a.side),this.menu.position(a.x,a.y)}}class _n extends ft{constructor(e){super("comments",e);h(this,"boxes",{});h(this,"contextMenu");h(this,"_view");this.contextMenu=new mn,this._view=e,e.domElements.append(this.contextMenu.node)}_getCandleCoords(e,i){return{x:e.scales.x.convert(i.open_time),y:e.scales.y.convert((i.open+i.close)/2)}}createBox({boxId:e,coords:i,model:n,comments:r}){const a=new gn({boxId:e,model:n,comments:r,coords:i,view:this._view,onBoxActivate:l=>{const c=r[0].candle;fn.animateToDataCoords(n,c.open_time,(c.open+c.close)/2),this.boxes[l].setState({isActive:!0})},onBoxDeactivate:l=>this.boxes[l].setState({isActive:!1})});this.boxes[e]=a,this.dom.append(a.node)}render(e){this.contextMenu.setState({model:e}),this.contextMenu.forceUpdate();const i=e.comments.grouped,n=new Set(Object.keys(i));Object.entries(i).forEach(([r,a])=>{const l=this._getCandleCoords(e,a[0].candle),c={boxId:r,coords:l,comments:a};this.boxes[r]?this.boxes[r].setState({comments:a,coords:l}):this.createBox({...c,model:e})}),Object.keys(this.boxes).forEach(r=>{n.has(r)||(this.boxes[r].node.remove(),delete this.boxes[r])})}}class pn extends ft{constructor(e){super("guides",e);h(this,"horizontalMarker");h(this,"verticalMarker");this.horizontalMarker=new S({tag:"div",className:this.cx("marker","marker-h")}),this.verticalMarker=new S({tag:"div",className:this.cx("marker","marker-v")}),this.dom.append(this.horizontalMarker.node),this.dom.append(this.verticalMarker.node)}update(e){this.verticalMarker.node.style.display=e.isShowX?"flex":"none",this.horizontalMarker.node.style.display=e.isShowY?"flex":"none"}hide(){this.verticalMarker.node.style.display="none",this.horizontalMarker.node.style.display="none",this.canvas.clear()}show(){this.verticalMarker.node.style.display="flex",this.horizontalMarker.node.style.display="flex"}render(e,{x:i,y:n}){this.canvas.clear();const{layout:{area:r,chart:a},config:{guides:l,yAxis:c,xAxis:d},colorScheme:{guides:{horizontalMarker:g,verticalMarker:f}}}=e;l.isShowY&&W.horizontalMarker({ctx:this.canvas.ctx,node:this.horizontalMarker.node,x:r.left,y:n,lineLength:a.width,text:e.scales.y.invert(n).toFixed(2),position:c.position,mainColor:g.main,lineColor:g.line,textColor:g.text}),l.isShowX&&W.verticalMarker({ctx:this.canvas.ctx,node:this.verticalMarker.node,text:D.timeFormat("%a %d, %b %y %H:%M")(e.scales.x.invert(i)),position:d.position,x:i,y:r.top,lineLength:a.height,mainColor:f.main,lineColor:f.line,textColor:f.text})}}function Fe(s,t,e,{fillColor:i,strokeColor:n,candleWidth:r,strokeWidth:a},l){const c=x=>e.scales.x.convert(x),d=x=>e.scales.y.convert(x),g=c(t.open_time),f=d(t.open),_=d(t.close),p=e.trade.timeRange.includes(t.open_time.getTime()),v=e.trade.timeRange.length&&!p,b=x=>v?A.mix(x,l).toString():x;s.fillStyle=b(i),s.strokeStyle=b(n),s.lineWidth=a,s.beginPath(),s.moveTo(g,d(t.high)),s.lineTo(g,d(t.low)),s.stroke();const y=Math.min(f,_),C=Math.abs(_-f),w=g-r/2;s.fillRect(w,y,r,C),s.strokeRect(w,y,r,C)}function vn(s,t){const{strokeWidth:e,style:i}=t.config.candles,{candles:n,bg:r}=t.colorScheme,a=t.config.candles.baseWidth*t.scales.factorX;t.candles.missingData.forEach((l,c)=>{const d=n.noDataFill[c%n.noDataFill.length],g=i==="filled"?d:n.noDataStroke;Fe(s,l,t,{fillColor:d,strokeColor:g,candleWidth:a,strokeWidth:e},r)})}function bn(s,t){const{strokeWidth:e,style:i}=t.config.candles,n=t.config.candles.baseWidth*t.scales.factorX,{candles:r,bg:a}=t.colorScheme,[l,c]=t.scales.x.domain();t.candles.preparedData.filter(f=>f.open_time>=l&&f.open_time<=c).forEach(f=>{const _=f.close>=f.open?"up":"down",p=_==="up"?r.risingFill:r.fallingFill,v=_==="up"?r.risingStroke:r.fallingStroke;Fe(s,f,t,{fillColor:p,strokeColor:i==="filled"?p:v,candleWidth:n,strokeWidth:e},a)})}class yn extends S{constructor({className:e,isAdaptPosition:i}={}){super({tag:"div",className:e});h(this,"_isAdaptPosition");this._isAdaptPosition=!!i}show({x:e,y:i,parent:n,offset:r=8}){let a=e+r,l=i+r;if(this._isAdaptPosition){this.updateAbsolutePosition();const c=this.absolutePosition,d={top:0,left:0,bottom:n.bottom-n.top,right:n.right-n.left};a+c.width>d.right&&(a=e-c.width-r,a<d.left+r&&(a=d.left+r)),l+c.height>d.bottom&&(l=i-c.height-r,l<d.top+r&&(l=d.top+r))}this.node.style.opacity="1",this.node.style.visibility="visible",this.node.style.left=`${a}px`,this.node.style.top=`${l}px`}hide(){this.node.style.opacity="0",this.node.style.visibility="hidden"}}class xn extends yn{constructor(t){super({className:t,isAdaptPosition:!0});const e=new S({tag:"p"});e.node.textContent="No data from broker",this.append(e.node)}}class wn extends ft{constructor(e){super("candles",e);h(this,"noDataTooltip");this.noDataTooltip=new xn(this.cx("no-data")),this.dom.append(this.noDataTooltip.node)}render(e){this.canvas.clear(),vn(this.canvas.ctx,e),bn(this.canvas.ctx,e)}}class Cn{constructor(t){h(this,"container");h(this,"width");h(this,"height");h(this,"wrapper");h(this,"domElements");h(this,"canvasesContainer");h(this,"mainCanvas");h(this,"binding");h(this,"userMarkers");h(this,"guideMarkers");h(this,"trade");h(this,"comments");h(this,"candles");this.container=t,this.wrapper=new S({tag:"div",className:"sc-charts-cs"}),t.append(this.wrapper.node);const{width:e,height:i}=t.getBoundingClientRect();this.width=e,this.height=i,this.mainCanvas=new we({className:"sc-charts-cs__canvas-main",width:e,height:i,isMain:!0}),this.domElements=new S({tag:"div",className:"sc-charts-cs__dom-elements"}),this.canvasesContainer=new S({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 hi(this.mainCanvas.node),this.userMarkers=new Ji(this),this.comments=new _n(this),this.candles=new wn(this),this.trade=new qi(this),this.guideMarkers=new pn(this)}renderAll(t){this.mainCanvas.clear(),this.candles.render(t),Ot.xAxis(this.mainCanvas.ctx,t),Ot.yAxis(this.mainCanvas.ctx,t),Ot.intersection(this.mainCanvas.ctx,t),this.trade.renderAll(t),this.userMarkers.render(t.userMarkers.data),this.comments.render(t)}}class Mn{constructor(t){h(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"});h(this,"ignoredLogEvents",[]);t&&(this.ignoredLogEvents=t)}log(t,e){if(this.ignoredLogEvents.includes(t))return;const i=this.logColors[t]||"color: gray";let n;try{n=JSON.parse(JSON.stringify(e))}catch{n=e}console.log(`%c[SUBSCRIBE] ${t}`,i,n)}}class An{constructor(t,e){h(this,"_model");h(this,"_view");h(this,"_enableLogging");h(this,"_logger");this._model=t,this._view=e,this._enableLogging=!1,this._logger=new Mn(["scale_event"])}subscribeWithLogging(t,e){const i=n=>{this._enableLogging&&this._logger.log(t,n),e(n)};this._model.subscribe(t,i)}init(){this.subscribeWithLogging("init_model",()=>{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",t=>{this._model.config.update(t),this._model.layout.updateConfig(this._model.config),this._model.userMarkers.rebuild(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_candles",t=>{this._model.candles.update(t),this._model.scales.reinit(),this._model.trade.recalculate(),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_trade",t=>{this._model.trade.updateTrade(t),this._view.renderAll(this._model)}),this.subscribeWithLogging("update_user_markers",t=>{this._model.userMarkers.updateMarkers(t),this._view.userMarkers.render(this._model.userMarkers.data)}),this.subscribeWithLogging("update_color_scheme",t=>{this._model.colorScheme.update(t),this._view.mainCanvas.background=this._model.colorScheme.bg,this._view.renderAll(this._model)}),this.subscribeWithLogging("open_trade_label_tooltip",({trade:t,x:e,y:i})=>{this._model.trade.setActiveTrade(t.tradeType,t.candle.open_time.getTime()),this._view.trade.renderAll(this._model),this._view.trade.labelTooltip.updateContent(t.trades),this._view.trade.labelTooltip.setState({isShow:!0,x:e,y:i,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:t,y:e})=>{this._view.candles.noDataTooltip.show({x:t,y:e,parent:this._model.layout.area})}),this.subscribeWithLogging("leave_nodata_candle",()=>{this._view.candles.noDataTooltip.hide()}),this.subscribeWithLogging("mouseover_trade_label_tooltip",t=>{this._model.trade.setHoveredTrade(t.tradeType,t.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",t=>{this._model.comments.data=t,this._view.renderAll(this._model)})}}class Be{constructor(){h(this,"_map",new Map)}add(t,e,i){let n=this._map.get(t);n||(n={},this._map.set(t,n)),n[e]||(n[e]=new Set),n[e].add(i)}remove(t,e,i){var r;const n=this._map.get(t);(r=n==null?void 0:n[e])==null||r.delete(i)}removeAll(t){this._map.delete(t)}emit(t,e){const i=this._map.get(t),n=i==null?void 0:i[e.type];if(!n)return!1;let r=!1;const a={...e,stopPropagation:()=>{r=!0}};for(const l of n)if(l(a),r)break;return r}}class Tn{constructor(){h(this,"_elements",[]);h(this,"_listeners",new Be);h(this,"_lastHovered",new Set);h(this,"_dragContext",null)}get isDragging(){return this._dragContext!==null}register(...t){this._elements.push(...t)}unregister(t){this._elements=this._elements.filter(e=>e!==t),this._listeners.removeAll(t),this._lastHovered.delete(t)}clear(){this._elements=[],this._listeners=new Be,this._lastHovered.clear()}on(t,e,i){this._listeners.add(t,e,i)}off(t,e,i){this._listeners.remove(t,e,i)}dispatchMouseMove(t,e){if(this._dragContext){this._emitSingle(this._dragContext.target,{type:"drag",target:this._dragContext.target,x:t,y:e,prevX:this._dragContext.lastX,prevY:this._dragContext.lastY}),this._dragContext.lastX=t,this._dragContext.lastY=e;return}const i=this._getHitsAt(t,e),n=new Set(i.map(r=>r.target));for(const r of i)if(!this._lastHovered.has(r.target)&&this._emitSingle(r.target,{type:"mouseover",target:r.target,x:r.x,y:r.y})||this._emitSingle(r.target,{type:"mousemove",target:r.target,x:r.x,y:r.y}))break;for(const r of this._lastHovered)n.has(r)||this._emitSingle(r,{type:"mouseleave",target:r,x:t,y:e});this._lastHovered=n}dispatchMouseDown(t,e){const i=this._getHitsAt(t,e);if(i.length===0){this._dragContext=null;return}this._dragContext=null;for(const n of i)if(this._emitSingle(n.target,{type:"mousedown",target:n.target,x:n.x,y:n.y})){this._dragContext={target:n.target,lastX:t,lastY:e};break}!this._dragContext&&i.length>0&&(this._dragContext={target:i[i.length-1].target,lastX:t,lastY:e})}dispatchMouseUp(t,e){this._dragContext&&this._emitSingle(this._dragContext.target,{type:"mouseup",target:this._dragContext.target,x:t,y:e}),this._dragContext=null}dispatchClick(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"click",target:n.target,x:n.x,y:n.y}))break}dispatchDblClick(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"dblclick",target:n.target,x:n.x,y:n.y}))break}dispatchContextMenu(t,e){const i=this._getHitsAt(t,e);for(const n of i)if(this._emitSingle(n.target,{type:"contextmenu",target:n.target,x:n.x,y:n.y}))break}dispatchWheel(t,e,i,n,r){const a=this._getHitsAt(t,e);for(const l of a)if(this._emitSingle(l.target,{type:"wheel",target:l.target,x:l.x,y:l.y,deltaX:i,deltaY:n,deltaZ:r}))break}hitTestAll(t,e){return this._getHitsAt(t,e)}_getHitsAt(t,e){return this._elements.map(i=>i.hitTest(t,e)).filter(i=>i!==null)}_emitSingle(t,e){let i=!1;const n={...e,stopPropagation(){i=!0}};return this._listeners.emit(t,n),i}}class Sn{constructor(t){this.model=t}hitTest(t,e){const{candles:{missingData:i},scales:{x:n,y:r},config:{candles:{baseWidth:a}}}=this.model;for(const l of i){const c=n.convert(l.open_time),d=r.convert(l.high),g=r.convert(l.low),f=c-a/2,_=c+a/2,p=Math.min(d,g),v=Math.max(d,g);if(t>=f&&t<=_&&e>=p&&e<=v)return{target:this,x:t,y:e,type:"candle",candle:l}}return null}}class kn{constructor(t,e){h(this,"_model");h(this,"_hitManager");h(this,"_hit");this._model=t,this._hitManager=e,this._hit=new Sn(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mouseover",t=>{const e=this._hit.hitTest(t.x,t.y);if(!e)return;const i=this._model.scales.x.convert(e.candle.open_time),n=this._model.scales.y.convert(e.candle.high)-4;this._model.eventBus.emit("hover_nodata_candle",{x:i,y:n})}),this._hitManager.on(this._hit,"mouseleave",()=>{this._model.eventBus.emit("leave_nodata_candle")})}}class Dn{constructor(t){this.model=t}hitTest(t,e){const{tradedCandles:i}=this.model.trade,{x:n,y:r}=this.model.scales,a=16,l=4;for(const{candle:c,trades:d}of i){const f=n.convert(c.open_time)+this.model.config.candles.baseWidth/2,_=a,p=a;for(const v of["buy","sell"]){const b=d.filter(x=>x.type===v);if(!b.length)continue;const y=v==="buy"?r.convert(c.low)+l+At(a):r.convert(c.high)-l-a-At(a),C=t>=f-_/2&&t<=f+_/2,w=e>=y&&e<=y+p;if(C&&w)return{target:this,type:"trade-label",tradeType:v,x:t,y:e,candle:c,trades:b}}}return null}}class Ln{constructor(t,e){h(this,"_model");h(this,"_hitManager");h(this,"_tradeLabelHit");this._model=t,this._hitManager=e,this._tradeLabelHit=new Dn(t),this._hitManager.register(this._tradeLabelHit)}register(){this._hitManager.on(this._tradeLabelHit,"click",t=>{const e=this._tradeLabelHit.hitTest(t.x,t.y);if(!e)return;const i=this._model.scales.x.convert(e.candle.open_time),n=this._model.scales.y.convert(e.trades[0].type==="buy"?e.candle.low:e.candle.high),r=e.trades[0].type==="buy"?n+4+At(16)+8:n-4-16-At(16)+8;this._model.eventBus.emit("open_trade_label_tooltip",{trade:{candle:e.candle,trades:e.trades,tradeType:e.tradeType},x:i,y:r})}),this._hitManager.on(this._tradeLabelHit,"mouseover",t=>{const e=this._tradeLabelHit.hitTest(t.x,t.y);e&&this._model.eventBus.emit("mouseover_trade_label_tooltip",{candle:e.candle,trades:e.trades,tradeType:e.tradeType})}),this._hitManager.on(this._tradeLabelHit,"mouseleave",()=>{this._model.eventBus.emit("mouseleave_trade_label_tooltip")})}}class En{constructor(t){this.model=t}hitTest(t,e){const{xAxis:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"x-axis"}:null}}class Nn{constructor(t){this.model=t}hitTest(t,e){const{area:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"area"}:null}}class In{constructor(t){this.model=t}hitTest(t,e){const{yAxis:i}=this.model.layout;return t>=i.x&&t<=i.x+i.width&&e>=i.y&&e<=i.y+i.height?{target:this,x:t,y:e,type:"y-axis"}:null}}function Fn(s,t){let e={x:0,y:0},i=null;return n=>{Math.abs(n.x-e.x)<s&&Math.abs(n.y-e.y)<s||(e={x:n.x,y:n.y},i&&cancelAnimationFrame(i),i=requestAnimationFrame(()=>{t(n),i=null}))}}function Bn(s,t){let e=null;return i=>{const n=i.x-(i.prevX??i.x),r=i.y-(i.prevY??i.y);Math.abs(n)<s&&Math.abs(r)<s||(e&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{t(i),e=null}))}}class Hn{constructor(t,e){h(this,"_model");h(this,"_hitManager");h(this,"_hit");this._model=t,this._hitManager=e,this._hit=new En(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"drag",t=>{const e=t.x-(t.prevX??t.x);this._model.scales.scale("x",-e)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.scale("x",1,"absolute"),this._model.scales.pan("x",0,"absolute")})}}class Rn{constructor(t,e){h(this,"_model");h(this,"_hitManager");h(this,"_hit");this._model=t,this._hitManager=e,this._hit=new In(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"drag",t=>{const e=t.y-(t.prevY??t.y);this._model.scales.scale("y",-e)}),this._hitManager.on(this._hit,"dblclick",()=>{this._model.scales.fitYToVisibleCandles()})}}class $n{constructor(t,e,i){h(this,"_model");h(this,"_view");h(this,"_hitManager");h(this,"_hit");this._model=t,this._view=e,this._hitManager=i,this._hit=new Nn(t),this._hitManager.register(this._hit)}register(){this._hitManager.on(this._hit,"mousemove",Fn(1,t=>{this._view.guideMarkers.show(),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"mouseleave",()=>{this._view.guideMarkers.hide()}),this._hitManager.on(this._hit,"drag",Bn(1,t=>{const e=t.x-(t.prevX??t.x),i=t.y-(t.prevY??t.y);this._model.scales.pan("x",e),this._model.scales.pan("y",i),this._view.guideMarkers.render(this._model,{x:t.x,y:t.y})})),this._hitManager.on(this._hit,"contextmenu",({x:t})=>{const e=this._model.scales.x.invert(t),i=Pt.findByDate(e,this._model.candles.allData);i&&(this._view.comments.contextMenu.setState({isShow:!0,candle:i}),this._view.comments.render(this._model))}),this._hitManager.on(this._hit,"wheel",t=>{var n,r;if(!t.deltaY)return;const e=-t.deltaY,i=(r=(n=this._model.config)==null?void 0:n.candles)==null?void 0:r.zoomOnWheel;["x","both"].includes(i)&&this._model.scales.scale("x",e),["y","both"].includes(i)&&this._model.scales.scale("y",e)})}}class zn{constructor(t,e,i){h(this,"_hitManager");h(this,"_candlesHandler");h(this,"_tradeLabelsHandler");h(this,"_xAxisHandler");h(this,"_yAxisHandler");h(this,"_areaHandler");this._hitManager=i,this._candlesHandler=new kn(t,this._hitManager),this._tradeLabelsHandler=new Ln(t,this._hitManager),this._xAxisHandler=new Hn(t,this._hitManager),this._yAxisHandler=new Rn(t,this._hitManager),this._areaHandler=new $n(t,e,this._hitManager)}register(){this._candlesHandler.register(),this._tradeLabelsHandler.register(),this._xAxisHandler.register(),this._yAxisHandler.register(),this._areaHandler.register()}}class Pn{constructor(t,e){h(this,"_model");h(this,"_view");h(this,"_subscriptionsManager");h(this,"_hitManager",new Tn);h(this,"_boundMouseMove",this.onDocumentMouseMove.bind(this));h(this,"_boundMouseUp",this.onDocumentMouseUp.bind(this));this._model=t,this._view=e,this._subscriptionsManager=new An(t,e)}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 zn(this._model,this._view,this._hitManager).register()}onContextMenu(t){t.preventDefault();const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchContextMenu(e,i)}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(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchDblClick(e,i)}onDocumentClick(t){const e=this.getMouseRelative(t);this._hitManager.dispatchClick(e.x,e.y),!this._hitManager.hitTestAll(e.x,e.y).find(n=>n.type==="trade-label")&&this._model.trade.hasActiveTrade&&this._model.eventBus.emit("close_trade_label_tooltip")}getMouseRelative(t){return{x:t.clientX-this._view.mainCanvas.absolutePosition.left,y:t.clientY-this._view.mainCanvas.absolutePosition.top}}onDocumentMouseMove(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseMove(e,i)}onMouseDown(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseDown(e,i),t.preventDefault(),document.addEventListener("mouseup",this._boundMouseUp),this._hitManager.isDragging&&document.addEventListener("mousemove",this._boundMouseMove)}onMouseUp(t){const e=this.getMouseRelative(t);this._hitManager.dispatchMouseUp(e.x,e.y),document.removeEventListener("mouseup",this._boundMouseUp)}onDocumentMouseUp(t){const{x:e,y:i}=this.getMouseRelative(t);this._hitManager.dispatchMouseUp(e,i),document.removeEventListener("mouseup",this._boundMouseUp),document.removeEventListener("mousemove",this._boundMouseMove)}onMouseMove(t){var r;if(!this._hitManager.isDragging){const{x:a,y:l}=this.getMouseRelative(t);this._hitManager.dispatchMouseMove(a,l)}const{x:e,y:i}=this.getMouseRelative(t),n=this._hitManager.hitTestAll(e,i);(r=n[0])!=null&&r.type&&(n[0].type==="area"?this._view.mainCanvas.node.style.cursor="crosshair":n[0].type==="trade-label"?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(t){t.preventDefault(),this._hitManager.dispatchWheel(t.offsetX,t.offsetY,t.deltaX,t.deltaY,t.deltaZ)}}class On{constructor(t,{chartId:e,candles:i,config:n,trade:r,userMarkers:a,colorScheme:l,comments:c}){h(this,"_model");h(this,"_view");h(this,"_controller");const d=document.querySelector(t);if(!d)throw new Error(`Element with selector "${t}" not found!`);if(!e||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(e))throw new Error("chartId is required and must be a valid id (only letters, numbers or underscores. The first character must be a letter)");this._model=new ri({chartId:e,candles:i,config:n,container:d,trade:r,userMarkers:a,colorScheme:l,comments:c}),this._view=new Cn(d),this._controller=new Pn(this._model,this._view),this._controller.init()}updateConfig(t){this._model.updateConfig(t)}updateTrade(t){this._model.updateTrade(t)}updateUserMarkers(t){this._model.updateUserMarkers(t)}updateColorScheme(t){this._model.updateColorScheme(t)}updateCandles(t){this._model.updateCandles(t)}updateComments(t){this._model.updateComments(t)}}$.CandlestickChart=On,$.createLineChart=Rs,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
|
4
3
|
//# sourceMappingURL=charts-core.umd.cjs.map
|