@gearbox-protocol/ui-kit 3.0.1 → 3.0.2

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 f=require("react/jsx-runtime"),se=require("lightweight-charts"),d=require("react"),Pe=require("../../hooks/use-media-query.cjs"),ce=require("../../utils/cn.cjs"),O=require("../../utils/colors.cjs"),K=require("./default-config.cjs"),Y=require("./formatters.cjs"),Te=require("./graph-current-value.cjs"),Fe=require("./graph-tooltip.cjs"),Me=require("./plugins/vertical-line.cjs");function Ee(e){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const u in e)if(u!=="default"){const w=Object.getOwnPropertyDescriptor(e,u);Object.defineProperty(m,u,w.get?w:{enumerable:!0,get:()=>e[u]})}}return m.default=e,Object.freeze(m)}const ie=Ee(d);function Re(e,m,u){const w=e.labelText??"",b=e.value,y=b===void 0?"":typeof b=="number"?m==="$"?`$${Y.formatExactValue(b,void 0,u)}`:m==="%"?`${Y.formatExactValue(b,void 0,u)}%`:Y.formatExactValue(b,m!=="none"&&m!=="%"&&m!=="$"?m:void 0,u):String(b);return{labelText:w,valueStr:y}}const Q=[{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)"}],_e=137.5;function ue(e){if(e<Q.length)return Q[e];const u=(e-Q.length)*_e%360,w=O.hslToHex(u,70,50),{topColor:b,bottomColor:y}=O.generateColorsFromBase(w);return{line:w,top:b,bottom:y}}function Ae({series:e,className:m,showLegend:u=!1,onUnselectSeries:w,xMeasureUnit:b="time",yMeasureUnit:y="token",optionsOverrides:H,verticalLineOptions:x,currentValueDecimals:J,useSharedPriceScale:j=!1,showCurrentValue:we=!0,graphTitle:U,yScaleMin:fe,yScaleMinMultiple:ge}){const L=d.useRef(null),V=d.useRef(new Map),ee=d.useRef(!1),de=d.useRef(!0),te=d.useRef(null),ye=d.useRef(null),A=d.useRef(null),oe=d.useRef(null),N=Pe.useIsMobile(),M=ie.useMemo(()=>e.flatMap(t=>t.data),[e]),Ve=ie.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[be,re]=d.useState(()=>{if(!Ve)return;const t=new Map;for(const a of e)a.data.length>0&&t.set(a.label,a.data[a.data.length-1]);return t}),[me,E]=d.useState(null),[he,pe]=d.useState([]);d.useEffect(()=>{const t=()=>{if(L.current&&A.current){const l=A.current.clientWidth,i=A.current.clientHeight;L.current.resize(l,i)}},a=A.current,r=a?new ResizeObserver(t):null;return a&&r?.observe(a),()=>{a&&r?.unobserve(a)}},[]),d.useEffect(()=>{if(!oe.current||ee.current)return;const t=K.getDefaultOptions(),a=O.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),r=se.createChart(oe.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!N,textColor:a},...N&&{crosshair:{...t.crosshair,mode:se.CrosshairMode.Magnet}},...H});return L.current=r,ee.current=!0,()=>{r.remove(),L.current=null,ee.current=!1,V.current.clear()}},[N,H]),d.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const r=e.filter(o=>o.data.length>0).length<=1?fe:ge,l=b==="time"?Y.getXFormatters(b,M):Y.getXFormatters(b),i=M.map(o=>o.value),{formatter:c,tickmarksFormatter:g,updateVisibleRange:P,updateLastValues:h}=Y.createAdaptiveYAxisFormatter(i,y,{yScaleMin:r});te.current=P,ye.current=h;const T=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);h(T);const F=K.getDefaultOptions();t.applyOptions({localization:{...F.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...F.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const p=(M.length>0?Math.min(...M.map(o=>o.value)):0)<0,S=M.some(o=>o.value===0),C=!p&&S,v=e.length>1&&!j,R=e.length>1&&!j||N,_=O.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...F.rightPriceScale||{},visible:!R,textColor:_,...C&&{scaleMargins:{top:.3,bottom:0}}}});const I=new Set(V.current.keys()),D=new Set(e.map(o=>o.label));for(const o of I)if(!D.has(o)){const n=V.current.get(o);n&&(t.removeSeries(n),V.current.delete(o))}const q=K.getDefaultSeries(),ne=[];let Z=0;for(let o=0;o<e.length;o++){const n=e[o],W=ue(o),z=n.lineColor??n.color??W.line;let $,B;if(n.lineColor??n.color)if(n.topColor&&n.bottomColor)$=n.topColor,B=n.bottomColor;else if(n.topColor){const s=O.generateColorsFromBase(z);$=n.topColor,B=s.bottomColor}else if(n.bottomColor)$=O.generateColorsFromBase(z).topColor,B=n.bottomColor;else{const s=O.generateColorsFromBase(z);$=s.topColor,B=s.bottomColor}else $=n.topColor||W.top,B=n.bottomColor||W.bottom;if(n.data.length===0){const s=V.current.get(n.label);s&&(t.removeSeries(s),V.current.delete(n.label));continue}const ke=(n.data.length>0?Math.min(...n.data.map(s=>s.value)):0)<0,Ne=n.data.some(s=>s.value===0),je=!ke&&Ne,ve=j||!v||Z===0?"right":`scale-${Z}`;v&&ne.push({priceScaleId:ve||"right",shouldPreventNegativeAxis:je,seriesIndex:Z});const xe=(j||!v)&&r!==void 0&&typeof r=="number",Se={lineColor:z,topColor:$,bottomColor:B,priceScaleId:ve,priceFormat:{type:"custom",minMove:.01,formatter:xe&&typeof r=="number"?s=>c(s<r?r:s):c,tickmarksFormatter:g},autoscaleInfoProvider:s=>{if(!xe)return s();const le=s();if(le?.priceRange){const Le=r;le.priceRange.minValue=Le}return le}};let G=V.current.get(n.label);G?(G.applyOptions(Se),G.setData(n.data.map(s=>({...s,time:s.time})))):(G=t.addSeries(se.AreaSeries,{...q,...Se}),G.setData(n.data.map(s=>({...s,time:s.time}))),V.current.set(n.label,G)),Z++}if(v&&ne.length>0)for(const o of ne)try{const n=t.priceScale(o.priceScaleId);n&&n.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...o.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:_})}catch(n){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,n)}else if(!v)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:r!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:_})}catch{}if(r!==void 0&&!N&&(j||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),M.length>0){const o=M.map(z=>Number(z.time)),n=Math.min(...o),W=Math.max(...o);t.timeScale().setVisibleRange({from:n,to:W})}de.current&&(de.current=!1);const ae=new Map;for(const o of e)o.data.length>0&&ae.set(o.label,o.data[o.data.length-1]);re(ae.size>0?ae:void 0)},[e,M,b,y,N,j,fe,ge]),d.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const a=e.length===1;let r;for(const i of e)if(i.data.length>0){r=i.data[i.data.length-1].time;break}if(!r)return;const l=i=>{const{time:c=r,seriesData:g,point:P}=i||{},h=Array.from(V.current.values());if(!P||!c){const k=new Map;for(const p of e)p.data.length>0&&k.set(p.label,p.data[p.data.length-1]);if(re(k.size>0?k:void 0),a||j)E(null);else if(h[0]&&r){const S=t.timeScale().timeToCoordinate(r),C=e[0];if(C.data.length>0){const v=C.data[C.data.length-1].value,R=h[0].priceToCoordinate(v);S!==null&&R!==null&&E({x:S,y:R})}}return}const T=new Map;let F;for(let k=0;k<e.length;k++){const p=e[k],S=h[k];if(!S)continue;const C=g?.get(S),v=C&&"value"in C?C.value:void 0;let R;if(v!==void 0)R=v;else{const _=Number(c),I=p.data;let D=0;for(let q=I.length-1;q>=0;q--)if(Number(I[q].time)<=_){D=I[q].value;break}R=D}k===0&&(F=R),T.set(p.label,{value:R,time:c})}if(re(T),F!==void 0&&h[0]){const p=t.timeScale().timeToCoordinate(c),S=h[0].priceToCoordinate(F);if(p!==null&&S!==null){const C=A.current;if(C){const v=C.querySelector(".LightweightChart");if(v){const R=v.getBoundingClientRect(),_=C.getBoundingClientRect(),I=p+(R.left-_.left),D=S+(R.top-_.top);E({x:I,y:D})}else E({x:p,y:S})}else E({x:p,y:S})}else E(null)}else E(null)};return t.subscribeCrosshairMove(l),N&&t.subscribeClick(l),!a&&!j&&requestAnimationFrame(()=>{const i=Array.from(V.current.values());if(i[0]&&r&&e[0]?.data.length>0){const g=t.timeScale().timeToCoordinate(r),P=e[0].data[e[0].data.length-1].value,h=i[0].priceToCoordinate(P);g!==null&&h!==null&&E({x:g,y:h})}}),()=>{t.unsubscribeCrosshairMove(l),N&&t.unsubscribeClick(l)}},[e,j,N]),d.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const a=t.timeScale(),r=()=>{if(!te.current)return;const l=a.getVisibleRange();if(!l)return;const i=Number(l.from),c=Number(l.to),g=[];for(const P of e)for(const h of P.data){const T=Number(h.time);T>=i&&T<=c&&g.push(h.value)}g.length>0&&te.current(g)};return a.subscribeVisibleLogicalRangeChange(r),()=>{a.unsubscribeVisibleLogicalRangeChange(r)}},[e]),d.useEffect(()=>{const t=L.current,a=Array.from(V.current.values()),r=[];if(t&&a.length>0&&x){const l=K.getDefaultVerticalLine(),i=a[0];for(const c of x){const g=new Me.VertLine(t,i,c.xCoordinate,{...l,...c.options||{}});i.attachPrimitive(g),r.push(g)}}return()=>{if(a.length>0){const l=a[0];for(const i of r)l.detachPrimitive(i)}}},[x]),d.useEffect(()=>{const t=L.current;if(!t||!x?.length){pe([]);return}const a=()=>{const i=t.timeScale(),c=x.map(g=>i.timeToCoordinate(g.xCoordinate)??null);pe(c)};a();const r=t.timeScale(),l=()=>{a()};return r.subscribeVisibleLogicalRangeChange(l),()=>{r.unsubscribeVisibleLogicalRangeChange(l)}},[x]);const X=e.length===1,Ce=ie.useMemo(()=>{if(X&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[X,e]);return f.jsxs("div",{ref:A,className:ce.cn("relative z-[1] w-full h-full overflow-hidden p-0",m),children:[U!=null&&U!==!1&&X?f.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:f.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:U})}):we&&X&&Ce&&f.jsx(Te.GraphCurrentValue,{point:Ce,xMeasureUnit:b,yMeasureUnit:y,decimals:J}),be&&me&&f.jsx(Fe.GraphTooltip,{points:be,xMeasureUnit:b,yMeasureUnit:y,series:e,position:me,containerRef:A,decimals:J}),u&&f.jsx(Ie,{series:e,onUnselect:w}),x&&x.length>0&&he.length===x.length&&f.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:x.map((t,a)=>{const r=he[a],l=t.options??{},i=l.showLabel!==!1;if(r===null||!i)return null;const{labelText:c,valueStr:g}=Re(l,y,J);if(!(c||g))return null;const h=l.labelBackgroundColor??l.color??"hsl(var(--background))",T=l.labelTextColor??"hsl(var(--foreground))",F=`${String(t.xCoordinate)}-${c}`;return f.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:r,transform:"translateX(-50%)",backgroundColor:h,color:T},children:[c&&f.jsx("span",{className:"block",children:c}),g&&f.jsx("span",{className:ce.cn("block",c&&"mt-0.5"),children:g})]},F)})}),f.jsx("div",{ref:oe,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ie({series:e,onUnselect:m}){return f.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((u,w)=>{const b=ue(w),y=(u.lineColor??u.color)||b.line,H=u.data.length===0;return f.jsxs("div",{className:ce.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",H&&"opacity-50"),children:[f.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:y}}),f.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[u.label,H&&" (no data)"]}),m&&f.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),m(u.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 ${u.label}`,children:f.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:[f.jsx("title",{children:"Close"}),f.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),f.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},u.label)})})}exports.DEFAULT_SERIES_COLORS=Q;exports.Graph=Ae;exports.getSeriesColorPalette=ue;exports.getVerticalLineTooltipContent=Re;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),le=require("lightweight-charts"),d=require("react"),Pe=require("../../hooks/use-media-query.cjs"),ie=require("../../utils/cn.cjs"),A=require("../../utils/colors.cjs"),W=require("./default-config.cjs"),$=require("./formatters.cjs"),Te=require("./graph-current-value.cjs"),Me=require("./graph-tooltip.cjs"),Ee=require("./plugins/vertical-line.cjs");function _e(e){const b=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const w=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(b,s,w.get?w:{enumerable:!0,get:()=>e[s]})}}return b.default=e,Object.freeze(b)}const se=_e(d);function Se(e,b,s){const w=e.labelText??"",m=e.value,V=m===void 0?"":typeof m=="number"?b==="$"?`$${$.formatExactValue(m,void 0,s)}`:b==="%"?`${$.formatExactValue(m,void 0,s)}%`:$.formatExactValue(m,b!=="none"&&b!=="%"&&b!=="$"?b:void 0,s):String(m);return{labelText:w,valueStr:V}}function Re(e,b){for(let s=e.length-1;s>=0;s--)if(Number(e[s].time)<=b)return e[s].value;return 0}const X=[{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)"}],Ae=137.5;function ce(e){if(e<X.length)return X[e];const s=(e-X.length)*Ae%360,w=A.hslToHex(s,70,50),{topColor:m,bottomColor:V}=A.generateColorsFromBase(w);return{line:w,top:m,bottom:V}}function Ie({series:e,className:b,showLegend:s=!1,onUnselectSeries:w,xMeasureUnit:m="time",yMeasureUnit:V="token",optionsOverrides:B,verticalLineOptions:S,currentValueDecimals:Z,useSharedPriceScale:j=!1,showCurrentValue:we=!0,graphTitle:K,yScaleMin:ue,yScaleMinMultiple:fe}){const F=d.useRef(null),y=d.useRef(new Map),Q=d.useRef(!1),ge=d.useRef(!0),J=d.useRef(null),Ve=d.useRef(null),_=d.useRef(null),U=d.useRef(null),N=Pe.useIsMobile(),M=se.useMemo(()=>e.flatMap(t=>t.data),[e]),ye=se.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[de,ee]=d.useState(()=>{if(!ye)return;const t=new Map;for(const a of e)a.data.length>0&&t.set(a.label,a.data[a.data.length-1]);return t}),[be,E]=d.useState(null),[me,he]=d.useState([]);d.useEffect(()=>{const t=()=>{if(F.current&&_.current){const l=_.current.clientWidth,c=_.current.clientHeight;F.current.resize(l,c)}},a=_.current,r=a?new ResizeObserver(t):null;return a&&r?.observe(a),()=>{a&&r?.unobserve(a)}},[]),d.useEffect(()=>{if(!U.current||Q.current)return;const t=W.getDefaultOptions(),a=A.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),r=le.createChart(U.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!N,textColor:a},...N&&{crosshair:{...t.crosshair,mode:le.CrosshairMode.Magnet}},...B});return F.current=r,Q.current=!0,()=>{r.remove(),F.current=null,Q.current=!1,y.current.clear()}},[N,B]),d.useEffect(()=>{const t=F.current;if(!t||e.length===0)return;const r=e.filter(o=>o.data.length>0).length<=1?ue:fe,l=m==="time"?$.getXFormatters(m,M):$.getXFormatters(m),c=M.map(o=>o.value),{formatter:u,tickmarksFormatter:g,updateVisibleRange:L,updateLastValues:p}=$.createAdaptiveYAxisFormatter(c,V,{yScaleMin:r});J.current=L,Ve.current=p;const P=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);p(P);const T=W.getDefaultOptions();t.applyOptions({localization:{...T.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...T.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const h=(M.length>0?Math.min(...M.map(o=>o.value)):0)<0,R=M.some(o=>o.value===0),C=!h&&R,v=e.length>1&&!j,x=e.length>1&&!j||N,I=A.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...T.rightPriceScale||{},visible:!x,textColor:I,...C&&{scaleMargins:{top:.3,bottom:0}}}});const te=new Set(y.current.keys()),oe=new Set(e.map(o=>o.label));for(const o of te)if(!oe.has(o)){const n=y.current.get(o);n&&(t.removeSeries(n),y.current.delete(o))}const ke=W.getDefaultSeries(),re=[];let H=0;for(let o=0;o<e.length;o++){const n=e[o],G=ce(o),O=n.lineColor??n.color??G.line;let D,q;if(n.lineColor??n.color)if(n.topColor&&n.bottomColor)D=n.topColor,q=n.bottomColor;else if(n.topColor){const i=A.generateColorsFromBase(O);D=n.topColor,q=i.bottomColor}else if(n.bottomColor)D=A.generateColorsFromBase(O).topColor,q=n.bottomColor;else{const i=A.generateColorsFromBase(O);D=i.topColor,q=i.bottomColor}else D=n.topColor||G.top,q=n.bottomColor||G.bottom;if(n.data.length===0){const i=y.current.get(n.label);i&&(t.removeSeries(i),y.current.delete(n.label));continue}const Ne=(n.data.length>0?Math.min(...n.data.map(i=>i.value)):0)<0,je=n.data.some(i=>i.value===0),Fe=!Ne&&je,Ce=j||!v||H===0?"right":`scale-${H}`;v&&re.push({priceScaleId:Ce||"right",shouldPreventNegativeAxis:Fe,seriesIndex:H});const ve=(j||!v)&&r!==void 0&&typeof r=="number",xe={lineColor:O,topColor:D,bottomColor:q,priceScaleId:Ce,priceFormat:{type:"custom",minMove:.01,formatter:ve&&typeof r=="number"?i=>u(i<r?r:i):u,tickmarksFormatter:g},autoscaleInfoProvider:i=>{if(!ve)return i();const ae=i();if(ae?.priceRange){const Le=r;ae.priceRange.minValue=Le}return ae}};let z=y.current.get(n.label);z?(z.applyOptions(xe),z.setData(n.data.map(i=>({...i,time:i.time})))):(z=t.addSeries(le.AreaSeries,{...ke,...xe}),z.setData(n.data.map(i=>({...i,time:i.time}))),y.current.set(n.label,z)),H++}if(v&&re.length>0)for(const o of re)try{const n=t.priceScale(o.priceScaleId);n&&n.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...o.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:I})}catch(n){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,n)}else if(!v)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:r!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:I})}catch{}if(r!==void 0&&!N&&(j||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),M.length>0){const o=M.map(O=>Number(O.time)),n=Math.min(...o),G=Math.max(...o);t.timeScale().setVisibleRange({from:n,to:G})}ge.current&&(ge.current=!1);const ne=new Map;for(const o of e)o.data.length>0&&ne.set(o.label,o.data[o.data.length-1]);ee(ne.size>0?ne:void 0)},[e,M,m,V,N,j,ue,fe]),d.useEffect(()=>{const t=F.current;if(!t||e.length===0)return;const a=e.length===1;let r;for(const c of e)if(c.data.length>0){r=c.data[c.data.length-1].time;break}if(!r)return;const l=c=>{const{time:u=r,seriesData:g,point:L}=c||{},p=Array.from(y.current.values());if(!L||!u){const k=new Map;for(const h of e)h.data.length>0&&k.set(h.label,h.data[h.data.length-1]);if(ee(k.size>0?k:void 0),a||j)E(null);else if(p[0]&&r){const R=t.timeScale().timeToCoordinate(r),C=e[0];if(C.data.length>0){const v=C.data[C.data.length-1].value,x=p[0].priceToCoordinate(v);R!==null&&x!==null&&E({x:R,y:x})}}return}const P=new Map;let T;for(let k=0;k<e.length;k++){const h=e[k],R=p[k];if(!R)continue;const C=g?.get(R),v=C&&"value"in C?C.value:void 0;let x;v!==void 0?x=v:a?x=h.data[h.data.length-1]?.value??0:x=Re(h.data,Number(u)),k===0&&(T=x),P.set(h.label,{value:x,time:u})}if(ee(P),T!==void 0&&p[0]){const h=t.timeScale().timeToCoordinate(u),R=p[0].priceToCoordinate(T);if(h!==null&&R!==null){const C=_.current;if(C){const v=C.querySelector(".LightweightChart");if(v){const x=v.getBoundingClientRect(),I=C.getBoundingClientRect(),te=h+(x.left-I.left),oe=R+(x.top-I.top);E({x:te,y:oe})}else E({x:h,y:R})}else E({x:h,y:R})}else E(null)}else E(null)};return t.subscribeCrosshairMove(l),N&&t.subscribeClick(l),!a&&!j&&requestAnimationFrame(()=>{const c=Array.from(y.current.values());if(c[0]&&r&&e[0]?.data.length>0){const g=t.timeScale().timeToCoordinate(r),L=e[0].data[e[0].data.length-1].value,p=c[0].priceToCoordinate(L);g!==null&&p!==null&&E({x:g,y:p})}}),()=>{t.unsubscribeCrosshairMove(l),N&&t.unsubscribeClick(l)}},[e,j,N]),d.useEffect(()=>{const t=F.current;if(!t||e.length===0)return;const a=t.timeScale(),r=()=>{if(!J.current)return;const l=a.getVisibleRange();if(!l)return;const c=Number(l.from),u=Number(l.to),g=[];for(const L of e)for(const p of L.data){const P=Number(p.time);P>=c&&P<=u&&g.push(p.value)}g.length>0&&J.current(g)};return a.subscribeVisibleLogicalRangeChange(r),()=>{a.unsubscribeVisibleLogicalRangeChange(r)}},[e]),d.useEffect(()=>{const t=F.current,a=Array.from(y.current.values()),r=[];if(t&&a.length>0&&S){const l=W.getDefaultVerticalLine(),c=a[0];for(const u of S){const g=new Ee.VertLine(t,c,u.xCoordinate,{...l,...u.options||{}});c.attachPrimitive(g),r.push(g)}}return()=>{if(a.length>0){const l=a[0];for(const c of r)l.detachPrimitive(c)}}},[S]),d.useEffect(()=>{const t=F.current;if(!t||!S?.length){he([]);return}const a=()=>{const c=t.timeScale(),u=S.map(g=>c.timeToCoordinate(g.xCoordinate)??null);he(u)};a();const r=t.timeScale(),l=()=>{a()};return r.subscribeVisibleLogicalRangeChange(l),()=>{r.unsubscribeVisibleLogicalRangeChange(l)}},[S]);const Y=e.length===1,pe=se.useMemo(()=>{if(Y&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[Y,e]);return f.jsxs("div",{ref:_,className:ie.cn("relative z-[1] w-full h-full overflow-hidden p-0",b),children:[K!=null&&K!==!1&&Y?f.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:f.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:K})}):we&&Y&&pe&&f.jsx(Te.GraphCurrentValue,{point:pe,xMeasureUnit:m,yMeasureUnit:V,decimals:Z}),de&&be&&f.jsx(Me.GraphTooltip,{points:de,xMeasureUnit:m,yMeasureUnit:V,series:e,position:be,containerRef:_,decimals:Z}),s&&f.jsx(Oe,{series:e,onUnselect:w}),S&&S.length>0&&me.length===S.length&&f.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:S.map((t,a)=>{const r=me[a],l=t.options??{},c=l.showLabel!==!1;if(r===null||!c)return null;const{labelText:u,valueStr:g}=Se(l,V,Z);if(!(u||g))return null;const p=l.labelBackgroundColor??l.color??"hsl(var(--background))",P=l.labelTextColor??"hsl(var(--foreground))",T=`${String(t.xCoordinate)}-${u}`;return f.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:r,transform:"translateX(-50%)",backgroundColor:p,color:P},children:[u&&f.jsx("span",{className:"block",children:u}),g&&f.jsx("span",{className:ie.cn("block",u&&"mt-0.5"),children:g})]},T)})}),f.jsx("div",{ref:U,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Oe({series:e,onUnselect:b}){return f.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((s,w)=>{const m=ce(w),V=(s.lineColor??s.color)||m.line,B=s.data.length===0;return f.jsxs("div",{className:ie.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",B&&"opacity-50"),children:[f.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:V}}),f.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[s.label,B&&" (no data)"]}),b&&f.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),b(s.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 ${s.label}`,children:f.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:[f.jsx("title",{children:"Close"}),f.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),f.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},s.label)})})}exports.DEFAULT_SERIES_COLORS=X;exports.Graph=Ie;exports.getSeriesColorPalette=ce;exports.getStepForwardValue=Re;exports.getVerticalLineTooltipContent=Se;
@@ -1,24 +1,30 @@
1
- import { jsxs as X, jsx as h } from "react/jsx-runtime";
1
+ import { jsxs as H, jsx as h } from "react/jsx-runtime";
2
2
  import { createChart as At, CrosshairMode as It, AreaSeries as zt } from "lightweight-charts";
3
- import * as lt from "react";
4
- import { useRef as z, useState as it, useEffect as E } from "react";
3
+ import * as at from "react";
4
+ import { useRef as I, useState as lt, useEffect as $ } from "react";
5
5
  import { useIsMobile as $t } from "../../hooks/use-media-query.js";
6
- import { cn as ut } from "../../utils/cn.js";
7
- import { resolveCSSColor as wt, generateColorsFromBase as K, hslToHex as Dt } from "../../utils/colors.js";
8
- import { getDefaultOptions as Rt, getDefaultSeries as Et, getDefaultVerticalLine as Gt } from "./default-config.js";
9
- import { getXFormatters as Vt, createAdaptiveYAxisFormatter as Bt, formatExactValue as st } from "./formatters.js";
6
+ import { cn as ct } from "../../utils/cn.js";
7
+ import { resolveCSSColor as St, generateColorsFromBase as X, hslToHex as Dt } from "../../utils/colors.js";
8
+ import { getDefaultOptions as wt, getDefaultSeries as Et, getDefaultVerticalLine as Gt } from "./default-config.js";
9
+ import { getXFormatters as Rt, createAdaptiveYAxisFormatter as Bt, formatExactValue as it } from "./formatters.js";
10
10
  import { GraphCurrentValue as Ot } from "./graph-current-value.js";
11
11
  import { GraphTooltip as Yt } from "./graph-tooltip.js";
12
12
  import { VertLine as jt } from "./plugins/vertical-line.js";
13
- function Ht(e, v, m) {
14
- const F = e.labelText ?? "", f = e.value, w = f === void 0 ? "" : typeof f == "number" ? v === "$" ? `$${st(f, void 0, m)}` : v === "%" ? `${st(f, void 0, m)}%` : st(
15
- f,
16
- v !== "none" && v !== "%" && v !== "$" ? v : void 0,
17
- m
18
- ) : String(f);
19
- return { labelText: F, valueStr: w };
13
+ function Ht(e, p, u) {
14
+ const T = e.labelText ?? "", g = e.value, w = g === void 0 ? "" : typeof g == "number" ? p === "$" ? `$${it(g, void 0, u)}` : p === "%" ? `${it(g, void 0, u)}%` : it(
15
+ g,
16
+ p !== "none" && p !== "%" && p !== "$" ? p : void 0,
17
+ u
18
+ ) : String(g);
19
+ return { labelText: T, valueStr: w };
20
20
  }
21
- const ct = [
21
+ function Wt(e, p) {
22
+ for (let u = e.length - 1; u >= 0; u--)
23
+ if (Number(e[u].time) <= p)
24
+ return e[u].value;
25
+ return 0;
26
+ }
27
+ const st = [
22
28
  // 0 green (emerald)
23
29
  {
24
30
  line: "#02c39a",
@@ -133,60 +139,60 @@ const ct = [
133
139
  top: "rgba(71, 85, 105, 0.56)",
134
140
  bottom: "rgba(71, 85, 105, 0.04)"
135
141
  }
136
- ], Wt = 137.5;
137
- function yt(e) {
138
- if (e < ct.length)
139
- return ct[e];
140
- const m = (e - ct.length) * Wt % 360, F = Dt(m, 70, 50), { topColor: f, bottomColor: w } = K(F);
141
- return { line: F, top: f, bottom: w };
142
+ ], _t = 137.5;
143
+ function Vt(e) {
144
+ if (e < st.length)
145
+ return st[e];
146
+ const u = (e - st.length) * _t % 360, T = Dt(u, 70, 50), { topColor: g, bottomColor: w } = X(T);
147
+ return { line: T, top: g, bottom: w };
142
148
  }
143
- function ie({
149
+ function se({
144
150
  series: e,
145
- className: v,
146
- showLegend: m = !1,
147
- onUnselectSeries: F,
148
- xMeasureUnit: f = "time",
151
+ className: p,
152
+ showLegend: u = !1,
153
+ onUnselectSeries: T,
154
+ xMeasureUnit: g = "time",
149
155
  yMeasureUnit: w = "token",
150
- optionsOverrides: W,
151
- verticalLineOptions: C,
152
- currentValueDecimals: J,
153
- useSharedPriceScale: k = !1,
154
- showCurrentValue: kt = !0,
155
- graphTitle: Q,
156
- yScaleMin: ft,
157
- yScaleMinMultiple: gt
156
+ optionsOverrides: Y,
157
+ verticalLineOptions: x,
158
+ currentValueDecimals: q,
159
+ useSharedPriceScale: N = !1,
160
+ showCurrentValue: yt = !0,
161
+ graphTitle: Z,
162
+ yScaleMin: ut,
163
+ yScaleMinMultiple: ft
158
164
  }) {
159
- const N = z(null), R = z(/* @__PURE__ */ new Map()), U = z(!1), mt = z(!0), tt = z(
165
+ const k = I(null), R = I(/* @__PURE__ */ new Map()), K = I(!1), gt = I(!0), J = I(
160
166
  null
161
- ), Nt = z(null), $ = z(null), et = z(null), y = $t(), M = lt.useMemo(() => e.flatMap((t) => t.data), [e]), Lt = lt.useMemo(() => {
167
+ ), Nt = I(null), z = I(null), Q = I(null), y = $t(), M = at.useMemo(() => e.flatMap((t) => t.data), [e]), kt = at.useMemo(() => {
162
168
  if (e.length > 0) {
163
169
  const t = e[e.length - 1];
164
170
  if (t.data.length > 0)
165
171
  return t.data[t.data.length - 1];
166
172
  }
167
- }, [e]), [dt, ot] = it(() => {
168
- if (!Lt) return;
173
+ }, [e]), [dt, U] = lt(() => {
174
+ if (!kt) return;
169
175
  const t = /* @__PURE__ */ new Map();
170
176
  for (const a of e)
171
177
  a.data.length > 0 && t.set(a.label, a.data[a.data.length - 1]);
172
178
  return t;
173
- }), [bt, A] = it(null), [ht, pt] = it([]);
174
- E(() => {
179
+ }), [mt, A] = lt(null), [bt, ht] = lt([]);
180
+ $(() => {
175
181
  const t = () => {
176
- if (N.current && $.current) {
177
- const l = $.current.clientWidth, s = $.current.clientHeight;
178
- N.current.resize(l, s);
182
+ if (k.current && z.current) {
183
+ const l = z.current.clientWidth, s = z.current.clientHeight;
184
+ k.current.resize(l, s);
179
185
  }
180
- }, a = $.current, r = a ? new ResizeObserver(t) : null;
186
+ }, a = z.current, r = a ? new ResizeObserver(t) : null;
181
187
  return a && r?.observe(a), () => {
182
188
  a && r?.unobserve(a);
183
189
  };
184
- }, []), E(() => {
185
- if (!et.current || U.current) return;
186
- const t = Rt(), a = wt(
190
+ }, []), $(() => {
191
+ if (!Q.current || K.current) return;
192
+ const t = wt(), a = St(
187
193
  "hsl(var(--foreground))",
188
194
  "rgb(0, 0, 0)"
189
- ), r = At(et.current, {
195
+ ), r = At(Q.current, {
190
196
  ...t,
191
197
  rightPriceScale: {
192
198
  ...t.rightPriceScale || {},
@@ -199,29 +205,29 @@ function ie({
199
205
  mode: It.Magnet
200
206
  }
201
207
  },
202
- ...W
208
+ ...Y
203
209
  });
204
- return N.current = r, U.current = !0, () => {
205
- r.remove(), N.current = null, U.current = !1, R.current.clear();
210
+ return k.current = r, K.current = !0, () => {
211
+ r.remove(), k.current = null, K.current = !1, R.current.clear();
206
212
  };
207
- }, [y, W]), E(() => {
208
- const t = N.current;
213
+ }, [y, Y]), $(() => {
214
+ const t = k.current;
209
215
  if (!t || e.length === 0) return;
210
- const r = e.filter((o) => o.data.length > 0).length <= 1 ? ft : gt, l = f === "time" ? Vt(f, M) : Vt(f), s = M.map((o) => o.value), {
216
+ const r = e.filter((o) => o.data.length > 0).length <= 1 ? ut : ft, l = g === "time" ? Rt(g, M) : Rt(g), s = M.map((o) => o.value), {
211
217
  formatter: c,
212
- tickmarksFormatter: u,
218
+ tickmarksFormatter: f,
213
219
  updateVisibleRange: L,
214
- updateLastValues: g
220
+ updateLastValues: m
215
221
  } = Bt(s, w, {
216
222
  yScaleMin: r
217
223
  });
218
- tt.current = L, Nt.current = g;
224
+ J.current = L, Nt.current = m;
219
225
  const P = e.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
220
- g(P);
221
- const T = Rt();
226
+ m(P);
227
+ const F = wt();
222
228
  t.applyOptions({
223
229
  localization: {
224
- ...T.localization || {},
230
+ ...F.localization || {},
225
231
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
226
232
  timeFormatter: (o) => (
227
233
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
@@ -229,21 +235,21 @@ function ie({
229
235
  )
230
236
  },
231
237
  timeScale: {
232
- ...T.timeScale || {},
238
+ ...F.timeScale || {},
233
239
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
234
240
  tickMarkFormatter: l.tickMarkFormatter,
235
241
  minBarSpacing: 0
236
242
  }
237
243
  });
238
- const d = (M.length > 0 ? Math.min(...M.map((o) => o.value)) : 0) < 0, x = M.some((o) => o.value === 0), b = !d && x, p = e.length > 1 && !k, S = e.length > 1 && !k || y, I = wt(
244
+ const d = (M.length > 0 ? Math.min(...M.map((o) => o.value)) : 0) < 0, S = M.some((o) => o.value === 0), b = !d && S, v = e.length > 1 && !N, C = e.length > 1 && !N || y, D = St(
239
245
  "hsl(var(--foreground))",
240
246
  "rgb(0, 0, 0)"
241
247
  );
242
248
  t.applyOptions({
243
249
  rightPriceScale: {
244
- ...T.rightPriceScale || {},
245
- visible: !S,
246
- textColor: I,
250
+ ...F.rightPriceScale || {},
251
+ visible: !C,
252
+ textColor: D,
247
253
  ...b && {
248
254
  scaleMargins: {
249
255
  top: 0.3,
@@ -252,83 +258,83 @@ function ie({
252
258
  }
253
259
  }
254
260
  });
255
- const D = new Set(R.current.keys()), G = new Set(e.map((o) => o.label));
256
- for (const o of D)
257
- if (!G.has(o)) {
261
+ const tt = new Set(R.current.keys()), et = new Set(e.map((o) => o.label));
262
+ for (const o of tt)
263
+ if (!et.has(o)) {
258
264
  const n = R.current.get(o);
259
265
  n && (t.removeSeries(n), R.current.delete(o));
260
266
  }
261
- const B = Et(), rt = [];
262
- let Z = 0;
267
+ const Lt = Et(), ot = [];
268
+ let _ = 0;
263
269
  for (let o = 0; o < e.length; o++) {
264
- const n = e[o], _ = yt(o), O = n.lineColor ?? n.color ?? _.line;
265
- let Y, j;
270
+ const n = e[o], j = Vt(o), E = n.lineColor ?? n.color ?? j.line;
271
+ let G, B;
266
272
  if (n.lineColor ?? n.color)
267
273
  if (n.topColor && n.bottomColor)
268
- Y = n.topColor, j = n.bottomColor;
274
+ G = n.topColor, B = n.bottomColor;
269
275
  else if (n.topColor) {
270
- const i = K(O);
271
- Y = n.topColor, j = i.bottomColor;
276
+ const i = X(E);
277
+ G = n.topColor, B = i.bottomColor;
272
278
  } else if (n.bottomColor)
273
- Y = K(O).topColor, j = n.bottomColor;
279
+ G = X(E).topColor, B = n.bottomColor;
274
280
  else {
275
- const i = K(O);
276
- Y = i.topColor, j = i.bottomColor;
281
+ const i = X(E);
282
+ G = i.topColor, B = i.bottomColor;
277
283
  }
278
284
  else
279
- Y = n.topColor || _.top, j = n.bottomColor || _.bottom;
285
+ G = n.topColor || j.top, B = n.bottomColor || j.bottom;
280
286
  if (n.data.length === 0) {
281
287
  const i = R.current.get(n.label);
282
288
  i && (t.removeSeries(i), R.current.delete(n.label));
283
289
  continue;
284
290
  }
285
- const Pt = (n.data.length > 0 ? Math.min(...n.data.map((i) => i.value)) : 0) < 0, Tt = n.data.some((i) => i.value === 0), Ft = !Pt && Tt, Ct = k || !p || Z === 0 ? "right" : `scale-${Z}`;
286
- p && rt.push({
287
- priceScaleId: Ct || "right",
288
- shouldPreventNegativeAxis: Ft,
289
- seriesIndex: Z
291
+ const Pt = (n.data.length > 0 ? Math.min(...n.data.map((i) => i.value)) : 0) < 0, Ft = n.data.some((i) => i.value === 0), Tt = !Pt && Ft, vt = N || !v || _ === 0 ? "right" : `scale-${_}`;
292
+ v && ot.push({
293
+ priceScaleId: vt || "right",
294
+ shouldPreventNegativeAxis: Tt,
295
+ seriesIndex: _
290
296
  });
291
- const xt = (k || !p) && r !== void 0 && typeof r == "number", St = {
292
- lineColor: O,
293
- topColor: Y,
294
- bottomColor: j,
295
- priceScaleId: Ct,
297
+ const Ct = (N || !v) && r !== void 0 && typeof r == "number", xt = {
298
+ lineColor: E,
299
+ topColor: G,
300
+ bottomColor: B,
301
+ priceScaleId: vt,
296
302
  priceFormat: {
297
303
  type: "custom",
298
304
  minMove: 0.01,
299
- formatter: xt && typeof r == "number" ? (i) => c(
305
+ formatter: Ct && typeof r == "number" ? (i) => c(
300
306
  i < r ? r : i
301
307
  ) : c,
302
- tickmarksFormatter: u
308
+ tickmarksFormatter: f
303
309
  },
304
310
  autoscaleInfoProvider: (i) => {
305
- if (!xt) return i();
306
- const at = i();
307
- if (at?.priceRange) {
311
+ if (!Ct) return i();
312
+ const nt = i();
313
+ if (nt?.priceRange) {
308
314
  const Mt = r;
309
- at.priceRange.minValue = Mt;
315
+ nt.priceRange.minValue = Mt;
310
316
  }
311
- return at;
317
+ return nt;
312
318
  }
313
319
  };
314
- let H = R.current.get(n.label);
315
- H ? (H.applyOptions(St), H.setData(
320
+ let O = R.current.get(n.label);
321
+ O ? (O.applyOptions(xt), O.setData(
316
322
  n.data.map((i) => ({
317
323
  ...i,
318
324
  time: i.time
319
325
  }))
320
- )) : (H = t.addSeries(zt, {
321
- ...B,
322
- ...St
323
- }), H.setData(
326
+ )) : (O = t.addSeries(zt, {
327
+ ...Lt,
328
+ ...xt
329
+ }), O.setData(
324
330
  n.data.map((i) => ({
325
331
  ...i,
326
332
  time: i.time
327
333
  }))
328
- ), R.current.set(n.label, H)), Z++;
334
+ ), R.current.set(n.label, O)), _++;
329
335
  }
330
- if (p && rt.length > 0)
331
- for (const o of rt)
336
+ if (v && ot.length > 0)
337
+ for (const o of ot)
332
338
  try {
333
339
  const n = t.priceScale(o.priceScaleId);
334
340
  n && n.applyOptions({
@@ -346,7 +352,7 @@ function ie({
346
352
  borderVisible: !0,
347
353
  borderColor: "rgba(224, 227, 235, 0.1)",
348
354
  entireTextOnly: !1,
349
- textColor: I
355
+ textColor: D
350
356
  });
351
357
  } catch (n) {
352
358
  console.warn(
@@ -354,7 +360,7 @@ function ie({
354
360
  n
355
361
  );
356
362
  }
357
- else if (!p)
363
+ else if (!v)
358
364
  try {
359
365
  const o = t.priceScale("right");
360
366
  o && o.applyOptions({
@@ -372,34 +378,34 @@ function ie({
372
378
  borderVisible: !0,
373
379
  borderColor: "rgba(224, 227, 235, 0.1)",
374
380
  entireTextOnly: !1,
375
- textColor: I
381
+ textColor: D
376
382
  });
377
383
  } catch {
378
384
  }
379
- if (r !== void 0 && !y && (k || !p) && t.applyOptions({
385
+ if (r !== void 0 && !y && (N || !v) && t.applyOptions({
380
386
  handleScroll: {
381
387
  vertTouchDrag: !1
382
388
  }
383
389
  }), M.length > 0) {
384
- const o = M.map((O) => Number(O.time)), n = Math.min(...o), _ = Math.max(...o);
385
- t.timeScale().setVisibleRange({ from: n, to: _ });
390
+ const o = M.map((E) => Number(E.time)), n = Math.min(...o), j = Math.max(...o);
391
+ t.timeScale().setVisibleRange({ from: n, to: j });
386
392
  }
387
- mt.current && (mt.current = !1);
388
- const nt = /* @__PURE__ */ new Map();
393
+ gt.current && (gt.current = !1);
394
+ const rt = /* @__PURE__ */ new Map();
389
395
  for (const o of e)
390
- o.data.length > 0 && nt.set(o.label, o.data[o.data.length - 1]);
391
- ot(nt.size > 0 ? nt : void 0);
396
+ o.data.length > 0 && rt.set(o.label, o.data[o.data.length - 1]);
397
+ U(rt.size > 0 ? rt : void 0);
392
398
  }, [
393
399
  e,
394
400
  M,
395
- f,
401
+ g,
396
402
  w,
397
403
  y,
398
- k,
399
- ft,
400
- gt
401
- ]), E(() => {
402
- const t = N.current;
404
+ N,
405
+ ut,
406
+ ft
407
+ ]), $(() => {
408
+ const t = k.current;
403
409
  if (!t || e.length === 0) return;
404
410
  const a = e.length === 1;
405
411
  let r;
@@ -410,102 +416,90 @@ function ie({
410
416
  }
411
417
  if (!r) return;
412
418
  const l = (s) => {
413
- const { time: c = r, seriesData: u, point: L } = s || {}, g = Array.from(R.current.values());
419
+ const { time: c = r, seriesData: f, point: L } = s || {}, m = Array.from(R.current.values());
414
420
  if (!L || !c) {
415
421
  const V = /* @__PURE__ */ new Map();
416
422
  for (const d of e)
417
423
  d.data.length > 0 && V.set(d.label, d.data[d.data.length - 1]);
418
- if (ot(V.size > 0 ? V : void 0), a || k)
424
+ if (U(V.size > 0 ? V : void 0), a || N)
419
425
  A(null);
420
- else if (g[0] && r) {
421
- const x = t.timeScale().timeToCoordinate(r), b = e[0];
426
+ else if (m[0] && r) {
427
+ const S = t.timeScale().timeToCoordinate(r), b = e[0];
422
428
  if (b.data.length > 0) {
423
- const p = b.data[b.data.length - 1].value, S = g[0].priceToCoordinate(p);
424
- x !== null && S !== null && A({ x, y: S });
429
+ const v = b.data[b.data.length - 1].value, C = m[0].priceToCoordinate(v);
430
+ S !== null && C !== null && A({ x: S, y: C });
425
431
  }
426
432
  }
427
433
  return;
428
434
  }
429
435
  const P = /* @__PURE__ */ new Map();
430
- let T;
436
+ let F;
431
437
  for (let V = 0; V < e.length; V++) {
432
- const d = e[V], x = g[V];
433
- if (!x) continue;
434
- const b = u?.get(x), p = b && "value" in b ? b.value : void 0;
435
- let S;
436
- if (p !== void 0)
437
- S = p;
438
- else {
439
- const I = Number(c), D = d.data;
440
- let G = 0;
441
- for (let B = D.length - 1; B >= 0; B--)
442
- if (Number(D[B].time) <= I) {
443
- G = D[B].value;
444
- break;
445
- }
446
- S = G;
447
- }
448
- V === 0 && (T = S), P.set(d.label, { value: S, time: c });
438
+ const d = e[V], S = m[V];
439
+ if (!S) continue;
440
+ const b = f?.get(S), v = b && "value" in b ? b.value : void 0;
441
+ let C;
442
+ v !== void 0 ? C = v : a ? C = d.data[d.data.length - 1]?.value ?? 0 : C = Wt(d.data, Number(c)), V === 0 && (F = C), P.set(d.label, { value: C, time: c });
449
443
  }
450
- if (ot(P), T !== void 0 && g[0]) {
451
- const d = t.timeScale().timeToCoordinate(c), x = g[0].priceToCoordinate(T);
452
- if (d !== null && x !== null) {
453
- const b = $.current;
444
+ if (U(P), F !== void 0 && m[0]) {
445
+ const d = t.timeScale().timeToCoordinate(c), S = m[0].priceToCoordinate(F);
446
+ if (d !== null && S !== null) {
447
+ const b = z.current;
454
448
  if (b) {
455
- const p = b.querySelector(
449
+ const v = b.querySelector(
456
450
  ".LightweightChart"
457
451
  );
458
- if (p) {
459
- const S = p.getBoundingClientRect(), I = b.getBoundingClientRect(), D = d + (S.left - I.left), G = x + (S.top - I.top);
460
- A({ x: D, y: G });
452
+ if (v) {
453
+ const C = v.getBoundingClientRect(), D = b.getBoundingClientRect(), tt = d + (C.left - D.left), et = S + (C.top - D.top);
454
+ A({ x: tt, y: et });
461
455
  } else
462
- A({ x: d, y: x });
456
+ A({ x: d, y: S });
463
457
  } else
464
- A({ x: d, y: x });
458
+ A({ x: d, y: S });
465
459
  } else
466
460
  A(null);
467
461
  } else
468
462
  A(null);
469
463
  };
470
- return t.subscribeCrosshairMove(l), y && t.subscribeClick(l), !a && !k && requestAnimationFrame(() => {
464
+ return t.subscribeCrosshairMove(l), y && t.subscribeClick(l), !a && !N && requestAnimationFrame(() => {
471
465
  const s = Array.from(R.current.values());
472
466
  if (s[0] && r && e[0]?.data.length > 0) {
473
- const u = t.timeScale().timeToCoordinate(r), L = e[0].data[e[0].data.length - 1].value, g = s[0].priceToCoordinate(L);
474
- u !== null && g !== null && A({ x: u, y: g });
467
+ const f = t.timeScale().timeToCoordinate(r), L = e[0].data[e[0].data.length - 1].value, m = s[0].priceToCoordinate(L);
468
+ f !== null && m !== null && A({ x: f, y: m });
475
469
  }
476
470
  }), () => {
477
471
  t.unsubscribeCrosshairMove(l), y && t.unsubscribeClick(l);
478
472
  };
479
- }, [e, k, y]), E(() => {
480
- const t = N.current;
473
+ }, [e, N, y]), $(() => {
474
+ const t = k.current;
481
475
  if (!t || e.length === 0) return;
482
476
  const a = t.timeScale(), r = () => {
483
- if (!tt.current) return;
477
+ if (!J.current) return;
484
478
  const l = a.getVisibleRange();
485
479
  if (!l) return;
486
- const s = Number(l.from), c = Number(l.to), u = [];
480
+ const s = Number(l.from), c = Number(l.to), f = [];
487
481
  for (const L of e)
488
- for (const g of L.data) {
489
- const P = Number(g.time);
490
- P >= s && P <= c && u.push(g.value);
482
+ for (const m of L.data) {
483
+ const P = Number(m.time);
484
+ P >= s && P <= c && f.push(m.value);
491
485
  }
492
- u.length > 0 && tt.current(u);
486
+ f.length > 0 && J.current(f);
493
487
  };
494
488
  return a.subscribeVisibleLogicalRangeChange(r), () => {
495
489
  a.unsubscribeVisibleLogicalRangeChange(
496
490
  r
497
491
  );
498
492
  };
499
- }, [e]), E(() => {
500
- const t = N.current, a = Array.from(R.current.values()), r = [];
501
- if (t && a.length > 0 && C) {
493
+ }, [e]), $(() => {
494
+ const t = k.current, a = Array.from(R.current.values()), r = [];
495
+ if (t && a.length > 0 && x) {
502
496
  const l = Gt(), s = a[0];
503
- for (const c of C) {
504
- const u = new jt(t, s, c.xCoordinate, {
497
+ for (const c of x) {
498
+ const f = new jt(t, s, c.xCoordinate, {
505
499
  ...l,
506
500
  ...c.options || {}
507
501
  });
508
- s.attachPrimitive(u), r.push(u);
502
+ s.attachPrimitive(f), r.push(f);
509
503
  }
510
504
  }
511
505
  return () => {
@@ -515,15 +509,15 @@ function ie({
515
509
  l.detachPrimitive(s);
516
510
  }
517
511
  };
518
- }, [C]), E(() => {
519
- const t = N.current;
520
- if (!t || !C?.length) {
521
- pt([]);
512
+ }, [x]), $(() => {
513
+ const t = k.current;
514
+ if (!t || !x?.length) {
515
+ ht([]);
522
516
  return;
523
517
  }
524
518
  const a = () => {
525
- const s = t.timeScale(), c = C.map((u) => s.timeToCoordinate(u.xCoordinate) ?? null);
526
- pt(c);
519
+ const s = t.timeScale(), c = x.map((f) => s.timeToCoordinate(f.xCoordinate) ?? null);
520
+ ht(c);
527
521
  };
528
522
  a();
529
523
  const r = t.timeScale(), l = () => {
@@ -532,76 +526,76 @@ function ie({
532
526
  return r.subscribeVisibleLogicalRangeChange(l), () => {
533
527
  r.unsubscribeVisibleLogicalRangeChange(l);
534
528
  };
535
- }, [C]);
536
- const q = e.length === 1, vt = lt.useMemo(() => {
537
- if (q && e.length > 0) {
529
+ }, [x]);
530
+ const W = e.length === 1, pt = at.useMemo(() => {
531
+ if (W && e.length > 0) {
538
532
  const t = e[0];
539
533
  if (t.data.length > 0)
540
534
  return t.data[t.data.length - 1];
541
535
  }
542
- }, [q, e]);
543
- return /* @__PURE__ */ X(
536
+ }, [W, e]);
537
+ return /* @__PURE__ */ H(
544
538
  "div",
545
539
  {
546
- ref: $,
547
- className: ut(
540
+ ref: z,
541
+ className: ct(
548
542
  "relative z-[1] w-full h-full overflow-hidden p-0",
549
- v
543
+ p
550
544
  ),
551
545
  children: [
552
- Q != null && Q !== !1 && q ? /* @__PURE__ */ h("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ h("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: Q }) }) : kt && q && vt && /* @__PURE__ */ h(
546
+ Z != null && Z !== !1 && W ? /* @__PURE__ */ h("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ h("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: Z }) }) : yt && W && pt && /* @__PURE__ */ h(
553
547
  Ot,
554
548
  {
555
- point: vt,
556
- xMeasureUnit: f,
549
+ point: pt,
550
+ xMeasureUnit: g,
557
551
  yMeasureUnit: w,
558
- decimals: J
552
+ decimals: q
559
553
  }
560
554
  ),
561
- dt && bt && /* @__PURE__ */ h(
555
+ dt && mt && /* @__PURE__ */ h(
562
556
  Yt,
563
557
  {
564
558
  points: dt,
565
- xMeasureUnit: f,
559
+ xMeasureUnit: g,
566
560
  yMeasureUnit: w,
567
561
  series: e,
568
- position: bt,
569
- containerRef: $,
570
- decimals: J
562
+ position: mt,
563
+ containerRef: z,
564
+ decimals: q
571
565
  }
572
566
  ),
573
- m && /* @__PURE__ */ h(_t, { series: e, onUnselect: F }),
574
- C && C.length > 0 && ht.length === C.length && /* @__PURE__ */ h(
567
+ u && /* @__PURE__ */ h(Xt, { series: e, onUnselect: T }),
568
+ x && x.length > 0 && bt.length === x.length && /* @__PURE__ */ h(
575
569
  "div",
576
570
  {
577
571
  className: "absolute inset-0 z-[5] pointer-events-none",
578
572
  "aria-hidden": !0,
579
- children: C.map((t, a) => {
580
- const r = ht[a], l = t.options ?? {}, s = l.showLabel !== !1;
573
+ children: x.map((t, a) => {
574
+ const r = bt[a], l = t.options ?? {}, s = l.showLabel !== !1;
581
575
  if (r === null || !s) return null;
582
- const { labelText: c, valueStr: u } = Ht(
576
+ const { labelText: c, valueStr: f } = Ht(
583
577
  l,
584
578
  w,
585
- J
579
+ q
586
580
  );
587
- if (!(c || u)) return null;
588
- const g = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", P = l.labelTextColor ?? "hsl(var(--foreground))", T = `${String(t.xCoordinate)}-${c}`;
589
- return /* @__PURE__ */ X(
581
+ if (!(c || f)) return null;
582
+ const m = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", P = l.labelTextColor ?? "hsl(var(--foreground))", F = `${String(t.xCoordinate)}-${c}`;
583
+ return /* @__PURE__ */ H(
590
584
  "div",
591
585
  {
592
586
  className: "absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
593
587
  style: {
594
588
  left: r,
595
589
  transform: "translateX(-50%)",
596
- backgroundColor: g,
590
+ backgroundColor: m,
597
591
  color: P
598
592
  },
599
593
  children: [
600
594
  c && /* @__PURE__ */ h("span", { className: "block", children: c }),
601
- u && /* @__PURE__ */ h("span", { className: ut("block", c && "mt-0.5"), children: u })
595
+ f && /* @__PURE__ */ h("span", { className: ct("block", c && "mt-0.5"), children: f })
602
596
  ]
603
597
  },
604
- T
598
+ F
605
599
  );
606
600
  })
607
601
  }
@@ -609,7 +603,7 @@ function ie({
609
603
  /* @__PURE__ */ h(
610
604
  "div",
611
605
  {
612
- ref: et,
606
+ ref: Q,
613
607
  className: "LightweightChart w-full h-full overflow-hidden"
614
608
  }
615
609
  )
@@ -617,18 +611,18 @@ function ie({
617
611
  }
618
612
  );
619
613
  }
620
- function _t({
614
+ function Xt({
621
615
  series: e,
622
- onUnselect: v
616
+ onUnselect: p
623
617
  }) {
624
- return /* @__PURE__ */ h("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: e.map((m, F) => {
625
- const f = yt(F), w = (m.lineColor ?? m.color) || f.line, W = m.data.length === 0;
626
- return /* @__PURE__ */ X(
618
+ return /* @__PURE__ */ h("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: e.map((u, T) => {
619
+ const g = Vt(T), w = (u.lineColor ?? u.color) || g.line, Y = u.data.length === 0;
620
+ return /* @__PURE__ */ H(
627
621
  "div",
628
622
  {
629
- className: ut(
623
+ className: ct(
630
624
  "flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
631
- W && "opacity-50"
625
+ Y && "opacity-50"
632
626
  ),
633
627
  children: [
634
628
  /* @__PURE__ */ h(
@@ -638,20 +632,20 @@ function _t({
638
632
  style: { backgroundColor: w }
639
633
  }
640
634
  ),
641
- /* @__PURE__ */ X("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
642
- m.label,
643
- W && " (no data)"
635
+ /* @__PURE__ */ H("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
636
+ u.label,
637
+ Y && " (no data)"
644
638
  ] }),
645
- v && /* @__PURE__ */ h(
639
+ p && /* @__PURE__ */ h(
646
640
  "button",
647
641
  {
648
642
  type: "button",
649
- onClick: (C) => {
650
- C.stopPropagation(), v(m.label);
643
+ onClick: (x) => {
644
+ x.stopPropagation(), p(u.label);
651
645
  },
652
646
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
653
- "aria-label": `Remove ${m.label}`,
654
- children: /* @__PURE__ */ X(
647
+ "aria-label": `Remove ${u.label}`,
648
+ children: /* @__PURE__ */ H(
655
649
  "svg",
656
650
  {
657
651
  xmlns: "http://www.w3.org/2000/svg",
@@ -676,13 +670,14 @@ function _t({
676
670
  )
677
671
  ]
678
672
  },
679
- m.label
673
+ u.label
680
674
  );
681
675
  }) });
682
676
  }
683
677
  export {
684
- ct as DEFAULT_SERIES_COLORS,
685
- ie as Graph,
686
- yt as getSeriesColorPalette,
678
+ st as DEFAULT_SERIES_COLORS,
679
+ se as Graph,
680
+ Vt as getSeriesColorPalette,
681
+ Wt as getStepForwardValue,
687
682
  Ht as getVerticalLineTooltipContent
688
683
  };
@@ -32,6 +32,12 @@ export declare function getVerticalLineTooltipContent(opts: VerticalLineOptions,
32
32
  labelText: string;
33
33
  valueStr: string;
34
34
  };
35
+ /**
36
+ * Step-forward interpolation: find the last data point with
37
+ * `time <= crosshairTime` and return its value.
38
+ * Returns 0 when the crosshair is before the first data point (no history).
39
+ */
40
+ export declare function getStepForwardValue(data: ReadonlyArray<Point>, crosshairTime: number): number;
35
41
  /**
36
42
  * Palette ordered for maximum contrast; first color is the original teal.
37
43
  * Greens/teals are spread out so that when only a subset of series is visible,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/ui-kit",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Internal UI components",
5
5
  "repository": "https://github.com/gearbox-protocol/ui-kit",
6
6
  "license": "MIT",