@intentius/behold 0.29.56 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +323 -26
- package/THIRD_PARTY.md +21 -0
- package/demos.json +1 -1
- package/dist/cli.js +12393 -8612
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +10 -10
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-three-cloud/README.md +17 -9
- package/example-three-cloud/aws/chant.config.ts +1 -1
- package/example-three-cloud/aws/site.component.ts +13 -0
- package/example-three-cloud/azure/chant.config.ts +1 -1
- package/example-three-cloud/azure/src/site.component.ts +13 -0
- package/example-three-cloud/azure/src/site.ts +12 -46
- package/example-three-cloud/dns/chant.config.ts +1 -1
- package/example-three-cloud/dns/src/records.component.ts +14 -0
- package/example-three-cloud/dns/src/route53.ts +8 -39
- package/example-three-cloud/gcp/chant.config.ts +1 -1
- package/example-three-cloud/gcp/src/site.component.ts +13 -0
- package/example-three-cloud/gcp/src/site.ts +12 -92
- package/example-three-cloud/package-lock.json +19 -19
- package/example-three-cloud/package.json +4 -4
- package/example-three-cloud/scripts/front-door.ts +89 -15
- package/licenses/aws-architecture-icons-TERMS.md +19 -0
- package/licenses/azure-architecture-icons-Microsoft_Terms_of_Use.pdf +0 -0
- package/licenses/azure-architecture-icons-TERMS.md +20 -0
- package/licenses/google-cloud-icons-TERMS.md +15 -0
- package/package.json +8 -9
- package/web/agent-move.js +60 -0
- package/web/agent-move.test.js +55 -0
- package/web/app.js +1084 -66
- package/web/dots-lod.js +1 -1
- package/web/edge-weight.d.ts +5 -0
- package/web/edge-weight.js +71 -0
- package/web/edge-weight.test.js +49 -0
- package/web/embed.d.ts +3 -0
- package/web/embed.js +5 -3
- package/web/embed.test.js +8 -0
- package/web/icons/aws/alb.svg +1 -0
- package/web/icons/aws/api-gateway.svg +1 -0
- package/web/icons/aws/app-runner.svg +1 -0
- package/web/icons/aws/appsync.svg +1 -0
- package/web/icons/aws/athena.svg +1 -0
- package/web/icons/aws/auto-scaling.svg +1 -0
- package/web/icons/aws/backup.svg +1 -0
- package/web/icons/aws/batch.svg +1 -0
- package/web/icons/aws/bedrock-agentcore.svg +1 -0
- package/web/icons/aws/bedrock.svg +1 -0
- package/web/icons/aws/certificate-manager.svg +1 -0
- package/web/icons/aws/cloud-map.svg +1 -0
- package/web/icons/aws/cloud.svg +1 -0
- package/web/icons/aws/cloudformation.svg +1 -0
- package/web/icons/aws/cloudfront.svg +1 -0
- package/web/icons/aws/cloudtrail.svg +1 -0
- package/web/icons/aws/cloudwatch-alarm.svg +1 -0
- package/web/icons/aws/cloudwatch-logs.svg +1 -0
- package/web/icons/aws/cloudwatch.svg +1 -0
- package/web/icons/aws/codebuild.svg +1 -0
- package/web/icons/aws/codecommit.svg +1 -0
- package/web/icons/aws/codedeploy.svg +1 -0
- package/web/icons/aws/codepipeline.svg +1 -0
- package/web/icons/aws/cognito.svg +1 -0
- package/web/icons/aws/config.svg +1 -0
- package/web/icons/aws/documentdb.svg +1 -0
- package/web/icons/aws/dynamodb-table.svg +1 -0
- package/web/icons/aws/dynamodb.svg +1 -0
- package/web/icons/aws/ebs-volume.svg +1 -0
- package/web/icons/aws/ec2-instance.svg +1 -0
- package/web/icons/aws/ec2.svg +1 -0
- package/web/icons/aws/ecr-registry.svg +1 -0
- package/web/icons/aws/ecr.svg +1 -0
- package/web/icons/aws/ecs-service.svg +1 -0
- package/web/icons/aws/ecs-task.svg +1 -0
- package/web/icons/aws/ecs.svg +1 -0
- package/web/icons/aws/efs.svg +1 -0
- package/web/icons/aws/eks.svg +1 -0
- package/web/icons/aws/elastic-beanstalk.svg +1 -0
- package/web/icons/aws/elastic-ip.svg +1 -0
- package/web/icons/aws/elasticache.svg +1 -0
- package/web/icons/aws/elb.svg +1 -0
- package/web/icons/aws/emr.svg +1 -0
- package/web/icons/aws/eventbridge.svg +1 -0
- package/web/icons/aws/firehose.svg +1 -0
- package/web/icons/aws/global-accelerator.svg +1 -0
- package/web/icons/aws/glue.svg +1 -0
- package/web/icons/aws/guardduty.svg +1 -0
- package/web/icons/aws/iam.svg +1 -0
- package/web/icons/aws/internet-gateway.svg +1 -0
- package/web/icons/aws/keyspaces.svg +1 -0
- package/web/icons/aws/kinesis.svg +1 -0
- package/web/icons/aws/kms.svg +1 -0
- package/web/icons/aws/lambda-function.svg +1 -0
- package/web/icons/aws/lambda.svg +1 -0
- package/web/icons/aws/mq.svg +1 -0
- package/web/icons/aws/msk.svg +1 -0
- package/web/icons/aws/nat-gateway.svg +1 -0
- package/web/icons/aws/neptune.svg +1 -0
- package/web/icons/aws/network-acl.svg +1 -0
- package/web/icons/aws/network-firewall.svg +1 -0
- package/web/icons/aws/opensearch.svg +1 -0
- package/web/icons/aws/organizations.svg +1 -0
- package/web/icons/aws/rds-instance.svg +1 -0
- package/web/icons/aws/rds.svg +1 -0
- package/web/icons/aws/redshift.svg +1 -0
- package/web/icons/aws/route-53-hosted-zone.svg +1 -0
- package/web/icons/aws/route-53.svg +1 -0
- package/web/icons/aws/router.svg +1 -0
- package/web/icons/aws/s3-bucket.svg +1 -0
- package/web/icons/aws/s3.svg +1 -0
- package/web/icons/aws/sagemaker.svg +1 -0
- package/web/icons/aws/secrets-manager.svg +1 -0
- package/web/icons/aws/ses.svg +1 -0
- package/web/icons/aws/shield.svg +1 -0
- package/web/icons/aws/sns-topic.svg +1 -0
- package/web/icons/aws/sns.svg +1 -0
- package/web/icons/aws/sqs-queue.svg +1 -0
- package/web/icons/aws/sqs.svg +1 -0
- package/web/icons/aws/step-functions.svg +1 -0
- package/web/icons/aws/systems-manager.svg +1 -0
- package/web/icons/aws/transfer-family.svg +1 -0
- package/web/icons/aws/transit-gateway.svg +1 -0
- package/web/icons/aws/vpc-endpoints.svg +1 -0
- package/web/icons/aws/vpc-lattice.svg +1 -0
- package/web/icons/aws/vpc.svg +1 -0
- package/web/icons/aws/vpn-gateway.svg +1 -0
- package/web/icons/aws/waf.svg +1 -0
- package/web/icons/azure/app-service-plan.svg +1 -0
- package/web/icons/azure/app-services.svg +1 -0
- package/web/icons/azure/application-gateway.svg +1 -0
- package/web/icons/azure/container-app.svg +1 -0
- package/web/icons/azure/container-apps-environment.svg +1 -0
- package/web/icons/azure/container-instances.svg +1 -0
- package/web/icons/azure/container-registry.svg +1 -0
- package/web/icons/azure/cosmos-db.svg +1 -0
- package/web/icons/azure/dns-zone.svg +1 -0
- package/web/icons/azure/front-door.svg +1 -0
- package/web/icons/azure/function-app.svg +1 -0
- package/web/icons/azure/kubernetes-service.svg +1 -0
- package/web/icons/azure/load-balancer.svg +1 -0
- package/web/icons/azure/log-analytics.svg +1 -0
- package/web/icons/azure/managed-identity.svg +1 -0
- package/web/icons/azure/mysql.svg +1 -0
- package/web/icons/azure/nat.svg +1 -0
- package/web/icons/azure/network-security-group.svg +1 -0
- package/web/icons/azure/postgresql.svg +1 -0
- package/web/icons/azure/public-ip.svg +1 -0
- package/web/icons/azure/redis.svg +1 -0
- package/web/icons/azure/resource-group.svg +1 -0
- package/web/icons/azure/route-table.svg +1 -0
- package/web/icons/azure/sql-database.svg +1 -0
- package/web/icons/azure/sql-server.svg +1 -0
- package/web/icons/azure/subnet.svg +1 -0
- package/web/icons/azure/subscription.svg +1 -0
- package/web/icons/azure/virtual-machine.svg +1 -0
- package/web/icons/azure/virtual-network-gateway.svg +1 -0
- package/web/icons/azure/virtual-network.svg +1 -0
- package/web/icons/gcp/artifact-registry.svg +1 -0
- package/web/icons/gcp/bigquery.svg +1 -0
- package/web/icons/gcp/bigtable.svg +1 -0
- package/web/icons/gcp/certificate-manager.svg +1 -0
- package/web/icons/gcp/cloud-armor.svg +1 -0
- package/web/icons/gcp/cloud-build.svg +1 -0
- package/web/icons/gcp/cloud-composer.svg +1 -0
- package/web/icons/gcp/cloud-dns.svg +1 -0
- package/web/icons/gcp/cloud-functions.svg +1 -0
- package/web/icons/gcp/cloud-load-balancing.svg +1 -0
- package/web/icons/gcp/cloud-logging.svg +1 -0
- package/web/icons/gcp/cloud-monitoring.svg +1 -0
- package/web/icons/gcp/cloud-nat.svg +1 -0
- package/web/icons/gcp/cloud-router.svg +1 -0
- package/web/icons/gcp/cloud-run.svg +1 -0
- package/web/icons/gcp/cloud-scheduler.svg +1 -0
- package/web/icons/gcp/cloud-spanner.svg +1 -0
- package/web/icons/gcp/cloud-sql.svg +1 -0
- package/web/icons/gcp/cloud-storage.svg +1 -0
- package/web/icons/gcp/cloud-tasks.svg +1 -0
- package/web/icons/gcp/compute-engine.svg +1 -0
- package/web/icons/gcp/dataflow.svg +1 -0
- package/web/icons/gcp/external-ip.svg +1 -0
- package/web/icons/gcp/firestore.svg +1 -0
- package/web/icons/gcp/firewall-rules.svg +1 -0
- package/web/icons/gcp/gke.svg +1 -0
- package/web/icons/gcp/iam.svg +1 -0
- package/web/icons/gcp/kms.svg +1 -0
- package/web/icons/gcp/memorystore.svg +1 -0
- package/web/icons/gcp/persistent-disk.svg +1 -0
- package/web/icons/gcp/project.svg +1 -0
- package/web/icons/gcp/pubsub.svg +1 -0
- package/web/icons/gcp/secret-manager.svg +1 -0
- package/web/icons/gcp/vpc.svg +1 -0
- package/web/index.html +98 -9
- package/web/net-trace.js +649 -0
- package/web/net-trace.test.js +180 -0
- package/web/panel.js +28 -4
- package/web/release.js +6 -4
- package/web/release.test.js +2 -2
- package/web/search-view.d.ts +27 -0
- package/web/search-view.js +213 -0
- package/web/search-view.test.js +144 -0
- package/web/shot-frame.d.ts +5 -0
- package/web/shot-frame.js +116 -0
- package/web/shot-frame.test.js +90 -0
- package/web/themes.js +1 -1
- package/web/view-url.d.ts +18 -0
- package/web/view-url.js +162 -10
- package/web/view-url.test.js +72 -1
package/web/app.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
import "./view-repo.js"; // behold#571: first, so every read carries the page's ?repo=
|
|
12
12
|
import { createRefreshQueue } from "./refresh-queue.js";
|
|
13
13
|
import { indexCompositeMembers } from "./composite-members.js";
|
|
14
|
-
import { readViewQuery, writeViewQuery, settleView, settlePlace, refusalLine, withOpening, defaultEnv } from "./view-url.js";
|
|
14
|
+
import { readViewQuery, writeViewQuery, settleView, settlePlace, refusalLine, withOpening, defaultEnv, restoreViewQuery, viewFromObject } from "./view-url.js";
|
|
15
|
+
import { agentBanner, agentEntry, wholeQuestion } from "./agent-move.js";
|
|
15
16
|
import { quietCardLines, readEmbed, selectMessage, viewFromMessage, wheelPx, wheelZoomsBare } from "./embed.js";
|
|
16
17
|
import { WORDS as POP_WORDS, cardRoot as popCardRoot, placePopover, popReduce, popState, resourcePopover, rootPopover } from "./kiosk-popover.js";
|
|
17
18
|
import { waveListKey, waveListOf } from "./kiosk-wave-list.js";
|
|
@@ -42,6 +43,8 @@ import { auditLines as yrAuditLines, cornerText as yrCorner, datedWords as yrDat
|
|
|
42
43
|
import { cardProgress as tgCardProgress, progressLines as tgProgressLines, progressSection as tgProgressSection, stampProgress as tgStampProgress } from "./terragucci-progress.js";
|
|
43
44
|
import { seconds, whyQuery, whyView } from "./why.js";
|
|
44
45
|
import { edgeKey, edgeLabel, edgeLegend, edgeTitle, isCiKind, viaIndex } from "./edge-kind.js";
|
|
46
|
+
import { edgeWeights, weightLegend } from "./edge-weight.js";
|
|
47
|
+
import { networkFindings, OUTSIDE, traceRoute } from "./net-trace.js";
|
|
45
48
|
import { readCostLine } from "./read-cost.js";
|
|
46
49
|
import { mountHistoryPicker } from "./history-picker.js";
|
|
47
50
|
import { applyMemberFrame, createMemberFrames, pendingLine, stillPending } from "./pending.js";
|
|
@@ -71,7 +74,7 @@ import {
|
|
|
71
74
|
totalsText,
|
|
72
75
|
deltaRows,
|
|
73
76
|
} from "./behaviour-scale.js";
|
|
74
|
-
import { addPanelTab, initPanel, setPanelTab, togglePanelCollapsed, isPanelCollapsed } from "./panel.js";
|
|
77
|
+
import { addPanelTab, initPanel, setPanelTab, togglePanelCollapsed, isPanelCollapsed, foldPanelOnPhone } from "./panel.js";
|
|
75
78
|
// #254: the carve walkthrough's stepper — everything it DECIDES is a pure
|
|
76
79
|
// function in there; this file owns the fetches, the graph selection, and the
|
|
77
80
|
// "carved" marker the last step leaves on a card.
|
|
@@ -127,6 +130,8 @@ import { comparisonRow, comparisonSummary } from "./cross-env.js";
|
|
|
127
130
|
// The marker-vs-derived mark on a choudoufu card: how its identity was found.
|
|
128
131
|
import { identityMark, tagGlyphSvg } from "./identity-mark.js";
|
|
129
132
|
import { shotFromMessage, shotViewBox, tweenViewBox, unionBox, sameViewBox, heldFrame, heldInsets, heldTarget, holdsStage, medianWidth, smallStage } from "./kiosk-shot.js"; // behold#571: Watch's camera
|
|
133
|
+
import { SHOT_ATTR, SHOT_CAPTION_PX, SHOT_DIM, queryFrame, readShotFrame, shotCaption, shotLit, shotProvenance, shotState } from "./shot-frame.js"; // behold#915: the page `behold shot` photographs
|
|
134
|
+
import { countsLine, groupLabel, groupMarks, queryLine, queryMarks, searchKey, searchUrl, stackIndex, uncapturedLine } from "./search-view.js"; // behold#913: `q` drawn; behold#922: groups
|
|
130
135
|
// #712, #715: the dots layer, the zoom past the cards. Mounted for a live
|
|
131
136
|
// carve when the estate has choudoufu roots or estate rosters
|
|
132
137
|
// (/api/terragucci/carve, liveCarveGate below), or when /api/graph's meta
|
|
@@ -150,7 +155,7 @@ if (embedOpts.embed && embedOpts.bare) document.documentElement.classList.add("b
|
|
|
150
155
|
// screen, so any scroll over the graph moved it and paused Watch.
|
|
151
156
|
const kioskTouch = () => !!(embedOpts.embed && embedOpts.bare) && typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
|
152
157
|
if (kioskTouch()) document.documentElement.classList.add("kiosk-touch");
|
|
153
|
-
initPanel({ embed: embedOpts.embed, phone: typeof matchMedia === "function" && matchMedia(INSPECT_PHONE_QUERY).matches });
|
|
158
|
+
initPanel({ embed: embedOpts.embed, phone: typeof matchMedia === "function" && matchMedia(INSPECT_PHONE_QUERY).matches, phoneQuery: INSPECT_PHONE_QUERY });
|
|
154
159
|
mountThemePicker(document.getElementById("panel-theme"));
|
|
155
160
|
|
|
156
161
|
// Colour node fills by category/kind using the theme's FULL palette (spicypath-style, so the
|
|
@@ -184,9 +189,9 @@ try {
|
|
|
184
189
|
let savedColourMode = colourMode;
|
|
185
190
|
|
|
186
191
|
const COLOUR_MODE_TITLE = {
|
|
187
|
-
drift: "
|
|
188
|
-
cost: "
|
|
189
|
-
headroom: "
|
|
192
|
+
drift: "Color each card by what chant observed live — the overlay behold has always drawn",
|
|
193
|
+
cost: "Color each card by the engine's cost per hour, low to high across this estate. An entity nothing priced draws neutral, never the cheap end.",
|
|
194
|
+
headroom: "Color each card by how far it is from saturation — the LOWER of the axes the engine reported. An entity nothing priced draws neutral.",
|
|
190
195
|
};
|
|
191
196
|
|
|
192
197
|
/** `meta.behaviour` off the last render, or null. */
|
|
@@ -325,8 +330,74 @@ function recolorNodesByCategory(ir) {
|
|
|
325
330
|
const bar = g.querySelector('rect[width="4"]');
|
|
326
331
|
if (bar) bar.setAttribute("fill", "var(--runtime)");
|
|
327
332
|
}
|
|
333
|
+
markCloudBoxes();
|
|
328
334
|
renderGraphLegend();
|
|
329
335
|
}
|
|
336
|
+
|
|
337
|
+
// behold#824: an estate across clouds draws one boundary box per cloud (AWS
|
|
338
|
+
// account, Azure subscription, GCP project). Each is marked with its cloud so
|
|
339
|
+
// the stylesheet can give it that vendor's colour, box and title together, and
|
|
340
|
+
// three clouds read as three clouds at a glance rather than three grey boxes.
|
|
341
|
+
const CLOUD_OF_BOX = [
|
|
342
|
+
[/^AWS account\b/, "aws"],
|
|
343
|
+
[/^Azure subscription\b/, "azure"],
|
|
344
|
+
[/^GCP project\b/, "gcp"],
|
|
345
|
+
];
|
|
346
|
+
function cloudOfBox(title) {
|
|
347
|
+
for (const [re, cloud] of CLOUD_OF_BOX) if (re.test(title)) return cloud;
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
function markCloudBoxes() {
|
|
351
|
+
const svg = document.querySelector("#graph svg");
|
|
352
|
+
if (!svg) return;
|
|
353
|
+
// A project box (the composites and resources zooms draw one per workspace
|
|
354
|
+
// member) takes its cloud from its resources' lexicon when they share one:
|
|
355
|
+
// `dns`, Route 53 and an Op, is an AWS box.
|
|
356
|
+
const lexiconsOf = new Map();
|
|
357
|
+
for (const n of (lastGraphIr && lastGraphIr.nodes) || []) {
|
|
358
|
+
const slash = n.id.indexOf("/");
|
|
359
|
+
if (slash < 1 || !n.lexicon) continue;
|
|
360
|
+
const m = n.id.slice(0, slash);
|
|
361
|
+
(lexiconsOf.get(m) ?? lexiconsOf.set(m, new Set()).get(m)).add(n.lexicon);
|
|
362
|
+
}
|
|
363
|
+
// Only the cloud lexicons count: a member that also holds an Op or other
|
|
364
|
+
// non-cloud cards (dns, with its front-door Op) is still that cloud's.
|
|
365
|
+
const memberCloud = (id) => {
|
|
366
|
+
const clouds = [...(lexiconsOf.get(id) ?? [])].filter((l) => ["aws", "azure", "gcp"].includes(l));
|
|
367
|
+
return clouds.length === 1 ? clouds[0] : null;
|
|
368
|
+
};
|
|
369
|
+
const titles = new Map();
|
|
370
|
+
for (const rect of svg.querySelectorAll("rect[data-group-id]")) {
|
|
371
|
+
const id = rect.getAttribute("data-group-id") || "";
|
|
372
|
+
const cloud = cloudOfBox(id) || memberCloud(id);
|
|
373
|
+
if (!cloud) continue;
|
|
374
|
+
rect.setAttribute("data-cloud", cloud);
|
|
375
|
+
titles.set(rect.getAttribute("data-group-id"), cloud);
|
|
376
|
+
}
|
|
377
|
+
if (!titles.size) return;
|
|
378
|
+
for (const t of svg.querySelectorAll("text")) {
|
|
379
|
+
const cloud = titles.get((t.textContent || "").trim());
|
|
380
|
+
if (!cloud || t.getAttribute("data-cloud")) continue;
|
|
381
|
+
t.setAttribute("data-cloud", cloud);
|
|
382
|
+
// #872: the vendor's own mark before the title, drawn as published. The
|
|
383
|
+
// title moves right by the mark's width, once (data-cloud guards it).
|
|
384
|
+
const size = 20;
|
|
385
|
+
const x = Number(t.getAttribute("x"));
|
|
386
|
+
const y = Number(t.getAttribute("y"));
|
|
387
|
+
const mark = document.createElementNS(SVGNS, "image");
|
|
388
|
+
mark.setAttribute("href", `icons/${CLOUD_MARK[cloud]}.svg`);
|
|
389
|
+
mark.setAttribute("x", String(x));
|
|
390
|
+
mark.setAttribute("y", String(y - size + 4));
|
|
391
|
+
mark.setAttribute("width", String(size));
|
|
392
|
+
mark.setAttribute("height", String(size));
|
|
393
|
+
mark.setAttribute("data-cloud-mark", cloud);
|
|
394
|
+
t.parentNode.insertBefore(mark, t);
|
|
395
|
+
t.setAttribute("x", String(x + size + 6));
|
|
396
|
+
}
|
|
397
|
+
declutterBoxHeads(boxLabelsOf(svg)); // the marks moved titles right
|
|
398
|
+
}
|
|
399
|
+
/** The vendored mark each cloud box wears (src/cloud-icons.ts vendors them). */
|
|
400
|
+
const CLOUD_MARK = { aws: "aws/cloud", azure: "azure/subscription", gcp: "gcp/project" };
|
|
330
401
|
onThemeChange(() => (recolorNodesByCategory(), drawTgReads())); // behold#571: drawTgReads redraws the marks in the theme's colours
|
|
331
402
|
// behold#824: the legend on the graph itself. In drift mode a card's fill is
|
|
332
403
|
// its resource kind (one hue per kind, nothing more) and its state is the bar
|
|
@@ -337,11 +408,15 @@ onThemeChange(() => (recolorNodesByCategory(), drawTgReads())); // behold#571: d
|
|
|
337
408
|
// viewer (a "legend" button brings it back).
|
|
338
409
|
const LEGEND_KEY = "behold.graph.legend.hidden";
|
|
339
410
|
function legendHidden() {
|
|
411
|
+
let saved = null;
|
|
340
412
|
try {
|
|
341
|
-
|
|
342
|
-
} catch {
|
|
343
|
-
|
|
344
|
-
|
|
413
|
+
saved = localStorage.getItem(LEGEND_KEY);
|
|
414
|
+
} catch {}
|
|
415
|
+
// On a phone the legend starts folded to its button: open, it covers a third of the graph.
|
|
416
|
+
return saved === "1" || (saved === null && onPhone());
|
|
417
|
+
}
|
|
418
|
+
function onPhone() {
|
|
419
|
+
return typeof matchMedia === "function" && matchMedia(INSPECT_PHONE_QUERY).matches;
|
|
345
420
|
}
|
|
346
421
|
function renderGraphLegend() {
|
|
347
422
|
const host = document.getElementById("graph");
|
|
@@ -363,7 +438,7 @@ function renderGraphLegend() {
|
|
|
363
438
|
el.className = "closed";
|
|
364
439
|
el.appendChild(button("legend", "act", () => {
|
|
365
440
|
try {
|
|
366
|
-
localStorage.
|
|
441
|
+
localStorage.setItem(LEGEND_KEY, "0");
|
|
367
442
|
} catch {}
|
|
368
443
|
renderGraphLegend();
|
|
369
444
|
}));
|
|
@@ -406,7 +481,20 @@ function renderGraphLegend() {
|
|
|
406
481
|
f.style.background = colorForCategory(k);
|
|
407
482
|
fills.appendChild(f);
|
|
408
483
|
}
|
|
409
|
-
|
|
484
|
+
const clouds = [...new Set([...document.querySelectorAll("#graph rect[data-cloud]")].map((r) => r.getAttribute("data-cloud")))];
|
|
485
|
+
if (clouds.length) {
|
|
486
|
+
const sw = document.createElement("span");
|
|
487
|
+
sw.className = "gl-fills";
|
|
488
|
+
const names = { aws: "AWS", azure: "Azure", gcp: "GCP" };
|
|
489
|
+
for (const c of ["aws", "azure", "gcp"].filter((c) => clouds.includes(c))) {
|
|
490
|
+
const f = document.createElement("i");
|
|
491
|
+
f.style.background = `var(--cloud-${c})`;
|
|
492
|
+
f.title = names[c];
|
|
493
|
+
sw.appendChild(f);
|
|
494
|
+
}
|
|
495
|
+
line(sw, `box color: cloud (${["aws", "azure", "gcp"].filter((c) => clouds.includes(c)).map((c) => names[c]).join(", ")})`);
|
|
496
|
+
}
|
|
497
|
+
line(fills, "card color: resource kind");
|
|
410
498
|
const sub = document.createElement("div");
|
|
411
499
|
sub.className = "gl-sub";
|
|
412
500
|
sub.textContent = "bar and outline: state";
|
|
@@ -424,6 +512,28 @@ function renderGraphLegend() {
|
|
|
424
512
|
bar.style.background = DRIFT_STATUS_VAR[k];
|
|
425
513
|
line(bar, label, String(counts[k]));
|
|
426
514
|
}
|
|
515
|
+
const weights = weightLegend(lastEdgeWeights);
|
|
516
|
+
if (weights.length) {
|
|
517
|
+
const es = document.createElement("div");
|
|
518
|
+
es.className = "gl-sub";
|
|
519
|
+
es.textContent = "edges";
|
|
520
|
+
el.appendChild(es);
|
|
521
|
+
for (const r of weights) {
|
|
522
|
+
const sw = document.createElementNS(SVGNS, "svg");
|
|
523
|
+
sw.setAttribute("class", "edge-swatch gl-edge");
|
|
524
|
+
sw.setAttribute("viewBox", "0 0 22 10");
|
|
525
|
+
sw.setAttribute("width", "22");
|
|
526
|
+
sw.setAttribute("height", "10");
|
|
527
|
+
const g = document.createElementNS(SVGNS, "g");
|
|
528
|
+
g.setAttribute("data-edge-weight", r.weight);
|
|
529
|
+
const stroke = document.createElementNS(SVGNS, "path");
|
|
530
|
+
stroke.setAttribute("class", "pin-edge-line");
|
|
531
|
+
stroke.setAttribute("d", "M 1 5 L 21 5");
|
|
532
|
+
g.appendChild(stroke);
|
|
533
|
+
sw.appendChild(g);
|
|
534
|
+
line(sw, r.title, String(r.count));
|
|
535
|
+
}
|
|
536
|
+
}
|
|
427
537
|
const health = hmLegendRows(hmAnswer);
|
|
428
538
|
if (health.length) {
|
|
429
539
|
const hs = document.createElement("div");
|
|
@@ -500,12 +610,14 @@ if (staticMode) {
|
|
|
500
610
|
|
|
501
611
|
/** Canonical key for a read URL — path + the lens params (whitelisted, sorted)
|
|
502
612
|
* 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"];
|
|
613
|
+
const LENS_PARAMS = ["alike", "collapse", "components", "countBy", "detail", "env", "logical", "ops", "plan", "q", "radial", "runtime", "snapshot", "stacks", "tier"]; // q, snapshot: behold#913's /api/search; countBy, plan: behold#922
|
|
504
614
|
function canonicalKey(path, params) {
|
|
505
615
|
// Components + logical + ops views ignore detail/radial — drop them so they
|
|
506
616
|
// match the single captured snapshot (MUST match src/export.ts).
|
|
507
617
|
const flat = params.get("components") === "1" || params.get("logical") === "1" || params.get("ops") === "1" || params.get("stacks") === "1";
|
|
508
|
-
|
|
618
|
+
// behold#922: `plan` picks a snapshot of /api/graph (the cards' plan facts) and /api/search only; #404's one-shot plan on an overlay replays the overlay as captured.
|
|
619
|
+
const planned = path === "/api/graph" || path === "/api/search";
|
|
620
|
+
const q = LENS_PARAMS.filter((k) => params.has(k) && !(flat && (k === "detail" || k === "radial")) && !(k === "plan" && !planned))
|
|
509
621
|
.map((k) => `${k}=${params.get(k)}`)
|
|
510
622
|
.join("&");
|
|
511
623
|
return q ? `${path}?${q}` : path;
|
|
@@ -1044,7 +1156,7 @@ function renderBehaviourSection(section, b) {
|
|
|
1044
1156
|
if (typeof b.headroom.cpu === "number") axes.push(`cpu ${fmtHeadroom(b.headroom.cpu)}`);
|
|
1045
1157
|
if (typeof b.headroom.latency === "number") axes.push(`latency ${fmtHeadroom(b.headroom.latency)}`);
|
|
1046
1158
|
const worst = headroomOf(b);
|
|
1047
|
-
add("headroom", figureWithBadge(`${axes.join(" · ")} —
|
|
1159
|
+
add("headroom", figureWithBadge(`${axes.join(" · ")} — colors on ${fmtHeadroom(worst)}`, one, meta));
|
|
1048
1160
|
add("error rate", figureWithBadge(`${(b.errorRate * 100).toFixed(2)}% of requests at ${b.at.traffic}`, one, meta));
|
|
1049
1161
|
add("resilience", figureWithBadge(`${RESILIENCE_WORD[b.resilience.verdict] || b.resilience.verdict} — ${b.resilience.failure}`, one, meta));
|
|
1050
1162
|
if (b.resilience.note) add("resilience note", b.resilience.note);
|
|
@@ -1287,8 +1399,36 @@ function inspect(node) {
|
|
|
1287
1399
|
});
|
|
1288
1400
|
}
|
|
1289
1401
|
|
|
1290
|
-
// #
|
|
1291
|
-
|
|
1402
|
+
// #881: trace the way in to a network card, or a workload behind one.
|
|
1403
|
+
if (!view.components && /^(AWS::(ECS|EC2|ElasticLoadBalancingV2|Lambda|RDS)::|GCP::(Run|Compute)::|Microsoft\.App\/)/.test(node.kind || "")) {
|
|
1404
|
+
panel.appendChild(actButton("trace from outside to here", () => traceTo(node.id), "Follow traffic from the internet to this card, hop by hop"));
|
|
1405
|
+
}
|
|
1406
|
+
// #877: a stack opens here: the cards it holds, each with its state.
|
|
1407
|
+
if (Array.isArray(node.attrs && node.attrs._stackOf)) {
|
|
1408
|
+
const h = document.createElement("h3");
|
|
1409
|
+
h.textContent = `stacked · ${node.attrs._stackOf.length}`;
|
|
1410
|
+
panel.appendChild(h);
|
|
1411
|
+
const dl = document.createElement("dl");
|
|
1412
|
+
for (const m of node.attrs._stackOf) {
|
|
1413
|
+
const dt = document.createElement("dt");
|
|
1414
|
+
dt.textContent = m.status ? STATUS_LABEL[m.status] || m.status : "card";
|
|
1415
|
+
const dd = document.createElement("dd");
|
|
1416
|
+
dd.textContent = m.id;
|
|
1417
|
+
dl.append(dt, dd);
|
|
1418
|
+
}
|
|
1419
|
+
panel.appendChild(dl);
|
|
1420
|
+
panel.appendChild(actButton("draw them all", () => { view.alike = false; load(); }, "Turn stacking off and draw every card"));
|
|
1421
|
+
}
|
|
1422
|
+
if (typeof (node.attrs && node.attrs._usedBy) === "number") {
|
|
1423
|
+
const p = document.createElement("p");
|
|
1424
|
+
p.style.color = "var(--muted)";
|
|
1425
|
+
p.textContent = `${node.attrs._usedBy} cards refer to this one; their lines are left out while alike cards are stacked.`;
|
|
1426
|
+
panel.appendChild(p);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// #471: why this card is the way it is, read from chant when asked. A
|
|
1430
|
+
// stack (#877) is behold's, not chant's, so it has no why of its own.
|
|
1431
|
+
if (!Array.isArray(node.attrs && node.attrs._stackOf)) renderWhySection(panel, { node: node.id });
|
|
1292
1432
|
|
|
1293
1433
|
// #401: the behaviour block, field by field, with a badge on every figure.
|
|
1294
1434
|
// The colour on the card carries one number at a time (whichever mode is
|
|
@@ -1370,7 +1510,7 @@ function inspect(node) {
|
|
|
1370
1510
|
tick("at", tickStatus.at);
|
|
1371
1511
|
if (tickStatus.tickId) tick("tick", tickStatus.tickId);
|
|
1372
1512
|
if (tickStatus.stale) {
|
|
1373
|
-
tick("", "older than the operator's own cadence allows for — this verdict is history, so no
|
|
1513
|
+
tick("", "older than the operator's own cadence allows for — this verdict is history, so no color was taken from it");
|
|
1374
1514
|
}
|
|
1375
1515
|
}
|
|
1376
1516
|
|
|
@@ -1428,12 +1568,18 @@ function inspect(node) {
|
|
|
1428
1568
|
rel(k, v);
|
|
1429
1569
|
}
|
|
1430
1570
|
}
|
|
1571
|
+
// #899: a run that ended after this release and did not pass, from chant's run index.
|
|
1572
|
+
const since = node.attrs._runSince;
|
|
1573
|
+
if (since) {
|
|
1574
|
+
rel("since", `${since.job} ${since.status === "fail" ? "failed" : since.status} at ${since.commit.slice(0, 12)}`);
|
|
1575
|
+
rel("", `run ${since.runId}, ended ${since.ended}, ${since.member ? `for ${since.member}` : "for the whole workspace"}. A release records only a success, so this is what came after it.`);
|
|
1576
|
+
}
|
|
1431
1577
|
}
|
|
1432
1578
|
|
|
1433
1579
|
// Declared attributes — the source-of-truth values / cross-resource refs.
|
|
1434
1580
|
// The `release` chip is the card's abbreviation of the section above, not a
|
|
1435
1581
|
// declared value, so it stays out of this list when the section rendered.
|
|
1436
|
-
const attrKeys = Object.keys(node.attrs || {}).filter((k) => !k.startsWith("_") && !(k === "release" && release));
|
|
1582
|
+
const attrKeys = Object.keys(node.attrs || {}).filter((k) => !k.startsWith("_") && !((k === "release" || k === "since") && release));
|
|
1437
1583
|
if (attrKeys.length) {
|
|
1438
1584
|
const decl = section("declared");
|
|
1439
1585
|
// #393 item 10: a choudoufu card that can be adopted leads with the write
|
|
@@ -1580,6 +1726,9 @@ let bulkDiffCache = null; // { env, nodes: { <id>: { observed, diff, health } }
|
|
|
1580
1726
|
// from its own cache on the loads that follow, so the drift stays on screen
|
|
1581
1727
|
// without anyone paying for a second full pass over the account.
|
|
1582
1728
|
let planDriftOnce = false;
|
|
1729
|
+
// #910: ONE-SHOT, the same way: set by "Read the plan on the Terraform roots",
|
|
1730
|
+
// consumed by the source-graph load that carries `plan=1`.
|
|
1731
|
+
let terraformPlanOnce = false;
|
|
1583
1732
|
async function loadNodeDiff(id) {
|
|
1584
1733
|
if (publicMode) return null; // #569: /api/diff is refused in a public view
|
|
1585
1734
|
if (!bulkDiffCache || bulkDiffCache.env !== view.env) {
|
|
@@ -1814,12 +1963,23 @@ function wire(ir) {
|
|
|
1814
1963
|
host.querySelectorAll(".sel").forEach((n) => n.classList.remove("sel"));
|
|
1815
1964
|
g.classList.add("sel");
|
|
1816
1965
|
inspect(node);
|
|
1966
|
+
// On a phone the pane is folded under the graph; a tap on a card is asking for it.
|
|
1967
|
+
if (onPhone()) document.getElementById("app").classList.remove("inspect-collapsed");
|
|
1817
1968
|
noteSelection(node.id);
|
|
1818
1969
|
// #254: in carve mode a click is also the walkthrough's Pick step — the
|
|
1819
1970
|
// inspect pane already shows the score arithmetic the lens spelled out,
|
|
1820
1971
|
// and the stepper picks up the same node.
|
|
1821
1972
|
carvePick(node);
|
|
1822
1973
|
});
|
|
1974
|
+
// A double-click goes one zoom finer, at the fit.
|
|
1975
|
+
g.addEventListener("dblclick", (e) => {
|
|
1976
|
+
const next = DRILL[zoomValue()];
|
|
1977
|
+
if (panMoved || !next || !availableZooms().some(([, z]) => z === next)) return;
|
|
1978
|
+
e.preventDefault();
|
|
1979
|
+
applyZoom(next);
|
|
1980
|
+
renderStatusbar();
|
|
1981
|
+
load();
|
|
1982
|
+
});
|
|
1823
1983
|
}
|
|
1824
1984
|
// #475/#476: a member's box picks the member. Only boxes that are members
|
|
1825
1985
|
// (a wave or a VPC box is not one), and only a click on the box itself, not
|
|
@@ -1860,7 +2020,9 @@ function wire(ir) {
|
|
|
1860
2020
|
// member (#475) is the estate member the view is on: a host opens behold with
|
|
1861
2021
|
// ?member=, and picking a card or a member box moves it. It changes no fetch;
|
|
1862
2022
|
// the graph is the whole estate, framed on that member's box.
|
|
1863
|
-
|
|
2023
|
+
// q, snapshot (#913, #914): the question the view asks and the recorded snapshot it reads. Carried in the URL and
|
|
2024
|
+
// moved by an agent; nothing draws q until #913's search read lands.
|
|
2025
|
+
const view = { member: null, env: null, gates: null, focus: null, run: null, q: null, snapshot: null, plan: false, countBy: null, detail: 2, components: true, logical: false, runtime: false, ops: false, tier: null, target: null, stack: null, radial: false, collapse: false, alike: true, compareTo: null };
|
|
1864
2026
|
|
|
1865
2027
|
// #182: `components` is the boot default, but a project that declares no
|
|
1866
2028
|
// components renders it as ZERO nodes — the first screen was a blank graph
|
|
@@ -1884,8 +2046,10 @@ let autoZoomFallback = true;
|
|
|
1884
2046
|
// #571: a terragucci repo that declares its roots as components
|
|
1885
2047
|
// (`terragucci.components.json`, /api/project's `terragucciComponents`) does
|
|
1886
2048
|
// have a components picture, so it opens there whatever its member kind.
|
|
1887
|
-
function bootZoom(memberKinds, terragucciComponents) {
|
|
2049
|
+
function bootZoom(memberKinds, terragucciComponents, componentsDeclared) {
|
|
1888
2050
|
if (terragucciComponents) return "components";
|
|
2051
|
+
// #897: an estate whose members declare no component has no components picture.
|
|
2052
|
+
if (componentsDeclared === false) return "resources";
|
|
1889
2053
|
return memberKinds && memberKinds.length && !memberKinds.includes("chant") ? "resources" : "components";
|
|
1890
2054
|
}
|
|
1891
2055
|
|
|
@@ -1954,13 +2118,19 @@ let pendingTotal = 0;
|
|
|
1954
2118
|
* `stacksCapable`, which is false for an estate and for a single-lexicon
|
|
1955
2119
|
* project, where the answer could only ever be one box. */
|
|
1956
2120
|
let stacksCapable = false;
|
|
2121
|
+
/** #897: false when an estate's members declare no component (/api/project); undefined for a single project. */
|
|
2122
|
+
let componentsDeclared;
|
|
1957
2123
|
/** The zoom stops this project can actually offer — `runtime` needs an env AND
|
|
1958
2124
|
* a member whose substrate has an owner chain, `ops` needs emitted op.json
|
|
1959
2125
|
* files. Both the panel and ⌘K read this, so a stop never appears in one
|
|
1960
2126
|
* surface and not the other. */
|
|
1961
2127
|
function availableZooms() {
|
|
1962
|
-
return ZOOM_OPTS.filter(([, z]) =>
|
|
2128
|
+
return ZOOM_OPTS.filter(([, z]) =>
|
|
2129
|
+
z === "runtime" ? Boolean(view.env) && runtimeCapable : z === "ops" ? opsAvailable > 0 : z === "stacks" ? stacksCapable : z === "components" ? componentsDeclared !== false : true,
|
|
2130
|
+
);
|
|
1963
2131
|
}
|
|
2132
|
+
/** The zoom a double-clicked card goes to: the next finer one. */
|
|
2133
|
+
const DRILL = { components: "logical", logical: "composites", composites: "resources", resources: "attributes" };
|
|
1964
2134
|
/** Current zoom value from (components, logical, ops, detail). */
|
|
1965
2135
|
function zoomValue() {
|
|
1966
2136
|
if (view.components) return "components";
|
|
@@ -1980,6 +2150,55 @@ function applyZoom(z) {
|
|
|
1980
2150
|
if (z !== "components" && z !== "logical" && z !== "ops" && z !== "stacks") view.detail = ZOOM_DETAIL[z] ?? 2;
|
|
1981
2151
|
}
|
|
1982
2152
|
|
|
2153
|
+
/** An estate of several projects: the stacked view and its toggle apply. */
|
|
2154
|
+
function isEstate() {
|
|
2155
|
+
return !!(lastMeta && lastMeta.estate > 1);
|
|
2156
|
+
}
|
|
2157
|
+
/** The zooms the server stacks alike cards on: the ones that draw every card. */
|
|
2158
|
+
function alikeZoom() {
|
|
2159
|
+
return ["composites", "resources", "attributes"].includes(zoomValue());
|
|
2160
|
+
}
|
|
2161
|
+
const ALIKE_TITLE =
|
|
2162
|
+
"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";
|
|
2163
|
+
/** Stack or unstack alike cards. From a zoom that doesn't stack, go to resources stacked. */
|
|
2164
|
+
function toggleAlike() {
|
|
2165
|
+
if (!alikeZoom()) {
|
|
2166
|
+
applyZoom("resources");
|
|
2167
|
+
view.alike = true;
|
|
2168
|
+
nowline("stack alike draws on the resources zoom, so the view moved there");
|
|
2169
|
+
} else view.alike = !view.alike;
|
|
2170
|
+
renderStatusbar();
|
|
2171
|
+
load();
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
/** Toggles over the canvas's top edge: the view features one click away. */
|
|
2175
|
+
function ensureViewToggles(host) {
|
|
2176
|
+
if (!host) return;
|
|
2177
|
+
let bar = document.getElementById("view-toggles");
|
|
2178
|
+
if (!bar || bar.parentElement !== host) {
|
|
2179
|
+
bar = document.createElement("div");
|
|
2180
|
+
bar.id = "view-toggles";
|
|
2181
|
+
host.appendChild(bar);
|
|
2182
|
+
}
|
|
2183
|
+
bar.innerHTML = "";
|
|
2184
|
+
if (isEstate()) {
|
|
2185
|
+
const b = button("▦ stack alike", "vt" + (view.alike && alikeZoom() ? " active" : ""), toggleAlike);
|
|
2186
|
+
b.title = ALIKE_TITLE;
|
|
2187
|
+
bar.appendChild(b);
|
|
2188
|
+
}
|
|
2189
|
+
if (!view.components && !view.ops) {
|
|
2190
|
+
const b = button("⇢ trace", "vt", () => {
|
|
2191
|
+
setPanelTab("model");
|
|
2192
|
+
renderPanelModel();
|
|
2193
|
+
const sec = document.querySelector(".net-trace");
|
|
2194
|
+
if (sec) sec.scrollIntoView({ block: "nearest" });
|
|
2195
|
+
});
|
|
2196
|
+
b.title = "Trace traffic hop by hop to a card, and see the network findings (Model tab)";
|
|
2197
|
+
bar.appendChild(b);
|
|
2198
|
+
}
|
|
2199
|
+
bar.style.display = bar.children.length ? "" : "none";
|
|
2200
|
+
}
|
|
2201
|
+
|
|
1983
2202
|
// --- Floating control panel content ---------------------------------------
|
|
1984
2203
|
// panel.js owns the chrome (drag, snap to edges/corners, collapse, tabs);
|
|
1985
2204
|
// these functions own what's IN the tabs, re-rendered from renderStatusbar()
|
|
@@ -2028,6 +2247,7 @@ function renderPanelView() {
|
|
|
2028
2247
|
panelOpt(label.replace(/^zoom: /, ""), v === current, () => {
|
|
2029
2248
|
applyZoom(v);
|
|
2030
2249
|
renderStatusbar();
|
|
2250
|
+
foldPanelOnPhone();
|
|
2031
2251
|
load();
|
|
2032
2252
|
}),
|
|
2033
2253
|
);
|
|
@@ -2036,7 +2256,7 @@ function renderPanelView() {
|
|
|
2036
2256
|
// this tab is for is "what am I looking at", and colour is half that answer.
|
|
2037
2257
|
// Sits below the stops because it is not a granularity: every zoom paints in
|
|
2038
2258
|
// whichever of the three you picked.
|
|
2039
|
-
zoom.appendChild(panelHeading("
|
|
2259
|
+
zoom.appendChild(panelHeading("color by"));
|
|
2040
2260
|
for (const mode of COLOUR_MODES) {
|
|
2041
2261
|
const gate = mode === "drift" ? { available: true, reason: "" } : modeAvailability(lastMeta, mode);
|
|
2042
2262
|
const b = panelOpt(
|
|
@@ -2076,6 +2296,13 @@ function renderPanelView() {
|
|
|
2076
2296
|
if (estate) radial.disabled = true;
|
|
2077
2297
|
zoom.appendChild(radial);
|
|
2078
2298
|
}
|
|
2299
|
+
// #877: cards of one kind in a box stack into one with a count. An estate
|
|
2300
|
+
// lens, like collapse: the server stacks within each project's box. Offered
|
|
2301
|
+
// on every zoom: from one that doesn't stack, it moves to resources.
|
|
2302
|
+
if (isEstate()) {
|
|
2303
|
+
if (view.components || view.logical || view.ops) zoom.appendChild(panelHeading("layout"));
|
|
2304
|
+
zoom.appendChild(panelOpt("stack alike", view.alike && alikeZoom(), toggleAlike, ALIKE_TITLE));
|
|
2305
|
+
}
|
|
2079
2306
|
const tools = document.getElementById("panel-viewtools");
|
|
2080
2307
|
tools.innerHTML = "";
|
|
2081
2308
|
tools.appendChild(panelHeading("graph"));
|
|
@@ -2083,6 +2310,7 @@ function renderPanelView() {
|
|
|
2083
2310
|
row.className = "prow";
|
|
2084
2311
|
row.appendChild(actButton("⤢ fit", () => fitGraph(), "Reset zoom/pan to fit. Pinch or ⌘/Ctrl+scroll zooms at the cursor; drag pans."));
|
|
2085
2312
|
row.appendChild(actButton("↓ SVG", () => exportSvg(), "Export the current graph as a standalone SVG file"));
|
|
2313
|
+
row.appendChild(actButton("↓ PNG", () => exportPng(), "Save the view as a picture, with the options below"));
|
|
2086
2314
|
const collapsed = document.getElementById("app").classList.contains("inspect-collapsed");
|
|
2087
2315
|
row.appendChild(
|
|
2088
2316
|
actButton(collapsed ? "show inspect" : "hide inspect", () => {
|
|
@@ -2098,6 +2326,24 @@ function renderPanelView() {
|
|
|
2098
2326
|
lanes.style.cssText = "color:var(--pending);text-decoration:none;font-size:var(--t-body)";
|
|
2099
2327
|
row.appendChild(lanes);
|
|
2100
2328
|
tools.appendChild(row);
|
|
2329
|
+
// #882: the picture's options: its scale, and whether a heading and the key go in.
|
|
2330
|
+
const png = document.createElement("div");
|
|
2331
|
+
png.className = "prow png-opts";
|
|
2332
|
+
const scaleSel = document.createElement("select");
|
|
2333
|
+
for (const k of [1, 2, 3, 4]) scaleSel.add(new Option(`${k}×`, String(k), false, pngOpts.scale === k));
|
|
2334
|
+
scaleSel.title = "Pixels per point of the picture";
|
|
2335
|
+
scaleSel.addEventListener("change", () => (pngOpts.scale = Number(scaleSel.value)));
|
|
2336
|
+
const check = (label, prop) => {
|
|
2337
|
+
const l = document.createElement("label");
|
|
2338
|
+
const c = document.createElement("input");
|
|
2339
|
+
c.type = "checkbox";
|
|
2340
|
+
c.checked = pngOpts[prop];
|
|
2341
|
+
c.addEventListener("change", () => (pngOpts[prop] = c.checked));
|
|
2342
|
+
l.append(c, ` ${label}`);
|
|
2343
|
+
return l;
|
|
2344
|
+
};
|
|
2345
|
+
png.append("PNG ", scaleSel, check("heading", "heading"), check("key", "key"));
|
|
2346
|
+
tools.appendChild(png);
|
|
2101
2347
|
}
|
|
2102
2348
|
|
|
2103
2349
|
// Scope tab: which world the graph reads — env (source vs live overlay),
|
|
@@ -2764,6 +3010,7 @@ function applyWantedView(want) {
|
|
|
2764
3010
|
zooms: availableZooms().map(([, z]) => z),
|
|
2765
3011
|
tiers,
|
|
2766
3012
|
lenses: COLOUR_MODES,
|
|
3013
|
+
env: view.env, // a snapshot is of the env the view is on
|
|
2767
3014
|
});
|
|
2768
3015
|
urlRefusals.push(...first.refused, ...refused);
|
|
2769
3016
|
if (apply.tier) view.tier = apply.tier;
|
|
@@ -2773,10 +3020,18 @@ function applyWantedView(want) {
|
|
|
2773
3020
|
}
|
|
2774
3021
|
if (apply.lens) colourMode = apply.lens; // not written to localStorage: the link's pick, not yours
|
|
2775
3022
|
if ("radial" in apply) view.radial = apply.radial;
|
|
3023
|
+
if ("alike" in apply) view.alike = apply.alike;
|
|
2776
3024
|
if ("gates" in apply) view.gates = apply.gates;
|
|
2777
3025
|
if ("focus" in apply) view.focus = apply.focus; // #569: drawn by drawTgReads, no new read
|
|
2778
3026
|
if ("run" in apply) view.run = apply.run; // #569: which run the view draws; read in the message handler
|
|
2779
3027
|
if ("pull" in apply) view.pull = apply.pull; // the cycle's pull request: a commit's run never draws another's plan
|
|
3028
|
+
if ("q" in apply) view.q = apply.q; // #914 carries it; #913 draws it (drawQuery)
|
|
3029
|
+
if ("snapshot" in apply) view.snapshot = apply.snapshot;
|
|
3030
|
+
if (!view.env) view.snapshot = null; // a snapshot is of an env: the source graph has none
|
|
3031
|
+
// behold#922: the plan read (the cards' plan facts, q at the plan depth) and q's grouping.
|
|
3032
|
+
if ("plan" in apply) view.plan = apply.plan;
|
|
3033
|
+
if (view.plan) view.snapshot = null; // settleView refuses the two together; a plan is now
|
|
3034
|
+
if ("countBy" in apply) view.countBy = apply.countBy;
|
|
2780
3035
|
if (want.member === null) {
|
|
2781
3036
|
view.member = null;
|
|
2782
3037
|
selectedNodeId = null;
|
|
@@ -2790,7 +3045,7 @@ function applyWantedView(want) {
|
|
|
2790
3045
|
return fetchKey() !== before;
|
|
2791
3046
|
}
|
|
2792
3047
|
function fetchKey() {
|
|
2793
|
-
return [view.env, zoomValue(), view.tier, view.radial].join("|");
|
|
3048
|
+
return [view.env, zoomValue(), view.tier, view.radial, view.alike, view.plan].join("|"); // plan: behold#922's plan facts on the cards
|
|
2794
3049
|
}
|
|
2795
3050
|
|
|
2796
3051
|
// #476: the host moves the view with a `behold:view` message carrying the same
|
|
@@ -2798,11 +3053,19 @@ function fetchKey() {
|
|
|
2798
3053
|
window.addEventListener("message", (e) => {
|
|
2799
3054
|
const want = viewFromMessage(e, embedOpts.host);
|
|
2800
3055
|
if (!want) return;
|
|
3056
|
+
moveViewTo(want);
|
|
3057
|
+
});
|
|
3058
|
+
|
|
3059
|
+
/** Move the view the way a host's `behold:view` does: settle it, re-read what
|
|
3060
|
+
* it changed, and say what couldn't be opened. An agent's move (#914) and Back
|
|
3061
|
+
* from one come through here too. */
|
|
3062
|
+
function moveViewTo(want) {
|
|
2801
3063
|
const lensBefore = colourMode;
|
|
2802
3064
|
const gatesBefore = view.gates;
|
|
2803
3065
|
const focusBefore = view.focus;
|
|
2804
3066
|
const runBefore = view.run;
|
|
2805
3067
|
const pullBefore = view.pull;
|
|
3068
|
+
const queryBefore = searchKey(view);
|
|
2806
3069
|
const moved = applyWantedView(want);
|
|
2807
3070
|
if (view.run !== runBefore || view.pull !== pullBefore) {
|
|
2808
3071
|
if (tgServed) void loadTgProgress({ fresh: true }); // #569: the run the narration is about
|
|
@@ -2822,14 +3085,90 @@ window.addEventListener("message", (e) => {
|
|
|
2822
3085
|
return;
|
|
2823
3086
|
}
|
|
2824
3087
|
if (colourMode !== lensBefore) recolorNodesByCategory();
|
|
3088
|
+
if (searchKey(view) !== queryBefore) void drawQuery(); // #913: a new question over the same graph
|
|
2825
3089
|
if (pendingPlace && lastGraphIr) afterPaint(lastGraphIr);
|
|
2826
3090
|
else if (want.member === null) fitGraph();
|
|
2827
3091
|
const line = refusalLine(urlRefusals);
|
|
2828
3092
|
urlRefusals = [];
|
|
2829
3093
|
if (line) nowline(line);
|
|
2830
3094
|
renderStatusbar();
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
// --- #914: an agent moved the tab --------------------------------------------
|
|
3098
|
+
// POST /api/view sends a `view` event on /api/events. The tab moves the way a
|
|
3099
|
+
// host's message moves it, says who asked and when, and pushes a history entry
|
|
3100
|
+
// so the banner's Back and the browser's Back both return to the view it left.
|
|
3101
|
+
// The person's own changes keep replacing the entry they are on (syncViewUrl).
|
|
3102
|
+
// An embedded frame with a host ignores the event: its view is the host's (#476).
|
|
3103
|
+
function agentMove(data) {
|
|
3104
|
+
if (embedOpts.embed && embedOpts.host) return;
|
|
3105
|
+
let ev;
|
|
3106
|
+
try {
|
|
3107
|
+
ev = JSON.parse(data);
|
|
3108
|
+
} catch {
|
|
3109
|
+
return;
|
|
3110
|
+
}
|
|
3111
|
+
if (!ev || typeof ev !== "object") return;
|
|
3112
|
+
const want = wholeQuestion(viewFromObject(ev.view).want, view);
|
|
3113
|
+
if (!Object.keys(want).length) return;
|
|
3114
|
+
const move = { id: String(ev.id || ""), by: String(ev.by || "an agent"), movedAt: String(ev.movedAt || ""), q: typeof want.q === "string" ? want.q : "" };
|
|
3115
|
+
syncViewUrl(); // the entry being left holds the view as it is now
|
|
3116
|
+
const entry = agentEntry(history.state, move);
|
|
3117
|
+
try {
|
|
3118
|
+
// The new entry starts as a copy of the one being left; moveViewTo's syncViewUrl writes the new view into it.
|
|
3119
|
+
if (entry.push) history.pushState(entry.state, "", location.href);
|
|
3120
|
+
else history.replaceState(entry.state, "", location.href);
|
|
3121
|
+
} catch {
|
|
3122
|
+
/* a sandboxed frame may refuse; the move still happens */
|
|
3123
|
+
}
|
|
3124
|
+
moveViewTo(want);
|
|
3125
|
+
showAgentBanner(move);
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
// Back, from the banner or the browser: the URL is the view to go back to.
|
|
3129
|
+
window.addEventListener("popstate", (e) => {
|
|
3130
|
+
if (!viewUrlReady) return;
|
|
3131
|
+
const defaults = { env: defaultEnv(manifest && manifest.opening, projectInfo && projectInfo.currentEnv), lens: savedColourMode };
|
|
3132
|
+
moveViewTo(restoreViewQuery(location.search, defaults));
|
|
3133
|
+
const move = e.state && e.state.beholdMove;
|
|
3134
|
+
if (move) showAgentBanner(move);
|
|
3135
|
+
else hideAgentBanner();
|
|
2831
3136
|
});
|
|
2832
3137
|
|
|
3138
|
+
function showAgentBanner(move) {
|
|
3139
|
+
let el = document.getElementById("agent-banner");
|
|
3140
|
+
if (!el) {
|
|
3141
|
+
el = document.createElement("div");
|
|
3142
|
+
el.id = "agent-banner";
|
|
3143
|
+
el.setAttribute("role", "status");
|
|
3144
|
+
document.body.appendChild(el);
|
|
3145
|
+
}
|
|
3146
|
+
const b = agentBanner(move, new Date(move.movedAt));
|
|
3147
|
+
el.innerHTML = "";
|
|
3148
|
+
const text = document.createElement("span");
|
|
3149
|
+
text.className = "agent-banner-text";
|
|
3150
|
+
text.textContent = b.text;
|
|
3151
|
+
el.appendChild(text);
|
|
3152
|
+
const back = document.createElement("button");
|
|
3153
|
+
back.className = "agent-banner-back";
|
|
3154
|
+
back.textContent = "Back";
|
|
3155
|
+
back.title = "Return to the view before this move";
|
|
3156
|
+
back.addEventListener("click", () => history.back());
|
|
3157
|
+
el.appendChild(back);
|
|
3158
|
+
const close = document.createElement("button");
|
|
3159
|
+
close.className = "agent-banner-close";
|
|
3160
|
+
close.textContent = "×";
|
|
3161
|
+
close.title = "Dismiss; Back in the browser still returns";
|
|
3162
|
+
close.addEventListener("click", hideAgentBanner);
|
|
3163
|
+
el.appendChild(close);
|
|
3164
|
+
el.hidden = false;
|
|
3165
|
+
el.dataset.request = move.id;
|
|
3166
|
+
}
|
|
3167
|
+
function hideAgentBanner() {
|
|
3168
|
+
const el = document.getElementById("agent-banner");
|
|
3169
|
+
if (el) el.hidden = true;
|
|
3170
|
+
}
|
|
3171
|
+
|
|
2833
3172
|
/** Tell the host what was picked: a card (member + node) or a member's box. */
|
|
2834
3173
|
function embedSelected(member, node) {
|
|
2835
3174
|
if (embedOpts.embed && member) setInspectCollapsed(!node);
|
|
@@ -3009,17 +3348,168 @@ function afterPaint(ir) {
|
|
|
3009
3348
|
if (place.apply.node) {
|
|
3010
3349
|
selectNode(place.apply.node, { quiet: true });
|
|
3011
3350
|
revealNode(place.apply.node);
|
|
3012
|
-
}
|
|
3351
|
+
} else if (view.member) revealMember(view.member);
|
|
3013
3352
|
renderStatusbar();
|
|
3014
3353
|
} else if (selectedNodeId && !ids.has(selectedNodeId)) {
|
|
3015
|
-
// The pick isn't on this view any more; the URL stops naming it.
|
|
3354
|
+
// The pick isn't on this view any more; the URL stops naming it. The view
|
|
3355
|
+
// stays at the fit: a member a pick implied is no reason to zoom in on it.
|
|
3016
3356
|
selectedNodeId = null;
|
|
3017
3357
|
syncViewUrl();
|
|
3358
|
+
const panel = document.getElementById("inspect-body");
|
|
3359
|
+
if (panel) panel.innerHTML = '<h2>Inspect</h2><p style="color:var(--ink2)">Click a node</p>';
|
|
3018
3360
|
}
|
|
3019
|
-
if (view.member && !selectedNodeId) revealMember(view.member);
|
|
3020
3361
|
const line = refusalLine(urlRefusals);
|
|
3021
3362
|
urlRefusals = [];
|
|
3022
3363
|
if (line) nowline(line);
|
|
3364
|
+
void drawQuery(); // #913: every paint draws the view's question over the new svg
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
// --- behold#913: `q` drawn ----------------------------------------------------
|
|
3368
|
+
// The view's query is read through GET /api/search (chant answers, behold
|
|
3369
|
+
// draws: src/search.ts), once per query, env and snapshot, and again after a
|
|
3370
|
+
// `changed` event. Each paint lights the matches, draws the edges on their
|
|
3371
|
+
// paths, dims the rest, and says the query and chant's provenance in one line
|
|
3372
|
+
// (web/search-view.js decides; this applies). A refused query lights and dims
|
|
3373
|
+
// nothing; no matches dims everything and outlines the near-misses.
|
|
3374
|
+
let queryAnswer = null; // {key, answer} once read
|
|
3375
|
+
let queryReading = null; // {key, promise} while a read is in flight
|
|
3376
|
+
async function readQuery(key) {
|
|
3377
|
+
if (queryAnswer && queryAnswer.key === key) return queryAnswer.answer;
|
|
3378
|
+
if (queryReading && queryReading.key === key) return queryReading.promise;
|
|
3379
|
+
const promise = (async () => {
|
|
3380
|
+
let answer;
|
|
3381
|
+
try {
|
|
3382
|
+
const res = await apiFetch(searchUrl(view));
|
|
3383
|
+
answer = await res.json().catch(() => ({ error: `the search answered ${res.status}` }));
|
|
3384
|
+
if (staticMode && res.status === 404) answer = { error: uncapturedLine(view.q, manifest && manifest.queries), uncaptured: true };
|
|
3385
|
+
} catch (err) {
|
|
3386
|
+
answer = { error: `the search failed: ${err.message}` };
|
|
3387
|
+
}
|
|
3388
|
+
if (searchKey(view) === key) queryAnswer = { key, answer };
|
|
3389
|
+
return answer;
|
|
3390
|
+
})();
|
|
3391
|
+
queryReading = { key, promise };
|
|
3392
|
+
try {
|
|
3393
|
+
return await promise;
|
|
3394
|
+
} finally {
|
|
3395
|
+
if (queryReading && queryReading.key === key) queryReading = null;
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
/** The answer the shot frame draws: null while none is wanted, undefined while it is read. */
|
|
3399
|
+
function queryAnswerNow() {
|
|
3400
|
+
const key = searchKey(view);
|
|
3401
|
+
if (!key) return null;
|
|
3402
|
+
return queryAnswer && queryAnswer.key === key ? queryAnswer.answer : undefined;
|
|
3403
|
+
}
|
|
3404
|
+
function clearQueryMarks(svg) {
|
|
3405
|
+
if (!svg) return;
|
|
3406
|
+
for (const el of svg.querySelectorAll("[data-q]")) el.removeAttribute("data-q");
|
|
3407
|
+
for (const el of svg.querySelectorAll("[data-q-near]")) {
|
|
3408
|
+
el.removeAttribute("data-q-near");
|
|
3409
|
+
const t = el.querySelector(":scope > title.q-near-title");
|
|
3410
|
+
if (t) t.remove();
|
|
3411
|
+
}
|
|
3412
|
+
for (const el of svg.querySelectorAll("[data-q-unobserved]")) el.removeAttribute("data-q-unobserved");
|
|
3413
|
+
// behold#922: a counts answer's group colours and labels.
|
|
3414
|
+
for (const el of svg.querySelectorAll("[data-q-group]")) {
|
|
3415
|
+
el.removeAttribute("data-q-group");
|
|
3416
|
+
el.style.removeProperty("--q-group");
|
|
3417
|
+
}
|
|
3418
|
+
for (const el of svg.querySelectorAll(".q-group-label")) el.remove();
|
|
3419
|
+
}
|
|
3420
|
+
async function drawQuery() {
|
|
3421
|
+
const key = searchKey(view);
|
|
3422
|
+
const lineEl = document.getElementById("q-line");
|
|
3423
|
+
if (!key) {
|
|
3424
|
+
clearQueryMarks(currentSvg());
|
|
3425
|
+
if (lineEl) lineEl.hidden = true;
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
const answer = await readQuery(key);
|
|
3429
|
+
if (searchKey(view) !== key) return; // the view moved on while it was read
|
|
3430
|
+
const svg = currentSvg();
|
|
3431
|
+
clearQueryMarks(svg);
|
|
3432
|
+
const cardEls = svg ? [...svg.querySelectorAll("[data-node-id]")] : [];
|
|
3433
|
+
const edgeEls = svg ? [...svg.querySelectorAll("g[data-edge-from]")] : [];
|
|
3434
|
+
const cardIds = new Set(cardEls.map((g) => g.getAttribute("data-node-id")));
|
|
3435
|
+
const stackOf = stackIndex(lastGraphIr && lastGraphIr.nodes, cardIds);
|
|
3436
|
+
const marks = queryMarks(
|
|
3437
|
+
answer,
|
|
3438
|
+
cardIds,
|
|
3439
|
+
edgeEls.map((g) => ({ from: g.getAttribute("data-edge-from"), to: g.getAttribute("data-edge-to") })),
|
|
3440
|
+
stackOf,
|
|
3441
|
+
);
|
|
3442
|
+
for (const g of cardEls) {
|
|
3443
|
+
const id = g.getAttribute("data-node-id");
|
|
3444
|
+
const m = marks.cardMarks.get(id);
|
|
3445
|
+
if (m) g.setAttribute("data-q", m);
|
|
3446
|
+
if (marks.unobserved.has(id)) g.setAttribute("data-q-unobserved", "1");
|
|
3447
|
+
if (marks.near.has(id)) {
|
|
3448
|
+
g.setAttribute("data-q-near", "1");
|
|
3449
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
3450
|
+
t.setAttribute("class", "q-near-title");
|
|
3451
|
+
t.textContent = `near miss: fails ${marks.near.get(id)}`;
|
|
3452
|
+
g.prepend(t);
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
edgeEls.forEach((g, i) => {
|
|
3456
|
+
if (marks.edgeMarks[i]) g.setAttribute("data-q", marks.edgeMarks[i]);
|
|
3457
|
+
});
|
|
3458
|
+
drawGroups(svg, answer, cardEls, stackOf);
|
|
3459
|
+
if (embedOpts.bare) return; // a bare frame has no chrome: the shot frame draws its own caption
|
|
3460
|
+
const line = queryLine(view, answer, marks);
|
|
3461
|
+
let el = lineEl;
|
|
3462
|
+
if (!el) {
|
|
3463
|
+
el = document.createElement("div");
|
|
3464
|
+
el.id = "q-line";
|
|
3465
|
+
el.setAttribute("role", "status");
|
|
3466
|
+
document.body.appendChild(el);
|
|
3467
|
+
}
|
|
3468
|
+
el.hidden = false;
|
|
3469
|
+
el.dataset.tone = line.tone;
|
|
3470
|
+
el.innerHTML = "";
|
|
3471
|
+
const main = document.createElement("div");
|
|
3472
|
+
main.className = "q-line-main";
|
|
3473
|
+
main.textContent = line.text;
|
|
3474
|
+
el.appendChild(main);
|
|
3475
|
+
if (line.notSearched) {
|
|
3476
|
+
const ns = document.createElement("div");
|
|
3477
|
+
ns.className = "q-line-not-searched";
|
|
3478
|
+
ns.textContent = line.notSearched;
|
|
3479
|
+
el.appendChild(ns);
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
/**
|
|
3484
|
+
* behold#922: a counts answer drawn: each group's cards outlined in the
|
|
3485
|
+
* group's colour, and the group's first drawn card labelled with the group
|
|
3486
|
+
* and chant's count (web/search-view.js groupMarks). The cards are already
|
|
3487
|
+
* lit by drawQuery; this says which group each is in.
|
|
3488
|
+
*/
|
|
3489
|
+
function drawGroups(svg, answer, cardEls, stackOf) {
|
|
3490
|
+
if (!svg) return;
|
|
3491
|
+
const gm = groupMarks(answer, new Set(cardEls.map((g) => g.getAttribute("data-node-id"))), stackOf);
|
|
3492
|
+
if (!gm.groups.length) return;
|
|
3493
|
+
const byId = new Map(cardEls.map((g) => [g.getAttribute("data-node-id"), g]));
|
|
3494
|
+
for (const [id, i] of gm.cardGroup) {
|
|
3495
|
+
const g = byId.get(id);
|
|
3496
|
+
g.setAttribute("data-q-group", gm.groups[i].group);
|
|
3497
|
+
g.style.setProperty("--q-group", gm.groups[i].colour);
|
|
3498
|
+
}
|
|
3499
|
+
for (const grp of gm.groups) {
|
|
3500
|
+
const g = grp.label && byId.get(grp.label);
|
|
3501
|
+
const rect = g && g.querySelector(":scope > rect");
|
|
3502
|
+
if (!rect) continue;
|
|
3503
|
+
const x = Number(rect.getAttribute("x") || 0);
|
|
3504
|
+
const y = Number(rect.getAttribute("y") || 0);
|
|
3505
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
3506
|
+
t.setAttribute("class", "q-group-label");
|
|
3507
|
+
t.setAttribute("x", String(x));
|
|
3508
|
+
t.setAttribute("y", String(y - 4));
|
|
3509
|
+
t.setAttribute("fill", grp.colour);
|
|
3510
|
+
t.textContent = groupLabel(grp);
|
|
3511
|
+
g.appendChild(t);
|
|
3512
|
+
}
|
|
3023
3513
|
}
|
|
3024
3514
|
|
|
3025
3515
|
/** A card was picked (graph click, panel row, palette, the link). */
|
|
@@ -3092,9 +3582,15 @@ function syncViewUrl() {
|
|
|
3092
3582
|
lens: colourMode,
|
|
3093
3583
|
node: place.node || selectedNodeId,
|
|
3094
3584
|
radial: view.radial && !view.components && !view.logical && !view.ops,
|
|
3585
|
+
// Stacked is the default, so only an estate's every-card view is written.
|
|
3586
|
+
alike: isEstate() && alikeZoom() ? view.alike : undefined,
|
|
3095
3587
|
gates: view.gates,
|
|
3096
3588
|
focus: view.focus,
|
|
3097
3589
|
run: view.run,
|
|
3590
|
+
q: view.q,
|
|
3591
|
+
snapshot: view.snapshot,
|
|
3592
|
+
plan: view.plan,
|
|
3593
|
+
countBy: view.countBy,
|
|
3098
3594
|
};
|
|
3099
3595
|
const defaults = { env: defaultEnv(manifest && manifest.opening, projectInfo && projectInfo.currentEnv), lens: savedColourMode };
|
|
3100
3596
|
const next = location.pathname + writeViewQuery(location.search, state, defaults) + location.hash;
|
|
@@ -3232,16 +3728,188 @@ function renderPanelModel() {
|
|
|
3232
3728
|
}
|
|
3233
3729
|
}
|
|
3234
3730
|
renderEdgeLegend(host, ir);
|
|
3731
|
+
renderNetworkSection(host);
|
|
3235
3732
|
renderBehaviourRefusal(host);
|
|
3236
3733
|
renderBehaviourDiagnostics(host);
|
|
3237
3734
|
}
|
|
3238
3735
|
|
|
3736
|
+
// #881: the network section. The trace reads the rules on each card, which
|
|
3737
|
+
// only the attributes zoom (detail 3) carries, so the section reads that graph
|
|
3738
|
+
// once per env and tier, through apiFetch (a static export captures it). The
|
|
3739
|
+
// trace and the findings are computed here, from that graph (web/net-trace.js).
|
|
3740
|
+
const NETWORK_KIND = /^(AWS::(EC2|ElasticLoadBalancingV2)::|GCP::(Compute|Run)::|Microsoft\.(Network|App)\/)/;
|
|
3741
|
+
const net = { key: null, ir: null, error: null, from: OUTSIDE, to: null, port: 80, result: null };
|
|
3742
|
+
|
|
3743
|
+
function netKey() {
|
|
3744
|
+
return `${view.env || ""}|${view.tier || ""}`;
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
function loadNetworkGraph() {
|
|
3748
|
+
const key = netKey();
|
|
3749
|
+
if (net.key === key) return;
|
|
3750
|
+
Object.assign(net, { key, ir: null, error: null, result: null });
|
|
3751
|
+
const q = new URLSearchParams({ detail: "3" });
|
|
3752
|
+
if (view.env) q.set("env", view.env);
|
|
3753
|
+
if (view.tier) q.set("tier", view.tier);
|
|
3754
|
+
apiFetch(`${view.env ? "/api/overlay" : "/api/graph"}?${q}`)
|
|
3755
|
+
.then((r) => r.json())
|
|
3756
|
+
.then((d) => {
|
|
3757
|
+
if (net.key !== key) return;
|
|
3758
|
+
if (!d.ir) throw new Error(d.error || "no graph");
|
|
3759
|
+
net.ir = d.ir;
|
|
3760
|
+
if (net.to) runTrace();
|
|
3761
|
+
renderPanelModel();
|
|
3762
|
+
})
|
|
3763
|
+
.catch((err) => {
|
|
3764
|
+
if (net.key !== key) return;
|
|
3765
|
+
net.error = String(err.message || err);
|
|
3766
|
+
renderPanelModel();
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
function runTrace() {
|
|
3771
|
+
if (!net.ir || !net.to) return;
|
|
3772
|
+
net.result = traceRoute(net.ir, { from: net.from, to: net.to, port: net.port });
|
|
3773
|
+
markTrace();
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
/** Trace from outside to a card, from the inspect pane. */
|
|
3777
|
+
function traceTo(id) {
|
|
3778
|
+
Object.assign(net, { from: OUTSIDE, to: id });
|
|
3779
|
+
loadNetworkGraph();
|
|
3780
|
+
runTrace();
|
|
3781
|
+
setPanelTab("model");
|
|
3782
|
+
renderPanelModel();
|
|
3783
|
+
}
|
|
3784
|
+
|
|
3785
|
+
/** Each hop's card marked open or closed on the canvas; the rest fade. */
|
|
3786
|
+
function markTrace() {
|
|
3787
|
+
const svg = document.querySelector("#graph svg");
|
|
3788
|
+
if (!svg) return;
|
|
3789
|
+
svg.querySelectorAll(".trace-open, .trace-closed").forEach((n) => n.classList.remove("trace-open", "trace-closed"));
|
|
3790
|
+
const hops = (net.result && net.result.hops) || [];
|
|
3791
|
+
svg.classList.toggle("tracing", hops.length > 0);
|
|
3792
|
+
for (const h of hops) {
|
|
3793
|
+
const g = h.id && svg.querySelector(`g[data-node-id="${CSS.escape(h.id)}"]`);
|
|
3794
|
+
// A card two hops share stays closed if either is.
|
|
3795
|
+
if (g && !g.classList.contains("trace-closed")) g.classList.add(h.open ? "trace-open" : "trace-closed");
|
|
3796
|
+
if (g && !h.open) g.classList.replace("trace-open", "trace-closed");
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
|
|
3800
|
+
/** A stack-qualified id (`aws/<stack>::alb`) reads as its member and name. */
|
|
3801
|
+
function shortIds(text) {
|
|
3802
|
+
return text.replace(/([^\s/]+\/)[^\s/:]*::/g, "$1");
|
|
3803
|
+
}
|
|
3804
|
+
|
|
3805
|
+
/** A row whose text wraps: a dot, what it is, the sentence, and a tag. */
|
|
3806
|
+
function netRow(color, what, text, tag, onClick) {
|
|
3807
|
+
const row = document.createElement("div");
|
|
3808
|
+
row.className = "net-row" + (onClick ? " clickable" : "");
|
|
3809
|
+
const dot = document.createElement("span");
|
|
3810
|
+
dot.className = "dot";
|
|
3811
|
+
dot.style.background = color;
|
|
3812
|
+
const body = document.createElement("span");
|
|
3813
|
+
const w = document.createElement("b");
|
|
3814
|
+
w.textContent = what;
|
|
3815
|
+
// A stack-qualified id (`aws/<stack>::alb`) reads as its member and name.
|
|
3816
|
+
body.append(w, " " + shortIds(text));
|
|
3817
|
+
if (tag) {
|
|
3818
|
+
const t = document.createElement("span");
|
|
3819
|
+
t.className = "tag";
|
|
3820
|
+
t.textContent = tag;
|
|
3821
|
+
body.appendChild(t);
|
|
3822
|
+
}
|
|
3823
|
+
row.append(dot, body);
|
|
3824
|
+
if (onClick) row.addEventListener("click", onClick);
|
|
3825
|
+
return row;
|
|
3826
|
+
}
|
|
3827
|
+
|
|
3828
|
+
function renderNetworkSection(host) {
|
|
3829
|
+
if (view.components || view.ops) return;
|
|
3830
|
+
// The section reads its own every-card graph, so a zoom that folds the
|
|
3831
|
+
// network away (composites, logical) still traces it.
|
|
3832
|
+
loadNetworkGraph();
|
|
3833
|
+
if (net.ir && !net.ir.nodes.some((n) => NETWORK_KIND.test(n.kind || ""))) return;
|
|
3834
|
+
host.appendChild(panelHeading("network"));
|
|
3835
|
+
if (net.error) {
|
|
3836
|
+
host.appendChild(panelMuted(`the network couldn't be read: ${net.error}`));
|
|
3837
|
+
return;
|
|
3838
|
+
}
|
|
3839
|
+
if (!net.ir) {
|
|
3840
|
+
host.appendChild(panelMuted("reading the network…"));
|
|
3841
|
+
return;
|
|
3842
|
+
}
|
|
3843
|
+
const findings = networkFindings(net.ir);
|
|
3844
|
+
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."));
|
|
3845
|
+
for (const f of findings) host.appendChild(netRow("var(--degraded)", f.finding, f.text, "", () => selectNode(f.ids[0])));
|
|
3846
|
+
|
|
3847
|
+
// The trace: from, to, port.
|
|
3848
|
+
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();
|
|
3849
|
+
const pick = (label, value, options, onChange) => {
|
|
3850
|
+
const row = document.createElement("label");
|
|
3851
|
+
row.className = "net-pick";
|
|
3852
|
+
row.append(label + " ");
|
|
3853
|
+
const sel = document.createElement("select");
|
|
3854
|
+
for (const [v, text] of options) {
|
|
3855
|
+
const o = document.createElement("option");
|
|
3856
|
+
o.value = v;
|
|
3857
|
+
o.textContent = text;
|
|
3858
|
+
if (v === value) o.selected = true;
|
|
3859
|
+
sel.appendChild(o);
|
|
3860
|
+
}
|
|
3861
|
+
sel.addEventListener("change", () => onChange(sel.value));
|
|
3862
|
+
row.appendChild(sel);
|
|
3863
|
+
return row;
|
|
3864
|
+
};
|
|
3865
|
+
const form = document.createElement("div");
|
|
3866
|
+
form.className = "net-trace";
|
|
3867
|
+
form.appendChild(pick("from", net.from, [[OUTSIDE, "outside (the internet)"], ...cards.map((c) => [c, c])], (v) => (net.from = v)));
|
|
3868
|
+
form.appendChild(pick("to", net.to || "", [["", "pick a card"], ...cards.map((c) => [c, c])], (v) => (net.to = v || null)));
|
|
3869
|
+
const portRow = document.createElement("label");
|
|
3870
|
+
portRow.className = "net-pick";
|
|
3871
|
+
portRow.append("port ");
|
|
3872
|
+
const port = document.createElement("input");
|
|
3873
|
+
port.type = "number";
|
|
3874
|
+
port.min = "1";
|
|
3875
|
+
port.max = "65535";
|
|
3876
|
+
port.value = String(net.port);
|
|
3877
|
+
port.addEventListener("change", () => (net.port = Number(port.value)));
|
|
3878
|
+
portRow.appendChild(port);
|
|
3879
|
+
form.appendChild(portRow);
|
|
3880
|
+
const row = document.createElement("div");
|
|
3881
|
+
row.className = "prow";
|
|
3882
|
+
row.appendChild(
|
|
3883
|
+
actButton("trace", () => {
|
|
3884
|
+
net.port = Number(port.value);
|
|
3885
|
+
runTrace();
|
|
3886
|
+
renderPanelModel();
|
|
3887
|
+
}, "Follow the traffic hop by hop and mark where it stops"),
|
|
3888
|
+
);
|
|
3889
|
+
if (net.result) row.appendChild(actButton("clear", () => { net.result = null; markTrace(); renderPanelModel(); }));
|
|
3890
|
+
form.appendChild(row);
|
|
3891
|
+
host.appendChild(form);
|
|
3892
|
+
|
|
3893
|
+
const r = net.result;
|
|
3894
|
+
if (!r) return;
|
|
3895
|
+
if (r.unread) {
|
|
3896
|
+
host.appendChild(panelMuted(r.unread));
|
|
3897
|
+
return;
|
|
3898
|
+
}
|
|
3899
|
+
host.appendChild(panelMuted(shortIds(r.reached ? `${r.port} arrives at ${r.to}.` : `${r.port} stops at ${r.stop}.`)));
|
|
3900
|
+
for (const h of r.hops) {
|
|
3901
|
+
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);
|
|
3902
|
+
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";
|
|
3903
|
+
host.appendChild(row);
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3239
3907
|
// #553: the CI edge kinds this graph draws, each with a stroke drawn by the
|
|
3240
3908
|
// same rules as the graph's own edges (index.html matches `.edge-swatch` beside
|
|
3241
3909
|
// `#graph`), so the legend changes with the theme. Nothing on a graph that
|
|
3242
3910
|
// holds only references.
|
|
3243
3911
|
function renderEdgeLegend(host, ir) {
|
|
3244
|
-
const rows = edgeLegend(ir.edges || []);
|
|
3912
|
+
const rows = [...edgeLegend(ir.edges || []), ...weightLegend(lastEdgeWeights)];
|
|
3245
3913
|
if (!rows.length) return;
|
|
3246
3914
|
host.appendChild(panelHeading("edges"));
|
|
3247
3915
|
for (const r of rows) {
|
|
@@ -3256,6 +3924,7 @@ function renderEdgeLegend(host, ir) {
|
|
|
3256
3924
|
const g = document.createElementNS(SVGNS, "g");
|
|
3257
3925
|
if (r.kind) g.setAttribute("data-edge-kind", r.kind);
|
|
3258
3926
|
if (r.cross) g.setAttribute("data-edge-cross", "true");
|
|
3927
|
+
if (r.weight) g.setAttribute("data-edge-weight", r.weight);
|
|
3259
3928
|
const line = document.createElementNS(SVGNS, "path");
|
|
3260
3929
|
line.setAttribute("class", "pin-edge-line");
|
|
3261
3930
|
line.setAttribute("d", "M 1 5 L 27 5");
|
|
@@ -3729,7 +4398,7 @@ function markDriftedCards(ir) {
|
|
|
3729
4398
|
const count_ = mark.attributes.length;
|
|
3730
4399
|
tag.textContent = `~ ${count_} attribute${count_ === 1 ? "" : "s"}`;
|
|
3731
4400
|
const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
3732
|
-
title.textContent = `The plan would ${(mark.actions || ["update"]).join("+")} this: ${mark.attributes.join(", ")}. Ownership is unchanged — the card's
|
|
4401
|
+
title.textContent = `The plan would ${(mark.actions || ["update"]).join("+")} this: ${mark.attributes.join(", ")}. Ownership is unchanged — the card's color is still its ownership verdict.`;
|
|
3733
4402
|
g.appendChild(title);
|
|
3734
4403
|
g.appendChild(tag);
|
|
3735
4404
|
}
|
|
@@ -5943,15 +6612,22 @@ function kioskTellBoxes() {
|
|
|
5943
6612
|
* so the graph pane never shows an empty frame.
|
|
5944
6613
|
*/
|
|
5945
6614
|
var drawnTold = false;
|
|
5946
|
-
|
|
5947
|
-
|
|
6615
|
+
/** Whether the graph has drawn with its marks: "failed" when it could not, true once drawn, false while it is still coming. */
|
|
6616
|
+
function graphDrawnState() {
|
|
5948
6617
|
const svg = currentSvg();
|
|
5949
|
-
|
|
5950
|
-
if (!
|
|
6618
|
+
if (document.querySelector("#graph > .err")) return "failed";
|
|
6619
|
+
if (!(svg && svg.querySelector("[data-node-id]"))) return false;
|
|
5951
6620
|
// The marks: terragucci's reports answered (or refused), or chant's loop has its own.
|
|
5952
|
-
if (
|
|
6621
|
+
if (terragucciComponentsRepo && !tgAnswer && !chantPrDrawn()) return false;
|
|
5953
6622
|
// behold#631: a chant repo's loop: its first read of /api/chant/pr, answered or not.
|
|
5954
|
-
if (!
|
|
6623
|
+
if (!terragucciComponentsRepo && view.components && chantFacets && !staticMode && !chantPrRead) return false;
|
|
6624
|
+
return true;
|
|
6625
|
+
}
|
|
6626
|
+
function kioskTellDrawn() {
|
|
6627
|
+
if (drawnTold || !embedOpts.host || window.parent === window) return;
|
|
6628
|
+
const drawnState = graphDrawnState();
|
|
6629
|
+
if (!drawnState) return;
|
|
6630
|
+
const failed = drawnState === "failed";
|
|
5955
6631
|
drawnTold = true;
|
|
5956
6632
|
try {
|
|
5957
6633
|
window.parent.postMessage({ type: "behold:drawn", failed }, embedOpts.host);
|
|
@@ -5962,6 +6638,97 @@ function kioskTellDrawn() {
|
|
|
5962
6638
|
// A graph that failed draws no svg and no reads: say so too, so the kiosk is never left waiting.
|
|
5963
6639
|
if (embedOpts.bare) setInterval(kioskTellDrawn, 1000);
|
|
5964
6640
|
|
|
6641
|
+
// --- behold#915: the page `behold shot` photographs ---------------------------
|
|
6642
|
+
// `?embed=1&bare=1&frame=matches` (web/shot-frame.js). Once the graph has
|
|
6643
|
+
// drawn, the cards the view asks for are lit and the rest dimmed, the lit
|
|
6644
|
+
// cards are framed with the kiosk's arithmetic at once (no move), one caption
|
|
6645
|
+
// line says what was asked, from where and when, and <html> gets
|
|
6646
|
+
// `data-behold-shot`. A graph that never draws never sets it, so the driver
|
|
6647
|
+
// times out and writes nothing.
|
|
6648
|
+
const shotFrameOn = !!embedOpts.bare && readShotFrame(location.search) === "matches";
|
|
6649
|
+
// The link as loaded: the page rewrites its URL as it settles the view (a card it lacks drops out), and the shot answers what was asked.
|
|
6650
|
+
const shotAsked = new URLSearchParams(location.search);
|
|
6651
|
+
var shotFrameDone = false; // var: setupGraphViewBox reads it, and may run before this line is reached
|
|
6652
|
+
var shotQueryFailed = false; // behold#913: the query was refused, or its live read failed
|
|
6653
|
+
function shotFrameTick() {
|
|
6654
|
+
if (!shotFrameOn || shotFrameDone) return;
|
|
6655
|
+
const drawnState = graphDrawnState();
|
|
6656
|
+
if (!drawnState) return;
|
|
6657
|
+
// behold#913: a query is drawn once chant has answered it (drawQuery marks the cards first).
|
|
6658
|
+
if (drawnState !== "failed" && queryAnswerNow() === undefined) return;
|
|
6659
|
+
shotFrameDone = true;
|
|
6660
|
+
const state = shotFrameApply(drawnState === "failed");
|
|
6661
|
+
// Two frames, so what was set above is painted before the driver looks.
|
|
6662
|
+
requestAnimationFrame(() => requestAnimationFrame(() => document.documentElement.setAttribute(SHOT_ATTR, state)));
|
|
6663
|
+
}
|
|
6664
|
+
/** Light, dim, frame and caption the graph as it is drawn now; the state the shot reports. */
|
|
6665
|
+
function shotFrameApply(failed = !!document.querySelector("#graph > .err")) {
|
|
6666
|
+
const params = shotAsked;
|
|
6667
|
+
const svg = currentSvg();
|
|
6668
|
+
const host = document.getElementById("graph");
|
|
6669
|
+
let lit = { ids: [], asked: false, label: null };
|
|
6670
|
+
if (!failed && svg && host) {
|
|
6671
|
+
const ownRect = (g) => g.querySelector(":scope > rect") || g;
|
|
6672
|
+
const cards = [...svg.querySelectorAll("[data-node-id]")].map((g) => ({ id: g.getAttribute("data-node-id"), g, box: userBoxOf(svg, ownRect(g)) }));
|
|
6673
|
+
const groups = [...svg.querySelectorAll("rect[data-group-id]")].map((r) => ({ id: r.getAttribute("data-group-id"), box: userBoxOf(svg, r) }));
|
|
6674
|
+
// behold#913: the query's matched node ids (drawQuery has marked the cards and the path edges). Without a
|
|
6675
|
+
// query, the link's own node and focus, as asked: a card the graph lacks is a question with no answer, never the whole graph.
|
|
6676
|
+
const qa = queryAnswerNow();
|
|
6677
|
+
// #908 stage 3: the matches and the frame come from drawQuery's marks, so a stack holding a match counts and the path is in the picture.
|
|
6678
|
+
const qf = qa && qa.draw ? queryFrame(cards.map((c) => ({ id: c.id, mark: c.g.getAttribute("data-q") }))) : null;
|
|
6679
|
+
lit = shotLit({ node: params.get("node"), focus: params.get("focus") }, cards, groups, qa ? (qf ? qf.lit : []) : null);
|
|
6680
|
+
shotQueryFailed = !!qa && (!qa.draw || !!qa.draw.failure);
|
|
6681
|
+
const on = new Set(lit.ids);
|
|
6682
|
+
for (const c of cards) {
|
|
6683
|
+
// A query's on-path cards stay at full weight; a refused query dims nothing.
|
|
6684
|
+
const dim = qa ? c.g.getAttribute("data-q") === "dim" : lit.asked && !on.has(c.id);
|
|
6685
|
+
c.g.style.opacity = dim ? String(SHOT_DIM) : "";
|
|
6686
|
+
if (dim || (qa && !on.has(c.id))) c.g.setAttribute("data-shot-dim", "1");
|
|
6687
|
+
else c.g.removeAttribute("data-shot-dim");
|
|
6688
|
+
}
|
|
6689
|
+
for (const e of svg.querySelectorAll("[data-edge-from]")) {
|
|
6690
|
+
const mark = e.getAttribute("data-q");
|
|
6691
|
+
const dim = qa ? mark === "dim" : lit.asked && !(on.has(e.getAttribute("data-edge-from")) && on.has(e.getAttribute("data-edge-to")));
|
|
6692
|
+
e.style.opacity = dim ? String(SHOT_DIM) : "";
|
|
6693
|
+
}
|
|
6694
|
+
// The lit cards, or with none lit the whole graph as drawn (its boxes' titles and all).
|
|
6695
|
+
const whole = vbInit && { x: vbInit[0], y: vbInit[1], x2: vbInit[0] + vbInit[2], y2: vbInit[1] + vbInit[3] };
|
|
6696
|
+
const framed = qf ? new Set(qf.frame) : on;
|
|
6697
|
+
const target = (lit.ids.length && unionBox(cards.filter((c) => framed.has(c.id)).map((c) => c.box))) || whole;
|
|
6698
|
+
const pane = host.getBoundingClientRect();
|
|
6699
|
+
const to = target && shotViewBox(target, { width: pane.width, height: pane.height }, { bottom: SHOT_CAPTION_PX });
|
|
6700
|
+
if (to) {
|
|
6701
|
+
vb = to;
|
|
6702
|
+
vbAtFit = false;
|
|
6703
|
+
applyVB();
|
|
6704
|
+
}
|
|
6705
|
+
}
|
|
6706
|
+
const qa = queryAnswerNow();
|
|
6707
|
+
const state = shotState({ failed: failed || shotQueryFailed, lit });
|
|
6708
|
+
const err = document.querySelector("#graph > .err");
|
|
6709
|
+
let cap = document.getElementById("shot-caption");
|
|
6710
|
+
if (!cap) {
|
|
6711
|
+
cap = document.createElement("div");
|
|
6712
|
+
cap.id = "shot-caption";
|
|
6713
|
+
cap.style.cssText = `position:fixed;left:0;right:0;bottom:0;height:${SHOT_CAPTION_PX}px;padding:0 12px;font:13px/1 system-ui,sans-serif;line-height:${SHOT_CAPTION_PX}px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;z-index:50;background:var(--bg, #0d1117);color:var(--fg, #e6edf3);border-top:1px solid var(--border, #30363d)`;
|
|
6714
|
+
document.body.appendChild(cap);
|
|
6715
|
+
}
|
|
6716
|
+
cap.style.color = state === "failed" ? "var(--degraded, #f85149)" : "var(--fg, #e6edf3)";
|
|
6717
|
+
// behold#913: chant's own provenance line, and its failure, when a query was asked.
|
|
6718
|
+
const qFailure = qa ? (qa.draw ? qa.draw.failure && [qa.draw.failure.message, qa.draw.failure.hint].filter(Boolean).join(". ") : qa.error || "the search failed") : null;
|
|
6719
|
+
cap.textContent = shotCaption({
|
|
6720
|
+
query: params.get("q") || (params.get("countBy") ? "the whole graph" : null),
|
|
6721
|
+
counts: qa && qa.draw && qa.draw.counts ? countsLine(qa.draw.counts) : null,
|
|
6722
|
+
label: lit.label,
|
|
6723
|
+
provenance: (qa && qa.draw && qa.draw.provenance) || shotProvenance({ env: view.env, snapshot: params.get("snapshot") }),
|
|
6724
|
+
failure: state === "failed" ? (err ? (err.textContent || "the graph failed to draw").split("\n")[0] : qFailure || "the graph failed to draw") : null,
|
|
6725
|
+
state,
|
|
6726
|
+
plan: !!view.plan,
|
|
6727
|
+
});
|
|
6728
|
+
return state;
|
|
6729
|
+
}
|
|
6730
|
+
if (shotFrameOn) setInterval(shotFrameTick, 250);
|
|
6731
|
+
|
|
5965
6732
|
window.addEventListener("message", (e) => {
|
|
5966
6733
|
if (!embedOpts.bare) return;
|
|
5967
6734
|
const shot = shotFromMessage(e, embedOpts.host);
|
|
@@ -7094,7 +7861,7 @@ function renderStatusbar() {
|
|
|
7094
7861
|
// #399: which colour the graph is in is state, not a control, so it belongs
|
|
7095
7862
|
// on the strip the same way the zoom and the env do. Only when it is not
|
|
7096
7863
|
// drift — drift is what the strip has always implied.
|
|
7097
|
-
if (activeColourMode() !== "drift") parts.push(`
|
|
7864
|
+
if (activeColourMode() !== "drift") parts.push(`color: ${activeColourMode()}`);
|
|
7098
7865
|
if (view.stack) parts.push(`stack: ${view.stack}`);
|
|
7099
7866
|
if (axes.tier) parts.push(`tier: ${axes.tier}`);
|
|
7100
7867
|
if (view.radial && !view.components && !view.logical && !view.ops) parts.push("radial");
|
|
@@ -7976,6 +8743,7 @@ function relabelEdgeChip(chip, kind, via) {
|
|
|
7976
8743
|
// for a CI edge (#553), its `kind` and `crossPipeline` (web/edge-kind.js says
|
|
7977
8744
|
// them in words). Shown as a native SVG <title> tooltip on hover; the stamped
|
|
7978
8745
|
// attributes also drive the dashed and per-kind styles (index.html).
|
|
8746
|
+
let lastEdgeWeights = new Map();
|
|
7979
8747
|
function wireEdgeHighlight(svgEl, ir) {
|
|
7980
8748
|
const edges = [...svgEl.querySelectorAll("g[data-edge-from]")];
|
|
7981
8749
|
if (!edges.length) return;
|
|
@@ -7983,6 +8751,12 @@ function wireEdgeHighlight(svgEl, ir) {
|
|
|
7983
8751
|
// two kinds on one pair keep their own reason. pinhole stamps data-edge-via
|
|
7984
8752
|
// itself; this fills it in where it did not.
|
|
7985
8753
|
const viaOf = viaIndex(ir.edges || []);
|
|
8754
|
+
// #878: each reference weighed by how it was found (web/edge-weight.js).
|
|
8755
|
+
lastEdgeWeights = edgeWeights(ir.edges || [], new Map((ir.nodes || []).map((n) => [n.id, n.kind])));
|
|
8756
|
+
for (const g of edges) {
|
|
8757
|
+
const w = lastEdgeWeights.get(`${g.getAttribute("data-edge-from")}→${g.getAttribute("data-edge-to")}`);
|
|
8758
|
+
if (w) g.setAttribute("data-edge-weight", w);
|
|
8759
|
+
}
|
|
7986
8760
|
for (const g of edges) {
|
|
7987
8761
|
const from = g.getAttribute("data-edge-from");
|
|
7988
8762
|
const to = g.getAttribute("data-edge-to");
|
|
@@ -7997,10 +8771,21 @@ function wireEdgeHighlight(svgEl, ir) {
|
|
|
7997
8771
|
}
|
|
7998
8772
|
// behold#744: raised under the terragucci reads' layer, whose lines and pills stay over every edge.
|
|
7999
8773
|
const raise = (g) => g.parentNode && g.parentNode.insertBefore(g, g.parentNode.querySelector(":scope > [data-tg-reads]"));
|
|
8000
|
-
|
|
8774
|
+
wireEdgeLabelPeek(svgEl);
|
|
8775
|
+
// Delegated: light and raise whichever edge the pointer is over (its hit-path
|
|
8776
|
+
// catches it). Lit by a class, not `:hover`: raising re-inserts the element,
|
|
8777
|
+
// and a re-inserted element loses `:hover` until the pointer moves again, so
|
|
8778
|
+
// the line flickered rather than lit.
|
|
8001
8779
|
svgEl.addEventListener("mouseover", (e) => {
|
|
8002
8780
|
const g = e.target.closest && e.target.closest("g[data-edge-from]");
|
|
8003
|
-
if (g)
|
|
8781
|
+
if (!g) return;
|
|
8782
|
+
g.classList.add("edge-over");
|
|
8783
|
+
const top = g.parentNode && g.parentNode.querySelector(":scope > [data-tg-reads]");
|
|
8784
|
+
if (g.nextElementSibling !== top) raise(g);
|
|
8785
|
+
});
|
|
8786
|
+
svgEl.addEventListener("mouseout", (e) => {
|
|
8787
|
+
const g = e.target.closest && e.target.closest("g[data-edge-from]");
|
|
8788
|
+
if (g && !(e.relatedTarget && g.contains(e.relatedTarget))) g.classList.remove("edge-over");
|
|
8004
8789
|
});
|
|
8005
8790
|
// Hovering a node lights (and raises) every edge on it.
|
|
8006
8791
|
for (const card of svgEl.querySelectorAll("[data-node-id]")) {
|
|
@@ -8638,6 +9423,7 @@ function render(ir, svg, m) {
|
|
|
8638
9423
|
if (embedOpts.bare) quietCardLines(svgEl);
|
|
8639
9424
|
setupGraphViewBox(svgEl);
|
|
8640
9425
|
wireEdgeHighlight(svgEl, ir);
|
|
9426
|
+
markTrace(); // #881: a trace stays marked across a redraw
|
|
8641
9427
|
}
|
|
8642
9428
|
// #712: only the dots preview's meta carries `dots`. #715: a live carve, when the gate opened.
|
|
8643
9429
|
if (svgEl && m && m.dots) {
|
|
@@ -8767,6 +9553,8 @@ function setupGraphViewBox(svg) {
|
|
|
8767
9553
|
applyVB();
|
|
8768
9554
|
// behold#571: in the kiosk's Watch mode a re-render keeps the shot the kiosk asked for.
|
|
8769
9555
|
if (kioskShot) queueMicrotask(() => applyKioskShot(false));
|
|
9556
|
+
// behold#915: a re-render keeps the shot's lights and framing.
|
|
9557
|
+
if (shotFrameDone) queueMicrotask(() => shotFrameApply());
|
|
8770
9558
|
} else {
|
|
8771
9559
|
vbInit = vb = null;
|
|
8772
9560
|
}
|
|
@@ -8899,9 +9687,16 @@ function watchPaneForFit(host) {
|
|
|
8899
9687
|
// every pan and zoom; only the type gets bigger.
|
|
8900
9688
|
//
|
|
8901
9689
|
// The floor yields to the box: a label may not grow past a fraction of the
|
|
8902
|
-
// box's height, nor past its width. A sub-box too small to hold readable type
|
|
8903
|
-
//
|
|
8904
|
-
//
|
|
9690
|
+
// box's height, nor past its width. A sub-box too small to hold readable type at this zoom says
|
|
9691
|
+
// so by staying small, rather than by writing across its neighbours. A title
|
|
9692
|
+
// pinhole's own size can't fit across its box shrinks to fit.
|
|
9693
|
+
//
|
|
9694
|
+
// pinhole's baseline is set for its own size, so a title grown in place would
|
|
9695
|
+
// rise out through the box's top edge. As it grows its baseline steps down
|
|
9696
|
+
// by the same amount, keeping its top inside the box.
|
|
9697
|
+
const BOX_LABEL_PAD = 6; // units between a box's top edge and the top of its grown title
|
|
9698
|
+
const BOX_LABEL_ASCENT = 0.95; // the font's ascent above the baseline, as a fraction of the size
|
|
9699
|
+
const BOX_LABEL_MIN = 7; // the smallest a title shrinks to fit across its box
|
|
8905
9700
|
const BOX_LABEL_GUTTER = 34; // units below a box's top edge that the title row occupies
|
|
8906
9701
|
const BOX_LABEL_MAX_H = 8; // a label may be at most box height / this
|
|
8907
9702
|
const BOX_LABEL_EM = 0.62; // rough advance width per char, as a fraction of the size
|
|
@@ -8944,7 +9739,7 @@ function boxLabelsOf(svg) {
|
|
|
8944
9739
|
const box = boxes.find((b) => y > b.y && y <= b.y + BOX_LABEL_GUTTER && x >= b.x - 2 && x <= b.x + b.w + 2);
|
|
8945
9740
|
if (!box) continue;
|
|
8946
9741
|
t.dataset.pinFont = String(base);
|
|
8947
|
-
labels.push({ el: t, box, base });
|
|
9742
|
+
labels.push({ el: t, box, base, y, shift: 0 });
|
|
8948
9743
|
}
|
|
8949
9744
|
}
|
|
8950
9745
|
boxLabelCache = { svg, labels };
|
|
@@ -8967,20 +9762,64 @@ function scaleBoxLabels() {
|
|
|
8967
9762
|
boxLabelScale = scale;
|
|
8968
9763
|
for (const l of labels) {
|
|
8969
9764
|
const chars = Math.max(4, (l.el.textContent || "").length);
|
|
8970
|
-
const
|
|
8971
|
-
const
|
|
8972
|
-
|
|
9765
|
+
const across = (l.box.w - 2 * BOX_LABEL_PAD) / (chars * BOX_LABEL_EM);
|
|
9766
|
+
const floor = Math.max(BOX_LABEL_MIN, Math.min(l.base, across));
|
|
9767
|
+
const cap = Math.max(floor, Math.min(l.box.h / BOX_LABEL_MAX_H, across));
|
|
9768
|
+
const size = Math.round(Math.max(floor, Math.min(l.base / scale, cap)) * 10) / 10;
|
|
9769
|
+
l.el.setAttribute("font-size", String(size));
|
|
9770
|
+
// Step the baseline down as far as the title grew; read y live, since a placement move shifts it.
|
|
9771
|
+
const shift = Math.max(0, l.box.y + BOX_LABEL_PAD + size * BOX_LABEL_ASCENT - l.y);
|
|
9772
|
+
if (shift !== l.shift) {
|
|
9773
|
+
const y = parseFloat(l.el.getAttribute("y"));
|
|
9774
|
+
if (Number.isFinite(y)) l.el.setAttribute("y", String(Math.round((y - l.shift + shift) * 10) / 10));
|
|
9775
|
+
l.shift = shift;
|
|
9776
|
+
}
|
|
9777
|
+
}
|
|
9778
|
+
declutterBoxHeads(labels);
|
|
9779
|
+
}
|
|
9780
|
+
|
|
9781
|
+
/**
|
|
9782
|
+
* A narrow box can't hold its title and its count badge on one row: the two
|
|
9783
|
+
* ran into each other ("awscards · all managed"). The title is the box's
|
|
9784
|
+
* name, so it keeps the row; the badge steps aside and becomes the box's
|
|
9785
|
+
* tooltip instead, and comes back once the zoom leaves it room (behold#824).
|
|
9786
|
+
*/
|
|
9787
|
+
function declutterBoxHeads(labels) {
|
|
9788
|
+
const byBox = new Map();
|
|
9789
|
+
for (const l of labels) (byBox.get(l.box) ?? byBox.set(l.box, []).get(l.box)).push(l.el);
|
|
9790
|
+
for (const els of byBox.values()) {
|
|
9791
|
+
const badge = els.find((t) => t.getAttribute("text-anchor") === "end");
|
|
9792
|
+
const title = els.find((t) => t !== badge);
|
|
9793
|
+
if (!badge || !title) continue;
|
|
9794
|
+
badge.style.display = "";
|
|
9795
|
+
let clash = false;
|
|
9796
|
+
try {
|
|
9797
|
+
const a = title.getBBox();
|
|
9798
|
+
const b = badge.getBBox();
|
|
9799
|
+
clash = a.x + a.width + 6 > b.x;
|
|
9800
|
+
} catch {
|
|
9801
|
+
continue;
|
|
9802
|
+
}
|
|
9803
|
+
badge.style.display = clash ? "none" : "";
|
|
9804
|
+
const rect = title.parentNode && title.parentNode.querySelector(":scope > rect[data-group-id]");
|
|
9805
|
+
if (rect && clash && !rect.querySelector(":scope > title")) {
|
|
9806
|
+
const tip = document.createElementNS(SVGNS, "title");
|
|
9807
|
+
tip.textContent = `${rect.getAttribute("data-group-id")}: ${badge.textContent}`;
|
|
9808
|
+
rect.appendChild(tip);
|
|
9809
|
+
}
|
|
8973
9810
|
}
|
|
8974
9811
|
}
|
|
8975
9812
|
|
|
8976
9813
|
// 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
|
|
8978
|
-
//
|
|
8979
|
-
//
|
|
8980
|
-
//
|
|
8981
|
-
//
|
|
8982
|
-
|
|
8983
|
-
|
|
9814
|
+
// units, which on a graph fitted at a quarter scale is under 3px, and enlarged
|
|
9815
|
+
// to be readable there it piles onto the cards around it. So a label shows at
|
|
9816
|
+
// its own size once the zoom makes it readable (EDGE_LABEL_MIN_PX on screen),
|
|
9817
|
+
// and below that it is hidden unless its edge is lit: hovering a card lights
|
|
9818
|
+
// every edge on it (`.edge-hi`), and hovering an edge peeks its own labels.
|
|
9819
|
+
// A lit small label is drawn up to EDGE_LABEL_MAX_K times larger, so it can be
|
|
9820
|
+
// read; only a card's few edges light at once, so they don't pile up.
|
|
9821
|
+
const EDGE_LABEL_MIN_PX = 8;
|
|
9822
|
+
const EDGE_LABEL_MAX_K = 4;
|
|
8984
9823
|
let edgeLabelState = { svg: null, scale: null };
|
|
8985
9824
|
|
|
8986
9825
|
function scaleEdgeLabels() {
|
|
@@ -8994,16 +9833,35 @@ function scaleEdgeLabels() {
|
|
|
8994
9833
|
for (const g of svg.querySelectorAll("g[data-edge-via]")) {
|
|
8995
9834
|
const text = g.querySelector(":scope > text");
|
|
8996
9835
|
const rect = g.querySelector(":scope > rect");
|
|
8997
|
-
if (!text
|
|
9836
|
+
if (!text) continue;
|
|
8998
9837
|
const size = parseFloat(text.getAttribute("font-size")) || 10.5;
|
|
8999
|
-
const
|
|
9000
|
-
|
|
9001
|
-
|
|
9838
|
+
const small = size * scale < EDGE_LABEL_MIN_PX;
|
|
9839
|
+
g.toggleAttribute("data-label-small", small);
|
|
9840
|
+
// A small label shows only while its edge is lit, a few at a time, so it
|
|
9841
|
+
// is drawn big enough to read then, scaled about its pill's centre.
|
|
9842
|
+
const k = small ? Math.min(EDGE_LABEL_MAX_K, EDGE_LABEL_MIN_PX / (size * scale)) : 1;
|
|
9843
|
+
const cx = rect ? Number(rect.getAttribute("x")) + Number(rect.getAttribute("width")) / 2 : Number(text.getAttribute("x"));
|
|
9844
|
+
const cy = rect ? Number(rect.getAttribute("y")) + Number(rect.getAttribute("height")) / 2 : Number(text.getAttribute("y"));
|
|
9002
9845
|
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");
|
|
9846
|
+
for (const el of rect ? [rect, text] : [text]) t ? el.setAttribute("transform", t) : el.removeAttribute("transform");
|
|
9004
9847
|
}
|
|
9005
9848
|
}
|
|
9006
9849
|
|
|
9850
|
+
/** Hovering an edge shows the labels that belong to it, however far out the zoom. */
|
|
9851
|
+
function wireEdgeLabelPeek(svgEl) {
|
|
9852
|
+
const labelsOf = (from, to) => svgEl.querySelectorAll(`g[data-edge-from="${CSS.escape(from)}"][data-edge-to="${CSS.escape(to)}"][data-edge-via]`);
|
|
9853
|
+
svgEl.addEventListener("mouseover", (e) => {
|
|
9854
|
+
const g = e.target.closest && e.target.closest("g[data-edge-from]");
|
|
9855
|
+
if (!g) return;
|
|
9856
|
+
for (const l of labelsOf(g.getAttribute("data-edge-from"), g.getAttribute("data-edge-to"))) l.classList.add("label-peek");
|
|
9857
|
+
});
|
|
9858
|
+
svgEl.addEventListener("mouseout", (e) => {
|
|
9859
|
+
const g = e.target.closest && e.target.closest("g[data-edge-from]");
|
|
9860
|
+
if (!g) return;
|
|
9861
|
+
for (const l of labelsOf(g.getAttribute("data-edge-from"), g.getAttribute("data-edge-to"))) l.classList.remove("label-peek");
|
|
9862
|
+
});
|
|
9863
|
+
}
|
|
9864
|
+
|
|
9007
9865
|
// How much of the viewBox one card should take when ⌘K lands on it (#393): the
|
|
9008
9866
|
// window is this many card-widths across, so a 301-card estate arrives readable
|
|
9009
9867
|
// rather than at whatever zoom the last gesture left. Never wider than the fit,
|
|
@@ -9547,6 +10405,7 @@ function applyLayout() {
|
|
|
9547
10405
|
indexLayout(svgEl);
|
|
9548
10406
|
reloadLayoutDeltas();
|
|
9549
10407
|
ensureLayoutReset(host);
|
|
10408
|
+
ensureViewToggles(host);
|
|
9550
10409
|
ensureLayoutDrag(host);
|
|
9551
10410
|
const lens = currentLensKey();
|
|
9552
10411
|
if (currentLayoutKey() && layoutServer.lens !== lens) pullServerLayout(lens);
|
|
@@ -9690,17 +10549,17 @@ function ensureLayoutDrag(host) {
|
|
|
9690
10549
|
});
|
|
9691
10550
|
}
|
|
9692
10551
|
|
|
9693
|
-
/** The "↺
|
|
10552
|
+
/** The "↺ placement" control beside ⤢ fit — shown only while something is hand-placed. */
|
|
9694
10553
|
function ensureLayoutReset(host) {
|
|
9695
10554
|
if (!host) return;
|
|
9696
10555
|
let btn = document.getElementById("layout-reset");
|
|
9697
10556
|
if (!btn || btn.parentElement !== host) {
|
|
9698
10557
|
btn = document.createElement("button");
|
|
9699
10558
|
btn.id = "layout-reset";
|
|
9700
|
-
btn.textContent = "↺
|
|
10559
|
+
btn.textContent = "↺ placement";
|
|
9701
10560
|
btn.title =
|
|
9702
|
-
"
|
|
9703
|
-
"(A resized box never reflows what's inside it
|
|
10561
|
+
"Put every card and box you moved on this lens back where behold placed them. " +
|
|
10562
|
+
"(A resized box never reflows what's inside it; only the next layout does that.)";
|
|
9704
10563
|
btn.addEventListener("click", (e) => {
|
|
9705
10564
|
e.stopPropagation();
|
|
9706
10565
|
const key = currentLayoutKey();
|
|
@@ -9713,7 +10572,7 @@ function ensureLayoutReset(host) {
|
|
|
9713
10572
|
layoutDeltas = {};
|
|
9714
10573
|
renderLayout();
|
|
9715
10574
|
ensureLayoutReset(host);
|
|
9716
|
-
nowline("↺
|
|
10575
|
+
nowline("↺ placement reset: every card is back where behold placed it");
|
|
9717
10576
|
});
|
|
9718
10577
|
host.appendChild(btn);
|
|
9719
10578
|
}
|
|
@@ -9870,10 +10729,15 @@ async function loadOnce(opts = {}, isCurrent = () => true) {
|
|
|
9870
10729
|
if (view.runtime) q.set("runtime", "1");
|
|
9871
10730
|
// #404: the attribute-drift read, when this load is the one the person
|
|
9872
10731
|
// asked for it on. Consumed here — the next load goes without it.
|
|
9873
|
-
if (planDriftOnce) {
|
|
9874
|
-
q.set("plan", "1");
|
|
10732
|
+
if (planDriftOnce || view.plan) {
|
|
10733
|
+
q.set("plan", "1"); // behold#922: a view with plan=1 reads the plan on every load
|
|
9875
10734
|
planDriftOnce = false;
|
|
9876
10735
|
}
|
|
10736
|
+
} else if ((terraformPlanOnce || view.plan) && !view.components) {
|
|
10737
|
+
// #910: the plan on the stock Terraform roots, read through chant onto
|
|
10738
|
+
// the source graph's cards. One-shot, like #404's above.
|
|
10739
|
+
q.set("plan", "1");
|
|
10740
|
+
terraformPlanOnce = false;
|
|
9877
10741
|
}
|
|
9878
10742
|
// Radial layout (entity view only) — curl the wide DAG onto concentric rings.
|
|
9879
10743
|
if (view.radial && !view.components && !view.logical && !view.ops) q.set("radial", "1");
|
|
@@ -9882,6 +10746,8 @@ async function loadOnce(opts = {}, isCurrent = () => true) {
|
|
|
9882
10746
|
// and the ops view have no member boxes to shut — and it rides both the
|
|
9883
10747
|
// source graph and the overlay, so picking an env doesn't undo it.
|
|
9884
10748
|
if (view.collapse && !view.components && !view.ops) q.set("collapse", "1");
|
|
10749
|
+
// #877: an estate stacks alike cards by default; `alike=0` draws every card.
|
|
10750
|
+
if (!view.alike && !view.components && !view.logical && !view.ops) q.set("alike", "0");
|
|
9885
10751
|
// The CI + resources facets are component-DAG-mode-only details. Load
|
|
9886
10752
|
// both whenever components mode is on, env picked or not — #59 unifies
|
|
9887
10753
|
// the CI facet (#58), the live-status join (#57), and resources (#59) so
|
|
@@ -9984,6 +10850,14 @@ function replayMemberFrames(load) {
|
|
|
9984
10850
|
* of `GET /api/overlay`, which is where the drift read lives — so this row
|
|
9985
10851
|
* goes through `load()`, the path that actually renders those cards.
|
|
9986
10852
|
*/
|
|
10853
|
+
async function readTerraformPlan() {
|
|
10854
|
+
terraformPlanOnce = true;
|
|
10855
|
+
nowline("↻ reading the plan on the Terraform roots…");
|
|
10856
|
+
await load();
|
|
10857
|
+
const note = lastMeta && lastMeta.note ? String(lastMeta.note).split(" · ").find((p) => p.startsWith("plan: ")) : null;
|
|
10858
|
+
nowline(note ? `↻ ${note}` : "↻ the plan could not be read");
|
|
10859
|
+
}
|
|
10860
|
+
|
|
9987
10861
|
async function refreshWithPlan() {
|
|
9988
10862
|
planDriftOnce = true;
|
|
9989
10863
|
bulkDiffCache = null; // the pane's rows come from /api/diff — re-fetch them against the new plan
|
|
@@ -10065,7 +10939,8 @@ async function initPickers() {
|
|
|
10065
10939
|
runtimeCapable = !!info.runtimeCapable;
|
|
10066
10940
|
stacksCapable = !!info.stacksCapable;
|
|
10067
10941
|
terragucciComponentsRepo = !!info.terragucciComponents;
|
|
10068
|
-
|
|
10942
|
+
componentsDeclared = info.componentsDeclared;
|
|
10943
|
+
const boot = bootZoom(info.memberKinds, terragucciComponentsRepo, componentsDeclared);
|
|
10069
10944
|
if (boot !== "components") {
|
|
10070
10945
|
applyZoom(boot);
|
|
10071
10946
|
autoZoomFallback = false;
|
|
@@ -10125,7 +11000,11 @@ events.addEventListener("member", (e) => {
|
|
|
10125
11000
|
renderStatusbar();
|
|
10126
11001
|
});
|
|
10127
11002
|
|
|
11003
|
+
// #914: an agent's POST /api/view.
|
|
11004
|
+
events.addEventListener("view", (e) => agentMove(e.data));
|
|
11005
|
+
|
|
10128
11006
|
events.addEventListener("changed", () => {
|
|
11007
|
+
queryAnswer = null; // #913: the source or the estate moved: the next paint asks again
|
|
10129
11008
|
bulkDiffCache = null; // an op ran → per-node live state may have changed
|
|
10130
11009
|
whyAnswers.clear(); // #471: a why read before the change may no longer hold
|
|
10131
11010
|
load();
|
|
@@ -10915,6 +11794,140 @@ function exportSvg() {
|
|
|
10915
11794
|
nowline(`↓ exported ${a.download}`);
|
|
10916
11795
|
}
|
|
10917
11796
|
|
|
11797
|
+
// behold#882: the graph as a picture, for a document or a slide. The SVG on
|
|
11798
|
+
// the page leans on the stylesheet (theme variables, the cloud tints, edge
|
|
11799
|
+
// styles) and on linked vendor marks, none of which a bare copy carries, so
|
|
11800
|
+
// the copy gets every element's computed paint written onto it and each mark
|
|
11801
|
+
// inlined. It is the view as it stands (zoomed in, it is the zoomed view),
|
|
11802
|
+
// at 1-4x, optionally under a heading and with the graph's key drawn in.
|
|
11803
|
+
const PNG_PAINT = ["fill", "stroke", "stroke-width", "stroke-dasharray", "stroke-linecap", "opacity", "fill-opacity", "stroke-opacity", "font-size", "font-family", "font-weight", "display", "visibility"];
|
|
11804
|
+
const PNG_HEAD = 44;
|
|
11805
|
+
let pngOpts = { scale: 2, heading: true, key: true };
|
|
11806
|
+
|
|
11807
|
+
async function inlineMarks(clone) {
|
|
11808
|
+
for (const img of clone.querySelectorAll("image")) {
|
|
11809
|
+
const href = img.getAttribute("href") || img.getAttribute("xlink:href") || "";
|
|
11810
|
+
if (!href || href.startsWith("data:")) continue;
|
|
11811
|
+
try {
|
|
11812
|
+
const text = await (await fetch(href)).text();
|
|
11813
|
+
img.setAttribute("href", `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(text)))}`);
|
|
11814
|
+
} catch {
|
|
11815
|
+
img.remove();
|
|
11816
|
+
}
|
|
11817
|
+
}
|
|
11818
|
+
}
|
|
11819
|
+
|
|
11820
|
+
function keyRows() {
|
|
11821
|
+
const legend = document.getElementById("graph-legend");
|
|
11822
|
+
if (!legend || legend.classList.contains("closed")) return [];
|
|
11823
|
+
const rows = [];
|
|
11824
|
+
for (const el of legend.children) {
|
|
11825
|
+
if (el.classList.contains("gl-head")) continue;
|
|
11826
|
+
if (el.classList.contains("gl-sub")) {
|
|
11827
|
+
rows.push({ sub: el.textContent });
|
|
11828
|
+
continue;
|
|
11829
|
+
}
|
|
11830
|
+
const swatch = el.firstElementChild;
|
|
11831
|
+
const colours = swatch && swatch.children.length ? [...swatch.children].map((c) => getComputedStyle(c).backgroundColor) : swatch ? [getComputedStyle(swatch).backgroundColor] : [];
|
|
11832
|
+
const text = el.querySelector(".grow")?.textContent ?? "";
|
|
11833
|
+
const count = el.querySelector(".gl-count")?.textContent ?? "";
|
|
11834
|
+
rows.push({ colours, text, count });
|
|
11835
|
+
}
|
|
11836
|
+
return rows;
|
|
11837
|
+
}
|
|
11838
|
+
|
|
11839
|
+
async function exportPng() {
|
|
11840
|
+
const svg = currentSvg();
|
|
11841
|
+
if (!svg || !vb) {
|
|
11842
|
+
nowline("✗ export: no graph loaded yet");
|
|
11843
|
+
return;
|
|
11844
|
+
}
|
|
11845
|
+
const { scale, heading, key } = pngOpts;
|
|
11846
|
+
// At the fit the view leaves room for the floating panel; the picture takes
|
|
11847
|
+
// the graph's own bounds instead, with a margin. Zoomed or panned, it takes
|
|
11848
|
+
// the view as it stands.
|
|
11849
|
+
const pad = vbInit ? Math.max(vbInit[2], vbInit[3]) * 0.02 : 0;
|
|
11850
|
+
const area = vbAtFit && vbInit ? [vbInit[0] - pad, vbInit[1] - pad, vbInit[2] + 2 * pad, vbInit[3] + 2 * pad] : vb;
|
|
11851
|
+
const box = svg.getBoundingClientRect();
|
|
11852
|
+
const w = Math.round(box.width);
|
|
11853
|
+
const h = Math.round((w * area[3]) / area[2]);
|
|
11854
|
+
const head = heading ? PNG_HEAD : 0;
|
|
11855
|
+
// The key gets a band of its own under the graph, never drawn over it.
|
|
11856
|
+
const rowsForKey = key ? keyRows() : [];
|
|
11857
|
+
const keyLine = 17;
|
|
11858
|
+
const keyBand = rowsForKey.length ? rowsForKey.length * keyLine + 28 : 0;
|
|
11859
|
+
const clone = svg.cloneNode(true);
|
|
11860
|
+
const from = [svg, ...svg.querySelectorAll("*")];
|
|
11861
|
+
const to = [clone, ...clone.querySelectorAll("*")];
|
|
11862
|
+
for (let i = 0; i < from.length && i < to.length; i++) {
|
|
11863
|
+
const cs = getComputedStyle(from[i]);
|
|
11864
|
+
to[i].setAttribute("style", PNG_PAINT.map((p) => `${p}:${cs.getPropertyValue(p)}`).join(";"));
|
|
11865
|
+
}
|
|
11866
|
+
await inlineMarks(clone);
|
|
11867
|
+
clone.setAttribute("x", "0");
|
|
11868
|
+
clone.setAttribute("y", String(head));
|
|
11869
|
+
clone.setAttribute("width", String(w));
|
|
11870
|
+
clone.setAttribute("height", String(h));
|
|
11871
|
+
clone.setAttribute("viewBox", area.join(" "));
|
|
11872
|
+
const root = getComputedStyle(document.documentElement);
|
|
11873
|
+
const bg = root.getPropertyValue("--bg").trim() || "#ffffff";
|
|
11874
|
+
const fg = root.getPropertyValue("--fg").trim() || "#000000";
|
|
11875
|
+
const muted = root.getPropertyValue("--muted").trim() || fg;
|
|
11876
|
+
const esc = (t) => String(t).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
11877
|
+
const title = esc(document.title || "behold");
|
|
11878
|
+
const sub = esc(document.getElementById("meta")?.textContent?.trim() ?? "");
|
|
11879
|
+
const total = h + head + keyBand;
|
|
11880
|
+
const parts = [`<rect width="${w}" height="${total}" fill="${bg}"/>`];
|
|
11881
|
+
if (heading) {
|
|
11882
|
+
parts.push(`<text x="16" y="22" fill="${fg}" font-family="system-ui, sans-serif" font-size="16" font-weight="700">${title}</text>`);
|
|
11883
|
+
parts.push(`<text x="16" y="38" fill="${muted}" font-family="system-ui, sans-serif" font-size="11">${sub}</text>`);
|
|
11884
|
+
}
|
|
11885
|
+
parts.push(new XMLSerializer().serializeToString(clone));
|
|
11886
|
+
if (rowsForKey.length) {
|
|
11887
|
+
const kx = 16;
|
|
11888
|
+
const ky = head + h + 14;
|
|
11889
|
+
rowsForKey.forEach((r, i) => {
|
|
11890
|
+
const y = ky + i * keyLine + 9;
|
|
11891
|
+
if (r.sub) {
|
|
11892
|
+
parts.push(`<text x="${kx}" y="${y + 3}" fill="${muted}" font-family="system-ui, sans-serif" font-size="10.5">${esc(r.sub)}</text>`);
|
|
11893
|
+
return;
|
|
11894
|
+
}
|
|
11895
|
+
r.colours.forEach((c, j) => parts.push(`<rect x="${kx + j * 9}" y="${y - 6}" width="7" height="11" rx="1.5" fill="${c}"/>`));
|
|
11896
|
+
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>`);
|
|
11897
|
+
});
|
|
11898
|
+
}
|
|
11899
|
+
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>`;
|
|
11900
|
+
const url = URL.createObjectURL(new Blob([doc], { type: "image/svg+xml" }));
|
|
11901
|
+
try {
|
|
11902
|
+
const img = new Image();
|
|
11903
|
+
await new Promise((ok, fail) => {
|
|
11904
|
+
img.onload = ok;
|
|
11905
|
+
img.onerror = () => fail(new Error("the picture did not render"));
|
|
11906
|
+
img.src = url;
|
|
11907
|
+
});
|
|
11908
|
+
const canvas = document.createElement("canvas");
|
|
11909
|
+
canvas.width = w * scale;
|
|
11910
|
+
canvas.height = total * scale;
|
|
11911
|
+
const ctx = canvas.getContext("2d");
|
|
11912
|
+
ctx.scale(scale, scale);
|
|
11913
|
+
ctx.drawImage(img, 0, 0);
|
|
11914
|
+
const blob = await new Promise((ok) => canvas.toBlob(ok, "image/png"));
|
|
11915
|
+
const a = document.createElement("a");
|
|
11916
|
+
a.href = URL.createObjectURL(blob);
|
|
11917
|
+
a.download = `behold-${zoomValue()}${view.env ? "-" + view.env : ""}@${scale}x.png`;
|
|
11918
|
+
a.style.display = "none";
|
|
11919
|
+
document.body.appendChild(a);
|
|
11920
|
+
a.click();
|
|
11921
|
+
a.remove();
|
|
11922
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
|
11923
|
+
nowline(`↓ exported ${a.download}`);
|
|
11924
|
+
} catch (e) {
|
|
11925
|
+
nowline(`✗ export: ${e.message}`);
|
|
11926
|
+
} finally {
|
|
11927
|
+
URL.revokeObjectURL(url);
|
|
11928
|
+
}
|
|
11929
|
+
}
|
|
11930
|
+
|
|
10918
11931
|
// --- Command palette (⌘K / Ctrl+K, #73) -----------------------------------
|
|
10919
11932
|
// Ported from spicypath's FG-036 pattern (../spicypath/src/index.html: search
|
|
10920
11933
|
// `#palette`, `paletteCommands`, `openPalette`) — same shape (module-level
|
|
@@ -10951,6 +11964,10 @@ function paletteCommands() {
|
|
|
10951
11964
|
: ["Re-check live with plan (attribute drift) — pick an environment first", () => showToast("attribute drift is read from a plan, which needs an environment to plan against", false)],
|
|
10952
11965
|
);
|
|
10953
11966
|
}
|
|
11967
|
+
// #910: a stock Terraform root's plan, through chant, onto its cards.
|
|
11968
|
+
if (!staticMode && !publicMode && !view.env && projectInfo && (projectInfo.memberKinds || []).includes("terraform")) {
|
|
11969
|
+
c.push(["Read the plan on the Terraform roots (replaces, forcing attributes, unknowns, drift)", () => readTerraformPlan()]);
|
|
11970
|
+
}
|
|
10954
11971
|
c.push(["Fit graph to view", () => fitGraph()]);
|
|
10955
11972
|
c.push(["Export: current graph as SVG", () => exportSvg()]);
|
|
10956
11973
|
const inspectCollapsed = document.getElementById("app").classList.contains("inspect-collapsed");
|
|
@@ -10989,7 +12006,7 @@ function paletteCommands() {
|
|
|
10989
12006
|
const gate = mode === "drift" ? { available: true, reason: "" } : modeAvailability(lastMeta, mode);
|
|
10990
12007
|
const why = gate.available ? "" : ` — ${gate.reason}`;
|
|
10991
12008
|
c.push([
|
|
10992
|
-
`
|
|
12009
|
+
`color by: ${mode}${mode === activeColourMode() ? " ✓" : ""}${why}`,
|
|
10993
12010
|
() => {
|
|
10994
12011
|
if (!gate.available) return showToast(gate.reason, false);
|
|
10995
12012
|
setColourMode(mode);
|
|
@@ -11014,6 +12031,7 @@ function paletteCommands() {
|
|
|
11014
12031
|
if (!staticMode && !view.components && !view.ops) {
|
|
11015
12032
|
c.push([view.collapse ? "Expand all" : "Collapse large boxes", () => { view.collapse = !view.collapse; load(); }]);
|
|
11016
12033
|
}
|
|
12034
|
+
if (isEstate()) c.push([view.alike && alikeZoom() ? "Unstack alike cards" : "Stack alike cards", toggleAlike]);
|
|
11017
12035
|
|
|
11018
12036
|
// Env/stack/tier/target selection — replaces the old header pickers.
|
|
11019
12037
|
if (view.member) c.push([`member: whole estate (leave ${view.member})`, () => { view.member = null; selectedNodeId = null; renderStatusbar(); fitGraph(); }]);
|