@gearbox-protocol/permissionless-ui 1.26.3 → 1.26.5

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