import { createChart, CandlestickSeries, BarSeries, LineSeries, AreaSeries, BaselineSeries, HistogramSeries, createSeriesMarkers, type IChartApi, type ISeriesApi, type SeriesType, type MouseEventParams, type Time, type IPriceLine, type ISeriesMarkersPluginApi, ColorType, LineStyle, } from 'lightweight-charts-v5'; import type { OHLCVBar, ChartType, Theme, IndicatorConfig } from './types'; import { calculateIndicator, getIndicatorDef, type PlotData, type MarkerData } from './indicatorRegistry'; import { calcAutoFib } from './calculations'; interface ThemeTokens { bgColor: string; textColor: string; gridColor: string; borderColor: string; crosshairColor: string; upColor: string; downColor: string; } const DARK: ThemeTokens = { bgColor: '#131722', textColor: '#D1D4DC', gridColor: '#1e2330', borderColor: '#2A2E39', crosshairColor: '#9598A1', upColor: '#26a69a', downColor: '#ef5350', }; const LIGHT: ThemeTokens = { bgColor: '#FFFFFF', textColor: '#131722', gridColor: '#F0F3FA', borderColor: '#E0E3EB', crosshairColor: '#758696', upColor: '#26a69a', downColor: '#ef5350', }; interface IndicatorEntry { id: string; type: string; seriesList: ISeriesApi[]; paneIndex?: number; alertLines: IPriceLine[]; config: IndicatorConfig; } interface AlertEntry { price: number; label: string; line: IPriceLine; } interface FibLevel { price: number; label: string; line: IPriceLine; } function getTheme(theme: Theme): ThemeTokens { return theme === 'dark' ? DARK : LIGHT; } export class ChartManager { private chart: IChartApi; private container: HTMLElement; private mainSeries: ISeriesApi | null = null; private volumeSeries: ISeriesApi<'Histogram'> | null = null; private indicators = new Map(); private alertEntries: AlertEntry[] = []; private fibLines: FibLevel[] = []; private drawingTool = 'cursor'; private drawingPoints: { time: Time; price: number }[] = []; private drawingLines: IPriceLine[] = []; private _clickHandler: ((p: MouseEventParams