@markdy/renderer-dom 1.4.0 → 1.4.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.d.ts CHANGED
@@ -169,6 +169,8 @@ interface Diagram {
169
169
  exportSvg(options?: SvgExportOptions): string;
170
170
  exportPng(options?: PngExportOptions): Promise<Blob>;
171
171
  exportGif(options?: GifDiagramExportOptions): Promise<Blob>;
172
+ resize(): void;
173
+ resetView(): void;
172
174
  destroy(): void;
173
175
  }
174
176
  /**
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
  }
@@ -4141,18 +4179,32 @@ function ensureSceneStyles(doc) {
4141
4179
  inset: 0 !important;
4142
4180
  z-index: 999999 !important;
4143
4181
  width: 100vw !important;
4182
+ width: 100dvw !important;
4144
4183
  height: 100vh !important;
4184
+ height: 100dvh !important;
4145
4185
  max-width: 100vw !important;
4186
+ max-width: 100dvw !important;
4146
4187
  max-height: 100vh !important;
4188
+ max-height: 100dvh !important;
4147
4189
  background-color: var(--md-canvas, #0b101b) !important;
4148
4190
  box-sizing: border-box !important;
4149
4191
  display: flex !important;
4150
4192
  flex-direction: column !important;
4151
4193
  justify-content: space-between !important;
4152
4194
  align-items: center !important;
4153
- padding: 16px 20px 12px !important;
4195
+ padding: max(16px, env(safe-area-inset-top, 16px)) max(20px, env(safe-area-inset-right, 20px)) max(12px, env(safe-area-inset-bottom, 12px)) max(20px, env(safe-area-inset-left, 20px)) !important;
4154
4196
  overflow: hidden !important;
4155
4197
  }
4198
+ .markdy-fullscreen-host .markdy-diagram-root,
4199
+ .markdy--pseudo-fullscreen .markdy-diagram-root {
4200
+ flex: 1 1 auto !important;
4201
+ width: 100% !important;
4202
+ height: 100% !important;
4203
+ display: flex !important;
4204
+ flex-direction: column !important;
4205
+ justify-content: space-between !important;
4206
+ align-items: center !important;
4207
+ }
4156
4208
  .markdy-diagram-root:fullscreen .markdy-viewport,
4157
4209
  .markdy-diagram-root:-webkit-full-screen .markdy-viewport,
4158
4210
  .markdy-diagram-root:-moz-full-screen .markdy-viewport,
@@ -4164,6 +4216,7 @@ function ensureSceneStyles(doc) {
4164
4216
  height: 100% !important;
4165
4217
  max-width: 100% !important;
4166
4218
  max-height: calc(100vh - 64px) !important;
4219
+ max-height: calc(100dvh - 64px) !important;
4167
4220
  display: flex !important;
4168
4221
  align-items: center !important;
4169
4222
  justify-content: center !important;
@@ -4178,7 +4231,7 @@ function ensureSceneStyles(doc) {
4178
4231
  width: 100% !important;
4179
4232
  max-width: 1400px !important;
4180
4233
  margin: 0 auto !important;
4181
- padding: 8px 12px 4px !important;
4234
+ padding: 8px 12px max(4px, env(safe-area-inset-bottom, 4px)) !important;
4182
4235
  }
4183
4236
  @media (hover: none) and (pointer: coarse) {
4184
4237
  .markdy-controls {
@@ -4404,8 +4457,12 @@ function snapRouteEndpointsToShapes2(points, from, to) {
4404
4457
  out[out.length - 1] = snapPortToNodeShape2(to, out[out.length - 1], out[out.length - 2], false);
4405
4458
  return dedupePoints2(out);
4406
4459
  }
4407
- function routeEdgePoints2(from, to, routeObstacles, bounds, lane) {
4460
+ function routeEdgePoints2(from, to, routeObstacles, bounds, lane, diagramType = "architecture", isVerticalTree = false) {
4408
4461
  if (from.shape === "circle" && to.shape === "circle") return circleBoundaryRoute2(from, to);
4462
+ if (diagramType === "tree") {
4463
+ const treeRoute = routeTreeEdgePoints(from, to, lane, isVerticalTree, bounds);
4464
+ if (treeRoute) return snapRouteEndpointsToShapes2(treeRoute, from, to);
4465
+ }
4409
4466
  const raw = routeOrthogonal(boxRect(from), boxRect(to), routeObstacles, bounds, lane);
4410
4467
  return snapRouteEndpointsToShapes2(raw, from, to);
4411
4468
  }
@@ -4725,6 +4782,7 @@ function renderPureVectorSvg(plan, options = {}) {
4725
4782
  `;
4726
4783
  const nodeMap = new Map(plan.nodes.map((n) => [n.id, n]));
4727
4784
  const laneByPair = /* @__PURE__ */ new Map();
4785
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || plan.meta?.direction === "TB" || plan.meta?.direction === "BT");
4728
4786
  plan.edges.forEach((edge, index) => {
4729
4787
  const from = nodeMap.get(edge.from);
4730
4788
  const to = nodeMap.get(edge.to);
@@ -4736,7 +4794,7 @@ function renderPureVectorSvg(plan, options = {}) {
4736
4794
  const style = EDGE_STYLES2[edge.kind] || EDGE_STYLES2.request;
4737
4795
  const isSelfLoop = from.id === to.id;
4738
4796
  const lane = nextEdgeLane(laneByPair, from, to);
4739
- const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane));
4797
+ const points = isSelfLoop ? dedupePoints2(selfLoopPath(from, bounds)) : dedupePoints2(routeEdgePoints2(from, to, routeObstacles, bounds, lane, plan.diagramType, isVerticalTree));
4740
4798
  const d = toPathD(points, 14, existingPaths);
4741
4799
  existingPaths.push(points);
4742
4800
  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 +4809,8 @@ function renderPureVectorSvg(plan, options = {}) {
4751
4809
  for (let i = 0; i < points.length - 1; i++) {
4752
4810
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
4753
4811
  }
4754
- const maxAvailW = Math.max(48, longestSegLen - 24);
4812
+ const isTreeVertical = plan.diagramType === "tree" && isVerticalTree;
4813
+ const maxAvailW = isTreeVertical ? Math.max(48, Math.min(68, longestSegLen - 12)) : Math.max(48, longestSegLen - 24);
4755
4814
  const lines = wrapFlowLabelText(edge.label, maxAvailW);
4756
4815
  const maxChars = Math.max(...lines.map((l) => l.length));
4757
4816
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -6362,6 +6421,7 @@ function createDiagram(opts) {
6362
6421
  plan.theme,
6363
6422
  { width: plan.meta.width, height: plan.meta.height }
6364
6423
  ) : [];
6424
+ const isVerticalTree = Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB");
6365
6425
  let allAnims = [
6366
6426
  ...sequenceAnims,
6367
6427
  ...buildStructuralEdgeAnimations(
@@ -6373,12 +6433,13 @@ function createDiagram(opts) {
6373
6433
  edgeRuntimes,
6374
6434
  edgeSceneId,
6375
6435
  plan.diagramType,
6376
- plan.cues
6436
+ plan.cues,
6437
+ isVerticalTree
6377
6438
  ),
6378
6439
  ...buildCueAnimations(plan.cues, nodeEls, plan.nodes, plan.theme, cameraLayer, titleEl, {
6379
6440
  width: plan.meta.width,
6380
6441
  height: plan.meta.height
6381
- }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType),
6442
+ }, plan.edges, edgeRuntimes, edgeSceneId, plan.diagramType, isVerticalTree),
6382
6443
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6383
6444
  ];
6384
6445
  mountAnnotations(annotationLayer, plan.annotations, plan.nodes, plan.theme, {
@@ -6452,7 +6513,8 @@ function createDiagram(opts) {
6452
6513
  edgeRuntimes,
6453
6514
  edgeSceneId,
6454
6515
  plan.diagramType,
6455
- plan.cues
6516
+ plan.cues,
6517
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6456
6518
  );
6457
6519
  for (const anim of allAnims) anim.cancel();
6458
6520
  allAnims = [
@@ -6476,7 +6538,8 @@ function createDiagram(opts) {
6476
6538
  plan.edges,
6477
6539
  edgeRuntimes,
6478
6540
  edgeSceneId,
6479
- plan.diagramType
6541
+ plan.diagramType,
6542
+ Boolean(plan.treeBuses?.some((b) => b.vertical) || ast.meta.direction === "TB")
6480
6543
  ),
6481
6544
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6482
6545
  ];
@@ -6902,6 +6965,14 @@ function createDiagram(opts) {
6902
6965
  async exportGif(options) {
6903
6966
  return await exportDiagramAsGif(container, diagram, options);
6904
6967
  },
6968
+ resize() {
6969
+ scaleScene();
6970
+ applyViewportTransform();
6971
+ syncControls();
6972
+ },
6973
+ resetView() {
6974
+ resetViewportTransform();
6975
+ },
6905
6976
  destroy() {
6906
6977
  diagram.pause();
6907
6978
  hostThemeObserver?.disconnect();
@@ -7324,6 +7395,16 @@ function createDiagram(opts) {
7324
7395
  button.setAttribute("aria-pressed", "false");
7325
7396
  const host = container;
7326
7397
  let isPseudoFull = false;
7398
+ let originalBodyOverflow = null;
7399
+ function isNativeFullscreenSupported() {
7400
+ if (typeof document === "undefined") return false;
7401
+ if (typeof navigator !== "undefined" && /iPhone|iPod/i.test(navigator.userAgent)) {
7402
+ return false;
7403
+ }
7404
+ return Boolean(
7405
+ document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled
7406
+ );
7407
+ }
7327
7408
  function syncFullscreenState() {
7328
7409
  const isFull = isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
7329
7410
  button.setAttribute("aria-pressed", isFull ? "true" : "false");
@@ -7331,54 +7412,82 @@ function createDiagram(opts) {
7331
7412
  button.innerHTML = isFull ? `${ICONS2.fullscreen}Exit` : `${ICONS2.fullscreen}Full`;
7332
7413
  if (isFull) {
7333
7414
  host.classList.add("markdy-fullscreen-host");
7415
+ if (isPseudoFull) {
7416
+ host.classList.add("markdy--pseudo-fullscreen");
7417
+ if (typeof document !== "undefined" && document.body && originalBodyOverflow === null) {
7418
+ originalBodyOverflow = document.body.style.overflow;
7419
+ document.body.style.overflow = "hidden";
7420
+ }
7421
+ }
7334
7422
  } else {
7335
7423
  host.classList.remove("markdy-fullscreen-host");
7336
7424
  host.classList.remove("markdy--pseudo-fullscreen");
7425
+ if (typeof document !== "undefined" && document.body && originalBodyOverflow !== null) {
7426
+ document.body.style.overflow = originalBodyOverflow;
7427
+ originalBodyOverflow = null;
7428
+ }
7337
7429
  }
7338
7430
  requestAnimationFrame(() => {
7339
7431
  scaleScene();
7340
7432
  applyViewportTransform();
7341
7433
  syncControls();
7342
7434
  });
7435
+ setTimeout(() => {
7436
+ scaleScene();
7437
+ applyViewportTransform();
7438
+ syncControls();
7439
+ }, 120);
7343
7440
  }
7344
7441
  async function toggleFullscreen() {
7345
7442
  try {
7346
- const isCurrentlyFull = isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.mozFullScreenElement === host || document.msFullscreenElement === host;
7443
+ const isCurrentlyFull = isPseudoFull || document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host;
7347
7444
  if (!isCurrentlyFull) {
7348
- const req = host.requestFullscreen?.bind(host) || host.webkitRequestFullscreen?.bind(host) || host.mozRequestFullScreen?.bind(host) || host.msRequestFullscreen?.bind(host) || viewport.requestFullscreen?.bind(viewport) || viewport.webkitRequestFullscreen?.bind(viewport);
7349
- if (req) {
7350
- try {
7351
- await req();
7352
- } catch {
7353
- isPseudoFull = true;
7354
- host.classList.add("markdy--pseudo-fullscreen");
7355
- syncFullscreenState();
7445
+ let enteredNative = false;
7446
+ if (isNativeFullscreenSupported()) {
7447
+ const req = host.requestFullscreen?.bind(host) || host.webkitRequestFullscreen?.bind(host) || host.mozRequestFullScreen?.bind(host) || host.msRequestFullscreen?.bind(host) || viewport.requestFullscreen?.bind(viewport) || viewport.webkitRequestFullscreen?.bind(viewport);
7448
+ if (req) {
7449
+ try {
7450
+ const res = req();
7451
+ if (res && typeof res.then === "function") {
7452
+ await res;
7453
+ }
7454
+ enteredNative = Boolean(
7455
+ document.fullscreenElement === host || document.fullscreenElement === viewport || document.webkitFullscreenElement === host || document.webkitFullscreenElement === viewport || document.mozFullScreenElement === host || document.msFullscreenElement === host
7456
+ );
7457
+ } catch {
7458
+ enteredNative = false;
7459
+ }
7356
7460
  }
7357
- } else {
7461
+ }
7462
+ if (!enteredNative) {
7358
7463
  isPseudoFull = true;
7359
- host.classList.add("markdy--pseudo-fullscreen");
7360
7464
  syncFullscreenState();
7361
7465
  }
7362
7466
  } else {
7363
7467
  if (isPseudoFull) {
7364
7468
  isPseudoFull = false;
7365
- host.classList.remove("markdy--pseudo-fullscreen");
7366
7469
  syncFullscreenState();
7367
7470
  } else {
7368
7471
  const exit = document.exitFullscreen?.bind(document) || document.webkitExitFullscreen?.bind(document) || document.mozCancelFullScreen?.bind(document) || document.msExitFullscreen?.bind(document);
7369
7472
  if (exit) {
7370
- await exit();
7473
+ try {
7474
+ const res = exit();
7475
+ if (res && typeof res.then === "function") {
7476
+ await res;
7477
+ }
7478
+ } catch {
7479
+ }
7371
7480
  }
7481
+ isPseudoFull = false;
7482
+ syncFullscreenState();
7372
7483
  }
7373
7484
  }
7374
7485
  } catch {
7375
7486
  if (!isPseudoFull) {
7376
7487
  isPseudoFull = true;
7377
- host.classList.add("markdy--pseudo-fullscreen");
7378
7488
  syncFullscreenState();
7379
7489
  } else {
7380
7490
  isPseudoFull = false;
7381
- host.classList.remove("markdy--pseudo-fullscreen");
7382
7491
  syncFullscreenState();
7383
7492
  }
7384
7493
  }
@@ -7390,7 +7499,6 @@ function createDiagram(opts) {
7390
7499
  const handleEscKey = (e) => {
7391
7500
  if (e.key === "Escape" && isPseudoFull) {
7392
7501
  isPseudoFull = false;
7393
- host.classList.remove("markdy--pseudo-fullscreen");
7394
7502
  syncFullscreenState();
7395
7503
  }
7396
7504
  };
@@ -7405,7 +7513,12 @@ function createDiagram(opts) {
7405
7513
  document.removeEventListener("mozfullscreenchange", syncFullscreenState);
7406
7514
  document.removeEventListener("MSFullscreenChange", syncFullscreenState);
7407
7515
  window.removeEventListener("keydown", handleEscKey);
7516
+ if (originalBodyOverflow !== null && typeof document !== "undefined" && document.body) {
7517
+ document.body.style.overflow = originalBodyOverflow;
7518
+ originalBodyOverflow = null;
7519
+ }
7408
7520
  if (isPseudoFull) {
7521
+ isPseudoFull = false;
7409
7522
  host.classList.remove("markdy--pseudo-fullscreen");
7410
7523
  host.classList.remove("markdy-fullscreen-host");
7411
7524
  }
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.2",
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.2"
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.2"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",