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