@tradecanvas/chart 1.69.0 → 1.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/Chart.d.ts +15 -96
  2. package/dist/Chart.d.ts.map +1 -1
  3. package/dist/DataManager.d.ts +7 -0
  4. package/dist/DataManager.d.ts.map +1 -1
  5. package/dist/{LayoutSession-CoCMrrbh.js → LayoutSession-Bcy79w0l.js} +1030 -829
  6. package/dist/LayoutSession-Bcy79w0l.js.map +1 -0
  7. package/dist/LayoutSession-D7S6GZgJ.cjs +2 -0
  8. package/dist/LayoutSession-D7S6GZgJ.cjs.map +1 -0
  9. package/dist/SeriesStore.d.ts +2 -0
  10. package/dist/SeriesStore.d.ts.map +1 -1
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/model/DisplaySeries.d.ts +50 -0
  14. package/dist/model/DisplaySeries.d.ts.map +1 -0
  15. package/dist/model/DrawingPanes.d.ts +24 -0
  16. package/dist/model/DrawingPanes.d.ts.map +1 -0
  17. package/dist/model/IndicatorHistory.d.ts +52 -0
  18. package/dist/model/IndicatorHistory.d.ts.map +1 -0
  19. package/dist/model/IndicatorPanes.d.ts +76 -0
  20. package/dist/model/IndicatorPanes.d.ts.map +1 -0
  21. package/dist/model/IndicatorSetup.d.ts +34 -0
  22. package/dist/model/IndicatorSetup.d.ts.map +1 -0
  23. package/dist/model/PaneLayout.d.ts +55 -0
  24. package/dist/model/PaneLayout.d.ts.map +1 -0
  25. package/dist/model/PriceFit.d.ts +75 -0
  26. package/dist/model/PriceFit.d.ts.map +1 -0
  27. package/dist/model/SymbolRequests.d.ts +34 -0
  28. package/dist/model/SymbolRequests.d.ts.map +1 -0
  29. package/dist/widget/index.cjs +1 -1
  30. package/dist/widget/index.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/LayoutSession-BWC7O5R9.cjs +0 -2
  33. package/dist/LayoutSession-BWC7O5R9.cjs.map +0 -1
  34. package/dist/LayoutSession-CoCMrrbh.js.map +0 -1
  35. package/dist/PaneManager.d.ts +0 -19
  36. package/dist/PaneManager.d.ts.map +0 -1
@@ -1,12 +1,12 @@
1
- import { DARK_THEME as e, DEFAULT_PANEL_HEIGHT as t, LIGHT_THEME as n, LayerType as r, MIN_PANEL_HEIGHT as i, PHI as a, PRICE_AXIS_WIDTH as o, TIME_AXIS_HEIGHT as s, autoPricePrecision as c, barDateZone as l, barTimeUnit as u, barsAreDaily as d, chartStyleValue as f, computePriceLimits as p, computePriceRange as m, createMarketTheme as h, formatPrice as g, fractionTick as _, indicatorSource as v, isValidTimeZone as y, mergeBar as ee, niceNumber as te, normalizeBarTime as b, parseIndicatorSource as x, priceFormatterFor as ne, priceStepAt as re, readChartStyleOverrides as ie, readChartTypeOptions as ae, readIndicatorPlotStyles as oe, readPaneStyle as se, resolveChartTheme as ce, sessionMinute as S, setLocale as le, stepDecimals as ue, symbolTimeZone as C, tickBarCount as de, timeframeToMs as w, zonedDateFormatter as fe } from "@tradecanvas/commons";
2
- import { AlertDragHandler as pe, AlertManager as me, Animator as he, AreaRenderer as ge, AxisDragHandler as _e, BarCountdown as ve, BarRenderer as ye, BaselineRenderer as be, CandlestickRenderer as xe, ChartLegend as Se, ChartStateManager as T, CompareRenderer as Ce, CompareSymbolIndicator as we, CompareSymbolPaneIndicator as Te, CorrelationCoefficientIndicator as Ee, CorrelationLogIndicator as De, CrosshairHandler as Oe, CrosshairTooltip as ke, CurrentPriceLine as Ae, DEFAULT_SESSION_HOURS as je, DataExporter as E, DepthHeatmapRenderer as Me, DrawingManager as Ne, DrawingRenderer as Pe, EquivolumeRenderer as Fe, EventBus as Ie, GridRenderer as Le, HLCAreaRenderer as Re, HiLoRenderer as ze, HollowCandleRenderer as Be, IndicatorEngine as Ve, InteractionManager as He, KagiRenderer as Ue, KeyboardHandler as We, LineRenderer as Ge, LineWithMarkersRenderer as Ke, MarketProfileRenderer as qe, MeasureOverlay as Je, PRICE_AXIS_ADD_STRIP as Ye, PRICE_SCALE_MARGIN as D, PanHandler as Xe, PaneResizeHandler as Ze, PeriodLevelsRenderer as Qe, PinnedTooltip as $e, PivotMarkersRenderer as et, PointAndFigureRenderer as tt, PriceAxis as nt, PriceAxisAddButton as rt, PriceLines as it, RenderEngine as at, RenkoRenderer as ot, ReplayManager as st, ResamplingAdapter as ct, ReshapeMemo as lt, SYMBOL_INDICATOR_IDS as O, SYMBOL_ZONE_WAIT_MS as ut, Screenshot as k, SelectionBoxOverlay as dt, SessionBreaks as ft, SessionShading as pt, SignalMarkerManager as mt, SpreadIndicator as ht, StepLineRenderer as gt, StreamManager as _t, SymbolSeriesStore as vt, TimeAxis as yt, TradeZoneManager as bt, TradingManager as xt, TradingRenderer as St, UndoRedoManager as Ct, Viewport as wt, VolumeCandleRenderer as Tt, VolumeProfileRenderer as Et, VolumeRenderer as Dt, Watermark as Ot, ZoomHandler as kt, axisTimes as A, barTimeStepMs as At, findDominantSwing as jt, gpuContextsLeft as Mt, isPriceLevelAlert as Nt, isRegularSession as Pt, loadWebGL as Ft, mergeSessionHours as It, pointAndFigureColumns as Lt, rangePresetStart as Rt, readAlertOptions as zt, registerBuiltInDrawingTools as Bt, registerBuiltInIndicators as Vt, servesTimeframe as j, sourceParam as M, streamAdapterOf as Ht, timestampToBarIndex as N, toHeikinAshi as Ut, toKagi as Wt, toLineBreak as Gt, toRangeBars as Kt, toRenko as qt, whenGpuContextFree as Jt, withResampling as P, xToBarIndex as Yt, xToTime as F, yToPrice as Xt } from "@tradecanvas/core";
1
+ import { DARK_THEME as e, DEFAULT_PANEL_HEIGHT as t, LIGHT_THEME as n, LayerType as r, MIN_PANEL_HEIGHT as i, PHI as a, PRICE_AXIS_WIDTH as o, TIME_AXIS_HEIGHT as s, autoPricePrecision as c, barDateZone as l, barTimeUnit as u, barsAreDaily as d, chartStyleValue as f, computePriceLimits as p, computePriceRange as m, createMarketTheme as h, formatPrice as g, fractionTick as _, indicatorSource as v, isValidTimeZone as y, mergeBar as ee, niceNumber as te, normalizeBarTime as b, parseIndicatorSource as x, priceFormatterFor as ne, priceStepAt as re, readChartStyleOverrides as ie, readChartTypeOptions as S, readIndicatorPlotStyles as ae, readPaneStyle as oe, resolveChartTheme as se, sessionMinute as C, setLocale as ce, stepDecimals as le, symbolTimeZone as w, tickBarCount as ue, timeframeToMs as T, zonedDateFormatter as de } from "@tradecanvas/commons";
2
+ import { AlertDragHandler as fe, AlertManager as pe, Animator as me, AreaRenderer as he, AxisDragHandler as ge, BarCountdown as _e, BarRenderer as ve, BaselineRenderer as ye, CandlestickRenderer as be, ChartLegend as xe, ChartStateManager as E, CompareRenderer as Se, CompareSymbolIndicator as Ce, CompareSymbolPaneIndicator as we, CorrelationCoefficientIndicator as Te, CorrelationLogIndicator as Ee, CrosshairHandler as De, CrosshairTooltip as Oe, CurrentPriceLine as ke, DEFAULT_SESSION_HOURS as Ae, DataExporter as D, DepthHeatmapRenderer as je, DrawingManager as Me, DrawingRenderer as Ne, EquivolumeRenderer as Pe, EventBus as Fe, GridRenderer as Ie, HLCAreaRenderer as Le, HiLoRenderer as Re, HollowCandleRenderer as ze, IndicatorEngine as Be, InteractionManager as Ve, KagiRenderer as He, KeyboardHandler as Ue, LineRenderer as We, LineWithMarkersRenderer as Ge, MarketProfileRenderer as Ke, MeasureOverlay as qe, PRICE_AXIS_ADD_STRIP as Je, PRICE_SCALE_MARGIN as O, PanHandler as Ye, PaneResizeHandler as Xe, PeriodLevelsRenderer as Ze, PinnedTooltip as Qe, PivotMarkersRenderer as $e, PointAndFigureRenderer as et, PriceAxis as tt, PriceAxisAddButton as nt, PriceLines as rt, RenderEngine as it, RenkoRenderer as at, ReplayManager as ot, ResamplingAdapter as st, ReshapeMemo as ct, SYMBOL_INDICATOR_IDS as lt, SYMBOL_ZONE_WAIT_MS as ut, Screenshot as k, SelectionBoxOverlay as dt, SessionBreaks as ft, SessionShading as pt, SignalMarkerManager as mt, SpreadIndicator as ht, StepLineRenderer as gt, StreamManager as _t, SymbolSeriesStore as vt, TimeAxis as yt, TradeZoneManager as bt, TradingManager as xt, TradingRenderer as St, UndoRedoManager as Ct, Viewport as wt, VolumeCandleRenderer as Tt, VolumeProfileRenderer as Et, VolumeRenderer as Dt, Watermark as Ot, ZoomHandler as kt, axisTimes as At, barTimeStepMs as jt, findDominantSwing as Mt, gpuContextsLeft as Nt, isPriceLevelAlert as Pt, isRegularSession as Ft, loadWebGL as It, mergeSessionHours as Lt, pointAndFigureColumns as Rt, rangePresetStart as zt, readAlertOptions as Bt, registerBuiltInDrawingTools as Vt, registerBuiltInIndicators as Ht, servesTimeframe as A, sourceParam as j, streamAdapterOf as Ut, timestampToBarIndex as M, toHeikinAshi as Wt, toKagi as Gt, toLineBreak as Kt, toRangeBars as qt, toRenko as Jt, whenGpuContextFree as Yt, withResampling as N, xToBarIndex as Xt, xToTime as P, yToPrice as Zt } from "@tradecanvas/core";
3
3
  //#region src/regularHours.ts
4
- var Zt = 864e5, Qt = 10;
5
- function $t(e, t) {
6
- let n = C(e);
4
+ var Qt = 864e5, $t = 10;
5
+ function en(e, t) {
6
+ let n = w(e);
7
7
  if (!n || !y(n) || t.length < 2) return null;
8
8
  let r = (e?.sessions ?? []).flatMap((e) => {
9
- let t = S(e.start), n = S(e.end);
9
+ let t = C(e.start), n = C(e.end);
10
10
  return t === null || n === null ? [] : [{
11
11
  startMinute: t,
12
12
  endMinute: n
@@ -14,34 +14,34 @@ function $t(e, t) {
14
14
  });
15
15
  if (r.length === 0) return null;
16
16
  let i = u(t), a = Infinity;
17
- for (let e = Math.max(1, t.length - Qt); e < t.length; e++) {
17
+ for (let e = Math.max(1, t.length - $t); e < t.length; e++) {
18
18
  let n = (t[e].time - t[e - 1].time) * i;
19
19
  n > 0 && n < a && (a = n);
20
20
  }
21
- if (!(a < Zt)) return null;
21
+ if (!(a < Qt)) return null;
22
22
  let o = {
23
23
  timeZone: n,
24
24
  windows: r,
25
25
  startMinute: r[0].startMinute,
26
26
  endMinute: r[r.length - 1].endMinute
27
27
  };
28
- return (e) => Pt(e * i, o);
28
+ return (e) => Ft(e * i, o);
29
29
  }
30
30
  //#endregion
31
31
  //#region src/chartA11y.ts
32
- var en = {
32
+ var tn = {
33
33
  role: "chart",
34
34
  summary: "{what}. Last price {close}.",
35
35
  empty: "Chart, no data.",
36
36
  view: "Showing {count} bars, {from} to {to}. High {high}, low {low}.",
37
37
  bar: "{time}: open {open}, high {high}, low {low}, close {close}, volume {volume}.",
38
38
  keys: "Arrow keys scroll and zoom, Home and End go to the start and the end. Comma and period read the bars one at a time."
39
- }, I = (e, t) => e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e), tn = [
39
+ }, F = (e, t) => e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e), nn = [
40
40
  "role",
41
41
  "aria-roledescription",
42
42
  "aria-label",
43
43
  "aria-describedby"
44
- ], nn = 400, rn = 1e3, an = class {
44
+ ], rn = 400, an = 1e3, on = class {
45
45
  live;
46
46
  help;
47
47
  labels;
@@ -55,20 +55,20 @@ var en = {
55
55
  };
56
56
  constructor(e, t, n = {}) {
57
57
  this.container = e, this.source = t, this.labels = {
58
- ...en,
58
+ ...tn,
59
59
  ...n
60
60
  };
61
- for (let t of tn) this.before.set(t, e.getAttribute(t));
62
- e.setAttribute("role", "application"), this.help = on("div", "tc-sr-only"), this.help.id = `tc-chart-keys-${Math.random().toString(36).slice(2, 10)}`, e.setAttribute("aria-describedby", this.help.id), this.live = on("div", "tc-sr-only tc-sr-live"), this.live.setAttribute("aria-live", "polite"), this.live.setAttribute("aria-atomic", "true"), e.append(this.help, this.live), e.addEventListener("blur", this.onBlur), this.applyLabels();
61
+ for (let t of nn) this.before.set(t, e.getAttribute(t));
62
+ e.setAttribute("role", "application"), this.help = sn("div", "tc-sr-only"), this.help.id = `tc-chart-keys-${Math.random().toString(36).slice(2, 10)}`, e.setAttribute("aria-describedby", this.help.id), this.live = sn("div", "tc-sr-only tc-sr-live"), this.live.setAttribute("aria-live", "polite"), this.live.setAttribute("aria-atomic", "true"), e.append(this.help, this.live), e.addEventListener("blur", this.onBlur), this.applyLabels();
63
63
  }
64
64
  setLabels(e) {
65
65
  this.labels = {
66
- ...en,
66
+ ...tn,
67
67
  ...e
68
68
  }, this.applyLabels();
69
69
  }
70
70
  refresh(e = !1) {
71
- let t = rn - (Date.now() - this.summaryAt);
71
+ let t = an - (Date.now() - this.summaryAt);
72
72
  if (e || t <= 0 || this.container.getAttribute("aria-label") === this.labels.empty) {
73
73
  this.summaryTimer && clearTimeout(this.summaryTimer), this.summaryTimer = null, this.summaryAt = Date.now(), this.container.setAttribute("aria-label", this.summary());
74
74
  return;
@@ -80,7 +80,7 @@ var en = {
80
80
  viewMoved() {
81
81
  this.cursor = null, this.viewTimer && clearTimeout(this.viewTimer), this.viewTimer = setTimeout(() => {
82
82
  this.viewTimer = null, this.say(this.viewText());
83
- }, nn);
83
+ }, rn);
84
84
  }
85
85
  readBar(e) {
86
86
  let t = this.source.bars();
@@ -93,13 +93,13 @@ var en = {
93
93
  let i = t[this.cursor];
94
94
  this.source.showBar(i.time);
95
95
  let a = this.source.formatPrice;
96
- this.say(I(this.labels.bar, {
96
+ this.say(F(this.labels.bar, {
97
97
  time: this.source.formatTime(i.time),
98
98
  open: a(i.open),
99
99
  high: a(i.high),
100
100
  low: a(i.low),
101
101
  close: a(i.close),
102
- volume: sn(i.volume ?? 0)
102
+ volume: cn(i.volume ?? 0)
103
103
  }));
104
104
  }
105
105
  destroy() {
@@ -118,7 +118,7 @@ var en = {
118
118
  this.labels.typeName ? this.labels.typeName(t) : t,
119
119
  this.source.timeframe()
120
120
  ].filter(Boolean).join(", ");
121
- return I(this.labels.summary, {
121
+ return F(this.labels.summary, {
122
122
  what: n,
123
123
  close: this.source.formatPrice(e[e.length - 1].close)
124
124
  });
@@ -128,7 +128,7 @@ var en = {
128
128
  if (e.length === 0) return this.labels.empty;
129
129
  let t = this.source.visibleRange(), n = Math.max(0, Math.min(e.length - 1, Math.ceil(t.from))), r = Math.max(n, Math.min(e.length - 1, Math.floor(t.to))), i = -Infinity, a = Infinity;
130
130
  for (let t = n; t <= r; t++) i = Math.max(i, e[t].high), a = Math.min(a, e[t].low);
131
- return I(this.labels.view, {
131
+ return F(this.labels.view, {
132
132
  count: r - n + 1,
133
133
  from: this.source.formatTime(e[n].time),
134
134
  to: this.source.formatTime(e[r].time),
@@ -140,7 +140,7 @@ var en = {
140
140
  this.live.textContent = e;
141
141
  }
142
142
  };
143
- function on(e, t) {
143
+ function sn(e, t) {
144
144
  let n = document.createElement(e);
145
145
  return n.className = t, Object.assign(n.style, {
146
146
  position: "absolute",
@@ -154,17 +154,17 @@ function on(e, t) {
154
154
  border: "0"
155
155
  }), n;
156
156
  }
157
- function sn(e) {
157
+ function cn(e) {
158
158
  return Number.isInteger(e) ? String(e) : e.toFixed(2);
159
159
  }
160
160
  //#endregion
161
161
  //#region src/indicatorLabel.ts
162
- var cn = 3, ln = {
162
+ var ln = 3, un = {
163
163
  stochrsi: 4,
164
164
  ichimoku: 4
165
165
  };
166
- function un(e, t, n, r) {
167
- let i = Object.keys(n || t).map((e) => t[e]).filter((e) => typeof e == "number" && Number.isFinite(e)).slice(0, ln[e] ?? cn).map((e) => String(Number(e.toFixed(4)))), a = typeof t.symbol == "string" && t.symbol ? [t.symbol] : [];
166
+ function dn(e, t, n, r) {
167
+ let i = Object.keys(n || t).map((e) => t[e]).filter((e) => typeof e == "number" && Number.isFinite(e)).slice(0, un[e] ?? ln).map((e) => String(Number(e.toFixed(4)))), a = typeof t.symbol == "string" && t.symbol ? [t.symbol] : [];
168
168
  return [
169
169
  e === "spread" && t.mode === "ratio" ? "Ratio" : r ?? e.toUpperCase(),
170
170
  ...a,
@@ -173,52 +173,52 @@ function un(e, t, n, r) {
173
173
  }
174
174
  //#endregion
175
175
  //#region src/charts/ChartTypeStrategy.ts
176
- function dn(e) {
176
+ function fn(e) {
177
177
  switch (e) {
178
178
  case "candlestick":
179
179
  case "heikinAshi":
180
180
  case "lineBreak":
181
- case "rangeBars": return new xe();
182
- case "line": return new Ge();
183
- case "area": return new ge();
184
- case "bar": return new ye();
185
- case "hollowCandle": return new Be();
186
- case "baseline": return new be();
187
- case "renko": return new ot();
188
- case "kagi": return new Ue();
189
- case "pointAndFigure": return new tt();
181
+ case "rangeBars": return new be();
182
+ case "line": return new We();
183
+ case "area": return new he();
184
+ case "bar": return new ve();
185
+ case "hollowCandle": return new ze();
186
+ case "baseline": return new ye();
187
+ case "renko": return new at();
188
+ case "kagi": return new He();
189
+ case "pointAndFigure": return new et();
190
190
  case "volumeCandles": return new Tt();
191
- case "equivolume": return new Fe();
192
- case "hlcArea": return new Re();
191
+ case "equivolume": return new Pe();
192
+ case "hlcArea": return new Le();
193
193
  case "stepLine": return new gt();
194
- case "lineWithMarkers": return new Ke();
195
- case "hiLo": return new ze();
196
- default: return new xe();
194
+ case "lineWithMarkers": return new Ge();
195
+ case "hiLo": return new Re();
196
+ default: return new be();
197
197
  }
198
198
  }
199
- function fn(e, t, n = {}, r, i) {
199
+ function pn(e, t, n = {}, r, i) {
200
200
  if (t.length === 0) return t;
201
201
  switch (e) {
202
- case "heikinAshi": return Ut(t);
202
+ case "heikinAshi": return Wt(t);
203
203
  case "renko": {
204
204
  let e = n.renko?.boxSize;
205
- return typeof e == "number" ? qt(t, { brickSize: e }, i) : qt(t, {
205
+ return typeof e == "number" ? Jt(t, { brickSize: e }, i) : Jt(t, {
206
206
  brickSize: 0,
207
207
  useATR: !0,
208
208
  atrPeriod: n.renko?.atrPeriod ?? 14
209
209
  }, i);
210
210
  }
211
- case "lineBreak": return Gt(t, n.lineBreak?.lines ?? 3);
212
- case "kagi": return Wt(t, n.kagi?.reversal ?? 4, n.kagi?.reversalType ?? "percent", i);
213
- case "pointAndFigure": return mn(t, n, i).columns;
214
- case "rangeBars": return Kt(t, {
211
+ case "lineBreak": return Kt(t, n.lineBreak?.lines ?? 3);
212
+ case "kagi": return Gt(t, n.kagi?.reversal ?? 4, n.kagi?.reversalType ?? "percent", i);
213
+ case "pointAndFigure": return hn(t, n, i).columns;
214
+ case "rangeBars": return qt(t, {
215
215
  rangeSize: wn(t, n, r),
216
216
  includeForming: !0
217
217
  }, i);
218
218
  default: return t;
219
219
  }
220
220
  }
221
- function pn(e) {
221
+ function mn(e) {
222
222
  switch (e) {
223
223
  case "heikinAshi":
224
224
  case "renko":
@@ -229,36 +229,36 @@ function pn(e) {
229
229
  default: return !1;
230
230
  }
231
231
  }
232
- function L(e) {
233
- return e !== "heikinAshi" && pn(e);
232
+ function I(e) {
233
+ return e !== "heikinAshi" && mn(e);
234
234
  }
235
- function mn(e, t = {}, n) {
236
- return Lt(e, _n(e, t), t.pointAndFigure?.reversal ?? 3, n);
235
+ function hn(e, t = {}, n) {
236
+ return Rt(e, vn(e, t), t.pointAndFigure?.reversal ?? 3, n);
237
237
  }
238
- var hn = 50, gn = .01;
239
- function _n(e, t = {}) {
238
+ var gn = 50, _n = .01;
239
+ function vn(e, t = {}) {
240
240
  let n = t.pointAndFigure?.boxSize;
241
241
  if (typeof n == "number") return n;
242
- let r = vn(e, e.length > 1 ? e.length - 1 : e.length);
243
- return r > 0 ? Cn(te(r / hn, !0)) : Math.abs(e[e.length - 1]?.close ?? 0) * gn || 1;
242
+ let r = yn(e, e.length > 1 ? e.length - 1 : e.length);
243
+ return r > 0 ? L(te(r / gn, !0)) : Math.abs(e[e.length - 1]?.close ?? 0) * _n || 1;
244
244
  }
245
- function vn(e, t) {
245
+ function yn(e, t) {
246
246
  let n = -Infinity, r = Infinity;
247
247
  for (let i = 0; i < t; i++) e[i].high > n && (n = e[i].high), e[i].low < r && (r = e[i].low);
248
248
  let i = n - r;
249
249
  return Number.isFinite(i) ? i : 0;
250
250
  }
251
- var yn = 100, bn = 3, xn = .01, Sn = 15, Cn = (e) => Number(e.toPrecision(Sn));
251
+ var bn = 100, xn = 3, Sn = .01, Cn = 15, L = (e) => Number(e.toPrecision(Cn));
252
252
  function wn(e, t = {}, n) {
253
253
  let r = t.rangeBars?.range;
254
254
  if (typeof r == "number") return r;
255
- let i = e.length >= bn ? En(e) : 0, a = Math.abs(e[e.length - 1]?.close ?? 0);
256
- return kn(Cn(te(i > 0 ? i : a * xn || 1, !0)), n);
255
+ let i = e.length >= xn ? En(e) : 0, a = Math.abs(e[e.length - 1]?.close ?? 0);
256
+ return kn(L(te(i > 0 ? i : a * Sn || 1, !0)), n);
257
257
  }
258
258
  function Tn(e) {
259
259
  let t = e.length - 1;
260
260
  return {
261
- from: Math.max(0, t - yn),
261
+ from: Math.max(0, t - bn),
262
262
  end: t
263
263
  };
264
264
  }
@@ -281,16 +281,16 @@ function On(e, t) {
281
281
  return e === void 0 ? t : t === void 0 ? e : Math.max(e, t);
282
282
  }
283
283
  function kn(e, t) {
284
- return t === void 0 || !(t > 0) ? e : Cn(Math.max(1, Math.round(e / t)) * t);
284
+ return t === void 0 || !(t > 0) ? e : L(Math.max(1, Math.round(e / t)) * t);
285
285
  }
286
286
  function An(e, t) {
287
287
  let n = t?.(e);
288
- return n ? n.createRenderer() : dn(e);
288
+ return n ? n.createRenderer() : fn(e);
289
289
  }
290
290
  function jn(e, t, n, r, i, a) {
291
291
  if (t.length === 0) return t;
292
292
  let o = n?.(e);
293
- return o?.transform ? o.transform(t) : fn(e, t, r, i, a);
293
+ return o?.transform ? o.transform(t) : pn(e, t, r, i, a);
294
294
  }
295
295
  //#endregion
296
296
  //#region src/state/AutoSaveScheduler.ts
@@ -368,19 +368,23 @@ function Ln(e, t) {
368
368
  }
369
369
  var V = class {
370
370
  data = [];
371
+ changes = 0;
371
372
  withSeriesTime(e) {
372
373
  return Ln(this.data, e);
373
374
  }
374
375
  getData() {
375
376
  return this.data;
376
377
  }
378
+ version() {
379
+ return this.changes;
380
+ }
377
381
  setData(e) {
378
382
  let t = [];
379
383
  for (let n = 0; n < e.length; n++) {
380
384
  let r = e[n];
381
385
  R(r) && t.push(Nn(r) ? r : z(r));
382
386
  }
383
- this.data = t;
387
+ this.data = t, this.changes++;
384
388
  }
385
389
  prependBars(e) {
386
390
  let t = this.data.length > 0 ? this.data[0].time : Infinity, n = [];
@@ -393,15 +397,15 @@ var V = class {
393
397
  n.sort((e, t) => e.time - t.time);
394
398
  let r = 0;
395
399
  for (let e = 0; e < n.length; e++) r > 0 && n[r - 1].time === n[e].time || (n[r++] = n[e]);
396
- return n.length = r, this.data = n.concat(this.data), r;
400
+ return n.length = r, this.data = n.concat(this.data), this.changes++, r;
397
401
  }
398
402
  appendBar(e) {
399
- R(e) && this.data.push(z(this.withSeriesTime(e)));
403
+ R(e) && (this.data.push(z(this.withSeriesTime(e))), this.changes++);
400
404
  }
401
405
  updateLastBar(e) {
402
406
  if (!R(e)) return;
403
407
  let t = z(this.withSeriesTime(e));
404
- if (this.data.length === 0) {
408
+ if (this.changes++, this.data.length === 0) {
405
409
  this.data.push(t);
406
410
  return;
407
411
  }
@@ -415,19 +419,19 @@ var V = class {
415
419
  return B(this.data[n], r) ? {
416
420
  index: n,
417
421
  changed: !1
418
- } : (this.data[n] = r, {
422
+ } : (this.data[n] = r, this.changes++, {
419
423
  index: n,
420
424
  changed: !0
421
425
  });
422
426
  }
423
427
  updateLastBarFromTick(e) {
424
- this.data.length !== 0 && (!isFinite(e.price) || e.price < 0 || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0) || (this.data[this.data.length - 1] = ee(this.data[this.data.length - 1], this.withSeriesTime(e))));
428
+ this.data.length !== 0 && (!isFinite(e.price) || e.price < 0 || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0) || (this.data[this.data.length - 1] = ee(this.data[this.data.length - 1], this.withSeriesTime(e)), this.changes++));
425
429
  }
426
430
  getLength() {
427
431
  return this.data.length;
428
432
  }
429
433
  clear() {
430
- this.data = [];
434
+ this.data = [], this.changes++;
431
435
  }
432
436
  }, H = {
433
437
  to: "none",
@@ -466,6 +470,9 @@ var zn = class {
466
470
  revision() {
467
471
  return this.shownRevision;
468
472
  }
473
+ version() {
474
+ return this.shown.version();
475
+ }
469
476
  liveBars() {
470
477
  return this.aside?.getData() ?? this.whole ?? this.shown.getData();
471
478
  }
@@ -679,8 +686,486 @@ function Bn(e, t) {
679
686
  return r === 0 || r === e.length ? null : e.slice(0, r).concat(t);
680
687
  }
681
688
  //#endregion
689
+ //#region src/model/PriceFit.ts
690
+ var Vn = a ** -7, Hn = class {
691
+ auto;
692
+ preferred;
693
+ pending = !0;
694
+ arriving = !0;
695
+ constructor(e) {
696
+ this.auto = e, this.preferred = e;
697
+ }
698
+ isAuto() {
699
+ return this.auto;
700
+ }
701
+ shouldFit() {
702
+ return this.auto || this.pending;
703
+ }
704
+ setAuto(e, t) {
705
+ this.auto = e, this.preferred = e, !e && t && (this.arriving = !1);
706
+ }
707
+ hold() {
708
+ this.auto = !1, this.pending = !1;
709
+ }
710
+ resume() {
711
+ this.auto = !0;
712
+ }
713
+ newSeries(e) {
714
+ this.auto = this.preferred, this.pending = !0, this.arriving = e;
715
+ }
716
+ settle(e, t) {
717
+ if (!this.pending || t === 0 || e.chartRect.width <= 0) return;
718
+ let n = e.offset <= 0 && t * (e.barWidth + e.barSpacing) - e.offset <= e.chartRect.width;
719
+ this.arriving && n || (this.pending = !1);
720
+ }
721
+ fit(e, t, n, r) {
722
+ if (t.length === 0) return;
723
+ let i = Math.max(0, n.visibleRange.from), a = Math.min(n.visibleRange.to, t.length - 1), o = Wn(Wn(m(t, i, a, 0), r.overlayRange(i, a)), r.compareRange(t, n)), s = r.volumeRatio(t, i, a), c = s === null ? O : s + Vn;
724
+ e.setScaleMargins(e.isInvertScale() ? {
725
+ top: c,
726
+ bottom: O
727
+ } : {
728
+ top: O,
729
+ bottom: c
730
+ }), e.fitToPrices(o.min, o.max);
731
+ }
732
+ };
733
+ function Un(e, t, n) {
734
+ for (let r = t; r <= n; r++) if (e[r].volume > 0) return !0;
735
+ return !1;
736
+ }
737
+ function Wn(e, t) {
738
+ return e ? t ? {
739
+ min: Math.min(e.min, t.min),
740
+ max: Math.max(e.max, t.max)
741
+ } : e : t;
742
+ }
743
+ //#endregion
744
+ //#region src/model/DisplaySeries.ts
745
+ var Gn = class {
746
+ series = null;
747
+ madeAt = null;
748
+ epoch = 0;
749
+ memo = new ct();
750
+ constructor(e) {
751
+ this.sources = e;
752
+ }
753
+ get() {
754
+ let e = this.sources.bars();
755
+ if (e.length === 0) return e;
756
+ let t = this.sources.chartType(), n = this.sources.chartTypeOptions(), r = t === "rangeBars" ? Dn(e, (e) => this.sources.stepAt(e)) : void 0, i = this.sources.version(), a = this.madeAt;
757
+ return this.series && a && a.version === i && a.type === t && a.options === n && a.step === r && a.epoch === this.epoch ? this.series : (this.series = this.make(t, e, n, r), this.madeAt = {
758
+ version: i,
759
+ type: t,
760
+ options: n,
761
+ step: r,
762
+ epoch: this.epoch
763
+ }, this.series);
764
+ }
765
+ invalidate() {
766
+ this.epoch++;
767
+ }
768
+ reset() {
769
+ this.invalidate(), this.memo.clear();
770
+ }
771
+ make(e, t, n, r) {
772
+ let { lookup: i } = this.sources;
773
+ if (e !== "pointAndFigure" || i(e)) return jn(e, t, i, n, r, this.memo);
774
+ let { columns: a, boxSize: o } = hn(t, n, this.memo);
775
+ return this.sources.onBoxSize(o), a;
776
+ }
777
+ }, Kn = {
778
+ min: 0,
779
+ max: 100
780
+ }, qn = class {
781
+ layout = null;
782
+ infos = null;
783
+ styles = /* @__PURE__ */ new Map();
784
+ constructor(e, t, n) {
785
+ this.manager = e, this.sources = t, this.onLayout = n;
786
+ }
787
+ resolved() {
788
+ return this.layout || (this.layout = this.manager.resolve(), this.onLayout(Jn(this.layout))), this.layout;
789
+ }
790
+ invalidate() {
791
+ this.layout = null, this.infos = null;
792
+ }
793
+ invalidateScales() {
794
+ this.infos = null;
795
+ }
796
+ panels(e) {
797
+ if (this.infos) return this.infos;
798
+ let t = e(), { from: n, to: r } = t.visibleRange;
799
+ return this.infos = this.resolved().panels.map((e) => {
800
+ let i = e.config.id, a = e.config.logScale ? this.sources.getPaneValueRange(i, n, r, !0) : null, o = a ?? this.sources.getPaneValueRange(i, n, r) ?? { ...Kn }, s = this.styles.get(i);
801
+ return {
802
+ instanceId: i,
803
+ members: this.sources.getPaneMembers(i),
804
+ ...s ? { style: s } : {},
805
+ rect: e.rect,
806
+ viewport: {
807
+ ...t,
808
+ chartRect: {
809
+ x: e.rect.x,
810
+ y: e.rect.y + 20,
811
+ width: e.rect.width,
812
+ height: Math.max(0, e.rect.height - 20)
813
+ },
814
+ priceRange: o,
815
+ logScale: a !== null,
816
+ scaleMode: e.config.percentScale ? "percentage" : "regular",
817
+ scaleBaseline: e.config.percentScale ? this.baseline(i, n, r) : void 0,
818
+ formatPrice: void 0,
819
+ pricePrecision: void 0,
820
+ priceUnit: void 0,
821
+ invertScale: !!e.config.invertScale
822
+ }
823
+ };
824
+ }), this.infos;
825
+ }
826
+ timeAxisTop() {
827
+ let { mainChartRect: e, panels: t } = this.resolved(), n = t.filter((e) => e.config.position === "bottom").reduce((e, t) => e + t.rect.height, 0);
828
+ return e.y + e.height + n;
829
+ }
830
+ offChartType() {
831
+ let e = this.sources.getActiveIndicators(), t = new Set(e.filter((e) => e.offChartType).map((e) => e.instanceId)), n = /* @__PURE__ */ new Set();
832
+ for (let r of this.manager.getPanels()) {
833
+ let i = e.filter((e) => e.instanceId === r.id || e.pane === r.id);
834
+ i.length > 0 && i.every((e) => t.has(e.instanceId)) && n.add(r.id);
835
+ }
836
+ return n;
837
+ }
838
+ style(e) {
839
+ return this.styles.get(e);
840
+ }
841
+ setStyle(e, t) {
842
+ return JSON.stringify(t) === JSON.stringify(this.styles.get(e) ?? null) ? !1 : (t ? this.styles.set(e, t) : this.styles.delete(e), this.infos = null, !0);
843
+ }
844
+ passStyle(e, t) {
845
+ let n = this.styles.get(e);
846
+ this.styles.delete(e), t && n && this.styles.set(t, n), this.infos = null;
847
+ }
848
+ baseline(e, t, n) {
849
+ let r = this.sources.getOutput(e)?.series, i = this.sources.getIndicatorDescriptor(e);
850
+ if (!r || !i) return;
851
+ let a = i.plots?.[0]?.key;
852
+ for (let e = Math.max(0, t); e <= n && e < r.length; e++) {
853
+ let t = r[e];
854
+ if (!t) continue;
855
+ let n = a === void 0 ? Object.values(t).find((e) => typeof e == "number" && Number.isFinite(e)) : t[a];
856
+ if (typeof n == "number" && Number.isFinite(n) && n !== 0) return n;
857
+ }
858
+ }
859
+ };
860
+ function Jn(e) {
861
+ let t = e.mainChartRect, n = t.y, r = t.y + t.height;
862
+ for (let t of e.panels) t.config.position !== "top" && t.config.position !== "bottom" || (n = Math.min(n, t.rect.y), r = Math.max(r, t.rect.y + t.rect.height));
863
+ return {
864
+ top: n,
865
+ bottom: r
866
+ };
867
+ }
868
+ function Yn(e) {
869
+ return e.length > 0 ? { renames: e } : {};
870
+ }
871
+ var W = (e, t) => JSON.stringify(e) === JSON.stringify(t), Xn = class {
872
+ steps;
873
+ snapshot;
874
+ enabled;
875
+ now;
876
+ depth = 0;
877
+ edit = null;
878
+ renames = null;
879
+ constructor(e) {
880
+ this.steps = e.steps, this.snapshot = e.snapshot, this.enabled = e.enabled, this.now = e.now ?? (() => performance.now());
881
+ }
882
+ record(e, t) {
883
+ if (this.depth > 0 || !this.enabled()) return t();
884
+ let n = this.snapshot(), r = [], i = this.renames;
885
+ this.renames = r;
886
+ let a;
887
+ try {
888
+ a = this.quietly(t);
889
+ } finally {
890
+ this.renames = i;
891
+ }
892
+ let o = this.snapshot();
893
+ return W(n, o) || this.push(e, n, o, r), a;
894
+ }
895
+ push(e, t, n, r) {
896
+ let i = this.now(), a = this.steps.last(), o = a?.type === "indicators" ? a.indicators : void 0, s = e !== void 0 && o?.subject === e && i - (o.at ?? 0) < 800 && W(o.after, t), c = {
897
+ type: "indicators",
898
+ before: null,
899
+ after: null
900
+ };
901
+ s && o ? W(o.before, n) ? this.steps.dropLast() : this.steps.replaceLast({
902
+ ...c,
903
+ indicators: {
904
+ ...o,
905
+ after: n,
906
+ at: i,
907
+ ...Yn([...o.renames ?? [], ...r])
908
+ }
909
+ }) : this.steps.push({
910
+ ...c,
911
+ indicators: {
912
+ before: t,
913
+ after: n,
914
+ subject: e,
915
+ at: i,
916
+ ...Yn(r)
917
+ }
918
+ });
919
+ }
920
+ quietly(e) {
921
+ this.depth++;
922
+ try {
923
+ return e();
924
+ } finally {
925
+ this.depth--;
926
+ }
927
+ }
928
+ renamed(e, t) {
929
+ this.renames?.push([e, t]);
930
+ }
931
+ begin(e) {
932
+ this.end(), this.enabled() && (this.edit = {
933
+ subject: e,
934
+ before: this.snapshot()
935
+ }, this.depth++);
936
+ }
937
+ end() {
938
+ let e = this.edit;
939
+ if (!e) return;
940
+ this.edit = null, this.depth--;
941
+ let t = this.snapshot();
942
+ W(t, e.before) || this.steps.push({
943
+ type: "indicators",
944
+ before: null,
945
+ after: null,
946
+ indicators: {
947
+ before: e.before,
948
+ after: t,
949
+ subject: e.subject,
950
+ at: this.now()
951
+ }
952
+ });
953
+ }
954
+ }, Zn = class {
955
+ constructor(e, t, n) {
956
+ this.members = e, this.slots = t, this.handover = n;
957
+ }
958
+ ownsPane(e) {
959
+ return this.slots.getPanels().some((t) => t.id === e);
960
+ }
961
+ paneOf(e) {
962
+ return this.members.getIndicatorConfig(e)?.pane ?? e;
963
+ }
964
+ hostOf(e, t) {
965
+ if (e === t) return null;
966
+ if (this.ownsPane(e)) return e;
967
+ let n = this.members.getIndicatorConfig(e)?.pane;
968
+ return n && n !== t ? n : null;
969
+ }
970
+ paneFor(e, t, n, r) {
971
+ if (n) return this.hostOf(n, r);
972
+ if (e.placement !== "overlay") return null;
973
+ let i = j(e), a = i ? x(t[i]) : null;
974
+ return a ? this.hostOf(a.instanceId, r) : null;
975
+ }
976
+ sourceOf(e) {
977
+ let t = this.members.getIndicatorDescriptor(e), n = t ? j(t) : null;
978
+ return n ? this.members.getIndicatorConfig(e)?.params[n] : void 0;
979
+ }
980
+ followSource(e, t) {
981
+ let n = this.members.getIndicatorDescriptor(e), r = this.members.getIndicatorConfig(e), i = n ? j(n) : null;
982
+ if (n?.placement !== "overlay" || !r || !i || r.params[i] === t) return !1;
983
+ let a = x(r.params[i]), o = a ? this.hostOf(a.instanceId, e) : x(t) ? null : r.pane ?? null;
984
+ return (o ?? void 0) === r.pane ? !1 : (this.members.setPane(e, o), !0);
985
+ }
986
+ moveHost(e, t) {
987
+ let n = this.members.getIndicatorConfig(e), r = this.members.getIndicatorDescriptor(e);
988
+ if (!n || !r) return;
989
+ let i = j(r);
990
+ if (r.placement === "overlay" && i && x(n.params[i])) return;
991
+ if (t === "price") return r.placement === "overlay" && n.pane ? null : void 0;
992
+ if (t === "new") return r.placement === "panel" && !this.ownsPane(e) ? null : void 0;
993
+ let a = this.hostOf(t, e);
994
+ return a && a !== n.pane && a !== e ? a : void 0;
995
+ }
996
+ isPanel(e) {
997
+ return this.members.getIndicatorDescriptor(e)?.placement === "panel";
998
+ }
999
+ detach(e, t = () => void 0) {
1000
+ if (!this.members.getIndicatorConfig(e)) return null;
1001
+ let n = this.members.getPaneMembers(e), r = this.ownsPane(e) ? n.find((e) => this.isPanel(e)) ?? null : null;
1002
+ this.members.removeIndicator(e), this.handover.passStyle(e, r), r ? (this.members.setPane(r, null), this.handover.renamePane(e, r)) : this.slots.removePanel(e);
1003
+ for (let e of n) e !== r && this.members.setPane(e, r), t(e);
1004
+ return n;
1005
+ }
1006
+ move(e, t) {
1007
+ let n = this.moveHost(e, t), r = this.members.getIndicatorConfig(e);
1008
+ if (n === void 0 || !r) return null;
1009
+ let i = r.pane, a = new Set([e]);
1010
+ if (this.ownsPane(e)) for (let t of this.leavePane(e, n)) a.add(t);
1011
+ if (this.members.setPane(e, n), t === "new") {
1012
+ this.slots.addPanel(e, "bottom");
1013
+ for (let t of this.members.getDependents(e)) this.members.getIndicatorConfig(t)?.pane === i && (this.members.setPane(t, e), a.add(t));
1014
+ }
1015
+ return [...a];
1016
+ }
1017
+ leavePane(e, t) {
1018
+ let n = this.members.getPaneMembers(e), r = new Set(this.members.getDependents(e)), i = n.filter((e) => !r.has(e)), a = i.find((e) => this.isPanel(e)) ?? null;
1019
+ if (this.handover.passStyle(e, a), a) {
1020
+ this.members.setPane(a, null), this.handover.renamePane(e, a);
1021
+ for (let e of i) e !== a && this.members.setPane(e, a);
1022
+ } else {
1023
+ this.slots.removePanel(e);
1024
+ for (let e of i) this.members.setPane(e, null);
1025
+ }
1026
+ this.handover.invalidateScales();
1027
+ for (let i of n) r.has(i) && this.members.setPane(i, t ?? e);
1028
+ return n;
1029
+ }
1030
+ };
1031
+ //#endregion
1032
+ //#region src/model/IndicatorSetup.ts
1033
+ function Qn(e, t, n) {
1034
+ let r = t.getPanels(), i = t.getMaximizedPanel();
1035
+ return e.getActiveIndicators().map((t) => {
1036
+ let a = r.find((e) => e.id === t.instanceId), o = e.getIndicatorConfig(t.instanceId), s = a ? n(t.instanceId) : null;
1037
+ return {
1038
+ id: t.id,
1039
+ instanceId: t.instanceId,
1040
+ params: { ...t.params },
1041
+ position: a?.position,
1042
+ style: e.getIndicatorStyle(t.instanceId) ?? void 0,
1043
+ visible: t.visible,
1044
+ levels: o?.levels?.slice(),
1045
+ pane: t.pane,
1046
+ scale: o?.scale,
1047
+ ...o?.intervals ? { intervals: e.getIntervals(t.instanceId) ?? void 0 } : {},
1048
+ ...s ? { paneStyle: { ...s } } : {},
1049
+ ...a ? {
1050
+ paneSize: a.size,
1051
+ paneOrder: r.indexOf(a),
1052
+ ...a.collapsed ? { paneCollapsed: !0 } : {},
1053
+ ...i === t.instanceId ? { paneMaximized: !0 } : {},
1054
+ ...a.logScale ? { paneLog: !0 } : {},
1055
+ ...a.invertScale ? { paneInvert: !0 } : {},
1056
+ ...a.percentScale ? { panePercent: !0 } : {}
1057
+ } : {}
1058
+ };
1059
+ });
1060
+ }
1061
+ function $n(e, t) {
1062
+ for (let [n, r] of t) n.paneSize !== void 0 && e.setPanelSize(r, n.paneSize), (n.paneSize !== void 0 || n.paneCollapsed) && e.setPanelCollapsed(r, !!n.paneCollapsed), n.paneSize !== void 0 && e.setPanelScale(r, {
1063
+ log: !!n.paneLog,
1064
+ invert: !!n.paneInvert,
1065
+ percent: !!n.panePercent
1066
+ });
1067
+ let n = t.filter(([e]) => e.paneOrder !== void 0).sort(([e], [t]) => (e.paneOrder ?? 0) - (t.paneOrder ?? 0)).map(([, e]) => e);
1068
+ n.length > 1 && e.orderPanels(n);
1069
+ let r = t.find(([e]) => e.paneMaximized);
1070
+ e.setMaximizedPanel(r ? r[1] : null);
1071
+ }
1072
+ function er(e) {
1073
+ let t = new Map(e.map((e) => [e.instanceId, e])), n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
1074
+ if (r.has(e.instanceId) || i.has(e.instanceId)) return;
1075
+ i.add(e.instanceId);
1076
+ let o = [e.pane, ...Object.values(e.params).map((e) => x(e)?.instanceId)];
1077
+ for (let e of o) {
1078
+ let n = e ? t.get(e) : void 0;
1079
+ n && a(n);
1080
+ }
1081
+ i.delete(e.instanceId), r.add(e.instanceId), n.push(e);
1082
+ };
1083
+ for (let t of e) a(t);
1084
+ return n;
1085
+ }
1086
+ function tr(e, t) {
1087
+ return e.id === t.id && (e.pane ?? null) === (t.pane ?? null) && (e.scale ?? null) === (t.scale ?? null) && e.position === void 0 == (t.position === void 0);
1088
+ }
1089
+ function nr(e, t) {
1090
+ let n = new Map(t.map((e) => [e.instanceId, e])), r = /* @__PURE__ */ new Set();
1091
+ for (let t of e) {
1092
+ let e = n.get(t.instanceId);
1093
+ e && tr(t, e) && rr(t, e) && r.add(t.instanceId);
1094
+ }
1095
+ for (let t of e) t.pane && !r.has(t.pane) && r.delete(t.instanceId);
1096
+ return r;
1097
+ }
1098
+ function rr(e, t) {
1099
+ let n = Object.keys(e.params);
1100
+ return n.length === Object.keys(t.params).length && n.every((e) => e in t.params);
1101
+ }
1102
+ function ir(e, t) {
1103
+ let n = { ...e };
1104
+ for (let [e, r] of Object.entries(n)) {
1105
+ let i = x(r), a = i && t.get(i.instanceId);
1106
+ a && (n[e] = v(a, i.key));
1107
+ }
1108
+ return n;
1109
+ }
1110
+ //#endregion
1111
+ //#region src/model/SymbolRequests.ts
1112
+ function ar(e, t) {
1113
+ let n = t.symbol;
1114
+ return lt.has(e) && typeof n == "string" ? n.trim() : "";
1115
+ }
1116
+ var or = class {
1117
+ asked = /* @__PURE__ */ new Set();
1118
+ constructor(e, t) {
1119
+ this.readers = e, this.held = t;
1120
+ }
1121
+ required() {
1122
+ let e = /* @__PURE__ */ new Set();
1123
+ for (let t of this.readers.getActiveIndicators()) {
1124
+ let n = ar(t.id, t.params);
1125
+ n && e.add(n);
1126
+ }
1127
+ return [...e];
1128
+ }
1129
+ readersOf(e) {
1130
+ let t = e.trim();
1131
+ return this.readers.getActiveIndicators().filter((e) => lt.has(e.id) && String(e.params.symbol ?? "").trim() === t).map((e) => e.instanceId);
1132
+ }
1133
+ given(e) {
1134
+ this.asked.delete(e.trim());
1135
+ }
1136
+ forgetUnread() {
1137
+ let e = new Set(this.required());
1138
+ for (let t of this.asked) e.has(t) || this.asked.delete(t);
1139
+ }
1140
+ toAsk(e) {
1141
+ this.forgetUnread();
1142
+ let t = this.readers.getIndicatorConfig(e), n = t ? ar(t.id, t.params) : "";
1143
+ return !n || this.held.has(n) || this.asked.has(n) ? null : (this.asked.add(n), n);
1144
+ }
1145
+ }, sr = (e, t) => e.x >= t.x && e.x <= t.x + t.width && e.y >= t.y && e.y <= t.y + t.height;
1146
+ function cr(e, t, n, r) {
1147
+ if (!sr(e, t)) {
1148
+ for (let t of n) {
1149
+ let n = r(t.id);
1150
+ if (n && sr(e, n.chartRect)) return t.id;
1151
+ }
1152
+ return null;
1153
+ }
1154
+ }
1155
+ function lr(e, t, n, r) {
1156
+ if (!e || e.position !== "top" && e.position !== "bottom" || t) return null;
1157
+ let i = n();
1158
+ return !i || i.chartRect.height < 24 ? null : {
1159
+ ...i,
1160
+ data: r()
1161
+ };
1162
+ }
1163
+ function ur(e, t, n) {
1164
+ return !n && e.some((e) => e.id === t);
1165
+ }
1166
+ //#endregion
682
1167
  //#region src/HistoryPager.ts
683
- var Vn = 5e3, Hn = 6e4, Un = 500, Wn = class {
1168
+ var dr = 5e3, fr = 6e4, pr = 500, mr = class {
684
1169
  loader = null;
685
1170
  pageSize = 500;
686
1171
  loading = !1;
@@ -735,7 +1220,7 @@ var Vn = 5e3, Hn = 6e4, Un = 500, Wn = class {
735
1220
  return n === this.seq ? (this.loading = !1, e instanceof Error && e.name === "AbortError" ? (this.emit({
736
1221
  state: "loaded",
737
1222
  count: 0
738
- }), 0) : (this.failures++, this.retryAt = this.now() + Math.min(Hn, Vn * 2 ** (this.failures - 1)), this.emit({
1223
+ }), 0) : (this.failures++, this.retryAt = this.now() + Math.min(fr, dr * 2 ** (this.failures - 1)), this.emit({
739
1224
  state: "error",
740
1225
  count: 0,
741
1226
  error: e instanceof Error ? e.message : String(e)
@@ -768,10 +1253,10 @@ var Vn = 5e3, Hn = 6e4, Un = 500, Wn = class {
768
1253
  };
769
1254
  //#endregion
770
1255
  //#region src/ThemeManager.ts
771
- function Gn(e, t) {
1256
+ function hr(e, t) {
772
1257
  return e.family === t.family && e.sizeSmall === t.sizeSmall && e.sizeMedium === t.sizeMedium && e.sizeLarge === t.sizeLarge;
773
1258
  }
774
- var Kn = class t {
1259
+ var gr = class t {
775
1260
  base;
776
1261
  shape = null;
777
1262
  font = null;
@@ -790,13 +1275,13 @@ var Kn = class t {
790
1275
  return i;
791
1276
  }
792
1277
  getTheme() {
793
- return this.effective ??= ce(this.base, this.chartType, this.merged()), this.effective;
1278
+ return this.effective ??= se(this.base, this.chartType, this.merged()), this.effective;
794
1279
  }
795
1280
  getBaseTheme() {
796
1281
  return this.base;
797
1282
  }
798
1283
  setTheme(e) {
799
- let n = t.read(e), r = this.font !== null && Gn(n.font, this.base.font);
1284
+ let n = t.read(e), r = this.font !== null && hr(n.font, this.base.font);
800
1285
  this.base = n, r || (this.themeFont = n.font), this.shape && (this.base = {
801
1286
  ...this.base,
802
1287
  shape: {
@@ -878,7 +1363,7 @@ var Kn = class t {
878
1363
  };
879
1364
  //#endregion
880
1365
  //#region src/style/styleOptions.ts
881
- function qn(e, t) {
1366
+ function _r(e, t) {
882
1367
  return t ? {
883
1368
  ...t.visible === void 0 ? {} : { [`crosshair.${e}.visible`]: t.visible },
884
1369
  ...t.color === void 0 ? {} : { [`crosshair.${e}.color`]: t.color },
@@ -886,22 +1371,22 @@ function qn(e, t) {
886
1371
  ...t.width === void 0 ? {} : { [`crosshair.${e}.width`]: t.width }
887
1372
  } : {};
888
1373
  }
889
- function Jn(e) {
1374
+ function vr(e) {
890
1375
  let { grid: t, crosshair: n } = e, r = n?.vLine?.labelBackground ?? n?.hLine?.labelBackground;
891
1376
  return {
892
1377
  ...t?.hLineColor === void 0 ? {} : { "grid.horizontal.color": t.hLineColor },
893
1378
  ...t?.hLineStyle === void 0 ? {} : { "grid.horizontal.style": t.hLineStyle },
894
1379
  ...t?.vLineColor === void 0 ? {} : { "grid.vertical.color": t.vLineColor },
895
1380
  ...t?.vLineStyle === void 0 ? {} : { "grid.vertical.style": t.vLineStyle },
896
- ...qn("horizontal", n?.hLine),
897
- ...qn("vertical", n?.vLine),
1381
+ ..._r("horizontal", n?.hLine),
1382
+ ..._r("vertical", n?.vLine),
898
1383
  ...r === void 0 ? {} : { "crosshair.labelBackground": r },
899
1384
  ...e.overrides
900
1385
  };
901
1386
  }
902
1387
  //#endregion
903
1388
  //#region src/layout/LayoutManager.ts
904
- var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom", Zn = class {
1389
+ var yr = 200, br = 80, G = (e) => e.position === "top" || e.position === "bottom", xr = class {
905
1390
  panels = [];
906
1391
  containerWidth = 0;
907
1392
  containerHeight = 0;
@@ -918,8 +1403,8 @@ var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom
918
1403
  this.panels.push({
919
1404
  id: e,
920
1405
  position: n,
921
- size: r ?? (a ? Yn : t),
922
- minSize: a ? Xn : i,
1406
+ size: r ?? (a ? yr : t),
1407
+ minSize: a ? br : i,
923
1408
  content: {
924
1409
  type: "indicator",
925
1410
  indicatorInstanceId: e
@@ -938,14 +1423,14 @@ var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom
938
1423
  }
939
1424
  setPanelCollapsed(e, t) {
940
1425
  let n = this.panels.find((t) => t.id === e);
941
- return !n || !W(n) || this.maximized === null && !!n.collapsed === t ? !1 : (this.maximized = null, n.collapsed = t || void 0, !0);
1426
+ return !n || !G(n) || this.maximized === null && !!n.collapsed === t ? !1 : (this.maximized = null, n.collapsed = t || void 0, !0);
942
1427
  }
943
1428
  isPanelCollapsed(e) {
944
1429
  return !!this.panels.find((t) => t.id === e)?.collapsed;
945
1430
  }
946
1431
  isPanelShownCollapsed(e) {
947
1432
  let t = this.panels.find((t) => t.id === e);
948
- return !t || !W(t) ? !1 : this.maximized === null ? !!t.collapsed : this.maximized !== e;
1433
+ return !t || !G(t) ? !1 : this.maximized === null ? !!t.collapsed : this.maximized !== e;
949
1434
  }
950
1435
  setPanelScale(e, t) {
951
1436
  let n = this.panels.find((t) => t.id === e);
@@ -961,7 +1446,7 @@ var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom
961
1446
  }
962
1447
  setMaximizedPanel(e) {
963
1448
  let t = e === null ? null : this.panels.find((t) => t.id === e);
964
- return e !== null && (!t || !W(t)) || this.maximized === e ? !1 : (this.maximized = e, t && (t.collapsed = void 0), !0);
1449
+ return e !== null && (!t || !G(t)) || this.maximized === e ? !1 : (this.maximized = e, t && (t.collapsed = void 0), !0);
965
1450
  }
966
1451
  getMaximizedPanel() {
967
1452
  return this.maximized;
@@ -982,19 +1467,19 @@ var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom
982
1467
  this.panels = [...this.panels].sort((e, n) => t(e) - t(n));
983
1468
  }
984
1469
  shownSize(e, t) {
985
- return W(e) ? this.maximized ? e.id === this.maximized ? t : 20 : e.collapsed ? 20 : e.size : e.size;
1470
+ return G(e) ? this.maximized ? e.id === this.maximized ? t : 20 : e.collapsed ? 20 : e.size : e.size;
986
1471
  }
987
1472
  setPanelPosition(e, n) {
988
1473
  let r = this.panels.find((t) => t.id === e);
989
1474
  if (r) {
990
1475
  let a = r.position === "left" || r.position === "right", o = n === "left" || n === "right";
991
- r.position = n, a !== o && (r.size = o ? Yn : t, r.minSize = o ? Xn : i), o && (r.collapsed = void 0, this.maximized === e && (this.maximized = null));
1476
+ r.position = n, a !== o && (r.size = o ? yr : t, r.minSize = o ? br : i), o && (r.collapsed = void 0, this.maximized === e && (this.maximized = null));
992
1477
  }
993
1478
  }
994
1479
  setPanelSize(e, t) {
995
1480
  let n = this.panels.find((t) => t.id === e);
996
1481
  if (n) {
997
- let e = W(n) ? this.containerHeight - s - 48 : this.containerWidth / 2, r = e > n.minSize ? Math.min(t, e) : t;
1482
+ let e = G(n) ? this.containerHeight - s - 48 : this.containerWidth / 2, r = e > n.minSize ? Math.min(t, e) : t;
998
1483
  n.size = Math.max(n.minSize, r), n.collapsed = void 0, this.maximized = null;
999
1484
  }
1000
1485
  }
@@ -1108,8 +1593,8 @@ var Yn = 200, Xn = 80, W = (e) => e.position === "top" || e.position === "bottom
1108
1593
  getMainChartRect() {
1109
1594
  return this.resolve().mainChartRect;
1110
1595
  }
1111
- }, Qn = 14, $n = 14, er = 22, tr = 4;
1112
- function nr(e) {
1596
+ }, Sr = 14, Cr = 14, wr = 22, Tr = 4;
1597
+ function Er(e) {
1113
1598
  let { min: t, max: n, lastPrice: r, locale: i, fontFamily: a, fontSizeSmall: s, measure: l } = e, u = e.tagPrecision ?? c(t, n), d = u, f = r === null ? [t, n] : [
1114
1599
  t,
1115
1600
  n,
@@ -1118,16 +1603,16 @@ function nr(e) {
1118
1603
  for (let t of f) {
1119
1604
  if (!Number.isFinite(t)) continue;
1120
1605
  let n = e.scaleLabel ? e.scaleLabel(t) : e.format ? e.format(t) : g(t, u, i), r = e.format ? n : g(t, d, i);
1121
- p = Math.max(p, l(n, `500 ${s}px ${a}`) + Qn, l(r, `bold 11px ${a}`) + $n, l(r, `600 ${s}px ${a}`) + er);
1606
+ p = Math.max(p, l(n, `500 ${s}px ${a}`) + Sr, l(r, `bold 11px ${a}`) + Cr, l(r, `600 ${s}px ${a}`) + wr);
1122
1607
  }
1123
- return p <= o ? o : Math.ceil(p / tr) * tr;
1608
+ return p <= o ? o : Math.ceil(p / Tr) * Tr;
1124
1609
  }
1125
- function rr(e, t) {
1610
+ function Dr(e, t) {
1126
1611
  return t > e || t <= e - 12 ? t : e;
1127
1612
  }
1128
1613
  //#endregion
1129
1614
  //#region src/layout/labelWidths.ts
1130
- var ir = 512, ar = class {
1615
+ var Or = 512, kr = class {
1131
1616
  widths = /* @__PURE__ */ new Map();
1132
1617
  fonts;
1133
1618
  forget = () => this.widths.clear();
@@ -1138,12 +1623,12 @@ var ir = 512, ar = class {
1138
1623
  let r = `${t}\n${e}`, i = this.widths.get(r);
1139
1624
  if (i !== void 0) return i;
1140
1625
  let a = n();
1141
- return this.widths.size >= ir && this.widths.clear(), this.widths.set(r, a), a;
1626
+ return this.widths.size >= Or && this.widths.clear(), this.widths.set(r, a), a;
1142
1627
  }
1143
1628
  destroy() {
1144
1629
  this.fonts?.removeEventListener("loadingdone", this.forget), this.widths.clear();
1145
1630
  }
1146
- }, or = class {
1631
+ }, Ar = class {
1147
1632
  netY = 0;
1148
1633
  travelX = 0;
1149
1634
  engaged = !1;
@@ -1159,11 +1644,11 @@ var ir = 512, ar = class {
1159
1644
  }
1160
1645
  return this.engaged;
1161
1646
  }
1162
- }, sr = 1;
1163
- function cr(e, t) {
1647
+ }, jr = 1;
1648
+ function Mr(e, t) {
1164
1649
  return e.filter((e) => e.enabled !== !1 && (e.descriptor.layer ?? "overlay") === t);
1165
1650
  }
1166
- function G(e) {
1651
+ function K(e) {
1167
1652
  switch (e.kind) {
1168
1653
  case "indicator": return `indicator:${e.plugin.descriptor.id}`;
1169
1654
  case "drawing": return `drawing:${e.plugin.descriptor.type}`;
@@ -1173,25 +1658,25 @@ function G(e) {
1173
1658
  }
1174
1659
  //#endregion
1175
1660
  //#region src/plugins/registry.ts
1176
- var K = /* @__PURE__ */ new Map();
1177
- function lr(e) {
1178
- K.set(G(e), e);
1661
+ var q = /* @__PURE__ */ new Map();
1662
+ function Nr(e) {
1663
+ q.set(K(e), e);
1179
1664
  }
1180
- function ur(e) {
1181
- return K.delete(e);
1665
+ function Pr(e) {
1666
+ return q.delete(e);
1182
1667
  }
1183
- function dr() {
1184
- return [...K.values()];
1668
+ function Fr() {
1669
+ return [...q.values()];
1185
1670
  }
1186
- function fr() {
1187
- K.clear();
1671
+ function Ir() {
1672
+ q.clear();
1188
1673
  }
1189
1674
  //#endregion
1190
1675
  //#region src/plugins/PluginManager.ts
1191
- var pr = class {
1676
+ var Lr = class {
1192
1677
  plugins = /* @__PURE__ */ new Map();
1193
1678
  constructor(e, t = {}) {
1194
- if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of dr()) this.add(e);
1679
+ if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of Fr()) this.add(e);
1195
1680
  for (let e of t.plugins ?? []) this.add(e);
1196
1681
  }
1197
1682
  register(e) {
@@ -1219,17 +1704,17 @@ var pr = class {
1219
1704
  return e;
1220
1705
  }
1221
1706
  add(e) {
1222
- this.plugins.set(G(e), e), e.kind === "indicator" && this.indicatorEngine.register(e.plugin);
1707
+ this.plugins.set(K(e), e), e.kind === "indicator" && this.indicatorEngine.register(e.plugin);
1223
1708
  }
1224
- }, mr = {
1709
+ }, Rr = {
1225
1710
  orderPlace: (e, t) => e.placeOrder(t),
1226
1711
  orderModify: (e, t) => e.modifyOrder(t),
1227
1712
  orderCancel: (e, t) => e.cancelOrder(t),
1228
1713
  positionModify: (e, t) => e.modifyPosition(t),
1229
1714
  positionClose: (e, t) => e.closePosition(t),
1230
- positionReverse: (e, t, n) => hr(e, t, n)
1715
+ positionReverse: (e, t, n) => zr(e, t, n)
1231
1716
  };
1232
- async function hr(e, t, n) {
1717
+ async function zr(e, t, n) {
1233
1718
  let { reversing: r } = n;
1234
1719
  if (!r.has(t.positionId)) {
1235
1720
  r.add(t.positionId);
@@ -1258,7 +1743,7 @@ async function hr(e, t, n) {
1258
1743
  }
1259
1744
  }
1260
1745
  }
1261
- function gr(e, t) {
1746
+ function Br(e, t) {
1262
1747
  let n = [], r = null, i = {
1263
1748
  positions: () => r ?? t.getPositions?.() ?? [],
1264
1749
  reversing: /* @__PURE__ */ new Set()
@@ -1268,8 +1753,8 @@ function gr(e, t) {
1268
1753
  e.data && t.onFill?.(e.data);
1269
1754
  };
1270
1755
  e.on("orders", a), e.on("positions", o), e.on("error", s), e.on("fill", c), n.push(() => e.off("orders", a), () => e.off("positions", o), () => e.off("error", s), () => e.off("fill", c));
1271
- for (let r of Object.keys(mr)) {
1272
- let a = mr[r], o = t.onIntent(r, (n) => {
1756
+ for (let r of Object.keys(Rr)) {
1757
+ let a = Rr[r], o = t.onIntent(r, (n) => {
1273
1758
  Promise.resolve(a(e, n, i)).catch((e) => t.onError({
1274
1759
  message: `Execution command failed: ${r}`,
1275
1760
  cause: e
@@ -1283,7 +1768,7 @@ function gr(e, t) {
1283
1768
  }
1284
1769
  //#endregion
1285
1770
  //#region src/replay/ReplayStepLoader.ts
1286
- var _r = 1e3, vr = class {
1771
+ var Vr = 1e3, Hr = class {
1287
1772
  pieces = /* @__PURE__ */ new Map();
1288
1773
  asked = /* @__PURE__ */ new Set();
1289
1774
  inFlight = !1;
@@ -1316,7 +1801,7 @@ var _r = 1e3, vr = class {
1316
1801
  this.done = !0;
1317
1802
  }
1318
1803
  ask(e, t) {
1319
- let { ratio: n, barMs: r, step: i, report: a } = this.options, o = Math.max(1, Math.floor(_r / n)), s = Math.min(e.length, t + o), c = s < e.length ? e[s].time : e[e.length - 1].time + r, l = e.slice(t, s);
1804
+ let { ratio: n, barMs: r, step: i, report: a } = this.options, o = Math.max(1, Math.floor(Vr / n)), s = Math.min(e.length, t + o), c = s < e.length ? e[s].time : e[e.length - 1].time + r, l = e.slice(t, s);
1320
1805
  for (let e of l) this.asked.add(e.time);
1321
1806
  this.inFlight = !0, a({
1322
1807
  state: "loading",
@@ -1357,12 +1842,12 @@ var _r = 1e3, vr = class {
1357
1842
  ...n === void 0 ? {} : { error: n }
1358
1843
  });
1359
1844
  }
1360
- }, yr = 1 / 3, br = .25, xr = .5;
1361
- function Sr(e, t) {
1362
- let n = (e.high - e.low) * br;
1363
- return t.filter((t) => t.close > e.high + n || t.close < e.low - n).length <= t.length * xr;
1845
+ }, Ur = 1 / 3, Wr = .25, Gr = .5;
1846
+ function Kr(e, t) {
1847
+ let n = (e.high - e.low) * Wr;
1848
+ return t.filter((t) => t.close > e.high + n || t.close < e.low - n).length <= t.length * Gr;
1364
1849
  }
1365
- function Cr(e) {
1850
+ function qr(e) {
1366
1851
  return e.close >= e.open ? [
1367
1852
  e.open,
1368
1853
  e.low,
@@ -1375,22 +1860,22 @@ function Cr(e) {
1375
1860
  e.close
1376
1861
  ];
1377
1862
  }
1378
- function wr(e, t, n) {
1379
- let r = Cr(e), i = [
1863
+ function Jr(e, t, n) {
1864
+ let r = qr(e), i = [
1380
1865
  1,
1381
1866
  2,
1382
1867
  3
1383
1868
  ].map((e) => Math.abs(r[e] - r[e - 1])), a = i[0] + i[1] + i[2], o = [], s = 0;
1384
1869
  return r.forEach((r, c) => {
1385
- c > 0 && (s += a > 0 ? i[c - 1] / a : yr), !(c === 0 && t > 0) && o.push({
1870
+ c > 0 && (s += a > 0 ? i[c - 1] / a : Ur), !(c === 0 && t > 0) && o.push({
1386
1871
  price: r,
1387
1872
  time: e.time,
1388
1873
  at: (t + s) / n
1389
1874
  });
1390
1875
  }), o;
1391
1876
  }
1392
- function Tr(e, t = []) {
1393
- let n = t.length > 0 && Sr(e, t) ? t : [e], r = n.length, i = Er(n.flatMap((e, t) => wr(e, t, r)), e), a = n.reduce((e, t) => e + (t.volume ?? 0), 0), o = 0;
1877
+ function Yr(e, t = []) {
1878
+ let n = t.length > 0 && Kr(e, t) ? t : [e], r = n.length, i = Xr(n.flatMap((e, t) => Jr(e, t, r)), e), a = n.reduce((e, t) => e + (t.volume ?? 0), 0), o = 0;
1394
1879
  return {
1395
1880
  bar: e,
1396
1881
  points: i,
@@ -1400,7 +1885,7 @@ function Tr(e, t = []) {
1400
1885
  }))
1401
1886
  };
1402
1887
  }
1403
- function Er(e, t) {
1888
+ function Xr(e, t) {
1404
1889
  let n = e.length - 1, r = e.map((e, r) => ({
1405
1890
  ...e,
1406
1891
  price: r === 0 ? t.open : r === n ? t.close : Math.min(t.high, Math.max(t.low, e.price))
@@ -1415,7 +1900,7 @@ function Er(e, t) {
1415
1900
  };
1416
1901
  return i(t.high, (e, t) => e > t), i(t.low, (e, t) => e < t), r;
1417
1902
  }
1418
- function Dr(e, t) {
1903
+ function Zr(e, t) {
1419
1904
  let n = e.points;
1420
1905
  if (t <= n[0].at) return n[0].price;
1421
1906
  for (let e = 1; e < n.length; e++) if (t <= n[e].at) {
@@ -1424,8 +1909,8 @@ function Dr(e, t) {
1424
1909
  }
1425
1910
  return n[n.length - 1].price;
1426
1911
  }
1427
- var Or = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0;
1428
- function kr(e, t) {
1912
+ var Qr = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0;
1913
+ function $r(e, t) {
1429
1914
  let n = 0, r = 0;
1430
1915
  for (let i of e.volumeAt) {
1431
1916
  if (t >= i.at) {
@@ -1436,10 +1921,10 @@ function kr(e, t) {
1436
1921
  }
1437
1922
  return n;
1438
1923
  }
1439
- function Ar(e, t) {
1440
- let n = Or(t);
1924
+ function ei(e, t) {
1925
+ let n = Qr(t);
1441
1926
  if (n >= 1) return { ...e.bar };
1442
- let r = Dr(e, n), i = Math.max(e.points[0].price, r), a = Math.min(e.points[0].price, r);
1927
+ let r = Zr(e, n), i = Math.max(e.points[0].price, r), a = Math.min(e.points[0].price, r);
1443
1928
  for (let t of e.points) {
1444
1929
  if (t.at > n) break;
1445
1930
  i = Math.max(i, t.price), a = Math.min(a, t.price);
@@ -1450,29 +1935,29 @@ function Ar(e, t) {
1450
1935
  high: i,
1451
1936
  low: a,
1452
1937
  close: r,
1453
- volume: kr(e, n)
1938
+ volume: $r(e, n)
1454
1939
  };
1455
1940
  }
1456
- function jr(e, t) {
1457
- let n = Or(t), r = 0;
1941
+ function ti(e, t) {
1942
+ let n = Qr(t), r = 0;
1458
1943
  for (let t of e.points) {
1459
1944
  if (t.at > n) break;
1460
1945
  r = t.at;
1461
1946
  }
1462
1947
  return r;
1463
1948
  }
1464
- function q(e, t, n) {
1949
+ function J(e, t, n) {
1465
1950
  let r = [], i = e.bar.time;
1466
1951
  for (let a of e.points) {
1467
1952
  if (a.at > n) break;
1468
1953
  i = a.time, a.at > t && r.push([a.price, a.time]);
1469
1954
  }
1470
- let a = Dr(e, n);
1955
+ let a = Zr(e, n);
1471
1956
  return (r.length === 0 || r[r.length - 1][0] !== a) && r.push([a, i]), r;
1472
1957
  }
1473
1958
  //#endregion
1474
1959
  //#region src/replay/replayStep.ts
1475
- var Mr = [
1960
+ var ni = [
1476
1961
  "1m",
1477
1962
  "3m",
1478
1963
  "5m",
@@ -1483,48 +1968,41 @@ var Mr = [
1483
1968
  "4h",
1484
1969
  "1d"
1485
1970
  ];
1486
- function Nr(e, t) {
1487
- let n = w(e);
1488
- return n > 0 ? Mr.filter((e) => {
1489
- let r = w(e);
1971
+ function ri(e, t) {
1972
+ let n = T(e);
1973
+ return n > 0 ? ni.filter((e) => {
1974
+ let r = T(e);
1490
1975
  return r < n && n % r === 0 && t(e);
1491
1976
  }) : [];
1492
1977
  }
1493
- function Pr(e, t, n) {
1494
- let r = Nr(t, n);
1978
+ function ii(e, t, n) {
1979
+ let r = ri(t, n);
1495
1980
  if (e !== "auto") return r.includes(e) ? e : null;
1496
- let i = w(t);
1497
- return r.find((e) => i / w(e) <= 60) ?? null;
1981
+ let i = T(t);
1982
+ return r.find((e) => i / T(e) <= 60) ?? null;
1498
1983
  }
1499
1984
  //#endregion
1500
1985
  //#region src/Chart.ts
1501
- var Fr = {
1502
- min: 0,
1503
- max: 100
1504
- }, Ir = "exchange", Lr = Ir;
1505
- function Rr(e) {
1986
+ var ai = "exchange", oi = ai;
1987
+ function si(e) {
1506
1988
  if (typeof e == "string" && e !== "exchange" && !y(e)) throw RangeError(`Unknown time zone: ${e}`);
1507
1989
  if (typeof e == "number" && !Number.isFinite(e)) throw RangeError(`Invalid UTC offset: ${e}`);
1508
1990
  }
1509
- function zr(e, t) {
1510
- let { timeZone: n, timezone: r } = e, i = n !== void 0 && r !== void 0 && n !== r && n === t ? r : C(e);
1991
+ function ci(e, t) {
1992
+ let { timeZone: n, timezone: r } = e, i = n !== void 0 && r !== void 0 && n !== r && n === t ? r : w(e);
1511
1993
  return i === void 0 ? e : {
1512
1994
  ...e,
1513
1995
  timeZone: i,
1514
1996
  timezone: i
1515
1997
  };
1516
1998
  }
1517
- var Br = .08, Vr = a ** -7, Hr = 800, Ur = 24;
1518
- function Wr(e) {
1519
- return e.length > 0 ? { renames: e } : {};
1520
- }
1521
- var Gr = 20, Kr = 8, qr = 10, Jr = {
1999
+ var li = .08, ui = 20, di = 8, fi = 10, pi = {
1522
2000
  ArrowLeft: [-1, 0],
1523
2001
  ArrowRight: [1, 0],
1524
2002
  ArrowUp: [0, -1],
1525
2003
  ArrowDown: [0, 1]
1526
- }, Yr = new Set(["horizontalLine", "crossLine"]), Xr = new Set(["verticalLine", "crossLine"]), Zr = class {
1527
- static version = "1.69.0";
2004
+ }, mi = new Set(["horizontalLine", "crossLine"]), hi = new Set(["verticalLine", "crossLine"]), gi = class {
2005
+ static version = "1.70.0";
1528
2006
  engine;
1529
2007
  viewport;
1530
2008
  series = new zn((e) => this.sessionKeep(e), (e) => this.followLiveChange(e));
@@ -1541,20 +2019,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1541
2019
  executionAdapter = null;
1542
2020
  execTeardown = null;
1543
2021
  autoScrollOnNewBar = !0;
1544
- displayDataCache = null;
1545
2022
  indicatorsOnDrawn = null;
1546
- reshapeMemo = new lt();
1547
- displayDataStep;
2023
+ display;
1548
2024
  indicatorUpdateFrom = null;
1549
- resolvedLayoutCache = null;
1550
- panelInfoCache = null;
1551
- paneStyles = /* @__PURE__ */ new Map();
2025
+ panes;
2026
+ indicatorPanes;
2027
+ indicatorHistory;
1552
2028
  lastBackground = null;
1553
2029
  renderScheduled = !1;
1554
2030
  renderDeferred = !1;
1555
2031
  priceAxisWidth = o;
1556
2032
  measureCtx;
1557
- labelWidths = new ar();
2033
+ labelWidths = new kr();
1558
2034
  containerSizeCache = null;
1559
2035
  containerSizeCacheTime = 0;
1560
2036
  lastEmittedRange = null;
@@ -1565,11 +2041,9 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1565
2041
  watermark;
1566
2042
  barCountdown;
1567
2043
  unrestoredIndicators = [];
1568
- indicatorHistoryDepth = 0;
1569
- indicatorEdit = null;
1570
2044
  removedDrawingAlerts = /* @__PURE__ */ new Map();
1571
2045
  zoomAreaMode = !1;
1572
- priceAxisAddButton = new rt();
2046
+ priceAxisAddButton = new nt();
1573
2047
  displayTz = null;
1574
2048
  timeZoneSetting = null;
1575
2049
  symbolInfo = null;
@@ -1580,7 +2054,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1580
2054
  studyZoneReleaseQueued = !1;
1581
2055
  sessionBreaks;
1582
2056
  sessionShading;
1583
- hostSessionHours = { ...je };
2057
+ hostSessionHours = { ...Ae };
1584
2058
  compareRenderer;
1585
2059
  countdownInterval = null;
1586
2060
  pausedFor = {
@@ -1626,14 +2100,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1626
2100
  disposed = !1;
1627
2101
  chartTypeOptions = {};
1628
2102
  mainSeriesVisible = !0;
1629
- priceLines = new it();
2103
+ priceLines = new rt();
1630
2104
  symbolSeries = new vt();
1631
2105
  extendedHours = !0;
1632
2106
  replayRestarting = !1;
1633
- requestedSymbols = /* @__PURE__ */ new Set();
2107
+ symbolRequests;
1634
2108
  gridRenderer;
1635
2109
  priceAxis;
1636
- leftPriceAxis = new nt();
2110
+ leftPriceAxis = new tt();
1637
2111
  leftScaleRequested = !1;
1638
2112
  leftAxisWidth = o;
1639
2113
  leftViewport = null;
@@ -1648,9 +2122,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1648
2122
  priceFormatter = null;
1649
2123
  priceUnit = null;
1650
2124
  paneTitles = !0;
1651
- defaultAutoScale;
1652
- priceFitPending = !0;
1653
- seriesArriving = !0;
2125
+ priceFit;
1654
2126
  keyboardHandler = null;
1655
2127
  a11y = null;
1656
2128
  onWindowKeyDown = null;
@@ -1666,10 +2138,20 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1666
2138
  snapshotKey = null;
1667
2139
  historyCheckQueued = !1;
1668
2140
  constructor(e, t) {
1669
- t.timeZone != null && Rr(t.timeZone), this.container = e, this.options = {
2141
+ t.timeZone != null && si(t.timeZone), this.container = e, this.options = {
1670
2142
  ...t,
1671
2143
  chartType: t.chartType ?? "candlestick"
1672
- }, this.numberLocale = t.numberLocale ?? "en-US", this.defaultAutoScale = t.autoScale !== !1;
2144
+ }, this.numberLocale = t.numberLocale ?? "en-US", this.priceFit = new Hn(t.autoScale !== !1), this.display = new Gn({
2145
+ bars: () => this.series.bars(),
2146
+ version: () => this.series.version(),
2147
+ chartType: () => this.options.chartType,
2148
+ chartTypeOptions: () => this.chartTypeOptions,
2149
+ lookup: (e) => this.pluginManager.getChartType(e),
2150
+ stepAt: (e) => this.stepAt(e),
2151
+ onBoxSize: (e) => {
2152
+ this.chartRenderer instanceof et && this.chartRenderer.setBoxSize(e);
2153
+ }
2154
+ });
1673
2155
  let n = t.features ?? {};
1674
2156
  this.features = {
1675
2157
  drawings: n.drawings ?? !0,
@@ -1705,15 +2187,23 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1705
2187
  logScale: n.logScale ?? !0,
1706
2188
  timeframes: n.timeframes ?? [],
1707
2189
  defaultTimeframeFavorites: n.defaultTimeframeFavorites ?? []
1708
- }, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", e.style.userSelect = "none", e.style.webkitUserSelect = "none", this.history = new Wn({
2190
+ }, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", e.style.userSelect = "none", e.style.webkitUserSelect = "none", this.history = new mr({
1709
2191
  oldestTime: () => (this.replaySession ? this.series.liveBars() : this.series.bars())[0]?.time ?? null,
1710
2192
  prepend: (e) => this.prependBars(e),
1711
2193
  emit: (e) => this.eventBus.emit("historyLoad", e)
1712
- }), this.themeManager = new Kn(t.theme), this.themeManager.setChartType(this.options.chartType ?? "candlestick"), this.applyStyle(Jn(t), "host", !1), this.layoutManager = new Zn(), this.indicatorEngine = new Ve(), this.pluginManager = new pr(this.indicatorEngine, { plugins: t.plugins }), this.eventBus = new Ie(), Vt(this.indicatorEngine), this.indicatorEngine.register(new we(this.symbolSeries)), this.indicatorEngine.register(new Te(this.symbolSeries)), this.indicatorEngine.register(new ht(this.symbolSeries)), this.indicatorEngine.register(new Ee(this.symbolSeries)), this.indicatorEngine.register(new De(this.symbolSeries)), this.drawingManager = new Ne(), Bt(this.drawingManager), this.drawingRenderer = new Pe(this.drawingManager), this.drawingRenderer.setKeepOut(() => this.legendKeepOut()), this.drawingRenderer.setTimeFormat((e) => this.crosshairHandler.formatTime(e, this.getDisplayData())), this.drawingManager.setRequestRender(() => {
2194
+ }), this.themeManager = new gr(t.theme), this.themeManager.setChartType(this.options.chartType ?? "candlestick"), this.applyStyle(vr(t), "host", !1), this.layoutManager = new xr(), this.indicatorEngine = new Be(), this.panes = new qn(this.layoutManager, this.indicatorEngine, (e) => this.crosshairHandler.setReportBounds(e)), this.indicatorPanes = new Zn(this.indicatorEngine, this.layoutManager, {
2195
+ passStyle: (e, t) => this.panes.passStyle(e, t),
2196
+ renamePane: (e, t) => this.renamePane(e, t),
2197
+ invalidateScales: () => this.panes.invalidateScales()
2198
+ }), this.symbolRequests = new or(this.indicatorEngine, this.symbolSeries), this.pluginManager = new Lr(this.indicatorEngine, { plugins: t.plugins }), this.eventBus = new Fe(), Ht(this.indicatorEngine), this.indicatorEngine.register(new Ce(this.symbolSeries)), this.indicatorEngine.register(new we(this.symbolSeries)), this.indicatorEngine.register(new ht(this.symbolSeries)), this.indicatorEngine.register(new Te(this.symbolSeries)), this.indicatorEngine.register(new Ee(this.symbolSeries)), this.drawingManager = new Me(), Vt(this.drawingManager), this.drawingRenderer = new Ne(this.drawingManager), this.drawingRenderer.setKeepOut(() => this.legendKeepOut()), this.drawingRenderer.setTimeFormat((e) => this.crosshairHandler.formatTime(e, this.getDisplayData())), this.drawingManager.setRequestRender(() => {
1713
2199
  this.syncRenderContext(), this.engine.requestRender(r.Overlay), this.scheduleAutoSave();
1714
2200
  }), this.drawingManager.setEventCallback((e, t) => {
1715
2201
  this.followDrawingAlerts(e, t?.id), this.eventBus.emit(e, t), (e === "drawingCreate" || e === "drawingUpdate" || e === "drawingRemove") && this.announceStateChange();
1716
- }), this.drawingManager.setToolFilter((e) => this.features.drawings && (this.features.drawingTools.length === 0 || this.features.drawingTools.includes(e))), this.undoRedoManager = new Ct();
2202
+ }), this.drawingManager.setToolFilter((e) => this.features.drawings && (this.features.drawingTools.length === 0 || this.features.drawingTools.includes(e))), this.undoRedoManager = new Ct(), this.indicatorHistory = new Xn({
2203
+ steps: this.undoRedoManager,
2204
+ snapshot: () => this.getIndicatorSetup(),
2205
+ enabled: () => this.features.drawingUndoRedo
2206
+ });
1717
2207
  let i = "";
1718
2208
  this.undoRedoManager.setOnChange(() => {
1719
2209
  let { canUndo: e, canRedo: t } = this.undoRedoManager.getState(), n = `${e}|${t}`;
@@ -1731,7 +2221,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1731
2221
  contextMenu: { enabled: this.features.tradingContextMenu }
1732
2222
  }), this.tradingRenderer = new St(this.tradingManager), this.tradingManager.setContainer(e), this.tradingManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradingManager.setEventCallback((e, t) => {
1733
2223
  this.eventBus.emit(e, t);
1734
- }), this.engine = new at(e, t.maxPixelRatio);
2224
+ }), this.engine = new it(e, t.maxPixelRatio);
1735
2225
  let a = this.engine.dprManager.getContainerSize();
1736
2226
  if (this.viewport = new wt(a.width, a.height, t.minBarSpacing ?? 2, t.maxBarSpacing ?? 30, t.rightMargin ?? 5), t.barLayout && this.viewport.setBarLayout(t.barLayout), this.viewport.setPanLimits({
1737
2227
  freePan: t.freePan ?? !0,
@@ -1740,9 +2230,9 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1740
2230
  if (e.width <= 0 || e.height <= 0) return;
1741
2231
  let t = this.viewport.isAtEnd();
1742
2232
  this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(t), this.eventBus.emit("resize", e);
1743
- }, this.chartRenderer = this.createChartRenderer(this.options.chartType), this.gridRenderer = new Le(), t.grid?.visible === !1 && this.gridRenderer.setVisible(!1), this.priceAxis = new nt(), this.priceAxis.setLocale(this.numberLocale), this.leftPriceAxis.setLocale(this.numberLocale), this.viewport.setNumberLocale(this.numberLocale), this.timeAxis = new yt(), this.timeAxis.setLocale(this.numberLocale), this.crosshairHandler = new Oe(), this.crosshairHandler.setLocale(this.numberLocale), this.applyTimeSpacing(), t.crosshair?.mode && this.crosshairHandler.setMode(t.crosshair.mode), this.crosshairHandler.setDataSource(() => this.crosshairSeries()), this.crosshairHandler.setCallback((e, t) => {
2233
+ }, this.chartRenderer = this.createChartRenderer(this.options.chartType), this.gridRenderer = new Ie(), t.grid?.visible === !1 && this.gridRenderer.setVisible(!1), this.priceAxis = new tt(), this.priceAxis.setLocale(this.numberLocale), this.leftPriceAxis.setLocale(this.numberLocale), this.viewport.setNumberLocale(this.numberLocale), this.timeAxis = new yt(), this.timeAxis.setLocale(this.numberLocale), this.crosshairHandler = new De(), this.crosshairHandler.setLocale(this.numberLocale), this.applyTimeSpacing(), t.crosshair?.mode && this.crosshairHandler.setMode(t.crosshair.mode), this.crosshairHandler.setDataSource(() => this.crosshairSeries()), this.crosshairHandler.setCallback((e, t) => {
1744
2234
  if (e !== null && t) {
1745
- let n = this.crosshairSeries(), i = e >= 0 && e < n.length ? n[e] : void 0, a = e > 0 ? n[e - 1]?.close : void 0, o = A(n), s = i ? o[e]?.time ?? i.time : void 0;
2235
+ let n = this.crosshairSeries(), i = e >= 0 && e < n.length ? n[e] : void 0, a = e > 0 ? n[e - 1]?.close : void 0, o = At(n), s = i ? o[e]?.time ?? i.time : void 0;
1746
2236
  this.chartLegend.setHoverBar(i ?? null, e > 0 ? n[e - 1] ?? null : null), this.features.legend && this.engine.requestRender(r.Hover);
1747
2237
  let c = this.viewport.getState(), l = t.y >= c.chartRect.y && t.y <= c.chartRect.y + c.chartRect.height;
1748
2238
  if (i && l && this.features.crosshairTooltip) {
@@ -1754,7 +2244,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1754
2244
  prevClose: a,
1755
2245
  priceRange: c.priceRange,
1756
2246
  plot: c.chartRect,
1757
- barStepMs: At(o),
2247
+ barStepMs: jt(o),
1758
2248
  timeUnit: u(o)
1759
2249
  });
1760
2250
  } else this.crosshairTooltip.hide();
@@ -1770,14 +2260,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1770
2260
  let e = this.crosshairHandler.getSyncedSlot();
1771
2261
  e !== null && this.showSyncedBar(e);
1772
2262
  }
1773
- }), this.chartLegend = new Se(), this.chartLegend.setChartType(this.options.chartType), this.chartLegend.setLocale(this.numberLocale), this.chartLegend.setResizeListener(() => {
2263
+ }), this.chartLegend = new xe(), this.chartLegend.setChartType(this.options.chartType), this.chartLegend.setLocale(this.numberLocale), this.chartLegend.setResizeListener(() => {
1774
2264
  this.eventBus.emit("legendResize", { bottom: this.getLegendBottom() }), this.engine.requestRender();
1775
- }), this.watermark = new Ot(), t.watermark && this.watermark.setConfig(t.watermark), this.volumeRenderer = new Dt(), this.volumeProfile = new Et(), this.marketProfile = new qe(), this.depthHeatmap = new Me(), this.periodLevels = new Qe(), this.pivotMarkers = new et(), this.barCountdown = new ve(), this.barCountdown.setVisible(this.features.barCountdown), this.sessionBreaks = new ft(), this.sessionShading = new pt(), this.compareRenderer = new Ce(), t.sessionBreaks ? this.sessionBreaks.setConfig({
2265
+ }), this.watermark = new Ot(), t.watermark && this.watermark.setConfig(t.watermark), this.volumeRenderer = new Dt(), this.volumeProfile = new Et(), this.marketProfile = new Ke(), this.depthHeatmap = new je(), this.periodLevels = new Ze(), this.pivotMarkers = new $e(), this.barCountdown = new _e(), this.barCountdown.setVisible(this.features.barCountdown), this.sessionBreaks = new ft(), this.sessionShading = new pt(), this.compareRenderer = new Se(), t.sessionBreaks ? this.sessionBreaks.setConfig({
1776
2266
  visible: t.sessionBreaks.visible ?? !0,
1777
2267
  color: t.sessionBreaks.color,
1778
2268
  lineStyle: t.sessionBreaks.lineStyle,
1779
2269
  lineWidth: t.sessionBreaks.lineWidth
1780
- }) : t.features?.sessionBreaks !== !1 && this.sessionBreaks.setVisible(!0), t.logScale && this.features.logScale && this.viewport.setLogScale(!0), this.animator = new he(), this.crosshairTooltip = new ke(), this.crosshairTooltip.create(e), this.crosshairTooltip.setLocale(this.numberLocale), this.pinnedTooltip = new $e(), this.pinnedTooltip.create(e), this.pinnedTooltip.setLocale(this.numberLocale), t.priceFormat && this.applyPriceFormat(t.priceFormat), t.chartTypeOptions && (this.chartTypeOptions = ae(t.chartTypeOptions)), t.highLowLines && this.priceLines.setHighLow(!0), t.shapes && this.themeManager.setShape(ri(t.shapes)), t.font && this.themeManager.setFont(ni(t.font)), this.priceLines.setPriceText((e) => this.formatPrice(e)), t.extendedHours === !1 && (this.extendedHours = !1), t.timeFormatter && this.applyTimeFormatter(t.timeFormatter), this.keyboardHandler = new We({
2270
+ }) : t.features?.sessionBreaks !== !1 && this.sessionBreaks.setVisible(!0), t.logScale && this.features.logScale && this.viewport.setLogScale(!0), this.animator = new me(), this.crosshairTooltip = new Oe(), this.crosshairTooltip.create(e), this.crosshairTooltip.setLocale(this.numberLocale), this.pinnedTooltip = new Qe(), this.pinnedTooltip.create(e), this.pinnedTooltip.setLocale(this.numberLocale), t.priceFormat && this.applyPriceFormat(t.priceFormat), t.chartTypeOptions && (this.chartTypeOptions = S(t.chartTypeOptions)), t.highLowLines && this.priceLines.setHighLow(!0), t.shapes && this.themeManager.setShape(bi(t.shapes)), t.font && this.themeManager.setFont(yi(t.font)), this.priceLines.setPriceText((e) => this.formatPrice(e)), t.extendedHours === !1 && (this.extendedHours = !1), t.timeFormatter && this.applyTimeFormatter(t.timeFormatter), this.keyboardHandler = new Ue({
1781
2271
  scrollBars: (e) => {
1782
2272
  let t = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
1783
2273
  this.viewport.scrollBy(e * t), this.updateViewportAndRender();
@@ -1794,7 +2284,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1794
2284
  },
1795
2285
  fitContent: () => this.fitContent()
1796
2286
  }), this.keyboardHandler.setEnabled(this.features.keyboard), t.a11y !== !1) {
1797
- this.a11y = new an(e, {
2287
+ this.a11y = new on(e, {
1798
2288
  symbol: () => this.currentSymbol || this.symbolInfo?.symbol || "",
1799
2289
  timeframe: () => this.streamTimeframe ?? "",
1800
2290
  chartType: () => this.options.chartType ?? "candlestick",
@@ -1825,8 +2315,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1825
2315
  }
1826
2316
  this.keyboardHandler.handleKey(e) && (e.preventDefault(), this.a11y?.viewMoved());
1827
2317
  }
1828
- }, window.addEventListener("keydown", this.onWindowKeyDown), this.currentPriceLine = new Ae(), this.currentPriceLine.setLocale(this.numberLocale), this.priceAxis.setReservedPriceProvider(() => this.currentPriceLine.isVisible() ? this.currentPriceLine.getPrice() : null), this.alertManager = new me(), this.alertManager.setDrawingLevels((e) => this.drawingLevelsNow(e)), this.alertManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.compareRenderer.setReservedLevels(() => this.alertManager.getAlerts().filter(Nt).map((e) => e.price)), this.alertManager.on("triggered", (e) => {
1829
- this.eventBus.emit("alertTriggered", J(e)), this.eventBus.emit("dataUpdate", {
2318
+ }, window.addEventListener("keydown", this.onWindowKeyDown), this.currentPriceLine = new ke(), this.currentPriceLine.setLocale(this.numberLocale), this.priceAxis.setReservedPriceProvider(() => this.currentPriceLine.isVisible() ? this.currentPriceLine.getPrice() : null), this.alertManager = new pe(), this.alertManager.setDrawingLevels((e) => this.drawingLevelsNow(e)), this.alertManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.compareRenderer.setReservedLevels(() => this.alertManager.getAlerts().filter(Pt).map((e) => e.price)), this.alertManager.on("triggered", (e) => {
2319
+ this.eventBus.emit("alertTriggered", Y(e)), this.eventBus.emit("dataUpdate", {
1830
2320
  kind: "alert",
1831
2321
  alert: "triggered",
1832
2322
  alertId: e.id,
@@ -1834,13 +2324,13 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1834
2324
  message: e.message
1835
2325
  });
1836
2326
  }), this.alertManager.on("added", (e) => {
1837
- this.eventBus.emit("alertAdd", J(e));
2327
+ this.eventBus.emit("alertAdd", Y(e));
1838
2328
  }), this.alertManager.on("removed", (e) => {
1839
2329
  this.eventBus.emit("alertRemove", { id: e });
1840
2330
  }), this.alertManager.on("expired", (e) => {
1841
- this.eventBus.emit("alertExpired", J(e));
2331
+ this.eventBus.emit("alertExpired", Y(e));
1842
2332
  }), this.alertManager.on("updated", (e) => {
1843
- this.eventBus.emit("alertUpdate", J(e));
2333
+ this.eventBus.emit("alertUpdate", Y(e));
1844
2334
  }), this.signalMarkerManager = new mt(), this.signalMarkerManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.signalMarkerManager.setDataGetter(() => this.series.bars()), this.signalMarkerManager.on("added", (e) => {
1845
2335
  this.eventBus.emit("signalMarkerAdd", {
1846
2336
  id: e.id,
@@ -1856,7 +2346,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1856
2346
  });
1857
2347
  }), this.tradeZoneManager.on("removed", (e) => {
1858
2348
  this.eventBus.emit("tradeZoneRemove", { id: e });
1859
- }), this.replayManager = new st(), this.replayManager.on("complete", () => {
2349
+ }), this.replayManager = new ot(), this.replayManager.on("complete", () => {
1860
2350
  let e = this.getReplayBarIndex(), t = this.replayCoarse?.[e];
1861
2351
  t && this.eventBus.emit("replayComplete", {
1862
2352
  barIndex: e,
@@ -1864,15 +2354,15 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1864
2354
  });
1865
2355
  }), this.replayManager.on("stateChange", (e) => {
1866
2356
  this.replayRestarting || this.eventBus.emit("replayState", { state: e });
1867
- }), this.measureOverlay = new Je(), this.interactionManager = new He(e), this.features.panning) {
1868
- let e = new or();
1869
- this.interactionManager.setPanHandler(new Xe((t, n) => {
1870
- t && this.viewport.scrollBy(t), e.step(t, n, this.options.autoScale !== !1) && n && (this.holdPriceScale(), this.viewport.panPriceRange(n)), this.updateViewportAndRender();
2357
+ }), this.measureOverlay = new qe(), this.interactionManager = new Ve(e), this.features.panning) {
2358
+ let e = new Ar();
2359
+ this.interactionManager.setPanHandler(new Ye((t, n) => {
2360
+ t && this.viewport.scrollBy(t), e.step(t, n, this.priceFit.isAuto()) && n && (this.holdPriceScale(), this.viewport.panPriceRange(n)), this.updateViewportAndRender();
1871
2361
  }, () => e.reset()));
1872
2362
  }
1873
2363
  if (this.interactionManager.setAxisStrips(() => ({
1874
2364
  plot: this.viewport.getState().chartRect,
1875
- timeAxisTop: this.timeAxisTop(),
2365
+ timeAxisTop: this.panes.timeAxisTop(),
1876
2366
  left: {
1877
2367
  width: this.isLeftPriceScaleShown() ? this.leftAxisWidth : 0,
1878
2368
  scales: !this.indicatorEngine.hasLeftScaleOverlays()
@@ -1881,14 +2371,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1881
2371
  this.interactionManager.setZoomHandler(new kt((e, t) => {
1882
2372
  this.viewport.zoom(e, t - this.viewport.getState().chartRect.x), this.updateViewportAndRender();
1883
2373
  }));
1884
- let e = new _e((e) => {
2374
+ let e = new ge((e) => {
1885
2375
  this.holdPriceScale(), this.viewport.scalePriceRange(e), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
1886
2376
  }, (e) => {
1887
2377
  let t = this.viewport.getState().chartRect.width;
1888
2378
  this.viewport.zoom(1 / e - 1, t / 2), this.updateViewportAndRender();
1889
2379
  });
1890
2380
  this.interactionManager.setAxisDragHandler(e, () => this.viewport.getState(), (e) => {
1891
- e === "price" ? (this.options.autoScale = !0, this.updateViewportAndRender()) : this.fitContent();
2381
+ e === "price" ? (this.priceFit.resume(), this.updateViewportAndRender()) : this.fitContent();
1892
2382
  });
1893
2383
  }
1894
2384
  if (this.features.crosshair && this.interactionManager.setCrosshairHandler(this.crosshairHandler), this.features.drawings && (this.interactionManager.setDrawingManager(this.drawingManager, () => ({
@@ -1906,7 +2396,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1906
2396
  y: t.y
1907
2397
  });
1908
2398
  })), this.interactionManager.setChartContextMenu((e, t) => this.eventBus.hasListeners("chartContextMenu") ? (this.eventBus.emit("chartContextMenu", this.contextAt(e, t)), !0) : !1), this.applyPriceAxisAdd(), this.interactionManager.setPriceAxisAddButton(this.priceAxisAddButton, (e) => {
1909
- let t = Xt(e.y, this.viewport.getState());
2399
+ let t = Zt(e.y, this.viewport.getState());
1910
2400
  Number.isFinite(t) && this.eventBus.emit("priceAxisAdd", {
1911
2401
  price: t,
1912
2402
  x: e.x,
@@ -1916,10 +2406,10 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1916
2406
  ...this.viewport.getState(),
1917
2407
  data: this.getDisplayData()
1918
2408
  })), this.features.alerts) {
1919
- let e = new pe(this.alertManager, () => this.viewport.getState());
2409
+ let e = new fe(this.alertManager, () => this.viewport.getState());
1920
2410
  this.interactionManager.setAlertDragHandler(e);
1921
2411
  }
1922
- let o = new Ze();
2412
+ let o = new Xe();
1923
2413
  o.configure(() => this.getResolvedLayout(), (e, t) => this.setPanelSize(e, t)), this.interactionManager.setPaneResizeHandler(o), this.interactionManager.setAltClickHandler((e) => {
1924
2414
  let t = this.getDisplayData();
1925
2415
  if (t.length === 0) return;
@@ -1943,7 +2433,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1943
2433
  x: e.x,
1944
2434
  y: e.y
1945
2435
  }), t.length === 0) return;
1946
- let r = Yt(e.x, this.viewport.getState());
2436
+ let r = Xt(e.x, this.viewport.getState());
1947
2437
  r < 0 || r >= t.length || this.eventBus.emit("barClick", {
1948
2438
  bar: t[r],
1949
2439
  barIndex: r,
@@ -1988,7 +2478,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
1988
2478
  end: () => {
1989
2479
  let e = this.selectionBoxOverlay.end();
1990
2480
  if (e && this.zoomAreaMode) {
1991
- if (e.x1 - e.x0 < Kr) return;
2481
+ if (e.x1 - e.x0 < di) return;
1992
2482
  this.zoomToBox(e), this.setZoomAreaMode(!1);
1993
2483
  return;
1994
2484
  }
@@ -2023,10 +2513,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2023
2513
  this.loadDuringReplay(e);
2024
2514
  return;
2025
2515
  }
2026
- this.snapshotKey = null, this.endReplaySession(), this.history.reset(), this.series.load(e), this.crosshairHandler.setData(this.series.bars()), this.displayDataCache = null, this.reshapeMemo.clear(), this.sessionBreaks.invalidateCache(), this.options.autoScale = this.defaultAutoScale, this.priceFitPending = !0;
2027
- let n = this.series.bars();
2028
- this.seriesArriving = n.length === 0;
2029
- let r = n[n.length - 1];
2516
+ this.snapshotKey = null, this.endReplaySession(), this.history.reset(), this.series.load(e), this.crosshairHandler.setData(this.series.bars()), this.display.reset(), this.sessionBreaks.invalidateCache(), this.priceFit.newSeries(this.series.length() === 0);
2517
+ let n = this.series.bars(), r = n[n.length - 1];
2030
2518
  t || (this.alertManager.clearLastValues(), r && this.alertManager.seedLastValue("price", r.close)), this.recalcIndicators(n), r && this.currentPriceLine.setPrice(r.close), this.updateViewportAndRender(!0), this.fitFewColumns(), this.emitBars(n.length);
2031
2519
  }
2032
2520
  loadDuringReplay(e) {
@@ -2039,8 +2527,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2039
2527
  let t = this.getDisplayData(), n = Math.max(0, Math.min(t.length - 1, Math.floor(this.viewport.getState().visibleRange.from))), r = t[n]?.time, { added: i, taken: a } = this.series.prepend(e);
2040
2528
  if (i === 0) return a;
2041
2529
  let o = this.series.bars();
2042
- if (this.crosshairHandler.setData(o), this.displayDataCache = null, this.reshapeMemo.clear(), this.sessionBreaks.invalidateCache(), this.pinnedTooltip.isPinned() && this.pinnedTooltip.unpin(), this.measureOverlay.end(), this.recalcIndicators(o), r !== void 0) {
2043
- let e = Math.round(N(r, this.getDisplayData()));
2530
+ if (this.crosshairHandler.setData(o), this.display.reset(), this.sessionBreaks.invalidateCache(), this.pinnedTooltip.isPinned() && this.pinnedTooltip.unpin(), this.measureOverlay.end(), this.recalcIndicators(o), r !== void 0) {
2531
+ let e = Math.round(M(r, this.getDisplayData()));
2044
2532
  this.viewport.prependBars(e - n);
2045
2533
  }
2046
2534
  return this.updateViewportAndRender(), a;
@@ -2052,7 +2540,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2052
2540
  return;
2053
2541
  }
2054
2542
  let n = this.series.bars();
2055
- this.crosshairHandler.setData(n), this.displayDataCache = null, this.reshapeMemo.clear(), this.sessionBreaks.invalidateCache(), this.recalcIndicators(n), n.length > 0 && this.currentPriceLine.setPrice(n[n.length - 1].close), this.updateViewportAndRender(t), this.emitBars(n.length);
2543
+ this.crosshairHandler.setData(n), this.display.reset(), this.sessionBreaks.invalidateCache(), this.recalcIndicators(n), n.length > 0 && this.currentPriceLine.setPrice(n[n.length - 1].close), this.updateViewportAndRender(t), this.emitBars(n.length);
2056
2544
  }
2057
2545
  setHistoryLoader(e, t) {
2058
2546
  this.historyFromStream = !1, this.hostHistoryLoader = e !== null, this.history.setLoader(e, t?.pageSize), this.checkHistory();
@@ -2068,17 +2556,17 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2068
2556
  }
2069
2557
  checkHistory() {
2070
2558
  this.historyCheckQueued || !this.history.hasLoader() || (this.historyCheckQueued = !0, queueMicrotask(() => {
2071
- if (this.historyCheckQueued = !1, !this.replayPages() || !this.history.hasLoader() || L(this.options.chartType)) return;
2559
+ if (this.historyCheckQueued = !1, !this.replayPages() || !this.history.hasLoader() || I(this.options.chartType)) return;
2072
2560
  let { visibleRange: e, chartRect: t } = this.viewport.getState();
2073
2561
  if (t.width <= 0) return;
2074
2562
  let { from: n, to: r } = e;
2075
- this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(Gr, r - n));
2563
+ this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(ui, r - n));
2076
2564
  }));
2077
2565
  }
2078
2566
  useStreamHistory(e, t, n = !0) {
2079
2567
  if (this.hostHistoryLoader) return;
2080
- let r = P(e), i = r.fetchHistoryBefore, a = this.streamTimeframe;
2081
- if (!i || a === null || de(a) !== null) {
2568
+ let r = N(e), i = r.fetchHistoryBefore, a = this.streamTimeframe;
2569
+ if (!i || a === null || ue(a) !== null) {
2082
2570
  this.historyFromStream && this.history.setLoader(null), this.historyFromStream = !1;
2083
2571
  return;
2084
2572
  }
@@ -2088,33 +2576,31 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2088
2576
  appendBar(e) {
2089
2577
  if (!R(e)) return;
2090
2578
  let t = this.series.append(e);
2091
- if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
2579
+ if (t.to !== "shown") {
2092
2580
  this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
2093
2581
  return;
2094
2582
  }
2095
2583
  let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
2096
- this.crosshairHandler.setData(i), this.displayDataCache = null, this.recalcIndicatorsFrom(i, i.length - 2), this.currentPriceLine.setPrice(e.close, i[i.length - 2]?.close), this.updateViewportAndRender(n), i.length !== r && this.emitBars(i.length), this.followLivePrice(e.close);
2584
+ this.crosshairHandler.setData(i), this.recalcIndicatorsFrom(i, i.length - 2), this.currentPriceLine.setPrice(e.close, i[i.length - 2]?.close), this.updateViewportAndRender(n), i.length !== r && this.emitBars(i.length), this.followLivePrice(e.close);
2097
2585
  }
2098
2586
  appendBars(e) {
2099
2587
  if (e = e.filter(R), e.length === 0) return;
2100
2588
  let t = e[e.length - 1].close, n = this.series.appendMany(e);
2101
- if (n.refiltered && (this.displayDataCache = null), n.shown === 0) {
2589
+ if (n.shown === 0) {
2102
2590
  this.takeLivePrice(t), n.aside || this.scheduleRender();
2103
2591
  return;
2104
2592
  }
2105
- let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = n.before;
2106
- this.displayDataCache = null;
2107
- let a = this.series.bars();
2593
+ let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = n.before, a = this.series.bars();
2108
2594
  this.recalcIndicatorsFrom(a, i - 1), this.crosshairHandler.setData(a), this.currentPriceLine.setPrice(t, a[a.length - 2]?.close), this.updateViewportAndRender(r), a.length !== i && this.emitBars(a.length), this.followLivePrice(t);
2109
2595
  }
2110
2596
  updateLastBar(e) {
2111
2597
  if (!R(e)) return;
2112
2598
  let t = this.series.updateLast(e);
2113
- if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
2599
+ if (t.to !== "shown") {
2114
2600
  this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
2115
2601
  return;
2116
2602
  }
2117
- this.currentPriceLine.setPrice(e.close), this.options.chartType !== "candlestick" && this.options.chartType !== "line" && this.options.chartType !== "area" && this.options.chartType !== "bar" && this.options.chartType !== "hollowCandle" && (this.displayDataCache = null);
2603
+ this.currentPriceLine.setPrice(e.close);
2118
2604
  let n = this.series.bars();
2119
2605
  this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.close), this.scheduleRender();
2120
2606
  }
@@ -2125,7 +2611,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2125
2611
  this.takeLivePrice(e.price), t.to === "hidden" && this.scheduleRender();
2126
2612
  return;
2127
2613
  }
2128
- this.currentPriceLine.setPrice(e.price), this.options.chartType !== "candlestick" && this.options.chartType !== "line" && this.options.chartType !== "area" && this.options.chartType !== "bar" && this.options.chartType !== "hollowCandle" && (this.displayDataCache = null);
2614
+ this.currentPriceLine.setPrice(e.price);
2129
2615
  let n = this.series.bars();
2130
2616
  this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.price), this.scheduleRender();
2131
2617
  }
@@ -2136,7 +2622,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2136
2622
  }
2137
2623
  showCorrection(e) {
2138
2624
  let t = this.series.bars(), n = t[e];
2139
- this.displayDataCache = null, this.reshapeMemo.clear(), this.indicatorEngine.deferRecalculateFrom(t, e), this.announceIndicatorUpdate(e), e === t.length - 1 && (this.currentPriceLine.setPrice(n.close, t[e - 1]?.close), this.alertManager.seedLastValue("price", n.close)), this.refreshShownBar(e), this.eventBus.emit("dataUpdate", {
2625
+ this.display.reset(), this.indicatorEngine.deferRecalculateFrom(t, e), this.announceIndicatorUpdate(e), e === t.length - 1 && (this.currentPriceLine.setPrice(n.close, t[e - 1]?.close), this.alertManager.seedLastValue("price", n.close)), this.refreshShownBar(e), this.eventBus.emit("dataUpdate", {
2140
2626
  kind: "correction",
2141
2627
  time: n.time,
2142
2628
  index: e
@@ -2157,29 +2643,29 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2157
2643
  }
2158
2644
  setChartType(e) {
2159
2645
  let t = this.options.chartType ?? "candlestick";
2160
- this.options.chartType = e, this.themeManager.setChartType(e), this.chartRenderer = this.createChartRenderer(e), this.chartLegend.setChartType(e), this.displayDataCache = null, this.applyTimeSpacing(), this.updateViewportAndRender(!0), this.fitFewColumns(), this.markStateChanged(), e !== t && this.eventBus.emit("chartTypeChange", {
2646
+ this.options.chartType = e, this.themeManager.setChartType(e), this.chartRenderer = this.createChartRenderer(e), this.display.invalidate(), this.chartLegend.setChartType(e), this.applyTimeSpacing(), this.updateViewportAndRender(!0), this.fitFewColumns(), this.markStateChanged(), e !== t && this.eventBus.emit("chartTypeChange", {
2161
2647
  type: e,
2162
2648
  previous: t
2163
2649
  });
2164
2650
  }
2165
2651
  fitFewColumns() {
2166
2652
  let e = this.options.chartType;
2167
- if (!L(e) || this.pluginManager.getChartType(e)) return;
2653
+ if (!I(e) || this.pluginManager.getChartType(e)) return;
2168
2654
  let t = this.getDisplayData().length, { chartRect: n, barWidth: r, barSpacing: i } = this.viewport.getState(), a = n.width / (r + i);
2169
2655
  t > 0 && a > t + this.viewport.getRightMargin() && this.fitContent();
2170
2656
  }
2171
2657
  applyTimeSpacing() {
2172
- let e = !this.tickStream && !L(this.options.chartType);
2658
+ let e = !this.tickStream && !I(this.options.chartType);
2173
2659
  this.timeAxis.setTimesPastData(e), this.crosshairHandler.setTimesPastData(e);
2174
2660
  }
2175
2661
  setChartTypeOptions(e) {
2176
2662
  this.chartTypeOptions = {
2177
2663
  ...this.chartTypeOptions,
2178
- ...ae(e)
2179
- }, this.displayDataCache = null, this.updateViewportAndRender(!0), this.fitFewColumns(), this.a11y?.refresh(!0), this.markStateChanged();
2664
+ ...S(e)
2665
+ }, this.updateViewportAndRender(!0), this.fitFewColumns(), this.a11y?.refresh(!0), this.markStateChanged();
2180
2666
  }
2181
2667
  getChartTypeOptions() {
2182
- return ae(this.chartTypeOptions);
2668
+ return S(this.chartTypeOptions);
2183
2669
  }
2184
2670
  setExtendedHours(e) {
2185
2671
  e !== this.extendedHours && (this.extendedHours = e, this.reapplyExtendedHours(), this.markStateChanged());
@@ -2188,18 +2674,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2188
2674
  return this.extendedHours;
2189
2675
  }
2190
2676
  sessionKeep(e) {
2191
- return this.extendedHours ? null : $t(this.symbolInfo, e);
2677
+ return this.extendedHours ? null : en(this.symbolInfo, e);
2192
2678
  }
2193
2679
  reapplyExtendedHours() {
2194
2680
  if (!this.series.refilter()) return;
2195
2681
  let e = this.series.bars();
2196
- this.crosshairHandler.setData(e), this.displayDataCache = null, this.reshapeMemo.clear(), this.sessionBreaks.invalidateCache(), this.recalcIndicators(e), this.updateViewportAndRender(!0), this.emitBars(e.length);
2682
+ this.crosshairHandler.setData(e), this.display.reset(), this.sessionBreaks.invalidateCache(), this.recalcIndicators(e), this.updateViewportAndRender(!0), this.emitBars(e.length);
2197
2683
  }
2198
2684
  quoteLines() {
2199
2685
  return this.priceLines.setQuoteShown(this.replaySession === null), this.priceLines;
2200
2686
  }
2201
2687
  setShapes(e) {
2202
- let t = ri(e);
2688
+ let t = bi(e);
2203
2689
  t.tagRadius !== void 0 && (this.themeManager.setShape({
2204
2690
  ...this.themeManager.getTheme().shape,
2205
2691
  ...t
@@ -2211,7 +2697,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2211
2697
  setFont(e) {
2212
2698
  if (e === null) this.themeManager.setFont(null);
2213
2699
  else {
2214
- let t = ni(e);
2700
+ let t = yi(e);
2215
2701
  if (Object.keys(t).length === 0) return;
2216
2702
  this.themeManager.setFont(t);
2217
2703
  }
@@ -2245,11 +2731,11 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2245
2731
  return this.priceLines.getBidAsk();
2246
2732
  }
2247
2733
  addIndicator(e, t, n = "bottom", r = {}) {
2248
- return this.recordIndicators(void 0, () => this.addIndicatorNow(e, t ?? {}, n, r));
2734
+ return this.indicatorHistory.record(void 0, () => this.addIndicatorNow(e, t ?? {}, n, r));
2249
2735
  }
2250
2736
  addIndicatorNow(e, t, n, r) {
2251
2737
  if (!this.isIndicatorAllowed(e)) return null;
2252
- let i = this.indicatorEngine.getAvailableIndicators().find((t) => t.id === e), a = i ? this.paneFor(i, t, r.pane) : null, o = this.indicatorEngine.addIndicator(e, t, this.indicatorBars(), {
2738
+ let i = this.indicatorEngine.getAvailableIndicators().find((t) => t.id === e), a = i ? this.indicatorPanes.paneFor(i, t, r.pane) : null, o = this.indicatorEngine.addIndicator(e, t, this.indicatorBars(), {
2253
2739
  ...a ? { pane: a } : {},
2254
2740
  ...r.scale === "left" ? { scale: "left" } : {},
2255
2741
  ...r.instanceId ? { instanceId: r.instanceId } : {}
@@ -2260,67 +2746,41 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2260
2746
  }), this.markStateChanged(), this.requestMissingSymbols(o), o;
2261
2747
  }
2262
2748
  setSymbolSeries(e, t) {
2263
- e = e.trim(), this.symbolSeries.set(e, t), this.requestedSymbols.delete(e);
2264
- let n = this.indicatorBars(), r = !1;
2265
- for (let t of this.indicatorEngine.getActiveIndicators()) !O.has(t.id) || String(t.params.symbol ?? "").trim() !== e.trim() || (this.indicatorEngine.updateIndicator(t.instanceId, {}, n), r = !0);
2266
- r && (this.announceIndicatorUpdate(0), this.updateViewportAndRender());
2267
- }
2268
- forgetUnreadSymbols() {
2269
- let e = new Set(this.getRequiredSymbols());
2270
- for (let t of this.requestedSymbols) e.has(t) || this.requestedSymbols.delete(t);
2749
+ e = e.trim(), this.symbolSeries.set(e, t), this.symbolRequests.given(e);
2750
+ let n = this.symbolRequests.readersOf(e);
2751
+ if (n.length === 0) return;
2752
+ let r = this.indicatorBars();
2753
+ for (let e of n) this.indicatorEngine.updateIndicator(e, {}, r);
2754
+ this.announceIndicatorUpdate(0), this.updateViewportAndRender();
2271
2755
  }
2272
2756
  getSymbolSeries(e) {
2273
2757
  return this.symbolSeries.get(e) ?? null;
2274
2758
  }
2275
2759
  getRequiredSymbols() {
2276
- let e = /* @__PURE__ */ new Set();
2277
- for (let t of this.indicatorEngine.getActiveIndicators()) {
2278
- let n = t.params.symbol;
2279
- O.has(t.id) && typeof n == "string" && n.trim() && e.add(n.trim());
2280
- }
2281
- return [...e];
2760
+ return this.symbolRequests.required();
2282
2761
  }
2283
2762
  requestMissingSymbols(e) {
2284
- this.forgetUnreadSymbols();
2285
- let t = this.indicatorEngine.getIndicatorConfig(e), n = t && O.has(t.id) && typeof t.params.symbol == "string" ? t.params.symbol.trim() : "";
2286
- !n || this.symbolSeries.has(n) || this.requestedSymbols.has(n) || (this.requestedSymbols.add(n), this.eventBus.emit("symbolSeriesRequest", { symbol: n }));
2763
+ let t = this.symbolRequests.toAsk(e);
2764
+ t && this.eventBus.emit("symbolSeriesRequest", { symbol: t });
2287
2765
  }
2288
2766
  updateIndicator(e, t) {
2289
- this.recordIndicators(e, () => this.updateIndicatorNow(e, t));
2767
+ this.indicatorHistory.record(e, () => this.updateIndicatorNow(e, t));
2290
2768
  }
2291
2769
  updateIndicatorNow(e, t) {
2292
- let n = this.indicatorEngine.getIndicatorDescriptor(e), r = n ? M(n) : null, i = r ? this.indicatorEngine.getIndicatorConfig(e)?.params[r] : void 0;
2770
+ let n = this.indicatorPanes.sourceOf(e);
2293
2771
  this.indicatorEngine.updateIndicator(e, t, this.indicatorBars()), this.announceIndicatorUpdate(0), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
2294
2772
  instanceId: e,
2295
2773
  change: "params"
2296
- }), this.requestMissingSymbols(e);
2297
- let a = this.indicatorEngine.getIndicatorConfig(e);
2298
- if (n?.placement === "overlay" && a && r && a.params[r] !== i) {
2299
- let t = x(a.params[r]), n = t ? this.paneHostOf(t.instanceId, e) : x(i) ? null : a.pane ?? null;
2300
- (n ?? void 0) !== a.pane && (this.indicatorEngine.setPane(e, n), this.eventBus.emit("indicatorChange", {
2301
- instanceId: e,
2302
- change: "pane"
2303
- }));
2304
- }
2305
- this.updateViewportAndRender();
2306
- }
2307
- paneFor(e, t, n, r) {
2308
- if (n) return this.paneHostOf(n, r);
2309
- if (e.placement !== "overlay") return null;
2310
- let i = M(e), a = i ? x(t[i]) : null;
2311
- return a ? this.paneHostOf(a.instanceId, r) : null;
2312
- }
2313
- paneHostOf(e, t) {
2314
- if (e === t) return null;
2315
- if (this.layoutManager.getPanels().some((t) => t.id === e)) return e;
2316
- let n = this.indicatorEngine.getIndicatorConfig(e)?.pane;
2317
- return n && n !== t ? n : null;
2774
+ }), this.requestMissingSymbols(e), this.indicatorPanes.followSource(e, n) && this.eventBus.emit("indicatorChange", {
2775
+ instanceId: e,
2776
+ change: "pane"
2777
+ }), this.updateViewportAndRender();
2318
2778
  }
2319
2779
  getIndicatorLevels(e) {
2320
2780
  return this.indicatorEngine.getLevels(e);
2321
2781
  }
2322
2782
  setIndicatorScale(e, t) {
2323
- return this.recordIndicators(e, () => this.setIndicatorScaleNow(e, t));
2783
+ return this.indicatorHistory.record(e, () => this.setIndicatorScaleNow(e, t));
2324
2784
  }
2325
2785
  setIndicatorScaleNow(e, t) {
2326
2786
  return this.indicatorEngine.setScale(e, t) ? (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2353,8 +2813,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2353
2813
  return {
2354
2814
  ...e,
2355
2815
  priceRange: {
2356
- min: t.min - n * Br,
2357
- max: t.max + n * Br
2816
+ min: t.min - n * li,
2817
+ max: t.max + n * li
2358
2818
  },
2359
2819
  logScale: !1,
2360
2820
  scaleMode: "regular",
@@ -2365,7 +2825,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2365
2825
  };
2366
2826
  }
2367
2827
  setIndicatorLevels(e, t) {
2368
- this.recordIndicators(e, () => this.setIndicatorLevelsNow(e, t));
2828
+ this.indicatorHistory.record(e, () => this.setIndicatorLevelsNow(e, t));
2369
2829
  }
2370
2830
  setIndicatorLevelsNow(e, t) {
2371
2831
  this.indicatorEngine.setLevels(e, t) && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2374,10 +2834,10 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2374
2834
  }));
2375
2835
  }
2376
2836
  removeIndicator(e) {
2377
- this.recordIndicators(void 0, () => this.removeIndicatorNow(e));
2837
+ this.indicatorHistory.record(void 0, () => this.removeIndicatorNow(e));
2378
2838
  }
2379
2839
  removeIndicators(e) {
2380
- this.recordIndicators(void 0, () => {
2840
+ this.indicatorHistory.record(void 0, () => {
2381
2841
  for (let t of e) this.removeIndicatorNow(t);
2382
2842
  });
2383
2843
  }
@@ -2388,16 +2848,10 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2388
2848
  this.markStateChanged(), this.updateViewportAndRender();
2389
2849
  }
2390
2850
  detachIndicator(e) {
2391
- if (!this.indicatorEngine.getIndicatorConfig(e)) return;
2392
- let t = this.layoutManager.getPanels().find((t) => t.id === e), n = this.indicatorEngine.getPaneMembers(e), r = t ? n.find((e) => this.indicatorEngine.getIndicatorDescriptor(e)?.placement === "panel") ?? null : null;
2393
- this.indicatorEngine.removeIndicator(e);
2394
- let i = this.paneStyles.get(e);
2395
- this.paneStyles.delete(e), r ? (this.indicatorEngine.setPane(r, null), this.renamePane(e, r), i && this.paneStyles.set(r, i)) : this.layoutManager.removePanel(e);
2396
- for (let e of n) e !== r && this.indicatorEngine.setPane(e, r), this.eventBus.emit("indicatorChange", {
2851
+ this.indicatorPanes.detach(e, (e) => this.eventBus.emit("indicatorChange", {
2397
2852
  instanceId: e,
2398
2853
  change: "pane"
2399
- });
2400
- this.eventBus.emit("indicatorRemove", { instanceId: e }), this.forgetUnreadSymbols();
2854
+ })) && (this.eventBus.emit("indicatorRemove", { instanceId: e }), this.symbolRequests.forgetUnread());
2401
2855
  }
2402
2856
  getIndicatorStyle(e) {
2403
2857
  return this.indicatorEngine.getIndicatorStyle(e);
@@ -2407,21 +2861,21 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2407
2861
  this.indicatorEngine.setStyleDefaults(e, null);
2408
2862
  return;
2409
2863
  }
2410
- let { plots: n, ...r } = t, i = n === void 0 ? void 0 : oe(n);
2864
+ let { plots: n, ...r } = t, i = n === void 0 ? void 0 : ae(n);
2411
2865
  this.indicatorEngine.setStyleDefaults(e, {
2412
2866
  ...r,
2413
2867
  ...i ? { plots: i } : {}
2414
2868
  });
2415
2869
  }
2416
2870
  setPaneStyle(e, t) {
2417
- let n = this.paneOf(e);
2418
- this.layoutManager.getPanels().some((e) => e.id === n) && this.recordIndicators(n, () => this.setPaneStyleNow(n, t ? se(t) : null));
2871
+ let n = this.indicatorPanes.paneOf(e);
2872
+ this.layoutManager.getPanels().some((e) => e.id === n) && this.indicatorHistory.record(n, () => this.setPaneStyleNow(n, t ? oe(t) : null));
2419
2873
  }
2420
2874
  setPaneStyleNow(e, t) {
2421
- JSON.stringify(t) !== JSON.stringify(this.paneStyles.get(e) ?? null) && (t ? this.paneStyles.set(e, t) : this.paneStyles.delete(e), this.panelInfoCache = null, this.syncRenderContext(), this.engine.requestRender(), this.markStateChanged());
2875
+ this.panes.setStyle(e, t) && (this.syncRenderContext(), this.engine.requestRender(), this.markStateChanged());
2422
2876
  }
2423
2877
  getPaneStyle(e) {
2424
- let t = this.paneStyles.get(this.paneOf(e));
2878
+ let t = this.panes.style(this.indicatorPanes.paneOf(e));
2425
2879
  return t ? { ...t } : null;
2426
2880
  }
2427
2881
  getIndicatorOutput(e) {
@@ -2434,8 +2888,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2434
2888
  return this.pluginManager;
2435
2889
  }
2436
2890
  static indicators() {
2437
- let e = new Ve();
2438
- return Vt(e), e.getAvailableIndicators();
2891
+ let e = new Be();
2892
+ return Ht(e), e.getAvailableIndicators();
2439
2893
  }
2440
2894
  setPanelPosition(e, t) {
2441
2895
  this.layoutManager.setPanelPosition(e, t), this.updateViewportAndRender(), this.eventBus.emit("indicatorChange", {
@@ -2450,96 +2904,52 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2450
2904
  }), this.markStateChanged();
2451
2905
  }
2452
2906
  moveIndicatorToPane(e, t) {
2453
- return this.recordIndicators(e, () => this.moveIndicatorToPaneNow(e, t));
2907
+ return this.indicatorHistory.record(e, () => this.moveIndicatorToPaneNow(e, t));
2454
2908
  }
2455
2909
  canMoveIndicatorToPane(e, t) {
2456
- return this.paneMoveHost(e, t) !== void 0;
2457
- }
2458
- paneMoveHost(e, t) {
2459
- let n = this.indicatorEngine.getIndicatorConfig(e), r = this.indicatorEngine.getIndicatorDescriptor(e);
2460
- if (!n || !r) return;
2461
- let i = M(r);
2462
- if (r.placement === "overlay" && i && x(n.params[i])) return;
2463
- if (t === "price") return r.placement === "overlay" && n.pane ? null : void 0;
2464
- if (t === "new") {
2465
- let t = this.layoutManager.getPanels().some((t) => t.id === e);
2466
- return r.placement === "panel" && !t ? null : void 0;
2467
- }
2468
- let a = this.paneHostOf(t, e);
2469
- return a && a !== n.pane && a !== e ? a : void 0;
2910
+ return this.indicatorPanes.moveHost(e, t) !== void 0;
2470
2911
  }
2471
2912
  moveIndicatorToPaneNow(e, t) {
2472
- let n = this.paneMoveHost(e, t), r = this.indicatorEngine.getIndicatorConfig(e);
2473
- if (n === void 0 || !r) return !1;
2474
- let i = r.pane, a = this.layoutManager.getPanels().some((t) => t.id === e), o = new Set([e]);
2475
- if (a) {
2476
- let t = this.indicatorEngine.getPaneMembers(e), r = new Set(this.indicatorEngine.getDependents(e)), i = t.filter((e) => !r.has(e)), a = i.find((e) => this.indicatorEngine.getIndicatorDescriptor(e)?.placement === "panel") ?? null, s = this.paneStyles.get(e);
2477
- if (this.paneStyles.delete(e), a) {
2478
- this.indicatorEngine.setPane(a, null), this.renamePane(e, a), s && this.paneStyles.set(a, s);
2479
- for (let e of i) e !== a && this.indicatorEngine.setPane(e, a);
2480
- } else {
2481
- this.layoutManager.removePanel(e);
2482
- for (let e of i) this.indicatorEngine.setPane(e, null);
2483
- }
2484
- this.panelInfoCache = null;
2485
- for (let i of t) r.has(i) && this.indicatorEngine.setPane(i, n ?? e), o.add(i);
2486
- }
2487
- if (this.indicatorEngine.setPane(e, n), t === "new") {
2488
- this.layoutManager.addPanel(e, "bottom");
2489
- for (let t of this.indicatorEngine.getDependents(e)) this.indicatorEngine.getIndicatorConfig(t)?.pane === i && (this.indicatorEngine.setPane(t, e), o.add(t));
2490
- }
2491
- for (let e of o) this.eventBus.emit("indicatorChange", {
2913
+ let n = this.indicatorPanes.move(e, t);
2914
+ if (!n) return !1;
2915
+ for (let e of n) this.eventBus.emit("indicatorChange", {
2492
2916
  instanceId: e,
2493
2917
  change: "pane"
2494
2918
  });
2495
2919
  return this.updateViewportAndRender(), this.markStateChanged(), !0;
2496
2920
  }
2497
2921
  setPaneCollapsed(e, t) {
2498
- let n = this.paneOf(e);
2499
- return this.recordIndicators(n, () => this.paneChange(n, "collapsed", () => this.layoutManager.setPanelCollapsed(n, t)));
2922
+ let n = this.indicatorPanes.paneOf(e);
2923
+ return this.indicatorHistory.record(n, () => this.paneChange(n, "collapsed", () => this.layoutManager.setPanelCollapsed(n, t)));
2500
2924
  }
2501
2925
  isPaneCollapsed(e) {
2502
- return this.layoutManager.isPanelShownCollapsed(this.paneOf(e));
2926
+ return this.layoutManager.isPanelShownCollapsed(this.indicatorPanes.paneOf(e));
2503
2927
  }
2504
2928
  setMaximizedPane(e) {
2505
- let t = e === null ? null : this.paneOf(e), n = t ?? this.layoutManager.getMaximizedPanel() ?? "";
2506
- return this.recordIndicators(n, () => this.paneChange(n, "maximized", () => this.layoutManager.setMaximizedPanel(t)));
2929
+ let t = e === null ? null : this.indicatorPanes.paneOf(e), n = t ?? this.layoutManager.getMaximizedPanel() ?? "";
2930
+ return this.indicatorHistory.record(n, () => this.paneChange(n, "maximized", () => this.layoutManager.setMaximizedPanel(t)));
2507
2931
  }
2508
2932
  getMaximizedPane() {
2509
2933
  return this.layoutManager.getMaximizedPanel();
2510
2934
  }
2511
2935
  setPaneScale(e, t) {
2512
- let n = this.paneOf(e);
2513
- return this.recordIndicators(n, () => this.paneChange(n, "scale", () => this.layoutManager.setPanelScale(n, t)));
2936
+ let n = this.indicatorPanes.paneOf(e);
2937
+ return this.indicatorHistory.record(n, () => this.paneChange(n, "scale", () => this.layoutManager.setPanelScale(n, t)));
2514
2938
  }
2515
2939
  getPaneScale(e) {
2516
- let t = this.layoutManager.getPanels().find((t) => t.id === this.paneOf(e));
2940
+ let t = this.layoutManager.getPanels().find((t) => t.id === this.indicatorPanes.paneOf(e));
2517
2941
  return {
2518
2942
  log: !!t?.logScale,
2519
2943
  invert: !!t?.invertScale,
2520
2944
  percent: !!t?.percentScale
2521
2945
  };
2522
2946
  }
2523
- paneBaseline(e, t, n) {
2524
- let r = this.indicatorEngine.getOutput(e)?.series, i = this.indicatorEngine.getIndicatorDescriptor(e);
2525
- if (!r || !i) return;
2526
- let a = i.plots?.[0]?.key;
2527
- for (let e = Math.max(0, t); e <= n && e < r.length; e++) {
2528
- let t = r[e];
2529
- if (!t) continue;
2530
- let n = a === void 0 ? Object.values(t).find((e) => typeof e == "number" && Number.isFinite(e)) : t[a];
2531
- if (typeof n == "number" && Number.isFinite(n) && n !== 0) return n;
2532
- }
2533
- }
2534
2947
  movePane(e, t) {
2535
- let n = this.paneOf(e);
2536
- return this.recordIndicators(n, () => this.paneChange(n, "order", () => this.layoutManager.movePanel(n, t)));
2948
+ let n = this.indicatorPanes.paneOf(e);
2949
+ return this.indicatorHistory.record(n, () => this.paneChange(n, "order", () => this.layoutManager.movePanel(n, t)));
2537
2950
  }
2538
2951
  canMovePane(e, t) {
2539
- return this.layoutManager.canMovePanel(this.paneOf(e), t);
2540
- }
2541
- paneOf(e) {
2542
- return this.indicatorEngine.getIndicatorConfig(e)?.pane ?? e;
2952
+ return this.layoutManager.canMovePanel(this.indicatorPanes.paneOf(e), t);
2543
2953
  }
2544
2954
  paneChange(e, t, n) {
2545
2955
  return n() ? (this.updateViewportAndRender(), this.eventBus.emit("paneChange", {
@@ -2594,12 +3004,12 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2594
3004
  }), n;
2595
3005
  }
2596
3006
  isTimeAligned() {
2597
- return L(this.options.chartType) ? !1 : this.getDisplayData().length === this.series.length();
3007
+ return I(this.options.chartType) ? !1 : this.getDisplayData().length === this.series.length();
2598
3008
  }
2599
3009
  roundPrice(e) {
2600
3010
  if (!Number.isFinite(e)) return e;
2601
3011
  let t = this.stepAt(e);
2602
- if (t !== void 0) return Number((Math.round(e / t) * t).toFixed(ue(t)));
3012
+ if (t !== void 0) return Number((Math.round(e / t) * t).toFixed(le(t)));
2603
3013
  let { min: n, max: r } = this.viewport.getState().priceRange;
2604
3014
  return Number(e.toFixed(this.marketPricePrecision ?? c(n, r)));
2605
3015
  }
@@ -2683,7 +3093,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2683
3093
  }
2684
3094
  autoFib() {
2685
3095
  if (!this.features.drawings) return null;
2686
- let e = this.getDisplayData(), t = this.viewport.getState(), n = jt(e, t.visibleRange.from, t.visibleRange.to);
3096
+ let e = this.getDisplayData(), t = this.viewport.getState(), n = Mt(e, t.visibleRange.from, t.visibleRange.to);
2687
3097
  return n ? this.addDrawing({
2688
3098
  type: "fibRetracement",
2689
3099
  anchors: [n[0], n[1]]
@@ -2696,9 +3106,9 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2696
3106
  return this.drawingManager.removeDrawings(e);
2697
3107
  }
2698
3108
  nudgeSelectedDrawings(e) {
2699
- let t = Jr[e.key];
3109
+ let t = pi[e.key];
2700
3110
  if (!t || !this.features.drawings || e.ctrlKey || e.metaKey || e.altKey) return !1;
2701
- let n = e.shiftKey ? qr : 1, r = {
3111
+ let n = e.shiftKey ? fi : 1, r = {
2702
3112
  ...this.viewport.getState(),
2703
3113
  data: this.getDisplayData()
2704
3114
  };
@@ -2792,7 +3202,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2792
3202
  recordUndo(e) {
2793
3203
  if (!this.features.drawingUndoRedo || typeof e?.undo != "function" || typeof e.redo != "function") return;
2794
3204
  let t = performance.now(), n = this.undoRedoManager.last();
2795
- if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < Hr) {
3205
+ if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < 800) {
2796
3206
  this.undoRedoManager.replaceLast({
2797
3207
  ...n,
2798
3208
  custom: {
@@ -2839,7 +3249,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2839
3249
  x: t.x,
2840
3250
  y: t.y
2841
3251
  };
2842
- if ((e === "plot" || e === "priceAxis") && (r.price = Xt(t.y, n)), (e === "plot" || e === "timeAxis") && n.data.length > 0 && (r.time = F(t.x, n)), e === "pane") {
3252
+ if ((e === "plot" || e === "priceAxis") && (r.price = Zt(t.y, n)), (e === "plot" || e === "timeAxis") && n.data.length > 0 && (r.time = P(t.x, n)), e === "pane") {
2843
3253
  let e = this.getIndicatorPanes().find((e) => t.y >= e.rect.y && t.y <= e.rect.y + e.rect.height);
2844
3254
  e && (r.pane = e.instanceId);
2845
3255
  }
@@ -2847,7 +3257,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2847
3257
  }
2848
3258
  applyPriceAxisAdd() {
2849
3259
  let e = this.features.priceAxisAddButton && this.features.crosshair;
2850
- this.priceAxisAddButton.setEnabled(e), this.tradingManager.setTagInset(e ? Ye : 0);
3260
+ this.priceAxisAddButton.setEnabled(e), this.tradingManager.setTagInset(e ? Je : 0);
2851
3261
  }
2852
3262
  setPriceAxisAddButton(e) {
2853
3263
  this.features.priceAxisAddButton = e, this.applyPriceAxisAdd(), this.engine.requestRender(r.Overlay);
@@ -2869,7 +3279,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2869
3279
  ...this.viewport.getState(),
2870
3280
  data: this.getDisplayData()
2871
3281
  };
2872
- this.setVisibleRange(F(e.x0, t), F(e.x1, t));
3282
+ this.setVisibleRange(P(e.x0, t), P(e.x1, t));
2873
3283
  }
2874
3284
  lockAllDrawings() {
2875
3285
  this.drawingManager.lockAllDrawings();
@@ -2914,7 +3324,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2914
3324
  for (let e of this.indicatorEngine.getActiveIndicators()) {
2915
3325
  let t = this.indicatorEngine.getOutput(e.instanceId)?.series;
2916
3326
  if (!t) continue;
2917
- let r = un(e.id, e.params, e.descriptor.defaultConfig, e.descriptor.shortName), o = e.descriptor.plots ?? Object.keys(t.find((e) => e) ?? {}).map((e) => ({
3327
+ let r = dn(e.id, e.params, e.descriptor.defaultConfig, e.descriptor.shortName), o = e.descriptor.plots ?? Object.keys(t.find((e) => e) ?? {}).map((e) => ({
2918
3328
  key: e,
2919
3329
  title: e
2920
3330
  }));
@@ -2938,11 +3348,11 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2938
3348
  }
2939
3349
  getExportText(e = "csv", t = {}) {
2940
3350
  let { bars: n, columns: r } = this.getExportData(t);
2941
- return e === "json" ? E.toJSON(n, r) : E.toCSV(n, r);
3351
+ return e === "json" ? D.toJSON(n, r) : D.toCSV(n, r);
2942
3352
  }
2943
3353
  download(e, t, n) {
2944
3354
  let r = this.getExportText(e, n);
2945
- e === "json" ? E.download(r, t ?? "chart-data.json", "application/json") : E.download(r, t ?? "chart-data.csv", "text/csv");
3355
+ e === "json" ? D.download(r, t ?? "chart-data.json", "application/json") : D.download(r, t ?? "chart-data.csv", "text/csv");
2946
3356
  }
2947
3357
  setAutoSave(e, t = 5e3) {
2948
3358
  this.autoSaveScheduler.enable(e, t);
@@ -2973,7 +3383,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2973
3383
  return this.indicatorEngine.getActiveIndicators();
2974
3384
  }
2975
3385
  setIndicatorVisible(e, t) {
2976
- this.recordIndicators(e, () => this.setIndicatorVisibleNow(e, t));
3386
+ this.indicatorHistory.record(e, () => this.setIndicatorVisibleNow(e, t));
2977
3387
  }
2978
3388
  setIndicatorVisibleNow(e, t) {
2979
3389
  this.indicatorEngine.setVisible(e, t) !== null && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2982,7 +3392,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
2982
3392
  }));
2983
3393
  }
2984
3394
  setIndicatorIntervals(e, t) {
2985
- this.recordIndicators(e, () => this.setIndicatorIntervalsNow(e, t));
3395
+ this.indicatorHistory.record(e, () => this.setIndicatorIntervalsNow(e, t));
2986
3396
  }
2987
3397
  setIndicatorIntervalsNow(e, t) {
2988
3398
  this.indicatorEngine.setIntervals(e, t) && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -3001,10 +3411,10 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3001
3411
  } : null;
3002
3412
  }
3003
3413
  updateIndicatorStyle(e, t) {
3004
- this.recordIndicators(e, () => this.updateIndicatorStyleNow(e, t));
3414
+ this.indicatorHistory.record(e, () => this.updateIndicatorStyleNow(e, t));
3005
3415
  }
3006
3416
  updateIndicatorStyleNow(e, t) {
3007
- let { plots: n, ...r } = t, i = n === void 0 ? void 0 : oe(n);
3417
+ let { plots: n, ...r } = t, i = n === void 0 ? void 0 : ae(n);
3008
3418
  this.indicatorEngine.updateIndicatorStyle(e, {
3009
3419
  ...r,
3010
3420
  ...i ? { plots: i } : {}
@@ -3126,29 +3536,29 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3126
3536
  async connect(e) {
3127
3537
  let t = {
3128
3538
  ...e,
3129
- adapter: Ht(e),
3539
+ adapter: Ut(e),
3130
3540
  feed: void 0
3131
3541
  };
3132
- if (!j(t.adapter, t.timeframe)) throw RangeError(`${t.adapter.name} cannot serve the ${t.timeframe} timeframe`);
3542
+ if (!A(t.adapter, t.timeframe)) throw RangeError(`${t.adapter.name} cannot serve the ${t.timeframe} timeframe`);
3133
3543
  this.snapshotKey = null, this.holdReplayFor(t.symbol), this.disconnectStream(), this.streamManager = new _t(), this.streamManager.setTimeZone(this.studyZoneHeld ? this.studyZone : this.getExchangeTimeZone()), this.streamManager.on("snapshot", (e) => {
3134
3544
  let n = this.streamSeriesKey(t.adapter);
3135
3545
  n === this.snapshotKey && this.replaySession ? this.series.mergeSnapshot(e) : n === this.snapshotKey && this.series.length() > 0 ? this.mergeSnapshot(e) : (this.replaySession && this.useStreamHistory(t.adapter, t.historyPageSize, !1), this.setData(e)), this.snapshotKey = n, this.useStreamHistory(t.adapter, t.historyPageSize);
3136
3546
  }), this.streamManager.on("barClose", (e) => {
3137
3547
  if (!R(e)) return;
3138
3548
  let t = this.series.placeStreamBar(e);
3139
- if (t.refiltered && (this.displayDataCache = null), t.to === "none") {
3549
+ if (t.to === "none") {
3140
3550
  this.updateBar(e);
3141
3551
  return;
3142
3552
  }
3143
3553
  if (t.to === "aside" && this.followLivePrice(e.close), t.to !== "shown") return;
3144
3554
  let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
3145
- this.crosshairHandler.setData(i), this.displayDataCache = null, this.recalcIndicatorsFrom(i, i.length - 2), this.updateViewportAndRender(n), i.length !== r && this.emitBars(i.length), this.followLivePrice(e.close);
3555
+ this.crosshairHandler.setData(i), this.recalcIndicatorsFrom(i, i.length - 2), this.updateViewportAndRender(n), i.length !== r && this.emitBars(i.length), this.followLivePrice(e.close);
3146
3556
  }), this.streamManager.on("barCorrection", (e) => {
3147
3557
  this.updateBar(e);
3148
3558
  }), this.streamManager.on("barUpdate", (e) => {
3149
3559
  if (!R(e)) return;
3150
3560
  let t = this.series.placeStreamBar(e);
3151
- if (t.refiltered && (this.displayDataCache = null), t.to === "none" || (this.replaySession || this.currentPriceLine.setPrice(e.close), this.replaySession)) return;
3561
+ if (t.to === "none" || (this.replaySession || this.currentPriceLine.setPrice(e.close), this.replaySession)) return;
3152
3562
  let n = t.before;
3153
3563
  if (t.to !== "shown") {
3154
3564
  this.scheduleRender();
@@ -3186,18 +3596,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3186
3596
  }), this.streamManager.on("symbolInfo", (e) => this.applyFeedSymbolInfo(e)), this.autoScrollOnNewBar = t.autoScroll !== !1, this.setStreamTarget(t.symbol, t.timeframe), this.streamAdapter = t.adapter;
3187
3597
  let n = this.streamManager;
3188
3598
  if (this.resolveStreamSymbol(t.adapter, t.symbol), await n.connect(t), this.streamManager !== n) return;
3189
- let i = w(t.timeframe);
3599
+ let i = T(t.timeframe);
3190
3600
  this.barCountdown.setTimeframeMs(i), this.countdownInterval && clearInterval(this.countdownInterval), this.countdownInterval = setInterval(() => {
3191
3601
  this.barCountdown.isVisible() && this.engine.requestRender(r.Hover);
3192
3602
  }, 1e3);
3193
3603
  }
3194
3604
  streamSeriesKey(e) {
3195
- let t = P(e), n = this.streamTimeframe, r = t instanceof ct && n !== null ? t.bucketFor(this.currentSymbol, n) : null;
3605
+ let t = N(e), n = this.streamTimeframe, r = t instanceof st && n !== null ? t.bucketFor(this.currentSymbol, n) : null;
3196
3606
  return `${this.currentSymbol}|${n}|${r?.timeZone ?? ""}`;
3197
3607
  }
3198
3608
  setStreamTarget(e, t) {
3199
3609
  let n = this.announcedSymbol;
3200
- this.currentSymbol = e, this.streamTimeframe = t, this.tickStream = de(t) !== null, this.applyTimeSpacing(), e !== n && this.chartLegend.setSymbol(e), e !== n && (this.announcedSymbol = e, this.eventBus.emit("symbolChange", {
3610
+ this.currentSymbol = e, this.streamTimeframe = t, this.tickStream = ue(t) !== null, this.applyTimeSpacing(), e !== n && this.chartLegend.setSymbol(e), e !== n && (this.announcedSymbol = e, this.eventBus.emit("symbolChange", {
3201
3611
  symbol: e,
3202
3612
  previous: n
3203
3613
  })), this.useTimeframe(t);
@@ -3215,8 +3625,8 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3215
3625
  async switchStream(e, t) {
3216
3626
  if (!this.streamManager) return;
3217
3627
  let n = this.streamAdapter;
3218
- if (n && !j(n, t)) throw RangeError(`${n.name} cannot serve the ${t} timeframe`);
3219
- this.holdReplayFor(e), this.setStreamTarget(e, t), this.historyFromStream && this.history.setLoader(null), this.barCountdown.setTimeframeMs(w(t)), n && this.resolveStreamSymbol(n, e), await this.streamManager.switchTo(e, t);
3628
+ if (n && !A(n, t)) throw RangeError(`${n.name} cannot serve the ${t} timeframe`);
3629
+ this.holdReplayFor(e), this.setStreamTarget(e, t), this.historyFromStream && this.history.setLoader(null), this.barCountdown.setTimeframeMs(T(t)), n && this.resolveStreamSymbol(n, e), await this.streamManager.switchTo(e, t);
3220
3630
  }
3221
3631
  isIndicatorAllowed(e) {
3222
3632
  let t = this.features.indicatorIds;
@@ -3235,7 +3645,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3235
3645
  }
3236
3646
  connectExecution(e, t = {}) {
3237
3647
  if (!this.features.trading) throw Error("connectExecution requires features.trading to be enabled");
3238
- this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = gr(e, {
3648
+ this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = Br(e, {
3239
3649
  onIntent: (e, t) => {
3240
3650
  let n = (e) => t(e.payload);
3241
3651
  return this.eventBus.on(e, n), () => this.eventBus.off(e, n);
@@ -3311,14 +3721,6 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3311
3721
  comparesDrawn() {
3312
3722
  return this.isTimeAligned();
3313
3723
  }
3314
- panesOffChartType() {
3315
- let e = this.indicatorEngine.getActiveIndicators(), t = new Set(e.filter((e) => e.offChartType).map((e) => e.instanceId)), n = /* @__PURE__ */ new Set();
3316
- for (let r of this.layoutManager.getPanels()) {
3317
- let i = e.filter((e) => e.instanceId === r.id || e.pane === r.id);
3318
- i.length > 0 && i.every((e) => t.has(e.instanceId)) && n.add(r.id);
3319
- }
3320
- return n;
3321
- }
3322
3724
  clearCompareSymbols() {
3323
3725
  let e = this.compareRenderer.getSymbols().map((e) => e.id);
3324
3726
  this.compareRenderer.clear(), this.updateViewportAndRender();
@@ -3368,18 +3770,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3368
3770
  goToTime(e) {
3369
3771
  let t = this.getDisplayData();
3370
3772
  if (t.length === 0 || !Number.isFinite(e)) return -1;
3371
- let n = Math.max(0, Math.min(t.length - 1, Math.floor(N(e, t)))), r = this.viewport.getState(), i = n * (r.barWidth + r.barSpacing) + r.barWidth / 2 - r.chartRect.width / 2;
3773
+ let n = Math.max(0, Math.min(t.length - 1, Math.floor(M(e, t)))), r = this.viewport.getState(), i = n * (r.barWidth + r.barSpacing) + r.barWidth / 2 - r.chartRect.width / 2;
3372
3774
  return this.viewport.scrollBy(i - r.offset), this.updateViewportAndRender(), n;
3373
3775
  }
3374
3776
  setVisibleRangePreset(e) {
3375
3777
  let t = this.getDisplayData();
3376
3778
  if (t.length === 0) return;
3377
- let n = t.length - 1, r = u(t), i = Rt(e, t[n].time * r, this.displayTz), a = i === null ? null : i / r;
3779
+ let n = t.length - 1, r = u(t), i = zt(e, t[n].time * r, this.displayTz), a = i === null ? null : i / r;
3378
3780
  if (a === null || a < t[0].time) {
3379
3781
  this.fitContent();
3380
3782
  return;
3381
3783
  }
3382
- let o = N(a, t), s = Math.min(n, e === "YTD" ? Math.ceil(o) : Math.floor(o) + 1);
3784
+ let o = M(a, t), s = Math.min(n, e === "YTD" ? Math.ceil(o) : Math.floor(o) + 1);
3383
3785
  this.viewport.zoomToBarRange(s, n + this.viewport.getRightMargin()), this.viewport.scrollToEnd(), this.updateViewportAndRender();
3384
3786
  }
3385
3787
  scrollToEnd() {
@@ -3404,7 +3806,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3404
3806
  setVisibleRange(e, t) {
3405
3807
  let n = this.getDisplayData();
3406
3808
  if (n.length === 0) return;
3407
- let r = N(Math.min(e, t), n), i = N(Math.max(e, t), n);
3809
+ let r = M(Math.min(e, t), n), i = M(Math.max(e, t), n);
3408
3810
  this.viewport.zoomToBarRange(r, i), this.updateViewportAndRender();
3409
3811
  }
3410
3812
  suspend() {
@@ -3544,13 +3946,13 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3544
3946
  }), this.engine.requestRender(r.Background);
3545
3947
  }
3546
3948
  setAutoScale(e) {
3547
- this.options.autoScale = e, this.defaultAutoScale = e, !e && this.series.length() > 0 && (this.seriesArriving = !1), this.updateViewportAndRender();
3949
+ this.priceFit.setAuto(e, this.series.length() > 0), this.updateViewportAndRender();
3548
3950
  }
3549
3951
  holdPriceScale() {
3550
- this.options.autoScale = !1, this.priceFitPending = !1;
3952
+ this.priceFit.hold();
3551
3953
  }
3552
3954
  isAutoScale() {
3553
- return this.options.autoScale !== !1;
3955
+ return this.priceFit.isAuto();
3554
3956
  }
3555
3957
  setCrosshairMode(e) {
3556
3958
  this.crosshairHandler.setMode(e), this.engine.requestRender(r.Hover);
@@ -3562,7 +3964,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3562
3964
  e ? this.crosshairHandler.onPointerMove(e) : this.crosshairHandler.onPointerLeave(), this.engine.requestRender(r.Hover);
3563
3965
  }
3564
3966
  setCrosshairTime(e) {
3565
- let t = this.getDisplayData(), n = e === null || t.length === 0 ? null : Math.floor(N(e, t));
3967
+ let t = this.getDisplayData(), n = e === null || t.length === 0 ? null : Math.floor(M(e, t));
3566
3968
  n !== this.crosshairHandler.getSyncedSlot() && (this.crosshairHandler.setSyncedSlot(n), this.showSyncedBar(n), this.engine.requestRender(r.Hover));
3567
3969
  }
3568
3970
  showSyncedBar(e) {
@@ -3572,7 +3974,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3572
3974
  }
3573
3975
  let t = this.crosshairSeries(), n = e >= 0 && e < t.length ? t[e] : void 0, r = n && e > 0 ? t[e - 1] : void 0;
3574
3976
  this.crosshairHandler.getPosition() || this.chartLegend.setHoverBar(n ?? null, r ?? null);
3575
- let i = n ? A(t)[e]?.time ?? n.time : void 0;
3977
+ let i = n ? At(t)[e]?.time ?? n.time : void 0;
3576
3978
  this.eventBus.emit("crosshairSync", {
3577
3979
  barIndex: e,
3578
3980
  ...n ? { bar: n } : {},
@@ -3651,7 +4053,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3651
4053
  return this.periodLevels.getPeriod();
3652
4054
  }
3653
4055
  setTimeZone(e) {
3654
- Rr(e), this.timeZoneSetting = e, this.applyTimeZone();
4056
+ si(e), this.timeZoneSetting = e, this.applyTimeZone();
3655
4057
  }
3656
4058
  getTimeZone() {
3657
4059
  return this.timeZoneSetting;
@@ -3660,7 +4062,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3660
4062
  return this.displayTz;
3661
4063
  }
3662
4064
  getExchangeTimeZone() {
3663
- return [C(this.symbolInfo), this.marketConfig?.timeZone].find((e) => e && y(e)) ?? null;
4065
+ return [w(this.symbolInfo), this.marketConfig?.timeZone].find((e) => e && y(e)) ?? null;
3664
4066
  }
3665
4067
  setTimezone(e) {
3666
4068
  this.setTimeZone(e);
@@ -3702,7 +4104,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3702
4104
  }
3703
4105
  spokenBarTime(e) {
3704
4106
  let t = this.getDisplayData(), n = e * u(t), r = this.numberLocale || "en-US";
3705
- return d(t) === !0 ? fe(r, { dateStyle: "medium" }, l(n, this.displayTz, this.getExchangeTimeZone()))(n) : fe(r, {
4107
+ return d(t) === !0 ? de(r, { dateStyle: "medium" }, l(n, this.displayTz, this.getExchangeTimeZone()))(n) : de(r, {
3706
4108
  dateStyle: "medium",
3707
4109
  timeStyle: "short"
3708
4110
  }, this.displayTz)(n);
@@ -3715,18 +4117,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3715
4117
  this.studyZoneHeld = !1, this.endStudyZoneWait(), this.useSymbolInfo(e);
3716
4118
  }
3717
4119
  useSymbolInfo(e) {
3718
- let t = e && this.symbolInfo?.symbol === e.symbol ? C(this.symbolInfo) : void 0;
3719
- this.symbolInfo = e ? zr({
4120
+ let t = e && this.symbolInfo?.symbol === e.symbol ? w(this.symbolInfo) : void 0;
4121
+ this.symbolInfo = e ? ci({
3720
4122
  ...e,
3721
4123
  sessions: e.sessions?.map((e) => ({ ...e }))
3722
4124
  }, t) : null, this.chartLegend.setExchange(this.symbolInfo?.exchange ?? ""), this.engine.requestRender(r.Hover), this.priceAxis.setPriceTick(this.symbolInfo?.minTick ?? null), this.marketConfig?.pricePrecision === void 0 && this.applyPricePrecision(this.symbolInfo?.pricePrecision ?? null);
3723
4125
  let n = (this.symbolInfo?.sessions ?? []).flatMap((e) => {
3724
- let t = S(e.start), n = S(e.end);
4126
+ let t = C(e.start), n = C(e.end);
3725
4127
  return t === null || n === null ? [] : [{
3726
4128
  startMinute: t,
3727
4129
  endMinute: n
3728
4130
  }];
3729
- }), i = C(this.symbolInfo);
4131
+ }), i = w(this.symbolInfo);
3730
4132
  this.sessionShading.replaceConfig(n.length > 0 && i && y(i) ? {
3731
4133
  timeZone: i,
3732
4134
  windows: n,
@@ -3741,15 +4143,15 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3741
4143
  if (!e || typeof e != "object") return;
3742
4144
  let t = this.currentSymbol, n = (e) => !e || e.toUpperCase() === t.toUpperCase();
3743
4145
  if (!n(e.symbol)) return;
3744
- let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = zr({
4146
+ let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = ci({
3745
4147
  ...r,
3746
4148
  ...e,
3747
4149
  symbol: e.symbol || r?.symbol || t
3748
- }, C(r));
4150
+ }, w(r));
3749
4151
  r && JSON.stringify(i) === JSON.stringify(r) || (this.symbolInfoSeq++, this.setSymbolInfo(i));
3750
4152
  }
3751
4153
  resolveStreamSymbol(e, t) {
3752
- let n = P(e), r = n.resolveSymbol?.bind(n);
4154
+ let n = N(e), r = n.resolveSymbol?.bind(n);
3753
4155
  if (this.symbolInfo && this.symbolInfo.symbol !== t ? (r ? this.holdStudyZone() : this.studyZoneHeld = !1, this.useSymbolInfo(null)) : r && this.studyZoneHeld && this.holdStudyZone(), !r) {
3754
4156
  this.releaseStudyZone();
3755
4157
  return;
@@ -3780,7 +4182,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3780
4182
  return this.sessionShading.isVisible();
3781
4183
  }
3782
4184
  setSessionShadingConfig(e) {
3783
- this.hostSessionHours = It(this.hostSessionHours, e), this.sessionShading.replaceConfig(this.hostSessionHours), this.engine.requestRender(r.Background);
4185
+ this.hostSessionHours = Lt(this.hostSessionHours, e), this.sessionShading.replaceConfig(this.hostSessionHours), this.engine.requestRender(r.Background);
3784
4186
  }
3785
4187
  setTooltipVisible(e) {
3786
4188
  e || this.crosshairTooltip.hide();
@@ -3802,11 +4204,11 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3802
4204
  return this.waitForGpu(null), e === "canvas" ? (this.applyRenderer(null), "canvas") : this.engine.getGpu() ? "webgl" : this.takeGpu(e, t, !0);
3803
4205
  }
3804
4206
  async takeGpu(e, t, n) {
3805
- let { gpu: r, reason: i } = await Ft(e);
3806
- return t !== this.rendererToken || this.disposed ? (r?.destroy(), this.getRenderer()) : i === "limit" ? Mt() > 0 ? this.takeGpu(e, t, n) : (this.waitForGpu(() => void this.takeGpu(e, t, !1)), n && this.applyRenderer(null, "limit"), this.getRenderer()) : ((r || n) && this.applyRenderer(r, i), this.getRenderer());
4207
+ let { gpu: r, reason: i } = await It(e);
4208
+ return t !== this.rendererToken || this.disposed ? (r?.destroy(), this.getRenderer()) : i === "limit" ? Nt() > 0 ? this.takeGpu(e, t, n) : (this.waitForGpu(() => void this.takeGpu(e, t, !1)), n && this.applyRenderer(null, "limit"), this.getRenderer()) : ((r || n) && this.applyRenderer(r, i), this.getRenderer());
3807
4209
  }
3808
4210
  waitForGpu(e) {
3809
- this.stopWaitingForGpu?.(), this.stopWaitingForGpu = e ? Jt(e) : null;
4211
+ this.stopWaitingForGpu?.(), this.stopWaitingForGpu = e ? Yt(e) : null;
3810
4212
  }
3811
4213
  getRenderer() {
3812
4214
  return this.engine.getGpu() ? "webgl" : "canvas";
@@ -3985,24 +4387,24 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
3985
4387
  let t = this.replaySession ? this.replayOffset : 0;
3986
4388
  if (!this.replaySession) {
3987
4389
  if (this.series.length() === 0) return;
3988
- this.series.beginReplay(), this.replaySession = di(this.currentSymbol);
4390
+ this.series.beginReplay(), this.replaySession = Ti(this.currentSymbol);
3989
4391
  }
3990
4392
  let n = this.replaySession, { steps: r, startTime: i, hideHistory: a, revealMarks: o, step: s, ...c } = e ?? {};
3991
4393
  c.animate = c.animate === !0;
3992
4394
  let l = this.series.inHoursShown(this.series.liveBars()), u = t > 0 && i === void 0 && a !== !1, d = c.startIndex;
3993
- i !== void 0 && d === void 0 ? d = Y(l, i) : u && d !== void 0 && (d += t);
4395
+ i !== void 0 && d === void 0 ? d = X(l, i) : u && d !== void 0 && (d += t);
3994
4396
  let f = u ? t : a && d !== void 0 && d > 0 ? Math.min(Math.floor(d), l.length - 1) : 0, p = f > 0 ? l.slice(f) : l;
3995
4397
  d !== void 0 && (c.startIndex = d - f), n.windowTime = f > 0 ? p[0]?.time ?? null : null, n.steps = r ?? null, n.stepsSymbol = this.currentSymbol, n.until = null, n.animate = c.animate, n.step = c.animate ? s ?? null : null, this.replayRevealMarks = o !== !1, this.useReplayLoader(n, !0);
3996
4398
  let m = r ? this.replayStepsOver(n, p, !0) : null;
3997
- this.options.autoScale = !0, this.buildReplay(p, m, f);
4399
+ this.priceFit.resume(), this.buildReplay(p, m, f);
3998
4400
  let h = this.replayStepsSeries;
3999
- h && c.startIndex !== void 0 && (c.startIndex = bi(h, p, c.startIndex));
4401
+ h && c.startIndex !== void 0 && (c.startIndex = Fi(h, p, c.startIndex));
4000
4402
  let g = h ?? p, _ = g[Math.max(0, Math.min(Math.floor(Number(c.startIndex ?? 0)) || 0, g.length - 1))];
4001
4403
  this.revealReplayMarks(this.replayRevealMarks ? _?.time ?? null : null), n.held && (n.held.state = c.paused ? "paused" : "playing", c.paused = !0), !c.paused && c.startIndex !== void 0 && c.startIndex >= 1 && this.replaySeek(c.startIndex - 1), this.replayManager.play(c);
4002
4404
  }
4003
4405
  buildReplay(e, t, n) {
4004
4406
  let r = this.replaySession?.animate === !0, i = r ? null : t;
4005
- this.replayPieces = r && t ? Ci(t, e) : null, this.replayForming = null, this.replayOffset = n, this.replayStepsSeries = i, this.replayCoarse = e;
4407
+ this.replayPieces = r && t ? Ri(t, e) : null, this.replayForming = null, this.replayOffset = n, this.replayStepsSeries = i, this.replayCoarse = e;
4006
4408
  let a = this.replayRestarting;
4007
4409
  this.replayRestarting = !0;
4008
4410
  try {
@@ -4016,7 +4418,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4016
4418
  let n = t, a = e[t];
4017
4419
  if (i) {
4018
4420
  let r = i[t];
4019
- n = Q(e, r.time), c = c !== null && s === t - 1 && n === o - 1 && c ? Ti(c, r) : xi(e[n], i, t), a = Si(i, e, t, n) ? e[n] : c;
4421
+ n = Q(e, r.time), c = c !== null && s === t - 1 && n === o - 1 && c ? Bi(c, r) : Ii(e[n], i, t), a = Li(i, e, t, n) ? e[n] : c;
4020
4422
  }
4021
4423
  let u = this.replayForming;
4022
4424
  this.replayForming = null, s = t;
@@ -4028,7 +4430,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4028
4430
  } else this.series.showReplayed([...e.slice(0, n), a]), this.recalcIndicators(this.series.bars());
4029
4431
  o = d, this.replayCause === "older" && (this.viewport.prependBars(d - h), m = !1), this.currentPriceLine.setPrice(a.close, n > 0 ? e[n - 1].close : void 0), this.crosshairHandler.setData(this.series.bars());
4030
4432
  let g = l[t + 1]?.time ?? l[t].time + (t > 0 ? l[t].time - l[t - 1].time : 1);
4031
- this.replaySession && (this.replaySession.until = g), this.replayRevealMarks && this.revealReplayMarks(g), this.displayDataCache = null, this.reshapeMemo.clear(), this.updateViewportAndRender(m), r ? this.feedReplayForming(e, t, u?.index === t ? u.path : this.replayPathOf(e, t), 1) : this.feedReplaySteps(l, t);
4433
+ this.replaySession && (this.replaySession.until = g), this.replayRevealMarks && this.revealReplayMarks(g), this.display.reset(), this.updateViewportAndRender(m), r ? this.feedReplayForming(e, t, u?.index === t ? u.path : this.replayPathOf(e, t), 1) : this.feedReplaySteps(l, t);
4032
4434
  let _ = this.replayCause === null ? p ? "play" : "seek" : "series";
4033
4435
  this.eventBus.emit("replayStep", {
4034
4436
  barIndex: n,
@@ -4040,7 +4442,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4040
4442
  });
4041
4443
  }), r && (this.replayPhaseUnsub = this.replayManager.on("phase", ({ index: t, fraction: n }) => {
4042
4444
  if (!e[t] || this.series.length() !== o || o !== t && o !== t + 1) return;
4043
- let r = this.replayForming?.index === t ? this.replayForming.path : this.replayPathOf(e, t), i = wi() ? jr(r, n) : n, a = o === t, s = a && this.autoScrollOnNewBar && this.viewport.isAtEnd(), c = Ar(r, i);
4445
+ let r = this.replayForming?.index === t ? this.replayForming.path : this.replayPathOf(e, t), i = zi() ? ti(r, n) : n, a = o === t, s = a && this.autoScrollOnNewBar && this.viewport.isAtEnd(), c = ei(r, i);
4044
4446
  a ? this.series.appendReplayed(c) : this.series.updateReplayed(c), o = t + 1, this.replayForming = {
4045
4447
  index: t,
4046
4448
  path: r
@@ -4050,30 +4452,30 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4050
4452
  drawFormingBar(e, t, n, r) {
4051
4453
  this.currentPriceLine.setPrice(e.close, t);
4052
4454
  let i = this.series.bars();
4053
- if (this.recalcIndicatorsFrom(i, i.length - 1), (n || !si.has(this.options.chartType)) && (this.displayDataCache = null), !n) {
4455
+ if (this.recalcIndicatorsFrom(i, i.length - 1), !n) {
4054
4456
  this.scheduleRender();
4055
4457
  return;
4056
4458
  }
4057
- this.crosshairHandler.setData(i), this.reshapeMemo.clear(), this.updateViewportAndRender(r);
4459
+ this.crosshairHandler.setData(i), this.display.reset(), this.updateViewportAndRender(r);
4058
4460
  }
4059
4461
  replayPathOf(e, t) {
4060
4462
  let n = e[t];
4061
- return Tr(n, this.replayPieces?.get(n.time) ?? this.replayLoader?.loader.piecesOf(n.time) ?? []);
4463
+ return Yr(n, this.replayPieces?.get(n.time) ?? this.replayLoader?.loader.piecesOf(n.time) ?? []);
4062
4464
  }
4063
4465
  loadReplaySteps(e, t) {
4064
4466
  let n = this.replayLoader?.loader;
4065
4467
  if (!n) return;
4066
4468
  n.evictBefore(e[t].time);
4067
4469
  let r = this.replayManager.getStepMs();
4068
- n.ensure(e, t, Number.isFinite(r) && r > 0 ? Math.ceil(oi / r) : 1);
4470
+ n.ensure(e, t, Number.isFinite(r) && r > 0 ? Math.ceil(xi / r) : 1);
4069
4471
  }
4070
4472
  useReplayLoader(e, t) {
4071
- let n = this.streamAdapter, r = this.streamTimeframe, i = e.step && n && r !== null ? Pr(e.step, r, (e) => j(n, e)) : null, a = `${this.currentSymbol}|${r}|${i}`;
4473
+ let n = this.streamAdapter, r = this.streamTimeframe, i = e.step && n && r !== null ? ii(e.step, r, (e) => A(n, e)) : null, a = `${this.currentSymbol}|${r}|${i}`;
4072
4474
  if (!t && this.replayLoader?.key === a || (this.replayLoader?.loader.dispose(), this.replayLoader = null, !i || !n || r === null)) return;
4073
- let o = P(n), s = o.fetchHistoryBefore, c = this.currentSymbol, l = w(r), u = new vr({
4475
+ let o = N(n), s = o.fetchHistoryBefore, c = this.currentSymbol, l = T(r), u = new Hr({
4074
4476
  source: s ? (e, t) => s.call(o, c, i, e, t) : null,
4075
4477
  step: i,
4076
- ratio: Math.max(1, Math.round(l / w(i))),
4478
+ ratio: Math.max(1, Math.round(l / T(i))),
4077
4479
  barMs: l,
4078
4480
  keep: (e) => this.series.inHoursShown(e),
4079
4481
  report: (e) => this.eventBus.emit("replayStepsLoad", e)
@@ -4088,18 +4490,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4088
4490
  if (!i || !a?.setMarkPrice || !o) return;
4089
4491
  let s = i.fedTime;
4090
4492
  if (s === null) {
4091
- i.fedTime = o.time, i.fedFraction = r, this.feedReplayPrice(Ar(n, r).close, o.time);
4493
+ i.fedTime = o.time, i.fedFraction = r, this.feedReplayPrice(ei(n, r).close, o.time);
4092
4494
  return;
4093
4495
  }
4094
4496
  if (o.time < s || o.time === s && r <= i.fedFraction) return;
4095
4497
  let c = [];
4096
4498
  if (o.time > s) {
4097
- let a = Y(e, s);
4098
- e[a]?.time === s && i.fedFraction < 1 && c.push(...q(this.replayPathOf(e, a), i.fedFraction, 1));
4099
- let o = e.slice(X(e, s), t), l = Math.ceil(o.length / _i);
4100
- for (let e = 0; e < o.length; e += l) c.push(...vi(o.slice(e, e + l)));
4101
- c.push(...q(n, -1, r));
4102
- } else c.push(...q(n, i.fedFraction, r));
4499
+ let a = X(e, s);
4500
+ e[a]?.time === s && i.fedFraction < 1 && c.push(...J(this.replayPathOf(e, a), i.fedFraction, 1));
4501
+ let o = e.slice(Z(e, s), t), l = Math.ceil(o.length / ji);
4502
+ for (let e = 0; e < o.length; e += l) c.push(...Mi(o.slice(e, e + l)));
4503
+ c.push(...J(n, -1, r));
4504
+ } else c.push(...J(n, i.fedFraction, r));
4103
4505
  i.fedTime = o.time, i.fedFraction = r;
4104
4506
  for (let [e, t] of c) a.setMarkPrice(e, t);
4105
4507
  let l = c[c.length - 1]?.[0];
@@ -4114,9 +4516,9 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4114
4516
  if (!t) return;
4115
4517
  let n = this.series.inHoursShown(this.series.liveBars());
4116
4518
  if (n.length === 0) return;
4117
- let r = t.windowTime === null ? 0 : Math.min(Y(n, t.windowTime), n.length - 1), i = r > 0 ? n.slice(r) : n;
4519
+ let r = t.windowTime === null ? 0 : Math.min(X(n, t.windowTime), n.length - 1), i = r > 0 ? n.slice(r) : n;
4118
4520
  this.useReplayLoader(t, !1);
4119
- let a = this.replayStepsOver(t, i), o = t.animate ? null : a, s = t.until === null ? 0 : mi(o ?? i, t.until);
4521
+ let a = this.replayStepsOver(t, i), o = t.animate ? null : a, s = t.until === null ? 0 : Oi(o ?? i, t.until);
4120
4522
  if (s < 0 && this.canPageBackForReplay(t)) {
4121
4523
  this.holdReplay(), t.held && t.held.pagesBack++, queueMicrotask(() => void this.pageBackForReplay(t));
4122
4524
  return;
@@ -4124,7 +4526,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4124
4526
  let c = this.getReplayState(), l = t.held !== null && (e === "hours" || e === "bar"), u = t.held?.state ?? c;
4125
4527
  l || (t.held = null), t.symbol = this.currentSymbol;
4126
4528
  let d = this.replayManager.remainingMs();
4127
- this.clearBarHolders(), t.animate && pi(t, this.replayCoarse, i);
4529
+ this.clearBarHolders(), t.animate && Di(t, this.replayCoarse, i);
4128
4530
  let f = this.replayRestarting;
4129
4531
  this.replayRestarting = !0, this.replayCause = e === "older" ? "older" : "series";
4130
4532
  try {
@@ -4147,14 +4549,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4147
4549
  }
4148
4550
  replayStepsOver(e, t, n = !1) {
4149
4551
  if (!e.steps || e.stepsSymbol !== this.currentSymbol) return null;
4150
- let r = yi(this.series.inHoursShown(e.steps), t);
4151
- return r && (n || gi(r, t)) ? r : null;
4552
+ let r = Pi(this.series.inHoursShown(e.steps), t);
4553
+ return r && (n || Ai(r, t)) ? r : null;
4152
4554
  }
4153
4555
  canPageBackForReplay(e) {
4154
- return this.history.hasLoader() && this.history.hasMore() && (e.held?.pagesBack ?? 0) < ci;
4556
+ return this.history.hasLoader() && this.history.hasMore() && (e.held?.pagesBack ?? 0) < Si;
4155
4557
  }
4156
4558
  async pageBackForReplay(e) {
4157
- this.replaySession !== e || !e.held || await this.history.loadMore() > 0 || this.replaySession !== e || !e.held || (e.held.pagesBack = ci, this.rebaseReplay("older"));
4559
+ this.replaySession !== e || !e.held || await this.history.loadMore() > 0 || this.replaySession !== e || !e.held || (e.held.pagesBack = Si, this.rebaseReplay("older"));
4158
4560
  }
4159
4561
  holdReplay() {
4160
4562
  let e = this.replaySession;
@@ -4187,7 +4589,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4187
4589
  this.signalMarkerManager.setRevealUntil(e, t), this.tradeZoneManager.setRevealUntil(e, t);
4188
4590
  }
4189
4591
  replaySeekToTime(e) {
4190
- !this.replaySession || !this.replayCoarse || this.replaySeek(Math.max(0, mi(this.replayStepsSeries ?? this.replayCoarse, e)));
4592
+ !this.replaySession || !this.replayCoarse || this.replaySeek(Math.max(0, Oi(this.replayStepsSeries ?? this.replayCoarse, e)));
4191
4593
  }
4192
4594
  feedReplayPrice(e, t) {
4193
4595
  let n = this.executionAdapter;
@@ -4207,10 +4609,10 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4207
4609
  return;
4208
4610
  }
4209
4611
  if (i.time <= n.fedTime) return;
4210
- let a = e.slice(X(e, n.fedTime), t + 1);
4612
+ let a = e.slice(Z(e, n.fedTime), t + 1);
4211
4613
  n.fedTime = i.time;
4212
- let o = Math.ceil(a.length / _i);
4213
- for (let e = 0; e < a.length; e += o) for (let [t, n] of vi(a.slice(e, e + o))) r.setMarkPrice(t, n);
4614
+ let o = Math.ceil(a.length / ji);
4615
+ for (let e = 0; e < a.length; e += o) for (let [t, n] of Mi(a.slice(e, e + o))) r.setMarkPrice(t, n);
4214
4616
  this.tradingManager.setCurrentPrice(i.close);
4215
4617
  }
4216
4618
  getReplayBarIndex() {
@@ -4221,7 +4623,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4221
4623
  }
4222
4624
  replaySeekToBar(e) {
4223
4625
  let t = this.replayStepsSeries;
4224
- this.replaySeek(t && this.replayCoarse ? bi(t, this.replayCoarse, e) : e);
4626
+ this.replaySeek(t && this.replayCoarse ? Fi(t, this.replayCoarse, e) : e);
4225
4627
  }
4226
4628
  replayPause() {
4227
4629
  this.setHeldState("paused") || this.replayManager.pause();
@@ -4262,7 +4664,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4262
4664
  let { x: r, y: c } = this.drawingManager.anchorPoint(t.type, e, n);
4263
4665
  i = Math.min(i, r), a = Math.max(a, r), o = Math.min(o, c), s = Math.max(s, c);
4264
4666
  }
4265
- return Yr.has(t.type) ? [i, a] = [r.x, r.x + r.width] : t.type === "horizontalRay" && (a = r.x + r.width), Xr.has(t.type) && ([o, s] = [r.y, r.y + r.height]), i = Math.max(i, r.x), a = Math.min(a, r.x + r.width), o = Math.max(o, r.y), s = Math.min(s, r.y + r.height), i <= a && o <= s ? {
4667
+ return mi.has(t.type) ? [i, a] = [r.x, r.x + r.width] : t.type === "horizontalRay" && (a = r.x + r.width), hi.has(t.type) && ([o, s] = [r.y, r.y + r.height]), i = Math.max(i, r.x), a = Math.min(a, r.x + r.width), o = Math.max(o, r.y), s = Math.min(s, r.y + r.height), i <= a && o <= s ? {
4266
4668
  x: i,
4267
4669
  y: o,
4268
4670
  width: a - i,
@@ -4298,7 +4700,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4298
4700
  };
4299
4701
  }
4300
4702
  captureSnapshot() {
4301
- return T.capture({
4703
+ return E.capture({
4302
4704
  getDrawings: () => [...this.getDrawings().filter((e) => e.paneId === void 0 || this.layoutManager.getPanels().some((t) => t.id === e.paneId)), ...this.keptPaneDrawings],
4303
4705
  getTheme: () => this.themeManager.getBaseTheme(),
4304
4706
  getAlerts: () => this.getAlerts(),
@@ -4311,26 +4713,23 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4311
4713
  });
4312
4714
  }
4313
4715
  restoreIndicators(e, t) {
4314
- let n = Qr(e), r = /* @__PURE__ */ new Map();
4716
+ let n = er(e), r = /* @__PURE__ */ new Map();
4315
4717
  this.unrestoredIndicators = [];
4316
4718
  let i = new Set(this.indicatorEngine.getAvailableIndicators().map((e) => e.id)), a = [], o = /* @__PURE__ */ new Set();
4317
4719
  if (t) {
4318
- let e = new Map(n.map((e) => [e.instanceId, e])), t = this.getIndicatorSetup();
4319
- for (let n of t) {
4320
- let t = e.get(n.instanceId);
4321
- t && $r(n, t) && o.add(n.instanceId);
4720
+ let e = this.getIndicatorSetup();
4721
+ for (let t of nr(e, n)) o.add(t);
4722
+ for (let t of e) o.has(t.instanceId) || this.removeIndicator(t.instanceId);
4723
+ let t = new Map(e.map((e) => [e.instanceId, e.pane]));
4724
+ for (let e = !0; e;) {
4725
+ e = !1;
4726
+ for (let n of [...o]) {
4727
+ let r = t.get(n);
4728
+ this.indicatorEngine.getIndicatorConfig(n) && !(r && !o.has(r)) || (this.indicatorEngine.getIndicatorConfig(n) && this.removeIndicator(n), o.delete(n), e = !0);
4729
+ }
4322
4730
  }
4323
- for (let e of t) o.has(e.instanceId) || this.removeIndicator(e.instanceId);
4324
- for (let e of [...o]) this.indicatorEngine.getIndicatorConfig(e) || o.delete(e);
4325
4731
  } else for (let e of this.indicatorEngine.getActiveIndicators()) this.removeIndicator(e.instanceId);
4326
- let s = (e) => {
4327
- let t = { ...e };
4328
- for (let [e, n] of Object.entries(t)) {
4329
- let i = x(n), a = i && r.get(i.instanceId);
4330
- a && (t[e] = v(a, i.key));
4331
- }
4332
- return t;
4333
- };
4732
+ let s = (e) => ir(e, r);
4334
4733
  for (let e of n) {
4335
4734
  let n = null;
4336
4735
  if (o.has(e.instanceId)) {
@@ -4363,7 +4762,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4363
4762
  }
4364
4763
  r.set(e.instanceId, n), a.push([e, n]), this.restoreLooks(n, e);
4365
4764
  }
4366
- return this.restorePanes(a), this.updateViewportAndRender(), r;
4765
+ return this.indicatorEngine.orderIndicators(e.flatMap((e) => r.get(e.instanceId) ?? [])), $n(this.layoutManager, a), this.updateViewportAndRender(), r;
4367
4766
  }
4368
4767
  restoreLooks(e, t) {
4369
4768
  let { plots: n, ...r } = this.indicatorEngine.getIndicatorStyle(e) ?? {
@@ -4380,50 +4779,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4380
4779
  let s = t.levels ?? null;
4381
4780
  JSON.stringify(s) !== JSON.stringify(o?.levels ?? null) && this.setIndicatorLevels(e, s);
4382
4781
  let c = t.intervals ?? null;
4383
- JSON.stringify(c) !== JSON.stringify(o?.intervals ?? null) && this.setIndicatorIntervalsNow(e, c), this.setPaneStyleNow(e, t.paneStyle ? se(t.paneStyle) : null);
4384
- }
4385
- restorePanes(e) {
4386
- for (let [t, n] of e) t.paneSize !== void 0 && this.layoutManager.setPanelSize(n, t.paneSize), (t.paneSize !== void 0 || t.paneCollapsed) && this.layoutManager.setPanelCollapsed(n, !!t.paneCollapsed), t.paneSize !== void 0 && this.layoutManager.setPanelScale(n, {
4387
- log: !!t.paneLog,
4388
- invert: !!t.paneInvert,
4389
- percent: !!t.panePercent
4390
- });
4391
- let t = e.filter(([e]) => e.paneOrder !== void 0).sort(([e], [t]) => (e.paneOrder ?? 0) - (t.paneOrder ?? 0)).map(([, e]) => e);
4392
- t.length > 1 && this.layoutManager.orderPanels(t);
4393
- let n = e.find(([e]) => e.paneMaximized);
4394
- this.layoutManager.setMaximizedPanel(n ? n[1] : null);
4782
+ JSON.stringify(c) !== JSON.stringify(o?.intervals ?? null) && this.setIndicatorIntervalsNow(e, c), this.setPaneStyleNow(e, t.paneStyle ? oe(t.paneStyle) : null);
4395
4783
  }
4396
4784
  getIndicatorSetup() {
4397
- let e = this.layoutManager.getPanels(), t = this.layoutManager.getMaximizedPanel();
4398
- return [...this.indicatorEngine.getActiveIndicators().map((n) => {
4399
- let r = e.find((e) => e.id === n.instanceId), i = this.indicatorEngine.getIndicatorConfig(n.instanceId);
4400
- return {
4401
- id: n.id,
4402
- instanceId: n.instanceId,
4403
- params: { ...n.params },
4404
- position: r?.position,
4405
- style: this.indicatorEngine.getIndicatorStyle(n.instanceId) ?? void 0,
4406
- visible: n.visible,
4407
- levels: i?.levels?.slice(),
4408
- pane: n.pane,
4409
- scale: i?.scale,
4410
- ...i?.intervals ? { intervals: this.indicatorEngine.getIntervals(n.instanceId) ?? void 0 } : {},
4411
- ...r && this.paneStyles.has(n.instanceId) ? { paneStyle: { ...this.paneStyles.get(n.instanceId) } } : {},
4412
- ...r ? {
4413
- paneSize: r.size,
4414
- paneOrder: e.indexOf(r),
4415
- ...r.collapsed ? { paneCollapsed: !0 } : {},
4416
- ...t === n.instanceId ? { paneMaximized: !0 } : {},
4417
- ...r.logScale ? { paneLog: !0 } : {},
4418
- ...r.invertScale ? { paneInvert: !0 } : {},
4419
- ...r.percentScale ? { panePercent: !0 } : {}
4420
- } : {}
4421
- };
4422
- }), ...this.unrestoredIndicators];
4785
+ return [...Qn(this.indicatorEngine, this.layoutManager, (e) => this.panes.style(e) ?? null), ...this.unrestoredIndicators];
4423
4786
  }
4424
4787
  applyIndicatorSetup(e) {
4425
- this.features.indicators && this.recordIndicators(void 0, () => {
4426
- let t = new Map(this.indicatorEngine.getActiveIndicators().map((e) => [e.instanceId, e.id])), n = this.withoutIndicatorHistory(() => this.restoreIndicators(e, !1));
4788
+ this.features.indicators && this.indicatorHistory.record(void 0, () => {
4789
+ let t = new Map(this.indicatorEngine.getActiveIndicators().map((e) => [e.instanceId, e.id])), n = this.indicatorHistory.quietly(() => this.restoreIndicators(e, !1));
4427
4790
  this.followIndicatorAlerts(t, [...n.values()]), this.markStateChanged();
4428
4791
  });
4429
4792
  }
@@ -4451,117 +4814,49 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4451
4814
  }
4452
4815
  }
4453
4816
  beginIndicatorEdit(e) {
4454
- this.endIndicatorEdit(), this.features.drawingUndoRedo && (this.indicatorEdit = {
4455
- subject: e,
4456
- before: this.getIndicatorSetup()
4457
- }, this.indicatorHistoryDepth++);
4817
+ this.indicatorHistory.begin(e);
4458
4818
  }
4459
4819
  endIndicatorEdit() {
4460
- let e = this.indicatorEdit;
4461
- if (!e) return;
4462
- this.indicatorEdit = null, this.indicatorHistoryDepth--;
4463
- let t = this.getIndicatorSetup();
4464
- JSON.stringify(t) !== JSON.stringify(e.before) && this.undoRedoManager.push({
4465
- type: "indicators",
4466
- before: null,
4467
- after: null,
4468
- indicators: {
4469
- before: e.before,
4470
- after: t,
4471
- subject: e.subject,
4472
- at: performance.now()
4473
- }
4474
- });
4475
- }
4476
- withoutIndicatorHistory(e) {
4477
- this.indicatorHistoryDepth++;
4478
- try {
4479
- return e();
4480
- } finally {
4481
- this.indicatorHistoryDepth--;
4482
- }
4483
- }
4484
- recordIndicators(e, t) {
4485
- if (this.indicatorHistoryDepth > 0 || !this.features.drawingUndoRedo) return t();
4486
- let n = this.getIndicatorSetup(), r = [], i = this.paneRenames;
4487
- this.paneRenames = r;
4488
- let a;
4489
- try {
4490
- a = this.withoutIndicatorHistory(t);
4491
- } finally {
4492
- this.paneRenames = i;
4493
- }
4494
- let o = this.getIndicatorSetup();
4495
- if (JSON.stringify(n) === JSON.stringify(o)) return a;
4496
- let s = performance.now(), c = this.undoRedoManager.last(), l = e !== void 0 && c?.type === "indicators" && c.indicators?.subject === e && s - (c.indicators.at ?? 0) < Hr && JSON.stringify(c.indicators.after) === JSON.stringify(n), u = {
4497
- type: "indicators",
4498
- before: null,
4499
- after: null
4500
- };
4501
- return l && c?.indicators ? JSON.stringify(c.indicators.before) === JSON.stringify(o) ? this.undoRedoManager.dropLast() : this.undoRedoManager.replaceLast({
4502
- ...u,
4503
- indicators: {
4504
- ...c.indicators,
4505
- after: o,
4506
- at: s,
4507
- ...Wr([...c.indicators.renames ?? [], ...r])
4508
- }
4509
- }) : this.undoRedoManager.push({
4510
- ...u,
4511
- indicators: {
4512
- before: n,
4513
- after: o,
4514
- subject: e,
4515
- at: s,
4516
- ...Wr(r)
4517
- }
4518
- }), a;
4820
+ this.indicatorHistory.end();
4519
4821
  }
4520
4822
  applyIndicatorStep(e, t) {
4521
4823
  let n = e.indicators;
4522
4824
  if (!n) return;
4523
- this.withoutIndicatorHistory(() => this.restoreIndicators(t === "undo" ? n.before : n.after, !0));
4825
+ this.replayingIndicatorStep = !0;
4826
+ try {
4827
+ this.indicatorHistory.quietly(() => this.restoreIndicators(t === "undo" ? n.before : n.after, !0));
4828
+ } finally {
4829
+ this.replayingIndicatorStep = !1;
4830
+ }
4524
4831
  let r = n.renames ?? [], i = t === "undo" ? [...r].reverse().map(([e, t]) => [t, e]) : r;
4525
4832
  for (let [e, t] of i) this.drawingManager.renamePanes(new Map([[e, t]]));
4526
4833
  this.markStateChanged();
4527
4834
  }
4528
4835
  keptPaneDrawings = [];
4836
+ replayingIndicatorStep = !1;
4529
4837
  takesDrawing(e, t) {
4530
- return this.layoutManager.getPanels().some((t) => t.id === e) ? !this.drawingManager.getDescriptor(t)?.priceOnly : !1;
4838
+ return ur(this.layoutManager.getPanels(), e, !!this.drawingManager.getDescriptor(t)?.priceOnly);
4531
4839
  }
4532
- paneRenames = null;
4533
4840
  renamePane(e, t) {
4534
- this.layoutManager.renamePanel(e, t), this.drawingManager.renamePanes(new Map([[e, t]])), this.paneRenames?.push([e, t]);
4841
+ this.layoutManager.renamePanel(e, t), this.replayingIndicatorStep || this.drawingManager.renamePanes(new Map([[e, t]])), this.indicatorHistory.renamed(e, t);
4535
4842
  }
4536
4843
  drawingPaneAt(e) {
4537
- let t = (t) => e.x >= t.x && e.x <= t.x + t.width && e.y >= t.y && e.y <= t.y + t.height;
4538
- if (!t(this.viewport.getState().chartRect)) {
4539
- for (let e of this.layoutManager.getPanels()) {
4540
- let n = this.drawingPaneViewport(e.id);
4541
- if (n && t(n.chartRect)) return e.id;
4542
- }
4543
- return null;
4544
- }
4844
+ return cr(e, this.viewport.getState().chartRect, this.layoutManager.getPanels(), (e) => this.drawingPaneViewport(e));
4545
4845
  }
4546
4846
  drawingPaneViewport(e) {
4547
4847
  let t = this.layoutManager.getPanels().find((t) => t.id === e);
4548
- if (!t || t.position !== "top" && t.position !== "bottom" || this.layoutManager.isPanelShownCollapsed(e)) return null;
4549
- let n = this.buildPanelRenderInfos().find((t) => t.instanceId === e);
4550
- return !n || n.viewport.chartRect.height < Ur ? null : {
4551
- ...n.viewport,
4552
- data: this.getDisplayData()
4553
- };
4848
+ return lr(t, !!t && this.layoutManager.isPanelShownCollapsed(e), () => this.buildPanelRenderInfos().find((t) => t.instanceId === e)?.viewport, () => this.getDisplayData());
4554
4849
  }
4555
4850
  saveState(e) {
4556
4851
  if (!this.features.saveLoad) return null;
4557
- let t = this.captureSnapshot(), n = T.serialize(t);
4558
- return e && T.saveToStorage(e, t), n;
4852
+ let t = this.captureSnapshot(), n = E.serialize(t);
4853
+ return e && E.saveToStorage(e, t), n;
4559
4854
  }
4560
4855
  loadState(e) {
4561
4856
  if (!this.features.saveLoad) return;
4562
- let t = T.deserialize(e);
4563
- this.chartTypeOptions = t.chartTypeOptions ?? {}, this.displayDataCache = null, this.reshapeMemo.clear(), t.chartType && this.setChartType(t.chartType), t.drawings && this.setDrawings(t.drawings), (t.theme === "dark" || t.theme === "light") && this.setTheme(t.theme), t.version >= 3 && this.themeManager.setUserOverrides(t.overrides ?? {}) && this.styleChanged("user");
4564
- let n = t.version >= 2 && this.features.indicators ? this.withoutIndicatorHistory(() => this.restoreIndicators(t.indicators, !1)) : /* @__PURE__ */ new Map();
4857
+ let t = E.deserialize(e);
4858
+ this.chartTypeOptions = t.chartTypeOptions ?? {}, this.display.reset(), t.chartType && this.setChartType(t.chartType), t.drawings && this.setDrawings(t.drawings), (t.theme === "dark" || t.theme === "light") && this.setTheme(t.theme), t.version >= 3 && this.themeManager.setUserOverrides(t.overrides ?? {}) && this.styleChanged("user");
4859
+ let n = t.version >= 2 && this.features.indicators ? this.indicatorHistory.quietly(() => this.restoreIndicators(t.indicators, !1)) : /* @__PURE__ */ new Map();
4565
4860
  this.drawingManager.renamePanes(n);
4566
4861
  let r = new Set(this.unrestoredIndicators.map((e) => e.instanceId)), i = this.drawingManager.getDrawings(), a = i.filter((e) => e.paneId === void 0 || this.takesDrawing(e.paneId, e.type));
4567
4862
  if (this.keptPaneDrawings = i.filter((e) => e.paneId !== void 0 && r.has(e.paneId)), a.length !== i.length && this.drawingManager.setDrawings(a), this.undoRedoManager.clear(), t.alerts && this.features.alerts) {
@@ -4572,7 +4867,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4572
4867
  let t = e.indexOf(":"), r = t > 0 ? n.get(e.slice(0, t)) : void 0;
4573
4868
  return r ? r + e.slice(t) : e;
4574
4869
  }, r = t(e.channel), i = {
4575
- ...zt(e),
4870
+ ...Bt(e),
4576
4871
  ...e.target ? { target: t(e.target) } : {}
4577
4872
  };
4578
4873
  if (!e.expired) {
@@ -4592,19 +4887,19 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4592
4887
  }
4593
4888
  loadStateFromStorage(e) {
4594
4889
  if (!this.features.saveLoad) return !1;
4595
- let t = T.loadFromStorage(e);
4596
- return t ? (this.loadState(T.serialize(t)), !0) : !1;
4890
+ let t = E.loadFromStorage(e);
4891
+ return t ? (this.loadState(E.serialize(t)), !0) : !1;
4597
4892
  }
4598
4893
  downloadState(e) {
4599
- this.features.saveLoad && T.downloadFile(this.captureSnapshot(), e);
4894
+ this.features.saveLoad && E.downloadFile(this.captureSnapshot(), e);
4600
4895
  }
4601
4896
  async loadStateFromFile() {
4602
4897
  if (!this.features.saveLoad) return;
4603
- let e = await T.loadFromFile();
4604
- this.loadState(T.serialize(e));
4898
+ let e = await E.loadFromFile();
4899
+ this.loadState(E.serialize(e));
4605
4900
  }
4606
4901
  setLocale(e) {
4607
- le(e), this.engine.requestRender();
4902
+ ce(e), this.engine.requestRender();
4608
4903
  }
4609
4904
  setNumberLocale(e) {
4610
4905
  this.numberLocale = e, this.viewport.setNumberLocale(e), this.priceAxis.setLocale(e), this.leftPriceAxis.setLocale(e), this.crosshairHandler.setLocale(e), this.timeAxis.setLocale(e), this.chartLegend.setLocale(e), this.crosshairTooltip.setLocale(e), this.pinnedTooltip.setLocale(e), this.currentPriceLine.setLocale(e), this.updateViewportAndRender();
@@ -4655,23 +4950,13 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4655
4950
  }
4656
4951
  createChartRenderer(e) {
4657
4952
  let t = An(e, (e) => this.pluginManager.getChartType(e));
4658
- return t instanceof ze && t.setPriceText((e) => this.formatPrice(e)), t;
4953
+ return t instanceof Re && t.setPriceText((e) => this.formatPrice(e)), t;
4659
4954
  }
4660
4955
  crosshairSeries() {
4661
4956
  return this.isTimeAligned() ? this.series.bars() : this.getDisplayData();
4662
4957
  }
4663
4958
  getDisplayData() {
4664
- let e = this.series.bars(), t = this.options.chartType === "rangeBars" ? Dn(e, (e) => this.stepAt(e)) : void 0;
4665
- if (this.displayDataCache && t === this.displayDataStep) return this.displayDataCache;
4666
- if (e.length === 0) return e;
4667
- let n = this.displaySeries(e, t);
4668
- return this.displayDataCache = n, this.displayDataStep = t, n;
4669
- }
4670
- displaySeries(e, t) {
4671
- let n = this.options.chartType, r = (e) => this.pluginManager.getChartType(e);
4672
- if (n !== "pointAndFigure" || r(n)) return jn(n, e, r, this.chartTypeOptions, t, this.reshapeMemo);
4673
- let { columns: i, boxSize: a } = mn(e, this.chartTypeOptions, this.reshapeMemo);
4674
- return this.chartRenderer instanceof tt && this.chartRenderer.setBoxSize(a), i;
4959
+ return this.display.get();
4675
4960
  }
4676
4961
  recalcIndicatorsFrom(e, t) {
4677
4962
  if (!this.isTimeAligned()) return this.recalcIndicators(e);
@@ -4683,7 +4968,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4683
4968
  }
4684
4969
  exportBars() {
4685
4970
  if (this.isTimeAligned()) return this.series.bars();
4686
- let e = this.getDisplayData(), t = A(e);
4971
+ let e = this.getDisplayData(), t = At(e);
4687
4972
  return e.map((e, n) => ({
4688
4973
  ...e,
4689
4974
  time: t[n]?.time ?? e.time
@@ -4726,50 +5011,38 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4726
5011
  }
4727
5012
  }
4728
5013
  refitForTick() {
4729
- this.panelInfoCache = null, this.fitDataAndAxes(), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
5014
+ this.panes.invalidateScales(), this.fitDataAndAxes(), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
4730
5015
  }
4731
5016
  applyDataToViewport(e = !1) {
4732
5017
  let t = this.getDisplayData();
4733
- this.syncIndicatorBars(t);
4734
- let n = this.options.autoScale !== !1 || this.priceFitPending;
4735
- this.viewport.updateData(t, !1), e && (this.viewport.scrollToEnd(), this.viewport.updateData(t, !1));
4736
- let r = this.viewport.getState();
5018
+ this.syncIndicatorBars(t), this.viewport.updateData(t, !1), e && (this.viewport.scrollToEnd(), this.viewport.updateData(t, !1));
5019
+ let n = this.viewport.getState();
4737
5020
  if (t.length > 0) {
4738
- let e = Math.max(0, Math.min(r.visibleRange.from, t.length - 1));
5021
+ let e = Math.max(0, Math.min(n.visibleRange.from, t.length - 1));
4739
5022
  this.viewport.setScaleBaseline(t[e]?.close);
4740
5023
  }
4741
- return n && this.fitPriceScale(t, this.viewport.getState()), t;
5024
+ return this.priceFit.shouldFit() && this.fitPriceScale(t, this.viewport.getState()), t;
4742
5025
  }
4743
5026
  fitPriceScale(e, t) {
4744
- if (e.length === 0) return;
4745
- let n = Math.max(0, t.visibleRange.from), r = Math.min(t.visibleRange.to, e.length - 1), i = ai(ai(m(e, n, r, 0), this.indicatorEngine.getOverlayPriceRange(n, r)), this.features.compareSymbols && this.comparesDrawn() ? this.compareRenderer.getPriceRange(e, t) : null), a = this.features.volume && this.volumeRenderer.isVisible() && ii(e, n, r) ? this.volumeRenderer.getHeightRatio() + Vr : D;
4746
- this.viewport.setScaleMargins(this.viewport.isInvertScale() ? {
4747
- top: a,
4748
- bottom: D
4749
- } : {
4750
- top: D,
4751
- bottom: a
4752
- }), this.viewport.fitToPrices(i.min, i.max);
5027
+ this.priceFit.fit(this.viewport, e, t, {
5028
+ overlayRange: (e, t) => this.indicatorEngine.getOverlayPriceRange(e, t),
5029
+ compareRange: (e, t) => this.features.compareSymbols && this.comparesDrawn() ? this.compareRenderer.getPriceRange(e, t) : null,
5030
+ volumeRatio: (e, t, n) => this.features.volume && this.volumeRenderer.isVisible() && Un(e, t, n) ? this.volumeRenderer.getHeightRatio() : null
5031
+ });
4753
5032
  }
4754
5033
  updateViewportAndRender(e = !1) {
4755
- this.indicatorEngine.setBarsTimed(this.comparesDrawn()), this.layoutManager.setPanelsAside(this.panesOffChartType()), this.resolvedLayoutCache = null, this.panelInfoCache = null, this.layoutManager.setLeftAxisWidth(this.isLeftPriceScaleShown() ? this.leftAxisWidth : 0);
5034
+ this.indicatorEngine.setBarsTimed(this.comparesDrawn()), this.layoutManager.setPanelsAside(this.panes.offChartType()), this.panes.invalidate(), this.layoutManager.setLeftAxisWidth(this.isLeftPriceScaleShown() ? this.leftAxisWidth : 0);
4756
5035
  let t = this.getResolvedLayout();
4757
5036
  this.viewport.setChartRect(t.mainChartRect), this.fitDataAndAxes(e), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
4758
5037
  }
4759
5038
  fitDataAndAxes(e = !1) {
4760
5039
  let t = this.applyDataToViewport(e), n = this.fitPriceAxisWidth();
4761
- this.leftViewport = this.computeLeftViewport(), (this.fitLeftAxisWidth() || n) && this.applyDataToViewport(e), this.priceFitPending && this.priceFitDone(t) && (this.priceFitPending = !1);
4762
- }
4763
- priceFitDone(e) {
4764
- let { chartRect: t, offset: n, barWidth: r, barSpacing: i } = this.viewport.getState();
4765
- if (e.length === 0 || t.width <= 0) return !1;
4766
- let a = n <= 0 && e.length * (r + i) - n <= t.width;
4767
- return !(this.seriesArriving && a);
5040
+ this.leftViewport = this.computeLeftViewport(), (this.fitLeftAxisWidth() || n) && this.applyDataToViewport(e), this.priceFit.settle(this.viewport.getState(), t.length);
4768
5041
  }
4769
5042
  fitLeftAxisWidth() {
4770
5043
  let e = this.leftViewport;
4771
5044
  if (!e) return !1;
4772
- let t = this.themeManager.getTheme(), n = nr({
5045
+ let t = this.themeManager.getTheme(), n = Er({
4773
5046
  min: e.priceRange.min,
4774
5047
  max: e.priceRange.max,
4775
5048
  lastPrice: null,
@@ -4778,12 +5051,12 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4778
5051
  fontFamily: t.font.family,
4779
5052
  fontSizeSmall: t.font.sizeSmall,
4780
5053
  measure: (e, t) => this.measureText(e, t)
4781
- }), r = rr(this.leftAxisWidth, n);
4782
- return r === this.leftAxisWidth ? !1 : (this.leftAxisWidth = r, this.layoutManager.setLeftAxisWidth(r), this.resolvedLayoutCache = null, this.panelInfoCache = null, this.viewport.setChartRect(this.getResolvedLayout().mainChartRect), !0);
5054
+ }), r = Dr(this.leftAxisWidth, n);
5055
+ return r === this.leftAxisWidth ? !1 : (this.leftAxisWidth = r, this.layoutManager.setLeftAxisWidth(r), this.panes.invalidate(), this.viewport.setChartRect(this.getResolvedLayout().mainChartRect), !0);
4783
5056
  }
4784
5057
  fitPriceAxisWidth() {
4785
5058
  if (!this.features.priceAxis) return !1;
4786
- let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = nr({
5059
+ let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = Er({
4787
5060
  min: e.min,
4788
5061
  max: e.max,
4789
5062
  lastPrice: this.currentPriceLine.getPrice(),
@@ -4794,14 +5067,14 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4794
5067
  fontFamily: t.font.family,
4795
5068
  fontSizeSmall: t.font.sizeSmall,
4796
5069
  measure: (e, t) => this.measureText(e, t)
4797
- }), r = rr(this.priceAxisWidth, n);
4798
- return r === this.priceAxisWidth ? !1 : (this.priceAxisWidth = r, this.layoutManager.setPriceAxisWidth(r), this.viewport.setPriceAxisWidth(r), this.resolvedLayoutCache = null, this.panelInfoCache = null, this.viewport.setChartRect(this.getResolvedLayout().mainChartRect), !0);
5070
+ }), r = Dr(this.priceAxisWidth, n);
5071
+ return r === this.priceAxisWidth ? !1 : (this.priceAxisWidth = r, this.layoutManager.setPriceAxisWidth(r), this.viewport.setPriceAxisWidth(r), this.panes.invalidate(), this.viewport.setChartRect(this.getResolvedLayout().mainChartRect), !0);
4799
5072
  }
4800
5073
  measureText(e, t) {
4801
5074
  let n = this.engine.layerManager.getLayer(r.Main)?.ctx;
4802
- if (n?.canvas.isConnected) return this.labelWidths.get(e, t, () => ei(n, e, t));
5075
+ if (n?.canvas.isConnected) return this.labelWidths.get(e, t, () => _i(n, e, t));
4803
5076
  let i = n ?? this.detachedMeasureContext();
4804
- return i ? ei(i, e, t) : e.length * 7;
5077
+ return i ? _i(i, e, t) : e.length * 7;
4805
5078
  }
4806
5079
  detachedMeasureContext() {
4807
5080
  return this.measureCtx === void 0 && (this.measureCtx = typeof document < "u" ? document.createElement("canvas").getContext("2d") : null), this.measureCtx;
@@ -4825,57 +5098,18 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4825
5098
  })), this.lastEmittedBarWidth !== e.barWidth && (this.lastEmittedBarWidth = e.barWidth, this.eventBus.emit("zoomChange", { barWidth: e.barWidth })), this.checkHistory();
4826
5099
  }
4827
5100
  getResolvedLayout() {
4828
- return this.resolvedLayoutCache || (this.resolvedLayoutCache = this.layoutManager.resolve(), this.syncCrosshairBounds(this.resolvedLayoutCache)), this.resolvedLayoutCache;
4829
- }
4830
- syncCrosshairBounds(e) {
4831
- let t = e.mainChartRect, n = t.y, r = t.y + t.height;
4832
- for (let t of e.panels) t.config.position !== "top" && t.config.position !== "bottom" || (n = Math.min(n, t.rect.y), r = Math.max(r, t.rect.y + t.rect.height));
4833
- this.crosshairHandler.setReportBounds({
4834
- top: n,
4835
- bottom: r
4836
- });
5101
+ return this.panes.resolved();
4837
5102
  }
4838
5103
  cachedContainerSize() {
4839
5104
  let e = Date.now();
4840
5105
  return (!this.containerSizeCache || e - this.containerSizeCacheTime > 500) && (this.containerSizeCache = this.engine.dprManager.getContainerSize(), this.containerSizeCacheTime = e), this.containerSizeCache;
4841
5106
  }
4842
5107
  buildPanelRenderInfos() {
4843
- if (this.panelInfoCache) return this.panelInfoCache;
4844
- let e = this.getResolvedLayout(), t = this.viewport.getState(), { from: n, to: r } = t.visibleRange, i = e.panels.map((e) => {
4845
- let i = e.config.logScale ? this.indicatorEngine.getPaneValueRange(e.config.id, n, r, !0) : null, a = i ?? this.indicatorEngine.getPaneValueRange(e.config.id, n, r) ?? { ...Fr }, o = {
4846
- x: e.rect.x,
4847
- y: e.rect.y + 20,
4848
- width: e.rect.width,
4849
- height: Math.max(0, e.rect.height - 20)
4850
- }, s = this.paneStyles.get(e.config.id);
4851
- return {
4852
- instanceId: e.config.id,
4853
- members: this.indicatorEngine.getPaneMembers(e.config.id),
4854
- ...s ? { style: s } : {},
4855
- rect: e.rect,
4856
- viewport: {
4857
- ...t,
4858
- chartRect: o,
4859
- priceRange: a,
4860
- logScale: i !== null,
4861
- scaleMode: e.config.percentScale ? "percentage" : "regular",
4862
- scaleBaseline: e.config.percentScale ? this.paneBaseline(e.config.id, n, r) : void 0,
4863
- formatPrice: void 0,
4864
- pricePrecision: void 0,
4865
- priceUnit: void 0,
4866
- invertScale: !!e.config.invertScale
4867
- }
4868
- };
4869
- });
4870
- return this.panelInfoCache = i, i;
4871
- }
4872
- timeAxisTop() {
4873
- let e = this.getResolvedLayout(), t = e.panels.filter((e) => e.config.position === "bottom").reduce((e, t) => e + t.rect.height, 0);
4874
- return e.mainChartRect.y + e.mainChartRect.height + t;
5108
+ return this.panes.panels(() => this.viewport.getState());
4875
5109
  }
4876
5110
  syncRenderContext() {
4877
5111
  this.pinnedTooltip.isPinned() && this.pinnedTooltip.reposition(this.viewport.getState(), null, null, this.themeManager.getTheme());
4878
- let e = this.features.indicators ? this.buildPanelRenderInfos() : [], t = this.timeAxisTop(), n = this.getDisplayData();
5112
+ let e = this.features.indicators ? this.buildPanelRenderInfos() : [], t = this.panes.timeAxisTop(), n = this.getDisplayData();
4879
5113
  this.leftViewport = this.computeLeftViewport(), this.engine.setRenderContext({
4880
5114
  leftViewport: this.leftViewport,
4881
5115
  leftPriceAxis: this.leftPriceAxis,
@@ -4927,7 +5161,7 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4927
5161
  });
4928
5162
  }
4929
5163
  drawOverlayPlugins(e, t) {
4930
- let n = cr(this.pluginManager.getOverlays(), t);
5164
+ let n = Mr(this.pluginManager.getOverlays(), t);
4931
5165
  if (n.length === 0) return;
4932
5166
  let r = {
4933
5167
  viewport: this.viewport.getState(),
@@ -4948,33 +5182,16 @@ var Gr = 20, Kr = 8, qr = 10, Jr = {
4948
5182
  };
4949
5183
  }
4950
5184
  };
4951
- function Qr(e) {
4952
- let t = new Map(e.map((e) => [e.instanceId, e])), n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
4953
- if (r.has(e.instanceId) || i.has(e.instanceId)) return;
4954
- i.add(e.instanceId);
4955
- let o = [e.pane, ...Object.values(e.params).map((e) => x(e)?.instanceId)];
4956
- for (let e of o) {
4957
- let n = e ? t.get(e) : void 0;
4958
- n && a(n);
4959
- }
4960
- i.delete(e.instanceId), r.add(e.instanceId), n.push(e);
4961
- };
4962
- for (let t of e) a(t);
4963
- return n;
4964
- }
4965
- function $r(e, t) {
4966
- return e.id === t.id && (e.pane ?? null) === (t.pane ?? null) && (e.scale ?? null) === (t.scale ?? null) && e.position === void 0 == (t.position === void 0);
4967
- }
4968
- function ei(e, t, n) {
5185
+ function _i(e, t, n) {
4969
5186
  let r = e.font;
4970
5187
  e.font = n;
4971
5188
  let i = e.measureText(t).width;
4972
5189
  return e.font = r, i;
4973
5190
  }
4974
- var ti = 300;
4975
- function ni(e) {
5191
+ var vi = 300;
5192
+ function yi(e) {
4976
5193
  let t = {}, n = e.family;
4977
- typeof n == "string" && n.trim() !== "" && n.length <= ti && !/[;{}<>\\]|\/\*/.test(n) && (t.family = n);
5194
+ typeof n == "string" && n.trim() !== "" && n.length <= vi && !/[;{}<>\\]|\/\*/.test(n) && (t.family = n);
4978
5195
  for (let n of [
4979
5196
  "sizeSmall",
4980
5197
  "sizeMedium",
@@ -4985,21 +5202,11 @@ function ni(e) {
4985
5202
  }
4986
5203
  return t;
4987
5204
  }
4988
- function ri(e) {
5205
+ function bi(e) {
4989
5206
  let t = e.tagRadius;
4990
5207
  return typeof t == "number" && Number.isFinite(t) && t >= 0 ? { tagRadius: Math.min(t, 999) } : {};
4991
5208
  }
4992
- function ii(e, t, n) {
4993
- for (let r = t; r <= n; r++) if (e[r].volume > 0) return !0;
4994
- return !1;
4995
- }
4996
- function ai(e, t) {
4997
- return e ? t ? {
4998
- min: Math.min(e.min, t.min),
4999
- max: Math.max(e.max, t.max)
5000
- } : e : t;
5001
- }
5002
- function J(e) {
5209
+ function Y(e) {
5003
5210
  return {
5004
5211
  id: e.id,
5005
5212
  price: e.price,
@@ -5014,14 +5221,8 @@ function J(e) {
5014
5221
  bars: e.bars
5015
5222
  };
5016
5223
  }
5017
- var oi = 8e3, si = new Set([
5018
- "candlestick",
5019
- "line",
5020
- "area",
5021
- "bar",
5022
- "hollowCandle"
5023
- ]), ci = 10, li = 50, ui = .001;
5024
- function di(e) {
5224
+ var xi = 8e3, Si = 10, Ci = 50, wi = .001;
5225
+ function Ti(e) {
5025
5226
  return {
5026
5227
  price: null,
5027
5228
  fedTime: null,
@@ -5036,42 +5237,42 @@ function di(e) {
5036
5237
  held: null
5037
5238
  };
5038
5239
  }
5039
- function fi(e, t) {
5240
+ function Ei(e, t) {
5040
5241
  let n = e[t + 1];
5041
- return n ? n.time - e[t].time : Z(e);
5242
+ return n ? n.time - e[t].time : Ni(e);
5042
5243
  }
5043
- function pi(e, t, n) {
5244
+ function Di(e, t, n) {
5044
5245
  let r = e.fedTime;
5045
5246
  if (r === null || !t || t.length === 0 || n.length === 0) return;
5046
- let i = fi(t, Q(t, r)), a = r + (Number.isFinite(i) ? e.fedFraction * i : 0), o = Q(n, a), s = n[o].time;
5247
+ let i = Ei(t, Q(t, r)), a = r + (Number.isFinite(i) ? e.fedFraction * i : 0), o = Q(n, a), s = n[o].time;
5047
5248
  if (s > a) return;
5048
- let c = fi(n, o);
5249
+ let c = Ei(n, o);
5049
5250
  if (a === s && o > 0) {
5050
5251
  e.fedTime = n[o - 1].time, e.fedFraction = 1;
5051
5252
  return;
5052
5253
  }
5053
5254
  e.fedTime = s, e.fedFraction = Number.isFinite(c) && c > 0 ? Math.min(1, (a - s) / c) : 0;
5054
5255
  }
5055
- function mi(e, t) {
5056
- let n = X(e, t), r = e.length - 1;
5057
- return n > r && r >= 0 && e[r].time + Z(e) <= t ? r : Math.max(-1, n - 2);
5256
+ function Oi(e, t) {
5257
+ let n = Z(e, t), r = e.length - 1;
5258
+ return n > r && r >= 0 && e[r].time + Ni(e) <= t ? r : Math.max(-1, n - 2);
5058
5259
  }
5059
- function hi(e) {
5260
+ function ki(e) {
5060
5261
  let t = Infinity;
5061
5262
  for (let n = Math.max(1, e.length - 10); n < e.length; n++) t = Math.min(t, e[n].time - e[n - 1].time);
5062
5263
  return t;
5063
5264
  }
5064
- function gi(e, t) {
5065
- if (!(hi(e) < hi(t))) return !1;
5066
- let n = Math.max(0, e.length - li);
5265
+ function Ai(e, t) {
5266
+ if (!(ki(e) < ki(t))) return !1;
5267
+ let n = Math.max(0, e.length - Ci);
5067
5268
  for (let r = n; r < e.length; r++) {
5068
- let n = t[Q(t, e[r].time)], i = (n.high - n.low) * ui + 2 ** -52;
5269
+ let n = t[Q(t, e[r].time)], i = (n.high - n.low) * wi + 2 ** -52;
5069
5270
  if (e[r].close > n.high + i || e[r].close < n.low - i) return !1;
5070
5271
  }
5071
5272
  return !0;
5072
5273
  }
5073
- var _i = 500;
5074
- function Y(e, t) {
5274
+ var ji = 500;
5275
+ function X(e, t) {
5075
5276
  let n = 0, r = e.length;
5076
5277
  for (; n < r;) {
5077
5278
  let i = n + r >> 1;
@@ -5079,7 +5280,7 @@ function Y(e, t) {
5079
5280
  }
5080
5281
  return n;
5081
5282
  }
5082
- function X(e, t) {
5283
+ function Z(e, t) {
5083
5284
  let n = 0, r = e.length;
5084
5285
  for (; n < r;) {
5085
5286
  let i = n + r >> 1;
@@ -5087,20 +5288,20 @@ function X(e, t) {
5087
5288
  }
5088
5289
  return n;
5089
5290
  }
5090
- function vi(e) {
5291
+ function Mi(e) {
5091
5292
  let t = 0, n = 0;
5092
5293
  for (let r = 1; r < e.length; r++) e[r].low < e[t].low && (t = r), e[r].high > e[n].high && (n = r);
5093
5294
  let r = [e[t].low, e[t].time], i = [e[n].high, e[n].time], a = t === n ? e[t].close >= e[t].open : t < n, o = e[e.length - 1];
5094
5295
  return [...a ? [r, i] : [i, r], [o.close, o.time]];
5095
5296
  }
5096
- function Z(e) {
5297
+ function Ni(e) {
5097
5298
  let t = 0;
5098
5299
  for (let n = Math.max(1, e.length - 10); n < e.length; n++) t = Math.max(t, e[n].time - e[n - 1].time);
5099
5300
  return t > 0 ? t : Infinity;
5100
5301
  }
5101
- function yi(e, t) {
5302
+ function Pi(e, t) {
5102
5303
  if (t.length === 0) return null;
5103
- let n = t[t.length - 1].time + Z(t), r = e.filter((e) => Rn(e) && e.time >= t[0].time && e.time < n).sort((e, t) => e.time - t.time), i = [];
5304
+ let n = t[t.length - 1].time + Ni(t), r = e.filter((e) => Rn(e) && e.time >= t[0].time && e.time < n).sort((e, t) => e.time - t.time), i = [];
5104
5305
  for (let e of r) (i.length === 0 || i[i.length - 1].time !== e.time) && i.push(e);
5105
5306
  if (i.length === 0) return null;
5106
5307
  let a = t.findIndex((e) => e.time >= i[0].time);
@@ -5116,26 +5317,26 @@ function Q(e, t) {
5116
5317
  }
5117
5318
  return n;
5118
5319
  }
5119
- function bi(e, t, n) {
5320
+ function Fi(e, t, n) {
5120
5321
  let r = Math.max(0, Math.min(Math.floor(Number.isFinite(n) ? n : 0), t.length - 1)), i = r + 1 < t.length ? t[r + 1].time : Infinity, a = -1;
5121
5322
  for (let t = 0; t < e.length && e[t].time < i; t++) a = t;
5122
5323
  return Math.max(0, a);
5123
5324
  }
5124
- function xi(e, t, n) {
5325
+ function Ii(e, t, n) {
5125
5326
  let r = n;
5126
5327
  for (; r > 0 && t[r - 1].time >= e.time;) r--;
5127
5328
  let i = {
5128
5329
  ...t[r],
5129
5330
  time: e.time
5130
5331
  };
5131
- for (let e = r + 1; e <= n; e++) i = Ti(i, t[e]);
5332
+ for (let e = r + 1; e <= n; e++) i = Bi(i, t[e]);
5132
5333
  return i;
5133
5334
  }
5134
- function Si(e, t, n, r) {
5335
+ function Li(e, t, n, r) {
5135
5336
  let i = e[n + 1], a = t[r + 1];
5136
5337
  return i !== void 0 && a !== void 0 && i.time >= a.time;
5137
5338
  }
5138
- function Ci(e, t) {
5339
+ function Ri(e, t) {
5139
5340
  let n = /* @__PURE__ */ new Map();
5140
5341
  for (let r of e) {
5141
5342
  let e = t[Q(t, r.time)].time, i = n.get(e);
@@ -5143,10 +5344,10 @@ function Ci(e, t) {
5143
5344
  }
5144
5345
  return n;
5145
5346
  }
5146
- function wi() {
5347
+ function zi() {
5147
5348
  return typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
5148
5349
  }
5149
- function Ti(e, t) {
5350
+ function Bi(e, t) {
5150
5351
  return {
5151
5352
  time: e.time,
5152
5353
  open: e.open,
@@ -5158,26 +5359,26 @@ function Ti(e, t) {
5158
5359
  }
5159
5360
  //#endregion
5160
5361
  //#region src/io/parseOHLCV.ts
5161
- var Ei = [
5362
+ var Vi = [
5162
5363
  "time",
5163
5364
  "timestamp",
5164
5365
  "date",
5165
5366
  "datetime",
5166
5367
  "t"
5167
- ], Di = ["open", "o"], Oi = ["high", "h"], ki = ["low", "l"], Ai = ["close", "c"], ji = [
5368
+ ], Hi = ["open", "o"], Ui = ["high", "h"], Wi = ["low", "l"], Gi = ["close", "c"], Ki = [
5168
5369
  "volume",
5169
5370
  "vol",
5170
5371
  "v"
5171
5372
  ];
5172
- function Mi(e) {
5373
+ function qi(e) {
5173
5374
  let t = e.trim();
5174
- return t ? t[0] === "[" || t[0] === "{" ? Ni(t) : Pi(t) : {
5375
+ return t ? t[0] === "[" || t[0] === "{" ? Ji(t) : Yi(t) : {
5175
5376
  data: [],
5176
5377
  rowCount: 0,
5177
5378
  skipped: 0
5178
5379
  };
5179
5380
  }
5180
- function Ni(e) {
5381
+ function Ji(e) {
5181
5382
  let t;
5182
5383
  try {
5183
5384
  t = JSON.parse(e);
@@ -5187,19 +5388,19 @@ function Ni(e) {
5187
5388
  if (!Array.isArray(t)) throw Error("Expected a JSON array of OHLCV rows");
5188
5389
  let n = [], r = 0;
5189
5390
  for (let e of t) {
5190
- let t = Array.isArray(e) ? zi(e) : Ri(e);
5391
+ let t = Array.isArray(e) ? ea(e) : $i(e);
5191
5392
  t ? n.push(t) : r++;
5192
5393
  }
5193
- return Vi(n, t.length, r);
5394
+ return na(n, t.length, r);
5194
5395
  }
5195
- function Pi(e) {
5396
+ function Yi(e) {
5196
5397
  let t = e.split(/\r?\n/).filter((e) => e.trim().length > 0);
5197
5398
  if (t.length === 0) return {
5198
5399
  data: [],
5199
5400
  rowCount: 0,
5200
5401
  skipped: 0
5201
5402
  };
5202
- let n = Fi(t[0]), r = Ii(t[0], n).map((e) => e.trim().toLowerCase()), i = r.some((e) => isNaN(Number(e)) && e.length > 0), a = i ? Li(r) : {
5403
+ let n = Xi(t[0]), r = Zi(t[0], n).map((e) => e.trim().toLowerCase()), i = r.some((e) => isNaN(Number(e)) && e.length > 0), a = i ? Qi(r) : {
5203
5404
  time: 0,
5204
5405
  open: 1,
5205
5406
  high: 2,
@@ -5210,7 +5411,7 @@ function Pi(e) {
5210
5411
  if (a.time < 0 || a.open < 0 || a.high < 0 || a.low < 0 || a.close < 0) throw Error("CSV is missing required column(s): time, open, high, low, close");
5211
5412
  let o = [], s = 0;
5212
5413
  for (let e = +!!i; e < t.length; e++) {
5213
- let r = Ii(t[e], n), i = Bi(r[a.time]), c = $(r[a.open]), l = $(r[a.high]), u = $(r[a.low]), d = $(r[a.close]), f = a.volume >= 0 ? Number(r[a.volume]) : 0;
5414
+ let r = Zi(t[e], n), i = ta(r[a.time]), c = $(r[a.open]), l = $(r[a.high]), u = $(r[a.low]), d = $(r[a.close]), f = a.volume >= 0 ? Number(r[a.volume]) : 0;
5214
5415
  if (i === null || ![
5215
5416
  c,
5216
5417
  l,
@@ -5229,9 +5430,9 @@ function Pi(e) {
5229
5430
  volume: Number.isFinite(f) ? f : 0
5230
5431
  });
5231
5432
  }
5232
- return Vi(o, t.length - +!!i, s);
5433
+ return na(o, t.length - +!!i, s);
5233
5434
  }
5234
- function Fi(e) {
5435
+ function Xi(e) {
5235
5436
  let t = {
5236
5437
  ",": 0,
5237
5438
  ";": 0,
@@ -5243,7 +5444,7 @@ function Fi(e) {
5243
5444
  for (let [e, i] of Object.entries(t)) i > r && (n = e, r = i);
5244
5445
  return n;
5245
5446
  }
5246
- function Ii(e, t) {
5447
+ function Zi(e, t) {
5247
5448
  let n = [], r = "", i = !1;
5248
5449
  for (let a = 0; a < e.length; a++) {
5249
5450
  let o = e[a];
@@ -5251,25 +5452,25 @@ function Ii(e, t) {
5251
5452
  }
5252
5453
  return n.push(r), n;
5253
5454
  }
5254
- function Li(e) {
5455
+ function Qi(e) {
5255
5456
  let t = (t) => e.findIndex((e) => t.includes(e));
5256
5457
  return {
5257
- time: t(Ei),
5258
- open: t(Di),
5259
- high: t(Oi),
5260
- low: t(ki),
5261
- close: t(Ai),
5262
- volume: t(ji)
5458
+ time: t(Vi),
5459
+ open: t(Hi),
5460
+ high: t(Ui),
5461
+ low: t(Wi),
5462
+ close: t(Gi),
5463
+ volume: t(Ki)
5263
5464
  };
5264
5465
  }
5265
- function Ri(e) {
5466
+ function $i(e) {
5266
5467
  let t = (t) => {
5267
5468
  for (let n of t) {
5268
5469
  if (e[n] !== void 0) return e[n];
5269
5470
  let t = n.toUpperCase();
5270
5471
  if (e[t] !== void 0) return e[t];
5271
5472
  }
5272
- }, n = Bi(String(t(Ei) ?? "")), r = Number(t(Di)), i = Number(t(Oi)), a = Number(t(ki)), o = Number(t(Ai)), s = Number(t(ji) ?? 0);
5473
+ }, n = ta(String(t(Vi) ?? "")), r = Number(t(Hi)), i = Number(t(Ui)), a = Number(t(Wi)), o = Number(t(Gi)), s = Number(t(Ki) ?? 0);
5273
5474
  return n === null || ![
5274
5475
  r,
5275
5476
  i,
@@ -5284,9 +5485,9 @@ function Ri(e) {
5284
5485
  volume: Number.isFinite(s) ? s : 0
5285
5486
  };
5286
5487
  }
5287
- function zi(e) {
5488
+ function ea(e) {
5288
5489
  if (e.length < 5) return null;
5289
- let t = Bi(String(e[0])), n = Number(e[1]), r = Number(e[2]), i = Number(e[3]), a = Number(e[4]), o = e.length >= 6 ? Number(e[5]) : 0;
5490
+ let t = ta(String(e[0])), n = Number(e[1]), r = Number(e[2]), i = Number(e[3]), a = Number(e[4]), o = e.length >= 6 ? Number(e[5]) : 0;
5290
5491
  return t === null || ![
5291
5492
  n,
5292
5493
  r,
@@ -5304,7 +5505,7 @@ function zi(e) {
5304
5505
  function $(e) {
5305
5506
  return e === void 0 || e.trim() === "" ? NaN : Number(e);
5306
5507
  }
5307
- function Bi(e) {
5508
+ function ta(e) {
5308
5509
  let t = e.trim();
5309
5510
  if (!t) return null;
5310
5511
  let n = Number(t);
@@ -5312,7 +5513,7 @@ function Bi(e) {
5312
5513
  let r = Date.parse(t);
5313
5514
  return Number.isFinite(r) ? r : null;
5314
5515
  }
5315
- function Vi(e, t, n) {
5516
+ function na(e, t, n) {
5316
5517
  e.sort((e, t) => e.time - t.time);
5317
5518
  let r = [];
5318
5519
  for (let t of e) r.length > 0 && r[r.length - 1].time === t.time ? r[r.length - 1] = t : r.push(t);
@@ -5324,7 +5525,7 @@ function Vi(e, t, n) {
5324
5525
  }
5325
5526
  //#endregion
5326
5527
  //#region src/io/DragDropImporter.ts
5327
- var Hi = class {
5528
+ var ra = class {
5328
5529
  host;
5329
5530
  overlay = null;
5330
5531
  callbacks;
@@ -5345,19 +5546,19 @@ var Hi = class {
5345
5546
  this.host.removeEventListener("dragenter", this.bound.dragenter), this.host.removeEventListener("dragover", this.bound.dragover), this.host.removeEventListener("dragleave", this.bound.dragleave), this.host.removeEventListener("drop", this.bound.drop), this.hideOverlay();
5346
5547
  }
5347
5548
  onDragEnter(e) {
5348
- Ui(e) && (e.preventDefault(), this.depth++, this.showOverlay());
5549
+ ia(e) && (e.preventDefault(), this.depth++, this.showOverlay());
5349
5550
  }
5350
5551
  onDragOver(e) {
5351
- Ui(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"));
5552
+ ia(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"));
5352
5553
  }
5353
5554
  onDragLeave(e) {
5354
- Ui(e) && (this.depth = Math.max(0, this.depth - 1), this.depth === 0 && this.hideOverlay());
5555
+ ia(e) && (this.depth = Math.max(0, this.depth - 1), this.depth === 0 && this.hideOverlay());
5355
5556
  }
5356
5557
  async onDrop(e) {
5357
5558
  e.preventDefault(), this.depth = 0, this.hideOverlay();
5358
5559
  let t = e.dataTransfer?.files?.[0];
5359
5560
  if (t) try {
5360
- let e = Mi(await t.text());
5561
+ let e = qi(await t.text());
5361
5562
  if (e.data.length === 0) throw Error(`No valid OHLCV rows found in "${t.name}"`);
5362
5563
  this.callbacks.onData(e.data, e, t);
5363
5564
  } catch (e) {
@@ -5388,12 +5589,12 @@ var Hi = class {
5388
5589
  this.overlay?.remove(), this.overlay = null;
5389
5590
  }
5390
5591
  };
5391
- function Ui(e) {
5592
+ function ia(e) {
5392
5593
  return e.dataTransfer?.types?.includes("Files") ?? !1;
5393
5594
  }
5394
5595
  //#endregion
5395
5596
  //#region src/state/layoutStorage.ts
5396
- function Wi(e) {
5597
+ function aa(e) {
5397
5598
  let t = {
5398
5599
  id: e.id,
5399
5600
  name: e.name,
@@ -5401,11 +5602,11 @@ function Wi(e) {
5401
5602
  };
5402
5603
  return e.symbol !== void 0 && (t.symbol = e.symbol), e.timeframe !== void 0 && (t.timeframe = e.timeframe), e.kind !== void 0 && (t.kind = e.kind), t;
5403
5604
  }
5404
- var Gi = (e, t) => t.updatedAt - e.updatedAt;
5405
- function Ki(e) {
5605
+ var oa = (e, t) => t.updatedAt - e.updatedAt;
5606
+ function sa(e) {
5406
5607
  if (typeof e != "object" || !e) return null;
5407
5608
  let t = e;
5408
- return typeof t.id != "string" || !t.id || typeof t.name != "string" || typeof t.updatedAt != "number" || !Number.isFinite(t.updatedAt) ? null : Wi({
5609
+ return typeof t.id != "string" || !t.id || typeof t.name != "string" || typeof t.updatedAt != "number" || !Number.isFinite(t.updatedAt) ? null : aa({
5409
5610
  id: t.id,
5410
5611
  name: t.name,
5411
5612
  updatedAt: t.updatedAt,
@@ -5414,17 +5615,17 @@ function Ki(e) {
5414
5615
  kind: typeof t.kind == "string" ? t.kind : void 0
5415
5616
  });
5416
5617
  }
5417
- function qi(e) {
5418
- let t = Ki(e), n = t ? e.content : void 0;
5618
+ function ca(e) {
5619
+ let t = sa(e), n = t ? e.content : void 0;
5419
5620
  return t && typeof n == "string" ? {
5420
5621
  ...t,
5421
5622
  content: n
5422
5623
  } : null;
5423
5624
  }
5424
- function Ji(e = []) {
5625
+ function la(e = []) {
5425
5626
  let t = new Map(e.map((e) => [e.id, { ...e }]));
5426
5627
  return {
5427
- list: () => [...t.values()].map(Wi).sort(Gi),
5628
+ list: () => [...t.values()].map(aa).sort(oa),
5428
5629
  load: (e) => {
5429
5630
  let n = t.get(e);
5430
5631
  return n ? { ...n } : null;
@@ -5437,7 +5638,7 @@ function Ji(e = []) {
5437
5638
  }
5438
5639
  };
5439
5640
  }
5440
- function Yi(e = "tcw:layouts:") {
5641
+ function ua(e = "tcw:layouts:") {
5441
5642
  let t = `${e}index`, n = (t) => `${e}item:${t}`, r = () => {
5442
5643
  let e;
5443
5644
  try {
@@ -5445,10 +5646,10 @@ function Yi(e = "tcw:layouts:") {
5445
5646
  } catch {
5446
5647
  return [];
5447
5648
  }
5448
- return Array.isArray(e) ? e.map(Ki).filter((e) => e !== null) : [];
5649
+ return Array.isArray(e) ? e.map(sa).filter((e) => e !== null) : [];
5449
5650
  }, i = (e) => localStorage.setItem(t, JSON.stringify(e));
5450
5651
  return {
5451
- list: () => r().sort(Gi),
5652
+ list: () => r().sort(oa),
5452
5653
  load: (e) => {
5453
5654
  let t = r().find((t) => t.id === e), i = t ? localStorage.getItem(n(e)) : null;
5454
5655
  return t && i !== null ? {
@@ -5457,7 +5658,7 @@ function Yi(e = "tcw:layouts:") {
5457
5658
  } : null;
5458
5659
  },
5459
5660
  save: (e) => {
5460
- localStorage.setItem(n(e.id), e.content), i([...r().filter((t) => t.id !== e.id), Wi(e)]);
5661
+ localStorage.setItem(n(e.id), e.content), i([...r().filter((t) => t.id !== e.id), aa(e)]);
5461
5662
  },
5462
5663
  remove: (e) => {
5463
5664
  i(r().filter((t) => t.id !== e)), localStorage.removeItem(n(e));
@@ -5466,14 +5667,14 @@ function Yi(e = "tcw:layouts:") {
5466
5667
  }
5467
5668
  //#endregion
5468
5669
  //#region src/state/LayoutSession.ts
5469
- var Xi = 80;
5470
- function Zi(e) {
5670
+ var da = 80;
5671
+ function fa(e) {
5471
5672
  return e.replace(/\s+/g, " ").trim().slice(0, 80).trim() || null;
5472
5673
  }
5473
- function Qi() {
5674
+ function pa() {
5474
5675
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
5475
5676
  }
5476
- function $i(e) {
5677
+ function ma(e) {
5477
5678
  let { id: t, name: n, symbol: r, timeframe: i, updatedAt: a, kind: o } = e;
5478
5679
  return {
5479
5680
  id: t,
@@ -5484,7 +5685,7 @@ function $i(e) {
5484
5685
  ...o === void 0 ? {} : { kind: o }
5485
5686
  };
5486
5687
  }
5487
- var ea = class {
5688
+ var ha = class {
5488
5689
  currentLayout = null;
5489
5690
  savedContent = null;
5490
5691
  dirty = !1;
@@ -5500,7 +5701,7 @@ var ea = class {
5500
5701
  now;
5501
5702
  newId;
5502
5703
  constructor(e, t, n = {}) {
5503
- this.storage = e, this.host = t, this.options = n, this.autoSave = n.autoSave ?? !0, this.debounceMs = n.debounceMs ?? 1500, this.kind = n.kind ?? "chart", this.now = n.now ?? Date.now, this.newId = n.newId ?? Qi;
5704
+ this.storage = e, this.host = t, this.options = n, this.autoSave = n.autoSave ?? !0, this.debounceMs = n.debounceMs ?? 1500, this.kind = n.kind ?? "chart", this.now = n.now ?? Date.now, this.newId = n.newId ?? pa;
5504
5705
  }
5505
5706
  current() {
5506
5707
  return this.currentLayout;
@@ -5516,7 +5717,7 @@ var ea = class {
5516
5717
  }
5517
5718
  async list() {
5518
5719
  let e = await this.storage.list();
5519
- return Array.isArray(e) ? e.map(Ki).filter((e) => e !== null && (e.kind ?? "chart") === this.kind).sort((e, t) => t.updatedAt - e.updatedAt) : [];
5720
+ return Array.isArray(e) ? e.map(sa).filter((e) => e !== null && (e.kind ?? "chart") === this.kind).sort((e, t) => t.updatedAt - e.updatedAt) : [];
5520
5721
  }
5521
5722
  save() {
5522
5723
  return this.queue(() => {
@@ -5525,12 +5726,12 @@ var ea = class {
5525
5726
  });
5526
5727
  }
5527
5728
  saveAs(e) {
5528
- let t = Zi(e);
5729
+ let t = fa(e);
5529
5730
  return t ? this.queue(() => this.write(this.newId(), t)) : Promise.reject(/* @__PURE__ */ Error("A layout needs a name"));
5530
5731
  }
5531
5732
  open(e) {
5532
5733
  return this.queue(async () => {
5533
- let t = qi(await this.storage.load(e));
5734
+ let t = ca(await this.storage.load(e));
5534
5735
  if (!t || t.id !== e || (t.kind ?? "chart") !== this.kind || this.destroyed) return !1;
5535
5736
  this.cancelTimer(), this.applying++;
5536
5737
  try {
@@ -5540,13 +5741,13 @@ var ea = class {
5540
5741
  } finally {
5541
5742
  this.applying--;
5542
5743
  }
5543
- return this.cancelTimer(), this.currentLayout = $i(t), this.savedContent = this.host.capture().content, this.dirty = !1, this.notify(), !0;
5744
+ return this.cancelTimer(), this.currentLayout = ma(t), this.savedContent = this.host.capture().content, this.dirty = !1, this.notify(), !0;
5544
5745
  });
5545
5746
  }
5546
5747
  rename(e, t) {
5547
- let n = Zi(t);
5748
+ let n = fa(t);
5548
5749
  return n ? this.queue(async () => {
5549
- let t = qi(await this.storage.load(e));
5750
+ let t = ca(await this.storage.load(e));
5550
5751
  !t || t.id !== e || (await this.storage.save({
5551
5752
  ...t,
5552
5753
  name: n
@@ -5624,7 +5825,7 @@ var ea = class {
5624
5825
  content: n.content
5625
5826
  };
5626
5827
  await this.storage.save(r);
5627
- let i = $i(r);
5828
+ let i = ma(r);
5628
5829
  return this.currentLayout = i, this.savedContent = n.content, this.dirty = !1, this.notify(), i;
5629
5830
  }
5630
5831
  forget() {
@@ -5645,6 +5846,6 @@ var ea = class {
5645
5846
  }
5646
5847
  };
5647
5848
  //#endregion
5648
- export { Un as C, B as D, R as E, un as O, Kn as S, V as T, ur as _, Ji as a, G as b, Zr as c, Nr as d, Pr as f, lr as g, dr as h, Yi as i, Lr as l, fr as m, Xi as n, Hi as o, pr as p, Zi as r, Mi as s, ea as t, Ir as u, sr as v, Vn as w, Zn as x, cr as y };
5849
+ export { pr as C, B as D, R as E, dn as O, gr as S, V as T, Pr as _, la as a, K as b, gi as c, ri as d, ii as f, Nr as g, Fr as h, ua as i, oi as l, Ir as m, da as n, ra as o, Lr as p, fa as r, qi as s, ha as t, ai as u, jr as v, dr as w, xr as x, Mr as y };
5649
5850
 
5650
- //# sourceMappingURL=LayoutSession-CoCMrrbh.js.map
5851
+ //# sourceMappingURL=LayoutSession-Bcy79w0l.js.map