@markdy/renderer-dom 1.4.7 → 1.4.8

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 +51 -13
  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%),
@@ -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(plan.meta.width / 2, leftSpan, rightSpan);
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
  }
@@ -6892,7 +6927,8 @@ function createDiagram(opts) {
6892
6927
  const bounds = computeContentBounds();
6893
6928
  const contentW = bounds.width;
6894
6929
  const contentH = bounds.height;
6895
- const widthScale = vWidth * targetRatio / contentW;
6930
+ const { symmetricContentW, symmetricMinX } = computeSymmetricContentSpan(plan, bounds);
6931
+ const widthScale = vWidth * targetRatio / symmetricContentW;
6896
6932
  if (resolvedFit === "contain") {
6897
6933
  const heightScale = (vHeight - 24) * targetRatio / contentH;
6898
6934
  fitScale = Math.min(widthScale, heightScale);
@@ -6904,18 +6940,20 @@ function createDiagram(opts) {
6904
6940
  const minimum = Number.isFinite(minReadableScale) && minReadableScale >= 0 && minReadableScale <= 1 ? minReadableScale : 0.9;
6905
6941
  fitScale = Math.max(fitScale, minimum);
6906
6942
  }
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));
6943
+ const scaleStr = fitScale.toFixed(4);
6944
+ const roundedScale = parseFloat(scaleStr);
6945
+ scene.style.setProperty("--markdy-scale", scaleStr);
6946
+ viewport.style.setProperty("--markdy-scale", scaleStr);
6947
+ container.style.setProperty("--markdy-scale", scaleStr);
6910
6948
  if (titleEl && contentW > 0) {
6911
6949
  titleEl.style.maxWidth = `${Math.max(contentW - 112, 280)}px`;
6912
6950
  }
6913
- const scaledContentW = contentW * fitScale;
6951
+ const scaledSymmetricW = symmetricContentW * fitScale;
6914
6952
  const scaledContentH = contentH * fitScale;
6915
6953
  const resetScroll = !scrollableViewport || lastScrollBounds !== bounds;
6916
- scrollableViewport = fitMode === "auto" && (scaledContentW > vWidth || scaledContentH > vHeight);
6954
+ scrollableViewport = fitMode === "auto" && (scaledSymmetricW > vWidth || scaledContentH > vHeight);
6917
6955
  lastScrollBounds = bounds;
6918
- const frameWidth = scrollableViewport ? Math.max(vWidth, scaledContentW + 24) : vWidth;
6956
+ const frameWidth = scrollableViewport ? Math.max(vWidth, scaledSymmetricW + 24) : vWidth;
6919
6957
  const frameHeight = scrollableViewport ? Math.max(vHeight, scaledContentH + 28) : vHeight;
6920
6958
  sceneFrame.style.width = scrollableViewport ? `${frameWidth}px` : "100%";
6921
6959
  sceneFrame.style.height = scrollableViewport ? `${frameHeight}px` : "100%";
@@ -6929,17 +6967,17 @@ function createDiagram(opts) {
6929
6967
  viewport.removeAttribute("tabindex");
6930
6968
  viewport.removeAttribute("aria-label");
6931
6969
  }
6932
- sceneOffsetX = (frameWidth - scaledContentW) / 2 - bounds.minX * fitScale;
6970
+ sceneOffsetX = (frameWidth - scaledSymmetricW) / 2 - symmetricMinX * fitScale;
6933
6971
  if (resolvedFit === "contain") {
6934
6972
  sceneOffsetY = (frameHeight - scaledContentH) / 2 - bounds.minY * fitScale;
6935
6973
  } else {
6936
- const topSafeMargin = scaledContentH <= vHeight ? Math.max(14, Math.min(24, (vHeight - scaledContentH) / 2)) : 14;
6974
+ const topSafeMargin = scaledContentH <= vHeight ? Math.max(16, (vHeight - scaledContentH) / 2) : 16;
6937
6975
  sceneOffsetY = topSafeMargin - bounds.minY * fitScale;
6938
6976
  }
6939
6977
  scene.style.left = `${sceneOffsetX}px`;
6940
6978
  scene.style.top = `${sceneOffsetY}px`;
6941
6979
  scene.style.transformOrigin = "0 0";
6942
- scene.style.transform = `scale(${fitScale})`;
6980
+ scene.style.transform = `scale(${roundedScale})`;
6943
6981
  if (scrollableViewport || fitViewActive) {
6944
6982
  cameraLayer.style.setProperty("transform", "none", "important");
6945
6983
  } 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.8",
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.8"
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.8"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",