@luxalgo/vela 0.5.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.
Files changed (61) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +28 -0
  3. package/README.md +135 -0
  4. package/dist/DataProvider-DKNDHpNv.d.cts +134 -0
  5. package/dist/DataProvider-Dzd-Erlk.d.ts +134 -0
  6. package/dist/chunk-7UFX5ZIG.js +5976 -0
  7. package/dist/chunk-GYD2THPV.js +252 -0
  8. package/dist/chunk-KCCZNKH7.js +19137 -0
  9. package/dist/chunk-KM6LHB3Y.js +76 -0
  10. package/dist/chunk-OVQKKXLZ.js +3978 -0
  11. package/dist/chunk-Q3XQHLIH.js +7 -0
  12. package/dist/chunk-RHIDOUFL.js +698 -0
  13. package/dist/contributions-hX3EUyjG.d.ts +1528 -0
  14. package/dist/contributions-o1GRKPI_.d.cts +1528 -0
  15. package/dist/history-Dzxz-MQj.d.ts +298 -0
  16. package/dist/history-LJkz4-sS.d.cts +298 -0
  17. package/dist/icons-BZYbJXSV.d.cts +10 -0
  18. package/dist/icons-BZYbJXSV.d.ts +10 -0
  19. package/dist/index.cjs +25294 -0
  20. package/dist/index.d.cts +1189 -0
  21. package/dist/index.d.ts +1189 -0
  22. package/dist/index.js +5 -0
  23. package/dist/keymap-CGOz5F5f.d.cts +64 -0
  24. package/dist/keymap-CGOz5F5f.d.ts +64 -0
  25. package/dist/options-Q-576hIi.d.cts +1545 -0
  26. package/dist/options-Q-576hIi.d.ts +1545 -0
  27. package/dist/plugin-D94muTV-.d.cts +405 -0
  28. package/dist/plugin-aGUD1epn.d.ts +405 -0
  29. package/dist/plugin.cjs +5967 -0
  30. package/dist/plugin.d.cts +7 -0
  31. package/dist/plugin.d.ts +7 -0
  32. package/dist/plugin.js +3 -0
  33. package/dist/providers/binance.cjs +390 -0
  34. package/dist/providers/binance.d.cts +62 -0
  35. package/dist/providers/binance.d.ts +62 -0
  36. package/dist/providers/binance.js +388 -0
  37. package/dist/providers/coinbase.cjs +462 -0
  38. package/dist/providers/coinbase.d.cts +59 -0
  39. package/dist/providers/coinbase.d.ts +59 -0
  40. package/dist/providers/coinbase.js +460 -0
  41. package/dist/providers/hyperliquid.cjs +361 -0
  42. package/dist/providers/hyperliquid.d.cts +54 -0
  43. package/dist/providers/hyperliquid.d.ts +54 -0
  44. package/dist/providers/hyperliquid.js +359 -0
  45. package/dist/side-panel-CT9ZwIGz.d.cts +63 -0
  46. package/dist/side-panel-CT9ZwIGz.d.ts +63 -0
  47. package/dist/ui.cjs +1030 -0
  48. package/dist/ui.d.cts +188 -0
  49. package/dist/ui.d.ts +188 -0
  50. package/dist/ui.js +3 -0
  51. package/dist/vela.global.js +26509 -0
  52. package/dist/vela.global.min.js +230 -0
  53. package/dist/widget.cjs +31178 -0
  54. package/dist/widget.d.cts +799 -0
  55. package/dist/widget.d.ts +799 -0
  56. package/dist/widget.js +1060 -0
  57. package/dist/workspace.cjs +31692 -0
  58. package/dist/workspace.d.cts +579 -0
  59. package/dist/workspace.d.ts +579 -0
  60. package/dist/workspace.js +1694 -0
  61. package/package.json +95 -0
@@ -0,0 +1,298 @@
1
+ import { V as VisibleRangePreset } from './options-Q-576hIi.js';
2
+ import { D as DataProvider } from './DataProvider-Dzd-Erlk.js';
3
+ import { S as ScriptingEngine, V as Vela } from './contributions-hX3EUyjG.js';
4
+
5
+ interface RangePreset {
6
+ /** Button label. */
7
+ id: string;
8
+ /** Timeframe to switch to for this range. */
9
+ tf: string;
10
+ /** The core visible-range preset framed once the chart is ready. */
11
+ preset: VisibleRangePreset;
12
+ /**
13
+ * Bars the window needs AT `tf` — the fetch budget for the rebuild. Without it the
14
+ * chart loads its default depth and the framed window is clipped to whatever
15
+ * history happens to be loaded (a "1D" that only shows 16 hours). Includes a small
16
+ * margin; `ALL` asks for as much history as the provider will serve.
17
+ */
18
+ bars: number;
19
+ }
20
+ /**
21
+ * Range chips — each pairs a timeframe, a visible window, and the fetch depth that
22
+ * window needs. Resolutions follow the reference: the shorter the range, the finer the
23
+ * bars (1 day of 1-minute bars … 5 years of weekly bars).
24
+ */
25
+ declare const RANGE_PRESETS: readonly RangePreset[];
26
+ interface BottombarOptions {
27
+ timezone: string;
28
+ onRange: (preset: RangePreset) => void;
29
+ onTimezone: (zone: string) => void;
30
+ onSettingsClick?: () => void;
31
+ }
32
+ declare class Bottombar {
33
+ readonly el: HTMLElement;
34
+ private readonly clockEl;
35
+ private readonly tzLabelEl;
36
+ private readonly tzButton;
37
+ private readonly tzMenu;
38
+ private readonly settingsTip;
39
+ private readonly rangeButtons;
40
+ private timezone;
41
+ private timer;
42
+ constructor(host: HTMLElement, opts: BottombarOptions);
43
+ setTimezone(zone: string): void;
44
+ /** Highlight (or clear with null) the active range chip — cleared on manual tf changes. */
45
+ setActiveRange(id: string | null): void;
46
+ destroy(): void;
47
+ private tzItems;
48
+ private tick;
49
+ }
50
+
51
+ interface IndicatorManifestEntry {
52
+ name: string;
53
+ /** Inline script source (one of script/url required). */
54
+ script?: string;
55
+ /** Fetch the source from here instead (resolved relative to the manifest URL). */
56
+ url?: string;
57
+ /** Engine language (default: the chart's default engine). */
58
+ language?: string;
59
+ /** Add to the chart at startup (default true). Disabled entries only appear in pickers. */
60
+ enabled?: boolean;
61
+ /** Picker grouping (default 'Indicators'). */
62
+ category?: string;
63
+ }
64
+ type IndicatorManifest = IndicatorManifestEntry[] | {
65
+ indicators: IndicatorManifestEntry[];
66
+ };
67
+ /** A manifest entry with its source resolved and ready for `chart.addIndicator`. */
68
+ interface ResolvedIndicator {
69
+ name: string;
70
+ script: string;
71
+ language?: string;
72
+ enabled: boolean;
73
+ category?: string;
74
+ }
75
+ /** An async manifest source — called once at resolution time. The escape hatch for
76
+ * manifests that a URL can't express: a filesystem read, an authenticated API, a
77
+ * bundler dynamic import. A rejection behaves like a failing manifest URL. */
78
+ type IndicatorLoader = () => Promise<IndicatorManifest>;
79
+ /** Load the indicator list: a manifest object, a URL string returning the manifest JSON,
80
+ * or an async loader function returning the manifest. Entries with `url` sources are
81
+ * fetched here too (relative to the manifest URL when there is one). Entries that fail
82
+ * to resolve are dropped with a console warning — one broken script must not take the
83
+ * chart down. */
84
+ declare function resolveIndicators(config: string | IndicatorManifest | IndicatorLoader, fetchImpl?: typeof fetch): Promise<ResolvedIndicator[]>;
85
+
86
+ /** The linkable dimensions. `crosshair` mirrors the pointer time onto same-group
87
+ * cells as GHOST crosshairs (renderers without the optional `setExternalCrosshair`
88
+ * seam simply never display one). */
89
+ type SyncKind = 'viewport' | 'symbol' | 'timeframe' | 'crosshair';
90
+ /**
91
+ * One link's configuration: `false`/absent = off; `true` = ALL cells linked (one
92
+ * implicit group); a record maps cell id → group name, and only cells sharing a group
93
+ * follow each other (a cell absent from the record is unlinked).
94
+ */
95
+ type SyncSetting = boolean | Readonly<Record<string, string>>;
96
+ interface SyncOptions {
97
+ viewport?: SyncSetting;
98
+ symbol?: SyncSetting;
99
+ timeframe?: SyncSetting;
100
+ crosshair?: SyncSetting;
101
+ }
102
+ /** Splitter track weights along each grid axis. */
103
+ interface TrackSizes {
104
+ cols?: number[];
105
+ rows?: number[];
106
+ }
107
+ /**
108
+ * The docked side panels — a SHELL-level pref (one dock serves every cell of a workspace).
109
+ * `open` is the single panel showing (the dock is exclusive); `widths` holds only the columns
110
+ * the user actually resized, by panel id, so a panel's declared width stays in charge until
111
+ * then. Absent altogether in documents written before the dock existed.
112
+ */
113
+ interface PanelsState {
114
+ open?: string;
115
+ widths?: Record<string, number>;
116
+ }
117
+ /** Per-chart (per-cell) state: the market, the display prefs, the content documents,
118
+ * and the indicator ledger. The widget's whole chart state is ONE of these. */
119
+ interface CellState {
120
+ symbol?: string;
121
+ /** The symbol's venue. Mirrors the symbol's own `EXCHANGE:` prefix on new saves;
122
+ * pre-prefix documents stored it beside a BARE symbol — {@link prefixedSymbol}
123
+ * welds the two back into the one canonical form at restore time. */
124
+ provider?: string;
125
+ timeframe?: string;
126
+ priceStyle?: string;
127
+ bars?: number;
128
+ /** Symbol watermark visibility — a per-chart display pref. */
129
+ watermark?: boolean;
130
+ /** Indicator titles (the in-chart legend rows) visibility — a per-chart display pref. */
131
+ indicatorTitles?: boolean;
132
+ /** The renderer's cosmetic config document (`renderer.getConfig()`). */
133
+ rendererConfig?: unknown;
134
+ /** The user-drawings document (`drawings.toJSON()`). */
135
+ drawings?: unknown;
136
+ /** The indicator ledger: manifest entries by name + present native types. */
137
+ indicators?: {
138
+ manifest: string[];
139
+ natives: string[];
140
+ };
141
+ }
142
+ /** One entry of the document's `charts` array: a chart's state plus its cell IDENTITY. */
143
+ interface ChartState extends CellState {
144
+ /** The cell's durable identity — its declared name (`btc`), or `c<N>` for a slot no
145
+ * entry declared. Unique within the document; array position restores slot order. */
146
+ id: string;
147
+ }
148
+ /** The versioned shell-state document — everything `applyState` restores. */
149
+ interface WorkspaceState {
150
+ version: 1;
151
+ /** The layout id — always `'1'` for a widget. Restoring an id that is not
152
+ * registered keeps the current layout — register custom layouts
153
+ * (`registerLayout`) before applying a saved state. */
154
+ layout: string;
155
+ /** Splitter track weights, per layout id (workspace only). */
156
+ trackSizes?: Record<string, TrackSizes>;
157
+ activeCellId?: string;
158
+ /** Sync links (workspace only). */
159
+ sync?: SyncOptions;
160
+ /** Shared display timezone. */
161
+ timezone?: string;
162
+ /** Favorite drawing-tool types — a SHARED preference (one star set per shell). */
163
+ favorites?: string[];
164
+ /** The docked side panels: which one is open, and the widths the user dragged. */
165
+ panels?: PanelsState;
166
+ /** Per-chart state, one entry per SLOT (a single `c1` entry for the widget).
167
+ * Ids are unique — the codec drops id-less entries and keeps the LAST duplicate. */
168
+ charts: ChartState[];
169
+ }
170
+ declare function encodeState(state: WorkspaceState): string;
171
+ /** Parse + sanitize a persisted payload. Null on anything unusable (wrong version,
172
+ * not JSON, not an object) — malformed FIELDS are dropped, never thrown on. */
173
+ declare function decodeState(raw: string): WorkspaceState | null;
174
+ /**
175
+ * Validate an untrusted state document field by field (the `applyState` gate). Unknown
176
+ * or malformed fields are dropped; nested renderer-config / drawings documents pass
177
+ * through OPAQUELY — their own consumers (`applyConfig`, `fromJSON`) validate them.
178
+ */
179
+ declare function sanitizeState(doc: unknown): WorkspaceState | null;
180
+
181
+ /** The storage contract BOTH shells persist through (the widget and the workspace —
182
+ * one name, one shape). Methods may be synchronous or return promises. */
183
+ interface VelaStorage {
184
+ get(key: string): string | null | Promise<string | null>;
185
+ set(key: string, value: string): void | Promise<void>;
186
+ remove?(key: string): void | Promise<void>;
187
+ }
188
+ /** @deprecated Use {@link VelaStorage} — same contract, shell-neutral name. */
189
+ type WidgetStorage = VelaStorage;
190
+ /**
191
+ * The default adapter — window.localStorage, silent on quota/privacy failures.
192
+ *
193
+ * `storageKey` pins the PHYSICAL localStorage entry: every read/write lands on that
194
+ * one name, whatever logical key the shell passes — the way to choose where the state
195
+ * lives without touching the `persist` option (one shell instance per adapter then;
196
+ * two shells sharing a pinned adapter would overwrite each other). Omitted, the
197
+ * shell's own key is used as-is (the historical behavior).
198
+ */
199
+ declare function localStorageAdapter(storageKey?: string): WidgetStorage;
200
+ interface PersistedState {
201
+ symbol?: string;
202
+ timeframe?: string;
203
+ priceStyle?: string;
204
+ timezone?: string;
205
+ bars?: string;
206
+ watermark?: string;
207
+ /** Comma-joined favorite drawing-tool types. */
208
+ favorites?: string;
209
+ }
210
+ /** Parse a LEGACY prefs payload (never throws — junk yields `{}`). */
211
+ declare function parsePersisted(raw: string | null): PersistedState;
212
+ /** Load the persisted state — synchronous result for sync storages, else a promise. */
213
+ declare function loadPersisted(storage: WidgetStorage, storageKey: string): PersistedState | Promise<PersistedState>;
214
+ /** Save (fire-and-forget — async adapter failures are the adapter's concern). */
215
+ declare function savePersisted(storage: WidgetStorage, storageKey: string, state: PersistedState): void;
216
+ /**
217
+ * LEGACY migration — convert the widget's pre-unified three-key layout (prefs under
218
+ * the main key, renderer config under `<key>:config`, drawings under `<key>:drawings`)
219
+ * into ONE unified state document (the same format the workspace persists, with a
220
+ * single `c1` cell). Null when the payload holds no usable state. Pure — the caller
221
+ * reads the keys, then rewrites the main key and drops the legacy sub-keys.
222
+ */
223
+ declare function legacyWidgetState(prefs: PersistedState, rawConfig: string | null, rawDrawings: string | null): WorkspaceState | null;
224
+
225
+ /** What a shell (widget or workspace) accepts BEYOND the chart options themselves. */
226
+ interface VelaShellOptions {
227
+ /** Provider factories, keyed by provider name. The shell owns the call cycle: the
228
+ * widget re-instantiates on each chart rebuild; the workspace instantiates once
229
+ * onto its single shared feed. */
230
+ providers?: Record<string, () => DataProvider>;
231
+ /** Scripting-engine factories, keyed by language — ONE instance per chart (the
232
+ * widget's chart, each workspace cell), so a worker engine gets its own thread and
233
+ * dies with its chart. Return a shared instance from the factory to opt into one
234
+ * engine for everything. Merged OVER the app-level `registerDefaultEngine`
235
+ * registry — an instance factory wins for its language. */
236
+ engines?: Record<string, () => ScriptingEngine>;
237
+ /** Indicator manifest: inline, a URL returning it, or an ASYNC LOADER function
238
+ * (`() => Promise<manifest>` — filesystem reads, authenticated APIs, dynamic
239
+ * imports). Resolved ONCE; entries with `enabled: true` auto-add to every FRESH
240
+ * chart (restored cells re-add their own recorded set instead). */
241
+ indicators?: string | IndicatorManifest | IndicatorLoader;
242
+ /** Topbar timeframe presets (chart timeframe values). */
243
+ timeframes?: string[];
244
+ /** Display timezone (IANA; default 'Etc/UTC') — one zone for the whole shell. */
245
+ timezone?: string;
246
+ /** Chrome toggles (all default true). */
247
+ statusline?: boolean;
248
+ watermark?: boolean;
249
+ bottombar?: boolean;
250
+ /** Focus the chart when the shell mounts so keyboard shortcuts work from the first
251
+ * keystroke — no initial click needed. Default false: an embedded shell must never
252
+ * steal the page's focus from the host's own controls. */
253
+ autofocus?: boolean;
254
+ /** Bring the shell back AS YOU LEFT IT: persist the full state document
255
+ * (`getState()`) and restore it at construction. `true` uses the shell's default
256
+ * key ('vela-widget' / 'vela-workspace'); a string is the storage key. */
257
+ persist?: boolean | string;
258
+ /** Storage backend for `persist` — defaults to localStorage in BOTH shells. Inject
259
+ * any {@link VelaStorage} (sync or async) for custom backends (REST, IndexedDB, …)
260
+ * or the exported in-memory adapter for session-lived state. */
261
+ storage?: VelaStorage;
262
+ }
263
+
264
+ interface HistoryAction {
265
+ undo(): void;
266
+ redo(): void;
267
+ }
268
+ declare class WidgetHistory {
269
+ private readonly getChart;
270
+ private readonly undoStack;
271
+ private readonly redoStack;
272
+ private readonly listeners;
273
+ private unsubs;
274
+ private muted;
275
+ /** `getChart` late-resolves the CURRENT chart: drawing steps recorded before a chart
276
+ * rebuild must undo on the chart that exists when the user presses Ctrl+Z, not on a
277
+ * destroyed instance captured at record time. */
278
+ constructor(getChart?: () => Vela | null);
279
+ /** Record a reversible action (a fresh edit forks history: redo branch clears). */
280
+ push(action: HistoryAction): void;
281
+ undo(): void;
282
+ redo(): void;
283
+ /** Run `fn` without recording — for programmatic state application (setState,
284
+ * ledger restore), whose indicator/drawing events are not user edits. */
285
+ silently(fn: () => void): void;
286
+ get canUndo(): boolean;
287
+ get canRedo(): boolean;
288
+ onChange(cb: () => void): () => void;
289
+ /** (Re)bind to a chart: drawing edits enter the unified stack as delegate steps. */
290
+ onChart(chart: Vela): void;
291
+ destroy(): void;
292
+ private pushDrawingStep;
293
+ /** Replaying an action must not re-record the drawing events it triggers. */
294
+ private mutedRun;
295
+ private notify;
296
+ }
297
+
298
+ export { Bottombar as B, type CellState as C, type IndicatorLoader as I, type PanelsState as P, type ResolvedIndicator as R, type SyncSetting as S, type TrackSizes as T, type VelaStorage as V, WidgetHistory as W, type RangePreset as a, type VelaShellOptions as b, type SyncOptions as c, type SyncKind as d, type WorkspaceState as e, type ChartState as f, decodeState as g, encodeState as h, type PersistedState as i, type BottombarOptions as j, type IndicatorManifest as k, type IndicatorManifestEntry as l, RANGE_PRESETS as m, type WidgetStorage as n, legacyWidgetState as o, loadPersisted as p, localStorageAdapter as q, parsePersisted as r, sanitizeState as s, resolveIndicators as t, savePersisted as u };
@@ -0,0 +1,298 @@
1
+ import { V as VisibleRangePreset } from './options-Q-576hIi.cjs';
2
+ import { D as DataProvider } from './DataProvider-DKNDHpNv.cjs';
3
+ import { S as ScriptingEngine, V as Vela } from './contributions-o1GRKPI_.cjs';
4
+
5
+ interface RangePreset {
6
+ /** Button label. */
7
+ id: string;
8
+ /** Timeframe to switch to for this range. */
9
+ tf: string;
10
+ /** The core visible-range preset framed once the chart is ready. */
11
+ preset: VisibleRangePreset;
12
+ /**
13
+ * Bars the window needs AT `tf` — the fetch budget for the rebuild. Without it the
14
+ * chart loads its default depth and the framed window is clipped to whatever
15
+ * history happens to be loaded (a "1D" that only shows 16 hours). Includes a small
16
+ * margin; `ALL` asks for as much history as the provider will serve.
17
+ */
18
+ bars: number;
19
+ }
20
+ /**
21
+ * Range chips — each pairs a timeframe, a visible window, and the fetch depth that
22
+ * window needs. Resolutions follow the reference: the shorter the range, the finer the
23
+ * bars (1 day of 1-minute bars … 5 years of weekly bars).
24
+ */
25
+ declare const RANGE_PRESETS: readonly RangePreset[];
26
+ interface BottombarOptions {
27
+ timezone: string;
28
+ onRange: (preset: RangePreset) => void;
29
+ onTimezone: (zone: string) => void;
30
+ onSettingsClick?: () => void;
31
+ }
32
+ declare class Bottombar {
33
+ readonly el: HTMLElement;
34
+ private readonly clockEl;
35
+ private readonly tzLabelEl;
36
+ private readonly tzButton;
37
+ private readonly tzMenu;
38
+ private readonly settingsTip;
39
+ private readonly rangeButtons;
40
+ private timezone;
41
+ private timer;
42
+ constructor(host: HTMLElement, opts: BottombarOptions);
43
+ setTimezone(zone: string): void;
44
+ /** Highlight (or clear with null) the active range chip — cleared on manual tf changes. */
45
+ setActiveRange(id: string | null): void;
46
+ destroy(): void;
47
+ private tzItems;
48
+ private tick;
49
+ }
50
+
51
+ interface IndicatorManifestEntry {
52
+ name: string;
53
+ /** Inline script source (one of script/url required). */
54
+ script?: string;
55
+ /** Fetch the source from here instead (resolved relative to the manifest URL). */
56
+ url?: string;
57
+ /** Engine language (default: the chart's default engine). */
58
+ language?: string;
59
+ /** Add to the chart at startup (default true). Disabled entries only appear in pickers. */
60
+ enabled?: boolean;
61
+ /** Picker grouping (default 'Indicators'). */
62
+ category?: string;
63
+ }
64
+ type IndicatorManifest = IndicatorManifestEntry[] | {
65
+ indicators: IndicatorManifestEntry[];
66
+ };
67
+ /** A manifest entry with its source resolved and ready for `chart.addIndicator`. */
68
+ interface ResolvedIndicator {
69
+ name: string;
70
+ script: string;
71
+ language?: string;
72
+ enabled: boolean;
73
+ category?: string;
74
+ }
75
+ /** An async manifest source — called once at resolution time. The escape hatch for
76
+ * manifests that a URL can't express: a filesystem read, an authenticated API, a
77
+ * bundler dynamic import. A rejection behaves like a failing manifest URL. */
78
+ type IndicatorLoader = () => Promise<IndicatorManifest>;
79
+ /** Load the indicator list: a manifest object, a URL string returning the manifest JSON,
80
+ * or an async loader function returning the manifest. Entries with `url` sources are
81
+ * fetched here too (relative to the manifest URL when there is one). Entries that fail
82
+ * to resolve are dropped with a console warning — one broken script must not take the
83
+ * chart down. */
84
+ declare function resolveIndicators(config: string | IndicatorManifest | IndicatorLoader, fetchImpl?: typeof fetch): Promise<ResolvedIndicator[]>;
85
+
86
+ /** The linkable dimensions. `crosshair` mirrors the pointer time onto same-group
87
+ * cells as GHOST crosshairs (renderers without the optional `setExternalCrosshair`
88
+ * seam simply never display one). */
89
+ type SyncKind = 'viewport' | 'symbol' | 'timeframe' | 'crosshair';
90
+ /**
91
+ * One link's configuration: `false`/absent = off; `true` = ALL cells linked (one
92
+ * implicit group); a record maps cell id → group name, and only cells sharing a group
93
+ * follow each other (a cell absent from the record is unlinked).
94
+ */
95
+ type SyncSetting = boolean | Readonly<Record<string, string>>;
96
+ interface SyncOptions {
97
+ viewport?: SyncSetting;
98
+ symbol?: SyncSetting;
99
+ timeframe?: SyncSetting;
100
+ crosshair?: SyncSetting;
101
+ }
102
+ /** Splitter track weights along each grid axis. */
103
+ interface TrackSizes {
104
+ cols?: number[];
105
+ rows?: number[];
106
+ }
107
+ /**
108
+ * The docked side panels — a SHELL-level pref (one dock serves every cell of a workspace).
109
+ * `open` is the single panel showing (the dock is exclusive); `widths` holds only the columns
110
+ * the user actually resized, by panel id, so a panel's declared width stays in charge until
111
+ * then. Absent altogether in documents written before the dock existed.
112
+ */
113
+ interface PanelsState {
114
+ open?: string;
115
+ widths?: Record<string, number>;
116
+ }
117
+ /** Per-chart (per-cell) state: the market, the display prefs, the content documents,
118
+ * and the indicator ledger. The widget's whole chart state is ONE of these. */
119
+ interface CellState {
120
+ symbol?: string;
121
+ /** The symbol's venue. Mirrors the symbol's own `EXCHANGE:` prefix on new saves;
122
+ * pre-prefix documents stored it beside a BARE symbol — {@link prefixedSymbol}
123
+ * welds the two back into the one canonical form at restore time. */
124
+ provider?: string;
125
+ timeframe?: string;
126
+ priceStyle?: string;
127
+ bars?: number;
128
+ /** Symbol watermark visibility — a per-chart display pref. */
129
+ watermark?: boolean;
130
+ /** Indicator titles (the in-chart legend rows) visibility — a per-chart display pref. */
131
+ indicatorTitles?: boolean;
132
+ /** The renderer's cosmetic config document (`renderer.getConfig()`). */
133
+ rendererConfig?: unknown;
134
+ /** The user-drawings document (`drawings.toJSON()`). */
135
+ drawings?: unknown;
136
+ /** The indicator ledger: manifest entries by name + present native types. */
137
+ indicators?: {
138
+ manifest: string[];
139
+ natives: string[];
140
+ };
141
+ }
142
+ /** One entry of the document's `charts` array: a chart's state plus its cell IDENTITY. */
143
+ interface ChartState extends CellState {
144
+ /** The cell's durable identity — its declared name (`btc`), or `c<N>` for a slot no
145
+ * entry declared. Unique within the document; array position restores slot order. */
146
+ id: string;
147
+ }
148
+ /** The versioned shell-state document — everything `applyState` restores. */
149
+ interface WorkspaceState {
150
+ version: 1;
151
+ /** The layout id — always `'1'` for a widget. Restoring an id that is not
152
+ * registered keeps the current layout — register custom layouts
153
+ * (`registerLayout`) before applying a saved state. */
154
+ layout: string;
155
+ /** Splitter track weights, per layout id (workspace only). */
156
+ trackSizes?: Record<string, TrackSizes>;
157
+ activeCellId?: string;
158
+ /** Sync links (workspace only). */
159
+ sync?: SyncOptions;
160
+ /** Shared display timezone. */
161
+ timezone?: string;
162
+ /** Favorite drawing-tool types — a SHARED preference (one star set per shell). */
163
+ favorites?: string[];
164
+ /** The docked side panels: which one is open, and the widths the user dragged. */
165
+ panels?: PanelsState;
166
+ /** Per-chart state, one entry per SLOT (a single `c1` entry for the widget).
167
+ * Ids are unique — the codec drops id-less entries and keeps the LAST duplicate. */
168
+ charts: ChartState[];
169
+ }
170
+ declare function encodeState(state: WorkspaceState): string;
171
+ /** Parse + sanitize a persisted payload. Null on anything unusable (wrong version,
172
+ * not JSON, not an object) — malformed FIELDS are dropped, never thrown on. */
173
+ declare function decodeState(raw: string): WorkspaceState | null;
174
+ /**
175
+ * Validate an untrusted state document field by field (the `applyState` gate). Unknown
176
+ * or malformed fields are dropped; nested renderer-config / drawings documents pass
177
+ * through OPAQUELY — their own consumers (`applyConfig`, `fromJSON`) validate them.
178
+ */
179
+ declare function sanitizeState(doc: unknown): WorkspaceState | null;
180
+
181
+ /** The storage contract BOTH shells persist through (the widget and the workspace —
182
+ * one name, one shape). Methods may be synchronous or return promises. */
183
+ interface VelaStorage {
184
+ get(key: string): string | null | Promise<string | null>;
185
+ set(key: string, value: string): void | Promise<void>;
186
+ remove?(key: string): void | Promise<void>;
187
+ }
188
+ /** @deprecated Use {@link VelaStorage} — same contract, shell-neutral name. */
189
+ type WidgetStorage = VelaStorage;
190
+ /**
191
+ * The default adapter — window.localStorage, silent on quota/privacy failures.
192
+ *
193
+ * `storageKey` pins the PHYSICAL localStorage entry: every read/write lands on that
194
+ * one name, whatever logical key the shell passes — the way to choose where the state
195
+ * lives without touching the `persist` option (one shell instance per adapter then;
196
+ * two shells sharing a pinned adapter would overwrite each other). Omitted, the
197
+ * shell's own key is used as-is (the historical behavior).
198
+ */
199
+ declare function localStorageAdapter(storageKey?: string): WidgetStorage;
200
+ interface PersistedState {
201
+ symbol?: string;
202
+ timeframe?: string;
203
+ priceStyle?: string;
204
+ timezone?: string;
205
+ bars?: string;
206
+ watermark?: string;
207
+ /** Comma-joined favorite drawing-tool types. */
208
+ favorites?: string;
209
+ }
210
+ /** Parse a LEGACY prefs payload (never throws — junk yields `{}`). */
211
+ declare function parsePersisted(raw: string | null): PersistedState;
212
+ /** Load the persisted state — synchronous result for sync storages, else a promise. */
213
+ declare function loadPersisted(storage: WidgetStorage, storageKey: string): PersistedState | Promise<PersistedState>;
214
+ /** Save (fire-and-forget — async adapter failures are the adapter's concern). */
215
+ declare function savePersisted(storage: WidgetStorage, storageKey: string, state: PersistedState): void;
216
+ /**
217
+ * LEGACY migration — convert the widget's pre-unified three-key layout (prefs under
218
+ * the main key, renderer config under `<key>:config`, drawings under `<key>:drawings`)
219
+ * into ONE unified state document (the same format the workspace persists, with a
220
+ * single `c1` cell). Null when the payload holds no usable state. Pure — the caller
221
+ * reads the keys, then rewrites the main key and drops the legacy sub-keys.
222
+ */
223
+ declare function legacyWidgetState(prefs: PersistedState, rawConfig: string | null, rawDrawings: string | null): WorkspaceState | null;
224
+
225
+ /** What a shell (widget or workspace) accepts BEYOND the chart options themselves. */
226
+ interface VelaShellOptions {
227
+ /** Provider factories, keyed by provider name. The shell owns the call cycle: the
228
+ * widget re-instantiates on each chart rebuild; the workspace instantiates once
229
+ * onto its single shared feed. */
230
+ providers?: Record<string, () => DataProvider>;
231
+ /** Scripting-engine factories, keyed by language — ONE instance per chart (the
232
+ * widget's chart, each workspace cell), so a worker engine gets its own thread and
233
+ * dies with its chart. Return a shared instance from the factory to opt into one
234
+ * engine for everything. Merged OVER the app-level `registerDefaultEngine`
235
+ * registry — an instance factory wins for its language. */
236
+ engines?: Record<string, () => ScriptingEngine>;
237
+ /** Indicator manifest: inline, a URL returning it, or an ASYNC LOADER function
238
+ * (`() => Promise<manifest>` — filesystem reads, authenticated APIs, dynamic
239
+ * imports). Resolved ONCE; entries with `enabled: true` auto-add to every FRESH
240
+ * chart (restored cells re-add their own recorded set instead). */
241
+ indicators?: string | IndicatorManifest | IndicatorLoader;
242
+ /** Topbar timeframe presets (chart timeframe values). */
243
+ timeframes?: string[];
244
+ /** Display timezone (IANA; default 'Etc/UTC') — one zone for the whole shell. */
245
+ timezone?: string;
246
+ /** Chrome toggles (all default true). */
247
+ statusline?: boolean;
248
+ watermark?: boolean;
249
+ bottombar?: boolean;
250
+ /** Focus the chart when the shell mounts so keyboard shortcuts work from the first
251
+ * keystroke — no initial click needed. Default false: an embedded shell must never
252
+ * steal the page's focus from the host's own controls. */
253
+ autofocus?: boolean;
254
+ /** Bring the shell back AS YOU LEFT IT: persist the full state document
255
+ * (`getState()`) and restore it at construction. `true` uses the shell's default
256
+ * key ('vela-widget' / 'vela-workspace'); a string is the storage key. */
257
+ persist?: boolean | string;
258
+ /** Storage backend for `persist` — defaults to localStorage in BOTH shells. Inject
259
+ * any {@link VelaStorage} (sync or async) for custom backends (REST, IndexedDB, …)
260
+ * or the exported in-memory adapter for session-lived state. */
261
+ storage?: VelaStorage;
262
+ }
263
+
264
+ interface HistoryAction {
265
+ undo(): void;
266
+ redo(): void;
267
+ }
268
+ declare class WidgetHistory {
269
+ private readonly getChart;
270
+ private readonly undoStack;
271
+ private readonly redoStack;
272
+ private readonly listeners;
273
+ private unsubs;
274
+ private muted;
275
+ /** `getChart` late-resolves the CURRENT chart: drawing steps recorded before a chart
276
+ * rebuild must undo on the chart that exists when the user presses Ctrl+Z, not on a
277
+ * destroyed instance captured at record time. */
278
+ constructor(getChart?: () => Vela | null);
279
+ /** Record a reversible action (a fresh edit forks history: redo branch clears). */
280
+ push(action: HistoryAction): void;
281
+ undo(): void;
282
+ redo(): void;
283
+ /** Run `fn` without recording — for programmatic state application (setState,
284
+ * ledger restore), whose indicator/drawing events are not user edits. */
285
+ silently(fn: () => void): void;
286
+ get canUndo(): boolean;
287
+ get canRedo(): boolean;
288
+ onChange(cb: () => void): () => void;
289
+ /** (Re)bind to a chart: drawing edits enter the unified stack as delegate steps. */
290
+ onChart(chart: Vela): void;
291
+ destroy(): void;
292
+ private pushDrawingStep;
293
+ /** Replaying an action must not re-record the drawing events it triggers. */
294
+ private mutedRun;
295
+ private notify;
296
+ }
297
+
298
+ export { Bottombar as B, type CellState as C, type IndicatorLoader as I, type PanelsState as P, type ResolvedIndicator as R, type SyncSetting as S, type TrackSizes as T, type VelaStorage as V, WidgetHistory as W, type RangePreset as a, type VelaShellOptions as b, type SyncOptions as c, type SyncKind as d, type WorkspaceState as e, type ChartState as f, decodeState as g, encodeState as h, type PersistedState as i, type BottombarOptions as j, type IndicatorManifest as k, type IndicatorManifestEntry as l, RANGE_PRESETS as m, type WidgetStorage as n, legacyWidgetState as o, loadPersisted as p, localStorageAdapter as q, parsePersisted as r, sanitizeState as s, resolveIndicators as t, savePersisted as u };
@@ -0,0 +1,10 @@
1
+ /** Register (or replace) an icon's raw `<svg>` markup under an id. */
2
+ declare function registerIcon(id: string, svg: string): void;
3
+ /** The raw `<svg>` markup for an id, or null. */
4
+ declare function iconMarkup(id: string): string | null;
5
+ /** Tier A: a 16×16 chrome icon. `extra` overrides root attributes (e.g. a filled variant). */
6
+ declare function svg16(body: string, extra?: string): string;
7
+ /** Tier B: a 24×24 drawing-tool icon. `extra` overrides root attributes. */
8
+ declare function svg24(body: string, extra?: string): string;
9
+
10
+ export { svg24 as a, iconMarkup as i, registerIcon as r, svg16 as s };
@@ -0,0 +1,10 @@
1
+ /** Register (or replace) an icon's raw `<svg>` markup under an id. */
2
+ declare function registerIcon(id: string, svg: string): void;
3
+ /** The raw `<svg>` markup for an id, or null. */
4
+ declare function iconMarkup(id: string): string | null;
5
+ /** Tier A: a 16×16 chrome icon. `extra` overrides root attributes (e.g. a filled variant). */
6
+ declare function svg16(body: string, extra?: string): string;
7
+ /** Tier B: a 24×24 drawing-tool icon. `extra` overrides root attributes. */
8
+ declare function svg24(body: string, extra?: string): string;
9
+
10
+ export { svg24 as a, iconMarkup as i, registerIcon as r, svg16 as s };