{
  "version": 3,
  "sources": ["../../../src/rendering-util/layout-algorithms/ddlt/captureContract.ts", "../../../src/rendering-util/layout-algorithms/ddlt/sizeCapture.ts"],
  "sourcesContent": ["export const DDLT_SIZE_CAPTURE_VERSION = 1;\n\n/** The `.sizes.json` id of an edge's centre label, as `createEdgeLabelNodes` names it. */\nexport function edgeLabelFixtureId(edge: { start?: string; end?: string; id: string }): string {\n  return `edge-label-${edge.start}-${edge.end}-${edge.id}`;\n}\n\n/** The `.sizes.json` id of a subgraph's measured title (its `labelBBox`). */\nexport function groupTitleFixtureId(group: { id: string }): string {\n  return `group-title-${group.id}`;\n}\n", "import type { Selection } from 'd3';\nimport type { LayoutData } from '../../types.js';\nimport {\n  DDLT_SIZE_CAPTURE_VERSION,\n  edgeLabelFixtureId,\n  groupTitleFixtureId,\n} from './captureContract.js';\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// DDLT size capture (dev / test tooling \u2014 NOT part of production rendering)\n//\n// This module is dynamically imported by createGraphWithElements ONLY when\n// `window.mermaidCaptureSizes` is set, so it is never bundled into a production\n// render path (it lands in a lazily-loaded chunk instead).\n//\n// When enabled, it records the measured bounding-box dimensions of every leaf\n// node and edge-label dummy node, matching the `.sizes.json` fixture format used\n// by DOM-Decoupled Layout Testing (see\n// e2e/platform/dev-diagrams/layout-tests/*.sizes.json).\n//\n// Toggle from the browser devtools:\n//\n//   window.mermaidCaptureSizes = true;   // enable\n//   window.mermaidCaptureSizes = false;  // disable\n//\n// Each diagram rendered while enabled updates `window.mermaidLastCapturedSizes`\n// and is also appended to `window.mermaidCapturedSizes` (an array) for\n// programmatic access from dev-explorer or test tooling.\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\ntype D3Selection<T extends SVGElement = SVGElement> = Selection<\n  T,\n  unknown,\n  Element | null,\n  unknown\n>;\n\ninterface CapturedNodeSize {\n  id: string;\n  width: number;\n  height: number;\n}\n\ninterface CapturedSizesMetadata {\n  captureVersion: number;\n  capturedAt: string;\n  capturedFrom: string;\n}\n\ninterface CapturedSizes {\n  nodes: CapturedNodeSize[];\n  metadata: CapturedSizesMetadata;\n}\n\ninterface CapturedEntry {\n  svgId: string;\n  sizes: CapturedSizes;\n}\n\ninterface CaptureGlobal {\n  mermaidCaptureSizes?: boolean;\n  mermaidCapturedSizes?: CapturedEntry[];\n  mermaidLastCapturedSizes?: CapturedEntry;\n}\n\nfunction getCaptureGlobal(): CaptureGlobal | undefined {\n  if (typeof globalThis === 'undefined') {\n    return undefined;\n  }\n  return globalThis as unknown as CaptureGlobal;\n}\n\n/**\n * Whether DDLT size capture is enabled. Kept here so callers can avoid importing\n * this module at all in production \u2014 the createGraph guard reads the raw\n * `globalThis.mermaidCaptureSizes` flag directly and only dynamically imports\n * this module when it is truthy.\n */\nexport function shouldCaptureSizes(): boolean {\n  return Boolean(getCaptureGlobal()?.mermaidCaptureSizes);\n}\n\nfunction capturedFromLocation(): string {\n  if (typeof location === 'undefined') {\n    return 'browser-dev';\n  }\n  return `${location.pathname}${location.search}`;\n}\n\nfunction emitCapturedSizes(captured: CapturedSizes, element: D3Selection): void {\n  const g = getCaptureGlobal();\n  if (!g) {\n    return;\n  }\n\n  // Identify the owning SVG so captures can be told apart when a page\n  // renders many diagrams (e.g. knsv3.html).\n  const domNode = element.node();\n  const ownerSvg =\n    (domNode && 'ownerSVGElement' in domNode ? domNode.ownerSVGElement : null) ?? domNode;\n  const svgId = ownerSvg?.id ?? '(unknown)';\n\n  // `mermaidCapturedSizes` accumulates one entry per captured render and is never\n  // trimmed; in a long dev session, `delete window.mermaidCapturedSizes` to reset it.\n  g.mermaidCapturedSizes ??= [];\n  const entry = { svgId, sizes: captured };\n  g.mermaidCapturedSizes.push(entry);\n  g.mermaidLastCapturedSizes = entry;\n}\n\n/**\n * Record the measured sizes of every leaf + edge-label node, centre edge label and subgraph\n * title from an\n * already-laid-out {@link LayoutData} into `window.mermaidCapturedSizes`.\n *\n * Reads `node.width`/`node.height` set by createGraphWithElements during\n * measurement, so the capture lives entirely outside the production render path.\n *\n * @param element - The container the diagram was rendered into.\n * @param data4Layout - Layout data whose nodes have been measured.\n */\nexport function captureNodeSizes(element: D3Selection, data4Layout: LayoutData): void {\n  const nodes: CapturedNodeSize[] = [];\n  for (const node of data4Layout.nodes) {\n    if (node.isGroup) {\n      continue;\n    }\n    nodes.push({ id: node.id, width: node.width ?? 0, height: node.height ?? 0 });\n  }\n  // Centre labels measured on the edge itself (`insertEdgeLabel`), for layouts that do not turn\n  // them into `edge-label-*` nodes. A label already measured as a node keeps that entry.\n  const seen = new Set(nodes.map((n) => n.id));\n  for (const edge of data4Layout.edges) {\n    const label = typeof edge.label === 'string' ? edge.label.trim() : edge.label;\n    const id = edgeLabelFixtureId(edge);\n    if (!label || seen.has(id) || !(typeof edge.width === 'number')) {\n      continue;\n    }\n    seen.add(id);\n    nodes.push({ id, width: edge.width, height: edge.height ?? 0 });\n  }\n  // Subgraph titles (`measureGroupLabel`), which size the band above a group's content.\n  for (const node of data4Layout.nodes) {\n    if (node.isGroup && node.labelBBox) {\n      nodes.push({\n        id: groupTitleFixtureId(node),\n        width: node.labelBBox.width,\n        height: node.labelBBox.height,\n      });\n    }\n  }\n  if (nodes.length === 0) {\n    return;\n  }\n  emitCapturedSizes(\n    {\n      metadata: {\n        captureVersion: DDLT_SIZE_CAPTURE_VERSION,\n        capturedAt: new Date().toISOString(),\n        capturedFrom: capturedFromLocation(),\n      },\n      nodes,\n    },\n    element\n  );\n}\n"],
  "mappings": ";;;;;AAAO,IAAM,4BAA4B;AAGlC,SAAS,mBAAmB,MAA4D;AAC7F,SAAO,cAAc,KAAK,KAAK,IAAI,KAAK,GAAG,IAAI,KAAK,EAAE;AACxD;AAFgB;AAKT,SAAS,oBAAoB,OAA+B;AACjE,SAAO,eAAe,MAAM,EAAE;AAChC;AAFgB;;;ACyDhB,SAAS,mBAA8C;AACrD,MAAI,OAAO,eAAe,aAAa;AACrC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AALS;AAaF,SAAS,qBAA8B;AAC5C,SAAO,QAAQ,iBAAiB,GAAG,mBAAmB;AACxD;AAFgB;AAIhB,SAAS,uBAA+B;AACtC,MAAI,OAAO,aAAa,aAAa;AACnC,WAAO;AAAA,EACT;AACA,SAAO,GAAG,SAAS,QAAQ,GAAG,SAAS,MAAM;AAC/C;AALS;AAOT,SAAS,kBAAkB,UAAyB,SAA4B;AAC9E,QAAM,IAAI,iBAAiB;AAC3B,MAAI,CAAC,GAAG;AACN;AAAA,EACF;AAIA,QAAM,UAAU,QAAQ,KAAK;AAC7B,QAAM,YACH,WAAW,qBAAqB,UAAU,QAAQ,kBAAkB,SAAS;AAChF,QAAM,QAAQ,UAAU,MAAM;AAI9B,IAAE,yBAAyB,CAAC;AAC5B,QAAM,QAAQ,EAAE,OAAO,OAAO,SAAS;AACvC,IAAE,qBAAqB,KAAK,KAAK;AACjC,IAAE,2BAA2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