@principal-ai/subsystems-react 0.56.30 → 0.56.32

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.
@@ -254,6 +254,81 @@ export interface Point {
254
254
  y: number;
255
255
  }
256
256
 
257
+ export interface LayoutRect {
258
+ x: number;
259
+ y: number;
260
+ width: number;
261
+ height: number;
262
+ }
263
+
264
+ export interface EdgeBoundsGeometry {
265
+ points?: readonly Point[];
266
+ /** Center of the edge's overlay label, in absolute flow coordinates. */
267
+ labelCenter?: Point;
268
+ }
269
+
270
+ /**
271
+ * Bounds the visible graph geometry in ELK's absolute flow coordinate space.
272
+ * React Flow's `fitView` frames nodes only; routed edges and their overlay labels
273
+ * can extend beyond those rectangles. Callers can include label boxes as rects.
274
+ */
275
+ export function boundsOfRectsAndPoints(
276
+ rects: Iterable<LayoutRect>,
277
+ points: Iterable<Point>,
278
+ ): LayoutRect | undefined {
279
+ let minX = Infinity;
280
+ let minY = Infinity;
281
+ let maxX = -Infinity;
282
+ let maxY = -Infinity;
283
+
284
+ for (const rect of rects) {
285
+ const right = rect.x + rect.width;
286
+ const bottom = rect.y + rect.height;
287
+ if (![rect.x, rect.y, right, bottom].every(Number.isFinite)) continue;
288
+ minX = Math.min(minX, rect.x);
289
+ minY = Math.min(minY, rect.y);
290
+ maxX = Math.max(maxX, right);
291
+ maxY = Math.max(maxY, bottom);
292
+ }
293
+ for (const point of points) {
294
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) continue;
295
+ minX = Math.min(minX, point.x);
296
+ minY = Math.min(minY, point.y);
297
+ maxX = Math.max(maxX, point.x);
298
+ maxY = Math.max(maxY, point.y);
299
+ }
300
+
301
+ if (!Number.isFinite(minX) || !Number.isFinite(minY)) return undefined;
302
+ return {
303
+ x: minX,
304
+ y: minY,
305
+ width: Math.max(1, maxX - minX),
306
+ height: Math.max(1, maxY - minY),
307
+ };
308
+ }
309
+
310
+ /** Bounds node rectangles together with routed edge paths and centered labels. */
311
+ export function graphGeometryBounds(
312
+ nodeRects: Iterable<LayoutRect>,
313
+ edges: Iterable<EdgeBoundsGeometry>,
314
+ labelSize: { width: number; height: number },
315
+ ): LayoutRect | undefined {
316
+ const rects = [...nodeRects];
317
+ const points: Point[] = [];
318
+ for (const edge of edges) {
319
+ if (edge.points) points.push(...edge.points);
320
+ if (edge.labelCenter) {
321
+ rects.push({
322
+ x: edge.labelCenter.x - labelSize.width / 2,
323
+ y: edge.labelCenter.y - labelSize.height / 2,
324
+ width: labelSize.width,
325
+ height: labelSize.height,
326
+ });
327
+ }
328
+ }
329
+ return boundsOfRectsAndPoints(rects, points);
330
+ }
331
+
257
332
  /** ELK edge section with bend points */
258
333
  interface ElkEdgeSection {
259
334
  id: string;