@markdy/renderer-dom 1.4.7 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +64 -21
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -3472,9 +3472,12 @@ function ensureSceneStyles(doc) {
3472
3472
  const style = doc.createElement("style");
3473
3473
  style.id = SCENE_STYLE_ID;
3474
3474
  style.textContent = `
3475
+ .markdy-viewport,
3475
3476
  .markdy-scene-root {
3476
3477
  isolation: isolate;
3477
3478
  }
3479
+ .markdy-viewport::before,
3480
+ .markdy-viewport::after,
3478
3481
  .markdy-scene-root::before,
3479
3482
  .markdy-scene-root::after {
3480
3483
  content: "";
@@ -3482,6 +3485,7 @@ function ensureSceneStyles(doc) {
3482
3485
  inset: 0;
3483
3486
  pointer-events: none;
3484
3487
  }
3488
+ .markdy-viewport::before,
3485
3489
  .markdy-scene-root::before {
3486
3490
  z-index: 0;
3487
3491
  background:
@@ -3491,6 +3495,7 @@ function ensureSceneStyles(doc) {
3491
3495
  mask-image: radial-gradient(ellipse at 50% 48%, #000 65%, transparent 100%);
3492
3496
  opacity: 0.55;
3493
3497
  }
3498
+ .markdy-viewport::after,
3494
3499
  .markdy-scene-root::after {
3495
3500
  z-index: 1;
3496
3501
  background:
@@ -3499,6 +3504,14 @@ function ensureSceneStyles(doc) {
3499
3504
  opacity: 0.68;
3500
3505
  }
3501
3506
  .markdy-scene-content { z-index: 2; }
3507
+ .markdy-viewport .markdy-scene-root {
3508
+ background: transparent !important;
3509
+ }
3510
+ .markdy-viewport .markdy-scene-root::before,
3511
+ .markdy-viewport .markdy-scene-root::after {
3512
+ display: none !important;
3513
+ }
3514
+ .markdy-viewport[data-markdy-theme="nebula"]::before,
3502
3515
  .markdy-scene-root[data-markdy-theme="nebula"]::before {
3503
3516
  background:
3504
3517
  radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--md-soft) 20%, transparent), transparent 36%),
@@ -3507,32 +3520,38 @@ function ensureSceneStyles(doc) {
3507
3520
  mask-image: radial-gradient(ellipse at 50% 50%, #000 70%, transparent 100%);
3508
3521
  opacity: 0.95;
3509
3522
  }
3523
+ .markdy-viewport[data-markdy-theme="nebula"]::after,
3510
3524
  .markdy-scene-root[data-markdy-theme="nebula"]::after {
3511
3525
  background:
3512
3526
  radial-gradient(ellipse at 50% 42%, color-mix(in srgb, var(--md-accent) 16%, transparent), transparent 56%),
3513
3527
  linear-gradient(180deg, transparent 0%, var(--md-vignette) 100%);
3514
3528
  opacity: 0.85;
3515
3529
  }
3530
+ .markdy-viewport[data-markdy-theme="terminal"]::before,
3516
3531
  .markdy-scene-root[data-markdy-theme="terminal"]::before {
3517
3532
  background:
3518
3533
  radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.08) 1px, transparent 1px) 0 0 / 20px 20px;
3519
3534
  mask-image: none;
3520
3535
  opacity: 0.45;
3521
3536
  }
3537
+ .markdy-viewport[data-markdy-theme="terminal"]::after,
3522
3538
  .markdy-scene-root[data-markdy-theme="terminal"]::after {
3523
3539
  background:
3524
3540
  radial-gradient(ellipse at 50% 0%, rgba(255, 90, 54, 0.1), transparent 52%),
3525
3541
  linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.55) 100%);
3526
3542
  opacity: 0.75;
3527
3543
  }
3544
+ .markdy-viewport[data-markdy-theme="sketchy"]::before,
3528
3545
  .markdy-scene-root[data-markdy-theme="sketchy"]::before {
3529
3546
  background: none;
3530
3547
  opacity: 0;
3531
3548
  }
3549
+ .markdy-viewport[data-markdy-theme="sketchy"]::after,
3532
3550
  .markdy-scene-root[data-markdy-theme="sketchy"]::after {
3533
3551
  background: none;
3534
3552
  opacity: 0;
3535
3553
  }
3554
+ .markdy-viewport[data-markdy-theme="ink"]::before,
3536
3555
  .markdy-scene-root[data-markdy-theme="ink"]::before {
3537
3556
  background:
3538
3557
  radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--md-accent) 9%, transparent) 1px, transparent 1px) 0 0 / 20px 20px,
@@ -3541,6 +3560,7 @@ function ensureSceneStyles(doc) {
3541
3560
  mask-image: radial-gradient(ellipse at 50% 50%, #000 75%, transparent 100%);
3542
3561
  opacity: 0.75;
3543
3562
  }
3563
+ .markdy-viewport[data-markdy-theme="ink"]::after,
3544
3564
  .markdy-scene-root[data-markdy-theme="ink"]::after {
3545
3565
  background:
3546
3566
  radial-gradient(ellipse at 50% -10%, color-mix(in srgb, var(--md-accent) 12%, transparent), transparent 50%),
@@ -3548,12 +3568,14 @@ function ensureSceneStyles(doc) {
3548
3568
  linear-gradient(180deg, transparent 0%, rgba(219, 234, 254, 0.25) 80%, var(--md-vignette) 100%);
3549
3569
  opacity: 0.85;
3550
3570
  }
3571
+ .markdy-viewport[data-markdy-theme="doodle"]::before,
3551
3572
  .markdy-scene-root[data-markdy-theme="doodle"]::before {
3552
3573
  background:
3553
3574
  radial-gradient(circle at 50% 50%, rgba(24, 24, 27, 0.06) 1.5px, transparent 1.5px) 0 0 / 20px 20px;
3554
3575
  mask-image: none;
3555
3576
  opacity: 0.7;
3556
3577
  }
3578
+ .markdy-viewport[data-markdy-theme="doodle"]::after,
3557
3579
  .markdy-scene-root[data-markdy-theme="doodle"]::after {
3558
3580
  background:
3559
3581
  radial-gradient(ellipse at 85% 15%, rgba(244, 63, 94, 0.05), transparent 45%),
@@ -6265,7 +6287,7 @@ function computeDiagramContentBounds(plan, options) {
6265
6287
  }
6266
6288
  const hasBeatCaptions = plan.beats && plan.beats.some((b) => b.label && b.label.trim().length > 0);
6267
6289
  if (hasBeatCaptions) {
6268
- maxY = Math.max(maxY, plan.meta.height - 18);
6290
+ maxY = Math.max(maxY, maxY + 36);
6269
6291
  }
6270
6292
  for (const ann of plan.annotations ?? []) {
6271
6293
  const targetNode = plan.nodes.find((n) => n.id === ann.target);
@@ -6292,6 +6314,16 @@ function computeDiagramContentBounds(plan, options) {
6292
6314
  const height = Math.max(maxY - minY, 80);
6293
6315
  return { minX, minY, maxX, maxY, width, height };
6294
6316
  }
6317
+ function computeSymmetricContentSpan(plan, bounds) {
6318
+ const canvasCenterX = plan.meta.width / 2;
6319
+ const leftSpan = Math.max(0, canvasCenterX - bounds.minX);
6320
+ const rightSpan = Math.max(0, bounds.maxX - canvasCenterX);
6321
+ const halfSpanX = Math.max(leftSpan, rightSpan, bounds.width / 2);
6322
+ return {
6323
+ symmetricContentW: halfSpanX * 2,
6324
+ symmetricMinX: canvasCenterX - halfSpanX
6325
+ };
6326
+ }
6295
6327
  function createDiagram(opts) {
6296
6328
  const {
6297
6329
  container,
@@ -6427,7 +6459,8 @@ function createDiagram(opts) {
6427
6459
  });
6428
6460
  if (container.style.aspectRatio) container.style.aspectRatio = "unset";
6429
6461
  const initialBounds = computeDiagramContentBounds(plan, contentPadding !== void 0 ? { padding: contentPadding } : void 0);
6430
- const contentRatio = `${initialBounds.width} / ${initialBounds.height}`;
6462
+ const { symmetricContentW: initialSymmetricW } = computeSymmetricContentSpan(plan, initialBounds);
6463
+ const contentRatio = `${initialSymmetricW} / ${initialBounds.height}`;
6431
6464
  const viewport = document.createElement("div");
6432
6465
  viewport.className = "markdy-viewport";
6433
6466
  applyThemeVariables(viewport, plan.theme);
@@ -6734,7 +6767,8 @@ function createDiagram(opts) {
6734
6767
  Object.assign(ast.meta, newPlan.meta);
6735
6768
  scene.style.width = `${newPlan.meta.width}px`;
6736
6769
  scene.style.height = `${newPlan.meta.height}px`;
6737
- viewport.style.aspectRatio = `${newBounds.width} / ${newBounds.height}`;
6770
+ const { symmetricContentW: newSymmetricW } = computeSymmetricContentSpan(newPlan, newBounds);
6771
+ viewport.style.aspectRatio = `${newSymmetricW} / ${newBounds.height}`;
6738
6772
  Object.assign(plan, newPlan);
6739
6773
  contentBounds = newBounds;
6740
6774
  for (const node of plan.nodes) {
@@ -6815,7 +6849,8 @@ function createDiagram(opts) {
6815
6849
  ...buildBeatCaptionAnimations(plan.beats, captionLayer)
6816
6850
  ];
6817
6851
  contentBounds = computeDiagramContentBounds(plan, { padding: contentPadding, routedEdges: edgeRuntimes.values() });
6818
- viewport.style.aspectRatio = `${contentBounds.width} / ${contentBounds.height}`;
6852
+ const { symmetricContentW: relayoutSymmetricW } = computeSymmetricContentSpan(plan, contentBounds);
6853
+ viewport.style.aspectRatio = `${relayoutSymmetricW} / ${contentBounds.height}`;
6819
6854
  applyCurrentTime();
6820
6855
  scaleScene();
6821
6856
  }
@@ -6832,10 +6867,14 @@ function createDiagram(opts) {
6832
6867
  return;
6833
6868
  }
6834
6869
  const vWidth = viewport.clientWidth || container.clientWidth || plan.meta.width;
6835
- const naturalHeight = vWidth * contentBounds.height / contentBounds.width;
6870
+ const initialMeasureBounds = computeContentBounds();
6871
+ const { symmetricContentW: initSymW } = computeSymmetricContentSpan(plan, initialMeasureBounds);
6872
+ const naturalHeight = vWidth * initialMeasureBounds.height / initSymW;
6836
6873
  const vHeight = viewport.clientHeight || container.clientHeight || naturalHeight;
6837
- const resolvedFit = fitViewActive ? "contain" : fitMode === "auto" ? Math.abs(vHeight - naturalHeight) > 2 ? "contain" : "width" : fitMode;
6838
- const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
6874
+ const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 3;
6875
+ const resolvedFit = fitViewActive ? "contain" : fitMode === "auto" ? isHeightConstrained ? "contain" : "width" : fitMode;
6876
+ const defaultTargetRatio = vWidth <= 480 ? 0.95 : 0.9;
6877
+ const targetRatio = Math.min(1, Math.max(0.85, targetWidthRatio ?? defaultTargetRatio));
6839
6878
  const ADAPTABLE_DIAGRAM_TYPES = /* @__PURE__ */ new Set([
6840
6879
  "architecture",
6841
6880
  "flowchart",
@@ -6853,12 +6892,12 @@ function createDiagram(opts) {
6853
6892
  ]);
6854
6893
  if (shouldAdaptOrientation && ADAPTABLE_DIAGRAM_TYPES.has(plan.diagramType)) {
6855
6894
  const detectedOrientation = detectContainerOrientation(activeOrientation);
6856
- const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
6857
6895
  const containerRatio = vWidth / Math.max(1, vHeight);
6858
6896
  let currentOrientation = activeOrientation;
6859
6897
  const score = (orientation) => {
6860
- const { bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
6861
- const widthScale2 = vWidth * targetRatio / bounds2.width;
6898
+ const { plan: candPlan, bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
6899
+ const { symmetricContentW: candSymW } = computeSymmetricContentSpan(candPlan, bounds2);
6900
+ const widthScale2 = vWidth * targetRatio / candSymW;
6862
6901
  const heightScale = isHeightConstrained ? Math.max(1, vHeight - 24) * targetRatio / bounds2.height : 1;
6863
6902
  return {
6864
6903
  fit: Math.min(1, widthScale2, heightScale),
@@ -6892,7 +6931,8 @@ function createDiagram(opts) {
6892
6931
  const bounds = computeContentBounds();
6893
6932
  const contentW = bounds.width;
6894
6933
  const contentH = bounds.height;
6895
- const widthScale = vWidth * targetRatio / contentW;
6934
+ const { symmetricContentW, symmetricMinX } = computeSymmetricContentSpan(plan, bounds);
6935
+ const widthScale = vWidth * targetRatio / symmetricContentW;
6896
6936
  if (resolvedFit === "contain") {
6897
6937
  const heightScale = (vHeight - 24) * targetRatio / contentH;
6898
6938
  fitScale = Math.min(widthScale, heightScale);
@@ -6901,21 +6941,24 @@ function createDiagram(opts) {
6901
6941
  }
6902
6942
  if (!Number.isFinite(fitScale) || fitScale <= 0) fitScale = 1;
6903
6943
  if (fitMode === "auto" && !fitViewActive) {
6904
- const minimum = Number.isFinite(minReadableScale) && minReadableScale >= 0 && minReadableScale <= 1 ? minReadableScale : 0.9;
6944
+ const defaultMin = vWidth <= 480 ? 0.75 : 0.85;
6945
+ const minimum = Number.isFinite(minReadableScale) && minReadableScale >= 0 && minReadableScale <= 1 ? minReadableScale : defaultMin;
6905
6946
  fitScale = Math.max(fitScale, minimum);
6906
6947
  }
6907
- scene.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6908
- viewport.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6909
- container.style.setProperty("--markdy-scale", fitScale.toFixed(4));
6948
+ const scaleStr = fitScale.toFixed(4);
6949
+ const roundedScale = parseFloat(scaleStr);
6950
+ scene.style.setProperty("--markdy-scale", scaleStr);
6951
+ viewport.style.setProperty("--markdy-scale", scaleStr);
6952
+ container.style.setProperty("--markdy-scale", scaleStr);
6910
6953
  if (titleEl && contentW > 0) {
6911
6954
  titleEl.style.maxWidth = `${Math.max(contentW - 112, 280)}px`;
6912
6955
  }
6913
- const scaledContentW = contentW * fitScale;
6956
+ const scaledSymmetricW = symmetricContentW * fitScale;
6914
6957
  const scaledContentH = contentH * fitScale;
6915
6958
  const resetScroll = !scrollableViewport || lastScrollBounds !== bounds;
6916
- scrollableViewport = fitMode === "auto" && (scaledContentW > vWidth || scaledContentH > vHeight);
6959
+ scrollableViewport = fitMode === "auto" && (scaledSymmetricW > vWidth || scaledContentH > vHeight);
6917
6960
  lastScrollBounds = bounds;
6918
- const frameWidth = scrollableViewport ? Math.max(vWidth, scaledContentW + 24) : vWidth;
6961
+ const frameWidth = scrollableViewport ? Math.max(vWidth, scaledSymmetricW + 24) : vWidth;
6919
6962
  const frameHeight = scrollableViewport ? Math.max(vHeight, scaledContentH + 28) : vHeight;
6920
6963
  sceneFrame.style.width = scrollableViewport ? `${frameWidth}px` : "100%";
6921
6964
  sceneFrame.style.height = scrollableViewport ? `${frameHeight}px` : "100%";
@@ -6929,17 +6972,17 @@ function createDiagram(opts) {
6929
6972
  viewport.removeAttribute("tabindex");
6930
6973
  viewport.removeAttribute("aria-label");
6931
6974
  }
6932
- sceneOffsetX = (frameWidth - scaledContentW) / 2 - bounds.minX * fitScale;
6975
+ sceneOffsetX = (frameWidth - scaledSymmetricW) / 2 - symmetricMinX * fitScale;
6933
6976
  if (resolvedFit === "contain") {
6934
6977
  sceneOffsetY = (frameHeight - scaledContentH) / 2 - bounds.minY * fitScale;
6935
6978
  } else {
6936
- const topSafeMargin = scaledContentH <= vHeight ? Math.max(14, Math.min(24, (vHeight - scaledContentH) / 2)) : 14;
6979
+ const topSafeMargin = scaledContentH <= vHeight ? Math.max(16, (vHeight - scaledContentH) / 2) : 16;
6937
6980
  sceneOffsetY = topSafeMargin - bounds.minY * fitScale;
6938
6981
  }
6939
6982
  scene.style.left = `${sceneOffsetX}px`;
6940
6983
  scene.style.top = `${sceneOffsetY}px`;
6941
6984
  scene.style.transformOrigin = "0 0";
6942
- scene.style.transform = `scale(${fitScale})`;
6985
+ scene.style.transform = `scale(${roundedScale})`;
6943
6986
  if (scrollableViewport || fitViewActive) {
6944
6987
  cameraLayer.style.setProperty("transform", "none", "important");
6945
6988
  } else if (cameraLayer.style.getPropertyPriority("transform") === "important") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
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.7"
49
+ "@markdy/core": "1.4.9"
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.7"
56
+ "@markdy/stdlib-systems": "1.4.9"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",