@gearbox-protocol/permissionless-ui 1.26.4 → 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 u=require("react/jsx-runtime"),ue=require("lightweight-charts"),c=require("react"),Ae=require("../../hooks/use-media-query.cjs"),ge=require("../../utils/cn.cjs"),I=require("../../utils/colors.cjs"),X=require("./default-config.cjs"),D=require("./formatters.cjs"),Ie=require("./graph-current-value.cjs"),ye=require("./graph-tooltip.cjs"),Oe=require("./plugins/vertical-line.cjs");function ze(e){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const f in e)if(f!=="default"){const y=Object.getOwnPropertyDescriptor(e,f);Object.defineProperty(m,f,y.get?y:{enumerable:!0,get:()=>e[f]})}}return m.default=e,Object.freeze(m)}const fe=ze(c);function Ve(e,m,f){const y=e.labelText??"",b=e.value,x=b===void 0?"":typeof b=="number"?m==="$"?`$${D.formatExactValue(b,void 0,f)}`:m==="%"?`${D.formatExactValue(b,void 0,f)}%`:D.formatExactValue(b,m!=="none"&&m!=="%"&&m!=="$"?m:void 0,f):String(b);return{labelText:y,valueStr:x}}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)"}],qe=137.5;function de(e){if(e<Z.length)return Z[e];const f=(e-Z.length)*qe%360,y=I.hslToHex(f,70,50),{topColor:b,bottomColor:x}=I.generateColorsFromBase(y);return{line:y,top:b,bottom:x}}function De({series:e,className:m,showLegend:f=!1,onUnselectSeries:y,xMeasureUnit:b="time",yMeasureUnit:x="token",optionsOverrides:$,verticalLineOptions:S,currentValueDecimals:G,useSharedPriceScale:L=!1,showCurrentValue:ke=!0,graphTitle:K,yScaleMin:be,yScaleMinMultiple:me}){const j=c.useRef(null),V=c.useRef(new Map),Q=c.useRef(!1),J=c.useRef(new Set),he=c.useRef(0),pe=c.useRef(!0),U=c.useRef(null),je=c.useRef(null),_=c.useRef(null),ee=c.useRef(null),R=Ae.useIsMobile(),M=fe.useMemo(()=>e.flatMap(t=>t.data),[e]),Le=fe.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[Y,te]=c.useState(()=>{if(!Le)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}),[oe,A]=c.useState(null),[Ce,ve]=c.useState([]);c.useEffect(()=>{const t=()=>{if(j.current&&_.current){const l=_.current.clientWidth,i=_.current.clientHeight;j.current.resize(l,i),j.current.timeScale().fitContent()}},a=_.current,n=a?new ResizeObserver(t):null;return a&&n?.observe(a),()=>{a&&n?.unobserve(a)}},[]),c.useEffect(()=>{if(!ee.current||Q.current)return;const t=X.getDefaultOptions(),a=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),n=ue.createChart(ee.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!R,textColor:a},...R&&{crosshair:{...t.crosshair,mode:ue.CrosshairMode.Magnet}},...$});return j.current=n,Q.current=!0,()=>{n.remove(),j.current=null,Q.current=!1,V.current.clear()}},[R,$]),c.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const n=e.filter(o=>o.data.length>0).length<=1?be:me,l=b==="time"?D.getXFormatters(b,M):D.getXFormatters(b),i=M.map(o=>o.value),{formatter:g,tickmarksFormatter:d,updateVisibleRange:N,updateLastValues:h}=D.createAdaptiveYAxisFormatter(i,x,{yScaleMin:n});U.current=N,je.current=h;const P=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);h(P);const T=X.getDefaultOptions();t.applyOptions({localization:{...T.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...T.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const p=(M.length>0?Math.min(...M.map(o=>o.value)):0)<0,w=M.some(o=>o.value===0),C=!p&&w,v=e.length>1&&!L,F=e.length>1&&!L||R,E=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...T.rightPriceScale||{},visible:!F,textColor:E,...C&&{scaleMargins:{top:.3,bottom:0}}}});const ne=new Set(V.current.keys()),re=new Set(e.map(o=>o.label));for(const o of ne)if(!re.has(o)){const r=V.current.get(o);r&&(t.removeSeries(r),V.current.delete(o))}const Ne=X.getDefaultSeries(),ae=[];let H=0;for(let o=0;o<e.length;o++){const r=e[o],ie=de(o),W=r.lineColor??r.color??ie.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 s=I.generateColorsFromBase(W);O=r.topColor,z=s.bottomColor}else if(r.bottomColor)O=I.generateColorsFromBase(W).topColor,z=r.bottomColor;else{const s=I.generateColorsFromBase(W);O=s.topColor,z=s.bottomColor}else O=r.topColor||ie.top,z=r.bottomColor||ie.bottom;if(r.data.length===0){const s=V.current.get(r.label);s&&(t.removeSeries(s),V.current.delete(r.label));continue}const Fe=(r.data.length>0?Math.min(...r.data.map(s=>s.value)):0)<0,Ee=r.data.some(s=>s.value===0),_e=!Fe&&Ee,Se=L||!v||H===0?"right":`scale-${H}`;v&&ae.push({priceScaleId:Se||"right",shouldPreventNegativeAxis:_e,seriesIndex:H});const Re=(L||!v)&&n!==void 0&&typeof n=="number",we={lineColor:W,topColor:O,bottomColor:z,priceScaleId:Se,priceFormat:{type:"custom",minMove:.01,formatter:Re&&typeof n=="number"?s=>g(s<n?n:s):g,tickmarksFormatter:d},autoscaleInfoProvider:s=>{if(!Re)return s();const ce=s();if(ce?.priceRange){const Me=n;ce.priceRange.minValue=Me}return ce}};let q=V.current.get(r.label);q?(q.applyOptions(we),q.setData(r.data.map(s=>({...s,time:s.time})))):(q=t.addSeries(ue.AreaSeries,{...Ne,...we}),q.setData(r.data.map(s=>({...s,time:s.time}))),V.current.set(r.label,q)),H++}if(v&&ae.length>0)for(const o of ae)try{const r=t.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(!v)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!R,autoScale:!0,scaleMargins:{top:.1,bottom:n!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:E})}catch{}n!==void 0&&!R&&(L||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}});const le=new Set(e.map(o=>o.label)),Pe=le.size!==J.current.size||[...le].some(o=>!J.current.has(o)),Te=M.length!==he.current;(pe.current||Pe||Te||R)&&(t.timeScale().fitContent(),pe.current=!1),J.current=le,he.current=M.length;const se=new Map;for(const o of e)o.data.length>0&&se.set(o.label,o.data[o.data.length-1]);te(se.size>0?se:void 0)},[e,M,b,x,R,L,be,me]),c.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const a=e.length===1;let n;for(const i of e)if(i.data.length>0){n=i.data[i.data.length-1].time;break}if(!n)return;const l=i=>{const{time:g=n,seriesData:d,point:N}=i||{},h=Array.from(V.current.values());if(!N||!g){const k=new Map;for(const p of e)p.data.length>0&&k.set(p.label,p.data[p.data.length-1]);if(te(k.size>0?k:void 0),a||L)A(null);else if(h[0]&&n){const w=t.timeScale().timeToCoordinate(n),C=e[0];if(C.data.length>0){const v=C.data[C.data.length-1].value,F=h[0].priceToCoordinate(v);w!==null&&F!==null&&A({x:w,y:F})}}return}const P=new Map;let T;for(let k=0;k<e.length;k++){const p=e[k],w=h[k];if(!w)continue;const C=d?.get(w),v=C&&"value"in C?C.value:void 0,F=p.data[p.data.length-1],E=v!==void 0?v:F?.value??0;k===0&&(T=E),P.set(p.label,{value:E,time:g})}if(te(P),T!==void 0&&h[0]){const p=t.timeScale().timeToCoordinate(g),w=h[0].priceToCoordinate(T);if(p!==null&&w!==null){const C=_.current;if(C){const v=C.querySelector(".LightweightChart");if(v){const F=v.getBoundingClientRect(),E=C.getBoundingClientRect(),ne=p+(F.left-E.left),re=w+(F.top-E.top);A({x:ne,y:re})}else A({x:p,y:w})}else A({x:p,y:w})}else A(null)}else A(null)};return t.subscribeCrosshairMove(l),R&&t.subscribeClick(l),!a&&!L&&requestAnimationFrame(()=>{const i=Array.from(V.current.values());if(i[0]&&n&&e[0]?.data.length>0){const d=t.timeScale().timeToCoordinate(n),N=e[0].data[e[0].data.length-1].value,h=i[0].priceToCoordinate(N);d!==null&&h!==null&&A({x:d,y:h})}}),()=>{t.unsubscribeCrosshairMove(l),R&&t.unsubscribeClick(l)}},[e,L,R]),c.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const a=t.timeScale(),n=()=>{if(!U.current)return;const l=a.getVisibleRange();if(!l)return;const i=Number(l.from),g=Number(l.to),d=[];for(const N of e)for(const h of N.data){const P=Number(h.time);P>=i&&P<=g&&d.push(h.value)}d.length>0&&U.current(d)};return a.subscribeVisibleLogicalRangeChange(n),()=>{a.unsubscribeVisibleLogicalRangeChange(n)}},[e]),c.useEffect(()=>{const t=j.current,a=Array.from(V.current.values()),n=[];if(t&&a.length>0&&S){const l=X.getDefaultVerticalLine(),i=a[0];for(const g of S){const d=new Oe.VertLine(t,i,g.xCoordinate,{...l,...g.options||{}});i.attachPrimitive(d),n.push(d)}}return()=>{if(a.length>0){const l=a[0];for(const i of n)l.detachPrimitive(i)}}},[S]),c.useEffect(()=>{const t=j.current;if(!t||!S?.length){ve([]);return}const a=()=>{const i=t.timeScale(),g=S.map(d=>i.timeToCoordinate(d.xCoordinate)??null);ve(g)};a();const n=t.timeScale(),l=()=>{a()};return n.subscribeVisibleLogicalRangeChange(l),()=>{n.unsubscribeVisibleLogicalRangeChange(l)}},[S]);const B=e.length===1,xe=fe.useMemo(()=>{if(B&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[B,e]);return u.jsxs("div",{ref:_,className:ge.cn("relative z-[1] w-full h-full overflow-hidden p-0",m),children:[K!=null&&K!==!1&&B?u.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:u.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:K})}):ke&&B&&xe&&u.jsx(Ie.GraphCurrentValue,{point:xe,xMeasureUnit:b,yMeasureUnit:x,decimals:G}),Y&&oe&&u.jsx(ye.GraphTooltip,{points:Y,xMeasureUnit:b,yMeasureUnit:x,series:e,position:oe,containerRef:_,decimals:G}),Y&&!oe&&!B&&R&&u.jsx(ye.GraphTooltip,{points:Y,xMeasureUnit:b,yMeasureUnit:x,series:e,containerRef:_,decimals:G,className:"top-2 left-2"}),f&&u.jsx($e,{series:e,onUnselect:y}),S&&S.length>0&&Ce.length===S.length&&u.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:S.map((t,a)=>{const n=Ce[a],l=t.options??{},i=l.showLabel!==!1;if(n===null||!i)return null;const{labelText:g,valueStr:d}=Ve(l,x,G);if(!(g||d))return null;const h=l.labelBackgroundColor??l.color??"hsl(var(--background))",P=l.labelTextColor??"hsl(var(--foreground))",T=`${String(t.xCoordinate)}-${g}`;return u.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:h,color:P},children:[g&&u.jsx("span",{className:"block",children:g}),d&&u.jsx("span",{className:ge.cn("block",g&&"mt-0.5"),children:d})]},T)})}),u.jsx("div",{ref:ee,className:"LightweightChart w-full h-full overflow-hidden"})]})}function $e({series:e,onUnselect:m}){return u.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((f,y)=>{const b=de(y),x=(f.lineColor??f.color)||b.line,$=f.data.length===0;return u.jsxs("div",{className:ge.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",$&&"opacity-50"),children:[u.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:x}}),u.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[f.label,$&&" (no data)"]}),m&&u.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),m(f.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${f.label}`,children:u.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:[u.jsx("title",{children:"Close"}),u.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f.label)})})}exports.DEFAULT_SERIES_COLORS=Z;exports.Graph=De;exports.getSeriesColorPalette=de;exports.getVerticalLineTooltipContent=Ve;
|
|
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)"
|
|
@@ -21,7 +21,10 @@ function i() {
|
|
|
21
21
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
22
22
|
visible: !0,
|
|
23
23
|
fixLeftEdge: !0,
|
|
24
|
-
fixRightEdge: !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
|
|
25
28
|
},
|
|
26
29
|
rightPriceScale: {
|
|
27
30
|
visible: !0,
|
|
@@ -71,7 +74,7 @@ function a() {
|
|
|
71
74
|
lineWidth: 2
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
|
-
function
|
|
77
|
+
function s() {
|
|
75
78
|
return {
|
|
76
79
|
showLabel: !0,
|
|
77
80
|
color: e.lineColor,
|
|
@@ -79,7 +82,7 @@ function b() {
|
|
|
79
82
|
width: 2
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
|
-
const
|
|
85
|
+
const b = {
|
|
83
86
|
timeScale: {
|
|
84
87
|
borderVisible: !0,
|
|
85
88
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
@@ -127,9 +130,9 @@ const s = {
|
|
|
127
130
|
};
|
|
128
131
|
export {
|
|
129
132
|
e as DEFAULT_AREA_SERIES,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
b as DEFAULT_OPTIONS,
|
|
134
|
+
i as DEFAULT_VERTICAL_LINE,
|
|
135
|
+
t as getDefaultOptions,
|
|
133
136
|
a as getDefaultSeries,
|
|
134
|
-
|
|
137
|
+
s as getDefaultVerticalLine
|
|
135
138
|
};
|