@orangecharts/wrun-chart-host 0.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.
Files changed (198) hide show
  1. package/README.md +72 -0
  2. package/dist/constants/governed-exchanges.constants.d.ts +11 -0
  3. package/dist/constants/governed-exchanges.constants.js +11 -0
  4. package/dist/constants/indicator-sets.constants.d.ts +8 -0
  5. package/dist/constants/indicator-sets.constants.js +8 -0
  6. package/dist/constants/interval.constants.d.ts +34 -0
  7. package/dist/constants/interval.constants.js +121 -0
  8. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
  9. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
  10. package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
  11. package/dist/constants/tpo-color-schemes.constants.js +32 -0
  12. package/dist/host-env.d.ts +102 -0
  13. package/dist/host-env.js +26 -0
  14. package/dist/index.d.ts +93 -0
  15. package/dist/index.js +96 -0
  16. package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
  17. package/dist/indicators/controls/tpo-letter.util.js +13 -0
  18. package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
  19. package/dist/indicators/controls/tpo-session.util.js +389 -0
  20. package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
  22. package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
  23. package/dist/interfaces/om-panel-data.interface.js +7 -0
  24. package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
  25. package/dist/interfaces/wrun-runtime.interface.js +55 -0
  26. package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
  27. package/dist/utility/chart/calendar-interval.util.js +81 -0
  28. package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
  29. package/dist/utility/chart/candle-bar-end.util.js +23 -0
  30. package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
  31. package/dist/utility/chart/cme-realtime.util.js +53 -0
  32. package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
  33. package/dist/utility/chart/interval-ladder.util.js +92 -0
  34. package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
  35. package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
  36. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
  37. package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
  38. package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
  39. package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
  40. package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
  41. package/dist/utility/chart/kscript-output-role.util.js +215 -0
  42. package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
  43. package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
  44. package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
  45. package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
  46. package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
  47. package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
  48. package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
  49. package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
  50. package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
  51. package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
  52. package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
  53. package/dist/utility/chart/om-panel-push-style.util.js +301 -0
  54. package/dist/utility/chart/om-panel.util.d.ts +166 -0
  55. package/dist/utility/chart/om-panel.util.js +815 -0
  56. package/dist/utility/chart/om-series.util.d.ts +42 -0
  57. package/dist/utility/chart/om-series.util.js +330 -0
  58. package/dist/utility/chart/om-target.util.d.ts +11 -0
  59. package/dist/utility/chart/om-target.util.js +24 -0
  60. package/dist/utility/chart/om-widget.util.d.ts +148 -0
  61. package/dist/utility/chart/om-widget.util.js +413 -0
  62. package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
  63. package/dist/utility/chart/overlay-output-budget.util.js +109 -0
  64. package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
  65. package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
  66. package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
  67. package/dist/utility/chart/profile-row-height.util.js +110 -0
  68. package/dist/utility/chart/session-interval.util.d.ts +1 -0
  69. package/dist/utility/chart/session-interval.util.js +35 -0
  70. package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
  71. package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
  72. package/dist/utility/chart/trading-day.util.d.ts +70 -0
  73. package/dist/utility/chart/trading-day.util.js +238 -0
  74. package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
  75. package/dist/utility/chart/wrun-legend-name.util.js +87 -0
  76. package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
  77. package/dist/utility/chart/wrun-run-result.util.js +5179 -0
  78. package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
  79. package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
  80. package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
  81. package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
  82. package/dist/utility/number-format.util.d.ts +68 -0
  83. package/dist/utility/number-format.util.js +188 -0
  84. package/dist/utility/v2/opra-governed.util.d.ts +1 -0
  85. package/dist/utility/v2/opra-governed.util.js +13 -0
  86. package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
  87. package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
  88. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
  89. package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
  90. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
  91. package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
  92. package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
  93. package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
  94. package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
  95. package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
  96. package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
  97. package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
  98. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
  99. package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
  100. package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
  101. package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
  102. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
  103. package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
  104. package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
  105. package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
  106. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
  107. package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
  108. package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
  109. package/dist/utility/wrun/wrun-card-style.util.js +539 -0
  110. package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
  111. package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
  112. package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
  113. package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
  114. package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
  115. package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
  116. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
  117. package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
  118. package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
  119. package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
  120. package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
  121. package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
  122. package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
  123. package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
  124. package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
  125. package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
  126. package/dist/utility/wrun/wrun-frames.d.ts +217 -0
  127. package/dist/utility/wrun/wrun-frames.js +1021 -0
  128. package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
  129. package/dist/utility/wrun/wrun-handles.util.js +2050 -0
  130. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
  131. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
  132. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
  133. package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
  134. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
  135. package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
  136. package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
  137. package/dist/utility/wrun/wrun-hover.util.js +534 -0
  138. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
  139. package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
  140. package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
  141. package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
  142. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
  143. package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
  144. package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
  145. package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
  146. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
  147. package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
  148. package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
  149. package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
  150. package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
  151. package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
  152. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
  153. package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
  154. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
  155. package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
  156. package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
  157. package/dist/utility/wrun/wrun-pack.util.js +301 -0
  158. package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
  159. package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
  160. package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
  161. package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
  162. package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
  163. package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
  164. package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
  165. package/dist/utility/wrun/wrun-param-values.util.js +230 -0
  166. package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
  167. package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
  168. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
  169. package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
  170. package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
  171. package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
  172. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
  173. package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
  174. package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
  175. package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
  176. package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
  177. package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
  178. package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
  179. package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
  180. package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
  181. package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
  182. package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
  183. package/dist/utility/wrun/wrun-style-words.util.js +439 -0
  184. package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
  185. package/dist/utility/wrun/wrun-table-look.util.js +225 -0
  186. package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
  187. package/dist/utility/wrun/wrun-text-look.util.js +227 -0
  188. package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
  189. package/dist/utility/wrun/wrun-text-params.util.js +171 -0
  190. package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
  191. package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
  192. package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
  193. package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
  194. package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
  195. package/dist/utility/wrun/wrun-visibility-table.js +237 -0
  196. package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
  197. package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
  198. package/package.json +38 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The batched records' readout (WRUN-BATCHED-MARKS): a `marks`, `spans` or `rays` record's meta
3
+ * decode, the number formats a template (and a marks caption) prints with, and the tooltip text.
4
+ * The batched mount registers the text as its readout's `text` (wrun-batched-marks.util
5
+ * `wrunBatchedChildConfig`), so the boot-path hover inspector prints a record through the thin
6
+ * registry (wrun-canvas-readout.util) and never loads this module itself. A timed spans or rays
7
+ * record (stride 5, WRUN-MARKS-CONTRACT F2) answers `{{start}}` and `{{end}}`, printed as the
8
+ * chart prints a time (wrun-chart-time.util), its meta read from its fifth field.
9
+ */
10
+ import { type WrunBatchedHoverRecord, type WrunCanvasReadout } from './wrun-canvas-readout.util.js';
11
+ /** A marks record's meta, `side + 4 * fills + 262144 * offset_ms`, read apart. */
12
+ export interface WrunMarkMeta {
13
+ /** 0..3: 0 sell, 1 buy (the record's colour index). */
14
+ side: number;
15
+ /** 0..65535. */
16
+ fills: number;
17
+ /** 0..2^30: the record's time inside its bar. */
18
+ offsetMs: number;
19
+ }
20
+ /** The largest `offset_ms` a marks meta packs (2^30 ms, 12.4 days). */
21
+ export declare const WRUN_MARK_META_MAX_OFFSET_MS: number;
22
+ /**
23
+ * A marks meta read apart by integer arithmetic (decode by division and modulo, exact below 2^53:
24
+ * the largest meta is 2^30 * 262144 + 262143 < 2^49). Null for a value that is no packed meta: not
25
+ * a finite whole number, negative, or past the largest offset.
26
+ */
27
+ export declare function decodeWrunMarkMeta(meta: number): WrunMarkMeta | null;
28
+ /** A spans or rays record's meta, `style + 8 * word + 256 * extend`, read apart. */
29
+ export interface WrunSpanMeta {
30
+ /** 0..7: the record's colour index. */
31
+ style: number;
32
+ /** 0..31: the word index (`words[word]`). */
33
+ word: number;
34
+ /** The extend bit: the record runs on to the right edge (a span to it, a ray along its slope). */
35
+ extend: boolean;
36
+ }
37
+ /** A spans or rays meta read apart, extend as the bit it is (`floor(meta / 256) % 2`, the engine's
38
+ * read); null for a value that is no packed meta (not a whole number from 0 to 511: a meta past
39
+ * the extend bit packs a field this chart does not read). */
40
+ export declare function decodeWrunSpanMeta(meta: number): WrunSpanMeta | null;
41
+ /** The `{{token}}` words a timed (stride-5) section's tooltip takes, by kind (the kit's
42
+ * WRUN_BATCHED_TIMED_TOOLTIP_TOKENS): `{{start}}` and `{{end}}` in place of `{{length}}`. Any other
43
+ * token stays as written on a timed record. */
44
+ export declare const WRUN_BATCHED_TIMED_TOOLTIP_TOKENS: Readonly<{
45
+ spans: readonly ['top', 'bottom', 'start', 'end', 'word'];
46
+ rays: readonly ['y1', 'y2', 'start', 'end', 'word'];
47
+ }>;
48
+ /**
49
+ * A timed record's start and end (epoch ms, the engine's rule): the start, or the record's own bar
50
+ * time when it is not a number; the end, or the start when it is not after it (a zero-length record
51
+ * at the start).
52
+ */
53
+ export declare function wrunTimedRecordSpan(record: Pick<WrunBatchedHoverRecord, 'ts' | 'fields'>): [number, number];
54
+ /** The number formats a batched template (and a marks caption) prints with. */
55
+ export type WrunBatchedNumberFormat = 'compact' | 'price' | 'int';
56
+ /** A number in a batched format: `compact` is Big Trades 0.3.2's caption ("1.2M", "1.2K", a whole
57
+ * number from 100, one decimal from 1, two below 1), `int` the rounded whole number, `price` the
58
+ * pane's price; a negative value keeps its sign. Not finite: '-'. */
59
+ export declare function formatWrunBatchedNumber(value: number, format: WrunBatchedNumberFormat | 'amount', formatPrice: (value: number) => string): string;
60
+ /**
61
+ * A batched record's tooltip (WRUN-BATCHED-MARKS): `{{name}}` or `{{name:<compact|price|int>}}`.
62
+ * Marks read `{{side}}`, `{{qty}}` (default the full amount), `{{price}}` (default price) and
63
+ * `{{fills}}` (default int); spans `{{top}}` and `{{bottom}}`, rays `{{y1}}` and `{{y2}}` (default
64
+ * price), both `{{length}}` (the length in bars, default int) and `{{word}}` (the section's word the meta
65
+ * names, '' when none); a timed record (stride 5) `{{start}}` and `{{end}}` in place of `{{length}}`,
66
+ * each the time as the chart prints it (`formatters.formatTime`, else wrun-chart-time.util shifted by
67
+ * the display offset the mount door stamped on the readout), its meta its fifth field; `{{label}}` is
68
+ * the readout's title. A placeholder
69
+ * the record does not read, or a format word outside the three, stays as written; a hole (a
70
+ * non-finite field) prints '-'.
71
+ */
72
+ export declare function wrunBatchedReadoutText(readout: WrunCanvasReadout, record: WrunBatchedHoverRecord, formatters: {
73
+ formatPrice: (value: number) => string;
74
+ formatTime?: (ms: number) => string;
75
+ }): string;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * The batched records' readout (WRUN-BATCHED-MARKS): a `marks`, `spans` or `rays` record's meta
3
+ * decode, the number formats a template (and a marks caption) prints with, and the tooltip text.
4
+ * The batched mount registers the text as its readout's `text` (wrun-batched-marks.util
5
+ * `wrunBatchedChildConfig`), so the boot-path hover inspector prints a record through the thin
6
+ * registry (wrun-canvas-readout.util) and never loads this module itself. A timed spans or rays
7
+ * record (stride 5, WRUN-MARKS-CONTRACT F2) answers `{{start}}` and `{{end}}`, printed as the
8
+ * chart prints a time (wrun-chart-time.util), its meta read from its fifth field.
9
+ */
10
+ import { CANVAS_PLACEHOLDER } from './wrun-canvas-readout.util.js';
11
+ import { wrunChartTimeText } from './wrun-chart-time.util.js';
12
+ /** The largest `offset_ms` a marks meta packs (2^30 ms, 12.4 days). */
13
+ export const WRUN_MARK_META_MAX_OFFSET_MS = 2 ** 30;
14
+ /**
15
+ * A marks meta read apart by integer arithmetic (decode by division and modulo, exact below 2^53:
16
+ * the largest meta is 2^30 * 262144 + 262143 < 2^49). Null for a value that is no packed meta: not
17
+ * a finite whole number, negative, or past the largest offset.
18
+ */
19
+ export function decodeWrunMarkMeta(meta) {
20
+ if (!Number.isInteger(meta) || meta < 0)
21
+ return null;
22
+ const offsetMs = Math.floor(meta / 262144);
23
+ if (offsetMs > WRUN_MARK_META_MAX_OFFSET_MS)
24
+ return null;
25
+ return { side: meta % 4, fills: Math.floor(meta / 4) % 65536, offsetMs };
26
+ }
27
+ /** A spans or rays meta read apart, extend as the bit it is (`floor(meta / 256) % 2`, the engine's
28
+ * read); null for a value that is no packed meta (not a whole number from 0 to 511: a meta past
29
+ * the extend bit packs a field this chart does not read). */
30
+ export function decodeWrunSpanMeta(meta) {
31
+ if (!Number.isInteger(meta) || meta < 0 || meta > 511)
32
+ return null;
33
+ return { style: meta % 8, word: Math.floor(meta / 8) % 32, extend: Math.floor(meta / 256) % 2 === 1 };
34
+ }
35
+ /** The `{{token}}` words a timed (stride-5) section's tooltip takes, by kind (the kit's
36
+ * WRUN_BATCHED_TIMED_TOOLTIP_TOKENS): `{{start}}` and `{{end}}` in place of `{{length}}`. Any other
37
+ * token stays as written on a timed record. */
38
+ export const WRUN_BATCHED_TIMED_TOOLTIP_TOKENS = Object.freeze({
39
+ spans: Object.freeze(['top', 'bottom', 'start', 'end', 'word']),
40
+ rays: Object.freeze(['y1', 'y2', 'start', 'end', 'word']),
41
+ });
42
+ /** A timed record's field positions: `[top|y1, bottom|y2, startTs, endTs, meta]`. */
43
+ const TIMED_START = 2;
44
+ const TIMED_END = 3;
45
+ const TIMED_META = 4;
46
+ /**
47
+ * A timed record's start and end (epoch ms, the engine's rule): the start, or the record's own bar
48
+ * time when it is not a number; the end, or the start when it is not after it (a zero-length record
49
+ * at the start).
50
+ */
51
+ export function wrunTimedRecordSpan(record) {
52
+ const at = (index) => {
53
+ const value = record.fields[index];
54
+ return typeof value === 'number' && Number.isFinite(value) ? value : Number.NaN;
55
+ };
56
+ const written = at(TIMED_START);
57
+ const start = Number.isFinite(written) ? written : record.ts;
58
+ const end = at(TIMED_END);
59
+ return [start, Number.isFinite(end) && end > start ? end : start];
60
+ }
61
+ const BATCHED_FORMATS = new Set(['compact', 'price', 'int']);
62
+ /** `tenths` (a whole count of tenths) as "1.5" or "2" (never "2.0"). */
63
+ function tenthsText(tenths) {
64
+ const whole = Math.trunc(tenths / 10);
65
+ const rest = Math.abs(tenths % 10);
66
+ return rest === 0 ? String(whole) : `${whole}.${rest}`;
67
+ }
68
+ /** The full amount (Big Trades 0.3.2's hover size): >= 100 whole, >= 1 one decimal (a trailing
69
+ * ".0" dropped), below 1 two decimals ("0.50"). */
70
+ function amountText(value) {
71
+ if (value >= 100)
72
+ return String(Math.round(value));
73
+ if (value >= 1)
74
+ return tenthsText(Math.round(value * 10));
75
+ return (Math.round(value * 100) / 100).toFixed(2);
76
+ }
77
+ /** A number in a batched format: `compact` is Big Trades 0.3.2's caption ("1.2M", "1.2K", a whole
78
+ * number from 100, one decimal from 1, two below 1), `int` the rounded whole number, `price` the
79
+ * pane's price; a negative value keeps its sign. Not finite: '-'. */
80
+ export function formatWrunBatchedNumber(value, format, formatPrice) {
81
+ if (!Number.isFinite(value))
82
+ return '-';
83
+ if (format === 'price')
84
+ return formatPrice(value);
85
+ if (format === 'int')
86
+ return String(Math.round(value));
87
+ const sign = value < 0 ? '-' : '';
88
+ const size = Math.abs(value);
89
+ if (format === 'amount')
90
+ return `${sign}${amountText(size)}`;
91
+ if (size >= 1_000_000)
92
+ return `${sign}${tenthsText(Math.round(size / 100_000))}M`;
93
+ if (size >= 1_000)
94
+ return `${sign}${tenthsText(Math.round(size / 100))}K`;
95
+ return `${sign}${amountText(size)}`;
96
+ }
97
+ /** The side words `{{side}}` prints, the template's own register (the author writes the template
98
+ * around them, as Big Trades 0.3.2's module wrote "Buy" and "Sell"). Sides 2 and 3 print their
99
+ * number. */
100
+ const SIDE_WORDS = { 0: 'Sell', 1: 'Buy' };
101
+ /**
102
+ * A batched record's tooltip (WRUN-BATCHED-MARKS): `{{name}}` or `{{name:<compact|price|int>}}`.
103
+ * Marks read `{{side}}`, `{{qty}}` (default the full amount), `{{price}}` (default price) and
104
+ * `{{fills}}` (default int); spans `{{top}}` and `{{bottom}}`, rays `{{y1}}` and `{{y2}}` (default
105
+ * price), both `{{length}}` (the length in bars, default int) and `{{word}}` (the section's word the meta
106
+ * names, '' when none); a timed record (stride 5) `{{start}}` and `{{end}}` in place of `{{length}}`,
107
+ * each the time as the chart prints it (`formatters.formatTime`, else wrun-chart-time.util shifted by
108
+ * the display offset the mount door stamped on the readout), its meta its fifth field; `{{label}}` is
109
+ * the readout's title. A placeholder
110
+ * the record does not read, or a format word outside the three, stays as written; a hole (a
111
+ * non-finite field) prints '-'.
112
+ */
113
+ export function wrunBatchedReadoutText(readout, record, formatters) {
114
+ const field = (at) => {
115
+ const value = record.fields[at];
116
+ return typeof value === 'number' ? value : Number.NaN;
117
+ };
118
+ const timed = readout.timed === true && (readout.kind === 'spans' || readout.kind === 'rays');
119
+ const markMeta = readout.kind === 'marks' ? decodeWrunMarkMeta(field(2)) : null;
120
+ const spanMeta = readout.kind === 'spans' || readout.kind === 'rays' ? decodeWrunSpanMeta(field(timed ? TIMED_META : 3)) : null;
121
+ // A printed time never breaks across the card's lines: its words are joined by no-break spaces.
122
+ const timeText = (ms) => {
123
+ const text = formatters.formatTime !== undefined
124
+ ? formatters.formatTime(ms)
125
+ : wrunChartTimeText(ms + (readout.timeOffsetMs ?? 0));
126
+ return text === undefined ? '-' : text.replace(/ /g, '\u00a0');
127
+ };
128
+ const number = (value, written, fallback) => formatWrunBatchedNumber(value, written !== undefined ? written : fallback, formatters.formatPrice);
129
+ return readout.tooltip.replace(CANVAS_PLACEHOLDER, (literal, name, format) => {
130
+ if (format !== undefined && !BATCHED_FORMATS.has(format))
131
+ return literal;
132
+ if (name === 'label')
133
+ return readout.label;
134
+ if (readout.kind === 'marks') {
135
+ switch (name) {
136
+ case 'side':
137
+ return markMeta === null ? '-' : (SIDE_WORDS[markMeta.side] ?? String(markMeta.side));
138
+ case 'qty':
139
+ return number(field(1), format, 'amount');
140
+ case 'price':
141
+ return number(field(0), format, 'price');
142
+ case 'fills':
143
+ return markMeta === null ? '-' : number(markMeta.fills, format, 'int');
144
+ default:
145
+ return literal;
146
+ }
147
+ }
148
+ const first = readout.kind === 'spans' ? 'top' : 'y1';
149
+ const second = readout.kind === 'spans' ? 'bottom' : 'y2';
150
+ if (timed &&
151
+ !WRUN_BATCHED_TIMED_TOOLTIP_TOKENS[readout.kind].includes(name)) {
152
+ return literal;
153
+ }
154
+ switch (name) {
155
+ case first:
156
+ return number(field(0), format, 'price');
157
+ case second:
158
+ return number(field(1), format, 'price');
159
+ case 'length':
160
+ return number(field(2), format, 'int');
161
+ case 'start':
162
+ return timed ? timeText(wrunTimedRecordSpan(record)[0]) : literal;
163
+ case 'end':
164
+ return timed ? timeText(wrunTimedRecordSpan(record)[1]) : literal;
165
+ case 'word':
166
+ return spanMeta === null ? '' : (readout.words?.[spanMeta.word] ?? '');
167
+ default:
168
+ return literal;
169
+ }
170
+ });
171
+ }
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Boxes and segments: per-bar geometry an Indicator package declares on its
3
+ * sheet (`wrun/metadata.json` `boxes` / `segments`) over outputs that already
4
+ * stream, evaluated by the host from the output rows it holds. No wire
5
+ * record carries the geometry: every anchor is a declared numeric output or
6
+ * a literal bar offset, so the sheet additions are legal under wrun-1 and
7
+ * wrun-2 alike and the wasm ABI is untouched.
8
+ *
9
+ * Sheet contract (frozen across hosts):
10
+ * - `boxes[]`: `{ name, top, bottom, x_from, x_to, when, panel, color,
11
+ * border_color, opacity (0..1, default 0.2), border_width (0..10,
12
+ * default 1) }`, at most 16. PT-box-ladder (WRUN-STYLE g2) adds the
13
+ * per-bar colour ladders: `color_by` + `colors` (1..64) or
14
+ * `color_packed_by` for the fill, `border_color_by` + `border_colors`
15
+ * (1..64) or `border_color_packed_by` for the border; a `_by` and its
16
+ * palette come together and never beside the packed form, every name a
17
+ * declared output (data-only ones included).
18
+ * - Every colour key also takes a theme token (`theme.up` ... `theme.accent`,
19
+ * TH-theme-tokens) beside its own grammar; the token rides to the paint
20
+ * pass unresolved.
21
+ * - `segments[]`: `{ name, y_from, y_to, x_from, x_to, when, panel, color,
22
+ * width (0.5..20, default 1), line_style (solid|dashed|dotted, default
23
+ * solid) }`, at most 16.
24
+ * - `x_from` / `x_to` are bar OFFSETS relative to the evaluated bar
25
+ * (negative = past), either a literal in [-500, 500], whole or
26
+ * fractional, or the name of an output whose per-bar value is truncated
27
+ * to an integer; both default 0. `when` optionally gates the bar (drawn
28
+ * only when finite and nonzero). `panel` defaults to the panel of the
29
+ * first y output.
30
+ *
31
+ * Per-bar semantics (`evaluateWrunSpans`): on the run's row grid, bar i
32
+ * draws nothing when the row is not ready, when any referenced output
33
+ * (y anchors, output-valued offsets, `when`) is non-finite there, or when
34
+ * `when` is 0; otherwise the span runs from row i + x_from to row i + x_to
35
+ * (a fractional literal anchors on the row of its whole bars) with anchors
36
+ * clamped to the loaded range's edges, carrying both y values in declared
37
+ * order. An edge's time is om's one placement rule (`wrunSpanEdgeTs`, the
38
+ * vendored wrunShapeEdgeTs): the whole bars on the row grid, a fraction
39
+ * as that share of the run's bar interval, where the kScript engine draws
40
+ * `bars.time[0] - currentInterval * 0.5`. The chart adapter shapes the
41
+ * spans into the kScript engine's own per-bar records (a box = a plotRange
42
+ * record, a segment = a per-bar line drawing), so the forming bar's
43
+ * re-evaluation on every tick REPLACES its record instead of stacking one.
44
+ *
45
+ * The vendored indicator kit types the raw sheet arrays as `WrunBox` /
46
+ * `WrunSegment` (every style field optional). This util reads
47
+ * them as untyped parsed JSON on purpose (a malformed sheet must refuse by
48
+ * name, not typecheck its way past) and hands back the defaults-applied
49
+ * `WrunBoxSpec` / `WrunSegmentSpec` forms the chart adapter consumes.
50
+ *
51
+ * The sheet's `strategy` section (wrun-3, OM-WRUN3-STRATEGIES-CONTRACT
52
+ * section 3) is read here too, in the same style: `readWrunStrategySheet`
53
+ * validates the section with the om validator's wording (every field
54
+ * optional, the engine's own value rules, `{ "param": "<name>" }` links on
55
+ * numeric fields, the four cross-field refusals by name) and hands the
56
+ * validated section to the shared host's resolver
57
+ * (`resolveWrunStrategySheet`, through the seam), which turns it into the
58
+ * engine's declared config at run time. The rows side table at the
59
+ * bottom (`attachWrunStrategy` / `wrunStrategyOf`) carries a run's
60
+ * `StrategyOutput` from the host to the run-result adapter the way the
61
+ * handle set travels.
62
+ */
63
+ import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
64
+ import type { StrategyOutput, WrunStrategySheet } from '@orangecharts/indicator-kit/host';
65
+ export declare const WRUN_BOX_CAP = 16;
66
+ export declare const WRUN_SEGMENT_CAP = 16;
67
+ /** A box colour ladder (`colors`, `border_colors`) lists 1..64 colours. */
68
+ export declare const WRUN_BOX_LADDER_CAP = 64;
69
+ type WrunBarOffsetRef = string | number;
70
+ export type WrunVisualPanel = 'overlay' | 'lower';
71
+ type WrunSegmentLineStyle = 'solid' | 'dashed' | 'dotted';
72
+ export interface WrunBoxSpec {
73
+ name: string;
74
+ top: string;
75
+ bottom: string;
76
+ x_from: WrunBarOffsetRef;
77
+ x_to: WrunBarOffsetRef;
78
+ when?: string;
79
+ panel?: WrunVisualPanel;
80
+ color?: string;
81
+ border_color?: string;
82
+ /** Fill alpha, 0..1. */
83
+ opacity: number;
84
+ /** Border stroke width, 0..10 (0 = no visible border). */
85
+ border_width: number;
86
+ /** PT-box-ladder: the output whose floor picks the bar's fill colour from
87
+ * `colors` (1..64, hex, rgb(), hsl() or a theme token), or an output of
88
+ * packed rgba; the same pair for the border. */
89
+ color_by?: string;
90
+ colors?: string[];
91
+ color_packed_by?: string;
92
+ border_color_by?: string;
93
+ border_colors?: string[];
94
+ border_color_packed_by?: string;
95
+ }
96
+ export interface WrunSegmentSpec {
97
+ name: string;
98
+ y_from: string;
99
+ y_to: string;
100
+ x_from: WrunBarOffsetRef;
101
+ x_to: WrunBarOffsetRef;
102
+ when?: string;
103
+ panel?: WrunVisualPanel;
104
+ color?: string;
105
+ /** Stroke width, 0.5..20. */
106
+ width: number;
107
+ line_style: WrunSegmentLineStyle;
108
+ }
109
+ /** The sheet fields this util reads; a package metadata object may carry
110
+ * them beside the kit-typed fields. */
111
+ export interface WrunBoxSegmentSheet {
112
+ boxes?: unknown;
113
+ segments?: unknown;
114
+ }
115
+ /** One evaluated bar: the two x anchors as CLAMPED row indexes in declared
116
+ * order (a fractional offset's row is the row of its whole bars) and the
117
+ * two y values in declared order. */
118
+ export interface WrunBarSpan {
119
+ fromRow: number;
120
+ toRow: number;
121
+ a: number;
122
+ b: number;
123
+ }
124
+ export interface WrunSpanRefs {
125
+ /** First y anchor (a box's `top`, a segment's `y_from`). */
126
+ a: string;
127
+ /** Second y anchor (a box's `bottom`, a segment's `y_to`). */
128
+ b: string;
129
+ x_from: WrunBarOffsetRef;
130
+ x_to: WrunBarOffsetRef;
131
+ when?: string;
132
+ }
133
+ export declare function isWrunAlphaColor(color: string): boolean;
134
+ /** The sheet's `boxes`, defaults applied, refused by name on a bad
135
+ * declaration (cap, cross-reference, offset, style range). Absent = []. */
136
+ export declare function readWrunBoxSpecs(metadata: WrunIndicatorMetadata): WrunBoxSpec[];
137
+ /** The sheet's `segments`, defaults applied, refused by name on a bad
138
+ * declaration. Absent = []. */
139
+ export declare function readWrunSegmentSpecs(metadata: WrunIndicatorMetadata): WrunSegmentSpec[];
140
+ /** Evaluate one declaration's spans over the row grid: one entry per row,
141
+ * `null` where the bar draws nothing. `outputIndexByName` maps declared
142
+ * output names to their column; every reference in `refs` must resolve
143
+ * (the readers above guarantee it for sheet declarations). */
144
+ export declare function evaluateWrunSpans(rows: ReadonlyArray<WrunOutputRow>, outputIndexByName: ReadonlyMap<string, number>, refs: WrunSpanRefs): Array<WrunBarSpan | null>;
145
+ /** The time a box or segment edge sits at: `offset` (a literal as written,
146
+ * an output-valued one already truncated) from the bar at `rowAt`, its
147
+ * whole bars through `rowTs` (the run's row grid, with the adapter's reach
148
+ * past the loaded rows) and its fraction as that share of `intervalMs`
149
+ * (the run's bar interval, kScript's currentInterval). om's one placement
150
+ * rule, vendored verbatim: a whole offset is exactly its row's time. */
151
+ export declare function wrunSpanEdgeTs(rowTs: (rowAt: number) => number, rowAt: number, offset: number, intervalMs: number): number;
152
+ /** The sheet field this util reads; a package metadata object carries it
153
+ * beside the kit-typed fields. The kit types it as `WrunStrategy`; this
154
+ * util reads it untyped on purpose, like the boxes and segments above (a
155
+ * malformed sheet must refuse by name, not typecheck its way past). */
156
+ export interface WrunStrategySheetHolder {
157
+ strategy?: unknown;
158
+ }
159
+ /** True when the sheet declares the strategy section (an Indicator that
160
+ * runs the broker), whatever the section holds. */
161
+ export declare function isWrunStrategySheet(metadata: WrunIndicatorMetadata | WrunStrategySheetHolder): boolean;
162
+ /**
163
+ * The sheet's `strategy` section, validated, or undefined when the sheet
164
+ * declares none. Every refusal names the sheet and the field in the om
165
+ * validator's words; the section itself comes back verbatim (literals and
166
+ * `{ "param": ... }` links, no default injected), the form the shared
167
+ * host's `resolveWrunStrategySheet` resolves against the instance's
168
+ * params at run time. Read during a run only (the host loaded first). Cross-field rules, each refusing by name:
169
+ * - a param link names a declared param (`wrun_strategy_*` links resolve at
170
+ * init() from the instance's params);
171
+ * - `slippage_model: "bookEstimate"` needs an order book provider no host
172
+ * supplies in this rung (`wrun_strategy_slippage_model_unsupported`);
173
+ * - the primary input (index 0) is the broker feed, so it reads source
174
+ * class `ohlcv` on the instance's own market (`wrun_strategy_feed_not_ohlcv`);
175
+ * - `strategy.position` and `strategy.equity` are host-published and
176
+ * reserved across the chart-name namespace (`wrun_strategy_reserved_output`).
177
+ */
178
+ export declare function readWrunStrategySheet(metadata: WrunIndicatorMetadata): WrunStrategySheet | undefined;
179
+ /** The instance's params by declared name from init()'s positional
180
+ * argument block (`buildWrunInitArgs` order), the values a
181
+ * `{ "param": ... }` link resolves from. */
182
+ export declare function wrunStrategyParamsOf(metadata: Pick<WrunIndicatorMetadata, 'params'>, initArgs: readonly number[]): Record<string, number>;
183
+ export declare function attachWrunStrategy(rows: ReadonlyArray<WrunOutputRow>, strategy: StrategyOutput): void;
184
+ export declare function wrunStrategyOf(rows: ReadonlyArray<WrunOutputRow>): StrategyOutput | undefined;
185
+ export {};