@intentius/behold 0.29.56 → 0.29.57

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.
Files changed (173) hide show
  1. package/THIRD_PARTY.md +21 -0
  2. package/dist/cli.js +7611 -6919
  3. package/example-three-cloud/azure/composites/container-app-site.ts +77 -0
  4. package/example-three-cloud/azure/src/site.ts +14 -46
  5. package/example-three-cloud/dns/composites/latency-entry.ts +73 -0
  6. package/example-three-cloud/dns/src/route53.ts +9 -39
  7. package/example-three-cloud/gcp/composites/public-cloud-run.ts +102 -0
  8. package/example-three-cloud/gcp/src/site.ts +16 -96
  9. package/licenses/aws-architecture-icons-TERMS.md +19 -0
  10. package/licenses/azure-architecture-icons-Microsoft_Terms_of_Use.pdf +0 -0
  11. package/licenses/azure-architecture-icons-TERMS.md +20 -0
  12. package/licenses/google-cloud-icons-TERMS.md +15 -0
  13. package/package.json +1 -1
  14. package/web/app.js +557 -18
  15. package/web/edge-weight.d.ts +5 -0
  16. package/web/edge-weight.js +71 -0
  17. package/web/edge-weight.test.js +49 -0
  18. package/web/icons/aws/alb.svg +1 -0
  19. package/web/icons/aws/api-gateway.svg +1 -0
  20. package/web/icons/aws/app-runner.svg +1 -0
  21. package/web/icons/aws/appsync.svg +1 -0
  22. package/web/icons/aws/athena.svg +1 -0
  23. package/web/icons/aws/auto-scaling.svg +1 -0
  24. package/web/icons/aws/backup.svg +1 -0
  25. package/web/icons/aws/batch.svg +1 -0
  26. package/web/icons/aws/bedrock-agentcore.svg +1 -0
  27. package/web/icons/aws/bedrock.svg +1 -0
  28. package/web/icons/aws/certificate-manager.svg +1 -0
  29. package/web/icons/aws/cloud-map.svg +1 -0
  30. package/web/icons/aws/cloud.svg +1 -0
  31. package/web/icons/aws/cloudformation.svg +1 -0
  32. package/web/icons/aws/cloudfront.svg +1 -0
  33. package/web/icons/aws/cloudtrail.svg +1 -0
  34. package/web/icons/aws/cloudwatch-alarm.svg +1 -0
  35. package/web/icons/aws/cloudwatch-logs.svg +1 -0
  36. package/web/icons/aws/cloudwatch.svg +1 -0
  37. package/web/icons/aws/codebuild.svg +1 -0
  38. package/web/icons/aws/codecommit.svg +1 -0
  39. package/web/icons/aws/codedeploy.svg +1 -0
  40. package/web/icons/aws/codepipeline.svg +1 -0
  41. package/web/icons/aws/cognito.svg +1 -0
  42. package/web/icons/aws/config.svg +1 -0
  43. package/web/icons/aws/documentdb.svg +1 -0
  44. package/web/icons/aws/dynamodb-table.svg +1 -0
  45. package/web/icons/aws/dynamodb.svg +1 -0
  46. package/web/icons/aws/ebs-volume.svg +1 -0
  47. package/web/icons/aws/ec2-instance.svg +1 -0
  48. package/web/icons/aws/ec2.svg +1 -0
  49. package/web/icons/aws/ecr-registry.svg +1 -0
  50. package/web/icons/aws/ecr.svg +1 -0
  51. package/web/icons/aws/ecs-service.svg +1 -0
  52. package/web/icons/aws/ecs-task.svg +1 -0
  53. package/web/icons/aws/ecs.svg +1 -0
  54. package/web/icons/aws/efs.svg +1 -0
  55. package/web/icons/aws/eks.svg +1 -0
  56. package/web/icons/aws/elastic-beanstalk.svg +1 -0
  57. package/web/icons/aws/elastic-ip.svg +1 -0
  58. package/web/icons/aws/elasticache.svg +1 -0
  59. package/web/icons/aws/elb.svg +1 -0
  60. package/web/icons/aws/emr.svg +1 -0
  61. package/web/icons/aws/eventbridge.svg +1 -0
  62. package/web/icons/aws/firehose.svg +1 -0
  63. package/web/icons/aws/global-accelerator.svg +1 -0
  64. package/web/icons/aws/glue.svg +1 -0
  65. package/web/icons/aws/guardduty.svg +1 -0
  66. package/web/icons/aws/iam.svg +1 -0
  67. package/web/icons/aws/internet-gateway.svg +1 -0
  68. package/web/icons/aws/keyspaces.svg +1 -0
  69. package/web/icons/aws/kinesis.svg +1 -0
  70. package/web/icons/aws/kms.svg +1 -0
  71. package/web/icons/aws/lambda-function.svg +1 -0
  72. package/web/icons/aws/lambda.svg +1 -0
  73. package/web/icons/aws/mq.svg +1 -0
  74. package/web/icons/aws/msk.svg +1 -0
  75. package/web/icons/aws/nat-gateway.svg +1 -0
  76. package/web/icons/aws/neptune.svg +1 -0
  77. package/web/icons/aws/network-acl.svg +1 -0
  78. package/web/icons/aws/network-firewall.svg +1 -0
  79. package/web/icons/aws/opensearch.svg +1 -0
  80. package/web/icons/aws/organizations.svg +1 -0
  81. package/web/icons/aws/rds-instance.svg +1 -0
  82. package/web/icons/aws/rds.svg +1 -0
  83. package/web/icons/aws/redshift.svg +1 -0
  84. package/web/icons/aws/route-53-hosted-zone.svg +1 -0
  85. package/web/icons/aws/route-53.svg +1 -0
  86. package/web/icons/aws/router.svg +1 -0
  87. package/web/icons/aws/s3-bucket.svg +1 -0
  88. package/web/icons/aws/s3.svg +1 -0
  89. package/web/icons/aws/sagemaker.svg +1 -0
  90. package/web/icons/aws/secrets-manager.svg +1 -0
  91. package/web/icons/aws/ses.svg +1 -0
  92. package/web/icons/aws/shield.svg +1 -0
  93. package/web/icons/aws/sns-topic.svg +1 -0
  94. package/web/icons/aws/sns.svg +1 -0
  95. package/web/icons/aws/sqs-queue.svg +1 -0
  96. package/web/icons/aws/sqs.svg +1 -0
  97. package/web/icons/aws/step-functions.svg +1 -0
  98. package/web/icons/aws/systems-manager.svg +1 -0
  99. package/web/icons/aws/transfer-family.svg +1 -0
  100. package/web/icons/aws/transit-gateway.svg +1 -0
  101. package/web/icons/aws/vpc-endpoints.svg +1 -0
  102. package/web/icons/aws/vpc-lattice.svg +1 -0
  103. package/web/icons/aws/vpc.svg +1 -0
  104. package/web/icons/aws/vpn-gateway.svg +1 -0
  105. package/web/icons/aws/waf.svg +1 -0
  106. package/web/icons/azure/app-service-plan.svg +1 -0
  107. package/web/icons/azure/app-services.svg +1 -0
  108. package/web/icons/azure/application-gateway.svg +1 -0
  109. package/web/icons/azure/container-app.svg +1 -0
  110. package/web/icons/azure/container-apps-environment.svg +1 -0
  111. package/web/icons/azure/container-instances.svg +1 -0
  112. package/web/icons/azure/container-registry.svg +1 -0
  113. package/web/icons/azure/cosmos-db.svg +1 -0
  114. package/web/icons/azure/dns-zone.svg +1 -0
  115. package/web/icons/azure/front-door.svg +1 -0
  116. package/web/icons/azure/function-app.svg +1 -0
  117. package/web/icons/azure/kubernetes-service.svg +1 -0
  118. package/web/icons/azure/load-balancer.svg +1 -0
  119. package/web/icons/azure/log-analytics.svg +1 -0
  120. package/web/icons/azure/managed-identity.svg +1 -0
  121. package/web/icons/azure/mysql.svg +1 -0
  122. package/web/icons/azure/nat.svg +1 -0
  123. package/web/icons/azure/network-security-group.svg +1 -0
  124. package/web/icons/azure/postgresql.svg +1 -0
  125. package/web/icons/azure/public-ip.svg +1 -0
  126. package/web/icons/azure/redis.svg +1 -0
  127. package/web/icons/azure/resource-group.svg +1 -0
  128. package/web/icons/azure/route-table.svg +1 -0
  129. package/web/icons/azure/sql-database.svg +1 -0
  130. package/web/icons/azure/sql-server.svg +1 -0
  131. package/web/icons/azure/subnet.svg +1 -0
  132. package/web/icons/azure/subscription.svg +1 -0
  133. package/web/icons/azure/virtual-machine.svg +1 -0
  134. package/web/icons/azure/virtual-network-gateway.svg +1 -0
  135. package/web/icons/azure/virtual-network.svg +1 -0
  136. package/web/icons/gcp/artifact-registry.svg +1 -0
  137. package/web/icons/gcp/bigquery.svg +1 -0
  138. package/web/icons/gcp/bigtable.svg +1 -0
  139. package/web/icons/gcp/certificate-manager.svg +1 -0
  140. package/web/icons/gcp/cloud-armor.svg +1 -0
  141. package/web/icons/gcp/cloud-build.svg +1 -0
  142. package/web/icons/gcp/cloud-composer.svg +1 -0
  143. package/web/icons/gcp/cloud-dns.svg +1 -0
  144. package/web/icons/gcp/cloud-functions.svg +1 -0
  145. package/web/icons/gcp/cloud-load-balancing.svg +1 -0
  146. package/web/icons/gcp/cloud-logging.svg +1 -0
  147. package/web/icons/gcp/cloud-monitoring.svg +1 -0
  148. package/web/icons/gcp/cloud-nat.svg +1 -0
  149. package/web/icons/gcp/cloud-router.svg +1 -0
  150. package/web/icons/gcp/cloud-run.svg +1 -0
  151. package/web/icons/gcp/cloud-scheduler.svg +1 -0
  152. package/web/icons/gcp/cloud-spanner.svg +1 -0
  153. package/web/icons/gcp/cloud-sql.svg +1 -0
  154. package/web/icons/gcp/cloud-storage.svg +1 -0
  155. package/web/icons/gcp/cloud-tasks.svg +1 -0
  156. package/web/icons/gcp/compute-engine.svg +1 -0
  157. package/web/icons/gcp/dataflow.svg +1 -0
  158. package/web/icons/gcp/external-ip.svg +1 -0
  159. package/web/icons/gcp/firestore.svg +1 -0
  160. package/web/icons/gcp/firewall-rules.svg +1 -0
  161. package/web/icons/gcp/gke.svg +1 -0
  162. package/web/icons/gcp/iam.svg +1 -0
  163. package/web/icons/gcp/kms.svg +1 -0
  164. package/web/icons/gcp/memorystore.svg +1 -0
  165. package/web/icons/gcp/persistent-disk.svg +1 -0
  166. package/web/icons/gcp/project.svg +1 -0
  167. package/web/icons/gcp/pubsub.svg +1 -0
  168. package/web/icons/gcp/secret-manager.svg +1 -0
  169. package/web/icons/gcp/vpc.svg +1 -0
  170. package/web/index.html +34 -0
  171. package/web/net-trace.js +649 -0
  172. package/web/net-trace.test.js +180 -0
  173. package/web/view-url.js +12 -7
package/web/app.js CHANGED
@@ -42,6 +42,8 @@ import { auditLines as yrAuditLines, cornerText as yrCorner, datedWords as yrDat
42
42
  import { cardProgress as tgCardProgress, progressLines as tgProgressLines, progressSection as tgProgressSection, stampProgress as tgStampProgress } from "./terragucci-progress.js";
43
43
  import { seconds, whyQuery, whyView } from "./why.js";
44
44
  import { edgeKey, edgeLabel, edgeLegend, edgeTitle, isCiKind, viaIndex } from "./edge-kind.js";
45
+ import { edgeWeights, weightLegend } from "./edge-weight.js";
46
+ import { networkFindings, OUTSIDE, traceRoute } from "./net-trace.js";
45
47
  import { readCostLine } from "./read-cost.js";
46
48
  import { mountHistoryPicker } from "./history-picker.js";
47
49
  import { applyMemberFrame, createMemberFrames, pendingLine, stillPending } from "./pending.js";
@@ -325,8 +327,74 @@ function recolorNodesByCategory(ir) {
325
327
  const bar = g.querySelector('rect[width="4"]');
326
328
  if (bar) bar.setAttribute("fill", "var(--runtime)");
327
329
  }
330
+ markCloudBoxes();
328
331
  renderGraphLegend();
329
332
  }
333
+
334
+ // behold#824: an estate across clouds draws one boundary box per cloud (AWS
335
+ // account, Azure subscription, GCP project). Each is marked with its cloud so
336
+ // the stylesheet can give it that vendor's colour, box and title together, and
337
+ // three clouds read as three clouds at a glance rather than three grey boxes.
338
+ const CLOUD_OF_BOX = [
339
+ [/^AWS account\b/, "aws"],
340
+ [/^Azure subscription\b/, "azure"],
341
+ [/^GCP project\b/, "gcp"],
342
+ ];
343
+ function cloudOfBox(title) {
344
+ for (const [re, cloud] of CLOUD_OF_BOX) if (re.test(title)) return cloud;
345
+ return null;
346
+ }
347
+ function markCloudBoxes() {
348
+ const svg = document.querySelector("#graph svg");
349
+ if (!svg) return;
350
+ // A project box (the composites and resources zooms draw one per workspace
351
+ // member) takes its cloud from its resources' lexicon when they share one:
352
+ // `dns`, Route 53 and an Op, is an AWS box.
353
+ const lexiconsOf = new Map();
354
+ for (const n of (lastGraphIr && lastGraphIr.nodes) || []) {
355
+ const slash = n.id.indexOf("/");
356
+ if (slash < 1 || !n.lexicon) continue;
357
+ const m = n.id.slice(0, slash);
358
+ (lexiconsOf.get(m) ?? lexiconsOf.set(m, new Set()).get(m)).add(n.lexicon);
359
+ }
360
+ // Only the cloud lexicons count: a member that also holds an Op or other
361
+ // non-cloud cards (dns, with its front-door Op) is still that cloud's.
362
+ const memberCloud = (id) => {
363
+ const clouds = [...(lexiconsOf.get(id) ?? [])].filter((l) => ["aws", "azure", "gcp"].includes(l));
364
+ return clouds.length === 1 ? clouds[0] : null;
365
+ };
366
+ const titles = new Map();
367
+ for (const rect of svg.querySelectorAll("rect[data-group-id]")) {
368
+ const id = rect.getAttribute("data-group-id") || "";
369
+ const cloud = cloudOfBox(id) || memberCloud(id);
370
+ if (!cloud) continue;
371
+ rect.setAttribute("data-cloud", cloud);
372
+ titles.set(rect.getAttribute("data-group-id"), cloud);
373
+ }
374
+ if (!titles.size) return;
375
+ for (const t of svg.querySelectorAll("text")) {
376
+ const cloud = titles.get((t.textContent || "").trim());
377
+ if (!cloud || t.getAttribute("data-cloud")) continue;
378
+ t.setAttribute("data-cloud", cloud);
379
+ // #872: the vendor's own mark before the title, drawn as published. The
380
+ // title moves right by the mark's width, once (data-cloud guards it).
381
+ const size = 20;
382
+ const x = Number(t.getAttribute("x"));
383
+ const y = Number(t.getAttribute("y"));
384
+ const mark = document.createElementNS(SVGNS, "image");
385
+ mark.setAttribute("href", `icons/${CLOUD_MARK[cloud]}.svg`);
386
+ mark.setAttribute("x", String(x));
387
+ mark.setAttribute("y", String(y - size + 4));
388
+ mark.setAttribute("width", String(size));
389
+ mark.setAttribute("height", String(size));
390
+ mark.setAttribute("data-cloud-mark", cloud);
391
+ t.parentNode.insertBefore(mark, t);
392
+ t.setAttribute("x", String(x + size + 6));
393
+ }
394
+ declutterBoxHeads(boxLabelsOf(svg)); // the marks moved titles right
395
+ }
396
+ /** The vendored mark each cloud box wears (src/cloud-icons.ts vendors them). */
397
+ const CLOUD_MARK = { aws: "aws/cloud", azure: "azure/subscription", gcp: "gcp/project" };
330
398
  onThemeChange(() => (recolorNodesByCategory(), drawTgReads())); // behold#571: drawTgReads redraws the marks in the theme's colours
331
399
  // behold#824: the legend on the graph itself. In drift mode a card's fill is
332
400
  // its resource kind (one hue per kind, nothing more) and its state is the bar
@@ -406,6 +474,19 @@ function renderGraphLegend() {
406
474
  f.style.background = colorForCategory(k);
407
475
  fills.appendChild(f);
408
476
  }
477
+ const clouds = [...new Set([...document.querySelectorAll("#graph rect[data-cloud]")].map((r) => r.getAttribute("data-cloud")))];
478
+ if (clouds.length) {
479
+ const sw = document.createElement("span");
480
+ sw.className = "gl-fills";
481
+ const names = { aws: "AWS", azure: "Azure", gcp: "GCP" };
482
+ for (const c of ["aws", "azure", "gcp"].filter((c) => clouds.includes(c))) {
483
+ const f = document.createElement("i");
484
+ f.style.background = `var(--cloud-${c})`;
485
+ f.title = names[c];
486
+ sw.appendChild(f);
487
+ }
488
+ line(sw, `box colour: cloud (${["aws", "azure", "gcp"].filter((c) => clouds.includes(c)).map((c) => names[c]).join(", ")})`);
489
+ }
409
490
  line(fills, "card colour: resource kind");
410
491
  const sub = document.createElement("div");
411
492
  sub.className = "gl-sub";
@@ -424,6 +505,28 @@ function renderGraphLegend() {
424
505
  bar.style.background = DRIFT_STATUS_VAR[k];
425
506
  line(bar, label, String(counts[k]));
426
507
  }
508
+ const weights = weightLegend(lastEdgeWeights);
509
+ if (weights.length) {
510
+ const es = document.createElement("div");
511
+ es.className = "gl-sub";
512
+ es.textContent = "edges";
513
+ el.appendChild(es);
514
+ for (const r of weights) {
515
+ const sw = document.createElementNS(SVGNS, "svg");
516
+ sw.setAttribute("class", "edge-swatch gl-edge");
517
+ sw.setAttribute("viewBox", "0 0 22 10");
518
+ sw.setAttribute("width", "22");
519
+ sw.setAttribute("height", "10");
520
+ const g = document.createElementNS(SVGNS, "g");
521
+ g.setAttribute("data-edge-weight", r.weight);
522
+ const stroke = document.createElementNS(SVGNS, "path");
523
+ stroke.setAttribute("class", "pin-edge-line");
524
+ stroke.setAttribute("d", "M 1 5 L 21 5");
525
+ g.appendChild(stroke);
526
+ sw.appendChild(g);
527
+ line(sw, r.title, String(r.count));
528
+ }
529
+ }
427
530
  const health = hmLegendRows(hmAnswer);
428
531
  if (health.length) {
429
532
  const hs = document.createElement("div");
@@ -500,7 +603,7 @@ if (staticMode) {
500
603
 
501
604
  /** Canonical key for a read URL — path + the lens params (whitelisted, sorted)
502
605
  * that select a distinct snapshot. MUST match src/export.ts `canonicalKey`. */
503
- const LENS_PARAMS = ["collapse", "components", "detail", "env", "logical", "ops", "radial", "runtime", "stacks", "tier"];
606
+ const LENS_PARAMS = ["alike", "collapse", "components", "detail", "env", "logical", "ops", "radial", "runtime", "stacks", "tier"];
504
607
  function canonicalKey(path, params) {
505
608
  // Components + logical + ops views ignore detail/radial — drop them so they
506
609
  // match the single captured snapshot (MUST match src/export.ts).
@@ -1287,8 +1390,36 @@ function inspect(node) {
1287
1390
  });
1288
1391
  }
1289
1392
 
1290
- // #471: why this card is the way it is, read from chant when asked.
1291
- renderWhySection(panel, { node: node.id });
1393
+ // #881: trace the way in to a network card, or a workload behind one.
1394
+ if (!view.components && /^(AWS::(ECS|EC2|ElasticLoadBalancingV2|Lambda|RDS)::|GCP::(Run|Compute)::|Microsoft\.App\/)/.test(node.kind || "")) {
1395
+ panel.appendChild(actButton("trace from outside to here", () => traceTo(node.id), "Follow traffic from the internet to this card, hop by hop"));
1396
+ }
1397
+ // #877: a stack opens here: the cards it holds, each with its state.
1398
+ if (Array.isArray(node.attrs && node.attrs._stackOf)) {
1399
+ const h = document.createElement("h3");
1400
+ h.textContent = `stacked · ${node.attrs._stackOf.length}`;
1401
+ panel.appendChild(h);
1402
+ const dl = document.createElement("dl");
1403
+ for (const m of node.attrs._stackOf) {
1404
+ const dt = document.createElement("dt");
1405
+ dt.textContent = m.status ? STATUS_LABEL[m.status] || m.status : "card";
1406
+ const dd = document.createElement("dd");
1407
+ dd.textContent = m.id;
1408
+ dl.append(dt, dd);
1409
+ }
1410
+ panel.appendChild(dl);
1411
+ panel.appendChild(actButton("draw them all", () => { view.alike = false; load(); }, "Turn stacking off and draw every card"));
1412
+ }
1413
+ if (typeof (node.attrs && node.attrs._usedBy) === "number") {
1414
+ const p = document.createElement("p");
1415
+ p.style.color = "var(--muted)";
1416
+ p.textContent = `${node.attrs._usedBy} cards refer to this one; their lines are left out while alike cards are stacked.`;
1417
+ panel.appendChild(p);
1418
+ }
1419
+
1420
+ // #471: why this card is the way it is, read from chant when asked. A
1421
+ // stack (#877) is behold's, not chant's, so it has no why of its own.
1422
+ if (!Array.isArray(node.attrs && node.attrs._stackOf)) renderWhySection(panel, { node: node.id });
1292
1423
 
1293
1424
  // #401: the behaviour block, field by field, with a badge on every figure.
1294
1425
  // The colour on the card carries one number at a time (whichever mode is
@@ -1860,7 +1991,7 @@ function wire(ir) {
1860
1991
  // member (#475) is the estate member the view is on: a host opens behold with
1861
1992
  // ?member=, and picking a card or a member box moves it. It changes no fetch;
1862
1993
  // the graph is the whole estate, framed on that member's box.
1863
- const view = { member: null, env: null, gates: null, focus: null, run: null, detail: 2, components: true, logical: false, runtime: false, ops: false, tier: null, target: null, stack: null, radial: false, collapse: false, compareTo: null };
1994
+ const view = { member: null, env: null, gates: null, focus: null, run: null, detail: 2, components: true, logical: false, runtime: false, ops: false, tier: null, target: null, stack: null, radial: false, collapse: false, alike: false, compareTo: null };
1864
1995
 
1865
1996
  // #182: `components` is the boot default, but a project that declares no
1866
1997
  // components renders it as ZERO nodes — the first screen was a blank graph
@@ -2075,6 +2206,21 @@ function renderPanelView() {
2075
2206
  );
2076
2207
  if (estate) radial.disabled = true;
2077
2208
  zoom.appendChild(radial);
2209
+ // #877: cards of one kind in a box stack into one with a count. An estate
2210
+ // lens, like collapse: the server stacks within each project's box.
2211
+ if (estate) {
2212
+ zoom.appendChild(
2213
+ panelOpt(
2214
+ "stack alike",
2215
+ view.alike,
2216
+ () => {
2217
+ view.alike = !view.alike;
2218
+ load();
2219
+ },
2220
+ "Three or more cards of one kind in a box draw as one card with a count; a card many others refer to carries the number instead of the lines",
2221
+ ),
2222
+ );
2223
+ }
2078
2224
  }
2079
2225
  const tools = document.getElementById("panel-viewtools");
2080
2226
  tools.innerHTML = "";
@@ -2083,6 +2229,7 @@ function renderPanelView() {
2083
2229
  row.className = "prow";
2084
2230
  row.appendChild(actButton("⤢ fit", () => fitGraph(), "Reset zoom/pan to fit. Pinch or ⌘/Ctrl+scroll zooms at the cursor; drag pans."));
2085
2231
  row.appendChild(actButton("↓ SVG", () => exportSvg(), "Export the current graph as a standalone SVG file"));
2232
+ row.appendChild(actButton("↓ PNG", () => exportPng(), "Save the view as a picture, with the options below"));
2086
2233
  const collapsed = document.getElementById("app").classList.contains("inspect-collapsed");
2087
2234
  row.appendChild(
2088
2235
  actButton(collapsed ? "show inspect" : "hide inspect", () => {
@@ -2098,6 +2245,24 @@ function renderPanelView() {
2098
2245
  lanes.style.cssText = "color:var(--pending);text-decoration:none;font-size:var(--t-body)";
2099
2246
  row.appendChild(lanes);
2100
2247
  tools.appendChild(row);
2248
+ // #882: the picture's options: its scale, and whether a heading and the key go in.
2249
+ const png = document.createElement("div");
2250
+ png.className = "prow png-opts";
2251
+ const scaleSel = document.createElement("select");
2252
+ for (const k of [1, 2, 3, 4]) scaleSel.add(new Option(`${k}×`, String(k), false, pngOpts.scale === k));
2253
+ scaleSel.title = "Pixels per point of the picture";
2254
+ scaleSel.addEventListener("change", () => (pngOpts.scale = Number(scaleSel.value)));
2255
+ const check = (label, prop) => {
2256
+ const l = document.createElement("label");
2257
+ const c = document.createElement("input");
2258
+ c.type = "checkbox";
2259
+ c.checked = pngOpts[prop];
2260
+ c.addEventListener("change", () => (pngOpts[prop] = c.checked));
2261
+ l.append(c, ` ${label}`);
2262
+ return l;
2263
+ };
2264
+ png.append("PNG ", scaleSel, check("heading", "heading"), check("key", "key"));
2265
+ tools.appendChild(png);
2101
2266
  }
2102
2267
 
2103
2268
  // Scope tab: which world the graph reads — env (source vs live overlay),
@@ -2773,6 +2938,7 @@ function applyWantedView(want) {
2773
2938
  }
2774
2939
  if (apply.lens) colourMode = apply.lens; // not written to localStorage: the link's pick, not yours
2775
2940
  if ("radial" in apply) view.radial = apply.radial;
2941
+ if ("alike" in apply) view.alike = apply.alike;
2776
2942
  if ("gates" in apply) view.gates = apply.gates;
2777
2943
  if ("focus" in apply) view.focus = apply.focus; // #569: drawn by drawTgReads, no new read
2778
2944
  if ("run" in apply) view.run = apply.run; // #569: which run the view draws; read in the message handler
@@ -2790,7 +2956,7 @@ function applyWantedView(want) {
2790
2956
  return fetchKey() !== before;
2791
2957
  }
2792
2958
  function fetchKey() {
2793
- return [view.env, zoomValue(), view.tier, view.radial].join("|");
2959
+ return [view.env, zoomValue(), view.tier, view.radial, view.alike].join("|");
2794
2960
  }
2795
2961
 
2796
2962
  // #476: the host moves the view with a `behold:view` message carrying the same
@@ -3092,6 +3258,7 @@ function syncViewUrl() {
3092
3258
  lens: colourMode,
3093
3259
  node: place.node || selectedNodeId,
3094
3260
  radial: view.radial && !view.components && !view.logical && !view.ops,
3261
+ alike: view.alike && !view.components && !view.logical && !view.ops,
3095
3262
  gates: view.gates,
3096
3263
  focus: view.focus,
3097
3264
  run: view.run,
@@ -3232,16 +3399,185 @@ function renderPanelModel() {
3232
3399
  }
3233
3400
  }
3234
3401
  renderEdgeLegend(host, ir);
3402
+ renderNetworkSection(host, ir);
3235
3403
  renderBehaviourRefusal(host);
3236
3404
  renderBehaviourDiagnostics(host);
3237
3405
  }
3238
3406
 
3407
+ // #881: the network section. The trace reads the rules on each card, which
3408
+ // only the attributes zoom (detail 3) carries, so the section reads that graph
3409
+ // once per env and tier, through apiFetch (a static export captures it). The
3410
+ // trace and the findings are computed here, from that graph (web/net-trace.js).
3411
+ const NETWORK_KIND = /^(AWS::(EC2|ElasticLoadBalancingV2)::|GCP::(Compute|Run)::|Microsoft\.(Network|App)\/)/;
3412
+ const net = { key: null, ir: null, error: null, from: OUTSIDE, to: null, port: 80, result: null };
3413
+
3414
+ function netKey() {
3415
+ return `${view.env || ""}|${view.tier || ""}`;
3416
+ }
3417
+
3418
+ function loadNetworkGraph() {
3419
+ const key = netKey();
3420
+ if (net.key === key) return;
3421
+ Object.assign(net, { key, ir: null, error: null, result: null });
3422
+ const q = new URLSearchParams({ detail: "3" });
3423
+ if (view.env) q.set("env", view.env);
3424
+ if (view.tier) q.set("tier", view.tier);
3425
+ apiFetch(`${view.env ? "/api/overlay" : "/api/graph"}?${q}`)
3426
+ .then((r) => r.json())
3427
+ .then((d) => {
3428
+ if (net.key !== key) return;
3429
+ if (!d.ir) throw new Error(d.error || "no graph");
3430
+ net.ir = d.ir;
3431
+ if (net.to) runTrace();
3432
+ renderPanelModel();
3433
+ })
3434
+ .catch((err) => {
3435
+ if (net.key !== key) return;
3436
+ net.error = String(err.message || err);
3437
+ renderPanelModel();
3438
+ });
3439
+ }
3440
+
3441
+ function runTrace() {
3442
+ if (!net.ir || !net.to) return;
3443
+ net.result = traceRoute(net.ir, { from: net.from, to: net.to, port: net.port });
3444
+ markTrace();
3445
+ }
3446
+
3447
+ /** Trace from outside to a card, from the inspect pane. */
3448
+ function traceTo(id) {
3449
+ Object.assign(net, { from: OUTSIDE, to: id });
3450
+ loadNetworkGraph();
3451
+ runTrace();
3452
+ setPanelTab("model");
3453
+ renderPanelModel();
3454
+ }
3455
+
3456
+ /** Each hop's card marked open or closed on the canvas; the rest fade. */
3457
+ function markTrace() {
3458
+ const svg = document.querySelector("#graph svg");
3459
+ if (!svg) return;
3460
+ svg.querySelectorAll(".trace-open, .trace-closed").forEach((n) => n.classList.remove("trace-open", "trace-closed"));
3461
+ const hops = (net.result && net.result.hops) || [];
3462
+ svg.classList.toggle("tracing", hops.length > 0);
3463
+ for (const h of hops) {
3464
+ const g = h.id && svg.querySelector(`g[data-node-id="${CSS.escape(h.id)}"]`);
3465
+ // A card two hops share stays closed if either is.
3466
+ if (g && !g.classList.contains("trace-closed")) g.classList.add(h.open ? "trace-open" : "trace-closed");
3467
+ if (g && !h.open) g.classList.replace("trace-open", "trace-closed");
3468
+ }
3469
+ }
3470
+
3471
+ /** A stack-qualified id (`aws/<stack>::alb`) reads as its member and name. */
3472
+ function shortIds(text) {
3473
+ return text.replace(/([^\s/]+\/)[^\s/:]*::/g, "$1");
3474
+ }
3475
+
3476
+ /** A row whose text wraps: a dot, what it is, the sentence, and a tag. */
3477
+ function netRow(color, what, text, tag, onClick) {
3478
+ const row = document.createElement("div");
3479
+ row.className = "net-row" + (onClick ? " clickable" : "");
3480
+ const dot = document.createElement("span");
3481
+ dot.className = "dot";
3482
+ dot.style.background = color;
3483
+ const body = document.createElement("span");
3484
+ const w = document.createElement("b");
3485
+ w.textContent = what;
3486
+ // A stack-qualified id (`aws/<stack>::alb`) reads as its member and name.
3487
+ body.append(w, " " + shortIds(text));
3488
+ if (tag) {
3489
+ const t = document.createElement("span");
3490
+ t.className = "tag";
3491
+ t.textContent = tag;
3492
+ body.appendChild(t);
3493
+ }
3494
+ row.append(dot, body);
3495
+ if (onClick) row.addEventListener("click", onClick);
3496
+ return row;
3497
+ }
3498
+
3499
+ function renderNetworkSection(host, ir) {
3500
+ if (view.components || view.ops || !(ir.nodes || []).some((n) => NETWORK_KIND.test(n.kind || ""))) return;
3501
+ loadNetworkGraph();
3502
+ host.appendChild(panelHeading("network"));
3503
+ if (net.error) {
3504
+ host.appendChild(panelMuted(`the network couldn't be read: ${net.error}`));
3505
+ return;
3506
+ }
3507
+ if (!net.ir) {
3508
+ host.appendChild(panelMuted("reading the network…"));
3509
+ return;
3510
+ }
3511
+ const findings = networkFindings(net.ir);
3512
+ if (!findings.length) host.appendChild(panelMuted("no findings: no ranges overlap, every public subnet has a way out, no load balancer sits in one zone, and no admin port is open to anyone."));
3513
+ for (const f of findings) host.appendChild(netRow("var(--degraded)", f.finding, f.text, "", () => selectNode(f.ids[0])));
3514
+
3515
+ // The trace: from, to, port.
3516
+ const cards = net.ir.nodes.filter((n) => NETWORK_KIND.test(n.kind || "") || /^(AWS::(ECS|EC2|Lambda|RDS)::|GCP::Run::|Microsoft\.App\/)/.test(n.kind || "")).map((n) => n.id).sort();
3517
+ const pick = (label, value, options, onChange) => {
3518
+ const row = document.createElement("label");
3519
+ row.className = "net-pick";
3520
+ row.append(label + " ");
3521
+ const sel = document.createElement("select");
3522
+ for (const [v, text] of options) {
3523
+ const o = document.createElement("option");
3524
+ o.value = v;
3525
+ o.textContent = text;
3526
+ if (v === value) o.selected = true;
3527
+ sel.appendChild(o);
3528
+ }
3529
+ sel.addEventListener("change", () => onChange(sel.value));
3530
+ row.appendChild(sel);
3531
+ return row;
3532
+ };
3533
+ const form = document.createElement("div");
3534
+ form.className = "net-trace";
3535
+ form.appendChild(pick("from", net.from, [[OUTSIDE, "outside (the internet)"], ...cards.map((c) => [c, c])], (v) => (net.from = v)));
3536
+ form.appendChild(pick("to", net.to || "", [["", "pick a card"], ...cards.map((c) => [c, c])], (v) => (net.to = v || null)));
3537
+ const portRow = document.createElement("label");
3538
+ portRow.className = "net-pick";
3539
+ portRow.append("port ");
3540
+ const port = document.createElement("input");
3541
+ port.type = "number";
3542
+ port.min = "1";
3543
+ port.max = "65535";
3544
+ port.value = String(net.port);
3545
+ port.addEventListener("change", () => (net.port = Number(port.value)));
3546
+ portRow.appendChild(port);
3547
+ form.appendChild(portRow);
3548
+ const row = document.createElement("div");
3549
+ row.className = "prow";
3550
+ row.appendChild(
3551
+ actButton("trace", () => {
3552
+ net.port = Number(port.value);
3553
+ runTrace();
3554
+ renderPanelModel();
3555
+ }, "Follow the traffic hop by hop and mark where it stops"),
3556
+ );
3557
+ if (net.result) row.appendChild(actButton("clear", () => { net.result = null; markTrace(); renderPanelModel(); }));
3558
+ form.appendChild(row);
3559
+ host.appendChild(form);
3560
+
3561
+ const r = net.result;
3562
+ if (!r) return;
3563
+ if (r.unread) {
3564
+ host.appendChild(panelMuted(r.unread));
3565
+ return;
3566
+ }
3567
+ host.appendChild(panelMuted(shortIds(r.reached ? `${r.port} arrives at ${r.to}.` : `${r.port} stops at ${r.stop}.`)));
3568
+ for (const h of r.hops) {
3569
+ const row = netRow(h.open ? "var(--managed)" : "var(--degraded)", h.step, h.why, h.basis === "live" ? "live" : h.seen ? "source · card live" : "source", h.id ? () => selectNode(h.id) : undefined);
3570
+ row.title = h.basis === "live" ? "Judged from the rule as the live estate holds it" : h.seen ? "Judged from the rule in the source; the card itself was read live" : "Judged from the source alone";
3571
+ host.appendChild(row);
3572
+ }
3573
+ }
3574
+
3239
3575
  // #553: the CI edge kinds this graph draws, each with a stroke drawn by the
3240
3576
  // same rules as the graph's own edges (index.html matches `.edge-swatch` beside
3241
3577
  // `#graph`), so the legend changes with the theme. Nothing on a graph that
3242
3578
  // holds only references.
3243
3579
  function renderEdgeLegend(host, ir) {
3244
- const rows = edgeLegend(ir.edges || []);
3580
+ const rows = [...edgeLegend(ir.edges || []), ...weightLegend(lastEdgeWeights)];
3245
3581
  if (!rows.length) return;
3246
3582
  host.appendChild(panelHeading("edges"));
3247
3583
  for (const r of rows) {
@@ -3256,6 +3592,7 @@ function renderEdgeLegend(host, ir) {
3256
3592
  const g = document.createElementNS(SVGNS, "g");
3257
3593
  if (r.kind) g.setAttribute("data-edge-kind", r.kind);
3258
3594
  if (r.cross) g.setAttribute("data-edge-cross", "true");
3595
+ if (r.weight) g.setAttribute("data-edge-weight", r.weight);
3259
3596
  const line = document.createElementNS(SVGNS, "path");
3260
3597
  line.setAttribute("class", "pin-edge-line");
3261
3598
  line.setAttribute("d", "M 1 5 L 27 5");
@@ -7976,6 +8313,7 @@ function relabelEdgeChip(chip, kind, via) {
7976
8313
  // for a CI edge (#553), its `kind` and `crossPipeline` (web/edge-kind.js says
7977
8314
  // them in words). Shown as a native SVG <title> tooltip on hover; the stamped
7978
8315
  // attributes also drive the dashed and per-kind styles (index.html).
8316
+ let lastEdgeWeights = new Map();
7979
8317
  function wireEdgeHighlight(svgEl, ir) {
7980
8318
  const edges = [...svgEl.querySelectorAll("g[data-edge-from]")];
7981
8319
  if (!edges.length) return;
@@ -7983,6 +8321,12 @@ function wireEdgeHighlight(svgEl, ir) {
7983
8321
  // two kinds on one pair keep their own reason. pinhole stamps data-edge-via
7984
8322
  // itself; this fills it in where it did not.
7985
8323
  const viaOf = viaIndex(ir.edges || []);
8324
+ // #878: each reference weighed by how it was found (web/edge-weight.js).
8325
+ lastEdgeWeights = edgeWeights(ir.edges || [], new Map((ir.nodes || []).map((n) => [n.id, n.kind])));
8326
+ for (const g of edges) {
8327
+ const w = lastEdgeWeights.get(`${g.getAttribute("data-edge-from")}→${g.getAttribute("data-edge-to")}`);
8328
+ if (w) g.setAttribute("data-edge-weight", w);
8329
+ }
7986
8330
  for (const g of edges) {
7987
8331
  const from = g.getAttribute("data-edge-from");
7988
8332
  const to = g.getAttribute("data-edge-to");
@@ -7997,6 +8341,7 @@ function wireEdgeHighlight(svgEl, ir) {
7997
8341
  }
7998
8342
  // behold#744: raised under the terragucci reads' layer, whose lines and pills stay over every edge.
7999
8343
  const raise = (g) => g.parentNode && g.parentNode.insertBefore(g, g.parentNode.querySelector(":scope > [data-tg-reads]"));
8344
+ wireEdgeLabelPeek(svgEl);
8000
8345
  // Delegated: raise whichever edge the pointer is over (its hit-path catches it).
8001
8346
  svgEl.addEventListener("mouseover", (e) => {
8002
8347
  const g = e.target.closest && e.target.closest("g[data-edge-from]");
@@ -8638,6 +8983,7 @@ function render(ir, svg, m) {
8638
8983
  if (embedOpts.bare) quietCardLines(svgEl);
8639
8984
  setupGraphViewBox(svgEl);
8640
8985
  wireEdgeHighlight(svgEl, ir);
8986
+ markTrace(); // #881: a trace stays marked across a redraw
8641
8987
  }
8642
8988
  // #712: only the dots preview's meta carries `dots`. #715: a live carve, when the gate opened.
8643
8989
  if (svgEl && m && m.dots) {
@@ -8971,16 +9317,51 @@ function scaleBoxLabels() {
8971
9317
  const size = Math.max(l.base, Math.min(l.base / scale, cap));
8972
9318
  l.el.setAttribute("font-size", String(Math.round(size * 10) / 10));
8973
9319
  }
9320
+ declutterBoxHeads(labels);
9321
+ }
9322
+
9323
+ /**
9324
+ * A narrow box can't hold its title and its count badge on one row: the two
9325
+ * ran into each other ("awscards · all managed"). The title is the box's
9326
+ * name, so it keeps the row; the badge steps aside and becomes the box's
9327
+ * tooltip instead, and comes back once the zoom leaves it room (behold#824).
9328
+ */
9329
+ function declutterBoxHeads(labels) {
9330
+ const byBox = new Map();
9331
+ for (const l of labels) (byBox.get(l.box) ?? byBox.set(l.box, []).get(l.box)).push(l.el);
9332
+ for (const els of byBox.values()) {
9333
+ const badge = els.find((t) => t.getAttribute("text-anchor") === "end");
9334
+ const title = els.find((t) => t !== badge);
9335
+ if (!badge || !title) continue;
9336
+ badge.style.display = "";
9337
+ let clash = false;
9338
+ try {
9339
+ const a = title.getBBox();
9340
+ const b = badge.getBBox();
9341
+ clash = a.x + a.width + 6 > b.x;
9342
+ } catch {
9343
+ continue;
9344
+ }
9345
+ badge.style.display = clash ? "none" : "";
9346
+ const rect = title.parentNode && title.parentNode.querySelector(":scope > rect[data-group-id]");
9347
+ if (rect && clash && !rect.querySelector(":scope > title")) {
9348
+ const tip = document.createElementNS(SVGNS, "title");
9349
+ tip.textContent = `${rect.getAttribute("data-group-id")}: ${badge.textContent}`;
9350
+ rect.appendChild(tip);
9351
+ }
9352
+ }
8974
9353
  }
8975
9354
 
8976
9355
  // behold#824: an edge's label (`import`, `HealthCheckId`) is drawn at 10.5
8977
- // units, which on a graph fitted at a quarter scale is under 3px — present but
8978
- // unreadable. Each label's pill and text are scaled about the pill's own centre
8979
- // until the text renders at EDGE_LABEL_MIN_PX on screen, up to EDGE_LABEL_MAX_K
8980
- // times its drawn size, so it stays on its line and never swamps the cards.
8981
- // Zoomed in far enough, the label is left exactly as pinhole drew it.
8982
- const EDGE_LABEL_MIN_PX = 9;
8983
- const EDGE_LABEL_MAX_K = 3;
9356
+ // units, which on a graph fitted at a quarter scale is under 3px, and enlarged
9357
+ // to be readable there it piles onto the cards around it. So a label shows at
9358
+ // its own size once the zoom makes it readable (EDGE_LABEL_MIN_PX on screen),
9359
+ // and below that it is hidden unless its edge is lit: hovering a card lights
9360
+ // every edge on it (`.edge-hi`), and hovering an edge peeks its own labels.
9361
+ // A lit small label is drawn up to EDGE_LABEL_MAX_K times larger, so it can be
9362
+ // read; only a card's few edges light at once, so they don't pile up.
9363
+ const EDGE_LABEL_MIN_PX = 8;
9364
+ const EDGE_LABEL_MAX_K = 4;
8984
9365
  let edgeLabelState = { svg: null, scale: null };
8985
9366
 
8986
9367
  function scaleEdgeLabels() {
@@ -8994,16 +9375,35 @@ function scaleEdgeLabels() {
8994
9375
  for (const g of svg.querySelectorAll("g[data-edge-via]")) {
8995
9376
  const text = g.querySelector(":scope > text");
8996
9377
  const rect = g.querySelector(":scope > rect");
8997
- if (!text || !rect) continue;
9378
+ if (!text) continue;
8998
9379
  const size = parseFloat(text.getAttribute("font-size")) || 10.5;
8999
- const k = Math.min(EDGE_LABEL_MAX_K, Math.max(1, EDGE_LABEL_MIN_PX / (size * scale)));
9000
- const cx = Number(rect.getAttribute("x")) + Number(rect.getAttribute("width")) / 2;
9001
- const cy = Number(rect.getAttribute("y")) + Number(rect.getAttribute("height")) / 2;
9380
+ const small = size * scale < EDGE_LABEL_MIN_PX;
9381
+ g.toggleAttribute("data-label-small", small);
9382
+ // A small label shows only while its edge is lit, a few at a time, so it
9383
+ // is drawn big enough to read then, scaled about its pill's centre.
9384
+ const k = small ? Math.min(EDGE_LABEL_MAX_K, EDGE_LABEL_MIN_PX / (size * scale)) : 1;
9385
+ const cx = rect ? Number(rect.getAttribute("x")) + Number(rect.getAttribute("width")) / 2 : Number(text.getAttribute("x"));
9386
+ const cy = rect ? Number(rect.getAttribute("y")) + Number(rect.getAttribute("height")) / 2 : Number(text.getAttribute("y"));
9002
9387
  const t = k === 1 ? null : `translate(${cx} ${cy}) scale(${Math.round(k * 100) / 100}) translate(${-cx} ${-cy})`;
9003
- for (const el of [rect, text]) t ? el.setAttribute("transform", t) : el.removeAttribute("transform");
9388
+ for (const el of rect ? [rect, text] : [text]) t ? el.setAttribute("transform", t) : el.removeAttribute("transform");
9004
9389
  }
9005
9390
  }
9006
9391
 
9392
+ /** Hovering an edge shows the labels that belong to it, however far out the zoom. */
9393
+ function wireEdgeLabelPeek(svgEl) {
9394
+ const labelsOf = (from, to) => svgEl.querySelectorAll(`g[data-edge-from="${CSS.escape(from)}"][data-edge-to="${CSS.escape(to)}"][data-edge-via]`);
9395
+ svgEl.addEventListener("mouseover", (e) => {
9396
+ const g = e.target.closest && e.target.closest("g[data-edge-from]");
9397
+ if (!g) return;
9398
+ for (const l of labelsOf(g.getAttribute("data-edge-from"), g.getAttribute("data-edge-to"))) l.classList.add("label-peek");
9399
+ });
9400
+ svgEl.addEventListener("mouseout", (e) => {
9401
+ const g = e.target.closest && e.target.closest("g[data-edge-from]");
9402
+ if (!g) return;
9403
+ for (const l of labelsOf(g.getAttribute("data-edge-from"), g.getAttribute("data-edge-to"))) l.classList.remove("label-peek");
9404
+ });
9405
+ }
9406
+
9007
9407
  // How much of the viewBox one card should take when ⌘K lands on it (#393): the
9008
9408
  // window is this many card-widths across, so a 301-card estate arrives readable
9009
9409
  // rather than at whatever zoom the last gesture left. Never wider than the fit,
@@ -9882,6 +10282,8 @@ async function loadOnce(opts = {}, isCurrent = () => true) {
9882
10282
  // and the ops view have no member boxes to shut — and it rides both the
9883
10283
  // source graph and the overlay, so picking an env doesn't undo it.
9884
10284
  if (view.collapse && !view.components && !view.ops) q.set("collapse", "1");
10285
+ // #877: stack alike cards, the same estate-box lens on both routes.
10286
+ if (view.alike && !view.components && !view.logical && !view.ops) q.set("alike", "1");
9885
10287
  // The CI + resources facets are component-DAG-mode-only details. Load
9886
10288
  // both whenever components mode is on, env picked or not — #59 unifies
9887
10289
  // the CI facet (#58), the live-status join (#57), and resources (#59) so
@@ -10915,6 +11317,140 @@ function exportSvg() {
10915
11317
  nowline(`↓ exported ${a.download}`);
10916
11318
  }
10917
11319
 
11320
+ // behold#882: the graph as a picture, for a document or a slide. The SVG on
11321
+ // the page leans on the stylesheet (theme variables, the cloud tints, edge
11322
+ // styles) and on linked vendor marks, none of which a bare copy carries, so
11323
+ // the copy gets every element's computed paint written onto it and each mark
11324
+ // inlined. It is the view as it stands (zoomed in, it is the zoomed view),
11325
+ // at 1-4x, optionally under a heading and with the graph's key drawn in.
11326
+ const PNG_PAINT = ["fill", "stroke", "stroke-width", "stroke-dasharray", "stroke-linecap", "opacity", "fill-opacity", "stroke-opacity", "font-size", "font-family", "font-weight", "display", "visibility"];
11327
+ const PNG_HEAD = 44;
11328
+ let pngOpts = { scale: 2, heading: true, key: true };
11329
+
11330
+ async function inlineMarks(clone) {
11331
+ for (const img of clone.querySelectorAll("image")) {
11332
+ const href = img.getAttribute("href") || img.getAttribute("xlink:href") || "";
11333
+ if (!href || href.startsWith("data:")) continue;
11334
+ try {
11335
+ const text = await (await fetch(href)).text();
11336
+ img.setAttribute("href", `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(text)))}`);
11337
+ } catch {
11338
+ img.remove();
11339
+ }
11340
+ }
11341
+ }
11342
+
11343
+ function keyRows() {
11344
+ const legend = document.getElementById("graph-legend");
11345
+ if (!legend || legend.classList.contains("closed")) return [];
11346
+ const rows = [];
11347
+ for (const el of legend.children) {
11348
+ if (el.classList.contains("gl-head")) continue;
11349
+ if (el.classList.contains("gl-sub")) {
11350
+ rows.push({ sub: el.textContent });
11351
+ continue;
11352
+ }
11353
+ const swatch = el.firstElementChild;
11354
+ const colours = swatch && swatch.children.length ? [...swatch.children].map((c) => getComputedStyle(c).backgroundColor) : swatch ? [getComputedStyle(swatch).backgroundColor] : [];
11355
+ const text = el.querySelector(".grow")?.textContent ?? "";
11356
+ const count = el.querySelector(".gl-count")?.textContent ?? "";
11357
+ rows.push({ colours, text, count });
11358
+ }
11359
+ return rows;
11360
+ }
11361
+
11362
+ async function exportPng() {
11363
+ const svg = currentSvg();
11364
+ if (!svg || !vb) {
11365
+ nowline("✗ export: no graph loaded yet");
11366
+ return;
11367
+ }
11368
+ const { scale, heading, key } = pngOpts;
11369
+ // At the fit the view leaves room for the floating panel; the picture takes
11370
+ // the graph's own bounds instead, with a margin. Zoomed or panned, it takes
11371
+ // the view as it stands.
11372
+ const pad = vbInit ? Math.max(vbInit[2], vbInit[3]) * 0.02 : 0;
11373
+ const area = vbAtFit && vbInit ? [vbInit[0] - pad, vbInit[1] - pad, vbInit[2] + 2 * pad, vbInit[3] + 2 * pad] : vb;
11374
+ const box = svg.getBoundingClientRect();
11375
+ const w = Math.round(box.width);
11376
+ const h = Math.round((w * area[3]) / area[2]);
11377
+ const head = heading ? PNG_HEAD : 0;
11378
+ // The key gets a band of its own under the graph, never drawn over it.
11379
+ const rowsForKey = key ? keyRows() : [];
11380
+ const keyLine = 17;
11381
+ const keyBand = rowsForKey.length ? rowsForKey.length * keyLine + 28 : 0;
11382
+ const clone = svg.cloneNode(true);
11383
+ const from = [svg, ...svg.querySelectorAll("*")];
11384
+ const to = [clone, ...clone.querySelectorAll("*")];
11385
+ for (let i = 0; i < from.length && i < to.length; i++) {
11386
+ const cs = getComputedStyle(from[i]);
11387
+ to[i].setAttribute("style", PNG_PAINT.map((p) => `${p}:${cs.getPropertyValue(p)}`).join(";"));
11388
+ }
11389
+ await inlineMarks(clone);
11390
+ clone.setAttribute("x", "0");
11391
+ clone.setAttribute("y", String(head));
11392
+ clone.setAttribute("width", String(w));
11393
+ clone.setAttribute("height", String(h));
11394
+ clone.setAttribute("viewBox", area.join(" "));
11395
+ const root = getComputedStyle(document.documentElement);
11396
+ const bg = root.getPropertyValue("--bg").trim() || "#ffffff";
11397
+ const fg = root.getPropertyValue("--fg").trim() || "#000000";
11398
+ const muted = root.getPropertyValue("--muted").trim() || fg;
11399
+ const esc = (t) => String(t).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
11400
+ const title = esc(document.title || "behold");
11401
+ const sub = esc(document.getElementById("meta")?.textContent?.trim() ?? "");
11402
+ const total = h + head + keyBand;
11403
+ const parts = [`<rect width="${w}" height="${total}" fill="${bg}"/>`];
11404
+ if (heading) {
11405
+ parts.push(`<text x="16" y="22" fill="${fg}" font-family="system-ui, sans-serif" font-size="16" font-weight="700">${title}</text>`);
11406
+ parts.push(`<text x="16" y="38" fill="${muted}" font-family="system-ui, sans-serif" font-size="11">${sub}</text>`);
11407
+ }
11408
+ parts.push(new XMLSerializer().serializeToString(clone));
11409
+ if (rowsForKey.length) {
11410
+ const kx = 16;
11411
+ const ky = head + h + 14;
11412
+ rowsForKey.forEach((r, i) => {
11413
+ const y = ky + i * keyLine + 9;
11414
+ if (r.sub) {
11415
+ parts.push(`<text x="${kx}" y="${y + 3}" fill="${muted}" font-family="system-ui, sans-serif" font-size="10.5">${esc(r.sub)}</text>`);
11416
+ return;
11417
+ }
11418
+ r.colours.forEach((c, j) => parts.push(`<rect x="${kx + j * 9}" y="${y - 6}" width="7" height="11" rx="1.5" fill="${c}"/>`));
11419
+ parts.push(`<text x="${kx + 32}" y="${y + 3}" fill="${fg}" font-family="system-ui, sans-serif" font-size="11.5">${esc(r.text)}${r.count ? ` <tspan fill="${muted}">${esc(r.count)}</tspan>` : ""}</text>`);
11420
+ });
11421
+ }
11422
+ const doc = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${w}" height="${total}" viewBox="0 0 ${w} ${total}">${parts.join("")}</svg>`;
11423
+ const url = URL.createObjectURL(new Blob([doc], { type: "image/svg+xml" }));
11424
+ try {
11425
+ const img = new Image();
11426
+ await new Promise((ok, fail) => {
11427
+ img.onload = ok;
11428
+ img.onerror = () => fail(new Error("the picture did not render"));
11429
+ img.src = url;
11430
+ });
11431
+ const canvas = document.createElement("canvas");
11432
+ canvas.width = w * scale;
11433
+ canvas.height = total * scale;
11434
+ const ctx = canvas.getContext("2d");
11435
+ ctx.scale(scale, scale);
11436
+ ctx.drawImage(img, 0, 0);
11437
+ const blob = await new Promise((ok) => canvas.toBlob(ok, "image/png"));
11438
+ const a = document.createElement("a");
11439
+ a.href = URL.createObjectURL(blob);
11440
+ a.download = `behold-${zoomValue()}${view.env ? "-" + view.env : ""}@${scale}x.png`;
11441
+ a.style.display = "none";
11442
+ document.body.appendChild(a);
11443
+ a.click();
11444
+ a.remove();
11445
+ setTimeout(() => URL.revokeObjectURL(a.href), 1000);
11446
+ nowline(`↓ exported ${a.download}`);
11447
+ } catch (e) {
11448
+ nowline(`✗ export: ${e.message}`);
11449
+ } finally {
11450
+ URL.revokeObjectURL(url);
11451
+ }
11452
+ }
11453
+
10918
11454
  // --- Command palette (⌘K / Ctrl+K, #73) -----------------------------------
10919
11455
  // Ported from spicypath's FG-036 pattern (../spicypath/src/index.html: search
10920
11456
  // `#palette`, `paletteCommands`, `openPalette`) — same shape (module-level
@@ -11014,6 +11550,9 @@ function paletteCommands() {
11014
11550
  if (!staticMode && !view.components && !view.ops) {
11015
11551
  c.push([view.collapse ? "Expand all" : "Collapse large boxes", () => { view.collapse = !view.collapse; load(); }]);
11016
11552
  }
11553
+ if (!view.components && !view.logical && !view.ops && lastMeta && lastMeta.estate > 1) {
11554
+ c.push([view.alike ? "Unstack alike cards" : "Stack alike cards", () => { view.alike = !view.alike; load(); }]);
11555
+ }
11017
11556
 
11018
11557
  // Env/stack/tier/target selection — replaces the old header pickers.
11019
11558
  if (view.member) c.push([`member: whole estate (leave ${view.member})`, () => { view.member = null; selectedNodeId = null; renderStatusbar(); fitGraph(); }]);