@gearbox-protocol/ui-kit 3.0.0 → 3.0.1

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