@crazyhappyone/auto-graph 0.1.0 → 0.1.1

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.
@@ -3147,6 +3147,15 @@ function fitDslLabel(label, measurer) {
3147
3147
  function point(value) {
3148
3148
  return { x: value.x, y: value.y };
3149
3149
  }
3150
+
3151
+ // src/ir/diagnostics.ts
3152
+ var DELIVERABILITY_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
3153
+ "constraints.locked-target-not-moved",
3154
+ "routing.evidence.crossing_forbidden",
3155
+ "routing.obstacle.unavoidable",
3156
+ "route_obstacle_fallback",
3157
+ "routing.text-clearance.unresolved"
3158
+ ]);
3150
3159
  var DEFAULT_OPTIONS = {
3151
3160
  nodesep: 80,
3152
3161
  ranksep: 100,
@@ -3393,21 +3402,29 @@ function routeEdge(input) {
3393
3402
  }
3394
3403
  function finalizeRoute(points, softObstacles, hardObstacles, diagnostics) {
3395
3404
  const simplified = simplifyRoute(points);
3405
+ if (simplified.length >= 3) {
3406
+ return simplified;
3407
+ }
3396
3408
  const crossesHardObstacles = routeCrossesBoxes(simplified, hardObstacles);
3397
3409
  const crossesSoftObstacles = routeCrossesBoxes(simplified, softObstacles);
3398
- if (simplified.length < 3 && (crossesHardObstacles || crossesSoftObstacles)) {
3410
+ if (!crossesHardObstacles && !crossesSoftObstacles) {
3411
+ return simplified;
3412
+ }
3413
+ const expanded = expandFallbackRoute(simplified, [
3414
+ ...softObstacles,
3415
+ ...hardObstacles
3416
+ ]);
3417
+ const expandedCrossesHard = routeCrossesBoxes(expanded, hardObstacles);
3418
+ const expandedCrossesSoft = routeCrossesBoxes(expanded, softObstacles);
3419
+ if (expandedCrossesHard || expandedCrossesSoft) {
3399
3420
  diagnostics.push({
3400
- severity: crossesHardObstacles ? "error" : "warning",
3421
+ severity: expandedCrossesHard ? "error" : "warning",
3401
3422
  code: "route_obstacle_fallback",
3402
3423
  message: "Obstacle-aware routing fell back to fewer than three route points.",
3403
3424
  detail: { pointCount: simplified.length }
3404
3425
  });
3405
- return expandFallbackRoute(simplified, [
3406
- ...softObstacles,
3407
- ...hardObstacles
3408
- ]);
3409
3426
  }
3410
- return simplified;
3427
+ return expanded;
3411
3428
  }
3412
3429
  function expandFallbackRoute(points, obstacles) {
3413
3430
  if (points.length !== 2) {
@@ -3438,12 +3455,12 @@ function expandFallbackRoute(points, obstacles) {
3438
3455
  const hv = diagonalDetourHV(source, target, obstacles);
3439
3456
  const vh = diagonalDetourVH(source, target, obstacles);
3440
3457
  const viable = [hv, vh].filter((c) => !routeCrossesBoxes(c, obstacles));
3441
- if (viable.length > 0) {
3458
+ const [firstViable, ...remainingViable] = viable;
3459
+ if (firstViable !== void 0) {
3442
3460
  const directLen = Math.hypot(target.x - source.x, target.y - source.y);
3443
- let best = viable[0];
3444
- for (let i = 1; i < viable.length; i += 1) {
3445
- const cand = viable[i];
3446
- if (cand !== void 0 && pathLength(cand) - directLen < pathLength(best) - directLen) {
3461
+ let best = firstViable;
3462
+ for (const cand of remainingViable) {
3463
+ if (pathLength(cand) - directLen < pathLength(best) - directLen) {
3447
3464
  best = cand;
3448
3465
  }
3449
3466
  }
@@ -4029,6 +4046,7 @@ function solveDiagram(diagram, options = {}) {
4029
4046
  ];
4030
4047
  const initialContentBounds = layoutBoxes.length === 0 ? { x: 0, y: 0, width: 0} : unionBoxes(layoutBoxes);
4031
4048
  placeEvidenceBlocks(
4049
+ options.obstacleMargin ?? 0,
4032
4050
  [
4033
4051
  ...coordinatedMatrices,
4034
4052
  ...coordinatedTables,
@@ -4095,17 +4113,33 @@ function solveDiagram(diagram, options = {}) {
4095
4113
  ...baseTextAnnotations.filter(isPreRouteTextObstacle),
4096
4114
  ...frameTextAnnotation.filter(isPreRouteTextObstacle)
4097
4115
  ];
4116
+ const margin = options.obstacleMargin ?? 0;
4117
+ const softObstacles = [
4118
+ ...coordinatedTables.map((table) => expandBox(table.box, margin)),
4119
+ ...coordinatedEvidencePanels.map((panel) => expandBox(panel.box, margin))
4120
+ ];
4121
+ const hardObstacles = coordinatedMatrices.map(
4122
+ (matrix) => expandBox(matrix.box, margin)
4123
+ );
4124
+ const titleBarObstacles = [];
4125
+ if (frame !== void 0) {
4126
+ titleBarObstacles.push(expandBox(frame.titleBox, margin));
4127
+ }
4128
+ for (const swimlane of coordinatedSwimlanes) {
4129
+ for (const lane of swimlane.lanes) {
4130
+ if (lane.headerBox !== void 0 && lane.headerBox.width > 0 && lane.headerBox.height > 0) {
4131
+ titleBarObstacles.push(expandBox(lane.headerBox, margin));
4132
+ }
4133
+ }
4134
+ }
4098
4135
  const coordinatedEdges = coordinateEdges(
4099
4136
  styledEdges,
4100
4137
  nodeGeometryById,
4101
4138
  coordinatedNodes,
4102
4139
  [...nodeGeometryById.values()].map((geometry) => geometry.obstacleBox),
4103
- [
4104
- ...coordinatedTables.map((table) => table.box),
4105
- ...coordinatedEvidencePanels.map((panel) => panel.box)
4106
- ],
4140
+ [...softObstacles, ...titleBarObstacles],
4107
4141
  routingTextObstacles,
4108
- coordinatedMatrices.map((matrix) => matrix.box),
4142
+ hardObstacles,
4109
4143
  diagram.direction,
4110
4144
  options,
4111
4145
  diagnostics
@@ -4140,6 +4174,16 @@ function solveDiagram(diagram, options = {}) {
4140
4174
  options.pageBounds
4141
4175
  )
4142
4176
  );
4177
+ let degraded = false;
4178
+ const resultDiagnostics = diagnostics.map((diagnostic) => {
4179
+ if (DELIVERABILITY_DIAGNOSTIC_CODES.has(diagnostic.code)) {
4180
+ degraded = true;
4181
+ if (options.strict) {
4182
+ return { ...diagnostic, severity: "error" };
4183
+ }
4184
+ }
4185
+ return diagnostic;
4186
+ });
4143
4187
  return {
4144
4188
  id: diagram.id,
4145
4189
  ...diagram.title === void 0 ? {} : { title: diagram.title },
@@ -4151,7 +4195,8 @@ function solveDiagram(diagram, options = {}) {
4151
4195
  ...coordinatedMatrices.length === 0 ? {} : { matrices: coordinatedMatrices },
4152
4196
  ...coordinatedTables.length === 0 ? {} : { tables: coordinatedTables },
4153
4197
  ...coordinatedEvidencePanels.length === 0 ? {} : { evidencePanels: coordinatedEvidencePanels },
4154
- diagnostics,
4198
+ diagnostics: resultDiagnostics,
4199
+ degraded,
4155
4200
  bounds: frame === void 0 ? unionBoxes(boundsBase) : unionBoxes([...boundsBase, frame.box, frame.titleBox]),
4156
4201
  ...frame === void 0 ? {} : { frame },
4157
4202
  ...textAnnotations.length === 0 ? {} : { textAnnotations },
@@ -5537,16 +5582,25 @@ function blockBox(block, defaultSize) {
5537
5582
  height: block.size?.height ?? defaultSize.height
5538
5583
  };
5539
5584
  }
5540
- function placeEvidenceBlocks(blocks, contentBounds) {
5585
+ function placeEvidenceBlocks(obstacleMargin, blocks, contentBounds) {
5586
+ const margin = normalizeInsets(obstacleMargin);
5587
+ const horizontalGap = Math.max(
5588
+ DEFAULT_EVIDENCE_BLOCK_GAP,
5589
+ margin.right + margin.left
5590
+ );
5591
+ const verticalGap = Math.max(
5592
+ DEFAULT_EVIDENCE_BLOCK_GAP,
5593
+ margin.bottom + margin.top
5594
+ );
5541
5595
  let nextY = contentBounds.y;
5542
- const x = contentBounds.x + contentBounds.width + DEFAULT_EVIDENCE_BLOCK_GAP;
5596
+ const x = contentBounds.x + contentBounds.width + horizontalGap;
5543
5597
  for (const block of blocks) {
5544
5598
  if (block.position !== void 0) {
5545
5599
  continue;
5546
5600
  }
5547
5601
  block.box.x = x;
5548
5602
  block.box.y = nextY;
5549
- nextY += block.box.height + DEFAULT_EVIDENCE_BLOCK_GAP;
5603
+ nextY += block.box.height + verticalGap;
5550
5604
  }
5551
5605
  }
5552
5606
  function columnXOffsets(table, box) {