@coderyo/core 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +164 -7
- package/dist/index.js +772 -100
- package/dist/index.js.map +1 -1
- package/package.json +21 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
|
+
import * as _coderyo_indicators from '@coderyo/indicators';
|
|
2
|
+
import { IndicatorConfig, IndicatorLayerInfo, IndicatorLayerId } from '@coderyo/indicators';
|
|
3
|
+
export { DEFAULT_INDICATOR_CONFIG, IndicatorConfig, IndicatorLayerId, IndicatorLayerInfo, IndicatorSource, clearedIndicatorConfig, disableIndicatorLayer, hasAnyActiveIndicators, hasMainChartOverlays, hasVisibleIndicatorPanes, indicatorConfigStorageKey, listActiveIndicatorLayers } from '@coderyo/indicators';
|
|
1
4
|
import * as _coderyo_drawings from '@coderyo/drawings';
|
|
2
5
|
import { DrawingRecord, DrawingStyleMeta } from '@coderyo/drawings';
|
|
3
6
|
import * as _coderyo_data from '@coderyo/data';
|
|
4
7
|
import { RealtimeStreamMode, Interval, DataProvider, SymbolResolver, Bar } from '@coderyo/data';
|
|
5
|
-
import { IndicatorConfig } from '@coderyo/indicators';
|
|
6
8
|
import { FetchPolicy } from '@coderyo/virtual-window';
|
|
7
|
-
import
|
|
9
|
+
import * as _coderyo_renderer_lite from '@coderyo/renderer-lite';
|
|
10
|
+
import { ChartPaneId, ChartVisibleRange } from '@coderyo/renderer-lite';
|
|
8
11
|
export { ChartVisibleRange } from '@coderyo/renderer-lite';
|
|
9
|
-
import { BridgeAdapter, BridgeOutboundType } from '@coderyo/bridge';
|
|
12
|
+
import { BridgeLayerPane, BridgeAdapter, BridgeOutboundType } from '@coderyo/bridge';
|
|
10
13
|
export { PINE_EDITOR_DEFAULT, PINE_SAMPLE_SCRIPT, PineCompileResult, PineIrProgram, PinePlotSeries, compilePineLite, runPineLite } from '@coderyo/pine-lite';
|
|
11
14
|
|
|
15
|
+
/** Layer fields used to map layout preset chart panes → renderer sync groups. */
|
|
16
|
+
type LayerSyncInput = {
|
|
17
|
+
type: string;
|
|
18
|
+
pageId?: string;
|
|
19
|
+
syncTimeScaleGroupId?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Per-pane patch: `string` = shared group; `null` = independent; `undefined` = pane absent on scope. */
|
|
22
|
+
type PaneSyncGroupPatch = {
|
|
23
|
+
main?: string | null;
|
|
24
|
+
volume?: string | null;
|
|
25
|
+
indicator?: string | null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve pane sync group ids from layout layers.
|
|
29
|
+
* When `pageId` is set, only layers on that page are considered (multi-page presets).
|
|
30
|
+
*/
|
|
31
|
+
declare function resolvePaneSyncGroupsFromLayers(layers: LayerSyncInput[], pageId?: string): PaneSyncGroupPatch;
|
|
32
|
+
|
|
12
33
|
interface ChartGapsFeatures {
|
|
13
34
|
whitespace?: boolean;
|
|
14
35
|
fillVisibleHoles?: boolean;
|
|
@@ -40,6 +61,13 @@ interface ChartFeatures {
|
|
|
40
61
|
tickStream?: boolean;
|
|
41
62
|
/** Run Pine-lite VM in a Web Worker when available (default true). */
|
|
42
63
|
pineWorker?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* On interval/symbol reload, set bar spacing (px) for the interval (default true).
|
|
66
|
+
* Does not choose how many bars are visible — use history limit / setVisibleRange.
|
|
67
|
+
*/
|
|
68
|
+
autoBarSpacingOnInterval?: boolean;
|
|
69
|
+
/** Override default bar spacing per interval (integrator). */
|
|
70
|
+
barSpacingByInterval?: Partial<Record<Interval, number>>;
|
|
43
71
|
}
|
|
44
72
|
interface ResolvedChartFeatures {
|
|
45
73
|
fetchPolicy: FetchPolicy;
|
|
@@ -56,12 +84,24 @@ interface ResolvedChartFeatures {
|
|
|
56
84
|
telemetry: boolean;
|
|
57
85
|
tickStream: boolean;
|
|
58
86
|
pineWorker: boolean;
|
|
87
|
+
autoBarSpacingOnInterval: boolean;
|
|
88
|
+
barSpacingByInterval?: Partial<Record<Interval, number>>;
|
|
59
89
|
}
|
|
60
90
|
declare const DEFAULT_CHART_FEATURES: ResolvedChartFeatures;
|
|
61
91
|
declare function resolveChartFeatures(partial?: ChartFeatures): ResolvedChartFeatures;
|
|
62
92
|
/** Empty chart until integrator calls setSymbol. */
|
|
63
93
|
declare const PENDING_SYMBOL = "";
|
|
64
94
|
|
|
95
|
+
/** Pluggable key-value storage for `indicatorPersist` (default: `localStorage`). */
|
|
96
|
+
interface ChartStorageAdapter {
|
|
97
|
+
getItem(key: string): string | null;
|
|
98
|
+
setItem(key: string, value: string): void;
|
|
99
|
+
}
|
|
100
|
+
declare function createLocalChartStorage(): ChartStorageAdapter;
|
|
101
|
+
declare const defaultChartStorage: ChartStorageAdapter;
|
|
102
|
+
declare function loadIndicatorConfig(storage: ChartStorageAdapter, symbol: string, interval: string): IndicatorConfig;
|
|
103
|
+
declare function saveIndicatorConfig(storage: ChartStorageAdapter, symbol: string, interval: string, config: IndicatorConfig): void;
|
|
104
|
+
|
|
65
105
|
interface ChartOptions {
|
|
66
106
|
width?: number;
|
|
67
107
|
height?: number;
|
|
@@ -72,6 +112,8 @@ interface ChartOptions {
|
|
|
72
112
|
chartId?: string;
|
|
73
113
|
/** Host element below main chart for MACD/RSI/KDJ panes (from ui-shell layout). */
|
|
74
114
|
indicatorHost?: HTMLElement;
|
|
115
|
+
/** P2: separate volume pane mount (layer compositor). */
|
|
116
|
+
volumeMount?: HTMLElement;
|
|
75
117
|
dataProvider: DataProvider;
|
|
76
118
|
/** Integrator feature flags (minimal defaults). */
|
|
77
119
|
features?: ChartFeatures;
|
|
@@ -86,6 +128,8 @@ interface ChartOptions {
|
|
|
86
128
|
};
|
|
87
129
|
/** @deprecated Use features.indicators */
|
|
88
130
|
indicatorConfig?: IndicatorConfig;
|
|
131
|
+
/** Storage backend for `features.indicatorPersist` (default `localStorage`). */
|
|
132
|
+
chartStorage?: ChartStorageAdapter;
|
|
89
133
|
}
|
|
90
134
|
type ChartEvent = 'connectionChange' | 'barUpdate' | 'error' | 'visibleRangeChange' | 'symbolChange' | 'intervalChange' | 'crosshairChange' | 'destroyed' | 'drawingSelectionChange' | 'drawingContextMenu' | 'requestCursorTool' | 'featuresChange' | 'telemetry';
|
|
91
135
|
type EventHandler = (payload?: unknown) => void;
|
|
@@ -93,7 +137,9 @@ declare class ChartController {
|
|
|
93
137
|
private readonly container;
|
|
94
138
|
private readonly options;
|
|
95
139
|
private readonly store;
|
|
96
|
-
private
|
|
140
|
+
private fetchPolicy;
|
|
141
|
+
/** Per sync-group viewport for loadMore / render slicing (active bus drives IChart APIs). */
|
|
142
|
+
private readonly virtualWindows;
|
|
97
143
|
private readonly orchestrator;
|
|
98
144
|
private readonly handlers;
|
|
99
145
|
private subscriptionId;
|
|
@@ -111,10 +157,15 @@ declare class ChartController {
|
|
|
111
157
|
private catchUpInFlight;
|
|
112
158
|
private lastCatchUpAt;
|
|
113
159
|
private offPageResume;
|
|
160
|
+
/** After clearAllIndicators(); blocks Pine replot until script/features change. */
|
|
161
|
+
private pinePlotsSuppressed;
|
|
162
|
+
private readonly chartStorage;
|
|
163
|
+
private readonly onPaneResize;
|
|
114
164
|
constructor(container: HTMLElement, options: ChartOptions);
|
|
115
165
|
getFeatures(): ResolvedChartFeatures;
|
|
116
166
|
setFeatures(patch: ChartFeatures): this;
|
|
117
167
|
hasActiveSymbol(): boolean;
|
|
168
|
+
private activeVirtualWindow;
|
|
118
169
|
private applyFeatures;
|
|
119
170
|
private recompilePine;
|
|
120
171
|
private applyPinePlots;
|
|
@@ -138,6 +189,10 @@ declare class ChartController {
|
|
|
138
189
|
width?: number;
|
|
139
190
|
height?: number;
|
|
140
191
|
}): this;
|
|
192
|
+
/** P2: limit LWC resize to focused panes; also selects that pane's time-scale sync group for IChart APIs. */
|
|
193
|
+
setChartPaneResizeFocus(pane: ChartPaneId | 'all'): this;
|
|
194
|
+
/** Apply `syncTimeScaleGroupId` from layout layers to pane buses (empty = independent). */
|
|
195
|
+
applyTimeScaleSyncFromLayers(layers: LayerSyncInput[], pageId?: string): this;
|
|
141
196
|
setDrawingTool(tool: _coderyo_drawings.DrawingTool): this;
|
|
142
197
|
deleteSelectedDrawing(): boolean;
|
|
143
198
|
copySelectedDrawing(): DrawingRecord | null;
|
|
@@ -145,6 +200,14 @@ declare class ChartController {
|
|
|
145
200
|
updateSelectedDrawingStyle(patch: DrawingStyleMeta): void;
|
|
146
201
|
deselectDrawing(): void;
|
|
147
202
|
setIndicatorConfig(config: IndicatorConfig | null): void;
|
|
203
|
+
private applyPersistedIndicatorsOnInit;
|
|
204
|
+
private applyPersistedIndicatorsForContext;
|
|
205
|
+
/** @public List built-in indicator layers currently enabled on the chart. */
|
|
206
|
+
listIndicatorLayers(): IndicatorLayerInfo[];
|
|
207
|
+
/** @public Disable a single built-in indicator layer by id. */
|
|
208
|
+
disableIndicatorLayer(id: IndicatorLayerId): IndicatorConfig;
|
|
209
|
+
clearAllIndicators(): IndicatorConfig;
|
|
210
|
+
clearAllDrawings(): number;
|
|
148
211
|
setReturnToCursorAfterDraw(v: boolean): void;
|
|
149
212
|
setSymbol(symbol: string): Promise<void>;
|
|
150
213
|
setInterval(interval: Interval): Promise<void>;
|
|
@@ -178,7 +241,76 @@ declare class ChartController {
|
|
|
178
241
|
private emit;
|
|
179
242
|
}
|
|
180
243
|
|
|
244
|
+
/** Minimal chart surface for layer time-scale sync (matches `IChart.applyTimeScaleSyncFromLayers`). */
|
|
245
|
+
interface LayerTimeScaleSyncChart {
|
|
246
|
+
applyTimeScaleSyncFromLayers(layers: Array<{
|
|
247
|
+
type: string;
|
|
248
|
+
pageId?: string;
|
|
249
|
+
syncTimeScaleGroupId?: string;
|
|
250
|
+
}>, pageId?: string): unknown;
|
|
251
|
+
}
|
|
252
|
+
type LayerBridgePane = BridgeLayerPane;
|
|
253
|
+
interface LayerBridgePreset {
|
|
254
|
+
version?: number;
|
|
255
|
+
revision?: number;
|
|
256
|
+
pages: Array<{
|
|
257
|
+
id: string;
|
|
258
|
+
title?: string;
|
|
259
|
+
}>;
|
|
260
|
+
layers: Array<{
|
|
261
|
+
id: string;
|
|
262
|
+
pageId: string;
|
|
263
|
+
type: string;
|
|
264
|
+
syncTimeScaleGroupId?: string;
|
|
265
|
+
visible?: boolean;
|
|
266
|
+
}>;
|
|
267
|
+
groups: Array<{
|
|
268
|
+
id: string;
|
|
269
|
+
layerIds?: string[];
|
|
270
|
+
name?: string;
|
|
271
|
+
}>;
|
|
272
|
+
[key: string]: unknown;
|
|
273
|
+
}
|
|
274
|
+
/** Minimal LayerController surface for bridge wiring (avoids ui-shell in tests). */
|
|
275
|
+
interface LayerBridgeController {
|
|
276
|
+
activePageId: string;
|
|
277
|
+
presetRevision: number;
|
|
278
|
+
getPreset(): LayerBridgePreset;
|
|
279
|
+
setLayerSyncGroup(layerId: string, groupId: string | null | undefined): boolean;
|
|
280
|
+
setLayerVisible(layerId: string, visible: boolean): void;
|
|
281
|
+
setActivePage(pageId: string): boolean;
|
|
282
|
+
setPreset(next: LayerBridgePreset): boolean;
|
|
283
|
+
}
|
|
284
|
+
interface ChartLayerBridgeRegistration {
|
|
285
|
+
chartId: string;
|
|
286
|
+
chart: LayerTimeScaleSyncChart;
|
|
287
|
+
layerController: LayerBridgeController;
|
|
288
|
+
compositorApply?: () => void;
|
|
289
|
+
syncCompositorShellVisibility?: () => void;
|
|
290
|
+
normalizePreset?: (input: LayerBridgePreset) => LayerBridgePreset;
|
|
291
|
+
mergePreset?: (current: LayerBridgePreset, partial: LayerBridgePreset) => LayerBridgePreset;
|
|
292
|
+
}
|
|
293
|
+
declare function registerChartLayerBridge(reg: ChartLayerBridgeRegistration): () => void;
|
|
294
|
+
declare function unregisterChartLayerBridge(chartId: string): void;
|
|
295
|
+
declare function clearLayerBridgeVisitedPages(chartId: string): void;
|
|
296
|
+
declare function hasLayerBridgeRegistration(chartId?: string): boolean;
|
|
297
|
+
declare function isValidLayerBridgePane(pane: unknown): pane is LayerBridgePane;
|
|
298
|
+
/** Resolve chart pane → layer ids (`allPages` scans every page). */
|
|
299
|
+
declare function resolvePaneLayerIds(preset: Pick<LayerBridgePreset, 'layers' | 'pages'>, pane: LayerBridgePane, opts?: {
|
|
300
|
+
allPages?: boolean;
|
|
301
|
+
activePageId?: string;
|
|
302
|
+
}): string[];
|
|
303
|
+
interface HandleLayerBridgeMessageOptions {
|
|
304
|
+
bridge: BridgeAdapter;
|
|
305
|
+
post: (type: string, payload: Record<string, unknown>) => void;
|
|
306
|
+
}
|
|
307
|
+
/** Handle a single inbound `host.layer.*` message; returns true if handled. */
|
|
308
|
+
declare function handleLayerBridgeMessage(type: string, payload: Record<string, unknown>, opts: HandleLayerBridgeMessageOptions): boolean;
|
|
309
|
+
/** Expose resolved sync groups for tests (same as chart `applyTimeScaleSyncFromLayers`). */
|
|
310
|
+
declare function resolvePaneSyncGroupsForBridge(layers: LayerBridgePreset['layers'], pageId?: string): PaneSyncGroupPatch;
|
|
311
|
+
|
|
181
312
|
declare const TRADVIEW_API_VERSION: 1;
|
|
313
|
+
|
|
182
314
|
interface WireChartBridgeOptions {
|
|
183
315
|
controller: ChartController;
|
|
184
316
|
chart: IChart;
|
|
@@ -187,18 +319,21 @@ interface WireChartBridgeOptions {
|
|
|
187
319
|
/** Allowlist of outbound bridge events; default all mapped events. */
|
|
188
320
|
outboundEvents?: BridgeOutboundType[];
|
|
189
321
|
crosshairThrottleMs?: number;
|
|
322
|
+
/** Schema 2 layer bridge (register via `registerChartLayerBridge` or pass here). */
|
|
323
|
+
layerBridge?: ChartLayerBridgeRegistration;
|
|
190
324
|
}
|
|
325
|
+
/** @public Wire host bridge messages to chart + controller events. */
|
|
191
326
|
declare function wireChartBridge(opts: WireChartBridgeOptions): () => void;
|
|
192
327
|
|
|
193
328
|
/** Synced by scripts/sync-versions.mjs from repo VERSION file */
|
|
194
|
-
declare const TRADVIEW_VERSION: "1.0
|
|
329
|
+
declare const TRADVIEW_VERSION: "1.1.0";
|
|
195
330
|
|
|
196
331
|
/** Playground / docs: opt-in full TV-like chart features. */
|
|
197
332
|
declare function createDemoChartFeatures(opts: {
|
|
198
333
|
indicatorConfig?: IndicatorConfig;
|
|
199
334
|
returnToCursorAfterDraw?: boolean;
|
|
200
335
|
}): ChartFeatures;
|
|
201
|
-
declare function createDemoChartOptions(base: Pick<ChartOptions, 'dataProvider' | 'indicatorHost' | 'symbolResolver' | 'chartId'> & {
|
|
336
|
+
declare function createDemoChartOptions(base: Pick<ChartOptions, 'dataProvider' | 'indicatorHost' | 'volumeMount' | 'symbolResolver' | 'chartId'> & {
|
|
202
337
|
symbol: string;
|
|
203
338
|
interval: Interval;
|
|
204
339
|
theme?: 'dark' | 'light';
|
|
@@ -214,7 +349,10 @@ interface CreateChartOptions extends Omit<ChartOptions, 'dataProvider'> {
|
|
|
214
349
|
/** If set, only these bridge outbound events are posted. */
|
|
215
350
|
bridgeOutboundEvents?: BridgeOutboundType[];
|
|
216
351
|
bridgeCrosshairThrottleMs?: number;
|
|
352
|
+
/** Schema 2: remote layer control (`host.layer.*`). */
|
|
353
|
+
layerBridge?: ChartLayerBridgeRegistration;
|
|
217
354
|
}
|
|
355
|
+
/** @public Chart instance API for integrators (apiVersion 1). */
|
|
218
356
|
interface IChart {
|
|
219
357
|
setSymbol(symbol: string): IChart;
|
|
220
358
|
setInterval(interval: _coderyo_data.Interval): IChart;
|
|
@@ -238,6 +376,13 @@ interface IChart {
|
|
|
238
376
|
width?: number;
|
|
239
377
|
height?: number;
|
|
240
378
|
}): IChart;
|
|
379
|
+
setChartPaneResizeFocus(pane: _coderyo_renderer_lite.ChartPaneId | 'all'): IChart;
|
|
380
|
+
/** Apply layout layer `syncTimeScaleGroupId` values to renderer pane buses. */
|
|
381
|
+
applyTimeScaleSyncFromLayers(layers: Array<{
|
|
382
|
+
type: string;
|
|
383
|
+
pageId?: string;
|
|
384
|
+
syncTimeScaleGroupId?: string;
|
|
385
|
+
}>, pageId?: string): IChart;
|
|
241
386
|
setFullscreen(enabled: boolean): IChart;
|
|
242
387
|
exportImage(opts?: {
|
|
243
388
|
pixelRatio?: number;
|
|
@@ -252,6 +397,14 @@ interface IChart {
|
|
|
252
397
|
updateSelectedDrawingStyle(patch: DrawingStyleMeta): void;
|
|
253
398
|
deselectDrawing(): void;
|
|
254
399
|
setIndicatorConfig(config: IndicatorConfig | null): void;
|
|
400
|
+
/** @public List enabled built-in indicator layers (MA, MACD, volume pane, etc.). */
|
|
401
|
+
listIndicatorLayers(): _coderyo_indicators.IndicatorLayerInfo[];
|
|
402
|
+
/** @public Disable one built-in indicator layer; returns applied config. */
|
|
403
|
+
disableIndicatorLayer(id: _coderyo_indicators.IndicatorLayerId): IndicatorConfig;
|
|
404
|
+
/** Hide all indicator panes and overlays; returns the applied config. */
|
|
405
|
+
clearAllIndicators(): IndicatorConfig;
|
|
406
|
+
/** Remove all drawings for the current symbol/interval; returns count removed. */
|
|
407
|
+
clearAllDrawings(): number;
|
|
255
408
|
setReturnToCursorAfterDraw(v: boolean): void;
|
|
256
409
|
setFeatures(patch: ChartFeatures): IChart;
|
|
257
410
|
getFeatures(): ResolvedChartFeatures;
|
|
@@ -263,6 +416,10 @@ interface IChart {
|
|
|
263
416
|
subscribeBars(handler: (bar: _coderyo_data.Bar) => void): () => void;
|
|
264
417
|
destroy(): void;
|
|
265
418
|
}
|
|
419
|
+
/** @public Create a chart in the given container. */
|
|
266
420
|
declare function createChart(target: HTMLElement | string, options: CreateChartOptions): IChart;
|
|
267
421
|
|
|
268
|
-
|
|
422
|
+
/** @public Upsert merge for Bridge `host.layer.setPreset` (`replace: false`). */
|
|
423
|
+
declare function mergeLayerBridgePreset(current: LayerBridgePreset, partial: LayerBridgePreset): LayerBridgePreset;
|
|
424
|
+
|
|
425
|
+
export { ChartController, type ChartEvent, type ChartFeatures, type ChartLayerBridgeRegistration, type ChartOptions, type ChartStorageAdapter, type CreateChartOptions, DEFAULT_CHART_FEATURES, type IChart, type LayerBridgeController, type LayerBridgePane, type LayerBridgePreset, type LayerSyncInput, type LayerTimeScaleSyncChart, PENDING_SYMBOL, type PaneSyncGroupPatch, type ResolvedChartFeatures, TRADVIEW_API_VERSION, TRADVIEW_VERSION, type WireChartBridgeOptions, clearLayerBridgeVisitedPages, createChart, createDemoChartFeatures, createDemoChartOptions, createLocalChartStorage, defaultChartStorage, handleLayerBridgeMessage, hasLayerBridgeRegistration, isValidLayerBridgePane, loadIndicatorConfig, mergeLayerBridgePreset, registerChartLayerBridge, resolveChartFeatures, resolvePaneLayerIds, resolvePaneSyncGroupsForBridge, resolvePaneSyncGroupsFromLayers, saveIndicatorConfig, unregisterChartLayerBridge, wireChartBridge };
|