@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,77 @@
1
+ import type { WrunRunFailedIdentity, WrunRunWindow } from './wrun-lifecycle.contract.js';
2
+ import { type WrunCapNoticeChart, type WrunCapNoticeRetained, type WrunCellsCapSummary } from '../../host-env.js';
3
+ export type { WrunCellsCapSummary };
4
+ /** ONE run's drawing budget, carried by the parent result and its lower panes' results. */
5
+ export interface WrunDrawingsBudget {
6
+ /** Drawings the run asked for, parent and lower panes together. */
7
+ total: number;
8
+ /** Drawings the preflight kept (at most `cap`). */
9
+ keptAfterPreflight: number;
10
+ /** The drawing budget the preflight applied. */
11
+ cap: number;
12
+ /** Increases with every budgeted result: the door never lets an older revision overwrite a newer row. */
13
+ revision: number;
14
+ }
15
+ /** The context a result's drawings carry: the result's own field, else the one keyed by its
16
+ * drawings array (a live batch rebuilt around the array). */
17
+ export declare function wrunDrawingsBudgetOf(output: unknown): WrunDrawingsBudget | undefined;
18
+ interface WrunBudgetedResult {
19
+ drawings?: unknown[];
20
+ childOverlays?: ReadonlyArray<{
21
+ kind: string;
22
+ result?: unknown;
23
+ }>;
24
+ }
25
+ /**
26
+ * The drawing budget over one result (the full run's preflight, and every live tick re-entering it):
27
+ * the parent and its lower panes (series children) count together; past the budget the newest
28
+ * drawings by `createdBar` are kept (a tie: the later record), tables and widgets are never dropped
29
+ * (they take their room first), and every result's drawings array is replaced by its kept records
30
+ * (the records, their ids and the worker's handle ledger are untouched, so a later tick that mutates
31
+ * an older trimmed handle trims the same way again). The context rides every member. Mutates the
32
+ * result's `drawings` fields in place; returns the context.
33
+ */
34
+ export declare function trimWrunRunDrawings(runResult: WrunBudgetedResult): WrunDrawingsBudget;
35
+ /** An overlay's engine settings as one comparable string ('' when they cannot be read). */
36
+ export declare function wrunSettingsSignature(settings: unknown): string;
37
+ /**
38
+ * A run's identity: the window it computes (the requested window's bounds, else the chart's loaded
39
+ * main rows, first to last) and the settings it computes with. Undefined when the window cannot be
40
+ * read (no rows), so nothing latches on it.
41
+ */
42
+ export declare function wrunRunIdentityOf(input: {
43
+ window?: WrunRunWindow;
44
+ mainRows?: unknown;
45
+ settings: unknown;
46
+ }): WrunRunFailedIdentity | undefined;
47
+ /** Hand a run's rejection the identity of the run that failed (the run's settle producer). An
48
+ * identity already carried wins; a non-object rejection carries none. */
49
+ export declare function annotateWrunRunFailedIdentity<T>(error: T, identity: WrunRunFailedIdentity | undefined): T;
50
+ /** The failed run's identity a rejection carries, or undefined. */
51
+ export declare function wrunRunFailedIdentityOf(error: unknown): WrunRunFailedIdentity | undefined;
52
+ /** The locale keys of the "Cells capped" row's words: the host writes the row in its own words through them (web:
53
+ * wrun-cap-notice-publish.util). Data only, the package never translates. Here they also stay in the web app's boot
54
+ * locale bundle, as when this module wrote the row's words (scripts/i18n-boot-keys.mjs harvests the dotted literals
55
+ * of the pre-candle closure). */
56
+ export declare const WRUN_CELLS_NOTICE_KEYS: {
57
+ readonly retained: "kscript.errors.RUN_RETAINED_BARS";
58
+ readonly capped: "kscript.errors.CELLS_CAPPED";
59
+ readonly retainedFix: "kscript.fix.RUN_RETAINED_BARS";
60
+ readonly cappedFix: "kscript.fix.CELLS_CAPPED";
61
+ };
62
+ /** The chart a notice belongs to (the host env's notice chart: any engine instance). */
63
+ type CellsChart = WrunCapNoticeChart;
64
+ /** The budgets that report into the one "Cells capped" row: the heatmap children's and the batched
65
+ * marks children's (each its own cap). */
66
+ export type WrunCellsBudgetFamily = 'heatmap' | 'batched';
67
+ /** Several budgets' summaries as the one row reads them: the mounted cells summed; capped when any
68
+ * budget is, its totals and caps summed, the most bars asked for and the fewest kept. */
69
+ export declare function combineWrunCellsCapSummaries(summaries: ReadonlyArray<WrunCellsCapSummary>): WrunCellsCapSummary;
70
+ /**
71
+ * Owe the Indicator's cells notice for one budget (`family`, the heatmaps' by default): one publish
72
+ * per chart per batch of seams, reading every budget's summary when it runs (the last seam's
73
+ * numbers), never a stale snapshot. Never throws.
74
+ */
75
+ export declare function scheduleWrunCellsCapNotice(tc: CellsChart, overlayId: string, summary: () => WrunCellsCapSummary, family?: WrunCellsBudgetFamily): void;
76
+ /** The run's retained range on the Indicator's row (design 5), null when the run calculated every loaded bar. */
77
+ export declare function noteWrunRunRetained(tc: CellsChart, overlayId: string, retained: WrunCapNoticeRetained | null): void;
@@ -0,0 +1,296 @@
1
+ /**
2
+ * What the chart's caps leave behind for a wrun Indicator (WRUN-COST-GUARD U4, "caps trim and say"):
3
+ *
4
+ * - the DRAWINGS run context: a run over the drawing budget (`OVERLAY_HISTORICAL_DRAWING_BUDGET`)
5
+ * keeps its newest drawings by `createdBar` across the parent and its lower panes
6
+ * (`trimWrunRunDrawings`, the full run's preflight and every live tick alike), and ONE context
7
+ * `{ total, keptAfterPreflight, cap, revision }` rides each of those results (a field on the
8
+ * result, and keyed by its drawings array so a live batch that carries the array alone still finds
9
+ * it). The drawing door (kscript-drawings.util `publishDrawingCapDiagnostic`) is the only writer of
10
+ * the "Drawings capped" row: it reads the context, applies its own per-kind caps and the linefill
11
+ * closure, and publishes the final count once per revision;
12
+ * - the CELLS notice: ONE "Cells capped" row per Indicator for all its heatmap children and its
13
+ * batched marks children (`scheduleWrunCellsCapNotice`, fed by wrun-heatmap-cell-budget.util and
14
+ * wrun-batched-marks.util, one reader per budget; a publish reads both and sums them), written
15
+ * by the host (the env's `diagnostics.publishCapNotice`; web: wrun-cap-notice-publish.util, beside
16
+ * every other row, cleared once every child fits again, with the Indicator's mounted cell count for
17
+ * the cost table). The run's retained range (`noteWrunRunRetained`,
18
+ * design 5) is a third family under its own key, ahead of the children's words, never summed;
19
+ * - the identity of a run the ROW cap refused (`FE_KSCRIPT_OUTPUT_OVERSIZED` cannot be trimmed
20
+ * without changing the plot): its window and settings ride the rejection, so the recovery's
21
+ * deterministic latch holds the same run on the same window instead of spending it again.
22
+ *
23
+ * Import graph: the output budgets and the host env at import; the host writes each owed notice (no
24
+ * store, no chart instance, no i18n here).
25
+ */
26
+ import { OVERLAY_HISTORICAL_DRAWING_BUDGET } from '../chart/overlay-output-budget.util.js';
27
+ import { wrunChartHostEnv, } from '../../host-env.js';
28
+ /** Chrome the preflight never trims (bounded by the door's own per-kind and per-pane caps). */
29
+ const UNTRIMMED_DRAWING_KINDS = new Set(['table', 'card', 'feed', 'meter', 'ladder']);
30
+ const budgetsByDrawings = new WeakMap();
31
+ let revisions = 0;
32
+ function isRecord(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
34
+ }
35
+ function isDrawingsBudget(value) {
36
+ return (isRecord(value) &&
37
+ typeof value.total === 'number' &&
38
+ typeof value.keptAfterPreflight === 'number' &&
39
+ typeof value.cap === 'number' &&
40
+ typeof value.revision === 'number');
41
+ }
42
+ /** The context a result's drawings carry: the result's own field, else the one keyed by its
43
+ * drawings array (a live batch rebuilt around the array). */
44
+ export function wrunDrawingsBudgetOf(output) {
45
+ if (!isRecord(output))
46
+ return undefined;
47
+ if (isDrawingsBudget(output.drawingsBudget))
48
+ return output.drawingsBudget;
49
+ const drawings = output.drawings;
50
+ return Array.isArray(drawings) ? budgetsByDrawings.get(drawings) : undefined;
51
+ }
52
+ /**
53
+ * The drawing budget over one result (the full run's preflight, and every live tick re-entering it):
54
+ * the parent and its lower panes (series children) count together; past the budget the newest
55
+ * drawings by `createdBar` are kept (a tie: the later record), tables and widgets are never dropped
56
+ * (they take their room first), and every result's drawings array is replaced by its kept records
57
+ * (the records, their ids and the worker's handle ledger are untouched, so a later tick that mutates
58
+ * an older trimmed handle trims the same way again). The context rides every member. Mutates the
59
+ * result's `drawings` fields in place; returns the context.
60
+ */
61
+ export function trimWrunRunDrawings(runResult) {
62
+ const members = [runResult];
63
+ for (const child of runResult.childOverlays ?? []) {
64
+ if (child.kind === 'series' && isRecord(child.result))
65
+ members.push(child.result);
66
+ }
67
+ const total = members.reduce((sum, member) => sum + (Array.isArray(member.drawings) ? member.drawings.length : 0), 0);
68
+ const cap = OVERLAY_HISTORICAL_DRAWING_BUDGET;
69
+ let kept = total;
70
+ if (total > cap) {
71
+ const candidates = [];
72
+ let untrimmed = 0;
73
+ members.forEach((member, at) => {
74
+ (member.drawings ?? []).forEach((drawing, index) => {
75
+ if (isRecord(drawing) && typeof drawing.kind === 'string' && UNTRIMMED_DRAWING_KINDS.has(drawing.kind)) {
76
+ untrimmed += 1;
77
+ return;
78
+ }
79
+ const bar = isRecord(drawing) ? drawing.createdBar : undefined;
80
+ candidates.push({
81
+ member: at,
82
+ index,
83
+ createdBar: typeof bar === 'number' && Number.isFinite(bar) ? bar : Number.NEGATIVE_INFINITY,
84
+ });
85
+ });
86
+ });
87
+ const room = Math.max(0, cap - untrimmed);
88
+ candidates.sort((a, b) => (b.createdBar === a.createdBar ? 0 : b.createdBar > a.createdBar ? 1 : -1) ||
89
+ a.member - b.member ||
90
+ b.index - a.index);
91
+ const keep = members.map(() => new Set());
92
+ for (const candidate of candidates.slice(0, room))
93
+ keep[candidate.member].add(candidate.index);
94
+ members.forEach((member, at) => {
95
+ const drawings = member.drawings;
96
+ if (!Array.isArray(drawings))
97
+ return;
98
+ const next = drawings.filter((drawing, index) => keep[at].has(index) ||
99
+ (isRecord(drawing) && typeof drawing.kind === 'string' && UNTRIMMED_DRAWING_KINDS.has(drawing.kind)));
100
+ if (next.length !== drawings.length)
101
+ member.drawings = next;
102
+ });
103
+ kept = untrimmed + Math.min(room, candidates.length);
104
+ }
105
+ revisions += 1;
106
+ const budget = { total, keptAfterPreflight: kept, cap, revision: revisions };
107
+ for (const member of members) {
108
+ member.drawingsBudget = budget;
109
+ if (Array.isArray(member.drawings))
110
+ budgetsByDrawings.set(member.drawings, budget);
111
+ }
112
+ return budget;
113
+ }
114
+ // ---------------------------------------------------------------------------
115
+ // The row cap's refusal: the identity the deterministic latch compares
116
+ // ---------------------------------------------------------------------------
117
+ /** Keys the chart writes onto an overlay's engine settings without a run of its own: the legend's
118
+ * error stamp (written BECAUSE the run failed) and the style tier (paint-only, `__style__*`). */
119
+ function signatureKey(key) {
120
+ return key !== 'errorMessage' && !key.startsWith('__style__');
121
+ }
122
+ /** An overlay's engine settings as one comparable string ('' when they cannot be read). */
123
+ export function wrunSettingsSignature(settings) {
124
+ if (!isRecord(settings))
125
+ return '';
126
+ try {
127
+ return JSON.stringify(Object.keys(settings)
128
+ .filter(signatureKey)
129
+ .sort()
130
+ .map((key) => [key, settings[key]]));
131
+ }
132
+ catch {
133
+ return '';
134
+ }
135
+ }
136
+ /** A chart row's time (its first cell), NaN for anything else. */
137
+ function rowTs(row) {
138
+ const ts = Array.isArray(row) || ArrayBuffer.isView(row) ? Number(row[0]) : Number.NaN;
139
+ return Number.isFinite(ts) ? ts : Number.NaN;
140
+ }
141
+ /**
142
+ * A run's identity: the window it computes (the requested window's bounds, else the chart's loaded
143
+ * main rows, first to last) and the settings it computes with. Undefined when the window cannot be
144
+ * read (no rows), so nothing latches on it.
145
+ */
146
+ export function wrunRunIdentityOf(input) {
147
+ let first;
148
+ let last;
149
+ if (input.window) {
150
+ first = input.window.fromMs;
151
+ last = input.window.toMs;
152
+ }
153
+ else {
154
+ const rows = input.mainRows;
155
+ if (!Array.isArray(rows) || rows.length === 0)
156
+ return undefined;
157
+ first = rowTs(rows[0]);
158
+ last = rowTs(rows[rows.length - 1]);
159
+ }
160
+ if (!Number.isFinite(first) || !Number.isFinite(last))
161
+ return undefined;
162
+ return { windowFirstTs: first, windowLastTs: last, settingsSignature: wrunSettingsSignature(input.settings) };
163
+ }
164
+ const failedIdentities = new WeakMap();
165
+ /** Hand a run's rejection the identity of the run that failed (the run's settle producer). An
166
+ * identity already carried wins; a non-object rejection carries none. */
167
+ export function annotateWrunRunFailedIdentity(error, identity) {
168
+ if (identity !== undefined && error && typeof error === 'object' && !failedIdentities.has(error)) {
169
+ failedIdentities.set(error, identity);
170
+ }
171
+ return error;
172
+ }
173
+ /** The failed run's identity a rejection carries, or undefined. */
174
+ export function wrunRunFailedIdentityOf(error) {
175
+ return error && typeof error === 'object' ? failedIdentities.get(error) : undefined;
176
+ }
177
+ // ---------------------------------------------------------------------------
178
+ // Cells: the one "Cells capped" row per Indicator
179
+ // ---------------------------------------------------------------------------
180
+ /** The locale keys of the "Cells capped" row's words: the host writes the row in its own words through them (web:
181
+ * wrun-cap-notice-publish.util). Data only, the package never translates. Here they also stay in the web app's boot
182
+ * locale bundle, as when this module wrote the row's words (scripts/i18n-boot-keys.mjs harvests the dotted literals
183
+ * of the pre-candle closure). */
184
+ export const WRUN_CELLS_NOTICE_KEYS = {
185
+ retained: 'kscript.errors.RUN_RETAINED_BARS',
186
+ capped: 'kscript.errors.CELLS_CAPPED',
187
+ retainedFix: 'kscript.fix.RUN_RETAINED_BARS',
188
+ cappedFix: 'kscript.fix.CELLS_CAPPED',
189
+ };
190
+ /** Per chart, per Indicator, each budget's reader of its CURRENT summary: kept between publishes, so a
191
+ * publish one budget owes reads the other's too (the row is the Indicator's, not a budget's). */
192
+ const cellReaders = new WeakMap();
193
+ /** Per chart: the Indicators whose notice is owed. */
194
+ const pendingCells = new WeakMap();
195
+ /** Per chart, per Indicator, the run's retained range: kept apart from the cell readers, so no sum counts it. */
196
+ const retainedRanges = new WeakMap();
197
+ /** Several budgets' summaries as the one row reads them: the mounted cells summed; capped when any
198
+ * budget is, its totals and caps summed, the most bars asked for and the fewest kept. */
199
+ export function combineWrunCellsCapSummaries(summaries) {
200
+ const mounted = summaries.reduce((sum, summary) => sum + summary.mounted, 0);
201
+ const capped = summaries.flatMap((summary) => (summary.capped === null ? [] : [summary.capped]));
202
+ if (capped.length === 0)
203
+ return { mounted, capped: null };
204
+ return {
205
+ mounted,
206
+ capped: {
207
+ total: capped.reduce((sum, entry) => sum + entry.total, 0),
208
+ drawn: capped.reduce((sum, entry) => sum + entry.drawn, 0),
209
+ cap: capped.reduce((sum, entry) => sum + entry.cap, 0),
210
+ bars: Math.max(...capped.map((entry) => entry.bars)),
211
+ drawnBars: Math.min(...capped.map((entry) => entry.drawnBars)),
212
+ },
213
+ };
214
+ }
215
+ /** The Indicator's current summary over every budget that reported for it; a budget that holds
216
+ * nothing and caps nothing leaves the readers. */
217
+ function currentCellsSummary(tc, overlayId) {
218
+ const families = cellReaders.get(tc)?.get(overlayId);
219
+ const summaries = [];
220
+ for (const [family, read] of families ?? []) {
221
+ const summary = read();
222
+ if (summary.mounted === 0 && summary.capped === null)
223
+ families?.delete(family);
224
+ else
225
+ summaries.push(summary);
226
+ }
227
+ if (families?.size === 0)
228
+ cellReaders.get(tc)?.delete(overlayId);
229
+ return combineWrunCellsCapSummaries(summaries);
230
+ }
231
+ /**
232
+ * Owe the Indicator's cells notice for one budget (`family`, the heatmaps' by default): one publish
233
+ * per chart per batch of seams, reading every budget's summary when it runs (the last seam's
234
+ * numbers), never a stale snapshot. Never throws.
235
+ */
236
+ export function scheduleWrunCellsCapNotice(tc, overlayId, summary, family = 'heatmap') {
237
+ let readers = cellReaders.get(tc);
238
+ if (!readers) {
239
+ readers = new Map();
240
+ cellReaders.set(tc, readers);
241
+ }
242
+ let families = readers.get(overlayId);
243
+ if (!families) {
244
+ families = new Map();
245
+ readers.set(overlayId, families);
246
+ }
247
+ families.set(family, summary);
248
+ oweWrunCellsNotice(tc, overlayId);
249
+ }
250
+ /** The run's retained range on the Indicator's row (design 5), null when the run calculated every loaded bar. */
251
+ export function noteWrunRunRetained(tc, overlayId, retained) {
252
+ const ranges = retainedRanges.get(tc) ?? new Map();
253
+ if (retained === null) {
254
+ if (!ranges.delete(overlayId))
255
+ return;
256
+ }
257
+ else
258
+ ranges.set(overlayId, { ...retained });
259
+ retainedRanges.set(tc, ranges);
260
+ oweWrunCellsNotice(tc, overlayId);
261
+ }
262
+ /** Owe the Indicator's row one publish per chart per batch, reading every family when it runs. */
263
+ function oweWrunCellsNotice(tc, overlayId) {
264
+ let pending = pendingCells.get(tc);
265
+ const first = pending === undefined;
266
+ if (!pending) {
267
+ pending = new Set();
268
+ pendingCells.set(tc, pending);
269
+ }
270
+ pending.add(overlayId);
271
+ if (!first)
272
+ return;
273
+ // The host publishes the batch once it can write (web: wrun-cap-notice-publish.util): each notice is read
274
+ // when it is reached, and a host that cannot write drops the batch. Never throws into the seam.
275
+ const take = function* () {
276
+ const owed = pendingCells.get(tc);
277
+ pendingCells.delete(tc);
278
+ for (const id of owed ?? []) {
279
+ yield {
280
+ chart: tc,
281
+ overlayId: id,
282
+ summary: currentCellsSummary(tc, id),
283
+ retained: retainedRanges.get(tc)?.get(id),
284
+ };
285
+ }
286
+ };
287
+ const drop = () => {
288
+ pendingCells.delete(tc);
289
+ };
290
+ try {
291
+ wrunChartHostEnv().diagnostics.publishCapNotice({ take, drop });
292
+ }
293
+ catch {
294
+ drop();
295
+ }
296
+ }
@@ -0,0 +1,154 @@
1
+ /**
2
+ * WRUN-STYLE g3 (DW01 DW04 DW05 DW06 DW11 DW38): the widget looks of
3
+ * `draw.card`, `draw.feed`, `draw.meter` and `draw.ladder`, from the sheet's
4
+ * snake_case words to the engine's camelCase keys (titan `DrawingCardStyle`,
5
+ * `DrawingLadderStyle`, `DrawingCardHeadline` and the record props beside
6
+ * them). Three doors, all pure (no chart, no DOM, worker safe):
7
+ *
8
+ * - `wrunWidgetEngineProps(drawing, sheetId)`: the `style` block of a card,
9
+ * feed or meter record (DW04 chrome preset and inks, DW11 surface and type,
10
+ * DW01 rule). A card always carries an opaque surface and, without
11
+ * `state_by`, no state chrome (template QA D30, C39, B16); a feed or meter
12
+ * carries nothing when the declaration has no look word, so its record
13
+ * stays byte-identical. It also checks every other word of the declaration
14
+ * (headline fields, row colours, feed and meter words) so one door refuses
15
+ * by name.
16
+ * - `wrunLadderEngineStyle(drawing, sheetId)`: the ladder's own `style` (DW38).
17
+ * - `wrunWidgetRecordPatch(drawing, props, ctx)`: the record props beside the
18
+ * style: the headline's font fields (DW01), `layer` (DW05), `safeArea`
19
+ * (DW06), the feed's `timeFormat`, the meter's `barHeight` and
20
+ * `trackColor`, the ladder's pre-formatted `valueTexts` (DW38).
21
+ *
22
+ * Every range the kit enforces is restated here (X22) and refused by name:
23
+ * `WRUN <sheet id>: <kind> drawing '<name>' <key> ...`. Colour words ride
24
+ * through unresolved (a theme token resolves at the drawing door,
25
+ * kscript-drawings.util); font words resolve to their CSS stacks here (X14),
26
+ * since titan never sees a font word. `corner_radius` lands as the engine's
27
+ * `cornerRadius` (D1, X15).
28
+ *
29
+ * One word is translated rather than passed through (clip audit item 30):
30
+ * `controls: "none"` reaches the engine as `hover` (wrunWidgetEngineControls),
31
+ * so a widget never loses the viewer's hide control.
32
+ */
33
+ import type { WrunCardDrawing, WrunDrawing, WrunValueFormatKeys, WrunWidgetControls, WrunWidgetStyle } from '../../interfaces/wrun-runtime.interface.js';
34
+ export declare const WRUN_WIDGET_CORNER_RADIUS_MAX_PX = 32;
35
+ export declare const WRUN_WIDGET_PADDING_MAX_PX = 24;
36
+ export declare const WRUN_WIDGET_WIDTH_MIN_PX = 80;
37
+ export declare const WRUN_WIDGET_WIDTH_MAX_PX = 1200;
38
+ export declare const WRUN_WIDGET_BORDER_WIDTH_MAX_PX = 10;
39
+ export declare const WRUN_WIDGET_OFFSET_MAX_PX = 4096;
40
+ export declare const WRUN_WIDGET_FONT_SIZE_MIN_PX = 6;
41
+ export declare const WRUN_WIDGET_FONT_SIZE_MAX_PX = 64;
42
+ export declare const WRUN_WIDGET_GRADIENT_MIN_STOPS = 2;
43
+ export declare const WRUN_WIDGET_GRADIENT_MAX_STOPS = 8;
44
+ export declare const WRUN_LADDER_WIDTH_FRAC_MIN = 0.02;
45
+ export declare const WRUN_LADDER_WIDTH_FRAC_MAX = 0.5;
46
+ export declare const WRUN_METER_BAR_HEIGHT_MIN_PX = 2;
47
+ export declare const WRUN_METER_BAR_HEIGHT_MAX_PX = 40;
48
+ /** The card headline's defaults (DW01): 24 px, bold, left-aligned. */
49
+ export declare const WRUN_CARD_HEADLINE_FONT_SIZE_PX = 24;
50
+ export declare const WRUN_CARD_HEADLINE_FONT_WEIGHT = "bold";
51
+ export declare const WRUN_CARD_HEADLINE_ALIGN = "left";
52
+ /** The controls words the engine is handed: never `none` (item 30). */
53
+ export type WrunWidgetEngineControls = Exclude<WrunWidgetControls, 'none'>;
54
+ /**
55
+ * The engine's controls word for a declared one (clip audit item 30). The
56
+ * sheet's `none` still validates and still removes the glyphs at rest, but
57
+ * it reaches the engine as `hover`: the engine's own `none` never paints a
58
+ * hide glyph AND ignores the viewer's hidden override, which leaves a widget
59
+ * on the chart with no way to close it. `hover` paints nothing until the
60
+ * pointer is inside the box, then the hide control (the collapse glyph beside
61
+ * it), and honours the override. `always` and `hover` pass through untouched.
62
+ */
63
+ export declare function wrunWidgetEngineControls(word: WrunWidgetControls | undefined): WrunWidgetEngineControls | undefined;
64
+ /** The frozen colour-word message (the foundation's, 2.1). */
65
+ export declare const WRUN_COLOR_WORD_MESSAGE = "a colour must be #rrggbb, #rrggbbaa or one of theme.up, theme.down, theme.text, theme.muted, theme.bg, theme.grid, theme.accent";
66
+ /**
67
+ * DW04: what `chrome: "plain"` stands for, in the sheet's words: no state
68
+ * text, no stripe, no border, a muted title, glyphs on hover. A word declared
69
+ * beside the preset wins over it.
70
+ */
71
+ export declare const WRUN_CHROME_PLAIN_DEFAULTS: Readonly<{
72
+ readonly show_state: false;
73
+ readonly stripe: false;
74
+ readonly border_width: 0;
75
+ readonly title_text_color: "theme.muted";
76
+ readonly controls: "hover";
77
+ }>;
78
+ /**
79
+ * The surface of a card that declares none (template QA D30, C39): the
80
+ * chart's own background, opaque. The engine's default card surface is a
81
+ * 7 to 10 percent wash, so candles drew through the rows of a card anchored
82
+ * over the newest bars. A declared `background_color` or
83
+ * `background_gradient` wins; a declared `background_opacity` alone dims
84
+ * this surface.
85
+ */
86
+ export declare const WRUN_CARD_DEFAULT_BACKGROUND = "theme.bg";
87
+ /**
88
+ * What a card without `state_by` paints instead of state chrome (template QA
89
+ * B16): no state word (the engine would print "ok"), no state stripe, and a
90
+ * frame in the grid ink instead of the `ok` state teal. The stripe and the
91
+ * frame stay the author's when the card names its own ink (`accent_color` or
92
+ * `state_colors`), and every word declared beside them wins.
93
+ */
94
+ export declare const WRUN_CARD_STATELESS_DEFAULTS: Readonly<{
95
+ readonly show_state: false;
96
+ readonly stripe: false;
97
+ readonly border_color: "theme.grid";
98
+ }>;
99
+ /** A sheet number-format spec (conventions 8) without undefined keys. */
100
+ export interface WrunWidgetNumberFormat {
101
+ format: string;
102
+ decimals?: number;
103
+ signed?: boolean;
104
+ unit?: string;
105
+ }
106
+ /**
107
+ * The surface, type and chrome words of a card, feed or meter (DW04 DW11
108
+ * DW01) as the engine's `style` block. The `chrome: "plain"` preset fills
109
+ * `showState`, `stripe`, `borderWidth`, `titleColor` and `controls` unless
110
+ * the same word is declared beside it; a card's `state_colors` and
111
+ * `accent_color` are exclusive; `controls: "none"` lands as `hover`
112
+ * (wrunWidgetEngineControls, item 30). A card always carries a surface
113
+ * (WRUN_CARD_DEFAULT_BACKGROUND when it declares none) and, without
114
+ * `state_by`, no state chrome (WRUN_CARD_STATELESS_DEFAULTS). A feed or meter
115
+ * gets `{}` (no `style` key) when no look word is declared, so its record is
116
+ * what it always was. Every other word of the declaration is checked here
117
+ * too, so one door refuses by name.
118
+ */
119
+ export declare function wrunWidgetEngineProps(drawing: WrunDrawing, sheetId: string): {
120
+ style?: Record<string, unknown>;
121
+ };
122
+ /**
123
+ * The ladder's look (DW38) as the engine's `style` block: its share of the
124
+ * pane, the inset from the docked side (`offset[0]`; y must be 0), the bar
125
+ * alpha and inks, the value text's font and the divider ink. Undefined when
126
+ * no look word is declared. The value-text format words are checked here
127
+ * too (the record patch prints them).
128
+ */
129
+ export declare function wrunLadderEngineStyle(drawing: WrunDrawing, sheetId: string): Record<string, unknown> | undefined;
130
+ /**
131
+ * The record props beside a widget's style: a card's headline font fields
132
+ * (DW01), `layer: 'top'` for `above_drawings` (DW05), `safeArea` (DW06), a
133
+ * feed's `timeFormat`, a meter's `barHeight` and `trackColor`, a ladder's
134
+ * `valueTexts` (DW38). `props` is the record the selection produced; the
135
+ * returned patch is assigned over it by the run-result adapter. `ctx.offchart`
136
+ * is the overlay side the record lands on (the adapter routes the pane by
137
+ * it; no patch key depends on it today); `ctx.sheetId` names the sheet in a
138
+ * refusal (the style doors above have refused the same words already).
139
+ */
140
+ export declare function wrunWidgetRecordPatch(drawing: WrunDrawing, props: Record<string, unknown>, ctx: {
141
+ priceDigits?: number;
142
+ offchart: boolean;
143
+ sheetId?: string;
144
+ }): Record<string, unknown>;
145
+ /** The number format a ladder declares for its value texts (DW38), for
146
+ * callers that print a ladder value themselves; undefined when none. */
147
+ export declare function wrunLadderValueFormat(drawing: Extract<WrunDrawing, {
148
+ kind: 'ladder';
149
+ }> & WrunValueFormatKeys, sheetId: string): WrunWidgetNumberFormat | undefined;
150
+ /** The widget style words a card, feed or meter declaration may carry (the
151
+ * g3 surface + chrome keys), for callers that need the list. */
152
+ export declare const WRUN_WIDGET_STYLE_KEYS: ReadonlyArray<keyof WrunWidgetStyle>;
153
+ /** The card-only words (DW01, DW04) beside the shared style keys. */
154
+ export declare const WRUN_CARD_STYLE_KEYS: ReadonlyArray<keyof WrunCardDrawing>;