@tradecanvas/chart 1.68.1 → 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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/Chart.d.ts +20 -97
  3. package/dist/Chart.d.ts.map +1 -1
  4. package/dist/DataManager.d.ts +7 -0
  5. package/dist/DataManager.d.ts.map +1 -1
  6. package/dist/HistoryPager.d.ts.map +1 -1
  7. package/dist/{LayoutSession-EEUFJm3J.js → LayoutSession-Bcy79w0l.js} +1082 -873
  8. package/dist/LayoutSession-Bcy79w0l.js.map +1 -0
  9. package/dist/LayoutSession-D7S6GZgJ.cjs +2 -0
  10. package/dist/LayoutSession-D7S6GZgJ.cjs.map +1 -0
  11. package/dist/SeriesStore.d.ts +2 -0
  12. package/dist/SeriesStore.d.ts.map +1 -1
  13. package/dist/grid/ChartGrid.d.ts +5 -5
  14. package/dist/grid/ChartGrid.d.ts.map +1 -1
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +69 -69
  20. package/dist/index.js.map +1 -1
  21. package/dist/model/DisplaySeries.d.ts +50 -0
  22. package/dist/model/DisplaySeries.d.ts.map +1 -0
  23. package/dist/model/DrawingPanes.d.ts +24 -0
  24. package/dist/model/DrawingPanes.d.ts.map +1 -0
  25. package/dist/model/IndicatorHistory.d.ts +52 -0
  26. package/dist/model/IndicatorHistory.d.ts.map +1 -0
  27. package/dist/model/IndicatorPanes.d.ts +76 -0
  28. package/dist/model/IndicatorPanes.d.ts.map +1 -0
  29. package/dist/model/IndicatorSetup.d.ts +34 -0
  30. package/dist/model/IndicatorSetup.d.ts.map +1 -0
  31. package/dist/model/PaneLayout.d.ts +55 -0
  32. package/dist/model/PaneLayout.d.ts.map +1 -0
  33. package/dist/model/PriceFit.d.ts +75 -0
  34. package/dist/model/PriceFit.d.ts.map +1 -0
  35. package/dist/model/SymbolRequests.d.ts +34 -0
  36. package/dist/model/SymbolRequests.d.ts.map +1 -0
  37. package/dist/widget/ChartWidget.d.ts +1 -1
  38. package/dist/widget/ChartWidget.d.ts.map +1 -1
  39. package/dist/widget/ChartWidgetGrid.d.ts +2 -2
  40. package/dist/widget/ChartWidgetGrid.d.ts.map +1 -1
  41. package/dist/widget/index.cjs +22 -22
  42. package/dist/widget/index.cjs.map +1 -1
  43. package/dist/widget/index.js +1774 -1761
  44. package/dist/widget/index.js.map +1 -1
  45. package/dist/widget/types.d.ts +8 -1
  46. package/dist/widget/types.d.ts.map +1 -1
  47. package/package.json +3 -3
  48. package/dist/LayoutSession-DQLEWUw6.cjs +0 -2
  49. package/dist/LayoutSession-DQLEWUw6.cjs.map +0 -1
  50. package/dist/LayoutSession-EEUFJm3J.js.map +0 -1
  51. package/dist/PaneManager.d.ts +0 -19
  52. 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, timestampToBarIndex as N, toHeikinAshi as Ht, toKagi as Ut, toLineBreak as Wt, toRangeBars as Gt, toRenko as Kt, whenGpuContextFree as qt, withResampling as P, xToBarIndex as Jt, xToTime as F, yToPrice as Yt } 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 Xt = 864e5, Zt = 10;
5
- function Qt(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 Qt(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 - Zt); 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 < Xt)) 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 $t = {
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), en = [
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
- ], tn = 400, nn = 1e3, rn = class {
44
+ ], rn = 400, an = 1e3, on = class {
45
45
  live;
46
46
  help;
47
47
  labels;
@@ -55,20 +55,20 @@ var $t = {
55
55
  };
56
56
  constructor(e, t, n = {}) {
57
57
  this.container = e, this.source = t, this.labels = {
58
- ...$t,
58
+ ...tn,
59
59
  ...n
60
60
  };
61
- for (let t of en) this.before.set(t, e.getAttribute(t));
62
- e.setAttribute("role", "application"), this.help = an("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 = an("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
- ...$t,
66
+ ...tn,
67
67
  ...e
68
68
  }, this.applyLabels();
69
69
  }
70
70
  refresh(e = !1) {
71
- let t = nn - (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 $t = {
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
- }, tn);
83
+ }, rn);
84
84
  }
85
85
  readBar(e) {
86
86
  let t = this.source.bars();
@@ -93,13 +93,13 @@ var $t = {
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: on(i.volume ?? 0)
102
+ volume: cn(i.volume ?? 0)
103
103
  }));
104
104
  }
105
105
  destroy() {
@@ -118,7 +118,7 @@ var $t = {
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 $t = {
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 $t = {
140
140
  this.live.textContent = e;
141
141
  }
142
142
  };
143
- function an(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 an(e, t) {
154
154
  border: "0"
155
155
  }), n;
156
156
  }
157
- function on(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 sn = 3, cn = {
162
+ var ln = 3, un = {
163
163
  stochrsi: 4,
164
164
  ichimoku: 4
165
165
  };
166
- function ln(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, cn[e] ?? sn).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 ln(e, t, n, r) {
173
173
  }
174
174
  //#endregion
175
175
  //#region src/charts/ChartTypeStrategy.ts
176
- function un(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 dn(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 Ht(t);
202
+ case "heikinAshi": return Wt(t);
203
203
  case "renko": {
204
204
  let e = n.renko?.boxSize;
205
- return typeof e == "number" ? Kt(t, { brickSize: e }, i) : Kt(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 Wt(t, n.lineBreak?.lines ?? 3);
212
- case "kagi": return Ut(t, n.kagi?.reversal ?? 4, n.kagi?.reversalType ?? "percent", i);
213
- case "pointAndFigure": return pn(t, n, i).columns;
214
- case "rangeBars": return Gt(t, {
215
- rangeSize: Cn(t, n, r),
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
+ rangeSize: wn(t, n, r),
216
216
  includeForming: !0
217
217
  }, i);
218
218
  default: return t;
219
219
  }
220
220
  }
221
- function fn(e) {
221
+ function mn(e) {
222
222
  switch (e) {
223
223
  case "heikinAshi":
224
224
  case "renko":
@@ -229,72 +229,72 @@ function fn(e) {
229
229
  default: return !1;
230
230
  }
231
231
  }
232
- function L(e) {
233
- return e !== "heikinAshi" && fn(e);
232
+ function I(e) {
233
+ return e !== "heikinAshi" && mn(e);
234
234
  }
235
- function pn(e, t = {}, n) {
236
- return Lt(e, gn(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 mn = 50, hn = .01;
239
- function gn(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 = _n(e, e.length > 1 ? e.length - 1 : e.length);
243
- return r > 0 ? Sn(te(r / mn, !0)) : Math.abs(e[e.length - 1]?.close ?? 0) * hn || 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 _n(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 vn = 100, yn = 3, bn = .01, xn = 15, Sn = (e) => Number(e.toPrecision(xn));
252
- function Cn(e, t = {}, n) {
251
+ var bn = 100, xn = 3, Sn = .01, Cn = 15, L = (e) => Number(e.toPrecision(Cn));
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 >= yn ? Tn(e) : 0, a = Math.abs(e[e.length - 1]?.close ?? 0);
256
- return On(Sn(te(i > 0 ? i : a * bn || 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
- function wn(e) {
258
+ function Tn(e) {
259
259
  let t = e.length - 1;
260
260
  return {
261
- from: Math.max(0, t - vn),
261
+ from: Math.max(0, t - bn),
262
262
  end: t
263
263
  };
264
264
  }
265
- function Tn(e) {
266
- let { from: t, end: n } = wn(e), r = 0;
265
+ function En(e) {
266
+ let { from: t, end: n } = Tn(e), r = 0;
267
267
  for (let i = t; i < n; i++) {
268
268
  let { high: t, low: n } = e[i], a = i > 0 ? e[i - 1].close : n;
269
269
  r += Math.max(t - n, Math.abs(t - a), Math.abs(n - a));
270
270
  }
271
271
  return n > t ? r / (n - t) : 0;
272
272
  }
273
- function En(e, t) {
274
- let { from: n, end: r } = wn(e);
273
+ function Dn(e, t) {
274
+ let { from: n, end: r } = Tn(e);
275
275
  if (r <= n) return t(e[e.length - 1]?.close ?? 0);
276
276
  let i = -Infinity, a = Infinity;
277
277
  for (let t = n; t < r; t++) i = Math.max(i, e[t].high), a = Math.min(a, e[t].low);
278
- return Dn(t(i), t(a));
279
- }
280
- function Dn(e, t) {
281
- return e === void 0 ? t : t === void 0 ? e : Math.max(e, t);
278
+ return On(t(i), t(a));
282
279
  }
283
280
  function On(e, t) {
284
- return t === void 0 || !(t > 0) ? e : Sn(Math.max(1, Math.round(e / t)) * t);
281
+ return e === void 0 ? t : t === void 0 ? e : Math.max(e, t);
285
282
  }
286
283
  function kn(e, t) {
284
+ return t === void 0 || !(t > 0) ? e : L(Math.max(1, Math.round(e / t)) * t);
285
+ }
286
+ function An(e, t) {
287
287
  let n = t?.(e);
288
- return n ? n.createRenderer() : un(e);
288
+ return n ? n.createRenderer() : fn(e);
289
289
  }
290
- function An(e, t, n, r, i, a) {
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) : dn(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
297
- var jn = class {
297
+ var Mn = class {
298
298
  timer = null;
299
299
  delayMs = 0;
300
300
  key = null;
@@ -329,7 +329,7 @@ function R(e) {
329
329
  let { open: t, high: n, low: r, close: i } = e;
330
330
  return !(!isFinite(t) || !isFinite(n) || !isFinite(r) || !isFinite(i) || t < 0 || n < 0 || r < 0 || i < 0 || n < r || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0));
331
331
  }
332
- function Mn(e) {
332
+ function Nn(e) {
333
333
  return e.volume !== void 0 && e.high >= e.open && e.high >= e.close && e.low <= e.open && e.low <= e.close;
334
334
  }
335
335
  function z(e) {
@@ -343,24 +343,24 @@ function z(e) {
343
343
  function B(e, t) {
344
344
  return e === t || e.time === t.time && e.open === t.open && e.high === t.high && e.low === t.low && e.close === t.close && e.volume === t.volume;
345
345
  }
346
- function Nn(e, t) {
346
+ function Pn(e, t) {
347
347
  for (let n = e.length - 1; n >= 0; n--) {
348
348
  if (e[n].time === t) return n;
349
349
  if (e[n].time < t) return -1;
350
350
  }
351
351
  return -1;
352
352
  }
353
- var Pn = {
353
+ var Fn = {
354
354
  index: -1,
355
355
  changed: !1
356
356
  };
357
- function Fn(e, t) {
357
+ function In(e, t) {
358
358
  if (e.length === 0) return t;
359
359
  let n = b(t);
360
360
  return u(e) === 1 ? n : n / 1e3;
361
361
  }
362
- function In(e, t) {
363
- let n = Fn(e, t.time);
362
+ function Ln(e, t) {
363
+ let n = In(e, t.time);
364
364
  return n === t.time ? t : {
365
365
  ...t,
366
366
  time: n
@@ -368,66 +368,70 @@ function In(e, t) {
368
368
  }
369
369
  var V = class {
370
370
  data = [];
371
+ changes = 0;
371
372
  withSeriesTime(e) {
372
- return In(this.data, e);
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
- R(r) && t.push(Mn(r) ? r : z(r));
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 = [];
387
391
  for (let r = 0; r < e.length; r++) {
388
392
  if (!R(e[r])) continue;
389
393
  let i = this.withSeriesTime(e[r]);
390
- i.time >= t || n.push(Mn(i) ? i : z(i));
394
+ i.time >= t || n.push(Nn(i) ? i : z(i));
391
395
  }
392
396
  if (n.length === 0) return 0;
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
  }
408
412
  this.data[this.data.length - 1] = t;
409
413
  }
410
414
  replaceBar(e) {
411
- if (!R(e)) return Pn;
412
- let t = this.withSeriesTime(e), n = Nn(this.data, t.time);
413
- if (n < 0) return Pn;
415
+ if (!R(e)) return Fn;
416
+ let t = this.withSeriesTime(e), n = Pn(this.data, t.time);
417
+ if (n < 0) return Fn;
414
418
  let r = z(t);
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",
@@ -440,7 +444,7 @@ function U(e, t) {
440
444
  let r = b(t.time), i = b(n.time);
441
445
  return r > i ? "append" : r === i ? "update" : "stale";
442
446
  }
443
- function Ln(e) {
447
+ function Rn(e) {
444
448
  return [
445
449
  e.time,
446
450
  e.open,
@@ -449,7 +453,7 @@ function Ln(e) {
449
453
  e.close
450
454
  ].every(Number.isFinite);
451
455
  }
452
- var Rn = class {
456
+ var zn = class {
453
457
  shown = new V();
454
458
  whole = null;
455
459
  aside = null;
@@ -466,6 +470,9 @@ var Rn = 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
  }
@@ -489,7 +496,7 @@ var Rn = class {
489
496
  }
490
497
  let t = null, n = e;
491
498
  if (this.whole) {
492
- let r = this.whole[0]?.time, i = /* @__PURE__ */ new Set(), a = e.filter(Ln).map((e) => this.inSeriesUnit(e)).filter((e) => (r === void 0 || e.time < r) && !i.has(e.time) && i.add(e.time)).sort((e, t) => e.time - t.time);
499
+ let r = this.whole[0]?.time, i = /* @__PURE__ */ new Set(), a = e.filter(Rn).map((e) => this.inSeriesUnit(e)).filter((e) => (r === void 0 || e.time < r) && !i.has(e.time) && i.add(e.time)).sort((e, t) => e.time - t.time);
493
500
  this.whole = [...a, ...this.whole];
494
501
  let o = this.hoursFilter(this.whole);
495
502
  t = a.length, n = o ? a.filter((e) => o(e.time)) : a;
@@ -501,8 +508,8 @@ var Rn = class {
501
508
  };
502
509
  }
503
510
  mergeSnapshot(e) {
504
- if (this.aside) return this.aside.setData(zn(this.aside.getData(), e) ?? e), this.onLiveChange({ kind: "series" }), !0;
505
- let t = zn(this.whole ?? this.shown.getData(), e);
511
+ if (this.aside) return this.aside.setData(Bn(this.aside.getData(), e) ?? e), this.onLiveChange({ kind: "series" }), !0;
512
+ let t = Bn(this.whole ?? this.shown.getData(), e);
506
513
  return t ? (this.shown.setData(this.regularOnly(t)), !0) : !1;
507
514
  }
508
515
  refilter() {
@@ -559,7 +566,7 @@ var Rn = class {
559
566
  mergeTick(e) {
560
567
  if (this.aside) return this.aside.updateLastBarFromTick(e), this.wrote("aside", !1);
561
568
  let t = this.whole ? this.hoursFilter(this.whole) : null;
562
- if (t && this.whole && !t(Fn(this.whole, e.time))) return this.wrote("hidden", !1);
569
+ if (t && this.whole && !t(In(this.whole, e.time))) return this.wrote("hidden", !1);
563
570
  let n = this.shown.getLength();
564
571
  this.shown.updateLastBarFromTick(e);
565
572
  let r = this.whole, i = this.shown.getData()[this.shown.getLength() - 1];
@@ -602,7 +609,7 @@ var Rn = class {
602
609
  });
603
610
  }
604
611
  if (!R(e)) return H;
605
- let t = this.inSeriesUnit(e), n = this.whole, r = n ? Nn(n, t.time) : -1;
612
+ let t = this.inSeriesUnit(e), n = this.whole, r = n ? Pn(n, t.time) : -1;
606
613
  if (n) {
607
614
  if (r < 0 || !R(n[r])) return H;
608
615
  let e = this.hoursFilter(n);
@@ -636,7 +643,7 @@ var Rn = class {
636
643
  this.shown.updateLastBar(e);
637
644
  }
638
645
  inSeriesUnit(e) {
639
- return In(this.whole ?? this.shown.getData(), e);
646
+ return Ln(this.whole ?? this.shown.getData(), e);
640
647
  }
641
648
  replaceHidden(e, t, n) {
642
649
  let r = z(n), i = !B(e[t], r);
@@ -673,14 +680,492 @@ var Rn = class {
673
680
  return !r || r(e.time);
674
681
  }
675
682
  };
676
- function zn(e, t) {
683
+ function Bn(e, t) {
677
684
  let n = t[0]?.time, r = 0;
678
685
  for (; n !== void 0 && r < e.length && e[r].time < n;) r++;
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 Bn = 5e3, Vn = 6e4, Hn = 500, Un = class {
1168
+ var dr = 5e3, fr = 6e4, pr = 500, mr = class {
684
1169
  loader = null;
685
1170
  pageSize = 500;
686
1171
  loading = !1;
@@ -732,11 +1217,14 @@ var Bn = 5e3, Vn = 6e4, Hn = 500, Un = class {
732
1217
  try {
733
1218
  r = await e(t, this.pageSize);
734
1219
  } catch (e) {
735
- return n === this.seq ? (this.loading = !1, this.failures++, this.retryAt = this.now() + Math.min(Vn, Bn * 2 ** (this.failures - 1)), this.emit({
1220
+ return n === this.seq ? (this.loading = !1, e instanceof Error && e.name === "AbortError" ? (this.emit({
1221
+ state: "loaded",
1222
+ count: 0
1223
+ }), 0) : (this.failures++, this.retryAt = this.now() + Math.min(fr, dr * 2 ** (this.failures - 1)), this.emit({
736
1224
  state: "error",
737
1225
  count: 0,
738
1226
  error: e instanceof Error ? e.message : String(e)
739
- }), 0) : 0;
1227
+ }), 0)) : 0;
740
1228
  }
741
1229
  if (n !== this.seq) return 0;
742
1230
  this.loading = !1, this.failures = 0, this.retryAt = 0;
@@ -765,10 +1253,10 @@ var Bn = 5e3, Vn = 6e4, Hn = 500, Un = class {
765
1253
  };
766
1254
  //#endregion
767
1255
  //#region src/ThemeManager.ts
768
- function Wn(e, t) {
1256
+ function hr(e, t) {
769
1257
  return e.family === t.family && e.sizeSmall === t.sizeSmall && e.sizeMedium === t.sizeMedium && e.sizeLarge === t.sizeLarge;
770
1258
  }
771
- var Gn = class t {
1259
+ var gr = class t {
772
1260
  base;
773
1261
  shape = null;
774
1262
  font = null;
@@ -787,13 +1275,13 @@ var Gn = class t {
787
1275
  return i;
788
1276
  }
789
1277
  getTheme() {
790
- 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;
791
1279
  }
792
1280
  getBaseTheme() {
793
1281
  return this.base;
794
1282
  }
795
1283
  setTheme(e) {
796
- let n = t.read(e), r = this.font !== null && Wn(n.font, this.base.font);
1284
+ let n = t.read(e), r = this.font !== null && hr(n.font, this.base.font);
797
1285
  this.base = n, r || (this.themeFont = n.font), this.shape && (this.base = {
798
1286
  ...this.base,
799
1287
  shape: {
@@ -875,7 +1363,7 @@ var Gn = class t {
875
1363
  };
876
1364
  //#endregion
877
1365
  //#region src/style/styleOptions.ts
878
- function Kn(e, t) {
1366
+ function _r(e, t) {
879
1367
  return t ? {
880
1368
  ...t.visible === void 0 ? {} : { [`crosshair.${e}.visible`]: t.visible },
881
1369
  ...t.color === void 0 ? {} : { [`crosshair.${e}.color`]: t.color },
@@ -883,22 +1371,22 @@ function Kn(e, t) {
883
1371
  ...t.width === void 0 ? {} : { [`crosshair.${e}.width`]: t.width }
884
1372
  } : {};
885
1373
  }
886
- function qn(e) {
1374
+ function vr(e) {
887
1375
  let { grid: t, crosshair: n } = e, r = n?.vLine?.labelBackground ?? n?.hLine?.labelBackground;
888
1376
  return {
889
1377
  ...t?.hLineColor === void 0 ? {} : { "grid.horizontal.color": t.hLineColor },
890
1378
  ...t?.hLineStyle === void 0 ? {} : { "grid.horizontal.style": t.hLineStyle },
891
1379
  ...t?.vLineColor === void 0 ? {} : { "grid.vertical.color": t.vLineColor },
892
1380
  ...t?.vLineStyle === void 0 ? {} : { "grid.vertical.style": t.vLineStyle },
893
- ...Kn("horizontal", n?.hLine),
894
- ...Kn("vertical", n?.vLine),
1381
+ ..._r("horizontal", n?.hLine),
1382
+ ..._r("vertical", n?.vLine),
895
1383
  ...r === void 0 ? {} : { "crosshair.labelBackground": r },
896
1384
  ...e.overrides
897
1385
  };
898
1386
  }
899
1387
  //#endregion
900
1388
  //#region src/layout/LayoutManager.ts
901
- var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom", Xn = class {
1389
+ var yr = 200, br = 80, G = (e) => e.position === "top" || e.position === "bottom", xr = class {
902
1390
  panels = [];
903
1391
  containerWidth = 0;
904
1392
  containerHeight = 0;
@@ -915,8 +1403,8 @@ var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom
915
1403
  this.panels.push({
916
1404
  id: e,
917
1405
  position: n,
918
- size: r ?? (a ? Jn : t),
919
- minSize: a ? Yn : i,
1406
+ size: r ?? (a ? yr : t),
1407
+ minSize: a ? br : i,
920
1408
  content: {
921
1409
  type: "indicator",
922
1410
  indicatorInstanceId: e
@@ -935,14 +1423,14 @@ var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom
935
1423
  }
936
1424
  setPanelCollapsed(e, t) {
937
1425
  let n = this.panels.find((t) => t.id === e);
938
- 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);
939
1427
  }
940
1428
  isPanelCollapsed(e) {
941
1429
  return !!this.panels.find((t) => t.id === e)?.collapsed;
942
1430
  }
943
1431
  isPanelShownCollapsed(e) {
944
1432
  let t = this.panels.find((t) => t.id === e);
945
- 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;
946
1434
  }
947
1435
  setPanelScale(e, t) {
948
1436
  let n = this.panels.find((t) => t.id === e);
@@ -958,7 +1446,7 @@ var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom
958
1446
  }
959
1447
  setMaximizedPanel(e) {
960
1448
  let t = e === null ? null : this.panels.find((t) => t.id === e);
961
- 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);
962
1450
  }
963
1451
  getMaximizedPanel() {
964
1452
  return this.maximized;
@@ -979,19 +1467,19 @@ var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom
979
1467
  this.panels = [...this.panels].sort((e, n) => t(e) - t(n));
980
1468
  }
981
1469
  shownSize(e, t) {
982
- 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;
983
1471
  }
984
1472
  setPanelPosition(e, n) {
985
1473
  let r = this.panels.find((t) => t.id === e);
986
1474
  if (r) {
987
1475
  let a = r.position === "left" || r.position === "right", o = n === "left" || n === "right";
988
- r.position = n, a !== o && (r.size = o ? Jn : t, r.minSize = o ? Yn : 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));
989
1477
  }
990
1478
  }
991
1479
  setPanelSize(e, t) {
992
1480
  let n = this.panels.find((t) => t.id === e);
993
1481
  if (n) {
994
- 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;
995
1483
  n.size = Math.max(n.minSize, r), n.collapsed = void 0, this.maximized = null;
996
1484
  }
997
1485
  }
@@ -1105,8 +1593,8 @@ var Jn = 200, Yn = 80, W = (e) => e.position === "top" || e.position === "bottom
1105
1593
  getMainChartRect() {
1106
1594
  return this.resolve().mainChartRect;
1107
1595
  }
1108
- }, Zn = 14, Qn = 14, $n = 22, er = 4;
1109
- function tr(e) {
1596
+ }, Sr = 14, Cr = 14, wr = 22, Tr = 4;
1597
+ function Er(e) {
1110
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] : [
1111
1599
  t,
1112
1600
  n,
@@ -1115,16 +1603,16 @@ function tr(e) {
1115
1603
  for (let t of f) {
1116
1604
  if (!Number.isFinite(t)) continue;
1117
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);
1118
- p = Math.max(p, l(n, `500 ${s}px ${a}`) + Zn, l(r, `bold 11px ${a}`) + Qn, l(r, `600 ${s}px ${a}`) + $n);
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);
1119
1607
  }
1120
- return p <= o ? o : Math.ceil(p / er) * er;
1608
+ return p <= o ? o : Math.ceil(p / Tr) * Tr;
1121
1609
  }
1122
- function nr(e, t) {
1610
+ function Dr(e, t) {
1123
1611
  return t > e || t <= e - 12 ? t : e;
1124
1612
  }
1125
1613
  //#endregion
1126
1614
  //#region src/layout/labelWidths.ts
1127
- var rr = 512, ir = class {
1615
+ var Or = 512, kr = class {
1128
1616
  widths = /* @__PURE__ */ new Map();
1129
1617
  fonts;
1130
1618
  forget = () => this.widths.clear();
@@ -1135,12 +1623,12 @@ var rr = 512, ir = class {
1135
1623
  let r = `${t}\n${e}`, i = this.widths.get(r);
1136
1624
  if (i !== void 0) return i;
1137
1625
  let a = n();
1138
- return this.widths.size >= rr && this.widths.clear(), this.widths.set(r, a), a;
1626
+ return this.widths.size >= Or && this.widths.clear(), this.widths.set(r, a), a;
1139
1627
  }
1140
1628
  destroy() {
1141
1629
  this.fonts?.removeEventListener("loadingdone", this.forget), this.widths.clear();
1142
1630
  }
1143
- }, ar = class {
1631
+ }, Ar = class {
1144
1632
  netY = 0;
1145
1633
  travelX = 0;
1146
1634
  engaged = !1;
@@ -1156,11 +1644,11 @@ var rr = 512, ir = class {
1156
1644
  }
1157
1645
  return this.engaged;
1158
1646
  }
1159
- }, or = 1;
1160
- function sr(e, t) {
1647
+ }, jr = 1;
1648
+ function Mr(e, t) {
1161
1649
  return e.filter((e) => e.enabled !== !1 && (e.descriptor.layer ?? "overlay") === t);
1162
1650
  }
1163
- function G(e) {
1651
+ function K(e) {
1164
1652
  switch (e.kind) {
1165
1653
  case "indicator": return `indicator:${e.plugin.descriptor.id}`;
1166
1654
  case "drawing": return `drawing:${e.plugin.descriptor.type}`;
@@ -1170,25 +1658,25 @@ function G(e) {
1170
1658
  }
1171
1659
  //#endregion
1172
1660
  //#region src/plugins/registry.ts
1173
- var K = /* @__PURE__ */ new Map();
1174
- function cr(e) {
1175
- K.set(G(e), e);
1661
+ var q = /* @__PURE__ */ new Map();
1662
+ function Nr(e) {
1663
+ q.set(K(e), e);
1176
1664
  }
1177
- function lr(e) {
1178
- return K.delete(e);
1665
+ function Pr(e) {
1666
+ return q.delete(e);
1179
1667
  }
1180
- function ur() {
1181
- return [...K.values()];
1668
+ function Fr() {
1669
+ return [...q.values()];
1182
1670
  }
1183
- function dr() {
1184
- K.clear();
1671
+ function Ir() {
1672
+ q.clear();
1185
1673
  }
1186
1674
  //#endregion
1187
1675
  //#region src/plugins/PluginManager.ts
1188
- var fr = class {
1676
+ var Lr = class {
1189
1677
  plugins = /* @__PURE__ */ new Map();
1190
1678
  constructor(e, t = {}) {
1191
- if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of ur()) this.add(e);
1679
+ if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of Fr()) this.add(e);
1192
1680
  for (let e of t.plugins ?? []) this.add(e);
1193
1681
  }
1194
1682
  register(e) {
@@ -1216,17 +1704,17 @@ var fr = class {
1216
1704
  return e;
1217
1705
  }
1218
1706
  add(e) {
1219
- 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);
1220
1708
  }
1221
- }, pr = {
1709
+ }, Rr = {
1222
1710
  orderPlace: (e, t) => e.placeOrder(t),
1223
1711
  orderModify: (e, t) => e.modifyOrder(t),
1224
1712
  orderCancel: (e, t) => e.cancelOrder(t),
1225
1713
  positionModify: (e, t) => e.modifyPosition(t),
1226
1714
  positionClose: (e, t) => e.closePosition(t),
1227
- positionReverse: (e, t, n) => mr(e, t, n)
1715
+ positionReverse: (e, t, n) => zr(e, t, n)
1228
1716
  };
1229
- async function mr(e, t, n) {
1717
+ async function zr(e, t, n) {
1230
1718
  let { reversing: r } = n;
1231
1719
  if (!r.has(t.positionId)) {
1232
1720
  r.add(t.positionId);
@@ -1255,7 +1743,7 @@ async function mr(e, t, n) {
1255
1743
  }
1256
1744
  }
1257
1745
  }
1258
- function hr(e, t) {
1746
+ function Br(e, t) {
1259
1747
  let n = [], r = null, i = {
1260
1748
  positions: () => r ?? t.getPositions?.() ?? [],
1261
1749
  reversing: /* @__PURE__ */ new Set()
@@ -1265,8 +1753,8 @@ function hr(e, t) {
1265
1753
  e.data && t.onFill?.(e.data);
1266
1754
  };
1267
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));
1268
- for (let r of Object.keys(pr)) {
1269
- let a = pr[r], o = t.onIntent(r, (n) => {
1756
+ for (let r of Object.keys(Rr)) {
1757
+ let a = Rr[r], o = t.onIntent(r, (n) => {
1270
1758
  Promise.resolve(a(e, n, i)).catch((e) => t.onError({
1271
1759
  message: `Execution command failed: ${r}`,
1272
1760
  cause: e
@@ -1280,7 +1768,7 @@ function hr(e, t) {
1280
1768
  }
1281
1769
  //#endregion
1282
1770
  //#region src/replay/ReplayStepLoader.ts
1283
- var gr = 1e3, _r = class {
1771
+ var Vr = 1e3, Hr = class {
1284
1772
  pieces = /* @__PURE__ */ new Map();
1285
1773
  asked = /* @__PURE__ */ new Set();
1286
1774
  inFlight = !1;
@@ -1313,7 +1801,7 @@ var gr = 1e3, _r = class {
1313
1801
  this.done = !0;
1314
1802
  }
1315
1803
  ask(e, t) {
1316
- let { ratio: n, barMs: r, step: i, report: a } = this.options, o = Math.max(1, Math.floor(gr / 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);
1317
1805
  for (let e of l) this.asked.add(e.time);
1318
1806
  this.inFlight = !0, a({
1319
1807
  state: "loading",
@@ -1354,12 +1842,12 @@ var gr = 1e3, _r = class {
1354
1842
  ...n === void 0 ? {} : { error: n }
1355
1843
  });
1356
1844
  }
1357
- }, vr = 1 / 3, yr = .25, br = .5;
1358
- function xr(e, t) {
1359
- let n = (e.high - e.low) * yr;
1360
- return t.filter((t) => t.close > e.high + n || t.close < e.low - n).length <= t.length * br;
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;
1361
1849
  }
1362
- function Sr(e) {
1850
+ function qr(e) {
1363
1851
  return e.close >= e.open ? [
1364
1852
  e.open,
1365
1853
  e.low,
@@ -1372,22 +1860,22 @@ function Sr(e) {
1372
1860
  e.close
1373
1861
  ];
1374
1862
  }
1375
- function Cr(e, t, n) {
1376
- let r = Sr(e), i = [
1863
+ function Jr(e, t, n) {
1864
+ let r = qr(e), i = [
1377
1865
  1,
1378
1866
  2,
1379
1867
  3
1380
1868
  ].map((e) => Math.abs(r[e] - r[e - 1])), a = i[0] + i[1] + i[2], o = [], s = 0;
1381
1869
  return r.forEach((r, c) => {
1382
- c > 0 && (s += a > 0 ? i[c - 1] / a : vr), !(c === 0 && t > 0) && o.push({
1870
+ c > 0 && (s += a > 0 ? i[c - 1] / a : Ur), !(c === 0 && t > 0) && o.push({
1383
1871
  price: r,
1384
1872
  time: e.time,
1385
1873
  at: (t + s) / n
1386
1874
  });
1387
1875
  }), o;
1388
1876
  }
1389
- function wr(e, t = []) {
1390
- let n = t.length > 0 && xr(e, t) ? t : [e], r = n.length, i = Tr(n.flatMap((e, t) => Cr(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;
1391
1879
  return {
1392
1880
  bar: e,
1393
1881
  points: i,
@@ -1397,7 +1885,7 @@ function wr(e, t = []) {
1397
1885
  }))
1398
1886
  };
1399
1887
  }
1400
- function Tr(e, t) {
1888
+ function Xr(e, t) {
1401
1889
  let n = e.length - 1, r = e.map((e, r) => ({
1402
1890
  ...e,
1403
1891
  price: r === 0 ? t.open : r === n ? t.close : Math.min(t.high, Math.max(t.low, e.price))
@@ -1412,7 +1900,7 @@ function Tr(e, t) {
1412
1900
  };
1413
1901
  return i(t.high, (e, t) => e > t), i(t.low, (e, t) => e < t), r;
1414
1902
  }
1415
- function Er(e, t) {
1903
+ function Zr(e, t) {
1416
1904
  let n = e.points;
1417
1905
  if (t <= n[0].at) return n[0].price;
1418
1906
  for (let e = 1; e < n.length; e++) if (t <= n[e].at) {
@@ -1421,8 +1909,8 @@ function Er(e, t) {
1421
1909
  }
1422
1910
  return n[n.length - 1].price;
1423
1911
  }
1424
- var Dr = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0;
1425
- function Or(e, t) {
1912
+ var Qr = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0;
1913
+ function $r(e, t) {
1426
1914
  let n = 0, r = 0;
1427
1915
  for (let i of e.volumeAt) {
1428
1916
  if (t >= i.at) {
@@ -1433,10 +1921,10 @@ function Or(e, t) {
1433
1921
  }
1434
1922
  return n;
1435
1923
  }
1436
- function kr(e, t) {
1437
- let n = Dr(t);
1924
+ function ei(e, t) {
1925
+ let n = Qr(t);
1438
1926
  if (n >= 1) return { ...e.bar };
1439
- let r = Er(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);
1440
1928
  for (let t of e.points) {
1441
1929
  if (t.at > n) break;
1442
1930
  i = Math.max(i, t.price), a = Math.min(a, t.price);
@@ -1447,29 +1935,29 @@ function kr(e, t) {
1447
1935
  high: i,
1448
1936
  low: a,
1449
1937
  close: r,
1450
- volume: Or(e, n)
1938
+ volume: $r(e, n)
1451
1939
  };
1452
1940
  }
1453
- function Ar(e, t) {
1454
- let n = Dr(t), r = 0;
1941
+ function ti(e, t) {
1942
+ let n = Qr(t), r = 0;
1455
1943
  for (let t of e.points) {
1456
1944
  if (t.at > n) break;
1457
1945
  r = t.at;
1458
1946
  }
1459
1947
  return r;
1460
1948
  }
1461
- function q(e, t, n) {
1949
+ function J(e, t, n) {
1462
1950
  let r = [], i = e.bar.time;
1463
1951
  for (let a of e.points) {
1464
1952
  if (a.at > n) break;
1465
1953
  i = a.time, a.at > t && r.push([a.price, a.time]);
1466
1954
  }
1467
- let a = Er(e, n);
1955
+ let a = Zr(e, n);
1468
1956
  return (r.length === 0 || r[r.length - 1][0] !== a) && r.push([a, i]), r;
1469
1957
  }
1470
1958
  //#endregion
1471
1959
  //#region src/replay/replayStep.ts
1472
- var jr = [
1960
+ var ni = [
1473
1961
  "1m",
1474
1962
  "3m",
1475
1963
  "5m",
@@ -1480,51 +1968,44 @@ var jr = [
1480
1968
  "4h",
1481
1969
  "1d"
1482
1970
  ];
1483
- function Mr(e, t) {
1484
- let n = w(e);
1485
- return n > 0 ? jr.filter((e) => {
1486
- 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);
1487
1975
  return r < n && n % r === 0 && t(e);
1488
1976
  }) : [];
1489
1977
  }
1490
- function Nr(e, t, n) {
1491
- let r = Mr(t, n);
1978
+ function ii(e, t, n) {
1979
+ let r = ri(t, n);
1492
1980
  if (e !== "auto") return r.includes(e) ? e : null;
1493
- let i = w(t);
1494
- return r.find((e) => i / w(e) <= 60) ?? null;
1981
+ let i = T(t);
1982
+ return r.find((e) => i / T(e) <= 60) ?? null;
1495
1983
  }
1496
1984
  //#endregion
1497
1985
  //#region src/Chart.ts
1498
- var Pr = {
1499
- min: 0,
1500
- max: 100
1501
- }, Fr = "exchange", Ir = Fr;
1502
- function Lr(e) {
1986
+ var ai = "exchange", oi = ai;
1987
+ function si(e) {
1503
1988
  if (typeof e == "string" && e !== "exchange" && !y(e)) throw RangeError(`Unknown time zone: ${e}`);
1504
1989
  if (typeof e == "number" && !Number.isFinite(e)) throw RangeError(`Invalid UTC offset: ${e}`);
1505
1990
  }
1506
- function Rr(e, t) {
1507
- 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);
1508
1993
  return i === void 0 ? e : {
1509
1994
  ...e,
1510
1995
  timeZone: i,
1511
1996
  timezone: i
1512
1997
  };
1513
1998
  }
1514
- var zr = .08, Br = a ** -7, Vr = 800, Hr = 24;
1515
- function Ur(e) {
1516
- return e.length > 0 ? { renames: e } : {};
1517
- }
1518
- var Wr = 20, Gr = 8, Kr = 10, qr = {
1999
+ var li = .08, ui = 20, di = 8, fi = 10, pi = {
1519
2000
  ArrowLeft: [-1, 0],
1520
2001
  ArrowRight: [1, 0],
1521
2002
  ArrowUp: [0, -1],
1522
2003
  ArrowDown: [0, 1]
1523
- }, Jr = new Set(["horizontalLine", "crossLine"]), Yr = new Set(["verticalLine", "crossLine"]), Xr = class {
1524
- static version = "1.68.1";
2004
+ }, mi = new Set(["horizontalLine", "crossLine"]), hi = new Set(["verticalLine", "crossLine"]), gi = class {
2005
+ static version = "1.70.0";
1525
2006
  engine;
1526
2007
  viewport;
1527
- series = new Rn((e) => this.sessionKeep(e), (e) => this.followLiveChange(e));
2008
+ series = new zn((e) => this.sessionKeep(e), (e) => this.followLiveChange(e));
1528
2009
  themeManager;
1529
2010
  layoutManager;
1530
2011
  pluginManager;
@@ -1538,20 +2019,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1538
2019
  executionAdapter = null;
1539
2020
  execTeardown = null;
1540
2021
  autoScrollOnNewBar = !0;
1541
- displayDataCache = null;
1542
2022
  indicatorsOnDrawn = null;
1543
- reshapeMemo = new lt();
1544
- displayDataStep;
2023
+ display;
1545
2024
  indicatorUpdateFrom = null;
1546
- resolvedLayoutCache = null;
1547
- panelInfoCache = null;
1548
- paneStyles = /* @__PURE__ */ new Map();
2025
+ panes;
2026
+ indicatorPanes;
2027
+ indicatorHistory;
1549
2028
  lastBackground = null;
1550
2029
  renderScheduled = !1;
1551
2030
  renderDeferred = !1;
1552
2031
  priceAxisWidth = o;
1553
2032
  measureCtx;
1554
- labelWidths = new ir();
2033
+ labelWidths = new kr();
1555
2034
  containerSizeCache = null;
1556
2035
  containerSizeCacheTime = 0;
1557
2036
  lastEmittedRange = null;
@@ -1562,11 +2041,9 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1562
2041
  watermark;
1563
2042
  barCountdown;
1564
2043
  unrestoredIndicators = [];
1565
- indicatorHistoryDepth = 0;
1566
- indicatorEdit = null;
1567
2044
  removedDrawingAlerts = /* @__PURE__ */ new Map();
1568
2045
  zoomAreaMode = !1;
1569
- priceAxisAddButton = new rt();
2046
+ priceAxisAddButton = new nt();
1570
2047
  displayTz = null;
1571
2048
  timeZoneSetting = null;
1572
2049
  symbolInfo = null;
@@ -1577,7 +2054,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1577
2054
  studyZoneReleaseQueued = !1;
1578
2055
  sessionBreaks;
1579
2056
  sessionShading;
1580
- hostSessionHours = { ...je };
2057
+ hostSessionHours = { ...Ae };
1581
2058
  compareRenderer;
1582
2059
  countdownInterval = null;
1583
2060
  pausedFor = {
@@ -1611,7 +2088,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1611
2088
  replayForming = null;
1612
2089
  replayPhaseUnsub = null;
1613
2090
  undoRedoManager;
1614
- autoSaveScheduler = new jn((e) => this.saveState(e));
2091
+ autoSaveScheduler = new Mn((e) => this.saveState(e));
1615
2092
  animator;
1616
2093
  crosshairTooltip;
1617
2094
  pinnedTooltip;
@@ -1623,14 +2100,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1623
2100
  disposed = !1;
1624
2101
  chartTypeOptions = {};
1625
2102
  mainSeriesVisible = !0;
1626
- priceLines = new it();
2103
+ priceLines = new rt();
1627
2104
  symbolSeries = new vt();
1628
2105
  extendedHours = !0;
1629
2106
  replayRestarting = !1;
1630
- requestedSymbols = /* @__PURE__ */ new Set();
2107
+ symbolRequests;
1631
2108
  gridRenderer;
1632
2109
  priceAxis;
1633
- leftPriceAxis = new nt();
2110
+ leftPriceAxis = new tt();
1634
2111
  leftScaleRequested = !1;
1635
2112
  leftAxisWidth = o;
1636
2113
  leftViewport = null;
@@ -1645,9 +2122,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1645
2122
  priceFormatter = null;
1646
2123
  priceUnit = null;
1647
2124
  paneTitles = !0;
1648
- defaultAutoScale;
1649
- priceFitPending = !0;
1650
- seriesArriving = !0;
2125
+ priceFit;
1651
2126
  keyboardHandler = null;
1652
2127
  a11y = null;
1653
2128
  onWindowKeyDown = null;
@@ -1663,10 +2138,20 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1663
2138
  snapshotKey = null;
1664
2139
  historyCheckQueued = !1;
1665
2140
  constructor(e, t) {
1666
- t.timeZone != null && Lr(t.timeZone), this.container = e, this.options = {
2141
+ t.timeZone != null && si(t.timeZone), this.container = e, this.options = {
1667
2142
  ...t,
1668
2143
  chartType: t.chartType ?? "candlestick"
1669
- }, 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
+ });
1670
2155
  let n = t.features ?? {};
1671
2156
  this.features = {
1672
2157
  drawings: n.drawings ?? !0,
@@ -1702,15 +2187,23 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1702
2187
  logScale: n.logScale ?? !0,
1703
2188
  timeframes: n.timeframes ?? [],
1704
2189
  defaultTimeframeFavorites: n.defaultTimeframeFavorites ?? []
1705
- }, 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 Un({
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({
1706
2191
  oldestTime: () => (this.replaySession ? this.series.liveBars() : this.series.bars())[0]?.time ?? null,
1707
2192
  prepend: (e) => this.prependBars(e),
1708
2193
  emit: (e) => this.eventBus.emit("historyLoad", e)
1709
- }), this.themeManager = new Gn(t.theme), this.themeManager.setChartType(this.options.chartType ?? "candlestick"), this.applyStyle(qn(t), "host", !1), this.layoutManager = new Xn(), this.indicatorEngine = new Ve(), this.pluginManager = new fr(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(() => {
1710
2199
  this.syncRenderContext(), this.engine.requestRender(r.Overlay), this.scheduleAutoSave();
1711
2200
  }), this.drawingManager.setEventCallback((e, t) => {
1712
2201
  this.followDrawingAlerts(e, t?.id), this.eventBus.emit(e, t), (e === "drawingCreate" || e === "drawingUpdate" || e === "drawingRemove") && this.announceStateChange();
1713
- }), 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
+ });
1714
2207
  let i = "";
1715
2208
  this.undoRedoManager.setOnChange(() => {
1716
2209
  let { canUndo: e, canRedo: t } = this.undoRedoManager.getState(), n = `${e}|${t}`;
@@ -1728,7 +2221,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1728
2221
  contextMenu: { enabled: this.features.tradingContextMenu }
1729
2222
  }), this.tradingRenderer = new St(this.tradingManager), this.tradingManager.setContainer(e), this.tradingManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradingManager.setEventCallback((e, t) => {
1730
2223
  this.eventBus.emit(e, t);
1731
- }), this.engine = new at(e, t.maxPixelRatio);
2224
+ }), this.engine = new it(e, t.maxPixelRatio);
1732
2225
  let a = this.engine.dprManager.getContainerSize();
1733
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({
1734
2227
  freePan: t.freePan ?? !0,
@@ -1737,9 +2230,9 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1737
2230
  if (e.width <= 0 || e.height <= 0) return;
1738
2231
  let t = this.viewport.isAtEnd();
1739
2232
  this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(t), this.eventBus.emit("resize", e);
1740
- }, 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) => {
1741
2234
  if (e !== null && t) {
1742
- 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;
1743
2236
  this.chartLegend.setHoverBar(i ?? null, e > 0 ? n[e - 1] ?? null : null), this.features.legend && this.engine.requestRender(r.Hover);
1744
2237
  let c = this.viewport.getState(), l = t.y >= c.chartRect.y && t.y <= c.chartRect.y + c.chartRect.height;
1745
2238
  if (i && l && this.features.crosshairTooltip) {
@@ -1751,7 +2244,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1751
2244
  prevClose: a,
1752
2245
  priceRange: c.priceRange,
1753
2246
  plot: c.chartRect,
1754
- barStepMs: At(o),
2247
+ barStepMs: jt(o),
1755
2248
  timeUnit: u(o)
1756
2249
  });
1757
2250
  } else this.crosshairTooltip.hide();
@@ -1767,14 +2260,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1767
2260
  let e = this.crosshairHandler.getSyncedSlot();
1768
2261
  e !== null && this.showSyncedBar(e);
1769
2262
  }
1770
- }), 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(() => {
1771
2264
  this.eventBus.emit("legendResize", { bottom: this.getLegendBottom() }), this.engine.requestRender();
1772
- }), 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({
1773
2266
  visible: t.sessionBreaks.visible ?? !0,
1774
2267
  color: t.sessionBreaks.color,
1775
2268
  lineStyle: t.sessionBreaks.lineStyle,
1776
2269
  lineWidth: t.sessionBreaks.lineWidth
1777
- }) : 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(ni(t.shapes)), t.font && this.themeManager.setFont(ti(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({
1778
2271
  scrollBars: (e) => {
1779
2272
  let t = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
1780
2273
  this.viewport.scrollBy(e * t), this.updateViewportAndRender();
@@ -1791,7 +2284,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1791
2284
  },
1792
2285
  fitContent: () => this.fitContent()
1793
2286
  }), this.keyboardHandler.setEnabled(this.features.keyboard), t.a11y !== !1) {
1794
- this.a11y = new rn(e, {
2287
+ this.a11y = new on(e, {
1795
2288
  symbol: () => this.currentSymbol || this.symbolInfo?.symbol || "",
1796
2289
  timeframe: () => this.streamTimeframe ?? "",
1797
2290
  chartType: () => this.options.chartType ?? "candlestick",
@@ -1822,8 +2315,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1822
2315
  }
1823
2316
  this.keyboardHandler.handleKey(e) && (e.preventDefault(), this.a11y?.viewMoved());
1824
2317
  }
1825
- }, 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) => {
1826
- 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", {
1827
2320
  kind: "alert",
1828
2321
  alert: "triggered",
1829
2322
  alertId: e.id,
@@ -1831,13 +2324,13 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1831
2324
  message: e.message
1832
2325
  });
1833
2326
  }), this.alertManager.on("added", (e) => {
1834
- this.eventBus.emit("alertAdd", J(e));
2327
+ this.eventBus.emit("alertAdd", Y(e));
1835
2328
  }), this.alertManager.on("removed", (e) => {
1836
2329
  this.eventBus.emit("alertRemove", { id: e });
1837
2330
  }), this.alertManager.on("expired", (e) => {
1838
- this.eventBus.emit("alertExpired", J(e));
2331
+ this.eventBus.emit("alertExpired", Y(e));
1839
2332
  }), this.alertManager.on("updated", (e) => {
1840
- this.eventBus.emit("alertUpdate", J(e));
2333
+ this.eventBus.emit("alertUpdate", Y(e));
1841
2334
  }), this.signalMarkerManager = new mt(), this.signalMarkerManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.signalMarkerManager.setDataGetter(() => this.series.bars()), this.signalMarkerManager.on("added", (e) => {
1842
2335
  this.eventBus.emit("signalMarkerAdd", {
1843
2336
  id: e.id,
@@ -1853,7 +2346,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1853
2346
  });
1854
2347
  }), this.tradeZoneManager.on("removed", (e) => {
1855
2348
  this.eventBus.emit("tradeZoneRemove", { id: e });
1856
- }), this.replayManager = new st(), this.replayManager.on("complete", () => {
2349
+ }), this.replayManager = new ot(), this.replayManager.on("complete", () => {
1857
2350
  let e = this.getReplayBarIndex(), t = this.replayCoarse?.[e];
1858
2351
  t && this.eventBus.emit("replayComplete", {
1859
2352
  barIndex: e,
@@ -1861,15 +2354,15 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1861
2354
  });
1862
2355
  }), this.replayManager.on("stateChange", (e) => {
1863
2356
  this.replayRestarting || this.eventBus.emit("replayState", { state: e });
1864
- }), this.measureOverlay = new Je(), this.interactionManager = new He(e), this.features.panning) {
1865
- let e = new ar();
1866
- this.interactionManager.setPanHandler(new Xe((t, n) => {
1867
- 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();
1868
2361
  }, () => e.reset()));
1869
2362
  }
1870
2363
  if (this.interactionManager.setAxisStrips(() => ({
1871
2364
  plot: this.viewport.getState().chartRect,
1872
- timeAxisTop: this.timeAxisTop(),
2365
+ timeAxisTop: this.panes.timeAxisTop(),
1873
2366
  left: {
1874
2367
  width: this.isLeftPriceScaleShown() ? this.leftAxisWidth : 0,
1875
2368
  scales: !this.indicatorEngine.hasLeftScaleOverlays()
@@ -1878,14 +2371,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1878
2371
  this.interactionManager.setZoomHandler(new kt((e, t) => {
1879
2372
  this.viewport.zoom(e, t - this.viewport.getState().chartRect.x), this.updateViewportAndRender();
1880
2373
  }));
1881
- let e = new _e((e) => {
2374
+ let e = new ge((e) => {
1882
2375
  this.holdPriceScale(), this.viewport.scalePriceRange(e), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
1883
2376
  }, (e) => {
1884
2377
  let t = this.viewport.getState().chartRect.width;
1885
2378
  this.viewport.zoom(1 / e - 1, t / 2), this.updateViewportAndRender();
1886
2379
  });
1887
2380
  this.interactionManager.setAxisDragHandler(e, () => this.viewport.getState(), (e) => {
1888
- e === "price" ? (this.options.autoScale = !0, this.updateViewportAndRender()) : this.fitContent();
2381
+ e === "price" ? (this.priceFit.resume(), this.updateViewportAndRender()) : this.fitContent();
1889
2382
  });
1890
2383
  }
1891
2384
  if (this.features.crosshair && this.interactionManager.setCrosshairHandler(this.crosshairHandler), this.features.drawings && (this.interactionManager.setDrawingManager(this.drawingManager, () => ({
@@ -1903,7 +2396,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1903
2396
  y: t.y
1904
2397
  });
1905
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) => {
1906
- let t = Yt(e.y, this.viewport.getState());
2399
+ let t = Zt(e.y, this.viewport.getState());
1907
2400
  Number.isFinite(t) && this.eventBus.emit("priceAxisAdd", {
1908
2401
  price: t,
1909
2402
  x: e.x,
@@ -1913,10 +2406,10 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1913
2406
  ...this.viewport.getState(),
1914
2407
  data: this.getDisplayData()
1915
2408
  })), this.features.alerts) {
1916
- let e = new pe(this.alertManager, () => this.viewport.getState());
2409
+ let e = new fe(this.alertManager, () => this.viewport.getState());
1917
2410
  this.interactionManager.setAlertDragHandler(e);
1918
2411
  }
1919
- let o = new Ze();
2412
+ let o = new Xe();
1920
2413
  o.configure(() => this.getResolvedLayout(), (e, t) => this.setPanelSize(e, t)), this.interactionManager.setPaneResizeHandler(o), this.interactionManager.setAltClickHandler((e) => {
1921
2414
  let t = this.getDisplayData();
1922
2415
  if (t.length === 0) return;
@@ -1940,7 +2433,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1940
2433
  x: e.x,
1941
2434
  y: e.y
1942
2435
  }), t.length === 0) return;
1943
- let r = Jt(e.x, this.viewport.getState());
2436
+ let r = Xt(e.x, this.viewport.getState());
1944
2437
  r < 0 || r >= t.length || this.eventBus.emit("barClick", {
1945
2438
  bar: t[r],
1946
2439
  barIndex: r,
@@ -1985,7 +2478,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
1985
2478
  end: () => {
1986
2479
  let e = this.selectionBoxOverlay.end();
1987
2480
  if (e && this.zoomAreaMode) {
1988
- if (e.x1 - e.x0 < Gr) return;
2481
+ if (e.x1 - e.x0 < di) return;
1989
2482
  this.zoomToBox(e), this.setZoomAreaMode(!1);
1990
2483
  return;
1991
2484
  }
@@ -2020,10 +2513,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2020
2513
  this.loadDuringReplay(e);
2021
2514
  return;
2022
2515
  }
2023
- 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;
2024
- let n = this.series.bars();
2025
- this.seriesArriving = n.length === 0;
2026
- 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];
2027
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);
2028
2519
  }
2029
2520
  loadDuringReplay(e) {
@@ -2036,8 +2527,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2036
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);
2037
2528
  if (i === 0) return a;
2038
2529
  let o = this.series.bars();
2039
- 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) {
2040
- 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()));
2041
2532
  this.viewport.prependBars(e - n);
2042
2533
  }
2043
2534
  return this.updateViewportAndRender(), a;
@@ -2049,7 +2540,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2049
2540
  return;
2050
2541
  }
2051
2542
  let n = this.series.bars();
2052
- 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);
2053
2544
  }
2054
2545
  setHistoryLoader(e, t) {
2055
2546
  this.historyFromStream = !1, this.hostHistoryLoader = e !== null, this.history.setLoader(e, t?.pageSize), this.checkHistory();
@@ -2065,17 +2556,17 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2065
2556
  }
2066
2557
  checkHistory() {
2067
2558
  this.historyCheckQueued || !this.history.hasLoader() || (this.historyCheckQueued = !0, queueMicrotask(() => {
2068
- 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;
2069
2560
  let { visibleRange: e, chartRect: t } = this.viewport.getState();
2070
2561
  if (t.width <= 0) return;
2071
2562
  let { from: n, to: r } = e;
2072
- this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(Wr, r - n));
2563
+ this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(ui, r - n));
2073
2564
  }));
2074
2565
  }
2075
2566
  useStreamHistory(e, t, n = !0) {
2076
2567
  if (this.hostHistoryLoader) return;
2077
- let r = P(e), i = r.fetchHistoryBefore, a = this.streamTimeframe;
2078
- 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) {
2079
2570
  this.historyFromStream && this.history.setLoader(null), this.historyFromStream = !1;
2080
2571
  return;
2081
2572
  }
@@ -2085,33 +2576,31 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2085
2576
  appendBar(e) {
2086
2577
  if (!R(e)) return;
2087
2578
  let t = this.series.append(e);
2088
- if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
2579
+ if (t.to !== "shown") {
2089
2580
  this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
2090
2581
  return;
2091
2582
  }
2092
2583
  let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
2093
- 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);
2094
2585
  }
2095
2586
  appendBars(e) {
2096
2587
  if (e = e.filter(R), e.length === 0) return;
2097
2588
  let t = e[e.length - 1].close, n = this.series.appendMany(e);
2098
- if (n.refiltered && (this.displayDataCache = null), n.shown === 0) {
2589
+ if (n.shown === 0) {
2099
2590
  this.takeLivePrice(t), n.aside || this.scheduleRender();
2100
2591
  return;
2101
2592
  }
2102
- let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = n.before;
2103
- this.displayDataCache = null;
2104
- let a = this.series.bars();
2593
+ let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = n.before, a = this.series.bars();
2105
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);
2106
2595
  }
2107
2596
  updateLastBar(e) {
2108
2597
  if (!R(e)) return;
2109
2598
  let t = this.series.updateLast(e);
2110
- if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
2599
+ if (t.to !== "shown") {
2111
2600
  this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
2112
2601
  return;
2113
2602
  }
2114
- 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);
2115
2604
  let n = this.series.bars();
2116
2605
  this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.close), this.scheduleRender();
2117
2606
  }
@@ -2122,7 +2611,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2122
2611
  this.takeLivePrice(e.price), t.to === "hidden" && this.scheduleRender();
2123
2612
  return;
2124
2613
  }
2125
- 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);
2126
2615
  let n = this.series.bars();
2127
2616
  this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.price), this.scheduleRender();
2128
2617
  }
@@ -2133,7 +2622,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2133
2622
  }
2134
2623
  showCorrection(e) {
2135
2624
  let t = this.series.bars(), n = t[e];
2136
- 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", {
2137
2626
  kind: "correction",
2138
2627
  time: n.time,
2139
2628
  index: e
@@ -2154,29 +2643,29 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2154
2643
  }
2155
2644
  setChartType(e) {
2156
2645
  let t = this.options.chartType ?? "candlestick";
2157
- 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", {
2158
2647
  type: e,
2159
2648
  previous: t
2160
2649
  });
2161
2650
  }
2162
2651
  fitFewColumns() {
2163
2652
  let e = this.options.chartType;
2164
- if (!L(e) || this.pluginManager.getChartType(e)) return;
2653
+ if (!I(e) || this.pluginManager.getChartType(e)) return;
2165
2654
  let t = this.getDisplayData().length, { chartRect: n, barWidth: r, barSpacing: i } = this.viewport.getState(), a = n.width / (r + i);
2166
2655
  t > 0 && a > t + this.viewport.getRightMargin() && this.fitContent();
2167
2656
  }
2168
2657
  applyTimeSpacing() {
2169
- let e = !this.tickStream && !L(this.options.chartType);
2658
+ let e = !this.tickStream && !I(this.options.chartType);
2170
2659
  this.timeAxis.setTimesPastData(e), this.crosshairHandler.setTimesPastData(e);
2171
2660
  }
2172
2661
  setChartTypeOptions(e) {
2173
2662
  this.chartTypeOptions = {
2174
2663
  ...this.chartTypeOptions,
2175
- ...ae(e)
2176
- }, 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();
2177
2666
  }
2178
2667
  getChartTypeOptions() {
2179
- return ae(this.chartTypeOptions);
2668
+ return S(this.chartTypeOptions);
2180
2669
  }
2181
2670
  setExtendedHours(e) {
2182
2671
  e !== this.extendedHours && (this.extendedHours = e, this.reapplyExtendedHours(), this.markStateChanged());
@@ -2185,18 +2674,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2185
2674
  return this.extendedHours;
2186
2675
  }
2187
2676
  sessionKeep(e) {
2188
- return this.extendedHours ? null : Qt(this.symbolInfo, e);
2677
+ return this.extendedHours ? null : en(this.symbolInfo, e);
2189
2678
  }
2190
2679
  reapplyExtendedHours() {
2191
2680
  if (!this.series.refilter()) return;
2192
2681
  let e = this.series.bars();
2193
- 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);
2194
2683
  }
2195
2684
  quoteLines() {
2196
2685
  return this.priceLines.setQuoteShown(this.replaySession === null), this.priceLines;
2197
2686
  }
2198
2687
  setShapes(e) {
2199
- let t = ni(e);
2688
+ let t = bi(e);
2200
2689
  t.tagRadius !== void 0 && (this.themeManager.setShape({
2201
2690
  ...this.themeManager.getTheme().shape,
2202
2691
  ...t
@@ -2208,7 +2697,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2208
2697
  setFont(e) {
2209
2698
  if (e === null) this.themeManager.setFont(null);
2210
2699
  else {
2211
- let t = ti(e);
2700
+ let t = yi(e);
2212
2701
  if (Object.keys(t).length === 0) return;
2213
2702
  this.themeManager.setFont(t);
2214
2703
  }
@@ -2242,11 +2731,11 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2242
2731
  return this.priceLines.getBidAsk();
2243
2732
  }
2244
2733
  addIndicator(e, t, n = "bottom", r = {}) {
2245
- return this.recordIndicators(void 0, () => this.addIndicatorNow(e, t ?? {}, n, r));
2734
+ return this.indicatorHistory.record(void 0, () => this.addIndicatorNow(e, t ?? {}, n, r));
2246
2735
  }
2247
2736
  addIndicatorNow(e, t, n, r) {
2248
2737
  if (!this.isIndicatorAllowed(e)) return null;
2249
- 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(), {
2250
2739
  ...a ? { pane: a } : {},
2251
2740
  ...r.scale === "left" ? { scale: "left" } : {},
2252
2741
  ...r.instanceId ? { instanceId: r.instanceId } : {}
@@ -2257,67 +2746,41 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2257
2746
  }), this.markStateChanged(), this.requestMissingSymbols(o), o;
2258
2747
  }
2259
2748
  setSymbolSeries(e, t) {
2260
- e = e.trim(), this.symbolSeries.set(e, t), this.requestedSymbols.delete(e);
2261
- let n = this.indicatorBars(), r = !1;
2262
- 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);
2263
- r && (this.announceIndicatorUpdate(0), this.updateViewportAndRender());
2264
- }
2265
- forgetUnreadSymbols() {
2266
- let e = new Set(this.getRequiredSymbols());
2267
- 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();
2268
2755
  }
2269
2756
  getSymbolSeries(e) {
2270
2757
  return this.symbolSeries.get(e) ?? null;
2271
2758
  }
2272
2759
  getRequiredSymbols() {
2273
- let e = /* @__PURE__ */ new Set();
2274
- for (let t of this.indicatorEngine.getActiveIndicators()) {
2275
- let n = t.params.symbol;
2276
- O.has(t.id) && typeof n == "string" && n.trim() && e.add(n.trim());
2277
- }
2278
- return [...e];
2760
+ return this.symbolRequests.required();
2279
2761
  }
2280
2762
  requestMissingSymbols(e) {
2281
- this.forgetUnreadSymbols();
2282
- let t = this.indicatorEngine.getIndicatorConfig(e), n = t && O.has(t.id) && typeof t.params.symbol == "string" ? t.params.symbol.trim() : "";
2283
- !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 });
2284
2765
  }
2285
2766
  updateIndicator(e, t) {
2286
- this.recordIndicators(e, () => this.updateIndicatorNow(e, t));
2767
+ this.indicatorHistory.record(e, () => this.updateIndicatorNow(e, t));
2287
2768
  }
2288
2769
  updateIndicatorNow(e, t) {
2289
- 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);
2290
2771
  this.indicatorEngine.updateIndicator(e, t, this.indicatorBars()), this.announceIndicatorUpdate(0), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
2291
2772
  instanceId: e,
2292
2773
  change: "params"
2293
- }), this.requestMissingSymbols(e);
2294
- let a = this.indicatorEngine.getIndicatorConfig(e);
2295
- if (n?.placement === "overlay" && a && r && a.params[r] !== i) {
2296
- let t = x(a.params[r]), n = t ? this.paneHostOf(t.instanceId, e) : x(i) ? null : a.pane ?? null;
2297
- (n ?? void 0) !== a.pane && (this.indicatorEngine.setPane(e, n), this.eventBus.emit("indicatorChange", {
2298
- instanceId: e,
2299
- change: "pane"
2300
- }));
2301
- }
2302
- this.updateViewportAndRender();
2303
- }
2304
- paneFor(e, t, n, r) {
2305
- if (n) return this.paneHostOf(n, r);
2306
- if (e.placement !== "overlay") return null;
2307
- let i = M(e), a = i ? x(t[i]) : null;
2308
- return a ? this.paneHostOf(a.instanceId, r) : null;
2309
- }
2310
- paneHostOf(e, t) {
2311
- if (e === t) return null;
2312
- if (this.layoutManager.getPanels().some((t) => t.id === e)) return e;
2313
- let n = this.indicatorEngine.getIndicatorConfig(e)?.pane;
2314
- 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();
2315
2778
  }
2316
2779
  getIndicatorLevels(e) {
2317
2780
  return this.indicatorEngine.getLevels(e);
2318
2781
  }
2319
2782
  setIndicatorScale(e, t) {
2320
- return this.recordIndicators(e, () => this.setIndicatorScaleNow(e, t));
2783
+ return this.indicatorHistory.record(e, () => this.setIndicatorScaleNow(e, t));
2321
2784
  }
2322
2785
  setIndicatorScaleNow(e, t) {
2323
2786
  return this.indicatorEngine.setScale(e, t) ? (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2350,8 +2813,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2350
2813
  return {
2351
2814
  ...e,
2352
2815
  priceRange: {
2353
- min: t.min - n * zr,
2354
- max: t.max + n * zr
2816
+ min: t.min - n * li,
2817
+ max: t.max + n * li
2355
2818
  },
2356
2819
  logScale: !1,
2357
2820
  scaleMode: "regular",
@@ -2362,7 +2825,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2362
2825
  };
2363
2826
  }
2364
2827
  setIndicatorLevels(e, t) {
2365
- this.recordIndicators(e, () => this.setIndicatorLevelsNow(e, t));
2828
+ this.indicatorHistory.record(e, () => this.setIndicatorLevelsNow(e, t));
2366
2829
  }
2367
2830
  setIndicatorLevelsNow(e, t) {
2368
2831
  this.indicatorEngine.setLevels(e, t) && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2371,10 +2834,10 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2371
2834
  }));
2372
2835
  }
2373
2836
  removeIndicator(e) {
2374
- this.recordIndicators(void 0, () => this.removeIndicatorNow(e));
2837
+ this.indicatorHistory.record(void 0, () => this.removeIndicatorNow(e));
2375
2838
  }
2376
2839
  removeIndicators(e) {
2377
- this.recordIndicators(void 0, () => {
2840
+ this.indicatorHistory.record(void 0, () => {
2378
2841
  for (let t of e) this.removeIndicatorNow(t);
2379
2842
  });
2380
2843
  }
@@ -2385,16 +2848,10 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2385
2848
  this.markStateChanged(), this.updateViewportAndRender();
2386
2849
  }
2387
2850
  detachIndicator(e) {
2388
- if (!this.indicatorEngine.getIndicatorConfig(e)) return;
2389
- 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;
2390
- this.indicatorEngine.removeIndicator(e);
2391
- let i = this.paneStyles.get(e);
2392
- this.paneStyles.delete(e), r ? (this.indicatorEngine.setPane(r, null), this.renamePane(e, r), i && this.paneStyles.set(r, i)) : this.layoutManager.removePanel(e);
2393
- 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", {
2394
2852
  instanceId: e,
2395
2853
  change: "pane"
2396
- });
2397
- this.eventBus.emit("indicatorRemove", { instanceId: e }), this.forgetUnreadSymbols();
2854
+ })) && (this.eventBus.emit("indicatorRemove", { instanceId: e }), this.symbolRequests.forgetUnread());
2398
2855
  }
2399
2856
  getIndicatorStyle(e) {
2400
2857
  return this.indicatorEngine.getIndicatorStyle(e);
@@ -2404,21 +2861,21 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2404
2861
  this.indicatorEngine.setStyleDefaults(e, null);
2405
2862
  return;
2406
2863
  }
2407
- 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);
2408
2865
  this.indicatorEngine.setStyleDefaults(e, {
2409
2866
  ...r,
2410
2867
  ...i ? { plots: i } : {}
2411
2868
  });
2412
2869
  }
2413
2870
  setPaneStyle(e, t) {
2414
- let n = this.paneOf(e);
2415
- 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));
2416
2873
  }
2417
2874
  setPaneStyleNow(e, t) {
2418
- 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());
2419
2876
  }
2420
2877
  getPaneStyle(e) {
2421
- let t = this.paneStyles.get(this.paneOf(e));
2878
+ let t = this.panes.style(this.indicatorPanes.paneOf(e));
2422
2879
  return t ? { ...t } : null;
2423
2880
  }
2424
2881
  getIndicatorOutput(e) {
@@ -2431,8 +2888,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2431
2888
  return this.pluginManager;
2432
2889
  }
2433
2890
  static indicators() {
2434
- let e = new Ve();
2435
- return Vt(e), e.getAvailableIndicators();
2891
+ let e = new Be();
2892
+ return Ht(e), e.getAvailableIndicators();
2436
2893
  }
2437
2894
  setPanelPosition(e, t) {
2438
2895
  this.layoutManager.setPanelPosition(e, t), this.updateViewportAndRender(), this.eventBus.emit("indicatorChange", {
@@ -2447,96 +2904,52 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2447
2904
  }), this.markStateChanged();
2448
2905
  }
2449
2906
  moveIndicatorToPane(e, t) {
2450
- return this.recordIndicators(e, () => this.moveIndicatorToPaneNow(e, t));
2907
+ return this.indicatorHistory.record(e, () => this.moveIndicatorToPaneNow(e, t));
2451
2908
  }
2452
2909
  canMoveIndicatorToPane(e, t) {
2453
- return this.paneMoveHost(e, t) !== void 0;
2454
- }
2455
- paneMoveHost(e, t) {
2456
- let n = this.indicatorEngine.getIndicatorConfig(e), r = this.indicatorEngine.getIndicatorDescriptor(e);
2457
- if (!n || !r) return;
2458
- let i = M(r);
2459
- if (r.placement === "overlay" && i && x(n.params[i])) return;
2460
- if (t === "price") return r.placement === "overlay" && n.pane ? null : void 0;
2461
- if (t === "new") {
2462
- let t = this.layoutManager.getPanels().some((t) => t.id === e);
2463
- return r.placement === "panel" && !t ? null : void 0;
2464
- }
2465
- let a = this.paneHostOf(t, e);
2466
- return a && a !== n.pane && a !== e ? a : void 0;
2910
+ return this.indicatorPanes.moveHost(e, t) !== void 0;
2467
2911
  }
2468
2912
  moveIndicatorToPaneNow(e, t) {
2469
- let n = this.paneMoveHost(e, t), r = this.indicatorEngine.getIndicatorConfig(e);
2470
- if (n === void 0 || !r) return !1;
2471
- let i = r.pane, a = this.layoutManager.getPanels().some((t) => t.id === e), o = new Set([e]);
2472
- if (a) {
2473
- 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);
2474
- if (this.paneStyles.delete(e), a) {
2475
- this.indicatorEngine.setPane(a, null), this.renamePane(e, a), s && this.paneStyles.set(a, s);
2476
- for (let e of i) e !== a && this.indicatorEngine.setPane(e, a);
2477
- } else {
2478
- this.layoutManager.removePanel(e);
2479
- for (let e of i) this.indicatorEngine.setPane(e, null);
2480
- }
2481
- this.panelInfoCache = null;
2482
- for (let i of t) r.has(i) && this.indicatorEngine.setPane(i, n ?? e), o.add(i);
2483
- }
2484
- if (this.indicatorEngine.setPane(e, n), t === "new") {
2485
- this.layoutManager.addPanel(e, "bottom");
2486
- for (let t of this.indicatorEngine.getDependents(e)) this.indicatorEngine.getIndicatorConfig(t)?.pane === i && (this.indicatorEngine.setPane(t, e), o.add(t));
2487
- }
2488
- 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", {
2489
2916
  instanceId: e,
2490
2917
  change: "pane"
2491
2918
  });
2492
2919
  return this.updateViewportAndRender(), this.markStateChanged(), !0;
2493
2920
  }
2494
2921
  setPaneCollapsed(e, t) {
2495
- let n = this.paneOf(e);
2496
- 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)));
2497
2924
  }
2498
2925
  isPaneCollapsed(e) {
2499
- return this.layoutManager.isPanelShownCollapsed(this.paneOf(e));
2926
+ return this.layoutManager.isPanelShownCollapsed(this.indicatorPanes.paneOf(e));
2500
2927
  }
2501
2928
  setMaximizedPane(e) {
2502
- let t = e === null ? null : this.paneOf(e), n = t ?? this.layoutManager.getMaximizedPanel() ?? "";
2503
- 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)));
2504
2931
  }
2505
2932
  getMaximizedPane() {
2506
2933
  return this.layoutManager.getMaximizedPanel();
2507
2934
  }
2508
2935
  setPaneScale(e, t) {
2509
- let n = this.paneOf(e);
2510
- 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)));
2511
2938
  }
2512
2939
  getPaneScale(e) {
2513
- 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));
2514
2941
  return {
2515
2942
  log: !!t?.logScale,
2516
2943
  invert: !!t?.invertScale,
2517
2944
  percent: !!t?.percentScale
2518
2945
  };
2519
2946
  }
2520
- paneBaseline(e, t, n) {
2521
- let r = this.indicatorEngine.getOutput(e)?.series, i = this.indicatorEngine.getIndicatorDescriptor(e);
2522
- if (!r || !i) return;
2523
- let a = i.plots?.[0]?.key;
2524
- for (let e = Math.max(0, t); e <= n && e < r.length; e++) {
2525
- let t = r[e];
2526
- if (!t) continue;
2527
- let n = a === void 0 ? Object.values(t).find((e) => typeof e == "number" && Number.isFinite(e)) : t[a];
2528
- if (typeof n == "number" && Number.isFinite(n) && n !== 0) return n;
2529
- }
2530
- }
2531
2947
  movePane(e, t) {
2532
- let n = this.paneOf(e);
2533
- 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)));
2534
2950
  }
2535
2951
  canMovePane(e, t) {
2536
- return this.layoutManager.canMovePanel(this.paneOf(e), t);
2537
- }
2538
- paneOf(e) {
2539
- return this.indicatorEngine.getIndicatorConfig(e)?.pane ?? e;
2952
+ return this.layoutManager.canMovePanel(this.indicatorPanes.paneOf(e), t);
2540
2953
  }
2541
2954
  paneChange(e, t, n) {
2542
2955
  return n() ? (this.updateViewportAndRender(), this.eventBus.emit("paneChange", {
@@ -2591,12 +3004,12 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2591
3004
  }), n;
2592
3005
  }
2593
3006
  isTimeAligned() {
2594
- 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();
2595
3008
  }
2596
3009
  roundPrice(e) {
2597
3010
  if (!Number.isFinite(e)) return e;
2598
3011
  let t = this.stepAt(e);
2599
- 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)));
2600
3013
  let { min: n, max: r } = this.viewport.getState().priceRange;
2601
3014
  return Number(e.toFixed(this.marketPricePrecision ?? c(n, r)));
2602
3015
  }
@@ -2680,7 +3093,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2680
3093
  }
2681
3094
  autoFib() {
2682
3095
  if (!this.features.drawings) return null;
2683
- 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);
2684
3097
  return n ? this.addDrawing({
2685
3098
  type: "fibRetracement",
2686
3099
  anchors: [n[0], n[1]]
@@ -2693,9 +3106,9 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2693
3106
  return this.drawingManager.removeDrawings(e);
2694
3107
  }
2695
3108
  nudgeSelectedDrawings(e) {
2696
- let t = qr[e.key];
3109
+ let t = pi[e.key];
2697
3110
  if (!t || !this.features.drawings || e.ctrlKey || e.metaKey || e.altKey) return !1;
2698
- let n = e.shiftKey ? Kr : 1, r = {
3111
+ let n = e.shiftKey ? fi : 1, r = {
2699
3112
  ...this.viewport.getState(),
2700
3113
  data: this.getDisplayData()
2701
3114
  };
@@ -2789,7 +3202,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2789
3202
  recordUndo(e) {
2790
3203
  if (!this.features.drawingUndoRedo || typeof e?.undo != "function" || typeof e.redo != "function") return;
2791
3204
  let t = performance.now(), n = this.undoRedoManager.last();
2792
- if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < Vr) {
3205
+ if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < 800) {
2793
3206
  this.undoRedoManager.replaceLast({
2794
3207
  ...n,
2795
3208
  custom: {
@@ -2836,7 +3249,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2836
3249
  x: t.x,
2837
3250
  y: t.y
2838
3251
  };
2839
- if ((e === "plot" || e === "priceAxis") && (r.price = Yt(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") {
2840
3253
  let e = this.getIndicatorPanes().find((e) => t.y >= e.rect.y && t.y <= e.rect.y + e.rect.height);
2841
3254
  e && (r.pane = e.instanceId);
2842
3255
  }
@@ -2844,7 +3257,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2844
3257
  }
2845
3258
  applyPriceAxisAdd() {
2846
3259
  let e = this.features.priceAxisAddButton && this.features.crosshair;
2847
- this.priceAxisAddButton.setEnabled(e), this.tradingManager.setTagInset(e ? Ye : 0);
3260
+ this.priceAxisAddButton.setEnabled(e), this.tradingManager.setTagInset(e ? Je : 0);
2848
3261
  }
2849
3262
  setPriceAxisAddButton(e) {
2850
3263
  this.features.priceAxisAddButton = e, this.applyPriceAxisAdd(), this.engine.requestRender(r.Overlay);
@@ -2866,7 +3279,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2866
3279
  ...this.viewport.getState(),
2867
3280
  data: this.getDisplayData()
2868
3281
  };
2869
- this.setVisibleRange(F(e.x0, t), F(e.x1, t));
3282
+ this.setVisibleRange(P(e.x0, t), P(e.x1, t));
2870
3283
  }
2871
3284
  lockAllDrawings() {
2872
3285
  this.drawingManager.lockAllDrawings();
@@ -2911,7 +3324,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2911
3324
  for (let e of this.indicatorEngine.getActiveIndicators()) {
2912
3325
  let t = this.indicatorEngine.getOutput(e.instanceId)?.series;
2913
3326
  if (!t) continue;
2914
- let r = ln(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) => ({
2915
3328
  key: e,
2916
3329
  title: e
2917
3330
  }));
@@ -2935,11 +3348,11 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2935
3348
  }
2936
3349
  getExportText(e = "csv", t = {}) {
2937
3350
  let { bars: n, columns: r } = this.getExportData(t);
2938
- return e === "json" ? E.toJSON(n, r) : E.toCSV(n, r);
3351
+ return e === "json" ? D.toJSON(n, r) : D.toCSV(n, r);
2939
3352
  }
2940
3353
  download(e, t, n) {
2941
3354
  let r = this.getExportText(e, n);
2942
- 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");
2943
3356
  }
2944
3357
  setAutoSave(e, t = 5e3) {
2945
3358
  this.autoSaveScheduler.enable(e, t);
@@ -2970,7 +3383,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2970
3383
  return this.indicatorEngine.getActiveIndicators();
2971
3384
  }
2972
3385
  setIndicatorVisible(e, t) {
2973
- this.recordIndicators(e, () => this.setIndicatorVisibleNow(e, t));
3386
+ this.indicatorHistory.record(e, () => this.setIndicatorVisibleNow(e, t));
2974
3387
  }
2975
3388
  setIndicatorVisibleNow(e, t) {
2976
3389
  this.indicatorEngine.setVisible(e, t) !== null && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2979,7 +3392,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2979
3392
  }));
2980
3393
  }
2981
3394
  setIndicatorIntervals(e, t) {
2982
- this.recordIndicators(e, () => this.setIndicatorIntervalsNow(e, t));
3395
+ this.indicatorHistory.record(e, () => this.setIndicatorIntervalsNow(e, t));
2983
3396
  }
2984
3397
  setIndicatorIntervalsNow(e, t) {
2985
3398
  this.indicatorEngine.setIntervals(e, t) && (this.updateViewportAndRender(), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
@@ -2998,10 +3411,10 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
2998
3411
  } : null;
2999
3412
  }
3000
3413
  updateIndicatorStyle(e, t) {
3001
- this.recordIndicators(e, () => this.updateIndicatorStyleNow(e, t));
3414
+ this.indicatorHistory.record(e, () => this.updateIndicatorStyleNow(e, t));
3002
3415
  }
3003
3416
  updateIndicatorStyleNow(e, t) {
3004
- 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);
3005
3418
  this.indicatorEngine.updateIndicatorStyle(e, {
3006
3419
  ...r,
3007
3420
  ...i ? { plots: i } : {}
@@ -3121,26 +3534,31 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3121
3534
  this.features.trading && this.tradingManager.setConfig(e);
3122
3535
  }
3123
3536
  async connect(e) {
3124
- if (!j(e.adapter, e.timeframe)) throw RangeError(`${e.adapter.name} cannot serve the ${e.timeframe} timeframe`);
3125
- this.snapshotKey = null, this.holdReplayFor(e.symbol), this.disconnectStream(), this.streamManager = new _t(), this.streamManager.setTimeZone(this.studyZoneHeld ? this.studyZone : this.getExchangeTimeZone()), this.streamManager.on("snapshot", (t) => {
3126
- let n = this.streamSeriesKey(e.adapter);
3127
- n === this.snapshotKey && this.replaySession ? this.series.mergeSnapshot(t) : n === this.snapshotKey && this.series.length() > 0 ? this.mergeSnapshot(t) : (this.replaySession && this.useStreamHistory(e.adapter, e.historyPageSize, !1), this.setData(t)), this.snapshotKey = n, this.useStreamHistory(e.adapter, e.historyPageSize);
3537
+ let t = {
3538
+ ...e,
3539
+ adapter: Ut(e),
3540
+ feed: void 0
3541
+ };
3542
+ if (!A(t.adapter, t.timeframe)) throw RangeError(`${t.adapter.name} cannot serve the ${t.timeframe} timeframe`);
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) => {
3544
+ let n = this.streamSeriesKey(t.adapter);
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);
3128
3546
  }), this.streamManager.on("barClose", (e) => {
3129
3547
  if (!R(e)) return;
3130
3548
  let t = this.series.placeStreamBar(e);
3131
- if (t.refiltered && (this.displayDataCache = null), t.to === "none") {
3549
+ if (t.to === "none") {
3132
3550
  this.updateBar(e);
3133
3551
  return;
3134
3552
  }
3135
3553
  if (t.to === "aside" && this.followLivePrice(e.close), t.to !== "shown") return;
3136
3554
  let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
3137
- 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);
3138
3556
  }), this.streamManager.on("barCorrection", (e) => {
3139
3557
  this.updateBar(e);
3140
3558
  }), this.streamManager.on("barUpdate", (e) => {
3141
3559
  if (!R(e)) return;
3142
3560
  let t = this.series.placeStreamBar(e);
3143
- 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;
3144
3562
  let n = t.before;
3145
3563
  if (t.to !== "shown") {
3146
3564
  this.scheduleRender();
@@ -3175,21 +3593,21 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3175
3593
  kind: "error",
3176
3594
  error: e.message
3177
3595
  });
3178
- }), this.streamManager.on("symbolInfo", (e) => this.applyFeedSymbolInfo(e)), this.autoScrollOnNewBar = e.autoScroll !== !1, this.setStreamTarget(e.symbol, e.timeframe), this.streamAdapter = e.adapter;
3179
- let t = this.streamManager;
3180
- if (this.resolveStreamSymbol(e.adapter, e.symbol), await t.connect(e), this.streamManager !== t) return;
3181
- let n = w(e.timeframe);
3182
- this.barCountdown.setTimeframeMs(n), this.countdownInterval && clearInterval(this.countdownInterval), this.countdownInterval = setInterval(() => {
3596
+ }), this.streamManager.on("symbolInfo", (e) => this.applyFeedSymbolInfo(e)), this.autoScrollOnNewBar = t.autoScroll !== !1, this.setStreamTarget(t.symbol, t.timeframe), this.streamAdapter = t.adapter;
3597
+ let n = this.streamManager;
3598
+ if (this.resolveStreamSymbol(t.adapter, t.symbol), await n.connect(t), this.streamManager !== n) return;
3599
+ let i = T(t.timeframe);
3600
+ this.barCountdown.setTimeframeMs(i), this.countdownInterval && clearInterval(this.countdownInterval), this.countdownInterval = setInterval(() => {
3183
3601
  this.barCountdown.isVisible() && this.engine.requestRender(r.Hover);
3184
3602
  }, 1e3);
3185
3603
  }
3186
3604
  streamSeriesKey(e) {
3187
- 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;
3188
3606
  return `${this.currentSymbol}|${n}|${r?.timeZone ?? ""}`;
3189
3607
  }
3190
3608
  setStreamTarget(e, t) {
3191
3609
  let n = this.announcedSymbol;
3192
- 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", {
3193
3611
  symbol: e,
3194
3612
  previous: n
3195
3613
  })), this.useTimeframe(t);
@@ -3207,8 +3625,8 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3207
3625
  async switchStream(e, t) {
3208
3626
  if (!this.streamManager) return;
3209
3627
  let n = this.streamAdapter;
3210
- if (n && !j(n, t)) throw RangeError(`${n.name} cannot serve the ${t} timeframe`);
3211
- 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);
3212
3630
  }
3213
3631
  isIndicatorAllowed(e) {
3214
3632
  let t = this.features.indicatorIds;
@@ -3227,7 +3645,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3227
3645
  }
3228
3646
  connectExecution(e, t = {}) {
3229
3647
  if (!this.features.trading) throw Error("connectExecution requires features.trading to be enabled");
3230
- this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = hr(e, {
3648
+ this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = Br(e, {
3231
3649
  onIntent: (e, t) => {
3232
3650
  let n = (e) => t(e.payload);
3233
3651
  return this.eventBus.on(e, n), () => this.eventBus.off(e, n);
@@ -3303,14 +3721,6 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3303
3721
  comparesDrawn() {
3304
3722
  return this.isTimeAligned();
3305
3723
  }
3306
- panesOffChartType() {
3307
- let e = this.indicatorEngine.getActiveIndicators(), t = new Set(e.filter((e) => e.offChartType).map((e) => e.instanceId)), n = /* @__PURE__ */ new Set();
3308
- for (let r of this.layoutManager.getPanels()) {
3309
- let i = e.filter((e) => e.instanceId === r.id || e.pane === r.id);
3310
- i.length > 0 && i.every((e) => t.has(e.instanceId)) && n.add(r.id);
3311
- }
3312
- return n;
3313
- }
3314
3724
  clearCompareSymbols() {
3315
3725
  let e = this.compareRenderer.getSymbols().map((e) => e.id);
3316
3726
  this.compareRenderer.clear(), this.updateViewportAndRender();
@@ -3360,18 +3770,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3360
3770
  goToTime(e) {
3361
3771
  let t = this.getDisplayData();
3362
3772
  if (t.length === 0 || !Number.isFinite(e)) return -1;
3363
- 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;
3364
3774
  return this.viewport.scrollBy(i - r.offset), this.updateViewportAndRender(), n;
3365
3775
  }
3366
3776
  setVisibleRangePreset(e) {
3367
3777
  let t = this.getDisplayData();
3368
3778
  if (t.length === 0) return;
3369
- 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;
3370
3780
  if (a === null || a < t[0].time) {
3371
3781
  this.fitContent();
3372
3782
  return;
3373
3783
  }
3374
- 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);
3375
3785
  this.viewport.zoomToBarRange(s, n + this.viewport.getRightMargin()), this.viewport.scrollToEnd(), this.updateViewportAndRender();
3376
3786
  }
3377
3787
  scrollToEnd() {
@@ -3396,7 +3806,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3396
3806
  setVisibleRange(e, t) {
3397
3807
  let n = this.getDisplayData();
3398
3808
  if (n.length === 0) return;
3399
- 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);
3400
3810
  this.viewport.zoomToBarRange(r, i), this.updateViewportAndRender();
3401
3811
  }
3402
3812
  suspend() {
@@ -3536,13 +3946,13 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3536
3946
  }), this.engine.requestRender(r.Background);
3537
3947
  }
3538
3948
  setAutoScale(e) {
3539
- 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();
3540
3950
  }
3541
3951
  holdPriceScale() {
3542
- this.options.autoScale = !1, this.priceFitPending = !1;
3952
+ this.priceFit.hold();
3543
3953
  }
3544
3954
  isAutoScale() {
3545
- return this.options.autoScale !== !1;
3955
+ return this.priceFit.isAuto();
3546
3956
  }
3547
3957
  setCrosshairMode(e) {
3548
3958
  this.crosshairHandler.setMode(e), this.engine.requestRender(r.Hover);
@@ -3554,7 +3964,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3554
3964
  e ? this.crosshairHandler.onPointerMove(e) : this.crosshairHandler.onPointerLeave(), this.engine.requestRender(r.Hover);
3555
3965
  }
3556
3966
  setCrosshairTime(e) {
3557
- 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));
3558
3968
  n !== this.crosshairHandler.getSyncedSlot() && (this.crosshairHandler.setSyncedSlot(n), this.showSyncedBar(n), this.engine.requestRender(r.Hover));
3559
3969
  }
3560
3970
  showSyncedBar(e) {
@@ -3564,7 +3974,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3564
3974
  }
3565
3975
  let t = this.crosshairSeries(), n = e >= 0 && e < t.length ? t[e] : void 0, r = n && e > 0 ? t[e - 1] : void 0;
3566
3976
  this.crosshairHandler.getPosition() || this.chartLegend.setHoverBar(n ?? null, r ?? null);
3567
- let i = n ? A(t)[e]?.time ?? n.time : void 0;
3977
+ let i = n ? At(t)[e]?.time ?? n.time : void 0;
3568
3978
  this.eventBus.emit("crosshairSync", {
3569
3979
  barIndex: e,
3570
3980
  ...n ? { bar: n } : {},
@@ -3643,7 +4053,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3643
4053
  return this.periodLevels.getPeriod();
3644
4054
  }
3645
4055
  setTimeZone(e) {
3646
- Lr(e), this.timeZoneSetting = e, this.applyTimeZone();
4056
+ si(e), this.timeZoneSetting = e, this.applyTimeZone();
3647
4057
  }
3648
4058
  getTimeZone() {
3649
4059
  return this.timeZoneSetting;
@@ -3652,7 +4062,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3652
4062
  return this.displayTz;
3653
4063
  }
3654
4064
  getExchangeTimeZone() {
3655
- 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;
3656
4066
  }
3657
4067
  setTimezone(e) {
3658
4068
  this.setTimeZone(e);
@@ -3694,7 +4104,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3694
4104
  }
3695
4105
  spokenBarTime(e) {
3696
4106
  let t = this.getDisplayData(), n = e * u(t), r = this.numberLocale || "en-US";
3697
- 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, {
3698
4108
  dateStyle: "medium",
3699
4109
  timeStyle: "short"
3700
4110
  }, this.displayTz)(n);
@@ -3707,18 +4117,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3707
4117
  this.studyZoneHeld = !1, this.endStudyZoneWait(), this.useSymbolInfo(e);
3708
4118
  }
3709
4119
  useSymbolInfo(e) {
3710
- let t = e && this.symbolInfo?.symbol === e.symbol ? C(this.symbolInfo) : void 0;
3711
- this.symbolInfo = e ? Rr({
4120
+ let t = e && this.symbolInfo?.symbol === e.symbol ? w(this.symbolInfo) : void 0;
4121
+ this.symbolInfo = e ? ci({
3712
4122
  ...e,
3713
4123
  sessions: e.sessions?.map((e) => ({ ...e }))
3714
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);
3715
4125
  let n = (this.symbolInfo?.sessions ?? []).flatMap((e) => {
3716
- let t = S(e.start), n = S(e.end);
4126
+ let t = C(e.start), n = C(e.end);
3717
4127
  return t === null || n === null ? [] : [{
3718
4128
  startMinute: t,
3719
4129
  endMinute: n
3720
4130
  }];
3721
- }), i = C(this.symbolInfo);
4131
+ }), i = w(this.symbolInfo);
3722
4132
  this.sessionShading.replaceConfig(n.length > 0 && i && y(i) ? {
3723
4133
  timeZone: i,
3724
4134
  windows: n,
@@ -3733,15 +4143,15 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3733
4143
  if (!e || typeof e != "object") return;
3734
4144
  let t = this.currentSymbol, n = (e) => !e || e.toUpperCase() === t.toUpperCase();
3735
4145
  if (!n(e.symbol)) return;
3736
- let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = Rr({
4146
+ let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = ci({
3737
4147
  ...r,
3738
4148
  ...e,
3739
4149
  symbol: e.symbol || r?.symbol || t
3740
- }, C(r));
4150
+ }, w(r));
3741
4151
  r && JSON.stringify(i) === JSON.stringify(r) || (this.symbolInfoSeq++, this.setSymbolInfo(i));
3742
4152
  }
3743
4153
  resolveStreamSymbol(e, t) {
3744
- let n = P(e), r = n.resolveSymbol?.bind(n);
4154
+ let n = N(e), r = n.resolveSymbol?.bind(n);
3745
4155
  if (this.symbolInfo && this.symbolInfo.symbol !== t ? (r ? this.holdStudyZone() : this.studyZoneHeld = !1, this.useSymbolInfo(null)) : r && this.studyZoneHeld && this.holdStudyZone(), !r) {
3746
4156
  this.releaseStudyZone();
3747
4157
  return;
@@ -3772,7 +4182,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3772
4182
  return this.sessionShading.isVisible();
3773
4183
  }
3774
4184
  setSessionShadingConfig(e) {
3775
- 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);
3776
4186
  }
3777
4187
  setTooltipVisible(e) {
3778
4188
  e || this.crosshairTooltip.hide();
@@ -3794,11 +4204,11 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3794
4204
  return this.waitForGpu(null), e === "canvas" ? (this.applyRenderer(null), "canvas") : this.engine.getGpu() ? "webgl" : this.takeGpu(e, t, !0);
3795
4205
  }
3796
4206
  async takeGpu(e, t, n) {
3797
- let { gpu: r, reason: i } = await Ft(e);
3798
- 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());
3799
4209
  }
3800
4210
  waitForGpu(e) {
3801
- this.stopWaitingForGpu?.(), this.stopWaitingForGpu = e ? qt(e) : null;
4211
+ this.stopWaitingForGpu?.(), this.stopWaitingForGpu = e ? Yt(e) : null;
3802
4212
  }
3803
4213
  getRenderer() {
3804
4214
  return this.engine.getGpu() ? "webgl" : "canvas";
@@ -3977,24 +4387,24 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
3977
4387
  let t = this.replaySession ? this.replayOffset : 0;
3978
4388
  if (!this.replaySession) {
3979
4389
  if (this.series.length() === 0) return;
3980
- this.series.beginReplay(), this.replaySession = ui(this.currentSymbol);
4390
+ this.series.beginReplay(), this.replaySession = Ti(this.currentSymbol);
3981
4391
  }
3982
4392
  let n = this.replaySession, { steps: r, startTime: i, hideHistory: a, revealMarks: o, step: s, ...c } = e ?? {};
3983
4393
  c.animate = c.animate === !0;
3984
4394
  let l = this.series.inHoursShown(this.series.liveBars()), u = t > 0 && i === void 0 && a !== !1, d = c.startIndex;
3985
- 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);
3986
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;
3987
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);
3988
4398
  let m = r ? this.replayStepsOver(n, p, !0) : null;
3989
- this.options.autoScale = !0, this.buildReplay(p, m, f);
4399
+ this.priceFit.resume(), this.buildReplay(p, m, f);
3990
4400
  let h = this.replayStepsSeries;
3991
- h && c.startIndex !== void 0 && (c.startIndex = yi(h, p, c.startIndex));
4401
+ h && c.startIndex !== void 0 && (c.startIndex = Fi(h, p, c.startIndex));
3992
4402
  let g = h ?? p, _ = g[Math.max(0, Math.min(Math.floor(Number(c.startIndex ?? 0)) || 0, g.length - 1))];
3993
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);
3994
4404
  }
3995
4405
  buildReplay(e, t, n) {
3996
4406
  let r = this.replaySession?.animate === !0, i = r ? null : t;
3997
- this.replayPieces = r && t ? Si(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;
3998
4408
  let a = this.replayRestarting;
3999
4409
  this.replayRestarting = !0;
4000
4410
  try {
@@ -4008,7 +4418,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4008
4418
  let n = t, a = e[t];
4009
4419
  if (i) {
4010
4420
  let r = i[t];
4011
- n = Q(e, r.time), c = c !== null && s === t - 1 && n === o - 1 && c ? wi(c, r) : bi(e[n], i, t), a = xi(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;
4012
4422
  }
4013
4423
  let u = this.replayForming;
4014
4424
  this.replayForming = null, s = t;
@@ -4020,7 +4430,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4020
4430
  } else this.series.showReplayed([...e.slice(0, n), a]), this.recalcIndicators(this.series.bars());
4021
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());
4022
4432
  let g = l[t + 1]?.time ?? l[t].time + (t > 0 ? l[t].time - l[t - 1].time : 1);
4023
- 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);
4024
4434
  let _ = this.replayCause === null ? p ? "play" : "seek" : "series";
4025
4435
  this.eventBus.emit("replayStep", {
4026
4436
  barIndex: n,
@@ -4032,7 +4442,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4032
4442
  });
4033
4443
  }), r && (this.replayPhaseUnsub = this.replayManager.on("phase", ({ index: t, fraction: n }) => {
4034
4444
  if (!e[t] || this.series.length() !== o || o !== t && o !== t + 1) return;
4035
- let r = this.replayForming?.index === t ? this.replayForming.path : this.replayPathOf(e, t), i = Ci() ? Ar(r, n) : n, a = o === t, s = a && this.autoScrollOnNewBar && this.viewport.isAtEnd(), c = kr(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);
4036
4446
  a ? this.series.appendReplayed(c) : this.series.updateReplayed(c), o = t + 1, this.replayForming = {
4037
4447
  index: t,
4038
4448
  path: r
@@ -4042,30 +4452,30 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4042
4452
  drawFormingBar(e, t, n, r) {
4043
4453
  this.currentPriceLine.setPrice(e.close, t);
4044
4454
  let i = this.series.bars();
4045
- if (this.recalcIndicatorsFrom(i, i.length - 1), (n || !oi.has(this.options.chartType)) && (this.displayDataCache = null), !n) {
4455
+ if (this.recalcIndicatorsFrom(i, i.length - 1), !n) {
4046
4456
  this.scheduleRender();
4047
4457
  return;
4048
4458
  }
4049
- this.crosshairHandler.setData(i), this.reshapeMemo.clear(), this.updateViewportAndRender(r);
4459
+ this.crosshairHandler.setData(i), this.display.reset(), this.updateViewportAndRender(r);
4050
4460
  }
4051
4461
  replayPathOf(e, t) {
4052
4462
  let n = e[t];
4053
- return wr(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) ?? []);
4054
4464
  }
4055
4465
  loadReplaySteps(e, t) {
4056
4466
  let n = this.replayLoader?.loader;
4057
4467
  if (!n) return;
4058
4468
  n.evictBefore(e[t].time);
4059
4469
  let r = this.replayManager.getStepMs();
4060
- n.ensure(e, t, Number.isFinite(r) && r > 0 ? Math.ceil(ai / r) : 1);
4470
+ n.ensure(e, t, Number.isFinite(r) && r > 0 ? Math.ceil(xi / r) : 1);
4061
4471
  }
4062
4472
  useReplayLoader(e, t) {
4063
- let n = this.streamAdapter, r = this.streamTimeframe, i = e.step && n && r !== null ? Nr(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}`;
4064
4474
  if (!t && this.replayLoader?.key === a || (this.replayLoader?.loader.dispose(), this.replayLoader = null, !i || !n || r === null)) return;
4065
- let o = P(n), s = o.fetchHistoryBefore, c = this.currentSymbol, l = w(r), u = new _r({
4475
+ let o = N(n), s = o.fetchHistoryBefore, c = this.currentSymbol, l = T(r), u = new Hr({
4066
4476
  source: s ? (e, t) => s.call(o, c, i, e, t) : null,
4067
4477
  step: i,
4068
- ratio: Math.max(1, Math.round(l / w(i))),
4478
+ ratio: Math.max(1, Math.round(l / T(i))),
4069
4479
  barMs: l,
4070
4480
  keep: (e) => this.series.inHoursShown(e),
4071
4481
  report: (e) => this.eventBus.emit("replayStepsLoad", e)
@@ -4080,18 +4490,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4080
4490
  if (!i || !a?.setMarkPrice || !o) return;
4081
4491
  let s = i.fedTime;
4082
4492
  if (s === null) {
4083
- i.fedTime = o.time, i.fedFraction = r, this.feedReplayPrice(kr(n, r).close, o.time);
4493
+ i.fedTime = o.time, i.fedFraction = r, this.feedReplayPrice(ei(n, r).close, o.time);
4084
4494
  return;
4085
4495
  }
4086
4496
  if (o.time < s || o.time === s && r <= i.fedFraction) return;
4087
4497
  let c = [];
4088
4498
  if (o.time > s) {
4089
- let a = Y(e, s);
4090
- e[a]?.time === s && i.fedFraction < 1 && c.push(...q(this.replayPathOf(e, a), i.fedFraction, 1));
4091
- let o = e.slice(X(e, s), t), l = Math.ceil(o.length / gi);
4092
- for (let e = 0; e < o.length; e += l) c.push(..._i(o.slice(e, e + l)));
4093
- c.push(...q(n, -1, r));
4094
- } 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));
4095
4505
  i.fedTime = o.time, i.fedFraction = r;
4096
4506
  for (let [e, t] of c) a.setMarkPrice(e, t);
4097
4507
  let l = c[c.length - 1]?.[0];
@@ -4106,9 +4516,9 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4106
4516
  if (!t) return;
4107
4517
  let n = this.series.inHoursShown(this.series.liveBars());
4108
4518
  if (n.length === 0) return;
4109
- 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;
4110
4520
  this.useReplayLoader(t, !1);
4111
- let a = this.replayStepsOver(t, i), o = t.animate ? null : a, s = t.until === null ? 0 : pi(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);
4112
4522
  if (s < 0 && this.canPageBackForReplay(t)) {
4113
4523
  this.holdReplay(), t.held && t.held.pagesBack++, queueMicrotask(() => void this.pageBackForReplay(t));
4114
4524
  return;
@@ -4116,7 +4526,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4116
4526
  let c = this.getReplayState(), l = t.held !== null && (e === "hours" || e === "bar"), u = t.held?.state ?? c;
4117
4527
  l || (t.held = null), t.symbol = this.currentSymbol;
4118
4528
  let d = this.replayManager.remainingMs();
4119
- this.clearBarHolders(), t.animate && fi(t, this.replayCoarse, i);
4529
+ this.clearBarHolders(), t.animate && Di(t, this.replayCoarse, i);
4120
4530
  let f = this.replayRestarting;
4121
4531
  this.replayRestarting = !0, this.replayCause = e === "older" ? "older" : "series";
4122
4532
  try {
@@ -4139,14 +4549,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4139
4549
  }
4140
4550
  replayStepsOver(e, t, n = !1) {
4141
4551
  if (!e.steps || e.stepsSymbol !== this.currentSymbol) return null;
4142
- let r = vi(this.series.inHoursShown(e.steps), t);
4143
- return r && (n || hi(r, t)) ? r : null;
4552
+ let r = Pi(this.series.inHoursShown(e.steps), t);
4553
+ return r && (n || Ai(r, t)) ? r : null;
4144
4554
  }
4145
4555
  canPageBackForReplay(e) {
4146
- return this.history.hasLoader() && this.history.hasMore() && (e.held?.pagesBack ?? 0) < si;
4556
+ return this.history.hasLoader() && this.history.hasMore() && (e.held?.pagesBack ?? 0) < Si;
4147
4557
  }
4148
4558
  async pageBackForReplay(e) {
4149
- this.replaySession !== e || !e.held || await this.history.loadMore() > 0 || this.replaySession !== e || !e.held || (e.held.pagesBack = si, 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"));
4150
4560
  }
4151
4561
  holdReplay() {
4152
4562
  let e = this.replaySession;
@@ -4179,7 +4589,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4179
4589
  this.signalMarkerManager.setRevealUntil(e, t), this.tradeZoneManager.setRevealUntil(e, t);
4180
4590
  }
4181
4591
  replaySeekToTime(e) {
4182
- !this.replaySession || !this.replayCoarse || this.replaySeek(Math.max(0, pi(this.replayStepsSeries ?? this.replayCoarse, e)));
4592
+ !this.replaySession || !this.replayCoarse || this.replaySeek(Math.max(0, Oi(this.replayStepsSeries ?? this.replayCoarse, e)));
4183
4593
  }
4184
4594
  feedReplayPrice(e, t) {
4185
4595
  let n = this.executionAdapter;
@@ -4199,10 +4609,10 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4199
4609
  return;
4200
4610
  }
4201
4611
  if (i.time <= n.fedTime) return;
4202
- let a = e.slice(X(e, n.fedTime), t + 1);
4612
+ let a = e.slice(Z(e, n.fedTime), t + 1);
4203
4613
  n.fedTime = i.time;
4204
- let o = Math.ceil(a.length / gi);
4205
- for (let e = 0; e < a.length; e += o) for (let [t, n] of _i(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);
4206
4616
  this.tradingManager.setCurrentPrice(i.close);
4207
4617
  }
4208
4618
  getReplayBarIndex() {
@@ -4213,7 +4623,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4213
4623
  }
4214
4624
  replaySeekToBar(e) {
4215
4625
  let t = this.replayStepsSeries;
4216
- this.replaySeek(t && this.replayCoarse ? yi(t, this.replayCoarse, e) : e);
4626
+ this.replaySeek(t && this.replayCoarse ? Fi(t, this.replayCoarse, e) : e);
4217
4627
  }
4218
4628
  replayPause() {
4219
4629
  this.setHeldState("paused") || this.replayManager.pause();
@@ -4254,7 +4664,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4254
4664
  let { x: r, y: c } = this.drawingManager.anchorPoint(t.type, e, n);
4255
4665
  i = Math.min(i, r), a = Math.max(a, r), o = Math.min(o, c), s = Math.max(s, c);
4256
4666
  }
4257
- return Jr.has(t.type) ? [i, a] = [r.x, r.x + r.width] : t.type === "horizontalRay" && (a = r.x + r.width), Yr.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 ? {
4258
4668
  x: i,
4259
4669
  y: o,
4260
4670
  width: a - i,
@@ -4290,7 +4700,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4290
4700
  };
4291
4701
  }
4292
4702
  captureSnapshot() {
4293
- return T.capture({
4703
+ return E.capture({
4294
4704
  getDrawings: () => [...this.getDrawings().filter((e) => e.paneId === void 0 || this.layoutManager.getPanels().some((t) => t.id === e.paneId)), ...this.keptPaneDrawings],
4295
4705
  getTheme: () => this.themeManager.getBaseTheme(),
4296
4706
  getAlerts: () => this.getAlerts(),
@@ -4303,26 +4713,23 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4303
4713
  });
4304
4714
  }
4305
4715
  restoreIndicators(e, t) {
4306
- let n = Zr(e), r = /* @__PURE__ */ new Map();
4716
+ let n = er(e), r = /* @__PURE__ */ new Map();
4307
4717
  this.unrestoredIndicators = [];
4308
4718
  let i = new Set(this.indicatorEngine.getAvailableIndicators().map((e) => e.id)), a = [], o = /* @__PURE__ */ new Set();
4309
4719
  if (t) {
4310
- let e = new Map(n.map((e) => [e.instanceId, e])), t = this.getIndicatorSetup();
4311
- for (let n of t) {
4312
- let t = e.get(n.instanceId);
4313
- t && Qr(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
+ }
4314
4730
  }
4315
- for (let e of t) o.has(e.instanceId) || this.removeIndicator(e.instanceId);
4316
- for (let e of [...o]) this.indicatorEngine.getIndicatorConfig(e) || o.delete(e);
4317
4731
  } else for (let e of this.indicatorEngine.getActiveIndicators()) this.removeIndicator(e.instanceId);
4318
- let s = (e) => {
4319
- let t = { ...e };
4320
- for (let [e, n] of Object.entries(t)) {
4321
- let i = x(n), a = i && r.get(i.instanceId);
4322
- a && (t[e] = v(a, i.key));
4323
- }
4324
- return t;
4325
- };
4732
+ let s = (e) => ir(e, r);
4326
4733
  for (let e of n) {
4327
4734
  let n = null;
4328
4735
  if (o.has(e.instanceId)) {
@@ -4355,7 +4762,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4355
4762
  }
4356
4763
  r.set(e.instanceId, n), a.push([e, n]), this.restoreLooks(n, e);
4357
4764
  }
4358
- 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;
4359
4766
  }
4360
4767
  restoreLooks(e, t) {
4361
4768
  let { plots: n, ...r } = this.indicatorEngine.getIndicatorStyle(e) ?? {
@@ -4372,50 +4779,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4372
4779
  let s = t.levels ?? null;
4373
4780
  JSON.stringify(s) !== JSON.stringify(o?.levels ?? null) && this.setIndicatorLevels(e, s);
4374
4781
  let c = t.intervals ?? null;
4375
- JSON.stringify(c) !== JSON.stringify(o?.intervals ?? null) && this.setIndicatorIntervalsNow(e, c), this.setPaneStyleNow(e, t.paneStyle ? se(t.paneStyle) : null);
4376
- }
4377
- restorePanes(e) {
4378
- 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, {
4379
- log: !!t.paneLog,
4380
- invert: !!t.paneInvert,
4381
- percent: !!t.panePercent
4382
- });
4383
- let t = e.filter(([e]) => e.paneOrder !== void 0).sort(([e], [t]) => (e.paneOrder ?? 0) - (t.paneOrder ?? 0)).map(([, e]) => e);
4384
- t.length > 1 && this.layoutManager.orderPanels(t);
4385
- let n = e.find(([e]) => e.paneMaximized);
4386
- 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);
4387
4783
  }
4388
4784
  getIndicatorSetup() {
4389
- let e = this.layoutManager.getPanels(), t = this.layoutManager.getMaximizedPanel();
4390
- return [...this.indicatorEngine.getActiveIndicators().map((n) => {
4391
- let r = e.find((e) => e.id === n.instanceId), i = this.indicatorEngine.getIndicatorConfig(n.instanceId);
4392
- return {
4393
- id: n.id,
4394
- instanceId: n.instanceId,
4395
- params: { ...n.params },
4396
- position: r?.position,
4397
- style: this.indicatorEngine.getIndicatorStyle(n.instanceId) ?? void 0,
4398
- visible: n.visible,
4399
- levels: i?.levels?.slice(),
4400
- pane: n.pane,
4401
- scale: i?.scale,
4402
- ...i?.intervals ? { intervals: this.indicatorEngine.getIntervals(n.instanceId) ?? void 0 } : {},
4403
- ...r && this.paneStyles.has(n.instanceId) ? { paneStyle: { ...this.paneStyles.get(n.instanceId) } } : {},
4404
- ...r ? {
4405
- paneSize: r.size,
4406
- paneOrder: e.indexOf(r),
4407
- ...r.collapsed ? { paneCollapsed: !0 } : {},
4408
- ...t === n.instanceId ? { paneMaximized: !0 } : {},
4409
- ...r.logScale ? { paneLog: !0 } : {},
4410
- ...r.invertScale ? { paneInvert: !0 } : {},
4411
- ...r.percentScale ? { panePercent: !0 } : {}
4412
- } : {}
4413
- };
4414
- }), ...this.unrestoredIndicators];
4785
+ return [...Qn(this.indicatorEngine, this.layoutManager, (e) => this.panes.style(e) ?? null), ...this.unrestoredIndicators];
4415
4786
  }
4416
4787
  applyIndicatorSetup(e) {
4417
- this.features.indicators && this.recordIndicators(void 0, () => {
4418
- 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));
4419
4790
  this.followIndicatorAlerts(t, [...n.values()]), this.markStateChanged();
4420
4791
  });
4421
4792
  }
@@ -4443,117 +4814,49 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4443
4814
  }
4444
4815
  }
4445
4816
  beginIndicatorEdit(e) {
4446
- this.endIndicatorEdit(), this.features.drawingUndoRedo && (this.indicatorEdit = {
4447
- subject: e,
4448
- before: this.getIndicatorSetup()
4449
- }, this.indicatorHistoryDepth++);
4817
+ this.indicatorHistory.begin(e);
4450
4818
  }
4451
4819
  endIndicatorEdit() {
4452
- let e = this.indicatorEdit;
4453
- if (!e) return;
4454
- this.indicatorEdit = null, this.indicatorHistoryDepth--;
4455
- let t = this.getIndicatorSetup();
4456
- JSON.stringify(t) !== JSON.stringify(e.before) && this.undoRedoManager.push({
4457
- type: "indicators",
4458
- before: null,
4459
- after: null,
4460
- indicators: {
4461
- before: e.before,
4462
- after: t,
4463
- subject: e.subject,
4464
- at: performance.now()
4465
- }
4466
- });
4467
- }
4468
- withoutIndicatorHistory(e) {
4469
- this.indicatorHistoryDepth++;
4470
- try {
4471
- return e();
4472
- } finally {
4473
- this.indicatorHistoryDepth--;
4474
- }
4475
- }
4476
- recordIndicators(e, t) {
4477
- if (this.indicatorHistoryDepth > 0 || !this.features.drawingUndoRedo) return t();
4478
- let n = this.getIndicatorSetup(), r = [], i = this.paneRenames;
4479
- this.paneRenames = r;
4480
- let a;
4481
- try {
4482
- a = this.withoutIndicatorHistory(t);
4483
- } finally {
4484
- this.paneRenames = i;
4485
- }
4486
- let o = this.getIndicatorSetup();
4487
- if (JSON.stringify(n) === JSON.stringify(o)) return a;
4488
- let s = performance.now(), c = this.undoRedoManager.last(), l = e !== void 0 && c?.type === "indicators" && c.indicators?.subject === e && s - (c.indicators.at ?? 0) < Vr && JSON.stringify(c.indicators.after) === JSON.stringify(n), u = {
4489
- type: "indicators",
4490
- before: null,
4491
- after: null
4492
- };
4493
- return l && c?.indicators ? JSON.stringify(c.indicators.before) === JSON.stringify(o) ? this.undoRedoManager.dropLast() : this.undoRedoManager.replaceLast({
4494
- ...u,
4495
- indicators: {
4496
- ...c.indicators,
4497
- after: o,
4498
- at: s,
4499
- ...Ur([...c.indicators.renames ?? [], ...r])
4500
- }
4501
- }) : this.undoRedoManager.push({
4502
- ...u,
4503
- indicators: {
4504
- before: n,
4505
- after: o,
4506
- subject: e,
4507
- at: s,
4508
- ...Ur(r)
4509
- }
4510
- }), a;
4820
+ this.indicatorHistory.end();
4511
4821
  }
4512
4822
  applyIndicatorStep(e, t) {
4513
4823
  let n = e.indicators;
4514
4824
  if (!n) return;
4515
- 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
+ }
4516
4831
  let r = n.renames ?? [], i = t === "undo" ? [...r].reverse().map(([e, t]) => [t, e]) : r;
4517
4832
  for (let [e, t] of i) this.drawingManager.renamePanes(new Map([[e, t]]));
4518
4833
  this.markStateChanged();
4519
4834
  }
4520
4835
  keptPaneDrawings = [];
4836
+ replayingIndicatorStep = !1;
4521
4837
  takesDrawing(e, t) {
4522
- 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);
4523
4839
  }
4524
- paneRenames = null;
4525
4840
  renamePane(e, t) {
4526
- 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);
4527
4842
  }
4528
4843
  drawingPaneAt(e) {
4529
- let t = (t) => e.x >= t.x && e.x <= t.x + t.width && e.y >= t.y && e.y <= t.y + t.height;
4530
- if (!t(this.viewport.getState().chartRect)) {
4531
- for (let e of this.layoutManager.getPanels()) {
4532
- let n = this.drawingPaneViewport(e.id);
4533
- if (n && t(n.chartRect)) return e.id;
4534
- }
4535
- return null;
4536
- }
4844
+ return cr(e, this.viewport.getState().chartRect, this.layoutManager.getPanels(), (e) => this.drawingPaneViewport(e));
4537
4845
  }
4538
4846
  drawingPaneViewport(e) {
4539
4847
  let t = this.layoutManager.getPanels().find((t) => t.id === e);
4540
- if (!t || t.position !== "top" && t.position !== "bottom" || this.layoutManager.isPanelShownCollapsed(e)) return null;
4541
- let n = this.buildPanelRenderInfos().find((t) => t.instanceId === e);
4542
- return !n || n.viewport.chartRect.height < Hr ? null : {
4543
- ...n.viewport,
4544
- data: this.getDisplayData()
4545
- };
4848
+ return lr(t, !!t && this.layoutManager.isPanelShownCollapsed(e), () => this.buildPanelRenderInfos().find((t) => t.instanceId === e)?.viewport, () => this.getDisplayData());
4546
4849
  }
4547
4850
  saveState(e) {
4548
4851
  if (!this.features.saveLoad) return null;
4549
- let t = this.captureSnapshot(), n = T.serialize(t);
4550
- return e && T.saveToStorage(e, t), n;
4852
+ let t = this.captureSnapshot(), n = E.serialize(t);
4853
+ return e && E.saveToStorage(e, t), n;
4551
4854
  }
4552
4855
  loadState(e) {
4553
4856
  if (!this.features.saveLoad) return;
4554
- let t = T.deserialize(e);
4555
- 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");
4556
- 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();
4557
4860
  this.drawingManager.renamePanes(n);
4558
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));
4559
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) {
@@ -4564,7 +4867,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4564
4867
  let t = e.indexOf(":"), r = t > 0 ? n.get(e.slice(0, t)) : void 0;
4565
4868
  return r ? r + e.slice(t) : e;
4566
4869
  }, r = t(e.channel), i = {
4567
- ...zt(e),
4870
+ ...Bt(e),
4568
4871
  ...e.target ? { target: t(e.target) } : {}
4569
4872
  };
4570
4873
  if (!e.expired) {
@@ -4584,19 +4887,19 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4584
4887
  }
4585
4888
  loadStateFromStorage(e) {
4586
4889
  if (!this.features.saveLoad) return !1;
4587
- let t = T.loadFromStorage(e);
4588
- 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;
4589
4892
  }
4590
4893
  downloadState(e) {
4591
- this.features.saveLoad && T.downloadFile(this.captureSnapshot(), e);
4894
+ this.features.saveLoad && E.downloadFile(this.captureSnapshot(), e);
4592
4895
  }
4593
4896
  async loadStateFromFile() {
4594
4897
  if (!this.features.saveLoad) return;
4595
- let e = await T.loadFromFile();
4596
- this.loadState(T.serialize(e));
4898
+ let e = await E.loadFromFile();
4899
+ this.loadState(E.serialize(e));
4597
4900
  }
4598
4901
  setLocale(e) {
4599
- le(e), this.engine.requestRender();
4902
+ ce(e), this.engine.requestRender();
4600
4903
  }
4601
4904
  setNumberLocale(e) {
4602
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();
@@ -4646,24 +4949,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4646
4949
  this.disposed = !0, this.stopWatchingVisibility?.(), this.stopWatchingVisibility = null, this.waitForGpu(null), this.countdownInterval && clearInterval(this.countdownInterval), this.history.setLoader(null), this.disableAutoSave(), this.disconnectStream(), this.disconnectExecution(), this.onWindowKeyDown &&= (window.removeEventListener("keydown", this.onWindowKeyDown), null), this.keyboardHandler = null, this.a11y?.destroy(), this.a11y = null, this.interactionManager.detach(), this.tradingManager.destroy(), this.animator.dispose(), this.crosshairTooltip.destroy(), this.pinnedTooltip.destroy(), this.replayRestarting = !0, this.replayManager.dispose(), this.alertManager.dispose(), this.undoRedoManager.clear(), this.engine.destroy(), this.eventBus.destroy(), this.labelWidths.destroy(), this.container.innerHTML = "";
4647
4950
  }
4648
4951
  createChartRenderer(e) {
4649
- let t = kn(e, (e) => this.pluginManager.getChartType(e));
4650
- return t instanceof ze && t.setPriceText((e) => this.formatPrice(e)), t;
4952
+ let t = An(e, (e) => this.pluginManager.getChartType(e));
4953
+ return t instanceof Re && t.setPriceText((e) => this.formatPrice(e)), t;
4651
4954
  }
4652
4955
  crosshairSeries() {
4653
4956
  return this.isTimeAligned() ? this.series.bars() : this.getDisplayData();
4654
4957
  }
4655
4958
  getDisplayData() {
4656
- let e = this.series.bars(), t = this.options.chartType === "rangeBars" ? En(e, (e) => this.stepAt(e)) : void 0;
4657
- if (this.displayDataCache && t === this.displayDataStep) return this.displayDataCache;
4658
- if (e.length === 0) return e;
4659
- let n = this.displaySeries(e, t);
4660
- return this.displayDataCache = n, this.displayDataStep = t, n;
4661
- }
4662
- displaySeries(e, t) {
4663
- let n = this.options.chartType, r = (e) => this.pluginManager.getChartType(e);
4664
- if (n !== "pointAndFigure" || r(n)) return An(n, e, r, this.chartTypeOptions, t, this.reshapeMemo);
4665
- let { columns: i, boxSize: a } = pn(e, this.chartTypeOptions, this.reshapeMemo);
4666
- return this.chartRenderer instanceof tt && this.chartRenderer.setBoxSize(a), i;
4959
+ return this.display.get();
4667
4960
  }
4668
4961
  recalcIndicatorsFrom(e, t) {
4669
4962
  if (!this.isTimeAligned()) return this.recalcIndicators(e);
@@ -4675,7 +4968,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4675
4968
  }
4676
4969
  exportBars() {
4677
4970
  if (this.isTimeAligned()) return this.series.bars();
4678
- let e = this.getDisplayData(), t = A(e);
4971
+ let e = this.getDisplayData(), t = At(e);
4679
4972
  return e.map((e, n) => ({
4680
4973
  ...e,
4681
4974
  time: t[n]?.time ?? e.time
@@ -4718,50 +5011,38 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4718
5011
  }
4719
5012
  }
4720
5013
  refitForTick() {
4721
- 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();
4722
5015
  }
4723
5016
  applyDataToViewport(e = !1) {
4724
5017
  let t = this.getDisplayData();
4725
- this.syncIndicatorBars(t);
4726
- let n = this.options.autoScale !== !1 || this.priceFitPending;
4727
- this.viewport.updateData(t, !1), e && (this.viewport.scrollToEnd(), this.viewport.updateData(t, !1));
4728
- 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();
4729
5020
  if (t.length > 0) {
4730
- 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));
4731
5022
  this.viewport.setScaleBaseline(t[e]?.close);
4732
5023
  }
4733
- return n && this.fitPriceScale(t, this.viewport.getState()), t;
5024
+ return this.priceFit.shouldFit() && this.fitPriceScale(t, this.viewport.getState()), t;
4734
5025
  }
4735
5026
  fitPriceScale(e, t) {
4736
- if (e.length === 0) return;
4737
- let n = Math.max(0, t.visibleRange.from), r = Math.min(t.visibleRange.to, e.length - 1), i = ii(ii(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() && ri(e, n, r) ? this.volumeRenderer.getHeightRatio() + Br : D;
4738
- this.viewport.setScaleMargins(this.viewport.isInvertScale() ? {
4739
- top: a,
4740
- bottom: D
4741
- } : {
4742
- top: D,
4743
- bottom: a
4744
- }), 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
+ });
4745
5032
  }
4746
5033
  updateViewportAndRender(e = !1) {
4747
- 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);
4748
5035
  let t = this.getResolvedLayout();
4749
5036
  this.viewport.setChartRect(t.mainChartRect), this.fitDataAndAxes(e), this.syncRenderContext(), this.engine.requestRender(), this.emitViewportEvents();
4750
5037
  }
4751
5038
  fitDataAndAxes(e = !1) {
4752
5039
  let t = this.applyDataToViewport(e), n = this.fitPriceAxisWidth();
4753
- this.leftViewport = this.computeLeftViewport(), (this.fitLeftAxisWidth() || n) && this.applyDataToViewport(e), this.priceFitPending && this.priceFitDone(t) && (this.priceFitPending = !1);
4754
- }
4755
- priceFitDone(e) {
4756
- let { chartRect: t, offset: n, barWidth: r, barSpacing: i } = this.viewport.getState();
4757
- if (e.length === 0 || t.width <= 0) return !1;
4758
- let a = n <= 0 && e.length * (r + i) - n <= t.width;
4759
- return !(this.seriesArriving && a);
5040
+ this.leftViewport = this.computeLeftViewport(), (this.fitLeftAxisWidth() || n) && this.applyDataToViewport(e), this.priceFit.settle(this.viewport.getState(), t.length);
4760
5041
  }
4761
5042
  fitLeftAxisWidth() {
4762
5043
  let e = this.leftViewport;
4763
5044
  if (!e) return !1;
4764
- let t = this.themeManager.getTheme(), n = tr({
5045
+ let t = this.themeManager.getTheme(), n = Er({
4765
5046
  min: e.priceRange.min,
4766
5047
  max: e.priceRange.max,
4767
5048
  lastPrice: null,
@@ -4770,12 +5051,12 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4770
5051
  fontFamily: t.font.family,
4771
5052
  fontSizeSmall: t.font.sizeSmall,
4772
5053
  measure: (e, t) => this.measureText(e, t)
4773
- }), r = nr(this.leftAxisWidth, n);
4774
- 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);
4775
5056
  }
4776
5057
  fitPriceAxisWidth() {
4777
5058
  if (!this.features.priceAxis) return !1;
4778
- let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = tr({
5059
+ let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = Er({
4779
5060
  min: e.min,
4780
5061
  max: e.max,
4781
5062
  lastPrice: this.currentPriceLine.getPrice(),
@@ -4786,14 +5067,14 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4786
5067
  fontFamily: t.font.family,
4787
5068
  fontSizeSmall: t.font.sizeSmall,
4788
5069
  measure: (e, t) => this.measureText(e, t)
4789
- }), r = nr(this.priceAxisWidth, n);
4790
- 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);
4791
5072
  }
4792
5073
  measureText(e, t) {
4793
5074
  let n = this.engine.layerManager.getLayer(r.Main)?.ctx;
4794
- if (n?.canvas.isConnected) return this.labelWidths.get(e, t, () => $r(n, e, t));
5075
+ if (n?.canvas.isConnected) return this.labelWidths.get(e, t, () => _i(n, e, t));
4795
5076
  let i = n ?? this.detachedMeasureContext();
4796
- return i ? $r(i, e, t) : e.length * 7;
5077
+ return i ? _i(i, e, t) : e.length * 7;
4797
5078
  }
4798
5079
  detachedMeasureContext() {
4799
5080
  return this.measureCtx === void 0 && (this.measureCtx = typeof document < "u" ? document.createElement("canvas").getContext("2d") : null), this.measureCtx;
@@ -4817,57 +5098,18 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4817
5098
  })), this.lastEmittedBarWidth !== e.barWidth && (this.lastEmittedBarWidth = e.barWidth, this.eventBus.emit("zoomChange", { barWidth: e.barWidth })), this.checkHistory();
4818
5099
  }
4819
5100
  getResolvedLayout() {
4820
- return this.resolvedLayoutCache || (this.resolvedLayoutCache = this.layoutManager.resolve(), this.syncCrosshairBounds(this.resolvedLayoutCache)), this.resolvedLayoutCache;
4821
- }
4822
- syncCrosshairBounds(e) {
4823
- let t = e.mainChartRect, n = t.y, r = t.y + t.height;
4824
- 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));
4825
- this.crosshairHandler.setReportBounds({
4826
- top: n,
4827
- bottom: r
4828
- });
5101
+ return this.panes.resolved();
4829
5102
  }
4830
5103
  cachedContainerSize() {
4831
5104
  let e = Date.now();
4832
5105
  return (!this.containerSizeCache || e - this.containerSizeCacheTime > 500) && (this.containerSizeCache = this.engine.dprManager.getContainerSize(), this.containerSizeCacheTime = e), this.containerSizeCache;
4833
5106
  }
4834
5107
  buildPanelRenderInfos() {
4835
- if (this.panelInfoCache) return this.panelInfoCache;
4836
- let e = this.getResolvedLayout(), t = this.viewport.getState(), { from: n, to: r } = t.visibleRange, i = e.panels.map((e) => {
4837
- 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) ?? { ...Pr }, o = {
4838
- x: e.rect.x,
4839
- y: e.rect.y + 20,
4840
- width: e.rect.width,
4841
- height: Math.max(0, e.rect.height - 20)
4842
- }, s = this.paneStyles.get(e.config.id);
4843
- return {
4844
- instanceId: e.config.id,
4845
- members: this.indicatorEngine.getPaneMembers(e.config.id),
4846
- ...s ? { style: s } : {},
4847
- rect: e.rect,
4848
- viewport: {
4849
- ...t,
4850
- chartRect: o,
4851
- priceRange: a,
4852
- logScale: i !== null,
4853
- scaleMode: e.config.percentScale ? "percentage" : "regular",
4854
- scaleBaseline: e.config.percentScale ? this.paneBaseline(e.config.id, n, r) : void 0,
4855
- formatPrice: void 0,
4856
- pricePrecision: void 0,
4857
- priceUnit: void 0,
4858
- invertScale: !!e.config.invertScale
4859
- }
4860
- };
4861
- });
4862
- return this.panelInfoCache = i, i;
4863
- }
4864
- timeAxisTop() {
4865
- let e = this.getResolvedLayout(), t = e.panels.filter((e) => e.config.position === "bottom").reduce((e, t) => e + t.rect.height, 0);
4866
- return e.mainChartRect.y + e.mainChartRect.height + t;
5108
+ return this.panes.panels(() => this.viewport.getState());
4867
5109
  }
4868
5110
  syncRenderContext() {
4869
5111
  this.pinnedTooltip.isPinned() && this.pinnedTooltip.reposition(this.viewport.getState(), null, null, this.themeManager.getTheme());
4870
- 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();
4871
5113
  this.leftViewport = this.computeLeftViewport(), this.engine.setRenderContext({
4872
5114
  leftViewport: this.leftViewport,
4873
5115
  leftPriceAxis: this.leftPriceAxis,
@@ -4919,7 +5161,7 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4919
5161
  });
4920
5162
  }
4921
5163
  drawOverlayPlugins(e, t) {
4922
- let n = sr(this.pluginManager.getOverlays(), t);
5164
+ let n = Mr(this.pluginManager.getOverlays(), t);
4923
5165
  if (n.length === 0) return;
4924
5166
  let r = {
4925
5167
  viewport: this.viewport.getState(),
@@ -4940,33 +5182,16 @@ var Wr = 20, Gr = 8, Kr = 10, qr = {
4940
5182
  };
4941
5183
  }
4942
5184
  };
4943
- function Zr(e) {
4944
- let t = new Map(e.map((e) => [e.instanceId, e])), n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
4945
- if (r.has(e.instanceId) || i.has(e.instanceId)) return;
4946
- i.add(e.instanceId);
4947
- let o = [e.pane, ...Object.values(e.params).map((e) => x(e)?.instanceId)];
4948
- for (let e of o) {
4949
- let n = e ? t.get(e) : void 0;
4950
- n && a(n);
4951
- }
4952
- i.delete(e.instanceId), r.add(e.instanceId), n.push(e);
4953
- };
4954
- for (let t of e) a(t);
4955
- return n;
4956
- }
4957
- function Qr(e, t) {
4958
- 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);
4959
- }
4960
- function $r(e, t, n) {
5185
+ function _i(e, t, n) {
4961
5186
  let r = e.font;
4962
5187
  e.font = n;
4963
5188
  let i = e.measureText(t).width;
4964
5189
  return e.font = r, i;
4965
5190
  }
4966
- var ei = 300;
4967
- function ti(e) {
5191
+ var vi = 300;
5192
+ function yi(e) {
4968
5193
  let t = {}, n = e.family;
4969
- typeof n == "string" && n.trim() !== "" && n.length <= ei && !/[;{}<>\\]|\/\*/.test(n) && (t.family = n);
5194
+ typeof n == "string" && n.trim() !== "" && n.length <= vi && !/[;{}<>\\]|\/\*/.test(n) && (t.family = n);
4970
5195
  for (let n of [
4971
5196
  "sizeSmall",
4972
5197
  "sizeMedium",
@@ -4977,21 +5202,11 @@ function ti(e) {
4977
5202
  }
4978
5203
  return t;
4979
5204
  }
4980
- function ni(e) {
5205
+ function bi(e) {
4981
5206
  let t = e.tagRadius;
4982
5207
  return typeof t == "number" && Number.isFinite(t) && t >= 0 ? { tagRadius: Math.min(t, 999) } : {};
4983
5208
  }
4984
- function ri(e, t, n) {
4985
- for (let r = t; r <= n; r++) if (e[r].volume > 0) return !0;
4986
- return !1;
4987
- }
4988
- function ii(e, t) {
4989
- return e ? t ? {
4990
- min: Math.min(e.min, t.min),
4991
- max: Math.max(e.max, t.max)
4992
- } : e : t;
4993
- }
4994
- function J(e) {
5209
+ function Y(e) {
4995
5210
  return {
4996
5211
  id: e.id,
4997
5212
  price: e.price,
@@ -5006,14 +5221,8 @@ function J(e) {
5006
5221
  bars: e.bars
5007
5222
  };
5008
5223
  }
5009
- var ai = 8e3, oi = new Set([
5010
- "candlestick",
5011
- "line",
5012
- "area",
5013
- "bar",
5014
- "hollowCandle"
5015
- ]), si = 10, ci = 50, li = .001;
5016
- function ui(e) {
5224
+ var xi = 8e3, Si = 10, Ci = 50, wi = .001;
5225
+ function Ti(e) {
5017
5226
  return {
5018
5227
  price: null,
5019
5228
  fedTime: null,
@@ -5028,42 +5237,42 @@ function ui(e) {
5028
5237
  held: null
5029
5238
  };
5030
5239
  }
5031
- function di(e, t) {
5240
+ function Ei(e, t) {
5032
5241
  let n = e[t + 1];
5033
- return n ? n.time - e[t].time : Z(e);
5242
+ return n ? n.time - e[t].time : Ni(e);
5034
5243
  }
5035
- function fi(e, t, n) {
5244
+ function Di(e, t, n) {
5036
5245
  let r = e.fedTime;
5037
5246
  if (r === null || !t || t.length === 0 || n.length === 0) return;
5038
- let i = di(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;
5039
5248
  if (s > a) return;
5040
- let c = di(n, o);
5249
+ let c = Ei(n, o);
5041
5250
  if (a === s && o > 0) {
5042
5251
  e.fedTime = n[o - 1].time, e.fedFraction = 1;
5043
5252
  return;
5044
5253
  }
5045
5254
  e.fedTime = s, e.fedFraction = Number.isFinite(c) && c > 0 ? Math.min(1, (a - s) / c) : 0;
5046
5255
  }
5047
- function pi(e, t) {
5048
- let n = X(e, t), r = e.length - 1;
5049
- 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);
5050
5259
  }
5051
- function mi(e) {
5260
+ function ki(e) {
5052
5261
  let t = Infinity;
5053
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);
5054
5263
  return t;
5055
5264
  }
5056
- function hi(e, t) {
5057
- if (!(mi(e) < mi(t))) return !1;
5058
- let n = Math.max(0, e.length - ci);
5265
+ function Ai(e, t) {
5266
+ if (!(ki(e) < ki(t))) return !1;
5267
+ let n = Math.max(0, e.length - Ci);
5059
5268
  for (let r = n; r < e.length; r++) {
5060
- let n = t[Q(t, e[r].time)], i = (n.high - n.low) * li + 2 ** -52;
5269
+ let n = t[Q(t, e[r].time)], i = (n.high - n.low) * wi + 2 ** -52;
5061
5270
  if (e[r].close > n.high + i || e[r].close < n.low - i) return !1;
5062
5271
  }
5063
5272
  return !0;
5064
5273
  }
5065
- var gi = 500;
5066
- function Y(e, t) {
5274
+ var ji = 500;
5275
+ function X(e, t) {
5067
5276
  let n = 0, r = e.length;
5068
5277
  for (; n < r;) {
5069
5278
  let i = n + r >> 1;
@@ -5071,7 +5280,7 @@ function Y(e, t) {
5071
5280
  }
5072
5281
  return n;
5073
5282
  }
5074
- function X(e, t) {
5283
+ function Z(e, t) {
5075
5284
  let n = 0, r = e.length;
5076
5285
  for (; n < r;) {
5077
5286
  let i = n + r >> 1;
@@ -5079,20 +5288,20 @@ function X(e, t) {
5079
5288
  }
5080
5289
  return n;
5081
5290
  }
5082
- function _i(e) {
5291
+ function Mi(e) {
5083
5292
  let t = 0, n = 0;
5084
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);
5085
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];
5086
5295
  return [...a ? [r, i] : [i, r], [o.close, o.time]];
5087
5296
  }
5088
- function Z(e) {
5297
+ function Ni(e) {
5089
5298
  let t = 0;
5090
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);
5091
5300
  return t > 0 ? t : Infinity;
5092
5301
  }
5093
- function vi(e, t) {
5302
+ function Pi(e, t) {
5094
5303
  if (t.length === 0) return null;
5095
- let n = t[t.length - 1].time + Z(t), r = e.filter((e) => Ln(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 = [];
5096
5305
  for (let e of r) (i.length === 0 || i[i.length - 1].time !== e.time) && i.push(e);
5097
5306
  if (i.length === 0) return null;
5098
5307
  let a = t.findIndex((e) => e.time >= i[0].time);
@@ -5108,26 +5317,26 @@ function Q(e, t) {
5108
5317
  }
5109
5318
  return n;
5110
5319
  }
5111
- function yi(e, t, n) {
5320
+ function Fi(e, t, n) {
5112
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;
5113
5322
  for (let t = 0; t < e.length && e[t].time < i; t++) a = t;
5114
5323
  return Math.max(0, a);
5115
5324
  }
5116
- function bi(e, t, n) {
5325
+ function Ii(e, t, n) {
5117
5326
  let r = n;
5118
5327
  for (; r > 0 && t[r - 1].time >= e.time;) r--;
5119
5328
  let i = {
5120
5329
  ...t[r],
5121
5330
  time: e.time
5122
5331
  };
5123
- for (let e = r + 1; e <= n; e++) i = wi(i, t[e]);
5332
+ for (let e = r + 1; e <= n; e++) i = Bi(i, t[e]);
5124
5333
  return i;
5125
5334
  }
5126
- function xi(e, t, n, r) {
5335
+ function Li(e, t, n, r) {
5127
5336
  let i = e[n + 1], a = t[r + 1];
5128
5337
  return i !== void 0 && a !== void 0 && i.time >= a.time;
5129
5338
  }
5130
- function Si(e, t) {
5339
+ function Ri(e, t) {
5131
5340
  let n = /* @__PURE__ */ new Map();
5132
5341
  for (let r of e) {
5133
5342
  let e = t[Q(t, r.time)].time, i = n.get(e);
@@ -5135,10 +5344,10 @@ function Si(e, t) {
5135
5344
  }
5136
5345
  return n;
5137
5346
  }
5138
- function Ci() {
5347
+ function zi() {
5139
5348
  return typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
5140
5349
  }
5141
- function wi(e, t) {
5350
+ function Bi(e, t) {
5142
5351
  return {
5143
5352
  time: e.time,
5144
5353
  open: e.open,
@@ -5150,26 +5359,26 @@ function wi(e, t) {
5150
5359
  }
5151
5360
  //#endregion
5152
5361
  //#region src/io/parseOHLCV.ts
5153
- var Ti = [
5362
+ var Vi = [
5154
5363
  "time",
5155
5364
  "timestamp",
5156
5365
  "date",
5157
5366
  "datetime",
5158
5367
  "t"
5159
- ], Ei = ["open", "o"], Di = ["high", "h"], Oi = ["low", "l"], ki = ["close", "c"], Ai = [
5368
+ ], Hi = ["open", "o"], Ui = ["high", "h"], Wi = ["low", "l"], Gi = ["close", "c"], Ki = [
5160
5369
  "volume",
5161
5370
  "vol",
5162
5371
  "v"
5163
5372
  ];
5164
- function ji(e) {
5373
+ function qi(e) {
5165
5374
  let t = e.trim();
5166
- return t ? t[0] === "[" || t[0] === "{" ? Mi(t) : Ni(t) : {
5375
+ return t ? t[0] === "[" || t[0] === "{" ? Ji(t) : Yi(t) : {
5167
5376
  data: [],
5168
5377
  rowCount: 0,
5169
5378
  skipped: 0
5170
5379
  };
5171
5380
  }
5172
- function Mi(e) {
5381
+ function Ji(e) {
5173
5382
  let t;
5174
5383
  try {
5175
5384
  t = JSON.parse(e);
@@ -5179,19 +5388,19 @@ function Mi(e) {
5179
5388
  if (!Array.isArray(t)) throw Error("Expected a JSON array of OHLCV rows");
5180
5389
  let n = [], r = 0;
5181
5390
  for (let e of t) {
5182
- let t = Array.isArray(e) ? Ri(e) : Li(e);
5391
+ let t = Array.isArray(e) ? ea(e) : $i(e);
5183
5392
  t ? n.push(t) : r++;
5184
5393
  }
5185
- return Bi(n, t.length, r);
5394
+ return na(n, t.length, r);
5186
5395
  }
5187
- function Ni(e) {
5396
+ function Yi(e) {
5188
5397
  let t = e.split(/\r?\n/).filter((e) => e.trim().length > 0);
5189
5398
  if (t.length === 0) return {
5190
5399
  data: [],
5191
5400
  rowCount: 0,
5192
5401
  skipped: 0
5193
5402
  };
5194
- let n = Pi(t[0]), r = Fi(t[0], n).map((e) => e.trim().toLowerCase()), i = r.some((e) => isNaN(Number(e)) && e.length > 0), a = i ? Ii(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) : {
5195
5404
  time: 0,
5196
5405
  open: 1,
5197
5406
  high: 2,
@@ -5202,7 +5411,7 @@ function Ni(e) {
5202
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");
5203
5412
  let o = [], s = 0;
5204
5413
  for (let e = +!!i; e < t.length; e++) {
5205
- let r = Fi(t[e], n), i = zi(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;
5206
5415
  if (i === null || ![
5207
5416
  c,
5208
5417
  l,
@@ -5221,9 +5430,9 @@ function Ni(e) {
5221
5430
  volume: Number.isFinite(f) ? f : 0
5222
5431
  });
5223
5432
  }
5224
- return Bi(o, t.length - +!!i, s);
5433
+ return na(o, t.length - +!!i, s);
5225
5434
  }
5226
- function Pi(e) {
5435
+ function Xi(e) {
5227
5436
  let t = {
5228
5437
  ",": 0,
5229
5438
  ";": 0,
@@ -5235,7 +5444,7 @@ function Pi(e) {
5235
5444
  for (let [e, i] of Object.entries(t)) i > r && (n = e, r = i);
5236
5445
  return n;
5237
5446
  }
5238
- function Fi(e, t) {
5447
+ function Zi(e, t) {
5239
5448
  let n = [], r = "", i = !1;
5240
5449
  for (let a = 0; a < e.length; a++) {
5241
5450
  let o = e[a];
@@ -5243,25 +5452,25 @@ function Fi(e, t) {
5243
5452
  }
5244
5453
  return n.push(r), n;
5245
5454
  }
5246
- function Ii(e) {
5455
+ function Qi(e) {
5247
5456
  let t = (t) => e.findIndex((e) => t.includes(e));
5248
5457
  return {
5249
- time: t(Ti),
5250
- open: t(Ei),
5251
- high: t(Di),
5252
- low: t(Oi),
5253
- close: t(ki),
5254
- volume: t(Ai)
5458
+ time: t(Vi),
5459
+ open: t(Hi),
5460
+ high: t(Ui),
5461
+ low: t(Wi),
5462
+ close: t(Gi),
5463
+ volume: t(Ki)
5255
5464
  };
5256
5465
  }
5257
- function Li(e) {
5466
+ function $i(e) {
5258
5467
  let t = (t) => {
5259
5468
  for (let n of t) {
5260
5469
  if (e[n] !== void 0) return e[n];
5261
5470
  let t = n.toUpperCase();
5262
5471
  if (e[t] !== void 0) return e[t];
5263
5472
  }
5264
- }, n = zi(String(t(Ti) ?? "")), r = Number(t(Ei)), i = Number(t(Di)), a = Number(t(Oi)), o = Number(t(ki)), s = Number(t(Ai) ?? 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);
5265
5474
  return n === null || ![
5266
5475
  r,
5267
5476
  i,
@@ -5276,9 +5485,9 @@ function Li(e) {
5276
5485
  volume: Number.isFinite(s) ? s : 0
5277
5486
  };
5278
5487
  }
5279
- function Ri(e) {
5488
+ function ea(e) {
5280
5489
  if (e.length < 5) return null;
5281
- let t = zi(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;
5282
5491
  return t === null || ![
5283
5492
  n,
5284
5493
  r,
@@ -5296,7 +5505,7 @@ function Ri(e) {
5296
5505
  function $(e) {
5297
5506
  return e === void 0 || e.trim() === "" ? NaN : Number(e);
5298
5507
  }
5299
- function zi(e) {
5508
+ function ta(e) {
5300
5509
  let t = e.trim();
5301
5510
  if (!t) return null;
5302
5511
  let n = Number(t);
@@ -5304,7 +5513,7 @@ function zi(e) {
5304
5513
  let r = Date.parse(t);
5305
5514
  return Number.isFinite(r) ? r : null;
5306
5515
  }
5307
- function Bi(e, t, n) {
5516
+ function na(e, t, n) {
5308
5517
  e.sort((e, t) => e.time - t.time);
5309
5518
  let r = [];
5310
5519
  for (let t of e) r.length > 0 && r[r.length - 1].time === t.time ? r[r.length - 1] = t : r.push(t);
@@ -5316,7 +5525,7 @@ function Bi(e, t, n) {
5316
5525
  }
5317
5526
  //#endregion
5318
5527
  //#region src/io/DragDropImporter.ts
5319
- var Vi = class {
5528
+ var ra = class {
5320
5529
  host;
5321
5530
  overlay = null;
5322
5531
  callbacks;
@@ -5337,19 +5546,19 @@ var Vi = class {
5337
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();
5338
5547
  }
5339
5548
  onDragEnter(e) {
5340
- Hi(e) && (e.preventDefault(), this.depth++, this.showOverlay());
5549
+ ia(e) && (e.preventDefault(), this.depth++, this.showOverlay());
5341
5550
  }
5342
5551
  onDragOver(e) {
5343
- Hi(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"));
5552
+ ia(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"));
5344
5553
  }
5345
5554
  onDragLeave(e) {
5346
- Hi(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());
5347
5556
  }
5348
5557
  async onDrop(e) {
5349
5558
  e.preventDefault(), this.depth = 0, this.hideOverlay();
5350
5559
  let t = e.dataTransfer?.files?.[0];
5351
5560
  if (t) try {
5352
- let e = ji(await t.text());
5561
+ let e = qi(await t.text());
5353
5562
  if (e.data.length === 0) throw Error(`No valid OHLCV rows found in "${t.name}"`);
5354
5563
  this.callbacks.onData(e.data, e, t);
5355
5564
  } catch (e) {
@@ -5380,12 +5589,12 @@ var Vi = class {
5380
5589
  this.overlay?.remove(), this.overlay = null;
5381
5590
  }
5382
5591
  };
5383
- function Hi(e) {
5592
+ function ia(e) {
5384
5593
  return e.dataTransfer?.types?.includes("Files") ?? !1;
5385
5594
  }
5386
5595
  //#endregion
5387
5596
  //#region src/state/layoutStorage.ts
5388
- function Ui(e) {
5597
+ function aa(e) {
5389
5598
  let t = {
5390
5599
  id: e.id,
5391
5600
  name: e.name,
@@ -5393,11 +5602,11 @@ function Ui(e) {
5393
5602
  };
5394
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;
5395
5604
  }
5396
- var Wi = (e, t) => t.updatedAt - e.updatedAt;
5397
- function Gi(e) {
5605
+ var oa = (e, t) => t.updatedAt - e.updatedAt;
5606
+ function sa(e) {
5398
5607
  if (typeof e != "object" || !e) return null;
5399
5608
  let t = e;
5400
- return typeof t.id != "string" || !t.id || typeof t.name != "string" || typeof t.updatedAt != "number" || !Number.isFinite(t.updatedAt) ? null : Ui({
5609
+ return typeof t.id != "string" || !t.id || typeof t.name != "string" || typeof t.updatedAt != "number" || !Number.isFinite(t.updatedAt) ? null : aa({
5401
5610
  id: t.id,
5402
5611
  name: t.name,
5403
5612
  updatedAt: t.updatedAt,
@@ -5406,17 +5615,17 @@ function Gi(e) {
5406
5615
  kind: typeof t.kind == "string" ? t.kind : void 0
5407
5616
  });
5408
5617
  }
5409
- function Ki(e) {
5410
- let t = Gi(e), n = t ? e.content : void 0;
5618
+ function ca(e) {
5619
+ let t = sa(e), n = t ? e.content : void 0;
5411
5620
  return t && typeof n == "string" ? {
5412
5621
  ...t,
5413
5622
  content: n
5414
5623
  } : null;
5415
5624
  }
5416
- function qi(e = []) {
5625
+ function la(e = []) {
5417
5626
  let t = new Map(e.map((e) => [e.id, { ...e }]));
5418
5627
  return {
5419
- list: () => [...t.values()].map(Ui).sort(Wi),
5628
+ list: () => [...t.values()].map(aa).sort(oa),
5420
5629
  load: (e) => {
5421
5630
  let n = t.get(e);
5422
5631
  return n ? { ...n } : null;
@@ -5429,7 +5638,7 @@ function qi(e = []) {
5429
5638
  }
5430
5639
  };
5431
5640
  }
5432
- function Ji(e = "tcw:layouts:") {
5641
+ function ua(e = "tcw:layouts:") {
5433
5642
  let t = `${e}index`, n = (t) => `${e}item:${t}`, r = () => {
5434
5643
  let e;
5435
5644
  try {
@@ -5437,10 +5646,10 @@ function Ji(e = "tcw:layouts:") {
5437
5646
  } catch {
5438
5647
  return [];
5439
5648
  }
5440
- return Array.isArray(e) ? e.map(Gi).filter((e) => e !== null) : [];
5649
+ return Array.isArray(e) ? e.map(sa).filter((e) => e !== null) : [];
5441
5650
  }, i = (e) => localStorage.setItem(t, JSON.stringify(e));
5442
5651
  return {
5443
- list: () => r().sort(Wi),
5652
+ list: () => r().sort(oa),
5444
5653
  load: (e) => {
5445
5654
  let t = r().find((t) => t.id === e), i = t ? localStorage.getItem(n(e)) : null;
5446
5655
  return t && i !== null ? {
@@ -5449,7 +5658,7 @@ function Ji(e = "tcw:layouts:") {
5449
5658
  } : null;
5450
5659
  },
5451
5660
  save: (e) => {
5452
- localStorage.setItem(n(e.id), e.content), i([...r().filter((t) => t.id !== e.id), Ui(e)]);
5661
+ localStorage.setItem(n(e.id), e.content), i([...r().filter((t) => t.id !== e.id), aa(e)]);
5453
5662
  },
5454
5663
  remove: (e) => {
5455
5664
  i(r().filter((t) => t.id !== e)), localStorage.removeItem(n(e));
@@ -5458,14 +5667,14 @@ function Ji(e = "tcw:layouts:") {
5458
5667
  }
5459
5668
  //#endregion
5460
5669
  //#region src/state/LayoutSession.ts
5461
- var Yi = 80;
5462
- function Xi(e) {
5670
+ var da = 80;
5671
+ function fa(e) {
5463
5672
  return e.replace(/\s+/g, " ").trim().slice(0, 80).trim() || null;
5464
5673
  }
5465
- function Zi() {
5674
+ function pa() {
5466
5675
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
5467
5676
  }
5468
- function Qi(e) {
5677
+ function ma(e) {
5469
5678
  let { id: t, name: n, symbol: r, timeframe: i, updatedAt: a, kind: o } = e;
5470
5679
  return {
5471
5680
  id: t,
@@ -5476,7 +5685,7 @@ function Qi(e) {
5476
5685
  ...o === void 0 ? {} : { kind: o }
5477
5686
  };
5478
5687
  }
5479
- var $i = class {
5688
+ var ha = class {
5480
5689
  currentLayout = null;
5481
5690
  savedContent = null;
5482
5691
  dirty = !1;
@@ -5492,7 +5701,7 @@ var $i = class {
5492
5701
  now;
5493
5702
  newId;
5494
5703
  constructor(e, t, n = {}) {
5495
- 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 ?? Zi;
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;
5496
5705
  }
5497
5706
  current() {
5498
5707
  return this.currentLayout;
@@ -5508,7 +5717,7 @@ var $i = class {
5508
5717
  }
5509
5718
  async list() {
5510
5719
  let e = await this.storage.list();
5511
- return Array.isArray(e) ? e.map(Gi).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) : [];
5512
5721
  }
5513
5722
  save() {
5514
5723
  return this.queue(() => {
@@ -5517,12 +5726,12 @@ var $i = class {
5517
5726
  });
5518
5727
  }
5519
5728
  saveAs(e) {
5520
- let t = Xi(e);
5729
+ let t = fa(e);
5521
5730
  return t ? this.queue(() => this.write(this.newId(), t)) : Promise.reject(/* @__PURE__ */ Error("A layout needs a name"));
5522
5731
  }
5523
5732
  open(e) {
5524
5733
  return this.queue(async () => {
5525
- let t = Ki(await this.storage.load(e));
5734
+ let t = ca(await this.storage.load(e));
5526
5735
  if (!t || t.id !== e || (t.kind ?? "chart") !== this.kind || this.destroyed) return !1;
5527
5736
  this.cancelTimer(), this.applying++;
5528
5737
  try {
@@ -5532,13 +5741,13 @@ var $i = class {
5532
5741
  } finally {
5533
5742
  this.applying--;
5534
5743
  }
5535
- return this.cancelTimer(), this.currentLayout = Qi(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;
5536
5745
  });
5537
5746
  }
5538
5747
  rename(e, t) {
5539
- let n = Xi(t);
5748
+ let n = fa(t);
5540
5749
  return n ? this.queue(async () => {
5541
- let t = Ki(await this.storage.load(e));
5750
+ let t = ca(await this.storage.load(e));
5542
5751
  !t || t.id !== e || (await this.storage.save({
5543
5752
  ...t,
5544
5753
  name: n
@@ -5616,7 +5825,7 @@ var $i = class {
5616
5825
  content: n.content
5617
5826
  };
5618
5827
  await this.storage.save(r);
5619
- let i = Qi(r);
5828
+ let i = ma(r);
5620
5829
  return this.currentLayout = i, this.savedContent = n.content, this.dirty = !1, this.notify(), i;
5621
5830
  }
5622
5831
  forget() {
@@ -5637,6 +5846,6 @@ var $i = class {
5637
5846
  }
5638
5847
  };
5639
5848
  //#endregion
5640
- export { Hn as C, B as D, R as E, ln as O, Gn as S, V as T, lr as _, qi as a, G as b, Xr as c, Mr as d, Nr as f, cr as g, ur as h, Ji as i, Ir as l, dr as m, Yi as n, Vi as o, fr as p, Xi as r, ji as s, $i as t, Fr as u, or as v, Bn as w, Xn as x, sr 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 };
5641
5850
 
5642
- //# sourceMappingURL=LayoutSession-EEUFJm3J.js.map
5851
+ //# sourceMappingURL=LayoutSession-Bcy79w0l.js.map