@gearbox-protocol/permissionless-ui 1.26.2 → 1.26.3

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,147 +1,189 @@
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}`;
1
+ import { TickMarkType as S } from "lightweight-charts";
2
+ import { DateTime as $ } from "luxon";
3
+ import { isBelowDisplayThreshold as x, FORMAT_CONSTANTS as U, toSignificantDigits as H, formatNumberWithSuffix as I } from "../../utils/format-number.js";
4
+ const { MIN_DISPLAY_THRESHOLD: g, MAX_EXPONENTIAL_THRESHOLD: R } = U, V = (t, e, n = "full") => {
5
+ if (x(t))
6
+ return e ? `<${g}${e}` : `<${g}`;
6
7
  if (t === 0)
7
8
  return e ? `0${e}` : "0";
8
- const a = R(t, {
9
- maxExponentialThreshold: p,
9
+ const a = I(t, {
10
+ maxExponentialThreshold: R,
10
11
  minimumFractionDigits: 0,
11
- maximumFractionDigits: r === "short" ? 1 : 0,
12
- format: r,
13
- adaptiveDecimals: r === "short"
12
+ maximumFractionDigits: n === "short" ? 1 : 0,
13
+ format: n,
14
+ adaptiveDecimals: n === "short"
14
15
  });
15
16
  return e ? `${a}${e}` : a;
16
- }, X = 2, H = (t, e) => {
17
- if (L(t))
18
- return e ? `<${f}${e}` : `<${f}`;
17
+ }, X = 2, O = (t, e) => {
18
+ if (x(t))
19
+ return e ? `<${g}${e}` : `<${g}`;
19
20
  if (t === 0)
20
21
  return e ? `0${e}` : "0";
21
- const r = I(t, X);
22
- return e ? `${r}${e}` : r;
23
- }, P = 4, b = (t) => {
24
- if (L(t))
25
- return `<${f}`;
22
+ const n = H(t, X);
23
+ return e ? `${n}${e}` : n;
24
+ }, P = 4, C = (t) => {
25
+ if (x(t))
26
+ return `<${g}`;
26
27
  if (t === 0)
27
28
  return "0";
28
- const e = Math.round(t), r = Math.abs(t - 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}`;
29
+ const e = Math.round(t), n = Math.abs(t - e);
30
+ return n > 0 && n < 0.01 ? t.toFixed(12).replace(/0+$/, "").replace(/\.$/, "") : H(t, P);
31
+ }, w = (t, e) => {
32
+ if (x(t))
33
+ return e ? `<${g} ${e}` : `<${g}`;
33
34
  if (t === 0)
34
35
  return e ? `0 ${e}` : "0";
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;
36
+ const n = Number.isInteger(t), a = Math.abs(t), c = n && a >= 1e3, s = Math.round(t), o = Math.abs(t - s);
37
+ if (o > 0 && o < 0.01 && !c) {
38
+ const D = t.toFixed(12).replace(/0+$/, "").replace(/\.$/, "");
39
+ return e ? `${D} ${e}` : D;
39
40
  }
40
- const $ = R(t, {
41
- maxExponentialThreshold: p,
42
- minimumFractionDigits: r ? 0 : 2,
43
- maximumFractionDigits: s ? 1 : r ? 0 : 2,
44
- format: s ? "short" : "full",
45
- adaptiveDecimals: s
41
+ const l = I(t, {
42
+ maxExponentialThreshold: R,
43
+ minimumFractionDigits: n ? 0 : 2,
44
+ maximumFractionDigits: c ? 1 : n ? 0 : 2,
45
+ format: c ? "short" : "full",
46
+ adaptiveDecimals: c
46
47
  });
47
- return e ? `${$} ${e}` : $;
48
+ return e ? `${l} ${e}` : l;
48
49
  }, 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) {
50
+ "%": O,
51
+ $: V,
52
+ token: w,
53
+ none: C
54
+ }, tt = (t) => N[t] || N.token;
55
+ function et(t, e, n = 4) {
55
56
  if (t === 0)
56
57
  return e ? `0 ${e}` : "0";
57
58
  const a = t.toLocaleString("en-US", {
58
59
  minimumFractionDigits: 0,
59
- maximumFractionDigits: r
60
+ maximumFractionDigits: n
60
61
  });
61
62
  return e ? `${a} ${e}` : a;
62
63
  }
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;
68
- let i = 1, m = "";
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);
64
+ function rt(t, e, n) {
65
+ const a = n?.yScaleMin;
66
+ let c = t.length > 0 ? Math.min(...t) : 0, s = t.length > 0 ? Math.max(...t) : 0, o = [];
67
+ const u = () => {
68
+ const r = s - c, i = (c + s) / 2;
69
+ let f = 1, m = "";
70
+ i >= 1e9 ? (f = 1e9, m = "B") : i >= 1e6 ? (f = 1e6, m = "M") : i >= 1e3 && (f = 1e3, m = "K");
71
+ const T = r / 10 / f;
72
+ let M = 1;
73
+ if (T > 0) {
74
+ const L = Math.floor(Math.log10(T));
75
+ M = Math.max(1, -L), M = Math.min(M, 4);
75
76
  }
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", {
77
+ return { scale: f, suffix: m, decimals: M };
78
+ }, l = (r, i, f) => {
79
+ const m = i > 1 ? r / i : r, d = Math.abs(m) >= 1 ? 1 : 4;
80
+ return i > 1 ? `${(r / i).toLocaleString("en-US", {
80
81
  minimumFractionDigits: 0,
81
- maximumFractionDigits: g,
82
+ maximumFractionDigits: d,
82
83
  useGrouping: !1
83
- })}${i}` : n.toLocaleString("en-US", {
84
+ })}${f}` : r.toLocaleString("en-US", {
84
85
  minimumFractionDigits: 0,
85
- maximumFractionDigits: g,
86
+ maximumFractionDigits: d,
86
87
  useGrouping: !1
87
88
  });
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
89
+ }, D = 0.02, k = (r) => {
90
+ if (a !== void 0 && r < a) return "";
91
+ if (r === 0) return "0";
92
+ const { scale: i, suffix: f, decimals: m } = u(), d = s - c, F = d > 0 ? o.filter(
93
+ (h) => Math.abs(h) >= d * D
94
+ ) : o, M = (d > 0 ? d / 10 : 0) * 0.05, L = Math.abs(r) * 1e-10 || 1e-10;
95
+ if (F.some(
96
+ (h) => Math.abs(h - r) < L
99
97
  ))
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
98
+ return l(r, i, f);
99
+ if (F.length > 0 && M > 0) {
100
+ const h = F.reduce(
101
+ (p, A) => Math.abs(A - r) < Math.abs(p - r) ? A : p
104
102
  );
105
- if (Math.abs(n - c) / (Math.abs(c) || 1e-10) < O)
106
- return h(c, o, i);
103
+ if (Math.abs(r - h) < M)
104
+ return l(h, i, f);
107
105
  }
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", {
106
+ const G = i > 1 ? r / i : r, E = Math.abs(G) >= 1 ? Math.min(1, m) : m;
107
+ return i > 1 ? `${(r / i).toLocaleString("en-US", {
110
108
  minimumFractionDigits: 0,
111
- maximumFractionDigits: T,
109
+ maximumFractionDigits: E,
112
110
  useGrouping: !1
113
- })}${i}` : n.toLocaleString("en-US", {
111
+ })}${f}` : r.toLocaleString("en-US", {
114
112
  minimumFractionDigits: 0,
115
- maximumFractionDigits: T,
113
+ maximumFractionDigits: E,
116
114
  useGrouping: !1
117
115
  });
118
- }, updateVisibleRange: (n) => {
119
- n.length > 0 && (s = Math.min(...n), u = Math.max(...n));
120
- }, updateLastValues: (n) => {
121
- F = [...n];
122
- } };
116
+ };
117
+ return {
118
+ formatter: (r) => k(r),
119
+ tickmarksFormatter: (r) => {
120
+ const i = /* @__PURE__ */ new Set();
121
+ return r.map((f) => {
122
+ const m = k(f);
123
+ return !m || i.has(m) ? "" : (i.add(m), m);
124
+ });
125
+ },
126
+ updateVisibleRange: (r) => {
127
+ r.length > 0 && (c = Math.min(...r), s = Math.max(...r));
128
+ },
129
+ updateLastValues: (r) => {
130
+ o = [...r];
131
+ }
132
+ };
123
133
  }
124
- const k = (t) => D.fromSeconds(Number(t)).toFormat("dd/LL/yyyy HH:mm"), w = (t) => D.fromSeconds(Number(t)).toFormat("HH:mm"), z = () => {
125
- let t = null;
126
- return (e) => {
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");
134
+ const b = (t) => $.fromSeconds(Number(t)).toFormat("dd/LL/yyyy HH:mm"), Y = (t) => $.fromSeconds(Number(t)).toFormat("HH:mm"), y = (t, e) => O(Number(t), e), _ = {
135
+ time: b,
136
+ "%": y
137
+ };
138
+ function W(t) {
139
+ const e = /* @__PURE__ */ new Map();
140
+ return (n, a, c) => {
141
+ const s = $.fromSeconds(Number(n));
142
+ let o;
143
+ if (t === 0)
144
+ o = s.toFormat("HH:mm");
145
+ else
146
+ switch (a) {
147
+ case S.Year:
148
+ o = s.toFormat("yyyy");
149
+ break;
150
+ case S.Month:
151
+ o = s.toFormat("MMM yy");
152
+ break;
153
+ case S.DayOfMonth:
154
+ o = t > 365 ? s.toFormat("dd MMM yy") : s.toFormat("dd MMM");
155
+ break;
156
+ case S.Time:
157
+ case S.TimeWithSeconds:
158
+ o = s.toFormat("HH:mm");
159
+ break;
160
+ default:
161
+ o = s.toFormat("dd MMM");
162
+ }
163
+ let u = e.get(a);
164
+ return u || (u = /* @__PURE__ */ new Set(), e.set(a, u)), u.has(o) ? " " : (u.add(o), o);
129
165
  };
130
- }, B = (t, e) => H(Number(t), e), _ = {
131
- time: k,
132
- "%": B
133
- }, v = (t, e) => {
166
+ }
167
+ const z = (t, e) => {
134
168
  if (t === "time" && e && e.length > 0) {
135
- const r = D.fromSeconds(Number(e[0].time)), a = D.fromSeconds(
169
+ const a = $.fromSeconds(Number(e[0].time)), c = $.fromSeconds(
136
170
  Number(e[e.length - 1].time)
137
- );
138
- return r.hasSame(a, "day") ? w : z();
171
+ ), s = a.hasSame(c, "day"), o = s ? 0 : Math.ceil(c.diff(a, "days").days);
172
+ return {
173
+ timeFormatter: s ? Y : b,
174
+ tickMarkFormatter: W(o)
175
+ };
139
176
  }
140
- return _[t] || _.time;
141
- };
177
+ const n = _[t] || _.time;
178
+ return {
179
+ timeFormatter: n,
180
+ tickMarkFormatter: (a) => n(a, void 0)
181
+ };
182
+ }, nt = (t, e) => z(t, e).timeFormatter;
142
183
  export {
143
- Q as createAdaptiveYAxisFormatter,
144
- J as formatExactValue,
145
- v as getXFormatter,
146
- q as getYFormatter
184
+ rt as createAdaptiveYAxisFormatter,
185
+ et as formatExactValue,
186
+ nt as getXFormatter,
187
+ z as getXFormatters,
188
+ tt as getYFormatter
147
189
  };
@@ -13,28 +13,28 @@ function M({
13
13
  containerRef: b,
14
14
  decimals: u
15
15
  }) {
16
- const w = k(null), [f, l] = F(t), C = A(g);
16
+ const w = k(null), [f, a] = F(t), C = A(g);
17
17
  S(() => {
18
18
  if (!t) {
19
- l(t);
19
+ a(t);
20
20
  return;
21
21
  }
22
22
  const r = b?.current;
23
23
  if (!r) {
24
- l(t);
24
+ a(t);
25
25
  return;
26
26
  }
27
27
  const c = w.current;
28
28
  if (!c) {
29
- l(t);
29
+ a(t);
30
30
  return;
31
31
  }
32
32
  const o = r.getBoundingClientRect(), i = c.getBoundingClientRect();
33
33
  let n = t.x, e = t.y;
34
- const s = i.width, p = i.height, a = 8;
35
- n - s / 2 < a ? n = s / 2 + a : n + s / 2 > o.width - a && (n = o.width - s / 2 - a);
34
+ const s = i.width, p = i.height, l = 8;
35
+ n - s / 2 < l ? n = s / 2 + l : n + s / 2 > o.width - l && (n = o.width - s / 2 - l);
36
36
  const y = p + 8;
37
- e - y < a ? e = t.y + 20 : e = t.y - y, l({ x: n, y: e });
37
+ e - y < l ? e = t.y + 20 : e = t.y - y, a({ x: n, y: e });
38
38
  }, [t, b]);
39
39
  const P = f ? {
40
40
  left: `${f.x}px`,
@@ -59,7 +59,7 @@ function M({
59
59
  v.map((r, c) => {
60
60
  const o = d.get(r.label);
61
61
  if (!o) return null;
62
- const i = B(c), n = r.color || i.line, e = r.yMeasureUnit || N, s = e !== "%" && e !== "$" && e !== "none" ? e : void 0, p = e === "$" ? `$${x(o.value, void 0, u)}` : e === "%" ? `${x(o.value, void 0, u)}%` : x(o.value, s, u);
62
+ const i = B(c), n = (r.lineColor ?? r.color) || i.line, e = r.yMeasureUnit || N, s = e !== "%" && e !== "$" && e !== "none" ? e : void 0, p = e === "$" ? `$${x(o.value, void 0, u)}` : e === "%" ? `${x(o.value, void 0, u)}%` : x(o.value, s, u);
63
63
  return /* @__PURE__ */ h(
64
64
  "div",
65
65
  {