@forgecharts/sdk 1.5.34 → 1.5.36

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/internal.js CHANGED
@@ -3,6 +3,103 @@ import { forwardRef, useRef, useState, useEffect, useImperativeHandle, useCallba
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
4
  import ReactDOM from 'react-dom';
5
5
 
6
+ // ../shared/src/time/timeframeRegistry.ts
7
+ function isCalendarTimeframe(key) {
8
+ return key === "1w" || key === "1M" || key === "3M" || key === "6M" || key === "12M";
9
+ }
10
+ function isTickTimeframe(key) {
11
+ return /^\d+t$/i.test(key);
12
+ }
13
+
14
+ // ../shared/src/time/timeUtils.ts
15
+ var MONDAY_EPOCH_OFFSET_MS = 3456e5;
16
+ var WEEK_MS = 6048e5;
17
+ function timeframeToMs(tf) {
18
+ if (isCalendarTimeframe(tf)) return null;
19
+ if (isTickTimeframe(tf)) return null;
20
+ const secs = parseTfSeconds(tf);
21
+ return secs !== null ? secs * 1e3 : null;
22
+ }
23
+ function parseTfSeconds(tf) {
24
+ const m = /^(\d+)(s|m|h|d|w|M)$/.exec(tf);
25
+ if (!m) return null;
26
+ const n = parseInt(m[1], 10);
27
+ const unit = m[2];
28
+ const UNIT_SECONDS = {
29
+ s: 1,
30
+ m: 60,
31
+ h: 3600,
32
+ d: 86400,
33
+ w: 604800,
34
+ M: 2592e3
35
+ };
36
+ const unitSec = UNIT_SECONDS[unit];
37
+ return unitSec !== void 0 ? n * unitSec : null;
38
+ }
39
+ function getBucketStart(timeMs, timeframe) {
40
+ if (timeframe === "1w") return getWeekBucketStart(timeMs);
41
+ if (timeframe === "1M") return getMonthBucketStart(timeMs);
42
+ if (timeframe === "3M") return getQuarterBucketStart(timeMs);
43
+ if (timeframe === "6M") return getHalfYearBucketStart(timeMs);
44
+ if (timeframe === "12M") return getYearBucketStart(timeMs);
45
+ const secs = parseTfSeconds(timeframe);
46
+ if (secs && secs > 0) return Math.floor(timeMs / (secs * 1e3)) * (secs * 1e3);
47
+ return Math.floor(timeMs / 6e4) * 6e4;
48
+ }
49
+ function getWeekBucketStart(timeMs) {
50
+ return Math.floor((timeMs - MONDAY_EPOCH_OFFSET_MS) / WEEK_MS) * WEEK_MS + MONDAY_EPOCH_OFFSET_MS;
51
+ }
52
+ function getMonthBucketStart(timeMs) {
53
+ const d = new Date(timeMs);
54
+ return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1);
55
+ }
56
+ function getQuarterBucketStart(timeMs) {
57
+ const d = new Date(timeMs);
58
+ const quarterMonth = Math.floor(d.getUTCMonth() / 3) * 3;
59
+ return Date.UTC(d.getUTCFullYear(), quarterMonth, 1);
60
+ }
61
+ function getHalfYearBucketStart(timeMs) {
62
+ const d = new Date(timeMs);
63
+ const halfMonth = d.getUTCMonth() < 6 ? 0 : 6;
64
+ return Date.UTC(d.getUTCFullYear(), halfMonth, 1);
65
+ }
66
+ function getYearBucketStart(timeMs) {
67
+ return Date.UTC(new Date(timeMs).getUTCFullYear(), 0, 1);
68
+ }
69
+
70
+ // ../shared/src/marketHours.ts
71
+ function isGLBXWeekend(nowMs = Date.now()) {
72
+ const d = new Date(nowMs);
73
+ const day = d.getUTCDay();
74
+ const hour = d.getUTCHours();
75
+ if (day === 6) return true;
76
+ if (day === 0 && hour < 22) return true;
77
+ if (day === 5 && hour >= 21) return true;
78
+ return false;
79
+ }
80
+ function centralParts(nowMs) {
81
+ const parts = new Intl.DateTimeFormat("en-US", {
82
+ timeZone: "America/Chicago",
83
+ weekday: "short",
84
+ hour: "2-digit",
85
+ minute: "2-digit",
86
+ // h23 rather than hour12:false — the latter yields '24' for midnight in
87
+ // some ICU builds, which would parse as an hour that never matches.
88
+ hourCycle: "h23"
89
+ }).formatToParts(new Date(nowMs));
90
+ const get = (t) => parts.find((p) => p.type === t)?.value ?? "";
91
+ return {
92
+ weekday: get("weekday"),
93
+ hour: parseInt(get("hour"), 10),
94
+ minute: parseInt(get("minute"), 10)
95
+ };
96
+ }
97
+ function isGLBXDailyBreak(nowMs = Date.now()) {
98
+ const { weekday, hour } = centralParts(nowMs);
99
+ if (hour !== 16) return false;
100
+ return weekday === "Mon" || weekday === "Tue" || weekday === "Wed" || weekday === "Thu";
101
+ }
102
+
6
103
  // src/core/CanvasLayer.ts
7
104
  var CanvasLayer = class {
8
105
  canvas;
@@ -96,81 +193,6 @@ function computeTicks(min, max, targetCount) {
96
193
  return ticks;
97
194
  }
98
195
 
99
- // ../shared/src/time/timeframeRegistry.ts
100
- function isCalendarTimeframe(key) {
101
- return key === "1w" || key === "1M" || key === "3M" || key === "6M" || key === "12M";
102
- }
103
- function isTickTimeframe(key) {
104
- return /^\d+t$/i.test(key);
105
- }
106
-
107
- // ../shared/src/time/timeUtils.ts
108
- var MONDAY_EPOCH_OFFSET_MS = 3456e5;
109
- var WEEK_MS = 6048e5;
110
- function timeframeToMs(tf) {
111
- if (isCalendarTimeframe(tf)) return null;
112
- if (isTickTimeframe(tf)) return null;
113
- const secs = parseTfSeconds(tf);
114
- return secs !== null ? secs * 1e3 : null;
115
- }
116
- function parseTfSeconds(tf) {
117
- const m = /^(\d+)(s|m|h|d|w|M)$/.exec(tf);
118
- if (!m) return null;
119
- const n = parseInt(m[1], 10);
120
- const unit = m[2];
121
- const UNIT_SECONDS = {
122
- s: 1,
123
- m: 60,
124
- h: 3600,
125
- d: 86400,
126
- w: 604800,
127
- M: 2592e3
128
- };
129
- const unitSec = UNIT_SECONDS[unit];
130
- return unitSec !== void 0 ? n * unitSec : null;
131
- }
132
- function getBucketStart(timeMs, timeframe) {
133
- if (timeframe === "1w") return getWeekBucketStart(timeMs);
134
- if (timeframe === "1M") return getMonthBucketStart(timeMs);
135
- if (timeframe === "3M") return getQuarterBucketStart(timeMs);
136
- if (timeframe === "6M") return getHalfYearBucketStart(timeMs);
137
- if (timeframe === "12M") return getYearBucketStart(timeMs);
138
- const secs = parseTfSeconds(timeframe);
139
- if (secs && secs > 0) return Math.floor(timeMs / (secs * 1e3)) * (secs * 1e3);
140
- return Math.floor(timeMs / 6e4) * 6e4;
141
- }
142
- function getWeekBucketStart(timeMs) {
143
- return Math.floor((timeMs - MONDAY_EPOCH_OFFSET_MS) / WEEK_MS) * WEEK_MS + MONDAY_EPOCH_OFFSET_MS;
144
- }
145
- function getMonthBucketStart(timeMs) {
146
- const d = new Date(timeMs);
147
- return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1);
148
- }
149
- function getQuarterBucketStart(timeMs) {
150
- const d = new Date(timeMs);
151
- const quarterMonth = Math.floor(d.getUTCMonth() / 3) * 3;
152
- return Date.UTC(d.getUTCFullYear(), quarterMonth, 1);
153
- }
154
- function getHalfYearBucketStart(timeMs) {
155
- const d = new Date(timeMs);
156
- const halfMonth = d.getUTCMonth() < 6 ? 0 : 6;
157
- return Date.UTC(d.getUTCFullYear(), halfMonth, 1);
158
- }
159
- function getYearBucketStart(timeMs) {
160
- return Date.UTC(new Date(timeMs).getUTCFullYear(), 0, 1);
161
- }
162
-
163
- // ../shared/src/marketHours.ts
164
- function isGLBXWeekend(nowMs = Date.now()) {
165
- const d = new Date(nowMs);
166
- const day = d.getUTCDay();
167
- const hour = d.getUTCHours();
168
- if (day === 6) return true;
169
- if (day === 0 && hour < 22) return true;
170
- if (day === 5 && hour >= 21) return true;
171
- return false;
172
- }
173
-
174
196
  // ../utils/src/time.ts
175
197
  function parseTimeframeSeconds(tf) {
176
198
  return parseTfSeconds(tf);
@@ -5189,7 +5211,7 @@ var Chart = class {
5189
5211
  const tfSecs = _tfToSeconds(this._interval);
5190
5212
  const now = Math.floor(exchangeNow() / 1e3);
5191
5213
  const remaining = tfSecs - now % tfSecs;
5192
- const showCd = this._options.showCountdown !== false;
5214
+ const showCd = this._options.showCountdown !== false && !isGLBXDailyBreak(now * 1e3);
5193
5215
  const priceLabel = _formatLastPrice(price, this._options.pricePrecision);
5194
5216
  const lineH = 15;
5195
5217
  const boxH = showCd ? lineH * 2 + 1 : lineH;
@@ -7721,9 +7743,10 @@ var PixiLastPriceRenderer = class {
7721
7743
  cx += dashLen + gapLen;
7722
7744
  }
7723
7745
  this._lineGfx.stroke();
7724
- const showCd = this.showCountdown;
7725
- const tfSecs = tfToSeconds(interval);
7726
7746
  const now = Math.floor(exchangeNow() / 1e3);
7747
+ const halted = isGLBXDailyBreak(now * 1e3);
7748
+ const showCd = this.showCountdown && !halted;
7749
+ const tfSecs = tfToSeconds(interval);
7727
7750
  const remaining = tfSecs - now % tfSecs;
7728
7751
  this._lastSec = now;
7729
7752
  const lineH = 15;
@@ -19991,7 +20014,7 @@ function LeftToolbar({ activeTool, onSelectTool, drawingFavorites, onDrawingFavo
19991
20014
  /* @__PURE__ */ jsx(
19992
20015
  MagnetTool,
19993
20016
  {
19994
- mode: magnetMode ?? "snap-xy",
20017
+ mode: magnetMode ?? "snap-x",
19995
20018
  ...onMagnetModeChange ? { onChange: onMagnetModeChange } : {}
19996
20019
  }
19997
20020
  ),
@@ -23022,7 +23045,7 @@ var ChartCanvas = forwardRef(
23022
23045
  const [indicators, setIndicators] = useState([]);
23023
23046
  const [totalHeight, setTotalHeight] = useState(600);
23024
23047
  const [activeTool, setActiveTool] = useState(initialActiveTool ?? "cursor");
23025
- const [magnetMode, setMagnetMode] = useState(initialMagnetMode ?? "snap-xy");
23048
+ const [magnetMode, setMagnetMode] = useState(initialMagnetMode ?? "snap-x");
23026
23049
  const [drawingFavorites, setDrawingFavorites] = useState(drawingFavoritesProp ?? []);
23027
23050
  const [ctxMenu, setCtxMenu] = useState(null);
23028
23051
  const [chartCtxMenu, setChartCtxMenu] = useState(null);
@@ -23302,7 +23325,7 @@ var ChartCanvas = forwardRef(
23302
23325
  const initTool = initialActiveTool ?? "cursor";
23303
23326
  chart.setCrosshairEnabled(initTool === "crosshair");
23304
23327
  chart.setNativeCursorHidden(initTool !== "cursor");
23305
- chart.setMagnetMode(initialMagnetMode ?? "snap-xy");
23328
+ chart.setMagnetMode(initialMagnetMode ?? "snap-x");
23306
23329
  syncChartState();
23307
23330
  return () => {
23308
23331
  chart.destroy();