@orangecharts/wrun-chart-host 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/constants/governed-exchanges.constants.d.ts +11 -0
- package/dist/constants/governed-exchanges.constants.js +11 -0
- package/dist/constants/indicator-sets.constants.d.ts +8 -0
- package/dist/constants/indicator-sets.constants.js +8 -0
- package/dist/constants/interval.constants.d.ts +34 -0
- package/dist/constants/interval.constants.js +121 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
- package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
- package/dist/constants/tpo-color-schemes.constants.js +32 -0
- package/dist/host-env.d.ts +102 -0
- package/dist/host-env.js +26 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +96 -0
- package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
- package/dist/indicators/controls/tpo-letter.util.js +13 -0
- package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
- package/dist/indicators/controls/tpo-session.util.js +389 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
- package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
- package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
- package/dist/interfaces/om-panel-data.interface.js +7 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
- package/dist/interfaces/wrun-runtime.interface.js +55 -0
- package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
- package/dist/utility/chart/calendar-interval.util.js +81 -0
- package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
- package/dist/utility/chart/candle-bar-end.util.js +23 -0
- package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
- package/dist/utility/chart/cme-realtime.util.js +53 -0
- package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
- package/dist/utility/chart/interval-ladder.util.js +92 -0
- package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
- package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
- package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
- package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
- package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
- package/dist/utility/chart/kscript-output-role.util.js +215 -0
- package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
- package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
- package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
- package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
- package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
- package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
- package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
- package/dist/utility/chart/om-panel-push-style.util.js +301 -0
- package/dist/utility/chart/om-panel.util.d.ts +166 -0
- package/dist/utility/chart/om-panel.util.js +815 -0
- package/dist/utility/chart/om-series.util.d.ts +42 -0
- package/dist/utility/chart/om-series.util.js +330 -0
- package/dist/utility/chart/om-target.util.d.ts +11 -0
- package/dist/utility/chart/om-target.util.js +24 -0
- package/dist/utility/chart/om-widget.util.d.ts +148 -0
- package/dist/utility/chart/om-widget.util.js +413 -0
- package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
- package/dist/utility/chart/overlay-output-budget.util.js +109 -0
- package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
- package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
- package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
- package/dist/utility/chart/profile-row-height.util.js +110 -0
- package/dist/utility/chart/session-interval.util.d.ts +1 -0
- package/dist/utility/chart/session-interval.util.js +35 -0
- package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
- package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
- package/dist/utility/chart/trading-day.util.d.ts +70 -0
- package/dist/utility/chart/trading-day.util.js +238 -0
- package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
- package/dist/utility/chart/wrun-legend-name.util.js +87 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
- package/dist/utility/chart/wrun-run-result.util.js +5179 -0
- package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
- package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
- package/dist/utility/number-format.util.d.ts +68 -0
- package/dist/utility/number-format.util.js +188 -0
- package/dist/utility/v2/opra-governed.util.d.ts +1 -0
- package/dist/utility/v2/opra-governed.util.js +13 -0
- package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
- package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
- package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
- package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
- package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
- package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
- package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
- package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
- package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
- package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
- package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
- package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
- package/dist/utility/wrun/wrun-card-style.util.js +539 -0
- package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
- package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
- package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
- package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
- package/dist/utility/wrun/wrun-frames.d.ts +217 -0
- package/dist/utility/wrun/wrun-frames.js +1021 -0
- package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
- package/dist/utility/wrun/wrun-handles.util.js +2050 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
- package/dist/utility/wrun/wrun-hover.util.js +534 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
- package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
- package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
- package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
- package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
- package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
- package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
- package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
- package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
- package/dist/utility/wrun/wrun-pack.util.js +301 -0
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
- package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
- package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
- package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-param-values.util.js +230 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
- package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
- package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
- package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
- package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
- package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
- package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
- package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
- package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
- package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
- package/dist/utility/wrun/wrun-style-words.util.js +439 -0
- package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
- package/dist/utility/wrun/wrun-table-look.util.js +225 -0
- package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-text-look.util.js +227 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
- package/dist/utility/wrun/wrun-text-params.util.js +171 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
- package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
- package/dist/utility/wrun/wrun-visibility-table.js +237 -0
- package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
- package/package.json +38 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The socket row store (WRUN-PARITY-PLAN contract C7): the merged picture of every decoded `wrunHost`
|
|
3
|
+
* reply the cloud sent for one overlay's session (docs/features/kscript/wrun/wrun-browser-runtime.md,
|
|
4
|
+
* "The session store"), and that picture's cell rows in the shapes the price canvases read ("Cell rows and
|
|
5
|
+
* the cells memo").
|
|
6
|
+
* Result pages and live tails merge into one ascending row list and one cell row list per celled
|
|
7
|
+
* input; the newest frames, handles and refusals ride beside them, guarded by `asOfMs` so an older
|
|
8
|
+
* page never replaces a newer snapshot. Every apply rebuilds the run result over the whole session,
|
|
9
|
+
* as the own run rebuilds over its whole window.
|
|
10
|
+
*
|
|
11
|
+
* One owner reads it: the socket row source (`wrun-socket-row-source.ts`, one session per source,
|
|
12
|
+
* no session cap: Q3 of the plan, pan-back as deep as the browser lane's). The hosted glue's registry
|
|
13
|
+
* (one session per chart index and overlay id) went with the glue in lane parity U16: a cloud
|
|
14
|
+
* overlay's session is its row source's.
|
|
15
|
+
*
|
|
16
|
+
* `mergeWrunHostedReply` and the cell conversions (`wrunCellRowsFromHostedGrids` and its parts) are
|
|
17
|
+
* pure: they never mutate the session, the wire or any row list. It imports types only beside the
|
|
18
|
+
* interval table: the cell conversion reads `Intervals.map_unit`, the table `wrunChartIntervalMsOf`
|
|
19
|
+
* reads, and keeps `wrun-chart-context.util` out of the socket source's graph.
|
|
20
|
+
*/
|
|
21
|
+
import { Intervals } from '../../constants/interval.constants.js';
|
|
22
|
+
/** The merge's default cap, for a caller that names no policy. A merge above it drops the OLDEST
|
|
23
|
+
* bars, and the cell rows with them, whatever the reply's window: the session always keeps the
|
|
24
|
+
* newest bars, so it never loses continuity with live. The socket row source merges with no cap
|
|
25
|
+
* (`WRUN_SOCKET_ROW_STORE_UNCAPPED`): plan Q3 moved the cloud's caps to the profile. */
|
|
26
|
+
export const WRUN_HOSTED_SESSION_MAX_BARS = 5_000;
|
|
27
|
+
/** The merge policy of the socket row source: every bar the cloud answered stays (plan Q3). */
|
|
28
|
+
export const WRUN_SOCKET_ROW_STORE_UNCAPPED = Object.freeze({ maxBars: Infinity });
|
|
29
|
+
/**
|
|
30
|
+
* Merge one decoded reply into the session.
|
|
31
|
+
*
|
|
32
|
+
* 1. A missing session or another identity starts empty. A `live` reply with no session of its
|
|
33
|
+
* identity is refused `no-session`; a `result` with no sheet and no session sheet `no-sheet`.
|
|
34
|
+
* 2. Rows, `result`: the stored rows inside the reply's window (`fromMs <= ts <= toMs`) are
|
|
35
|
+
* replaced by the reply's rows inside it, order kept.
|
|
36
|
+
* 3. Rows, `live`: the stored rows at or after the reply's first row are replaced by the reply's.
|
|
37
|
+
* 4. Cell rows, per `<kind>:<input>` entry, by the same two rules (a live entry cuts at the
|
|
38
|
+
* earlier of the reply's first row and its own first row). An entry the reply does not carry
|
|
39
|
+
* keeps its rows.
|
|
40
|
+
* 5. Snapshots are accepted when the session starts empty, holds no finite `asOfMs`, or the
|
|
41
|
+
* reply's `asOfMs` is not older; then frames, handles, refusals and `asOfMs` are the reply's
|
|
42
|
+
* (absent means absent), else the session's.
|
|
43
|
+
* 6. Handle bar stamps index the merged rows: a reply's stamp maps through its own row's ts; a
|
|
44
|
+
* negative or unresolved stamp is -1; a missing stamp takes the same id's previous stamp,
|
|
45
|
+
* else the last merged bar. Kept handles are re-based by ts the same way.
|
|
46
|
+
* 7. Above the policy's `maxBars` (default WRUN_HOSTED_SESSION_MAX_BARS) the oldest bars drop,
|
|
47
|
+
* whatever the reply's window. A result page whose rows all fall below the bars kept changes
|
|
48
|
+
* none of the session's bars or cell rows (its snapshots are still judged by rule 5). The
|
|
49
|
+
* socket row source passes WRUN_SOCKET_ROW_STORE_UNCAPPED: nothing drops.
|
|
50
|
+
*/
|
|
51
|
+
export function mergeWrunHostedReply(session, wire, reply, policy = {}) {
|
|
52
|
+
const maxBars = policy.maxBars ?? WRUN_HOSTED_SESSION_MAX_BARS;
|
|
53
|
+
const base = session !== undefined && session.identity === reply.identity ? session : undefined;
|
|
54
|
+
if (reply.kind === 'live' && base === undefined)
|
|
55
|
+
return { refused: 'no-session' };
|
|
56
|
+
const sheet = sheetOf(wire) ?? base?.sheet;
|
|
57
|
+
if (sheet === undefined)
|
|
58
|
+
return { refused: 'no-sheet' };
|
|
59
|
+
const merged = reply.kind === 'result'
|
|
60
|
+
? mergeResultPage(base, wire)
|
|
61
|
+
: mergeLiveTail(base?.rows ?? [], base?.grids ?? new Map(), wire);
|
|
62
|
+
const { rows, grids } = reply.kind === 'result' && base !== undefined && pageBelowCap(wire.rows, merged.rows, maxBars)
|
|
63
|
+
? { rows: [...base.rows], grids: new Map(base.grids) }
|
|
64
|
+
: capBars(merged.rows, merged.grids, maxBars);
|
|
65
|
+
const indexOfTs = rowIndexOfTs(rows);
|
|
66
|
+
const previousRows = base?.rows ?? [];
|
|
67
|
+
const rebase = (stamp) => (stamp < 0 ? -1 : indexOfTs(previousRows[stamp]?.ts));
|
|
68
|
+
const acceptedSnapshots = base === undefined || !Number.isFinite(base.asOfMs) || wire.asOfMs >= base.asOfMs;
|
|
69
|
+
let frames;
|
|
70
|
+
let handles;
|
|
71
|
+
let refusals;
|
|
72
|
+
let asOfMs;
|
|
73
|
+
if (base === undefined || acceptedSnapshots) {
|
|
74
|
+
frames = wire.frames !== undefined ? [...wire.frames] : undefined;
|
|
75
|
+
handles =
|
|
76
|
+
wire.handles !== undefined
|
|
77
|
+
? replyHandles(wire.handles, wire.rows, base?.handles, indexOfTs, rebase, rows.length - 1)
|
|
78
|
+
: undefined;
|
|
79
|
+
refusals = wire.refusals.map((refusal) => ({ ...refusal }));
|
|
80
|
+
asOfMs = wire.asOfMs;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
frames = base.frames;
|
|
84
|
+
handles = base.handles?.map((record) => withStamps(record, rebase(record.createdBar), rebase(record.mutatedBar)));
|
|
85
|
+
refusals = base.refusals;
|
|
86
|
+
asOfMs = base.asOfMs;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
session: {
|
|
90
|
+
identity: reply.identity,
|
|
91
|
+
sheet,
|
|
92
|
+
rows,
|
|
93
|
+
grids,
|
|
94
|
+
...(frames !== undefined ? { frames } : {}),
|
|
95
|
+
...(handles !== undefined ? { handles } : {}),
|
|
96
|
+
refusals,
|
|
97
|
+
asOfMs,
|
|
98
|
+
},
|
|
99
|
+
acceptedSnapshots,
|
|
100
|
+
tailRows: wire.rows.length,
|
|
101
|
+
newBars: barsNewerThan(rows, previousRows[previousRows.length - 1]?.ts),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** The wire's sheet as the app's sheet type. The kit declares the sheet with its own copy of
|
|
105
|
+
* the frozen sheet contract; the app's WrunIndicatorMetadata is the copy every painter reads.
|
|
106
|
+
* The decode already checked the shape (arrays `inputs` and `outputs`, `params` and
|
|
107
|
+
* `inputSources` defaulted). */
|
|
108
|
+
function sheetOf(wire) {
|
|
109
|
+
return wire.sheet;
|
|
110
|
+
}
|
|
111
|
+
/** A grid entry's key in the session (`<kind>:<input>`): a reply's entry merges into the stored entry of its key. */
|
|
112
|
+
export function wrunHostedGridKey(grid) {
|
|
113
|
+
return `${grid.kind}:${grid.input}`;
|
|
114
|
+
}
|
|
115
|
+
function rowTs(row) {
|
|
116
|
+
return row.ts;
|
|
117
|
+
}
|
|
118
|
+
function cellTs(row) {
|
|
119
|
+
return row[0];
|
|
120
|
+
}
|
|
121
|
+
/** Rules 2 and 4 for a result page: splice the reply's window into the stored rows. */
|
|
122
|
+
function mergeResultPage(base, wire) {
|
|
123
|
+
const { fromMs, toMs } = wire.window;
|
|
124
|
+
const rows = spliceWindow(base?.rows ?? [], wire.rows, rowTs, fromMs, toMs);
|
|
125
|
+
const grids = mergeGrids(base?.grids, wire.grids, (stored, incoming) => spliceWindow(stored, incoming, cellTs, fromMs, toMs));
|
|
126
|
+
return { rows, grids };
|
|
127
|
+
}
|
|
128
|
+
/** Rules 3 and 4 for a live tail: replace the stored tail from the reply's first row. */
|
|
129
|
+
function mergeLiveTail(storedRows, storedGrids, wire) {
|
|
130
|
+
const cut = wire.rows[0]?.ts ?? Number.POSITIVE_INFINITY;
|
|
131
|
+
const rows = spliceTail(storedRows, wire.rows, rowTs, cut);
|
|
132
|
+
// A cell entry also cuts at its own first row when that is earlier, so its rows stay ascending.
|
|
133
|
+
const grids = mergeGrids(storedGrids, wire.grids, (stored, incoming) => spliceTail(stored, incoming, cellTs, Math.min(cut, incoming[0]?.[0] ?? Number.POSITIVE_INFINITY)));
|
|
134
|
+
return { rows, grids };
|
|
135
|
+
}
|
|
136
|
+
/** The stored entries in their order with the reply's carried ones merged in, then the reply's
|
|
137
|
+
* new entries. An entry the reply does not carry keeps its rows. */
|
|
138
|
+
function mergeGrids(stored, incoming, splice) {
|
|
139
|
+
const carried = new Map();
|
|
140
|
+
for (const grid of incoming)
|
|
141
|
+
carried.set(wrunHostedGridKey(grid), grid);
|
|
142
|
+
const grids = new Map();
|
|
143
|
+
for (const [key, grid] of stored ?? []) {
|
|
144
|
+
const next = carried.get(key);
|
|
145
|
+
grids.set(key, next !== undefined ? { ...next, rows: splice(grid.rows, next.rows) } : grid);
|
|
146
|
+
}
|
|
147
|
+
for (const [key, next] of carried) {
|
|
148
|
+
if (!grids.has(key))
|
|
149
|
+
grids.set(key, { ...next, rows: splice([], next.rows) });
|
|
150
|
+
}
|
|
151
|
+
return grids;
|
|
152
|
+
}
|
|
153
|
+
/** The stored items before `fromMs`, the incoming items inside `[fromMs, toMs]`, then the stored
|
|
154
|
+
* items after `toMs`: ascending when both lists are. */
|
|
155
|
+
function spliceWindow(stored, incoming, tsOf, fromMs, toMs) {
|
|
156
|
+
const merged = [];
|
|
157
|
+
let at = 0;
|
|
158
|
+
while (at < stored.length && tsOf(stored[at]) < fromMs)
|
|
159
|
+
merged.push(stored[at++]);
|
|
160
|
+
for (const item of incoming) {
|
|
161
|
+
const ts = tsOf(item);
|
|
162
|
+
if (fromMs <= ts && ts <= toMs)
|
|
163
|
+
merged.push(item);
|
|
164
|
+
}
|
|
165
|
+
while (at < stored.length && tsOf(stored[at]) <= toMs)
|
|
166
|
+
at += 1;
|
|
167
|
+
while (at < stored.length)
|
|
168
|
+
merged.push(stored[at++]);
|
|
169
|
+
return merged;
|
|
170
|
+
}
|
|
171
|
+
/** The stored items before `cut`, then every incoming item (the live tick's own tail rule,
|
|
172
|
+
* walking back from the end). */
|
|
173
|
+
function spliceTail(stored, incoming, tsOf, cut) {
|
|
174
|
+
let keep = stored.length;
|
|
175
|
+
while (keep > 0 && tsOf(stored[keep - 1]) >= cut)
|
|
176
|
+
keep -= 1;
|
|
177
|
+
const merged = stored.slice(0, keep);
|
|
178
|
+
for (const item of incoming)
|
|
179
|
+
merged.push(item);
|
|
180
|
+
return merged;
|
|
181
|
+
}
|
|
182
|
+
/** Rule 7: above the cap the oldest bars go, and the cell rows older than the first bar kept. The
|
|
183
|
+
* newest bars always stay, whichever side the reply sits on: dropping them for a pan-back page
|
|
184
|
+
* would leave the next live tail appended after a gap. */
|
|
185
|
+
function capBars(rows, grids, maxBars) {
|
|
186
|
+
if (rows.length <= maxBars)
|
|
187
|
+
return { rows, grids };
|
|
188
|
+
const kept = rows.slice(rows.length - maxBars);
|
|
189
|
+
const firstTs = kept[0].ts;
|
|
190
|
+
const trimmed = new Map();
|
|
191
|
+
for (const [key, grid] of grids) {
|
|
192
|
+
trimmed.set(key, { ...grid, rows: grid.rows.filter((row) => row[0] >= firstTs) });
|
|
193
|
+
}
|
|
194
|
+
return { rows: kept, grids: trimmed };
|
|
195
|
+
}
|
|
196
|
+
/** True when the merge runs over the cap and every row of the page is older than the bars the cap
|
|
197
|
+
* keeps: such a page would only have taken stored bars out of its window, so the session keeps
|
|
198
|
+
* its bars and cell rows as they were. */
|
|
199
|
+
function pageBelowCap(pageRows, mergedRows, maxBars) {
|
|
200
|
+
if (mergedRows.length <= maxBars)
|
|
201
|
+
return false;
|
|
202
|
+
const firstKeptTs = mergedRows[mergedRows.length - maxBars].ts;
|
|
203
|
+
return pageRows.every((row) => row.ts < firstKeptTs);
|
|
204
|
+
}
|
|
205
|
+
/** The merged index of a bar by its ts (binary search over ascending rows), -1 when absent. */
|
|
206
|
+
function rowIndexOfTs(rows) {
|
|
207
|
+
return (ts) => {
|
|
208
|
+
if (ts === undefined || !Number.isFinite(ts))
|
|
209
|
+
return -1;
|
|
210
|
+
let low = 0;
|
|
211
|
+
let high = rows.length - 1;
|
|
212
|
+
while (low <= high) {
|
|
213
|
+
const mid = (low + high) >> 1;
|
|
214
|
+
const at = rows[mid].ts;
|
|
215
|
+
if (at === ts)
|
|
216
|
+
return mid;
|
|
217
|
+
if (at < ts)
|
|
218
|
+
low = mid + 1;
|
|
219
|
+
else
|
|
220
|
+
high = mid - 1;
|
|
221
|
+
}
|
|
222
|
+
return -1;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** Rule 6 for the reply's handles: stamps re-based from the reply's rows onto the merged rows. */
|
|
226
|
+
function replyHandles(handles, replyRows, previous, indexOfTs, rebase, lastIndex) {
|
|
227
|
+
const previousById = new Map();
|
|
228
|
+
for (const record of previous ?? [])
|
|
229
|
+
previousById.set(record.id, record);
|
|
230
|
+
const stampOf = (stamp, previousStamp) => {
|
|
231
|
+
if (typeof stamp === 'number' && Number.isFinite(stamp)) {
|
|
232
|
+
return stamp < 0 ? -1 : indexOfTs(replyRows[stamp]?.ts);
|
|
233
|
+
}
|
|
234
|
+
return previousStamp !== undefined ? rebase(previousStamp) : lastIndex;
|
|
235
|
+
};
|
|
236
|
+
return handles.map((record) => {
|
|
237
|
+
const before = previousById.get(record.id);
|
|
238
|
+
// A stamp can arrive missing or null although the kit types it as a number (a live frame
|
|
239
|
+
// carries none; JSON writes a NaN stamp as null).
|
|
240
|
+
const stamps = record;
|
|
241
|
+
return withStamps(record, stampOf(stamps.createdBar, before?.createdBar), stampOf(stamps.mutatedBar, before?.mutatedBar));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/** A copy of a handle record with its bar stamps replaced, as the app's record type (the kit
|
|
245
|
+
* declares the same wire record with its own copy of the props). */
|
|
246
|
+
function withStamps(record, createdBar, mutatedBar) {
|
|
247
|
+
return { ...record, createdBar, mutatedBar };
|
|
248
|
+
}
|
|
249
|
+
/** How many rows are newer than `previousLastTs` (every row when there was none). */
|
|
250
|
+
function barsNewerThan(rows, previousLastTs) {
|
|
251
|
+
if (previousLastTs === undefined)
|
|
252
|
+
return rows.length;
|
|
253
|
+
let count = 0;
|
|
254
|
+
for (let at = rows.length - 1; at >= 0 && rows[at].ts > previousLastTs; at -= 1)
|
|
255
|
+
count += 1;
|
|
256
|
+
return count;
|
|
257
|
+
}
|
|
258
|
+
// ── Cell rows: the session's grids in the shapes the price canvases read ───────────────────────
|
|
259
|
+
/**
|
|
260
|
+
* A hosted run has no lane buffers: the cloud sends each celled input's rows as the module read them,
|
|
261
|
+
* `[ts, ...tuples]` in the host contract order, and these become the `WrunCellRows` an own run hands
|
|
262
|
+
* to wrunHeatmapChildren and wrunProfileChildren (wrun-canvases.util), so both lanes paint through
|
|
263
|
+
* the same builders (wrun-browser-runtime.md, "Cell rows and the cells memo"):
|
|
264
|
+
*
|
|
265
|
+
* - book `[ts, price, size, side, ...]` (size absolute, side +1 bid and -1 ask) becomes the book
|
|
266
|
+
* lane's `[ts, price, side * size, ...]` (asks negative). Zero-size levels stay.
|
|
267
|
+
* - volume_profile `[ts, low, high, buy, sell, ...]` becomes `[ts, [low, high, buy, sell], ...]`,
|
|
268
|
+
* the nested buckets the footprint hands to the engine as they are.
|
|
269
|
+
* - intrabar `[ts, offset_ms, open, high, low, close, volume, ...]` becomes the leg's candles
|
|
270
|
+
* `[ts + offset_ms, open, high, low, close, volume]`, one flat ascending list per input.
|
|
271
|
+
*
|
|
272
|
+
* Tuples step by the entry's own `width`; a trailing incomplete tuple is dropped.
|
|
273
|
+
*/
|
|
274
|
+
/** The leading columns each conversion reads from one tuple. */
|
|
275
|
+
const BOOK_COLUMNS = 3;
|
|
276
|
+
const PROFILE_COLUMNS = 4;
|
|
277
|
+
const INTRABAR_COLUMNS = 6;
|
|
278
|
+
/**
|
|
279
|
+
* The canvases' cell rows from the session's grid entries: the first `cells` entry of class
|
|
280
|
+
* `book` is the book lane, the first of class `volume_profile` the profile lane, every
|
|
281
|
+
* `intrabar` entry its input's candles (the lowest input index also `intrabarRows`, its interval
|
|
282
|
+
* from the sheet's pin when the interval table knows the word), and the chart's own candles
|
|
283
|
+
* `ohlcvRows`. Any other entry is ignored. Pure: rows are read, never written.
|
|
284
|
+
*/
|
|
285
|
+
export function wrunCellRowsFromHostedGrids(sheet, grids, chartCandles) {
|
|
286
|
+
return wrunCellRowsFromHostedLanes(sheet, grids, (grid) => wrunHostedGridLaneRows(grid), chartCandles);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The same cell rows with each entry's lane rows from `laneOf`, asked only for the entries the
|
|
290
|
+
* canvases read: the whole conversion converts them (`wrunHostedGridLaneRows`), the socket row
|
|
291
|
+
* source answers the ones its cells memo kept (`SocketWrunRowSource.cellRows`).
|
|
292
|
+
*/
|
|
293
|
+
export function wrunCellRowsFromHostedLanes(sheet, grids, laneOf, chartCandles) {
|
|
294
|
+
const cellRows = {};
|
|
295
|
+
let book;
|
|
296
|
+
let profile;
|
|
297
|
+
const intrabar = [];
|
|
298
|
+
for (const grid of grids.values()) {
|
|
299
|
+
if (grid.kind === 'cells') {
|
|
300
|
+
if (grid.class === 'book')
|
|
301
|
+
book ??= grid;
|
|
302
|
+
else if (grid.class === 'volume_profile')
|
|
303
|
+
profile ??= grid;
|
|
304
|
+
}
|
|
305
|
+
else if (grid.kind === 'intrabar') {
|
|
306
|
+
intrabar.push(grid);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (book !== undefined)
|
|
310
|
+
cellRows.bookRows = laneOf(book);
|
|
311
|
+
if (profile !== undefined)
|
|
312
|
+
cellRows.volumeProfileRows = laneOf(profile);
|
|
313
|
+
if (chartCandles !== undefined)
|
|
314
|
+
cellRows.ohlcvRows = chartCandles;
|
|
315
|
+
if (intrabar.length > 0) {
|
|
316
|
+
const byInput = {};
|
|
317
|
+
const intervalByInput = {};
|
|
318
|
+
let first;
|
|
319
|
+
for (const grid of intrabar) {
|
|
320
|
+
const candles = laneOf(grid);
|
|
321
|
+
byInput[grid.input] = candles;
|
|
322
|
+
const intervalMs = intervalMsOf(sheet.inputSources?.[grid.input]?.interval);
|
|
323
|
+
if (intervalMs !== undefined)
|
|
324
|
+
intervalByInput[grid.input] = intervalMs;
|
|
325
|
+
const index = sheet.inputs.find((input) => input.name === grid.input)?.index ?? Number.POSITIVE_INFINITY;
|
|
326
|
+
if (first === undefined || index < first.index)
|
|
327
|
+
first = { index, candles };
|
|
328
|
+
}
|
|
329
|
+
if (first !== undefined)
|
|
330
|
+
cellRows.intrabarRows = first.candles;
|
|
331
|
+
cellRows.intrabarRowsByInput = byInput;
|
|
332
|
+
cellRows.intrabarIntervalMsByInput = intervalByInput;
|
|
333
|
+
}
|
|
334
|
+
return cellRows;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* The lane rows of an entry's rows `[from, to)` (default all), in row order: a book row's
|
|
338
|
+
* `[ts, price, side * size, ...]` and a volume_profile row's `[ts, [low, high, buy, sell], ...]`
|
|
339
|
+
* (one each), an intrabar row's candles (one per timed tuple). Fresh rows; none for another class.
|
|
340
|
+
*/
|
|
341
|
+
export function wrunHostedGridLaneRows(grid, from = 0, to = grid.rows.length) {
|
|
342
|
+
const lane = [];
|
|
343
|
+
const { rows, width } = grid;
|
|
344
|
+
if (grid.kind === 'intrabar') {
|
|
345
|
+
for (let index = from; index < to; index += 1)
|
|
346
|
+
pushIntrabarCandles(lane, rows[index], width);
|
|
347
|
+
}
|
|
348
|
+
else if (grid.class === 'book') {
|
|
349
|
+
for (let index = from; index < to; index += 1)
|
|
350
|
+
lane.push(bookLaneRow(rows[index], width));
|
|
351
|
+
}
|
|
352
|
+
else if (grid.class === 'volume_profile') {
|
|
353
|
+
for (let index = from; index < to; index += 1)
|
|
354
|
+
lane.push(profileLaneRow(rows[index], width));
|
|
355
|
+
}
|
|
356
|
+
return lane;
|
|
357
|
+
}
|
|
358
|
+
/** How many lane rows `wrunHostedGridLaneRows(grid, from, to)` answers, converting none: one per
|
|
359
|
+
* book or volume_profile row, one per timed tuple of an intrabar row. */
|
|
360
|
+
export function wrunHostedGridLaneRowCount(grid, from = 0, to = grid.rows.length) {
|
|
361
|
+
if (grid.kind !== 'intrabar')
|
|
362
|
+
return grid.class === 'book' || grid.class === 'volume_profile' ? to - from : 0;
|
|
363
|
+
let count = 0;
|
|
364
|
+
for (let index = from; index < to; index += 1)
|
|
365
|
+
count += timedIntrabarTuples(grid.rows[index], grid.width);
|
|
366
|
+
return count;
|
|
367
|
+
}
|
|
368
|
+
/** An interval word's milliseconds from the chart's interval table (`wrunChartIntervalMsOf`'s read). */
|
|
369
|
+
function intervalMsOf(interval) {
|
|
370
|
+
if (typeof interval !== 'string')
|
|
371
|
+
return undefined;
|
|
372
|
+
const ms = Intervals.map_unit[interval];
|
|
373
|
+
return typeof ms === 'number' && Number.isFinite(ms) && ms > 0 ? ms : undefined;
|
|
374
|
+
}
|
|
375
|
+
/** `[ts, price, size, side, ...]` to `[ts, price, side * size, ...]`. */
|
|
376
|
+
function bookLaneRow(row, width) {
|
|
377
|
+
const lane = [row[0]];
|
|
378
|
+
if (width < BOOK_COLUMNS)
|
|
379
|
+
return lane;
|
|
380
|
+
for (let at = 1; at + width <= row.length; at += width) {
|
|
381
|
+
lane.push(row[at], row[at + 2] * row[at + 1]);
|
|
382
|
+
}
|
|
383
|
+
return lane;
|
|
384
|
+
}
|
|
385
|
+
/** `[ts, low, high, buy, sell, ...]` to `[ts, [low, high, buy, sell], ...]`. */
|
|
386
|
+
function profileLaneRow(row, width) {
|
|
387
|
+
const lane = [row[0]];
|
|
388
|
+
if (width < PROFILE_COLUMNS)
|
|
389
|
+
return lane;
|
|
390
|
+
for (let at = 1; at + width <= row.length; at += width) {
|
|
391
|
+
lane.push([row[at], row[at + 1], row[at + 2], row[at + 3]]);
|
|
392
|
+
}
|
|
393
|
+
return lane;
|
|
394
|
+
}
|
|
395
|
+
/** A row's `[offset_ms, o, h, l, c, v]` tuples as candles `[ts + offset_ms, o, h, l, c, v]`, onto
|
|
396
|
+
* `lane` in order (ascending: a row's finer candles open inside its own bar, offsets ascending).
|
|
397
|
+
* A tuple whose offset is not finite has no time and is skipped. */
|
|
398
|
+
function pushIntrabarCandles(lane, row, width) {
|
|
399
|
+
if (width < INTRABAR_COLUMNS)
|
|
400
|
+
return;
|
|
401
|
+
for (let at = 1; at + width <= row.length; at += width) {
|
|
402
|
+
const offset = row[at];
|
|
403
|
+
if (!Number.isFinite(offset))
|
|
404
|
+
continue;
|
|
405
|
+
lane.push([row[0] + offset, row[at + 1], row[at + 2], row[at + 3], row[at + 4], row[at + 5]]);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** How many candles `pushIntrabarCandles` makes of a row: its timed tuples. */
|
|
409
|
+
function timedIntrabarTuples(row, width) {
|
|
410
|
+
if (width < INTRABAR_COLUMNS)
|
|
411
|
+
return 0;
|
|
412
|
+
let count = 0;
|
|
413
|
+
for (let at = 1; at + width <= row.length; at += width)
|
|
414
|
+
if (Number.isFinite(row[at]))
|
|
415
|
+
count += 1;
|
|
416
|
+
return count;
|
|
417
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FE-only flags the settings seam writes onto a wrun declaration (never
|
|
3
|
+
* honoured from a published sheet: the seam sets or drops them on every
|
|
4
|
+
* paint), read by the builders that paint it. A leaf on purpose: the seam
|
|
5
|
+
* (wrun-color-settings.util, main thread) writes them and the levels child
|
|
6
|
+
* (wrun-levels-child.util, worker and main thread alike) reads them, so
|
|
7
|
+
* neither pulls the other's graph in.
|
|
8
|
+
*/
|
|
9
|
+
/** Set beside a docked level's `color` when the settings moved it away from
|
|
10
|
+
* the published declaration's colour (`levelColorPickedWrites`): the levels
|
|
11
|
+
* child then paints every row with the pick and leaves aside what would
|
|
12
|
+
* paint over it, the frame's per-row colours, the `gradient` stops with
|
|
13
|
+
* their `gradient_direction` and an outline's `border_color` (a bars-shape
|
|
14
|
+
* border only frames the fill and stays), so the colour row the dialog
|
|
15
|
+
* offers always does something. */
|
|
16
|
+
export declare const WRUN_LEVELS_COLOR_PICKED_KEY = "color_picked";
|
|
17
|
+
/** True when the level's colour was set away from its declaration. */
|
|
18
|
+
export declare function isWrunLevelsColorPicked(declaration: unknown): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FE-only flags the settings seam writes onto a wrun declaration (never
|
|
3
|
+
* honoured from a published sheet: the seam sets or drops them on every
|
|
4
|
+
* paint), read by the builders that paint it. A leaf on purpose: the seam
|
|
5
|
+
* (wrun-color-settings.util, main thread) writes them and the levels child
|
|
6
|
+
* (wrun-levels-child.util, worker and main thread alike) reads them, so
|
|
7
|
+
* neither pulls the other's graph in.
|
|
8
|
+
*/
|
|
9
|
+
import { isRecord } from '../chart/kscript-run-result-shape.util.js';
|
|
10
|
+
/** Set beside a docked level's `color` when the settings moved it away from
|
|
11
|
+
* the published declaration's colour (`levelColorPickedWrites`): the levels
|
|
12
|
+
* child then paints every row with the pick and leaves aside what would
|
|
13
|
+
* paint over it, the frame's per-row colours, the `gradient` stops with
|
|
14
|
+
* their `gradient_direction` and an outline's `border_color` (a bars-shape
|
|
15
|
+
* border only frames the fill and stays), so the colour row the dialog
|
|
16
|
+
* offers always does something. */
|
|
17
|
+
export const WRUN_LEVELS_COLOR_PICKED_KEY = 'color_picked';
|
|
18
|
+
/** True when the level's colour was set away from its declaration. */
|
|
19
|
+
export function isWrunLevelsColorPicked(declaration) {
|
|
20
|
+
return isRecord(declaration) && declaration[WRUN_LEVELS_COLOR_PICKED_KEY] === true;
|
|
21
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app half of the wrun styling vocabulary (WRUN-STYLE freeze, section
|
|
3
|
+
* 2.3): the colour words and theme tokens every colour key accepts and their
|
|
4
|
+
* paint-time resolution against the chart's theme, the font words with their
|
|
5
|
+
* CSS stacks, the one number formatter every surface prints a declared number
|
|
6
|
+
* with (the freeze's 2.2 text, pinned by
|
|
7
|
+
* tests/fixtures/wrun/wrun-value-format-corpus.json, byte-identical to the om
|
|
8
|
+
* corpus), and the theme-token packing every host restates (the draw ABI
|
|
9
|
+
* sentinel, the wire text, the packed f64 form).
|
|
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
|
|
13
|
+
* wrun-value-format.ts; the two sides must agree on every word and byte.
|
|
14
|
+
*
|
|
15
|
+
* Theme tokens ride sheets, wire props and run outputs unresolved; they
|
|
16
|
+
* resolve at the mount doors with `resolveWrunColorWord(word,
|
|
17
|
+
* wrunColorThemeOf(tc))` and re-resolve on a theme switch without a rerun
|
|
18
|
+
* (`onWrunThemeChange`).
|
|
19
|
+
*/
|
|
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"];
|
|
23
|
+
export type WrunThemeColorToken = (typeof WRUN_THEME_COLOR_TOKENS)[number];
|
|
24
|
+
/** A theme token with its alpha (0..1). */
|
|
25
|
+
export interface WrunThemeTokenRef {
|
|
26
|
+
token: WrunThemeColorToken;
|
|
27
|
+
alpha: number;
|
|
28
|
+
}
|
|
29
|
+
/** 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
|
|
31
|
+
* other `theme.` word and every non-string are not colour words. */
|
|
32
|
+
export declare function isWrunColorWord(value: unknown): value is string;
|
|
33
|
+
/** The token a string names: `theme.<t>` (alpha 1) or the wire's
|
|
34
|
+
* `theme.<t>/aa` (alpha = the byte / 255); null for anything else. */
|
|
35
|
+
export declare function parseWrunThemeToken(value: unknown): WrunThemeTokenRef | null;
|
|
36
|
+
/** The wire word of a token: `theme.<t>` when its alpha byte is 255, else
|
|
37
|
+
* `theme.<t>/aa` (two lowercase hex digits). Alpha is clamped to 0..1; a
|
|
38
|
+
* non-finite alpha reads as 1. */
|
|
39
|
+
export declare function wrunThemeTokenWord(ref: WrunThemeTokenRef): string;
|
|
40
|
+
/** REPLACES a token's alpha with `alpha` (the `withOpacity` rule, the
|
|
41
|
+
* kScript opacity() convention): `theme.up/80` at 0.2 is `theme.up/33`.
|
|
42
|
+
* Alpha is clamped to 0..1. A non-token string and a non-finite alpha come
|
|
43
|
+
* back unchanged. */
|
|
44
|
+
export declare function wrunThemeTokenWithAlpha(value: string, alpha: number): string;
|
|
45
|
+
/** MULTIPLIES a token's alpha by `factor` (the `multiplyWrunOpacity` rule,
|
|
46
|
+
* conventions 3): `theme.up` at 0.5 is `theme.up/80`, `theme.up/80` at 0.5
|
|
47
|
+
* is `theme.up/40`. The product is clamped to 0..1. A non-token string and
|
|
48
|
+
* a non-finite factor come back unchanged. */
|
|
49
|
+
export declare function wrunThemeTokenScaleAlpha(value: string, factor: number): string;
|
|
50
|
+
/** The seven palette colours a chart's theme answers a token with, as CSS
|
|
51
|
+
* colour strings. */
|
|
52
|
+
export interface WrunColorTheme {
|
|
53
|
+
up: string;
|
|
54
|
+
down: string;
|
|
55
|
+
text: string;
|
|
56
|
+
muted: string;
|
|
57
|
+
bg: string;
|
|
58
|
+
grid: string;
|
|
59
|
+
accent: string;
|
|
60
|
+
}
|
|
61
|
+
/** The palette of a chart (`tc`, feature-detected: a bare test double or a
|
|
62
|
+
* pin without a theme answers the dark defaults): up and down from the
|
|
63
|
+
* candle colours, text from the x axis font colour, muted = text at alpha
|
|
64
|
+
* x 0.55, bg and grid from the theme, accent from `noteWrunThemeApplied`
|
|
65
|
+
* (fallback '#ff4608'). */
|
|
66
|
+
export declare function wrunColorThemeOf(tc: unknown): WrunColorTheme;
|
|
67
|
+
/** Records the accent colour of a theme apply for `tc` (a WeakMap, so a
|
|
68
|
+
* disposed chart leaves nothing behind), then tells every
|
|
69
|
+
* `onWrunThemeChange` listener the chart's palette may have moved. Called
|
|
70
|
+
* by applyChartTheme after every apply; a listener that throws is logged
|
|
71
|
+
* and never stops the others or the apply. */
|
|
72
|
+
export declare function noteWrunThemeApplied(tc: object, accent: string): void;
|
|
73
|
+
/** Subscribes to theme applies (the HUD re-resolves its tokens here); the
|
|
74
|
+
* returned function unsubscribes. */
|
|
75
|
+
export declare function onWrunThemeChange(listener: (tc: object) => void): () => void;
|
|
76
|
+
/** Resolves a colour word against a palette: a token (with or without the
|
|
77
|
+
* `/aa` alpha) becomes the palette colour with alpha = palette alpha x
|
|
78
|
+
* token alpha, `#rrggbb` (lowercase) when that rounds to 1, else
|
|
79
|
+
* `rgba(r, g, b, a)`. A palette colour the parser cannot read comes back
|
|
80
|
+
* as the palette wrote it; any non-token string comes back unchanged. */
|
|
81
|
+
export declare function resolveWrunColorWord(word: string, theme: WrunColorTheme): string;
|
|
82
|
+
/** `#rrggbbaa` as `rgba(r, g, b, a)` (a = the byte / 255 at three decimals)
|
|
83
|
+
* for consumers that cannot read 8-digit hex (the domain panes); every
|
|
84
|
+
* other string comes back unchanged. */
|
|
85
|
+
export declare function wrunHex8ToRgba(color: string): string;
|
|
86
|
+
/** The four font families; each maps to a system stack below, never a
|
|
87
|
+
* downloaded font (`ui` is the app font). */
|
|
88
|
+
export declare const WRUN_FONT_FAMILIES: readonly ["ui", "mono", "serif", "rounded"];
|
|
89
|
+
export type WrunFontFamily = (typeof WRUN_FONT_FAMILIES)[number];
|
|
90
|
+
export declare const WRUN_FONT_WEIGHTS: readonly ["normal", "medium", "bold"];
|
|
91
|
+
export type WrunFontWeight = (typeof WRUN_FONT_WEIGHTS)[number];
|
|
92
|
+
/** The CSS stack of each font word (frozen, 2.3). */
|
|
93
|
+
export declare const WRUN_FONT_FAMILY_CSS: Readonly<Record<WrunFontFamily, string>>;
|
|
94
|
+
/** A font word's CSS stack; anything that is not one of the four words is
|
|
95
|
+
* undefined (the caller keeps its default). */
|
|
96
|
+
export declare function wrunFontFamilyCss(word: unknown): string | undefined;
|
|
97
|
+
/** A weight word's CSS weight: normal 400, medium 500, bold 700; anything
|
|
98
|
+
* else is undefined. */
|
|
99
|
+
export declare function wrunFontWeightCss(word: unknown): 400 | 500 | 700 | undefined;
|
|
100
|
+
/** Value formats for legend entries, tooltips, HUD tiles, hover blocks,
|
|
101
|
+
* panels, levels, panes and widgets: "price" (the market's precision),
|
|
102
|
+
* "%" (percent), "si" (K / M / B / T suffixes), "int", a fixed decimal
|
|
103
|
+
* count, "usd" (compact with a $ sign) or "auto" (6 significant digits
|
|
104
|
+
* with "," thousands). */
|
|
105
|
+
export declare const WRUN_VALUE_FORMATS: readonly ["price", "%", "si", "int", "0", "0.0", "0.00", "0.000", "usd", "auto"];
|
|
106
|
+
export type WrunValueFormat = (typeof WRUN_VALUE_FORMATS)[number];
|
|
107
|
+
/** Card rows and the card headline also take "pct" (the value x 100 as a
|
|
108
|
+
* percent). */
|
|
109
|
+
export declare const WRUN_CARD_VALUE_FORMATS: readonly ["price", "%", "si", "int", "0", "0.0", "0.00", "0.000", "usd", "auto", "pct"];
|
|
110
|
+
export type WrunCardValueFormat = (typeof WRUN_CARD_VALUE_FORMATS)[number];
|
|
111
|
+
/** Bounds on the format companions: `decimals` 0..8, `unit` 0..8 chars. */
|
|
112
|
+
export declare const WRUN_MAX_VALUE_DECIMALS = 8;
|
|
113
|
+
export declare const WRUN_MAX_VALUE_UNIT_CHARS = 8;
|
|
114
|
+
/** What a surface declares for one printed number. `priceDigits` is the
|
|
115
|
+
* chart's price precision (or a pane's step digits), used by "price". Every
|
|
116
|
+
* field also takes undefined so a parsed sheet entry passes as is. */
|
|
117
|
+
export interface WrunNumberFormatSpec {
|
|
118
|
+
format?: string | undefined;
|
|
119
|
+
decimals?: number | undefined;
|
|
120
|
+
signed?: boolean | undefined;
|
|
121
|
+
unit?: string | undefined;
|
|
122
|
+
priceDigits?: number | undefined;
|
|
123
|
+
}
|
|
124
|
+
/** Prints one number the way its surface declared (format, decimals,
|
|
125
|
+
* signed, unit, priceDigits). Without a format: today's card text
|
|
126
|
+
* (`String(Number(value.toPrecision(6)))`) when no companion is declared,
|
|
127
|
+
* else "auto". Non-finite prints "" (the caller prints its own hole mark).
|
|
128
|
+
* Byte-identical to the om twin: tests/fixtures/wrun/wrun-value-format-corpus.json. */
|
|
129
|
+
export declare function formatWrunNumber(value: number, spec?: WrunNumberFormatSpec): string;
|
|
130
|
+
/** The draw ABI's theme token sentinel: a `wrun_draw_color` rgba whose
|
|
131
|
+
* alpha byte is 0x00, red byte 0x7e and green byte k in 1..7 is token k of
|
|
132
|
+
* {@link WRUN_THEME_COLOR_TOKENS} with its alpha in the blue byte. Every
|
|
133
|
+
* other value is a plain colour. */
|
|
134
|
+
export declare const WRUN3_THEME_TOKEN_MARKER = 126;
|
|
135
|
+
/** Decodes the draw ABI sentinel (`0xRRGGBBAA` as an i32 or u32): a token
|
|
136
|
+
* when the alpha byte is 0, the red byte the marker and the green byte in
|
|
137
|
+
* 1..7, else null (a plain colour, exactly as before the sentinel). */
|
|
138
|
+
export declare function wrunThemeTokenOfI32(rgba: number): WrunThemeTokenRef | null;
|
|
139
|
+
/** The wire colour of a `wrun_draw_color` rgba: a token's word, else
|
|
140
|
+
* today's `rgba(r,g,b,a)` text (no spaces, alpha at three decimals). */
|
|
141
|
+
export declare function wrunDrawColorWire(rgba: number): string;
|
|
142
|
+
/** The packed f64 form of a token (`*_packed_by` outputs, colour params):
|
|
143
|
+
* `-(k * 1024 + round(alpha * 1000))`, a negative integer no colour ever
|
|
144
|
+
* packed to. Alpha is clamped to 0..1. */
|
|
145
|
+
export declare function wrunPackedThemeToken(ref: WrunThemeTokenRef): number;
|
|
146
|
+
/** Decodes a packed colour: a finite negative integer whose k lands in 1..7
|
|
147
|
+
* and whose alpha part is at most 1000 is a token, anything else null. */
|
|
148
|
+
export declare function wrunThemeTokenOfPacked(value: number): WrunThemeTokenRef | null;
|