@loadmap/react 0.3.1 → 0.5.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
@@ -2,8 +2,9 @@ import { compare, headroom, reach } from "@loadmap/core";
2
2
  import { fitLinear } from "@loadmap/core/calibrate";
3
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
4
  import { anchor, cluster, defineView, edge, labelsAt, layout, legPath, localElk, node, pointAt, pool, structureKey } from "@loadmap/layout";
5
- import { memo, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
5
+ import { memo, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { morph } from "@loadmap/layout/internal";
7
8
  import { createSim } from "@loadmap/sim";
8
9
  export * from "@loadmap/core";
9
10
  // src/scenarios.tsx
@@ -154,21 +155,40 @@ function Compare({ lm, title = "Scenarios compared" }) {
154
155
  ]
155
156
  });
156
157
  }
157
- /** The width of an element in CSS pixels, kept current: the chart draws at its own size so text stays legible. */
158
- function useWidth(fallback) {
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) {
159
160
  const ref = useRef(null);
160
- const [w, setW] = useState(fallback);
161
+ const [size, setSize] = useState({
162
+ width: fallback,
163
+ height: 0
164
+ });
161
165
  useEffect(() => {
162
166
  const el = ref.current;
163
167
  if (!el) return;
164
168
  const ro = new ResizeObserver(([e]) => {
165
- const x = Math.round(e?.contentRect.width ?? el.clientWidth);
166
- if (x > 0) setW(x);
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
+ });
167
175
  });
168
176
  ro.observe(el);
169
177
  return () => ro.disconnect();
170
178
  }, []);
171
- return [ref, w];
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]);
172
192
  }
173
193
  /** 1, 2, 5, 10, 20, 50, … inside [from, to]; decades only when there is little room. */
174
194
  function ticks(from, to, roomy) {
@@ -192,15 +212,8 @@ function ticks(from, to, roomy) {
192
212
  */
193
213
  function HeadroomChart({ lm, title = "Headroom" }) {
194
214
  const { model, values } = lm;
195
- const rest = JSON.stringify({
196
- ...values,
197
- load: null
198
- });
199
- const h = useMemo(() => headroom(model, {
200
- ...values,
201
- load: model.load.default
202
- }), [model, rest]);
203
- const [wrap, width] = useWidth(640);
215
+ const h = useHeadroom(lm);
216
+ const [wrap, { width }] = useSize(640);
204
217
  const [hover, setHover] = useState(null);
205
218
  const clip = useId().replace(/:/g, "");
206
219
  const dated = !!model.growth;
@@ -547,24 +560,36 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
547
560
  const barRef = useRef(null);
548
561
  const boardRef = useRef(null);
549
562
  const buttonRef = useRef(null);
550
- const [screen, setScreen] = useState(false);
551
- const [overlay, setOverlay] = useState(false);
552
- const full = screen || overlay;
563
+ const full = lm.fullScreen;
553
564
  const [tip, setTip] = useState(null);
554
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;
555
575
  useEffect(() => {
556
- if (scene) engine.setScene(scene);
557
576
  engine.bind(svgRef.current, canvasRef.current);
577
+ }, [
578
+ engine,
579
+ frame,
580
+ reducedMotion
581
+ ]);
582
+ useEffect(() => {
558
583
  if (lm.root) engine.readColors(lm.root);
559
584
  }, [
560
585
  engine,
561
586
  scene,
562
- reducedMotion,
563
587
  lm.root
564
588
  ]);
565
589
  useEffect(() => {
566
590
  engine.drawnValues = JSON.stringify(lm.values);
567
591
  engine.drawnFocus = lm.focus;
592
+ engine.drawnFrame = frameId;
568
593
  });
569
594
  useEffect(() => {
570
595
  const board = boardRef.current;
@@ -588,39 +613,6 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
588
613
  raf = requestAnimationFrame(frame);
589
614
  return () => cancelAnimationFrame(raf);
590
615
  }, [engine, reducedMotion]);
591
- useEffect(() => {
592
- const el = lm.root ?? wrapRef.current;
593
- const f = () => setScreen(!!el && document.fullscreenElement === el);
594
- document.addEventListener("fullscreenchange", f);
595
- return () => document.removeEventListener("fullscreenchange", f);
596
- }, [lm.root]);
597
- useEffect(() => {
598
- const el = lm.root ?? wrapRef.current;
599
- if (!el || !full) return;
600
- el.setAttribute("data-full", overlay ? "overlay" : "screen");
601
- const top = overlay && typeof el.showPopover === "function";
602
- if (top) {
603
- el.popover = "manual";
604
- el.showPopover();
605
- }
606
- return () => {
607
- el.removeAttribute("data-full");
608
- if (top) {
609
- el.hidePopover();
610
- el.removeAttribute("popover");
611
- }
612
- };
613
- }, [
614
- lm.root,
615
- full,
616
- overlay
617
- ]);
618
- useEffect(() => {
619
- if (!overlay) return;
620
- const f = (e) => e.key === "Escape" && setOverlay(false);
621
- document.addEventListener("keydown", f);
622
- return () => document.removeEventListener("keydown", f);
623
- }, [overlay]);
624
616
  const was = useRef(false);
625
617
  useEffect(() => {
626
618
  if (was.current && !full) buttonRef.current?.focus();
@@ -629,27 +621,71 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
629
621
  useEffect(() => {
630
622
  const wrap = wrapRef.current;
631
623
  const bar = barRef.current;
632
- if (!full || !scene || !wrap || !bar) return;
624
+ const root = lm.root;
625
+ if (!full || !scene || !wrap || !bar || !root) return;
626
+ const px = (x) => Number.parseFloat(x) || 0;
633
627
  const fit = () => {
634
- const h = wrap.clientHeight - bar.offsetHeight - Number.parseFloat(getComputedStyle(wrap).rowGap || "0");
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);
635
638
  const w = Math.min(wrap.clientWidth, h * scene.width / scene.height);
636
639
  wrap.style.setProperty("--lm-fit", `${Math.max(0, Math.floor(w))}px`);
637
640
  };
638
641
  const ro = new ResizeObserver(fit);
639
- ro.observe(wrap);
640
- ro.observe(bar);
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
+ });
641
657
  return () => {
642
658
  ro.disconnect();
659
+ mo.disconnect();
643
660
  wrap.style.removeProperty("--lm-fit");
644
661
  };
645
- }, [full, scene]);
646
- const toggle = () => {
647
- const el = lm.root ?? wrapRef.current;
648
- if (overlay) setOverlay(false);
649
- else if (document.fullscreenElement) document.exitFullscreen().catch(() => {});
650
- else if (el?.requestFullscreen) el.requestFullscreen().catch(() => setOverlay(true));
651
- else setOverlay(true);
652
- };
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
+ ]);
653
689
  return /* @__PURE__ */ jsxs("div", {
654
690
  className: "lm-wrap",
655
691
  ref: wrapRef,
@@ -657,22 +693,37 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
657
693
  /* @__PURE__ */ jsxs("div", {
658
694
  className: "lm-bar",
659
695
  ref: barRef,
660
- children: [legend ? /* @__PURE__ */ jsx(Legend, { lm }) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsx("button", {
661
- type: "button",
662
- className: "lm-btn",
663
- onClick: toggle,
664
- "aria-pressed": full,
665
- ref: buttonRef,
666
- children: full ? "✕ Close" : "⤢ Full screen"
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
+ })]
667
718
  })]
668
719
  }),
669
720
  /* @__PURE__ */ jsxs("div", {
670
721
  className: "lm-board",
671
722
  ref: boardRef,
672
- style: scene ? { aspectRatio: `${scene.width} / ${scene.height}` } : { minHeight: 240 },
673
- children: [scene && /* @__PURE__ */ jsx(Structure, {
723
+ style: frame ? { aspectRatio: `${frame.width} / ${frame.height}` } : { minHeight: 240 },
724
+ children: [frame && /* @__PURE__ */ jsx(Structure, {
674
725
  lm,
675
- scene,
726
+ scene: frame,
676
727
  svgRef,
677
728
  rates: reducedMotion,
678
729
  setTip,
@@ -693,6 +744,22 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null }) {
693
744
  ]
694
745
  });
695
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
+ }
696
763
  function Legend({ lm }) {
697
764
  const flows = lm.view.def.flows;
698
765
  const grey = Object.values(lm.ev.overload).some((o) => o.merge) || Object.values(lm.ev.stages).some((s) => s.kind === "fanout");
@@ -817,20 +884,29 @@ const Structure = memo(function Structure({ lm, scene, svgRef, rates, setTip, on
817
884
  });
818
885
  const pathOf = (pts) => pts.map(([x, y], i) => `${i ? "L" : "M"}${x} ${y}`).join(" ");
819
886
  function Edge({ e, text, marker }) {
820
- return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("path", {
821
- d: pathOf(e.points),
822
- fill: "none",
823
- stroke: "var(--lm-muted)",
824
- strokeOpacity: ".7",
825
- markerEnd: `url(#${marker})`
826
- }), e.label && text && /* @__PURE__ */ jsx("text", {
827
- x: e.label.x + e.label.w / 2,
828
- y: e.label.y + e.label.h / 2 + 4,
829
- textAnchor: "middle",
830
- fontSize: "11",
831
- fill: "var(--lm-muted)",
832
- children: text
833
- })] });
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
+ });
834
910
  }
835
911
  /** With reduced motion, each flow is a static stroke along its edges, its width scaled by its rate. */
836
912
  function RateStrokes({ lm, scene }) {
@@ -866,7 +942,7 @@ function RateStrokes({ lm, scene }) {
866
942
  }
867
943
  return /* @__PURE__ */ jsx("g", { children: out });
868
944
  }
869
- function Txt({ s, children, anchor = "middle", fill = "currentColor" }) {
945
+ function Txt({ s, children, anchor = "middle", fill = "currentColor", opacity }) {
870
946
  return /* @__PURE__ */ jsx("text", {
871
947
  x: s.x,
872
948
  y: s.y,
@@ -874,6 +950,7 @@ function Txt({ s, children, anchor = "middle", fill = "currentColor" }) {
874
950
  fontWeight: s.weight,
875
951
  textAnchor: anchor,
876
952
  fill,
953
+ opacity,
877
954
  children
878
955
  });
879
956
  }
@@ -882,9 +959,13 @@ function Node({ n, state, title, sub, lm, focused, selected, handlers }) {
882
959
  const flows = lm.view.def.flows;
883
960
  const st = n.kind === "pool" ? lm.ev.stages[n.stages[0] ?? ""] : void 0;
884
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);
885
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})`;
886
965
  return /* @__PURE__ */ jsxs("g", {
887
966
  style: { color: "var(--lm-fg)" },
967
+ opacity: n.fade,
968
+ transform: grow,
888
969
  "data-node": n.id,
889
970
  "data-focus": focused || void 0,
890
971
  "data-selected": selected || void 0,
@@ -920,8 +1001,8 @@ function Node({ n, state, title, sub, lm, focused, selected, handlers }) {
920
1001
  children: sub
921
1002
  }),
922
1003
  n.members.map((m, i) => /* @__PURE__ */ jsxs("g", {
923
- "data-idle": i >= running || void 0,
924
- opacity: i >= running ? .45 : void 0,
1004
+ "data-idle": idle(i) || void 0,
1005
+ opacity: idle(i) ? .45 * (m.fade ?? 1) : m.fade,
925
1006
  children: [/* @__PURE__ */ jsx("rect", {
926
1007
  x: m.x,
927
1008
  y: m.y,
@@ -930,7 +1011,7 @@ function Node({ n, state, title, sub, lm, focused, selected, handlers }) {
930
1011
  rx: "4",
931
1012
  fill: "none",
932
1013
  stroke: "var(--lm-line)",
933
- strokeDasharray: i >= running ? "3 3" : void 0
1014
+ strokeDasharray: idle(i) ? "3 3" : void 0
934
1015
  }), /* @__PURE__ */ jsx(Txt, {
935
1016
  s: m.spot,
936
1017
  anchor: "start",
@@ -938,43 +1019,48 @@ function Node({ n, state, title, sub, lm, focused, selected, handlers }) {
938
1019
  children: m.label
939
1020
  })]
940
1021
  }, m.label)),
941
- n.groups.map((g) => /* @__PURE__ */ jsx(Txt, {
1022
+ n.groups.map((g, i) => /* @__PURE__ */ jsx(Txt, {
942
1023
  s: g.spot,
943
1024
  anchor: "start",
944
1025
  fill: tokenColor(flows[g.flow]?.color ?? "muted"),
1026
+ opacity: g.fade,
945
1027
  children: g.text
946
- }, `${g.flow}@${g.spot.x},${g.spot.y}`)),
1028
+ }, `${g.flow}#${i}`)),
947
1029
  n.cells.map((c) => /* @__PURE__ */ jsx("rect", {
948
1030
  x: c.x,
949
1031
  y: c.y,
950
1032
  width: c.w,
951
1033
  height: c.h,
952
1034
  rx: "1.5",
1035
+ opacity: c.fade,
953
1036
  fill: "var(--lm-lane)",
954
1037
  stroke: tokenColor(flows[c.flow]?.color ?? "muted"),
955
1038
  strokeOpacity: ".6"
956
1039
  }, `${c.stage}/${c.flow}/${c.index}`)),
957
- n.slots.map((s) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
958
- x: s.x,
959
- y: s.y,
960
- width: s.w,
961
- height: s.h,
962
- rx: "2",
963
- fill: "var(--lm-surface)",
964
- stroke: "currentColor",
965
- strokeOpacity: ".45"
966
- }), /* @__PURE__ */ jsx("rect", {
967
- "data-slot": s.index,
968
- "data-stage": n.stages[0],
969
- "data-y": s.y,
970
- "data-s": s.w,
971
- x: s.x + 1,
972
- y: s.y + s.h - 1,
973
- width: s.w - 2,
974
- height: 0,
975
- rx: "1",
976
- fill: "var(--lm-accent)"
977
- })] }, s.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)),
978
1064
  selected && /* @__PURE__ */ jsx("rect", {
979
1065
  className: "lm-selected",
980
1066
  x: n.x - 3,
@@ -1328,34 +1414,42 @@ function Meters({ lm }) {
1328
1414
  children: items.map((m) => /* @__PURE__ */ jsxs("div", {
1329
1415
  className: "lm-meter",
1330
1416
  "data-state": m.state,
1331
- children: [/* @__PURE__ */ jsx("b", { children: m.value }), /* @__PURE__ */ jsx("span", { children: m.label })]
1417
+ children: [/* @__PURE__ */ jsx("b", { children: m.value }), /* @__PURE__ */ jsx("span", {
1418
+ title: m.label,
1419
+ children: m.label
1420
+ })]
1332
1421
  }, m.key))
1333
1422
  })] });
1334
1423
  }
1424
+ /** The load slider with its label and value. */
1425
+ function LoadRange({ lm }) {
1426
+ const load = lm.model.load;
1427
+ const x = lm.values.load;
1428
+ return /* @__PURE__ */ jsxs("label", {
1429
+ className: "lm-range",
1430
+ children: [/* @__PURE__ */ jsxs("span", { children: [
1431
+ load.label,
1432
+ " ",
1433
+ /* @__PURE__ */ jsxs("output", { children: [fmt$1(x), "×"] })
1434
+ ] }), /* @__PURE__ */ jsx("input", {
1435
+ type: "range",
1436
+ min: load.min,
1437
+ max: load.max,
1438
+ step: load.step,
1439
+ value: x,
1440
+ onChange: (e) => lm.setValues({ load: Number(e.target.value) })
1441
+ })]
1442
+ });
1443
+ }
1335
1444
  /** The load slider, the presets and every parameter, greyed out where it does not apply. */
1336
1445
  function Controls({ lm }) {
1337
1446
  const { model, values, setValues, ev } = lm;
1338
1447
  const v = values;
1339
- const load = model.load;
1340
1448
  return /* @__PURE__ */ jsxs("div", {
1341
1449
  className: "lm-card lm-controls",
1342
1450
  children: [
1343
1451
  /* @__PURE__ */ jsx("h3", { children: "Load" }),
1344
- /* @__PURE__ */ jsxs("label", {
1345
- className: "lm-range",
1346
- children: [/* @__PURE__ */ jsxs("span", { children: [
1347
- load.label,
1348
- " ",
1349
- /* @__PURE__ */ jsxs("output", { children: [fmt$1(v.load), "×"] })
1350
- ] }), /* @__PURE__ */ jsx("input", {
1351
- type: "range",
1352
- min: load.min,
1353
- max: load.max,
1354
- step: load.step,
1355
- value: v.load,
1356
- onChange: (e) => setValues({ load: Number(e.target.value) })
1357
- })]
1358
- }),
1452
+ /* @__PURE__ */ jsx(LoadRange, { lm }),
1359
1453
  /* @__PURE__ */ jsx("div", {
1360
1454
  className: "lm-presets",
1361
1455
  children: ev.presets.map((p) => {
@@ -1494,17 +1588,329 @@ function describe(a) {
1494
1588
  /** Exact below 1,000 (3.9 cores), compact above (12k req/s). */
1495
1589
  const num = (x) => Math.abs(x) >= 1e3 ? compact$1(x) : fmt$1(x);
1496
1590
  const sig = (x) => Number(x.toPrecision(3)).toString();
1591
+ // src/compact.tsx
1592
+ /** The names a reader sees for the panels, on the tabs and the buttons that open them. */
1593
+ const NAMES = {
1594
+ verdict: "Verdict",
1595
+ live: "Live",
1596
+ limits: "Limits",
1597
+ controls: "Load",
1598
+ headroom: "Headroom",
1599
+ compare: "Compare",
1600
+ assumptions: "Assumptions"
1601
+ };
1602
+ /**
1603
+ * The verdict in one line, from the same evaluation as the sentence: the load, how far the target holds, the first
1604
+ * limit and how sure its capacity is, what is past capacity. The sentence is its tooltip and opens under "Why".
1605
+ */
1606
+ function VerdictLine({ lm, verdict = true, extra = 0, open, assumptions }) {
1607
+ const { ev, model, values } = lm;
1608
+ const first = ev.firstLimit;
1609
+ const range = ev.target;
1610
+ const target = `${pct$1(model.thresholds.target)} target`;
1611
+ const c = first?.capacity;
1612
+ const sure = !c ? "" : c.provenance === "estimated" ? `est${c.within ? ` ${plusMinus(c)}` : ""}` : plusMinus(c);
1613
+ const over = ev.ranked.filter((x) => (x.util ?? 0) > model.thresholds.full);
1614
+ const when = range ? whenRange(model, range) : "";
1615
+ const estimated = ev.assumptions.filter((a) => a.kind === "capacity" && a.capacity.provenance === "estimated").length;
1616
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1617
+ verdict && /* @__PURE__ */ jsx("p", {
1618
+ className: "lm-headline",
1619
+ title: ev.verdict.text,
1620
+ "aria-live": "polite",
1621
+ children: !first || !range ? ev.verdict.text : /* @__PURE__ */ jsxs(Fragment, { children: [
1622
+ /* @__PURE__ */ jsxs("b", {
1623
+ className: "lm-num",
1624
+ children: [fmt$1(values.load), "×"]
1625
+ }),
1626
+ " ·",
1627
+ " ",
1628
+ values.load < range.low ? /* @__PURE__ */ jsxs(Fragment, { children: [
1629
+ "the ",
1630
+ target,
1631
+ " holds to ",
1632
+ /* @__PURE__ */ jsx("b", {
1633
+ className: "lm-num",
1634
+ children: multiples(range, model.searchMax, true)
1635
+ }),
1636
+ when && ` (${when})`
1637
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1638
+ "past the ",
1639
+ target,
1640
+ " from ",
1641
+ /* @__PURE__ */ jsx("b", {
1642
+ className: "lm-num",
1643
+ children: multiple$1(range.low, model.searchMax)
1644
+ })
1645
+ ] }),
1646
+ " ",
1647
+ "· first limit ",
1648
+ /* @__PURE__ */ jsx("b", { children: first.name }),
1649
+ sure && /* @__PURE__ */ jsx("span", {
1650
+ className: "lm-tag",
1651
+ "data-kind": c?.provenance === "estimated" ? "estimated" : "range",
1652
+ children: sure
1653
+ }),
1654
+ over.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1655
+ " ",
1656
+ "· ",
1657
+ /* @__PURE__ */ jsx("b", { children: over.map((x) => x.name).join(", ") }),
1658
+ " past capacity"
1659
+ ] })
1660
+ ] })
1661
+ }),
1662
+ open && verdict && /* @__PURE__ */ jsx("button", {
1663
+ type: "button",
1664
+ className: "lm-link",
1665
+ onClick: (e) => open("verdict", e.currentTarget),
1666
+ children: "Why ›"
1667
+ }),
1668
+ open && assumptions && /* @__PURE__ */ jsxs("button", {
1669
+ type: "button",
1670
+ className: "lm-link",
1671
+ onClick: (e) => open("assumptions", e.currentTarget),
1672
+ children: [
1673
+ "What this assumes · ",
1674
+ ev.assumptions.length + extra,
1675
+ estimated > 0 && ` (${estimated} estimated)`,
1676
+ " ›"
1677
+ ]
1678
+ })
1679
+ ] });
1680
+ }
1681
+ /** The order of the cards in the dock: what the reader changes first, what it changes next to it. */
1682
+ const DOCK = [
1683
+ "controls",
1684
+ "live",
1685
+ "limits",
1686
+ "headroom",
1687
+ "compare"
1688
+ ];
1689
+ /**
1690
+ * Full screen's panels, compact, side by side in a box the screen sizes: what does not fit is left out whole, and
1691
+ * each card opens its panel whole. A phone shows one at a time, under tabs.
1692
+ */
1693
+ function Dock({ lm, panels, open }) {
1694
+ const shown = DOCK.filter((p) => panels.includes(p));
1695
+ const [tab, setTab] = useState(null);
1696
+ if (!shown.length) return null;
1697
+ const active = tab && shown.includes(tab) ? tab : shown[0];
1698
+ return /* @__PURE__ */ jsxs("div", {
1699
+ className: "lm-dock",
1700
+ children: [/* @__PURE__ */ jsx("fieldset", {
1701
+ className: "lm-tabs",
1702
+ "aria-label": "Panels",
1703
+ children: shown.map((p) => /* @__PURE__ */ jsx("button", {
1704
+ type: "button",
1705
+ "aria-pressed": p === active,
1706
+ onClick: () => setTab(p),
1707
+ children: NAMES[p]
1708
+ }, p))
1709
+ }), shown.map((p) => /* @__PURE__ */ jsx(Card, {
1710
+ lm,
1711
+ panel: p,
1712
+ open,
1713
+ active: p === active
1714
+ }, p))]
1715
+ });
1716
+ }
1717
+ function Card({ lm, panel, open, active }) {
1718
+ const box = useRef(null);
1719
+ const more = useRef(null);
1720
+ useClip(box, more);
1721
+ return /* @__PURE__ */ jsxs("div", {
1722
+ className: "lm-mini",
1723
+ "data-mini": panel,
1724
+ "data-active": active || void 0,
1725
+ ref: box,
1726
+ children: [panel === "controls" ? /* @__PURE__ */ jsx(Controls, { lm }) : panel === "compare" ? /* @__PURE__ */ jsx(Compare, { lm }) : /* @__PURE__ */ jsx("div", {
1727
+ className: "lm-card",
1728
+ 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 })] })
1729
+ }), /* @__PURE__ */ jsx("button", {
1730
+ type: "button",
1731
+ className: "lm-more",
1732
+ ref: more,
1733
+ "aria-label": `${NAMES[panel]}, all of it`,
1734
+ onClick: (e) => open(panel, e.currentTarget),
1735
+ children: "›"
1736
+ })]
1737
+ });
1738
+ }
1739
+ /** The rows a card leaves out whole when they do not fit. */
1740
+ const ROWS = ".lm-meter, .lm-mini-lim, .lm-controls > *, .lm-table tbody tr";
1741
+ /**
1742
+ * Hides the rows that cross the bottom of the card, and counts them on its button. Runs again when the card's size
1743
+ * or its rows change: the meters come and go with the load, and the order of the limits with it.
1744
+ */
1745
+ function useClip(box, more) {
1746
+ useEffect(() => {
1747
+ const card = box.current?.querySelector(".lm-card");
1748
+ if (!card) return;
1749
+ const clip = () => {
1750
+ const r = card.getBoundingClientRect();
1751
+ const bottom = r.bottom - Number.parseFloat(getComputedStyle(card).paddingBottom || "0");
1752
+ let n = 0;
1753
+ for (const row of card.querySelectorAll(ROWS)) {
1754
+ const out = r.height > 0 && row.getBoundingClientRect().bottom > bottom + .5;
1755
+ row.toggleAttribute("data-clip", out);
1756
+ if (out && !row.matches("h3")) n++;
1757
+ }
1758
+ if (more.current) more.current.dataset.more = n ? `+${n}` : "";
1759
+ };
1760
+ const ro = new ResizeObserver(clip);
1761
+ ro.observe(card);
1762
+ const mo = new MutationObserver(clip);
1763
+ mo.observe(card, {
1764
+ childList: true,
1765
+ subtree: true
1766
+ });
1767
+ clip();
1768
+ return () => {
1769
+ ro.disconnect();
1770
+ mo.disconnect();
1771
+ };
1772
+ }, [box, more]);
1773
+ }
1774
+ /**
1775
+ * The limits in their order, a line each: the name and how sure its capacity is, the bar, the utilization, where it
1776
+ * is full. The first is the first limit: the verdict line names it.
1777
+ */
1778
+ function MiniLimits({ lm }) {
1779
+ const { ev, model } = lm;
1780
+ const top = Math.max(1.5, model.thresholds.full * 1.5);
1781
+ const at = (u) => `${u / top * 100}%`;
1782
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Where it runs out" }), /* @__PURE__ */ jsx("div", {
1783
+ className: "lm-mini-limits",
1784
+ children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
1785
+ className: "lm-mini-lim",
1786
+ "data-component": c.id,
1787
+ children: [
1788
+ /* @__PURE__ */ jsxs("span", {
1789
+ className: "lm-name",
1790
+ title: c.name,
1791
+ children: [c.name, c.capacity?.provenance === "estimated" ? /* @__PURE__ */ jsx("span", {
1792
+ className: "lm-tag",
1793
+ "data-kind": "estimated",
1794
+ children: "est"
1795
+ }) : !!c.capacity?.within && /* @__PURE__ */ jsx("span", {
1796
+ className: "lm-tag",
1797
+ "data-kind": "range",
1798
+ children: "±"
1799
+ })]
1800
+ }),
1801
+ /* @__PURE__ */ jsxs("span", {
1802
+ className: "lm-track",
1803
+ role: "img",
1804
+ "aria-label": `${c.name} at ${c.util == null ? "off" : pct$1(c.util)}`,
1805
+ children: [
1806
+ /* @__PURE__ */ jsx("span", {
1807
+ className: "lm-fill",
1808
+ "data-state": c.state,
1809
+ style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
1810
+ }),
1811
+ /* @__PURE__ */ jsx("span", {
1812
+ className: "lm-tick",
1813
+ style: { left: at(model.thresholds.target) }
1814
+ }),
1815
+ /* @__PURE__ */ jsx("span", {
1816
+ className: "lm-tick",
1817
+ style: { left: at(model.thresholds.full) }
1818
+ })
1819
+ ]
1820
+ }),
1821
+ /* @__PURE__ */ jsx("span", {
1822
+ className: "lm-val",
1823
+ children: c.util == null ? "—" : pct$1(c.util)
1824
+ }),
1825
+ /* @__PURE__ */ jsx("span", {
1826
+ className: "lm-val lm-sub",
1827
+ 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)}`
1828
+ })
1829
+ ]
1830
+ }, c.id))
1831
+ })] });
1832
+ }
1833
+ /** The headroom chart as a sparkline: each scenario's line, the target, the load; where the shown one crosses it. */
1834
+ function Sparkline({ lm }) {
1835
+ const { model, values } = lm;
1836
+ const h = useHeadroom(lm);
1837
+ const [box, { width: W, height: H }] = useSize(240);
1838
+ const top = Math.max(1.5, model.thresholds.full * 1.5);
1839
+ const lx = (x) => W * Math.log(x / h.from) / Math.log(h.to / h.from);
1840
+ const ly = (u) => 2 + (H - 4) * (1 - Math.min(u, top) / top);
1841
+ const path = (s) => {
1842
+ let d = "";
1843
+ let pen = false;
1844
+ for (const [x, u] of s) {
1845
+ if (u == null) {
1846
+ pen = false;
1847
+ continue;
1848
+ }
1849
+ d += `${pen ? "L" : "M"}${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`;
1850
+ pen = true;
1851
+ }
1852
+ return d;
1853
+ };
1854
+ const line = h.lines.find((l) => l.selected) ?? h.lines[0];
1855
+ const target = pct$1(model.thresholds.target);
1856
+ const reaches = line ? `${line.targetRange ? multiples(line.targetRange, model.searchMax, true) : multiple$1(line.target, model.searchMax)}` : "";
1857
+ const when = line ? whenRange(model, line.targetRange) : "";
1858
+ const loadX = lx(Math.min(h.to, Math.max(h.from, values.load)));
1859
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
1860
+ className: "lm-spark",
1861
+ ref: box,
1862
+ children: H > 0 && /* @__PURE__ */ jsxs("svg", {
1863
+ width: W,
1864
+ height: H,
1865
+ "aria-hidden": "true",
1866
+ children: [
1867
+ /* @__PURE__ */ jsx("line", {
1868
+ className: "lm-spark-th",
1869
+ x1: 0,
1870
+ x2: W,
1871
+ y1: ly(model.thresholds.target),
1872
+ y2: ly(model.thresholds.target)
1873
+ }),
1874
+ h.lines.map((l) => /* @__PURE__ */ jsx("path", {
1875
+ d: path(l.envelope),
1876
+ fill: "none",
1877
+ stroke: scenarioColor(model, l.label),
1878
+ strokeWidth: l.selected ? 2 : 1.25
1879
+ }, l.label ?? "")),
1880
+ /* @__PURE__ */ jsx("line", {
1881
+ className: "lm-spark-load",
1882
+ x1: loadX,
1883
+ x2: loadX,
1884
+ y1: 0,
1885
+ y2: H
1886
+ })
1887
+ ]
1888
+ })
1889
+ }), line && /* @__PURE__ */ jsxs("p", {
1890
+ className: "lm-spark-text",
1891
+ title: `${line.label ?? "It"} reaches the ${target} target at ${reaches}`,
1892
+ children: [
1893
+ line.label ?? "It",
1894
+ " reaches the ",
1895
+ target,
1896
+ " target at ",
1897
+ reaches,
1898
+ when && ` (${when})`,
1899
+ "."
1900
+ ]
1901
+ })] });
1902
+ }
1497
1903
  // src/story.tsx
1498
1904
  /**
1499
- * The model's story, a step at a time: the step's text, where it is, back and next. ← and → move through it while
1500
- * the bar has the keyboard focus (the sliders keep their own arrows).
1905
+ * The model's story, a step at a time: the step's text, where it is, play, back and next. ← and → move through it
1906
+ * while the bar has the keyboard focus (the sliders keep their own arrows). The text keeps the room of the longest
1907
+ * step, so stepping through it never moves what is below.
1501
1908
  */
1502
1909
  function Story({ lm }) {
1503
1910
  const bar = useRef(null);
1504
1911
  const { story } = lm.model;
1505
1912
  if (!story.length) return null;
1506
1913
  const i = lm.step;
1507
- const step = i == null ? null : story[i];
1508
1914
  const last = story.length - 1;
1509
1915
  const go = (to) => {
1510
1916
  const next = Math.max(0, Math.min(last, to));
@@ -1516,29 +1922,63 @@ function Story({ lm }) {
1516
1922
  else return;
1517
1923
  e.preventDefault();
1518
1924
  };
1925
+ const playing = lm.storyPlaying;
1519
1926
  return /* @__PURE__ */ jsxs("fieldset", {
1520
1927
  className: "lm-story",
1521
1928
  onKeyDown: keys,
1522
1929
  ref: bar,
1523
1930
  tabIndex: -1,
1931
+ "data-playing": playing || void 0,
1524
1932
  children: [
1525
1933
  /* @__PURE__ */ jsx("legend", { children: "Story" }),
1526
- /* @__PURE__ */ jsx("p", {
1934
+ /* @__PURE__ */ jsx("span", {
1935
+ className: "lm-sr",
1527
1936
  "aria-live": "polite",
1528
- children: step ? /* @__PURE__ */ jsxs(Fragment, { children: [
1529
- /* @__PURE__ */ jsxs("b", { children: [
1530
- i + 1,
1531
- " of ",
1532
- story.length
1533
- ] }),
1534
- " ",
1535
- step.text,
1536
- lm.stepChanged && /* @__PURE__ */ jsx("em", { children: " You changed the values since." })
1537
- ] }) : `A walk through this model in ${story.length} steps.`
1937
+ 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." : ""}`
1938
+ }),
1939
+ /* @__PURE__ */ jsxs("p", {
1940
+ "aria-hidden": "true",
1941
+ children: [/* @__PURE__ */ jsxs("span", {
1942
+ "data-shown": i == null || void 0,
1943
+ children: [
1944
+ "A walk through this model in ",
1945
+ story.length,
1946
+ " steps."
1947
+ ]
1948
+ }), story.map((st, k) => /* @__PURE__ */ jsxs("span", {
1949
+ "data-shown": k === i || void 0,
1950
+ children: [
1951
+ /* @__PURE__ */ jsxs("b", { children: [
1952
+ k + 1,
1953
+ " of ",
1954
+ story.length
1955
+ ] }),
1956
+ " ",
1957
+ st.text,
1958
+ /* @__PURE__ */ jsx("em", {
1959
+ "data-shown": k === i && lm.stepChanged || void 0,
1960
+ children: " You changed the values since."
1961
+ })
1962
+ ]
1963
+ }, k))]
1964
+ }),
1965
+ i != null && /* @__PURE__ */ jsx("span", {
1966
+ className: "lm-story-progress",
1967
+ "aria-hidden": "true",
1968
+ children: story.map((st, k) => /* @__PURE__ */ jsx("i", {
1969
+ "data-state": k < i ? "done" : k === i ? "now" : void 0,
1970
+ style: k === i ? { "--lm-step": `${st.seconds}s` } : void 0
1971
+ }, k === i ? `${k}-${playing}` : k))
1538
1972
  }),
1539
1973
  /* @__PURE__ */ jsxs("span", {
1540
1974
  className: "lm-story-nav",
1541
1975
  children: [
1976
+ /* @__PURE__ */ jsx("button", {
1977
+ type: "button",
1978
+ onClick: () => lm.setStoryPlaying(!playing),
1979
+ "aria-pressed": playing,
1980
+ children: playing ? "❚❚ Pause" : "▶ Play"
1981
+ }),
1542
1982
  i != null && /* @__PURE__ */ jsx("button", {
1543
1983
  type: "button",
1544
1984
  onClick: () => go(i - 1),
@@ -1605,31 +2045,128 @@ const LOADMAP_CSS = `
1605
2045
  .lm-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .78rem; color: var(--lm-muted); }
1606
2046
  .lm-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; margin-right: 5px; }
1607
2047
 
1608
- /* full screen (the browser's, or a fixed overlay): the diagram as large as fits, beside a panel of the verdict, the
1609
- live meters and the controls; the board's size comes from Diagram (--lm-fit), the load never changes it */
1610
- .lm-side, .lm-ranked { display: contents; }
1611
- .lm[data-full] { height: 100vh; height: 100dvh; padding: 16px; overflow: auto; overscroll-behavior: contain; align-content: start; }
2048
+ /* full screen (the browser's, or a fixed overlay): a column that never scrolls. The diagram as wide as the screen on
2049
+ top; under it the verdict in a line and the panels, compact, in a dock the screen sizes. The load changes what is
2050
+ in them, never their size, so it never moves the board. Focus: the diagram, the story, the verdict and the load */
2051
+ .lm-side, .lm-card > .lm-panel { display: contents; }
2052
+ .lm-panel { display: grid; gap: 14px; min-width: 0; }
2053
+ .lm[data-full] { height: 100vh; height: 100dvh; padding: 16px; overflow: hidden; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; position: relative; }
1612
2054
  .lm[data-full="overlay"] { position: fixed; inset: 0; z-index: 2147483000; width: auto; max-width: none; max-height: none; margin: 0; border: 0; }
1613
- .lm[data-full]:has(> .lm-side) { overflow: hidden; grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 400px); grid-template-rows: repeat(3, auto) minmax(0, 1fr); row-gap: 0; }
1614
- .lm[data-full]:has(> .lm-side) > :is(h2, .lm-scenarios, .lm-story) { grid-column: 1; margin-bottom: 12px; }
2055
+ .lm[data-full] > * { flex: none; }
1615
2056
  /* a page of its own keeps the rest outside full screen, as <Loadmap> does */
1616
- .lm[data-full]:has(> .lm-side) > :not(h2, .lm-scenarios, .lm-story, .lm-wrap, .lm-side) { display: none; }
1617
- .lm[data-full] .lm-wrap { height: calc(100dvh - 32px); grid-template-rows: auto auto; align-content: center; }
1618
- .lm[data-full]:has(> .lm-side) > .lm-wrap { grid-column: 1; grid-row: 4; height: auto; min-height: 0; }
1619
- /* left under the bar, so the legend starts where the board does */
2057
+ .lm[data-full] > :not(.lm-head, h2, .lm-scenarios, .lm-story, .lm-wrap, .lm-line, .lm-dock, .lm-side) { display: none; }
2058
+ .lm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; min-width: 0; }
2059
+ .lm-head h2 { font-size: 1.1rem; }
2060
+ .lm[data-full] .lm-wrap { gap: 6px; }
2061
+ /* the board as large as fits (--lm-fit, from Diagram), left under the bar, so the legend starts where the board does */
1620
2062
  .lm[data-full] .lm-board { width: var(--lm-fit, 100%); margin: 0; align-self: start; justify-self: start; }
1621
- .lm[data-full] > .lm-side { grid-column: 2; grid-row: 1 / -1; display: grid; gap: 14px; align-content: start; min-height: 0; overflow: auto; overscroll-behavior: contain; container-type: inline-size; }
1622
- .lm[data-full] .lm-more { display: none; }
2063
+ .lm-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
2064
+ .lm-modes { display: inline-flex; margin: 0; padding: 0; min-width: 0; border: 1px solid var(--lm-line); border-radius: 6px; overflow: hidden; }
2065
+ .lm-modes button { font: 500 .8rem var(--lm-font); color: var(--lm-fg); background: var(--lm-surface); border: 0; padding: 6px 12px; cursor: pointer; }
2066
+ .lm-modes button[aria-pressed="true"] { background: var(--lm-fg); color: var(--lm-surface); }
2067
+ .lm[data-full] .lm-story { padding: 6px 12px; }
2068
+ .lm[data-full] [data-out] { display: none; }
2069
+
2070
+ .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; }
2071
+ .lm-line[data-tier="warn"] { border-color: var(--lm-warn); }
2072
+ .lm-line[data-tier="over"] { border-color: var(--lm-drop); }
2073
+ .lm-headline { flex: 1 1 auto; min-width: 0; margin: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2074
+ .lm-num { font: 600 .95em var(--lm-mono); font-variant-numeric: tabular-nums; }
2075
+ .lm-link { font: 500 .8rem var(--lm-font); color: var(--lm-accent); background: none; border: 0; padding: 2px 4px; cursor: pointer; white-space: nowrap; }
2076
+ .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; }
2077
+ .lm-line output { font-family: var(--lm-mono); font-variant-numeric: tabular-nums; }
2078
+ .lm-line input[type=range] { width: 100%; accent-color: var(--lm-accent); }
2079
+
2080
+ .lm-dock { display: flex; gap: 10px; min-width: 0; }
2081
+ .lm[data-full] > .lm-dock { flex: 1 1 0; min-height: clamp(200px, 26dvh, 340px); }
2082
+ .lm-tabs { display: none; margin: 0; padding: 0; border: 0; min-width: 0; }
2083
+ .lm-mini { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; display: grid; container-type: inline-size; }
2084
+ .lm-mini[data-mini="controls"] { flex-grow: 1.25; }
2085
+ .lm-mini[data-mini="limits"] { flex-grow: 1.45; }
2086
+ .lm-mini[data-mini="live"] { flex-grow: .8; }
2087
+ .lm-mini[data-mini="headroom"] { flex-grow: .9; }
2088
+ .lm-mini[data-mini="compare"] { flex-grow: 1.3; }
2089
+ .lm-mini > .lm-card { min-height: 0; overflow: hidden; padding: 10px 12px; gap: 6px; align-content: start; }
2090
+ .lm-mini [data-clip] { visibility: hidden; }
2091
+ .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; }
2092
+ .lm-more[data-more]:not([data-more=""])::before { content: attr(data-more) " "; }
2093
+ .lm-mini .lm-meters { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px; }
2094
+ .lm-mini .lm-meter { display: flex; align-items: baseline; gap: 8px; padding: 3px 8px; }
2095
+ .lm-mini .lm-meter b { flex: none; font-size: .9rem; }
2096
+ .lm-mini .lm-meter span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2097
+ /* one grid for every row, so the bars line up whatever the names */
2098
+ .lm-mini-limits { display: grid; grid-template-columns: minmax(0, max-content) minmax(48px, 1fr) auto auto; gap: 6px 10px; }
2099
+ .lm-mini-lim { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: center; font-size: .8rem; }
2100
+ .lm-mini-lim .lm-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2101
+ .lm-mini-lim .lm-tag { margin-left: 5px; }
2102
+ .lm-mini-lim .lm-track { height: 9px; }
2103
+ .lm-mini-lim .lm-val { white-space: nowrap; }
2104
+ .lm-mini-lim .lm-sub { font: 400 .74rem var(--lm-mono); color: var(--lm-muted); }
2105
+ .lm-mini .lm-controls { gap: 6px; column-gap: 16px; }
2106
+ .lm-mini .lm-controls small, .lm-mini .lm-controls > h3:not(:first-child) { display: none; }
2107
+ .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; }
2108
+ .lm-mini .lm-select { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: .8rem; }
2109
+ .lm-mini .lm-select select { width: auto; padding: 1px 6px; font-size: .78rem; }
2110
+ .lm-mini .lm-switch { font-size: .8rem; }
2111
+ .lm-mini .lm-switch input { margin-top: 2px; }
2112
+ .lm-mini .lm-presets { gap: 4px; }
2113
+ .lm-mini .lm-presets button { padding: 2px 8px; font-size: .72rem; }
2114
+ @container (min-width: 420px) {
2115
+ .lm-mini .lm-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
2116
+ .lm-mini .lm-controls > :is(h3, .lm-presets), .lm-mini .lm-controls > h3 + .lm-range { grid-column: 1 / -1; }
2117
+ }
2118
+ .lm-mini .lm-compare > :not(h3:first-child, .lm-table-wrap:nth-child(3)) { display: none; }
2119
+ .lm-mini .lm-table { font-size: .76rem; }
2120
+ .lm-mini .lm-table th, .lm-mini .lm-table td { padding: 3px 8px 3px 0; }
2121
+ .lm-mini .lm-table small { display: none; }
2122
+ .lm-mini .lm-table thead th { white-space: nowrap; font-size: .6rem; }
2123
+ .lm-mini > .lm-card:has(> .lm-spark) { grid-template-rows: auto minmax(0, 1fr) auto; align-content: stretch; }
2124
+ .lm-spark { position: relative; min-height: 0; }
2125
+ .lm-spark svg { position: absolute; inset: 0; display: block; overflow: visible; }
2126
+ .lm-spark-th { stroke: var(--lm-muted); stroke-dasharray: 4 3; }
2127
+ .lm-spark-load { stroke: var(--lm-fg); opacity: .45; }
2128
+ .lm-spark-text { margin: 0; font-size: .76rem; color: var(--lm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2129
+
2130
+ /* the drawer: the page's own panel, alone, over the right of the board */
2131
+ .lm[data-full] > .lm-drawer:not([data-drawer]) { display: none; }
2132
+ .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; }
2133
+ .lm-side[data-drawer] :is(.lm-panel, .lm-strip, .lm-charts, .lm-card):not([data-drawn]):not(.lm-panel *) { display: none; }
2134
+ .lm-side[data-drawer] .lm-strip { grid-template-columns: minmax(0, 1fr); }
2135
+ .lm-drawer-bar { display: flex; justify-content: flex-end; }
2136
+
2137
+ /* 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
2138
+ third of the screen */
2139
+ .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; }
2140
+
2141
+ /* focus: the board and what runs on it in the middle of the screen */
2142
+ .lm[data-mode="focus"] .lm-scenarios, .lm[data-mode="focus"] > .lm-side:not(.lm-drawer) { display: none; }
2143
+ .lm[data-mode="focus"] > .lm-wrap { margin-top: auto; }
2144
+ .lm[data-mode="focus"] > :is(.lm-story, .lm-line) { order: 1; }
2145
+ .lm[data-mode="focus"]::after { content: ""; order: 2; margin-top: auto; }
2146
+ .lm[data-mode="focus"] > .lm-story { border-left-width: 4px; padding: 10px 14px; }
2147
+ .lm[data-mode="focus"] > .lm-story p { font-size: 1.1rem; }
2148
+
1623
2149
  @media (max-width: 760px) {
1624
- .lm[data-full]:has(> .lm-side) { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(3, auto) minmax(0, 3fr) minmax(0, 2fr); }
1625
- .lm[data-full] > .lm-side { grid-column: 1; grid-row: 5; margin-top: 12px; }
1626
- .lm[data-full] > h2 { display: none; }
1627
- /* a phone keeps the board as wide as the screen and scrolls it: fitted to the height it is too small to read */
1628
- .lm[data-full]:has(> .lm-side) > .lm-wrap { overflow: auto; align-content: start; }
2150
+ .lm[data-full] { padding: 10px; gap: 8px; }
2151
+ /* the page has the title, and the legend: here they would leave the diagram no room */
2152
+ .lm[data-full] > h2, .lm[data-full] :is(.lm-head h2, .lm-legend, .lm-story legend) { display: none; }
2153
+ /* the one exception: here the diagram runs top to bottom, and shrunk to the screen it is too small to read, so it
2154
+ pans in a box of its own with the bar on top. The page never scrolls */
1629
2155
  .lm[data-full] .lm-board { width: 100%; }
1630
- /* the controls first in the short panel: the diagram, the verdict and the meters answer them */
1631
- .lm[data-full] .lm-side > .lm-strip:not(.lm-more) { display: contents; }
1632
- .lm[data-full] .lm-side .lm-controls { order: -1; }
2156
+ .lm[data-full] > .lm-wrap { height: 40dvh; overflow: auto; row-gap: 0; overscroll-behavior: contain; }
2157
+ .lm[data-mode="focus"] > .lm-wrap { height: auto; flex: 1 1 0; min-height: 0; margin-top: 0; }
2158
+ .lm[data-full] .lm-bar { position: sticky; top: 0; z-index: 1; padding-bottom: 8px; background: var(--lm-bg); }
2159
+ .lm[data-full] .lm-line { flex-wrap: wrap; }
2160
+ .lm[data-full] > .lm-story { padding: 6px 10px; gap: 6px 10px; }
2161
+ .lm[data-full] > .lm-story p { font-size: .84rem; }
2162
+ .lm[data-full] .lm-story button { padding: 4px 10px; }
2163
+ .lm[data-full] .lm-headline { flex-basis: 100%; }
2164
+ .lm-dock { flex-direction: column; min-height: 0; gap: 6px; }
2165
+ .lm-tabs { display: flex; flex: none; gap: 2px; border-bottom: 1px solid var(--lm-line); overflow: hidden; }
2166
+ .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; }
2167
+ .lm-tabs button[aria-pressed="true"] { color: var(--lm-fg); border-color: var(--lm-fg); }
2168
+ .lm-mini:not([data-active]) { display: none; }
2169
+ .lm[data-full] > .lm-side[data-drawer] { inset: 8px; width: auto; }
1633
2170
  }
1634
2171
 
1635
2172
  .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; }
@@ -1695,7 +2232,15 @@ const LOADMAP_CSS = `
1695
2232
  .lm-scenarios i, .lm-table i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; margin-right: 6px; }
1696
2233
  .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); }
1697
2234
  .lm-story legend { float: left; font: 600 .74rem var(--lm-font); text-transform: uppercase; letter-spacing: .08em; color: var(--lm-muted); padding: 0; }
1698
- .lm-story p { flex: 1 1 240px; margin: 0; font: 400 .9rem/1.4 var(--lm-font); color: var(--lm-fg); }
2235
+ .lm-story p { flex: 1 1 240px; display: grid; margin: 0; font: 400 .9rem/1.4 var(--lm-font); color: var(--lm-fg); }
2236
+ .lm-story p > span { grid-area: 1 / 1; }
2237
+ .lm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
2238
+ .lm-story p > span:not([data-shown]), .lm-story em:not([data-shown]) { visibility: hidden; }
2239
+ .lm-story-progress { display: flex; align-items: center; gap: 4px; }
2240
+ .lm-story-progress i { position: relative; width: 28px; height: 4px; border-radius: 2px; background: var(--lm-line); overflow: hidden; }
2241
+ .lm-story-progress i[data-state="done"], .lm-story:not([data-playing]) .lm-story-progress i[data-state="now"] { background: var(--lm-accent); }
2242
+ .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; }
2243
+ @keyframes lm-step { from { transform: scaleX(0); } to { transform: scaleX(1); } }
1699
2244
  .lm-story b { font-weight: 600; color: var(--lm-muted); margin-right: 4px; white-space: nowrap; }
1700
2245
  .lm-story-nav { display: flex; gap: 6px; }
1701
2246
  .lm-story em { color: var(--lm-muted); }
@@ -1727,7 +2272,10 @@ const LOADMAP_CSS = `
1727
2272
  .lm-node { cursor: pointer; outline: none; }
1728
2273
  .lm-node:focus-visible > :first-child { stroke-width: 3; }
1729
2274
 
1730
- @media (prefers-reduced-motion: reduce) { .lm-fill { transition: none; } }
2275
+ @media (prefers-reduced-motion: reduce) {
2276
+ .lm-fill { transition: none; }
2277
+ .lm-story[data-playing] .lm-story-progress i[data-state="now"]::before { animation: none; transform: none; }
2278
+ }
1731
2279
  `;
1732
2280
  /** Adds the stylesheet once per document. */
1733
2281
  function injectStyles(doc = document) {
@@ -1819,9 +2367,9 @@ const TOKENS = [
1819
2367
  /** The stroke of a hollow dot, in scene units. */
1820
2368
  const RING = 1.4;
1821
2369
  /**
1822
- * Everything that moves, without React: the sim, the dots on the canvas and the worker fills in the SVG. React
1823
- * renders the structure once per scene; the engine updates the moving parts every frame, and export drives it frame
1824
- * by frame instead of the animation loop.
2370
+ * Everything that moves, without React: the sim, the dots on the canvas, the worker fills in the SVG, and the move from
2371
+ * one structure to the next. React renders the structure once per scene, and once per frame while it moves; the engine
2372
+ * updates the moving parts every frame, and export drives it frame by frame instead of the animation loop.
1825
2373
  */
1826
2374
  var Engine = class {
1827
2375
  model;
@@ -1829,6 +2377,13 @@ var Engine = class {
1829
2377
  sim;
1830
2378
  ev;
1831
2379
  scene = null;
2380
+ /** What the diagram draws now: the scene, or a frame of the move to it. */
2381
+ frame = null;
2382
+ /** Counts the frames: export waits until the diagram drew this one. */
2383
+ frameId = 0;
2384
+ drawnFrame = -1;
2385
+ /** Seconds a new structure takes to move in; 0 cuts. */
2386
+ transition = .8;
1832
2387
  /** The structure key the current values want; `scene.key` catches up once the layout is done. */
1833
2388
  wantKey = "";
1834
2389
  /** The values React last drew labels and colours for; a frame is complete once they match `ev.values`. */
@@ -1845,6 +2400,15 @@ var Engine = class {
1845
2400
  #o;
1846
2401
  #slots = [];
1847
2402
  #paths = /* @__PURE__ */ new Map();
2403
+ #move = null;
2404
+ #listeners = /* @__PURE__ */ new Set();
2405
+ /** The last steps came while paused: export drives a paused engine, a page that only paused it does not. */
2406
+ #driven = false;
2407
+ /** While the structure moves, each leg's path in this frame, shared by the dots on it. */
2408
+ #legs = {
2409
+ frame: -1,
2410
+ paths: /* @__PURE__ */ new Map()
2411
+ };
1848
2412
  constructor(model, view, ev, o = {}) {
1849
2413
  this.model = model;
1850
2414
  this.view = view;
@@ -1858,20 +2422,49 @@ var Engine = class {
1858
2422
  this.ev = ev;
1859
2423
  if (!same) this.sim.update(ev);
1860
2424
  }
1861
- setScene(scene) {
2425
+ /**
2426
+ * Takes a new scene. A new structure moves in from what is drawn now, unless `cut`, the diagram turned (a new
2427
+ * direction is a new screen size, not a new design), or it is paused with nothing stepping it; the first scene just
2428
+ * shows.
2429
+ */
2430
+ setScene(scene, o = {}) {
1862
2431
  if (scene === this.scene) return;
2432
+ const from = this.frame;
2433
+ const seconds = this.transition;
1863
2434
  this.scene = scene;
1864
2435
  this.#paths.clear();
2436
+ const move = from && !o.cut && seconds > 0 && Number.isFinite(seconds) && (!this.paused || this.#driven) && from.direction === scene.direction && from.key !== scene.key;
2437
+ this.#move = move ? {
2438
+ at: morph(from, scene),
2439
+ t: 0,
2440
+ seconds
2441
+ } : null;
2442
+ this.#show(move ? this.#move.at(0) : scene);
1865
2443
  }
1866
- /** Starts the sim over from empty queues, with this seed (default: the original one). */
2444
+ /** Calls `f` whenever the frame changes; returns a function that stops it. */
2445
+ subscribe = (f) => {
2446
+ this.#listeners.add(f);
2447
+ return () => this.#listeners.delete(f);
2448
+ };
2449
+ #show(frame) {
2450
+ this.frame = frame;
2451
+ this.frameId++;
2452
+ for (const f of this.#listeners) f();
2453
+ }
2454
+ /** Starts the sim over from empty queues, with this seed (default: the original one), and ends a move. */
1867
2455
  reset(seed) {
1868
2456
  this.sim = createSim(this.model, this.ev, {
1869
2457
  ...this.#o,
1870
2458
  seed: seed ?? this.#o.seed
1871
2459
  });
1872
2460
  this.#paths.clear();
2461
+ if (this.#move && this.scene) {
2462
+ this.#move = null;
2463
+ this.#show(this.scene);
2464
+ }
1873
2465
  }
1874
2466
  bind(svg, canvas) {
2467
+ const fresh = canvas !== this.canvas;
1875
2468
  this.svg = svg;
1876
2469
  this.canvas = canvas;
1877
2470
  this.#slots = [];
@@ -1883,7 +2476,8 @@ var Engine = class {
1883
2476
  y: Number(el.dataset.y),
1884
2477
  s: Number(el.dataset.s)
1885
2478
  });
1886
- this.resize();
2479
+ if (fresh) this.resize();
2480
+ this.drawFills();
1887
2481
  }
1888
2482
  /** Reads the theme tokens from the element that carries them. Call again when the theme changes. */
1889
2483
  readColors(root) {
@@ -1905,22 +2499,33 @@ var Engine = class {
1905
2499
  const r = c.getBoundingClientRect();
1906
2500
  if (!r.width) return;
1907
2501
  const dpr = Math.min(2, globalThis.devicePixelRatio || 1);
1908
- c.width = Math.round(r.width * dpr);
1909
- c.height = Math.round(r.height * dpr);
2502
+ const w = Math.round(r.width * dpr);
2503
+ const h = Math.round(r.height * dpr);
2504
+ if (c.width === w && c.height === h) return;
2505
+ c.width = w;
2506
+ c.height = h;
2507
+ this.draw();
1910
2508
  }
2509
+ /** Advances the sim, and the move to a new structure, by `dtReal` seconds. */
1911
2510
  step(dtReal, o = {}) {
2511
+ this.#driven = this.paused;
1912
2512
  this.sim.step(dtReal, o);
2513
+ const m = this.#move;
2514
+ if (!m || dtReal <= 0) return;
2515
+ m.t += dtReal / m.seconds;
2516
+ if (m.t >= 1) this.#move = null;
2517
+ this.#show(m.at(m.t));
1913
2518
  }
1914
2519
  /** Draws the dots on the overlay canvas and the worker fills in the SVG. */
1915
2520
  draw(o = {}) {
1916
2521
  this.drawFills();
1917
2522
  const c = this.canvas;
1918
2523
  const ctx = c?.getContext("2d");
1919
- if (!c || !ctx || !this.scene) return;
2524
+ if (!c || !ctx || !this.frame) return;
1920
2525
  ctx.setTransform(1, 0, 0, 1, 0, 0);
1921
2526
  ctx.clearRect(0, 0, c.width, c.height);
1922
2527
  if (o.particles === false) return;
1923
- this.paintParticles(ctx, c.width / this.scene.width);
2528
+ this.paintParticles(ctx, c.width / this.frame.width);
1924
2529
  }
1925
2530
  drawFills() {
1926
2531
  for (const sl of this.#slots) {
@@ -1932,7 +2537,7 @@ var Engine = class {
1932
2537
  }
1933
2538
  /** Every dot as it is drawn now, in scene units: for the canvas, and for an SVG export. */
1934
2539
  dots() {
1935
- const scene = this.scene;
2540
+ const scene = this.frame;
1936
2541
  if (!scene) return [];
1937
2542
  const out = [];
1938
2543
  const live = /* @__PURE__ */ new Set();
@@ -1955,7 +2560,7 @@ var Engine = class {
1955
2560
  }
1956
2561
  /** Paints the dots onto any 2D context, scene units × `scale`: the overlay, or an export frame. */
1957
2562
  paintParticles(ctx, scale) {
1958
- if (!this.scene) return;
2563
+ if (!this.frame) return;
1959
2564
  ctx.save();
1960
2565
  ctx.transform(scale, 0, 0, scale, 0, 0);
1961
2566
  for (const d of this.dots()) {
@@ -1977,6 +2582,20 @@ var Engine = class {
1977
2582
  #position(scene, d) {
1978
2583
  if (d.phase !== "move") return anchor(scene, d.to, d.flow);
1979
2584
  const key = `${d.leg}|${d.from.stage}|${d.from.cell}|${d.to.stage}|${d.to.cell}`;
2585
+ if (this.#move) {
2586
+ const legs = this.#legs;
2587
+ if (legs.frame !== this.frameId) {
2588
+ legs.frame = this.frameId;
2589
+ legs.paths.clear();
2590
+ }
2591
+ const leg = `${d.flow}|${key}`;
2592
+ let points = legs.paths.get(leg);
2593
+ if (!points) {
2594
+ points = legPath(scene, d.from, d.to, d.flow);
2595
+ legs.paths.set(leg, points);
2596
+ }
2597
+ return pointAt(points, d.t / d.dur);
2598
+ }
1980
2599
  let p = this.#paths.get(d.id);
1981
2600
  if (!p || p.key !== key) {
1982
2601
  p = {
@@ -2012,6 +2631,7 @@ function useLoadmap(model, view, o = {}) {
2012
2631
  const engineRef = useRef(null);
2013
2632
  if (!engineRef.current || engineRef.current.model !== model || engineRef.current.view !== view) engineRef.current = new Engine(model, view, ev, o);
2014
2633
  const engine = engineRef.current;
2634
+ engine.transition = o.transition ?? .8;
2015
2635
  const [root, setRoot] = useState(null);
2016
2636
  const wide = o.direction ?? "RIGHT";
2017
2637
  const [direction, setDirection] = useState(wide);
@@ -2119,6 +2739,89 @@ function useLoadmap(model, view, o = {}) {
2119
2739
  const focus = shown && !stepChanged ? shown.focus ?? null : null;
2120
2740
  engine.wantFocus = focus;
2121
2741
  engine.storyStep = step;
2742
+ const [playing, setPlaying] = useState(false);
2743
+ if (playing && (step == null || stepChanged)) setPlaying(false);
2744
+ const storyPlaying = playing && step != null && !stepChanged;
2745
+ useEffect(() => {
2746
+ if (!storyPlaying || step == null) return;
2747
+ const last = model.story.length - 1;
2748
+ const t = setTimeout(() => step < last ? setStep(step + 1) : setPlaying(false), model.story[step].seconds * 1e3);
2749
+ return () => clearTimeout(t);
2750
+ }, [
2751
+ storyPlaying,
2752
+ step,
2753
+ model,
2754
+ setStep
2755
+ ]);
2756
+ const setStoryPlaying = useCallback((on) => {
2757
+ if (on && (step == null || stepChanged || step === model.story.length - 1)) setStep(step == null || step === model.story.length - 1 ? 0 : step);
2758
+ setPlaying(on && model.story.length > 0);
2759
+ }, [
2760
+ step,
2761
+ stepChanged,
2762
+ model,
2763
+ setStep
2764
+ ]);
2765
+ const [screen, setScreen] = useState(false);
2766
+ const [overlay, setOverlay] = useState(false);
2767
+ const fullScreen = screen || overlay;
2768
+ useEffect(() => {
2769
+ const f = () => setScreen(!!root && document.fullscreenElement === root);
2770
+ document.addEventListener("fullscreenchange", f);
2771
+ return () => document.removeEventListener("fullscreenchange", f);
2772
+ }, [root]);
2773
+ const start = o.fullScreenMode ?? "panels";
2774
+ const [modeState, setModeState] = useState({
2775
+ start,
2776
+ mode: start
2777
+ });
2778
+ const fullScreenMode = modeState.start === start ? modeState.mode : start;
2779
+ const setFullScreenMode = useCallback((mode) => setModeState({
2780
+ start,
2781
+ mode
2782
+ }), [start]);
2783
+ useEffect(() => {
2784
+ if (!root || !fullScreen) return;
2785
+ root.setAttribute("data-full", overlay ? "overlay" : "screen");
2786
+ const top = overlay && typeof root.showPopover === "function";
2787
+ if (top) {
2788
+ root.popover = "manual";
2789
+ root.showPopover();
2790
+ }
2791
+ return () => {
2792
+ root.removeAttribute("data-full");
2793
+ if (top) {
2794
+ root.hidePopover();
2795
+ root.removeAttribute("popover");
2796
+ }
2797
+ };
2798
+ }, [
2799
+ root,
2800
+ fullScreen,
2801
+ overlay
2802
+ ]);
2803
+ useEffect(() => {
2804
+ if (!root || !fullScreen) return;
2805
+ root.setAttribute("data-mode", fullScreenMode);
2806
+ return () => root.removeAttribute("data-mode");
2807
+ }, [
2808
+ root,
2809
+ fullScreen,
2810
+ fullScreenMode
2811
+ ]);
2812
+ useEffect(() => {
2813
+ if (!overlay) return;
2814
+ const f = (e) => e.key === "Escape" && setOverlay(false);
2815
+ document.addEventListener("keydown", f);
2816
+ return () => document.removeEventListener("keydown", f);
2817
+ }, [overlay]);
2818
+ const toggleFullScreen = useCallback(() => {
2819
+ if (!root) return;
2820
+ if (overlay) setOverlay(false);
2821
+ else if (document.fullscreenElement) document.exitFullscreen().catch(() => {});
2822
+ else if (root.requestFullscreen) root.requestFullscreen().catch(() => setOverlay(true));
2823
+ else setOverlay(true);
2824
+ }, [root, overlay]);
2122
2825
  return {
2123
2826
  model,
2124
2827
  view,
@@ -2130,6 +2833,12 @@ function useLoadmap(model, view, o = {}) {
2130
2833
  stepChanged,
2131
2834
  setStep,
2132
2835
  focus,
2836
+ storyPlaying,
2837
+ setStoryPlaying,
2838
+ fullScreen,
2839
+ toggleFullScreen,
2840
+ fullScreenMode,
2841
+ setFullScreenMode,
2133
2842
  ev,
2134
2843
  scene,
2135
2844
  labels,
@@ -2183,48 +2892,136 @@ function LoadmapRoot({ lm, theme = "auto", children }) {
2183
2892
  children
2184
2893
  });
2185
2894
  }
2895
+ /** The panels full screen shows with the diagram, compact: the verdict and the assumptions in a line under it. */
2896
+ const LOADMAP_PANELS = [
2897
+ "verdict",
2898
+ "live",
2899
+ "limits",
2900
+ "controls",
2901
+ "headroom",
2902
+ "compare",
2903
+ "assumptions"
2904
+ ];
2186
2905
  /** The whole page piece: scenarios, diagram, verdict, headroom, live meters, limits, controls and assumptions. */
2187
- function Loadmap({ model, view, theme, title, assumptions, headroom = true, compare = true, onNodeClick, selected, ref, ...o }) {
2906
+ function Loadmap({ model, view, theme, title, assumptions, headroom = true, compare = true, fullScreen = LOADMAP_PANELS, onNodeClick, selected, ref, ...o }) {
2188
2907
  const lm = useLoadmap(model, view, o);
2189
2908
  useImperativeHandle(ref, () => handleOf(lm), [lm]);
2190
2909
  const side = compare && model.scenarios.length > 1;
2910
+ const charts = [];
2911
+ if (headroom) charts.push("headroom");
2912
+ if (side) charts.push("compare");
2913
+ const out = (...panels) => panels.some((p) => fullScreen.includes(p)) ? void 0 : "";
2914
+ const listed = (p) => fullScreen.includes(p) && (p === "headroom" ? headroom : p !== "compare" || side);
2915
+ const full = lm.fullScreen;
2916
+ const focus = full && lm.fullScreenMode === "focus";
2917
+ const [drawer, setDrawer] = useState(null);
2918
+ if (drawer && !full) setDrawer(null);
2919
+ const close = useRef(null);
2920
+ useEffect(() => {
2921
+ if (drawer) close.current?.focus();
2922
+ }, [drawer]);
2923
+ const open = (p, from) => setDrawer({
2924
+ panel: p,
2925
+ from
2926
+ });
2927
+ const shut = () => {
2928
+ drawer?.from.focus();
2929
+ setDrawer(null);
2930
+ };
2931
+ useEffect(() => {
2932
+ if (!drawer) return;
2933
+ const f = (e) => {
2934
+ if (e.key !== "Escape") return;
2935
+ e.stopPropagation();
2936
+ drawer.from.focus();
2937
+ setDrawer(null);
2938
+ };
2939
+ document.addEventListener("keydown", f, true);
2940
+ return () => document.removeEventListener("keydown", f, true);
2941
+ }, [drawer]);
2942
+ const drawn = (...panels) => drawer && panels.includes(drawer.panel) ? "" : void 0;
2943
+ const panel = (id, children) => /* @__PURE__ */ jsx("div", {
2944
+ className: "lm-panel",
2945
+ "data-panel": id,
2946
+ "data-out": out(id),
2947
+ "data-drawn": drawn(id),
2948
+ children: (!full || drawer?.panel === id) && children
2949
+ });
2950
+ const heading = title !== false && /* @__PURE__ */ jsx("h2", { children: title ?? model.title });
2951
+ const verdict = listed("verdict");
2952
+ const line = focus ? verdict || listed("controls") : verdict || listed("assumptions");
2191
2953
  return /* @__PURE__ */ jsxs(LoadmapRoot, {
2192
2954
  lm,
2193
2955
  theme,
2194
2956
  children: [
2195
- title !== false && /* @__PURE__ */ jsx("h2", { children: title ?? model.title }),
2196
- /* @__PURE__ */ jsx(Scenarios, { lm }),
2957
+ full ? /* @__PURE__ */ jsxs("div", {
2958
+ className: "lm-head",
2959
+ children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })]
2960
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [heading, /* @__PURE__ */ jsx(Scenarios, { lm })] }),
2197
2961
  /* @__PURE__ */ jsx(Story, { lm }),
2198
2962
  /* @__PURE__ */ jsx(Diagram, {
2199
2963
  lm,
2200
2964
  onNodeClick,
2201
2965
  selected
2202
2966
  }),
2967
+ full && line && /* @__PURE__ */ jsxs("div", {
2968
+ className: "lm-line",
2969
+ "data-tier": lm.ev.verdict.tier,
2970
+ children: [/* @__PURE__ */ jsx(VerdictLine, {
2971
+ lm,
2972
+ verdict,
2973
+ extra: assumptions?.length,
2974
+ open,
2975
+ assumptions: !focus && listed("assumptions")
2976
+ }), focus && listed("controls") && /* @__PURE__ */ jsx(LoadRange, { lm })]
2977
+ }),
2978
+ full && !focus && /* @__PURE__ */ jsx(Dock, {
2979
+ lm,
2980
+ panels: LOADMAP_PANELS.filter(listed),
2981
+ open
2982
+ }),
2203
2983
  /* @__PURE__ */ jsxs("div", {
2204
- className: "lm-side",
2984
+ className: "lm-side lm-drawer",
2985
+ "data-out": out("verdict", "live", "limits", "controls", ...charts, "assumptions"),
2986
+ "data-drawer": drawer?.panel,
2987
+ ...drawer && {
2988
+ role: "dialog",
2989
+ "aria-label": "The whole panel"
2990
+ },
2205
2991
  children: [
2206
- /* @__PURE__ */ jsx(Verdict, { lm }),
2207
- (headroom || side) && /* @__PURE__ */ jsxs("div", {
2208
- className: headroom && side ? "lm-more lm-strip" : "lm-more",
2209
- children: [headroom && /* @__PURE__ */ jsx(HeadroomChart, { lm }), side && /* @__PURE__ */ jsx(Compare, { lm })]
2992
+ drawer && /* @__PURE__ */ jsx("div", {
2993
+ className: "lm-drawer-bar",
2994
+ "data-drawn": "",
2995
+ children: /* @__PURE__ */ jsx("button", {
2996
+ type: "button",
2997
+ className: "lm-btn",
2998
+ onClick: shut,
2999
+ ref: close,
3000
+ children: "✕ Back to full screen"
3001
+ })
3002
+ }),
3003
+ panel("verdict", /* @__PURE__ */ jsx(Verdict, { lm })),
3004
+ charts.length > 0 && /* @__PURE__ */ jsxs("div", {
3005
+ className: charts.length > 1 ? "lm-charts lm-strip" : "lm-charts",
3006
+ "data-out": out(...charts),
3007
+ "data-drawn": drawn(...charts),
3008
+ children: [headroom && panel("headroom", /* @__PURE__ */ jsx(HeadroomChart, { lm })), side && panel("compare", /* @__PURE__ */ jsx(Compare, { lm }))]
2210
3009
  }),
2211
3010
  /* @__PURE__ */ jsxs("div", {
2212
- className: "lm-strip",
3011
+ className: "lm-strip lm-live",
3012
+ "data-out": out("live", "limits", "controls"),
3013
+ "data-drawn": drawn("live", "limits", "controls"),
2213
3014
  children: [/* @__PURE__ */ jsxs("div", {
2214
3015
  className: "lm-card",
2215
- children: [/* @__PURE__ */ jsx(Meters, { lm }), /* @__PURE__ */ jsx("div", {
2216
- className: "lm-more lm-ranked",
2217
- children: /* @__PURE__ */ jsx(Limits, { lm })
2218
- })]
2219
- }), /* @__PURE__ */ jsx(Controls, { lm })]
3016
+ "data-out": out("live", "limits"),
3017
+ "data-drawn": drawn("live", "limits"),
3018
+ children: [panel("live", /* @__PURE__ */ jsx(Meters, { lm })), panel("limits", /* @__PURE__ */ jsx(Limits, { lm }))]
3019
+ }), panel("controls", /* @__PURE__ */ jsx(Controls, { lm }))]
2220
3020
  }),
2221
- /* @__PURE__ */ jsx("div", {
2222
- className: "lm-more",
2223
- children: /* @__PURE__ */ jsx(Assumptions, {
2224
- lm,
2225
- extra: assumptions
2226
- })
2227
- })
3021
+ panel("assumptions", /* @__PURE__ */ jsx(Assumptions, {
3022
+ lm,
3023
+ extra: assumptions
3024
+ }))
2228
3025
  ]
2229
3026
  })
2230
3027
  ]
@@ -2236,7 +3033,7 @@ function handleOf(lm) {
2236
3033
  engine,
2237
3034
  async ready(timeoutMs = 1e4) {
2238
3035
  const t0 = performance.now();
2239
- const drawn = () => engine.scene && engine.scene.key === engine.wantKey && engine.svg && engine.drawnValues === JSON.stringify(engine.ev.values) && engine.drawnFocus === engine.wantFocus;
3036
+ 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;
2240
3037
  while (!drawn()) {
2241
3038
  if (performance.now() - t0 > timeoutMs) throw new Error("loadmap: layout not ready");
2242
3039
  await new Promise((r) => requestAnimationFrame(r));
@@ -2257,11 +3054,11 @@ function handleOf(lm) {
2257
3054
  engine.step(dt, { particles: true });
2258
3055
  engine.draw({ particles: true });
2259
3056
  },
2260
- board: () => engine.svg && engine.canvas && engine.scene ? {
3057
+ board: () => engine.svg && engine.canvas && engine.frame ? {
2261
3058
  svg: engine.svg,
2262
3059
  canvas: engine.canvas,
2263
- scene: engine.scene
3060
+ scene: engine.frame
2264
3061
  } : null
2265
3062
  };
2266
3063
  }
2267
- export { Assumptions, Compare, Controls, Diagram, HeadroomChart, LOADMAP_CSS, Limits, Loadmap, LoadmapRoot, Meters, Scenarios, Story, Verdict, cluster, compact, defineView, edge, fitLinear, fmt, handleOf, injectStyles, multiple, node, pct, pool, scenarioColor, secs, useComparison, useLoadmap };
3064
+ 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 };