@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,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,
17
- b
18
- ) : String(m);
19
- return { labelText: A, valueStr: R };
1
+ import { jsxs as j, jsx as p } from "react/jsx-runtime";
2
+ import { createChart as Gt, CrosshairMode as Ot, AreaSeries as Bt } from "lightweight-charts";
3
+ import * as ct from "react";
4
+ import { useRef as P, useState as ut, useEffect as $ } 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 Vt, generateColorsFromBase as q, hslToHex as jt } from "../../utils/colors.js";
8
+ import { getDefaultOptions as yt, getDefaultSeries as Ht, 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 Lt } from "./graph-tooltip.js";
12
+ import { VertLine as qt } from "./plugins/vertical-line.js";
13
+ function Zt(e, S, C) {
14
+ const A = e.labelText ?? "", f = e.value, w = f === void 0 ? "" : typeof f == "number" ? S === "$" ? `$${ft(f, void 0, C)}` : S === "%" ? `${ft(f, void 0, C)}%` : ft(
15
+ f,
16
+ S !== "none" && S !== "%" && S !== "$" ? S : void 0,
17
+ C
18
+ ) : String(f);
19
+ return { labelText: A, valueStr: w };
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 Nt(e) {
138
+ if (e < gt.length)
139
+ return gt[e];
140
+ const C = (e - gt.length) * Kt % 360, A = jt(C, 70, 50), { topColor: f, bottomColor: w } = q(A);
141
+ return { line: A, top: f, bottom: w };
123
142
  }
124
- function ce({
125
- series: t,
126
- className: x,
127
- showLegend: b = !1,
143
+ function ge({
144
+ series: e,
145
+ className: S,
146
+ showLegend: C = !1,
128
147
  onUnselectSeries: A,
129
- xMeasureUnit: m = "time",
130
- yMeasureUnit: R = "token",
148
+ xMeasureUnit: f = "time",
149
+ yMeasureUnit: w = "token",
131
150
  optionsOverrides: B,
132
- verticalLineOptions: S,
133
- currentValueDecimals: X,
134
- useSharedPriceScale: k = !1,
151
+ verticalLineOptions: R,
152
+ currentValueDecimals: H,
153
+ useSharedPriceScale: T = !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 k = P(null), y = P(/* @__PURE__ */ new Map()), K = P(!1), J = P(/* @__PURE__ */ new Set()), ht = P(0), pt = P(!0), Q = P(
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 = P(null), I = P(null), U = P(null), V = 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, E] = ut(null), [Ct, vt] = ut([]);
174
+ $(() => {
175
+ const t = () => {
176
+ if (k.current && I.current) {
177
+ const i = I.current.clientWidth, l = I.current.clientHeight;
178
+ k.current.resize(i, l), k.current.timeScale().fitContent();
160
179
  }
161
- }, a = F.current, n = a ? new ResizeObserver(e) : null;
180
+ }, a = I.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
+ }, []), $(() => {
185
+ if (!U.current || K.current) return;
186
+ const t = yt(), a = Vt(
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: !V,
175
194
  textColor: a
176
195
  },
196
+ ...V && {
197
+ crosshair: {
198
+ ...t.crosshair,
199
+ mode: Ot.Magnet
200
+ }
201
+ },
177
202
  ...B
178
203
  });
179
- return N.current = n, Z.current = !0, () => {
180
- n.remove(), N.current = null, Z.current = !1, V.current.clear();
204
+ return k.current = n, K.current = !0, () => {
205
+ n.remove(), k.current = null, K.current = !1, y.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
+ }, [V, B]), $(() => {
208
+ const t = k.current;
209
+ if (!t || e.length === 0) return;
210
+ const n = e.filter((o) => o.data.length > 0).length <= 1 ? mt : bt, i = f === "time" ? kt(f, z) : kt(f), l = z.map((o) => o.value), {
186
211
  formatter: c,
187
- updateVisibleRange: f,
188
- updateLastValues: y
189
- } = Yt(l, R, {
212
+ tickmarksFormatter: g,
213
+ updateVisibleRange: L,
214
+ updateLastValues: b
215
+ } = _t(l, w, {
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 = b;
219
+ const N = e.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
220
+ b(N);
221
+ const v = yt();
222
+ t.applyOptions({
197
223
  localization: {
198
- ...w.localization || {},
199
- timeFormatter: i ? (
224
+ ...v.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
+ i.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
+ ...v.timeScale || {},
233
+ // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
234
+ tickMarkFormatter: i.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, h = z.some((o) => o.value === 0), m = !d && h, u = e.length > 1 && !T, F = e.length > 1 && !T || V, M = Vt(
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
+ ...v.rightPriceScale || {},
245
+ visible: !F,
246
+ textColor: M,
247
+ ...m && {
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(y.current.keys()), nt = new Set(e.map((o) => o.label));
256
+ for (const o of ot)
257
+ if (!nt.has(o)) {
258
+ const r = y.current.get(o);
259
+ r && (t.removeSeries(r), y.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;
261
+ const Mt = Ht(), rt = [];
262
+ let _ = 0;
263
+ for (let o = 0; o < e.length; o++) {
264
+ const r = e[o], it = Nt(o), X = r.lineColor ?? r.color ?? it.line;
240
265
  let D, G;
241
266
  if (r.lineColor ?? r.color)
242
267
  if (r.topColor && r.bottomColor)
243
268
  D = r.topColor, G = r.bottomColor;
244
269
  else if (r.topColor) {
245
- const s = _(W);
270
+ const s = q(X);
246
271
  D = r.topColor, G = s.bottomColor;
247
272
  } else if (r.bottomColor)
248
- D = _(W).topColor, G = r.bottomColor;
273
+ D = q(X).topColor, G = r.bottomColor;
249
274
  else {
250
- const s = _(W);
275
+ const s = q(X);
251
276
  D = s.topColor, G = s.bottomColor;
252
277
  }
253
278
  else
254
- D = r.topColor || at.top, G = r.bottomColor || at.bottom;
279
+ D = 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 s = y.current.get(r.label);
282
+ s && (t.removeSeries(s), y.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((s) => s.value)) : 0) < 0, Et = r.data.some((s) => s.value === 0), $t = !zt && Et, St = T || !u || _ === 0 ? "right" : `scale-${_}`;
286
+ u && rt.push({
262
287
  priceScaleId: St || "right",
263
- shouldPreventNegativeAxis: zt,
264
- seriesIndex: H
288
+ shouldPreventNegativeAxis: $t,
289
+ seriesIndex: _
265
290
  });
266
- const wt = (k || !u) && n !== void 0 && typeof n == "number", Rt = {
267
- lineColor: W,
291
+ const wt = (T || !u) && n !== void 0 && typeof n == "number", Rt = {
292
+ lineColor: X,
268
293
  topColor: D,
269
294
  bottomColor: G,
270
295
  priceScaleId: St,
271
296
  priceFormat: {
272
297
  type: "custom",
298
+ minMove: 0.01,
273
299
  formatter: wt && typeof n == "number" ? (s) => c(
274
300
  s < n ? n : s
275
- ) : c
301
+ ) : c,
302
+ tickmarksFormatter: g
276
303
  },
277
304
  autoscaleInfoProvider: (s) => {
278
305
  if (!wt) return s();
279
- const lt = s();
280
- if (lt?.priceRange) {
281
- const Et = n;
282
- lt.priceRange.minValue = Et;
306
+ const st = s();
307
+ if (st?.priceRange) {
308
+ const Dt = n;
309
+ st.priceRange.minValue = Dt;
283
310
  }
284
- return lt;
311
+ return st;
285
312
  }
286
313
  };
287
- let O = V.current.get(r.label);
314
+ let O = y.current.get(r.label);
288
315
  O ? (O.applyOptions(Rt), O.setData(
289
316
  r.data.map((s) => ({
290
317
  ...s,
291
318
  time: s.time
292
319
  }))
293
- )) : (O = e.addAreaSeries({
294
- ...et,
320
+ )) : (O = t.addSeries(Bt, {
321
+ ...Mt,
295
322
  ...Rt
296
323
  }), O.setData(
297
324
  r.data.map((s) => ({
298
325
  ...s,
299
326
  time: s.time
300
327
  }))
301
- ), V.current.set(r.label, O)), H++;
328
+ ), y.current.set(r.label, O)), _++;
302
329
  }
303
- if (u && ot.length > 0)
304
- for (const o of ot)
330
+ if (u && 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: M
323
350
  });
324
351
  } catch (r) {
325
352
  console.warn(
@@ -329,15 +356,15 @@ function ce({
329
356
  }
330
357
  else if (!u)
331
358
  try {
332
- const o = e.priceScale("right");
359
+ const o = t.priceScale("right");
333
360
  o && o.applyOptions({
334
- visible: !$,
361
+ visible: !V,
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 || m ? 0 : 0.1,
367
+ ...m && {
341
368
  top: 0.3
342
369
  }
343
370
  },
@@ -345,133 +372,133 @@ function ce({
345
372
  borderVisible: !0,
346
373
  borderColor: "rgba(224, 227, 235, 0.1)",
347
374
  entireTextOnly: !1,
348
- textColor: L
375
+ textColor: M
349
376
  });
350
377
  } catch {
351
378
  }
352
- n !== void 0 && (k || !u) && e.applyOptions({
379
+ n !== void 0 && !V && (T || !u) && 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)), At = at.size !== J.current.size || [...at].some((o) => !J.current.has(o)), It = z.length !== ht.current;
385
+ (pt.current || At || It || V) && (t.timeScale().fitContent(), pt.current = !1), J.current = at, ht.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
+ w,
395
+ V,
396
+ T,
397
+ mt,
398
+ bt
399
+ ]), $(() => {
400
+ const t = k.current;
401
+ if (!t || e.length === 0) return;
402
+ const a = e.length === 1;
376
403
  let n;
377
- for (const l of t)
404
+ for (const l of e)
378
405
  if (l.data.length > 0) {
379
406
  n = l.data[l.data.length - 1].time;
380
407
  break;
381
408
  }
382
409
  if (!n) return;
383
410
  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 });
411
+ const { time: c = n, seriesData: g, point: L } = l || {}, b = Array.from(y.current.values());
412
+ if (!L || !c) {
413
+ const x = /* @__PURE__ */ new Map();
414
+ for (const d of e)
415
+ d.data.length > 0 && x.set(d.label, d.data[d.data.length - 1]);
416
+ if (tt(x.size > 0 ? x : void 0), a || T)
417
+ E(null);
418
+ else if (b[0] && n) {
419
+ const h = t.timeScale().timeToCoordinate(n), m = e[0];
420
+ if (m.data.length > 0) {
421
+ const u = m.data[m.data.length - 1].value, F = b[0].priceToCoordinate(u);
422
+ h !== null && F !== null && E({ x: h, 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 N = /* @__PURE__ */ new Map();
428
+ let v;
429
+ for (let x = 0; x < e.length; x++) {
430
+ const d = e[x], h = b[x];
431
+ if (!h) continue;
432
+ const m = g?.get(h), u = m && "value" in m ? m.value : void 0, F = d.data[d.data.length - 1], M = u !== void 0 ? u : F?.value ?? 0;
433
+ x === 0 && (v = M), N.set(d.label, { value: M, 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(N), v !== void 0 && b[0]) {
436
+ const d = t.timeScale().timeToCoordinate(c), h = b[0].priceToCoordinate(v);
437
+ if (d !== null && h !== null) {
438
+ const m = I.current;
439
+ if (m) {
440
+ const u = m.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 (u) {
444
+ const F = u.getBoundingClientRect(), M = m.getBoundingClientRect(), ot = d + (F.left - M.left), nt = h + (F.top - M.top);
445
+ E({ x: ot, y: nt });
419
446
  } else
420
- I({ x: d, y: g });
447
+ E({ x: d, y: h });
421
448
  } else
422
- I({ x: d, y: g });
449
+ E({ x: d, y: h });
423
450
  } else
424
- I(null);
451
+ E(null);
425
452
  } else
426
- I(null);
453
+ E(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(i), V && t.subscribeClick(i), !a && !T && requestAnimationFrame(() => {
456
+ const l = Array.from(y.current.values());
457
+ if (l[0] && n && e[0]?.data.length > 0) {
458
+ const g = t.timeScale().timeToCoordinate(n), L = e[0].data[e[0].data.length - 1].value, b = l[0].priceToCoordinate(L);
459
+ g !== null && b !== null && E({ x: g, y: b });
433
460
  }
434
461
  }), () => {
435
- e.unsubscribeCrosshairMove(i);
462
+ t.unsubscribeCrosshairMove(i), V && t.unsubscribeClick(i);
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 = () => {
464
+ }, [e, T, V]), $(() => {
465
+ const t = k.current;
466
+ if (!t || e.length === 0) return;
467
+ const a = t.timeScale(), n = Math.max(...e.map((l) => l.data.length)), i = () => {
441
468
  if (n === 0) return;
442
469
  const l = a.getVisibleLogicalRange();
443
470
  if (!l) return;
444
471
  const c = {
445
472
  from: 0,
446
473
  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);
474
+ }, g = typeof l.from == "number" ? l.from : 0, L = typeof l.to == "number" ? l.to : n - 1;
475
+ if (Q.current) {
476
+ const x = Math.max(0, Math.floor(g)), d = Math.min(n - 1, Math.ceil(L)), h = [];
477
+ for (const m of e)
478
+ for (let u = x; u <= d && u < m.data.length; u++)
479
+ h.push(m.data[u].value);
480
+ h.length > 0 && Q.current(h);
454
481
  }
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);
482
+ const b = 0.01;
483
+ let N = !1;
484
+ const v = { ...l };
485
+ g < c.from - b && (v.from = c.from, N = !0), L > c.to + b && (v.to = c.to, N = !0), N && a.setVisibleLogicalRange(v);
459
486
  };
460
487
  return a.subscribeVisibleLogicalRangeChange(i), () => {
461
488
  a.unsubscribeVisibleLogicalRangeChange(
462
489
  i
463
490
  );
464
491
  };
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, {
492
+ }, [e]), $(() => {
493
+ const t = k.current, a = Array.from(y.current.values()), n = [];
494
+ if (t && a.length > 0 && R) {
495
+ const i = Wt(), l = a[0];
496
+ for (const c of R) {
497
+ const g = new qt(t, l, c.xCoordinate, {
471
498
  ...i,
472
499
  ...c.options || {}
473
500
  });
474
- l.attachPrimitive(f), n.push(f);
501
+ l.attachPrimitive(g), n.push(g);
475
502
  }
476
503
  }
477
504
  return () => {
@@ -481,93 +508,105 @@ function ce({
481
508
  i.detachPrimitive(l);
482
509
  }
483
510
  };
484
- }, [S]), E(() => {
485
- const e = N.current;
486
- if (!e || !S?.length) {
511
+ }, [R]), $(() => {
512
+ const t = k.current;
513
+ if (!t || !R?.length) {
487
514
  vt([]);
488
515
  return;
489
516
  }
490
517
  const a = () => {
491
- const l = e.timeScale(), c = S.map((f) => l.timeToCoordinate(f.xCoordinate) ?? null);
518
+ const l = t.timeScale(), c = R.map((g) => l.timeToCoordinate(g.xCoordinate) ?? null);
492
519
  vt(c);
493
520
  };
494
521
  a();
495
- const n = e.timeScale(), i = () => {
522
+ const n = t.timeScale(), i = () => {
496
523
  a();
497
524
  };
498
525
  return n.subscribeVisibleLogicalRangeChange(i), () => {
499
526
  n.unsubscribeVisibleLogicalRangeChange(i);
500
527
  };
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];
528
+ }, [R]);
529
+ const Y = e.length === 1, xt = ct.useMemo(() => {
530
+ if (Y && e.length > 0) {
531
+ const t = e[0];
532
+ if (t.data.length > 0)
533
+ return t.data[t.data.length - 1];
507
534
  }
508
- }, [j, t]);
509
- return /* @__PURE__ */ Y(
535
+ }, [Y, e]);
536
+ return /* @__PURE__ */ j(
510
537
  "div",
511
538
  {
512
- ref: F,
513
- className: ft(
539
+ ref: I,
540
+ className: dt(
514
541
  "relative z-[1] w-full h-full overflow-hidden p-0",
515
- x
542
+ S
516
543
  ),
517
544
  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,
545
+ Z != null && Z !== !1 && Y ? /* @__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: Z }) }) : Pt && Y && xt && /* @__PURE__ */ p(
546
+ Xt,
520
547
  {
521
548
  point: xt,
522
- xMeasureUnit: m,
523
- yMeasureUnit: R,
524
- decimals: X
549
+ xMeasureUnit: f,
550
+ yMeasureUnit: w,
551
+ decimals: H
552
+ }
553
+ ),
554
+ W && et && /* @__PURE__ */ p(
555
+ Lt,
556
+ {
557
+ points: W,
558
+ xMeasureUnit: f,
559
+ yMeasureUnit: w,
560
+ series: e,
561
+ position: et,
562
+ containerRef: I,
563
+ decimals: H
525
564
  }
526
565
  ),
527
- ht && pt && /* @__PURE__ */ p(
528
- Ht,
566
+ W && !et && !Y && V && /* @__PURE__ */ p(
567
+ Lt,
529
568
  {
530
- points: ht,
531
- xMeasureUnit: m,
532
- yMeasureUnit: R,
533
- series: t,
534
- position: pt,
535
- containerRef: F,
536
- decimals: X
569
+ points: W,
570
+ xMeasureUnit: f,
571
+ yMeasureUnit: w,
572
+ series: e,
573
+ containerRef: I,
574
+ decimals: H,
575
+ className: "top-2 left-2"
537
576
  }
538
577
  ),
539
- b && /* @__PURE__ */ p(qt, { series: t, onUnselect: A }),
540
- S && S.length > 0 && Ct.length === S.length && /* @__PURE__ */ p(
578
+ C && /* @__PURE__ */ p(Jt, { series: e, onUnselect: A }),
579
+ R && R.length > 0 && Ct.length === R.length && /* @__PURE__ */ p(
541
580
  "div",
542
581
  {
543
582
  className: "absolute inset-0 z-[5] pointer-events-none",
544
583
  "aria-hidden": !0,
545
- children: S.map((e, a) => {
546
- const n = Ct[a], i = e.options ?? {}, l = i.showLabel !== !1;
584
+ children: R.map((t, a) => {
585
+ const n = Ct[a], i = t.options ?? {}, l = i.showLabel !== !1;
547
586
  if (n === null || !l) return null;
548
- const { labelText: c, valueStr: f } = _t(
587
+ const { labelText: c, valueStr: g } = Zt(
549
588
  i,
550
- R,
551
- X
589
+ w,
590
+ H
552
591
  );
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(
592
+ if (!(c || g)) return null;
593
+ const b = i.labelBackgroundColor ?? i.color ?? "hsl(var(--background))", N = i.labelTextColor ?? "hsl(var(--foreground))", v = `${String(t.xCoordinate)}-${c}`;
594
+ return /* @__PURE__ */ j(
556
595
  "div",
557
596
  {
558
597
  className: "absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
559
598
  style: {
560
599
  left: n,
561
600
  transform: "translateX(-50%)",
562
- backgroundColor: h,
563
- color: w
601
+ backgroundColor: b,
602
+ color: N
564
603
  },
565
604
  children: [
566
605
  c && /* @__PURE__ */ p("span", { className: "block", children: c }),
567
- f && /* @__PURE__ */ p("span", { className: ft("block", c && "mt-0.5"), children: f })
606
+ g && /* @__PURE__ */ p("span", { className: dt("block", c && "mt-0.5"), children: g })
568
607
  ]
569
608
  },
570
- P
609
+ v
571
610
  );
572
611
  })
573
612
  }
@@ -575,7 +614,7 @@ function ce({
575
614
  /* @__PURE__ */ p(
576
615
  "div",
577
616
  {
578
- ref: Q,
617
+ ref: U,
579
618
  className: "LightweightChart w-full h-full overflow-hidden"
580
619
  }
581
620
  )
@@ -583,16 +622,16 @@ function ce({
583
622
  }
584
623
  );
585
624
  }
586
- function qt({
587
- series: t,
588
- onUnselect: x
625
+ function Jt({
626
+ series: e,
627
+ onUnselect: S
589
628
  }) {
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(
629
+ return /* @__PURE__ */ p("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: e.map((C, A) => {
630
+ const f = Nt(A), w = (C.lineColor ?? C.color) || f.line, B = C.data.length === 0;
631
+ return /* @__PURE__ */ j(
593
632
  "div",
594
633
  {
595
- className: ft(
634
+ className: dt(
596
635
  "flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
597
636
  B && "opacity-50"
598
637
  ),
@@ -601,23 +640,23 @@ function qt({
601
640
  "div",
602
641
  {
603
642
  className: "w-3 h-3 rounded-sm",
604
- style: { backgroundColor: R }
643
+ style: { backgroundColor: w }
605
644
  }
606
645
  ),
607
- /* @__PURE__ */ Y("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
608
- b.label,
646
+ /* @__PURE__ */ j("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
647
+ C.label,
609
648
  B && " (no data)"
610
649
  ] }),
611
- x && /* @__PURE__ */ p(
650
+ S && /* @__PURE__ */ p(
612
651
  "button",
613
652
  {
614
653
  type: "button",
615
- onClick: (S) => {
616
- S.stopPropagation(), x(b.label);
654
+ onClick: (R) => {
655
+ R.stopPropagation(), S(C.label);
617
656
  },
618
657
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
619
- "aria-label": `Remove ${b.label}`,
620
- children: /* @__PURE__ */ Y(
658
+ "aria-label": `Remove ${C.label}`,
659
+ children: /* @__PURE__ */ j(
621
660
  "svg",
622
661
  {
623
662
  xmlns: "http://www.w3.org/2000/svg",
@@ -642,13 +681,13 @@ function qt({
642
681
  )
643
682
  ]
644
683
  },
645
- b.label
684
+ C.label
646
685
  );
647
686
  }) });
648
687
  }
649
688
  export {
650
- ut as DEFAULT_SERIES_COLORS,
651
- ce as Graph,
689
+ gt as DEFAULT_SERIES_COLORS,
690
+ ge as Graph,
652
691
  Nt as getSeriesColorPalette,
653
- _t as getVerticalLineTooltipContent
692
+ Zt as getVerticalLineTooltipContent
654
693
  };