glassbrain 0.2.0-alpha.4 → 0.2.0-alpha.5

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/README.md CHANGED
@@ -41,7 +41,11 @@ it as an error (forty kinds without colours look exactly like one kind):
41
41
 
42
42
  `parent` is required on every node (null for the one root) and says what sits inside what **and where
43
43
  it sits**: `id@order`, or `id@-1` for an explicitly unordered set. The layout reads the numbers
44
- clockwise, and a root whose children are numbered *is* the 2.5D layer view. There is no layer field.
44
+ clockwise when seeding recursive sectors: the outer circle has `n+1` equal sectors for `n` children, with
45
+ sector 0 empty and centered at the top. Descendants subdivide their parent’s angular interval around the same
46
+ origin, without adding further empty sectors. Each child samples a small normal angular offset; unordered siblings also
47
+ shuffle sector order. Re-layout discards saved coordinates and samples a new seed. The force solver relaxes it
48
+ without a final rotation. A root whose children are numbered *is* the 2.5D layer view. There is no layer field.
45
49
  A [JSON Schema](https://github.com/voidixyn/glassbrain/blob/main/schema/graph.schema.json) describes every field, and the CLI answers in a form an
46
50
  agent can act on — findings identify the problem and structural advice suggests a next step:
47
51
 
@@ -526,6 +526,7 @@ function changedSubset(d) {
526
526
  var VIRTUAL_ROOT = "__gk_root__";
527
527
  var RESERVED_CLASSES = ["container", "crosslayer", "contains", "root", "gb-node"];
528
528
  var cls = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_");
529
+ var edgeKindClass = (kind) => kind === "contains" ? "gb-relation-contains" : cls(kind);
529
530
  function nodeClasses(n, profile, o) {
530
531
  return [
531
532
  "gb-node",
@@ -655,7 +656,7 @@ function buildElements(model, profile, opts = {}) {
655
656
  const { source, target } = e;
656
657
  if (source === target) continue;
657
658
  if (!nodeIds.has(source) || !nodeIds.has(target)) continue;
658
- const id = e.id ?? `${e.kind ?? "e"}:${source}->${target}`;
659
+ const id = e.id ?? `${e.kind === "contains" ? "relation:contains" : e.kind ?? "e"}:${source}->${target}`;
659
660
  if (seen.has(id)) continue;
660
661
  seen.add(id);
661
662
  const cross = layerOf.get(source) !== layerOf.get(target);
@@ -672,7 +673,7 @@ function buildElements(model, profile, opts = {}) {
672
673
  _force: profile.layoutEdge(e)
673
674
  },
674
675
  classes: [
675
- profile.edgeClass(e) || "plain",
676
+ (profile.edgeClass(e) || "plain").split(/\s+/).map(edgeKindClass).join(" "),
676
677
  ...(e.flags ?? []).map(cls),
677
678
  cross ? "crosslayer" : ""
678
679
  ].filter(Boolean).join(" ")
@@ -1065,7 +1066,7 @@ function paletteStyle(profile, theme = LIGHT_THEME, nodeScale = 1) {
1065
1066
  for (const [kind, raw] of Object.entries(profile.edgePalette ?? {})) {
1066
1067
  const color = themeColor(theme, raw);
1067
1068
  out.push({
1068
- selector: `edge.${cls(kind)}`,
1069
+ selector: `edge.${edgeKindClass(kind)}`,
1069
1070
  style: { "line-color": color, "target-arrow-color": color, "source-arrow-color": color }
1070
1071
  });
1071
1072
  }
@@ -1076,7 +1077,7 @@ function paletteStyle(profile, theme = LIGHT_THEME, nodeScale = 1) {
1076
1077
  out.push({ selector: `node.${cls(kind)}`, style: { width: size, height: size } });
1077
1078
  }
1078
1079
  for (const [kind, k] of Object.entries(profile.edgeWidth ?? {})) {
1079
- if (k !== 1) out.push({ selector: `edge.${cls(kind)}`, style: { width: (el) => edgeWidthOf(el) * k } });
1080
+ if (k !== 1) out.push({ selector: `edge.${edgeKindClass(kind)}`, style: { width: (el) => edgeWidthOf(el) * k } });
1080
1081
  }
1081
1082
  for (const flag of profile.placeholderFlags ?? []) {
1082
1083
  out.push({
@@ -2351,6 +2352,7 @@ export {
2351
2352
  VIRTUAL_ROOT,
2352
2353
  RESERVED_CLASSES,
2353
2354
  cls,
2355
+ edgeKindClass,
2354
2356
  nodeClasses,
2355
2357
  buildElements,
2356
2358
  isNodeEl,
@@ -37,7 +37,13 @@ function runLayoutJob(job) {
37
37
  return new Promise((resolve, reject) => {
38
38
  let cy;
39
39
  try {
40
- cy = cytoscape({ headless: true, styleEnabled: true, elements: job.elements, style: GEOMETRY_STYLE });
40
+ cy = cytoscape({
41
+ headless: true,
42
+ styleEnabled: true,
43
+ elements: job.elements,
44
+ style: GEOMETRY_STYLE,
45
+ layout: { name: "preset", fit: false }
46
+ });
41
47
  } catch (err) {
42
48
  reject(err);
43
49
  return;
@@ -91,5 +97,6 @@ var inlinePool = () => [{
91
97
  }];
92
98
 
93
99
  export {
100
+ LAYOUTS,
94
101
  inlinePool
95
102
  };
@@ -24,6 +24,7 @@ import {
24
24
  diffModels,
25
25
  diffSkinStyle,
26
26
  edgeFade,
27
+ edgeKindClass,
27
28
  edgeTraffic,
28
29
  edgesOf,
29
30
  graphStyle,
@@ -52,7 +53,7 @@ import {
52
53
  unionSides,
53
54
  untheme,
54
55
  validateModel
55
- } from "./chunk-SEOAVI3E.js";
56
+ } from "./chunk-F4HDKER4.js";
56
57
  import {
57
58
  DetailPanel,
58
59
  I,
@@ -64,8 +65,9 @@ import {
64
65
  EN
65
66
  } from "./chunk-ISWKAU5G.js";
66
67
  import {
68
+ LAYOUTS,
67
69
  inlinePool
68
- } from "./chunk-YGRPNAXE.js";
70
+ } from "./chunk-OE5IRKWZ.js";
69
71
  import {
70
72
  __publicField
71
73
  } from "./chunk-ZA47FP7C.js";
@@ -129,6 +131,7 @@ var EDGE_REACH = 0.5;
129
131
  var reachOf = (vis, lineW, touch = false, base = EDGE_REACH) => (base * (touch ? 2.4 : 1) + lineW / 2) * vis;
130
132
  var hittable = (reach) => reach * 2 >= 1;
131
133
  var detailed = (leafPx) => leafPx >= DETAIL_LEAF;
134
+ var edgeKindHidden = (skeleton, kind, hidden) => !skeleton && hidden.has(kind);
132
135
  var shapeOf = (name) => /hexagon|octagon|pentagon|heptagon/.test(name) ? "hexagon" : /diamond/.test(name) ? "diamond" : /rectangle|square|barrel|tag/.test(name) ? "rect" : "circle";
133
136
  var arrowOf = (name) => name === "none" ? "none" : name === "tee" ? "tee" : "triangle";
134
137
  function installPainter(cy, opts) {
@@ -260,7 +263,7 @@ function installPainter(cy, opts) {
260
263
  if (!muteKinds.nodes.size && !muteKinds.edges.size) return out;
261
264
  for (const n of [...nodes, ...parents]) if (muteKinds.nodes.has(n.ele.data("kind"))) out.add(n.id);
262
265
  for (const e of edges) {
263
- if (muteKinds.edges.has(e.ele.data("kind")) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
266
+ if (edgeKindHidden(e.skeleton, e.ele.data("kind"), muteKinds.edges) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
264
267
  }
265
268
  return out;
266
269
  };
@@ -773,11 +776,11 @@ function partitionElements(elements) {
773
776
  const attached = new Set(nodes.filter(isAttached).map((n) => n.data.id));
774
777
  const parentOf = /* @__PURE__ */ new Map();
775
778
  for (const n of nodes) {
776
- const p = n.data.parent;
779
+ const p = n.data.parentId ?? n.data.parent;
777
780
  if (p && p !== VIRTUAL_ROOT) parentOf.set(n.data.id, p);
778
781
  }
779
782
  for (const e of edges) {
780
- if (e.data.kind === "contains" && e.data.source !== VIRTUAL_ROOT) {
783
+ if (e.classes?.split(/\s+/).includes("contains") && e.data.source !== VIRTUAL_ROOT && !parentOf.has(e.data.target)) {
781
784
  parentOf.set(e.data.target, e.data.source);
782
785
  }
783
786
  }
@@ -924,7 +927,7 @@ function readOrder(elements) {
924
927
  const p = el.data.parentId ?? el.data.parent;
925
928
  if (p) rawParent.set(id, p);
926
929
  const raw = el.data.order;
927
- rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) ? raw : null);
930
+ rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : null);
928
931
  }
929
932
  const parentOf = /* @__PURE__ */ new Map();
930
933
  const kids = /* @__PURE__ */ new Map();
@@ -953,137 +956,73 @@ function readOrder(elements) {
953
956
  orderedKids.set(parent, sorted);
954
957
  any = true;
955
958
  }
956
- return any ? { parentOf, orderedKids, nodeIds, any } : null;
959
+ return nodeIds.size ? { parentOf, orderedKids, nodeIds, any } : null;
957
960
  }
958
- function hash01(id) {
959
- let h = 2166136261;
960
- for (let i = 0; i < id.length; i++) {
961
- h ^= id.charCodeAt(i);
962
- h = Math.imul(h, 16777619);
963
- }
964
- return (h >>> 0) % 1e5 / 1e5;
965
- }
966
- var TAU = Math.PI * 2;
967
- var RING = 320;
968
- function orderSeed(elements, info) {
969
- const children = /* @__PURE__ */ new Map();
970
- for (const [id, parent] of info.parentOf) {
971
- const arr = children.get(parent);
972
- arr ? arr.push(id) : children.set(parent, [id]);
973
- }
974
- const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
975
- const weight = /* @__PURE__ */ new Map();
976
- const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
977
- const hit = weight.get(id);
978
- if (hit != null) return hit;
979
- if (seen.has(id)) return 1;
980
- seen.add(id);
981
- let n = 1;
982
- for (const k of children.get(id) ?? []) n += weigh(k, seen);
983
- weight.set(id, n);
984
- return n;
985
- };
986
- for (const id of info.nodeIds) weigh(id);
987
- const out = {};
988
- const place = (id, cx, cy, from, to, level) => {
989
- const r = level * RING;
990
- const mid = (from + to) / 2;
991
- out[id] = { x: cx + Math.cos(mid) * r, y: cy + Math.sin(mid) * r };
992
- const kids = children.get(id) ?? [];
993
- if (!kids.length) return;
994
- const ordered = info.orderedKids.get(id);
995
- const list = ordered ?? kids;
996
- const total = list.reduce((s, k) => s + weigh(k), 0) || 1;
997
- let at = from;
998
- for (const k of list) {
999
- const span = (to - from) * weigh(k) / total;
1000
- const jitter = ordered ? 0 : (hash01(k) - 0.5) * span * 0.6;
1001
- const a = at + jitter;
1002
- place(k, cx, cy, a, a + span, level + 1);
1003
- at += span;
1004
- }
1005
- };
1006
- if (roots.length === 1) place(roots[0], 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
1007
- else if (roots.length > 1) {
1008
- roots.forEach((root, i) => {
1009
- const from = -Math.PI / 2 + TAU * i / roots.length;
1010
- place(root, 0, 0, from, from + TAU / roots.length, 0);
1011
- });
1012
- }
1013
- if ((children.get(VIRTUAL_PARENT) ?? []).length) {
1014
- place(VIRTUAL_PARENT, 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
1015
- delete out[VIRTUAL_PARENT];
961
+ function shuffled(ids, random) {
962
+ const out = [...ids].sort();
963
+ for (let i = out.length - 1; i > 0; i--) {
964
+ const j = Math.floor(random() * (i + 1));
965
+ [out[i], out[j]] = [out[j], out[i]];
1016
966
  }
1017
967
  return out;
1018
968
  }
1019
- var angle = (p) => Math.atan2(p.y, p.x);
1020
- function enforceOrder(elements, info, positions) {
969
+ var TAU = Math.PI * 2;
970
+ function orderSeed(elements, info, dims = {}, random = Math.random) {
971
+ const gap = LAYOUTS["cose-bilkent"].opts.idealEdgeLength;
1021
972
  const children = /* @__PURE__ */ new Map();
1022
973
  for (const [id, parent] of info.parentOf) {
1023
- const arr = children.get(parent);
1024
- arr ? arr.push(id) : children.set(parent, [id]);
974
+ const list = children.get(parent);
975
+ list ? list.push(id) : children.set(parent, [id]);
1025
976
  }
1026
- const out = {};
1027
- for (const [id, p] of Object.entries(positions)) out[id] = { ...p };
1028
- const weight = /* @__PURE__ */ new Map();
1029
- const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
1030
- const hit = weight.get(id);
1031
- if (hit != null) return hit;
1032
- if (seen.has(id)) return 1;
1033
- seen.add(id);
1034
- let n = 1;
1035
- for (const k of children.get(id) ?? []) n += weigh(k, seen);
1036
- weight.set(id, n);
1037
- return n;
977
+ const diameter = (id) => {
978
+ const d = dims[id];
979
+ return d ? Math.hypot(d.w, d.h) : gap;
1038
980
  };
1039
- const subtree = (id, acc = []) => {
1040
- acc.push(id);
1041
- for (const k of children.get(id) ?? []) subtree(k, acc);
1042
- return acc;
981
+ const widths = /* @__PURE__ */ new Map();
982
+ const width = (id) => {
983
+ const cached = widths.get(id);
984
+ if (cached !== void 0) return cached;
985
+ const value = Math.max(
986
+ diameter(id) + gap,
987
+ (children.get(id) ?? []).reduce((sum, child) => sum + width(child), 0)
988
+ );
989
+ widths.set(id, value);
990
+ return value;
1043
991
  };
1044
- const rotate = (ids, pivot, delta) => {
1045
- if (Math.abs(delta) < 1e-6) return;
1046
- const c = Math.cos(delta), s = Math.sin(delta);
1047
- for (const id of ids) {
1048
- const p = out[id];
1049
- if (!p) continue;
1050
- const dx = p.x - pivot.x, dy = p.y - pivot.y;
1051
- out[id] = { x: pivot.x + dx * c - dy * s, y: pivot.y + dx * s + dy * c };
1052
- }
992
+ const offset = (span) => {
993
+ const z = Math.sqrt(-2 * Math.log(1 - random())) * Math.cos(TAU * random());
994
+ return Math.max(-3, Math.min(3, z)) * span / 8;
1053
995
  };
1054
- const settle = (parent) => {
1055
- const list = info.orderedKids.get(parent);
1056
- if (!list) {
1057
- for (const id of children.get(parent) ?? []) settle(id);
1058
- return;
1059
- }
1060
- const present = list.filter((id) => out[id]);
1061
- if (present.length < 2) return;
1062
- const pivot = out[parent] ?? {
1063
- x: present.reduce((s, id) => s + out[id].x, 0) / present.length,
1064
- y: present.reduce((s, id) => s + out[id].y, 0) / present.length
1065
- };
1066
- const total = present.reduce((s, id) => s + weigh(id), 0) || 1;
1067
- let at = angle({ x: out[present[0]].x - pivot.x, y: out[present[0]].y - pivot.y });
1068
- for (const id of present) {
1069
- const p = out[id];
1070
- const cur = angle({ x: p.x - pivot.x, y: p.y - pivot.y });
1071
- let delta = at - cur;
1072
- while (delta > Math.PI) delta -= TAU;
1073
- while (delta < -Math.PI) delta += TAU;
1074
- rotate(subtree(id), pivot, delta);
1075
- at += TAU * weigh(id) / total;
1076
- }
1077
- for (const id of present) settle(id);
996
+ const out = {};
997
+ const placeChildren = (parent, ids, parentRadius, sector) => {
998
+ const list = (parent === null ? void 0 : info.orderedKids.get(parent)) ?? shuffled(ids, random);
999
+ if (!list.length) return;
1000
+ const span = sector ? (sector.to - sector.from) / list.length : TAU / (list.length + 1);
1001
+ list.forEach((id, i) => {
1002
+ const middle2 = sector ? sector.from + (i + 0.5) * span : -Math.PI / 2 + (i + 1) * span;
1003
+ const angle = middle2 + offset(span);
1004
+ const clearance = gap + (diameter(parent ?? VIRTUAL_PARENT) + diameter(id)) / 2;
1005
+ const radius = Math.max(parentRadius + clearance, width(id) / span);
1006
+ const p = { x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
1007
+ out[id] = p;
1008
+ placeChildren(id, children.get(id) ?? [], radius, { from: middle2 - span / 2, to: middle2 + span / 2 });
1009
+ });
1078
1010
  };
1079
1011
  const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
1080
- for (const root of roots) settle(root);
1081
- if (children.has(VIRTUAL_PARENT)) settle(VIRTUAL_PARENT);
1012
+ if (children.has(VIRTUAL_PARENT)) roots.push(VIRTUAL_PARENT);
1013
+ if (roots.length === 1) {
1014
+ const root = roots[0];
1015
+ out[root] = { x: 0, y: 0 };
1016
+ placeChildren(root, children.get(root) ?? [], 0);
1017
+ } else {
1018
+ placeChildren(null, roots, 0);
1019
+ }
1020
+ delete out[VIRTUAL_PARENT];
1082
1021
  return out;
1083
1022
  }
1084
1023
 
1085
1024
  // src/layout/engine.ts
1086
- var CACHE_PREFIX = "gb:pos:v3:";
1025
+ var CACHE_PREFIX = "gb:pos:v6:";
1087
1026
  var CACHE_KEEP = 16;
1088
1027
  function shapeHash(elements, salt) {
1089
1028
  const parts = [];
@@ -1307,11 +1246,7 @@ async function runWhole(req, aborted) {
1307
1246
  if (el.data.source) {
1308
1247
  if (el.data._force !== false) edges.push({ data: el.data, classes: el.classes });
1309
1248
  } else {
1310
- const d = req.dims[el.data.id];
1311
- nodes.push({
1312
- data: { ...el.data, detail: void 0, ...d ? { _w: d.w, _h: d.h } : {} },
1313
- classes: el.classes
1314
- });
1249
+ nodes.push(toJobNode(el, req.dims, req.seed));
1315
1250
  }
1316
1251
  }
1317
1252
  const [runner] = req.pool(1);
@@ -1345,16 +1280,18 @@ function computeLayout(req) {
1345
1280
  const current = inflight.get(owner);
1346
1281
  if (current) current.superseded = true;
1347
1282
  const order = readOrder(req.elements);
1348
- const job = order && !req.seed ? { ...req, seed: orderSeed(req.elements, order) } : req;
1283
+ const known = req.force ? void 0 : req.seed;
1284
+ const complete = order && known && [...order.nodeIds].every((id) => known[id]);
1285
+ const seed = complete ? known : { ...order ? orderSeed(req.elements, order, req.dims) : {}, ...known };
1286
+ const job = { ...req, seed };
1349
1287
  const run = { hash, superseded: false, promise: null };
1350
1288
  const runner = mode === "whole" ? runWhole : runDivide;
1351
1289
  run.promise = runner(job, () => run.superseded).then((pos) => {
1352
- const settled = order ? enforceOrder(req.elements, order, pos) : pos;
1353
1290
  if (!run.stale) {
1354
- cachePut(hash, settled);
1355
- lastByNs.set(ns, { hash, pos: settled });
1291
+ cachePut(hash, pos);
1292
+ lastByNs.set(ns, { hash, pos });
1356
1293
  }
1357
- return settled;
1294
+ return pos;
1358
1295
  }).finally(() => {
1359
1296
  if (inflight.get(owner) === run) inflight.delete(owner);
1360
1297
  });
@@ -2043,7 +1980,7 @@ function ViewMenu(p) {
2043
1980
  "data-y": pop.placement?.side,
2044
1981
  style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
2045
1982
  onClick: (e) => {
2046
- if (e.target.closest(".gb-menu-item")) pop.setOpen(false);
1983
+ if (e.target.closest(".gb-menu-item") && !e.target.closest("[data-menu-keep-open]")) pop.setOpen(false);
2047
1984
  },
2048
1985
  onChange: (e) => {
2049
1986
  if (e.target.tagName === "SELECT") pop.setOpen(false);
@@ -2107,7 +2044,8 @@ function Toolbar(p) {
2107
2044
  ] }),
2108
2045
  (p.onRelayout || p.onRestructure) && /* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
2109
2046
  p.onRelayout && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRelayout, disabled: p.busy, children: t.relayout }),
2110
- p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRestructure, disabled: p.busy, children: t.restructure })
2047
+ p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", "data-menu-keep-open": p.restructureContent ? true : void 0, onClick: p.onRestructure, disabled: p.busy, children: t.restructure }),
2048
+ p.restructureContent
2111
2049
  ] })
2112
2050
  ] })
2113
2051
  ] });
@@ -2925,7 +2863,7 @@ function readMarks(c, cy, style, nodeKinds, edgeKinds) {
2925
2863
  }
2926
2864
  for (const k of edgeKinds) {
2927
2865
  if (c.strokes.has(k) || !live) continue;
2928
- const e = cy.edges(`.${cls(k)}`)[0];
2866
+ const e = cy.edges(`.${edgeKindClass(k)}`)[0];
2929
2867
  if (e) c.strokes.set(k, { dash: e.pstyle("line-style").value, head: arrowOf(e.pstyle("target-arrow-shape").value), tail: arrowOf(e.pstyle("source-arrow-shape").value) });
2930
2868
  }
2931
2869
  return {
@@ -3565,8 +3503,7 @@ function hideEdgesByKind(cy, hn, he, prev) {
3565
3503
  const off = /* @__PURE__ */ new Set();
3566
3504
  if (hn.size || he.size) {
3567
3505
  cy.edges().forEach((e) => {
3568
- if (e.hasClass("contains")) return;
3569
- if (he.has(e.data("kind")) || hn.has(e.source().data("kind")) || hn.has(e.target().data("kind"))) off.add(e.id());
3506
+ if (edgeKindHidden(e.hasClass("contains"), e.data("kind"), he) || hn.has(e.source().data("kind")) || hn.has(e.target().data("kind"))) off.add(e.id());
3570
3507
  });
3571
3508
  }
3572
3509
  for (const id of prev) if (!off.has(id)) cy.$id(id).style("display", "element");
@@ -3719,12 +3656,13 @@ function presenceGroups(cy, live, marks) {
3719
3656
  graft: cy.collection(bucket.graft)
3720
3657
  };
3721
3658
  }
3722
- function seatOrphans(pos, built) {
3659
+ function seatOrphans(pos, built, excluded = /* @__PURE__ */ new Set()) {
3723
3660
  const missing = [];
3724
3661
  let sx = 0, sy = 0, n = 0;
3725
3662
  for (const el of built.elements) {
3726
3663
  if (el.data.source) continue;
3727
3664
  const id = el.data.id;
3665
+ if (excluded.has(id)) continue;
3728
3666
  const p = pos[id];
3729
3667
  if (p) {
3730
3668
  sx += p.x;
@@ -3831,6 +3769,7 @@ function GraphCanvas(props) {
3831
3769
  renderEditor,
3832
3770
  resolveUrl,
3833
3771
  onRestructure,
3772
+ restructureContent,
3834
3773
  layerIssue,
3835
3774
  onForceLayers,
3836
3775
  animate = true,
@@ -4824,10 +4763,10 @@ function GraphCanvas(props) {
4824
4763
  const v0 = cam();
4825
4764
  const leftBefore = leftRef.current;
4826
4765
  applyPositions(cy, union, false);
4827
- leftRef.current = /* @__PURE__ */ new Set();
4766
+ leftRef.current = leftBefore;
4828
4767
  fitAll(cy);
4829
4768
  const vU = cam();
4830
- leftRef.current = t.leaving;
4769
+ leftRef.current = /* @__PURE__ */ new Set([...leftBefore, ...t.leaving]);
4831
4770
  fitAll(cy);
4832
4771
  const v1 = cam();
4833
4772
  leftRef.current = leftBefore;
@@ -4924,6 +4863,7 @@ function GraphCanvas(props) {
4924
4863
  worn.push([el, Object.fromEntries(SKIN_SIZE_PROPS.map((p) => [p, el.style(p)]))]);
4925
4864
  });
4926
4865
  }
4866
+ const hiddenBeforeMeasure = cy.nodes().filter((n) => n.style("display") === "none");
4927
4867
  cy.batch(() => {
4928
4868
  for (const [el] of worn) el.removeStyle(sizeProps);
4929
4869
  cy.nodes().style("display", "none");
@@ -4932,13 +4872,14 @@ function GraphCanvas(props) {
4932
4872
  const dims = {};
4933
4873
  cy.nodes(":childless").forEach((n) => {
4934
4874
  const d = n.layoutDimensions({ nodeDimensionsIncludeLabels: true });
4935
- dims[n.id()] = { w: d.w, h: d.h };
4875
+ dims[n.id()] = { w: Math.round(d.w * 64) / 64, h: Math.round(d.h * 64) / 64 };
4936
4876
  });
4937
4877
  dimsRef.current = dims;
4938
4878
  if (scaled) cy.style(sheetFor(false));
4939
4879
  if (worn.length) cy.batch(() => {
4940
4880
  for (const [el, v] of worn) el.style(v);
4941
4881
  });
4882
+ hiddenBeforeMeasure.style("display", "none");
4942
4883
  if (diffRef.current) hideGhosts(cy);
4943
4884
  const run = ++runRef.current;
4944
4885
  if (owedLayoutRef.current && (force || !owedLayoutRef.current.force)) owedLayoutRef.current = null;
@@ -4962,7 +4903,7 @@ function GraphCanvas(props) {
4962
4903
  return { positions, source: "preset" };
4963
4904
  }
4964
4905
  let known;
4965
- if (force || layoutModeRef.current === "continue") {
4906
+ if (!force && layoutModeRef.current === "continue") {
4966
4907
  const all = { ...preset, ...rawRef.current };
4967
4908
  known = {};
4968
4909
  for (const id of ids) if (all[id]) known[id] = all[id];
@@ -5025,7 +4966,7 @@ function GraphCanvas(props) {
5025
4966
  onLayoutRef.current(own, { source: layoutSource, ms: layoutMsRef.current });
5026
4967
  }
5027
4968
  const stay = [...leaving].filter((id) => !positions[id] && dispRef.current[id]);
5028
- seatOrphans(positions, built);
4969
+ seatOrphans(positions, built, /* @__PURE__ */ new Set([...leftRef.current, ...leaving]));
5029
4970
  rawRef.current = positions;
5030
4971
  layerOfRef.current = layerOf;
5031
4972
  const t = viewRef.current.planes ? 1 : 0;
@@ -5783,6 +5724,7 @@ ${lt}`;
5783
5724
  onAdd: editable ? startAdd : void 0,
5784
5725
  onRelayout: controls.relayout && !diff ? relayout : void 0,
5785
5726
  onRestructure: controls.relayout && !diff ? onRestructure : void 0,
5727
+ restructureContent: controls.relayout && !diff ? restructureContent : void 0,
5786
5728
  layerIssue,
5787
5729
  onForceLayers
5788
5730
  }
@@ -5889,6 +5831,7 @@ export {
5889
5831
  reachOf,
5890
5832
  hittable,
5891
5833
  detailed,
5834
+ edgeKindHidden,
5892
5835
  shapeOf,
5893
5836
  arrowOf,
5894
5837
  relaxOverlaps,
@@ -1671,6 +1671,14 @@ var parentCycle = {
1671
1671
  return out;
1672
1672
  }
1673
1673
  };
1674
+ var reservedContains = {
1675
+ code: "parent-error",
1676
+ level: "error",
1677
+ run: ({ model }) => model.edges.some((e) => e.kind === "contains") ? [{
1678
+ message: 'edge kind "contains" is reserved for the parent structure',
1679
+ fix: "express containment with the child node's parent field and remove the redundant edge. If this is another relationship, give its kind a distinct name and update edgePalette."
1680
+ }] : []
1681
+ };
1674
1682
  var orderMixed = {
1675
1683
  code: "order-error",
1676
1684
  level: "error",
@@ -1920,6 +1928,7 @@ var rules = [
1920
1928
  layerField,
1921
1929
  unknownParent,
1922
1930
  parentCycle,
1931
+ reservedContains,
1923
1932
  orderMixed,
1924
1933
  orderDuplicate,
1925
1934
  conflictingDefinition,