import { Avoid } from "libavoid-js"; //#region src/types.d.ts /** ELK JSON graph types */ interface ElkPoint { x: number; y: number; } interface ElkEdgeSection { id: string; startPoint: ElkPoint; endPoint: ElkPoint; bendPoints?: ElkPoint[]; } interface ElkPort { id: string; x?: number; y?: number; width?: number; height?: number; properties?: Record; } interface ElkEdge { id: string; /** Simple format */ source?: string; target?: string; sourcePort?: string; targetPort?: string; /** Extended format */ sources?: string[]; targets?: string[]; /** Routing results */ sections?: ElkEdgeSection[]; sourcePoint?: ElkPoint; targetPoint?: ElkPoint; bendPoints?: ElkPoint[]; properties?: Record; } interface ElkNode { id: string; x?: number; y?: number; width?: number; height?: number; children?: ElkNode[]; ports?: ElkPort[]; edges?: ElkEdge[]; properties?: Record; padding?: { top?: number; right?: number; bottom?: number; left?: number; }; } interface ElkGraph extends ElkNode {} /** Cardinal direction for edge connection sides */ type ConnectionSide = "north" | "south" | "east" | "west"; /** Route result for a single edge */ interface RouteResult { sourcePoint: ElkPoint; targetPoint: ElkPoint; bendPoints: ElkPoint[]; sourceSide: ConnectionSide; targetSide: ConnectionSide; } /** Self-loop handling strategy */ type SelfLoopHandling = "skip" | "fallback"; /** Router configuration: penalties, distances, and nudging behavior. */ interface LibavoidRouterOptions { /** Routing style. Default: 'orthogonal' */ routingType?: "orthogonal" | "polyline"; /** Per-segment cost beyond the first. Default: 10 */ segmentPenalty?: number; /** Tight bend cost. Default: 0 */ anglePenalty?: number; /** Edge crossing cost. Default: 0 */ crossingPenalty?: number; /** Cluster boundary crossing cost. Default: 0 */ clusterCrossingPenalty?: number; /** Sharing path with immovable edge. Default: 0 */ fixedSharedPathPenalty?: number; /** Going backwards. Default: 0 */ reverseDirectionPenalty?: number; /** Port direction penalty. Default: 100 */ portDirectionPenalty?: number; /** Padding around obstacles. Default: 4 */ shapeBufferDistance?: number; /** Space between parallel segments. Default: 4 */ idealNudgingDistance?: number; /** Nudging options */ nudgeOrthogonalSegmentsConnectedToShapes?: boolean; nudgeOrthogonalTouchingColinearSegments?: boolean; performUnifyingNudgingPreprocessingStep?: boolean; nudgeSharedPathsWithCommonEndPoint?: boolean; } /** Options for one-shot routing (routeEdges / routeEdgesInPlace). */ interface LibavoidRoutingOptions extends LibavoidRouterOptions { /** Only route edges with these IDs. Others are left unchanged. */ edgeIds?: string[]; /** How to handle self-loop edges (source === target). Default: 'skip' */ selfLoopHandling?: SelfLoopHandling; } //#endregion //#region src/route-edges.d.ts /** * Initialize the libavoid WASM module. * * Called automatically by {@link routeEdges}, {@link routeEdgesInPlace}, and * `createRoutingSession` on first use. You can call it explicitly to control * initialization timing or to provide a WASM URL in browser environments. * * Subsequent calls return the same promise (the `wasmPath` from the first call wins). * A warning is logged if a subsequent call provides a different `wasmPath`. * * In browser environments, you **must** call this with a URL to the libavoid.wasm * file (e.g. served from your app's public directory) before using the routing APIs. */ declare function init(wasmPath?: string): Promise; /** * Route edges on an ELK JSON graph using libavoid. * * Returns a Map of edge ID → RouteResult. The input graph is NOT modified. * Automatically initializes the WASM module on first call if not already done * (Node.js only; in browsers, call {@link init} with a WASM URL first). * * **Coordinate system:** The returned {@link RouteResult} points use * **absolute** coordinates. If you need coordinates relative to the edge's * owner node (as in ELK JSON), use {@link routeEdgesInPlace} instead. */ declare function routeEdges(graph: ElkGraph, options?: LibavoidRoutingOptions): Promise>; /** * Route edges on an ELK JSON graph, mutating the graph in place. * * This is the backward-compatible API that writes routes directly * into the graph's edge objects. * * **Coordinate system:** Edge routes are written as coordinates **relative** * to the edge's owner node's content area (inside padding), matching the * ELK JSON convention. This differs from {@link routeEdges}, which returns * absolute coordinates. */ declare function routeEdgesInPlace(graph: ElkGraph, options?: LibavoidRoutingOptions): Promise; //#endregion //#region src/parser.d.ts interface ResolvedNode { id: string; x: number; y: number; width: number; height: number; ports: ResolvedPort[]; parentId: string | null; /** Whether this node has children (is a container/group node) */ hasChildren: boolean; padding: { top: number; right: number; bottom: number; left: number; }; } interface ResolvedPort { id: string; nodeId: string; x: number; y: number; width: number; height: number; side: "NORTH" | "SOUTH" | "EAST" | "WEST"; } //#endregion //#region src/libavoid-session.d.ts /** Extract WASM types from the Avoid interface (not directly exported by libavoid-js) */ type WasmRouter = Avoid["Router"]; type WasmShapeRef = Avoid["ShapeRef"]; type WasmConnRef = Avoid["ConnRef"]; /** * Free an Emscripten-wrapped C++ object. * The `.delete()` method exists at runtime but is not in the libavoid-js type definitions. */ interface ShapeEntry { node: ResolvedNode; shapeRef: WasmShapeRef; } interface ConnectorEntry { connRef: WasmConnRef; edge: { id: string; }; } interface LibavoidSession { avoid: Avoid; connectors: Map; edgeEndpointNodes: Set; nodes: Map; portPinClassIds: Map; router: WasmRouter; shapes: Map; } //#endregion //#region src/session.d.ts /** * A long-lived routing session that supports incremental updates. * * libavoid natively supports moving shapes and re-routing only affected connectors. * This avoids the overhead of creating/destroying the full WASM state on every frame. */ declare class RoutingSession { private session; private avoid; private destroyed; /** @internal Use createRoutingSession() instead. */ constructor(session: LibavoidSession, avoid: Avoid); /** * Move a node to a new position. The shape obstacle is updated in the router. * Call processTransaction() after all moves to re-route affected edges. * * Moving a container node also moves all descendant shapes by the same delta. */ moveNode(nodeId: string, position: { x: number; y: number; }): void; private moveShapeAndTrack; private isDescendantOf; /** * Add a new edge connector to the session. * The source and target nodes must already exist in the session. */ addEdge(edge: { id: string; source: string; target: string; sourcePort?: string; targetPort?: string; }): void; /** * Remove an edge from the session. */ removeEdge(edgeId: string): void; /** * Process pending changes and return updated routes. * Only edges affected by shape moves or additions are re-routed. * * **Coordinate system:** The returned {@link RouteResult} points use * **absolute** coordinates (matching the coordinate space used during * session creation). To convert to ELK-relative coordinates, subtract * the owner node's content area origin. */ processTransaction(): Map; /** * Destroy the session and free WASM memory. * The session cannot be used after this call. */ destroy(): void; /** * Support for the TC39 Explicit Resource Management proposal. * Allows usage with `using session = await createRoutingSession(graph)`. */ [Symbol.dispose](): void; private assertNotDestroyed; } /** * Create a long-lived routing session for incremental updates. * * Use this instead of routeEdges() when you need to update node positions * frequently (e.g., during drag operations) without re-creating the * entire router on every frame. * * @example * ```ts * const session = await createRoutingSession(graph, options); * * // On node drag: * session.moveNode("n1", { x: newX, y: newY }); * const routes = session.processTransaction(); * * // Cleanup: * session.destroy(); * ``` */ declare function createRoutingSession(graph: ElkGraph, options?: LibavoidRouterOptions): Promise; //#endregion export { type ConnectionSide, type ElkEdge, type ElkEdgeSection, type ElkGraph, type ElkNode, type ElkPoint, type ElkPort, type LibavoidRouterOptions, type LibavoidRoutingOptions, type RouteResult, type RoutingSession, type SelfLoopHandling, createRoutingSession, init, routeEdges, routeEdgesInPlace }; //# sourceMappingURL=index.d.cts.map