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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),U=require("lightweight-charts"),b=require("react"),Je=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),E=require("../../utils/colors.cjs"),ie=require("./default-config.cjs"),ee=require("./formatters.cjs"),Ye=require("./graph-current-value.cjs"),Ue=require("./graph-tooltip.cjs"),et=require("./plugins/vertical-line.cjs");function tt(e){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const c in e)if(c!=="default"){const h=Object.getOwnPropertyDescriptor(e,c);Object.defineProperty(i,c,h.get?h:{enumerable:!0,get:()=>e[c]})}}return i.default=e,Object.freeze(i)}const Se=tt(b);class ot{_yTop;_yBottom;_color;constructor(i,c,h){this._yTop=i,this._yBottom=c,this._color=h}draw(i){i.useBitmapCoordinateSpace(c=>{const h=c.context,p=c.verticalPixelRatio,_=this._yTop===null?0:this._yTop*p,H=this._yBottom===null?c.bitmapSize.height:this._yBottom*p,w=Math.min(_,H),M=Math.max(_,H);h.fillStyle=this._color,h.fillRect(0,w,c.bitmapSize.width,M-w)})}}class rt{_source;_yTop=null;_yBottom=null;constructor(i){this._source=i}update(){const i=this._source.series;this._yTop=this._source.priceTop===void 0?null:i.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:i.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new ot(this._yTop,this._yBottom,this._source.color)}}class nt{series;priceTop;priceBottom;color;_paneViews;constructor(i,c,h,p){this.series=i,this.priceTop=c,this.priceBottom=h,this.color=p,this._paneViews=[new rt(this)]}updateAllViews(){for(const i of this._paneViews)i.update()}paneViews(){return this._paneViews}}function We(e,i,c){const h=e.labelText??"",p=e.value,_=p===void 0?"":typeof p=="number"?i==="$"?`$${ee.formatExactValue(p,void 0,c)}`:i==="%"?`${ee.formatExactValue(p,void 0,c)}%`:ee.formatExactValue(p,i!=="none"&&i!=="%"&&i!=="$"?i:void 0,c):String(p);return{labelText:h,valueStr:_}}function $e(e,i){for(let c=e.length-1;c>=0;c--)if(Number(e[c].time)<=i)return e[c].value;return 0}const ce=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],lt=137.5;function xe(e){if(e<ce.length)return ce[e];const c=(e-ce.length)*lt%360,h=E.hslToHex(c,70,50),{topColor:p,bottomColor:_}=E.generateColorsFromBase(h);return{line:h,top:p,bottom:_}}function at({series:e,className:i,showLegend:c=!1,onUnselectSeries:h,xMeasureUnit:p="time",yMeasureUnit:_="token",optionsOverrides:H,verticalLineOptions:w,priceLineOptions:M,zoneOptions:$,currentValueDecimals:ue,useSharedPriceScale:q=!1,dualYAxis:k=!1,defaultVisiblePriceScaleId:ye="right",leftPriceScaleTitle:we,rightPriceScaleTitle:st,showCurrentValue:Oe=!0,graphTitle:fe,yScaleMin:Re,yScaleMinMultiple:Te,visibleTimeFrom:X,disableZoom:le=!1,hideDefaultTooltip:ge=!1}){const I=b.useRef(null),R=b.useRef(new Map),he=b.useRef(!1),_e=b.useRef(!0),Ve=b.useRef([]),Z=b.useRef(null),de=b.useRef(null),ae=b.useRef(null),N=Je.useIsMobile(),A=Se.useMemo(()=>e.flatMap(o=>o.data),[e]),Ge=Se.useMemo(()=>{if(e.length>0){const o=e[e.length-1];if(o.data.length>0)return o.data[o.data.length-1]}},[e]),[Ne,pe]=b.useState(()=>{if(!Ge)return;const o=new Map;for(const a of e)a.data.length>0&&o.set(a.label,a.data[a.data.length-1]);return o}),[Pe,O]=b.useState(null),[Le,Me]=b.useState([]);b.useEffect(()=>{const o=()=>{try{if(I.current&&Z.current){const n=Z.current.clientWidth,s=Z.current.clientHeight;I.current.resize(n,s)}}catch{}},a=Z.current,l=a?new ResizeObserver(o):null;return ae.current=l,a&&l?.observe(a),()=>{a&&l?.unobserve(a),l?.disconnect(),ae.current=null}},[]),b.useEffect(()=>{if(!de.current||he.current)return;const o=ie.getDefaultOptions(),a=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{},n=U.createChart(de.current,{...o,leftPriceScale:{...o.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...o.rightPriceScale||{},visible:!N,textColor:a},...N&&{crosshair:{...o.crosshair,mode:U.CrosshairMode.Magnet}},...l,...H});return I.current=n,he.current=!0,()=>{ae.current?.disconnect(),ae.current=null,n.remove(),I.current=null,he.current=!1,R.current.clear()}},[N,H,le]),b.useEffect(()=>{const o=I.current;o&&o.applyOptions(le?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[le]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const l=e.filter(r=>r.data.length>0).length<=1?Re:Te,n=p==="time"?ee.getXFormatters(p,A):ee.getXFormatters(p),s=new Map;{let r=0;for(const t of e)t.data.length!==0&&(s.set(t.label,t.priceScaleId??(r===0?"left":"right")),r++)}const g=(r,t,f)=>{const{formatter:B,tickmarksFormatter:y,updateVisibleRange:z,updateLastValues:Be}=ee.createAdaptiveYAxisFormatter(r,t,{yScaleMin:l}),me=e.filter(K=>K.data.length>0&&f.has(K.label)).map(K=>K.data[K.data.length-1].value);return Be(me),{formatter:B,tickmarksFormatter:y,updateVisibleRange:z,labels:f}},u=[];if(k)for(const r of["left","right"]){const t=new Set,f=[];let B=_;for(const y of e)if(y.data.length!==0&&s.get(y.label)===r){t.size===0&&y.yMeasureUnit&&(B=y.yMeasureUnit),t.add(y.label);for(const z of y.data)f.push(z.value)}t.size>0&&u.push(g(f,B,t))}else{const r=A.map(f=>f.value),t=new Set(e.filter(f=>f.data.length>0).map(f=>f.label));u.push(g(r,_,t))}Ve.current=u;const C=new Map;for(const r of u)for(const t of r.labels)C.set(t,r);const S=ie.getDefaultOptions();o.applyOptions({localization:{...S.localization||{},timeFormatter:r=>n.timeFormatter(parseFloat(r),void 0)},timeScale:{...S.timeScale||{},tickMarkFormatter:n.tickMarkFormatter,minBarSpacing:0}});const j=(A.length>0?Math.min(...A.map(r=>r.value)):0)<0,T=A.some(r=>r.value===0),m=!j&&T,x=!k&&e.length>1&&!q,P=k?N:e.length>1&&!q||N,L=E.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({...k&&{defaultVisiblePriceScaleId:ye},leftPriceScale:{...S.leftPriceScale||{},visible:k&&!N,textColor:L,...k&&we&&{}},rightPriceScale:{...S.rightPriceScale||{},visible:k?!N:!P,textColor:L,...m&&!k&&{scaleMargins:{top:.3,bottom:0}}}});const V=new Set(R.current.keys()),Q=new Set(e.map(r=>r.label));for(const r of V)if(!Q.has(r)){const t=R.current.get(r);t&&(o.removeSeries(t),R.current.delete(r))}const J=ie.getDefaultSeries(),te=[];let oe=0;const je=e.find(r=>r.data.length>0),re=new Map;if(M&&M.length>0)for(const r of M){if(!Number.isFinite(r.price))continue;const t=r.seriesLabel??je?.label;if(!t)continue;const f=re.get(t)??[];f.push(r.price),re.set(t,f)}if($&&$.length>0)for(const r of $){const t=r.seriesLabel??je?.label;if(!t)continue;const f=re.get(t)??[];Number.isFinite(r.priceTop)&&f.push(r.priceTop),Number.isFinite(r.priceBottom)&&f.push(r.priceBottom),re.set(t,f)}for(let r=0;r<e.length;r++){const t=e[r],f=xe(r),B=t.lineColor??t.color??f.line;let y,z;if(t.lineColor??t.color)if(t.topColor&&t.bottomColor)y=t.topColor,z=t.bottomColor;else if(t.topColor){const d=E.generateColorsFromBase(B);y=t.topColor,z=d.bottomColor}else if(t.bottomColor)y=E.generateColorsFromBase(B).topColor,z=t.bottomColor;else{const d=E.generateColorsFromBase(B);y=d.topColor,z=d.bottomColor}else y=t.topColor||f.top,z=t.bottomColor||f.bottom;if(t.data.length===0){const d=R.current.get(t.label);d&&(o.removeSeries(d),R.current.delete(t.label));continue}const me=(t.data.length>0?Math.min(...t.data.map(d=>d.value)):0)<0,K=t.data.some(d=>d.value===0),He=!me&&K,Fe=k?t.priceScaleId??(oe===0?"left":"right"):q||!x||oe===0?"right":`scale-${oe}`;x&&te.push({priceScaleId:Fe||"right",shouldPreventNegativeAxis:He,seriesIndex:oe});const De=(q||!x)&&l!==void 0&&typeof l=="number",Xe=re.get(t.label)??[],Ze=d=>{const D=d();if(D?.priceRange){De&&(D.priceRange.minValue=l);for(const W of Xe)W<D.priceRange.minValue&&(D.priceRange.minValue=W),W>D.priceRange.maxValue&&(D.priceRange.maxValue=W)}return D},Ee=C.get(t.label)??u[0],Ie=Ee.formatter,Ke=Ee.tickmarksFormatter,ve={lineColor:B,topColor:y,bottomColor:z,priceScaleId:Fe,...t.seriesType==="line"&&{lineStyle:t.lineStyle??U.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:De&&typeof l=="number"?d=>Ie(d<l?l:d):Ie,tickmarksFormatter:Ke},autoscaleInfoProvider:Ze},ze=t.seriesType==="line";let F=R.current.get(t.label);const Y=t.data.map(d=>({...d,time:d.time}));if(X!==void 0&&Y.length>0&&Number(Y[0].time)>X){const d=Number(Y[0].time),D=d-X,W=86400,Qe=D>180*W?7*W:D>30*W?W:6*3600,qe=[];for(let Ce=X;Ce<d;Ce+=Qe)qe.push({time:Ce});Y.unshift(...qe)}F&&F.seriesType()!==(ze?"Line":"Area")&&(o.removeSeries(F),R.current.delete(t.label),F=void 0),F?(F.applyOptions(ve),F.setData(Y)):(ze?F=o.addSeries(U.LineSeries,{...J,...ve}):F=o.addSeries(U.AreaSeries,{...J,...ve}),F.setData(Y),R.current.set(t.label,F)),oe++}if(k)try{const r=o.priceScale("left"),t=o.priceScale("right"),f={visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:.1},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L};r?.applyOptions(f),t?.applyOptions(f)}catch{}else if(x&&te.length>0)for(const r of te)try{const t=o.priceScale(r.priceScaleId);t&&t.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...r.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch(t){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,t)}else if(!x)try{const r=o.priceScale("right");r&&r.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:l!==void 0||m?0:.1,...m&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:L})}catch{}if(l!==void 0&&!N&&(q||!x)&&o.applyOptions({handleScroll:{vertTouchDrag:!1}}),A.length>0){const r=A.map(y=>Number(y.time)),t=Math.min(...r),f=X!==void 0?Math.min(X,t):t,B=Math.max(...r);o.timeScale().setVisibleRange({from:f,to:B})}_e.current&&(_e.current=!1);const be=new Map;for(const r of e)r.data.length>0&&be.set(r.label,r.data[r.data.length-1]);pe(be.size>0?be:void 0)},[e,A,p,_,N,q,k,ye,we,Re,Te,X,M,$]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const a=e.length===1;let l;for(const s of e)if(s.data.length>0){l=s.data[s.data.length-1].time;break}if(!l)return;const n=s=>{const{time:g=l,seriesData:u,point:C}=s||{},S=Array.from(R.current.values());if(!C||!g){const T=new Map;for(const m of e)m.data.length>0&&T.set(m.label,m.data[m.data.length-1]);if(pe(T.size>0?T:void 0),a||q||ge)O(null);else if(S[0]&&l){const x=o.timeScale().timeToCoordinate(l),P=e[0];if(P.data.length>0){const L=P.data[P.data.length-1].value,V=S[0].priceToCoordinate(L);x!==null&&V!==null&&O({x,y:V})}}return}const G=new Map;let j;for(let T=0;T<e.length;T++){const m=e[T],x=S[T];if(!x)continue;const P=u?.get(x),L=P&&"value"in P?P.value:void 0;let V;if(L!==void 0)V=L;else if(a){const Q=Number(g),J=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;Q<J?V=Number.NaN:V=m.data[m.data.length-1]?.value??0}else V=$e(m.data,Number(g));Number.isNaN(V)||(j===void 0&&(j=V),G.set(m.label,{value:V,time:g}))}if(pe(G),j!==void 0&&S[0]){const m=o.timeScale().timeToCoordinate(g),x=S[0].priceToCoordinate(j);if(m!==null&&x!==null){const P=Z.current;if(P){const L=P.querySelector(".LightweightChart");if(L){const V=L.getBoundingClientRect(),Q=P.getBoundingClientRect(),J=m+(V.left-Q.left),te=x+(V.top-Q.top);O({x:J,y:te})}else O({x:m,y:x})}else O({x:m,y:x})}else O(null)}else O(null)};return o.subscribeCrosshairMove(n),N&&o.subscribeClick(n),!a&&!q&&!ge&&requestAnimationFrame(()=>{const s=Array.from(R.current.values());if(s[0]&&l&&e[0]?.data.length>0){const u=o.timeScale().timeToCoordinate(l),C=e[0].data[e[0].data.length-1].value,S=s[0].priceToCoordinate(C);u!==null&&S!==null&&O({x:u,y:S})}}),()=>{o.unsubscribeCrosshairMove(n),N&&o.unsubscribeClick(n)}},[e,q,N,ge]),b.useEffect(()=>{const o=I.current;if(!o||e.length===0)return;const a=o.timeScale(),l=()=>{const n=Ve.current;if(n.length===0)return;const s=a.getVisibleRange();if(!s)return;const g=Number(s.from),u=Number(s.to);for(const C of n){const S=[];for(const G of e)if(C.labels.has(G.label))for(const j of G.data){const T=Number(j.time);T>=g&&T<=u&&S.push(j.value)}S.length>0&&C.updateVisibleRange(S)}};return a.subscribeVisibleLogicalRangeChange(l),()=>{a.unsubscribeVisibleLogicalRangeChange(l)}},[e]),b.useEffect(()=>{const o=I.current,a=Array.from(R.current.values()),l=[];if(o&&a.length>0&&w){const n=ie.getDefaultVerticalLine(),s=a[0];for(const g of w){const u={...n,...g.options||{}};u.color&&(u.color=E.resolveCSSColor(u.color,u.color));const C=new et.VertLine(o,s,g.xCoordinate,u);s.attachPrimitive(C),l.push(C)}}return()=>{if(a.length>0){const n=a[0];for(const s of l)n.detachPrimitive(s)}}},[w,e]),b.useEffect(()=>{const o=[];if(M&&M.length>0){const a=Array.from(R.current.values())[0],l=E.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const n of M){if(!Number.isFinite(n.price))continue;const s=n.seriesLabel?R.current.get(n.seriesLabel):a;if(!s)continue;const g=s.createPriceLine({price:n.price,color:n.color?E.resolveCSSColor(n.color,n.color):l,lineWidth:n.lineWidth??1,lineStyle:n.lineStyle??U.LineStyle.Dashed,axisLabelVisible:n.axisLabelVisible??!0,title:n.title??""});o.push({series:s,line:g})}}return()=>{for(const{series:a,line:l}of o)try{a.removePriceLine(l)}catch{}}},[M,e]),b.useEffect(()=>{const o=[];if($&&$.length>0){const a=Array.from(R.current.values())[0],l="rgba(239, 68, 68, 0.12)";for(const n of $){const s=n.seriesLabel?R.current.get(n.seriesLabel):a;if(!s)continue;const g=n.color?E.resolveCSSColor(n.color,l):l,u=new nt(s,n.priceTop,n.priceBottom,g);s.attachPrimitive(u),o.push({series:s,zone:u})}}return()=>{for(const{series:a,zone:l}of o)try{a.detachPrimitive(l)}catch{}}},[$,e]),b.useEffect(()=>{const o=I.current;if(!o||!w?.length){Me([]);return}const a=()=>{const s=o.timeScale(),g=w.map(u=>s.timeToCoordinate(u.xCoordinate)??null);Me(g)};a();const l=o.timeScale(),n=()=>{a()};return l.subscribeVisibleLogicalRangeChange(n),()=>{l.unsubscribeVisibleLogicalRangeChange(n)}},[w,e]);const se=e.length===1,ke=Se.useMemo(()=>{if(se&&e.length>0){const o=e[0];if(o.data.length>0)return o.data[o.data.length-1]}},[se,e]);return v.jsxs("div",{ref:Z,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",i),children:[fe!=null&&fe!==!1&&se?v.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:v.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:fe})}):Oe&&se&&ke&&v.jsx(Ye.GraphCurrentValue,{point:ke,xMeasureUnit:p,yMeasureUnit:_,decimals:ue}),Ne&&Pe&&v.jsx(Ue.GraphTooltip,{points:Ne,xMeasureUnit:p,yMeasureUnit:_,series:e,position:Pe,containerRef:Z,decimals:ue}),c&&v.jsx(Ae,{series:e,onUnselect:h}),w&&w.length>0&&Le.length===w.length&&v.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:w.map((o,a)=>{const l=Le[a],n=o.options??{},s=n.showLabel!==!1;if(l===null||!s)return null;const{labelText:g,valueStr:u}=We(n,_,ue),C=n.tooltipText??"";if(!(g||u||C))return null;const G=n.labelBackgroundColor??n.color??"hsl(var(--background))",j=n.labelTextColor??"hsl(var(--foreground))",T=`${String(o.xCoordinate)}-${g}-${C}`;return v.jsxs("div",{className:ne.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",C&&"pointer-events-auto cursor-default"),style:{left:l,transform:"translateX(-50%)",backgroundColor:G,color:j},children:[g&&v.jsx("span",{className:"block",children:g}),u&&v.jsx("span",{className:ne.cn("block",g&&"mt-0.5"),children:u}),C&&v.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:C})]},T)})}),v.jsx("div",{ref:de,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ae({series:e,onUnselect:i,inline:c=!1}){return v.jsx("div",{className:ne.cn("flex flex-wrap gap-2",c?"items-center":"absolute top-0 left-2 z-[10]"),children:e.map((h,p)=>{const _=xe(p),H=(h.lineColor??h.color)||_.line,w=h.data.length===0;return v.jsxs("div",{className:ne.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",w&&"opacity-50"),children:[v.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:H}}),v.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[h.label,w&&" (no data)"]}),i&&v.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),i(h.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${h.label}`,children:v.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[v.jsx("title",{children:"Close"}),v.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),v.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},h.label)})})}exports.DEFAULT_SERIES_COLORS=ce;exports.Graph=at;exports.GraphLegend=Ae;exports.getSeriesColorPalette=xe;exports.getStepForwardValue=$e;exports.getVerticalLineTooltipContent=We;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),O=require("lightweight-charts"),v=require("react"),Je=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),I=require("../../utils/colors.cjs"),ie=require("./default-config.cjs"),ee=require("./formatters.cjs"),Ye=require("./graph-current-value.cjs"),Ue=require("./graph-tooltip.cjs"),et=require("./plugins/vertical-line.cjs");function tt(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const u in e)if(u!=="default"){const c=Object.getOwnPropertyDescriptor(e,u);Object.defineProperty(n,u,c.get?c:{enumerable:!0,get:()=>e[u]})}}return n.default=e,Object.freeze(n)}const Ce=tt(v);class ot{_yTop;_yBottom;_color;constructor(n,u,c){this._yTop=n,this._yBottom=u,this._color=c}draw(n){n.useBitmapCoordinateSpace(u=>{const c=u.context,g=u.verticalPixelRatio,C=this._yTop===null?0:this._yTop*g,E=this._yBottom===null?u.bitmapSize.height:this._yBottom*g,w=Math.min(C,E),k=Math.max(C,E);c.fillStyle=this._color,c.fillRect(0,w,u.bitmapSize.width,k-w)})}}class rt{_source;_yTop=null;_yBottom=null;constructor(n){this._source=n}update(){const n=this._source.series;this._yTop=this._source.priceTop===void 0?null:n.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:n.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new ot(this._yTop,this._yBottom,this._source.color)}}class nt{series;priceTop;priceBottom;color;_paneViews;constructor(n,u,c,g){this.series=n,this.priceTop=u,this.priceBottom=c,this.color=g,this._paneViews=[new rt(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function st(e,n){switch(e){case O.LineStyle.Dotted:return[n,n];case O.LineStyle.Dashed:return[2*n,2*n];case O.LineStyle.LargeDashed:return[6*n,6*n];case O.LineStyle.SparseDotted:return[n,4*n];default:return[]}}class lt{_y;_color;_lineWidth;_lineStyle;constructor(n,u,c,g){this._y=n,this._color=u,this._lineWidth=c,this._lineStyle=g}draw(n){n.useBitmapCoordinateSpace(u=>{if(this._y===null)return;const c=u.context,g=u.verticalPixelRatio,C=Math.max(1,Math.round(this._lineWidth*g)),E=Math.round(this._y*g);c.save(),c.strokeStyle=this._color,c.lineWidth=C,c.setLineDash(st(this._lineStyle,C)),c.beginPath(),c.moveTo(0,E),c.lineTo(u.bitmapSize.width,E),c.stroke(),c.restore()})}}class at{_source;_y=null;constructor(n){this._source=n}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new lt(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class it{series;price;color;lineWidth;lineStyle;_paneViews;constructor(n,u,c,g,C){this.series=n,this.price=u,this.color=c,this.lineWidth=g,this.lineStyle=C,this._paneViews=[new at(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function We(e,n,u){const c=e.labelText??"",g=e.value,C=g===void 0?"":typeof g=="number"?n==="$"?`$${ee.formatExactValue(g,void 0,u)}`:n==="%"?`${ee.formatExactValue(g,void 0,u)}%`:ee.formatExactValue(g,n!=="none"&&n!=="%"&&n!=="$"?n:void 0,u):String(g);return{labelText:c,valueStr:C}}function Oe(e,n){for(let u=e.length-1;u>=0;u--)if(Number(e[u].time)<=n)return e[u].value;return 0}const ce=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],ct=137.5;function xe(e){if(e<ce.length)return ce[e];const u=(e-ce.length)*ct%360,c=I.hslToHex(u,70,50),{topColor:g,bottomColor:C}=I.generateColorsFromBase(c);return{line:c,top:g,bottom:C}}function ut({series:e,className:n,showLegend:u=!1,onUnselectSeries:c,xMeasureUnit:g="time",yMeasureUnit:C="token",optionsOverrides:E,verticalLineOptions:w,priceLineOptions:k,zoneOptions:G,currentValueDecimals:ue,useSharedPriceScale:$=!1,dualYAxis:j=!1,defaultVisiblePriceScaleId:ye="right",leftPriceScaleTitle:_e,rightPriceScaleTitle:ft,showCurrentValue:Ae=!0,graphTitle:fe,yScaleMin:we,yScaleMinMultiple:Te,visibleTimeFrom:K,disableZoom:se=!1,hideDefaultTooltip:he=!1}){const z=v.useRef(null),y=v.useRef(new Map),ge=v.useRef(!1),Ve=v.useRef(!0),Re=v.useRef([]),Q=v.useRef(null),de=v.useRef(null),le=v.useRef(null),N=Je.useIsMobile(),H=Ce.useMemo(()=>e.flatMap(o=>o.data),[e]),Ge=Ce.useMemo(()=>{if(e.length>0){const o=e[e.length-1];if(o.data.length>0)return o.data[o.data.length-1]}},[e]),[Ne,pe]=v.useState(()=>{if(!Ge)return;const o=new Map;for(const i of e)i.data.length>0&&o.set(i.label,i.data[i.data.length-1]);return o}),[Pe,X]=v.useState(null),[Le,Me]=v.useState([]);v.useEffect(()=>{const o=()=>{try{if(z.current&&Q.current){const a=Q.current.clientWidth,l=Q.current.clientHeight;z.current.resize(a,l)}}catch{}},i=Q.current,s=i?new ResizeObserver(o):null;return le.current=s,i&&s?.observe(i),()=>{i&&s?.unobserve(i),s?.disconnect(),le.current=null}},[]),v.useEffect(()=>{if(!de.current||ge.current)return;const o=ie.getDefaultOptions(),i=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),s=se?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{},a=O.createChart(de.current,{...o,leftPriceScale:{...o.leftPriceScale||{},visible:!1,textColor:i},rightPriceScale:{...o.rightPriceScale||{},visible:!N,textColor:i},...N&&{crosshair:{...o.crosshair,mode:O.CrosshairMode.Magnet}},...s,...E});return z.current=a,ge.current=!0,()=>{le.current?.disconnect(),le.current=null,a.remove(),z.current=null,ge.current=!1,y.current.clear()}},[N,E,se]),v.useEffect(()=>{const o=z.current;o&&o.applyOptions(se?{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}})},[se]),v.useEffect(()=>{const o=z.current;if(!o||e.length===0)return;const s=e.filter(r=>r.data.length>0).length<=1?we:Te,a=g==="time"?ee.getXFormatters(g,H):ee.getXFormatters(g),l=new Map;{let r=0;for(const t of e)t.data.length!==0&&(l.set(t.label,t.priceScaleId??(r===0?"left":"right")),r++)}const f=(r,t,d)=>{const{formatter:D,tickmarksFormatter:R,updateVisibleRange:W,updateLastValues:je}=ee.createAdaptiveYAxisFormatter(r,t,{yScaleMin:s}),me=e.filter(J=>J.data.length>0&&d.has(J.label)).map(J=>J.data[J.data.length-1].value);return je(me),{formatter:D,tickmarksFormatter:R,updateVisibleRange:W,labels:d}},h=[];if(j)for(const r of["left","right"]){const t=new Set,d=[];let D=C;for(const R of e)if(R.data.length!==0&&l.get(R.label)===r){t.size===0&&R.yMeasureUnit&&(D=R.yMeasureUnit),t.add(R.label);for(const W of R.data)d.push(W.value)}t.size>0&&h.push(f(d,D,t))}else{const r=H.map(d=>d.value),t=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));h.push(f(r,C,t))}Re.current=h;const m=new Map;for(const r of h)for(const t of r.labels)m.set(t,r);const x=ie.getDefaultOptions();o.applyOptions({localization:{...x.localization||{},timeFormatter:r=>a.timeFormatter(parseFloat(r),void 0)},timeScale:{...x.timeScale||{},tickMarkFormatter:a.tickMarkFormatter,minBarSpacing:0}});const P=(H.length>0?Math.min(...H.map(r=>r.value)):0)<0,T=H.some(r=>r.value===0),p=!P&&T,_=!j&&e.length>1&&!$,L=j?N:e.length>1&&!$||N,M=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({...j&&{defaultVisiblePriceScaleId:ye},leftPriceScale:{...x.leftPriceScale||{},visible:j&&!N,textColor:M,...j&&_e&&{}},rightPriceScale:{...x.rightPriceScale||{},visible:j?!N:!L,textColor:M,...p&&!j&&{scaleMargins:{top:.3,bottom:0}}}});const V=new Set(y.current.keys()),Z=new Set(e.map(r=>r.label));for(const r of V)if(!Z.has(r)){const t=y.current.get(r);t&&(o.removeSeries(t),y.current.delete(r))}const Y=ie.getDefaultSeries(),te=[];let oe=0;const De=e.find(r=>r.data.length>0),re=new Map;if(k&&k.length>0)for(const r of k){if(!Number.isFinite(r.price))continue;const t=r.seriesLabel??De?.label;if(!t)continue;const d=re.get(t)??[];d.push(r.price),re.set(t,d)}if(G&&G.length>0)for(const r of G){const t=r.seriesLabel??De?.label;if(!t)continue;const d=re.get(t)??[];Number.isFinite(r.priceTop)&&d.push(r.priceTop),Number.isFinite(r.priceBottom)&&d.push(r.priceBottom),re.set(t,d)}for(let r=0;r<e.length;r++){const t=e[r],d=xe(r),D=t.lineColor??t.color??d.line;let R,W;if(t.lineColor??t.color)if(t.topColor&&t.bottomColor)R=t.topColor,W=t.bottomColor;else if(t.topColor){const b=I.generateColorsFromBase(D);R=t.topColor,W=b.bottomColor}else if(t.bottomColor)R=I.generateColorsFromBase(D).topColor,W=t.bottomColor;else{const b=I.generateColorsFromBase(D);R=b.topColor,W=b.bottomColor}else R=t.topColor||d.top,W=t.bottomColor||d.bottom;if(t.data.length===0){const b=y.current.get(t.label);b&&(o.removeSeries(b),y.current.delete(t.label));continue}const me=(t.data.length>0?Math.min(...t.data.map(b=>b.value)):0)<0,J=t.data.some(b=>b.value===0),He=!me&&J,Fe=j?t.priceScaleId??(oe===0?"left":"right"):$||!_||oe===0?"right":`scale-${oe}`;_&&te.push({priceScaleId:Fe||"right",shouldPreventNegativeAxis:He,seriesIndex:oe});const Be=($||!_)&&s!==void 0&&typeof s=="number",Xe=re.get(t.label)??[],Ze=b=>{const B=b();if(B?.priceRange){Be&&(B.priceRange.minValue=s);for(const A of Xe)A<B.priceRange.minValue&&(B.priceRange.minValue=A),A>B.priceRange.maxValue&&(B.priceRange.maxValue=A)}return B},Ie=m.get(t.label)??h[0],Ee=Ie.formatter,Ke=Ie.tickmarksFormatter,ve={lineColor:D,topColor:R,bottomColor:W,priceScaleId:Fe,...t.seriesType==="line"&&{lineStyle:t.lineStyle??O.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:Be&&typeof s=="number"?b=>Ee(b<s?s:b):Ee,tickmarksFormatter:Ke},autoscaleInfoProvider:Ze},ze=t.seriesType==="line";let F=y.current.get(t.label);const U=t.data.map(b=>({...b,time:b.time}));if(K!==void 0&&U.length>0&&Number(U[0].time)>K){const b=Number(U[0].time),B=b-K,A=86400,Qe=B>180*A?7*A:B>30*A?A:6*3600,qe=[];for(let Se=K;Se<b;Se+=Qe)qe.push({time:Se});U.unshift(...qe)}F&&F.seriesType()!==(ze?"Line":"Area")&&(o.removeSeries(F),y.current.delete(t.label),F=void 0),F?(F.applyOptions(ve),F.setData(U)):(ze?F=o.addSeries(O.LineSeries,{...Y,...ve}):F=o.addSeries(O.AreaSeries,{...Y,...ve}),F.setData(U),y.current.set(t.label,F)),oe++}if(j)try{const r=o.priceScale("left"),t=o.priceScale("right"),d={visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:.1},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M};r?.applyOptions(d),t?.applyOptions(d)}catch{}else if(_&&te.length>0)for(const r of te)try{const t=o.priceScale(r.priceScaleId);t&&t.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...r.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M})}catch(t){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,t)}else if(!_)try{const r=o.priceScale("right");r&&r.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:s!==void 0||p?0:.1,...p&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M})}catch{}if(s!==void 0&&!N&&($||!_)&&o.applyOptions({handleScroll:{vertTouchDrag:!1}}),H.length>0){const r=H.map(t=>Number(t.time)).filter(t=>Number.isFinite(t));if(r.length>0){const t=Math.min(...r),d=K!==void 0?Math.min(K,t):t,D=Math.max(...r);if(Number(d)<=Number(D))try{o.timeScale().setVisibleRange({from:d,to:D})}catch{try{o.timeScale().fitContent()}catch{}}}}Ve.current&&(Ve.current=!1);const be=new Map;for(const r of e)r.data.length>0&&be.set(r.label,r.data[r.data.length-1]);pe(be.size>0?be:void 0)},[e,H,g,C,N,$,j,ye,_e,we,Te,K,k,G]),v.useEffect(()=>{const o=z.current;if(!o||e.length===0)return;const i=e.length===1;let s;for(const l of e)if(l.data.length>0){s=l.data[l.data.length-1].time;break}if(!s)return;const a=l=>{const{time:f=s,seriesData:h,point:m}=l||{},x=Array.from(y.current.values());if(!m||!f){const T=new Map;for(const p of e)p.data.length>0&&T.set(p.label,p.data[p.data.length-1]);if(pe(T.size>0?T:void 0),i||$||he)X(null);else if(x[0]&&s){const _=o.timeScale().timeToCoordinate(s),L=e[0];if(L.data.length>0){const M=L.data[L.data.length-1].value,V=x[0].priceToCoordinate(M);_!==null&&V!==null&&X({x:_,y:V})}}return}const q=new Map;let P;for(let T=0;T<e.length;T++){const p=e[T],_=y.current.get(p.label);if(!_)continue;const L=h?.get(_),M=L&&"value"in L?L.value:void 0;let V;if(M!==void 0)V=M;else if(i){const Z=Number(f),Y=p.data.length>0?Number(p.data[0].time):Number.POSITIVE_INFINITY;Z<Y?V=Number.NaN:V=p.data[p.data.length-1]?.value??0}else{const Z=p.data.length>0?Number(p.data[0].time):Number.POSITIVE_INFINITY;if(Number(f)<Z)continue;V=Oe(p.data,Number(f))}Number.isNaN(V)||(P===void 0&&(P=V),q.set(p.label,{value:V,time:f}))}if(pe(q),P!==void 0&&x[0]){const p=o.timeScale().timeToCoordinate(f),_=x[0].priceToCoordinate(P);if(p!==null&&_!==null){const L=Q.current;if(L){const M=L.querySelector(".LightweightChart");if(M){const V=M.getBoundingClientRect(),Z=L.getBoundingClientRect(),Y=p+(V.left-Z.left),te=_+(V.top-Z.top);X({x:Y,y:te})}else X({x:p,y:_})}else X({x:p,y:_})}else X(null)}else X(null)};return o.subscribeCrosshairMove(a),N&&o.subscribeClick(a),!i&&!$&&!he&&requestAnimationFrame(()=>{const l=Array.from(y.current.values());if(l[0]&&s&&e[0]?.data.length>0){const h=o.timeScale().timeToCoordinate(s),m=e[0].data[e[0].data.length-1].value,x=l[0].priceToCoordinate(m);h!==null&&x!==null&&X({x:h,y:x})}}),()=>{o.unsubscribeCrosshairMove(a),N&&o.unsubscribeClick(a)}},[e,$,N,he]),v.useEffect(()=>{const o=z.current;if(!o||e.length===0)return;const i=o.timeScale(),s=()=>{const a=Re.current;if(a.length===0)return;const l=i.getVisibleRange();if(!l)return;const f=Number(l.from),h=Number(l.to);for(const m of a){const x=[];for(const q of e)if(m.labels.has(q.label))for(const P of q.data){const T=Number(P.time);T>=f&&T<=h&&x.push(P.value)}x.length>0&&m.updateVisibleRange(x)}};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[e]),v.useEffect(()=>{const o=z.current,i=Array.from(y.current.values()),s=[];if(o&&i.length>0&&w){const a=ie.getDefaultVerticalLine(),l=i[0];for(const f of w){const h={...a,...f.options||{}};h.color&&(h.color=I.resolveCSSColor(h.color,h.color));const m=new et.VertLine(o,l,f.xCoordinate,h);l.attachPrimitive(m),s.push(m)}}return()=>{if(i.length>0){const a=i[0];for(const l of s)a.detachPrimitive(l)}}},[w,e]),v.useEffect(()=>{const o=[],i=[];if(k&&k.length>0){const s=Array.from(y.current.values())[0],a=I.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const l of k){if(!Number.isFinite(l.price))continue;const f=l.seriesLabel?y.current.get(l.seriesLabel):s;if(!f)continue;const h=l.color?I.resolveCSSColor(l.color,l.color):a,m=l.lineWidth??1,x=l.lineStyle??O.LineStyle.Dashed,q=f.createPriceLine({price:l.price,color:h,lineWidth:m,lineStyle:x,axisLabelVisible:l.axisLabelVisible??!0,title:l.title??""});o.push({series:f,line:q});const P=new it(f,l.price,h,m,x);f.attachPrimitive(P),i.push({series:f,primitive:P})}}return()=>{for(const{series:s,primitive:a}of i)try{s.detachPrimitive(a)}catch{}for(const{series:s,line:a}of o)try{s.removePriceLine(a)}catch{}}},[k,e]),v.useEffect(()=>{const o=[];if(G&&G.length>0){const i=Array.from(y.current.values())[0],s="rgba(239, 68, 68, 0.12)";for(const a of G){const l=a.seriesLabel?y.current.get(a.seriesLabel):i;if(!l)continue;const f=a.color?I.resolveCSSColor(a.color,s):s,h=new nt(l,a.priceTop,a.priceBottom,f);l.attachPrimitive(h),o.push({series:l,zone:h})}}return()=>{for(const{series:i,zone:s}of o)try{i.detachPrimitive(s)}catch{}}},[G,e]),v.useEffect(()=>{const o=z.current;if(!o||!w?.length){Me([]);return}const i=()=>{const l=o.timeScale(),f=w.map(h=>l.timeToCoordinate(h.xCoordinate)??null);Me(f)};i();const s=o.timeScale(),a=()=>{i()};return s.subscribeVisibleLogicalRangeChange(a),()=>{s.unsubscribeVisibleLogicalRangeChange(a)}},[w,e]);const ae=e.length===1,ke=Ce.useMemo(()=>{if(ae&&e.length>0){const o=e[0];if(o.data.length>0)return o.data[o.data.length-1]}},[ae,e]);return S.jsxs("div",{ref:Q,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[fe!=null&&fe!==!1&&ae?S.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:S.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:fe})}):Ae&&ae&&ke&&S.jsx(Ye.GraphCurrentValue,{point:ke,xMeasureUnit:g,yMeasureUnit:C,decimals:ue}),Ne&&Pe&&S.jsx(Ue.GraphTooltip,{points:Ne,xMeasureUnit:g,yMeasureUnit:C,series:e,position:Pe,containerRef:Q,decimals:ue}),u&&S.jsx($e,{series:e,onUnselect:c}),w&&w.length>0&&Le.length===w.length&&S.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:w.map((o,i)=>{const s=Le[i],a=o.options??{},l=a.showLabel!==!1;if(s===null||!l)return null;const{labelText:f,valueStr:h}=We(a,C,ue),m=a.tooltipText??"";if(!(f||h||m))return null;const q=a.labelBackgroundColor??a.color??"hsl(var(--background))",P=a.labelTextColor??"hsl(var(--foreground))",T=`${String(o.xCoordinate)}-${f}-${m}`;return S.jsxs("div",{className:ne.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",m&&"pointer-events-auto cursor-default"),style:{left:s,transform:"translateX(-50%)",backgroundColor:q,color:P},children:[f&&S.jsx("span",{className:"block",children:f}),h&&S.jsx("span",{className:ne.cn("block",f&&"mt-0.5"),children:h}),m&&S.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})]},T)})}),S.jsx("div",{ref:de,className:"LightweightChart w-full h-full overflow-hidden"})]})}function $e({series:e,onUnselect:n,inline:u=!1}){return S.jsx("div",{className:ne.cn("flex flex-wrap gap-2",u?"items-center":"absolute top-0 left-2 z-[10]"),children:e.map((c,g)=>{const C=xe(g),E=(c.lineColor??c.color)||C.line,w=c.data.length===0;return S.jsxs("div",{className:ne.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",w&&"opacity-50"),children:[S.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:E}}),S.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[c.label,w&&" (no data)"]}),n&&S.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),n(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:S.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:[S.jsx("title",{children:"Close"}),S.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},c.label)})})}exports.DEFAULT_SERIES_COLORS=ce;exports.Graph=ut;exports.GraphLegend=$e;exports.getSeriesColorPalette=xe;exports.getStepForwardValue=Oe;exports.getVerticalLineTooltipContent=We;