@gearbox-protocol/ui-kit 3.14.0-next.37 → 3.14.0-next.39

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,46 +1,46 @@
1
- import { jsxs as re, jsx as y } from "react/jsx-runtime";
2
- import { createChart as Ue, CrosshairMode as et, LineStyle as Ge, LineSeries as tt, AreaSeries as ot } from "lightweight-charts";
3
- import * as Ce from "react";
4
- import { useRef as X, useState as Se, useEffect as W } from "react";
5
- import { useIsMobile as rt } from "../../hooks/use-media-query.js";
6
- import { cn as ne } from "../../utils/cn.js";
7
- import { resolveCSSColor as U, generateColorsFromBase as se, hslToHex as nt } from "../../utils/colors.js";
8
- import { getDefaultOptions as je, getDefaultSeries as lt, getDefaultVerticalLine as at } from "./default-config.js";
9
- import { getXFormatters as He, formatExactValue as xe, createAdaptiveYAxisFormatter as it } from "./formatters.js";
10
- import { GraphCurrentValue as st } from "./graph-current-value.js";
11
- import { GraphTooltip as ct } from "./graph-tooltip.js";
12
- import { VertLine as ut } from "./plugins/vertical-line.js";
13
- class ft {
1
+ import { jsxs as ne, jsx as w } from "react/jsx-runtime";
2
+ import { createChart as ot, CrosshairMode as rt, LineStyle as ee, LineSeries as nt, AreaSeries as lt } from "lightweight-charts";
3
+ import * as ye from "react";
4
+ import { useRef as Z, useState as ce, useEffect as $ } from "react";
5
+ import { useIsMobile as it } from "../../hooks/use-media-query.js";
6
+ import { cn as le } from "../../utils/cn.js";
7
+ import { resolveCSSColor as U, generateColorsFromBase as ue, hslToHex as at } from "../../utils/colors.js";
8
+ import { getDefaultOptions as je, getDefaultSeries as st, getDefaultVerticalLine as ct } from "./default-config.js";
9
+ import { getXFormatters as He, formatExactValue as xe, createAdaptiveYAxisFormatter as ut } from "./formatters.js";
10
+ import { GraphCurrentValue as ft } from "./graph-current-value.js";
11
+ import { GraphTooltip as ht } from "./graph-tooltip.js";
12
+ import { VertLine as dt } from "./plugins/vertical-line.js";
13
+ class pt {
14
14
  _yTop;
15
15
  _yBottom;
16
16
  _color;
17
- constructor(c, g, b) {
18
- this._yTop = c, this._yBottom = g, this._color = b;
17
+ constructor(n, f, c) {
18
+ this._yTop = n, this._yBottom = f, this._color = c;
19
19
  }
20
- draw(c) {
21
- c.useBitmapCoordinateSpace((g) => {
22
- const b = g.context, d = g.verticalPixelRatio, w = this._yTop === null ? 0 : this._yTop * d, q = this._yBottom === null ? g.bitmapSize.height : this._yBottom * d, x = Math.min(w, q), k = Math.max(w, q);
23
- b.fillStyle = this._color, b.fillRect(0, x, g.bitmapSize.width, k - x);
20
+ draw(n) {
21
+ n.useBitmapCoordinateSpace((f) => {
22
+ const c = f.context, d = f.verticalPixelRatio, v = this._yTop === null ? 0 : this._yTop * d, z = this._yBottom === null ? f.bitmapSize.height : this._yBottom * d, x = Math.min(v, z), M = Math.max(v, z);
23
+ c.fillStyle = this._color, c.fillRect(0, x, f.bitmapSize.width, M - x);
24
24
  });
25
25
  }
26
26
  }
27
- class ht {
27
+ class mt {
28
28
  _source;
29
29
  _yTop = null;
30
30
  _yBottom = null;
31
- constructor(c) {
32
- this._source = c;
31
+ constructor(n) {
32
+ this._source = n;
33
33
  }
34
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);
35
+ const n = this._source.series;
36
+ this._yTop = this._source.priceTop === void 0 ? null : n.priceToCoordinate(this._source.priceTop), this._yBottom = this._source.priceBottom === void 0 ? null : n.priceToCoordinate(this._source.priceBottom);
37
37
  }
38
38
  /** Draw beneath the series line/area so the data stays readable. */
39
39
  zOrder() {
40
40
  return "bottom";
41
41
  }
42
42
  renderer() {
43
- return new ft(this._yTop, this._yBottom, this._source.color);
43
+ return new pt(this._yTop, this._yBottom, this._source.color);
44
44
  }
45
45
  }
46
46
  class gt {
@@ -49,31 +49,109 @@ class gt {
49
49
  priceBottom;
50
50
  color;
51
51
  _paneViews;
52
- constructor(c, g, b, d) {
53
- this.series = c, this.priceTop = g, this.priceBottom = b, this.color = d, this._paneViews = [new ht(this)];
52
+ constructor(n, f, c, d) {
53
+ this.series = n, this.priceTop = f, this.priceBottom = c, this.color = d, this._paneViews = [new mt(this)];
54
54
  }
55
55
  updateAllViews() {
56
- for (const c of this._paneViews) c.update();
56
+ for (const n of this._paneViews) n.update();
57
57
  }
58
58
  paneViews() {
59
59
  return this._paneViews;
60
60
  }
61
61
  }
62
- function dt(o, c, g) {
63
- const b = o.labelText ?? "", d = o.value, w = d === void 0 ? "" : typeof d == "number" ? c === "$" ? `$${xe(d, void 0, g)}` : c === "%" ? `${xe(d, void 0, g)}%` : xe(
62
+ function bt(e, n) {
63
+ switch (e) {
64
+ case ee.Dotted:
65
+ return [n, n];
66
+ case ee.Dashed:
67
+ return [2 * n, 2 * n];
68
+ case ee.LargeDashed:
69
+ return [6 * n, 6 * n];
70
+ case ee.SparseDotted:
71
+ return [n, 4 * n];
72
+ default:
73
+ return [];
74
+ }
75
+ }
76
+ class vt {
77
+ _y;
78
+ _color;
79
+ _lineWidth;
80
+ _lineStyle;
81
+ constructor(n, f, c, d) {
82
+ this._y = n, this._color = f, this._lineWidth = c, this._lineStyle = d;
83
+ }
84
+ draw(n) {
85
+ n.useBitmapCoordinateSpace((f) => {
86
+ if (this._y === null) return;
87
+ const c = f.context, d = f.verticalPixelRatio, v = Math.max(1, Math.round(this._lineWidth * d)), z = Math.round(this._y * d);
88
+ c.save(), c.strokeStyle = this._color, c.lineWidth = v, c.setLineDash(bt(this._lineStyle, v)), c.beginPath(), c.moveTo(0, z), c.lineTo(f.bitmapSize.width, z), c.stroke(), c.restore();
89
+ });
90
+ }
91
+ }
92
+ class St {
93
+ _source;
94
+ _y = null;
95
+ constructor(n) {
96
+ this._source = n;
97
+ }
98
+ update() {
99
+ this._y = this._source.series.priceToCoordinate(this._source.price);
100
+ }
101
+ /**
102
+ * Draw on the top pane (top canvas) so a liquidation price line stays above
103
+ * every series' area/line fill, price zones and the crosshair — native
104
+ * `createPriceLine` only draws in the "normal" group and can be hidden behind
105
+ * a later series in multi-series charts.
106
+ */
107
+ zOrder() {
108
+ return "top";
109
+ }
110
+ renderer() {
111
+ return new vt(
112
+ this._y,
113
+ this._source.color,
114
+ this._source.lineWidth,
115
+ this._source.lineStyle
116
+ );
117
+ }
118
+ }
119
+ class Ct {
120
+ series;
121
+ price;
122
+ color;
123
+ lineWidth;
124
+ lineStyle;
125
+ _paneViews;
126
+ constructor(n, f, c, d, v) {
127
+ this.series = n, this.price = f, this.color = c, this.lineWidth = d, this.lineStyle = v, this._paneViews = [new St(this)];
128
+ }
129
+ updateAllViews() {
130
+ for (const n of this._paneViews) n.update();
131
+ }
132
+ paneViews() {
133
+ return this._paneViews;
134
+ }
135
+ }
136
+ function yt(e, n, f) {
137
+ const c = e.labelText ?? "", d = e.value, v = d === void 0 ? "" : typeof d == "number" ? n === "$" ? `$${xe(d, void 0, f)}` : n === "%" ? `${xe(d, void 0, f)}%` : xe(
64
138
  d,
65
- c !== "none" && c !== "%" && c !== "$" ? c : void 0,
66
- g
139
+ n !== "none" && n !== "%" && n !== "$" ? n : void 0,
140
+ f
67
141
  ) : String(d);
68
- return { labelText: b, valueStr: w };
142
+ return { labelText: c, valueStr: v };
69
143
  }
70
- function mt(o, c) {
71
- for (let g = o.length - 1; g >= 0; g--)
72
- if (Number(o[g].time) <= c)
73
- return o[g].value;
144
+ const Oe = 40;
145
+ function xt(e, n) {
146
+ return n <= 0 ? { left: e, transform: "translateX(-50%)" } : e <= Oe ? { left: e, transform: "translateX(4px)" } : e >= n - Oe ? { left: e, transform: "translateX(calc(-100% - 4px))" } : { left: e, transform: "translateX(-50%)" };
147
+ }
148
+ function wt(e, n) {
149
+ for (let f = e.length - 1; f >= 0; f--)
150
+ if (Number(e[f].time) <= n)
151
+ return e[f].value;
74
152
  return 0;
75
153
  }
76
- const ye = [
154
+ const we = [
77
155
  // 0 green (emerald)
78
156
  {
79
157
  line: "#02c39a",
@@ -188,70 +266,70 @@ const ye = [
188
266
  top: "rgba(71, 85, 105, 0.56)",
189
267
  bottom: "rgba(71, 85, 105, 0.04)"
190
268
  }
191
- ], bt = 137.5;
192
- function Xe(o) {
193
- if (o < ye.length)
194
- return ye[o];
195
- const g = (o - ye.length) * bt % 360, b = nt(g, 70, 50), { topColor: d, bottomColor: w } = se(b);
196
- return { line: b, top: d, bottom: w };
269
+ ], _t = 137.5;
270
+ function qe(e) {
271
+ if (e < we.length)
272
+ return we[e];
273
+ const f = (e - we.length) * _t % 360, c = at(f, 70, 50), { topColor: d, bottomColor: v } = ue(c);
274
+ return { line: c, top: d, bottom: v };
197
275
  }
198
- function Lt({
199
- series: o,
200
- className: c,
201
- showLegend: g = !1,
202
- onUnselectSeries: b,
276
+ function Wt({
277
+ series: e,
278
+ className: n,
279
+ showLegend: f = !1,
280
+ onUnselectSeries: c,
203
281
  xMeasureUnit: d = "time",
204
- yMeasureUnit: w = "token",
205
- optionsOverrides: q,
282
+ yMeasureUnit: v = "token",
283
+ optionsOverrides: z,
206
284
  verticalLineOptions: x,
207
- priceLineOptions: k,
208
- zoneOptions: A,
209
- currentValueDecimals: ce,
210
- useSharedPriceScale: $ = !1,
211
- dualYAxis: _ = !1,
212
- defaultVisiblePriceScaleId: we = "right",
285
+ priceLineOptions: M,
286
+ zoneOptions: j,
287
+ currentValueDecimals: fe,
288
+ useSharedPriceScale: G = !1,
289
+ dualYAxis: D = !1,
290
+ defaultVisiblePriceScaleId: _e = "right",
213
291
  leftPriceScaleTitle: Ne,
214
- rightPriceScaleTitle: vt,
215
- showCurrentValue: qe = !0,
216
- graphTitle: ue,
292
+ rightPriceScaleTitle: Tt,
293
+ showCurrentValue: Ze = !0,
294
+ graphTitle: he,
217
295
  yScaleMin: Te,
218
296
  yScaleMinMultiple: Ve,
219
- visibleTimeFrom: Z,
220
- disableZoom: le = !1,
221
- hideDefaultTooltip: fe = !1
297
+ visibleTimeFrom: K,
298
+ disableZoom: ie = !1,
299
+ hideDefaultTooltip: de = !1
222
300
  }) {
223
- const I = X(null), v = X(/* @__PURE__ */ new Map()), he = X(!1), Re = X(!0), Pe = X([]), K = X(null), ge = X(null), ae = X(null), R = rt(), G = Ce.useMemo(() => o.flatMap((t) => t.data), [o]), Ze = Ce.useMemo(() => {
224
- if (o.length > 0) {
225
- const t = o[o.length - 1];
226
- if (t.data.length > 0)
227
- return t.data[t.data.length - 1];
301
+ const E = Z(null), C = Z(/* @__PURE__ */ new Map()), pe = Z(!1), Pe = Z(!0), Le = Z([]), I = Z(null), me = Z(null), ae = Z(null), V = it(), H = ye.useMemo(() => e.flatMap((o) => o.data), [e]), Ke = ye.useMemo(() => {
302
+ if (e.length > 0) {
303
+ const o = e[e.length - 1];
304
+ if (o.data.length > 0)
305
+ return o.data[o.data.length - 1];
228
306
  }
229
- }, [o]), [Me, de] = Se(() => {
230
- if (!Ze) return;
231
- const t = /* @__PURE__ */ new Map();
232
- for (const a of o)
233
- a.data.length > 0 && t.set(a.label, a.data[a.data.length - 1]);
234
- return t;
235
- }), [ke, j] = Se(null), [Le, _e] = Se([]);
236
- W(() => {
237
- const t = () => {
307
+ }, [e]), [Re, ge] = ce(() => {
308
+ if (!Ke) return;
309
+ const o = /* @__PURE__ */ new Map();
310
+ for (const s of e)
311
+ s.data.length > 0 && o.set(s.label, s.data[s.data.length - 1]);
312
+ return o;
313
+ }), [Me, O] = ce(null), [ke, De] = ce([]), [Je, Ie] = ce(0);
314
+ $(() => {
315
+ const o = () => {
238
316
  try {
239
- if (I.current && K.current) {
240
- const n = K.current.clientWidth, i = K.current.clientHeight;
241
- I.current.resize(n, i);
317
+ if (I.current && Ie(I.current.clientWidth), E.current && I.current) {
318
+ const a = I.current.clientWidth, i = I.current.clientHeight;
319
+ E.current.resize(a, i);
242
320
  }
243
321
  } catch {
244
322
  }
245
- }, a = K.current, l = a ? new ResizeObserver(t) : null;
246
- return ae.current = l, a && l?.observe(a), () => {
247
- a && l?.unobserve(a), l?.disconnect(), ae.current = null;
323
+ }, s = I.current, l = s ? new ResizeObserver(o) : null;
324
+ return ae.current = l, s && l?.observe(s), () => {
325
+ s && l?.unobserve(s), l?.disconnect(), ae.current = null;
248
326
  };
249
- }, []), W(() => {
250
- if (!ge.current || he.current) return;
251
- const t = je(), a = U(
327
+ }, []), $(() => {
328
+ if (!me.current || pe.current) return;
329
+ const o = je(), s = U(
252
330
  "hsl(var(--foreground))",
253
331
  "rgb(0, 0, 0)"
254
- ), l = le ? {
332
+ ), l = ie ? {
255
333
  handleScale: {
256
334
  mouseWheel: !1,
257
335
  pinch: !1,
@@ -264,34 +342,34 @@ function Lt({
264
342
  horzTouchDrag: !1,
265
343
  vertTouchDrag: !1
266
344
  }
267
- } : {}, n = Ue(ge.current, {
268
- ...t,
345
+ } : {}, a = ot(me.current, {
346
+ ...o,
269
347
  leftPriceScale: {
270
- ...t.leftPriceScale || {},
348
+ ...o.leftPriceScale || {},
271
349
  visible: !1,
272
- textColor: a
350
+ textColor: s
273
351
  },
274
352
  rightPriceScale: {
275
- ...t.rightPriceScale || {},
276
- visible: !R,
277
- textColor: a
353
+ ...o.rightPriceScale || {},
354
+ visible: !V,
355
+ textColor: s
278
356
  },
279
- ...R && {
357
+ ...V && {
280
358
  crosshair: {
281
- ...t.crosshair,
282
- mode: et.Magnet
359
+ ...o.crosshair,
360
+ mode: rt.Magnet
283
361
  }
284
362
  },
285
363
  ...l,
286
- ...q
364
+ ...z
287
365
  });
288
- return I.current = n, he.current = !0, () => {
289
- ae.current?.disconnect(), ae.current = null, n.remove(), I.current = null, he.current = !1, v.current.clear();
366
+ return E.current = a, pe.current = !0, () => {
367
+ ae.current?.disconnect(), ae.current = null, a.remove(), E.current = null, pe.current = !1, C.current.clear();
290
368
  };
291
- }, [R, q, le]), W(() => {
292
- const t = I.current;
293
- t && t.applyOptions(
294
- le ? {
369
+ }, [V, z, ie]), $(() => {
370
+ const o = E.current;
371
+ o && o.applyOptions(
372
+ ie ? {
295
373
  handleScale: {
296
374
  mouseWheel: !1,
297
375
  pinch: !1,
@@ -319,89 +397,89 @@ function Lt({
319
397
  }
320
398
  }
321
399
  );
322
- }, [le]), W(() => {
323
- const t = I.current;
324
- if (!t || o.length === 0) return;
325
- const l = o.filter((r) => r.data.length > 0).length <= 1 ? Te : Ve, n = d === "time" ? He(d, G) : He(d), i = /* @__PURE__ */ new Map();
400
+ }, [ie]), $(() => {
401
+ const o = E.current;
402
+ if (!o || e.length === 0) return;
403
+ const l = e.filter((r) => r.data.length > 0).length <= 1 ? Te : Ve, a = d === "time" ? He(d, H) : He(d), i = /* @__PURE__ */ new Map();
326
404
  {
327
405
  let r = 0;
328
- for (const e of o)
329
- e.data.length !== 0 && (i.set(
330
- e.label,
331
- e.priceScaleId ?? (r === 0 ? "left" : "right")
406
+ for (const t of e)
407
+ t.data.length !== 0 && (i.set(
408
+ t.label,
409
+ t.priceScaleId ?? (r === 0 ? "left" : "right")
332
410
  ), r++);
333
411
  }
334
- const f = (r, e, s) => {
412
+ const u = (r, t, p) => {
335
413
  const {
336
- formatter: L,
337
- tickmarksFormatter: V,
338
- updateVisibleRange: z,
339
- updateLastValues: De
340
- } = it(r, e, {
414
+ formatter: k,
415
+ tickmarksFormatter: T,
416
+ updateVisibleRange: A,
417
+ updateLastValues: ze
418
+ } = ut(r, t, {
341
419
  yScaleMin: l
342
- }), be = o.filter((O) => O.data.length > 0 && s.has(O.label)).map((O) => O.data[O.data.length - 1].value);
343
- return De(be), { formatter: L, tickmarksFormatter: V, updateVisibleRange: z, labels: s };
344
- }, u = [];
345
- if (_)
420
+ }), ve = e.filter((J) => J.data.length > 0 && p.has(J.label)).map((J) => J.data[J.data.length - 1].value);
421
+ return ze(ve), { formatter: k, tickmarksFormatter: T, updateVisibleRange: A, labels: p };
422
+ }, h = [];
423
+ if (D)
346
424
  for (const r of ["left", "right"]) {
347
- const e = /* @__PURE__ */ new Set(), s = [];
348
- let L = w;
349
- for (const V of o)
350
- if (V.data.length !== 0 && i.get(V.label) === r) {
351
- e.size === 0 && V.yMeasureUnit && (L = V.yMeasureUnit), e.add(V.label);
352
- for (const z of V.data) s.push(z.value);
425
+ const t = /* @__PURE__ */ new Set(), p = [];
426
+ let k = v;
427
+ for (const T of e)
428
+ if (T.data.length !== 0 && i.get(T.label) === r) {
429
+ t.size === 0 && T.yMeasureUnit && (k = T.yMeasureUnit), t.add(T.label);
430
+ for (const A of T.data) p.push(A.value);
353
431
  }
354
- e.size > 0 && u.push(f(s, L, e));
432
+ t.size > 0 && h.push(u(p, k, t));
355
433
  }
356
434
  else {
357
- const r = G.map((s) => s.value), e = new Set(
358
- o.filter((s) => s.data.length > 0).map((s) => s.label)
435
+ const r = H.map((p) => p.value), t = new Set(
436
+ e.filter((p) => p.data.length > 0).map((p) => p.label)
359
437
  );
360
- u.push(f(r, w, e));
438
+ h.push(u(r, v, t));
361
439
  }
362
- Pe.current = u;
363
- const p = /* @__PURE__ */ new Map();
364
- for (const r of u)
365
- for (const e of r.labels)
366
- p.set(e, r);
367
- const C = je();
368
- t.applyOptions({
440
+ Le.current = h;
441
+ const b = /* @__PURE__ */ new Map();
442
+ for (const r of h)
443
+ for (const t of r.labels)
444
+ b.set(t, r);
445
+ const S = je();
446
+ o.applyOptions({
369
447
  localization: {
370
- ...C.localization || {},
448
+ ...S.localization || {},
371
449
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
372
450
  timeFormatter: (r) => (
373
451
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
374
- n.timeFormatter(parseFloat(r), void 0)
452
+ a.timeFormatter(parseFloat(r), void 0)
375
453
  )
376
454
  },
377
455
  timeScale: {
378
- ...C.timeScale || {},
456
+ ...S.timeScale || {},
379
457
  // biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
380
- tickMarkFormatter: n.tickMarkFormatter,
458
+ tickMarkFormatter: a.tickMarkFormatter,
381
459
  minBarSpacing: 0
382
460
  }
383
461
  });
384
- const B = (G.length > 0 ? Math.min(...G.map((r) => r.value)) : 0) < 0, N = G.some((r) => r.value === 0), m = !B && N, S = !_ && o.length > 1 && !$, P = _ ? R : o.length > 1 && !$ || R, M = U(
462
+ const P = (H.length > 0 ? Math.min(...H.map((r) => r.value)) : 0) < 0, _ = H.some((r) => r.value === 0), m = !P && _, y = !D && e.length > 1 && !G, L = D ? V : e.length > 1 && !G || V, R = U(
385
463
  "hsl(var(--foreground))",
386
464
  "rgb(0, 0, 0)"
387
465
  );
388
- t.applyOptions({
389
- ..._ && {
390
- defaultVisiblePriceScaleId: we
466
+ o.applyOptions({
467
+ ...D && {
468
+ defaultVisiblePriceScaleId: _e
391
469
  },
392
470
  leftPriceScale: {
393
- ...C.leftPriceScale || {},
394
- visible: _ && !R,
395
- textColor: M,
396
- ..._ && Ne && {
471
+ ...S.leftPriceScale || {},
472
+ visible: D && !V,
473
+ textColor: R,
474
+ ...D && Ne && {
397
475
  // lightweight-charts uses scale margins; title shown via localization if needed
398
476
  }
399
477
  },
400
478
  rightPriceScale: {
401
- ...C.rightPriceScale || {},
402
- visible: _ ? !R : !P,
403
- textColor: M,
404
- ...m && !_ && {
479
+ ...S.rightPriceScale || {},
480
+ visible: D ? !V : !L,
481
+ textColor: R,
482
+ ...m && !D && {
405
483
  scaleMargins: {
406
484
  top: 0.3,
407
485
  bottom: 0
@@ -409,123 +487,123 @@ function Lt({
409
487
  }
410
488
  }
411
489
  });
412
- const T = new Set(v.current.keys()), J = new Set(o.map((r) => r.label));
413
- for (const r of T)
414
- if (!J.has(r)) {
415
- const e = v.current.get(r);
416
- e && (t.removeSeries(e), v.current.delete(r));
490
+ const N = new Set(C.current.keys()), q = new Set(e.map((r) => r.label));
491
+ for (const r of N)
492
+ if (!q.has(r)) {
493
+ const t = C.current.get(r);
494
+ t && (o.removeSeries(t), C.current.delete(r));
417
495
  }
418
- const Q = lt(), ee = [];
419
- let te = 0;
420
- const Fe = o.find((r) => r.data.length > 0), oe = /* @__PURE__ */ new Map();
421
- if (k && k.length > 0)
422
- for (const r of k) {
496
+ const Q = st(), te = [];
497
+ let oe = 0;
498
+ const Fe = e.find((r) => r.data.length > 0), re = /* @__PURE__ */ new Map();
499
+ if (M && M.length > 0)
500
+ for (const r of M) {
423
501
  if (!Number.isFinite(r.price)) continue;
424
- const e = r.seriesLabel ?? Fe?.label;
425
- if (!e) continue;
426
- const s = oe.get(e) ?? [];
427
- s.push(r.price), oe.set(e, s);
502
+ const t = r.seriesLabel ?? Fe?.label;
503
+ if (!t) continue;
504
+ const p = re.get(t) ?? [];
505
+ p.push(r.price), re.set(t, p);
428
506
  }
429
- if (A && A.length > 0)
430
- for (const r of A) {
431
- const e = r.seriesLabel ?? Fe?.label;
432
- if (!e) continue;
433
- const s = oe.get(e) ?? [];
434
- Number.isFinite(r.priceTop) && s.push(r.priceTop), Number.isFinite(r.priceBottom) && s.push(r.priceBottom), oe.set(e, s);
507
+ if (j && j.length > 0)
508
+ for (const r of j) {
509
+ const t = r.seriesLabel ?? Fe?.label;
510
+ if (!t) continue;
511
+ const p = re.get(t) ?? [];
512
+ Number.isFinite(r.priceTop) && p.push(r.priceTop), Number.isFinite(r.priceBottom) && p.push(r.priceBottom), re.set(t, p);
435
513
  }
436
- for (let r = 0; r < o.length; r++) {
437
- const e = o[r], s = Xe(r), L = e.lineColor ?? e.color ?? s.line;
438
- let V, z;
439
- if (e.lineColor ?? e.color)
440
- if (e.topColor && e.bottomColor)
441
- V = e.topColor, z = e.bottomColor;
442
- else if (e.topColor) {
443
- const h = se(L);
444
- V = e.topColor, z = h.bottomColor;
445
- } else if (e.bottomColor)
446
- V = se(L).topColor, z = e.bottomColor;
514
+ for (let r = 0; r < e.length; r++) {
515
+ const t = e[r], p = qe(r), k = t.lineColor ?? t.color ?? p.line;
516
+ let T, A;
517
+ if (t.lineColor ?? t.color)
518
+ if (t.topColor && t.bottomColor)
519
+ T = t.topColor, A = t.bottomColor;
520
+ else if (t.topColor) {
521
+ const g = ue(k);
522
+ T = t.topColor, A = g.bottomColor;
523
+ } else if (t.bottomColor)
524
+ T = ue(k).topColor, A = t.bottomColor;
447
525
  else {
448
- const h = se(L);
449
- V = h.topColor, z = h.bottomColor;
526
+ const g = ue(k);
527
+ T = g.topColor, A = g.bottomColor;
450
528
  }
451
529
  else
452
- V = e.topColor || s.top, z = e.bottomColor || s.bottom;
453
- if (e.data.length === 0) {
454
- const h = v.current.get(e.label);
455
- h && (t.removeSeries(h), v.current.delete(e.label));
530
+ T = t.topColor || p.top, A = t.bottomColor || p.bottom;
531
+ if (t.data.length === 0) {
532
+ const g = C.current.get(t.label);
533
+ g && (o.removeSeries(g), C.current.delete(t.label));
456
534
  continue;
457
535
  }
458
- const be = (e.data.length > 0 ? Math.min(...e.data.map((h) => h.value)) : 0) < 0, O = e.data.some((h) => h.value === 0), Ke = !be && O, Ie = _ ? e.priceScaleId ?? (te === 0 ? "left" : "right") : $ || !S || te === 0 ? "right" : `scale-${te}`;
459
- S && ee.push({
460
- priceScaleId: Ie || "right",
461
- shouldPreventNegativeAxis: Ke,
462
- seriesIndex: te
536
+ const ve = (t.data.length > 0 ? Math.min(...t.data.map((g) => g.value)) : 0) < 0, J = t.data.some((g) => g.value === 0), Qe = !ve && J, Ee = D ? t.priceScaleId ?? (oe === 0 ? "left" : "right") : G || !y || oe === 0 ? "right" : `scale-${oe}`;
537
+ y && te.push({
538
+ priceScaleId: Ee || "right",
539
+ shouldPreventNegativeAxis: Qe,
540
+ seriesIndex: oe
463
541
  });
464
- const ze = ($ || !S) && l !== void 0 && typeof l == "number", Oe = oe.get(e.label) ?? [], Je = (h) => {
465
- const D = h();
466
- if (D?.priceRange) {
467
- ze && (D.priceRange.minValue = l);
468
- for (const E of Oe)
469
- E < D.priceRange.minValue && (D.priceRange.minValue = E), E > D.priceRange.maxValue && (D.priceRange.maxValue = E);
542
+ const We = (G || !y) && l !== void 0 && typeof l == "number", Ye = re.get(t.label) ?? [], Ue = (g) => {
543
+ const F = g();
544
+ if (F?.priceRange) {
545
+ We && (F.priceRange.minValue = l);
546
+ for (const X of Ye)
547
+ X < F.priceRange.minValue && (F.priceRange.minValue = X), X > F.priceRange.maxValue && (F.priceRange.maxValue = X);
470
548
  }
471
- return D;
472
- }, We = p.get(e.label) ?? u[0], $e = We.formatter, Qe = We.tickmarksFormatter, pe = {
473
- lineColor: L,
474
- topColor: V,
475
- bottomColor: z,
476
- priceScaleId: Ie,
477
- ...e.seriesType === "line" && {
478
- lineStyle: e.lineStyle ?? Ge.Solid
549
+ return F;
550
+ }, Ae = b.get(t.label) ?? h[0], $e = Ae.formatter, et = Ae.tickmarksFormatter, Se = {
551
+ lineColor: k,
552
+ topColor: T,
553
+ bottomColor: A,
554
+ priceScaleId: Ee,
555
+ ...t.seriesType === "line" && {
556
+ lineStyle: t.lineStyle ?? ee.Solid
479
557
  },
480
558
  priceFormat: {
481
559
  type: "custom",
482
560
  minMove: 0.01,
483
- formatter: ze && typeof l == "number" ? (h) => $e(
484
- h < l ? l : h
561
+ formatter: We && typeof l == "number" ? (g) => $e(
562
+ g < l ? l : g
485
563
  ) : $e,
486
- tickmarksFormatter: Qe
564
+ tickmarksFormatter: et
487
565
  },
488
- autoscaleInfoProvider: Je
489
- }, Ee = e.seriesType === "line";
490
- let F = v.current.get(e.label);
491
- const Y = e.data.map((h) => ({
492
- ...h,
493
- time: h.time
566
+ autoscaleInfoProvider: Ue
567
+ }, Ge = t.seriesType === "line";
568
+ let B = C.current.get(t.label);
569
+ const Y = t.data.map((g) => ({
570
+ ...g,
571
+ time: g.time
494
572
  }));
495
- if (Z !== void 0 && Y.length > 0 && Number(Y[0].time) > Z) {
496
- const h = Number(Y[0].time), D = h - Z, E = 86400, Ye = D > 180 * E ? 7 * E : D > 30 * E ? E : 6 * 3600, Ae = [];
497
- for (let ve = Z; ve < h; ve += Ye)
498
- Ae.push({ time: ve });
499
- Y.unshift(...Ae);
573
+ if (K !== void 0 && Y.length > 0 && Number(Y[0].time) > K) {
574
+ const g = Number(Y[0].time), F = g - K, X = 86400, tt = F > 180 * X ? 7 * X : F > 30 * X ? X : 6 * 3600, Xe = [];
575
+ for (let Ce = K; Ce < g; Ce += tt)
576
+ Xe.push({ time: Ce });
577
+ Y.unshift(...Xe);
500
578
  }
501
- F && F.seriesType() !== (Ee ? "Line" : "Area") && (t.removeSeries(F), v.current.delete(e.label), F = void 0), F ? (F.applyOptions(pe), F.setData(Y)) : (Ee ? F = t.addSeries(tt, {
579
+ B && B.seriesType() !== (Ge ? "Line" : "Area") && (o.removeSeries(B), C.current.delete(t.label), B = void 0), B ? (B.applyOptions(Se), B.setData(Y)) : (Ge ? B = o.addSeries(nt, {
502
580
  ...Q,
503
- ...pe
504
- }) : F = t.addSeries(ot, {
581
+ ...Se
582
+ }) : B = o.addSeries(lt, {
505
583
  ...Q,
506
- ...pe
507
- }), F.setData(Y), v.current.set(e.label, F)), te++;
584
+ ...Se
585
+ }), B.setData(Y), C.current.set(t.label, B)), oe++;
508
586
  }
509
- if (_)
587
+ if (D)
510
588
  try {
511
- const r = t.priceScale("left"), e = t.priceScale("right"), s = {
512
- visible: !R,
589
+ const r = o.priceScale("left"), t = o.priceScale("right"), p = {
590
+ visible: !V,
513
591
  autoScale: !0,
514
592
  scaleMargins: { top: 0.1, bottom: 0.1 },
515
593
  alignLabels: !0,
516
594
  borderVisible: !0,
517
595
  borderColor: "rgba(224, 227, 235, 0.1)",
518
596
  entireTextOnly: !1,
519
- textColor: M
597
+ textColor: R
520
598
  };
521
- r?.applyOptions(s), e?.applyOptions(s);
599
+ r?.applyOptions(p), t?.applyOptions(p);
522
600
  } catch {
523
601
  }
524
- else if (S && ee.length > 0)
525
- for (const r of ee)
602
+ else if (y && te.length > 0)
603
+ for (const r of te)
526
604
  try {
527
- const e = t.priceScale(r.priceScaleId);
528
- e && e.applyOptions({
605
+ const t = o.priceScale(r.priceScaleId);
606
+ t && t.applyOptions({
529
607
  visible: !1,
530
608
  autoScale: !0,
531
609
  scaleMargins: {
@@ -540,19 +618,19 @@ function Lt({
540
618
  borderVisible: !0,
541
619
  borderColor: "rgba(224, 227, 235, 0.1)",
542
620
  entireTextOnly: !1,
543
- textColor: M
621
+ textColor: R
544
622
  });
545
- } catch (e) {
623
+ } catch (t) {
546
624
  console.warn(
547
625
  `Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,
548
- e
626
+ t
549
627
  );
550
628
  }
551
- else if (!S)
629
+ else if (!y)
552
630
  try {
553
- const r = t.priceScale("right");
631
+ const r = o.priceScale("right");
554
632
  r && r.applyOptions({
555
- visible: !R,
633
+ visible: !V,
556
634
  autoScale: !0,
557
635
  scaleMargins: {
558
636
  top: 0.1,
@@ -566,326 +644,344 @@ function Lt({
566
644
  borderVisible: !0,
567
645
  borderColor: "rgba(224, 227, 235, 0.1)",
568
646
  entireTextOnly: !1,
569
- textColor: M
647
+ textColor: R
570
648
  });
571
649
  } catch {
572
650
  }
573
- if (l !== void 0 && !R && ($ || !S) && t.applyOptions({
651
+ if (l !== void 0 && !V && (G || !y) && o.applyOptions({
574
652
  handleScroll: {
575
653
  vertTouchDrag: !1
576
654
  }
577
- }), G.length > 0) {
578
- const r = G.map((e) => Number(e.time)).filter((e) => Number.isFinite(e));
655
+ }), H.length > 0) {
656
+ const r = H.map((t) => Number(t.time)).filter((t) => Number.isFinite(t));
579
657
  if (r.length > 0) {
580
- const e = Math.min(...r), s = Z !== void 0 ? Math.min(Z, e) : e, L = Math.max(...r);
581
- if (Number(s) <= Number(L))
658
+ const t = Math.min(...r), p = K !== void 0 ? Math.min(K, t) : t, k = Math.max(...r);
659
+ if (Number(p) <= Number(k))
582
660
  try {
583
- t.timeScale().setVisibleRange({ from: s, to: L });
661
+ o.timeScale().setVisibleRange({ from: p, to: k });
584
662
  } catch {
585
663
  try {
586
- t.timeScale().fitContent();
664
+ o.timeScale().fitContent();
587
665
  } catch {
588
666
  }
589
667
  }
590
668
  }
591
669
  }
592
- Re.current && (Re.current = !1);
593
- const me = /* @__PURE__ */ new Map();
594
- for (const r of o)
595
- r.data.length > 0 && me.set(r.label, r.data[r.data.length - 1]);
596
- de(me.size > 0 ? me : void 0);
670
+ Pe.current && (Pe.current = !1);
671
+ const be = /* @__PURE__ */ new Map();
672
+ for (const r of e)
673
+ r.data.length > 0 && be.set(r.label, r.data[r.data.length - 1]);
674
+ ge(be.size > 0 ? be : void 0);
597
675
  }, [
598
- o,
599
- G,
676
+ e,
677
+ H,
600
678
  d,
601
- w,
602
- R,
603
- $,
604
- _,
605
- we,
679
+ v,
680
+ V,
681
+ G,
682
+ D,
683
+ _e,
606
684
  Ne,
607
685
  Te,
608
686
  Ve,
609
- Z,
610
- k,
611
- A
612
- ]), W(() => {
613
- const t = I.current;
614
- if (!t || o.length === 0) return;
615
- const a = o.length === 1;
687
+ K,
688
+ M,
689
+ j
690
+ ]), $(() => {
691
+ const o = E.current;
692
+ if (!o || e.length === 0) return;
693
+ const s = e.length === 1;
616
694
  let l;
617
- for (const i of o)
695
+ for (const i of e)
618
696
  if (i.data.length > 0) {
619
697
  l = i.data[i.data.length - 1].time;
620
698
  break;
621
699
  }
622
700
  if (!l) return;
623
- const n = (i) => {
624
- const { time: f = l, seriesData: u, point: p } = i || {}, C = Array.from(v.current.values());
625
- if (!p || !f) {
626
- const N = /* @__PURE__ */ new Map();
627
- for (const m of o)
628
- m.data.length > 0 && N.set(m.label, m.data[m.data.length - 1]);
629
- if (de(N.size > 0 ? N : void 0), a || $ || fe)
630
- j(null);
631
- else if (C[0] && l) {
632
- const S = t.timeScale().timeToCoordinate(l), P = o[0];
633
- if (P.data.length > 0) {
634
- const M = P.data[P.data.length - 1].value, T = C[0].priceToCoordinate(M);
635
- S !== null && T !== null && j({ x: S, y: T });
701
+ const a = (i) => {
702
+ const { time: u = l, seriesData: h, point: b } = i || {}, S = Array.from(C.current.values());
703
+ if (!b || !u) {
704
+ const _ = /* @__PURE__ */ new Map();
705
+ for (const m of e)
706
+ m.data.length > 0 && _.set(m.label, m.data[m.data.length - 1]);
707
+ if (ge(_.size > 0 ? _ : void 0), s || G || de)
708
+ O(null);
709
+ else if (S[0] && l) {
710
+ const y = o.timeScale().timeToCoordinate(l), L = e[0];
711
+ if (L.data.length > 0) {
712
+ const R = L.data[L.data.length - 1].value, N = S[0].priceToCoordinate(R);
713
+ y !== null && N !== null && O({ x: y, y: N });
636
714
  }
637
715
  }
638
716
  return;
639
717
  }
640
- const H = /* @__PURE__ */ new Map();
641
- let B;
642
- for (let N = 0; N < o.length; N++) {
643
- const m = o[N], S = v.current.get(m.label);
644
- if (!S) continue;
645
- const P = u?.get(S), M = P && "value" in P ? P.value : void 0;
646
- let T;
647
- if (M !== void 0)
648
- T = M;
649
- else if (a) {
650
- const J = Number(f), Q = m.data.length > 0 ? Number(m.data[0].time) : Number.POSITIVE_INFINITY;
651
- J < Q ? T = Number.NaN : T = m.data[m.data.length - 1]?.value ?? 0;
652
- } else
653
- T = mt(m.data, Number(f));
654
- Number.isNaN(T) || (B === void 0 && (B = T), H.set(m.label, { value: T, time: f }));
718
+ const W = /* @__PURE__ */ new Map();
719
+ let P;
720
+ for (let _ = 0; _ < e.length; _++) {
721
+ const m = e[_], y = C.current.get(m.label);
722
+ if (!y) continue;
723
+ const L = h?.get(y), R = L && "value" in L ? L.value : void 0;
724
+ let N;
725
+ if (R !== void 0)
726
+ N = R;
727
+ else if (s) {
728
+ const q = Number(u), Q = m.data.length > 0 ? Number(m.data[0].time) : Number.POSITIVE_INFINITY;
729
+ q < Q ? N = Number.NaN : N = m.data[m.data.length - 1]?.value ?? 0;
730
+ } else {
731
+ const q = m.data.length > 0 ? Number(m.data[0].time) : Number.POSITIVE_INFINITY;
732
+ if (Number(u) < q) continue;
733
+ N = wt(m.data, Number(u));
734
+ }
735
+ Number.isNaN(N) || (P === void 0 && (P = N), W.set(m.label, { value: N, time: u }));
655
736
  }
656
- if (de(H), B !== void 0 && C[0]) {
657
- const m = t.timeScale().timeToCoordinate(f), S = C[0].priceToCoordinate(B);
658
- if (m !== null && S !== null) {
659
- const P = K.current;
660
- if (P) {
661
- const M = P.querySelector(
737
+ if (ge(W), P !== void 0 && S[0]) {
738
+ const m = o.timeScale().timeToCoordinate(u), y = S[0].priceToCoordinate(P);
739
+ if (m !== null && y !== null) {
740
+ const L = I.current;
741
+ if (L) {
742
+ const R = L.querySelector(
662
743
  ".LightweightChart"
663
744
  );
664
- if (M) {
665
- const T = M.getBoundingClientRect(), J = P.getBoundingClientRect(), Q = m + (T.left - J.left), ee = S + (T.top - J.top);
666
- j({ x: Q, y: ee });
745
+ if (R) {
746
+ const N = R.getBoundingClientRect(), q = L.getBoundingClientRect(), Q = m + (N.left - q.left), te = y + (N.top - q.top);
747
+ O({ x: Q, y: te });
667
748
  } else
668
- j({ x: m, y: S });
749
+ O({ x: m, y });
669
750
  } else
670
- j({ x: m, y: S });
751
+ O({ x: m, y });
671
752
  } else
672
- j(null);
753
+ O(null);
673
754
  } else
674
- j(null);
755
+ O(null);
675
756
  };
676
- return t.subscribeCrosshairMove(n), R && t.subscribeClick(n), !a && !$ && !fe && requestAnimationFrame(() => {
677
- const i = Array.from(v.current.values());
678
- if (i[0] && l && o[0]?.data.length > 0) {
679
- const u = t.timeScale().timeToCoordinate(l), p = o[0].data[o[0].data.length - 1].value, C = i[0].priceToCoordinate(p);
680
- u !== null && C !== null && j({ x: u, y: C });
757
+ return o.subscribeCrosshairMove(a), V && o.subscribeClick(a), !s && !G && !de && requestAnimationFrame(() => {
758
+ const i = Array.from(C.current.values());
759
+ if (i[0] && l && e[0]?.data.length > 0) {
760
+ const h = o.timeScale().timeToCoordinate(l), b = e[0].data[e[0].data.length - 1].value, S = i[0].priceToCoordinate(b);
761
+ h !== null && S !== null && O({ x: h, y: S });
681
762
  }
682
763
  }), () => {
683
- t.unsubscribeCrosshairMove(n), R && t.unsubscribeClick(n);
764
+ o.unsubscribeCrosshairMove(a), V && o.unsubscribeClick(a);
684
765
  };
685
- }, [o, $, R, fe]), W(() => {
686
- const t = I.current;
687
- if (!t || o.length === 0) return;
688
- const a = t.timeScale(), l = () => {
689
- const n = Pe.current;
690
- if (n.length === 0) return;
691
- const i = a.getVisibleRange();
766
+ }, [e, G, V, de]), $(() => {
767
+ const o = E.current;
768
+ if (!o || e.length === 0) return;
769
+ const s = o.timeScale(), l = () => {
770
+ const a = Le.current;
771
+ if (a.length === 0) return;
772
+ const i = s.getVisibleRange();
692
773
  if (!i) return;
693
- const f = Number(i.from), u = Number(i.to);
694
- for (const p of n) {
695
- const C = [];
696
- for (const H of o)
697
- if (p.labels.has(H.label))
698
- for (const B of H.data) {
699
- const N = Number(B.time);
700
- N >= f && N <= u && C.push(B.value);
774
+ const u = Number(i.from), h = Number(i.to);
775
+ for (const b of a) {
776
+ const S = [];
777
+ for (const W of e)
778
+ if (b.labels.has(W.label))
779
+ for (const P of W.data) {
780
+ const _ = Number(P.time);
781
+ _ >= u && _ <= h && S.push(P.value);
701
782
  }
702
- C.length > 0 && p.updateVisibleRange(C);
783
+ S.length > 0 && b.updateVisibleRange(S);
703
784
  }
704
785
  };
705
- return a.subscribeVisibleLogicalRangeChange(l), () => {
706
- a.unsubscribeVisibleLogicalRangeChange(
786
+ return s.subscribeVisibleLogicalRangeChange(l), () => {
787
+ s.unsubscribeVisibleLogicalRangeChange(
707
788
  l
708
789
  );
709
790
  };
710
- }, [o]), W(() => {
711
- const t = I.current, a = Array.from(v.current.values()), l = [];
712
- if (t && a.length > 0 && x) {
713
- const n = at(), i = a[0];
714
- for (const f of x) {
715
- const u = {
716
- ...n,
717
- ...f.options || {}
791
+ }, [e]), $(() => {
792
+ const o = E.current, s = Array.from(C.current.values()), l = [];
793
+ if (o && s.length > 0 && x) {
794
+ const a = ct(), i = s[0];
795
+ for (const u of x) {
796
+ const h = {
797
+ ...a,
798
+ ...u.options || {}
718
799
  };
719
- u.color && (u.color = U(u.color, u.color));
720
- const p = new ut(t, i, f.xCoordinate, u);
721
- i.attachPrimitive(p), l.push(p);
800
+ h.color && (h.color = U(h.color, h.color));
801
+ const b = new dt(o, i, u.xCoordinate, h);
802
+ i.attachPrimitive(b), l.push(b);
722
803
  }
723
804
  }
724
805
  return () => {
725
- if (a.length > 0) {
726
- const n = a[0];
806
+ if (s.length > 0) {
807
+ const a = s[0];
727
808
  for (const i of l)
728
- n.detachPrimitive(i);
809
+ a.detachPrimitive(i);
729
810
  }
730
811
  };
731
- }, [x, o]), W(() => {
732
- const t = [];
733
- if (k && k.length > 0) {
734
- const a = Array.from(v.current.values())[0], l = U(
812
+ }, [x, e]), $(() => {
813
+ const o = [], s = [];
814
+ if (M && M.length > 0) {
815
+ const l = Array.from(C.current.values())[0], a = U(
735
816
  "hsl(var(--destructive))",
736
817
  "rgb(239, 68, 68)"
737
818
  );
738
- for (const n of k) {
739
- if (!Number.isFinite(n.price)) continue;
740
- const i = n.seriesLabel ? v.current.get(n.seriesLabel) : a;
741
- if (!i) continue;
742
- const f = i.createPriceLine({
743
- price: n.price,
744
- color: n.color ? U(n.color, n.color) : l,
745
- lineWidth: n.lineWidth ?? 1,
746
- lineStyle: n.lineStyle ?? Ge.Dashed,
747
- axisLabelVisible: n.axisLabelVisible ?? !0,
748
- title: n.title ?? ""
819
+ for (const i of M) {
820
+ if (!Number.isFinite(i.price)) continue;
821
+ const u = i.seriesLabel ? C.current.get(i.seriesLabel) : l;
822
+ if (!u) continue;
823
+ const h = i.color ? U(i.color, i.color) : a, b = i.lineWidth ?? 1, S = i.lineStyle ?? ee.Dashed, W = u.createPriceLine({
824
+ price: i.price,
825
+ color: h,
826
+ lineWidth: b,
827
+ lineStyle: S,
828
+ axisLabelVisible: i.axisLabelVisible ?? !0,
829
+ title: i.title ?? ""
749
830
  });
750
- t.push({ series: i, line: f });
831
+ o.push({ series: u, line: W });
832
+ const P = new Ct(
833
+ u,
834
+ i.price,
835
+ h,
836
+ b,
837
+ S
838
+ );
839
+ u.attachPrimitive(P), s.push({ series: u, primitive: P });
751
840
  }
752
841
  }
753
842
  return () => {
754
- for (const { series: a, line: l } of t)
843
+ for (const { series: l, primitive: a } of s)
755
844
  try {
756
- a.removePriceLine(l);
845
+ l.detachPrimitive(a);
846
+ } catch {
847
+ }
848
+ for (const { series: l, line: a } of o)
849
+ try {
850
+ l.removePriceLine(a);
757
851
  } catch {
758
852
  }
759
853
  };
760
- }, [k, o]), W(() => {
761
- const t = [];
762
- if (A && A.length > 0) {
763
- const a = Array.from(v.current.values())[0], l = "rgba(239, 68, 68, 0.12)";
764
- for (const n of A) {
765
- const i = n.seriesLabel ? v.current.get(n.seriesLabel) : a;
854
+ }, [M, e]), $(() => {
855
+ const o = [];
856
+ if (j && j.length > 0) {
857
+ const s = Array.from(C.current.values())[0], l = "rgba(239, 68, 68, 0.12)";
858
+ for (const a of j) {
859
+ const i = a.seriesLabel ? C.current.get(a.seriesLabel) : s;
766
860
  if (!i) continue;
767
- const f = n.color ? U(n.color, l) : l, u = new gt(
861
+ const u = a.color ? U(a.color, l) : l, h = new gt(
768
862
  i,
769
- n.priceTop,
770
- n.priceBottom,
771
- f
863
+ a.priceTop,
864
+ a.priceBottom,
865
+ u
772
866
  );
773
- i.attachPrimitive(u), t.push({ series: i, zone: u });
867
+ i.attachPrimitive(h), o.push({ series: i, zone: h });
774
868
  }
775
869
  }
776
870
  return () => {
777
- for (const { series: a, zone: l } of t)
871
+ for (const { series: s, zone: l } of o)
778
872
  try {
779
- a.detachPrimitive(l);
873
+ s.detachPrimitive(l);
780
874
  } catch {
781
875
  }
782
876
  };
783
- }, [A, o]), W(() => {
784
- const t = I.current;
785
- if (!t || !x?.length) {
786
- _e([]);
877
+ }, [j, e]), $(() => {
878
+ const o = E.current;
879
+ if (!o || !x?.length) {
880
+ De([]);
787
881
  return;
788
882
  }
789
- const a = () => {
790
- const i = t.timeScale(), f = x.map((u) => i.timeToCoordinate(u.xCoordinate) ?? null);
791
- _e(f);
883
+ const s = () => {
884
+ const i = o.timeScale(), u = x.map((h) => i.timeToCoordinate(h.xCoordinate) ?? null);
885
+ De(u), I.current && Ie(I.current.clientWidth);
792
886
  };
793
- a();
794
- const l = t.timeScale(), n = () => {
795
- a();
887
+ s();
888
+ const l = o.timeScale(), a = () => {
889
+ s();
796
890
  };
797
- return l.subscribeVisibleLogicalRangeChange(n), () => {
798
- l.unsubscribeVisibleLogicalRangeChange(n);
891
+ return l.subscribeVisibleLogicalRangeChange(a), () => {
892
+ l.unsubscribeVisibleLogicalRangeChange(a);
799
893
  };
800
- }, [x, o]);
801
- const ie = o.length === 1, Be = Ce.useMemo(() => {
802
- if (ie && o.length > 0) {
803
- const t = o[0];
804
- if (t.data.length > 0)
805
- return t.data[t.data.length - 1];
894
+ }, [x, e]);
895
+ const se = e.length === 1, Be = ye.useMemo(() => {
896
+ if (se && e.length > 0) {
897
+ const o = e[0];
898
+ if (o.data.length > 0)
899
+ return o.data[o.data.length - 1];
806
900
  }
807
- }, [ie, o]);
808
- return /* @__PURE__ */ re(
901
+ }, [se, e]);
902
+ return /* @__PURE__ */ ne(
809
903
  "div",
810
904
  {
811
- ref: K,
812
- className: ne(
905
+ ref: I,
906
+ className: le(
813
907
  "relative z-[1] w-full h-full overflow-hidden p-0",
814
- c
908
+ n
815
909
  ),
816
910
  children: [
817
- ue != null && ue !== !1 && ie ? /* @__PURE__ */ y("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ y("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: ue }) }) : qe && ie && Be && /* @__PURE__ */ y(
818
- st,
911
+ he != null && he !== !1 && se ? /* @__PURE__ */ w("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ w("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: he }) }) : Ze && se && Be && /* @__PURE__ */ w(
912
+ ft,
819
913
  {
820
914
  point: Be,
821
915
  xMeasureUnit: d,
822
- yMeasureUnit: w,
823
- decimals: ce
916
+ yMeasureUnit: v,
917
+ decimals: fe
824
918
  }
825
919
  ),
826
- Me && ke && /* @__PURE__ */ y(
827
- ct,
920
+ Re && Me && /* @__PURE__ */ w(
921
+ ht,
828
922
  {
829
- points: Me,
923
+ points: Re,
830
924
  xMeasureUnit: d,
831
- yMeasureUnit: w,
832
- series: o,
833
- position: ke,
834
- containerRef: K,
835
- decimals: ce
925
+ yMeasureUnit: v,
926
+ series: e,
927
+ position: Me,
928
+ containerRef: I,
929
+ decimals: fe
836
930
  }
837
931
  ),
838
- g && /* @__PURE__ */ y(pt, { series: o, onUnselect: b }),
839
- x && x.length > 0 && Le.length === x.length && /* @__PURE__ */ y(
932
+ f && /* @__PURE__ */ w(Nt, { series: e, onUnselect: c }),
933
+ x && x.length > 0 && ke.length === x.length && /* @__PURE__ */ w(
840
934
  "div",
841
935
  {
842
936
  className: "absolute inset-0 z-[5] pointer-events-none",
843
937
  "aria-hidden": !0,
844
- children: x.map((t, a) => {
845
- const l = Le[a], n = t.options ?? {}, i = n.showLabel !== !1;
938
+ children: x.map((o, s) => {
939
+ const l = ke[s], a = o.options ?? {}, i = a.showLabel !== !1;
846
940
  if (l === null || !i) return null;
847
- const { labelText: f, valueStr: u } = dt(
848
- n,
849
- w,
850
- ce
851
- ), p = n.tooltipText ?? "";
852
- if (!(f || u || p)) return null;
853
- const H = n.labelBackgroundColor ?? n.color ?? "hsl(var(--background))", B = n.labelTextColor ?? "hsl(var(--foreground))", N = `${String(t.xCoordinate)}-${f}-${p}`;
854
- return /* @__PURE__ */ re(
941
+ const { labelText: u, valueStr: h } = yt(
942
+ a,
943
+ v,
944
+ fe
945
+ ), b = a.tooltipText ?? "";
946
+ if (!(u || h || b)) return null;
947
+ const W = a.labelBackgroundColor ?? a.color ?? "hsl(var(--background))", P = a.labelTextColor ?? "hsl(var(--foreground))", _ = `${String(o.xCoordinate)}-${u}-${b}`, m = xt(
948
+ l,
949
+ Je
950
+ );
951
+ return /* @__PURE__ */ ne(
855
952
  "div",
856
953
  {
857
- className: ne(
954
+ className: le(
858
955
  "group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
859
- p && "pointer-events-auto cursor-default"
956
+ b && "pointer-events-auto cursor-default"
860
957
  ),
861
958
  style: {
862
- left: l,
863
- transform: "translateX(-50%)",
864
- backgroundColor: H,
865
- color: B
959
+ ...m,
960
+ backgroundColor: W,
961
+ color: P
866
962
  },
867
963
  children: [
868
- f && /* @__PURE__ */ y("span", { className: "block", children: f }),
869
- u && /* @__PURE__ */ y("span", { className: ne("block", f && "mt-0.5"), children: u }),
870
- p && /* @__PURE__ */ y(
964
+ u && /* @__PURE__ */ w("span", { className: "block", children: u }),
965
+ h && /* @__PURE__ */ w("span", { className: le("block", u && "mt-0.5"), children: h }),
966
+ b && /* @__PURE__ */ w(
871
967
  "span",
872
968
  {
873
969
  className: "pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",
874
970
  role: "tooltip",
875
- children: p
971
+ children: b
876
972
  }
877
973
  )
878
974
  ]
879
975
  },
880
- N
976
+ _
881
977
  );
882
978
  })
883
979
  }
884
980
  ),
885
- /* @__PURE__ */ y(
981
+ /* @__PURE__ */ w(
886
982
  "div",
887
983
  {
888
- ref: ge,
984
+ ref: me,
889
985
  className: "LightweightChart w-full h-full overflow-hidden"
890
986
  }
891
987
  )
@@ -893,49 +989,49 @@ function Lt({
893
989
  }
894
990
  );
895
991
  }
896
- function pt({
897
- series: o,
898
- onUnselect: c,
899
- inline: g = !1
992
+ function Nt({
993
+ series: e,
994
+ onUnselect: n,
995
+ inline: f = !1
900
996
  }) {
901
- return /* @__PURE__ */ y(
997
+ return /* @__PURE__ */ w(
902
998
  "div",
903
999
  {
904
- className: ne(
1000
+ className: le(
905
1001
  "flex flex-wrap gap-2",
906
- g ? "items-center" : "absolute top-0 left-2 z-[10]"
1002
+ f ? "items-center" : "absolute top-0 left-2 z-[10]"
907
1003
  ),
908
- children: o.map((b, d) => {
909
- const w = Xe(d), q = (b.lineColor ?? b.color) || w.line, x = b.data.length === 0;
910
- return /* @__PURE__ */ re(
1004
+ children: e.map((c, d) => {
1005
+ const v = qe(d), z = (c.lineColor ?? c.color) || v.line, x = c.data.length === 0;
1006
+ return /* @__PURE__ */ ne(
911
1007
  "div",
912
1008
  {
913
- className: ne(
1009
+ className: le(
914
1010
  "flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
915
1011
  x && "opacity-50"
916
1012
  ),
917
1013
  children: [
918
- /* @__PURE__ */ y(
1014
+ /* @__PURE__ */ w(
919
1015
  "div",
920
1016
  {
921
1017
  className: "w-3 h-3 rounded-sm",
922
- style: { backgroundColor: q }
1018
+ style: { backgroundColor: z }
923
1019
  }
924
1020
  ),
925
- /* @__PURE__ */ re("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
926
- b.label,
1021
+ /* @__PURE__ */ ne("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
1022
+ c.label,
927
1023
  x && " (no data)"
928
1024
  ] }),
929
- c && /* @__PURE__ */ y(
1025
+ n && /* @__PURE__ */ w(
930
1026
  "button",
931
1027
  {
932
1028
  type: "button",
933
- onClick: (k) => {
934
- k.stopPropagation(), c(b.label);
1029
+ onClick: (M) => {
1030
+ M.stopPropagation(), n(c.label);
935
1031
  },
936
1032
  className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
937
- "aria-label": `Remove ${b.label}`,
938
- children: /* @__PURE__ */ re(
1033
+ "aria-label": `Remove ${c.label}`,
1034
+ children: /* @__PURE__ */ ne(
939
1035
  "svg",
940
1036
  {
941
1037
  xmlns: "http://www.w3.org/2000/svg",
@@ -950,9 +1046,9 @@ function pt({
950
1046
  className: "text-muted-foreground hover:text-foreground",
951
1047
  "aria-hidden": "true",
952
1048
  children: [
953
- /* @__PURE__ */ y("title", { children: "Close" }),
954
- /* @__PURE__ */ y("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
955
- /* @__PURE__ */ y("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1049
+ /* @__PURE__ */ w("title", { children: "Close" }),
1050
+ /* @__PURE__ */ w("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1051
+ /* @__PURE__ */ w("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
956
1052
  ]
957
1053
  }
958
1054
  )
@@ -960,17 +1056,19 @@ function pt({
960
1056
  )
961
1057
  ]
962
1058
  },
963
- b.label
1059
+ c.label
964
1060
  );
965
1061
  })
966
1062
  }
967
1063
  );
968
1064
  }
969
1065
  export {
970
- ye as DEFAULT_SERIES_COLORS,
971
- Lt as Graph,
972
- pt as GraphLegend,
973
- Xe as getSeriesColorPalette,
974
- mt as getStepForwardValue,
975
- dt as getVerticalLineTooltipContent
1066
+ we as DEFAULT_SERIES_COLORS,
1067
+ Wt as Graph,
1068
+ Nt as GraphLegend,
1069
+ Oe as VERTICAL_LINE_LABEL_EDGE_PADDING,
1070
+ qe as getSeriesColorPalette,
1071
+ wt as getStepForwardValue,
1072
+ xt as getVerticalLineLabelStyle,
1073
+ yt as getVerticalLineTooltipContent
976
1074
  };