@markdy/renderer-dom 1.4.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +97 -49
  2. package/package.json +3 -3
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";
@@ -755,8 +802,12 @@ function snapRouteEndpointsToShapes(points, from, to) {
755
802
  out[out.length - 1] = snapPortToNodeShape(to, out[out.length - 1], out[out.length - 2], false);
756
803
  return dedupePoints(out);
757
804
  }
758
- function routeEdgePoints(from, to, routeObstacles, bounds, lane) {
805
+ function routeEdgePoints(from, to, routeObstacles, bounds, lane, diagramType = "architecture", isVerticalTree = false) {
759
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
+ }
760
811
  const raw = routeOrthogonal(boxRect(from), boxRect(to), routeObstacles, bounds, lane);
761
812
  return snapRouteEndpointsToShapes(raw, from, to);
762
813
  }
@@ -892,12 +943,12 @@ function computeEdgeLabelColor(edgeColor, isDark) {
892
943
  }
893
944
  return `color-mix(in srgb, ${edgeColor} 75%, #090d16)`;
894
945
  }
895
- 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) {
896
947
  ensureDefs(svg, theme, sceneId);
897
948
  const color = theme.edges[kind] ?? theme.edges.request ?? theme.accent;
898
949
  const style = EDGE_STYLES[kind] ?? EDGE_STYLES.request;
899
950
  const isSelfLoop = from.id === to.id;
900
- 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));
901
952
  const d = toPathD(points, 14, existingPaths);
902
953
  const len = polylineLength(points);
903
954
  const edgeId = `${from.id}_${to.id}`;
@@ -940,7 +991,8 @@ function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObst
940
991
  for (let i = 0; i < points.length - 1; i++) {
941
992
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
942
993
  }
943
- const maxAvailW = Math.max(90, 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);
944
996
  const lines = wrapFlowLabelText(label, maxAvailW);
945
997
  const maxChars = Math.max(...lines.map((l) => l.length));
946
998
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -1201,7 +1253,8 @@ function computeFrameTransform(targetIds, nodes, bounds, requestedZoom = DEFAULT
1201
1253
  const ty = Math.round((bounds.height / 2 - centerY * scale) * 10) / 10;
1202
1254
  return `translate(${tx}px, ${ty}px) scale(${Math.round(scale * 1e3) / 1e3})`;
1203
1255
  }
1204
- 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;
1205
1258
  const anims = [];
1206
1259
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
1207
1260
  const rectById = new Map(nodes.map((n) => [n.id, boxRect(n)]));
@@ -1237,7 +1290,9 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1237
1290
  [...allNodeRects, ...edgeLabels],
1238
1291
  bounds,
1239
1292
  lane,
1240
- placedPaths
1293
+ placedPaths,
1294
+ diagramType,
1295
+ isVertical
1241
1296
  );
1242
1297
  placedPaths.push(runtime.points);
1243
1298
  if (runtime.labelRect) edgeLabels.push(runtime.labelRect);
@@ -1386,7 +1441,9 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1386
1441
  labelObstacles,
1387
1442
  bounds,
1388
1443
  lane,
1389
- placedPaths
1444
+ placedPaths,
1445
+ diagramType,
1446
+ isVertical
1390
1447
  );
1391
1448
  placedPaths.push(runtime.points);
1392
1449
  if (runtime.labelRect) placedLabels.push(runtime.labelRect);
@@ -1436,7 +1493,8 @@ function buildCueAnimations(cues, nodeEls, nodes, theme, scene, titleEl, bounds,
1436
1493
  for (const a of anims) a.pause();
1437
1494
  return anims;
1438
1495
  }
1439
- 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;
1440
1498
  const structural = edges.filter(
1441
1499
  (e) => e.structural && diagramType !== "sequence" && !(diagramType === "tree" && !e.label)
1442
1500
  );
@@ -1491,7 +1549,9 @@ function buildStructuralEdgeAnimations(edges, nodes, theme, scene, bounds, edgeR
1491
1549
  labelObstacles,
1492
1550
  bounds,
1493
1551
  lane,
1494
- placedPaths
1552
+ placedPaths,
1553
+ diagramType,
1554
+ isVertical
1495
1555
  );
1496
1556
  placedPaths.push(runtime.points);
1497
1557
  if (runtime.labelRect) placedLabels.push(runtime.labelRect);
@@ -2220,27 +2280,30 @@ function ensureNodeStyles(doc) {
2220
2280
  box-sizing: border-box;
2221
2281
  }
2222
2282
  .markdy-node__icon {
2223
- flex: 0 0 28px;
2283
+ flex: 0 0 auto;
2224
2284
  width: 28px;
2225
2285
  height: 28px;
2226
- border-radius: 7px;
2227
- display: inline-flex;
2286
+ display: flex;
2228
2287
  align-items: center;
2229
2288
  justify-content: center;
2230
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 14%, transparent);
2289
+ background: transparent;
2290
+ box-shadow: none;
2231
2291
  color: var(--md-role-color, var(--md-accent));
2232
- box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-role-color, var(--md-accent)) 35%, transparent);
2233
2292
  transition: transform 0.2s ease;
2234
2293
  }
2235
2294
  .markdy-node__icon svg {
2236
- width: 18px;
2237
- height: 18px;
2295
+ width: 26px;
2296
+ height: 26px;
2297
+ display: block;
2238
2298
  stroke: currentColor;
2239
2299
  stroke-width: 1.8;
2240
2300
  fill: none;
2241
2301
  stroke-linecap: round;
2242
2302
  stroke-linejoin: round;
2243
2303
  }
2304
+ .markdy-node__icon[data-vector-symbol] svg {
2305
+ stroke: none;
2306
+ }
2244
2307
  .markdy-node__icon[data-media="image"] {
2245
2308
  background: transparent;
2246
2309
  box-shadow: none;
@@ -2621,13 +2684,6 @@ function ensureNodeStyles(doc) {
2621
2684
  0 8px 24px -4px rgba(29, 78, 216, 0.14),
2622
2685
  inset 0 1px 0 rgba(255, 255, 255, 0.9);
2623
2686
  }
2624
- .markdy-scene-root[data-markdy-theme="ink"] .markdy-node__icon {
2625
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 10%, #ffffff);
2626
- border: 1px solid color-mix(in srgb, var(--md-role-color, var(--md-accent)) 30%, transparent);
2627
- border-radius: 6px;
2628
- width: 30px;
2629
- height: 30px;
2630
- }
2631
2687
  .markdy-scene-root[data-markdy-theme="ink"] .markdy-node__tech {
2632
2688
  background: #eff6ff;
2633
2689
  color: #1e3a8a;
@@ -2646,10 +2702,6 @@ function ensureNodeStyles(doc) {
2646
2702
  0 8px 24px -4px rgba(29, 78, 216, 0.18),
2647
2703
  inset 0 1px 0 #ffffff;
2648
2704
  }
2649
- .markdy-scene-root[data-markdy-theme="ink"] .markdy-node[data-focal="1"] .markdy-node__icon {
2650
- background: rgba(29, 78, 216, 0.12);
2651
- border-color: rgba(29, 78, 216, 0.40);
2652
- }
2653
2705
  .markdy-scene-root[data-markdy-theme="ink"] .markdy-node[data-shape="diamond"][data-focal="1"] {
2654
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));
2655
2707
  }
@@ -2663,14 +2715,6 @@ function ensureNodeStyles(doc) {
2663
2715
  transform: translate(-1.5px, -1.5px) rotate(-0.6deg);
2664
2716
  box-shadow: 5.5px 5.5px 0 #18181b, 0 10px 20px -4px rgba(24, 24, 27, 0.12);
2665
2717
  }
2666
- .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node__icon {
2667
- background: color-mix(in srgb, var(--md-role-color, var(--md-accent)) 16%, #ffffff);
2668
- border: 1.75px solid #18181b;
2669
- border-radius: 50% 45% 55% 48% / 48% 55% 45% 50%;
2670
- width: 30px;
2671
- height: 30px;
2672
- box-shadow: 1.5px 1.5px 0 #18181b;
2673
- }
2674
2718
  .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node__tech {
2675
2719
  background: #fef08a;
2676
2720
  color: #18181b;
@@ -2687,12 +2731,6 @@ function ensureNodeStyles(doc) {
2687
2731
  border: 2.25px solid #18181b;
2688
2732
  background: linear-gradient(135deg, #ffffff 0%, #fff1f2 100%);
2689
2733
  box-shadow: 4.5px 4.5px 0 #f43f5e, 0 0 0 2px #18181b;
2690
- }
2691
- .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node[data-focal="1"] .markdy-node__icon {
2692
- background: #f43f5e;
2693
- color: #ffffff;
2694
- border-color: #18181b;
2695
- }
2696
2734
  .markdy-scene-root[data-markdy-theme="doodle"] .markdy-node[data-shape="diamond"][data-focal="1"] {
2697
2735
  filter: drop-shadow(0 0 1.5px #18181b) drop-shadow(4.5px 4.5px 0 #f43f5e);
2698
2736
  }
@@ -4404,8 +4442,12 @@ function snapRouteEndpointsToShapes2(points, from, to) {
4404
4442
  out[out.length - 1] = snapPortToNodeShape2(to, out[out.length - 1], out[out.length - 2], false);
4405
4443
  return dedupePoints2(out);
4406
4444
  }
4407
- function routeEdgePoints2(from, to, routeObstacles, bounds, lane) {
4445
+ function routeEdgePoints2(from, to, routeObstacles, bounds, lane, diagramType = "architecture", isVerticalTree = false) {
4408
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
+ }
4409
4451
  const raw = routeOrthogonal(boxRect(from), boxRect(to), routeObstacles, bounds, lane);
4410
4452
  return snapRouteEndpointsToShapes2(raw, from, to);
4411
4453
  }
@@ -4725,6 +4767,7 @@ function renderPureVectorSvg(plan, options = {}) {
4725
4767
  `;
4726
4768
  const nodeMap = new Map(plan.nodes.map((n) => [n.id, n]));
4727
4769
  const laneByPair = /* @__PURE__ */ new Map();
4770
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || plan.meta?.direction === "TB" || plan.meta?.direction === "BT");
4728
4771
  plan.edges.forEach((edge, index) => {
4729
4772
  const from = nodeMap.get(edge.from);
4730
4773
  const to = nodeMap.get(edge.to);
@@ -4736,7 +4779,7 @@ function renderPureVectorSvg(plan, options = {}) {
4736
4779
  const style = EDGE_STYLES2[edge.kind] || EDGE_STYLES2.request;
4737
4780
  const isSelfLoop = from.id === to.id;
4738
4781
  const lane = nextEdgeLane(laneByPair, from, to);
4739
- 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));
4740
4783
  const d = toPathD(points, 14, existingPaths);
4741
4784
  existingPaths.push(points);
4742
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)"' : "";
@@ -4751,7 +4794,8 @@ function renderPureVectorSvg(plan, options = {}) {
4751
4794
  for (let i = 0; i < points.length - 1; i++) {
4752
4795
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
4753
4796
  }
4754
- 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);
4755
4799
  const lines = wrapFlowLabelText(edge.label, maxAvailW);
4756
4800
  const maxChars = Math.max(...lines.map((l) => l.length));
4757
4801
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -6362,6 +6406,7 @@ function createDiagram(opts) {
6362
6406
  plan.theme,
6363
6407
  { width: plan.meta.width, height: plan.meta.height }
6364
6408
  ) : [];
6409
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB");
6365
6410
  let allAnims = [
6366
6411
  ...sequenceAnims,
6367
6412
  ...buildStructuralEdgeAnimations(
@@ -6373,12 +6418,13 @@ function createDiagram(opts) {
6373
6418
  edgeRuntimes,
6374
6419
  edgeSceneId,
6375
6420
  plan.diagramType,
6376
- plan.cues
6421
+ plan.cues,
6422
+ isVerticalTree
6377
6423
  ),
6378
6424
  ...buildCueAnimations(plan.cues, nodeEls, plan.nodes, plan.theme, cameraLayer, titleEl, {
6379
6425
  width: plan.meta.width,
6380
6426
  height: plan.meta.height
6381
- }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType),
6427
+ }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType, isVerticalTree),
6382
6428
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6383
6429
  ];
6384
6430
  mountAnnotations(annotationLayer, plan.annotations, plan.nodes, plan.theme, {
@@ -6452,7 +6498,8 @@ function createDiagram(opts) {
6452
6498
  edgeRuntimes,
6453
6499
  edgeSceneId,
6454
6500
  plan.diagramType,
6455
- plan.cues
6501
+ plan.cues,
6502
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6456
6503
  );
6457
6504
  for (const anim of allAnims) anim.cancel();
6458
6505
  allAnims = [
@@ -6476,7 +6523,8 @@ function createDiagram(opts) {
6476
6523
  plan.edges,
6477
6524
  edgeRuntimes,
6478
6525
  edgeSceneId,
6479
- plan.diagramType
6526
+ plan.diagramType,
6527
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6480
6528
  ),
6481
6529
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6482
6530
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.4.0",
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.4.0"
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.4.0"
56
+ "@markdy/stdlib-systems": "1.4.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",