hyperprop-charting-library 0.1.143 → 0.1.144

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
@@ -86,9 +86,20 @@ interface ChartOptions {
86
86
  dataLine?: DataLineOptions;
87
87
  animation?: AnimationOptions;
88
88
  indicatorUpdate?: IndicatorUpdateOptions;
89
+ /**
90
+ * Zone every timestamp is rendered in: an IANA id ("America/New_York"),
91
+ * "utc", or "local" (default). Affects axis labels, the crosshair tag, the
92
+ * data line and day boundaries — never the underlying data.
93
+ */
94
+ timezone?: ChartTimezone;
95
+ /** Clock style for rendered times. Default "24h". */
96
+ timeFormat?: TimeFormat;
97
+ session?: SessionOptions;
98
+ history?: HistoryOptions;
89
99
  crosshair?: CrosshairOptions;
90
100
  grid?: GridOptions;
91
101
  watermark?: WatermarkOptions;
102
+ alerts?: AlertOptions[];
92
103
  priceLines?: PriceLineOptions[];
93
104
  orderLines?: OrderLineOptions[];
94
105
  tickerLine?: TickerLineOptions;
@@ -550,7 +561,7 @@ interface ChartContextMenuEvent {
550
561
  };
551
562
  }
552
563
  /** Built-in keyboard actions, reported after the chart applies them. */
553
- type ChartKeyboardAction = "delete-drawing" | "cancel" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
564
+ type ChartKeyboardAction = "delete-drawing" | "cancel" | "undo" | "redo" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
554
565
  interface ChartKeyboardShortcutEvent {
555
566
  action: ChartKeyboardAction;
556
567
  /** The originating `KeyboardEvent.key`. */
@@ -570,6 +581,8 @@ interface KeyboardOptions {
570
581
  panBars?: number;
571
582
  /** Delete/Backspace removes the selected drawing. Default true. */
572
583
  deleteSelectedDrawing?: boolean;
584
+ /** Ctrl/Cmd+Z and Ctrl/Cmd+Shift+Z (or Ctrl+Y). Default true. */
585
+ undoRedo?: boolean;
573
586
  }
574
587
  /**
575
588
  * Deep zoom-out rendering. Once bars are narrower than `thresholdPx`, several
@@ -977,6 +990,80 @@ interface ChartInstance {
977
990
  type?: "image/png" | "image/jpeg";
978
991
  quality?: number;
979
992
  }) => string;
993
+ /**
994
+ * Render every timestamp in another zone — "America/New_York" for CME
995
+ * futures, "utc", "local", any IANA id. Data is untouched; only labels,
996
+ * the crosshair tag and day/session boundaries move. Unknown ids fall back
997
+ * to local time rather than throwing.
998
+ */
999
+ setTimezone: (timezone: ChartTimezone) => void;
1000
+ getTimezone: () => ChartTimezone;
1001
+ /** Switch rendered clock times between 24-hour and 12-hour. */
1002
+ setTimeFormat: (format: TimeFormat) => void;
1003
+ getTimeFormat: () => TimeFormat;
1004
+ /**
1005
+ * Teach the chart the instrument's trading hours. Session starts then get
1006
+ * their own separators (a futures day opening at 18:00 ET is one session,
1007
+ * not two calendar days) and out-of-session bars can be tinted.
1008
+ */
1009
+ setSession: (session: SessionOptions | SessionSpec | SessionPresetName | null) => void;
1010
+ getSession: () => SessionOptions;
1011
+ /**
1012
+ * Step back through drawing edits — create, move, restyle, delete, clear.
1013
+ * Returns false when there is nothing left to undo. Viewport changes are
1014
+ * deliberately not recorded (panning is not an edit), and neither are bulk
1015
+ * host syncs through `setDrawings`, so a host echoing state back never
1016
+ * pollutes the stack.
1017
+ */
1018
+ undo: () => boolean;
1019
+ redo: () => boolean;
1020
+ canUndo: () => boolean;
1021
+ canRedo: () => boolean;
1022
+ /** Current stack state, for enabling/labelling host buttons. */
1023
+ getUndoRedoState: () => UndoRedoState;
1024
+ onUndoRedoStateChange: (handler: ((state: UndoRedoState) => void) | null) => void;
1025
+ /** Drop both stacks, e.g. after loading a different symbol. */
1026
+ clearHistory: () => void;
1027
+ /**
1028
+ * Hide every bar after a chosen point and reveal them one at a time, so a
1029
+ * setup can be re-traded without lookahead. Indicators, drawings and the
1030
+ * price scale all see only the revealed bars. Live bars arriving while
1031
+ * replay runs are buffered, not shown, and `stopReplay()` restores the full
1032
+ * series.
1033
+ */
1034
+ startReplay: (options?: ReplayStartOptions) => void;
1035
+ stopReplay: () => void;
1036
+ /** Reveal `bars` more bars (negative rewinds). Default 1. */
1037
+ replayStep: (bars?: number) => void;
1038
+ replayPlay: (speed?: number) => void;
1039
+ replayPause: () => void;
1040
+ /** Bars revealed per second. */
1041
+ setReplaySpeed: (speed: number) => void;
1042
+ getReplayState: () => ReplayState;
1043
+ onReplayStateChange: (handler: ((state: ReplayState) => void) | null) => void;
1044
+ /**
1045
+ * Horizontal watch levels with a bell tag on the price axis. The chart
1046
+ * draws them, lets the user drag them, and fires `onAlertTrigger` when
1047
+ * price satisfies the condition — delivery (push, email, sound) is the
1048
+ * host's job.
1049
+ */
1050
+ setAlerts: (alerts: AlertOptions[]) => void;
1051
+ addAlert: (alert: AlertOptions) => string;
1052
+ updateAlert: (id: string, patch: Partial<AlertOptions>) => void;
1053
+ removeAlert: (id: string) => void;
1054
+ getAlerts: () => AlertOptions[];
1055
+ onAlertTrigger: (handler: ((event: AlertTriggerEvent) => void) | null) => void;
1056
+ /** Drag, delete-button and click interactions on an alert line. */
1057
+ onAlertAction: (handler: ((event: AlertActionEvent) => void) | null) => void;
1058
+ /** Badges pinned to bars (earnings, releases, your own annotations). */
1059
+ setBarMarks: (marks: BarMarkOptions[]) => void;
1060
+ getBarMarks: () => BarMarkOptions[];
1061
+ /** Badges on the time axis, for date-anchored events. */
1062
+ setTimescaleMarks: (marks: TimescaleMarkOptions[]) => void;
1063
+ getTimescaleMarks: () => TimescaleMarkOptions[];
1064
+ onMarkClick: (handler: ((event: MarkClickEvent) => void) | null) => void;
1065
+ /** Fires with the hovered mark, and with null when the pointer leaves it. */
1066
+ onMarkHover: (handler: ((event: MarkHoverEvent | null) => void) | null) => void;
980
1067
  resize: (width?: number, height?: number) => void;
981
1068
  destroy: () => void;
982
1069
  }
@@ -1017,12 +1104,182 @@ interface ChartSavedState {
1017
1104
  /** Optional for backward compatibility with pre-0.1.137 blobs. */
1018
1105
  priceScale?: PriceScaleOptions;
1019
1106
  drawingDefaults: Partial<Record<DrawingToolType, DrawingDefaults>>;
1107
+ /** Added in 0.1.144. */
1108
+ alerts?: AlertOptions[];
1109
+ timezone?: ChartTimezone;
1110
+ timeFormat?: TimeFormat;
1020
1111
  }
1021
1112
  type PriceScaleMode = "linear" | "log" | "percent";
1022
1113
  interface PriceScaleOptions {
1023
1114
  mode: PriceScaleMode;
1024
1115
  inverted: boolean;
1025
1116
  }
1117
+ /** IANA zone id, or the shorthands "local" (default) and "utc". */
1118
+ type ChartTimezone = "local" | "utc" | (string & {});
1119
+ type TimeFormat = "24h" | "12h";
1120
+ /** One continuous trading window in wall-clock time, e.g. 09:30 → 16:00. */
1121
+ interface SessionSegment {
1122
+ /** "HH:MM" in the session's own zone. */
1123
+ start: string;
1124
+ /** "HH:MM". Earlier than `start` means the window runs past midnight. */
1125
+ end: string;
1126
+ }
1127
+ interface SessionSpec {
1128
+ /** Zone the segment times are quoted in. Defaults to the machine zone. */
1129
+ timezone?: string;
1130
+ /**
1131
+ * Days the session *opens*, 0 = Sunday. Defaults to Monday–Friday. For a
1132
+ * window that runs past midnight this is the evening side: CME futures open
1133
+ * Sunday–Thursday (`[0,1,2,3,4]`) and trade into Monday–Friday morning, so
1134
+ * Friday evening is correctly closed for the weekend.
1135
+ */
1136
+ days?: number[];
1137
+ /** Defaults to a single all-day window. */
1138
+ segments?: SessionSegment[];
1139
+ }
1140
+ type SessionPresetName = "cme-futures" | "cme-rth" | "us-equities" | "us-equities-extended" | "24x7";
1141
+ /**
1142
+ * Trading-hours awareness. Without a spec the chart falls back to calendar
1143
+ * days for separators and shades nothing — the behavior of earlier versions.
1144
+ */
1145
+ interface SessionOptions {
1146
+ /** A preset name or your own spec. null disables session handling. */
1147
+ spec?: SessionSpec | SessionPresetName | null;
1148
+ /** Vertical rule at each session start. Default true when a spec is set. */
1149
+ separators?: boolean;
1150
+ /**
1151
+ * Tint bars that fall outside the session (overnight/extended hours), the
1152
+ * way TradingView greys pre/post market. Default false.
1153
+ */
1154
+ highlightOutOfSession?: boolean;
1155
+ outOfSessionColor?: string;
1156
+ }
1157
+ interface HistoryOptions {
1158
+ /** Default true. */
1159
+ enabled?: boolean;
1160
+ /** Steps kept before the oldest is dropped. Default 100. */
1161
+ limit?: number;
1162
+ }
1163
+ interface UndoRedoState {
1164
+ canUndo: boolean;
1165
+ canRedo: boolean;
1166
+ /** Human label of the step `undo()` would reverse, e.g. "Move drawing". */
1167
+ undoLabel: string | null;
1168
+ redoLabel: string | null;
1169
+ }
1170
+ interface ReplayStartOptions {
1171
+ /** Bar to resume from. Ignored when `fromTimeMs` is given. */
1172
+ fromIndex?: number;
1173
+ /** Resume from the bar at (or just before) this timestamp. */
1174
+ fromTimeMs?: number;
1175
+ /** Bars revealed per second while playing. Default 1. */
1176
+ speed?: number;
1177
+ /** Start playing immediately instead of waiting for `replayPlay()`. */
1178
+ play?: boolean;
1179
+ }
1180
+ interface ReplayState {
1181
+ active: boolean;
1182
+ playing: boolean;
1183
+ /** Bars per second. */
1184
+ speed: number;
1185
+ /** Index of the last revealed bar within the full series. */
1186
+ index: number;
1187
+ /** Length of the full series. */
1188
+ total: number;
1189
+ /** True once every bar has been revealed. */
1190
+ atEnd: boolean;
1191
+ /** Timestamp of the last revealed bar. */
1192
+ timeMs: number | null;
1193
+ }
1194
+ /**
1195
+ * "crossing" fires in either direction; the directional variants only fire on
1196
+ * the matching side; "greater"/"less" fire as soon as price is on that side,
1197
+ * including immediately if it already is.
1198
+ */
1199
+ type AlertCondition = "crossing" | "crossing-up" | "crossing-down" | "greater" | "less";
1200
+ interface AlertOptions {
1201
+ id?: string;
1202
+ price: number;
1203
+ /** Default "crossing". */
1204
+ condition?: AlertCondition;
1205
+ /** Extra text on the axis pill, after the price. */
1206
+ label?: string;
1207
+ color?: string;
1208
+ /** Armed and watching. Default true. */
1209
+ active?: boolean;
1210
+ /** Set by the chart when the condition is met; dims the line. */
1211
+ triggered?: boolean;
1212
+ /** Disarm after the first trigger. Default true. */
1213
+ once?: boolean;
1214
+ /** Let the user drag the line to a new price. Default true. */
1215
+ draggable?: boolean;
1216
+ }
1217
+ interface AlertTriggerEvent {
1218
+ alert: AlertOptions;
1219
+ /** Price that satisfied the condition. */
1220
+ price: number;
1221
+ timeMs: number;
1222
+ /** Bar index the trigger was detected on. */
1223
+ index: number;
1224
+ }
1225
+ interface AlertActionEvent {
1226
+ alert: AlertOptions;
1227
+ action: "move" | "remove" | "click";
1228
+ /** New price for "move". */
1229
+ price?: number;
1230
+ /** True for intermediate updates while the line is still being dragged. */
1231
+ dragging?: boolean;
1232
+ }
1233
+ type MarkShape = "circle" | "square" | "diamond" | "flag";
1234
+ /**
1235
+ * A small badge pinned to one bar — earnings, a news headline, an economic
1236
+ * release, a rule window. The chart resolves `time` to the bar it falls on.
1237
+ */
1238
+ interface BarMarkOptions {
1239
+ id?: string;
1240
+ /** Epoch ms or ISO string. */
1241
+ time: number | string;
1242
+ /** Default "below". Ignored when `price` is set. */
1243
+ position?: "above" | "below";
1244
+ /** Pin at an exact price instead of the bar's high/low. */
1245
+ price?: number;
1246
+ /** One or two characters drawn inside the badge, e.g. "E" or "FOMC"[0]. */
1247
+ label?: string;
1248
+ /** Tooltip text shown on hover. */
1249
+ text?: string;
1250
+ color?: string;
1251
+ textColor?: string;
1252
+ /** Badge radius in px. Default 7. */
1253
+ size?: number;
1254
+ shape?: MarkShape;
1255
+ }
1256
+ /** A badge on the time axis, for date-anchored events. */
1257
+ interface TimescaleMarkOptions {
1258
+ id?: string;
1259
+ time: number | string;
1260
+ label?: string;
1261
+ text?: string;
1262
+ color?: string;
1263
+ textColor?: string;
1264
+ shape?: MarkShape;
1265
+ }
1266
+ interface MarkClickEvent {
1267
+ kind: "bar" | "timescale";
1268
+ mark: BarMarkOptions | TimescaleMarkOptions;
1269
+ x: number;
1270
+ y: number;
1271
+ clientX: number;
1272
+ clientY: number;
1273
+ }
1274
+ interface MarkHoverEvent {
1275
+ kind: "bar" | "timescale";
1276
+ mark: BarMarkOptions | TimescaleMarkOptions;
1277
+ /** Canvas coordinates of the badge center. */
1278
+ x: number;
1279
+ y: number;
1280
+ clientX: number;
1281
+ clientY: number;
1282
+ }
1026
1283
 
1027
1284
  interface ScriptIndicatorInputDef {
1028
1285
  key: string;
@@ -1140,6 +1397,15 @@ declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) =>
1140
1397
  declare const CHART_THEMES: Record<ChartThemeName, ChartTheme>;
1141
1398
  declare const CHART_THEME_NAMES: ChartThemeName[];
1142
1399
 
1400
+ /** True when the runtime accepts the zone id, so a typo can't break the chart. */
1401
+ declare const isValidTimeZone: (timeZone: string) => boolean;
1402
+ /**
1403
+ * Ready-made session definitions. `cme-futures` is the full electronic
1404
+ * session (Sunday 18:00 ET through Friday 17:00 ET with the daily 17:00–18:00
1405
+ * maintenance break); `cme-rth` is the US index pit-equivalent day session.
1406
+ */
1407
+ declare const SESSION_PRESETS: Record<SessionPresetName, SessionSpec>;
1408
+
1143
1409
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
1144
1410
 
1145
- export { type AccessibilityOptions, type AnimationOptions, 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 DataLineOptions, 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 IndicatorUpdateOptions, 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 };
1411
+ export { type AccessibilityOptions, type AlertActionEvent, type AlertCondition, type AlertOptions, type AlertTriggerEvent, type AnimationOptions, type AxisOptions, type BarMarkOptions, 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 ChartTimezone, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DataLineOptions, 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 HistoryOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type IndicatorUpdateOptions, type KeyboardOptions, type LabelsOptions, type MarkClickEvent, type MarkHoverEvent, type MarkShape, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, type ReplayStartOptions, type ReplayState, SCRIPT_SOURCE_INPUT_VALUES, SESSION_PRESETS, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type SessionOptions, type SessionPresetName, type SessionSegment, type SessionSpec, type TickerLineOptions, type TimeFormat, type TimescaleMarkOptions, type TouchOptions, type TradeMarkerOptions, type UndoRedoState, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, isValidTimeZone, validateScriptSource };
package/dist/index.d.ts CHANGED
@@ -86,9 +86,20 @@ interface ChartOptions {
86
86
  dataLine?: DataLineOptions;
87
87
  animation?: AnimationOptions;
88
88
  indicatorUpdate?: IndicatorUpdateOptions;
89
+ /**
90
+ * Zone every timestamp is rendered in: an IANA id ("America/New_York"),
91
+ * "utc", or "local" (default). Affects axis labels, the crosshair tag, the
92
+ * data line and day boundaries — never the underlying data.
93
+ */
94
+ timezone?: ChartTimezone;
95
+ /** Clock style for rendered times. Default "24h". */
96
+ timeFormat?: TimeFormat;
97
+ session?: SessionOptions;
98
+ history?: HistoryOptions;
89
99
  crosshair?: CrosshairOptions;
90
100
  grid?: GridOptions;
91
101
  watermark?: WatermarkOptions;
102
+ alerts?: AlertOptions[];
92
103
  priceLines?: PriceLineOptions[];
93
104
  orderLines?: OrderLineOptions[];
94
105
  tickerLine?: TickerLineOptions;
@@ -550,7 +561,7 @@ interface ChartContextMenuEvent {
550
561
  };
551
562
  }
552
563
  /** Built-in keyboard actions, reported after the chart applies them. */
553
- type ChartKeyboardAction = "delete-drawing" | "cancel" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
564
+ type ChartKeyboardAction = "delete-drawing" | "cancel" | "undo" | "redo" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
554
565
  interface ChartKeyboardShortcutEvent {
555
566
  action: ChartKeyboardAction;
556
567
  /** The originating `KeyboardEvent.key`. */
@@ -570,6 +581,8 @@ interface KeyboardOptions {
570
581
  panBars?: number;
571
582
  /** Delete/Backspace removes the selected drawing. Default true. */
572
583
  deleteSelectedDrawing?: boolean;
584
+ /** Ctrl/Cmd+Z and Ctrl/Cmd+Shift+Z (or Ctrl+Y). Default true. */
585
+ undoRedo?: boolean;
573
586
  }
574
587
  /**
575
588
  * Deep zoom-out rendering. Once bars are narrower than `thresholdPx`, several
@@ -977,6 +990,80 @@ interface ChartInstance {
977
990
  type?: "image/png" | "image/jpeg";
978
991
  quality?: number;
979
992
  }) => string;
993
+ /**
994
+ * Render every timestamp in another zone — "America/New_York" for CME
995
+ * futures, "utc", "local", any IANA id. Data is untouched; only labels,
996
+ * the crosshair tag and day/session boundaries move. Unknown ids fall back
997
+ * to local time rather than throwing.
998
+ */
999
+ setTimezone: (timezone: ChartTimezone) => void;
1000
+ getTimezone: () => ChartTimezone;
1001
+ /** Switch rendered clock times between 24-hour and 12-hour. */
1002
+ setTimeFormat: (format: TimeFormat) => void;
1003
+ getTimeFormat: () => TimeFormat;
1004
+ /**
1005
+ * Teach the chart the instrument's trading hours. Session starts then get
1006
+ * their own separators (a futures day opening at 18:00 ET is one session,
1007
+ * not two calendar days) and out-of-session bars can be tinted.
1008
+ */
1009
+ setSession: (session: SessionOptions | SessionSpec | SessionPresetName | null) => void;
1010
+ getSession: () => SessionOptions;
1011
+ /**
1012
+ * Step back through drawing edits — create, move, restyle, delete, clear.
1013
+ * Returns false when there is nothing left to undo. Viewport changes are
1014
+ * deliberately not recorded (panning is not an edit), and neither are bulk
1015
+ * host syncs through `setDrawings`, so a host echoing state back never
1016
+ * pollutes the stack.
1017
+ */
1018
+ undo: () => boolean;
1019
+ redo: () => boolean;
1020
+ canUndo: () => boolean;
1021
+ canRedo: () => boolean;
1022
+ /** Current stack state, for enabling/labelling host buttons. */
1023
+ getUndoRedoState: () => UndoRedoState;
1024
+ onUndoRedoStateChange: (handler: ((state: UndoRedoState) => void) | null) => void;
1025
+ /** Drop both stacks, e.g. after loading a different symbol. */
1026
+ clearHistory: () => void;
1027
+ /**
1028
+ * Hide every bar after a chosen point and reveal them one at a time, so a
1029
+ * setup can be re-traded without lookahead. Indicators, drawings and the
1030
+ * price scale all see only the revealed bars. Live bars arriving while
1031
+ * replay runs are buffered, not shown, and `stopReplay()` restores the full
1032
+ * series.
1033
+ */
1034
+ startReplay: (options?: ReplayStartOptions) => void;
1035
+ stopReplay: () => void;
1036
+ /** Reveal `bars` more bars (negative rewinds). Default 1. */
1037
+ replayStep: (bars?: number) => void;
1038
+ replayPlay: (speed?: number) => void;
1039
+ replayPause: () => void;
1040
+ /** Bars revealed per second. */
1041
+ setReplaySpeed: (speed: number) => void;
1042
+ getReplayState: () => ReplayState;
1043
+ onReplayStateChange: (handler: ((state: ReplayState) => void) | null) => void;
1044
+ /**
1045
+ * Horizontal watch levels with a bell tag on the price axis. The chart
1046
+ * draws them, lets the user drag them, and fires `onAlertTrigger` when
1047
+ * price satisfies the condition — delivery (push, email, sound) is the
1048
+ * host's job.
1049
+ */
1050
+ setAlerts: (alerts: AlertOptions[]) => void;
1051
+ addAlert: (alert: AlertOptions) => string;
1052
+ updateAlert: (id: string, patch: Partial<AlertOptions>) => void;
1053
+ removeAlert: (id: string) => void;
1054
+ getAlerts: () => AlertOptions[];
1055
+ onAlertTrigger: (handler: ((event: AlertTriggerEvent) => void) | null) => void;
1056
+ /** Drag, delete-button and click interactions on an alert line. */
1057
+ onAlertAction: (handler: ((event: AlertActionEvent) => void) | null) => void;
1058
+ /** Badges pinned to bars (earnings, releases, your own annotations). */
1059
+ setBarMarks: (marks: BarMarkOptions[]) => void;
1060
+ getBarMarks: () => BarMarkOptions[];
1061
+ /** Badges on the time axis, for date-anchored events. */
1062
+ setTimescaleMarks: (marks: TimescaleMarkOptions[]) => void;
1063
+ getTimescaleMarks: () => TimescaleMarkOptions[];
1064
+ onMarkClick: (handler: ((event: MarkClickEvent) => void) | null) => void;
1065
+ /** Fires with the hovered mark, and with null when the pointer leaves it. */
1066
+ onMarkHover: (handler: ((event: MarkHoverEvent | null) => void) | null) => void;
980
1067
  resize: (width?: number, height?: number) => void;
981
1068
  destroy: () => void;
982
1069
  }
@@ -1017,12 +1104,182 @@ interface ChartSavedState {
1017
1104
  /** Optional for backward compatibility with pre-0.1.137 blobs. */
1018
1105
  priceScale?: PriceScaleOptions;
1019
1106
  drawingDefaults: Partial<Record<DrawingToolType, DrawingDefaults>>;
1107
+ /** Added in 0.1.144. */
1108
+ alerts?: AlertOptions[];
1109
+ timezone?: ChartTimezone;
1110
+ timeFormat?: TimeFormat;
1020
1111
  }
1021
1112
  type PriceScaleMode = "linear" | "log" | "percent";
1022
1113
  interface PriceScaleOptions {
1023
1114
  mode: PriceScaleMode;
1024
1115
  inverted: boolean;
1025
1116
  }
1117
+ /** IANA zone id, or the shorthands "local" (default) and "utc". */
1118
+ type ChartTimezone = "local" | "utc" | (string & {});
1119
+ type TimeFormat = "24h" | "12h";
1120
+ /** One continuous trading window in wall-clock time, e.g. 09:30 → 16:00. */
1121
+ interface SessionSegment {
1122
+ /** "HH:MM" in the session's own zone. */
1123
+ start: string;
1124
+ /** "HH:MM". Earlier than `start` means the window runs past midnight. */
1125
+ end: string;
1126
+ }
1127
+ interface SessionSpec {
1128
+ /** Zone the segment times are quoted in. Defaults to the machine zone. */
1129
+ timezone?: string;
1130
+ /**
1131
+ * Days the session *opens*, 0 = Sunday. Defaults to Monday–Friday. For a
1132
+ * window that runs past midnight this is the evening side: CME futures open
1133
+ * Sunday–Thursday (`[0,1,2,3,4]`) and trade into Monday–Friday morning, so
1134
+ * Friday evening is correctly closed for the weekend.
1135
+ */
1136
+ days?: number[];
1137
+ /** Defaults to a single all-day window. */
1138
+ segments?: SessionSegment[];
1139
+ }
1140
+ type SessionPresetName = "cme-futures" | "cme-rth" | "us-equities" | "us-equities-extended" | "24x7";
1141
+ /**
1142
+ * Trading-hours awareness. Without a spec the chart falls back to calendar
1143
+ * days for separators and shades nothing — the behavior of earlier versions.
1144
+ */
1145
+ interface SessionOptions {
1146
+ /** A preset name or your own spec. null disables session handling. */
1147
+ spec?: SessionSpec | SessionPresetName | null;
1148
+ /** Vertical rule at each session start. Default true when a spec is set. */
1149
+ separators?: boolean;
1150
+ /**
1151
+ * Tint bars that fall outside the session (overnight/extended hours), the
1152
+ * way TradingView greys pre/post market. Default false.
1153
+ */
1154
+ highlightOutOfSession?: boolean;
1155
+ outOfSessionColor?: string;
1156
+ }
1157
+ interface HistoryOptions {
1158
+ /** Default true. */
1159
+ enabled?: boolean;
1160
+ /** Steps kept before the oldest is dropped. Default 100. */
1161
+ limit?: number;
1162
+ }
1163
+ interface UndoRedoState {
1164
+ canUndo: boolean;
1165
+ canRedo: boolean;
1166
+ /** Human label of the step `undo()` would reverse, e.g. "Move drawing". */
1167
+ undoLabel: string | null;
1168
+ redoLabel: string | null;
1169
+ }
1170
+ interface ReplayStartOptions {
1171
+ /** Bar to resume from. Ignored when `fromTimeMs` is given. */
1172
+ fromIndex?: number;
1173
+ /** Resume from the bar at (or just before) this timestamp. */
1174
+ fromTimeMs?: number;
1175
+ /** Bars revealed per second while playing. Default 1. */
1176
+ speed?: number;
1177
+ /** Start playing immediately instead of waiting for `replayPlay()`. */
1178
+ play?: boolean;
1179
+ }
1180
+ interface ReplayState {
1181
+ active: boolean;
1182
+ playing: boolean;
1183
+ /** Bars per second. */
1184
+ speed: number;
1185
+ /** Index of the last revealed bar within the full series. */
1186
+ index: number;
1187
+ /** Length of the full series. */
1188
+ total: number;
1189
+ /** True once every bar has been revealed. */
1190
+ atEnd: boolean;
1191
+ /** Timestamp of the last revealed bar. */
1192
+ timeMs: number | null;
1193
+ }
1194
+ /**
1195
+ * "crossing" fires in either direction; the directional variants only fire on
1196
+ * the matching side; "greater"/"less" fire as soon as price is on that side,
1197
+ * including immediately if it already is.
1198
+ */
1199
+ type AlertCondition = "crossing" | "crossing-up" | "crossing-down" | "greater" | "less";
1200
+ interface AlertOptions {
1201
+ id?: string;
1202
+ price: number;
1203
+ /** Default "crossing". */
1204
+ condition?: AlertCondition;
1205
+ /** Extra text on the axis pill, after the price. */
1206
+ label?: string;
1207
+ color?: string;
1208
+ /** Armed and watching. Default true. */
1209
+ active?: boolean;
1210
+ /** Set by the chart when the condition is met; dims the line. */
1211
+ triggered?: boolean;
1212
+ /** Disarm after the first trigger. Default true. */
1213
+ once?: boolean;
1214
+ /** Let the user drag the line to a new price. Default true. */
1215
+ draggable?: boolean;
1216
+ }
1217
+ interface AlertTriggerEvent {
1218
+ alert: AlertOptions;
1219
+ /** Price that satisfied the condition. */
1220
+ price: number;
1221
+ timeMs: number;
1222
+ /** Bar index the trigger was detected on. */
1223
+ index: number;
1224
+ }
1225
+ interface AlertActionEvent {
1226
+ alert: AlertOptions;
1227
+ action: "move" | "remove" | "click";
1228
+ /** New price for "move". */
1229
+ price?: number;
1230
+ /** True for intermediate updates while the line is still being dragged. */
1231
+ dragging?: boolean;
1232
+ }
1233
+ type MarkShape = "circle" | "square" | "diamond" | "flag";
1234
+ /**
1235
+ * A small badge pinned to one bar — earnings, a news headline, an economic
1236
+ * release, a rule window. The chart resolves `time` to the bar it falls on.
1237
+ */
1238
+ interface BarMarkOptions {
1239
+ id?: string;
1240
+ /** Epoch ms or ISO string. */
1241
+ time: number | string;
1242
+ /** Default "below". Ignored when `price` is set. */
1243
+ position?: "above" | "below";
1244
+ /** Pin at an exact price instead of the bar's high/low. */
1245
+ price?: number;
1246
+ /** One or two characters drawn inside the badge, e.g. "E" or "FOMC"[0]. */
1247
+ label?: string;
1248
+ /** Tooltip text shown on hover. */
1249
+ text?: string;
1250
+ color?: string;
1251
+ textColor?: string;
1252
+ /** Badge radius in px. Default 7. */
1253
+ size?: number;
1254
+ shape?: MarkShape;
1255
+ }
1256
+ /** A badge on the time axis, for date-anchored events. */
1257
+ interface TimescaleMarkOptions {
1258
+ id?: string;
1259
+ time: number | string;
1260
+ label?: string;
1261
+ text?: string;
1262
+ color?: string;
1263
+ textColor?: string;
1264
+ shape?: MarkShape;
1265
+ }
1266
+ interface MarkClickEvent {
1267
+ kind: "bar" | "timescale";
1268
+ mark: BarMarkOptions | TimescaleMarkOptions;
1269
+ x: number;
1270
+ y: number;
1271
+ clientX: number;
1272
+ clientY: number;
1273
+ }
1274
+ interface MarkHoverEvent {
1275
+ kind: "bar" | "timescale";
1276
+ mark: BarMarkOptions | TimescaleMarkOptions;
1277
+ /** Canvas coordinates of the badge center. */
1278
+ x: number;
1279
+ y: number;
1280
+ clientX: number;
1281
+ clientY: number;
1282
+ }
1026
1283
 
1027
1284
  interface ScriptIndicatorInputDef {
1028
1285
  key: string;
@@ -1140,6 +1397,15 @@ declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) =>
1140
1397
  declare const CHART_THEMES: Record<ChartThemeName, ChartTheme>;
1141
1398
  declare const CHART_THEME_NAMES: ChartThemeName[];
1142
1399
 
1400
+ /** True when the runtime accepts the zone id, so a typo can't break the chart. */
1401
+ declare const isValidTimeZone: (timeZone: string) => boolean;
1402
+ /**
1403
+ * Ready-made session definitions. `cme-futures` is the full electronic
1404
+ * session (Sunday 18:00 ET through Friday 17:00 ET with the daily 17:00–18:00
1405
+ * maintenance break); `cme-rth` is the US index pit-equivalent day session.
1406
+ */
1407
+ declare const SESSION_PRESETS: Record<SessionPresetName, SessionSpec>;
1408
+
1143
1409
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
1144
1410
 
1145
- export { type AccessibilityOptions, type AnimationOptions, 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 DataLineOptions, 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 IndicatorUpdateOptions, 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 };
1411
+ export { type AccessibilityOptions, type AlertActionEvent, type AlertCondition, type AlertOptions, type AlertTriggerEvent, type AnimationOptions, type AxisOptions, type BarMarkOptions, 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 ChartTimezone, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DataLineOptions, 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 HistoryOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type IndicatorUpdateOptions, type KeyboardOptions, type LabelsOptions, type MarkClickEvent, type MarkHoverEvent, type MarkShape, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, type ReplayStartOptions, type ReplayState, SCRIPT_SOURCE_INPUT_VALUES, SESSION_PRESETS, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type SessionOptions, type SessionPresetName, type SessionSegment, type SessionSpec, type TickerLineOptions, type TimeFormat, type TimescaleMarkOptions, type TouchOptions, type TradeMarkerOptions, type UndoRedoState, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, isValidTimeZone, validateScriptSource };