@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,20 @@
1
+ /**
2
+ * The boot path's door to the setting-words decode (`wrun-setting-words.util`): the Strategy
3
+ * Tester's naming, which store/chart evaluates before the first candle, names a wrun strategy's
4
+ * changed settings through here, so the decode stays off the pre-candle closure
5
+ * (docs/features/kscript/wrun/wrun-browser-runtime.md, "Boot doors").
6
+ *
7
+ * - Bound: the decode binds itself as it evaluates; every lane that mounts a wrun overlay builds its
8
+ * rows (wrun-script-inputs.util) and so evaluates it first, and a strategy's name comes from its
9
+ * run, after the mount.
10
+ * - Not mine: a kScript overlay never asks.
11
+ * - Late: unbound, the name prints the stored value, as before the decode.
12
+ *
13
+ * Pure on purpose (no import): the decode rides the worker graphs too.
14
+ */
15
+ import type * as WrunSettingWords from './wrun-setting-words.util.js';
16
+ export type WrunSettingWordsRuntime = Pick<typeof WrunSettingWords, 'wrunCodedWords' | 'wrunRowWordsShapes'>;
17
+ /** Hand the decode over: it calls this as it evaluates. */
18
+ export declare function bindWrunSettingWords(loaded: WrunSettingWordsRuntime): void;
19
+ /** The decode when bound, else undefined (the caller prints the stored value). */
20
+ export declare function wrunSettingWordsRuntime(): WrunSettingWordsRuntime | undefined;
@@ -0,0 +1,9 @@
1
+ let runtime;
2
+ /** Hand the decode over: it calls this as it evaluates. */
3
+ export function bindWrunSettingWords(loaded) {
4
+ runtime = loaded;
5
+ }
6
+ /** The decode when bound, else undefined (the caller prints the stored value). */
7
+ export function wrunSettingWordsRuntime() {
8
+ return runtime;
9
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Setting words: a wrun setting as the words a person reads, the ONE decode
3
+ * every text surface goes through (docs/features/kscript/wrun/wrun-typed-inputs.md,
4
+ * "Setting words"). wrun stores a choice as a code: a select its option value
5
+ * (a timeframe is a position in its sheet's word list, so "2" is 5m on one
6
+ * sheet and 15m on another), a multi a bitmask, a time epoch seconds, a
7
+ * session's start and end minutes after midnight. A surface hands the
8
+ * setting's shape and its stored value here and prints what comes back; it
9
+ * never decodes a code on its own.
10
+ *
11
+ * Pure and worker-safe: no i18n. The boot path reaches it through its door
12
+ * (wrun-setting-words.lazy.ts, bound below as this module evaluates). A
13
+ * surface that localizes passes the platform words (wrunSettingWordsFor,
14
+ * wrun-dialog-rows); without them a choice prints its label as the author
15
+ * wrote it, a word all the same.
16
+ */
17
+ import type { WrunScriptInputDeclaration } from './wrun-script-inputs.util.js';
18
+ /** What a decode needs to know about a setting: its kind and, for a choice, its option values and labels. */
19
+ export interface WrunWordsShape {
20
+ /** The row type, or a param's control type (wrunParamControlType). */
21
+ type?: string;
22
+ options?: ReadonlyArray<string>;
23
+ optionLabels?: ReadonlyArray<string>;
24
+ /** What a stale choice (an index past the options) reads as, as the dialog's row read does. */
25
+ defaultValue?: unknown;
26
+ /** A session window's start or end: the value is minutes after midnight. */
27
+ minutesOfDay?: boolean;
28
+ /** A Style row's property: `visible` reads as a toggle, `opacity` as a percent. */
29
+ styleProperty?: string;
30
+ }
31
+ /** The viewer's words for the platform's own vocabulary; every key is optional. */
32
+ export interface WrunSettingWords {
33
+ on?: string;
34
+ off?: string;
35
+ /** An empty multi. */
36
+ none?: string;
37
+ /** The timeframe word list's "follow the chart" choice. */
38
+ chart?: string;
39
+ /** The line styles by their platform word (solid, dashed, dotted). */
40
+ lineStyles?: Readonly<Record<string, string>>;
41
+ /** The zone a time reads in, ms east of UTC; UTC when absent. */
42
+ zoneOffsetMs?: number;
43
+ }
44
+ /** A choice label as the viewer reads it: a platform word ("chart", a line
45
+ * style) in the viewer's language when the surface passes its words, any
46
+ * other label as written. Display only: a stored value, a persisted label
47
+ * and every lookup by label keep the original word. */
48
+ export declare function wrunChoiceWord(label: string, words?: WrunSettingWords): string;
49
+ /** The words of a coded setting (a choice, a multi, a time, a session clock);
50
+ * undefined for every other kind, which a surface prints its own way. */
51
+ export declare function wrunCodedWords(shape: WrunWordsShape, value: unknown, words?: WrunSettingWords): string | undefined;
52
+ /** Any setting as the words a person reads: a coded one decoded, a toggle as
53
+ * its word (1/0 without words), a list joined, a line style as its word, an
54
+ * opacity as a percent, anything else as written. */
55
+ export declare function wrunSettingWords(shape: WrunWordsShape, value: unknown, words?: WrunSettingWords): string;
56
+ /** A settings row's shape. */
57
+ export declare function wrunRowWordsShape(row: WrunScriptInputDeclaration, minutesOfDay?: boolean): WrunWordsShape;
58
+ /** Every value row's shape by name, read off the whole row set: a session's
59
+ * start and end are plain number rows, and only their composite says they
60
+ * are clocks. A composite holds no value of its own (a unit composite's
61
+ * value member shares its name and wins). */
62
+ export declare function wrunRowWordsShapes(rows: ReadonlyArray<WrunScriptInputDeclaration>): Map<string, WrunWordsShape>;
63
+ /** The `when` gate: a toggle's true, a number other than 0, a numeric string other than "0". */
64
+ export declare function isTruthySetting(value: unknown): boolean;
65
+ /** Whether a multi's mask has bit `bit` set. Arithmetic, not bitwise: a mask
66
+ * is a double and holds every bit a multi declares (bitwise ops cut it to 32). */
67
+ export declare function multiMaskHas(mask: number, bit: number): boolean;
68
+ export declare function multiMaskIndices(mask: number, bits: number): number[];
69
+ /** Minutes from midnight as "HH:MM" (a session field's value). */
70
+ export declare function minutesToClock(minutes: number): string;
71
+ /** A 24h clock ("HH:MM", "H:MM", or the digits alone: "0930") as minutes
72
+ * from midnight; undefined for anything else. */
73
+ export declare function clockToMinutes(text: string): number | undefined;
74
+ /** Epoch seconds as the "YYYY-MM-DDTHH:MM" wall time a datetime-local field
75
+ * holds, in the zone `offsetMs` east of UTC (read with UTC getters, never
76
+ * the browser's zone). */
77
+ export declare function epochToLocalInput(seconds: number, offsetMs?: number): string;
78
+ /** A time value as people read it: its date and clock in the zone `offsetMs` east of UTC. */
79
+ export declare function describeTime(value: unknown, offsetMs?: number): string;
@@ -0,0 +1,176 @@
1
+ import { WRUN_TIMEFRAME_WORDS, wrunSelectOptionValue } from './wrun-color-settings.util.js';
2
+ import { bindWrunSettingWords } from './wrun-setting-words.lazy.js';
3
+ const CHART_WORD = WRUN_TIMEFRAME_WORDS[0];
4
+ /** A choice label as the viewer reads it: a platform word ("chart", a line
5
+ * style) in the viewer's language when the surface passes its words, any
6
+ * other label as written. Display only: a stored value, a persisted label
7
+ * and every lookup by label keep the original word. */
8
+ export function wrunChoiceWord(label, words) {
9
+ if (!words)
10
+ return label;
11
+ const word = label.trim().toLowerCase();
12
+ if (word === CHART_WORD)
13
+ return words.chart ?? label;
14
+ const lineStyles = words.lineStyles;
15
+ return lineStyles && Object.prototype.hasOwnProperty.call(lineStyles, word) ? lineStyles[word] : label;
16
+ }
17
+ /** The words of a coded setting (a choice, a multi, a time, a session clock);
18
+ * undefined for every other kind, which a surface prints its own way. */
19
+ export function wrunCodedWords(shape, value, words) {
20
+ if (shape.minutesOfDay) {
21
+ // Minutes after midnight, or a clock the session fields accept ("9:30", "0930").
22
+ const clock = typeof value === 'string' ? clockToMinutes(value) : undefined;
23
+ const minutes = clock ?? (typeof value === 'string' && value.trim() === '' ? Number.NaN : Number(value));
24
+ return Number.isFinite(minutes) ? minutesToClock(minutes) : undefined;
25
+ }
26
+ switch (shape.type) {
27
+ case 'select':
28
+ return choiceWords(shape, value, words);
29
+ case 'multi':
30
+ return multiWords(shape, value, words);
31
+ case 'time':
32
+ return describeTime(value, words?.zoneOffsetMs);
33
+ default:
34
+ return undefined;
35
+ }
36
+ }
37
+ /** Any setting as the words a person reads: a coded one decoded, a toggle as
38
+ * its word (1/0 without words), a list joined, a line style as its word, an
39
+ * opacity as a percent, anything else as written. */
40
+ export function wrunSettingWords(shape, value, words) {
41
+ if (Array.isArray(value))
42
+ return value.map(String).join(', ');
43
+ if (shape.type === 'boolean' || shape.styleProperty === 'visible') {
44
+ const on = isTruthySetting(value);
45
+ if (words?.on !== undefined && words.off !== undefined)
46
+ return on ? words.on : words.off;
47
+ return on ? '1' : '0';
48
+ }
49
+ // A Style row's line style holds the platform word itself ("dashed").
50
+ if (shape.styleProperty === 'lineStyle' && typeof value === 'string')
51
+ return wrunChoiceWord(value, words);
52
+ const coded = wrunCodedWords(shape, value, words);
53
+ if (coded !== undefined)
54
+ return coded;
55
+ if (shape.styleProperty === 'opacity')
56
+ return `${Math.round((Number(value) || 0) * 100)}%`;
57
+ return value === undefined || value === null ? '' : String(value);
58
+ }
59
+ /** The option a stored choice names (through the one select read), else the
60
+ * default's (a stale index), as its label. */
61
+ function choiceWords(shape, value, words) {
62
+ const options = shape.options ?? [];
63
+ if (options.length === 0)
64
+ return undefined;
65
+ const labels = shape.optionLabels ?? [];
66
+ const picked = wrunSelectOptionValue(options, labels, value) ?? wrunSelectOptionValue(options, labels, shape.defaultValue);
67
+ if (picked === undefined)
68
+ return undefined;
69
+ const label = labels[options.indexOf(picked)];
70
+ return wrunChoiceWord(typeof label === 'string' && label.trim() !== '' ? label : picked, words);
71
+ }
72
+ function multiWords(shape, value, words) {
73
+ const labels = shape.optionLabels ?? [];
74
+ if (labels.length === 0)
75
+ return undefined;
76
+ const mask = Number(value);
77
+ const set = multiMaskIndices(Number.isFinite(mask) ? mask : 0, labels.length).map((bit) => labels[bit]);
78
+ return set.length ? set.join(', ') : (words?.none ?? '');
79
+ }
80
+ // ── shapes ──────────────────────────────────────────────────────────────────
81
+ /** A settings row's shape. */
82
+ export function wrunRowWordsShape(row, minutesOfDay = false) {
83
+ return {
84
+ type: row.type,
85
+ ...(row.options ? { options: row.options } : {}),
86
+ ...(row.optionLabels ? { optionLabels: row.optionLabels } : {}),
87
+ defaultValue: row.defaultValue,
88
+ ...(minutesOfDay ? { minutesOfDay } : {}),
89
+ ...(row.styleOf?.property ? { styleProperty: row.styleOf.property } : {}),
90
+ };
91
+ }
92
+ /** Every value row's shape by name, read off the whole row set: a session's
93
+ * start and end are plain number rows, and only their composite says they
94
+ * are clocks. A composite holds no value of its own (a unit composite's
95
+ * value member shares its name and wins). */
96
+ export function wrunRowWordsShapes(rows) {
97
+ const byName = new Map(rows.filter((row) => !row.virtual).map((row) => [row.name, row]));
98
+ const clocks = new Set();
99
+ for (const row of rows) {
100
+ if (row.type !== 'session')
101
+ continue;
102
+ for (const name of row.members ?? []) {
103
+ const member = byName.get(name);
104
+ if (member && (member.type === 'number' || member.type === 'int'))
105
+ clocks.add(name);
106
+ }
107
+ }
108
+ const shapes = new Map();
109
+ for (const [name, row] of byName)
110
+ shapes.set(name, wrunRowWordsShape(row, clocks.has(name)));
111
+ return shapes;
112
+ }
113
+ // ── codecs (the settings dialog re-exports them) ────────────────────────────
114
+ /** The `when` gate: a toggle's true, a number other than 0, a numeric string other than "0". */
115
+ export function isTruthySetting(value) {
116
+ if (typeof value === 'boolean')
117
+ return value;
118
+ if (typeof value === 'number')
119
+ return value !== 0;
120
+ if (typeof value === 'string') {
121
+ const trimmed = value.trim().toLowerCase();
122
+ if (trimmed === '' || trimmed === 'false')
123
+ return false;
124
+ const numeric = Number(trimmed);
125
+ return Number.isFinite(numeric) ? numeric !== 0 : true;
126
+ }
127
+ return Boolean(value);
128
+ }
129
+ /** Whether a multi's mask has bit `bit` set. Arithmetic, not bitwise: a mask
130
+ * is a double and holds every bit a multi declares (bitwise ops cut it to 32). */
131
+ export function multiMaskHas(mask, bit) {
132
+ return Math.floor(Math.trunc(mask) / 2 ** bit) % 2 === 1;
133
+ }
134
+ export function multiMaskIndices(mask, bits) {
135
+ const on = [];
136
+ for (let bit = 0; bit < bits; bit += 1)
137
+ if (multiMaskHas(mask, bit))
138
+ on.push(bit);
139
+ return on;
140
+ }
141
+ /** Minutes from midnight as "HH:MM" (a session field's value). */
142
+ export function minutesToClock(minutes) {
143
+ const total = ((Math.round(minutes) % 1440) + 1440) % 1440;
144
+ const hours = Math.floor(total / 60);
145
+ const mins = total % 60;
146
+ return `${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}`;
147
+ }
148
+ /** A 24h clock ("HH:MM", "H:MM", or the digits alone: "0930") as minutes
149
+ * from midnight; undefined for anything else. */
150
+ export function clockToMinutes(text) {
151
+ const match = /^\s*(\d{1,2}):?(\d{2})\s*$/.exec(text);
152
+ if (!match)
153
+ return undefined;
154
+ const hours = Number(match[1]);
155
+ const mins = Number(match[2]);
156
+ if (hours > 23 || mins > 59)
157
+ return undefined;
158
+ return hours * 60 + mins;
159
+ }
160
+ /** Epoch seconds as the "YYYY-MM-DDTHH:MM" wall time a datetime-local field
161
+ * holds, in the zone `offsetMs` east of UTC (read with UTC getters, never
162
+ * the browser's zone). */
163
+ export function epochToLocalInput(seconds, offsetMs = 0) {
164
+ if (!Number.isFinite(seconds))
165
+ return '';
166
+ const wall = new Date(seconds * 1000 + offsetMs);
167
+ if (Number.isNaN(wall.getTime()))
168
+ return '';
169
+ const pad = (n) => String(n).padStart(2, '0');
170
+ return `${wall.getUTCFullYear()}-${pad(wall.getUTCMonth() + 1)}-${pad(wall.getUTCDate())}T${pad(wall.getUTCHours())}:${pad(wall.getUTCMinutes())}`;
171
+ }
172
+ /** A time value as people read it: its date and clock in the zone `offsetMs` east of UTC. */
173
+ export function describeTime(value, offsetMs = 0) {
174
+ return epochToLocalInput(Number(value), offsetMs).replace('T', ' ');
175
+ }
176
+ bindWrunSettingWords({ wrunCodedWords, wrunRowWordsShapes });
@@ -0,0 +1,98 @@
1
+ import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
2
+ import type { WrunHandleRecord } from './wrun-handles.util.js';
3
+ import type { WrunHostedGrid, WrunHostedRefusal, WrunHostedWire } from './wrun-hosted-wire.util.js';
4
+ import type { WrunCellRows } from './wrun-canvases.util.js';
5
+ /** The merge's default cap, for a caller that names no policy. A merge above it drops the OLDEST
6
+ * bars, and the cell rows with them, whatever the reply's window: the session always keeps the
7
+ * newest bars, so it never loses continuity with live. The socket row source merges with no cap
8
+ * (`WRUN_SOCKET_ROW_STORE_UNCAPPED`): plan Q3 moved the cloud's caps to the profile. */
9
+ export declare const WRUN_HOSTED_SESSION_MAX_BARS = 5000;
10
+ /** The merge policy of the socket row source: every bar the cloud answered stays (plan Q3). */
11
+ export declare const WRUN_SOCKET_ROW_STORE_UNCAPPED: WrunHostedMergePolicy;
12
+ /** How a merge keeps bars: `maxBars` is the most the merged session holds (default
13
+ * `WRUN_HOSTED_SESSION_MAX_BARS`; `Infinity` keeps every bar). */
14
+ export interface WrunHostedMergePolicy {
15
+ maxBars?: number;
16
+ }
17
+ export interface WrunHostedSession {
18
+ /** Whose replies merge here; a reply of another identity starts a new session. */
19
+ identity: string;
20
+ /** The sheet the cloud ran: a result's own sheet, else the session's. */
21
+ sheet: WrunIndicatorMetadata;
22
+ /** Every bar held, ascending by ts, unshifted, ready flags kept. */
23
+ rows: WrunOutputRow[];
24
+ /** The cell rows per celled input, keyed `<kind>:<input>` (kinds `cells` and `intrabar`). */
25
+ grids: ReadonlyMap<string, WrunHostedGrid>;
26
+ /** The newest snapshots by slot (undefined = unwritten). */
27
+ frames?: (string | undefined)[];
28
+ /** The newest live handle set; bar stamps index `rows` (-1 = before the rows or unresolved). */
29
+ handles?: WrunHandleRecord[];
30
+ /** The families the cloud refused, from the reply the snapshots came from. */
31
+ refusals: WrunHostedRefusal[];
32
+ /** The open of the newest bar the run behind the snapshots evaluated. */
33
+ asOfMs: number;
34
+ }
35
+ /** What a reply is: its identity (the caller's run identity) and its message kind. */
36
+ export interface WrunHostedReply {
37
+ identity: string;
38
+ kind: 'result' | 'live';
39
+ }
40
+ export type WrunHostedMerge = {
41
+ session: WrunHostedSession;
42
+ /** The reply's frames, handles, refusals and asOfMs replaced the session's. */
43
+ acceptedSnapshots: boolean;
44
+ /** The reply's row count. */
45
+ tailRows: number;
46
+ /** How many bars are newer than the session's previous last bar. */
47
+ newBars: number;
48
+ } | {
49
+ refused: 'no-sheet' | 'no-session';
50
+ };
51
+ /**
52
+ * Merge one decoded reply into the session.
53
+ *
54
+ * 1. A missing session or another identity starts empty. A `live` reply with no session of its
55
+ * identity is refused `no-session`; a `result` with no sheet and no session sheet `no-sheet`.
56
+ * 2. Rows, `result`: the stored rows inside the reply's window (`fromMs <= ts <= toMs`) are
57
+ * replaced by the reply's rows inside it, order kept.
58
+ * 3. Rows, `live`: the stored rows at or after the reply's first row are replaced by the reply's.
59
+ * 4. Cell rows, per `<kind>:<input>` entry, by the same two rules (a live entry cuts at the
60
+ * earlier of the reply's first row and its own first row). An entry the reply does not carry
61
+ * keeps its rows.
62
+ * 5. Snapshots are accepted when the session starts empty, holds no finite `asOfMs`, or the
63
+ * reply's `asOfMs` is not older; then frames, handles, refusals and `asOfMs` are the reply's
64
+ * (absent means absent), else the session's.
65
+ * 6. Handle bar stamps index the merged rows: a reply's stamp maps through its own row's ts; a
66
+ * negative or unresolved stamp is -1; a missing stamp takes the same id's previous stamp,
67
+ * else the last merged bar. Kept handles are re-based by ts the same way.
68
+ * 7. Above the policy's `maxBars` (default WRUN_HOSTED_SESSION_MAX_BARS) the oldest bars drop,
69
+ * whatever the reply's window. A result page whose rows all fall below the bars kept changes
70
+ * none of the session's bars or cell rows (its snapshots are still judged by rule 5). The
71
+ * socket row source passes WRUN_SOCKET_ROW_STORE_UNCAPPED: nothing drops.
72
+ */
73
+ export declare function mergeWrunHostedReply(session: WrunHostedSession | undefined, wire: WrunHostedWire, reply: WrunHostedReply, policy?: WrunHostedMergePolicy): WrunHostedMerge;
74
+ /** A grid entry's key in the session (`<kind>:<input>`): a reply's entry merges into the stored entry of its key. */
75
+ export declare function wrunHostedGridKey(grid: Pick<WrunHostedGrid, 'kind' | 'input'>): string;
76
+ /**
77
+ * The canvases' cell rows from the session's grid entries: the first `cells` entry of class
78
+ * `book` is the book lane, the first of class `volume_profile` the profile lane, every
79
+ * `intrabar` entry its input's candles (the lowest input index also `intrabarRows`, its interval
80
+ * from the sheet's pin when the interval table knows the word), and the chart's own candles
81
+ * `ohlcvRows`. Any other entry is ignored. Pure: rows are read, never written.
82
+ */
83
+ export declare function wrunCellRowsFromHostedGrids(sheet: Pick<WrunIndicatorMetadata, 'inputs' | 'inputSources'>, grids: ReadonlyMap<string, WrunHostedGrid> | ReadonlyArray<WrunHostedGrid>, chartCandles?: ReadonlyArray<unknown>): WrunCellRows;
84
+ /**
85
+ * The same cell rows with each entry's lane rows from `laneOf`, asked only for the entries the
86
+ * canvases read: the whole conversion converts them (`wrunHostedGridLaneRows`), the socket row
87
+ * source answers the ones its cells memo kept (`SocketWrunRowSource.cellRows`).
88
+ */
89
+ export declare function wrunCellRowsFromHostedLanes(sheet: Pick<WrunIndicatorMetadata, 'inputs' | 'inputSources'>, grids: ReadonlyMap<string, WrunHostedGrid> | ReadonlyArray<WrunHostedGrid>, laneOf: (grid: WrunHostedGrid) => ReadonlyArray<unknown>, chartCandles?: ReadonlyArray<unknown>): WrunCellRows;
90
+ /**
91
+ * The lane rows of an entry's rows `[from, to)` (default all), in row order: a book row's
92
+ * `[ts, price, side * size, ...]` and a volume_profile row's `[ts, [low, high, buy, sell], ...]`
93
+ * (one each), an intrabar row's candles (one per timed tuple). Fresh rows; none for another class.
94
+ */
95
+ export declare function wrunHostedGridLaneRows(grid: WrunHostedGrid, from?: number, to?: number): unknown[];
96
+ /** How many lane rows `wrunHostedGridLaneRows(grid, from, to)` answers, converting none: one per
97
+ * book or volume_profile row, one per timed tuple of an intrabar row. */
98
+ export declare function wrunHostedGridLaneRowCount(grid: WrunHostedGrid, from?: number, to?: number): number;