@tradecanvas/commons 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ function f(e, t, n) {
81
81
  function p(e) {
82
82
  return e > 0xe8d4a51000 ? e : e * 1e3;
83
83
  }
84
- function ee(e) {
84
+ function m(e) {
85
85
  return {
86
86
  time: p(e.time ?? e.t ?? 0),
87
87
  open: e.open ?? e.o ?? 0,
@@ -91,11 +91,11 @@ function ee(e) {
91
91
  volume: e.volume ?? e.v ?? 0
92
92
  };
93
93
  }
94
- function m(e, t, n) {
94
+ function ee(e, t, n) {
95
95
  let r = Math.max(0, t), i = Math.min(e.length, n + 1);
96
96
  return e.slice(r, i);
97
97
  }
98
- function h(e, t) {
98
+ function te(e, t) {
99
99
  let n = 0, r = e.length - 1;
100
100
  for (; n <= r;) {
101
101
  let i = n + r >>> 1;
@@ -105,7 +105,7 @@ function h(e, t) {
105
105
  }
106
106
  return n;
107
107
  }
108
- function g(e, t, n, r = .05) {
108
+ function h(e, t, n, r = .05) {
109
109
  if (e.length === 0) return {
110
110
  min: 0,
111
111
  max: 1
@@ -122,7 +122,7 @@ function g(e, t, n, r = .05) {
122
122
  max: s + c * r
123
123
  };
124
124
  }
125
- function _(e, t) {
125
+ function g(e, t) {
126
126
  return {
127
127
  ...e,
128
128
  high: Math.max(e.high, t.price),
@@ -134,15 +134,15 @@ function _(e, t) {
134
134
  }
135
135
  //#endregion
136
136
  //#region src/utils/color.ts
137
- function v(e, t = 1) {
137
+ function _(e, t = 1) {
138
138
  return `rgba(${parseInt(e.slice(1, 3), 16)}, ${parseInt(e.slice(3, 5), 16)}, ${parseInt(e.slice(5, 7), 16)}, ${t})`;
139
139
  }
140
- function y(e, t) {
141
- if (e.startsWith("#")) return v(e, t);
140
+ function ne(e, t) {
141
+ if (e.startsWith("#")) return _(e, t);
142
142
  let n = e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
143
143
  return n ? `rgba(${n[1]}, ${n[2]}, ${n[3]}, ${t})` : e;
144
144
  }
145
- function b(e, t, n) {
145
+ function re(e, t, n) {
146
146
  let r = (e) => (e = e.replace("#", ""), e.length === 3 && (e = e[0] + e[0] + e[1] + e[1] + e[2] + e[2]), {
147
147
  r: parseInt(e.slice(0, 2), 16),
148
148
  g: parseInt(e.slice(2, 4), 16),
@@ -152,7 +152,7 @@ function b(e, t, n) {
152
152
  }
153
153
  //#endregion
154
154
  //#region src/utils/time.ts
155
- var x = {
155
+ var v = {
156
156
  "1s": 1e3,
157
157
  "5s": 5e3,
158
158
  "15s": 15e3,
@@ -180,11 +180,11 @@ var x = {
180
180
  "6M": 15552e6,
181
181
  "12M": 31536e6
182
182
  };
183
- function te(e) {
184
- return x[e];
183
+ function ie(e) {
184
+ return v[e];
185
185
  }
186
- function ne(e, t) {
187
- let n = new Date(e), r = x[t];
186
+ function ae(e, t) {
187
+ let n = new Date(e), r = v[t];
188
188
  return r >= 864e5 ? n.toLocaleDateString(void 0, {
189
189
  month: "short",
190
190
  day: "numeric"
@@ -197,11 +197,11 @@ function ne(e, t) {
197
197
  second: "2-digit"
198
198
  });
199
199
  }
200
- function re(e, t) {
201
- let n = x[t];
200
+ function oe(e, t) {
201
+ let n = v[t];
202
202
  return Math.floor(e / n) * n;
203
203
  }
204
- function ie(e, t) {
204
+ function se(e, t) {
205
205
  if (t === null) {
206
206
  let t = new Date(e);
207
207
  return {
@@ -221,15 +221,15 @@ function ie(e, t) {
221
221
  minutes: n.getUTCMinutes()
222
222
  };
223
223
  }
224
- function ae(e) {
224
+ function ce(e) {
225
225
  return e.hours === 0 && e.minutes === 0;
226
226
  }
227
- function S(e) {
227
+ function le(e) {
228
228
  let t = e === null ? -(/* @__PURE__ */ new Date()).getTimezoneOffset() : e, n = t >= 0 ? "+" : "-", r = Math.abs(t), i = Math.floor(r / 60), a = r % 60;
229
229
  return a === 0 ? `UTC${n}${i}` : `UTC${n}${i}:${String(a).padStart(2, "0")}`;
230
230
  }
231
- var C = Date.UTC(1970, 0, 5);
232
- function w(e) {
231
+ var y = Date.UTC(1970, 0, 5);
232
+ function b(e) {
233
233
  let t = /^(\d+)([smhdwM])$/.exec(e);
234
234
  return t ? {
235
235
  count: parseInt(t[1], 10),
@@ -239,29 +239,39 @@ function w(e) {
239
239
  unit: "m"
240
240
  };
241
241
  }
242
- function T(e, t, n = 1) {
243
- let { count: r, unit: i } = w(t);
242
+ function x(e, t, n = 1) {
243
+ let { count: r, unit: i } = b(t);
244
244
  if (i === "s" || i === "m" || i === "h" || i === "d") {
245
- let n = x[t];
245
+ let n = v[t];
246
246
  return Math.floor(e / n) * n;
247
247
  }
248
248
  let a = new Date(e);
249
249
  if (i === "w") {
250
- let e = x["1d"], t = (a.getUTCDay() - n + 7) % 7, i = Date.UTC(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate() - t);
250
+ let e = v["1d"], t = (a.getUTCDay() - n + 7) % 7, i = Date.UTC(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate() - t);
251
251
  if (r <= 1) return i;
252
- let o = Math.floor((i - C) / (7 * e));
253
- return C + Math.floor(o / r) * r * 7 * e;
252
+ let o = Math.floor((i - y) / (7 * e));
253
+ return y + Math.floor(o / r) * r * 7 * e;
254
254
  }
255
255
  let o = a.getUTCFullYear() * 12 + a.getUTCMonth(), s = Math.floor(o / r) * r;
256
256
  return Date.UTC(Math.floor(s / 12), s % 12, 1);
257
257
  }
258
258
  //#endregion
259
259
  //#region src/utils/precision.ts
260
- function E(e, t = 2, n = "en-US") {
261
- return e.toLocaleString(n, {
260
+ var S = 64, C = /* @__PURE__ */ new Map();
261
+ function w(e, t) {
262
+ let n = `${e}|${t}`, r = C.get(n);
263
+ return r || (C.size >= S && C.clear(), r = new Intl.NumberFormat(e, {
262
264
  minimumFractionDigits: t,
263
265
  maximumFractionDigits: t
264
- });
266
+ }), C.set(n, r)), r;
267
+ }
268
+ function T(e, t = 2, n = "en-US") {
269
+ return w(n, t).format(e);
270
+ }
271
+ function E(e, t) {
272
+ if (!(t > e) || !Number.isFinite(e) || !Number.isFinite(t)) return 2;
273
+ let n = f(e, t, 8);
274
+ return n > 0 && n < 1 ? Math.ceil(-Math.log10(n)) + 1 : 2;
265
275
  }
266
276
  function D(e, t, n, r = 2, i = "en-US") {
267
277
  if ((t === "percentage" || t === "indexedTo100") && n && n !== 0) {
@@ -269,12 +279,9 @@ function D(e, t, n, r = 2, i = "en-US") {
269
279
  let t = (e / n - 1) * 100;
270
280
  return `${t > 0 ? "+" : ""}${t.toFixed(2)}%`;
271
281
  }
272
- return (e / n * 100).toLocaleString(i, {
273
- minimumFractionDigits: 2,
274
- maximumFractionDigits: 2
275
- });
282
+ return T(e / n * 100, 2, i);
276
283
  }
277
- return E(e, r, i);
284
+ return T(e, r, i);
278
285
  }
279
286
  function O(e) {
280
287
  return e >= 1e9 ? (e / 1e9).toFixed(2) + "B" : e >= 1e6 ? (e / 1e6).toFixed(2) + "M" : e >= 1e3 ? (e / 1e3).toFixed(2) + "K" : e.toFixed(0);
@@ -354,7 +361,7 @@ var A = {
354
361
  sizeSmall: 10,
355
362
  sizeMedium: 12,
356
363
  sizeLarge: 14
357
- }, oe = {
364
+ }, H = {
358
365
  name: "dark",
359
366
  background: "#131722",
360
367
  text: "#D1D4DC",
@@ -374,7 +381,7 @@ var A = {
374
381
  axisLabel: "#D1D4DC",
375
382
  axisLabelBackground: "#2A2E39",
376
383
  font: V
377
- }, H = {
384
+ }, U = {
378
385
  name: "light",
379
386
  background: "#FFFFFF",
380
387
  text: "#131722",
@@ -394,7 +401,7 @@ var A = {
394
401
  axisLabel: "#131722",
395
402
  axisLabelBackground: "#F0F3FA",
396
403
  font: V
397
- }, U = {
404
+ }, ue = {
398
405
  name: "terminal",
399
406
  background: "#0E0E0E",
400
407
  text: "#C0C0C0",
@@ -626,19 +633,19 @@ var A = {
626
633
  numberDecimalSeparator: ",",
627
634
  numberGroupSeparator: "."
628
635
  }, K = new Map([["en", W], ["vi", G]]), q = "en", J = W;
629
- function se(e) {
636
+ function de(e) {
630
637
  q = e, J = K.get(e) ?? W;
631
638
  }
632
- function ce() {
639
+ function fe() {
633
640
  return q;
634
641
  }
635
- function le(e) {
642
+ function pe(e) {
636
643
  return J[e] ?? W[e] ?? e;
637
644
  }
638
- function ue(e, t) {
645
+ function me(e, t) {
639
646
  K.set(e, t);
640
647
  }
641
- function de(e) {
648
+ function he(e) {
642
649
  return K.get(e ?? q) ?? W;
643
650
  }
644
651
  function Y(e, t = 2, n) {
@@ -646,22 +653,22 @@ function Y(e, t = 2, n) {
646
653
  for (let e = l.length - 1, t = 0; e >= 0; e--, t++) t > 0 && t % 3 == 0 && (u = a + u), u = l[e] + u;
647
654
  return c && (u = "-" + u), s ? u + i + s : u;
648
655
  }
649
- function fe(e) {
656
+ function ge(e) {
650
657
  return Y(e, 0, "vi");
651
658
  }
652
- function pe(e, t) {
659
+ function X(e, t) {
653
660
  return e >= 1e9 ? Y(e / 1e9, 2, t ?? q) + "B" : e >= 1e6 ? Y(e / 1e6, 2, t ?? q) + "M" : e >= 1e3 ? Y(e / 1e3, 2, t ?? q) + "K" : Y(e, 0, t ?? q);
654
661
  }
655
662
  //#endregion
656
663
  //#region src/market/presets.ts
657
- var X = {
664
+ var Z = {
658
665
  up: "#FF0000",
659
666
  down: "#0000FF",
660
667
  unchanged: "#FFD700",
661
668
  ceiling: "#FF00FF",
662
669
  floor: "#00FFFF",
663
670
  reference: "#FFD700"
664
- }, Z = [
671
+ }, Q = [
665
672
  {
666
673
  name: "ATO",
667
674
  startTime: "09:00",
@@ -692,7 +699,7 @@ var X = {
692
699
  endTime: "14:45",
693
700
  type: "preClose"
694
701
  }
695
- ], Q = [
702
+ ], $ = [
696
703
  {
697
704
  name: "Phiên 1",
698
705
  startTime: "09:00",
@@ -717,7 +724,7 @@ var X = {
717
724
  endTime: "14:45",
718
725
  type: "preClose"
719
726
  }
720
- ], $ = {
727
+ ], _e = {
721
728
  type: "stock",
722
729
  exchange: "HOSE",
723
730
  currency: "VND",
@@ -729,9 +736,9 @@ var X = {
729
736
  ceilingPercent: 7,
730
737
  floorPercent: 7
731
738
  },
732
- sessions: Z,
733
- colorScheme: X
734
- }, me = {
739
+ sessions: Q,
740
+ colorScheme: Z
741
+ }, ve = {
735
742
  type: "stock",
736
743
  exchange: "HNX",
737
744
  currency: "VND",
@@ -743,9 +750,9 @@ var X = {
743
750
  ceilingPercent: 10,
744
751
  floorPercent: 10
745
752
  },
746
- sessions: Q,
747
- colorScheme: X
748
- }, he = {
753
+ sessions: $,
754
+ colorScheme: Z
755
+ }, ye = {
749
756
  type: "stock",
750
757
  exchange: "UPCOM",
751
758
  currency: "VND",
@@ -757,14 +764,14 @@ var X = {
757
764
  ceilingPercent: 15,
758
765
  floorPercent: 15
759
766
  },
760
- sessions: Q,
761
- colorScheme: X
762
- }, ge = {
767
+ sessions: $,
768
+ colorScheme: Z
769
+ }, be = {
763
770
  type: "crypto",
764
771
  currency: "USDT",
765
772
  pricePrecision: 2,
766
773
  priceLimits: { enabled: !1 }
767
- }, _e = {
774
+ }, xe = {
768
775
  type: "stock",
769
776
  exchange: "NYSE",
770
777
  currency: "USD",
@@ -792,18 +799,18 @@ var X = {
792
799
  }
793
800
  ]
794
801
  };
795
- function ve(e) {
802
+ function Se(e) {
796
803
  return {
797
804
  ...e,
798
- candleUp: X.up,
799
- candleDown: X.down,
800
- candleUpWick: X.up,
801
- candleDownWick: X.down,
805
+ candleUp: Z.up,
806
+ candleDown: Z.down,
807
+ candleUpWick: Z.up,
808
+ candleDownWick: Z.down,
802
809
  volumeUp: "rgba(255, 0, 0, 0.3)",
803
810
  volumeDown: "rgba(0, 0, 255, 0.3)"
804
811
  };
805
812
  }
806
- function ye(e, t) {
813
+ function Ce(e, t) {
807
814
  if (!t.priceLimits?.enabled || !t.priceLimits.ceilingPercent) return null;
808
815
  let n = t.priceLimits.ceilingPercent / 100, r = (t.priceLimits.floorPercent ?? t.priceLimits.ceilingPercent) / 100;
809
816
  return {
@@ -812,12 +819,12 @@ function ye(e, t) {
812
819
  reference: e
813
820
  };
814
821
  }
815
- function be(e) {
822
+ function we(e) {
816
823
  let t = /* @__PURE__ */ new Date(), n = `${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}`;
817
824
  for (let t of e) if (n >= t.startTime && n < t.endTime) return t;
818
825
  return null;
819
826
  }
820
827
  //#endregion
821
- export { U as DARK_TERMINAL, oe as DARK_THEME, I as DEFAULT_BAR_SPACING, F as DEFAULT_BAR_WIDTH, A as DEFAULT_CHART_OPTIONS, t as DEFAULT_DRAWING_STYLE, B as DEFAULT_PANEL_HEIGHT, a as DEFAULT_RECONNECT, r as DEFAULT_SIGNAL_STYLE, o as DEFAULT_STREAM_CONFIG, P as DEFAULT_TIMEFRAME_FAVORITES, i as DEFAULT_TRADE_ZONE_STYLE, n as DEFAULT_TRADING_CONFIG, Q as HNX_SESSIONS, Z as HOSE_SESSIONS, H as LIGHT_THEME, e as LayerType, ge as MARKET_CRYPTO, me as MARKET_HNX, $ as MARKET_HOSE, _e as MARKET_NYSE, he as MARKET_UPCOM, z as MIN_PANEL_HEIGHT, L as PRICE_AXIS_WIDTH, j as TIMEFRAMES_CRYPTO, N as TIMEFRAMES_FOREX, M as TIMEFRAMES_STOCK, R as TIME_AXIS_HEIGHT, X as VN_COLORS, re as alignToTimeframe, s as clamp, ye as computePriceLimits, g as computePriceRange, f as computeTickStep, ve as createVNTheme, k as detectPrecision, W as en, h as findBarIndex, Y as formatNumber, E as formatPrice, D as formatPriceScaleLabel, ne as formatTimestamp, fe as formatVND, O as formatVolume, pe as formatVolumeLoc, be as getCurrentSession, ce as getLocale, de as getLocaleStrings, v as hexToRgba, l as inverseLerp, ae as isDateOnly, c as lerp, b as lerpColor, _ as mergeBar, d as niceNumber, ee as normalizeBar, p as normalizeBarTime, ue as registerLocale, u as roundToStep, se as setLocale, m as sliceVisibleData, le as t, ie as timeParts, T as timeframeBucketStart, te as timeframeToMs, S as tzLabel, G as vi, y as withAlpha };
828
+ export { ue as DARK_TERMINAL, H as DARK_THEME, I as DEFAULT_BAR_SPACING, F as DEFAULT_BAR_WIDTH, A as DEFAULT_CHART_OPTIONS, t as DEFAULT_DRAWING_STYLE, B as DEFAULT_PANEL_HEIGHT, a as DEFAULT_RECONNECT, r as DEFAULT_SIGNAL_STYLE, o as DEFAULT_STREAM_CONFIG, P as DEFAULT_TIMEFRAME_FAVORITES, i as DEFAULT_TRADE_ZONE_STYLE, n as DEFAULT_TRADING_CONFIG, $ as HNX_SESSIONS, Q as HOSE_SESSIONS, U as LIGHT_THEME, e as LayerType, be as MARKET_CRYPTO, ve as MARKET_HNX, _e as MARKET_HOSE, xe as MARKET_NYSE, ye as MARKET_UPCOM, z as MIN_PANEL_HEIGHT, L as PRICE_AXIS_WIDTH, j as TIMEFRAMES_CRYPTO, N as TIMEFRAMES_FOREX, M as TIMEFRAMES_STOCK, R as TIME_AXIS_HEIGHT, Z as VN_COLORS, oe as alignToTimeframe, E as autoPricePrecision, s as clamp, Ce as computePriceLimits, h as computePriceRange, f as computeTickStep, Se as createVNTheme, k as detectPrecision, W as en, te as findBarIndex, Y as formatNumber, T as formatPrice, D as formatPriceScaleLabel, ae as formatTimestamp, ge as formatVND, O as formatVolume, X as formatVolumeLoc, we as getCurrentSession, fe as getLocale, he as getLocaleStrings, _ as hexToRgba, l as inverseLerp, ce as isDateOnly, c as lerp, re as lerpColor, g as mergeBar, d as niceNumber, m as normalizeBar, p as normalizeBarTime, me as registerLocale, u as roundToStep, de as setLocale, ee as sliceVisibleData, pe as t, se as timeParts, x as timeframeBucketStart, ie as timeframeToMs, le as tzLabel, G as vi, ne as withAlpha };
822
829
 
823
830
  //# sourceMappingURL=index.js.map