@markdy/renderer-dom 1.4.4 → 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.
- package/dist/index.js +65 -20
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -6220,11 +6220,17 @@ 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
|
|
6227
|
+
const currentHeight = container.clientHeight || 0;
|
|
6228
|
+
const height = hasInitialHeightConstraint ? currentHeight > 0 ? currentHeight : initialContainerHeight : 0;
|
|
6226
6229
|
const breakpoint = previous === "portrait" ? 672 : previous === "landscape" ? 608 : 640;
|
|
6227
|
-
if (
|
|
6230
|
+
if (width <= 440) {
|
|
6231
|
+
return "portrait";
|
|
6232
|
+
}
|
|
6233
|
+
if (height > 0) {
|
|
6228
6234
|
const ratio = width / height;
|
|
6229
6235
|
const ratioBreakpoint = previous === "portrait" ? 1.15 : previous === "landscape" ? 0.88 : 1;
|
|
6230
6236
|
if (ratio >= ratioBreakpoint) {
|
|
@@ -6232,14 +6238,14 @@ function createDiagram(opts) {
|
|
|
6232
6238
|
}
|
|
6233
6239
|
return "portrait";
|
|
6234
6240
|
}
|
|
6235
|
-
return
|
|
6241
|
+
return "landscape";
|
|
6236
6242
|
}
|
|
6237
6243
|
const ast = parse(code);
|
|
6238
6244
|
for (const w of ast.diagnostics) {
|
|
6239
6245
|
if (w.severity === "warning") onWarning(w);
|
|
6240
6246
|
}
|
|
6241
|
-
const hasExplicitDirection = ast.meta.explicitDirection === true;
|
|
6242
|
-
const shouldAdaptOrientation = responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
|
|
6247
|
+
const hasExplicitDirection = ast.meta.explicitDirection === true && ast.meta.layoutMode !== "auto";
|
|
6248
|
+
const shouldAdaptOrientation = ast.meta.layoutMode === "auto" || responsiveLayout === true || responsiveLayout === "auto" && !hasExplicitDirection;
|
|
6243
6249
|
const reverseDirection = ast.meta.direction === "RL" || ast.meta.direction === "BT";
|
|
6244
6250
|
const directionForOrientation = (orientation) => orientation === "portrait" ? reverseDirection ? "BT" : "TB" : reverseDirection ? "RL" : "LR";
|
|
6245
6251
|
let activeOrientation = detectContainerOrientation();
|
|
@@ -6608,7 +6614,15 @@ function createDiagram(opts) {
|
|
|
6608
6614
|
function layoutForDirection(direction) {
|
|
6609
6615
|
const cached = layoutPlans.get(direction);
|
|
6610
6616
|
if (cached?.plan.theme === plan.theme) return cached;
|
|
6611
|
-
const
|
|
6617
|
+
const candidateAst = {
|
|
6618
|
+
...ast,
|
|
6619
|
+
meta: {
|
|
6620
|
+
...ast.meta,
|
|
6621
|
+
direction,
|
|
6622
|
+
...shouldAdaptOrientation ? { explicitWidth: false, explicitHeight: false } : {}
|
|
6623
|
+
}
|
|
6624
|
+
};
|
|
6625
|
+
const candidate = compilePlan(candidateAst, plan.theme);
|
|
6612
6626
|
const entry = { plan: candidate, bounds: computeDiagramContentBounds(candidate, { padding: contentPadding }) };
|
|
6613
6627
|
layoutPlans.set(direction, entry);
|
|
6614
6628
|
return entry;
|
|
@@ -6723,20 +6737,51 @@ function createDiagram(opts) {
|
|
|
6723
6737
|
const vHeight = viewport.clientHeight || container.clientHeight || naturalHeight;
|
|
6724
6738
|
const resolvedFit = fitViewActive ? "contain" : fitMode === "auto" ? Math.abs(vHeight - naturalHeight) > 2 ? "contain" : "width" : fitMode;
|
|
6725
6739
|
const targetRatio = Math.min(1, Math.max(0.9, targetWidthRatio ?? 0.96));
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
+
const ADAPTABLE_DIAGRAM_TYPES = /* @__PURE__ */ new Set([
|
|
6741
|
+
"architecture",
|
|
6742
|
+
"flowchart",
|
|
6743
|
+
"state",
|
|
6744
|
+
"tree",
|
|
6745
|
+
"medallion",
|
|
6746
|
+
"swimlane",
|
|
6747
|
+
"timeline",
|
|
6748
|
+
"gantt",
|
|
6749
|
+
"layers",
|
|
6750
|
+
"loop",
|
|
6751
|
+
"nested",
|
|
6752
|
+
"flywheel",
|
|
6753
|
+
"pyramid"
|
|
6754
|
+
]);
|
|
6755
|
+
if (shouldAdaptOrientation && ADAPTABLE_DIAGRAM_TYPES.has(plan.diagramType)) {
|
|
6756
|
+
const detectedOrientation = detectContainerOrientation(activeOrientation);
|
|
6757
|
+
const isHeightConstrained = hasInitialHeightConstraint || vHeight > 0 && Math.abs(vHeight - naturalHeight) > 2;
|
|
6758
|
+
const containerRatio = vWidth / Math.max(1, vHeight);
|
|
6759
|
+
let currentOrientation = activeOrientation;
|
|
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
|
|
6768
|
+
};
|
|
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";
|
|
6740
6785
|
}
|
|
6741
6786
|
}
|
|
6742
6787
|
if (currentOrientation !== activeOrientation) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.4.
|
|
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.
|
|
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.
|
|
56
|
+
"@markdy/stdlib-systems": "1.4.6"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|