@statelyai/layout 0.1.2 → 0.2.0

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.
Files changed (61) hide show
  1. package/NOTICE.md +43 -0
  2. package/README.md +82 -4
  3. package/dist/elkjs/index.cjs +8 -0
  4. package/dist/elkjs/index.d.cts +146 -0
  5. package/dist/elkjs/index.d.mts +42 -39
  6. package/dist/elkjs/index.mjs +2 -1483
  7. package/dist/elkjs/main.cjs +17 -0
  8. package/dist/elkjs/main.d.cts +10 -0
  9. package/dist/elkjs/main.d.mts +11 -0
  10. package/dist/elkjs/main.mjs +17 -0
  11. package/dist/elkjs/worker-api.cjs +3 -0
  12. package/dist/elkjs/worker-api.d.cts +3 -0
  13. package/dist/elkjs/worker-api.d.mts +3 -0
  14. package/dist/elkjs/worker-api.mjs +3 -0
  15. package/dist/elkjs/worker.cjs +86 -0
  16. package/dist/elkjs/worker.d.cts +17 -0
  17. package/dist/elkjs/worker.d.mts +17 -0
  18. package/dist/elkjs/worker.mjs +86 -0
  19. package/dist/elkjs-BVnDwnBQ.cjs +1551 -0
  20. package/dist/elkjs-CFlfkEBz.mjs +1528 -0
  21. package/dist/{index-8xYkohbz.d.mts → index-BSH2bloA.d.mts} +77 -3
  22. package/dist/index-CG712jzV.d.cts +1286 -0
  23. package/dist/index.cjs +188 -0
  24. package/dist/index.d.cts +77 -0
  25. package/dist/index.d.mts +2 -2
  26. package/dist/index.mjs +24 -25
  27. package/dist/layered/index.cjs +38 -0
  28. package/dist/layered/index.d.cts +2 -0
  29. package/dist/layered/index.d.mts +1 -1
  30. package/dist/layered/index.mjs +1 -1
  31. package/dist/{layered-COIyXvwb.mjs → layered-Bz2nWmVp.mjs} +2298 -45
  32. package/dist/layered-Cf9Rn8l7.cjs +12061 -0
  33. package/dist/layout-engine-BNex9jxg.cjs +712 -0
  34. package/dist/{spore-BeKUA1Mb.mjs → layout-engine-WbC0YjjT.mjs} +159 -5
  35. package/dist/public-types-B8rAALJq.d.mts +109 -0
  36. package/dist/public-types-CVB0hXGk.d.cts +109 -0
  37. package/dist/worker-client-D3HMK33r.cjs +98 -0
  38. package/dist/worker-client-DAT_z2OR.d.mts +19 -0
  39. package/dist/worker-client-DVhklF6A.d.cts +19 -0
  40. package/dist/worker-client-DkwS4sHx.mjs +92 -0
  41. package/package.json +39 -9
  42. package/src/authoring/coordinates.ts +106 -0
  43. package/src/authoring/partial.ts +584 -0
  44. package/src/authoring/routing.ts +211 -0
  45. package/src/box.ts +22 -0
  46. package/src/constraints.ts +222 -0
  47. package/src/elkjs/index.ts +100 -37
  48. package/src/elkjs/main.ts +19 -0
  49. package/src/elkjs/public-types.ts +125 -0
  50. package/src/elkjs/worker-api.ts +29 -0
  51. package/src/elkjs/worker-client.ts +138 -0
  52. package/src/elkjs/worker.ts +117 -0
  53. package/src/index.ts +13 -0
  54. package/src/internal/elkjs-compatibility.ts +17 -0
  55. package/src/internal/layout-engine.ts +126 -0
  56. package/src/layered/index.ts +31 -3
  57. package/src/layered/strategies.ts +68 -3
  58. package/src/layout.ts +35 -28
  59. package/src/packing.ts +22 -0
  60. package/src/random.ts +75 -3
  61. package/src/types.ts +17 -2
@@ -1,6 +1,66 @@
1
1
  import { LayoutConstraints } from "@statelyai/graph/layout";
2
2
  import { EntityRect, Graph, GraphEdge, GraphNode, GraphPatch, GraphPort, Point, VisualGraph } from "@statelyai/graph";
3
3
 
4
+ //#region src/constraints.d.ts
5
+ type GeometryReference = {
6
+ nodeId: string;
7
+ } | {
8
+ edgeId: string;
9
+ part: "label";
10
+ };
11
+ type ConstraintStrength = "required" | "strong" | "medium" | "weak";
12
+ type GeometryAttribute = "x" | "y" | "centerX" | "centerY" | "right" | "bottom";
13
+ interface ConstraintBase {
14
+ id: string;
15
+ strength?: ConstraintStrength;
16
+ }
17
+ interface AlignConstraint extends ConstraintBase {
18
+ kind: "align";
19
+ entities: readonly GeometryReference[];
20
+ axis: "x" | "y";
21
+ anchor?: "start" | "center" | "end";
22
+ }
23
+ interface DistributeConstraint extends ConstraintBase {
24
+ kind: "distribute";
25
+ entities: readonly GeometryReference[];
26
+ axis: "x" | "y";
27
+ spacing?: "gaps" | "centers";
28
+ gap?: number;
29
+ }
30
+ interface PinConstraint extends ConstraintBase {
31
+ kind: "pin";
32
+ entity: GeometryReference;
33
+ x?: number;
34
+ y?: number;
35
+ }
36
+ interface LinearConstraint extends ConstraintBase {
37
+ kind: "linear";
38
+ terms: readonly {
39
+ entity: GeometryReference;
40
+ attribute: GeometryAttribute;
41
+ coefficient: number;
42
+ }[];
43
+ relation: "eq" | "le" | "ge";
44
+ value: number;
45
+ }
46
+ interface WaypointConstraint extends ConstraintBase {
47
+ kind: "waypoint";
48
+ edgeId: string;
49
+ point: {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ }
54
+ type LayoutConstraint = AlignConstraint | DistributeConstraint | PinConstraint | LinearConstraint | WaypointConstraint;
55
+ /** Serializable constraint constructors; graph geometry stays in @statelyai/graph. */
56
+ declare const c: {
57
+ align: (value: Omit<AlignConstraint, "kind">) => AlignConstraint;
58
+ distribute: (value: Omit<DistributeConstraint, "kind">) => DistributeConstraint;
59
+ pin: (value: Omit<PinConstraint, "kind">) => PinConstraint;
60
+ linear: (value: Omit<LinearConstraint, "kind">) => LinearConstraint;
61
+ waypoint: (value: Omit<WaypointConstraint, "kind">) => WaypointConstraint;
62
+ };
63
+ //#endregion
4
64
  //#region src/types.d.ts
5
65
  type AnyGraph = Graph<unknown, unknown, unknown, unknown>;
6
66
  type LayoutDirection = "up" | "down" | "left" | "right";
@@ -11,8 +71,16 @@ type LayoutScope = {
11
71
  previous: VisualGraph;
12
72
  } | {
13
73
  mode: "partial";
14
- previous: VisualGraph;
15
- nodeIds: readonly string[];
74
+ /** Missing current geometry falls back to these matching entity IDs. */
75
+ previous?: VisualGraph;
76
+ /** Position permission only. Omitted or empty selects no nodes. */
77
+ nodeIds?: readonly string[];
78
+ /** Edge selection never grants permission to move endpoints. */
79
+ edgeIds?: readonly string[];
80
+ /** Defaults to affected; automatic changes obey edgeGeometry. */
81
+ routing?: "selected" | "affected";
82
+ /** Defaults to both; dimensions remain fixed. */
83
+ edgeGeometry?: "routes" | "labels" | "both";
16
84
  } | {
17
85
  mode: "route-only";
18
86
  previous: VisualGraph;
@@ -24,6 +92,8 @@ interface LayoutDiagnostic {
24
92
  message: string;
25
93
  entityIds?: readonly string[];
26
94
  phase?: string;
95
+ constraintIds?: readonly string[];
96
+ geometry?: "node" | "routes" | "labels";
27
97
  }
28
98
  interface LayoutPhaseMetrics {
29
99
  id: string;
@@ -36,6 +106,8 @@ interface LayoutMetrics {
36
106
  phases: readonly LayoutPhaseMetrics[];
37
107
  }
38
108
  interface LayoutCapabilities {
109
+ /** Common geometry constraints; absent means unsupported. */
110
+ constraints?: boolean;
39
111
  full: boolean;
40
112
  incremental: boolean;
41
113
  partial: boolean;
@@ -50,6 +122,7 @@ interface LayoutAlgorithm<Options = unknown> {
50
122
  }
51
123
  interface LayoutExecutionContext {
52
124
  readonly scope: LayoutScope;
125
+ readonly constraints?: readonly LayoutConstraint[];
53
126
  readonly signal?: AbortSignal;
54
127
  readonly diagnostics: LayoutDiagnostic[];
55
128
  measurePhase<T>(id: string, run: () => T): T;
@@ -60,6 +133,7 @@ interface LayoutRequest<N = unknown, E = unknown, G = unknown, P = unknown, O =
60
133
  algorithm?: string | LayoutAlgorithm<O>;
61
134
  options?: O;
62
135
  scope?: LayoutScope;
136
+ constraints?: readonly LayoutConstraint[];
63
137
  signal?: AbortSignal;
64
138
  }
65
139
  interface LayoutResult<N = unknown, E = unknown, G = unknown, P = unknown> {
@@ -1209,4 +1283,4 @@ declare function placeNodesWithNetworkSimplex(input: LayeredPhaseInput, order: L
1209
1283
  declare function getLayeredLayout<N, E, G, P>(graph: Graph<N, E, G, P> | VisualGraph<N, E, G, P>, options?: LayeredLayoutOptions): VisualGraph<N, E, G, P>;
1210
1284
  declare const layeredAlgorithm: LayoutAlgorithm<LayeredLayoutOptions>;
1211
1285
  //#endregion
1212
- export { LayeringStrategy as $, routeEdgesOrthogonally as A, LayerOrder as B, breakCyclesWithModelOrderDepthFirstSearch as C, minimizeCrossingsWithModelOrder as D, minimizeCrossingsWithMedian as E, CycleBreaker as F, LayoutPadding as G, LayeredPhaseInput as H, EdgeRouter as I, NodeSize as J, NodePlacement as K, EdgeRoutes as L, routeEdgesWithSplines as M, AcyclicOrientation as N, placeNodesInLayers as O, CrossingMinimizer as P, LayeredAdvancedOptions as Q, LayerAssigner as R, breakCyclesWithModelOrderBreadthFirstSearch as S, minimizeCrossingsWithBarycenter as T, LayeredSpacing as U, LayeredLayoutOptions as V, LayeredStrategies as W, CycleBreakingStrategy as X, CrossingMinimizationStrategy as Y, EdgeRoutingStyle as Z, breakCyclesByStronglyConnectedNodeType as _, LayoutResult as _t, placeNodesWithBrandesKoepf as a, ElkLayeredOptionName as at, breakCyclesInteractively as b, assignLayersWithNetworkSimplex as c, AnyGraph as ct, assignLayersByLongestPath as d, LayoutDiagnostic as dt, NodePlacementStrategy as et, assignLayersByLongestPathToSink as f, LayoutDirection as ft, breakCyclesByStronglyConnectedConnectivity as g, LayoutRequest as gt, breakCyclesByModelOrder as h, LayoutPhaseMetrics as ht, placeNodesWithLinearSegments as i, ElkLayeredOptionId as it, routeEdgesWithPolylines as j, placeNodesInteractively as k, assignLayersByBreadthFirstModelOrder as l, LayoutAlgorithm as lt, assignLayersWithCoffmanGraham as m, LayoutMetrics as mt, layeredAlgorithm as n, toElkLayeredOptions as nt, assignLayersWithStretchWidth as o, ElkLayeredOptionValueByName as ot, assignLayersInteractively as p, LayoutExecutionContext as pt, NodePlacer as q, placeNodesWithNetworkSimplex as r, elkLayeredEnumValues as rt, assignLayersWithMinWidth as s, elkLayeredOptionDefinitions as st, getLayeredLayout as t, fromElkLayeredOptionId as tt, assignLayersByDepthFirstModelOrder as u, LayoutCapabilities as ut, breakCyclesGreedily as v, LayoutScope as vt, minimizeCrossingsInteractively as w, breakCyclesWithDepthFirstSearch as x, breakCyclesGreedilyByModelOrder as y, LayerAssignment as z };
1286
+ export { LayeringStrategy as $, routeEdgesOrthogonally as A, LayerOrder as B, breakCyclesWithModelOrderDepthFirstSearch as C, GeometryReference as Ct, minimizeCrossingsWithModelOrder as D, WaypointConstraint as Dt, minimizeCrossingsWithMedian as E, PinConstraint as Et, CycleBreaker as F, LayoutPadding as G, LayeredPhaseInput as H, EdgeRouter as I, NodeSize as J, NodePlacement as K, EdgeRoutes as L, routeEdgesWithSplines as M, AcyclicOrientation as N, placeNodesInLayers as O, c as Ot, CrossingMinimizer as P, LayeredAdvancedOptions as Q, LayerAssigner as R, breakCyclesWithModelOrderBreadthFirstSearch as S, GeometryAttribute as St, minimizeCrossingsWithBarycenter as T, LinearConstraint as Tt, LayeredSpacing as U, LayeredLayoutOptions as V, LayeredStrategies as W, CycleBreakingStrategy as X, CrossingMinimizationStrategy as Y, EdgeRoutingStyle as Z, breakCyclesByStronglyConnectedNodeType as _, LayoutResult as _t, placeNodesWithBrandesKoepf as a, ElkLayeredOptionName as at, breakCyclesInteractively as b, ConstraintStrength as bt, assignLayersWithNetworkSimplex as c, AnyGraph as ct, assignLayersByLongestPath as d, LayoutDiagnostic as dt, NodePlacementStrategy as et, assignLayersByLongestPathToSink as f, LayoutDirection as ft, breakCyclesByStronglyConnectedConnectivity as g, LayoutRequest as gt, breakCyclesByModelOrder as h, LayoutPhaseMetrics as ht, placeNodesWithLinearSegments as i, ElkLayeredOptionId as it, routeEdgesWithPolylines as j, placeNodesInteractively as k, assignLayersByBreadthFirstModelOrder as l, LayoutAlgorithm as lt, assignLayersWithCoffmanGraham as m, LayoutMetrics as mt, layeredAlgorithm as n, toElkLayeredOptions as nt, assignLayersWithStretchWidth as o, ElkLayeredOptionValueByName as ot, assignLayersInteractively as p, LayoutExecutionContext as pt, NodePlacer as q, placeNodesWithNetworkSimplex as r, elkLayeredEnumValues as rt, assignLayersWithMinWidth as s, elkLayeredOptionDefinitions as st, getLayeredLayout as t, fromElkLayeredOptionId as tt, assignLayersByDepthFirstModelOrder as u, LayoutCapabilities as ut, breakCyclesGreedily as v, LayoutScope as vt, minimizeCrossingsInteractively as w, LayoutConstraint as wt, breakCyclesWithDepthFirstSearch as x, DistributeConstraint as xt, breakCyclesGreedilyByModelOrder as y, AlignConstraint as yt, LayerAssignment as z };