@markdy/renderer-dom 1.4.5 → 1.4.6

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 +31 -19
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -6224,8 +6224,12 @@ function createDiagram(opts) {
6224
6224
  const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
6225
6225
  function detectContainerOrientation(previous) {
6226
6226
  const width = container.clientWidth || (typeof window === "undefined" ? 1024 : window.innerWidth);
6227
- const height = hasInitialHeightConstraint ? initialContainerHeight : 0;
6227
+ const currentHeight = container.clientHeight || 0;
6228
+ const height = hasInitialHeightConstraint ? currentHeight > 0 ? currentHeight : initialContainerHeight : 0;
6228
6229
  const breakpoint = previous === "portrait" ? 672 : previous === "landscape" ? 608 : 640;
6230
+ if (width <= 440) {
6231
+ return "portrait";
6232
+ }
6229
6233
  if (height > 0) {
6230
6234
  const ratio = width / height;
6231
6235
  const ratioBreakpoint = previous === "portrait" ? 1.15 : previous === "landscape" ? 0.88 : 1;
@@ -6234,7 +6238,7 @@ function createDiagram(opts) {
6234
6238
  }
6235
6239
  return "portrait";
6236
6240
  }
6237
- return width < breakpoint ? "portrait" : "landscape";
6241
+ return "landscape";
6238
6242
  }
6239
6243
  const ast = parse(code);
6240
6244
  for (const w of ast.diagnostics) {
@@ -6615,7 +6619,7 @@ function createDiagram(opts) {
6615
6619
  meta: {
6616
6620
  ...ast.meta,
6617
6621
  direction,
6618
- ...ast.meta.layoutMode === "auto" || responsiveLayout === true ? { explicitWidth: false, explicitHeight: false } : {}
6622
+ ...shouldAdaptOrientation ? { explicitWidth: false, explicitHeight: false } : {}
6619
6623
  }
6620
6624
  };
6621
6625
  const candidate = compilePlan(candidateAst, plan.theme);
@@ -6753,23 +6757,31 @@ function createDiagram(opts) {
6753
6757
  const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
6754
6758
  const containerRatio = vWidth / Math.max(1, vHeight);
6755
6759
  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);
6760
+ const score = (orientation) => {
6761
+ const { bounds: bounds2 } = layoutForDirection(directionForOrientation(orientation));
6762
+ const widthScale2 = vWidth * targetRatio / bounds2.width;
6763
+ const heightScale = isHeightConstrained ? Math.max(1, vHeight - 24) * targetRatio / bounds2.height : 1;
6764
+ return {
6765
+ fit: Math.min(1, widthScale2, heightScale),
6766
+ widthScale: widthScale2,
6767
+ bounds: bounds2
6762
6768
  };
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
- }
6769
+ };
6770
+ const scoreP = score("portrait");
6771
+ const scoreL = score("landscape");
6772
+ if (activeOrientation === "landscape") {
6773
+ if (detectedOrientation === "portrait") {
6774
+ currentOrientation = "portrait";
6775
+ } else if (!isHeightConstrained && scoreP.widthScale >= 0.7 && scoreL.widthScale < 0.65) {
6776
+ currentOrientation = "portrait";
6777
+ } else if (scoreP.fit > scoreL.fit * 1.25) {
6778
+ currentOrientation = "portrait";
6779
+ }
6780
+ } else {
6781
+ if (detectedOrientation === "landscape" && (scoreL.fit >= Math.min(0.85, scoreP.fit) || scoreL.widthScale >= 0.75)) {
6782
+ currentOrientation = "landscape";
6783
+ } else if (scoreL.fit > scoreP.fit * 1.25) {
6784
+ currentOrientation = "landscape";
6773
6785
  }
6774
6786
  }
6775
6787
  if (currentOrientation !== activeOrientation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
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.5"
49
+ "@markdy/core": "1.4.6"
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.5"
56
+ "@markdy/stdlib-systems": "1.4.6"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",