@peers-app/peers-ui 0.33.20 → 0.33.22
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/command-palette/command-palette.js +3 -43
- package/dist/components/markdown-editor/autolink-plugin.d.ts +5 -1
- package/dist/components/markdown-editor/autolink-plugin.js +5 -8
- package/dist/components/markdown-editor/blocks.d.ts +83 -0
- package/dist/components/markdown-editor/blocks.js +201 -0
- package/dist/components/markdown-editor/code-plugin.d.ts +21 -0
- package/dist/components/markdown-editor/code-plugin.js +109 -0
- package/dist/components/markdown-editor/editor.d.ts +12 -5
- package/dist/components/markdown-editor/editor.js +27 -6
- package/dist/components/markdown-editor/link-plugin.d.ts +41 -0
- package/dist/components/markdown-editor/link-plugin.js +334 -0
- package/dist/components/markdown-editor/markdown-plugin.d.ts +8 -5
- package/dist/components/markdown-editor/markdown-plugin.js +14 -7
- package/dist/components/markdown-editor/mentions-plugin.js +5 -1
- package/dist/components/markdown-editor/theme.d.ts +35 -0
- package/dist/components/markdown-editor/theme.js +36 -0
- package/dist/components/markdown-editor/toolbar.d.ts +11 -0
- package/dist/components/markdown-editor/toolbar.js +16 -5
- package/dist/components/qr-scanner.js +2 -34
- package/dist/graph/ring-layout.d.ts +62 -0
- package/dist/graph/ring-layout.js +100 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
- package/dist/screens/network-viewer/graph/edge-route.js +133 -0
- package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
- package/dist/screens/network-viewer/graph/label-placement.js +134 -0
- package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
- package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
- package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
- package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
- package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
- package/dist/screens/network-viewer/graph/network-graph.js +419 -0
- package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
- package/dist/screens/network-viewer/network-viewer.js +65 -8
- package/dist/tabs-layout/linger.d.ts +75 -0
- package/dist/tabs-layout/linger.js +121 -0
- package/dist/tabs-layout/network-status-details.d.ts +27 -0
- package/dist/tabs-layout/network-status-details.js +203 -0
- package/dist/tabs-layout/network-status-format.d.ts +22 -0
- package/dist/tabs-layout/network-status-format.js +58 -0
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
- package/dist/tabs-layout/network-status-indicator.js +27 -133
- package/dist/tabs-layout/network-status-model.d.ts +71 -0
- package/dist/tabs-layout/network-status-model.js +155 -0
- package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
- package/dist/tabs-layout/use-network-details-data.js +90 -0
- package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
- package/dist/tabs-layout/use-syncing-look.js +50 -0
- package/dist/theme.css +846 -0
- package/package.json +10 -8
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.canScanQr = canScanQr;
|
|
37
4
|
exports.QrScanner = QrScanner;
|
|
@@ -130,7 +97,8 @@ function QrScanner(props) {
|
|
|
130
97
|
(async () => {
|
|
131
98
|
try {
|
|
132
99
|
if (!detector) {
|
|
133
|
-
|
|
100
|
+
// Loaded on first use. A `require`, as `import()` would be a separate bundle chunk.
|
|
101
|
+
jsqr = require("jsqr").default;
|
|
134
102
|
}
|
|
135
103
|
stream = await navigator.mediaDevices.getUserMedia({
|
|
136
104
|
video: { facingMode: { ideal: "environment" } },
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ring layout for a graph drawn around one node: the center, what it connects to on the first
|
|
3
|
+
* ring, what those connect to on the second, and so on. Plain math with no rendering, so each
|
|
4
|
+
* view draws its own nodes and edges. Lifted from the Notes package's Graph view.
|
|
5
|
+
*/
|
|
6
|
+
/** A node's place: its ring (0 is the center), angle, and the slice of circle it owns. */
|
|
7
|
+
export interface RingPlaced {
|
|
8
|
+
key: string;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
/** How many steps from the center. */
|
|
12
|
+
ring: number;
|
|
13
|
+
/** Direction from the center, in radians; straight up is `-Math.PI / 2`. */
|
|
14
|
+
angle: number;
|
|
15
|
+
/** The arc this node owns; its own neighbors fan out inside it. */
|
|
16
|
+
span: number;
|
|
17
|
+
/** The node it was reached from. */
|
|
18
|
+
parent?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What {@link layoutRings} needs. */
|
|
21
|
+
export interface RingLayoutOptions {
|
|
22
|
+
/** The node at the center. */
|
|
23
|
+
center: string;
|
|
24
|
+
/** A node's neighbors, in the order to place them. Unknown keys return an empty list. */
|
|
25
|
+
neighbors: (key: string) => readonly string[];
|
|
26
|
+
/** How many rings; 0 for as many as there are. */
|
|
27
|
+
steps: number;
|
|
28
|
+
/** How far the outer ring reaches across. */
|
|
29
|
+
rx: number;
|
|
30
|
+
/** How far the outer ring reaches up and down. */
|
|
31
|
+
ry: number;
|
|
32
|
+
/** The most nodes to place, center included. 60 unless set. */
|
|
33
|
+
maxNodes?: number;
|
|
34
|
+
}
|
|
35
|
+
/** A laid-out graph. */
|
|
36
|
+
export interface RingLayout {
|
|
37
|
+
/** The placed nodes, center first, then ring by ring. */
|
|
38
|
+
nodes: RingPlaced[];
|
|
39
|
+
/** For a node whose neighbors didn't all fit under the cap, how many were left out. */
|
|
40
|
+
more: Map<string, number>;
|
|
41
|
+
}
|
|
42
|
+
/** The most nodes a layout places unless told otherwise. */
|
|
43
|
+
export declare const RING_LAYOUT_MAX_NODES = 60;
|
|
44
|
+
/**
|
|
45
|
+
* Lay a graph out in rings around the center, one step per ring. The first ring shares the
|
|
46
|
+
* whole circle; each node's own neighbors fan out inside its slice. A node is placed once, on
|
|
47
|
+
* the first ring that reaches it. Nodes with no path to the center are left out.
|
|
48
|
+
*
|
|
49
|
+
* @param options - The center, the neighbors of each node, and the room there is.
|
|
50
|
+
* @returns Each placed node, and how many neighbors the cap left out per node.
|
|
51
|
+
*/
|
|
52
|
+
export declare function layoutRings(options: RingLayoutOptions): RingLayout;
|
|
53
|
+
/**
|
|
54
|
+
* Fit a layout to the space it has: center its nodes in it, and stretch each direction (up to
|
|
55
|
+
* half again) to fill it. Rings are laid out around the center, so a graph that grows one way
|
|
56
|
+
* would otherwise leave the other side empty.
|
|
57
|
+
*
|
|
58
|
+
* @param nodes - The laid-out nodes; they're moved in place.
|
|
59
|
+
* @param width - The room across, after margins for labels.
|
|
60
|
+
* @param height - The room up and down, after margins for labels.
|
|
61
|
+
*/
|
|
62
|
+
export declare function fitRingLayout(nodes: RingPlaced[], width: number, height: number): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ring layout for a graph drawn around one node: the center, what it connects to on the first
|
|
4
|
+
* ring, what those connect to on the second, and so on. Plain math with no rendering, so each
|
|
5
|
+
* view draws its own nodes and edges. Lifted from the Notes package's Graph view.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.RING_LAYOUT_MAX_NODES = void 0;
|
|
9
|
+
exports.layoutRings = layoutRings;
|
|
10
|
+
exports.fitRingLayout = fitRingLayout;
|
|
11
|
+
/** The most nodes a layout places unless told otherwise. */
|
|
12
|
+
exports.RING_LAYOUT_MAX_NODES = 60;
|
|
13
|
+
/**
|
|
14
|
+
* Lay a graph out in rings around the center, one step per ring. The first ring shares the
|
|
15
|
+
* whole circle; each node's own neighbors fan out inside its slice. A node is placed once, on
|
|
16
|
+
* the first ring that reaches it. Nodes with no path to the center are left out.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The center, the neighbors of each node, and the room there is.
|
|
19
|
+
* @returns Each placed node, and how many neighbors the cap left out per node.
|
|
20
|
+
*/
|
|
21
|
+
function layoutRings(options) {
|
|
22
|
+
const { center, neighbors, steps, rx, ry } = options;
|
|
23
|
+
const maxNodes = options.maxNodes ?? exports.RING_LAYOUT_MAX_NODES;
|
|
24
|
+
const placed = new Map([
|
|
25
|
+
[center, { key: center, x: 0, y: 0, ring: 0, angle: -Math.PI / 2, span: 2 * Math.PI }],
|
|
26
|
+
]);
|
|
27
|
+
const more = new Map();
|
|
28
|
+
const rings = [[center]];
|
|
29
|
+
const last = steps === 0 ? Number.POSITIVE_INFINITY : steps;
|
|
30
|
+
for (let ring = 1; ring <= last; ring++) {
|
|
31
|
+
const next = [];
|
|
32
|
+
for (const parentKey of rings[ring - 1]) {
|
|
33
|
+
const parent = placed.get(parentKey);
|
|
34
|
+
const wanted = [...new Set(neighbors(parentKey))].filter((key) => !placed.has(key));
|
|
35
|
+
const kids = wanted.slice(0, Math.max(0, maxNodes - placed.size));
|
|
36
|
+
if (kids.length < wanted.length)
|
|
37
|
+
more.set(parentKey, wanted.length - kids.length);
|
|
38
|
+
if (!kids.length)
|
|
39
|
+
continue;
|
|
40
|
+
const span = ring === 1 ? 2 * Math.PI : parent.span * 0.9;
|
|
41
|
+
kids.forEach((key, index) => {
|
|
42
|
+
const angle = ring === 1
|
|
43
|
+
? -Math.PI / 2 + (index * span) / kids.length
|
|
44
|
+
: parent.angle - span / 2 + ((index + 0.5) * span) / kids.length;
|
|
45
|
+
placed.set(key, {
|
|
46
|
+
key,
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
ring,
|
|
50
|
+
angle,
|
|
51
|
+
span: span / kids.length,
|
|
52
|
+
parent: parentKey,
|
|
53
|
+
});
|
|
54
|
+
next.push(key);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!next.length)
|
|
58
|
+
break;
|
|
59
|
+
rings.push(next);
|
|
60
|
+
}
|
|
61
|
+
const deepest = rings.length - 1;
|
|
62
|
+
for (const node of placed.values()) {
|
|
63
|
+
if (!node.ring)
|
|
64
|
+
continue;
|
|
65
|
+
const f = (node.ring / deepest) ** 0.85;
|
|
66
|
+
// A single ring stays close to the center instead of spreading to the edges.
|
|
67
|
+
const fx = deepest === 1 ? Math.min(270, rx * 0.78) : rx * f;
|
|
68
|
+
const fy = deepest === 1 ? Math.min(220, ry * 0.78) : ry * f;
|
|
69
|
+
node.x = Math.cos(node.angle) * fx;
|
|
70
|
+
node.y = Math.sin(node.angle) * fy;
|
|
71
|
+
}
|
|
72
|
+
return { nodes: [...placed.values()], more };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Fit a layout to the space it has: center its nodes in it, and stretch each direction (up to
|
|
76
|
+
* half again) to fill it. Rings are laid out around the center, so a graph that grows one way
|
|
77
|
+
* would otherwise leave the other side empty.
|
|
78
|
+
*
|
|
79
|
+
* @param nodes - The laid-out nodes; they're moved in place.
|
|
80
|
+
* @param width - The room across, after margins for labels.
|
|
81
|
+
* @param height - The room up and down, after margins for labels.
|
|
82
|
+
*/
|
|
83
|
+
function fitRingLayout(nodes, width, height) {
|
|
84
|
+
if (nodes.length < 2)
|
|
85
|
+
return;
|
|
86
|
+
const xs = nodes.map((node) => node.x);
|
|
87
|
+
const ys = nodes.map((node) => node.y);
|
|
88
|
+
const minX = Math.min(...xs);
|
|
89
|
+
const maxX = Math.max(...xs);
|
|
90
|
+
const minY = Math.min(...ys);
|
|
91
|
+
const maxY = Math.max(...ys);
|
|
92
|
+
const sx = maxX > minX ? Math.min(1.5, width / (maxX - minX)) : 1;
|
|
93
|
+
const sy = maxY > minY ? Math.min(1.5, height / (maxY - minY)) : 1;
|
|
94
|
+
const midX = (minX + maxX) / 2;
|
|
95
|
+
const midY = (minY + maxY) / 2;
|
|
96
|
+
for (const node of nodes) {
|
|
97
|
+
node.x = (node.x - midX) * sx;
|
|
98
|
+
node.y = (node.y - midY) * sy;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./components/sortable-list";
|
|
|
13
13
|
export * from "./components/tabs";
|
|
14
14
|
export { Typeahead, type TypeaheadItem } from "./components/typeahead";
|
|
15
15
|
export { isDesktop, mainContentPath } from "./globals";
|
|
16
|
+
export * from "./graph/ring-layout";
|
|
16
17
|
export * from "./groups";
|
|
17
18
|
export * from "./hooks";
|
|
18
19
|
export { openLink } from "./host-shell/host-shell-consumer";
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ var globals_1 = require("./globals");
|
|
|
35
35
|
Object.defineProperty(exports, "isDesktop", { enumerable: true, get: function () { return globals_1.isDesktop; } });
|
|
36
36
|
Object.defineProperty(exports, "mainContentPath", { enumerable: true, get: function () { return globals_1.mainContentPath; } });
|
|
37
37
|
// Groups: names, colors and icons from System Groups, and the dialog that edits a group's look.
|
|
38
|
+
__exportStar(require("./graph/ring-layout"), exports);
|
|
38
39
|
__exportStar(require("./groups"), exports);
|
|
39
40
|
__exportStar(require("./hooks"), exports);
|
|
40
41
|
var host_shell_consumer_1 = require("./host-shell/host-shell-consumer");
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** A point on the stage. */
|
|
2
|
+
export interface RoutePoint {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
/** A device on the stage: where it is and how big its circle is. */
|
|
7
|
+
export interface RouteNode extends RoutePoint {
|
|
8
|
+
key: string;
|
|
9
|
+
/** The circle's radius. */
|
|
10
|
+
r: number;
|
|
11
|
+
}
|
|
12
|
+
/** The room kept between a line and a circle it goes around, in pixels. */
|
|
13
|
+
export declare const ROUTE_MARGIN = 16;
|
|
14
|
+
/**
|
|
15
|
+
* Where to bend the line between two devices so it passes no other device's circle. The line
|
|
16
|
+
* becomes a quadratic curve through the returned control point. Of the gentle bends that clear
|
|
17
|
+
* every circle, it takes the one that leaves each end at the widest angle from that end's other
|
|
18
|
+
* lines, so it neither runs along one of them nor looks like it carries on from one; the gentler
|
|
19
|
+
* bend wins a near tie. With no other lines it bends just enough.
|
|
20
|
+
*
|
|
21
|
+
* @param from - One end.
|
|
22
|
+
* @param to - The other end.
|
|
23
|
+
* @param nodes - Every device on the stage; the two ends are skipped.
|
|
24
|
+
* @param linesAt - Where each device's lines go: the far end of each.
|
|
25
|
+
* @returns The control point, or undefined when the straight line is clear.
|
|
26
|
+
*/
|
|
27
|
+
export declare function bendAround(from: RouteNode, to: RouteNode, nodes: readonly RouteNode[], linesAt?: (key: string) => readonly RoutePoint[]): RoutePoint | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* A point on the curve from `from` to `to` through `control`.
|
|
30
|
+
*
|
|
31
|
+
* @param t - How far along, 0 to 1.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pointOnCurve(from: RoutePoint, control: RoutePoint, to: RoutePoint, t: number): RoutePoint;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Where a line between two devices goes: straight, or bent around a device it would otherwise
|
|
3
|
+
// pass over. A straight line through a device reads as a connection through it.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ROUTE_MARGIN = void 0;
|
|
6
|
+
exports.bendAround = bendAround;
|
|
7
|
+
exports.pointOnCurve = pointOnCurve;
|
|
8
|
+
/** The room kept between a line and a circle it goes around, in pixels. */
|
|
9
|
+
exports.ROUTE_MARGIN = 16;
|
|
10
|
+
/** Bends whose end angles differ by less than this, in radians, count as equally clear. */
|
|
11
|
+
const ANGLE_TIE = Math.PI / 180;
|
|
12
|
+
/** How many bends are tried on each side, from the least that clears to the gentlest limit. */
|
|
13
|
+
const STEPS = 32;
|
|
14
|
+
/**
|
|
15
|
+
* The most a line bows to keep its ends clear of other lines, as control-point depth over its
|
|
16
|
+
* length: the curve's middle then sits at most an eighth of the length out. It bows further only
|
|
17
|
+
* when it must, to clear a circle.
|
|
18
|
+
*/
|
|
19
|
+
const GENTLE = 0.25;
|
|
20
|
+
/**
|
|
21
|
+
* Where to bend the line between two devices so it passes no other device's circle. The line
|
|
22
|
+
* becomes a quadratic curve through the returned control point. Of the gentle bends that clear
|
|
23
|
+
* every circle, it takes the one that leaves each end at the widest angle from that end's other
|
|
24
|
+
* lines, so it neither runs along one of them nor looks like it carries on from one; the gentler
|
|
25
|
+
* bend wins a near tie. With no other lines it bends just enough.
|
|
26
|
+
*
|
|
27
|
+
* @param from - One end.
|
|
28
|
+
* @param to - The other end.
|
|
29
|
+
* @param nodes - Every device on the stage; the two ends are skipped.
|
|
30
|
+
* @param linesAt - Where each device's lines go: the far end of each.
|
|
31
|
+
* @returns The control point, or undefined when the straight line is clear.
|
|
32
|
+
*/
|
|
33
|
+
function bendAround(from, to, nodes, linesAt = () => []) {
|
|
34
|
+
const dx = to.x - from.x;
|
|
35
|
+
const dy = to.y - from.y;
|
|
36
|
+
const length = Math.hypot(dx, dy);
|
|
37
|
+
if (length < 1)
|
|
38
|
+
return undefined;
|
|
39
|
+
const ux = dx / length;
|
|
40
|
+
const uy = dy / length;
|
|
41
|
+
// A unit vector across the line.
|
|
42
|
+
const nx = -uy;
|
|
43
|
+
const ny = ux;
|
|
44
|
+
const hits = [];
|
|
45
|
+
for (const node of nodes) {
|
|
46
|
+
if (node.key === from.key || node.key === to.key)
|
|
47
|
+
continue;
|
|
48
|
+
const rx = node.x - from.x;
|
|
49
|
+
const ry = node.y - from.y;
|
|
50
|
+
// How far along the line the circle sits, 0 to 1; one right at an end can't be bent around.
|
|
51
|
+
const t = (rx * ux + ry * uy) / length;
|
|
52
|
+
if (t < 0.08 || t > 0.92)
|
|
53
|
+
continue;
|
|
54
|
+
const side = rx * nx + ry * ny;
|
|
55
|
+
const room = node.r + exports.ROUTE_MARGIN;
|
|
56
|
+
if (Math.abs(side) < room)
|
|
57
|
+
hits.push({ t, side, room });
|
|
58
|
+
}
|
|
59
|
+
if (!hits.length)
|
|
60
|
+
return undefined;
|
|
61
|
+
// A curve through control offset `depth` sits 2t(1-t)·depth from the straight line at t.
|
|
62
|
+
const leastDepth = (direction) => {
|
|
63
|
+
let depth = 0;
|
|
64
|
+
for (const hit of hits) {
|
|
65
|
+
const towards = hit.side * direction;
|
|
66
|
+
// Bowing away from a circle needs room minus how far it already is; bowing towards one
|
|
67
|
+
// has to pass all the way beyond it.
|
|
68
|
+
const away = towards > 0 ? towards + hit.room : hit.room + towards;
|
|
69
|
+
depth = Math.max(depth, away / (2 * hit.t * (1 - hit.t)));
|
|
70
|
+
}
|
|
71
|
+
return depth;
|
|
72
|
+
};
|
|
73
|
+
const controlFor = (direction, depth) => ({
|
|
74
|
+
x: (from.x + to.x) / 2 + nx * direction * depth,
|
|
75
|
+
y: (from.y + to.y) / 2 + ny * direction * depth,
|
|
76
|
+
});
|
|
77
|
+
// Never more than 40% of the length out at the middle, so it stays an arc and never a loop.
|
|
78
|
+
const most = 0.8 * length;
|
|
79
|
+
let best;
|
|
80
|
+
for (const direction of [1, -1]) {
|
|
81
|
+
const least = leastDepth(direction);
|
|
82
|
+
if (least > most)
|
|
83
|
+
continue;
|
|
84
|
+
const gentlest = Math.max(least, GENTLE * length);
|
|
85
|
+
for (let step = 0; step <= STEPS; step++) {
|
|
86
|
+
const depth = least + ((gentlest - least) * step) / STEPS;
|
|
87
|
+
const control = controlFor(direction, depth);
|
|
88
|
+
const angle = clearance(from, to, control, linesAt);
|
|
89
|
+
if (!best ||
|
|
90
|
+
angle > best.angle + ANGLE_TIE ||
|
|
91
|
+
(angle > best.angle - ANGLE_TIE && depth < best.depth)) {
|
|
92
|
+
best = { control, angle, depth };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Nothing within reach clears every circle: bend as far as allowed, on the easier side.
|
|
97
|
+
return best?.control ?? controlFor(leastDepth(-1) < leastDepth(1) ? -1 : 1, most);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The smallest angle, in radians, between the way a bent line leaves either end and that end's
|
|
101
|
+
* other lines.
|
|
102
|
+
*/
|
|
103
|
+
function clearance(from, to, control, linesAt) {
|
|
104
|
+
let least = Math.PI;
|
|
105
|
+
for (const [end, other] of [
|
|
106
|
+
[from, to],
|
|
107
|
+
[to, from],
|
|
108
|
+
]) {
|
|
109
|
+
const leaving = Math.atan2(control.y - end.y, control.x - end.x);
|
|
110
|
+
for (const far of linesAt(end.key)) {
|
|
111
|
+
if (far.x === other.x && far.y === other.y)
|
|
112
|
+
continue;
|
|
113
|
+
const along = Math.atan2(far.y - end.y, far.x - end.x);
|
|
114
|
+
const gap = Math.abs(((leaving - along + 3 * Math.PI) % (2 * Math.PI)) - Math.PI);
|
|
115
|
+
least = Math.min(least, gap);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return least;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A point on the curve from `from` to `to` through `control`.
|
|
122
|
+
*
|
|
123
|
+
* @param t - How far along, 0 to 1.
|
|
124
|
+
*/
|
|
125
|
+
function pointOnCurve(from, control, to, t) {
|
|
126
|
+
const a = (1 - t) * (1 - t);
|
|
127
|
+
const b = 2 * t * (1 - t);
|
|
128
|
+
const c = t * t;
|
|
129
|
+
return {
|
|
130
|
+
x: a * from.x + b * control.x + c * to.x,
|
|
131
|
+
y: a * from.y + b * control.y + c * to.y,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Where a device's name sits around its circle. */
|
|
2
|
+
export type LabelSide = "below" | "above" | "right" | "left";
|
|
3
|
+
/** A device whose name needs a place, with its circle and the size of its name. */
|
|
4
|
+
export interface LabelNode {
|
|
5
|
+
key: string;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
/** The circle's radius. */
|
|
9
|
+
r: number;
|
|
10
|
+
/** The name's width and height, estimated. */
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
/** A line drawn between two devices, and which of its ends carry an arrowhead. */
|
|
15
|
+
export interface LabelSegment {
|
|
16
|
+
a: string;
|
|
17
|
+
b: string;
|
|
18
|
+
x1: number;
|
|
19
|
+
y1: number;
|
|
20
|
+
x2: number;
|
|
21
|
+
y2: number;
|
|
22
|
+
arrowAtA: boolean;
|
|
23
|
+
arrowAtB: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** A rectangle, as its left, top, right and bottom edges. */
|
|
26
|
+
export interface LabelBox {
|
|
27
|
+
x0: number;
|
|
28
|
+
y0: number;
|
|
29
|
+
x1: number;
|
|
30
|
+
y1: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Estimate how much room a device's name takes, for a font size in pixels.
|
|
34
|
+
*
|
|
35
|
+
* SVG text can't be measured before it is drawn, so this uses an average character width,
|
|
36
|
+
* a little wider for bold.
|
|
37
|
+
*/
|
|
38
|
+
export declare function estimateLabelSize(text: string, fontSize: number, bold?: boolean): {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
/** The rectangle a device's name covers on one side of its circle. */
|
|
43
|
+
export declare function labelBox(node: LabelNode, side: LabelSide): LabelBox;
|
|
44
|
+
/** Whether a line passes through a rectangle (Liang–Barsky clipping). */
|
|
45
|
+
export declare function segmentCrossesBox(segment: Pick<LabelSegment, "x1" | "y1" | "x2" | "y2">, box: LabelBox): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Choose a side for each device's name, where it hides the least.
|
|
48
|
+
*
|
|
49
|
+
* Each name tries below, above, right and left of its circle, in that order of preference,
|
|
50
|
+
* and takes the side with the least in the way: arrowheads pointing at its own device count
|
|
51
|
+
* most, then other circles, names already placed, and lines. Devices are placed in the order
|
|
52
|
+
* given, so put the ones whose names matter most first.
|
|
53
|
+
*/
|
|
54
|
+
export declare function placeLabels(nodes: readonly LabelNode[], segments: readonly LabelSegment[]): Map<string, LabelSide>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateLabelSize = estimateLabelSize;
|
|
4
|
+
exports.labelBox = labelBox;
|
|
5
|
+
exports.segmentCrossesBox = segmentCrossesBox;
|
|
6
|
+
exports.placeLabels = placeLabels;
|
|
7
|
+
/** The space between a circle and its name. */
|
|
8
|
+
const GAP = 4;
|
|
9
|
+
/** The sides tried, with what each costs before anything is in its way: below reads best. */
|
|
10
|
+
const SIDES = [
|
|
11
|
+
["below", 0],
|
|
12
|
+
["above", 0.5],
|
|
13
|
+
["right", 2.5],
|
|
14
|
+
["left", 3],
|
|
15
|
+
];
|
|
16
|
+
/** What one thing in a name's way costs. */
|
|
17
|
+
const COST = {
|
|
18
|
+
/** An arrowhead pointing at this device: the name's outline would hide it. */
|
|
19
|
+
arrowHere: 4,
|
|
20
|
+
/** Another device's circle. */
|
|
21
|
+
circle: 5,
|
|
22
|
+
/** A name already placed. */
|
|
23
|
+
label: 3,
|
|
24
|
+
/** One of this device's own lines. */
|
|
25
|
+
ownLine: 1.5,
|
|
26
|
+
/** Any other line. */
|
|
27
|
+
line: 1,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Estimate how much room a device's name takes, for a font size in pixels.
|
|
31
|
+
*
|
|
32
|
+
* SVG text can't be measured before it is drawn, so this uses an average character width,
|
|
33
|
+
* a little wider for bold.
|
|
34
|
+
*/
|
|
35
|
+
function estimateLabelSize(text, fontSize, bold = false) {
|
|
36
|
+
return { width: text.length * fontSize * (bold ? 0.62 : 0.56), height: fontSize + 2 };
|
|
37
|
+
}
|
|
38
|
+
/** The rectangle a device's name covers on one side of its circle. */
|
|
39
|
+
function labelBox(node, side) {
|
|
40
|
+
const { x, y, r, width, height } = node;
|
|
41
|
+
switch (side) {
|
|
42
|
+
case "below":
|
|
43
|
+
return { x0: x - width / 2, y0: y + r + GAP, x1: x + width / 2, y1: y + r + GAP + height };
|
|
44
|
+
case "above":
|
|
45
|
+
return { x0: x - width / 2, y0: y - r - GAP - height, x1: x + width / 2, y1: y - r - GAP };
|
|
46
|
+
case "right":
|
|
47
|
+
return { x0: x + r + GAP, y0: y - height / 2, x1: x + r + GAP + width, y1: y + height / 2 };
|
|
48
|
+
case "left":
|
|
49
|
+
return { x0: x - r - GAP - width, y0: y - height / 2, x1: x - r - GAP, y1: y + height / 2 };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Whether a line passes through a rectangle (Liang–Barsky clipping). */
|
|
53
|
+
function segmentCrossesBox(segment, box) {
|
|
54
|
+
const dx = segment.x2 - segment.x1;
|
|
55
|
+
const dy = segment.y2 - segment.y1;
|
|
56
|
+
const p = [-dx, dx, -dy, dy];
|
|
57
|
+
const q = [segment.x1 - box.x0, box.x1 - segment.x1, segment.y1 - box.y0, box.y1 - segment.y1];
|
|
58
|
+
let t0 = 0;
|
|
59
|
+
let t1 = 1;
|
|
60
|
+
for (let i = 0; i < 4; i++) {
|
|
61
|
+
if (p[i] === 0) {
|
|
62
|
+
if (q[i] < 0)
|
|
63
|
+
return false;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const t = q[i] / p[i];
|
|
67
|
+
if (p[i] < 0) {
|
|
68
|
+
if (t > t1)
|
|
69
|
+
return false;
|
|
70
|
+
if (t > t0)
|
|
71
|
+
t0 = t;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (t < t0)
|
|
75
|
+
return false;
|
|
76
|
+
if (t < t1)
|
|
77
|
+
t1 = t;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
function circleTouchesBox(node, box) {
|
|
83
|
+
const nearestX = Math.max(box.x0, Math.min(node.x, box.x1));
|
|
84
|
+
const nearestY = Math.max(box.y0, Math.min(node.y, box.y1));
|
|
85
|
+
return Math.hypot(node.x - nearestX, node.y - nearestY) < node.r;
|
|
86
|
+
}
|
|
87
|
+
function boxesOverlap(a, b) {
|
|
88
|
+
return a.x0 < b.x1 && b.x0 < a.x1 && a.y0 < b.y1 && b.y0 < a.y1;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Choose a side for each device's name, where it hides the least.
|
|
92
|
+
*
|
|
93
|
+
* Each name tries below, above, right and left of its circle, in that order of preference,
|
|
94
|
+
* and takes the side with the least in the way: arrowheads pointing at its own device count
|
|
95
|
+
* most, then other circles, names already placed, and lines. Devices are placed in the order
|
|
96
|
+
* given, so put the ones whose names matter most first.
|
|
97
|
+
*/
|
|
98
|
+
function placeLabels(nodes, segments) {
|
|
99
|
+
const sides = new Map();
|
|
100
|
+
const placed = [];
|
|
101
|
+
for (const node of nodes) {
|
|
102
|
+
let best = "below";
|
|
103
|
+
let bestCost = Number.POSITIVE_INFINITY;
|
|
104
|
+
let bestBox = labelBox(node, best);
|
|
105
|
+
for (const [side, preference] of SIDES) {
|
|
106
|
+
const box = labelBox(node, side);
|
|
107
|
+
let cost = preference;
|
|
108
|
+
for (const segment of segments) {
|
|
109
|
+
if (!segmentCrossesBox(segment, box))
|
|
110
|
+
continue;
|
|
111
|
+
const arrowHere = (segment.a === node.key && segment.arrowAtA) ||
|
|
112
|
+
(segment.b === node.key && segment.arrowAtB);
|
|
113
|
+
const own = segment.a === node.key || segment.b === node.key;
|
|
114
|
+
cost += arrowHere ? COST.arrowHere : own ? COST.ownLine : COST.line;
|
|
115
|
+
}
|
|
116
|
+
for (const other of nodes) {
|
|
117
|
+
if (other !== node && circleTouchesBox(other, box))
|
|
118
|
+
cost += COST.circle;
|
|
119
|
+
}
|
|
120
|
+
for (const taken of placed) {
|
|
121
|
+
if (boxesOverlap(taken, box))
|
|
122
|
+
cost += COST.label;
|
|
123
|
+
}
|
|
124
|
+
if (cost < bestCost) {
|
|
125
|
+
best = side;
|
|
126
|
+
bestCost = cost;
|
|
127
|
+
bestBox = box;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
sides.set(node.key, best);
|
|
131
|
+
placed.push(bestBox);
|
|
132
|
+
}
|
|
133
|
+
return sides;
|
|
134
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { INetworkOverview } from "@peers-app/peers-sdk";
|
|
2
|
+
import { type EdgeHealth, type NetEdge, type NetGraph } from "./network-graph-model";
|
|
3
|
+
/** What the card's buttons do. */
|
|
4
|
+
export interface NetworkGraphCardActions {
|
|
5
|
+
onViewDetails: (deviceId: string) => void;
|
|
6
|
+
onDisconnect: (deviceId: string) => void;
|
|
7
|
+
onConnect: (deviceId: string) => void;
|
|
8
|
+
/** Devices being dialed now. */
|
|
9
|
+
connecting: ReadonlySet<string>;
|
|
10
|
+
/** Select a device, from a connection's card. */
|
|
11
|
+
onSelectNode: (deviceId: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/** What the card is about: a device, a connection, or (with neither) this device. */
|
|
14
|
+
export type NetSelection = {
|
|
15
|
+
kind: "node";
|
|
16
|
+
key: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "edge";
|
|
19
|
+
key: string;
|
|
20
|
+
};
|
|
21
|
+
/** The floating card: this device, the selected device, or the selected connection. */
|
|
22
|
+
export declare function NetworkGraphCard(props: {
|
|
23
|
+
graph: NetGraph;
|
|
24
|
+
overview: INetworkOverview;
|
|
25
|
+
selection: NetSelection | undefined;
|
|
26
|
+
selectedGroupIds: readonly string[];
|
|
27
|
+
health: (edge: NetEdge) => EdgeHealth;
|
|
28
|
+
actions: NetworkGraphCardActions;
|
|
29
|
+
onClose: () => void;
|
|
30
|
+
}): import("react/jsx-runtime").JSX.Element;
|