@gearbox-protocol/permissionless-ui 1.26.2 → 1.26.4

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,225 +1,250 @@
1
- import { jsxs as Y, jsx as p } from "react/jsx-runtime";
2
- import { createChart as $t } from "lightweight-charts";
3
- import * as it from "react";
4
- import { useRef as T, useState as st, useEffect as E } from "react";
5
- import { useIsMobile as Dt } from "../../hooks/use-media-query.js";
6
- import { cn as ft } from "../../utils/cn.js";
7
- import { resolveCSSColor as Vt, generateColorsFromBase as _, hslToHex as Gt } from "../../utils/colors.js";
8
- import { getDefaultOptions as yt, getDefaultSeries as Ot, getDefaultVerticalLine as Bt } from "./default-config.js";
9
- import { getXFormatter as Lt, createAdaptiveYAxisFormatter as Yt, formatExactValue as ct } from "./formatters.js";
10
- import { GraphCurrentValue as jt } from "./graph-current-value.js";
11
- import { GraphTooltip as Ht } from "./graph-tooltip.js";
12
- import { VertLine as Wt } from "./plugins/vertical-line.js";
13
- function _t(t, x, b) {
14
- const A = t.labelText ?? "", m = t.value, R = m === void 0 ? "" : typeof m == "number" ? x === "$" ? `$${ct(m, void 0, b)}` : x === "%" ? `${ct(m, void 0, b)}%` : ct(
15
- m,
16
- x !== "none" && x !== "%" && x !== "$" ? x : void 0,
1
+ import { jsxs as H, jsx as m } from "react/jsx-runtime";
2
+ import { createChart as Gt, CrosshairMode as Bt, AreaSeries as Ot } from "lightweight-charts";
3
+ import * as ct from "react";
4
+ import { useRef as k, useState as ut, useEffect as D } from "react";
5
+ import { useIsMobile as Yt } from "../../hooks/use-media-query.js";
6
+ import { cn as dt } from "../../utils/cn.js";
7
+ import { resolveCSSColor as yt, generateColorsFromBase as q, hslToHex as Ht } from "../../utils/colors.js";
8
+ import { getDefaultOptions as Vt, getDefaultSeries as jt, getDefaultVerticalLine as Wt } from "./default-config.js";
9
+ import { getXFormatters as kt, createAdaptiveYAxisFormatter as _t, formatExactValue as ft } from "./formatters.js";
10
+ import { GraphCurrentValue as Xt } from "./graph-current-value.js";
11
+ import { GraphTooltip as Nt } from "./graph-tooltip.js";
12
+ import { VertLine as qt } from "./plugins/vertical-line.js";
13
+ function Zt(e, C, b) {
14
+ const I = e.labelText ?? "", f = e.value, v = f === void 0 ? "" : typeof f == "number" ? C === "$" ? `$${ft(f, void 0, b)}` : C === "%" ? `${ft(f, void 0, b)}%` : ft(
15
+ f,
16
+ C !== "none" && C !== "%" && C !== "$" ? C : void 0,
17
17
  b
18
- ) : String(m);
19
- return { labelText: A, valueStr: R };
18
+ ) : String(f);
19
+ return { labelText: I, valueStr: v };
20
20
  }
21
- const ut = [
21
+ const gt = [
22
+ // 0 green (emerald)
22
23
  {
23
24
  line: "#02c39a",
24
25
  top: "rgba(2, 195, 154, 0.56)",
25
26
  bottom: "rgba(2, 195, 154, 0.04)"
26
27
  },
28
+ // 1 blue
27
29
  {
28
30
  line: "#3b82f6",
29
31
  top: "rgba(59, 130, 246, 0.56)",
30
32
  bottom: "rgba(59, 130, 246, 0.04)"
31
33
  },
34
+ // 2 red
32
35
  {
33
36
  line: "#ef4444",
34
37
  top: "rgba(239, 68, 68, 0.56)",
35
38
  bottom: "rgba(239, 68, 68, 0.04)"
36
39
  },
40
+ // 3 amber
37
41
  {
38
42
  line: "#f59e0b",
39
43
  top: "rgba(245, 158, 11, 0.56)",
40
44
  bottom: "rgba(245, 158, 11, 0.04)"
41
45
  },
46
+ // 4 violet
42
47
  {
43
48
  line: "#8b5cf6",
44
49
  top: "rgba(139, 92, 246, 0.56)",
45
50
  bottom: "rgba(139, 92, 246, 0.04)"
46
51
  },
52
+ // 5 pink
47
53
  {
48
54
  line: "#ec4899",
49
55
  top: "rgba(236, 72, 153, 0.56)",
50
56
  bottom: "rgba(236, 72, 153, 0.04)"
51
57
  },
58
+ // 6 cyan
52
59
  {
53
60
  line: "#06b6d4",
54
61
  top: "rgba(6, 182, 212, 0.56)",
55
62
  bottom: "rgba(6, 182, 212, 0.04)"
56
63
  },
64
+ // 7 orange
57
65
  {
58
- line: "#0ea5e9",
59
- top: "rgba(14, 165, 233, 0.56)",
60
- bottom: "rgba(14, 165, 233, 0.04)"
66
+ line: "#ea580c",
67
+ top: "rgba(234, 88, 12, 0.56)",
68
+ bottom: "rgba(234, 88, 12, 0.04)"
61
69
  },
70
+ // 8 lime
62
71
  {
63
- line: "#6366f1",
64
- top: "rgba(99, 102, 241, 0.56)",
65
- bottom: "rgba(99, 102, 241, 0.04)"
72
+ line: "#84cc16",
73
+ top: "rgba(132, 204, 22, 0.56)",
74
+ bottom: "rgba(132, 204, 22, 0.04)"
66
75
  },
76
+ // 9 fuchsia
67
77
  {
68
78
  line: "#d946ef",
69
79
  top: "rgba(217, 70, 239, 0.56)",
70
80
  bottom: "rgba(217, 70, 239, 0.04)"
71
81
  },
82
+ // 10 sky
72
83
  {
73
- line: "#10b981",
74
- top: "rgba(16, 185, 129, 0.56)",
75
- bottom: "rgba(16, 185, 129, 0.04)"
76
- },
77
- {
78
- line: "#ea580c",
79
- top: "rgba(234, 88, 12, 0.56)",
80
- bottom: "rgba(234, 88, 12, 0.04)"
81
- },
82
- {
83
- line: "#84cc16",
84
- top: "rgba(132, 204, 22, 0.56)",
85
- bottom: "rgba(132, 204, 22, 0.04)"
84
+ line: "#0ea5e9",
85
+ top: "rgba(14, 165, 233, 0.56)",
86
+ bottom: "rgba(14, 165, 233, 0.04)"
86
87
  },
88
+ // 11 teal
87
89
  {
88
- line: "#0d9488",
89
- top: "rgba(13, 148, 136, 0.56)",
90
- bottom: "rgba(13, 148, 136, 0.04)"
90
+ line: "#14b8a6",
91
+ top: "rgba(20, 184, 166, 0.56)",
92
+ bottom: "rgba(20, 184, 166, 0.04)"
91
93
  },
94
+ // 12 yellow
92
95
  {
93
96
  line: "#eab308",
94
97
  top: "rgba(234, 179, 8, 0.56)",
95
98
  bottom: "rgba(234, 179, 8, 0.04)"
96
99
  },
100
+ // 13 rose
97
101
  {
98
102
  line: "#f43f5e",
99
103
  top: "rgba(244, 63, 94, 0.56)",
100
104
  bottom: "rgba(244, 63, 94, 0.04)"
101
105
  },
106
+ // 14 indigo
107
+ {
108
+ line: "#6366f1",
109
+ top: "rgba(99, 102, 241, 0.56)",
110
+ bottom: "rgba(99, 102, 241, 0.04)"
111
+ },
112
+ // 15 emerald
113
+ {
114
+ line: "#10b981",
115
+ top: "rgba(16, 185, 129, 0.56)",
116
+ bottom: "rgba(16, 185, 129, 0.04)"
117
+ },
118
+ // 16 warm-gray
102
119
  {
103
- line: "#d97706",
104
- top: "rgba(217, 119, 6, 0.56)",
105
- bottom: "rgba(217, 119, 6, 0.04)"
120
+ line: "#78716c",
121
+ top: "rgba(120, 113, 108, 0.56)",
122
+ bottom: "rgba(120, 113, 108, 0.04)"
106
123
  },
124
+ // 17 slate
107
125
  {
108
126
  line: "#64748b",
109
127
  top: "rgba(100, 116, 139, 0.56)",
110
128
  bottom: "rgba(100, 116, 139, 0.04)"
111
129
  },
130
+ // 18 dark-slate
112
131
  {
113
132
  line: "#475569",
114
133
  top: "rgba(71, 85, 105, 0.56)",
115
134
  bottom: "rgba(71, 85, 105, 0.04)"
116
135
  }
117
- ], Xt = 137.5;
118
- function Nt(t) {
119
- if (t < ut.length)
120
- return ut[t];
121
- const b = (t - ut.length) * Xt % 360, A = Gt(b, 70, 50), { topColor: m, bottomColor: R } = _(A);
122
- return { line: A, top: m, bottom: R };
136
+ ], Kt = 137.5;
137
+ function Lt(e) {
138
+ if (e < gt.length)
139
+ return gt[e];
140
+ const b = (e - gt.length) * Kt % 360, I = Ht(b, 70, 50), { topColor: f, bottomColor: v } = q(I);
141
+ return { line: I, top: f, bottom: v };
123
142
  }
124
- function ce({
125
- series: t,
126
- className: x,
143
+ function ge({
144
+ series: e,
145
+ className: C,
127
146
  showLegend: b = !1,
128
- onUnselectSeries: A,
129
- xMeasureUnit: m = "time",
130
- yMeasureUnit: R = "token",
131
- optionsOverrides: B,
132
- verticalLineOptions: S,
133
- currentValueDecimals: X,
134
- useSharedPriceScale: k = !1,
147
+ onUnselectSeries: I,
148
+ xMeasureUnit: f = "time",
149
+ yMeasureUnit: v = "token",
150
+ optionsOverrides: O,
151
+ verticalLineOptions: x,
152
+ currentValueDecimals: j,
153
+ useSharedPriceScale: N = !1,
135
154
  showCurrentValue: Pt = !0,
136
- graphTitle: q,
137
- yScaleMin: dt,
138
- yScaleMinMultiple: gt
155
+ graphTitle: Z,
156
+ yScaleMin: mt,
157
+ yScaleMinMultiple: bt
139
158
  }) {
140
- const N = T(null), V = T(/* @__PURE__ */ new Map()), Z = T(!1), K = T(/* @__PURE__ */ new Set()), mt = T(0), bt = T(!0), J = T(
159
+ const V = k(null), R = k(/* @__PURE__ */ new Map()), K = k(!1), J = k(/* @__PURE__ */ new Set()), pt = k(0), ht = k(!0), Q = k(
141
160
  null
142
- ), Tt = T(null), F = T(null), Q = T(null), $ = Dt(), M = it.useMemo(() => t.flatMap((e) => e.data), [t]), kt = it.useMemo(() => {
143
- if (t.length > 0) {
144
- const e = t[t.length - 1];
145
- if (e.data.length > 0)
146
- return e.data[e.data.length - 1];
161
+ ), Tt = k(null), M = k(null), U = k(null), S = Yt(), z = ct.useMemo(() => e.flatMap((t) => t.data), [e]), Ft = ct.useMemo(() => {
162
+ if (e.length > 0) {
163
+ const t = e[e.length - 1];
164
+ if (t.data.length > 0)
165
+ return t.data[t.data.length - 1];
147
166
  }
148
- }, [t]), [ht, U] = st(() => {
149
- if (!kt) return;
150
- const e = /* @__PURE__ */ new Map();
151
- for (const a of t)
152
- a.data.length > 0 && e.set(a.label, a.data[a.data.length - 1]);
153
- return e;
154
- }), [pt, I] = st(null), [Ct, vt] = st([]);
155
- E(() => {
156
- const e = () => {
157
- if (N.current && F.current) {
158
- const i = F.current.clientWidth, l = F.current.clientHeight;
159
- N.current.resize(i, l), N.current.timeScale().fitContent();
167
+ }, [e]), [W, tt] = ut(() => {
168
+ if (!Ft) return;
169
+ const t = /* @__PURE__ */ new Map();
170
+ for (const a of e)
171
+ a.data.length > 0 && t.set(a.label, a.data[a.data.length - 1]);
172
+ return t;
173
+ }), [et, $] = ut(null), [Ct, vt] = ut([]);
174
+ D(() => {
175
+ const t = () => {
176
+ if (V.current && M.current) {
177
+ const l = M.current.clientWidth, s = M.current.clientHeight;
178
+ V.current.resize(l, s), V.current.timeScale().fitContent();
160
179
  }
161
- }, a = F.current, n = a ? new ResizeObserver(e) : null;
180
+ }, a = M.current, n = a ? new ResizeObserver(t) : null;
162
181
  return a && n?.observe(a), () => {
163
182
  a && n?.unobserve(a);
164
183
  };
165
- }, []), E(() => {
166
- if (!Q.current || Z.current) return;
167
- const e = yt(), a = Vt(
184
+ }, []), D(() => {
185
+ if (!U.current || K.current) return;
186
+ const t = Vt(), a = yt(
168
187
  "hsl(var(--foreground))",
169
188
  "rgb(0, 0, 0)"
170
- ), n = $t(Q.current, {
171
- ...e,
189
+ ), n = Gt(U.current, {
190
+ ...t,
172
191
  rightPriceScale: {
173
- ...e.rightPriceScale || {},
174
- visible: !$,
192
+ ...t.rightPriceScale || {},
193
+ visible: !S,
175
194
  textColor: a
176
195
  },
177
- ...B
196
+ ...S && {
197
+ crosshair: {
198
+ ...t.crosshair,
199
+ mode: Bt.Magnet
200
+ }
201
+ },
202
+ ...O
178
203
  });
179
- return N.current = n, Z.current = !0, () => {
180
- n.remove(), N.current = null, Z.current = !1, V.current.clear();
204
+ return V.current = n, K.current = !0, () => {
205
+ n.remove(), V.current = null, K.current = !1, R.current.clear();
181
206
  };
182
- }, [$, B]), E(() => {
183
- const e = N.current;
184
- if (!e || t.length === 0) return;
185
- const n = t.filter((o) => o.data.length > 0).length <= 1 ? dt : gt, i = m === "time" ? Lt(m, M) : Lt(m), l = M.map((o) => o.value), {
207
+ }, [S, O]), D(() => {
208
+ const t = V.current;
209
+ if (!t || e.length === 0) return;
210
+ const n = e.filter((o) => o.data.length > 0).length <= 1 ? mt : bt, l = f === "time" ? kt(f, z) : kt(f), s = z.map((o) => o.value), {
186
211
  formatter: c,
187
- updateVisibleRange: f,
188
- updateLastValues: y
189
- } = Yt(l, R, {
212
+ tickmarksFormatter: u,
213
+ updateVisibleRange: L,
214
+ updateLastValues: g
215
+ } = _t(s, v, {
190
216
  yScaleMin: n
191
217
  });
192
- J.current = f, Tt.current = y;
193
- const h = t.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
194
- y(h);
195
- const w = yt();
196
- e.applyOptions({
218
+ Q.current = L, Tt.current = g;
219
+ const P = e.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
220
+ g(P);
221
+ const T = Vt();
222
+ t.applyOptions({
197
223
  localization: {
198
- ...w.localization || {},
199
- timeFormatter: i ? (
224
+ ...T.localization || {},
225
+ // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
226
+ timeFormatter: (o) => (
200
227
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
201
- ((o) => i(parseFloat(o), void 0))
202
- ) : void 0
228
+ l.timeFormatter(parseFloat(o), void 0)
229
+ )
203
230
  },
204
231
  timeScale: {
205
- ...w.timeScale || {},
206
- tickMarkFormatter: i ? (
207
- // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
208
- ((o) => i(parseFloat(o), void 0))
209
- ) : void 0,
232
+ ...T.timeScale || {},
233
+ // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
234
+ tickMarkFormatter: l.tickMarkFormatter,
210
235
  minBarSpacing: 0
211
236
  }
212
237
  });
213
- const C = (M.length > 0 ? Math.min(...M.map((o) => o.value)) : 0) < 0, d = M.some((o) => o.value === 0), g = !C && d, u = t.length > 1 && !k, v = t.length > 1 && !k || $, L = Vt(
238
+ const d = (z.length > 0 ? Math.min(...z.map((o) => o.value)) : 0) < 0, w = z.some((o) => o.value === 0), p = !d && w, h = e.length > 1 && !N, F = e.length > 1 && !N || S, A = yt(
214
239
  "hsl(var(--foreground))",
215
240
  "rgb(0, 0, 0)"
216
241
  );
217
- e.applyOptions({
242
+ t.applyOptions({
218
243
  rightPriceScale: {
219
- ...w.rightPriceScale || {},
220
- visible: !v,
221
- textColor: L,
222
- ...g && {
244
+ ...T.rightPriceScale || {},
245
+ visible: !F,
246
+ textColor: A,
247
+ ...p && {
223
248
  scaleMargins: {
224
249
  top: 0.3,
225
250
  bottom: 0
@@ -227,83 +252,85 @@ function ce({
227
252
  }
228
253
  }
229
254
  });
230
- const z = new Set(V.current.keys()), tt = new Set(t.map((o) => o.label));
231
- for (const o of z)
232
- if (!tt.has(o)) {
233
- const r = V.current.get(o);
234
- r && (e.removeSeries(r), V.current.delete(o));
255
+ const ot = new Set(R.current.keys()), nt = new Set(e.map((o) => o.label));
256
+ for (const o of ot)
257
+ if (!nt.has(o)) {
258
+ const r = R.current.get(o);
259
+ r && (t.removeSeries(r), R.current.delete(o));
235
260
  }
236
- const et = Ot(), ot = [];
237
- let H = 0;
238
- for (let o = 0; o < t.length; o++) {
239
- const r = t[o], at = Nt(o), W = r.lineColor ?? r.color ?? at.line;
240
- let D, G;
261
+ const At = jt(), rt = [];
262
+ let _ = 0;
263
+ for (let o = 0; o < e.length; o++) {
264
+ const r = e[o], it = Lt(o), X = r.lineColor ?? r.color ?? it.line;
265
+ let E, G;
241
266
  if (r.lineColor ?? r.color)
242
267
  if (r.topColor && r.bottomColor)
243
- D = r.topColor, G = r.bottomColor;
268
+ E = r.topColor, G = r.bottomColor;
244
269
  else if (r.topColor) {
245
- const s = _(W);
246
- D = r.topColor, G = s.bottomColor;
270
+ const i = q(X);
271
+ E = r.topColor, G = i.bottomColor;
247
272
  } else if (r.bottomColor)
248
- D = _(W).topColor, G = r.bottomColor;
273
+ E = q(X).topColor, G = r.bottomColor;
249
274
  else {
250
- const s = _(W);
251
- D = s.topColor, G = s.bottomColor;
275
+ const i = q(X);
276
+ E = i.topColor, G = i.bottomColor;
252
277
  }
253
278
  else
254
- D = r.topColor || at.top, G = r.bottomColor || at.bottom;
279
+ E = r.topColor || it.top, G = r.bottomColor || it.bottom;
255
280
  if (r.data.length === 0) {
256
- const s = V.current.get(r.label);
257
- s && (e.removeSeries(s), V.current.delete(r.label));
281
+ const i = R.current.get(r.label);
282
+ i && (t.removeSeries(i), R.current.delete(r.label));
258
283
  continue;
259
284
  }
260
- const It = (r.data.length > 0 ? Math.min(...r.data.map((s) => s.value)) : 0) < 0, Ft = r.data.some((s) => s.value === 0), zt = !It && Ft, St = k || !u || H === 0 ? "right" : `scale-${H}`;
261
- u && ot.push({
285
+ const zt = (r.data.length > 0 ? Math.min(...r.data.map((i) => i.value)) : 0) < 0, $t = r.data.some((i) => i.value === 0), Dt = !zt && $t, St = N || !h || _ === 0 ? "right" : `scale-${_}`;
286
+ h && rt.push({
262
287
  priceScaleId: St || "right",
263
- shouldPreventNegativeAxis: zt,
264
- seriesIndex: H
288
+ shouldPreventNegativeAxis: Dt,
289
+ seriesIndex: _
265
290
  });
266
- const wt = (k || !u) && n !== void 0 && typeof n == "number", Rt = {
267
- lineColor: W,
268
- topColor: D,
291
+ const wt = (N || !h) && n !== void 0 && typeof n == "number", Rt = {
292
+ lineColor: X,
293
+ topColor: E,
269
294
  bottomColor: G,
270
295
  priceScaleId: St,
271
296
  priceFormat: {
272
297
  type: "custom",
273
- formatter: wt && typeof n == "number" ? (s) => c(
274
- s < n ? n : s
275
- ) : c
298
+ minMove: 0.01,
299
+ formatter: wt && typeof n == "number" ? (i) => c(
300
+ i < n ? n : i
301
+ ) : c,
302
+ tickmarksFormatter: u
276
303
  },
277
- autoscaleInfoProvider: (s) => {
278
- if (!wt) return s();
279
- const lt = s();
280
- if (lt?.priceRange) {
304
+ autoscaleInfoProvider: (i) => {
305
+ if (!wt) return i();
306
+ const st = i();
307
+ if (st?.priceRange) {
281
308
  const Et = n;
282
- lt.priceRange.minValue = Et;
309
+ st.priceRange.minValue = Et;
283
310
  }
284
- return lt;
311
+ return st;
285
312
  }
286
313
  };
287
- let O = V.current.get(r.label);
288
- O ? (O.applyOptions(Rt), O.setData(
289
- r.data.map((s) => ({
290
- ...s,
291
- time: s.time
314
+ let B = R.current.get(r.label);
315
+ B ? (B.applyOptions(Rt), B.setData(
316
+ r.data.map((i) => ({
317
+ ...i,
318
+ time: i.time
292
319
  }))
293
- )) : (O = e.addAreaSeries({
294
- ...et,
320
+ )) : (B = t.addSeries(Ot, {
321
+ ...At,
295
322
  ...Rt
296
- }), O.setData(
297
- r.data.map((s) => ({
298
- ...s,
299
- time: s.time
323
+ }), B.setData(
324
+ r.data.map((i) => ({
325
+ ...i,
326
+ time: i.time
300
327
  }))
301
- ), V.current.set(r.label, O)), H++;
328
+ ), R.current.set(r.label, B)), _++;
302
329
  }
303
- if (u && ot.length > 0)
304
- for (const o of ot)
330
+ if (h && rt.length > 0)
331
+ for (const o of rt)
305
332
  try {
306
- const r = e.priceScale(o.priceScaleId);
333
+ const r = t.priceScale(o.priceScaleId);
307
334
  r && r.applyOptions({
308
335
  visible: !1,
309
336
  autoScale: !0,
@@ -319,7 +346,7 @@ function ce({
319
346
  borderVisible: !0,
320
347
  borderColor: "rgba(224, 227, 235, 0.1)",
321
348
  entireTextOnly: !1,
322
- textColor: L
349
+ textColor: A
323
350
  });
324
351
  } catch (r) {
325
352
  console.warn(
@@ -327,17 +354,17 @@ function ce({
327
354
  r
328
355
  );
329
356
  }
330
- else if (!u)
357
+ else if (!h)
331
358
  try {
332
- const o = e.priceScale("right");
359
+ const o = t.priceScale("right");
333
360
  o && o.applyOptions({
334
- visible: !$,
361
+ visible: !S,
335
362
  autoScale: !0,
336
363
  scaleMargins: {
337
364
  top: 0.1,
338
365
  // No bottom margin when yScaleMin is set so the scale doesn't extend below the minimum (avoids negative labels like -10M)
339
- bottom: n !== void 0 || g ? 0 : 0.1,
340
- ...g && {
366
+ bottom: n !== void 0 || p ? 0 : 0.1,
367
+ ...p && {
341
368
  top: 0.3
342
369
  }
343
370
  },
@@ -345,237 +372,241 @@ function ce({
345
372
  borderVisible: !0,
346
373
  borderColor: "rgba(224, 227, 235, 0.1)",
347
374
  entireTextOnly: !1,
348
- textColor: L
375
+ textColor: A
349
376
  });
350
377
  } catch {
351
378
  }
352
- n !== void 0 && (k || !u) && e.applyOptions({
379
+ n !== void 0 && !S && (N || !h) && t.applyOptions({
353
380
  handleScroll: {
354
381
  vertTouchDrag: !1
355
382
  }
356
383
  });
357
- const nt = new Set(t.map((o) => o.label)), At = nt.size !== K.current.size || [...nt].some((o) => !K.current.has(o)), Mt = M.length !== mt.current;
358
- (bt.current || At || Mt || $) && (e.timeScale().fitContent(), bt.current = !1), K.current = nt, mt.current = M.length;
359
- const rt = /* @__PURE__ */ new Map();
360
- for (const o of t)
361
- o.data.length > 0 && rt.set(o.label, o.data[o.data.length - 1]);
362
- U(rt.size > 0 ? rt : void 0);
384
+ const at = new Set(e.map((o) => o.label)), It = at.size !== J.current.size || [...at].some((o) => !J.current.has(o)), Mt = z.length !== pt.current;
385
+ (ht.current || It || Mt || S) && (t.timeScale().fitContent(), ht.current = !1), J.current = at, pt.current = z.length;
386
+ const lt = /* @__PURE__ */ new Map();
387
+ for (const o of e)
388
+ o.data.length > 0 && lt.set(o.label, o.data[o.data.length - 1]);
389
+ tt(lt.size > 0 ? lt : void 0);
363
390
  }, [
364
- t,
365
- M,
366
- m,
367
- R,
368
- $,
369
- k,
370
- dt,
371
- gt
372
- ]), E(() => {
373
- const e = N.current;
374
- if (!e || t.length === 0) return;
375
- const a = t.length === 1;
391
+ e,
392
+ z,
393
+ f,
394
+ v,
395
+ S,
396
+ N,
397
+ mt,
398
+ bt
399
+ ]), D(() => {
400
+ const t = V.current;
401
+ if (!t || e.length === 0) return;
402
+ const a = e.length === 1;
376
403
  let n;
377
- for (const l of t)
378
- if (l.data.length > 0) {
379
- n = l.data[l.data.length - 1].time;
404
+ for (const s of e)
405
+ if (s.data.length > 0) {
406
+ n = s.data[s.data.length - 1].time;
380
407
  break;
381
408
  }
382
409
  if (!n) return;
383
- const i = (l) => {
384
- const { time: c = n, seriesData: f, point: y } = l || {}, h = Array.from(V.current.values());
385
- if (!y || !c) {
386
- const C = /* @__PURE__ */ new Map();
387
- for (const d of t)
388
- d.data.length > 0 && C.set(d.label, d.data[d.data.length - 1]);
389
- if (U(C.size > 0 ? C : void 0), a || k)
390
- I(null);
391
- else if (h[0] && n) {
392
- const g = e.timeScale().timeToCoordinate(n), u = t[0];
393
- if (u.data.length > 0) {
394
- const v = u.data[u.data.length - 1].value, L = h[0].priceToCoordinate(v);
395
- g !== null && L !== null && I({ x: g, y: L });
410
+ const l = (s) => {
411
+ const { time: c = n, seriesData: u, point: L } = s || {}, g = Array.from(R.current.values());
412
+ if (!L || !c) {
413
+ const y = /* @__PURE__ */ new Map();
414
+ for (const d of e)
415
+ d.data.length > 0 && y.set(d.label, d.data[d.data.length - 1]);
416
+ if (tt(y.size > 0 ? y : void 0), a || N)
417
+ $(null);
418
+ else if (g[0] && n) {
419
+ const w = t.timeScale().timeToCoordinate(n), p = e[0];
420
+ if (p.data.length > 0) {
421
+ const h = p.data[p.data.length - 1].value, F = g[0].priceToCoordinate(h);
422
+ w !== null && F !== null && $({ x: w, y: F });
396
423
  }
397
424
  }
398
425
  return;
399
426
  }
400
- const w = /* @__PURE__ */ new Map();
401
- let P;
402
- for (let C = 0; C < t.length; C++) {
403
- const d = t[C], g = h[C];
404
- if (!g) continue;
405
- const u = f?.get(g), v = u && "value" in u ? u.value : void 0, L = d.data[d.data.length - 1], z = v !== void 0 ? v : L?.value ?? 0;
406
- C === 0 && (P = z), w.set(d.label, { value: z, time: c });
427
+ const P = /* @__PURE__ */ new Map();
428
+ let T;
429
+ for (let y = 0; y < e.length; y++) {
430
+ const d = e[y], w = g[y];
431
+ if (!w) continue;
432
+ const p = u?.get(w), h = p && "value" in p ? p.value : void 0, F = d.data[d.data.length - 1], A = h !== void 0 ? h : F?.value ?? 0;
433
+ y === 0 && (T = A), P.set(d.label, { value: A, time: c });
407
434
  }
408
- if (U(w), P !== void 0 && h[0]) {
409
- const d = e.timeScale().timeToCoordinate(c), g = h[0].priceToCoordinate(P);
410
- if (d !== null && g !== null) {
411
- const u = F.current;
412
- if (u) {
413
- const v = u.querySelector(
435
+ if (tt(P), T !== void 0 && g[0]) {
436
+ const d = t.timeScale().timeToCoordinate(c), w = g[0].priceToCoordinate(T);
437
+ if (d !== null && w !== null) {
438
+ const p = M.current;
439
+ if (p) {
440
+ const h = p.querySelector(
414
441
  ".LightweightChart"
415
442
  );
416
- if (v) {
417
- const L = v.getBoundingClientRect(), z = u.getBoundingClientRect(), tt = d + (L.left - z.left), et = g + (L.top - z.top);
418
- I({ x: tt, y: et });
443
+ if (h) {
444
+ const F = h.getBoundingClientRect(), A = p.getBoundingClientRect(), ot = d + (F.left - A.left), nt = w + (F.top - A.top);
445
+ $({ x: ot, y: nt });
419
446
  } else
420
- I({ x: d, y: g });
447
+ $({ x: d, y: w });
421
448
  } else
422
- I({ x: d, y: g });
449
+ $({ x: d, y: w });
423
450
  } else
424
- I(null);
451
+ $(null);
425
452
  } else
426
- I(null);
453
+ $(null);
427
454
  };
428
- return e.subscribeCrosshairMove(i), !a && !k && requestAnimationFrame(() => {
429
- const l = Array.from(V.current.values());
430
- if (l[0] && n && t[0]?.data.length > 0) {
431
- const f = e.timeScale().timeToCoordinate(n), y = t[0].data[t[0].data.length - 1].value, h = l[0].priceToCoordinate(y);
432
- f !== null && h !== null && I({ x: f, y: h });
455
+ return t.subscribeCrosshairMove(l), S && t.subscribeClick(l), !a && !N && requestAnimationFrame(() => {
456
+ const s = Array.from(R.current.values());
457
+ if (s[0] && n && e[0]?.data.length > 0) {
458
+ const u = t.timeScale().timeToCoordinate(n), L = e[0].data[e[0].data.length - 1].value, g = s[0].priceToCoordinate(L);
459
+ u !== null && g !== null && $({ x: u, y: g });
433
460
  }
434
461
  }), () => {
435
- e.unsubscribeCrosshairMove(i);
462
+ t.unsubscribeCrosshairMove(l), S && t.unsubscribeClick(l);
436
463
  };
437
- }, [t, k]), E(() => {
438
- const e = N.current;
439
- if (!e || t.length === 0) return;
440
- const a = e.timeScale(), n = Math.max(...t.map((l) => l.data.length)), i = () => {
441
- if (n === 0) return;
442
- const l = a.getVisibleLogicalRange();
464
+ }, [e, N, S]), D(() => {
465
+ const t = V.current;
466
+ if (!t || e.length === 0) return;
467
+ const a = t.timeScale(), n = () => {
468
+ if (!Q.current) return;
469
+ const l = a.getVisibleRange();
443
470
  if (!l) return;
444
- const c = {
445
- from: 0,
446
- to: n - 1
447
- }, f = typeof l.from == "number" ? l.from : 0, y = typeof l.to == "number" ? l.to : n - 1;
448
- if (J.current) {
449
- const C = Math.max(0, Math.floor(f)), d = Math.min(n - 1, Math.ceil(y)), g = [];
450
- for (const u of t)
451
- for (let v = C; v <= d && v < u.data.length; v++)
452
- g.push(u.data[v].value);
453
- g.length > 0 && J.current(g);
454
- }
455
- const h = 0.01;
456
- let w = !1;
457
- const P = { ...l };
458
- f < c.from - h && (P.from = c.from, w = !0), y > c.to + h && (P.to = c.to, w = !0), w && a.setVisibleLogicalRange(P);
471
+ const s = Number(l.from), c = Number(l.to), u = [];
472
+ for (const L of e)
473
+ for (const g of L.data) {
474
+ const P = Number(g.time);
475
+ P >= s && P <= c && u.push(g.value);
476
+ }
477
+ u.length > 0 && Q.current(u);
459
478
  };
460
- return a.subscribeVisibleLogicalRangeChange(i), () => {
479
+ return a.subscribeVisibleLogicalRangeChange(n), () => {
461
480
  a.unsubscribeVisibleLogicalRangeChange(
462
- i
481
+ n
463
482
  );
464
483
  };
465
- }, [t]), E(() => {
466
- const e = N.current, a = Array.from(V.current.values()), n = [];
467
- if (e && a.length > 0 && S) {
468
- const i = Bt(), l = a[0];
469
- for (const c of S) {
470
- const f = new Wt(e, l, c.xCoordinate, {
471
- ...i,
484
+ }, [e]), D(() => {
485
+ const t = V.current, a = Array.from(R.current.values()), n = [];
486
+ if (t && a.length > 0 && x) {
487
+ const l = Wt(), s = a[0];
488
+ for (const c of x) {
489
+ const u = new qt(t, s, c.xCoordinate, {
490
+ ...l,
472
491
  ...c.options || {}
473
492
  });
474
- l.attachPrimitive(f), n.push(f);
493
+ s.attachPrimitive(u), n.push(u);
475
494
  }
476
495
  }
477
496
  return () => {
478
497
  if (a.length > 0) {
479
- const i = a[0];
480
- for (const l of n)
481
- i.detachPrimitive(l);
498
+ const l = a[0];
499
+ for (const s of n)
500
+ l.detachPrimitive(s);
482
501
  }
483
502
  };
484
- }, [S]), E(() => {
485
- const e = N.current;
486
- if (!e || !S?.length) {
503
+ }, [x]), D(() => {
504
+ const t = V.current;
505
+ if (!t || !x?.length) {
487
506
  vt([]);
488
507
  return;
489
508
  }
490
509
  const a = () => {
491
- const l = e.timeScale(), c = S.map((f) => l.timeToCoordinate(f.xCoordinate) ?? null);
510
+ const s = t.timeScale(), c = x.map((u) => s.timeToCoordinate(u.xCoordinate) ?? null);
492
511
  vt(c);
493
512
  };
494
513
  a();
495
- const n = e.timeScale(), i = () => {
514
+ const n = t.timeScale(), l = () => {
496
515
  a();
497
516
  };
498
- return n.subscribeVisibleLogicalRangeChange(i), () => {
499
- n.unsubscribeVisibleLogicalRangeChange(i);
517
+ return n.subscribeVisibleLogicalRangeChange(l), () => {
518
+ n.unsubscribeVisibleLogicalRangeChange(l);
500
519
  };
501
- }, [S]);
502
- const j = t.length === 1, xt = it.useMemo(() => {
503
- if (j && t.length > 0) {
504
- const e = t[0];
505
- if (e.data.length > 0)
506
- return e.data[e.data.length - 1];
520
+ }, [x]);
521
+ const Y = e.length === 1, xt = ct.useMemo(() => {
522
+ if (Y && e.length > 0) {
523
+ const t = e[0];
524
+ if (t.data.length > 0)
525
+ return t.data[t.data.length - 1];
507
526
  }
508
- }, [j, t]);
509
- return /* @__PURE__ */ Y(
527
+ }, [Y, e]);
528
+ return /* @__PURE__ */ H(
510
529
  "div",
511
530
  {
512
- ref: F,
513
- className: ft(
531
+ ref: M,
532
+ className: dt(
514
533
  "relative z-[1] w-full h-full overflow-hidden p-0",
515
- x
534
+ C
516
535
  ),
517
536
  children: [
518
- q != null && q !== !1 && j ? /* @__PURE__ */ p("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ p("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: q }) }) : Pt && j && xt && /* @__PURE__ */ p(
519
- jt,
537
+ Z != null && Z !== !1 && Y ? /* @__PURE__ */ m("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ m("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: Z }) }) : Pt && Y && xt && /* @__PURE__ */ m(
538
+ Xt,
520
539
  {
521
540
  point: xt,
522
- xMeasureUnit: m,
523
- yMeasureUnit: R,
524
- decimals: X
541
+ xMeasureUnit: f,
542
+ yMeasureUnit: v,
543
+ decimals: j
544
+ }
545
+ ),
546
+ W && et && /* @__PURE__ */ m(
547
+ Nt,
548
+ {
549
+ points: W,
550
+ xMeasureUnit: f,
551
+ yMeasureUnit: v,
552
+ series: e,
553
+ position: et,
554
+ containerRef: M,
555
+ decimals: j
525
556
  }
526
557
  ),
527
- ht && pt && /* @__PURE__ */ p(
528
- Ht,
558
+ W && !et && !Y && S && /* @__PURE__ */ m(
559
+ Nt,
529
560
  {
530
- points: ht,
531
- xMeasureUnit: m,
532
- yMeasureUnit: R,
533
- series: t,
534
- position: pt,
535
- containerRef: F,
536
- decimals: X
561
+ points: W,
562
+ xMeasureUnit: f,
563
+ yMeasureUnit: v,
564
+ series: e,
565
+ containerRef: M,
566
+ decimals: j,
567
+ className: "top-2 left-2"
537
568
  }
538
569
  ),
539
- b && /* @__PURE__ */ p(qt, { series: t, onUnselect: A }),
540
- S && S.length > 0 && Ct.length === S.length && /* @__PURE__ */ p(
570
+ b && /* @__PURE__ */ m(Jt, { series: e, onUnselect: I }),
571
+ x && x.length > 0 && Ct.length === x.length && /* @__PURE__ */ m(
541
572
  "div",
542
573
  {
543
574
  className: "absolute inset-0 z-[5] pointer-events-none",
544
575
  "aria-hidden": !0,
545
- children: S.map((e, a) => {
546
- const n = Ct[a], i = e.options ?? {}, l = i.showLabel !== !1;
547
- if (n === null || !l) return null;
548
- const { labelText: c, valueStr: f } = _t(
549
- i,
550
- R,
551
- X
576
+ children: x.map((t, a) => {
577
+ const n = Ct[a], l = t.options ?? {}, s = l.showLabel !== !1;
578
+ if (n === null || !s) return null;
579
+ const { labelText: c, valueStr: u } = Zt(
580
+ l,
581
+ v,
582
+ j
552
583
  );
553
- if (!(c || f)) return null;
554
- const h = i.labelBackgroundColor ?? i.color ?? "hsl(var(--background))", w = i.labelTextColor ?? "hsl(var(--foreground))", P = `${String(e.xCoordinate)}-${c}`;
555
- return /* @__PURE__ */ Y(
584
+ if (!(c || u)) return null;
585
+ const g = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", P = l.labelTextColor ?? "hsl(var(--foreground))", T = `${String(t.xCoordinate)}-${c}`;
586
+ return /* @__PURE__ */ H(
556
587
  "div",
557
588
  {
558
589
  className: "absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
559
590
  style: {
560
591
  left: n,
561
592
  transform: "translateX(-50%)",
562
- backgroundColor: h,
563
- color: w
593
+ backgroundColor: g,
594
+ color: P
564
595
  },
565
596
  children: [
566
- c && /* @__PURE__ */ p("span", { className: "block", children: c }),
567
- f && /* @__PURE__ */ p("span", { className: ft("block", c && "mt-0.5"), children: f })
597
+ c && /* @__PURE__ */ m("span", { className: "block", children: c }),
598
+ u && /* @__PURE__ */ m("span", { className: dt("block", c && "mt-0.5"), children: u })
568
599
  ]
569
600
  },
570
- P
601
+ T
571
602
  );
572
603
  })
573
604
  }
574
605
  ),
575
- /* @__PURE__ */ p(
606
+ /* @__PURE__ */ m(
576
607
  "div",
577
608
  {
578
- ref: Q,
609
+ ref: U,
579
610
  className: "LightweightChart w-full h-full overflow-hidden"
580
611
  }
581
612
  )
@@ -583,41 +614,41 @@ function ce({
583
614
  }
584
615
  );
585
616
  }
586
- function qt({
587
- series: t,
588
- onUnselect: x
617
+ function Jt({
618
+ series: e,
619
+ onUnselect: C
589
620
  }) {
590
- return /* @__PURE__ */ p("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: t.map((b, A) => {
591
- const m = Nt(A), R = (b.lineColor ?? b.color) || m.line, B = b.data.length === 0;
592
- return /* @__PURE__ */ Y(
621
+ return /* @__PURE__ */ m("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: e.map((b, I) => {
622
+ const f = Lt(I), v = (b.lineColor ?? b.color) || f.line, O = b.data.length === 0;
623
+ return /* @__PURE__ */ H(
593
624
  "div",
594
625
  {
595
- className: ft(
626
+ className: dt(
596
627
  "flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
597
- B && "opacity-50"
628
+ O && "opacity-50"
598
629
  ),
599
630
  children: [
600
- /* @__PURE__ */ p(
631
+ /* @__PURE__ */ m(
601
632
  "div",
602
633
  {
603
634
  className: "w-3 h-3 rounded-sm",
604
- style: { backgroundColor: R }
635
+ style: { backgroundColor: v }
605
636
  }
606
637
  ),
607
- /* @__PURE__ */ Y("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
638
+ /* @__PURE__ */ H("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
608
639
  b.label,
609
- B && " (no data)"
640
+ O && " (no data)"
610
641
  ] }),
611
- x && /* @__PURE__ */ p(
642
+ C && /* @__PURE__ */ m(
612
643
  "button",
613
644
  {
614
645
  type: "button",
615
- onClick: (S) => {
616
- S.stopPropagation(), x(b.label);
646
+ onClick: (x) => {
647
+ x.stopPropagation(), C(b.label);
617
648
  },
618
649
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
619
650
  "aria-label": `Remove ${b.label}`,
620
- children: /* @__PURE__ */ Y(
651
+ children: /* @__PURE__ */ H(
621
652
  "svg",
622
653
  {
623
654
  xmlns: "http://www.w3.org/2000/svg",
@@ -632,9 +663,9 @@ function qt({
632
663
  className: "text-muted-foreground hover:text-foreground",
633
664
  "aria-hidden": "true",
634
665
  children: [
635
- /* @__PURE__ */ p("title", { children: "Close" }),
636
- /* @__PURE__ */ p("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
637
- /* @__PURE__ */ p("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
666
+ /* @__PURE__ */ m("title", { children: "Close" }),
667
+ /* @__PURE__ */ m("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
668
+ /* @__PURE__ */ m("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
638
669
  ]
639
670
  }
640
671
  )
@@ -647,8 +678,8 @@ function qt({
647
678
  }) });
648
679
  }
649
680
  export {
650
- ut as DEFAULT_SERIES_COLORS,
651
- ce as Graph,
652
- Nt as getSeriesColorPalette,
653
- _t as getVerticalLineTooltipContent
681
+ gt as DEFAULT_SERIES_COLORS,
682
+ ge as Graph,
683
+ Lt as getSeriesColorPalette,
684
+ Zt as getVerticalLineTooltipContent
654
685
  };