@markdy/renderer-dom 1.4.4 → 1.4.5

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 +52 -19
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -6220,11 +6220,13 @@ function createDiagram(opts) {
6220
6220
  defaultFit,
6221
6221
  fit: explicitFitOption
6222
6222
  } = opts;
6223
+ const initialContainerHeight = container.clientHeight || 0;
6224
+ const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
6223
6225
  function detectContainerOrientation(previous) {
6224
6226
  const width = container.clientWidth || (typeof window === "undefined" ? 1024 : window.innerWidth);
6225
- const height = container.clientHeight || 0;
6227
+ const height = hasInitialHeightConstraint ? initialContainerHeight : 0;
6226
6228
  const breakpoint = previous === "portrait" ? 672 : previous === "landscape" ? 608 : 640;
6227
- if (height > 0 && container.clientHeight > 0) {
6229
+ if (height > 0) {
6228
6230
  const ratio = width / height;
6229
6231
  const ratioBreakpoint = previous === "portrait" ? 1.15 : previous === "landscape" ? 0.88 : 1;
6230
6232
  if (ratio >= ratioBreakpoint) {
@@ -6238,8 +6240,8 @@ function createDiagram(opts) {
6238
6240
  for (const w of ast.diagnostics) {
6239
6241
  if (w.severity === "warning") onWarning(w);
6240
6242
  }
6241
- const hasExplicitDirection = ast.meta.explicitDirection === true;
6242
- const shouldAdaptOrientation = responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
6243
+ const hasExplicitDirection = ast.meta.explicitDirection === true && ast.meta.layoutMode !== "auto";
6244
+ const shouldAdaptOrientation = ast.meta.layoutMode === "auto" || responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
6243
6245
  const reverseDirection = ast.meta.direction === "RL" || ast.meta.direction === "BT";
6244
6246
  const directionForOrientation = (orientation) => orientation === "portrait" ? reverseDirection ? "BT" : "TB" : reverseDirection ? "RL" : "LR";
6245
6247
  let activeOrientation = detectContainerOrientation();
@@ -6608,7 +6610,15 @@ function createDiagram(opts) {
6608
6610
  function layoutForDirection(direction) {
6609
6611
  const cached = layoutPlans.get(direction);
6610
6612
  if (cached?.plan.theme === plan.theme) return cached;
6611
- const candidate = compilePlan({ ...ast, meta: { ...ast.meta, direction } }, plan.theme);
6613
+ const candidateAst = {
6614
+ ...ast,
6615
+ meta: {
6616
+ ...ast.meta,
6617
+ direction,
6618
+ ...ast.meta.layoutMode === "auto" || responsiveLayout === true ? { explicitWidth: false, explicitHeight: false } : {}
6619
+ }
6620
+ };
6621
+ const candidate = compilePlan(candidateAst, plan.theme);
6612
6622
  const entry = { plan: candidate, bounds: computeDiagramContentBounds(candidate, { padding: contentPadding }) };
6613
6623
  layoutPlans.set(direction, entry);
6614
6624
  return entry;
@@ -6723,20 +6733,43 @@ function createDiagram(opts) {
6723
6733
  const vHeight = viewport.clientHeight || container.clientHeight || naturalHeight;
6724
6734
  const resolvedFit = fitViewActive ? "contain" : fitMode === "auto" ? Math.abs(vHeight - naturalHeight) > 2 ? "contain" : "width" : fitMode;
6725
6735
  const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
6726
- if (shouldAdaptOrientation && !fitViewActive) {
6727
- let currentOrientation = detectContainerOrientation(activeOrientation);
6728
- if (fitMode === "auto" && (!ast.meta.explicitWidth || !ast.meta.explicitHeight) && ["architecture", "flowchart", "state", "tree", "medallion", "swimlane", "timeline", "gantt", "layers", "loop"].includes(plan.diagramType)) {
6729
- const isHeightConstrained = resolvedFit === "contain" || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
6730
- const containerRatio = vWidth / Math.max(1, vHeight);
6731
- if (!(activeOrientation === "landscape" && containerRatio >= 1)) {
6732
- const score = (orientation) => {
6733
- const { bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
6734
- const widthScale2 = vWidth * targetRatio / bounds2.width;
6735
- const heightScale = isHeightConstrained ? Math.max(1, vHeight - 24) * targetRatio / bounds2.height : 1;
6736
- return Math.min(1, widthScale2, heightScale);
6737
- };
6738
- const alternative = activeOrientation === "portrait" ? "landscape" : "portrait";
6739
- currentOrientation = score(alternative) > score(activeOrientation) * 1.2 ? alternative : activeOrientation;
6736
+ const ADAPTABLE_DIAGRAM_TYPES = /* @__PURE__ */ new Set([
6737
+ "architecture",
6738
+ "flowchart",
6739
+ "state",
6740
+ "tree",
6741
+ "medallion",
6742
+ "swimlane",
6743
+ "timeline",
6744
+ "gantt",
6745
+ "layers",
6746
+ "loop",
6747
+ "nested",
6748
+ "flywheel",
6749
+ "pyramid"
6750
+ ]);
6751
+ if (shouldAdaptOrientation && ADAPTABLE_DIAGRAM_TYPES.has(plan.diagramType)) {
6752
+ const detectedOrientation = detectContainerOrientation(activeOrientation);
6753
+ const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
6754
+ const containerRatio = vWidth / Math.max(1, vHeight);
6755
+ let currentOrientation = activeOrientation;
6756
+ if (!isHeightConstrained || !(activeOrientation === "landscape" && containerRatio >= 1)) {
6757
+ const score = (orientation) => {
6758
+ const { bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
6759
+ const widthScale2 = vWidth * targetRatio / bounds2.width;
6760
+ const heightScale = isHeightConstrained ? Math.max(1, vHeight - 24) * targetRatio / bounds2.height : 1;
6761
+ return Math.min(1, widthScale2, heightScale);
6762
+ };
6763
+ if (activeOrientation === "landscape") {
6764
+ if (detectedOrientation === "portrait" || score("portrait") > score("landscape") * 1.2) {
6765
+ currentOrientation = "portrait";
6766
+ }
6767
+ } else {
6768
+ if (detectedOrientation === "landscape" && score("landscape") >= Math.min(0.85, score("portrait"))) {
6769
+ currentOrientation = "landscape";
6770
+ } else if (score("landscape") > score("portrait") * 1.2) {
6771
+ currentOrientation = "landscape";
6772
+ }
6740
6773
  }
6741
6774
  }
6742
6775
  if (currentOrientation !== activeOrientation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
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.4"
49
+ "@markdy/core": "1.4.5"
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.4"
56
+ "@markdy/stdlib-systems": "1.4.5"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",