@loadmap/react 0.17.0 → 0.18.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.
@@ -212,7 +212,7 @@ function stepDetail(a, b, components) {
212
212
  }).filter(Boolean).join(" · ");
213
213
  }
214
214
  // src/Diagram.tsx
215
- const Detail = lazy(() => import("./later-Dk7QnTxR.js").then((m) => ({ default: m.Detail })));
215
+ const Detail = lazy(() => import("./later-B9SnId7C.js").then((m) => ({ default: m.Detail })));
216
216
  const STATE_STROKE = {
217
217
  off: "var(--lm-line)",
218
218
  ok: "var(--lm-ok)",
@@ -285,11 +285,27 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
285
285
  engine.drawnFrame = frameId;
286
286
  });
287
287
  useEffect(() => {
288
- const board = boardRef.current;
289
- if (!board) return;
290
- const ro = new ResizeObserver(() => engine.resize());
291
- ro.observe(board);
292
- return () => ro.disconnect();
288
+ const canvas = canvasRef.current;
289
+ if (!canvas) return;
290
+ const box = typeof ResizeObserverEntry !== "undefined" && "devicePixelContentBoxSize" in ResizeObserverEntry.prototype ? "device-pixel-content-box" : "content-box";
291
+ const ro = new ResizeObserver(([e]) => {
292
+ const px = e?.target === engine.canvas && pixels(e);
293
+ if (px) engine.resize(px);
294
+ });
295
+ let mq;
296
+ const watch = () => {
297
+ mq?.removeEventListener("change", watch);
298
+ ro.disconnect();
299
+ ro.observe(canvas, { box });
300
+ if (typeof matchMedia !== "function") return;
301
+ mq = matchMedia(`(resolution: ${globalThis.devicePixelRatio || 1}dppx)`);
302
+ mq.addEventListener("change", watch);
303
+ };
304
+ watch();
305
+ return () => {
306
+ ro.disconnect();
307
+ mq?.removeEventListener("change", watch);
308
+ };
293
309
  }, [engine]);
294
310
  const shape = useRef({
295
311
  canvas: !!canvas,
@@ -501,6 +517,25 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
501
517
  ]
502
518
  });
503
519
  }
520
+ /**
521
+ * The device pixels an element covers: as the browser counts them, snapped as it draws, unless they disagree with its
522
+ * size × the pixel ratio (an emulated ratio, which Chromium leaves out of them). Nothing for an element not shown.
523
+ */
524
+ function pixels(e) {
525
+ const s = e.contentBoxSize[0];
526
+ if (!s?.inlineSize || !s.blockSize) return null;
527
+ const dpr = globalThis.devicePixelRatio || 1;
528
+ const width = Math.round(s.inlineSize * dpr);
529
+ const height = Math.round(s.blockSize * dpr);
530
+ const d = e.devicePixelContentBoxSize?.[0];
531
+ return d && Math.abs(d.inlineSize - width) <= 1 && Math.abs(d.blockSize - height) <= 1 ? {
532
+ width: d.inlineSize,
533
+ height: d.blockSize
534
+ } : {
535
+ width,
536
+ height
537
+ };
538
+ }
504
539
  /** The keyboard is in a field that takes letters: the first target of the key, inside a web component too. */
505
540
  function typing(t) {
506
541
  if (!(t instanceof HTMLElement)) return false;
@@ -1081,561 +1116,188 @@ function workerElk(make) {
1081
1116
  });
1082
1117
  } };
1083
1118
  }
1084
- // src/panels.tsx
1085
- /** The model's one-sentence answer for the current values, and which capacity to measure when it is unsure. */
1086
- function Verdict({ lm }) {
1087
- const { measure } = lm.ev;
1088
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
1089
- className: "lm-verdict",
1090
- "data-tier": lm.ev.verdict.tier,
1091
- "aria-live": "polite",
1092
- children: lm.ev.verdict.text
1093
- }), measure && /* @__PURE__ */ jsx("p", {
1094
- className: "lm-measure",
1095
- "data-component": measure.component,
1096
- children: measure.text
1097
- })] });
1119
+ // src/scenarios.tsx
1120
+ /** Scenario identity colours, in declaration order; a fifth and later scenario is drawn muted. */
1121
+ const SERIES = [
1122
+ "var(--lm-s1)",
1123
+ "var(--lm-s2)",
1124
+ "var(--lm-s3)",
1125
+ "var(--lm-s4)"
1126
+ ];
1127
+ /** The colour of a scenario by label; values of the reader's own are drawn in the text colour. */
1128
+ function scenarioColor(model, label) {
1129
+ if (label == null) return "var(--lm-fg)";
1130
+ const i = model.scenarios.findIndex((s) => s.label === label);
1131
+ return SERIES[i] ?? "var(--lm-muted)";
1098
1132
  }
1099
- /** "±30 %" for a capacity with a range. */
1100
- const plusMinus = (c) => c?.within ? `±${pct(c.within)}` : "";
1101
- /** Each component's utilization in the order they reach the target, with where they cross it and 100 %. */
1102
- function Limits({ lm, title = "Where it runs out, in order" }) {
1103
- const { ev, model } = lm;
1104
- const top = Math.max(1.5, model.thresholds.full * 1.5);
1105
- const at = (u) => `${u / top * 100}%`;
1106
- const span = (r, x) => r ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax);
1107
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1108
- /* @__PURE__ */ jsx("h3", { children: title }),
1109
- /* @__PURE__ */ jsxs("div", {
1110
- className: "lm-scale",
1111
- "aria-hidden": "true",
1112
- children: [
1113
- /* @__PURE__ */ jsx("span", {}),
1114
- /* @__PURE__ */ jsxs("div", { children: [
1115
- /* @__PURE__ */ jsx("span", {
1116
- style: {
1117
- left: 0,
1118
- transform: "none"
1119
- },
1120
- children: "0"
1121
- }),
1122
- /* @__PURE__ */ jsxs("span", {
1123
- style: { left: at(model.thresholds.target) },
1124
- children: [pct(model.thresholds.target), " target"]
1125
- }),
1126
- /* @__PURE__ */ jsx("span", {
1127
- style: { left: at(model.thresholds.full) },
1128
- children: pct(model.thresholds.full)
1129
- }),
1130
- /* @__PURE__ */ jsx("span", {
1131
- style: {
1132
- left: "100%",
1133
- transform: "translateX(-100%)"
1134
- },
1135
- children: pct(top)
1136
- })
1137
- ] }),
1138
- /* @__PURE__ */ jsx("span", {})
1139
- ]
1140
- }),
1141
- /* @__PURE__ */ jsx("div", {
1142
- className: "lm-limits",
1143
- children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
1144
- className: "lm-lim",
1145
- "data-component": c.id,
1146
- children: [
1147
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("b", { children: [
1148
- c.name,
1149
- c === ev.firstLimit && /* @__PURE__ */ jsx("span", {
1150
- className: "lm-tag",
1151
- "data-kind": "first",
1152
- children: "limit"
1133
+ const lineName = (l) => l.label ?? "These values";
1134
+ /** A month for a table cell or an axis: "Mar 2031"; "now" for a crossing already reached. */
1135
+ function when(model, x) {
1136
+ const d = model.dateAt(x);
1137
+ return d ? monthOf(d, true) : x != null && x <= 1 && model.growth ? "now" : "";
1138
+ }
1139
+ /** The months of both edges: "Sep 2029–Feb 2030", or one month when they agree. */
1140
+ function whenRange(model, r) {
1141
+ if (!r) return "";
1142
+ const [lo, hi] = [when(model, r.low), when(model, r.high)];
1143
+ return !hi || lo === hi ? lo : `${lo}–${hi}`;
1144
+ }
1145
+ /** The comparison at the shown load: crossings do not depend on it, the verdicts do. */
1146
+ function useComparison(lm) {
1147
+ return useMemo(() => compare(lm.model, lm.values.load), [lm.model, lm.values.load]);
1148
+ }
1149
+ /** One button per scenario: a reader switches designs without touching the controls. The load stays. */
1150
+ function Scenarios({ lm }) {
1151
+ const { model } = lm;
1152
+ if (!model.scenarios.length) return null;
1153
+ return /* @__PURE__ */ jsxs("fieldset", {
1154
+ className: "lm-scenarios",
1155
+ children: [
1156
+ /* @__PURE__ */ jsx("legend", { children: "Scenario" }),
1157
+ model.scenarios.map((s) => /* @__PURE__ */ jsxs("button", {
1158
+ type: "button",
1159
+ "aria-pressed": lm.scenario?.label === s.label,
1160
+ onClick: () => lm.setScenario(s.label),
1161
+ children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, s.label) } }), s.label]
1162
+ }, s.label)),
1163
+ !lm.scenario && /* @__PURE__ */ jsx("span", {
1164
+ className: "lm-own",
1165
+ children: "your own values"
1166
+ })
1167
+ ]
1168
+ });
1169
+ }
1170
+ /** "+107 %" against the baseline; "same" within a rounding; nothing where either never runs out. */
1171
+ function change(x) {
1172
+ if (x == null || !Number.isFinite(x) || x === 0) return "";
1173
+ if (Math.abs(x - 1) < .005) return "same";
1174
+ return `${x > 1 ? "+" : "−"}${pct(Math.abs(x - 1))}`;
1175
+ }
1176
+ /** The scenarios side by side: which buys more headroom, where each first runs out, and per component. */
1177
+ function Compare({ lm, title = "Scenarios compared" }) {
1178
+ const { model } = lm;
1179
+ const c = useComparison(lm);
1180
+ if (c.rows.length < 2) return null;
1181
+ const target = `${pct(model.thresholds.target)} target`;
1182
+ const at = (r) => /* @__PURE__ */ jsxs(Fragment, { children: [r ? multiples(r, model.searchMax, true) : multiple(null), whenRange(model, r) && /* @__PURE__ */ jsx("small", { children: whenRange(model, r) })] });
1183
+ return /* @__PURE__ */ jsxs("div", {
1184
+ className: "lm-card lm-compare",
1185
+ children: [
1186
+ /* @__PURE__ */ jsx("h3", { children: title }),
1187
+ /* @__PURE__ */ jsx("p", {
1188
+ className: "lm-compare-text",
1189
+ children: c.text
1190
+ }),
1191
+ /* @__PURE__ */ jsx("div", {
1192
+ className: "lm-table-wrap",
1193
+ children: /* @__PURE__ */ jsxs("table", {
1194
+ className: "lm-table",
1195
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
1196
+ /* @__PURE__ */ jsx("th", {
1197
+ scope: "col",
1198
+ children: "Scenario"
1153
1199
  }),
1154
- c.capacity?.provenance === "estimated" ? /* @__PURE__ */ jsxs("span", {
1155
- className: "lm-tag",
1156
- "data-kind": "estimated",
1157
- children: ["estimate", c.capacity.within ? ` ${plusMinus(c.capacity)}` : ""]
1158
- }) : !!c.capacity?.within && /* @__PURE__ */ jsx("span", {
1159
- className: "lm-tag",
1160
- "data-kind": "range",
1161
- children: plusMinus(c.capacity)
1200
+ /* @__PURE__ */ jsx("th", {
1201
+ scope: "col",
1202
+ children: "Limited by"
1203
+ }),
1204
+ /* @__PURE__ */ jsx("th", {
1205
+ scope: "col",
1206
+ children: target
1207
+ }),
1208
+ /* @__PURE__ */ jsx("th", {
1209
+ scope: "col",
1210
+ children: "Runs out"
1162
1211
  })
1163
- ] }), /* @__PURE__ */ jsx("span", {
1164
- className: "lm-sub",
1165
- children: c.describe ?? (c.capacity ? `${fmt(c.capacity.value)} ${c.capacity.unit}` : "switched off")
1166
- })] }),
1167
- /* @__PURE__ */ jsxs("div", {
1168
- className: "lm-track",
1169
- role: "img",
1170
- "aria-label": `${c.name} at ${c.util == null ? "off" : pct(c.util)}`,
1212
+ ] }) }), /* @__PURE__ */ jsx("tbody", { children: c.rows.map((r) => /* @__PURE__ */ jsxs("tr", {
1213
+ "data-scenario": r.label,
1214
+ "aria-current": lm.scenario?.label === r.label || void 0,
1171
1215
  children: [
1172
- /* @__PURE__ */ jsx("div", {
1173
- className: "lm-fill",
1174
- "data-state": c.state,
1175
- style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
1216
+ /* @__PURE__ */ jsxs("th", {
1217
+ scope: "row",
1218
+ children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, r.label) } }), r.label]
1176
1219
  }),
1177
- /* @__PURE__ */ jsx("div", {
1178
- className: "lm-tick",
1179
- style: { left: at(model.thresholds.target) }
1220
+ /* @__PURE__ */ jsx("td", {
1221
+ className: "lm-text",
1222
+ children: r.firstLimit?.name ?? "—"
1180
1223
  }),
1181
- /* @__PURE__ */ jsx("div", {
1182
- className: "lm-tick",
1183
- style: { left: at(model.thresholds.full) }
1224
+ /* @__PURE__ */ jsx("td", {
1225
+ "data-multiple": r.target ?? "",
1226
+ "data-high": r.targetRange?.high ?? "",
1227
+ children: at(r.targetRange)
1228
+ }),
1229
+ /* @__PURE__ */ jsx("td", {
1230
+ "data-multiple": r.full ?? "",
1231
+ "data-high": r.fullRange?.high ?? "",
1232
+ children: at(r.fullRange)
1184
1233
  })
1185
1234
  ]
1186
- }),
1187
- /* @__PURE__ */ jsxs("div", {
1188
- className: "lm-val",
1189
- children: [c.util == null ? "—" : `${pct(c.util)} · ${num(c.demand ?? 0)} ${c.capacity?.unit ?? ""}`, /* @__PURE__ */ jsx("small", { children: c.util == null ? "switched off" : `${pct(model.thresholds.target)} at ${span(c.targetRange, c.target)} · full at ${span(c.fullRange, c.full)}` })]
1190
- })
1191
- ]
1192
- }, c.id))
1193
- })
1194
- ] });
1195
- }
1196
- /**
1197
- * Live numbers: from the sim, lag and drops per queue, busy workers, rejected requests; from the model, pods running,
1198
- * cache answers and retries.
1199
- */
1200
- function Meters({ lm }) {
1201
- const [, tick] = useState(0);
1202
- useEffect(() => {
1203
- const t = setInterval(() => tick((x) => x + 1), 250);
1204
- return () => clearInterval(t);
1205
- }, []);
1206
- const { ev, engine, model } = lm;
1207
- const sim = engine.sim;
1208
- const flowLabel = (f) => model.def.flows[f]?.label ?? f;
1209
- const items = [];
1210
- for (const s of Object.values(ev.stages)) {
1211
- if (s.kind === "queue") for (const f of model.flowIds.filter((x) => ev.routes[x]?.includes(s.id))) {
1212
- const q = sim.queue(s.id, f);
1213
- const rules = ev.overload[f] ?? {};
1214
- items.push({
1215
- key: `${s.id}/${f}/lag`,
1216
- value: secs(q.lag),
1217
- label: `${flowLabel(f)} lag in ${s.label}`,
1218
- state: q.lag > 60 ? "over" : q.lag > 5 ? "warn" : "ok"
1219
- });
1220
- if (rules.merge) items.push({
1221
- key: `${s.id}/${f}/merge`,
1222
- value: compact(q.merged),
1223
- label: `${flowLabel(f)} superseded /s (${rules.merge.reason ?? "newest kept"})`,
1224
- state: q.merged > .5 ? "warn" : "ok"
1225
- });
1226
- if (rules.drop) items.push({
1227
- key: `${s.id}/${f}/drop`,
1228
- value: compact(q.dropped),
1229
- label: `${flowLabel(f)} dropped /s (${rules.drop.reason ?? "too old"})`,
1230
- state: q.dropped > .5 ? "over" : "ok"
1231
- });
1232
- }
1233
- if (s.kind === "workers") {
1234
- const b = sim.busy(s.id);
1235
- items.push({
1236
- key: `${s.id}/busy`,
1237
- value: pct(b),
1238
- label: `${s.label} busy`,
1239
- state: b > .95 ? "over" : b > .5 ? "warn" : "ok"
1240
- });
1241
- if (s.autoscale) items.push({
1242
- key: `${s.id}/pods`,
1243
- value: `${s.running} of ${s.pods}`,
1244
- label: `${s.label} pods running`,
1245
- state: s.running < s.pods ? "ok" : (ev.components[s.component]?.util ?? 0) > model.thresholds.full ? "over" : "warn"
1246
- });
1247
- }
1248
- if (s.kind === "cache") items.push({
1249
- key: `${s.id}/hits`,
1250
- value: compact(sim.arriving(s.id) * (1 - sim.shed(s.id)) * s.hit),
1251
- label: `answered at ${s.label} /s (${pct(s.hit)} hits)`,
1252
- state: "ok"
1253
- });
1254
- if ((s.kind === "pass" || s.kind === "limit" || s.kind === "cache") && sim.shed(s.id) > 0) items.push({
1255
- key: `${s.id}/shed`,
1256
- value: pct(sim.shed(s.id)),
1257
- label: `rejected at ${s.label}`,
1258
- state: "over"
1259
- });
1260
- }
1261
- for (const f of model.flowIds) {
1262
- const r = ev.retry[f];
1263
- if (!r || !(r.rate > 0)) continue;
1264
- const per = r.attempts / r.rate;
1265
- items.push({
1266
- key: `${f}/attempts`,
1267
- value: `${fmt(per)}×`,
1268
- label: `${flowLabel(f)} attempts per ${model.def.flows[f]?.unit ?? "unit"}`,
1269
- state: per > 1.05 ? "warn" : "ok"
1270
- });
1271
- items.push({
1272
- key: `${f}/failed`,
1273
- value: pct(r.failed),
1274
- label: `${flowLabel(f)} failing after ${r.times} ${r.times === 1 ? "retry" : "retries"}`,
1275
- state: r.failed > .005 ? "over" : "ok"
1276
- });
1277
- }
1278
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Live" }), /* @__PURE__ */ jsx("div", {
1279
- className: "lm-meters",
1280
- children: items.map((m) => /* @__PURE__ */ jsxs("div", {
1281
- className: "lm-meter",
1282
- "data-state": m.state,
1283
- children: [/* @__PURE__ */ jsx("b", { children: m.value }), /* @__PURE__ */ jsx("span", {
1284
- title: m.label,
1285
- children: m.label
1286
- })]
1287
- }, m.key))
1288
- })] });
1289
- }
1290
- /** The load slider with its label and value. */
1291
- function LoadRange({ lm }) {
1292
- const load = lm.model.load;
1293
- const x = lm.values.load;
1294
- return /* @__PURE__ */ jsxs("label", {
1295
- className: "lm-range",
1296
- children: [/* @__PURE__ */ jsxs("span", { children: [
1297
- load.label,
1298
- " ",
1299
- /* @__PURE__ */ jsxs("output", { children: [fmt(x), "×"] })
1300
- ] }), /* @__PURE__ */ jsx("input", {
1301
- type: "range",
1302
- min: load.min,
1303
- max: load.max,
1304
- step: load.step,
1305
- value: x,
1306
- onChange: (e) => lm.setValues({ load: Number(e.target.value) })
1307
- })]
1308
- });
1309
- }
1310
- /** The load slider, the presets and every parameter, greyed out where it does not apply. */
1311
- function Controls({ lm }) {
1312
- const { model, values, setValues, ev } = lm;
1313
- const v = values;
1314
- return /* @__PURE__ */ jsxs("div", {
1315
- className: "lm-card lm-controls",
1316
- children: [
1317
- /* @__PURE__ */ jsx("h3", { children: "Load" }),
1318
- /* @__PURE__ */ jsx(LoadRange, { lm }),
1319
- /* @__PURE__ */ jsx("div", {
1320
- className: "lm-presets",
1321
- children: ev.presets.map((p) => {
1322
- const on = Object.entries(p.values).every(([k, x]) => v[k] === x);
1323
- return /* @__PURE__ */ jsx("button", {
1324
- type: "button",
1325
- "aria-pressed": on,
1326
- onClick: () => setValues(p.values),
1327
- children: p.label
1328
- }, p.label);
1235
+ }, r.label)) })]
1329
1236
  })
1330
1237
  }),
1331
- model.params.length > 1 && /* @__PURE__ */ jsx("h3", { children: "Design" }),
1332
- model.params.map(({ id, def }) => {
1333
- if (def.kind === "load") return null;
1334
- const enabled = model.isEnabled(id, v);
1335
- const tag = def.tag && /* @__PURE__ */ jsx("span", {
1336
- className: "lm-tag",
1337
- "data-kind": "estimated",
1338
- children: def.tag
1339
- });
1340
- if (def.kind === "switch") return /* @__PURE__ */ jsxs("label", {
1341
- className: `lm-switch${enabled ? "" : " lm-off"}`,
1342
- children: [
1343
- /* @__PURE__ */ jsx("input", {
1344
- type: "checkbox",
1345
- checked: Boolean(v[id]),
1346
- disabled: !enabled,
1347
- onChange: (e) => setValues({ [id]: e.target.checked })
1348
- }),
1349
- /* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
1350
- def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
1351
- ]
1352
- }, id);
1353
- if (def.kind === "select") return /* @__PURE__ */ jsxs("label", {
1354
- className: `lm-select${enabled ? "" : " lm-off"}`,
1355
- children: [
1356
- /* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
1357
- /* @__PURE__ */ jsx("select", {
1358
- value: String(v[id]),
1359
- disabled: !enabled,
1360
- onChange: (e) => {
1361
- const opt = def.options.find((o) => String(o) === e.target.value);
1362
- setValues({ [id]: opt });
1363
- },
1364
- children: def.options.map((o) => /* @__PURE__ */ jsx("option", {
1365
- value: String(o),
1366
- children: def.format ? def.format(o) : String(o)
1367
- }, String(o)))
1368
- }),
1369
- def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
1370
- ]
1371
- }, id);
1372
- return /* @__PURE__ */ jsxs("label", {
1373
- className: `lm-range${enabled ? "" : " lm-off"}`,
1374
- children: [
1375
- /* @__PURE__ */ jsxs("span", { children: [
1376
- def.label,
1377
- tag,
1378
- " ",
1379
- /* @__PURE__ */ jsx("output", { children: def.format ? def.format(v[id]) : fmt(v[id]) })
1380
- ] }),
1381
- /* @__PURE__ */ jsx("input", {
1382
- type: "range",
1383
- min: def.min,
1384
- max: def.max,
1385
- step: def.step,
1386
- value: v[id],
1387
- disabled: !enabled,
1388
- onChange: (e) => setValues({ [id]: Number(e.target.value) })
1389
- }),
1390
- def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
1391
- ]
1392
- }, id);
1238
+ /* @__PURE__ */ jsxs("h3", { children: [target, ", by component"] }),
1239
+ /* @__PURE__ */ jsx("div", {
1240
+ className: "lm-table-wrap",
1241
+ children: /* @__PURE__ */ jsxs("table", {
1242
+ className: "lm-table",
1243
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
1244
+ scope: "col",
1245
+ children: "Component"
1246
+ }), c.rows.map((r) => /* @__PURE__ */ jsx("th", {
1247
+ scope: "col",
1248
+ children: r.label
1249
+ }, r.label))] }) }), /* @__PURE__ */ jsx("tbody", { children: model.componentIds.map((id, k) => /* @__PURE__ */ jsxs("tr", {
1250
+ "data-component": id,
1251
+ children: [/* @__PURE__ */ jsx("th", {
1252
+ scope: "row",
1253
+ children: c.rows[0].components[k].name
1254
+ }), c.rows.map((r, i) => {
1255
+ const x = r.components[k];
1256
+ return /* @__PURE__ */ jsxs("td", {
1257
+ "data-multiple": x.target ?? "",
1258
+ children: [x.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true), i > 0 && change(x.change) && /* @__PURE__ */ jsx("small", { children: change(x.change) })]
1259
+ }, r.label);
1260
+ })]
1261
+ }, id)) })]
1262
+ })
1393
1263
  })
1394
1264
  ]
1395
1265
  });
1396
1266
  }
1397
- /** What the model assumes: every capacity with its provenance, every fit, and anything the page adds. */
1398
- function Assumptions({ lm, extra = [] }) {
1399
- return /* @__PURE__ */ jsxs("div", {
1400
- className: "lm-card",
1401
- children: [/* @__PURE__ */ jsx("h3", { children: "What this assumes" }), /* @__PURE__ */ jsxs("ul", {
1402
- className: "lm-facts",
1403
- 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}`))]
1404
- })]
1267
+ /** The size of an element in CSS pixels, kept current: a chart draws at its own size so text stays legible. */
1268
+ function useSize(fallback) {
1269
+ const ref = useRef(null);
1270
+ const [size, setSize] = useState({
1271
+ width: fallback,
1272
+ height: 0
1405
1273
  });
1274
+ useEffect(() => {
1275
+ const el = ref.current;
1276
+ if (!el) return;
1277
+ const ro = new ResizeObserver(([e]) => {
1278
+ const width = Math.round(e?.contentRect.width ?? el.clientWidth);
1279
+ const height = Math.round(e?.contentRect.height ?? el.clientHeight);
1280
+ if (width > 0) setSize((s) => s.width === width && s.height === height ? s : {
1281
+ width,
1282
+ height
1283
+ });
1284
+ });
1285
+ ro.observe(el);
1286
+ return () => ro.disconnect();
1287
+ }, []);
1288
+ return [ref, size];
1406
1289
  }
1407
- function describe(a) {
1408
- if (a.kind === "capacity") {
1409
- const c = a.capacity;
1410
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1411
- /* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
1412
- " ",
1413
- fmt(c.value),
1414
- " ",
1415
- c.unit,
1416
- c.within ? ` ${plusMinus(c)}` : "",
1417
- ",",
1418
- " ",
1419
- /* @__PURE__ */ jsx("span", {
1420
- className: "lm-prov",
1421
- "data-kind": c.provenance,
1422
- children: c.provenance
1423
- }),
1424
- c.source ? ` (${c.source})` : "",
1425
- "."
1426
- ] });
1427
- }
1428
- const f = a.fit;
1429
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1430
- /* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
1431
- " ",
1432
- f.y,
1433
- " = ",
1434
- sig(f.a),
1435
- " + ",
1436
- sig(f.b),
1437
- " × ",
1438
- f.x,
1439
- ", r² ",
1440
- f.r2.toFixed(3),
1441
- " over ",
1442
- f.n,
1443
- " points,",
1444
- " ",
1445
- /* @__PURE__ */ jsx("span", {
1446
- className: "lm-prov",
1447
- "data-kind": "measured",
1448
- children: "measured"
1449
- }),
1450
- f.source ? ` (${f.source})` : "",
1451
- "."
1452
- ] });
1453
- }
1454
- /** Exact below 1,000 (3.9 cores), compact above (12k req/s). */
1455
- const num = (x) => Math.abs(x) >= 1e3 ? compact(x) : fmt(x);
1456
- const sig = (x) => Number(x.toPrecision(3)).toString();
1457
- // src/scenarios.tsx
1458
- /** Scenario identity colours, in declaration order; a fifth and later scenario is drawn muted. */
1459
- const SERIES = [
1460
- "var(--lm-s1)",
1461
- "var(--lm-s2)",
1462
- "var(--lm-s3)",
1463
- "var(--lm-s4)"
1464
- ];
1465
- /** The colour of a scenario by label; values of the reader's own are drawn in the text colour. */
1466
- function scenarioColor(model, label) {
1467
- if (label == null) return "var(--lm-fg)";
1468
- const i = model.scenarios.findIndex((s) => s.label === label);
1469
- return SERIES[i] ?? "var(--lm-muted)";
1470
- }
1471
- const lineName = (l) => l.label ?? "These values";
1472
- /** A month for a table cell or an axis: "Mar 2031"; "now" for a crossing already reached. */
1473
- function when(model, x) {
1474
- const d = model.dateAt(x);
1475
- return d ? monthOf(d, true) : x != null && x <= 1 && model.growth ? "now" : "";
1476
- }
1477
- /** The months of both edges: "Sep 2029–Feb 2030", or one month when they agree. */
1478
- function whenRange(model, r) {
1479
- if (!r) return "";
1480
- const [lo, hi] = [when(model, r.low), when(model, r.high)];
1481
- return !hi || lo === hi ? lo : `${lo}–${hi}`;
1482
- }
1483
- /** The comparison at the shown load: crossings do not depend on it, the verdicts do. */
1484
- function useComparison(lm) {
1485
- return useMemo(() => compare(lm.model, lm.values.load), [lm.model, lm.values.load]);
1486
- }
1487
- /** One button per scenario: a reader switches designs without touching the controls. The load stays. */
1488
- function Scenarios({ lm }) {
1489
- const { model } = lm;
1490
- if (!model.scenarios.length) return null;
1491
- return /* @__PURE__ */ jsxs("fieldset", {
1492
- className: "lm-scenarios",
1493
- children: [
1494
- /* @__PURE__ */ jsx("legend", { children: "Scenario" }),
1495
- model.scenarios.map((s) => /* @__PURE__ */ jsxs("button", {
1496
- type: "button",
1497
- "aria-pressed": lm.scenario?.label === s.label,
1498
- onClick: () => lm.setScenario(s.label),
1499
- children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, s.label) } }), s.label]
1500
- }, s.label)),
1501
- !lm.scenario && /* @__PURE__ */ jsx("span", {
1502
- className: "lm-own",
1503
- children: "your own values"
1504
- })
1505
- ]
1506
- });
1507
- }
1508
- /** "+107 %" against the baseline; "same" within a rounding; nothing where either never runs out. */
1509
- function change(x) {
1510
- if (x == null || !Number.isFinite(x) || x === 0) return "";
1511
- if (Math.abs(x - 1) < .005) return "same";
1512
- return `${x > 1 ? "+" : "−"}${pct(Math.abs(x - 1))}`;
1513
- }
1514
- /** The scenarios side by side: which buys more headroom, where each first runs out, and per component. */
1515
- function Compare({ lm, title = "Scenarios compared" }) {
1516
- const { model } = lm;
1517
- const c = useComparison(lm);
1518
- if (c.rows.length < 2) return null;
1519
- const target = `${pct(model.thresholds.target)} target`;
1520
- const at = (r) => /* @__PURE__ */ jsxs(Fragment, { children: [r ? multiples(r, model.searchMax, true) : multiple(null), whenRange(model, r) && /* @__PURE__ */ jsx("small", { children: whenRange(model, r) })] });
1521
- return /* @__PURE__ */ jsxs("div", {
1522
- className: "lm-card lm-compare",
1523
- children: [
1524
- /* @__PURE__ */ jsx("h3", { children: title }),
1525
- /* @__PURE__ */ jsx("p", {
1526
- className: "lm-compare-text",
1527
- children: c.text
1528
- }),
1529
- /* @__PURE__ */ jsx("div", {
1530
- className: "lm-table-wrap",
1531
- children: /* @__PURE__ */ jsxs("table", {
1532
- className: "lm-table",
1533
- children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
1534
- /* @__PURE__ */ jsx("th", {
1535
- scope: "col",
1536
- children: "Scenario"
1537
- }),
1538
- /* @__PURE__ */ jsx("th", {
1539
- scope: "col",
1540
- children: "Limited by"
1541
- }),
1542
- /* @__PURE__ */ jsx("th", {
1543
- scope: "col",
1544
- children: target
1545
- }),
1546
- /* @__PURE__ */ jsx("th", {
1547
- scope: "col",
1548
- children: "Runs out"
1549
- })
1550
- ] }) }), /* @__PURE__ */ jsx("tbody", { children: c.rows.map((r) => /* @__PURE__ */ jsxs("tr", {
1551
- "data-scenario": r.label,
1552
- "aria-current": lm.scenario?.label === r.label || void 0,
1553
- children: [
1554
- /* @__PURE__ */ jsxs("th", {
1555
- scope: "row",
1556
- children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, r.label) } }), r.label]
1557
- }),
1558
- /* @__PURE__ */ jsx("td", {
1559
- className: "lm-text",
1560
- children: r.firstLimit?.name ?? "—"
1561
- }),
1562
- /* @__PURE__ */ jsx("td", {
1563
- "data-multiple": r.target ?? "",
1564
- "data-high": r.targetRange?.high ?? "",
1565
- children: at(r.targetRange)
1566
- }),
1567
- /* @__PURE__ */ jsx("td", {
1568
- "data-multiple": r.full ?? "",
1569
- "data-high": r.fullRange?.high ?? "",
1570
- children: at(r.fullRange)
1571
- })
1572
- ]
1573
- }, r.label)) })]
1574
- })
1575
- }),
1576
- /* @__PURE__ */ jsxs("h3", { children: [target, ", by component"] }),
1577
- /* @__PURE__ */ jsx("div", {
1578
- className: "lm-table-wrap",
1579
- children: /* @__PURE__ */ jsxs("table", {
1580
- className: "lm-table",
1581
- children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
1582
- scope: "col",
1583
- children: "Component"
1584
- }), c.rows.map((r) => /* @__PURE__ */ jsx("th", {
1585
- scope: "col",
1586
- children: r.label
1587
- }, r.label))] }) }), /* @__PURE__ */ jsx("tbody", { children: model.componentIds.map((id, k) => /* @__PURE__ */ jsxs("tr", {
1588
- "data-component": id,
1589
- children: [/* @__PURE__ */ jsx("th", {
1590
- scope: "row",
1591
- children: c.rows[0].components[k].name
1592
- }), c.rows.map((r, i) => {
1593
- const x = r.components[k];
1594
- return /* @__PURE__ */ jsxs("td", {
1595
- "data-multiple": x.target ?? "",
1596
- children: [x.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true), i > 0 && change(x.change) && /* @__PURE__ */ jsx("small", { children: change(x.change) })]
1597
- }, r.label);
1598
- })]
1599
- }, id)) })]
1600
- })
1601
- })
1602
- ]
1603
- });
1604
- }
1605
- /** The size of an element in CSS pixels, kept current: a chart draws at its own size so text stays legible. */
1606
- function useSize(fallback) {
1607
- const ref = useRef(null);
1608
- const [size, setSize] = useState({
1609
- width: fallback,
1610
- height: 0
1611
- });
1612
- useEffect(() => {
1613
- const el = ref.current;
1614
- if (!el) return;
1615
- const ro = new ResizeObserver(([e]) => {
1616
- const width = Math.round(e?.contentRect.width ?? el.clientWidth);
1617
- const height = Math.round(e?.contentRect.height ?? el.clientHeight);
1618
- if (width > 0) setSize((s) => s.width === width && s.height === height ? s : {
1619
- width,
1620
- height
1621
- });
1622
- });
1623
- ro.observe(el);
1624
- return () => ro.disconnect();
1625
- }, []);
1626
- return [ref, size];
1627
- }
1628
- /** Every scenario's line over the load: it depends on every value but the load, which is only the marker. */
1629
- function useHeadroom(lm) {
1630
- const { model, values } = lm;
1631
- const rest = JSON.stringify({
1632
- ...values,
1633
- load: null
1634
- });
1635
- return useMemo(() => headroom(model, {
1636
- ...values,
1637
- load: model.load.default
1638
- }), [model, rest]);
1290
+ /** Every scenario's line over the load: it depends on every value but the load, which is only the marker. */
1291
+ function useHeadroom(lm) {
1292
+ const { model, values } = lm;
1293
+ const rest = JSON.stringify({
1294
+ ...values,
1295
+ load: null
1296
+ });
1297
+ return useMemo(() => headroom(model, {
1298
+ ...values,
1299
+ load: model.load.default
1300
+ }), [model, rest]);
1639
1301
  }
1640
1302
  /**
1641
1303
  * The width of a label in the chart's 11 px monospace (`--lm-mono`), measured once the chart is on the page, so its
@@ -1915,125 +1577,640 @@ function HeadroomChart({ lm, title = "Headroom" }) {
1915
1577
  className: "lm-axis",
1916
1578
  children: shown
1917
1579
  }),
1918
- h.lines.flatMap((l) => [[
1919
- "target",
1920
- l.targetRange,
1921
- model.thresholds.target
1922
- ], [
1923
- "full",
1924
- l.fullRange,
1925
- model.thresholds.full
1926
- ]].map(([kind, r, u]) => {
1927
- if (!l.band || !r || !Number.isFinite(r.low) || r.low > h.to) return null;
1928
- const [x1, x2] = [lx(Math.max(h.from, r.low)), lx(Math.min(h.to, r.high))];
1929
- const y = ly(u);
1930
- return /* @__PURE__ */ jsxs("g", {
1931
- "data-range": kind,
1932
- "data-scenario": lineName(l),
1933
- "data-low": r.low,
1934
- "data-high": r.high,
1935
- stroke: scenarioColor(model, l.label),
1936
- strokeWidth: l.selected ? 3 : 2,
1937
- strokeOpacity: l.selected ? 1 : .6,
1938
- children: [
1939
- /* @__PURE__ */ jsx("line", {
1940
- x1,
1941
- x2,
1942
- y1: y,
1943
- y2: y
1944
- }),
1945
- /* @__PURE__ */ jsx("line", {
1946
- x1,
1947
- x2: x1,
1948
- y1: y - 5,
1949
- y2: y + 5
1950
- }),
1951
- Number.isFinite(r.high) && r.high <= h.to && /* @__PURE__ */ jsx("line", {
1952
- x1: x2,
1953
- x2,
1954
- y1: y - 5,
1955
- y2: y + 5
1956
- })
1957
- ]
1958
- }, `${lineName(l)}/${kind}/range`);
1959
- })),
1960
- h.lines.flatMap((l) => [[
1961
- "target",
1962
- l.target,
1963
- l.targetRange,
1964
- model.thresholds.target
1965
- ], [
1966
- "full",
1967
- l.full,
1968
- l.fullRange,
1969
- model.thresholds.full
1970
- ]].map(([kind, x, r, u]) => x != null && Number.isFinite(x) && x >= h.from && x <= h.to ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("circle", {
1971
- "data-crossing": kind,
1972
- "data-scenario": lineName(l),
1973
- "data-multiple": x,
1974
- cx: lx(x),
1975
- cy: ly(u),
1976
- r: "4",
1977
- fill: scenarioColor(model, l.label),
1978
- stroke: "var(--lm-surface)",
1979
- strokeWidth: "2"
1980
- }), l.selected && mark(r && l0(r) ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax), lx(r && l0(r) ? Math.max(h.from, r.low) : x), ly(u) - 8)] }, `${lineName(l)}/${kind}`) : null)),
1981
- hx != null && /* @__PURE__ */ jsx("line", {
1982
- x1: lx(hx),
1983
- x2: lx(hx),
1984
- y1: m.t,
1985
- y2: m.t + ph,
1986
- stroke: "var(--lm-fg)",
1987
- strokeOpacity: ".8"
1580
+ h.lines.flatMap((l) => [[
1581
+ "target",
1582
+ l.targetRange,
1583
+ model.thresholds.target
1584
+ ], [
1585
+ "full",
1586
+ l.fullRange,
1587
+ model.thresholds.full
1588
+ ]].map(([kind, r, u]) => {
1589
+ if (!l.band || !r || !Number.isFinite(r.low) || r.low > h.to) return null;
1590
+ const [x1, x2] = [lx(Math.max(h.from, r.low)), lx(Math.min(h.to, r.high))];
1591
+ const y = ly(u);
1592
+ return /* @__PURE__ */ jsxs("g", {
1593
+ "data-range": kind,
1594
+ "data-scenario": lineName(l),
1595
+ "data-low": r.low,
1596
+ "data-high": r.high,
1597
+ stroke: scenarioColor(model, l.label),
1598
+ strokeWidth: l.selected ? 3 : 2,
1599
+ strokeOpacity: l.selected ? 1 : .6,
1600
+ children: [
1601
+ /* @__PURE__ */ jsx("line", {
1602
+ x1,
1603
+ x2,
1604
+ y1: y,
1605
+ y2: y
1606
+ }),
1607
+ /* @__PURE__ */ jsx("line", {
1608
+ x1,
1609
+ x2: x1,
1610
+ y1: y - 5,
1611
+ y2: y + 5
1612
+ }),
1613
+ Number.isFinite(r.high) && r.high <= h.to && /* @__PURE__ */ jsx("line", {
1614
+ x1: x2,
1615
+ x2,
1616
+ y1: y - 5,
1617
+ y2: y + 5
1618
+ })
1619
+ ]
1620
+ }, `${lineName(l)}/${kind}/range`);
1621
+ })),
1622
+ h.lines.flatMap((l) => [[
1623
+ "target",
1624
+ l.target,
1625
+ l.targetRange,
1626
+ model.thresholds.target
1627
+ ], [
1628
+ "full",
1629
+ l.full,
1630
+ l.fullRange,
1631
+ model.thresholds.full
1632
+ ]].map(([kind, x, r, u]) => x != null && Number.isFinite(x) && x >= h.from && x <= h.to ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("circle", {
1633
+ "data-crossing": kind,
1634
+ "data-scenario": lineName(l),
1635
+ "data-multiple": x,
1636
+ cx: lx(x),
1637
+ cy: ly(u),
1638
+ r: "4",
1639
+ fill: scenarioColor(model, l.label),
1640
+ stroke: "var(--lm-surface)",
1641
+ strokeWidth: "2"
1642
+ }), l.selected && mark(r && l0(r) ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax), lx(r && l0(r) ? Math.max(h.from, r.low) : x), ly(u) - 8)] }, `${lineName(l)}/${kind}`) : null)),
1643
+ hx != null && /* @__PURE__ */ jsx("line", {
1644
+ x1: lx(hx),
1645
+ x2: lx(hx),
1646
+ y1: m.t,
1647
+ y2: m.t + ph,
1648
+ stroke: "var(--lm-fg)",
1649
+ strokeOpacity: ".8"
1650
+ }),
1651
+ /* @__PURE__ */ jsx("rect", {
1652
+ x: m.l,
1653
+ y: m.t,
1654
+ width: pw,
1655
+ height: ph,
1656
+ fill: "transparent",
1657
+ onPointerMove: onMove,
1658
+ onPointerDown: onMove,
1659
+ onPointerLeave: () => setHover(null)
1660
+ })
1661
+ ]
1662
+ }), hover != null && hx != null && /* @__PURE__ */ jsxs("div", {
1663
+ className: "lm-tip",
1664
+ role: "status",
1665
+ ref: tip,
1666
+ style: {
1667
+ left: lx(hx) + 10,
1668
+ top: m.t
1669
+ },
1670
+ children: [
1671
+ /* @__PURE__ */ jsxs("b", { children: [
1672
+ fmt(hx),
1673
+ "×",
1674
+ when(model, hx) && ` · ${when(model, hx)}`
1675
+ ] }),
1676
+ h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [
1677
+ /* @__PURE__ */ jsx("b", {
1678
+ className: "lm-key",
1679
+ style: { background: scenarioColor(model, l.label) }
1680
+ }),
1681
+ /* @__PURE__ */ jsx("strong", { children: l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1]) }),
1682
+ " ",
1683
+ lineName(l)
1684
+ ] }, lineName(l))),
1685
+ selected?.components.map((c) => /* @__PURE__ */ jsxs("span", {
1686
+ className: "lm-sub",
1687
+ children: [
1688
+ /* @__PURE__ */ jsx("strong", { children: c.points[hover][1] == null ? "off" : pct(c.points[hover][1]) }),
1689
+ " ",
1690
+ c.name
1691
+ ]
1692
+ }, c.id))
1693
+ ]
1694
+ })]
1695
+ })
1696
+ ]
1697
+ });
1698
+ }
1699
+ // src/track.ts
1700
+ /**
1701
+ * The load as a place on the slider, 0 to 1, and back, snapped to the load's step. A load that spans ten times or more
1702
+ * is on a log scale, as the headroom chart is, so today, the target and where it runs out do not crowd its first tenth.
1703
+ */
1704
+ function loadScale({ min, max, step }) {
1705
+ const log = min > 0 && max >= min * 10;
1706
+ const f = log ? Math.log : (x) => x;
1707
+ const lo = f(min);
1708
+ const span = f(max) - lo || 1;
1709
+ return {
1710
+ at: (x) => (f(Math.min(max, Math.max(min, x))) - lo) / span,
1711
+ of: (t) => {
1712
+ const x = log ? Math.exp(lo + t * span) : lo + t * span;
1713
+ return Math.min(max, Math.max(min, Number((min + Math.round((x - min) / step) * step).toPrecision(12))));
1714
+ }
1715
+ };
1716
+ }
1717
+ /** The presets that set the load, in their order; a derived one says its own multiple, which the step rounds down. */
1718
+ function marksOf(presets, full, { step, max }, fmt) {
1719
+ return presets.flatMap((p) => {
1720
+ const load = p.values.load;
1721
+ if (load == null) return [];
1722
+ return [{
1723
+ preset: p,
1724
+ load,
1725
+ text: p.derived && p.label.split(" · ")[1] || `${fmt(load)}×`,
1726
+ kind: !p.derived ? "preset" : full && load >= Math.min(max, Math.floor(full.low / step) * step) - 1e-9 ? "full" : "target"
1727
+ }];
1728
+ });
1729
+ }
1730
+ /** The slider's zones: under the target, past it, past capacity; a ± range is the blend between its two edges. */
1731
+ function zones(target, full, at) {
1732
+ const p = (x) => `${(at(x) * 100).toFixed(2)}%`;
1733
+ const stops = ["var(--lm-ok) 0"];
1734
+ if (target) stops.push(`var(--lm-ok) ${p(target.low)}`, `var(--lm-warn) ${p(target.high)}`);
1735
+ if (full) stops.push(`var(--lm-${target ? "warn" : "ok"}) ${p(full.low)}`, `var(--lm-drop) ${p(full.high)}`);
1736
+ return `linear-gradient(to right, ${stops.join(", ")})`;
1737
+ }
1738
+ /**
1739
+ * Which marks keep their label on a track this wide, the rest keeping their tick: the crossings first, then the
1740
+ * presets in their order. Widths are estimated from the text, so the same track hides the same labels on any machine.
1741
+ */
1742
+ function labelled(marks, at, width) {
1743
+ const room = (m) => m.text.length * 7 + 8;
1744
+ const order = marks.map((_, i) => i).sort((a, b) => Number(marks[a].kind === "preset") - Number(marks[b].kind === "preset"));
1745
+ const kept = [];
1746
+ const out = marks.map(() => false);
1747
+ for (const i of order) {
1748
+ const x = at(marks[i].load) * width;
1749
+ const w = room(marks[i]);
1750
+ const left = Math.min(Math.max(0, x - w / 2), width - w);
1751
+ if (kept.some(([l, r]) => left < r && left + w > l)) continue;
1752
+ kept.push([left, left + w]);
1753
+ out[i] = true;
1754
+ }
1755
+ return out;
1756
+ }
1757
+ // src/panels.tsx
1758
+ /** The model's one-sentence answer for the current values, and which capacity to measure when it is unsure. */
1759
+ function Verdict({ lm }) {
1760
+ const { measure } = lm.ev;
1761
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
1762
+ className: "lm-verdict",
1763
+ "data-tier": lm.ev.verdict.tier,
1764
+ "aria-live": "polite",
1765
+ children: lm.ev.verdict.text
1766
+ }), measure && /* @__PURE__ */ jsx("p", {
1767
+ className: "lm-measure",
1768
+ "data-component": measure.component,
1769
+ children: measure.text
1770
+ })] });
1771
+ }
1772
+ /** "±30 %" for a capacity with a range. */
1773
+ const plusMinus = (c) => c?.within ? `±${pct(c.within)}` : "";
1774
+ /** Each component's utilization in the order they reach the target, with where they cross it and 100 %. */
1775
+ function Limits({ lm, title = "Where it runs out, in order" }) {
1776
+ const { ev, model } = lm;
1777
+ const top = Math.max(1.5, model.thresholds.full * 1.5);
1778
+ const at = (u) => `${u / top * 100}%`;
1779
+ const span = (r, x) => r ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax);
1780
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1781
+ /* @__PURE__ */ jsx("h3", { children: title }),
1782
+ /* @__PURE__ */ jsxs("div", {
1783
+ className: "lm-scale",
1784
+ "aria-hidden": "true",
1785
+ children: [
1786
+ /* @__PURE__ */ jsx("span", {}),
1787
+ /* @__PURE__ */ jsxs("div", { children: [
1788
+ /* @__PURE__ */ jsx("span", {
1789
+ style: {
1790
+ left: 0,
1791
+ transform: "none"
1792
+ },
1793
+ children: "0"
1794
+ }),
1795
+ /* @__PURE__ */ jsxs("span", {
1796
+ style: { left: at(model.thresholds.target) },
1797
+ children: [pct(model.thresholds.target), " target"]
1798
+ }),
1799
+ /* @__PURE__ */ jsx("span", {
1800
+ style: { left: at(model.thresholds.full) },
1801
+ children: pct(model.thresholds.full)
1802
+ }),
1803
+ /* @__PURE__ */ jsx("span", {
1804
+ style: {
1805
+ left: "100%",
1806
+ transform: "translateX(-100%)"
1807
+ },
1808
+ children: pct(top)
1809
+ })
1810
+ ] }),
1811
+ /* @__PURE__ */ jsx("span", {})
1812
+ ]
1813
+ }),
1814
+ /* @__PURE__ */ jsx("div", {
1815
+ className: "lm-limits",
1816
+ children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
1817
+ className: "lm-lim",
1818
+ "data-component": c.id,
1819
+ children: [
1820
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("b", { children: [
1821
+ c.name,
1822
+ c === ev.firstLimit && /* @__PURE__ */ jsx("span", {
1823
+ className: "lm-tag",
1824
+ "data-kind": "first",
1825
+ children: "limit"
1826
+ }),
1827
+ c.capacity?.provenance === "estimated" ? /* @__PURE__ */ jsxs("span", {
1828
+ className: "lm-tag",
1829
+ "data-kind": "estimated",
1830
+ children: ["estimate", c.capacity.within ? ` ${plusMinus(c.capacity)}` : ""]
1831
+ }) : !!c.capacity?.within && /* @__PURE__ */ jsx("span", {
1832
+ className: "lm-tag",
1833
+ "data-kind": "range",
1834
+ children: plusMinus(c.capacity)
1835
+ })
1836
+ ] }), /* @__PURE__ */ jsx("span", {
1837
+ className: "lm-sub",
1838
+ children: c.describe ?? (c.capacity ? `${fmt(c.capacity.value)} ${c.capacity.unit}` : "switched off")
1839
+ })] }),
1840
+ /* @__PURE__ */ jsxs("div", {
1841
+ className: "lm-track",
1842
+ role: "img",
1843
+ "aria-label": `${c.name} at ${c.util == null ? "off" : pct(c.util)}`,
1844
+ children: [
1845
+ /* @__PURE__ */ jsx("div", {
1846
+ className: "lm-fill",
1847
+ "data-state": c.state,
1848
+ style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
1849
+ }),
1850
+ /* @__PURE__ */ jsx("div", {
1851
+ className: "lm-tick",
1852
+ style: { left: at(model.thresholds.target) }
1853
+ }),
1854
+ /* @__PURE__ */ jsx("div", {
1855
+ className: "lm-tick",
1856
+ style: { left: at(model.thresholds.full) }
1857
+ })
1858
+ ]
1859
+ }),
1860
+ /* @__PURE__ */ jsxs("div", {
1861
+ className: "lm-val",
1862
+ children: [c.util == null ? "—" : `${pct(c.util)} · ${num(c.demand ?? 0)} ${c.capacity?.unit ?? ""}`, /* @__PURE__ */ jsx("small", { children: c.util == null ? "switched off" : `${pct(model.thresholds.target)} at ${span(c.targetRange, c.target)} · full at ${span(c.fullRange, c.full)}` })]
1863
+ })
1864
+ ]
1865
+ }, c.id))
1866
+ })
1867
+ ] });
1868
+ }
1869
+ /**
1870
+ * Live numbers: from the sim, lag and drops per queue, busy workers, rejected requests; from the model, pods running,
1871
+ * cache answers and retries.
1872
+ */
1873
+ function Meters({ lm }) {
1874
+ const [, tick] = useState(0);
1875
+ useEffect(() => {
1876
+ const t = setInterval(() => tick((x) => x + 1), 250);
1877
+ return () => clearInterval(t);
1878
+ }, []);
1879
+ const { ev, engine, model } = lm;
1880
+ const sim = engine.sim;
1881
+ const flowLabel = (f) => model.def.flows[f]?.label ?? f;
1882
+ const items = [];
1883
+ for (const s of Object.values(ev.stages)) {
1884
+ if (s.kind === "queue") for (const f of model.flowIds.filter((x) => ev.routes[x]?.includes(s.id))) {
1885
+ const q = sim.queue(s.id, f);
1886
+ const rules = ev.overload[f] ?? {};
1887
+ items.push({
1888
+ key: `${s.id}/${f}/lag`,
1889
+ value: secs(q.lag),
1890
+ label: `${flowLabel(f)} lag in ${s.label}`,
1891
+ state: q.lag > 60 ? "over" : q.lag > 5 ? "warn" : "ok"
1892
+ });
1893
+ if (rules.merge) items.push({
1894
+ key: `${s.id}/${f}/merge`,
1895
+ value: compact(q.merged),
1896
+ label: `${flowLabel(f)} superseded /s (${rules.merge.reason ?? "newest kept"})`,
1897
+ state: q.merged > .5 ? "warn" : "ok"
1898
+ });
1899
+ if (rules.drop) items.push({
1900
+ key: `${s.id}/${f}/drop`,
1901
+ value: compact(q.dropped),
1902
+ label: `${flowLabel(f)} dropped /s (${rules.drop.reason ?? "too old"})`,
1903
+ state: q.dropped > .5 ? "over" : "ok"
1904
+ });
1905
+ }
1906
+ if (s.kind === "workers") {
1907
+ const b = sim.busy(s.id);
1908
+ items.push({
1909
+ key: `${s.id}/busy`,
1910
+ value: pct(b),
1911
+ label: `${s.label} busy`,
1912
+ state: b > .95 ? "over" : b > .5 ? "warn" : "ok"
1913
+ });
1914
+ if (s.autoscale) items.push({
1915
+ key: `${s.id}/pods`,
1916
+ value: `${s.running} of ${s.pods}`,
1917
+ label: `${s.label} pods running`,
1918
+ state: s.running < s.pods ? "ok" : (ev.components[s.component]?.util ?? 0) > model.thresholds.full ? "over" : "warn"
1919
+ });
1920
+ }
1921
+ if (s.kind === "cache") items.push({
1922
+ key: `${s.id}/hits`,
1923
+ value: compact(sim.arriving(s.id) * (1 - sim.shed(s.id)) * s.hit),
1924
+ label: `answered at ${s.label} /s (${pct(s.hit)} hits)`,
1925
+ state: "ok"
1926
+ });
1927
+ if ((s.kind === "pass" || s.kind === "limit" || s.kind === "cache") && sim.shed(s.id) > 0) items.push({
1928
+ key: `${s.id}/shed`,
1929
+ value: pct(sim.shed(s.id)),
1930
+ label: `rejected at ${s.label}`,
1931
+ state: "over"
1932
+ });
1933
+ }
1934
+ for (const f of model.flowIds) {
1935
+ const r = ev.retry[f];
1936
+ if (!r || !(r.rate > 0)) continue;
1937
+ const per = r.attempts / r.rate;
1938
+ items.push({
1939
+ key: `${f}/attempts`,
1940
+ value: `${fmt(per)}×`,
1941
+ label: `${flowLabel(f)} attempts per ${model.def.flows[f]?.unit ?? "unit"}`,
1942
+ state: per > 1.05 ? "warn" : "ok"
1943
+ });
1944
+ items.push({
1945
+ key: `${f}/failed`,
1946
+ value: pct(r.failed),
1947
+ label: `${flowLabel(f)} failing after ${r.times} ${r.times === 1 ? "retry" : "retries"}`,
1948
+ state: r.failed > .005 ? "over" : "ok"
1949
+ });
1950
+ }
1951
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Live" }), /* @__PURE__ */ jsx("div", {
1952
+ className: "lm-meters",
1953
+ children: items.map((m) => /* @__PURE__ */ jsxs("div", {
1954
+ className: "lm-meter",
1955
+ "data-state": m.state,
1956
+ children: [/* @__PURE__ */ jsx("b", { children: m.value }), /* @__PURE__ */ jsx("span", {
1957
+ title: m.label,
1958
+ children: m.label
1959
+ })]
1960
+ }, m.key))
1961
+ })] });
1962
+ }
1963
+ /** A preset's values are the shown ones. */
1964
+ const isOn = (lm, p) => Object.entries(p.values).every(([k, x]) => lm.values[k] === x);
1965
+ /**
1966
+ * The load slider: its label, the load with its date, and a track coloured by what the load does (under the target,
1967
+ * past it, past capacity). Under it, a mark for each preset that sets the load, which a click takes; ← → move a
1968
+ * step, Page Up and Page Down to the next mark. A load that spans ten times or more is on a log scale.
1969
+ */
1970
+ function LoadRange({ lm }) {
1971
+ const { model, ev } = lm;
1972
+ const load = model.load;
1973
+ const x = lm.values.load;
1974
+ const id = useId();
1975
+ const [box, { width }] = useSize(240);
1976
+ const { at, of } = loadScale(load);
1977
+ const marks = marksOf(ev.presets, ev.full, load, fmt);
1978
+ const shown = labelled(marks, at, width);
1979
+ const set = (to) => lm.setValues({ load: of(at(to)) });
1980
+ const key = (e) => {
1981
+ const by = {
1982
+ ArrowRight: 1,
1983
+ ArrowUp: 1,
1984
+ ArrowLeft: -1,
1985
+ ArrowDown: -1
1986
+ }[e.key];
1987
+ const loads = marks.map((m) => m.load).sort((a, b) => a - b);
1988
+ const to = by ? x + by * load.step : e.key === "PageUp" ? loads.find((l) => l > x) ?? load.max : e.key === "PageDown" ? loads.findLast((l) => l < x) ?? load.min : e.key === "Home" ? load.min : e.key === "End" ? load.max : null;
1989
+ if (to == null) return;
1990
+ e.preventDefault();
1991
+ set(to);
1992
+ };
1993
+ const date = when(model, x);
1994
+ const wide = Math.max(...[
1995
+ load.min,
1996
+ load.max,
1997
+ load.min + load.step
1998
+ ].map((n) => fmt(n).length)) + 1;
1999
+ return /* @__PURE__ */ jsxs("div", {
2000
+ className: "lm-range lm-load",
2001
+ children: [
2002
+ /* @__PURE__ */ jsx("label", {
2003
+ htmlFor: id,
2004
+ title: load.label,
2005
+ children: load.label
2006
+ }),
2007
+ /* @__PURE__ */ jsxs("output", {
2008
+ htmlFor: id,
2009
+ style: { minWidth: `${Math.max(wide, date ? 6 : 0)}ch` },
2010
+ children: [
2011
+ fmt(x),
2012
+ "×",
2013
+ date && /* @__PURE__ */ jsx("small", { children: date })
2014
+ ]
2015
+ }),
2016
+ /* @__PURE__ */ jsxs("div", {
2017
+ className: "lm-load-track",
2018
+ style: { "--lm-at": at(x) },
2019
+ children: [
2020
+ /* @__PURE__ */ jsx("input", {
2021
+ id,
2022
+ type: "range",
2023
+ min: 0,
2024
+ max: 1,
2025
+ step: "any",
2026
+ value: at(x),
2027
+ "aria-valuetext": `${fmt(x)}×${date ? `, ${date}` : ""}`,
2028
+ onChange: (e) => set(of(Number(e.target.value))),
2029
+ onKeyDown: key
2030
+ }),
2031
+ /* @__PURE__ */ jsx("i", {
2032
+ className: "lm-zones",
2033
+ style: { background: zones(ev.target, ev.full, at) }
2034
+ }),
2035
+ /* @__PURE__ */ jsx("div", {
2036
+ className: "lm-marks",
2037
+ ref: box,
2038
+ children: marks.map((m, i) => /* @__PURE__ */ jsx("button", {
2039
+ type: "button",
2040
+ "data-kind": m.kind,
2041
+ "data-label": shown[i] || void 0,
2042
+ style: { left: `${at(m.load) * 100}%` },
2043
+ title: m.preset.label,
2044
+ "aria-label": m.preset.label,
2045
+ "aria-pressed": isOn(lm, m.preset),
2046
+ onClick: () => lm.setValues(m.preset.values),
2047
+ children: /* @__PURE__ */ jsx("span", { children: m.text })
2048
+ }, m.preset.label))
2049
+ })
2050
+ ]
2051
+ })
2052
+ ]
2053
+ });
2054
+ }
2055
+ /**
2056
+ * The scenarios and the load in one bar, above the diagram: the reader moves the load and watches what it does. It
2057
+ * stays in view while the page scrolls (under `--lm-sticky-top`, for a page's own fixed header); on a phone it sits
2058
+ * under the diagram, in thumb reach.
2059
+ */
2060
+ function LoadBar({ lm }) {
2061
+ return /* @__PURE__ */ jsxs("div", {
2062
+ className: "lm-loadbar",
2063
+ children: [/* @__PURE__ */ jsx(Scenarios, { lm }), /* @__PURE__ */ jsx(LoadRange, { lm })]
2064
+ });
2065
+ }
2066
+ /**
2067
+ * The load slider (unless `load` is false: the page shows a `LoadBar`), the presets that set no load, and every
2068
+ * parameter, greyed out where it does not apply.
2069
+ */
2070
+ function Controls({ lm, load = true }) {
2071
+ const { model, values, setValues, ev } = lm;
2072
+ const v = values;
2073
+ const presets = ev.presets.filter((p) => !("load" in p.values));
2074
+ return /* @__PURE__ */ jsxs("div", {
2075
+ className: "lm-card lm-controls",
2076
+ children: [
2077
+ load && /* @__PURE__ */ jsx("h3", { children: "Load" }),
2078
+ load && /* @__PURE__ */ jsx(LoadRange, { lm }),
2079
+ presets.length > 0 && /* @__PURE__ */ jsx("div", {
2080
+ className: "lm-presets",
2081
+ children: presets.map((p) => /* @__PURE__ */ jsx("button", {
2082
+ type: "button",
2083
+ "aria-pressed": isOn(lm, p),
2084
+ onClick: () => setValues(p.values),
2085
+ children: p.label
2086
+ }, p.label))
2087
+ }),
2088
+ model.params.length > 1 && /* @__PURE__ */ jsx("h3", { children: "Design" }),
2089
+ model.params.map(({ id, def }) => {
2090
+ if (def.kind === "load") return null;
2091
+ const enabled = model.isEnabled(id, v);
2092
+ const tag = def.tag && /* @__PURE__ */ jsx("span", {
2093
+ className: "lm-tag",
2094
+ "data-kind": "estimated",
2095
+ children: def.tag
2096
+ });
2097
+ if (def.kind === "switch") return /* @__PURE__ */ jsxs("label", {
2098
+ className: `lm-switch${enabled ? "" : " lm-off"}`,
2099
+ children: [
2100
+ /* @__PURE__ */ jsx("input", {
2101
+ type: "checkbox",
2102
+ checked: Boolean(v[id]),
2103
+ disabled: !enabled,
2104
+ onChange: (e) => setValues({ [id]: e.target.checked })
2105
+ }),
2106
+ /* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
2107
+ def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
2108
+ ]
2109
+ }, id);
2110
+ if (def.kind === "select") return /* @__PURE__ */ jsxs("label", {
2111
+ className: `lm-select${enabled ? "" : " lm-off"}`,
2112
+ children: [
2113
+ /* @__PURE__ */ jsxs("span", { children: [def.label, tag] }),
2114
+ /* @__PURE__ */ jsx("select", {
2115
+ value: String(v[id]),
2116
+ disabled: !enabled,
2117
+ onChange: (e) => {
2118
+ const opt = def.options.find((o) => String(o) === e.target.value);
2119
+ setValues({ [id]: opt });
2120
+ },
2121
+ children: def.options.map((o) => /* @__PURE__ */ jsx("option", {
2122
+ value: String(o),
2123
+ children: def.format ? def.format(o) : String(o)
2124
+ }, String(o)))
1988
2125
  }),
1989
- /* @__PURE__ */ jsx("rect", {
1990
- x: m.l,
1991
- y: m.t,
1992
- width: pw,
1993
- height: ph,
1994
- fill: "transparent",
1995
- onPointerMove: onMove,
1996
- onPointerDown: onMove,
1997
- onPointerLeave: () => setHover(null)
1998
- })
2126
+ def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
1999
2127
  ]
2000
- }), hover != null && hx != null && /* @__PURE__ */ jsxs("div", {
2001
- className: "lm-tip",
2002
- role: "status",
2003
- ref: tip,
2004
- style: {
2005
- left: lx(hx) + 10,
2006
- top: m.t
2007
- },
2128
+ }, id);
2129
+ return /* @__PURE__ */ jsxs("label", {
2130
+ className: `lm-range${enabled ? "" : " lm-off"}`,
2008
2131
  children: [
2009
- /* @__PURE__ */ jsxs("b", { children: [
2010
- fmt(hx),
2011
- "×",
2012
- when(model, hx) && ` · ${when(model, hx)}`
2013
- ] }),
2014
- h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [
2015
- /* @__PURE__ */ jsx("b", {
2016
- className: "lm-key",
2017
- style: { background: scenarioColor(model, l.label) }
2018
- }),
2019
- /* @__PURE__ */ jsx("strong", { children: l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1]) }),
2132
+ /* @__PURE__ */ jsxs("span", { children: [
2133
+ def.label,
2134
+ tag,
2020
2135
  " ",
2021
- lineName(l)
2022
- ] }, lineName(l))),
2023
- selected?.components.map((c) => /* @__PURE__ */ jsxs("span", {
2024
- className: "lm-sub",
2025
- children: [
2026
- /* @__PURE__ */ jsx("strong", { children: c.points[hover][1] == null ? "off" : pct(c.points[hover][1]) }),
2027
- " ",
2028
- c.name
2029
- ]
2030
- }, c.id))
2136
+ /* @__PURE__ */ jsx("output", { children: def.format ? def.format(v[id]) : fmt(v[id]) })
2137
+ ] }),
2138
+ /* @__PURE__ */ jsx("input", {
2139
+ type: "range",
2140
+ min: def.min,
2141
+ max: def.max,
2142
+ step: def.step,
2143
+ value: v[id],
2144
+ disabled: !enabled,
2145
+ onChange: (e) => setValues({ [id]: Number(e.target.value) })
2146
+ }),
2147
+ def.hint && /* @__PURE__ */ jsx("small", { children: def.hint })
2031
2148
  ]
2032
- })]
2149
+ }, id);
2033
2150
  })
2034
2151
  ]
2035
2152
  });
2036
2153
  }
2154
+ /** What the model assumes: every capacity with its provenance, every fit, and anything the page adds. */
2155
+ function Assumptions({ lm, extra = [] }) {
2156
+ return /* @__PURE__ */ jsxs("div", {
2157
+ className: "lm-card",
2158
+ children: [/* @__PURE__ */ jsx("h3", { children: "What this assumes" }), /* @__PURE__ */ jsxs("ul", {
2159
+ className: "lm-facts",
2160
+ 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}`))]
2161
+ })]
2162
+ });
2163
+ }
2164
+ function describe(a) {
2165
+ if (a.kind === "capacity") {
2166
+ const c = a.capacity;
2167
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2168
+ /* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
2169
+ " ",
2170
+ fmt(c.value),
2171
+ " ",
2172
+ c.unit,
2173
+ c.within ? ` ${plusMinus(c)}` : "",
2174
+ ",",
2175
+ " ",
2176
+ /* @__PURE__ */ jsx("span", {
2177
+ className: "lm-prov",
2178
+ "data-kind": c.provenance,
2179
+ children: c.provenance
2180
+ }),
2181
+ c.source ? ` (${c.source})` : "",
2182
+ "."
2183
+ ] });
2184
+ }
2185
+ const f = a.fit;
2186
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2187
+ /* @__PURE__ */ jsxs("b", { children: [a.name, ":"] }),
2188
+ " ",
2189
+ f.y,
2190
+ " = ",
2191
+ sig(f.a),
2192
+ " + ",
2193
+ sig(f.b),
2194
+ " × ",
2195
+ f.x,
2196
+ ", r² ",
2197
+ f.r2.toFixed(3),
2198
+ " over ",
2199
+ f.n,
2200
+ " points,",
2201
+ " ",
2202
+ /* @__PURE__ */ jsx("span", {
2203
+ className: "lm-prov",
2204
+ "data-kind": "measured",
2205
+ children: "measured"
2206
+ }),
2207
+ f.source ? ` (${f.source})` : "",
2208
+ "."
2209
+ ] });
2210
+ }
2211
+ /** Exact below 1,000 (3.9 cores), compact above (12k req/s). */
2212
+ const num = (x) => Math.abs(x) >= 1e3 ? compact(x) : fmt(x);
2213
+ const sig = (x) => Number(x.toPrecision(3)).toString();
2037
2214
  // src/story.tsx
2038
2215
  /**
2039
2216
  * The model's story, a step at a time: the step's text, where it is, play, back and next. ← and → move through it
@@ -2208,9 +2385,10 @@ const LOADMAP_CSS = `
2208
2385
  .lm[data-full="overlay"] { position: fixed; inset: 0; z-index: 2147483000; width: auto; max-width: none; max-height: none; margin: 0; border: 0; }
2209
2386
  .lm[data-full] > * { flex: none; }
2210
2387
  /* a page of its own keeps the rest outside full screen, as <Loadmap> does */
2211
- .lm[data-full] > :not(.lm-head, h2, .lm-scenarios, .lm-story, .lm-wrap, .lm-line, .lm-dock, .lm-side) { display: none; }
2388
+ .lm[data-full] > :not(.lm-head, h2, .lm-scenarios, .lm-loadbar, .lm-story, .lm-wrap, .lm-line, .lm-dock, .lm-side) { display: none; }
2212
2389
  .lm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; min-width: 0; }
2213
2390
  .lm-head h2 { font-size: 1.1rem; }
2391
+ .lm-head .lm-loadbar { flex: 1 1 520px; }
2214
2392
  .lm[data-full] .lm-wrap { gap: 6px; }
2215
2393
  /* the board as large as fits (--lm-fit, from Diagram), left under the bar, so the legend starts where the board does */
2216
2394
  .lm[data-full] .lm-board { width: var(--lm-fit, 100%); margin: 0; align-self: start; justify-self: start; }
@@ -2227,9 +2405,6 @@ const LOADMAP_CSS = `
2227
2405
  .lm-headline { flex: 1 1 auto; min-width: 0; margin: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2228
2406
  .lm-num { font: 600 .95em var(--lm-mono); font-variant-numeric: tabular-nums; }
2229
2407
  .lm-link { font: 500 .8rem var(--lm-font); color: var(--lm-accent); background: none; border: 0; padding: 2px 4px; cursor: pointer; white-space: nowrap; }
2230
- .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; }
2231
- .lm-line output { font-family: var(--lm-mono); font-variant-numeric: tabular-nums; }
2232
- .lm-line input[type=range] { width: 100%; accent-color: var(--lm-accent); }
2233
2408
 
2234
2409
  .lm-dock { display: flex; gap: 10px; min-width: 0; }
2235
2410
  .lm[data-full] > .lm-dock { flex: 1 1 0; min-height: clamp(200px, 26dvh, 340px); }
@@ -2267,7 +2442,7 @@ const LOADMAP_CSS = `
2267
2442
  .lm-mini .lm-presets button { padding: 2px 8px; font-size: .72rem; }
2268
2443
  @container (min-width: 420px) {
2269
2444
  .lm-mini .lm-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
2270
- .lm-mini .lm-controls > :is(h3, .lm-presets), .lm-mini .lm-controls > h3 + .lm-range { grid-column: 1 / -1; }
2445
+ .lm-mini .lm-controls > :is(h3, .lm-presets) { grid-column: 1 / -1; }
2271
2446
  }
2272
2447
  .lm-mini .lm-compare > :not(h3:first-child, .lm-table-wrap:nth-child(3)) { display: none; }
2273
2448
  .lm-mini .lm-table { font-size: .76rem; }
@@ -2293,7 +2468,7 @@ const LOADMAP_CSS = `
2293
2468
  .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; }
2294
2469
 
2295
2470
  /* focus: the board and what runs on it in the middle of the screen */
2296
- .lm[data-mode="focus"] .lm-scenarios, .lm[data-mode="focus"] > .lm-side:not(.lm-drawer) { display: none; }
2471
+ .lm[data-mode="focus"] > .lm-side:not(.lm-drawer) { display: none; }
2297
2472
  .lm[data-mode="focus"] > .lm-wrap { margin-top: auto; }
2298
2473
  .lm[data-mode="focus"] > :is(.lm-story, .lm-line) { order: 1; }
2299
2474
  .lm[data-mode="focus"]::after { content: ""; order: 2; margin-top: auto; }
@@ -2316,11 +2491,24 @@ const LOADMAP_CSS = `
2316
2491
  .lm[data-full] .lm-story button { padding: 4px 10px; }
2317
2492
  .lm[data-full] .lm-headline { flex-basis: 100%; }
2318
2493
  .lm-dock { flex-direction: column; min-height: 0; gap: 6px; }
2494
+ /* the load bar takes some of the dock's room: the load is no longer in a card */
2495
+ .lm[data-full] > .lm-dock { min-height: clamp(170px, 22dvh, 340px); }
2319
2496
  .lm-tabs { display: flex; flex: none; gap: 2px; border-bottom: 1px solid var(--lm-line); overflow: hidden; }
2320
2497
  .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; }
2321
2498
  .lm-tabs button[aria-pressed="true"] { color: var(--lm-fg); border-color: var(--lm-fg); }
2322
2499
  .lm-mini:not([data-active]) { display: none; }
2323
2500
  .lm[data-full] > .lm-side[data-drawer] { inset: 8px; width: auto; }
2501
+ /* the load in thumb reach: the bar under the board and the story, over the verdict */
2502
+ .lm[data-full] .lm-head { display: contents; }
2503
+ .lm[data-full] .lm-loadbar { order: 2; flex: none; }
2504
+ /* two lines, so the board keeps its room: the scenarios and the load's value, then the track; the label names the
2505
+ slider unseen */
2506
+ .lm[data-full] .lm-load small { display: none; }
2507
+ .lm[data-full] .lm-load { display: contents; }
2508
+ .lm[data-full] :is(.lm-loadbar legend, .lm-load > label) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
2509
+ .lm[data-full] .lm-load > output { margin-left: auto; }
2510
+ .lm[data-full] .lm-load-track { flex: 1 1 100%; }
2511
+ .lm[data-full] > :is(.lm-line, .lm-dock) { order: 3; }
2324
2512
  }
2325
2513
 
2326
2514
  .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; }
@@ -2401,6 +2589,35 @@ const LOADMAP_CSS = `
2401
2589
  .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; }
2402
2590
  .lm-story button[aria-disabled="true"] { opacity: .45; cursor: default; }
2403
2591
  .lm-own { font-size: .78rem; color: var(--lm-muted); }
2592
+
2593
+ /* the scenarios and the load over the board, in view while the page scrolls; on a phone under the board */
2594
+ .lm-loadbar { position: sticky; top: var(--lm-sticky-top, 0px); z-index: 3; container-type: inline-size; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; padding: 6px 12px 2px; background: var(--lm-surface); border: 1px solid var(--lm-line); border-radius: 8px; box-shadow: 0 4px 14px -10px rgb(0 0 0 / .4); }
2595
+ .lm-loadbar .lm-scenarios { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; padding: 2px; }
2596
+ .lm-loadbar .lm-scenarios button { flex: none; white-space: nowrap; }
2597
+ .lm-loadbar .lm-load { flex: 1 1 300px; }
2598
+ @container (min-width: 720px) {
2599
+ .lm-loadbar .lm-load { grid-template: "label track value" / minmax(0, max-content) minmax(160px, 1fr) auto; align-items: start; }
2600
+ .lm-loadbar .lm-load > label { max-width: 14em; padding-top: 6px; }
2601
+ }
2602
+ @container (max-width: 520px) {
2603
+ .lm:not([data-full]) > .lm-loadbar { order: 1; top: auto; bottom: 0; }
2604
+ .lm:not([data-full]) > .lm-side { order: 2; }
2605
+ }
2606
+ /* the load: its label and value, the track under them, the marks under it */
2607
+ .lm-load { display: grid; grid-template: "label value" "track track" / minmax(0, 1fr) auto; align-items: center; gap: 0 12px; font-size: .84rem; min-width: 0; }
2608
+ .lm-load > label { grid-area: label; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2609
+ .lm-load > output { grid-area: value; text-align: right; font: 600 .95rem/1.2 var(--lm-mono); font-variant-numeric: tabular-nums; }
2610
+ .lm-load small { display: block; font: 400 .7rem var(--lm-mono); color: var(--lm-muted); }
2611
+ .lm-load-track { grid-area: track; position: relative; min-width: 0; padding-bottom: 22px; }
2612
+ .lm-load input { display: block; width: 100%; height: 32px; margin: 0; accent-color: var(--lm-accent); cursor: pointer; }
2613
+ .lm-zones, .lm-marks { position: absolute; left: 8px; right: 8px; top: 30px; }
2614
+ .lm-zones { height: 4px; border-radius: 2px; }
2615
+ .lm-marks button { position: absolute; top: 0; transform: translateX(-50%); min-width: 20px; height: 24px; padding: 7px 2px 0; border: 0; background: none; font: 500 .68rem var(--lm-mono); color: var(--lm-accent); white-space: nowrap; cursor: pointer; }
2616
+ .lm-marks button::before { content: ""; position: absolute; left: 50%; top: 0; width: 2px; height: 6px; margin-left: -1px; background: currentColor; }
2617
+ .lm-marks button:not([data-label]) span { display: none; }
2618
+ .lm-marks [data-kind="target"] { color: var(--lm-warn); }
2619
+ .lm-marks [data-kind="full"] { color: var(--lm-drop); }
2620
+ .lm-marks [aria-pressed="true"] { font-weight: 700; text-decoration: underline; }
2404
2621
  .lm-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: 3px; margin-right: 6px; }
2405
2622
 
2406
2623
  .lm-compare-text { margin: 0; }
@@ -2616,7 +2833,6 @@ var Engine = class {
2616
2833
  }
2617
2834
  }
2618
2835
  bind(svg, canvas) {
2619
- const fresh = canvas !== this.canvas;
2620
2836
  this.svg = svg;
2621
2837
  this.canvas = canvas;
2622
2838
  this.#slots = [];
@@ -2628,7 +2844,6 @@ var Engine = class {
2628
2844
  y: Number(el.dataset.y),
2629
2845
  s: Number(el.dataset.s)
2630
2846
  });
2631
- if (fresh) this.resize();
2632
2847
  this.drawFills();
2633
2848
  this.applyCamera();
2634
2849
  }
@@ -2646,15 +2861,21 @@ var Engine = class {
2646
2861
  if (outcome === "superseded" || outcome === "unread") return this.colors.muted || "#5d6d7c";
2647
2862
  return this.colors.ok || "#2a7f5a";
2648
2863
  }
2649
- resize() {
2864
+ /**
2865
+ * Gives the canvas one pixel for each of the screen's: `px`, the device pixels the browser says it covers, else its
2866
+ * size × the pixel ratio. With any other size the browser stretches the dots and blurs them. Wants no scene: a board
2867
+ * that has its size before its first layout keeps it.
2868
+ */
2869
+ resize(px) {
2650
2870
  const c = this.canvas;
2651
- if (!c || !this.scene) return;
2652
- const r = c.getBoundingClientRect();
2653
- if (!r.width) return;
2654
- const dpr = Math.min(2, globalThis.devicePixelRatio || 1);
2655
- const w = Math.round(r.width * dpr);
2656
- const h = Math.round(r.height * dpr);
2657
- if (c.width === w && c.height === h) return;
2871
+ if (!c) return;
2872
+ let { width: w, height: h } = px ?? c.getBoundingClientRect();
2873
+ if (!px) {
2874
+ const dpr = globalThis.devicePixelRatio || 1;
2875
+ w = Math.round(w * dpr);
2876
+ h = Math.round(h * dpr);
2877
+ }
2878
+ if (!w || !h || c.width === w && c.height === h) return;
2658
2879
  c.width = w;
2659
2880
  c.height = h;
2660
2881
  this.draw();
@@ -3343,8 +3564,8 @@ function canvasMeasure(fontFamily) {
3343
3564
  };
3344
3565
  }
3345
3566
  // src/Loadmap.tsx
3346
- const Dock = lazy(() => import("./later-Dk7QnTxR.js").then((m) => ({ default: m.Dock })));
3347
- const VerdictLine = lazy(() => import("./later-Dk7QnTxR.js").then((m) => ({ default: m.VerdictLine })));
3567
+ const Dock = lazy(() => import("./later-B9SnId7C.js").then((m) => ({ default: m.Dock })));
3568
+ const VerdictLine = lazy(() => import("./later-B9SnId7C.js").then((m) => ({ default: m.VerdictLine })));
3348
3569
  /** What the page's own switch says, on `<html>`: `data-theme`, or a `dark` or `light` class; null when it says nothing. */
3349
3570
  function pageTheme() {
3350
3571
  if (typeof document === "undefined") return null;
@@ -3419,16 +3640,20 @@ const LOADMAP_PANELS = [
3419
3640
  "compare",
3420
3641
  "assumptions"
3421
3642
  ];
3422
- /** The whole page piece: scenarios, diagram, verdict, headroom, live meters, limits, controls and assumptions. */
3643
+ /**
3644
+ * The whole page piece: the scenarios and the load in a bar over the diagram, the diagram, verdict, headroom, live
3645
+ * meters, limits, the design controls and assumptions.
3646
+ */
3423
3647
  function Loadmap({ model, view, theme, title, assumptions, headroom = true, compare = true, fullScreen = LOADMAP_PANELS, onNodeClick, selected, ref, ...o }) {
3424
3648
  const lm = useLoadmap(model, view, o);
3425
3649
  useImperativeHandle(ref, () => handleOf(lm), [lm]);
3426
3650
  const side = compare && model.scenarios.length > 1;
3651
+ const design = model.params.length > 1 || lm.ev.presets.some((p) => !("load" in p.values));
3427
3652
  const charts = [];
3428
3653
  if (headroom) charts.push("headroom");
3429
3654
  if (side) charts.push("compare");
3430
3655
  const out = (...panels) => panels.some((p) => fullScreen.includes(p)) ? void 0 : "";
3431
- const listed = (p) => fullScreen.includes(p) && (p === "headroom" ? headroom : p !== "compare" || side);
3656
+ const listed = (p) => fullScreen.includes(p) && (p === "headroom" ? headroom : p === "compare" ? side : p !== "controls" || design);
3432
3657
  const full = lm.fullScreen;
3433
3658
  const focus = full && lm.fullScreenMode === "focus";
3434
3659
  const [drawer, setDrawer] = useState(null);
@@ -3466,25 +3691,25 @@ function Loadmap({ model, view, theme, title, assumptions, headroom = true, comp
3466
3691
  });
3467
3692
  const heading = title !== false && /* @__PURE__ */ jsx("h2", { children: title ?? model.title });
3468
3693
  const verdict = listed("verdict");
3469
- const line = focus ? verdict || listed("controls") : verdict || listed("assumptions");
3694
+ const line = focus ? verdict : verdict || listed("assumptions");
3470
3695
  return /* @__PURE__ */ jsxs(LoadmapRoot, {
3471
3696
  lm,
3472
3697
  theme,
3473
3698
  children: [
3474
3699
  full ? /* @__PURE__ */ jsxs("div", {
3475
3700
  className: "lm-head",
3476
- children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })]
3477
- }) : /* @__PURE__ */ jsxs(Fragment, { children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })] }),
3701
+ children: [heading, /* @__PURE__ */ jsx(LoadBar, { lm })]
3702
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [heading, /* @__PURE__ */ jsx(LoadBar, { lm })] }),
3478
3703
  /* @__PURE__ */ jsx(Story, { lm }),
3479
3704
  /* @__PURE__ */ jsx(Diagram, {
3480
3705
  lm,
3481
3706
  onNodeClick,
3482
3707
  selected
3483
3708
  }),
3484
- full && line && /* @__PURE__ */ jsxs("div", {
3709
+ full && line && /* @__PURE__ */ jsx("div", {
3485
3710
  className: "lm-line",
3486
3711
  "data-tier": lm.ev.verdict.tier,
3487
- children: [/* @__PURE__ */ jsx(Suspense, {
3712
+ children: /* @__PURE__ */ jsx(Suspense, {
3488
3713
  fallback: null,
3489
3714
  children: /* @__PURE__ */ jsx(VerdictLine, {
3490
3715
  lm,
@@ -3493,7 +3718,7 @@ function Loadmap({ model, view, theme, title, assumptions, headroom = true, comp
3493
3718
  open,
3494
3719
  assumptions: !focus && listed("assumptions")
3495
3720
  })
3496
- }), focus && listed("controls") && /* @__PURE__ */ jsx(LoadRange, { lm })]
3721
+ })
3497
3722
  }),
3498
3723
  full && !focus && /* @__PURE__ */ jsx(Suspense, {
3499
3724
  fallback: null,
@@ -3539,7 +3764,10 @@ function Loadmap({ model, view, theme, title, assumptions, headroom = true, comp
3539
3764
  "data-out": out("live", "limits"),
3540
3765
  "data-drawn": drawn("live", "limits"),
3541
3766
  children: [panel("live", /* @__PURE__ */ jsx(Meters, { lm })), panel("limits", /* @__PURE__ */ jsx(Limits, { lm }))]
3542
- }), panel("controls", /* @__PURE__ */ jsx(Controls, { lm }))]
3767
+ }), design && panel("controls", /* @__PURE__ */ jsx(Controls, {
3768
+ lm,
3769
+ load: false
3770
+ }))]
3543
3771
  }),
3544
3772
  panel("assumptions", /* @__PURE__ */ jsx(Assumptions, {
3545
3773
  lm,
@@ -3589,4 +3817,4 @@ function handleOf(lm) {
3589
3817
  } : null
3590
3818
  };
3591
3819
  }
3592
- export { Verdict as C, boxComponent as D, Diagram as E, rankLabels as O, Meters as S, workerElk as T, whenRange as _, usePageTheme as a, Limits as b, injectStyles as c, HeadroomChart as d, Scenarios as f, useSize as g, useHeadroom as h, handleOf as i, Story as l, useComparison as m, Loadmap as n, useLoadmap as o, scenarioColor as p, LoadmapRoot as r, LOADMAP_CSS as s, LOADMAP_PANELS as t, Compare as u, Assumptions as v, plusMinus as w, LoadRange as x, Controls as y };
3820
+ export { useHeadroom as C, Diagram as D, workerElk as E, boxComponent as O, useComparison as S, whenRange as T, plusMinus as _, usePageTheme as a, Scenarios as b, injectStyles as c, Controls as d, Limits as f, Verdict as g, Meters as h, handleOf as i, rankLabels as k, Story as l, LoadRange as m, Loadmap as n, useLoadmap as o, LoadBar as p, LoadmapRoot as r, LOADMAP_CSS as s, LOADMAP_PANELS as t, Assumptions as u, Compare as v, useSize as w, scenarioColor as x, HeadroomChart as y };