/** * Flowchart Wrapper Class * * A unified API for building, mutating, and querying flowchart diagrams. * Provides a fluent interface that wraps the FlowchartAST. * * @example Creating a new flowchart * ```typescript * const diagram = Flowchart.create() * .addNode('A', 'Start') * .addNode('B', 'End') * .addLink('A', 'B'); * * console.log(diagram.render()); * ``` * * @example Parsing and modifying * ```typescript * const diagram = Flowchart.parse(`flowchart LR * A --> B --> C`); * * diagram.removeNode('B', { reconnect: true }); * // Now: A --> C * ``` */ import { DiagramWrapper } from './diagram-wrapper.js'; import type { AddLinkOptions, AddNodeOptions, FindNodesQuery, LinkInfo, RemoveNodeOptions } from './flowchart-types.js'; import type { FlowchartAST, FlowchartDirection, FlowchartLink, FlowchartLinkStroke, FlowchartLinkType, FlowchartNode, FlowchartNodeShape, FlowchartSubgraph } from './types/flowchart.js'; import type { RenderOptions } from './types/render-options.js'; export type { AddLinkOptions, AddNodeOptions, FindNodesQuery, LinkInfo, RemoveNodeOptions }; import { extractChain, getAncestors, getChain, getPath, getReachable, insertBetween, rebaseNodes, removeAndReconnect, reverseChain, spliceChain, yankChain } from './flowchart-graph-ops.js'; /** * A fluent wrapper for FlowchartAST that supports building, mutating, and querying. */ export declare class Flowchart extends DiagramWrapper { private constructor(); /** * Create a new empty flowchart * @param direction - Layout direction (default: 'TD') */ static create(direction?: FlowchartDirection): Flowchart; /** * Create a Flowchart wrapper from an existing AST * @param ast - The AST to wrap */ static from(ast: FlowchartAST): Flowchart; /** * Parse Mermaid syntax and create a Flowchart wrapper * @param text - Mermaid flowchart syntax */ static parse(text: string): Flowchart; /** * Render to Mermaid syntax * @param options - Render options */ render(options?: RenderOptions): string; /** * Create a deep clone of this flowchart */ clone(): Flowchart; /** * Get the flowchart direction */ get direction(): FlowchartDirection; /** * Set the flowchart direction */ set direction(dir: FlowchartDirection); /** * Get all node IDs */ get nodeIds(): string[]; /** * Get all nodes as an array */ get nodes(): FlowchartNode[]; /** * Get all links */ get links(): FlowchartLink[]; /** * Get all subgraphs */ get subgraphs(): FlowchartSubgraph[]; /** * Get the number of nodes */ get nodeCount(): number; /** * Get the number of links */ get linkCount(): number; /** * Check if a node exists * @param id - Node ID */ hasNode(id: string): boolean; /** * Get a node by ID * @param id - Node ID * @returns The node or undefined if not found */ getNode(id: string): FlowchartNode | undefined; /** * Add a node to the flowchart * @param id - Node ID * @param text - Node text/label (optional, defaults to ID) * @param options - Additional options * @returns this (for chaining) */ addNode(id: string, text?: string, options?: AddNodeOptions): this; /** * Remove a node from the flowchart * @param id - Node ID * @param options - Removal options * @returns this (for chaining) */ removeNode(id: string, options?: RemoveNodeOptions): this; /** * Set the text of a node * @param id - Node ID * @param text - New text * @returns this (for chaining) */ setNodeText(id: string, text: string): this; /** * Set the shape of a node * @param id - Node ID * @param shape - New shape * @returns this (for chaining) */ setNodeShape(id: string, shape: FlowchartNodeShape): this; /** * Add a class to a node * @param id - Node ID * @param className - Class name to add * @returns this (for chaining) */ addClass(id: string, className: string): this; /** * Remove a class from a node * @param id - Node ID * @param className - Class name to remove * @returns this (for chaining) */ removeClass(id: string, className: string): this; /** * Get classes assigned to a node * @param id - Node ID * @returns Array of class names (empty if none) */ getClasses(id: string): string[]; /** * Find nodes matching a query * @param query - Query options * @returns Array of matching node IDs */ findNodes(query: FindNodesQuery): string[]; /** * Add a link between two nodes * @param source - Source node ID * @param target - Target node ID * @param options - Link options * @returns this (for chaining) */ addLink(source: string, target: string, options?: AddLinkOptions): this; /** * Remove a link by index * @param index - Link index * @returns this (for chaining) */ removeLink(index: number): this; /** * Remove all links between two nodes * @param source - Source node ID * @param target - Target node ID * @returns this (for chaining) */ removeLinksBetween(source: string, target: string): this; /** * Get a link by index * @param index - Link index * @returns The link or undefined */ getLink(index: number): FlowchartLink | undefined; /** * Flip the direction of a link * @param index - Link index * @returns this (for chaining) */ flipLink(index: number): this; /** * Set the type of a link * @param index - Link index * @param type - New arrow type * @returns this (for chaining) */ setLinkType(index: number, type: FlowchartLinkType): this; /** * Set the stroke style of a link * @param index - Link index * @param stroke - New stroke style * @returns this (for chaining) */ setLinkStroke(index: number, stroke: FlowchartLinkStroke): this; /** * Set the text of a link * @param index - Link index * @param text - New text (or undefined to remove) * @returns this (for chaining) */ setLinkText(index: number, text: string | undefined): this; /** * Get all links from a node (outgoing) * @param nodeId - Node ID * @returns Array of link info with indices */ getLinksFrom(nodeId: string): LinkInfo[]; /** * Get all links to a node (incoming) * @param nodeId - Node ID * @returns Array of link info with indices */ getLinksTo(nodeId: string): LinkInfo[]; /** * Add links from multiple sources to one target * @param sources - Array of source node IDs * @param target - Target node ID * @param options - Link options * @returns this (for chaining) */ addLinksFromMany(sources: string[], target: string, options?: AddLinkOptions): this; /** * Add links from one source to multiple targets * @param source - Source node ID * @param targets - Array of target node IDs * @param options - Link options * @returns this (for chaining) */ addLinksToMany(source: string, targets: string[], options?: AddLinkOptions): this; /** * Create a new subgraph * @param id - Subgraph ID * @param nodeIds - Node IDs to include * @param title - Optional title (defaults to ID) * @returns this (for chaining) */ createSubgraph(id: string, nodeIds: string[], title?: string): this; /** * Dissolve a subgraph (remove it but keep its nodes) * @param id - Subgraph ID * @returns this (for chaining) */ dissolveSubgraph(id: string): this; /** * Move nodes to a subgraph * @param nodeIds - Node IDs to move * @param subgraphId - Target subgraph ID * @returns this (for chaining) */ moveToSubgraph(nodeIds: string[], subgraphId: string): this; /** * Extract nodes from their subgraph to the root level * @param nodeIds - Node IDs to extract * @returns this (for chaining) */ extractFromSubgraph(nodeIds: string[]): this; /** * Merge one subgraph into another * @param sourceId - Subgraph to merge from (will be dissolved) * @param targetId - Subgraph to merge into * @returns this (for chaining) */ mergeSubgraphs(sourceId: string, targetId: string): this; /** * Get a subgraph by ID * @param id - Subgraph ID * @returns The subgraph or undefined */ getSubgraph(id: string): FlowchartSubgraph | undefined; /** Insert a node between two connected nodes */ insertBetween: typeof insertBetween; /** Remove a node and reconnect its neighbors */ removeAndReconnect: typeof removeAndReconnect; /** Get all nodes reachable from a starting node */ getReachable: typeof getReachable; /** Get all nodes that can reach a target node */ getAncestors: typeof getAncestors; /** Get the shortest path between two nodes */ getPath: typeof getPath; /** Get a linear chain of nodes between two points */ getChain: typeof getChain; /** Remove a chain of nodes and reconnect around them */ yankChain: typeof yankChain; /** Splice a chain of existing nodes between two points */ spliceChain: typeof spliceChain; /** Reverse the direction of all links in a chain */ reverseChain: typeof reverseChain; /** Extract a subchain from the graph as a new Flowchart */ extractChain: typeof extractChain; /** Move a set of nodes to be children of a new parent */ rebaseNodes: typeof rebaseNodes; } //# sourceMappingURL=flowchart.d.ts.map