@aranzatech/diagrams-bpmn 0.3.6 → 0.3.7

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.
@@ -1063,11 +1063,39 @@ function routeMidX(sAbs, sW, tAbs, tW) {
1063
1063
  const rightEdge = Math.max(sAbs.x, tAbs.x);
1064
1064
  return leftEdge < rightEdge ? leftEdge + (rightEdge - leftEdge) * 0.35 : sAbs.x + sW / 2;
1065
1065
  }
1066
+ var HANDLE_SIDES = ["right", "left", "top", "bottom"];
1067
+ function borderHandle(point, rect, kind) {
1068
+ const dist = {
1069
+ right: Math.abs(point.x - (rect.x + rect.w)),
1070
+ left: Math.abs(point.x - rect.x),
1071
+ top: Math.abs(point.y - rect.y),
1072
+ bottom: Math.abs(point.y - (rect.y + rect.h))
1073
+ };
1074
+ let side = "right";
1075
+ let best = Infinity;
1076
+ for (const s of HANDLE_SIDES) {
1077
+ if (dist[s] < best) {
1078
+ best = dist[s];
1079
+ side = s;
1080
+ }
1081
+ }
1082
+ return `${kind}-${side}`;
1083
+ }
1066
1084
  var SAME_ROW_THRESHOLD = 15;
1067
1085
  function routeEdges(edges, layoutNodes, backEdgeIds, laneIds, poolIds) {
1068
1086
  const byId = new Map(layoutNodes.map((n) => [n.id, n]));
1069
1087
  const cache = /* @__PURE__ */ new Map();
1070
1088
  const abs = (id) => absolutePos(id, byId, cache);
1089
+ const handlesFor = (srcId, tgtId, pts) => {
1090
+ if (pts.length < 2) return {};
1091
+ const s = byId.get(srcId), t = byId.get(tgtId);
1092
+ if (!s || !t) return {};
1093
+ const sa = abs(srcId), ta = abs(tgtId);
1094
+ return {
1095
+ sourceHandle: borderHandle(pts[0], { x: sa.x, y: sa.y, w: nW(s), h: nH(s) }, "source"),
1096
+ targetHandle: borderHandle(pts[pts.length - 1], { x: ta.x, y: ta.y, w: nW(t), h: nH(t) }, "target")
1097
+ };
1098
+ };
1071
1099
  const sortedLanes = [...laneIds].map((id) => byId.get(id)).filter((n) => !!n).sort((a, b) => abs(a.id).y - abs(b.id).y);
1072
1100
  const contentInfos = layoutNodes.filter((n) => !poolIds.has(n.id) && !laneIds.has(n.id)).map((n) => {
1073
1101
  const p = abs(n.id);
@@ -1135,7 +1163,11 @@ function routeEdges(edges, layoutNodes, backEdgeIds, laneIds, poolIds) {
1135
1163
  if (edgeType === "messageFlow") {
1136
1164
  const pts = routeMessageFlow(edge);
1137
1165
  if (pts) {
1138
- return { ...edge, data: { ...edge.data, routingPoints: pts } };
1166
+ return {
1167
+ ...edge,
1168
+ ...handlesFor(edge.source, edge.target, pts),
1169
+ data: { ...edge.data, routingPoints: pts }
1170
+ };
1139
1171
  }
1140
1172
  }
1141
1173
  const d = { ...edge.data };
@@ -1249,7 +1281,13 @@ function routeEdges(edges, layoutNodes, backEdgeIds, laneIds, poolIds) {
1249
1281
  } else if (Math.abs(sCY - tCY) <= SAME_ROW_THRESHOLD) {
1250
1282
  const d = { ...edge.data };
1251
1283
  delete d.routingPoints;
1252
- return { ...edge, data: d };
1284
+ const goesRight = tCX >= sCX;
1285
+ return {
1286
+ ...edge,
1287
+ sourceHandle: goesRight ? "source-right" : "source-left",
1288
+ targetHandle: goesRight ? "target-left" : "target-right",
1289
+ data: d
1290
+ };
1253
1291
  } else {
1254
1292
  const handle = edge.sourceHandle ?? "";
1255
1293
  const exitsTop = handle.includes("top");
@@ -1286,7 +1324,11 @@ function routeEdges(edges, layoutNodes, backEdgeIds, laneIds, poolIds) {
1286
1324
  ];
1287
1325
  }
1288
1326
  }
1289
- return { ...edge, data: { ...edge.data, routingPoints } };
1327
+ return {
1328
+ ...edge,
1329
+ ...handlesFor(edge.source, edge.target, routingPoints),
1330
+ data: { ...edge.data, routingPoints }
1331
+ };
1290
1332
  });
1291
1333
  return spreadVerticalChannels(routed);
1292
1334
  }