@orangecharts/wrun-chart-host 0.4.0 → 0.6.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 (331) hide show
  1. package/README.md +17 -5
  2. package/dist/constants/exchange-names.leaf.d.ts +8 -0
  3. package/dist/constants/exchange-names.leaf.js +101 -0
  4. package/dist/constants/feature-flags.constants.js +7 -2
  5. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +15 -0
  6. package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
  7. package/dist/constants/opra-compliance.constants.d.ts +19 -0
  8. package/dist/constants/opra-compliance.constants.js +19 -0
  9. package/dist/constants/replay-ladder.leaf.d.ts +30 -0
  10. package/dist/constants/replay-ladder.leaf.js +99 -0
  11. package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
  12. package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
  13. package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
  14. package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
  15. package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
  16. package/dist/constants/scriptEditor/execution.constants.js +14 -0
  17. package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
  18. package/dist/constants/wrun-prefix-safe.constants.js +26 -0
  19. package/dist/host-env.d.ts +301 -22
  20. package/dist/host-env.js +15 -0
  21. package/dist/host-ports.types.d.ts +853 -29
  22. package/dist/index.d.ts +140 -2
  23. package/dist/index.js +140 -2
  24. package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
  25. package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
  26. package/dist/interfaces/market-event.interface.d.ts +231 -0
  27. package/dist/interfaces/market-event.interface.js +15 -0
  28. package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
  29. package/dist/interfaces/opra-realtime.interface.js +34 -59
  30. package/dist/interfaces/replay.interface.d.ts +285 -0
  31. package/dist/interfaces/replay.interface.js +1 -0
  32. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  33. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  34. package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
  35. package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
  36. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
  37. package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
  38. package/dist/market-data/billing.interface.d.ts +219 -0
  39. package/dist/market-data/billing.interface.js +58 -0
  40. package/dist/market-data/venue-governed.util.d.ts +2 -0
  41. package/dist/market-data/venue-governed.util.js +10 -0
  42. package/dist/market-data/venue.d.ts +122 -0
  43. package/dist/market-data/venue.js +1 -0
  44. package/dist/market-data/venues/index.d.ts +97 -0
  45. package/dist/market-data/venues/index.js +33 -0
  46. package/dist/market-data/venues/opra.contract.copy.json +35 -0
  47. package/dist/market-data/venues/opra.d.ts +70 -0
  48. package/dist/market-data/venues/opra.js +74 -0
  49. package/dist/replay/replayIndicatorRows.d.ts +31 -0
  50. package/dist/replay/replayIndicatorRows.js +117 -0
  51. package/dist/replay/replayLadder.d.ts +85 -0
  52. package/dist/replay/replayLadder.js +388 -0
  53. package/dist/utility/auth/server-clock.util.d.ts +81 -0
  54. package/dist/utility/auth/server-clock.util.js +238 -0
  55. package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
  56. package/dist/utility/chart/builtin-identity.util.js +51 -0
  57. package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
  58. package/dist/utility/chart/cache-alignment.util.js +926 -0
  59. package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
  60. package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
  61. package/dist/utility/chart/chart-mount-epoch.util.d.ts +17 -0
  62. package/dist/utility/chart/chart-mount-epoch.util.js +61 -0
  63. package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
  64. package/dist/utility/chart/chart-time-domain.util.js +23 -0
  65. package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
  66. package/dist/utility/chart/color-customization.leaf.js +16 -0
  67. package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
  68. package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
  69. package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
  70. package/dist/utility/chart/gesture-timing.leaf.js +29 -0
  71. package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
  72. package/dist/utility/chart/governed-contract-coin.util.js +39 -0
  73. package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
  74. package/dist/utility/chart/host-bar-placement.util.js +447 -0
  75. package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
  76. package/dist/utility/chart/index-host-tier.util.js +118 -0
  77. package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
  78. package/dist/utility/chart/index-mode-admission.util.js +67 -0
  79. package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
  80. package/dist/utility/chart/indicator-error-message.util.js +44 -0
  81. package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
  82. package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
  83. package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
  84. package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
  85. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
  86. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
  87. package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
  88. package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
  89. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
  90. package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
  91. package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
  92. package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
  93. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
  94. package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
  95. package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
  96. package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
  97. package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
  98. package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
  99. package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
  100. package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
  101. package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
  102. package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
  103. package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
  104. package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
  105. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
  106. package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
  107. package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
  108. package/dist/utility/chart/kscript-source-retention.util.js +218 -0
  109. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
  110. package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
  111. package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
  112. package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
  113. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
  114. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
  115. package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
  116. package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
  117. package/dist/utility/chart/live-cadence.util.d.ts +38 -0
  118. package/dist/utility/chart/live-cadence.util.js +37 -0
  119. package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
  120. package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
  121. package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
  122. package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
  123. package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
  124. package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
  125. package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
  126. package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
  127. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
  128. package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
  129. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
  130. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
  131. package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
  132. package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
  133. package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
  134. package/dist/utility/chart/mixed-mode.util.js +139 -0
  135. package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
  136. package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
  137. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
  138. package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
  139. package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
  140. package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
  141. package/dist/utility/chart/price-precision.util.d.ts +40 -0
  142. package/dist/utility/chart/price-precision.util.js +70 -0
  143. package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
  144. package/dist/utility/chart/profile-block-size.util.js +141 -0
  145. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
  146. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
  147. package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
  148. package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
  149. package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
  150. package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
  151. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
  152. package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
  153. package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
  154. package/dist/utility/chart/titan-constants.pin.js +18 -5
  155. package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
  156. package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
  157. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
  158. package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
  159. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
  160. package/dist/utility/chart/wrun-run-result.util.js +20 -14
  161. package/dist/utility/common/data-processing.util.d.ts +138 -0
  162. package/dist/utility/common/data-processing.util.js +346 -0
  163. package/dist/utility/common/visible-timeout.util.d.ts +13 -4
  164. package/dist/utility/common/visible-timeout.util.js +23 -8
  165. package/dist/utility/exchange-format.leaf.d.ts +1 -0
  166. package/dist/utility/exchange-format.leaf.js +47 -0
  167. package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
  168. package/dist/utility/market-events/earnings-scope.util.js +92 -0
  169. package/dist/utility/market-events/market-events.util.d.ts +147 -0
  170. package/dist/utility/market-events/market-events.util.js +392 -0
  171. package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
  172. package/dist/utility/market-events/zoned-clock.util.js +11 -0
  173. package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
  174. package/dist/utility/options/option-venue-disclosure.util.js +56 -0
  175. package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
  176. package/dist/utility/scriptEditor/package-semver.util.js +120 -0
  177. package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
  178. package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
  179. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
  180. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
  181. package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
  182. package/dist/utility/v2/governed-tier.leaf.js +113 -0
  183. package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
  184. package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
  185. package/dist/utility/wrun/sources/lanes/series.js +2 -2
  186. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +4 -4
  187. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +5 -6
  188. package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
  189. package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
  190. package/dist/utility/wrun/wrun-bar-count.util.d.ts +94 -0
  191. package/dist/utility/wrun/wrun-bar-count.util.js +274 -0
  192. package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
  193. package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
  194. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
  195. package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
  196. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
  197. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
  198. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
  199. package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
  200. package/dist/utility/wrun/wrun-deadline.util.js +2 -1
  201. package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
  202. package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
  203. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
  204. package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
  205. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
  206. package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
  207. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
  208. package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
  209. package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
  210. package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
  211. package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
  212. package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
  213. package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
  214. package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
  215. package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
  216. package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
  217. package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
  218. package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
  219. package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
  220. package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
  221. package/dist/utility/wrun/wrun-host.service.d.ts +330 -0
  222. package/dist/utility/wrun/wrun-host.service.js +855 -0
  223. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  224. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  225. package/dist/utility/wrun/wrun-inert-legend.util.d.ts +33 -0
  226. package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
  227. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
  228. package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
  229. package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
  230. package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
  231. package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
  232. package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
  233. package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
  234. package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
  235. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
  236. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
  237. package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
  238. package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
  239. package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
  240. package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
  241. package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
  242. package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
  243. package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
  244. package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
  245. package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
  246. package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
  247. package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
  248. package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
  249. package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
  250. package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
  251. package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
  252. package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
  253. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
  254. package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
  255. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
  256. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
  257. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
  258. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
  259. package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
  260. package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
  261. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
  262. package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
  263. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
  264. package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
  265. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  266. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +24 -9
  267. package/dist/utility/wrun/wrun-panel-mount.util.js +138 -43
  268. package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
  269. package/dist/utility/wrun/wrun-param-map.util.js +40 -47
  270. package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
  271. package/dist/utility/wrun/wrun-param-values.util.js +5 -5
  272. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
  273. package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
  274. package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
  275. package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
  276. package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
  277. package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
  278. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
  279. package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
  280. package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
  281. package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
  282. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  283. package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
  284. package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
  285. package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
  286. package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
  287. package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
  288. package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
  289. package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
  290. package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
  291. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
  292. package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
  293. package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
  294. package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
  295. package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
  296. package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
  297. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
  298. package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
  299. package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
  300. package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
  301. package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
  302. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  303. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  304. package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
  305. package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
  306. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
  307. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
  308. package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
  309. package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
  310. package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
  311. package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
  312. package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
  313. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
  314. package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
  315. package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
  316. package/dist/utility/wrun/wrun-text-params.util.js +19 -30
  317. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
  318. package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
  319. package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
  320. package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
  321. package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
  322. package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
  323. package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
  324. package/dist/utility/wrun-alert-params.leaf.js +24 -0
  325. package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
  326. package/dist/utils/replay/replay-buffer-math.js +684 -0
  327. package/dist/workers/wrun/wrun-abi-host.d.ts +203 -0
  328. package/dist/workers/wrun/wrun-abi-host.js +1220 -0
  329. package/dist/workers/wrun/wrun-engine-handler.d.ts +20 -0
  330. package/dist/workers/wrun/wrun-engine-handler.js +380 -0
  331. package/package.json +3 -3
@@ -0,0 +1,684 @@
1
+ import { Intervals } from '../../constants/interval.constants.js';
2
+ import { intervalLabelForMs } from '../../utility/chart/interval-registry.util.js';
3
+ import { CANDLE_TICK_BACKFILL_SEC, FALLBACK_VIEW_BEHIND_MS, FOLLOW_SPAN_ECHO_TOLERANCE_BARS, MONDAY_BUCKET_ORIGIN_MS, REPLAY_COARSE_FORWARD_BATCH, REPLAY_FOLLOW_RIGHT_OFFSET_FRACTION, REPLAY_FORWARD_BATCH, } from '../../constants/replay-ladder.leaf.js';
4
+ import { replayResolutionBookEdgeSec, replayResolutionStepMs, tfLabelForMs } from '../../replay/replayLadder.js';
5
+ const DAY_MS = Intervals.DAY;
6
+ const WEEK_MS = Intervals.WEEK;
7
+ export function firstRejectedReplayFetch(results) {
8
+ return results.find((result) => result.status === 'rejected') ?? null;
9
+ }
10
+ export function throwRejectedReplayFetch(results) {
11
+ const rejected = firstRejectedReplayFetch(results);
12
+ if (!rejected) {
13
+ return;
14
+ }
15
+ throw rejected.reason;
16
+ }
17
+ export const cloneRows = (rows) => (rows ?? []).map((row) => row.slice());
18
+ export const isReplayOhlcRow = (row) => Number.isFinite(row[0]) &&
19
+ Number.isFinite(row[1]) &&
20
+ Number.isFinite(row[2]) &&
21
+ Number.isFinite(row[3]) &&
22
+ Number.isFinite(row[4]);
23
+ export function sortedPrefixEnd(rows, cutoffMs, timestampForRow, inclusive) {
24
+ let low = 0;
25
+ let high = rows.length;
26
+ while (low < high) {
27
+ const mid = Math.floor((low + high) / 2);
28
+ const timestamp = timestampForRow(rows[mid]);
29
+ const inPrefix = Number.isFinite(timestamp) && (inclusive ? timestamp <= cutoffMs : timestamp < cutoffMs);
30
+ if (inPrefix) {
31
+ low = mid + 1;
32
+ }
33
+ else {
34
+ high = mid;
35
+ }
36
+ }
37
+ return low;
38
+ }
39
+ export function sortedLowerBound(rows, cutoffMs, timestampForRow) {
40
+ let low = 0;
41
+ let high = rows.length;
42
+ while (low < high) {
43
+ const mid = Math.floor((low + high) / 2);
44
+ const timestamp = timestampForRow(rows[mid]);
45
+ if (Number.isFinite(timestamp) && timestamp < cutoffMs) {
46
+ low = mid + 1;
47
+ }
48
+ else {
49
+ high = mid;
50
+ }
51
+ }
52
+ return low;
53
+ }
54
+ export function isIrregularReplayBuffer(buffer) {
55
+ return buffer.timestampMode === 'irregular';
56
+ }
57
+ const replayRowsStamp = (rows) => ({
58
+ rows,
59
+ length: rows.length,
60
+ lastTs: rows[rows.length - 1]?.[0],
61
+ });
62
+ const replayRowsStampMatches = (stamp, rows) => stamp.rows === rows && stamp.length === rows.length && stamp.lastTs === rows[rows.length - 1]?.[0];
63
+ // The replay clock reads these once or more per tick (end of buffer, next
64
+ // timeline stamp, autoload threshold, the overlay's timeline), while the rows
65
+ // they derive from change once per forward batch. Rebuilding them per read
66
+ // cost O(rows) to O(rows log rows) several times per tick, growing with every
67
+ // bar played. Keyed by buffer, so a replaced buffer starts clean.
68
+ const playableSubRowsMemo = new WeakMap();
69
+ const replayTimelineMemo = new WeakMap();
70
+ const playableEndMemo = new WeakMap();
71
+ function replayTimelineRows(buffer, rows) {
72
+ return rows.filter((row) => {
73
+ const ts = row[0];
74
+ return typeof ts === 'number' && Number.isFinite(ts) && ts >= buffer.anchorMs;
75
+ });
76
+ }
77
+ /**
78
+ * The irregular replay timeline: every playable stamp at or after the anchor.
79
+ * Memoized per buffer, so the same array comes back until the playable rows,
80
+ * the anchor or the chart interval change. Callers must treat it as read-only.
81
+ */
82
+ export function replayTimelineTimestamps(buffer, chartIntervalMs) {
83
+ const rows = playableRowsForBuffer(buffer, chartIntervalMs);
84
+ const memo = replayTimelineMemo.get(buffer);
85
+ if (memo &&
86
+ memo.anchorMs === buffer.anchorMs &&
87
+ memo.chartIntervalMs === chartIntervalMs &&
88
+ replayRowsStampMatches(memo.source, rows)) {
89
+ return memo.timestamps;
90
+ }
91
+ const timestamps = replayTimelineRows(buffer, rows).map((row) => row[0]);
92
+ if (!timestamps.length || timestamps[0] > buffer.anchorMs) {
93
+ timestamps.unshift(buffer.anchorMs);
94
+ }
95
+ const sorted = Array.from(new Set(timestamps)).sort((a, b) => a - b);
96
+ replayTimelineMemo.set(buffer, {
97
+ source: replayRowsStamp(rows),
98
+ anchorMs: buffer.anchorMs,
99
+ chartIntervalMs,
100
+ timestamps: sorted,
101
+ });
102
+ return sorted;
103
+ }
104
+ export function replayIndexForTimestamp(buffer, chartIntervalMs, timestampMs) {
105
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
106
+ if (!timestamps.length) {
107
+ return 0;
108
+ }
109
+ const index = sortedPrefixEnd(timestamps, timestampMs, (timestamp) => timestamp, true) - 1;
110
+ return Math.max(0, Math.min(timestamps.length - 1, index));
111
+ }
112
+ export function replayNearestTimelineTimestamp(buffer, chartIntervalMs, timestampMs) {
113
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
114
+ if (!timestamps.length) {
115
+ return buffer.anchorMs;
116
+ }
117
+ const lowerIndex = Math.max(0, sortedPrefixEnd(timestamps, timestampMs, (timestamp) => timestamp, true) - 1);
118
+ const upperIndex = Math.min(timestamps.length - 1, lowerIndex + 1);
119
+ const lower = timestamps[lowerIndex];
120
+ const upper = timestamps[upperIndex];
121
+ return Math.abs(timestampMs - lower) <= Math.abs(upper - timestampMs) ? lower : upper;
122
+ }
123
+ export function nextReplayTimelineTimestamp(buffer, chartIntervalMs, afterMs) {
124
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
125
+ const index = sortedPrefixEnd(timestamps, afterMs, (timestamp) => timestamp, true);
126
+ return timestamps[index] ?? null;
127
+ }
128
+ export function previousReplayTimelineTimestamp(buffer, chartIntervalMs, beforeMs) {
129
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
130
+ const index = sortedLowerBound(timestamps, beforeMs, (timestamp) => timestamp) - 1;
131
+ return timestamps[Math.max(0, index)] ?? null;
132
+ }
133
+ export function replayAutoloadThresholdMs(buffer, chartIntervalMs, prefetchBars) {
134
+ if (!isIrregularReplayBuffer(buffer)) {
135
+ const stepMs = replayResolutionMs(buffer.tf, chartIntervalMs);
136
+ return buffer.anchorMs + Math.max(0, buffer.loadedBars - prefetchBars) * stepMs;
137
+ }
138
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
139
+ if (!timestamps.length) {
140
+ return buffer.anchorMs;
141
+ }
142
+ return timestamps[Math.max(0, timestamps.length - 1 - prefetchBars)] ?? buffer.anchorMs;
143
+ }
144
+ export function replayViewportSpanMs(viewport, chartIntervalMs) {
145
+ const startKey = Number(viewport?.startKey);
146
+ const endKey = Number(viewport?.endKey);
147
+ if (Number.isFinite(startKey) && Number.isFinite(endKey) && endKey > startKey) {
148
+ return (endKey - startKey) * chartIntervalMs;
149
+ }
150
+ const startTs = Number(viewport?.startTs);
151
+ const endTs = Number(viewport?.endTs);
152
+ if (Number.isFinite(startTs) && Number.isFinite(endTs) && endTs > startTs) {
153
+ return endTs - startTs;
154
+ }
155
+ return null;
156
+ }
157
+ /**
158
+ * The user's framing of the anchor bar, in bars, read from the key-denominated
159
+ * viewport BEFORE the anchor load touches the engine. Null when the anchor is
160
+ * off-screen (the reveal recenters onto the follow frame then) or the
161
+ * viewport is unreadable.
162
+ *
163
+ * Bars, not timestamps: the pre-fetch truncation drops every bar after the
164
+ * anchor and the engine re-anchors a live-following window onto the new tail
165
+ * (the anchor bar ends up at the old live-edge offset, ~90% of the width, no
166
+ * runway to its right). Writing the captured window back by timestamp would
167
+ * undo that on a uniform grid only: past the mounted tail the engine maps
168
+ * timestamps at interval pitch, so on a sparse or session-gap grid a
169
+ * wall-clock window holds a different number of bars than it did and the
170
+ * anchor moves anyway. Keeping the bar counts on each side of the anchor
171
+ * survives the truncation, the buffer's own row numbering, and any grid.
172
+ */
173
+ export function replayAnchorFraming(viewport, anchorIndex) {
174
+ const startKey = Number(viewport?.startKey);
175
+ const endKey = Number(viewport?.endKey);
176
+ if (!Number.isFinite(startKey) || !Number.isFinite(endKey) || endKey <= startKey)
177
+ return null;
178
+ if (!Number.isFinite(anchorIndex) || anchorIndex < startKey || anchorIndex > endKey)
179
+ return null;
180
+ return { leftBars: anchorIndex - startKey, rightBars: endKey - anchorIndex };
181
+ }
182
+ /** The key window that puts the anchor bar (now at `anchorIndex`) back into its captured framing. */
183
+ export function replayAnchorFramingRange(framing, anchorIndex) {
184
+ return { startKey: anchorIndex - framing.leftBars, endKey: anchorIndex + framing.rightBars };
185
+ }
186
+ export function replayFollowRange(buffer, targetMs) {
187
+ // KEY-denominated for EVERY buffer with rows, uniform included (not just
188
+ // irregular session grids): candles are trade-driven, so a thin market's
189
+ // "uniform" grid is sparse too (interval buckets with no bar), and a TIME
190
+ // window of viewBehindMs then contains fewer bars than span / interval.
191
+ // Denominating the window in keys holds the visible BAR count constant no
192
+ // matter how much wall time those bars span; buffers with no rows yet keep
193
+ // the time-window fallback below.
194
+ if (buffer.fullRows.length) {
195
+ const chartIntervalMs = buffer.chartIntervalMs ?? Intervals.MINUTE;
196
+ const visibleBars = Math.max(2, Math.round(buffer.viewBehindMs / chartIntervalMs));
197
+ const rightOffsetBars = Math.max(0, Math.round(visibleBars * REPLAY_FOLLOW_RIGHT_OFFSET_FRACTION));
198
+ const targetIndex = Math.max(0, sortedPrefixEnd(buffer.fullRows, targetMs, (row) => row[0], true) - 1);
199
+ const endKey = Math.max(visibleBars, targetIndex + 1 + rightOffsetBars);
200
+ const startKey = Math.max(0, endKey - visibleBars);
201
+ const startIndex = Math.min(buffer.fullRows.length - 1, Math.floor(startKey));
202
+ const endIndex = Math.min(buffer.fullRows.length - 1, Math.max(0, Math.ceil(endKey) - 1));
203
+ const startTs = buffer.fullRows[startIndex]?.[0];
204
+ const endTs = buffer.fullRows[endIndex]?.[0];
205
+ if (typeof startTs === 'number' && typeof endTs === 'number' && Number.isFinite(startTs)) {
206
+ return {
207
+ startTs,
208
+ endTs: endTs > startTs ? endTs : startTs + chartIntervalMs,
209
+ startKey,
210
+ endKey,
211
+ };
212
+ }
213
+ }
214
+ const visibleSpanMs = buffer.viewBehindMs > 0 ? buffer.viewBehindMs : FALLBACK_VIEW_BEHIND_MS;
215
+ const rightOffsetMs = visibleSpanMs * REPLAY_FOLLOW_RIGHT_OFFSET_FRACTION;
216
+ const firstRowMs = buffer.fullRows[0]?.[0];
217
+ let startTs = targetMs + rightOffsetMs - visibleSpanMs;
218
+ let endTs = targetMs + rightOffsetMs;
219
+ if (typeof firstRowMs === 'number' && startTs < firstRowMs) {
220
+ startTs = firstRowMs;
221
+ endTs = firstRowMs + visibleSpanMs;
222
+ }
223
+ return {
224
+ startTs,
225
+ endTs,
226
+ };
227
+ }
228
+ function hasReplayFollowKeyRange(range) {
229
+ return (typeof range.startKey === 'number' &&
230
+ typeof range.endKey === 'number' &&
231
+ Number.isFinite(range.startKey) &&
232
+ Number.isFinite(range.endKey) &&
233
+ range.endKey > range.startKey);
234
+ }
235
+ export function applyReplayFollowRange(target, range) {
236
+ if (hasReplayFollowKeyRange(range) && typeof target.resetRange === 'function') {
237
+ target.resetRange(range.startKey, range.endKey);
238
+ return;
239
+ }
240
+ target.resetRangeByTs?.(range.startTs, range.endTs);
241
+ }
242
+ /**
243
+ * Records the span of a follow range replay is about to drive the viewport to
244
+ * (a direct apply, a reveal reset, or a camera glide target) as the buffer's
245
+ * echo baseline. adoptUserReplayFollowSpan compares the live viewport against
246
+ * this baseline to tell a genuine user zoom from the follow window's own echo.
247
+ */
248
+ export function recordAppliedReplayFollowSpan(buffer, range, chartIntervalMs) {
249
+ buffer.followAppliedSpan = {
250
+ tsSpanMs: range.endTs - range.startTs,
251
+ ...(hasReplayFollowKeyRange(range) ? { keySpanMs: (range.endKey - range.startKey) * chartIntervalMs } : {}),
252
+ };
253
+ }
254
+ /**
255
+ * Adopts the viewport's span into buffer.viewBehindMs ONLY when it is a
256
+ * genuine user zoom. The previous behavior (re-derive the span from the
257
+ * viewport on every sync) re-imported the follow window's own echo, and on a
258
+ * sparse grid that echo is keySpan * interval, which understates the wall
259
+ * span, so each sync ratcheted the follow zoom down (300 -> 2 bars in ~40
260
+ * ticks). A viewport span within FOLLOW_SPAN_ECHO_TOLERANCE_BARS of the last
261
+ * applied window (in the viewport's own denomination) is the echo and keeps
262
+ * the stored span; anything else is the user's and is adopted.
263
+ */
264
+ export function adoptUserReplayFollowSpan(buffer, viewport, chartIntervalMs) {
265
+ const spanMs = replayViewportSpanMs(viewport, chartIntervalMs);
266
+ if (spanMs === null) {
267
+ return;
268
+ }
269
+ const applied = buffer.followAppliedSpan;
270
+ if (applied) {
271
+ const startKey = Number(viewport?.startKey);
272
+ const endKey = Number(viewport?.endKey);
273
+ const viewportSpanIsKeys = Number.isFinite(startKey) && Number.isFinite(endKey) && endKey > startKey;
274
+ const appliedSpanMs = viewportSpanIsKeys ? (applied.keySpanMs ?? applied.tsSpanMs) : applied.tsSpanMs;
275
+ if (Math.abs(spanMs - appliedSpanMs) <= FOLLOW_SPAN_ECHO_TOLERANCE_BARS * chartIntervalMs) {
276
+ return;
277
+ }
278
+ }
279
+ buffer.viewBehindMs = Math.max(2 * chartIntervalMs, spanMs);
280
+ }
281
+ export function pruneTickCandleRows(buffer, playheadMs, chartIntervalMs = Intervals.MINUTE) {
282
+ if (!buffer.subRows?.length) {
283
+ return;
284
+ }
285
+ const anchorBucketStartMs = alignChartBucketMs(buffer.anchorMs, chartIntervalMs);
286
+ if (!replayUsesSubRowRail(buffer, chartIntervalMs) &&
287
+ !isIrregularReplayBuffer(buffer) &&
288
+ buffer.anchorMs === anchorBucketStartMs) {
289
+ // A settled (non-sub-row) path mounts this chart bucket from fullRows; retained fine
290
+ // rows would let ReplayClock fold the already-settled candle again. While the sub-row
291
+ // rail is ACTIVE those same rows are the anchor bucket's forming source: pruning them
292
+ // froze the last candle for the whole first bucket and made coverage refetch the
293
+ // window every tick (fetch -> merge -> prune loop).
294
+ const settledAnchorBucketEndMs = anchorBucketStartMs + chartIntervalMs;
295
+ buffer.subRows = buffer.subRows.filter((row) => typeof row[0] === 'number' && Number.isFinite(row[0]) && row[0] >= settledAnchorBucketEndMs);
296
+ }
297
+ if (buffer.tf.kind !== 'tick' || !buffer.subRows.length) {
298
+ return;
299
+ }
300
+ const activeBucketStartMs = alignChartBucketMs(playheadMs, chartIntervalMs);
301
+ const minTs = Math.min(activeBucketStartMs, playheadMs - CANDLE_TICK_BACKFILL_SEC * 1000);
302
+ buffer.subRows = buffer.subRows.filter((row) => typeof row[0] === 'number' && row[0] >= minTs);
303
+ }
304
+ /**
305
+ * The heatmap analog of pruneTickCandleRows: sheds buffered book columns
306
+ * outside [windowMinMs, windowMaxMs] (inclusive), keeping only the span the
307
+ * session can actually reach (candle floor .. forward book coverage). Any
308
+ * eviction also drops the pan-back no-gain latch, whose evidence (column
309
+ * count, deepest column) predates the eviction: a later pan into an evicted
310
+ * span must re-fetch instead of being latch-suppressed.
311
+ */
312
+ export function pruneReplayHeatmapColumnsToWindow(buffer, windowMinMs, windowMaxMs) {
313
+ const columns = buffer.heatmapColumns;
314
+ if (!columns.length) {
315
+ return 0;
316
+ }
317
+ const startIndex = sortedLowerBound(columns, windowMinMs, (column) => column[1]);
318
+ const endIndex = sortedPrefixEnd(columns, windowMaxMs, (column) => column[1], true);
319
+ if (startIndex === 0 && endIndex >= columns.length) {
320
+ return 0;
321
+ }
322
+ buffer.heatmapColumns = columns.slice(startIndex, Math.max(startIndex, endIndex));
323
+ buffer.panBackGapFill = undefined;
324
+ return columns.length - buffer.heatmapColumns.length;
325
+ }
326
+ export function mergeRowsByTimestamp(existing, incoming) {
327
+ if (!incoming.length) {
328
+ return existing;
329
+ }
330
+ const byTime = new Map();
331
+ for (const row of existing) {
332
+ const ts = row[0];
333
+ if (typeof ts === 'number') {
334
+ byTime.set(ts, row.slice());
335
+ }
336
+ }
337
+ for (const row of incoming) {
338
+ const ts = row[0];
339
+ if (typeof ts === 'number') {
340
+ byTime.set(ts, row.slice());
341
+ }
342
+ }
343
+ return Array.from(byTime.values()).sort((a, b) => a[0] - b[0]);
344
+ }
345
+ export function aggregateOhlcvRows(rows, bucketMs, minMs = -Infinity, maxMs = Infinity, options = {}) {
346
+ if (!rows.length) {
347
+ return [];
348
+ }
349
+ const byBucket = new Map();
350
+ const originMs = options.originMs ?? 0;
351
+ const timestamp = options.timestamp ?? 'start';
352
+ const sorted = rows
353
+ .filter((row) => typeof row[0] === 'number' && row[0] >= minMs && row[0] <= maxMs)
354
+ .sort((a, b) => a[0] - b[0]);
355
+ for (const row of sorted) {
356
+ const ts = row[0];
357
+ const bucketStartTs = Math.floor((ts - originMs) / bucketMs) * bucketMs + originMs;
358
+ let bucketTs = bucketStartTs;
359
+ if (timestamp === 'end') {
360
+ bucketTs = bucketStartTs + bucketMs - 1;
361
+ }
362
+ if (bucketTs > maxMs) {
363
+ continue;
364
+ }
365
+ const existing = byBucket.get(bucketTs);
366
+ if (!existing) {
367
+ byBucket.set(bucketTs, [bucketTs, row[1], row[2], row[3], row[4], row[5] ?? 0]);
368
+ continue;
369
+ }
370
+ existing[2] = Math.max(existing[2], row[2]);
371
+ existing[3] = Math.min(existing[3], row[3]);
372
+ existing[4] = row[4];
373
+ existing[5] = (existing[5] ?? 0) + (row[5] ?? 0);
374
+ }
375
+ return Array.from(byBucket.values()).sort((a, b) => a[0] - b[0]);
376
+ }
377
+ function aggregateReplaySubRows(rows, stepMs, minMs, maxMs, originMs) {
378
+ return aggregateOhlcvRows(rows, stepMs, minMs, maxMs, {
379
+ originMs,
380
+ timestamp: stepMs > Intervals.SECOND ? 'end' : 'start',
381
+ });
382
+ }
383
+ export function sourceGranularReplaySubRows(rows, minMs, maxMs) {
384
+ return rows
385
+ .filter((row) => typeof row[0] === 'number' && Number.isFinite(row[0]) && row[0] >= minMs && row[0] <= maxMs)
386
+ .map((row) => row.slice())
387
+ .sort((left, right) => left[0] - right[0]);
388
+ }
389
+ export function replaySubSourceIntervalMs(buffer, chartIntervalMs) {
390
+ const explicitIntervalMs = buffer.subSourceIntervalMs;
391
+ if (typeof explicitIntervalMs === 'number' && Number.isFinite(explicitIntervalMs) && explicitIntervalMs > 0) {
392
+ return explicitIntervalMs;
393
+ }
394
+ const requestIntervalMs = buffer.subRequestInterval
395
+ ? sourceIntervalMsForLabel(buffer.subRequestInterval)
396
+ : sourceIntervalMsForLabel(replayResolutionSourceLabel(buffer.tf, chartIntervalMs));
397
+ return requestIntervalMs ?? replayResolutionMs(buffer.tf, chartIntervalMs);
398
+ }
399
+ /**
400
+ * Whether the sub rows already hold what the forming candle shows at the
401
+ * playhead: on the tick rail a row inside [this step, playhead] of the active
402
+ * chart bucket, on a bar lane a source row whose interval closed inside it.
403
+ * Runs every clock tick (the candle coverage check); sub rows stay sorted, so
404
+ * the first row at or past the earliest qualifying stamp decides instead of a
405
+ * scan of the whole rail, which on bar lanes is never shed and grows one batch
406
+ * per autoload.
407
+ */
408
+ export function replaySubRowsHoldFormingRow(buffer, playheadMs, chartIntervalMs, stepMs, subSourceIntervalMs) {
409
+ const subRows = buffer.subRows;
410
+ if (!subRows?.length)
411
+ return false;
412
+ const activeBucketStartMs = alignChartBucketMs(playheadMs, chartIntervalMs);
413
+ const tickRail = buffer.tf.kind === 'tick';
414
+ const formingFromMs = tickRail
415
+ ? Math.max(activeBucketStartMs, Math.floor(playheadMs / stepMs) * stepMs)
416
+ : activeBucketStartMs;
417
+ const firstRow = subRows[sortedLowerBound(subRows, formingFromMs, (row) => row[0])];
418
+ if (firstRow === undefined)
419
+ return false;
420
+ return tickRail ? firstRow[0] <= playheadMs : firstRow[0] + subSourceIntervalMs <= playheadMs;
421
+ }
422
+ export function formingChartRowFromSubRows(buffer, chartIntervalMs, targetMs) {
423
+ if (!buffer.subRows?.length) {
424
+ return null;
425
+ }
426
+ const bucketStartMs = alignChartBucketMs(targetMs, chartIntervalMs);
427
+ // Tick rows are point-in-time events and retain their existing inclusive reveal semantics.
428
+ // Bar-lane source rows are start-stamped and become playable only after their source interval closes.
429
+ const completionOffsetMs = buffer.tf.kind === 'tick' ? 0 : replaySubSourceIntervalMs(buffer, chartIntervalMs);
430
+ const startIndex = sortedLowerBound(buffer.subRows, bucketStartMs, (row) => row[0]);
431
+ const endIndex = sortedPrefixEnd(buffer.subRows, targetMs - completionOffsetMs, (row) => row[0], true);
432
+ const rows = aggregateOhlcvRows(buffer.subRows.slice(startIndex, endIndex), chartIntervalMs, bucketStartMs, targetMs, {
433
+ originMs: chartBucketOriginMs(chartIntervalMs),
434
+ });
435
+ return rows[0] ?? null;
436
+ }
437
+ export function mergeHeatmapColumns(existing, incoming) {
438
+ if (!incoming.length) {
439
+ return existing;
440
+ }
441
+ const byTime = new Map();
442
+ for (const column of existing) {
443
+ byTime.set(column[1], column);
444
+ }
445
+ for (const column of incoming) {
446
+ byTime.set(column[1], column);
447
+ }
448
+ return Array.from(byTime.values()).sort((a, b) => a[1] - b[1]);
449
+ }
450
+ export function mergeHeatmapColumnsIncrementally(existing, incoming) {
451
+ if (!incoming.length) {
452
+ return existing;
453
+ }
454
+ if (!existing.length) {
455
+ return incoming;
456
+ }
457
+ const existingLastTime = existing[existing.length - 1][1];
458
+ const incomingFirstTime = incoming[0][1];
459
+ if (incomingFirstTime >= existingLastTime) {
460
+ let incomingIndex = 0;
461
+ if (incomingFirstTime === existingLastTime) {
462
+ existing[existing.length - 1] = incoming[0];
463
+ incomingIndex = 1;
464
+ }
465
+ for (; incomingIndex < incoming.length; incomingIndex += 1) {
466
+ existing.push(incoming[incomingIndex]);
467
+ }
468
+ return existing;
469
+ }
470
+ return mergeHeatmapColumns(existing, incoming);
471
+ }
472
+ export function isReplayTimestampVisible(timestampMs, targetMs) {
473
+ return timestampMs <= targetMs;
474
+ }
475
+ /**
476
+ * The rows the clock plays: the chart rows, or on a finer sub-row rail the sub
477
+ * rows collapsed to the replay step. The collapsed rows are memoized per buffer
478
+ * (they re-aggregated every sub row up to three times per tick), so callers
479
+ * must treat the result as read-only, as they already must for fullRows.
480
+ */
481
+ export function playableRowsForBuffer(buffer, chartIntervalMs) {
482
+ // replayUsesSubRowRail already requires subRows; the local read only lets the compiler see it.
483
+ const subRows = buffer.subRows;
484
+ if (subRows !== undefined && replayUsesSubRowRail(buffer, chartIntervalMs)) {
485
+ const stepMs = buffer.subStepMs ?? replayResolutionMs(buffer.tf, chartIntervalMs);
486
+ const originMs = buffer.subOriginMs ?? chartBucketOriginMs(stepMs);
487
+ const memo = playableSubRowsMemo.get(buffer);
488
+ if (memo && memo.stepMs === stepMs && memo.originMs === originMs && replayRowsStampMatches(memo.source, subRows)) {
489
+ return memo.rows;
490
+ }
491
+ const rows = aggregateReplaySubRows(subRows, stepMs, -Infinity, Infinity, originMs);
492
+ playableSubRowsMemo.set(buffer, { source: replayRowsStamp(subRows), stepMs, originMs, rows });
493
+ return rows;
494
+ }
495
+ return buffer.fullRows;
496
+ }
497
+ export function replayUsesSubRowRail(buffer, chartIntervalMs) {
498
+ return replayResolutionMs(buffer.tf, chartIntervalMs) < chartIntervalMs && buffer.subRows !== undefined;
499
+ }
500
+ export function replayForwardBatchForStepMs(stepMs) {
501
+ return stepMs >= DAY_MS ? REPLAY_COARSE_FORWARD_BATCH : REPLAY_FORWARD_BATCH;
502
+ }
503
+ export function replayResolutionMs(tf, chartIntervalMs) {
504
+ const stepMs = replayResolutionStepMs(tf);
505
+ if (Number.isFinite(stepMs) && stepMs > 0) {
506
+ return stepMs;
507
+ }
508
+ return chartIntervalMs;
509
+ }
510
+ export function replayResolutionLabel(tf, chartIntervalMs) {
511
+ void chartIntervalMs;
512
+ if (tf.kind === 'tick') {
513
+ return '1s';
514
+ }
515
+ return tf.tf;
516
+ }
517
+ export function replayResolutionSourceLabel(tf, chartIntervalMs) {
518
+ void chartIntervalMs;
519
+ if (tf.kind === 'tick') {
520
+ return '1s';
521
+ }
522
+ return supportedReplaySourceInterval(tf.tf);
523
+ }
524
+ export function supportedReplaySourceInterval(intervalLabel) {
525
+ if (intervalLabel === '10m') {
526
+ return '5m';
527
+ }
528
+ if (intervalLabel === '2h' || intervalLabel === '3h') {
529
+ return '1h';
530
+ }
531
+ if (intervalLabel === '1w') {
532
+ return '1d';
533
+ }
534
+ return intervalLabel;
535
+ }
536
+ export function replayCandleSourceInterval(chartIntervalMs) {
537
+ return supportedReplaySourceInterval(chartIntervalLabel(chartIntervalMs));
538
+ }
539
+ export function alignProbeCursorMs(cursorMs, stepMs) {
540
+ if (!Number.isFinite(cursorMs) || !Number.isFinite(stepMs) || stepMs <= 1) {
541
+ return Math.max(0, cursorMs);
542
+ }
543
+ return Math.max(0, Math.floor(cursorMs / stepMs) * stepMs);
544
+ }
545
+ export function chartBucketOriginMs(chartIntervalMs) {
546
+ if (chartIntervalMs === WEEK_MS) {
547
+ return MONDAY_BUCKET_ORIGIN_MS;
548
+ }
549
+ return 0;
550
+ }
551
+ export function alignChartBucketMs(timestampMs, chartIntervalMs) {
552
+ const originMs = chartBucketOriginMs(chartIntervalMs);
553
+ return Math.floor((timestampMs - originMs) / chartIntervalMs) * chartIntervalMs + originMs;
554
+ }
555
+ export function replayResolutionRestartAnchorMs(args) {
556
+ // Continue at the playhead: a resolution or interval pick is a playback
557
+ // setting, not a session restart (rewinding a recent anchor onto a
558
+ // seconds-long runway read as a dead transport, 2026-07-26 field dump).
559
+ // rebuildAnchorMs is playhead-preferring and itself falls back to the user
560
+ // anchor when playback already finished (the replay-again affordance) or
561
+ // before any playhead exists. startReplayV3At floors the anchor to the
562
+ // CHART bucket (alignChartBucketMs), so a mid-bucket playhead still starts
563
+ // bucket-aligned (the initial-bar guarantee that motivated the old
564
+ // restart-at-pick-anchor); the continuation can give back up to one chart
565
+ // bucket of already-watched playback, never reveal unwatched bars.
566
+ if (Number.isFinite(args.rebuildAnchorMs) && args.rebuildAnchorMs > 0) {
567
+ return args.rebuildAnchorMs;
568
+ }
569
+ return typeof args.userAnchorMs === 'number' && Number.isFinite(args.userAnchorMs)
570
+ ? args.userAnchorMs
571
+ : args.rebuildAnchorMs;
572
+ }
573
+ export function sourceIntervalMsForLabel(label) {
574
+ const intervalMs = Intervals.map_unit?.[label];
575
+ if (typeof intervalMs === 'number' && Number.isFinite(intervalMs) && intervalMs > 0) {
576
+ return intervalMs;
577
+ }
578
+ return null;
579
+ }
580
+ export function aggregateSourceRowsToChartInterval(rows, sourceInterval, chartIntervalMs, minMs, maxMs) {
581
+ const sourceIntervalMs = sourceIntervalMsForLabel(sourceInterval);
582
+ if (!sourceIntervalMs || sourceIntervalMs >= chartIntervalMs) {
583
+ return rows;
584
+ }
585
+ return aggregateOhlcvRows(rows, chartIntervalMs, minMs, maxMs, {
586
+ originMs: chartBucketOriginMs(chartIntervalMs),
587
+ });
588
+ }
589
+ export function chartIntervalLabel(chartIntervalMs) {
590
+ const interval = intervalLabelForMs(chartIntervalMs);
591
+ return typeof interval === 'string' ? interval : tfLabelForMs(chartIntervalMs);
592
+ }
593
+ export function replayHeatmapResolutionLabel(tf, chartIntervalMs) {
594
+ // Tick lane: the order book is fetched at 1s (server BLOCK_BOOK_SNAPSHOT_AGG &interval=SECOND);
595
+ // Synthetic bar resolutions fetch a supported source rail and are collapsed in the replay buffer.
596
+ return replayResolutionSourceLabel(tf, chartIntervalMs);
597
+ }
598
+ export function maxLoadedBarsForReplayResolution(tf, chartIntervalMs) {
599
+ const tfMs = replayResolutionMs(tf, chartIntervalMs);
600
+ const stepSec = Math.max(1, Math.floor(tfMs / 1000));
601
+ const bookEdgeSec = replayResolutionBookEdgeSec(tf);
602
+ if (!Number.isFinite(bookEdgeSec) || bookEdgeSec <= 0) {
603
+ return Number.POSITIVE_INFINITY;
604
+ }
605
+ return Math.max(0, Math.floor(bookEdgeSec / stepSec));
606
+ }
607
+ export function loadedBarsForRows(buffer, chartIntervalMs) {
608
+ const maxLoadedBars = maxLoadedBarsForReplayResolution(buffer.tf, chartIntervalMs);
609
+ if (isIrregularReplayBuffer(buffer)) {
610
+ const rawLoadedBars = Math.max(0, replayTimelineTimestamps(buffer, chartIntervalMs).length - 1);
611
+ return Math.min(rawLoadedBars, maxLoadedBars);
612
+ }
613
+ const tfMs = replayResolutionMs(buffer.tf, chartIntervalMs);
614
+ const rows = playableRowsForBuffer(buffer, chartIntervalMs);
615
+ const maxTs = rows.reduce((max, row) => {
616
+ const ts = row[0];
617
+ return typeof ts === 'number' && ts > max ? ts : max;
618
+ }, buffer.anchorMs);
619
+ const rawLoadedBars = Math.max(0, Math.floor((maxTs - buffer.anchorMs) / tfMs));
620
+ return Math.min(rawLoadedBars, maxLoadedBars);
621
+ }
622
+ export function encodedHeatmapColumn(time, source) {
623
+ if (!Number.isFinite(time) || !source.length) {
624
+ return null;
625
+ }
626
+ if (source.length >= 2 && source[0] === source.length && Math.abs(source[1] - time) < 1) {
627
+ return Float64Array.from(source);
628
+ }
629
+ const column = new Float64Array(2 + source.length);
630
+ column[0] = column.length;
631
+ column[1] = time;
632
+ for (let i = 0; i < source.length; i++) {
633
+ column[i + 2] = source[i];
634
+ }
635
+ return column;
636
+ }
637
+ export function downsampleHeatmapColumns(columns, stepMs, minMs = -Infinity, maxMs = Infinity) {
638
+ if (!columns.length || stepMs <= Intervals.SECOND) {
639
+ return columns;
640
+ }
641
+ const byBucket = new Map();
642
+ for (const column of [...columns].sort((a, b) => a[1] - b[1])) {
643
+ const ts = column[1];
644
+ if (!Number.isFinite(ts)) {
645
+ continue;
646
+ }
647
+ const bucketStartMs = Math.floor(ts / stepMs) * stepMs;
648
+ const bucketEndMs = bucketStartMs + stepMs;
649
+ if (bucketEndMs <= minMs || bucketStartMs > maxMs) {
650
+ continue;
651
+ }
652
+ const next = ts === bucketStartMs ? column : Float64Array.from(column);
653
+ if (next !== column)
654
+ next[1] = bucketStartMs;
655
+ byBucket.set(bucketStartMs, next);
656
+ }
657
+ return Array.from(byBucket.values()).sort((a, b) => a[1] - b[1]);
658
+ }
659
+ /** Newest playable stamp after the anchor (-Infinity when none), memoized per buffer like the rows it scans. */
660
+ function playableRowsEndMs(buffer, chartIntervalMs) {
661
+ const rows = playableRowsForBuffer(buffer, chartIntervalMs);
662
+ const memo = playableEndMemo.get(buffer);
663
+ if (memo && memo.anchorMs === buffer.anchorMs && replayRowsStampMatches(memo.source, rows)) {
664
+ return memo.endMs;
665
+ }
666
+ const endMs = rows.reduce((max, row) => {
667
+ const ts = row[0];
668
+ return typeof ts === 'number' && ts > buffer.anchorMs && ts > max ? ts : max;
669
+ }, Number.NEGATIVE_INFINITY);
670
+ playableEndMemo.set(buffer, { source: replayRowsStamp(rows), anchorMs: buffer.anchorMs, endMs });
671
+ return endMs;
672
+ }
673
+ export function replayBufferEndMs(buffer, chartIntervalMs) {
674
+ if (isIrregularReplayBuffer(buffer)) {
675
+ const timestamps = replayTimelineTimestamps(buffer, chartIntervalMs);
676
+ return timestamps[timestamps.length - 1] ?? buffer.anchorMs;
677
+ }
678
+ const requestedEndMs = buffer.anchorMs + buffer.loadedBars * replayResolutionMs(buffer.tf, chartIntervalMs);
679
+ const playableEndMs = playableRowsEndMs(buffer, chartIntervalMs);
680
+ if (!Number.isFinite(playableEndMs)) {
681
+ return buffer.loading ? requestedEndMs : buffer.anchorMs;
682
+ }
683
+ return Math.min(requestedEndMs, playableEndMs);
684
+ }