@tradecanvas/commons 0.9.0 → 1.0.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 h(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 g(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 _(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 te(e, t) {
125
+ function v(e, t) {
126
126
  return {
127
127
  ...e,
128
128
  high: Math.max(e.high, t.price),
@@ -134,15 +134,15 @@ function te(e, t) {
134
134
  }
135
135
  //#endregion
136
136
  //#region src/utils/color.ts
137
- function _(e, t = 1) {
137
+ function y(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 v(e, t) {
141
- if (e.startsWith("#")) return _(e, t);
140
+ function b(e, t) {
141
+ if (e.startsWith("#")) return y(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 y(e, t, n) {
145
+ function x(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 y(e, t, n) {
152
152
  }
153
153
  //#endregion
154
154
  //#region src/utils/time.ts
155
- var b = {
155
+ var S = {
156
156
  "1s": 1e3,
157
157
  "5s": 5e3,
158
158
  "15s": 15e3,
@@ -180,11 +180,11 @@ var b = {
180
180
  "6M": 15552e6,
181
181
  "12M": 31536e6
182
182
  };
183
- function ne(e) {
184
- return b[e];
183
+ function ee(e) {
184
+ return S[e];
185
185
  }
186
- function re(e, t) {
187
- let n = new Date(e), r = b[t];
186
+ function te(e, t) {
187
+ let n = new Date(e), r = S[t];
188
188
  return r >= 864e5 ? n.toLocaleDateString(void 0, {
189
189
  month: "short",
190
190
  day: "numeric"
@@ -197,22 +197,84 @@ function re(e, t) {
197
197
  second: "2-digit"
198
198
  });
199
199
  }
200
- function ie(e, t) {
201
- let n = b[t];
200
+ function ne(e, t) {
201
+ let n = S[t];
202
202
  return Math.floor(e / n) * n;
203
203
  }
204
+ function re(e, t) {
205
+ if (t === null) {
206
+ let t = new Date(e);
207
+ return {
208
+ month: t.getMonth() + 1,
209
+ day: t.getDate(),
210
+ hours: t.getHours(),
211
+ minutes: t.getMinutes()
212
+ };
213
+ }
214
+ let n = new Date(e + t * 6e4);
215
+ return {
216
+ month: n.getUTCMonth() + 1,
217
+ day: n.getUTCDate(),
218
+ hours: n.getUTCHours(),
219
+ minutes: n.getUTCMinutes()
220
+ };
221
+ }
222
+ function ie(e) {
223
+ let t = e === null ? -(/* @__PURE__ */ new Date()).getTimezoneOffset() : e, n = t >= 0 ? "+" : "-", r = Math.abs(t), i = Math.floor(r / 60), a = r % 60;
224
+ return a === 0 ? `UTC${n}${i}` : `UTC${n}${i}:${String(a).padStart(2, "0")}`;
225
+ }
226
+ var C = Date.UTC(1970, 0, 5);
227
+ function w(e) {
228
+ let t = /^(\d+)([smhdwM])$/.exec(e);
229
+ return t ? {
230
+ count: parseInt(t[1], 10),
231
+ unit: t[2]
232
+ } : {
233
+ count: 1,
234
+ unit: "m"
235
+ };
236
+ }
237
+ function T(e, t, n = 1) {
238
+ let { count: r, unit: i } = w(t);
239
+ if (i === "s" || i === "m" || i === "h" || i === "d") {
240
+ let n = S[t];
241
+ return Math.floor(e / n) * n;
242
+ }
243
+ let a = new Date(e);
244
+ if (i === "w") {
245
+ let e = S["1d"], t = (a.getUTCDay() - n + 7) % 7, i = Date.UTC(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate() - t);
246
+ if (r <= 1) return i;
247
+ let o = Math.floor((i - C) / (7 * e));
248
+ return C + Math.floor(o / r) * r * 7 * e;
249
+ }
250
+ let o = a.getUTCFullYear() * 12 + a.getUTCMonth(), s = Math.floor(o / r) * r;
251
+ return Date.UTC(Math.floor(s / 12), s % 12, 1);
252
+ }
204
253
  //#endregion
205
254
  //#region src/utils/precision.ts
206
- function x(e, t = 2, n = "en-US") {
255
+ function E(e, t = 2, n = "en-US") {
207
256
  return e.toLocaleString(n, {
208
257
  minimumFractionDigits: t,
209
258
  maximumFractionDigits: t
210
259
  });
211
260
  }
212
- function S(e) {
261
+ function D(e, t, n, r = 2, i = "en-US") {
262
+ if ((t === "percentage" || t === "indexedTo100") && n && n !== 0) {
263
+ if (t === "percentage") {
264
+ let t = (e / n - 1) * 100;
265
+ return `${t > 0 ? "+" : ""}${t.toFixed(2)}%`;
266
+ }
267
+ return (e / n * 100).toLocaleString(i, {
268
+ minimumFractionDigits: 2,
269
+ maximumFractionDigits: 2
270
+ });
271
+ }
272
+ return E(e, r, i);
273
+ }
274
+ function O(e) {
213
275
  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);
214
276
  }
215
- function C(e) {
277
+ function k(e) {
216
278
  let t = 0;
217
279
  for (let n of e) {
218
280
  let e = n.toString(), r = e.indexOf(".");
@@ -222,7 +284,7 @@ function C(e) {
222
284
  }
223
285
  //#endregion
224
286
  //#region src/constants/defaults.ts
225
- var w = {
287
+ var A = {
226
288
  autoScale: !0,
227
289
  rightMargin: 5,
228
290
  minBarSpacing: 2,
@@ -233,7 +295,7 @@ var w = {
233
295
  vLineStyle: "solid"
234
296
  },
235
297
  crosshair: { mode: "magnet" }
236
- }, T = [
298
+ }, j = [
237
299
  "1s",
238
300
  "1m",
239
301
  "3m",
@@ -250,7 +312,7 @@ var w = {
250
312
  "3d",
251
313
  "1w",
252
314
  "1M"
253
- ], E = [
315
+ ], M = [
254
316
  "1m",
255
317
  "5m",
256
318
  "15m",
@@ -264,7 +326,7 @@ var w = {
264
326
  "3M",
265
327
  "6M",
266
328
  "12M"
267
- ], D = [
329
+ ], N = [
268
330
  "1m",
269
331
  "5m",
270
332
  "15m",
@@ -274,7 +336,7 @@ var w = {
274
336
  "1d",
275
337
  "1w",
276
338
  "1M"
277
- ], O = [
339
+ ], P = [
278
340
  "1m",
279
341
  "5m",
280
342
  "15m",
@@ -282,12 +344,12 @@ var w = {
282
344
  "4h",
283
345
  "1d",
284
346
  "1w"
285
- ], k = 8, A = 2, j = 70, M = 30, N = 60, P = 120, F = {
347
+ ], F = 8, I = 2, L = 70, R = 30, z = 60, B = 120, V = {
286
348
  family: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif",
287
349
  sizeSmall: 10,
288
350
  sizeMedium: 12,
289
351
  sizeLarge: 14
290
- }, I = {
352
+ }, H = {
291
353
  name: "dark",
292
354
  background: "#131722",
293
355
  text: "#D1D4DC",
@@ -306,8 +368,8 @@ var w = {
306
368
  axisLine: "#2A2E39",
307
369
  axisLabel: "#D1D4DC",
308
370
  axisLabelBackground: "#2A2E39",
309
- font: F
310
- }, L = {
371
+ font: V
372
+ }, ae = {
311
373
  name: "light",
312
374
  background: "#FFFFFF",
313
375
  text: "#131722",
@@ -326,8 +388,8 @@ var w = {
326
388
  axisLine: "#E0E3EB",
327
389
  axisLabel: "#131722",
328
390
  axisLabelBackground: "#F0F3FA",
329
- font: F
330
- }, R = {
391
+ font: V
392
+ }, U = {
331
393
  name: "terminal",
332
394
  background: "#0E0E0E",
333
395
  text: "#C0C0C0",
@@ -352,7 +414,7 @@ var w = {
352
414
  sizeMedium: 12,
353
415
  sizeLarge: 14
354
416
  }
355
- }, z = {
417
+ }, W = {
356
418
  candlestick: "Candlestick",
357
419
  line: "Line",
358
420
  area: "Area",
@@ -455,7 +517,7 @@ var w = {
455
517
  error: "Error",
456
518
  numberDecimalSeparator: ".",
457
519
  numberGroupSeparator: ","
458
- }, B = {
520
+ }, G = {
459
521
  candlestick: "Nến",
460
522
  line: "Đường",
461
523
  area: "Vùng",
@@ -558,32 +620,32 @@ var w = {
558
620
  error: "Lỗi",
559
621
  numberDecimalSeparator: ",",
560
622
  numberGroupSeparator: "."
561
- }, V = new Map([["en", z], ["vi", B]]), H = "en", U = z;
562
- function W(e) {
563
- H = e, U = V.get(e) ?? z;
623
+ }, K = new Map([["en", W], ["vi", G]]), q = "en", J = W;
624
+ function oe(e) {
625
+ q = e, J = K.get(e) ?? W;
564
626
  }
565
- function G() {
566
- return H;
627
+ function se() {
628
+ return q;
567
629
  }
568
- function K(e) {
569
- return U[e] ?? z[e] ?? e;
630
+ function ce(e) {
631
+ return J[e] ?? W[e] ?? e;
570
632
  }
571
- function q(e, t) {
572
- V.set(e, t);
633
+ function le(e, t) {
634
+ K.set(e, t);
573
635
  }
574
- function J(e) {
575
- return V.get(e ?? H) ?? z;
636
+ function ue(e) {
637
+ return K.get(e ?? q) ?? W;
576
638
  }
577
639
  function Y(e, t = 2, n) {
578
- let r = V.get(n ?? H) ?? z, i = r.numberDecimalSeparator, a = r.numberGroupSeparator, [o, s] = e.toFixed(t).split("."), c = o.startsWith("-"), l = c ? o.slice(1) : o, u = "";
640
+ let r = K.get(n ?? q) ?? W, i = r.numberDecimalSeparator, a = r.numberGroupSeparator, [o, s] = e.toFixed(t).split("."), c = o.startsWith("-"), l = c ? o.slice(1) : o, u = "";
579
641
  for (let e = l.length - 1, t = 0; e >= 0; e--, t++) t > 0 && t % 3 == 0 && (u = a + u), u = l[e] + u;
580
642
  return c && (u = "-" + u), s ? u + i + s : u;
581
643
  }
582
- function ae(e) {
644
+ function de(e) {
583
645
  return Y(e, 0, "vi");
584
646
  }
585
- function oe(e, t) {
586
- return e >= 1e9 ? Y(e / 1e9, 2, t ?? H) + "B" : e >= 1e6 ? Y(e / 1e6, 2, t ?? H) + "M" : e >= 1e3 ? Y(e / 1e3, 2, t ?? H) + "K" : Y(e, 0, t ?? H);
647
+ function fe(e, t) {
648
+ 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);
587
649
  }
588
650
  //#endregion
589
651
  //#region src/market/presets.ts
@@ -650,7 +712,7 @@ var X = {
650
712
  endTime: "14:45",
651
713
  type: "preClose"
652
714
  }
653
- ], $ = {
715
+ ], pe = {
654
716
  type: "stock",
655
717
  exchange: "HOSE",
656
718
  currency: "VND",
@@ -664,7 +726,7 @@ var X = {
664
726
  },
665
727
  sessions: Z,
666
728
  colorScheme: X
667
- }, se = {
729
+ }, me = {
668
730
  type: "stock",
669
731
  exchange: "HNX",
670
732
  currency: "VND",
@@ -678,7 +740,7 @@ var X = {
678
740
  },
679
741
  sessions: Q,
680
742
  colorScheme: X
681
- }, ce = {
743
+ }, he = {
682
744
  type: "stock",
683
745
  exchange: "UPCOM",
684
746
  currency: "VND",
@@ -692,12 +754,12 @@ var X = {
692
754
  },
693
755
  sessions: Q,
694
756
  colorScheme: X
695
- }, le = {
757
+ }, ge = {
696
758
  type: "crypto",
697
759
  currency: "USDT",
698
760
  pricePrecision: 2,
699
761
  priceLimits: { enabled: !1 }
700
- }, ue = {
762
+ }, $ = {
701
763
  type: "stock",
702
764
  exchange: "NYSE",
703
765
  currency: "USD",
@@ -725,7 +787,7 @@ var X = {
725
787
  }
726
788
  ]
727
789
  };
728
- function de(e) {
790
+ function _e(e) {
729
791
  return {
730
792
  ...e,
731
793
  candleUp: X.up,
@@ -736,7 +798,7 @@ function de(e) {
736
798
  volumeDown: "rgba(0, 0, 255, 0.3)"
737
799
  };
738
800
  }
739
- function fe(e, t) {
801
+ function ve(e, t) {
740
802
  if (!t.priceLimits?.enabled || !t.priceLimits.ceilingPercent) return null;
741
803
  let n = t.priceLimits.ceilingPercent / 100, r = (t.priceLimits.floorPercent ?? t.priceLimits.ceilingPercent) / 100;
742
804
  return {
@@ -745,12 +807,12 @@ function fe(e, t) {
745
807
  reference: e
746
808
  };
747
809
  }
748
- function pe(e) {
810
+ function ye(e) {
749
811
  let t = /* @__PURE__ */ new Date(), n = `${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}`;
750
812
  for (let t of e) if (n >= t.startTime && n < t.endTime) return t;
751
813
  return null;
752
814
  }
753
815
  //#endregion
754
- export { R as DARK_TERMINAL, I as DARK_THEME, A as DEFAULT_BAR_SPACING, k as DEFAULT_BAR_WIDTH, w as DEFAULT_CHART_OPTIONS, t as DEFAULT_DRAWING_STYLE, P as DEFAULT_PANEL_HEIGHT, a as DEFAULT_RECONNECT, r as DEFAULT_SIGNAL_STYLE, o as DEFAULT_STREAM_CONFIG, O as DEFAULT_TIMEFRAME_FAVORITES, i as DEFAULT_TRADE_ZONE_STYLE, n as DEFAULT_TRADING_CONFIG, Q as HNX_SESSIONS, Z as HOSE_SESSIONS, L as LIGHT_THEME, e as LayerType, le as MARKET_CRYPTO, se as MARKET_HNX, $ as MARKET_HOSE, ue as MARKET_NYSE, ce as MARKET_UPCOM, N as MIN_PANEL_HEIGHT, j as PRICE_AXIS_WIDTH, T as TIMEFRAMES_CRYPTO, D as TIMEFRAMES_FOREX, E as TIMEFRAMES_STOCK, M as TIME_AXIS_HEIGHT, X as VN_COLORS, ie as alignToTimeframe, s as clamp, fe as computePriceLimits, g as computePriceRange, f as computeTickStep, de as createVNTheme, C as detectPrecision, z as en, h as findBarIndex, Y as formatNumber, x as formatPrice, re as formatTimestamp, ae as formatVND, S as formatVolume, oe as formatVolumeLoc, pe as getCurrentSession, G as getLocale, J as getLocaleStrings, _ as hexToRgba, l as inverseLerp, c as lerp, y as lerpColor, te as mergeBar, d as niceNumber, ee as normalizeBar, p as normalizeBarTime, q as registerLocale, u as roundToStep, W as setLocale, m as sliceVisibleData, K as t, ne as timeframeToMs, B as vi, v as withAlpha };
816
+ export { U 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, Q as HNX_SESSIONS, Z as HOSE_SESSIONS, ae as LIGHT_THEME, e as LayerType, ge as MARKET_CRYPTO, me as MARKET_HNX, pe as MARKET_HOSE, $ 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, ne as alignToTimeframe, s as clamp, ve as computePriceLimits, _ as computePriceRange, f as computeTickStep, _e as createVNTheme, k as detectPrecision, W as en, g as findBarIndex, Y as formatNumber, E as formatPrice, D as formatPriceScaleLabel, te as formatTimestamp, de as formatVND, O as formatVolume, fe as formatVolumeLoc, ye as getCurrentSession, se as getLocale, ue as getLocaleStrings, y as hexToRgba, l as inverseLerp, c as lerp, x as lerpColor, v as mergeBar, d as niceNumber, m as normalizeBar, p as normalizeBarTime, le as registerLocale, u as roundToStep, oe as setLocale, h as sliceVisibleData, ce as t, re as timeParts, T as timeframeBucketStart, ee as timeframeToMs, ie as tzLabel, G as vi, b as withAlpha };
755
817
 
756
818
  //# sourceMappingURL=index.js.map