@markdy/renderer-dom 1.3.3 → 1.4.1

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.d.ts CHANGED
@@ -142,10 +142,15 @@ interface DiagramOptions {
142
142
  */
143
143
  fitMode?: "width" | "contain";
144
144
  /**
145
- * Target container width fill fraction (0.95 - 1.0) when fitMode is "width".
146
- * Defaults to 0.98 (edge-to-edge with 1% clean margins).
145
+ * Target container width fill fraction (0.90 - 1.0) when fitMode is "width".
146
+ * Defaults to 0.96 (clean edge-to-edge framing with comfortable 2% safe margins).
147
147
  */
148
148
  targetWidthRatio?: number;
149
+ /**
150
+ * Custom safe clearance padding in px around diagram elements.
151
+ * Defaults to 28px for grouped diagrams and 22px for ungrouped diagrams.
152
+ */
153
+ contentPadding?: number;
149
154
  }
150
155
  interface Diagram {
151
156
  play(): void;
package/dist/index.js CHANGED
@@ -230,7 +230,7 @@ function wrapFlowLabelText(text, maxAvailableWidth) {
230
230
  const CHAR_WIDTH = 6.6;
231
231
  const PAD = 8;
232
232
  const singleLineWidth = text.length * CHAR_WIDTH + PAD;
233
- if (singleLineWidth <= maxAvailableWidth || text.length <= 18 || !text.includes(" ")) {
233
+ if (singleLineWidth <= maxAvailableWidth || maxAvailableWidth >= 70 && text.length <= 18 || !text.includes(" ")) {
234
234
  return [text];
235
235
  }
236
236
  const words = text.trim().split(/\s+/);
@@ -651,6 +651,53 @@ function routeOrthogonal(sourceRect, targetRect, obstacles, bounds, lane = 0) {
651
651
  }
652
652
  return cleanCollinearPoints(best.map((p) => clampPointToScene(p, bounds)));
653
653
  }
654
+ function routeTreeEdgePoints(from, to, lane, isVertical, bounds) {
655
+ if (to.y < from.y + from.height - 12) return null;
656
+ if (isVertical) {
657
+ if (to.x < from.x - 4) return null;
658
+ if (Math.abs(to.x - from.x) < 4) {
659
+ const pX = round1(from.x + from.width / 2);
660
+ const cX = round1(to.x + to.width / 2);
661
+ return cleanCollinearPoints([
662
+ { x: pX, y: from.y + from.height },
663
+ { x: cX, y: to.y }
664
+ ].map((p) => clampPointToScene(p, bounds)));
665
+ }
666
+ const trunkBaseX = Math.round((from.x + 18) / 4) * 4;
667
+ const maxShift = Math.max(0, Math.min(16, (to.x - from.x) / 3));
668
+ const shift = lane === 0 ? 0 : -Math.min(maxShift, lane * 4);
669
+ const trunkX = trunkBaseX + shift;
670
+ const fromY = from.y + from.height;
671
+ const toY = round1(to.y + to.height / 2);
672
+ const raw = [
673
+ { x: trunkX, y: fromY },
674
+ { x: trunkX, y: toY },
675
+ { x: to.x, y: toY }
676
+ ];
677
+ return cleanCollinearPoints(raw.map((p) => clampPointToScene(p, bounds)));
678
+ } else {
679
+ const pX = round1(from.x + from.width / 2);
680
+ const pY = from.y + from.height;
681
+ const cX = round1(to.x + to.width / 2);
682
+ const cY = to.y;
683
+ if (Math.abs(pX - cX) < 2) {
684
+ return cleanCollinearPoints([
685
+ { x: pX, y: pY },
686
+ { x: cX, y: cY }
687
+ ].map((p) => clampPointToScene(p, bounds)));
688
+ }
689
+ const branchY = round1((pY + cY) / 2);
690
+ const laneShift = lane === 0 ? 0 : (lane % 2 === 1 ? 1 : -1) * Math.ceil(lane / 2) * 5;
691
+ const midY = round1(branchY + laneShift);
692
+ const raw = [
693
+ { x: pX, y: pY },
694
+ { x: pX, y: midY },
695
+ { x: cX, y: midY },
696
+ { x: cX, y: cY }
697
+ ];
698
+ return cleanCollinearPoints(raw.map((p) => clampPointToScene(p, bounds)));
699
+ }
700
+ }
654
701
 
655
702
  // src/edges.ts
656
703
  var EDGE_LAYER_ATTR = "data-markdy-edge-layer";
@@ -687,6 +734,16 @@ function circleBoundaryRoute(from, to) {
687
734
  const uy = dy / distance;
688
735
  const fromRadius = Math.min(from.width, from.height) / 2;
689
736
  const toRadius = Math.min(to.width, to.height) / 2;
737
+ if (distance < fromRadius + toRadius) {
738
+ const midX = (fromCenter.x + toCenter.x) / 2;
739
+ const midY = (fromCenter.y + toCenter.y) / 2;
740
+ const overlap = fromRadius + toRadius - distance;
741
+ const halfSpan = Math.max(24, Math.min(64, overlap * 0.5));
742
+ return dedupePoints([
743
+ { x: midX - ux * halfSpan, y: midY - uy * halfSpan },
744
+ { x: midX + ux * halfSpan, y: midY + uy * halfSpan }
745
+ ]);
746
+ }
690
747
  return dedupePoints([
691
748
  { x: fromCenter.x + ux * fromRadius, y: fromCenter.y + uy * fromRadius },
692
749
  { x: toCenter.x - ux * toRadius, y: toCenter.y - uy * toRadius }
@@ -745,8 +802,12 @@ function snapRouteEndpointsToShapes(points, from, to) {
745
802
  out[out.length - 1] = snapPortToNodeShape(to, out[out.length - 1], out[out.length - 2], false);
746
803
  return dedupePoints(out);
747
804
  }
748
- function routeEdgePoints(from, to, routeObstacles, bounds, lane) {
805
+ function routeEdgePoints(from, to, routeObstacles, bounds, lane, diagramType = "architecture", isVerticalTree = false) {
749
806
  if (from.shape === "circle" && to.shape === "circle") return circleBoundaryRoute(from, to);
807
+ if (diagramType === "tree") {
808
+ const treeRoute = routeTreeEdgePoints(from, to, lane, isVerticalTree, bounds);
809
+ if (treeRoute) return snapRouteEndpointsToShapes(treeRoute, from, to);
810
+ }
750
811
  const raw = routeOrthogonal(boxRect(from), boxRect(to), routeObstacles, bounds, lane);
751
812
  return snapRouteEndpointsToShapes(raw, from, to);
752
813
  }
@@ -882,12 +943,12 @@ function computeEdgeLabelColor(edgeColor, isDark) {
882
943
  }
883
944
  return `color-mix(in srgb, ${edgeColor} 75%, #090d16)`;
884
945
  }
885
- function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObstacles, labelObstacles, bounds, lane, existingPaths = []) {
946
+ function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObstacles, labelObstacles, bounds, lane, existingPaths = [], diagramType = "architecture", isVerticalTree = false) {
886
947
  ensureDefs(svg, theme, sceneId);
887
948
  const color = theme.edges[kind] ?? theme.edges.request ?? theme.accent;
888
949
  const style = EDGE_STYLES[kind] ?? EDGE_STYLES.request;
889
950
  const isSelfLoop = from.id === to.id;
890
- const points = isSelfLoop ? dedupePoints(selfLoopPath(from, bounds)) : dedupePoints(routeEdgePoints(from, to, routeObstacles, bounds, lane));
951
+ const points = isSelfLoop ? dedupePoints(selfLoopPath(from, bounds)) : dedupePoints(routeEdgePoints(from, to, routeObstacles, bounds, lane, diagramType, isVerticalTree));
891
952
  const d = toPathD(points, 14, existingPaths);
892
953
  const len = polylineLength(points);
893
954
  const edgeId = `${from.id}_${to.id}`;
@@ -930,7 +991,8 @@ function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObst
930
991
  for (let i = 0; i < points.length - 1; i++) {
931
992
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
932
993
  }
933
- const maxAvailW = Math.max(48, longestSegLen - 24);
994
+ const isTreeVertical = diagramType === "tree" && isVerticalTree;
995
+ const maxAvailW = isTreeVertical ? Math.max(48, Math.min(68, longestSegLen - 12)) : Math.max(90, longestSegLen - 24);
934
996
  const lines = wrapFlowLabelText(label, maxAvailW);
935
997
  const maxChars = Math.max(...lines.map((l) => l.length));
936
998
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -1191,7 +1253,8 @@ function computeFrameTransform(targetIds, nodes, bounds, requestedZoom = DEFAULT
1191
1253
  const ty = Math.round((bounds.height / 2 - centerY * scale) * 10) / 10;
1192
1254
  return `translate(${tx}px, ${ty}px) scale(${Math.round(scale * 1e3) / 1e3})`;
1193
1255
  }
1194
- function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds, edges = [], edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture") {
1256
+ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds, edges = [], edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture", isVerticalTree) {
1257
+ const isVertical = isVerticalTree ?? bounds.height > bounds.width;
1195
1258
  const anims = [];
1196
1259
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
1197
1260
  const rectById = new Map(nodes.map((n) => [n.id, boxRect(n)]));
@@ -1227,7 +1290,9 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1227
1290
  [...allNodeRects, ...edgeLabels],
1228
1291
  bounds,
1229
1292
  lane,
1230
- placedPaths
1293
+ placedPaths,
1294
+ diagramType,
1295
+ isVertical
1231
1296
  );
1232
1297
  placedPaths.push(runtime.points);
1233
1298
  if (runtime.labelRect) edgeLabels.push(runtime.labelRect);
@@ -1376,7 +1441,9 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1376
1441
  labelObstacles,
1377
1442
  bounds,
1378
1443
  lane,
1379
- placedPaths
1444
+ placedPaths,
1445
+ diagramType,
1446
+ isVertical
1380
1447
  );
1381
1448
  placedPaths.push(runtime.points);
1382
1449
  if (runtime.labelRect) placedLabels.push(runtime.labelRect);
@@ -1426,7 +1493,8 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1426
1493
  for (const a of anims) a.pause();
1427
1494
  return anims;
1428
1495
  }
1429
- function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture", cues = []) {
1496
+ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeRuntimes = /* @__PURE__ */ new Map(), sceneId = createEdgeSceneId(), diagramType = "architecture", cues = [], isVerticalTree) {
1497
+ const isVertical = isVerticalTree ?? bounds.height > bounds.width;
1430
1498
  const structural = edges.filter(
1431
1499
  (e) => e.structural && diagramType !== "sequence" && !(diagramType === "tree" && !e.label)
1432
1500
  );
@@ -1481,7 +1549,9 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
1481
1549
  labelObstacles,
1482
1550
  bounds,
1483
1551
  lane,
1484
- placedPaths
1552
+ placedPaths,
1553
+ diagramType,
1554
+ isVertical
1485
1555
  );
1486
1556
  placedPaths.push(runtime.points);
1487
1557
  if (runtime.labelRect) placedLabels.push(runtime.labelRect);
@@ -1960,46 +2030,92 @@ function mountTimelineLayer(layer, nodes, theme, bounds) {
1960
2030
  layer.appendChild(svg);
1961
2031
  const SAFE = 40;
1962
2032
  const TITLE_BAND = 64;
1963
- const contentH = bounds.height - SAFE - TITLE_BAND - SAFE;
1964
- const baselineY = TITLE_BAND + contentH / 2;
1965
- const minX = Math.min(...nodes.map((n) => n.x)) - 20;
1966
- const maxX = Math.max(...nodes.map((n) => n.x + n.width)) + 20;
1967
2033
  const strokeAxis = theme?.edges?.dependency ?? theme?.rule ?? theme?.border ?? "#64748b";
1968
2034
  const strokeBorder = theme?.edges?.dependency ?? theme?.border ?? "#64748b";
1969
2035
  const accentColor = theme?.accent ?? "#38bdf8";
1970
2036
  const surfaceFill = theme?.surfaceRaised ?? theme?.surface ?? "#ffffff";
1971
- const axis = doc.createElementNS("http://www.w3.org/2000/svg", "line");
1972
- axis.setAttribute("x1", String(Math.max(40, minX)));
1973
- axis.setAttribute("y1", String(baselineY));
1974
- axis.setAttribute("x2", String(Math.min(bounds.width - 40, maxX)));
1975
- axis.setAttribute("y2", String(baselineY));
1976
- axis.setAttribute("stroke", strokeAxis);
1977
- axis.setAttribute("stroke-width", "2");
1978
- axis.setAttribute("stroke-linecap", "round");
1979
- axis.setAttribute("opacity", "0.75");
1980
- svg.appendChild(axis);
1981
- for (const node of nodes) {
1982
- const nodeCenterX = node.x + node.width / 2;
1983
- const isAbove = node.y + node.height <= baselineY + 10;
1984
- const targetY = isAbove ? node.y + node.height : node.y;
1985
- const stem = doc.createElementNS("http://www.w3.org/2000/svg", "line");
1986
- stem.setAttribute("x1", String(nodeCenterX));
1987
- stem.setAttribute("y1", String(baselineY));
1988
- stem.setAttribute("x2", String(nodeCenterX));
1989
- stem.setAttribute("y2", String(targetY));
1990
- stem.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
1991
- stem.setAttribute("stroke-width", node.focal ? "2" : "1.5");
1992
- stem.setAttribute("stroke-dasharray", node.focal ? "none" : "4 4");
1993
- stem.setAttribute("opacity", node.focal ? "0.95" : "0.75");
1994
- svg.appendChild(stem);
1995
- const pip = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
1996
- pip.setAttribute("cx", String(nodeCenterX));
1997
- pip.setAttribute("cy", String(baselineY));
1998
- pip.setAttribute("r", node.focal ? "5.5" : "4");
1999
- pip.setAttribute("fill", node.focal ? accentColor : surfaceFill);
2000
- pip.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2001
- pip.setAttribute("stroke-width", "2");
2002
- svg.appendChild(pip);
2037
+ const isVertical = bounds.height > bounds.width || nodes.length > 1 && Math.abs(nodes[1].y - nodes[0].y) > Math.abs(nodes[1].x - nodes[0].x);
2038
+ if (isVertical) {
2039
+ const centerX = bounds.width / 2;
2040
+ const minY = Math.min(...nodes.map((n) => n.y)) - 16;
2041
+ const maxY = Math.max(...nodes.map((n) => n.y + n.height)) + 16;
2042
+ const axis = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2043
+ axis.setAttribute("class", "markdy-timeline-axis");
2044
+ axis.setAttribute("x1", String(centerX));
2045
+ axis.setAttribute("y1", String(Math.max(SAFE, minY)));
2046
+ axis.setAttribute("x2", String(centerX));
2047
+ axis.setAttribute("y2", String(Math.min(bounds.height - SAFE, maxY)));
2048
+ axis.setAttribute("stroke", strokeAxis);
2049
+ axis.setAttribute("stroke-width", "2");
2050
+ axis.setAttribute("stroke-linecap", "round");
2051
+ axis.setAttribute("opacity", "0.75");
2052
+ svg.appendChild(axis);
2053
+ for (const node of nodes) {
2054
+ const nodeCenterY = node.y + node.height / 2;
2055
+ const isLeft = node.x + node.width / 2 < centerX;
2056
+ const targetX = isLeft ? node.x + node.width : node.x;
2057
+ const stem = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2058
+ stem.setAttribute("class", "markdy-timeline-stem");
2059
+ stem.setAttribute("x1", String(centerX));
2060
+ stem.setAttribute("y1", String(nodeCenterY));
2061
+ stem.setAttribute("x2", String(targetX));
2062
+ stem.setAttribute("y2", String(nodeCenterY));
2063
+ stem.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2064
+ stem.setAttribute("stroke-width", node.focal ? "2" : "1.5");
2065
+ stem.setAttribute("stroke-dasharray", node.focal ? "none" : "4 4");
2066
+ stem.setAttribute("opacity", node.focal ? "0.95" : "0.75");
2067
+ svg.appendChild(stem);
2068
+ const pip = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
2069
+ pip.setAttribute("class", "markdy-timeline-pip");
2070
+ pip.setAttribute("cx", String(centerX));
2071
+ pip.setAttribute("cy", String(nodeCenterY));
2072
+ pip.setAttribute("r", node.focal ? "5.5" : "4");
2073
+ pip.setAttribute("fill", node.focal ? accentColor : surfaceFill);
2074
+ pip.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2075
+ pip.setAttribute("stroke-width", "2");
2076
+ svg.appendChild(pip);
2077
+ }
2078
+ } else {
2079
+ const contentH = bounds.height - SAFE - TITLE_BAND - SAFE;
2080
+ const baselineY = TITLE_BAND + contentH / 2;
2081
+ const minX = Math.min(...nodes.map((n) => n.x)) - 20;
2082
+ const maxX = Math.max(...nodes.map((n) => n.x + n.width)) + 20;
2083
+ const axis = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2084
+ axis.setAttribute("class", "markdy-timeline-axis");
2085
+ axis.setAttribute("x1", String(Math.max(40, minX)));
2086
+ axis.setAttribute("y1", String(baselineY));
2087
+ axis.setAttribute("x2", String(Math.min(bounds.width - 40, maxX)));
2088
+ axis.setAttribute("y2", String(baselineY));
2089
+ axis.setAttribute("stroke", strokeAxis);
2090
+ axis.setAttribute("stroke-width", "2");
2091
+ axis.setAttribute("stroke-linecap", "round");
2092
+ axis.setAttribute("opacity", "0.75");
2093
+ svg.appendChild(axis);
2094
+ for (const node of nodes) {
2095
+ const nodeCenterX = node.x + node.width / 2;
2096
+ const isAbove = node.y + node.height <= baselineY + 10;
2097
+ const targetY = isAbove ? node.y + node.height : node.y;
2098
+ const stem = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2099
+ stem.setAttribute("class", "markdy-timeline-stem");
2100
+ stem.setAttribute("x1", String(nodeCenterX));
2101
+ stem.setAttribute("y1", String(baselineY));
2102
+ stem.setAttribute("x2", String(nodeCenterX));
2103
+ stem.setAttribute("y2", String(targetY));
2104
+ stem.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2105
+ stem.setAttribute("stroke-width", node.focal ? "2" : "1.5");
2106
+ stem.setAttribute("stroke-dasharray", node.focal ? "none" : "4 4");
2107
+ stem.setAttribute("opacity", node.focal ? "0.95" : "0.75");
2108
+ svg.appendChild(stem);
2109
+ const pip = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
2110
+ pip.setAttribute("class", "markdy-timeline-pip");
2111
+ pip.setAttribute("cx", String(nodeCenterX));
2112
+ pip.setAttribute("cy", String(baselineY));
2113
+ pip.setAttribute("r", node.focal ? "5.5" : "4");
2114
+ pip.setAttribute("fill", node.focal ? accentColor : surfaceFill);
2115
+ pip.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2116
+ pip.setAttribute("stroke-width", "2");
2117
+ svg.appendChild(pip);
2118
+ }
2003
2119
  }
2004
2120
  }
2005
2121
 
@@ -2164,27 +2280,30 @@ function ensureNodeStyles(doc) {
2164
2280
  box-sizing: border-box;
2165
2281
  }
2166
2282
  .markdy-node__icon {
2167
- flex: 0 0 28px;
2283
+ flex: 0 0 auto;
2168
2284
  width: 28px;
2169
2285
  height: 28px;
2170
- border-radius: 7px;
2171
- display: inline-flex;
2286
+ display: flex;
2172
2287
  align-items: center;
2173
2288
  justify-content: center;
2174
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 14%, transparent);
2289
+ background: transparent;
2290
+ box-shadow: none;
2175
2291
  color: var(--md-role-color, var(--md-accent));
2176
- box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-role-color, var(--md-accent)) 35%, transparent);
2177
2292
  transition: transform 0.2s ease;
2178
2293
  }
2179
2294
  .markdy-node__icon svg {
2180
- width: 18px;
2181
- height: 18px;
2295
+ width: 26px;
2296
+ height: 26px;
2297
+ display: block;
2182
2298
  stroke: currentColor;
2183
2299
  stroke-width: 1.8;
2184
2300
  fill: none;
2185
2301
  stroke-linecap: round;
2186
2302
  stroke-linejoin: round;
2187
2303
  }
2304
+ .markdy-node__icon[data-vector-symbol] svg {
2305
+ stroke: none;
2306
+ }
2188
2307
  .markdy-node__icon[data-media="image"] {
2189
2308
  background: transparent;
2190
2309
  box-shadow: none;
@@ -2258,9 +2377,10 @@ function ensureNodeStyles(doc) {
2258
2377
  .markdy-node[data-role="data"] { border-radius: 12px 12px 16px 16px; }
2259
2378
  .markdy-scene-title {
2260
2379
  position: absolute;
2261
- left: 48px;
2262
- top: 28px;
2263
- right: 48px;
2380
+ left: 56px;
2381
+ top: 32px;
2382
+ right: 56px;
2383
+ max-width: calc(100% - 112px);
2264
2384
  z-index: 130;
2265
2385
  font-size: 30px;
2266
2386
  font-weight: 700;
@@ -2269,6 +2389,8 @@ function ensureNodeStyles(doc) {
2269
2389
  opacity: 0;
2270
2390
  transform: translateY(-6px);
2271
2391
  font-family: var(--md-font-title, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif);
2392
+ pointer-events: none;
2393
+ word-break: break-word;
2272
2394
  }
2273
2395
  .markdy-scene-title[data-visible="1"] {
2274
2396
  opacity: 1;
@@ -2445,15 +2567,26 @@ function ensureNodeStyles(doc) {
2445
2567
  border-radius: 999px;
2446
2568
  }
2447
2569
  .markdy-node[data-is-container="1"] {
2448
- background: color-mix(in srgb, var(--md-surface-raised) 25%, transparent);
2449
- border: 1px solid color-mix(in srgb, var(--md-role-color, var(--md-accent)) 40%, var(--md-border) 60%);
2450
- box-shadow: inset 0 0 0 1px var(--md-hairline), 0 4px 16px -4px var(--md-shadow, rgba(0,0,0,0.25));
2570
+ background: color-mix(in srgb, var(--md-surface-raised) 20%, transparent);
2571
+ border: 1.5px solid color-mix(in srgb, var(--md-role-color, var(--md-accent)) 45%, var(--md-border) 55%);
2572
+ border-radius: 20px;
2573
+ box-shadow: inset 0 0 0 1px var(--md-hairline), 0 8px 24px -6px var(--md-shadow, rgba(0,0,0,0.25));
2451
2574
  backdrop-filter: blur(8px);
2452
2575
  -webkit-backdrop-filter: blur(8px);
2576
+ pointer-events: none;
2453
2577
  }
2454
2578
  .markdy-node[data-is-container="1"] .markdy-node__body {
2455
- align-items: flex-start;
2456
- padding: 12px 16px;
2579
+ height: auto;
2580
+ min-height: 44px;
2581
+ align-items: center;
2582
+ padding: 10px 18px;
2583
+ pointer-events: auto;
2584
+ }
2585
+ .markdy-node[data-is-container="1"] .markdy-node__label {
2586
+ font-size: 13.5px;
2587
+ font-weight: 700;
2588
+ letter-spacing: -0.01em;
2589
+ color: var(--md-text);
2457
2590
  }
2458
2591
  .markdy-node[data-is-container="1"][data-focal="1"] {
2459
2592
  background: color-mix(in srgb, var(--md-accent-tint, var(--md-accent)) 16%, transparent);
@@ -2551,13 +2684,6 @@ function ensureNodeStyles(doc) {
2551
2684
  0 8px 24px -4px rgba(29, 78, 216, 0.14),
2552
2685
  inset 0 1px 0 rgba(255, 255, 255, 0.9);
2553
2686
  }
2554
- .markdy-scene-root[data-markdy-theme="ink"] .markdy-node__icon {
2555
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 10%, #ffffff);
2556
- border: 1px solid color-mix(in srgb, var(--md-role-color, var(--md-accent)) 30%, transparent);
2557
- border-radius: 6px;
2558
- width: 30px;
2559
- height: 30px;
2560
- }
2561
2687
  .markdy-scene-root[data-markdy-theme="ink"] .markdy-node__tech {
2562
2688
  background: #eff6ff;
2563
2689
  color: #1e3a8a;
@@ -2576,10 +2702,6 @@ function ensureNodeStyles(doc) {
2576
2702
  0 8px 24px -4px rgba(29, 78, 216, 0.18),
2577
2703
  inset 0 1px 0 #ffffff;
2578
2704
  }
2579
- .markdy-scene-root[data-markdy-theme="ink"] .markdy-node[data-focal="1"] .markdy-node__icon {
2580
- background: rgba(29, 78, 216, 0.12);
2581
- border-color: rgba(29, 78, 216, 0.40);
2582
- }
2583
2705
  .markdy-scene-root[data-markdy-theme="ink"] .markdy-node[data-shape="diamond"][data-focal="1"] {
2584
2706
  filter: drop-shadow(0 0 1.5px #1d4ed8) drop-shadow(3px 3px 0 rgba(29, 78, 216, 0.25)) drop-shadow(0 6px 20px rgba(29, 78, 216, 0.16));
2585
2707
  }
@@ -2593,14 +2715,6 @@ function ensureNodeStyles(doc) {
2593
2715
  transform: translate(-1.5px, -1.5px) rotate(-0.6deg);
2594
2716
  box-shadow: 5.5px 5.5px 0 #18181b, 0 10px 20px -4px rgba(24, 24, 27, 0.12);
2595
2717
  }
2596
- .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node__icon {
2597
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 16%, #ffffff);
2598
- border: 1.75px solid #18181b;
2599
- border-radius: 50% 45% 55% 48% / 48% 55% 45% 50%;
2600
- width: 30px;
2601
- height: 30px;
2602
- box-shadow: 1.5px 1.5px 0 #18181b;
2603
- }
2604
2718
  .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node__tech {
2605
2719
  background: #fef08a;
2606
2720
  color: #18181b;
@@ -2617,12 +2731,6 @@ function ensureNodeStyles(doc) {
2617
2731
  border: 2.25px solid #18181b;
2618
2732
  background: linear-gradient(135deg, #ffffff 0%, #fff1f2 100%);
2619
2733
  box-shadow: 4.5px 4.5px 0 #f43f5e, 0 0 0 2px #18181b;
2620
- }
2621
- .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node[data-focal="1"] .markdy-node__icon {
2622
- background: #f43f5e;
2623
- color: #ffffff;
2624
- border-color: #18181b;
2625
- }
2626
2734
  .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node[data-shape="diamond"][data-focal="1"] {
2627
2735
  filter: drop-shadow(0 0 1.5px #18181b) drop-shadow(4.5px 4.5px 0 #f43f5e);
2628
2736
  }
@@ -3302,7 +3410,7 @@ function mountTreeBuses(layer, buses, theme) {
3302
3410
  Object.assign(layer.style, {
3303
3411
  position: "absolute",
3304
3412
  inset: "0",
3305
- zIndex: "42",
3413
+ zIndex: "52",
3306
3414
  pointerEvents: "none"
3307
3415
  });
3308
3416
  const doc = layer.ownerDocument;
@@ -3319,29 +3427,50 @@ function mountTreeBuses(layer, buses, theme) {
3319
3427
  for (const bus of buses) {
3320
3428
  const group = doc.createElementNS("http://www.w3.org/2000/svg", "g");
3321
3429
  group.setAttribute("data-tree-bus", bus.id);
3322
- for (const childX of bus.childXs) {
3323
- const pathEl = doc.createElementNS("http://www.w3.org/2000/svg", "path");
3324
- let d;
3325
- if (Math.abs(childX - bus.parentX) < 1) {
3326
- d = toPathD([
3430
+ if (bus.vertical) {
3431
+ bus.childXs.forEach((childX, idx) => {
3432
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
3433
+ const pathEl = doc.createElementNS("http://www.w3.org/2000/svg", "path");
3434
+ const d = toPathD([
3327
3435
  { x: bus.parentX, y: bus.parentY },
3328
- { x: childX, y: bus.childY }
3329
- ], 12);
3330
- } else {
3331
- d = toPathD([
3332
- { x: bus.parentX, y: bus.parentY },
3333
- { x: bus.parentX, y: bus.branchY },
3334
- { x: childX, y: bus.branchY },
3335
- { x: childX, y: bus.childY }
3336
- ], 12);
3337
- }
3338
- pathEl.setAttribute("d", d);
3339
- pathEl.setAttribute("fill", "none");
3340
- pathEl.setAttribute("stroke", stroke);
3341
- pathEl.setAttribute("stroke-width", "1.6");
3342
- pathEl.setAttribute("stroke-linecap", "round");
3343
- pathEl.setAttribute("stroke-linejoin", "round");
3344
- group.appendChild(pathEl);
3436
+ { x: bus.parentX, y: targetY },
3437
+ { x: childX, y: targetY }
3438
+ ], 10);
3439
+ pathEl.setAttribute("d", d);
3440
+ pathEl.setAttribute("fill", "none");
3441
+ pathEl.setAttribute("stroke", stroke);
3442
+ pathEl.setAttribute("stroke-width", "1.6");
3443
+ pathEl.setAttribute("stroke-linecap", "round");
3444
+ pathEl.setAttribute("stroke-linejoin", "round");
3445
+ group.appendChild(pathEl);
3446
+ });
3447
+ } else {
3448
+ bus.childXs.forEach((childX, idx) => {
3449
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
3450
+ const pathEl = doc.createElementNS("http://www.w3.org/2000/svg", "path");
3451
+ let d;
3452
+ if (Math.abs(childX - bus.parentX) < 1) {
3453
+ d = toPathD([
3454
+ { x: bus.parentX, y: bus.parentY },
3455
+ { x: childX, y: targetY }
3456
+ ], 12);
3457
+ } else {
3458
+ const branchY = bus.childYs ? (bus.parentY + targetY) / 2 : bus.branchY;
3459
+ d = toPathD([
3460
+ { x: bus.parentX, y: bus.parentY },
3461
+ { x: bus.parentX, y: branchY },
3462
+ { x: childX, y: branchY },
3463
+ { x: childX, y: targetY }
3464
+ ], 12);
3465
+ }
3466
+ pathEl.setAttribute("d", d);
3467
+ pathEl.setAttribute("fill", "none");
3468
+ pathEl.setAttribute("stroke", stroke);
3469
+ pathEl.setAttribute("stroke-width", "1.6");
3470
+ pathEl.setAttribute("stroke-linecap", "round");
3471
+ pathEl.setAttribute("stroke-linejoin", "round");
3472
+ group.appendChild(pathEl);
3473
+ });
3345
3474
  }
3346
3475
  svg.appendChild(group);
3347
3476
  }
@@ -4313,8 +4442,12 @@ function snapRouteEndpointsToShapes2(points, from, to) {
4313
4442
  out[out.length - 1] = snapPortToNodeShape2(to, out[out.length - 1], out[out.length - 2], false);
4314
4443
  return dedupePoints2(out);
4315
4444
  }
4316
- function routeEdgePoints2(from, to, routeObstacles, bounds, lane) {
4445
+ function routeEdgePoints2(from, to, routeObstacles, bounds, lane, diagramType = "architecture", isVerticalTree = false) {
4317
4446
  if (from.shape === "circle" && to.shape === "circle") return circleBoundaryRoute2(from, to);
4447
+ if (diagramType === "tree") {
4448
+ const treeRoute = routeTreeEdgePoints(from, to, lane, isVerticalTree, bounds);
4449
+ if (treeRoute) return snapRouteEndpointsToShapes2(treeRoute, from, to);
4450
+ }
4318
4451
  const raw = routeOrthogonal(boxRect(from), boxRect(to), routeObstacles, bounds, lane);
4319
4452
  return snapRouteEndpointsToShapes2(raw, from, to);
4320
4453
  }
@@ -4479,23 +4612,38 @@ function renderPureVectorSvg(plan, options = {}) {
4479
4612
  `;
4480
4613
  const busStroke = theme.edges?.dependency ?? theme.border ?? "#64748b";
4481
4614
  for (const bus of plan.treeBuses) {
4482
- for (const childX of bus.childXs) {
4483
- let d;
4484
- if (Math.abs(childX - bus.parentX) < 1) {
4485
- d = toPathD([
4486
- { x: bus.parentX, y: bus.parentY },
4487
- { x: childX, y: bus.childY }
4488
- ], 12);
4489
- } else {
4490
- d = toPathD([
4615
+ if (bus.vertical) {
4616
+ bus.childXs.forEach((childX, idx) => {
4617
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
4618
+ const d = toPathD([
4491
4619
  { x: bus.parentX, y: bus.parentY },
4492
- { x: bus.parentX, y: bus.branchY },
4493
- { x: childX, y: bus.branchY },
4494
- { x: childX, y: bus.childY }
4495
- ], 12);
4496
- }
4497
- svg += ` <path d="${d}" fill="none" stroke="${busStroke}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
4620
+ { x: bus.parentX, y: targetY },
4621
+ { x: childX, y: targetY }
4622
+ ], 10);
4623
+ svg += ` <path d="${d}" fill="none" stroke="${busStroke}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
4498
4624
  `;
4625
+ });
4626
+ } else {
4627
+ bus.childXs.forEach((childX, idx) => {
4628
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
4629
+ let d;
4630
+ if (Math.abs(childX - bus.parentX) < 1) {
4631
+ d = toPathD([
4632
+ { x: bus.parentX, y: bus.parentY },
4633
+ { x: childX, y: targetY }
4634
+ ], 12);
4635
+ } else {
4636
+ const branchY = bus.childYs ? (bus.parentY + targetY) / 2 : bus.branchY;
4637
+ d = toPathD([
4638
+ { x: bus.parentX, y: bus.parentY },
4639
+ { x: bus.parentX, y: branchY },
4640
+ { x: childX, y: branchY },
4641
+ { x: childX, y: targetY }
4642
+ ], 12);
4643
+ }
4644
+ svg += ` <path d="${d}" fill="none" stroke="${busStroke}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
4645
+ `;
4646
+ });
4499
4647
  }
4500
4648
  }
4501
4649
  svg += ` </g>
@@ -4560,6 +4708,57 @@ function renderPureVectorSvg(plan, options = {}) {
4560
4708
  }
4561
4709
  }
4562
4710
  svg += ` </g>
4711
+ `;
4712
+ }
4713
+ if (plan.diagramType === "timeline" && plan.nodes && plan.nodes.length > 0) {
4714
+ svg += ` <!-- Timeline Track Layer -->
4715
+ <g class="markdy-timeline-layer">
4716
+ `;
4717
+ const isVertical = height > width || plan.nodes.length > 1 && Math.abs(plan.nodes[1].y - plan.nodes[0].y) > Math.abs(plan.nodes[1].x - plan.nodes[0].x);
4718
+ const strokeAxis = theme.edges?.dependency ?? theme.rule ?? theme.border ?? "#64748b";
4719
+ const strokeBorder = theme.edges?.dependency ?? theme.border ?? "#64748b";
4720
+ const surfaceFill = theme.surfaceRaised ?? theme.surface ?? (isDark ? "#1e293b" : "#ffffff");
4721
+ if (isVertical) {
4722
+ const centerX = width / 2;
4723
+ const minY = Math.min(...plan.nodes.map((n) => n.y)) - 16;
4724
+ const maxY = Math.max(...plan.nodes.map((n) => n.y + n.height)) + 16;
4725
+ svg += ` <line class="markdy-timeline-axis" x1="${centerX}" y1="${Math.max(40, minY)}" x2="${centerX}" y2="${Math.min(height - 40, maxY)}" stroke="${strokeAxis}" stroke-width="2" stroke-linecap="round" opacity="0.75"/>
4726
+ `;
4727
+ for (const node of plan.nodes) {
4728
+ const nodeCenterY = node.y + node.height / 2;
4729
+ const isLeft = node.x + node.width / 2 < centerX;
4730
+ const targetX = isLeft ? node.x + node.width : node.x;
4731
+ const focal = node.focal;
4732
+ const stemStroke = focal ? accent : strokeBorder;
4733
+ const stemDash = focal ? "" : 'stroke-dasharray="4 4"';
4734
+ svg += ` <line class="markdy-timeline-stem" x1="${centerX}" y1="${nodeCenterY}" x2="${targetX}" y2="${nodeCenterY}" stroke="${stemStroke}" stroke-width="${focal ? "2" : "1.5"}" ${stemDash} opacity="${focal ? "0.95" : "0.75"}"/>
4735
+ `;
4736
+ svg += ` <circle class="markdy-timeline-pip" cx="${centerX}" cy="${nodeCenterY}" r="${focal ? "5.5" : "4"}" fill="${focal ? accent : surfaceFill}" stroke="${focal ? accent : strokeBorder}" stroke-width="2"/>
4737
+ `;
4738
+ }
4739
+ } else {
4740
+ const SAFE = 40;
4741
+ const TITLE_BAND = 64;
4742
+ const contentH = height - SAFE - TITLE_BAND - SAFE;
4743
+ const baselineY = TITLE_BAND + contentH / 2;
4744
+ const minX = Math.min(...plan.nodes.map((n) => n.x)) - 20;
4745
+ const maxX = Math.max(...plan.nodes.map((n) => n.x + n.width)) + 20;
4746
+ svg += ` <line class="markdy-timeline-axis" x1="${Math.max(40, minX)}" y1="${baselineY}" x2="${Math.min(width - 40, maxX)}" y2="${baselineY}" stroke="${strokeAxis}" stroke-width="2" stroke-linecap="round" opacity="0.75"/>
4747
+ `;
4748
+ for (const node of plan.nodes) {
4749
+ const nodeCenterX = node.x + node.width / 2;
4750
+ const isAbove = node.y + node.height <= baselineY + 10;
4751
+ const targetY = isAbove ? node.y + node.height : node.y;
4752
+ const focal = node.focal;
4753
+ const stemStroke = focal ? accent : strokeBorder;
4754
+ const stemDash = focal ? "" : 'stroke-dasharray="4 4"';
4755
+ svg += ` <line class="markdy-timeline-stem" x1="${nodeCenterX}" y1="${baselineY}" x2="${nodeCenterX}" y2="${targetY}" stroke="${stemStroke}" stroke-width="${focal ? "2" : "1.5"}" ${stemDash} opacity="${focal ? "0.95" : "0.75"}"/>
4756
+ `;
4757
+ svg += ` <circle class="markdy-timeline-pip" cx="${nodeCenterX}" cy="${baselineY}" r="${focal ? "5.5" : "4"}" fill="${focal ? accent : surfaceFill}" stroke="${focal ? accent : strokeBorder}" stroke-width="2"/>
4758
+ `;
4759
+ }
4760
+ }
4761
+ svg += ` </g>
4563
4762
  `;
4564
4763
  }
4565
4764
  if (plan.diagramType !== "sequence" && plan.edges && plan.edges.length > 0) {
@@ -4568,6 +4767,7 @@ function renderPureVectorSvg(plan, options = {}) {
4568
4767
  `;
4569
4768
  const nodeMap = new Map(plan.nodes.map((n) => [n.id, n]));
4570
4769
  const laneByPair = /* @__PURE__ */ new Map();
4770
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || plan.meta?.direction === "TB" || plan.meta?.direction === "BT");
4571
4771
  plan.edges.forEach((edge, index) => {
4572
4772
  const from = nodeMap.get(edge.from);
4573
4773
  const to = nodeMap.get(edge.to);
@@ -4579,7 +4779,7 @@ function renderPureVectorSvg(plan, options = {}) {
4579
4779
  const style = EDGE_STYLES2[edge.kind] || EDGE_STYLES2.request;
4580
4780
  const isSelfLoop = from.id === to.id;
4581
4781
  const lane = nextEdgeLane(laneByPair, from, to);
4582
- const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane));
4782
+ const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane, plan.diagramType, isVerticalTree));
4583
4783
  const d = toPathD(points, 14, existingPaths);
4584
4784
  existingPaths.push(points);
4585
4785
  const markerAttr = style.marker === "arrow" ? 'marker-end="url(#arrow-request)"' : style.marker === "arrow-open" ? 'marker-end="url(#arrow-response)"' : style.marker === "dot" ? 'marker-end="url(#arrow-event)"' : "";
@@ -4594,7 +4794,8 @@ function renderPureVectorSvg(plan, options = {}) {
4594
4794
  for (let i = 0; i < points.length - 1; i++) {
4595
4795
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
4596
4796
  }
4597
- const maxAvailW = Math.max(48, longestSegLen - 24);
4797
+ const isTreeVertical = plan.diagramType === "tree" && isVerticalTree;
4798
+ const maxAvailW = isTreeVertical ? Math.max(48, Math.min(68, longestSegLen - 12)) : Math.max(48, longestSegLen - 24);
4598
4799
  const lines = wrapFlowLabelText(edge.label, maxAvailW);
4599
4800
  const maxChars = Math.max(...lines.map((l) => l.length));
4600
4801
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -5741,10 +5942,28 @@ function detectHostTheme(container) {
5741
5942
  }
5742
5943
  return "paper";
5743
5944
  }
5945
+ var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
5946
+ "quadrant",
5947
+ "swimlane",
5948
+ "timeline",
5949
+ "radar",
5950
+ "constellation",
5951
+ "gantt"
5952
+ ]);
5744
5953
  function computeDiagramContentBounds(plan, options) {
5745
5954
  if (!plan.nodes || plan.nodes.length === 0) {
5746
5955
  return { minX: 0, minY: 0, maxX: plan.meta.width, maxY: plan.meta.height, width: plan.meta.width, height: plan.meta.height };
5747
5956
  }
5957
+ if (CANVAS_WIDE_ARCHETYPES.has(plan.diagramType)) {
5958
+ return {
5959
+ minX: 0,
5960
+ minY: 0,
5961
+ maxX: plan.meta.width,
5962
+ maxY: plan.meta.height,
5963
+ width: plan.meta.width,
5964
+ height: plan.meta.height
5965
+ };
5966
+ }
5748
5967
  let minX = Infinity;
5749
5968
  let minY = Infinity;
5750
5969
  let maxX = -Infinity;
@@ -5767,6 +5986,15 @@ function computeDiagramContentBounds(plan, options) {
5767
5986
  maxX = Math.max(maxX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
5768
5987
  maxY = Math.max(maxY, bus.parentY, bus.branchY, bus.childY);
5769
5988
  }
5989
+ for (const edge of plan.edges ?? []) {
5990
+ if (edge.selfLoop) {
5991
+ const fromNode = plan.nodes.find((n) => n.id === edge.from);
5992
+ if (fromNode) {
5993
+ minY = Math.min(minY, fromNode.y - 40);
5994
+ maxY = Math.max(maxY, fromNode.y + fromNode.height + 40);
5995
+ }
5996
+ }
5997
+ }
5770
5998
  if (plan.diagramType === "sequence") {
5771
5999
  let maxMsgY = minY;
5772
6000
  for (const msg of plan.sequenceMessages ?? []) {
@@ -5778,8 +6006,13 @@ function computeDiagramContentBounds(plan, options) {
5778
6006
  maxY = Math.max(maxY, maxMsgY, plan.meta.height - 24);
5779
6007
  }
5780
6008
  const titleText = (plan.title ?? plan.meta?.title ?? "").trim();
5781
- if (titleText.length > 0) {
5782
- minY = Math.min(minY, 20);
6009
+ const hasTitle = titleText.length > 0;
6010
+ if (hasTitle) {
6011
+ minX = 0;
6012
+ minY = 0;
6013
+ const titleEstimatedW = Math.min(plan.meta.width, 56 + titleText.length * 17 + 56);
6014
+ maxX = Math.max(maxX, titleEstimatedW);
6015
+ maxY = Math.max(maxY, 72);
5783
6016
  }
5784
6017
  const hasBeatCaptions = plan.beats && plan.beats.some((b) => b.label && b.label.trim().length > 0);
5785
6018
  if (hasBeatCaptions) {
@@ -5794,11 +6027,18 @@ function computeDiagramContentBounds(plan, options) {
5794
6027
  maxY = Math.max(maxY, targetNode.y + targetNode.height + 24);
5795
6028
  }
5796
6029
  }
5797
- const pad = options?.padding ?? (options?.tight === false ? 24 : 10);
5798
- minX = Math.max(0, minX - pad);
5799
- minY = Math.max(0, minY - pad);
5800
- maxX = Math.min(plan.meta.width, maxX + pad);
5801
- maxY = Math.min(plan.meta.height, maxY + pad);
6030
+ const defaultPad = plan.groupBoundaries && plan.groupBoundaries.length > 0 ? 28 : 22;
6031
+ const pad = options?.padding ?? (options?.tight === false ? 36 : defaultPad);
6032
+ minX = Math.max(-pad, minX - pad);
6033
+ minY = Math.max(-pad, minY - pad);
6034
+ maxX = Math.min(plan.meta.width + pad, maxX + pad);
6035
+ maxY = Math.min(plan.meta.height + pad, maxY + pad);
6036
+ if (minX > 0 && minX <= pad) minX = 0;
6037
+ if (minY > 0 && minY <= pad) minY = 0;
6038
+ if (hasTitle) {
6039
+ minX = 0;
6040
+ minY = 0;
6041
+ }
5802
6042
  const width = Math.max(maxX - minX, 100);
5803
6043
  const height = Math.max(maxY - minY, 80);
5804
6044
  return { minX, minY, maxX, maxY, width, height };
@@ -5826,7 +6066,8 @@ function createDiagram(opts) {
5826
6066
  onEnded,
5827
6067
  responsiveLayout = true,
5828
6068
  fitMode = "width",
5829
- targetWidthRatio = 0.98
6069
+ targetWidthRatio = 0.96,
6070
+ contentPadding
5830
6071
  } = opts;
5831
6072
  function detectContainerOrientation() {
5832
6073
  const cWidth = container?.clientWidth || 0;
@@ -5852,7 +6093,7 @@ function createDiagram(opts) {
5852
6093
  if (w.severity === "warning") onWarning(w);
5853
6094
  }
5854
6095
  const hasExplicitDirection = ast.meta.explicitDirection === true;
5855
- const shouldAdaptOrientation = responsiveLayout !== false && (!hasExplicitDirection || responsiveLayout === true);
6096
+ const shouldAdaptOrientation = responsiveLayout !== false && !hasExplicitDirection;
5856
6097
  let activeOrientation = detectContainerOrientation();
5857
6098
  if (shouldAdaptOrientation) {
5858
6099
  ast.meta.direction = activeOrientation === "portrait" ? "TB" : "LR";
@@ -5930,7 +6171,7 @@ function createDiagram(opts) {
5930
6171
  });
5931
6172
  if (container.style.aspectRatio) container.style.aspectRatio = "unset";
5932
6173
  if (container.style.overflow === "hidden") container.style.overflow = "visible";
5933
- const initialBounds = computeDiagramContentBounds(plan);
6174
+ const initialBounds = computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
5934
6175
  const contentRatio = `${initialBounds.width} / ${initialBounds.height}`;
5935
6176
  const viewport = document.createElement("div");
5936
6177
  viewport.className = "markdy-viewport";
@@ -6044,7 +6285,7 @@ function createDiagram(opts) {
6044
6285
  left: "0",
6045
6286
  width: `${plan.meta.width}px`,
6046
6287
  height: `${plan.meta.height}px`,
6047
- overflow: "hidden",
6288
+ overflow: "visible",
6048
6289
  userSelect: "none",
6049
6290
  transformOrigin: "0 0"
6050
6291
  });
@@ -6165,6 +6406,7 @@ function createDiagram(opts) {
6165
6406
  plan.theme,
6166
6407
  { width: plan.meta.width, height: plan.meta.height }
6167
6408
  ) : [];
6409
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB");
6168
6410
  let allAnims = [
6169
6411
  ...sequenceAnims,
6170
6412
  ...buildStructuralEdgeAnimations(
@@ -6176,12 +6418,13 @@ function createDiagram(opts) {
6176
6418
  edgeRuntimes,
6177
6419
  edgeSceneId,
6178
6420
  plan.diagramType,
6179
- plan.cues
6421
+ plan.cues,
6422
+ isVerticalTree
6180
6423
  ),
6181
6424
  ...buildCueAnimations(plan.cues, nodeEls, plan.nodes, plan.theme, cameraLayer, titleEl, {
6182
6425
  width: plan.meta.width,
6183
6426
  height: plan.meta.height
6184
- }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType),
6427
+ }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType, isVerticalTree),
6185
6428
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6186
6429
  ];
6187
6430
  mountAnnotations(annotationLayer, plan.annotations, plan.nodes, plan.theme, {
@@ -6196,7 +6439,7 @@ function createDiagram(opts) {
6196
6439
  let sceneOffsetX = 0;
6197
6440
  let sceneOffsetY = 0;
6198
6441
  function computeContentBounds() {
6199
- return computeDiagramContentBounds(plan);
6442
+ return computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6200
6443
  }
6201
6444
  function relayoutOrientation(newDirection) {
6202
6445
  ast.meta.direction = newDirection;
@@ -6204,7 +6447,7 @@ function createDiagram(opts) {
6204
6447
  if (!ast.meta.explicitWidth) ast.meta.width = dims.width;
6205
6448
  if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
6206
6449
  const newPlan = compilePlan(ast, plan.theme);
6207
- const newBounds = computeDiagramContentBounds(newPlan);
6450
+ const newBounds = computeDiagramContentBounds(newPlan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6208
6451
  scene.style.width = `${newPlan.meta.width}px`;
6209
6452
  scene.style.height = `${newPlan.meta.height}px`;
6210
6453
  viewport.style.aspectRatio = `${newBounds.width} / ${newBounds.height}`;
@@ -6222,12 +6465,28 @@ function createDiagram(opts) {
6222
6465
  el.style.top = `${node.y}px`;
6223
6466
  el.style.width = `${node.width}px`;
6224
6467
  el.style.height = `${node.height}px`;
6468
+ el.style.setProperty("--md-node-w", `${node.width}px`);
6469
+ el.style.setProperty("--md-node-h", `${node.height}px`);
6225
6470
  }
6226
6471
  }
6227
6472
  treeLayer.innerHTML = "";
6228
6473
  mountTreeBuses(treeLayer, plan.treeBuses, plan.theme);
6229
6474
  groupLayer.innerHTML = "";
6230
6475
  mountGroupBoundaries(groupLayer, plan.groupBoundaries, plan.theme);
6476
+ constellationLayer.innerHTML = "";
6477
+ if (plan.diagramType === "constellation") {
6478
+ mountConstellationLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6479
+ } else if (plan.diagramType === "radar") {
6480
+ mountRadarLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6481
+ } else if (plan.diagramType === "timeline") {
6482
+ mountTimelineLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6483
+ } else if (plan.diagramType === "quadrant") {
6484
+ mountQuadrantLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6485
+ } else if (plan.diagramType === "swimlane") {
6486
+ mountSwimlaneLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6487
+ } else if (plan.diagramType === "gantt") {
6488
+ mountGanttLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6489
+ }
6231
6490
  structuralEdgeHost.innerHTML = "";
6232
6491
  edgeRuntimes.clear();
6233
6492
  const newStructuralAnims = buildStructuralEdgeAnimations(
@@ -6239,7 +6498,8 @@ function createDiagram(opts) {
6239
6498
  edgeRuntimes,
6240
6499
  edgeSceneId,
6241
6500
  plan.diagramType,
6242
- plan.cues
6501
+ plan.cues,
6502
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6243
6503
  );
6244
6504
  for (const anim of allAnims) anim.cancel();
6245
6505
  allAnims = [
@@ -6263,7 +6523,8 @@ function createDiagram(opts) {
6263
6523
  plan.edges,
6264
6524
  edgeRuntimes,
6265
6525
  edgeSceneId,
6266
- plan.diagramType
6526
+ plan.diagramType,
6527
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6267
6528
  ),
6268
6529
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6269
6530
  ];
@@ -6296,10 +6557,10 @@ function createDiagram(opts) {
6296
6557
  const bounds = computeContentBounds();
6297
6558
  const contentW = bounds.width;
6298
6559
  const contentH = bounds.height;
6299
- const targetRatio = Math.min(1, Math.max(0.95, targetWidthRatio ?? 0.98));
6560
+ const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
6300
6561
  const widthScale = vWidth * targetRatio / contentW;
6301
6562
  if (fitMode === "contain") {
6302
- const heightScale = (vHeight - 16) * targetRatio / contentH;
6563
+ const heightScale = (vHeight - 24) * targetRatio / contentH;
6303
6564
  fitScale = Math.min(widthScale, heightScale);
6304
6565
  } else {
6305
6566
  fitScale = widthScale;
@@ -6308,13 +6569,16 @@ function createDiagram(opts) {
6308
6569
  scene.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6309
6570
  viewport.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6310
6571
  container.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6572
+ if (titleEl && contentW > 0) {
6573
+ titleEl.style.maxWidth = `${Math.max(contentW - 112, 280)}px`;
6574
+ }
6311
6575
  const scaledContentW = contentW * fitScale;
6312
6576
  const scaledContentH = contentH * fitScale;
6313
6577
  sceneOffsetX = (vWidth - scaledContentW) / 2 - bounds.minX * fitScale;
6314
6578
  if (fitMode === "contain") {
6315
6579
  sceneOffsetY = (vHeight - scaledContentH) / 2 - bounds.minY * fitScale;
6316
6580
  } else {
6317
- const topSafeMargin = scaledContentH <= vHeight ? Math.max(8, Math.min(18, (vHeight - scaledContentH) / 2)) : 8;
6581
+ const topSafeMargin = scaledContentH <= vHeight ? Math.max(14, Math.min(24, (vHeight - scaledContentH) / 2)) : 14;
6318
6582
  sceneOffsetY = topSafeMargin - bounds.minY * fitScale;
6319
6583
  }
6320
6584
  scene.style.left = `${sceneOffsetX}px`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
4
4
  "description": "Browser renderer for diagram-native animated MarkdyScript architecture diagrams, built on the Web Animations API.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,14 +46,14 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "html2canvas": "^1.4.1",
49
- "@markdy/core": "1.3.3"
49
+ "@markdy/core": "1.4.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "jsdom": "^29.1.1",
53
53
  "tsup": "^8.5.1",
54
54
  "typescript": "^5.9.3",
55
55
  "vitest": "^4.1.7",
56
- "@markdy/stdlib-systems": "1.3.3"
56
+ "@markdy/stdlib-systems": "1.4.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",