@markdy/core 1.0.19 → 1.0.20
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 +28 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -630,7 +630,7 @@ function resolvePlayer(config = {}, overrides = {}) {
|
|
|
630
630
|
svg: resolveControl(configuredControls.svg),
|
|
631
631
|
share: resolveControl(configuredControls.share),
|
|
632
632
|
code: resolveControl(configuredControls.code, false),
|
|
633
|
-
theme: resolveControl(configuredControls.theme,
|
|
633
|
+
theme: resolveControl(configuredControls.theme, hostControlDefault)
|
|
634
634
|
};
|
|
635
635
|
const interactionOn = overrides.interactiveViewport !== false && (overrides.interactiveViewport === true || config.interaction !== void 0 || overrides.controls === true);
|
|
636
636
|
const gestures = {
|
|
@@ -895,12 +895,33 @@ function layoutRanked(ast, edges, opts) {
|
|
|
895
895
|
nodeGroupIndex.set(memberId, gIdx);
|
|
896
896
|
}
|
|
897
897
|
});
|
|
898
|
-
|
|
898
|
+
const nodeDeclOrder = new Map(nodeIds.map((id, idx) => [id, idx]));
|
|
899
|
+
const incomingParents = /* @__PURE__ */ new Map();
|
|
900
|
+
for (const id of nodeIds) incomingParents.set(id, []);
|
|
901
|
+
for (const e of edges) {
|
|
902
|
+
if (e.kind !== "response" && !e.selfLoop && ast.nodes[e.from] && ast.nodes[e.to]) {
|
|
903
|
+
incomingParents.get(e.to)?.push(e.from);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
const rankOrder = /* @__PURE__ */ new Map();
|
|
907
|
+
const sortedRanks = [...byRank.keys()].sort((a, b) => a - b);
|
|
908
|
+
for (const r of sortedRanks) {
|
|
909
|
+
const ids = byRank.get(r);
|
|
899
910
|
ids.sort((a, b) => {
|
|
900
911
|
const ga = nodeGroupIndex.has(a) ? nodeGroupIndex.get(a) : 9999;
|
|
901
912
|
const gb = nodeGroupIndex.has(b) ? nodeGroupIndex.get(b) : 9999;
|
|
902
913
|
if (ga !== gb) return ga - gb;
|
|
903
|
-
|
|
914
|
+
const parentsA = (incomingParents.get(a) ?? []).filter((p) => rankOrder.has(p));
|
|
915
|
+
const parentsB = (incomingParents.get(b) ?? []).filter((p) => rankOrder.has(p));
|
|
916
|
+
if (parentsA.length > 0 && parentsB.length > 0) {
|
|
917
|
+
const avgA = parentsA.reduce((sum, p) => sum + (rankOrder.get(p) ?? 0), 0) / parentsA.length;
|
|
918
|
+
const avgB = parentsB.reduce((sum, p) => sum + (rankOrder.get(p) ?? 0), 0) / parentsB.length;
|
|
919
|
+
if (Math.abs(avgA - avgB) > 1e-3) return avgA - avgB;
|
|
920
|
+
}
|
|
921
|
+
return (nodeDeclOrder.get(a) ?? 0) - (nodeDeclOrder.get(b) ?? 0);
|
|
922
|
+
});
|
|
923
|
+
ids.forEach((id, idx) => {
|
|
924
|
+
rankOrder.set(id, idx);
|
|
904
925
|
});
|
|
905
926
|
}
|
|
906
927
|
const isVertical = direction === "TB" || direction === "BT";
|
|
@@ -1681,7 +1702,7 @@ function layoutNodes(ast, edges) {
|
|
|
1681
1702
|
const dtype = diagramType(ast);
|
|
1682
1703
|
switch (dtype) {
|
|
1683
1704
|
case "flowchart":
|
|
1684
|
-
return layoutRanked(ast, edges, { forceVertical:
|
|
1705
|
+
return layoutRanked(ast, edges, { forceVertical: ast.meta.direction === "TB" || ast.meta.direction === "BT" });
|
|
1685
1706
|
case "tree":
|
|
1686
1707
|
return layoutTree(ast, edges.some((edge) => edge.structural) ? edges.filter((edge) => edge.structural) : edges);
|
|
1687
1708
|
case "sequence":
|
|
@@ -2978,6 +2999,9 @@ function parse(source, opts = {}) {
|
|
|
2978
2999
|
diagnostics.push({ severity: "warning", message: `unknown diagram type '${v}'`, line: lineNo });
|
|
2979
3000
|
} else {
|
|
2980
3001
|
meta.type = t;
|
|
3002
|
+
if (t === "flowchart" && !props.direction && !props.layout && !inlineLayout) {
|
|
3003
|
+
meta.direction = "TB";
|
|
3004
|
+
}
|
|
2981
3005
|
}
|
|
2982
3006
|
}
|
|
2983
3007
|
}
|
package/package.json
CHANGED