@gearbox-protocol/ui-kit 3.14.0-next.36 → 3.14.0-next.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),U=require("lightweight-charts"),b=require("react"),Je=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),E=require("../../utils/colors.cjs"),ie=require("./default-config.cjs"),ee=require("./formatters.cjs"),Ye=require("./graph-current-value.cjs"),Ue=require("./graph-tooltip.cjs"),et=require("./plugins/vertical-line.cjs");function tt(e){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const c in e)if(c!=="default"){const h=Object.getOwnPropertyDescriptor(e,c);Object.defineProperty(i,c,h.get?h:{enumerable:!0,get:()=>e[c]})}}return i.default=e,Object.freeze(i)}const Se=tt(b);class ot{_yTop;_yBottom;_color;constructor(i,c,h){this._yTop=i,this._yBottom=c,this._color=h}draw(i){i.useBitmapCoordinateSpace(c=>{const h=c.context,p=c.verticalPixelRatio,_=this._yTop===null?0:this._yTop*p,H=this._yBottom===null?c.bitmapSize.height:this._yBottom*p,w=Math.min(_,H),M=Math.max(_,H);h.fillStyle=this._color,h.fillRect(0,w,c.bitmapSize.width,M-w)})}}class rt{_source;_yTop=null;_yBottom=null;constructor(i){this._source=i}update(){const i=this._source.series;this._yTop=this._source.priceTop===void 0?null:i.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:i.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new ot(this._yTop,this._yBottom,this._source.color)}}class nt{series;priceTop;priceBottom;color;_paneViews;constructor(i,c,h,p){this.series=i,this.priceTop=c,this.priceBottom=h,this.color=p,this._paneViews=[new rt(this)]}updateAllViews(){for(const i of this._paneViews)i.update()}paneViews(){return this._paneViews}}function We(e,i,c){const h=e.labelText??"",p=e.value,_=p===void 0?"":typeof p=="number"?i==="$"?`$${ee.formatExactValue(p,void 0,c)}`:i==="%"?`${ee.formatExactValue(p,void 0,c)}%`:ee.formatExactValue(p,i!=="none"&&i!=="%"&&i!=="$"?i:void 0,c):String(p);return{labelText:h,valueStr:_}}function $e(e,i){for(let c=e.length-1;c>=0;c--)if(Number(e[c].time)<=i)return e[c].value;return 0}const ce=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],lt=137.5;function xe(e){if(e<ce.length)return ce[e];const c=(e-ce.length)*lt%360,h=E.hslToHex(c,70,50),{topColor:p,bottomColor:_}=E.generateColorsFromBase(h);return{line:h,top:p,bottom:_}}function at({series:e,className:i,showLegend:c=!1,onUnselectSeries:h,xMeasureUnit:p="time",yMeasureUnit:_="token",optionsOverrides:H,verticalLineOptions:w,priceLineOptions:M,zoneOptions:$,currentValueDecimals:ue,useSharedPriceScale:q=!1,dualYAxis:k=!1,defaultVisiblePriceScaleId:ye="right",leftPriceScaleTitle:we,rightPriceScaleTitle:st,showCurrentValue:Oe=!0,graphTitle:fe,yScaleMin:Re,yScaleMinMultiple:Te,visibleTimeFrom:X,disableZoom:le=!1,hideDefaultTooltip:ge=!1}){const I=b.useRef(null),R=b.useRef(new Map),he=b.useRef(!1),_e=b.useRef(!0),Ve=b.useRef([]),Z=b.useRef(null),de=b.useRef(null),ae=b.useRef(null),N=Je.useIsMobile(),A=Se.useMemo(()=>e.flatMap(o=>o.data),[e]),Ge=Se.useMemo(()=>{if(e.length>0){const o=e[e.length-1];if(o.data.length>0)return o.data[o.data.length-1]}},[e]),[Ne,pe]=b.useState(()=>{if(!Ge)return;const o=new Map;for(const a of e)a.data.length>0&&o.set(a.label,a.data[a.data.length-1]);return o}),[Pe,O]=b.useState(null),[Le,Me]=b.useState([]);b.useEffect(()=>{const o=()=>{try{if(I.current&&Z.current){const n=Z.current.clientWidth,s=Z.current.clientHeight;I.current.resize(n,s)}}catch{}},a=Z.current,l=a?new ResizeObserver(o):null;return ae.current=l,a&&l?.observe(a),()=>{a&&l?.unobserve(a),l?.disconnect(),ae.current=null}},[]),b.useEffect(()=>{if(!de.current||he.current)return;const o=ie.getDefaultOptions(),a=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{},n=U.createChart(de.current,{...o,leftPriceScale:{...o.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...o.rightPriceScale||{},visible:!N,textColor:a},...N&&{crosshair:{...o.crosshair,mode:U.CrosshairMode.Magnet}},...l,...H});return I.current=n,he.current=!0,()=>{ae.current?.disconnect(),ae.current=null,n.remove(),I.current=null,he.current=!1,R.current.clear()}},[N,H,le]),b.useEffect(()=>{const o=I.current;o&&o.applyOptions(le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[le]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const l=e.filter(r=>r.data.length>0).length<=1?Re:Te,n=p==="time"?ee.getXFormatters(p,A):ee.getXFormatters(p),s=new Map;{let r=0;for(const t of e)t.data.length!==0&&(s.set(t.label,t.priceScaleId??(r===0?"left":"right")),r++)}const g=(r,t,f)=>{const{formatter:B,tickmarksFormatter:y,updateVisibleRange:z,updateLastValues:Be}=ee.createAdaptiveYAxisFormatter(r,t,{yScaleMin:l}),me=e.filter(K=>K.data.length>0&&f.has(K.label)).map(K=>K.data[K.data.length-1].value);return Be(me),{formatter:B,tickmarksFormatter:y,updateVisibleRange:z,labels:f}},u=[];if(k)for(const r of["left","right"]){const t=new Set,f=[];let B=_;for(const y of e)if(y.data.length!==0&&s.get(y.label)===r){t.size===0&&y.yMeasureUnit&&(B=y.yMeasureUnit),t.add(y.label);for(const z of y.data)f.push(z.value)}t.size>0&&u.push(g(f,B,t))}else{const r=A.map(f=>f.value),t=new Set(e.filter(f=>f.data.length>0).map(f=>f.label));u.push(g(r,_,t))}Ve.current=u;const C=new Map;for(const r of u)for(const t of r.labels)C.set(t,r);const S=ie.getDefaultOptions();o.applyOptions({localization:{...S.localization||{},timeFormatter:r=>n.timeFormatter(parseFloat(r),void 0)},timeScale:{...S.timeScale||{},tickMarkFormatter:n.tickMarkFormatter,minBarSpacing:0}});const j=(A.length>0?Math.min(...A.map(r=>r.value)):0)<0,T=A.some(r=>r.value===0),m=!j&&T,x=!k&&e.length>1&&!q,P=k?N:e.length>1&&!q||N,L=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({...k&&{defaultVisiblePriceScaleId:ye},leftPriceScale:{...S.leftPriceScale||{},visible:k&&!N,textColor:L,...k&&we&&{}},rightPriceScale:{...S.rightPriceScale||{},visible:k?!N:!P,textColor:L,...m&&!k&&{scaleMargins:{top:.3,bottom:0}}}});const V=new Set(R.current.keys()),Q=new Set(e.map(r=>r.label));for(const r of V)if(!Q.has(r)){const t=R.current.get(r);t&&(o.removeSeries(t),R.current.delete(r))}const J=ie.getDefaultSeries(),te=[];let oe=0;const je=e.find(r=>r.data.length>0),re=new Map;if(M&&M.length>0)for(const r of M){if(!Number.isFinite(r.price))continue;const t=r.seriesLabel??je?.label;if(!t)continue;const f=re.get(t)??[];f.push(r.price),re.set(t,f)}if($&&$.length>0)for(const r of $){const t=r.seriesLabel??je?.label;if(!t)continue;const f=re.get(t)??[];Number.isFinite(r.priceTop)&&f.push(r.priceTop),Number.isFinite(r.priceBottom)&&f.push(r.priceBottom),re.set(t,f)}for(let r=0;r<e.length;r++){const t=e[r],f=xe(r),B=t.lineColor??t.color??f.line;let y,z;if(t.lineColor??t.color)if(t.topColor&&t.bottomColor)y=t.topColor,z=t.bottomColor;else if(t.topColor){const d=E.generateColorsFromBase(B);y=t.topColor,z=d.bottomColor}else if(t.bottomColor)y=E.generateColorsFromBase(B).topColor,z=t.bottomColor;else{const d=E.generateColorsFromBase(B);y=d.topColor,z=d.bottomColor}else y=t.topColor||f.top,z=t.bottomColor||f.bottom;if(t.data.length===0){const d=R.current.get(t.label);d&&(o.removeSeries(d),R.current.delete(t.label));continue}const me=(t.data.length>0?Math.min(...t.data.map(d=>d.value)):0)<0,K=t.data.some(d=>d.value===0),He=!me&&K,Fe=k?t.priceScaleId??(oe===0?"left":"right"):q||!x||oe===0?"right":`scale-${oe}`;x&&te.push({priceScaleId:Fe||"right",shouldPreventNegativeAxis:He,seriesIndex:oe});const De=(q||!x)&&l!==void 0&&typeof l=="number",Xe=re.get(t.label)??[],Ze=d=>{const D=d();if(D?.priceRange){De&&(D.priceRange.minValue=l);for(const W of Xe)W<D.priceRange.minValue&&(D.priceRange.minValue=W),W>D.priceRange.maxValue&&(D.priceRange.maxValue=W)}return D},Ee=C.get(t.label)??u[0],Ie=Ee.formatter,Ke=Ee.tickmarksFormatter,ve={lineColor:B,topColor:y,bottomColor:z,priceScaleId:Fe,...t.seriesType==="line"&&{lineStyle:t.lineStyle??U.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:De&&typeof l=="number"?d=>Ie(d<l?l:d):Ie,tickmarksFormatter:Ke},autoscaleInfoProvider:Ze},ze=t.seriesType==="line";let F=R.current.get(t.label);const Y=t.data.map(d=>({...d,time:d.time}));if(X!==void 0&&Y.length>0&&Number(Y[0].time)>X){const d=Number(Y[0].time),D=d-X,W=86400,Qe=D>180*W?7*W:D>30*W?W:6*3600,qe=[];for(let Ce=X;Ce<d;Ce+=Qe)qe.push({time:Ce});Y.unshift(...qe)}F&&F.seriesType()!==(ze?"Line":"Area")&&(o.removeSeries(F),R.current.delete(t.label),F=void 0),F?(F.applyOptions(ve),F.setData(Y)):(ze?F=o.addSeries(U.LineSeries,{...J,...ve}):F=o.addSeries(U.AreaSeries,{...J,...ve}),F.setData(Y),R.current.set(t.label,F)),oe++}if(k)try{const r=o.priceScale("left"),t=o.priceScale("right"),f={visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:.1},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L};r?.applyOptions(f),t?.applyOptions(f)}catch{}else if(x&&te.length>0)for(const r of te)try{const t=o.priceScale(r.priceScaleId);t&&t.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...r.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch(t){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,t)}else if(!x)try{const r=o.priceScale("right");r&&r.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:l!==void 0||m?0:.1,...m&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch{}if(l!==void 0&&!N&&(q||!x)&&o.applyOptions({handleScroll:{vertTouchDrag:!1}}),A.length>0){const r=A.map(y=>Number(y.time)),t=Math.min(...r),f=X!==void 0?Math.min(X,t):t,B=Math.max(...r);o.timeScale().setVisibleRange({from:f,to:B})}_e.current&&(_e.current=!1);const be=new Map;for(const r of e)r.data.length>0&&be.set(r.label,r.data[r.data.length-1]);pe(be.size>0?be:void 0)},[e,A,p,_,N,q,k,ye,we,Re,Te,X,M,$]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const a=e.length===1;let l;for(const s of e)if(s.data.length>0){l=s.data[s.data.length-1].time;break}if(!l)return;const n=s=>{const{time:g=l,seriesData:u,point:C}=s||{},S=Array.from(R.current.values());if(!C||!g){const T=new Map;for(const m of e)m.data.length>0&&T.set(m.label,m.data[m.data.length-1]);if(pe(T.size>0?T:void 0),a||q||ge)O(null);else if(S[0]&&l){const x=o.timeScale().timeToCoordinate(l),P=e[0];if(P.data.length>0){const L=P.data[P.data.length-1].value,V=S[0].priceToCoordinate(L);x!==null&&V!==null&&O({x,y:V})}}return}const G=new Map;let j;for(let T=0;T<e.length;T++){const m=e[T],x=S[T];if(!x)continue;const P=u?.get(x),L=P&&"value"in P?P.value:void 0;let V;if(L!==void 0)V=L;else if(a){const Q=Number(g),J=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;Q<J?V=Number.NaN:V=m.data[m.data.length-1]?.value??0}else V=$e(m.data,Number(g));Number.isNaN(V)||(j===void 0&&(j=V),G.set(m.label,{value:V,time:g}))}if(pe(G),j!==void 0&&S[0]){const m=o.timeScale().timeToCoordinate(g),x=S[0].priceToCoordinate(j);if(m!==null&&x!==null){const P=Z.current;if(P){const L=P.querySelector(".LightweightChart");if(L){const V=L.getBoundingClientRect(),Q=P.getBoundingClientRect(),J=m+(V.left-Q.left),te=x+(V.top-Q.top);O({x:J,y:te})}else O({x:m,y:x})}else O({x:m,y:x})}else O(null)}else O(null)};return o.subscribeCrosshairMove(n),N&&o.subscribeClick(n),!a&&!q&&!ge&&requestAnimationFrame(()=>{const s=Array.from(R.current.values());if(s[0]&&l&&e[0]?.data.length>0){const u=o.timeScale().timeToCoordinate(l),C=e[0].data[e[0].data.length-1].value,S=s[0].priceToCoordinate(C);u!==null&&S!==null&&O({x:u,y:S})}}),()=>{o.unsubscribeCrosshairMove(n),N&&o.unsubscribeClick(n)}},[e,q,N,ge]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const a=o.timeScale(),l=()=>{const n=Ve.current;if(n.length===0)return;const s=a.getVisibleRange();if(!s)return;const g=Number(s.from),u=Number(s.to);for(const C of n){const S=[];for(const G of e)if(C.labels.has(G.label))for(const j of G.data){const T=Number(j.time);T>=g&&T<=u&&S.push(j.value)}S.length>0&&C.updateVisibleRange(S)}};return a.subscribeVisibleLogicalRangeChange(l),()=>{a.unsubscribeVisibleLogicalRangeChange(l)}},[e]),b.useEffect(()=>{const o=I.current,a=Array.from(R.current.values()),l=[];if(o&&a.length>0&&w){const n=ie.getDefaultVerticalLine(),s=a[0];for(const g of w){const u={...n,...g.options||{}};u.color&&(u.color=E.resolveCSSColor(u.color,u.color));const C=new et.VertLine(o,s,g.xCoordinate,u);s.attachPrimitive(C),l.push(C)}}return()=>{if(a.length>0){const n=a[0];for(const s of l)n.detachPrimitive(s)}}},[w,e]),b.useEffect(()=>{const o=[];if(M&&M.length>0){const a=Array.from(R.current.values())[0],l=E.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const n of M){if(!Number.isFinite(n.price))continue;const s=n.seriesLabel?R.current.get(n.seriesLabel):a;if(!s)continue;const g=s.createPriceLine({price:n.price,color:n.color?E.resolveCSSColor(n.color,n.color):l,lineWidth:n.lineWidth??1,lineStyle:n.lineStyle??U.LineStyle.Dashed,axisLabelVisible:n.axisLabelVisible??!0,title:n.title??""});o.push({series:s,line:g})}}return()=>{for(const{series:a,line:l}of o)try{a.removePriceLine(l)}catch{}}},[M,e]),b.useEffect(()=>{const o=[];if($&&$.length>0){const a=Array.from(R.current.values())[0],l="rgba(239, 68, 68, 0.12)";for(const n of $){const s=n.seriesLabel?R.current.get(n.seriesLabel):a;if(!s)continue;const g=n.color?E.resolveCSSColor(n.color,l):l,u=new nt(s,n.priceTop,n.priceBottom,g);s.attachPrimitive(u),o.push({series:s,zone:u})}}return()=>{for(const{series:a,zone:l}of o)try{a.detachPrimitive(l)}catch{}}},[$,e]),b.useEffect(()=>{const o=I.current;if(!o||!w?.length){Me([]);return}const a=()=>{const s=o.timeScale(),g=w.map(u=>s.timeToCoordinate(u.xCoordinate)??null);Me(g)};a();const l=o.timeScale(),n=()=>{a()};return l.subscribeVisibleLogicalRangeChange(n),()=>{l.unsubscribeVisibleLogicalRangeChange(n)}},[w,e]);const se=e.length===1,ke=Se.useMemo(()=>{if(se&&e.length>0){const o=e[0];if(o.data.length>0)return o.data[o.data.length-1]}},[se,e]);return v.jsxs("div",{ref:Z,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",i),children:[fe!=null&&fe!==!1&&se?v.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:v.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:fe})}):Oe&&se&&ke&&v.jsx(Ye.GraphCurrentValue,{point:ke,xMeasureUnit:p,yMeasureUnit:_,decimals:ue}),Ne&&Pe&&v.jsx(Ue.GraphTooltip,{points:Ne,xMeasureUnit:p,yMeasureUnit:_,series:e,position:Pe,containerRef:Z,decimals:ue}),c&&v.jsx(Ae,{series:e,onUnselect:h}),w&&w.length>0&&Le.length===w.length&&v.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:w.map((o,a)=>{const l=Le[a],n=o.options??{},s=n.showLabel!==!1;if(l===null||!s)return null;const{labelText:g,valueStr:u}=We(n,_,ue),C=n.tooltipText??"";if(!(g||u||C))return null;const G=n.labelBackgroundColor??n.color??"hsl(var(--background))",j=n.labelTextColor??"hsl(var(--foreground))",T=`${String(o.xCoordinate)}-${g}-${C}`;return v.jsxs("div",{className:ne.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",C&&"pointer-events-auto cursor-default"),style:{left:l,transform:"translateX(-50%)",backgroundColor:G,color:j},children:[g&&v.jsx("span",{className:"block",children:g}),u&&v.jsx("span",{className:ne.cn("block",g&&"mt-0.5"),children:u}),C&&v.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:C})]},T)})}),v.jsx("div",{ref:de,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ae({series:e,onUnselect:i,inline:c=!1}){return v.jsx("div",{className:ne.cn("flex flex-wrap gap-2",c?"items-center":"absolute top-0 left-2 z-[10]"),children:e.map((h,p)=>{const _=xe(p),H=(h.lineColor??h.color)||_.line,w=h.data.length===0;return v.jsxs("div",{className:ne.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",w&&"opacity-50"),children:[v.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:H}}),v.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[h.label,w&&" (no data)"]}),i&&v.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),i(h.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${h.label}`,children:v.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[v.jsx("title",{children:"Close"}),v.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),v.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},h.label)})})}exports.DEFAULT_SERIES_COLORS=ce;exports.Graph=at;exports.GraphLegend=Ae;exports.getSeriesColorPalette=xe;exports.getStepForwardValue=$e;exports.getVerticalLineTooltipContent=We;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),U=require("lightweight-charts"),m=require("react"),Je=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),E=require("../../utils/colors.cjs"),ie=require("./default-config.cjs"),ee=require("./formatters.cjs"),Ye=require("./graph-current-value.cjs"),Ue=require("./graph-tooltip.cjs"),et=require("./plugins/vertical-line.cjs");function tt(t){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const c in t)if(c!=="default"){const h=Object.getOwnPropertyDescriptor(t,c);Object.defineProperty(i,c,h.get?h:{enumerable:!0,get:()=>t[c]})}}return i.default=t,Object.freeze(i)}const Se=tt(m);class ot{_yTop;_yBottom;_color;constructor(i,c,h){this._yTop=i,this._yBottom=c,this._color=h}draw(i){i.useBitmapCoordinateSpace(c=>{const h=c.context,p=c.verticalPixelRatio,R=this._yTop===null?0:this._yTop*p,H=this._yBottom===null?c.bitmapSize.height:this._yBottom*p,w=Math.min(R,H),M=Math.max(R,H);h.fillStyle=this._color,h.fillRect(0,w,c.bitmapSize.width,M-w)})}}class rt{_source;_yTop=null;_yBottom=null;constructor(i){this._source=i}update(){const i=this._source.series;this._yTop=this._source.priceTop===void 0?null:i.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:i.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new ot(this._yTop,this._yBottom,this._source.color)}}class nt{series;priceTop;priceBottom;color;_paneViews;constructor(i,c,h,p){this.series=i,this.priceTop=c,this.priceBottom=h,this.color=p,this._paneViews=[new rt(this)]}updateAllViews(){for(const i of this._paneViews)i.update()}paneViews(){return this._paneViews}}function We(t,i,c){const h=t.labelText??"",p=t.value,R=p===void 0?"":typeof p=="number"?i==="$"?`$${ee.formatExactValue(p,void 0,c)}`:i==="%"?`${ee.formatExactValue(p,void 0,c)}%`:ee.formatExactValue(p,i!=="none"&&i!=="%"&&i!=="$"?i:void 0,c):String(p);return{labelText:h,valueStr:R}}function $e(t,i){for(let c=t.length-1;c>=0;c--)if(Number(t[c].time)<=i)return t[c].value;return 0}const ce=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],lt=137.5;function xe(t){if(t<ce.length)return ce[t];const c=(t-ce.length)*lt%360,h=E.hslToHex(c,70,50),{topColor:p,bottomColor:R}=E.generateColorsFromBase(h);return{line:h,top:p,bottom:R}}function at({series:t,className:i,showLegend:c=!1,onUnselectSeries:h,xMeasureUnit:p="time",yMeasureUnit:R="token",optionsOverrides:H,verticalLineOptions:w,priceLineOptions:M,zoneOptions:$,currentValueDecimals:ue,useSharedPriceScale:q=!1,dualYAxis:j=!1,defaultVisiblePriceScaleId:ye="right",leftPriceScaleTitle:we,rightPriceScaleTitle:st,showCurrentValue:Oe=!0,graphTitle:fe,yScaleMin:Re,yScaleMinMultiple:Te,visibleTimeFrom:X,disableZoom:le=!1,hideDefaultTooltip:ge=!1}){const I=m.useRef(null),S=m.useRef(new Map),he=m.useRef(!1),Ne=m.useRef(!0),_e=m.useRef([]),Z=m.useRef(null),de=m.useRef(null),ae=m.useRef(null),V=Je.useIsMobile(),A=Se.useMemo(()=>t.flatMap(o=>o.data),[t]),Ge=Se.useMemo(()=>{if(t.length>0){const o=t[t.length-1];if(o.data.length>0)return o.data[o.data.length-1]}},[t]),[Ve,pe]=m.useState(()=>{if(!Ge)return;const o=new Map;for(const a of t)a.data.length>0&&o.set(a.label,a.data[a.data.length-1]);return o}),[Pe,O]=m.useState(null),[Le,Me]=m.useState([]);m.useEffect(()=>{const o=()=>{try{if(I.current&&Z.current){const n=Z.current.clientWidth,s=Z.current.clientHeight;I.current.resize(n,s)}}catch{}},a=Z.current,l=a?new ResizeObserver(o):null;return ae.current=l,a&&l?.observe(a),()=>{a&&l?.unobserve(a),l?.disconnect(),ae.current=null}},[]),m.useEffect(()=>{if(!de.current||he.current)return;const o=ie.getDefaultOptions(),a=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{},n=U.createChart(de.current,{...o,leftPriceScale:{...o.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...o.rightPriceScale||{},visible:!V,textColor:a},...V&&{crosshair:{...o.crosshair,mode:U.CrosshairMode.Magnet}},...l,...H});return I.current=n,he.current=!0,()=>{ae.current?.disconnect(),ae.current=null,n.remove(),I.current=null,he.current=!1,S.current.clear()}},[V,H,le]),m.useEffect(()=>{const o=I.current;o&&o.applyOptions(le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[le]),m.useEffect(()=>{const o=I.current;if(!o||t.length===0)return;const l=t.filter(r=>r.data.length>0).length<=1?Re:Te,n=p==="time"?ee.getXFormatters(p,A):ee.getXFormatters(p),s=new Map;{let r=0;for(const e of t)e.data.length!==0&&(s.set(e.label,e.priceScaleId??(r===0?"left":"right")),r++)}const g=(r,e,u)=>{const{formatter:k,tickmarksFormatter:_,updateVisibleRange:z,updateLastValues:Fe}=ee.createAdaptiveYAxisFormatter(r,e,{yScaleMin:l}),me=t.filter(K=>K.data.length>0&&u.has(K.label)).map(K=>K.data[K.data.length-1].value);return Fe(me),{formatter:k,tickmarksFormatter:_,updateVisibleRange:z,labels:u}},f=[];if(j)for(const r of["left","right"]){const e=new Set,u=[];let k=R;for(const _ of t)if(_.data.length!==0&&s.get(_.label)===r){e.size===0&&_.yMeasureUnit&&(k=_.yMeasureUnit),e.add(_.label);for(const z of _.data)u.push(z.value)}e.size>0&&f.push(g(u,k,e))}else{const r=A.map(u=>u.value),e=new Set(t.filter(u=>u.data.length>0).map(u=>u.label));f.push(g(r,R,e))}_e.current=f;const C=new Map;for(const r of f)for(const e of r.labels)C.set(e,r);const x=ie.getDefaultOptions();o.applyOptions({localization:{...x.localization||{},timeFormatter:r=>n.timeFormatter(parseFloat(r),void 0)},timeScale:{...x.timeScale||{},tickMarkFormatter:n.tickMarkFormatter,minBarSpacing:0}});const F=(A.length>0?Math.min(...A.map(r=>r.value)):0)<0,T=A.some(r=>r.value===0),b=!F&&T,y=!j&&t.length>1&&!q,P=j?V:t.length>1&&!q||V,L=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({...j&&{defaultVisiblePriceScaleId:ye},leftPriceScale:{...x.leftPriceScale||{},visible:j&&!V,textColor:L,...j&&we&&{}},rightPriceScale:{...x.rightPriceScale||{},visible:j?!V:!P,textColor:L,...b&&!j&&{scaleMargins:{top:.3,bottom:0}}}});const N=new Set(S.current.keys()),Q=new Set(t.map(r=>r.label));for(const r of N)if(!Q.has(r)){const e=S.current.get(r);e&&(o.removeSeries(e),S.current.delete(r))}const J=ie.getDefaultSeries(),te=[];let oe=0;const je=t.find(r=>r.data.length>0),re=new Map;if(M&&M.length>0)for(const r of M){if(!Number.isFinite(r.price))continue;const e=r.seriesLabel??je?.label;if(!e)continue;const u=re.get(e)??[];u.push(r.price),re.set(e,u)}if($&&$.length>0)for(const r of $){const e=r.seriesLabel??je?.label;if(!e)continue;const u=re.get(e)??[];Number.isFinite(r.priceTop)&&u.push(r.priceTop),Number.isFinite(r.priceBottom)&&u.push(r.priceBottom),re.set(e,u)}for(let r=0;r<t.length;r++){const e=t[r],u=xe(r),k=e.lineColor??e.color??u.line;let _,z;if(e.lineColor??e.color)if(e.topColor&&e.bottomColor)_=e.topColor,z=e.bottomColor;else if(e.topColor){const d=E.generateColorsFromBase(k);_=e.topColor,z=d.bottomColor}else if(e.bottomColor)_=E.generateColorsFromBase(k).topColor,z=e.bottomColor;else{const d=E.generateColorsFromBase(k);_=d.topColor,z=d.bottomColor}else _=e.topColor||u.top,z=e.bottomColor||u.bottom;if(e.data.length===0){const d=S.current.get(e.label);d&&(o.removeSeries(d),S.current.delete(e.label));continue}const me=(e.data.length>0?Math.min(...e.data.map(d=>d.value)):0)<0,K=e.data.some(d=>d.value===0),He=!me&&K,Be=j?e.priceScaleId??(oe===0?"left":"right"):q||!y||oe===0?"right":`scale-${oe}`;y&&te.push({priceScaleId:Be||"right",shouldPreventNegativeAxis:He,seriesIndex:oe});const De=(q||!y)&&l!==void 0&&typeof l=="number",Xe=re.get(e.label)??[],Ze=d=>{const D=d();if(D?.priceRange){De&&(D.priceRange.minValue=l);for(const W of Xe)W<D.priceRange.minValue&&(D.priceRange.minValue=W),W>D.priceRange.maxValue&&(D.priceRange.maxValue=W)}return D},Ee=C.get(e.label)??f[0],Ie=Ee.formatter,Ke=Ee.tickmarksFormatter,ve={lineColor:k,topColor:_,bottomColor:z,priceScaleId:Be,...e.seriesType==="line"&&{lineStyle:e.lineStyle??U.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:De&&typeof l=="number"?d=>Ie(d<l?l:d):Ie,tickmarksFormatter:Ke},autoscaleInfoProvider:Ze},ze=e.seriesType==="line";let B=S.current.get(e.label);const Y=e.data.map(d=>({...d,time:d.time}));if(X!==void 0&&Y.length>0&&Number(Y[0].time)>X){const d=Number(Y[0].time),D=d-X,W=86400,Qe=D>180*W?7*W:D>30*W?W:6*3600,qe=[];for(let Ce=X;Ce<d;Ce+=Qe)qe.push({time:Ce});Y.unshift(...qe)}B&&B.seriesType()!==(ze?"Line":"Area")&&(o.removeSeries(B),S.current.delete(e.label),B=void 0),B?(B.applyOptions(ve),B.setData(Y)):(ze?B=o.addSeries(U.LineSeries,{...J,...ve}):B=o.addSeries(U.AreaSeries,{...J,...ve}),B.setData(Y),S.current.set(e.label,B)),oe++}if(j)try{const r=o.priceScale("left"),e=o.priceScale("right"),u={visible:!V,autoScale:!0,scaleMargins:{top:.1,bottom:.1},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L};r?.applyOptions(u),e?.applyOptions(u)}catch{}else if(y&&te.length>0)for(const r of te)try{const e=o.priceScale(r.priceScaleId);e&&e.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...r.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch(e){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,e)}else if(!y)try{const r=o.priceScale("right");r&&r.applyOptions({visible:!V,autoScale:!0,scaleMargins:{top:.1,bottom:l!==void 0||b?0:.1,...b&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch{}if(l!==void 0&&!V&&(q||!y)&&o.applyOptions({handleScroll:{vertTouchDrag:!1}}),A.length>0){const r=A.map(e=>Number(e.time)).filter(e=>Number.isFinite(e));if(r.length>0){const e=Math.min(...r),u=X!==void 0?Math.min(X,e):e,k=Math.max(...r);if(Number(u)<=Number(k))try{o.timeScale().setVisibleRange({from:u,to:k})}catch{try{o.timeScale().fitContent()}catch{}}}}Ne.current&&(Ne.current=!1);const be=new Map;for(const r of t)r.data.length>0&&be.set(r.label,r.data[r.data.length-1]);pe(be.size>0?be:void 0)},[t,A,p,R,V,q,j,ye,we,Re,Te,X,M,$]),m.useEffect(()=>{const o=I.current;if(!o||t.length===0)return;const a=t.length===1;let l;for(const s of t)if(s.data.length>0){l=s.data[s.data.length-1].time;break}if(!l)return;const n=s=>{const{time:g=l,seriesData:f,point:C}=s||{},x=Array.from(S.current.values());if(!C||!g){const T=new Map;for(const b of t)b.data.length>0&&T.set(b.label,b.data[b.data.length-1]);if(pe(T.size>0?T:void 0),a||q||ge)O(null);else if(x[0]&&l){const y=o.timeScale().timeToCoordinate(l),P=t[0];if(P.data.length>0){const L=P.data[P.data.length-1].value,N=x[0].priceToCoordinate(L);y!==null&&N!==null&&O({x:y,y:N})}}return}const G=new Map;let F;for(let T=0;T<t.length;T++){const b=t[T],y=S.current.get(b.label);if(!y)continue;const P=f?.get(y),L=P&&"value"in P?P.value:void 0;let N;if(L!==void 0)N=L;else if(a){const Q=Number(g),J=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;Q<J?N=Number.NaN:N=b.data[b.data.length-1]?.value??0}else N=$e(b.data,Number(g));Number.isNaN(N)||(F===void 0&&(F=N),G.set(b.label,{value:N,time:g}))}if(pe(G),F!==void 0&&x[0]){const b=o.timeScale().timeToCoordinate(g),y=x[0].priceToCoordinate(F);if(b!==null&&y!==null){const P=Z.current;if(P){const L=P.querySelector(".LightweightChart");if(L){const N=L.getBoundingClientRect(),Q=P.getBoundingClientRect(),J=b+(N.left-Q.left),te=y+(N.top-Q.top);O({x:J,y:te})}else O({x:b,y})}else O({x:b,y})}else O(null)}else O(null)};return o.subscribeCrosshairMove(n),V&&o.subscribeClick(n),!a&&!q&&!ge&&requestAnimationFrame(()=>{const s=Array.from(S.current.values());if(s[0]&&l&&t[0]?.data.length>0){const f=o.timeScale().timeToCoordinate(l),C=t[0].data[t[0].data.length-1].value,x=s[0].priceToCoordinate(C);f!==null&&x!==null&&O({x:f,y:x})}}),()=>{o.unsubscribeCrosshairMove(n),V&&o.unsubscribeClick(n)}},[t,q,V,ge]),m.useEffect(()=>{const o=I.current;if(!o||t.length===0)return;const a=o.timeScale(),l=()=>{const n=_e.current;if(n.length===0)return;const s=a.getVisibleRange();if(!s)return;const g=Number(s.from),f=Number(s.to);for(const C of n){const x=[];for(const G of t)if(C.labels.has(G.label))for(const F of G.data){const T=Number(F.time);T>=g&&T<=f&&x.push(F.value)}x.length>0&&C.updateVisibleRange(x)}};return a.subscribeVisibleLogicalRangeChange(l),()=>{a.unsubscribeVisibleLogicalRangeChange(l)}},[t]),m.useEffect(()=>{const o=I.current,a=Array.from(S.current.values()),l=[];if(o&&a.length>0&&w){const n=ie.getDefaultVerticalLine(),s=a[0];for(const g of w){const f={...n,...g.options||{}};f.color&&(f.color=E.resolveCSSColor(f.color,f.color));const C=new et.VertLine(o,s,g.xCoordinate,f);s.attachPrimitive(C),l.push(C)}}return()=>{if(a.length>0){const n=a[0];for(const s of l)n.detachPrimitive(s)}}},[w,t]),m.useEffect(()=>{const o=[];if(M&&M.length>0){const a=Array.from(S.current.values())[0],l=E.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const n of M){if(!Number.isFinite(n.price))continue;const s=n.seriesLabel?S.current.get(n.seriesLabel):a;if(!s)continue;const g=s.createPriceLine({price:n.price,color:n.color?E.resolveCSSColor(n.color,n.color):l,lineWidth:n.lineWidth??1,lineStyle:n.lineStyle??U.LineStyle.Dashed,axisLabelVisible:n.axisLabelVisible??!0,title:n.title??""});o.push({series:s,line:g})}}return()=>{for(const{series:a,line:l}of o)try{a.removePriceLine(l)}catch{}}},[M,t]),m.useEffect(()=>{const o=[];if($&&$.length>0){const a=Array.from(S.current.values())[0],l="rgba(239, 68, 68, 0.12)";for(const n of $){const s=n.seriesLabel?S.current.get(n.seriesLabel):a;if(!s)continue;const g=n.color?E.resolveCSSColor(n.color,l):l,f=new nt(s,n.priceTop,n.priceBottom,g);s.attachPrimitive(f),o.push({series:s,zone:f})}}return()=>{for(const{series:a,zone:l}of o)try{a.detachPrimitive(l)}catch{}}},[$,t]),m.useEffect(()=>{const o=I.current;if(!o||!w?.length){Me([]);return}const a=()=>{const s=o.timeScale(),g=w.map(f=>s.timeToCoordinate(f.xCoordinate)??null);Me(g)};a();const l=o.timeScale(),n=()=>{a()};return l.subscribeVisibleLogicalRangeChange(n),()=>{l.unsubscribeVisibleLogicalRangeChange(n)}},[w,t]);const se=t.length===1,ke=Se.useMemo(()=>{if(se&&t.length>0){const o=t[0];if(o.data.length>0)return o.data[o.data.length-1]}},[se,t]);return v.jsxs("div",{ref:Z,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",i),children:[fe!=null&&fe!==!1&&se?v.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:v.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:fe})}):Oe&&se&&ke&&v.jsx(Ye.GraphCurrentValue,{point:ke,xMeasureUnit:p,yMeasureUnit:R,decimals:ue}),Ve&&Pe&&v.jsx(Ue.GraphTooltip,{points:Ve,xMeasureUnit:p,yMeasureUnit:R,series:t,position:Pe,containerRef:Z,decimals:ue}),c&&v.jsx(Ae,{series:t,onUnselect:h}),w&&w.length>0&&Le.length===w.length&&v.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:w.map((o,a)=>{const l=Le[a],n=o.options??{},s=n.showLabel!==!1;if(l===null||!s)return null;const{labelText:g,valueStr:f}=We(n,R,ue),C=n.tooltipText??"";if(!(g||f||C))return null;const G=n.labelBackgroundColor??n.color??"hsl(var(--background))",F=n.labelTextColor??"hsl(var(--foreground))",T=`${String(o.xCoordinate)}-${g}-${C}`;return v.jsxs("div",{className:ne.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",C&&"pointer-events-auto cursor-default"),style:{left:l,transform:"translateX(-50%)",backgroundColor:G,color:F},children:[g&&v.jsx("span",{className:"block",children:g}),f&&v.jsx("span",{className:ne.cn("block",g&&"mt-0.5"),children:f}),C&&v.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:C})]},T)})}),v.jsx("div",{ref:de,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ae({series:t,onUnselect:i,inline:c=!1}){return v.jsx("div",{className:ne.cn("flex flex-wrap gap-2",c?"items-center":"absolute top-0 left-2 z-[10]"),children:t.map((h,p)=>{const R=xe(p),H=(h.lineColor??h.color)||R.line,w=h.data.length===0;return v.jsxs("div",{className:ne.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",w&&"opacity-50"),children:[v.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:H}}),v.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[h.label,w&&" (no data)"]}),i&&v.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),i(h.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${h.label}`,children:v.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[v.jsx("title",{children:"Close"}),v.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),v.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},h.label)})})}exports.DEFAULT_SERIES_COLORS=ce;exports.Graph=at;exports.GraphLegend=Ae;exports.getSeriesColorPalette=xe;exports.getStepForwardValue=$e;exports.getVerticalLineTooltipContent=We;
@@ -1,4 +1,4 @@
1
- import { jsxs as re, jsx as T } from "react/jsx-runtime";
1
+ import { jsxs as re, jsx as y } from "react/jsx-runtime";
2
2
  import { createChart as Ue, CrosshairMode as et, LineStyle as Ge, LineSeries as tt, AreaSeries as ot } from "lightweight-charts";
3
3
  import * as Ce from "react";
4
4
  import { useRef as X, useState as Se, useEffect as W } from "react";
@@ -14,13 +14,13 @@ class ft {
14
14
  _yTop;
15
15
  _yBottom;
16
16
  _color;
17
- constructor(s, g, m) {
18
- this._yTop = s, this._yBottom = g, this._color = m;
17
+ constructor(c, g, b) {
18
+ this._yTop = c, this._yBottom = g, this._color = b;
19
19
  }
20
- draw(s) {
21
- s.useBitmapCoordinateSpace((g) => {
22
- const m = g.context, d = g.verticalPixelRatio, N = this._yTop === null ? 0 : this._yTop * d, q = this._yBottom === null ? g.bitmapSize.height : this._yBottom * d, x = Math.min(N, q), k = Math.max(N, q);
23
- m.fillStyle = this._color, m.fillRect(0, x, g.bitmapSize.width, k - x);
20
+ draw(c) {
21
+ c.useBitmapCoordinateSpace((g) => {
22
+ const b = g.context, d = g.verticalPixelRatio, w = this._yTop === null ? 0 : this._yTop * d, q = this._yBottom === null ? g.bitmapSize.height : this._yBottom * d, x = Math.min(w, q), k = Math.max(w, q);
23
+ b.fillStyle = this._color, b.fillRect(0, x, g.bitmapSize.width, k - x);
24
24
  });
25
25
  }
26
26
  }
@@ -28,12 +28,12 @@ class ht {
28
28
  _source;
29
29
  _yTop = null;
30
30
  _yBottom = null;
31
- constructor(s) {
32
- this._source = s;
31
+ constructor(c) {
32
+ this._source = c;
33
33
  }
34
34
  update() {
35
- const s = this._source.series;
36
- this._yTop = this._source.priceTop === void 0 ? null : s.priceToCoordinate(this._source.priceTop), this._yBottom = this._source.priceBottom === void 0 ? null : s.priceToCoordinate(this._source.priceBottom);
35
+ const c = this._source.series;
36
+ this._yTop = this._source.priceTop === void 0 ? null : c.priceToCoordinate(this._source.priceTop), this._yBottom = this._source.priceBottom === void 0 ? null : c.priceToCoordinate(this._source.priceBottom);
37
37
  }
38
38
  /** Draw beneath the series line/area so the data stays readable. */
39
39
  zOrder() {
@@ -49,27 +49,27 @@ class gt {
49
49
  priceBottom;
50
50
  color;
51
51
  _paneViews;
52
- constructor(s, g, m, d) {
53
- this.series = s, this.priceTop = g, this.priceBottom = m, this.color = d, this._paneViews = [new ht(this)];
52
+ constructor(c, g, b, d) {
53
+ this.series = c, this.priceTop = g, this.priceBottom = b, this.color = d, this._paneViews = [new ht(this)];
54
54
  }
55
55
  updateAllViews() {
56
- for (const s of this._paneViews) s.update();
56
+ for (const c of this._paneViews) c.update();
57
57
  }
58
58
  paneViews() {
59
59
  return this._paneViews;
60
60
  }
61
61
  }
62
- function dt(o, s, g) {
63
- const m = o.labelText ?? "", d = o.value, N = d === void 0 ? "" : typeof d == "number" ? s === "$" ? `$${xe(d, void 0, g)}` : s === "%" ? `${xe(d, void 0, g)}%` : xe(
62
+ function dt(o, c, g) {
63
+ const b = o.labelText ?? "", d = o.value, w = d === void 0 ? "" : typeof d == "number" ? c === "$" ? `$${xe(d, void 0, g)}` : c === "%" ? `${xe(d, void 0, g)}%` : xe(
64
64
  d,
65
- s !== "none" && s !== "%" && s !== "$" ? s : void 0,
65
+ c !== "none" && c !== "%" && c !== "$" ? c : void 0,
66
66
  g
67
67
  ) : String(d);
68
- return { labelText: m, valueStr: N };
68
+ return { labelText: b, valueStr: w };
69
69
  }
70
- function mt(o, s) {
70
+ function mt(o, c) {
71
71
  for (let g = o.length - 1; g >= 0; g--)
72
- if (Number(o[g].time) <= s)
72
+ if (Number(o[g].time) <= c)
73
73
  return o[g].value;
74
74
  return 0;
75
75
  }
@@ -188,39 +188,39 @@ const ye = [
188
188
  top: "rgba(71, 85, 105, 0.56)",
189
189
  bottom: "rgba(71, 85, 105, 0.04)"
190
190
  }
191
- ], pt = 137.5;
191
+ ], bt = 137.5;
192
192
  function Xe(o) {
193
193
  if (o < ye.length)
194
194
  return ye[o];
195
- const g = (o - ye.length) * pt % 360, m = nt(g, 70, 50), { topColor: d, bottomColor: N } = se(m);
196
- return { line: m, top: d, bottom: N };
195
+ const g = (o - ye.length) * bt % 360, b = nt(g, 70, 50), { topColor: d, bottomColor: w } = se(b);
196
+ return { line: b, top: d, bottom: w };
197
197
  }
198
198
  function Lt({
199
199
  series: o,
200
- className: s,
200
+ className: c,
201
201
  showLegend: g = !1,
202
- onUnselectSeries: m,
202
+ onUnselectSeries: b,
203
203
  xMeasureUnit: d = "time",
204
- yMeasureUnit: N = "token",
204
+ yMeasureUnit: w = "token",
205
205
  optionsOverrides: q,
206
206
  verticalLineOptions: x,
207
207
  priceLineOptions: k,
208
208
  zoneOptions: A,
209
209
  currentValueDecimals: ce,
210
210
  useSharedPriceScale: $ = !1,
211
- dualYAxis: L = !1,
211
+ dualYAxis: _ = !1,
212
212
  defaultVisiblePriceScaleId: we = "right",
213
- leftPriceScaleTitle: Te,
213
+ leftPriceScaleTitle: Ne,
214
214
  rightPriceScaleTitle: vt,
215
215
  showCurrentValue: qe = !0,
216
216
  graphTitle: ue,
217
- yScaleMin: Ne,
217
+ yScaleMin: Te,
218
218
  yScaleMinMultiple: Ve,
219
219
  visibleTimeFrom: Z,
220
220
  disableZoom: le = !1,
221
221
  hideDefaultTooltip: fe = !1
222
222
  }) {
223
- const I = X(null), y = X(/* @__PURE__ */ new Map()), he = X(!1), Re = X(!0), Pe = X([]), K = X(null), ge = X(null), ae = X(null), R = rt(), G = Ce.useMemo(() => o.flatMap((t) => t.data), [o]), Ze = Ce.useMemo(() => {
223
+ const I = X(null), v = X(/* @__PURE__ */ new Map()), he = X(!1), Re = X(!0), Pe = X([]), K = X(null), ge = X(null), ae = X(null), R = rt(), G = Ce.useMemo(() => o.flatMap((t) => t.data), [o]), Ze = Ce.useMemo(() => {
224
224
  if (o.length > 0) {
225
225
  const t = o[o.length - 1];
226
226
  if (t.data.length > 0)
@@ -286,7 +286,7 @@ function Lt({
286
286
  ...q
287
287
  });
288
288
  return I.current = n, he.current = !0, () => {
289
- ae.current?.disconnect(), ae.current = null, n.remove(), I.current = null, he.current = !1, y.current.clear();
289
+ ae.current?.disconnect(), ae.current = null, n.remove(), I.current = null, he.current = !1, v.current.clear();
290
290
  };
291
291
  }, [R, q, le]), W(() => {
292
292
  const t = I.current;
@@ -322,7 +322,7 @@ function Lt({
322
322
  }, [le]), W(() => {
323
323
  const t = I.current;
324
324
  if (!t || o.length === 0) return;
325
- const l = o.filter((r) => r.data.length > 0).length <= 1 ? Ne : Ve, n = d === "time" ? He(d, G) : He(d), i = /* @__PURE__ */ new Map();
325
+ const l = o.filter((r) => r.data.length > 0).length <= 1 ? Te : Ve, n = d === "time" ? He(d, G) : He(d), i = /* @__PURE__ */ new Map();
326
326
  {
327
327
  let r = 0;
328
328
  for (const e of o)
@@ -331,43 +331,43 @@ function Lt({
331
331
  e.priceScaleId ?? (r === 0 ? "left" : "right")
332
332
  ), r++);
333
333
  }
334
- const f = (r, e, u) => {
334
+ const f = (r, e, s) => {
335
335
  const {
336
- formatter: B,
337
- tickmarksFormatter: S,
336
+ formatter: L,
337
+ tickmarksFormatter: V,
338
338
  updateVisibleRange: z,
339
- updateLastValues: Fe
339
+ updateLastValues: De
340
340
  } = it(r, e, {
341
341
  yScaleMin: l
342
- }), pe = o.filter((O) => O.data.length > 0 && u.has(O.label)).map((O) => O.data[O.data.length - 1].value);
343
- return Fe(pe), { formatter: B, tickmarksFormatter: S, updateVisibleRange: z, labels: u };
344
- }, c = [];
345
- if (L)
342
+ }), be = o.filter((O) => O.data.length > 0 && s.has(O.label)).map((O) => O.data[O.data.length - 1].value);
343
+ return De(be), { formatter: L, tickmarksFormatter: V, updateVisibleRange: z, labels: s };
344
+ }, u = [];
345
+ if (_)
346
346
  for (const r of ["left", "right"]) {
347
- const e = /* @__PURE__ */ new Set(), u = [];
348
- let B = N;
349
- for (const S of o)
350
- if (S.data.length !== 0 && i.get(S.label) === r) {
351
- e.size === 0 && S.yMeasureUnit && (B = S.yMeasureUnit), e.add(S.label);
352
- for (const z of S.data) u.push(z.value);
347
+ const e = /* @__PURE__ */ new Set(), s = [];
348
+ let L = w;
349
+ for (const V of o)
350
+ if (V.data.length !== 0 && i.get(V.label) === r) {
351
+ e.size === 0 && V.yMeasureUnit && (L = V.yMeasureUnit), e.add(V.label);
352
+ for (const z of V.data) s.push(z.value);
353
353
  }
354
- e.size > 0 && c.push(f(u, B, e));
354
+ e.size > 0 && u.push(f(s, L, e));
355
355
  }
356
356
  else {
357
- const r = G.map((u) => u.value), e = new Set(
358
- o.filter((u) => u.data.length > 0).map((u) => u.label)
357
+ const r = G.map((s) => s.value), e = new Set(
358
+ o.filter((s) => s.data.length > 0).map((s) => s.label)
359
359
  );
360
- c.push(f(r, N, e));
360
+ u.push(f(r, w, e));
361
361
  }
362
- Pe.current = c;
363
- const b = /* @__PURE__ */ new Map();
364
- for (const r of c)
362
+ Pe.current = u;
363
+ const p = /* @__PURE__ */ new Map();
364
+ for (const r of u)
365
365
  for (const e of r.labels)
366
- b.set(e, r);
367
- const v = je();
366
+ p.set(e, r);
367
+ const C = je();
368
368
  t.applyOptions({
369
369
  localization: {
370
- ...v.localization || {},
370
+ ...C.localization || {},
371
371
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
372
372
  timeFormatter: (r) => (
373
373
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
@@ -375,33 +375,33 @@ function Lt({
375
375
  )
376
376
  },
377
377
  timeScale: {
378
- ...v.timeScale || {},
378
+ ...C.timeScale || {},
379
379
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
380
380
  tickMarkFormatter: n.tickMarkFormatter,
381
381
  minBarSpacing: 0
382
382
  }
383
383
  });
384
- const _ = (G.length > 0 ? Math.min(...G.map((r) => r.value)) : 0) < 0, w = G.some((r) => r.value === 0), p = !_ && w, C = !L && o.length > 1 && !$, P = L ? R : o.length > 1 && !$ || R, M = U(
384
+ const B = (G.length > 0 ? Math.min(...G.map((r) => r.value)) : 0) < 0, N = G.some((r) => r.value === 0), m = !B && N, S = !_ && o.length > 1 && !$, P = _ ? R : o.length > 1 && !$ || R, M = U(
385
385
  "hsl(var(--foreground))",
386
386
  "rgb(0, 0, 0)"
387
387
  );
388
388
  t.applyOptions({
389
- ...L && {
389
+ ..._ && {
390
390
  defaultVisiblePriceScaleId: we
391
391
  },
392
392
  leftPriceScale: {
393
- ...v.leftPriceScale || {},
394
- visible: L && !R,
393
+ ...C.leftPriceScale || {},
394
+ visible: _ && !R,
395
395
  textColor: M,
396
- ...L && Te && {
396
+ ..._ && Ne && {
397
397
  // lightweight-charts uses scale margins; title shown via localization if needed
398
398
  }
399
399
  },
400
400
  rightPriceScale: {
401
- ...v.rightPriceScale || {},
402
- visible: L ? !R : !P,
401
+ ...C.rightPriceScale || {},
402
+ visible: _ ? !R : !P,
403
403
  textColor: M,
404
- ...p && !L && {
404
+ ...m && !_ && {
405
405
  scaleMargins: {
406
406
  top: 0.3,
407
407
  bottom: 0
@@ -409,69 +409,69 @@ function Lt({
409
409
  }
410
410
  }
411
411
  });
412
- const V = new Set(y.current.keys()), J = new Set(o.map((r) => r.label));
413
- for (const r of V)
412
+ const T = new Set(v.current.keys()), J = new Set(o.map((r) => r.label));
413
+ for (const r of T)
414
414
  if (!J.has(r)) {
415
- const e = y.current.get(r);
416
- e && (t.removeSeries(e), y.current.delete(r));
415
+ const e = v.current.get(r);
416
+ e && (t.removeSeries(e), v.current.delete(r));
417
417
  }
418
418
  const Q = lt(), ee = [];
419
419
  let te = 0;
420
- const De = o.find((r) => r.data.length > 0), oe = /* @__PURE__ */ new Map();
420
+ const Fe = o.find((r) => r.data.length > 0), oe = /* @__PURE__ */ new Map();
421
421
  if (k && k.length > 0)
422
422
  for (const r of k) {
423
423
  if (!Number.isFinite(r.price)) continue;
424
- const e = r.seriesLabel ?? De?.label;
424
+ const e = r.seriesLabel ?? Fe?.label;
425
425
  if (!e) continue;
426
- const u = oe.get(e) ?? [];
427
- u.push(r.price), oe.set(e, u);
426
+ const s = oe.get(e) ?? [];
427
+ s.push(r.price), oe.set(e, s);
428
428
  }
429
429
  if (A && A.length > 0)
430
430
  for (const r of A) {
431
- const e = r.seriesLabel ?? De?.label;
431
+ const e = r.seriesLabel ?? Fe?.label;
432
432
  if (!e) continue;
433
- const u = oe.get(e) ?? [];
434
- Number.isFinite(r.priceTop) && u.push(r.priceTop), Number.isFinite(r.priceBottom) && u.push(r.priceBottom), oe.set(e, u);
433
+ const s = oe.get(e) ?? [];
434
+ Number.isFinite(r.priceTop) && s.push(r.priceTop), Number.isFinite(r.priceBottom) && s.push(r.priceBottom), oe.set(e, s);
435
435
  }
436
436
  for (let r = 0; r < o.length; r++) {
437
- const e = o[r], u = Xe(r), B = e.lineColor ?? e.color ?? u.line;
438
- let S, z;
437
+ const e = o[r], s = Xe(r), L = e.lineColor ?? e.color ?? s.line;
438
+ let V, z;
439
439
  if (e.lineColor ?? e.color)
440
440
  if (e.topColor && e.bottomColor)
441
- S = e.topColor, z = e.bottomColor;
441
+ V = e.topColor, z = e.bottomColor;
442
442
  else if (e.topColor) {
443
- const h = se(B);
444
- S = e.topColor, z = h.bottomColor;
443
+ const h = se(L);
444
+ V = e.topColor, z = h.bottomColor;
445
445
  } else if (e.bottomColor)
446
- S = se(B).topColor, z = e.bottomColor;
446
+ V = se(L).topColor, z = e.bottomColor;
447
447
  else {
448
- const h = se(B);
449
- S = h.topColor, z = h.bottomColor;
448
+ const h = se(L);
449
+ V = h.topColor, z = h.bottomColor;
450
450
  }
451
451
  else
452
- S = e.topColor || u.top, z = e.bottomColor || u.bottom;
452
+ V = e.topColor || s.top, z = e.bottomColor || s.bottom;
453
453
  if (e.data.length === 0) {
454
- const h = y.current.get(e.label);
455
- h && (t.removeSeries(h), y.current.delete(e.label));
454
+ const h = v.current.get(e.label);
455
+ h && (t.removeSeries(h), v.current.delete(e.label));
456
456
  continue;
457
457
  }
458
- const pe = (e.data.length > 0 ? Math.min(...e.data.map((h) => h.value)) : 0) < 0, O = e.data.some((h) => h.value === 0), Ke = !pe && O, Ie = L ? e.priceScaleId ?? (te === 0 ? "left" : "right") : $ || !C || te === 0 ? "right" : `scale-${te}`;
459
- C && ee.push({
458
+ const be = (e.data.length > 0 ? Math.min(...e.data.map((h) => h.value)) : 0) < 0, O = e.data.some((h) => h.value === 0), Ke = !be && O, Ie = _ ? e.priceScaleId ?? (te === 0 ? "left" : "right") : $ || !S || te === 0 ? "right" : `scale-${te}`;
459
+ S && ee.push({
460
460
  priceScaleId: Ie || "right",
461
461
  shouldPreventNegativeAxis: Ke,
462
462
  seriesIndex: te
463
463
  });
464
- const ze = ($ || !C) && l !== void 0 && typeof l == "number", Oe = oe.get(e.label) ?? [], Je = (h) => {
465
- const F = h();
466
- if (F?.priceRange) {
467
- ze && (F.priceRange.minValue = l);
464
+ const ze = ($ || !S) && l !== void 0 && typeof l == "number", Oe = oe.get(e.label) ?? [], Je = (h) => {
465
+ const D = h();
466
+ if (D?.priceRange) {
467
+ ze && (D.priceRange.minValue = l);
468
468
  for (const E of Oe)
469
- E < F.priceRange.minValue && (F.priceRange.minValue = E), E > F.priceRange.maxValue && (F.priceRange.maxValue = E);
469
+ E < D.priceRange.minValue && (D.priceRange.minValue = E), E > D.priceRange.maxValue && (D.priceRange.maxValue = E);
470
470
  }
471
- return F;
472
- }, We = b.get(e.label) ?? c[0], $e = We.formatter, Qe = We.tickmarksFormatter, be = {
473
- lineColor: B,
474
- topColor: S,
471
+ return D;
472
+ }, We = p.get(e.label) ?? u[0], $e = We.formatter, Qe = We.tickmarksFormatter, pe = {
473
+ lineColor: L,
474
+ topColor: V,
475
475
  bottomColor: z,
476
476
  priceScaleId: Ie,
477
477
  ...e.seriesType === "line" && {
@@ -487,28 +487,28 @@ function Lt({
487
487
  },
488
488
  autoscaleInfoProvider: Je
489
489
  }, Ee = e.seriesType === "line";
490
- let D = y.current.get(e.label);
490
+ let F = v.current.get(e.label);
491
491
  const Y = e.data.map((h) => ({
492
492
  ...h,
493
493
  time: h.time
494
494
  }));
495
495
  if (Z !== void 0 && Y.length > 0 && Number(Y[0].time) > Z) {
496
- const h = Number(Y[0].time), F = h - Z, E = 86400, Ye = F > 180 * E ? 7 * E : F > 30 * E ? E : 6 * 3600, Ae = [];
496
+ const h = Number(Y[0].time), D = h - Z, E = 86400, Ye = D > 180 * E ? 7 * E : D > 30 * E ? E : 6 * 3600, Ae = [];
497
497
  for (let ve = Z; ve < h; ve += Ye)
498
498
  Ae.push({ time: ve });
499
499
  Y.unshift(...Ae);
500
500
  }
501
- D && D.seriesType() !== (Ee ? "Line" : "Area") && (t.removeSeries(D), y.current.delete(e.label), D = void 0), D ? (D.applyOptions(be), D.setData(Y)) : (Ee ? D = t.addSeries(tt, {
501
+ F && F.seriesType() !== (Ee ? "Line" : "Area") && (t.removeSeries(F), v.current.delete(e.label), F = void 0), F ? (F.applyOptions(pe), F.setData(Y)) : (Ee ? F = t.addSeries(tt, {
502
502
  ...Q,
503
- ...be
504
- }) : D = t.addSeries(ot, {
503
+ ...pe
504
+ }) : F = t.addSeries(ot, {
505
505
  ...Q,
506
- ...be
507
- }), D.setData(Y), y.current.set(e.label, D)), te++;
506
+ ...pe
507
+ }), F.setData(Y), v.current.set(e.label, F)), te++;
508
508
  }
509
- if (L)
509
+ if (_)
510
510
  try {
511
- const r = t.priceScale("left"), e = t.priceScale("right"), u = {
511
+ const r = t.priceScale("left"), e = t.priceScale("right"), s = {
512
512
  visible: !R,
513
513
  autoScale: !0,
514
514
  scaleMargins: { top: 0.1, bottom: 0.1 },
@@ -518,10 +518,10 @@ function Lt({
518
518
  entireTextOnly: !1,
519
519
  textColor: M
520
520
  };
521
- r?.applyOptions(u), e?.applyOptions(u);
521
+ r?.applyOptions(s), e?.applyOptions(s);
522
522
  } catch {
523
523
  }
524
- else if (C && ee.length > 0)
524
+ else if (S && ee.length > 0)
525
525
  for (const r of ee)
526
526
  try {
527
527
  const e = t.priceScale(r.priceScaleId);
@@ -548,7 +548,7 @@ function Lt({
548
548
  e
549
549
  );
550
550
  }
551
- else if (!C)
551
+ else if (!S)
552
552
  try {
553
553
  const r = t.priceScale("right");
554
554
  r && r.applyOptions({
@@ -557,8 +557,8 @@ function Lt({
557
557
  scaleMargins: {
558
558
  top: 0.1,
559
559
  // No bottom margin when yScaleMin is set so the scale doesn't extend below the minimum (avoids negative labels like -10M)
560
- bottom: l !== void 0 || p ? 0 : 0.1,
561
- ...p && {
560
+ bottom: l !== void 0 || m ? 0 : 0.1,
561
+ ...m && {
562
562
  top: 0.3
563
563
  }
564
564
  },
@@ -570,13 +570,24 @@ function Lt({
570
570
  });
571
571
  } catch {
572
572
  }
573
- if (l !== void 0 && !R && ($ || !C) && t.applyOptions({
573
+ if (l !== void 0 && !R && ($ || !S) && t.applyOptions({
574
574
  handleScroll: {
575
575
  vertTouchDrag: !1
576
576
  }
577
577
  }), G.length > 0) {
578
- const r = G.map((S) => Number(S.time)), e = Math.min(...r), u = Z !== void 0 ? Math.min(Z, e) : e, B = Math.max(...r);
579
- t.timeScale().setVisibleRange({ from: u, to: B });
578
+ const r = G.map((e) => Number(e.time)).filter((e) => Number.isFinite(e));
579
+ if (r.length > 0) {
580
+ const e = Math.min(...r), s = Z !== void 0 ? Math.min(Z, e) : e, L = Math.max(...r);
581
+ if (Number(s) <= Number(L))
582
+ try {
583
+ t.timeScale().setVisibleRange({ from: s, to: L });
584
+ } catch {
585
+ try {
586
+ t.timeScale().fitContent();
587
+ } catch {
588
+ }
589
+ }
590
+ }
580
591
  }
581
592
  Re.current && (Re.current = !1);
582
593
  const me = /* @__PURE__ */ new Map();
@@ -587,13 +598,13 @@ function Lt({
587
598
  o,
588
599
  G,
589
600
  d,
590
- N,
601
+ w,
591
602
  R,
592
603
  $,
593
- L,
604
+ _,
594
605
  we,
595
- Te,
596
606
  Ne,
607
+ Te,
597
608
  Ve,
598
609
  Z,
599
610
  k,
@@ -610,63 +621,63 @@ function Lt({
610
621
  }
611
622
  if (!l) return;
612
623
  const n = (i) => {
613
- const { time: f = l, seriesData: c, point: b } = i || {}, v = Array.from(y.current.values());
614
- if (!b || !f) {
615
- const w = /* @__PURE__ */ new Map();
616
- for (const p of o)
617
- p.data.length > 0 && w.set(p.label, p.data[p.data.length - 1]);
618
- if (de(w.size > 0 ? w : void 0), a || $ || fe)
624
+ const { time: f = l, seriesData: u, point: p } = i || {}, C = Array.from(v.current.values());
625
+ if (!p || !f) {
626
+ const N = /* @__PURE__ */ new Map();
627
+ for (const m of o)
628
+ m.data.length > 0 && N.set(m.label, m.data[m.data.length - 1]);
629
+ if (de(N.size > 0 ? N : void 0), a || $ || fe)
619
630
  j(null);
620
- else if (v[0] && l) {
621
- const C = t.timeScale().timeToCoordinate(l), P = o[0];
631
+ else if (C[0] && l) {
632
+ const S = t.timeScale().timeToCoordinate(l), P = o[0];
622
633
  if (P.data.length > 0) {
623
- const M = P.data[P.data.length - 1].value, V = v[0].priceToCoordinate(M);
624
- C !== null && V !== null && j({ x: C, y: V });
634
+ const M = P.data[P.data.length - 1].value, T = C[0].priceToCoordinate(M);
635
+ S !== null && T !== null && j({ x: S, y: T });
625
636
  }
626
637
  }
627
638
  return;
628
639
  }
629
640
  const H = /* @__PURE__ */ new Map();
630
- let _;
631
- for (let w = 0; w < o.length; w++) {
632
- const p = o[w], C = v[w];
633
- if (!C) continue;
634
- const P = c?.get(C), M = P && "value" in P ? P.value : void 0;
635
- let V;
641
+ let B;
642
+ for (let N = 0; N < o.length; N++) {
643
+ const m = o[N], S = v.current.get(m.label);
644
+ if (!S) continue;
645
+ const P = u?.get(S), M = P && "value" in P ? P.value : void 0;
646
+ let T;
636
647
  if (M !== void 0)
637
- V = M;
648
+ T = M;
638
649
  else if (a) {
639
- const J = Number(f), Q = p.data.length > 0 ? Number(p.data[0].time) : Number.POSITIVE_INFINITY;
640
- J < Q ? V = Number.NaN : V = p.data[p.data.length - 1]?.value ?? 0;
650
+ const J = Number(f), Q = m.data.length > 0 ? Number(m.data[0].time) : Number.POSITIVE_INFINITY;
651
+ J < Q ? T = Number.NaN : T = m.data[m.data.length - 1]?.value ?? 0;
641
652
  } else
642
- V = mt(p.data, Number(f));
643
- Number.isNaN(V) || (_ === void 0 && (_ = V), H.set(p.label, { value: V, time: f }));
653
+ T = mt(m.data, Number(f));
654
+ Number.isNaN(T) || (B === void 0 && (B = T), H.set(m.label, { value: T, time: f }));
644
655
  }
645
- if (de(H), _ !== void 0 && v[0]) {
646
- const p = t.timeScale().timeToCoordinate(f), C = v[0].priceToCoordinate(_);
647
- if (p !== null && C !== null) {
656
+ if (de(H), B !== void 0 && C[0]) {
657
+ const m = t.timeScale().timeToCoordinate(f), S = C[0].priceToCoordinate(B);
658
+ if (m !== null && S !== null) {
648
659
  const P = K.current;
649
660
  if (P) {
650
661
  const M = P.querySelector(
651
662
  ".LightweightChart"
652
663
  );
653
664
  if (M) {
654
- const V = M.getBoundingClientRect(), J = P.getBoundingClientRect(), Q = p + (V.left - J.left), ee = C + (V.top - J.top);
665
+ const T = M.getBoundingClientRect(), J = P.getBoundingClientRect(), Q = m + (T.left - J.left), ee = S + (T.top - J.top);
655
666
  j({ x: Q, y: ee });
656
667
  } else
657
- j({ x: p, y: C });
668
+ j({ x: m, y: S });
658
669
  } else
659
- j({ x: p, y: C });
670
+ j({ x: m, y: S });
660
671
  } else
661
672
  j(null);
662
673
  } else
663
674
  j(null);
664
675
  };
665
676
  return t.subscribeCrosshairMove(n), R && t.subscribeClick(n), !a && !$ && !fe && requestAnimationFrame(() => {
666
- const i = Array.from(y.current.values());
677
+ const i = Array.from(v.current.values());
667
678
  if (i[0] && l && o[0]?.data.length > 0) {
668
- const c = t.timeScale().timeToCoordinate(l), b = o[0].data[o[0].data.length - 1].value, v = i[0].priceToCoordinate(b);
669
- c !== null && v !== null && j({ x: c, y: v });
679
+ const u = t.timeScale().timeToCoordinate(l), p = o[0].data[o[0].data.length - 1].value, C = i[0].priceToCoordinate(p);
680
+ u !== null && C !== null && j({ x: u, y: C });
670
681
  }
671
682
  }), () => {
672
683
  t.unsubscribeCrosshairMove(n), R && t.unsubscribeClick(n);
@@ -679,16 +690,16 @@ function Lt({
679
690
  if (n.length === 0) return;
680
691
  const i = a.getVisibleRange();
681
692
  if (!i) return;
682
- const f = Number(i.from), c = Number(i.to);
683
- for (const b of n) {
684
- const v = [];
693
+ const f = Number(i.from), u = Number(i.to);
694
+ for (const p of n) {
695
+ const C = [];
685
696
  for (const H of o)
686
- if (b.labels.has(H.label))
687
- for (const _ of H.data) {
688
- const w = Number(_.time);
689
- w >= f && w <= c && v.push(_.value);
697
+ if (p.labels.has(H.label))
698
+ for (const B of H.data) {
699
+ const N = Number(B.time);
700
+ N >= f && N <= u && C.push(B.value);
690
701
  }
691
- v.length > 0 && b.updateVisibleRange(v);
702
+ C.length > 0 && p.updateVisibleRange(C);
692
703
  }
693
704
  };
694
705
  return a.subscribeVisibleLogicalRangeChange(l), () => {
@@ -697,17 +708,17 @@ function Lt({
697
708
  );
698
709
  };
699
710
  }, [o]), W(() => {
700
- const t = I.current, a = Array.from(y.current.values()), l = [];
711
+ const t = I.current, a = Array.from(v.current.values()), l = [];
701
712
  if (t && a.length > 0 && x) {
702
713
  const n = at(), i = a[0];
703
714
  for (const f of x) {
704
- const c = {
715
+ const u = {
705
716
  ...n,
706
717
  ...f.options || {}
707
718
  };
708
- c.color && (c.color = U(c.color, c.color));
709
- const b = new ut(t, i, f.xCoordinate, c);
710
- i.attachPrimitive(b), l.push(b);
719
+ u.color && (u.color = U(u.color, u.color));
720
+ const p = new ut(t, i, f.xCoordinate, u);
721
+ i.attachPrimitive(p), l.push(p);
711
722
  }
712
723
  }
713
724
  return () => {
@@ -720,13 +731,13 @@ function Lt({
720
731
  }, [x, o]), W(() => {
721
732
  const t = [];
722
733
  if (k && k.length > 0) {
723
- const a = Array.from(y.current.values())[0], l = U(
734
+ const a = Array.from(v.current.values())[0], l = U(
724
735
  "hsl(var(--destructive))",
725
736
  "rgb(239, 68, 68)"
726
737
  );
727
738
  for (const n of k) {
728
739
  if (!Number.isFinite(n.price)) continue;
729
- const i = n.seriesLabel ? y.current.get(n.seriesLabel) : a;
740
+ const i = n.seriesLabel ? v.current.get(n.seriesLabel) : a;
730
741
  if (!i) continue;
731
742
  const f = i.createPriceLine({
732
743
  price: n.price,
@@ -749,17 +760,17 @@ function Lt({
749
760
  }, [k, o]), W(() => {
750
761
  const t = [];
751
762
  if (A && A.length > 0) {
752
- const a = Array.from(y.current.values())[0], l = "rgba(239, 68, 68, 0.12)";
763
+ const a = Array.from(v.current.values())[0], l = "rgba(239, 68, 68, 0.12)";
753
764
  for (const n of A) {
754
- const i = n.seriesLabel ? y.current.get(n.seriesLabel) : a;
765
+ const i = n.seriesLabel ? v.current.get(n.seriesLabel) : a;
755
766
  if (!i) continue;
756
- const f = n.color ? U(n.color, l) : l, c = new gt(
767
+ const f = n.color ? U(n.color, l) : l, u = new gt(
757
768
  i,
758
769
  n.priceTop,
759
770
  n.priceBottom,
760
771
  f
761
772
  );
762
- i.attachPrimitive(c), t.push({ series: i, zone: c });
773
+ i.attachPrimitive(u), t.push({ series: i, zone: u });
763
774
  }
764
775
  }
765
776
  return () => {
@@ -776,7 +787,7 @@ function Lt({
776
787
  return;
777
788
  }
778
789
  const a = () => {
779
- const i = t.timeScale(), f = x.map((c) => i.timeToCoordinate(c.xCoordinate) ?? null);
790
+ const i = t.timeScale(), f = x.map((u) => i.timeToCoordinate(u.xCoordinate) ?? null);
780
791
  _e(f);
781
792
  };
782
793
  a();
@@ -800,32 +811,32 @@ function Lt({
800
811
  ref: K,
801
812
  className: ne(
802
813
  "relative z-[1] w-full h-full overflow-hidden p-0",
803
- s
814
+ c
804
815
  ),
805
816
  children: [
806
- ue != null && ue !== !1 && ie ? /* @__PURE__ */ T("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ T("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: ue }) }) : qe && ie && Be && /* @__PURE__ */ T(
817
+ ue != null && ue !== !1 && ie ? /* @__PURE__ */ y("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ y("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: ue }) }) : qe && ie && Be && /* @__PURE__ */ y(
807
818
  st,
808
819
  {
809
820
  point: Be,
810
821
  xMeasureUnit: d,
811
- yMeasureUnit: N,
822
+ yMeasureUnit: w,
812
823
  decimals: ce
813
824
  }
814
825
  ),
815
- Me && ke && /* @__PURE__ */ T(
826
+ Me && ke && /* @__PURE__ */ y(
816
827
  ct,
817
828
  {
818
829
  points: Me,
819
830
  xMeasureUnit: d,
820
- yMeasureUnit: N,
831
+ yMeasureUnit: w,
821
832
  series: o,
822
833
  position: ke,
823
834
  containerRef: K,
824
835
  decimals: ce
825
836
  }
826
837
  ),
827
- g && /* @__PURE__ */ T(bt, { series: o, onUnselect: m }),
828
- x && x.length > 0 && Le.length === x.length && /* @__PURE__ */ T(
838
+ g && /* @__PURE__ */ y(pt, { series: o, onUnselect: b }),
839
+ x && x.length > 0 && Le.length === x.length && /* @__PURE__ */ y(
829
840
  "div",
830
841
  {
831
842
  className: "absolute inset-0 z-[5] pointer-events-none",
@@ -833,45 +844,45 @@ function Lt({
833
844
  children: x.map((t, a) => {
834
845
  const l = Le[a], n = t.options ?? {}, i = n.showLabel !== !1;
835
846
  if (l === null || !i) return null;
836
- const { labelText: f, valueStr: c } = dt(
847
+ const { labelText: f, valueStr: u } = dt(
837
848
  n,
838
- N,
849
+ w,
839
850
  ce
840
- ), b = n.tooltipText ?? "";
841
- if (!(f || c || b)) return null;
842
- const H = n.labelBackgroundColor ?? n.color ?? "hsl(var(--background))", _ = n.labelTextColor ?? "hsl(var(--foreground))", w = `${String(t.xCoordinate)}-${f}-${b}`;
851
+ ), p = n.tooltipText ?? "";
852
+ if (!(f || u || p)) return null;
853
+ const H = n.labelBackgroundColor ?? n.color ?? "hsl(var(--background))", B = n.labelTextColor ?? "hsl(var(--foreground))", N = `${String(t.xCoordinate)}-${f}-${p}`;
843
854
  return /* @__PURE__ */ re(
844
855
  "div",
845
856
  {
846
857
  className: ne(
847
858
  "group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
848
- b && "pointer-events-auto cursor-default"
859
+ p && "pointer-events-auto cursor-default"
849
860
  ),
850
861
  style: {
851
862
  left: l,
852
863
  transform: "translateX(-50%)",
853
864
  backgroundColor: H,
854
- color: _
865
+ color: B
855
866
  },
856
867
  children: [
857
- f && /* @__PURE__ */ T("span", { className: "block", children: f }),
858
- c && /* @__PURE__ */ T("span", { className: ne("block", f && "mt-0.5"), children: c }),
859
- b && /* @__PURE__ */ T(
868
+ f && /* @__PURE__ */ y("span", { className: "block", children: f }),
869
+ u && /* @__PURE__ */ y("span", { className: ne("block", f && "mt-0.5"), children: u }),
870
+ p && /* @__PURE__ */ y(
860
871
  "span",
861
872
  {
862
873
  className: "pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",
863
874
  role: "tooltip",
864
- children: b
875
+ children: p
865
876
  }
866
877
  )
867
878
  ]
868
879
  },
869
- w
880
+ N
870
881
  );
871
882
  })
872
883
  }
873
884
  ),
874
- /* @__PURE__ */ T(
885
+ /* @__PURE__ */ y(
875
886
  "div",
876
887
  {
877
888
  ref: ge,
@@ -882,20 +893,20 @@ function Lt({
882
893
  }
883
894
  );
884
895
  }
885
- function bt({
896
+ function pt({
886
897
  series: o,
887
- onUnselect: s,
898
+ onUnselect: c,
888
899
  inline: g = !1
889
900
  }) {
890
- return /* @__PURE__ */ T(
901
+ return /* @__PURE__ */ y(
891
902
  "div",
892
903
  {
893
904
  className: ne(
894
905
  "flex flex-wrap gap-2",
895
906
  g ? "items-center" : "absolute top-0 left-2 z-[10]"
896
907
  ),
897
- children: o.map((m, d) => {
898
- const N = Xe(d), q = (m.lineColor ?? m.color) || N.line, x = m.data.length === 0;
908
+ children: o.map((b, d) => {
909
+ const w = Xe(d), q = (b.lineColor ?? b.color) || w.line, x = b.data.length === 0;
899
910
  return /* @__PURE__ */ re(
900
911
  "div",
901
912
  {
@@ -904,7 +915,7 @@ function bt({
904
915
  x && "opacity-50"
905
916
  ),
906
917
  children: [
907
- /* @__PURE__ */ T(
918
+ /* @__PURE__ */ y(
908
919
  "div",
909
920
  {
910
921
  className: "w-3 h-3 rounded-sm",
@@ -912,18 +923,18 @@ function bt({
912
923
  }
913
924
  ),
914
925
  /* @__PURE__ */ re("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
915
- m.label,
926
+ b.label,
916
927
  x && " (no data)"
917
928
  ] }),
918
- s && /* @__PURE__ */ T(
929
+ c && /* @__PURE__ */ y(
919
930
  "button",
920
931
  {
921
932
  type: "button",
922
933
  onClick: (k) => {
923
- k.stopPropagation(), s(m.label);
934
+ k.stopPropagation(), c(b.label);
924
935
  },
925
936
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
926
- "aria-label": `Remove ${m.label}`,
937
+ "aria-label": `Remove ${b.label}`,
927
938
  children: /* @__PURE__ */ re(
928
939
  "svg",
929
940
  {
@@ -939,9 +950,9 @@ function bt({
939
950
  className: "text-muted-foreground hover:text-foreground",
940
951
  "aria-hidden": "true",
941
952
  children: [
942
- /* @__PURE__ */ T("title", { children: "Close" }),
943
- /* @__PURE__ */ T("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
944
- /* @__PURE__ */ T("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
953
+ /* @__PURE__ */ y("title", { children: "Close" }),
954
+ /* @__PURE__ */ y("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
955
+ /* @__PURE__ */ y("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
945
956
  ]
946
957
  }
947
958
  )
@@ -949,7 +960,7 @@ function bt({
949
960
  )
950
961
  ]
951
962
  },
952
- m.label
963
+ b.label
953
964
  );
954
965
  })
955
966
  }
@@ -958,7 +969,7 @@ function bt({
958
969
  export {
959
970
  ye as DEFAULT_SERIES_COLORS,
960
971
  Lt as Graph,
961
- bt as GraphLegend,
972
+ pt as GraphLegend,
962
973
  Xe as getSeriesColorPalette,
963
974
  mt as getStepForwardValue,
964
975
  dt as getVerticalLineTooltipContent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/ui-kit",
3
- "version": "3.14.0-next.36",
3
+ "version": "3.14.0-next.37",
4
4
  "description": "Internal UI components",
5
5
  "repository": {
6
6
  "type": "git",