mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
96 lines (93 loc) • 2.78 kB
JavaScript
import {
__name
} from "./chunk-42YUCIBL.mjs";
// src/rendering-util/layout-algorithms/ddlt/captureContract.ts
var DDLT_SIZE_CAPTURE_VERSION = 1;
function edgeLabelFixtureId(edge) {
return `edge-label-${edge.start}-${edge.end}-${edge.id}`;
}
__name(edgeLabelFixtureId, "edgeLabelFixtureId");
function groupTitleFixtureId(group) {
return `group-title-${group.id}`;
}
__name(groupTitleFixtureId, "groupTitleFixtureId");
// src/rendering-util/layout-algorithms/ddlt/sizeCapture.ts
function getCaptureGlobal() {
if (typeof globalThis === "undefined") {
return void 0;
}
return globalThis;
}
__name(getCaptureGlobal, "getCaptureGlobal");
function shouldCaptureSizes() {
return Boolean(getCaptureGlobal()?.mermaidCaptureSizes);
}
__name(shouldCaptureSizes, "shouldCaptureSizes");
function capturedFromLocation() {
if (typeof location === "undefined") {
return "browser-dev";
}
return `${location.pathname}${location.search}`;
}
__name(capturedFromLocation, "capturedFromLocation");
function emitCapturedSizes(captured, element) {
const g = getCaptureGlobal();
if (!g) {
return;
}
const domNode = element.node();
const ownerSvg = (domNode && "ownerSVGElement" in domNode ? domNode.ownerSVGElement : null) ?? domNode;
const svgId = ownerSvg?.id ?? "(unknown)";
g.mermaidCapturedSizes ??= [];
const entry = { svgId, sizes: captured };
g.mermaidCapturedSizes.push(entry);
g.mermaidLastCapturedSizes = entry;
}
__name(emitCapturedSizes, "emitCapturedSizes");
function captureNodeSizes(element, data4Layout) {
const nodes = [];
for (const node of data4Layout.nodes) {
if (node.isGroup) {
continue;
}
nodes.push({ id: node.id, width: node.width ?? 0, height: node.height ?? 0 });
}
const seen = new Set(nodes.map((n) => n.id));
for (const edge of data4Layout.edges) {
const label = typeof edge.label === "string" ? edge.label.trim() : edge.label;
const id = edgeLabelFixtureId(edge);
if (!label || seen.has(id) || !(typeof edge.width === "number")) {
continue;
}
seen.add(id);
nodes.push({ id, width: edge.width, height: edge.height ?? 0 });
}
for (const node of data4Layout.nodes) {
if (node.isGroup && node.labelBBox) {
nodes.push({
id: groupTitleFixtureId(node),
width: node.labelBBox.width,
height: node.labelBBox.height
});
}
}
if (nodes.length === 0) {
return;
}
emitCapturedSizes(
{
metadata: {
captureVersion: DDLT_SIZE_CAPTURE_VERSION,
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
capturedFrom: capturedFromLocation()
},
nodes
},
element
);
}
__name(captureNodeSizes, "captureNodeSizes");
export {
captureNodeSizes,
shouldCaptureSizes
};