d5-mermaid 0.3.1 → 0.3.2

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
@@ -12,6 +12,20 @@ function normalizeDirection(value) {
12
12
  return normalized === "LR" || normalized === "RL" || normalized === "TB" || normalized === "BT" ? normalized : null;
13
13
  }
14
14
  var DIRECTION_RE = /^\s*direction\s+(LR|RL|TB|TD|BT)\s*$/i;
15
+ function isAgainstFlow(direction, src, tgt) {
16
+ switch (direction) {
17
+ case "TB":
18
+ return tgt.y < src.y - 1;
19
+ case "BT":
20
+ return tgt.y > src.y + 1;
21
+ case "LR":
22
+ return tgt.x < src.x - 1;
23
+ case "RL":
24
+ return tgt.x > src.x + 1;
25
+ default:
26
+ return false;
27
+ }
28
+ }
15
29
 
16
30
  // src/d5-domain/db.ts
17
31
  var DEFAULT_DIRECTION = "TB";
@@ -1931,6 +1945,7 @@ function gridDimensions(count, cellWidth, gap, targetWidth) {
1931
1945
  }
1932
1946
 
1933
1947
  // src/d5-domain/renderer.ts
1948
+ var BACK_EDGE_TITLE = "Runs against the dominant flow \u2014 likely part of a dependency cycle among these subdomains.";
1934
1949
  var REL_LABEL_MAX_WIDTH = 150;
1935
1950
  var SVG_NS2 = "http://www.w3.org/2000/svg";
1936
1951
  var SUBDOMAIN_MIN_WIDTH = 180;
@@ -2118,6 +2133,7 @@ function render(db, container) {
2118
2133
  group.appendChild(typeText);
2119
2134
  container.appendChild(group);
2120
2135
  });
2136
+ let hasBackEdge = false;
2121
2137
  relationships.forEach((rel) => {
2122
2138
  const edge = g.edge(rel.source, rel.target);
2123
2139
  if (!edge || !edge.points || edge.points.length === 0) return;
@@ -2127,9 +2143,15 @@ function render(db, container) {
2127
2143
  }));
2128
2144
  const srcNode = g.node(rel.source);
2129
2145
  const tgtNode = g.node(rel.target);
2130
- const isBackEdge = !!srcNode && !!tgtNode && tgtNode.y < srcNode.y - 1;
2146
+ const isBackEdge = !!srcNode && !!tgtNode && isAgainstFlow(direction, srcNode, tgtNode);
2147
+ if (isBackEdge) hasBackEdge = true;
2131
2148
  const group = document.createElementNS(SVG_NS2, "g");
2132
2149
  group.setAttribute("class", isBackEdge ? "d5-rel d5-rel-back" : "d5-rel");
2150
+ if (isBackEdge) {
2151
+ const titleEl = document.createElementNS(SVG_NS2, "title");
2152
+ titleEl.textContent = BACK_EDGE_TITLE;
2153
+ group.appendChild(titleEl);
2154
+ }
2133
2155
  const pathString = generateCurvePath(shiftedPoints);
2134
2156
  const path = document.createElementNS(SVG_NS2, "path");
2135
2157
  path.setAttribute("d", pathString);
@@ -2181,6 +2203,26 @@ function render(db, container) {
2181
2203
  legendGroup.appendChild(label);
2182
2204
  legendX += 90;
2183
2205
  });
2206
+ if (hasBackEdge) {
2207
+ const swatchY = legendY + 7;
2208
+ const line = document.createElementNS(SVG_NS2, "line");
2209
+ line.setAttribute("x1", String(legendX));
2210
+ line.setAttribute("y1", String(swatchY));
2211
+ line.setAttribute("x2", String(legendX + 14));
2212
+ line.setAttribute("y2", String(swatchY));
2213
+ line.setAttribute("stroke", "#94a3b8");
2214
+ line.setAttribute("stroke-width", "1.5");
2215
+ line.setAttribute("stroke-dasharray", "6 4");
2216
+ legendGroup.appendChild(line);
2217
+ const label = document.createElementNS(SVG_NS2, "text");
2218
+ label.setAttribute("x", String(legendX + 20));
2219
+ label.setAttribute("y", String(legendY + 11));
2220
+ label.setAttribute("font-size", "11");
2221
+ label.setAttribute("fill", "#64748b");
2222
+ label.textContent = "Reverse dependency (cycle)";
2223
+ legendGroup.appendChild(label);
2224
+ legendX += 170;
2225
+ }
2184
2226
  container.appendChild(legendGroup);
2185
2227
  }
2186
2228
 
package/dist/index.js CHANGED
@@ -10,6 +10,20 @@ function normalizeDirection(value) {
10
10
  return normalized === "LR" || normalized === "RL" || normalized === "TB" || normalized === "BT" ? normalized : null;
11
11
  }
12
12
  var DIRECTION_RE = /^\s*direction\s+(LR|RL|TB|TD|BT)\s*$/i;
13
+ function isAgainstFlow(direction, src, tgt) {
14
+ switch (direction) {
15
+ case "TB":
16
+ return tgt.y < src.y - 1;
17
+ case "BT":
18
+ return tgt.y > src.y + 1;
19
+ case "LR":
20
+ return tgt.x < src.x - 1;
21
+ case "RL":
22
+ return tgt.x > src.x + 1;
23
+ default:
24
+ return false;
25
+ }
26
+ }
13
27
 
14
28
  // src/d5-domain/db.ts
15
29
  var DEFAULT_DIRECTION = "TB";
@@ -1929,6 +1943,7 @@ function gridDimensions(count, cellWidth, gap, targetWidth) {
1929
1943
  }
1930
1944
 
1931
1945
  // src/d5-domain/renderer.ts
1946
+ var BACK_EDGE_TITLE = "Runs against the dominant flow \u2014 likely part of a dependency cycle among these subdomains.";
1932
1947
  var REL_LABEL_MAX_WIDTH = 150;
1933
1948
  var SVG_NS2 = "http://www.w3.org/2000/svg";
1934
1949
  var SUBDOMAIN_MIN_WIDTH = 180;
@@ -2116,6 +2131,7 @@ function render(db, container) {
2116
2131
  group.appendChild(typeText);
2117
2132
  container.appendChild(group);
2118
2133
  });
2134
+ let hasBackEdge = false;
2119
2135
  relationships.forEach((rel) => {
2120
2136
  const edge = g.edge(rel.source, rel.target);
2121
2137
  if (!edge || !edge.points || edge.points.length === 0) return;
@@ -2125,9 +2141,15 @@ function render(db, container) {
2125
2141
  }));
2126
2142
  const srcNode = g.node(rel.source);
2127
2143
  const tgtNode = g.node(rel.target);
2128
- const isBackEdge = !!srcNode && !!tgtNode && tgtNode.y < srcNode.y - 1;
2144
+ const isBackEdge = !!srcNode && !!tgtNode && isAgainstFlow(direction, srcNode, tgtNode);
2145
+ if (isBackEdge) hasBackEdge = true;
2129
2146
  const group = document.createElementNS(SVG_NS2, "g");
2130
2147
  group.setAttribute("class", isBackEdge ? "d5-rel d5-rel-back" : "d5-rel");
2148
+ if (isBackEdge) {
2149
+ const titleEl = document.createElementNS(SVG_NS2, "title");
2150
+ titleEl.textContent = BACK_EDGE_TITLE;
2151
+ group.appendChild(titleEl);
2152
+ }
2131
2153
  const pathString = generateCurvePath(shiftedPoints);
2132
2154
  const path = document.createElementNS(SVG_NS2, "path");
2133
2155
  path.setAttribute("d", pathString);
@@ -2179,6 +2201,26 @@ function render(db, container) {
2179
2201
  legendGroup.appendChild(label);
2180
2202
  legendX += 90;
2181
2203
  });
2204
+ if (hasBackEdge) {
2205
+ const swatchY = legendY + 7;
2206
+ const line = document.createElementNS(SVG_NS2, "line");
2207
+ line.setAttribute("x1", String(legendX));
2208
+ line.setAttribute("y1", String(swatchY));
2209
+ line.setAttribute("x2", String(legendX + 14));
2210
+ line.setAttribute("y2", String(swatchY));
2211
+ line.setAttribute("stroke", "#94a3b8");
2212
+ line.setAttribute("stroke-width", "1.5");
2213
+ line.setAttribute("stroke-dasharray", "6 4");
2214
+ legendGroup.appendChild(line);
2215
+ const label = document.createElementNS(SVG_NS2, "text");
2216
+ label.setAttribute("x", String(legendX + 20));
2217
+ label.setAttribute("y", String(legendY + 11));
2218
+ label.setAttribute("font-size", "11");
2219
+ label.setAttribute("fill", "#64748b");
2220
+ label.textContent = "Reverse dependency (cycle)";
2221
+ legendGroup.appendChild(label);
2222
+ legendX += 170;
2223
+ }
2182
2224
  container.appendChild(legendGroup);
2183
2225
  }
2184
2226
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d5-mermaid",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Mermaid.js extension for D5 (Domain Driven Design Definitive Diagrams) — visualize DDD strategic and tactical patterns",
5
5
  "type": "module",
6
6
  "repository": {