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