@lilt-ui/charts 0.1.0 → 0.2.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +75 -0
  3. package/dist/analysis-BJRmXHOB.js +62 -0
  4. package/dist/cards/box-plot-card.d.ts +30 -0
  5. package/dist/cards/cartesian-card.d.ts +54 -3
  6. package/dist/cards/range-chart-card.d.ts +28 -0
  7. package/dist/cartesian-card-BDZs0v6E.js +7235 -0
  8. package/dist/chart-context.d.ts +18 -0
  9. package/dist/chart-data-CCwLQeXa.js +44 -0
  10. package/dist/chart.d.ts +3 -1
  11. package/dist/data.js +3 -2
  12. package/dist/engine/box.d.ts +18 -0
  13. package/dist/engine/domains.d.ts +2 -0
  14. package/dist/engine/geometry.d.ts +2 -1
  15. package/dist/engine/normalize.d.ts +2 -4
  16. package/dist/engine/ranges.d.ts +59 -0
  17. package/dist/finance/candle-geometry.d.ts +55 -0
  18. package/dist/finance/candles.d.ts +18 -0
  19. package/dist/finance/cards/candlestick-chart-card.d.ts +41 -0
  20. package/dist/finance/cards/depth-chart-card.d.ts +32 -0
  21. package/dist/finance/cards/indicator-chart-card.d.ts +52 -0
  22. package/dist/finance/cards/pane.d.ts +24 -0
  23. package/dist/finance/cards/portfolio-chart-card.d.ts +22 -0
  24. package/dist/finance/cards/price-chart-card.d.ts +27 -0
  25. package/dist/finance/index.d.ts +17 -0
  26. package/dist/finance/indicators.d.ts +65 -0
  27. package/dist/finance/order-book.d.ts +26 -0
  28. package/dist/finance.d.ts +2 -0
  29. package/dist/finance.js +1157 -0
  30. package/dist/index.d.ts +10 -1
  31. package/dist/index.js +2235 -8793
  32. package/dist/interaction/field-values.d.ts +12 -0
  33. package/dist/interaction/inspection-layer.d.ts +4 -1
  34. package/dist/marks/contract.d.ts +49 -0
  35. package/dist/marks/use-range-mark.d.ts +19 -0
  36. package/dist/primitives/annotations.d.ts +1 -1
  37. package/dist/primitives/box-plot.d.ts +4 -0
  38. package/dist/primitives/error-bar.d.ts +4 -0
  39. package/dist/primitives/interval-band.d.ts +2 -2
  40. package/dist/primitives/range-bar.d.ts +4 -0
  41. package/dist/styles.css +1 -1
  42. package/dist/types.d.ts +80 -13
  43. package/package.json +11 -2
  44. package/dist/analysis-BLLWEKBw.js +0 -105
@@ -0,0 +1,1157 @@
1
+ "use client";
2
+ import { A as e, B as t, C as n, D as r, E as i, I as a, J as o, N as s, O as c, R as l, S as u, T as d, V as f, Z as p, b as m, d as h, g, h as _, i as v, k as y, ot as b, p as x, r as S, t as C, u as w, v as T, w as E, z as D } from "./cartesian-card-BDZs0v6E.js";
3
+ import { useEffect as O, useMemo as k, useRef as A, useState as j } from "react";
4
+ import { Fragment as M, jsx as N, jsxs as P } from "react/jsx-runtime";
5
+ //#region src/finance/candle-geometry.ts
6
+ var F = "var(--lilt-candle-up)", I = "var(--lilt-candle-down)";
7
+ function L(e) {
8
+ return Math.round(e * 100) / 100;
9
+ }
10
+ function R(e, t, n) {
11
+ let r = e.fields[t], i = r?.[n.open], a = r?.[n.high], o = r?.[n.low], s = e.values[t];
12
+ return i == null || a == null || o == null || s == null ? null : {
13
+ open: i,
14
+ high: a,
15
+ low: o,
16
+ close: s,
17
+ up: s >= i
18
+ };
19
+ }
20
+ function z(e, t, n) {
21
+ for (let r of e) {
22
+ let e = R(r, t, n);
23
+ if (!e) continue;
24
+ let i = Math.max(e.open, e.close), a = Math.min(e.open, e.close);
25
+ if (e.high < i || e.low > a) throw Error(`Lilt Candles on series "${t}" expects low ≤ open, close ≤ high at row ${r.sourceIndex + 1}.`);
26
+ }
27
+ }
28
+ function B(e, t, n, r) {
29
+ let i = Math.max(1, n.columnWidth), o = i / 2, s = L(e), c = L(n.y(t.high)), l = L(n.y(t.low));
30
+ if (r === "ohlc") {
31
+ let r = L(n.y(t.open)), i = L(n.y(t.close)), a = L(Math.max(2, o));
32
+ return {
33
+ body: null,
34
+ hollow: null,
35
+ stroke: `M${s},${c}V${l}M${L(e - a)},${r}H${s}M${s},${i}H${L(e + a)}`
36
+ };
37
+ }
38
+ let u = n.y(Math.max(t.open, t.close)), d = n.y(Math.min(t.open, t.close));
39
+ if (d - u < 1) {
40
+ let e = (u + d) / 2;
41
+ u = e - .5, d = e + .5;
42
+ }
43
+ let f = r === "hollow" && t.up && i >= 3, p = f ? .5 : 0, m = a(e - o + p, u + p, Math.max(1, i - p * 2), Math.max(1, d - u - p * 2), i >= 6 ? 1.5 : 0), h = (c < u ? `M${s},${c}V${L(u)}` : "") + (l > d ? `M${s},${L(d)}V${l}` : "");
44
+ return {
45
+ body: f ? null : m,
46
+ hollow: f ? m : null,
47
+ stroke: h
48
+ };
49
+ }
50
+ function V(t, n, r, i, a, o) {
51
+ let c = new e(), l = new e(), u = new e();
52
+ for (let { row: e, cx: d } of s(t, i)) {
53
+ let t = R(e, n, r);
54
+ if (!t) continue;
55
+ let s = o(e, t), f = B(d, t, i, a);
56
+ f.body && c.add(s, f.body), f.hollow && l.add(s, f.hollow), f.stroke && u.add(s, f.stroke);
57
+ }
58
+ return {
59
+ bodies: c.entries(),
60
+ hollow: l.entries(),
61
+ strokes: u.entries()
62
+ };
63
+ }
64
+ //#endregion
65
+ //#region src/finance/candles.tsx
66
+ function H(e, t, n) {
67
+ return f(e, t, n.up ? F : I);
68
+ }
69
+ function U({ paths: e, display: t }) {
70
+ let n = t === "ohlc" ? 1.5 : 1;
71
+ return /* @__PURE__ */ P(M, { children: [
72
+ e.strokes.map(({ color: e, d: r }) => /* @__PURE__ */ N("path", {
73
+ d: r,
74
+ fill: "none",
75
+ strokeWidth: n,
76
+ strokeLinecap: t === "ohlc" ? "round" : "butt",
77
+ style: { stroke: e }
78
+ }, `stroke-${e}`)),
79
+ e.bodies.map(({ color: e, d: t }) => /* @__PURE__ */ N("path", {
80
+ d: t,
81
+ style: { fill: e }
82
+ }, `body-${e}`)),
83
+ e.hollow.map(({ color: e, d: t }) => /* @__PURE__ */ N("path", {
84
+ d: t,
85
+ strokeWidth: 1,
86
+ style: {
87
+ fill: "var(--lilt-surface)",
88
+ stroke: e
89
+ }
90
+ }, `hollow-${e}`))
91
+ ] });
92
+ }
93
+ var W = t(function({ series: e, open: t, high: n, low: r, display: i = "candle", className: a }) {
94
+ let o = y("Candles", e, [
95
+ t,
96
+ n,
97
+ r
98
+ ], "column"), { snapshot: s, descriptor: c, scales: l } = o, u = k(() => {
99
+ let a = {
100
+ open: t,
101
+ high: n,
102
+ low: r
103
+ };
104
+ return z(s.data.rows, e, a), V(s.data.rows, e, a, l, i, (e, t) => H(c, e, t));
105
+ }, [
106
+ s,
107
+ e,
108
+ t,
109
+ n,
110
+ r,
111
+ l,
112
+ i,
113
+ c
114
+ ]);
115
+ return /* @__PURE__ */ N("g", {
116
+ "aria-hidden": "true",
117
+ className: ["lilt-chart__candles", a].filter(Boolean).join(" "),
118
+ "data-series": e,
119
+ "data-display": i,
120
+ clipPath: o.clipPath,
121
+ mask: o.mask,
122
+ style: {
123
+ opacity: o.opacity,
124
+ transition: o.reducedMotion ? void 0 : "opacity 160ms ease-out"
125
+ },
126
+ children: /* @__PURE__ */ N(U, {
127
+ paths: u,
128
+ display: i
129
+ })
130
+ });
131
+ }, {
132
+ layout: "column",
133
+ series: (e) => e.series,
134
+ fields: (e) => [
135
+ e.open,
136
+ e.high,
137
+ e.low
138
+ ],
139
+ highlight: (e, { row: t, snapshot: n, descriptor: r }) => {
140
+ let i = R(t, e.series, e);
141
+ if (!i) return null;
142
+ let a = e.display ?? "candle", o = c(n, e.series), s = B(o.x(t.x), i, o, a), l = H(r, t, i);
143
+ return /* @__PURE__ */ N("g", {
144
+ className: "lilt-chart__candle-highlight",
145
+ children: /* @__PURE__ */ N(U, {
146
+ display: a,
147
+ paths: {
148
+ bodies: s.body ? [{
149
+ color: l,
150
+ d: s.body
151
+ }] : [],
152
+ hollow: s.hollow ? [{
153
+ color: l,
154
+ d: s.hollow
155
+ }] : [],
156
+ strokes: s.stroke ? [{
157
+ color: l,
158
+ d: s.stroke
159
+ }] : []
160
+ }
161
+ })
162
+ });
163
+ }
164
+ });
165
+ //#endregion
166
+ //#region src/finance/cards/pane.tsx
167
+ function G({ context: e, label: t, caption: n, readout: r, series: i, height: a, y: o, bars: s, xAxis: c = !1, children: l }) {
168
+ let [d, f] = j(null), p = d ?? e.data.at(-1) ?? null;
169
+ return /* @__PURE__ */ P("div", {
170
+ className: "lilt-card__pane",
171
+ children: [n ? /* @__PURE__ */ P("span", {
172
+ className: "lilt-card__pane-caption",
173
+ "aria-hidden": "true",
174
+ children: [/* @__PURE__ */ N("span", {
175
+ className: "lilt-card__pane-name",
176
+ children: n
177
+ }), r && p && !e.loading ? r(p) : null]
178
+ }) : null, /* @__PURE__ */ N(b, {
179
+ className: "lilt-card__chart",
180
+ "aria-label": t,
181
+ data: e.data,
182
+ x: e.x,
183
+ y: o,
184
+ series: i,
185
+ controller: e.controller,
186
+ onSelectionChange: r ? (e) => f(e?.row ?? null) : void 0,
187
+ motion: e.motion,
188
+ status: e.loading ? "loading" : "ready",
189
+ children: /* @__PURE__ */ P(D, {
190
+ height: a,
191
+ margins: {
192
+ ...e.margins,
193
+ top: 6,
194
+ bottom: c ? 28 : 4
195
+ },
196
+ axis: e.axis,
197
+ pill: e.hoverStyle,
198
+ axisInset: e.axisInset,
199
+ slots: e.slots || !!s,
200
+ bars: s,
201
+ background: "none",
202
+ children: [l, c ? /* @__PURE__ */ N(u, { labels: "fit" }) : null]
203
+ })
204
+ })]
205
+ });
206
+ }
207
+ //#endregion
208
+ //#region src/finance/cards/candlestick-chart-card.tsx
209
+ function K(e, t) {
210
+ let n = e[t];
211
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
212
+ }
213
+ function q(e, t, n) {
214
+ let r = e.length ? K(e[0], t) : null, i = e.length ? K(e.at(-1), n) : null;
215
+ return r && i !== null ? i / r - 1 : void 0;
216
+ }
217
+ function ee(e) {
218
+ return (t) => {
219
+ let n = t.series[0]?.fields;
220
+ return !n?.length || n.some((e) => e.value === null) ? null : n.map((t) => `${t.label[0]} ${e(t.value)}`).join(" ");
221
+ };
222
+ }
223
+ var te = {
224
+ minimumFractionDigits: 2,
225
+ maximumFractionDigits: 2
226
+ };
227
+ function ne({ open: e, high: t, low: n, close: r, volume: a, display: o = "candle", scale: s = "linear", label: c = "Price", live: u = !1, data: f, ranges: p, delta: m, valueFormat: h = te, locale: g = "en-US", volumeHeight: _ = 64, ...v }) {
228
+ let y = k(() => S(g, h).full, [g, JSON.stringify(h)]), b = k(() => S(g).compact, [g]), x = k(() => p?.map((t) => ({
229
+ ...t,
230
+ delta: t.delta ?? q(t.data, e, r)
231
+ })), [
232
+ p,
233
+ e,
234
+ r
235
+ ]), w = (q(f ?? p?.[0]?.data ?? [], e, r) ?? 0) >= 0, T = (t) => (K(t, r) ?? 0) >= (K(t, e) ?? 0), E = o === "area", D = {
236
+ open: {
237
+ label: "Open",
238
+ accessor: (t) => K(t, e)
239
+ },
240
+ high: {
241
+ label: "High",
242
+ accessor: (e) => K(e, t)
243
+ },
244
+ low: {
245
+ label: "Low",
246
+ accessor: (e) => K(e, n)
247
+ }
248
+ };
249
+ return /* @__PURE__ */ N(C, {
250
+ ...v,
251
+ data: f,
252
+ ranges: x,
253
+ delta: m ?? (f ? q(f, e, r) : void 0),
254
+ valueFormat: h,
255
+ locale: g,
256
+ aggregate: "last",
257
+ tiles: !1,
258
+ live: u,
259
+ series: [{
260
+ key: r,
261
+ label: c,
262
+ color: E ? w ? F : I : void 0
263
+ }],
264
+ shape: {
265
+ kind: "marks",
266
+ id: `candles:${o}:${s}:${e}:${t}:${n}:${!!a}`,
267
+ includeZero: !1,
268
+ scale: s,
269
+ slots: !0,
270
+ xAxis: !a,
271
+ series: () => E ? {
272
+ fields: D,
273
+ area: { treatment: "fade" },
274
+ curve: "linear"
275
+ } : {
276
+ fields: D,
277
+ line: { showInspectionPoint: !1 }
278
+ },
279
+ describe: ee(y),
280
+ draw: (e) => e.map((e) => E ? [/* @__PURE__ */ N(l, { series: e }, `area-${e}`), /* @__PURE__ */ N(i, { series: e }, `line-${e}`)] : /* @__PURE__ */ N(W, {
281
+ series: e,
282
+ open: "open",
283
+ high: "high",
284
+ low: "low",
285
+ display: o
286
+ }, e))
287
+ },
288
+ panes: a ? (e) => /* @__PURE__ */ N(G, {
289
+ context: e,
290
+ label: `${v.title} volume`,
291
+ caption: "Volume",
292
+ height: _,
293
+ xAxis: !0,
294
+ y: {
295
+ includeZero: !0,
296
+ ticks: 2,
297
+ format: b
298
+ },
299
+ bars: { series: ["volume"] },
300
+ series: [{
301
+ id: "volume",
302
+ label: "Volume",
303
+ accessor: (e) => K(e, a),
304
+ formatValue: b,
305
+ colorAt: (e) => T(e) ? "color-mix(in srgb, var(--lilt-candle-up) 42%, transparent)" : "color-mix(in srgb, var(--lilt-candle-down) 42%, transparent)",
306
+ bar: { radius: 1 }
307
+ }],
308
+ children: /* @__PURE__ */ N(d, { series: "volume" })
309
+ }) : void 0
310
+ });
311
+ }
312
+ //#endregion
313
+ //#region src/finance/indicators.ts
314
+ function J(e) {
315
+ return typeof e == "number" && Number.isFinite(e);
316
+ }
317
+ function Y(e, t) {
318
+ if (!Number.isInteger(t) || t < 1) throw Error(`Lilt ${e} period must be a positive integer; received ${t}.`);
319
+ }
320
+ function X(e, t) {
321
+ Y("sma", t);
322
+ let n = [], r = 0, i = 0;
323
+ for (let a = 0; a < e.length; a += 1) {
324
+ let o = e[a];
325
+ J(o) && (r += o, i += 1);
326
+ let s = a - t >= 0 ? e[a - t] : void 0;
327
+ a - t >= 0 && J(s) && (r -= s, --i), n.push(a >= t - 1 && i === t ? r / t : null);
328
+ }
329
+ return n;
330
+ }
331
+ function Z(e, t) {
332
+ Y("ema", t);
333
+ let n = 2 / (t + 1), r = [], i = null, a = [];
334
+ for (let o of e) {
335
+ if (!J(o)) {
336
+ r.push(null);
337
+ continue;
338
+ }
339
+ if (i === null) {
340
+ a.push(o), a.length === t && (i = a.reduce((e, t) => e + t, 0) / t), r.push(i);
341
+ continue;
342
+ }
343
+ i = o * n + i * (1 - n), r.push(i);
344
+ }
345
+ return r;
346
+ }
347
+ function re(e, t = 14) {
348
+ Y("rsi", t);
349
+ let n = e.map(() => null), r = null, i = 0, a = 0, o = 0, s = 0, c = 0;
350
+ return e.forEach((e, l) => {
351
+ if (!J(e)) return;
352
+ if (r === null) {
353
+ r = e;
354
+ return;
355
+ }
356
+ let u = e - r;
357
+ r = e;
358
+ let d = Math.max(0, u), f = Math.max(0, -u);
359
+ if (o += 1, o <= t) {
360
+ if (i += d, a += f, o < t) return;
361
+ s = i / t, c = a / t;
362
+ } else s = (s * (t - 1) + d) / t, c = (c * (t - 1) + f) / t;
363
+ n[l] = c === 0 ? s === 0 ? 50 : 100 : 100 - 100 / (1 + s / c);
364
+ }), n;
365
+ }
366
+ function ie(e, t = 12, n = 26, r = 9) {
367
+ if (t >= n) throw Error("Lilt macd needs a fast period shorter than the slow period.");
368
+ let i = Z(e, t), a = Z(e, n), o = e.map((e, t) => {
369
+ let n = i[t], r = a[t];
370
+ return n === null || r === null ? null : n - r;
371
+ }), s = Z(o, r);
372
+ return {
373
+ macd: o,
374
+ signal: s,
375
+ histogram: o.map((e, t) => {
376
+ let n = s[t];
377
+ return e === null || n === null ? null : e - n;
378
+ })
379
+ };
380
+ }
381
+ function ae(e, t = 20, n = 2) {
382
+ let r = X(e, t), i = [], a = [];
383
+ return r.forEach((r, o) => {
384
+ if (r === null) {
385
+ i.push(null), a.push(null);
386
+ return;
387
+ }
388
+ let s = 0;
389
+ for (let n = o - t + 1; n <= o; n += 1) s += (e[n] - r) ** 2;
390
+ let c = Math.sqrt(s / t) * n;
391
+ i.push(r + c), a.push(r - c);
392
+ }), {
393
+ middle: r,
394
+ upper: i,
395
+ lower: a
396
+ };
397
+ }
398
+ function oe(e) {
399
+ let t = -Infinity;
400
+ return e.map((e) => J(e) ? (t = Math.max(t, e), t > 0 ? e / t - 1 : 0) : null);
401
+ }
402
+ function se(e) {
403
+ let t = e.find(J);
404
+ return e.map((e) => J(e) && t !== void 0 && t !== 0 ? e / t - 1 : null);
405
+ }
406
+ function ce(e, t) {
407
+ for (let n of t) if (!J(n.price) || !J(n.size) || n.size < 0) throw Error(`Lilt order book ${e} need finite prices and non-negative sizes; received ${n.price} × ${n.size}.`);
408
+ }
409
+ function le(e, t) {
410
+ ce("bids", e), ce("asks", t);
411
+ let n = (e) => {
412
+ let t = /* @__PURE__ */ new Map();
413
+ for (let n of e) t.set(n.price, (t.get(n.price) ?? 0) + n.size);
414
+ return [...t].map(([e, t]) => ({
415
+ price: e,
416
+ size: t
417
+ }));
418
+ }, r = n(e).sort((e, t) => t.price - e.price), i = n(t).sort((e, t) => e.price - t.price), a = r[0]?.price ?? null, o = i[0]?.price ?? null;
419
+ if (a !== null && o !== null && a >= o) throw Error(`Lilt order book is crossed: best bid ${a} ≥ best ask ${o}.`);
420
+ let s = 0, c = r.map((e) => (s += e.size, {
421
+ price: e.price,
422
+ bid: s,
423
+ ask: null,
424
+ size: e.size,
425
+ side: "bid"
426
+ })), l = 0, u = i.map((e) => (l += e.size, {
427
+ price: e.price,
428
+ bid: null,
429
+ ask: l,
430
+ size: e.size,
431
+ side: "ask"
432
+ }));
433
+ return {
434
+ levels: [...c.reverse(), ...u],
435
+ bestBid: a,
436
+ bestAsk: o,
437
+ mid: a !== null && o !== null ? (a + o) / 2 : null,
438
+ spread: a !== null && o !== null ? o - a : null,
439
+ bidDepth: s,
440
+ askDepth: l
441
+ };
442
+ }
443
+ //#endregion
444
+ //#region src/finance/cards/indicator-chart-card.tsx
445
+ function ue(e) {
446
+ return e.map((e, t) => {
447
+ let n = typeof e == "string" ? { kind: e } : e, r = "period" in n && n.period !== void 0 ? n.period : (n.kind, 20), i = "deviations" in n && n.deviations !== void 0 ? n.deviations : 2, a = n.kind === "bollinger" ? "BB" : n.kind.toUpperCase();
448
+ return {
449
+ id: `__overlay${t}`,
450
+ label: `${a} ${r}`,
451
+ kind: n.kind,
452
+ period: r,
453
+ deviations: i
454
+ };
455
+ });
456
+ }
457
+ function de(e) {
458
+ return e.map((e, t) => {
459
+ let n = typeof e == "string" ? { kind: e } : e;
460
+ return {
461
+ kind: n.kind,
462
+ id: `__pane${t}`,
463
+ period: "period" in n && n.period !== void 0 ? n.period : 14,
464
+ fast: "fast" in n && n.fast !== void 0 ? n.fast : 12,
465
+ slow: "slow" in n && n.slow !== void 0 ? n.slow : 26,
466
+ signal: "signal" in n && n.signal !== void 0 ? n.signal : 9
467
+ };
468
+ });
469
+ }
470
+ function Q(e, t) {
471
+ if (!t) return null;
472
+ let n = e[t];
473
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
474
+ }
475
+ function fe(e, t, n, r) {
476
+ let i = e.map((e) => Q(e, t)), a = e.map((e) => ({ ...e })), o = (e, t) => t.forEach((t, n) => a[n][e] = t);
477
+ for (let e of n) if (e.kind === "bollinger") {
478
+ let t = ae(i, e.period, e.deviations);
479
+ o(e.id, t.middle), o(`${e.id}Upper`, t.upper), o(`${e.id}Lower`, t.lower);
480
+ } else o(e.id, (e.kind === "sma" ? X : Z)(i, e.period));
481
+ for (let e of r) if (e.kind === "rsi" && o(e.id, re(i, e.period)), e.kind === "macd") {
482
+ let t = ie(i, e.fast, e.slow, e.signal);
483
+ o(`${e.id}Macd`, t.macd), o(`${e.id}Signal`, t.signal), o(`${e.id}Histogram`, t.histogram);
484
+ }
485
+ return a;
486
+ }
487
+ var pe = {
488
+ minimumFractionDigits: 2,
489
+ maximumFractionDigits: 2
490
+ }, me = [
491
+ "var(--lilt-series-4)",
492
+ "var(--lilt-series-3)",
493
+ "var(--lilt-series-5)"
494
+ ];
495
+ function he({ close: e, open: t, high: n, low: a, volume: o, display: s, overlays: c = [], panes: l = ["rsi", "macd"], label: u = "Price", scale: f = "linear", live: p = !1, data: h, ranges: g, delta: _, valueFormat: v = pe, locale: y = "en-US", paneHeight: b = 72, ...x }) {
496
+ let w = !!(t && n && a), E = s ?? (w ? "candle" : "line");
497
+ if (E !== "line" && !w) throw Error("Lilt IndicatorChartCard candles need open, high and low fields.");
498
+ let D = JSON.stringify(c), O = JSON.stringify(l), A = k(() => ue(c), [D]), j = k(() => de(l), [O]);
499
+ if (j.some((e) => e.kind === "volume") && !o) throw Error("Lilt IndicatorChartCard needs a `volume` field for a volume pane.");
500
+ let L = k(() => h ? fe(h, e, A, j) : void 0, [
501
+ h,
502
+ e,
503
+ A,
504
+ j
505
+ ]), R = k(() => g?.map((n) => ({
506
+ ...n,
507
+ data: fe(n.data, e, A, j),
508
+ delta: n.delta ?? (t ? q(n.data, t, e) : void 0)
509
+ })), [
510
+ g,
511
+ e,
512
+ t,
513
+ A,
514
+ j
515
+ ]), z = k(() => S(y, v).full, [y, JSON.stringify(v)]), B = k(() => S(y, { maximumFractionDigits: 2 }).full, [y]), V = k(() => S(y).compact, [y]), H = w ? {
516
+ open: {
517
+ label: "Open",
518
+ accessor: (e) => Q(e, t)
519
+ },
520
+ high: {
521
+ label: "High",
522
+ accessor: (e) => Q(e, n)
523
+ },
524
+ low: {
525
+ label: "Low",
526
+ accessor: (e) => Q(e, a)
527
+ }
528
+ } : void 0, U = new Map(A.map((e) => [e.id, e])), K = h?.length ? Q(h[0], e) : null, te = h?.length ? Q(h.at(-1), e) : null, ne = K === null || te === null || te >= K, J = j.at(-1)?.id, Y = (n, r) => {
529
+ let a = n.id === J, s = (e) => (t) => Q(t, e), c = (e, t, n) => {
530
+ let r = Q(e, t);
531
+ return /* @__PURE__ */ P("span", {
532
+ className: "lilt-card__pane-value",
533
+ children: [n ? `${n} ` : "", r === null ? "—" : B(r)]
534
+ }, t);
535
+ };
536
+ if (n.kind === "volume") return /* @__PURE__ */ N(G, {
537
+ context: r,
538
+ label: `${x.title} volume`,
539
+ caption: "Volume",
540
+ readout: (e) => /* @__PURE__ */ N("span", {
541
+ className: "lilt-card__pane-value",
542
+ children: Q(e, o) === null ? "—" : V(Q(e, o))
543
+ }),
544
+ height: b,
545
+ xAxis: a,
546
+ y: {
547
+ includeZero: !0,
548
+ ticks: 2,
549
+ format: V
550
+ },
551
+ bars: { series: ["volume"] },
552
+ series: [{
553
+ id: "volume",
554
+ label: "Volume",
555
+ accessor: s(o),
556
+ formatValue: V,
557
+ colorAt: (n) => (Q(n, e) ?? 0) >= (Q(n, t) ?? Q(n, e) ?? 0) ? "color-mix(in srgb, var(--lilt-candle-up) 42%, transparent)" : "color-mix(in srgb, var(--lilt-candle-down) 42%, transparent)",
558
+ bar: { radius: 1 }
559
+ }],
560
+ children: /* @__PURE__ */ N(d, { series: "volume" })
561
+ }, n.id);
562
+ if (n.kind === "rsi") return /* @__PURE__ */ P(G, {
563
+ context: r,
564
+ label: `${x.title} RSI ${n.period}`,
565
+ caption: `RSI ${n.period}`,
566
+ readout: (e) => c(e, n.id),
567
+ height: b,
568
+ xAxis: a,
569
+ y: {
570
+ domain: [0, 100],
571
+ ticks: 2,
572
+ format: (e) => String(Math.round(e))
573
+ },
574
+ series: [{
575
+ id: n.id,
576
+ label: `RSI ${n.period}`,
577
+ accessor: s(n.id),
578
+ color: "var(--lilt-series-1)",
579
+ formatValue: B,
580
+ line: { width: 1.5 }
581
+ }],
582
+ children: [
583
+ /* @__PURE__ */ N(m, {
584
+ axis: "y",
585
+ from: 30,
586
+ to: 70,
587
+ color: "var(--lilt-series-1)"
588
+ }),
589
+ /* @__PURE__ */ N(T, {
590
+ value: 70,
591
+ color: "var(--lilt-muted)"
592
+ }),
593
+ /* @__PURE__ */ N(T, {
594
+ value: 30,
595
+ color: "var(--lilt-muted)"
596
+ }),
597
+ /* @__PURE__ */ N(i, { series: n.id })
598
+ ]
599
+ }, n.id);
600
+ let l = `${n.id}Macd`, u = `${n.id}Signal`, f = `${n.id}Histogram`;
601
+ return /* @__PURE__ */ P(G, {
602
+ context: r,
603
+ label: `${x.title} MACD`,
604
+ caption: `MACD ${n.fast} · ${n.slow} · ${n.signal}`,
605
+ readout: (e) => [c(e, l), c(e, u, "Signal")],
606
+ height: b,
607
+ xAxis: a,
608
+ y: {
609
+ includeZero: !0,
610
+ ticks: 2,
611
+ format: B
612
+ },
613
+ bars: { series: [f] },
614
+ series: [
615
+ {
616
+ id: f,
617
+ label: "Histogram",
618
+ accessor: s(f),
619
+ formatValue: B,
620
+ colorAt: (e) => (Q(e, f) ?? 0) >= 0 ? "color-mix(in srgb, var(--lilt-candle-up) 55%, transparent)" : "color-mix(in srgb, var(--lilt-candle-down) 55%, transparent)",
621
+ bar: { radius: 1 }
622
+ },
623
+ {
624
+ id: l,
625
+ label: "MACD",
626
+ accessor: s(l),
627
+ color: "var(--lilt-series-4)",
628
+ formatValue: B,
629
+ line: { width: 1.5 }
630
+ },
631
+ {
632
+ id: u,
633
+ label: "Signal",
634
+ accessor: s(u),
635
+ color: "var(--lilt-series-3)",
636
+ formatValue: B,
637
+ line: {
638
+ width: 1.5,
639
+ dasharray: "3 3"
640
+ }
641
+ }
642
+ ],
643
+ children: [
644
+ /* @__PURE__ */ N(d, { series: f }),
645
+ /* @__PURE__ */ N(i, { series: l }),
646
+ /* @__PURE__ */ N(i, { series: u })
647
+ ]
648
+ }, n.id);
649
+ };
650
+ return /* @__PURE__ */ N(C, {
651
+ ...x,
652
+ data: L,
653
+ ranges: R,
654
+ delta: _ ?? (h && t ? q(h, t, e) : void 0),
655
+ valueFormat: v,
656
+ locale: y,
657
+ aggregate: "last",
658
+ headlineSeries: e,
659
+ pillSeries: e,
660
+ tiles: !1,
661
+ live: p,
662
+ series: [{
663
+ key: e,
664
+ label: u,
665
+ color: E === "line" ? ne ? F : I : void 0
666
+ }, ...A.map((e, t) => ({
667
+ key: e.id,
668
+ label: e.label,
669
+ color: me[t % me.length]
670
+ }))],
671
+ shape: {
672
+ kind: "marks",
673
+ id: `indicator:${E}:${f}:${t}:${n}:${a}:${D}:${O}`,
674
+ includeZero: !1,
675
+ scale: f,
676
+ slots: !0,
677
+ xAxis: j.length === 0,
678
+ series: (e) => {
679
+ let t = U.get(e);
680
+ return t ? {
681
+ curve: "monotone",
682
+ line: {
683
+ width: 1.5,
684
+ showInspectionPoint: !1
685
+ },
686
+ ...t.kind === "bollinger" ? { fields: {
687
+ upper: {
688
+ label: "Upper",
689
+ accessor: (e) => Q(e, `${t.id}Upper`)
690
+ },
691
+ lower: {
692
+ label: "Lower",
693
+ accessor: (e) => Q(e, `${t.id}Lower`)
694
+ }
695
+ } } : {}
696
+ } : E === "line" ? {
697
+ fields: H,
698
+ curve: "linear",
699
+ line: { width: 2 }
700
+ } : { fields: H };
701
+ },
702
+ describe: w ? ee(z) : void 0,
703
+ draw: (e) => e.map((e) => {
704
+ let t = U.get(e);
705
+ return t ? t.kind === "bollinger" ? [/* @__PURE__ */ N(r, {
706
+ series: e,
707
+ lower: "lower",
708
+ upper: "upper"
709
+ }, `band-${e}`), /* @__PURE__ */ N(i, { series: e }, `line-${e}`)] : /* @__PURE__ */ N(i, { series: e }, e) : E === "line" ? /* @__PURE__ */ N(i, { series: e }, e) : /* @__PURE__ */ N(W, {
710
+ series: e,
711
+ open: "open",
712
+ high: "high",
713
+ low: "low",
714
+ display: E
715
+ }, e);
716
+ })
717
+ },
718
+ panes: j.length ? (e) => /* @__PURE__ */ N(M, { children: j.map((t) => Y(t, e)) }) : void 0
719
+ });
720
+ }
721
+ //#endregion
722
+ //#region src/finance/cards/depth-chart-card.tsx
723
+ function ge({ price: e, label: t }) {
724
+ let { snapshot: n } = p();
725
+ if (e < n.xDomain[0] || e > n.xDomain[1]) return null;
726
+ let r = n.xToPixel(e);
727
+ return /* @__PURE__ */ P("g", {
728
+ className: "lilt-card__depth-mid",
729
+ "aria-hidden": "true",
730
+ children: [/* @__PURE__ */ N("line", {
731
+ x1: r,
732
+ x2: r,
733
+ y1: n.plot.top + 18,
734
+ y2: n.plot.bottom,
735
+ strokeDasharray: "2 4",
736
+ vectorEffect: "non-scaling-stroke"
737
+ }), /* @__PURE__ */ N("text", {
738
+ x: r,
739
+ y: n.plot.top + 10,
740
+ textAnchor: "middle",
741
+ children: t
742
+ })]
743
+ });
744
+ }
745
+ var _e = {
746
+ style: "currency",
747
+ currency: "USD",
748
+ minimumFractionDigits: 2,
749
+ maximumFractionDigits: 2
750
+ };
751
+ function ve({ title: e, bids: t, asks: r, valueFormat: a = _e, sizeFormat: o, locale: s = "en-US", height: c = 220, axis: d = "minimal", background: f = "dots", hoverStyle: p = "soft", surface: m, numberStyle: v, loading: y = !1, motion: C, className: T, style: O }) {
752
+ let A = k(() => le(t, r), [t, r]), M = JSON.stringify(a), L = JSON.stringify(o ?? null), R = k(() => S(s, a), [s, M]), z = k(() => S(s, o), [s, L]), B = k(() => S(s, {
753
+ style: "percent",
754
+ maximumFractionDigits: 3
755
+ }).full, [s]), [V, H] = j(null), U = k(() => [{
756
+ id: "bid",
757
+ label: "Bids",
758
+ accessor: (e) => e.bid,
759
+ color: F,
760
+ curve: "step-before",
761
+ area: { treatment: "fade" },
762
+ line: { width: 1.5 },
763
+ formatValue: z.full
764
+ }, {
765
+ id: "ask",
766
+ label: "Asks",
767
+ accessor: (e) => e.ask,
768
+ color: I,
769
+ curve: "step-after",
770
+ area: { treatment: "fade" },
771
+ line: { width: 1.5 },
772
+ formatValue: z.full
773
+ }], [z]), W = A.spread !== null && A.mid ? `${R.full(A.spread)} (${B(A.spread / A.mid)})` : "—", G = V ? V.bid ?? V.ask : null;
774
+ return /* @__PURE__ */ P(w, {
775
+ "aria-label": e,
776
+ surface: m,
777
+ numberStyle: v,
778
+ motion: C,
779
+ className: ["lilt-card--depth", T].filter(Boolean).join(" "),
780
+ style: O,
781
+ children: [
782
+ /* @__PURE__ */ P(x, { children: [/* @__PURE__ */ N(_, { children: e }), /* @__PURE__ */ N(g, {
783
+ value: A.mid,
784
+ format: R.full,
785
+ loading: y,
786
+ motion: C,
787
+ children: y ? null : V && G !== null ? /* @__PURE__ */ P(h, { children: [
788
+ z.full(G),
789
+ " ",
790
+ V.side === "bid" ? "bid" : "ask",
791
+ " depth at",
792
+ " ",
793
+ R.full(V.price)
794
+ ] }) : /* @__PURE__ */ N(h, { children: "Mid price" })
795
+ })] }),
796
+ /* @__PURE__ */ P("dl", {
797
+ className: "lilt-card__stats",
798
+ children: [
799
+ /* @__PURE__ */ P("div", { children: [/* @__PURE__ */ N("dt", { children: "Spread" }), /* @__PURE__ */ N("dd", { children: y ? "—" : W })] }),
800
+ /* @__PURE__ */ P("div", {
801
+ "data-side": "bid",
802
+ children: [/* @__PURE__ */ N("dt", { children: "Bid depth" }), /* @__PURE__ */ N("dd", { children: y ? "—" : z.compact(A.bidDepth) })]
803
+ }),
804
+ /* @__PURE__ */ P("div", {
805
+ "data-side": "ask",
806
+ children: [/* @__PURE__ */ N("dt", { children: "Ask depth" }), /* @__PURE__ */ N("dd", { children: y ? "—" : z.compact(A.askDepth) })]
807
+ })
808
+ ]
809
+ }),
810
+ /* @__PURE__ */ N(b, {
811
+ className: "lilt-card__chart",
812
+ "aria-label": `${e} depth by price`,
813
+ data: A.levels,
814
+ x: {
815
+ type: "number",
816
+ accessor: (e) => e.price,
817
+ format: R.full
818
+ },
819
+ y: {
820
+ includeZero: !0,
821
+ ticks: 3,
822
+ format: z.compact
823
+ },
824
+ series: U,
825
+ onSelectionChange: (e) => H(e?.row ?? null),
826
+ motion: C,
827
+ status: y ? "loading" : "ready",
828
+ children: /* @__PURE__ */ P(D, {
829
+ height: c,
830
+ axis: d,
831
+ background: f,
832
+ pill: p,
833
+ margins: {
834
+ top: 8,
835
+ right: 4,
836
+ bottom: 28,
837
+ left: 4
838
+ },
839
+ children: [
840
+ /* @__PURE__ */ N(E, { pattern: "lines" }),
841
+ /* @__PURE__ */ N(l, { series: "bid" }),
842
+ /* @__PURE__ */ N(l, { series: "ask" }),
843
+ /* @__PURE__ */ N(i, { series: "bid" }),
844
+ /* @__PURE__ */ N(i, { series: "ask" }),
845
+ A.mid === null ? null : /* @__PURE__ */ N(ge, {
846
+ price: A.mid,
847
+ label: `Mid ${R.full(A.mid)}`
848
+ }),
849
+ /* @__PURE__ */ N(u, { labels: "fit" }),
850
+ /* @__PURE__ */ N(n, {})
851
+ ]
852
+ })
853
+ })
854
+ ]
855
+ });
856
+ }
857
+ //#endregion
858
+ //#region src/finance/cards/portfolio-chart-card.tsx
859
+ function $(e, t) {
860
+ if (!t) return null;
861
+ let n = e[t];
862
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
863
+ }
864
+ function ye(e, t, n) {
865
+ let r = e.at(-1), i = $(r, t), a = $(r, n);
866
+ return i !== null && a ? i / a - 1 : void 0;
867
+ }
868
+ function be({ value: e, basis: t, label: n = "Value", drawdown: r = !0, drawdownHeight: a = 64, data: o, ranges: s, delta: c, locale: u = "en-US", ...d }) {
869
+ let f = o ?? s?.[0]?.data ?? [], p = k(() => s?.map((n) => ({
870
+ ...n,
871
+ delta: n.delta ?? ye(n.data, e, t)
872
+ })), [
873
+ s,
874
+ e,
875
+ t
876
+ ]), m = k(() => S(u, {
877
+ style: "percent",
878
+ minimumFractionDigits: 1,
879
+ maximumFractionDigits: 1
880
+ }).full, [u]), h = k(() => {
881
+ let t = oe(f.map((t) => $(t, e))).filter((e) => e !== null);
882
+ return t.length ? Math.min(...t) : null;
883
+ }, [f, e]);
884
+ return /* @__PURE__ */ N(C, {
885
+ ...d,
886
+ data: o,
887
+ ranges: p,
888
+ delta: c ?? (o ? ye(o, e, t) : void 0),
889
+ locale: u,
890
+ aggregate: "last",
891
+ headlineSeries: e,
892
+ pillSeries: e,
893
+ tiles: !1,
894
+ restCaption: t ? () => "over basis" : void 0,
895
+ series: [{
896
+ key: e,
897
+ label: n
898
+ }, ...t ? [{
899
+ key: t,
900
+ label: "Basis",
901
+ dashed: !0
902
+ }] : []],
903
+ shape: {
904
+ kind: "marks",
905
+ id: `portfolio:${e}:${t}:${r}`,
906
+ includeZero: !1,
907
+ xAxis: !r,
908
+ series: (e) => e === t ? {
909
+ curve: "step-after",
910
+ color: "var(--lilt-muted)"
911
+ } : {
912
+ area: { treatment: "fade" },
913
+ curve: "monotone"
914
+ },
915
+ draw: (e) => e.map((e) => [/* @__PURE__ */ N(l, { series: e }, `area-${e}`), /* @__PURE__ */ N(i, { series: e }, e)])
916
+ },
917
+ panes: r ? (t) => {
918
+ let n = oe(t.data.map((t) => $(t, e))), r = new Map(t.data.map((e, t) => [e, n[t] ?? null]));
919
+ return /* @__PURE__ */ P(G, {
920
+ context: t,
921
+ label: `${d.title} drawdown`,
922
+ caption: "Drawdown",
923
+ readout: (e) => /* @__PURE__ */ P(M, { children: [/* @__PURE__ */ N("span", {
924
+ className: "lilt-card__pane-value",
925
+ children: r.get(e) == null ? "—" : m(r.get(e))
926
+ }), h === null ? null : /* @__PURE__ */ P("span", {
927
+ className: "lilt-card__pane-value",
928
+ children: ["Max ", m(h)]
929
+ })] }),
930
+ height: a,
931
+ xAxis: !0,
932
+ y: {
933
+ includeZero: !0,
934
+ ticks: 2,
935
+ format: m
936
+ },
937
+ series: [{
938
+ id: "drawdown",
939
+ label: "Drawdown",
940
+ accessor: (e) => r.get(e) ?? null,
941
+ color: "var(--lilt-candle-down)",
942
+ formatValue: m,
943
+ area: { treatment: "fade" },
944
+ line: { width: 1.5 },
945
+ curve: "monotone"
946
+ }],
947
+ children: [/* @__PURE__ */ N(l, { series: "drawdown" }), /* @__PURE__ */ N(i, { series: "drawdown" })]
948
+ });
949
+ } : void 0
950
+ });
951
+ }
952
+ //#endregion
953
+ //#region src/finance/cards/price-chart-card.tsx
954
+ function xe(e, t) {
955
+ let n = e[t];
956
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
957
+ }
958
+ function Se(e, t) {
959
+ let n = e.map((e) => xe(e, t)).filter((e) => e !== null);
960
+ return n.length > 1 ? {
961
+ first: n[0],
962
+ last: n.at(-1)
963
+ } : null;
964
+ }
965
+ function Ce(e, t) {
966
+ let n = e.map((e) => ({ ...e }));
967
+ for (let r of t) se(e.map((e) => xe(e, r))).forEach((e, t) => n[t][`__rebased${r}`] = e);
968
+ return n;
969
+ }
970
+ var we = {
971
+ style: "currency",
972
+ currency: "USD",
973
+ minimumFractionDigits: 2,
974
+ maximumFractionDigits: 2
975
+ };
976
+ function Te({ price: e, symbol: t, name: n, icon: r, display: a = "area", versus: o, data: s, ranges: c, delta: u, valueFormat: d = we, locale: f = "en-US", title: p, ...m }) {
977
+ let h = !!o?.length, g = k(() => [e, ...(o ?? []).map((e) => e.key)], [e, o]), _ = k(() => s ? h ? Ce(s, g) : s : void 0, [
978
+ s,
979
+ h,
980
+ g
981
+ ]), y = k(() => c?.map((t) => {
982
+ let n = Se(t.data, e);
983
+ return {
984
+ ...t,
985
+ data: h ? Ce(t.data, g) : t.data,
986
+ delta: t.delta ?? (n && n.first ? n.last / n.first - 1 : void 0)
987
+ };
988
+ }), [
989
+ c,
990
+ h,
991
+ g,
992
+ e
993
+ ]), b = Se(s ?? c?.[0]?.data ?? [], e), x = !b || b.last >= b.first, w = k(() => S(f, d).full, [f, JSON.stringify(d)]), T = k(() => S(f, {
994
+ style: "percent",
995
+ minimumFractionDigits: 1,
996
+ maximumFractionDigits: 1
997
+ }).full, [f]), E = (e) => h ? `__rebased${e}` : e, D = /* @__PURE__ */ P("span", {
998
+ className: "lilt-card__ticker",
999
+ children: [
1000
+ r ? /* @__PURE__ */ N("span", {
1001
+ className: "lilt-card__ticker-icon",
1002
+ children: r
1003
+ }) : null,
1004
+ /* @__PURE__ */ N("span", {
1005
+ className: "lilt-card__ticker-symbol",
1006
+ children: t ?? p
1007
+ }),
1008
+ n ? /* @__PURE__ */ N("span", {
1009
+ className: "lilt-card__ticker-name",
1010
+ children: n
1011
+ }) : null
1012
+ ]
1013
+ });
1014
+ return /* @__PURE__ */ N(C, {
1015
+ ...m,
1016
+ title: p,
1017
+ heading: D,
1018
+ data: _,
1019
+ ranges: y,
1020
+ delta: h ? void 0 : u ?? (s && b && b.first ? b.last / b.first - 1 : void 0),
1021
+ valueFormat: h ? {
1022
+ style: "percent",
1023
+ maximumFractionDigits: 1
1024
+ } : d,
1025
+ formatValue: h ? (e) => v(T)(e) : void 0,
1026
+ locale: f,
1027
+ aggregate: "last",
1028
+ headlineSeries: E(e),
1029
+ pillSeries: h ? "nearest" : E(e),
1030
+ tiles: h,
1031
+ restCaption: h ? void 0 : (t) => {
1032
+ let n = Se(t, e);
1033
+ return n ? v(w)(n.last - n.first) : null;
1034
+ },
1035
+ series: [{
1036
+ key: E(e),
1037
+ label: t ?? p,
1038
+ color: h ? void 0 : x ? F : I
1039
+ }, ...(o ?? []).map((e) => ({
1040
+ ...e,
1041
+ key: E(e.key)
1042
+ }))],
1043
+ shape: {
1044
+ kind: "marks",
1045
+ id: `price:${a}:${g.join()}:${h}`,
1046
+ includeZero: h,
1047
+ series: () => a === "area" && !h ? {
1048
+ area: { treatment: "fade" },
1049
+ curve: "monotone"
1050
+ } : { curve: "monotone" },
1051
+ draw: (e) => e.map((e) => a === "area" && !h ? [/* @__PURE__ */ N(l, { series: e }, `area-${e}`), /* @__PURE__ */ N(i, { series: e }, e)] : /* @__PURE__ */ N(i, { series: e }, e))
1052
+ },
1053
+ bleed: m.bleed ?? !0
1054
+ });
1055
+ }
1056
+ //#endregion
1057
+ //#region src/finance/order-book.tsx
1058
+ function Ee(e, t, n) {
1059
+ let r = /* @__PURE__ */ new Map();
1060
+ for (let t of e) Number.isFinite(t.price) && Number.isFinite(t.size) && t.size > 0 && r.set(t.price, (r.get(t.price) ?? 0) + t.size);
1061
+ let i = [...r].map(([e, t]) => ({
1062
+ price: e,
1063
+ size: t
1064
+ })).sort((e, n) => t === "bid" ? n.price - e.price : e.price - n.price).slice(0, n), a = 0;
1065
+ return i.map((e) => (a += e.size, {
1066
+ ...e,
1067
+ total: a,
1068
+ side: t
1069
+ }));
1070
+ }
1071
+ function De(e, t) {
1072
+ let n = A(null), [r, i] = j(/* @__PURE__ */ new Set());
1073
+ return O(() => {
1074
+ let r = new Map(e.map((e) => [`${e.side}:${e.price}`, e.size])), a = n.current;
1075
+ if (n.current = r, !t || !a) return;
1076
+ let o = new Set([...r].filter(([e, t]) => a.get(e) !== t).map(([e]) => e));
1077
+ if (!o.size) return;
1078
+ i(o);
1079
+ let s = window.setTimeout(() => i(/* @__PURE__ */ new Set()), 600);
1080
+ return () => window.clearTimeout(s);
1081
+ }, [e, t]), r;
1082
+ }
1083
+ function Oe({ title: e, bids: t, asks: n, depth: r = 8, valueFormat: i = {
1084
+ minimumFractionDigits: 2,
1085
+ maximumFractionDigits: 2
1086
+ }, sizeFormat: a, locale: s = "en-US", flash: c = !0, surface: l, motion: u, className: d, style: f }) {
1087
+ let p = o(u ?? "auto"), m = JSON.stringify(i), h = JSON.stringify(a ?? null), g = k(() => S(s, i).full, [s, m]), _ = k(() => S(s, a).compact, [s, h]), v = k(() => S(s, {
1088
+ style: "percent",
1089
+ maximumFractionDigits: 3
1090
+ }).full, [s]), y = k(() => Ee(t, "bid", r), [t, r]), b = k(() => Ee(n, "ask", r), [n, r]), x = De(k(() => [...b, ...y], [b, y]), c && !p), C = Math.max(1, b.at(-1)?.total ?? 0, y.at(-1)?.total ?? 0), T = y[0]?.price, E = b[0]?.price, D = T !== void 0 && E !== void 0 ? {
1091
+ value: E - T,
1092
+ mid: (E + T) / 2
1093
+ } : null, O = (e) => /* @__PURE__ */ P("tr", {
1094
+ className: "lilt-order-book__level",
1095
+ "data-side": e.side,
1096
+ "data-flash": x.has(`${e.side}:${e.price}`) || void 0,
1097
+ style: { "--lilt-depth": `${e.total / C * 100}%` },
1098
+ children: [
1099
+ /* @__PURE__ */ N("th", {
1100
+ scope: "row",
1101
+ children: g(e.price)
1102
+ }),
1103
+ /* @__PURE__ */ N("td", { children: _(e.size) }),
1104
+ /* @__PURE__ */ N("td", { children: _(e.total) })
1105
+ ]
1106
+ }, `${e.side}:${e.price}`);
1107
+ return /* @__PURE__ */ N(w, {
1108
+ "aria-label": e,
1109
+ surface: l,
1110
+ motion: u,
1111
+ className: ["lilt-card--order-book", d].filter(Boolean).join(" "),
1112
+ style: f,
1113
+ children: /* @__PURE__ */ P("table", {
1114
+ className: "lilt-order-book",
1115
+ children: [
1116
+ /* @__PURE__ */ N("caption", { children: e }),
1117
+ /* @__PURE__ */ N("thead", { children: /* @__PURE__ */ P("tr", { children: [
1118
+ /* @__PURE__ */ N("th", {
1119
+ scope: "col",
1120
+ children: "Price"
1121
+ }),
1122
+ /* @__PURE__ */ N("th", {
1123
+ scope: "col",
1124
+ children: "Size"
1125
+ }),
1126
+ /* @__PURE__ */ N("th", {
1127
+ scope: "col",
1128
+ children: "Total"
1129
+ })
1130
+ ] }) }),
1131
+ /* @__PURE__ */ N("tbody", {
1132
+ "aria-label": "Asks",
1133
+ children: [...b].reverse().map(O)
1134
+ }),
1135
+ /* @__PURE__ */ N("tbody", {
1136
+ "aria-label": "Spread",
1137
+ children: /* @__PURE__ */ P("tr", {
1138
+ className: "lilt-order-book__spread",
1139
+ children: [/* @__PURE__ */ N("th", {
1140
+ scope: "row",
1141
+ children: D ? g(D.mid) : "—"
1142
+ }), /* @__PURE__ */ N("td", {
1143
+ colSpan: 2,
1144
+ children: D ? `Spread ${g(D.value)} · ${v(D.value / D.mid)}` : "No spread"
1145
+ })]
1146
+ })
1147
+ }),
1148
+ /* @__PURE__ */ N("tbody", {
1149
+ "aria-label": "Bids",
1150
+ children: y.map(O)
1151
+ })
1152
+ ]
1153
+ })
1154
+ });
1155
+ }
1156
+ //#endregion
1157
+ export { W as Candles, ne as CandlestickChartCard, ve as DepthChartCard, he as IndicatorChartCard, Oe as OrderBook, be as PortfolioChartCard, Te as PriceChartCard, ae as bollinger, le as depthLevels, oe as drawdown, Z as ema, ie as macd, se as rebase, re as rsi, X as sma };