@gearbox-protocol/ui-kit 3.14.0-next.31 → 3.14.0-next.33

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,30 +1,79 @@
1
- import { jsxs as K, jsx as p } from "react/jsx-runtime";
2
- import { createChart as We, CrosshairMode as Ye, AreaSeries as Ge } from "lightweight-charts";
3
- import * as fe from "react";
4
- import { useRef as L, useState as de, useEffect as $ } from "react";
5
- import { useIsMobile as Be } from "../../hooks/use-media-query.js";
6
- import { cn as he } from "../../utils/cn.js";
7
- import { resolveCSSColor as Me, generateColorsFromBase as ee, hslToHex as je } from "../../utils/colors.js";
8
- import { getDefaultOptions as Pe, getDefaultSeries as He, getDefaultVerticalLine as _e } from "./default-config.js";
9
- import { getXFormatters as Te, createAdaptiveYAxisFormatter as Xe, formatExactValue as ge } from "./formatters.js";
10
- import { GraphCurrentValue as qe } from "./graph-current-value.js";
11
- import { GraphTooltip as Ke } from "./graph-tooltip.js";
12
- import { VertLine as Je } from "./plugins/vertical-line.js";
13
- function Qe(t, v, u) {
14
- const D = t.labelText ?? "", g = t.value, N = g === void 0 ? "" : typeof g == "number" ? v === "$" ? `$${ge(g, void 0, u)}` : v === "%" ? `${ge(g, void 0, u)}%` : ge(
15
- g,
16
- v !== "none" && v !== "%" && v !== "$" ? v : void 0,
17
- u
18
- ) : String(g);
19
- return { labelText: D, valueStr: N };
1
+ import { jsxs as U, jsx as S } from "react/jsx-runtime";
2
+ import { createChart as He, CrosshairMode as Xe, AreaSeries as qe, LineStyle as Ze } from "lightweight-charts";
3
+ import * as ge from "react";
4
+ import { useRef as I, useState as be, useEffect as L } from "react";
5
+ import { useIsMobile as Ke } from "../../hooks/use-media-query.js";
6
+ import { cn as Ce } from "../../utils/cn.js";
7
+ import { resolveCSSColor as O, generateColorsFromBase as ne, hslToHex as Je } from "../../utils/colors.js";
8
+ import { getDefaultOptions as De, getDefaultSeries as Qe, getDefaultVerticalLine as Oe } from "./default-config.js";
9
+ import { getXFormatters as Be, createAdaptiveYAxisFormatter as Ue, formatExactValue as pe } from "./formatters.js";
10
+ import { GraphCurrentValue as et } from "./graph-current-value.js";
11
+ import { GraphTooltip as tt } from "./graph-tooltip.js";
12
+ import { VertLine as ot } from "./plugins/vertical-line.js";
13
+ class rt {
14
+ _yTop;
15
+ _yBottom;
16
+ _color;
17
+ constructor(c, s, b) {
18
+ this._yTop = c, this._yBottom = s, this._color = b;
19
+ }
20
+ draw(c) {
21
+ c.useBitmapCoordinateSpace((s) => {
22
+ const b = s.context, h = s.verticalPixelRatio, y = this._yTop === null ? 0 : this._yTop * h, z = this._yBottom === null ? s.bitmapSize.height : this._yBottom * h, p = Math.min(y, z), R = Math.max(y, z);
23
+ b.fillStyle = this._color, b.fillRect(0, p, s.bitmapSize.width, R - p);
24
+ });
25
+ }
26
+ }
27
+ class nt {
28
+ _source;
29
+ _yTop = null;
30
+ _yBottom = null;
31
+ constructor(c) {
32
+ this._source = c;
33
+ }
34
+ update() {
35
+ const c = this._source.series;
36
+ this._yTop = this._source.priceTop === void 0 ? null : c.priceToCoordinate(this._source.priceTop), this._yBottom = this._source.priceBottom === void 0 ? null : c.priceToCoordinate(this._source.priceBottom);
37
+ }
38
+ /** Draw beneath the series line/area so the data stays readable. */
39
+ zOrder() {
40
+ return "bottom";
41
+ }
42
+ renderer() {
43
+ return new rt(this._yTop, this._yBottom, this._source.color);
44
+ }
20
45
  }
21
- function Ze(t, v) {
22
- for (let u = t.length - 1; u >= 0; u--)
23
- if (Number(t[u].time) <= v)
24
- return t[u].value;
46
+ class at {
47
+ series;
48
+ priceTop;
49
+ priceBottom;
50
+ color;
51
+ _paneViews;
52
+ constructor(c, s, b, h) {
53
+ this.series = c, this.priceTop = s, this.priceBottom = b, this.color = h, this._paneViews = [new nt(this)];
54
+ }
55
+ updateAllViews() {
56
+ for (const c of this._paneViews) c.update();
57
+ }
58
+ paneViews() {
59
+ return this._paneViews;
60
+ }
61
+ }
62
+ function lt(t, c, s) {
63
+ const b = t.labelText ?? "", h = t.value, y = h === void 0 ? "" : typeof h == "number" ? c === "$" ? `$${pe(h, void 0, s)}` : c === "%" ? `${pe(h, void 0, s)}%` : pe(
64
+ h,
65
+ c !== "none" && c !== "%" && c !== "$" ? c : void 0,
66
+ s
67
+ ) : String(h);
68
+ return { labelText: b, valueStr: y };
69
+ }
70
+ function it(t, c) {
71
+ for (let s = t.length - 1; s >= 0; s--)
72
+ if (Number(t[s].time) <= c)
73
+ return t[s].value;
25
74
  return 0;
26
75
  }
27
- const me = [
76
+ const ve = [
28
77
  // 0 green (emerald)
29
78
  {
30
79
  line: "#02c39a",
@@ -139,65 +188,67 @@ const me = [
139
188
  top: "rgba(71, 85, 105, 0.56)",
140
189
  bottom: "rgba(71, 85, 105, 0.04)"
141
190
  }
142
- ], Ue = 137.5;
143
- function Le(t) {
144
- if (t < me.length)
145
- return me[t];
146
- const u = (t - me.length) * Ue % 360, D = je(u, 70, 50), { topColor: g, bottomColor: N } = ee(D);
147
- return { line: D, top: g, bottom: N };
191
+ ], st = 137.5;
192
+ function Fe(t) {
193
+ if (t < ve.length)
194
+ return ve[t];
195
+ const s = (t - ve.length) * st % 360, b = Je(s, 70, 50), { topColor: h, bottomColor: y } = ne(b);
196
+ return { line: b, top: h, bottom: y };
148
197
  }
149
- function ht({
198
+ function Nt({
150
199
  series: t,
151
- className: v,
152
- showLegend: u = !1,
153
- onUnselectSeries: D,
154
- xMeasureUnit: g = "time",
155
- yMeasureUnit: N = "token",
156
- optionsOverrides: _,
157
- verticalLineOptions: x,
158
- currentValueDecimals: te,
159
- useSharedPriceScale: M = !1,
160
- showCurrentValue: De = !0,
161
- graphTitle: oe,
162
- yScaleMin: be,
163
- yScaleMinMultiple: pe,
164
- visibleTimeFrom: E,
165
- disableZoom: J = !1
200
+ className: c,
201
+ showLegend: s = !1,
202
+ onUnselectSeries: b,
203
+ xMeasureUnit: h = "time",
204
+ yMeasureUnit: y = "token",
205
+ optionsOverrides: z,
206
+ verticalLineOptions: p,
207
+ priceLineOptions: R,
208
+ zoneOptions: W,
209
+ currentValueDecimals: ae,
210
+ useSharedPriceScale: D = !1,
211
+ showCurrentValue: Ae = !0,
212
+ graphTitle: le,
213
+ yScaleMin: xe,
214
+ yScaleMinMultiple: Se,
215
+ visibleTimeFrom: j,
216
+ disableZoom: ee = !1
166
217
  }) {
167
- const R = L(null), w = L(/* @__PURE__ */ new Map()), re = L(!1), ve = L(!0), ne = L(
218
+ const T = I(null), v = I(/* @__PURE__ */ new Map()), ie = I(!1), ye = I(!0), se = I(
168
219
  null
169
- ), Ie = L(null), O = L(null), ae = L(null), Q = L(null), V = Be(), I = fe.useMemo(() => t.flatMap((e) => e.data), [t]), ze = fe.useMemo(() => {
220
+ ), Ie = I(null), H = I(null), ce = I(null), te = I(null), P = Ke(), $ = ge.useMemo(() => t.flatMap((e) => e.data), [t]), ze = ge.useMemo(() => {
170
221
  if (t.length > 0) {
171
222
  const e = t[t.length - 1];
172
223
  if (e.data.length > 0)
173
224
  return e.data[e.data.length - 1];
174
225
  }
175
- }, [t]), [Ce, le] = de(() => {
226
+ }, [t]), [we, ue] = be(() => {
176
227
  if (!ze) return;
177
228
  const e = /* @__PURE__ */ new Map();
178
- for (const a of t)
179
- a.data.length > 0 && e.set(a.label, a.data[a.data.length - 1]);
229
+ for (const l of t)
230
+ l.data.length > 0 && e.set(l.label, l.data[l.data.length - 1]);
180
231
  return e;
181
- }), [xe, z] = de(null), [Se, Ne] = de([]);
182
- $(() => {
232
+ }), [Ne, E] = be(null), [Ve, Re] = be([]);
233
+ L(() => {
183
234
  const e = () => {
184
235
  try {
185
- if (R.current && O.current) {
186
- const l = O.current.clientWidth, i = O.current.clientHeight;
187
- R.current.resize(l, i);
236
+ if (T.current && H.current) {
237
+ const r = H.current.clientWidth, i = H.current.clientHeight;
238
+ T.current.resize(r, i);
188
239
  }
189
240
  } catch {
190
241
  }
191
- }, a = O.current, r = a ? new ResizeObserver(e) : null;
192
- return Q.current = r, a && r?.observe(a), () => {
193
- a && r?.unobserve(a), r?.disconnect(), Q.current = null;
242
+ }, l = H.current, n = l ? new ResizeObserver(e) : null;
243
+ return te.current = n, l && n?.observe(l), () => {
244
+ l && n?.unobserve(l), n?.disconnect(), te.current = null;
194
245
  };
195
- }, []), $(() => {
196
- if (!ae.current || re.current) return;
197
- const e = Pe(), a = Me(
246
+ }, []), L(() => {
247
+ if (!ce.current || ie.current) return;
248
+ const e = De(), l = O(
198
249
  "hsl(var(--foreground))",
199
250
  "rgb(0, 0, 0)"
200
- ), r = J ? {
251
+ ), n = ee ? {
201
252
  handleScale: {
202
253
  mouseWheel: !1,
203
254
  pinch: !1,
@@ -210,29 +261,29 @@ function ht({
210
261
  horzTouchDrag: !1,
211
262
  vertTouchDrag: !1
212
263
  }
213
- } : {}, l = We(ae.current, {
264
+ } : {}, r = He(ce.current, {
214
265
  ...e,
215
266
  rightPriceScale: {
216
267
  ...e.rightPriceScale || {},
217
- visible: !V,
218
- textColor: a
268
+ visible: !P,
269
+ textColor: l
219
270
  },
220
- ...V && {
271
+ ...P && {
221
272
  crosshair: {
222
273
  ...e.crosshair,
223
- mode: Ye.Magnet
274
+ mode: Xe.Magnet
224
275
  }
225
276
  },
226
- ...r,
227
- ..._
277
+ ...n,
278
+ ...z
228
279
  });
229
- return R.current = l, re.current = !0, () => {
230
- Q.current?.disconnect(), Q.current = null, l.remove(), R.current = null, re.current = !1, w.current.clear();
280
+ return T.current = r, ie.current = !0, () => {
281
+ te.current?.disconnect(), te.current = null, r.remove(), T.current = null, ie.current = !1, v.current.clear();
231
282
  };
232
- }, [V, _, J]), $(() => {
233
- const e = R.current;
283
+ }, [P, z, ee]), L(() => {
284
+ const e = T.current;
234
285
  e && e.applyOptions(
235
- J ? {
286
+ ee ? {
236
287
  handleScale: {
237
288
  mouseWheel: !1,
238
289
  pinch: !1,
@@ -260,47 +311,47 @@ function ht({
260
311
  }
261
312
  }
262
313
  );
263
- }, [J]), $(() => {
264
- const e = R.current;
314
+ }, [ee]), L(() => {
315
+ const e = T.current;
265
316
  if (!e || t.length === 0) return;
266
- const r = t.filter((o) => o.data.length > 0).length <= 1 ? be : pe, l = g === "time" ? Te(g, I) : Te(g), i = I.map((o) => o.value), {
267
- formatter: c,
268
- tickmarksFormatter: f,
269
- updateVisibleRange: P,
270
- updateLastValues: m
271
- } = Xe(i, N, {
272
- yScaleMin: r
317
+ const n = t.filter((o) => o.data.length > 0).length <= 1 ? xe : Se, r = h === "time" ? Be(h, $) : Be(h), i = $.map((o) => o.value), {
318
+ formatter: u,
319
+ tickmarksFormatter: d,
320
+ updateVisibleRange: B,
321
+ updateLastValues: g
322
+ } = Ue(i, y, {
323
+ yScaleMin: n
273
324
  });
274
- ne.current = P, Ie.current = m;
275
- const T = t.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
276
- m(T);
277
- const k = Pe();
325
+ se.current = B, Ie.current = g;
326
+ const F = t.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
327
+ g(F);
328
+ const M = De();
278
329
  e.applyOptions({
279
330
  localization: {
280
- ...k.localization || {},
331
+ ...M.localization || {},
281
332
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
282
333
  timeFormatter: (o) => (
283
334
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
284
- l.timeFormatter(parseFloat(o), void 0)
335
+ r.timeFormatter(parseFloat(o), void 0)
285
336
  )
286
337
  },
287
338
  timeScale: {
288
- ...k.timeScale || {},
339
+ ...M.timeScale || {},
289
340
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
290
- tickMarkFormatter: l.tickMarkFormatter,
341
+ tickMarkFormatter: r.tickMarkFormatter,
291
342
  minBarSpacing: 0
292
343
  }
293
344
  });
294
- const d = (I.length > 0 ? Math.min(...I.map((o) => o.value)) : 0) < 0, S = I.some((o) => o.value === 0), h = !d && S, C = t.length > 1 && !M, b = t.length > 1 && !M || V, A = Me(
345
+ const m = ($.length > 0 ? Math.min(...$.map((o) => o.value)) : 0) < 0, N = $.some((o) => o.value === 0), C = !m && N, w = t.length > 1 && !D, x = t.length > 1 && !D || P, Y = O(
295
346
  "hsl(var(--foreground))",
296
347
  "rgb(0, 0, 0)"
297
348
  );
298
349
  e.applyOptions({
299
350
  rightPriceScale: {
300
- ...k.rightPriceScale || {},
301
- visible: !b,
302
- textColor: A,
303
- ...h && {
351
+ ...M.rightPriceScale || {},
352
+ visible: !x,
353
+ textColor: Y,
354
+ ...C && {
304
355
  scaleMargins: {
305
356
  top: 0.3,
306
357
  bottom: 0
@@ -308,86 +359,102 @@ function ht({
308
359
  }
309
360
  }
310
361
  });
311
- const X = new Set(w.current.keys()), se = new Set(t.map((o) => o.label));
312
- for (const o of X)
313
- if (!se.has(o)) {
314
- const n = w.current.get(o);
315
- n && (e.removeSeries(n), w.current.delete(o));
362
+ const J = new Set(v.current.keys()), fe = new Set(t.map((o) => o.label));
363
+ for (const o of J)
364
+ if (!fe.has(o)) {
365
+ const a = v.current.get(o);
366
+ a && (e.removeSeries(a), v.current.delete(o));
367
+ }
368
+ const We = Qe(), he = [];
369
+ let re = 0;
370
+ const Pe = t.find((o) => o.data.length > 0), Q = /* @__PURE__ */ new Map();
371
+ if (R && R.length > 0)
372
+ for (const o of R) {
373
+ if (!Number.isFinite(o.price)) continue;
374
+ const a = o.seriesLabel ?? Pe?.label;
375
+ if (!a) continue;
376
+ const V = Q.get(a) ?? [];
377
+ V.push(o.price), Q.set(a, V);
378
+ }
379
+ if (W && W.length > 0)
380
+ for (const o of W) {
381
+ const a = o.seriesLabel ?? Pe?.label;
382
+ if (!a) continue;
383
+ const V = Q.get(a) ?? [];
384
+ Number.isFinite(o.priceTop) && V.push(o.priceTop), Number.isFinite(o.priceBottom) && V.push(o.priceBottom), Q.set(a, V);
316
385
  }
317
- const Ae = He(), ie = [];
318
- let U = 0;
319
386
  for (let o = 0; o < t.length; o++) {
320
- const n = t[o], q = Le(o), W = n.lineColor ?? n.color ?? q.line;
321
- let F, Y;
322
- if (n.lineColor ?? n.color)
323
- if (n.topColor && n.bottomColor)
324
- F = n.topColor, Y = n.bottomColor;
325
- else if (n.topColor) {
326
- const s = ee(W);
327
- F = n.topColor, Y = s.bottomColor;
328
- } else if (n.bottomColor)
329
- F = ee(W).topColor, Y = n.bottomColor;
387
+ const a = t[o], V = Fe(o), X = a.lineColor ?? a.color ?? V.line;
388
+ let G, q;
389
+ if (a.lineColor ?? a.color)
390
+ if (a.topColor && a.bottomColor)
391
+ G = a.topColor, q = a.bottomColor;
392
+ else if (a.topColor) {
393
+ const f = ne(X);
394
+ G = a.topColor, q = f.bottomColor;
395
+ } else if (a.bottomColor)
396
+ G = ne(X).topColor, q = a.bottomColor;
330
397
  else {
331
- const s = ee(W);
332
- F = s.topColor, Y = s.bottomColor;
398
+ const f = ne(X);
399
+ G = f.topColor, q = f.bottomColor;
333
400
  }
334
401
  else
335
- F = n.topColor || q.top, Y = n.bottomColor || q.bottom;
336
- if (n.data.length === 0) {
337
- const s = w.current.get(n.label);
338
- s && (e.removeSeries(s), w.current.delete(n.label));
402
+ G = a.topColor || V.top, q = a.bottomColor || V.bottom;
403
+ if (a.data.length === 0) {
404
+ const f = v.current.get(a.label);
405
+ f && (e.removeSeries(f), v.current.delete(a.label));
339
406
  continue;
340
407
  }
341
- const Fe = (n.data.length > 0 ? Math.min(...n.data.map((s) => s.value)) : 0) < 0, $e = n.data.some((s) => s.value === 0), Ee = !Fe && $e, Re = M || !C || U === 0 ? "right" : `scale-${U}`;
342
- C && ie.push({
343
- priceScaleId: Re || "right",
344
- shouldPreventNegativeAxis: Ee,
345
- seriesIndex: U
408
+ const $e = (a.data.length > 0 ? Math.min(...a.data.map((f) => f.value)) : 0) < 0, Ee = a.data.some((f) => f.value === 0), Ye = !$e && Ee, Me = D || !w || re === 0 ? "right" : `scale-${re}`;
409
+ w && he.push({
410
+ priceScaleId: Me || "right",
411
+ shouldPreventNegativeAxis: Ye,
412
+ seriesIndex: re
346
413
  });
347
- const Ve = (M || !C) && r !== void 0 && typeof r == "number", ke = {
348
- lineColor: W,
349
- topColor: F,
350
- bottomColor: Y,
351
- priceScaleId: Re,
414
+ const _e = (D || !w) && n !== void 0 && typeof n == "number", Ge = Q.get(a.label) ?? [], ke = {
415
+ lineColor: X,
416
+ topColor: G,
417
+ bottomColor: q,
418
+ priceScaleId: Me,
352
419
  priceFormat: {
353
420
  type: "custom",
354
421
  minMove: 0.01,
355
- formatter: Ve && typeof r == "number" ? (s) => c(
356
- s < r ? r : s
357
- ) : c,
358
- tickmarksFormatter: f
422
+ formatter: _e && typeof n == "number" ? (f) => u(
423
+ f < n ? n : f
424
+ ) : u,
425
+ tickmarksFormatter: d
359
426
  },
360
- autoscaleInfoProvider: (s) => {
361
- if (!Ve) return s();
362
- const j = s();
363
- if (j?.priceRange) {
364
- const H = r;
365
- j.priceRange.minValue = H;
427
+ autoscaleInfoProvider: (f) => {
428
+ const k = f();
429
+ if (k?.priceRange) {
430
+ _e && (k.priceRange.minValue = n);
431
+ for (const A of Ge)
432
+ A < k.priceRange.minValue && (k.priceRange.minValue = A), A > k.priceRange.maxValue && (k.priceRange.maxValue = A);
366
433
  }
367
- return j;
434
+ return k;
368
435
  }
369
436
  };
370
- let G = w.current.get(n.label);
371
- const B = n.data.map((s) => ({
372
- ...s,
373
- time: s.time
437
+ let Z = v.current.get(a.label);
438
+ const K = a.data.map((f) => ({
439
+ ...f,
440
+ time: f.time
374
441
  }));
375
- if (E !== void 0 && B.length > 0 && Number(B[0].time) > E) {
376
- const s = Number(B[0].time), j = s - E, H = 86400, Oe = j > 180 * H ? 7 * H : j > 30 * H ? H : 6 * 3600, ye = [];
377
- for (let ue = E; ue < s; ue += Oe)
378
- ye.push({ time: ue });
379
- B.unshift(...ye);
442
+ if (j !== void 0 && K.length > 0 && Number(K[0].time) > j) {
443
+ const f = Number(K[0].time), k = f - j, A = 86400, je = k > 180 * A ? 7 * A : k > 30 * A ? A : 6 * 3600, Le = [];
444
+ for (let me = j; me < f; me += je)
445
+ Le.push({ time: me });
446
+ K.unshift(...Le);
380
447
  }
381
- G ? (G.applyOptions(ke), G.setData(B)) : (G = e.addSeries(Ge, {
382
- ...Ae,
448
+ Z ? (Z.applyOptions(ke), Z.setData(K)) : (Z = e.addSeries(qe, {
449
+ ...We,
383
450
  ...ke
384
- }), G.setData(B), w.current.set(n.label, G)), U++;
451
+ }), Z.setData(K), v.current.set(a.label, Z)), re++;
385
452
  }
386
- if (C && ie.length > 0)
387
- for (const o of ie)
453
+ if (w && he.length > 0)
454
+ for (const o of he)
388
455
  try {
389
- const n = e.priceScale(o.priceScaleId);
390
- n && n.applyOptions({
456
+ const a = e.priceScale(o.priceScaleId);
457
+ a && a.applyOptions({
391
458
  visible: !1,
392
459
  autoScale: !0,
393
460
  scaleMargins: {
@@ -402,25 +469,25 @@ function ht({
402
469
  borderVisible: !0,
403
470
  borderColor: "rgba(224, 227, 235, 0.1)",
404
471
  entireTextOnly: !1,
405
- textColor: A
472
+ textColor: Y
406
473
  });
407
- } catch (n) {
474
+ } catch (a) {
408
475
  console.warn(
409
476
  `Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,
410
- n
477
+ a
411
478
  );
412
479
  }
413
- else if (!C)
480
+ else if (!w)
414
481
  try {
415
482
  const o = e.priceScale("right");
416
483
  o && o.applyOptions({
417
- visible: !V,
484
+ visible: !P,
418
485
  autoScale: !0,
419
486
  scaleMargins: {
420
487
  top: 0.1,
421
488
  // No bottom margin when yScaleMin is set so the scale doesn't extend below the minimum (avoids negative labels like -10M)
422
- bottom: r !== void 0 || h ? 0 : 0.1,
423
- ...h && {
489
+ bottom: n !== void 0 || C ? 0 : 0.1,
490
+ ...C && {
424
491
  top: 0.3
425
492
  }
426
493
  },
@@ -428,240 +495,294 @@ function ht({
428
495
  borderVisible: !0,
429
496
  borderColor: "rgba(224, 227, 235, 0.1)",
430
497
  entireTextOnly: !1,
431
- textColor: A
498
+ textColor: Y
432
499
  });
433
500
  } catch {
434
501
  }
435
- if (r !== void 0 && !V && (M || !C) && e.applyOptions({
502
+ if (n !== void 0 && !P && (D || !w) && e.applyOptions({
436
503
  handleScroll: {
437
504
  vertTouchDrag: !1
438
505
  }
439
- }), I.length > 0) {
440
- const o = I.map((F) => Number(F.time)), n = Math.min(...o), q = E !== void 0 ? Math.min(E, n) : n, W = Math.max(...o);
441
- e.timeScale().setVisibleRange({ from: q, to: W });
506
+ }), $.length > 0) {
507
+ const o = $.map((G) => Number(G.time)), a = Math.min(...o), V = j !== void 0 ? Math.min(j, a) : a, X = Math.max(...o);
508
+ e.timeScale().setVisibleRange({ from: V, to: X });
442
509
  }
443
- ve.current && (ve.current = !1);
444
- const ce = /* @__PURE__ */ new Map();
510
+ ye.current && (ye.current = !1);
511
+ const de = /* @__PURE__ */ new Map();
445
512
  for (const o of t)
446
- o.data.length > 0 && ce.set(o.label, o.data[o.data.length - 1]);
447
- le(ce.size > 0 ? ce : void 0);
513
+ o.data.length > 0 && de.set(o.label, o.data[o.data.length - 1]);
514
+ ue(de.size > 0 ? de : void 0);
448
515
  }, [
449
516
  t,
450
- I,
451
- g,
452
- N,
453
- V,
454
- M,
455
- be,
456
- pe,
457
- E
458
- ]), $(() => {
459
- const e = R.current;
517
+ $,
518
+ h,
519
+ y,
520
+ P,
521
+ D,
522
+ xe,
523
+ Se,
524
+ j,
525
+ R,
526
+ W
527
+ ]), L(() => {
528
+ const e = T.current;
460
529
  if (!e || t.length === 0) return;
461
- const a = t.length === 1;
462
- let r;
530
+ const l = t.length === 1;
531
+ let n;
463
532
  for (const i of t)
464
533
  if (i.data.length > 0) {
465
- r = i.data[i.data.length - 1].time;
534
+ n = i.data[i.data.length - 1].time;
466
535
  break;
467
536
  }
468
- if (!r) return;
469
- const l = (i) => {
470
- const { time: c = r, seriesData: f, point: P } = i || {}, m = Array.from(w.current.values());
471
- if (!P || !c) {
472
- const y = /* @__PURE__ */ new Map();
473
- for (const d of t)
474
- d.data.length > 0 && y.set(d.label, d.data[d.data.length - 1]);
475
- if (le(y.size > 0 ? y : void 0), a || M)
476
- z(null);
477
- else if (m[0] && r) {
478
- const S = e.timeScale().timeToCoordinate(r), h = t[0];
479
- if (h.data.length > 0) {
480
- const C = h.data[h.data.length - 1].value, b = m[0].priceToCoordinate(C);
481
- S !== null && b !== null && z({ x: S, y: b });
537
+ if (!n) return;
538
+ const r = (i) => {
539
+ const { time: u = n, seriesData: d, point: B } = i || {}, g = Array.from(v.current.values());
540
+ if (!B || !u) {
541
+ const _ = /* @__PURE__ */ new Map();
542
+ for (const m of t)
543
+ m.data.length > 0 && _.set(m.label, m.data[m.data.length - 1]);
544
+ if (ue(_.size > 0 ? _ : void 0), l || D)
545
+ E(null);
546
+ else if (g[0] && n) {
547
+ const N = e.timeScale().timeToCoordinate(n), C = t[0];
548
+ if (C.data.length > 0) {
549
+ const w = C.data[C.data.length - 1].value, x = g[0].priceToCoordinate(w);
550
+ N !== null && x !== null && E({ x: N, y: x });
482
551
  }
483
552
  }
484
553
  return;
485
554
  }
486
- const T = /* @__PURE__ */ new Map();
487
- let k;
488
- for (let y = 0; y < t.length; y++) {
489
- const d = t[y], S = m[y];
490
- if (!S) continue;
491
- const h = f?.get(S), C = h && "value" in h ? h.value : void 0;
492
- let b;
493
- if (C !== void 0)
494
- b = C;
495
- else if (a) {
496
- const A = Number(c), X = d.data.length > 0 ? Number(d.data[0].time) : Number.POSITIVE_INFINITY;
497
- A < X ? b = Number.NaN : b = d.data[d.data.length - 1]?.value ?? 0;
555
+ const F = /* @__PURE__ */ new Map();
556
+ let M;
557
+ for (let _ = 0; _ < t.length; _++) {
558
+ const m = t[_], N = g[_];
559
+ if (!N) continue;
560
+ const C = d?.get(N), w = C && "value" in C ? C.value : void 0;
561
+ let x;
562
+ if (w !== void 0)
563
+ x = w;
564
+ else if (l) {
565
+ const Y = Number(u), J = m.data.length > 0 ? Number(m.data[0].time) : Number.POSITIVE_INFINITY;
566
+ Y < J ? x = Number.NaN : x = m.data[m.data.length - 1]?.value ?? 0;
498
567
  } else
499
- b = Ze(d.data, Number(c));
500
- Number.isNaN(b) || (k === void 0 && (k = b), T.set(d.label, { value: b, time: c }));
568
+ x = it(m.data, Number(u));
569
+ Number.isNaN(x) || (M === void 0 && (M = x), F.set(m.label, { value: x, time: u }));
501
570
  }
502
- if (le(T), k !== void 0 && m[0]) {
503
- const d = e.timeScale().timeToCoordinate(c), S = m[0].priceToCoordinate(k);
504
- if (d !== null && S !== null) {
505
- const h = O.current;
506
- if (h) {
507
- const C = h.querySelector(
571
+ if (ue(F), M !== void 0 && g[0]) {
572
+ const m = e.timeScale().timeToCoordinate(u), N = g[0].priceToCoordinate(M);
573
+ if (m !== null && N !== null) {
574
+ const C = H.current;
575
+ if (C) {
576
+ const w = C.querySelector(
508
577
  ".LightweightChart"
509
578
  );
510
- if (C) {
511
- const b = C.getBoundingClientRect(), A = h.getBoundingClientRect(), X = d + (b.left - A.left), se = S + (b.top - A.top);
512
- z({ x: X, y: se });
579
+ if (w) {
580
+ const x = w.getBoundingClientRect(), Y = C.getBoundingClientRect(), J = m + (x.left - Y.left), fe = N + (x.top - Y.top);
581
+ E({ x: J, y: fe });
513
582
  } else
514
- z({ x: d, y: S });
583
+ E({ x: m, y: N });
515
584
  } else
516
- z({ x: d, y: S });
585
+ E({ x: m, y: N });
517
586
  } else
518
- z(null);
587
+ E(null);
519
588
  } else
520
- z(null);
589
+ E(null);
521
590
  };
522
- return e.subscribeCrosshairMove(l), V && e.subscribeClick(l), !a && !M && requestAnimationFrame(() => {
523
- const i = Array.from(w.current.values());
524
- if (i[0] && r && t[0]?.data.length > 0) {
525
- const f = e.timeScale().timeToCoordinate(r), P = t[0].data[t[0].data.length - 1].value, m = i[0].priceToCoordinate(P);
526
- f !== null && m !== null && z({ x: f, y: m });
591
+ return e.subscribeCrosshairMove(r), P && e.subscribeClick(r), !l && !D && requestAnimationFrame(() => {
592
+ const i = Array.from(v.current.values());
593
+ if (i[0] && n && t[0]?.data.length > 0) {
594
+ const d = e.timeScale().timeToCoordinate(n), B = t[0].data[t[0].data.length - 1].value, g = i[0].priceToCoordinate(B);
595
+ d !== null && g !== null && E({ x: d, y: g });
527
596
  }
528
597
  }), () => {
529
- e.unsubscribeCrosshairMove(l), V && e.unsubscribeClick(l);
598
+ e.unsubscribeCrosshairMove(r), P && e.unsubscribeClick(r);
530
599
  };
531
- }, [t, M, V]), $(() => {
532
- const e = R.current;
600
+ }, [t, D, P]), L(() => {
601
+ const e = T.current;
533
602
  if (!e || t.length === 0) return;
534
- const a = e.timeScale(), r = () => {
535
- if (!ne.current) return;
536
- const l = a.getVisibleRange();
537
- if (!l) return;
538
- const i = Number(l.from), c = Number(l.to), f = [];
539
- for (const P of t)
540
- for (const m of P.data) {
541
- const T = Number(m.time);
542
- T >= i && T <= c && f.push(m.value);
603
+ const l = e.timeScale(), n = () => {
604
+ if (!se.current) return;
605
+ const r = l.getVisibleRange();
606
+ if (!r) return;
607
+ const i = Number(r.from), u = Number(r.to), d = [];
608
+ for (const B of t)
609
+ for (const g of B.data) {
610
+ const F = Number(g.time);
611
+ F >= i && F <= u && d.push(g.value);
543
612
  }
544
- f.length > 0 && ne.current(f);
613
+ d.length > 0 && se.current(d);
545
614
  };
546
- return a.subscribeVisibleLogicalRangeChange(r), () => {
547
- a.unsubscribeVisibleLogicalRangeChange(
548
- r
615
+ return l.subscribeVisibleLogicalRangeChange(n), () => {
616
+ l.unsubscribeVisibleLogicalRangeChange(
617
+ n
549
618
  );
550
619
  };
551
- }, [t]), $(() => {
552
- const e = R.current, a = Array.from(w.current.values()), r = [];
553
- if (e && a.length > 0 && x) {
554
- const l = _e(), i = a[0];
555
- for (const c of x) {
556
- const f = new Je(e, i, c.xCoordinate, {
557
- ...l,
558
- ...c.options || {}
620
+ }, [t]), L(() => {
621
+ const e = T.current, l = Array.from(v.current.values()), n = [];
622
+ if (e && l.length > 0 && p) {
623
+ const r = Oe(), i = l[0];
624
+ for (const u of p) {
625
+ const d = new ot(e, i, u.xCoordinate, {
626
+ ...r,
627
+ ...u.options || {}
559
628
  });
560
- i.attachPrimitive(f), r.push(f);
629
+ i.attachPrimitive(d), n.push(d);
561
630
  }
562
631
  }
563
632
  return () => {
564
- if (a.length > 0) {
565
- const l = a[0];
566
- for (const i of r)
567
- l.detachPrimitive(i);
633
+ if (l.length > 0) {
634
+ const r = l[0];
635
+ for (const i of n)
636
+ r.detachPrimitive(i);
568
637
  }
569
638
  };
570
- }, [x, t]), $(() => {
571
- const e = R.current;
572
- if (!e || !x?.length) {
573
- Ne([]);
639
+ }, [p, t]), L(() => {
640
+ const e = [];
641
+ if (R && R.length > 0) {
642
+ const l = Array.from(v.current.values())[0], n = O(
643
+ "hsl(var(--destructive))",
644
+ "rgb(239, 68, 68)"
645
+ );
646
+ for (const r of R) {
647
+ if (!Number.isFinite(r.price)) continue;
648
+ const i = r.seriesLabel ? v.current.get(r.seriesLabel) : l;
649
+ if (!i) continue;
650
+ const u = i.createPriceLine({
651
+ price: r.price,
652
+ color: r.color ? O(r.color, r.color) : n,
653
+ lineWidth: r.lineWidth ?? 1,
654
+ lineStyle: r.lineStyle ?? Ze.Dashed,
655
+ axisLabelVisible: r.axisLabelVisible ?? !0,
656
+ title: r.title ?? ""
657
+ });
658
+ e.push({ series: i, line: u });
659
+ }
660
+ }
661
+ return () => {
662
+ for (const { series: l, line: n } of e)
663
+ try {
664
+ l.removePriceLine(n);
665
+ } catch {
666
+ }
667
+ };
668
+ }, [R, t]), L(() => {
669
+ const e = [];
670
+ if (W && W.length > 0) {
671
+ const l = Array.from(v.current.values())[0], n = "rgba(239, 68, 68, 0.12)";
672
+ for (const r of W) {
673
+ const i = r.seriesLabel ? v.current.get(r.seriesLabel) : l;
674
+ if (!i) continue;
675
+ const u = r.color ? O(r.color, n) : n, d = new at(
676
+ i,
677
+ r.priceTop,
678
+ r.priceBottom,
679
+ u
680
+ );
681
+ i.attachPrimitive(d), e.push({ series: i, zone: d });
682
+ }
683
+ }
684
+ return () => {
685
+ for (const { series: l, zone: n } of e)
686
+ try {
687
+ l.detachPrimitive(n);
688
+ } catch {
689
+ }
690
+ };
691
+ }, [W, t]), L(() => {
692
+ const e = T.current;
693
+ if (!e || !p?.length) {
694
+ Re([]);
574
695
  return;
575
696
  }
576
- const a = () => {
577
- const i = e.timeScale(), c = x.map((f) => i.timeToCoordinate(f.xCoordinate) ?? null);
578
- Ne(c);
697
+ const l = () => {
698
+ const i = e.timeScale(), u = p.map((d) => i.timeToCoordinate(d.xCoordinate) ?? null);
699
+ Re(u);
579
700
  };
580
- a();
581
- const r = e.timeScale(), l = () => {
582
- a();
701
+ l();
702
+ const n = e.timeScale(), r = () => {
703
+ l();
583
704
  };
584
- return r.subscribeVisibleLogicalRangeChange(l), () => {
585
- r.unsubscribeVisibleLogicalRangeChange(l);
705
+ return n.subscribeVisibleLogicalRangeChange(r), () => {
706
+ n.unsubscribeVisibleLogicalRangeChange(r);
586
707
  };
587
- }, [x, t]);
588
- const Z = t.length === 1, we = fe.useMemo(() => {
589
- if (Z && t.length > 0) {
708
+ }, [p, t]);
709
+ const oe = t.length === 1, Te = ge.useMemo(() => {
710
+ if (oe && t.length > 0) {
590
711
  const e = t[0];
591
712
  if (e.data.length > 0)
592
713
  return e.data[e.data.length - 1];
593
714
  }
594
- }, [Z, t]);
595
- return /* @__PURE__ */ K(
715
+ }, [oe, t]);
716
+ return /* @__PURE__ */ U(
596
717
  "div",
597
718
  {
598
- ref: O,
599
- className: he(
719
+ ref: H,
720
+ className: Ce(
600
721
  "relative z-[1] w-full h-full overflow-hidden p-0",
601
- v
722
+ c
602
723
  ),
603
724
  children: [
604
- oe != null && oe !== !1 && Z ? /* @__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: oe }) }) : De && Z && we && /* @__PURE__ */ p(
605
- qe,
725
+ le != null && le !== !1 && oe ? /* @__PURE__ */ S("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ S("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: le }) }) : Ae && oe && Te && /* @__PURE__ */ S(
726
+ et,
606
727
  {
607
- point: we,
608
- xMeasureUnit: g,
609
- yMeasureUnit: N,
610
- decimals: te
728
+ point: Te,
729
+ xMeasureUnit: h,
730
+ yMeasureUnit: y,
731
+ decimals: ae
611
732
  }
612
733
  ),
613
- Ce && xe && /* @__PURE__ */ p(
614
- Ke,
734
+ we && Ne && /* @__PURE__ */ S(
735
+ tt,
615
736
  {
616
- points: Ce,
617
- xMeasureUnit: g,
618
- yMeasureUnit: N,
737
+ points: we,
738
+ xMeasureUnit: h,
739
+ yMeasureUnit: y,
619
740
  series: t,
620
- position: xe,
621
- containerRef: O,
622
- decimals: te
741
+ position: Ne,
742
+ containerRef: H,
743
+ decimals: ae
623
744
  }
624
745
  ),
625
- u && /* @__PURE__ */ p(et, { series: t, onUnselect: D }),
626
- x && x.length > 0 && Se.length === x.length && /* @__PURE__ */ p(
746
+ s && /* @__PURE__ */ S(ct, { series: t, onUnselect: b }),
747
+ p && p.length > 0 && Ve.length === p.length && /* @__PURE__ */ S(
627
748
  "div",
628
749
  {
629
750
  className: "absolute inset-0 z-[5] pointer-events-none",
630
751
  "aria-hidden": !0,
631
- children: x.map((e, a) => {
632
- const r = Se[a], l = e.options ?? {}, i = l.showLabel !== !1;
633
- if (r === null || !i) return null;
634
- const { labelText: c, valueStr: f } = Qe(
635
- l,
636
- N,
637
- te
752
+ children: p.map((e, l) => {
753
+ const n = Ve[l], r = e.options ?? {}, i = r.showLabel !== !1;
754
+ if (n === null || !i) return null;
755
+ const { labelText: u, valueStr: d } = lt(
756
+ r,
757
+ y,
758
+ ae
638
759
  );
639
- if (!(c || f)) return null;
640
- const m = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", T = l.labelTextColor ?? "hsl(var(--foreground))", k = `${String(e.xCoordinate)}-${c}`;
641
- return /* @__PURE__ */ K(
760
+ if (!(u || d)) return null;
761
+ const g = r.labelBackgroundColor ?? r.color ?? "hsl(var(--background))", F = r.labelTextColor ?? "hsl(var(--foreground))", M = `${String(e.xCoordinate)}-${u}`;
762
+ return /* @__PURE__ */ U(
642
763
  "div",
643
764
  {
644
765
  className: "absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
645
766
  style: {
646
- left: r,
767
+ left: n,
647
768
  transform: "translateX(-50%)",
648
- backgroundColor: m,
649
- color: T
769
+ backgroundColor: g,
770
+ color: F
650
771
  },
651
772
  children: [
652
- c && /* @__PURE__ */ p("span", { className: "block", children: c }),
653
- f && /* @__PURE__ */ p("span", { className: he("block", c && "mt-0.5"), children: f })
773
+ u && /* @__PURE__ */ S("span", { className: "block", children: u }),
774
+ d && /* @__PURE__ */ S("span", { className: Ce("block", u && "mt-0.5"), children: d })
654
775
  ]
655
776
  },
656
- k
777
+ M
657
778
  );
658
779
  })
659
780
  }
660
781
  ),
661
- /* @__PURE__ */ p(
782
+ /* @__PURE__ */ S(
662
783
  "div",
663
784
  {
664
- ref: ae,
785
+ ref: ce,
665
786
  className: "LightweightChart w-full h-full overflow-hidden"
666
787
  }
667
788
  )
@@ -669,41 +790,41 @@ function ht({
669
790
  }
670
791
  );
671
792
  }
672
- function et({
793
+ function ct({
673
794
  series: t,
674
- onUnselect: v
795
+ onUnselect: c
675
796
  }) {
676
- return /* @__PURE__ */ p("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: t.map((u, D) => {
677
- const g = Le(D), N = (u.lineColor ?? u.color) || g.line, _ = u.data.length === 0;
678
- return /* @__PURE__ */ K(
797
+ return /* @__PURE__ */ S("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: t.map((s, b) => {
798
+ const h = Fe(b), y = (s.lineColor ?? s.color) || h.line, z = s.data.length === 0;
799
+ return /* @__PURE__ */ U(
679
800
  "div",
680
801
  {
681
- className: he(
802
+ className: Ce(
682
803
  "flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
683
- _ && "opacity-50"
804
+ z && "opacity-50"
684
805
  ),
685
806
  children: [
686
- /* @__PURE__ */ p(
807
+ /* @__PURE__ */ S(
687
808
  "div",
688
809
  {
689
810
  className: "w-3 h-3 rounded-sm",
690
- style: { backgroundColor: N }
811
+ style: { backgroundColor: y }
691
812
  }
692
813
  ),
693
- /* @__PURE__ */ K("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
694
- u.label,
695
- _ && " (no data)"
814
+ /* @__PURE__ */ U("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
815
+ s.label,
816
+ z && " (no data)"
696
817
  ] }),
697
- v && /* @__PURE__ */ p(
818
+ c && /* @__PURE__ */ S(
698
819
  "button",
699
820
  {
700
821
  type: "button",
701
- onClick: (x) => {
702
- x.stopPropagation(), v(u.label);
822
+ onClick: (p) => {
823
+ p.stopPropagation(), c(s.label);
703
824
  },
704
825
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
705
- "aria-label": `Remove ${u.label}`,
706
- children: /* @__PURE__ */ K(
826
+ "aria-label": `Remove ${s.label}`,
827
+ children: /* @__PURE__ */ U(
707
828
  "svg",
708
829
  {
709
830
  xmlns: "http://www.w3.org/2000/svg",
@@ -718,9 +839,9 @@ function et({
718
839
  className: "text-muted-foreground hover:text-foreground",
719
840
  "aria-hidden": "true",
720
841
  children: [
721
- /* @__PURE__ */ p("title", { children: "Close" }),
722
- /* @__PURE__ */ p("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
723
- /* @__PURE__ */ p("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
842
+ /* @__PURE__ */ S("title", { children: "Close" }),
843
+ /* @__PURE__ */ S("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
844
+ /* @__PURE__ */ S("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
724
845
  ]
725
846
  }
726
847
  )
@@ -728,14 +849,14 @@ function et({
728
849
  )
729
850
  ]
730
851
  },
731
- u.label
852
+ s.label
732
853
  );
733
854
  }) });
734
855
  }
735
856
  export {
736
- me as DEFAULT_SERIES_COLORS,
737
- ht as Graph,
738
- Le as getSeriesColorPalette,
739
- Ze as getStepForwardValue,
740
- Qe as getVerticalLineTooltipContent
857
+ ve as DEFAULT_SERIES_COLORS,
858
+ Nt as Graph,
859
+ Fe as getSeriesColorPalette,
860
+ it as getStepForwardValue,
861
+ lt as getVerticalLineTooltipContent
741
862
  };