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