@loadmap/react 0.34.0 → 0.36.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.
@@ -1,6 +1,7 @@
1
1
  import { Evaluation, Model, Scenario, Values } from "@loadmap/core";
2
2
  import { Direction, ElkEngine, Scene, View, labelsAt } from "@loadmap/layout";
3
3
  import { ReactNode, Ref } from "react";
4
+ import { Room } from "@loadmap/layout/internal";
4
5
  import { Particle, Sim, SimOptions } from "@loadmap/sim";
5
6
  /** A part of the scene the board shows, in scene units. */
6
7
  interface Rect {
@@ -169,6 +170,10 @@ declare class Engine {
169
170
  drawnFrame: number;
170
171
  /** Seconds a new structure takes to move in; 0 cuts. */
171
172
  transition: number;
173
+ /** The room the board has for the diagram, as the board measured it; null until one did. */
174
+ room: Room | null;
175
+ /** A board said it will tell its room (a canvas, once its zoom is there): nothing is laid out before it has. */
176
+ roomDue: boolean;
172
177
  /** The structure key the current values want; `scene.key` catches up once the layout is done. */
173
178
  wantKey: string;
174
179
  /** The values React last drew labels and colours for; a frame is complete once they match `ev.values`. */
@@ -213,6 +218,10 @@ declare class Engine {
213
218
  }): void;
214
219
  /** Calls `f` whenever the frame changes; returns a function that stops it. */
215
220
  subscribe: (f: () => void) => (() => void);
221
+ /** A board will tell its room, or will not after all. */
222
+ expectRoom(due: boolean): void;
223
+ /** The board's room for the diagram: the direction follows it. Told only when it changed by a pixel or more. */
224
+ setRoom(room: Room | null): void;
216
225
  /** Starts the sim over from empty queues, with this seed (default: the original one), and ends a move. */
217
226
  reset(seed?: number): void;
218
227
  bind(svg: SVGSVGElement | null, canvas: HTMLCanvasElement | null): void;
@@ -288,10 +297,19 @@ interface LoadmapOptions<P> extends SimOptions {
288
297
  /** Below this container width the diagram is laid out top to bottom. Default 640. */
289
298
  narrowBelow?: number;
290
299
  /**
291
- * Which way the diagram runs where there is room. Default: from its shape (`directionOf`), right unless its widest
292
- * layer has more boxes than its longest chain; below `narrowBelow` it is always DOWN.
300
+ * Which way the diagram runs. Default `auto`: the way that fits the room it is given larger (a board that fills its
301
+ * container, a canvas between its insets; on a page, the board's width by most of the window's height), and where
302
+ * both fit about as well, the way its shape suggests (`directionOf`: right unless its widest layer has more boxes
303
+ * than its longest chain). Neither the load nor a scenario, step or control turns it: only the room and the
304
+ * structure do. `RIGHT` or `DOWN` holds it. Below `narrowBelow` it is always DOWN, whichever is set.
293
305
  */
294
- direction?: Direction;
306
+ direction?: Direction | 'auto';
307
+ /**
308
+ * The rows a long diagram is folded into (columns, running down). Default `auto`: one row where its titles read
309
+ * with ease in the room it is given, else the fewest rows, three at most, that draw it clearly larger. A number
310
+ * holds it: 1 never folds. A narrow screen (`narrowBelow`) never folds.
311
+ */
312
+ rows?: number | 'auto';
295
313
  /** What full screen opens with: the panels around the diagram, or mainly the diagram and the story. Default panels. */
296
314
  fullScreenMode?: FullScreenMode;
297
315
  /**
@@ -3,7 +3,7 @@ import { capital, compact, duration, fmt, monthOf, multiple, multiples, pct, sec
3
3
  import { anchor, directionOf, labelsAt, layout, legPath, localElk, pointAt, structureKey } from "@loadmap/layout";
4
4
  import { Suspense, lazy, memo, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { morph, shapesOf } from "@loadmap/layout/internal";
6
+ import { arrange, morph, shapesOf } from "@loadmap/layout/internal";
7
7
  import { createSim } from "@loadmap/sim";
8
8
  // src/ranks.ts
9
9
  /** Badges after the limit: the two next in line. */
@@ -211,7 +211,7 @@ function stepDetail(a, b, components) {
211
211
  }).filter(Boolean).join(" · ");
212
212
  }
213
213
  // src/Diagram.tsx
214
- const Detail = lazy(() => import("./later-COuXolCO.js").then((m) => ({ default: m.Detail })));
214
+ const Detail = lazy(() => import("./later-XkpIfZ0O.js").then((m) => ({ default: m.Detail })));
215
215
  const STATE_STROKE = {
216
216
  off: "var(--lm-line)",
217
217
  ok: "var(--lm-ok)",
@@ -226,9 +226,27 @@ const tokenColor = (c) => [
226
226
  "drop",
227
227
  "muted"
228
228
  ].includes(c) ? `var(--lm-${c})` : c;
229
+ /**
230
+ * The height a board that fills the screen or its frame has under the bar: the root's, less the rows around the wrap,
231
+ * each with its gap (a flexible row at its min-height): not where they are now, which a centred wrap would change.
232
+ */
233
+ function heightUnder(root, wrap, bar) {
234
+ const px = (x) => Number.parseFloat(x) || 0;
235
+ const rs = getComputedStyle(root);
236
+ let around = px(rs.paddingTop) + px(rs.paddingBottom);
237
+ const add = (el) => {
238
+ const cs = getComputedStyle(el);
239
+ if (cs.display === "none" || cs.position === "absolute" || cs.position === "fixed") return;
240
+ around += px(rs.rowGap) + (px(cs.flexGrow) > 0 ? px(cs.minHeight) : el.offsetHeight);
241
+ };
242
+ for (const el of root.children) if (el !== wrap) add(el);
243
+ if (getComputedStyle(root, "::after").content !== "none") around += px(rs.rowGap);
244
+ return root.clientHeight - around - bar.offsetHeight - px(getComputedStyle(wrap).rowGap);
245
+ }
229
246
  function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = false }) {
230
247
  const { scene, engine, reducedMotion } = lm;
231
248
  const zoom = lm.zoom || !!canvas;
249
+ const boxed = !!canvas;
232
250
  const inset = {
233
251
  top: 0,
234
252
  right: 0,
@@ -319,13 +337,18 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
319
337
  const board = boardRef.current;
320
338
  if (!zoom || !board) return;
321
339
  let gone = false;
322
- import("./zoom-BgEnKkef.js").then(({ mountZoom }) => {
340
+ if (canvas) engine.expectRoom(true);
341
+ import("./zoom-B_Ux15iu.js").then(({ mountZoom }) => {
323
342
  if (!gone) zoomed.current = mountZoom(board, engine, () => shape.current);
324
- }).catch(() => {});
343
+ }).catch(() => engine.expectRoom(false));
325
344
  return () => {
326
345
  gone = true;
327
346
  zoomed.current?.off();
328
347
  zoomed.current = null;
348
+ if (canvas) {
349
+ engine.expectRoom(false);
350
+ engine.setRoom(null);
351
+ }
329
352
  };
330
353
  }, [
331
354
  engine,
@@ -378,18 +401,8 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
378
401
  const bar = barRef.current;
379
402
  const root = lm.root;
380
403
  if (!full || !scene || !wrap || !bar || !root) return;
381
- const px = (x) => Number.parseFloat(x) || 0;
382
404
  const fit = () => {
383
- const rs = getComputedStyle(root);
384
- let around = px(rs.paddingTop) + px(rs.paddingBottom);
385
- const add = (el) => {
386
- const cs = getComputedStyle(el);
387
- if (cs.display === "none" || cs.position === "absolute" || cs.position === "fixed") return;
388
- around += px(rs.rowGap) + (px(cs.flexGrow) > 0 ? px(cs.minHeight) : el.offsetHeight);
389
- };
390
- for (const el of root.children) if (el !== wrap) add(el);
391
- if (getComputedStyle(root, "::after").content !== "none") around += px(rs.rowGap);
392
- const h = root.clientHeight - around - bar.offsetHeight - px(getComputedStyle(wrap).rowGap);
405
+ const h = heightUnder(root, wrap, bar);
393
406
  const w = Math.min(wrap.clientWidth, h * scene.width / scene.height);
394
407
  wrap.style.setProperty("--lm-fit", `${Math.max(0, Math.floor(w))}px`);
395
408
  };
@@ -419,6 +432,29 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
419
432
  scene,
420
433
  lm.root
421
434
  ]);
435
+ useLayoutEffect(() => {
436
+ const wrap = wrapRef.current;
437
+ const bar = barRef.current;
438
+ const root = lm.root;
439
+ if (!wrap || boxed || full && !(root && bar)) return;
440
+ let off;
441
+ let gone = false;
442
+ engine.expectRoom(true);
443
+ import("./room-CxanblU8.js").then(({ watchRoom }) => {
444
+ if (!gone) off = watchRoom(engine, wrap, root, full && root && bar ? () => heightUnder(root, wrap, bar) : null);
445
+ }).catch(() => engine.expectRoom(false));
446
+ return () => {
447
+ gone = true;
448
+ off?.();
449
+ engine.expectRoom(false);
450
+ engine.setRoom(null);
451
+ };
452
+ }, [
453
+ engine,
454
+ boxed,
455
+ full,
456
+ lm.root
457
+ ]);
422
458
  const { setFullScreenMode, fullScreenMode } = lm;
423
459
  const modesRef = useRef(null);
424
460
  useEffect(() => {
@@ -2901,6 +2937,10 @@ var Engine = class {
2901
2937
  drawnFrame = -1;
2902
2938
  /** Seconds a new structure takes to move in; 0 cuts. */
2903
2939
  transition = .8;
2940
+ /** The room the board has for the diagram, as the board measured it; null until one did. */
2941
+ room = null;
2942
+ /** A board said it will tell its room (a canvas, once its zoom is there): nothing is laid out before it has. */
2943
+ roomDue = false;
2904
2944
  /** The structure key the current values want; `scene.key` catches up once the layout is done. */
2905
2945
  wantKey = "";
2906
2946
  /** The values React last drew labels and colours for; a frame is complete once they match `ev.values`. */
@@ -3031,6 +3071,20 @@ var Engine = class {
3031
3071
  this.#listeners.add(f);
3032
3072
  return () => this.#listeners.delete(f);
3033
3073
  };
3074
+ /** A board will tell its room, or will not after all. */
3075
+ expectRoom(due) {
3076
+ if (this.roomDue === due) return;
3077
+ this.roomDue = due;
3078
+ for (const f of this.#listeners) f();
3079
+ }
3080
+ /** The board's room for the diagram: the direction follows it. Told only when it changed by a pixel or more. */
3081
+ setRoom(room) {
3082
+ const was = this.room;
3083
+ if (was === room) return;
3084
+ if (was && room && Math.abs(was.w - room.w) < 1 && Math.abs(was.h - room.h) < 1) return;
3085
+ this.room = room;
3086
+ for (const f of this.#listeners) f();
3087
+ }
3034
3088
  #show(frame) {
3035
3089
  this.frame = frame;
3036
3090
  this.frameId++;
@@ -3487,6 +3541,17 @@ var Engine = class {
3487
3541
  }
3488
3542
  };
3489
3543
  // src/useLoadmap.ts
3544
+ /** The rows `auto` may fold a diagram into. */
3545
+ const FOLDS = [
3546
+ 1,
3547
+ 2,
3548
+ 3
3549
+ ];
3550
+ /** Stands for a room that is still to come. */
3551
+ const DUE = {
3552
+ w: 0,
3553
+ h: 0
3554
+ };
3490
3555
  /** The state behind a loadmap: values, the model's evaluation, the layout and the engine. */
3491
3556
  function useLoadmap(model, view, o = {}) {
3492
3557
  const init = () => ({
@@ -3517,15 +3582,16 @@ function useLoadmap(model, view, o = {}) {
3517
3582
  });
3518
3583
  engine.transition = o.transition ?? .8;
3519
3584
  const [root, setRoot] = useState(null);
3520
- const wide = o.direction ?? directionOf(view);
3585
+ const auto = o.direction == null || o.direction === "auto";
3586
+ const shape = directionOf(view);
3521
3587
  const [narrow, setNarrow] = useState(false);
3522
- const direction = narrow ? "DOWN" : wide;
3523
3588
  const [measure, setMeasure] = useState(null);
3524
3589
  const [laid, setLaid] = useState(null);
3525
3590
  const scene = laid?.view === view ? laid.scene : null;
3526
3591
  const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
3527
3592
  engine.reducedMotion = reducedMotion;
3528
3593
  const narrowBelow = o.narrowBelow ?? 640;
3594
+ const elk = o.elk;
3529
3595
  useEffect(() => {
3530
3596
  if (!evaluated.current || evaluated.current.values === values) engine.setEvaluation(ev);
3531
3597
  }, [
@@ -3543,22 +3609,82 @@ function useLoadmap(model, view, o = {}) {
3543
3609
  ro.observe(root);
3544
3610
  return () => ro.disconnect();
3545
3611
  }, [root, narrowBelow]);
3612
+ const told = useSyncExternalStore(engine.subscribe, () => engine.room ?? (engine.roomDue ? DUE : null), () => null);
3613
+ const due = told === DUE;
3614
+ const room = due ? null : told;
3615
+ const [picked, setPicked] = useState(null);
3616
+ const stands = useRef(null);
3617
+ const held = narrow ? "DOWN" : auto ? null : o.direction;
3618
+ const fixed = narrow ? 1 : typeof o.rows === "number" && o.rows >= 1 ? Math.floor(o.rows) : null;
3619
+ const chooses = !!room && !(held && fixed);
3620
+ const among = `${held} ${fixed}`;
3621
+ useEffect(() => {
3622
+ if (!chooses || !room || !measure) return;
3623
+ let live = true;
3624
+ const at = {
3625
+ measure,
3626
+ elk: elk ?? pageElk()
3627
+ };
3628
+ const ways = (held ? [held] : ["RIGHT", "DOWN"]).flatMap((direction) => (fixed ? [fixed] : FOLDS).map((rows) => ({
3629
+ direction,
3630
+ rows
3631
+ })));
3632
+ const keep = stands.current ?? {
3633
+ direction: directionOf(view),
3634
+ rows: 1
3635
+ };
3636
+ const take = (a) => {
3637
+ if (!live) return;
3638
+ stands.current = a;
3639
+ setPicked((p) => p?.view === view && p.among === among && p.direction === a.direction && p.rows === a.rows ? p : {
3640
+ view,
3641
+ among,
3642
+ ...a
3643
+ });
3644
+ };
3645
+ arrange(view, ways, room, keep, at).then(take, (err) => {
3646
+ console.error("loadmap: layout failed", err);
3647
+ take({
3648
+ direction: held ?? keep.direction,
3649
+ rows: fixed ?? 1
3650
+ });
3651
+ });
3652
+ return () => {
3653
+ live = false;
3654
+ };
3655
+ }, [
3656
+ chooses,
3657
+ held,
3658
+ fixed,
3659
+ among,
3660
+ room,
3661
+ measure,
3662
+ view,
3663
+ elk
3664
+ ]);
3665
+ const pending = due || chooses && (picked?.view !== view || picked.among !== among);
3666
+ const waits = due || chooses && !picked;
3667
+ const chosen = chooses ? picked : null;
3668
+ const direction = held ?? chosen?.direction ?? shape;
3669
+ const rows = fixed ?? (chosen && chosen.direction === direction ? chosen.rows : 1);
3546
3670
  const key = useMemo(() => measure ? structureKey(view, ev, {
3547
3671
  direction,
3672
+ rows,
3548
3673
  measure
3549
3674
  }) : "", [
3550
3675
  view,
3551
3676
  ev,
3552
3677
  direction,
3678
+ rows,
3553
3679
  measure
3554
3680
  ]);
3555
- if (fresh) engine.wantKey = key;
3556
- const elk = o.elk;
3681
+ if (fresh) engine.wantKey = pending ? "" : key;
3557
3682
  useEffect(() => {
3558
- if (!measure || !key) return;
3683
+ if (!measure || !key || waits) return;
3559
3684
  let live = true;
3560
3685
  layout(view, engine.ev, {
3561
3686
  direction,
3687
+ rows,
3562
3688
  measure,
3563
3689
  elk: elk ?? pageElk()
3564
3690
  }).then((s) => {
@@ -3575,8 +3701,10 @@ function useLoadmap(model, view, o = {}) {
3575
3701
  view,
3576
3702
  engine,
3577
3703
  direction,
3704
+ rows,
3578
3705
  measure,
3579
- elk
3706
+ elk,
3707
+ waits
3580
3708
  ]);
3581
3709
  const labels = useMemo(() => labelsAt(view, ev), [view, ev]);
3582
3710
  const valuesRef = useRef(values);
@@ -3805,8 +3933,8 @@ function canvasMeasure(fontFamily) {
3805
3933
  };
3806
3934
  }
3807
3935
  // src/Loadmap.tsx
3808
- const Dock = lazy(() => import("./later-COuXolCO.js").then((m) => ({ default: m.Dock })));
3809
- const VerdictLine = lazy(() => import("./later-COuXolCO.js").then((m) => ({ default: m.VerdictLine })));
3936
+ const Dock = lazy(() => import("./later-XkpIfZ0O.js").then((m) => ({ default: m.Dock })));
3937
+ const VerdictLine = lazy(() => import("./later-XkpIfZ0O.js").then((m) => ({ default: m.VerdictLine })));
3810
3938
  /** What the page's own switch says, on `<html>`: `data-theme`, or a `dark` or `light` class; null when it says nothing. */
3811
3939
  function pageTheme() {
3812
3940
  if (typeof document === "undefined") return null;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Insets, a as LoadmapProps, c as handleOf, d as LoadmapController, f as LoadmapOptions, g as Engine, h as Dot, i as LoadmapPanel, l as usePageTheme, m as Cue, n as Loadmap, o as LoadmapRoot, p as useLoadmap, r as LoadmapHandle, s as Theme, t as LOADMAP_PANELS, u as FullScreenMode } from "./Loadmap-CBHK-gaN.js";
1
+ import { _ as Insets, a as LoadmapProps, c as handleOf, d as LoadmapController, f as LoadmapOptions, g as Engine, h as Dot, i as LoadmapPanel, l as usePageTheme, m as Cue, n as Loadmap, o as LoadmapRoot, p as useLoadmap, r as LoadmapHandle, s as Theme, t as LOADMAP_PANELS, u as FullScreenMode } from "./Loadmap-CqMtEnju.js";
2
2
  import { Comparison, Model } from "@loadmap/core";
3
3
  import { fitLinear } from "@loadmap/core/calibrate";
4
4
  import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as useComparison, D as workerElk, O as Diagram, S as scenarioColor, _ as Verdict, a as usePageTheme, b as HeadroomChart, c as injectStyles, f as Controls, g as Meters, h as LoadRange, i as handleOf, l as Story, m as LoadBar, n as Loadmap, o as useLoadmap, p as Limits, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, x as Scenarios, y as Compare } from "./Loadmap-BfV3dSNt.js";
1
+ import { C as useComparison, D as workerElk, O as Diagram, S as scenarioColor, _ as Verdict, a as usePageTheme, b as HeadroomChart, c as injectStyles, f as Controls, g as Meters, h as LoadRange, i as handleOf, l as Story, m as LoadBar, n as Loadmap, o as useLoadmap, p as Limits, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, x as Scenarios, y as Compare } from "./Loadmap-DeE-vrG_.js";
2
2
  import { fitLinear } from "@loadmap/core/calibrate";
3
3
  import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
4
4
  import { MEASURES, fromSnapshot, originText, parseSnapshot, summarize } from "@loadmap/core/measure";
@@ -1,4 +1,4 @@
1
- import { A as rankLabels, C as useComparison, E as whenRange, S as scenarioColor, T as useSize, d as CapTag, f as Controls, g as Meters, k as boxComponent, v as plusMinus, w as useHeadroom, y as Compare } from "./Loadmap-BfV3dSNt.js";
1
+ import { A as rankLabels, C as useComparison, E as whenRange, S as scenarioColor, T as useSize, d as CapTag, f as Controls, g as Meters, k as boxComponent, v as plusMinus, w as useHeadroom, y as Compare } from "./Loadmap-DeE-vrG_.js";
2
2
  import { reach } from "@loadmap/core";
3
3
  import { compact, fmt, multiple, multiples, pct } from "@loadmap/core/format";
4
4
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -0,0 +1,53 @@
1
+ // src/room.ts
2
+ /** The share of the window's height a board on a page counts as its room: the diagram and its controls in one view. */
3
+ const INLINE_HEIGHT = .7;
4
+ /**
5
+ * Tells the engine the room of a board, now and as it changes, until the function it returns is called.
6
+ *
7
+ * A board on a page (`under` null) takes its height from the diagram, so its room is its width by most of the
8
+ * window's height. The height is read again only when the width changes: a phone's address bar sliding away resizes
9
+ * the window, and must not turn the diagram under a scroll.
10
+ *
11
+ * A board that fills the screen or its frame has what the rows around its wrap leave (`under()`), told again only for
12
+ * a new size of the root or another mode, not when a row grows: a story step with a longer text must not move every
13
+ * box. On a small screen it has none: there the board is as wide as the screen whatever its height and pans in a box
14
+ * of its own, so the diagram runs as its shape says, in one row.
15
+ */
16
+ function watchRoom(engine, wrap, root, under) {
17
+ const view = wrap.ownerDocument.defaultView;
18
+ let page = {
19
+ w: 0,
20
+ h: 0
21
+ };
22
+ let at = "";
23
+ const tell = () => {
24
+ const w = wrap.clientWidth;
25
+ if (under && root) {
26
+ const key = `${root.clientWidth} ${root.clientHeight} ${root.dataset.mode}`;
27
+ if (key === at) return;
28
+ at = key;
29
+ const h = under();
30
+ engine.setRoom(!view?.matchMedia("(max-width: 760px)").matches && w > 0 && h > 0 ? {
31
+ w,
32
+ h
33
+ } : null);
34
+ } else {
35
+ if (Math.abs(w - page.w) >= 1) page = {
36
+ w,
37
+ h: INLINE_HEIGHT * (view?.innerHeight ?? 0)
38
+ };
39
+ if (page.w > 0 && page.h > 0) engine.setRoom(page);
40
+ }
41
+ engine.expectRoom(false);
42
+ };
43
+ const ro = new ResizeObserver(tell);
44
+ ro.observe(under && root ? root : wrap);
45
+ const mo = new MutationObserver(tell);
46
+ if (under && root) mo.observe(root, { attributeFilter: ["data-mode"] });
47
+ tell();
48
+ return () => {
49
+ ro.disconnect();
50
+ mo.disconnect();
51
+ };
52
+ }
53
+ export { watchRoom };
package/dist/source.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as LoadmapProps } from "./Loadmap-CBHK-gaN.js";
1
+ import { a as LoadmapProps } from "./Loadmap-CqMtEnju.js";
2
2
  import { CompileOptions } from "@loadmap/dsl";
3
3
  export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'view'> {
4
4
  /** The `.loadmap` text. Compiled again when its tokens change: spaces, line breaks and comments change nothing. */
package/dist/source.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-BfV3dSNt.js";
1
+ import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-DeE-vrG_.js";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
  import { compile, formatDiagnostic, loadCatalogFor, loadedCatalog, needsCatalog, sharedValues } from "@loadmap/dsl";
@@ -36,11 +36,20 @@ function shown(v, vp) {
36
36
  h
37
37
  };
38
38
  }
39
+ /** The room Fit has for the diagram: the free part less its margin. */
40
+ function room(vp) {
41
+ const f = free(vp);
42
+ const m = Math.min(vp.margin, f.w / 4, f.h / 4);
43
+ return {
44
+ w: f.w - 2 * m,
45
+ h: f.h - 2 * m
46
+ };
47
+ }
39
48
  /** The view that shows `r` centred in the free part, as large as fits with the margin, no closer than `max`. */
40
49
  function frame(r, vp, max = vp.fitMax) {
41
50
  const f = free(vp);
42
- const m = Math.min(vp.margin, f.w / 4, f.h / 4);
43
- const k = Math.min((f.w - 2 * m) / r.w, (f.h - 2 * m) / r.h, max);
51
+ const fits = room(vp);
52
+ const k = Math.min(fits.w / r.w, fits.h / r.h, max);
44
53
  return at(r.x + r.w / 2, r.y + r.h / 2, f.x + f.w / 2, f.y + f.h / 2, k, vp);
45
54
  }
46
55
  /** The view at scale `k` that puts the scene point (sx, sy) at the board point (px, py). */
@@ -597,7 +606,10 @@ function mountZoom(board, engine, shape) {
597
606
  const r = board.getBoundingClientRect();
598
607
  const w = r.width - 2 * board.clientLeft;
599
608
  const h = r.height - 2 * board.clientTop;
600
- if (!(w > 0 && h > 0)) return;
609
+ if (!(w > 0 && h > 0)) {
610
+ if (canvas) engine.expectRoom(false);
611
+ return;
612
+ }
601
613
  const vp = {
602
614
  w,
603
615
  h,
@@ -610,6 +622,7 @@ function mountZoom(board, engine, shape) {
610
622
  off = attachZoom(board, engine.viewer, { always: canvas });
611
623
  }
612
624
  engine.viewer.setViewport(vp);
625
+ if (canvas) engine.setRoom(room(vp));
613
626
  };
614
627
  measure();
615
628
  const ro = new ResizeObserver(measure);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Interactive capacity models for React: an architecture diagram with moving dots, the limits ranked, the verdict, scenarios and headroom.",
5
5
  "keywords": [
6
6
  "loadmap",
@@ -39,10 +39,10 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@loadmap/core": "0.34.0",
43
- "@loadmap/dsl": "0.34.0",
44
- "@loadmap/sim": "0.34.0",
45
- "@loadmap/layout": "0.34.0",
42
+ "@loadmap/core": "0.36.0",
43
+ "@loadmap/dsl": "0.36.0",
44
+ "@loadmap/sim": "0.36.0",
45
+ "@loadmap/layout": "0.36.0",
46
46
  "elkjs": "^0.12.1"
47
47
  },
48
48
  "peerDependencies": {