@gearbox-protocol/permissionless-ui 1.25.0 → 1.26.0
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.
- package/dist/cjs/components/graph/formatters.cjs +1 -1
- package/dist/cjs/components/graph/graph-view.cjs +1 -1
- package/dist/cjs/components/graph/graph.cjs +1 -1
- package/dist/cjs/components/trading-view/trading-view.cjs +1 -1
- package/dist/esm/components/graph/formatters.js +101 -80
- package/dist/esm/components/graph/graph-view.js +107 -92
- package/dist/esm/components/graph/graph.js +323 -306
- package/dist/esm/components/trading-view/trading-view.js +175 -109
- package/dist/types/components/graph/formatters.d.ts +8 -1
- package/dist/types/components/graph/graph-view.d.ts +11 -1
- package/dist/types/components/graph/graph.d.ts +20 -1
- package/dist/types/components/graph/index.d.ts +1 -1
- package/dist/types/components/trading-view/trading-view.d.ts +25 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("luxon"),c=require("../../utils/format-number.cjs"),{MIN_DISPLAY_THRESHOLD:u,MAX_EXPONENTIAL_THRESHOLD:p}=c.FORMAT_CONSTANTS,V=(t,e,n="full")=>{if(c.isBelowDisplayThreshold(t))return e?`<${u}${e}`:`<${u}`;if(t===0)return e?`0${e}`:"0";const a=c.formatNumberWithSuffix(t,{maxExponentialThreshold:p,minimumFractionDigits:0,maximumFractionDigits:n==="short"?1:0,format:n,adaptiveDecimals:n==="short"});return e?`${a}${e}`:a},U=2,I=(t,e)=>{if(c.isBelowDisplayThreshold(t))return e?`<${u}${e}`:`<${u}`;if(t===0)return e?`0${e}`:"0";const n=c.toSignificantDigits(t,U);return e?`${n}${e}`:n},b=4,G=t=>{if(c.isBelowDisplayThreshold(t))return`<${u}`;if(t===0)return"0";const e=Math.round(t),n=Math.abs(t-e);return n>0&&n<.01?t.toFixed(12).replace(/0+$/,"").replace(/\.$/,""):c.toSignificantDigits(t,b)},X=(t,e)=>{if(c.isBelowDisplayThreshold(t))return e?`<${u} ${e}`:`<${u}`;if(t===0)return e?`0 ${e}`:"0";const n=Number.isInteger(t),a=Math.abs(t),s=n&&a>=1e3,l=Math.round(t),d=Math.abs(t-l);if(d>0&&d<.01&&!s){const g=t.toFixed(12).replace(/0+$/,"").replace(/\.$/,"");return e?`${g} ${e}`:g}const $=c.formatNumberWithSuffix(t,{maxExponentialThreshold:p,minimumFractionDigits:n?0:2,maximumFractionDigits:s?1:n?0:2,format:s?"short":"full",adaptiveDecimals:s});return e?`${$} ${e}`:$},N={"%":I,$:V,token:X,none:G},C=t=>N[t]||N.token;function P(t,e,n=4){if(t===0)return e?`0 ${e}`:"0";const a=t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:n});return e?`${a} ${e}`:a}function w(t,e,n){const a=n?.yScaleMin;let s=t.length>0?Math.min(...t):0,l=t.length>0?Math.max(...t):0,d=!1,T=[];const $=()=>{const r=l-s,o=(s+l)/2;let i=1,m="";o>=1e9?(i=1e9,m="B"):o>=1e6?(i=1e6,m="M"):o>=1e3&&(i=1e3,m="K");const D=r/10/i;let S=1;if(D>0){const x=Math.floor(Math.log10(D));S=Math.max(1,-x),S=Math.min(S,4)}return{scale:i,suffix:m,decimals:S}},g=(r,o,i)=>{const m=o>1?r/o:r,h=Math.abs(m)>=1?1:4;return o>1?`${(r/o).toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:h,useGrouping:!1})}${i}`:r.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:h,useGrouping:!1})},R=.12,H=.02;return{formatter:r=>{if(a!==void 0&&r<a)return"";if(r===0)return d?"":(d=!0,"0");r>0&&(d=!1);const{scale:o,suffix:i,decimals:m}=$(),h=l-s,M=h>0?T.filter(f=>Math.abs(f)>=h*H):T,D=Math.abs(r)*1e-10||1e-10;if(M.some(f=>Math.abs(f-r)<D))return g(r,o,i);if(M.length>0){const f=M.reduce((A,E)=>Math.abs(E-r)<Math.abs(A-r)?E:A);if(Math.abs(r-f)/(Math.abs(f)||1e-10)<R)return g(f,o,i)}const x=o>1?r/o:r,L=Math.abs(x)>=1?Math.min(1,m):m;return o>1?`${(r/o).toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:L,useGrouping:!1})}${i}`:r.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:L,useGrouping:!1})},updateVisibleRange:r=>{r.length>0&&(s=Math.min(...r),l=Math.max(...r))},updateLastValues:r=>{T=[...r]}}}const y=t=>F.DateTime.fromSeconds(Number(t)).toFormat("dd/LL/yyyy HH:mm"),Y=t=>F.DateTime.fromSeconds(Number(t)).toFormat("HH:mm"),B=()=>{let t=null;return e=>{const n=F.DateTime.fromSeconds(Number(e)),a=n.toFormat("yyyy-MM-dd");return a!==t?(t=a,n.toFormat("dd MMM")):n.toFormat("HH:mm")}},k=(t,e)=>I(Number(t),e),_={time:y,"%":k},W=(t,e)=>{if(t==="time"&&e&&e.length>0){const n=F.DateTime.fromSeconds(Number(e[0].time)),a=F.DateTime.fromSeconds(Number(e[e.length-1].time));return n.hasSame(a,"day")?Y:B()}return _[t]||_.time};exports.createAdaptiveYAxisFormatter=w;exports.formatExactValue=P;exports.getXFormatter=W;exports.getYFormatter=C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("class-variance-authority"),o=require("react"),V=require("../../utils/cn.cjs"),D=require("./graph.cjs");function L(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const i=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,i.get?i:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const A=L(o),k=q.cva("relative w-full overflow-hidden rounded-lg border-border border bg-card text-card-foreground",{variants:{variant:{default:"shadow",elevated:"shadow-lg",outlined:"border-2",ghost:"border-0 shadow-none"},size:{sm:"h-48 sm:h-64",default:"h-64 sm:h-96",lg:"h-96 sm:h-[32rem]",xl:"h-[32rem] sm:h-[48rem]",full:"h-full"},padding:{none:"p-0",sm:"p-2",default:"p-4 sm:p-6",lg:"p-6"}},defaultVariants:{variant:"default",size:"default",padding:"default"}}),j=A.forwardRef(({className:t,variant:s,size:a,padding:i,title:n,description:r,toolbar:l,loading:c=!1,emptyMessage:d,error:u,children:f,...p},v)=>{const m=n||r||l;return e.jsxs("div",{ref:v,className:V.cn("flex flex-col",k({variant:s,size:a,padding:i,className:t})),...p,children:[m&&e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-4 shrink-0",children:[(n||r)&&e.jsxs("div",{className:"flex-1",children:[n&&e.jsx("h3",{className:"text-base sm:text-lg font-semibold leading-none tracking-tight",children:n}),r&&e.jsx("p",{className:"mt-1 text-xs sm:text-sm text-muted-foreground",children:r})]}),l&&e.jsx("div",{className:"shrink-0 w-full",children:l})]}),e.jsxs("div",{className:"relative flex-1 w-full min-h-0",children:[c&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center opacity-0 animate-delayed-fade-in",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"}),e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground",children:"Loading..."})]})}),u&&e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-destructive",children:[e.jsx("svg",{className:"h-12 w-12",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"text-xs sm:text-sm font-medium",children:u})]})}),!u&&!f&&d&&e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[e.jsx("svg",{className:"h-12 w-12",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"})}),e.jsx("span",{className:"text-xs sm:text-sm",children:d})]})}),e.jsx("div",{className:V.cn("w-full h-full transition-[filter] duration-300 delay-300",c&&"blur-sm pointer-events-none"),children:!u&&f})]})]})});j.displayName="GraphView";function H({series:t,data:s,lineColor:a,color:i,topColor:n,bottomColor:r,graphId:l,onUnselectSeries:c,loading:d,title:u,description:f,toolbar:p,emptyMessage:v="No data available",error:m,containerClassName:R,variant:G,size:W,padding:S,yMeasureUnit:g,showCurrentValue:b,...O}){const h=o.useMemo(()=>{if(t&&t.length>0)return t;if(s&&s.length>0){const y=a??i;return[{data:s.map(x=>({time:typeof x.time=="number"?x.time:Number(x.time),value:x.value})),label:"Value",yMeasureUnit:g,...y&&{lineColor:y},...n&&{topColor:n},...r&&{bottomColor:r}}]}return[]},[t,s,g,a,i,n,r]),z=!d&&h.length===0,N=o.useRef(h);h.length>0&&(N.current=h);const w=d&&h.length===0?N.current:h,_=w.length>0;return e.jsx(j,{className:R,variant:G,size:W,padding:S,title:u,description:f,toolbar:p,loading:d,error:m,emptyMessage:z?v:void 0,children:_&&!m&&e.jsx(D.Graph,{series:w,yMeasureUnit:g,...c?{onUnselectSeries:c}:{},...b!==void 0?{showCurrentValue:b}:{},...O})})}function M(t=0){const s=o.useRef(null),a=o.useRef(null),[i,n]=o.useState(null);return o.useEffect(()=>{const r=()=>{if(s.current&&a.current){const d=a.current.clientWidth,u=s.current.clientWidth;n(d-u-t)}},l=a.current,c=l?new ResizeObserver(r):null;return l&&c?.observe(l),()=>{l&&c?.unobserve(l)}},[t]),{graphWidth:i,parentRef:a,asideRef:s}}exports.GraphView=j;exports.GraphViewWithData=H;exports.graphViewVariants=k;exports.useGraphAside=M;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),ye=require("lightweight-charts"),u=require("react"),Ve=require("../../hooks/use-media-query.cjs"),le=require("../../utils/cn.cjs"),I=require("../../utils/colors.cjs"),X=require("./default-config.cjs"),D=require("./formatters.cjs"),Le=require("./graph-current-value.cjs"),Pe=require("./graph-tooltip.cjs"),je=require("./plugins/vertical-line.cjs");function Te(e){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const g in e)if(g!=="default"){const y=Object.getOwnPropertyDescriptor(e,g);Object.defineProperty(p,g,y.get?y:{enumerable:!0,get:()=>e[g]})}}return p.default=e,Object.freeze(p)}const ae=Te(u);function me(e,p,g){const y=e.labelText??"",h=e.value,P=h===void 0?"":typeof h=="number"?p==="$"?`$${D.formatExactValue(h,void 0,g)}`:p==="%"?`${D.formatExactValue(h,void 0,g)}%`:D.formatExactValue(h,p!=="none"&&p!=="%"&&p!=="$"?p:void 0,g):String(h);return{labelText:y,valueStr:P}}const Y=[{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:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 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:"#0d9488",top:"rgba(13, 148, 136, 0.56)",bottom:"rgba(13, 148, 136, 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:"#d97706",top:"rgba(217, 119, 6, 0.56)",bottom:"rgba(217, 119, 6, 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)"}],Ne=137.5;function se(e){if(e<Y.length)return Y[e];const g=(e-Y.length)*Ne%360,y=I.hslToHex(g,70,50),{topColor:h,bottomColor:P}=I.generateColorsFromBase(y);return{line:y,top:h,bottom:P}}function Ee({series:e,className:p,showLegend:g=!1,onUnselectSeries:y,xMeasureUnit:h="time",yMeasureUnit:P="token",optionsOverrides:$,verticalLineOptions:R,currentValueDecimals:W,useSharedPriceScale:H=!1,showCurrentValue:he=!0}){const j=u.useRef(null),V=u.useRef(new Map),Z=u.useRef(!1),K=u.useRef(new Set),ie=u.useRef(0),ce=u.useRef(!0),Q=u.useRef(null),pe=u.useRef(null),M=u.useRef(null),J=u.useRef(null),O=Ve.useIsMobile(),E=ae.useMemo(()=>e.flatMap(t=>t.data),[e]),Ce=ae.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[ue,U]=u.useState(()=>{if(!Ce)return;const t=new Map;for(const n of e)n.data.length>0&&t.set(n.label,n.data[n.data.length-1]);return t}),[ge,F]=u.useState(null),[fe,de]=u.useState([]);u.useEffect(()=>{const t=()=>{if(j.current&&M.current){const s=M.current.clientWidth,r=M.current.clientHeight;j.current.resize(s,r),j.current.timeScale().fitContent()}},n=M.current,l=n?new ResizeObserver(t):null;return n&&l?.observe(n),()=>{n&&l?.unobserve(n)}},[]),u.useEffect(()=>{if(!J.current||Z.current)return;const t=X.getDefaultOptions(),n=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=ye.createChart(J.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!O,textColor:n},...$});return j.current=l,Z.current=!0,()=>{l.remove(),j.current=null,Z.current=!1,V.current.clear()}},[O,$]),u.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const n=h==="time"?D.getXFormatter(h,E):D.getXFormatter(h),l=E.map(o=>o.value),{formatter:s,updateVisibleRange:r,updateLastValues:i}=D.createAdaptiveYAxisFormatter(l);Q.current=r,pe.current=i;const f=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);i(f);const w=X.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:n?(o=>n(parseFloat(o),void 0)):void 0},timeScale:{...w.timeScale||{},tickMarkFormatter:n?(o=>n(parseFloat(o),void 0)):void 0,minBarSpacing:0}});const T=(E.length>0?Math.min(...E.map(o=>o.value)):0)<0,L=E.some(o=>o.value===0),v=!T&&L,c=e.length>1&&!H,C=e.length>1&&!H||O,d=I.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...w.rightPriceScale||{},visible:!C,textColor:d,...v&&{scaleMargins:{top:.3,bottom:0}}}});const S=new Set(V.current.keys()),N=new Set(e.map(o=>o.label));for(const o of S)if(!N.has(o)){const a=V.current.get(o);a&&(t.removeSeries(a),V.current.delete(o))}const k=X.getDefaultSeries(),B=[];let q=0;for(let o=0;o<e.length;o++){const a=e[o],ne=se(o),G=a.color||ne.line;let _,A;if(a.color)if(a.topColor&&a.bottomColor)_=a.topColor,A=a.bottomColor;else if(a.topColor){const b=I.generateColorsFromBase(G);_=a.topColor,A=b.bottomColor}else if(a.bottomColor)_=I.generateColorsFromBase(G).topColor,A=a.bottomColor;else{const b=I.generateColorsFromBase(G);_=b.topColor,A=b.bottomColor}else _=a.topColor||ne.top,A=a.bottomColor||ne.bottom;if(a.data.length===0){const b=V.current.get(a.label);b&&(t.removeSeries(b),V.current.delete(a.label));continue}const Se=(a.data.length>0?Math.min(...a.data.map(b=>b.value)):0)<0,Re=a.data.some(b=>b.value===0),we=!Se&&Re,re=H||!c||q===0?"right":`scale-${q}`;c&&B.push({priceScaleId:re||"right",shouldPreventNegativeAxis:we,seriesIndex:q});let z=V.current.get(a.label);z?(z.applyOptions({lineColor:G,topColor:_,bottomColor:A,priceScaleId:re,priceFormat:{type:"custom",formatter:s}}),z.setData(a.data.map(b=>({...b,time:b.time})))):(z=t.addAreaSeries({...k,lineColor:G,topColor:_,bottomColor:A,priceScaleId:re,priceFormat:{type:"custom",formatter:s}}),z.setData(a.data.map(b=>({...b,time:b.time}))),V.current.set(a.label,z)),q++}if(c&&B.length>0)for(const o of B)try{const a=t.priceScale(o.priceScaleId);a&&a.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:d})}catch(a){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,a)}else if(!c)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!O,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...v&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:d})}catch{}const te=new Set(e.map(o=>o.label)),ve=te.size!==K.current.size||[...te].some(o=>!K.current.has(o)),xe=E.length!==ie.current;(ce.current||ve||xe||O)&&(t.timeScale().fitContent(),ce.current=!1),K.current=te,ie.current=E.length;const oe=new Map;for(const o of e)o.data.length>0&&oe.set(o.label,o.data[o.data.length-1]);U(oe.size>0?oe:void 0)},[e,E,h,P,O,H]),u.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const n=e.length===1;let l;for(const r of e)if(r.data.length>0){l=r.data[r.data.length-1].time;break}if(!l)return;const s=r=>{const{time:i=l,seriesData:f,point:w}=r||{},x=Array.from(V.current.values());if(!w||!i){const v=new Map;for(const c of e)c.data.length>0&&v.set(c.label,c.data[c.data.length-1]);if(U(v.size>0?v:void 0),n)F(null);else if(x[0]&&l){const C=t.timeScale().timeToCoordinate(l),d=e[0];if(d.data.length>0){const S=d.data[d.data.length-1].value,N=x[0].priceToCoordinate(S);C!==null&&N!==null&&F({x:C,y:N})}}return}const T=new Map;let L;for(let v=0;v<e.length;v++){const c=e[v],C=x[v];if(!C)continue;const d=f?.get(C),S=d&&"value"in d?d.value:void 0,N=c.data[c.data.length-1],k=S!==void 0?S:N?.value??0;v===0&&(L=k),T.set(c.label,{value:k,time:i})}if(U(T),L!==void 0&&x[0]){const c=t.timeScale().timeToCoordinate(i),C=x[0].priceToCoordinate(L);if(c!==null&&C!==null){const d=M.current;if(d){const S=d.querySelector(".LightweightChart");if(S){const N=S.getBoundingClientRect(),k=d.getBoundingClientRect(),B=c+(N.left-k.left),q=C+(N.top-k.top);F({x:B,y:q})}else F({x:c,y:C})}else F({x:c,y:C})}else F(null)}else F(null)};return t.subscribeCrosshairMove(s),n||requestAnimationFrame(()=>{const r=Array.from(V.current.values());if(r[0]&&l&&e[0]?.data.length>0){const f=t.timeScale().timeToCoordinate(l),w=e[0].data[e[0].data.length-1].value,x=r[0].priceToCoordinate(w);f!==null&&x!==null&&F({x:f,y:x})}}),()=>{t.unsubscribeCrosshairMove(s)}},[e]),u.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const n=t.timeScale(),l=Math.max(...e.map(r=>r.data.length)),s=()=>{if(l===0)return;const r=n.getVisibleLogicalRange();if(!r)return;const i={from:0,to:l-1},f=typeof r.from=="number"?r.from:0,w=typeof r.to=="number"?r.to:l-1;if(Q.current){const v=Math.max(0,Math.floor(f)),c=Math.min(l-1,Math.ceil(w)),C=[];for(const d of e)for(let S=v;S<=c&&S<d.data.length;S++)C.push(d.data[S].value);C.length>0&&Q.current(C)}const x=.01;let T=!1;const L={...r};f<i.from-x&&(L.from=i.from,T=!0),w>i.to+x&&(L.to=i.to,T=!0),T&&n.setVisibleLogicalRange(L)};return n.subscribeVisibleLogicalRangeChange(s),()=>{n.unsubscribeVisibleLogicalRangeChange(s)}},[e]),u.useEffect(()=>{const t=j.current,n=Array.from(V.current.values()),l=[];if(t&&n.length>0&&R){const s=X.getDefaultVerticalLine(),r=n[0];for(const i of R){const f=new je.VertLine(t,r,i.xCoordinate,{...s,...i.options||{}});r.attachPrimitive(f),l.push(f)}}return()=>{if(n.length>0){const s=n[0];for(const r of l)s.detachPrimitive(r)}}},[R]),u.useEffect(()=>{const t=j.current;if(!t||!R?.length){de([]);return}const n=()=>{const r=t.timeScale(),i=R.map(f=>r.timeToCoordinate(f.xCoordinate)??null);de(i)};n();const l=t.timeScale(),s=()=>{n()};return l.subscribeVisibleLogicalRangeChange(s),()=>{l.unsubscribeVisibleLogicalRangeChange(s)}},[R]);const ee=e.length===1,be=ae.useMemo(()=>{if(ee&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[ee,e]);return m.jsxs("div",{ref:M,className:le.cn("relative z-[1] w-full h-full overflow-hidden p-0",p),children:[he&&ee&&be&&m.jsx(Le.GraphCurrentValue,{point:be,xMeasureUnit:h,yMeasureUnit:P,decimals:W}),ue&&ge&&m.jsx(Pe.GraphTooltip,{points:ue,xMeasureUnit:h,yMeasureUnit:P,series:e,position:ge,containerRef:M,decimals:W}),g&&m.jsx(Fe,{series:e,onUnselect:y}),R&&R.length>0&&fe.length===R.length&&m.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:R.map((t,n)=>{const l=fe[n],s=t.options??{},r=s.showLabel!==!1;if(l===null||!r)return null;const{labelText:i,valueStr:f}=me(s,P,W);if(!(i||f))return null;const x=s.labelBackgroundColor??s.color??"hsl(var(--background))",T=s.labelTextColor??"hsl(var(--foreground))",L=`${String(t.xCoordinate)}-${i}`;return m.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:l,transform:"translateX(-50%)",backgroundColor:x,color:T},children:[i&&m.jsx("span",{className:"block",children:i}),f&&m.jsx("span",{className:le.cn("block",i&&"mt-0.5"),children:f})]},L)})}),m.jsx("div",{ref:J,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Fe({series:e,onUnselect:p}){return m.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((g,y)=>{const h=se(y),P=g.color||h.line,$=g.data.length===0;return m.jsxs("div",{className:le.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",$&&"opacity-50"),children:[m.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:P}}),m.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[g.label,$&&" (no data)"]}),p&&m.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),p(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:m.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:[m.jsx("title",{children:"Close"}),m.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),m.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},g.label)})})}exports.DEFAULT_SERIES_COLORS=Y;exports.Graph=Ee;exports.getSeriesColorPalette=se;exports.getVerticalLineTooltipContent=me;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),Fe=require("lightweight-charts"),f=require("react"),Me=require("../../hooks/use-media-query.cjs"),ce=require("../../utils/cn.cjs"),A=require("../../utils/colors.cjs"),H=require("./default-config.cjs"),q=require("./formatters.cjs"),_e=require("./graph-current-value.cjs"),Ae=require("./graph-tooltip.cjs"),Ie=require("./plugins/vertical-line.cjs");function Oe(e){const C=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const g in e)if(g!=="default"){const y=Object.getOwnPropertyDescriptor(e,g);Object.defineProperty(C,g,y.get?y:{enumerable:!0,get:()=>e[g]})}}return C.default=e,Object.freeze(C)}const ie=Oe(f);function we(e,C,g){const y=e.labelText??"",p=e.value,V=p===void 0?"":typeof p=="number"?C==="$"?`$${q.formatExactValue(p,void 0,g)}`:C==="%"?`${q.formatExactValue(p,void 0,g)}%`:q.formatExactValue(p,C!=="none"&&C!=="%"&&C!=="$"?C:void 0,g):String(p);return{labelText:y,valueStr:V}}const W=[{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:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 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:"#0d9488",top:"rgba(13, 148, 136, 0.56)",bottom:"rgba(13, 148, 136, 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:"#d97706",top:"rgba(217, 119, 6, 0.56)",bottom:"rgba(217, 119, 6, 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)"}],ze=137.5;function ue(e){if(e<W.length)return W[e];const g=(e-W.length)*ze%360,y=A.hslToHex(g,70,50),{topColor:p,bottomColor:V}=A.generateColorsFromBase(y);return{line:y,top:p,bottom:V}}function De({series:e,className:C,showLegend:g=!1,onUnselectSeries:y,xMeasureUnit:p="time",yMeasureUnit:V="token",optionsOverrides:$,verticalLineOptions:R,currentValueDecimals:X,useSharedPriceScale:E=!1,showCurrentValue:ye=!0,graphTitle:Z,yScaleMin:fe,yScaleMinMultiple:ge}){const N=f.useRef(null),L=f.useRef(new Map),K=f.useRef(!1),Q=f.useRef(new Set),de=f.useRef(0),be=f.useRef(!0),J=f.useRef(null),Ve=f.useRef(null),M=f.useRef(null),U=f.useRef(null),I=Me.useIsMobile(),k=ie.useMemo(()=>e.flatMap(t=>t.data),[e]),Le=ie.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[me,ee]=f.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}),[he,F]=f.useState(null),[pe,Ce]=f.useState([]);f.useEffect(()=>{const t=()=>{if(N.current&&M.current){const s=M.current.clientWidth,l=M.current.clientHeight;N.current.resize(s,l),N.current.timeScale().fitContent()}},a=M.current,n=a?new ResizeObserver(t):null;return a&&n?.observe(a),()=>{a&&n?.unobserve(a)}},[]),f.useEffect(()=>{if(!U.current||K.current)return;const t=H.getDefaultOptions(),a=A.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),n=Fe.createChart(U.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!I,textColor:a},...$});return N.current=n,K.current=!0,()=>{n.remove(),N.current=null,K.current=!1,L.current.clear()}},[I,$]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const n=e.filter(o=>o.data.length>0).length<=1?fe:ge,s=p==="time"?q.getXFormatter(p,k):q.getXFormatter(p),l=k.map(o=>o.value),{formatter:c,updateVisibleRange:b,updateLastValues:j}=q.createAdaptiveYAxisFormatter(l,V,{yScaleMin:n});J.current=b,Ve.current=j;const v=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);j(v);const w=H.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:s?(o=>s(parseFloat(o),void 0)):void 0},timeScale:{...w.timeScale||{},tickMarkFormatter:s?(o=>s(parseFloat(o),void 0)):void 0,minBarSpacing:0}});const x=(k.length>0?Math.min(...k.map(o=>o.value)):0)<0,m=k.some(o=>o.value===0),h=!x&&m,u=e.length>1&&!E,S=e.length>1&&!E||I,P=A.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...w.rightPriceScale||{},visible:!S,textColor:P,...h&&{scaleMargins:{top:.3,bottom:0}}}});const _=new Set(L.current.keys()),te=new Set(e.map(o=>o.label));for(const o of _)if(!te.has(o)){const r=L.current.get(o);r&&(t.removeSeries(r),L.current.delete(o))}const oe=H.getDefaultSeries(),ne=[];let G=0;for(let o=0;o<e.length;o++){const r=e[o],le=ue(o),Y=r.lineColor??r.color??le.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=A.generateColorsFromBase(Y);O=r.topColor,z=i.bottomColor}else if(r.bottomColor)O=A.generateColorsFromBase(Y).topColor,z=r.bottomColor;else{const i=A.generateColorsFromBase(Y);O=i.topColor,z=i.bottomColor}else O=r.topColor||le.top,z=r.bottomColor||le.bottom;if(r.data.length===0){const i=L.current.get(r.label);i&&(t.removeSeries(i),L.current.delete(r.label));continue}const Ne=(r.data.length>0?Math.min(...r.data.map(i=>i.value)):0)<0,Te=r.data.some(i=>i.value===0),Ee=!Ne&&Te,xe=E||!u||G===0?"right":`scale-${G}`;u&&ne.push({priceScaleId:xe||"right",shouldPreventNegativeAxis:Ee,seriesIndex:G});const Se=(E||!u)&&n!==void 0&&typeof n=="number",Re={lineColor:Y,topColor:O,bottomColor:z,priceScaleId:xe,priceFormat:{type:"custom",formatter:Se&&typeof n=="number"?i=>c(i<n?n:i):c},autoscaleInfoProvider:i=>{if(!Se)return i();const se=i();if(se?.priceRange){const ke=n;se.priceRange.minValue=ke}return se}};let D=L.current.get(r.label);D?(D.applyOptions(Re),D.setData(r.data.map(i=>({...i,time:i.time})))):(D=t.addAreaSeries({...oe,...Re}),D.setData(r.data.map(i=>({...i,time:i.time}))),L.current.set(r.label,D)),G++}if(u&&ne.length>0)for(const o of ne)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:P})}catch(r){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,r)}else if(!u)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!I,autoScale:!0,scaleMargins:{top:.1,bottom:n!==void 0||h?0:.1,...h&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:P})}catch{}n!==void 0&&(E||!u)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}});const re=new Set(e.map(o=>o.label)),je=re.size!==Q.current.size||[...re].some(o=>!Q.current.has(o)),Pe=k.length!==de.current;(be.current||je||Pe||I)&&(t.timeScale().fitContent(),be.current=!1),Q.current=re,de.current=k.length;const ae=new Map;for(const o of e)o.data.length>0&&ae.set(o.label,o.data[o.data.length-1]);ee(ae.size>0?ae:void 0)},[e,k,p,V,I,E,fe,ge]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const a=e.length===1;let n;for(const l of e)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:b,point:j}=l||{},v=Array.from(L.current.values());if(!j||!c){const x=new Map;for(const m of e)m.data.length>0&&x.set(m.label,m.data[m.data.length-1]);if(ee(x.size>0?x:void 0),a||E)F(null);else if(v[0]&&n){const h=t.timeScale().timeToCoordinate(n),u=e[0];if(u.data.length>0){const S=u.data[u.data.length-1].value,P=v[0].priceToCoordinate(S);h!==null&&P!==null&&F({x:h,y:P})}}return}const w=new Map;let T;for(let x=0;x<e.length;x++){const m=e[x],h=v[x];if(!h)continue;const u=b?.get(h),S=u&&"value"in u?u.value:void 0,P=m.data[m.data.length-1],_=S!==void 0?S:P?.value??0;x===0&&(T=_),w.set(m.label,{value:_,time:c})}if(ee(w),T!==void 0&&v[0]){const m=t.timeScale().timeToCoordinate(c),h=v[0].priceToCoordinate(T);if(m!==null&&h!==null){const u=M.current;if(u){const S=u.querySelector(".LightweightChart");if(S){const P=S.getBoundingClientRect(),_=u.getBoundingClientRect(),te=m+(P.left-_.left),oe=h+(P.top-_.top);F({x:te,y:oe})}else F({x:m,y:h})}else F({x:m,y:h})}else F(null)}else F(null)};return t.subscribeCrosshairMove(s),!a&&!E&&requestAnimationFrame(()=>{const l=Array.from(L.current.values());if(l[0]&&n&&e[0]?.data.length>0){const b=t.timeScale().timeToCoordinate(n),j=e[0].data[e[0].data.length-1].value,v=l[0].priceToCoordinate(j);b!==null&&v!==null&&F({x:b,y:v})}}),()=>{t.unsubscribeCrosshairMove(s)}},[e,E]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const a=t.timeScale(),n=Math.max(...e.map(l=>l.data.length)),s=()=>{if(n===0)return;const l=a.getVisibleLogicalRange();if(!l)return;const c={from:0,to:n-1},b=typeof l.from=="number"?l.from:0,j=typeof l.to=="number"?l.to:n-1;if(J.current){const x=Math.max(0,Math.floor(b)),m=Math.min(n-1,Math.ceil(j)),h=[];for(const u of e)for(let S=x;S<=m&&S<u.data.length;S++)h.push(u.data[S].value);h.length>0&&J.current(h)}const v=.01;let w=!1;const T={...l};b<c.from-v&&(T.from=c.from,w=!0),j>c.to+v&&(T.to=c.to,w=!0),w&&a.setVisibleLogicalRange(T)};return a.subscribeVisibleLogicalRangeChange(s),()=>{a.unsubscribeVisibleLogicalRangeChange(s)}},[e]),f.useEffect(()=>{const t=N.current,a=Array.from(L.current.values()),n=[];if(t&&a.length>0&&R){const s=H.getDefaultVerticalLine(),l=a[0];for(const c of R){const b=new Ie.VertLine(t,l,c.xCoordinate,{...s,...c.options||{}});l.attachPrimitive(b),n.push(b)}}return()=>{if(a.length>0){const s=a[0];for(const l of n)s.detachPrimitive(l)}}},[R]),f.useEffect(()=>{const t=N.current;if(!t||!R?.length){Ce([]);return}const a=()=>{const l=t.timeScale(),c=R.map(b=>l.timeToCoordinate(b.xCoordinate)??null);Ce(c)};a();const n=t.timeScale(),s=()=>{a()};return n.subscribeVisibleLogicalRangeChange(s),()=>{n.unsubscribeVisibleLogicalRangeChange(s)}},[R]);const B=e.length===1,ve=ie.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 d.jsxs("div",{ref:M,className:ce.cn("relative z-[1] w-full h-full overflow-hidden p-0",C),children:[Z!=null&&Z!==!1&&B?d.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:d.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Z})}):ye&&B&&ve&&d.jsx(_e.GraphCurrentValue,{point:ve,xMeasureUnit:p,yMeasureUnit:V,decimals:X}),me&&he&&d.jsx(Ae.GraphTooltip,{points:me,xMeasureUnit:p,yMeasureUnit:V,series:e,position:he,containerRef:M,decimals:X}),g&&d.jsx(qe,{series:e,onUnselect:y}),R&&R.length>0&&pe.length===R.length&&d.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:R.map((t,a)=>{const n=pe[a],s=t.options??{},l=s.showLabel!==!1;if(n===null||!l)return null;const{labelText:c,valueStr:b}=we(s,V,X);if(!(c||b))return null;const v=s.labelBackgroundColor??s.color??"hsl(var(--background))",w=s.labelTextColor??"hsl(var(--foreground))",T=`${String(t.xCoordinate)}-${c}`;return d.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:w},children:[c&&d.jsx("span",{className:"block",children:c}),b&&d.jsx("span",{className:ce.cn("block",c&&"mt-0.5"),children:b})]},T)})}),d.jsx("div",{ref:U,className:"LightweightChart w-full h-full overflow-hidden"})]})}function qe({series:e,onUnselect:C}){return d.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((g,y)=>{const p=ue(y),V=(g.lineColor??g.color)||p.line,$=g.data.length===0;return d.jsxs("div",{className:ce.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",$&&"opacity-50"),children:[d.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:V}}),d.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[g.label,$&&" (no data)"]}),C&&d.jsx("button",{type:"button",onClick:R=>{R.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:d.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:[d.jsx("title",{children:"Close"}),d.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},g.label)})})}exports.DEFAULT_SERIES_COLORS=W;exports.Graph=De;exports.getSeriesColorPalette=ue;exports.getVerticalLineTooltipContent=we;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),m=require("react"),G=require("sonner"),K=require("../../hooks/use-media-query.cjs");require("@gearbox-protocol/sdk");const ee=require("../../utils/cn.cjs");require("luxon");require("../../utils/z-index.cjs");const te=require("../buttons/range-buttons/range-buttons.cjs"),S=require("../graph/graph.cjs"),re=require("../graph/graph-view.cjs"),oe=require("./graph-dropdown.cjs"),ne=({size:e=16})=>r.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-label":"Expand fullscreen",children:[r.jsx("title",{children:"Expand fullscreen"}),r.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})]}),ie=({size:e=16})=>r.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-label":"Exit fullscreen",children:[r.jsx("title",{children:"Exit fullscreen"}),r.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"})]}),R="permissionless-ui:tradingview-series-colors:";function L(e){if(typeof window>"u"||!window.localStorage)return new Map;try{const t=window.localStorage.getItem(R+e);if(!t)return new Map;const i=JSON.parse(t);return i==null||typeof i!="object"?new Map:new Map(Object.entries(i).filter(([,l])=>typeof l=="number"&&l>=0&&l<S.DEFAULT_SERIES_COLORS.length))}catch{return new Map}}function se(e,t){if(!(typeof window>"u"||!window.localStorage))try{window.localStorage.setItem(R+e,JSON.stringify(Object.fromEntries(t)))}catch{}}function le(e,t){if(t.size===0)return;const i=L(e);for(const[l,h]of t)i.set(l,h);se(e,i)}function ce({data:e,yMeasureUnit:t,height:i=306,defaultGraph:l,onGraphSelected:h,graphs:j,isMultipleSelect:O,range:q,rangeList:C,setRange:N,onGraphExpanded:y,isGraphExpanded:k,onUnselectSeries:T,graphsWithNoData:V,loadingGraphs:D,noDataMessage:_="No data available for this graph",currentValueDecimals:B,containerClassName:F,useSharedPriceScale:z,showCurrentValue:W,yScaleMin:H,yScaleMinMultiple:J,seriesColorPersistenceKey:w,...$}){const f=m.useMemo(()=>Array.isArray(e)?e:e?[e]:[],[e]),A=m.useMemo(()=>Array.isArray(e)&&e.length>1,[e]),E=K.useIsMobile(),Q=m.useCallback((b,M)=>{G.toast.error(_)},[_]),X=m.useMemo(()=>{if(t)return Array.isArray(t)?t[0]:t},[t]),P=(!E&&y||C.length>0||h&&j&&l)&&r.jsxs("div",{className:"z-10 w-full flex flex-row flex-wrap sm:flex-nowrap items-center gap-2",children:[r.jsx("div",{children:h&&j&&l&&r.jsx(oe.GraphDropdown,{onSelected:h,items:j,defaultItem:l,multiple:O,graphsWithNoData:V,loadingGraphs:D,onNoDataSelected:Q})}),r.jsxs("div",{className:"flex flex-row flex-nowrap justify-start sm:justify-end items-center flex-1",children:[r.jsx(te.RangeButtons,{range:q,rangeList:C,setRange:N}),!E&&y&&r.jsx("button",{type:"button",className:"px-2.5 py-1.5 flex min-w-[44px] min-h-[26px] justify-center items-center text-xs leading-[14px] font-medium text-center rounded-md border cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring bg-muted border-muted text-muted-foreground hover:border-secondary ml-1.5",onClick:y,children:k?r.jsx(ie,{size:16}):r.jsx(ne,{size:16})})]})]}),u=m.useRef(new Map),g=m.useRef(0),Y=m.useMemo(()=>{const b=Array.isArray(t)?t:void 0;if(w&&f.length>0){const s=L(w);let d=-1;for(const x of f){const p=x?.title||"";if(!p)continue;const a=s.get(p);!u.current.has(p)&&a!==void 0&&(u.current.set(p,a),a>d&&(d=a))}d>=0&&(g.current=Math.max(g.current,d+1))}const M=f.map((s,d)=>{const x=s?.title||`Series ${d+1}`;if(!u.current.has(x)){const o=new Set(Array.from(u.current.values()));let n=g.current;for(let c=0;c<S.DEFAULT_SERIES_COLORS.length;c++){const v=(g.current+c)%S.DEFAULT_SERIES_COLORS.length;if(!o.has(v)){n=v;break}}u.current.set(x,n),g.current=n+1}const p=u.current.get(x)??0,a=S.getSeriesColorPalette(p),U=[...s?.data||[]].sort((o,n)=>{const c=typeof o.time=="number"?o.time:Number(o.time),v=typeof n.time=="number"?n.time:Number(n.time);return c-v}).reduce((o,n)=>{const c=n.time;return o.length===0||o[o.length-1].time!==c?o.push({time:c,value:n.value}):o[o.length-1]={time:c,value:n.value},o},[]),I=s?.lineColor??s?.color??void 0;return{data:U,label:x,yMeasureUnit:b?.[d]??(Array.isArray(t)?void 0:t),...I!=null?{lineColor:I,...s?.topColor!=null&&{topColor:s.topColor},...s?.bottomColor!=null&&{bottomColor:s.bottomColor}}:{color:a.line,topColor:a.top,bottomColor:a.bottom}}});return w&&u.current.size>0&&le(w,u.current),M},[f,t,w]),Z=A&&f.length>0?f.some(b=>!b):!e;return r.jsx("div",{style:{width:"100%",height:i?`${i}px`:void 0},className:"w-full",children:r.jsx(re.GraphViewWithData,{series:Y,loading:Z,toolbar:P,size:i?"full":"default",containerClassName:ee.cn("h-full",F),showLegend:A,onUnselectSeries:T,yMeasureUnit:X,currentValueDecimals:B,useSharedPriceScale:z,showCurrentValue:W,yScaleMin:H,yScaleMinMultiple:J,...$})})}exports.TradingView=ce;
|
|
@@ -1,126 +1,147 @@
|
|
|
1
|
-
import { DateTime as
|
|
2
|
-
import { isBelowDisplayThreshold as
|
|
3
|
-
const { MIN_DISPLAY_THRESHOLD:
|
|
4
|
-
if (
|
|
5
|
-
return e ? `<${
|
|
1
|
+
import { DateTime as D } from "luxon";
|
|
2
|
+
import { isBelowDisplayThreshold as L, FORMAT_CONSTANTS as G, toSignificantDigits as I, formatNumberWithSuffix as R } from "../../utils/format-number.js";
|
|
3
|
+
const { MIN_DISPLAY_THRESHOLD: f, MAX_EXPONENTIAL_THRESHOLD: p } = G, C = (t, e, r = "full") => {
|
|
4
|
+
if (L(t))
|
|
5
|
+
return e ? `<${f}${e}` : `<${f}`;
|
|
6
6
|
if (t === 0)
|
|
7
7
|
return e ? `0${e}` : "0";
|
|
8
|
-
const
|
|
9
|
-
maxExponentialThreshold:
|
|
8
|
+
const a = R(t, {
|
|
9
|
+
maxExponentialThreshold: p,
|
|
10
10
|
minimumFractionDigits: 0,
|
|
11
11
|
maximumFractionDigits: r === "short" ? 1 : 0,
|
|
12
12
|
format: r,
|
|
13
13
|
adaptiveDecimals: r === "short"
|
|
14
14
|
});
|
|
15
|
-
return e ? `${
|
|
16
|
-
},
|
|
17
|
-
if (
|
|
18
|
-
return e ? `<${
|
|
15
|
+
return e ? `${a}${e}` : a;
|
|
16
|
+
}, X = 2, H = (t, e) => {
|
|
17
|
+
if (L(t))
|
|
18
|
+
return e ? `<${f}${e}` : `<${f}`;
|
|
19
19
|
if (t === 0)
|
|
20
20
|
return e ? `0${e}` : "0";
|
|
21
|
-
const r =
|
|
21
|
+
const r = I(t, X);
|
|
22
22
|
return e ? `${r}${e}` : r;
|
|
23
|
-
},
|
|
24
|
-
if (
|
|
25
|
-
return `<${
|
|
23
|
+
}, P = 4, b = (t) => {
|
|
24
|
+
if (L(t))
|
|
25
|
+
return `<${f}`;
|
|
26
26
|
if (t === 0)
|
|
27
27
|
return "0";
|
|
28
28
|
const e = Math.round(t), r = Math.abs(t - e);
|
|
29
|
-
return r > 0 && r < 0.01 ? t.toFixed(12).replace(/0+$/, "").replace(/\.$/, "") :
|
|
30
|
-
},
|
|
31
|
-
if (
|
|
32
|
-
return e ? `<${
|
|
29
|
+
return r > 0 && r < 0.01 ? t.toFixed(12).replace(/0+$/, "").replace(/\.$/, "") : I(t, P);
|
|
30
|
+
}, Y = (t, e) => {
|
|
31
|
+
if (L(t))
|
|
32
|
+
return e ? `<${f} ${e}` : `<${f}`;
|
|
33
33
|
if (t === 0)
|
|
34
34
|
return e ? `0 ${e}` : "0";
|
|
35
|
-
const r = Number.isInteger(t),
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
return e ? `${
|
|
35
|
+
const r = Number.isInteger(t), a = Math.abs(t), s = r && a >= 1e3, u = Math.round(t), d = Math.abs(t - u);
|
|
36
|
+
if (d > 0 && d < 0.01 && !s) {
|
|
37
|
+
const h = t.toFixed(12).replace(/0+$/, "").replace(/\.$/, "");
|
|
38
|
+
return e ? `${h} ${e}` : h;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
maxExponentialThreshold:
|
|
40
|
+
const $ = R(t, {
|
|
41
|
+
maxExponentialThreshold: p,
|
|
42
42
|
minimumFractionDigits: r ? 0 : 2,
|
|
43
43
|
maximumFractionDigits: s ? 1 : r ? 0 : 2,
|
|
44
44
|
format: s ? "short" : "full",
|
|
45
45
|
adaptiveDecimals: s
|
|
46
46
|
});
|
|
47
|
-
return e ? `${
|
|
48
|
-
},
|
|
49
|
-
"%":
|
|
50
|
-
$:
|
|
51
|
-
token:
|
|
52
|
-
none:
|
|
53
|
-
},
|
|
54
|
-
function
|
|
47
|
+
return e ? `${$} ${e}` : $;
|
|
48
|
+
}, N = {
|
|
49
|
+
"%": H,
|
|
50
|
+
$: C,
|
|
51
|
+
token: Y,
|
|
52
|
+
none: b
|
|
53
|
+
}, q = (t) => N[t] || N.token;
|
|
54
|
+
function J(t, e, r = 4) {
|
|
55
55
|
if (t === 0)
|
|
56
56
|
return e ? `0 ${e}` : "0";
|
|
57
|
-
const
|
|
57
|
+
const a = t.toLocaleString("en-US", {
|
|
58
58
|
minimumFractionDigits: 0,
|
|
59
59
|
maximumFractionDigits: r
|
|
60
60
|
});
|
|
61
|
-
return e ? `${
|
|
61
|
+
return e ? `${a} ${e}` : a;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
function Q(t, e, r) {
|
|
64
|
+
const a = r?.yScaleMin;
|
|
65
|
+
let s = t.length > 0 ? Math.min(...t) : 0, u = t.length > 0 ? Math.max(...t) : 0, d = !1, F = [];
|
|
66
|
+
const $ = () => {
|
|
67
|
+
const n = u - s, o = (s + u) / 2;
|
|
67
68
|
let i = 1, m = "";
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
let
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
|
|
69
|
+
o >= 1e9 ? (i = 1e9, m = "B") : o >= 1e6 ? (i = 1e6, m = "M") : o >= 1e3 && (i = 1e3, m = "K");
|
|
70
|
+
const M = n / 10 / i;
|
|
71
|
+
let S = 1;
|
|
72
|
+
if (M > 0) {
|
|
73
|
+
const x = Math.floor(Math.log10(M));
|
|
74
|
+
S = Math.max(1, -x), S = Math.min(S, 4);
|
|
74
75
|
}
|
|
75
|
-
return { scale: i, suffix: m, decimals:
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
return { scale: i, suffix: m, decimals: S };
|
|
77
|
+
}, h = (n, o, i) => {
|
|
78
|
+
const m = o > 1 ? n / o : n, g = Math.abs(m) >= 1 ? 1 : 4;
|
|
79
|
+
return o > 1 ? `${(n / o).toLocaleString("en-US", {
|
|
80
|
+
minimumFractionDigits: 0,
|
|
81
|
+
maximumFractionDigits: g,
|
|
82
|
+
useGrouping: !1
|
|
83
|
+
})}${i}` : n.toLocaleString("en-US", {
|
|
84
|
+
minimumFractionDigits: 0,
|
|
85
|
+
maximumFractionDigits: g,
|
|
86
|
+
useGrouping: !1
|
|
87
|
+
});
|
|
88
|
+
}, O = 0.12, U = 0.02;
|
|
89
|
+
return { formatter: (n) => {
|
|
90
|
+
if (a !== void 0 && n < a) return "";
|
|
91
|
+
if (n === 0)
|
|
92
|
+
return d ? "" : (d = !0, "0");
|
|
93
|
+
n > 0 && (d = !1);
|
|
94
|
+
const { scale: o, suffix: i, decimals: m } = $(), g = u - s, l = g > 0 ? F.filter(
|
|
95
|
+
(c) => Math.abs(c) >= g * U
|
|
96
|
+
) : F, M = Math.abs(n) * 1e-10 || 1e-10;
|
|
97
|
+
if (l.some(
|
|
98
|
+
(c) => Math.abs(c - n) < M
|
|
99
|
+
))
|
|
100
|
+
return h(n, o, i);
|
|
101
|
+
if (l.length > 0) {
|
|
102
|
+
const c = l.reduce(
|
|
103
|
+
(E, A) => Math.abs(A - n) < Math.abs(E - n) ? A : E
|
|
104
|
+
);
|
|
105
|
+
if (Math.abs(n - c) / (Math.abs(c) || 1e-10) < O)
|
|
106
|
+
return h(c, o, i);
|
|
107
|
+
}
|
|
108
|
+
const x = o > 1 ? n / o : n, T = Math.abs(x) >= 1 ? Math.min(1, m) : m;
|
|
109
|
+
return o > 1 ? `${(n / o).toLocaleString("en-US", {
|
|
89
110
|
minimumFractionDigits: 0,
|
|
90
|
-
maximumFractionDigits:
|
|
111
|
+
maximumFractionDigits: T,
|
|
91
112
|
useGrouping: !1
|
|
92
|
-
})}${i}` :
|
|
113
|
+
})}${i}` : n.toLocaleString("en-US", {
|
|
93
114
|
minimumFractionDigits: 0,
|
|
94
|
-
maximumFractionDigits:
|
|
115
|
+
maximumFractionDigits: T,
|
|
95
116
|
useGrouping: !1
|
|
96
117
|
});
|
|
97
|
-
}, updateVisibleRange: (
|
|
98
|
-
|
|
99
|
-
}, updateLastValues: (
|
|
100
|
-
|
|
118
|
+
}, updateVisibleRange: (n) => {
|
|
119
|
+
n.length > 0 && (s = Math.min(...n), u = Math.max(...n));
|
|
120
|
+
}, updateLastValues: (n) => {
|
|
121
|
+
F = [...n];
|
|
101
122
|
} };
|
|
102
123
|
}
|
|
103
|
-
const
|
|
124
|
+
const k = (t) => D.fromSeconds(Number(t)).toFormat("dd/LL/yyyy HH:mm"), w = (t) => D.fromSeconds(Number(t)).toFormat("HH:mm"), z = () => {
|
|
104
125
|
let t = null;
|
|
105
126
|
return (e) => {
|
|
106
|
-
const r =
|
|
107
|
-
return
|
|
127
|
+
const r = D.fromSeconds(Number(e)), a = r.toFormat("yyyy-MM-dd");
|
|
128
|
+
return a !== t ? (t = a, r.toFormat("dd MMM")) : r.toFormat("HH:mm");
|
|
108
129
|
};
|
|
109
|
-
},
|
|
110
|
-
time:
|
|
111
|
-
"%":
|
|
112
|
-
},
|
|
130
|
+
}, B = (t, e) => H(Number(t), e), _ = {
|
|
131
|
+
time: k,
|
|
132
|
+
"%": B
|
|
133
|
+
}, v = (t, e) => {
|
|
113
134
|
if (t === "time" && e && e.length > 0) {
|
|
114
|
-
const r =
|
|
135
|
+
const r = D.fromSeconds(Number(e[0].time)), a = D.fromSeconds(
|
|
115
136
|
Number(e[e.length - 1].time)
|
|
116
137
|
);
|
|
117
|
-
return r.hasSame(
|
|
138
|
+
return r.hasSame(a, "day") ? w : z();
|
|
118
139
|
}
|
|
119
|
-
return
|
|
140
|
+
return _[t] || _.time;
|
|
120
141
|
};
|
|
121
142
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
Q as createAdaptiveYAxisFormatter,
|
|
144
|
+
J as formatExactValue,
|
|
145
|
+
v as getXFormatter,
|
|
146
|
+
q as getYFormatter
|
|
126
147
|
};
|