@tradecanvas/core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -200,7 +200,7 @@ var D = class {
200
200
  render(e) {
201
201
  let t = this.renderCtx;
202
202
  if (!t) return;
203
- let { viewport: n, theme: r, data: i } = t;
203
+ let { viewport: n, theme: r, data: i } = t, a = t.numberLocale ?? "en-US";
204
204
  if (!(n.chartRect.width <= 0 || n.chartRect.height <= 0)) {
205
205
  if (e.has(s.Background) && this.bgLayer && (this.bgLayer.clear(), t.gridRenderer?.render(this.bgLayer.ctx, n, r), t.sessionBreaks?.render(this.bgLayer.ctx, n, r, i), t.watermark?.render(this.bgLayer.ctx, n, r)), e.has(s.Main) && this.mainLayer) {
206
206
  this.mainLayer.clear();
@@ -236,42 +236,42 @@ var D = class {
236
236
  this.uiLayer.clear();
237
237
  let e = this.uiLayer.ctx;
238
238
  if (t.priceAxis?.render(e, n, r), t.tradingRenderer?.renderAxisBadges(e, n, r), t.currentPriceLine?.render(e, n, r), t.timeAxis?.render(e, n, r, i, t.timeAxisY), t.chartLegend?.render(e, n, r, i), t.barCountdown?.render(e, n, r, i), t.panels.length > 0) {
239
- let n = t.crosshairHandler?.getPosition(), a = t.indicatorEngine, o = `${r.font.sizeSmall}px ${r.font.family}`, s;
240
- if (a) {
241
- let e = a.getPanelIndicators();
242
- s = /* @__PURE__ */ new Map();
243
- for (let t of e) s.set(t.instanceId, t);
239
+ let n = t.crosshairHandler?.getPosition(), o = t.indicatorEngine, s = `${r.font.sizeSmall}px ${r.font.family}`, l;
240
+ if (o) {
241
+ let e = o.getPanelIndicators();
242
+ l = /* @__PURE__ */ new Map();
243
+ for (let t of e) l.set(t.instanceId, t);
244
244
  }
245
- for (let l of t.panels) {
246
- let t = l.viewport, u = l.rect, { min: d, max: m } = t.priceRange;
247
- if (m - d <= 0 || u.height <= 0) continue;
248
- let h = u.x + u.width, g = t.chartRect;
249
- e.strokeStyle = r.axisLine, e.lineWidth = 1, e.beginPath(), e.moveTo(h + .5, u.y), e.lineTo(h + .5, u.y + u.height), e.stroke();
250
- let _ = f(d, m, 4), v = Math.ceil(d / _) * _, y = _ < 1 ? Math.ceil(-Math.log10(_)) + 1 : +(_ < 10);
251
- e.font = o, e.textBaseline = "middle", e.textAlign = "left";
252
- for (let n = v; n <= m; n += _) {
245
+ for (let u of t.panels) {
246
+ let t = u.viewport, d = u.rect, { min: m, max: h } = t.priceRange;
247
+ if (h - m <= 0 || d.height <= 0) continue;
248
+ let g = d.x + d.width, _ = t.chartRect;
249
+ e.strokeStyle = r.axisLine, e.lineWidth = 1, e.beginPath(), e.moveTo(g + .5, d.y), e.lineTo(g + .5, d.y + d.height), e.stroke();
250
+ let v = f(m, h, 4), y = Math.ceil(m / v) * v, b = v < 1 ? Math.ceil(-Math.log10(v)) + 1 : +(v < 10);
251
+ e.font = s, e.textBaseline = "middle", e.textAlign = "left";
252
+ for (let n = y; n <= h; n += v) {
253
253
  let i = C(n, t);
254
- i < g.y || i > g.y + g.height || (e.strokeStyle = r.axisLine, e.beginPath(), e.moveTo(h, Math.round(i) + .5), e.lineTo(h + 4, Math.round(i) + .5), e.stroke(), e.fillStyle = r.axisLabel, e.fillText(p(n, y), h + 6, i));
254
+ i < _.y || i > _.y + _.height || (e.strokeStyle = r.axisLine, e.beginPath(), e.moveTo(g, Math.round(i) + .5), e.lineTo(g + 4, Math.round(i) + .5), e.stroke(), e.fillStyle = r.axisLabel, e.fillText(p(n, b, a), g + 6, i));
255
255
  }
256
- if (n && n.x >= u.x && n.x <= u.x + u.width && n.y >= u.y && n.y <= u.y + u.height) {
257
- let i = p(T(n.y, t), y);
256
+ if (n && n.x >= d.x && n.x <= d.x + d.width && n.y >= d.y && n.y <= d.y + d.height) {
257
+ let i = p(T(n.y, t), b, a);
258
258
  e.font = `bold ${r.font.sizeSmall}px ${r.font.family}`;
259
- let a = e.measureText(i).width, o = Math.min(a + 10, c - 2);
260
- e.fillStyle = r.crosshair, e.fillRect(h + 1, n.y - 9, o, 18), e.fillStyle = r.background, e.textBaseline = "middle", e.textAlign = "left", e.fillText(i, h + 5, n.y);
259
+ let o = e.measureText(i).width, s = Math.min(o + 10, c - 2);
260
+ e.fillStyle = r.crosshair, e.fillRect(g + 1, n.y - 9, s, 18), e.fillStyle = r.background, e.textBaseline = "middle", e.textAlign = "left", e.fillText(i, g + 5, n.y);
261
261
  }
262
- if (n && a) {
263
- let c = w(n.x, t), d = Math.max(0, Math.min((i?.length ?? 1) - 1, Math.round(c))), f = a.getOutput(l.instanceId);
264
- if (f?.series && d < f.series.length) {
265
- let t = f.series[d];
262
+ if (n && o) {
263
+ let a = w(n.x, t), c = Math.max(0, Math.min((i?.length ?? 1) - 1, Math.round(a))), f = o.getOutput(u.instanceId);
264
+ if (f?.series && c < f.series.length) {
265
+ let t = f.series[c];
266
266
  if (t) {
267
267
  let n = [];
268
268
  for (let e in t) {
269
269
  let r = t[e];
270
- r !== void 0 && n.push(`${e}: ${r.toFixed(y)}`);
270
+ r !== void 0 && n.push(`${e}: ${r.toFixed(b)}`);
271
271
  }
272
272
  if (n.length > 0) {
273
- let t = s?.get(l.instanceId), i = t ? e.measureText(t.descriptor.name).width + 14 : 10;
274
- e.font = o, e.fillStyle = r.textSecondary, e.textBaseline = "top", e.textAlign = "left", e.fillText(n.join(" "), u.x + i, u.y + 6);
273
+ let t = l?.get(u.instanceId), i = t ? e.measureText(t.descriptor.name).width + 14 : 10;
274
+ e.font = s, e.fillStyle = r.textSecondary, e.textBaseline = "top", e.textAlign = "left", e.fillText(n.join(" "), d.x + i, d.y + 6);
275
275
  }
276
276
  }
277
277
  }
@@ -957,7 +957,7 @@ var j = class {
957
957
  });
958
958
  return e;
959
959
  }
960
- }, M = class extends j {
960
+ }, ve = class extends j {
961
961
  descriptor = {
962
962
  id: "sma",
963
963
  name: "Simple Moving Average",
@@ -989,7 +989,7 @@ var j = class {
989
989
  }
990
990
  e.stroke();
991
991
  }
992
- }, N = class extends j {
992
+ }, ye = class extends j {
993
993
  descriptor = {
994
994
  id: "ema",
995
995
  name: "Exponential Moving Average",
@@ -1026,7 +1026,7 @@ var j = class {
1026
1026
  }
1027
1027
  e.stroke();
1028
1028
  }
1029
- }, P = class extends j {
1029
+ }, be = class extends j {
1030
1030
  descriptor = {
1031
1031
  id: "bb",
1032
1032
  name: "Bollinger Bands",
@@ -1081,7 +1081,7 @@ var j = class {
1081
1081
  e.stroke();
1082
1082
  }
1083
1083
  }
1084
- }, F = class extends j {
1084
+ }, xe = class extends j {
1085
1085
  descriptor = {
1086
1086
  id: "vwap",
1087
1087
  name: "Volume Weighted Average Price",
@@ -1116,7 +1116,7 @@ var j = class {
1116
1116
  }
1117
1117
  e.stroke();
1118
1118
  }
1119
- }, I = class extends j {
1119
+ }, Se = class extends j {
1120
1120
  descriptor = {
1121
1121
  id: "ichimoku",
1122
1122
  name: "Ichimoku Cloud",
@@ -1176,7 +1176,7 @@ var j = class {
1176
1176
  };
1177
1177
  x(c, l, u, r.colors[0], r.lineWidths[0]), x(d, f, p, r.colors[1] ?? "#FF9800", r.lineWidths[0]), x(m, h, g, r.colors[2] ?? "#26A69A", 1), x(v, y, b, r.colors[3] ?? "#EF5350", 1);
1178
1178
  }
1179
- }, L = class extends j {
1179
+ }, Ce = class extends j {
1180
1180
  descriptor = {
1181
1181
  id: "psar",
1182
1182
  name: "Parabolic SAR",
@@ -1222,7 +1222,7 @@ var j = class {
1222
1222
  e.beginPath(), e.arc(o, c, s, 0, Math.PI * 2), e.fillStyle = a.trend === 1 ? r.colors[0] : r.colors[1] ?? "#EF5350", e.fill();
1223
1223
  }
1224
1224
  }
1225
- }, R = class extends j {
1225
+ }, we = class extends j {
1226
1226
  descriptor = {
1227
1227
  id: "supertrend",
1228
1228
  name: "Supertrend",
@@ -1270,7 +1270,7 @@ var j = class {
1270
1270
  d !== 0 && (e.beginPath(), e.strokeStyle = p === 1 ? s : c, e.lineWidth = r.lineWidths[0] + .5, e.moveTo(l, u), e.lineTo(o, f), e.stroke()), l = o, u = f, d = p;
1271
1271
  }
1272
1272
  }
1273
- }, z = class extends j {
1273
+ }, Te = class extends j {
1274
1274
  descriptor = {
1275
1275
  id: "keltner",
1276
1276
  name: "Keltner Channel",
@@ -1327,7 +1327,7 @@ var j = class {
1327
1327
  }
1328
1328
  this.drawBand(e, s, l, _(r.colors[0], .08)), this.drawLine(e, s, r.colors[0], r.lineWidths[0]), this.drawLine(e, c, r.colors[1] ?? r.colors[0], r.lineWidths[0]), this.drawLine(e, l, r.colors[0], r.lineWidths[0]);
1329
1329
  }
1330
- }, B = class extends j {
1330
+ }, Ee = class extends j {
1331
1331
  descriptor = {
1332
1332
  id: "donchian",
1333
1333
  name: "Donchian Channel",
@@ -1372,7 +1372,7 @@ var j = class {
1372
1372
  }
1373
1373
  this.drawBand(e, s, l, _(r.colors[0], .08)), this.drawLine(e, s, r.colors[0], r.lineWidths[0]), this.drawLine(e, c, r.colors[1] ?? "#787B86", 1), this.drawLine(e, l, r.colors[0], r.lineWidths[0]);
1374
1374
  }
1375
- }, V = class extends j {
1375
+ }, De = class extends j {
1376
1376
  descriptor = {
1377
1377
  id: "rsi",
1378
1378
  name: "Relative Strength Index",
@@ -1423,7 +1423,7 @@ var j = class {
1423
1423
  }
1424
1424
  e.stroke();
1425
1425
  }
1426
- }, H = class extends j {
1426
+ }, Oe = class extends j {
1427
1427
  descriptor = {
1428
1428
  id: "macd",
1429
1429
  name: "MACD",
@@ -1490,7 +1490,7 @@ var j = class {
1490
1490
  }
1491
1491
  e.fillStyle = m, e.fill(v), e.fillStyle = h, e.fill(y), e.strokeStyle = g, e.lineWidth = r.lineWidths[0], e.lineJoin = "round", e.stroke(C), e.strokeStyle = _, e.stroke(w);
1492
1492
  }
1493
- }, ve = class extends j {
1493
+ }, ke = class extends j {
1494
1494
  descriptor = {
1495
1495
  id: "stochastic",
1496
1496
  name: "Stochastic Oscillator",
@@ -1565,7 +1565,7 @@ var j = class {
1565
1565
  };
1566
1566
  l("k", r.colors[0]), l("d", r.colors[1] ?? "#FF9800");
1567
1567
  }
1568
- }, ye = class extends j {
1568
+ }, Ae = class extends j {
1569
1569
  descriptor = {
1570
1570
  id: "atr",
1571
1571
  name: "Average True Range",
@@ -1619,7 +1619,7 @@ var j = class {
1619
1619
  }
1620
1620
  e.stroke();
1621
1621
  }
1622
- }, be = class extends j {
1622
+ }, je = class extends j {
1623
1623
  descriptor = {
1624
1624
  id: "adx",
1625
1625
  name: "Average Directional Index",
@@ -1692,7 +1692,7 @@ var j = class {
1692
1692
  };
1693
1693
  l("adx", r.colors[0]), l("plusDI", r.colors[1] ?? "#26A69A"), l("minusDI", r.colors[2] ?? "#EF5350");
1694
1694
  }
1695
- }, xe = class extends j {
1695
+ }, Me = class extends j {
1696
1696
  descriptor = {
1697
1697
  id: "obv",
1698
1698
  name: "On Balance Volume",
@@ -1738,7 +1738,7 @@ var j = class {
1738
1738
  }
1739
1739
  e.stroke();
1740
1740
  }
1741
- }, Se = class extends j {
1741
+ }, Ne = class extends j {
1742
1742
  descriptor = {
1743
1743
  id: "williamsR",
1744
1744
  name: "Williams %R",
@@ -1778,7 +1778,7 @@ var j = class {
1778
1778
  }
1779
1779
  e.stroke();
1780
1780
  }
1781
- }, Ce = class extends j {
1781
+ }, M = class extends j {
1782
1782
  descriptor = {
1783
1783
  id: "cci",
1784
1784
  name: "Commodity Channel Index",
@@ -1833,7 +1833,7 @@ var j = class {
1833
1833
  }
1834
1834
  e.stroke();
1835
1835
  }
1836
- }, we = class extends j {
1836
+ }, N = class extends j {
1837
1837
  descriptor = {
1838
1838
  id: "mfi",
1839
1839
  name: "Money Flow Index",
@@ -1878,7 +1878,7 @@ var j = class {
1878
1878
  }
1879
1879
  e.stroke();
1880
1880
  }
1881
- }, Te = class extends j {
1881
+ }, P = class extends j {
1882
1882
  descriptor = {
1883
1883
  id: "aroon",
1884
1884
  name: "Aroon",
@@ -1920,7 +1920,7 @@ var j = class {
1920
1920
  };
1921
1921
  l("up", r.colors[0]), l("down", r.colors[1] ?? "#EF5350");
1922
1922
  }
1923
- }, Ee = class extends j {
1923
+ }, F = class extends j {
1924
1924
  descriptor = {
1925
1925
  id: "roc",
1926
1926
  name: "Rate of Change",
@@ -1964,7 +1964,7 @@ var j = class {
1964
1964
  }
1965
1965
  e.stroke();
1966
1966
  }
1967
- }, De = class extends j {
1967
+ }, I = class extends j {
1968
1968
  descriptor = {
1969
1969
  id: "tsi",
1970
1970
  name: "True Strength Index",
@@ -2033,7 +2033,7 @@ var j = class {
2033
2033
  };
2034
2034
  h("tsi", r.colors[0]), h("signal", r.colors[1] ?? "#FF9800");
2035
2035
  }
2036
- }, Oe = class extends j {
2036
+ }, L = class extends j {
2037
2037
  descriptor = {
2038
2038
  id: "cmf",
2039
2039
  name: "Chaikin Money Flow",
@@ -2078,7 +2078,7 @@ var j = class {
2078
2078
  }
2079
2079
  }
2080
2080
  }
2081
- }, ke = class extends j {
2081
+ }, R = class extends j {
2082
2082
  descriptor = {
2083
2083
  id: "stddev",
2084
2084
  name: "Standard Deviation",
@@ -2124,7 +2124,7 @@ var j = class {
2124
2124
  }
2125
2125
  e.stroke();
2126
2126
  }
2127
- }, Ae = class extends j {
2127
+ }, z = class extends j {
2128
2128
  descriptor = {
2129
2129
  id: "volumeProfile",
2130
2130
  name: "Volume Profile",
@@ -2174,7 +2174,7 @@ var j = class {
2174
2174
  e.fillStyle = l[t] > u * .7 ? r.colors[1] ?? "rgba(255, 152, 0, 0.5)" : r.colors[0] ?? "rgba(33, 150, 243, 0.3)", e.fillRect(i.x, s - d / 2, p, Math.max(d - 1, 1));
2175
2175
  }
2176
2176
  }
2177
- }, je = class extends j {
2177
+ }, Pe = class extends j {
2178
2178
  descriptor = {
2179
2179
  id: "ad",
2180
2180
  name: "Accumulation/Distribution",
@@ -2220,7 +2220,7 @@ var j = class {
2220
2220
  }
2221
2221
  e.stroke();
2222
2222
  }
2223
- }, Me = class extends j {
2223
+ }, Fe = class extends j {
2224
2224
  descriptor = {
2225
2225
  id: "vroc",
2226
2226
  name: "Volume Rate of Change",
@@ -2262,12 +2262,12 @@ var j = class {
2262
2262
  };
2263
2263
  //#endregion
2264
2264
  //#region src/indicators/registry.ts
2265
- function Ne(e) {
2266
- e.register(new M()), e.register(new N()), e.register(new P()), e.register(new F()), e.register(new I()), e.register(new L()), e.register(new R()), e.register(new z()), e.register(new B()), e.register(new V()), e.register(new H()), e.register(new ve()), e.register(new ye()), e.register(new be()), e.register(new xe()), e.register(new Se()), e.register(new Ce()), e.register(new we()), e.register(new Te()), e.register(new Ee()), e.register(new De()), e.register(new Oe()), e.register(new ke()), e.register(new Ae()), e.register(new je()), e.register(new Me());
2265
+ function Ie(e) {
2266
+ e.register(new ve()), e.register(new ye()), e.register(new be()), e.register(new xe()), e.register(new Se()), e.register(new Ce()), e.register(new we()), e.register(new Te()), e.register(new Ee()), e.register(new De()), e.register(new Oe()), e.register(new ke()), e.register(new Ae()), e.register(new je()), e.register(new Me()), e.register(new Ne()), e.register(new M()), e.register(new N()), e.register(new P()), e.register(new F()), e.register(new I()), e.register(new L()), e.register(new R()), e.register(new z()), e.register(new Pe()), e.register(new Fe());
2267
2267
  }
2268
2268
  //#endregion
2269
2269
  //#region src/axis/GridRenderer.ts
2270
- var Pe = class {
2270
+ var Le = class {
2271
2271
  visible = !0;
2272
2272
  setVisible(e) {
2273
2273
  this.visible = e;
@@ -2296,7 +2296,11 @@ var Pe = class {
2296
2296
  }
2297
2297
  e.stroke();
2298
2298
  }
2299
- }, Fe = class {
2299
+ }, Re = class {
2300
+ locale = "en-US";
2301
+ setLocale(e) {
2302
+ this.locale = e;
2303
+ }
2300
2304
  render(e, t, n) {
2301
2305
  let { chartRect: r, priceRange: i } = t, a = r.x + r.width, o = i.max - i.min;
2302
2306
  if (o <= 0) return;
@@ -2307,7 +2311,7 @@ var Pe = class {
2307
2311
  let t = r.y + r.height * (1 - (e - i.min) * s);
2308
2312
  h.push({
2309
2313
  y: t,
2310
- text: p(e, d)
2314
+ text: p(e, d, this.locale)
2311
2315
  });
2312
2316
  }
2313
2317
  e.font = m, e.textBaseline = "middle", e.textAlign = "left", e.fillStyle = n.axisLabelBackground;
@@ -2315,7 +2319,7 @@ var Pe = class {
2315
2319
  e.fillStyle = n.axisLabel;
2316
2320
  for (let { y: t, text: n } of h) e.fillText(n, a + 5, t);
2317
2321
  }
2318
- }, U = /* @__PURE__ */ new Date(), Ie = (e) => e < 10 ? "0" + e : "" + e, Le = -(/* @__PURE__ */ new Date()).getTimezoneOffset() / 60, Re = `UTC${Le >= 0 ? "+" : ""}${Le}`, ze = class {
2322
+ }, B = /* @__PURE__ */ new Date(), ze = (e) => e < 10 ? "0" + e : "" + e, Be = -(/* @__PURE__ */ new Date()).getTimezoneOffset() / 60, Ve = `UTC${Be >= 0 ? "+" : ""}${Be}`, He = class {
2319
2323
  render(e, t, n, r, i) {
2320
2324
  let { chartRect: a } = t, o = i ?? a.y + a.height;
2321
2325
  e.strokeStyle = n.axisLine, e.lineWidth = 1, e.beginPath(), e.moveTo(a.x, o + .5), e.lineTo(a.x + a.width, o + .5), e.stroke();
@@ -2325,14 +2329,14 @@ var Pe = class {
2325
2329
  for (let t = l; t <= u && t < r.length; t++) {
2326
2330
  if (t % c !== 0) continue;
2327
2331
  let n = t * s + d, i = r[t].time, a = i > 0xe8d4a51000 ? i : i * 1e3;
2328
- U.setTime(a);
2329
- let l = U.getDate(), u = U.getMonth() + 1, p = U.getHours(), m = U.getMinutes(), h;
2330
- l === f ? h = `${Ie(p)}:${Ie(m)}` : (h = `${u}/${l}`, f = l), e.fillText(h, n, o + 5);
2332
+ B.setTime(a);
2333
+ let l = B.getDate(), u = B.getMonth() + 1, p = B.getHours(), m = B.getMinutes(), h;
2334
+ l === f ? h = `${ze(p)}:${ze(m)}` : (h = `${u}/${l}`, f = l), e.fillText(h, n, o + 5);
2331
2335
  }
2332
2336
  let p = a.x + a.width - 4, m = o + 4;
2333
- e.font = `${n.font.sizeSmall - 1}px ${n.font.family}`, e.textAlign = "right", e.textBaseline = "top", e.fillStyle = n.textSecondary, e.fillText(Re, p, m);
2337
+ e.font = `${n.font.sizeSmall - 1}px ${n.font.family}`, e.textAlign = "right", e.textBaseline = "top", e.fillStyle = n.textSecondary, e.fillText(Ve, p, m);
2334
2338
  }
2335
- }, Be = class {
2339
+ }, Ue = class {
2336
2340
  panHandler = null;
2337
2341
  zoomHandler = null;
2338
2342
  crosshairHandler = null;
@@ -2347,6 +2351,7 @@ var Pe = class {
2347
2351
  y: 0
2348
2352
  };
2349
2353
  touchActive = !1;
2354
+ cachedRect = null;
2350
2355
  constructor(e) {
2351
2356
  this.element = e;
2352
2357
  }
@@ -2370,6 +2375,7 @@ var Pe = class {
2370
2375
  }
2371
2376
  attach() {
2372
2377
  let e = () => this.viewportGetter?.() ?? null, t = (t) => {
2378
+ this.invalidateRect();
2373
2379
  let n = this.getMousePos(t), r = e();
2374
2380
  this.tradingManager && r && this.tradingManager.onPointerDown(n, r) || this.drawingManager && r && this.drawingManager.onPointerDown(n, r) || this.panHandler?.onPointerDown(n);
2375
2381
  }, n = (t) => {
@@ -2397,7 +2403,7 @@ var Pe = class {
2397
2403
  let n = e();
2398
2404
  this.tradingManager && n && (t.preventDefault(), this.tradingManager.onContextMenu(this.getMousePos(t), n));
2399
2405
  }, c = (e) => {
2400
- if (e.preventDefault(), e.touches.length === 1) {
2406
+ if (e.preventDefault(), this.invalidateRect(), e.touches.length === 1) {
2401
2407
  let t = this.getTouchPos(e.touches[0]);
2402
2408
  this.panHandler?.onPointerDown(t), this.crosshairHandler?.onPointerMove(t), this.touchActive = !0;
2403
2409
  } else e.touches.length === 2 && (this.panHandler?.onPointerUp(), this.lastTouchDist = this.getTouchDistance(e.touches[0], e.touches[1]), this.lastTouchMid = this.getTouchMidpoint(e.touches[0], e.touches[1]), this.touchActive = !0);
@@ -2421,22 +2427,28 @@ var Pe = class {
2421
2427
  let t = this.getTouchPos(e.touches[0]);
2422
2428
  this.panHandler?.onPointerDown(t);
2423
2429
  }
2424
- };
2425
- this.element.addEventListener("mousedown", t), this.element.addEventListener("mousemove", n), document.addEventListener("mouseup", r), this.element.addEventListener("mouseleave", i), this.element.addEventListener("wheel", a, { passive: !1 }), this.element.addEventListener("contextmenu", s), this.element.addEventListener("touchstart", c, { passive: !1 }), this.element.addEventListener("touchmove", l, { passive: !1 }), this.element.addEventListener("touchend", u), document.addEventListener("keydown", o), this.boundHandlers.push(() => this.element.removeEventListener("mousedown", t), () => this.element.removeEventListener("mousemove", n), () => document.removeEventListener("mouseup", r), () => this.element.removeEventListener("mouseleave", i), () => this.element.removeEventListener("wheel", a), () => this.element.removeEventListener("contextmenu", s), () => this.element.removeEventListener("touchstart", c), () => this.element.removeEventListener("touchmove", l), () => this.element.removeEventListener("touchend", u), () => document.removeEventListener("keydown", o));
2430
+ }, d = () => this.invalidateRect(), f = () => this.invalidateRect();
2431
+ this.element.addEventListener("mousedown", t), this.element.addEventListener("mousemove", n), document.addEventListener("mouseup", r), this.element.addEventListener("mouseleave", i), this.element.addEventListener("wheel", a, { passive: !1 }), this.element.addEventListener("contextmenu", s), this.element.addEventListener("touchstart", c, { passive: !1 }), this.element.addEventListener("touchmove", l, { passive: !1 }), this.element.addEventListener("touchend", u), document.addEventListener("keydown", o), window.addEventListener("resize", d), this.element.addEventListener("scroll", f, { passive: !0 }), this.boundHandlers.push(() => this.element.removeEventListener("mousedown", t), () => this.element.removeEventListener("mousemove", n), () => document.removeEventListener("mouseup", r), () => this.element.removeEventListener("mouseleave", i), () => this.element.removeEventListener("wheel", a), () => this.element.removeEventListener("contextmenu", s), () => this.element.removeEventListener("touchstart", c), () => this.element.removeEventListener("touchmove", l), () => this.element.removeEventListener("touchend", u), () => document.removeEventListener("keydown", o), () => window.removeEventListener("resize", d), () => this.element.removeEventListener("scroll", f));
2426
2432
  }
2427
2433
  detach() {
2428
2434
  for (let e of this.boundHandlers) e();
2429
- this.boundHandlers = [];
2435
+ this.boundHandlers = [], this.cachedRect = null;
2436
+ }
2437
+ invalidateRect() {
2438
+ this.cachedRect = null;
2439
+ }
2440
+ getRect() {
2441
+ return this.cachedRect ||= this.element.getBoundingClientRect(), this.cachedRect;
2430
2442
  }
2431
2443
  getMousePos(e) {
2432
- let t = this.element.getBoundingClientRect();
2444
+ let t = this.getRect();
2433
2445
  return {
2434
2446
  x: e.clientX - t.left,
2435
2447
  y: e.clientY - t.top
2436
2448
  };
2437
2449
  }
2438
2450
  getTouchPos(e) {
2439
- let t = this.element.getBoundingClientRect();
2451
+ let t = this.getRect();
2440
2452
  return {
2441
2453
  x: e.clientX - t.left,
2442
2454
  y: e.clientY - t.top
@@ -2446,13 +2458,13 @@ var Pe = class {
2446
2458
  return Math.hypot(t.clientX - e.clientX, t.clientY - e.clientY);
2447
2459
  }
2448
2460
  getTouchMidpoint(e, t) {
2449
- let n = this.element.getBoundingClientRect();
2461
+ let n = this.getRect();
2450
2462
  return {
2451
2463
  x: (e.clientX + t.clientX) / 2 - n.left,
2452
2464
  y: (e.clientY + t.clientY) / 2 - n.top
2453
2465
  };
2454
2466
  }
2455
- }, Ve = class {
2467
+ }, We = class {
2456
2468
  dragging = !1;
2457
2469
  lastX = 0;
2458
2470
  lastTime = 0;
@@ -2488,7 +2500,7 @@ var Pe = class {
2488
2500
  stopMomentum() {
2489
2501
  this.momentumId &&= (cancelAnimationFrame(this.momentumId), 0);
2490
2502
  }
2491
- }, He = class {
2503
+ }, Ge = class {
2492
2504
  callback;
2493
2505
  sensitivity;
2494
2506
  pendingDelta = 0;
@@ -2507,13 +2519,14 @@ var Pe = class {
2507
2519
  dispose() {
2508
2520
  this.rafId &&= (cancelAnimationFrame(this.rafId), 0);
2509
2521
  }
2510
- }, Ue = class {
2522
+ }, Ke = class {
2511
2523
  position = null;
2512
2524
  callback = null;
2513
2525
  data = [];
2514
2526
  magnetMode = !0;
2515
2527
  mode = "magnet";
2516
2528
  pricePrecision = 2;
2529
+ locale = "en-US";
2517
2530
  pendingBarIndex = null;
2518
2531
  pendingPoint = null;
2519
2532
  callbackScheduled = !1;
@@ -2536,6 +2549,9 @@ var Pe = class {
2536
2549
  setPricePrecision(e) {
2537
2550
  this.pricePrecision = e;
2538
2551
  }
2552
+ setLocale(e) {
2553
+ this.locale = e;
2554
+ }
2539
2555
  getPosition() {
2540
2556
  return this.position;
2541
2557
  }
@@ -2554,7 +2570,7 @@ var Pe = class {
2554
2570
  x: i,
2555
2571
  y: a
2556
2572
  }, this.lastCallbackBarIndex = o, this.scheduleCallback()), e.setLineDash([4, 4]), e.strokeStyle = n.crosshair, e.lineWidth = 1, e.beginPath(), e.moveTo(Math.round(i) + .5, r.y), e.lineTo(Math.round(i) + .5, r.y + r.height), e.stroke(), e.beginPath(), e.moveTo(r.x, Math.round(a) + .5), e.lineTo(r.x + r.width, Math.round(a) + .5), e.stroke(), e.setLineDash([]);
2557
- let s = p(T(a, t), this.pricePrecision), l = r.x + r.width + 1;
2573
+ let s = p(T(a, t), this.pricePrecision, this.locale), l = r.x + r.width + 1;
2558
2574
  e.fillStyle = n.axisLabelBackground, e.fillRect(l, a - 10, c - 2, 20), e.fillStyle = n.axisLabel, e.font = `${n.font.sizeSmall}px ${n.font.family}`, e.textBaseline = "middle", e.textAlign = "left", e.fillText(s, l + 5, a);
2559
2575
  }
2560
2576
  scheduleCallback() {
@@ -2565,7 +2581,7 @@ var Pe = class {
2565
2581
  flushCallback(e, t) {
2566
2582
  this.callback?.(e, t);
2567
2583
  }
2568
- }, We = class {
2584
+ }, qe = class {
2569
2585
  callbacks;
2570
2586
  enabled = !0;
2571
2587
  constructor(e) {
@@ -2591,7 +2607,7 @@ var Pe = class {
2591
2607
  default: return !1;
2592
2608
  }
2593
2609
  }
2594
- }, Ge = class {
2610
+ }, Je = class {
2595
2611
  el = null;
2596
2612
  visible = !1;
2597
2613
  timeEl;
@@ -2630,8 +2646,8 @@ var Pe = class {
2630
2646
  this.changeEl.textContent = `${l}${a(s)} (${l}${c.toFixed(2)}%)`, this.changeEl.style.color = i;
2631
2647
  let u = t.volume;
2632
2648
  this.volEl.textContent = `Vol ${u >= 1e6 ? (u / 1e6).toFixed(1) + "M" : u >= 1e3 ? (u / 1e3).toFixed(1) + "K" : u.toFixed(0)}`, this.volEl.style.color = n.textSecondary;
2633
- let d = Ke(n.background);
2634
- this.el.style.background = d ? qe(n.background, .95) : qe(n.background, .97), this.el.style.border = `1px solid ${n.axisLine}`, this.el.style.boxShadow = d ? "0 4px 12px rgba(0,0,0,0.5)" : "0 4px 12px rgba(0,0,0,0.15)", this.el.style.color = n.text, this.el.style.backdropFilter = "blur(8px)", !this.measured && this.visible && (this.measuredWidth = this.el.offsetWidth, this.measuredHeight = this.el.offsetHeight, this.measured = !0);
2649
+ let d = Ye(n.background);
2650
+ this.el.style.background = d ? Xe(n.background, .95) : Xe(n.background, .97), this.el.style.border = `1px solid ${n.axisLine}`, this.el.style.boxShadow = d ? "0 4px 12px rgba(0,0,0,0.5)" : "0 4px 12px rgba(0,0,0,0.15)", this.el.style.color = n.text, this.el.style.backdropFilter = "blur(8px)", !this.measured && this.visible && (this.measuredWidth = this.el.offsetWidth, this.measuredHeight = this.el.offsetHeight, this.measured = !0);
2635
2651
  let f = e.x + 16, p = e.y - 40;
2636
2652
  f + this.measuredWidth > r.width - 80 && (f = e.x - this.measuredWidth - 16), p < 4 && (p = 4), p + this.measuredHeight > r.height && (p = r.height - this.measuredHeight - 4), this.el.style.transform = `translate(${Math.round(f)}px, ${Math.round(p)}px)`, this.el.style.left = "0", this.el.style.top = "0", this.visible ||= (this.el.style.display = "block", !0);
2637
2653
  }
@@ -2656,7 +2672,7 @@ var Pe = class {
2656
2672
  return document.createElement("span");
2657
2673
  }
2658
2674
  };
2659
- function Ke(e) {
2675
+ function Ye(e) {
2660
2676
  if (e.startsWith("#")) {
2661
2677
  let t = e.slice(1), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t.slice(0, 6), r = parseInt(n.slice(0, 2), 16), i = parseInt(n.slice(2, 4), 16), a = parseInt(n.slice(4, 6), 16);
2662
2678
  return (.299 * r + .587 * i + .114 * a) / 255 < .5;
@@ -2668,7 +2684,7 @@ function Ke(e) {
2668
2684
  }
2669
2685
  return !0;
2670
2686
  }
2671
- function qe(e, t) {
2687
+ function Xe(e, t) {
2672
2688
  if (e.startsWith("#")) {
2673
2689
  let n = e.slice(1), r = n.length === 3 ? n.split("").map((e) => e + e).join("") : n.slice(0, 6);
2674
2690
  return `rgba(${parseInt(r.slice(0, 2), 16)}, ${parseInt(r.slice(2, 4), 16)}, ${parseInt(r.slice(4, 6), 16)}, ${t})`;
@@ -2677,7 +2693,7 @@ function qe(e, t) {
2677
2693
  }
2678
2694
  //#endregion
2679
2695
  //#region src/events/EventBus.ts
2680
- var Je = class {
2696
+ var Ze = class {
2681
2697
  listeners = /* @__PURE__ */ new Map();
2682
2698
  tauriBridge = null;
2683
2699
  on(e, t) {
@@ -2708,7 +2724,7 @@ var Je = class {
2708
2724
  destroy() {
2709
2725
  this.listeners.clear(), this.tauriBridge = null;
2710
2726
  }
2711
- }, W = class {
2727
+ }, V = class {
2712
2728
  hitTestAnchor(e, t, n, r) {
2713
2729
  for (let i = 0; i < t.anchors.length; i++) {
2714
2730
  let a = this.anchorToPixel(t.anchors[i], n);
@@ -2763,7 +2779,16 @@ var Je = class {
2763
2779
  let r = n.x - t.x, i = n.y - t.y, a = Math.hypot(r, i);
2764
2780
  return a === 0 ? Math.hypot(e.x - t.x, e.y - t.y) : Math.abs(r * (t.y - e.y) - i * (t.x - e.x)) / a;
2765
2781
  }
2766
- }, Ye = 1, Xe = class {
2782
+ }, Qe = 1;
2783
+ function H(e) {
2784
+ return {
2785
+ ...e,
2786
+ anchors: e.anchors.map((e) => ({ ...e })),
2787
+ style: { ...e.style },
2788
+ meta: e.meta ? { ...e.meta } : void 0
2789
+ };
2790
+ }
2791
+ var $e = class {
2767
2792
  registry = /* @__PURE__ */ new Map();
2768
2793
  drawings = [];
2769
2794
  state = "idle";
@@ -2935,7 +2960,7 @@ var Je = class {
2935
2960
  e && this.undoRedo?.push({
2936
2961
  type: "drawingModify",
2937
2962
  before: this.dragBeforeState,
2938
- after: structuredClone(e)
2963
+ after: H(e)
2939
2964
  });
2940
2965
  }
2941
2966
  return this.state = "selected", this.dragStartPoint = null, this.dragStartAnchors = [], this.dragAnchorIndex = -1, this.dragBeforeState = null, !0;
@@ -2968,7 +2993,7 @@ var Je = class {
2968
2993
  let t = this.drawings.find((t) => t.id === e);
2969
2994
  if (!t) return null;
2970
2995
  let n = structuredClone(t);
2971
- return n.id = `tc_drawing_${Ye++}`, n.anchors = n.anchors.map((e) => ({
2996
+ return n.id = `tc_drawing_${Qe++}`, n.anchors = n.anchors.map((e) => ({
2972
2997
  ...e,
2973
2998
  time: e.time + 3
2974
2999
  })), n.locked = !1, this.drawings.push(n), this.undoRedo?.push({
@@ -3010,7 +3035,7 @@ var Je = class {
3010
3035
  if (!n) return !1;
3011
3036
  let r = w(e.x, t), i = T(e.y, t), a = this.snapToOHLC(r, i, t);
3012
3037
  return this.creatingDrawing ? (this.creatingDrawing.anchors.push(a), this.committedAnchors++, this.previewAnchor = null, this.committedAnchors >= n.descriptor.requiredAnchors && this.finalizeCreation(), this.requestRender?.(), !0) : (this.creatingDrawing = {
3013
- id: `tc_drawing_${Ye++}`,
3038
+ id: `tc_drawing_${Qe++}`,
3014
3039
  type: this.activeTool,
3015
3040
  anchors: [a],
3016
3041
  style: { ...this.activeStyle },
@@ -3032,8 +3057,8 @@ var Je = class {
3032
3057
  let r = this.registry.get(n.type);
3033
3058
  if (r) {
3034
3059
  let i = r.hitTestAnchor(e, n, t, 8);
3035
- if (i >= 0) return this.state = "resizing", this.dragAnchorIndex = i, this.dragStartPoint = e, this.dragBeforeState = structuredClone(n), !0;
3036
- if (r.hitTest(e, n, t, 8)) return this.state = "moving", this.dragStartPoint = e, this.dragStartAnchors = n.anchors.map((e) => ({ ...e })), this.dragBeforeState = structuredClone(n), !0;
3060
+ if (i >= 0) return this.state = "resizing", this.dragAnchorIndex = i, this.dragStartPoint = e, this.dragBeforeState = H(n), !0;
3061
+ if (r.hitTest(e, n, t, 8)) return this.state = "moving", this.dragStartPoint = e, this.dragStartAnchors = n.anchors.map((e) => ({ ...e })), this.dragBeforeState = H(n), !0;
3037
3062
  }
3038
3063
  }
3039
3064
  }
@@ -3061,14 +3086,14 @@ var Je = class {
3061
3086
  price: T(e.y, t)
3062
3087
  }, this.requestRender?.(), !0);
3063
3088
  }
3064
- }, Ze = class {
3089
+ }, et = class {
3065
3090
  constructor(e) {
3066
3091
  this.manager = e;
3067
3092
  }
3068
3093
  render(e, t) {
3069
3094
  this.manager.render(e, t);
3070
3095
  }
3071
- }, Qe = class extends W {
3096
+ }, tt = class extends V {
3072
3097
  descriptor = {
3073
3098
  type: "trendLine",
3074
3099
  name: "Trend Line",
@@ -3084,7 +3109,7 @@ var Je = class {
3084
3109
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n);
3085
3110
  return this.distanceToLine(e, i, a) <= r;
3086
3111
  }
3087
- }, $e = class extends W {
3112
+ }, nt = class extends V {
3088
3113
  descriptor = {
3089
3114
  type: "horizontalLine",
3090
3115
  name: "Horizontal Line",
@@ -3100,7 +3125,7 @@ var Je = class {
3100
3125
  let i = C(t.anchors[0].price, n);
3101
3126
  return Math.abs(e.y - i) <= r && e.x >= n.chartRect.x && e.x <= n.chartRect.x + n.chartRect.width;
3102
3127
  }
3103
- }, et = class extends W {
3128
+ }, rt = class extends V {
3104
3129
  descriptor = {
3105
3130
  type: "verticalLine",
3106
3131
  name: "Vertical Line",
@@ -3116,7 +3141,7 @@ var Je = class {
3116
3141
  let i = this.anchorToPixel(t.anchors[0], n), { chartRect: a } = n;
3117
3142
  return Math.abs(e.x - i.x) <= r && e.y >= a.y && e.y <= a.y + a.height;
3118
3143
  }
3119
- }, tt = class extends W {
3144
+ }, it = class extends V {
3120
3145
  descriptor = {
3121
3146
  type: "ray",
3122
3147
  name: "Ray",
@@ -3134,7 +3159,7 @@ var Je = class {
3134
3159
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = a.x - i.x, s = a.y - i.y;
3135
3160
  return ((e.x - i.x) * o + (e.y - i.y) * s) / (o * o + s * s) < 0 ? !1 : this.distanceToInfiniteLine(e, i, a) <= r;
3136
3161
  }
3137
- }, nt = class extends W {
3162
+ }, at = class extends V {
3138
3163
  descriptor = {
3139
3164
  type: "extendedLine",
3140
3165
  name: "Extended Line",
@@ -3152,7 +3177,7 @@ var Je = class {
3152
3177
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n);
3153
3178
  return this.distanceToInfiniteLine(e, i, a) <= r;
3154
3179
  }
3155
- }, rt = class extends W {
3180
+ }, ot = class extends V {
3156
3181
  descriptor = {
3157
3182
  type: "parallelChannel",
3158
3183
  name: "Parallel Channel",
@@ -3189,7 +3214,7 @@ var Je = class {
3189
3214
  }
3190
3215
  return !1;
3191
3216
  }
3192
- }, it = class extends W {
3217
+ }, st = class extends V {
3193
3218
  descriptor = {
3194
3219
  type: "regressionChannel",
3195
3220
  name: "Regression Channel",
@@ -3212,7 +3237,7 @@ var Je = class {
3212
3237
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = Math.hypot(a.x - i.x, a.y - i.y), s = Math.max(10, Math.min(o * .2, 100));
3213
3238
  return this.distanceToLine(e, i, a) <= r + s;
3214
3239
  }
3215
- }, G = [
3240
+ }, U = [
3216
3241
  0,
3217
3242
  .236,
3218
3243
  .382,
@@ -3220,7 +3245,7 @@ var Je = class {
3220
3245
  .618,
3221
3246
  .786,
3222
3247
  1
3223
- ], at = class extends W {
3248
+ ], ct = class extends V {
3224
3249
  descriptor = {
3225
3250
  type: "fibRetracement",
3226
3251
  name: "Fibonacci Retracement",
@@ -3230,13 +3255,13 @@ var Je = class {
3230
3255
  if (t.anchors.length < 2) return;
3231
3256
  let { chartRect: i } = n, a = t.anchors[0].price, o = t.anchors[1].price, s = a - o;
3232
3257
  e.font = "11px sans-serif", e.textBaseline = "middle";
3233
- for (let r of G) {
3258
+ for (let r of U) {
3234
3259
  let a = o + s * (1 - r), c = C(a, n);
3235
3260
  this.applyLineStyle(e, t.style), e.globalAlpha = r === 0 || r === 1 ? 1 : .7, e.beginPath(), e.moveTo(i.x, c), e.lineTo(i.x + i.width, c), e.stroke(), e.fillStyle = t.style.color, e.textAlign = "left", e.fillText(`${(r * 100).toFixed(1)}% (${a.toFixed(2)})`, i.x + 4, c - 2);
3236
3261
  }
3237
3262
  if (e.globalAlpha = 1, t.style.fillColor) {
3238
- for (let r = 0; r < G.length - 1; r++) {
3239
- let a = o + s * (1 - G[r]), c = o + s * (1 - G[r + 1]), l = C(a, n), u = C(c, n);
3263
+ for (let r = 0; r < U.length - 1; r++) {
3264
+ let a = o + s * (1 - U[r]), c = o + s * (1 - U[r + 1]), l = C(a, n), u = C(c, n);
3240
3265
  e.fillStyle = t.style.fillColor, e.globalAlpha = .05 + r * .02, e.fillRect(i.x, Math.min(l, u), i.width, Math.abs(u - l));
3241
3266
  }
3242
3267
  e.globalAlpha = 1;
@@ -3248,13 +3273,13 @@ var Je = class {
3248
3273
  let { chartRect: i } = n;
3249
3274
  if (e.x < i.x - r || e.x > i.x + i.width + r) return !1;
3250
3275
  let a = t.anchors[0].price, o = t.anchors[1].price, s = a - o;
3251
- for (let t of G) {
3276
+ for (let t of U) {
3252
3277
  let i = C(o + s * (1 - t), n);
3253
3278
  if (Math.abs(e.y - i) <= r) return !0;
3254
3279
  }
3255
3280
  return !1;
3256
3281
  }
3257
- }, ot = [
3282
+ }, lt = [
3258
3283
  0,
3259
3284
  .618,
3260
3285
  1,
@@ -3263,7 +3288,7 @@ var Je = class {
3263
3288
  2.618,
3264
3289
  3.618,
3265
3290
  4.236
3266
- ], st = class extends W {
3291
+ ], ut = class extends V {
3267
3292
  descriptor = {
3268
3293
  type: "fibExtension",
3269
3294
  name: "Fibonacci Extension",
@@ -3279,7 +3304,7 @@ var Je = class {
3279
3304
  }
3280
3305
  let { chartRect: i } = n, a = t.anchors[0].price, o = t.anchors[1].price, s = t.anchors[2].price, c = a - o;
3281
3306
  e.font = "11px sans-serif", e.textBaseline = "middle", e.textAlign = "left";
3282
- for (let r of ot) {
3307
+ for (let r of lt) {
3283
3308
  let a = C(s + c * r, n);
3284
3309
  this.applyLineStyle(e, t.style), e.globalAlpha = r === 0 || r === 1 ? 1 : .6, e.beginPath(), e.moveTo(i.x, a), e.lineTo(i.x + i.width, a), e.stroke(), e.fillStyle = t.style.color, e.fillText(`${(r * 100).toFixed(1)}%`, i.x + 4, a - 2);
3285
3310
  }
@@ -3290,13 +3315,13 @@ var Je = class {
3290
3315
  let { chartRect: i } = n;
3291
3316
  if (e.x < i.x - r || e.x > i.x + i.width + r) return !1;
3292
3317
  let a = t.anchors[0].price - t.anchors[1].price;
3293
- for (let i of ot) {
3318
+ for (let i of lt) {
3294
3319
  let o = C(t.anchors[2].price + a * i, n);
3295
3320
  if (Math.abs(e.y - o) <= r) return !0;
3296
3321
  }
3297
3322
  return !1;
3298
3323
  }
3299
- }, ct = class extends W {
3324
+ }, dt = class extends V {
3300
3325
  descriptor = {
3301
3326
  type: "rectangle",
3302
3327
  name: "Rectangle",
@@ -3314,7 +3339,7 @@ var Je = class {
3314
3339
  let u = Math.min(i.x, a.x) + r, d = Math.min(i.y, a.y) + r, f = Math.max(i.x, a.x) - r, p = Math.max(i.y, a.y) - r;
3315
3340
  return !(e.x > u && e.x < f && e.y > d && e.y < p) || !!t.style.fillColor;
3316
3341
  }
3317
- }, lt = class extends W {
3342
+ }, ft = class extends V {
3318
3343
  descriptor = {
3319
3344
  type: "ellipse",
3320
3345
  name: "Ellipse",
@@ -3330,7 +3355,7 @@ var Je = class {
3330
3355
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = (i.x + a.x) / 2, s = (i.y + a.y) / 2, c = Math.max(Math.abs(a.x - i.x) / 2, 1), l = Math.max(Math.abs(a.y - i.y) / 2, 1), u = (e.x - o) / c, d = (e.y - s) / l, f = Math.sqrt(u * u + d * d), p = r / Math.max(Math.min(c, l), 4);
3331
3356
  return t.style.fillColor ? f <= 1 + p : Math.abs(f - 1) <= p;
3332
3357
  }
3333
- }, ut = class extends W {
3358
+ }, pt = class extends V {
3334
3359
  descriptor = {
3335
3360
  type: "triangle",
3336
3361
  name: "Triangle",
@@ -3356,7 +3381,7 @@ var Je = class {
3356
3381
  }
3357
3382
  return !1;
3358
3383
  }
3359
- }, dt = class extends W {
3384
+ }, mt = class extends V {
3360
3385
  descriptor = {
3361
3386
  type: "pitchfork",
3362
3387
  name: "Andrews' Pitchfork",
@@ -3392,7 +3417,7 @@ var Je = class {
3392
3417
  };
3393
3418
  return this.distanceToInfiniteLine(e, a, u) <= r || this.distanceToInfiniteLine(e, o, d) <= r;
3394
3419
  }
3395
- }, ft = [
3420
+ }, ht = [
3396
3421
  "1",
3397
3422
  "2",
3398
3423
  "3",
@@ -3401,7 +3426,7 @@ var Je = class {
3401
3426
  "A",
3402
3427
  "B",
3403
3428
  "C"
3404
- ], pt = class extends W {
3429
+ ], gt = class extends V {
3405
3430
  descriptor = {
3406
3431
  type: "elliottWave",
3407
3432
  name: "Elliott Wave",
@@ -3413,9 +3438,9 @@ var Je = class {
3413
3438
  this.applyLineStyle(e, t.style), e.beginPath(), e.moveTo(i[0].x, i[0].y);
3414
3439
  for (let t = 1; t < i.length; t++) e.lineTo(i[t].x, i[t].y);
3415
3440
  e.stroke(), this.resetLineStyle(e), e.font = "bold 12px sans-serif", e.fillStyle = t.style.color, e.textAlign = "center";
3416
- for (let t = 0; t < i.length && t < ft.length; t++) {
3441
+ for (let t = 0; t < i.length && t < ht.length; t++) {
3417
3442
  let n = t % 2 == 0 ? -12 : 12;
3418
- e.textBaseline = n < 0 ? "bottom" : "top", e.fillText(ft[t], i[t].x, i[t].y + n);
3443
+ e.textBaseline = n < 0 ? "bottom" : "top", e.fillText(ht[t], i[t].x, i[t].y + n);
3419
3444
  }
3420
3445
  r && this.renderAnchorHandles(e, t, n);
3421
3446
  }
@@ -3425,7 +3450,7 @@ var Je = class {
3425
3450
  for (let t = 0; t < i.length - 1; t++) if (this.distanceToLine(e, i[t], i[t + 1]) <= r) return !0;
3426
3451
  return !1;
3427
3452
  }
3428
- }, mt = class extends W {
3453
+ }, _t = class extends V {
3429
3454
  descriptor = {
3430
3455
  type: "priceRange",
3431
3456
  name: "Price Range",
@@ -3443,7 +3468,7 @@ var Je = class {
3443
3468
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = Math.min(i.x, a.x), s = Math.max(i.x, a.x), c = Math.min(i.y, a.y), l = Math.max(i.y, a.y);
3444
3469
  return e.x >= o - r && e.x <= s + r && e.y >= c - r && e.y <= l + r;
3445
3470
  }
3446
- }, ht = class extends W {
3471
+ }, vt = class extends V {
3447
3472
  descriptor = {
3448
3473
  type: "dateRange",
3449
3474
  name: "Date Range",
@@ -3461,7 +3486,7 @@ var Je = class {
3461
3486
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), { chartRect: o } = n, s = Math.min(i.x, a.x), c = Math.max(i.x, a.x);
3462
3487
  return e.x >= s - r && e.x <= c + r && e.y >= o.y && e.y <= o.y + o.height;
3463
3488
  }
3464
- }, gt = class extends W {
3489
+ }, yt = class extends V {
3465
3490
  descriptor = {
3466
3491
  type: "measure",
3467
3492
  name: "Measure",
@@ -3483,7 +3508,7 @@ var Je = class {
3483
3508
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n);
3484
3509
  return this.distanceToLine(e, i, a) <= r;
3485
3510
  }
3486
- }, _t = class extends W {
3511
+ }, bt = class extends V {
3487
3512
  descriptor = {
3488
3513
  type: "text",
3489
3514
  name: "Text",
@@ -3503,7 +3528,7 @@ var Je = class {
3503
3528
  let i = this.anchorToPixel(t.anchors[0], n), a = t.style.fontSize || 14;
3504
3529
  return e.x >= i.x - r && e.x <= i.x + 80 + r && e.y >= i.y - r && e.y <= i.y + a + r;
3505
3530
  }
3506
- }, vt = class extends W {
3531
+ }, xt = class extends V {
3507
3532
  descriptor = {
3508
3533
  type: "arrow",
3509
3534
  name: "Arrow",
@@ -3521,7 +3546,7 @@ var Je = class {
3521
3546
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n);
3522
3547
  return this.distanceToLine(e, i, a) <= r;
3523
3548
  }
3524
- }, yt = [
3549
+ }, St = [
3525
3550
  {
3526
3551
  label: "8x1",
3527
3552
  ratio: 8
@@ -3558,7 +3583,7 @@ var Je = class {
3558
3583
  label: "1x8",
3559
3584
  ratio: .125
3560
3585
  }
3561
- ], bt = class extends W {
3586
+ ], Ct = class extends V {
3562
3587
  descriptor = {
3563
3588
  type: "gannFan",
3564
3589
  name: "Gann Fan",
@@ -3570,7 +3595,7 @@ var Je = class {
3570
3595
  if (Math.abs(o) < 1) return;
3571
3596
  let c = s / o, l = o > 0 ? 1 : -1, { chartRect: u } = n, d = l > 0 ? u.x + u.width : u.x;
3572
3597
  this.applyLineStyle(e, t.style);
3573
- for (let { label: n, ratio: r } of yt) {
3598
+ for (let { label: n, ratio: r } of St) {
3574
3599
  let a = c * r, o = d, s = i.y + a * (o - i.x);
3575
3600
  e.globalAlpha = r === 1 ? 1 : .5, e.lineWidth = r === 1 ? t.style.lineWidth : Math.max(.5, t.style.lineWidth * .7), e.beginPath(), e.moveTo(i.x, i.y), e.lineTo(o, s), e.stroke();
3576
3601
  let f = o - l * 4, p = s;
@@ -3583,7 +3608,7 @@ var Je = class {
3583
3608
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = a.x - i.x, s = a.y - i.y;
3584
3609
  if (Math.abs(o) < 1) return !1;
3585
3610
  let c = s / o, l = o > 0 ? 1 : -1, { chartRect: u } = n, d = l > 0 ? u.x + u.width : u.x;
3586
- for (let { ratio: t } of yt) {
3611
+ for (let { ratio: t } of St) {
3587
3612
  let n = c * t, a = d, o = i.y + n * (a - i.x);
3588
3613
  if (this.distanceToLine(e, i, {
3589
3614
  x: a,
@@ -3592,7 +3617,7 @@ var Je = class {
3592
3617
  }
3593
3618
  return !1;
3594
3619
  }
3595
- }, K = [
3620
+ }, W = [
3596
3621
  0,
3597
3622
  .25,
3598
3623
  .333,
@@ -3600,7 +3625,7 @@ var Je = class {
3600
3625
  .667,
3601
3626
  .75,
3602
3627
  1
3603
- ], xt = class extends W {
3628
+ ], wt = class extends V {
3604
3629
  descriptor = {
3605
3630
  type: "gannBox",
3606
3631
  name: "Gann Box",
@@ -3611,18 +3636,18 @@ var Je = class {
3611
3636
  let i = this.anchorToPixel(t.anchors[0], n), a = this.anchorToPixel(t.anchors[1], n), o = Math.min(i.x, a.x), s = Math.max(i.x, a.x), c = Math.min(i.y, a.y), l = Math.max(i.y, a.y), u = s - o, d = l - c;
3612
3637
  if (!(u < 2 || d < 2)) {
3613
3638
  this.applyLineStyle(e, t.style), e.strokeRect(o, c, u, d), e.save(), e.globalAlpha = .35;
3614
- for (let t of K) {
3639
+ for (let t of W) {
3615
3640
  if (t === 0 || t === 1) continue;
3616
3641
  let n = c + d * t;
3617
3642
  e.beginPath(), e.moveTo(o, n), e.lineTo(s, n), e.stroke();
3618
3643
  }
3619
- for (let t of K) {
3644
+ for (let t of W) {
3620
3645
  if (t === 0 || t === 1) continue;
3621
3646
  let n = o + u * t;
3622
3647
  e.beginPath(), e.moveTo(n, c), e.lineTo(n, l), e.stroke();
3623
3648
  }
3624
3649
  e.globalAlpha = .5, e.setLineDash([4, 3]), e.beginPath(), e.moveTo(o, c), e.lineTo(s, l), e.stroke(), e.beginPath(), e.moveTo(s, c), e.lineTo(o, l), e.stroke(), e.restore(), this.resetLineStyle(e), e.fillStyle = t.style.color, e.font = "8px sans-serif", e.globalAlpha = .6, e.textBaseline = "bottom", e.textAlign = "right";
3625
- for (let t of K) {
3650
+ for (let t of W) {
3626
3651
  if (t === 0 || t === 1) continue;
3627
3652
  let n = c + d * t;
3628
3653
  e.fillText(`${(t * 100).toFixed(0)}%`, o - 3, n);
@@ -3647,7 +3672,7 @@ var Je = class {
3647
3672
  y: l
3648
3673
  }) <= r;
3649
3674
  }
3650
- }, St = class extends W {
3675
+ }, Tt = class extends V {
3651
3676
  descriptor = {
3652
3677
  type: "anchoredVWAP",
3653
3678
  name: "Anchored VWAP",
@@ -3719,7 +3744,7 @@ var Je = class {
3719
3744
  }
3720
3745
  return !1;
3721
3746
  }
3722
- }, Ct = class extends W {
3747
+ }, Et = class extends V {
3723
3748
  descriptor = {
3724
3749
  type: "volumeProfileRange",
3725
3750
  name: "Volume Profile (Range)",
@@ -3764,12 +3789,12 @@ var Je = class {
3764
3789
  };
3765
3790
  //#endregion
3766
3791
  //#region src/drawings/tools/index.ts
3767
- function wt(e) {
3768
- e.register(new Qe()), e.register(new $e()), e.register(new et()), e.register(new tt()), e.register(new nt()), e.register(new rt()), e.register(new it()), e.register(new at()), e.register(new st()), e.register(new ct()), e.register(new lt()), e.register(new ut()), e.register(new dt()), e.register(new pt()), e.register(new mt()), e.register(new ht()), e.register(new gt()), e.register(new _t()), e.register(new vt()), e.register(new bt()), e.register(new xt()), e.register(new St()), e.register(new Ct());
3792
+ function Dt(e) {
3793
+ e.register(new tt()), e.register(new nt()), e.register(new rt()), e.register(new it()), e.register(new at()), e.register(new ot()), e.register(new st()), e.register(new ct()), e.register(new ut()), e.register(new dt()), e.register(new ft()), e.register(new pt()), e.register(new mt()), e.register(new gt()), e.register(new _t()), e.register(new vt()), e.register(new yt()), e.register(new bt()), e.register(new xt()), e.register(new Ct()), e.register(new wt()), e.register(new Tt()), e.register(new Et());
3769
3794
  }
3770
3795
  //#endregion
3771
3796
  //#region src/trading/OrderRenderer.ts
3772
- var Tt = class {
3797
+ var Ot = class {
3773
3798
  render(e, t, n, r, i, a) {
3774
3799
  let o = i.orderColors?.buy ?? "#26A69A", s = i.orderColors?.sell ?? "#EF5350", { chartRect: c } = n;
3775
3800
  for (let i of t) {
@@ -3807,7 +3832,7 @@ var Tt = class {
3807
3832
  }
3808
3833
  return null;
3809
3834
  }
3810
- }, Et = class {
3835
+ }, kt = class {
3811
3836
  render(e, t, n, r, i, a) {
3812
3837
  let { chartRect: o } = r, s = a.positionColors?.profit ?? "#26A69A", c = a.positionColors?.loss ?? "#EF5350", l = a.positionColors?.entry ?? "#2196F3", u = a.pricePrecision ?? 2;
3813
3838
  for (let a of t) {
@@ -3840,7 +3865,7 @@ var Tt = class {
3840
3865
  e.fillStyle = o, e.fillRect(l, t - 9, c - 2, 18), e.fillStyle = "#FFFFFF", e.font = `11px ${r.font.family}`, e.textAlign = "left", e.textBaseline = "middle", e.fillText(i.entryPrice.toFixed(s), l + 5, t);
3841
3866
  }
3842
3867
  }
3843
- }, Dt = class {
3868
+ }, At = class {
3844
3869
  render(e, t, n, r) {
3845
3870
  if (!r.depthOverlay?.enabled) return;
3846
3871
  let { chartRect: i } = n, a = r.depthOverlay.bidColor ?? "rgba(38,166,154,0.15)", o = r.depthOverlay.askColor ?? "rgba(239,83,80,0.15)", s = r.depthOverlay.maxWidth ?? 100, c = 0, l = [], u = 0;
@@ -3871,7 +3896,7 @@ var Tt = class {
3871
3896
  e.fillRect(p - o, a - f / 2, o, f);
3872
3897
  }
3873
3898
  }
3874
- }, Ot = class {
3899
+ }, jt = class {
3875
3900
  dragState = null;
3876
3901
  startY = 0;
3877
3902
  dragging = !1;
@@ -3935,7 +3960,7 @@ var Tt = class {
3935
3960
  isActive() {
3936
3961
  return this.dragState !== null;
3937
3962
  }
3938
- }, kt = class {
3963
+ }, Mt = class {
3939
3964
  menuElement = null;
3940
3965
  removeHandler = null;
3941
3966
  onItemSelect = null;
@@ -4019,17 +4044,17 @@ var Tt = class {
4019
4044
  destroy() {
4020
4045
  this.hide(), this.onItemSelect = null;
4021
4046
  }
4022
- }, At = class {
4047
+ }, Nt = class {
4023
4048
  orders = [];
4024
4049
  positions = [];
4025
4050
  depthData = null;
4026
4051
  currentPrice = null;
4027
4052
  config;
4028
- orderRenderer = new Tt();
4029
- positionRenderer = new Et();
4030
- depthOverlay = new Dt();
4053
+ orderRenderer = new Ot();
4054
+ positionRenderer = new kt();
4055
+ depthOverlay = new At();
4031
4056
  dragHandler;
4032
- contextMenu = new kt();
4057
+ contextMenu = new Mt();
4033
4058
  requestRender = null;
4034
4059
  eventCallback = null;
4035
4060
  container = null;
@@ -4037,7 +4062,7 @@ var Tt = class {
4037
4062
  this.config = {
4038
4063
  ...a,
4039
4064
  ...e
4040
- }, this.dragHandler = new Ot(this.config.dragThreshold), this.contextMenu.onItemSelect = (e) => {
4065
+ }, this.dragHandler = new jt(this.config.dragThreshold), this.contextMenu.onItemSelect = (e) => {
4041
4066
  this.eventCallback?.("orderPlace", e);
4042
4067
  };
4043
4068
  }
@@ -4098,7 +4123,7 @@ var Tt = class {
4098
4123
  destroy() {
4099
4124
  this.contextMenu.destroy();
4100
4125
  }
4101
- }, jt = class {
4126
+ }, Pt = class {
4102
4127
  constructor(e) {
4103
4128
  this.manager = e;
4104
4129
  }
@@ -4108,7 +4133,7 @@ var Tt = class {
4108
4133
  renderAxisBadges(e, t, n) {
4109
4134
  this.manager.renderAxisBadges(e, t, n);
4110
4135
  }
4111
- }, q = class {
4136
+ }, G = class {
4112
4137
  listeners = /* @__PURE__ */ new Map();
4113
4138
  on(e, t) {
4114
4139
  let n = this.listeners.get(e);
@@ -4130,7 +4155,7 @@ var Tt = class {
4130
4155
  removeAllListeners() {
4131
4156
  this.listeners.clear();
4132
4157
  }
4133
- }, Mt = class extends q {
4158
+ }, Ft = class extends G {
4134
4159
  currentBar = null;
4135
4160
  timeframeMs;
4136
4161
  tickRing;
@@ -4192,7 +4217,7 @@ var Tt = class {
4192
4217
  alignToTimeframe(e) {
4193
4218
  return Math.floor(e / this.timeframeMs) * this.timeframeMs;
4194
4219
  }
4195
- }, J = class extends q {
4220
+ }, K = class extends G {
4196
4221
  config;
4197
4222
  attempt = 0;
4198
4223
  timer = null;
@@ -4239,7 +4264,7 @@ var Tt = class {
4239
4264
  let e = this.config.baseDelay, t = this.config.backoffMultiplier ** (this.attempt - 1), n = Math.min(e * t, this.config.maxDelay), r = n * .25 * (Math.random() * 2 - 1);
4240
4265
  return Math.max(0, Math.round(n + r));
4241
4266
  }
4242
- }, Nt = class {
4267
+ }, It = class {
4243
4268
  price = null;
4244
4269
  previousClose = null;
4245
4270
  visible = !0;
@@ -4270,12 +4295,12 @@ var Tt = class {
4270
4295
  let f = s - 5;
4271
4296
  e.beginPath(), e.moveTo(f, r), e.lineTo(f + 5, r - 5), e.lineTo(f + 5, r + 5), e.closePath(), e.fill(), e.fillStyle = "#FFFFFF", e.textBaseline = "middle", e.textAlign = "left", e.fillText(l, s + 5, r);
4272
4297
  }
4273
- }, Pt = class extends q {
4298
+ }, Lt = class extends G {
4274
4299
  config = null;
4275
4300
  adapter = null;
4276
4301
  aggregator = null;
4277
4302
  reconnector;
4278
- priceLine = new Nt();
4303
+ priceLine = new It();
4279
4304
  state = "disconnected";
4280
4305
  lastPrice = null;
4281
4306
  previousClose = null;
@@ -4283,13 +4308,13 @@ var Tt = class {
4283
4308
  heartbeatTimer = null;
4284
4309
  lastMessageTime = 0;
4285
4310
  constructor() {
4286
- super(), this.reconnector = new J(), this.wireReconnector();
4311
+ super(), this.reconnector = new K(), this.wireReconnector();
4287
4312
  }
4288
4313
  async connect(e) {
4289
4314
  this.disconnect(), this.config = {
4290
4315
  ...i,
4291
4316
  ...e
4292
- }, this.adapter = e.adapter, this.aggregator = new Mt(e.timeframe), this.reconnector.removeAllListeners(), this.reconnector.stop(), this.reconnector = new J(e.reconnect ?? r), this.wireReconnector(), this.aggregator.on("bar", (e) => {
4317
+ }, this.adapter = e.adapter, this.aggregator = new Ft(e.timeframe), this.reconnector.removeAllListeners(), this.reconnector.stop(), this.reconnector = new K(e.reconnect ?? r), this.wireReconnector(), this.aggregator.on("bar", (e) => {
4293
4318
  this.emit("barUpdate", e), this.updatePrice(e.close);
4294
4319
  }), this.aggregator.on("barClose", (e) => {
4295
4320
  this.previousClose = e.close, this.emit("barClose", e);
@@ -4349,20 +4374,28 @@ var Tt = class {
4349
4374
  });
4350
4375
  }
4351
4376
  wireAdapter() {
4352
- this.adapter && (this.adapter.on("connectionChange", ((e) => {
4377
+ if (!this.adapter) return;
4378
+ let e = this.adapter, t = (e) => {
4353
4379
  let t = e.data;
4354
4380
  this.lastMessageTime = Date.now(), t === "connected" ? (this.reconnector.onConnected(), this.setState("connected")) : (t === "disconnected" || t === "error") && this.reconnector.schedule(() => this.doConnect());
4355
- })), this.adapter.on("tick", ((e) => {
4381
+ };
4382
+ e.on("connectionChange", t), this.unsubscribers.push(() => e.off("connectionChange", t));
4383
+ let n = (e) => {
4356
4384
  this.lastMessageTime = Date.now();
4357
4385
  let t = e.data;
4358
4386
  this.emit("tick", t), this.config?.aggregateTicks && this.aggregator ? this.aggregator.processTick(t) : this.updatePrice(t.price);
4359
- })), this.adapter.on("bar", ((e) => {
4387
+ };
4388
+ e.on("tick", n), this.unsubscribers.push(() => e.off("tick", n));
4389
+ let r = (e) => {
4360
4390
  this.lastMessageTime = Date.now();
4361
4391
  let { bar: t, closed: n } = e.data;
4362
4392
  this.aggregator && this.aggregator.processBar(t, n);
4363
- })), this.adapter.on("error", ((e) => {
4393
+ };
4394
+ e.on("bar", r), this.unsubscribers.push(() => e.off("bar", r));
4395
+ let i = (e) => {
4364
4396
  this.emit("error", { message: e.data?.message ?? "Adapter error" });
4365
- })));
4397
+ };
4398
+ e.on("error", i), this.unsubscribers.push(() => e.off("error", i));
4366
4399
  }
4367
4400
  updatePrice(e) {
4368
4401
  e !== this.lastPrice && (this.lastPrice = e, this.priceLine.setPrice(e, this.previousClose ?? void 0), this.emit("priceChange", {
@@ -4391,7 +4424,7 @@ var Tt = class {
4391
4424
  dispose() {
4392
4425
  this.disconnect(), this.removeAllListeners();
4393
4426
  }
4394
- }, Ft = {
4427
+ }, Rt = {
4395
4428
  "1s": "1s",
4396
4429
  "1m": "1m",
4397
4430
  "3m": "3m",
@@ -4408,7 +4441,7 @@ var Tt = class {
4408
4441
  "3d": "3d",
4409
4442
  "1w": "1w",
4410
4443
  "1M": "1M"
4411
- }, It = class {
4444
+ }, zt = class {
4412
4445
  name = "binance";
4413
4446
  ws = null;
4414
4447
  state = "disconnected";
@@ -4429,7 +4462,7 @@ var Tt = class {
4429
4462
  return this.state;
4430
4463
  }
4431
4464
  async fetchHistory(e, t, n = 500) {
4432
- let r = Ft[t] ?? "15m", i = `${this.restBase}/klines?symbol=${e}&interval=${r}&limit=${n}`, a = await fetch(i);
4465
+ let r = Rt[t] ?? "15m", i = `${this.restBase}/klines?symbol=${e}&interval=${r}&limit=${n}`, a = await fetch(i);
4433
4466
  if (!a.ok) throw Error(`Binance REST error: ${a.status}`);
4434
4467
  return (await a.json()).map((e) => ({
4435
4468
  time: e[0],
@@ -4452,7 +4485,7 @@ var Tt = class {
4452
4485
  }
4453
4486
  connectWs() {
4454
4487
  if (!this.config) return;
4455
- let e = `${this.config.symbol.toLowerCase()}@kline_${Ft[this.config.timeframe] ?? "15m"}`, t = `${this.wsBase}/${e}`;
4488
+ let e = `${this.config.symbol.toLowerCase()}@kline_${Rt[this.config.timeframe] ?? "15m"}`, t = `${this.wsBase}/${e}`;
4456
4489
  this.setState("connecting");
4457
4490
  try {
4458
4491
  this.ws = new WebSocket(t);
@@ -4505,7 +4538,7 @@ var Tt = class {
4505
4538
  for (let e of n) e(r);
4506
4539
  }
4507
4540
  }
4508
- }, Lt = class {
4541
+ }, Bt = class {
4509
4542
  name = "mock";
4510
4543
  state = "disconnected";
4511
4544
  listeners = /* @__PURE__ */ new Map();
@@ -4600,7 +4633,7 @@ var Tt = class {
4600
4633
  for (let e of n) e(r);
4601
4634
  }
4602
4635
  }
4603
- }, Rt = {
4636
+ }, Vt = {
4604
4637
  visible: !0,
4605
4638
  showSymbol: !0,
4606
4639
  showOHLC: !0,
@@ -4608,8 +4641,8 @@ var Tt = class {
4608
4641
  showVolume: !0,
4609
4642
  position: "top-left",
4610
4643
  fontSize: 12
4611
- }, zt = class {
4612
- config = { ...Rt };
4644
+ }, Ht = class {
4645
+ config = { ...Vt };
4613
4646
  symbol = "";
4614
4647
  timeframe = "";
4615
4648
  hoverBar = null;
@@ -4696,7 +4729,7 @@ var Tt = class {
4696
4729
  }
4697
4730
  }
4698
4731
  }
4699
- }, Bt = class {
4732
+ }, Ut = class {
4700
4733
  static toDataURL(e, t) {
4701
4734
  let n = e.querySelectorAll("canvas");
4702
4735
  if (n.length === 0) return "";
@@ -4718,7 +4751,7 @@ var Tt = class {
4718
4751
  let i = document.createElement("a");
4719
4752
  i.href = r, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
4720
4753
  }
4721
- }, Vt = class {
4754
+ }, Wt = class {
4722
4755
  config = null;
4723
4756
  setConfig(e) {
4724
4757
  this.config = e;
@@ -4728,7 +4761,7 @@ var Tt = class {
4728
4761
  let { chartRect: r } = t, i = this.config.fontSize ?? 48, a = this.config.color ?? n.textSecondary;
4729
4762
  e.save(), e.globalAlpha = .07, e.font = `bold ${i}px ${n.font.family}`, e.fillStyle = a, e.textAlign = "center", e.textBaseline = "middle", e.fillText(this.config.text, r.x + r.width / 2, r.y + r.height / 2), e.restore();
4730
4763
  }
4731
- }, Ht = class {
4764
+ }, Gt = class {
4732
4765
  visible = !0;
4733
4766
  timeframeMs = 0;
4734
4767
  setVisible(e) {
@@ -4751,7 +4784,7 @@ var Tt = class {
4751
4784
  let t = Math.ceil(e / 1e3), n = Math.floor(t / 3600), r = Math.floor(t % 3600 / 60), i = t % 60;
4752
4785
  return n > 0 ? `${n}:${String(r).padStart(2, "0")}:${String(i).padStart(2, "0")}` : `${r}:${String(i).padStart(2, "0")}`;
4753
4786
  }
4754
- }, Ut = class {
4787
+ }, Kt = class {
4755
4788
  config = { visible: !1 };
4756
4789
  cachedBreaks = [];
4757
4790
  lastDataLength = 0;
@@ -4795,7 +4828,7 @@ var Tt = class {
4795
4828
  invalidateCache() {
4796
4829
  this.lastDataLength = 0, this.cachedBreaks = [];
4797
4830
  }
4798
- }, Wt = 1, Gt = class extends q {
4831
+ }, qt = 1, Jt = class extends G {
4799
4832
  alerts = [];
4800
4833
  lastPrice = null;
4801
4834
  requestRender = null;
@@ -4807,7 +4840,7 @@ var Tt = class {
4807
4840
  this.pricePrecision = e;
4808
4841
  }
4809
4842
  addAlert(e, t = "crossing", n, r = !1) {
4810
- let i = `tc_alert_${Wt++}`, a = {
4843
+ let i = `tc_alert_${qt++}`, a = {
4811
4844
  id: i,
4812
4845
  price: e,
4813
4846
  condition: t,
@@ -4887,7 +4920,7 @@ var Tt = class {
4887
4920
  e.fillText(s, r.x + r.width - 4, a - 2);
4888
4921
  }
4889
4922
  }
4890
- }, Kt = class extends q {
4923
+ }, Yt = class extends G {
4891
4924
  data = [];
4892
4925
  currentIndex = 0;
4893
4926
  timer = null;
@@ -4941,10 +4974,10 @@ var Tt = class {
4941
4974
  dispose() {
4942
4975
  this.stop(), this.removeAllListeners(), this.data = [];
4943
4976
  }
4944
- }, Y = 1, qt = class {
4977
+ }, q = 1, Xt = class {
4945
4978
  static capture(e, t) {
4946
4979
  return {
4947
- version: Y,
4980
+ version: q,
4948
4981
  timestamp: Date.now(),
4949
4982
  chartType: t?.chartType ?? "candlestick",
4950
4983
  symbol: t?.symbol,
@@ -4967,7 +5000,7 @@ var Tt = class {
4967
5000
  }
4968
5001
  static deserialize(e) {
4969
5002
  let t = JSON.parse(e);
4970
- return t.version !== Y && console.warn(`Chart state version mismatch: ${t.version} vs ${Y}`), t;
5003
+ return t.version !== q && console.warn(`Chart state version mismatch: ${t.version} vs ${q}`), t;
4971
5004
  }
4972
5005
  static saveToStorage(e, t) {
4973
5006
  localStorage.setItem(e, this.serialize(t));
@@ -4994,7 +5027,7 @@ var Tt = class {
4994
5027
  }, n.click();
4995
5028
  });
4996
5029
  }
4997
- }, Jt = class {
5030
+ }, Zt = class {
4998
5031
  undoStack = [];
4999
5032
  redoStack = [];
5000
5033
  maxHistory = 50;
@@ -5030,7 +5063,7 @@ var Tt = class {
5030
5063
  redoCount: this.redoStack.length
5031
5064
  };
5032
5065
  }
5033
- }, Yt = class {
5066
+ }, Qt = class {
5034
5067
  static toCSV(e) {
5035
5068
  return ["Time,Open,High,Low,Close,Volume", ...e.map((e) => `${new Date(e.time).toISOString()},${e.open},${e.high},${e.low},${e.close},${e.volume}`)].join("\n");
5036
5069
  }
@@ -5048,7 +5081,7 @@ var Tt = class {
5048
5081
  let r = new Blob([e], { type: n }), i = URL.createObjectURL(r), a = document.createElement("a");
5049
5082
  a.href = i, a.download = t, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(i);
5050
5083
  }
5051
- }, Xt = {
5084
+ }, $t = {
5052
5085
  linear: (e) => e,
5053
5086
  easeOutCubic: (e) => 1 - (1 - e) ** 3,
5054
5087
  easeOutQuart: (e) => 1 - (1 - e) ** 4,
@@ -5056,7 +5089,7 @@ var Tt = class {
5056
5089
  easeOutExpo: (e) => e === 1 ? 1 : 1 - 2 ** (-10 * e),
5057
5090
  easeOutElastic: (e) => e === 0 || e === 1 ? e : 2 ** (-10 * e) * Math.sin((e * 10 - .75) * (2 * Math.PI / 3)) + 1,
5058
5091
  spring: (e) => 1 - Math.E ** (-6 * e) * Math.cos(8 * e)
5059
- }, Zt = class {
5092
+ }, en = class {
5060
5093
  animations = /* @__PURE__ */ new Map();
5061
5094
  frameId = 0;
5062
5095
  running = !1;
@@ -5064,7 +5097,7 @@ var Tt = class {
5064
5097
  this.animations.set(e, {
5065
5098
  startTime: -1,
5066
5099
  duration: t.duration,
5067
- easing: t.easing ?? Xt.easeOutCubic,
5100
+ easing: t.easing ?? $t.easeOutCubic,
5068
5101
  onUpdate: t.onUpdate,
5069
5102
  onComplete: t.onComplete
5070
5103
  }), this.running || (this.running = !0, this.tick());
@@ -5099,10 +5132,10 @@ var Tt = class {
5099
5132
  };
5100
5133
  //#endregion
5101
5134
  //#region src/finance/BaseFinanceChart.ts
5102
- function Qt(t) {
5135
+ function tn(t) {
5103
5136
  return !t || t === "dark" ? e : t === "light" ? o : t;
5104
5137
  }
5105
- var $t = class {
5138
+ var nn = class {
5106
5139
  canvas;
5107
5140
  ctx;
5108
5141
  container;
@@ -5113,12 +5146,14 @@ var $t = class {
5113
5146
  frameId = null;
5114
5147
  resizeObserver;
5115
5148
  constructor(e, t) {
5116
- this.container = e, this.theme = Qt(t), this.canvas = document.createElement("canvas"), this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", e.appendChild(this.canvas), this.ctx = this.canvas.getContext("2d"), this.dpr = window.devicePixelRatio || 1, this.updateSize(), this.resizeObserver = new ResizeObserver(() => {
5149
+ this.container = e, this.theme = tn(t), this.canvas = document.createElement("canvas"), this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", e.appendChild(this.canvas), this.ctx = this.canvas.getContext("2d"), this.dpr = window.devicePixelRatio || 1, this.updateSize(), this.resizeObserver = new ResizeObserver(() => {
5117
5150
  this.updateSize(), this.requestRender();
5118
5151
  }), this.resizeObserver.observe(e);
5119
5152
  }
5120
5153
  updateSize() {
5121
- this.dpr = window.devicePixelRatio || 1, this.width = this.container.clientWidth, this.height = this.container.clientHeight, this.canvas.width = this.width * this.dpr, this.canvas.height = this.height * this.dpr;
5154
+ this.dpr = window.devicePixelRatio || 1;
5155
+ let e = this.container.getBoundingClientRect();
5156
+ this.width = e.width || this.container.clientWidth, this.height = e.height || this.container.clientHeight, this.canvas.width = Math.max(1, Math.floor(this.width * this.dpr)), this.canvas.height = Math.max(1, Math.floor(this.height * this.dpr));
5122
5157
  }
5123
5158
  requestRender() {
5124
5159
  this.frameId === null && (this.frameId = requestAnimationFrame(() => {
@@ -5126,12 +5161,12 @@ var $t = class {
5126
5161
  }));
5127
5162
  }
5128
5163
  setTheme(e) {
5129
- this.theme = Qt(e), this.requestRender();
5164
+ this.theme = tn(e), this.requestRender();
5130
5165
  }
5131
5166
  destroy() {
5132
5167
  this.frameId !== null && cancelAnimationFrame(this.frameId), this.resizeObserver.disconnect(), this.canvas.remove();
5133
5168
  }
5134
- }, en = class {
5169
+ }, rn = class {
5135
5170
  pos = null;
5136
5171
  canvas;
5137
5172
  onUpdate;
@@ -5163,7 +5198,7 @@ var $t = class {
5163
5198
  };
5164
5199
  //#endregion
5165
5200
  //#region src/finance/SparklineRenderer.ts
5166
- function tn(e, t, n, r, i) {
5201
+ function an(e, t, n, r, i) {
5167
5202
  let { data: a, mode: o = "area", lineWidth: s = 1.5, showLastPoint: c = !1, showMinMax: l = !1 } = r;
5168
5203
  if (a.length < 2 || t <= 0 || n <= 0) return;
5169
5204
  let u = r.color ?? i.lineColor, d = r.fillColor ?? u, f = t - 4, p = n - 4, m = Infinity, h = -Infinity, g = 0, _ = 0;
@@ -5188,8 +5223,8 @@ function tn(e, t, n, r, i) {
5188
5223
  }
5189
5224
  //#endregion
5190
5225
  //#region src/finance/DepthChartRenderer.ts
5191
- var nn = 50, rn = 60, X = 20, an = .2;
5192
- function on(e) {
5226
+ var on = 50, sn = 60, J = 20, cn = .2;
5227
+ function ln(e) {
5193
5228
  let t = [...e].sort((e, t) => t.price - e.price), n = [], r = 0;
5194
5229
  for (let e of t) r += e.volume, n.push({
5195
5230
  price: e.price,
@@ -5197,7 +5232,7 @@ function on(e) {
5197
5232
  });
5198
5233
  return n;
5199
5234
  }
5200
- function sn(e) {
5235
+ function un(e) {
5201
5236
  let t = [...e].sort((e, t) => e.price - t.price), n = [], r = 0;
5202
5237
  for (let e of t) r += e.volume, n.push({
5203
5238
  price: e.price,
@@ -5205,20 +5240,20 @@ function sn(e) {
5205
5240
  });
5206
5241
  return n;
5207
5242
  }
5208
- function cn(e, t) {
5243
+ function dn(e, t) {
5209
5244
  return {
5210
- left: nn,
5211
- right: e - rn,
5212
- top: X,
5213
- bottom: t - X,
5214
- plotWidth: e - nn - rn,
5215
- plotHeight: t - X * 2
5245
+ left: on,
5246
+ right: e - sn,
5247
+ top: J,
5248
+ bottom: t - J,
5249
+ plotWidth: e - on - sn,
5250
+ plotHeight: t - J * 2
5216
5251
  };
5217
5252
  }
5218
- function ln(e, t, n, r) {
5253
+ function fn(e, t, n, r) {
5219
5254
  e.fillStyle = r, e.fillRect(0, 0, t, n);
5220
5255
  }
5221
- function un(e, t, n, r, i, a, o, s) {
5256
+ function pn(e, t, n, r, i, a, o, s) {
5222
5257
  let { left: c, right: l, top: u, bottom: d, plotWidth: p, plotHeight: m } = t;
5223
5258
  e.save(), e.strokeStyle = a.grid, e.lineWidth = .5, e.fillStyle = a.axisLabel, e.font = `${a.font.sizeSmall}px ${a.font.family}`;
5224
5259
  let h = f(0, i, 5);
@@ -5233,7 +5268,7 @@ function un(e, t, n, r, i, a, o, s) {
5233
5268
  }
5234
5269
  e.restore();
5235
5270
  }
5236
- function dn(e, t, n, r, i, a, o, s, c) {
5271
+ function mn(e, t, n, r, i, a, o, s, c) {
5237
5272
  if (t.length === 0) return;
5238
5273
  let { left: l, bottom: u, plotWidth: d, plotHeight: f } = n, p = (e) => l + (e - r) / i * d, m = (e) => u - e / a * f;
5239
5274
  if (e.beginPath(), c === "bid") {
@@ -5266,14 +5301,14 @@ function dn(e, t, n, r, i, a, o, s, c) {
5266
5301
  }
5267
5302
  e.strokeStyle = s, e.lineWidth = 1.5, e.stroke();
5268
5303
  }
5269
- function fn(e, t, n, r, i, a, o, s, c) {
5304
+ function hn(e, t, n, r, i, a, o, s, c) {
5270
5305
  let { left: l, top: u, bottom: d, plotWidth: f } = r, p = l + (t - i) / a * f;
5271
5306
  if (e.save(), e.strokeStyle = o.textSecondary, e.lineWidth = 1, e.setLineDash([4, 4]), e.beginPath(), e.moveTo(p, u), e.lineTo(p, d), e.stroke(), e.restore(), s) {
5272
5307
  let t = `Spread: ${c(n)}`;
5273
5308
  e.save(), e.font = `${o.font.sizeSmall}px ${o.font.family}`, e.fillStyle = o.textSecondary, e.textAlign = "center", e.textBaseline = "bottom", e.fillText(t, p, u - 2), e.restore();
5274
5309
  }
5275
5310
  }
5276
- function pn(e, t, n, r, i, a, o, s, c, l, u) {
5311
+ function gn(e, t, n, r, i, a, o, s, c, l, u) {
5277
5312
  let { left: d, top: f, bottom: p, plotWidth: m, plotHeight: h } = i, g = t.x;
5278
5313
  if (g < d || g > i.right) return;
5279
5314
  let _ = a + (g - d) / m * o, v = 0, y = "";
@@ -5299,47 +5334,47 @@ function pn(e, t, n, r, i, a, o, s, c, l, u) {
5299
5334
  for (let t = 0; t < b.length; t++) e.fillText(b[t], C + 8, w + 6 + t * (c.font.sizeSmall + 4));
5300
5335
  e.restore();
5301
5336
  }
5302
- function mn(e) {
5337
+ function _n(e) {
5303
5338
  return e.toFixed(2);
5304
5339
  }
5305
- function hn(e) {
5340
+ function vn(e) {
5306
5341
  return e >= 1e6 ? (e / 1e6).toFixed(2) + "M" : e >= 1e3 ? (e / 1e3).toFixed(1) + "K" : e.toFixed(0);
5307
5342
  }
5308
- function gn(e, t, n, r, i, a) {
5343
+ function yn(e, t, n, r, i, a) {
5309
5344
  let { data: o } = r;
5310
5345
  if (o.bids.length === 0 && o.asks.length === 0 || t <= 0 || n <= 0) return;
5311
- let s = r.bidColor ?? i.candleUp, c = r.askColor ?? i.candleDown, l = r.bidFillColor ?? s + "40", u = r.askFillColor ?? c + "40", d = r.midPriceLine !== !1, f = r.spreadLabel !== !1, p = r.priceFormat ?? mn, m = r.volumeFormat ?? hn, h = on(o.bids), g = sn(o.asks), _ = h.length > 0 ? h[0].price : 0, v = g.length > 0 ? g[0].price : 0, y = h.length > 0 && g.length > 0 ? (_ + v) / 2 : _ || v, b = g.length > 0 && h.length > 0 ? v - _ : 0, x = h.length > 0 ? h[h.length - 1].price : y, S = g.length > 0 ? g[g.length - 1].price : y, C = Math.max(y - x, S - y) * (1 + an), w = y - C, T = y + C, E = T - w, D = h.length > 0 ? h[h.length - 1].cumulativeVolume : 0, O = g.length > 0 ? g[g.length - 1].cumulativeVolume : 0, k = Math.max(D, O) || 1, A = cn(t, n);
5312
- ln(e, t, n, i.background), un(e, A, w, T, k, i, p, m), dn(e, h, A, w, E, k, l, s, "bid"), dn(e, g, A, w, E, k, u, c, "ask"), d && fn(e, y, b, A, w, E, i, f, p), a && pn(e, a, h, g, A, w, E, k, i, p, m);
5346
+ let s = r.bidColor ?? i.candleUp, c = r.askColor ?? i.candleDown, l = r.bidFillColor ?? s + "40", u = r.askFillColor ?? c + "40", d = r.midPriceLine !== !1, f = r.spreadLabel !== !1, p = r.priceFormat ?? _n, m = r.volumeFormat ?? vn, h = ln(o.bids), g = un(o.asks), _ = h.length > 0 ? h[0].price : 0, v = g.length > 0 ? g[0].price : 0, y = h.length > 0 && g.length > 0 ? (_ + v) / 2 : _ || v, b = g.length > 0 && h.length > 0 ? v - _ : 0, x = h.length > 0 ? h[h.length - 1].price : y, S = g.length > 0 ? g[g.length - 1].price : y, C = Math.max(y - x, S - y) * (1 + cn), w = y - C, T = y + C, E = T - w, D = h.length > 0 ? h[h.length - 1].cumulativeVolume : 0, O = g.length > 0 ? g[g.length - 1].cumulativeVolume : 0, k = Math.max(D, O) || 1, A = dn(t, n);
5347
+ fn(e, t, n, i.background), pn(e, A, w, T, k, i, p, m), mn(e, h, A, w, E, k, l, s, "bid"), mn(e, g, A, w, E, k, u, c, "ask"), d && hn(e, y, b, A, w, E, i, f, p), a && gn(e, a, h, g, A, w, E, k, i, p, m);
5313
5348
  }
5314
5349
  //#endregion
5315
5350
  //#region src/finance/EquityCurveRenderer.ts
5316
- var _n = 70, vn = 30, yn = 20, bn = 20, xn = .05;
5317
- function Sn(e, t) {
5351
+ var bn = 70, xn = 30, Sn = 20, Cn = 20, wn = .05;
5352
+ function Tn(e, t) {
5318
5353
  return {
5319
- left: _n,
5320
- right: e - yn,
5321
- top: bn,
5322
- bottom: t - vn,
5323
- plotWidth: e - _n - yn,
5324
- plotHeight: t - bn - vn
5354
+ left: bn,
5355
+ right: e - Sn,
5356
+ top: Cn,
5357
+ bottom: t - xn,
5358
+ plotWidth: e - bn - Sn,
5359
+ plotHeight: t - Cn - xn
5325
5360
  };
5326
5361
  }
5327
- function Cn(e, t) {
5362
+ function En(e, t) {
5328
5363
  let n = Infinity, r = -Infinity;
5329
5364
  for (let t of e) t.value < n && (n = t.value), t.value > r && (r = t.value);
5330
5365
  if (t) for (let e of t) e.value < n && (n = e.value), e.value > r && (r = e.value);
5331
- let i = (r - n) * xn;
5366
+ let i = (r - n) * wn;
5332
5367
  return {
5333
5368
  valMin: n - i,
5334
5369
  valMax: r + i
5335
5370
  };
5336
5371
  }
5337
- function wn(e) {
5372
+ function Dn(e) {
5338
5373
  let t = [], n = -Infinity;
5339
5374
  for (let r of e) r.value > n && (n = r.value), t.push(n);
5340
5375
  return t;
5341
5376
  }
5342
- function Tn(e) {
5377
+ function On(e) {
5343
5378
  let t = 864e5;
5344
5379
  if (365.25 * t, e < 7 * t) {
5345
5380
  let e = new Intl.DateTimeFormat(void 0, {
@@ -5361,13 +5396,13 @@ function Tn(e) {
5361
5396
  });
5362
5397
  return (e) => n.format(new Date(e));
5363
5398
  }
5364
- function En(e) {
5399
+ function kn(e) {
5365
5400
  return Math.abs(e) >= 1e6 ? (e / 1e6).toFixed(2) + "M" : Math.abs(e) >= 1e3 ? (e / 1e3).toFixed(1) + "K" : e.toFixed(2);
5366
5401
  }
5367
- function Dn(e, t, n, r) {
5402
+ function An(e, t, n, r) {
5368
5403
  e.fillStyle = r, e.fillRect(0, 0, t, n);
5369
5404
  }
5370
- function On(e, t, n, r, i, a, o, s, c) {
5405
+ function jn(e, t, n, r, i, a, o, s, c) {
5371
5406
  let { left: l, right: u, top: d, bottom: p, plotWidth: m, plotHeight: h } = t;
5372
5407
  e.save(), e.strokeStyle = o.grid, e.lineWidth = .5, e.fillStyle = o.axisLabel, e.font = `${o.font.sizeSmall}px ${o.font.family}`;
5373
5408
  let g = f(n, r, 6), _ = Math.ceil(n / g) * g;
@@ -5382,21 +5417,21 @@ function On(e, t, n, r, i, a, o, s, c) {
5382
5417
  }
5383
5418
  e.restore();
5384
5419
  }
5385
- function Z(e, t, n, r, i, a, o, s, c) {
5420
+ function Mn(e, t, n, r, i, a, o, s, c) {
5386
5421
  if (t.length < 2) return;
5387
5422
  let { left: l, bottom: u, plotWidth: d, plotHeight: f } = n, p = (e) => l + (e - r) / i * d, m = (e) => u - (e - a) / o * f;
5388
5423
  e.save(), e.beginPath(), e.moveTo(p(t[0].time), m(t[0].value));
5389
5424
  for (let n = 1; n < t.length; n++) e.lineTo(p(t[n].time), m(t[n].value));
5390
5425
  e.strokeStyle = s, e.lineWidth = c, e.lineJoin = "round", e.stroke(), e.restore();
5391
5426
  }
5392
- function kn(e, t, n, r, i, a, o, s) {
5427
+ function Nn(e, t, n, r, i, a, o, s) {
5393
5428
  if (t.length < 2) return;
5394
5429
  let { left: c, bottom: l, plotWidth: u, plotHeight: d } = n, f = (e) => c + (e - r) / i * u, p = (e) => l - (e - a) / o * d, m = e.createLinearGradient(0, n.top, 0, l);
5395
5430
  m.addColorStop(0, s + "40"), m.addColorStop(1, "transparent"), e.save(), e.beginPath(), e.moveTo(f(t[0].time), p(t[0].value));
5396
5431
  for (let n = 1; n < t.length; n++) e.lineTo(f(t[n].time), p(t[n].value));
5397
5432
  e.lineTo(f(t[t.length - 1].time), l), e.lineTo(f(t[0].time), l), e.closePath(), e.fillStyle = m, e.fill(), e.restore();
5398
5433
  }
5399
- function An(e, t, n, r, i, a, o, s, c) {
5434
+ function Pn(e, t, n, r, i, a, o, s, c) {
5400
5435
  if (t.length < 2) return;
5401
5436
  let { left: l, bottom: u, plotWidth: d, plotHeight: f } = r, p = (e) => l + (e - i) / a * d, m = (e) => u - (e - o) / s * f;
5402
5437
  e.save(), e.fillStyle = c, e.beginPath(), e.moveTo(p(t[0].time), m(n[0]));
@@ -5404,12 +5439,12 @@ function An(e, t, n, r, i, a, o, s, c) {
5404
5439
  for (let n = t.length - 1; n >= 0; n--) e.lineTo(p(t[n].time), m(t[n].value));
5405
5440
  e.closePath(), e.fill(), e.restore();
5406
5441
  }
5407
- function jn(e, t, n, r, i, a, o, s, c, l) {
5442
+ function Fn(e, t, n, r, i, a, o, s, c, l) {
5408
5443
  if (t.length === 0) return;
5409
5444
  let { left: u, bottom: d, plotWidth: f, plotHeight: p } = n, m = t[t.length - 1], h = u + (m.time - r) / i * f, g = d - (m.value - a) / o * p;
5410
5445
  e.save(), e.font = `${l.font.sizeSmall}px ${l.font.family}`, e.fillStyle = c, e.textAlign = "left", e.textBaseline = "middle", e.fillText(s, h + 4, g), e.restore();
5411
5446
  }
5412
- function Mn(e, t, n, r, i, a, o, s, c, l, u, d) {
5447
+ function In(e, t, n, r, i, a, o, s, c, l, u, d) {
5413
5448
  let { left: f, top: p, bottom: m, plotWidth: h, plotHeight: g } = i, _ = t.x;
5414
5449
  if (_ < f || _ > i.right) return;
5415
5450
  e.save(), e.strokeStyle = l.crosshair, e.lineWidth = .5, e.setLineDash([4, 4]), e.beginPath(), e.moveTo(_, p), e.lineTo(_, m), e.stroke(), e.restore();
@@ -5427,15 +5462,15 @@ function Mn(e, t, n, r, i, a, o, s, c, l, u, d) {
5427
5462
  for (let t = 0; t < S.length; t++) e.fillText(S[t], D + 8, O + 6 + t * (l.font.sizeSmall + 4));
5428
5463
  e.restore();
5429
5464
  }
5430
- function Nn(e, t, n, r, i, a) {
5465
+ function Ln(e, t, n, r, i, a) {
5431
5466
  let { data: o } = r;
5432
5467
  if (o.length < 2 || t <= 0 || n <= 0) return;
5433
- let s = r.lineColor ?? i.lineColor, c = r.lineWidth ?? 1.5, l = r.drawdown === !0, u = r.drawdownColor ?? i.candleDown + "30", d = r.fillArea === !0, f = r.benchmark, p = r.benchmarkColor ?? i.textSecondary, m = r.benchmarkLabel ?? "Benchmark", h = r.valueFormat ?? En, { valMin: g, valMax: _ } = Cn(o, f), v = _ - g || 1, y = o[0].time, b = o[o.length - 1].time, x = b - y || 1, S = r.timeFormat ?? Tn(x), C = Sn(t, n);
5434
- Dn(e, t, n, i.background), On(e, C, g, _, y, b, i, h, S), l && An(e, o, wn(o), C, y, x, g, v, u), d && kn(e, o, C, y, x, g, v, s), Z(e, o, C, y, x, g, v, s, c), f && f.length >= 2 && (Z(e, f, C, y, x, g, v, p, 1), jn(e, f, C, y, x, g, v, m, p, i)), a && Mn(e, a, o, f, C, y, x, g, v, i, S, h);
5468
+ let s = r.lineColor ?? i.lineColor, c = r.lineWidth ?? 1.5, l = r.drawdown === !0, u = r.drawdownColor ?? i.candleDown + "30", d = r.fillArea === !0, f = r.benchmark, p = r.benchmarkColor ?? i.textSecondary, m = r.benchmarkLabel ?? "Benchmark", h = r.valueFormat ?? kn, { valMin: g, valMax: _ } = En(o, f), v = _ - g || 1, y = o[0].time, b = o[o.length - 1].time, x = b - y || 1, S = r.timeFormat ?? On(x), C = Tn(t, n);
5469
+ An(e, t, n, i.background), jn(e, C, g, _, y, b, i, h, S), l && Pn(e, o, Dn(o), C, y, x, g, v, u), d && Nn(e, o, C, y, x, g, v, s), Mn(e, o, C, y, x, g, v, s, c), f && f.length >= 2 && (Mn(e, f, C, y, x, g, v, p, 1), Fn(e, f, C, y, x, g, v, m, p, i)), a && In(e, a, o, f, C, y, x, g, v, i, S, h);
5435
5470
  }
5436
5471
  //#endregion
5437
5472
  //#region src/finance/HeatmapLayout.ts
5438
- function Pn(e, t, n) {
5473
+ function Rn(e, t, n) {
5439
5474
  if (e.length === 0) return [];
5440
5475
  let r = e.length, i = Math.ceil(Math.sqrt(r)), a = Math.ceil(r / i), o = t.width / i, s = t.height / a, c = [];
5441
5476
  for (let a = 0; a < r; a++) {
@@ -5452,7 +5487,7 @@ function Pn(e, t, n) {
5452
5487
  }
5453
5488
  return c;
5454
5489
  }
5455
- function Fn(e, t) {
5490
+ function zn(e, t) {
5456
5491
  let n = e.reduce((e, t) => e + t, 0);
5457
5492
  if (n === 0 || t === 0) return Infinity;
5458
5493
  let r = 0;
@@ -5462,7 +5497,7 @@ function Fn(e, t) {
5462
5497
  }
5463
5498
  return r;
5464
5499
  }
5465
- function Q(e, t, n, r, i, a) {
5500
+ function Y(e, t, n, r, i, a) {
5466
5501
  let o = r ? n.height : n.width, s = e.reduce((e, t) => e + t, 0), c = o > 0 ? s / o : 0, l = 0;
5467
5502
  for (let o = 0; o < e.length; o++) {
5468
5503
  let s = c > 0 ? e[o] / c : 0, u;
@@ -5482,19 +5517,19 @@ function Q(e, t, n, r, i, a) {
5482
5517
  }), l += s;
5483
5518
  }
5484
5519
  }
5485
- function In(e, t, n, r, i) {
5520
+ function Bn(e, t, n, r, i) {
5486
5521
  if (e.length === 0) return;
5487
5522
  let a = n.width >= n.height, o = a ? n.height : n.width;
5488
5523
  if (e.length === 1) {
5489
- Q(e, t, n, a, r, i);
5524
+ Y(e, t, n, a, r, i);
5490
5525
  return;
5491
5526
  }
5492
5527
  let s = [], c = [], l = 0;
5493
5528
  for (; l < e.length;) {
5494
5529
  let u = [...s, e[l]];
5495
- if (s.length === 0 || Fn(u, o) <= Fn(s, o)) s.push(e[l]), c.push(t[l]), l++;
5530
+ if (s.length === 0 || zn(u, o) <= zn(s, o)) s.push(e[l]), c.push(t[l]), l++;
5496
5531
  else {
5497
- Q(s, c, n, a, r, i);
5532
+ Y(s, c, n, a, r, i);
5498
5533
  let u = s.reduce((e, t) => e + t, 0), d = o > 0 ? u / o : 0;
5499
5534
  n = a ? {
5500
5535
  x: n.x + d,
@@ -5506,28 +5541,28 @@ function In(e, t, n, r, i) {
5506
5541
  y: n.y + d,
5507
5542
  width: n.width,
5508
5543
  height: n.height - d
5509
- }, In(e.slice(l), t.slice(l), n, r, i);
5544
+ }, Bn(e.slice(l), t.slice(l), n, r, i);
5510
5545
  return;
5511
5546
  }
5512
5547
  }
5513
- s.length > 0 && Q(s, c, n, a, r, i);
5548
+ s.length > 0 && Y(s, c, n, a, r, i);
5514
5549
  }
5515
- function Ln(e, t, n) {
5550
+ function Vn(e, t, n) {
5516
5551
  if (e.length === 0) return [];
5517
5552
  let r = [...e].sort((e, t) => t.weight - e.weight), i = r.reduce((e, t) => e + Math.max(0, t.weight), 0);
5518
5553
  if (i === 0) return [];
5519
5554
  let a = t.width * t.height, o = r.map((e) => Math.max(0, e.weight) / i * a), s = r.map((e) => e.id), c = [];
5520
- return In(o, s, { ...t }, n, c), c;
5555
+ return Bn(o, s, { ...t }, n, c), c;
5521
5556
  }
5522
5557
  //#endregion
5523
5558
  //#region src/finance/HeatmapRenderer.ts
5524
- function Rn(e) {
5559
+ function Hn(e) {
5525
5560
  return (e >= 0 ? "+" : "") + e.toFixed(2) + "%";
5526
5561
  }
5527
- function zn(e) {
5562
+ function Un(e) {
5528
5563
  return e.label;
5529
5564
  }
5530
- function Bn(e, t) {
5565
+ function Wn(e, t) {
5531
5566
  let n = t.min ?? -5, r = t.max ?? 5;
5532
5567
  if (e <= n) return t.negative;
5533
5568
  if (e >= r) return t.positive;
@@ -5538,11 +5573,11 @@ function Bn(e, t) {
5538
5573
  let i = e / r;
5539
5574
  return m(t.zero, t.positive, i);
5540
5575
  }
5541
- function $(e, t, n, r, i, a) {
5576
+ function X(e, t, n, r, i, a) {
5542
5577
  let o = Math.min(a, r / 2, i / 2);
5543
5578
  e.beginPath(), e.moveTo(t + o, n), e.lineTo(t + r - o, n), e.arcTo(t + r, n, t + r, n + o, o), e.lineTo(t + r, n + i - o), e.arcTo(t + r, n + i, t + r - o, n + i, o), e.lineTo(t + o, n + i), e.arcTo(t, n + i, t, n + i - o, o), e.lineTo(t, n + o), e.arcTo(t, n, t + o, n, o), e.closePath();
5544
5579
  }
5545
- function Vn(e, t, n, r, i, a, o, s, c, l, u) {
5580
+ function Gn(e, t, n, r, i, a, o, s, c, l, u) {
5546
5581
  if (i < 40 || a < 30) return;
5547
5582
  let d = n + i / 2, f = r + a / 2;
5548
5583
  if (e.save(), e.shadowColor = "rgba(0,0,0,0.6)", e.shadowBlur = 2, e.fillStyle = "#FFFFFF", e.textAlign = "center", s) {
@@ -5555,22 +5590,22 @@ function Vn(e, t, n, r, i, a, o, s, c, l, u) {
5555
5590
  }
5556
5591
  e.restore();
5557
5592
  }
5558
- function Hn(e, t, n, r, i, a, o, s) {
5593
+ function Kn(e, t, n, r, i, a, o, s) {
5559
5594
  let c = [o(t), s(t.value)];
5560
5595
  if (t.meta) for (let [e, n] of Object.entries(t.meta)) c.push(e + ": " + String(n));
5561
5596
  e.save(), e.font = a.font.sizeSmall + "px " + a.font.family;
5562
5597
  let l = Math.max(...c.map((t) => e.measureText(t).width)) + 16, u = a.font.sizeSmall + 4, d = c.length * u + 12, f = n.x + 14, p = n.y - d / 2;
5563
- f + l > r && (f = n.x - l - 14), p < 0 && (p = 0), p + d > i && (p = i - d), e.fillStyle = a.axisLabelBackground, e.globalAlpha = .92, $(e, f, p, l, d, 4), e.fill(), e.globalAlpha = 1, e.fillStyle = a.text, e.textBaseline = "top", e.textAlign = "left";
5598
+ f + l > r && (f = n.x - l - 14), p < 0 && (p = 0), p + d > i && (p = i - d), e.fillStyle = a.axisLabelBackground, e.globalAlpha = .92, X(e, f, p, l, d, 4), e.fill(), e.globalAlpha = 1, e.fillStyle = a.text, e.textBaseline = "top", e.textAlign = "left";
5564
5599
  for (let t = 0; t < c.length; t++) e.fillText(c[t], f + 8, p + 6 + t * u);
5565
5600
  e.restore();
5566
5601
  }
5567
- function Un(e, t, n, r, i, a, o, s) {
5602
+ function qn(e, t, n, r, i, a, o, s) {
5568
5603
  if (r.length === 0 || i.length === 0 || t <= 0 || n <= 0) return null;
5569
5604
  let c = a.colorScale ?? {
5570
5605
  negative: "#EF5350",
5571
5606
  zero: "#424242",
5572
5607
  positive: "#26A69A"
5573
- }, l = a.cellRadius ?? 4, u = a.showLabels !== !1, d = a.showValues !== !1, f = a.valueFormat ?? Rn, p = a.labelFormat ?? zn, m = /* @__PURE__ */ new Map();
5608
+ }, l = a.cellRadius ?? 4, u = a.showLabels !== !1, d = a.showValues !== !1, f = a.valueFormat ?? Hn, p = a.labelFormat ?? Un, m = /* @__PURE__ */ new Map();
5574
5609
  for (let e of r) m.set(e.id, e);
5575
5610
  let h = null, g = null;
5576
5611
  if (s) for (let e of i) {
@@ -5591,12 +5626,272 @@ function Un(e, t, n, r, i, a, o, s) {
5591
5626
  if (!n) continue;
5592
5627
  let { x: r, y: i, width: a, height: s } = t.rect;
5593
5628
  if (a <= 0 || s <= 0) continue;
5594
- let g = Bn(n.value, c);
5595
- $(e, r, i, a, s, l), e.fillStyle = g, e.fill(), Vn(e, n, r, i, a, s, o, u, d, p, f), t.id === h && ($(e, r, i, a, s, l), e.strokeStyle = "#FFFFFF", e.lineWidth = 1.5, e.stroke());
5629
+ let g = Wn(n.value, c);
5630
+ X(e, r, i, a, s, l), e.fillStyle = g, e.fill(), Gn(e, n, r, i, a, s, o, u, d, p, f), t.id === h && (X(e, r, i, a, s, l), e.strokeStyle = "#FFFFFF", e.lineWidth = 1.5, e.stroke());
5631
+ }
5632
+ return g && s && Kn(e, g.cell, s, t, n, o, p, f), g;
5633
+ }
5634
+ //#endregion
5635
+ //#region src/finance/WaterfallRenderer.ts
5636
+ var Jn = 60, Z = 12, Yn = 24, Xn = 40, Zn = .7, Qn = 1;
5637
+ function $n(e) {
5638
+ return e.type ? e.type : e.value > 0 ? "positive" : e.value < 0 ? "negative" : "subtotal";
5639
+ }
5640
+ function er(e) {
5641
+ let t = Math.abs(e);
5642
+ return t >= 1e6 ? (e / 1e6).toFixed(2) + "M" : t >= 1e3 ? (e / 1e3).toFixed(1) + "K" : e.toFixed(2);
5643
+ }
5644
+ function tr(e, t) {
5645
+ return {
5646
+ left: Jn,
5647
+ right: e - Z,
5648
+ top: Yn,
5649
+ bottom: t - Xn,
5650
+ plotWidth: e - Jn - Z,
5651
+ plotHeight: t - Yn - Xn
5652
+ };
5653
+ }
5654
+ function nr(e, t, n, r, i) {
5655
+ let a = Array(e.length), o = Array(e.length), s = t.plotWidth / e.length, c = s * n, l = (s - c) / 2, { left: u, bottom: d, plotHeight: f } = t, p = 0;
5656
+ for (let t = 0; t < e.length; t++) {
5657
+ let n = e[t], m = $n(n), h, g;
5658
+ m === "total" || m === "subtotal" ? (h = 0, g = n.value, p = n.value) : (h = p, g = p + n.value, p = g);
5659
+ let _ = Math.min(h, g), v = Math.max(h, g), y = d - (_ - r) / i * f, b = d - (v - r) / i * f, x = Math.min(y, b), S = Math.max(Math.abs(b - y), Qn), C = u + t * s, w = C + l;
5660
+ a[t] = {
5661
+ label: n.label,
5662
+ value: n.value,
5663
+ start: h,
5664
+ end: g,
5665
+ type: m,
5666
+ rectX: w,
5667
+ rectY: x,
5668
+ rectW: c,
5669
+ rectH: S,
5670
+ slotX: C,
5671
+ slotW: s
5672
+ }, o[t] = p;
5673
+ }
5674
+ return {
5675
+ bars: a,
5676
+ cumulatives: o
5677
+ };
5678
+ }
5679
+ function rr(e) {
5680
+ if (e.length === 0) return {
5681
+ valMin: 0,
5682
+ valMax: 1
5683
+ };
5684
+ let t = 0, n = 0, r = 0;
5685
+ for (let i = 0; i < e.length; i++) {
5686
+ let a = e[i], o = $n(a), s, c;
5687
+ o === "total" || o === "subtotal" ? (s = 0, c = a.value, r = a.value) : (s = r, c = r + a.value, r = c), s < t && (t = s), c < t && (t = c), s > n && (n = s), c > n && (n = c);
5688
+ }
5689
+ let i = (n - t || 1) * .1;
5690
+ return {
5691
+ valMin: t - i,
5692
+ valMax: n + i
5693
+ };
5694
+ }
5695
+ function ir(e, t, n, r) {
5696
+ e.fillStyle = r, e.fillRect(0, 0, t, n);
5697
+ }
5698
+ function ar(e, t, n, r, i, a) {
5699
+ let { left: o, right: s, top: c, bottom: l, plotHeight: u } = t, d = r - n || 1;
5700
+ e.strokeStyle = i.grid, e.lineWidth = .5, e.fillStyle = i.axisLabel, e.font = `${i.font.sizeSmall}px ${i.font.family}`, e.textAlign = "right", e.textBaseline = "middle";
5701
+ let p = f(n, r, 5), m = Math.ceil(n / p) * p;
5702
+ e.beginPath();
5703
+ for (let t = m; t <= r; t += p) {
5704
+ let r = Math.round(l - (t - n) / d * u) + .5;
5705
+ r < c || r > l || (e.moveTo(o, r), e.lineTo(s, r));
5706
+ }
5707
+ e.stroke();
5708
+ for (let t = m; t <= r; t += p) {
5709
+ let r = l - (t - n) / d * u;
5710
+ r < c - 1 || r > l + 1 || e.fillText(a(t), o - 6, r);
5711
+ }
5712
+ if (n < 0 && r > 0) {
5713
+ let t = Math.round(l - (0 - n) / d * u) + .5;
5714
+ e.strokeStyle = i.axisLine, e.lineWidth = 1, e.beginPath(), e.moveTo(o, t), e.lineTo(s, t), e.stroke();
5715
+ }
5716
+ }
5717
+ function or(e, t, n) {
5718
+ let r = [
5719
+ "positive",
5720
+ "negative",
5721
+ "total",
5722
+ "subtotal"
5723
+ ];
5724
+ for (let i = 0; i < r.length; i++) {
5725
+ let a = r[i], o = n[a], s = !1;
5726
+ e.beginPath();
5727
+ for (let n = 0; n < t.length; n++) {
5728
+ let r = t[n];
5729
+ if (r.type !== a) continue;
5730
+ let i = Math.round(r.rectX), o = Math.round(r.rectY), c = Math.round(r.rectW), l = Math.round(r.rectH);
5731
+ e.rect(i, o, c, l), s = !0;
5732
+ }
5733
+ s && (e.fillStyle = o, e.fill());
5734
+ }
5735
+ }
5736
+ function sr(e, t, n, r, i, a, o) {
5737
+ if (o === "none" || t.length < 2) return;
5738
+ let { bottom: s, plotHeight: c } = n;
5739
+ e.strokeStyle = a, e.lineWidth = 1, o === "dashed" ? e.setLineDash([4, 4]) : e.setLineDash([]), e.beginPath();
5740
+ for (let n = 0; n < t.length - 1; n++) {
5741
+ let a = t[n], o = t[n + 1], l = a.end, u = Math.round(s - (l - r) / i * c) + .5, d = Math.round(a.rectX + a.rectW), f = Math.round(o.rectX);
5742
+ f <= d || (e.moveTo(d, u), e.lineTo(f, u));
5743
+ }
5744
+ e.stroke(), e.setLineDash([]);
5745
+ }
5746
+ function cr(e, t, n, r, i, a) {
5747
+ e.fillStyle = r.text, e.font = `${r.font.sizeSmall}px ${r.font.family}`, e.textAlign = "center";
5748
+ for (let r = 0; r < t.length; r++) {
5749
+ let o = t[r], s;
5750
+ s = o.type === "total" || o.type === "subtotal" ? i(o.value) : a ? `${o.value >= 0 ? "+" : ""}${i(o.value)}` : i(n[r]);
5751
+ let c = o.rectX + o.rectW / 2;
5752
+ o.end < o.start ? (e.textBaseline = "top", e.fillText(s, c, o.rectY + o.rectH + 4)) : (e.textBaseline = "bottom", e.fillText(s, c, o.rectY - 4));
5753
+ }
5754
+ }
5755
+ function lr(e, t, n, r, i) {
5756
+ e.fillStyle = r.axisLabel, e.font = `${r.font.sizeSmall}px ${r.font.family}`, e.textAlign = "center", e.textBaseline = "top";
5757
+ let a = n.bottom + 6, o = t.length > 0 ? t[0].slotW - 4 : 0, s = !1;
5758
+ for (let n = 0; n < t.length; n++) if (e.measureText(i(t[n].label)).width > o) {
5759
+ s = !0;
5760
+ break;
5761
+ }
5762
+ if (!s) {
5763
+ for (let n = 0; n < t.length; n++) {
5764
+ let r = t[n], o = r.slotX + r.slotW / 2;
5765
+ e.fillText(i(r.label), o, a);
5766
+ }
5767
+ return;
5768
+ }
5769
+ e.save(), e.textAlign = "right", e.textBaseline = "middle";
5770
+ for (let n = 0; n < t.length; n++) {
5771
+ let r = t[n], o = r.slotX + r.slotW / 2;
5772
+ e.setTransform(1, 0, 0, 1, o, a + 4), e.rotate(-Math.PI / 4), e.fillText(i(r.label), 0, 0);
5773
+ }
5774
+ e.setTransform(1, 0, 0, 1, 0, 0), e.restore();
5775
+ }
5776
+ function ur(e, t, n) {
5777
+ if (t < n.left || t > n.right) return null;
5778
+ for (let n = 0; n < e.length; n++) {
5779
+ let r = e[n];
5780
+ if (t >= r.slotX && t <= r.slotX + r.slotW) return n;
5781
+ }
5782
+ return null;
5783
+ }
5784
+ function dr(e, t, n, r, i, a, o, s) {
5785
+ let c = t[r], l = n[r], u = Math.round(c.slotX + c.slotW / 2) + .5;
5786
+ e.strokeStyle = o.crosshair, e.lineWidth = .5, e.setLineDash([4, 4]), e.beginPath(), e.moveTo(u, a.top), e.lineTo(u, a.bottom), e.stroke(), e.setLineDash([]);
5787
+ let d = [
5788
+ c.label,
5789
+ `Value: ${c.value >= 0 && (c.type === "positive" || c.type === "negative") ? "+" : ""}${s(c.value)}`,
5790
+ `Total: ${s(l)}`
5791
+ ];
5792
+ e.font = `${o.font.sizeSmall}px ${o.font.family}`;
5793
+ let f = 0;
5794
+ for (let t = 0; t < d.length; t++) {
5795
+ let n = e.measureText(d[t]).width;
5796
+ n > f && (f = n);
5797
+ }
5798
+ let p = f + 16, m = d.length * (o.font.sizeSmall + 4) + 12, h = i.x + 10, g = i.y - m / 2;
5799
+ h + p > a.right && (h = i.x - p - 10), g < a.top && (g = a.top), g + m > a.bottom && (g = a.bottom - m), e.fillStyle = o.axisLabelBackground, e.globalAlpha = .9, e.fillRect(h, g, p, m), e.globalAlpha = 1, e.fillStyle = o.text, e.textAlign = "left", e.textBaseline = "top";
5800
+ let _ = o.font.sizeSmall + 4;
5801
+ for (let t = 0; t < d.length; t++) e.fillText(d[t], h + 8, g + 6 + t * _);
5802
+ }
5803
+ function fr(e, t, n, r, i, a) {
5804
+ let { data: o } = r;
5805
+ if (!o || o.length === 0 || t <= 0 || n <= 0) return { hitBar: null };
5806
+ let s = r.positiveColor ?? i.candleUp, c = r.negativeColor ?? i.candleDown, l = r.totalColor ?? i.lineColor, u = r.subtotalColor ?? i.textSecondary, d = r.connectorColor ?? i.textSecondary, f = r.connectorStyle ?? "dashed", p = r.barWidth ?? Zn, m = r.showValues !== !1, h = r.showDelta !== !1, g = r.valueFormat ?? er, _ = r.labelFormat ?? ((e) => e), { valMin: v, valMax: y } = rr(o), b = y - v || 1, x = tr(t, n), { bars: S, cumulatives: C } = nr(o, x, p, v, b);
5807
+ ir(e, t, n, i.background), ar(e, x, v, y, i, g), sr(e, S, x, v, b, d, f), or(e, S, {
5808
+ positive: s,
5809
+ negative: c,
5810
+ total: l,
5811
+ subtotal: u
5812
+ }), m && cr(e, S, C, i, g, h), lr(e, S, x, i, _);
5813
+ let w = a ? ur(S, a.x, x) : null;
5814
+ return a && w !== null && dr(e, S, C, w, a, x, i, g), { hitBar: w };
5815
+ }
5816
+ //#endregion
5817
+ //#region src/finance/GaugeRenderer.ts
5818
+ var pr = Math.PI / 180, mr = 135, hr = 405, gr = .25;
5819
+ function _r(e) {
5820
+ let t = Math.abs(e);
5821
+ return t >= 1e6 ? (e / 1e6).toFixed(2) + "M" : t >= 1e3 ? (e / 1e3).toFixed(1) + "K" : Number.isInteger(e) ? e.toFixed(0) : e.toFixed(1);
5822
+ }
5823
+ function Q(e, t, n) {
5824
+ return e < t ? t : e > n ? n : e;
5825
+ }
5826
+ function vr(e, t, n) {
5827
+ let r = n.min ?? 0, i = n.max ?? 100, a = i - r || 1, o = (n.startAngle ?? mr) * pr, s = (n.endAngle ?? hr) * pr, c = n.thickness ?? gr, l = e / 2, u = t / 2 + t * .05, d = Math.max(10, Math.min(e, t) / 2 - 24);
5828
+ return {
5829
+ cx: l,
5830
+ cy: u,
5831
+ radius: d,
5832
+ innerRadius: Math.max(2, d * (1 - c)),
5833
+ startAngle: o,
5834
+ endAngle: s,
5835
+ angleRange: s - o,
5836
+ min: r,
5837
+ max: i,
5838
+ range: a
5839
+ };
5840
+ }
5841
+ function $(e, t) {
5842
+ let n = Q((e - t.min) / t.range, 0, 1);
5843
+ return t.startAngle + t.angleRange * n;
5844
+ }
5845
+ function yr(e, t, n, r) {
5846
+ e.fillStyle = r, e.fillRect(0, 0, t, n);
5847
+ }
5848
+ function br(e, t, n) {
5849
+ e.beginPath(), e.arc(t.cx, t.cy, t.radius, t.startAngle, t.endAngle, !1), e.arc(t.cx, t.cy, t.innerRadius, t.endAngle, t.startAngle, !0), e.closePath(), e.fillStyle = n, e.fill();
5850
+ }
5851
+ function xr(e, t, n) {
5852
+ let r = Q(n.from, t.min, t.max), i = Q(n.to, t.min, t.max);
5853
+ if (i <= r) return;
5854
+ let a = $(r, t), o = $(i, t);
5855
+ e.beginPath(), e.arc(t.cx, t.cy, t.radius, a, o, !1), e.arc(t.cx, t.cy, t.innerRadius, o, a, !0), e.closePath(), e.fillStyle = n.color, e.fill();
5856
+ }
5857
+ function Sr(e, t, n, r, i) {
5858
+ let a = $(n, t);
5859
+ a <= t.startAngle || (e.globalAlpha = i, e.beginPath(), e.arc(t.cx, t.cy, t.radius, t.startAngle, a, !1), e.arc(t.cx, t.cy, t.innerRadius, a, t.startAngle, !0), e.closePath(), e.fillStyle = r, e.fill(), e.globalAlpha = 1);
5860
+ }
5861
+ function Cr(e, t, n, r) {
5862
+ let i = $(n, t), a = Math.cos(i), o = Math.sin(i), s = t.radius - 2, c = t.innerRadius * .25, l = -o, u = a, d = t.cx + a * s, f = t.cy + o * s, p = t.cx + l * 4 - a * c, m = t.cy + u * 4 - o * c, h = t.cx - l * 4 - a * c, g = t.cy - u * 4 - o * c;
5863
+ e.beginPath(), e.moveTo(d, f), e.lineTo(p, m), e.lineTo(h, g), e.closePath(), e.fillStyle = r, e.fill(), e.beginPath(), e.arc(t.cx, t.cy, Math.max(4, t.innerRadius * .12), 0, Math.PI * 2), e.fill();
5864
+ }
5865
+ function wr(e, t, n, r, i) {
5866
+ let a = Math.round(t.innerRadius * .55), o = Math.round(i.font.sizeMedium);
5867
+ e.fillStyle = i.text, e.textAlign = "center", e.textBaseline = "middle", e.font = `600 ${a}px ${i.font.family}`;
5868
+ let s = !!r, c = s ? t.cy - o * .6 : t.cy - a * .1;
5869
+ e.fillText(n, t.cx, c), s && (e.fillStyle = i.textSecondary, e.font = `${o}px ${i.font.family}`, e.fillText(r, t.cx, t.cy + a * .55));
5870
+ }
5871
+ function Tr(e, t, n, r) {
5872
+ e.fillStyle = r.textSecondary, e.font = `${r.font.sizeSmall}px ${r.font.family}`;
5873
+ let i = t.radius + 10, a = Math.cos(t.startAngle), o = Math.sin(t.startAngle), s = Math.cos(t.endAngle), c = Math.sin(t.endAngle), l = t.cx + a * i, u = t.cy + o * i, d = t.cx + s * i, f = t.cy + c * i;
5874
+ e.textBaseline = "middle", e.textAlign = a < -.2 ? "right" : a > .2 ? "left" : "center", e.fillText(n(t.min), l, u), e.textAlign = s < -.2 ? "right" : s > .2 ? "left" : "center", e.fillText(n(t.max), d, f);
5875
+ }
5876
+ function Er(e, t, n, r) {
5877
+ e.fillStyle = r.textSecondary, e.font = `${r.font.sizeSmall}px ${r.font.family}`, e.textAlign = "center", e.textBaseline = "middle";
5878
+ let i = (t.radius + t.innerRadius) / 2;
5879
+ for (let r = 0; r < n.length; r++) {
5880
+ let a = n[r];
5881
+ if (!a.label) continue;
5882
+ let o = $((Q(a.from, t.min, t.max) + Q(a.to, t.min, t.max)) / 2, t), s = t.cx + Math.cos(o) * i, c = t.cy + Math.sin(o) * i;
5883
+ e.fillText(a.label, s, c);
5596
5884
  }
5597
- return g && s && Hn(e, g.cell, s, t, n, o, p, f), g;
5885
+ }
5886
+ function Dr(e, t, n, r, i, a) {
5887
+ if (t <= 0 || n <= 0) return;
5888
+ let o = vr(t, n, r), s = r.trackColor ?? i.grid, c = r.needleColor ?? i.text, l = r.showValue !== !1, u = r.showZoneLabels === !0, d = r.valueFormat ?? _r, f = Q(a, o.min, o.max);
5889
+ yr(e, t, n, i.background), br(e, o, s);
5890
+ let p = r.zones;
5891
+ if (p && p.length > 0) for (let t = 0; t < p.length; t++) xr(e, o, p[t]);
5892
+ Sr(e, o, f, c, .12), Cr(e, o, f, c), l && wr(e, o, d(f), r.label, i), Tr(e, o, d, i), u && p && p.length > 0 && Er(e, o, p, i);
5598
5893
  }
5599
5894
  //#endregion
5600
- export { be as ADXIndicator, ye as ATRIndicator, je as AccumulationDistributionIndicator, Gt as AlertManager, St as AnchoredVWAPTool, Zt as Animator, te as AreaRenderer, Te as AroonIndicator, vt as ArrowTool, Ht as BarCountdown, ne as BarRenderer, $t as BaseFinanceChart, ie as BaselineRenderer, It as BinanceAdapter, P as BollingerBandsIndicator, Ce as CCIIndicator, Oe as CMFIndicator, A as CandlestickRenderer, v as CanvasLayer, zt as ChartLegend, qt as ChartStateManager, le as CompareRenderer, Ue as CrosshairHandler, Ge as CrosshairTooltip, Nt as CurrentPriceLine, Rt as DEFAULT_LEGEND_CONFIG, x as DPRManager, Yt as DataExporter, ht as DateRangeTool, Dt as DepthOverlay, B as DonchianChannelIndicator, W as DrawingBase, Xe as DrawingManager, Ze as DrawingRenderer, N as EMAIndicator, Xt as Easing, pt as ElliottWaveTool, lt as EllipseTool, q as Emitter, Je as EventBus, nt as ExtendedLineTool, st as FibExtensionTool, at as FibRetracementTool, en as FinanceCrosshair, xt as GannBoxTool, bt as GannFanTool, Pe as GridRenderer, re as HollowCandleRenderer, $e as HorizontalLineTool, I as IchimokuIndicator, j as IndicatorBase, _e as IndicatorEngine, Be as InteractionManager, oe as KagiRenderer, z as KeltnerChannelIndicator, We as KeyboardHandler, y as LayerManager, ee as LineRenderer, H as MACDIndicator, we as MFIIndicator, gt as MeasureTool, Lt as MockAdapter, xe as OBVIndicator, Tt as OrderRenderer, Ve as PanHandler, L as ParabolicSARIndicator, rt as ParallelChannelTool, dt as PitchforkTool, se as PointAndFigureRenderer, Et as PositionRenderer, Fe as PriceAxis, mt as PriceRangeTool, Ee as ROCIndicator, V as RSIIndicator, tt as RayTool, J as ReconnectManager, ct as RectangleTool, it as RegressionChannelTool, D as RenderEngine, b as RenderLoop, ae as RenkoRenderer, Kt as ReplayManager, M as SMAIndicator, Bt as Screenshot, Ut as SessionBreaks, ke as StdDevIndicator, ve as StochasticIndicator, Pt as StreamManager, R as SupertrendIndicator, De as TSIIndicator, _t as TextAnnotationTool, Mt as TickAggregator, ze as TimeAxis, kt as TradingContextMenu, Ot as TradingDragHandler, At as TradingManager, jt as TradingRenderer, Qe as TrendLineTool, ut as TriangleTool, Jt as UndoRedoManager, Me as VROCIndicator, F as VWAPIndicator, et as VerticalLineTool, O as Viewport, Ae as VolumeProfileIndicator, Ct as VolumeProfileRangeTool, ce as VolumeRenderer, Vt as Watermark, Se as WilliamsRIndicator, He as ZoomHandler, S as barIndexToX, k as getVisibleData, Ln as layoutSquarifiedTreemap, Pn as layoutUniformGrid, C as priceToY, wt as registerBuiltInDrawingTools, Ne as registerBuiltInIndicators, gn as renderDepthChart, Nn as renderEquityCurve, Un as renderHeatmap, tn as renderSparkline, E as timestampToBarIndex, ue as toHeikinAshi, me as toKagi, pe as toLineBreak, he as toPointAndFigure, de as toRenko, w as xToBarIndex, T as yToPrice };
5895
+ export { je as ADXIndicator, Ae as ATRIndicator, Pe as AccumulationDistributionIndicator, Jt as AlertManager, Tt as AnchoredVWAPTool, en as Animator, te as AreaRenderer, P as AroonIndicator, xt as ArrowTool, Gt as BarCountdown, ne as BarRenderer, nn as BaseFinanceChart, ie as BaselineRenderer, zt as BinanceAdapter, be as BollingerBandsIndicator, M as CCIIndicator, L as CMFIndicator, A as CandlestickRenderer, v as CanvasLayer, Ht as ChartLegend, Xt as ChartStateManager, le as CompareRenderer, Ke as CrosshairHandler, Je as CrosshairTooltip, It as CurrentPriceLine, Vt as DEFAULT_LEGEND_CONFIG, x as DPRManager, Qt as DataExporter, vt as DateRangeTool, At as DepthOverlay, Ee as DonchianChannelIndicator, V as DrawingBase, $e as DrawingManager, et as DrawingRenderer, ye as EMAIndicator, $t as Easing, gt as ElliottWaveTool, ft as EllipseTool, G as Emitter, Ze as EventBus, at as ExtendedLineTool, ut as FibExtensionTool, ct as FibRetracementTool, rn as FinanceCrosshair, wt as GannBoxTool, Ct as GannFanTool, Le as GridRenderer, re as HollowCandleRenderer, nt as HorizontalLineTool, Se as IchimokuIndicator, j as IndicatorBase, _e as IndicatorEngine, Ue as InteractionManager, oe as KagiRenderer, Te as KeltnerChannelIndicator, qe as KeyboardHandler, y as LayerManager, ee as LineRenderer, Oe as MACDIndicator, N as MFIIndicator, yt as MeasureTool, Bt as MockAdapter, Me as OBVIndicator, Ot as OrderRenderer, We as PanHandler, Ce as ParabolicSARIndicator, ot as ParallelChannelTool, mt as PitchforkTool, se as PointAndFigureRenderer, kt as PositionRenderer, Re as PriceAxis, _t as PriceRangeTool, F as ROCIndicator, De as RSIIndicator, it as RayTool, K as ReconnectManager, dt as RectangleTool, st as RegressionChannelTool, D as RenderEngine, b as RenderLoop, ae as RenkoRenderer, Yt as ReplayManager, ve as SMAIndicator, Ut as Screenshot, Kt as SessionBreaks, R as StdDevIndicator, ke as StochasticIndicator, Lt as StreamManager, we as SupertrendIndicator, I as TSIIndicator, bt as TextAnnotationTool, Ft as TickAggregator, He as TimeAxis, Mt as TradingContextMenu, jt as TradingDragHandler, Nt as TradingManager, Pt as TradingRenderer, tt as TrendLineTool, pt as TriangleTool, Zt as UndoRedoManager, Fe as VROCIndicator, xe as VWAPIndicator, rt as VerticalLineTool, O as Viewport, z as VolumeProfileIndicator, Et as VolumeProfileRangeTool, ce as VolumeRenderer, Wt as Watermark, Ne as WilliamsRIndicator, Ge as ZoomHandler, S as barIndexToX, k as getVisibleData, Vn as layoutSquarifiedTreemap, Rn as layoutUniformGrid, C as priceToY, Dt as registerBuiltInDrawingTools, Ie as registerBuiltInIndicators, yn as renderDepthChart, Ln as renderEquityCurve, Dr as renderGauge, qn as renderHeatmap, an as renderSparkline, fr as renderWaterfall, E as timestampToBarIndex, ue as toHeikinAshi, me as toKagi, pe as toLineBreak, he as toPointAndFigure, de as toRenko, w as xToBarIndex, T as yToPrice };
5601
5896
 
5602
5897
  //# sourceMappingURL=index.js.map