@gearbox-protocol/permissionless-ui 1.23.0 → 1.23.1

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