@tradecanvas/chart 0.4.0 → 0.6.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/README.md +120 -9
- package/dist/Chart-CrrTKx3r.js +1027 -0
- package/dist/Chart-CrrTKx3r.js.map +1 -0
- package/dist/Chart-DoR8L8Uk.cjs +2 -0
- package/dist/Chart-DoR8L8Uk.cjs.map +1 -0
- package/dist/Chart.d.ts +22 -8
- package/dist/Chart.d.ts.map +1 -1
- package/dist/charts/ChartTypeStrategy.d.ts +18 -0
- package/dist/charts/ChartTypeStrategy.d.ts.map +1 -0
- package/dist/charts/IndicatorPriceRange.d.ts +16 -0
- package/dist/charts/IndicatorPriceRange.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1010
- package/dist/index.js.map +1 -1
- package/dist/state/AutoSaveScheduler.d.ts +26 -0
- package/dist/state/AutoSaveScheduler.d.ts.map +1 -0
- package/dist/widget/ChartWidget.d.ts +43 -0
- package/dist/widget/ChartWidget.d.ts.map +1 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts +19 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts.map +1 -0
- package/dist/widget/WidgetDropdown.d.ts +18 -0
- package/dist/widget/WidgetDropdown.d.ts.map +1 -0
- package/dist/widget/WidgetSettings.d.ts +25 -0
- package/dist/widget/WidgetSettings.d.ts.map +1 -0
- package/dist/widget/WidgetStatusBar.d.ts +15 -0
- package/dist/widget/WidgetStatusBar.d.ts.map +1 -0
- package/dist/widget/WidgetStyles.d.ts +9 -0
- package/dist/widget/WidgetStyles.d.ts.map +1 -0
- package/dist/widget/WidgetToolbar.d.ts +22 -0
- package/dist/widget/WidgetToolbar.d.ts.map +1 -0
- package/dist/widget/icons.d.ts +2 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/widget/index.cjs +740 -0
- package/dist/widget/index.cjs.map +1 -0
- package/dist/widget/index.d.ts +3 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +1058 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/types.d.ts +105 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/dist/widget/widgetConfig.d.ts +16 -0
- package/dist/widget/widgetConfig.d.ts.map +1 -0
- package/package.json +14 -4
|
@@ -0,0 +1,1058 @@
|
|
|
1
|
+
import { t as e } from "../Chart-CrrTKx3r.js";
|
|
2
|
+
import { DARK_THEME as t, LIGHT_THEME as n } from "@tradecanvas/commons";
|
|
3
|
+
//#region src/widget/widgetConfig.ts
|
|
4
|
+
var r = [
|
|
5
|
+
{
|
|
6
|
+
label: "1m",
|
|
7
|
+
value: "1m"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
label: "5m",
|
|
11
|
+
value: "5m"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
label: "15m",
|
|
15
|
+
value: "15m"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: "1H",
|
|
19
|
+
value: "1h"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: "4H",
|
|
23
|
+
value: "4h"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: "1D",
|
|
27
|
+
value: "1d"
|
|
28
|
+
}
|
|
29
|
+
], i = [
|
|
30
|
+
{
|
|
31
|
+
label: "Candlestick",
|
|
32
|
+
value: "candlestick"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: "Line",
|
|
36
|
+
value: "line"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: "Area",
|
|
40
|
+
value: "area"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: "Bar",
|
|
44
|
+
value: "bar"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: "Heikin-Ashi",
|
|
48
|
+
value: "heikinAshi"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
label: "Hollow Candle",
|
|
52
|
+
value: "hollowCandle"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: "Baseline",
|
|
56
|
+
value: "baseline"
|
|
57
|
+
}
|
|
58
|
+
], a = [
|
|
59
|
+
{
|
|
60
|
+
label: "Lines",
|
|
61
|
+
tools: [
|
|
62
|
+
{
|
|
63
|
+
label: "Trend Line",
|
|
64
|
+
value: "trendLine"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: "Ray",
|
|
68
|
+
value: "ray"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
label: "Extended Line",
|
|
72
|
+
value: "extendedLine"
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: "Horizontal/Vertical",
|
|
78
|
+
tools: [{
|
|
79
|
+
label: "Horizontal Line",
|
|
80
|
+
value: "horizontalLine"
|
|
81
|
+
}, {
|
|
82
|
+
label: "Vertical Line",
|
|
83
|
+
value: "verticalLine"
|
|
84
|
+
}]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
label: "Channels",
|
|
88
|
+
tools: [{
|
|
89
|
+
label: "Parallel Channel",
|
|
90
|
+
value: "parallelChannel"
|
|
91
|
+
}, {
|
|
92
|
+
label: "Regression Channel",
|
|
93
|
+
value: "regressionChannel"
|
|
94
|
+
}]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: "Fibonacci",
|
|
98
|
+
tools: [{
|
|
99
|
+
label: "Fib Retracement",
|
|
100
|
+
value: "fibRetracement"
|
|
101
|
+
}, {
|
|
102
|
+
label: "Fib Extension",
|
|
103
|
+
value: "fibExtension"
|
|
104
|
+
}]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: "Shapes",
|
|
108
|
+
tools: [
|
|
109
|
+
{
|
|
110
|
+
label: "Rectangle",
|
|
111
|
+
value: "rectangle"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
label: "Ellipse",
|
|
115
|
+
value: "ellipse"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
label: "Triangle",
|
|
119
|
+
value: "triangle"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
label: "Gann & Advanced",
|
|
125
|
+
tools: [
|
|
126
|
+
{
|
|
127
|
+
label: "Pitchfork",
|
|
128
|
+
value: "pitchfork"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
label: "Gann Fan",
|
|
132
|
+
value: "gannFan"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
label: "Gann Box",
|
|
136
|
+
value: "gannBox"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
label: "Elliott Wave",
|
|
140
|
+
value: "elliottWave"
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
label: "Measure",
|
|
146
|
+
tools: [
|
|
147
|
+
{
|
|
148
|
+
label: "Price Range",
|
|
149
|
+
value: "priceRange"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
label: "Date Range",
|
|
153
|
+
value: "dateRange"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
label: "Measure",
|
|
157
|
+
value: "measure"
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
label: "Annotation",
|
|
163
|
+
tools: [{
|
|
164
|
+
label: "Text",
|
|
165
|
+
value: "text"
|
|
166
|
+
}, {
|
|
167
|
+
label: "Arrow",
|
|
168
|
+
value: "arrow"
|
|
169
|
+
}]
|
|
170
|
+
}
|
|
171
|
+
], o = [
|
|
172
|
+
{
|
|
173
|
+
id: "sma",
|
|
174
|
+
name: "SMA",
|
|
175
|
+
type: "overlay"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: "ema",
|
|
179
|
+
name: "EMA",
|
|
180
|
+
type: "overlay"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "bb",
|
|
184
|
+
name: "Bollinger Bands",
|
|
185
|
+
type: "overlay"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
id: "vwap",
|
|
189
|
+
name: "VWAP",
|
|
190
|
+
type: "overlay"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "ichimoku",
|
|
194
|
+
name: "Ichimoku Cloud",
|
|
195
|
+
type: "overlay"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: "psar",
|
|
199
|
+
name: "Parabolic SAR",
|
|
200
|
+
type: "overlay"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "supertrend",
|
|
204
|
+
name: "Supertrend",
|
|
205
|
+
type: "overlay"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: "keltner",
|
|
209
|
+
name: "Keltner Channel",
|
|
210
|
+
type: "overlay"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: "donchian",
|
|
214
|
+
name: "Donchian Channel",
|
|
215
|
+
type: "overlay"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
id: "rsi",
|
|
219
|
+
name: "RSI",
|
|
220
|
+
type: "panel"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "macd",
|
|
224
|
+
name: "MACD",
|
|
225
|
+
type: "panel"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "stochastic",
|
|
229
|
+
name: "Stochastic",
|
|
230
|
+
type: "panel"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
id: "atr",
|
|
234
|
+
name: "ATR",
|
|
235
|
+
type: "panel"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "adx",
|
|
239
|
+
name: "ADX",
|
|
240
|
+
type: "panel"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: "obv",
|
|
244
|
+
name: "OBV",
|
|
245
|
+
type: "panel"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: "williamsR",
|
|
249
|
+
name: "Williams %R",
|
|
250
|
+
type: "panel"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
id: "cci",
|
|
254
|
+
name: "CCI",
|
|
255
|
+
type: "panel"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
id: "mfi",
|
|
259
|
+
name: "MFI",
|
|
260
|
+
type: "panel"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "roc",
|
|
264
|
+
name: "ROC",
|
|
265
|
+
type: "panel"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "tsi",
|
|
269
|
+
name: "TSI",
|
|
270
|
+
type: "panel"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: "cmf",
|
|
274
|
+
name: "CMF",
|
|
275
|
+
type: "panel"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
id: "aroon",
|
|
279
|
+
name: "Aroon",
|
|
280
|
+
type: "panel"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: "stddev",
|
|
284
|
+
name: "Std Deviation",
|
|
285
|
+
type: "panel"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: "vroc",
|
|
289
|
+
name: "Volume ROC",
|
|
290
|
+
type: "panel"
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: "ad",
|
|
294
|
+
name: "Acc/Dist",
|
|
295
|
+
type: "panel"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
id: "volumeProfile",
|
|
299
|
+
name: "Volume Profile",
|
|
300
|
+
type: "panel"
|
|
301
|
+
}
|
|
302
|
+
], s = [
|
|
303
|
+
"sma",
|
|
304
|
+
"ema",
|
|
305
|
+
"bb",
|
|
306
|
+
"rsi",
|
|
307
|
+
"macd",
|
|
308
|
+
"stochastic",
|
|
309
|
+
"vwap",
|
|
310
|
+
"atr",
|
|
311
|
+
"obv",
|
|
312
|
+
"ichimoku"
|
|
313
|
+
], c = [
|
|
314
|
+
"BTCUSDT",
|
|
315
|
+
"ETHUSDT",
|
|
316
|
+
"SOLUSDT",
|
|
317
|
+
"BNBUSDT"
|
|
318
|
+
], l = {
|
|
319
|
+
candleUpColor: "#26A69A",
|
|
320
|
+
candleDownColor: "#EF5350",
|
|
321
|
+
candleUpWick: "#26A69A",
|
|
322
|
+
candleDownWick: "#EF5350",
|
|
323
|
+
backgroundColor: "#131722",
|
|
324
|
+
gridColor: "#1E222D",
|
|
325
|
+
gridVisible: !0,
|
|
326
|
+
volumeVisible: !0,
|
|
327
|
+
legendVisible: !0,
|
|
328
|
+
barCountdown: !0,
|
|
329
|
+
logScale: !1,
|
|
330
|
+
autoScale: !0,
|
|
331
|
+
crosshairMode: "magnet",
|
|
332
|
+
numberLocale: "en-US"
|
|
333
|
+
}, u = "/* === TradeCanvas Widget Styles === */\n\n.tcw-root {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;\n font-size: 13px;\n color: #d1d4dc;\n background: #131722;\n position: relative;\n overflow: hidden;\n\n /* Dark theme tokens (default) */\n --tcw-bg: #131722;\n --tcw-bg-elevated: #1E222D;\n --tcw-border: #2A2E39;\n --tcw-text: #d1d4dc;\n --tcw-text-dim: #b2b5be;\n --tcw-text-muted: #787b86;\n --tcw-accent: #2962ff;\n --tcw-accent-dim: rgba(41,98,255,0.15);\n --tcw-accent-glow: rgba(41,98,255,0.12);\n --tcw-red: #ef5350;\n --tcw-green: #26a69a;\n --tcw-transition: 0.15s ease;\n --tcw-radius-lg: 8px;\n --tcw-font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;\n --tcw-hover-bg: rgba(255,255,255,0.04);\n}\n\n.tcw-root[data-tcw-theme=\"light\"] {\n color: #131722;\n background: #ffffff;\n\n --tcw-bg: #ffffff;\n --tcw-bg-elevated: #f0f3fa;\n --tcw-border: #e0e3eb;\n --tcw-text: #131722;\n --tcw-text-dim: #434651;\n --tcw-text-muted: #787b86;\n --tcw-accent: #2962ff;\n --tcw-accent-dim: rgba(41,98,255,0.1);\n --tcw-accent-glow: rgba(41,98,255,0.08);\n --tcw-red: #ef5350;\n --tcw-green: #26a69a;\n --tcw-hover-bg: rgba(0,0,0,0.04);\n}\n\n/* === Toolbar === */\n\n.tcw-toolbar {\n display: flex;\n align-items: center;\n gap: 0;\n padding: 0 12px;\n height: 40px;\n border-bottom: 1px solid var(--tcw-border);\n background: var(--tcw-bg-elevated);\n flex-shrink: 0;\n position: relative;\n z-index: 20;\n}\n\n.tcw-toolbar-symbol {\n font-size: 13px;\n font-weight: 700;\n color: var(--tcw-text);\n padding: 0 10px;\n white-space: nowrap;\n letter-spacing: -0.01em;\n cursor: pointer;\n border: none;\n background: none;\n font-family: inherit;\n}\n\n.tcw-toolbar-sep {\n width: 1px;\n height: 20px;\n background: var(--tcw-border);\n flex-shrink: 0;\n}\n\n.tcw-toolbar-group {\n display: flex;\n align-items: center;\n gap: 2px;\n padding: 0 8px;\n}\n\n.tcw-toolbar-spacer {\n flex: 1;\n}\n\n.tcw-btn {\n padding: 4px 8px;\n font-size: 12px;\n font-family: inherit;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--tcw-text-dim);\n cursor: pointer;\n transition: all var(--tcw-transition);\n white-space: nowrap;\n line-height: 1;\n}\n\n.tcw-btn:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-btn.tcw-active {\n background: var(--tcw-accent);\n color: white;\n}\n\n.tcw-btn-icon {\n width: 32px;\n height: 32px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n font-family: inherit;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--tcw-text-muted);\n cursor: pointer;\n transition: all var(--tcw-transition);\n line-height: 1;\n position: relative;\n}\n\n.tcw-btn-icon:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-badge-count {\n font-size: 10px;\n color: var(--tcw-accent);\n background: var(--tcw-accent-dim);\n padding: 0 4px;\n border-radius: 8px;\n font-weight: 600;\n}\n\n.tcw-indicator-chips {\n display: flex;\n align-items: center;\n gap: 4px;\n padding: 0 4px;\n flex-wrap: nowrap;\n overflow: hidden;\n}\n\n.tcw-indicator-chip {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n padding: 2px 6px 2px 8px;\n font-size: 11px;\n font-weight: 500;\n background: var(--tcw-accent-dim);\n color: var(--tcw-accent);\n border-radius: 4px;\n white-space: nowrap;\n line-height: 1.4;\n}\n\n.tcw-chip-remove {\n cursor: pointer;\n opacity: 0.6;\n padding: 0 2px;\n transition: opacity var(--tcw-transition);\n border: none;\n background: none;\n color: inherit;\n display: inline-flex;\n align-items: center;\n}\n\n.tcw-chip-remove:hover {\n opacity: 1;\n}\n\n/* === Dropdown === */\n\n.tcw-dropdown-trigger {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n padding: 4px 8px;\n font-size: 12px;\n font-family: inherit;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--tcw-text-dim);\n cursor: pointer;\n transition: all var(--tcw-transition);\n white-space: nowrap;\n line-height: 1;\n}\n\n.tcw-dropdown-trigger:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-dropdown {\n position: absolute;\n top: 100%;\n margin-top: 4px;\n background: var(--tcw-bg-elevated);\n border: 1px solid var(--tcw-border);\n border-radius: var(--tcw-radius-lg);\n box-shadow: 0 8px 32px rgba(0,0,0,0.4);\n z-index: 50;\n padding: 4px 0;\n max-height: 400px;\n overflow-y: auto;\n}\n\n.tcw-dropdown-item {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 6px 12px;\n font-size: 12px;\n color: var(--tcw-text-dim);\n cursor: pointer;\n transition: background var(--tcw-transition), color var(--tcw-transition);\n width: 100%;\n border: none;\n background: none;\n font-family: inherit;\n text-align: left;\n}\n\n.tcw-dropdown-item:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-dropdown-item.tcw-active {\n color: var(--tcw-accent);\n}\n\n.tcw-dropdown-label {\n text-transform: uppercase;\n font-size: 10px;\n color: var(--tcw-text-muted);\n letter-spacing: 0.05em;\n padding: 6px 12px;\n font-weight: 600;\n}\n\n.tcw-dropdown-divider {\n border-top: 1px solid var(--tcw-border);\n margin: 4px 0;\n}\n\n.tcw-tag {\n font-size: 10px;\n color: var(--tcw-text-muted);\n padding: 1px 5px;\n border-radius: 3px;\n background: var(--tcw-hover-bg);\n}\n\n/* === Body === */\n\n.tcw-body {\n display: flex;\n flex: 1;\n min-height: 0;\n}\n\n.tcw-chart-container {\n flex: 1;\n min-width: 0;\n min-height: 0;\n width: 100%;\n height: 100%;\n}\n\n/* === Sidebar === */\n\n.tcw-sidebar {\n width: 36px;\n flex-shrink: 0;\n background: var(--tcw-bg-elevated);\n border-right: 1px solid var(--tcw-border);\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 4px 0;\n overflow: visible;\n}\n\n.tcw-tool-group-wrap {\n position: relative;\n}\n\n.tcw-sidebar-btn {\n width: 36px;\n height: 32px;\n display: flex;\n align-items: center;\n justify-content: center;\n border: none;\n background: transparent;\n color: var(--tcw-text-muted);\n cursor: pointer;\n font-family: inherit;\n transition: all var(--tcw-transition);\n position: relative;\n flex-shrink: 0;\n line-height: 1;\n}\n\n.tcw-sidebar-btn:hover {\n color: var(--tcw-text);\n background: var(--tcw-hover-bg);\n}\n\n.tcw-sidebar-btn.tcw-active {\n color: var(--tcw-accent);\n background: var(--tcw-accent-glow);\n}\n\n.tcw-sidebar-btn.tcw-danger:hover {\n color: var(--tcw-red);\n background: rgba(239,68,68,0.1);\n}\n\n.tcw-multi-dot {\n position: absolute;\n bottom: 2px;\n right: 2px;\n width: 4px;\n height: 4px;\n border-radius: 50%;\n background: var(--tcw-text-muted);\n}\n\n.tcw-sidebar-divider {\n width: 20px;\n height: 1px;\n background: var(--tcw-border);\n margin: 4px 0;\n flex-shrink: 0;\n}\n\n.tcw-sidebar-spacer {\n flex: 1;\n}\n\n/* === Flyout === */\n\n.tcw-flyout {\n position: absolute;\n left: 100%;\n top: 0;\n margin-left: 2px;\n min-width: 160px;\n background: var(--tcw-bg-elevated);\n border: 1px solid var(--tcw-border);\n border-radius: var(--tcw-radius-lg);\n box-shadow: 0 8px 32px rgba(0,0,0,0.4);\n z-index: 30;\n padding: 4px 0;\n}\n\n.tcw-flyout-header {\n text-transform: uppercase;\n font-size: 10px;\n color: var(--tcw-text-muted);\n letter-spacing: 0.05em;\n padding: 6px 12px;\n font-weight: 600;\n}\n\n.tcw-flyout-item {\n padding: 6px 12px;\n font-size: 12px;\n color: var(--tcw-text-dim);\n cursor: pointer;\n width: 100%;\n display: block;\n border: none;\n background: none;\n text-align: left;\n font-family: inherit;\n transition: background var(--tcw-transition), color var(--tcw-transition);\n}\n\n.tcw-flyout-item:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-flyout-item.tcw-active {\n color: var(--tcw-accent);\n}\n\n/* === Modal === */\n\n.tcw-modal-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0,0,0,0.5);\n backdrop-filter: blur(4px);\n -webkit-backdrop-filter: blur(4px);\n z-index: 100;\n}\n\n.tcw-modal {\n position: fixed;\n z-index: 101;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background: var(--tcw-bg-elevated);\n border: 1px solid var(--tcw-border);\n border-radius: var(--tcw-radius-lg);\n width: 480px;\n max-width: 90vw;\n max-height: 80vh;\n display: flex;\n flex-direction: column;\n box-shadow: 0 24px 64px rgba(0,0,0,0.5);\n}\n\n.tcw-modal-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 16px 20px;\n border-bottom: 1px solid var(--tcw-border);\n}\n\n.tcw-modal-header h3 {\n font-size: 15px;\n font-weight: 600;\n margin: 0;\n color: var(--tcw-text);\n}\n\n.tcw-modal-close {\n width: 28px;\n height: 28px;\n display: flex;\n align-items: center;\n justify-content: center;\n border: none;\n background: transparent;\n color: var(--tcw-text-muted);\n cursor: pointer;\n border-radius: 4px;\n transition: all var(--tcw-transition);\n}\n\n.tcw-modal-close:hover {\n background: var(--tcw-hover-bg);\n color: var(--tcw-text);\n}\n\n.tcw-modal-tabs {\n display: flex;\n gap: 0;\n padding: 0 20px;\n border-bottom: 1px solid var(--tcw-border);\n}\n\n.tcw-modal-tab {\n padding: 10px 16px;\n font-size: 12px;\n font-weight: 500;\n color: var(--tcw-text-muted);\n border: none;\n background: none;\n cursor: pointer;\n border-bottom: 2px solid transparent;\n margin-bottom: -1px;\n transition: color var(--tcw-transition);\n font-family: inherit;\n text-transform: capitalize;\n}\n\n.tcw-modal-tab:hover {\n color: var(--tcw-text-dim);\n}\n\n.tcw-modal-tab.tcw-active {\n color: var(--tcw-accent);\n border-bottom-color: var(--tcw-accent);\n}\n\n.tcw-modal-body {\n padding: 20px;\n overflow-y: auto;\n flex: 1;\n}\n\n.tcw-settings-section {\n margin-bottom: 20px;\n}\n\n.tcw-settings-section:last-child {\n margin-bottom: 0;\n}\n\n.tcw-settings-section-title {\n font-size: 11px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n color: var(--tcw-text-muted);\n margin-bottom: 12px;\n}\n\n.tcw-settings-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 0;\n}\n\n.tcw-settings-row + .tcw-settings-row {\n border-top: 1px solid rgba(255,255,255,0.03);\n}\n\n.tcw-root[data-tcw-theme=\"light\"] .tcw-settings-row + .tcw-settings-row {\n border-top: 1px solid rgba(0,0,0,0.04);\n}\n\n.tcw-settings-label {\n font-size: 13px;\n color: var(--tcw-text-dim);\n}\n\n.tcw-color-picker-wrap {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tcw-color-picker-wrap input[type='color'] {\n width: 28px;\n height: 28px;\n border: 1px solid var(--tcw-border);\n border-radius: 4px;\n background: none;\n cursor: pointer;\n padding: 2px;\n}\n\n.tcw-color-picker-wrap input[type='color']::-webkit-color-swatch-wrapper {\n padding: 0;\n}\n\n.tcw-color-picker-wrap input[type='color']::-webkit-color-swatch {\n border: none;\n border-radius: 2px;\n}\n\n.tcw-color-hex {\n font-size: 11px;\n font-family: var(--tcw-font-mono);\n color: var(--tcw-text-muted);\n min-width: 60px;\n}\n\n.tcw-toggle {\n width: 36px;\n height: 20px;\n background: rgba(255,255,255,0.1);\n border-radius: 10px;\n position: relative;\n cursor: pointer;\n transition: background var(--tcw-transition);\n border: none;\n padding: 0;\n flex-shrink: 0;\n}\n\n.tcw-toggle::after {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: 16px;\n height: 16px;\n border-radius: 50%;\n background: var(--tcw-text-muted);\n transition: all var(--tcw-transition);\n}\n\n.tcw-toggle.tcw-on {\n background: var(--tcw-accent);\n}\n\n.tcw-toggle.tcw-on::after {\n left: 18px;\n background: white;\n}\n\n.tcw-root[data-tcw-theme=\"light\"] .tcw-toggle {\n background: rgba(0,0,0,0.1);\n}\n\n.tcw-root[data-tcw-theme=\"light\"] .tcw-toggle::after {\n background: #888;\n}\n\n.tcw-root[data-tcw-theme=\"light\"] .tcw-toggle.tcw-on {\n background: var(--tcw-accent);\n}\n\n.tcw-root[data-tcw-theme=\"light\"] .tcw-toggle.tcw-on::after {\n background: white;\n}\n\n.tcw-settings-select {\n padding: 4px 8px;\n font-size: 12px;\n font-family: inherit;\n background: var(--tcw-bg);\n border: 1px solid var(--tcw-border);\n border-radius: 4px;\n color: var(--tcw-text);\n cursor: pointer;\n}\n\n.tcw-modal-footer {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 12px 20px;\n border-top: 1px solid var(--tcw-border);\n}\n\n.tcw-reset-link {\n font-size: 12px;\n color: var(--tcw-text-muted);\n cursor: pointer;\n border: none;\n background: none;\n font-family: inherit;\n text-decoration: underline;\n text-underline-offset: 2px;\n transition: color var(--tcw-transition);\n}\n\n.tcw-reset-link:hover {\n color: var(--tcw-text-dim);\n}\n\n.tcw-done-btn {\n padding: 6px 16px;\n font-size: 12px;\n font-weight: 500;\n background: var(--tcw-accent);\n color: white;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n font-family: inherit;\n transition: background var(--tcw-transition);\n}\n\n.tcw-done-btn:hover {\n background: #2563eb;\n}\n\n/* === Status Bar === */\n\n.tcw-statusbar {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 6px 16px;\n border-top: 1px solid var(--tcw-border);\n background: var(--tcw-bg-elevated);\n font-size: 11px;\n color: var(--tcw-text-muted);\n flex-shrink: 0;\n}\n\n.tcw-status-indicator {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tcw-status-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: var(--tcw-text-muted);\n transition: background 0.3s;\n}\n\n.tcw-status-dot.tcw-connected {\n background: var(--tcw-green);\n}\n\n.tcw-status-dot.tcw-error {\n background: var(--tcw-red);\n}\n\n/* === Responsive === */\n\n@media (max-width: 768px) {\n .tcw-toolbar {\n padding: 0 8px;\n height: 36px;\n }\n .tcw-toolbar-sep {\n display: none;\n }\n .tcw-indicator-chips {\n display: none;\n }\n .tcw-sidebar {\n width: 32px;\n }\n .tcw-sidebar-btn {\n width: 32px;\n height: 28px;\n }\n}\n", d = 0, f = "tcw-styles";
|
|
334
|
+
function p() {
|
|
335
|
+
if (d++, d > 1 || document.getElementById(f)) return;
|
|
336
|
+
let e = document.createElement("style");
|
|
337
|
+
e.id = f, e.textContent = u, document.head.appendChild(e);
|
|
338
|
+
}
|
|
339
|
+
function m() {
|
|
340
|
+
if (d--, d > 0) return;
|
|
341
|
+
let e = document.getElementById(f);
|
|
342
|
+
e && e.remove();
|
|
343
|
+
}
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/widget/icons.ts
|
|
346
|
+
var h = {
|
|
347
|
+
cursor: "<path d=\"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z\"/><path d=\"M13 13l6 6\"/>",
|
|
348
|
+
trendingUp: "<polyline points=\"22 7 13.5 15.5 8.5 10.5 2 17\"/><polyline points=\"16 7 22 7 22 13\"/>",
|
|
349
|
+
minus: "<path d=\"M5 12h14\"/>",
|
|
350
|
+
penLine: "<path d=\"M12 20h9\"/><path d=\"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z\"/>",
|
|
351
|
+
hash: "<line x1=\"4\" y1=\"9\" x2=\"20\" y2=\"9\"/><line x1=\"4\" y1=\"15\" x2=\"20\" y2=\"15\"/><line x1=\"10\" y1=\"3\" x2=\"8\" y2=\"21\"/><line x1=\"16\" y1=\"3\" x2=\"14\" y2=\"21\"/>",
|
|
352
|
+
square: "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\"/>",
|
|
353
|
+
gitBranch: "<line x1=\"6\" y1=\"3\" x2=\"6\" y2=\"15\"/><circle cx=\"18\" cy=\"6\" r=\"3\"/><circle cx=\"6\" cy=\"18\" r=\"3\"/><path d=\"M18 9a9 9 0 0 1-9 9\"/>",
|
|
354
|
+
ruler: "<path d=\"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z\"/><path d=\"m14.5 12.5 2-2\"/><path d=\"m11.5 9.5 2-2\"/><path d=\"m8.5 6.5 2-2\"/><path d=\"m17.5 15.5 2-2\"/>",
|
|
355
|
+
type: "<polyline points=\"4 7 4 4 20 4 20 7\"/><line x1=\"9\" y1=\"20\" x2=\"15\" y2=\"20\"/><line x1=\"12\" y1=\"4\" x2=\"12\" y2=\"20\"/>",
|
|
356
|
+
magnet: "<path d=\"m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15\"/><path d=\"m5 8 4 4\"/><path d=\"m12 15 4 4\"/>",
|
|
357
|
+
undo: "<path d=\"M3 7v6h6\"/><path d=\"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13\"/>",
|
|
358
|
+
redo: "<path d=\"M21 7v6h-6\"/><path d=\"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3L21 13\"/>",
|
|
359
|
+
trash: "<path d=\"M3 6h18\"/><path d=\"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6\"/><path d=\"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2\"/><line x1=\"10\" y1=\"11\" x2=\"10\" y2=\"17\"/><line x1=\"14\" y1=\"11\" x2=\"14\" y2=\"17\"/>",
|
|
360
|
+
camera: "<path d=\"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z\"/><circle cx=\"12\" cy=\"13\" r=\"3\"/>",
|
|
361
|
+
settings: "<path d=\"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>",
|
|
362
|
+
moon: "<path d=\"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z\"/>",
|
|
363
|
+
sun: "<circle cx=\"12\" cy=\"12\" r=\"4\"/><path d=\"M12 2v2\"/><path d=\"M12 20v2\"/><path d=\"m4.93 4.93 1.41 1.41\"/><path d=\"m17.66 17.66 1.41 1.41\"/><path d=\"M2 12h2\"/><path d=\"M20 12h2\"/><path d=\"m6.34 17.66-1.41 1.41\"/><path d=\"m19.07 4.93-1.41 1.41\"/>",
|
|
364
|
+
chevronDown: "<path d=\"m6 9 6 6 6-6\"/>",
|
|
365
|
+
chevronUp: "<path d=\"m18 15-6-6-6 6\"/>",
|
|
366
|
+
barChart: "<line x1=\"12\" y1=\"20\" x2=\"12\" y2=\"10\"/><line x1=\"18\" y1=\"20\" x2=\"18\" y2=\"4\"/><line x1=\"6\" y1=\"20\" x2=\"6\" y2=\"16\"/>",
|
|
367
|
+
x: "<path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>",
|
|
368
|
+
play: "<polygon points=\"6 3 20 12 6 21 6 3\"/>",
|
|
369
|
+
pause: "<rect width=\"4\" height=\"16\" x=\"6\" y=\"4\"/><rect width=\"4\" height=\"16\" x=\"14\" y=\"4\"/>",
|
|
370
|
+
stop: "<rect width=\"14\" height=\"14\" x=\"5\" y=\"5\" rx=\"1\"/>",
|
|
371
|
+
receipt: "<path d=\"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z\"/><path d=\"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8\"/><path d=\"M12 17.5v-11\"/>"
|
|
372
|
+
};
|
|
373
|
+
function g(e, t = 14) {
|
|
374
|
+
let n = h[e];
|
|
375
|
+
return n ? `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${n}</svg>` : "";
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/widget/WidgetDropdown.ts
|
|
379
|
+
var _ = class {
|
|
380
|
+
trigger;
|
|
381
|
+
panel;
|
|
382
|
+
_isOpen = !1;
|
|
383
|
+
onOutsideClick;
|
|
384
|
+
onEscapeKey;
|
|
385
|
+
onTriggerClick;
|
|
386
|
+
constructor(e, t = {}) {
|
|
387
|
+
this.trigger = e, this.panel = document.createElement("div"), this.panel.className = "tcw-dropdown", this.panel.style.width = t.width ?? "200px", t.align === "right" ? this.panel.style.right = "0" : this.panel.style.left = "0", this.panel.style.display = "none", e.style.position = "relative", e.appendChild(this.panel), this.onTriggerClick = () => {
|
|
388
|
+
this._isOpen ? this.close() : this.open();
|
|
389
|
+
}, this.onOutsideClick = (e) => {
|
|
390
|
+
this.trigger.contains(e.target) || this.close();
|
|
391
|
+
}, this.onEscapeKey = (e) => {
|
|
392
|
+
e.key === "Escape" && this.close();
|
|
393
|
+
}, e.addEventListener("click", this.onTriggerClick);
|
|
394
|
+
}
|
|
395
|
+
setContent(e) {
|
|
396
|
+
this.panel.innerHTML = e;
|
|
397
|
+
}
|
|
398
|
+
open() {
|
|
399
|
+
this._isOpen || (this._isOpen = !0, this.panel.style.display = "", document.addEventListener("mousedown", this.onOutsideClick), document.addEventListener("keydown", this.onEscapeKey));
|
|
400
|
+
}
|
|
401
|
+
close() {
|
|
402
|
+
this._isOpen && (this._isOpen = !1, this.panel.style.display = "none", document.removeEventListener("mousedown", this.onOutsideClick), document.removeEventListener("keydown", this.onEscapeKey));
|
|
403
|
+
}
|
|
404
|
+
isOpen() {
|
|
405
|
+
return this._isOpen;
|
|
406
|
+
}
|
|
407
|
+
destroy() {
|
|
408
|
+
this.trigger.removeEventListener("click", this.onTriggerClick), document.removeEventListener("mousedown", this.onOutsideClick), document.removeEventListener("keydown", this.onEscapeKey), this.panel.remove();
|
|
409
|
+
}
|
|
410
|
+
}, v = class {
|
|
411
|
+
config;
|
|
412
|
+
callbacks;
|
|
413
|
+
el;
|
|
414
|
+
chartTypeDropdown = null;
|
|
415
|
+
indicatorDropdown = null;
|
|
416
|
+
tfButtons = [];
|
|
417
|
+
chipsContainer = null;
|
|
418
|
+
themeBtn = null;
|
|
419
|
+
constructor(e, t, n) {
|
|
420
|
+
this.config = t, this.callbacks = n, this.el = document.createElement("div"), this.el.className = "tcw-toolbar", this.build(), e.appendChild(this.el);
|
|
421
|
+
}
|
|
422
|
+
build() {
|
|
423
|
+
let { config: e, callbacks: t, el: n } = this, r = document.createElement("button");
|
|
424
|
+
r.className = "tcw-toolbar-symbol", r.dataset.role = "symbol", r.addEventListener("click", t.onSymbolClick), n.appendChild(r), n.appendChild(this.sep());
|
|
425
|
+
let i = document.createElement("div");
|
|
426
|
+
i.className = "tcw-toolbar-group";
|
|
427
|
+
for (let n of e.timeframes) {
|
|
428
|
+
let e = document.createElement("button");
|
|
429
|
+
e.className = "tcw-btn", e.textContent = n.label, e.dataset.tf = n.value, e.addEventListener("click", () => t.onTimeframe(n.value)), i.appendChild(e), this.tfButtons.push(e);
|
|
430
|
+
}
|
|
431
|
+
n.appendChild(i), n.appendChild(this.sep());
|
|
432
|
+
let a = document.createElement("div");
|
|
433
|
+
a.style.position = "relative", a.style.display = "inline-flex";
|
|
434
|
+
let o = document.createElement("button");
|
|
435
|
+
o.className = "tcw-dropdown-trigger", o.dataset.role = "charttype", a.appendChild(o), n.appendChild(a), this.chartTypeDropdown = new _(a, { width: "160px" }), this.buildChartTypeMenu(), n.appendChild(this.sep());
|
|
436
|
+
let s = document.createElement("div");
|
|
437
|
+
s.style.position = "relative", s.style.display = "inline-flex";
|
|
438
|
+
let c = document.createElement("button");
|
|
439
|
+
c.className = "tcw-dropdown-trigger", c.dataset.role = "indicators", s.appendChild(c), n.appendChild(s), this.indicatorDropdown = new _(s, { width: "280px" }), this.buildIndicatorMenu(), this.chipsContainer = document.createElement("div"), this.chipsContainer.className = "tcw-indicator-chips", n.appendChild(this.chipsContainer), n.appendChild(this.spacer());
|
|
440
|
+
let l = this.iconBtn("camera", "Screenshot", t.onScreenshot);
|
|
441
|
+
n.appendChild(l);
|
|
442
|
+
let u = this.iconBtn("settings", "Chart Settings", t.onSettings);
|
|
443
|
+
n.appendChild(u), this.themeBtn = this.iconBtn("moon", "Toggle theme", t.onToggleTheme), this.themeBtn.dataset.role = "theme", n.appendChild(this.themeBtn);
|
|
444
|
+
}
|
|
445
|
+
buildChartTypeMenu() {
|
|
446
|
+
if (!this.chartTypeDropdown) return;
|
|
447
|
+
let e = this.config.chartTypes.map((e) => `<button class="tcw-dropdown-item" data-ct="${e.value}">${e.label}</button>`).join("");
|
|
448
|
+
this.chartTypeDropdown.setContent(e), this.chartTypeDropdown.panel.querySelectorAll(".tcw-dropdown-item").forEach((e) => {
|
|
449
|
+
e.addEventListener("click", (e) => {
|
|
450
|
+
let t = e.currentTarget.dataset.ct;
|
|
451
|
+
this.callbacks.onChartType(t), this.chartTypeDropdown?.close();
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
buildIndicatorMenu() {
|
|
456
|
+
if (!this.indicatorDropdown) return;
|
|
457
|
+
let { indicators: e, popularIndicatorIds: t } = this.config, n = e.filter((e) => t.includes(e.id)), r = e.filter((e) => !t.includes(e.id)), i = "<div class=\"tcw-dropdown-label\">Popular</div>";
|
|
458
|
+
for (let e of n) i += `<button class="tcw-dropdown-item" data-ind="${e.id}"><span>${e.name}</span><span class="tcw-tag">${e.type}</span></button>`;
|
|
459
|
+
i += "<div class=\"tcw-dropdown-divider\"></div>", i += "<div class=\"tcw-dropdown-label\">All</div>";
|
|
460
|
+
for (let e of r) i += `<button class="tcw-dropdown-item" data-ind="${e.id}"><span>${e.name}</span><span class="tcw-tag">${e.type}</span></button>`;
|
|
461
|
+
this.indicatorDropdown.setContent(i), this.indicatorDropdown.panel.querySelectorAll(".tcw-dropdown-item[data-ind]").forEach((e) => {
|
|
462
|
+
e.addEventListener("click", (e) => {
|
|
463
|
+
let t = e.currentTarget.dataset.ind;
|
|
464
|
+
this.callbacks.onAddIndicator(t);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
update(e) {
|
|
469
|
+
let t = this.el.querySelector("[data-role=\"symbol\"]");
|
|
470
|
+
t && (t.textContent = e.symbol);
|
|
471
|
+
for (let t of this.tfButtons) t.classList.toggle("tcw-active", t.dataset.tf === e.timeframe);
|
|
472
|
+
let n = this.el.querySelector("[data-role=\"charttype\"]");
|
|
473
|
+
if (n) {
|
|
474
|
+
let t = this.config.chartTypes.find((t) => t.value === e.chartType)?.label ?? "Candles";
|
|
475
|
+
n.innerHTML = `${g("barChart", 14)} ${t} ${g("chevronDown", 12)}`;
|
|
476
|
+
}
|
|
477
|
+
let r = this.el.querySelector("[data-role=\"indicators\"]");
|
|
478
|
+
if (r) {
|
|
479
|
+
let t = e.activeIndicators.size, n = `${g("trendingUp", 14)} Indicators`;
|
|
480
|
+
t > 0 && (n += ` <span class="tcw-badge-count">${t}</span>`), r.innerHTML = n;
|
|
481
|
+
}
|
|
482
|
+
if (this.chipsContainer) {
|
|
483
|
+
let t = this.getActiveIndicatorList(e);
|
|
484
|
+
this.chipsContainer.innerHTML = "";
|
|
485
|
+
for (let e of t) {
|
|
486
|
+
let t = document.createElement("div");
|
|
487
|
+
t.className = "tcw-indicator-chip";
|
|
488
|
+
let n = document.createElement("span");
|
|
489
|
+
n.textContent = e.label, t.appendChild(n);
|
|
490
|
+
let r = document.createElement("button");
|
|
491
|
+
r.className = "tcw-chip-remove", r.innerHTML = g("x", 10), r.addEventListener("click", () => this.callbacks.onRemoveIndicator(e.instanceId)), t.appendChild(r), this.chipsContainer.appendChild(t);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
this.themeBtn && (this.themeBtn.innerHTML = e.isDark ? g("moon", 14) : g("sun", 14));
|
|
495
|
+
}
|
|
496
|
+
getActiveIndicatorList(e) {
|
|
497
|
+
let t = [];
|
|
498
|
+
for (let [n, r] of e.activeIndicators.entries()) t.push({
|
|
499
|
+
instanceId: r,
|
|
500
|
+
id: n,
|
|
501
|
+
label: n.toUpperCase()
|
|
502
|
+
});
|
|
503
|
+
return t;
|
|
504
|
+
}
|
|
505
|
+
sep() {
|
|
506
|
+
let e = document.createElement("span");
|
|
507
|
+
return e.className = "tcw-toolbar-sep", e;
|
|
508
|
+
}
|
|
509
|
+
spacer() {
|
|
510
|
+
let e = document.createElement("span");
|
|
511
|
+
return e.className = "tcw-toolbar-spacer", e;
|
|
512
|
+
}
|
|
513
|
+
iconBtn(e, t, n) {
|
|
514
|
+
let r = document.createElement("button");
|
|
515
|
+
return r.className = "tcw-btn-icon", r.title = t, r.innerHTML = g(e, 14), r.addEventListener("click", n), r;
|
|
516
|
+
}
|
|
517
|
+
destroy() {
|
|
518
|
+
this.chartTypeDropdown?.destroy(), this.indicatorDropdown?.destroy(), this.el.remove();
|
|
519
|
+
}
|
|
520
|
+
}, y = [
|
|
521
|
+
"trendingUp",
|
|
522
|
+
"minus",
|
|
523
|
+
"penLine",
|
|
524
|
+
"hash",
|
|
525
|
+
"square",
|
|
526
|
+
"gitBranch",
|
|
527
|
+
"ruler",
|
|
528
|
+
"type"
|
|
529
|
+
], b = class {
|
|
530
|
+
config;
|
|
531
|
+
callbacks;
|
|
532
|
+
el;
|
|
533
|
+
groupWraps = [];
|
|
534
|
+
groupButtons = [];
|
|
535
|
+
cursorBtn = null;
|
|
536
|
+
magnetBtn = null;
|
|
537
|
+
flyoutEl = null;
|
|
538
|
+
constructor(e, t, n) {
|
|
539
|
+
this.config = t, this.callbacks = n, this.el = document.createElement("div"), this.el.className = "tcw-sidebar", this.build(), e.appendChild(this.el);
|
|
540
|
+
}
|
|
541
|
+
build() {
|
|
542
|
+
let { config: e, callbacks: t, el: n } = this;
|
|
543
|
+
this.cursorBtn = document.createElement("button"), this.cursorBtn.className = "tcw-sidebar-btn", this.cursorBtn.title = "Cursor", this.cursorBtn.innerHTML = g("cursor", 14), this.cursorBtn.addEventListener("click", t.onCancelDrawing), n.appendChild(this.cursorBtn), n.appendChild(this.divider()), e.drawingToolGroups.forEach((e, r) => {
|
|
544
|
+
let i = document.createElement("div");
|
|
545
|
+
i.className = "tcw-tool-group-wrap";
|
|
546
|
+
let a = document.createElement("button");
|
|
547
|
+
if (a.className = "tcw-sidebar-btn", a.title = e.label, a.innerHTML = g(y[r] ?? "square", 14), e.tools.length > 1) {
|
|
548
|
+
let e = document.createElement("span");
|
|
549
|
+
e.className = "tcw-multi-dot", a.appendChild(e);
|
|
550
|
+
}
|
|
551
|
+
a.addEventListener("click", () => t.onDrawingTool(e.tools[0].value)), i.appendChild(a), i.addEventListener("mouseenter", () => this.showFlyout(r)), i.addEventListener("mouseleave", () => this.hideFlyout()), n.appendChild(i), this.groupWraps.push(i), this.groupButtons.push(a);
|
|
552
|
+
});
|
|
553
|
+
let r = document.createElement("div");
|
|
554
|
+
r.className = "tcw-sidebar-spacer", n.appendChild(r), n.appendChild(this.divider()), this.magnetBtn = document.createElement("button"), this.magnetBtn.className = "tcw-sidebar-btn", this.magnetBtn.title = "Magnet", this.magnetBtn.innerHTML = g("magnet", 14), this.magnetBtn.addEventListener("click", t.onToggleMagnet), n.appendChild(this.magnetBtn);
|
|
555
|
+
let i = document.createElement("button");
|
|
556
|
+
i.className = "tcw-sidebar-btn", i.title = "Undo", i.innerHTML = g("undo", 14), i.addEventListener("click", t.onUndo), n.appendChild(i);
|
|
557
|
+
let a = document.createElement("button");
|
|
558
|
+
a.className = "tcw-sidebar-btn", a.title = "Redo", a.innerHTML = g("redo", 14), a.addEventListener("click", t.onRedo), n.appendChild(a);
|
|
559
|
+
let o = document.createElement("button");
|
|
560
|
+
o.className = "tcw-sidebar-btn tcw-danger", o.title = "Clear all", o.innerHTML = g("trash", 14), o.addEventListener("click", t.onClearDrawings), n.appendChild(o);
|
|
561
|
+
}
|
|
562
|
+
showFlyout(e) {
|
|
563
|
+
let t = this.config.drawingToolGroups[e];
|
|
564
|
+
if (!t || t.tools.length <= 1) return;
|
|
565
|
+
this.hideFlyout();
|
|
566
|
+
let n = document.createElement("div");
|
|
567
|
+
n.className = "tcw-flyout";
|
|
568
|
+
let r = document.createElement("div");
|
|
569
|
+
r.className = "tcw-flyout-header", r.textContent = t.label, n.appendChild(r);
|
|
570
|
+
for (let e of t.tools) {
|
|
571
|
+
let t = document.createElement("button");
|
|
572
|
+
t.className = "tcw-flyout-item", t.textContent = e.label, t.dataset.toolValue = e.value, t.addEventListener("click", () => {
|
|
573
|
+
this.callbacks.onDrawingTool(e.value), this.hideFlyout();
|
|
574
|
+
}), n.appendChild(t);
|
|
575
|
+
}
|
|
576
|
+
this.flyoutEl = n, this.groupWraps[e].appendChild(n);
|
|
577
|
+
}
|
|
578
|
+
hideFlyout() {
|
|
579
|
+
this.flyoutEl &&= (this.flyoutEl.remove(), null);
|
|
580
|
+
}
|
|
581
|
+
update(e) {
|
|
582
|
+
this.cursorBtn && this.cursorBtn.classList.toggle("tcw-active", e.activeTool === null);
|
|
583
|
+
let { drawingToolGroups: t } = this.config;
|
|
584
|
+
for (let n = 0; n < t.length; n++) {
|
|
585
|
+
let r = t[n].tools.some((t) => t.value === e.activeTool);
|
|
586
|
+
this.groupButtons[n].classList.toggle("tcw-active", r);
|
|
587
|
+
}
|
|
588
|
+
this.flyoutEl && this.flyoutEl.querySelectorAll(".tcw-flyout-item").forEach((t) => {
|
|
589
|
+
let n = t;
|
|
590
|
+
n.classList.toggle("tcw-active", n.dataset.toolValue === e.activeTool);
|
|
591
|
+
}), this.magnetBtn && (this.magnetBtn.classList.toggle("tcw-active", e.magnetEnabled), this.magnetBtn.title = e.magnetEnabled ? "Magnet ON" : "Magnet OFF");
|
|
592
|
+
}
|
|
593
|
+
divider() {
|
|
594
|
+
let e = document.createElement("div");
|
|
595
|
+
return e.className = "tcw-sidebar-divider", e;
|
|
596
|
+
}
|
|
597
|
+
destroy() {
|
|
598
|
+
this.hideFlyout(), this.el.remove();
|
|
599
|
+
}
|
|
600
|
+
}, x = [
|
|
601
|
+
"style",
|
|
602
|
+
"display",
|
|
603
|
+
"scale"
|
|
604
|
+
], S = class {
|
|
605
|
+
callbacks;
|
|
606
|
+
backdrop = null;
|
|
607
|
+
modal = null;
|
|
608
|
+
currentTab = "style";
|
|
609
|
+
currentSettings = null;
|
|
610
|
+
bodyEl = null;
|
|
611
|
+
tabButtons = [];
|
|
612
|
+
constructor(e) {
|
|
613
|
+
this.callbacks = e;
|
|
614
|
+
}
|
|
615
|
+
open(e) {
|
|
616
|
+
this.currentSettings = { ...e }, this.currentTab = "style", this.buildModal();
|
|
617
|
+
}
|
|
618
|
+
close() {
|
|
619
|
+
this.backdrop?.remove(), this.modal?.remove(), this.backdrop = null, this.modal = null, this.bodyEl = null, this.tabButtons = [];
|
|
620
|
+
}
|
|
621
|
+
buildModal() {
|
|
622
|
+
this.backdrop = document.createElement("div"), this.backdrop.className = "tcw-modal-backdrop", this.backdrop.addEventListener("click", () => {
|
|
623
|
+
this.callbacks.onClose(), this.close();
|
|
624
|
+
}), document.body.appendChild(this.backdrop), this.modal = document.createElement("div"), this.modal.className = "tcw-modal";
|
|
625
|
+
let e = document.createElement("div");
|
|
626
|
+
e.className = "tcw-modal-header";
|
|
627
|
+
let t = document.createElement("h3");
|
|
628
|
+
t.textContent = "Chart Settings", e.appendChild(t);
|
|
629
|
+
let n = document.createElement("button");
|
|
630
|
+
n.className = "tcw-modal-close", n.innerHTML = g("x", 16), n.addEventListener("click", () => {
|
|
631
|
+
this.callbacks.onClose(), this.close();
|
|
632
|
+
}), e.appendChild(n), this.modal.appendChild(e);
|
|
633
|
+
let r = document.createElement("div");
|
|
634
|
+
r.className = "tcw-modal-tabs", this.tabButtons = [];
|
|
635
|
+
for (let e of x) {
|
|
636
|
+
let t = document.createElement("button");
|
|
637
|
+
t.className = "tcw-modal-tab", t.textContent = e, t.dataset.tab = e, e === this.currentTab && t.classList.add("tcw-active"), t.addEventListener("click", () => {
|
|
638
|
+
this.currentTab = e, this.tabButtons.forEach((t) => t.classList.toggle("tcw-active", t.dataset.tab === e)), this.renderTabContent();
|
|
639
|
+
}), r.appendChild(t), this.tabButtons.push(t);
|
|
640
|
+
}
|
|
641
|
+
this.modal.appendChild(r), this.bodyEl = document.createElement("div"), this.bodyEl.className = "tcw-modal-body", this.modal.appendChild(this.bodyEl), this.renderTabContent();
|
|
642
|
+
let i = document.createElement("div");
|
|
643
|
+
i.className = "tcw-modal-footer";
|
|
644
|
+
let a = document.createElement("button");
|
|
645
|
+
a.className = "tcw-reset-link", a.textContent = "Reset to defaults", a.addEventListener("click", () => this.callbacks.onReset()), i.appendChild(a);
|
|
646
|
+
let o = document.createElement("button");
|
|
647
|
+
o.className = "tcw-done-btn", o.textContent = "Done", o.addEventListener("click", () => {
|
|
648
|
+
this.callbacks.onClose(), this.close();
|
|
649
|
+
}), i.appendChild(o), this.modal.appendChild(i), document.body.appendChild(this.modal);
|
|
650
|
+
let s = (e) => {
|
|
651
|
+
e.key === "Escape" && (document.removeEventListener("keydown", s), this.callbacks.onClose(), this.close());
|
|
652
|
+
};
|
|
653
|
+
document.addEventListener("keydown", s);
|
|
654
|
+
}
|
|
655
|
+
renderTabContent() {
|
|
656
|
+
if (!(!this.bodyEl || !this.currentSettings)) switch (this.bodyEl.innerHTML = "", this.currentTab) {
|
|
657
|
+
case "style":
|
|
658
|
+
this.renderStyleTab();
|
|
659
|
+
break;
|
|
660
|
+
case "display":
|
|
661
|
+
this.renderDisplayTab();
|
|
662
|
+
break;
|
|
663
|
+
case "scale":
|
|
664
|
+
this.renderScaleTab();
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
renderStyleTab() {
|
|
669
|
+
if (!this.bodyEl || !this.currentSettings) return;
|
|
670
|
+
let e = this.currentSettings, t = this.section("Candle Colors");
|
|
671
|
+
t.appendChild(this.colorRow("Up Body", e.candleUpColor, (e) => this.patch({ candleUpColor: e }))), t.appendChild(this.colorRow("Down Body", e.candleDownColor, (e) => this.patch({ candleDownColor: e }))), t.appendChild(this.colorRow("Up Wick", e.candleUpWick, (e) => this.patch({ candleUpWick: e }))), t.appendChild(this.colorRow("Down Wick", e.candleDownWick, (e) => this.patch({ candleDownWick: e }))), this.bodyEl.appendChild(t);
|
|
672
|
+
let n = this.section("Background");
|
|
673
|
+
n.appendChild(this.colorRow("Background", e.backgroundColor, (e) => this.patch({ backgroundColor: e }))), n.appendChild(this.colorRow("Grid", e.gridColor, (e) => this.patch({ gridColor: e }))), this.bodyEl.appendChild(n);
|
|
674
|
+
}
|
|
675
|
+
renderDisplayTab() {
|
|
676
|
+
if (!this.bodyEl || !this.currentSettings) return;
|
|
677
|
+
let e = this.currentSettings, t = this.section();
|
|
678
|
+
t.appendChild(this.toggleRow("Grid Lines", e.gridVisible, (e) => this.patch({ gridVisible: e }))), t.appendChild(this.toggleRow("Volume", e.volumeVisible, (e) => this.patch({ volumeVisible: e }))), t.appendChild(this.toggleRow("OHLC Legend", e.legendVisible, (e) => this.patch({ legendVisible: e }))), t.appendChild(this.toggleRow("Bar Countdown", e.barCountdown, (e) => this.patch({ barCountdown: e }))), t.appendChild(this.selectRow("Crosshair Mode", e.crosshairMode, [
|
|
679
|
+
{
|
|
680
|
+
label: "Magnet",
|
|
681
|
+
value: "magnet"
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
label: "Normal",
|
|
685
|
+
value: "normal"
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
label: "Hidden",
|
|
689
|
+
value: "hidden"
|
|
690
|
+
}
|
|
691
|
+
], (e) => this.patch({ crosshairMode: e }))), t.appendChild(this.selectRow("Number Locale", e.numberLocale, [
|
|
692
|
+
{
|
|
693
|
+
label: "en-US (65,234.00)",
|
|
694
|
+
value: "en-US"
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
label: "de-DE (65.234,00)",
|
|
698
|
+
value: "de-DE"
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
label: "fr-FR (65 234,00)",
|
|
702
|
+
value: "fr-FR"
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
label: "vi-VN (65.234,00)",
|
|
706
|
+
value: "vi-VN"
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
label: "en-IN (65,234.00)",
|
|
710
|
+
value: "en-IN"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
label: "ja-JP (65,234.00)",
|
|
714
|
+
value: "ja-JP"
|
|
715
|
+
}
|
|
716
|
+
], (e) => this.patch({ numberLocale: e }))), this.bodyEl.appendChild(t);
|
|
717
|
+
}
|
|
718
|
+
renderScaleTab() {
|
|
719
|
+
if (!this.bodyEl || !this.currentSettings) return;
|
|
720
|
+
let e = this.currentSettings, t = this.section();
|
|
721
|
+
t.appendChild(this.toggleRow("Auto Scale", e.autoScale, (e) => this.patch({ autoScale: e }))), t.appendChild(this.toggleRow("Log Scale", e.logScale, (e) => this.patch({ logScale: e }))), this.bodyEl.appendChild(t);
|
|
722
|
+
}
|
|
723
|
+
patch(e) {
|
|
724
|
+
this.currentSettings && Object.assign(this.currentSettings, e), this.callbacks.onChange(e);
|
|
725
|
+
}
|
|
726
|
+
section(e) {
|
|
727
|
+
let t = document.createElement("div");
|
|
728
|
+
if (t.className = "tcw-settings-section", e) {
|
|
729
|
+
let n = document.createElement("div");
|
|
730
|
+
n.className = "tcw-settings-section-title", n.textContent = e, t.appendChild(n);
|
|
731
|
+
}
|
|
732
|
+
return t;
|
|
733
|
+
}
|
|
734
|
+
colorRow(e, t, n) {
|
|
735
|
+
let r = document.createElement("div");
|
|
736
|
+
r.className = "tcw-settings-row";
|
|
737
|
+
let i = document.createElement("span");
|
|
738
|
+
i.className = "tcw-settings-label", i.textContent = e, r.appendChild(i);
|
|
739
|
+
let a = document.createElement("div");
|
|
740
|
+
a.className = "tcw-color-picker-wrap";
|
|
741
|
+
let o = document.createElement("input");
|
|
742
|
+
o.type = "color", o.value = t;
|
|
743
|
+
let s = document.createElement("span");
|
|
744
|
+
return s.className = "tcw-color-hex", s.textContent = t, o.addEventListener("input", () => {
|
|
745
|
+
s.textContent = o.value, n(o.value);
|
|
746
|
+
}), a.appendChild(o), a.appendChild(s), r.appendChild(a), r;
|
|
747
|
+
}
|
|
748
|
+
toggleRow(e, t, n) {
|
|
749
|
+
let r = document.createElement("div");
|
|
750
|
+
r.className = "tcw-settings-row";
|
|
751
|
+
let i = document.createElement("span");
|
|
752
|
+
i.className = "tcw-settings-label", i.textContent = e, r.appendChild(i);
|
|
753
|
+
let a = document.createElement("button");
|
|
754
|
+
return a.className = `tcw-toggle${t ? " tcw-on" : ""}`, a.addEventListener("click", () => {
|
|
755
|
+
let e = !a.classList.contains("tcw-on");
|
|
756
|
+
a.classList.toggle("tcw-on", e), n(e);
|
|
757
|
+
}), r.appendChild(a), r;
|
|
758
|
+
}
|
|
759
|
+
selectRow(e, t, n, r) {
|
|
760
|
+
let i = document.createElement("div");
|
|
761
|
+
i.className = "tcw-settings-row";
|
|
762
|
+
let a = document.createElement("span");
|
|
763
|
+
a.className = "tcw-settings-label", a.textContent = e, i.appendChild(a);
|
|
764
|
+
let o = document.createElement("select");
|
|
765
|
+
o.className = "tcw-settings-select";
|
|
766
|
+
for (let e of n) {
|
|
767
|
+
let n = document.createElement("option");
|
|
768
|
+
n.value = e.value, n.textContent = e.label, e.value === t && (n.selected = !0), o.appendChild(n);
|
|
769
|
+
}
|
|
770
|
+
return o.addEventListener("change", () => r(o.value)), i.appendChild(o), i;
|
|
771
|
+
}
|
|
772
|
+
destroy() {
|
|
773
|
+
this.close();
|
|
774
|
+
}
|
|
775
|
+
}, C = class {
|
|
776
|
+
el;
|
|
777
|
+
dotEl;
|
|
778
|
+
messageEl;
|
|
779
|
+
infoEl;
|
|
780
|
+
constructor(e) {
|
|
781
|
+
this.el = document.createElement("div"), this.el.className = "tcw-statusbar";
|
|
782
|
+
let t = document.createElement("div");
|
|
783
|
+
t.className = "tcw-status-indicator", this.dotEl = document.createElement("span"), this.dotEl.className = "tcw-status-dot", t.appendChild(this.dotEl), this.messageEl = document.createElement("span"), t.appendChild(this.messageEl), this.el.appendChild(t), this.infoEl = document.createElement("span"), this.el.appendChild(this.infoEl), e.appendChild(this.el);
|
|
784
|
+
}
|
|
785
|
+
update(e) {
|
|
786
|
+
this.dotEl.className = "tcw-status-dot", e.connectionState === "connected" ? this.dotEl.classList.add("tcw-connected") : e.connectionState === "error" && this.dotEl.classList.add("tcw-error"), this.messageEl.textContent = e.message, this.infoEl.textContent = `${e.symbol} ${e.timeframe}`;
|
|
787
|
+
}
|
|
788
|
+
destroy() {
|
|
789
|
+
this.el.remove();
|
|
790
|
+
}
|
|
791
|
+
}, w = class {
|
|
792
|
+
chart;
|
|
793
|
+
state;
|
|
794
|
+
toolbar = null;
|
|
795
|
+
sidebar = null;
|
|
796
|
+
settings = null;
|
|
797
|
+
statusBar = null;
|
|
798
|
+
root;
|
|
799
|
+
chartContainer;
|
|
800
|
+
destroyed = !1;
|
|
801
|
+
options;
|
|
802
|
+
symbolIndex = 0;
|
|
803
|
+
symbols;
|
|
804
|
+
settingsState;
|
|
805
|
+
adapter = null;
|
|
806
|
+
constructor(t, n = {}) {
|
|
807
|
+
this.options = n, this.symbols = n.symbols ?? c, this.settingsState = { ...l };
|
|
808
|
+
let u = this.resolveIsDark(n.theme), d = this.resolveTheme(n.theme);
|
|
809
|
+
this.state = {
|
|
810
|
+
symbol: n.symbol ?? this.symbols[0] ?? "BTCUSDT",
|
|
811
|
+
timeframe: n.timeframe ?? "5m",
|
|
812
|
+
chartType: n.chartOptions?.chartType ?? "candlestick",
|
|
813
|
+
isDark: u,
|
|
814
|
+
activeIndicators: /* @__PURE__ */ new Map(),
|
|
815
|
+
activeTool: null,
|
|
816
|
+
magnetEnabled: !0,
|
|
817
|
+
connectionState: "connecting",
|
|
818
|
+
connectionMessage: "Connecting..."
|
|
819
|
+
};
|
|
820
|
+
let f = this.symbols.indexOf(this.state.symbol);
|
|
821
|
+
f >= 0 && (this.symbolIndex = f), p(), this.root = document.createElement("div"), this.root.className = "tcw-root", this.root.dataset.tcwTheme = u ? "dark" : "light", t.appendChild(this.root), n.toolbar !== !1 && (this.toolbar = new v(this.root, {
|
|
822
|
+
symbols: this.symbols,
|
|
823
|
+
timeframes: n.timeframes ? r.filter((e) => n.timeframes.includes(e.value)) : r,
|
|
824
|
+
chartTypes: n.chartTypes ? i.filter((e) => n.chartTypes.includes(e.value)) : i,
|
|
825
|
+
indicators: o,
|
|
826
|
+
popularIndicatorIds: s
|
|
827
|
+
}, {
|
|
828
|
+
onSymbolClick: () => this.handleSymbolClick(),
|
|
829
|
+
onTimeframe: (e) => this.handleTimeframe(e),
|
|
830
|
+
onChartType: (e) => this.handleChartType(e),
|
|
831
|
+
onAddIndicator: (e) => this.handleAddIndicator(e),
|
|
832
|
+
onRemoveIndicator: (e) => this.handleRemoveIndicator(e),
|
|
833
|
+
onScreenshot: () => this.chart.screenshot(),
|
|
834
|
+
onSettings: () => this.openSettings(),
|
|
835
|
+
onToggleTheme: () => this.handleToggleTheme()
|
|
836
|
+
}));
|
|
837
|
+
let m = document.createElement("div");
|
|
838
|
+
m.className = "tcw-body", n.drawingTools !== !1 && (this.sidebar = new b(m, { drawingToolGroups: a }, {
|
|
839
|
+
onDrawingTool: (e) => this.handleDrawingTool(e),
|
|
840
|
+
onCancelDrawing: () => this.handleCancelDrawing(),
|
|
841
|
+
onToggleMagnet: () => this.handleToggleMagnet(),
|
|
842
|
+
onUndo: () => this.chart.undo(),
|
|
843
|
+
onRedo: () => this.chart.redo(),
|
|
844
|
+
onClearDrawings: () => {
|
|
845
|
+
this.chart.clearDrawings(), this.state = {
|
|
846
|
+
...this.state,
|
|
847
|
+
activeTool: null
|
|
848
|
+
}, this.updateUI();
|
|
849
|
+
}
|
|
850
|
+
})), this.chartContainer = document.createElement("div"), this.chartContainer.className = "tcw-chart-container", m.appendChild(this.chartContainer), this.root.appendChild(m), this.chart = new e(this.chartContainer, {
|
|
851
|
+
chartType: this.state.chartType,
|
|
852
|
+
theme: d,
|
|
853
|
+
autoScale: !0,
|
|
854
|
+
crosshair: { mode: "magnet" },
|
|
855
|
+
features: {
|
|
856
|
+
drawings: !0,
|
|
857
|
+
drawingMagnet: !0,
|
|
858
|
+
drawingUndoRedo: !0,
|
|
859
|
+
indicators: !0,
|
|
860
|
+
trading: n.trading !== !1,
|
|
861
|
+
tradingContextMenu: n.trading !== !1,
|
|
862
|
+
volume: !0,
|
|
863
|
+
legend: !0,
|
|
864
|
+
crosshair: !0,
|
|
865
|
+
keyboard: !0,
|
|
866
|
+
screenshot: !0,
|
|
867
|
+
alerts: !0,
|
|
868
|
+
barCountdown: !0,
|
|
869
|
+
logScale: !0,
|
|
870
|
+
watermark: !0
|
|
871
|
+
},
|
|
872
|
+
...n.chartOptions
|
|
873
|
+
}), n.statusBar !== !1 && (this.statusBar = new C(this.root)), n.settings !== !1 && (this.settings = new S({
|
|
874
|
+
onChange: (e) => this.applySettings(e),
|
|
875
|
+
onReset: () => this.resetSettings(),
|
|
876
|
+
onClose: () => {}
|
|
877
|
+
})), n.adapter && (this.adapter = n.adapter, this.connectStream()), this.updateUI(), n.onReady?.(this.chart);
|
|
878
|
+
}
|
|
879
|
+
async setSymbol(e) {
|
|
880
|
+
this.state = {
|
|
881
|
+
...this.state,
|
|
882
|
+
symbol: e
|
|
883
|
+
};
|
|
884
|
+
let t = this.symbols.indexOf(e);
|
|
885
|
+
t >= 0 && (this.symbolIndex = t), this.options.onSymbolChange?.(e), this.updateUI(), this.adapter && await this.connectStream();
|
|
886
|
+
}
|
|
887
|
+
async setTimeframe(e) {
|
|
888
|
+
this.state = {
|
|
889
|
+
...this.state,
|
|
890
|
+
timeframe: e
|
|
891
|
+
}, this.options.onTimeframeChange?.(e), this.updateUI(), this.adapter && await this.connectStream();
|
|
892
|
+
}
|
|
893
|
+
setTheme(e) {
|
|
894
|
+
let t = this.resolveIsDark(e), n = this.resolveTheme(e);
|
|
895
|
+
this.state = {
|
|
896
|
+
...this.state,
|
|
897
|
+
isDark: t
|
|
898
|
+
}, this.root.dataset.tcwTheme = t ? "dark" : "light", this.chart.setTheme(n), this.updateUI();
|
|
899
|
+
}
|
|
900
|
+
getChart() {
|
|
901
|
+
return this.chart;
|
|
902
|
+
}
|
|
903
|
+
destroy() {
|
|
904
|
+
this.destroyed || (this.destroyed = !0, this.toolbar?.destroy(), this.sidebar?.destroy(), this.settings?.destroy(), this.statusBar?.destroy(), this.chart.destroy(), this.root.remove(), m());
|
|
905
|
+
}
|
|
906
|
+
handleSymbolClick() {
|
|
907
|
+
this.symbolIndex = (this.symbolIndex + 1) % this.symbols.length;
|
|
908
|
+
let e = this.symbols[this.symbolIndex];
|
|
909
|
+
this.state = {
|
|
910
|
+
...this.state,
|
|
911
|
+
symbol: e
|
|
912
|
+
}, this.options.onSymbolChange?.(e), this.updateUI(), this.adapter && this.connectStream();
|
|
913
|
+
}
|
|
914
|
+
handleTimeframe(e) {
|
|
915
|
+
this.state = {
|
|
916
|
+
...this.state,
|
|
917
|
+
timeframe: e
|
|
918
|
+
}, this.options.onTimeframeChange?.(e), this.updateUI(), this.adapter && this.connectStream();
|
|
919
|
+
}
|
|
920
|
+
handleChartType(e) {
|
|
921
|
+
this.state = {
|
|
922
|
+
...this.state,
|
|
923
|
+
chartType: e
|
|
924
|
+
}, this.chart.setChartType(e), this.updateUI();
|
|
925
|
+
}
|
|
926
|
+
handleAddIndicator(e) {
|
|
927
|
+
if (this.state.activeIndicators.has(e)) {
|
|
928
|
+
let t = this.state.activeIndicators.get(e);
|
|
929
|
+
this.chart.removeIndicator(t);
|
|
930
|
+
let n = new Map(this.state.activeIndicators);
|
|
931
|
+
n.delete(e), this.state = {
|
|
932
|
+
...this.state,
|
|
933
|
+
activeIndicators: n
|
|
934
|
+
};
|
|
935
|
+
} else {
|
|
936
|
+
let t = this.chart.addIndicator(e);
|
|
937
|
+
if (t) {
|
|
938
|
+
let n = new Map(this.state.activeIndicators);
|
|
939
|
+
n.set(e, t), this.state = {
|
|
940
|
+
...this.state,
|
|
941
|
+
activeIndicators: n
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
this.updateUI();
|
|
946
|
+
}
|
|
947
|
+
handleRemoveIndicator(e) {
|
|
948
|
+
this.chart.removeIndicator(e);
|
|
949
|
+
let t = new Map(this.state.activeIndicators);
|
|
950
|
+
for (let [n, r] of t.entries()) if (r === e) {
|
|
951
|
+
t.delete(n);
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
this.state = {
|
|
955
|
+
...this.state,
|
|
956
|
+
activeIndicators: t
|
|
957
|
+
}, this.updateUI();
|
|
958
|
+
}
|
|
959
|
+
handleDrawingTool(e) {
|
|
960
|
+
this.state = {
|
|
961
|
+
...this.state,
|
|
962
|
+
activeTool: e
|
|
963
|
+
}, this.chart.setDrawingTool(e), this.updateUI();
|
|
964
|
+
}
|
|
965
|
+
handleCancelDrawing() {
|
|
966
|
+
this.state = {
|
|
967
|
+
...this.state,
|
|
968
|
+
activeTool: null
|
|
969
|
+
}, this.chart.setDrawingTool(null), this.updateUI();
|
|
970
|
+
}
|
|
971
|
+
handleToggleMagnet() {
|
|
972
|
+
let e = !this.state.magnetEnabled;
|
|
973
|
+
this.state = {
|
|
974
|
+
...this.state,
|
|
975
|
+
magnetEnabled: e
|
|
976
|
+
}, this.chart.setDrawingMagnet(e), this.updateUI();
|
|
977
|
+
}
|
|
978
|
+
handleToggleTheme() {
|
|
979
|
+
let e = !this.state.isDark;
|
|
980
|
+
this.state = {
|
|
981
|
+
...this.state,
|
|
982
|
+
isDark: e
|
|
983
|
+
}, this.root.dataset.tcwTheme = e ? "dark" : "light", this.chart.setTheme(e ? t : n), this.chart.setWatermark(this.state.symbol.replace("USDT", " / USDT"), {
|
|
984
|
+
fontSize: 48,
|
|
985
|
+
color: e ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.03)"
|
|
986
|
+
}), this.updateUI();
|
|
987
|
+
}
|
|
988
|
+
openSettings() {
|
|
989
|
+
this.settings?.open(this.settingsState);
|
|
990
|
+
}
|
|
991
|
+
applySettings(e) {
|
|
992
|
+
this.settingsState = {
|
|
993
|
+
...this.settingsState,
|
|
994
|
+
...e
|
|
995
|
+
}, e.gridVisible !== void 0 && this.chart.setGridVisible(e.gridVisible), e.volumeVisible !== void 0 && this.chart.setVolumeVisible(e.volumeVisible), e.crosshairMode !== void 0 && this.chart.setCrosshairMode(e.crosshairMode), e.autoScale !== void 0 && this.chart.setAutoScale(e.autoScale), e.logScale !== void 0 && this.chart.setLogScale(e.logScale), e.numberLocale !== void 0 && this.chart.setNumberLocale(e.numberLocale);
|
|
996
|
+
let t = { ...this.chart.getTheme() }, n = !1;
|
|
997
|
+
e.candleUpColor !== void 0 && (t.candleUp = e.candleUpColor, n = !0), e.candleDownColor !== void 0 && (t.candleDown = e.candleDownColor, n = !0), e.candleUpWick !== void 0 && (t.candleUpWick = e.candleUpWick, n = !0), e.candleDownWick !== void 0 && (t.candleDownWick = e.candleDownWick, n = !0), e.backgroundColor !== void 0 && (t.background = e.backgroundColor, n = !0), e.gridColor !== void 0 && (t.grid = e.gridColor, n = !0), n && this.chart.setTheme(t);
|
|
998
|
+
}
|
|
999
|
+
resetSettings() {
|
|
1000
|
+
this.settingsState = { ...l }, this.applySettings(this.settingsState);
|
|
1001
|
+
}
|
|
1002
|
+
async connectStream() {
|
|
1003
|
+
if (this.adapter) {
|
|
1004
|
+
this.state = {
|
|
1005
|
+
...this.state,
|
|
1006
|
+
connectionState: "connecting",
|
|
1007
|
+
connectionMessage: "Connecting..."
|
|
1008
|
+
}, this.updateUI();
|
|
1009
|
+
try {
|
|
1010
|
+
this.chart.disconnectStream(), await this.chart.connect({
|
|
1011
|
+
adapter: this.adapter,
|
|
1012
|
+
symbol: this.state.symbol,
|
|
1013
|
+
timeframe: this.state.timeframe,
|
|
1014
|
+
historyLimit: this.options.historyLimit ?? 500
|
|
1015
|
+
}), this.chart.setWatermark(this.state.symbol.replace("USDT", " / USDT"), {
|
|
1016
|
+
fontSize: 48,
|
|
1017
|
+
color: this.state.isDark ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.03)"
|
|
1018
|
+
}), this.state = {
|
|
1019
|
+
...this.state,
|
|
1020
|
+
connectionState: "connected",
|
|
1021
|
+
connectionMessage: "Live"
|
|
1022
|
+
};
|
|
1023
|
+
} catch (e) {
|
|
1024
|
+
this.state = {
|
|
1025
|
+
...this.state,
|
|
1026
|
+
connectionState: "error",
|
|
1027
|
+
connectionMessage: e instanceof Error ? e.message : "Connection failed"
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
this.updateUI();
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
updateUI() {
|
|
1034
|
+
this.toolbar?.update(this.state), this.sidebar?.update(this.state), this.statusBar?.update({
|
|
1035
|
+
connectionState: this.state.connectionState,
|
|
1036
|
+
message: this.state.connectionMessage,
|
|
1037
|
+
symbol: this.state.symbol,
|
|
1038
|
+
timeframe: this.state.timeframe
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
resolveIsDark(e) {
|
|
1042
|
+
return e === void 0 || e === "dark" ? !0 : e === "light" ? !1 : typeof e == "object" && e.background ? this.isColorDark(e.background) : !0;
|
|
1043
|
+
}
|
|
1044
|
+
resolveTheme(e) {
|
|
1045
|
+
return e === void 0 || e === "dark" ? t : e === "light" ? n : typeof e == "object" ? e : t;
|
|
1046
|
+
}
|
|
1047
|
+
isColorDark(e) {
|
|
1048
|
+
if (e.startsWith("#") && e.length >= 7) {
|
|
1049
|
+
let t = parseInt(e.slice(1, 3), 16), n = parseInt(e.slice(3, 5), 16), r = parseInt(e.slice(5, 7), 16);
|
|
1050
|
+
return t + n + r < 384;
|
|
1051
|
+
}
|
|
1052
|
+
return !0;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
//#endregion
|
|
1056
|
+
export { w as ChartWidget };
|
|
1057
|
+
|
|
1058
|
+
//# sourceMappingURL=index.js.map
|