@gearbox-protocol/ui-kit 4.5.1 → 4.5.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 C=require("react/jsx-runtime"),$=require("lightweight-charts"),g=require("react"),Y=require("./colors.cjs"),ct=require("../../hooks/use-media-query.cjs"),Q=require("../../utils/cn.cjs"),I=require("./default-config.cjs"),re=require("./formatters.cjs"),ut=require("./graph-current-value.cjs"),ft=require("./graph-tooltip.cjs"),ht=require("./plugins/vertical-line.cjs"),dt=require("./series-config.cjs"),Ke=require("./series-palette.cjs"),qe=require("./y-axis-scale.cjs");function pt(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const u=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(r,l,u.get?u:{enumerable:!0,get:()=>e[l]})}}return r.default=e,Object.freeze(r)}const ye=pt(g);function oe(e){return e.id??e.label}function $e({lastIndex:e,width:r,padLeft:l,padRight:u,paddingPx:h=I.AXIS_TIME_EDGE_PADDING_PX}){if(e<0)return null;const f=(l||u)&&r>0?h*Math.max(e,1)/r:0;return{from:l&&f!==0?-f:0,to:u?e+f:e}}function We(e,r,l){if(!l)return e.values().next().value;const u=e.get(l);if(u)return u;const h=r.find(f=>f.id===l||f.label===l);return h?e.get(oe(h)):void 0}class gt{_yTop;_yBottom;_color;constructor(r,l,u){this._yTop=r,this._yBottom=l,this._color=u}draw(r){r.useBitmapCoordinateSpace(l=>{const u=l.context,h=l.verticalPixelRatio,f=this._yTop===null?0:this._yTop*h,x=this._yBottom===null?l.bitmapSize.height:this._yBottom*h,R=Math.min(f,x),D=Math.max(f,x);u.fillStyle=this._color,u.fillRect(0,R,l.bitmapSize.width,D-R)})}}class mt{_source;_yTop=null;_yBottom=null;constructor(r){this._source=r}update(){const r=this._source.series;this._yTop=this._source.priceTop===void 0?null:r.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:r.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new gt(this._yTop,this._yBottom,this._source.color)}}class bt{series;priceTop;priceBottom;color;_paneViews;constructor(r,l,u,h){this.series=r,this.priceTop=l,this.priceBottom=u,this.color=h,this._paneViews=[new mt(this)]}updateAllViews(){for(const r of this._paneViews)r.update()}paneViews(){return this._paneViews}}function St(e,r){switch(e){case $.LineStyle.Dotted:return[r,r];case $.LineStyle.Dashed:return[2*r,2*r];case $.LineStyle.LargeDashed:return[6*r,6*r];case $.LineStyle.SparseDotted:return[r,4*r];default:return[]}}class Ct{_y;_color;_lineWidth;_lineStyle;constructor(r,l,u,h){this._y=r,this._color=l,this._lineWidth=u,this._lineStyle=h}draw(r){r.useBitmapCoordinateSpace(l=>{if(this._y===null)return;const u=l.context,h=l.verticalPixelRatio,f=Math.max(1,Math.round(this._lineWidth*h)),x=Math.round(this._y*h);u.save(),u.strokeStyle=this._color,u.lineWidth=f,u.setLineDash(St(this._lineStyle,f)),u.beginPath(),u.moveTo(0,x),u.lineTo(l.bitmapSize.width,x),u.stroke(),u.restore()})}}class xt{_source;_y=null;constructor(r){this._source=r}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new Ct(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class vt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(r,l,u,h,f){this.series=r,this.price=l,this.color=u,this.lineWidth=h,this.lineStyle=f,this._paneViews=[new xt(this)]}updateAllViews(){for(const r of this._paneViews)r.update()}paneViews(){return this._paneViews}}function He(e,r,l){const u=e.labelText??"",h=e.value,f=h===void 0?"":typeof h=="number"?r==="$"?`$${re.formatExactValue(h,void 0,l)}`:r==="%"?`${re.formatExactValue(h,void 0,l)}%`:re.formatExactValue(h,r!=="none"&&r!=="%"&&r!=="$"&&!re.isRatioUnit(r)?r:void 0,l):String(h);return{labelText:u,valueStr:f}}const _e=4;function Oe(e,r,l){const u={left:e,transform:"translateX(-50%)"};if(r<=0||!l||l<=0)return u;const h=l/2,f=_e+h,x=r-_e-h;return x<f?{left:r/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,f),x),transform:"translateX(-50%)"}}function Ze(e,r){for(let l=e.length-1;l>=0;l--)if(Number(e[l].time)<=r)return e[l].value;return 0}function yt({series:e,className:r,showLegend:l=!1,onUnselectSeries:u,xMeasureUnit:h="time",yMeasureUnit:f="token",optionsOverrides:x,verticalLineOptions:R,priceLineOptions:D,zoneOptions:F,currentValueDecimals:se,useSharedPriceScale:H=!1,dualYAxis:z=!1,defaultVisiblePriceScaleId:we="right",showCurrentValue:Qe=!0,graphTitle:pe,yScaleMin:Pe,yScaleMinMultiple:Re,visibleTimeFrom:le,disableZoom:Te=!1,hideDefaultTooltip:ge=!1}){const A=g.useRef(null),N=g.useRef(new Map),me=g.useRef(!1),Le=g.useRef(!0),Ne=g.useRef([]),ae=g.useRef(0),j=g.useRef(null),be=g.useRef(null),Ve=g.useRef(null),T=ct.useIsMobile(),ce=ye.useMemo(()=>e.flatMap(t=>t.data),[e]),Je=ye.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[ke,Se]=g.useState(()=>{if(!Je)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}),[Ee,J]=g.useState(null),[Ie,Me]=g.useState([]),[Ue,De]=g.useState(0),Ae=g.useRef(new Map),[et,tt]=g.useState({}),[U,ot]=g.useState(0);g.useEffect(()=>{const t=()=>{try{if(j.current&&De(j.current.clientWidth),A.current&&j.current){const s=j.current.clientWidth,c=j.current.clientHeight;A.current.resize(s,c);try{ae.current=A.current.paneSize().height}catch{}}}catch{}},a=j.current,n=a?new ResizeObserver(t):null;return Ve.current=n,a&&n?.observe(a),()=>{a&&n?.unobserve(a),n?.disconnect(),Ve.current=null}},[]),g.useEffect(()=>{if(!be.current||me.current)return;const t=I.getDefaultOptions(),a=Y.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),n=$.createChart(be.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:a},...T&&{crosshair:{...t.crosshair,mode:$.CrosshairMode.Magnet}}});A.current=n,me.current=!0;try{ae.current=n.paneSize().height}catch{ae.current=0}return ot(s=>s+1),()=>{n.remove(),A.current=null,me.current=!1,N.current.clear()}},[T]),g.useEffect(()=>{const t=A.current;t&&t.applyOptions(Te?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[U,Te]),g.useEffect(()=>{const t=A.current;!t||!x||t.applyOptions(x)},[U,x]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const n=e.filter(i=>i.data.length>0).length<=1?Pe:Re,s=h==="time"?re.getXFormatters(h,ce):re.getXFormatters(h),c=new Map(dt.resolvePriceScaleSides(e).map(({series:i,side:o})=>[i.label,o])),p=(i,o,d)=>{const{formatter:k,tickmarksFormatter:E,updateVisibleRange:B}=re.createAdaptiveYAxisFormatter(i,o,{yScaleMin:n});return{formatter:k,tickmarksFormatter:E,updateVisibleRange:B,labels:d}},m=[];if(z)for(const i of["left","right"]){const o=new Set,d=[];let k=f;for(const E of e)if(E.data.length!==0&&c.get(E.label)===i){o.size===0&&E.yMeasureUnit&&(k=E.yMeasureUnit),o.add(E.label);for(const B of E.data)d.push(B.value)}o.size>0&&m.push(p(d,k,o))}else{const i=ce.map(d=>d.value),o=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));m.push(p(i,f,o))}Ne.current=m;const _=new Map;for(const i of m)for(const o of i.labels)_.set(o,i);const w=I.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:i=>s.timeFormatter(parseFloat(i),void 0)},timeScale:{...w.timeScale||{},...x?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const v=!z&&e.length>1&&!H,G=z?T:e.length>1&&!H||T,V=Y.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...z&&{defaultVisiblePriceScaleId:we},leftPriceScale:{...w.leftPriceScale||{},...x?.leftPriceScale,visible:z&&!T,textColor:V},rightPriceScale:{...w.rightPriceScale||{},...x?.rightPriceScale,visible:z?!T:!G,textColor:V}});const ee=new Set(N.current.keys()),q=new Set(e.map(oe));for(const i of ee)if(!q.has(i)){const o=N.current.get(i);o&&(t.removeSeries(o),N.current.delete(i))}const b=I.getDefaultSeries(),M=[];let L=0;const W=e.find(i=>i.data.length>0),y=new Map;if(D&&D.length>0)for(const i of D){if(!Number.isFinite(i.price))continue;const o=i.seriesLabel??W?.label;if(!o)continue;const d=y.get(o)??[];d.push(i.price),y.set(o,d)}if(F&&F.length>0)for(const i of F){const o=i.seriesLabel??W?.label;if(!o)continue;const d=y.get(o)??[];Number.isFinite(i.priceTop)&&d.push(i.priceTop),Number.isFinite(i.priceBottom)&&d.push(i.priceBottom),y.set(o,d)}for(let i=0;i<e.length;i++){const o=e[i],d=oe(o),k=Ke.getSeriesColorPalette(i),E=o.lineColor??o.color??k.line;let B,Z;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)B=o.topColor,Z=o.bottomColor;else if(o.topColor){const S=Y.generateColorsFromBase(E);B=o.topColor,Z=S.bottomColor}else if(o.bottomColor)B=Y.generateColorsFromBase(E).topColor,Z=o.bottomColor;else{const S=Y.generateColorsFromBase(E);B=S.topColor,Z=S.bottomColor}else B=o.topColor||k.top,Z=o.bottomColor||k.bottom;if(o.data.length===0){const S=N.current.get(d);S&&(t.removeSeries(S),N.current.delete(d));continue}const ue=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,he=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,rt=ue<0,nt=o.data.some(S=>S.value===0),it=!rt&&nt,Be=qe.pickMinMove(he-ue),Fe=z?o.priceScaleId??(L===0?"left":"right"):H||!v||L===0?"right":`scale-${L}`;v&&M.push({priceScaleId:Fe||"right",seriesIndex:L});const Ce=(H||!v)&&n!==void 0&&typeof n=="number",st=y.get(o.label)??[],lt=S=>{const P=S();if(P?.priceRange){Ce&&(P.priceRange.minValue=n);for(const K of st)K<P.priceRange.minValue&&(P.priceRange.minValue=K),K>P.priceRange.maxValue&&(P.priceRange.maxValue=K);const ie=Ce?n:it&&P.priceRange.minValue>=0?0:void 0,de=ae.current>0?ae.current:j.current?.clientHeight??0;if(de>0){const K=qe.niceAxisRange({min:P.priceRange.minValue,max:P.priceRange.maxValue,floor:ie,scaleHeightPx:de,fontSizePx:I.AXIS_FONT_SIZE,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,minMove:Be,edgePaddingPx:I.AXIS_EDGE_LABEL_PADDING_PX,edgePaddingTopPx:I.AXIS_TOP_LABEL_PADDING_PX});P.priceRange.minValue=K.min,P.priceRange.maxValue=K.max}P.margins={above:I.AXIS_TOP_LABEL_PADDING_PX,below:I.AXIS_EDGE_LABEL_PADDING_PX}}return P},ze=_.get(o.label)??m[0],Xe=ze.formatter,at=ze.tickmarksFormatter,xe={lineColor:E,topColor:B,bottomColor:Z,priceScaleId:Fe,...o.seriesType==="line"&&{lineStyle:o.lineStyle??$.LineStyle.Solid},priceFormat:{type:"custom",minMove:Be,formatter:Ce&&typeof n=="number"?S=>Xe(S<n?n:S):Xe,tickmarksFormatter:at},autoscaleInfoProvider:lt},Ge=o.seriesType==="line";let X=N.current.get(d);const ne=o.data.map(S=>({...S,time:S.time}));if(le!==void 0&&ne.length>0&&Number(ne[0].time)>le){const S=Number(ne[0].time),P=S-le,ie=86400,de=P>180*ie?7*ie:P>30*ie?ie:6*3600,K=[];for(let ve=le;ve<S;ve+=de)K.push({time:ve});ne.unshift(...K)}X&&X.seriesType()!==(Ge?"Line":"Area")&&(t.removeSeries(X),N.current.delete(d),X=void 0),X?(X.applyOptions(xe),X.setData(ne)):(Ge?X=t.addSeries($.LineSeries,{...b,...xe}):X=t.addSeries($.AreaSeries,{...b,...xe}),X.setData(ne),N.current.set(d,X)),L++}if(z)try{const i=t.priceScale("left"),o=t.priceScale("right"),d={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:V,...x?.rightPriceScale};i?.applyOptions(d),o?.applyOptions(d)}catch{}else if(v&&M.length>0)for(const i of M)try{const o=t.priceScale(i.priceScaleId);o&&o.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:V})}catch(o){console.warn(`Failed to configure price scale ${i.priceScaleId} for series ${i.seriesIndex}:`,o)}else if(!v)try{const i=t.priceScale("right");i&&i.applyOptions({visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:V,...x?.rightPriceScale})}catch{}n!==void 0&&!T&&(H||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}});let O=0;if(ce.length>0){const i=ce.map(d=>Number(d.time)).filter(d=>Number.isFinite(d)),o=new Set(i).size-1;if(o>=0){const d=()=>{const k=t.timeScale();if(h!=="time"){k.applyOptions({fixLeftEdge:!0,fixRightEdge:!0}),k.setVisibleLogicalRange({from:0,to:o});return}const E=z&&!T,B=z?!T:!G,Z=!E,ue=!B;k.applyOptions({fixLeftEdge:!Z,fixRightEdge:!ue}),O=requestAnimationFrame(()=>{const he=$e({lastIndex:o,width:k.width(),padLeft:Z,padRight:ue});try{he&&k.setVisibleLogicalRange(he)}catch{k.fitContent()}})};try{d()}catch{try{t.timeScale().fitContent(),d()}catch{}}}}Le.current&&(Le.current=!1),x&&t.applyOptions(x);const te=new Map;for(const i of e)i.data.length>0&&te.set(i.label,i.data[i.data.length-1]);return Se(te.size>0?te:void 0),()=>cancelAnimationFrame(O)},[U,e,ce,h,f,T,H,z,we,Pe,Re,le,D,F,x]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=e.length===1;let n;for(const c of e)if(c.data.length>0){n=c.data[c.data.length-1].time;break}if(!n)return;const s=c=>{const{time:p=n,seriesData:m,point:_}=c||{},w=e[0],v=w?N.current.get(oe(w)):void 0;if(!_||!p){const q=new Map;for(const b of e)b.data.length>0&&q.set(b.label,b.data[b.data.length-1]);if(Se(q.size>0?q:void 0),a||H||ge)J(null);else if(v&&n){const b=e[0];if(b&&b.data.length>0){const L=t.timeScale().timeToCoordinate(n),W=b.data[b.data.length-1].value,y=v.priceToCoordinate(W);L!==null&&y!==null&&J({x:L,y})}}return}const G=new Map;let V,ee=v;for(let q=0;q<e.length;q++){const b=e[q],M=N.current.get(oe(b));if(!M)continue;const L=m?.get(M),W=L&&"value"in L?L.value:void 0;let y;if(W!==void 0)y=W;else if(a){const O=Number(p),te=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;O<te?y=Number.NaN:y=b.data[b.data.length-1]?.value??0}else{const O=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;if(Number(p)<O)continue;y=Ze(b.data,Number(p))}Number.isNaN(y)||(V===void 0&&(V=y,ee=M),G.set(b.label,{value:y,time:p}))}if(Se(G),V!==void 0&&ee){const b=t.timeScale().timeToCoordinate(p),M=ee.priceToCoordinate(V);if(b!==null&&M!==null){const L=j.current;if(L){const W=L.querySelector(".LightweightChart");if(W){const y=W.getBoundingClientRect(),O=L.getBoundingClientRect(),te=b+(y.left-O.left),i=M+(y.top-O.top);J({x:te,y:i})}else J({x:b,y:M})}else J({x:b,y:M})}else J(null)}else J(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!a&&!H&&!ge&&requestAnimationFrame(()=>{const c=e[0],p=c?N.current.get(oe(c)):void 0;if(p&&n&&c.data.length>0){const _=t.timeScale().timeToCoordinate(n),w=c.data[c.data.length-1].value,v=p.priceToCoordinate(w);_!==null&&v!==null&&J({x:_,y:v})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,H,T,ge]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=t.timeScale(),n=()=>{const s=Ne.current;if(s.length===0)return;const c=a.getVisibleRange();if(!c)return;const p=Number(c.from),m=Number(c.to);for(const _ of s){const w=[];for(const v of e)if(_.labels.has(v.label))for(const G of v.data){const V=Number(G.time);V>=p&&V<=m&&w.push(G.value)}w.length>0&&_.updateVisibleRange(w)}};return a.subscribeVisibleLogicalRangeChange(n),()=>{a.unsubscribeVisibleLogicalRangeChange(n)}},[e]),g.useEffect(()=>{const t=A.current,a=Array.from(N.current.values()),n=[];if(t&&a.length>0&&R){const s=I.getDefaultVerticalLine(),c=a[0];for(const p of R){const m={...s,...p.options||{}};m.color&&(m.color=Y.resolveCSSColor(m.color,m.color));const _=new ht.VertLine(t,c,p.xCoordinate,m);c.attachPrimitive(_),n.push(_)}}return()=>{if(a.length>0){const s=a[0];for(const c of n)try{s.detachPrimitive(c)}catch{}}}},[R,e,U]),g.useEffect(()=>{const t=[],a=[];if(D&&D.length>0){const n=Y.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of D){if(!Number.isFinite(s.price))continue;const c=We(N.current,e,s.seriesLabel);if(!c)continue;const p=s.color?Y.resolveCSSColor(s.color,s.color):n,m=s.lineWidth??1,_=s.lineStyle??$.LineStyle.Dashed,w=c.createPriceLine({price:s.price,color:p,lineWidth:m,lineStyle:_,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:c,line:w});const v=new vt(c,s.price,p,m,_);c.attachPrimitive(v),a.push({series:c,primitive:v})}}return()=>{for(const{series:n,primitive:s}of a)try{n.detachPrimitive(s)}catch{}for(const{series:n,line:s}of t)try{n.removePriceLine(s)}catch{}}},[D,e,U]),g.useEffect(()=>{const t=[];if(F&&F.length>0){const a="rgba(239, 68, 68, 0.12)";for(const n of F){const s=We(N.current,e,n.seriesLabel);if(!s)continue;const c=n.color?Y.resolveCSSColor(n.color,a):a,p=new bt(s,n.priceTop,n.priceBottom,c);s.attachPrimitive(p),t.push({series:s,zone:p})}}return()=>{for(const{series:a,zone:n}of t)try{a.detachPrimitive(n)}catch{}}},[F,e,U]),g.useEffect(()=>{const t=A.current;if(!t||!R?.length){Me([]);return}const a=()=>{const c=t.timeScale(),p=R.map(m=>c.timeToCoordinate(m.xCoordinate)??null);Me(p),j.current&&De(j.current.clientWidth)};a();const n=t.timeScale(),s=()=>{a()};return n.subscribeVisibleLogicalRangeChange(s),()=>{n.unsubscribeVisibleLogicalRangeChange(s)}},[R,e,U]),g.useLayoutEffect(()=>{tt(t=>{const a={};let n=!1;for(const[s,c]of Ae.current){if(!c)continue;const p=c.offsetWidth;a[s]=p,t[s]!==p&&(n=!0)}return Object.keys(t).length!==Object.keys(a).length&&(n=!0),n?a:t})});const fe=e.length===1,je=ye.useMemo(()=>{if(fe&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[fe,e]);return C.jsxs("div",{ref:j,className:Q.cn("relative z-[1] w-full h-full overflow-hidden p-0",r),children:[pe!=null&&pe!==!1&&fe?C.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:C.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:pe})}):Qe&&fe&&je&&C.jsx(ut.GraphCurrentValue,{point:je,xMeasureUnit:h,yMeasureUnit:f,decimals:se}),ke&&Ee&&C.jsx(ft.GraphTooltip,{points:ke,xMeasureUnit:h,yMeasureUnit:f,series:e,position:Ee,containerRef:j,decimals:se}),l&&C.jsx(Ye,{series:e,onUnselect:u}),R&&R.length>0&&Ie.length===R.length&&C.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:R.map((t,a)=>{const n=Ie[a],s=t.options??{};if(n===null)return null;const{labelText:c,valueStr:p}=He(s,f,se),m=s.tooltipText??"";if(!(c||p||m))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",v=s.labelTextColor??"hsl(var(--foreground))",G=`${String(t.xCoordinate)}-${c}-${m}`,V=Oe(n,Ue,et[a]);return C.jsxs("div",{ref:ee=>{Ae.current.set(a,ee)},className:Q.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",m&&"pointer-events-auto cursor-default"),style:{...V,backgroundColor:w,color:v},children:[c&&C.jsx("span",{className:"block",children:c}),p&&C.jsx("span",{className:Q.cn("block",c&&"mt-0.5"),children:p}),m&&C.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:m})]},G)})}),C.jsx("div",{ref:be,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ye({series:e,markers:r,onUnselect:l,inline:u=!1}){const h=e.every(f=>f.data.length===0);return C.jsxs("div",{className:Q.cn("flex flex-wrap",u?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:[e.map((f,x)=>{const R=Ke.getSeriesColorPalette(x),D=(f.lineColor??f.color)||R.line,F=!h&&f.data.length===0;return C.jsxs("div",{className:Q.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",F&&"opacity-50"),children:[C.jsx("div",{className:Q.cn("shrink-0",u?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:D}}),C.jsxs("span",{className:Q.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:[f.label,F&&" (no data)"]}),l&&C.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),l(f.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 ${f.label}`,children:C.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:[C.jsx("title",{children:"Close"}),C.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),C.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f.id??f.label)}),r?.map(f=>C.jsxs("div",{className:Q.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border"),children:[C.jsx("div",{className:"h-3 w-0.5 shrink-0",style:{backgroundColor:f.color}}),C.jsx("span",{className:Q.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:f.label})]},f.id))]})}exports.Graph=yt;exports.GraphLegend=Ye;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=_e;exports.getStepForwardValue=Ze;exports.getVerticalLineLabelStyle=Oe;exports.getVerticalLineTooltipContent=He;exports.seriesIdentity=oe;exports.visibleLogicalRangeFor=$e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),$=require("lightweight-charts"),g=require("react"),Y=require("./colors.cjs"),ct=require("../../hooks/use-media-query.cjs"),Q=require("../../utils/cn.cjs"),I=require("./default-config.cjs"),re=require("./formatters.cjs"),ut=require("./graph-current-value.cjs"),ft=require("./graph-tooltip.cjs"),ht=require("./plugins/vertical-line.cjs"),dt=require("./series-config.cjs"),Ke=require("./series-palette.cjs"),qe=require("./y-axis-scale.cjs");function pt(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const u=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(r,l,u.get?u:{enumerable:!0,get:()=>e[l]})}}return r.default=e,Object.freeze(r)}const ye=pt(g);function oe(e){return e.id??e.label}function $e({lastIndex:e,width:r,padLeft:l,padRight:u,paddingPx:h=I.AXIS_TIME_EDGE_PADDING_PX}){if(e<0)return null;const f=(l||u)&&r>0?h*Math.max(e,1)/r:0;return{from:l&&f!==0?-f:0,to:u?e+f:e}}function We(e,r,l){if(!l)return e.values().next().value;const u=e.get(l);if(u)return u;const h=r.find(f=>f.id===l||f.label===l);return h?e.get(oe(h)):void 0}class gt{_yTop;_yBottom;_color;constructor(r,l,u){this._yTop=r,this._yBottom=l,this._color=u}draw(r){r.useBitmapCoordinateSpace(l=>{const u=l.context,h=l.verticalPixelRatio,f=this._yTop===null?0:this._yTop*h,x=this._yBottom===null?l.bitmapSize.height:this._yBottom*h,R=Math.min(f,x),D=Math.max(f,x);u.fillStyle=this._color,u.fillRect(0,R,l.bitmapSize.width,D-R)})}}class mt{_source;_yTop=null;_yBottom=null;constructor(r){this._source=r}update(){const r=this._source.series;this._yTop=this._source.priceTop===void 0?null:r.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:r.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new gt(this._yTop,this._yBottom,this._source.color)}}class bt{series;priceTop;priceBottom;color;_paneViews;constructor(r,l,u,h){this.series=r,this.priceTop=l,this.priceBottom=u,this.color=h,this._paneViews=[new mt(this)]}updateAllViews(){for(const r of this._paneViews)r.update()}paneViews(){return this._paneViews}}function St(e,r){switch(e){case $.LineStyle.Dotted:return[r,r];case $.LineStyle.Dashed:return[2*r,2*r];case $.LineStyle.LargeDashed:return[6*r,6*r];case $.LineStyle.SparseDotted:return[r,4*r];default:return[]}}class Ct{_y;_color;_lineWidth;_lineStyle;constructor(r,l,u,h){this._y=r,this._color=l,this._lineWidth=u,this._lineStyle=h}draw(r){r.useBitmapCoordinateSpace(l=>{if(this._y===null)return;const u=l.context,h=l.verticalPixelRatio,f=Math.max(1,Math.round(this._lineWidth*h)),x=Math.round(this._y*h);u.save(),u.strokeStyle=this._color,u.lineWidth=f,u.setLineDash(St(this._lineStyle,f)),u.beginPath(),u.moveTo(0,x),u.lineTo(l.bitmapSize.width,x),u.stroke(),u.restore()})}}class xt{_source;_y=null;constructor(r){this._source=r}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new Ct(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class vt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(r,l,u,h,f){this.series=r,this.price=l,this.color=u,this.lineWidth=h,this.lineStyle=f,this._paneViews=[new xt(this)]}updateAllViews(){for(const r of this._paneViews)r.update()}paneViews(){return this._paneViews}}function He(e,r,l){const u=e.labelText??"",h=e.value,f=h===void 0?"":typeof h=="number"?r==="$"?`$${re.formatExactValue(h,void 0,l)}`:r==="%"?`${re.formatExactValue(h,void 0,l)}%`:re.formatExactValue(h,r!=="none"&&r!=="%"&&r!=="$"&&!re.isRatioUnit(r)?r:void 0,l):String(h);return{labelText:u,valueStr:f}}const _e=4;function Oe(e,r,l){const u={left:e,transform:"translateX(-50%)"};if(r<=0||!l||l<=0)return u;const h=l/2,f=_e+h,x=r-_e-h;return x<f?{left:r/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,f),x),transform:"translateX(-50%)"}}function Ze(e,r){for(let l=e.length-1;l>=0;l--)if(Number(e[l].time)<=r)return e[l].value;return 0}function yt({series:e,className:r,showLegend:l=!1,onUnselectSeries:u,xMeasureUnit:h="time",yMeasureUnit:f="token",optionsOverrides:x,verticalLineOptions:R,priceLineOptions:D,zoneOptions:F,currentValueDecimals:se,useSharedPriceScale:H=!1,dualYAxis:z=!1,defaultVisiblePriceScaleId:we="right",showCurrentValue:Qe=!0,graphTitle:pe,yScaleMin:Pe,yScaleMinMultiple:Re,visibleTimeFrom:le,disableZoom:Te=!1,hideDefaultTooltip:ge=!1}){const A=g.useRef(null),V=g.useRef(new Map),me=g.useRef(!1),Le=g.useRef(!0),Ne=g.useRef([]),ae=g.useRef(0),j=g.useRef(null),be=g.useRef(null),Ve=g.useRef(null),T=ct.useIsMobile(),ce=ye.useMemo(()=>e.flatMap(t=>t.data),[e]),Je=ye.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[ke,Se]=g.useState(()=>{if(!Je)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}),[Ee,J]=g.useState(null),[Ie,Me]=g.useState([]),[Ue,De]=g.useState(0),Ae=g.useRef(new Map),[et,tt]=g.useState({}),[U,ot]=g.useState(0);g.useEffect(()=>{const t=()=>{try{if(j.current&&De(j.current.clientWidth),A.current&&j.current){const s=j.current.clientWidth,c=j.current.clientHeight;A.current.resize(s,c);try{ae.current=A.current.paneSize().height}catch{}}}catch{}},a=j.current,n=a?new ResizeObserver(t):null;return Ve.current=n,a&&n?.observe(a),()=>{a&&n?.unobserve(a),n?.disconnect(),Ve.current=null}},[]),g.useEffect(()=>{if(!be.current||me.current)return;const t=I.getDefaultOptions(),a=Y.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),n=$.createChart(be.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:a},...T&&{crosshair:{...t.crosshair,mode:$.CrosshairMode.Magnet}}});A.current=n,me.current=!0;try{ae.current=n.paneSize().height}catch{ae.current=0}return ot(s=>s+1),()=>{n.remove(),A.current=null,me.current=!1,V.current.clear()}},[T]),g.useEffect(()=>{const t=A.current;t&&t.applyOptions(Te?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[U,Te]),g.useEffect(()=>{const t=A.current;!t||!x||t.applyOptions(x)},[U,x]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const n=e.filter(i=>i.data.length>0).length<=1?Pe:Re,s=h==="time"?re.getXFormatters(h,ce):re.getXFormatters(h),c=new Map(dt.resolvePriceScaleSides(e).map(({series:i,side:o})=>[i.label,o])),p=(i,o,d)=>{const{formatter:E,tickmarksFormatter:N,updateVisibleRange:B}=re.createAdaptiveYAxisFormatter(i,o,{yScaleMin:n});return{formatter:E,tickmarksFormatter:N,updateVisibleRange:B,labels:d}},m=[];if(z)for(const i of["left","right"]){const o=new Set,d=[];let E=f;for(const N of e)if(N.data.length!==0&&c.get(N.label)===i){o.size===0&&N.yMeasureUnit&&(E=N.yMeasureUnit),o.add(N.label);for(const B of N.data)d.push(B.value)}o.size>0&&m.push(p(d,E,o))}else{const i=ce.map(d=>d.value),o=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));m.push(p(i,f,o))}Ne.current=m;const _=new Map;for(const i of m)for(const o of i.labels)_.set(o,i);const w=I.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:i=>s.timeFormatter(parseFloat(i),void 0)},timeScale:{...w.timeScale||{},...x?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const v=!z&&e.length>1&&!H,G=z?T:e.length>1&&!H||T,k=Y.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...z&&{defaultVisiblePriceScaleId:we},leftPriceScale:{...w.leftPriceScale||{},...x?.leftPriceScale,visible:z&&!T,textColor:k},rightPriceScale:{...w.rightPriceScale||{},...x?.rightPriceScale,visible:z?!T:!G,textColor:k}});const ee=new Set(V.current.keys()),q=new Set(e.map(oe));for(const i of ee)if(!q.has(i)){const o=V.current.get(i);o&&(t.removeSeries(o),V.current.delete(i))}const b=I.getDefaultSeries(),M=[];let L=0;const W=e.find(i=>i.data.length>0),y=new Map;if(D&&D.length>0)for(const i of D){if(!Number.isFinite(i.price))continue;const o=i.seriesLabel??W?.label;if(!o)continue;const d=y.get(o)??[];d.push(i.price),y.set(o,d)}if(F&&F.length>0)for(const i of F){const o=i.seriesLabel??W?.label;if(!o)continue;const d=y.get(o)??[];Number.isFinite(i.priceTop)&&d.push(i.priceTop),Number.isFinite(i.priceBottom)&&d.push(i.priceBottom),y.set(o,d)}for(let i=0;i<e.length;i++){const o=e[i],d=oe(o),E=Ke.getSeriesColorPalette(i),N=o.lineColor??o.color??E.line;let B,Z;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)B=o.topColor,Z=o.bottomColor;else if(o.topColor){const S=Y.generateColorsFromBase(N);B=o.topColor,Z=S.bottomColor}else if(o.bottomColor)B=Y.generateColorsFromBase(N).topColor,Z=o.bottomColor;else{const S=Y.generateColorsFromBase(N);B=S.topColor,Z=S.bottomColor}else B=o.topColor||E.top,Z=o.bottomColor||E.bottom;if(o.data.length===0){const S=V.current.get(d);S&&(t.removeSeries(S),V.current.delete(d));continue}const ue=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,he=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,rt=ue<0,nt=o.data.some(S=>S.value===0),it=!rt&&nt,Be=qe.pickMinMove(he-ue),Fe=z?o.priceScaleId??(L===0?"left":"right"):H||!v||L===0?"right":`scale-${L}`;v&&M.push({priceScaleId:Fe||"right",seriesIndex:L});const Ce=(H||!v)&&n!==void 0&&typeof n=="number",st=y.get(o.label)??[],lt=S=>{const P=S();if(P?.priceRange){Ce&&(P.priceRange.minValue=n);for(const K of st)K<P.priceRange.minValue&&(P.priceRange.minValue=K),K>P.priceRange.maxValue&&(P.priceRange.maxValue=K);const ie=Ce?n:it&&P.priceRange.minValue>=0?0:void 0,de=ae.current>0?ae.current:j.current?.clientHeight??0;if(de>0){const K=qe.niceAxisRange({min:P.priceRange.minValue,max:P.priceRange.maxValue,floor:ie,scaleHeightPx:de,fontSizePx:I.AXIS_FONT_SIZE,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,minMove:Be,edgePaddingPx:I.AXIS_EDGE_LABEL_PADDING_PX,edgePaddingTopPx:I.AXIS_TOP_LABEL_PADDING_PX});P.priceRange.minValue=K.min,P.priceRange.maxValue=K.max}P.margins={above:I.AXIS_TOP_LABEL_PADDING_PX,below:I.AXIS_EDGE_LABEL_PADDING_PX}}return P},ze=_.get(o.label)??m[0],Xe=ze.formatter,at=ze.tickmarksFormatter,xe={lineColor:N,topColor:B,bottomColor:Z,priceScaleId:Fe,...o.seriesType==="line"&&{color:N,lineStyle:o.lineStyle??$.LineStyle.Solid},priceFormat:{type:"custom",minMove:Be,formatter:Ce&&typeof n=="number"?S=>Xe(S<n?n:S):Xe,tickmarksFormatter:at},autoscaleInfoProvider:lt},Ge=o.seriesType==="line";let X=V.current.get(d);const ne=o.data.map(S=>({...S,time:S.time}));if(le!==void 0&&ne.length>0&&Number(ne[0].time)>le){const S=Number(ne[0].time),P=S-le,ie=86400,de=P>180*ie?7*ie:P>30*ie?ie:6*3600,K=[];for(let ve=le;ve<S;ve+=de)K.push({time:ve});ne.unshift(...K)}X&&X.seriesType()!==(Ge?"Line":"Area")&&(t.removeSeries(X),V.current.delete(d),X=void 0),X?(X.applyOptions(xe),X.setData(ne)):(Ge?X=t.addSeries($.LineSeries,{...b,...xe}):X=t.addSeries($.AreaSeries,{...b,...xe}),X.setData(ne),V.current.set(d,X)),L++}if(z)try{const i=t.priceScale("left"),o=t.priceScale("right"),d={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:k,...x?.rightPriceScale};i?.applyOptions(d),o?.applyOptions(d)}catch{}else if(v&&M.length>0)for(const i of M)try{const o=t.priceScale(i.priceScaleId);o&&o.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:k})}catch(o){console.warn(`Failed to configure price scale ${i.priceScaleId} for series ${i.seriesIndex}:`,o)}else if(!v)try{const i=t.priceScale("right");i&&i.applyOptions({visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:I.AXIS_TICK_MARK_DENSITY,textColor:k,...x?.rightPriceScale})}catch{}n!==void 0&&!T&&(H||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}});let O=0;if(ce.length>0){const i=ce.map(d=>Number(d.time)).filter(d=>Number.isFinite(d)),o=new Set(i).size-1;if(o>=0){const d=()=>{const E=t.timeScale();if(h!=="time"){E.applyOptions({fixLeftEdge:!0,fixRightEdge:!0}),E.setVisibleLogicalRange({from:0,to:o});return}const N=z&&!T,B=z?!T:!G,Z=!N,ue=!B;E.applyOptions({fixLeftEdge:!Z,fixRightEdge:!ue}),O=requestAnimationFrame(()=>{const he=$e({lastIndex:o,width:E.width(),padLeft:Z,padRight:ue});try{he&&E.setVisibleLogicalRange(he)}catch{E.fitContent()}})};try{d()}catch{try{t.timeScale().fitContent(),d()}catch{}}}}Le.current&&(Le.current=!1),x&&t.applyOptions(x);const te=new Map;for(const i of e)i.data.length>0&&te.set(i.label,i.data[i.data.length-1]);return Se(te.size>0?te:void 0),()=>cancelAnimationFrame(O)},[U,e,ce,h,f,T,H,z,we,Pe,Re,le,D,F,x]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=e.length===1;let n;for(const c of e)if(c.data.length>0){n=c.data[c.data.length-1].time;break}if(!n)return;const s=c=>{const{time:p=n,seriesData:m,point:_}=c||{},w=e[0],v=w?V.current.get(oe(w)):void 0;if(!_||!p){const q=new Map;for(const b of e)b.data.length>0&&q.set(b.label,b.data[b.data.length-1]);if(Se(q.size>0?q:void 0),a||H||ge)J(null);else if(v&&n){const b=e[0];if(b&&b.data.length>0){const L=t.timeScale().timeToCoordinate(n),W=b.data[b.data.length-1].value,y=v.priceToCoordinate(W);L!==null&&y!==null&&J({x:L,y})}}return}const G=new Map;let k,ee=v;for(let q=0;q<e.length;q++){const b=e[q],M=V.current.get(oe(b));if(!M)continue;const L=m?.get(M),W=L&&"value"in L?L.value:void 0;let y;if(W!==void 0)y=W;else if(a){const O=Number(p),te=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;O<te?y=Number.NaN:y=b.data[b.data.length-1]?.value??0}else{const O=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;if(Number(p)<O)continue;y=Ze(b.data,Number(p))}Number.isNaN(y)||(k===void 0&&(k=y,ee=M),G.set(b.label,{value:y,time:p}))}if(Se(G),k!==void 0&&ee){const b=t.timeScale().timeToCoordinate(p),M=ee.priceToCoordinate(k);if(b!==null&&M!==null){const L=j.current;if(L){const W=L.querySelector(".LightweightChart");if(W){const y=W.getBoundingClientRect(),O=L.getBoundingClientRect(),te=b+(y.left-O.left),i=M+(y.top-O.top);J({x:te,y:i})}else J({x:b,y:M})}else J({x:b,y:M})}else J(null)}else J(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!a&&!H&&!ge&&requestAnimationFrame(()=>{const c=e[0],p=c?V.current.get(oe(c)):void 0;if(p&&n&&c.data.length>0){const _=t.timeScale().timeToCoordinate(n),w=c.data[c.data.length-1].value,v=p.priceToCoordinate(w);_!==null&&v!==null&&J({x:_,y:v})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,H,T,ge]),g.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=t.timeScale(),n=()=>{const s=Ne.current;if(s.length===0)return;const c=a.getVisibleRange();if(!c)return;const p=Number(c.from),m=Number(c.to);for(const _ of s){const w=[];for(const v of e)if(_.labels.has(v.label))for(const G of v.data){const k=Number(G.time);k>=p&&k<=m&&w.push(G.value)}w.length>0&&_.updateVisibleRange(w)}};return a.subscribeVisibleLogicalRangeChange(n),()=>{a.unsubscribeVisibleLogicalRangeChange(n)}},[e]),g.useEffect(()=>{const t=A.current,a=Array.from(V.current.values()),n=[];if(t&&a.length>0&&R){const s=I.getDefaultVerticalLine(),c=a[0];for(const p of R){const m={...s,...p.options||{}};m.color&&(m.color=Y.resolveCSSColor(m.color,m.color));const _=new ht.VertLine(t,c,p.xCoordinate,m);c.attachPrimitive(_),n.push(_)}}return()=>{if(a.length>0){const s=a[0];for(const c of n)try{s.detachPrimitive(c)}catch{}}}},[R,e,U]),g.useEffect(()=>{const t=[],a=[];if(D&&D.length>0){const n=Y.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of D){if(!Number.isFinite(s.price))continue;const c=We(V.current,e,s.seriesLabel);if(!c)continue;const p=s.color?Y.resolveCSSColor(s.color,s.color):n,m=s.lineWidth??1,_=s.lineStyle??$.LineStyle.Dashed,w=c.createPriceLine({price:s.price,color:p,lineWidth:m,lineStyle:_,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:c,line:w});const v=new vt(c,s.price,p,m,_);c.attachPrimitive(v),a.push({series:c,primitive:v})}}return()=>{for(const{series:n,primitive:s}of a)try{n.detachPrimitive(s)}catch{}for(const{series:n,line:s}of t)try{n.removePriceLine(s)}catch{}}},[D,e,U]),g.useEffect(()=>{const t=[];if(F&&F.length>0){const a="rgba(239, 68, 68, 0.12)";for(const n of F){const s=We(V.current,e,n.seriesLabel);if(!s)continue;const c=n.color?Y.resolveCSSColor(n.color,a):a,p=new bt(s,n.priceTop,n.priceBottom,c);s.attachPrimitive(p),t.push({series:s,zone:p})}}return()=>{for(const{series:a,zone:n}of t)try{a.detachPrimitive(n)}catch{}}},[F,e,U]),g.useEffect(()=>{const t=A.current;if(!t||!R?.length){Me([]);return}const a=()=>{const c=t.timeScale(),p=R.map(m=>c.timeToCoordinate(m.xCoordinate)??null);Me(p),j.current&&De(j.current.clientWidth)};a();const n=t.timeScale(),s=()=>{a()};return n.subscribeVisibleLogicalRangeChange(s),()=>{n.unsubscribeVisibleLogicalRangeChange(s)}},[R,e,U]),g.useLayoutEffect(()=>{tt(t=>{const a={};let n=!1;for(const[s,c]of Ae.current){if(!c)continue;const p=c.offsetWidth;a[s]=p,t[s]!==p&&(n=!0)}return Object.keys(t).length!==Object.keys(a).length&&(n=!0),n?a:t})});const fe=e.length===1,je=ye.useMemo(()=>{if(fe&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[fe,e]);return C.jsxs("div",{ref:j,className:Q.cn("relative z-[1] w-full h-full overflow-hidden p-0",r),children:[pe!=null&&pe!==!1&&fe?C.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:C.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:pe})}):Qe&&fe&&je&&C.jsx(ut.GraphCurrentValue,{point:je,xMeasureUnit:h,yMeasureUnit:f,decimals:se}),ke&&Ee&&C.jsx(ft.GraphTooltip,{points:ke,xMeasureUnit:h,yMeasureUnit:f,series:e,position:Ee,containerRef:j,decimals:se}),l&&C.jsx(Ye,{series:e,onUnselect:u}),R&&R.length>0&&Ie.length===R.length&&C.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:R.map((t,a)=>{const n=Ie[a],s=t.options??{};if(n===null)return null;const{labelText:c,valueStr:p}=He(s,f,se),m=s.tooltipText??"";if(!(c||p||m))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",v=s.labelTextColor??"hsl(var(--foreground))",G=`${String(t.xCoordinate)}-${c}-${m}`,k=Oe(n,Ue,et[a]);return C.jsxs("div",{ref:ee=>{Ae.current.set(a,ee)},className:Q.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",m&&"pointer-events-auto cursor-default"),style:{...k,backgroundColor:w,color:v},children:[c&&C.jsx("span",{className:"block",children:c}),p&&C.jsx("span",{className:Q.cn("block",c&&"mt-0.5"),children:p}),m&&C.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:m})]},G)})}),C.jsx("div",{ref:be,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ye({series:e,markers:r,onUnselect:l,inline:u=!1}){const h=e.every(f=>f.data.length===0);return C.jsxs("div",{className:Q.cn("flex flex-wrap",u?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:[e.map((f,x)=>{const R=Ke.getSeriesColorPalette(x),D=(f.lineColor??f.color)||R.line,F=!h&&f.data.length===0;return C.jsxs("div",{className:Q.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",F&&"opacity-50"),children:[C.jsx("div",{className:Q.cn("shrink-0",u?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:D}}),C.jsxs("span",{className:Q.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:[f.label,F&&" (no data)"]}),l&&C.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),l(f.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 ${f.label}`,children:C.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:[C.jsx("title",{children:"Close"}),C.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),C.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f.id??f.label)}),r?.map(f=>C.jsxs("div",{className:Q.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border"),children:[C.jsx("div",{className:"h-3 w-0.5 shrink-0",style:{backgroundColor:f.color}}),C.jsx("span",{className:Q.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:f.label})]},f.id))]})}exports.Graph=yt;exports.GraphLegend=Ye;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=_e;exports.getStepForwardValue=Ze;exports.getVerticalLineLabelStyle=Oe;exports.getVerticalLineTooltipContent=He;exports.seriesIdentity=oe;exports.visibleLogicalRangeFor=$e;
@@ -206,7 +206,7 @@ function oo({
206
206
  disableZoom: ke = !1,
207
207
  hideDefaultTooltip: be = !1
208
208
  }) {
209
- const I = H(null), N = H(/* @__PURE__ */ new Map()), Se = H(!1), Le = H(!0), Me = H([]), ce = H(0), B = H(null), ve = H(null), De = H(null), R = gt(), ue = _e.useMemo(() => e.flatMap((t) => t.data), [e]), et = _e.useMemo(() => {
209
+ const I = H(null), V = H(/* @__PURE__ */ new Map()), Se = H(!1), Le = H(!0), Me = H([]), ce = H(0), B = H(null), ve = H(null), De = H(null), R = gt(), ue = _e.useMemo(() => e.flatMap((t) => t.data), [e]), et = _e.useMemo(() => {
210
210
  if (e.length > 0) {
211
211
  const t = e[e.length - 1];
212
212
  if (t.data.length > 0)
@@ -267,7 +267,7 @@ function oo({
267
267
  ce.current = 0;
268
268
  }
269
269
  return nt((l) => l + 1), () => {
270
- r.remove(), I.current = null, Se.current = !1, N.current.clear();
270
+ r.remove(), I.current = null, Se.current = !1, V.current.clear();
271
271
  };
272
272
  }, [R]), W(() => {
273
273
  const t = I.current;
@@ -312,21 +312,21 @@ function oo({
312
312
  o
313
313
  ])
314
314
  ), m = (i, o, d) => {
315
- const { formatter: k, tickmarksFormatter: L, updateVisibleRange: E } = xt(i, o, {
315
+ const { formatter: L, tickmarksFormatter: N, updateVisibleRange: E } = xt(i, o, {
316
316
  yScaleMin: r
317
317
  });
318
- return { formatter: k, tickmarksFormatter: L, updateVisibleRange: E, labels: d };
318
+ return { formatter: L, tickmarksFormatter: N, updateVisibleRange: E, labels: d };
319
319
  }, p = [];
320
320
  if (z)
321
321
  for (const i of ["left", "right"]) {
322
322
  const o = /* @__PURE__ */ new Set(), d = [];
323
- let k = u;
324
- for (const L of e)
325
- if (L.data.length !== 0 && a.get(L.label) === i) {
326
- o.size === 0 && L.yMeasureUnit && (k = L.yMeasureUnit), o.add(L.label);
327
- for (const E of L.data) d.push(E.value);
323
+ let L = u;
324
+ for (const N of e)
325
+ if (N.data.length !== 0 && a.get(N.label) === i) {
326
+ o.size === 0 && N.yMeasureUnit && (L = N.yMeasureUnit), o.add(N.label);
327
+ for (const E of N.data) d.push(E.value);
328
328
  }
329
- o.size > 0 && p.push(m(d, k, o));
329
+ o.size > 0 && p.push(m(d, L, o));
330
330
  }
331
331
  else {
332
332
  const i = ue.map((d) => d.value), o = new Set(
@@ -357,7 +357,7 @@ function oo({
357
357
  minBarSpacing: 0
358
358
  }
359
359
  });
360
- const v = !z && e.length > 1 && !K, X = z ? R : e.length > 1 && !K || R, V = ne(
360
+ const v = !z && e.length > 1 && !K, X = z ? R : e.length > 1 && !K || R, k = ne(
361
361
  "hsl(var(--muted-foreground))",
362
362
  "rgb(163, 163, 163)"
363
363
  );
@@ -369,20 +369,20 @@ function oo({
369
369
  ...x.leftPriceScale || {},
370
370
  ...S?.leftPriceScale,
371
371
  visible: z && !R,
372
- textColor: V
372
+ textColor: k
373
373
  },
374
374
  rightPriceScale: {
375
375
  ...x.rightPriceScale || {},
376
376
  ...S?.rightPriceScale,
377
377
  visible: z ? !R : !X,
378
- textColor: V
378
+ textColor: k
379
379
  }
380
380
  });
381
- const O = new Set(N.current.keys()), $ = new Set(e.map(ie));
381
+ const O = new Set(V.current.keys()), $ = new Set(e.map(ie));
382
382
  for (const i of O)
383
383
  if (!$.has(i)) {
384
- const o = N.current.get(i);
385
- o && (t.removeSeries(o), N.current.delete(i));
384
+ const o = V.current.get(i);
385
+ o && (t.removeSeries(o), V.current.delete(i));
386
386
  }
387
387
  const g = St(), M = [];
388
388
  let T = 0;
@@ -403,25 +403,25 @@ function oo({
403
403
  Number.isFinite(i.priceTop) && d.push(i.priceTop), Number.isFinite(i.priceBottom) && d.push(i.priceBottom), C.set(o, d);
404
404
  }
405
405
  for (let i = 0; i < e.length; i++) {
406
- const o = e[i], d = ie(o), k = Oe(i), L = o.lineColor ?? o.color ?? k.line;
406
+ const o = e[i], d = ie(o), L = Oe(i), N = o.lineColor ?? o.color ?? L.line;
407
407
  let E, q;
408
408
  if (o.lineColor ?? o.color)
409
409
  if (o.topColor && o.bottomColor)
410
410
  E = o.topColor, q = o.bottomColor;
411
411
  else if (o.topColor) {
412
- const b = Pe(L);
412
+ const b = Pe(N);
413
413
  E = o.topColor, q = b.bottomColor;
414
414
  } else if (o.bottomColor)
415
- E = Pe(L).topColor, q = o.bottomColor;
415
+ E = Pe(N).topColor, q = o.bottomColor;
416
416
  else {
417
- const b = Pe(L);
417
+ const b = Pe(N);
418
418
  E = b.topColor, q = b.bottomColor;
419
419
  }
420
420
  else
421
- E = o.topColor || k.top, q = o.bottomColor || k.bottom;
421
+ E = o.topColor || L.top, q = o.bottomColor || L.bottom;
422
422
  if (o.data.length === 0) {
423
- const b = N.current.get(d);
424
- b && (t.removeSeries(b), N.current.delete(d));
423
+ const b = V.current.get(d);
424
+ b && (t.removeSeries(b), V.current.delete(d));
425
425
  continue;
426
426
  }
427
427
  const fe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, de = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, it = fe < 0, lt = o.data.some((b) => b.value === 0), st = !it && lt, Xe = Tt(de - fe), $e = z ? o.priceScaleId ?? (T === 0 ? "left" : "right") : K || !v || T === 0 ? "right" : `scale-${T}`;
@@ -457,11 +457,12 @@ function oo({
457
457
  }
458
458
  return w;
459
459
  }, Ge = y.get(o.label) ?? p[0], je = Ge.formatter, ut = Ge.tickmarksFormatter, xe = {
460
- lineColor: L,
460
+ lineColor: N,
461
461
  topColor: E,
462
462
  bottomColor: q,
463
463
  priceScaleId: $e,
464
464
  ...o.seriesType === "line" && {
465
+ color: N,
465
466
  lineStyle: o.lineStyle ?? le.Solid
466
467
  },
467
468
  priceFormat: {
@@ -474,7 +475,7 @@ function oo({
474
475
  },
475
476
  autoscaleInfoProvider: ct
476
477
  }, He = o.seriesType === "line";
477
- let A = N.current.get(d);
478
+ let A = V.current.get(d);
478
479
  const te = o.data.map((b) => ({
479
480
  ...b,
480
481
  time: b.time
@@ -485,13 +486,13 @@ function oo({
485
486
  j.push({ time: we });
486
487
  te.unshift(...j);
487
488
  }
488
- A && A.seriesType() !== (He ? "Line" : "Area") && (t.removeSeries(A), N.current.delete(d), A = void 0), A ? (A.applyOptions(xe), A.setData(te)) : (He ? A = t.addSeries(dt, {
489
+ A && A.seriesType() !== (He ? "Line" : "Area") && (t.removeSeries(A), V.current.delete(d), A = void 0), A ? (A.applyOptions(xe), A.setData(te)) : (He ? A = t.addSeries(dt, {
489
490
  ...g,
490
491
  ...xe
491
492
  }) : A = t.addSeries(mt, {
492
493
  ...g,
493
494
  ...xe
494
- }), A.setData(te), N.current.set(d, A)), T++;
495
+ }), A.setData(te), V.current.set(d, A)), T++;
495
496
  }
496
497
  if (z)
497
498
  try {
@@ -502,7 +503,7 @@ function oo({
502
503
  alignLabels: !0,
503
504
  entireTextOnly: !1,
504
505
  tickMarkDensity: pe,
505
- textColor: V,
506
+ textColor: k,
506
507
  ...S?.rightPriceScale
507
508
  };
508
509
  i?.applyOptions(d), o?.applyOptions(d);
@@ -522,7 +523,7 @@ function oo({
522
523
  alignLabels: !0,
523
524
  entireTextOnly: !1,
524
525
  tickMarkDensity: pe,
525
- textColor: V
526
+ textColor: k
526
527
  });
527
528
  } catch (o) {
528
529
  console.warn(
@@ -543,7 +544,7 @@ function oo({
543
544
  alignLabels: !0,
544
545
  entireTextOnly: !1,
545
546
  tickMarkDensity: pe,
546
- textColor: V,
547
+ textColor: k,
547
548
  ...S?.rightPriceScale
548
549
  });
549
550
  } catch {
@@ -558,29 +559,29 @@ function oo({
558
559
  const i = ue.map((d) => Number(d.time)).filter((d) => Number.isFinite(d)), o = new Set(i).size - 1;
559
560
  if (o >= 0) {
560
561
  const d = () => {
561
- const k = t.timeScale();
562
+ const L = t.timeScale();
562
563
  if (h !== "time") {
563
- k.applyOptions({
564
+ L.applyOptions({
564
565
  fixLeftEdge: !0,
565
566
  fixRightEdge: !0
566
- }), k.setVisibleLogicalRange({ from: 0, to: o });
567
+ }), L.setVisibleLogicalRange({ from: 0, to: o });
567
568
  return;
568
569
  }
569
- const L = z && !R, E = z ? !R : !X, q = !L, fe = !E;
570
- k.applyOptions({
570
+ const N = z && !R, E = z ? !R : !X, q = !N, fe = !E;
571
+ L.applyOptions({
571
572
  fixLeftEdge: !q,
572
573
  fixRightEdge: !fe
573
574
  }), Z = requestAnimationFrame(() => {
574
575
  const de = Vt({
575
576
  lastIndex: o,
576
- width: k.width(),
577
+ width: L.width(),
577
578
  padLeft: q,
578
579
  padRight: fe
579
580
  });
580
581
  try {
581
- de && k.setVisibleLogicalRange(de);
582
+ de && L.setVisibleLogicalRange(de);
582
583
  } catch {
583
- k.fitContent();
584
+ L.fitContent();
584
585
  }
585
586
  });
586
587
  };
@@ -627,7 +628,7 @@ function oo({
627
628
  }
628
629
  if (!r) return;
629
630
  const l = (a) => {
630
- const { time: m = r, seriesData: p, point: y } = a || {}, x = e[0], v = x ? N.current.get(ie(x)) : void 0;
631
+ const { time: m = r, seriesData: p, point: y } = a || {}, x = e[0], v = x ? V.current.get(ie(x)) : void 0;
631
632
  if (!y || !m) {
632
633
  const $ = /* @__PURE__ */ new Map();
633
634
  for (const g of e)
@@ -644,9 +645,9 @@ function oo({
644
645
  return;
645
646
  }
646
647
  const X = /* @__PURE__ */ new Map();
647
- let V, O = v;
648
+ let k, O = v;
648
649
  for (let $ = 0; $ < e.length; $++) {
649
- const g = e[$], M = N.current.get(ie(g));
650
+ const g = e[$], M = V.current.get(ie(g));
650
651
  if (!M) continue;
651
652
  const T = p?.get(M), G = T && "value" in T ? T.value : void 0;
652
653
  let C;
@@ -660,10 +661,10 @@ function oo({
660
661
  if (Number(m) < Z) continue;
661
662
  C = At(g.data, Number(m));
662
663
  }
663
- Number.isNaN(C) || (V === void 0 && (V = C, O = M), X.set(g.label, { value: C, time: m }));
664
+ Number.isNaN(C) || (k === void 0 && (k = C, O = M), X.set(g.label, { value: C, time: m }));
664
665
  }
665
- if (Ce(X), V !== void 0 && O) {
666
- const g = t.timeScale().timeToCoordinate(m), M = O.priceToCoordinate(V);
666
+ if (Ce(X), k !== void 0 && O) {
667
+ const g = t.timeScale().timeToCoordinate(m), M = O.priceToCoordinate(k);
667
668
  if (g !== null && M !== null) {
668
669
  const T = B.current;
669
670
  if (T) {
@@ -683,7 +684,7 @@ function oo({
683
684
  Q(null);
684
685
  };
685
686
  return t.subscribeCrosshairMove(l), R && t.subscribeClick(l), !s && !K && !be && requestAnimationFrame(() => {
686
- const a = e[0], m = a ? N.current.get(ie(a)) : void 0;
687
+ const a = e[0], m = a ? V.current.get(ie(a)) : void 0;
687
688
  if (m && r && a.data.length > 0) {
688
689
  const y = t.timeScale().timeToCoordinate(r), x = a.data[a.data.length - 1].value, v = m.priceToCoordinate(x);
689
690
  y !== null && v !== null && Q({ x: y, y: v });
@@ -705,8 +706,8 @@ function oo({
705
706
  for (const v of e)
706
707
  if (y.labels.has(v.label))
707
708
  for (const X of v.data) {
708
- const V = Number(X.time);
709
- V >= m && V <= p && x.push(X.value);
709
+ const k = Number(X.time);
710
+ k >= m && k <= p && x.push(X.value);
710
711
  }
711
712
  x.length > 0 && y.updateVisibleRange(x);
712
713
  }
@@ -717,7 +718,7 @@ function oo({
717
718
  );
718
719
  };
719
720
  }, [e]), W(() => {
720
- const t = I.current, s = Array.from(N.current.values()), r = [];
721
+ const t = I.current, s = Array.from(V.current.values()), r = [];
721
722
  if (t && s.length > 0 && P) {
722
723
  const l = vt(), a = s[0];
723
724
  for (const m of P) {
@@ -755,7 +756,7 @@ function oo({
755
756
  for (const l of D) {
756
757
  if (!Number.isFinite(l.price)) continue;
757
758
  const a = Qe(
758
- N.current,
759
+ V.current,
759
760
  e,
760
761
  l.seriesLabel
761
762
  );
@@ -797,7 +798,7 @@ function oo({
797
798
  const s = "rgba(239, 68, 68, 0.12)";
798
799
  for (const r of F) {
799
800
  const l = Qe(
800
- N.current,
801
+ V.current,
801
802
  e,
802
803
  r.seriesLabel
803
804
  );
@@ -899,7 +900,7 @@ function oo({
899
900
  se
900
901
  ), p = l.tooltipText ?? "";
901
902
  if (!(a || m || p)) return null;
902
- const x = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", v = l.labelTextColor ?? "hsl(var(--foreground))", X = `${String(t.xCoordinate)}-${a}-${p}`, V = zt(
903
+ const x = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", v = l.labelTextColor ?? "hsl(var(--foreground))", X = `${String(t.xCoordinate)}-${a}-${p}`, k = zt(
903
904
  r,
904
905
  tt,
905
906
  ot[s]
@@ -915,7 +916,7 @@ function oo({
915
916
  p && "pointer-events-auto cursor-default"
916
917
  ),
917
918
  style: {
918
- ...V,
919
+ ...k,
919
920
  backgroundColor: x,
920
921
  color: v
921
922
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/ui-kit",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
4
4
  "description": "Internal UI components",
5
5
  "repository": {
6
6
  "type": "git",