@markdy/renderer-dom 1.3.3 → 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
@@ -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
@@ -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([
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([
4486
4577
  { x: bus.parentX, y: bus.parentY },
4487
- { x: childX, y: bus.childY }
4488
- ], 12);
4489
- } else {
4490
- d = toPathD([
4491
- { 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"/>
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"/>
4498
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
  }
5901
+ var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
5902
+ "quadrant",
5903
+ "swimlane",
5904
+ "timeline",
5905
+ "radar",
5906
+ "constellation",
5907
+ "gantt"
5908
+ ]);
5744
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,6 +5942,15 @@ function computeDiagramContentBounds(plan, options) {
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 ?? []) {
@@ -5778,8 +5962,13 @@ function computeDiagramContentBounds(plan, options) {
5778
5962
  maxY = Math.max(maxY, maxMsgY, plan.meta.height - 24);
5779
5963
  }
5780
5964
  const titleText = (plan.title ?? plan.meta?.title ?? "").trim();
5781
- if (titleText.length > 0) {
5782
- minY = Math.min(minY, 20);
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);
5783
5972
  }
5784
5973
  const hasBeatCaptions = plan.beats && plan.beats.some((b) => b.label && b.label.trim().length > 0);
5785
5974
  if (hasBeatCaptions) {
@@ -5794,11 +5983,18 @@ function computeDiagramContentBounds(plan, options) {
5794
5983
  maxY = Math.max(maxY, targetNode.y + targetNode.height + 24);
5795
5984
  }
5796
5985
  }
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);
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
+ }
5802
5998
  const width = Math.max(maxX - minX, 100);
5803
5999
  const height = Math.max(maxY - minY, 80);
5804
6000
  return { minX, minY, maxX, maxY, width, height };
@@ -5826,7 +6022,8 @@ function createDiagram(opts) {
5826
6022
  onEnded,
5827
6023
  responsiveLayout = true,
5828
6024
  fitMode = "width",
5829
- targetWidthRatio = 0.98
6025
+ targetWidthRatio = 0.96,
6026
+ contentPadding
5830
6027
  } = opts;
5831
6028
  function detectContainerOrientation() {
5832
6029
  const cWidth = container?.clientWidth || 0;
@@ -5852,7 +6049,7 @@ function createDiagram(opts) {
5852
6049
  if (w.severity === "warning") onWarning(w);
5853
6050
  }
5854
6051
  const hasExplicitDirection = ast.meta.explicitDirection === true;
5855
- const shouldAdaptOrientation = responsiveLayout !== false && (!hasExplicitDirection || responsiveLayout === true);
6052
+ const shouldAdaptOrientation = responsiveLayout !== false && !hasExplicitDirection;
5856
6053
  let activeOrientation = detectContainerOrientation();
5857
6054
  if (shouldAdaptOrientation) {
5858
6055
  ast.meta.direction = activeOrientation === "portrait" ? "TB" : "LR";
@@ -5930,7 +6127,7 @@ function createDiagram(opts) {
5930
6127
  });
5931
6128
  if (container.style.aspectRatio) container.style.aspectRatio = "unset";
5932
6129
  if (container.style.overflow === "hidden") container.style.overflow = "visible";
5933
- const initialBounds = computeDiagramContentBounds(plan);
6130
+ const initialBounds = computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
5934
6131
  const contentRatio = `${initialBounds.width} / ${initialBounds.height}`;
5935
6132
  const viewport = document.createElement("div");
5936
6133
  viewport.className = "markdy-viewport";
@@ -6044,7 +6241,7 @@ function createDiagram(opts) {
6044
6241
  left: "0",
6045
6242
  width: `${plan.meta.width}px`,
6046
6243
  height: `${plan.meta.height}px`,
6047
- overflow: "hidden",
6244
+ overflow: "visible",
6048
6245
  userSelect: "none",
6049
6246
  transformOrigin: "0 0"
6050
6247
  });
@@ -6196,7 +6393,7 @@ function createDiagram(opts) {
6196
6393
  let sceneOffsetX = 0;
6197
6394
  let sceneOffsetY = 0;
6198
6395
  function computeContentBounds() {
6199
- return computeDiagramContentBounds(plan);
6396
+ return computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6200
6397
  }
6201
6398
  function relayoutOrientation(newDirection) {
6202
6399
  ast.meta.direction = newDirection;
@@ -6204,7 +6401,7 @@ function createDiagram(opts) {
6204
6401
  if (!ast.meta.explicitWidth) ast.meta.width = dims.width;
6205
6402
  if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
6206
6403
  const newPlan = compilePlan(ast, plan.theme);
6207
- const newBounds = computeDiagramContentBounds(newPlan);
6404
+ const newBounds = computeDiagramContentBounds(newPlan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6208
6405
  scene.style.width = `${newPlan.meta.width}px`;
6209
6406
  scene.style.height = `${newPlan.meta.height}px`;
6210
6407
  viewport.style.aspectRatio = `${newBounds.width} / ${newBounds.height}`;
@@ -6222,12 +6419,28 @@ function createDiagram(opts) {
6222
6419
  el.style.top = `${node.y}px`;
6223
6420
  el.style.width = `${node.width}px`;
6224
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`);
6225
6424
  }
6226
6425
  }
6227
6426
  treeLayer.innerHTML = "";
6228
6427
  mountTreeBuses(treeLayer, plan.treeBuses, plan.theme);
6229
6428
  groupLayer.innerHTML = "";
6230
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
+ }
6231
6444
  structuralEdgeHost.innerHTML = "";
6232
6445
  edgeRuntimes.clear();
6233
6446
  const newStructuralAnims = buildStructuralEdgeAnimations(
@@ -6296,10 +6509,10 @@ function createDiagram(opts) {
6296
6509
  const bounds = computeContentBounds();
6297
6510
  const contentW = bounds.width;
6298
6511
  const contentH = bounds.height;
6299
- const targetRatio = Math.min(1, Math.max(0.95, targetWidthRatio ?? 0.98));
6512
+ const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
6300
6513
  const widthScale = vWidth * targetRatio / contentW;
6301
6514
  if (fitMode === "contain") {
6302
- const heightScale = (vHeight - 16) * targetRatio / contentH;
6515
+ const heightScale = (vHeight - 24) * targetRatio / contentH;
6303
6516
  fitScale = Math.min(widthScale, heightScale);
6304
6517
  } else {
6305
6518
  fitScale = widthScale;
@@ -6308,13 +6521,16 @@ function createDiagram(opts) {
6308
6521
  scene.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6309
6522
  viewport.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6310
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
+ }
6311
6527
  const scaledContentW = contentW * fitScale;
6312
6528
  const scaledContentH = contentH * fitScale;
6313
6529
  sceneOffsetX = (vWidth - scaledContentW) / 2 - bounds.minX * fitScale;
6314
6530
  if (fitMode === "contain") {
6315
6531
  sceneOffsetY = (vHeight - scaledContentH) / 2 - bounds.minY * fitScale;
6316
6532
  } else {
6317
- const topSafeMargin = scaledContentH <= vHeight ? Math.max(8, Math.min(18, (vHeight - scaledContentH) / 2)) : 8;
6533
+ const topSafeMargin = scaledContentH <= vHeight ? Math.max(14, Math.min(24, (vHeight - scaledContentH) / 2)) : 14;
6318
6534
  sceneOffsetY = topSafeMargin - bounds.minY * fitScale;
6319
6535
  }
6320
6536
  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.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.3"
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.3"
56
+ "@markdy/stdlib-systems": "1.4.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",