@gearbox-protocol/permissionless-ui 1.25.0 → 1.26.0

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