@gearbox-protocol/ui-kit 4.0.0-next.22 → 4.0.0-next.24

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