@loadmap/react 0.25.0 → 0.26.1
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/{Loadmap-Du_KZ0mk.d.ts → Loadmap-CBHK-gaN.d.ts} +18 -0
- package/dist/{Loadmap-c6WweQfq.js → Loadmap-Rla4011L.js} +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{later-B30jPIEX.js → later-Dg1NA8wt.js} +1 -1
- package/dist/source.d.ts +1 -1
- package/dist/source.js +1 -1
- package/dist/{zoom-S0CmdOL2.js → zoom-BgEnKkef.js} +66 -48
- package/package.json +5 -5
|
@@ -75,6 +75,18 @@ declare class Viewer {
|
|
|
75
75
|
* as the board changes. A story playing stops where it is: the reader took the view.
|
|
76
76
|
*/
|
|
77
77
|
setView(v: Viewpoint | null): void;
|
|
78
|
+
/**
|
|
79
|
+
* Moves the view to `to` (null: fitted). With `fly` it flies there, on the wall clock (a reader's view is never in a
|
|
80
|
+
* recording); without, and with reduced motion, it is there at once.
|
|
81
|
+
*/
|
|
82
|
+
go(to: Viewpoint | null, fly: boolean): void;
|
|
83
|
+
/** Ends a flight where it is. */
|
|
84
|
+
land(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Brings these boxes into view, flying there: at the same zoom, further out only as far as it takes to show them
|
|
87
|
+
* all. Nothing when they show already: a view the reader never moved shows the whole diagram.
|
|
88
|
+
*/
|
|
89
|
+
show(ids: readonly string[]): void;
|
|
78
90
|
/** The part of the scene the board shows now: its viewBox. */
|
|
79
91
|
box(): Rect | null;
|
|
80
92
|
/** Where the board draws the scene now, in its pixels: its scale and offset. */
|
|
@@ -383,6 +395,12 @@ interface LoadmapHandle {
|
|
|
383
395
|
* length in seconds. Picking a step or a value stops it.
|
|
384
396
|
*/
|
|
385
397
|
playStory(): number;
|
|
398
|
+
/**
|
|
399
|
+
* On a board the reader pans and zooms, brings these boxes (node ids) into view, flying there: at the same zoom,
|
|
400
|
+
* further out only as far as it takes to show them all. Nothing when they show already, while the diagram is fitted
|
|
401
|
+
* or the story plays.
|
|
402
|
+
*/
|
|
403
|
+
show(ids: readonly string[]): void;
|
|
386
404
|
/** The drawn board, for capturing frames: while the structure moves, `scene` is the frame drawn. */
|
|
387
405
|
board(): {
|
|
388
406
|
svg: SVGSVGElement;
|
|
@@ -212,7 +212,7 @@ function stepDetail(a, b, components) {
|
|
|
212
212
|
}).filter(Boolean).join(" · ");
|
|
213
213
|
}
|
|
214
214
|
// src/Diagram.tsx
|
|
215
|
-
const Detail = lazy(() => import("./later-
|
|
215
|
+
const Detail = lazy(() => import("./later-Dg1NA8wt.js").then((m) => ({ default: m.Detail })));
|
|
216
216
|
const STATE_STROKE = {
|
|
217
217
|
off: "var(--lm-line)",
|
|
218
218
|
ok: "var(--lm-ok)",
|
|
@@ -320,7 +320,7 @@ function Diagram({ lm, legend = true, onNodeClick, selected = null, canvas = fal
|
|
|
320
320
|
const board = boardRef.current;
|
|
321
321
|
if (!zoom || !board) return;
|
|
322
322
|
let gone = false;
|
|
323
|
-
import("./zoom-
|
|
323
|
+
import("./zoom-BgEnKkef.js").then(({ mountZoom }) => {
|
|
324
324
|
if (!gone) zoomed.current = mountZoom(board, engine, () => shape.current);
|
|
325
325
|
}).catch(() => {});
|
|
326
326
|
return () => {
|
|
@@ -3625,8 +3625,8 @@ function canvasMeasure(fontFamily) {
|
|
|
3625
3625
|
};
|
|
3626
3626
|
}
|
|
3627
3627
|
// src/Loadmap.tsx
|
|
3628
|
-
const Dock = lazy(() => import("./later-
|
|
3629
|
-
const VerdictLine = lazy(() => import("./later-
|
|
3628
|
+
const Dock = lazy(() => import("./later-Dg1NA8wt.js").then((m) => ({ default: m.Dock })));
|
|
3629
|
+
const VerdictLine = lazy(() => import("./later-Dg1NA8wt.js").then((m) => ({ default: m.VerdictLine })));
|
|
3630
3630
|
/** What the page's own switch says, on `<html>`: `data-theme`, or a `dark` or `light` class; null when it says nothing. */
|
|
3631
3631
|
function pageTheme() {
|
|
3632
3632
|
if (typeof document === "undefined") return null;
|
|
@@ -3858,6 +3858,7 @@ function handleOf(lm) {
|
|
|
3858
3858
|
engine.paused = false;
|
|
3859
3859
|
},
|
|
3860
3860
|
values: () => engine.ev.values,
|
|
3861
|
+
show: (ids) => engine.viewer?.show(ids),
|
|
3861
3862
|
setValues: (v) => lm.setValues(v),
|
|
3862
3863
|
setStoryStep: (i) => lm.setStep(i),
|
|
3863
3864
|
storyStep: () => engine.storyStep,
|
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-
|
|
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";
|
|
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 { D as Diagram, E as workerElk, S as useComparison, a as usePageTheme, b as Scenarios, c as injectStyles, d as Controls, f as Limits, g as Verdict, h as Meters, i as handleOf, l as Story, m as LoadRange, n as Loadmap, o as useLoadmap, p as LoadBar, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, v as Compare, x as scenarioColor, y as HeadroomChart } from "./Loadmap-
|
|
1
|
+
import { D as Diagram, E as workerElk, S as useComparison, a as usePageTheme, b as Scenarios, c as injectStyles, d as Controls, f as Limits, g as Verdict, h as Meters, i as handleOf, l as Story, m as LoadRange, n as Loadmap, o as useLoadmap, p as LoadBar, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, v as Compare, x as scenarioColor, y as HeadroomChart } from "./Loadmap-Rla4011L.js";
|
|
2
2
|
import { fitLinear } from "@loadmap/core/calibrate";
|
|
3
3
|
import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
|
|
4
4
|
import { cluster, defineView, directionOf, edge, node, pool } from "@loadmap/layout";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as useHeadroom, O as boxComponent, S as useComparison, T as whenRange, _ as plusMinus, d as Controls, h as Meters, k as rankLabels, v as Compare, w as useSize, x as scenarioColor } from "./Loadmap-
|
|
1
|
+
import { C as useHeadroom, O as boxComponent, S as useComparison, T as whenRange, _ as plusMinus, d as Controls, h as Meters, k as rankLabels, v as Compare, w as useSize, x as scenarioColor } from "./Loadmap-Rla4011L.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";
|
package/dist/source.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as LoadmapProps } from "./Loadmap-
|
|
1
|
+
import { a as LoadmapProps } from "./Loadmap-CBHK-gaN.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-
|
|
1
|
+
import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-Rla4011L.js";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { compile, formatDiagnostic, sharedValues } from "@loadmap/dsl";
|
|
@@ -121,12 +121,17 @@ function cameraOf(v, scene, fit, vp) {
|
|
|
121
121
|
h
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
/**
|
|
125
|
-
function
|
|
124
|
+
/** Whether `r` (a part of the scene) shows whole in the free part. */
|
|
125
|
+
function seen(v, vp, r) {
|
|
126
126
|
const f = free(vp);
|
|
127
127
|
const left = vp.w / 2 + (r.x - v.x) * v.k;
|
|
128
128
|
const top = vp.h / 2 + (r.y - v.y) * v.k;
|
|
129
|
-
return left >= f.x && top >= f.y && left + r.w * v.k <= f.x + f.w && top + r.h * v.k <= f.y + f.h
|
|
129
|
+
return left >= f.x && top >= f.y && left + r.w * v.k <= f.x + f.w && top + r.h * v.k <= f.y + f.h;
|
|
130
|
+
}
|
|
131
|
+
/** The view that brings `r` (a box) into the middle of the free part at the same scale; null when it shows whole. */
|
|
132
|
+
function bring(v, vp, r) {
|
|
133
|
+
const f = free(vp);
|
|
134
|
+
return seen(v, vp, r) ? null : at(r.x + r.w / 2, r.y + r.h / 2, f.x + f.w / 2, f.y + f.h / 2, v.k, vp);
|
|
130
135
|
}
|
|
131
136
|
/**
|
|
132
137
|
* The box `v` holds on to as the diagram moves from `from` to `to`: of the boxes in both, the one nearest the middle of
|
|
@@ -186,6 +191,10 @@ const whole = (s) => ({
|
|
|
186
191
|
w: s.width,
|
|
187
192
|
h: s.height
|
|
188
193
|
});
|
|
194
|
+
/** Seconds a jump from a button, a key or `show` takes; reduced motion cuts. */
|
|
195
|
+
const FLIGHT = .2;
|
|
196
|
+
/** Room `show` leaves around the boxes, in scene units: a limit's tag sits above its box. */
|
|
197
|
+
const ROOM = 30;
|
|
189
198
|
/**
|
|
190
199
|
* The reader's view of a board that pans and zooms: the board in pixels with what floats over it, and where the reader
|
|
191
200
|
* has moved. It comes with the code that pans and zooms, so a page that never zooms does not load it; the engine asks
|
|
@@ -198,6 +207,8 @@ var Viewer = class {
|
|
|
198
207
|
#view = null;
|
|
199
208
|
/** The box the view keeps still while the diagram moves to a new structure, and the view's centre from it. */
|
|
200
209
|
#anchor = null;
|
|
210
|
+
/** The frame a flight asked for next: a new move of the reader's takes over from it. */
|
|
211
|
+
#flight = 0;
|
|
201
212
|
constructor(engine, viewport) {
|
|
202
213
|
this.engine = engine;
|
|
203
214
|
this.viewport = viewport;
|
|
@@ -264,6 +275,51 @@ var Viewer = class {
|
|
|
264
275
|
this.#anchor = this.#view && scene && f !== scene ? anchorOf(this.#view, this.viewport, f, scene) : null;
|
|
265
276
|
this.#show();
|
|
266
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Moves the view to `to` (null: fitted). With `fly` it flies there, on the wall clock (a reader's view is never in a
|
|
280
|
+
* recording); without, and with reduced motion, it is there at once.
|
|
281
|
+
*/
|
|
282
|
+
go(to, fly) {
|
|
283
|
+
this.land();
|
|
284
|
+
const { engine } = this;
|
|
285
|
+
const from = this.shownView();
|
|
286
|
+
const target = to ?? this.fit();
|
|
287
|
+
if (!fly || engine.reducedMotion || !from || !target) {
|
|
288
|
+
this.setView(to);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (engine.playing) this.setView(from);
|
|
292
|
+
const t0 = performance.now();
|
|
293
|
+
const frame = (now) => {
|
|
294
|
+
const t = (now - t0) / 1e3 / FLIGHT;
|
|
295
|
+
if (engine.playing) return;
|
|
296
|
+
this.setView(t >= 1 ? to : towards(from, target, t));
|
|
297
|
+
if (t < 1) this.#flight = requestAnimationFrame(frame);
|
|
298
|
+
};
|
|
299
|
+
this.#flight = requestAnimationFrame(frame);
|
|
300
|
+
}
|
|
301
|
+
/** Ends a flight where it is. */
|
|
302
|
+
land() {
|
|
303
|
+
cancelAnimationFrame(this.#flight);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Brings these boxes into view, flying there: at the same zoom, further out only as far as it takes to show them
|
|
307
|
+
* all. Nothing when they show already: a view the reader never moved shows the whole diagram.
|
|
308
|
+
*/
|
|
309
|
+
show(ids) {
|
|
310
|
+
const v = this.#view && !this.engine.camera && this.shownView();
|
|
311
|
+
const ns = this.engine.frame?.nodes.filter((n) => ids.includes(n.id));
|
|
312
|
+
if (!v || !ns?.length) return;
|
|
313
|
+
const x = Math.min(...ns.map((n) => n.x)) - ROOM;
|
|
314
|
+
const y = Math.min(...ns.map((n) => n.y)) - ROOM;
|
|
315
|
+
const r = {
|
|
316
|
+
x,
|
|
317
|
+
y,
|
|
318
|
+
w: Math.max(...ns.map((n) => n.x + n.w)) + ROOM - x,
|
|
319
|
+
h: Math.max(...ns.map((n) => n.y + n.h)) + ROOM - y
|
|
320
|
+
};
|
|
321
|
+
if (!seen(v, this.viewport, r)) this.go(frame(r, this.viewport, v.k), true);
|
|
322
|
+
}
|
|
267
323
|
/** The part of the scene the board shows now: its viewBox. */
|
|
268
324
|
box() {
|
|
269
325
|
const v = this.shownView();
|
|
@@ -339,44 +395,6 @@ const ARROW = {
|
|
|
339
395
|
step: 40,
|
|
340
396
|
shift: 200
|
|
341
397
|
};
|
|
342
|
-
/** Seconds a jump from a button or a key takes; reduced motion cuts. */
|
|
343
|
-
const FLIGHT = .2;
|
|
344
|
-
const flights = /* @__PURE__ */ new WeakMap();
|
|
345
|
-
function land(viewer) {
|
|
346
|
-
const raf = flights.get(viewer);
|
|
347
|
-
if (raf != null) cancelAnimationFrame(raf);
|
|
348
|
-
flights.delete(viewer);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Moves the reader's view to `to` (null: fitted). From a button or a key it flies there, on the wall clock (a reader's
|
|
352
|
-
* view is never in a recording); from a drag or the wheel, and with reduced motion, it is there at once.
|
|
353
|
-
*/
|
|
354
|
-
function goTo(viewer, to, fly) {
|
|
355
|
-
land(viewer);
|
|
356
|
-
const from = viewer.shownView();
|
|
357
|
-
const target = to ?? viewer.fit();
|
|
358
|
-
if (!fly || viewer.engine.reducedMotion || !from || !target) {
|
|
359
|
-
viewer.setView(to);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
if (viewer.engine.playing) viewer.setView(from);
|
|
363
|
-
const t0 = performance.now();
|
|
364
|
-
const frame = (now) => {
|
|
365
|
-
if (viewer.engine.playing) {
|
|
366
|
-
flights.delete(viewer);
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
const t = (now - t0) / 1e3 / FLIGHT;
|
|
370
|
-
if (t >= 1) {
|
|
371
|
-
flights.delete(viewer);
|
|
372
|
-
viewer.setView(to);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
viewer.setView(towards(from, target, t));
|
|
376
|
-
flights.set(viewer, requestAnimationFrame(frame));
|
|
377
|
-
};
|
|
378
|
-
flights.set(viewer, requestAnimationFrame(frame));
|
|
379
|
-
}
|
|
380
398
|
/** Zooms by `factor` about the middle of the free part of the board. */
|
|
381
399
|
function zoomBy(viewer, factor) {
|
|
382
400
|
const v = viewer.shownView();
|
|
@@ -385,7 +403,7 @@ function zoomBy(viewer, factor) {
|
|
|
385
403
|
if (!v || !vp || !r) return;
|
|
386
404
|
const f = free(vp);
|
|
387
405
|
const k = Math.min(r.max, Math.max(r.min, v.k * factor));
|
|
388
|
-
|
|
406
|
+
viewer.go(zoomAt(v, vp, f.x + f.w / 2, f.y + f.h / 2, k / v.k), true);
|
|
389
407
|
}
|
|
390
408
|
/** The scene at one board pixel a scene unit, about the middle of the free part. */
|
|
391
409
|
function actualSize(viewer) {
|
|
@@ -419,7 +437,7 @@ function attachZoom(board, viewer, o) {
|
|
|
419
437
|
} catch {}
|
|
420
438
|
};
|
|
421
439
|
const move = (to) => {
|
|
422
|
-
land(
|
|
440
|
+
viewer.land();
|
|
423
441
|
viewer.setView(to);
|
|
424
442
|
};
|
|
425
443
|
const touch = () => {
|
|
@@ -513,8 +531,8 @@ function attachZoom(board, viewer, o) {
|
|
|
513
531
|
}[e.key];
|
|
514
532
|
if (e.key === "+" || e.key === "=") zoomBy(viewer, ZOOM_STEP);
|
|
515
533
|
else if (e.key === "-" || e.key === "_") zoomBy(viewer, 1 / ZOOM_STEP);
|
|
516
|
-
else if (e.key === "0")
|
|
517
|
-
else if (pan)
|
|
534
|
+
else if (e.key === "0") viewer.go(null, true);
|
|
535
|
+
else if (pan) viewer.go(panBy(v, pan[0], pan[1]), false);
|
|
518
536
|
else return;
|
|
519
537
|
e.preventDefault();
|
|
520
538
|
};
|
|
@@ -526,7 +544,7 @@ function attachZoom(board, viewer, o) {
|
|
|
526
544
|
const v = viewer.shownView();
|
|
527
545
|
if (!n || !v || !viewer.viewport || viewer.engine.playing) return;
|
|
528
546
|
const to = bring(v, viewer.viewport, n);
|
|
529
|
-
if (to)
|
|
547
|
+
if (to) viewer.go(to, true);
|
|
530
548
|
};
|
|
531
549
|
touch();
|
|
532
550
|
const off = viewer.engine.subscribe(touch);
|
|
@@ -539,7 +557,7 @@ function attachZoom(board, viewer, o) {
|
|
|
539
557
|
board.addEventListener("keydown", key);
|
|
540
558
|
board.addEventListener("focusin", focus);
|
|
541
559
|
return () => {
|
|
542
|
-
land(
|
|
560
|
+
viewer.land();
|
|
543
561
|
off();
|
|
544
562
|
for (const a of [
|
|
545
563
|
"tabindex",
|
|
@@ -659,7 +677,7 @@ function ZoomControls({ engine }) {
|
|
|
659
677
|
type: "button",
|
|
660
678
|
className: "lm-btn",
|
|
661
679
|
"aria-keyshortcuts": "0",
|
|
662
|
-
onClick: () =>
|
|
680
|
+
onClick: () => viewer.go(null, true),
|
|
663
681
|
children: "Fit"
|
|
664
682
|
})
|
|
665
683
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loadmap/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
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",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@loadmap/core": "0.
|
|
39
|
-
"@loadmap/dsl": "0.
|
|
40
|
-
"@loadmap/sim": "0.
|
|
41
|
-
"@loadmap/layout": "0.
|
|
38
|
+
"@loadmap/core": "0.26.1",
|
|
39
|
+
"@loadmap/dsl": "0.26.1",
|
|
40
|
+
"@loadmap/sim": "0.26.1",
|
|
41
|
+
"@loadmap/layout": "0.26.1",
|
|
42
42
|
"elkjs": "^0.12.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|