@orangecharts/wrun-chart-host 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +11 -5
  2. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +133 -0
  3. package/dist/constants/scriptEditor/builtin-script-snippets.js +451 -0
  4. package/dist/host-env.d.ts +8 -6
  5. package/dist/host-ports.types.d.ts +7 -22
  6. package/dist/index.d.ts +10 -0
  7. package/dist/index.js +10 -0
  8. package/dist/utility/chart/date-labelled-interval.leaf.d.ts +15 -0
  9. package/dist/utility/chart/date-labelled-interval.leaf.js +19 -0
  10. package/dist/utility/chart/indicator-run-interval.util.d.ts +130 -0
  11. package/dist/utility/chart/indicator-run-interval.util.js +268 -0
  12. package/dist/utility/chart/window-geometry.leaf.d.ts +119 -0
  13. package/dist/utility/chart/window-geometry.leaf.js +391 -0
  14. package/dist/utility/chart/window-owner.leaf.d.ts +19 -0
  15. package/dist/utility/chart/window-owner.leaf.js +24 -0
  16. package/dist/utility/html-escape.leaf.d.ts +11 -0
  17. package/dist/utility/html-escape.leaf.js +20 -0
  18. package/dist/utility/wrun/sources/lanes/option_daily.d.ts +43 -15
  19. package/dist/utility/wrun/sources/lanes/option_daily.js +78 -20
  20. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +14 -10
  21. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +5 -4
  22. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +22 -3
  23. package/dist/utility/wrun/sources/opra-option-lanes.util.js +38 -7
  24. package/dist/utility/wrun/sources/registry.js +31 -1
  25. package/dist/utility/wrun/sources/row-lane-registry.js +5 -5
  26. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +49 -0
  27. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +74 -18
  28. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +49 -0
  29. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +57 -47
  30. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +36 -4
  31. package/dist/utility/wrun/sources/row-lanes/option_surface.js +6 -12
  32. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +37 -3
  33. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +128 -2
  34. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +233 -51
  35. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +0 -8
  36. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +26 -24
  37. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +85 -104
  38. package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +29 -10
  39. package/dist/utility/wrun/wrun-opra-stats.leaf.js +29 -10
  40. package/dist/utility/wrun/wrun-panel-mount.lazy.d.ts +10 -0
  41. package/dist/utility/wrun/wrun-panel-mount.lazy.js +68 -0
  42. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +377 -0
  43. package/dist/utility/wrun/wrun-panel-mount.util.js +2251 -0
  44. package/dist/utility/wrun/wrun-pause-dim.util.d.ts +52 -0
  45. package/dist/utility/wrun/wrun-pause-dim.util.js +153 -0
  46. package/dist/utility/wrun/wrun-plot-gate.types.d.ts +23 -0
  47. package/dist/utility/wrun/wrun-plot-gate.types.js +7 -0
  48. package/dist/utility/wrun/wrun-run-interval-projection.types.d.ts +14 -0
  49. package/dist/utility/wrun/wrun-run-interval-projection.types.js +1 -0
  50. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The paused picture: a paused browser-run Indicator keeps what it last drew, and its heatmap
3
+ * canvases dim so the reader sees at a glance that the picture is frozen. Pause = frozen
4
+ * computation and frozen content: nothing is unmounted, nothing recomputes, and a paused canvas
5
+ * still paints whenever the chart paints.
6
+ *
7
+ * Only HEATMAP children dim (`<parent>::heatmap:<name>`, whose engine settings carry a numeric
8
+ * `opacity`, wrun-canvases.util heatmap settings): a matrix bakes its alpha into its fill
9
+ * colours, and profile children and the parent's own plots keep their look. The write is the
10
+ * engine's settings door (`updateSettings`, the path `rescaleWrunHeatmapChildren` uses), and the
11
+ * original opacity is remembered per engine instance and child id, so Resume (and a removal)
12
+ * puts it back and a replaced engine instance starts clean.
13
+ */
14
+ /** The share of its own opacity a paused heatmap keeps. */
15
+ export declare const WRUN_PAUSE_DIM_FACTOR = 0.35;
16
+ type DimChildMeta = {
17
+ id?: unknown;
18
+ settings?: object | null;
19
+ };
20
+ /** The engine surface the dim reads and writes (a TitanCharts instance in the app). */
21
+ export interface WrunPauseDimChart {
22
+ metadata?: ReadonlyArray<DimChildMeta> | null;
23
+ isDestroyed?: boolean;
24
+ updateSettings?(id: string, settings: Record<string, unknown>): unknown;
25
+ renderService?: {
26
+ renderOnce?(): void;
27
+ } | null;
28
+ }
29
+ /**
30
+ * Dim every mounted heatmap child of a paused Indicator. Idempotent: a child already dimmed by
31
+ * this pause is left as it is, and a child whose look a late mount rewrote (a mount the run
32
+ * started before the pause landed) is dimmed again from the look it has now. Returns how many
33
+ * children it dimmed.
34
+ */
35
+ export declare function dimWrunOverlayForPause(chart: WrunPauseDimChart | null | undefined, overlayId: string): number;
36
+ /**
37
+ * Re-apply a pause's dim after its heatmap children were rebuilt (a theme or timezone retranslate
38
+ * removes and re-adds them from their own settings, at full opacity). A no-op unless the Indicator
39
+ * is dimmed on this engine instance. Each mounted heatmap child takes the dimmed share of the
40
+ * original the dim remembered for it (Resume keeps putting that original back); a child the memory
41
+ * does not know yet has its own opacity remembered as its original first.
42
+ */
43
+ export declare function reapplyWrunPauseDim(tc: unknown, overlayId: string): void;
44
+ /** Put back the look of every child the pause dimmed (Resume, a removal) and forget it. Returns
45
+ * how many children took their opacity back. */
46
+ export declare function undimWrunOverlayForPause(chart: WrunPauseDimChart | null | undefined, overlayId: string): number;
47
+ /** Whether any child of the Indicator is dimmed on this engine instance. */
48
+ export declare function isWrunOverlayDimmedForPause(chart: WrunPauseDimChart | null | undefined, overlayId: string): boolean;
49
+ /** Chart teardown: the instance's dim memory goes with it (nothing is written: the engine is
50
+ * being destroyed, and a rebuilt chart mounts its children from their own settings). */
51
+ export declare function dropWrunPauseDimMemory(chart: WrunPauseDimChart | null | undefined): void;
52
+ export {};
@@ -0,0 +1,153 @@
1
+ import { wrunChildOverlayParentId } from './wrun-child-overlay-id.util.js';
2
+ /**
3
+ * The paused picture: a paused browser-run Indicator keeps what it last drew, and its heatmap
4
+ * canvases dim so the reader sees at a glance that the picture is frozen. Pause = frozen
5
+ * computation and frozen content: nothing is unmounted, nothing recomputes, and a paused canvas
6
+ * still paints whenever the chart paints.
7
+ *
8
+ * Only HEATMAP children dim (`<parent>::heatmap:<name>`, whose engine settings carry a numeric
9
+ * `opacity`, wrun-canvases.util heatmap settings): a matrix bakes its alpha into its fill
10
+ * colours, and profile children and the parent's own plots keep their look. The write is the
11
+ * engine's settings door (`updateSettings`, the path `rescaleWrunHeatmapChildren` uses), and the
12
+ * original opacity is remembered per engine instance and child id, so Resume (and a removal)
13
+ * puts it back and a replaced engine instance starts clean.
14
+ */
15
+ /** The share of its own opacity a paused heatmap keeps. */
16
+ export const WRUN_PAUSE_DIM_FACTOR = 0.35;
17
+ // Engine instance -> heatmap child id -> the opacity it had before the pause dimmed it.
18
+ const dimmedOpacityByChart = new WeakMap();
19
+ const HEATMAP_CHILD_SEGMENT = '::heatmap:';
20
+ function heatmapChildOpacity(meta, overlayId) {
21
+ const id = meta?.id;
22
+ if (typeof id !== 'string' || wrunChildOverlayParentId(id) !== overlayId)
23
+ return null;
24
+ if (!id.startsWith(`${overlayId}${HEATMAP_CHILD_SEGMENT}`))
25
+ return null;
26
+ const opacity = meta?.settings?.opacity;
27
+ return typeof opacity === 'number' && Number.isFinite(opacity) ? opacity : null;
28
+ }
29
+ function sameOpacity(a, b) {
30
+ return Math.abs(a - b) < 1e-9;
31
+ }
32
+ /** One opacity write through the engine's settings door (it schedules its own paint); an engine
33
+ * without the door takes the value on its meta. True when the write needs a paint of its own. */
34
+ function writeChildOpacity(chart, id, meta, opacity) {
35
+ if (typeof chart.updateSettings === 'function') {
36
+ void chart.updateSettings(id, { opacity });
37
+ return false;
38
+ }
39
+ meta.settings = { ...(meta.settings ?? {}), opacity };
40
+ return true;
41
+ }
42
+ function liveChart(chart) {
43
+ return !!chart && chart.isDestroyed !== true && Array.isArray(chart.metadata);
44
+ }
45
+ /**
46
+ * Dim every mounted heatmap child of a paused Indicator. Idempotent: a child already dimmed by
47
+ * this pause is left as it is, and a child whose look a late mount rewrote (a mount the run
48
+ * started before the pause landed) is dimmed again from the look it has now. Returns how many
49
+ * children it dimmed.
50
+ */
51
+ export function dimWrunOverlayForPause(chart, overlayId) {
52
+ if (!liveChart(chart))
53
+ return 0;
54
+ let memory = dimmedOpacityByChart.get(chart);
55
+ let dimmed = 0;
56
+ let paintOwed = false;
57
+ for (const meta of chart.metadata ?? []) {
58
+ const current = heatmapChildOpacity(meta, overlayId);
59
+ if (current === null)
60
+ continue;
61
+ const id = meta.id;
62
+ const original = memory?.get(id);
63
+ if (original !== undefined && sameOpacity(current, original * WRUN_PAUSE_DIM_FACTOR))
64
+ continue;
65
+ if (!memory) {
66
+ memory = new Map();
67
+ dimmedOpacityByChart.set(chart, memory);
68
+ }
69
+ memory.set(id, current);
70
+ paintOwed = writeChildOpacity(chart, id, meta, current * WRUN_PAUSE_DIM_FACTOR) || paintOwed;
71
+ dimmed += 1;
72
+ }
73
+ if (paintOwed)
74
+ chart.renderService?.renderOnce?.();
75
+ return dimmed;
76
+ }
77
+ /**
78
+ * Re-apply a pause's dim after its heatmap children were rebuilt (a theme or timezone retranslate
79
+ * removes and re-adds them from their own settings, at full opacity). A no-op unless the Indicator
80
+ * is dimmed on this engine instance. Each mounted heatmap child takes the dimmed share of the
81
+ * original the dim remembered for it (Resume keeps putting that original back); a child the memory
82
+ * does not know yet has its own opacity remembered as its original first.
83
+ */
84
+ export function reapplyWrunPauseDim(tc, overlayId) {
85
+ const target = tc;
86
+ if (!liveChart(target))
87
+ return;
88
+ const memory = dimmedOpacityByChart.get(target);
89
+ if (!memory || !isWrunOverlayDimmedForPause(target, overlayId))
90
+ return;
91
+ let paintOwed = false;
92
+ for (const meta of target.metadata ?? []) {
93
+ const current = heatmapChildOpacity(meta, overlayId);
94
+ if (current === null)
95
+ continue;
96
+ const id = meta.id;
97
+ let original = memory.get(id);
98
+ if (original === undefined) {
99
+ original = current;
100
+ memory.set(id, original);
101
+ }
102
+ const dimmed = original * WRUN_PAUSE_DIM_FACTOR;
103
+ if (sameOpacity(current, dimmed))
104
+ continue;
105
+ paintOwed = writeChildOpacity(target, id, meta, dimmed) || paintOwed;
106
+ }
107
+ if (paintOwed)
108
+ target.renderService?.renderOnce?.();
109
+ }
110
+ /** Put back the look of every child the pause dimmed (Resume, a removal) and forget it. Returns
111
+ * how many children took their opacity back. */
112
+ export function undimWrunOverlayForPause(chart, overlayId) {
113
+ if (!chart)
114
+ return 0;
115
+ const memory = dimmedOpacityByChart.get(chart);
116
+ if (!memory)
117
+ return 0;
118
+ let restored = 0;
119
+ let paintOwed = false;
120
+ for (const [id, original] of [...memory]) {
121
+ if (wrunChildOverlayParentId(id) !== overlayId)
122
+ continue;
123
+ memory.delete(id);
124
+ if (!liveChart(chart))
125
+ continue;
126
+ const meta = chart.metadata?.find((candidate) => candidate?.id === id);
127
+ if (!meta)
128
+ continue;
129
+ paintOwed = writeChildOpacity(chart, id, meta, original) || paintOwed;
130
+ restored += 1;
131
+ }
132
+ if (memory.size === 0)
133
+ dimmedOpacityByChart.delete(chart);
134
+ if (paintOwed)
135
+ chart.renderService?.renderOnce?.();
136
+ return restored;
137
+ }
138
+ /** Whether any child of the Indicator is dimmed on this engine instance. */
139
+ export function isWrunOverlayDimmedForPause(chart, overlayId) {
140
+ const memory = chart ? dimmedOpacityByChart.get(chart) : undefined;
141
+ if (!memory)
142
+ return false;
143
+ for (const id of memory.keys())
144
+ if (wrunChildOverlayParentId(id) === overlayId)
145
+ return true;
146
+ return false;
147
+ }
148
+ /** Chart teardown: the instance's dim memory goes with it (nothing is written: the engine is
149
+ * being destroyed, and a rebuilt chart mounts its children from their own settings). */
150
+ export function dropWrunPauseDimMemory(chart) {
151
+ if (chart)
152
+ dimmedOpacityByChart.delete(chart);
153
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The engine gate's refusal types of wrun-plot-gate-notice.util.ts (which imports them back and re-exports them) as a
3
+ * type leaf: the child mount (wrun-panel-mount.util) judges its batched children with them, and it moves into the
4
+ * wrun chart-host package, which the notice's writers (the chart store, the chart group, i18n and the refusal
5
+ * surface) may not reach.
6
+ */
7
+ /** The chart a notice is written for (any engine instance). */
8
+ export interface WrunPlotGateChart {
9
+ metadata: ReadonlyArray<{
10
+ id: string;
11
+ }>;
12
+ }
13
+ /** Why the engine gate refused a batched child: its pack failed to load, or the engine has no
14
+ * renderer for its kind (an older chart). */
15
+ export type WrunPlotGateCause = 'pack-failed' | 'old-engine';
16
+ /** One refused child: its kind, its section name and the cause (and, for a layout newer than this
17
+ * build, why: diagnostic text, never copy). */
18
+ export interface WrunPlotGateRefusal {
19
+ kind: string;
20
+ name: string;
21
+ cause: WrunPlotGateCause;
22
+ reason?: string;
23
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The engine gate's refusal types of wrun-plot-gate-notice.util.ts (which imports them back and re-exports them) as a
3
+ * type leaf: the child mount (wrun-panel-mount.util) judges its batched children with them, and it moves into the
4
+ * wrun chart-host package, which the notice's writers (the chart store, the chart group, i18n and the refusal
5
+ * surface) may not reach.
6
+ */
7
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The run-interval projection type of wrun-run-interval-session.util.ts (which re-exports it and builds one per run,
3
+ * `wrunRunIntervalProjectionOf`) as a type leaf: the child mount (wrun-panel-mount.util) hands it to the series
4
+ * child's integrate, and it moves into the wrun chart-host package, which the session's live context
5
+ * (wrun-overlay-drivers.util) and run-interval engine may not reach.
6
+ */
7
+ import type { OverlayRunInterval } from '../chart/indicator-run-interval.util.js';
8
+ /** What the kScript adapter's run-interval projection reads off a wrun integrate
9
+ * (kscript-titancharts-integration.util): the result's stamp, the chart and its venue. */
10
+ export interface WrunRunIntervalProjection {
11
+ runInterval: OverlayRunInterval;
12
+ chartIndex: number;
13
+ chartExchange?: string;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orangecharts/wrun-chart-host",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The wrun chart-host layer shared by the kiyotaka web app and the mobile app: the wrun result reader and painter model, cut from the web app (its reference implementation).",
5
5
  "type": "module",
6
6
  "files": [