wickchart 1.7.0 → 2.0.2

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.
@@ -1,4 +1,3 @@
1
- import { PresenceTracker } from './core.js';
2
1
  declare const HTMLElementBase: {
3
2
  new (): {};
4
3
  };
@@ -22,10 +21,6 @@ declare class WickChart extends HTMLElementBase {
22
21
  index: any;
23
22
  x: number;
24
23
  y: any;
25
- } | {
26
- index: number;
27
- x: number;
28
- y: number;
29
24
  };
30
25
  _dt: number;
31
26
  _ly: {
@@ -51,6 +46,11 @@ declare class WickChart extends HTMLElementBase {
51
46
  h: number;
52
47
  };
53
48
  };
49
+ _priceW: any;
50
+ _pwNarrow: {
51
+ want: any;
52
+ t: number;
53
+ };
54
54
  _cache: {
55
55
  v: number;
56
56
  map: {};
@@ -103,24 +103,13 @@ declare class WickChart extends HTMLElementBase {
103
103
  p2: number;
104
104
  period: number;
105
105
  };
106
- _coviewName: any;
107
- _coviewCh: BroadcastChannel;
108
- _coviewPeer: string;
109
- _coviewLast: number;
110
- _ghost: {
111
- index: number;
112
- yFrac: any;
113
- at: number;
114
- };
106
+ _coviewCh: any;
107
+ _ghost: any;
115
108
  _ghostTimer: number;
116
- _coviewLabel: any;
117
- _presence: PresenceTracker;
109
+ _presence: any;
118
110
  _coviewBeat: number;
119
- _coviewViewLast: number;
120
- _sonify: boolean;
121
- _actx: any;
122
- _lastToneIdx: number;
123
- _playToken: number;
111
+ _scenario: any;
112
+ _riskPlan: any;
124
113
  _measure: {
125
114
  iA: any;
126
115
  pA: number;
@@ -129,9 +118,6 @@ declare class WickChart extends HTMLElementBase {
129
118
  done: boolean;
130
119
  };
131
120
  _measuring: boolean;
132
- _walkTimer: number;
133
- _storyToken: number;
134
- _story: object[];
135
121
  _brush: boolean;
136
122
  _brushSel: {
137
123
  i0: number;
@@ -212,29 +198,6 @@ declare class WickChart extends HTMLElementBase {
212
198
  _tz: string;
213
199
  _vwapAnchor: string;
214
200
  _overlays: any[];
215
- _scenario: {
216
- path: {
217
- h: number;
218
- price: number;
219
- }[];
220
- horizon: number;
221
- cone: boolean;
222
- levels: number[];
223
- color: string | null;
224
- label: string;
225
- };
226
- _riskPlan: {
227
- entry: number;
228
- stop: number;
229
- risk: number;
230
- direction: 'long' | 'short';
231
- levels: {
232
- k: number;
233
- price: number;
234
- }[];
235
- maxK: number;
236
- label: string;
237
- };
238
201
  _onResize: () => void;
239
202
  _onPointerDown: (e: any) => void;
240
203
  _onPointerMove: (e: any) => void;
@@ -533,8 +496,7 @@ declare class WickChart extends HTMLElementBase {
533
496
  */
534
497
  /** @param {import('./core.js').IndicatorDef} def */
535
498
  static registerIndicator(name: any, def: import('./core.js').IndicatorDef): void;
536
- /** The tag this class registers as. (<hab-chart> is a deprecated alias
537
- * registered from the HabChart subclass, not this name.) */
499
+ /** The tag this class registers as. */
538
500
  static get elementName(): string;
539
501
  get data(): any[];
540
502
  /**
@@ -615,8 +577,7 @@ declare class WickChart extends HTMLElementBase {
615
577
  * WickScript predicate (`when`) on every streamed bar and fire on its
616
578
  * false→true edge — e.g. `when: 'crossup(rsi(close,14), 30)'` or
617
579
  * `when: 'volume > sma(volume,20) * 3'`. Scripted events carry the
618
- * triggering close as `price` plus the `when` source (deprecated
619
- * `hab:alert` alias still dispatched).
580
+ * triggering close as `price` plus the `when` source.
620
581
  * @param {{id?: string, price?: number, direction?: 'above'|'below'|'cross',
621
582
  * when?: string, once?: boolean}} alert
622
583
  * @returns {string|null} the alert id (null when no valid price/when,
@@ -656,96 +617,13 @@ declare class WickChart extends HTMLElementBase {
656
617
  addOverlay(ov: any): string | null;
657
618
  removeOverlay(id: any): void;
658
619
  clearOverlays(): void;
659
- /**
660
- * Scenario projection into future space: a ghost path of future prices
661
- * plus optional σ-bands (vol cone) from realized volatility.
662
- *
663
- * chart.setScenario({ path: [64000, 65500, 68000], label: 'bull case' });
664
- * chart.setScenario({ horizon: 48, cone: true }); // cone-only
665
- *
666
- * The path is an array of prices (or {price} objects) for future bars
667
- * 1..N; horizon defaults to the path length (1–500). `cone` (default
668
- * true) draws ±levels·σ bands widening with √h from the current realized
669
- * vol; `color` accepts up|down|accent or safe CSS colors. Setting a
670
- * scenario reserves future space on the right; analysis data — excluded
671
- * from getState/setState.
672
- * @param {object} spec
673
- * @returns {object|null} the normalized scenario, or null when invalid
674
- */
675
- setScenario(spec: object): object | null;
676
- clearScenario(): void;
677
- /** @returns {object|null} a copy of the active scenario */
620
+ /** @returns {object|null} a copy of the active scenario (set through the
621
+ * `_scenario` seam by the wickchart-scenario plugin; reserves future
622
+ * space via _rightMargin) */
678
623
  get scenario(): object | null;
679
- /**
680
- * Risk plan: an R-multiple grid anchored at entry/stop. 1R = |entry −
681
- * stop| (the risk unit); reward lines are drawn at kR beyond the entry
682
- * with the risk/reward zones shaded, so sizing and take-profit choices
683
- * read directly off the chart.
684
- *
685
- * chart.setRiskPlan({ entry: 64500, stop: 63800, multiples: [1, 2, 3] });
686
- * chart.setRiskPlan({ entry: 64500, stop: 63800, targets: [65900, 67300] });
687
- *
688
- * Direction is derived (stop below entry ⇒ long). Targets convert to
689
- * their R multiple; `multiples` win when both are given. Invalid specs
690
- * clear the plan (replace semantics, like setScenario); excluded from
691
- * getState/setState — it is app state, not chart state.
692
- * @param {object} spec
693
- * @returns {object|null} the normalized plan, or null when invalid
694
- */
695
- setRiskPlan(spec: object): object | null;
696
- clearRiskPlan(): void;
697
- /** @returns {object|null} a copy of the active risk plan */
624
+ /** @returns {object|null} a copy of the active risk plan (set through
625
+ * the `_riskPlan` seam by the wickchart-scenario plugin) */
698
626
  get riskPlan(): object | null;
699
- /** σ-cone for the active scenario, cached per data version. */
700
- _scenarioConeCache(): any;
701
- /** Tool manifest for LLM control — JSON-safe copy of AI_TOOLS. */
702
- aiTools(): any;
703
- /** System prompt for agent control — paste into any LLM alongside aiTools(). */
704
- aiPrompt(): string;
705
- /** Grounding context for a model: current state + visible-window summary. */
706
- aiContext(): {
707
- state: import("./core.js").ChartState;
708
- window: object;
709
- };
710
- /**
711
- * Apply a list of {tool, args} ops (typically LLM output) through the
712
- * validated dispatcher in core. Never throws — each op resolves
713
- * {ok, tool, result} or {ok: false, tool, error} so an agent can
714
- * self-correct.
715
- * @param {any} ops
716
- * @returns {Array<object>}
717
- */
718
- applyAI(ops: any): Array<object>;
719
- /**
720
- * Ask an AI to operate the chart. Builds the payload {system,
721
- * instruction, chart, tools}; with a `run` async function (your model
722
- * call — the chart itself never touches the network), applies the
723
- * returned ops and resolves {payload, ops, results}. Without `run`,
724
- * returns the payload for manual wiring — send it anywhere, then call
725
- * chart.applyAI(ops) with the model's answer.
726
- *
727
- * const { results } = await chart.ask('add RSI and mark the demand zone', {
728
- * run: async (payload) => (await callMyLLM(payload)).ops,
729
- * });
730
- *
731
- * @param {string} instruction natural-language request
732
- * @param {{run?: (payload: object) => Promise<any>}} [opts]
733
- */
734
- ask(instruction: string, opts?: {
735
- run?: (payload: object) => Promise<any>;
736
- }): Promise<{
737
- payload: {
738
- system: string;
739
- instruction: string;
740
- chart: {
741
- state: import("./core.js").ChartState;
742
- window: object;
743
- };
744
- tools: any;
745
- };
746
- ops: any;
747
- results: object[];
748
- }>;
749
627
  /** Check alerts against an incoming bar (prev close → new close).
750
628
  * Scripted (`when`) alerts evaluate their predicate series, cached per
751
629
  * data version, and fire on the false→true edge. */
@@ -802,6 +680,17 @@ declare class WickChart extends HTMLElementBase {
802
680
  _computeDt(): void;
803
681
  _updateAria(): void;
804
682
  _invalidate(): void;
683
+ /**
684
+ * Price-axis width with tick-noise immunity. The width is measured from
685
+ * the live last close, and digits in a proportional font measure
686
+ * differently ("1" is narrower than "8") — so on every tick the ceil()
687
+ * can flip a pixel, dragging the axis separator and with it every candle
688
+ * sideways (visibly shaking on high-frequency pairs). Grow at once so a
689
+ * wider label never clips; adopt a narrower width only after it has held
690
+ * for 750ms, and only when it's a real change (≥2px) rather than
691
+ * digit-width noise, so a flapping price can never wobble the layout.
692
+ */
693
+ _axisWidth(want: any): any;
805
694
  _prec(v: any): any;
806
695
  _palette(): {
807
696
  overlay: any;
@@ -980,84 +869,11 @@ declare class WickChart extends HTMLElementBase {
980
869
  _pointerMove(e: any): void;
981
870
  _pointerUp(e: any): void;
982
871
  _yToPrice(y: any): number;
872
+ /** Dispatch a `wick:name` event on the element. */
873
+ _fire(name: any, detail: any): void;
983
874
  _wheel(e: any): void;
984
875
  _keydown(e: any): void;
985
- /** Lazily-created shared AudioContext (enable within a user gesture). */
986
- _audio(): any;
987
- /** Short sine blip; `when` schedules against AudioContext time. */
988
- _tone(freq: any, dur?: number, when?: number): void;
989
- /** One tone for a bar's close, pitched by its position on the y-scale. */
990
- _sonifyBar(i: any): void;
991
- /** One tone per crosshair bar change (dedupes y-only moves). */
992
- _maybeSonify(idx: any): void;
993
- /**
994
- * Play the visible range as a pitch sweep (~4s), riding the crosshair —
995
- * the audible equivalent of running your eye along the price line.
996
- */
997
- playRange(): void;
998
876
  _emitCrosshair(hover: any): void;
999
- /** Join/leave the co-view channel named by the `co-view` attribute. */
1000
- _setupCoView(): void;
1001
- /** Broadcast our visible range for presence; throttled unless forced. */
1002
- _coviewSendView(force: any): void;
1003
- _coviewSend(msg: any): void;
1004
- _onCoMessage(m: any): void;
1005
- /** Dispatch `wick:name` (canonical) plus the deprecated `hab:name` alias,
1006
- * so 0.x listeners keep working until 2.0. */
1007
- _fire(name: any, detail: any): void;
1008
- /**
1009
- * Live co-view peers: who else is in the room and the time window each
1010
- * one is looking at — [{ id, name, range: {from, to}, at }], oldest
1011
- * sighting first. Peers fade out ~12 s after their last sighting.
1012
- * @returns {object[]}
1013
- */
1014
- getPeers(): object[];
1015
- /**
1016
- * Narrated timeline for a window (default: the visible range) — pivot
1017
- * highs/lows, volume spikes, gaps, RSI divergences plus derived legs
1018
- * ("+12.4% over 38 bars"), sorted by index. Pure data, perfect for
1019
- * caption UIs or the walk player.
1020
- * chart.narrate(); // visible range
1021
- * chart.narrate({ from, to }); // times in ms (s accepted)
1022
- * @param {{from?: number, to?: number}} [range]
1023
- * @returns {{i: number, time: number, type: string, side: string, note: string,
1024
- * legPct?: number, legBars?: number}[]}
1025
- */
1026
- narrate(range?: {
1027
- from?: number;
1028
- to?: number;
1029
- }): {
1030
- i: number;
1031
- time: number;
1032
- type: string;
1033
- side: string;
1034
- note: string;
1035
- legPct?: number;
1036
- legBars?: number;
1037
- }[];
1038
- /**
1039
- * Walk the chart through history like a story: the viewport slides
1040
- * from `from` to `to` while `wick:walk` events announce every step and
1041
- * the narrator's events (spikes, gaps, pivots, legs) as they're crossed.
1042
- * Any user interaction — pointer, wheel, keys, double-click — stops it.
1043
- * chart.walk({ from: 0, to: 500, speed: 120, step: 10 });
1044
- * chart.addEventListener('wick:walk', (e) => showCaption(e.detail));
1045
- * // detail: { phase: 'step'|'end'|'stop', index, events: [...], from, to }
1046
- * @param {{from?: number, to?: number, speed?: number, step?: number}} [opts]
1047
- * from/to are bar indices (default: last ~500 bars → the end)
1048
- * @returns {boolean} true when the walk started
1049
- */
1050
- walk(opts?: {
1051
- from?: number;
1052
- to?: number;
1053
- speed?: number;
1054
- step?: number;
1055
- }): boolean;
1056
- /**
1057
- * Stop the running walk (if any). Fires a final `wick:walk`
1058
- * { phase: 'stop' } unless called internally.
1059
- */
1060
- stopWalk(silent: any): void;
1061
877
  /**
1062
878
  * Commit a brush selection over [i0, i1]: stores it (draws the band
1063
879
  * and delta chip) and fires `wick:brush` with the range statistics.
@@ -1069,55 +885,6 @@ declare class WickChart extends HTMLElementBase {
1069
885
  clearBrush(): void;
1070
886
  /** @returns {object|null} the committed selection { i0, i1, stats } */
1071
887
  get brushSelection(): object | null;
1072
- /**
1073
- * Capture the current chart state as a story scene: view, series type,
1074
- * indicators, overlays, scenario and risk plan, plus a title/note.
1075
- * Build guided tours by capturing several and playing them back.
1076
- * const story = [
1077
- * chart.captureScene('Overview', 'The full picture'),
1078
- * { title: 'The breakout', range: { from, to }, indicators: 'sma:20' },
1079
- * ];
1080
- * chart.playStory(story);
1081
- * @param {string} [title]
1082
- * @param {string} [note]
1083
- * @returns {object} scene (plain data — snapshot of the moment)
1084
- */
1085
- captureScene(title?: string, note?: string): object;
1086
- /** @returns {object[]|null} a copy of the last played story */
1087
- getStory(): object[] | null;
1088
- /**
1089
- * Play a story: each scene applies its state (type / indicators /
1090
- * overlays / scenario / risk plan — set or clear), the camera eases
1091
- * to its range, then holds for its dwell. `wick:story` events narrate:
1092
- * { phase: 'scene' | 'end' | 'stop', index, total, scene, title, note }
1093
- * Any user interaction — pointer, wheel, keys, double-click — stops it.
1094
- * @param {object[]} story scenes (invalid entries dropped, max 20)
1095
- * @param {{dwell?: number, panMs?: number, loop?: boolean}} [opts]
1096
- * panMs clamps 100–5000 (default 900); loop replays forever
1097
- * @returns {boolean} true when playback started
1098
- */
1099
- playStory(story: object[], opts?: {
1100
- dwell?: number;
1101
- panMs?: number;
1102
- loop?: boolean;
1103
- }): boolean;
1104
- /**
1105
- * Stop story playback (if running). Fires a final `wick:story`
1106
- * { phase: 'stop' } unless called internally.
1107
- */
1108
- stopStory(silent: any): void;
1109
- /** Apply a scene's state (only the fields it carries). */
1110
- _applyScene(sc: any): void;
1111
- /** Map a scene's time range to bar indices (null when not applicable). */
1112
- _sceneTarget(sc: any): {
1113
- i0: number;
1114
- i1: number;
1115
- };
1116
- /** Ease the viewport to { i0, i1 } over `ms`; resolves early if the
1117
- * token changes (superseded or stopped). rAF when available. */
1118
- _storyTween(target: any, ms: any, token: any): Promise<any>;
1119
- /** Interrupt narrated playback (walk / story) on user input. */
1120
- _stopPlayback(): void;
1121
888
  _emitRange(): void;
1122
889
  }
1123
890
  export default WickChart;
@@ -15,10 +15,10 @@ declare class WickFeed extends HTMLElementBase {
15
15
  _scheduleRestart(): void;
16
16
  _teardown(): void;
17
17
  _setStatus(status: any, detail: any): void;
18
- /** Dispatch `wick-feed:name` plus the deprecated `hab-feed:name` alias. */
18
+ /** Dispatch `wick-feed:name`. */
19
19
  _fire(name: any, detail: any): void;
20
20
  /** Resolve the target chart (by `for` id, else the first chart element —
21
- * <wick-chart> or the deprecated <hab-chart>). */
21
+ * <wick-chart>). */
22
22
  _resolveChart(): Element;
23
23
  _restart(): void;
24
24
  _synthetic(gen: any, chart: any, key: any, tfId: any, limit: any, live: any, status?: string): void;