@overdoser/react-toolkit 0.7.0 → 0.8.1

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 (104) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/components/ActionButton/ActionButton.js +211 -0
  3. package/components/ActionButton/ActionButton.module.scss.js +47 -0
  4. package/components/ActionButton/CopyButton.js +66 -0
  5. package/components/Alert/Alert.js +82 -0
  6. package/components/Alert/Alert.module.scss.js +25 -0
  7. package/components/Avatar/Avatar.js +57 -0
  8. package/components/Avatar/Avatar.module.scss.js +43 -0
  9. package/components/Badge/Badge.js +38 -0
  10. package/components/Badge/Badge.module.scss.js +31 -0
  11. package/components/Breadcrumbs/Breadcrumbs.js +49 -0
  12. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +17 -0
  13. package/components/Button/Button.js +57 -0
  14. package/components/Button/Button.module.scss.js +47 -0
  15. package/components/Chart/AreaChart.js +244 -0
  16. package/components/Chart/Axis.js +45 -0
  17. package/components/Chart/BarChart.js +353 -0
  18. package/components/Chart/Chart.module.scss.js +61 -0
  19. package/components/Chart/ChartContainer.js +41 -0
  20. package/components/Chart/ChartLegend.js +31 -0
  21. package/components/Chart/ChartTooltip.js +42 -0
  22. package/components/Chart/LineChart.js +236 -0
  23. package/components/Chart/PieChart.js +248 -0
  24. package/components/Chart/RadarChart.js +221 -0
  25. package/components/Chart/Sparkline.js +69 -0
  26. package/components/Chart/TradingChart.js +732 -0
  27. package/components/Chart/scales.js +39 -0
  28. package/components/Chart/trading/indicators.js +68 -0
  29. package/components/Chart/trading/period.js +71 -0
  30. package/components/Chart/useChartDimensions.js +23 -0
  31. package/components/Divider/Divider.js +36 -0
  32. package/components/Divider/Divider.module.scss.js +31 -0
  33. package/components/Draggable/Draggable.js +155 -0
  34. package/components/Draggable/Draggable.module.scss.js +17 -0
  35. package/components/Drawer/Drawer.js +126 -0
  36. package/components/Drawer/Drawer.module.scss.js +117 -0
  37. package/components/Dropdown/Dropdown.js +142 -0
  38. package/components/Dropdown/Dropdown.module.scss.js +35 -0
  39. package/components/Dropdown/DropdownItem.js +31 -0
  40. package/components/Dropzone/Dropzone.js +107 -0
  41. package/components/Dropzone/Dropzone.module.scss.js +21 -0
  42. package/components/Form/Form.js +36 -0
  43. package/components/Form/Form.module.scss.js +29 -0
  44. package/components/Form/FormField.js +76 -0
  45. package/components/Form/FormRow.js +9 -0
  46. package/components/Form/formFieldDefaults.js +5 -0
  47. package/components/Link/Link.js +59 -0
  48. package/components/Link/Link.module.scss.js +16 -0
  49. package/components/List/List.js +46 -0
  50. package/components/List/List.module.scss.js +21 -0
  51. package/components/Modal/Modal.js +114 -0
  52. package/components/Modal/Modal.module.scss.js +31 -0
  53. package/components/Pagination/Pagination.js +84 -0
  54. package/components/Pagination/Pagination.module.scss.js +23 -0
  55. package/components/Pagination/paginationRange.js +24 -0
  56. package/components/Popover/Popover.js +138 -0
  57. package/components/Popover/Popover.module.scss.js +21 -0
  58. package/components/Skeleton/Skeleton.js +50 -0
  59. package/components/Skeleton/Skeleton.module.scss.js +25 -0
  60. package/components/Spinner/Spinner.js +25 -0
  61. package/components/Spinner/Spinner.module.scss.js +20 -0
  62. package/components/Table/Table.js +284 -0
  63. package/components/Table/Table.module.scss.js +59 -0
  64. package/components/Table/useTableSort.js +44 -0
  65. package/components/Tabs/Tabs.js +163 -0
  66. package/components/Tabs/Tabs.module.scss.js +53 -0
  67. package/components/Timer/Timer.js +159 -0
  68. package/components/Timer/Timer.module.scss.js +55 -0
  69. package/components/Toast/Toast.js +133 -0
  70. package/components/Toast/Toast.module.scss.js +62 -0
  71. package/components/Toast/toastStore.js +62 -0
  72. package/components/ToggleIconButton/ToggleIconButton.js +58 -0
  73. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +27 -0
  74. package/components/Tooltip/Tooltip.js +86 -0
  75. package/components/Tooltip/Tooltip.module.scss.js +30 -0
  76. package/components/Typography/Typography.js +37 -0
  77. package/components/Typography/Typography.module.scss.js +53 -0
  78. package/components/inputs/Checkbox/Checkbox.js +50 -0
  79. package/components/inputs/Checkbox/Checkbox.module.scss.js +15 -0
  80. package/components/inputs/Checkbox/CheckboxGroup.js +111 -0
  81. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +31 -0
  82. package/components/inputs/DatePicker/DatePicker.js +229 -0
  83. package/components/inputs/DatePicker/DatePicker.module.scss.js +45 -0
  84. package/components/inputs/DatePicker/dateUtils.js +41 -0
  85. package/components/inputs/Input/Input.js +50 -0
  86. package/components/inputs/Input/Input.module.scss.js +25 -0
  87. package/components/inputs/NumberInput/NumberInput.js +134 -0
  88. package/components/inputs/NumberInput/NumberInput.module.scss.js +25 -0
  89. package/components/inputs/Radio/Radio.js +68 -0
  90. package/components/inputs/Radio/Radio.module.scss.js +13 -0
  91. package/components/inputs/Select/Select.js +520 -0
  92. package/components/inputs/Select/Select.module.scss.js +69 -0
  93. package/components/inputs/Slider/Slider.js +128 -0
  94. package/components/inputs/Slider/Slider.module.scss.js +15 -0
  95. package/components/inputs/Textarea/Textarea.js +58 -0
  96. package/components/inputs/Textarea/Textarea.module.scss.js +25 -0
  97. package/hooks/useClickOutside.js +15 -0
  98. package/hooks/useFocusTrap.js +39 -0
  99. package/hooks/useKeyboard.js +19 -0
  100. package/hooks/usePortalPosition.js +20 -0
  101. package/index.css +1 -1
  102. package/index.js +119 -7000
  103. package/index.layered.css +1 -1
  104. package/package.json +3 -2
@@ -0,0 +1,732 @@
1
+ import { jsxs as et, jsx as x } from "react/jsx-runtime";
2
+ import { useRef as U, useState as St, useCallback as X, useMemo as qt, useLayoutEffect as Qt, useEffect as te } from "react";
3
+ import ee from "clsx";
4
+ import { niceTicks as Ht } from "./scales.js";
5
+ import { rsi as ne, sma as oe, ema as re, bollinger as ie } from "./trading/indicators.js";
6
+ import { periodToSeconds as le } from "./trading/period.js";
7
+ import mt from "./Chart.module.scss.js";
8
+ import { Popover as se } from "../Popover/Popover.js";
9
+ import { Button as ae } from "../Button/Button.js";
10
+ import { Dropdown as ce } from "../Dropdown/Dropdown.js";
11
+ const fe = 420, Tt = 64, vt = 28, he = 40, ue = 4, At = { rsi: 0.18, volume: 0.14 }, pe = 1, de = 40, kt = 0.1, me = 500, ge = [];
12
+ function Ze({
13
+ datafeed: t,
14
+ symbol: n,
15
+ resolution: e,
16
+ period: o,
17
+ seriesType: r = "candle",
18
+ indicators: l = ge,
19
+ precision: i = 2,
20
+ initialLookback: s = me,
21
+ height: c = fe,
22
+ upColor: g = "var(--crk-color-success)",
23
+ downColor: h = "var(--crk-color-danger)",
24
+ lineColor: f = "var(--crk-chart-1)",
25
+ timezone: d,
26
+ defaultTimezone: M = "local",
27
+ onTimezoneChange: k,
28
+ showConfigPanel: C = !0,
29
+ priceBadgeColorByDirection: L = !1,
30
+ priceBadgeShowTime: P = !1,
31
+ priceBadgeTimeFormat: j,
32
+ onCrosshair: N,
33
+ onVisibleRangeChange: Y,
34
+ className: _,
35
+ style: J
36
+ }) {
37
+ const z = U(null), Z = U(null), I = U([]), y = U({ from: 0, to: 0 }), F = U(null), V = U(null), G = U(!1), K = U(null), ht = U(null), wt = U(1), ut = U({ width: 0, height: 0 }), pt = U(() => {
38
+ }), yt = U(N), lt = U(Y);
39
+ yt.current = N, lt.current = Y;
40
+ const [st, Ot] = St(null), [Et, Ut] = St(M), dt = d ?? Et, _t = X(
41
+ (p) => {
42
+ d === void 0 && Ut(p), k?.(p);
43
+ },
44
+ [d, k]
45
+ ), bt = qt(
46
+ () => ({ up: g, down: h, line: f }),
47
+ [g, h, f]
48
+ ), q = l, nt = q.some((p) => p.type === "rsi"), ot = q.some((p) => p.type === "volume"), xt = X(() => {
49
+ const p = Z.current;
50
+ if (!p) return;
51
+ const a = p.getContext("2d");
52
+ if (!a) return;
53
+ const { width: A, height: b } = ut.current;
54
+ if (A === 0 || b === 0) return;
55
+ const R = wt.current;
56
+ a.save(), a.setTransform(1, 0, 0, 1, 0, 0), a.clearRect(0, 0, p.width, p.height), a.scale(R, R);
57
+ const m = Re(z.current, bt), H = Dt(z.current), S = I.current;
58
+ if (S.length === 0) {
59
+ Se(a, A, b, m), a.restore();
60
+ return;
61
+ }
62
+ const u = gt(A, b, nt, ot), { from: T, to: w } = we(y.current, S.length);
63
+ y.current = { from: T, to: w };
64
+ const W = S.slice(Math.max(0, Math.floor(T)), Math.min(S.length, Math.ceil(w) + 1)), $ = (v) => {
65
+ const it = w - T + 1, tt = u.plotWidth / it;
66
+ return u.plotLeft + (v - T + 0.5) * tt;
67
+ }, rt = u.plotWidth / (w - T + 1), Q = q.map((v) => ye(v, S)).filter((v) => v !== null).map((v) => ({ ...v, color: H(v.color) })), E = Bt(u.main, W, Q, T, w);
68
+ Mt(a, u.plotLeft, u.plotRight, E, m), Ae(a, u, E, i, m), a.save(), a.beginPath(), a.rect(u.plotLeft, E.paneTop, u.plotWidth, E.paneHeight), a.clip();
69
+ for (let v = 0; v < q.length; v++) {
70
+ const it = q[v], tt = Q[v];
71
+ tt && We(a, tt, it, S, T, w, $, E);
72
+ }
73
+ if (r === "candle" ? ke(a, S, T, w, $, rt, E, { up: m.up, down: m.down }) : r === "bar" ? Ce(a, S, T, w, $, rt, E, { up: m.up, down: m.down }) : Le(a, S, T, w, $, E, m.line, r === "area"), a.restore(), u.volume) {
74
+ const v = be(u.volume, S, T, w);
75
+ Mt(a, u.plotLeft, u.plotRight, v, m, !0), Ct(a, u, u.volume, "Volume", m), a.save(), a.beginPath(), a.rect(u.plotLeft, v.paneTop, u.plotWidth, v.paneHeight), a.clip(), $e(a, S, T, w, $, rt, v, { up: m.up, down: m.down }), a.restore();
76
+ }
77
+ if (u.rsi) {
78
+ const v = q.find((Jt) => Jt.type === "rsi"), it = v && v.type === "rsi" ? v.period ?? 14 : 14, tt = v && v.type === "rsi" ? v.overbought ?? 70 : 70, Rt = v && v.type === "rsi" ? v.oversold ?? 30 : 30, Gt = (v && v.type === "rsi" ? v.color : void 0) ?? "var(--crk-chart-5)", Kt = H(Gt), jt = ne(S, it), ct = {
79
+ paneTop: u.rsi.top,
80
+ paneBottom: u.rsi.bottom,
81
+ paneHeight: u.rsi.height,
82
+ priceMin: 0,
83
+ priceMax: 100,
84
+ ticks: [Rt, 50, tt]
85
+ };
86
+ Mt(a, u.plotLeft, u.plotRight, ct, m, !0), Ct(a, u, u.rsi, `RSI ${it}`, m), a.save(), a.beginPath(), a.rect(u.plotLeft, ct.paneTop, u.plotWidth, ct.paneHeight), a.clip(), ft(a, jt, T, w, $, ct, Kt), a.restore(), He(a, u, ct, tt, Rt, m);
87
+ }
88
+ Be(a, u, S, T, w, e, m), F.current && De(
89
+ a,
90
+ u,
91
+ F.current,
92
+ S,
93
+ T,
94
+ w,
95
+ $,
96
+ i,
97
+ E,
98
+ dt,
99
+ m,
100
+ e,
101
+ L,
102
+ P,
103
+ j
104
+ ), a.restore();
105
+ }, [r, q, nt, ot, i, bt, e, dt, L, P, j]);
106
+ pt.current = xt;
107
+ const O = X(() => {
108
+ if (ht.current === null) {
109
+ if (typeof requestAnimationFrame > "u") {
110
+ pt.current();
111
+ return;
112
+ }
113
+ ht.current = requestAnimationFrame(() => {
114
+ ht.current = null, pt.current();
115
+ });
116
+ }
117
+ }, []);
118
+ Qt(() => {
119
+ const p = z.current;
120
+ if (!p) return;
121
+ const a = () => {
122
+ const b = p.getBoundingClientRect(), R = typeof window < "u" && window.devicePixelRatio || 1;
123
+ wt.current = R, ut.current = { width: b.width, height: b.height };
124
+ const m = Z.current;
125
+ m && (m.width = Math.round(b.width * R), m.height = Math.round(b.height * R), m.style.width = `${b.width}px`, m.style.height = `${b.height}px`), O();
126
+ };
127
+ if (a(), typeof ResizeObserver > "u") return;
128
+ const A = new ResizeObserver(a);
129
+ return A.observe(p), () => A.disconnect();
130
+ }, [O]), te(() => {
131
+ let p = !1;
132
+ const a = Math.floor(Date.now() / 1e3), A = $t(e), b = o === "MAX", R = o !== void 0 ? le(o) : A * s, m = o !== void 0 ? Math.max(10, Math.ceil(R / A)) : s, H = b ? 0 : a - R;
133
+ I.current = [], y.current = { from: 0, to: 0 }, O(), t.getBars({ symbol: n, resolution: e, from: H, to: a, countBack: m }).then((u) => {
134
+ if (p) return;
135
+ const T = [...u].sort((W, $) => W.time - $.time);
136
+ I.current = T;
137
+ const w = T.length - 1;
138
+ if (o !== void 0)
139
+ y.current = { from: 0, to: w };
140
+ else {
141
+ const W = Math.min(T.length, Math.min(200, s));
142
+ y.current = {
143
+ from: Math.max(0, w - W + 1),
144
+ to: w
145
+ };
146
+ }
147
+ lt.current?.(y.current, T), O();
148
+ }).catch(() => {
149
+ });
150
+ const S = t.subscribeBars({
151
+ symbol: n,
152
+ resolution: e,
153
+ onTick: (u) => {
154
+ if (p) return;
155
+ const T = I.current, w = T[T.length - 1];
156
+ if (w && w.time === u.time)
157
+ T[T.length - 1] = u;
158
+ else if (!w || u.time > w.time) {
159
+ T.push(u);
160
+ const W = y.current;
161
+ W.to >= T.length - 2 && (y.current = { from: W.from + 1, to: W.to + 1 });
162
+ }
163
+ O();
164
+ }
165
+ });
166
+ return K.current = S, () => {
167
+ p = !0, K.current !== null && (t.unsubscribeBars(K.current), K.current = null);
168
+ };
169
+ }, [t, n, e, o, s]);
170
+ const at = X((p) => {
171
+ Ot(p), yt.current?.(p);
172
+ }, []), Ft = X((p) => {
173
+ p.currentTarget.setPointerCapture(p.pointerId);
174
+ const a = y.current;
175
+ V.current = { startX: p.clientX, from: a.from, to: a.to };
176
+ }, []), Nt = X(
177
+ (p) => {
178
+ const a = p.currentTarget.getBoundingClientRect(), A = p.clientX - a.left, b = p.clientY - a.top;
179
+ if (F.current = { x: A, y: b }, V.current) {
180
+ const { startX: H, from: S, to: u } = V.current, { width: T } = ut.current, w = Math.max(1, T - Tt), W = u - S + 1, $ = w / W, rt = -(p.clientX - H) / $;
181
+ let Q = S + rt, E = u + rt;
182
+ const v = I.current.length;
183
+ Q < 0 && (Zt(), Q = 0, E = W - 1), E > v - 1 && (E = v - 1, Q = E - W + 1), y.current = { from: Q, to: E }, lt.current?.(y.current, I.current);
184
+ }
185
+ const R = gt(a.width, a.height, nt, ot), m = y.current;
186
+ if (A >= R.plotLeft && A <= R.plotRight) {
187
+ const H = m.to - m.from + 1, S = R.plotWidth / H, u = Math.round(m.from + (A - R.plotLeft) / S - 0.5), T = I.current, w = Math.max(0, Math.min(T.length - 1, u)), W = T[w] ?? null, $ = Pe(b, R, T, m.from, m.to);
188
+ at({ barIndex: w, bar: W, priceAtCursor: $ });
189
+ } else
190
+ at(null);
191
+ O();
192
+ },
193
+ [nt, ot, O, at]
194
+ ), Xt = X((p) => {
195
+ p.currentTarget.releasePointerCapture(p.pointerId), V.current = null;
196
+ }, []), Yt = X(() => {
197
+ F.current = null, V.current = null, at(null), O();
198
+ }, [O, at]), Vt = X(
199
+ (p) => {
200
+ p.preventDefault();
201
+ const a = p.currentTarget.getBoundingClientRect(), A = p.clientX - a.left, b = gt(a.width, a.height, nt, ot), R = y.current, m = I.current;
202
+ if (m.length === 0) return;
203
+ const H = R.to - R.from + 1, S = p.deltaY > 0 ? 1 + kt : 1 / (1 + kt), u = Math.max(
204
+ b.plotWidth / de,
205
+ Math.min(m.length, b.plotWidth / pe, H * S)
206
+ ), T = R.from + (A - b.plotLeft) / (b.plotWidth / H), w = (T - R.from) / H;
207
+ let W = T - w * u, $ = W + u - 1;
208
+ W < 0 && (W = 0, $ = u - 1), $ > m.length - 1 && ($ = m.length - 1, W = $ - u + 1), y.current = { from: W, to: $ }, lt.current?.(y.current, m), O();
209
+ },
210
+ [nt, ot, O]
211
+ ), zt = X(
212
+ (p) => {
213
+ const a = y.current, A = a.to - a.from + 1, b = I.current;
214
+ if (b.length === 0) return;
215
+ let R = 0;
216
+ if (p.key === "ArrowLeft") R = -Math.max(1, Math.floor(A * 0.1));
217
+ else if (p.key === "ArrowRight") R = Math.max(1, Math.floor(A * 0.1));
218
+ else return;
219
+ p.preventDefault();
220
+ let m = a.from + R, H = a.to + R;
221
+ m < 0 && (m = 0, H = A - 1), H > b.length - 1 && (H = b.length - 1, m = H - A + 1), y.current = { from: m, to: H }, lt.current?.(y.current, b), O();
222
+ },
223
+ [O]
224
+ ), Zt = X(() => {
225
+ if (G.current) return;
226
+ const p = I.current;
227
+ if (p.length === 0) return;
228
+ G.current = !0;
229
+ const a = $t(e), A = p[0].time, b = A - a * s, R = A - a;
230
+ t.getBars({ symbol: n, resolution: e, from: b, to: R, countBack: s }).then((m) => {
231
+ if (m.length === 0) {
232
+ G.current = !1;
233
+ return;
234
+ }
235
+ const S = [...m].sort((T, w) => T.time - w.time).filter((T) => T.time < A), u = y.current;
236
+ I.current = [...S, ...p], y.current = { from: u.from + S.length, to: u.to + S.length }, G.current = !1, O();
237
+ }).catch(() => {
238
+ G.current = !1;
239
+ });
240
+ }, [t, n, e, s, O]);
241
+ return /* @__PURE__ */ et(
242
+ "div",
243
+ {
244
+ ref: z,
245
+ className: ee(mt.root, _),
246
+ style: { ...J, height: c, position: "relative" },
247
+ tabIndex: 0,
248
+ role: "figure",
249
+ "aria-label": `${n} ${e} chart`,
250
+ onKeyDown: zt,
251
+ children: [
252
+ /* @__PURE__ */ x(
253
+ "canvas",
254
+ {
255
+ ref: Z,
256
+ className: mt.svg,
257
+ onPointerDown: Ft,
258
+ onPointerMove: Nt,
259
+ onPointerUp: Xt,
260
+ onPointerLeave: Yt,
261
+ onWheel: Vt,
262
+ style: { cursor: V.current ? "grabbing" : "crosshair", touchAction: "none" }
263
+ }
264
+ ),
265
+ /* @__PURE__ */ et(
266
+ "div",
267
+ {
268
+ className: mt.tradingHeader,
269
+ style: {
270
+ position: "absolute",
271
+ top: ue,
272
+ left: 8,
273
+ right: 8,
274
+ pointerEvents: "none",
275
+ display: "flex",
276
+ alignItems: "center",
277
+ justifyContent: "space-between",
278
+ gap: 8
279
+ },
280
+ children: [
281
+ /* @__PURE__ */ et("div", { style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }, children: [
282
+ /* @__PURE__ */ x("strong", { children: n }),
283
+ /* @__PURE__ */ x("span", { style: { color: "var(--crk-color-text-muted)" }, children: e }),
284
+ st?.bar && /* @__PURE__ */ et("span", { style: { color: "var(--crk-color-text-muted)", whiteSpace: "nowrap" }, children: [
285
+ "O ",
286
+ st.bar.open.toFixed(i),
287
+ " · H ",
288
+ st.bar.high.toFixed(i),
289
+ " · L",
290
+ " ",
291
+ st.bar.low.toFixed(i),
292
+ " · C ",
293
+ st.bar.close.toFixed(i)
294
+ ] })
295
+ ] }),
296
+ C && /* @__PURE__ */ x("div", { style: { pointerEvents: "auto" }, children: /* @__PURE__ */ x(
297
+ se,
298
+ {
299
+ position: "bottom",
300
+ asChild: !0,
301
+ trigger: /* @__PURE__ */ x(
302
+ ae,
303
+ {
304
+ variant: "ghost",
305
+ size: "sm",
306
+ iconOnly: !0,
307
+ "aria-label": "Chart settings",
308
+ children: /* @__PURE__ */ x(ve, {})
309
+ }
310
+ ),
311
+ content: /* @__PURE__ */ x(
312
+ Te,
313
+ {
314
+ timezone: dt,
315
+ onTimezoneChange: _t
316
+ }
317
+ )
318
+ }
319
+ ) })
320
+ ]
321
+ }
322
+ )
323
+ ]
324
+ }
325
+ );
326
+ }
327
+ const Me = [
328
+ { value: "local", label: "Local time" },
329
+ { value: "utc", label: "UTC" },
330
+ { value: "America/New_York", label: "America / New York" },
331
+ { value: "America/Los_Angeles", label: "America / Los Angeles" },
332
+ { value: "Europe/London", label: "Europe / London" },
333
+ { value: "Europe/Berlin", label: "Europe / Berlin" },
334
+ { value: "Asia/Tokyo", label: "Asia / Tokyo" },
335
+ { value: "Asia/Singapore", label: "Asia / Singapore" }
336
+ ];
337
+ function Te({
338
+ timezone: t,
339
+ onTimezoneChange: n
340
+ }) {
341
+ return /* @__PURE__ */ et("div", { style: { minWidth: 220, padding: 4 }, children: [
342
+ /* @__PURE__ */ x(
343
+ "div",
344
+ {
345
+ style: {
346
+ fontWeight: 600,
347
+ fontSize: "var(--crk-font-size-sm)",
348
+ padding: "4px 4px 8px"
349
+ },
350
+ children: "Settings"
351
+ }
352
+ ),
353
+ /* @__PURE__ */ et("label", { style: { display: "flex", flexDirection: "column", gap: 4, padding: "4px" }, children: [
354
+ /* @__PURE__ */ x("span", { style: { fontSize: "var(--crk-font-size-xs)", color: "var(--crk-color-text-muted)" }, children: "Timezone" }),
355
+ /* @__PURE__ */ x(
356
+ ce,
357
+ {
358
+ options: Me.map((e) => ({ value: e.value, label: e.label })),
359
+ value: t,
360
+ onChange: (e) => n(e)
361
+ }
362
+ )
363
+ ] })
364
+ ] });
365
+ }
366
+ function ve() {
367
+ return /* @__PURE__ */ et(
368
+ "svg",
369
+ {
370
+ viewBox: "0 0 24 24",
371
+ fill: "none",
372
+ stroke: "currentColor",
373
+ strokeWidth: 2,
374
+ strokeLinecap: "round",
375
+ strokeLinejoin: "round",
376
+ "aria-hidden": "true",
377
+ children: [
378
+ /* @__PURE__ */ x("circle", { cx: "12", cy: "12", r: "3" }),
379
+ /* @__PURE__ */ x("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" })
380
+ ]
381
+ }
382
+ );
383
+ }
384
+ function gt(t, n, e, o) {
385
+ const l = Math.max(0, t - Tt), i = he, s = Math.max(i, n - vt), c = Math.max(0, l - 0), g = Math.max(0, s - i);
386
+ let h = g, f = i;
387
+ const d = { top: i, bottom: s, height: g };
388
+ let M = null, k = null;
389
+ const C = e ? At.rsi : 0, L = o ? At.volume : 0;
390
+ return h = g * (1 - C - L), d.top = f, d.height = h, d.bottom = d.top + h, f = d.bottom, e && (M = { top: f, height: g * C, bottom: f + g * C }, f = M.bottom), o && (k = { top: f, height: g * L, bottom: f + g * L }), { width: t, height: n, plotLeft: 0, plotRight: l, plotTop: i, plotBottom: s, plotWidth: c, plotHeight: g, main: d, rsi: M, volume: k };
391
+ }
392
+ function we(t, n) {
393
+ if (n === 0) return { from: 0, to: 0 };
394
+ let { from: e, to: o } = t;
395
+ if (o >= n) {
396
+ const r = o - e;
397
+ o = n - 1, e = Math.max(0, o - r);
398
+ }
399
+ return e < 0 && (e = 0), o < e && (o = e), { from: e, to: o };
400
+ }
401
+ function ye(t, n) {
402
+ if (t.type === "sma")
403
+ return { kind: "line", values: oe(n, t.period), color: t.color ?? "var(--crk-chart-2)" };
404
+ if (t.type === "ema")
405
+ return { kind: "line", values: re(n, t.period), color: t.color ?? "var(--crk-chart-3)" };
406
+ if (t.type === "bollinger") {
407
+ const e = ie(n, t.period, t.stdDev ?? 2);
408
+ return {
409
+ kind: "bollinger",
410
+ middle: e.middle,
411
+ upper: e.upper,
412
+ lower: e.lower,
413
+ color: t.color ?? "var(--crk-chart-4)",
414
+ fillOpacity: t.fillOpacity ?? 0.1
415
+ };
416
+ }
417
+ return null;
418
+ }
419
+ function Bt(t, n, e, o, r) {
420
+ let l = 1 / 0, i = -1 / 0;
421
+ for (const f of n)
422
+ f.low < l && (l = f.low), f.high > i && (i = f.high);
423
+ for (const f of e) {
424
+ const d = f.kind === "line" ? [f.values] : [f.upper, f.lower];
425
+ for (const M of d) {
426
+ const k = Math.max(0, Math.floor(o)), C = Math.min(M.length - 1, Math.ceil(r));
427
+ for (let L = k; L <= C; L++) {
428
+ const P = M[L];
429
+ P != null && (P < l && (l = P), P > i && (i = P));
430
+ }
431
+ }
432
+ }
433
+ (!isFinite(l) || !isFinite(i)) && (l = 0, i = 1);
434
+ const s = (i - l) * 0.08 || 1, c = Ht(l - s, i + s, 5), g = Math.min(c[0], l), h = Math.max(c[c.length - 1], i);
435
+ return { paneTop: t.top, paneBottom: t.bottom, paneHeight: t.height, priceMin: g, priceMax: h, ticks: c };
436
+ }
437
+ function be(t, n, e, o) {
438
+ let r = 0;
439
+ const l = Math.max(0, Math.floor(e)), i = Math.min(n.length - 1, Math.ceil(o));
440
+ for (let g = l; g <= i; g++) {
441
+ const h = n[g].volume ?? 0;
442
+ h > r && (r = h);
443
+ }
444
+ const s = Ht(0, r || 1, 3), c = Math.max(s[s.length - 1], r);
445
+ return { paneTop: t.top, paneBottom: t.bottom, paneHeight: t.height, priceMin: 0, priceMax: c, ticks: s };
446
+ }
447
+ function B(t, n) {
448
+ const e = (t - n.priceMin) / (n.priceMax - n.priceMin || 1);
449
+ return n.paneBottom - e * n.paneHeight;
450
+ }
451
+ function Dt(t) {
452
+ if (!t || typeof getComputedStyle > "u") return (r) => r;
453
+ const n = getComputedStyle(t), e = /* @__PURE__ */ new Map(), o = (r) => {
454
+ if (!r || !r.includes("var(")) return r;
455
+ const l = e.get(r);
456
+ if (l !== void 0) return l;
457
+ const i = /var\(\s*(--[a-zA-Z0-9_-]+)/.exec(r);
458
+ if (!i)
459
+ return e.set(r, r), r;
460
+ const s = n.getPropertyValue(i[1]).trim();
461
+ if (!s)
462
+ return e.set(r, r), r;
463
+ const c = s.includes("var(") ? o(s) : s;
464
+ return e.set(r, c), c;
465
+ };
466
+ return o;
467
+ }
468
+ function Re(t, n) {
469
+ const e = Dt(t);
470
+ return {
471
+ up: e(n.up),
472
+ down: e(n.down),
473
+ line: e(n.line),
474
+ text: e("var(--crk-color-text)") || "#0f172a",
475
+ textMuted: e("var(--crk-color-text-muted)") || "#94a3b8",
476
+ axis: e("var(--crk-chart-axis)") || "#94a3b8",
477
+ grid: e("var(--crk-chart-grid)") || "#e2e8f0",
478
+ bg: e("var(--crk-color-bg)") || "#ffffff"
479
+ };
480
+ }
481
+ function Se(t, n, e, o) {
482
+ t.fillStyle = o.textMuted, t.font = "13px system-ui, sans-serif", t.textAlign = "center", t.textBaseline = "middle", t.fillText("Loading…", n / 2, e / 2);
483
+ }
484
+ function Mt(t, n, e, o, r, l = !1) {
485
+ t.strokeStyle = r.grid, t.lineWidth = 1, t.beginPath();
486
+ for (const i of o.ticks) {
487
+ const s = Math.round(B(i, o)) + 0.5;
488
+ t.moveTo(n, s), t.lineTo(e, s);
489
+ }
490
+ t.stroke();
491
+ }
492
+ function Ae(t, n, e, o, r) {
493
+ t.fillStyle = r.axis, t.font = "11px system-ui, sans-serif", t.textAlign = "left", t.textBaseline = "middle";
494
+ for (const l of e.ticks) {
495
+ const i = B(l, e);
496
+ t.fillText(l.toFixed(o), n.plotRight + 6, i);
497
+ }
498
+ }
499
+ function ke(t, n, e, o, r, l, i, s) {
500
+ const c = Math.max(0, Math.floor(e)), g = Math.min(n.length - 1, Math.ceil(o)), h = Math.max(1, l * 0.7);
501
+ for (let f = c; f <= g; f++) {
502
+ const d = n[f], M = r(f), k = B(d.open, i), C = B(d.close, i), L = B(d.high, i), P = B(d.low, i), N = d.close >= d.open ? s.up : s.down;
503
+ t.strokeStyle = N, t.fillStyle = N, t.beginPath();
504
+ const Y = Math.round(M) + 0.5;
505
+ t.moveTo(Y, L), t.lineTo(Y, P), t.stroke();
506
+ const _ = Math.min(k, C), J = Math.max(1, Math.abs(C - k));
507
+ t.fillRect(Math.round(M - h / 2), Math.round(_), Math.round(h), Math.round(J));
508
+ }
509
+ }
510
+ function Ce(t, n, e, o, r, l, i, s) {
511
+ const c = Math.max(0, Math.floor(e)), g = Math.min(n.length - 1, Math.ceil(o)), h = Math.max(2, Math.min(l * 0.4, 8));
512
+ t.lineWidth = Math.max(1, Math.min(2, l * 0.18)), t.lineCap = "butt";
513
+ for (let f = c; f <= g; f++) {
514
+ const d = n[f], M = Math.round(r(f)) + 0.5, k = B(d.high, i), C = B(d.low, i), L = B(d.open, i), P = B(d.close, i), j = d.close >= d.open;
515
+ t.strokeStyle = j ? s.up : s.down, t.beginPath(), t.moveTo(M, k), t.lineTo(M, C), t.moveTo(M - h, L), t.lineTo(M, L), t.moveTo(M, P), t.lineTo(M + h, P), t.stroke();
516
+ }
517
+ }
518
+ function Le(t, n, e, o, r, l, i, s) {
519
+ const c = Math.max(0, Math.floor(e)), g = Math.min(n.length - 1, Math.ceil(o));
520
+ if (!(g <= c)) {
521
+ t.strokeStyle = i, t.lineWidth = 1.5, t.beginPath(), t.moveTo(r(c), B(n[c].close, l));
522
+ for (let h = c + 1; h <= g; h++)
523
+ t.lineTo(r(h), B(n[h].close, l));
524
+ t.stroke(), s && (t.globalAlpha = 0.18, t.fillStyle = i, t.lineTo(r(g), l.paneBottom), t.lineTo(r(c), l.paneBottom), t.closePath(), t.fill(), t.globalAlpha = 1);
525
+ }
526
+ }
527
+ function We(t, n, e, o, r, l, i, s) {
528
+ if (n.kind === "line") {
529
+ ft(t, n.values, r, l, i, s, n.color);
530
+ return;
531
+ }
532
+ const c = Math.max(0, Math.floor(r)), g = Math.min(o.length - 1, Math.ceil(l));
533
+ t.globalAlpha = n.fillOpacity, t.fillStyle = n.color, t.beginPath();
534
+ let h = !1;
535
+ for (let f = c; f <= g; f++) {
536
+ const d = n.upper[f];
537
+ if (d == null) continue;
538
+ const M = i(f), k = B(d, s);
539
+ h ? t.lineTo(M, k) : (t.moveTo(M, k), h = !0);
540
+ }
541
+ for (let f = g; f >= c; f--) {
542
+ const d = n.lower[f];
543
+ d != null && t.lineTo(i(f), B(d, s));
544
+ }
545
+ t.closePath(), t.fill(), t.globalAlpha = 1, ft(t, n.upper, r, l, i, s, n.color), ft(t, n.lower, r, l, i, s, n.color), ft(t, n.middle, r, l, i, s, n.color);
546
+ }
547
+ function ft(t, n, e, o, r, l, i) {
548
+ t.strokeStyle = i, t.lineWidth = 1.25, t.beginPath();
549
+ let s = !1;
550
+ const c = Math.max(0, Math.floor(e)), g = Math.min(n.length - 1, Math.ceil(o));
551
+ for (let h = c; h <= g; h++) {
552
+ const f = n[h];
553
+ if (f == null) {
554
+ s = !1;
555
+ continue;
556
+ }
557
+ const d = r(h), M = B(f, l);
558
+ s ? t.lineTo(d, M) : (t.moveTo(d, M), s = !0);
559
+ }
560
+ t.stroke();
561
+ }
562
+ function $e(t, n, e, o, r, l, i, s) {
563
+ const c = Math.max(0, Math.floor(e)), g = Math.min(n.length - 1, Math.ceil(o)), h = Math.max(1, l * 0.7);
564
+ for (let f = c; f <= g; f++) {
565
+ const d = n[f], M = d.volume ?? 0;
566
+ if (M === 0) continue;
567
+ const k = d.close >= d.open;
568
+ t.fillStyle = k ? s.up : s.down, t.globalAlpha = 0.55;
569
+ const C = B(M, i), L = i.paneBottom - C;
570
+ t.fillRect(Math.round(r(f) - h / 2), Math.round(C), Math.round(h), Math.round(L));
571
+ }
572
+ t.globalAlpha = 1;
573
+ }
574
+ function He(t, n, e, o, r, l) {
575
+ t.strokeStyle = l.grid, t.setLineDash([3, 3]), t.beginPath();
576
+ for (const i of [o, r]) {
577
+ const s = Math.round(B(i, e)) + 0.5;
578
+ t.moveTo(n.plotLeft, s), t.lineTo(n.plotRight, s);
579
+ }
580
+ t.stroke(), t.setLineDash([]), t.fillStyle = l.axis, t.font = "10px system-ui, sans-serif", t.textAlign = "left", t.textBaseline = "middle", t.fillText(String(o), n.plotRight + 6, B(o, e)), t.fillText(String(r), n.plotRight + 6, B(r, e));
581
+ }
582
+ function Ct(t, n, e, o, r) {
583
+ t.fillStyle = r.textMuted, t.font = "11px system-ui, sans-serif", t.textAlign = "left", t.textBaseline = "top", t.fillText(o, n.plotLeft + 6, e.top + 4);
584
+ }
585
+ function Be(t, n, e, o, r, l, i) {
586
+ const s = r - o + 1, c = n.plotWidth / s, g = Math.max(1, Math.round(80 / c));
587
+ t.fillStyle = i.axis, t.font = "11px system-ui, sans-serif", t.textAlign = "center", t.textBaseline = "middle";
588
+ const h = Math.max(0, Math.floor(o)), f = Math.min(e.length - 1, Math.ceil(r)), d = n.plotBottom + vt / 2;
589
+ for (let M = h; M <= f; M += g) {
590
+ const k = e[M], C = n.plotLeft + (M - o + 0.5) * c;
591
+ t.fillText(Ie(k.time, l), C, d);
592
+ }
593
+ }
594
+ function De(t, n, e, o, r, l, i, s, c, g, h, f, d, M, k) {
595
+ if (e.x < n.plotLeft || e.x > n.plotRight) return;
596
+ const C = l - r + 1, L = n.plotWidth / C, P = r + (e.x - n.plotLeft) / L - 0.5, j = Math.round(P), N = Math.max(0, Math.min(o.length - 1, j)), Y = i(N);
597
+ if (t.save(), t.strokeStyle = h.textMuted, t.setLineDash([3, 3]), t.lineWidth = 1, t.beginPath(), t.moveTo(Y + 0.5, n.plotTop), t.lineTo(Y + 0.5, n.plotBottom), t.moveTo(n.plotLeft, e.y + 0.5), t.lineTo(n.plotRight, e.y + 0.5), t.stroke(), t.setLineDash([]), e.y >= c.paneTop && e.y <= c.paneBottom) {
598
+ const _ = c.priceMax - (e.y - c.paneTop) / c.paneHeight * (c.priceMax - c.priceMin);
599
+ t.fillStyle = h.text, t.fillRect(n.plotRight, e.y - 9, Tt, 18), t.fillStyle = h.bg, t.font = "11px system-ui, sans-serif", t.textAlign = "left", t.textBaseline = "middle", t.fillText(_.toFixed(s), n.plotRight + 6, e.y);
600
+ }
601
+ if (o[N]) {
602
+ const _ = It(o[N].time, g);
603
+ t.font = "11px system-ui, sans-serif", t.textBaseline = "middle";
604
+ const Z = t.measureText(_).width + 8 * 2, I = vt, y = Math.max(
605
+ n.plotLeft,
606
+ Math.min(n.plotRight - Z, Y - Z / 2)
607
+ ), F = n.plotBottom;
608
+ t.fillStyle = h.text, t.fillRect(y, F, Z, I), t.fillStyle = h.bg, t.textAlign = "center", t.fillText(_, y + Z / 2, F + I / 2);
609
+ }
610
+ if (o[N]) {
611
+ const _ = o[N], J = _.close.toFixed(s);
612
+ let z = J;
613
+ if (M) {
614
+ const K = (k ?? Pt)(_.time, f, g);
615
+ K && (z = `${J} · ${K}`);
616
+ }
617
+ t.font = "11px system-ui, sans-serif", t.textBaseline = "middle";
618
+ const y = t.measureText(z).width + 8 * 2, F = 18, V = Math.max(
619
+ n.plotLeft,
620
+ Math.min(n.plotRight - y, Y - y / 2)
621
+ ), G = Math.max(0, n.plotTop - F - 2);
622
+ if (d) {
623
+ const K = _.close >= _.open;
624
+ t.fillStyle = K ? h.up : h.down, t.fillRect(V, G, y, F), t.fillStyle = "#ffffff";
625
+ } else
626
+ t.fillStyle = h.text, t.fillRect(V, G, y, F), t.fillStyle = h.bg;
627
+ t.textAlign = "center", t.fillText(z, V + y / 2, G + F / 2);
628
+ }
629
+ t.restore();
630
+ }
631
+ function Pe(t, n, e, o, r, l, i) {
632
+ const s = e.slice(Math.max(0, Math.floor(o)), Math.min(e.length, Math.ceil(r) + 1)), c = Bt(n.main, s, [], o, r);
633
+ return t < c.paneTop || t > c.paneBottom ? null : c.priceMax - (t - c.paneTop) / c.paneHeight * (c.priceMax - c.priceMin);
634
+ }
635
+ function Ie(t, n) {
636
+ const e = new Date(t * 1e3);
637
+ return n === "D" || n === "W" || n === "M" ? `${e.getUTCFullYear()}-${D(e.getUTCMonth() + 1)}-${D(e.getUTCDate())}` : `${D(e.getUTCHours())}:${D(e.getUTCMinutes())}`;
638
+ }
639
+ const Lt = [
640
+ "Jan",
641
+ "Feb",
642
+ "Mar",
643
+ "Apr",
644
+ "May",
645
+ "Jun",
646
+ "Jul",
647
+ "Aug",
648
+ "Sep",
649
+ "Oct",
650
+ "Nov",
651
+ "Dec"
652
+ ], Wt = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
653
+ function Pt(t, n, e) {
654
+ const o = new Date(t * 1e3), r = n === "D" || n === "W" || n === "M";
655
+ let l, i, s, c, g, h;
656
+ if (e === "local")
657
+ l = o.getDate(), i = o.getMonth(), s = o.getFullYear(), c = o.getHours(), g = o.getMinutes(), h = o.getDay();
658
+ else if (e === "utc")
659
+ l = o.getUTCDate(), i = o.getUTCMonth(), s = o.getUTCFullYear(), c = o.getUTCHours(), g = o.getUTCMinutes(), h = o.getUTCDay();
660
+ else
661
+ try {
662
+ const d = new Intl.DateTimeFormat("en-US", {
663
+ timeZone: e,
664
+ year: "numeric",
665
+ month: "2-digit",
666
+ day: "2-digit",
667
+ hour: "2-digit",
668
+ minute: "2-digit",
669
+ weekday: "short",
670
+ hour12: !1,
671
+ hourCycle: "h23"
672
+ }).formatToParts(o), M = (L) => d.find((P) => P.type === L)?.value ?? "";
673
+ l = Number(M("day")), i = Number(M("month")) - 1, s = Number(M("year")), c = Number(M("hour")), g = Number(M("minute"));
674
+ const k = M("weekday"), C = Wt.indexOf(k);
675
+ h = C >= 0 ? C : 0;
676
+ } catch {
677
+ return Pt(t, n, "utc");
678
+ }
679
+ return r ? `${l} ${Lt[i]} ${s}` : `${Wt[h]} ${l} ${Lt[i]} ${D(c)}:${D(g)}`;
680
+ }
681
+ function It(t, n) {
682
+ const e = new Date(t * 1e3);
683
+ if (n === "local")
684
+ return `${e.getFullYear()}-${D(e.getMonth() + 1)}-${D(e.getDate())} ${D(e.getHours())}:${D(e.getMinutes())}:${D(e.getSeconds())} ${Oe(e)}`;
685
+ if (n === "utc")
686
+ return `${e.getUTCFullYear()}-${D(e.getUTCMonth() + 1)}-${D(e.getUTCDate())} ${D(e.getUTCHours())}:${D(e.getUTCMinutes())}:${D(e.getUTCSeconds())} UTC`;
687
+ try {
688
+ const r = new Intl.DateTimeFormat("en-CA", {
689
+ timeZone: n,
690
+ year: "numeric",
691
+ month: "2-digit",
692
+ day: "2-digit",
693
+ hour: "2-digit",
694
+ minute: "2-digit",
695
+ second: "2-digit",
696
+ hour12: !1,
697
+ hourCycle: "h23",
698
+ timeZoneName: "short"
699
+ }).formatToParts(e), l = (s) => r.find((c) => c.type === s)?.value ?? "", i = l("timeZoneName") || n;
700
+ return `${l("year")}-${l("month")}-${l("day")} ${l("hour")}:${l("minute")}:${l("second")} ${i}`;
701
+ } catch {
702
+ return It(t, "utc");
703
+ }
704
+ }
705
+ function Oe(t) {
706
+ const n = -t.getTimezoneOffset(), e = n >= 0 ? "+" : "-", o = Math.abs(n);
707
+ return `${e}${D(Math.floor(o / 60))}:${D(o % 60)}`;
708
+ }
709
+ function D(t) {
710
+ return t < 10 ? `0${t}` : String(t);
711
+ }
712
+ function $t(t) {
713
+ if (t === "D") return 86400;
714
+ if (t === "W") return 86400 * 7;
715
+ if (t === "M") return 86400 * 30;
716
+ const n = Number(t);
717
+ if (Number.isFinite(n)) return n * 60;
718
+ const e = /^(\d+)([HhDdWwMm])$/.exec(t);
719
+ if (e) {
720
+ const o = Number(e[1]), r = e[2].toUpperCase();
721
+ if (r === "H") return o * 3600;
722
+ if (r === "D") return o * 86400;
723
+ if (r === "W") return o * 86400 * 7;
724
+ if (r === "M") return o * 60;
725
+ }
726
+ return 60;
727
+ }
728
+ export {
729
+ Ze as TradingChart,
730
+ $t as approxIntervalSeconds,
731
+ It as formatCrosshairTime
732
+ };