@coderyo/core 1.0.3 → 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 CHANGED
@@ -1,15 +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
- export { DEFAULT_INDICATOR_CONFIG, IndicatorConfig, IndicatorSource, clearedIndicatorConfig, hasAnyActiveIndicators, hasMainChartOverlays, hasVisibleIndicatorPanes, indicatorConfigStorageKey } from '@coderyo/indicators';
7
8
  import { FetchPolicy } from '@coderyo/virtual-window';
8
- import { ChartVisibleRange } from '@coderyo/renderer-lite';
9
+ import * as _coderyo_renderer_lite from '@coderyo/renderer-lite';
10
+ import { ChartPaneId, ChartVisibleRange } from '@coderyo/renderer-lite';
9
11
  export { ChartVisibleRange } from '@coderyo/renderer-lite';
10
- import { BridgeAdapter, BridgeOutboundType } from '@coderyo/bridge';
12
+ import { BridgeLayerPane, BridgeAdapter, BridgeOutboundType } from '@coderyo/bridge';
11
13
  export { PINE_EDITOR_DEFAULT, PINE_SAMPLE_SCRIPT, PineCompileResult, PineIrProgram, PinePlotSeries, compilePineLite, runPineLite } from '@coderyo/pine-lite';
12
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
+
13
33
  interface ChartGapsFeatures {
14
34
  whitespace?: boolean;
15
35
  fillVisibleHoles?: boolean;
@@ -92,6 +112,8 @@ interface ChartOptions {
92
112
  chartId?: string;
93
113
  /** Host element below main chart for MACD/RSI/KDJ panes (from ui-shell layout). */
94
114
  indicatorHost?: HTMLElement;
115
+ /** P2: separate volume pane mount (layer compositor). */
116
+ volumeMount?: HTMLElement;
95
117
  dataProvider: DataProvider;
96
118
  /** Integrator feature flags (minimal defaults). */
97
119
  features?: ChartFeatures;
@@ -115,7 +137,9 @@ declare class ChartController {
115
137
  private readonly container;
116
138
  private readonly options;
117
139
  private readonly store;
118
- private readonly virtualWindow;
140
+ private fetchPolicy;
141
+ /** Per sync-group viewport for loadMore / render slicing (active bus drives IChart APIs). */
142
+ private readonly virtualWindows;
119
143
  private readonly orchestrator;
120
144
  private readonly handlers;
121
145
  private subscriptionId;
@@ -136,10 +160,12 @@ declare class ChartController {
136
160
  /** After clearAllIndicators(); blocks Pine replot until script/features change. */
137
161
  private pinePlotsSuppressed;
138
162
  private readonly chartStorage;
163
+ private readonly onPaneResize;
139
164
  constructor(container: HTMLElement, options: ChartOptions);
140
165
  getFeatures(): ResolvedChartFeatures;
141
166
  setFeatures(patch: ChartFeatures): this;
142
167
  hasActiveSymbol(): boolean;
168
+ private activeVirtualWindow;
143
169
  private applyFeatures;
144
170
  private recompilePine;
145
171
  private applyPinePlots;
@@ -163,6 +189,10 @@ declare class ChartController {
163
189
  width?: number;
164
190
  height?: number;
165
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;
166
196
  setDrawingTool(tool: _coderyo_drawings.DrawingTool): this;
167
197
  deleteSelectedDrawing(): boolean;
168
198
  copySelectedDrawing(): DrawingRecord | null;
@@ -172,6 +202,10 @@ declare class ChartController {
172
202
  setIndicatorConfig(config: IndicatorConfig | null): void;
173
203
  private applyPersistedIndicatorsOnInit;
174
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;
175
209
  clearAllIndicators(): IndicatorConfig;
176
210
  clearAllDrawings(): number;
177
211
  setReturnToCursorAfterDraw(v: boolean): void;
@@ -207,7 +241,76 @@ declare class ChartController {
207
241
  private emit;
208
242
  }
209
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
+
210
312
  declare const TRADVIEW_API_VERSION: 1;
313
+
211
314
  interface WireChartBridgeOptions {
212
315
  controller: ChartController;
213
316
  chart: IChart;
@@ -216,18 +319,21 @@ interface WireChartBridgeOptions {
216
319
  /** Allowlist of outbound bridge events; default all mapped events. */
217
320
  outboundEvents?: BridgeOutboundType[];
218
321
  crosshairThrottleMs?: number;
322
+ /** Schema 2 layer bridge (register via `registerChartLayerBridge` or pass here). */
323
+ layerBridge?: ChartLayerBridgeRegistration;
219
324
  }
325
+ /** @public Wire host bridge messages to chart + controller events. */
220
326
  declare function wireChartBridge(opts: WireChartBridgeOptions): () => void;
221
327
 
222
328
  /** Synced by scripts/sync-versions.mjs from repo VERSION file */
223
- declare const TRADVIEW_VERSION: "1.0.3";
329
+ declare const TRADVIEW_VERSION: "1.1.0";
224
330
 
225
331
  /** Playground / docs: opt-in full TV-like chart features. */
226
332
  declare function createDemoChartFeatures(opts: {
227
333
  indicatorConfig?: IndicatorConfig;
228
334
  returnToCursorAfterDraw?: boolean;
229
335
  }): ChartFeatures;
230
- declare function createDemoChartOptions(base: Pick<ChartOptions, 'dataProvider' | 'indicatorHost' | 'symbolResolver' | 'chartId'> & {
336
+ declare function createDemoChartOptions(base: Pick<ChartOptions, 'dataProvider' | 'indicatorHost' | 'volumeMount' | 'symbolResolver' | 'chartId'> & {
231
337
  symbol: string;
232
338
  interval: Interval;
233
339
  theme?: 'dark' | 'light';
@@ -243,7 +349,10 @@ interface CreateChartOptions extends Omit<ChartOptions, 'dataProvider'> {
243
349
  /** If set, only these bridge outbound events are posted. */
244
350
  bridgeOutboundEvents?: BridgeOutboundType[];
245
351
  bridgeCrosshairThrottleMs?: number;
352
+ /** Schema 2: remote layer control (`host.layer.*`). */
353
+ layerBridge?: ChartLayerBridgeRegistration;
246
354
  }
355
+ /** @public Chart instance API for integrators (apiVersion 1). */
247
356
  interface IChart {
248
357
  setSymbol(symbol: string): IChart;
249
358
  setInterval(interval: _coderyo_data.Interval): IChart;
@@ -267,6 +376,13 @@ interface IChart {
267
376
  width?: number;
268
377
  height?: number;
269
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;
270
386
  setFullscreen(enabled: boolean): IChart;
271
387
  exportImage(opts?: {
272
388
  pixelRatio?: number;
@@ -281,6 +397,10 @@ interface IChart {
281
397
  updateSelectedDrawingStyle(patch: DrawingStyleMeta): void;
282
398
  deselectDrawing(): void;
283
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;
284
404
  /** Hide all indicator panes and overlays; returns the applied config. */
285
405
  clearAllIndicators(): IndicatorConfig;
286
406
  /** Remove all drawings for the current symbol/interval; returns count removed. */
@@ -296,6 +416,10 @@ interface IChart {
296
416
  subscribeBars(handler: (bar: _coderyo_data.Bar) => void): () => void;
297
417
  destroy(): void;
298
418
  }
419
+ /** @public Create a chart in the given container. */
299
420
  declare function createChart(target: HTMLElement | string, options: CreateChartOptions): IChart;
300
421
 
301
- export { ChartController, type ChartEvent, type ChartFeatures, type ChartOptions, type ChartStorageAdapter, type CreateChartOptions, DEFAULT_CHART_FEATURES, type IChart, PENDING_SYMBOL, type ResolvedChartFeatures, TRADVIEW_API_VERSION, TRADVIEW_VERSION, type WireChartBridgeOptions, createChart, createDemoChartFeatures, createDemoChartOptions, createLocalChartStorage, defaultChartStorage, loadIndicatorConfig, resolveChartFeatures, saveIndicatorConfig, wireChartBridge };
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 };