@markdy/renderer-dom 1.3.2 → 1.4.0

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
@@ -128,6 +128,29 @@ interface DiagramOptions {
128
128
  onTimeUpdate?: (seconds: number, durationSeconds: number) => void;
129
129
  onPlayStateChange?: (playing: boolean) => void;
130
130
  onEnded?: () => void;
131
+ /**
132
+ * Adaptive orientation & responsive layout mode.
133
+ * When true or "auto", switches to vertical Top-to-Bottom (TB) on mobile / portrait viewports,
134
+ * and horizontal Left-to-Right (LR) on desktop / landscape viewports.
135
+ * Defaults to true.
136
+ */
137
+ responsiveLayout?: boolean;
138
+ /**
139
+ * Auto-scaling mode for diagram framing:
140
+ * - "width" (default): Width-First Responsiveness (scale factor = containerWidth / contentWidth, filling 95% - 100% width).
141
+ * - "contain": Scales to fit both width and height within container bounds.
142
+ */
143
+ fitMode?: "width" | "contain";
144
+ /**
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
+ */
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;
131
154
  }
132
155
  interface Diagram {
133
156
  play(): void;
@@ -155,6 +178,17 @@ interface Diagram {
155
178
  * Default light mode is "paper", default dark mode is "nebula".
156
179
  */
157
180
  declare function detectHostTheme(container?: HTMLElement): "nebula" | "paper";
181
+ declare function computeDiagramContentBounds(plan: RenderPlan, options?: {
182
+ tight?: boolean;
183
+ padding?: number;
184
+ }): {
185
+ minX: number;
186
+ minY: number;
187
+ maxX: number;
188
+ maxY: number;
189
+ width: number;
190
+ height: number;
191
+ };
158
192
  declare function createDiagram(opts: DiagramOptions): Diagram;
159
193
 
160
194
  type SvgSpec = Array<[string, Record<string, string>]>;
@@ -277,4 +311,4 @@ declare function exportRouteShareCard(containerEl: HTMLElement, route: RouteCard
277
311
  */
278
312
  declare function exportReachShareCard(containerEl: HTMLElement, reach: ReachCardOptions, options?: ShareCardOptions): Promise<Blob>;
279
313
 
280
- export { type AnimationRecordFrame, type BlastRadiusResult, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type ReachCardOptions, type RouteCardOptions, type ShareCardOptions, type SvgExportOptions, type TimelineController, applyImpactHighlight, calculateBlastRadius, clearImpactHighlight, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsShareCard, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, exportReachShareCard, exportRouteShareCard, findShortestRoute, iconKeyForNode, renderPureVectorSvg, renderShareCardSvg };
314
+ export { type AnimationRecordFrame, type BlastRadiusResult, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type ReachCardOptions, type RouteCardOptions, type ShareCardOptions, type SvgExportOptions, type TimelineController, applyImpactHighlight, calculateBlastRadius, clearImpactHighlight, computeDiagramContentBounds, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsShareCard, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, exportReachShareCard, exportRouteShareCard, findShortestRoute, iconKeyForNode, renderPureVectorSvg, renderShareCardSvg };
package/dist/index.js CHANGED
@@ -687,6 +687,16 @@ function circleBoundaryRoute(from, to) {
687
687
  const uy = dy / distance;
688
688
  const fromRadius = Math.min(from.width, from.height) / 2;
689
689
  const toRadius = Math.min(to.width, to.height) / 2;
690
+ if (distance < fromRadius + toRadius) {
691
+ const midX = (fromCenter.x + toCenter.x) / 2;
692
+ const midY = (fromCenter.y + toCenter.y) / 2;
693
+ const overlap = fromRadius + toRadius - distance;
694
+ const halfSpan = Math.max(24, Math.min(64, overlap * 0.5));
695
+ return dedupePoints([
696
+ { x: midX - ux * halfSpan, y: midY - uy * halfSpan },
697
+ { x: midX + ux * halfSpan, y: midY + uy * halfSpan }
698
+ ]);
699
+ }
690
700
  return dedupePoints([
691
701
  { x: fromCenter.x + ux * fromRadius, y: fromCenter.y + uy * fromRadius },
692
702
  { x: toCenter.x - ux * toRadius, y: toCenter.y - uy * toRadius }
@@ -930,7 +940,7 @@ function createEdgeRuntime(svg, from, to, kind, label, theme, sceneId, routeObst
930
940
  for (let i = 0; i < points.length - 1; i++) {
931
941
  longestSegLen = Math.max(longestSegLen, Math.hypot(points[i + 1].x - points[i].x, points[i + 1].y - points[i].y));
932
942
  }
933
- const maxAvailW = Math.max(48, longestSegLen - 24);
943
+ const maxAvailW = Math.max(90, longestSegLen - 24);
934
944
  const lines = wrapFlowLabelText(label, maxAvailW);
935
945
  const maxChars = Math.max(...lines.map((l) => l.length));
936
946
  const textWidth = Math.max(36, maxChars * 6.6 + 8);
@@ -1960,46 +1970,92 @@ function mountTimelineLayer(layer, nodes, theme, bounds) {
1960
1970
  layer.appendChild(svg);
1961
1971
  const SAFE = 40;
1962
1972
  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
1973
  const strokeAxis = theme?.edges?.dependency ?? theme?.rule ?? theme?.border ?? "#64748b";
1968
1974
  const strokeBorder = theme?.edges?.dependency ?? theme?.border ?? "#64748b";
1969
1975
  const accentColor = theme?.accent ?? "#38bdf8";
1970
1976
  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);
1977
+ 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);
1978
+ if (isVertical) {
1979
+ const centerX = bounds.width / 2;
1980
+ const minY = Math.min(...nodes.map((n) => n.y)) - 16;
1981
+ const maxY = Math.max(...nodes.map((n) => n.y + n.height)) + 16;
1982
+ const axis = doc.createElementNS("http://www.w3.org/2000/svg", "line");
1983
+ axis.setAttribute("class", "markdy-timeline-axis");
1984
+ axis.setAttribute("x1", String(centerX));
1985
+ axis.setAttribute("y1", String(Math.max(SAFE, minY)));
1986
+ axis.setAttribute("x2", String(centerX));
1987
+ axis.setAttribute("y2", String(Math.min(bounds.height - SAFE, maxY)));
1988
+ axis.setAttribute("stroke", strokeAxis);
1989
+ axis.setAttribute("stroke-width", "2");
1990
+ axis.setAttribute("stroke-linecap", "round");
1991
+ axis.setAttribute("opacity", "0.75");
1992
+ svg.appendChild(axis);
1993
+ for (const node of nodes) {
1994
+ const nodeCenterY = node.y + node.height / 2;
1995
+ const isLeft = node.x + node.width / 2 < centerX;
1996
+ const targetX = isLeft ? node.x + node.width : node.x;
1997
+ const stem = doc.createElementNS("http://www.w3.org/2000/svg", "line");
1998
+ stem.setAttribute("class", "markdy-timeline-stem");
1999
+ stem.setAttribute("x1", String(centerX));
2000
+ stem.setAttribute("y1", String(nodeCenterY));
2001
+ stem.setAttribute("x2", String(targetX));
2002
+ stem.setAttribute("y2", String(nodeCenterY));
2003
+ stem.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2004
+ stem.setAttribute("stroke-width", node.focal ? "2" : "1.5");
2005
+ stem.setAttribute("stroke-dasharray", node.focal ? "none" : "4 4");
2006
+ stem.setAttribute("opacity", node.focal ? "0.95" : "0.75");
2007
+ svg.appendChild(stem);
2008
+ const pip = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
2009
+ pip.setAttribute("class", "markdy-timeline-pip");
2010
+ pip.setAttribute("cx", String(centerX));
2011
+ pip.setAttribute("cy", String(nodeCenterY));
2012
+ pip.setAttribute("r", node.focal ? "5.5" : "4");
2013
+ pip.setAttribute("fill", node.focal ? accentColor : surfaceFill);
2014
+ pip.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2015
+ pip.setAttribute("stroke-width", "2");
2016
+ svg.appendChild(pip);
2017
+ }
2018
+ } else {
2019
+ const contentH = bounds.height - SAFE - TITLE_BAND - SAFE;
2020
+ const baselineY = TITLE_BAND + contentH / 2;
2021
+ const minX = Math.min(...nodes.map((n) => n.x)) - 20;
2022
+ const maxX = Math.max(...nodes.map((n) => n.x + n.width)) + 20;
2023
+ const axis = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2024
+ axis.setAttribute("class", "markdy-timeline-axis");
2025
+ axis.setAttribute("x1", String(Math.max(40, minX)));
2026
+ axis.setAttribute("y1", String(baselineY));
2027
+ axis.setAttribute("x2", String(Math.min(bounds.width - 40, maxX)));
2028
+ axis.setAttribute("y2", String(baselineY));
2029
+ axis.setAttribute("stroke", strokeAxis);
2030
+ axis.setAttribute("stroke-width", "2");
2031
+ axis.setAttribute("stroke-linecap", "round");
2032
+ axis.setAttribute("opacity", "0.75");
2033
+ svg.appendChild(axis);
2034
+ for (const node of nodes) {
2035
+ const nodeCenterX = node.x + node.width / 2;
2036
+ const isAbove = node.y + node.height <= baselineY + 10;
2037
+ const targetY = isAbove ? node.y + node.height : node.y;
2038
+ const stem = doc.createElementNS("http://www.w3.org/2000/svg", "line");
2039
+ stem.setAttribute("class", "markdy-timeline-stem");
2040
+ stem.setAttribute("x1", String(nodeCenterX));
2041
+ stem.setAttribute("y1", String(baselineY));
2042
+ stem.setAttribute("x2", String(nodeCenterX));
2043
+ stem.setAttribute("y2", String(targetY));
2044
+ stem.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2045
+ stem.setAttribute("stroke-width", node.focal ? "2" : "1.5");
2046
+ stem.setAttribute("stroke-dasharray", node.focal ? "none" : "4 4");
2047
+ stem.setAttribute("opacity", node.focal ? "0.95" : "0.75");
2048
+ svg.appendChild(stem);
2049
+ const pip = doc.createElementNS("http://www.w3.org/2000/svg", "circle");
2050
+ pip.setAttribute("class", "markdy-timeline-pip");
2051
+ pip.setAttribute("cx", String(nodeCenterX));
2052
+ pip.setAttribute("cy", String(baselineY));
2053
+ pip.setAttribute("r", node.focal ? "5.5" : "4");
2054
+ pip.setAttribute("fill", node.focal ? accentColor : surfaceFill);
2055
+ pip.setAttribute("stroke", node.focal ? accentColor : strokeBorder);
2056
+ pip.setAttribute("stroke-width", "2");
2057
+ svg.appendChild(pip);
2058
+ }
2003
2059
  }
2004
2060
  }
2005
2061
 
@@ -2258,9 +2314,10 @@ function ensureNodeStyles(doc) {
2258
2314
  .markdy-node[data-role="data"] { border-radius: 12px 12px 16px 16px; }
2259
2315
  .markdy-scene-title {
2260
2316
  position: absolute;
2261
- left: 48px;
2262
- top: 28px;
2263
- right: 48px;
2317
+ left: 56px;
2318
+ top: 32px;
2319
+ right: 56px;
2320
+ max-width: calc(100% - 112px);
2264
2321
  z-index: 130;
2265
2322
  font-size: 30px;
2266
2323
  font-weight: 700;
@@ -2269,6 +2326,8 @@ function ensureNodeStyles(doc) {
2269
2326
  opacity: 0;
2270
2327
  transform: translateY(-6px);
2271
2328
  font-family: var(--md-font-title, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif);
2329
+ pointer-events: none;
2330
+ word-break: break-word;
2272
2331
  }
2273
2332
  .markdy-scene-title[data-visible="1"] {
2274
2333
  opacity: 1;
@@ -2445,15 +2504,26 @@ function ensureNodeStyles(doc) {
2445
2504
  border-radius: 999px;
2446
2505
  }
2447
2506
  .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));
2507
+ background: color-mix(in srgb, var(--md-surface-raised) 20%, transparent);
2508
+ border: 1.5px solid color-mix(in srgb, var(--md-role-color, var(--md-accent)) 45%, var(--md-border) 55%);
2509
+ border-radius: 20px;
2510
+ box-shadow: inset 0 0 0 1px var(--md-hairline), 0 8px 24px -6px var(--md-shadow, rgba(0,0,0,0.25));
2451
2511
  backdrop-filter: blur(8px);
2452
2512
  -webkit-backdrop-filter: blur(8px);
2513
+ pointer-events: none;
2453
2514
  }
2454
2515
  .markdy-node[data-is-container="1"] .markdy-node__body {
2455
- align-items: flex-start;
2456
- padding: 12px 16px;
2516
+ height: auto;
2517
+ min-height: 44px;
2518
+ align-items: center;
2519
+ padding: 10px 18px;
2520
+ pointer-events: auto;
2521
+ }
2522
+ .markdy-node[data-is-container="1"] .markdy-node__label {
2523
+ font-size: 13.5px;
2524
+ font-weight: 700;
2525
+ letter-spacing: -0.01em;
2526
+ color: var(--md-text);
2457
2527
  }
2458
2528
  .markdy-node[data-is-container="1"][data-focal="1"] {
2459
2529
  background: color-mix(in srgb, var(--md-accent-tint, var(--md-accent)) 16%, transparent);
@@ -3302,7 +3372,7 @@ function mountTreeBuses(layer, buses, theme) {
3302
3372
  Object.assign(layer.style, {
3303
3373
  position: "absolute",
3304
3374
  inset: "0",
3305
- zIndex: "42",
3375
+ zIndex: "52",
3306
3376
  pointerEvents: "none"
3307
3377
  });
3308
3378
  const doc = layer.ownerDocument;
@@ -3319,29 +3389,50 @@ function mountTreeBuses(layer, buses, theme) {
3319
3389
  for (const bus of buses) {
3320
3390
  const group = doc.createElementNS("http://www.w3.org/2000/svg", "g");
3321
3391
  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([
3327
- { x: bus.parentX, y: bus.parentY },
3328
- { x: childX, y: bus.childY }
3329
- ], 12);
3330
- } else {
3331
- d = toPathD([
3392
+ if (bus.vertical) {
3393
+ bus.childXs.forEach((childX, idx) => {
3394
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
3395
+ const pathEl = doc.createElementNS("http://www.w3.org/2000/svg", "path");
3396
+ const d = toPathD([
3332
3397
  { 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);
3398
+ { x: bus.parentX, y: targetY },
3399
+ { x: childX, y: targetY }
3400
+ ], 10);
3401
+ pathEl.setAttribute("d", d);
3402
+ pathEl.setAttribute("fill", "none");
3403
+ pathEl.setAttribute("stroke", stroke);
3404
+ pathEl.setAttribute("stroke-width", "1.6");
3405
+ pathEl.setAttribute("stroke-linecap", "round");
3406
+ pathEl.setAttribute("stroke-linejoin", "round");
3407
+ group.appendChild(pathEl);
3408
+ });
3409
+ } else {
3410
+ bus.childXs.forEach((childX, idx) => {
3411
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
3412
+ const pathEl = doc.createElementNS("http://www.w3.org/2000/svg", "path");
3413
+ let d;
3414
+ if (Math.abs(childX - bus.parentX) < 1) {
3415
+ d = toPathD([
3416
+ { x: bus.parentX, y: bus.parentY },
3417
+ { x: childX, y: targetY }
3418
+ ], 12);
3419
+ } else {
3420
+ const branchY = bus.childYs ? (bus.parentY + targetY) / 2 : bus.branchY;
3421
+ d = toPathD([
3422
+ { x: bus.parentX, y: bus.parentY },
3423
+ { x: bus.parentX, y: branchY },
3424
+ { x: childX, y: branchY },
3425
+ { x: childX, y: targetY }
3426
+ ], 12);
3427
+ }
3428
+ pathEl.setAttribute("d", d);
3429
+ pathEl.setAttribute("fill", "none");
3430
+ pathEl.setAttribute("stroke", stroke);
3431
+ pathEl.setAttribute("stroke-width", "1.6");
3432
+ pathEl.setAttribute("stroke-linecap", "round");
3433
+ pathEl.setAttribute("stroke-linejoin", "round");
3434
+ group.appendChild(pathEl);
3435
+ });
3345
3436
  }
3346
3437
  svg.appendChild(group);
3347
3438
  }
@@ -4479,23 +4570,38 @@ function renderPureVectorSvg(plan, options = {}) {
4479
4570
  `;
4480
4571
  const busStroke = theme.edges?.dependency ?? theme.border ?? "#64748b";
4481
4572
  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([
4573
+ if (bus.vertical) {
4574
+ bus.childXs.forEach((childX, idx) => {
4575
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
4576
+ const d = toPathD([
4491
4577
  { 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"/>
4578
+ { x: bus.parentX, y: targetY },
4579
+ { x: childX, y: targetY }
4580
+ ], 10);
4581
+ svg += ` <path d="${d}" fill="none" stroke="${busStroke}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
4498
4582
  `;
4583
+ });
4584
+ } else {
4585
+ bus.childXs.forEach((childX, idx) => {
4586
+ const targetY = bus.childYs ? bus.childYs[idx] ?? bus.childY : bus.childY;
4587
+ let d;
4588
+ if (Math.abs(childX - bus.parentX) < 1) {
4589
+ d = toPathD([
4590
+ { x: bus.parentX, y: bus.parentY },
4591
+ { x: childX, y: targetY }
4592
+ ], 12);
4593
+ } else {
4594
+ const branchY = bus.childYs ? (bus.parentY + targetY) / 2 : bus.branchY;
4595
+ d = toPathD([
4596
+ { x: bus.parentX, y: bus.parentY },
4597
+ { x: bus.parentX, y: branchY },
4598
+ { x: childX, y: branchY },
4599
+ { x: childX, y: targetY }
4600
+ ], 12);
4601
+ }
4602
+ svg += ` <path d="${d}" fill="none" stroke="${busStroke}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
4603
+ `;
4604
+ });
4499
4605
  }
4500
4606
  }
4501
4607
  svg += ` </g>
@@ -4560,6 +4666,57 @@ function renderPureVectorSvg(plan, options = {}) {
4560
4666
  }
4561
4667
  }
4562
4668
  svg += ` </g>
4669
+ `;
4670
+ }
4671
+ if (plan.diagramType === "timeline" && plan.nodes && plan.nodes.length > 0) {
4672
+ svg += ` <!-- Timeline Track Layer -->
4673
+ <g class="markdy-timeline-layer">
4674
+ `;
4675
+ 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);
4676
+ const strokeAxis = theme.edges?.dependency ?? theme.rule ?? theme.border ?? "#64748b";
4677
+ const strokeBorder = theme.edges?.dependency ?? theme.border ?? "#64748b";
4678
+ const surfaceFill = theme.surfaceRaised ?? theme.surface ?? (isDark ? "#1e293b" : "#ffffff");
4679
+ if (isVertical) {
4680
+ const centerX = width / 2;
4681
+ const minY = Math.min(...plan.nodes.map((n) => n.y)) - 16;
4682
+ const maxY = Math.max(...plan.nodes.map((n) => n.y + n.height)) + 16;
4683
+ 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"/>
4684
+ `;
4685
+ for (const node of plan.nodes) {
4686
+ const nodeCenterY = node.y + node.height / 2;
4687
+ const isLeft = node.x + node.width / 2 < centerX;
4688
+ const targetX = isLeft ? node.x + node.width : node.x;
4689
+ const focal = node.focal;
4690
+ const stemStroke = focal ? accent : strokeBorder;
4691
+ const stemDash = focal ? "" : 'stroke-dasharray="4 4"';
4692
+ 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"}"/>
4693
+ `;
4694
+ 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"/>
4695
+ `;
4696
+ }
4697
+ } else {
4698
+ const SAFE = 40;
4699
+ const TITLE_BAND = 64;
4700
+ const contentH = height - SAFE - TITLE_BAND - SAFE;
4701
+ const baselineY = TITLE_BAND + contentH / 2;
4702
+ const minX = Math.min(...plan.nodes.map((n) => n.x)) - 20;
4703
+ const maxX = Math.max(...plan.nodes.map((n) => n.x + n.width)) + 20;
4704
+ 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"/>
4705
+ `;
4706
+ for (const node of plan.nodes) {
4707
+ const nodeCenterX = node.x + node.width / 2;
4708
+ const isAbove = node.y + node.height <= baselineY + 10;
4709
+ const targetY = isAbove ? node.y + node.height : node.y;
4710
+ const focal = node.focal;
4711
+ const stemStroke = focal ? accent : strokeBorder;
4712
+ const stemDash = focal ? "" : 'stroke-dasharray="4 4"';
4713
+ 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"}"/>
4714
+ `;
4715
+ 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"/>
4716
+ `;
4717
+ }
4718
+ }
4719
+ svg += ` </g>
4563
4720
  `;
4564
4721
  }
4565
4722
  if (plan.diagramType !== "sequence" && plan.edges && plan.edges.length > 0) {
@@ -5741,10 +5898,28 @@ function detectHostTheme(container) {
5741
5898
  }
5742
5899
  return "paper";
5743
5900
  }
5744
- function computeDiagramContentBounds(plan) {
5901
+ var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
5902
+ "quadrant",
5903
+ "swimlane",
5904
+ "timeline",
5905
+ "radar",
5906
+ "constellation",
5907
+ "gantt"
5908
+ ]);
5909
+ function computeDiagramContentBounds(plan, options) {
5745
5910
  if (!plan.nodes || plan.nodes.length === 0) {
5746
5911
  return { minX: 0, minY: 0, maxX: plan.meta.width, maxY: plan.meta.height, width: plan.meta.width, height: plan.meta.height };
5747
5912
  }
5913
+ if (CANVAS_WIDE_ARCHETYPES.has(plan.diagramType)) {
5914
+ return {
5915
+ minX: 0,
5916
+ minY: 0,
5917
+ maxX: plan.meta.width,
5918
+ maxY: plan.meta.height,
5919
+ width: plan.meta.width,
5920
+ height: plan.meta.height
5921
+ };
5922
+ }
5748
5923
  let minX = Infinity;
5749
5924
  let minY = Infinity;
5750
5925
  let maxX = -Infinity;
@@ -5767,26 +5942,61 @@ function computeDiagramContentBounds(plan) {
5767
5942
  maxX = Math.max(maxX, bus.parentX, ...bus.childXs.length ? bus.childXs : [bus.parentX]);
5768
5943
  maxY = Math.max(maxY, bus.parentY, bus.branchY, bus.childY);
5769
5944
  }
5945
+ for (const edge of plan.edges ?? []) {
5946
+ if (edge.selfLoop) {
5947
+ const fromNode = plan.nodes.find((n) => n.id === edge.from);
5948
+ if (fromNode) {
5949
+ minY = Math.min(minY, fromNode.y - 40);
5950
+ maxY = Math.max(maxY, fromNode.y + fromNode.height + 40);
5951
+ }
5952
+ }
5953
+ }
5770
5954
  if (plan.diagramType === "sequence") {
5771
5955
  let maxMsgY = minY;
5772
5956
  for (const msg of plan.sequenceMessages ?? []) {
5773
- maxMsgY = Math.max(maxMsgY, msg.y + 60);
5957
+ maxMsgY = Math.max(maxMsgY, msg.y + 70);
5774
5958
  }
5775
5959
  for (const act of plan.sequenceActivations ?? []) {
5776
5960
  maxMsgY = Math.max(maxMsgY, act.y + act.height + 40);
5777
5961
  }
5778
- maxY = Math.max(maxY, maxMsgY, Math.min(plan.meta.height, 420));
5779
- }
5780
- if (plan.title) {
5781
- minY = Math.min(minY, 20);
5782
- }
5783
- const pad = 36;
5784
- minX = Math.max(0, minX - pad);
5785
- minY = Math.max(0, minY - pad);
5786
- maxX = Math.min(plan.meta.width, maxX + pad);
5787
- maxY = Math.min(plan.meta.height, maxY + pad);
5788
- const width = Math.max(maxX - minX, 200);
5789
- const height = Math.max(maxY - minY, 140);
5962
+ maxY = Math.max(maxY, maxMsgY, plan.meta.height - 24);
5963
+ }
5964
+ const titleText = (plan.title ?? plan.meta?.title ?? "").trim();
5965
+ const hasTitle = titleText.length > 0;
5966
+ if (hasTitle) {
5967
+ minX = 0;
5968
+ minY = 0;
5969
+ const titleEstimatedW = Math.min(plan.meta.width, 56 + titleText.length * 17 + 56);
5970
+ maxX = Math.max(maxX, titleEstimatedW);
5971
+ maxY = Math.max(maxY, 72);
5972
+ }
5973
+ const hasBeatCaptions = plan.beats && plan.beats.some((b) => b.label && b.label.trim().length > 0);
5974
+ if (hasBeatCaptions) {
5975
+ maxY = Math.max(maxY, plan.meta.height - 18);
5976
+ }
5977
+ for (const ann of plan.annotations ?? []) {
5978
+ const targetNode = plan.nodes.find((n) => n.id === ann.target);
5979
+ if (targetNode) {
5980
+ minX = Math.min(minX, targetNode.x - 24);
5981
+ maxX = Math.max(maxX, targetNode.x + targetNode.width + 24);
5982
+ minY = Math.min(minY, targetNode.y - 24);
5983
+ maxY = Math.max(maxY, targetNode.y + targetNode.height + 24);
5984
+ }
5985
+ }
5986
+ const defaultPad = plan.groupBoundaries && plan.groupBoundaries.length > 0 ? 28 : 22;
5987
+ const pad = options?.padding ?? (options?.tight === false ? 36 : defaultPad);
5988
+ minX = Math.max(-pad, minX - pad);
5989
+ minY = Math.max(-pad, minY - pad);
5990
+ maxX = Math.min(plan.meta.width + pad, maxX + pad);
5991
+ maxY = Math.min(plan.meta.height + pad, maxY + pad);
5992
+ if (minX > 0 && minX <= pad) minX = 0;
5993
+ if (minY > 0 && minY <= pad) minY = 0;
5994
+ if (hasTitle) {
5995
+ minX = 0;
5996
+ minY = 0;
5997
+ }
5998
+ const width = Math.max(maxX - minX, 100);
5999
+ const height = Math.max(maxY - minY, 80);
5790
6000
  return { minX, minY, maxX, maxY, width, height };
5791
6001
  }
5792
6002
  function createDiagram(opts) {
@@ -5809,16 +6019,40 @@ function createDiagram(opts) {
5809
6019
  onWarning = (w) => console.warn(`[markdy] line ${w.line}: ${w.message}`),
5810
6020
  onTimeUpdate,
5811
6021
  onPlayStateChange,
5812
- onEnded
6022
+ onEnded,
6023
+ responsiveLayout = true,
6024
+ fitMode = "width",
6025
+ targetWidthRatio = 0.96,
6026
+ contentPadding
5813
6027
  } = opts;
6028
+ function detectContainerOrientation() {
6029
+ const cWidth = container?.clientWidth || 0;
6030
+ const cHeight = container?.clientHeight || 0;
6031
+ if (typeof window === "undefined") {
6032
+ if (cWidth > 0 && cHeight > 0) {
6033
+ return cHeight > cWidth * 1.05 ? "portrait" : "landscape";
6034
+ }
6035
+ return "landscape";
6036
+ }
6037
+ const isMobileViewport = window.innerWidth < 768;
6038
+ if (isMobileViewport) {
6039
+ return "portrait";
6040
+ }
6041
+ if (cWidth > 0 && cHeight > 0) {
6042
+ if (cHeight > cWidth * 1.18) return "portrait";
6043
+ return "landscape";
6044
+ }
6045
+ return window.innerWidth < window.innerHeight ? "portrait" : "landscape";
6046
+ }
5814
6047
  const ast = parse(code);
5815
6048
  for (const w of ast.diagnostics) {
5816
6049
  if (w.severity === "warning") onWarning(w);
5817
6050
  }
5818
6051
  const hasExplicitDirection = ast.meta.explicitDirection === true;
5819
- if (!hasExplicitDirection) {
5820
- const isPortrait = typeof window !== "undefined" ? window.innerWidth < window.innerHeight || container && container.clientWidth > 0 && container.clientWidth < 640 : false;
5821
- ast.meta.direction = isPortrait ? "TB" : "LR";
6052
+ const shouldAdaptOrientation = responsiveLayout !== false && !hasExplicitDirection;
6053
+ let activeOrientation = detectContainerOrientation();
6054
+ if (shouldAdaptOrientation) {
6055
+ ast.meta.direction = activeOrientation === "portrait" ? "TB" : "LR";
5822
6056
  }
5823
6057
  if (!ast.meta.explicitWidth || !ast.meta.explicitHeight) {
5824
6058
  const dims = computeAdaptiveDimensions(ast);
@@ -5893,8 +6127,8 @@ function createDiagram(opts) {
5893
6127
  });
5894
6128
  if (container.style.aspectRatio) container.style.aspectRatio = "unset";
5895
6129
  if (container.style.overflow === "hidden") container.style.overflow = "visible";
5896
- const initialBounds = computeDiagramContentBounds(plan);
5897
- const naturalRatio = `${plan.meta.width} / ${plan.meta.height}`;
6130
+ const initialBounds = computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6131
+ const contentRatio = `${initialBounds.width} / ${initialBounds.height}`;
5898
6132
  const viewport = document.createElement("div");
5899
6133
  viewport.className = "markdy-viewport";
5900
6134
  applyThemeVariables(viewport, plan.theme);
@@ -5903,7 +6137,7 @@ function createDiagram(opts) {
5903
6137
  width: "100%",
5904
6138
  maxWidth: "100%",
5905
6139
  maxHeight: "100%",
5906
- aspectRatio: naturalRatio,
6140
+ aspectRatio: contentRatio,
5907
6141
  overflow: "hidden",
5908
6142
  boxSizing: "border-box",
5909
6143
  flex: "1 1 auto",
@@ -6007,7 +6241,7 @@ function createDiagram(opts) {
6007
6241
  left: "0",
6008
6242
  width: `${plan.meta.width}px`,
6009
6243
  height: `${plan.meta.height}px`,
6010
- overflow: "hidden",
6244
+ overflow: "visible",
6011
6245
  userSelect: "none",
6012
6246
  transformOrigin: "0 0"
6013
6247
  });
@@ -6118,51 +6352,9 @@ function createDiagram(opts) {
6118
6352
  nodeLayer.appendChild(el);
6119
6353
  nodeEls.set(node.id, el);
6120
6354
  }
6121
- let fitScale = 1;
6122
- let sceneOffsetX = 0;
6123
- let sceneOffsetY = 0;
6124
- function computeContentBounds() {
6125
- return computeDiagramContentBounds(plan);
6126
- }
6127
- function scaleScene() {
6128
- const isBrowserLayout = (viewport.clientWidth || container.clientWidth || 0) > 0;
6129
- if (!isBrowserLayout) {
6130
- fitScale = 1;
6131
- sceneOffsetX = 0;
6132
- sceneOffsetY = 0;
6133
- scene.style.left = "0px";
6134
- scene.style.top = "0px";
6135
- scene.style.transformOrigin = "0 0";
6136
- scene.style.transform = "scale(1)";
6137
- return;
6138
- }
6139
- const vWidth = viewport.clientWidth || container.clientWidth || plan.meta.width;
6140
- const fallbackHeight = vWidth * plan.meta.height / plan.meta.width;
6141
- const vHeight = viewport.clientHeight || container.clientHeight || fallbackHeight;
6142
- const padX = Math.max(12, Math.min(32, vWidth * 0.03));
6143
- const padY = Math.max(12, Math.min(28, vHeight * 0.03));
6144
- const availW = Math.max(80, vWidth - padX * 2);
6145
- const availH = Math.max(80, vHeight - padY * 2);
6146
- const canvasScaleX = availW / plan.meta.width;
6147
- const canvasScaleY = availH / plan.meta.height;
6148
- fitScale = Math.min(canvasScaleX, canvasScaleY);
6149
- if (!Number.isFinite(fitScale) || fitScale <= 0) fitScale = 1;
6150
- const scaledWidth = plan.meta.width * fitScale;
6151
- const scaledHeight = plan.meta.height * fitScale;
6152
- sceneOffsetX = (vWidth - scaledWidth) / 2;
6153
- sceneOffsetY = (vHeight - scaledHeight) / 2;
6154
- scene.style.left = `${sceneOffsetX}px`;
6155
- scene.style.top = `${sceneOffsetY}px`;
6156
- scene.style.transformOrigin = "0 0";
6157
- scene.style.transform = `scale(${fitScale})`;
6158
- }
6159
- scaleScene();
6160
- const resizeObserver = typeof ResizeObserver === "function" ? new ResizeObserver(scaleScene) : null;
6161
- resizeObserver?.observe(viewport);
6162
- if (container !== viewport) resizeObserver?.observe(container);
6163
6355
  const edgeRuntimes = /* @__PURE__ */ new Map();
6164
6356
  const edgeSceneId = createEdgeSceneId();
6165
- const sequenceAnims = plan.diagramType === "sequence" ? mountSequenceLayer(
6357
+ let sequenceAnims = plan.diagramType === "sequence" ? mountSequenceLayer(
6166
6358
  sequenceLayer,
6167
6359
  plan.nodes,
6168
6360
  plan.sequenceMessages,
@@ -6170,7 +6362,7 @@ function createDiagram(opts) {
6170
6362
  plan.theme,
6171
6363
  { width: plan.meta.width, height: plan.meta.height }
6172
6364
  ) : [];
6173
- const allAnims = [
6365
+ let allAnims = [
6174
6366
  ...sequenceAnims,
6175
6367
  ...buildStructuralEdgeAnimations(
6176
6368
  plan.edges,
@@ -6197,6 +6389,159 @@ function createDiagram(opts) {
6197
6389
  anim.pause();
6198
6390
  anim.currentTime = 0;
6199
6391
  }
6392
+ let fitScale = 1;
6393
+ let sceneOffsetX = 0;
6394
+ let sceneOffsetY = 0;
6395
+ function computeContentBounds() {
6396
+ return computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6397
+ }
6398
+ function relayoutOrientation(newDirection) {
6399
+ ast.meta.direction = newDirection;
6400
+ const dims = computeAdaptiveDimensions(ast);
6401
+ if (!ast.meta.explicitWidth) ast.meta.width = dims.width;
6402
+ if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
6403
+ const newPlan = compilePlan(ast, plan.theme);
6404
+ const newBounds = computeDiagramContentBounds(newPlan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6405
+ scene.style.width = `${newPlan.meta.width}px`;
6406
+ scene.style.height = `${newPlan.meta.height}px`;
6407
+ viewport.style.aspectRatio = `${newBounds.width} / ${newBounds.height}`;
6408
+ plan.nodes = newPlan.nodes;
6409
+ plan.edges = newPlan.edges;
6410
+ plan.groupBoundaries = newPlan.groupBoundaries;
6411
+ plan.treeBuses = newPlan.treeBuses;
6412
+ plan.cues = newPlan.cues;
6413
+ plan.beats = newPlan.beats;
6414
+ plan.meta = newPlan.meta;
6415
+ for (const node of plan.nodes) {
6416
+ const el = nodeEls.get(node.id);
6417
+ if (el) {
6418
+ el.style.left = `${node.x}px`;
6419
+ el.style.top = `${node.y}px`;
6420
+ el.style.width = `${node.width}px`;
6421
+ el.style.height = `${node.height}px`;
6422
+ el.style.setProperty("--md-node-w", `${node.width}px`);
6423
+ el.style.setProperty("--md-node-h", `${node.height}px`);
6424
+ }
6425
+ }
6426
+ treeLayer.innerHTML = "";
6427
+ mountTreeBuses(treeLayer, plan.treeBuses, plan.theme);
6428
+ groupLayer.innerHTML = "";
6429
+ mountGroupBoundaries(groupLayer, plan.groupBoundaries, plan.theme);
6430
+ constellationLayer.innerHTML = "";
6431
+ if (plan.diagramType === "constellation") {
6432
+ mountConstellationLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6433
+ } else if (plan.diagramType === "radar") {
6434
+ mountRadarLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6435
+ } else if (plan.diagramType === "timeline") {
6436
+ mountTimelineLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6437
+ } else if (plan.diagramType === "quadrant") {
6438
+ mountQuadrantLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6439
+ } else if (plan.diagramType === "swimlane") {
6440
+ mountSwimlaneLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6441
+ } else if (plan.diagramType === "gantt") {
6442
+ mountGanttLayer(constellationLayer, plan.nodes, plan.theme, { width: plan.meta.width, height: plan.meta.height });
6443
+ }
6444
+ structuralEdgeHost.innerHTML = "";
6445
+ edgeRuntimes.clear();
6446
+ const newStructuralAnims = buildStructuralEdgeAnimations(
6447
+ plan.edges,
6448
+ plan.nodes,
6449
+ plan.theme,
6450
+ structuralEdgeHost,
6451
+ { width: plan.meta.width, height: plan.meta.height },
6452
+ edgeRuntimes,
6453
+ edgeSceneId,
6454
+ plan.diagramType,
6455
+ plan.cues
6456
+ );
6457
+ for (const anim of allAnims) anim.cancel();
6458
+ allAnims = [
6459
+ ...plan.diagramType === "sequence" ? mountSequenceLayer(
6460
+ sequenceLayer,
6461
+ plan.nodes,
6462
+ plan.sequenceMessages,
6463
+ plan.sequenceActivations,
6464
+ plan.theme,
6465
+ { width: plan.meta.width, height: plan.meta.height }
6466
+ ) : [],
6467
+ ...newStructuralAnims,
6468
+ ...buildCueAnimations(
6469
+ plan.cues,
6470
+ nodeEls,
6471
+ plan.nodes,
6472
+ plan.theme,
6473
+ cameraLayer,
6474
+ titleEl,
6475
+ { width: plan.meta.width, height: plan.meta.height },
6476
+ plan.edges,
6477
+ edgeRuntimes,
6478
+ edgeSceneId,
6479
+ plan.diagramType
6480
+ ),
6481
+ ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6482
+ ];
6483
+ applyCurrentTime();
6484
+ scaleScene();
6485
+ }
6486
+ function scaleScene() {
6487
+ const isBrowserLayout = (viewport.clientWidth || container.clientWidth || 0) > 0;
6488
+ if (!isBrowserLayout) {
6489
+ fitScale = 1;
6490
+ sceneOffsetX = 0;
6491
+ sceneOffsetY = 0;
6492
+ scene.style.left = "0px";
6493
+ scene.style.top = "0px";
6494
+ scene.style.transformOrigin = "0 0";
6495
+ scene.style.transform = "scale(1)";
6496
+ return;
6497
+ }
6498
+ if (shouldAdaptOrientation) {
6499
+ const currentOrientation = detectContainerOrientation();
6500
+ if (currentOrientation !== activeOrientation) {
6501
+ activeOrientation = currentOrientation;
6502
+ relayoutOrientation(activeOrientation === "portrait" ? "TB" : "LR");
6503
+ return;
6504
+ }
6505
+ }
6506
+ const vWidth = viewport.clientWidth || container.clientWidth || plan.meta.width;
6507
+ const fallbackHeight = vWidth * plan.meta.height / plan.meta.width;
6508
+ const vHeight = viewport.clientHeight || container.clientHeight || fallbackHeight;
6509
+ const bounds = computeContentBounds();
6510
+ const contentW = bounds.width;
6511
+ const contentH = bounds.height;
6512
+ const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
6513
+ const widthScale = vWidth * targetRatio / contentW;
6514
+ if (fitMode === "contain") {
6515
+ const heightScale = (vHeight - 24) * targetRatio / contentH;
6516
+ fitScale = Math.min(widthScale, heightScale);
6517
+ } else {
6518
+ fitScale = widthScale;
6519
+ }
6520
+ if (!Number.isFinite(fitScale) || fitScale <= 0) fitScale = 1;
6521
+ scene.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6522
+ viewport.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6523
+ container.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6524
+ if (titleEl && contentW > 0) {
6525
+ titleEl.style.maxWidth = `${Math.max(contentW - 112, 280)}px`;
6526
+ }
6527
+ const scaledContentW = contentW * fitScale;
6528
+ const scaledContentH = contentH * fitScale;
6529
+ sceneOffsetX = (vWidth - scaledContentW) / 2 - bounds.minX * fitScale;
6530
+ if (fitMode === "contain") {
6531
+ sceneOffsetY = (vHeight - scaledContentH) / 2 - bounds.minY * fitScale;
6532
+ } else {
6533
+ const topSafeMargin = scaledContentH <= vHeight ? Math.max(14, Math.min(24, (vHeight - scaledContentH) / 2)) : 14;
6534
+ sceneOffsetY = topSafeMargin - bounds.minY * fitScale;
6535
+ }
6536
+ scene.style.left = `${sceneOffsetX}px`;
6537
+ scene.style.top = `${sceneOffsetY}px`;
6538
+ scene.style.transformOrigin = "0 0";
6539
+ scene.style.transform = `scale(${fitScale})`;
6540
+ }
6541
+ scaleScene();
6542
+ const resizeObserver = typeof ResizeObserver === "function" ? new ResizeObserver(scaleScene) : null;
6543
+ resizeObserver?.observe(viewport);
6544
+ if (container !== viewport) resizeObserver?.observe(container);
6200
6545
  let sceneMs = 0;
6201
6546
  let lastRafTs = null;
6202
6547
  let isPlaying = false;
@@ -7659,6 +8004,7 @@ export {
7659
8004
  applyImpactHighlight,
7660
8005
  calculateBlastRadius,
7661
8006
  clearImpactHighlight,
8007
+ computeDiagramContentBounds,
7662
8008
  createDiagram,
7663
8009
  detectHostTheme,
7664
8010
  encodeGifSequence,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
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.2"
49
+ "@markdy/core": "1.4.0"
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.2"
56
+ "@markdy/stdlib-systems": "1.4.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",