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