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