@gearbox-protocol/ui-kit 3.14.0-next.39 → 3.14.0-next.40
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"),G=require("lightweight-charts"),m=require("react"),tt=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),F=require("../../utils/colors.cjs"),ie=require("./default-config.cjs"),ee=require("./formatters.cjs"),ot=require("./graph-current-value.cjs"),rt=require("./graph-tooltip.cjs"),nt=require("./plugins/vertical-line.cjs");function st(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=st(m);class lt{_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,z=this._yBottom===null?u.bitmapSize.height:this._yBottom*g,w=Math.min(C,z),k=Math.max(C,z);c.fillStyle=this._color,c.fillRect(0,w,u.bitmapSize.width,k-w)})}}class at{_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 lt(this._yTop,this._yBottom,this._source.color)}}class it{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 at(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function ct(e,n){switch(e){case G.LineStyle.Dotted:return[n,n];case G.LineStyle.Dashed:return[2*n,2*n];case G.LineStyle.LargeDashed:return[6*n,6*n];case G.LineStyle.SparseDotted:return[n,4*n];default:return[]}}class ut{_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)),z=Math.round(this._y*g);c.save(),c.strokeStyle=this._color,c.lineWidth=C,c.setLineDash(ct(this._lineStyle,C)),c.beginPath(),c.moveTo(0,z),c.lineTo(u.bitmapSize.width,z),c.stroke(),c.restore()})}}class ft{_source;_y=null;constructor(n){this._source=n}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new ut(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class ht{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 ft(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function Ge(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}}const xe=40;function Oe(e,n){return n<=0?{left:e,transform:"translateX(-50%)"}:e<=xe?{left:e,transform:"translateX(4px)"}:e>=n-xe?{left:e,transform:"translateX(calc(-100% - 4px))"}:{left:e,transform:"translateX(-50%)"}}function $e(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)"}],gt=137.5;function ye(e){if(e<ce.length)return ce[e];const u=(e-ce.length)*gt%360,c=F.hslToHex(u,70,50),{topColor:g,bottomColor:C}=F.generateColorsFromBase(c);return{line:c,top:g,bottom:C}}function dt({series:e,className:n,showLegend:u=!1,onUnselectSeries:c,xMeasureUnit:g="time",yMeasureUnit:C="token",optionsOverrides:z,verticalLineOptions:w,priceLineOptions:k,zoneOptions:X,currentValueDecimals:ue,useSharedPriceScale:O=!1,dualYAxis:E=!1,defaultVisiblePriceScaleId:_e="right",leftPriceScaleTitle:we,rightPriceScaleTitle:pt,showCurrentValue:He=!0,graphTitle:fe,yScaleMin:Le,yScaleMinMultiple:Te,visibleTimeFrom:Q,disableZoom:se=!1,hideDefaultTooltip:he=!1}){const A=m.useRef(null),y=m.useRef(new Map),ge=m.useRef(!1),Ve=m.useRef(!0),Ne=m.useRef([]),I=m.useRef(null),de=m.useRef(null),le=m.useRef(null),N=tt.useIsMobile(),H=Ce.useMemo(()=>e.flatMap(o=>o.data),[e]),Ze=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]),[Re,pe]=m.useState(()=>{if(!Ze)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,Z]=m.useState(null),[Me,ke]=m.useState([]),[Ke,De]=m.useState(0);m.useEffect(()=>{const o=()=>{try{if(I.current&&De(I.current.clientWidth),A.current&&I.current){const a=I.current.clientWidth,l=I.current.clientHeight;A.current.resize(a,l)}}catch{}},i=I.current,s=i?new ResizeObserver(o):null;return le.current=s,i&&s?.observe(i),()=>{i&&s?.unobserve(i),s?.disconnect(),le.current=null}},[]),m.useEffect(()=>{if(!de.current||ge.current)return;const o=ie.getDefaultOptions(),i=F.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=G.createChart(de.current,{...o,leftPriceScale:{...o.leftPriceScale||{},visible:!1,textColor:i},rightPriceScale:{...o.rightPriceScale||{},visible:!N,textColor:i},...N&&{crosshair:{...o.crosshair,mode:G.CrosshairMode.Magnet}},...s,...z});return A.current=a,ge.current=!0,()=>{le.current?.disconnect(),le.current=null,a.remove(),A.current=null,ge.current=!1,y.current.clear()}},[N,z,se]),m.useEffect(()=>{const o=A.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]),m.useEffect(()=>{const o=A.current;if(!o||e.length===0)return;const s=e.filter(r=>r.data.length>0).length<=1?Le: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:V,updateVisibleRange:q,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:V,updateVisibleRange:q,labels:d}},h=[];if(E)for(const r of["left","right"]){const t=new Set,d=[];let D=C;for(const V of e)if(V.data.length!==0&&l.get(V.label)===r){t.size===0&&V.yMeasureUnit&&(D=V.yMeasureUnit),t.add(V.label);for(const q of V.data)d.push(q.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))}Ne.current=h;const S=new Map;for(const r of h)for(const t of r.labels)S.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 R=(H.length>0?Math.min(...H.map(r=>r.value)):0)<0,L=H.some(r=>r.value===0),p=!R&&L,_=!E&&e.length>1&&!O,P=E?N:e.length>1&&!O||N,M=F.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({...E&&{defaultVisiblePriceScaleId:_e},leftPriceScale:{...x.leftPriceScale||{},visible:E&&!N,textColor:M,...E&&we&&{}},rightPriceScale:{...x.rightPriceScale||{},visible:E?!N:!P,textColor:M,...p&&!E&&{scaleMargins:{top:.3,bottom:0}}}});const T=new Set(y.current.keys()),K=new Set(e.map(r=>r.label));for(const r of T)if(!K.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 Ie=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??Ie?.label;if(!t)continue;const d=re.get(t)??[];d.push(r.price),re.set(t,d)}if(X&&X.length>0)for(const r of X){const t=r.seriesLabel??Ie?.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=ye(r),D=t.lineColor??t.color??d.line;let V,q;if(t.lineColor??t.color)if(t.topColor&&t.bottomColor)V=t.topColor,q=t.bottomColor;else if(t.topColor){const b=F.generateColorsFromBase(D);V=t.topColor,q=b.bottomColor}else if(t.bottomColor)V=F.generateColorsFromBase(D).topColor,q=t.bottomColor;else{const b=F.generateColorsFromBase(D);V=b.topColor,q=b.bottomColor}else V=t.topColor||d.top,q=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),Qe=!me&&J,Be=E?t.priceScaleId??(oe===0?"left":"right"):O||!_||oe===0?"right":`scale-${oe}`;_&&te.push({priceScaleId:Be||"right",shouldPreventNegativeAxis:Qe,seriesIndex:oe});const Fe=(O||!_)&&s!==void 0&&typeof s=="number",Je=re.get(t.label)??[],Ye=b=>{const B=b();if(B?.priceRange){Fe&&(B.priceRange.minValue=s);for(const $ of Je)$<B.priceRange.minValue&&(B.priceRange.minValue=$),$>B.priceRange.maxValue&&(B.priceRange.maxValue=$)}return B},ze=S.get(t.label)??h[0],Ae=ze.formatter,Ue=ze.tickmarksFormatter,Se={lineColor:D,topColor:V,bottomColor:q,priceScaleId:Be,...t.seriesType==="line"&&{lineStyle:t.lineStyle??G.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:Fe&&typeof s=="number"?b=>Ae(b<s?s:b):Ae,tickmarksFormatter:Ue},autoscaleInfoProvider:Ye},We=t.seriesType==="line";let j=y.current.get(t.label);const U=t.data.map(b=>({...b,time:b.time}));if(Q!==void 0&&U.length>0&&Number(U[0].time)>Q){const b=Number(U[0].time),B=b-Q,$=86400,et=B>180*$?7*$:B>30*$?$:6*3600,qe=[];for(let ve=Q;ve<b;ve+=et)qe.push({time:ve});U.unshift(...qe)}j&&j.seriesType()!==(We?"Line":"Area")&&(o.removeSeries(j),y.current.delete(t.label),j=void 0),j?(j.applyOptions(Se),j.setData(U)):(We?j=o.addSeries(G.LineSeries,{...Y,...Se}):j=o.addSeries(G.AreaSeries,{...Y,...Se}),j.setData(U),y.current.set(t.label,j)),oe++}if(E)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||!_)&&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=Q!==void 0?Math.min(Q,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,O,E,_e,we,Le,Te,Q,k,X]),m.useEffect(()=>{const o=A.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:S}=l||{},x=Array.from(y.current.values());if(!S||!f){const L=new Map;for(const p of e)p.data.length>0&&L.set(p.label,p.data[p.data.length-1]);if(pe(L.size>0?L:void 0),i||O||he)Z(null);else if(x[0]&&s){const _=o.timeScale().timeToCoordinate(s),P=e[0];if(P.data.length>0){const M=P.data[P.data.length-1].value,T=x[0].priceToCoordinate(M);_!==null&&T!==null&&Z({x:_,y:T})}}return}const W=new Map;let R;for(let L=0;L<e.length;L++){const p=e[L],_=y.current.get(p.label);if(!_)continue;const P=h?.get(_),M=P&&"value"in P?P.value:void 0;let T;if(M!==void 0)T=M;else if(i){const K=Number(f),Y=p.data.length>0?Number(p.data[0].time):Number.POSITIVE_INFINITY;K<Y?T=Number.NaN:T=p.data[p.data.length-1]?.value??0}else{const K=p.data.length>0?Number(p.data[0].time):Number.POSITIVE_INFINITY;if(Number(f)<K)continue;T=$e(p.data,Number(f))}Number.isNaN(T)||(R===void 0&&(R=T),W.set(p.label,{value:T,time:f}))}if(pe(W),R!==void 0&&x[0]){const p=o.timeScale().timeToCoordinate(f),_=x[0].priceToCoordinate(R);if(p!==null&&_!==null){const P=I.current;if(P){const M=P.querySelector(".LightweightChart");if(M){const T=M.getBoundingClientRect(),K=P.getBoundingClientRect(),Y=p+(T.left-K.left),te=_+(T.top-K.top);Z({x:Y,y:te})}else Z({x:p,y:_})}else Z({x:p,y:_})}else Z(null)}else Z(null)};return o.subscribeCrosshairMove(a),N&&o.subscribeClick(a),!i&&!O&&!he&&requestAnimationFrame(()=>{const l=Array.from(y.current.values());if(l[0]&&s&&e[0]?.data.length>0){const h=o.timeScale().timeToCoordinate(s),S=e[0].data[e[0].data.length-1].value,x=l[0].priceToCoordinate(S);h!==null&&x!==null&&Z({x:h,y:x})}}),()=>{o.unsubscribeCrosshairMove(a),N&&o.unsubscribeClick(a)}},[e,O,N,he]),m.useEffect(()=>{const o=A.current;if(!o||e.length===0)return;const i=o.timeScale(),s=()=>{const a=Ne.current;if(a.length===0)return;const l=i.getVisibleRange();if(!l)return;const f=Number(l.from),h=Number(l.to);for(const S of a){const x=[];for(const W of e)if(S.labels.has(W.label))for(const R of W.data){const L=Number(R.time);L>=f&&L<=h&&x.push(R.value)}x.length>0&&S.updateVisibleRange(x)}};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[e]),m.useEffect(()=>{const o=A.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=F.resolveCSSColor(h.color,h.color));const S=new nt.VertLine(o,l,f.xCoordinate,h);l.attachPrimitive(S),s.push(S)}}return()=>{if(i.length>0){const a=i[0];for(const l of s)a.detachPrimitive(l)}}},[w,e]),m.useEffect(()=>{const o=[],i=[];if(k&&k.length>0){const s=Array.from(y.current.values())[0],a=F.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?F.resolveCSSColor(l.color,l.color):a,S=l.lineWidth??1,x=l.lineStyle??G.LineStyle.Dashed,W=f.createPriceLine({price:l.price,color:h,lineWidth:S,lineStyle:x,axisLabelVisible:l.axisLabelVisible??!0,title:l.title??""});o.push({series:f,line:W});const R=new ht(f,l.price,h,S,x);f.attachPrimitive(R),i.push({series:f,primitive:R})}}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]),m.useEffect(()=>{const o=[];if(X&&X.length>0){const i=Array.from(y.current.values())[0],s="rgba(239, 68, 68, 0.12)";for(const a of X){const l=a.seriesLabel?y.current.get(a.seriesLabel):i;if(!l)continue;const f=a.color?F.resolveCSSColor(a.color,s):s,h=new it(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{}}},[X,e]),m.useEffect(()=>{const o=A.current;if(!o||!w?.length){ke([]);return}const i=()=>{const l=o.timeScale(),f=w.map(h=>l.timeToCoordinate(h.xCoordinate)??null);ke(f),I.current&&De(I.current.clientWidth)};i();const s=o.timeScale(),a=()=>{i()};return s.subscribeVisibleLogicalRangeChange(a),()=>{s.unsubscribeVisibleLogicalRangeChange(a)}},[w,e]);const ae=e.length===1,Ee=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 v.jsxs("div",{ref:I,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[fe!=null&&fe!==!1&&ae?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})}):He&&ae&&Ee&&v.jsx(ot.GraphCurrentValue,{point:Ee,xMeasureUnit:g,yMeasureUnit:C,decimals:ue}),Re&&Pe&&v.jsx(rt.GraphTooltip,{points:Re,xMeasureUnit:g,yMeasureUnit:C,series:e,position:Pe,containerRef:I,decimals:ue}),u&&v.jsx(Xe,{series:e,onUnselect:c}),w&&w.length>0&&Me.length===w.length&&v.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:w.map((o,i)=>{const s=Me[i],a=o.options??{},l=a.showLabel!==!1;if(s===null||!l)return null;const{labelText:f,valueStr:h}=Ge(a,C,ue),S=a.tooltipText??"";if(!(f||h||S))return null;const W=a.labelBackgroundColor??a.color??"hsl(var(--background))",R=a.labelTextColor??"hsl(var(--foreground))",L=`${String(o.xCoordinate)}-${f}-${S}`,p=Oe(s,Ke);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",S&&"pointer-events-auto cursor-default"),style:{...p,backgroundColor:W,color:R},children:[f&&v.jsx("span",{className:"block",children:f}),h&&v.jsx("span",{className:ne.cn("block",f&&"mt-0.5"),children:h}),S&&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:S})]},L)})}),v.jsx("div",{ref:de,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Xe({series:e,onUnselect:n,inline:u=!1}){return v.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=ye(g),z=(c.lineColor??c.color)||C.line,w=c.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:z}}),v.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[c.label,w&&" (no data)"]}),n&&v.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: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"})]})})]},c.label)})})}exports.DEFAULT_SERIES_COLORS=ce;exports.Graph=dt;exports.GraphLegend=Xe;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=xe;exports.getSeriesColorPalette=ye;exports.getStepForwardValue=$e;exports.getVerticalLineLabelStyle=Oe;exports.getVerticalLineTooltipContent=Ge;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),q=require("lightweight-charts"),p=require("react"),lt=require("../../hooks/use-media-query.cjs"),ne=require("../../utils/cn.cjs"),z=require("../../utils/colors.cjs"),ce=require("./default-config.cjs"),ee=require("./formatters.cjs"),at=require("./graph-current-value.cjs"),it=require("./graph-tooltip.cjs"),ct=require("./plugins/vertical-line.cjs");function ut(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const c in e)if(c!=="default"){const u=Object.getOwnPropertyDescriptor(e,c);Object.defineProperty(n,c,u.get?u:{enumerable:!0,get:()=>e[c]})}}return n.default=e,Object.freeze(n)}const xe=ut(p);class ft{_yTop;_yBottom;_color;constructor(n,c,u){this._yTop=n,this._yBottom=c,this._color=u}draw(n){n.useBitmapCoordinateSpace(c=>{const u=c.context,h=c.verticalPixelRatio,S=this._yTop===null?0:this._yTop*h,P=this._yBottom===null?c.bitmapSize.height:this._yBottom*h,_=Math.min(S,P),E=Math.max(S,P);u.fillStyle=this._color,u.fillRect(0,_,c.bitmapSize.width,E-_)})}}class ht{_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 ft(this._yTop,this._yBottom,this._source.color)}}class gt{series;priceTop;priceBottom;color;_paneViews;constructor(n,c,u,h){this.series=n,this.priceTop=c,this.priceBottom=u,this.color=h,this._paneViews=[new ht(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function dt(e,n){switch(e){case q.LineStyle.Dotted:return[n,n];case q.LineStyle.Dashed:return[2*n,2*n];case q.LineStyle.LargeDashed:return[6*n,6*n];case q.LineStyle.SparseDotted:return[n,4*n];default:return[]}}class pt{_y;_color;_lineWidth;_lineStyle;constructor(n,c,u,h){this._y=n,this._color=c,this._lineWidth=u,this._lineStyle=h}draw(n){n.useBitmapCoordinateSpace(c=>{if(this._y===null)return;const u=c.context,h=c.verticalPixelRatio,S=Math.max(1,Math.round(this._lineWidth*h)),P=Math.round(this._y*h);u.save(),u.strokeStyle=this._color,u.lineWidth=S,u.setLineDash(dt(this._lineStyle,S)),u.beginPath(),u.moveTo(0,P),u.lineTo(c.bitmapSize.width,P),u.stroke(),u.restore()})}}class bt{_source;_y=null;constructor(n){this._source=n}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new pt(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class mt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(n,c,u,h,S){this.series=n,this.price=c,this.color=u,this.lineWidth=h,this.lineStyle=S,this._paneViews=[new bt(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function $e(e,n,c){const u=e.labelText??"",h=e.value,S=h===void 0?"":typeof h=="number"?n==="$"?`$${ee.formatExactValue(h,void 0,c)}`:n==="%"?`${ee.formatExactValue(h,void 0,c)}%`:ee.formatExactValue(h,n!=="none"&&n!=="%"&&n!=="$"?n:void 0,c):String(h);return{labelText:u,valueStr:S}}const ye=4;function Xe(e,n,c){const u={left:e,transform:"translateX(-50%)"};if(n<=0||!c||c<=0)return u;const h=c/2,S=ye+h,P=n-ye-h;return P<S?{left:n/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,S),P),transform:"translateX(-50%)"}}function He(e,n){for(let c=e.length-1;c>=0;c--)if(Number(e[c].time)<=n)return e[c].value;return 0}const ue=[{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)"}],St=137.5;function _e(e){if(e<ue.length)return ue[e];const c=(e-ue.length)*St%360,u=z.hslToHex(c,70,50),{topColor:h,bottomColor:S}=z.generateColorsFromBase(u);return{line:u,top:h,bottom:S}}function vt({series:e,className:n,showLegend:c=!1,onUnselectSeries:u,xMeasureUnit:h="time",yMeasureUnit:S="token",optionsOverrides:P,verticalLineOptions:_,priceLineOptions:E,zoneOptions:X,currentValueDecimals:fe,useSharedPriceScale:G=!1,dualYAxis:I=!1,defaultVisiblePriceScaleId:we="right",leftPriceScaleTitle:Le,rightPriceScaleTitle:Ct,showCurrentValue:Ke=!0,graphTitle:he,yScaleMin:Te,yScaleMinMultiple:Ve,visibleTimeFrom:Q,disableZoom:se=!1,hideDefaultTooltip:ge=!1}){const A=p.useRef(null),w=p.useRef(new Map),de=p.useRef(!1),Re=p.useRef(!0),Ne=p.useRef([]),j=p.useRef(null),pe=p.useRef(null),le=p.useRef(null),R=lt.useIsMobile(),H=xe.useMemo(()=>e.flatMap(t=>t.data),[e]),Qe=xe.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[Pe,be]=p.useState(()=>{if(!Qe)return;const t=new Map;for(const a of e)a.data.length>0&&t.set(a.label,a.data[a.data.length-1]);return t}),[Me,Z]=p.useState(null),[ke,Ee]=p.useState([]),[Je,De]=p.useState(0),Ie=p.useRef(new Map),[Ye,Ue]=p.useState({}),[ae,et]=p.useState(0);p.useEffect(()=>{const t=()=>{try{if(j.current&&De(j.current.clientWidth),A.current&&j.current){const i=j.current.clientWidth,l=j.current.clientHeight;A.current.resize(i,l)}}catch{}},a=j.current,s=a?new ResizeObserver(t):null;return le.current=s,a&&s?.observe(a),()=>{a&&s?.unobserve(a),s?.disconnect(),le.current=null}},[]),p.useEffect(()=>{if(!pe.current||de.current)return;const t=ce.getDefaultOptions(),a=z.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}}:{},i=q.createChart(pe.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:a},rightPriceScale:{...t.rightPriceScale||{},visible:!R,textColor:a},...R&&{crosshair:{...t.crosshair,mode:q.CrosshairMode.Magnet}},...s,...P});return A.current=i,de.current=!0,et(l=>l+1),()=>{le.current?.disconnect(),le.current=null,i.remove(),A.current=null,de.current=!1,w.current.clear()}},[R,P,se]),p.useEffect(()=>{const t=A.current;t&&t.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]),p.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const s=e.filter(r=>r.data.length>0).length<=1?Te:Ve,i=h==="time"?ee.getXFormatters(h,H):ee.getXFormatters(h),l=new Map;{let r=0;for(const o of e)o.data.length!==0&&(l.set(o.label,o.priceScaleId??(r===0?"left":"right")),r++)}const f=(r,o,d)=>{const{formatter:D,tickmarksFormatter:V,updateVisibleRange:O,updateLastValues:Fe}=ee.createAdaptiveYAxisFormatter(r,o,{yScaleMin:s}),Se=e.filter(J=>J.data.length>0&&d.has(J.label)).map(J=>J.data[J.data.length-1].value);return Fe(Se),{formatter:D,tickmarksFormatter:V,updateVisibleRange:O,labels:d}},g=[];if(I)for(const r of["left","right"]){const o=new Set,d=[];let D=S;for(const V of e)if(V.data.length!==0&&l.get(V.label)===r){o.size===0&&V.yMeasureUnit&&(D=V.yMeasureUnit),o.add(V.label);for(const O of V.data)d.push(O.value)}o.size>0&&g.push(f(d,D,o))}else{const r=H.map(d=>d.value),o=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));g.push(f(r,S,o))}Ne.current=g;const v=new Map;for(const r of g)for(const o of r.labels)v.set(o,r);const x=ce.getDefaultOptions();t.applyOptions({localization:{...x.localization||{},timeFormatter:r=>i.timeFormatter(parseFloat(r),void 0)},timeScale:{...x.timeScale||{},tickMarkFormatter:i.tickMarkFormatter,minBarSpacing:0}});const N=(H.length>0?Math.min(...H.map(r=>r.value)):0)<0,L=H.some(r=>r.value===0),b=!N&&L,y=!I&&e.length>1&&!G,M=I?R:e.length>1&&!G||R,k=z.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({...I&&{defaultVisiblePriceScaleId:we},leftPriceScale:{...x.leftPriceScale||{},visible:I&&!R,textColor:k,...I&&Le&&{}},rightPriceScale:{...x.rightPriceScale||{},visible:I?!R:!M,textColor:k,...b&&!I&&{scaleMargins:{top:.3,bottom:0}}}});const T=new Set(w.current.keys()),K=new Set(e.map(r=>r.label));for(const r of T)if(!K.has(r)){const o=w.current.get(r);o&&(t.removeSeries(o),w.current.delete(r))}const Y=ce.getDefaultSeries(),te=[];let oe=0;const Be=e.find(r=>r.data.length>0),re=new Map;if(E&&E.length>0)for(const r of E){if(!Number.isFinite(r.price))continue;const o=r.seriesLabel??Be?.label;if(!o)continue;const d=re.get(o)??[];d.push(r.price),re.set(o,d)}if(X&&X.length>0)for(const r of X){const o=r.seriesLabel??Be?.label;if(!o)continue;const d=re.get(o)??[];Number.isFinite(r.priceTop)&&d.push(r.priceTop),Number.isFinite(r.priceBottom)&&d.push(r.priceBottom),re.set(o,d)}for(let r=0;r<e.length;r++){const o=e[r],d=_e(r),D=o.lineColor??o.color??d.line;let V,O;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)V=o.topColor,O=o.bottomColor;else if(o.topColor){const m=z.generateColorsFromBase(D);V=o.topColor,O=m.bottomColor}else if(o.bottomColor)V=z.generateColorsFromBase(D).topColor,O=o.bottomColor;else{const m=z.generateColorsFromBase(D);V=m.topColor,O=m.bottomColor}else V=o.topColor||d.top,O=o.bottomColor||d.bottom;if(o.data.length===0){const m=w.current.get(o.label);m&&(t.removeSeries(m),w.current.delete(o.label));continue}const Se=(o.data.length>0?Math.min(...o.data.map(m=>m.value)):0)<0,J=o.data.some(m=>m.value===0),tt=!Se&&J,ze=I?o.priceScaleId??(oe===0?"left":"right"):G||!y||oe===0?"right":`scale-${oe}`;y&&te.push({priceScaleId:ze||"right",shouldPreventNegativeAxis:tt,seriesIndex:oe});const Ae=(G||!y)&&s!==void 0&&typeof s=="number",ot=re.get(o.label)??[],rt=m=>{const F=m();if(F?.priceRange){Ae&&(F.priceRange.minValue=s);for(const $ of ot)$<F.priceRange.minValue&&(F.priceRange.minValue=$),$>F.priceRange.maxValue&&(F.priceRange.maxValue=$)}return F},We=v.get(o.label)??g[0],Oe=We.formatter,nt=We.tickmarksFormatter,ve={lineColor:D,topColor:V,bottomColor:O,priceScaleId:ze,...o.seriesType==="line"&&{lineStyle:o.lineStyle??q.LineStyle.Solid},priceFormat:{type:"custom",minMove:.01,formatter:Ae&&typeof s=="number"?m=>Oe(m<s?s:m):Oe,tickmarksFormatter:nt},autoscaleInfoProvider:rt},qe=o.seriesType==="line";let B=w.current.get(o.label);const U=o.data.map(m=>({...m,time:m.time}));if(Q!==void 0&&U.length>0&&Number(U[0].time)>Q){const m=Number(U[0].time),F=m-Q,$=86400,st=F>180*$?7*$:F>30*$?$:6*3600,Ge=[];for(let Ce=Q;Ce<m;Ce+=st)Ge.push({time:Ce});U.unshift(...Ge)}B&&B.seriesType()!==(qe?"Line":"Area")&&(t.removeSeries(B),w.current.delete(o.label),B=void 0),B?(B.applyOptions(ve),B.setData(U)):(qe?B=t.addSeries(q.LineSeries,{...Y,...ve}):B=t.addSeries(q.AreaSeries,{...Y,...ve}),B.setData(U),w.current.set(o.label,B)),oe++}if(I)try{const r=t.priceScale("left"),o=t.priceScale("right"),d={visible:!R,autoScale:!0,scaleMargins:{top:.1,bottom:.1},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:k};r?.applyOptions(d),o?.applyOptions(d)}catch{}else if(y&&te.length>0)for(const r of te)try{const o=t.priceScale(r.priceScaleId);o&&o.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:k})}catch(o){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,o)}else if(!y)try{const r=t.priceScale("right");r&&r.applyOptions({visible:!R,autoScale:!0,scaleMargins:{top:.1,bottom:s!==void 0||b?0:.1,...b&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:k})}catch{}if(s!==void 0&&!R&&(G||!y)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),H.length>0){const r=H.map(o=>Number(o.time)).filter(o=>Number.isFinite(o));if(r.length>0){const o=Math.min(...r),d=Q!==void 0?Math.min(Q,o):o,D=Math.max(...r);if(Number(d)<=Number(D))try{t.timeScale().setVisibleRange({from:d,to:D})}catch{try{t.timeScale().fitContent()}catch{}}}}Re.current&&(Re.current=!1);const me=new Map;for(const r of e)r.data.length>0&&me.set(r.label,r.data[r.data.length-1]);be(me.size>0?me:void 0)},[e,H,h,S,R,G,I,we,Le,Te,Ve,Q,E,X]),p.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=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 i=l=>{const{time:f=s,seriesData:g,point:v}=l||{},x=Array.from(w.current.values());if(!v||!f){const L=new Map;for(const b of e)b.data.length>0&&L.set(b.label,b.data[b.data.length-1]);if(be(L.size>0?L:void 0),a||G||ge)Z(null);else if(x[0]&&s){const y=t.timeScale().timeToCoordinate(s),M=e[0];if(M.data.length>0){const k=M.data[M.data.length-1].value,T=x[0].priceToCoordinate(k);y!==null&&T!==null&&Z({x:y,y:T})}}return}const W=new Map;let N;for(let L=0;L<e.length;L++){const b=e[L],y=w.current.get(b.label);if(!y)continue;const M=g?.get(y),k=M&&"value"in M?M.value:void 0;let T;if(k!==void 0)T=k;else if(a){const K=Number(f),Y=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;K<Y?T=Number.NaN:T=b.data[b.data.length-1]?.value??0}else{const K=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;if(Number(f)<K)continue;T=He(b.data,Number(f))}Number.isNaN(T)||(N===void 0&&(N=T),W.set(b.label,{value:T,time:f}))}if(be(W),N!==void 0&&x[0]){const b=t.timeScale().timeToCoordinate(f),y=x[0].priceToCoordinate(N);if(b!==null&&y!==null){const M=j.current;if(M){const k=M.querySelector(".LightweightChart");if(k){const T=k.getBoundingClientRect(),K=M.getBoundingClientRect(),Y=b+(T.left-K.left),te=y+(T.top-K.top);Z({x:Y,y:te})}else Z({x:b,y})}else Z({x:b,y})}else Z(null)}else Z(null)};return t.subscribeCrosshairMove(i),R&&t.subscribeClick(i),!a&&!G&&!ge&&requestAnimationFrame(()=>{const l=Array.from(w.current.values());if(l[0]&&s&&e[0]?.data.length>0){const g=t.timeScale().timeToCoordinate(s),v=e[0].data[e[0].data.length-1].value,x=l[0].priceToCoordinate(v);g!==null&&x!==null&&Z({x:g,y:x})}}),()=>{t.unsubscribeCrosshairMove(i),R&&t.unsubscribeClick(i)}},[e,G,R,ge]),p.useEffect(()=>{const t=A.current;if(!t||e.length===0)return;const a=t.timeScale(),s=()=>{const i=Ne.current;if(i.length===0)return;const l=a.getVisibleRange();if(!l)return;const f=Number(l.from),g=Number(l.to);for(const v of i){const x=[];for(const W of e)if(v.labels.has(W.label))for(const N of W.data){const L=Number(N.time);L>=f&&L<=g&&x.push(N.value)}x.length>0&&v.updateVisibleRange(x)}};return a.subscribeVisibleLogicalRangeChange(s),()=>{a.unsubscribeVisibleLogicalRangeChange(s)}},[e]),p.useEffect(()=>{const t=A.current,a=Array.from(w.current.values()),s=[];if(t&&a.length>0&&_){const i=ce.getDefaultVerticalLine(),l=a[0];for(const f of _){const g={...i,...f.options||{}};g.color&&(g.color=z.resolveCSSColor(g.color,g.color));const v=new ct.VertLine(t,l,f.xCoordinate,g);l.attachPrimitive(v),s.push(v)}}return()=>{if(a.length>0){const i=a[0];for(const l of s)try{i.detachPrimitive(l)}catch{}}}},[_,e,ae]),p.useEffect(()=>{const t=[],a=[];if(E&&E.length>0){const s=Array.from(w.current.values())[0],i=z.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const l of E){if(!Number.isFinite(l.price))continue;const f=l.seriesLabel?w.current.get(l.seriesLabel):s;if(!f)continue;const g=l.color?z.resolveCSSColor(l.color,l.color):i,v=l.lineWidth??1,x=l.lineStyle??q.LineStyle.Dashed,W=f.createPriceLine({price:l.price,color:g,lineWidth:v,lineStyle:x,axisLabelVisible:l.axisLabelVisible??!0,title:l.title??""});t.push({series:f,line:W});const N=new mt(f,l.price,g,v,x);f.attachPrimitive(N),a.push({series:f,primitive:N})}}return()=>{for(const{series:s,primitive:i}of a)try{s.detachPrimitive(i)}catch{}for(const{series:s,line:i}of t)try{s.removePriceLine(i)}catch{}}},[E,e,ae]),p.useEffect(()=>{const t=[];if(X&&X.length>0){const a=Array.from(w.current.values())[0],s="rgba(239, 68, 68, 0.12)";for(const i of X){const l=i.seriesLabel?w.current.get(i.seriesLabel):a;if(!l)continue;const f=i.color?z.resolveCSSColor(i.color,s):s,g=new gt(l,i.priceTop,i.priceBottom,f);l.attachPrimitive(g),t.push({series:l,zone:g})}}return()=>{for(const{series:a,zone:s}of t)try{a.detachPrimitive(s)}catch{}}},[X,e,ae]),p.useEffect(()=>{const t=A.current;if(!t||!_?.length){Ee([]);return}const a=()=>{const l=t.timeScale(),f=_.map(g=>l.timeToCoordinate(g.xCoordinate)??null);Ee(f),j.current&&De(j.current.clientWidth)};a();const s=t.timeScale(),i=()=>{a()};return s.subscribeVisibleLogicalRangeChange(i),()=>{s.unsubscribeVisibleLogicalRangeChange(i)}},[_,e,ae]),p.useLayoutEffect(()=>{Ue(t=>{const a={};let s=!1;for(const[i,l]of Ie.current){if(!l)continue;const f=l.offsetWidth;a[i]=f,t[i]!==f&&(s=!0)}return Object.keys(t).length!==Object.keys(a).length&&(s=!0),s?a:t})});const ie=e.length===1,je=xe.useMemo(()=>{if(ie&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[ie,e]);return C.jsxs("div",{ref:j,className:ne.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[he!=null&&he!==!1&&ie?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:he})}):Ke&&ie&&je&&C.jsx(at.GraphCurrentValue,{point:je,xMeasureUnit:h,yMeasureUnit:S,decimals:fe}),Pe&&Me&&C.jsx(it.GraphTooltip,{points:Pe,xMeasureUnit:h,yMeasureUnit:S,series:e,position:Me,containerRef:j,decimals:fe}),c&&C.jsx(Ze,{series:e,onUnselect:u}),_&&_.length>0&&ke.length===_.length&&C.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:_.map((t,a)=>{const s=ke[a],i=t.options??{},l=i.showLabel!==!1;if(s===null||!l)return null;const{labelText:f,valueStr:g}=$e(i,S,fe),v=i.tooltipText??"";if(!(f||g||v))return null;const W=i.labelBackgroundColor??i.color??"hsl(var(--background))",N=i.labelTextColor??"hsl(var(--foreground))",L=`${String(t.xCoordinate)}-${f}-${v}`,b=Xe(s,Je,Ye[a]);return C.jsxs("div",{ref:y=>{Ie.current.set(a,y)},className:ne.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",v&&"pointer-events-auto cursor-default"),style:{...b,backgroundColor:W,color:N},children:[f&&C.jsx("span",{className:"block",children:f}),g&&C.jsx("span",{className:ne.cn("block",f&&"mt-0.5"),children:g}),v&&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:v})]},L)})}),C.jsx("div",{ref:pe,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ze({series:e,onUnselect:n,inline:c=!1}){return C.jsx("div",{className:ne.cn("flex flex-wrap gap-2",c?"items-center":"absolute top-0 left-2 z-[10]"),children:e.map((u,h)=>{const S=_e(h),P=(u.lineColor??u.color)||S.line,_=u.data.length===0;return C.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",_&&"opacity-50"),children:[C.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:P}}),C.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[u.label,_&&" (no data)"]}),n&&C.jsx("button",{type:"button",onClick:E=>{E.stopPropagation(),n(u.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${u.label}`,children: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"})]})})]},u.label)})})}exports.DEFAULT_SERIES_COLORS=ue;exports.Graph=vt;exports.GraphLegend=Ze;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=ye;exports.getSeriesColorPalette=_e;exports.getStepForwardValue=He;exports.getVerticalLineLabelStyle=Xe;exports.getVerticalLineTooltipContent=$e;
|