@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,1971 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A browser-run Indicator's params as TECHNICAL_SCRIPT script inputs: the
|
|
3
|
+
* ONE builder every mount uses (the registry loader's pane-first and
|
|
4
|
+
* download mounts, the editor's draft lane, the dev fixture loader, the
|
|
5
|
+
* hosted lane), the dialog layout built from those rows, the param values a
|
|
6
|
+
* run computes with, and the sheet's legend title template resolved against
|
|
7
|
+
* a run's param values.
|
|
8
|
+
*
|
|
9
|
+
* Settings-dialog keys on a param (frozen sheet contract, registry-validated:
|
|
10
|
+
* the om param schema is a non-strict object and the registry serves the
|
|
11
|
+
* sheet as published):
|
|
12
|
+
* - `label`: the row label, the kScript input label, printed verbatim (never
|
|
13
|
+
* re-cased). Absent = the name read as words (the legend's rule,
|
|
14
|
+
* wrunNameWords: `band_pct` reads "Band pct", `atr_len` "ATR len"). A
|
|
15
|
+
* `description` is never the label: it is the row's hint when the param
|
|
16
|
+
* declares no `hint` of its own.
|
|
17
|
+
* - `type`: 'number' (the default), 'int' (whole steps), 'boolean' (the
|
|
18
|
+
* dialog's toggle), 'select' (a labelled choice), 'color' (a colour
|
|
19
|
+
* row), 'time' (an instant, chart-pickable), 'price' (a level,
|
|
20
|
+
* chart-pickable), 'multi' (labelled chips, a bitmask at the module) or
|
|
21
|
+
* 'symbol' (a market picker). The module only ever receives numbers: the
|
|
22
|
+
* dialog writes a toggle as true/false, a select as its numeric-string
|
|
23
|
+
* value, a colour as its string, a symbol as "EXCHANGE:SYMBOL", and the
|
|
24
|
+
* run reads every flat setting back through wrunParamValuesFromSettings,
|
|
25
|
+
* so a toggle arrives as 1/0, a select as its option value, a colour as
|
|
26
|
+
* its packed number (wrun-color-settings.util), a time as epoch seconds,
|
|
27
|
+
* a multi as its bitmask and a symbol as 0 (the browser host applies the
|
|
28
|
+
* pick to the bound inputs instead).
|
|
29
|
+
* - `color_array`: N consecutive colour params render as ONE colour-array
|
|
30
|
+
* row named by the key (the kScript `color[]` input), member i = element i
|
|
31
|
+
* (the row lists the member params in `members`, frozen contract C1).
|
|
32
|
+
* - `style` (om): a style-only knob renders by its bound property (a colour
|
|
33
|
+
* row, a number field for width / opacity, a solid / dashed / dotted
|
|
34
|
+
* select for lineStyle) and never reaches init().
|
|
35
|
+
* - `step`: the number field's step; an 'int' steps by 1 unless declared.
|
|
36
|
+
* - `group`: the dialog group (its tabs; "Tab/Section" nests a section).
|
|
37
|
+
* - `option_labels`: a select's labels, parallel to `options` (the schema's
|
|
38
|
+
* numeric option values) or, without `options`, to the integers min..max.
|
|
39
|
+
* - Typed-inputs keys (WRUN-INPUTS-PLAN 1.1): `hint`, `row`, `when`,
|
|
40
|
+
* `hide`, `slider` and `host` ride the row verbatim; `hidden` and
|
|
41
|
+
* `host_fill` rows are never rendered; `range` / `list` / `session`
|
|
42
|
+
* members and a `unit` pair each collapse into ONE virtual composite row
|
|
43
|
+
* named by the composite (`virtual: true`, `members` in the frozen
|
|
44
|
+
* order: range [lo, hi], list [slot_0 .. slot_n-1, count], session
|
|
45
|
+
* [start, end, tz], unit [value, unit]) while every member keeps its own
|
|
46
|
+
* hidden row (the flat list is the persistence whitelist, and values
|
|
47
|
+
* live under the member keys: the composite row holds no value of its
|
|
48
|
+
* own).
|
|
49
|
+
* - `visible_by` (kit 0.69.0) rides the row as `visibleBy` (a composite's
|
|
50
|
+
* from its lead member, a Style row's from its output), so the dialog
|
|
51
|
+
* marks the row hidden on a market whose size unit the list leaves out
|
|
52
|
+
* (wrunRowVisibleHere) without the sheet; its value stays.
|
|
53
|
+
* Every number field carries its declared min/max (and step) in
|
|
54
|
+
* `constraints`, the only place the settings dialog reads bounds from.
|
|
55
|
+
*
|
|
56
|
+
* Style rows (frozen `__style__<target>__<property>` keys, fix-round
|
|
57
|
+
* contract C1: target = an output name, `text:<name>`, `heatmap:<name>`,
|
|
58
|
+
* `profile:<name>`, `levels:<name>`, or a batched section `marks:<name>`,
|
|
59
|
+
* `spans:<name>` or `rays:<name>`; every drawn kind past those through the
|
|
60
|
+
* visibility table, wrun-visibility-table.ts, the one list of targets every
|
|
61
|
+
* builder here reads: a band `range:<upper>/<lower>#<n>` or
|
|
62
|
+
* `fill:<first>/<second>#<n>`, `box:`, `segment:`, `drawing:<kind>:`,
|
|
63
|
+
* `handles:<kind>`, `matrix:` and `panel:` targets, every renderer kind as
|
|
64
|
+
* `text:<name>`, the candle tint and an inset output by name, each with a
|
|
65
|
+
* Visible row): one row per drawn target and
|
|
66
|
+
* property whose write PAINTS for it (a line: visible, width, lineStyle,
|
|
67
|
+
* color; an area adds opacity; a bar or histogram: visible, color, opacity,
|
|
68
|
+
* or one `colors` row for a two-tone pair; a mark: visible, width, color; a
|
|
69
|
+
* candle group: visible, width on its first output; a per-bar colour or
|
|
70
|
+
* width ladder (or a line's own gradient or split colours) drops the static
|
|
71
|
+
* row it replaces, see stylePropertiesOf; a text or label renderer: visible,
|
|
72
|
+
* color; a heatmap, a price profile or a docked level: visible plus the
|
|
73
|
+
* declared colours it paints; a batched section: visible, its colours and
|
|
74
|
+
* opacity, a ray its width and line style too, see childStyleRows),
|
|
75
|
+
* defaults from the declaration, skipped when a param of the sheet already
|
|
76
|
+
* paints that (target, property) (declaredStyleKnobs; an output's visible
|
|
77
|
+
* only when a boolean param owns it, wrunVisibilityOwners). They are FE-only
|
|
78
|
+
* declared inputs: persisted by name, painted into the sheet by the run
|
|
79
|
+
* path, never sent to a host, and the only rows of the 'redraw' tier (a save
|
|
80
|
+
* of nothing else restyles the mounted outputs in place, wrun-style-tier.util
|
|
81
|
+
* and wrun-style-patch.util; a `colors` row and a prefixed target's rows
|
|
82
|
+
* repaint through a rerun). A cloud record mounts the same rows (the registry
|
|
83
|
+
* loader builds both lanes' records here, over the full sheet): the one pass
|
|
84
|
+
* paints either row source's batch through the chart's own builders.
|
|
85
|
+
*
|
|
86
|
+
* The layout (buildWrunScriptLayout) groups the flat rows into pages and
|
|
87
|
+
* sections: from the sheet's `layout` when it declares one (params before
|
|
88
|
+
* the first page land on the 'general' page; a composite places once,
|
|
89
|
+
* whether the layout names it or its members; a section's toggle param is
|
|
90
|
+
* drawn by the section header, never as a row), else one page per `group`
|
|
91
|
+
* tab with 'general' first, the tabs a sheet without `layout` always had,
|
|
92
|
+
* a param that paints a drawn output moved onto the Style page beside it (a
|
|
93
|
+
* boolean that owns outputs' visibility in the first one's Visible slot);
|
|
94
|
+
* the 'style' page follows when style rows exist (a layout page the author
|
|
95
|
+
* titled like it holds them instead, after its own rows). A page or tab named
|
|
96
|
+
* as a built-in page (General, and Style while style rows exist) lands on
|
|
97
|
+
* that page, never a second tab with its label. It needs only the rows
|
|
98
|
+
* for hints and picks, so an overlay restored without its sheet still lays
|
|
99
|
+
* out (by group tabs).
|
|
100
|
+
*/
|
|
101
|
+
// All three import nothing themselves: this module loads in the worker's graph.
|
|
102
|
+
import { wrunLegendName } from '../chart/wrun-legend-name.util.js';
|
|
103
|
+
import { isReservedKScriptProvenanceKey } from '../chart/kscript-provenance-keys.util.js';
|
|
104
|
+
import { footprintPaintsVolumeColor } from './wrun-footprint-modes.util.js';
|
|
105
|
+
import { isWrunColorWord, wrunThemeTokenOfPacked, wrunThemeTokenWord } from './wrun-style-words.util.js';
|
|
106
|
+
import { isWrunColorParam, isWrunStyleParam, wrunColorArrayKey, wrunColorPalette, wrunColorParamDefault, wrunColorSettingString, wrunLineStyles, wrunParamChoices, wrunSelectOptionValue, wrunStyleBinding, parseWrunStyleTarget, wrunVisibilityOwnedOutputs, wrunVisibilityOwners, } from './wrun-color-settings.util.js';
|
|
107
|
+
import { findWrunVisibilityTarget, WRUN_HANDLE_KIND_RULES, WRUN_VISIBILITY_RULES, wrunVisibilityEntryTarget, wrunVisibilityTargetAt, } from './wrun-visibility-table.js';
|
|
108
|
+
import { wrunCodedWords } from './wrun-setting-words.util.js';
|
|
109
|
+
import { wrunRowVisibleHere } from './wrun-market-facts.util.js';
|
|
110
|
+
import { bitmaskValue, finiteNumber, nonEmptyString, numericValue, toggleValue, wrunMultiLabels, wrunTimeValue, } from './wrun-param-values.util.js';
|
|
111
|
+
import { wrunLegendLiteral, wrunTextParamCap, wrunTextParamDefault, wrunTextValueWithinCap, } from './wrun-text-params.util.js';
|
|
112
|
+
// The choice set and the one select read live beside the other settings
|
|
113
|
+
// readers (wrun-color-settings.util, the sheet seam's module); the builders
|
|
114
|
+
// here and their callers keep importing them from this module.
|
|
115
|
+
export { wrunParamChoices } from './wrun-color-settings.util.js';
|
|
116
|
+
/** The page every param before the first `page()` (and every ungrouped
|
|
117
|
+
* param of a sheet without `layout`) lands on. */
|
|
118
|
+
export const WRUN_GENERAL_PAGE_ID = 'general';
|
|
119
|
+
/** The derived Style page (appended when style rows exist). */
|
|
120
|
+
export const WRUN_STYLE_PAGE_ID = 'style';
|
|
121
|
+
/** The Style page's first section: a colour param over several drawn outputs. */
|
|
122
|
+
export const WRUN_STYLE_COLORS_SECTION_ID = 'colors';
|
|
123
|
+
/** The style-row name prefix (frozen): `__style__<output>__<property>`,
|
|
124
|
+
* the key the run path reads back (wrun-color-settings.util
|
|
125
|
+
* parseWrunStyleRowKey). */
|
|
126
|
+
const WRUN_STYLE_ROW_PREFIX = '__style__';
|
|
127
|
+
/** A sheet name as a settings row prints it: the legend's rule with the
|
|
128
|
+
* first letter capitalized (`band_pct` reads "Band pct", `atr_length` "ATR
|
|
129
|
+
* length"). The same words as wrunNameWords (wrun-hover.util), restated
|
|
130
|
+
* here because that module's imports reach the i18n plugin and this one
|
|
131
|
+
* loads in the worker's graph; the spec pins the two equal. */
|
|
132
|
+
function nameWords(name) {
|
|
133
|
+
const words = wrunLegendName(name);
|
|
134
|
+
return words === '' ? name : words[0].toUpperCase() + words.slice(1);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The words a settings row prints: its label verbatim (an author's words are
|
|
138
|
+
* never re-cased: "ATRs" stays "ATRs"), else the name read as words. A label
|
|
139
|
+
* that is the bare name (what an older build stamped on a param without one)
|
|
140
|
+
* reads as words too. The kScript dialog's Title Case is for kScript rows
|
|
141
|
+
* only (technical-script-input-rendering formatTechnicalScriptLabel).
|
|
142
|
+
*/
|
|
143
|
+
export function wrunRowLabel(row) {
|
|
144
|
+
const written = typeof row.label === 'string' ? row.label.trim() : '';
|
|
145
|
+
return written !== '' && written !== row.name ? written : nameWords(row.name);
|
|
146
|
+
}
|
|
147
|
+
/** The controls that already show a choice as words or a swatch. */
|
|
148
|
+
const WORDED_CONTROLS = new Set(['select', 'multi', 'boolean', 'color']);
|
|
149
|
+
/** A row's hint: the param's own `hint`, else its description (not on a
|
|
150
|
+
* port's worded control, WrunRowBuildOptions.port); none when it only
|
|
151
|
+
* repeats the label. */
|
|
152
|
+
function rowHint(param, label, options) {
|
|
153
|
+
const legend = options?.port === true && WORDED_CONTROLS.has(wrunParamControlType(param));
|
|
154
|
+
const hint = nonEmptyString(param.hint) ?? (legend ? undefined : nonEmptyString(param.description));
|
|
155
|
+
return hint !== undefined && hint.trim().toLowerCase() !== label.trim().toLowerCase() ? hint : undefined;
|
|
156
|
+
}
|
|
157
|
+
function isRecord(value) {
|
|
158
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
159
|
+
}
|
|
160
|
+
/** The style-row name (frozen): `__style__<output>__<property>`. */
|
|
161
|
+
export function wrunStyleRowName(output, property) {
|
|
162
|
+
return `${WRUN_STYLE_ROW_PREFIX}${output}__${property}`;
|
|
163
|
+
}
|
|
164
|
+
/** The control a param renders as: its declared `type` when the sheet gives
|
|
165
|
+
* what that control needs (a select needs a choice set, a multi its
|
|
166
|
+
* labels), else the number field every param rendered as before the key. */
|
|
167
|
+
export function wrunParamControlType(param) {
|
|
168
|
+
if (isWrunStyleParam(param)) {
|
|
169
|
+
const binding = wrunStyleBinding(param);
|
|
170
|
+
if (binding?.property === 'color')
|
|
171
|
+
return 'color';
|
|
172
|
+
return binding?.property === 'lineStyle' ? 'select' : 'number';
|
|
173
|
+
}
|
|
174
|
+
if (isWrunColorParam(param))
|
|
175
|
+
return 'color';
|
|
176
|
+
switch (param.type) {
|
|
177
|
+
case 'boolean':
|
|
178
|
+
return 'boolean';
|
|
179
|
+
case 'int':
|
|
180
|
+
return 'int';
|
|
181
|
+
case 'select':
|
|
182
|
+
return wrunParamChoices(param) === undefined ? 'number' : 'select';
|
|
183
|
+
case 'time':
|
|
184
|
+
return 'time';
|
|
185
|
+
case 'price':
|
|
186
|
+
return 'price';
|
|
187
|
+
case 'multi':
|
|
188
|
+
return wrunMultiLabels(param).length > 0 ? 'multi' : 'number';
|
|
189
|
+
case 'symbol':
|
|
190
|
+
return 'symbol';
|
|
191
|
+
case 'text':
|
|
192
|
+
return 'text';
|
|
193
|
+
default:
|
|
194
|
+
return 'number';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** A param's setting-words shape (wrun-setting-words.util): its control
|
|
198
|
+
* kind, its choices as the dialog's row lists them (a line-style knob's
|
|
199
|
+
* words, a select's option values and labels, a multi's bit labels), its
|
|
200
|
+
* declared default, and a session start or end as a clock. */
|
|
201
|
+
export function wrunParamWordsShape(param) {
|
|
202
|
+
const type = wrunParamControlType(param);
|
|
203
|
+
const shape = {
|
|
204
|
+
type,
|
|
205
|
+
defaultValue: param.default,
|
|
206
|
+
...(param.session_end === 'start' || param.session_end === 'end' ? { minutesOfDay: true } : {}),
|
|
207
|
+
};
|
|
208
|
+
if (type === 'select') {
|
|
209
|
+
if (isWrunStyleParam(param))
|
|
210
|
+
return { ...shape, options: wrunLineStyles() };
|
|
211
|
+
const choices = wrunParamChoices(param) ?? [];
|
|
212
|
+
return {
|
|
213
|
+
...shape,
|
|
214
|
+
options: choices.map((choice) => String(choice.value)),
|
|
215
|
+
optionLabels: choices.map((choice) => choice.label),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (type === 'multi') {
|
|
219
|
+
const labels = wrunMultiLabels(param);
|
|
220
|
+
return { ...shape, options: labels.map((_, at) => String(at)), optionLabels: labels };
|
|
221
|
+
}
|
|
222
|
+
return shape;
|
|
223
|
+
}
|
|
224
|
+
function numberConstraints(param, step) {
|
|
225
|
+
const constraints = {
|
|
226
|
+
...(typeof param.min === 'number' ? { min: param.min } : {}),
|
|
227
|
+
...(typeof param.max === 'number' ? { max: param.max } : {}),
|
|
228
|
+
...(typeof step === 'number' && Number.isFinite(step) && step > 0 ? { step } : {}),
|
|
229
|
+
};
|
|
230
|
+
return Object.keys(constraints).length > 0 ? constraints : undefined;
|
|
231
|
+
}
|
|
232
|
+
/** An om style knob's row: a colour row, a number field (width / opacity)
|
|
233
|
+
* or the line-style select, at its declared default. */
|
|
234
|
+
function styleKnobInput(param, base) {
|
|
235
|
+
const binding = wrunStyleBinding(param);
|
|
236
|
+
if (binding?.property === 'color') {
|
|
237
|
+
return { ...base, type: 'color', defaultValue: wrunColorSettingString(param.default) ?? '#000000' };
|
|
238
|
+
}
|
|
239
|
+
if (binding?.property === 'lineStyle') {
|
|
240
|
+
const options = wrunLineStyles();
|
|
241
|
+
const declared = typeof param.default === 'string' && options.includes(param.default) ? param.default : options[0];
|
|
242
|
+
return { ...base, type: 'select', defaultValue: declared, options };
|
|
243
|
+
}
|
|
244
|
+
const constraints = numberConstraints(param, param.step);
|
|
245
|
+
const fallback = typeof param.default === 'number' ? param.default : 0;
|
|
246
|
+
return { ...base, type: 'number', defaultValue: fallback, ...(constraints ? { constraints } : {}) };
|
|
247
|
+
}
|
|
248
|
+
/** The keys every row of a param carries: name, label (its own words, else
|
|
249
|
+
* the name read as words), group, the tier, the hint (its own, else the
|
|
250
|
+
* description), and the typed-inputs presentation keys when declared
|
|
251
|
+
* (absent keys stay absent). */
|
|
252
|
+
function rowBase(param, options) {
|
|
253
|
+
const group = nonEmptyString(param.group);
|
|
254
|
+
const label = nonEmptyString(param.label) ?? nameWords(param.name);
|
|
255
|
+
const hint = rowHint(param, label, options);
|
|
256
|
+
const row = nonEmptyString(param.row);
|
|
257
|
+
const when = nonEmptyString(param.when);
|
|
258
|
+
return {
|
|
259
|
+
name: param.name,
|
|
260
|
+
label,
|
|
261
|
+
...(group !== undefined ? { group } : {}),
|
|
262
|
+
settingsTier: 'refetch',
|
|
263
|
+
affectsCompute: true,
|
|
264
|
+
...(hint !== undefined ? { hint } : {}),
|
|
265
|
+
...(row !== undefined ? { row } : {}),
|
|
266
|
+
...(when !== undefined ? { when } : {}),
|
|
267
|
+
...(param.hide === true ? { hide: true } : {}),
|
|
268
|
+
...(param.slider === true ? { slider: true } : {}),
|
|
269
|
+
...(param.host === 'source' || param.host === 'interval' || param.host === 'symbol' ? { host: param.host } : {}),
|
|
270
|
+
...wrunRowVisibleBy(param.visible_by),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** A row's `visibleBy` from a declaration's `visible_by`: a copy of its size-unit list, nothing when
|
|
274
|
+
* the word is absent or holds no list. */
|
|
275
|
+
function wrunRowVisibleBy(visibleBy) {
|
|
276
|
+
const codes = visibleBy?.size_unit;
|
|
277
|
+
return Array.isArray(codes) ? { visibleBy: { size_unit: [...codes] } } : {};
|
|
278
|
+
}
|
|
279
|
+
/** The `<name>_unit` selects by the value param they qualify (`unit_for`). */
|
|
280
|
+
function unitSelectsByValue(params) {
|
|
281
|
+
const byValue = new Map();
|
|
282
|
+
const names = new Set(params.map((param) => param.name));
|
|
283
|
+
for (const param of params) {
|
|
284
|
+
const target = nonEmptyString(param.unit_for);
|
|
285
|
+
if (target !== undefined && names.has(target) && !byValue.has(target))
|
|
286
|
+
byValue.set(target, param);
|
|
287
|
+
}
|
|
288
|
+
return byValue;
|
|
289
|
+
}
|
|
290
|
+
/** The composite a param is a member of, if any. */
|
|
291
|
+
function compositeOf(param, unitSelects) {
|
|
292
|
+
const range = nonEmptyString(param.range);
|
|
293
|
+
if (range !== undefined && (param.range_end === 'lo' || param.range_end === 'hi'))
|
|
294
|
+
return { kind: 'range', name: range };
|
|
295
|
+
const list = nonEmptyString(param.list);
|
|
296
|
+
if (list !== undefined && (typeof param.list_index === 'number' || param.list_end === 'count')) {
|
|
297
|
+
return { kind: 'list', name: list };
|
|
298
|
+
}
|
|
299
|
+
const session = nonEmptyString(param.session);
|
|
300
|
+
if (session !== undefined &&
|
|
301
|
+
(param.session_end === 'start' || param.session_end === 'end' || param.session_end === 'tz')) {
|
|
302
|
+
return { kind: 'session', name: session };
|
|
303
|
+
}
|
|
304
|
+
if (unitSelects.has(param.name))
|
|
305
|
+
return { kind: 'unit', name: param.name };
|
|
306
|
+
const unitFor = nonEmptyString(param.unit_for);
|
|
307
|
+
if (unitFor !== undefined && unitSelects.get(unitFor) === param)
|
|
308
|
+
return { kind: 'unit', name: unitFor };
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
function numberDefault(param) {
|
|
312
|
+
return typeof param?.default === 'number' && Number.isFinite(param.default) ? param.default : 0;
|
|
313
|
+
}
|
|
314
|
+
/** A composite's own label: the first member's label, else the composite
|
|
315
|
+
* name read as words (the members' generated names never show; a
|
|
316
|
+
* description is the hint, never the label). */
|
|
317
|
+
function compositeLabel(members, name) {
|
|
318
|
+
return nonEmptyString(members[0]?.label) ?? nameWords(name);
|
|
319
|
+
}
|
|
320
|
+
/** The virtual composite row (holds no value; `members` hold theirs). */
|
|
321
|
+
function compositeRow(composite, params, unitSelects, options) {
|
|
322
|
+
const { kind, name } = composite;
|
|
323
|
+
const shared = (lead, members) => {
|
|
324
|
+
const { hint: _leadHint, ...base } = lead === undefined ? { name, label: name, hint: undefined } : rowBase(lead, options);
|
|
325
|
+
const label = compositeLabel(members, name);
|
|
326
|
+
// The lead member's hint (its own, else its description) against the composite's label.
|
|
327
|
+
const hint = lead === undefined ? undefined : rowHint(lead, label, options);
|
|
328
|
+
return {
|
|
329
|
+
...base,
|
|
330
|
+
name,
|
|
331
|
+
label,
|
|
332
|
+
...(hint !== undefined ? { hint } : {}),
|
|
333
|
+
settingsTier: 'refetch',
|
|
334
|
+
affectsCompute: true,
|
|
335
|
+
virtual: true,
|
|
336
|
+
// Members the author hid take their composite out of the dialog too.
|
|
337
|
+
...(members.length > 0 && members.every((member) => member.hidden === true) ? { hidden: true } : {}),
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
if (kind === 'range') {
|
|
341
|
+
const members = params.filter((param) => param.range === name);
|
|
342
|
+
const lo = members.find((param) => param.range_end === 'lo');
|
|
343
|
+
const hi = members.find((param) => param.range_end === 'hi');
|
|
344
|
+
const lead = lo ?? hi;
|
|
345
|
+
const constraints = lead === undefined ? undefined : numberConstraints(lead, lead.step);
|
|
346
|
+
return {
|
|
347
|
+
...shared(lead, members),
|
|
348
|
+
type: 'range',
|
|
349
|
+
defaultValue: [numberDefault(lo), numberDefault(hi)],
|
|
350
|
+
...(constraints ? { constraints } : {}),
|
|
351
|
+
members: [lo, hi].filter((param) => param !== undefined).map((param) => param.name),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
if (kind === 'list') {
|
|
355
|
+
const members = params.filter((param) => param.list === name);
|
|
356
|
+
const slots = members
|
|
357
|
+
.filter((param) => typeof param.list_index === 'number')
|
|
358
|
+
.sort((a, b) => a.list_index - b.list_index);
|
|
359
|
+
const count = members.find((param) => param.list_end === 'count');
|
|
360
|
+
const lead = slots[0] ?? count;
|
|
361
|
+
const constraints = slots[0] === undefined ? undefined : numberConstraints(slots[0], slots[0].step);
|
|
362
|
+
const declaredCount = Math.max(0, Math.min(slots.length, Math.round(numberDefault(count))));
|
|
363
|
+
return {
|
|
364
|
+
...shared(lead, members),
|
|
365
|
+
type: 'list',
|
|
366
|
+
defaultValue: slots.slice(0, count === undefined ? slots.length : declaredCount).map(numberDefault),
|
|
367
|
+
...(constraints ? { constraints } : {}),
|
|
368
|
+
members: [...slots, ...(count === undefined ? [] : [count])].map((param) => param.name),
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
if (kind === 'session') {
|
|
372
|
+
const members = params.filter((param) => param.session === name);
|
|
373
|
+
const start = members.find((param) => param.session_end === 'start');
|
|
374
|
+
const end = members.find((param) => param.session_end === 'end');
|
|
375
|
+
const tz = members.find((param) => param.session_end === 'tz');
|
|
376
|
+
// A zone the author hid is no part of the row: the strip draws no select for it, and its own
|
|
377
|
+
// hidden row keeps its value like any hidden param's.
|
|
378
|
+
const zone = tz?.hidden === true ? undefined : tz;
|
|
379
|
+
const choices = zone === undefined ? undefined : wrunParamChoices(zone);
|
|
380
|
+
return {
|
|
381
|
+
...shared(start ?? end ?? tz, members),
|
|
382
|
+
type: 'session',
|
|
383
|
+
defaultValue: [numberDefault(start), numberDefault(end), numberDefault(tz)],
|
|
384
|
+
...(choices !== undefined
|
|
385
|
+
? {
|
|
386
|
+
options: choices.map((choice) => String(choice.value)),
|
|
387
|
+
optionLabels: choices.map((choice) => choice.label),
|
|
388
|
+
}
|
|
389
|
+
: {}),
|
|
390
|
+
members: [start, end, zone]
|
|
391
|
+
.filter((param) => param !== undefined)
|
|
392
|
+
.map((param) => param.name),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const value = params.find((param) => param.name === name);
|
|
396
|
+
const unit = unitSelects.get(name);
|
|
397
|
+
const choices = wrunParamChoices(unit);
|
|
398
|
+
const constraints = numberConstraints(value, value.step ?? (value.type === 'int' ? 1 : undefined));
|
|
399
|
+
return {
|
|
400
|
+
...shared(value, [value, unit]),
|
|
401
|
+
type: 'unit',
|
|
402
|
+
defaultValue: [numberDefault(value), numberDefault(unit)],
|
|
403
|
+
...(constraints ? { constraints } : {}),
|
|
404
|
+
...(choices !== undefined
|
|
405
|
+
? { options: choices.map((choice) => String(choice.value)), optionLabels: choices.map((choice) => choice.label) }
|
|
406
|
+
: {}),
|
|
407
|
+
members: [value.name, unit.name],
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/** A bar's two-tone pair (contract C1), as declared: its sign palette
|
|
411
|
+
* (`colors` without a ladder: [0] at or above the base, [1] below; an entry
|
|
412
|
+
* past the second never draws) or a two-rung `color_by` ladder's table.
|
|
413
|
+
* Undefined for anything else: a packed per-bar colour, a ladder of three or
|
|
414
|
+
* more rungs, a table that is not all colour strings. */
|
|
415
|
+
function twoTonePair(output, kind) {
|
|
416
|
+
if (kind !== 'bar' || output.color_packed_by !== undefined || !Array.isArray(output.colors))
|
|
417
|
+
return undefined;
|
|
418
|
+
const colors = output.colors;
|
|
419
|
+
if (!colors.every((color) => nonEmptyString(color) !== undefined))
|
|
420
|
+
return undefined;
|
|
421
|
+
if (output.color_by !== undefined)
|
|
422
|
+
return colors.length === 2 ? [...colors] : undefined;
|
|
423
|
+
return colors.length >= 2 ? colors.slice(0, 2) : undefined;
|
|
424
|
+
}
|
|
425
|
+
/** True when a line strokes colours of its own and never reads its static
|
|
426
|
+
* `color` (style-rows audit item 3): two or more OT13 `gradient` stops (the
|
|
427
|
+
* look patch lays them as `gradientColors`, wrun-output-style.util) or an
|
|
428
|
+
* OT14 `split` (its `up_color` / `down_color` pair). Titan still honours the
|
|
429
|
+
* line's width and dash, and a declared opacity still fades the stops and
|
|
430
|
+
* the pair; any other output refuses both words. */
|
|
431
|
+
function strokesOwnColors(output) {
|
|
432
|
+
return (Array.isArray(output.gradient) && output.gradient.length >= 2) || output.split !== undefined;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* The style properties that PAINT for one drawn output, in dialog order: a
|
|
436
|
+
* row exists only where writing the output's key changes what the run-result
|
|
437
|
+
* adapter draws (utility/chart/wrun-run-result.util.ts), so the Style page
|
|
438
|
+
* never offers a control that does nothing.
|
|
439
|
+
* - `visible`: always.
|
|
440
|
+
* - `width`: the static width, unless a `width_by` ladder or a per-run
|
|
441
|
+
* `stroke_width_by` replaces it; never on a bar (its width is the bar
|
|
442
|
+
* spacing). A mark's width is its size, a candle group's the first
|
|
443
|
+
* output's.
|
|
444
|
+
* - `lineStyle`: line kinds only (the bar plotter reads no dash).
|
|
445
|
+
* - `color`: the static colour, unless per-bar colours replace it (a
|
|
446
|
+
* `color_by` ladder, a `color_packed_by` column, a bar's `colors` sign
|
|
447
|
+
* palette) or the line strokes its own (strokesOwnColors: OT13 gradient
|
|
448
|
+
* stops, an OT14 split's up / down pair; style-rows audit item 3), whose
|
|
449
|
+
* width, lineStyle and opacity rows stay; never on a candle group (its
|
|
450
|
+
* colours are a pair).
|
|
451
|
+
* - `colors`: a bar's two-tone pair (twoTonePair) in place of `color`: the
|
|
452
|
+
* up and down swatches of its sign palette, or the two rungs of its
|
|
453
|
+
* ladder.
|
|
454
|
+
* - `opacity`: it folds into the static colour (a gradient's stops and a
|
|
455
|
+
* split's pair alike) and an area's fill tint, so an area always carries
|
|
456
|
+
* it, a bar when its static colour paints, and a line or mark only when
|
|
457
|
+
* the sheet declares one (a declared opacity REPLACES the picked colour's
|
|
458
|
+
* alpha, so it needs its own control).
|
|
459
|
+
*/
|
|
460
|
+
function stylePropertiesOf(output, kind) {
|
|
461
|
+
const staticColor = kind !== 'candle' &&
|
|
462
|
+
output.color_by === undefined &&
|
|
463
|
+
output.color_packed_by === undefined &&
|
|
464
|
+
!(kind === 'bar' && Array.isArray(output.colors));
|
|
465
|
+
const staticWidth = kind !== 'bar' && output.width_by === undefined && output.stroke_width_by === undefined;
|
|
466
|
+
const opacity = kind === 'area' || (staticColor && (kind === 'bar' || output.opacity !== undefined));
|
|
467
|
+
return [
|
|
468
|
+
'visible',
|
|
469
|
+
...(staticWidth ? ['width'] : []),
|
|
470
|
+
...(kind === 'line' || kind === 'area' ? ['lineStyle'] : []),
|
|
471
|
+
...(staticColor && !strokesOwnColors(output) ? ['color'] : []),
|
|
472
|
+
...(twoTonePair(output, kind) !== undefined ? ['colors'] : []),
|
|
473
|
+
...(opacity ? ['opacity'] : []),
|
|
474
|
+
];
|
|
475
|
+
}
|
|
476
|
+
/** The default line palette for outputs without a declared colour, by
|
|
477
|
+
* declaration position: the run-result adapter's own table
|
|
478
|
+
* (utility/chart/wrun-run-result.util.ts WRUN_DEFAULT_PALETTE), mirrored
|
|
479
|
+
* here because that module imports this one. Pinned by the layout spec
|
|
480
|
+
* against wrunSheetLegendColors. */
|
|
481
|
+
const WRUN_OUTPUT_DEFAULT_PALETTE = [
|
|
482
|
+
'#ffc300',
|
|
483
|
+
'#4fc3f7',
|
|
484
|
+
'#a5d6a7',
|
|
485
|
+
'#f1627e',
|
|
486
|
+
'#ce93d8',
|
|
487
|
+
'#ffb74d',
|
|
488
|
+
'#80cbc4',
|
|
489
|
+
'#e6ee9c',
|
|
490
|
+
'#90caf9',
|
|
491
|
+
'#ef9a9a',
|
|
492
|
+
'#b0bec5',
|
|
493
|
+
'#fff176',
|
|
494
|
+
];
|
|
495
|
+
/** The sheet key each colour / width / opacity / line-style property paints,
|
|
496
|
+
* per section of the visibility table (the sheet's spelling: an output's
|
|
497
|
+
* `line_style`, a heatmap's `palette`, a profile's `buy_color` /
|
|
498
|
+
* `sell_color`). A section's target prefix and its entries are the table's
|
|
499
|
+
* (wrun-visibility-table.ts); `visible` paints every section's own
|
|
500
|
+
* `visible` key (an output's only through a boolean param that owns it,
|
|
501
|
+
* declaredStyleKnobs). */
|
|
502
|
+
const WRUN_STYLE_KEYS = {
|
|
503
|
+
outputs: new Map([
|
|
504
|
+
['color', 'color'],
|
|
505
|
+
['width', 'width'],
|
|
506
|
+
['line_style', 'lineStyle'],
|
|
507
|
+
// The om binding's spelling, read here as before.
|
|
508
|
+
['lineStyle', 'lineStyle'],
|
|
509
|
+
['opacity', 'opacity'],
|
|
510
|
+
['colors', 'colors'],
|
|
511
|
+
]),
|
|
512
|
+
renderers: new Map([['color', 'color']]),
|
|
513
|
+
heatmaps: new Map([['palette', 'colors']]),
|
|
514
|
+
profiles: new Map([
|
|
515
|
+
['buy_color', 'colors'],
|
|
516
|
+
['sell_color', 'colors'],
|
|
517
|
+
['palette', 'colors'],
|
|
518
|
+
]),
|
|
519
|
+
levels: new Map([['color', 'color']]),
|
|
520
|
+
// The batched sections (WRUN-BATCHED-MARKS): a mark's opacity is its `opacity_pct` (percent).
|
|
521
|
+
marks: new Map([
|
|
522
|
+
['colors', 'colors'],
|
|
523
|
+
['opacity_pct', 'opacity'],
|
|
524
|
+
]),
|
|
525
|
+
spans: new Map([
|
|
526
|
+
['colors', 'colors'],
|
|
527
|
+
['opacity', 'opacity'],
|
|
528
|
+
]),
|
|
529
|
+
rays: new Map([
|
|
530
|
+
['colors', 'colors'],
|
|
531
|
+
['opacity', 'opacity'],
|
|
532
|
+
['width', 'width'],
|
|
533
|
+
['line_style', 'lineStyle'],
|
|
534
|
+
]),
|
|
535
|
+
};
|
|
536
|
+
const WRUN_OUTPUT_STYLE_KEYS = WRUN_STYLE_KEYS.outputs;
|
|
537
|
+
/** An output style property word in either spelling: the om binding's
|
|
538
|
+
* (`lineStyle`) or the sheet output key's (`line_style`). `visible` is no
|
|
539
|
+
* param's to bind. */
|
|
540
|
+
function paintedPropertyOf(word) {
|
|
541
|
+
return typeof word === 'string' ? WRUN_OUTPUT_STYLE_KEYS.get(word) : undefined;
|
|
542
|
+
}
|
|
543
|
+
/** The output locations one param writes, read the way the paint seam reads
|
|
544
|
+
* a param's targets (wrun-color-settings.util paramTargets): its
|
|
545
|
+
* `style_targets` in either spelling (`{ path: ['outputs', name, key, ...] }`
|
|
546
|
+
* or the kit's `{ output, property }`), else its `paints` word (`"<output>"`
|
|
547
|
+
* = the colour, `"<output>.<key>"`), else an om style knob's own binding.
|
|
548
|
+
* `slot` marks a path into the key (`['outputs', o, 'colors', 0]`, one
|
|
549
|
+
* colour of a ladder). */
|
|
550
|
+
function paramOutputWrites(param) {
|
|
551
|
+
const writes = [];
|
|
552
|
+
const add = (output, word, slot = false) => {
|
|
553
|
+
if (typeof output === 'string' && output !== '')
|
|
554
|
+
writes.push({ output, word, slot });
|
|
555
|
+
};
|
|
556
|
+
const { style_targets: targets, paints } = param;
|
|
557
|
+
if (Array.isArray(targets)) {
|
|
558
|
+
for (const target of targets) {
|
|
559
|
+
if (!isRecord(target))
|
|
560
|
+
continue;
|
|
561
|
+
const path = target.path;
|
|
562
|
+
if (Array.isArray(path)) {
|
|
563
|
+
if (path.length >= 3 && path[0] === 'outputs')
|
|
564
|
+
add(path[1], path[2], path.length > 3);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
add(target.output, target.property);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else if (typeof paints === 'string' && paints !== '') {
|
|
572
|
+
const dot = paints.indexOf('.');
|
|
573
|
+
add(dot === -1 ? paints : paints.slice(0, dot), dot === -1 ? 'color' : paints.slice(dot + 1));
|
|
574
|
+
}
|
|
575
|
+
else if (isWrunStyleParam(param)) {
|
|
576
|
+
const binding = wrunStyleBinding(param);
|
|
577
|
+
if (binding !== undefined)
|
|
578
|
+
add(binding.output, binding.property);
|
|
579
|
+
}
|
|
580
|
+
return writes;
|
|
581
|
+
}
|
|
582
|
+
/** The name of a sheet container's entry a path segment addresses: the name
|
|
583
|
+
* itself, or the name of the entry at an index. */
|
|
584
|
+
function entryNameAt(entries, segment) {
|
|
585
|
+
if (typeof segment === 'string')
|
|
586
|
+
return nonEmptyString(segment);
|
|
587
|
+
if (typeof segment !== 'number' || !Array.isArray(entries))
|
|
588
|
+
return undefined;
|
|
589
|
+
const entry = entries[segment];
|
|
590
|
+
return isRecord(entry) ? nonEmptyString(entry.name) : undefined;
|
|
591
|
+
}
|
|
592
|
+
/** Every (target, property) the sheet's own params already control, read
|
|
593
|
+
* the way the paint seam reads a param's targets (wrun-color-settings.util
|
|
594
|
+
* paramTargets): its `style_targets` in either spelling (`{ path:
|
|
595
|
+
* [container, name or index, key] }`, an element of an array key included,
|
|
596
|
+
* or the kit's `{ output, property }`), else its `paints` word (`"<output>"`
|
|
597
|
+
* = the colour, `"<output>.<key>"`), else an om style knob's own binding.
|
|
598
|
+
* Unlike paramOutputWrites (the outputs a param joins on the Style page),
|
|
599
|
+
* every section of the visibility table counts, its entry named by the
|
|
600
|
+
* table's target (a band by its pair and ordinal, a handle kind by its
|
|
601
|
+
* kind), and one swatch of a `colors` pair counts as the pair. A target's
|
|
602
|
+
* `visible` counts for a boolean param that owns it (wrunVisibilityOwners:
|
|
603
|
+
* the one write the seam lands there), and past the outputs for any param
|
|
604
|
+
* that writes the key (a stats row's legacy 0..1 switch). A Style row for the
|
|
605
|
+
* same location would be a second control writing over the first. */
|
|
606
|
+
function declaredStyleKnobs(metadata) {
|
|
607
|
+
const declared = new Set();
|
|
608
|
+
for (const target of wrunVisibilityOwnedOutputs(metadata))
|
|
609
|
+
declared.add(`${target}.visible`);
|
|
610
|
+
const add = (output, word) => {
|
|
611
|
+
const property = paintedPropertyOf(word);
|
|
612
|
+
if (typeof output === 'string' && output !== '' && property !== undefined)
|
|
613
|
+
declared.add(`${output}.${property}`);
|
|
614
|
+
};
|
|
615
|
+
const addPath = (path) => {
|
|
616
|
+
const [container, entry, key] = path;
|
|
617
|
+
if (typeof container !== 'string' || typeof key !== 'string')
|
|
618
|
+
return;
|
|
619
|
+
const keys = WRUN_STYLE_KEYS[container];
|
|
620
|
+
const property = key === 'visible' && container !== 'outputs' ? 'visible' : keys?.get(key);
|
|
621
|
+
// A whole key, or one element of a list key (a palette stop, a swatch of a pair).
|
|
622
|
+
if (property === undefined || !(path.length === 3 || (path.length === 4 && property === 'colors')))
|
|
623
|
+
return;
|
|
624
|
+
if (container === 'outputs') {
|
|
625
|
+
const name = entryNameAt(metadata.outputs, entry);
|
|
626
|
+
if (name !== undefined)
|
|
627
|
+
declared.add(`${name}.${property}`);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
const target = wrunVisibilityTargetAt(metadata, container, entry);
|
|
631
|
+
if (target !== undefined)
|
|
632
|
+
declared.add(`${target.target}.${property}`);
|
|
633
|
+
};
|
|
634
|
+
for (const param of metadata.params ?? []) {
|
|
635
|
+
const { style_targets: styleTargets, paints } = param;
|
|
636
|
+
if (Array.isArray(styleTargets)) {
|
|
637
|
+
for (const target of styleTargets) {
|
|
638
|
+
if (!isRecord(target))
|
|
639
|
+
continue;
|
|
640
|
+
const path = target.path;
|
|
641
|
+
if (Array.isArray(path)) {
|
|
642
|
+
addPath(path);
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
add(target.output, target.property);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
else if (typeof paints === 'string' && paints !== '') {
|
|
650
|
+
const dot = paints.indexOf('.');
|
|
651
|
+
add(dot === -1 ? paints : paints.slice(0, dot), dot === -1 ? 'color' : paints.slice(dot + 1));
|
|
652
|
+
}
|
|
653
|
+
else if (isWrunStyleParam(param)) {
|
|
654
|
+
const binding = wrunStyleBinding(param);
|
|
655
|
+
if (binding !== undefined)
|
|
656
|
+
add(binding.output, binding.property);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return declared;
|
|
660
|
+
}
|
|
661
|
+
/** The width the engine draws an output of this kind at when the sheet
|
|
662
|
+
* declares none: titan's marker path sizes a mark at `width || 2`
|
|
663
|
+
* (kscriptRuntime markerSize), every stroke at `width || 1`. */
|
|
664
|
+
function undeclaredWidthOf(kind) {
|
|
665
|
+
return kind === 'mark' ? 2 : 1;
|
|
666
|
+
}
|
|
667
|
+
function styleRowDefault(output, paletteAt, property, kind) {
|
|
668
|
+
switch (property) {
|
|
669
|
+
case 'visible':
|
|
670
|
+
return output.visible !== false;
|
|
671
|
+
case 'width':
|
|
672
|
+
return finiteNumber(output.width) ?? undeclaredWidthOf(kind);
|
|
673
|
+
case 'lineStyle':
|
|
674
|
+
return typeof output.line_style === 'string' && wrunLineStyles().includes(output.line_style)
|
|
675
|
+
? output.line_style
|
|
676
|
+
: wrunLineStyles()[0];
|
|
677
|
+
case 'color':
|
|
678
|
+
return (nonEmptyString(output.color) ??
|
|
679
|
+
nonEmptyString(output.colors?.[0]) ??
|
|
680
|
+
WRUN_OUTPUT_DEFAULT_PALETTE[paletteAt % WRUN_OUTPUT_DEFAULT_PALETTE.length]);
|
|
681
|
+
case 'colors':
|
|
682
|
+
return twoTonePair(output, kind) ?? [];
|
|
683
|
+
default: {
|
|
684
|
+
const opacity = finiteNumber(output.opacity);
|
|
685
|
+
return opacity !== undefined && opacity >= 0 && opacity <= 1 ? opacity : 1;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/** One Style page row of a target at its default. Paint-only by
|
|
690
|
+
* construction: no init slot, it writes only its target's colour(s) /
|
|
691
|
+
* width / line_style / opacity through the paint seam, or its visibility
|
|
692
|
+
* after integration. */
|
|
693
|
+
function styleRowOf(target, property, defaultValue, swatches) {
|
|
694
|
+
return {
|
|
695
|
+
name: wrunStyleRowName(target, property),
|
|
696
|
+
// The property key: the dialog draws the frozen localized word for it.
|
|
697
|
+
label: property,
|
|
698
|
+
type: 'style',
|
|
699
|
+
defaultValue,
|
|
700
|
+
...(property === 'lineStyle' ? { options: wrunLineStyles() } : {}),
|
|
701
|
+
...(property === 'width' ? { constraints: { min: 0, max: 20, step: 0.5 } } : {}),
|
|
702
|
+
...(property === 'opacity' ? { constraints: { min: 0, max: 1, step: 0.05 } } : {}),
|
|
703
|
+
...(swatches !== undefined ? { swatches } : {}),
|
|
704
|
+
settingsTier: 'redraw',
|
|
705
|
+
affectsCompute: false,
|
|
706
|
+
styleOf: { output: target, property },
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function styleRow(output, paletteAt, property, kind) {
|
|
710
|
+
const swatches = property !== 'colors' ? undefined : output.color_by !== undefined ? ['stop', 'stop'] : ['up', 'down'];
|
|
711
|
+
return styleRowOf(output.name, property, styleRowDefault(output, paletteAt, property, kind), swatches);
|
|
712
|
+
}
|
|
713
|
+
/** A declared colour word, as written: a hex or rgb colour, or a theme
|
|
714
|
+
* token (`theme.up`); anything else (a number, an `@param` the extractor
|
|
715
|
+
* never resolved) is none. */
|
|
716
|
+
function colorWordOf(value) {
|
|
717
|
+
if (typeof value !== 'string')
|
|
718
|
+
return undefined;
|
|
719
|
+
return isWrunColorWord(value) || wrunColorSettingString(value) !== undefined ? value : undefined;
|
|
720
|
+
}
|
|
721
|
+
/** A batched section's declared colour as a row's settings string: a colour word as written, a
|
|
722
|
+
* packed number through the packed-colour decode (`#rrggbb`, or rgba), a packed theme token as its
|
|
723
|
+
* `theme.<token>` word; undefined for anything else. */
|
|
724
|
+
function batchedColorWordOf(value) {
|
|
725
|
+
if (typeof value === 'string')
|
|
726
|
+
return colorWordOf(value);
|
|
727
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
728
|
+
return undefined;
|
|
729
|
+
const token = wrunThemeTokenOfPacked(value);
|
|
730
|
+
return token !== null ? wrunThemeTokenWord(token) : wrunColorSettingString(value);
|
|
731
|
+
}
|
|
732
|
+
/** A batched section's declared colours, each as a settings string; undefined when the list is empty or
|
|
733
|
+
* any colour does not decode (the row would recolour the wrong swatch). */
|
|
734
|
+
function batchedColorsOf(value) {
|
|
735
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
736
|
+
return undefined;
|
|
737
|
+
const words = value.map(batchedColorWordOf);
|
|
738
|
+
return words.every((word) => word !== undefined) ? words : undefined;
|
|
739
|
+
}
|
|
740
|
+
/** A declared palette: two or more colour words, as written. */
|
|
741
|
+
function paletteOf(value) {
|
|
742
|
+
if (!Array.isArray(value) || value.length < 2)
|
|
743
|
+
return undefined;
|
|
744
|
+
const words = value.map(colorWordOf);
|
|
745
|
+
return words.every((word) => word !== undefined) ? words : undefined;
|
|
746
|
+
}
|
|
747
|
+
/** The text styles that draw through the price-tag path (wrun-handles.util
|
|
748
|
+
* wrunTextStyleIsPriceLabel), whose undeclared ink follows the theme
|
|
749
|
+
* instead of plain text's orange. */
|
|
750
|
+
const WRUN_PRICE_LABEL_TEXT_STYLES = new Set([
|
|
751
|
+
'price_label',
|
|
752
|
+
'callout',
|
|
753
|
+
'pill',
|
|
754
|
+
'badge',
|
|
755
|
+
'box',
|
|
756
|
+
'knockout',
|
|
757
|
+
'emblem',
|
|
758
|
+
]);
|
|
759
|
+
/** The colour titan draws a text or label renderer's record in when the
|
|
760
|
+
* renderer declares none: plain text's fixed `orange` (TextPlot), else (a
|
|
761
|
+
* price tag, a corner label) the theme's text ink, kept a theme token so it
|
|
762
|
+
* follows the theme (the paint seam writes no token, so an untouched row
|
|
763
|
+
* leaves the engine's own default in place). */
|
|
764
|
+
function undeclaredTextColorOf(renderer) {
|
|
765
|
+
const themed = (renderer.kind === 'label' && renderer.position !== undefined) ||
|
|
766
|
+
(typeof renderer.style === 'string' && WRUN_PRICE_LABEL_TEXT_STYLES.has(renderer.style));
|
|
767
|
+
return themed ? 'theme.text' : '#ffa500';
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* The Style rows of the sheet's other drawn targets, after the outputs'
|
|
771
|
+
* rows, one target at a time in the visibility table's order
|
|
772
|
+
* (wrun-visibility-table.ts wrunVisibilityTargets: the targets come from the
|
|
773
|
+
* table, never from a list here), each at its declaration's own values.
|
|
774
|
+
* Every drawn target offers Visible (default: its declaration's `visible`,
|
|
775
|
+
* on unless false), unless a param already writes it; the kinds that paint
|
|
776
|
+
* a colour, a width or a line style the builders read offer those rows too:
|
|
777
|
+
* - a text or label renderer (`text:<name>`): its colour unless per-record
|
|
778
|
+
* colours replace it (`color_by`, `color_packed_by`); a text renderer whose
|
|
779
|
+
* records only feed another's tooltips (`tooltip_from`) never draws and is
|
|
780
|
+
* no target; every other renderer kind (shape, bgcolor, barcolor, table,
|
|
781
|
+
* stats_row, inset) offers Visible only;
|
|
782
|
+
* - a heatmap (`heatmap:<name>`): its declared palette;
|
|
783
|
+
* - a price profile (`profile:<name>`): its colours: a footprint's buy /
|
|
784
|
+
* sell pair (theme up / down when undeclared, the canvas mount's rule)
|
|
785
|
+
* wherever it paints: never on a cluster, ladder or imbalance_only grid of
|
|
786
|
+
* volume or trades cells, which paint the volume colour
|
|
787
|
+
* (footprintPaintsVolumeColor, wrun-footprint-modes.util, the facts the
|
|
788
|
+
* mount door reads too; style-rows audit item 7), a volume profile's pair
|
|
789
|
+
* when it declares either, a TPO's declared palette;
|
|
790
|
+
* - a docked level (`levels:<name>`): its declared colour (a stacked level's
|
|
791
|
+
* colours ride its series). Gradient stops and an outline's border do not
|
|
792
|
+
* take it away: a pick paints every bar over the frame's row colours, the
|
|
793
|
+
* stops and the outline's border alike (wrun-levels-child.util; style-rows
|
|
794
|
+
* audit item 5);
|
|
795
|
+
* - a batched section (WRUN-BATCHED-MARKS: `marks:<name>`, `spans:<name>`,
|
|
796
|
+
* `rays:<name>`): its declared colours (a mark's [sell, buy] by side, a
|
|
797
|
+
* span's or ray's styles as stops; none when a colour does not decode) and
|
|
798
|
+
* its opacity (a mark's `opacity_pct` read as 0..1, default 0.3; a span's
|
|
799
|
+
* 0.2; a ray's 1: the kit's defaults, mirrored in wrun-batched-marks.util
|
|
800
|
+
* LOOK_DEFAULTS); a ray its width (default 1) and line style (default
|
|
801
|
+
* solid) too. Its look, size, caption and position take no row: a param
|
|
802
|
+
* binds them (`style_targets`);
|
|
803
|
+
* - a band (`range:<upper>/<lower>#<n>`, `fill:<first>/<second>#<n>`), a box,
|
|
804
|
+
* a segment, a sheet drawing, a draw-API handle kind, a matrix and a panel:
|
|
805
|
+
* Visible only (their colours ride params or the declaration).
|
|
806
|
+
*/
|
|
807
|
+
function childStyleRows(targets, declared) {
|
|
808
|
+
const rows = [];
|
|
809
|
+
const add = (target, property, defaultValue, swatches) => {
|
|
810
|
+
if (!declared.has(`${target}.${property}`))
|
|
811
|
+
rows.push(styleRowOf(target, property, defaultValue, swatches));
|
|
812
|
+
};
|
|
813
|
+
const stops = (palette) => palette.map(() => 'stop');
|
|
814
|
+
for (const { target, section, kind, entry } of targets) {
|
|
815
|
+
if (section === 'outputs')
|
|
816
|
+
continue;
|
|
817
|
+
add(target, 'visible', entry.visible !== false);
|
|
818
|
+
switch (section) {
|
|
819
|
+
case 'renderers':
|
|
820
|
+
if ((kind === 'text' || kind === 'label') &&
|
|
821
|
+
entry.color_by === undefined &&
|
|
822
|
+
entry.color_packed_by === undefined) {
|
|
823
|
+
add(target, 'color', colorWordOf(entry.color) ?? undeclaredTextColorOf(entry));
|
|
824
|
+
}
|
|
825
|
+
break;
|
|
826
|
+
case 'heatmaps': {
|
|
827
|
+
const palette = paletteOf(entry.palette);
|
|
828
|
+
if (palette !== undefined)
|
|
829
|
+
add(target, 'colors', palette, stops(palette));
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
case 'profiles': {
|
|
833
|
+
const buy = colorWordOf(entry.buy_color);
|
|
834
|
+
const sell = colorWordOf(entry.sell_color);
|
|
835
|
+
const pair = kind === 'footprint'
|
|
836
|
+
? !footprintPaintsVolumeColor(entry)
|
|
837
|
+
: kind === 'volume' && (buy !== undefined || sell !== undefined);
|
|
838
|
+
if (pair) {
|
|
839
|
+
add(target, 'colors', [buy ?? 'theme.up', sell ?? 'theme.down'], ['buy', 'sell']);
|
|
840
|
+
}
|
|
841
|
+
else if (kind === 'tpo') {
|
|
842
|
+
const palette = paletteOf(entry.palette);
|
|
843
|
+
if (palette !== undefined)
|
|
844
|
+
add(target, 'colors', palette, stops(palette));
|
|
845
|
+
}
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
case 'levels': {
|
|
849
|
+
const color = colorWordOf(entry.color);
|
|
850
|
+
if (color !== undefined && !Array.isArray(entry.series))
|
|
851
|
+
add(target, 'color', color);
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
case 'marks':
|
|
855
|
+
case 'spans':
|
|
856
|
+
case 'rays': {
|
|
857
|
+
const colors = batchedColorsOf(entry.colors);
|
|
858
|
+
if (colors !== undefined) {
|
|
859
|
+
const swatches = colors.map((_color, at) => section === 'marks' && at < 2 ? (at === 0 ? 'sell' : 'buy') : 'stop');
|
|
860
|
+
add(target, 'colors', colors, swatches);
|
|
861
|
+
}
|
|
862
|
+
const opacity = section === 'marks'
|
|
863
|
+
? (finiteNumber(entry.opacity_pct) ?? 30) / 100
|
|
864
|
+
: (finiteNumber(entry.opacity) ?? (section === 'spans' ? 0.2 : 1));
|
|
865
|
+
add(target, 'opacity', Math.min(1, Math.max(0, opacity)));
|
|
866
|
+
if (section === 'rays') {
|
|
867
|
+
add(target, 'width', finiteNumber(entry.width) ?? 1);
|
|
868
|
+
const lineStyle = typeof entry.line_style === 'string' ? entry.line_style : undefined;
|
|
869
|
+
add(target, 'lineStyle', lineStyle !== undefined && wrunLineStyles().includes(lineStyle) ? lineStyle : 'solid');
|
|
870
|
+
}
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
default:
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return rows;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Every drawn entry of a sheet as a Style target, in the visibility table's
|
|
881
|
+
* order (wrun-visibility-table.ts WRUN_VISIBILITY_RULES' key order, each
|
|
882
|
+
* section in declaration order, the outputs in output order): what the Style
|
|
883
|
+
* page offers a Visible row for, and what the visibility apply and the
|
|
884
|
+
* render selection read (wrun-run-result.util). Each entry through the
|
|
885
|
+
* table's one-entry read (wrunVisibilityEntryTarget, the frozen identities);
|
|
886
|
+
* the walk adds what only the whole sheet tells: a candle group draws once, as
|
|
887
|
+
* its first output, and a text renderer whose records only feed another's
|
|
888
|
+
* tooltips (`tooltip_from`) never mounts.
|
|
889
|
+
*/
|
|
890
|
+
export function wrunVisibilityTargets(sheet) {
|
|
891
|
+
const tooltipSources = new Set((Array.isArray(sheet.renderers) ? sheet.renderers : []).flatMap((renderer) => isRecord(renderer) && typeof renderer.tooltip_from === 'string' ? [renderer.tooltip_from] : []));
|
|
892
|
+
const targets = [];
|
|
893
|
+
for (const [section, rule] of Object.entries(WRUN_VISIBILITY_RULES)) {
|
|
894
|
+
if (rule === 'not-drawn')
|
|
895
|
+
continue;
|
|
896
|
+
const drawn = section;
|
|
897
|
+
if (drawn === 'outputs') {
|
|
898
|
+
targets.push(...outputVisibilityTargets(sheet));
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
const entries = sheet[drawn];
|
|
902
|
+
const count = drawn === 'handles' ? Object.keys(WRUN_HANDLE_KIND_RULES).length : Array.isArray(entries) ? entries.length : 0;
|
|
903
|
+
for (let at = 0; at < count; at += 1) {
|
|
904
|
+
const target = wrunVisibilityEntryTarget(sheet, drawn, at);
|
|
905
|
+
if (target === undefined)
|
|
906
|
+
continue;
|
|
907
|
+
if (drawn === 'renderers' && target.kind === 'text' && tooltipSources.has(String(target.entry.name)))
|
|
908
|
+
continue;
|
|
909
|
+
targets.push(target);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return targets;
|
|
913
|
+
}
|
|
914
|
+
/** The drawn outputs in output order (by `index`, else their place), a candle group once, as its first. */
|
|
915
|
+
function outputVisibilityTargets(sheet) {
|
|
916
|
+
const entries = Array.isArray(sheet.outputs) ? sheet.outputs : [];
|
|
917
|
+
const ordered = entries
|
|
918
|
+
.map((entry, at) => ({ entry, at }))
|
|
919
|
+
.filter(({ entry }) => isRecord(entry) && typeof entry.name === 'string')
|
|
920
|
+
.map(({ entry, at }) => ({ entry, at, index: finiteNumber(entry.index) ?? at }))
|
|
921
|
+
.sort((a, b) => a.index - b.index);
|
|
922
|
+
const targets = [];
|
|
923
|
+
let candleMembersLeft = 0;
|
|
924
|
+
for (const { entry, at } of ordered) {
|
|
925
|
+
if (candleMembersLeft > 0 && entry.plot === 'candle') {
|
|
926
|
+
candleMembersLeft -= 1;
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
candleMembersLeft = 0;
|
|
930
|
+
const target = wrunVisibilityEntryTarget(sheet, 'outputs', at);
|
|
931
|
+
if (target === undefined)
|
|
932
|
+
continue;
|
|
933
|
+
if (target.draw?.style === 'candle')
|
|
934
|
+
candleMembersLeft = 3;
|
|
935
|
+
targets.push(target);
|
|
936
|
+
}
|
|
937
|
+
return targets;
|
|
938
|
+
}
|
|
939
|
+
/** The sheet's drawn outputs in output order (the visibility table's output
|
|
940
|
+
* targets: a candle group as its first output, no data-only column, no
|
|
941
|
+
* transparent edge helper), each with its palette slot (the declaration
|
|
942
|
+
* position, data-only outputs holding theirs) and how it draws. */
|
|
943
|
+
function drawnStyleOutputs(metadata, targets = wrunVisibilityTargets(metadata)) {
|
|
944
|
+
const entries = Array.isArray(metadata.outputs) ? metadata.outputs : [];
|
|
945
|
+
const paletteSlots = new Map(entries
|
|
946
|
+
.map((output, position) => ({ position, index: isRecord(output) ? finiteNumber(output.index) : undefined }))
|
|
947
|
+
.filter(({ position }) => isRecord(entries[position]) && typeof entries[position].name === 'string')
|
|
948
|
+
.map(({ position, index }) => ({ position, index: index ?? position }))
|
|
949
|
+
.sort((a, b) => a.index - b.index)
|
|
950
|
+
.map(({ position }, paletteAt) => [position, paletteAt]));
|
|
951
|
+
return targets.flatMap((target) => target.section === 'outputs' && target.draw !== undefined
|
|
952
|
+
? [
|
|
953
|
+
{
|
|
954
|
+
output: target.entry,
|
|
955
|
+
paletteAt: paletteSlots.get(target.at) ?? target.at,
|
|
956
|
+
draw: target.draw,
|
|
957
|
+
},
|
|
958
|
+
]
|
|
959
|
+
: []);
|
|
960
|
+
}
|
|
961
|
+
/** The style rows of a sheet's drawn targets (wrun-visibility-table.ts, in
|
|
962
|
+
* its order): the outputs' rows, by how each draws (a candle tint and an
|
|
963
|
+
* inset strip offer Visible only), then every other drawn target's
|
|
964
|
+
* (childStyleRows). */
|
|
965
|
+
function styleRows(metadata) {
|
|
966
|
+
const targets = wrunVisibilityTargets(metadata);
|
|
967
|
+
const declared = declaredStyleKnobs(metadata);
|
|
968
|
+
const rows = [];
|
|
969
|
+
for (const { output, paletteAt, draw } of drawnStyleOutputs(metadata, targets)) {
|
|
970
|
+
const kind = draw.style;
|
|
971
|
+
for (const property of kind === undefined ? ['visible'] : stylePropertiesOf(output, kind)) {
|
|
972
|
+
if (declared.has(`${output.name}.${property}`))
|
|
973
|
+
continue;
|
|
974
|
+
// The output's `visible_by` rides its Style rows: where it mounts nothing, they hide.
|
|
975
|
+
rows.push({ ...styleRow(output, paletteAt, property, kind ?? 'line'), ...wrunRowVisibleBy(output.visible_by) });
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
rows.push(...childStyleRows(targets, declared));
|
|
979
|
+
return rows;
|
|
980
|
+
}
|
|
981
|
+
/** The sections whose readout `label` titles their Style line. */
|
|
982
|
+
const LABELLED_STYLE_SECTIONS = new Set(['heatmaps', 'marks', 'spans', 'rays']);
|
|
983
|
+
/** A draw-API handle kind's Style line title, the dialog's English fallback
|
|
984
|
+
* (WrunLayoutPanel localizes a handles section by its id). */
|
|
985
|
+
const HANDLE_STYLE_TITLES = {
|
|
986
|
+
line: 'Lines',
|
|
987
|
+
box: 'Boxes',
|
|
988
|
+
label: 'Labels',
|
|
989
|
+
polyline: 'Polylines',
|
|
990
|
+
};
|
|
991
|
+
/** True for a Style target whose line the dialog titles with its own localized words (a draw-API
|
|
992
|
+
* handle kind): its section carries the target as its `id`. */
|
|
993
|
+
export function isWrunLocalizedStyleTarget(target) {
|
|
994
|
+
return parseWrunStyleTarget(target).kind === 'handles';
|
|
995
|
+
}
|
|
996
|
+
/** A style target as the Style page names it, the legend's rule
|
|
997
|
+
* (wrunLegendName: a declared label, else the name read as words, `oi_change`
|
|
998
|
+
* -> "OI change"): an output by its `label`, a heatmap or a batched section by
|
|
999
|
+
* its readout `label`, a band by its sides' names (`Upper / Lower`; a range
|
|
1000
|
+
* by its own `label` when it declares one; a second band over the same pair
|
|
1001
|
+
* numbered), a sheet drawing by its name, a handle kind by its kind's word,
|
|
1002
|
+
* anything else (a renderer, a profile, a docked level, a box, a segment, a
|
|
1003
|
+
* matrix, a panel) by its name. */
|
|
1004
|
+
function styleTargetTitle(metadata, target) {
|
|
1005
|
+
const { kind, name } = parseWrunStyleTarget(target);
|
|
1006
|
+
const outputTitle = (output) => {
|
|
1007
|
+
const entry = (Array.isArray(metadata.outputs) ? metadata.outputs : []).find((candidate) => isRecord(candidate) && candidate.name === output);
|
|
1008
|
+
return wrunLegendName(output, entry?.label);
|
|
1009
|
+
};
|
|
1010
|
+
if (kind === 'output' || kind === 'unknown')
|
|
1011
|
+
return outputTitle(target);
|
|
1012
|
+
if (kind === 'fill' || kind === 'range') {
|
|
1013
|
+
const hash = name.lastIndexOf('#');
|
|
1014
|
+
const ordinal = hash === -1 ? 0 : Number(name.slice(hash + 1));
|
|
1015
|
+
const [first, second] = (hash === -1 ? name : name.slice(0, hash)).split('/');
|
|
1016
|
+
const declared = kind === 'range' ? findWrunVisibilityTarget(metadata, target)?.entry.label : undefined;
|
|
1017
|
+
const title = typeof declared === 'string' && declared.trim() !== ''
|
|
1018
|
+
? declared
|
|
1019
|
+
: `${outputTitle(first ?? '')} / ${outputTitle(second ?? '')}`;
|
|
1020
|
+
return Number.isFinite(ordinal) && ordinal > 0 ? `${title} (${ordinal + 1})` : title;
|
|
1021
|
+
}
|
|
1022
|
+
if (kind === 'handles')
|
|
1023
|
+
return HANDLE_STYLE_TITLES[name] ?? wrunLegendName(name);
|
|
1024
|
+
if (kind === 'drawing')
|
|
1025
|
+
return wrunLegendName(name.slice(name.indexOf(':') + 1));
|
|
1026
|
+
const found = findWrunVisibilityTarget(metadata, target);
|
|
1027
|
+
const labelled = found !== undefined && LABELLED_STYLE_SECTIONS.has(found.section) ? found.entry.label : undefined;
|
|
1028
|
+
return wrunLegendName(name, typeof labelled === 'string' ? labelled : undefined);
|
|
1029
|
+
}
|
|
1030
|
+
// ---------------------------------------------------------------------------
|
|
1031
|
+
// The flat list (the persistence whitelist).
|
|
1032
|
+
// ---------------------------------------------------------------------------
|
|
1033
|
+
/** The overlay's scriptInputs for a sheet (what the settings dialog renders
|
|
1034
|
+
* and the persist whitelist names), in param order: a colour-array row sits
|
|
1035
|
+
* at its first member's position, a composite row at its first member's
|
|
1036
|
+
* followed by the members' hidden rows, the style rows after every param.
|
|
1037
|
+
* A param row refetches (a compute param always reaches init(), and a
|
|
1038
|
+
* colour param's pick is an init arg the module may read besides the sheet
|
|
1039
|
+
* locations it paints). A style row is the redraw tier: a save whose every
|
|
1040
|
+
* changed row is one (or an om style knob) restyles the mounted outputs in
|
|
1041
|
+
* place from the sheet the new settings paint (wrunSheetWithSettings,
|
|
1042
|
+
* wrun-style-patch.util), and anything that patch cannot reach reruns. */
|
|
1043
|
+
export function buildWrunScriptInputs(metadata, options) {
|
|
1044
|
+
const params = metadata.params ?? [];
|
|
1045
|
+
const rows = [];
|
|
1046
|
+
const colorArrays = new Map();
|
|
1047
|
+
const composites = new Set();
|
|
1048
|
+
const unitSelects = unitSelectsByValue(params);
|
|
1049
|
+
for (const param of params) {
|
|
1050
|
+
// A param named after a provenance key (`builtinTwinOf`, `wrunRegistryRef`, ...) is never a settings row: the
|
|
1051
|
+
// dialog would write its value over the key that says which script the overlay runs.
|
|
1052
|
+
if (isReservedKScriptProvenanceKey(param.name))
|
|
1053
|
+
continue;
|
|
1054
|
+
const base = rowBase(param, options);
|
|
1055
|
+
const arrayKey = wrunColorArrayKey(param);
|
|
1056
|
+
if (arrayKey !== undefined) {
|
|
1057
|
+
if (isReservedKScriptProvenanceKey(arrayKey))
|
|
1058
|
+
continue;
|
|
1059
|
+
const row = colorArrays.get(arrayKey);
|
|
1060
|
+
if (row) {
|
|
1061
|
+
row.defaultValue.push(wrunColorParamDefault(param));
|
|
1062
|
+
row.members.push(param.name);
|
|
1063
|
+
}
|
|
1064
|
+
else {
|
|
1065
|
+
// The row stands for the kScript `color[]` input named by the key:
|
|
1066
|
+
// the first member's label, else that key read as words. Its members
|
|
1067
|
+
// are the member params in element order (C1: "a `color[]` row
|
|
1068
|
+
// carries `members: string[]`"), the names a lane without the sheet
|
|
1069
|
+
// packs element i under (wrunSheetParamsFromDeclarations).
|
|
1070
|
+
const label = nonEmptyString(param.label) ?? nameWords(arrayKey);
|
|
1071
|
+
const hint = rowHint(param, label, options);
|
|
1072
|
+
const { hint: _memberHint, ...shared } = base;
|
|
1073
|
+
const created = {
|
|
1074
|
+
...shared,
|
|
1075
|
+
name: arrayKey,
|
|
1076
|
+
label,
|
|
1077
|
+
...(hint !== undefined ? { hint } : {}),
|
|
1078
|
+
type: 'color[]',
|
|
1079
|
+
defaultValue: [wrunColorParamDefault(param)],
|
|
1080
|
+
members: [param.name],
|
|
1081
|
+
};
|
|
1082
|
+
colorArrays.set(arrayKey, created);
|
|
1083
|
+
rows.push(created);
|
|
1084
|
+
}
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
const composite = compositeOf(param, unitSelects);
|
|
1088
|
+
if (composite !== undefined) {
|
|
1089
|
+
const key = `${composite.kind}:${composite.name}`;
|
|
1090
|
+
if (!composites.has(key)) {
|
|
1091
|
+
composites.add(key);
|
|
1092
|
+
rows.push(compositeRow(composite, params, unitSelects, options));
|
|
1093
|
+
}
|
|
1094
|
+
rows.push({ ...paramInput(param, base), hidden: true });
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
const input = paramInput(param, base);
|
|
1098
|
+
rows.push(param.hidden === true || param.host_fill !== undefined ? { ...input, hidden: true } : input);
|
|
1099
|
+
}
|
|
1100
|
+
rows.push(...styleRows(metadata));
|
|
1101
|
+
return rows;
|
|
1102
|
+
}
|
|
1103
|
+
/** The rows as the dialog shows them on a market of size unit `sizeUnit` (wrunChartSizeUnit): a
|
|
1104
|
+
* row whose `visibleBy` leaves the unit out is hidden like a composite member, never placed, its
|
|
1105
|
+
* value kept (the run still reads it and the dialog's Reset still resets it). The rows themselves
|
|
1106
|
+
* when none hides. */
|
|
1107
|
+
export function wrunRowsOnMarket(rows, sizeUnit) {
|
|
1108
|
+
const hides = (row) => row.hidden !== true && !wrunRowVisibleHere(row.visibleBy, sizeUnit);
|
|
1109
|
+
if (!rows.some(hides))
|
|
1110
|
+
return rows;
|
|
1111
|
+
return rows.map((row) => (hides(row) ? { ...row, hidden: true } : row));
|
|
1112
|
+
}
|
|
1113
|
+
function paramInput(param, base) {
|
|
1114
|
+
if (isWrunStyleParam(param))
|
|
1115
|
+
return styleKnobInput(param, base);
|
|
1116
|
+
const fallback = typeof param.default === 'number' ? param.default : 0;
|
|
1117
|
+
switch (wrunParamControlType(param)) {
|
|
1118
|
+
case 'color':
|
|
1119
|
+
return { ...base, type: 'color', defaultValue: wrunColorParamDefault(param) };
|
|
1120
|
+
case 'boolean':
|
|
1121
|
+
return { ...base, type: 'boolean', defaultValue: fallback !== 0 };
|
|
1122
|
+
case 'select': {
|
|
1123
|
+
const choices = wrunParamChoices(param);
|
|
1124
|
+
return {
|
|
1125
|
+
...base,
|
|
1126
|
+
type: 'select',
|
|
1127
|
+
defaultValue: String(param.default ?? choices[0].value),
|
|
1128
|
+
options: choices.map((choice) => String(choice.value)),
|
|
1129
|
+
optionLabels: choices.map((choice) => choice.label),
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
case 'int': {
|
|
1133
|
+
const constraints = numberConstraints(param, param.step ?? 1);
|
|
1134
|
+
return { ...base, type: 'int', defaultValue: fallback, ...(constraints ? { constraints } : {}) };
|
|
1135
|
+
}
|
|
1136
|
+
case 'time': {
|
|
1137
|
+
const constraints = numberConstraints(param, undefined);
|
|
1138
|
+
return { ...base, type: 'time', defaultValue: fallback, ...(constraints ? { constraints } : {}) };
|
|
1139
|
+
}
|
|
1140
|
+
case 'price': {
|
|
1141
|
+
const constraints = numberConstraints(param, param.step);
|
|
1142
|
+
return { ...base, type: 'price', defaultValue: fallback, ...(constraints ? { constraints } : {}) };
|
|
1143
|
+
}
|
|
1144
|
+
case 'multi': {
|
|
1145
|
+
const labels = wrunMultiLabels(param);
|
|
1146
|
+
return {
|
|
1147
|
+
...base,
|
|
1148
|
+
type: 'multi',
|
|
1149
|
+
defaultValue: fallback,
|
|
1150
|
+
options: labels.map((_, at) => String(at)),
|
|
1151
|
+
optionLabels: labels,
|
|
1152
|
+
constraints: { min: 0, max: 2 ** labels.length - 1 },
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
case 'symbol':
|
|
1156
|
+
return { ...base, type: 'symbol', defaultValue: nonEmptyString(param.symbol_default) ?? '' };
|
|
1157
|
+
case 'text':
|
|
1158
|
+
// The declared words as the row's default (plain), the byte cap and
|
|
1159
|
+
// the line mode the control enforces; the sheet's `default` (0, the
|
|
1160
|
+
// byte count slot) never reaches the row. The row rides the cloud
|
|
1161
|
+
// createScript wire as the host's `scriptInputs` entry for the param
|
|
1162
|
+
// (`{ type: "text", defaultValue, maxBytes, multiline, settingsTier }`),
|
|
1163
|
+
// so every key is spelled out.
|
|
1164
|
+
return {
|
|
1165
|
+
...base,
|
|
1166
|
+
type: 'text',
|
|
1167
|
+
defaultValue: wrunTextParamDefault(param),
|
|
1168
|
+
maxBytes: wrunTextParamCap(param),
|
|
1169
|
+
multiline: param.multiline === true,
|
|
1170
|
+
};
|
|
1171
|
+
default: {
|
|
1172
|
+
const constraints = numberConstraints(param, param.step);
|
|
1173
|
+
return { ...base, type: 'number', defaultValue: fallback, ...(constraints ? { constraints } : {}) };
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* The rows an overlay persisted, drawn with the sheet's words: every row the
|
|
1179
|
+
* sheet builds now (a param, a composite, a colour array, a member) takes
|
|
1180
|
+
* its label and hint from that build, matched by name (a unit composite and
|
|
1181
|
+
* its value member, which share a name, each from its own kind). An older
|
|
1182
|
+
* build stamped a param's description as its label and no hint; the saved
|
|
1183
|
+
* indicator reads the same as a fresh add without a rerun. Values, types and
|
|
1184
|
+
* every other key stay as persisted; a style row (its label is its property
|
|
1185
|
+
* key) and a row the sheet no longer builds keep their own; a row whose
|
|
1186
|
+
* words already match is returned as is. `options` builds the words as the
|
|
1187
|
+
* mount did (a port's hint rule, WrunRowBuildOptions), so a row persisted
|
|
1188
|
+
* before the rule reads without its encoding legend.
|
|
1189
|
+
*/
|
|
1190
|
+
export function wrunRowsWithSheetWords(rows, sheet, options) {
|
|
1191
|
+
if (sheet === undefined || !Array.isArray(sheet.params) || sheet.params.length === 0)
|
|
1192
|
+
return [...rows];
|
|
1193
|
+
const keyOf = (row) => `${row.virtual === true ? 'virtual' : 'value'}:${row.name}`;
|
|
1194
|
+
const fresh = new Map();
|
|
1195
|
+
for (const row of buildWrunScriptInputs({ params: sheet.params }, options)) {
|
|
1196
|
+
if (row.styleOf === undefined && !fresh.has(keyOf(row)))
|
|
1197
|
+
fresh.set(keyOf(row), row);
|
|
1198
|
+
}
|
|
1199
|
+
return rows.map((row) => {
|
|
1200
|
+
const built = row.styleOf === undefined ? fresh.get(keyOf(row)) : undefined;
|
|
1201
|
+
if (built === undefined || (row.label === built.label && row.hint === built.hint))
|
|
1202
|
+
return row;
|
|
1203
|
+
const { hint: _persistedHint, ...rest } = row;
|
|
1204
|
+
return { ...rest, label: built.label, ...(built.hint !== undefined ? { hint: built.hint } : {}) };
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* The rows an overlay persisted, with every Style row its sheet offers now
|
|
1209
|
+
* that they lack appended in the builder's order: an overlay added before a
|
|
1210
|
+
* kind had a Visible row (a band, a box, a shape or table renderer, a
|
|
1211
|
+
* drawing, a handle kind) gains it when the settings dialog opens, without a
|
|
1212
|
+
* rerun or a fresh add. A row that exists is never rewritten (its value, its
|
|
1213
|
+
* words and its place stay) and no param row is ever added (the mount and
|
|
1214
|
+
* the cloud reconcile own those). The rows themselves (the same array) when
|
|
1215
|
+
* nothing is missing or the sheet is unknown, so a caller's change test is
|
|
1216
|
+
* one identity check.
|
|
1217
|
+
*/
|
|
1218
|
+
export function wrunRowsWithMissingStyleRows(rows, sheet) {
|
|
1219
|
+
if (sheet === undefined)
|
|
1220
|
+
return rows;
|
|
1221
|
+
const present = new Set(rows.flatMap((row) => (typeof row.name === 'string' ? [row.name] : [])));
|
|
1222
|
+
const missing = styleRows(sheet).filter((row) => !present.has(row.name));
|
|
1223
|
+
return missing.length === 0 ? rows : [...rows, ...missing];
|
|
1224
|
+
}
|
|
1225
|
+
// ---------------------------------------------------------------------------
|
|
1226
|
+
// The layout: pages and sections.
|
|
1227
|
+
// ---------------------------------------------------------------------------
|
|
1228
|
+
/** The built-in pages' own titles (English: the dialog draws each page's localized word by its id). */
|
|
1229
|
+
const WRUN_GENERAL_PAGE_TITLE = 'General';
|
|
1230
|
+
const WRUN_STYLE_PAGE_TITLE = 'Style';
|
|
1231
|
+
/**
|
|
1232
|
+
* The built-in page an author's page or group tab names: its title is a built-in page's title, General
|
|
1233
|
+
* or Style, or the word the dialog shows the Style page under (`styleWord`), trimmed and in any case.
|
|
1234
|
+
* Its rows land on that page: as a page of its own it would draw a second tab under the built-in
|
|
1235
|
+
* page's label, with an id like `general-2`. Any other name is the author's own page.
|
|
1236
|
+
*/
|
|
1237
|
+
function builtInPageId(title, styleWord) {
|
|
1238
|
+
const name = title.trim().toLowerCase();
|
|
1239
|
+
if (name === WRUN_GENERAL_PAGE_TITLE.toLowerCase())
|
|
1240
|
+
return WRUN_GENERAL_PAGE_ID;
|
|
1241
|
+
const styleNames = [WRUN_STYLE_PAGE_TITLE, styleWord ?? ''].map((word) => word.trim().toLowerCase());
|
|
1242
|
+
return name !== '' && styleNames.includes(name) ? WRUN_STYLE_PAGE_ID : undefined;
|
|
1243
|
+
}
|
|
1244
|
+
function pageSlug(title, taken) {
|
|
1245
|
+
const base = title
|
|
1246
|
+
.trim()
|
|
1247
|
+
.toLowerCase()
|
|
1248
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
1249
|
+
.replace(/^-+|-+$/g, '') || 'page';
|
|
1250
|
+
let slug = base;
|
|
1251
|
+
for (let n = 2; taken.has(slug); n += 1)
|
|
1252
|
+
slug = `${base}-${n}`;
|
|
1253
|
+
taken.add(slug);
|
|
1254
|
+
return slug;
|
|
1255
|
+
}
|
|
1256
|
+
function layoutEntries(metadata) {
|
|
1257
|
+
return Array.isArray(metadata.layout) ? metadata.layout.filter((entry) => isRecord(entry)) : [];
|
|
1258
|
+
}
|
|
1259
|
+
/** A style line's knobs, left to right (stylePropertiesOf's order). */
|
|
1260
|
+
const STYLE_LINE_KNOBS = [
|
|
1261
|
+
'visible',
|
|
1262
|
+
'width',
|
|
1263
|
+
'lineStyle',
|
|
1264
|
+
'color',
|
|
1265
|
+
'colors',
|
|
1266
|
+
'opacity',
|
|
1267
|
+
];
|
|
1268
|
+
/**
|
|
1269
|
+
* The rows of a sheet without a declared layout that belong on the Style
|
|
1270
|
+
* page beside the outputs they paint (223, 224: a colour on its group page
|
|
1271
|
+
* while the output's Style line held its toggle): a boolean param that owns
|
|
1272
|
+
* outputs' visibility (wrunVisibilityOwners) IS their Visible row, in the
|
|
1273
|
+
* first drawn one's Visible slot; a row whose param (every member of a
|
|
1274
|
+
* colour array) writes exactly one drawn output joins that output's line, at
|
|
1275
|
+
* the knob of the property it writes (a ladder slot or an unnamed key reads
|
|
1276
|
+
* as the colour for a colour row); a colour row over several drawn outputs
|
|
1277
|
+
* goes to the shared colours section (ruled 2026-10-05); any other row over
|
|
1278
|
+
* several drawn outputs joins the first one's line only when they read as
|
|
1279
|
+
* one line (sharedLineKnob). Locations that draw no Style line (renderers,
|
|
1280
|
+
* boxes, data-only outputs) do not count; any other row stays on its group
|
|
1281
|
+
* page.
|
|
1282
|
+
*/
|
|
1283
|
+
function stylePlacements(metadata, rows, drawn) {
|
|
1284
|
+
const placements = new Map();
|
|
1285
|
+
if (drawn.size === 0)
|
|
1286
|
+
return placements;
|
|
1287
|
+
const params = metadata.params ?? [];
|
|
1288
|
+
const owners = wrunVisibilityOwners(metadata);
|
|
1289
|
+
for (const row of rows) {
|
|
1290
|
+
if (row.virtual === true)
|
|
1291
|
+
continue;
|
|
1292
|
+
const visibleOf = row.type === 'boolean' ? owners.get(row.name)?.find((output) => drawn.has(output)) : undefined;
|
|
1293
|
+
if (visibleOf !== undefined) {
|
|
1294
|
+
placements.set(row, { output: visibleOf, property: 'visible' });
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
const members = row.type === 'color[]'
|
|
1298
|
+
? params.filter((param) => wrunColorArrayKey(param) === row.name)
|
|
1299
|
+
: params.filter((param) => param.name === row.name);
|
|
1300
|
+
const painted = new Map();
|
|
1301
|
+
for (const member of members) {
|
|
1302
|
+
for (const write of paramOutputWrites(member)) {
|
|
1303
|
+
if (!drawn.has(write.output) || painted.get(write.output) !== undefined)
|
|
1304
|
+
continue;
|
|
1305
|
+
painted.set(write.output, write.slot ? undefined : paintedPropertyOf(write.word));
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
const colour = row.type === 'color' || row.type === 'color[]';
|
|
1309
|
+
if (painted.size === 1) {
|
|
1310
|
+
const [[output, property]] = painted;
|
|
1311
|
+
placements.set(row, { output, property: property ?? (colour ? 'color' : undefined) });
|
|
1312
|
+
}
|
|
1313
|
+
else if (painted.size > 1 && colour) {
|
|
1314
|
+
placements.set(row, 'colors');
|
|
1315
|
+
}
|
|
1316
|
+
else if (painted.size > 1) {
|
|
1317
|
+
const shared = sharedLineKnob(metadata, painted);
|
|
1318
|
+
if (shared !== undefined)
|
|
1319
|
+
placements.set(row, shared);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return placements;
|
|
1323
|
+
}
|
|
1324
|
+
/** Where a param over several drawn outputs joins the Style page: the first
|
|
1325
|
+
* one's line at the knob it writes, when every output takes the same
|
|
1326
|
+
* property and the outputs read as one line (one title by the legend's
|
|
1327
|
+
* rule: a line and its unshifted twin, both "Chikou"). A param over lines
|
|
1328
|
+
* the page names apart (one Width for every line) stays on its page. */
|
|
1329
|
+
function sharedLineKnob(metadata, painted) {
|
|
1330
|
+
const properties = new Set(painted.values());
|
|
1331
|
+
const titles = new Set([...painted.keys()].map((output) => styleTargetTitle(metadata, output)));
|
|
1332
|
+
const [property] = properties;
|
|
1333
|
+
const [output] = painted.keys();
|
|
1334
|
+
return properties.size === 1 && property !== undefined && titles.size === 1 ? { output, property } : undefined;
|
|
1335
|
+
}
|
|
1336
|
+
/** A colour row whose words say nothing beyond its kind: "Color" (either spelling, plural too), or no
|
|
1337
|
+
* words at all beyond its name read as words. */
|
|
1338
|
+
function isBareColorLabel(row) {
|
|
1339
|
+
return /^colou?rs?$/i.test(wrunRowLabel(row).trim());
|
|
1340
|
+
}
|
|
1341
|
+
/** The words after a group's word: a capitalized first word steps down ("Line color" -> "line color"),
|
|
1342
|
+
* an acronym or a one-letter word stays ("ATR color", "A color"). */
|
|
1343
|
+
function lowerFirstWord(words) {
|
|
1344
|
+
return /^[A-Z][a-z]/.test(words) ? words.charAt(0).toLowerCase() + words.slice(1) : words;
|
|
1345
|
+
}
|
|
1346
|
+
/** The group tab a row's `group` names ("Tab/Section" -> "Tab"), undefined when ungrouped. */
|
|
1347
|
+
function groupTabOf(row) {
|
|
1348
|
+
const raw = (row.group ?? '').trim();
|
|
1349
|
+
const tab = raw.includes('/') ? raw.slice(0, raw.indexOf('/')).trim() : raw;
|
|
1350
|
+
return tab === '' ? undefined : tab;
|
|
1351
|
+
}
|
|
1352
|
+
function sheetPresets(metadata) {
|
|
1353
|
+
return (Array.isArray(metadata.presets) ? metadata.presets : [])
|
|
1354
|
+
.filter((preset) => isRecord(preset) && nonEmptyString(preset.name) !== undefined && isRecord(preset.values))
|
|
1355
|
+
.map((preset) => ({ name: preset.name, values: { ...preset.values } }));
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* The dialog layout of a sheet's rows: pages of sections of rows (copies of
|
|
1359
|
+
* the flat declarations, `page` / `section` / `order` set, `pick` on time /
|
|
1360
|
+
* price rows). The same layout on both lanes: the cloud applies every
|
|
1361
|
+
* host-applied pick the browser applies (a source or timeframe pick as its
|
|
1362
|
+
* select index, a market pick as its `EXCHANGE:SYMBOL` text, frozen contract
|
|
1363
|
+
* C1 of WRUN-PARITY-PLAN), so no row carries a lane hint and `cloudRun`
|
|
1364
|
+
* changes nothing (kept so the dialog's call compiles until it drops it).
|
|
1365
|
+
* With a sheet `layout`: pages, sections, dividers and notes in source
|
|
1366
|
+
* order, params before the first page on the 'general' page, a param the
|
|
1367
|
+
* layout never names appended there; a param a section names as its
|
|
1368
|
+
* `toggle` is drawn by that section's header and never as a row of its own.
|
|
1369
|
+
* Without one: one page per `group` tab
|
|
1370
|
+
* ('general' first, then first appearance), "Tab/Section" nesting a section,
|
|
1371
|
+
* exactly the tabs the dialog drew before layouts, except that a param that
|
|
1372
|
+
* paints a drawn output sits on the Style page (stylePlacements: on that
|
|
1373
|
+
* output's line, or in the shared colours section that opens the page) and a
|
|
1374
|
+
* group page left empty never appears. Hidden rows (composite members,
|
|
1375
|
+
* host-filled and author-hidden params, and any row, a Style row included,
|
|
1376
|
+
* the dialog hides on the chart's market) are never placed. The 'style' page
|
|
1377
|
+
* follows when style rows exist, one section per styled target that holds a
|
|
1378
|
+
* row (a drawn output whose every knob a param owns counts: the params
|
|
1379
|
+
* placed on its line), titled by the legend's rule (styleTargetTitle). A
|
|
1380
|
+
* page or group tab named as a built-in page (builtInPageId: General or
|
|
1381
|
+
* Style, or as the dialog shows the Style page, `stylePageTitle`, the
|
|
1382
|
+
* dialog's localized word; trimmed, any case) is that page instead, so the
|
|
1383
|
+
* dialog never shows two tabs with one label: its rows join the 'general'
|
|
1384
|
+
* page (an author's layout page named General makes that page where it
|
|
1385
|
+
* stands, unless params before the first page made it already, and the rows
|
|
1386
|
+
* the layout never names join it); the first page named Style takes the
|
|
1387
|
+
* 'style' id in its place, a tab named Style fills the Style page, still
|
|
1388
|
+
* last, and either way the output sections follow its own rows. Without
|
|
1389
|
+
* style rows there is no Style page to land on: the page or tab keeps its
|
|
1390
|
+
* own slug, as before.
|
|
1391
|
+
*/
|
|
1392
|
+
export function buildWrunScriptLayout(metadata, declarations, opts) {
|
|
1393
|
+
const params = metadata.params ?? [];
|
|
1394
|
+
const paramsByName = new Map(params.map((param) => [param.name, param]));
|
|
1395
|
+
const placeable = declarations.filter((row) => row.hidden !== true && row.styleOf === undefined && row.type !== 'divider' && row.type !== 'note');
|
|
1396
|
+
const rowsByName = new Map();
|
|
1397
|
+
for (const row of placeable)
|
|
1398
|
+
if (!rowsByName.has(row.name))
|
|
1399
|
+
rowsByName.set(row.name, row);
|
|
1400
|
+
// A composite by each member's name: a layout entry naming a member
|
|
1401
|
+
// places its composite.
|
|
1402
|
+
const compositeByMember = new Map();
|
|
1403
|
+
for (const row of placeable) {
|
|
1404
|
+
if (row.virtual !== true)
|
|
1405
|
+
continue;
|
|
1406
|
+
for (const member of row.members ?? [])
|
|
1407
|
+
if (!compositeByMember.has(member))
|
|
1408
|
+
compositeByMember.set(member, row);
|
|
1409
|
+
}
|
|
1410
|
+
// The value rows by name (a unit composite shares its name with its value
|
|
1411
|
+
// member: the member, the row that holds the value, answers here).
|
|
1412
|
+
const valueRowsByName = new Map();
|
|
1413
|
+
for (const row of declarations) {
|
|
1414
|
+
if (row.virtual !== true && row.styleOf === undefined && !valueRowsByName.has(row.name)) {
|
|
1415
|
+
valueRowsByName.set(row.name, row);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
const placed = new Set();
|
|
1419
|
+
let order = 0;
|
|
1420
|
+
let layoutRows = 0;
|
|
1421
|
+
const decorate = (row, pageId, sectionTitle) => {
|
|
1422
|
+
// A unit row picks like its value member (its first member).
|
|
1423
|
+
const valueType = row.type === 'unit' ? valueRowsByName.get(row.members?.[0] ?? row.name)?.type : row.type;
|
|
1424
|
+
const pick = valueType === 'time' ? 'time' : valueType === 'price' ? 'price' : undefined;
|
|
1425
|
+
return {
|
|
1426
|
+
...row,
|
|
1427
|
+
page: pageId,
|
|
1428
|
+
...(sectionTitle !== undefined ? { section: sectionTitle } : {}),
|
|
1429
|
+
order: order++,
|
|
1430
|
+
...(pick !== undefined ? { pick } : {}),
|
|
1431
|
+
};
|
|
1432
|
+
};
|
|
1433
|
+
const layoutRow = (type, pageId, sectionTitle, text = '') => {
|
|
1434
|
+
layoutRows += 1;
|
|
1435
|
+
return {
|
|
1436
|
+
name: `__${type}__${layoutRows}`,
|
|
1437
|
+
label: text,
|
|
1438
|
+
type,
|
|
1439
|
+
defaultValue: 0,
|
|
1440
|
+
settingsTier: 'refetch',
|
|
1441
|
+
affectsCompute: true,
|
|
1442
|
+
page: pageId,
|
|
1443
|
+
...(sectionTitle !== undefined ? { section: sectionTitle } : {}),
|
|
1444
|
+
order: order++,
|
|
1445
|
+
};
|
|
1446
|
+
};
|
|
1447
|
+
const pages = [];
|
|
1448
|
+
const slugs = new Set([WRUN_GENERAL_PAGE_ID, WRUN_STYLE_PAGE_ID]);
|
|
1449
|
+
// The General page there is, else a new one: first, or where an author's layout page named
|
|
1450
|
+
// General stands (`inPlace`; the layout is the author's placement).
|
|
1451
|
+
const generalPage = (inPlace = false) => {
|
|
1452
|
+
let page = pages.find((candidate) => candidate.id === WRUN_GENERAL_PAGE_ID);
|
|
1453
|
+
if (!page) {
|
|
1454
|
+
page = { id: WRUN_GENERAL_PAGE_ID, title: WRUN_GENERAL_PAGE_TITLE, sections: [] };
|
|
1455
|
+
if (inPlace)
|
|
1456
|
+
pages.push(page);
|
|
1457
|
+
else
|
|
1458
|
+
pages.unshift(page);
|
|
1459
|
+
}
|
|
1460
|
+
return page;
|
|
1461
|
+
};
|
|
1462
|
+
// Where a row the layout never named lands: the page's last section when
|
|
1463
|
+
// it is a plain one, else a fresh plain section after it (an unnamed row
|
|
1464
|
+
// must not inherit an author section's title, toggle or gate).
|
|
1465
|
+
const sweepSection = (page) => {
|
|
1466
|
+
const last = page.sections[page.sections.length - 1];
|
|
1467
|
+
const plain = last !== undefined &&
|
|
1468
|
+
last.title === undefined &&
|
|
1469
|
+
last.toggle === undefined &&
|
|
1470
|
+
last.when === undefined &&
|
|
1471
|
+
last.collapsed === undefined;
|
|
1472
|
+
if (plain)
|
|
1473
|
+
return last;
|
|
1474
|
+
const section = { rows: [] };
|
|
1475
|
+
page.sections.push(section);
|
|
1476
|
+
return section;
|
|
1477
|
+
};
|
|
1478
|
+
const styleDeclarations = declarations.filter((row) => row.styleOf !== undefined && row.hidden !== true);
|
|
1479
|
+
const entries = layoutEntries(metadata);
|
|
1480
|
+
const hasLayout = entries.length > 0;
|
|
1481
|
+
// The targets a Style line exists for, in page order: when the rows carry
|
|
1482
|
+
// a Style page at all, every drawn target of the sheet (the visibility
|
|
1483
|
+
// table's, wrun-visibility-table.ts), so a target whose every knob a param
|
|
1484
|
+
// owns (its Visible, its line style) keeps a line for those params; then
|
|
1485
|
+
// every target with style rows (an overlay restored without its sheet reads
|
|
1486
|
+
// them off its rows). The targets a param may join; a declared layout is
|
|
1487
|
+
// the author's placement.
|
|
1488
|
+
const styleTargets = new Set([
|
|
1489
|
+
...(styleDeclarations.length > 0 ? wrunVisibilityTargets(metadata).map(({ target }) => target) : []),
|
|
1490
|
+
...styleDeclarations.flatMap((row) => row.styleOf?.output ?? []),
|
|
1491
|
+
]);
|
|
1492
|
+
const placements = hasLayout
|
|
1493
|
+
? new Map()
|
|
1494
|
+
: stylePlacements(metadata, placeable, styleTargets);
|
|
1495
|
+
if (hasLayout) {
|
|
1496
|
+
let page;
|
|
1497
|
+
let section;
|
|
1498
|
+
// An author's page named as a built-in page is that page (builtInPageId): every one named
|
|
1499
|
+
// General, and the first named Style, which holds the style rows (none to hold, it keeps its slug).
|
|
1500
|
+
let styleHeld = styleDeclarations.length === 0;
|
|
1501
|
+
const currentPage = () => {
|
|
1502
|
+
if (!page)
|
|
1503
|
+
page = generalPage();
|
|
1504
|
+
return page;
|
|
1505
|
+
};
|
|
1506
|
+
const currentSection = () => {
|
|
1507
|
+
const owner = currentPage();
|
|
1508
|
+
if (!section) {
|
|
1509
|
+
section = { rows: [] };
|
|
1510
|
+
owner.sections.push(section);
|
|
1511
|
+
}
|
|
1512
|
+
return section;
|
|
1513
|
+
};
|
|
1514
|
+
// The rows a layout param entry names: its own row, the composite or
|
|
1515
|
+
// colour-array row it is a member of, or the host param rows an input it
|
|
1516
|
+
// names binds (a `param.source` declares the input; its select is
|
|
1517
|
+
// `<name>_field`).
|
|
1518
|
+
const rowsNamed = (name) => {
|
|
1519
|
+
const own = rowsByName.get(name) ?? compositeByMember.get(name);
|
|
1520
|
+
if (own)
|
|
1521
|
+
return [own];
|
|
1522
|
+
const param = paramsByName.get(name);
|
|
1523
|
+
const arrayKey = param === undefined ? undefined : wrunColorArrayKey(param);
|
|
1524
|
+
const arrayRow = arrayKey === undefined ? undefined : rowsByName.get(arrayKey);
|
|
1525
|
+
if (arrayRow)
|
|
1526
|
+
return [arrayRow];
|
|
1527
|
+
const source = metadata.inputSources?.[name];
|
|
1528
|
+
if (!source)
|
|
1529
|
+
return [];
|
|
1530
|
+
return [source.field_param, source.interval_param, source.symbol_param]
|
|
1531
|
+
.map((bound) => (bound === undefined ? undefined : rowsByName.get(bound)))
|
|
1532
|
+
.filter((row) => row !== undefined);
|
|
1533
|
+
};
|
|
1534
|
+
// A section's toggle is drawn in its header: the param's own row is
|
|
1535
|
+
// never placed (it stays a declared input, so the value persists).
|
|
1536
|
+
const sectionToggles = new Set();
|
|
1537
|
+
for (const entry of entries) {
|
|
1538
|
+
const toggle = entry.kind === 'section' ? nonEmptyString(entry.toggle) : undefined;
|
|
1539
|
+
if (toggle !== undefined)
|
|
1540
|
+
sectionToggles.add(toggle);
|
|
1541
|
+
}
|
|
1542
|
+
for (const entry of entries) {
|
|
1543
|
+
switch (entry.kind) {
|
|
1544
|
+
case 'page': {
|
|
1545
|
+
const title = nonEmptyString(entry.title) ?? 'Page';
|
|
1546
|
+
const builtIn = builtInPageId(title, opts.stylePageTitle);
|
|
1547
|
+
if (builtIn === WRUN_GENERAL_PAGE_ID) {
|
|
1548
|
+
page = generalPage(true);
|
|
1549
|
+
}
|
|
1550
|
+
else {
|
|
1551
|
+
const holdsStyle = !styleHeld && builtIn === WRUN_STYLE_PAGE_ID;
|
|
1552
|
+
if (holdsStyle)
|
|
1553
|
+
styleHeld = true;
|
|
1554
|
+
page = { id: holdsStyle ? WRUN_STYLE_PAGE_ID : pageSlug(title, slugs), title, sections: [] };
|
|
1555
|
+
pages.push(page);
|
|
1556
|
+
}
|
|
1557
|
+
section = undefined;
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
case 'section': {
|
|
1561
|
+
const owner = currentPage();
|
|
1562
|
+
const toggle = nonEmptyString(entry.toggle);
|
|
1563
|
+
const when = nonEmptyString(entry.when);
|
|
1564
|
+
section = {
|
|
1565
|
+
...(nonEmptyString(entry.title) !== undefined ? { title: entry.title } : {}),
|
|
1566
|
+
...(toggle !== undefined ? { toggle } : {}),
|
|
1567
|
+
...(entry.collapsed === true ? { collapsed: true } : {}),
|
|
1568
|
+
...(when !== undefined ? { when } : {}),
|
|
1569
|
+
rows: [],
|
|
1570
|
+
};
|
|
1571
|
+
owner.sections.push(section);
|
|
1572
|
+
break;
|
|
1573
|
+
}
|
|
1574
|
+
case 'divider': {
|
|
1575
|
+
const target = currentSection();
|
|
1576
|
+
target.rows.push(layoutRow('divider', currentPage().id, target.title));
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
case 'note': {
|
|
1580
|
+
const target = currentSection();
|
|
1581
|
+
target.rows.push(layoutRow('note', currentPage().id, target.title, nonEmptyString(entry.text) ?? ''));
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1584
|
+
case 'param': {
|
|
1585
|
+
for (const row of rowsNamed(typeof entry.name === 'string' ? entry.name : '')) {
|
|
1586
|
+
if (placed.has(row))
|
|
1587
|
+
continue;
|
|
1588
|
+
placed.add(row);
|
|
1589
|
+
if (sectionToggles.has(row.name))
|
|
1590
|
+
continue;
|
|
1591
|
+
const target = currentSection();
|
|
1592
|
+
target.rows.push(decorate(row, currentPage().id, target.title));
|
|
1593
|
+
}
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
default:
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
for (const row of placeable) {
|
|
1601
|
+
if (placed.has(row) || sectionToggles.has(row.name))
|
|
1602
|
+
continue;
|
|
1603
|
+
placed.add(row);
|
|
1604
|
+
const owner = generalPage();
|
|
1605
|
+
const target = sweepSection(owner);
|
|
1606
|
+
target.rows.push(decorate(row, owner.id, target.title));
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
else {
|
|
1610
|
+
const tabs = new Map();
|
|
1611
|
+
const sectionsOf = new Map();
|
|
1612
|
+
// A tab named as a built-in page fills that page (builtInPageId): General, and Style while the
|
|
1613
|
+
// sheet has style rows, its page still last (added after the tabs, its style sections after the
|
|
1614
|
+
// tab's rows). Without style rows there is no Style page, and the tab is a page of its own.
|
|
1615
|
+
let stylePage;
|
|
1616
|
+
for (const row of placeable) {
|
|
1617
|
+
// A row the Style page takes never opens its group page (a page left empty disappears).
|
|
1618
|
+
if (placements.has(row))
|
|
1619
|
+
continue;
|
|
1620
|
+
const raw = (row.group ?? '').trim();
|
|
1621
|
+
let tab = '';
|
|
1622
|
+
let sectionTitle;
|
|
1623
|
+
if (raw) {
|
|
1624
|
+
const slash = raw.indexOf('/');
|
|
1625
|
+
if (slash >= 0) {
|
|
1626
|
+
tab = raw.slice(0, slash).trim();
|
|
1627
|
+
sectionTitle = raw.slice(slash + 1).trim() || undefined;
|
|
1628
|
+
}
|
|
1629
|
+
else {
|
|
1630
|
+
tab = raw;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
const builtIn = tab === '' ? WRUN_GENERAL_PAGE_ID : builtInPageId(tab, opts.stylePageTitle);
|
|
1634
|
+
let page;
|
|
1635
|
+
if (builtIn === WRUN_GENERAL_PAGE_ID)
|
|
1636
|
+
page = generalPage();
|
|
1637
|
+
else if (builtIn === WRUN_STYLE_PAGE_ID && styleTargets.size > 0)
|
|
1638
|
+
page = stylePage ??= { id: WRUN_STYLE_PAGE_ID, title: WRUN_STYLE_PAGE_TITLE, sections: [] };
|
|
1639
|
+
else
|
|
1640
|
+
page = tabs.get(tab);
|
|
1641
|
+
if (!page) {
|
|
1642
|
+
page = { id: pageSlug(tab, slugs), title: tab, sections: [] };
|
|
1643
|
+
tabs.set(tab, page);
|
|
1644
|
+
pages.push(page);
|
|
1645
|
+
}
|
|
1646
|
+
let sections = sectionsOf.get(page);
|
|
1647
|
+
if (!sections) {
|
|
1648
|
+
sections = new Map();
|
|
1649
|
+
sectionsOf.set(page, sections);
|
|
1650
|
+
}
|
|
1651
|
+
let section = sections.get(sectionTitle ?? '');
|
|
1652
|
+
if (!section) {
|
|
1653
|
+
section = { ...(sectionTitle !== undefined ? { title: sectionTitle } : {}), rows: [] };
|
|
1654
|
+
sections.set(sectionTitle ?? '', section);
|
|
1655
|
+
page.sections.push(section);
|
|
1656
|
+
}
|
|
1657
|
+
section.rows.push(decorate(row, page.id, sectionTitle));
|
|
1658
|
+
}
|
|
1659
|
+
if (stylePage)
|
|
1660
|
+
pages.push(stylePage);
|
|
1661
|
+
}
|
|
1662
|
+
if (styleTargets.size > 0) {
|
|
1663
|
+
// The Style page an author's layout page (in its place) or group tab (last) opened, its rows
|
|
1664
|
+
// first; else the derived page, last.
|
|
1665
|
+
let page = pages.find((candidate) => candidate.id === WRUN_STYLE_PAGE_ID);
|
|
1666
|
+
if (!page) {
|
|
1667
|
+
page = { id: WRUN_STYLE_PAGE_ID, title: WRUN_STYLE_PAGE_TITLE, sections: [] };
|
|
1668
|
+
pages.push(page);
|
|
1669
|
+
}
|
|
1670
|
+
// The shared colours open the page. Gathered from several groups, each
|
|
1671
|
+
// group's colours share one line under the group's title (the tiers of
|
|
1672
|
+
// anchored-market-structure all say "Bullish" and "Bearish").
|
|
1673
|
+
const shared = placeable.filter((row) => placements.get(row) === 'colors');
|
|
1674
|
+
if (shared.length > 0) {
|
|
1675
|
+
const section = { id: WRUN_STYLE_COLORS_SECTION_ID, title: 'Colors', rows: [] };
|
|
1676
|
+
const tabs = shared.map(groupTabOf);
|
|
1677
|
+
const byGroup = new Set(tabs).size > 1;
|
|
1678
|
+
// A group's lone colour draws as an ordinary row (nothing to sit beside), where the line's
|
|
1679
|
+
// title would be lost: one that says only "Color" (the anchored VWAP's Daily, Weekly, ...
|
|
1680
|
+
// anchors) reads as its group's word, and one whose words another group's lone colour
|
|
1681
|
+
// repeats ("Line color" under Fast and under Slow) reads as its group's word and its own.
|
|
1682
|
+
const loneWords = new Map();
|
|
1683
|
+
for (const row of shared) {
|
|
1684
|
+
const tab = groupTabOf(row);
|
|
1685
|
+
if (!byGroup || tab === undefined || tabs.filter((other) => other === tab).length !== 1)
|
|
1686
|
+
continue;
|
|
1687
|
+
loneWords.set(row, isBareColorLabel(row) ? tab : wrunRowLabel(row));
|
|
1688
|
+
}
|
|
1689
|
+
const repeats = new Map();
|
|
1690
|
+
for (const words of loneWords.values())
|
|
1691
|
+
repeats.set(words.toLowerCase(), (repeats.get(words.toLowerCase()) ?? 0) + 1);
|
|
1692
|
+
for (const row of shared) {
|
|
1693
|
+
const tab = groupTabOf(row);
|
|
1694
|
+
const line = byGroup && tab !== undefined && row.row === undefined ? { row: tab } : {};
|
|
1695
|
+
const own = loneWords.get(row);
|
|
1696
|
+
const label = own === undefined
|
|
1697
|
+
? undefined
|
|
1698
|
+
: own === tab
|
|
1699
|
+
? own
|
|
1700
|
+
: (repeats.get(own.toLowerCase()) ?? 0) > 1
|
|
1701
|
+
? `${tab} ${lowerFirstWord(own)}`
|
|
1702
|
+
: undefined;
|
|
1703
|
+
section.rows.push({
|
|
1704
|
+
...decorate(row, page.id, section.title),
|
|
1705
|
+
...line,
|
|
1706
|
+
...(label !== undefined ? { label } : {}),
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
page.sections.push(section);
|
|
1710
|
+
}
|
|
1711
|
+
// One section per styled target (an output, or a C1 target such as
|
|
1712
|
+
// `text:<name>`): its style rows, and the params placed on its line, in
|
|
1713
|
+
// knob order; a target left with neither (its knobs owned by a param
|
|
1714
|
+
// placed on another line) has none. A param that stands for no knob
|
|
1715
|
+
// leads the line (265.1, 265.2): trailing the knobs, it pushed them out
|
|
1716
|
+
// of the columns every other line's knobs take and put the colour mid-line.
|
|
1717
|
+
const lines = new Map([...styleTargets].map((target) => [target, []]));
|
|
1718
|
+
const knobAt = (property) => property === undefined ? -1 : STYLE_LINE_KNOBS.indexOf(property);
|
|
1719
|
+
for (const row of styleDeclarations) {
|
|
1720
|
+
lines.get(row.styleOf.output)?.push({ row, at: knobAt(row.styleOf?.property) });
|
|
1721
|
+
}
|
|
1722
|
+
for (const row of placeable) {
|
|
1723
|
+
const placement = placements.get(row);
|
|
1724
|
+
if (placement === undefined || placement === 'colors')
|
|
1725
|
+
continue;
|
|
1726
|
+
lines.get(placement.output)?.push({ row, at: knobAt(placement.property), joined: placement });
|
|
1727
|
+
}
|
|
1728
|
+
for (const [output, line] of lines) {
|
|
1729
|
+
if (line.length === 0)
|
|
1730
|
+
continue;
|
|
1731
|
+
// The legend's name for the target, never its raw id; a draw-API handle
|
|
1732
|
+
// kind's line carries its target as the id the dialog localizes it by.
|
|
1733
|
+
const section = {
|
|
1734
|
+
...(isWrunLocalizedStyleTarget(output) ? { id: output } : {}),
|
|
1735
|
+
title: styleTargetTitle(metadata, output),
|
|
1736
|
+
rows: [],
|
|
1737
|
+
};
|
|
1738
|
+
for (const { row, joined } of [...line].sort((a, b) => a.at - b.at)) {
|
|
1739
|
+
const placed = decorate(row, page.id, section.title);
|
|
1740
|
+
if (joined === undefined) {
|
|
1741
|
+
section.rows.push(placed);
|
|
1742
|
+
}
|
|
1743
|
+
else {
|
|
1744
|
+
const property = joined.property === undefined ? {} : { property: joined.property };
|
|
1745
|
+
section.rows.push({ ...placed, styleLine: { output: joined.output, ...property } });
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
page.sections.push(section);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
return { pages, presets: sheetPresets(metadata), hasLayout };
|
|
1752
|
+
}
|
|
1753
|
+
// ---------------------------------------------------------------------------
|
|
1754
|
+
// Presets: sheet values to the dialog's storage types.
|
|
1755
|
+
// ---------------------------------------------------------------------------
|
|
1756
|
+
/** A colour the run can read (the hex / rgb spellings a colour setting
|
|
1757
|
+
* takes, or a packed number): anything else would show in the dialog while
|
|
1758
|
+
* the run kept the default. */
|
|
1759
|
+
function colorValue(raw) {
|
|
1760
|
+
return wrunColorSettingString(raw);
|
|
1761
|
+
}
|
|
1762
|
+
/** A colour-array row's value: exactly its declared members (the control's
|
|
1763
|
+
* and the palette's rule; the run reads member i at element i), element i
|
|
1764
|
+
* the stored element decoded, else (a named colour, `transparent`, a slot
|
|
1765
|
+
* the stored array never had) the member's declared default, so no slot
|
|
1766
|
+
* shifts. A stored array with no decodable element is no value (the row
|
|
1767
|
+
* reads its default). A row without declared members (none the builders
|
|
1768
|
+
* make) keeps its decodable elements. */
|
|
1769
|
+
function colorArrayValue(row, raw) {
|
|
1770
|
+
if (!Array.isArray(raw))
|
|
1771
|
+
return undefined;
|
|
1772
|
+
const defaults = Array.isArray(row.defaultValue)
|
|
1773
|
+
? row.defaultValue.filter((color) => typeof color === 'string')
|
|
1774
|
+
: [];
|
|
1775
|
+
const slots = defaults.length > 0 ? defaults.length : raw.length;
|
|
1776
|
+
const decoded = Array.from({ length: slots }, (_, at) => colorValue(raw[at]));
|
|
1777
|
+
if (!decoded.some((color) => color !== undefined))
|
|
1778
|
+
return undefined;
|
|
1779
|
+
return decoded.map((color, at) => color ?? defaults[at]).filter((color) => color !== undefined);
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* A value in the row's UI storage type (the frozen table the preset
|
|
1783
|
+
* normalizer below spells out), undefined when the row cannot store it: a
|
|
1784
|
+
* toggle a boolean (a 1/0 number or an on/off word reads), a select its
|
|
1785
|
+
* numeric option string (an option label or an index into the options
|
|
1786
|
+
* resolves; an index past them is no value), a colour a colour string (a
|
|
1787
|
+
* packed number decodes), a colour array its declared members (an
|
|
1788
|
+
* undecodable element its member's default, the slots never shift), a multi
|
|
1789
|
+
* its bitmask, a time epoch seconds, a symbol its non-empty string, a style
|
|
1790
|
+
* row its property value (a `colors` row its swatches, each a colour or a
|
|
1791
|
+
* theme token), everything else a finite number. The preset
|
|
1792
|
+
* normalizer and the dialog's row read (wrun-dialog-rows readRowValue)
|
|
1793
|
+
* share it, so a value persisted under an older package version (a packed
|
|
1794
|
+
* colour number under what is now a colour row, a 1 under a toggle, a
|
|
1795
|
+
* dropped option's index under a select) reads as the kind the republished
|
|
1796
|
+
* sheet declares; the persisted value itself is rewritten only by an edit
|
|
1797
|
+
* or a reset.
|
|
1798
|
+
*/
|
|
1799
|
+
export function coerceWrunRowValue(row, raw) {
|
|
1800
|
+
switch (row.type) {
|
|
1801
|
+
case 'boolean':
|
|
1802
|
+
return toggleValue(raw);
|
|
1803
|
+
case 'select':
|
|
1804
|
+
return wrunSelectOptionValue(row.options ?? [], row.optionLabels ?? [], raw);
|
|
1805
|
+
case 'color':
|
|
1806
|
+
return colorValue(raw);
|
|
1807
|
+
case 'color[]':
|
|
1808
|
+
return colorArrayValue(row, raw);
|
|
1809
|
+
case 'multi':
|
|
1810
|
+
return bitmaskValue(raw);
|
|
1811
|
+
case 'time':
|
|
1812
|
+
return wrunTimeValue(raw);
|
|
1813
|
+
case 'symbol':
|
|
1814
|
+
return typeof raw === 'string' && raw.trim() !== '' ? raw : undefined;
|
|
1815
|
+
case 'text':
|
|
1816
|
+
// Plain text within the row's cap (an empty string is a value: the
|
|
1817
|
+
// user cleared the field); a value over the cap is no value.
|
|
1818
|
+
return wrunTextValueWithinCap(raw, { multiline: row.multiline === true, maxBytes: row.maxBytes });
|
|
1819
|
+
case 'style':
|
|
1820
|
+
switch (row.styleOf?.property) {
|
|
1821
|
+
case 'visible':
|
|
1822
|
+
return toggleValue(raw);
|
|
1823
|
+
case 'lineStyle':
|
|
1824
|
+
return typeof raw === 'string' && (row.options ?? wrunLineStyles()).includes(raw) ? raw : undefined;
|
|
1825
|
+
case 'color':
|
|
1826
|
+
return colorValue(raw);
|
|
1827
|
+
case 'colors':
|
|
1828
|
+
return styleColorsValue(row, raw);
|
|
1829
|
+
default:
|
|
1830
|
+
return numericValue(raw);
|
|
1831
|
+
}
|
|
1832
|
+
default:
|
|
1833
|
+
return numericValue(raw);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
/** A `colors` style row's value: exactly its declared swatches, element i
|
|
1837
|
+
* the stored colour (a colour setting or a theme token) else the swatch's
|
|
1838
|
+
* default, so no swatch shifts; a stored list with no usable element is no
|
|
1839
|
+
* value (the row reads its default). */
|
|
1840
|
+
function styleColorsValue(row, raw) {
|
|
1841
|
+
if (!Array.isArray(raw))
|
|
1842
|
+
return undefined;
|
|
1843
|
+
const defaults = Array.isArray(row.defaultValue)
|
|
1844
|
+
? row.defaultValue.filter((color) => typeof color === 'string')
|
|
1845
|
+
: [];
|
|
1846
|
+
const slots = defaults.length > 0 ? defaults.length : raw.length;
|
|
1847
|
+
const stored = Array.from({ length: slots }, (_, at) => colorValue(raw[at]) ?? colorWordOf(raw[at]));
|
|
1848
|
+
if (!stored.some((color) => color !== undefined))
|
|
1849
|
+
return undefined;
|
|
1850
|
+
return stored.map((color, at) => color ?? defaults[at]).filter((color) => color !== undefined);
|
|
1851
|
+
}
|
|
1852
|
+
/**
|
|
1853
|
+
* A preset's values in the dialog's storage types (frozen contract, plan
|
|
1854
|
+
* 1.2): a toggle a boolean, a select its numeric option string (a label or
|
|
1855
|
+
* an index resolve to it), a colour a string (a packed number decodes), a
|
|
1856
|
+
* multi its bitmask, a time epoch seconds (a `YYYY-MM-DD HH:MM` UTC text
|
|
1857
|
+
* parses), a symbol its string, a style row its property value, everything
|
|
1858
|
+
* else a number. A key naming no declaration, a virtual composite (values
|
|
1859
|
+
* live under its members) or a value the row cannot store is dropped, so
|
|
1860
|
+
* the result applies as ONE settings patch of declared keys.
|
|
1861
|
+
*/
|
|
1862
|
+
export function normalizePresetValues(preset, declarations) {
|
|
1863
|
+
const rowsByName = new Map();
|
|
1864
|
+
for (const row of declarations) {
|
|
1865
|
+
if (row.type === 'divider' || row.type === 'note')
|
|
1866
|
+
continue;
|
|
1867
|
+
const current = rowsByName.get(row.name);
|
|
1868
|
+
// A unit composite shares its name with its value member: the member
|
|
1869
|
+
// (the row with a storage type) decides.
|
|
1870
|
+
if (current === undefined || (current.virtual === true && row.virtual !== true))
|
|
1871
|
+
rowsByName.set(row.name, row);
|
|
1872
|
+
}
|
|
1873
|
+
const values = {};
|
|
1874
|
+
for (const [name, raw] of Object.entries(isRecord(preset.values) ? preset.values : {})) {
|
|
1875
|
+
const row = rowsByName.get(name);
|
|
1876
|
+
if (row === undefined || row.virtual === true)
|
|
1877
|
+
continue;
|
|
1878
|
+
const stored = coerceWrunRowValue(row, raw);
|
|
1879
|
+
if (stored !== undefined)
|
|
1880
|
+
values[name] = stored;
|
|
1881
|
+
}
|
|
1882
|
+
return values;
|
|
1883
|
+
}
|
|
1884
|
+
// ---------------------------------------------------------------------------
|
|
1885
|
+
// Run values: the flat settings as init() numbers.
|
|
1886
|
+
// ---------------------------------------------------------------------------
|
|
1887
|
+
/** The overlay palette of a sheet with colour settings (colour params,
|
|
1888
|
+
* colour arrays, om colour knobs): their CURRENT colours under `settings` in
|
|
1889
|
+
* row order, a colour array flattened (no settings = the declared defaults).
|
|
1890
|
+
* Undefined for a sheet without colour settings, whose palette
|
|
1891
|
+
* (`legend_palette`, else derived) never follows a setting. The loaders
|
|
1892
|
+
* mount it (wrunSheetOverlayPalette) and every full run stamps it on the
|
|
1893
|
+
* live overlay (wrun-overlay-run.util), since a settings save drops a
|
|
1894
|
+
* TECHNICAL_SCRIPT's `colors`. Style rows never enter it. */
|
|
1895
|
+
export function wrunRunOverlayPalette(metadata, settings) {
|
|
1896
|
+
const colorRows = buildWrunScriptInputs(metadata).filter((row) => row.type === 'color' || row.type === 'color[]');
|
|
1897
|
+
return colorRows.length > 0 ? wrunColorPalette(colorRows, settings) : undefined;
|
|
1898
|
+
}
|
|
1899
|
+
// The run values are a thin fact the anchored tools' history demand reads on the boot path
|
|
1900
|
+
// (wrun-param-values.util); this module keeps exporting them for its own readers.
|
|
1901
|
+
export { wrunParamValuesFromSettings } from './wrun-param-values.util.js';
|
|
1902
|
+
// The twin's compute inputs are a thin fact the kScript stand-in reads at the cached candle paint
|
|
1903
|
+
// (wrun-twin-compute-inputs.util); this module keeps exporting them for its own readers.
|
|
1904
|
+
export { wrunTwinComputeInputNames } from './wrun-twin-compute-inputs.util.js';
|
|
1905
|
+
/** One param value in a legend title, rendered the way the chart renders a
|
|
1906
|
+
* kScript input's value in its customTitle (`"" + value`): a number as its
|
|
1907
|
+
* digits, a boolean toggle as "true", a select as its option label (a
|
|
1908
|
+
* kScript select's value IS its label, never empty), a colour as its
|
|
1909
|
+
* colour string, a text setting as its plain words (never markup; an
|
|
1910
|
+
* empty text keeps the token). Undefined keeps the literal token, the
|
|
1911
|
+
* chart's own rule for a falsy kScript value (0, a toggle off); an om
|
|
1912
|
+
* style knob (no run value) keeps it too. Every inserted value is LITERAL
|
|
1913
|
+
* legend text (wrunLegendLiteral: the HTML specials and `$` as entities),
|
|
1914
|
+
* because titan writes the suffix through innerHTML after its own `$token`
|
|
1915
|
+
* pass over the raw settings; the template's own characters stay as the
|
|
1916
|
+
* author wrote them. */
|
|
1917
|
+
function renderWrunParamTitleValue(param, value, text) {
|
|
1918
|
+
const rendered = renderWrunParamTitleWords(param, value, text);
|
|
1919
|
+
return rendered === undefined ? undefined : wrunLegendLiteral(rendered);
|
|
1920
|
+
}
|
|
1921
|
+
function renderWrunParamTitleWords(param, value, text) {
|
|
1922
|
+
if (isWrunStyleParam(param))
|
|
1923
|
+
return undefined;
|
|
1924
|
+
// A coded value (a choice, a multi, a time, a session clock) prints as its words, never its
|
|
1925
|
+
// code; an empty multi and an unset time (0) keep the literal token, the falsy rule below.
|
|
1926
|
+
const shape = wrunParamWordsShape(param);
|
|
1927
|
+
const coded = wrunCodedWords(shape, value);
|
|
1928
|
+
if (coded !== undefined)
|
|
1929
|
+
return coded === '' || (shape.type === 'time' && !value) ? undefined : coded;
|
|
1930
|
+
switch (shape.type) {
|
|
1931
|
+
case 'color':
|
|
1932
|
+
return wrunColorSettingString(value);
|
|
1933
|
+
case 'boolean':
|
|
1934
|
+
return Number.isFinite(value) && value !== 0 ? 'true' : undefined;
|
|
1935
|
+
case 'text': {
|
|
1936
|
+
const words = text ?? wrunTextParamDefault(param);
|
|
1937
|
+
return words === '' ? undefined : words;
|
|
1938
|
+
}
|
|
1939
|
+
default:
|
|
1940
|
+
return value ? `${value}` : undefined;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
function escapeRegExp(text) {
|
|
1944
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* The legend suffix a sheet's `custom_title` template (the kScript
|
|
1948
|
+
* define(customTitle=...) text) reads as for one run. Resolved here, not by
|
|
1949
|
+
* the chart: titan's own token pass (`/\$[a-zA-Z0-9]+/` against the flat
|
|
1950
|
+
* settings' raw values) can never see a snake_case param name, and a select
|
|
1951
|
+
* would read as its index. Each `$<param name>` token (longest name first,
|
|
1952
|
+
* and never the prefix of a longer identifier, so `$len` leaves `$len_fast`
|
|
1953
|
+
* alone) becomes the run's value (else the declared default) rendered like
|
|
1954
|
+
* a kScript input's; a falsy value keeps the literal token, and a token
|
|
1955
|
+
* naming no param stays as written. `texts` is the run's text settings by
|
|
1956
|
+
* name (wrunTextParamValuesFromSettings; absent = the declared words): a
|
|
1957
|
+
* text token becomes the plain words, inserted after the token pass and
|
|
1958
|
+
* never re-read as a template (a typed `$len` arrives literally).
|
|
1959
|
+
*/
|
|
1960
|
+
export function resolveWrunCustomTitle(template, params, values, texts) {
|
|
1961
|
+
const byName = new Map(params.map((param) => [param.name, param]));
|
|
1962
|
+
if (byName.size === 0)
|
|
1963
|
+
return template;
|
|
1964
|
+
const names = [...byName.keys()].sort((a, b) => b.length - a.length).map(escapeRegExp);
|
|
1965
|
+
const token = new RegExp(`\\$(${names.join('|')})(?![A-Za-z0-9_])`, 'g');
|
|
1966
|
+
return template.replace(token, (literal, name) => {
|
|
1967
|
+
const param = byName.get(name);
|
|
1968
|
+
const fallback = typeof param.default === 'number' ? param.default : 0;
|
|
1969
|
+
return renderWrunParamTitleValue(param, values?.[name] ?? fallback, texts?.[name]) ?? literal;
|
|
1970
|
+
});
|
|
1971
|
+
}
|