@gearbox-protocol/permissionless-ui 1.26.3 → 1.26.5
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../utils/colors.cjs"),e={topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:"#02c39a",lineWidth:2},o={showLabel:!0,color:"#02c39a",labelBackgroundColor:"#02c39a",width:2};function t(){const r=l.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");return{timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0,fixLeftEdge:!0,fixRightEdge:!0,lockVisibleTimeRangeOnResize:!0},rightPriceScale:{visible:!0,autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:r},layout:{background:{color:"transparent"},textColor:r,fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}}}function i(){return{topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:e.lineColor,lineWidth:2}}function a(){return{showLabel:!0,color:e.lineColor,labelBackgroundColor:e.lineColor,width:2}}const s={timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0,fixLeftEdge:!0,fixRightEdge:!0},rightPriceScale:{visible:!0,autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1},layout:{background:{color:"transparent"},textColor:"rgb(0, 0, 0)",fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}};exports.DEFAULT_AREA_SERIES=e;exports.DEFAULT_OPTIONS=s;exports.DEFAULT_VERTICAL_LINE=o;exports.getDefaultOptions=t;exports.getDefaultSeries=i;exports.getDefaultVerticalLine=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),ut=require("lightweight-charts"),u=require("react"),At=require("../../hooks/use-media-query.cjs"),gt=require("../../utils/cn.cjs"),I=require("../../utils/colors.cjs"),X=require("./default-config.cjs"),D=require("./formatters.cjs"),It=require("./graph-current-value.cjs"),yt=require("./graph-tooltip.cjs"),Ot=require("./plugins/vertical-line.cjs");function zt(t){const C=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const g in t)if(g!=="default"){const L=Object.getOwnPropertyDescriptor(t,g);Object.defineProperty(C,g,L.get?L:{enumerable:!0,get:()=>t[g]})}}return C.default=t,Object.freeze(C)}const ft=zt(u);function Vt(t,C,g){const L=t.labelText??"",b=t.value,w=b===void 0?"":typeof b=="number"?C==="$"?`$${D.formatExactValue(b,void 0,g)}`:C==="%"?`${D.formatExactValue(b,void 0,g)}%`:D.formatExactValue(b,C!=="none"&&C!=="%"&&C!=="$"?C:void 0,g):String(b);return{labelText:L,valueStr:w}}const Z=[{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)"}],qt=137.5;function dt(t){if(t<Z.length)return Z[t];const g=(t-Z.length)*qt%360,L=I.hslToHex(g,70,50),{topColor:b,bottomColor:w}=I.generateColorsFromBase(L);return{line:L,top:b,bottom:w}}function Dt({series:t,className:C,showLegend:g=!1,onUnselectSeries:L,xMeasureUnit:b="time",yMeasureUnit:w="token",optionsOverrides:$,verticalLineOptions:y,currentValueDecimals:G,useSharedPriceScale:N=!1,showCurrentValue:Lt=!0,graphTitle:K,yScaleMin:bt,yScaleMinMultiple:mt}){const k=u.useRef(null),j=u.useRef(new Map),Q=u.useRef(!1),J=u.useRef(new Set),ht=u.useRef(0),pt=u.useRef(!0),U=u.useRef(null),jt=u.useRef(null),M=u.useRef(null),tt=u.useRef(null),V=At.useIsMobile(),_=ft.useMemo(()=>t.flatMap(e=>e.data),[t]),kt=ft.useMemo(()=>{if(t.length>0){const e=t[t.length-1];if(e.data.length>0)return e.data[e.data.length-1]}},[t]),[Y,et]=u.useState(()=>{if(!kt)return;const e=new Map;for(const a of t)a.data.length>0&&e.set(a.label,a.data[a.data.length-1]);return e}),[ot,A]=u.useState(null),[Ct,vt]=u.useState([]);u.useEffect(()=>{const e=()=>{if(k.current&&M.current){const s=M.current.clientWidth,l=M.current.clientHeight;k.current.resize(s,l),k.current.timeScale().fitContent()}},a=M.current,n=a?new ResizeObserver(e):null;return a&&n?.observe(a),()=>{a&&n?.unobserve(a)}},[]),u.useEffect(()=>{if(!tt.current||Q.current)return;const e=X.getDefaultOptions(),a=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),n=ut.createChart(tt.current,{...e,rightPriceScale:{...e.rightPriceScale||{},visible:!V,textColor:a},...V&&{crosshair:{...e.crosshair,mode:ut.CrosshairMode.Magnet}},...$});return k.current=n,Q.current=!0,()=>{n.remove(),k.current=null,Q.current=!1,j.current.clear()}},[V,$]),u.useEffect(()=>{const e=k.current;if(!e||t.length===0)return;const n=t.filter(o=>o.data.length>0).length<=1?bt:mt,s=b==="time"?D.getXFormatters(b,_):D.getXFormatters(b),l=_.map(o=>o.value),{formatter:c,tickmarksFormatter:m,updateVisibleRange:P,updateLastValues:v}=D.createAdaptiveYAxisFormatter(l,w,{yScaleMin:n});U.current=P,jt.current=v;const T=t.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);v(T);const S=X.getDefaultOptions();e.applyOptions({localization:{...S.localization||{},timeFormatter:o=>s.timeFormatter(parseFloat(o),void 0)},timeScale:{...S.timeScale||{},tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const h=(_.length>0?Math.min(..._.map(o=>o.value)):0)<0,x=_.some(o=>o.value===0),p=!h&&x,d=t.length>1&&!N,F=t.length>1&&!N||V,E=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");e.applyOptions({rightPriceScale:{...S.rightPriceScale||{},visible:!F,textColor:E,...p&&{scaleMargins:{top:.3,bottom:0}}}});const nt=new Set(j.current.keys()),rt=new Set(t.map(o=>o.label));for(const o of nt)if(!rt.has(o)){const r=j.current.get(o);r&&(e.removeSeries(r),j.current.delete(o))}const Pt=X.getDefaultSeries(),at=[];let H=0;for(let o=0;o<t.length;o++){const r=t[o],it=dt(o),W=r.lineColor??r.color??it.line;let O,z;if(r.lineColor??r.color)if(r.topColor&&r.bottomColor)O=r.topColor,z=r.bottomColor;else if(r.topColor){const i=I.generateColorsFromBase(W);O=r.topColor,z=i.bottomColor}else if(r.bottomColor)O=I.generateColorsFromBase(W).topColor,z=r.bottomColor;else{const i=I.generateColorsFromBase(W);O=i.topColor,z=i.bottomColor}else O=r.topColor||it.top,z=r.bottomColor||it.bottom;if(r.data.length===0){const i=j.current.get(r.label);i&&(e.removeSeries(i),j.current.delete(r.label));continue}const Ft=(r.data.length>0?Math.min(...r.data.map(i=>i.value)):0)<0,Et=r.data.some(i=>i.value===0),Mt=!Ft&&Et,St=N||!d||H===0?"right":`scale-${H}`;d&&at.push({priceScaleId:St||"right",shouldPreventNegativeAxis:Mt,seriesIndex:H});const Rt=(N||!d)&&n!==void 0&&typeof n=="number",wt={lineColor:W,topColor:O,bottomColor:z,priceScaleId:St,priceFormat:{type:"custom",minMove:.01,formatter:Rt&&typeof n=="number"?i=>c(i<n?n:i):c,tickmarksFormatter:m},autoscaleInfoProvider:i=>{if(!Rt)return i();const ct=i();if(ct?.priceRange){const _t=n;ct.priceRange.minValue=_t}return ct}};let q=j.current.get(r.label);q?(q.applyOptions(wt),q.setData(r.data.map(i=>({...i,time:i.time})))):(q=e.addSeries(ut.AreaSeries,{...Pt,...wt}),q.setData(r.data.map(i=>({...i,time:i.time}))),j.current.set(r.label,q)),H++}if(d&&at.length>0)for(const o of at)try{const r=e.priceScale(o.priceScaleId);r&&r.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...o.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:E})}catch(r){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,r)}else if(!d)try{const o=e.priceScale("right");o&&o.applyOptions({visible:!V,autoScale:!0,scaleMargins:{top:.1,bottom:n!==void 0||p?0:.1,...p&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:E})}catch{}n!==void 0&&!V&&(N||!d)&&e.applyOptions({handleScroll:{vertTouchDrag:!1}});const lt=new Set(t.map(o=>o.label)),Tt=lt.size!==J.current.size||[...lt].some(o=>!J.current.has(o)),Nt=_.length!==ht.current;(pt.current||Tt||Nt||V)&&(e.timeScale().fitContent(),pt.current=!1),J.current=lt,ht.current=_.length;const st=new Map;for(const o of t)o.data.length>0&&st.set(o.label,o.data[o.data.length-1]);et(st.size>0?st:void 0)},[t,_,b,w,V,N,bt,mt]),u.useEffect(()=>{const e=k.current;if(!e||t.length===0)return;const a=t.length===1;let n;for(const l of t)if(l.data.length>0){n=l.data[l.data.length-1].time;break}if(!n)return;const s=l=>{const{time:c=n,seriesData:m,point:P}=l||{},v=Array.from(j.current.values());if(!P||!c){const R=new Map;for(const h of t)h.data.length>0&&R.set(h.label,h.data[h.data.length-1]);if(et(R.size>0?R:void 0),a||N)A(null);else if(v[0]&&n){const x=e.timeScale().timeToCoordinate(n),p=t[0];if(p.data.length>0){const d=p.data[p.data.length-1].value,F=v[0].priceToCoordinate(d);x!==null&&F!==null&&A({x,y:F})}}return}const T=new Map;let S;for(let R=0;R<t.length;R++){const h=t[R],x=v[R];if(!x)continue;const p=m?.get(x),d=p&&"value"in p?p.value:void 0,F=h.data[h.data.length-1],E=d!==void 0?d:F?.value??0;R===0&&(S=E),T.set(h.label,{value:E,time:c})}if(et(T),S!==void 0&&v[0]){const h=e.timeScale().timeToCoordinate(c),x=v[0].priceToCoordinate(S);if(h!==null&&x!==null){const p=M.current;if(p){const d=p.querySelector(".LightweightChart");if(d){const F=d.getBoundingClientRect(),E=p.getBoundingClientRect(),nt=h+(F.left-E.left),rt=x+(F.top-E.top);A({x:nt,y:rt})}else A({x:h,y:x})}else A({x:h,y:x})}else A(null)}else A(null)};return e.subscribeCrosshairMove(s),V&&e.subscribeClick(s),!a&&!N&&requestAnimationFrame(()=>{const l=Array.from(j.current.values());if(l[0]&&n&&t[0]?.data.length>0){const m=e.timeScale().timeToCoordinate(n),P=t[0].data[t[0].data.length-1].value,v=l[0].priceToCoordinate(P);m!==null&&v!==null&&A({x:m,y:v})}}),()=>{e.unsubscribeCrosshairMove(s),V&&e.unsubscribeClick(s)}},[t,N,V]),u.useEffect(()=>{const e=k.current;if(!e||t.length===0)return;const a=e.timeScale(),n=Math.max(...t.map(l=>l.data.length)),s=()=>{if(n===0)return;const l=a.getVisibleLogicalRange();if(!l)return;const c={from:0,to:n-1},m=typeof l.from=="number"?l.from:0,P=typeof l.to=="number"?l.to:n-1;if(U.current){const R=Math.max(0,Math.floor(m)),h=Math.min(n-1,Math.ceil(P)),x=[];for(const p of t)for(let d=R;d<=h&&d<p.data.length;d++)x.push(p.data[d].value);x.length>0&&U.current(x)}const v=.01;let T=!1;const S={...l};m<c.from-v&&(S.from=c.from,T=!0),P>c.to+v&&(S.to=c.to,T=!0),T&&a.setVisibleLogicalRange(S)};return a.subscribeVisibleLogicalRangeChange(s),()=>{a.unsubscribeVisibleLogicalRangeChange(s)}},[t]),u.useEffect(()=>{const e=k.current,a=Array.from(j.current.values()),n=[];if(e&&a.length>0&&y){const s=X.getDefaultVerticalLine(),l=a[0];for(const c of y){const m=new Ot.VertLine(e,l,c.xCoordinate,{...s,...c.options||{}});l.attachPrimitive(m),n.push(m)}}return()=>{if(a.length>0){const s=a[0];for(const l of n)s.detachPrimitive(l)}}},[y]),u.useEffect(()=>{const e=k.current;if(!e||!y?.length){vt([]);return}const a=()=>{const l=e.timeScale(),c=y.map(m=>l.timeToCoordinate(m.xCoordinate)??null);vt(c)};a();const n=e.timeScale(),s=()=>{a()};return n.subscribeVisibleLogicalRangeChange(s),()=>{n.unsubscribeVisibleLogicalRangeChange(s)}},[y]);const B=t.length===1,xt=ft.useMemo(()=>{if(B&&t.length>0){const e=t[0];if(e.data.length>0)return e.data[e.data.length-1]}},[B,t]);return f.jsxs("div",{ref:M,className:gt.cn("relative z-[1] w-full h-full overflow-hidden p-0",C),children:[K!=null&&K!==!1&&B?f.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:f.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:K})}):Lt&&B&&xt&&f.jsx(It.GraphCurrentValue,{point:xt,xMeasureUnit:b,yMeasureUnit:w,decimals:G}),Y&&ot&&f.jsx(yt.GraphTooltip,{points:Y,xMeasureUnit:b,yMeasureUnit:w,series:t,position:ot,containerRef:M,decimals:G}),Y&&!ot&&!B&&V&&f.jsx(yt.GraphTooltip,{points:Y,xMeasureUnit:b,yMeasureUnit:w,series:t,containerRef:M,decimals:G,className:"top-2 left-2"}),g&&f.jsx($t,{series:t,onUnselect:L}),y&&y.length>0&&Ct.length===y.length&&f.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:y.map((e,a)=>{const n=Ct[a],s=e.options??{},l=s.showLabel!==!1;if(n===null||!l)return null;const{labelText:c,valueStr:m}=Vt(s,w,G);if(!(c||m))return null;const v=s.labelBackgroundColor??s.color??"hsl(var(--background))",T=s.labelTextColor??"hsl(var(--foreground))",S=`${String(e.xCoordinate)}-${c}`;return f.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:n,transform:"translateX(-50%)",backgroundColor:v,color:T},children:[c&&f.jsx("span",{className:"block",children:c}),m&&f.jsx("span",{className:gt.cn("block",c&&"mt-0.5"),children:m})]},S)})}),f.jsx("div",{ref:tt,className:"LightweightChart w-full h-full overflow-hidden"})]})}function $t({series:t,onUnselect:C}){return f.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:t.map((g,L)=>{const b=dt(L),w=(g.lineColor??g.color)||b.line,$=g.data.length===0;return f.jsxs("div",{className:gt.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",$&&"opacity-50"),children:[f.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:w}}),f.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[g.label,$&&" (no data)"]}),C&&f.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),C(g.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 ${g.label}`,children:f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[f.jsx("title",{children:"Close"}),f.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),f.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},g.label)})})}exports.DEFAULT_SERIES_COLORS=Z;exports.Graph=Dt;exports.getSeriesColorPalette=dt;exports.getVerticalLineTooltipContent=Vt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),lt=require("lightweight-charts"),d=require("react"),Lt=require("../../hooks/use-media-query.cjs"),it=require("../../utils/cn.cjs"),I=require("../../utils/colors.cjs"),W=require("./default-config.cjs"),$=require("./formatters.cjs"),Tt=require("./graph-current-value.cjs"),Ft=require("./graph-tooltip.cjs"),Mt=require("./plugins/vertical-line.cjs");function Et(t){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const c in t)if(c!=="default"){const R=Object.getOwnPropertyDescriptor(t,c);Object.defineProperty(m,c,R.get?R:{enumerable:!0,get:()=>t[c]})}}return m.default=t,Object.freeze(m)}const st=Et(d);function St(t,m,c){const R=t.labelText??"",b=t.value,w=b===void 0?"":typeof b=="number"?m==="$"?`$${$.formatExactValue(b,void 0,c)}`:m==="%"?`${$.formatExactValue(b,void 0,c)}%`:$.formatExactValue(b,m!=="none"&&m!=="%"&&m!=="$"?m:void 0,c):String(b);return{labelText:R,valueStr:w}}const X=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],_t=137.5;function ct(t){if(t<X.length)return X[t];const c=(t-X.length)*_t%360,R=I.hslToHex(c,70,50),{topColor:b,bottomColor:w}=I.generateColorsFromBase(R);return{line:R,top:b,bottom:w}}function At({series:t,className:m,showLegend:c=!1,onUnselectSeries:R,xMeasureUnit:b="time",yMeasureUnit:w="token",optionsOverrides:B,verticalLineOptions:x,currentValueDecimals:Z,useSharedPriceScale:j=!1,showCurrentValue:Rt=!0,graphTitle:K,yScaleMin:ut,yScaleMinMultiple:ft}){const N=d.useRef(null),y=d.useRef(new Map),Q=d.useRef(!1),gt=d.useRef(!0),J=d.useRef(null),wt=d.useRef(null),A=d.useRef(null),U=d.useRef(null),k=Lt.useIsMobile(),E=st.useMemo(()=>t.flatMap(e=>e.data),[t]),yt=st.useMemo(()=>{if(t.length>0){const e=t[t.length-1];if(e.data.length>0)return e.data[e.data.length-1]}},[t]),[dt,tt]=d.useState(()=>{if(!yt)return;const e=new Map;for(const a of t)a.data.length>0&&e.set(a.label,a.data[a.data.length-1]);return e}),[bt,_]=d.useState(null),[mt,ht]=d.useState([]);d.useEffect(()=>{const e=()=>{if(N.current&&A.current){const l=A.current.clientWidth,i=A.current.clientHeight;N.current.resize(l,i)}},a=A.current,r=a?new ResizeObserver(e):null;return a&&r?.observe(a),()=>{a&&r?.unobserve(a)}},[]),d.useEffect(()=>{if(!U.current||Q.current)return;const e=W.getDefaultOptions(),a=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),r=lt.createChart(U.current,{...e,rightPriceScale:{...e.rightPriceScale||{},visible:!k,textColor:a},...k&&{crosshair:{...e.crosshair,mode:lt.CrosshairMode.Magnet}},...B});return N.current=r,Q.current=!0,()=>{r.remove(),N.current=null,Q.current=!1,y.current.clear()}},[k,B]),d.useEffect(()=>{const e=N.current;if(!e||t.length===0)return;const r=t.filter(o=>o.data.length>0).length<=1?ut:ft,l=b==="time"?$.getXFormatters(b,E):$.getXFormatters(b),i=E.map(o=>o.value),{formatter:u,tickmarksFormatter:g,updateVisibleRange:P,updateLastValues:h}=$.createAdaptiveYAxisFormatter(i,w,{yScaleMin:r});J.current=P,wt.current=h;const L=t.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);h(L);const T=W.getDefaultOptions();e.applyOptions({localization:{...T.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...T.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const p=(E.length>0?Math.min(...E.map(o=>o.value)):0)<0,S=E.some(o=>o.value===0),C=!p&&S,v=t.length>1&&!j,F=t.length>1&&!j||k,M=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");e.applyOptions({rightPriceScale:{...T.rightPriceScale||{},visible:!F,textColor:M,...C&&{scaleMargins:{top:.3,bottom:0}}}});const et=new Set(y.current.keys()),ot=new Set(t.map(o=>o.label));for(const o of et)if(!ot.has(o)){const n=y.current.get(o);n&&(e.removeSeries(n),y.current.delete(o))}const Vt=W.getDefaultSeries(),rt=[];let H=0;for(let o=0;o<t.length;o++){const n=t[o],G=ct(o),O=n.lineColor??n.color??G.line;let D,q;if(n.lineColor??n.color)if(n.topColor&&n.bottomColor)D=n.topColor,q=n.bottomColor;else if(n.topColor){const s=I.generateColorsFromBase(O);D=n.topColor,q=s.bottomColor}else if(n.bottomColor)D=I.generateColorsFromBase(O).topColor,q=n.bottomColor;else{const s=I.generateColorsFromBase(O);D=s.topColor,q=s.bottomColor}else D=n.topColor||G.top,q=n.bottomColor||G.bottom;if(n.data.length===0){const s=y.current.get(n.label);s&&(e.removeSeries(s),y.current.delete(n.label));continue}const kt=(n.data.length>0?Math.min(...n.data.map(s=>s.value)):0)<0,jt=n.data.some(s=>s.value===0),Nt=!kt&&jt,Ct=j||!v||H===0?"right":`scale-${H}`;v&&rt.push({priceScaleId:Ct||"right",shouldPreventNegativeAxis:Nt,seriesIndex:H});const vt=(j||!v)&&r!==void 0&&typeof r=="number",xt={lineColor:O,topColor:D,bottomColor:q,priceScaleId:Ct,priceFormat:{type:"custom",minMove:.01,formatter:vt&&typeof r=="number"?s=>u(s<r?r:s):u,tickmarksFormatter:g},autoscaleInfoProvider:s=>{if(!vt)return s();const at=s();if(at?.priceRange){const Pt=r;at.priceRange.minValue=Pt}return at}};let z=y.current.get(n.label);z?(z.applyOptions(xt),z.setData(n.data.map(s=>({...s,time:s.time})))):(z=e.addSeries(lt.AreaSeries,{...Vt,...xt}),z.setData(n.data.map(s=>({...s,time:s.time}))),y.current.set(n.label,z)),H++}if(v&&rt.length>0)for(const o of rt)try{const n=e.priceScale(o.priceScaleId);n&&n.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...o.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M})}catch(n){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,n)}else if(!v)try{const o=e.priceScale("right");o&&o.applyOptions({visible:!k,autoScale:!0,scaleMargins:{top:.1,bottom:r!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M})}catch{}if(r!==void 0&&!k&&(j||!v)&&e.applyOptions({handleScroll:{vertTouchDrag:!1}}),E.length>0){const o=E.map(O=>Number(O.time)),n=Math.min(...o),G=Math.max(...o);e.timeScale().setVisibleRange({from:n,to:G})}gt.current&&(gt.current=!1);const nt=new Map;for(const o of t)o.data.length>0&&nt.set(o.label,o.data[o.data.length-1]);tt(nt.size>0?nt:void 0)},[t,E,b,w,k,j,ut,ft]),d.useEffect(()=>{const e=N.current;if(!e||t.length===0)return;const a=t.length===1;let r;for(const i of t)if(i.data.length>0){r=i.data[i.data.length-1].time;break}if(!r)return;const l=i=>{const{time:u=r,seriesData:g,point:P}=i||{},h=Array.from(y.current.values());if(!P||!u){const V=new Map;for(const p of t)p.data.length>0&&V.set(p.label,p.data[p.data.length-1]);if(tt(V.size>0?V:void 0),a||j)_(null);else if(h[0]&&r){const S=e.timeScale().timeToCoordinate(r),C=t[0];if(C.data.length>0){const v=C.data[C.data.length-1].value,F=h[0].priceToCoordinate(v);S!==null&&F!==null&&_({x:S,y:F})}}return}const L=new Map;let T;for(let V=0;V<t.length;V++){const p=t[V],S=h[V];if(!S)continue;const C=g?.get(S),v=C&&"value"in C?C.value:void 0,F=p.data[p.data.length-1],M=v!==void 0?v:F?.value??0;V===0&&(T=M),L.set(p.label,{value:M,time:u})}if(tt(L),T!==void 0&&h[0]){const p=e.timeScale().timeToCoordinate(u),S=h[0].priceToCoordinate(T);if(p!==null&&S!==null){const C=A.current;if(C){const v=C.querySelector(".LightweightChart");if(v){const F=v.getBoundingClientRect(),M=C.getBoundingClientRect(),et=p+(F.left-M.left),ot=S+(F.top-M.top);_({x:et,y:ot})}else _({x:p,y:S})}else _({x:p,y:S})}else _(null)}else _(null)};return e.subscribeCrosshairMove(l),k&&e.subscribeClick(l),!a&&!j&&requestAnimationFrame(()=>{const i=Array.from(y.current.values());if(i[0]&&r&&t[0]?.data.length>0){const g=e.timeScale().timeToCoordinate(r),P=t[0].data[t[0].data.length-1].value,h=i[0].priceToCoordinate(P);g!==null&&h!==null&&_({x:g,y:h})}}),()=>{e.unsubscribeCrosshairMove(l),k&&e.unsubscribeClick(l)}},[t,j,k]),d.useEffect(()=>{const e=N.current;if(!e||t.length===0)return;const a=e.timeScale(),r=()=>{if(!J.current)return;const l=a.getVisibleRange();if(!l)return;const i=Number(l.from),u=Number(l.to),g=[];for(const P of t)for(const h of P.data){const L=Number(h.time);L>=i&&L<=u&&g.push(h.value)}g.length>0&&J.current(g)};return a.subscribeVisibleLogicalRangeChange(r),()=>{a.unsubscribeVisibleLogicalRangeChange(r)}},[t]),d.useEffect(()=>{const e=N.current,a=Array.from(y.current.values()),r=[];if(e&&a.length>0&&x){const l=W.getDefaultVerticalLine(),i=a[0];for(const u of x){const g=new Mt.VertLine(e,i,u.xCoordinate,{...l,...u.options||{}});i.attachPrimitive(g),r.push(g)}}return()=>{if(a.length>0){const l=a[0];for(const i of r)l.detachPrimitive(i)}}},[x]),d.useEffect(()=>{const e=N.current;if(!e||!x?.length){ht([]);return}const a=()=>{const i=e.timeScale(),u=x.map(g=>i.timeToCoordinate(g.xCoordinate)??null);ht(u)};a();const r=e.timeScale(),l=()=>{a()};return r.subscribeVisibleLogicalRangeChange(l),()=>{r.unsubscribeVisibleLogicalRangeChange(l)}},[x]);const Y=t.length===1,pt=st.useMemo(()=>{if(Y&&t.length>0){const e=t[0];if(e.data.length>0)return e.data[e.data.length-1]}},[Y,t]);return f.jsxs("div",{ref:A,className:it.cn("relative z-[1] w-full h-full overflow-hidden p-0",m),children:[K!=null&&K!==!1&&Y?f.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:f.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:K})}):Rt&&Y&&pt&&f.jsx(Tt.GraphCurrentValue,{point:pt,xMeasureUnit:b,yMeasureUnit:w,decimals:Z}),dt&&bt&&f.jsx(Ft.GraphTooltip,{points:dt,xMeasureUnit:b,yMeasureUnit:w,series:t,position:bt,containerRef:A,decimals:Z}),c&&f.jsx(It,{series:t,onUnselect:R}),x&&x.length>0&&mt.length===x.length&&f.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:x.map((e,a)=>{const r=mt[a],l=e.options??{},i=l.showLabel!==!1;if(r===null||!i)return null;const{labelText:u,valueStr:g}=St(l,w,Z);if(!(u||g))return null;const h=l.labelBackgroundColor??l.color??"hsl(var(--background))",L=l.labelTextColor??"hsl(var(--foreground))",T=`${String(e.xCoordinate)}-${u}`;return f.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:r,transform:"translateX(-50%)",backgroundColor:h,color:L},children:[u&&f.jsx("span",{className:"block",children:u}),g&&f.jsx("span",{className:it.cn("block",u&&"mt-0.5"),children:g})]},T)})}),f.jsx("div",{ref:U,className:"LightweightChart w-full h-full overflow-hidden"})]})}function It({series:t,onUnselect:m}){return f.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:t.map((c,R)=>{const b=ct(R),w=(c.lineColor??c.color)||b.line,B=c.data.length===0;return f.jsxs("div",{className:it.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",B&&"opacity-50"),children:[f.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:w}}),f.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[c.label,B&&" (no data)"]}),m&&f.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),m(c.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${c.label}`,children:f.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[f.jsx("title",{children:"Close"}),f.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),f.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},c.label)})})}exports.DEFAULT_SERIES_COLORS=X;exports.Graph=At;exports.getSeriesColorPalette=ct;exports.getVerticalLineTooltipContent=St;
|
|
@@ -4,13 +4,13 @@ const e = {
|
|
|
4
4
|
bottomColor: "rgba(76, 175, 80, 0.04)",
|
|
5
5
|
lineColor: "#02c39a",
|
|
6
6
|
lineWidth: 2
|
|
7
|
-
},
|
|
7
|
+
}, i = {
|
|
8
8
|
showLabel: !0,
|
|
9
9
|
color: "#02c39a",
|
|
10
10
|
labelBackgroundColor: "#02c39a",
|
|
11
11
|
width: 2
|
|
12
12
|
};
|
|
13
|
-
function
|
|
13
|
+
function t() {
|
|
14
14
|
const r = o(
|
|
15
15
|
"hsl(var(--foreground))",
|
|
16
16
|
"rgb(0, 0, 0)"
|
|
@@ -19,7 +19,12 @@ function i() {
|
|
|
19
19
|
timeScale: {
|
|
20
20
|
borderVisible: !0,
|
|
21
21
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
22
|
-
visible: !0
|
|
22
|
+
visible: !0,
|
|
23
|
+
fixLeftEdge: !0,
|
|
24
|
+
fixRightEdge: !0,
|
|
25
|
+
// Preserve visible time range on resize (e.g. when second series is added
|
|
26
|
+
// and legend appears). Avoids range shrinking to a few days.
|
|
27
|
+
lockVisibleTimeRangeOnResize: !0
|
|
23
28
|
},
|
|
24
29
|
rightPriceScale: {
|
|
25
30
|
visible: !0,
|
|
@@ -69,7 +74,7 @@ function a() {
|
|
|
69
74
|
lineWidth: 2
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
|
-
function
|
|
77
|
+
function s() {
|
|
73
78
|
return {
|
|
74
79
|
showLabel: !0,
|
|
75
80
|
color: e.lineColor,
|
|
@@ -77,11 +82,13 @@ function b() {
|
|
|
77
82
|
width: 2
|
|
78
83
|
};
|
|
79
84
|
}
|
|
80
|
-
const
|
|
85
|
+
const b = {
|
|
81
86
|
timeScale: {
|
|
82
87
|
borderVisible: !0,
|
|
83
88
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
84
|
-
visible: !0
|
|
89
|
+
visible: !0,
|
|
90
|
+
fixLeftEdge: !0,
|
|
91
|
+
fixRightEdge: !0
|
|
85
92
|
},
|
|
86
93
|
rightPriceScale: {
|
|
87
94
|
visible: !0,
|
|
@@ -123,9 +130,9 @@ const s = {
|
|
|
123
130
|
};
|
|
124
131
|
export {
|
|
125
132
|
e as DEFAULT_AREA_SERIES,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
133
|
+
b as DEFAULT_OPTIONS,
|
|
134
|
+
i as DEFAULT_VERTICAL_LINE,
|
|
135
|
+
t as getDefaultOptions,
|
|
129
136
|
a as getDefaultSeries,
|
|
130
|
-
|
|
137
|
+
s as getDefaultVerticalLine
|
|
131
138
|
};
|