@tradecanvas/chart 1.49.0 → 1.50.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.
@@ -294,19 +294,22 @@ function B(e) {
294
294
  volume: e.volume === void 0 ? 0 : Math.max(0, e.volume)
295
295
  };
296
296
  }
297
+ function sn(e, t) {
298
+ if (e.length === 0) return t;
299
+ let n = v(t);
300
+ return l(e) === 1 ? n : n / 1e3;
301
+ }
302
+ function cn(e, t) {
303
+ let n = sn(e, t.time);
304
+ return n === t.time ? t : {
305
+ ...t,
306
+ time: n
307
+ };
308
+ }
297
309
  var V = class {
298
310
  data = [];
299
- inSeriesUnit(e) {
300
- if (this.data.length === 0) return e;
301
- let t = v(e);
302
- return l(this.data) === 1 ? t : t / 1e3;
303
- }
304
311
  withSeriesTime(e) {
305
- let t = this.inSeriesUnit(e.time);
306
- return t === e.time ? e : {
307
- ...e,
308
- time: t
309
- };
312
+ return cn(this.data, e);
310
313
  }
311
314
  getData() {
312
315
  return this.data;
@@ -353,7 +356,199 @@ var V = class {
353
356
  clear() {
354
357
  this.data = [];
355
358
  }
356
- }, sn = 5e3, cn = 6e4, ln = 500, un = class {
359
+ };
360
+ //#endregion
361
+ //#region src/SeriesStore.ts
362
+ function H(e, t) {
363
+ let n = e[e.length - 1];
364
+ if (!n) return "append";
365
+ let r = v(t.time), i = v(n.time);
366
+ return r > i ? "append" : r === i ? "update" : "stale";
367
+ }
368
+ function ln(e) {
369
+ return [
370
+ e.time,
371
+ e.open,
372
+ e.high,
373
+ e.low,
374
+ e.close
375
+ ].every(Number.isFinite);
376
+ }
377
+ var un = class {
378
+ shown = new V();
379
+ whole = null;
380
+ aside = null;
381
+ constructor(e) {
382
+ this.hoursFilter = e;
383
+ }
384
+ bars() {
385
+ return this.shown.getData();
386
+ }
387
+ length() {
388
+ return this.shown.getLength();
389
+ }
390
+ liveBars() {
391
+ return this.aside?.getData() ?? this.whole ?? this.shown.getData();
392
+ }
393
+ load(e) {
394
+ this.shown.setData(this.regularOnly(e));
395
+ }
396
+ prepend(e) {
397
+ let t = null, n = e;
398
+ if (this.whole) {
399
+ 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);
400
+ this.whole = [...a, ...this.whole];
401
+ let o = this.hoursFilter(this.whole);
402
+ t = a.length, n = o ? a.filter((e) => o(e.time)) : a;
403
+ }
404
+ let r = this.shown.prependBars(n);
405
+ return {
406
+ added: r,
407
+ taken: t ?? r
408
+ };
409
+ }
410
+ mergeSnapshot(e) {
411
+ let t = this.whole ?? this.shown.getData(), n = e[0]?.time, r = 0;
412
+ for (; n !== void 0 && r < t.length && t[r].time < n;) r++;
413
+ return r === 0 || r === t.length ? !1 : (this.shown.setData(this.regularOnly(t.slice(0, r).concat(e))), !0);
414
+ }
415
+ refilter() {
416
+ if (this.aside) return !1;
417
+ let e = this.whole ?? this.shown.getData().slice();
418
+ return !this.whole && !this.hoursFilter(e) ? !1 : (this.shown.setData(this.regularOnly(e)), !0);
419
+ }
420
+ append(e) {
421
+ if (this.aside) return this.aside.appendBar(e), this.wrote("aside", !1);
422
+ let t = this.inSeriesUnit(e), n = this.startWholeSeries(t, "append");
423
+ if (!this.take(t, "append")) return this.wrote("hidden", n);
424
+ let r = this.shown.getLength();
425
+ return this.shown.appendBar(t), {
426
+ to: "shown",
427
+ before: r,
428
+ refiltered: n
429
+ };
430
+ }
431
+ appendMany(e) {
432
+ if (this.aside) {
433
+ for (let t of e) this.aside.appendBar(t);
434
+ return {
435
+ shown: 0,
436
+ before: this.shown.getLength(),
437
+ refiltered: !1,
438
+ aside: !0
439
+ };
440
+ }
441
+ let t = !1, n = [];
442
+ for (let r of e) {
443
+ let e = this.inSeriesUnit(r);
444
+ t = this.startWholeSeries(e, "append") || t, this.take(e, "append") && n.push(e);
445
+ }
446
+ let r = this.shown.getLength();
447
+ for (let e of n) this.shown.appendBar(e);
448
+ return {
449
+ shown: n.length,
450
+ before: r,
451
+ refiltered: t,
452
+ aside: !1
453
+ };
454
+ }
455
+ updateLast(e) {
456
+ if (this.aside) return this.aside.updateLastBar(e), this.wrote("aside", !1);
457
+ let t = this.inSeriesUnit(e), n = this.startWholeSeries(t, "update");
458
+ if (!this.take(t, "update")) return this.wrote("hidden", n);
459
+ let r = this.shown.getLength();
460
+ return this.shown.updateLastBar(t), {
461
+ to: "shown",
462
+ before: r,
463
+ refiltered: n
464
+ };
465
+ }
466
+ mergeTick(e) {
467
+ if (this.aside) return this.aside.updateLastBarFromTick(e), this.wrote("aside", !1);
468
+ let t = this.whole ? this.hoursFilter(this.whole) : null;
469
+ if (t && this.whole && !t(sn(this.whole, e.time))) return this.wrote("hidden", !1);
470
+ let n = this.shown.getLength();
471
+ this.shown.updateLastBarFromTick(e);
472
+ let r = this.whole, i = this.shown.getData()[this.shown.getLength() - 1];
473
+ return r && i && r.length > 0 && r[r.length - 1].time === i.time && (r[r.length - 1] = i), {
474
+ to: "shown",
475
+ before: n,
476
+ refiltered: !1
477
+ };
478
+ }
479
+ placeStreamBar(e) {
480
+ if (this.aside) {
481
+ let t = H(this.aside.getData(), e);
482
+ return t === "append" ? this.aside.appendBar(e) : t === "update" && this.aside.updateLastBar(e), this.wrote(t === "stale" ? "none" : "aside", !1);
483
+ }
484
+ let t = this.inSeriesUnit(e), n = H(this.whole ?? this.shown.getData(), t);
485
+ if (n === "stale") return this.wrote("none", !1);
486
+ let r = this.startWholeSeries(t, n);
487
+ if (!this.take(t, n)) return this.wrote("hidden", r);
488
+ let i = this.shown.getLength(), a = H(this.shown.getData(), t);
489
+ return a === "stale" ? {
490
+ to: "none",
491
+ before: i,
492
+ refiltered: r
493
+ } : (a === "append" ? this.shown.appendBar(t) : this.shown.updateLastBar(t), {
494
+ to: "shown",
495
+ before: i,
496
+ refiltered: r
497
+ });
498
+ }
499
+ loadAside(e) {
500
+ this.aside?.setData(e);
501
+ }
502
+ beginReplay() {
503
+ this.aside || (this.aside = new V(), this.aside.setData(this.whole ?? this.shown.getData()));
504
+ }
505
+ endReplay() {
506
+ let e = this.aside;
507
+ return this.aside = null, e ? e.getData() : null;
508
+ }
509
+ inHoursShown(e) {
510
+ let t = this.hoursFilter(e);
511
+ return t ? e.filter((e) => t(e.time)) : e.slice();
512
+ }
513
+ showReplayed(e) {
514
+ this.shown.setData(e);
515
+ }
516
+ appendReplayed(e) {
517
+ this.shown.appendBar(e);
518
+ }
519
+ updateReplayed(e) {
520
+ this.shown.updateLastBar(e);
521
+ }
522
+ inSeriesUnit(e) {
523
+ return cn(this.whole ?? this.shown.getData(), e);
524
+ }
525
+ wrote(e, t) {
526
+ return {
527
+ to: e,
528
+ before: this.shown.getLength(),
529
+ refiltered: t
530
+ };
531
+ }
532
+ regularOnly(e) {
533
+ let t = this.hoursFilter(e);
534
+ return this.whole = t ? e.slice() : null, t ? e.filter((e) => t(e.time)) : e;
535
+ }
536
+ startWholeSeries(e, t) {
537
+ if (this.whole) return !1;
538
+ let n = this.shown.getData(), r = n.slice(-12), i = t === "append" || r.length === 0 ? [...r, e] : [...r.slice(0, -1), e];
539
+ if (!this.hoursFilter(i)) return !1;
540
+ this.whole = n.slice();
541
+ let a = this.hoursFilter(this.whole.length > 1 ? this.whole : i);
542
+ return !a || !n.some((e) => !a(e.time)) ? !1 : (this.shown.setData(n.filter((e) => a(e.time))), !0);
543
+ }
544
+ take(e, t) {
545
+ let n = this.whole;
546
+ if (!n) return !0;
547
+ t === "append" || n.length === 0 ? n.push(e) : n[n.length - 1] = e;
548
+ let r = this.hoursFilter(n);
549
+ return !r || r(e.time);
550
+ }
551
+ }, dn = 5e3, fn = 6e4, pn = 500, mn = class {
357
552
  loader = null;
358
553
  pageSize = 500;
359
554
  loading = !1;
@@ -394,7 +589,7 @@ var V = class {
394
589
  try {
395
590
  r = await e(t, this.pageSize);
396
591
  } catch (e) {
397
- return n === this.seq ? (this.loading = !1, this.failures++, this.retryAt = this.now() + Math.min(cn, sn * 2 ** (this.failures - 1)), this.emit({
592
+ return n === this.seq ? (this.loading = !1, this.failures++, this.retryAt = this.now() + Math.min(fn, dn * 2 ** (this.failures - 1)), this.emit({
398
593
  state: "error",
399
594
  count: 0,
400
595
  error: e instanceof Error ? e.message : String(e)
@@ -424,15 +619,23 @@ var V = class {
424
619
  now() {
425
620
  return this.host.now ? this.host.now() : Date.now();
426
621
  }
427
- }, dn = class t {
622
+ };
623
+ //#endregion
624
+ //#region src/ThemeManager.ts
625
+ function hn(e, t) {
626
+ return e.family === t.family && e.sizeSmall === t.sizeSmall && e.sizeMedium === t.sizeMedium && e.sizeLarge === t.sizeLarge;
627
+ }
628
+ var gn = class t {
428
629
  base;
429
630
  shape = null;
631
+ font = null;
632
+ themeFont;
430
633
  chartType = "candlestick";
431
634
  host = {};
432
635
  user = /* @__PURE__ */ new Map();
433
636
  effective = null;
434
637
  constructor(e) {
435
- this.base = t.read(e);
638
+ this.base = t.read(e), this.themeFont = this.base.font;
436
639
  }
437
640
  static read(t) {
438
641
  if (!t || t === "dark") return { ...e };
@@ -447,14 +650,33 @@ var V = class {
447
650
  return this.base;
448
651
  }
449
652
  setTheme(e) {
450
- this.base = t.read(e), this.shape && (this.base = {
653
+ let n = t.read(e), r = this.font !== null && hn(n.font, this.base.font);
654
+ this.base = n, r || (this.themeFont = n.font), this.shape && (this.base = {
451
655
  ...this.base,
452
656
  shape: {
453
657
  ...this.base.shape,
454
658
  ...this.shape
455
659
  }
660
+ }), this.font && (this.base = {
661
+ ...this.base,
662
+ font: {
663
+ ...this.themeFont,
664
+ ...this.font
665
+ }
456
666
  }), this.effective = null;
457
667
  }
668
+ setFont(e) {
669
+ this.font = e ? {
670
+ ...this.font,
671
+ ...e
672
+ } : null, this.base = {
673
+ ...this.base,
674
+ font: this.font ? {
675
+ ...this.themeFont,
676
+ ...this.font
677
+ } : this.themeFont
678
+ }, this.effective = null;
679
+ }
458
680
  setShape(e) {
459
681
  this.shape = e ? { ...e } : null, this.base = {
460
682
  ...this.base,
@@ -510,7 +732,7 @@ var V = class {
510
732
  };
511
733
  //#endregion
512
734
  //#region src/style/styleOptions.ts
513
- function fn(e, t) {
735
+ function _n(e, t) {
514
736
  return t ? {
515
737
  ...t.visible === void 0 ? {} : { [`crosshair.${e}.visible`]: t.visible },
516
738
  ...t.color === void 0 ? {} : { [`crosshair.${e}.color`]: t.color },
@@ -518,22 +740,22 @@ function fn(e, t) {
518
740
  ...t.width === void 0 ? {} : { [`crosshair.${e}.width`]: t.width }
519
741
  } : {};
520
742
  }
521
- function pn(e) {
743
+ function vn(e) {
522
744
  let { grid: t, crosshair: n } = e, r = n?.vLine?.labelBackground ?? n?.hLine?.labelBackground;
523
745
  return {
524
746
  ...t?.hLineColor === void 0 ? {} : { "grid.horizontal.color": t.hLineColor },
525
747
  ...t?.hLineStyle === void 0 ? {} : { "grid.horizontal.style": t.hLineStyle },
526
748
  ...t?.vLineColor === void 0 ? {} : { "grid.vertical.color": t.vLineColor },
527
749
  ...t?.vLineStyle === void 0 ? {} : { "grid.vertical.style": t.vLineStyle },
528
- ...fn("horizontal", n?.hLine),
529
- ...fn("vertical", n?.vLine),
750
+ ..._n("horizontal", n?.hLine),
751
+ ..._n("vertical", n?.vLine),
530
752
  ...r === void 0 ? {} : { "crosshair.labelBackground": r },
531
753
  ...e.overrides
532
754
  };
533
755
  }
534
756
  //#endregion
535
757
  //#region src/layout/LayoutManager.ts
536
- var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom", gn = class {
758
+ var yn = 200, bn = 80, U = (e) => e.position === "top" || e.position === "bottom", xn = class {
537
759
  panels = [];
538
760
  containerWidth = 0;
539
761
  containerHeight = 0;
@@ -549,8 +771,8 @@ var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom
549
771
  this.panels.push({
550
772
  id: e,
551
773
  position: n,
552
- size: r ?? (a ? mn : t),
553
- minSize: a ? hn : i,
774
+ size: r ?? (a ? yn : t),
775
+ minSize: a ? bn : i,
554
776
  content: {
555
777
  type: "indicator",
556
778
  indicatorInstanceId: e
@@ -569,14 +791,14 @@ var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom
569
791
  }
570
792
  setPanelCollapsed(e, t) {
571
793
  let n = this.panels.find((t) => t.id === e);
572
- return !n || !H(n) || this.maximized === null && !!n.collapsed === t ? !1 : (this.maximized = null, n.collapsed = t || void 0, !0);
794
+ return !n || !U(n) || this.maximized === null && !!n.collapsed === t ? !1 : (this.maximized = null, n.collapsed = t || void 0, !0);
573
795
  }
574
796
  isPanelCollapsed(e) {
575
797
  return !!this.panels.find((t) => t.id === e)?.collapsed;
576
798
  }
577
799
  isPanelShownCollapsed(e) {
578
800
  let t = this.panels.find((t) => t.id === e);
579
- return !t || !H(t) ? !1 : this.maximized === null ? !!t.collapsed : this.maximized !== e;
801
+ return !t || !U(t) ? !1 : this.maximized === null ? !!t.collapsed : this.maximized !== e;
580
802
  }
581
803
  setPanelScale(e, t) {
582
804
  let n = this.panels.find((t) => t.id === e);
@@ -592,7 +814,7 @@ var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom
592
814
  }
593
815
  setMaximizedPanel(e) {
594
816
  let t = e === null ? null : this.panels.find((t) => t.id === e);
595
- return e !== null && (!t || !H(t)) || this.maximized === e ? !1 : (this.maximized = e, t && (t.collapsed = void 0), !0);
817
+ return e !== null && (!t || !U(t)) || this.maximized === e ? !1 : (this.maximized = e, t && (t.collapsed = void 0), !0);
596
818
  }
597
819
  getMaximizedPanel() {
598
820
  return this.maximized;
@@ -613,19 +835,19 @@ var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom
613
835
  this.panels = [...this.panels].sort((e, n) => t(e) - t(n));
614
836
  }
615
837
  shownSize(e, t) {
616
- return H(e) ? this.maximized ? e.id === this.maximized ? t : 20 : e.collapsed ? 20 : e.size : e.size;
838
+ return U(e) ? this.maximized ? e.id === this.maximized ? t : 20 : e.collapsed ? 20 : e.size : e.size;
617
839
  }
618
840
  setPanelPosition(e, n) {
619
841
  let r = this.panels.find((t) => t.id === e);
620
842
  if (r) {
621
843
  let a = r.position === "left" || r.position === "right", o = n === "left" || n === "right";
622
- r.position = n, a !== o && (r.size = o ? mn : t, r.minSize = o ? hn : i), o && (r.collapsed = void 0, this.maximized === e && (this.maximized = null));
844
+ r.position = n, a !== o && (r.size = o ? yn : t, r.minSize = o ? bn : i), o && (r.collapsed = void 0, this.maximized === e && (this.maximized = null));
623
845
  }
624
846
  }
625
847
  setPanelSize(e, t) {
626
848
  let n = this.panels.find((t) => t.id === e);
627
849
  if (n) {
628
- let e = H(n) ? this.containerHeight - s - 48 : this.containerWidth / 2, r = e > n.minSize ? Math.min(t, e) : t;
850
+ let e = U(n) ? this.containerHeight - s - 48 : this.containerWidth / 2, r = e > n.minSize ? Math.min(t, e) : t;
629
851
  n.size = Math.max(n.minSize, r), n.collapsed = void 0, this.maximized = null;
630
852
  }
631
853
  }
@@ -735,8 +957,8 @@ var mn = 200, hn = 80, H = (e) => e.position === "top" || e.position === "bottom
735
957
  getMainChartRect() {
736
958
  return this.resolve().mainChartRect;
737
959
  }
738
- }, _n = 14, vn = 14, yn = 22, bn = 4;
739
- function xn(e) {
960
+ }, Sn = 14, Cn = 14, wn = 22, Tn = 4;
961
+ function En(e) {
740
962
  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] : [
741
963
  t,
742
964
  n,
@@ -745,14 +967,14 @@ function xn(e) {
745
967
  for (let t of f) {
746
968
  if (!Number.isFinite(t)) continue;
747
969
  let n = e.scaleLabel ? e.scaleLabel(t) : e.format ? e.format(t) : p(t, u, i), r = e.format ? n : p(t, d, i);
748
- m = Math.max(m, l(n, `500 ${s}px ${a}`) + _n, l(r, `bold 11px ${a}`) + vn, l(r, `600 ${s}px ${a}`) + yn);
970
+ m = Math.max(m, l(n, `500 ${s}px ${a}`) + Sn, l(r, `bold 11px ${a}`) + Cn, l(r, `600 ${s}px ${a}`) + wn);
749
971
  }
750
- return m <= o ? o : Math.ceil(m / bn) * bn;
972
+ return m <= o ? o : Math.ceil(m / Tn) * Tn;
751
973
  }
752
- function Sn(e, t) {
974
+ function Dn(e, t) {
753
975
  return t > e || t <= e - 12 ? t : e;
754
976
  }
755
- var Cn = class {
977
+ var On = class {
756
978
  netY = 0;
757
979
  travelX = 0;
758
980
  engaged = !1;
@@ -768,11 +990,11 @@ var Cn = class {
768
990
  }
769
991
  return this.engaged;
770
992
  }
771
- }, wn = 1;
772
- function Tn(e, t) {
993
+ }, kn = 1;
994
+ function An(e, t) {
773
995
  return e.filter((e) => e.enabled !== !1 && (e.descriptor.layer ?? "overlay") === t);
774
996
  }
775
- function U(e) {
997
+ function W(e) {
776
998
  switch (e.kind) {
777
999
  case "indicator": return `indicator:${e.plugin.descriptor.id}`;
778
1000
  case "drawing": return `drawing:${e.plugin.descriptor.type}`;
@@ -782,25 +1004,25 @@ function U(e) {
782
1004
  }
783
1005
  //#endregion
784
1006
  //#region src/plugins/registry.ts
785
- var W = /* @__PURE__ */ new Map();
786
- function En(e) {
787
- W.set(U(e), e);
1007
+ var G = /* @__PURE__ */ new Map();
1008
+ function jn(e) {
1009
+ G.set(W(e), e);
788
1010
  }
789
- function Dn(e) {
790
- return W.delete(e);
1011
+ function Mn(e) {
1012
+ return G.delete(e);
791
1013
  }
792
- function On() {
793
- return [...W.values()];
1014
+ function Nn() {
1015
+ return [...G.values()];
794
1016
  }
795
- function kn() {
796
- W.clear();
1017
+ function Pn() {
1018
+ G.clear();
797
1019
  }
798
1020
  //#endregion
799
1021
  //#region src/plugins/PluginManager.ts
800
- var An = class {
1022
+ var Fn = class {
801
1023
  plugins = /* @__PURE__ */ new Map();
802
1024
  constructor(e, t = {}) {
803
- if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of On()) this.add(e);
1025
+ if (this.indicatorEngine = e, t.inheritGlobal !== !1) for (let e of Nn()) this.add(e);
804
1026
  for (let e of t.plugins ?? []) this.add(e);
805
1027
  }
806
1028
  register(e) {
@@ -828,17 +1050,17 @@ var An = class {
828
1050
  return e;
829
1051
  }
830
1052
  add(e) {
831
- this.plugins.set(U(e), e), e.kind === "indicator" && this.indicatorEngine.register(e.plugin);
1053
+ this.plugins.set(W(e), e), e.kind === "indicator" && this.indicatorEngine.register(e.plugin);
832
1054
  }
833
- }, jn = {
1055
+ }, In = {
834
1056
  orderPlace: (e, t) => e.placeOrder(t),
835
1057
  orderModify: (e, t) => e.modifyOrder(t),
836
1058
  orderCancel: (e, t) => e.cancelOrder(t),
837
1059
  positionModify: (e, t) => e.modifyPosition(t),
838
1060
  positionClose: (e, t) => e.closePosition(t),
839
- positionReverse: (e, t, n) => Mn(e, t, n)
1061
+ positionReverse: (e, t, n) => Ln(e, t, n)
840
1062
  };
841
- async function Mn(e, t, n) {
1063
+ async function Ln(e, t, n) {
842
1064
  let { reversing: r } = n;
843
1065
  if (!r.has(t.positionId)) {
844
1066
  r.add(t.positionId);
@@ -867,7 +1089,7 @@ async function Mn(e, t, n) {
867
1089
  }
868
1090
  }
869
1091
  }
870
- function Nn(e, t) {
1092
+ function Rn(e, t) {
871
1093
  let n = [], r = null, i = {
872
1094
  positions: () => r ?? t.getPositions?.() ?? [],
873
1095
  reversing: /* @__PURE__ */ new Set()
@@ -877,8 +1099,8 @@ function Nn(e, t) {
877
1099
  e.data && t.onFill?.(e.data);
878
1100
  };
879
1101
  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));
880
- for (let r of Object.keys(jn)) {
881
- let a = jn[r], o = t.onIntent(r, (n) => {
1102
+ for (let r of Object.keys(In)) {
1103
+ let a = In[r], o = t.onIntent(r, (n) => {
882
1104
  Promise.resolve(a(e, n, i)).catch((e) => t.onError({
883
1105
  message: `Execution command failed: ${r}`,
884
1106
  cause: e
@@ -892,15 +1114,15 @@ function Nn(e, t) {
892
1114
  }
893
1115
  //#endregion
894
1116
  //#region src/Chart.ts
895
- var Pn = {
1117
+ var zn = {
896
1118
  min: 0,
897
1119
  max: 100
898
- }, Fn = "exchange", In = Fn;
899
- function Ln(e) {
1120
+ }, Bn = "exchange", Vn = Bn;
1121
+ function Hn(e) {
900
1122
  if (typeof e == "string" && e !== "exchange" && !g(e)) throw RangeError(`Unknown time zone: ${e}`);
901
1123
  if (typeof e == "number" && !Number.isFinite(e)) throw RangeError(`Invalid UTC offset: ${e}`);
902
1124
  }
903
- function Rn(e, t) {
1125
+ function Un(e, t) {
904
1126
  let { timeZone: n, timezone: r } = e, i = n !== void 0 && r !== void 0 && n !== r && n === t ? r : w(e);
905
1127
  return i === void 0 ? e : {
906
1128
  ...e,
@@ -908,11 +1130,11 @@ function Rn(e, t) {
908
1130
  timezone: i
909
1131
  };
910
1132
  }
911
- var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontalLine", "crossLine"]), Gn = new Set(["verticalLine", "crossLine"]), Kn = class {
912
- static version = "1.49.0";
1133
+ var Wn = .08, Gn = a ** -7, Kn = 800, qn = 20, Jn = 8, Yn = new Set(["horizontalLine", "crossLine"]), Xn = new Set(["verticalLine", "crossLine"]), Zn = class {
1134
+ static version = "1.50.0";
913
1135
  engine;
914
1136
  viewport;
915
- dataManager;
1137
+ series = new un((e) => this.sessionKeep(e));
916
1138
  themeManager;
917
1139
  layoutManager;
918
1140
  pluginManager;
@@ -1001,7 +1223,6 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1001
1223
  symbolSeries = new at();
1002
1224
  extendedHours = !0;
1003
1225
  replayRestarting = !1;
1004
- fullSeries = null;
1005
1226
  requestedSymbols = /* @__PURE__ */ new Set();
1006
1227
  gridRenderer;
1007
1228
  priceAxis;
@@ -1036,7 +1257,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1036
1257
  snapshotKey = null;
1037
1258
  historyCheckQueued = !1;
1038
1259
  constructor(e, t) {
1039
- t.timeZone != null && Ln(t.timeZone), this.container = e, this.options = {
1260
+ t.timeZone != null && Hn(t.timeZone), this.container = e, this.options = {
1040
1261
  ...t,
1041
1262
  chartType: t.chartType ?? "candlestick"
1042
1263
  }, this.numberLocale = t.numberLocale ?? "en-US", this.defaultAutoScale = t.autoScale !== !1;
@@ -1074,11 +1295,11 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1074
1295
  logScale: n.logScale ?? !0,
1075
1296
  timeframes: n.timeframes ?? [],
1076
1297
  defaultTimeframeFavorites: n.defaultTimeframeFavorites ?? []
1077
- }, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", e.style.userSelect = "none", e.style.webkitUserSelect = "none", this.dataManager = new V(), this.history = new un({
1078
- oldestTime: () => this.dataManager.getData()[0]?.time ?? null,
1298
+ }, 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 mn({
1299
+ oldestTime: () => this.series.bars()[0]?.time ?? null,
1079
1300
  prepend: (e) => this.prependBars(e),
1080
1301
  emit: (e) => this.eventBus.emit("historyLoad", e)
1081
- }), this.themeManager = new dn(t.theme), this.themeManager.setChartType(this.options.chartType ?? "candlestick"), this.applyStyle(pn(t), "host", !1), this.layoutManager = new gn(), this.indicatorEngine = new O(), this.pluginManager = new An(this.indicatorEngine, { plugins: t.plugins }), this.eventBus = new je(), Dt(this.indicatorEngine), this.indicatorEngine.register(new be(this.symbolSeries)), this.indicatorEngine.register(new nt(this.symbolSeries)), this.indicatorEngine.register(new xe(this.symbolSeries)), this.indicatorEngine.register(new Se(this.symbolSeries)), this.drawingManager = new Oe(), Et(this.drawingManager), this.drawingRenderer = new ke(this.drawingManager), this.drawingManager.setRequestRender(() => {
1302
+ }), this.themeManager = new gn(t.theme), this.themeManager.setChartType(this.options.chartType ?? "candlestick"), this.applyStyle(vn(t), "host", !1), this.layoutManager = new xn(), this.indicatorEngine = new O(), this.pluginManager = new Fn(this.indicatorEngine, { plugins: t.plugins }), this.eventBus = new je(), Dt(this.indicatorEngine), this.indicatorEngine.register(new be(this.symbolSeries)), this.indicatorEngine.register(new nt(this.symbolSeries)), this.indicatorEngine.register(new xe(this.symbolSeries)), this.indicatorEngine.register(new Se(this.symbolSeries)), this.drawingManager = new Oe(), Et(this.drawingManager), this.drawingRenderer = new ke(this.drawingManager), this.drawingManager.setRequestRender(() => {
1082
1303
  this.syncRenderContext(), this.engine.requestRender(r.Overlay), this.scheduleAutoSave();
1083
1304
  }), this.drawingManager.setEventCallback((e, t) => {
1084
1305
  this.followDrawingAlerts(e, t?.id), this.eventBus.emit(e, t), (e === "drawingCreate" || e === "drawingUpdate" || e === "drawingRemove") && this.announceStateChange();
@@ -1095,14 +1316,14 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1095
1316
  primary: e[0] ?? null
1096
1317
  })), this.drawingManager.setForeignHistory((e, t) => {
1097
1318
  e.type === "custom" ? e.custom?.[t]() : this.applyIndicatorStep(e, t);
1098
- }), this.drawingManager.setDataGetter(() => this.dataManager.getData()), this.drawingManager.setDisplayDataGetter(() => this.getDisplayData()), t.crosshair?.mode === "magnet" && this.features.drawingMagnet && this.drawingManager.setMagnetMode("magnet"), this.tradingManager = new ct({
1319
+ }), this.drawingManager.setDataGetter(() => this.series.bars()), this.drawingManager.setDisplayDataGetter(() => this.getDisplayData()), t.crosshair?.mode === "magnet" && this.features.drawingMagnet && this.drawingManager.setMagnetMode("magnet"), this.tradingManager = new ct({
1099
1320
  enabled: this.features.trading,
1100
1321
  contextMenu: { enabled: this.features.tradingContextMenu }
1101
1322
  }), this.tradingRenderer = new lt(this.tradingManager), this.tradingManager.setContainer(e), this.tradingManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradingManager.setEventCallback((e, t) => {
1102
1323
  this.eventBus.emit(e, t);
1103
1324
  }), this.engine = new Ye(e, t.maxPixelRatio);
1104
1325
  let a = this.engine.dprManager.getContainerSize();
1105
- if (this.viewport = new dt(a.width, a.height, t.minBarSpacing ?? 2, t.maxBarSpacing ?? 30, t.rightMargin ?? 5), this.viewport.setPanLimits({
1326
+ if (this.viewport = new dt(a.width, a.height, t.minBarSpacing ?? 2, t.maxBarSpacing ?? 30, t.rightMargin ?? 5), t.barLayout && this.viewport.setBarLayout(t.barLayout), this.viewport.setPanLimits({
1106
1327
  freePan: t.freePan ?? !0,
1107
1328
  minVisibleBars: t.panLimits?.minVisibleBars ?? 3
1108
1329
  }), t.minBarUnit !== void 0 && this.viewport.setMinBarUnit(t.minBarUnit), this.layoutManager.resize(a.width, a.height), this.engine.onContainerResize = (e) => {
@@ -1131,7 +1352,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1131
1352
  color: t.sessionBreaks.color,
1132
1353
  lineStyle: t.sessionBreaks.lineStyle,
1133
1354
  lineWidth: t.sessionBreaks.lineWidth
1134
- }) : t.features?.sessionBreaks !== !1 && this.sessionBreaks.setVisible(!0), t.logScale && this.features.logScale && this.viewport.setLogScale(!0), this.animator = new de(), this.crosshairTooltip = new we(), this.crosshairTooltip.create(e), this.crosshairTooltip.setLocale(this.numberLocale), this.pinnedTooltip = new Ge(), this.pinnedTooltip.create(e), t.priceFormat && this.applyPriceFormat(t.priceFormat), t.chartTypeOptions && (this.chartTypeOptions = b(t.chartTypeOptions)), t.highLowLines && this.priceLines.setHighLow(!0), t.shapes && this.themeManager.setShape(Yn(t.shapes)), this.priceLines.setPriceText((e) => this.formatPrice(e)), t.extendedHours === !1 && (this.extendedHours = !1), t.timeFormatter && this.applyTimeFormatter(t.timeFormatter), this.keyboardHandler = new Le({
1355
+ }) : t.features?.sessionBreaks !== !1 && this.sessionBreaks.setVisible(!0), t.logScale && this.features.logScale && this.viewport.setLogScale(!0), this.animator = new de(), this.crosshairTooltip = new we(), this.crosshairTooltip.create(e), this.crosshairTooltip.setLocale(this.numberLocale), this.pinnedTooltip = new Ge(), this.pinnedTooltip.create(e), t.priceFormat && this.applyPriceFormat(t.priceFormat), t.chartTypeOptions && (this.chartTypeOptions = b(t.chartTypeOptions)), t.highLowLines && this.priceLines.setHighLow(!0), t.shapes && this.themeManager.setShape(nr(t.shapes)), t.font && this.themeManager.setFont(tr(t.font)), this.priceLines.setPriceText((e) => this.formatPrice(e)), t.extendedHours === !1 && (this.extendedHours = !1), t.timeFormatter && this.applyTimeFormatter(t.timeFormatter), this.keyboardHandler = new Le({
1135
1356
  scrollBars: (e) => {
1136
1357
  let t = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
1137
1358
  this.viewport.scrollBy(e * t), this.updateViewportAndRender();
@@ -1179,7 +1400,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1179
1400
  this.keyboardHandler.handleKey(e) && (e.preventDefault(), this.a11y?.viewMoved());
1180
1401
  }
1181
1402
  }, window.addEventListener("keydown", this.onWindowKeyDown), this.currentPriceLine = new Te(), this.currentPriceLine.setLocale(this.numberLocale), this.priceAxis.setReservedPriceProvider(() => this.currentPriceLine.isVisible() ? this.currentPriceLine.getPrice() : null), this.alertManager = new ue(), this.alertManager.setDrawingLevels((e) => this.drawingLevelsNow(e)), this.alertManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.alertManager.on("triggered", (e) => {
1182
- this.eventBus.emit("alertTriggered", G(e)), this.eventBus.emit("dataUpdate", {
1403
+ this.eventBus.emit("alertTriggered", K(e)), this.eventBus.emit("dataUpdate", {
1183
1404
  kind: "alert",
1184
1405
  alert: "triggered",
1185
1406
  alertId: e.id,
@@ -1187,14 +1408,14 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1187
1408
  message: e.message
1188
1409
  });
1189
1410
  }), this.alertManager.on("added", (e) => {
1190
- this.eventBus.emit("alertAdd", G(e));
1411
+ this.eventBus.emit("alertAdd", K(e));
1191
1412
  }), this.alertManager.on("removed", (e) => {
1192
1413
  this.eventBus.emit("alertRemove", { id: e });
1193
1414
  }), this.alertManager.on("expired", (e) => {
1194
- this.eventBus.emit("alertExpired", G(e));
1415
+ this.eventBus.emit("alertExpired", K(e));
1195
1416
  }), this.alertManager.on("updated", (e) => {
1196
- this.eventBus.emit("alertUpdate", G(e));
1197
- }), this.signalMarkerManager = new tt(), this.signalMarkerManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.signalMarkerManager.setDataGetter(() => this.dataManager.getData()), this.signalMarkerManager.on("added", (e) => {
1417
+ this.eventBus.emit("alertUpdate", K(e));
1418
+ }), this.signalMarkerManager = new tt(), this.signalMarkerManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.signalMarkerManager.setDataGetter(() => this.series.bars()), this.signalMarkerManager.on("added", (e) => {
1198
1419
  this.eventBus.emit("signalMarkerAdd", {
1199
1420
  id: e.id,
1200
1421
  source: e.source,
@@ -1202,7 +1423,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1202
1423
  });
1203
1424
  }), this.signalMarkerManager.on("removed", (e) => {
1204
1425
  this.eventBus.emit("signalMarkerRemove", { id: e });
1205
- }), this.tradeZoneManager = new st(), this.tradeZoneManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradeZoneManager.setDataGetter(() => this.dataManager.getData()), this.tradeZoneManager.on("added", (e) => {
1426
+ }), this.tradeZoneManager = new st(), this.tradeZoneManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradeZoneManager.setDataGetter(() => this.series.bars()), this.tradeZoneManager.on("added", (e) => {
1206
1427
  this.eventBus.emit("tradeZoneAdd", {
1207
1428
  id: e.id,
1208
1429
  direction: e.direction
@@ -1218,7 +1439,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1218
1439
  }), this.replayManager.on("stateChange", (e) => {
1219
1440
  this.replayRestarting || this.eventBus.emit("replayState", { state: e });
1220
1441
  }), this.measureOverlay = new Ve(), this.interactionManager = new Fe(e), this.features.panning) {
1221
- let e = new Cn();
1442
+ let e = new On();
1222
1443
  this.interactionManager.setPanHandler(new He((t, n) => {
1223
1444
  t && this.viewport.scrollBy(t), e.step(t, n, this.options.autoScale !== !1) && n && (this.options.autoScale = !1, this.viewport.panPriceRange(n)), this.updateViewportAndRender();
1224
1445
  }, () => e.reset()));
@@ -1272,7 +1493,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1272
1493
  let t = this.getDisplayData();
1273
1494
  if (t.length === 0) return;
1274
1495
  let n = this.viewport.getState(), i = n.barWidth + n.barSpacing, a = Math.round((n.offset + e.x) / i);
1275
- a < 0 || a >= t.length || (this.pinnedTooltip.isPinned() && this.pinnedTooltip.getPinnedIndex() === a ? this.pinnedTooltip.unpin() : this.pinnedTooltip.pin(t[a], a, this.themeManager.getTheme(), l(t)), this.pinnedTooltip.reposition(this.viewport.getState(), this.dataManager.getData()[a] ?? null, a, this.themeManager.getTheme()), this.engine.requestRender(r.Overlay));
1496
+ a < 0 || a >= t.length || (this.pinnedTooltip.isPinned() && this.pinnedTooltip.getPinnedIndex() === a ? this.pinnedTooltip.unpin() : this.pinnedTooltip.pin(t[a], a, this.themeManager.getTheme(), l(t)), this.pinnedTooltip.reposition(this.viewport.getState(), this.series.bars()[a] ?? null, a, this.themeManager.getTheme()), this.engine.requestRender(r.Overlay));
1276
1497
  }), this.interactionManager.setSignalMarkerHitTest((e) => this.eventBus.hasListeners("signalMarkerHover") || this.eventBus.hasListeners("signalMarkerClick") ? this.signalMarkerManager.markerAt(e, this.viewport.getState()) : null, (e, t) => this.eventBus.emit("signalMarkerHover", {
1277
1498
  marker: e,
1278
1499
  x: t.x,
@@ -1334,7 +1555,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1334
1555
  end: () => {
1335
1556
  let e = this.selectionBoxOverlay.end();
1336
1557
  if (e && this.zoomAreaMode) {
1337
- if (e.x1 - e.x0 < Un) return;
1558
+ if (e.x1 - e.x0 < Jn) return;
1338
1559
  this.zoomToBox(e), this.setZoomAreaMode(!1);
1339
1560
  return;
1340
1561
  }
@@ -1365,39 +1586,29 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1365
1586
  this.loadSeries(e, !1);
1366
1587
  }
1367
1588
  loadSeries(e, t) {
1368
- this.snapshotKey = null, this.endReplaySession(), this.history.reset(), this.dataManager.setData(this.regularOnly(e)), this.crosshairHandler.setData(this.dataManager.getData()), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.options.autoScale = this.defaultAutoScale;
1369
- let n = this.dataManager.getData(), r = n[n.length - 1];
1589
+ this.snapshotKey = null, this.endReplaySession(), this.history.reset(), this.series.load(e), this.crosshairHandler.setData(this.series.bars()), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.options.autoScale = this.defaultAutoScale;
1590
+ let n = this.series.bars(), r = n[n.length - 1];
1370
1591
  t || (this.alertManager.clearLastValues(), r && this.alertManager.seedLastValue("price", r.close)), this.recalcIndicators(n), r && this.currentPriceLine.setPrice(r.close), this.updateViewportAndRender(!0), this.emitBars(n.length);
1371
1592
  }
1372
1593
  prependBars(e) {
1373
1594
  if (this.replaySession) return 0;
1374
- let t = null;
1375
- if (this.fullSeries) {
1376
- let n = this.fullSeries[0]?.time, r = /* @__PURE__ */ new Set(), i = e.filter((e) => ir(e) && (n === void 0 || e.time < n) && !r.has(e.time) && r.add(e.time)).sort((e, t) => e.time - t.time);
1377
- this.fullSeries = [...i, ...this.fullSeries];
1378
- let a = this.sessionKeep(this.fullSeries);
1379
- t = i.length, e = a ? i.filter((e) => a(e.time)) : i;
1380
- }
1381
- let n = this.getDisplayData(), r = Math.max(0, Math.min(n.length - 1, Math.floor(this.viewport.getState().visibleRange.from))), i = n[r]?.time, a = this.dataManager.prependBars(e);
1382
- if (a === 0) return t ?? 0;
1383
- let o = this.dataManager.getData();
1384
- if (this.crosshairHandler.setData(o), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.pinnedTooltip.isPinned() && this.pinnedTooltip.unpin(), this.measureOverlay.end(), this.recalcIndicators(o), i !== void 0) {
1385
- let e = Math.round(F(i, this.getDisplayData()));
1386
- this.viewport.prependBars(e - r);
1595
+ 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);
1596
+ if (i === 0) return a;
1597
+ let o = this.series.bars();
1598
+ if (this.crosshairHandler.setData(o), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.pinnedTooltip.isPinned() && this.pinnedTooltip.unpin(), this.measureOverlay.end(), this.recalcIndicators(o), r !== void 0) {
1599
+ let e = Math.round(F(r, this.getDisplayData()));
1600
+ this.viewport.prependBars(e - n);
1387
1601
  }
1388
- return this.updateViewportAndRender(), t ?? a;
1602
+ return this.updateViewportAndRender(), a;
1389
1603
  }
1390
1604
  mergeSnapshot(e) {
1391
- let t = this.fullSeries ?? this.dataManager.getData(), n = e[0]?.time, r = 0;
1392
- for (; n !== void 0 && r < t.length && t[r].time < n;) r++;
1393
- if (r === 0 || r === t.length) {
1605
+ let t = this.viewport.isAtEnd();
1606
+ if (!this.series.mergeSnapshot(e)) {
1394
1607
  this.setData(e);
1395
1608
  return;
1396
1609
  }
1397
- let i = this.viewport.isAtEnd();
1398
- this.dataManager.setData(this.regularOnly(t.slice(0, r).concat(e)));
1399
- let a = this.dataManager.getData();
1400
- this.crosshairHandler.setData(a), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.recalcIndicators(a), a.length > 0 && this.currentPriceLine.setPrice(a[a.length - 1].close), this.updateViewportAndRender(i), this.emitBars(a.length);
1610
+ let n = this.series.bars();
1611
+ this.crosshairHandler.setData(n), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.recalcIndicators(n), n.length > 0 && this.currentPriceLine.setPrice(n[n.length - 1].close), this.updateViewportAndRender(t), this.emitBars(n.length);
1401
1612
  }
1402
1613
  setHistoryLoader(e, t) {
1403
1614
  this.historyFromStream = !1, this.hostHistoryLoader = e !== null, this.history.setLoader(e, t?.pageSize), this.checkHistory();
@@ -1417,7 +1628,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1417
1628
  let { visibleRange: e, chartRect: t } = this.viewport.getState();
1418
1629
  if (t.width <= 0) return;
1419
1630
  let { from: n, to: r } = e;
1420
- this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(Hn, r - n));
1631
+ this.history.maybeLoad(Math.max(0, Math.floor(n)), Math.max(qn, r - n));
1421
1632
  }));
1422
1633
  }
1423
1634
  useStreamHistory(e, t) {
@@ -1432,68 +1643,47 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1432
1643
  }
1433
1644
  appendBar(e) {
1434
1645
  if (!z(e)) return;
1435
- if (this.replaySession) {
1436
- this.replaySession.live.appendBar(e), this.takeLivePrice(e.close);
1437
- return;
1438
- }
1439
- if (!this.takeBar(e, "append")) {
1440
- this.takeLivePrice(e.close), this.scheduleRender();
1646
+ let t = this.series.append(e);
1647
+ if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
1648
+ this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
1441
1649
  return;
1442
1650
  }
1443
- let t = this.autoScrollOnNewBar && this.viewport.isAtEnd(), n = this.dataManager.getLength();
1444
- this.dataManager.appendBar(e);
1445
- let r = this.dataManager.getData();
1446
- this.crosshairHandler.setData(r), this.displayDataCache = null, this.recalcIndicatorsFrom(r, r.length - 2), this.currentPriceLine.setPrice(e.close), this.updateViewportAndRender(t), r.length !== n && this.emitBars(r.length), this.followLivePrice(e.close);
1651
+ let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
1652
+ this.crosshairHandler.setData(i), this.displayDataCache = null, this.recalcIndicatorsFrom(i, i.length - 2), this.currentPriceLine.setPrice(e.close), this.updateViewportAndRender(n), i.length !== r && this.emitBars(i.length), this.followLivePrice(e.close);
1447
1653
  }
1448
1654
  appendBars(e) {
1449
1655
  if (e = e.filter(z), e.length === 0) return;
1450
- let t = e[e.length - 1].close;
1451
- if (this.replaySession) {
1452
- for (let t of e) this.replaySession.live.appendBar(t);
1453
- this.takeLivePrice(t);
1656
+ let t = e[e.length - 1].close, n = this.series.appendMany(e);
1657
+ if (n.refiltered && (this.displayDataCache = null), n.shown === 0) {
1658
+ this.takeLivePrice(t), n.aside || this.scheduleRender();
1454
1659
  return;
1455
1660
  }
1456
- let n = e.filter((e) => this.takeBar(e, "append"));
1457
- if (n.length === 0) {
1458
- this.takeLivePrice(t), this.scheduleRender();
1459
- return;
1460
- }
1461
- let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = this.dataManager.getLength();
1462
- for (let e of n) this.dataManager.appendBar(e);
1661
+ let r = this.autoScrollOnNewBar && this.viewport.isAtEnd(), i = n.before;
1463
1662
  this.displayDataCache = null;
1464
- let a = this.dataManager.getData();
1663
+ let a = this.series.bars();
1465
1664
  this.recalcIndicatorsFrom(a, i - 1), this.crosshairHandler.setData(a), this.currentPriceLine.setPrice(t), this.updateViewportAndRender(r), a.length !== i && this.emitBars(a.length), this.followLivePrice(t);
1466
1665
  }
1467
1666
  updateLastBar(e) {
1468
1667
  if (!z(e)) return;
1469
- if (this.replaySession) {
1470
- this.replaySession.live.updateLastBar(e), this.takeLivePrice(e.close);
1471
- return;
1472
- }
1473
- if (!this.takeBar(e, "update")) {
1474
- this.takeLivePrice(e.close), this.scheduleRender();
1668
+ let t = this.series.updateLast(e);
1669
+ if (t.refiltered && (this.displayDataCache = null), t.to !== "shown") {
1670
+ this.takeLivePrice(e.close), t.to === "hidden" && this.scheduleRender();
1475
1671
  return;
1476
1672
  }
1477
- this.dataManager.updateLastBar(e), 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);
1478
- let t = this.dataManager.getData();
1479
- this.recalcIndicatorsFrom(t, t.length - 1), this.followLivePrice(e.close), this.scheduleRender();
1673
+ 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);
1674
+ let n = this.series.bars();
1675
+ this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.close), this.scheduleRender();
1480
1676
  }
1481
1677
  updateLastBarFromTick(e) {
1482
1678
  if (!Number.isFinite(e.price) || e.price < 0 || e.volume !== void 0 && !(Number.isFinite(e.volume) && e.volume >= 0)) return;
1483
- if (this.replaySession) {
1484
- this.replaySession.live.updateLastBarFromTick(e), this.takeLivePrice(e.price);
1485
- return;
1486
- }
1487
- let t = this.fullSeries ? this.sessionKeep(this.fullSeries) : null;
1488
- if (t && !t(e.time)) {
1489
- this.takeLivePrice(e.price), this.scheduleRender();
1679
+ let t = this.series.mergeTick(e);
1680
+ if (t.to !== "shown") {
1681
+ this.takeLivePrice(e.price), t.to === "hidden" && this.scheduleRender();
1490
1682
  return;
1491
1683
  }
1492
- this.dataManager.updateLastBarFromTick(e), this.currentPriceLine.setPrice(e.price);
1493
- let n = this.fullSeries, r = this.dataManager.getData()[this.dataManager.getLength() - 1];
1494
- n && r && n.length > 0 && n[n.length - 1].time === r.time && (n[n.length - 1] = r), this.options.chartType !== "candlestick" && this.options.chartType !== "line" && this.options.chartType !== "area" && this.options.chartType !== "bar" && this.options.chartType !== "hollowCandle" && (this.displayDataCache = null);
1495
- let i = this.dataManager.getData();
1496
- this.recalcIndicatorsFrom(i, i.length - 1), this.followLivePrice(e.price), this.scheduleRender();
1684
+ 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);
1685
+ let n = this.series.bars();
1686
+ this.recalcIndicatorsFrom(n, n.length - 1), this.followLivePrice(e.price), this.scheduleRender();
1497
1687
  }
1498
1688
  getChartType() {
1499
1689
  return this.options.chartType ?? "candlestick";
@@ -1527,46 +1717,16 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1527
1717
  sessionKeep(e) {
1528
1718
  return this.extendedHours ? null : Ht(this.symbolInfo, e);
1529
1719
  }
1530
- shownBars(e) {
1531
- let t = this.sessionKeep(e);
1532
- return t ? e.filter((e) => t(e.time)) : e.slice();
1533
- }
1534
- regularOnly(e) {
1535
- let t = this.sessionKeep(e);
1536
- return this.fullSeries = t ? e.slice() : null, t ? e.filter((e) => t(e.time)) : e;
1537
- }
1538
- placeStreamBar(e) {
1539
- let t = K(this.dataManager.getData(), e);
1540
- return t === "stale" ? !1 : (t === "append" ? this.dataManager.appendBar(e) : this.dataManager.updateLastBar(e), !0);
1541
- }
1542
- takeBar(e, t) {
1543
- if (!this.fullSeries && !this.extendedHours && !this.replaySession) {
1544
- let n = this.dataManager.getData(), r = n.slice(-12), i = t === "append" || r.length === 0 ? [...r, e] : [...r.slice(0, -1), e];
1545
- if (this.sessionKeep(i)) {
1546
- this.fullSeries = n.slice();
1547
- let e = this.sessionKeep(this.fullSeries.length > 1 ? this.fullSeries : i);
1548
- e && n.some((t) => !e(t.time)) && (this.dataManager.setData(n.filter((t) => e(t.time))), this.displayDataCache = null);
1549
- }
1550
- }
1551
- let n = this.fullSeries;
1552
- if (!n) return !0;
1553
- t === "append" || n.length === 0 ? n.push(e) : n[n.length - 1] = e;
1554
- let r = this.sessionKeep(n);
1555
- return !r || r(e.time);
1556
- }
1557
1720
  reapplyExtendedHours() {
1558
- if (this.replaySession) return;
1559
- let e = this.fullSeries ?? this.dataManager.getData().slice();
1560
- if (!this.fullSeries && !this.sessionKeep(e)) return;
1561
- this.dataManager.setData(this.regularOnly(e));
1562
- let t = this.dataManager.getData();
1563
- this.crosshairHandler.setData(t), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.recalcIndicators(t), this.updateViewportAndRender(!0), this.emitBars(t.length);
1721
+ if (!this.series.refilter()) return;
1722
+ let e = this.series.bars();
1723
+ this.crosshairHandler.setData(e), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.recalcIndicators(e), this.updateViewportAndRender(!0), this.emitBars(e.length);
1564
1724
  }
1565
1725
  quoteLines() {
1566
1726
  return this.priceLines.setQuoteShown(this.replaySession === null), this.priceLines;
1567
1727
  }
1568
1728
  setShapes(e) {
1569
- let t = Yn(e);
1729
+ let t = nr(e);
1570
1730
  t.tagRadius !== void 0 && (this.themeManager.setShape({
1571
1731
  ...this.themeManager.getTheme().shape,
1572
1732
  ...t
@@ -1575,6 +1735,24 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1575
1735
  getShapes() {
1576
1736
  return { ...this.themeManager.getTheme().shape };
1577
1737
  }
1738
+ setFont(e) {
1739
+ if (e === null) this.themeManager.setFont(null);
1740
+ else {
1741
+ let t = tr(e);
1742
+ if (Object.keys(t).length === 0) return;
1743
+ this.themeManager.setFont(t);
1744
+ }
1745
+ this.updateViewportAndRender();
1746
+ }
1747
+ getFont() {
1748
+ return { ...this.themeManager.getTheme().font };
1749
+ }
1750
+ setBarLayout(e) {
1751
+ e !== "golden" && e !== "classic" || e === this.viewport.getBarLayout() || (this.viewport.setBarLayout(e), this.updateViewportAndRender());
1752
+ }
1753
+ getBarLayout() {
1754
+ return this.viewport.getBarLayout();
1755
+ }
1578
1756
  setMainSeriesVisible(e) {
1579
1757
  this.mainSeriesVisible = e, this.syncRenderContext(), this.engine.requestRender();
1580
1758
  }
@@ -1598,7 +1776,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1598
1776
  }
1599
1777
  addIndicatorNow(e, t, n, r) {
1600
1778
  if (!this.isIndicatorAllowed(e)) return null;
1601
- 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.dataManager.getData(), {
1779
+ 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.series.bars(), {
1602
1780
  ...a ? { pane: a } : {},
1603
1781
  ...r.scale === "left" ? { scale: "left" } : {},
1604
1782
  ...r.instanceId ? { instanceId: r.instanceId } : {}
@@ -1610,7 +1788,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1610
1788
  }
1611
1789
  setSymbolSeries(e, t) {
1612
1790
  e = e.trim(), this.symbolSeries.set(e, t), this.requestedSymbols.delete(e);
1613
- let n = this.dataManager.getData(), r = !1;
1791
+ let n = this.series.bars(), r = !1;
1614
1792
  for (let t of this.indicatorEngine.getActiveIndicators()) !M.has(t.id) || String(t.params.symbol ?? "").trim() !== e.trim() || (this.indicatorEngine.updateIndicator(t.instanceId, {}, n), r = !0);
1615
1793
  r && (this.announceIndicatorUpdate(0), this.updateViewportAndRender());
1616
1794
  }
@@ -1639,7 +1817,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1639
1817
  }
1640
1818
  updateIndicatorNow(e, t) {
1641
1819
  let n = this.indicatorEngine.getIndicatorDescriptor(e), r = n ? P(n) : null, i = r ? this.indicatorEngine.getIndicatorConfig(e)?.params[r] : void 0;
1642
- this.indicatorEngine.updateIndicator(e, t, this.dataManager.getData()), this.announceIndicatorUpdate(0), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
1820
+ this.indicatorEngine.updateIndicator(e, t, this.series.bars()), this.announceIndicatorUpdate(0), this.markStateChanged(), this.eventBus.emit("indicatorChange", {
1643
1821
  instanceId: e,
1644
1822
  change: "params"
1645
1823
  }), this.requestMissingSymbols(e);
@@ -1699,8 +1877,8 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1699
1877
  return {
1700
1878
  ...e,
1701
1879
  priceRange: {
1702
- min: t.min - n * zn,
1703
- max: t.max + n * zn
1880
+ min: t.min - n * Wn,
1881
+ max: t.max + n * Wn
1704
1882
  },
1705
1883
  logScale: !1,
1706
1884
  scaleMode: "regular",
@@ -1910,7 +2088,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1910
2088
  return this.features.legend ? e + this.chartLegend.getHeight() : e;
1911
2089
  }
1912
2090
  isTimeAligned() {
1913
- return R(this.options.chartType) ? !1 : this.getDisplayData().length === this.dataManager.getLength();
2091
+ return R(this.options.chartType) ? !1 : this.getDisplayData().length === this.series.length();
1914
2092
  }
1915
2093
  roundPrice(e) {
1916
2094
  if (!Number.isFinite(e)) return e;
@@ -1920,7 +2098,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
1920
2098
  return Number(e.toFixed(this.marketPricePrecision ?? c(n, r)));
1921
2099
  }
1922
2100
  lastClose() {
1923
- let e = this.dataManager.getData();
2101
+ let e = this.series.bars();
1924
2102
  return e[e.length - 1]?.close ?? 0;
1925
2103
  }
1926
2104
  stepAt(e) {
@@ -2077,7 +2255,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2077
2255
  recordUndo(e) {
2078
2256
  if (!this.features.drawingUndoRedo || typeof e?.undo != "function" || typeof e.redo != "function") return;
2079
2257
  let t = performance.now(), n = this.undoRedoManager.last();
2080
- if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < Vn) {
2258
+ if (e.subject !== void 0 && n?.type === "custom" && n.custom?.subject === e.subject && t - n.custom.at < Kn) {
2081
2259
  this.undoRedoManager.replaceLast({
2082
2260
  ...n,
2083
2261
  custom: {
@@ -2181,7 +2359,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2181
2359
  });
2182
2360
  }
2183
2361
  getExportData(e = {}) {
2184
- let t = this.dataManager.getData(), n = 0, r = t.length - 1;
2362
+ let t = this.series.bars(), n = 0, r = t.length - 1;
2185
2363
  if (e.range === "visible") {
2186
2364
  let { visibleRange: e } = this.viewport.getState();
2187
2365
  n = Math.max(0, e.from), r = Math.min(t.length - 1, e.to);
@@ -2299,7 +2477,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2299
2477
  }
2300
2478
  startBracket(e, t) {
2301
2479
  if (!this.features.trading) return !1;
2302
- let n = this.dataManager.getData(), r = t ?? (n.length > 0 ? n[n.length - 1].close : null);
2480
+ let n = this.series.bars(), r = t ?? (n.length > 0 ? n[n.length - 1].close : null);
2303
2481
  return r === null ? !1 : (this.tradingManager.startBracket(e, r), !0);
2304
2482
  }
2305
2483
  cancelBracket() {
@@ -2313,7 +2491,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2313
2491
  }
2314
2492
  startOrderDraft(e, t) {
2315
2493
  if (!this.features.trading) return !1;
2316
- let n = this.dataManager.getData(), r = t ?? (n.length > 0 ? n[n.length - 1].close : null);
2494
+ let n = this.series.bars(), r = t ?? (n.length > 0 ? n[n.length - 1].close : null);
2317
2495
  return r === null ? !1 : (this.tradingManager.startOrderDraft(e, r), !0);
2318
2496
  }
2319
2497
  cancelOrderDraft() {
@@ -2383,13 +2561,13 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2383
2561
  this.replayTrades() || this.tradingManager.setCurrentPrice(e), this.features.alerts && this.checkAlerts(e);
2384
2562
  }
2385
2563
  checkAlerts(e) {
2386
- let t = this.replaySession ? this.replaySession.live.getData() : this.dataManager.getData();
2564
+ let t = this.replaySession ? this.series.liveBars() : this.series.bars();
2387
2565
  this.alertManager.setBarTime(t.length > 0 ? t[t.length - 1].time : null);
2388
2566
  let n = new Map([["price", e]]);
2389
2567
  this.replaySession || this.collectIndicatorValues(n), this.alertManager.checkChannels(n, { together: !0 }), this.alertManager.checkDrawings(e);
2390
2568
  }
2391
2569
  collectIndicatorValues(e) {
2392
- let t = this.dataManager.getData();
2570
+ let t = this.series.bars();
2393
2571
  if (t.length === 0) return;
2394
2572
  let n = t.length - 1, r = this.alertManager.getAlerts().flatMap((e) => e.target ? [e.channel, e.target] : [e.channel]);
2395
2573
  for (let t of r) {
@@ -2407,32 +2585,24 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2407
2585
  if (!Ot(e.adapter, e.timeframe)) throw RangeError(`${e.adapter.name} cannot serve the ${e.timeframe} timeframe`);
2408
2586
  this.snapshotKey = null, this.replayStop(), this.disconnectStream(), this.streamManager = new it(), this.streamManager.on("snapshot", (t) => {
2409
2587
  let n = `${this.currentSymbol}|${this.streamTimeframe}`;
2410
- this.replaySession ? this.replaySession.live.setData(t) : n === this.snapshotKey && this.dataManager.getLength() > 0 ? this.mergeSnapshot(t) : this.setData(t), this.snapshotKey = n, this.useStreamHistory(e.adapter, e.historyPageSize);
2588
+ this.replaySession ? this.series.loadAside(t) : n === this.snapshotKey && this.series.length() > 0 ? this.mergeSnapshot(t) : this.setData(t), this.snapshotKey = n, this.useStreamHistory(e.adapter, e.historyPageSize);
2411
2589
  }), this.streamManager.on("barClose", (e) => {
2412
2590
  if (!z(e)) return;
2413
- if (this.replaySession) {
2414
- this.replaySession.live.appendBar(e), this.followLivePrice(e.close);
2415
- return;
2416
- }
2417
- let t = K(this.fullSeries ?? this.dataManager.getData(), e);
2418
- if (t === "stale" || !this.takeBar(e, t)) return;
2419
- let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = this.dataManager.getLength();
2420
- if (!this.placeStreamBar(e)) return;
2421
- let i = this.dataManager.getData();
2591
+ let t = this.series.placeStreamBar(e);
2592
+ if (t.refiltered && (this.displayDataCache = null), t.to === "aside" && this.followLivePrice(e.close), t.to !== "shown") return;
2593
+ let n = this.autoScrollOnNewBar && this.viewport.isAtEnd(), r = t.before, i = this.series.bars();
2422
2594
  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);
2423
2595
  }), this.streamManager.on("barUpdate", (e) => {
2424
2596
  if (!z(e)) return;
2425
- if (this.replaySession) {
2426
- this.replaySession.live.updateLastBar(e);
2427
- return;
2428
- }
2429
- this.currentPriceLine.setPrice(e.close);
2430
- let t = K(this.fullSeries ?? this.dataManager.getData(), e), n = this.dataManager.getLength();
2431
- if (t === "stale" || !this.takeBar(e, t) || !this.placeStreamBar(e)) {
2597
+ this.replaySession || this.currentPriceLine.setPrice(e.close);
2598
+ let t = this.series.placeStreamBar(e);
2599
+ if (t.refiltered && (this.displayDataCache = null), this.replaySession) return;
2600
+ let n = t.before;
2601
+ if (t.to !== "shown") {
2432
2602
  this.scheduleRender();
2433
2603
  return;
2434
2604
  }
2435
- let r = this.dataManager.getData();
2605
+ let r = this.series.bars();
2436
2606
  this.indicatorEngine.deferRecalculateFrom(r, r.length - 1), this.announceIndicatorUpdate(r.length - 1), r.length !== n && this.emitBars(r.length), this.scheduleRender();
2437
2607
  }), this.setBidAsk(null), this.streamManager.on("quote", (e) => {
2438
2608
  let t = this.priceLines.getBidAsk();
@@ -2509,7 +2679,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2509
2679
  }
2510
2680
  connectExecution(e, t = {}) {
2511
2681
  if (!this.features.trading) throw Error("connectExecution requires features.trading to be enabled");
2512
- this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = Nn(e, {
2682
+ this.disconnectExecution(), this.executionAdapter = e, this.execTeardown = Rn(e, {
2513
2683
  onIntent: (e, t) => {
2514
2684
  let n = (e) => t(e.payload);
2515
2685
  return this.eventBus.on(e, n), () => this.eventBus.off(e, n);
@@ -2590,7 +2760,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2590
2760
  this.autoScrollOnNewBar = e;
2591
2761
  }
2592
2762
  scrollTo(e) {
2593
- let t = this.dataManager.getData();
2763
+ let t = this.series.bars();
2594
2764
  for (let n = 0; n < t.length; n++) if (t[n].time >= e) {
2595
2765
  let e = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
2596
2766
  this.viewport.scrollBy(n * e - this.viewport.getState().offset), this.updateViewportAndRender();
@@ -2795,7 +2965,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2795
2965
  n !== this.crosshairHandler.getSyncedSlot() && (this.crosshairHandler.setSyncedSlot(n), this.engine.requestRender(r.Hover));
2796
2966
  }
2797
2967
  getData() {
2798
- return this.dataManager.getData();
2968
+ return this.series.bars();
2799
2969
  }
2800
2970
  setGridVisible(e) {
2801
2971
  this.gridRenderer.setVisible(e), this.engine.requestRender(r.Background);
@@ -2837,7 +3007,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2837
3007
  e.opacity !== void 0 && this.depthHeatmap.setOpacity(e.opacity), e.capacity !== void 0 && this.depthHeatmap.setCapacity(e.capacity), this.engine.requestRender(r.Main);
2838
3008
  }
2839
3009
  pushDepthSnapshot(e, t) {
2840
- let n = this.dataManager.getData(), i = t ?? n[n.length - 1]?.time;
3010
+ let n = this.series.bars(), i = t ?? n[n.length - 1]?.time;
2841
3011
  i === void 0 || !Number.isFinite(i) || (this.depthHeatmap.push(i, e), this.depthHeatmap.isVisible() && this.engine.requestRender(r.Main));
2842
3012
  }
2843
3013
  clearDepthHeatmap() {
@@ -2853,7 +3023,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2853
3023
  this.periodLevels.setPeriod(e), this.engine.requestRender(r.Main);
2854
3024
  }
2855
3025
  setTimeZone(e) {
2856
- Ln(e), this.timeZoneSetting = e, this.applyTimeZone();
3026
+ Hn(e), this.timeZoneSetting = e, this.applyTimeZone();
2857
3027
  }
2858
3028
  getTimeZone() {
2859
3029
  return this.timeZoneSetting;
@@ -2885,7 +3055,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2885
3055
  }
2886
3056
  setSymbolInfo(e) {
2887
3057
  let t = e && this.symbolInfo?.symbol === e.symbol ? w(this.symbolInfo) : void 0;
2888
- this.symbolInfo = e ? Rn({
3058
+ this.symbolInfo = e ? Un({
2889
3059
  ...e,
2890
3060
  sessions: e.sessions?.map((e) => ({ ...e }))
2891
3061
  }, 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);
@@ -2910,7 +3080,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
2910
3080
  if (!e || typeof e != "object") return;
2911
3081
  let t = this.currentSymbol, n = (e) => !e || e.toUpperCase() === t.toUpperCase();
2912
3082
  if (!n(e.symbol)) return;
2913
- let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = Rn({
3083
+ let r = this.symbolInfo && n(this.symbolInfo.symbol) ? this.symbolInfo : null, i = Un({
2914
3084
  ...r,
2915
3085
  ...e,
2916
3086
  symbol: e.symbol || r?.symbol || t
@@ -3048,7 +3218,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3048
3218
  return this.features.alerts && this.drawingLevelsNow(e) !== null;
3049
3219
  }
3050
3220
  drawingLevelsNow(e) {
3051
- let t = this.replaySession ? this.replaySession.live.getData() : this.getDisplayData();
3221
+ let t = this.replaySession ? this.series.liveBars() : this.getDisplayData();
3052
3222
  if (t.length === 0) return null;
3053
3223
  let n = {
3054
3224
  ...this.viewport.getState(),
@@ -3132,41 +3302,39 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3132
3302
  this.history.reset();
3133
3303
  let t = this.replaySession ? this.replayOffset : 0;
3134
3304
  if (!this.replaySession) {
3135
- if (this.dataManager.getLength() === 0) return;
3136
- let e = new V();
3137
- e.setData(this.fullSeries ?? this.dataManager.getData()), this.replaySession = {
3138
- live: e,
3305
+ if (this.series.length() === 0) return;
3306
+ this.series.beginReplay(), this.replaySession = {
3139
3307
  price: null,
3140
3308
  fedTime: null
3141
3309
  };
3142
3310
  }
3143
- let { steps: n, startTime: r, hideHistory: i, revealMarks: a, ...o } = e ?? {}, s = this.shownBars(this.replaySession.live.getData()), c = t > 0 && r === void 0 && i !== !1, l = o.startIndex;
3144
- r !== void 0 && l === void 0 ? l = $n(s, r) : c && l !== void 0 && (l += t);
3311
+ let { steps: n, startTime: r, hideHistory: i, revealMarks: a, ...o } = e ?? {}, s = this.series.inHoursShown(this.series.liveBars()), c = t > 0 && r === void 0 && i !== !1, l = o.startIndex;
3312
+ r !== void 0 && l === void 0 ? l = or(s, r) : c && l !== void 0 && (l += t);
3145
3313
  let u = c ? t : i && l !== void 0 && l > 0 ? Math.min(Math.floor(l), s.length - 1) : 0, d = u > 0 ? s.slice(u) : s;
3146
3314
  l !== void 0 && (o.startIndex = l - u), this.replayOffset = u, this.replayRevealMarks = a !== !1;
3147
- let f = n ? rr(n, d) : null;
3315
+ let f = n ? ur(n, d) : null;
3148
3316
  this.replayStepsSeries = f, this.replayCoarse = d, this.options.autoScale = !0, this.replayRestarting = !0;
3149
3317
  try {
3150
3318
  this.replayManager.load(f ?? d);
3151
3319
  } finally {
3152
3320
  this.replayRestarting = !1;
3153
3321
  }
3154
- f && o.startIndex !== void 0 && (o.startIndex = or(f, d, o.startIndex)), this.replayBarUnsub?.();
3322
+ f && o.startIndex !== void 0 && (o.startIndex = fr(f, d, o.startIndex)), this.replayBarUnsub?.();
3155
3323
  let p = -1, m = -1, h = null, g = f ?? d;
3156
3324
  this.replayBarUnsub = this.replayManager.on("bar", ({ index: e }) => {
3157
3325
  let t = e, n = d[e];
3158
3326
  if (f) {
3159
3327
  let r = f[e];
3160
- t = ar(d, r.time), h = h !== null && m === e - 1 && t === p - 1 && h ? cr(h, r) : sr(d[t], f, e), n = h;
3328
+ t = dr(d, r.time), h = h !== null && m === e - 1 && t === p - 1 && h ? mr(h, r) : pr(d[t], f, e), n = h;
3161
3329
  }
3162
3330
  m = e;
3163
- let r = t + 1, i = p > 0 && r >= p && this.dataManager.getLength() === p, a = !(i && !this.replaySeeking) || this.autoScrollOnNewBar && this.viewport.isAtEnd();
3331
+ let r = t + 1, i = p > 0 && r >= p && this.series.length() === p, a = !(i && !this.replaySeeking) || this.autoScrollOnNewBar && this.viewport.isAtEnd();
3164
3332
  if (i) {
3165
- f && r > p && this.dataManager.updateLastBar(d[p - 1]);
3166
- for (let e = p; e < r - 1; e++) this.dataManager.appendBar(d[e]);
3167
- r > p ? this.dataManager.appendBar(n) : this.dataManager.updateLastBar(n), this.recalcIndicatorsFrom(this.dataManager.getData(), Math.max(0, p - 1));
3168
- } else this.dataManager.setData([...d.slice(0, t), n]), this.recalcIndicators(this.dataManager.getData());
3169
- p = r, this.currentPriceLine.setPrice(n.close, t > 0 ? d[t - 1].close : void 0), this.crosshairHandler.setData(this.dataManager.getData());
3333
+ f && r > p && this.series.updateReplayed(d[p - 1]);
3334
+ for (let e = p; e < r - 1; e++) this.series.appendReplayed(d[e]);
3335
+ r > p ? this.series.appendReplayed(n) : this.series.updateReplayed(n), this.recalcIndicatorsFrom(this.series.bars(), Math.max(0, p - 1));
3336
+ } else this.series.showReplayed([...d.slice(0, t), n]), this.recalcIndicators(this.series.bars());
3337
+ p = r, this.currentPriceLine.setPrice(n.close, t > 0 ? d[t - 1].close : void 0), this.crosshairHandler.setData(this.series.bars());
3170
3338
  let o = g[e + 1]?.time ?? g[e].time + (e > 0 ? g[e].time - g[e - 1].time : 1);
3171
3339
  this.replayRevealMarks && this.revealReplayMarks(o), this.displayDataCache = null, this.updateViewportAndRender(a), this.feedReplaySteps(g, e), this.eventBus.emit("replayStep", {
3172
3340
  barIndex: t,
@@ -3198,7 +3366,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3198
3366
  returnMarkToLive() {
3199
3367
  let e = this.replaySession;
3200
3368
  if (!e || !this.replayTrades()) return;
3201
- let t = e.live.getData(), n = e.price?.price ?? t[t.length - 1]?.close;
3369
+ let t = this.series.liveBars(), n = e.price?.price ?? t[t.length - 1]?.close;
3202
3370
  n !== void 0 && this.feedReplayPrice(n);
3203
3371
  }
3204
3372
  feedReplaySteps(e, t) {
@@ -3209,20 +3377,20 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3209
3377
  return;
3210
3378
  }
3211
3379
  if (i.time <= n.fedTime) return;
3212
- let a = e.slice(er(e, n.fedTime), t + 1);
3380
+ let a = e.slice(sr(e, n.fedTime), t + 1);
3213
3381
  n.fedTime = i.time;
3214
- let o = Math.ceil(a.length / Qn);
3215
- for (let e = 0; e < a.length; e += o) for (let [t, n] of tr(a.slice(e, e + o))) r.setMarkPrice(t, n);
3382
+ let o = Math.ceil(a.length / ar);
3383
+ for (let e = 0; e < a.length; e += o) for (let [t, n] of cr(a.slice(e, e + o))) r.setMarkPrice(t, n);
3216
3384
  this.tradingManager.setCurrentPrice(i.close);
3217
3385
  }
3218
3386
  getReplayBarIndex() {
3219
3387
  if (!this.replaySession) return -1;
3220
3388
  let { current: e } = this.replayManager.getProgress(), t = this.replayStepsSeries;
3221
- return t && this.replayCoarse ? ar(this.replayCoarse, t[e]?.time ?? -Infinity) : e;
3389
+ return t && this.replayCoarse ? dr(this.replayCoarse, t[e]?.time ?? -Infinity) : e;
3222
3390
  }
3223
3391
  replaySeekToBar(e) {
3224
3392
  let t = this.replayStepsSeries;
3225
- this.replaySeek(t && this.replayCoarse ? or(t, this.replayCoarse, e) : e);
3393
+ this.replaySeek(t && this.replayCoarse ? fr(t, this.replayCoarse, e) : e);
3226
3394
  }
3227
3395
  replayPause() {
3228
3396
  this.replayManager.pause();
@@ -3231,8 +3399,8 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3231
3399
  this.replayManager.resume();
3232
3400
  }
3233
3401
  replayStop() {
3234
- let e = this.replaySession;
3235
- this.endReplaySession(), e && (this.loadSeries(e.live.getData(), !0), e.price && this.currentPriceLine.setPrice(e.price.price, e.price.previousClose));
3402
+ let e = this.replaySession, t = this.endReplaySession();
3403
+ !e || !t || (this.loadSeries(t, !0), e.price && this.currentPriceLine.setPrice(e.price.price, e.price.previousClose));
3236
3404
  }
3237
3405
  isReplayActive() {
3238
3406
  return this.replaySession !== null;
@@ -3257,7 +3425,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3257
3425
  let t = kt(e.time, n), r = Ct(e.price, n);
3258
3426
  i = Math.min(i, t), a = Math.max(a, t), o = Math.min(o, r), s = Math.max(s, r);
3259
3427
  }
3260
- return Wn.has(t.type) ? [i, a] = [r.x, r.x + r.width] : t.type === "horizontalRay" && (a = r.x + r.width), Gn.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 ? {
3428
+ return Yn.has(t.type) ? [i, a] = [r.x, r.x + r.width] : t.type === "horizontalRay" && (a = r.x + r.width), Xn.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 ? {
3261
3429
  x: i,
3262
3430
  y: o,
3263
3431
  width: a - i,
@@ -3265,7 +3433,10 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3265
3433
  } : null;
3266
3434
  }
3267
3435
  endReplaySession() {
3268
- this.replaySession && (this.returnMarkToLive(), this.replaySession = null, this.replayStepsSeries = null, this.replayCoarse = null, this.replayBarUnsub?.(), this.replayBarUnsub = null, this.replayManager.stop(), this.replayOffset = 0, this.revealReplayMarks(null));
3436
+ if (!this.replaySession) return null;
3437
+ this.returnMarkToLive();
3438
+ let e = this.series.endReplay();
3439
+ return this.replaySession = null, this.replayStepsSeries = null, this.replayCoarse = null, this.replayBarUnsub?.(), this.replayBarUnsub = null, this.replayManager.stop(), this.replayOffset = 0, this.revealReplayMarks(null), e;
3269
3440
  }
3270
3441
  replaySeek(e) {
3271
3442
  this.replaySeeking = !0;
@@ -3298,14 +3469,14 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3298
3469
  });
3299
3470
  }
3300
3471
  restoreIndicators(e, t) {
3301
- let n = qn(e), r = /* @__PURE__ */ new Map();
3472
+ let n = Qn(e), r = /* @__PURE__ */ new Map();
3302
3473
  this.unrestoredIndicators = [];
3303
3474
  let i = new Set(this.indicatorEngine.getAvailableIndicators().map((e) => e.id)), a = [], o = /* @__PURE__ */ new Set();
3304
3475
  if (t) {
3305
3476
  let e = new Map(n.map((e) => [e.instanceId, e])), t = this.getIndicatorSetup();
3306
3477
  for (let n of t) {
3307
3478
  let t = e.get(n.instanceId);
3308
- t && Jn(n, t) && o.add(n.instanceId);
3479
+ t && $n(n, t) && o.add(n.instanceId);
3309
3480
  }
3310
3481
  for (let e of t) o.has(e.instanceId) || this.removeIndicator(e.instanceId);
3311
3482
  for (let e of [...o]) this.indicatorEngine.getIndicatorConfig(e) || o.delete(e);
@@ -3472,7 +3643,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3472
3643
  if (this.indicatorHistoryDepth > 0 || !this.features.drawingUndoRedo) return t();
3473
3644
  let n = this.getIndicatorSetup(), r = this.withoutIndicatorHistory(t), i = this.getIndicatorSetup();
3474
3645
  if (JSON.stringify(n) === JSON.stringify(i)) return r;
3475
- let a = performance.now(), o = this.undoRedoManager.last(), s = e !== void 0 && o?.type === "indicators" && o.indicators?.subject === e && a - (o.indicators.at ?? 0) < Vn && JSON.stringify(o.indicators.after) === JSON.stringify(n), c = {
3646
+ let a = performance.now(), o = this.undoRedoManager.last(), s = e !== void 0 && o?.type === "indicators" && o.indicators?.subject === e && a - (o.indicators.at ?? 0) < Kn && JSON.stringify(o.indicators.after) === JSON.stringify(n), c = {
3476
3647
  type: "indicators",
3477
3648
  before: null,
3478
3649
  after: null
@@ -3611,11 +3782,11 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3611
3782
  return t instanceof D && t.setPriceText((e) => this.formatPrice(e)), t;
3612
3783
  }
3613
3784
  crosshairSeries() {
3614
- return this.isTimeAligned() ? this.dataManager.getData() : this.getDisplayData();
3785
+ return this.isTimeAligned() ? this.series.bars() : this.getDisplayData();
3615
3786
  }
3616
3787
  getDisplayData() {
3617
3788
  if (this.displayDataCache) return this.displayDataCache;
3618
- let e = this.dataManager.getData();
3789
+ let e = this.series.bars();
3619
3790
  if (e.length === 0) return e;
3620
3791
  let t = rn(this.options.chartType, e, (e) => this.pluginManager.getChartType(e), this.chartTypeOptions);
3621
3792
  return this.chartRenderer instanceof A && !this.pluginManager.getChartType(this.options.chartType) && this.chartRenderer.setBoxSize(en(e, this.chartTypeOptions)), this.displayDataCache = t, t;
@@ -3671,7 +3842,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3671
3842
  }
3672
3843
  fitPriceScale(e, t) {
3673
3844
  if (e.length === 0) return;
3674
- let n = Math.max(0, t.visibleRange.from), r = Math.min(t.visibleRange.to, e.length - 1), i = Zn(Zn(f(e, n, r, 0), this.indicatorEngine.getOverlayPriceRange(n, r)), this.features.compareSymbols ? this.compareRenderer.getPriceRange(e, t) : null), a = this.features.volume && this.volumeRenderer.isVisible() && Xn(e, n, r) ? this.volumeRenderer.getHeightRatio() + Bn : k;
3845
+ let n = Math.max(0, t.visibleRange.from), r = Math.min(t.visibleRange.to, e.length - 1), i = ir(ir(f(e, n, r, 0), this.indicatorEngine.getOverlayPriceRange(n, r)), this.features.compareSymbols ? this.compareRenderer.getPriceRange(e, t) : null), a = this.features.volume && this.volumeRenderer.isVisible() && rr(e, n, r) ? this.volumeRenderer.getHeightRatio() + Gn : k;
3675
3846
  this.viewport.setScaleMargins(this.viewport.isInvertScale() ? {
3676
3847
  top: a,
3677
3848
  bottom: k
@@ -3693,7 +3864,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3693
3864
  fitLeftAxisWidth() {
3694
3865
  let e = this.leftViewport;
3695
3866
  if (!e) return !1;
3696
- let t = this.themeManager.getTheme(), n = xn({
3867
+ let t = this.themeManager.getTheme(), n = En({
3697
3868
  min: e.priceRange.min,
3698
3869
  max: e.priceRange.max,
3699
3870
  lastPrice: null,
@@ -3702,12 +3873,12 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3702
3873
  fontFamily: t.font.family,
3703
3874
  fontSizeSmall: t.font.sizeSmall,
3704
3875
  measure: (e, t) => this.measureText(e, t)
3705
- }), r = Sn(this.leftAxisWidth, n);
3876
+ }), r = Dn(this.leftAxisWidth, n);
3706
3877
  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);
3707
3878
  }
3708
3879
  fitPriceAxisWidth() {
3709
3880
  if (!this.features.priceAxis) return !1;
3710
- let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = xn({
3881
+ let { priceRange: e } = this.viewport.getState(), t = this.themeManager.getTheme(), n = En({
3711
3882
  min: e.min,
3712
3883
  max: e.max,
3713
3884
  lastPrice: this.currentPriceLine.getPrice(),
@@ -3718,7 +3889,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3718
3889
  fontFamily: t.font.family,
3719
3890
  fontSizeSmall: t.font.sizeSmall,
3720
3891
  measure: (e, t) => this.measureText(e, t)
3721
- }), r = Sn(this.priceAxisWidth, n);
3892
+ }), r = Dn(this.priceAxisWidth, n);
3722
3893
  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);
3723
3894
  }
3724
3895
  measureText(e, t) {
@@ -3762,7 +3933,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3762
3933
  buildPanelRenderInfos() {
3763
3934
  if (this.panelInfoCache) return this.panelInfoCache;
3764
3935
  let e = this.getResolvedLayout(), t = this.viewport.getState(), { from: n, to: r } = t.visibleRange, i = e.panels.map((e) => {
3765
- 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) ?? { ...Pn }, o = {
3936
+ 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) ?? { ...zn }, o = {
3766
3937
  x: e.rect.x,
3767
3938
  y: e.rect.y + 20,
3768
3939
  width: e.rect.width,
@@ -3844,7 +4015,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3844
4015
  });
3845
4016
  }
3846
4017
  drawOverlayPlugins(e, t) {
3847
- let n = Tn(this.pluginManager.getOverlays(), t);
4018
+ let n = An(this.pluginManager.getOverlays(), t);
3848
4019
  if (n.length === 0) return;
3849
4020
  let r = {
3850
4021
  viewport: this.viewport.getState(),
@@ -3865,7 +4036,7 @@ var zn = .08, Bn = a ** -7, Vn = 800, Hn = 20, Un = 8, Wn = new Set(["horizontal
3865
4036
  };
3866
4037
  }
3867
4038
  };
3868
- function qn(e) {
4039
+ function Qn(e) {
3869
4040
  let t = new Map(e.map((e) => [e.instanceId, e])), n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
3870
4041
  if (r.has(e.instanceId) || i.has(e.instanceId)) return;
3871
4042
  i.add(e.instanceId);
@@ -3879,24 +4050,38 @@ function qn(e) {
3879
4050
  for (let t of e) a(t);
3880
4051
  return n;
3881
4052
  }
3882
- function Jn(e, t) {
4053
+ function $n(e, t) {
3883
4054
  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);
3884
4055
  }
3885
- function Yn(e) {
4056
+ var er = 300;
4057
+ function tr(e) {
4058
+ let t = {}, n = e.family;
4059
+ typeof n == "string" && n.trim() !== "" && n.length <= er && !/[;{}<>\\]|\/\*/.test(n) && (t.family = n);
4060
+ for (let n of [
4061
+ "sizeSmall",
4062
+ "sizeMedium",
4063
+ "sizeLarge"
4064
+ ]) {
4065
+ let r = e[n];
4066
+ typeof r == "number" && Number.isFinite(r) && r > 0 && (t[n] = r);
4067
+ }
4068
+ return t;
4069
+ }
4070
+ function nr(e) {
3886
4071
  let t = e.tagRadius;
3887
4072
  return typeof t == "number" && Number.isFinite(t) && t >= 0 ? { tagRadius: Math.min(t, 999) } : {};
3888
4073
  }
3889
- function Xn(e, t, n) {
4074
+ function rr(e, t, n) {
3890
4075
  for (let r = t; r <= n; r++) if (e[r].volume > 0) return !0;
3891
4076
  return !1;
3892
4077
  }
3893
- function Zn(e, t) {
4078
+ function ir(e, t) {
3894
4079
  return e ? t ? {
3895
4080
  min: Math.min(e.min, t.min),
3896
4081
  max: Math.max(e.max, t.max)
3897
4082
  } : e : t;
3898
4083
  }
3899
- function G(e) {
4084
+ function K(e) {
3900
4085
  return {
3901
4086
  id: e.id,
3902
4087
  price: e.price,
@@ -3911,8 +4096,8 @@ function G(e) {
3911
4096
  bars: e.bars
3912
4097
  };
3913
4098
  }
3914
- var Qn = 500;
3915
- function $n(e, t) {
4099
+ var ar = 500;
4100
+ function or(e, t) {
3916
4101
  let n = 0, r = e.length;
3917
4102
  for (; n < r;) {
3918
4103
  let i = n + r >> 1;
@@ -3920,7 +4105,7 @@ function $n(e, t) {
3920
4105
  }
3921
4106
  return n;
3922
4107
  }
3923
- function er(e, t) {
4108
+ function sr(e, t) {
3924
4109
  let n = 0, r = e.length;
3925
4110
  for (; n < r;) {
3926
4111
  let i = n + r >> 1;
@@ -3928,20 +4113,20 @@ function er(e, t) {
3928
4113
  }
3929
4114
  return n;
3930
4115
  }
3931
- function tr(e) {
4116
+ function cr(e) {
3932
4117
  let t = 0, n = 0;
3933
4118
  for (let r = 1; r < e.length; r++) e[r].low < e[t].low && (t = r), e[r].high > e[n].high && (n = r);
3934
4119
  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];
3935
4120
  return [...a ? [r, i] : [i, r], [o.close, o.time]];
3936
4121
  }
3937
- function nr(e) {
4122
+ function lr(e) {
3938
4123
  let t = 0;
3939
4124
  for (let n = Math.max(1, e.length - 10); n < e.length; n++) t = Math.max(t, e[n].time - e[n - 1].time);
3940
4125
  return t > 0 ? t : Infinity;
3941
4126
  }
3942
- function rr(e, t) {
4127
+ function ur(e, t) {
3943
4128
  if (t.length === 0) return null;
3944
- let n = t[t.length - 1].time + nr(t), r = e.filter((e) => ir(e) && e.time >= t[0].time && e.time < n).sort((e, t) => e.time - t.time), i = [];
4129
+ let n = t[t.length - 1].time + lr(t), r = e.filter((e) => ln(e) && e.time >= t[0].time && e.time < n).sort((e, t) => e.time - t.time), i = [];
3945
4130
  for (let e of r) (i.length === 0 || i[i.length - 1].time !== e.time) && i.push(e);
3946
4131
  if (i.length === 0) return null;
3947
4132
  let a = t.findIndex((e) => e.time >= i[0].time);
@@ -3949,16 +4134,7 @@ function rr(e, t) {
3949
4134
  let o = t.slice(0, a), s = i.filter((e) => e.time >= t[a].time);
3950
4135
  return [...o, ...s];
3951
4136
  }
3952
- function ir(e) {
3953
- return [
3954
- e.time,
3955
- e.open,
3956
- e.high,
3957
- e.low,
3958
- e.close
3959
- ].every(Number.isFinite);
3960
- }
3961
- function ar(e, t) {
4137
+ function dr(e, t) {
3962
4138
  let n = 0, r = e.length - 1;
3963
4139
  for (; n < r;) {
3964
4140
  let i = n + r + 1 >> 1;
@@ -3966,22 +4142,22 @@ function ar(e, t) {
3966
4142
  }
3967
4143
  return n;
3968
4144
  }
3969
- function or(e, t, n) {
4145
+ function fr(e, t, n) {
3970
4146
  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;
3971
4147
  for (let t = 0; t < e.length && e[t].time < i; t++) a = t;
3972
4148
  return Math.max(0, a);
3973
4149
  }
3974
- function sr(e, t, n) {
4150
+ function pr(e, t, n) {
3975
4151
  let r = n;
3976
4152
  for (; r > 0 && t[r - 1].time >= e.time;) r--;
3977
4153
  let i = {
3978
4154
  ...t[r],
3979
4155
  time: e.time
3980
4156
  };
3981
- for (let e = r + 1; e <= n; e++) i = cr(i, t[e]);
4157
+ for (let e = r + 1; e <= n; e++) i = mr(i, t[e]);
3982
4158
  return i;
3983
4159
  }
3984
- function cr(e, t) {
4160
+ function mr(e, t) {
3985
4161
  return {
3986
4162
  time: e.time,
3987
4163
  open: e.open,
@@ -3991,34 +4167,28 @@ function cr(e, t) {
3991
4167
  volume: (e.volume ?? 0) + (t.volume ?? 0)
3992
4168
  };
3993
4169
  }
3994
- function K(e, t) {
3995
- let n = e[e.length - 1];
3996
- if (!n) return "append";
3997
- let r = v(t.time), i = v(n.time);
3998
- return r > i ? "append" : r === i ? "update" : "stale";
3999
- }
4000
4170
  //#endregion
4001
4171
  //#region src/io/parseOHLCV.ts
4002
- var lr = [
4172
+ var hr = [
4003
4173
  "time",
4004
4174
  "timestamp",
4005
4175
  "date",
4006
4176
  "datetime",
4007
4177
  "t"
4008
- ], ur = ["open", "o"], dr = ["high", "h"], fr = ["low", "l"], pr = ["close", "c"], q = [
4178
+ ], gr = ["open", "o"], _r = ["high", "h"], vr = ["low", "l"], yr = ["close", "c"], br = [
4009
4179
  "volume",
4010
4180
  "vol",
4011
4181
  "v"
4012
4182
  ];
4013
- function mr(e) {
4183
+ function q(e) {
4014
4184
  let t = e.trim();
4015
- return t ? t[0] === "[" || t[0] === "{" ? hr(t) : gr(t) : {
4185
+ return t ? t[0] === "[" || t[0] === "{" ? xr(t) : Sr(t) : {
4016
4186
  data: [],
4017
4187
  rowCount: 0,
4018
4188
  skipped: 0
4019
4189
  };
4020
4190
  }
4021
- function hr(e) {
4191
+ function xr(e) {
4022
4192
  let t;
4023
4193
  try {
4024
4194
  t = JSON.parse(e);
@@ -4028,19 +4198,19 @@ function hr(e) {
4028
4198
  if (!Array.isArray(t)) throw Error("Expected a JSON array of OHLCV rows");
4029
4199
  let n = [], r = 0;
4030
4200
  for (let e of t) {
4031
- let t = Array.isArray(e) ? xr(e) : br(e);
4201
+ let t = Array.isArray(e) ? Dr(e) : Er(e);
4032
4202
  t ? n.push(t) : r++;
4033
4203
  }
4034
- return Sr(n, t.length, r);
4204
+ return Or(n, t.length, r);
4035
4205
  }
4036
- function gr(e) {
4206
+ function Sr(e) {
4037
4207
  let t = e.split(/\r?\n/).filter((e) => e.trim().length > 0);
4038
4208
  if (t.length === 0) return {
4039
4209
  data: [],
4040
4210
  rowCount: 0,
4041
4211
  skipped: 0
4042
4212
  };
4043
- let n = _r(t[0]), r = vr(t[0], n).map((e) => e.trim().toLowerCase()), i = r.some((e) => isNaN(Number(e)) && e.length > 0), a = i ? yr(r) : {
4213
+ let n = Cr(t[0]), r = wr(t[0], n).map((e) => e.trim().toLowerCase()), i = r.some((e) => isNaN(Number(e)) && e.length > 0), a = i ? Tr(r) : {
4044
4214
  time: 0,
4045
4215
  open: 1,
4046
4216
  high: 2,
@@ -4051,7 +4221,7 @@ function gr(e) {
4051
4221
  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");
4052
4222
  let o = [], s = 0;
4053
4223
  for (let e = +!!i; e < t.length; e++) {
4054
- let r = vr(t[e], n), i = Y(r[a.time]), c = J(r[a.open]), l = J(r[a.high]), u = J(r[a.low]), d = J(r[a.close]), f = a.volume >= 0 ? Number(r[a.volume]) : 0;
4224
+ let r = wr(t[e], n), i = Y(r[a.time]), c = J(r[a.open]), l = J(r[a.high]), u = J(r[a.low]), d = J(r[a.close]), f = a.volume >= 0 ? Number(r[a.volume]) : 0;
4055
4225
  if (i === null || ![
4056
4226
  c,
4057
4227
  l,
@@ -4070,9 +4240,9 @@ function gr(e) {
4070
4240
  volume: Number.isFinite(f) ? f : 0
4071
4241
  });
4072
4242
  }
4073
- return Sr(o, t.length - +!!i, s);
4243
+ return Or(o, t.length - +!!i, s);
4074
4244
  }
4075
- function _r(e) {
4245
+ function Cr(e) {
4076
4246
  let t = {
4077
4247
  ",": 0,
4078
4248
  ";": 0,
@@ -4084,7 +4254,7 @@ function _r(e) {
4084
4254
  for (let [e, i] of Object.entries(t)) i > r && (n = e, r = i);
4085
4255
  return n;
4086
4256
  }
4087
- function vr(e, t) {
4257
+ function wr(e, t) {
4088
4258
  let n = [], r = "", i = !1;
4089
4259
  for (let a = 0; a < e.length; a++) {
4090
4260
  let o = e[a];
@@ -4092,25 +4262,25 @@ function vr(e, t) {
4092
4262
  }
4093
4263
  return n.push(r), n;
4094
4264
  }
4095
- function yr(e) {
4265
+ function Tr(e) {
4096
4266
  let t = (t) => e.findIndex((e) => t.includes(e));
4097
4267
  return {
4098
- time: t(lr),
4099
- open: t(ur),
4100
- high: t(dr),
4101
- low: t(fr),
4102
- close: t(pr),
4103
- volume: t(q)
4268
+ time: t(hr),
4269
+ open: t(gr),
4270
+ high: t(_r),
4271
+ low: t(vr),
4272
+ close: t(yr),
4273
+ volume: t(br)
4104
4274
  };
4105
4275
  }
4106
- function br(e) {
4276
+ function Er(e) {
4107
4277
  let t = (t) => {
4108
4278
  for (let n of t) {
4109
4279
  if (e[n] !== void 0) return e[n];
4110
4280
  let t = n.toUpperCase();
4111
4281
  if (e[t] !== void 0) return e[t];
4112
4282
  }
4113
- }, n = Y(String(t(lr) ?? "")), r = Number(t(ur)), i = Number(t(dr)), a = Number(t(fr)), o = Number(t(pr)), s = Number(t(q) ?? 0);
4283
+ }, n = Y(String(t(hr) ?? "")), r = Number(t(gr)), i = Number(t(_r)), a = Number(t(vr)), o = Number(t(yr)), s = Number(t(br) ?? 0);
4114
4284
  return n === null || ![
4115
4285
  r,
4116
4286
  i,
@@ -4125,7 +4295,7 @@ function br(e) {
4125
4295
  volume: Number.isFinite(s) ? s : 0
4126
4296
  };
4127
4297
  }
4128
- function xr(e) {
4298
+ function Dr(e) {
4129
4299
  if (e.length < 5) return null;
4130
4300
  let t = Y(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;
4131
4301
  return t === null || ![
@@ -4153,7 +4323,7 @@ function Y(e) {
4153
4323
  let r = Date.parse(t);
4154
4324
  return Number.isFinite(r) ? r : null;
4155
4325
  }
4156
- function Sr(e, t, n) {
4326
+ function Or(e, t, n) {
4157
4327
  e.sort((e, t) => e.time - t.time);
4158
4328
  let r = [];
4159
4329
  for (let t of e) r.length > 0 && r[r.length - 1].time === t.time ? r[r.length - 1] = t : r.push(t);
@@ -4165,7 +4335,7 @@ function Sr(e, t, n) {
4165
4335
  }
4166
4336
  //#endregion
4167
4337
  //#region src/io/DragDropImporter.ts
4168
- var Cr = class {
4338
+ var kr = class {
4169
4339
  host;
4170
4340
  overlay = null;
4171
4341
  callbacks;
@@ -4198,7 +4368,7 @@ var Cr = class {
4198
4368
  e.preventDefault(), this.depth = 0, this.hideOverlay();
4199
4369
  let t = e.dataTransfer?.files?.[0];
4200
4370
  if (t) try {
4201
- let e = mr(await t.text());
4371
+ let e = q(await t.text());
4202
4372
  if (e.data.length === 0) throw Error(`No valid OHLCV rows found in "${t.name}"`);
4203
4373
  this.callbacks.onData(e.data, e, t);
4204
4374
  } catch (e) {
@@ -4242,7 +4412,7 @@ function Z(e) {
4242
4412
  };
4243
4413
  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;
4244
4414
  }
4245
- var wr = (e, t) => t.updatedAt - e.updatedAt;
4415
+ var Ar = (e, t) => t.updatedAt - e.updatedAt;
4246
4416
  function Q(e) {
4247
4417
  if (typeof e != "object" || !e) return null;
4248
4418
  let t = e;
@@ -4255,17 +4425,17 @@ function Q(e) {
4255
4425
  kind: typeof t.kind == "string" ? t.kind : void 0
4256
4426
  });
4257
4427
  }
4258
- function Tr(e) {
4428
+ function jr(e) {
4259
4429
  let t = Q(e), n = t ? e.content : void 0;
4260
4430
  return t && typeof n == "string" ? {
4261
4431
  ...t,
4262
4432
  content: n
4263
4433
  } : null;
4264
4434
  }
4265
- function Er(e = []) {
4435
+ function Mr(e = []) {
4266
4436
  let t = new Map(e.map((e) => [e.id, { ...e }]));
4267
4437
  return {
4268
- list: () => [...t.values()].map(Z).sort(wr),
4438
+ list: () => [...t.values()].map(Z).sort(Ar),
4269
4439
  load: (e) => {
4270
4440
  let n = t.get(e);
4271
4441
  return n ? { ...n } : null;
@@ -4278,7 +4448,7 @@ function Er(e = []) {
4278
4448
  }
4279
4449
  };
4280
4450
  }
4281
- function Dr(e = "tcw:layouts:") {
4451
+ function Nr(e = "tcw:layouts:") {
4282
4452
  let t = `${e}index`, n = (t) => `${e}item:${t}`, r = () => {
4283
4453
  let e;
4284
4454
  try {
@@ -4289,7 +4459,7 @@ function Dr(e = "tcw:layouts:") {
4289
4459
  return Array.isArray(e) ? e.map(Q).filter((e) => e !== null) : [];
4290
4460
  }, i = (e) => localStorage.setItem(t, JSON.stringify(e));
4291
4461
  return {
4292
- list: () => r().sort(wr),
4462
+ list: () => r().sort(Ar),
4293
4463
  load: (e) => {
4294
4464
  let t = r().find((t) => t.id === e), i = t ? localStorage.getItem(n(e)) : null;
4295
4465
  return t && i !== null ? {
@@ -4307,14 +4477,14 @@ function Dr(e = "tcw:layouts:") {
4307
4477
  }
4308
4478
  //#endregion
4309
4479
  //#region src/state/LayoutSession.ts
4310
- var Or = 80;
4480
+ var Pr = 80;
4311
4481
  function $(e) {
4312
4482
  return e.replace(/\s+/g, " ").trim().slice(0, 80).trim() || null;
4313
4483
  }
4314
- function kr() {
4484
+ function Fr() {
4315
4485
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
4316
4486
  }
4317
- function Ar(e) {
4487
+ function Ir(e) {
4318
4488
  let { id: t, name: n, symbol: r, timeframe: i, updatedAt: a, kind: o } = e;
4319
4489
  return {
4320
4490
  id: t,
@@ -4325,7 +4495,7 @@ function Ar(e) {
4325
4495
  ...o === void 0 ? {} : { kind: o }
4326
4496
  };
4327
4497
  }
4328
- var jr = class {
4498
+ var Lr = class {
4329
4499
  currentLayout = null;
4330
4500
  savedContent = null;
4331
4501
  dirty = !1;
@@ -4341,7 +4511,7 @@ var jr = class {
4341
4511
  now;
4342
4512
  newId;
4343
4513
  constructor(e, t, n = {}) {
4344
- 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 ?? kr;
4514
+ 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 ?? Fr;
4345
4515
  }
4346
4516
  current() {
4347
4517
  return this.currentLayout;
@@ -4371,7 +4541,7 @@ var jr = class {
4371
4541
  }
4372
4542
  open(e) {
4373
4543
  return this.queue(async () => {
4374
- let t = Tr(await this.storage.load(e));
4544
+ let t = jr(await this.storage.load(e));
4375
4545
  if (!t || t.id !== e || (t.kind ?? "chart") !== this.kind || this.destroyed) return !1;
4376
4546
  this.cancelTimer(), this.applying++;
4377
4547
  try {
@@ -4381,13 +4551,13 @@ var jr = class {
4381
4551
  } finally {
4382
4552
  this.applying--;
4383
4553
  }
4384
- return this.cancelTimer(), this.currentLayout = Ar(t), this.savedContent = this.host.capture().content, this.dirty = !1, this.notify(), !0;
4554
+ return this.cancelTimer(), this.currentLayout = Ir(t), this.savedContent = this.host.capture().content, this.dirty = !1, this.notify(), !0;
4385
4555
  });
4386
4556
  }
4387
4557
  rename(e, t) {
4388
4558
  let n = $(t);
4389
4559
  return n ? this.queue(async () => {
4390
- let t = Tr(await this.storage.load(e));
4560
+ let t = jr(await this.storage.load(e));
4391
4561
  !t || t.id !== e || (await this.storage.save({
4392
4562
  ...t,
4393
4563
  name: n
@@ -4465,7 +4635,7 @@ var jr = class {
4465
4635
  content: n.content
4466
4636
  };
4467
4637
  await this.storage.save(r);
4468
- let i = Ar(r);
4638
+ let i = Ir(r);
4469
4639
  return this.currentLayout = i, this.savedContent = n.content, this.dirty = !1, this.notify(), i;
4470
4640
  }
4471
4641
  forget() {
@@ -4486,6 +4656,6 @@ var jr = class {
4486
4656
  }
4487
4657
  };
4488
4658
  //#endregion
4489
- export { V as C, sn as S, Xt as T, Tn as _, Er as a, dn as b, Kn as c, An as d, kn as f, wn as g, Dn as h, Dr as i, In as l, En as m, Or as n, Cr as o, On as p, $ as r, mr as s, jr as t, Fn as u, U as v, z as w, ln as x, gn as y };
4659
+ export { V as C, dn as S, Xt as T, An as _, Mr as a, gn as b, Zn as c, Fn as d, Pn as f, kn as g, Mn as h, Nr as i, Vn as l, jn as m, Pr as n, kr as o, Nn as p, $ as r, q as s, Lr as t, Bn as u, W as v, z as w, pn as x, xn as y };
4490
4660
 
4491
- //# sourceMappingURL=LayoutSession-OzzotveZ.js.map
4661
+ //# sourceMappingURL=LayoutSession-Dcvn5KMK.js.map