@diagrammo/dgmo 0.4.3 → 0.4.4

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/dist/index.cjs CHANGED
@@ -7212,7 +7212,7 @@ var init_parser9 = __esm({
7212
7212
  TAG_GROUP_RE = /^tag\s*:\s*(\w[\w\s]*?)(?:\s+alias\s+(\w+))?\s*$/;
7213
7213
  TAG_VALUE_RE = /^(\w[\w\s]*?)(?:\(([^)]+)\))?(\s+default)?\s*$/;
7214
7214
  COMPONENT_RE = /^([a-zA-Z_][\w]*)(.*)$/;
7215
- PIPE_META_RE = /\|\s*(\w+)\s*:\s*([^|]+)/g;
7215
+ PIPE_META_RE = /[|,]\s*(\w+)\s*:\s*([^|,]+)/g;
7216
7216
  PROPERTY_RE = /^([\w-]+)\s*:\s*(.+)$/;
7217
7217
  PERCENT_RE = /^([\d.]+)%$/;
7218
7218
  RANGE_RE = /^(\d+)-(\d+)$/;
@@ -15036,7 +15036,7 @@ function formatUptime(fraction) {
15036
15036
  if (pct >= 99) return `${pct.toFixed(1)}%`;
15037
15037
  return `${pct.toFixed(1)}%`;
15038
15038
  }
15039
- function layoutInfra(computed, selectedNodeId) {
15039
+ function layoutInfra(computed, selectedNodeId, collapsedNodes) {
15040
15040
  if (computed.nodes.length === 0) {
15041
15041
  return { nodes: [], edges: [], groups: [], options: {}, width: 0, height: 0 };
15042
15042
  }
@@ -15057,9 +15057,10 @@ function layoutInfra(computed, selectedNodeId) {
15057
15057
  const widthMap = /* @__PURE__ */ new Map();
15058
15058
  const heightMap = /* @__PURE__ */ new Map();
15059
15059
  for (const node of computed.nodes) {
15060
- const expanded = node.id === selectedNodeId;
15060
+ const isNodeCollapsed = collapsedNodes?.has(node.id) ?? false;
15061
+ const expanded = !isNodeCollapsed && node.id === selectedNodeId;
15061
15062
  const width = computeNodeWidth2(node, expanded, computed.options);
15062
- const height = computeNodeHeight2(node, expanded, computed.options);
15063
+ const height = isNodeCollapsed ? NODE_HEADER_HEIGHT + NODE_PAD_BOTTOM : computeNodeHeight2(node, expanded, computed.options);
15063
15064
  widthMap.set(node.id, width);
15064
15065
  heightMap.set(node.id, height);
15065
15066
  const inGroup = groupedNodeIds.has(node.id);
@@ -15632,10 +15633,27 @@ function renderEdgeLabels(svg, edges, palette, isDark, animate) {
15632
15633
  }
15633
15634
  }
15634
15635
  }
15635
- function renderNodes(svg, nodes, palette, isDark, animate, selectedNodeId, activeGroup, diagramOptions) {
15636
+ function resolveActiveTagStroke(node, activeGroup, tagGroups, palette) {
15637
+ const tg = tagGroups.find((t) => t.name.toLowerCase() === activeGroup.toLowerCase());
15638
+ if (!tg) return null;
15639
+ const tagKey = (tg.alias ?? tg.name).toLowerCase();
15640
+ const tagVal = node.tags[tagKey];
15641
+ if (!tagVal) return null;
15642
+ const tv = tg.values.find((v) => v.name.toLowerCase() === tagVal.toLowerCase());
15643
+ if (!tv?.color) return null;
15644
+ return resolveColor(tv.color, palette);
15645
+ }
15646
+ function renderNodes(svg, nodes, palette, isDark, animate, selectedNodeId, activeGroup, diagramOptions, collapsedNodes, tagGroups) {
15636
15647
  const mutedColor = palette.textMuted;
15637
15648
  for (const node of nodes) {
15638
- const { fill: fill2, stroke: stroke2, textFill } = nodeColor(node, palette, isDark);
15649
+ let { fill: fill2, stroke: stroke2, textFill } = nodeColor(node, palette, isDark);
15650
+ if (activeGroup && tagGroups && !node.isEdge) {
15651
+ const tagStroke = resolveActiveTagStroke(node, activeGroup, tagGroups, palette);
15652
+ if (tagStroke) {
15653
+ stroke2 = tagStroke;
15654
+ fill2 = mix(palette.bg, tagStroke, isDark ? 88 : 94);
15655
+ }
15656
+ }
15639
15657
  let cls = "infra-node";
15640
15658
  if (animate && node.isEdge) {
15641
15659
  cls += " infra-node-edge-throb";
@@ -15645,9 +15663,9 @@ function renderNodes(svg, nodes, palette, isDark, animate, selectedNodeId, activ
15645
15663
  else if (severity === "overloaded") cls += " infra-node-overload";
15646
15664
  else if (severity === "warning") cls += " infra-node-warning";
15647
15665
  }
15648
- const g = svg.append("g").attr("class", cls).attr("data-line-number", node.lineNumber).attr("data-infra-node", node.id);
15666
+ const g = svg.append("g").attr("class", cls).attr("data-line-number", node.lineNumber).attr("data-infra-node", node.id).attr("data-node-collapse", node.id).style("cursor", "pointer");
15649
15667
  if (node.id.startsWith("[")) {
15650
- g.attr("data-node-toggle", node.id).style("cursor", "pointer");
15668
+ g.attr("data-node-toggle", node.id);
15651
15669
  }
15652
15670
  for (const [tagKey, tagVal] of Object.entries(node.tags)) {
15653
15671
  g.attr(`data-tag-${tagKey.toLowerCase()}`, tagVal.toLowerCase());
@@ -15665,7 +15683,12 @@ function renderNodes(svg, nodes, palette, isDark, animate, selectedNodeId, activ
15665
15683
  g.append("rect").attr("x", x).attr("y", y).attr("width", node.width).attr("height", node.height).attr("rx", NODE_BORDER_RADIUS).attr("fill", fill2).attr("stroke", stroke2).attr("stroke-width", strokeWidth);
15666
15684
  const headerCenterY = y + NODE_HEADER_HEIGHT2 / 2 + NODE_FONT_SIZE3 * 0.35;
15667
15685
  g.append("text").attr("x", node.x).attr("y", headerCenterY).attr("text-anchor", "middle").attr("font-family", FONT_FAMILY).attr("font-size", NODE_FONT_SIZE3).attr("font-weight", "600").attr("fill", textFill).text(node.label);
15668
- {
15686
+ const isNodeCollapsed = collapsedNodes?.has(node.id) ?? false;
15687
+ if (isNodeCollapsed) {
15688
+ const chevronY = y + node.height - 6;
15689
+ g.append("text").attr("x", node.x).attr("y", chevronY).attr("text-anchor", "middle").attr("font-family", FONT_FAMILY).attr("font-size", 8).attr("fill", textFill).attr("opacity", 0.5).text("\u25BC");
15690
+ }
15691
+ if (!isNodeCollapsed) {
15669
15692
  const expanded = node.id === selectedNodeId;
15670
15693
  const displayProps = !node.isEdge && expanded ? getDisplayProps(node, expanded, diagramOptions) : [];
15671
15694
  const computedRows = getComputedRows(node, expanded);
@@ -15988,7 +16011,7 @@ function renderLegend3(rootSvg, legendGroups, totalWidth, legendY, palette, isDa
15988
16011
  cursorX += fullW + LEGEND_GROUP_GAP5;
15989
16012
  }
15990
16013
  }
15991
- function renderInfra(container, layout, palette, isDark, title, titleLineNumber, tagGroups, activeGroup, animate, playback, selectedNodeId, exportMode) {
16014
+ function renderInfra(container, layout, palette, isDark, title, titleLineNumber, tagGroups, activeGroup, animate, playback, selectedNodeId, exportMode, collapsedNodes) {
15992
16015
  d3Selection9.select(container).selectAll(":not([data-d3-tooltip])").remove();
15993
16016
  const legendGroups = computeInfraLegendGroups(layout.nodes, tagGroups ?? [], palette);
15994
16017
  const hasLegend = legendGroups.length > 0 || !!playback;
@@ -16047,7 +16070,7 @@ function renderInfra(container, layout, palette, isDark, title, titleLineNumber,
16047
16070
  }
16048
16071
  renderGroups(svg, layout.groups, palette, isDark);
16049
16072
  renderEdgePaths(svg, layout.edges, layout.nodes, palette, isDark, shouldAnimate);
16050
- renderNodes(svg, layout.nodes, palette, isDark, shouldAnimate, selectedNodeId, activeGroup, layout.options);
16073
+ renderNodes(svg, layout.nodes, palette, isDark, shouldAnimate, selectedNodeId, activeGroup, layout.options, collapsedNodes, tagGroups ?? []);
16051
16074
  if (shouldAnimate) {
16052
16075
  renderRejectParticles(svg, layout.nodes);
16053
16076
  }
@@ -21784,6 +21807,9 @@ function encodeDiagramUrl(dsl, options) {
21784
21807
  if (options?.viewState?.activeTagGroup) {
21785
21808
  hash += `&tag=${encodeURIComponent(options.viewState.activeTagGroup)}`;
21786
21809
  }
21810
+ if (options?.viewState?.collapsedGroups?.length) {
21811
+ hash += `&cg=${encodeURIComponent(options.viewState.collapsedGroups.join(","))}`;
21812
+ }
21787
21813
  return { url: `${baseUrl}?${hash}#${hash}` };
21788
21814
  }
21789
21815
  function decodeDiagramUrl(hash) {
@@ -21804,6 +21830,9 @@ function decodeDiagramUrl(hash) {
21804
21830
  if (key === "tag" && val) {
21805
21831
  viewState.activeTagGroup = val;
21806
21832
  }
21833
+ if (key === "cg" && val) {
21834
+ viewState.collapsedGroups = val.split(",").filter(Boolean);
21835
+ }
21807
21836
  }
21808
21837
  if (payload.startsWith("dgmo=")) {
21809
21838
  payload = payload.slice(5);