@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,413 @@
|
|
|
1
|
+
export const OM_WIDGET_MAX_ROWS = 12;
|
|
2
|
+
const OM_WIDGET_MAX_LADDER_ROWS = 64;
|
|
3
|
+
const OM_WIDGET_MAX_FEED_LINES = 50;
|
|
4
|
+
const OM_WIDGET_MAX_SPARK_POINTS = 64;
|
|
5
|
+
const OM_WIDGET_MAX_DRAWING_ITEMS = 256;
|
|
6
|
+
const OM_WIDGET_MAX_DRAWING_POINTS = 64;
|
|
7
|
+
export const OM_WIDGET_MAX_BYTES = 32 * 1024;
|
|
8
|
+
export const OM_WIDGET_MAX_PER_PANE = 8;
|
|
9
|
+
export const MAX_PANES = 64;
|
|
10
|
+
export const OM_WIDGET_PAYLOAD_ID_PATTERN = /^omwg:c(0|[1-9][0-9]?):[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
11
|
+
const WIDGET_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
12
|
+
const COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;
|
|
13
|
+
const ANCHORS = new Set([
|
|
14
|
+
'top_left',
|
|
15
|
+
'top_center',
|
|
16
|
+
'top_right',
|
|
17
|
+
'middle_left',
|
|
18
|
+
'middle_center',
|
|
19
|
+
'middle_right',
|
|
20
|
+
'bottom_left',
|
|
21
|
+
'bottom_center',
|
|
22
|
+
'bottom_right',
|
|
23
|
+
]);
|
|
24
|
+
const DRAWING_ANCHORS = new Set([...ANCHORS, 'top', 'bottom', 'left', 'right']);
|
|
25
|
+
const FRAME_KEYS = new Set(['chartIndex', 'payloadId', 'revision', 'clear', 'widget', 'source']);
|
|
26
|
+
const CLEAR_KEYS = new Set(['chartIndex', 'payloadId', 'revision', 'clear']);
|
|
27
|
+
const WIDGET_KEYS = {
|
|
28
|
+
card: new Set(['kind', 'id', 'title', 'state', 'anchor', 'offset', 'z', 'rows']),
|
|
29
|
+
ladder: new Set(['kind', 'id', 'title', 'side', 'divider', 'rows']),
|
|
30
|
+
feed: new Set(['kind', 'id', 'title', 'anchor', 'offset', 'z', 'lines']),
|
|
31
|
+
meter: new Set(['kind', 'id', 'title', 'anchor', 'offset', 'z', 'label', 'fraction', 'ramp', 'text']),
|
|
32
|
+
drawings: new Set(['kind', 'id', 'title', 'items']),
|
|
33
|
+
};
|
|
34
|
+
const DRAWING_ITEM_KEYS = {
|
|
35
|
+
line: new Set(['kind', 'anchor', 'x1', 'y1', 'x2', 'y2', 'color', 'width', 'style']),
|
|
36
|
+
box: new Set([
|
|
37
|
+
'kind',
|
|
38
|
+
'anchor',
|
|
39
|
+
'x1',
|
|
40
|
+
'y1',
|
|
41
|
+
'x2',
|
|
42
|
+
'y2',
|
|
43
|
+
'color',
|
|
44
|
+
'border',
|
|
45
|
+
'border_width',
|
|
46
|
+
'text',
|
|
47
|
+
'text_color',
|
|
48
|
+
'text_size',
|
|
49
|
+
]),
|
|
50
|
+
label: new Set(['kind', 'anchor', 'x', 'y', 'text', 'color', 'size', 'align']),
|
|
51
|
+
marker: new Set(['kind', 'anchor', 'x', 'y', 'shape', 'size', 'color']),
|
|
52
|
+
polyline: new Set(['kind', 'anchor', 'points', 'color', 'width']),
|
|
53
|
+
};
|
|
54
|
+
const ROW_KEYS = new Set(['label', 'value', 'color', 'countdown_to', 'clock', 'spark']);
|
|
55
|
+
const DIVIDER_KEYS = new Set(['label', 'price']);
|
|
56
|
+
const SOURCE_KEYS = new Set(['kind', 'ref', 'computedAtMs']);
|
|
57
|
+
export function isWidgetClearFrame(frame) {
|
|
58
|
+
return frame.clear === true;
|
|
59
|
+
}
|
|
60
|
+
function isRecord(value) {
|
|
61
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function isBoundedString(value, max, min = 1) {
|
|
64
|
+
return typeof value === 'string' && value.length >= min && value.length <= max;
|
|
65
|
+
}
|
|
66
|
+
function isInteger(value) {
|
|
67
|
+
return typeof value === 'number' && Number.isSafeInteger(value);
|
|
68
|
+
}
|
|
69
|
+
function isNonnegativeInteger(value) {
|
|
70
|
+
return isInteger(value) && value >= 0;
|
|
71
|
+
}
|
|
72
|
+
function isFiniteNumber(value) {
|
|
73
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
74
|
+
}
|
|
75
|
+
function isColor(value) {
|
|
76
|
+
return typeof value === 'string' && COLOR_PATTERN.test(value);
|
|
77
|
+
}
|
|
78
|
+
function isFraction(value) {
|
|
79
|
+
return isFiniteNumber(value) && value >= 0 && value <= 1;
|
|
80
|
+
}
|
|
81
|
+
function isSpark(value) {
|
|
82
|
+
return (Array.isArray(value) &&
|
|
83
|
+
value.length >= 1 &&
|
|
84
|
+
value.length <= OM_WIDGET_MAX_SPARK_POINTS &&
|
|
85
|
+
Array.from(value).every(isFiniteNumber));
|
|
86
|
+
}
|
|
87
|
+
function parseDrawingItem(value) {
|
|
88
|
+
if (!isRecord(value))
|
|
89
|
+
return { ok: false, rejectReason: 'invalid drawing item' };
|
|
90
|
+
const kind = value.kind;
|
|
91
|
+
if (kind !== 'line' && kind !== 'box' && kind !== 'label' && kind !== 'marker' && kind !== 'polyline') {
|
|
92
|
+
return { ok: false, rejectReason: 'invalid item.kind' };
|
|
93
|
+
}
|
|
94
|
+
if (Object.keys(value).some((key) => !DRAWING_ITEM_KEYS[kind].has(key))) {
|
|
95
|
+
return { ok: false, rejectReason: 'unknown item key' };
|
|
96
|
+
}
|
|
97
|
+
if (value.anchor !== undefined && (typeof value.anchor !== 'string' || !DRAWING_ANCHORS.has(value.anchor))) {
|
|
98
|
+
return { ok: false, rejectReason: 'invalid item.anchor' };
|
|
99
|
+
}
|
|
100
|
+
for (const field of ['color', 'border', 'text_color']) {
|
|
101
|
+
if (value[field] !== undefined && !isColor(value[field])) {
|
|
102
|
+
return { ok: false, rejectReason: `invalid item.${field}` };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const [field, min, max] of [
|
|
106
|
+
['width', 1, 10],
|
|
107
|
+
['border_width', 0, 10],
|
|
108
|
+
['size', kind === 'marker' ? 2 : 8, kind === 'marker' ? 40 : 48],
|
|
109
|
+
['text_size', 8, 48],
|
|
110
|
+
]) {
|
|
111
|
+
const number = value[field];
|
|
112
|
+
if (number !== undefined && (!isFiniteNumber(number) || number < min || number > max)) {
|
|
113
|
+
return { ok: false, rejectReason: `invalid item.${field}` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (kind === 'line' || kind === 'box') {
|
|
117
|
+
for (const field of ['x1', 'y1', 'x2', 'y2']) {
|
|
118
|
+
if (!isFiniteNumber(value[field]))
|
|
119
|
+
return { ok: false, rejectReason: `invalid item.${field}` };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (kind === 'line' && value.style !== undefined && !['solid', 'dashed', 'dotted'].includes(value.style)) {
|
|
123
|
+
return { ok: false, rejectReason: 'invalid item.style' };
|
|
124
|
+
}
|
|
125
|
+
if (kind === 'box' && value.text !== undefined && !isBoundedString(value.text, 80, 0)) {
|
|
126
|
+
return { ok: false, rejectReason: 'invalid item.text' };
|
|
127
|
+
}
|
|
128
|
+
if (kind === 'label' || kind === 'marker') {
|
|
129
|
+
if (!isFiniteNumber(value.x) || !isFiniteNumber(value.y)) {
|
|
130
|
+
return { ok: false, rejectReason: 'invalid item coordinates' };
|
|
131
|
+
}
|
|
132
|
+
if (kind === 'label' && !isBoundedString(value.text, 80)) {
|
|
133
|
+
return { ok: false, rejectReason: 'invalid item.text' };
|
|
134
|
+
}
|
|
135
|
+
if (kind === 'label' && value.align !== undefined && !['left', 'center', 'right'].includes(value.align)) {
|
|
136
|
+
return { ok: false, rejectReason: 'invalid item.align' };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (kind === 'marker') {
|
|
140
|
+
if (typeof value.shape !== 'string' ||
|
|
141
|
+
!['circle', 'square', 'diamond', 'up', 'down', 'cross'].includes(value.shape)) {
|
|
142
|
+
return { ok: false, rejectReason: 'invalid item.shape' };
|
|
143
|
+
}
|
|
144
|
+
if (value.size !== undefined && !isInteger(value.size)) {
|
|
145
|
+
return { ok: false, rejectReason: 'invalid item.size' };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (kind === 'polyline') {
|
|
149
|
+
if (!Array.isArray(value.points) || value.points.length < 2 || value.points.length > OM_WIDGET_MAX_DRAWING_POINTS) {
|
|
150
|
+
return { ok: false, rejectReason: `points must contain 2..${OM_WIDGET_MAX_DRAWING_POINTS} items` };
|
|
151
|
+
}
|
|
152
|
+
const points = [];
|
|
153
|
+
for (const point of value.points) {
|
|
154
|
+
if (!Array.isArray(point) || point.length !== 2 || !isFiniteNumber(point[0]) || !isFiniteNumber(point[1])) {
|
|
155
|
+
return { ok: false, rejectReason: 'invalid item point' };
|
|
156
|
+
}
|
|
157
|
+
points.push([point[0], point[1]]);
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, item: { ...value, points } };
|
|
160
|
+
}
|
|
161
|
+
return { ok: true, item: { ...value, kind } };
|
|
162
|
+
}
|
|
163
|
+
function parseWidgetBody(widget, payloadId) {
|
|
164
|
+
const kind = widget.kind === undefined ? 'card' : widget.kind;
|
|
165
|
+
if (kind !== 'card' && kind !== 'ladder' && kind !== 'feed' && kind !== 'meter' && kind !== 'drawings') {
|
|
166
|
+
return { ok: false, rejectReason: 'invalid widget.kind' };
|
|
167
|
+
}
|
|
168
|
+
if (Object.keys(widget).some((key) => !WIDGET_KEYS[kind].has(key))) {
|
|
169
|
+
return { ok: false, rejectReason: 'unknown widget key' };
|
|
170
|
+
}
|
|
171
|
+
if (!isBoundedString(widget.id, 64) || !WIDGET_ID_PATTERN.test(widget.id)) {
|
|
172
|
+
return { ok: false, rejectReason: 'invalid widget.id' };
|
|
173
|
+
}
|
|
174
|
+
if (payloadId.split(':')[2] !== widget.id)
|
|
175
|
+
return { ok: false, rejectReason: 'payloadId does not match widget.id' };
|
|
176
|
+
if (!isBoundedString(widget.title, 40))
|
|
177
|
+
return { ok: false, rejectReason: 'invalid widget.title' };
|
|
178
|
+
const identity = { id: widget.id, title: widget.title };
|
|
179
|
+
if (kind === 'drawings') {
|
|
180
|
+
if (!Array.isArray(widget.items) || widget.items.length < 1 || widget.items.length > OM_WIDGET_MAX_DRAWING_ITEMS) {
|
|
181
|
+
return { ok: false, rejectReason: `items must contain 1..${OM_WIDGET_MAX_DRAWING_ITEMS} items` };
|
|
182
|
+
}
|
|
183
|
+
const items = [];
|
|
184
|
+
for (const value of widget.items) {
|
|
185
|
+
const parsed = parseDrawingItem(value);
|
|
186
|
+
if (!parsed.ok)
|
|
187
|
+
return parsed;
|
|
188
|
+
items.push(parsed.item);
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, widget: { ...identity, kind, items } };
|
|
191
|
+
}
|
|
192
|
+
if (kind === 'ladder') {
|
|
193
|
+
if (widget.side !== 'right' && widget.side !== 'left') {
|
|
194
|
+
return { ok: false, rejectReason: 'invalid widget.side' };
|
|
195
|
+
}
|
|
196
|
+
let divider;
|
|
197
|
+
if (widget.divider !== undefined) {
|
|
198
|
+
if (!isRecord(widget.divider))
|
|
199
|
+
return { ok: false, rejectReason: 'invalid widget.divider' };
|
|
200
|
+
if (Object.keys(widget.divider).some((key) => !DIVIDER_KEYS.has(key))) {
|
|
201
|
+
return { ok: false, rejectReason: 'unknown divider key' };
|
|
202
|
+
}
|
|
203
|
+
if (!isBoundedString(widget.divider.label, 24) || !isFiniteNumber(widget.divider.price)) {
|
|
204
|
+
return { ok: false, rejectReason: 'invalid widget.divider' };
|
|
205
|
+
}
|
|
206
|
+
divider = { label: widget.divider.label, price: widget.divider.price };
|
|
207
|
+
}
|
|
208
|
+
if (!Array.isArray(widget.rows) || widget.rows.length < 1 || widget.rows.length > OM_WIDGET_MAX_LADDER_ROWS) {
|
|
209
|
+
return { ok: false, rejectReason: `rows must contain 1..${OM_WIDGET_MAX_LADDER_ROWS} items` };
|
|
210
|
+
}
|
|
211
|
+
const rows = [];
|
|
212
|
+
for (const row of widget.rows) {
|
|
213
|
+
if (!Array.isArray(row) ||
|
|
214
|
+
row.length < 3 ||
|
|
215
|
+
row.length > 4 ||
|
|
216
|
+
!isFiniteNumber(row[0]) ||
|
|
217
|
+
!isFiniteNumber(row[1]) ||
|
|
218
|
+
!isFraction(row[2]) ||
|
|
219
|
+
(row.length === 4 && !isColor(row[3]))) {
|
|
220
|
+
return { ok: false, rejectReason: 'invalid ladder row' };
|
|
221
|
+
}
|
|
222
|
+
rows.push(row.slice());
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
ok: true,
|
|
226
|
+
widget: { ...identity, kind, side: widget.side, ...(divider ? { divider } : {}), rows },
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (widget.anchor !== undefined && (typeof widget.anchor !== 'string' || !ANCHORS.has(widget.anchor))) {
|
|
230
|
+
return { ok: false, rejectReason: 'invalid widget.anchor' };
|
|
231
|
+
}
|
|
232
|
+
if (widget.offset !== undefined &&
|
|
233
|
+
(!Array.isArray(widget.offset) ||
|
|
234
|
+
widget.offset.length !== 2 ||
|
|
235
|
+
!isInteger(widget.offset[0]) ||
|
|
236
|
+
!isInteger(widget.offset[1]) ||
|
|
237
|
+
Math.abs(widget.offset[0]) > 200 ||
|
|
238
|
+
Math.abs(widget.offset[1]) > 200)) {
|
|
239
|
+
return { ok: false, rejectReason: 'invalid widget.offset' };
|
|
240
|
+
}
|
|
241
|
+
if (widget.z !== undefined && !isInteger(widget.z))
|
|
242
|
+
return { ok: false, rejectReason: 'invalid widget.z' };
|
|
243
|
+
const placement = {
|
|
244
|
+
...(widget.anchor !== undefined ? { anchor: widget.anchor } : {}),
|
|
245
|
+
...(widget.offset !== undefined ? { offset: [...widget.offset] } : {}),
|
|
246
|
+
...(widget.z !== undefined ? { z: widget.z } : {}),
|
|
247
|
+
};
|
|
248
|
+
if (kind === 'feed') {
|
|
249
|
+
if (!Array.isArray(widget.lines) || widget.lines.length < 1 || widget.lines.length > OM_WIDGET_MAX_FEED_LINES) {
|
|
250
|
+
return { ok: false, rejectReason: `lines must contain 1..${OM_WIDGET_MAX_FEED_LINES} items` };
|
|
251
|
+
}
|
|
252
|
+
const lines = [];
|
|
253
|
+
for (const line of widget.lines) {
|
|
254
|
+
if (!Array.isArray(line) ||
|
|
255
|
+
line.length < 2 ||
|
|
256
|
+
line.length > 3 ||
|
|
257
|
+
!isNonnegativeInteger(line[0]) ||
|
|
258
|
+
!isBoundedString(line[1], 80) ||
|
|
259
|
+
(line.length === 3 && !isColor(line[2]))) {
|
|
260
|
+
return { ok: false, rejectReason: 'invalid feed line' };
|
|
261
|
+
}
|
|
262
|
+
lines.push(line.slice());
|
|
263
|
+
}
|
|
264
|
+
return { ok: true, widget: { ...identity, kind, ...placement, lines } };
|
|
265
|
+
}
|
|
266
|
+
if (kind === 'meter') {
|
|
267
|
+
if (!isBoundedString(widget.label, 24))
|
|
268
|
+
return { ok: false, rejectReason: 'invalid widget.label' };
|
|
269
|
+
if (!isFraction(widget.fraction))
|
|
270
|
+
return { ok: false, rejectReason: 'invalid widget.fraction' };
|
|
271
|
+
if (!Array.isArray(widget.ramp) ||
|
|
272
|
+
widget.ramp.length < 2 ||
|
|
273
|
+
widget.ramp.length > 5 ||
|
|
274
|
+
!Array.from(widget.ramp).every(isColor)) {
|
|
275
|
+
return { ok: false, rejectReason: 'invalid widget.ramp' };
|
|
276
|
+
}
|
|
277
|
+
if (widget.text !== undefined && !isBoundedString(widget.text, 24, 0)) {
|
|
278
|
+
return { ok: false, rejectReason: 'invalid widget.text' };
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
ok: true,
|
|
282
|
+
widget: {
|
|
283
|
+
...identity,
|
|
284
|
+
kind,
|
|
285
|
+
...placement,
|
|
286
|
+
label: widget.label,
|
|
287
|
+
fraction: widget.fraction,
|
|
288
|
+
ramp: [...widget.ramp],
|
|
289
|
+
...(widget.text !== undefined ? { text: widget.text } : {}),
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (widget.state !== undefined &&
|
|
294
|
+
widget.state !== 'ok' &&
|
|
295
|
+
widget.state !== 'armed' &&
|
|
296
|
+
widget.state !== 'fired' &&
|
|
297
|
+
widget.state !== 'error') {
|
|
298
|
+
return { ok: false, rejectReason: 'invalid widget.state' };
|
|
299
|
+
}
|
|
300
|
+
if (!Array.isArray(widget.rows) || widget.rows.length < 1 || widget.rows.length > OM_WIDGET_MAX_ROWS) {
|
|
301
|
+
return { ok: false, rejectReason: `rows must contain 1..${OM_WIDGET_MAX_ROWS} items` };
|
|
302
|
+
}
|
|
303
|
+
const rows = [];
|
|
304
|
+
for (const row of widget.rows) {
|
|
305
|
+
if (!isRecord(row))
|
|
306
|
+
return { ok: false, rejectReason: 'invalid widget row' };
|
|
307
|
+
if (Object.keys(row).some((key) => !ROW_KEYS.has(key))) {
|
|
308
|
+
return { ok: false, rejectReason: 'unknown widget row key' };
|
|
309
|
+
}
|
|
310
|
+
if (!isBoundedString(row.label, 24))
|
|
311
|
+
return { ok: false, rejectReason: 'invalid row.label' };
|
|
312
|
+
if (row.value !== undefined && !isBoundedString(row.value, 24, 0)) {
|
|
313
|
+
return { ok: false, rejectReason: 'invalid row.value' };
|
|
314
|
+
}
|
|
315
|
+
if (row.color !== undefined && !isColor(row.color))
|
|
316
|
+
return { ok: false, rejectReason: 'invalid row.color' };
|
|
317
|
+
if (row.countdown_to !== undefined && !isNonnegativeInteger(row.countdown_to)) {
|
|
318
|
+
return { ok: false, rejectReason: 'invalid row.countdown_to' };
|
|
319
|
+
}
|
|
320
|
+
if (row.clock !== undefined && row.clock !== true)
|
|
321
|
+
return { ok: false, rejectReason: 'invalid row.clock' };
|
|
322
|
+
if (row.spark !== undefined && !isSpark(row.spark))
|
|
323
|
+
return { ok: false, rejectReason: 'invalid row.spark' };
|
|
324
|
+
rows.push({
|
|
325
|
+
label: row.label,
|
|
326
|
+
...(row.value !== undefined ? { value: row.value } : {}),
|
|
327
|
+
...(row.color !== undefined ? { color: row.color } : {}),
|
|
328
|
+
...(row.countdown_to !== undefined ? { countdown_to: row.countdown_to } : {}),
|
|
329
|
+
...(row.clock !== undefined ? { clock: true } : {}),
|
|
330
|
+
...(row.spark !== undefined ? { spark: [...row.spark] } : {}),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
ok: true,
|
|
335
|
+
widget: {
|
|
336
|
+
...identity,
|
|
337
|
+
kind,
|
|
338
|
+
...placement,
|
|
339
|
+
...(widget.state !== undefined ? { state: widget.state } : {}),
|
|
340
|
+
rows,
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/** Reject the whole envelope before a malformed frame can advance a revision floor. */
|
|
345
|
+
export function parseWidgetFrame(value) {
|
|
346
|
+
if (!isRecord(value))
|
|
347
|
+
return { ok: false, rejectReason: 'payload is not an object' };
|
|
348
|
+
if (Object.keys(value).some((key) => !FRAME_KEYS.has(key))) {
|
|
349
|
+
return { ok: false, rejectReason: 'unknown payload key' };
|
|
350
|
+
}
|
|
351
|
+
if (!isNonnegativeInteger(value.chartIndex) || value.chartIndex >= MAX_PANES) {
|
|
352
|
+
return { ok: false, rejectReason: 'invalid chartIndex' };
|
|
353
|
+
}
|
|
354
|
+
if (!isBoundedString(value.payloadId, 80) || !OM_WIDGET_PAYLOAD_ID_PATTERN.test(value.payloadId)) {
|
|
355
|
+
return { ok: false, rejectReason: 'invalid payloadId' };
|
|
356
|
+
}
|
|
357
|
+
const payloadParts = value.payloadId.split(':');
|
|
358
|
+
if (payloadParts[1] !== `c${value.chartIndex}`) {
|
|
359
|
+
return { ok: false, rejectReason: 'payloadId does not match chartIndex' };
|
|
360
|
+
}
|
|
361
|
+
if (!isNonnegativeInteger(value.revision))
|
|
362
|
+
return { ok: false, rejectReason: 'invalid revision stamp' };
|
|
363
|
+
if (value.clear !== undefined && value.clear !== true) {
|
|
364
|
+
return { ok: false, rejectReason: 'invalid clear flag (only true is wire-legal)' };
|
|
365
|
+
}
|
|
366
|
+
if (value.clear === true) {
|
|
367
|
+
if (Object.keys(value).some((key) => !CLEAR_KEYS.has(key))) {
|
|
368
|
+
return { ok: false, rejectReason: 'clear payload carries baggage' };
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
ok: true,
|
|
372
|
+
data: { chartIndex: value.chartIndex, payloadId: value.payloadId, revision: value.revision, clear: true },
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const widget = value.widget;
|
|
376
|
+
if (!isRecord(widget))
|
|
377
|
+
return { ok: false, rejectReason: 'invalid widget' };
|
|
378
|
+
const body = parseWidgetBody(widget, value.payloadId);
|
|
379
|
+
if (!body.ok)
|
|
380
|
+
return body;
|
|
381
|
+
let source;
|
|
382
|
+
if (value.source !== undefined) {
|
|
383
|
+
if (!isRecord(value.source))
|
|
384
|
+
return { ok: false, rejectReason: 'invalid source' };
|
|
385
|
+
const rawSource = value.source;
|
|
386
|
+
if (Object.keys(rawSource).some((key) => !SOURCE_KEYS.has(key))) {
|
|
387
|
+
return { ok: false, rejectReason: 'unknown source key' };
|
|
388
|
+
}
|
|
389
|
+
if (rawSource.kind !== 'watch' &&
|
|
390
|
+
rawSource.kind !== 'strategy' &&
|
|
391
|
+
rawSource.kind !== 'metric' &&
|
|
392
|
+
rawSource.kind !== 'custom') {
|
|
393
|
+
return { ok: false, rejectReason: 'invalid source.kind' };
|
|
394
|
+
}
|
|
395
|
+
if (!isBoundedString(rawSource.ref, 160))
|
|
396
|
+
return { ok: false, rejectReason: 'invalid source.ref' };
|
|
397
|
+
if (!isNonnegativeInteger(rawSource.computedAtMs)) {
|
|
398
|
+
return { ok: false, rejectReason: 'invalid source.computedAtMs' };
|
|
399
|
+
}
|
|
400
|
+
source = { kind: rawSource.kind, ref: rawSource.ref, computedAtMs: rawSource.computedAtMs };
|
|
401
|
+
}
|
|
402
|
+
const data = {
|
|
403
|
+
chartIndex: value.chartIndex,
|
|
404
|
+
payloadId: value.payloadId,
|
|
405
|
+
revision: value.revision,
|
|
406
|
+
widget: body.widget,
|
|
407
|
+
...(source !== undefined ? { source } : {}),
|
|
408
|
+
};
|
|
409
|
+
if (new TextEncoder().encode(JSON.stringify(data)).byteLength > OM_WIDGET_MAX_BYTES) {
|
|
410
|
+
return { ok: false, rejectReason: 'intent_too_large' };
|
|
411
|
+
}
|
|
412
|
+
return { ok: true, data };
|
|
413
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart's output budgets and the counters they read (rows, series, drawings, heatmap and batched-mark cells):
|
|
3
|
+
* pure arithmetic over a run result, split out of the overlay execution guard (overlay-execution-guard.ts, which
|
|
4
|
+
* re-exports every name here) so the wrun result reader core reads them without the guard's census, perf tracker
|
|
5
|
+
* and degrade registry. It rides the `@orangecharts/wrun-chart-host` package
|
|
6
|
+
* (docs/features/kscript/wrun/wrun-chart-host.md).
|
|
7
|
+
*/
|
|
8
|
+
export declare const OVERLAY_HISTORICAL_ROW_BUDGET = 400000;
|
|
9
|
+
export declare const OVERLAY_HISTORICAL_DRAWING_BUDGET = 2000;
|
|
10
|
+
export declare const OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET = 2000000;
|
|
11
|
+
export declare const WRUN_BATCHED_MARKS_CELL_BUDGET = 2000000;
|
|
12
|
+
export declare function shouldBlockOverlayHistoricalPreflightBudget(output: unknown, _stage?: string, _details?: Record<string, unknown>): boolean;
|
|
13
|
+
export declare function countOverlayOutputRows(output: unknown): number;
|
|
14
|
+
export declare function countOverlayOutputSeries(output: unknown): number;
|
|
15
|
+
export declare function countOverlayOutputDrawings(output: unknown): number;
|
|
16
|
+
export declare function exceedsOverlayHistoricalPreflightBudget(output: unknown, rowBudget?: number, seriesBudget?: number, drawingBudget?: number): boolean;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart's output budgets and the counters they read (rows, series, drawings, heatmap and batched-mark cells):
|
|
3
|
+
* pure arithmetic over a run result, split out of the overlay execution guard (overlay-execution-guard.ts, which
|
|
4
|
+
* re-exports every name here) so the wrun result reader core reads them without the guard's census, perf tracker
|
|
5
|
+
* and degrade registry. It rides the `@orangecharts/wrun-chart-host` package
|
|
6
|
+
* (docs/features/kscript/wrun/wrun-chart-host.md).
|
|
7
|
+
*/
|
|
8
|
+
// The row budget bounds ONE mount of a run's rows on the main thread (a runaway
|
|
9
|
+
// script's million-point plot never reaches the chart); the per-frame paint cost
|
|
10
|
+
// is the render tiers' job and a slow mount is the breaker's (OVERLAY_BUDGET_MS,
|
|
11
|
+
// three strikes pause the overlay). Sized 2026-10-11 from the other two bounds
|
|
12
|
+
// rather than guessed: the zoom-out cap keeps at most ~10,000 candles loaded
|
|
13
|
+
// (1,500 visible plus buffers and a 5,000-bar warm-up) and an overlay draws at
|
|
14
|
+
// most OVERLAY_HISTORICAL_SERIES_BUDGET series, 32 x 10,000 = 320,000, so a
|
|
15
|
+
// package that honours those two never meets this one. 150,000 (the 2026-06-25
|
|
16
|
+
// guess) refused a 12-series Anchored VWAP on a 13,270-candle 1-minute chart.
|
|
17
|
+
// Measured 2026-10-11 (headless Chromium, 18-core Mac, titan 1075, addOverlay
|
|
18
|
+
// of spline rows on the main thread): 100,000 points in 4 ms (1 series) to
|
|
19
|
+
// 17 ms (8 series); 300,000 to 500,000 points over 32 series in 48 to 79 ms;
|
|
20
|
+
// 800,000 in 92 ms. The per-series overhead dominates, so 400,000 stays well
|
|
21
|
+
// under one dropped frame.
|
|
22
|
+
export const OVERLAY_HISTORICAL_ROW_BUDGET = 400_000;
|
|
23
|
+
const OVERLAY_HISTORICAL_SERIES_BUDGET = 32;
|
|
24
|
+
export const OVERLAY_HISTORICAL_DRAWING_BUDGET = 2_000;
|
|
25
|
+
// Mounted heatmap cells (rows x levels, history plus live appends) a wrun overlay may hand the
|
|
26
|
+
// engine; past it the oldest bars are dropped and the legend says so ("Cells capped"). The
|
|
27
|
+
// value is set from the measured Book Heat fixture (dev-fixtures/wrun-fixtures/book-heat on the
|
|
28
|
+
// pinned BTCUSDC 15m 1,500 bars): the template as shipped mounts 1,500,000 cells (the book lane's
|
|
29
|
+
// 500 levels a side on every bar), and so does any finer max_cells (the kit sets no ceiling, the
|
|
30
|
+
// lane's depth bounds it); 2,000,000 never trims it and leaves 500 bars for its live appends.
|
|
31
|
+
export const OVERLAY_HISTORICAL_HEATMAP_CELL_BUDGET = 2_000_000;
|
|
32
|
+
// Mounted batched-mark cells (WRUN-BATCHED-MARKS: a wrun overlay's `marks`, `spans` and `rays`
|
|
33
|
+
// children) the overlay may hold: ONE budget over the CHILD copies of its three kinds, retained
|
|
34
|
+
// history and live appends alike (wrun-batched-marks.util). A cell is one scalar and a kept bar
|
|
35
|
+
// costs its child row (1 + slots x stride, empty slots included) and nothing else: the parent run's
|
|
36
|
+
// section columns are the run's rows (bounded apart, in the worker: WRUN_MAX_RUN_CELLS,
|
|
37
|
+
// wrun-run-cells.util) and a replace's old copy goes at the swap (a replace keeps the hard
|
|
38
|
+
// allowance, like a heatmap's hand-off). Past it the oldest bars are dropped before any copy is
|
|
39
|
+
// built and the "Cells capped" row says so (one row per Indicator, heatmaps included). Sized like
|
|
40
|
+
// the heatmap budget: Big Trades 0.4.0 (32 slots of 3 fields, 97 cells a bar) keeps 20,618 bars, so
|
|
41
|
+
// a 7-day 1m chart (10,080 bars) mounts whole and every rerun keeps it whole.
|
|
42
|
+
export const WRUN_BATCHED_MARKS_CELL_BUDGET = 2_000_000;
|
|
43
|
+
export function shouldBlockOverlayHistoricalPreflightBudget(output, _stage = 'overlay-historical-preflight', _details = {}) {
|
|
44
|
+
return (countOverlayOutputRows(output) > OVERLAY_HISTORICAL_ROW_BUDGET ||
|
|
45
|
+
countOverlayOutputDrawings(output) > OVERLAY_HISTORICAL_DRAWING_BUDGET);
|
|
46
|
+
}
|
|
47
|
+
export function countOverlayOutputRows(output) {
|
|
48
|
+
if (!output || typeof output !== 'object')
|
|
49
|
+
return 0;
|
|
50
|
+
const seen = new WeakSet();
|
|
51
|
+
const visit = (candidate) => {
|
|
52
|
+
if (!candidate || typeof candidate !== 'object')
|
|
53
|
+
return 0;
|
|
54
|
+
if (seen.has(candidate))
|
|
55
|
+
return 0;
|
|
56
|
+
seen.add(candidate);
|
|
57
|
+
const item = candidate;
|
|
58
|
+
let rows = 0;
|
|
59
|
+
if (Array.isArray(item.data))
|
|
60
|
+
rows += item.data.length;
|
|
61
|
+
if (Array.isArray(item.rawData))
|
|
62
|
+
rows += item.rawData.length;
|
|
63
|
+
if (Array.isArray(item.activeData))
|
|
64
|
+
rows += item.activeData.length;
|
|
65
|
+
if (Array.isArray(item.nestedMeta))
|
|
66
|
+
rows += item.nestedMeta.reduce((total, nested) => total + visit(nested), 0);
|
|
67
|
+
if (item.outputs && typeof item.outputs === 'object') {
|
|
68
|
+
rows += Object.values(item.outputs).reduce((total, nested) => total + visit(nested), 0);
|
|
69
|
+
}
|
|
70
|
+
return rows;
|
|
71
|
+
};
|
|
72
|
+
return visit(output);
|
|
73
|
+
}
|
|
74
|
+
export function countOverlayOutputSeries(output) {
|
|
75
|
+
if (!output || typeof output !== 'object')
|
|
76
|
+
return 0;
|
|
77
|
+
const seen = new WeakSet();
|
|
78
|
+
const visit = (candidate) => {
|
|
79
|
+
if (!candidate || typeof candidate !== 'object')
|
|
80
|
+
return 0;
|
|
81
|
+
if (seen.has(candidate))
|
|
82
|
+
return 0;
|
|
83
|
+
seen.add(candidate);
|
|
84
|
+
const item = candidate;
|
|
85
|
+
const hasSeries = Array.isArray(item.data) ||
|
|
86
|
+
Array.isArray(item.rawData) ||
|
|
87
|
+
Array.isArray(item.activeData) ||
|
|
88
|
+
item.plot !== undefined;
|
|
89
|
+
let series = hasSeries ? 1 : 0;
|
|
90
|
+
if (Array.isArray(item.nestedMeta))
|
|
91
|
+
series += item.nestedMeta.reduce((total, nested) => total + visit(nested), 0);
|
|
92
|
+
if (item.outputs && typeof item.outputs === 'object') {
|
|
93
|
+
series += Object.values(item.outputs).reduce((total, nested) => total + visit(nested), 0);
|
|
94
|
+
}
|
|
95
|
+
return series;
|
|
96
|
+
};
|
|
97
|
+
return visit(output);
|
|
98
|
+
}
|
|
99
|
+
export function countOverlayOutputDrawings(output) {
|
|
100
|
+
if (!output || typeof output !== 'object')
|
|
101
|
+
return 0;
|
|
102
|
+
const drawings = output.drawings;
|
|
103
|
+
return Array.isArray(drawings) ? drawings.length : 0;
|
|
104
|
+
}
|
|
105
|
+
export function exceedsOverlayHistoricalPreflightBudget(output, rowBudget = OVERLAY_HISTORICAL_ROW_BUDGET, seriesBudget = OVERLAY_HISTORICAL_SERIES_BUDGET, drawingBudget = OVERLAY_HISTORICAL_DRAWING_BUDGET) {
|
|
106
|
+
return (countOverlayOutputRows(output) > rowBudget ||
|
|
107
|
+
countOverlayOutputSeries(output) > seriesBudget ||
|
|
108
|
+
countOverlayOutputDrawings(output) > drawingBudget);
|
|
109
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface OverlayPaintFlags {
|
|
2
|
+
/** TH-theme-tokens: the sheet may carry `theme.<t>` colour words (a theme
|
|
3
|
+
* word in its JSON, or handles, frames or a `*_packed_by` key, whose
|
|
4
|
+
* colours arrive at run time), so the paint pass resolves tokens and
|
|
5
|
+
* re-resolves them on a theme switch. */
|
|
6
|
+
themeTokens: boolean;
|
|
7
|
+
/** DW21: the light-theme contrast guard; false keeps the author's colours
|
|
8
|
+
* on a light chart (`contrast_guard: false`). */
|
|
9
|
+
contrastGuard: boolean;
|
|
10
|
+
/** DW35: `stack_handles: true` keeps this overlay's anchored handle groups
|
|
11
|
+
* clear of earlier overlays' groups at the same corner. */
|
|
12
|
+
stackHandles: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The flags of an overlay nobody flagged: today's behaviour. */
|
|
15
|
+
export declare const DEFAULT_OVERLAY_PAINT_FLAGS: Readonly<OverlayPaintFlags>;
|
|
16
|
+
/** Records the flags of overlay `id` (a copy, booleans coerced: a missing
|
|
17
|
+
* `contrastGuard` reads as on, the others as off). */
|
|
18
|
+
export declare function setOverlayPaintFlags(id: string, flags: OverlayPaintFlags): void;
|
|
19
|
+
/** The flags of overlay `id` (a child id reads its parent's); the defaults
|
|
20
|
+
* when nothing was recorded. */
|
|
21
|
+
export declare function overlayPaintFlagsOf(id: string): Readonly<OverlayPaintFlags>;
|
|
22
|
+
/** Forgets the flags of overlay `id` (its reads answer the defaults again). */
|
|
23
|
+
export declare function clearOverlayPaintFlags(id: string): void;
|
|
24
|
+
export declare function __resetOverlayPaintFlagsForTests(): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-overlay paint flags (WRUN-STYLE g4: DW21, DW35, TH-theme-tokens): what
|
|
3
|
+
* the paint doors read about a mounted overlay's sheet without holding the
|
|
4
|
+
* sheet themselves. `rememberWrunOverlayMetadata` sets them when a loader
|
|
5
|
+
* remembers a sheet on any lane (a browser-run registry package, an editor
|
|
6
|
+
* draft, a dev fixture, a hosted Cloud run) and `forgetWrunOverlayMetadata`
|
|
7
|
+
* clears them with the overlay; the contrast guard, the drawing safe-area door
|
|
8
|
+
* and the run-result integration read them by overlay id.
|
|
9
|
+
*
|
|
10
|
+
* An overlay nobody flagged (every kScript overlay, a WRUN overlay before its
|
|
11
|
+
* loader bound it) answers the defaults, which are today's behaviour: no
|
|
12
|
+
* theme tokens to resolve, the light-theme contrast guard on, no handle
|
|
13
|
+
* stacking. A child overlay of a WRUN Indicator (`<parent>::series:<pane>`,
|
|
14
|
+
* `::panel:`, `::levels:`, `::heatmap:`, ...; wrun-child-overlay-id.util)
|
|
15
|
+
* answers its parent's flags: the lower pane paints the same sheet.
|
|
16
|
+
*
|
|
17
|
+
* Imports one other leaf (the child id grammar): main-thread and worker safe.
|
|
18
|
+
*/
|
|
19
|
+
import { wrunChildOverlayParentId } from '../wrun/wrun-child-overlay-id.util.js';
|
|
20
|
+
/** The flags of an overlay nobody flagged: today's behaviour. */
|
|
21
|
+
export const DEFAULT_OVERLAY_PAINT_FLAGS = Object.freeze({
|
|
22
|
+
themeTokens: false,
|
|
23
|
+
contrastGuard: true,
|
|
24
|
+
stackHandles: false,
|
|
25
|
+
});
|
|
26
|
+
const flagsByOverlay = new Map();
|
|
27
|
+
/** Records the flags of overlay `id` (a copy, booleans coerced: a missing
|
|
28
|
+
* `contrastGuard` reads as on, the others as off). */
|
|
29
|
+
export function setOverlayPaintFlags(id, flags) {
|
|
30
|
+
if (typeof id !== 'string')
|
|
31
|
+
return;
|
|
32
|
+
flagsByOverlay.set(id, Object.freeze({
|
|
33
|
+
themeTokens: flags?.themeTokens === true,
|
|
34
|
+
contrastGuard: flags?.contrastGuard !== false,
|
|
35
|
+
stackHandles: flags?.stackHandles === true,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** The flags of overlay `id` (a child id reads its parent's); the defaults
|
|
39
|
+
* when nothing was recorded. */
|
|
40
|
+
export function overlayPaintFlagsOf(id) {
|
|
41
|
+
if (typeof id !== 'string')
|
|
42
|
+
return DEFAULT_OVERLAY_PAINT_FLAGS;
|
|
43
|
+
const own = flagsByOverlay.get(id);
|
|
44
|
+
if (own !== undefined)
|
|
45
|
+
return own;
|
|
46
|
+
const parentId = wrunChildOverlayParentId(id);
|
|
47
|
+
return (parentId === null ? undefined : flagsByOverlay.get(parentId)) ?? DEFAULT_OVERLAY_PAINT_FLAGS;
|
|
48
|
+
}
|
|
49
|
+
/** Forgets the flags of overlay `id` (its reads answer the defaults again). */
|
|
50
|
+
export function clearOverlayPaintFlags(id) {
|
|
51
|
+
flagsByOverlay.delete(id);
|
|
52
|
+
}
|
|
53
|
+
export function __resetOverlayPaintFlagsForTests() {
|
|
54
|
+
flagsByOverlay.clear();
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The profile family a row table belongs to: one footprint column per bar,
|
|
2
|
+
* the TPO letters, or a session volume profile. */
|
|
3
|
+
export type ProfileRowKind = 'footprint' | 'tpo' | 'session';
|
|
4
|
+
/** The table label of an interval given in milliseconds: the registry's
|
|
5
|
+
* label when the span is a known interval (a custom one folds to its
|
|
6
|
+
* standard, the tuning rule), else the largest table label no longer than
|
|
7
|
+
* the span. An unknown or non-positive span reads as '' (the tables'
|
|
8
|
+
* fallback of 1). */
|
|
9
|
+
export declare function profileRowIntervalLabel(interval: string | number): string;
|
|
10
|
+
/**
|
|
11
|
+
* The row multiplier behind a profile canvas's `row_height: "auto"` (the
|
|
12
|
+
* native controls' `getBarsForInterval`): the kind's table at the chart
|
|
13
|
+
* interval (a label, or a span in milliseconds), 1 for an interval outside
|
|
14
|
+
* the table. A TPO period word (the engine's 'Daily' | 'Weekly' | 'Monthly',
|
|
15
|
+
* or the sheet's 'day' | 'week' | 'month') scales the TPO base by the native
|
|
16
|
+
* session multiplier, floored, exactly like the control.
|
|
17
|
+
*/
|
|
18
|
+
export declare function profileRowMultiplier(kind: ProfileRowKind, interval: string | number, period?: string): number;
|
|
19
|
+
/** The engine's TPO session word for a sheet period (`day` -> 'Daily'); an
|
|
20
|
+
* engine word passes through unchanged. */
|
|
21
|
+
export declare function tpoPeriodWord(period: string): string;
|