@orangecharts/wrun-chart-host 0.15.0 → 0.16.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 (175) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/economic.constants.d.ts +2 -0
  3. package/dist/constants/economic.constants.js +2 -0
  4. package/dist/constants/feature-flags.constants.d.ts +10 -0
  5. package/dist/constants/feature-flags.constants.js +52 -4
  6. package/dist/constants/feature-limits.constants.d.ts +72 -4
  7. package/dist/constants/feature-limits.constants.js +98 -20
  8. package/dist/constants/interval.constants.js +5 -0
  9. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +12 -0
  10. package/dist/constants/kscript-data-interval-restrictions.constants.js +14 -0
  11. package/dist/constants/typed-width-fold.leaf.d.ts +50 -0
  12. package/dist/constants/typed-width-fold.leaf.js +99 -0
  13. package/dist/constants/typed-width-source.leaf.d.ts +24 -0
  14. package/dist/constants/typed-width-source.leaf.js +126 -0
  15. package/dist/constants/typed-width.leaf.d.ts +57 -0
  16. package/dist/constants/typed-width.leaf.js +78 -0
  17. package/dist/host-env.d.ts +10 -0
  18. package/dist/host-env.js +7 -0
  19. package/dist/host-ports.types.d.ts +11 -0
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.js +3 -0
  22. package/dist/interfaces/kscript-diagnostics.interface.d.ts +28 -0
  23. package/dist/interfaces/wrun-runtime.interface.d.ts +63 -3
  24. package/dist/interfaces/wrun-runtime.interface.js +11 -0
  25. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +13 -0
  26. package/dist/kscript-data/controls/live-trades-merge.util.js +16 -1
  27. package/dist/market-data/billing.interface.d.ts +12 -45
  28. package/dist/market-data/billing.interface.js +2 -2
  29. package/dist/replay/replayLadder.js +7 -4
  30. package/dist/settings-templates/footprint-rows.d.ts +6 -0
  31. package/dist/settings-templates/footprint-rows.js +6 -0
  32. package/dist/settings-templates/frvp-fields.js +14 -0
  33. package/dist/settings-templates/indicator-fields.js +31 -0
  34. package/dist/settings-templates/tool-tables.generated.js +19 -1
  35. package/dist/utility/chart/__fixtures__/live-bucket-regular-golden.json +1706 -0
  36. package/dist/utility/chart/cache-alignment.util.d.ts +42 -0
  37. package/dist/utility/chart/cache-alignment.util.js +88 -18
  38. package/dist/utility/chart/calendar-interval.util.d.ts +83 -1
  39. package/dist/utility/chart/calendar-interval.util.js +152 -4
  40. package/dist/utility/chart/candle-bar-end.util.d.ts +11 -4
  41. package/dist/utility/chart/candle-bar-end.util.js +17 -6
  42. package/dist/utility/chart/chart-time-domain.util.d.ts +3 -0
  43. package/dist/utility/chart/chart-time-domain.util.js +13 -4
  44. package/dist/utility/chart/feed-interval.util.d.ts +4 -2
  45. package/dist/utility/chart/feed-interval.util.js +5 -2
  46. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +3 -1
  47. package/dist/utility/chart/fetch-dedupe-policy.util.js +19 -1
  48. package/dist/utility/chart/footprint-display-mode.util.d.ts +2 -0
  49. package/dist/utility/chart/footprint-display-mode.util.js +5 -0
  50. package/dist/utility/chart/governed-lanes-gate.util.d.ts +46 -0
  51. package/dist/utility/chart/governed-lanes-gate.util.js +71 -0
  52. package/dist/utility/chart/governed-lanes-reader-seat.d.ts +14 -0
  53. package/dist/utility/chart/governed-lanes-reader-seat.js +14 -0
  54. package/dist/utility/chart/history-wall.util.d.ts +13 -2
  55. package/dist/utility/chart/history-wall.util.js +11 -4
  56. package/dist/utility/chart/interval-ladder.util.d.ts +5 -2
  57. package/dist/utility/chart/interval-ladder.util.js +44 -4
  58. package/dist/utility/chart/interval-registry.util.d.ts +22 -1
  59. package/dist/utility/chart/interval-registry.util.js +50 -2
  60. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +32 -4
  61. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +22 -5
  62. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +10 -0
  63. package/dist/utility/chart/kscript-drawing-safe-area.util.js +30 -3
  64. package/dist/utility/chart/kscript-legend-entries.util.d.ts +21 -4
  65. package/dist/utility/chart/kscript-legend-entries.util.js +27 -5
  66. package/dist/utility/chart/kscript-main-grid-stages.util.js +74 -24
  67. package/dist/utility/chart/kscript-row-name.leaf.d.ts +13 -0
  68. package/dist/utility/chart/kscript-row-name.leaf.js +18 -0
  69. package/dist/utility/chart/kscript-venue-policy.util.d.ts +61 -26
  70. package/dist/utility/chart/kscript-venue-policy.util.js +138 -37
  71. package/dist/utility/chart/live-bucket.util.d.ts +29 -4
  72. package/dist/utility/chart/live-bucket.util.js +45 -12
  73. package/dist/utility/chart/market-session.util.d.ts +62 -10
  74. package/dist/utility/chart/market-session.util.js +93 -13
  75. package/dist/utility/chart/marketKind.util.d.ts +1 -7
  76. package/dist/utility/chart/marketKind.util.js +6 -8
  77. package/dist/utility/chart/mixed-mode.util.d.ts +17 -0
  78. package/dist/utility/chart/om-target.util.js +6 -4
  79. package/dist/utility/chart/price-precision.util.d.ts +20 -6
  80. package/dist/utility/chart/price-precision.util.js +34 -7
  81. package/dist/utility/chart/profile-frame-window.util.d.ts +15 -0
  82. package/dist/utility/chart/profile-frame-window.util.js +12 -0
  83. package/dist/utility/chart/rth-session.util.d.ts +3 -1
  84. package/dist/utility/chart/rth-session.util.js +3 -1
  85. package/dist/utility/chart/script-source-session.util.d.ts +43 -0
  86. package/dist/utility/chart/script-source-session.util.js +61 -0
  87. package/dist/utility/chart/typed-width-grid.util.d.ts +23 -0
  88. package/dist/utility/chart/typed-width-grid.util.js +203 -0
  89. package/dist/utility/common/transformations.util.d.ts +6 -0
  90. package/dist/utility/common/transformations.util.js +28 -4
  91. package/dist/utility/number-format.util.d.ts +14 -1
  92. package/dist/utility/number-format.util.js +22 -4
  93. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +24 -1
  94. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +113 -0
  95. package/dist/utility/v2/v2-enums.leaf.js +3 -0
  96. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +9 -3
  97. package/dist/utility/wrun/wrun-batched-marks.util.js +65 -17
  98. package/dist/utility/wrun/wrun-canvases.util.d.ts +4 -2
  99. package/dist/utility/wrun/wrun-canvases.util.js +7 -12
  100. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +5 -0
  101. package/dist/utility/wrun/wrun-cap-notice.util.js +23 -0
  102. package/dist/utility/wrun/wrun-card-style.util.d.ts +1 -1
  103. package/dist/utility/wrun/wrun-card-style.util.js +2 -2
  104. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +8 -0
  105. package/dist/utility/wrun/wrun-chart-market-facts.util.js +13 -1
  106. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +10 -0
  107. package/dist/utility/wrun/wrun-child-overlay-id.util.js +24 -0
  108. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.d.ts +72 -0
  109. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.js +151 -0
  110. package/dist/utility/wrun/wrun-color-facts.util.d.ts +3 -3
  111. package/dist/utility/wrun/wrun-color-facts.util.js +8 -5
  112. package/dist/utility/wrun/wrun-colour-tone.lazy.d.ts +20 -0
  113. package/dist/utility/wrun/wrun-colour-tone.lazy.js +23 -0
  114. package/dist/utility/wrun/wrun-colour-tone.util.d.ts +14 -0
  115. package/dist/utility/wrun/wrun-colour-tone.util.js +119 -0
  116. package/dist/utility/wrun/wrun-dark-pool.util.d.ts +3 -2
  117. package/dist/utility/wrun/wrun-dark-pool.util.js +5 -4
  118. package/dist/utility/wrun/wrun-frames.d.ts +1 -1
  119. package/dist/utility/wrun/wrun-frames.js +2 -2
  120. package/dist/utility/wrun/wrun-handles.util.d.ts +1 -1
  121. package/dist/utility/wrun/wrun-handles.util.js +1 -1
  122. package/dist/utility/wrun/wrun-host.service.d.ts +32 -2
  123. package/dist/utility/wrun/wrun-host.service.js +44 -2
  124. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +20 -0
  125. package/dist/utility/wrun/wrun-hosted-wire-caps.js +85 -2
  126. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +37 -0
  127. package/dist/utility/wrun/wrun-hosted-wire.util.js +54 -0
  128. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +1 -0
  129. package/dist/utility/wrun/wrun-hud-looks.util.js +6 -11
  130. package/dist/utility/wrun/wrun-integration-route.util.d.ts +24 -0
  131. package/dist/utility/wrun/wrun-integration-route.util.js +19 -0
  132. package/dist/utility/wrun/wrun-live-intake.util.js +17 -1
  133. package/dist/utility/wrun/wrun-live-patch.util.d.ts +6 -1
  134. package/dist/utility/wrun/wrun-live-patch.util.js +10 -4
  135. package/dist/utility/wrun/wrun-live-tick.util.js +59 -4
  136. package/dist/utility/wrun/wrun-overlay-drivers.util.js +3 -0
  137. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +15 -0
  138. package/dist/utility/wrun/wrun-overlay-run.util.js +274 -47
  139. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +1 -1
  140. package/dist/utility/wrun/wrun-panel-mount.util.js +42 -13
  141. package/dist/utility/wrun/wrun-pin-venues.util.js +5 -1
  142. package/dist/utility/wrun/wrun-refusal.util.d.ts +4 -0
  143. package/dist/utility/wrun/wrun-refusal.util.js +102 -13
  144. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  145. package/dist/utility/wrun/wrun-registry-errors.util.js +5 -3
  146. package/dist/utility/wrun/wrun-row-source-factory.js +17 -1
  147. package/dist/utility/wrun/wrun-row-source.d.ts +8 -1
  148. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +1 -1
  149. package/dist/utility/wrun/wrun-sandbox-row-source.js +9 -0
  150. package/dist/utility/wrun/wrun-setting-words.util.d.ts +12 -5
  151. package/dist/utility/wrun/wrun-setting-words.util.js +25 -8
  152. package/dist/utility/wrun/wrun-socket-row-source.d.ts +26 -1
  153. package/dist/utility/wrun/wrun-socket-row-source.js +125 -12
  154. package/dist/utility/wrun/wrun-source-rows.util.d.ts +3 -3
  155. package/dist/utility/wrun/wrun-source-rows.util.js +8 -7
  156. package/dist/utility/wrun/wrun-style-words.util.d.ts +31 -9
  157. package/dist/utility/wrun/wrun-style-words.util.js +46 -15
  158. package/dist/utility/wrun/wrun-trades-lane.util.js +2 -1
  159. package/dist/utility/wrun/wrun-trap-replay.util.d.ts +42 -0
  160. package/dist/utility/wrun/wrun-trap-replay.util.js +63 -0
  161. package/dist/utility/wrun/wrun-volume-profile.util.js +6 -5
  162. package/dist/utility/wrun-display-name.util.d.ts +10 -0
  163. package/dist/utility/wrun-display-name.util.js +21 -0
  164. package/dist/utils/replay/replay-buffer-math.d.ts +2 -0
  165. package/dist/utils/replay/replay-buffer-math.js +2 -0
  166. package/dist/workers/constants/socket-slots.d.ts +1 -1
  167. package/dist/workers/utils/time.worker.util.js +2 -2
  168. package/dist/workers/utils/volume-profile.worker.util.d.ts +9 -0
  169. package/dist/workers/utils/volume-profile.worker.util.js +20 -0
  170. package/dist/workers/wrun/wrun-abi-host.d.ts +3 -0
  171. package/dist/workers/wrun/wrun-abi-host.js +82 -5
  172. package/dist/workers/wrun/wrun-engine-handler.js +53 -4
  173. package/dist/workers/wrun/wrun-trap-frames.leaf.d.ts +28 -0
  174. package/dist/workers/wrun/wrun-trap-frames.leaf.js +108 -0
  175. package/package.json +11 -11
@@ -239,6 +239,8 @@ export declare class SocketWrunRowSource implements WrunRowSource {
239
239
  /** The served tier of the OPRA rows the session holds (contract opra-server-lanes C4: the newest receipt that named a
240
240
  * tier since the session opened), the one every merge is held to (`servedTierMoved`). */
241
241
  private retainedTier;
242
+ /** The governed planes' receipts the session's rows were served at (`governedTierMoved`), reset with the session. */
243
+ private retainedGoverned;
242
244
  /** A served-tier move no listener took yet (`dropSessionAtServedTier`): the next subscriber is told first. */
243
245
  private servedTierMoveOwed;
244
246
  constructor(deps?: WrunSocketRowSourceDeps);
@@ -247,7 +249,19 @@ export declare class SocketWrunRowSource implements WrunRowSource {
247
249
  /** The session's run-level keys as a batch carries them (copies): the newest strategy output and diagnostics a
248
250
  * result or a live frame carried, whichever merged last, the served legs' warning rows after the diagnostics, the
249
251
  * newest result's OPRA word and the receipt of the newest OPRA rows (a result's or a marked live frame's). */
250
- get sessionRunLevel(): Pick<WrunRowBatch, 'strategy' | 'diagnostics' | 'opra' | 'opraServed'>;
252
+ get sessionRunLevel(): Pick<WrunRowBatch, 'strategy' | 'diagnostics' | 'opra' | 'opraServed' | 'governed'>;
253
+ /** The overlay's sticky governed-plane mark (`governedMarks`), when its run named one. */
254
+ private governedMark;
255
+ /** Join a reply's governed-plane mark into the overlay's sticky one (`wrunGovernedMarkOf`, fail closed). */
256
+ private noteGoverned;
257
+ /** Join a mark read elsewhere (a failed ask's error frame, `wrunFailureGovernedOf`) into the overlay's sticky one. */
258
+ private noteGovernedMark;
259
+ /**
260
+ * A batch's run-level fields with the overlay's sticky governed-plane mark (`governed`), when its run named one. A
261
+ * run that read CME marks every diagnostic row the cloud answered beside its rows (`RuntimeDiagnostic.cme`: its
262
+ * execution errors can carry what the run computed), so every console export strips it, as the OPRA rows' mark.
263
+ */
264
+ private withGoverned;
251
265
  /** The session's cell rows in the shapes the price canvases read (the store's conversion), with the
252
266
  * chart's own candles. The cells memo keeps each entry's lane rows between reads: a read after a merge
253
267
  * converts only the rows the merge replaced (`extendWrunCellLane`), and a read with nothing merged since,
@@ -302,6 +316,17 @@ export declare class SocketWrunRowSource implements WrunRowSource {
302
316
  * session whose rows never named one.
303
317
  */
304
318
  private servedTierMoved;
319
+ /**
320
+ * The governed planes' twin of the OPRA rule (2026-11-11): an answer whose `wrunGoverned` receipt for a plane (CME,
321
+ * the US stocks tape) names another tier or delay than the receipt the session's rows were served at moves the
322
+ * session's served tier, so no real-time row stands beside a delayed one. Compared per plane the answer names, against
323
+ * the receipt the session retained for that plane (`retainedGoverned`); a plane either side does not name moves
324
+ * nothing. A receipt the chart could not read (no tier word or no delay) agrees with no readable one (fail closed); two
325
+ * equally unreadable receipts agree, so a server that never sends a readable receipt does not reseed on every frame.
326
+ */
327
+ private governedTierMoved;
328
+ /** A merged answer's governed receipts join the session's (each plane it names, its newest receipt). */
329
+ private retainGoverned;
305
330
  /**
306
331
  * The served tier moved under the session: nothing it holds may stand beside rows served at the new tier (a
307
332
  * real-time prefix under a delayed receipt, or the reverse). Its rows, coverage, owed window, cells and run-level
@@ -99,7 +99,8 @@ import { clearIndicatorInflight, scheduleIndicatorInflightFetch, } from '../char
99
99
  import { readWrunWireRef } from '../chart/wrun-wire-ref.util.js';
100
100
  import { wrunSocketPayloadSettings } from './wrun-cloud-record.util.js';
101
101
  import { wrunErrorFrameCodeOf, wrunForeignSupersedeOf, wrunFrameRefusalOf, wrunServerAnswerOfText, } from './wrun-hosted-wire-caps.js';
102
- import { readWrunHostedRunLevel, readWrunHostedWire, } from './wrun-hosted-wire.util.js';
102
+ import { readWrunHostedRunLevel, readWrunHostedWire, wrunGovernedMarkOf, } from './wrun-hosted-wire.util.js';
103
+ import { markWrunFailureGoverned, takeWrunFailureGoverned } from './wrun-cloud-cme-stamp.util.js';
103
104
  import { WRUN_LANE_WARMUP_LOOKBACK_CAP, wrunLaneWarmupBars } from './wrun-lane-warmup.util.js';
104
105
  import { wrunClampedLegDiagnostics } from './wrun-leg-fetch.util.js';
105
106
  import { wrunParamValuesFromSettings } from './wrun-param-values.util.js';
@@ -348,6 +349,37 @@ export function mergeWrunSocketSpans(spans, intervalMs) {
348
349
  export function wrunSocketPagePolicy(historical) {
349
350
  return resolveFetchDedupePolicy(historical ? { lane: 'indicator', isReplayBuffer: true } : { lane: 'indicator' });
350
351
  }
352
+ /**
353
+ * The governed-plane mark each overlay's cloud run carried (`<chartIndex>:<indicatorId>`, the reply's
354
+ * `output.wrunGoverned`): sticky for the run, so once any result or live frame of the overlay named a plane, every
355
+ * later batch and frame of it carries that plane, across paging, re-range, a settings change and a reconnect (a new
356
+ * create, or a new source for the same overlay). Never shed: withholding is always safe (the AI boundary never opens
357
+ * on CME), and the overlay's CME stamp is sticky for the mount too (wrun-cloud-cme-stamp.util).
358
+ */
359
+ const governedMarks = new Map();
360
+ /** The governed planes a receipt is compared on (`governedTierMoved`). */
361
+ const WRUN_SOCKET_GOVERNED_PLANES = ['cme', 'stocks'];
362
+ /** Two marks joined: every plane either names, the newer's receipt where both name one. Undefined while neither
363
+ * names any. */
364
+ function joinWrunGovernedMarks(held, next) {
365
+ if (next === undefined)
366
+ return held;
367
+ const joined = { ...(held ?? {}) };
368
+ for (const [plane, receipt] of Object.entries(next)) {
369
+ if (receipt !== undefined)
370
+ joined[plane] = { ...receipt };
371
+ }
372
+ return Object.keys(joined).length > 0 ? joined : undefined;
373
+ }
374
+ /** A copy of a mark (a batch never shares the source's). */
375
+ function copyWrunGovernedMark(mark) {
376
+ const copy = {};
377
+ for (const [plane, receipt] of Object.entries(mark)) {
378
+ if (receipt !== undefined)
379
+ copy[plane] = { ...receipt };
380
+ }
381
+ return copy;
382
+ }
351
383
  /** The sources following each overlay's cloud session (`<chartIndex>:<indicatorId>`): a facts-needed note
352
384
  * reaches the ask they have waiting. */
353
385
  const factsFollowers = new Map();
@@ -682,6 +714,8 @@ export class SocketWrunRowSource {
682
714
  /** The served tier of the OPRA rows the session holds (contract opra-server-lanes C4: the newest receipt that named a
683
715
  * tier since the session opened), the one every merge is held to (`servedTierMoved`). */
684
716
  retainedTier;
717
+ /** The governed planes' receipts the session's rows were served at (`governedTierMoved`), reset with the session. */
718
+ retainedGoverned;
685
719
  /** A served-tier move no listener took yet (`dropSessionAtServedTier`): the next subscriber is told first. */
686
720
  servedTierMoveOwed;
687
721
  constructor(deps = {}) {
@@ -710,7 +744,38 @@ export class SocketWrunRowSource {
710
744
  * result or a live frame carried, whichever merged last, the served legs' warning rows after the diagnostics, the
711
745
  * newest result's OPRA word and the receipt of the newest OPRA rows (a result's or a marked live frame's). */
712
746
  get sessionRunLevel() {
713
- return runLevelFields(this.runLevel);
747
+ return this.withGoverned(runLevelFields(this.runLevel));
748
+ }
749
+ /** The overlay's sticky governed-plane mark (`governedMarks`), when its run named one. */
750
+ governedMark() {
751
+ return this.identity !== undefined ? governedMarks.get(overlayKeyOf(this.identity)) : undefined;
752
+ }
753
+ /** Join a reply's governed-plane mark into the overlay's sticky one (`wrunGovernedMarkOf`, fail closed). */
754
+ noteGoverned(output) {
755
+ this.noteGovernedMark(wrunGovernedMarkOf(output));
756
+ }
757
+ /** Join a mark read elsewhere (a failed ask's error frame, `wrunFailureGovernedOf`) into the overlay's sticky one. */
758
+ noteGovernedMark(mark) {
759
+ if (this.identity === undefined || mark === undefined)
760
+ return;
761
+ const key = overlayKeyOf(this.identity);
762
+ const joined = joinWrunGovernedMarks(governedMarks.get(key), mark);
763
+ if (joined !== undefined)
764
+ governedMarks.set(key, joined);
765
+ }
766
+ /**
767
+ * A batch's run-level fields with the overlay's sticky governed-plane mark (`governed`), when its run named one. A
768
+ * run that read CME marks every diagnostic row the cloud answered beside its rows (`RuntimeDiagnostic.cme`: its
769
+ * execution errors can carry what the run computed), so every console export strips it, as the OPRA rows' mark.
770
+ */
771
+ withGoverned(fields) {
772
+ const mark = this.governedMark();
773
+ if (mark === undefined)
774
+ return fields;
775
+ const diagnostics = mark.cme !== undefined && fields.diagnostics !== undefined
776
+ ? { diagnostics: fields.diagnostics.map((row) => ({ ...row, cme: true })) }
777
+ : {};
778
+ return { ...fields, ...diagnostics, governed: copyWrunGovernedMark(mark) };
714
779
  }
715
780
  /** The session's cell rows in the shapes the price canvases read (the store's conversion), with the
716
781
  * chart's own candles. The cells memo keeps each entry's lane rows between reads: a read after a merge
@@ -750,6 +815,7 @@ export class SocketWrunRowSource {
750
815
  this.runLevel = {};
751
816
  this.lossesAtOpen = undefined;
752
817
  this.retainedTier = undefined;
818
+ this.retainedGoverned = undefined;
753
819
  this.servedTierMoveOwed = undefined;
754
820
  this.followLive();
755
821
  return this.withLoading(async () => {
@@ -882,6 +948,7 @@ export class SocketWrunRowSource {
882
948
  this.runLevel = {};
883
949
  this.flight = undefined;
884
950
  this.retainedTier = undefined;
951
+ this.retainedGoverned = undefined;
885
952
  this.servedTierMoveOwed = undefined;
886
953
  }
887
954
  /**
@@ -898,7 +965,11 @@ export class SocketWrunRowSource {
898
965
  enqueue(work) {
899
966
  const run = this.queue.then(work, work);
900
967
  this.queue = run.then(() => undefined, () => undefined);
901
- return run;
968
+ // Every failure the source rejects with carries the overlay's sticky governed-plane mark (a failed run that read
969
+ // CME surfaces marked: the run pass reads it back, wrun-cloud-cme-stamp.util `wrunFailureGovernedOf`).
970
+ return run.catch((error) => {
971
+ throw markWrunFailureGoverned(error, this.governedMark());
972
+ });
902
973
  }
903
974
  nextGeneration() {
904
975
  this.generationAbort.abort(new WrunSocketRowSourceStopped('superseded'));
@@ -1031,6 +1102,10 @@ export class SocketWrunRowSource {
1031
1102
  return { output };
1032
1103
  }
1033
1104
  catch (error) {
1105
+ // The error frame's governed-plane mark (its relayed `details.wrunGoverned`, the frozen contract) joins the
1106
+ // overlay's sticky one before anything else of the failure is read, as a reply's does (fail closed): a refusal
1107
+ // batch and every later failure or batch of the overlay carry it.
1108
+ this.noteGovernedMark(takeWrunFailureGoverned(error));
1034
1109
  // A superseded or torn-down ask reports the stop, whatever the transport said after it.
1035
1110
  this.assertCurrent(generation);
1036
1111
  // The cloud refused this ask for fact lists its payload lacked (the worker named them while it waited): once
@@ -1090,6 +1165,9 @@ export class SocketWrunRowSource {
1090
1165
  throw new WrunSocketRowSourceStopped('superseded');
1091
1166
  if (output === undefined || output === null)
1092
1167
  throw new WrunRowSourceTransientError('no-reply');
1168
+ // The run's governed-plane mark joins the overlay's sticky one before anything else of the reply is read: a
1169
+ // reply the source refuses or cannot read still marks the run (fail closed).
1170
+ this.noteGoverned(output);
1093
1171
  const read = await readWrunHostedWire(output);
1094
1172
  this.assertCurrent(generation);
1095
1173
  if (read.kind === 'absent')
@@ -1100,7 +1178,7 @@ export class SocketWrunRowSource {
1100
1178
  this.assertCurrent(generation);
1101
1179
  // A page (or the paging after a patch) the cloud served at another tier than the rows the session holds: none
1102
1180
  // of them may stand beside it, so the session is dropped and the overlay reseeds; the ask settles superseded.
1103
- if (freshSheet === undefined && this.servedTierMoved(level)) {
1181
+ if (freshSheet === undefined && this.servedTierMoved(level, output)) {
1104
1182
  this.dropSessionAtServedTier(read.wire.window);
1105
1183
  throw new WrunSocketRowSourceStopped('superseded');
1106
1184
  }
@@ -1141,9 +1219,12 @@ export class SocketWrunRowSource {
1141
1219
  ...(level.opra !== undefined ? { opra: level.opra } : {}),
1142
1220
  ...(opraServed !== undefined ? { opraServed } : {}),
1143
1221
  };
1144
- if (freshSheet !== undefined)
1222
+ if (freshSheet !== undefined) {
1145
1223
  this.retainedTier = undefined;
1224
+ this.retainedGoverned = undefined;
1225
+ }
1146
1226
  this.retainTier(level);
1227
+ this.retainGoverned(output);
1147
1228
  });
1148
1229
  }
1149
1230
  // ── The served tier ──────────────────────────────────────────────────────────────────────────
@@ -1158,9 +1239,34 @@ export class SocketWrunRowSource {
1158
1239
  * a downgrade or an upgrade). An answer that names no tier moves nothing (its rows read no OPRA yet), nor does a
1159
1240
  * session whose rows never named one.
1160
1241
  */
1161
- servedTierMoved(level) {
1242
+ servedTierMoved(level, output) {
1162
1243
  const tier = level.opra === true ? level.opraServed?.tier : undefined;
1163
- return tier !== undefined && this.retainedTier !== undefined && tier !== this.retainedTier;
1244
+ if (tier !== undefined && this.retainedTier !== undefined && tier !== this.retainedTier)
1245
+ return true;
1246
+ return output !== undefined && this.governedTierMoved(output);
1247
+ }
1248
+ /**
1249
+ * The governed planes' twin of the OPRA rule (2026-11-11): an answer whose `wrunGoverned` receipt for a plane (CME,
1250
+ * the US stocks tape) names another tier or delay than the receipt the session's rows were served at moves the
1251
+ * session's served tier, so no real-time row stands beside a delayed one. Compared per plane the answer names, against
1252
+ * the receipt the session retained for that plane (`retainedGoverned`); a plane either side does not name moves
1253
+ * nothing. A receipt the chart could not read (no tier word or no delay) agrees with no readable one (fail closed); two
1254
+ * equally unreadable receipts agree, so a server that never sends a readable receipt does not reseed on every frame.
1255
+ */
1256
+ governedTierMoved(output) {
1257
+ const next = wrunGovernedMarkOf(output);
1258
+ const held = this.retainedGoverned;
1259
+ if (next === undefined || held === undefined)
1260
+ return false;
1261
+ return WRUN_SOCKET_GOVERNED_PLANES.some((plane) => {
1262
+ const was = held[plane];
1263
+ const now = next[plane];
1264
+ return was !== undefined && now !== undefined && (was.tier !== now.tier || was.delaySeconds !== now.delaySeconds);
1265
+ });
1266
+ }
1267
+ /** A merged answer's governed receipts join the session's (each plane it names, its newest receipt). */
1268
+ retainGoverned(output) {
1269
+ this.retainedGoverned = joinWrunGovernedMarks(this.retainedGoverned, wrunGovernedMarkOf(output));
1164
1270
  }
1165
1271
  /**
1166
1272
  * The served tier moved under the session: nothing it holds may stand beside rows served at the new tier (a
@@ -1178,6 +1284,7 @@ export class SocketWrunRowSource {
1178
1284
  this.owed = undefined;
1179
1285
  this.cells = undefined;
1180
1286
  this.retainedTier = undefined;
1287
+ this.retainedGoverned = undefined;
1181
1288
  const frame = {
1182
1289
  window: { ...window },
1183
1290
  asOfMs: Number.NaN,
@@ -1349,7 +1456,7 @@ export class SocketWrunRowSource {
1349
1456
  frames: undefined,
1350
1457
  handles: undefined,
1351
1458
  refusals: [],
1352
- ...runLevelFields(this.runLevel),
1459
+ ...this.withGoverned(runLevelFields(this.runLevel)),
1353
1460
  };
1354
1461
  }
1355
1462
  const start = firstAtOrAfter(session.rows, window.fromMs);
@@ -1367,7 +1474,7 @@ export class SocketWrunRowSource {
1367
1474
  handles: rebasedHandles(session.handles, start),
1368
1475
  refusals: session.refusals.map((refusal) => ({ ...refusal })),
1369
1476
  ...(withSheet ? { sheet: session.sheet } : {}),
1370
- ...runLevelFields(this.runLevel),
1477
+ ...this.withGoverned(runLevelFields(this.runLevel)),
1371
1478
  ...(this.lossesAtOpen !== undefined ? { sessionLosses: this.lossesAtOpen } : {}),
1372
1479
  };
1373
1480
  }
@@ -1397,7 +1504,11 @@ export class SocketWrunRowSource {
1397
1504
  return;
1398
1505
  const generation = this.generation;
1399
1506
  void this.serial(async () => {
1400
- if (this.closed || generation !== this.generation)
1507
+ if (this.closed)
1508
+ return;
1509
+ // A frame's governed-plane mark joins the overlay's sticky one whatever becomes of the frame (fail closed).
1510
+ this.noteGoverned(output);
1511
+ if (generation !== this.generation)
1401
1512
  return;
1402
1513
  const read = await readWrunHostedWire(output);
1403
1514
  // An unreadable frame is skipped: the next result repaints.
@@ -1412,7 +1523,7 @@ export class SocketWrunRowSource {
1412
1523
  return;
1413
1524
  // A frame served at another tier than the rows the session holds never extends them: the session is dropped
1414
1525
  // and the overlay reseeds (`dropSessionAtServedTier`).
1415
- if (this.servedTierMoved(level)) {
1526
+ if (this.servedTierMoved(level, output)) {
1416
1527
  this.dropSessionAtServedTier(read.wire.window);
1417
1528
  return;
1418
1529
  }
@@ -1434,6 +1545,7 @@ export class SocketWrunRowSource {
1434
1545
  this.runLevel = { ...rest, ...(level.opraServed !== undefined ? { opraServed: level.opraServed } : {}) };
1435
1546
  }
1436
1547
  this.retainTier(level);
1548
+ this.retainGoverned(output);
1437
1549
  this.emitFrame(read.wire, merge, level);
1438
1550
  }).catch((error) => {
1439
1551
  console.warn('[wrun] socket row source live frame skipped:', error);
@@ -1457,7 +1569,7 @@ export class SocketWrunRowSource {
1457
1569
  frames: merge.acceptedSnapshots && wire.frames !== undefined ? session.frames : undefined,
1458
1570
  handles: rebasedHandles(session.handles, start),
1459
1571
  refusals: session.refusals.map((refusal) => ({ ...refusal })),
1460
- ...runLevelFields({ ...level, servedLegs: this.runLevel.servedLegs }),
1572
+ ...this.withGoverned(runLevelFields({ ...level, servedLegs: this.runLevel.servedLegs })),
1461
1573
  };
1462
1574
  this.deliver(frame);
1463
1575
  }
@@ -1796,6 +1908,7 @@ export function onWrunSocketRowSourceTestReset(reset) {
1796
1908
  export function __resetWrunSocketRowSourceForTests() {
1797
1909
  factsFollowers.clear();
1798
1910
  factsAskedAgain.clear();
1911
+ governedMarks.clear();
1799
1912
  for (const reset of transportStateResets)
1800
1913
  reset();
1801
1914
  }
@@ -658,9 +658,9 @@ export declare const WRUN_ODDS_EXCHANGE = "POLYMARKET";
658
658
  * interval. */
659
659
  export declare function wrunIntrabarLegFetchKey(intervalKey: string, market?: WrunPinnedMarket): string;
660
660
  export { wrunPinnedIntervalOf, type WrunPinnedInterval } from './wrun-pinned-interval.util.js';
661
- /** The chart's spelling of an interval span (an `Intervals.map_unit` key),
662
- * else the span in ms with a unit (a spelling `dataFetch` ignores, so a
663
- * grid leg's fetch falls back to the chart's own interval either way). */
661
+ /** The chart's spelling of an interval span (an `Intervals.map_unit` key): the resolver's own label first (28 days
662
+ * is 4w, never the legacy '1mm' row), else the first table row of that length, else the span in ms with a unit (a
663
+ * spelling `dataFetch` ignores, so a grid leg's fetch falls back to the chart's own interval either way). */
664
664
  export declare function wrunChartIntervalKeyOf(intervalMs: number): string;
665
665
  /** A pinned leg's fetch identity: the market (the chart's own when
666
666
  * unpinned, so the fetch payload's placeholders) and the leg interval, the
@@ -356,7 +356,8 @@ import { wrunChartHostEnv } from '../../host-env.js';
356
356
  import { packedOhlcvRowViews, unpackOhlcvRows, } from '../../instances/script-engine-worker-ohlcv-transfer.js';
357
357
  import { FeatureFlag } from '../../constants/feature-flags.constants.js';
358
358
  import { Intervals } from '../../constants/interval.constants.js';
359
- import { barEndMs, calendarBarStartMs, calendarLongestBarMs, calendarMonthsOfMs, isCalendarIntervalMs, } from '../chart/calendar-interval.util.js';
359
+ import { intervalLabelForMs } from '../chart/interval-ladder.util.js';
360
+ import { barEndMs, calendarBarStartMs, calendarLongestBarMs, calendarMonthsOfMs, chunkFloorMs, fixedGridFloorDivMs, isCalendarIntervalMs, } from '../chart/calendar-interval.util.js';
360
361
  import { WRUN_PINNED_INTERVALS, wrunPinnedIntervalOf } from './wrun-pinned-interval.util.js';
361
362
  import { realMainRows } from '../chart/indicator-gap-detector.util.js';
362
363
  import { placeRowsInHostBars, rowLastInstantMs } from '../chart/host-bar-placement.util.js';
@@ -726,12 +727,12 @@ export function wrunIntrabarLegFetchKey(intervalKey, market) {
726
727
  // The interval pin vocabulary is a thin fact the alert target reads too (wrun-pinned-interval.util);
727
728
  // this module keeps exporting it for its own readers.
728
729
  export { wrunPinnedIntervalOf } from './wrun-pinned-interval.util.js';
729
- /** The chart's spelling of an interval span (an `Intervals.map_unit` key),
730
- * else the span in ms with a unit (a spelling `dataFetch` ignores, so a
731
- * grid leg's fetch falls back to the chart's own interval either way). */
730
+ /** The chart's spelling of an interval span (an `Intervals.map_unit` key): the resolver's own label first (28 days
731
+ * is 4w, never the legacy '1mm' row), else the first table row of that length, else the span in ms with a unit (a
732
+ * spelling `dataFetch` ignores, so a grid leg's fetch falls back to the chart's own interval either way). */
732
733
  export function wrunChartIntervalKeyOf(intervalMs) {
733
734
  const entry = Object.entries(Intervals.map_unit).find(([, ms]) => ms === intervalMs);
734
- return entry ? entry[0] : `${intervalMs}ms`;
735
+ return intervalLabelForMs(intervalMs) ?? (entry ? entry[0] : `${intervalMs}ms`);
735
736
  }
736
737
  /** A pinned leg's fetch identity: the market (the chart's own when
737
738
  * unpinned, so the fetch payload's placeholders) and the leg interval, the
@@ -851,7 +852,7 @@ export function wrunWireRowPieces(fromMs, toMs, rowMs) {
851
852
  }
852
853
  const pieces = [];
853
854
  for (let at = fromMs; at < toMs;) {
854
- const edge = Math.min(toMs, Math.floor(at / bucketMs) * bucketMs + bucketMs);
855
+ const edge = Math.min(toMs, chunkFloorMs(at, bucketMs, rowMs) + bucketMs);
855
856
  pieces.push({ fromMs: at, toMs: edge });
856
857
  at = edge;
857
858
  }
@@ -1790,7 +1791,7 @@ export function wrunFormingBucketStart(ts, legMs) {
1790
1791
  const months = calendarMonthsOfMs(legMs);
1791
1792
  if (months !== null)
1792
1793
  return calendarBarStartMs(ts, months);
1793
- return Math.floor(ts / legMs) * legMs;
1794
+ return fixedGridFloorDivMs(ts, legMs);
1794
1795
  }
1795
1796
  /**
1796
1797
  * True when the package reads a lane laid on the chart's timeline besides the chart's own
@@ -8,8 +8,9 @@
8
8
  * corpus), and the theme-token packing every host restates (the draw ABI
9
9
  * sentinel, the wire text, the packed f64 form).
10
10
  *
11
- * Imports nothing (no vue, no DOM, no titan, no kit): main-thread and worker
12
- * safe. The om twin is packages/sdk/src/wrun-style-words.ts and
11
+ * Imports only the door to the mark colour maths (wrun-colour-tone.lazy,
12
+ * import-free; the maths stay off the pre-candle path): no vue, no DOM, no
13
+ * titan, no kit, main-thread and worker safe. The om twin is packages/sdk/src/wrun-style-words.ts and
13
14
  * wrun-value-format.ts; the two sides must agree on every word and byte.
14
15
  *
15
16
  * Theme tokens ride sheets, wire props and run outputs unresolved; they
@@ -17,17 +18,20 @@
17
18
  * wrunColorThemeOf(tc))` and re-resolve on a theme switch without a rerun
18
19
  * (`onWrunThemeChange`).
19
20
  */
20
- /** The seven theme colour tokens a colour key may name as `theme.<token>`.
21
- * Token k of the packed forms below is `index + 1` in this order. */
22
- export declare const WRUN_THEME_COLOR_TOKENS: readonly ["up", "down", "text", "muted", "bg", "grid", "accent"];
21
+ /** The nine theme colour tokens a colour key may name as `theme.<token>`.
22
+ * Token k of the packed forms below is `index + 1` in this order: the
23
+ * Big Trades looks round appended `up_mark` (k 8) and `down_mark` (k 9). */
24
+ export declare const WRUN_THEME_COLOR_TOKENS: readonly ["up", "down", "text", "muted", "bg", "grid", "accent", "up_mark", "down_mark"];
23
25
  export type WrunThemeColorToken = (typeof WRUN_THEME_COLOR_TOKENS)[number];
24
26
  /** A theme token with its alpha (0..1). */
25
27
  export interface WrunThemeTokenRef {
26
28
  token: WrunThemeColorToken;
27
29
  alpha: number;
28
30
  }
31
+ /** The tokens as a refusal lists them: `theme.up, theme.down, ...`. */
32
+ export declare const WRUN_THEME_TOKEN_WORDS_TEXT: string;
29
33
  /** True for the convention-2 colour word: `#rrggbb`, `#rrggbbaa` or one of
30
- * the seven tokens spelled exactly (`theme.up`); the `/aa` wire form, any
34
+ * the nine tokens spelled exactly (`theme.up`); the `/aa` wire form, any
31
35
  * other `theme.` word and every non-string are not colour words. */
32
36
  export declare function isWrunColorWord(value: unknown): value is string;
33
37
  /** The token a string names: `theme.<t>` (alpha 1) or the wire's
@@ -47,7 +51,7 @@ export declare function wrunThemeTokenWithAlpha(value: string, alpha: number): s
47
51
  * is `theme.up/40`. The product is clamped to 0..1. A non-token string and
48
52
  * a non-finite factor come back unchanged. */
49
53
  export declare function wrunThemeTokenScaleAlpha(value: string, factor: number): string;
50
- /** The seven palette colours a chart's theme answers a token with, as CSS
54
+ /** The nine palette colours a chart's theme answers a token with, as CSS
51
55
  * colour strings. */
52
56
  export interface WrunColorTheme {
53
57
  up: string;
@@ -57,12 +61,30 @@ export interface WrunColorTheme {
57
61
  bg: string;
58
62
  grid: string;
59
63
  accent: string;
64
+ /** The mark colour of each side: the candle colour stepped one tone away
65
+ * from the background (`markSideColour`). */
66
+ up_mark: string;
67
+ down_mark: string;
60
68
  }
69
+ /** A parsed colour: channels 0..255, alpha 0..1. */
70
+ export interface WrunRgbaParts {
71
+ r: number;
72
+ g: number;
73
+ b: number;
74
+ a: number;
75
+ }
76
+ /** A palette colour parsed: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,
77
+ * `rgb(r, g, b)` or `rgba(r, g, b, a)` (the forms the chart theme writes).
78
+ * Anything else is no colour. */
79
+ export declare function parseWrunCssColor(value: unknown): WrunRgbaParts | undefined;
61
80
  /** The palette of a chart (`tc`, feature-detected: a bare test double or a
62
81
  * pin without a theme answers the dark defaults): up and down from the
63
82
  * candle colours, text from the x axis font colour, muted = text at alpha
64
83
  * x 0.55, bg and grid from the theme, accent from `noteWrunThemeApplied`
65
- * (fallback '#ff4608'). */
84
+ * (fallback '#ff4608'), up_mark and down_mark the candle colours stepped
85
+ * one tone away from bg (`markSideColour`, through its door: the up and
86
+ * down colours until wrun-colour-tone.util has evaluated). Read at every mount and theme
87
+ * change, so the mark colours follow a theme switch with no rerun. */
66
88
  export declare function wrunColorThemeOf(tc: unknown): WrunColorTheme;
67
89
  /** Records the accent colour of a theme apply for `tc` (a WeakMap, so a
68
90
  * disposed chart leaves nothing behind), then tells every
@@ -143,6 +165,6 @@ export declare function wrunDrawColorWire(rgba: number): string;
143
165
  * `-(k * 1024 + round(alpha * 1000))`, a negative integer no colour ever
144
166
  * packed to. Alpha is clamped to 0..1. */
145
167
  export declare function wrunPackedThemeToken(ref: WrunThemeTokenRef): number;
146
- /** Decodes a packed colour: a finite negative integer whose k lands in 1..7
168
+ /** Decodes a packed colour: a finite negative integer whose k lands in 1..9
147
169
  * and whose alpha part is at most 1000 is a token, anything else null. */
148
170
  export declare function wrunThemeTokenOfPacked(value: number): WrunThemeTokenRef | null;
@@ -8,8 +8,9 @@
8
8
  * corpus), and the theme-token packing every host restates (the draw ABI
9
9
  * sentinel, the wire text, the packed f64 form).
10
10
  *
11
- * Imports nothing (no vue, no DOM, no titan, no kit): main-thread and worker
12
- * safe. The om twin is packages/sdk/src/wrun-style-words.ts and
11
+ * Imports only the door to the mark colour maths (wrun-colour-tone.lazy,
12
+ * import-free; the maths stay off the pre-candle path): no vue, no DOM, no
13
+ * titan, no kit, main-thread and worker safe. The om twin is packages/sdk/src/wrun-style-words.ts and
13
14
  * wrun-value-format.ts; the two sides must agree on every word and byte.
14
15
  *
15
16
  * Theme tokens ride sheets, wire props and run outputs unresolved; they
@@ -17,15 +18,27 @@
17
18
  * wrunColorThemeOf(tc))` and re-resolve on a theme switch without a rerun
18
19
  * (`onWrunThemeChange`).
19
20
  */
21
+ import { wrunMarkSideColour } from './wrun-colour-tone.lazy.js';
20
22
  // Colour words
21
- /** The seven theme colour tokens a colour key may name as `theme.<token>`.
22
- * Token k of the packed forms below is `index + 1` in this order. */
23
- export const WRUN_THEME_COLOR_TOKENS = ['up', 'down', 'text', 'muted', 'bg', 'grid', 'accent'];
23
+ /** The nine theme colour tokens a colour key may name as `theme.<token>`.
24
+ * Token k of the packed forms below is `index + 1` in this order: the
25
+ * Big Trades looks round appended `up_mark` (k 8) and `down_mark` (k 9). */
26
+ export const WRUN_THEME_COLOR_TOKENS = [
27
+ 'up',
28
+ 'down',
29
+ 'text',
30
+ 'muted',
31
+ 'bg',
32
+ 'grid',
33
+ 'accent',
34
+ 'up_mark',
35
+ 'down_mark',
36
+ ];
24
37
  const WRUN_THEME_TOKEN_PREFIX = 'theme.';
25
38
  /** The sheet colour word: `#rrggbb` or `#rrggbbaa` (alpha in the last byte). */
26
39
  const WRUN_HEX_COLOR_WORD_RE = /^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/;
27
40
  /** `theme.<token>` (a sheet word) or `theme.<token>/aa` (the wire form). */
28
- const WRUN_THEME_TOKEN_RE = /^theme\.([a-z]+)(?:\/([0-9a-fA-F]{2}))?$/;
41
+ const WRUN_THEME_TOKEN_RE = /^theme\.([a-z_]+)(?:\/([0-9a-fA-F]{2}))?$/;
29
42
  function wrunTokenOf(name) {
30
43
  return WRUN_THEME_COLOR_TOKENS.includes(name) ? name : undefined;
31
44
  }
@@ -35,8 +48,10 @@ function wrunTokenK(token) {
35
48
  function wrunTokenAlpha(alpha) {
36
49
  return Number.isFinite(alpha) ? Math.min(1, Math.max(0, alpha)) : 1;
37
50
  }
51
+ /** The tokens as a refusal lists them: `theme.up, theme.down, ...`. */
52
+ export const WRUN_THEME_TOKEN_WORDS_TEXT = WRUN_THEME_COLOR_TOKENS.map((token) => `theme.${token}`).join(', ');
38
53
  /** True for the convention-2 colour word: `#rrggbb`, `#rrggbbaa` or one of
39
- * the seven tokens spelled exactly (`theme.up`); the `/aa` wire form, any
54
+ * the nine tokens spelled exactly (`theme.up`); the `/aa` wire form, any
40
55
  * other `theme.` word and every non-string are not colour words. */
41
56
  export function isWrunColorWord(value) {
42
57
  if (typeof value !== 'string')
@@ -96,7 +111,9 @@ const WRUN_THEME_FALLBACK = {
96
111
  grid: '#2a2e39',
97
112
  accent: '#ff4608',
98
113
  };
99
- /** `muted` is the text colour at this fraction of its own alpha (X8). */
114
+ /** `muted` is the text colour at this fraction of its own alpha (X8);
115
+ * `up_mark` and `down_mark` are worked out from up, down and bg, so a bare
116
+ * chart answers them from the defaults above. */
100
117
  const WRUN_MUTED_ALPHA = 0.55;
101
118
  function wrunChannel(text) {
102
119
  const value = Number(text);
@@ -105,7 +122,7 @@ function wrunChannel(text) {
105
122
  /** A palette colour parsed: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,
106
123
  * `rgb(r, g, b)` or `rgba(r, g, b, a)` (the forms the chart theme writes).
107
124
  * Anything else is no colour. */
108
- function parseWrunCssColor(value) {
125
+ export function parseWrunCssColor(value) {
109
126
  if (typeof value !== 'string')
110
127
  return undefined;
111
128
  const text = value.trim().toLowerCase();
@@ -167,20 +184,28 @@ const wrunThemeListeners = new Set();
167
184
  * pin without a theme answers the dark defaults): up and down from the
168
185
  * candle colours, text from the x axis font colour, muted = text at alpha
169
186
  * x 0.55, bg and grid from the theme, accent from `noteWrunThemeApplied`
170
- * (fallback '#ff4608'). */
187
+ * (fallback '#ff4608'), up_mark and down_mark the candle colours stepped
188
+ * one tone away from bg (`markSideColour`, through its door: the up and
189
+ * down colours until wrun-colour-tone.util has evaluated). Read at every mount and theme
190
+ * change, so the mark colours follow a theme switch with no rerun. */
171
191
  export function wrunColorThemeOf(tc) {
172
192
  const chart = wrunRecordAt(tc);
173
193
  const theme = wrunRecordAt(chart?.theme);
174
194
  const text = wrunColorField(wrunRecordAt(theme?.xAxis)?.fontColor) ?? WRUN_THEME_FALLBACK.text;
175
195
  const accent = chart === undefined ? undefined : wrunAccentByChart.get(chart);
196
+ const up = wrunColorField(theme?.bullishCandleColor) ?? WRUN_THEME_FALLBACK.up;
197
+ const down = wrunColorField(theme?.bearishCandleColor) ?? WRUN_THEME_FALLBACK.down;
198
+ const bg = wrunColorField(theme?.backgroundColor) ?? WRUN_THEME_FALLBACK.bg;
176
199
  return {
177
- up: wrunColorField(theme?.bullishCandleColor) ?? WRUN_THEME_FALLBACK.up,
178
- down: wrunColorField(theme?.bearishCandleColor) ?? WRUN_THEME_FALLBACK.down,
200
+ up,
201
+ down,
179
202
  text,
180
203
  muted: wrunMutedOf(text),
181
- bg: wrunColorField(theme?.backgroundColor) ?? WRUN_THEME_FALLBACK.bg,
204
+ bg,
182
205
  grid: wrunColorField(wrunRecordAt(theme?.grid)?.color) ?? WRUN_THEME_FALLBACK.grid,
183
206
  accent: wrunColorField(accent) ?? WRUN_THEME_FALLBACK.accent,
207
+ up_mark: wrunMarkSideColour(up, bg),
208
+ down_mark: wrunMarkSideColour(down, bg),
184
209
  };
185
210
  }
186
211
  /** Records the accent colour of a theme apply for `tc` (a WeakMap, so a
@@ -396,6 +421,12 @@ export function formatWrunNumber(value, spec = {}) {
396
421
  * {@link WRUN_THEME_COLOR_TOKENS} with its alpha in the blue byte. Every
397
422
  * other value is a plain colour. */
398
423
  export const WRUN3_THEME_TOKEN_MARKER = 0x7e;
424
+ /** The tokens the i32 sentinel carries: the first seven only. The mark tokens
425
+ * (k 8, 9) exist as sheet words and in the packed f64 form, never in the
426
+ * sentinel: every published package's compiled `rgba()` zeroes alpha-0
427
+ * colours only for green 1..7, so green 8 or 9 at alpha 0 is an invisible
428
+ * plain colour and must stay one (the om corpus pins `0x7E09FF00`). */
429
+ const WRUN3_SENTINEL_TOKEN_COUNT = 7;
399
430
  /** Decodes the draw ABI sentinel (`0xRRGGBBAA` as an i32 or u32): a token
400
431
  * when the alpha byte is 0, the red byte the marker and the green byte in
401
432
  * 1..7, else null (a plain colour, exactly as before the sentinel). */
@@ -403,7 +434,7 @@ export function wrunThemeTokenOfI32(rgba) {
403
434
  if ((rgba & 0xff) !== 0 || rgba >>> 24 !== WRUN3_THEME_TOKEN_MARKER)
404
435
  return null;
405
436
  const k = (rgba >>> 16) & 0xff;
406
- const token = k >= 1 ? WRUN_THEME_COLOR_TOKENS[k - 1] : undefined;
437
+ const token = k >= 1 && k <= WRUN3_SENTINEL_TOKEN_COUNT ? WRUN_THEME_COLOR_TOKENS[k - 1] : undefined;
407
438
  if (token === undefined)
408
439
  return null;
409
440
  return { token, alpha: ((rgba >>> 8) & 0xff) / 255 };
@@ -426,7 +457,7 @@ export function wrunDrawColorWire(rgba) {
426
457
  export function wrunPackedThemeToken(ref) {
427
458
  return -(wrunTokenK(ref.token) * 1024 + Math.round(wrunTokenAlpha(ref.alpha) * 1000));
428
459
  }
429
- /** Decodes a packed colour: a finite negative integer whose k lands in 1..7
460
+ /** Decodes a packed colour: a finite negative integer whose k lands in 1..9
430
461
  * and whose alpha part is at most 1000 is a token, anything else null. */
431
462
  export function wrunThemeTokenOfPacked(value) {
432
463
  if (!Number.isInteger(value) || value >= 0)
@@ -28,6 +28,7 @@
28
28
  * `wrunLegPlacementLeadMs`) are the pinned candle legs' too.
29
29
  */
30
30
  import { Intervals } from '../../constants/interval.constants.js';
31
+ import { intervalLabelForMs } from '../chart/interval-ladder.util.js';
31
32
  import { barEndMs, isCalendarIntervalMs } from '../chart/calendar-interval.util.js';
32
33
  import { indexHostFetchTierMs, sourceRowsStraddleHostBars } from '../chart/index-host-tier.util.js';
33
34
  import { liveBucketVenueOf } from '../chart/live-bucket.util.js';
@@ -103,7 +104,7 @@ export function wrunLegPlacementLeadMs(chart, legMs, market) {
103
104
  * spec pins the two over every interval). */
104
105
  function wrunLegTierIntervalKey(intervalMs) {
105
106
  const entry = Object.entries(Intervals.map_unit).find(([, ms]) => ms === intervalMs);
106
- return entry ? entry[0] : `${intervalMs}ms`;
107
+ return intervalLabelForMs(intervalMs) ?? (entry ? entry[0] : `${intervalMs}ms`);
107
108
  }
108
109
  /**
109
110
  * The request a trades leg lane is asked with over a window `[fromMs, toMs]` (the run window's first bar through its