hyperprop-charting-library 0.1.139 → 0.1.141

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.cts CHANGED
@@ -81,6 +81,8 @@ interface ChartOptions {
81
81
  keyboard?: KeyboardOptions;
82
82
  accessibility?: AccessibilityOptions;
83
83
  downsampling?: DownsamplingOptions;
84
+ touch?: TouchOptions;
85
+ datafeedOptions?: DatafeedOptions;
84
86
  crosshair?: CrosshairOptions;
85
87
  grid?: GridOptions;
86
88
  watermark?: WatermarkOptions;
@@ -503,6 +505,19 @@ interface CrosshairPriceActionEvent {
503
505
  y: number;
504
506
  price: number;
505
507
  }
508
+ /** Press-and-hold on touch; also fired while the finger scrubs afterwards. */
509
+ interface ChartLongPressEvent {
510
+ x: number;
511
+ y: number;
512
+ clientX: number;
513
+ clientY: number;
514
+ price?: number;
515
+ index?: number;
516
+ time?: string;
517
+ point?: OhlcDataPoint;
518
+ /** False for the initial press, true for subsequent scrub updates. */
519
+ scrubbing: boolean;
520
+ }
506
521
  /**
507
522
  * What the pointer was over when the context menu was requested. Hosts switch
508
523
  * on this to show the right menu instead of re-deriving it from coordinates.
@@ -592,6 +607,90 @@ interface CompareSeriesOptions {
592
607
  /** Let this series widen the price scale. Default true. */
593
608
  includeInAutoScale?: boolean;
594
609
  }
610
+ /**
611
+ * A complete chart palette. Hosts otherwise configure a dozen colors one by
612
+ * one and re-push them on every light/dark toggle; a theme is that same set as
613
+ * one object, so `setTheme` is a single call.
614
+ */
615
+ interface ChartTheme {
616
+ name: string;
617
+ background: string;
618
+ upColor: string;
619
+ downColor: string;
620
+ /** Line/area/baseline series color. */
621
+ lineColor: string;
622
+ gridColor: string;
623
+ gridOpacity: number;
624
+ axisTextColor: string;
625
+ axisLineColor: string;
626
+ crosshairColor: string;
627
+ crosshairLabelBackground: string;
628
+ crosshairLabelText: string;
629
+ crosshairLabelBorder: string;
630
+ watermarkColor: string;
631
+ /** Indicator names/values drawn inside the plot and pane legends. */
632
+ indicatorTextColor: string;
633
+ /** Text drawn on colored order/preview pills. */
634
+ labelTextColor: string;
635
+ /** Background for preview labels and pills. */
636
+ labelBackground: string;
637
+ }
638
+ type ChartThemeName = "dark" | "light" | "midnight" | "high-contrast";
639
+ /** Touch ergonomics. Fingers are blunter than a mouse cursor. */
640
+ interface TouchOptions {
641
+ /**
642
+ * Multiplier applied to drawing/handle/divider hit tolerances for touch and
643
+ * pen input, so grabbing a line doesn't demand pixel accuracy. Mouse input
644
+ * is unaffected. Default 2.2 (≈16px handles become ≈35px targets).
645
+ */
646
+ hitToleranceScale?: number;
647
+ /** Press-and-hold on the plot shows an OHLC tooltip. Default true. */
648
+ longPressTooltip?: boolean;
649
+ /** How long the finger must rest before the tooltip appears. Default 400ms. */
650
+ longPressMs?: number;
651
+ }
652
+ /** Bar window the chart is asking a datafeed for. */
653
+ interface DatafeedBarsRequest {
654
+ /** Start of the wanted window in epoch ms (hint; `countBack` is authoritative). */
655
+ fromMs: number;
656
+ /** End of the wanted window in epoch ms, exclusive. */
657
+ toMs: number;
658
+ /** Roughly how many bars to return, counting back from `toMs`. */
659
+ countBack: number;
660
+ /** True for the initial load, false for older-history backfills. */
661
+ firstRequest: boolean;
662
+ }
663
+ /**
664
+ * Optional pull-based data source, shaped after TradingView's datafeed. Supply
665
+ * one and the chart loads its own history — including fetching older bars as
666
+ * the user scrolls left — instead of the host pushing everything through
667
+ * `setData`. `setData`/`upsertBar` keep working and take precedence, so this
668
+ * can be adopted one host at a time.
669
+ */
670
+ interface ChartDatafeed {
671
+ /** Awaited once before the first `getBars`, like TradingView's onReady. */
672
+ onReady?: () => Promise<void> | void;
673
+ /**
674
+ * Return bars for the requested window, oldest first. Return an empty array
675
+ * to signal there is no more history — the chart stops asking.
676
+ */
677
+ getBars: (request: DatafeedBarsRequest) => Promise<OhlcDataPoint[]> | OhlcDataPoint[];
678
+ /** Stream live updates; return a teardown function. */
679
+ subscribeBars?: (onBar: (bar: OhlcDataPoint) => void) => (() => void) | void;
680
+ /** Called when `getBars` rejects; the chart just stops that request. */
681
+ onError?: (error: unknown, request: DatafeedBarsRequest) => void;
682
+ }
683
+ interface DatafeedOptions {
684
+ /**
685
+ * Start fetching older bars when fewer than this many remain to the left of
686
+ * the viewport. Default 150.
687
+ */
688
+ prefetchThresholdBars?: number;
689
+ /** Minimum gap between backfill requests. Default 1200ms. */
690
+ cooldownMs?: number;
691
+ /** Bars requested per backfill. Default 1500. */
692
+ chunkBars?: number;
693
+ }
595
694
  interface AccessibilityOptions {
596
695
  /** aria-label on the canvas. Default "Price chart". */
597
696
  label?: string;
@@ -748,6 +847,15 @@ interface ChartInstance {
748
847
  */
749
848
  setPriceScale: (options: Partial<PriceScaleOptions>) => void;
750
849
  getPriceScale: () => PriceScaleOptions;
850
+ /**
851
+ * Apply a whole palette at once — a built-in preset name or your own
852
+ * `ChartTheme`. Replaces the per-color `updateOptions` juggling hosts do on
853
+ * every light/dark toggle. Anything the theme doesn't cover (order-line
854
+ * colors, drawing defaults) is left alone.
855
+ */
856
+ setTheme: (theme: ChartThemeName | ChartTheme) => void;
857
+ /** Name of the last applied theme, or null if colors were set by hand. */
858
+ getTheme: () => string | null;
751
859
  /**
752
860
  * Overlay other instruments on the main pane for comparison. Series are
753
861
  * aligned to the main series by timestamp (last known value carries forward
@@ -755,6 +863,15 @@ interface ChartInstance {
755
863
  * visible bar so differently-priced instruments stay comparable. Data is not
756
864
  * part of `saveState()` — the host re-supplies it.
757
865
  */
866
+ /**
867
+ * Attach (or clear with `null`) a pull-based datafeed. The chart loads the
868
+ * initial window, subscribes to live bars, and fetches older history as the
869
+ * user scrolls left. Returns a promise that resolves once the first batch is
870
+ * on screen.
871
+ */
872
+ setDatafeed: (datafeed: ChartDatafeed | null) => Promise<void>;
873
+ /** Fires when press-and-hold inspects a bar on touch. */
874
+ onLongPress: (handler: ((event: ChartLongPressEvent) => void) | null) => void;
758
875
  setCompareSeries: (series: CompareSeriesOptions[]) => void;
759
876
  addCompareSeries: (series: CompareSeriesOptions) => void;
760
877
  removeCompareSeries: (id: string) => void;
@@ -946,6 +1063,19 @@ declare const validateScriptSource: (source: string) => string | null;
946
1063
  */
947
1064
  declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) => IndicatorPlugin;
948
1065
 
1066
+ /**
1067
+ * Built-in palettes.
1068
+ *
1069
+ * `dark` and `light` mirror TradingView's own chart colors (sampled from their
1070
+ * rendered canvas), which is what most traders' eyes are calibrated to: the
1071
+ * candle colors stay the same across both and only the surface changes.
1072
+ * `midnight` is Hyperprop's long-standing default, kept as a named preset so
1073
+ * existing setups have something to go back to. `high-contrast` trades
1074
+ * prettiness for legibility on projectors and for low-vision users.
1075
+ */
1076
+ declare const CHART_THEMES: Record<ChartThemeName, ChartTheme>;
1077
+ declare const CHART_THEME_NAMES: ChartThemeName[];
1078
+
949
1079
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
950
1080
 
951
- export { type AccessibilityOptions, type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartOptions, type ChartSavedState, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type KeyboardOptions, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, SCRIPT_SOURCE_INPUT_VALUES, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type TickerLineOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };
1081
+ export { type AccessibilityOptions, type AxisOptions, type BuiltInIndicatorInfo, CHART_THEMES, CHART_THEME_NAMES, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartDatafeed, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartLongPressEvent, type ChartOptions, type ChartSavedState, type ChartTheme, type ChartThemeName, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DatafeedBarsRequest, type DatafeedOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type KeyboardOptions, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, SCRIPT_SOURCE_INPUT_VALUES, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type TickerLineOptions, type TouchOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };
package/dist/index.d.ts CHANGED
@@ -81,6 +81,8 @@ interface ChartOptions {
81
81
  keyboard?: KeyboardOptions;
82
82
  accessibility?: AccessibilityOptions;
83
83
  downsampling?: DownsamplingOptions;
84
+ touch?: TouchOptions;
85
+ datafeedOptions?: DatafeedOptions;
84
86
  crosshair?: CrosshairOptions;
85
87
  grid?: GridOptions;
86
88
  watermark?: WatermarkOptions;
@@ -503,6 +505,19 @@ interface CrosshairPriceActionEvent {
503
505
  y: number;
504
506
  price: number;
505
507
  }
508
+ /** Press-and-hold on touch; also fired while the finger scrubs afterwards. */
509
+ interface ChartLongPressEvent {
510
+ x: number;
511
+ y: number;
512
+ clientX: number;
513
+ clientY: number;
514
+ price?: number;
515
+ index?: number;
516
+ time?: string;
517
+ point?: OhlcDataPoint;
518
+ /** False for the initial press, true for subsequent scrub updates. */
519
+ scrubbing: boolean;
520
+ }
506
521
  /**
507
522
  * What the pointer was over when the context menu was requested. Hosts switch
508
523
  * on this to show the right menu instead of re-deriving it from coordinates.
@@ -592,6 +607,90 @@ interface CompareSeriesOptions {
592
607
  /** Let this series widen the price scale. Default true. */
593
608
  includeInAutoScale?: boolean;
594
609
  }
610
+ /**
611
+ * A complete chart palette. Hosts otherwise configure a dozen colors one by
612
+ * one and re-push them on every light/dark toggle; a theme is that same set as
613
+ * one object, so `setTheme` is a single call.
614
+ */
615
+ interface ChartTheme {
616
+ name: string;
617
+ background: string;
618
+ upColor: string;
619
+ downColor: string;
620
+ /** Line/area/baseline series color. */
621
+ lineColor: string;
622
+ gridColor: string;
623
+ gridOpacity: number;
624
+ axisTextColor: string;
625
+ axisLineColor: string;
626
+ crosshairColor: string;
627
+ crosshairLabelBackground: string;
628
+ crosshairLabelText: string;
629
+ crosshairLabelBorder: string;
630
+ watermarkColor: string;
631
+ /** Indicator names/values drawn inside the plot and pane legends. */
632
+ indicatorTextColor: string;
633
+ /** Text drawn on colored order/preview pills. */
634
+ labelTextColor: string;
635
+ /** Background for preview labels and pills. */
636
+ labelBackground: string;
637
+ }
638
+ type ChartThemeName = "dark" | "light" | "midnight" | "high-contrast";
639
+ /** Touch ergonomics. Fingers are blunter than a mouse cursor. */
640
+ interface TouchOptions {
641
+ /**
642
+ * Multiplier applied to drawing/handle/divider hit tolerances for touch and
643
+ * pen input, so grabbing a line doesn't demand pixel accuracy. Mouse input
644
+ * is unaffected. Default 2.2 (≈16px handles become ≈35px targets).
645
+ */
646
+ hitToleranceScale?: number;
647
+ /** Press-and-hold on the plot shows an OHLC tooltip. Default true. */
648
+ longPressTooltip?: boolean;
649
+ /** How long the finger must rest before the tooltip appears. Default 400ms. */
650
+ longPressMs?: number;
651
+ }
652
+ /** Bar window the chart is asking a datafeed for. */
653
+ interface DatafeedBarsRequest {
654
+ /** Start of the wanted window in epoch ms (hint; `countBack` is authoritative). */
655
+ fromMs: number;
656
+ /** End of the wanted window in epoch ms, exclusive. */
657
+ toMs: number;
658
+ /** Roughly how many bars to return, counting back from `toMs`. */
659
+ countBack: number;
660
+ /** True for the initial load, false for older-history backfills. */
661
+ firstRequest: boolean;
662
+ }
663
+ /**
664
+ * Optional pull-based data source, shaped after TradingView's datafeed. Supply
665
+ * one and the chart loads its own history — including fetching older bars as
666
+ * the user scrolls left — instead of the host pushing everything through
667
+ * `setData`. `setData`/`upsertBar` keep working and take precedence, so this
668
+ * can be adopted one host at a time.
669
+ */
670
+ interface ChartDatafeed {
671
+ /** Awaited once before the first `getBars`, like TradingView's onReady. */
672
+ onReady?: () => Promise<void> | void;
673
+ /**
674
+ * Return bars for the requested window, oldest first. Return an empty array
675
+ * to signal there is no more history — the chart stops asking.
676
+ */
677
+ getBars: (request: DatafeedBarsRequest) => Promise<OhlcDataPoint[]> | OhlcDataPoint[];
678
+ /** Stream live updates; return a teardown function. */
679
+ subscribeBars?: (onBar: (bar: OhlcDataPoint) => void) => (() => void) | void;
680
+ /** Called when `getBars` rejects; the chart just stops that request. */
681
+ onError?: (error: unknown, request: DatafeedBarsRequest) => void;
682
+ }
683
+ interface DatafeedOptions {
684
+ /**
685
+ * Start fetching older bars when fewer than this many remain to the left of
686
+ * the viewport. Default 150.
687
+ */
688
+ prefetchThresholdBars?: number;
689
+ /** Minimum gap between backfill requests. Default 1200ms. */
690
+ cooldownMs?: number;
691
+ /** Bars requested per backfill. Default 1500. */
692
+ chunkBars?: number;
693
+ }
595
694
  interface AccessibilityOptions {
596
695
  /** aria-label on the canvas. Default "Price chart". */
597
696
  label?: string;
@@ -748,6 +847,15 @@ interface ChartInstance {
748
847
  */
749
848
  setPriceScale: (options: Partial<PriceScaleOptions>) => void;
750
849
  getPriceScale: () => PriceScaleOptions;
850
+ /**
851
+ * Apply a whole palette at once — a built-in preset name or your own
852
+ * `ChartTheme`. Replaces the per-color `updateOptions` juggling hosts do on
853
+ * every light/dark toggle. Anything the theme doesn't cover (order-line
854
+ * colors, drawing defaults) is left alone.
855
+ */
856
+ setTheme: (theme: ChartThemeName | ChartTheme) => void;
857
+ /** Name of the last applied theme, or null if colors were set by hand. */
858
+ getTheme: () => string | null;
751
859
  /**
752
860
  * Overlay other instruments on the main pane for comparison. Series are
753
861
  * aligned to the main series by timestamp (last known value carries forward
@@ -755,6 +863,15 @@ interface ChartInstance {
755
863
  * visible bar so differently-priced instruments stay comparable. Data is not
756
864
  * part of `saveState()` — the host re-supplies it.
757
865
  */
866
+ /**
867
+ * Attach (or clear with `null`) a pull-based datafeed. The chart loads the
868
+ * initial window, subscribes to live bars, and fetches older history as the
869
+ * user scrolls left. Returns a promise that resolves once the first batch is
870
+ * on screen.
871
+ */
872
+ setDatafeed: (datafeed: ChartDatafeed | null) => Promise<void>;
873
+ /** Fires when press-and-hold inspects a bar on touch. */
874
+ onLongPress: (handler: ((event: ChartLongPressEvent) => void) | null) => void;
758
875
  setCompareSeries: (series: CompareSeriesOptions[]) => void;
759
876
  addCompareSeries: (series: CompareSeriesOptions) => void;
760
877
  removeCompareSeries: (id: string) => void;
@@ -946,6 +1063,19 @@ declare const validateScriptSource: (source: string) => string | null;
946
1063
  */
947
1064
  declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) => IndicatorPlugin;
948
1065
 
1066
+ /**
1067
+ * Built-in palettes.
1068
+ *
1069
+ * `dark` and `light` mirror TradingView's own chart colors (sampled from their
1070
+ * rendered canvas), which is what most traders' eyes are calibrated to: the
1071
+ * candle colors stay the same across both and only the surface changes.
1072
+ * `midnight` is Hyperprop's long-standing default, kept as a named preset so
1073
+ * existing setups have something to go back to. `high-contrast` trades
1074
+ * prettiness for legibility on projectors and for low-vision users.
1075
+ */
1076
+ declare const CHART_THEMES: Record<ChartThemeName, ChartTheme>;
1077
+ declare const CHART_THEME_NAMES: ChartThemeName[];
1078
+
949
1079
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
950
1080
 
951
- export { type AccessibilityOptions, type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartOptions, type ChartSavedState, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type KeyboardOptions, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, SCRIPT_SOURCE_INPUT_VALUES, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type TickerLineOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };
1081
+ export { type AccessibilityOptions, type AxisOptions, type BuiltInIndicatorInfo, CHART_THEMES, CHART_THEME_NAMES, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartDatafeed, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartLongPressEvent, type ChartOptions, type ChartSavedState, type ChartTheme, type ChartThemeName, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DatafeedBarsRequest, type DatafeedOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type KeyboardOptions, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, SCRIPT_SOURCE_INPUT_VALUES, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type TickerLineOptions, type TouchOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };