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

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