@loadmap/react 0.7.0 → 0.8.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 +10 -0
- package/dist/Loadmap-D_Kto8cB.js +3215 -0
- package/dist/Loadmap-VLbQ__eh.d.ts +206 -0
- package/dist/index.d.ts +12 -202
- package/dist/index.js +4 -3076
- package/dist/source.d.ts +16 -0
- package/dist/source.js +54 -0
- package/package.json +9 -4
|
@@ -0,0 +1,3215 @@
|
|
|
1
|
+
import { compare, headroom, reach } from "@loadmap/core";
|
|
2
|
+
import { compact, fmt, monthOf, multiple, multiples, pct, secs } from "@loadmap/core/format";
|
|
3
|
+
import { anchor, labelsAt, layout, legPath, localElk, pointAt, structureKey } from "@loadmap/layout";
|
|
4
|
+
import { memo, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { morph } from "@loadmap/layout/internal";
|
|
7
|
+
import { createSim } from "@loadmap/sim";
|
|
8
|
+
// src/scenarios.tsx
|
|
9
|
+
/** Scenario identity colours, in declaration order; a fifth and later scenario is drawn muted. */
|
|
10
|
+
const SERIES = [
|
|
11
|
+
"var(--lm-s1)",
|
|
12
|
+
"var(--lm-s2)",
|
|
13
|
+
"var(--lm-s3)",
|
|
14
|
+
"var(--lm-s4)"
|
|
15
|
+
];
|
|
16
|
+
/** The colour of a scenario by label; values of the reader's own are drawn in the text colour. */
|
|
17
|
+
function scenarioColor(model, label) {
|
|
18
|
+
if (label == null) return "var(--lm-fg)";
|
|
19
|
+
const i = model.scenarios.findIndex((s) => s.label === label);
|
|
20
|
+
return SERIES[i] ?? "var(--lm-muted)";
|
|
21
|
+
}
|
|
22
|
+
const lineName = (l) => l.label ?? "These values";
|
|
23
|
+
/** A month for a table cell or an axis: "Mar 2031"; "now" for a crossing already reached. */
|
|
24
|
+
function when(model, x) {
|
|
25
|
+
const d = model.dateAt(x);
|
|
26
|
+
return d ? monthOf(d, true) : x != null && x <= 1 && model.growth ? "now" : "";
|
|
27
|
+
}
|
|
28
|
+
/** The months of both edges: "Sep 2029–Feb 2030", or one month when they agree. */
|
|
29
|
+
function whenRange(model, r) {
|
|
30
|
+
if (!r) return "";
|
|
31
|
+
const [lo, hi] = [when(model, r.low), when(model, r.high)];
|
|
32
|
+
return !hi || lo === hi ? lo : `${lo}–${hi}`;
|
|
33
|
+
}
|
|
34
|
+
/** The comparison at the shown load: crossings do not depend on it, the verdicts do. */
|
|
35
|
+
function useComparison(lm) {
|
|
36
|
+
return useMemo(() => compare(lm.model, lm.values.load), [lm.model, lm.values.load]);
|
|
37
|
+
}
|
|
38
|
+
/** One button per scenario: a reader switches designs without touching the controls. The load stays. */
|
|
39
|
+
function Scenarios({ lm }) {
|
|
40
|
+
const { model } = lm;
|
|
41
|
+
if (!model.scenarios.length) return null;
|
|
42
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
43
|
+
className: "lm-scenarios",
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsx("legend", { children: "Scenario" }),
|
|
46
|
+
model.scenarios.map((s) => /* @__PURE__ */ jsxs("button", {
|
|
47
|
+
type: "button",
|
|
48
|
+
"aria-pressed": lm.scenario?.label === s.label,
|
|
49
|
+
onClick: () => lm.setScenario(s.label),
|
|
50
|
+
children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, s.label) } }), s.label]
|
|
51
|
+
}, s.label)),
|
|
52
|
+
!lm.scenario && /* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "lm-own",
|
|
54
|
+
children: "your own values"
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** "+107 %" against the baseline; "same" within a rounding; nothing where either never runs out. */
|
|
60
|
+
function change(x) {
|
|
61
|
+
if (x == null || !Number.isFinite(x) || x === 0) return "";
|
|
62
|
+
if (Math.abs(x - 1) < .005) return "same";
|
|
63
|
+
return `${x > 1 ? "+" : "−"}${pct(Math.abs(x - 1))}`;
|
|
64
|
+
}
|
|
65
|
+
/** The scenarios side by side: which buys more headroom, where each first runs out, and per component. */
|
|
66
|
+
function Compare({ lm, title = "Scenarios compared" }) {
|
|
67
|
+
const { model } = lm;
|
|
68
|
+
const c = useComparison(lm);
|
|
69
|
+
if (c.rows.length < 2) return null;
|
|
70
|
+
const target = `${pct(model.thresholds.target)} target`;
|
|
71
|
+
const at = (r) => /* @__PURE__ */ jsxs(Fragment, { children: [r ? multiples(r, model.searchMax, true) : multiple(null), whenRange(model, r) && /* @__PURE__ */ jsx("small", { children: whenRange(model, r) })] });
|
|
72
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
73
|
+
className: "lm-card lm-compare",
|
|
74
|
+
children: [
|
|
75
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
76
|
+
/* @__PURE__ */ jsx("p", {
|
|
77
|
+
className: "lm-compare-text",
|
|
78
|
+
children: c.text
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ jsx("div", {
|
|
81
|
+
className: "lm-table-wrap",
|
|
82
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
83
|
+
className: "lm-table",
|
|
84
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
85
|
+
/* @__PURE__ */ jsx("th", {
|
|
86
|
+
scope: "col",
|
|
87
|
+
children: "Scenario"
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ jsx("th", {
|
|
90
|
+
scope: "col",
|
|
91
|
+
children: "First limit"
|
|
92
|
+
}),
|
|
93
|
+
/* @__PURE__ */ jsx("th", {
|
|
94
|
+
scope: "col",
|
|
95
|
+
children: target
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ jsx("th", {
|
|
98
|
+
scope: "col",
|
|
99
|
+
children: "Runs out"
|
|
100
|
+
})
|
|
101
|
+
] }) }), /* @__PURE__ */ jsx("tbody", { children: c.rows.map((r) => /* @__PURE__ */ jsxs("tr", {
|
|
102
|
+
"data-scenario": r.label,
|
|
103
|
+
"aria-current": lm.scenario?.label === r.label || void 0,
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ jsxs("th", {
|
|
106
|
+
scope: "row",
|
|
107
|
+
children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, r.label) } }), r.label]
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsx("td", {
|
|
110
|
+
className: "lm-text",
|
|
111
|
+
children: r.firstLimit?.name ?? "—"
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ jsx("td", {
|
|
114
|
+
"data-multiple": r.target ?? "",
|
|
115
|
+
"data-high": r.targetRange?.high ?? "",
|
|
116
|
+
children: at(r.targetRange)
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ jsx("td", {
|
|
119
|
+
"data-multiple": r.full ?? "",
|
|
120
|
+
"data-high": r.fullRange?.high ?? "",
|
|
121
|
+
children: at(r.fullRange)
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
}, r.label)) })]
|
|
125
|
+
})
|
|
126
|
+
}),
|
|
127
|
+
/* @__PURE__ */ jsxs("h3", { children: [target, ", by component"] }),
|
|
128
|
+
/* @__PURE__ */ jsx("div", {
|
|
129
|
+
className: "lm-table-wrap",
|
|
130
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
131
|
+
className: "lm-table",
|
|
132
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
133
|
+
scope: "col",
|
|
134
|
+
children: "Component"
|
|
135
|
+
}), c.rows.map((r) => /* @__PURE__ */ jsx("th", {
|
|
136
|
+
scope: "col",
|
|
137
|
+
children: r.label
|
|
138
|
+
}, r.label))] }) }), /* @__PURE__ */ jsx("tbody", { children: model.componentIds.map((id, k) => /* @__PURE__ */ jsxs("tr", {
|
|
139
|
+
"data-component": id,
|
|
140
|
+
children: [/* @__PURE__ */ jsx("th", {
|
|
141
|
+
scope: "row",
|
|
142
|
+
children: c.rows[0].components[k].name
|
|
143
|
+
}), c.rows.map((r, i) => {
|
|
144
|
+
const x = r.components[k];
|
|
145
|
+
return /* @__PURE__ */ jsxs("td", {
|
|
146
|
+
"data-multiple": x.target ?? "",
|
|
147
|
+
children: [x.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true), i > 0 && change(x.change) && /* @__PURE__ */ jsx("small", { children: change(x.change) })]
|
|
148
|
+
}, r.label);
|
|
149
|
+
})]
|
|
150
|
+
}, id)) })]
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** The size of an element in CSS pixels, kept current: a chart draws at its own size so text stays legible. */
|
|
157
|
+
function useSize(fallback) {
|
|
158
|
+
const ref = useRef(null);
|
|
159
|
+
const [size, setSize] = useState({
|
|
160
|
+
width: fallback,
|
|
161
|
+
height: 0
|
|
162
|
+
});
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
const el = ref.current;
|
|
165
|
+
if (!el) return;
|
|
166
|
+
const ro = new ResizeObserver(([e]) => {
|
|
167
|
+
const width = Math.round(e?.contentRect.width ?? el.clientWidth);
|
|
168
|
+
const height = Math.round(e?.contentRect.height ?? el.clientHeight);
|
|
169
|
+
if (width > 0) setSize((s) => s.width === width && s.height === height ? s : {
|
|
170
|
+
width,
|
|
171
|
+
height
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
ro.observe(el);
|
|
175
|
+
return () => ro.disconnect();
|
|
176
|
+
}, []);
|
|
177
|
+
return [ref, size];
|
|
178
|
+
}
|
|
179
|
+
/** Every scenario's line over the load: it depends on every value but the load, which is only the marker. */
|
|
180
|
+
function useHeadroom(lm) {
|
|
181
|
+
const { model, values } = lm;
|
|
182
|
+
const rest = JSON.stringify({
|
|
183
|
+
...values,
|
|
184
|
+
load: null
|
|
185
|
+
});
|
|
186
|
+
return useMemo(() => headroom(model, {
|
|
187
|
+
...values,
|
|
188
|
+
load: model.load.default
|
|
189
|
+
}), [model, rest]);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The width of a label in the chart's 11 px monospace (`--lm-mono`), measured once the chart is on the page, so its
|
|
193
|
+
* labels are kept inside it whatever the theme's font.
|
|
194
|
+
*/
|
|
195
|
+
function useAxisMeasure(el) {
|
|
196
|
+
const [measure, setMeasure] = useState(() => (text, _weight) => text.length * 6.7);
|
|
197
|
+
useLayoutEffect(() => {
|
|
198
|
+
const ctx = el.current && document.createElement("canvas").getContext("2d");
|
|
199
|
+
if (!ctx) return;
|
|
200
|
+
const font = getComputedStyle(el.current).getPropertyValue("--lm-mono").trim() || "monospace";
|
|
201
|
+
setMeasure(() => (text, weight = 400) => {
|
|
202
|
+
ctx.font = `${weight} 11px ${font}`;
|
|
203
|
+
return ctx.measureText(text).width;
|
|
204
|
+
});
|
|
205
|
+
}, [el]);
|
|
206
|
+
return measure;
|
|
207
|
+
}
|
|
208
|
+
/** 1, 2, 5, 10, 20, 50, … inside [from, to]; decades only when there is little room. */
|
|
209
|
+
function ticks(from, to, roomy) {
|
|
210
|
+
const out = [];
|
|
211
|
+
for (let d = Math.floor(Math.log10(from)); d <= Math.ceil(Math.log10(to)); d++) for (const k of roomy ? [
|
|
212
|
+
1,
|
|
213
|
+
2,
|
|
214
|
+
5
|
|
215
|
+
] : [1]) {
|
|
216
|
+
const v = k * 10 ** d;
|
|
217
|
+
if (v >= from * .999 && v <= to * 1.001) out.push(Number(v.toPrecision(6)));
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Utilization over the load multiple. Each scenario's line is its highest utilization, so it crosses the target and
|
|
223
|
+
* 100 % exactly where its first limit does; the dots are those crossings, taken from the limits, not from the line.
|
|
224
|
+
* With a ± on a capacity, a band shows the line at every capacity's low and high bound, and a bracket on the target
|
|
225
|
+
* and 100 % lines spans where the band crosses them. The shown scenario's components are the thin lines under it.
|
|
226
|
+
* Hover or arrow keys read every line at one load.
|
|
227
|
+
*/
|
|
228
|
+
function HeadroomChart({ lm, title = "Headroom" }) {
|
|
229
|
+
const { model, values } = lm;
|
|
230
|
+
const h = useHeadroom(lm);
|
|
231
|
+
const [wrap, { width }] = useSize(640);
|
|
232
|
+
const [hover, setHover] = useState(null);
|
|
233
|
+
const clip = useId().replace(/:/g, "");
|
|
234
|
+
const measure = useAxisMeasure(wrap);
|
|
235
|
+
const tip = useRef(null);
|
|
236
|
+
useLayoutEffect(() => {
|
|
237
|
+
const el = tip.current;
|
|
238
|
+
if (el && hover != null) el.style.left = `${Math.max(0, Math.min(lx(xs[hover]) + 10, W - el.offsetWidth))}px`;
|
|
239
|
+
});
|
|
240
|
+
const dated = !!model.growth;
|
|
241
|
+
const m = {
|
|
242
|
+
l: 44,
|
|
243
|
+
r: 14,
|
|
244
|
+
t: 14,
|
|
245
|
+
b: dated ? 40 : 26
|
|
246
|
+
};
|
|
247
|
+
const W = width;
|
|
248
|
+
const H = Math.round(Math.min(300, Math.max(200, W * .45)));
|
|
249
|
+
const pw = W - m.l - m.r;
|
|
250
|
+
const ph = H - m.t - m.b;
|
|
251
|
+
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
252
|
+
const lx = (x) => m.l + pw * Math.log(x / h.from) / Math.log(h.to / h.from);
|
|
253
|
+
const ly = (u) => m.t + ph * (1 - Math.min(u, top * 1.2) / top);
|
|
254
|
+
const path = (s) => {
|
|
255
|
+
let d = "";
|
|
256
|
+
let pen = false;
|
|
257
|
+
for (const [x, u] of s) {
|
|
258
|
+
if (u == null) {
|
|
259
|
+
pen = false;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
d += `${pen ? "L" : "M"}${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`;
|
|
263
|
+
pen = true;
|
|
264
|
+
}
|
|
265
|
+
return d;
|
|
266
|
+
};
|
|
267
|
+
const xs = h.lines[0]?.envelope.map(([x]) => x) ?? [];
|
|
268
|
+
const selected = h.lines.find((l) => l.selected);
|
|
269
|
+
const roomy = W >= 480;
|
|
270
|
+
const tickList = ticks(h.from, h.to, roomy);
|
|
271
|
+
const labelled = (x) => roomy || Number.isInteger(Math.log10(x));
|
|
272
|
+
const near = (px) => {
|
|
273
|
+
let best = 0;
|
|
274
|
+
for (let i = 1; i < xs.length; i++) if (Math.abs(lx(xs[i]) - px) < Math.abs(lx(xs[best]) - px)) best = i;
|
|
275
|
+
return best;
|
|
276
|
+
};
|
|
277
|
+
const onMove = (e) => {
|
|
278
|
+
const r = e.currentTarget.ownerSVGElement.getBoundingClientRect();
|
|
279
|
+
setHover(near(e.clientX - r.left));
|
|
280
|
+
};
|
|
281
|
+
const onKey = (e) => {
|
|
282
|
+
const i = hover ?? near(lx(Math.min(h.to, Math.max(h.from, values.load))));
|
|
283
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
284
|
+
e.preventDefault();
|
|
285
|
+
setHover(Math.max(0, Math.min(xs.length - 1, i + (e.key === "ArrowRight" ? 1 : -1))));
|
|
286
|
+
} else if (e.key === "Escape") setHover(null);
|
|
287
|
+
};
|
|
288
|
+
const area = (b) => {
|
|
289
|
+
const both = b.upper.flatMap(([x, u], i) => {
|
|
290
|
+
const v = b.lower[i][1];
|
|
291
|
+
return u == null || v == null ? [] : [[
|
|
292
|
+
x,
|
|
293
|
+
u,
|
|
294
|
+
v
|
|
295
|
+
]];
|
|
296
|
+
});
|
|
297
|
+
if (both.length < 2) return "";
|
|
298
|
+
const up = both.map(([x, u]) => `${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`);
|
|
299
|
+
const down = both.map(([x, , v]) => `${lx(x).toFixed(1)} ${ly(v).toFixed(1)}`).reverse();
|
|
300
|
+
return `M${up.join("L")}L${down.join("L")}Z`;
|
|
301
|
+
};
|
|
302
|
+
const reaches = (r, x) => r && l0(r) ? multiples(r, model.searchMax) : multiple(x, model.searchMax);
|
|
303
|
+
const l0 = (r) => multiple(r.low, model.searchMax) !== multiple(r.high, model.searchMax);
|
|
304
|
+
const summary = h.lines.map((l) => `${lineName(l)} reaches the ${pct(model.thresholds.target)} target at ${reaches(l.targetRange, l.target)} and ${pct(model.thresholds.full)} at ${reaches(l.fullRange, l.full)}`).join("; ");
|
|
305
|
+
const loadX = lx(Math.min(h.to, Math.max(h.from, values.load)));
|
|
306
|
+
const hx = hover == null ? null : xs[hover];
|
|
307
|
+
const fromLeft = {
|
|
308
|
+
x: 0,
|
|
309
|
+
textAnchor: "start"
|
|
310
|
+
};
|
|
311
|
+
const fromRight = {
|
|
312
|
+
x: W,
|
|
313
|
+
textAnchor: "end"
|
|
314
|
+
};
|
|
315
|
+
/** A label beside a line at x: on the side it prefers if it fits, else the other, else against the nearer edge. */
|
|
316
|
+
const beside = (x, w, prefer, gap = 4) => {
|
|
317
|
+
const right = {
|
|
318
|
+
x: x + gap,
|
|
319
|
+
textAnchor: "start"
|
|
320
|
+
};
|
|
321
|
+
const left = {
|
|
322
|
+
x: x - gap,
|
|
323
|
+
textAnchor: "end"
|
|
324
|
+
};
|
|
325
|
+
const fitsRight = x + gap + w <= W;
|
|
326
|
+
const fitsLeft = x - gap - w >= 0;
|
|
327
|
+
if (prefer === "right" ? fitsRight : !fitsLeft && fitsRight) return right;
|
|
328
|
+
if (fitsLeft) return left;
|
|
329
|
+
return x < W / 2 ? fromLeft : fromRight;
|
|
330
|
+
};
|
|
331
|
+
/** A label centred on x, unless that passes an edge. */
|
|
332
|
+
const centred = (x, w) => x - w / 2 < 0 ? fromLeft : x + w / 2 > W ? fromRight : {
|
|
333
|
+
x,
|
|
334
|
+
textAnchor: "middle"
|
|
335
|
+
};
|
|
336
|
+
const shown = `shown: ${fmt(values.load)}×`;
|
|
337
|
+
/** A crossing's multiple, left of its dot where it fits. */
|
|
338
|
+
const mark = (t, x, y) => /* @__PURE__ */ jsx("text", {
|
|
339
|
+
...beside(x, measure(t, 600), "left", 6),
|
|
340
|
+
y,
|
|
341
|
+
className: "lm-mark",
|
|
342
|
+
children: t
|
|
343
|
+
});
|
|
344
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
345
|
+
className: "lm-card lm-headroom",
|
|
346
|
+
children: [
|
|
347
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
348
|
+
h.lines.length > 1 && /* @__PURE__ */ jsxs("div", {
|
|
349
|
+
className: "lm-legend",
|
|
350
|
+
children: [h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("b", {
|
|
351
|
+
className: "lm-key",
|
|
352
|
+
style: { background: scenarioColor(model, l.label) }
|
|
353
|
+
}), lineName(l)] }, lineName(l))), selected && /* @__PURE__ */ jsxs("span", { children: ["thin lines: each component of ", lineName(selected)] })]
|
|
354
|
+
}),
|
|
355
|
+
/* @__PURE__ */ jsxs("div", {
|
|
356
|
+
className: "lm-chart",
|
|
357
|
+
ref: wrap,
|
|
358
|
+
role: "slider",
|
|
359
|
+
"aria-label": `Utilization over the load multiple. ${summary}.`,
|
|
360
|
+
"aria-valuemin": h.from,
|
|
361
|
+
"aria-valuemax": h.to,
|
|
362
|
+
"aria-valuenow": hx ?? values.load,
|
|
363
|
+
"aria-valuetext": hx == null ? `${fmt(values.load)}×` : `${fmt(hx)}×: ${h.lines.map((l) => `${lineName(l)} ${l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1])}`).join(", ")}`,
|
|
364
|
+
tabIndex: 0,
|
|
365
|
+
onKeyDown: onKey,
|
|
366
|
+
onBlur: () => setHover(null),
|
|
367
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
368
|
+
width: W,
|
|
369
|
+
height: H,
|
|
370
|
+
viewBox: `0 0 ${W} ${H}`,
|
|
371
|
+
"aria-hidden": "true",
|
|
372
|
+
children: [
|
|
373
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", {
|
|
374
|
+
id: clip,
|
|
375
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
376
|
+
x: m.l,
|
|
377
|
+
y: m.t,
|
|
378
|
+
width: pw,
|
|
379
|
+
height: ph + 2
|
|
380
|
+
})
|
|
381
|
+
}) }),
|
|
382
|
+
[
|
|
383
|
+
0,
|
|
384
|
+
model.thresholds.target,
|
|
385
|
+
model.thresholds.full
|
|
386
|
+
].map((u) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
387
|
+
x1: m.l,
|
|
388
|
+
x2: W - m.r,
|
|
389
|
+
y1: ly(u),
|
|
390
|
+
y2: ly(u),
|
|
391
|
+
stroke: "var(--lm-line)"
|
|
392
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
393
|
+
x: m.l - 6,
|
|
394
|
+
y: ly(u) + 4,
|
|
395
|
+
textAnchor: "end",
|
|
396
|
+
className: "lm-axis",
|
|
397
|
+
children: pct(u)
|
|
398
|
+
})] }, u)),
|
|
399
|
+
/* @__PURE__ */ jsx("text", {
|
|
400
|
+
x: W - m.r,
|
|
401
|
+
y: ly(model.thresholds.target) - 5,
|
|
402
|
+
textAnchor: "end",
|
|
403
|
+
className: "lm-axis",
|
|
404
|
+
children: "target"
|
|
405
|
+
}),
|
|
406
|
+
tickList.map((x) => {
|
|
407
|
+
const label = `${fmt(x)}×`;
|
|
408
|
+
const date = dated && x > 1 ? when(model, x) : "";
|
|
409
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
410
|
+
className: "lm-axis",
|
|
411
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
412
|
+
x1: lx(x),
|
|
413
|
+
x2: lx(x),
|
|
414
|
+
y1: m.t + ph,
|
|
415
|
+
y2: m.t + ph + 4,
|
|
416
|
+
stroke: "var(--lm-line)"
|
|
417
|
+
}), labelled(x) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("text", {
|
|
418
|
+
...centred(lx(x), measure(label)),
|
|
419
|
+
y: m.t + ph + 16,
|
|
420
|
+
children: label
|
|
421
|
+
}), date && /* @__PURE__ */ jsx("text", {
|
|
422
|
+
...centred(lx(x), measure(date)),
|
|
423
|
+
y: m.t + ph + 30,
|
|
424
|
+
children: date
|
|
425
|
+
})] })]
|
|
426
|
+
}, x);
|
|
427
|
+
}),
|
|
428
|
+
/* @__PURE__ */ jsxs("g", {
|
|
429
|
+
clipPath: `url(#${clip})`,
|
|
430
|
+
children: [
|
|
431
|
+
[...h.lines].sort((a, b) => Number(a.selected) - Number(b.selected)).map((l) => l.band ? /* @__PURE__ */ jsx("path", {
|
|
432
|
+
"data-band": lineName(l),
|
|
433
|
+
d: area(l.band),
|
|
434
|
+
fill: scenarioColor(model, l.label),
|
|
435
|
+
fillOpacity: l.selected ? .2 : .08
|
|
436
|
+
}, lineName(l)) : null),
|
|
437
|
+
selected?.components.map((c) => /* @__PURE__ */ jsx("path", {
|
|
438
|
+
d: path(c.points),
|
|
439
|
+
fill: "none",
|
|
440
|
+
stroke: "var(--lm-muted)",
|
|
441
|
+
strokeOpacity: ".55",
|
|
442
|
+
strokeWidth: "1"
|
|
443
|
+
}, c.id)),
|
|
444
|
+
[...h.lines].sort((a, b) => Number(a.selected) - Number(b.selected)).map((l) => /* @__PURE__ */ jsx("path", {
|
|
445
|
+
"data-line": lineName(l),
|
|
446
|
+
d: path(l.envelope),
|
|
447
|
+
fill: "none",
|
|
448
|
+
stroke: scenarioColor(model, l.label),
|
|
449
|
+
strokeWidth: "2",
|
|
450
|
+
strokeLinejoin: "round",
|
|
451
|
+
strokeLinecap: "round"
|
|
452
|
+
}, lineName(l)))
|
|
453
|
+
]
|
|
454
|
+
}),
|
|
455
|
+
/* @__PURE__ */ jsx("line", {
|
|
456
|
+
x1: loadX,
|
|
457
|
+
x2: loadX,
|
|
458
|
+
y1: m.t,
|
|
459
|
+
y2: m.t + ph,
|
|
460
|
+
stroke: "var(--lm-fg)",
|
|
461
|
+
strokeOpacity: ".45"
|
|
462
|
+
}),
|
|
463
|
+
/* @__PURE__ */ jsx("text", {
|
|
464
|
+
...beside(loadX, measure(shown), "right"),
|
|
465
|
+
y: m.t + 10,
|
|
466
|
+
className: "lm-axis",
|
|
467
|
+
children: shown
|
|
468
|
+
}),
|
|
469
|
+
h.lines.flatMap((l) => [[
|
|
470
|
+
"target",
|
|
471
|
+
l.targetRange,
|
|
472
|
+
model.thresholds.target
|
|
473
|
+
], [
|
|
474
|
+
"full",
|
|
475
|
+
l.fullRange,
|
|
476
|
+
model.thresholds.full
|
|
477
|
+
]].map(([kind, r, u]) => {
|
|
478
|
+
if (!l.band || !r || !Number.isFinite(r.low) || r.low > h.to) return null;
|
|
479
|
+
const [x1, x2] = [lx(Math.max(h.from, r.low)), lx(Math.min(h.to, r.high))];
|
|
480
|
+
const y = ly(u);
|
|
481
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
482
|
+
"data-range": kind,
|
|
483
|
+
"data-scenario": lineName(l),
|
|
484
|
+
"data-low": r.low,
|
|
485
|
+
"data-high": r.high,
|
|
486
|
+
stroke: scenarioColor(model, l.label),
|
|
487
|
+
strokeWidth: l.selected ? 3 : 2,
|
|
488
|
+
strokeOpacity: l.selected ? 1 : .6,
|
|
489
|
+
children: [
|
|
490
|
+
/* @__PURE__ */ jsx("line", {
|
|
491
|
+
x1,
|
|
492
|
+
x2,
|
|
493
|
+
y1: y,
|
|
494
|
+
y2: y
|
|
495
|
+
}),
|
|
496
|
+
/* @__PURE__ */ jsx("line", {
|
|
497
|
+
x1,
|
|
498
|
+
x2: x1,
|
|
499
|
+
y1: y - 5,
|
|
500
|
+
y2: y + 5
|
|
501
|
+
}),
|
|
502
|
+
Number.isFinite(r.high) && r.high <= h.to && /* @__PURE__ */ jsx("line", {
|
|
503
|
+
x1: x2,
|
|
504
|
+
x2,
|
|
505
|
+
y1: y - 5,
|
|
506
|
+
y2: y + 5
|
|
507
|
+
})
|
|
508
|
+
]
|
|
509
|
+
}, `${lineName(l)}/${kind}/range`);
|
|
510
|
+
})),
|
|
511
|
+
h.lines.flatMap((l) => [[
|
|
512
|
+
"target",
|
|
513
|
+
l.target,
|
|
514
|
+
l.targetRange,
|
|
515
|
+
model.thresholds.target
|
|
516
|
+
], [
|
|
517
|
+
"full",
|
|
518
|
+
l.full,
|
|
519
|
+
l.fullRange,
|
|
520
|
+
model.thresholds.full
|
|
521
|
+
]].map(([kind, x, r, u]) => x != null && Number.isFinite(x) && x >= h.from && x <= h.to ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("circle", {
|
|
522
|
+
"data-crossing": kind,
|
|
523
|
+
"data-scenario": lineName(l),
|
|
524
|
+
"data-multiple": x,
|
|
525
|
+
cx: lx(x),
|
|
526
|
+
cy: ly(u),
|
|
527
|
+
r: "4",
|
|
528
|
+
fill: scenarioColor(model, l.label),
|
|
529
|
+
stroke: "var(--lm-surface)",
|
|
530
|
+
strokeWidth: "2"
|
|
531
|
+
}), l.selected && mark(r && l0(r) ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax), lx(r && l0(r) ? Math.max(h.from, r.low) : x), ly(u) - 8)] }, `${lineName(l)}/${kind}`) : null)),
|
|
532
|
+
hx != null && /* @__PURE__ */ jsx("line", {
|
|
533
|
+
x1: lx(hx),
|
|
534
|
+
x2: lx(hx),
|
|
535
|
+
y1: m.t,
|
|
536
|
+
y2: m.t + ph,
|
|
537
|
+
stroke: "var(--lm-fg)",
|
|
538
|
+
strokeOpacity: ".8"
|
|
539
|
+
}),
|
|
540
|
+
/* @__PURE__ */ jsx("rect", {
|
|
541
|
+
x: m.l,
|
|
542
|
+
y: m.t,
|
|
543
|
+
width: pw,
|
|
544
|
+
height: ph,
|
|
545
|
+
fill: "transparent",
|
|
546
|
+
onPointerMove: onMove,
|
|
547
|
+
onPointerDown: onMove,
|
|
548
|
+
onPointerLeave: () => setHover(null)
|
|
549
|
+
})
|
|
550
|
+
]
|
|
551
|
+
}), hover != null && hx != null && /* @__PURE__ */ jsxs("div", {
|
|
552
|
+
className: "lm-tip",
|
|
553
|
+
role: "status",
|
|
554
|
+
ref: tip,
|
|
555
|
+
style: {
|
|
556
|
+
left: lx(hx) + 10,
|
|
557
|
+
top: m.t
|
|
558
|
+
},
|
|
559
|
+
children: [
|
|
560
|
+
/* @__PURE__ */ jsxs("b", { children: [
|
|
561
|
+
fmt(hx),
|
|
562
|
+
"×",
|
|
563
|
+
when(model, hx) && ` · ${when(model, hx)}`
|
|
564
|
+
] }),
|
|
565
|
+
h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [
|
|
566
|
+
/* @__PURE__ */ jsx("b", {
|
|
567
|
+
className: "lm-key",
|
|
568
|
+
style: { background: scenarioColor(model, l.label) }
|
|
569
|
+
}),
|
|
570
|
+
/* @__PURE__ */ jsx("strong", { children: l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1]) }),
|
|
571
|
+
" ",
|
|
572
|
+
lineName(l)
|
|
573
|
+
] }, lineName(l))),
|
|
574
|
+
selected?.components.map((c) => /* @__PURE__ */ jsxs("span", {
|
|
575
|
+
className: "lm-sub",
|
|
576
|
+
children: [
|
|
577
|
+
/* @__PURE__ */ jsx("strong", { children: c.points[hover][1] == null ? "off" : pct(c.points[hover][1]) }),
|
|
578
|
+
" ",
|
|
579
|
+
c.name
|
|
580
|
+
]
|
|
581
|
+
}, c.id))
|
|
582
|
+
]
|
|
583
|
+
})]
|
|
584
|
+
})
|
|
585
|
+
]
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
// src/Diagram.tsx
|
|
589
|
+
const STATE_STROKE = {
|
|
590
|
+
off: "var(--lm-line)",
|
|
591
|
+
ok: "var(--lm-ok)",
|
|
592
|
+
warn: "var(--lm-warn)",
|
|
593
|
+
over: "var(--lm-drop)"
|
|
594
|
+
};
|
|
595
|
+
const tokenColor = (c) => [
|
|
596
|
+
"accent",
|
|
597
|
+
"alt",
|
|
598
|
+
"ok",
|
|
599
|
+
"warn",
|
|
600
|
+
"drop",
|
|
601
|
+
"muted"
|
|
602
|
+
].includes(c) ? `var(--lm-${c})` : c;
|
|
603
|
+
function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
|
|
604
|
+
const { scene, engine, reducedMotion } = lm;
|
|
605
|
+
const click = useRef(onNodeClick);
|
|
606
|
+
click.current = onNodeClick;
|
|
607
|
+
const [onClick] = useState(() => (id) => click.current?.(id));
|
|
608
|
+
const svgRef = useRef(null);
|
|
609
|
+
const canvasRef = useRef(null);
|
|
610
|
+
const wrapRef = useRef(null);
|
|
611
|
+
const barRef = useRef(null);
|
|
612
|
+
const boardRef = useRef(null);
|
|
613
|
+
const buttonRef = useRef(null);
|
|
614
|
+
const full = lm.fullScreen;
|
|
615
|
+
const [tip, setTip] = useState(null);
|
|
616
|
+
const detailId = useId();
|
|
617
|
+
useLayoutEffect(() => {
|
|
618
|
+
if (scene) engine.setScene(scene, { cut: reducedMotion });
|
|
619
|
+
}, [
|
|
620
|
+
engine,
|
|
621
|
+
scene,
|
|
622
|
+
reducedMotion
|
|
623
|
+
]);
|
|
624
|
+
const frameId = useSyncExternalStore(engine.subscribe, () => engine.frameId);
|
|
625
|
+
const frame = engine.frame;
|
|
626
|
+
useEffect(() => {
|
|
627
|
+
engine.bind(svgRef.current, canvasRef.current);
|
|
628
|
+
}, [
|
|
629
|
+
engine,
|
|
630
|
+
frame,
|
|
631
|
+
reducedMotion
|
|
632
|
+
]);
|
|
633
|
+
useEffect(() => {
|
|
634
|
+
if (lm.root) engine.readColors(lm.root);
|
|
635
|
+
}, [
|
|
636
|
+
engine,
|
|
637
|
+
scene,
|
|
638
|
+
lm.root
|
|
639
|
+
]);
|
|
640
|
+
useEffect(() => {
|
|
641
|
+
engine.drawnValues = JSON.stringify(lm.values);
|
|
642
|
+
engine.drawnFocus = lm.focus;
|
|
643
|
+
engine.drawnFrame = frameId;
|
|
644
|
+
});
|
|
645
|
+
useEffect(() => {
|
|
646
|
+
const board = boardRef.current;
|
|
647
|
+
if (!board) return;
|
|
648
|
+
const ro = new ResizeObserver(() => engine.resize());
|
|
649
|
+
ro.observe(board);
|
|
650
|
+
return () => ro.disconnect();
|
|
651
|
+
}, [engine]);
|
|
652
|
+
useEffect(() => {
|
|
653
|
+
let raf = 0;
|
|
654
|
+
let last = 0;
|
|
655
|
+
const frame = (ts) => {
|
|
656
|
+
const dt = last ? Math.min(.05, (ts - last) / 1e3) : 0;
|
|
657
|
+
last = ts;
|
|
658
|
+
if (!engine.paused && engine.scene) {
|
|
659
|
+
engine.step(dt, { particles: !reducedMotion });
|
|
660
|
+
engine.draw({ particles: !reducedMotion });
|
|
661
|
+
}
|
|
662
|
+
raf = requestAnimationFrame(frame);
|
|
663
|
+
};
|
|
664
|
+
raf = requestAnimationFrame(frame);
|
|
665
|
+
return () => cancelAnimationFrame(raf);
|
|
666
|
+
}, [engine, reducedMotion]);
|
|
667
|
+
const was = useRef(false);
|
|
668
|
+
useEffect(() => {
|
|
669
|
+
if (was.current && !full) buttonRef.current?.focus();
|
|
670
|
+
was.current = full;
|
|
671
|
+
}, [full]);
|
|
672
|
+
useEffect(() => {
|
|
673
|
+
const wrap = wrapRef.current;
|
|
674
|
+
const bar = barRef.current;
|
|
675
|
+
const root = lm.root;
|
|
676
|
+
if (!full || !scene || !wrap || !bar || !root) return;
|
|
677
|
+
const px = (x) => Number.parseFloat(x) || 0;
|
|
678
|
+
const fit = () => {
|
|
679
|
+
const rs = getComputedStyle(root);
|
|
680
|
+
let around = px(rs.paddingTop) + px(rs.paddingBottom);
|
|
681
|
+
const add = (el) => {
|
|
682
|
+
const cs = getComputedStyle(el);
|
|
683
|
+
if (cs.display === "none" || cs.position === "absolute" || cs.position === "fixed") return;
|
|
684
|
+
around += px(rs.rowGap) + (px(cs.flexGrow) > 0 ? px(cs.minHeight) : el.offsetHeight);
|
|
685
|
+
};
|
|
686
|
+
for (const el of root.children) if (el !== wrap) add(el);
|
|
687
|
+
if (getComputedStyle(root, "::after").content !== "none") around += px(rs.rowGap);
|
|
688
|
+
const h = root.clientHeight - around - bar.offsetHeight - px(getComputedStyle(wrap).rowGap);
|
|
689
|
+
const w = Math.min(wrap.clientWidth, h * scene.width / scene.height);
|
|
690
|
+
wrap.style.setProperty("--lm-fit", `${Math.max(0, Math.floor(w))}px`);
|
|
691
|
+
};
|
|
692
|
+
const ro = new ResizeObserver(fit);
|
|
693
|
+
const watch = () => {
|
|
694
|
+
ro.disconnect();
|
|
695
|
+
ro.observe(bar);
|
|
696
|
+
ro.observe(root);
|
|
697
|
+
for (const el of root.children) ro.observe(el);
|
|
698
|
+
};
|
|
699
|
+
watch();
|
|
700
|
+
const mo = new MutationObserver(() => {
|
|
701
|
+
watch();
|
|
702
|
+
fit();
|
|
703
|
+
});
|
|
704
|
+
mo.observe(root, {
|
|
705
|
+
childList: true,
|
|
706
|
+
attributeFilter: ["data-mode"]
|
|
707
|
+
});
|
|
708
|
+
return () => {
|
|
709
|
+
ro.disconnect();
|
|
710
|
+
mo.disconnect();
|
|
711
|
+
wrap.style.removeProperty("--lm-fit");
|
|
712
|
+
};
|
|
713
|
+
}, [
|
|
714
|
+
full,
|
|
715
|
+
scene,
|
|
716
|
+
lm.root
|
|
717
|
+
]);
|
|
718
|
+
const { setFullScreenMode, fullScreenMode } = lm;
|
|
719
|
+
const modesRef = useRef(null);
|
|
720
|
+
useEffect(() => {
|
|
721
|
+
const root = lm.root;
|
|
722
|
+
if (!full || !root) return;
|
|
723
|
+
const f = (e) => {
|
|
724
|
+
if (e.key !== "f" && e.key !== "F" || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
725
|
+
if (typing(e.composedPath()[0] ?? null) || root.querySelector(":scope > [data-drawer]")) return;
|
|
726
|
+
e.preventDefault();
|
|
727
|
+
if (e.repeat) return;
|
|
728
|
+
const next = fullScreenMode === "focus" ? "panels" : "focus";
|
|
729
|
+
if (document.activeElement?.closest(".lm-dock, .lm-line")) modesRef.current?.querySelector(`[data-mode="${next}"]`)?.focus();
|
|
730
|
+
setFullScreenMode(next);
|
|
731
|
+
};
|
|
732
|
+
document.addEventListener("keydown", f);
|
|
733
|
+
return () => document.removeEventListener("keydown", f);
|
|
734
|
+
}, [
|
|
735
|
+
full,
|
|
736
|
+
fullScreenMode,
|
|
737
|
+
setFullScreenMode,
|
|
738
|
+
lm.root
|
|
739
|
+
]);
|
|
740
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
741
|
+
className: "lm-wrap",
|
|
742
|
+
ref: wrapRef,
|
|
743
|
+
children: [
|
|
744
|
+
/* @__PURE__ */ jsxs("div", {
|
|
745
|
+
className: "lm-bar",
|
|
746
|
+
ref: barRef,
|
|
747
|
+
children: [legend ? /* @__PURE__ */ jsx(Legend, { lm }) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsxs("span", {
|
|
748
|
+
className: "lm-tools",
|
|
749
|
+
children: [full && /* @__PURE__ */ jsx("fieldset", {
|
|
750
|
+
className: "lm-modes",
|
|
751
|
+
"aria-label": "Full screen shows (F)",
|
|
752
|
+
ref: modesRef,
|
|
753
|
+
children: ["panels", "focus"].map((m) => /* @__PURE__ */ jsx("button", {
|
|
754
|
+
type: "button",
|
|
755
|
+
"data-mode": m,
|
|
756
|
+
"aria-pressed": fullScreenMode === m,
|
|
757
|
+
"aria-keyshortcuts": "F",
|
|
758
|
+
onClick: () => setFullScreenMode(m),
|
|
759
|
+
children: m === "panels" ? "Panels" : "Focus"
|
|
760
|
+
}, m))
|
|
761
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
762
|
+
type: "button",
|
|
763
|
+
className: "lm-btn",
|
|
764
|
+
onClick: lm.toggleFullScreen,
|
|
765
|
+
"aria-pressed": full,
|
|
766
|
+
ref: buttonRef,
|
|
767
|
+
children: full ? "✕ Close" : "⤢ Full screen"
|
|
768
|
+
})]
|
|
769
|
+
})]
|
|
770
|
+
}),
|
|
771
|
+
/* @__PURE__ */ jsxs("div", {
|
|
772
|
+
className: "lm-board",
|
|
773
|
+
ref: boardRef,
|
|
774
|
+
style: frame ? { aspectRatio: `${frame.width} / ${frame.height}` } : { minHeight: 240 },
|
|
775
|
+
children: [frame && /* @__PURE__ */ jsx(Structure, {
|
|
776
|
+
lm,
|
|
777
|
+
scene: frame,
|
|
778
|
+
svgRef,
|
|
779
|
+
rates: reducedMotion,
|
|
780
|
+
setTip,
|
|
781
|
+
onClick: onNodeClick ? onClick : void 0,
|
|
782
|
+
selected
|
|
783
|
+
}), /* @__PURE__ */ jsx("canvas", {
|
|
784
|
+
ref: canvasRef,
|
|
785
|
+
hidden: reducedMotion
|
|
786
|
+
})]
|
|
787
|
+
}),
|
|
788
|
+
frame && tip && /* @__PURE__ */ jsx(Detail, {
|
|
789
|
+
lm,
|
|
790
|
+
scene: frame,
|
|
791
|
+
id: tip.id,
|
|
792
|
+
board: boardRef.current,
|
|
793
|
+
detailId
|
|
794
|
+
})
|
|
795
|
+
]
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
/** The keyboard is in a field that takes letters: the first target of the key, inside a web component too. */
|
|
799
|
+
function typing(t) {
|
|
800
|
+
if (!(t instanceof HTMLElement)) return false;
|
|
801
|
+
if (t.isContentEditable || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) return true;
|
|
802
|
+
return t instanceof HTMLInputElement && ![
|
|
803
|
+
"range",
|
|
804
|
+
"checkbox",
|
|
805
|
+
"radio",
|
|
806
|
+
"button",
|
|
807
|
+
"submit",
|
|
808
|
+
"reset",
|
|
809
|
+
"image",
|
|
810
|
+
"file",
|
|
811
|
+
"color"
|
|
812
|
+
].includes(t.type);
|
|
813
|
+
}
|
|
814
|
+
function Legend({ lm }) {
|
|
815
|
+
const flows = lm.view.def.flows;
|
|
816
|
+
const grey = Object.values(lm.ev.overload).some((o) => o.merge) || Object.values(lm.ev.stages).some((s) => s.kind === "fanout");
|
|
817
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
818
|
+
className: "lm-legend",
|
|
819
|
+
children: [
|
|
820
|
+
Object.entries(flows).map(([f, v]) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("i", { style: { background: tokenColor(v.color) } }), v.label ?? f] }, f)),
|
|
821
|
+
/* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("i", { style: { background: "var(--lm-ok)" } }), "done"] }),
|
|
822
|
+
/* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("i", { style: { background: "var(--lm-drop)" } }), "dropped or rejected"] }),
|
|
823
|
+
grey && /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("i", { style: { background: "var(--lm-muted)" } }), "superseded or unread"] }),
|
|
824
|
+
/* @__PURE__ */ jsx("span", { children: lm.reducedMotion ? "line width: rate" : `one dot ≈ ${lm.engine.sim.dotScale.toLocaleString("en-US")} a second · ${lm.engine.sim.speed}× speed` })
|
|
825
|
+
]
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
/** The component a box stands for: its stages' component, or its own. */
|
|
829
|
+
function componentOf(lm, n) {
|
|
830
|
+
return n.stages.map((s) => lm.ev.stages[s]?.component).find(Boolean) ?? n.component ?? void 0;
|
|
831
|
+
}
|
|
832
|
+
/** The SVG. It does not read the detail's state, so a hover re-renders the detail, not every box and edge. */
|
|
833
|
+
const Structure = memo(function Structure({ lm, scene, svgRef, rates, setTip, onClick, selected }) {
|
|
834
|
+
const marker = useId().replace(/:/g, "");
|
|
835
|
+
const { labels, ev } = lm;
|
|
836
|
+
const stateOf = (n) => {
|
|
837
|
+
const c = componentOf(lm, n);
|
|
838
|
+
return c ? ev.components[c]?.state ?? null : null;
|
|
839
|
+
};
|
|
840
|
+
const handlers = (n) => {
|
|
841
|
+
const cid = componentOf(lm, n);
|
|
842
|
+
const c = cid ? ev.components[cid] : void 0;
|
|
843
|
+
const title = labels.nodes[n.id]?.title;
|
|
844
|
+
if (!c) {
|
|
845
|
+
if (!onClick) return {};
|
|
846
|
+
return {
|
|
847
|
+
tabIndex: 0,
|
|
848
|
+
role: "button",
|
|
849
|
+
className: "lm-node",
|
|
850
|
+
"aria-label": title ?? n.id,
|
|
851
|
+
"aria-pressed": selected === n.id,
|
|
852
|
+
onClick: () => onClick(n.id),
|
|
853
|
+
onKeyDown: (e) => {
|
|
854
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
855
|
+
e.preventDefault();
|
|
856
|
+
onClick(n.id);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
const press = () => {
|
|
862
|
+
setTip((t) => t?.pinned && t.id === n.id ? null : {
|
|
863
|
+
id: n.id,
|
|
864
|
+
pinned: true
|
|
865
|
+
});
|
|
866
|
+
onClick?.(n.id);
|
|
867
|
+
};
|
|
868
|
+
return {
|
|
869
|
+
tabIndex: 0,
|
|
870
|
+
role: "button",
|
|
871
|
+
className: "lm-node",
|
|
872
|
+
"aria-label": `${title && title !== c.name ? `${title}, ` : ""}${c.name}: ${c.util == null ? "switched off" : pct(c.util)}`,
|
|
873
|
+
...onClick ? { "aria-pressed": selected === n.id } : {},
|
|
874
|
+
onPointerEnter: (e) => e.pointerType === "mouse" && setTip((t) => t?.pinned ? t : {
|
|
875
|
+
id: n.id,
|
|
876
|
+
pinned: false
|
|
877
|
+
}),
|
|
878
|
+
onPointerLeave: (e) => e.pointerType === "mouse" && setTip((t) => t?.pinned ? t : null),
|
|
879
|
+
onFocus: () => setTip((t) => t?.pinned ? t : {
|
|
880
|
+
id: n.id,
|
|
881
|
+
pinned: false
|
|
882
|
+
}),
|
|
883
|
+
onBlur: () => setTip((t) => t?.pinned ? t : null),
|
|
884
|
+
onClick: press,
|
|
885
|
+
onKeyDown: (e) => {
|
|
886
|
+
if (e.key === "Escape") setTip(null);
|
|
887
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
888
|
+
e.preventDefault();
|
|
889
|
+
press();
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
};
|
|
894
|
+
const summary = scene.nodes.map((n) => labels.nodes[n.id]?.title).join(", ");
|
|
895
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
896
|
+
ref: svgRef,
|
|
897
|
+
viewBox: `0 0 ${scene.width} ${scene.height}`,
|
|
898
|
+
role: "group",
|
|
899
|
+
"aria-label": `Diagram: ${summary}`,
|
|
900
|
+
children: [
|
|
901
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("marker", {
|
|
902
|
+
id: marker,
|
|
903
|
+
viewBox: "0 0 10 10",
|
|
904
|
+
refX: "9",
|
|
905
|
+
refY: "5",
|
|
906
|
+
markerWidth: "7",
|
|
907
|
+
markerHeight: "7",
|
|
908
|
+
orient: "auto-start-reverse",
|
|
909
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
910
|
+
d: "M0 0 L10 5 L0 10 z",
|
|
911
|
+
fill: "var(--lm-muted)"
|
|
912
|
+
})
|
|
913
|
+
}) }),
|
|
914
|
+
rates && /* @__PURE__ */ jsx(RateStrokes, {
|
|
915
|
+
lm,
|
|
916
|
+
scene
|
|
917
|
+
}),
|
|
918
|
+
scene.edges.map((e) => /* @__PURE__ */ jsx(Edge, {
|
|
919
|
+
e,
|
|
920
|
+
text: labels.edges[e.id],
|
|
921
|
+
marker
|
|
922
|
+
}, e.id)),
|
|
923
|
+
scene.nodes.map((n) => /* @__PURE__ */ jsx(Node, {
|
|
924
|
+
n,
|
|
925
|
+
state: stateOf(n),
|
|
926
|
+
title: labels.nodes[n.id]?.title,
|
|
927
|
+
sub: labels.nodes[n.id]?.sub,
|
|
928
|
+
lm,
|
|
929
|
+
focused: !!lm.focus && componentOf(lm, n) === lm.focus,
|
|
930
|
+
selected: selected === n.id,
|
|
931
|
+
handlers: handlers(n)
|
|
932
|
+
}, n.id))
|
|
933
|
+
]
|
|
934
|
+
});
|
|
935
|
+
});
|
|
936
|
+
const pathOf = (pts) => pts.map(([x, y], i) => `${i ? "L" : "M"}${x} ${y}`).join(" ");
|
|
937
|
+
function Edge({ e, text, marker }) {
|
|
938
|
+
const drawing = e.draw != null && e.draw < 1;
|
|
939
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
940
|
+
opacity: e.fade,
|
|
941
|
+
children: [/* @__PURE__ */ jsx("path", {
|
|
942
|
+
d: pathOf(e.points),
|
|
943
|
+
fill: "none",
|
|
944
|
+
stroke: "var(--lm-muted)",
|
|
945
|
+
strokeOpacity: ".7",
|
|
946
|
+
markerEnd: drawing ? void 0 : `url(#${marker})`,
|
|
947
|
+
...drawing ? {
|
|
948
|
+
pathLength: 1,
|
|
949
|
+
strokeDasharray: 1,
|
|
950
|
+
strokeDashoffset: 1 - e.draw
|
|
951
|
+
} : {}
|
|
952
|
+
}), e.label && text && /* @__PURE__ */ jsx("text", {
|
|
953
|
+
x: e.label.x + e.label.w / 2,
|
|
954
|
+
y: e.label.y + e.label.h / 2 + 4,
|
|
955
|
+
textAnchor: "middle",
|
|
956
|
+
fontSize: "11",
|
|
957
|
+
fill: "var(--lm-muted)",
|
|
958
|
+
children: text
|
|
959
|
+
})]
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
/** With reduced motion, each flow is a static stroke along its edges, its width scaled by its rate. */
|
|
963
|
+
function RateStrokes({ lm, scene }) {
|
|
964
|
+
const { ev } = lm;
|
|
965
|
+
const flows = lm.view.def.flows;
|
|
966
|
+
const max = Math.max(1e-9, ...Object.values(ev.flows));
|
|
967
|
+
const out = [];
|
|
968
|
+
for (const f of Object.keys(flows)) {
|
|
969
|
+
const seq = [scene.flowFrom[f], ...(ev.routes[f] ?? []).map((s) => scene.stageNode[s])].filter((n, i, a) => n && n !== a[i - 1]);
|
|
970
|
+
const rate = ev.flows[f] ?? 0;
|
|
971
|
+
const legs = seq.slice(1).map((to, i) => [
|
|
972
|
+
seq[i],
|
|
973
|
+
to,
|
|
974
|
+
rate
|
|
975
|
+
]);
|
|
976
|
+
const last = (ev.routes[f] ?? []).at(-1);
|
|
977
|
+
const st = last ? ev.stages[last] : void 0;
|
|
978
|
+
if (st?.kind === "fanout") for (const b of st.to[f] ?? []) legs.push([
|
|
979
|
+
scene.stageNode[last],
|
|
980
|
+
scene.stageNode[b.stage],
|
|
981
|
+
rate * b.share
|
|
982
|
+
]);
|
|
983
|
+
for (const [from, to, r] of legs) {
|
|
984
|
+
const e = scene.edges.find((x) => x.from === from && x.to === to);
|
|
985
|
+
if (e) out.push(/* @__PURE__ */ jsx("path", {
|
|
986
|
+
d: pathOf(e.points),
|
|
987
|
+
fill: "none",
|
|
988
|
+
stroke: tokenColor(flows[f].color),
|
|
989
|
+
strokeOpacity: ".45",
|
|
990
|
+
strokeWidth: 1.5 + 6 * Math.min(r, max) / max
|
|
991
|
+
}, `${f}:${e.id}`));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return /* @__PURE__ */ jsx("g", { children: out });
|
|
995
|
+
}
|
|
996
|
+
function Txt({ s, children, anchor = "middle", fill = "currentColor", opacity }) {
|
|
997
|
+
return /* @__PURE__ */ jsx("text", {
|
|
998
|
+
x: s.x,
|
|
999
|
+
y: s.y,
|
|
1000
|
+
fontSize: s.size,
|
|
1001
|
+
fontWeight: s.weight,
|
|
1002
|
+
textAnchor: anchor,
|
|
1003
|
+
fill,
|
|
1004
|
+
opacity,
|
|
1005
|
+
children
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
function Node({ n, state, title, sub, lm, focused, selected, handlers }) {
|
|
1009
|
+
const stroke = state ? STATE_STROKE[state] : "var(--lm-line)";
|
|
1010
|
+
const flows = lm.view.def.flows;
|
|
1011
|
+
const st = n.kind === "pool" ? lm.ev.stages[n.stages[0] ?? ""] : void 0;
|
|
1012
|
+
const running = st?.kind === "workers" ? st.running : n.members.length;
|
|
1013
|
+
const idle = (i) => i >= running && i < (st?.kind === "workers" ? st.pods : n.members.length);
|
|
1014
|
+
const e = 6;
|
|
1015
|
+
const grow = n.fade == null ? void 0 : `translate(${n.x + n.w / 2} ${n.y + n.h / 2}) scale(${.92 + .08 * n.fade}) translate(${-n.x - n.w / 2} ${-n.y - n.h / 2})`;
|
|
1016
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
1017
|
+
style: { color: "var(--lm-fg)" },
|
|
1018
|
+
opacity: n.fade,
|
|
1019
|
+
transform: grow,
|
|
1020
|
+
"data-node": n.id,
|
|
1021
|
+
"data-focus": focused || void 0,
|
|
1022
|
+
"data-selected": selected || void 0,
|
|
1023
|
+
...handlers,
|
|
1024
|
+
children: [
|
|
1025
|
+
n.shape === "cylinder" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
|
|
1026
|
+
d: `M${n.x} ${n.y + e} A${n.w / 2} ${e} 0 0 1 ${n.x + n.w} ${n.y + e} V${n.y + n.h - e} A${n.w / 2} ${e} 0 0 1 ${n.x} ${n.y + n.h - e} Z`,
|
|
1027
|
+
fill: "var(--lm-surface)",
|
|
1028
|
+
stroke,
|
|
1029
|
+
strokeWidth: "1.5"
|
|
1030
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
1031
|
+
d: `M${n.x} ${n.y + e} A${n.w / 2} ${e} 0 0 0 ${n.x + n.w} ${n.y + e}`,
|
|
1032
|
+
fill: "none",
|
|
1033
|
+
stroke,
|
|
1034
|
+
strokeWidth: "1.5"
|
|
1035
|
+
})] }) : /* @__PURE__ */ jsx("rect", {
|
|
1036
|
+
x: n.x,
|
|
1037
|
+
y: n.y,
|
|
1038
|
+
width: n.w,
|
|
1039
|
+
height: n.h,
|
|
1040
|
+
rx: "6",
|
|
1041
|
+
fill: "var(--lm-surface)",
|
|
1042
|
+
stroke,
|
|
1043
|
+
strokeWidth: "1.5"
|
|
1044
|
+
}),
|
|
1045
|
+
/* @__PURE__ */ jsx(Txt, {
|
|
1046
|
+
s: n.title,
|
|
1047
|
+
children: title
|
|
1048
|
+
}),
|
|
1049
|
+
n.sub && sub && /* @__PURE__ */ jsx(Txt, {
|
|
1050
|
+
s: n.sub,
|
|
1051
|
+
fill: "var(--lm-muted)",
|
|
1052
|
+
children: sub
|
|
1053
|
+
}),
|
|
1054
|
+
n.members.map((m, i) => /* @__PURE__ */ jsxs("g", {
|
|
1055
|
+
"data-idle": idle(i) || void 0,
|
|
1056
|
+
opacity: idle(i) ? .45 * (m.fade ?? 1) : m.fade,
|
|
1057
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
1058
|
+
x: m.x,
|
|
1059
|
+
y: m.y,
|
|
1060
|
+
width: m.w,
|
|
1061
|
+
height: m.h,
|
|
1062
|
+
rx: "4",
|
|
1063
|
+
fill: "none",
|
|
1064
|
+
stroke: "var(--lm-line)",
|
|
1065
|
+
strokeDasharray: idle(i) ? "3 3" : void 0
|
|
1066
|
+
}), /* @__PURE__ */ jsx(Txt, {
|
|
1067
|
+
s: m.spot,
|
|
1068
|
+
anchor: "start",
|
|
1069
|
+
fill: "var(--lm-muted)",
|
|
1070
|
+
children: m.label
|
|
1071
|
+
})]
|
|
1072
|
+
}, m.label)),
|
|
1073
|
+
n.groups.map((g, i) => /* @__PURE__ */ jsx(Txt, {
|
|
1074
|
+
s: g.spot,
|
|
1075
|
+
anchor: "start",
|
|
1076
|
+
fill: tokenColor(flows[g.flow]?.color ?? "muted"),
|
|
1077
|
+
opacity: g.fade,
|
|
1078
|
+
children: g.text
|
|
1079
|
+
}, `${g.flow}#${i}`)),
|
|
1080
|
+
n.cells.map((c) => /* @__PURE__ */ jsx("rect", {
|
|
1081
|
+
x: c.x,
|
|
1082
|
+
y: c.y,
|
|
1083
|
+
width: c.w,
|
|
1084
|
+
height: c.h,
|
|
1085
|
+
rx: "1.5",
|
|
1086
|
+
opacity: c.fade,
|
|
1087
|
+
fill: "var(--lm-lane)",
|
|
1088
|
+
stroke: tokenColor(flows[c.flow]?.color ?? "muted"),
|
|
1089
|
+
strokeOpacity: ".6"
|
|
1090
|
+
}, `${c.stage}/${c.flow}/${c.index}`)),
|
|
1091
|
+
n.slots.map((s) => /* @__PURE__ */ jsxs("g", {
|
|
1092
|
+
opacity: s.fade,
|
|
1093
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
1094
|
+
x: s.x,
|
|
1095
|
+
y: s.y,
|
|
1096
|
+
width: s.w,
|
|
1097
|
+
height: s.h,
|
|
1098
|
+
rx: "2",
|
|
1099
|
+
fill: "var(--lm-surface)",
|
|
1100
|
+
stroke: "currentColor",
|
|
1101
|
+
strokeOpacity: ".45"
|
|
1102
|
+
}), /* @__PURE__ */ jsx("rect", {
|
|
1103
|
+
"data-slot": s.index,
|
|
1104
|
+
"data-stage": n.stages[0],
|
|
1105
|
+
"data-y": s.y,
|
|
1106
|
+
"data-s": s.w,
|
|
1107
|
+
x: s.x + 1,
|
|
1108
|
+
y: s.y + s.h - 1,
|
|
1109
|
+
width: s.w - 2,
|
|
1110
|
+
height: 0,
|
|
1111
|
+
rx: "1",
|
|
1112
|
+
fill: "var(--lm-accent)"
|
|
1113
|
+
})]
|
|
1114
|
+
}, s.index)),
|
|
1115
|
+
selected && /* @__PURE__ */ jsx("rect", {
|
|
1116
|
+
className: "lm-selected",
|
|
1117
|
+
x: n.x - 3,
|
|
1118
|
+
y: n.y - 3,
|
|
1119
|
+
width: n.w + 6,
|
|
1120
|
+
height: n.h + 6,
|
|
1121
|
+
rx: "8",
|
|
1122
|
+
fill: "none",
|
|
1123
|
+
stroke: "var(--lm-accent)",
|
|
1124
|
+
strokeWidth: "2.5"
|
|
1125
|
+
}),
|
|
1126
|
+
focused && /* @__PURE__ */ jsx("rect", {
|
|
1127
|
+
className: "lm-focus",
|
|
1128
|
+
x: n.x - 5,
|
|
1129
|
+
y: n.y - 5,
|
|
1130
|
+
width: n.w + 10,
|
|
1131
|
+
height: n.h + 10,
|
|
1132
|
+
rx: "9",
|
|
1133
|
+
fill: "none",
|
|
1134
|
+
stroke: "var(--lm-accent)",
|
|
1135
|
+
strokeWidth: "2",
|
|
1136
|
+
strokeDasharray: "5 4"
|
|
1137
|
+
})
|
|
1138
|
+
]
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* A box's component in words, over the board: utilization, demand against capacity and where it came from, where it
|
|
1143
|
+
* reaches the target and 100 % (with dates, given growth), and its target in each scenario. HTML, so exports leave it out.
|
|
1144
|
+
*/
|
|
1145
|
+
function Detail({ lm, scene, id, board, detailId }) {
|
|
1146
|
+
const { model, ev } = lm;
|
|
1147
|
+
const n = scene.nodes.find((x) => x.id === id);
|
|
1148
|
+
const cid = n && componentOf(lm, n);
|
|
1149
|
+
const comparison = useComparison(lm);
|
|
1150
|
+
const rows = model.scenarios.length > 1 ? comparison.rows : [];
|
|
1151
|
+
useEffect(() => {
|
|
1152
|
+
const el = board?.querySelector(`[data-node="${CSS.escape(id)}"]`);
|
|
1153
|
+
el?.setAttribute("aria-describedby", detailId);
|
|
1154
|
+
return () => el?.removeAttribute("aria-describedby");
|
|
1155
|
+
}, [
|
|
1156
|
+
board,
|
|
1157
|
+
id,
|
|
1158
|
+
detailId
|
|
1159
|
+
]);
|
|
1160
|
+
const c = cid ? ev.components[cid] : void 0;
|
|
1161
|
+
const tip = useRef(null);
|
|
1162
|
+
const box = n && `${n.x} ${n.y} ${n.w} ${n.h}`;
|
|
1163
|
+
useLayoutEffect(() => {
|
|
1164
|
+
const el = tip.current;
|
|
1165
|
+
const wrap = el?.offsetParent;
|
|
1166
|
+
if (!el || !n || !board || !(wrap instanceof HTMLElement)) return;
|
|
1167
|
+
const place = () => {
|
|
1168
|
+
const k = board.clientWidth / scene.width;
|
|
1169
|
+
const w = wrap.getBoundingClientRect();
|
|
1170
|
+
const y = (v) => v - w.top - wrap.clientTop + wrap.scrollTop;
|
|
1171
|
+
let lo = 0;
|
|
1172
|
+
let hi = innerHeight;
|
|
1173
|
+
for (let a = wrap; a; a = a.parentElement) {
|
|
1174
|
+
if (getComputedStyle(a).overflowY === "visible") continue;
|
|
1175
|
+
const r = a.getBoundingClientRect();
|
|
1176
|
+
lo = Math.max(lo, r.top);
|
|
1177
|
+
hi = Math.min(hi, r.bottom);
|
|
1178
|
+
}
|
|
1179
|
+
const [top, bottom] = [y(lo) + 4, y(hi) - 4];
|
|
1180
|
+
const h = el.offsetHeight;
|
|
1181
|
+
const boxTop = board.offsetTop + n.y * k;
|
|
1182
|
+
const boxBottom = board.offsetTop + (n.y + n.h) * k;
|
|
1183
|
+
const below = boxBottom + 6;
|
|
1184
|
+
const above = boxTop - 6 - h;
|
|
1185
|
+
const fits = (n.y + n.h / 2 < scene.height / 2 ? [below, above] : [above, below]).find((t) => t >= top && t + h <= bottom);
|
|
1186
|
+
const roomier = bottom - boxBottom >= boxTop - top ? below : above;
|
|
1187
|
+
el.style.top = `${Math.max(top, Math.min(fits ?? roomier, bottom - h))}px`;
|
|
1188
|
+
el.style.left = `${Math.max(0, Math.min(board.offsetLeft + n.x * k, wrap.clientWidth - el.offsetWidth))}px`;
|
|
1189
|
+
};
|
|
1190
|
+
place();
|
|
1191
|
+
const ro = new ResizeObserver(place);
|
|
1192
|
+
ro.observe(el);
|
|
1193
|
+
ro.observe(board);
|
|
1194
|
+
document.addEventListener("scroll", place, {
|
|
1195
|
+
capture: true,
|
|
1196
|
+
passive: true
|
|
1197
|
+
});
|
|
1198
|
+
addEventListener("resize", place);
|
|
1199
|
+
return () => {
|
|
1200
|
+
ro.disconnect();
|
|
1201
|
+
document.removeEventListener("scroll", place, { capture: true });
|
|
1202
|
+
removeEventListener("resize", place);
|
|
1203
|
+
};
|
|
1204
|
+
}, [
|
|
1205
|
+
box,
|
|
1206
|
+
board,
|
|
1207
|
+
scene
|
|
1208
|
+
]);
|
|
1209
|
+
if (!n || !c || !board) return null;
|
|
1210
|
+
const at = (r, x) => r ? reach(r, model.searchMax, model.dateAt) : multiple(x, model.searchMax);
|
|
1211
|
+
const num = (x) => Math.abs(x) >= 1e3 ? compact(x) : fmt(x);
|
|
1212
|
+
const cap = c.capacity;
|
|
1213
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1214
|
+
id: detailId,
|
|
1215
|
+
className: "lm-tip lm-detail",
|
|
1216
|
+
role: "tooltip",
|
|
1217
|
+
ref: tip,
|
|
1218
|
+
children: [
|
|
1219
|
+
/* @__PURE__ */ jsxs("b", { children: [c.name, c === ev.firstLimit && /* @__PURE__ */ jsx("span", {
|
|
1220
|
+
className: "lm-tag",
|
|
1221
|
+
"data-kind": "first",
|
|
1222
|
+
children: "first limit"
|
|
1223
|
+
})] }),
|
|
1224
|
+
c.util == null || !cap ? /* @__PURE__ */ jsx("span", { children: "switched off" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1225
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1226
|
+
/* @__PURE__ */ jsx("strong", { children: pct(c.util) }),
|
|
1227
|
+
" · ",
|
|
1228
|
+
num(c.demand ?? 0),
|
|
1229
|
+
" of ",
|
|
1230
|
+
fmt(cap.value),
|
|
1231
|
+
" ",
|
|
1232
|
+
cap.unit,
|
|
1233
|
+
cap.within ? ` ±${pct(cap.within)}` : ""
|
|
1234
|
+
] }),
|
|
1235
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1236
|
+
className: "lm-sub",
|
|
1237
|
+
children: [
|
|
1238
|
+
"capacity",
|
|
1239
|
+
" ",
|
|
1240
|
+
/* @__PURE__ */ jsx("span", {
|
|
1241
|
+
className: "lm-prov",
|
|
1242
|
+
"data-kind": cap.provenance,
|
|
1243
|
+
children: cap.provenance
|
|
1244
|
+
}),
|
|
1245
|
+
cap.source ? `, ${cap.source}` : ""
|
|
1246
|
+
]
|
|
1247
|
+
}),
|
|
1248
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1249
|
+
pct(model.thresholds.target),
|
|
1250
|
+
" at ",
|
|
1251
|
+
at(c.targetRange, c.target)
|
|
1252
|
+
] }),
|
|
1253
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1254
|
+
pct(model.thresholds.full),
|
|
1255
|
+
" at ",
|
|
1256
|
+
at(c.fullRange, c.full)
|
|
1257
|
+
] }),
|
|
1258
|
+
blocks(lm, n).map((line) => /* @__PURE__ */ jsx("span", { children: line }, line)),
|
|
1259
|
+
c.over && /* @__PURE__ */ jsxs("span", {
|
|
1260
|
+
className: "lm-sub",
|
|
1261
|
+
children: [
|
|
1262
|
+
"Past ",
|
|
1263
|
+
pct(model.thresholds.full),
|
|
1264
|
+
": ",
|
|
1265
|
+
c.over,
|
|
1266
|
+
"."
|
|
1267
|
+
]
|
|
1268
|
+
})
|
|
1269
|
+
] }),
|
|
1270
|
+
rows.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
1271
|
+
className: "lm-sub",
|
|
1272
|
+
children: [
|
|
1273
|
+
pct(model.thresholds.target),
|
|
1274
|
+
" by scenario:",
|
|
1275
|
+
" ",
|
|
1276
|
+
rows.map((r, i) => {
|
|
1277
|
+
const x = r.components.find((y) => y.id === cid);
|
|
1278
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1279
|
+
className: "lm-nowrap",
|
|
1280
|
+
children: [
|
|
1281
|
+
i > 0 && " · ",
|
|
1282
|
+
/* @__PURE__ */ jsx("b", {
|
|
1283
|
+
className: "lm-key",
|
|
1284
|
+
style: { background: scenarioColor(model, r.label) }
|
|
1285
|
+
}),
|
|
1286
|
+
r.label,
|
|
1287
|
+
" ",
|
|
1288
|
+
x?.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true)
|
|
1289
|
+
]
|
|
1290
|
+
}, r.label);
|
|
1291
|
+
})
|
|
1292
|
+
]
|
|
1293
|
+
})
|
|
1294
|
+
]
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
/** What a box's building blocks do at these values: pods running, cache answers, what a stage turns away. */
|
|
1298
|
+
function blocks(lm, n) {
|
|
1299
|
+
const out = [];
|
|
1300
|
+
for (const id of n.stages) {
|
|
1301
|
+
const s = lm.ev.stages[id];
|
|
1302
|
+
if (s?.kind === "workers" && s.autoscale) out.push(`${s.running} of ${s.pods} pods running, each held near ${pct(s.autoscale.target)}`);
|
|
1303
|
+
if (s?.kind === "cache") out.push(`${pct(s.hit)} answered here`);
|
|
1304
|
+
if ((s?.kind === "pass" || s?.kind === "limit" || s?.kind === "cache") && s.shed > 0) out.push(`${pct(s.shed)} of what reaches it turned away`);
|
|
1305
|
+
}
|
|
1306
|
+
return out;
|
|
1307
|
+
}
|
|
1308
|
+
// src/elk.ts
|
|
1309
|
+
let shared = null;
|
|
1310
|
+
/**
|
|
1311
|
+
* One ELK worker for every loadmap on the page, started on the first layout. When the worker cannot start or load
|
|
1312
|
+
* (no Worker, a CSP without worker-src, a dev server that pre-bundled this package away from the worker file), every
|
|
1313
|
+
* layout runs on the main thread instead: slower to start, the same result.
|
|
1314
|
+
*/
|
|
1315
|
+
function pageElk() {
|
|
1316
|
+
shared ??= workerElk(() => new Worker(new URL("./elk.worker.js", import.meta.url), {
|
|
1317
|
+
type: "module",
|
|
1318
|
+
name: "loadmap-elk"
|
|
1319
|
+
}));
|
|
1320
|
+
return shared;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* ELK in the worker `make` starts, falling back to the main thread: `<Loadmap elk={workerElk(…)}>` for a page whose
|
|
1324
|
+
* bundler inlines the worker (`@loadmap/react/elk.worker.js`), or that serves it from another place. Make it once,
|
|
1325
|
+
* outside a component: each engine starts its own worker.
|
|
1326
|
+
*/
|
|
1327
|
+
function workerElk(make) {
|
|
1328
|
+
let worker = null;
|
|
1329
|
+
let broken = typeof Worker === "undefined";
|
|
1330
|
+
let told = false;
|
|
1331
|
+
let next = 0;
|
|
1332
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1333
|
+
const tell = (why) => {
|
|
1334
|
+
if (told || typeof Worker === "undefined") return;
|
|
1335
|
+
told = true;
|
|
1336
|
+
console.info(`loadmap: the layout runs on the main thread, slower to start: the ELK worker did not start (${why}). A page can hand one in, <Loadmap elk={workerElk(() => new Worker(…))}>; a Content-Security-Policy must allow it (worker-src).`);
|
|
1337
|
+
};
|
|
1338
|
+
const fallBack = (why) => {
|
|
1339
|
+
tell(why);
|
|
1340
|
+
broken = true;
|
|
1341
|
+
worker?.terminate();
|
|
1342
|
+
worker = null;
|
|
1343
|
+
for (const [id, p] of pending) {
|
|
1344
|
+
pending.delete(id);
|
|
1345
|
+
localElk().then((elk) => elk.layout(p.graph)).then(p.resolve, p.reject);
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
const start = () => {
|
|
1349
|
+
if (worker || broken) return worker;
|
|
1350
|
+
try {
|
|
1351
|
+
worker = make();
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
fallBack(err instanceof Error ? err.message : String(err));
|
|
1354
|
+
return null;
|
|
1355
|
+
}
|
|
1356
|
+
worker.onmessage = ({ data }) => {
|
|
1357
|
+
const p = pending.get(data.id);
|
|
1358
|
+
if (!p) return;
|
|
1359
|
+
pending.delete(data.id);
|
|
1360
|
+
if (data.error != null) p.reject(new Error(data.error));
|
|
1361
|
+
else p.resolve(data.graph);
|
|
1362
|
+
};
|
|
1363
|
+
worker.onerror = (e) => {
|
|
1364
|
+
e.preventDefault();
|
|
1365
|
+
fallBack(e.message || "it failed to load or to run");
|
|
1366
|
+
};
|
|
1367
|
+
return worker;
|
|
1368
|
+
};
|
|
1369
|
+
return { layout(graph) {
|
|
1370
|
+
const w = start();
|
|
1371
|
+
if (!w) {
|
|
1372
|
+
tell("no Worker here");
|
|
1373
|
+
return localElk().then((elk) => elk.layout(graph));
|
|
1374
|
+
}
|
|
1375
|
+
return new Promise((resolve, reject) => {
|
|
1376
|
+
const id = next++;
|
|
1377
|
+
pending.set(id, {
|
|
1378
|
+
graph,
|
|
1379
|
+
resolve,
|
|
1380
|
+
reject
|
|
1381
|
+
});
|
|
1382
|
+
w.postMessage({
|
|
1383
|
+
id,
|
|
1384
|
+
graph
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
} };
|
|
1388
|
+
}
|
|
1389
|
+
// src/panels.tsx
|
|
1390
|
+
/** The model's one-sentence answer for the current values, and which capacity to measure when it is unsure. */
|
|
1391
|
+
function Verdict({ lm }) {
|
|
1392
|
+
const { measure } = lm.ev;
|
|
1393
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
|
|
1394
|
+
className: "lm-verdict",
|
|
1395
|
+
"data-tier": lm.ev.verdict.tier,
|
|
1396
|
+
"aria-live": "polite",
|
|
1397
|
+
children: lm.ev.verdict.text
|
|
1398
|
+
}), measure && /* @__PURE__ */ jsx("p", {
|
|
1399
|
+
className: "lm-measure",
|
|
1400
|
+
"data-component": measure.component,
|
|
1401
|
+
children: measure.text
|
|
1402
|
+
})] });
|
|
1403
|
+
}
|
|
1404
|
+
/** "±30 %" for a capacity with a range. */
|
|
1405
|
+
const plusMinus = (c) => c?.within ? `±${pct(c.within)}` : "";
|
|
1406
|
+
/** Each component's utilization in the order they reach the target, with where they cross it and 100 %. */
|
|
1407
|
+
function Limits({ lm, title = "Where it runs out, in order" }) {
|
|
1408
|
+
const { ev, model } = lm;
|
|
1409
|
+
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
1410
|
+
const at = (u) => `${u / top * 100}%`;
|
|
1411
|
+
const span = (r, x) => r ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax);
|
|
1412
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1413
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
1414
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1415
|
+
className: "lm-scale",
|
|
1416
|
+
"aria-hidden": "true",
|
|
1417
|
+
children: [
|
|
1418
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
1419
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1420
|
+
/* @__PURE__ */ jsx("span", {
|
|
1421
|
+
style: {
|
|
1422
|
+
left: 0,
|
|
1423
|
+
transform: "none"
|
|
1424
|
+
},
|
|
1425
|
+
children: "0"
|
|
1426
|
+
}),
|
|
1427
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1428
|
+
style: { left: at(model.thresholds.target) },
|
|
1429
|
+
children: [pct(model.thresholds.target), " target"]
|
|
1430
|
+
}),
|
|
1431
|
+
/* @__PURE__ */ jsx("span", {
|
|
1432
|
+
style: { left: at(model.thresholds.full) },
|
|
1433
|
+
children: pct(model.thresholds.full)
|
|
1434
|
+
}),
|
|
1435
|
+
/* @__PURE__ */ jsx("span", {
|
|
1436
|
+
style: {
|
|
1437
|
+
left: "100%",
|
|
1438
|
+
transform: "translateX(-100%)"
|
|
1439
|
+
},
|
|
1440
|
+
children: pct(top)
|
|
1441
|
+
})
|
|
1442
|
+
] }),
|
|
1443
|
+
/* @__PURE__ */ jsx("span", {})
|
|
1444
|
+
]
|
|
1445
|
+
}),
|
|
1446
|
+
/* @__PURE__ */ jsx("div", {
|
|
1447
|
+
className: "lm-limits",
|
|
1448
|
+
children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
|
|
1449
|
+
className: "lm-lim",
|
|
1450
|
+
"data-component": c.id,
|
|
1451
|
+
children: [
|
|
1452
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("b", { children: [
|
|
1453
|
+
c.name,
|
|
1454
|
+
c === ev.firstLimit && /* @__PURE__ */ jsx("span", {
|
|
1455
|
+
className: "lm-tag",
|
|
1456
|
+
"data-kind": "first",
|
|
1457
|
+
children: "first limit"
|
|
1458
|
+
}),
|
|
1459
|
+
c.capacity?.provenance === "estimated" ? /* @__PURE__ */ jsxs("span", {
|
|
1460
|
+
className: "lm-tag",
|
|
1461
|
+
"data-kind": "estimated",
|
|
1462
|
+
children: ["estimate", c.capacity.within ? ` ${plusMinus(c.capacity)}` : ""]
|
|
1463
|
+
}) : !!c.capacity?.within && /* @__PURE__ */ jsx("span", {
|
|
1464
|
+
className: "lm-tag",
|
|
1465
|
+
"data-kind": "range",
|
|
1466
|
+
children: plusMinus(c.capacity)
|
|
1467
|
+
})
|
|
1468
|
+
] }), /* @__PURE__ */ jsx("span", {
|
|
1469
|
+
className: "lm-sub",
|
|
1470
|
+
children: c.describe ?? (c.capacity ? `${fmt(c.capacity.value)} ${c.capacity.unit}` : "switched off")
|
|
1471
|
+
})] }),
|
|
1472
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1473
|
+
className: "lm-track",
|
|
1474
|
+
role: "img",
|
|
1475
|
+
"aria-label": `${c.name} at ${c.util == null ? "off" : pct(c.util)}`,
|
|
1476
|
+
children: [
|
|
1477
|
+
/* @__PURE__ */ jsx("div", {
|
|
1478
|
+
className: "lm-fill",
|
|
1479
|
+
"data-state": c.state,
|
|
1480
|
+
style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
|
|
1481
|
+
}),
|
|
1482
|
+
/* @__PURE__ */ jsx("div", {
|
|
1483
|
+
className: "lm-tick",
|
|
1484
|
+
style: { left: at(model.thresholds.target) }
|
|
1485
|
+
}),
|
|
1486
|
+
/* @__PURE__ */ jsx("div", {
|
|
1487
|
+
className: "lm-tick",
|
|
1488
|
+
style: { left: at(model.thresholds.full) }
|
|
1489
|
+
})
|
|
1490
|
+
]
|
|
1491
|
+
}),
|
|
1492
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1493
|
+
className: "lm-val",
|
|
1494
|
+
children: [c.util == null ? "—" : `${pct(c.util)} · ${num(c.demand ?? 0)} ${c.capacity?.unit ?? ""}`, /* @__PURE__ */ jsx("small", { children: c.util == null ? "switched off" : `${pct(model.thresholds.target)} at ${span(c.targetRange, c.target)} · full at ${span(c.fullRange, c.full)}` })]
|
|
1495
|
+
})
|
|
1496
|
+
]
|
|
1497
|
+
}, c.id))
|
|
1498
|
+
})
|
|
1499
|
+
] });
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Live numbers: from the sim, lag and drops per queue, busy workers, rejected requests; from the model, pods running,
|
|
1503
|
+
* cache answers and retries.
|
|
1504
|
+
*/
|
|
1505
|
+
function Meters({ lm }) {
|
|
1506
|
+
const [, tick] = useState(0);
|
|
1507
|
+
useEffect(() => {
|
|
1508
|
+
const t = setInterval(() => tick((x) => x + 1), 250);
|
|
1509
|
+
return () => clearInterval(t);
|
|
1510
|
+
}, []);
|
|
1511
|
+
const { ev, engine, model } = lm;
|
|
1512
|
+
const sim = engine.sim;
|
|
1513
|
+
const flowLabel = (f) => model.def.flows[f]?.label ?? f;
|
|
1514
|
+
const items = [];
|
|
1515
|
+
for (const s of Object.values(ev.stages)) {
|
|
1516
|
+
if (s.kind === "queue") for (const f of model.flowIds.filter((x) => ev.routes[x]?.includes(s.id))) {
|
|
1517
|
+
const q = sim.queue(s.id, f);
|
|
1518
|
+
const rules = ev.overload[f] ?? {};
|
|
1519
|
+
items.push({
|
|
1520
|
+
key: `${s.id}/${f}/lag`,
|
|
1521
|
+
value: secs(q.lag),
|
|
1522
|
+
label: `${flowLabel(f)} lag in ${s.label}`,
|
|
1523
|
+
state: q.lag > 60 ? "over" : q.lag > 5 ? "warn" : "ok"
|
|
1524
|
+
});
|
|
1525
|
+
if (rules.merge) items.push({
|
|
1526
|
+
key: `${s.id}/${f}/merge`,
|
|
1527
|
+
value: compact(q.merged),
|
|
1528
|
+
label: `${flowLabel(f)} superseded /s (${rules.merge.reason ?? "newest kept"})`,
|
|
1529
|
+
state: q.merged > .5 ? "warn" : "ok"
|
|
1530
|
+
});
|
|
1531
|
+
if (rules.drop) items.push({
|
|
1532
|
+
key: `${s.id}/${f}/drop`,
|
|
1533
|
+
value: compact(q.dropped),
|
|
1534
|
+
label: `${flowLabel(f)} dropped /s (${rules.drop.reason ?? "too old"})`,
|
|
1535
|
+
state: q.dropped > .5 ? "over" : "ok"
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
if (s.kind === "workers") {
|
|
1539
|
+
const b = sim.busy(s.id);
|
|
1540
|
+
items.push({
|
|
1541
|
+
key: `${s.id}/busy`,
|
|
1542
|
+
value: pct(b),
|
|
1543
|
+
label: `${s.label} busy`,
|
|
1544
|
+
state: b > .95 ? "over" : b > .5 ? "warn" : "ok"
|
|
1545
|
+
});
|
|
1546
|
+
if (s.autoscale) items.push({
|
|
1547
|
+
key: `${s.id}/pods`,
|
|
1548
|
+
value: `${s.running} of ${s.pods}`,
|
|
1549
|
+
label: `${s.label} pods running`,
|
|
1550
|
+
state: s.running < s.pods ? "ok" : (ev.components[s.component]?.util ?? 0) > model.thresholds.full ? "over" : "warn"
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
if (s.kind === "cache") items.push({
|
|
1554
|
+
key: `${s.id}/hits`,
|
|
1555
|
+
value: compact(sim.arriving(s.id) * (1 - sim.shed(s.id)) * s.hit),
|
|
1556
|
+
label: `answered at ${s.label} /s (${pct(s.hit)} hits)`,
|
|
1557
|
+
state: "ok"
|
|
1558
|
+
});
|
|
1559
|
+
if ((s.kind === "pass" || s.kind === "limit" || s.kind === "cache") && sim.shed(s.id) > 0) items.push({
|
|
1560
|
+
key: `${s.id}/shed`,
|
|
1561
|
+
value: pct(sim.shed(s.id)),
|
|
1562
|
+
label: `rejected at ${s.label}`,
|
|
1563
|
+
state: "over"
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
for (const f of model.flowIds) {
|
|
1567
|
+
const r = ev.retry[f];
|
|
1568
|
+
if (!r || !(r.rate > 0)) continue;
|
|
1569
|
+
const per = r.attempts / r.rate;
|
|
1570
|
+
items.push({
|
|
1571
|
+
key: `${f}/attempts`,
|
|
1572
|
+
value: `${fmt(per)}×`,
|
|
1573
|
+
label: `${flowLabel(f)} attempts per ${model.def.flows[f]?.unit ?? "unit"}`,
|
|
1574
|
+
state: per > 1.05 ? "warn" : "ok"
|
|
1575
|
+
});
|
|
1576
|
+
items.push({
|
|
1577
|
+
key: `${f}/failed`,
|
|
1578
|
+
value: pct(r.failed),
|
|
1579
|
+
label: `${flowLabel(f)} failing after ${r.times} ${r.times === 1 ? "retry" : "retries"}`,
|
|
1580
|
+
state: r.failed > .005 ? "over" : "ok"
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Live" }), /* @__PURE__ */ jsx("div", {
|
|
1584
|
+
className: "lm-meters",
|
|
1585
|
+
children: items.map((m) => /* @__PURE__ */ jsxs("div", {
|
|
1586
|
+
className: "lm-meter",
|
|
1587
|
+
"data-state": m.state,
|
|
1588
|
+
children: [/* @__PURE__ */ jsx("b", { children: m.value }), /* @__PURE__ */ jsx("span", {
|
|
1589
|
+
title: m.label,
|
|
1590
|
+
children: m.label
|
|
1591
|
+
})]
|
|
1592
|
+
}, m.key))
|
|
1593
|
+
})] });
|
|
1594
|
+
}
|
|
1595
|
+
/** The load slider with its label and value. */
|
|
1596
|
+
function LoadRange({ lm }) {
|
|
1597
|
+
const load = lm.model.load;
|
|
1598
|
+
const x = lm.values.load;
|
|
1599
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
1600
|
+
className: "lm-range",
|
|
1601
|
+
children: [/* @__PURE__ */ jsxs("span", { children: [
|
|
1602
|
+
load.label,
|
|
1603
|
+
" ",
|
|
1604
|
+
/* @__PURE__ */ jsxs("output", { children: [fmt(x), "×"] })
|
|
1605
|
+
] }), /* @__PURE__ */ jsx("input", {
|
|
1606
|
+
type: "range",
|
|
1607
|
+
min: load.min,
|
|
1608
|
+
max: load.max,
|
|
1609
|
+
step: load.step,
|
|
1610
|
+
value: x,
|
|
1611
|
+
onChange: (e) => lm.setValues({ load: Number(e.target.value) })
|
|
1612
|
+
})]
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
/** The load slider, the presets and every parameter, greyed out where it does not apply. */
|
|
1616
|
+
function Controls({ lm }) {
|
|
1617
|
+
const { model, values, setValues, ev } = lm;
|
|
1618
|
+
const v = values;
|
|
1619
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1620
|
+
className: "lm-card lm-controls",
|
|
1621
|
+
children: [
|
|
1622
|
+
/* @__PURE__ */ jsx("h3", { children: "Load" }),
|
|
1623
|
+
/* @__PURE__ */ jsx(LoadRange, { lm }),
|
|
1624
|
+
/* @__PURE__ */ jsx("div", {
|
|
1625
|
+
className: "lm-presets",
|
|
1626
|
+
children: ev.presets.map((p) => {
|
|
1627
|
+
const on = Object.entries(p.values).every(([k, x]) => v[k] === x);
|
|
1628
|
+
return /* @__PURE__ */ jsx("button", {
|
|
1629
|
+
type: "button",
|
|
1630
|
+
"aria-pressed": on,
|
|
1631
|
+
onClick: () => setValues(p.values),
|
|
1632
|
+
children: p.label
|
|
1633
|
+
}, p.label);
|
|
1634
|
+
})
|
|
1635
|
+
}),
|
|
1636
|
+
model.params.length > 1 && /* @__PURE__ */ jsx("h3", { children: "Design" }),
|
|
1637
|
+
model.params.map(({ id, def }) => {
|
|
1638
|
+
if (def.kind === "load") return null;
|
|
1639
|
+
const enabled = model.isEnabled(id, v);
|
|
1640
|
+
const tag = def.tag && /* @__PURE__ */ jsx("span", {
|
|
1641
|
+
className: "lm-tag",
|
|
1642
|
+
"data-kind": "estimated",
|
|
1643
|
+
children: def.tag
|
|
1644
|
+
});
|
|
1645
|
+
if (def.kind === "switch") return /* @__PURE__ */ jsxs("label", {
|
|
1646
|
+
className: `lm-switch${enabled ? "" : " lm-off"}`,
|
|
1647
|
+
children: [
|
|
1648
|
+
/* @__PURE__ */ jsx("input", {
|
|
1649
|
+
type: "checkbox",
|
|
1650
|
+
checked: Boolean(v[id]),
|
|
1651
|
+
disabled: !enabled,
|
|
1652
|
+
onChange: (e) => setValues({ [id]: e.target.checked })
|
|
1653
|
+
}),
|
|
1654
|
+
/* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
|
|
1655
|
+
def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
|
|
1656
|
+
]
|
|
1657
|
+
}, id);
|
|
1658
|
+
if (def.kind === "select") return /* @__PURE__ */ jsxs("label", {
|
|
1659
|
+
className: `lm-select${enabled ? "" : " lm-off"}`,
|
|
1660
|
+
children: [
|
|
1661
|
+
/* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
|
|
1662
|
+
/* @__PURE__ */ jsx("select", {
|
|
1663
|
+
value: String(v[id]),
|
|
1664
|
+
disabled: !enabled,
|
|
1665
|
+
onChange: (e) => {
|
|
1666
|
+
const opt = def.options.find((o) => String(o) === e.target.value);
|
|
1667
|
+
setValues({ [id]: opt });
|
|
1668
|
+
},
|
|
1669
|
+
children: def.options.map((o) => /* @__PURE__ */ jsx("option", {
|
|
1670
|
+
value: String(o),
|
|
1671
|
+
children: def.format ? def.format(o) : String(o)
|
|
1672
|
+
}, String(o)))
|
|
1673
|
+
}),
|
|
1674
|
+
def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
|
|
1675
|
+
]
|
|
1676
|
+
}, id);
|
|
1677
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
1678
|
+
className: `lm-range${enabled ? "" : " lm-off"}`,
|
|
1679
|
+
children: [
|
|
1680
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1681
|
+
def.label,
|
|
1682
|
+
tag,
|
|
1683
|
+
" ",
|
|
1684
|
+
/* @__PURE__ */ jsx("output", { children: def.format ? def.format(v[id]) : fmt(v[id]) })
|
|
1685
|
+
] }),
|
|
1686
|
+
/* @__PURE__ */ jsx("input", {
|
|
1687
|
+
type: "range",
|
|
1688
|
+
min: def.min,
|
|
1689
|
+
max: def.max,
|
|
1690
|
+
step: def.step,
|
|
1691
|
+
value: v[id],
|
|
1692
|
+
disabled: !enabled,
|
|
1693
|
+
onChange: (e) => setValues({ [id]: Number(e.target.value) })
|
|
1694
|
+
}),
|
|
1695
|
+
def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
|
|
1696
|
+
]
|
|
1697
|
+
}, id);
|
|
1698
|
+
})
|
|
1699
|
+
]
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
/** What the model assumes: every capacity with its provenance, every fit, and anything the page adds. */
|
|
1703
|
+
function Assumptions({ lm, extra = [] }) {
|
|
1704
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1705
|
+
className: "lm-card",
|
|
1706
|
+
children: [/* @__PURE__ */ jsx("h3", { children: "What this assumes" }), /* @__PURE__ */ jsxs("ul", {
|
|
1707
|
+
className: "lm-facts",
|
|
1708
|
+
children: [extra.map((x, i) => /* @__PURE__ */ jsx("li", { children: x }, i)), lm.ev.assumptions.map((a) => /* @__PURE__ */ jsx("li", { children: describe(a) }, a.kind === "capacity" ? `c:${a.component}` : `f:${a.name}`))]
|
|
1709
|
+
})]
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
function describe(a) {
|
|
1713
|
+
if (a.kind === "capacity") {
|
|
1714
|
+
const c = a.capacity;
|
|
1715
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1716
|
+
/* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
|
|
1717
|
+
" ",
|
|
1718
|
+
fmt(c.value),
|
|
1719
|
+
" ",
|
|
1720
|
+
c.unit,
|
|
1721
|
+
c.within ? ` ${plusMinus(c)}` : "",
|
|
1722
|
+
",",
|
|
1723
|
+
" ",
|
|
1724
|
+
/* @__PURE__ */ jsx("span", {
|
|
1725
|
+
className: "lm-prov",
|
|
1726
|
+
"data-kind": c.provenance,
|
|
1727
|
+
children: c.provenance
|
|
1728
|
+
}),
|
|
1729
|
+
c.source ? ` (${c.source})` : "",
|
|
1730
|
+
"."
|
|
1731
|
+
] });
|
|
1732
|
+
}
|
|
1733
|
+
const f = a.fit;
|
|
1734
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1735
|
+
/* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
|
|
1736
|
+
" ",
|
|
1737
|
+
f.y,
|
|
1738
|
+
" = ",
|
|
1739
|
+
sig(f.a),
|
|
1740
|
+
" + ",
|
|
1741
|
+
sig(f.b),
|
|
1742
|
+
" × ",
|
|
1743
|
+
f.x,
|
|
1744
|
+
", r² ",
|
|
1745
|
+
f.r2.toFixed(3),
|
|
1746
|
+
" over ",
|
|
1747
|
+
f.n,
|
|
1748
|
+
" points,",
|
|
1749
|
+
" ",
|
|
1750
|
+
/* @__PURE__ */ jsx("span", {
|
|
1751
|
+
className: "lm-prov",
|
|
1752
|
+
"data-kind": "measured",
|
|
1753
|
+
children: "measured"
|
|
1754
|
+
}),
|
|
1755
|
+
f.source ? ` (${f.source})` : "",
|
|
1756
|
+
"."
|
|
1757
|
+
] });
|
|
1758
|
+
}
|
|
1759
|
+
/** Exact below 1,000 (3.9 cores), compact above (12k req/s). */
|
|
1760
|
+
const num = (x) => Math.abs(x) >= 1e3 ? compact(x) : fmt(x);
|
|
1761
|
+
const sig = (x) => Number(x.toPrecision(3)).toString();
|
|
1762
|
+
// src/compact.tsx
|
|
1763
|
+
/** The names a reader sees for the panels, on the tabs and the buttons that open them. */
|
|
1764
|
+
const NAMES = {
|
|
1765
|
+
verdict: "Verdict",
|
|
1766
|
+
live: "Live",
|
|
1767
|
+
limits: "Limits",
|
|
1768
|
+
controls: "Load",
|
|
1769
|
+
headroom: "Headroom",
|
|
1770
|
+
compare: "Compare",
|
|
1771
|
+
assumptions: "Assumptions"
|
|
1772
|
+
};
|
|
1773
|
+
/**
|
|
1774
|
+
* The verdict in one line, from the same evaluation as the sentence: the load, how far the target holds, the first
|
|
1775
|
+
* limit and how sure its capacity is, what is past capacity. The sentence is its tooltip and opens under "Why".
|
|
1776
|
+
*/
|
|
1777
|
+
function VerdictLine({ lm, verdict = true, extra = 0, open, assumptions }) {
|
|
1778
|
+
const { ev, model, values } = lm;
|
|
1779
|
+
const first = ev.firstLimit;
|
|
1780
|
+
const range = ev.target;
|
|
1781
|
+
const target = `${pct(model.thresholds.target)} target`;
|
|
1782
|
+
const c = first?.capacity;
|
|
1783
|
+
const sure = !c ? "" : c.provenance === "estimated" ? `est${c.within ? ` ${plusMinus(c)}` : ""}` : plusMinus(c);
|
|
1784
|
+
const over = ev.ranked.filter((x) => (x.util ?? 0) > model.thresholds.full);
|
|
1785
|
+
const when = range ? whenRange(model, range) : "";
|
|
1786
|
+
const estimated = ev.assumptions.filter((a) => a.kind === "capacity" && a.capacity.provenance === "estimated").length;
|
|
1787
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1788
|
+
verdict && /* @__PURE__ */ jsx("p", {
|
|
1789
|
+
className: "lm-headline",
|
|
1790
|
+
title: ev.verdict.text,
|
|
1791
|
+
"aria-live": "polite",
|
|
1792
|
+
children: !first || !range ? ev.verdict.text : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1793
|
+
/* @__PURE__ */ jsxs("b", {
|
|
1794
|
+
className: "lm-num",
|
|
1795
|
+
children: [fmt(values.load), "×"]
|
|
1796
|
+
}),
|
|
1797
|
+
" ·",
|
|
1798
|
+
" ",
|
|
1799
|
+
values.load < range.low ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1800
|
+
"the ",
|
|
1801
|
+
target,
|
|
1802
|
+
" holds to ",
|
|
1803
|
+
/* @__PURE__ */ jsx("b", {
|
|
1804
|
+
className: "lm-num",
|
|
1805
|
+
children: multiples(range, model.searchMax, true)
|
|
1806
|
+
}),
|
|
1807
|
+
when && ` (${when})`
|
|
1808
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1809
|
+
"past the ",
|
|
1810
|
+
target,
|
|
1811
|
+
" from ",
|
|
1812
|
+
/* @__PURE__ */ jsx("b", {
|
|
1813
|
+
className: "lm-num",
|
|
1814
|
+
children: multiple(range.low, model.searchMax)
|
|
1815
|
+
})
|
|
1816
|
+
] }),
|
|
1817
|
+
" ",
|
|
1818
|
+
"· first limit ",
|
|
1819
|
+
/* @__PURE__ */ jsx("b", { children: first.name }),
|
|
1820
|
+
sure && /* @__PURE__ */ jsx("span", {
|
|
1821
|
+
className: "lm-tag",
|
|
1822
|
+
"data-kind": c?.provenance === "estimated" ? "estimated" : "range",
|
|
1823
|
+
children: sure
|
|
1824
|
+
}),
|
|
1825
|
+
over.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1826
|
+
" ",
|
|
1827
|
+
"· ",
|
|
1828
|
+
/* @__PURE__ */ jsx("b", { children: over.map((x) => x.name).join(", ") }),
|
|
1829
|
+
" past capacity"
|
|
1830
|
+
] })
|
|
1831
|
+
] })
|
|
1832
|
+
}),
|
|
1833
|
+
open && verdict && /* @__PURE__ */ jsx("button", {
|
|
1834
|
+
type: "button",
|
|
1835
|
+
className: "lm-link",
|
|
1836
|
+
onClick: (e) => open("verdict", e.currentTarget),
|
|
1837
|
+
children: "Why ›"
|
|
1838
|
+
}),
|
|
1839
|
+
open && assumptions && /* @__PURE__ */ jsxs("button", {
|
|
1840
|
+
type: "button",
|
|
1841
|
+
className: "lm-link",
|
|
1842
|
+
onClick: (e) => open("assumptions", e.currentTarget),
|
|
1843
|
+
children: [
|
|
1844
|
+
"What this assumes · ",
|
|
1845
|
+
ev.assumptions.length + extra,
|
|
1846
|
+
estimated > 0 && ` (${estimated} estimated)`,
|
|
1847
|
+
" ›"
|
|
1848
|
+
]
|
|
1849
|
+
})
|
|
1850
|
+
] });
|
|
1851
|
+
}
|
|
1852
|
+
/** The order of the cards in the dock: what the reader changes first, what it changes next to it. */
|
|
1853
|
+
const DOCK = [
|
|
1854
|
+
"controls",
|
|
1855
|
+
"live",
|
|
1856
|
+
"limits",
|
|
1857
|
+
"headroom",
|
|
1858
|
+
"compare"
|
|
1859
|
+
];
|
|
1860
|
+
/**
|
|
1861
|
+
* Full screen's panels, compact, side by side in a box the screen sizes: what does not fit is left out whole, and
|
|
1862
|
+
* each card opens its panel whole. A phone shows one at a time, under tabs.
|
|
1863
|
+
*/
|
|
1864
|
+
function Dock({ lm, panels, open }) {
|
|
1865
|
+
const shown = DOCK.filter((p) => panels.includes(p));
|
|
1866
|
+
const [tab, setTab] = useState(null);
|
|
1867
|
+
if (!shown.length) return null;
|
|
1868
|
+
const active = tab && shown.includes(tab) ? tab : shown[0];
|
|
1869
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1870
|
+
className: "lm-dock",
|
|
1871
|
+
children: [/* @__PURE__ */ jsx("fieldset", {
|
|
1872
|
+
className: "lm-tabs",
|
|
1873
|
+
"aria-label": "Panels",
|
|
1874
|
+
children: shown.map((p) => /* @__PURE__ */ jsx("button", {
|
|
1875
|
+
type: "button",
|
|
1876
|
+
"aria-pressed": p === active,
|
|
1877
|
+
onClick: () => setTab(p),
|
|
1878
|
+
children: NAMES[p]
|
|
1879
|
+
}, p))
|
|
1880
|
+
}), shown.map((p) => /* @__PURE__ */ jsx(Card, {
|
|
1881
|
+
lm,
|
|
1882
|
+
panel: p,
|
|
1883
|
+
open,
|
|
1884
|
+
active: p === active
|
|
1885
|
+
}, p))]
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
function Card({ lm, panel, open, active }) {
|
|
1889
|
+
const box = useRef(null);
|
|
1890
|
+
const more = useRef(null);
|
|
1891
|
+
useClip(box, more);
|
|
1892
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1893
|
+
className: "lm-mini",
|
|
1894
|
+
"data-mini": panel,
|
|
1895
|
+
"data-active": active || void 0,
|
|
1896
|
+
ref: box,
|
|
1897
|
+
children: [panel === "controls" ? /* @__PURE__ */ jsx(Controls, { lm }) : panel === "compare" ? /* @__PURE__ */ jsx(Compare, { lm }) : /* @__PURE__ */ jsx("div", {
|
|
1898
|
+
className: "lm-card",
|
|
1899
|
+
children: panel === "live" ? /* @__PURE__ */ jsx(Meters, { lm }) : panel === "limits" ? /* @__PURE__ */ jsx(MiniLimits, { lm }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Headroom" }), /* @__PURE__ */ jsx(Sparkline, { lm })] })
|
|
1900
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
1901
|
+
type: "button",
|
|
1902
|
+
className: "lm-more",
|
|
1903
|
+
ref: more,
|
|
1904
|
+
"aria-label": `${NAMES[panel]}, all of it`,
|
|
1905
|
+
onClick: (e) => open(panel, e.currentTarget),
|
|
1906
|
+
children: "›"
|
|
1907
|
+
})]
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
/** The rows a card leaves out whole when they do not fit. */
|
|
1911
|
+
const ROWS = ".lm-meter, .lm-mini-lim, .lm-controls > *, .lm-table tbody tr";
|
|
1912
|
+
/**
|
|
1913
|
+
* Hides the rows that cross the bottom of the card, and counts them on its button. Runs again when the card's size
|
|
1914
|
+
* or its rows change: the meters come and go with the load, and the order of the limits with it.
|
|
1915
|
+
*/
|
|
1916
|
+
function useClip(box, more) {
|
|
1917
|
+
useEffect(() => {
|
|
1918
|
+
const card = box.current?.querySelector(".lm-card");
|
|
1919
|
+
if (!card) return;
|
|
1920
|
+
const clip = () => {
|
|
1921
|
+
const r = card.getBoundingClientRect();
|
|
1922
|
+
const bottom = r.bottom - Number.parseFloat(getComputedStyle(card).paddingBottom || "0");
|
|
1923
|
+
let n = 0;
|
|
1924
|
+
for (const row of card.querySelectorAll(ROWS)) {
|
|
1925
|
+
const out = r.height > 0 && row.getBoundingClientRect().bottom > bottom + .5;
|
|
1926
|
+
row.toggleAttribute("data-clip", out);
|
|
1927
|
+
if (out && !row.matches("h3")) n++;
|
|
1928
|
+
}
|
|
1929
|
+
if (more.current) more.current.dataset.more = n ? `+${n}` : "";
|
|
1930
|
+
};
|
|
1931
|
+
const ro = new ResizeObserver(clip);
|
|
1932
|
+
ro.observe(card);
|
|
1933
|
+
const mo = new MutationObserver(clip);
|
|
1934
|
+
mo.observe(card, {
|
|
1935
|
+
childList: true,
|
|
1936
|
+
subtree: true
|
|
1937
|
+
});
|
|
1938
|
+
clip();
|
|
1939
|
+
return () => {
|
|
1940
|
+
ro.disconnect();
|
|
1941
|
+
mo.disconnect();
|
|
1942
|
+
};
|
|
1943
|
+
}, [box, more]);
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* The limits in their order, a line each: the name and how sure its capacity is, the bar, the utilization, where it
|
|
1947
|
+
* is full. The first is the first limit: the verdict line names it.
|
|
1948
|
+
*/
|
|
1949
|
+
function MiniLimits({ lm }) {
|
|
1950
|
+
const { ev, model } = lm;
|
|
1951
|
+
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
1952
|
+
const at = (u) => `${u / top * 100}%`;
|
|
1953
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Where it runs out" }), /* @__PURE__ */ jsx("div", {
|
|
1954
|
+
className: "lm-mini-limits",
|
|
1955
|
+
children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
|
|
1956
|
+
className: "lm-mini-lim",
|
|
1957
|
+
"data-component": c.id,
|
|
1958
|
+
children: [
|
|
1959
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1960
|
+
className: "lm-name",
|
|
1961
|
+
title: c.name,
|
|
1962
|
+
children: [c.name, c.capacity?.provenance === "estimated" ? /* @__PURE__ */ jsx("span", {
|
|
1963
|
+
className: "lm-tag",
|
|
1964
|
+
"data-kind": "estimated",
|
|
1965
|
+
children: "est"
|
|
1966
|
+
}) : !!c.capacity?.within && /* @__PURE__ */ jsx("span", {
|
|
1967
|
+
className: "lm-tag",
|
|
1968
|
+
"data-kind": "range",
|
|
1969
|
+
children: "±"
|
|
1970
|
+
})]
|
|
1971
|
+
}),
|
|
1972
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1973
|
+
className: "lm-track",
|
|
1974
|
+
role: "img",
|
|
1975
|
+
"aria-label": `${c.name} at ${c.util == null ? "off" : pct(c.util)}`,
|
|
1976
|
+
children: [
|
|
1977
|
+
/* @__PURE__ */ jsx("span", {
|
|
1978
|
+
className: "lm-fill",
|
|
1979
|
+
"data-state": c.state,
|
|
1980
|
+
style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
|
|
1981
|
+
}),
|
|
1982
|
+
/* @__PURE__ */ jsx("span", {
|
|
1983
|
+
className: "lm-tick",
|
|
1984
|
+
style: { left: at(model.thresholds.target) }
|
|
1985
|
+
}),
|
|
1986
|
+
/* @__PURE__ */ jsx("span", {
|
|
1987
|
+
className: "lm-tick",
|
|
1988
|
+
style: { left: at(model.thresholds.full) }
|
|
1989
|
+
})
|
|
1990
|
+
]
|
|
1991
|
+
}),
|
|
1992
|
+
/* @__PURE__ */ jsx("span", {
|
|
1993
|
+
className: "lm-val",
|
|
1994
|
+
children: c.util == null ? "—" : pct(c.util)
|
|
1995
|
+
}),
|
|
1996
|
+
/* @__PURE__ */ jsx("span", {
|
|
1997
|
+
className: "lm-val lm-sub",
|
|
1998
|
+
children: c.util == null ? "off" : c.full != null && !Number.isFinite(c.full) ? `full > ${fmt(model.searchMax)}×` : `full ${c.fullRange ? multiples(c.fullRange, model.searchMax, true) : multiple(c.full, model.searchMax)}`
|
|
1999
|
+
})
|
|
2000
|
+
]
|
|
2001
|
+
}, c.id))
|
|
2002
|
+
})] });
|
|
2003
|
+
}
|
|
2004
|
+
/** The headroom chart as a sparkline: each scenario's line, the target, the load; where the shown one crosses it. */
|
|
2005
|
+
function Sparkline({ lm }) {
|
|
2006
|
+
const { model, values } = lm;
|
|
2007
|
+
const h = useHeadroom(lm);
|
|
2008
|
+
const [box, { width: W, height: H }] = useSize(240);
|
|
2009
|
+
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
2010
|
+
const lx = (x) => W * Math.log(x / h.from) / Math.log(h.to / h.from);
|
|
2011
|
+
const ly = (u) => 8 + (H - 10) * (1 - Math.min(u, top * 1.2) / top);
|
|
2012
|
+
const path = (s) => {
|
|
2013
|
+
let d = "";
|
|
2014
|
+
let pen = false;
|
|
2015
|
+
for (const [x, u] of s) {
|
|
2016
|
+
if (u == null) {
|
|
2017
|
+
pen = false;
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
d += `${pen ? "L" : "M"}${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`;
|
|
2021
|
+
pen = true;
|
|
2022
|
+
}
|
|
2023
|
+
return d;
|
|
2024
|
+
};
|
|
2025
|
+
const line = h.lines.find((l) => l.selected) ?? h.lines[0];
|
|
2026
|
+
const target = pct(model.thresholds.target);
|
|
2027
|
+
const reaches = line ? `${line.targetRange ? multiples(line.targetRange, model.searchMax, true) : multiple(line.target, model.searchMax)}` : "";
|
|
2028
|
+
const when = line ? whenRange(model, line.targetRange) : "";
|
|
2029
|
+
const loadX = lx(Math.min(h.to, Math.max(h.from, values.load)));
|
|
2030
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
2031
|
+
className: "lm-spark",
|
|
2032
|
+
ref: box,
|
|
2033
|
+
children: H > 0 && /* @__PURE__ */ jsxs("svg", {
|
|
2034
|
+
width: W,
|
|
2035
|
+
height: H,
|
|
2036
|
+
"aria-hidden": "true",
|
|
2037
|
+
children: [
|
|
2038
|
+
/* @__PURE__ */ jsx("line", {
|
|
2039
|
+
className: "lm-spark-th",
|
|
2040
|
+
x1: 0,
|
|
2041
|
+
x2: W,
|
|
2042
|
+
y1: ly(model.thresholds.target),
|
|
2043
|
+
y2: ly(model.thresholds.target)
|
|
2044
|
+
}),
|
|
2045
|
+
h.lines.map((l) => /* @__PURE__ */ jsx("path", {
|
|
2046
|
+
d: path(l.envelope),
|
|
2047
|
+
fill: "none",
|
|
2048
|
+
stroke: scenarioColor(model, l.label),
|
|
2049
|
+
strokeWidth: l.selected ? 2 : 1.25
|
|
2050
|
+
}, l.label ?? "")),
|
|
2051
|
+
/* @__PURE__ */ jsx("line", {
|
|
2052
|
+
className: "lm-spark-load",
|
|
2053
|
+
x1: loadX,
|
|
2054
|
+
x2: loadX,
|
|
2055
|
+
y1: 0,
|
|
2056
|
+
y2: H
|
|
2057
|
+
})
|
|
2058
|
+
]
|
|
2059
|
+
})
|
|
2060
|
+
}), line && /* @__PURE__ */ jsxs("p", {
|
|
2061
|
+
className: "lm-spark-text",
|
|
2062
|
+
title: `${line.label ?? "It"} reaches the ${target} target at ${reaches}`,
|
|
2063
|
+
children: [
|
|
2064
|
+
line.label ?? "It",
|
|
2065
|
+
" reaches the ",
|
|
2066
|
+
target,
|
|
2067
|
+
" target at ",
|
|
2068
|
+
reaches,
|
|
2069
|
+
when && ` (${when})`,
|
|
2070
|
+
"."
|
|
2071
|
+
]
|
|
2072
|
+
})] });
|
|
2073
|
+
}
|
|
2074
|
+
// src/story.tsx
|
|
2075
|
+
/**
|
|
2076
|
+
* The model's story, a step at a time: the step's text, where it is, play, back and next. ← and → move through it
|
|
2077
|
+
* while the bar has the keyboard focus (the sliders keep their own arrows). The text keeps the room of the longest
|
|
2078
|
+
* step, so stepping through it never moves what is below.
|
|
2079
|
+
*/
|
|
2080
|
+
function Story({ lm }) {
|
|
2081
|
+
const bar = useRef(null);
|
|
2082
|
+
const { story } = lm.model;
|
|
2083
|
+
if (!story.length) return null;
|
|
2084
|
+
const i = lm.step;
|
|
2085
|
+
const last = story.length - 1;
|
|
2086
|
+
const go = (to) => {
|
|
2087
|
+
const next = Math.max(0, Math.min(last, to));
|
|
2088
|
+
if (next !== i) lm.setStep(next);
|
|
2089
|
+
};
|
|
2090
|
+
const keys = (e) => {
|
|
2091
|
+
if (e.key === "ArrowRight") go(i == null ? 0 : i + 1);
|
|
2092
|
+
else if (e.key === "ArrowLeft" && i != null) go(i - 1);
|
|
2093
|
+
else return;
|
|
2094
|
+
e.preventDefault();
|
|
2095
|
+
};
|
|
2096
|
+
const playing = lm.storyPlaying;
|
|
2097
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
2098
|
+
className: "lm-story",
|
|
2099
|
+
onKeyDown: keys,
|
|
2100
|
+
ref: bar,
|
|
2101
|
+
tabIndex: -1,
|
|
2102
|
+
"data-playing": playing || void 0,
|
|
2103
|
+
children: [
|
|
2104
|
+
/* @__PURE__ */ jsx("legend", { children: "Story" }),
|
|
2105
|
+
/* @__PURE__ */ jsx("span", {
|
|
2106
|
+
className: "lm-sr",
|
|
2107
|
+
"aria-live": "polite",
|
|
2108
|
+
children: i == null ? `A walk through this model in ${story.length} steps.` : `${i + 1} of ${story.length}. ${story[i].text}${lm.stepChanged ? " You changed the values since." : ""}`
|
|
2109
|
+
}),
|
|
2110
|
+
/* @__PURE__ */ jsxs("p", {
|
|
2111
|
+
"aria-hidden": "true",
|
|
2112
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
2113
|
+
"data-shown": i == null || void 0,
|
|
2114
|
+
children: [
|
|
2115
|
+
"A walk through this model in ",
|
|
2116
|
+
story.length,
|
|
2117
|
+
" steps."
|
|
2118
|
+
]
|
|
2119
|
+
}), story.map((st, k) => /* @__PURE__ */ jsxs("span", {
|
|
2120
|
+
"data-shown": k === i || void 0,
|
|
2121
|
+
children: [
|
|
2122
|
+
/* @__PURE__ */ jsxs("b", { children: [
|
|
2123
|
+
k + 1,
|
|
2124
|
+
" of ",
|
|
2125
|
+
story.length
|
|
2126
|
+
] }),
|
|
2127
|
+
" ",
|
|
2128
|
+
st.text,
|
|
2129
|
+
/* @__PURE__ */ jsx("em", {
|
|
2130
|
+
"data-shown": k === i && lm.stepChanged || void 0,
|
|
2131
|
+
children: " You changed the values since."
|
|
2132
|
+
})
|
|
2133
|
+
]
|
|
2134
|
+
}, k))]
|
|
2135
|
+
}),
|
|
2136
|
+
i != null && /* @__PURE__ */ jsx("span", {
|
|
2137
|
+
className: "lm-story-progress",
|
|
2138
|
+
"aria-hidden": "true",
|
|
2139
|
+
children: story.map((st, k) => /* @__PURE__ */ jsx("i", {
|
|
2140
|
+
"data-state": k < i ? "done" : k === i ? "now" : void 0,
|
|
2141
|
+
style: k === i ? { "--lm-step": `${st.seconds}s` } : void 0
|
|
2142
|
+
}, k === i ? `${k}-${playing}` : k))
|
|
2143
|
+
}),
|
|
2144
|
+
/* @__PURE__ */ jsxs("span", {
|
|
2145
|
+
className: "lm-story-nav",
|
|
2146
|
+
children: [
|
|
2147
|
+
/* @__PURE__ */ jsx("button", {
|
|
2148
|
+
type: "button",
|
|
2149
|
+
onClick: () => lm.setStoryPlaying(!playing),
|
|
2150
|
+
"aria-pressed": playing,
|
|
2151
|
+
children: playing ? "❚❚ Pause" : "▶ Play"
|
|
2152
|
+
}),
|
|
2153
|
+
i != null && /* @__PURE__ */ jsx("button", {
|
|
2154
|
+
type: "button",
|
|
2155
|
+
onClick: () => go(i - 1),
|
|
2156
|
+
"aria-disabled": i === 0,
|
|
2157
|
+
children: "Back"
|
|
2158
|
+
}),
|
|
2159
|
+
/* @__PURE__ */ jsx("button", {
|
|
2160
|
+
type: "button",
|
|
2161
|
+
onClick: () => go(i == null ? 0 : i + 1),
|
|
2162
|
+
"aria-disabled": i === last,
|
|
2163
|
+
children: i == null ? "Start" : "Next"
|
|
2164
|
+
}),
|
|
2165
|
+
i != null && lm.stepChanged && /* @__PURE__ */ jsx("button", {
|
|
2166
|
+
type: "button",
|
|
2167
|
+
onClick: () => {
|
|
2168
|
+
lm.setStep(i);
|
|
2169
|
+
bar.current?.focus();
|
|
2170
|
+
},
|
|
2171
|
+
children: "Show again"
|
|
2172
|
+
}),
|
|
2173
|
+
i != null && /* @__PURE__ */ jsx("button", {
|
|
2174
|
+
type: "button",
|
|
2175
|
+
onClick: () => lm.setStep(null),
|
|
2176
|
+
"aria-label": "Leave the story",
|
|
2177
|
+
children: "Done"
|
|
2178
|
+
})
|
|
2179
|
+
]
|
|
2180
|
+
})
|
|
2181
|
+
]
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
// src/styles.ts
|
|
2185
|
+
const LIGHT = `
|
|
2186
|
+
--lm-bg: #eef2f5; --lm-surface: #ffffff; --lm-fg: #17212b; --lm-muted: #5d6d7c; --lm-line: #c6d0da;
|
|
2187
|
+
--lm-accent: #0b6b8f; --lm-accent-soft: #d6e9f0; --lm-alt: #7a4f9a; --lm-alt-soft: #efe5f6;
|
|
2188
|
+
--lm-ok: #2a7f5a; --lm-warn: #b86e00; --lm-drop: #b7392e; --lm-lane: #e3e9ee;
|
|
2189
|
+
--lm-s1: #2a78d6; --lm-s2: #eb6834; --lm-s3: #6250d6; --lm-s4: #eda100; color-scheme: light;`;
|
|
2190
|
+
const DARK = `
|
|
2191
|
+
--lm-bg: #0d141b; --lm-surface: #151e27; --lm-fg: #e4ebf1; --lm-muted: #93a3b3; --lm-line: #2a3744;
|
|
2192
|
+
--lm-accent: #5fb7d6; --lm-accent-soft: #163442; --lm-alt: #c39be0; --lm-alt-soft: #2b2236;
|
|
2193
|
+
--lm-ok: #5fc08f; --lm-warn: #e2a24a; --lm-drop: #e26a5c; --lm-lane: #1b2631;
|
|
2194
|
+
--lm-s1: #3987e5; --lm-s2: #d95926; --lm-s3: #9085e9; --lm-s4: #c98500; color-scheme: dark;`;
|
|
2195
|
+
/**
|
|
2196
|
+
* Theme tokens and the layout of every piece. Scoped to `.lm`; override any `--lm-*` token to restyle. Two are for the
|
|
2197
|
+
* page around it: `--lm-pad` (the root's padding, 16px) and `--lm-root-bg` (its background, `--lm-bg`), for a card
|
|
2198
|
+
* that has its own, set on the root (`.card > .lm`) so they resolve there and reach no nested board; full screen
|
|
2199
|
+
* keeps both.
|
|
2200
|
+
*/
|
|
2201
|
+
const LOADMAP_CSS = `
|
|
2202
|
+
.lm { ${LIGHT}
|
|
2203
|
+
--lm-font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2204
|
+
--lm-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
2205
|
+
font: 14px/1.45 var(--lm-font); color: var(--lm-fg); background: var(--lm-root-bg, var(--lm-bg));
|
|
2206
|
+
display: grid; gap: 14px; padding: var(--lm-pad, 16px); min-width: 0; box-sizing: border-box; }
|
|
2207
|
+
@media (prefers-color-scheme: dark) { .lm:not([data-theme="light"]) { ${DARK} } }
|
|
2208
|
+
.lm[data-theme="dark"] { ${DARK} }
|
|
2209
|
+
.lm *, .lm *::before, .lm *::after { box-sizing: border-box; }
|
|
2210
|
+
.lm h2 { font-size: 1.3rem; font-weight: 600; margin: 0; text-wrap: balance; }
|
|
2211
|
+
.lm h3 { font: 600 .74rem var(--lm-font); text-transform: uppercase; letter-spacing: .08em; color: var(--lm-muted); margin: 0; }
|
|
2212
|
+
.lm button:focus-visible, .lm input:focus-visible, .lm select:focus-visible { outline: 2px solid var(--lm-accent); outline-offset: 2px; }
|
|
2213
|
+
.lm-problems { margin: 0; padding: 10px 12px; font: .8rem/1.5 var(--lm-mono); white-space: pre-wrap; overflow-x: auto; color: var(--lm-fg); background: var(--lm-surface); border: 1px solid var(--lm-line); border-left: 3px solid var(--lm-drop); border-radius: 6px; }
|
|
2214
|
+
.lm-note { margin: 0; font-size: .8rem; color: var(--lm-muted); }
|
|
2215
|
+
.lm-card { background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 8px; padding: 14px 16px; display: grid; gap: 12px; align-content: start; min-width: 0; }
|
|
2216
|
+
|
|
2217
|
+
.lm-wrap { display: grid; gap: 8px; min-width: 0; position: relative; }
|
|
2218
|
+
.lm-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
2219
|
+
.lm-btn { font: 500 .8rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
|
|
2220
|
+
.lm-board { position: relative; background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 8px; overflow: hidden; margin: 0 auto; width: 100%; }
|
|
2221
|
+
.lm-board svg { display: block; width: 100%; height: auto; font-family: var(--lm-font); }
|
|
2222
|
+
.lm-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
|
|
2223
|
+
.lm-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .78rem; color: var(--lm-muted); }
|
|
2224
|
+
.lm-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; margin-right: 5px; }
|
|
2225
|
+
|
|
2226
|
+
/* full screen (the browser's, or a fixed overlay): a column that never scrolls. The diagram as wide as the screen on
|
|
2227
|
+
top; under it the verdict in a line and the panels, compact, in a dock the screen sizes. The load changes what is
|
|
2228
|
+
in them, never their size, so it never moves the board. Focus: the diagram, the story, the verdict and the load */
|
|
2229
|
+
.lm-side, .lm-card > .lm-panel { display: contents; }
|
|
2230
|
+
.lm-panel { display: grid; gap: 14px; min-width: 0; }
|
|
2231
|
+
.lm[data-full] { height: 100vh; height: 100dvh; padding: 16px; background: var(--lm-bg); overflow: hidden; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; position: relative; }
|
|
2232
|
+
.lm[data-full="overlay"] { position: fixed; inset: 0; z-index: 2147483000; width: auto; max-width: none; max-height: none; margin: 0; border: 0; }
|
|
2233
|
+
.lm[data-full] > * { flex: none; }
|
|
2234
|
+
/* a page of its own keeps the rest outside full screen, as <Loadmap> does */
|
|
2235
|
+
.lm[data-full] > :not(.lm-head, h2, .lm-scenarios, .lm-story, .lm-wrap, .lm-line, .lm-dock, .lm-side) { display: none; }
|
|
2236
|
+
.lm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; min-width: 0; }
|
|
2237
|
+
.lm-head h2 { font-size: 1.1rem; }
|
|
2238
|
+
.lm[data-full] .lm-wrap { gap: 6px; }
|
|
2239
|
+
/* the board as large as fits (--lm-fit, from Diagram), left under the bar, so the legend starts where the board does */
|
|
2240
|
+
.lm[data-full] .lm-board { width: var(--lm-fit, 100%); margin: 0; align-self: start; justify-self: start; }
|
|
2241
|
+
.lm-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
|
|
2242
|
+
.lm-modes { display: inline-flex; margin: 0; padding: 0; min-width: 0; border: 1px solid var(--lm-line); border-radius: 6px; overflow: hidden; }
|
|
2243
|
+
.lm-modes button { font: 500 .8rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 0; padding: 6px 12px; cursor: pointer; }
|
|
2244
|
+
.lm-modes button[aria-pressed="true"] { background: var(--lm-fg); color: var(--lm-surface); }
|
|
2245
|
+
.lm[data-full] .lm-story { padding: 6px 12px; }
|
|
2246
|
+
.lm[data-full] [data-out] { display: none; }
|
|
2247
|
+
|
|
2248
|
+
.lm-line { display: flex; align-items: center; gap: 6px 14px; min-width: 0; padding: 6px 12px; border-left: 4px solid var(--lm-ok); background: var(--lm-accent-soft); border-radius: 0 6px 6px 0; }
|
|
2249
|
+
.lm-line[data-tier="warn"] { border-color: var(--lm-warn); }
|
|
2250
|
+
.lm-line[data-tier="over"] { border-color: var(--lm-drop); }
|
|
2251
|
+
.lm-headline { flex: 1 1 auto; min-width: 0; margin: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
2252
|
+
.lm-num { font: 600 .95em var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2253
|
+
.lm-link { font: 500 .8rem var(--lm-font); color: var(--lm-accent); background: none; border: 0; padding: 2px 4px; cursor: pointer; white-space: nowrap; }
|
|
2254
|
+
.lm-line .lm-range { flex: 0 1 380px; display: grid; grid-template-columns: auto minmax(100px, 1fr); align-items: center; gap: 10px; font-size: .84rem; }
|
|
2255
|
+
.lm-line output { font-family: var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2256
|
+
.lm-line input[type=range] { width: 100%; accent-color: var(--lm-accent); }
|
|
2257
|
+
|
|
2258
|
+
.lm-dock { display: flex; gap: 10px; min-width: 0; }
|
|
2259
|
+
.lm[data-full] > .lm-dock { flex: 1 1 0; min-height: clamp(200px, 26dvh, 340px); }
|
|
2260
|
+
.lm-tabs { display: none; margin: 0; padding: 0; border: 0; min-width: 0; }
|
|
2261
|
+
.lm-mini { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; display: grid; container-type: inline-size; }
|
|
2262
|
+
.lm-mini[data-mini="controls"] { flex-grow: 1.25; }
|
|
2263
|
+
.lm-mini[data-mini="limits"] { flex-grow: 1.45; }
|
|
2264
|
+
.lm-mini[data-mini="live"] { flex-grow: .8; }
|
|
2265
|
+
.lm-mini[data-mini="headroom"] { flex-grow: .9; }
|
|
2266
|
+
.lm-mini[data-mini="compare"] { flex-grow: 1.3; }
|
|
2267
|
+
.lm-mini > .lm-card { min-height: 0; overflow: hidden; padding: 10px 12px; gap: 6px; align-content: start; }
|
|
2268
|
+
.lm-mini [data-clip] { visibility: hidden; }
|
|
2269
|
+
.lm-more { position: absolute; top: 6px; right: 6px; font: 500 .8rem var(--lm-font); color: var(--lm-accent); background: var(--lm-surface); border: 0; border-radius: 4px; padding: 2px 6px; cursor: pointer; }
|
|
2270
|
+
.lm-more[data-more]:not([data-more=""])::before { content: attr(data-more) " "; }
|
|
2271
|
+
.lm-mini .lm-meters { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px; }
|
|
2272
|
+
.lm-mini .lm-meter { display: flex; align-items: baseline; gap: 8px; padding: 3px 8px; }
|
|
2273
|
+
.lm-mini .lm-meter b { flex: none; font-size: .9rem; }
|
|
2274
|
+
.lm-mini .lm-meter span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2275
|
+
/* one grid for every row, so the bars line up whatever the names */
|
|
2276
|
+
.lm-mini-limits { display: grid; grid-template-columns: minmax(0, max-content) minmax(48px, 1fr) auto auto; gap: 6px 10px; }
|
|
2277
|
+
.lm-mini-lim { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: center; font-size: .8rem; }
|
|
2278
|
+
.lm-mini-lim .lm-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
2279
|
+
.lm-mini-lim .lm-tag { margin-left: 5px; }
|
|
2280
|
+
.lm-mini-lim .lm-track { height: 9px; }
|
|
2281
|
+
.lm-mini-lim .lm-val { white-space: nowrap; }
|
|
2282
|
+
.lm-mini-lim .lm-sub { font: 400 .74rem var(--lm-mono); color: var(--lm-muted); }
|
|
2283
|
+
.lm-mini .lm-controls { gap: 6px; column-gap: 16px; }
|
|
2284
|
+
.lm-mini .lm-controls small, .lm-mini .lm-controls > h3:not(:first-child) { display: none; }
|
|
2285
|
+
.lm-mini .lm-controls label.lm-range { grid-template-columns: minmax(0, 1fr) minmax(90px, 1.2fr); align-items: center; gap: 10px; font-size: .8rem; }
|
|
2286
|
+
.lm-mini .lm-select { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: .8rem; }
|
|
2287
|
+
.lm-mini .lm-select select { width: auto; padding: 1px 6px; font-size: .78rem; }
|
|
2288
|
+
.lm-mini .lm-switch { font-size: .8rem; }
|
|
2289
|
+
.lm-mini .lm-switch input { margin-top: 2px; }
|
|
2290
|
+
.lm-mini .lm-presets { gap: 4px; }
|
|
2291
|
+
.lm-mini .lm-presets button { padding: 2px 8px; font-size: .72rem; }
|
|
2292
|
+
@container (min-width: 420px) {
|
|
2293
|
+
.lm-mini .lm-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
2294
|
+
.lm-mini .lm-controls > :is(h3, .lm-presets), .lm-mini .lm-controls > h3 + .lm-range { grid-column: 1 / -1; }
|
|
2295
|
+
}
|
|
2296
|
+
.lm-mini .lm-compare > :not(h3:first-child, .lm-table-wrap:nth-child(3)) { display: none; }
|
|
2297
|
+
.lm-mini .lm-table { font-size: .76rem; }
|
|
2298
|
+
.lm-mini .lm-table th, .lm-mini .lm-table td { padding: 3px 8px 3px 0; }
|
|
2299
|
+
.lm-mini .lm-table small { display: none; }
|
|
2300
|
+
.lm-mini .lm-table thead th { white-space: nowrap; font-size: .6rem; }
|
|
2301
|
+
.lm-mini > .lm-card:has(> .lm-spark) { grid-template-rows: auto minmax(0, 1fr) auto; align-content: stretch; }
|
|
2302
|
+
.lm-spark { position: relative; min-height: 0; }
|
|
2303
|
+
.lm-spark svg { position: absolute; inset: 0; display: block; overflow: hidden; }
|
|
2304
|
+
.lm-spark-th { stroke: var(--lm-muted); stroke-dasharray: 4 3; }
|
|
2305
|
+
.lm-spark-load { stroke: var(--lm-fg); opacity: .45; }
|
|
2306
|
+
.lm-spark-text { margin: 0; font-size: .76rem; color: var(--lm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
2307
|
+
|
|
2308
|
+
/* the drawer: the page's own panel, alone, over the right of the board */
|
|
2309
|
+
.lm[data-full] > .lm-drawer:not([data-drawer]) { display: none; }
|
|
2310
|
+
.lm[data-full] > .lm-drawer[data-drawer] { display: grid; gap: 14px; align-content: start; position: absolute; top: 16px; right: 16px; bottom: 16px; z-index: 4; width: min(640px, calc(100% - 32px)); overflow: auto; overscroll-behavior: contain; padding: 14px; background: var(--lm-bg); border: 1px solid var(--lm-line); border-radius: 10px; box-shadow: -8px 0 30px rgb(0 0 0 / .2); container-type: inline-size; }
|
|
2311
|
+
.lm-side[data-drawer] :is(.lm-panel, .lm-strip, .lm-charts, .lm-card):not([data-drawn]):not(.lm-panel *) { display: none; }
|
|
2312
|
+
.lm-side[data-drawer] .lm-strip { grid-template-columns: minmax(0, 1fr); }
|
|
2313
|
+
.lm-drawer-bar { display: flex; justify-content: flex-end; }
|
|
2314
|
+
|
|
2315
|
+
/* a page of its own: its .lm-side is a box under the board that scrolls on its own, the board as large as leaves it a
|
|
2316
|
+
third of the screen */
|
|
2317
|
+
.lm[data-full] > .lm-side:not(.lm-drawer) { display: grid; gap: 14px; align-content: start; flex: 1 1 0; min-height: 33dvh; overflow: auto; overscroll-behavior: contain; container-type: inline-size; }
|
|
2318
|
+
|
|
2319
|
+
/* focus: the board and what runs on it in the middle of the screen */
|
|
2320
|
+
.lm[data-mode="focus"] .lm-scenarios, .lm[data-mode="focus"] > .lm-side:not(.lm-drawer) { display: none; }
|
|
2321
|
+
.lm[data-mode="focus"] > .lm-wrap { margin-top: auto; }
|
|
2322
|
+
.lm[data-mode="focus"] > :is(.lm-story, .lm-line) { order: 1; }
|
|
2323
|
+
.lm[data-mode="focus"]::after { content: ""; order: 2; margin-top: auto; }
|
|
2324
|
+
.lm[data-mode="focus"] > .lm-story { border-left-width: 4px; padding: 10px 14px; }
|
|
2325
|
+
.lm[data-mode="focus"] > .lm-story p { font-size: 1.1rem; }
|
|
2326
|
+
|
|
2327
|
+
@media (max-width: 760px) {
|
|
2328
|
+
.lm[data-full] { padding: 10px; gap: 8px; }
|
|
2329
|
+
/* the page has the title, and the legend: here they would leave the diagram no room */
|
|
2330
|
+
.lm[data-full] > h2, .lm[data-full] :is(.lm-head h2, .lm-legend, .lm-story legend) { display: none; }
|
|
2331
|
+
/* the one exception: here the diagram runs top to bottom, and shrunk to the screen it is too small to read, so it
|
|
2332
|
+
pans in a box of its own with the bar on top. The page never scrolls */
|
|
2333
|
+
.lm[data-full] .lm-board { width: 100%; }
|
|
2334
|
+
.lm[data-full] > .lm-wrap { height: 40dvh; overflow: auto; row-gap: 0; overscroll-behavior: contain; }
|
|
2335
|
+
.lm[data-mode="focus"] > .lm-wrap { height: auto; flex: 1 1 0; min-height: 0; margin-top: 0; }
|
|
2336
|
+
.lm[data-full] .lm-bar { position: sticky; top: 0; z-index: 1; padding-bottom: 8px; background: var(--lm-bg); }
|
|
2337
|
+
.lm[data-full] .lm-line { flex-wrap: wrap; }
|
|
2338
|
+
.lm[data-full] > .lm-story { padding: 6px 10px; gap: 6px 10px; }
|
|
2339
|
+
.lm[data-full] > .lm-story p { font-size: .84rem; }
|
|
2340
|
+
.lm[data-full] .lm-story button { padding: 4px 10px; }
|
|
2341
|
+
.lm[data-full] .lm-headline { flex-basis: 100%; }
|
|
2342
|
+
.lm-dock { flex-direction: column; min-height: 0; gap: 6px; }
|
|
2343
|
+
.lm-tabs { display: flex; flex: none; gap: 2px; border-bottom: 1px solid var(--lm-line); overflow: hidden; }
|
|
2344
|
+
.lm-tabs button { font: 500 .78rem var(--lm-font); color: var(--lm-muted); background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 8px; cursor: pointer; white-space: nowrap; }
|
|
2345
|
+
.lm-tabs button[aria-pressed="true"] { color: var(--lm-fg); border-color: var(--lm-fg); }
|
|
2346
|
+
.lm-mini:not([data-active]) { display: none; }
|
|
2347
|
+
.lm[data-full] > .lm-side[data-drawer] { inset: 8px; width: auto; }
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
.lm-verdict { margin: 0; padding: 10px 14px; border-left: 4px solid var(--lm-ok); background: var(--lm-accent-soft); border-radius: 0 6px 6px 0; }
|
|
2351
|
+
.lm-verdict[data-tier="warn"] { border-color: var(--lm-warn); }
|
|
2352
|
+
.lm-verdict[data-tier="over"] { border-color: var(--lm-drop); }
|
|
2353
|
+
.lm-measure { margin: 6px 0 0; padding: 0 14px; font-size: .86rem; color: var(--lm-muted); }
|
|
2354
|
+
|
|
2355
|
+
.lm-strip { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 14px; align-items: start; }
|
|
2356
|
+
@container (max-width: 860px) { .lm-strip { grid-template-columns: minmax(0, 1fr); } }
|
|
2357
|
+
.lm { container-type: inline-size; }
|
|
2358
|
+
|
|
2359
|
+
.lm-meters { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
|
|
2360
|
+
.lm-meter { padding: 8px 10px; border-radius: 6px; background: var(--lm-bg); min-width: 0; }
|
|
2361
|
+
.lm-meter b { display: block; font: 500 1.15rem var(--lm-mono); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
2362
|
+
.lm-meter span { font-size: .74rem; color: var(--lm-muted); }
|
|
2363
|
+
.lm-meter[data-state="warn"] b { color: var(--lm-warn); } .lm-meter[data-state="over"] b { color: var(--lm-drop); }
|
|
2364
|
+
|
|
2365
|
+
.lm-limits { display: grid; gap: 10px; }
|
|
2366
|
+
.lm-lim, .lm-scale { display: grid; grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) 10rem; gap: 4px 14px; align-items: center; }
|
|
2367
|
+
@container (max-width: 640px) { .lm-lim, .lm-scale { grid-template-columns: minmax(0, 1fr); } .lm-scale > :first-child, .lm-scale > :last-child { display: none; } }
|
|
2368
|
+
.lm-lim b { display: block; font-weight: 600; font-size: .88rem; }
|
|
2369
|
+
.lm-lim .lm-sub { display: block; font-size: .74rem; color: var(--lm-muted); }
|
|
2370
|
+
.lm-tag { font: 600 .64rem var(--lm-font); text-transform: uppercase; letter-spacing: .06em; border-radius: 3px; padding: 1px 5px; margin-left: 6px; vertical-align: 1px; }
|
|
2371
|
+
.lm-tag[data-kind="first"] { color: var(--lm-surface); background: var(--lm-drop); }
|
|
2372
|
+
.lm-tag[data-kind="estimated"] { color: var(--lm-warn); border: 1px solid currentColor; }
|
|
2373
|
+
.lm-tag[data-kind="range"] { color: var(--lm-muted); border: 1px solid currentColor; }
|
|
2374
|
+
.lm-track { position: relative; height: 16px; background: var(--lm-bg); border-radius: 3px; overflow: hidden; }
|
|
2375
|
+
.lm-fill { position: absolute; inset: 0 auto 0 0; background: var(--lm-ok); transition: width .25s ease; }
|
|
2376
|
+
.lm-fill[data-state="warn"] { background: var(--lm-warn); } .lm-fill[data-state="over"] { background: var(--lm-drop); }
|
|
2377
|
+
.lm-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--lm-fg); opacity: .55; }
|
|
2378
|
+
.lm-val { font: 500 .8rem var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2379
|
+
.lm-val small { display: block; font: 400 .72rem var(--lm-font); color: var(--lm-muted); }
|
|
2380
|
+
.lm-scale { font: 400 .7rem var(--lm-mono); color: var(--lm-muted); }
|
|
2381
|
+
.lm-scale div { position: relative; height: 12px; }
|
|
2382
|
+
.lm-scale div span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
|
|
2383
|
+
|
|
2384
|
+
.lm-controls label.lm-range { display: grid; gap: 4px; font-size: .84rem; }
|
|
2385
|
+
.lm-controls label.lm-range > span { display: flex; justify-content: space-between; gap: 8px; }
|
|
2386
|
+
.lm-controls output { font-family: var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2387
|
+
.lm-controls input[type=range] { width: 100%; accent-color: var(--lm-accent); }
|
|
2388
|
+
.lm-presets { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
2389
|
+
.lm-presets button { font: 500 .76rem var(--lm-font); background: var(--lm-accent-soft); color: var(--lm-fg); border: 1px solid transparent; border-radius: 5px; padding: 5px 10px; cursor: pointer; }
|
|
2390
|
+
.lm-presets button[aria-pressed="true"] { border-color: var(--lm-accent); }
|
|
2391
|
+
.lm-switch { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 8px; align-items: start; font-size: .84rem; cursor: pointer; }
|
|
2392
|
+
.lm-switch input { margin: 3px 0 0; accent-color: var(--lm-accent); }
|
|
2393
|
+
.lm-switch small, .lm-select small { grid-column: 2; color: var(--lm-muted); font-size: .74rem; line-height: 1.3; }
|
|
2394
|
+
.lm-select { display: grid; gap: 4px; font-size: .84rem; }
|
|
2395
|
+
.lm-select select { width: 100%; min-width: 0; font: 400 .84rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 5px; padding: 5px 8px; }
|
|
2396
|
+
.lm-off { opacity: .45; cursor: default; }
|
|
2397
|
+
|
|
2398
|
+
.lm-facts { margin: 0; padding-left: 1.1em; font-size: .88rem; columns: 2; column-gap: 28px; }
|
|
2399
|
+
@container (max-width: 860px) { .lm-facts { columns: 1; } }
|
|
2400
|
+
.lm-facts li { margin-bottom: 8px; break-inside: avoid; }
|
|
2401
|
+
.lm-prov { font: 600 .66rem var(--lm-font); text-transform: uppercase; letter-spacing: .06em; }
|
|
2402
|
+
.lm-prov[data-kind="measured"] { color: var(--lm-ok); } .lm-prov[data-kind="estimated"] { color: var(--lm-warn); }
|
|
2403
|
+
.lm-prov[data-kind="configured"] { color: var(--lm-accent); }
|
|
2404
|
+
|
|
2405
|
+
/* scenario identity colours (s1–s4) are checked for colour-blind separation on both surfaces; text never wears them */
|
|
2406
|
+
.lm-scenarios { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
|
|
2407
|
+
.lm-scenarios legend { float: left; font: 600 .74rem var(--lm-font); text-transform: uppercase; letter-spacing: .08em; color: var(--lm-muted); margin-right: 6px; padding: 0; }
|
|
2408
|
+
.lm-scenarios button { font: 500 .84rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
|
|
2409
|
+
.lm-scenarios button[aria-pressed="true"] { border-color: var(--lm-fg); box-shadow: inset 0 0 0 1px var(--lm-fg); }
|
|
2410
|
+
.lm-scenarios i, .lm-table i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; margin-right: 6px; }
|
|
2411
|
+
.lm-story { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; min-width: 0; padding: 8px 12px; border: 1px solid var(--lm-line); border-left: 3px solid var(--lm-accent); border-radius: 6px; background: var(--lm-surface); }
|
|
2412
|
+
.lm-story legend { float: left; font: 600 .74rem var(--lm-font); text-transform: uppercase; letter-spacing: .08em; color: var(--lm-muted); padding: 0; }
|
|
2413
|
+
.lm-story p { flex: 1 1 240px; display: grid; margin: 0; font: 400 .9rem/1.4 var(--lm-font); color: var(--lm-fg); }
|
|
2414
|
+
.lm-story p > span { grid-area: 1 / 1; }
|
|
2415
|
+
.lm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
2416
|
+
.lm-story p > span:not([data-shown]), .lm-story em:not([data-shown]) { visibility: hidden; }
|
|
2417
|
+
.lm-story-progress { display: flex; align-items: center; gap: 4px; }
|
|
2418
|
+
.lm-story-progress i { position: relative; width: 28px; height: 4px; border-radius: 2px; background: var(--lm-line); overflow: hidden; }
|
|
2419
|
+
.lm-story-progress i[data-state="done"], .lm-story:not([data-playing]) .lm-story-progress i[data-state="now"] { background: var(--lm-accent); }
|
|
2420
|
+
.lm-story[data-playing] .lm-story-progress i[data-state="now"]::before { content: ""; position: absolute; inset: 0; background: var(--lm-accent); transform-origin: left; animation: lm-step var(--lm-step) linear both; }
|
|
2421
|
+
@keyframes lm-step { from { transform: scaleX(0); } to { transform: scaleX(1); } }
|
|
2422
|
+
.lm-story b { font-weight: 600; color: var(--lm-muted); margin-right: 4px; white-space: nowrap; }
|
|
2423
|
+
.lm-story-nav { display: flex; gap: 6px; }
|
|
2424
|
+
.lm-story em { color: var(--lm-muted); }
|
|
2425
|
+
.lm-story button { font: 500 .84rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
|
|
2426
|
+
.lm-story button[aria-disabled="true"] { opacity: .45; cursor: default; }
|
|
2427
|
+
.lm-own { font-size: .78rem; color: var(--lm-muted); }
|
|
2428
|
+
.lm-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: 3px; margin-right: 6px; }
|
|
2429
|
+
|
|
2430
|
+
.lm-compare-text { margin: 0; }
|
|
2431
|
+
.lm-table-wrap { overflow-x: auto; }
|
|
2432
|
+
.lm-table { border-collapse: collapse; width: 100%; font-size: .84rem; }
|
|
2433
|
+
.lm-table th, .lm-table td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--lm-line); vertical-align: top; }
|
|
2434
|
+
.lm-table thead th { font: 600 .7rem var(--lm-font); text-transform: uppercase; letter-spacing: .06em; color: var(--lm-muted); }
|
|
2435
|
+
.lm-table tbody th { font-weight: 600; white-space: nowrap; }
|
|
2436
|
+
.lm-table td { font-family: var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2437
|
+
.lm-table td.lm-text { font-family: var(--lm-font); }
|
|
2438
|
+
.lm-table td small { display: block; font: 400 .72rem var(--lm-font); color: var(--lm-muted); }
|
|
2439
|
+
.lm-table tr[aria-current] th { text-decoration: underline; text-underline-offset: 3px; }
|
|
2440
|
+
|
|
2441
|
+
.lm-chart { position: relative; min-width: 0; }
|
|
2442
|
+
.lm-chart svg { display: block; overflow: visible; }
|
|
2443
|
+
.lm-chart:focus-visible { outline: 2px solid var(--lm-accent); outline-offset: 2px; }
|
|
2444
|
+
.lm-axis, .lm-axis text { font: 400 11px var(--lm-mono); fill: var(--lm-muted); }
|
|
2445
|
+
.lm-mark { font: 600 11px var(--lm-mono); fill: var(--lm-fg); }
|
|
2446
|
+
.lm-tip { position: absolute; z-index: 2; display: grid; gap: 2px; width: max-content; max-width: min(17rem, calc(100% - 8px)); overflow-wrap: anywhere; padding: 8px 10px; font-size: .78rem; background: var(--lm-surface); color: var(--lm-fg); border: 1px solid var(--lm-line); border-radius: 6px; box-shadow: 0 4px 14px rgb(0 0 0 / .14); pointer-events: none; }
|
|
2447
|
+
.lm-tip strong { font: 600 .82rem var(--lm-mono); font-variant-numeric: tabular-nums; }
|
|
2448
|
+
.lm-tip .lm-sub { color: var(--lm-muted); }
|
|
2449
|
+
.lm-nowrap { white-space: nowrap; }
|
|
2450
|
+
.lm-node { cursor: pointer; outline: none; }
|
|
2451
|
+
.lm-node:focus-visible > :first-child { stroke-width: 3; }
|
|
2452
|
+
|
|
2453
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2454
|
+
.lm-fill { transition: none; }
|
|
2455
|
+
.lm-story[data-playing] .lm-story-progress i[data-state="now"]::before { animation: none; transform: none; }
|
|
2456
|
+
}
|
|
2457
|
+
`;
|
|
2458
|
+
/** Adds the stylesheet once per document. */
|
|
2459
|
+
function injectStyles(doc = document) {
|
|
2460
|
+
if (doc.getElementById("loadmap-css")) return;
|
|
2461
|
+
const el = doc.createElement("style");
|
|
2462
|
+
el.id = "loadmap-css";
|
|
2463
|
+
el.textContent = LOADMAP_CSS;
|
|
2464
|
+
doc.head.appendChild(el);
|
|
2465
|
+
}
|
|
2466
|
+
// src/engine.ts
|
|
2467
|
+
const TOKENS = [
|
|
2468
|
+
"accent",
|
|
2469
|
+
"alt",
|
|
2470
|
+
"ok",
|
|
2471
|
+
"warn",
|
|
2472
|
+
"drop",
|
|
2473
|
+
"muted",
|
|
2474
|
+
"fg",
|
|
2475
|
+
"surface",
|
|
2476
|
+
"line"
|
|
2477
|
+
];
|
|
2478
|
+
/** The stroke of a hollow dot, in scene units. */
|
|
2479
|
+
const RING = 1.4;
|
|
2480
|
+
/**
|
|
2481
|
+
* Everything that moves, without React: the sim, the dots on the canvas, the worker fills in the SVG, and the move from
|
|
2482
|
+
* one structure to the next. React renders the structure once per scene, and once per frame while it moves; the engine
|
|
2483
|
+
* updates the moving parts every frame, and export drives it frame by frame instead of the animation loop.
|
|
2484
|
+
*/
|
|
2485
|
+
var Engine = class {
|
|
2486
|
+
model;
|
|
2487
|
+
view;
|
|
2488
|
+
sim;
|
|
2489
|
+
ev;
|
|
2490
|
+
scene = null;
|
|
2491
|
+
/** What the diagram draws now: the scene, or a frame of the move to it. */
|
|
2492
|
+
frame = null;
|
|
2493
|
+
/** Counts the frames: export waits until the diagram drew this one. */
|
|
2494
|
+
frameId = 0;
|
|
2495
|
+
drawnFrame = -1;
|
|
2496
|
+
/** Seconds a new structure takes to move in; 0 cuts. */
|
|
2497
|
+
transition = .8;
|
|
2498
|
+
/** The structure key the current values want; `scene.key` catches up once the layout is done. */
|
|
2499
|
+
wantKey = "";
|
|
2500
|
+
/** The values React last drew labels and colours for; a frame is complete once they match `ev.values`. */
|
|
2501
|
+
drawnValues = "";
|
|
2502
|
+
/** The component a story step points at, and the one the diagram last outlined: export waits for them to match. */
|
|
2503
|
+
wantFocus = null;
|
|
2504
|
+
/** The story step shown, set as soon as one is chosen: a recorder holding an old handle still reads it. */
|
|
2505
|
+
storyStep = null;
|
|
2506
|
+
drawnFocus = null;
|
|
2507
|
+
paused = false;
|
|
2508
|
+
colors = {};
|
|
2509
|
+
svg = null;
|
|
2510
|
+
canvas = null;
|
|
2511
|
+
#o;
|
|
2512
|
+
#slots = [];
|
|
2513
|
+
#paths = /* @__PURE__ */ new Map();
|
|
2514
|
+
#move = null;
|
|
2515
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
2516
|
+
/** The last steps came while paused: export drives a paused engine, a page that only paused it does not. */
|
|
2517
|
+
#driven = false;
|
|
2518
|
+
/** While the structure moves, each leg's path in this frame, shared by the dots on it. */
|
|
2519
|
+
#legs = {
|
|
2520
|
+
frame: -1,
|
|
2521
|
+
paths: /* @__PURE__ */ new Map()
|
|
2522
|
+
};
|
|
2523
|
+
constructor(model, view, ev, o = {}) {
|
|
2524
|
+
this.model = model;
|
|
2525
|
+
this.view = view;
|
|
2526
|
+
this.ev = ev;
|
|
2527
|
+
this.#o = o;
|
|
2528
|
+
this.sim = createSim(model, ev, o);
|
|
2529
|
+
}
|
|
2530
|
+
setEvaluation(ev) {
|
|
2531
|
+
if (ev === this.ev) return;
|
|
2532
|
+
const same = JSON.stringify(ev.values) === JSON.stringify(this.ev.values);
|
|
2533
|
+
this.ev = ev;
|
|
2534
|
+
if (!same) this.sim.update(ev);
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Takes a new scene. A new structure moves in from what is drawn now, unless `cut`, the diagram turned (a new
|
|
2538
|
+
* direction is a new screen size, not a new design), or it is paused with nothing stepping it; the first scene just
|
|
2539
|
+
* shows.
|
|
2540
|
+
*/
|
|
2541
|
+
setScene(scene, o = {}) {
|
|
2542
|
+
if (scene === this.scene) return;
|
|
2543
|
+
const from = this.frame;
|
|
2544
|
+
const seconds = this.transition;
|
|
2545
|
+
this.scene = scene;
|
|
2546
|
+
this.#paths.clear();
|
|
2547
|
+
const move = from && !o.cut && seconds > 0 && Number.isFinite(seconds) && (!this.paused || this.#driven) && from.direction === scene.direction && from.key !== scene.key;
|
|
2548
|
+
this.#move = move ? {
|
|
2549
|
+
at: morph(from, scene),
|
|
2550
|
+
t: 0,
|
|
2551
|
+
seconds
|
|
2552
|
+
} : null;
|
|
2553
|
+
this.#show(move ? this.#move.at(0) : scene);
|
|
2554
|
+
}
|
|
2555
|
+
/** Calls `f` whenever the frame changes; returns a function that stops it. */
|
|
2556
|
+
subscribe = (f) => {
|
|
2557
|
+
this.#listeners.add(f);
|
|
2558
|
+
return () => this.#listeners.delete(f);
|
|
2559
|
+
};
|
|
2560
|
+
#show(frame) {
|
|
2561
|
+
this.frame = frame;
|
|
2562
|
+
this.frameId++;
|
|
2563
|
+
for (const f of this.#listeners) f();
|
|
2564
|
+
}
|
|
2565
|
+
/** Starts the sim over from empty queues, with this seed (default: the original one), and ends a move. */
|
|
2566
|
+
reset(seed) {
|
|
2567
|
+
this.sim = createSim(this.model, this.ev, {
|
|
2568
|
+
...this.#o,
|
|
2569
|
+
seed: seed ?? this.#o.seed
|
|
2570
|
+
});
|
|
2571
|
+
this.#paths.clear();
|
|
2572
|
+
if (this.#move && this.scene) {
|
|
2573
|
+
this.#move = null;
|
|
2574
|
+
this.#show(this.scene);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
bind(svg, canvas) {
|
|
2578
|
+
const fresh = canvas !== this.canvas;
|
|
2579
|
+
this.svg = svg;
|
|
2580
|
+
this.canvas = canvas;
|
|
2581
|
+
this.#slots = [];
|
|
2582
|
+
if (!svg) return;
|
|
2583
|
+
for (const el of svg.querySelectorAll("rect[data-slot]")) this.#slots.push({
|
|
2584
|
+
el,
|
|
2585
|
+
stage: el.dataset.stage,
|
|
2586
|
+
index: Number(el.dataset.slot),
|
|
2587
|
+
y: Number(el.dataset.y),
|
|
2588
|
+
s: Number(el.dataset.s)
|
|
2589
|
+
});
|
|
2590
|
+
if (fresh) this.resize();
|
|
2591
|
+
this.drawFills();
|
|
2592
|
+
}
|
|
2593
|
+
/** Reads the theme tokens from the element that carries them. Call again when the theme changes. */
|
|
2594
|
+
readColors(root) {
|
|
2595
|
+
const cs = getComputedStyle(root);
|
|
2596
|
+
for (const t of TOKENS) this.colors[t] = cs.getPropertyValue(`--lm-${t}`).trim();
|
|
2597
|
+
}
|
|
2598
|
+
flowColor(flow) {
|
|
2599
|
+
const c = this.view.def.flows[flow]?.color ?? "accent";
|
|
2600
|
+
return this.colors[c] || c;
|
|
2601
|
+
}
|
|
2602
|
+
outcomeColor(outcome) {
|
|
2603
|
+
if (outcome === "dropped" || outcome === "rejected") return this.colors.drop || "#b7392e";
|
|
2604
|
+
if (outcome === "superseded" || outcome === "unread") return this.colors.muted || "#5d6d7c";
|
|
2605
|
+
return this.colors.ok || "#2a7f5a";
|
|
2606
|
+
}
|
|
2607
|
+
resize() {
|
|
2608
|
+
const c = this.canvas;
|
|
2609
|
+
if (!c || !this.scene) return;
|
|
2610
|
+
const r = c.getBoundingClientRect();
|
|
2611
|
+
if (!r.width) return;
|
|
2612
|
+
const dpr = Math.min(2, globalThis.devicePixelRatio || 1);
|
|
2613
|
+
const w = Math.round(r.width * dpr);
|
|
2614
|
+
const h = Math.round(r.height * dpr);
|
|
2615
|
+
if (c.width === w && c.height === h) return;
|
|
2616
|
+
c.width = w;
|
|
2617
|
+
c.height = h;
|
|
2618
|
+
this.draw();
|
|
2619
|
+
}
|
|
2620
|
+
/** Advances the sim, and the move to a new structure, by `dtReal` seconds. */
|
|
2621
|
+
step(dtReal, o = {}) {
|
|
2622
|
+
this.#driven = this.paused;
|
|
2623
|
+
this.sim.step(dtReal, o);
|
|
2624
|
+
const m = this.#move;
|
|
2625
|
+
if (!m || dtReal <= 0) return;
|
|
2626
|
+
m.t += dtReal / m.seconds;
|
|
2627
|
+
if (m.t >= 1) this.#move = null;
|
|
2628
|
+
this.#show(m.at(m.t));
|
|
2629
|
+
}
|
|
2630
|
+
/** Draws the dots on the overlay canvas and the worker fills in the SVG. */
|
|
2631
|
+
draw(o = {}) {
|
|
2632
|
+
this.drawFills();
|
|
2633
|
+
const c = this.canvas;
|
|
2634
|
+
const ctx = c?.getContext("2d");
|
|
2635
|
+
if (!c || !ctx || !this.frame) return;
|
|
2636
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
2637
|
+
ctx.clearRect(0, 0, c.width, c.height);
|
|
2638
|
+
if (o.particles === false) return;
|
|
2639
|
+
this.paintParticles(ctx, c.width / this.frame.width);
|
|
2640
|
+
}
|
|
2641
|
+
drawFills() {
|
|
2642
|
+
for (const sl of this.#slots) {
|
|
2643
|
+
const b = this.sim.slotBusy(sl.stage, sl.index);
|
|
2644
|
+
const h = b < .02 ? 0 : (sl.s - 2) * b;
|
|
2645
|
+
sl.el.setAttribute("y", (sl.y + sl.s - 1 - h).toFixed(2));
|
|
2646
|
+
sl.el.setAttribute("height", h.toFixed(2));
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
/** Every dot as it is drawn now, in scene units: for the canvas, and for an SVG export. */
|
|
2650
|
+
dots() {
|
|
2651
|
+
const scene = this.frame;
|
|
2652
|
+
if (!scene) return [];
|
|
2653
|
+
const out = [];
|
|
2654
|
+
const live = /* @__PURE__ */ new Set();
|
|
2655
|
+
for (const d of this.sim.particles) {
|
|
2656
|
+
live.add(d.id);
|
|
2657
|
+
const [x, y] = this.#position(scene, d);
|
|
2658
|
+
const inCell = d.to.cell != null && d.phase !== "move";
|
|
2659
|
+
const done = d.outcome === "delivered" || d.outcome === "answered";
|
|
2660
|
+
out.push({
|
|
2661
|
+
x,
|
|
2662
|
+
y: y - (d.phase === "fade" && !done ? d.t / d.dur * 8 : 0),
|
|
2663
|
+
r: inCell ? 3 : 3.4,
|
|
2664
|
+
color: d.phase === "fade" ? this.outcomeColor(d.outcome) : this.flowColor(d.flow),
|
|
2665
|
+
alpha: d.phase === "fade" ? Math.max(0, 1 - d.t / d.dur) : 1,
|
|
2666
|
+
...d.attempt ? { ring: RING } : {}
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
for (const id of this.#paths.keys()) if (!live.has(id)) this.#paths.delete(id);
|
|
2670
|
+
return out;
|
|
2671
|
+
}
|
|
2672
|
+
/** Paints the dots onto any 2D context, scene units × `scale`: the overlay, or an export frame. */
|
|
2673
|
+
paintParticles(ctx, scale) {
|
|
2674
|
+
if (!this.frame) return;
|
|
2675
|
+
ctx.save();
|
|
2676
|
+
ctx.transform(scale, 0, 0, scale, 0, 0);
|
|
2677
|
+
for (const d of this.dots()) {
|
|
2678
|
+
ctx.globalAlpha = d.alpha;
|
|
2679
|
+
ctx.beginPath();
|
|
2680
|
+
if (d.ring) {
|
|
2681
|
+
ctx.strokeStyle = d.color;
|
|
2682
|
+
ctx.lineWidth = d.ring;
|
|
2683
|
+
ctx.arc(d.x, d.y, d.r - d.ring / 2, 0, Math.PI * 2);
|
|
2684
|
+
ctx.stroke();
|
|
2685
|
+
} else {
|
|
2686
|
+
ctx.fillStyle = d.color;
|
|
2687
|
+
ctx.arc(d.x, d.y, d.r, 0, Math.PI * 2);
|
|
2688
|
+
ctx.fill();
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
ctx.restore();
|
|
2692
|
+
}
|
|
2693
|
+
#position(scene, d) {
|
|
2694
|
+
if (d.phase !== "move") return anchor(scene, d.to, d.flow);
|
|
2695
|
+
const key = `${d.leg}|${d.from.stage}|${d.from.cell}|${d.to.stage}|${d.to.cell}`;
|
|
2696
|
+
if (this.#move) {
|
|
2697
|
+
const legs = this.#legs;
|
|
2698
|
+
if (legs.frame !== this.frameId) {
|
|
2699
|
+
legs.frame = this.frameId;
|
|
2700
|
+
legs.paths.clear();
|
|
2701
|
+
}
|
|
2702
|
+
const leg = `${d.flow}|${key}`;
|
|
2703
|
+
let points = legs.paths.get(leg);
|
|
2704
|
+
if (!points) {
|
|
2705
|
+
points = legPath(scene, d.from, d.to, d.flow);
|
|
2706
|
+
legs.paths.set(leg, points);
|
|
2707
|
+
}
|
|
2708
|
+
return pointAt(points, d.t / d.dur);
|
|
2709
|
+
}
|
|
2710
|
+
let p = this.#paths.get(d.id);
|
|
2711
|
+
if (!p || p.key !== key) {
|
|
2712
|
+
p = {
|
|
2713
|
+
key,
|
|
2714
|
+
points: legPath(scene, d.from, d.to, d.flow)
|
|
2715
|
+
};
|
|
2716
|
+
this.#paths.set(d.id, p);
|
|
2717
|
+
}
|
|
2718
|
+
return pointAt(p.points, d.t / d.dur);
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
// src/useLoadmap.ts
|
|
2722
|
+
/** The state behind a loadmap: values, the model's evaluation, the layout and the engine. */
|
|
2723
|
+
function useLoadmap(model, view, o = {}) {
|
|
2724
|
+
const init = () => ({
|
|
2725
|
+
...model.defaults(),
|
|
2726
|
+
...o.initial
|
|
2727
|
+
});
|
|
2728
|
+
const [state, setState] = useState(() => ({
|
|
2729
|
+
model,
|
|
2730
|
+
values: init()
|
|
2731
|
+
}));
|
|
2732
|
+
let values = state.values;
|
|
2733
|
+
if (state.model !== model) {
|
|
2734
|
+
values = init();
|
|
2735
|
+
setState({
|
|
2736
|
+
model,
|
|
2737
|
+
values
|
|
2738
|
+
});
|
|
2739
|
+
}
|
|
2740
|
+
const evaluated = useRef(null);
|
|
2741
|
+
const ev = useMemo(() => evaluated.current?.values === values ? evaluated.current.ev : model.evaluate(values), [model, values]);
|
|
2742
|
+
const engineRef = useRef(null);
|
|
2743
|
+
if (!engineRef.current || engineRef.current.model !== model || engineRef.current.view !== view) engineRef.current = new Engine(model, view, ev, o);
|
|
2744
|
+
const engine = engineRef.current;
|
|
2745
|
+
engine.transition = o.transition ?? .8;
|
|
2746
|
+
const [root, setRoot] = useState(null);
|
|
2747
|
+
const wide = o.direction ?? "RIGHT";
|
|
2748
|
+
const [direction, setDirection] = useState(wide);
|
|
2749
|
+
const [measure, setMeasure] = useState(null);
|
|
2750
|
+
const [laid, setLaid] = useState(null);
|
|
2751
|
+
const scene = laid?.view === view ? laid.scene : null;
|
|
2752
|
+
const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
2753
|
+
const narrowBelow = o.narrowBelow ?? 640;
|
|
2754
|
+
useEffect(() => engine.setEvaluation(ev), [engine, ev]);
|
|
2755
|
+
useEffect(() => {
|
|
2756
|
+
if (!root) return;
|
|
2757
|
+
setMeasure(() => canvasMeasure(getComputedStyle(root).fontFamily));
|
|
2758
|
+
const ro = new ResizeObserver(([e]) => {
|
|
2759
|
+
const w = e?.contentRect.width ?? root.clientWidth;
|
|
2760
|
+
setDirection(w > 0 && w < narrowBelow ? "DOWN" : wide);
|
|
2761
|
+
});
|
|
2762
|
+
ro.observe(root);
|
|
2763
|
+
return () => ro.disconnect();
|
|
2764
|
+
}, [
|
|
2765
|
+
root,
|
|
2766
|
+
narrowBelow,
|
|
2767
|
+
wide
|
|
2768
|
+
]);
|
|
2769
|
+
const key = useMemo(() => measure ? structureKey(view, ev, {
|
|
2770
|
+
direction,
|
|
2771
|
+
measure
|
|
2772
|
+
}) : "", [
|
|
2773
|
+
view,
|
|
2774
|
+
ev,
|
|
2775
|
+
direction,
|
|
2776
|
+
measure
|
|
2777
|
+
]);
|
|
2778
|
+
engine.wantKey = key;
|
|
2779
|
+
const elk = o.elk;
|
|
2780
|
+
useEffect(() => {
|
|
2781
|
+
if (!measure || !key) return;
|
|
2782
|
+
let live = true;
|
|
2783
|
+
layout(view, engine.ev, {
|
|
2784
|
+
direction,
|
|
2785
|
+
measure,
|
|
2786
|
+
elk: elk ?? pageElk()
|
|
2787
|
+
}).then((s) => {
|
|
2788
|
+
if (live) setLaid({
|
|
2789
|
+
view,
|
|
2790
|
+
scene: s
|
|
2791
|
+
});
|
|
2792
|
+
}, (err) => console.error("loadmap: layout failed", err));
|
|
2793
|
+
return () => {
|
|
2794
|
+
live = false;
|
|
2795
|
+
};
|
|
2796
|
+
}, [
|
|
2797
|
+
key,
|
|
2798
|
+
view,
|
|
2799
|
+
engine,
|
|
2800
|
+
direction,
|
|
2801
|
+
measure,
|
|
2802
|
+
elk
|
|
2803
|
+
]);
|
|
2804
|
+
const labels = useMemo(() => labelsAt(view, ev), [view, ev]);
|
|
2805
|
+
const valuesRef = useRef(values);
|
|
2806
|
+
valuesRef.current = values;
|
|
2807
|
+
const setValues = useCallback((v) => {
|
|
2808
|
+
const next = {
|
|
2809
|
+
...valuesRef.current,
|
|
2810
|
+
...v
|
|
2811
|
+
};
|
|
2812
|
+
valuesRef.current = next;
|
|
2813
|
+
const nextEv = model.evaluate(next);
|
|
2814
|
+
evaluated.current = {
|
|
2815
|
+
values: next,
|
|
2816
|
+
ev: nextEv
|
|
2817
|
+
};
|
|
2818
|
+
engine.setEvaluation(nextEv);
|
|
2819
|
+
setState({
|
|
2820
|
+
model,
|
|
2821
|
+
values: next
|
|
2822
|
+
});
|
|
2823
|
+
}, [engine, model]);
|
|
2824
|
+
const scenario = useMemo(() => model.scenarioOf(values), [model, values]);
|
|
2825
|
+
const setScenario = useCallback((label) => {
|
|
2826
|
+
const s = model.scenarios.find((x) => x.label === label);
|
|
2827
|
+
if (s) setValues(s.values);
|
|
2828
|
+
}, [model, setValues]);
|
|
2829
|
+
const [stepState, setStepState] = useState({
|
|
2830
|
+
model,
|
|
2831
|
+
i: null
|
|
2832
|
+
});
|
|
2833
|
+
const step = stepState.model === model && stepState.i != null && stepState.i < model.story.length ? stepState.i : null;
|
|
2834
|
+
const setStep = useCallback((i) => {
|
|
2835
|
+
const st = i == null ? void 0 : model.story[i];
|
|
2836
|
+
if (st) setValues(st.values);
|
|
2837
|
+
engine.wantFocus = st?.focus ?? null;
|
|
2838
|
+
engine.storyStep = st ? i : null;
|
|
2839
|
+
setStepState({
|
|
2840
|
+
model,
|
|
2841
|
+
i: st ? i : null
|
|
2842
|
+
});
|
|
2843
|
+
}, [
|
|
2844
|
+
model,
|
|
2845
|
+
setValues,
|
|
2846
|
+
engine
|
|
2847
|
+
]);
|
|
2848
|
+
const shown = step == null ? void 0 : model.story[step];
|
|
2849
|
+
const stepChanged = !!shown && Object.entries(shown.values).some(([k, v]) => values[k] !== v);
|
|
2850
|
+
const focus = shown && !stepChanged ? shown.focus ?? null : null;
|
|
2851
|
+
engine.wantFocus = focus;
|
|
2852
|
+
engine.storyStep = step;
|
|
2853
|
+
const [playing, setPlaying] = useState(false);
|
|
2854
|
+
if (playing && (step == null || stepChanged)) setPlaying(false);
|
|
2855
|
+
const storyPlaying = playing && step != null && !stepChanged;
|
|
2856
|
+
useEffect(() => {
|
|
2857
|
+
if (!storyPlaying || step == null) return;
|
|
2858
|
+
const last = model.story.length - 1;
|
|
2859
|
+
const t = setTimeout(() => step < last ? setStep(step + 1) : setPlaying(false), model.story[step].seconds * 1e3);
|
|
2860
|
+
return () => clearTimeout(t);
|
|
2861
|
+
}, [
|
|
2862
|
+
storyPlaying,
|
|
2863
|
+
step,
|
|
2864
|
+
model,
|
|
2865
|
+
setStep
|
|
2866
|
+
]);
|
|
2867
|
+
const setStoryPlaying = useCallback((on) => {
|
|
2868
|
+
if (on && (step == null || stepChanged || step === model.story.length - 1)) setStep(step == null || step === model.story.length - 1 ? 0 : step);
|
|
2869
|
+
setPlaying(on && model.story.length > 0);
|
|
2870
|
+
}, [
|
|
2871
|
+
step,
|
|
2872
|
+
stepChanged,
|
|
2873
|
+
model,
|
|
2874
|
+
setStep
|
|
2875
|
+
]);
|
|
2876
|
+
const [screen, setScreen] = useState(false);
|
|
2877
|
+
const [overlay, setOverlay] = useState(false);
|
|
2878
|
+
const fullScreen = screen || overlay;
|
|
2879
|
+
useEffect(() => {
|
|
2880
|
+
const f = () => setScreen(!!root && document.fullscreenElement === root);
|
|
2881
|
+
document.addEventListener("fullscreenchange", f);
|
|
2882
|
+
return () => document.removeEventListener("fullscreenchange", f);
|
|
2883
|
+
}, [root]);
|
|
2884
|
+
const start = o.fullScreenMode ?? "panels";
|
|
2885
|
+
const [modeState, setModeState] = useState({
|
|
2886
|
+
start,
|
|
2887
|
+
mode: start
|
|
2888
|
+
});
|
|
2889
|
+
const fullScreenMode = modeState.start === start ? modeState.mode : start;
|
|
2890
|
+
const setFullScreenMode = useCallback((mode) => setModeState({
|
|
2891
|
+
start,
|
|
2892
|
+
mode
|
|
2893
|
+
}), [start]);
|
|
2894
|
+
useEffect(() => {
|
|
2895
|
+
if (!root || !fullScreen) return;
|
|
2896
|
+
root.setAttribute("data-full", overlay ? "overlay" : "screen");
|
|
2897
|
+
const top = overlay && typeof root.showPopover === "function";
|
|
2898
|
+
if (top) {
|
|
2899
|
+
root.popover = "manual";
|
|
2900
|
+
root.showPopover();
|
|
2901
|
+
}
|
|
2902
|
+
return () => {
|
|
2903
|
+
root.removeAttribute("data-full");
|
|
2904
|
+
if (top) {
|
|
2905
|
+
root.hidePopover();
|
|
2906
|
+
root.removeAttribute("popover");
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
}, [
|
|
2910
|
+
root,
|
|
2911
|
+
fullScreen,
|
|
2912
|
+
overlay
|
|
2913
|
+
]);
|
|
2914
|
+
useEffect(() => {
|
|
2915
|
+
if (!root || !fullScreen) return;
|
|
2916
|
+
root.setAttribute("data-mode", fullScreenMode);
|
|
2917
|
+
return () => root.removeAttribute("data-mode");
|
|
2918
|
+
}, [
|
|
2919
|
+
root,
|
|
2920
|
+
fullScreen,
|
|
2921
|
+
fullScreenMode
|
|
2922
|
+
]);
|
|
2923
|
+
useEffect(() => {
|
|
2924
|
+
if (!overlay) return;
|
|
2925
|
+
const f = (e) => e.key === "Escape" && setOverlay(false);
|
|
2926
|
+
document.addEventListener("keydown", f);
|
|
2927
|
+
return () => document.removeEventListener("keydown", f);
|
|
2928
|
+
}, [overlay]);
|
|
2929
|
+
const toggleFullScreen = useCallback(() => {
|
|
2930
|
+
if (!root) return;
|
|
2931
|
+
if (overlay) setOverlay(false);
|
|
2932
|
+
else if (document.fullscreenElement) document.exitFullscreen().catch(() => {});
|
|
2933
|
+
else if (root.requestFullscreen) root.requestFullscreen().catch(() => setOverlay(true));
|
|
2934
|
+
else setOverlay(true);
|
|
2935
|
+
}, [root, overlay]);
|
|
2936
|
+
return {
|
|
2937
|
+
model,
|
|
2938
|
+
view,
|
|
2939
|
+
values,
|
|
2940
|
+
setValues,
|
|
2941
|
+
scenario,
|
|
2942
|
+
setScenario,
|
|
2943
|
+
step,
|
|
2944
|
+
stepChanged,
|
|
2945
|
+
setStep,
|
|
2946
|
+
focus,
|
|
2947
|
+
storyPlaying,
|
|
2948
|
+
setStoryPlaying,
|
|
2949
|
+
fullScreen,
|
|
2950
|
+
toggleFullScreen,
|
|
2951
|
+
fullScreenMode,
|
|
2952
|
+
setFullScreenMode,
|
|
2953
|
+
ev,
|
|
2954
|
+
scene,
|
|
2955
|
+
labels,
|
|
2956
|
+
direction,
|
|
2957
|
+
reducedMotion,
|
|
2958
|
+
engine,
|
|
2959
|
+
rootRef: setRoot,
|
|
2960
|
+
root
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
function useMediaQuery(q) {
|
|
2964
|
+
const [on, setOn] = useState(() => typeof matchMedia === "function" && matchMedia(q).matches);
|
|
2965
|
+
useEffect(() => {
|
|
2966
|
+
if (typeof matchMedia !== "function") return;
|
|
2967
|
+
const m = matchMedia(q);
|
|
2968
|
+
const f = () => setOn(m.matches);
|
|
2969
|
+
f();
|
|
2970
|
+
m.addEventListener("change", f);
|
|
2971
|
+
return () => m.removeEventListener("change", f);
|
|
2972
|
+
}, [q]);
|
|
2973
|
+
return on;
|
|
2974
|
+
}
|
|
2975
|
+
function canvasMeasure(fontFamily) {
|
|
2976
|
+
const ctx = document.createElement("canvas").getContext("2d");
|
|
2977
|
+
if (!ctx) return (t, size) => t.length * size * .6;
|
|
2978
|
+
return (text, size, weight = 400) => {
|
|
2979
|
+
ctx.font = `${weight} ${size}px ${fontFamily}`;
|
|
2980
|
+
return Math.ceil(ctx.measureText(text).width);
|
|
2981
|
+
};
|
|
2982
|
+
}
|
|
2983
|
+
// src/Loadmap.tsx
|
|
2984
|
+
/** What the page's own switch says, on `<html>`: `data-theme`, or a `dark` or `light` class; null when it says nothing. */
|
|
2985
|
+
function pageTheme() {
|
|
2986
|
+
if (typeof document === "undefined") return null;
|
|
2987
|
+
const html = document.documentElement;
|
|
2988
|
+
const t = html.dataset.theme;
|
|
2989
|
+
if (t === "dark" || t === "light") return t;
|
|
2990
|
+
if (html.classList.contains("dark")) return "dark";
|
|
2991
|
+
if (html.classList.contains("light")) return "light";
|
|
2992
|
+
return null;
|
|
2993
|
+
}
|
|
2994
|
+
const following = /* @__PURE__ */ new Set();
|
|
2995
|
+
let observer = null;
|
|
2996
|
+
function follow(changed) {
|
|
2997
|
+
following.add(changed);
|
|
2998
|
+
if (!observer && typeof MutationObserver !== "undefined") {
|
|
2999
|
+
observer = new MutationObserver(() => {
|
|
3000
|
+
for (const f of following) f();
|
|
3001
|
+
});
|
|
3002
|
+
observer.observe(document.documentElement, {
|
|
3003
|
+
attributes: true,
|
|
3004
|
+
attributeFilter: ["data-theme", "class"]
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
return () => {
|
|
3008
|
+
following.delete(changed);
|
|
3009
|
+
if (following.size) return;
|
|
3010
|
+
observer?.disconnect();
|
|
3011
|
+
observer = null;
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
const stay = () => () => {};
|
|
3015
|
+
/**
|
|
3016
|
+
* The theme to draw: `theme` itself; with `inherit`, what the page's own switch says, followed as it changes, and the
|
|
3017
|
+
* system's (`auto`) while it says nothing, as on the server.
|
|
3018
|
+
*/
|
|
3019
|
+
function usePageTheme(theme = "auto") {
|
|
3020
|
+
const page = useSyncExternalStore(theme === "inherit" ? follow : stay, pageTheme, () => null);
|
|
3021
|
+
return theme === "inherit" ? page ?? "auto" : theme;
|
|
3022
|
+
}
|
|
3023
|
+
/** The root element: theme tokens, styles, and the size the layout direction follows. */
|
|
3024
|
+
function LoadmapRoot({ lm, theme = "auto", children }) {
|
|
3025
|
+
useEffect(() => injectStyles(), []);
|
|
3026
|
+
const shown = usePageTheme(theme);
|
|
3027
|
+
useEffect(() => {
|
|
3028
|
+
if (!lm.root) return;
|
|
3029
|
+
lm.engine.readColors(lm.root);
|
|
3030
|
+
const m = matchMedia("(prefers-color-scheme: dark)");
|
|
3031
|
+
const f = () => lm.root && lm.engine.readColors(lm.root);
|
|
3032
|
+
m.addEventListener("change", f);
|
|
3033
|
+
return () => m.removeEventListener("change", f);
|
|
3034
|
+
}, [
|
|
3035
|
+
lm.root,
|
|
3036
|
+
lm.engine,
|
|
3037
|
+
shown
|
|
3038
|
+
]);
|
|
3039
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3040
|
+
className: "lm",
|
|
3041
|
+
"data-theme": shown === "auto" ? void 0 : shown,
|
|
3042
|
+
ref: lm.rootRef,
|
|
3043
|
+
children
|
|
3044
|
+
});
|
|
3045
|
+
}
|
|
3046
|
+
/** The panels full screen shows with the diagram, compact: the verdict and the assumptions in a line under it. */
|
|
3047
|
+
const LOADMAP_PANELS = [
|
|
3048
|
+
"verdict",
|
|
3049
|
+
"live",
|
|
3050
|
+
"limits",
|
|
3051
|
+
"controls",
|
|
3052
|
+
"headroom",
|
|
3053
|
+
"compare",
|
|
3054
|
+
"assumptions"
|
|
3055
|
+
];
|
|
3056
|
+
/** The whole page piece: scenarios, diagram, verdict, headroom, live meters, limits, controls and assumptions. */
|
|
3057
|
+
function Loadmap({ model, view, theme, title, assumptions, headroom = true, compare = true, fullScreen = LOADMAP_PANELS, onNodeClick, selected, ref, ...o }) {
|
|
3058
|
+
const lm = useLoadmap(model, view, o);
|
|
3059
|
+
useImperativeHandle(ref, () => handleOf(lm), [lm]);
|
|
3060
|
+
const side = compare && model.scenarios.length > 1;
|
|
3061
|
+
const charts = [];
|
|
3062
|
+
if (headroom) charts.push("headroom");
|
|
3063
|
+
if (side) charts.push("compare");
|
|
3064
|
+
const out = (...panels) => panels.some((p) => fullScreen.includes(p)) ? void 0 : "";
|
|
3065
|
+
const listed = (p) => fullScreen.includes(p) && (p === "headroom" ? headroom : p !== "compare" || side);
|
|
3066
|
+
const full = lm.fullScreen;
|
|
3067
|
+
const focus = full && lm.fullScreenMode === "focus";
|
|
3068
|
+
const [drawer, setDrawer] = useState(null);
|
|
3069
|
+
if (drawer && !full) setDrawer(null);
|
|
3070
|
+
const close = useRef(null);
|
|
3071
|
+
useEffect(() => {
|
|
3072
|
+
if (drawer) close.current?.focus();
|
|
3073
|
+
}, [drawer]);
|
|
3074
|
+
const open = (p, from) => setDrawer({
|
|
3075
|
+
panel: p,
|
|
3076
|
+
from
|
|
3077
|
+
});
|
|
3078
|
+
const shut = () => {
|
|
3079
|
+
drawer?.from.focus();
|
|
3080
|
+
setDrawer(null);
|
|
3081
|
+
};
|
|
3082
|
+
useEffect(() => {
|
|
3083
|
+
if (!drawer) return;
|
|
3084
|
+
const f = (e) => {
|
|
3085
|
+
if (e.key !== "Escape") return;
|
|
3086
|
+
e.stopPropagation();
|
|
3087
|
+
drawer.from.focus();
|
|
3088
|
+
setDrawer(null);
|
|
3089
|
+
};
|
|
3090
|
+
document.addEventListener("keydown", f, true);
|
|
3091
|
+
return () => document.removeEventListener("keydown", f, true);
|
|
3092
|
+
}, [drawer]);
|
|
3093
|
+
const drawn = (...panels) => drawer && panels.includes(drawer.panel) ? "" : void 0;
|
|
3094
|
+
const panel = (id, children) => /* @__PURE__ */ jsx("div", {
|
|
3095
|
+
className: "lm-panel",
|
|
3096
|
+
"data-panel": id,
|
|
3097
|
+
"data-out": out(id),
|
|
3098
|
+
"data-drawn": drawn(id),
|
|
3099
|
+
children: (!full || drawer?.panel === id) && children
|
|
3100
|
+
});
|
|
3101
|
+
const heading = title !== false && /* @__PURE__ */ jsx("h2", { children: title ?? model.title });
|
|
3102
|
+
const verdict = listed("verdict");
|
|
3103
|
+
const line = focus ? verdict || listed("controls") : verdict || listed("assumptions");
|
|
3104
|
+
return /* @__PURE__ */ jsxs(LoadmapRoot, {
|
|
3105
|
+
lm,
|
|
3106
|
+
theme,
|
|
3107
|
+
children: [
|
|
3108
|
+
full ? /* @__PURE__ */ jsxs("div", {
|
|
3109
|
+
className: "lm-head",
|
|
3110
|
+
children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })]
|
|
3111
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })] }),
|
|
3112
|
+
/* @__PURE__ */ jsx(Story, { lm }),
|
|
3113
|
+
/* @__PURE__ */ jsx(Diagram, {
|
|
3114
|
+
lm,
|
|
3115
|
+
onNodeClick,
|
|
3116
|
+
selected
|
|
3117
|
+
}),
|
|
3118
|
+
full && line && /* @__PURE__ */ jsxs("div", {
|
|
3119
|
+
className: "lm-line",
|
|
3120
|
+
"data-tier": lm.ev.verdict.tier,
|
|
3121
|
+
children: [/* @__PURE__ */ jsx(VerdictLine, {
|
|
3122
|
+
lm,
|
|
3123
|
+
verdict,
|
|
3124
|
+
extra: assumptions?.length,
|
|
3125
|
+
open,
|
|
3126
|
+
assumptions: !focus && listed("assumptions")
|
|
3127
|
+
}), focus && listed("controls") && /* @__PURE__ */ jsx(LoadRange, { lm })]
|
|
3128
|
+
}),
|
|
3129
|
+
full && !focus && /* @__PURE__ */ jsx(Dock, {
|
|
3130
|
+
lm,
|
|
3131
|
+
panels: LOADMAP_PANELS.filter(listed),
|
|
3132
|
+
open
|
|
3133
|
+
}),
|
|
3134
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3135
|
+
className: "lm-side lm-drawer",
|
|
3136
|
+
"data-out": out("verdict", "live", "limits", "controls", ...charts, "assumptions"),
|
|
3137
|
+
"data-drawer": drawer?.panel,
|
|
3138
|
+
...drawer && {
|
|
3139
|
+
role: "dialog",
|
|
3140
|
+
"aria-label": "The whole panel"
|
|
3141
|
+
},
|
|
3142
|
+
children: [
|
|
3143
|
+
drawer && /* @__PURE__ */ jsx("div", {
|
|
3144
|
+
className: "lm-drawer-bar",
|
|
3145
|
+
"data-drawn": "",
|
|
3146
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
3147
|
+
type: "button",
|
|
3148
|
+
className: "lm-btn",
|
|
3149
|
+
onClick: shut,
|
|
3150
|
+
ref: close,
|
|
3151
|
+
children: "✕ Back to full screen"
|
|
3152
|
+
})
|
|
3153
|
+
}),
|
|
3154
|
+
panel("verdict", /* @__PURE__ */ jsx(Verdict, { lm })),
|
|
3155
|
+
charts.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
3156
|
+
className: charts.length > 1 ? "lm-charts lm-strip" : "lm-charts",
|
|
3157
|
+
"data-out": out(...charts),
|
|
3158
|
+
"data-drawn": drawn(...charts),
|
|
3159
|
+
children: [headroom && panel("headroom", /* @__PURE__ */ jsx(HeadroomChart, { lm })), side && panel("compare", /* @__PURE__ */ jsx(Compare, { lm }))]
|
|
3160
|
+
}),
|
|
3161
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3162
|
+
className: "lm-strip lm-live",
|
|
3163
|
+
"data-out": out("live", "limits", "controls"),
|
|
3164
|
+
"data-drawn": drawn("live", "limits", "controls"),
|
|
3165
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
3166
|
+
className: "lm-card",
|
|
3167
|
+
"data-out": out("live", "limits"),
|
|
3168
|
+
"data-drawn": drawn("live", "limits"),
|
|
3169
|
+
children: [panel("live", /* @__PURE__ */ jsx(Meters, { lm })), panel("limits", /* @__PURE__ */ jsx(Limits, { lm }))]
|
|
3170
|
+
}), panel("controls", /* @__PURE__ */ jsx(Controls, { lm }))]
|
|
3171
|
+
}),
|
|
3172
|
+
panel("assumptions", /* @__PURE__ */ jsx(Assumptions, {
|
|
3173
|
+
lm,
|
|
3174
|
+
extra: assumptions
|
|
3175
|
+
}))
|
|
3176
|
+
]
|
|
3177
|
+
})
|
|
3178
|
+
]
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
function handleOf(lm) {
|
|
3182
|
+
const { engine } = lm;
|
|
3183
|
+
return {
|
|
3184
|
+
engine,
|
|
3185
|
+
async ready(timeoutMs = 1e4) {
|
|
3186
|
+
const t0 = performance.now();
|
|
3187
|
+
const drawn = () => engine.scene && engine.scene.key === engine.wantKey && engine.svg && engine.drawnValues === JSON.stringify(engine.ev.values) && engine.drawnFocus === engine.wantFocus && engine.drawnFrame === engine.frameId;
|
|
3188
|
+
while (!drawn()) {
|
|
3189
|
+
if (performance.now() - t0 > timeoutMs) throw new Error("loadmap: layout not ready");
|
|
3190
|
+
await new Promise((r) => requestAnimationFrame(r));
|
|
3191
|
+
}
|
|
3192
|
+
},
|
|
3193
|
+
pause: () => {
|
|
3194
|
+
engine.paused = true;
|
|
3195
|
+
},
|
|
3196
|
+
resume: () => {
|
|
3197
|
+
engine.paused = false;
|
|
3198
|
+
},
|
|
3199
|
+
values: () => engine.ev.values,
|
|
3200
|
+
setValues: (v) => lm.setValues(v),
|
|
3201
|
+
setStoryStep: (i) => lm.setStep(i),
|
|
3202
|
+
storyStep: () => engine.storyStep,
|
|
3203
|
+
reset: (seed) => engine.reset(seed),
|
|
3204
|
+
step: (dt) => {
|
|
3205
|
+
engine.step(dt, { particles: true });
|
|
3206
|
+
engine.draw({ particles: true });
|
|
3207
|
+
},
|
|
3208
|
+
board: () => engine.svg && engine.canvas && engine.frame ? {
|
|
3209
|
+
svg: engine.svg,
|
|
3210
|
+
canvas: engine.canvas,
|
|
3211
|
+
scene: engine.frame
|
|
3212
|
+
} : null
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
export { Compare as _, usePageTheme as a, scenarioColor as b, injectStyles as c, Controls as d, Limits as f, Diagram as g, workerElk as h, handleOf as i, Story as l, Verdict as m, Loadmap as n, useLoadmap as o, Meters as p, LoadmapRoot as r, LOADMAP_CSS as s, LOADMAP_PANELS as t, Assumptions as u, HeadroomChart as v, useComparison as x, Scenarios as y };
|