velo-plot 1.15.0 → 2.0.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 (104) hide show
  1. package/dist/{ChartCore-BimVvUEg.js → ChartCore-BhQ4j7f5.js} +2213 -1489
  2. package/dist/ChartCore-BhQ4j7f5.js.map +1 -0
  3. package/dist/SciPlot-GJvw7GJo.js +463 -0
  4. package/dist/SciPlot-GJvw7GJo.js.map +1 -0
  5. package/dist/assets/downsample.worker-C70QJ04y.js +2 -0
  6. package/dist/assets/downsample.worker-C70QJ04y.js.map +1 -0
  7. package/dist/assets/indicator.worker-bv0zC4EX.js +2 -0
  8. package/dist/assets/indicator.worker-bv0zC4EX.js.map +1 -0
  9. package/dist/axisFormat-SPX-CD5s.js +200 -0
  10. package/dist/axisFormat-SPX-CD5s.js.map +1 -0
  11. package/dist/core/InteractionManager.d.ts +1 -0
  12. package/dist/core/OverlayRenderer.d.ts +13 -0
  13. package/dist/core/chart/ChartAlerts.d.ts +42 -0
  14. package/dist/core/chart/ChartCore.d.ts +24 -1
  15. package/dist/core/chart/ChartRenderLoop.d.ts +9 -2
  16. package/dist/core/chart/ChartRenderer.d.ts +8 -2
  17. package/dist/core/chart/candlestickMarkers.d.ts +23 -0
  18. package/dist/core/chart/heikinAshi.d.ts +10 -0
  19. package/dist/core/chart/positionLines.d.ts +12 -0
  20. package/dist/core/chart/series/types.d.ts +2 -2
  21. package/dist/core/chart/types.d.ts +9 -0
  22. package/dist/core/format/axisFormat.d.ts +2 -1
  23. package/dist/core/indicator/addIndicator.d.ts +36 -0
  24. package/dist/core/indicator/index.d.ts +2 -0
  25. package/dist/core/indicator/indicatorPresets.d.ts +45 -0
  26. package/dist/core/series/Series.d.ts +3 -0
  27. package/dist/core/stacked/types.d.ts +8 -0
  28. package/dist/core/time/TimeScale.d.ts +31 -0
  29. package/dist/core/time/applyTimeScale.d.ts +10 -0
  30. package/dist/createStackedChart-DJSmqerD.js +706 -0
  31. package/dist/createStackedChart-DJSmqerD.js.map +1 -0
  32. package/dist/gpu/adapter/gpuRenderer.d.ts +21 -0
  33. package/dist/gpu/backends/webgpu/WebGPUBackend.d.ts +2 -1
  34. package/dist/gpuRenderer-BpaMYz-k.js +1848 -0
  35. package/dist/gpuRenderer-BpaMYz-k.js.map +1 -0
  36. package/dist/{index-DjeWClO9.js → index-CWipqOLP.js} +2 -2
  37. package/dist/{index-DjeWClO9.js.map → index-CWipqOLP.js.map} +1 -1
  38. package/dist/index-D7dTq6VB.js +503 -0
  39. package/dist/index-D7dTq6VB.js.map +1 -0
  40. package/dist/{index-Ce2JgkH_.js → index-DoYxf1cV.js} +86 -43
  41. package/dist/{index-Ce2JgkH_.js.map → index-DoYxf1cV.js.map} +1 -1
  42. package/dist/{index.core-C_-CFftD.js → index.core-fpZ1dYN0.js} +3 -3
  43. package/dist/{index.core-C_-CFftD.js.map → index.core-fpZ1dYN0.js.map} +1 -1
  44. package/dist/index.d.ts +17 -4
  45. package/dist/indicators--eJGmVox.js +302 -0
  46. package/dist/indicators--eJGmVox.js.map +1 -0
  47. package/dist/mockDatafeed-Cdg5hKEo.js +511 -0
  48. package/dist/mockDatafeed-Cdg5hKEo.js.map +1 -0
  49. package/dist/plugins/analysis.js +530 -807
  50. package/dist/plugins/analysis.js.map +1 -1
  51. package/dist/plugins/caching.js +26 -21
  52. package/dist/plugins/caching.js.map +1 -1
  53. package/dist/plugins/drawing-tools/index.d.ts +29 -0
  54. package/dist/plugins/drawing-tools/measure.d.ts +21 -0
  55. package/dist/plugins/drawing-tools/snapToCandle.d.ts +21 -0
  56. package/dist/plugins/gpu.js +202 -1895
  57. package/dist/plugins/gpu.js.map +1 -1
  58. package/dist/plugins/index.d.ts +2 -0
  59. package/dist/plugins/keyboard/index.d.ts +1 -7
  60. package/dist/plugins/keyboard.js +1 -1
  61. package/dist/plugins/lazy-load/types.d.ts +7 -0
  62. package/dist/plugins/lazy-load.js +131 -108
  63. package/dist/plugins/lazy-load.js.map +1 -1
  64. package/dist/plugins/replay/index.d.ts +19 -0
  65. package/dist/plugins/tools.js +1 -1
  66. package/dist/plugins/virtualization/types.d.ts +12 -0
  67. package/dist/plugins/virtualization.js +1 -1
  68. package/dist/pool-15HMCNv8.js +88 -0
  69. package/dist/pool-15HMCNv8.js.map +1 -0
  70. package/dist/react.js +5 -5
  71. package/dist/renderer/CandlestickRenderer.d.ts +1 -1
  72. package/dist/renderer/ChartSeriesRenderer.d.ts +6 -0
  73. package/dist/renderer/GpuChartRenderer.d.ts +23 -0
  74. package/dist/renderer/index.d.ts +3 -0
  75. package/dist/renderer/spike/WebGLGridSpike.d.ts +40 -0
  76. package/dist/testing/baselines/v1.15.0.json.d.ts +51 -0
  77. package/dist/testing/gridSpikeBenchmark.d.ts +49 -0
  78. package/dist/testing/index.d.ts +5 -0
  79. package/dist/testing/rendererBenchmark.d.ts +13 -0
  80. package/dist/testing/stage1BrowserBench.d.ts +42 -0
  81. package/dist/trading/datafeed.d.ts +48 -0
  82. package/dist/trading/index.d.ts +29 -0
  83. package/dist/trading/mockDatafeed.d.ts +9 -0
  84. package/dist/trading/ohlcvGenerator.d.ts +25 -0
  85. package/dist/trading.d.ts +1 -0
  86. package/dist/trading.js +95 -0
  87. package/dist/trading.js.map +1 -0
  88. package/dist/types.d.ts +22 -2
  89. package/dist/velo-plot.full.js +1088 -776
  90. package/dist/velo-plot.full.js.map +1 -1
  91. package/dist/velo-plot.js +15 -15
  92. package/dist/workers/downsample.d.ts +38 -0
  93. package/dist/workers/downsampleAsync.d.ts +6 -0
  94. package/dist/workers/indicator.worker.d.ts +32 -0
  95. package/dist/workers/indicatorsAsync.d.ts +26 -0
  96. package/dist/workers/pool.d.ts +36 -0
  97. package/package.json +23 -1
  98. package/dist/ChartCore-BimVvUEg.js.map +0 -1
  99. package/dist/axisFormat-B7o_uIEA.js +0 -127
  100. package/dist/axisFormat-B7o_uIEA.js.map +0 -1
  101. package/dist/createStackedChart-CjsKcOvX.js +0 -1088
  102. package/dist/createStackedChart-CjsKcOvX.js.map +0 -1
  103. package/dist/index-ChgIdk3N.js +0 -229
  104. package/dist/index-ChgIdk3N.js.map +0 -1
@@ -0,0 +1,706 @@
1
+ import { m as Lt, M as G, c as St, g as Yt, a as Bt, r as _t, h as Ot, b as jt, i as Nt } from "./ChartCore-BhQ4j7f5.js";
2
+ import { c as Wt } from "./index-CUGS98p4.js";
3
+ const ot = 5, rt = 1 / 6, qt = { top: 4, bottom: 8, left: 4 }, Dt = { bottom: 55 };
4
+ function Gt(t) {
5
+ if (typeof t == "number") return t;
6
+ switch (t) {
7
+ case "8k":
8
+ return 8;
9
+ case "4k":
10
+ return 4;
11
+ case "2k":
12
+ return 2;
13
+ default:
14
+ return 1;
15
+ }
16
+ }
17
+ function Ut(t) {
18
+ return new Promise((n, o) => {
19
+ const r = new Image();
20
+ r.onload = () => n(r), r.onerror = o, r.src = t;
21
+ });
22
+ }
23
+ function Pt(t, n) {
24
+ const o = t.getBoundingClientRect();
25
+ return {
26
+ x: o.left - n.left,
27
+ y: o.top - n.top,
28
+ width: o.width,
29
+ height: o.height
30
+ };
31
+ }
32
+ async function Kt(t, n, o, r, a, d = {}) {
33
+ var h;
34
+ const {
35
+ format: b = "png",
36
+ quality: k = 0.92,
37
+ resolution: y = "standard",
38
+ includeBackground: R = !0,
39
+ includeDividers: X = !0,
40
+ transparent: H = !1
41
+ } = d, E = Gt(y), $ = (((h = o[0]) == null ? void 0 : h.getDPR()) ?? (typeof window < "u" ? window.devicePixelRatio : 1)) * E, _ = o.map((l) => l.getDPR());
42
+ try {
43
+ if (E > 1) {
44
+ for (const m of o)
45
+ m.setDPR($), m.render();
46
+ await new Promise((m) => requestAnimationFrame(m)), await new Promise((m) => setTimeout(m, 50));
47
+ }
48
+ const l = t.getBoundingClientRect(), T = Math.max(1, Math.round(l.width * $)), S = Math.max(1, Math.round(l.height * $)), u = document.createElement("canvas");
49
+ u.width = T, u.height = S;
50
+ const f = u.getContext("2d");
51
+ if (!f) throw new Error("Failed to create export canvas");
52
+ !H && R && (f.fillStyle = a || "#ffffff", f.fillRect(0, 0, T, S));
53
+ const g = b === "jpeg" ? "jpeg" : "png";
54
+ for (let m = 0; m < n.length; m++) {
55
+ const w = Pt(n[m], l), M = o[m].exportImage(g), A = await Ut(M);
56
+ f.drawImage(
57
+ A,
58
+ Math.round(w.x * $),
59
+ Math.round(w.y * $),
60
+ Math.round(w.width * $),
61
+ Math.round(w.height * $)
62
+ );
63
+ }
64
+ if (X && r.length) {
65
+ f.fillStyle = "rgba(128, 128, 128, 0.35)";
66
+ for (const m of r) {
67
+ const w = Pt(m, l);
68
+ f.fillRect(
69
+ Math.round(w.x * $),
70
+ Math.round(w.y * $),
71
+ Math.max(1, Math.round(w.width * $)),
72
+ Math.max(1, Math.round(w.height * $))
73
+ );
74
+ }
75
+ }
76
+ const v = b === "jpeg" ? "image/jpeg" : b === "webp" ? "image/webp" : "image/png";
77
+ return u.toDataURL(v, k);
78
+ } finally {
79
+ if (E > 1)
80
+ for (let l = 0; l < o.length; l++)
81
+ o[l].setDPR(_[l]), o[l].render();
82
+ }
83
+ }
84
+ const D = "velo-pane-divider", F = "velo-pane-resizing";
85
+ function Qt(t) {
86
+ if (typeof document > "u") return;
87
+ let n = document.getElementById("velo-pane-divider-styles");
88
+ n || (n = document.createElement("style"), n.id = "velo-pane-divider-styles", document.head.appendChild(n));
89
+ const r = t === "horizontal" ? "ew-resize" : "ns-resize";
90
+ n.textContent = `
91
+ .${D} {
92
+ flex: 0 0 var(--velo-divider-size, 6px);
93
+ position: relative;
94
+ cursor: ${r};
95
+ touch-action: none;
96
+ z-index: 20;
97
+ background: transparent;
98
+ user-select: none;
99
+ }
100
+ .${D}::after {
101
+ content: "";
102
+ position: absolute;
103
+ background: rgba(128, 128, 128, 0.35);
104
+ transition: background 0.15s;
105
+ }
106
+ .${D}[data-direction="vertical"]::after {
107
+ left: 0;
108
+ right: 0;
109
+ top: 50%;
110
+ transform: translateY(-50%);
111
+ height: 1px;
112
+ }
113
+ .${D}[data-direction="horizontal"]::after {
114
+ top: 0;
115
+ bottom: 0;
116
+ left: 50%;
117
+ transform: translateX(-50%);
118
+ width: 1px;
119
+ }
120
+ .${D}:hover::after,
121
+ .${F} .${D}::after {
122
+ background: rgba(0, 242, 255, 0.65);
123
+ }
124
+ .${D}[data-direction="vertical"]:hover::after,
125
+ .${F} .${D}[data-direction="vertical"]::after {
126
+ height: 2px;
127
+ }
128
+ .${D}[data-direction="horizontal"]:hover::after,
129
+ .${F} .${D}[data-direction="horizontal"]::after {
130
+ width: 2px;
131
+ }
132
+ .${D}-handle {
133
+ position: absolute;
134
+ left: 50%;
135
+ top: 50%;
136
+ transform: translate(-50%, -50%);
137
+ width: 32px;
138
+ height: 12px;
139
+ display: flex;
140
+ align-items: center;
141
+ justify-content: center;
142
+ opacity: 0;
143
+ transition: opacity 0.15s;
144
+ pointer-events: none;
145
+ color: rgba(0, 242, 255, 0.9);
146
+ font-size: 10px;
147
+ line-height: 1;
148
+ }
149
+ .${D}:hover .${D}-handle,
150
+ .${F} .${D}-handle {
151
+ opacity: 1;
152
+ }
153
+ .${F} {
154
+ cursor: ${r} !important;
155
+ }
156
+ .${F} * {
157
+ cursor: ${r} !important;
158
+ }
159
+ .${F} [data-pane-id] {
160
+ position: relative !important;
161
+ overflow: hidden !important;
162
+ }
163
+ `;
164
+ }
165
+ function Zt(t, n, o) {
166
+ const r = document.createElement("div");
167
+ r.className = D, r.dataset.dividerIndex = String(t), r.dataset.direction = o, r.style.setProperty("--velo-divider-size", `${n}px`);
168
+ const a = document.createElement("div");
169
+ return a.className = `${D}-handle`, a.textContent = o === "horizontal" ? "⇔" : "⇕", r.appendChild(a), r;
170
+ }
171
+ function Vt(t, n) {
172
+ const o = n === "horizontal" ? "min-width:0;" : "min-height:0;";
173
+ return typeof t == "number" ? `flex:${t} 1 0;${o}` : `flex:1 1 ${t};${o}`;
174
+ }
175
+ function kt(t, n, o = rt, r = 0) {
176
+ if (n < 1 || t <= 0) return 1;
177
+ const a = t * o, d = Math.max(r, a);
178
+ return Math.min(d, t / n);
179
+ }
180
+ function Jt(t, n, o = rt, r = 0) {
181
+ return kt(t, n, o, r);
182
+ }
183
+ function te(t, n) {
184
+ const o = t.length;
185
+ if (o === 0) return t;
186
+ const r = Math.max(1, Math.round(n)), a = t.reduce((y, R) => y + R, 0);
187
+ if (a <= 0) {
188
+ const y = Math.floor(r / o), R = t.map(() => y);
189
+ return R[o - 1] = r - y * (o - 1), R;
190
+ }
191
+ const d = t.map((y) => y / a * r), b = [];
192
+ let k = 0;
193
+ for (let y = 0; y < o - 1; y++)
194
+ b.push(Math.max(1, Math.round(d[y]))), k += b[y];
195
+ return b.push(Math.max(1, r - k)), b;
196
+ }
197
+ function ee(t, n, o, r, a = {}) {
198
+ const d = a.direction ?? "vertical", b = d === "horizontal";
199
+ Qt(d);
200
+ const k = a.minPaneRatio ?? rt, y = a.minPanePx ?? 0, R = a.dividerSize ?? 6, X = n.length, H = (h) => b ? Jt(h, X, k, y) : kt(h, X, k, y), E = [], W = [];
201
+ if (n.length < 2)
202
+ return { dividers: E, destroy: () => {
203
+ } };
204
+ const $ = () => {
205
+ const h = E.length * R, l = b ? t.clientWidth : t.clientHeight;
206
+ return Math.max(1, l - h);
207
+ }, _ = (h, l, T, S) => {
208
+ var A;
209
+ const u = $(), f = H(u), g = S.reduce(
210
+ (x, z, I) => I === h || I === l ? x : x + z,
211
+ 0
212
+ ), v = u - g;
213
+ let m = S[h] + T;
214
+ m = Math.max(f, Math.min(v - f, m));
215
+ const w = v - m;
216
+ S[h] = m, S[l] = w;
217
+ const M = r.reduce((x, z) => x + z, 0);
218
+ if (r[h] = m / u * M, r[l] = w / u * M, (A = a.onDragMove) == null || A.call(a, S, h, l), a.onResize) {
219
+ const x = {};
220
+ for (let z = 0; z < o.length; z++)
221
+ x[o[z]] = r[z];
222
+ a.onResize(x);
223
+ }
224
+ };
225
+ for (let h = 0; h < n.length - 1; h++) {
226
+ const l = Zt(h, R, d);
227
+ n[h].after(l), E.push(l);
228
+ const S = (u) => {
229
+ var w, M;
230
+ u.preventDefault(), l.setPointerCapture(u.pointerId), t.classList.add(F);
231
+ const f = ((w = a.onDragStart) == null ? void 0 : w.call(a, h, h + 1)) ?? n.map(
232
+ (A) => b ? A.getBoundingClientRect().width : A.getBoundingClientRect().height
233
+ );
234
+ (M = a.onDragMove) == null || M.call(a, f, h, h + 1);
235
+ let g = b ? u.clientX : u.clientY;
236
+ const v = (A) => {
237
+ const x = b ? A.clientX : A.clientY, z = x - g;
238
+ g = x, z !== 0 && _(h, h + 1, z, f);
239
+ }, m = (A) => {
240
+ var x;
241
+ l.releasePointerCapture(A.pointerId), t.classList.remove(F), l.removeEventListener("pointermove", v), l.removeEventListener("pointerup", m), l.removeEventListener("pointercancel", m), (x = a.onDragEnd) == null || x.call(a, f);
242
+ };
243
+ l.addEventListener("pointermove", v), l.addEventListener("pointerup", m), l.addEventListener("pointercancel", m);
244
+ };
245
+ l.addEventListener("pointerdown", S), W.push(() => l.removeEventListener("pointerdown", S));
246
+ }
247
+ return {
248
+ dividers: E,
249
+ destroy: () => {
250
+ for (const h of W) h();
251
+ for (const h of E) h.remove();
252
+ t.classList.remove(F);
253
+ }
254
+ };
255
+ }
256
+ function ne(t, n, o = "vertical") {
257
+ for (let r = 0; r < t.length; r++)
258
+ t[r].style.cssText = `${Vt(n[r], o)}position:relative;overflow:hidden;`;
259
+ }
260
+ function Rt(t) {
261
+ return typeof t == "number" ? t : 1;
262
+ }
263
+ function oe(t, n = 6) {
264
+ if (!Number.isFinite(t) || t <= 0) return n;
265
+ const o = Math.floor(t / 36);
266
+ return Math.max(2, Math.min(n, o));
267
+ }
268
+ function ie(t, n = 8) {
269
+ if (!Number.isFinite(t) || t <= 0) return n;
270
+ const o = Math.floor(t / 72);
271
+ return Math.max(2, Math.min(n, o));
272
+ }
273
+ function zt(t) {
274
+ var o;
275
+ return t ? ((o = (Array.isArray(t) ? t : [t])[0]) == null ? void 0 : o.tickCount) ?? 6 : 6;
276
+ }
277
+ function re(t) {
278
+ const n = t.wrapper.clientHeight, o = t.wrapper.clientWidth, r = oe(n, t.baseYTickCount);
279
+ if (t.chart.updateYAxis("default", { tickCount: r }), t.showXAxis) {
280
+ const a = ie(o, t.baseXTickCount);
281
+ t.chart.updateXAxis({ tickCount: a });
282
+ }
283
+ }
284
+ function Ct(t) {
285
+ for (const n of t) re(n);
286
+ }
287
+ function Et(t) {
288
+ const n = t ? Array.isArray(t) ? t : [t] : [{}];
289
+ let o = 0, r = 0;
290
+ for (const a of n)
291
+ a.position === "right" ? r++ : o++;
292
+ return { left: Math.max(1, o), right: r };
293
+ }
294
+ function ae(t, n) {
295
+ var r;
296
+ let o = 0;
297
+ for (const a of t) {
298
+ const { left: d } = Et((r = a.chart) == null ? void 0 : r.yAxis);
299
+ o = Math.max(o, (d - 1) * 65);
300
+ }
301
+ return n + o;
302
+ }
303
+ function se(t, n) {
304
+ var r;
305
+ let o = 0;
306
+ for (const a of t) {
307
+ const { right: d } = Et((r = a.chart) == null ? void 0 : r.yAxis);
308
+ o = Math.max(o, d * 65);
309
+ }
310
+ return n + o;
311
+ }
312
+ function ce(t, n) {
313
+ const o = n === "horizontal" ? "min-width:0;" : "min-height:0;";
314
+ return typeof t == "number" ? `flex:${t} 1 0;${o}` : `flex:1 1 ${t};${o}`;
315
+ }
316
+ function $t(t) {
317
+ if (!(t != null && t.length)) return [];
318
+ const n = [];
319
+ for (const o of t)
320
+ o.type === "indicator" ? n.push(...Yt(o)) : n.push(o);
321
+ return n;
322
+ }
323
+ function Mt(t, n, o, r, a, d, b, k, y) {
324
+ var M, A, x, z, I, V, U, K, Q, J, tt, et, nt;
325
+ const R = r === 0, X = r === a - 1, H = y === "horizontal", W = !H && o.sharedXAxis !== "none" && !b, _ = H && (o.sharedYAxis ?? "left") !== "none" && !k, l = (o.gap ?? 0) > 0 ? qt : { top: 0, bottom: 0, left: 0 }, T = H ? {
326
+ top: d.top,
327
+ right: X ? d.right : l.left ?? 0,
328
+ left: _ ? l.left ?? 4 : d.left,
329
+ bottom: d.bottom
330
+ } : {
331
+ top: R ? d.top : l.top,
332
+ right: d.right,
333
+ left: d.left,
334
+ bottom: W ? l.bottom : X ? ((A = (M = o.layout) == null ? void 0 : M.margins) == null ? void 0 : A.bottom) ?? Dt.bottom : d.bottom
335
+ }, S = ((x = t.chart) == null ? void 0 : x.xAxis) ?? {}, u = {
336
+ ...S,
337
+ showLine: b ? S.showLine ?? !0 : !1,
338
+ showTicks: b ? S.showTicks ?? !0 : !1,
339
+ showLabels: b ? S.showLabels ?? !0 : !1
340
+ }, f = ((z = t.chart) == null ? void 0 : z.yAxis) ?? {}, v = (Array.isArray(f) ? f : [f]).map((q) => ({
341
+ ...q,
342
+ showLine: k ? q.showLine ?? !0 : !1,
343
+ showTicks: k ? q.showTicks ?? !0 : !1,
344
+ showLabels: k ? q.showLabels ?? !0 : !1
345
+ })), m = Array.isArray((I = t.chart) == null ? void 0 : I.yAxis) ? v : v[0];
346
+ return (t.interactive ?? !0) || (n.style.pointerEvents = "none"), {
347
+ ...t.chart,
348
+ id: t.id,
349
+ container: n,
350
+ showLegend: ((V = t.chart) == null ? void 0 : V.showLegend) ?? o.showLegend ?? !1,
351
+ theme: ((U = t.chart) == null ? void 0 : U.theme) ?? o.theme,
352
+ devicePixelRatio: o.devicePixelRatio ?? ((K = t.chart) == null ? void 0 : K.devicePixelRatio),
353
+ loading: ((Q = t.chart) == null ? void 0 : Q.loading) ?? !1,
354
+ xAxis: u,
355
+ yAxis: m,
356
+ layout: Lt({
357
+ ...o.layout,
358
+ ...(J = t.chart) == null ? void 0 : J.layout,
359
+ margins: { ...T, ...(tt = o.layout) == null ? void 0 : tt.margins, ...(nt = (et = t.chart) == null ? void 0 : et.layout) == null ? void 0 : nt.margins }
360
+ })
361
+ };
362
+ }
363
+ function it(t, n, o, r) {
364
+ const a = n > 0 && o > 0 ? r === "horizontal" ? `margin-left:${n}px;` : `margin-top:${n}px;` : "";
365
+ return `${ce(t, r)}position:relative;overflow:hidden;${a}`;
366
+ }
367
+ function le(t, n, o) {
368
+ return t === !1 ? {
369
+ axis: "none",
370
+ syncCursor: !1,
371
+ syncZoom: !1,
372
+ syncPan: !1,
373
+ bidirectional: !0,
374
+ masterId: void 0
375
+ } : {
376
+ axis: o === "horizontal" ? "y" : "x",
377
+ bidirectional: !0,
378
+ masterId: n,
379
+ syncCursor: !0,
380
+ syncZoom: !0,
381
+ syncPan: !0,
382
+ ...typeof t == "object" ? t : {}
383
+ };
384
+ }
385
+ function fe(t) {
386
+ var ut, ht, ft, mt, gt, pt, yt, xt;
387
+ const { container: n, panes: o } = t;
388
+ if (!n) throw new Error("[StackedChart] container is required");
389
+ if (o.length < 1 || o.length > ot)
390
+ throw new Error(`[StackedChart] panes must be 1–${ot}`);
391
+ const r = t.masterPaneId ?? o[0].id, a = t.direction ?? "vertical", d = a === "horizontal", b = t.sharedXAxis ?? "bottom", k = t.sharedYAxis ?? "left", y = t.gap ?? 0, R = t.resizable, X = !!R, H = typeof R == "object" ? R.dividerSize ?? 6 : 6, E = Lt(t.layout), W = ((ut = E.margins) == null ? void 0 : ut.left) ?? G.left, $ = ((ht = E.margins) == null ? void 0 : ht.right) ?? G.right, _ = ((ft = E.margins) == null ? void 0 : ft.top) ?? G.top, h = ae(o, W), l = se(o, $);
392
+ n.replaceChildren(), n.style.display = "flex", n.style.flexDirection = d ? "row" : "column", n.style.width = "100%";
393
+ const T = n.offsetHeight || parseInt(getComputedStyle(n).height, 10), S = n.offsetWidth || parseInt(getComputedStyle(n).width, 10);
394
+ d ? (S > 0 ? (n.style.width = `${S}px`, n.style.minWidth = `${S}px`) : n.style.width || (n.style.minWidth = "480px"), n.style.height = T > 0 ? `${T}px` : "320px", n.style.minHeight = n.style.height) : T > 0 ? (n.style.height = `${T}px`, n.style.minHeight = `${T}px`) : n.style.height || (n.style.minHeight = "320px"), n.style.overflow = "hidden", n.style.position = "relative";
395
+ const u = o.map((e) => e.id), f = o.map((e) => Rt(e.height)), g = /* @__PURE__ */ new Map(), v = [], m = [];
396
+ let w = null, M = !1, A = 0, x = 0, z = null;
397
+ const I = (e) => {
398
+ const i = Array.from({ length: v.length }, (s, c) => c);
399
+ for (const s of i) {
400
+ const c = g.get(u[s]);
401
+ c && c.resize();
402
+ }
403
+ Ct(
404
+ i.map((s) => m[s]).filter(Boolean)
405
+ );
406
+ }, V = () => {
407
+ A || (A = requestAnimationFrame(() => {
408
+ A = 0, !M && I();
409
+ }));
410
+ }, U = new ResizeObserver(() => {
411
+ M || V();
412
+ });
413
+ U.observe(n);
414
+ const K = () => {
415
+ for (let e = 0; e < v.length; e++)
416
+ v[e].style.cssText = it(f[e], y, e, a);
417
+ }, Q = () => {
418
+ const e = (v.length - 1) * H;
419
+ return d ? Math.max(1, n.clientWidth - e) : Math.max(1, n.clientHeight - e);
420
+ }, J = () => {
421
+ for (const e of v) {
422
+ const i = e.firstElementChild;
423
+ i && (i.style.cssText = "position:absolute;inset:0;width:100%;height:100%;");
424
+ }
425
+ }, tt = () => {
426
+ const e = Q(), i = v.map(
427
+ (c) => d ? c.getBoundingClientRect().width : c.getBoundingClientRect().height
428
+ ), s = i.reduce((c, p) => c + p, 0);
429
+ return s > 0 ? i.map((c) => c * (e / s)) : i;
430
+ }, et = (e) => {
431
+ for (let i = 0; i < v.length; i++) {
432
+ const s = Math.max(1, Math.round(e[i])), c = y > 0 && i > 0 ? d ? `margin-left:${y}px;` : `margin-top:${y}px;` : "", p = d ? "width" : "height";
433
+ v[i].style.cssText = `${p}:${s}px;flex:0 0 auto;min-height:0;min-width:0;position:relative;overflow:hidden;${c}`;
434
+ }
435
+ }, nt = () => {
436
+ if (x = 0, !M || !z) return;
437
+ const { sizes: e, leadingIdx: i, trailingIdx: s } = z;
438
+ et(e);
439
+ for (const c of [i, s]) {
440
+ const p = g.get(u[c]);
441
+ p && (p.resize(), Ct([m[c]]));
442
+ }
443
+ }, q = (e, i, s) => {
444
+ z = { sizes: e, leadingIdx: i, trailingIdx: s }, !x && (x = requestAnimationFrame(nt));
445
+ }, Tt = (e) => {
446
+ const i = e.reduce((c, p) => c + p, 0);
447
+ if (i <= 0) return;
448
+ const s = f.reduce((c, p) => c + p, 0);
449
+ for (let c = 0; c < f.length; c++)
450
+ f[c] = e[c] / i * s;
451
+ }, at = (e) => {
452
+ var i;
453
+ for (const s of g.values())
454
+ (i = s.setResizeSuspended) == null || i.call(s, e);
455
+ }, It = (e, i) => {
456
+ var s, c, p, C, P, Y;
457
+ for (let L = 0; L < u.length; L++)
458
+ L === e || L === i || (c = (s = g.get(u[L])) == null ? void 0 : s.setResizeSuspended) == null || c.call(s, !0);
459
+ (C = (p = g.get(u[e])) == null ? void 0 : p.setResizeSuspended) == null || C.call(p, !1), (Y = (P = g.get(u[i])) == null ? void 0 : P.setResizeSuspended) == null || Y.call(P, !1);
460
+ }, st = d ? ((gt = (mt = t.layout) == null ? void 0 : mt.margins) == null ? void 0 : gt.bottom) ?? Dt.bottom : G.bottom;
461
+ for (let e = 0; e < o.length; e++) {
462
+ const i = o[e], s = e === 0, c = e === o.length - 1, p = d ? i.showXAxis ?? !0 : i.showXAxis ?? (b === "bottom" ? c : !0), C = d ? i.showYAxis ?? (k === "left" ? s : !0) : i.showYAxis ?? !0, P = document.createElement("div");
463
+ P.dataset.paneId = i.id, P.style.cssText = it(f[e], y, e, a);
464
+ const Y = document.createElement("div");
465
+ Y.style.cssText = "position:absolute;inset:0;width:100%;height:100%;", P.appendChild(Y), n.appendChild(P), v.push(P);
466
+ const L = St(
467
+ Mt(
468
+ i,
469
+ Y,
470
+ t,
471
+ e,
472
+ o.length,
473
+ {
474
+ left: d && !C ? G.left : h,
475
+ right: l,
476
+ top: _,
477
+ bottom: st
478
+ },
479
+ p,
480
+ C,
481
+ a
482
+ )
483
+ ), j = $t(i.series);
484
+ if (j.length)
485
+ for (const N of j) L.addSeries(N);
486
+ i.yRange && i.yRange !== "auto" && L.zoom({ y: i.yRange, animate: !1 }), g.set(i.id, L), m.push({
487
+ chart: L,
488
+ wrapper: P,
489
+ baseYTickCount: zt((pt = i.chart) == null ? void 0 : pt.yAxis),
490
+ baseXTickCount: ((xt = (yt = i.chart) == null ? void 0 : yt.xAxis) == null ? void 0 : xt.tickCount) ?? 8,
491
+ showXAxis: p
492
+ });
493
+ }
494
+ if (X && o.length > 1) {
495
+ const e = typeof R == "object" ? {
496
+ minPaneRatio: R.minPaneRatio,
497
+ minPanePx: R.minPanePx,
498
+ dividerSize: R.dividerSize
499
+ } : {};
500
+ w = ee(
501
+ n,
502
+ v,
503
+ u,
504
+ f,
505
+ {
506
+ direction: a,
507
+ ...e,
508
+ onDragStart: (i, s) => (M = !0, at(!0), It(i, s), tt()),
509
+ onDragMove: (i, s, c) => {
510
+ q(i, s, c);
511
+ },
512
+ onDragEnd: (i) => {
513
+ x && (cancelAnimationFrame(x), x = 0), z = null, M = !1;
514
+ const s = te(i, Q());
515
+ Tt(s), J(), K(), at(!1), I();
516
+ }
517
+ }
518
+ );
519
+ }
520
+ const Z = g.get(r);
521
+ if (!Z)
522
+ throw new Error(`[StackedChart] masterPaneId "${r}" not found in panes`);
523
+ const O = Wt(
524
+ Array.from(g.values()),
525
+ le(t.sync, r, a)
526
+ ), Ft = () => {
527
+ const e = Z.theme ?? Z.baseTheme;
528
+ return (e == null ? void 0 : e.backgroundColor) ?? "#ffffff";
529
+ }, ct = () => {
530
+ const i = Date.now();
531
+ return new Promise((c) => {
532
+ const p = () => {
533
+ const C = Nt();
534
+ if (C.pending === 0 && !C.isProcessing || Date.now() - i > 8e3) {
535
+ c();
536
+ return;
537
+ }
538
+ setTimeout(p, 50);
539
+ };
540
+ p();
541
+ }).then(() => new Promise((c) => {
542
+ requestAnimationFrame(() => {
543
+ I(), c();
544
+ });
545
+ }));
546
+ }, lt = async (e = {}) => {
547
+ await ct();
548
+ for (const s of g.values()) s.render();
549
+ await new Promise((s) => requestAnimationFrame(s));
550
+ const i = await Kt(
551
+ n,
552
+ v,
553
+ Array.from(g.values()),
554
+ (w == null ? void 0 : w.dividers) ?? [],
555
+ Ft(),
556
+ e
557
+ );
558
+ if (e.download) {
559
+ const s = e.format === "jpeg" ? "jpg" : e.format ?? "png", c = document.createElement("a");
560
+ c.download = `${e.fileName ?? "velo-plot-stack"}.${s}`, c.href = i, document.body.appendChild(c), c.click(), document.body.removeChild(c);
561
+ }
562
+ return i;
563
+ }, dt = (e) => {
564
+ var vt, wt, bt, At;
565
+ if (g.size >= ot)
566
+ throw new Error(`[StackedChart] Cannot exceed ${ot} panes`);
567
+ if (g.has(e.id))
568
+ throw new Error(`[StackedChart] Pane "${e.id}" already exists`);
569
+ if (!d && b === "bottom" && u.length > 0) {
570
+ const B = u[u.length - 1];
571
+ (vt = g.get(B)) == null || vt.updateXAxis({
572
+ showLabels: !1,
573
+ showTicks: !1,
574
+ showLine: !1
575
+ });
576
+ }
577
+ const i = Rt(e.height ?? 0.25), s = f.reduce((B, Ht) => B + Ht, 0), c = s > 0 ? (1 - i) / s : 1;
578
+ for (let B = 0; B < f.length; B++) f[B] *= c;
579
+ const p = u.length;
580
+ u.push(e.id), f.push(i);
581
+ const C = document.createElement("div");
582
+ C.dataset.paneId = e.id, C.style.cssText = it(f[p], y, p, a);
583
+ const P = document.createElement("div");
584
+ P.style.cssText = "position:absolute;inset:0;width:100%;height:100%;", C.appendChild(P), n.appendChild(C), v.push(C);
585
+ const L = d ? e.showXAxis ?? !0 : e.showXAxis ?? (b === "bottom" ? !0 : !0), j = d ? e.showYAxis ?? (k === "left" ? p === 0 : !0) : e.showYAxis ?? !0, N = St(
586
+ Mt(
587
+ e,
588
+ P,
589
+ t,
590
+ p,
591
+ u.length,
592
+ {
593
+ left: d && !j ? G.left : h,
594
+ right: l,
595
+ top: _,
596
+ bottom: st
597
+ },
598
+ L,
599
+ j,
600
+ a
601
+ )
602
+ ), Xt = $t(e.series);
603
+ for (const B of Xt) N.addSeries(B);
604
+ return e.yRange && e.yRange !== "auto" && N.zoom({ y: e.yRange, animate: !1 }), g.set(e.id, N), m.push({
605
+ chart: N,
606
+ wrapper: C,
607
+ baseYTickCount: zt((wt = e.chart) == null ? void 0 : wt.yAxis),
608
+ baseXTickCount: ((At = (bt = e.chart) == null ? void 0 : bt.xAxis) == null ? void 0 : At.tickCount) ?? 8,
609
+ showXAxis: L
610
+ }), O.add(N), K(), I(), N;
611
+ };
612
+ return {
613
+ container: n,
614
+ getPane(e) {
615
+ return g.get(e);
616
+ },
617
+ getPanes() {
618
+ return Array.from(g.values());
619
+ },
620
+ getMaster() {
621
+ return Z;
622
+ },
623
+ getGroup() {
624
+ return O;
625
+ },
626
+ fitAll(e) {
627
+ O.fitAll(e);
628
+ },
629
+ resetAll() {
630
+ O.resetAll();
631
+ },
632
+ resize() {
633
+ I();
634
+ },
635
+ getPaneRatios() {
636
+ const e = {};
637
+ for (let i = 0; i < u.length; i++)
638
+ e[u[i]] = f[i];
639
+ return e;
640
+ },
641
+ setPaneRatios(e) {
642
+ for (let i = 0; i < u.length; i++) {
643
+ const s = u[i];
644
+ e[s] !== void 0 && (f[i] = e[s]);
645
+ }
646
+ ne(v, f, a), I();
647
+ },
648
+ setSyncAxis(e) {
649
+ O.syncAxis(e);
650
+ },
651
+ getSyncAxis() {
652
+ return O.getOptions().axis ?? "x";
653
+ },
654
+ setSyncOptions(e) {
655
+ O.updateOptions(e);
656
+ },
657
+ whenReady() {
658
+ return ct();
659
+ },
660
+ exportImage(e) {
661
+ return lt(e);
662
+ },
663
+ snapshot(e) {
664
+ return lt(e);
665
+ },
666
+ addPane(e) {
667
+ return dt(e);
668
+ },
669
+ async addIndicator(e, i = {}) {
670
+ var L;
671
+ const s = g.get(r) ?? Z;
672
+ if (i.pane !== "new")
673
+ return { ...await Bt(s, e, i), chart: s };
674
+ const c = _t(s, i.sourceSeriesId), { x: p, prices: C } = Ot(c), P = await jt(e, p, C, {
675
+ id: i.id ?? e,
676
+ label: i.label ?? e.toUpperCase(),
677
+ height: i.paneHeight ?? 0.25,
678
+ showXAxis: i.showXAxis,
679
+ period: i.period,
680
+ fastPeriod: i.fastPeriod,
681
+ slowPeriod: i.slowPeriod,
682
+ signalPeriod: i.signalPeriod,
683
+ stdDev: i.stdDev
684
+ }, c), Y = dt(P);
685
+ return {
686
+ id: P.id,
687
+ preset: e,
688
+ placement: "oscillator",
689
+ seriesIds: ((L = P.series) == null ? void 0 : L.map((j) => j.id)) ?? [],
690
+ paneId: P.id,
691
+ chart: Y
692
+ };
693
+ },
694
+ destroy() {
695
+ A && cancelAnimationFrame(A), x && cancelAnimationFrame(x), U.disconnect(), w == null || w.destroy(), O.destroy();
696
+ for (const e of g.values()) e.destroy();
697
+ g.clear(), n.replaceChildren();
698
+ }
699
+ };
700
+ }
701
+ export {
702
+ ot as S,
703
+ rt as a,
704
+ fe as c
705
+ };
706
+ //# sourceMappingURL=createStackedChart-DJSmqerD.js.map