bpmn-elk-layout 1.0.1 → 1.0.2

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 CHANGED
@@ -298,6 +298,11 @@ function lineIntersection(p1, p2, p3, p4) {
298
298
  }
299
299
 
300
300
  // src/utils/debug.ts
301
+ var cliMode = false;
302
+ function isDebugEnabled() {
303
+ if (cliMode) return false;
304
+ return typeof process !== "undefined" && process.env?.["DEBUG"] === "true";
305
+ }
301
306
  var DEBUG = typeof process !== "undefined" && process.env?.["DEBUG"] === "true";
302
307
 
303
308
  // src/layout/edge-routing/edge-fixer.ts
@@ -331,7 +336,7 @@ var EdgeFixer = class {
331
336
  const isFlowNode = flowNodePatterns.some((pattern) => pattern.test(id));
332
337
  const isPool = poolPatterns.some((pattern) => pattern.test(id));
333
338
  const bpmn = node.bpmn;
334
- if (DEBUG && (id.includes("lane") || id.includes("pool") || id.includes("end_fast") || id.includes("gateway_fast"))) {
339
+ if (isDebugEnabled() && (id.includes("lane") || id.includes("pool") || id.includes("end_fast") || id.includes("gateway_fast"))) {
335
340
  console.log(`[BPMN] EdgeFixer.collectNodePositions: id=${id}, offsetX=${offsetX}, offsetY=${offsetY}, bpmn=${JSON.stringify(bpmn)}`);
336
341
  console.log(`[BPMN] node.x=${node.x}, node.y=${node.y}, isFlowNode=${isFlowNode}, isPool=${isPool}`);
337
342
  }
@@ -420,7 +425,7 @@ var EdgeFixer = class {
420
425
  }
421
426
  const targetPos = targetId ? nodePositions.get(targetId) : void 0;
422
427
  const sourcePos = sourceId ? nodePositions.get(sourceId) : void 0;
423
- if (DEBUG && edge.id?.includes("back")) {
428
+ if (isDebugEnabled() && edge.id?.includes("back")) {
424
429
  console.log(`[BPMN] Edge ${edge.id}: sourceId=${sourceId}, targetId=${targetId}`);
425
430
  console.log(`[BPMN] Edge ${edge.id}: sourcePos=${JSON.stringify(sourcePos)}, targetPos=${JSON.stringify(targetPos)}`);
426
431
  console.log(`[BPMN] Edge ${edge.id}: waypoints.length=${waypoints.length}`);
@@ -429,7 +434,7 @@ var EdgeFixer = class {
429
434
  const lastWaypoint = waypoints[waypoints.length - 1];
430
435
  const secondLastWaypoint = waypoints[waypoints.length - 2];
431
436
  const isReturnEdge2 = targetPos.y + targetPos.height < sourcePos.y;
432
- if (DEBUG && edge.id?.includes("back")) {
437
+ if (isDebugEnabled() && edge.id?.includes("back")) {
433
438
  console.log(`[BPMN] Edge ${edge.id}: isReturnEdge=${isReturnEdge2}`);
434
439
  if (lastWaypoint) {
435
440
  console.log(`[BPMN] Edge ${edge.id}: lastWaypoint=(${lastWaypoint.x},${lastWaypoint.y})`);
@@ -449,7 +454,7 @@ var EdgeFixer = class {
449
454
  }
450
455
  }
451
456
  if (crossedNodes.length === 0) return;
452
- if (DEBUG) {
457
+ if (isDebugEnabled()) {
453
458
  console.log(`[BPMN] Edge ${edge.id} crosses nodes: ${crossedNodes.join(", ")}`);
454
459
  }
455
460
  if (!sourcePos || !targetPos) return;
@@ -500,7 +505,7 @@ var EdgeFixer = class {
500
505
  y: bp.y - containerOffsetY
501
506
  }));
502
507
  section.bendPoints = relativeBendPoints.length > 0 ? relativeBendPoints : void 0;
503
- if (DEBUG) {
508
+ if (isDebugEnabled()) {
504
509
  console.log(`[BPMN] Fixed edge ${edge.id} with ${relativeBendPoints.length} bend points`);
505
510
  }
506
511
  }
@@ -1290,7 +1295,8 @@ function applyNodeMoves(graph, movedNodes) {
1290
1295
  }
1291
1296
 
1292
1297
  // src/layout/post-processing/boundary-event/edge-recalculator.ts
1293
- function recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo, debug = false) {
1298
+ function recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo) {
1299
+ const debug = isDebugEnabled();
1294
1300
  const nodeMap = /* @__PURE__ */ new Map();
1295
1301
  const buildNodeMap2 = (node) => {
1296
1302
  nodeMap.set(node.id, node);
@@ -1367,7 +1373,8 @@ function recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo, deb
1367
1373
  };
1368
1374
  processEdges(graph);
1369
1375
  }
1370
- function recalculateEdgeWithObstacleAvoidance(edge, source, target, obstacleIds, nodeMap, debug = false) {
1376
+ function recalculateEdgeWithObstacleAvoidance(edge, source, target, obstacleIds, nodeMap) {
1377
+ const debug = isDebugEnabled();
1371
1378
  const sx = source.x ?? 0;
1372
1379
  const sy = source.y ?? 0;
1373
1380
  const sw = source.width ?? 100;
@@ -1588,8 +1595,8 @@ var BoundaryEventHandler = class {
1588
1595
  /**
1589
1596
  * Recalculate edge waypoints for edges connected to moved nodes
1590
1597
  */
1591
- recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo, debug = false) {
1592
- recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo, debug);
1598
+ recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo) {
1599
+ recalculateEdgesForMovedNodes(graph, movedNodes, boundaryEventInfo);
1593
1600
  }
1594
1601
  };
1595
1602
 
@@ -2476,7 +2483,7 @@ var LaneArranger = class {
2476
2483
  const targetId = edge.targets?.[0];
2477
2484
  const sourcePos = sourceId ? nodePositions.get(sourceId) : void 0;
2478
2485
  const targetPos = targetId ? nodePositions.get(targetId) : void 0;
2479
- if (DEBUG) {
2486
+ if (isDebugEnabled()) {
2480
2487
  console.log(`[BPMN] recalculatePoolEdges ${edge.id}: source=${sourceId}, target=${targetId}`);
2481
2488
  console.log(`[BPMN] sourcePos=${JSON.stringify(sourcePos)}`);
2482
2489
  console.log(`[BPMN] targetPos=${JSON.stringify(targetPos)}`);
@@ -2486,7 +2493,7 @@ var LaneArranger = class {
2486
2493
  const startY = sourcePos.y + sourcePos.height / 2;
2487
2494
  const endX = targetPos.x;
2488
2495
  const endY = targetPos.y + targetPos.height / 2;
2489
- if (DEBUG) {
2496
+ if (isDebugEnabled()) {
2490
2497
  console.log(`[BPMN] startX=${startX}, startY=${startY}, endX=${endX}, endY=${endY}`);
2491
2498
  }
2492
2499
  const waypoints = [];
@@ -2497,7 +2504,7 @@ var LaneArranger = class {
2497
2504
  waypoints.push({ x: midX, y: endY });
2498
2505
  }
2499
2506
  waypoints.push({ x: endX, y: endY });
2500
- if (DEBUG) {
2507
+ if (isDebugEnabled()) {
2501
2508
  console.log(`[BPMN] waypoints=${JSON.stringify(waypoints)}`);
2502
2509
  }
2503
2510
  edge._poolRelativeCoords = true;
@@ -3005,7 +3012,7 @@ var GatewayEdgeAdjuster = class {
3005
3012
  const gateways = /* @__PURE__ */ new Map();
3006
3013
  this.collectGateways(layoutedGraph, originalGraph, gateways, 0, 0);
3007
3014
  if (gateways.size === 0) return;
3008
- if (DEBUG) {
3015
+ if (isDebugEnabled()) {
3009
3016
  console.log(`[BPMN] GatewayEdgeAdjuster: Found ${gateways.size} gateways`);
3010
3017
  for (const [id, info] of gateways) {
3011
3018
  console.log(`[BPMN] - ${id}: bounds=(${info.bounds.x},${info.bounds.y},${info.bounds.width},${info.bounds.height})`);
@@ -3092,7 +3099,7 @@ var GatewayEdgeAdjuster = class {
3092
3099
  const section = edge.sections[0];
3093
3100
  const sourceId = edge.sources?.[0];
3094
3101
  const targetId = edge.targets?.[0];
3095
- if (DEBUG) {
3102
+ if (isDebugEnabled()) {
3096
3103
  console.log(`[BPMN] GatewayEdgeAdjuster: Processing edge ${edge.id}, offset=(${offsetX},${offsetY})`);
3097
3104
  console.log(`[BPMN] sourceId=${sourceId}, targetId=${targetId}`);
3098
3105
  console.log(`[BPMN] startPoint=(${section.startPoint.x},${section.startPoint.y}), endPoint=(${section.endPoint.x},${section.endPoint.y})`);
@@ -3104,7 +3111,7 @@ var GatewayEdgeAdjuster = class {
3104
3111
  }
3105
3112
  const targetGateway = targetId ? gateways.get(targetId) : void 0;
3106
3113
  if (targetGateway) {
3107
- if (DEBUG) {
3114
+ if (isDebugEnabled()) {
3108
3115
  console.log(`[BPMN] target gateway: ${targetId}, bounds=(${targetGateway.bounds.x},${targetGateway.bounds.y})`);
3109
3116
  console.log(`[BPMN] left corner: (${targetGateway.corners.left.x},${targetGateway.corners.left.y})`);
3110
3117
  }
@@ -3175,7 +3182,7 @@ var GatewayEdgeAdjuster = class {
3175
3182
  lastBend.x = newEnd.x;
3176
3183
  }
3177
3184
  }
3178
- if (DEBUG) {
3185
+ if (isDebugEnabled()) {
3179
3186
  console.log(`[BPMN] GatewayEdgeAdjuster: Adjusted edge ${edge.id} endpoint from (${endX},${endY}) to (${targetCorner.x},${targetCorner.y})`);
3180
3187
  }
3181
3188
  } else {
@@ -3189,7 +3196,7 @@ var GatewayEdgeAdjuster = class {
3189
3196
  x: intersectionPoint.x - offsetX,
3190
3197
  y: intersectionPoint.y - offsetY
3191
3198
  };
3192
- if (DEBUG) {
3199
+ if (isDebugEnabled()) {
3193
3200
  console.log(`[BPMN] GatewayEdgeAdjuster: Adjusted edge ${edge.id} endpoint to diamond intersection (${intersectionPoint.x},${intersectionPoint.y})`);
3194
3201
  }
3195
3202
  }
@@ -3449,7 +3456,7 @@ var ElkGraphPreparer = class {
3449
3456
  for (const startId of startEvents) {
3450
3457
  traverseMainFlow(startId);
3451
3458
  }
3452
- if (DEBUG) {
3459
+ if (isDebugEnabled()) {
3453
3460
  console.log(`[BPMN] Main flow nodes: ${Array.from(mainFlowNodes).join(", ")}`);
3454
3461
  }
3455
3462
  return mainFlowNodes;
@@ -3784,7 +3791,7 @@ var ResultMerger = class {
3784
3791
  return originalEdges.map((origEdge) => {
3785
3792
  const layoutedEdge = layoutedEdgeMap.get(origEdge.id);
3786
3793
  if (layoutedEdge) {
3787
- if (DEBUG && layoutedEdge.sections?.[0]?.bendPoints?.length) {
3794
+ if (isDebugEnabled() && layoutedEdge.sections?.[0]?.bendPoints?.length) {
3788
3795
  console.log(`[BPMN] Merge ${origEdge.id}: bendPoints=${JSON.stringify(layoutedEdge.sections[0].bendPoints)}`);
3789
3796
  }
3790
3797
  const mergedEdge = {
@@ -3922,7 +3929,7 @@ var MainFlowNormalizer = class {
3922
3929
  return;
3923
3930
  }
3924
3931
  const offsetY = currentMinY - TARGET_MAIN_FLOW_Y;
3925
- if (DEBUG) {
3932
+ if (isDebugEnabled()) {
3926
3933
  console.log(`[BPMN] Normalizing main flow: currentMinY=${currentMinY}, offsetY=${offsetY}`);
3927
3934
  console.log(`[BPMN] Upstream nodes: ${upstreamMainFlow.map((n) => n.id).join(", ")}`);
3928
3935
  console.log(`[BPMN] Downstream nodes: ${downstreamMainFlow.map((n) => n.id).join(", ")}`);
@@ -3930,7 +3937,7 @@ var MainFlowNormalizer = class {
3930
3937
  for (const node of otherUpstreamNodes) {
3931
3938
  if (node.y !== void 0) {
3932
3939
  node.y -= offsetY;
3933
- if (DEBUG) {
3940
+ if (isDebugEnabled()) {
3934
3941
  console.log(`[BPMN] Shifted upstream ${node.id} to y=${node.y}`);
3935
3942
  }
3936
3943
  }
@@ -3943,14 +3950,14 @@ var MainFlowNormalizer = class {
3943
3950
  const predecessorCenterY = predecessor.y + (predecessor.height ?? 80) / 2;
3944
3951
  const endNodeCenterY = (endNode.height ?? 36) / 2;
3945
3952
  endNode.y = predecessorCenterY - endNodeCenterY;
3946
- if (DEBUG) {
3953
+ if (isDebugEnabled()) {
3947
3954
  console.log(`[BPMN] Aligned endEvent ${endNode.id} with predecessor ${predecessorId}: y=${endNode.y}`);
3948
3955
  }
3949
3956
  }
3950
3957
  } else {
3951
3958
  if (endNode.y !== void 0) {
3952
3959
  endNode.y -= offsetY;
3953
- if (DEBUG) {
3960
+ if (isDebugEnabled()) {
3954
3961
  console.log(`[BPMN] Shifted upstream ${endNode.id} to y=${endNode.y} (no predecessor found)`);
3955
3962
  }
3956
3963
  }
@@ -3978,7 +3985,7 @@ var MainFlowNormalizer = class {
3978
3985
  const newY = prevBottom + MIN_SPACING;
3979
3986
  currNode.y = newY;
3980
3987
  adjustedEndEvents.set(currNode.id, newY);
3981
- if (DEBUG) {
3988
+ if (isDebugEnabled()) {
3982
3989
  console.log(`[BPMN] Adjusted overlapping endEvent ${currNode.id} at x=${x}: y=${currNode.y}`);
3983
3990
  }
3984
3991
  }
@@ -4002,7 +4009,7 @@ var MainFlowNormalizer = class {
4002
4009
  for (const node of downstreamMainFlow) {
4003
4010
  if (node.y !== void 0) {
4004
4011
  node.y -= downstreamOffsetY;
4005
- if (DEBUG) {
4012
+ if (isDebugEnabled()) {
4006
4013
  console.log(`[BPMN] Shifted downstream ${node.id} to y=${node.y}`);
4007
4014
  }
4008
4015
  }
@@ -4184,20 +4191,20 @@ var MainFlowNormalizer = class {
4184
4191
  lastBend.y = newTargetY;
4185
4192
  section.endPoint.y = newTargetY;
4186
4193
  edgesWithAdjustedEndpoint.add(edge.id);
4187
- if (DEBUG) {
4194
+ if (isDebugEnabled()) {
4188
4195
  console.log(`[BPMN] Updated edge ${edge.id} last bendPoint and endpoint to y=${newTargetY}`);
4189
4196
  }
4190
4197
  } else {
4191
4198
  section.endPoint.y = newTargetY;
4192
4199
  edgesWithAdjustedEndpoint.add(edge.id);
4193
- if (DEBUG) {
4200
+ if (isDebugEnabled()) {
4194
4201
  console.log(`[BPMN] Updated edge ${edge.id} endpoint to y=${newTargetY}`);
4195
4202
  }
4196
4203
  }
4197
4204
  } else if (section.endPoint) {
4198
4205
  section.endPoint.y = newTargetY;
4199
4206
  edgesWithAdjustedEndpoint.add(edge.id);
4200
- if (DEBUG) {
4207
+ if (isDebugEnabled()) {
4201
4208
  console.log(`[BPMN] Updated edge ${edge.id} endpoint to y=${newTargetY}`);
4202
4209
  }
4203
4210
  }
@@ -4311,7 +4318,7 @@ var GatewayPropagator = class {
4311
4318
  offset: 0,
4312
4319
  newX
4313
4320
  });
4314
- if (DEBUG) {
4321
+ if (isDebugEnabled()) {
4315
4322
  console.log(`[BPMN] Propagating gateway movement to ${targetId}: x ${currentX} -> ${newX}`);
4316
4323
  }
4317
4324
  this.propagateDownstreamX(targetId, newX, targetNode.width ?? 100, nodeMap, edgeMap, mainFlowNodes, gatewayMoves);
@@ -4339,7 +4346,7 @@ var GatewayPropagator = class {
4339
4346
  offset: 0,
4340
4347
  newX
4341
4348
  });
4342
- if (DEBUG) {
4349
+ if (isDebugEnabled()) {
4343
4350
  console.log(`[BPMN] Propagating X to ${targetId}: x ${currentX} -> ${newX}`);
4344
4351
  }
4345
4352
  this.propagateDownstreamX(targetId, newX, targetNode.width ?? 100, nodeMap, edgeMap, mainFlowNodes, moves);
@@ -4394,14 +4401,14 @@ var ElkLayouter = class {
4394
4401
  const layoutedElkGraph = await this.elk.layout(elkGraph);
4395
4402
  const mainFlowNodes = this.graphPreparer.identifyMainFlowNodes(sizedGraph, boundaryEventTargetIds);
4396
4403
  this.mainFlowNormalizer.normalize(layoutedElkGraph, mainFlowNodes, boundaryEventTargetIds, sizedGraph);
4397
- const movedNodes = this.boundaryEventHandler.identifyNodesToMove(layoutedElkGraph, boundaryEventInfo, sizedGraph, DEBUG);
4404
+ const movedNodes = this.boundaryEventHandler.identifyNodesToMove(layoutedElkGraph, boundaryEventInfo, sizedGraph, isDebugEnabled());
4398
4405
  if (movedNodes.size > 0) {
4399
4406
  this.boundaryEventHandler.applyNodeMoves(layoutedElkGraph, movedNodes);
4400
4407
  const gatewayMoves = this.boundaryEventHandler.repositionConvergingGateways(
4401
4408
  layoutedElkGraph,
4402
4409
  movedNodes,
4403
4410
  boundaryEventInfo,
4404
- DEBUG
4411
+ isDebugEnabled()
4405
4412
  );
4406
4413
  if (gatewayMoves.size > 0) {
4407
4414
  this.boundaryEventHandler.applyNodeMoves(layoutedElkGraph, gatewayMoves);
@@ -4410,7 +4417,7 @@ var ElkLayouter = class {
4410
4417
  for (const [id, move] of gatewayMoves) {
4411
4418
  movedNodes.set(id, move);
4412
4419
  }
4413
- this.boundaryEventHandler.recalculateEdgesForMovedNodes(layoutedElkGraph, movedNodes, boundaryEventInfo, DEBUG);
4420
+ this.boundaryEventHandler.recalculateEdgesForMovedNodes(layoutedElkGraph, movedNodes, boundaryEventInfo);
4414
4421
  }
4415
4422
  this.artifactPositioner.reposition(layoutedElkGraph, artifactInfo);
4416
4423
  this.laneArranger.rearrange(layoutedElkGraph, sizedGraph);
@@ -4684,7 +4691,7 @@ function adjustGatewayEndpoint(endpoint, adjacentPoint, gatewayBounds, isSource)
4684
4691
  const gatewayCenterX = gatewayBounds.x + gatewayBounds.width / 2;
4685
4692
  const gatewayCenterY = gatewayBounds.y + gatewayBounds.height / 2;
4686
4693
  const tolerance = 1;
4687
- if (DEBUG) {
4694
+ if (isDebugEnabled()) {
4688
4695
  console.log(`[BPMN] adjustGatewayEndpoint: isSource=${isSource}`);
4689
4696
  console.log(` endpoint: (${endpoint.x}, ${endpoint.y})`);
4690
4697
  console.log(` gatewayBounds: x=${gatewayBounds.x}, y=${gatewayBounds.y}, w=${gatewayBounds.width}, h=${gatewayBounds.height}`);
@@ -4696,22 +4703,22 @@ function adjustGatewayEndpoint(endpoint, adjacentPoint, gatewayBounds, isSource)
4696
4703
  const topCorner = { x: gatewayCenterX, y: gatewayBounds.y };
4697
4704
  const bottomCorner = { x: gatewayCenterX, y: gatewayBounds.y + gatewayBounds.height };
4698
4705
  if (Math.abs(endpoint.x - gatewayBounds.x) < tolerance && Math.abs(endpoint.y - gatewayCenterY) < tolerance) {
4699
- if (DEBUG) console.log(` -> Already at LEFT corner, no adjustment`);
4706
+ if (isDebugEnabled()) console.log(` -> Already at LEFT corner, no adjustment`);
4700
4707
  return endpoint;
4701
4708
  }
4702
4709
  if (Math.abs(endpoint.x - (gatewayBounds.x + gatewayBounds.width)) < tolerance && Math.abs(endpoint.y - gatewayCenterY) < tolerance) {
4703
- if (DEBUG) console.log(` -> Already at RIGHT corner, no adjustment`);
4710
+ if (isDebugEnabled()) console.log(` -> Already at RIGHT corner, no adjustment`);
4704
4711
  return endpoint;
4705
4712
  }
4706
4713
  if (Math.abs(endpoint.y - gatewayBounds.y) < tolerance && Math.abs(endpoint.x - gatewayCenterX) < tolerance) {
4707
- if (DEBUG) console.log(` -> Already at TOP corner, no adjustment`);
4714
+ if (isDebugEnabled()) console.log(` -> Already at TOP corner, no adjustment`);
4708
4715
  return endpoint;
4709
4716
  }
4710
4717
  if (Math.abs(endpoint.y - (gatewayBounds.y + gatewayBounds.height)) < tolerance && Math.abs(endpoint.x - gatewayCenterX) < tolerance) {
4711
- if (DEBUG) console.log(` -> Already at BOTTOM corner, no adjustment`);
4718
+ if (isDebugEnabled()) console.log(` -> Already at BOTTOM corner, no adjustment`);
4712
4719
  return endpoint;
4713
4720
  }
4714
- if (DEBUG) {
4721
+ if (isDebugEnabled()) {
4715
4722
  console.log(` -> NOT at corner, will adjust`);
4716
4723
  }
4717
4724
  const result = calculateDiamondIntersection(
@@ -4722,7 +4729,7 @@ function adjustGatewayEndpoint(endpoint, adjacentPoint, gatewayBounds, isSource)
4722
4729
  isSource,
4723
4730
  adjacentPoint
4724
4731
  );
4725
- if (DEBUG) {
4732
+ if (isDebugEnabled()) {
4726
4733
  console.log(` -> Adjusted to: (${result.x}, ${result.y})`);
4727
4734
  }
4728
4735
  return result;
@@ -5027,7 +5034,7 @@ var DiagramBuilder = class {
5027
5034
  const targetIsGateway = this.isGatewayType(targetNode?.type);
5028
5035
  let waypoints = [];
5029
5036
  const hasPreCalculatedSections = edge.sections && edge.sections.length > 0 && edge.sections[0]?.bendPoints && edge.sections[0].bendPoints.length > 0;
5030
- if (DEBUG && bePosition) {
5037
+ if (isDebugEnabled() && bePosition) {
5031
5038
  console.log(`[BPMN] buildEdge ${edge.id}: preCalculated=${hasPreCalculatedSections}`);
5032
5039
  }
5033
5040
  if (bePosition && targetPosition && !hasPreCalculatedSections) {