API
Each section is one entry point of the package. The options reference has the fields of each options object.
The core: the model, the engine, the strategies, the routers and the builder. It imports nothing.
Layout
Section titled “Layout”function layout(input: LayoutInput, options?: LayoutOptions): Layout;function createEngine(config?: EngineConfig): Engine;
interface Engine { layout(input: LayoutInput, options?: LayoutOptions): Layout; extend(config: EngineConfig): Engine; readonly strategies: ReadonlyMap<string, AnyStrategy>; readonly routers: ReadonlyMap<string, Router>; readonly limits: Limits;}
class IrekoError extends Error { readonly issues: readonly Issue[]; // the findings with the severity "error"}layout uses a shared engine with the built-in strategies and routers. It throws only in the strict mode, or for an input that is not an object with a root.
The option linkedShape of EngineConfig sets the code that gives the shape of a linked node. The default is the code of ireko. This option and its types LinkedShape and ShapePart have the tag @beta, so a release can change them.
The builder
Section titled “The builder”const grid: Builder<GridOptions>;const radial: Builder<RadialOptions>;const tree: Builder<TreeOptions>;const layers: Builder<LayersOptions>;function builder<O>(type: string): Builder<O>; // a builder for a strategy that you registerfunction node(id: string, options?: Omit<ContainerOptions, "gap" | "padding" | "header">): NodeSpec;
type Child = NodeSpec | string; // a node, or the identifier of a leaftype BuildOptions<O> = Partial<O> & ContainerOptions;interface ContainerOptions { label?; size?; fit?; data?; gap?; padding?; header? } // each container has these options, for each strategy
interface Builder<O> { (id: string, ...children: readonly Child[]): NodeSpec; // a linked node (id: string, options: BuildOptions<O>, ...children: readonly Child[]): NodeSpec; nested: { // a container (id: string, ...children: readonly Child[]): NodeSpec; (id: string, options: BuildOptions<O>, ...children: readonly Child[]): NodeSpec; };}A string child is a leaf with that identifier. The options object of a builder has the options of the strategy, and label, size, fit, data, gap, padding and header.
Strategies and routers
Section titled “Strategies and routers”function defineStrategy<O>(strategy: Strategy<O>): Strategy<O>;function defineRouter(router: Router): Router;const gridStrategy: Strategy<GridOptions>;const radialStrategy: Strategy<RadialOptions>;const treeStrategy: Strategy<TreeOptions>;const layersStrategy: Strategy<LayersOptions>;const BUILTIN_STRATEGY_NAMES: readonly string[]; // grid, radial, tree, layersconst straight: Router;const orthogonal: Router;const avoid: Router; // around the other boxesconst builtinStrategies: readonly AnyStrategy[];const builtinRouters: readonly Router[];const defaultLimits: Limits; // { maxNodes: 100000, maxDepth: 10000, maxChildren: 10000 }
function borderPoint(box: Rect, toward: Point): Point; // where the line to a point leaves a boxfunction defaultsOf<O>(schema: OptionSchema<O>): O;Write a strategy has the contract of Strategy, and edges has the contracts of Router and GraphRouter. These types are the inputs and the outputs of those contracts.
interface ArrangeInput<O> { id; mode: Mode; self: Size; children: readonly MeasuredChild[]; options: O; gap; depth; edges?: readonly ChildEdge[] } // the input of Strategy.arrangeinterface Arrangement { direction?: Direction; flow?: Direction; offsets: readonly Point[]; content?: Rect } // the output of Strategy.arrangeinterface AuditInput<O> { node: PlacedNode; children: readonly PlacedNode[]; options: O; gap } // the input of Strategy.audit, with absolute rectanglesinterface RouteInput { id; kind: "tree" | "extra"; source: Rect; target: Rect; direction?: Direction; obstacles?: readonly Rect[] } // the input of Router.route, with absolute rectanglesinterface GraphRouter { name?; route(input: GraphRouterInput): GraphRouterResult } // the option graphRouter: it routes all edges togetherinterface GraphRouterInput { nodes: readonly GraphNode[]; edges: readonly GraphEdge[] } // all boxes and all edges of one layoutinterface GraphNode { id; box: GraphBox; parent? } // parent: the nested container of the boxinterface GraphBox { x; y; w; h } // an absolute box: w is the width, and h is the heightinterface GraphEdge { id; source: { node }; target: { node } }interface GraphRouterResult { routes: readonly GraphRoute[] }interface GraphRoute { edge; points: readonly Point[]; through?: readonly string[] } // through: the boxes that the route goes throughinterface MeasuredChild { id; box: Size; extent: Rect; mode: Mode; shape?: Shape } // a child after the measure passinterface ChildEdge { from; to } // an edge between the subtrees of two children, as their indexesinterface Shape { rows: readonly Band[]; columns: readonly Band[] } // the shape of a subtree, relative to the top-left corner of its root boxinterface Band { from; to; min; max } // one band of a shapetype Direction = "down" | "up" | "left" | "right"; // the direction from a node to its children
type OptionSpec = NumberOption | BooleanOption | EnumOption; // the schema of one optioninterface NumberOption { type: "number"; default: number; min?; max?; integer?; description }interface BooleanOption { type: "boolean"; default: boolean; description }interface EnumOption<V extends string = string> { type: "enum"; values: readonly V[]; default: V; description }type OptionSpecFor<T> = [T] extends [number] ? NumberOption : [T] extends [boolean] ? BooleanOption : [T] extends [string] ? EnumOption<T> : never;Between from and to on one axis, a subtree is between min and max on the other axis. In the rows of a shape, from and to are y values. In the columns, they are x values. A tidy strategy uses the shape to put a subtree closer to its neighbors than the extent permits.
The model
Section titled “The model”interface LayoutInput { root: NodeSpec; edges?: EdgeSpec[] }interface NodeSpec { id; label?; layout?; mode?; fit?; size?; children?; data? }interface EdgeSpec { source; target; id?; label?; data? }
interface Layout { nodes: PlacedNode[]; // in paint order: each container before the boxes inside it edges: PlacedEdge[]; bounds: Rect; issues: Issue[];}interface PlacedNode extends Rect { id; label; parent?; container?; depth; mode; layout; scale; clip; childCount; data?;}interface PlacedEdge { id; source; target; kind: "tree" | "extra"; points: Point[]; label?; data? }
type LayoutRef = string | LayoutWithOptions; // the name of a strategy, or the name with optionsinterface LayoutWithOptions { type: string; [option: string]: unknown }type Mode = "nested" | "linked"; // the children are inside the box of the node, or around ittype Fit = "grow" | "scale" | "clip";type TreeEdges = "linked" | "all" | "none"; // the tree edges that the engine addstype Severity = "error" | "warning"; // an error changes the output, and a warning does nottype IssueCode = "DUPLICATE_ID" | "EMPTY_ID" | "UNKNOWN_LAYOUT" | "UNKNOWN_ROUTER" | "INVALID_OPTION" | "INVALID_SIZE" | "UNKNOWN_EDGE_END" | "SELF_LOOP" | "LIMIT_NODES" | "LIMIT_DEPTH" | "LIMIT_CHILDREN" | "STRATEGY_FAILED" | "ROUTER_FAILED" | "EDGE_THROUGH_BOX" | "NON_FINITE" | "OVERLAP" | "ESCAPE" | (string & {});interface TraceEvent { phase: "normalize" | "measure" | "place" | "route" | "audit"; data: unknown } // the output of one phase of the pipelineAll types are plain data. JSON holds each value with no loss.
With the fit grow, the container grows to fit its content. With scale, the content becomes smaller to fit the container. With clip, the content keeps its size and the renderer cuts it at the edge of the container.
Label sizes
Section titled “Label sizes”function fitText(options?: FitTextOptions): (node: NodeSpec) => Size;interface FitTextOptions { fontSize?; padding?: { x; y }; minWidth?; minHeight?; widthOf? }function estimateWidth(text: string, fontSize: number): number; // a sans-serif font, with no font engineGive fitText() to the measure option. widthOfCanvas(fontFamily) from ireko/render gives exact widths in a browser.
Geometry
Section titled “Geometry”Point, Size and Rect, and small functions on them: centerOf, union, unionAll, translate, inflate, overlaps, contains, rectAt.
ireko/shapes
Section titled “ireko/shapes”The layout of ireko, with the shapes of linked nodes from a module of the Vex compiler. It gives the same layout, to the bit. This entry shows the module of Vex. ireko is the choice for production use.
function layout(input: LayoutInput, options?: LayoutOptions): Layout;The bundle of this entry is 20.5 kB with gzip. The bundle of ireko is 18.6 kB. These sizes come from the build of this page.
This table gives the time of a layout with this entry, divided by the time with ireko. A value above 1 is slower. The A/A column is a second copy of ireko, and it shows the noise of the measure.
| Input | A/A | ireko/shapes |
|---|---|---|
| Full tree, 111 nodes | 1.013 | 1.098 |
| Full tree, 1111 nodes | 1.001 | 1.026 |
| Full tree, 11111 nodes | 1.006 | 1.073 |
| Examples | 0.995 | 1.026 |
| Random trees | 0.999 | 0.990 |
This table is a fixed study of ireko 0.1.4, from the commit 1d575a6 of 2026-11-04. It tells nothing about a newer release. The entry is slower on full trees and on the examples, and 1 % faster on random trees. The values are medians of 9 processes with 31 rounds each, on Node 24 in CI. Both layouts run in one process, so one call in the measure pass receives two functions. A program that imports one entry does not have this condition, and this measure does not give its time.
ireko/strategies/force
Section titled “ireko/strategies/force”The opt-in strategy force. Register it with createEngine({ strategies: [forceStrategy] }).
const forceStrategy: Strategy<ForceOptions>;const force: Builder<ForceOptions>;function relaxForces(nodes: RelaxNode[], edges: RelaxEdge[], options: Partial<RelaxOptions> & { bound }): Map<string, Point>;const RELAX_DEFAULTS; // { iterations: 150, springLength: 340, repulsion: 90000, margin: 12, inset: 4, minDistance: 20, centering: 0.005, maxStep: 30, separationPasses: 300, theta: 0 }const MAX_SPRING_STRENGTH: number; // 0.5: a larger strength throws a RangeErrorconst MAX_THETA: number; // 1: a larger theta throws a RangeErrorireko/text
Section titled “ireko/text”function parse(text: string, options?: ParseOptions): ParseResult;function print(input: LayoutInput, options?: PrintOptions): string;interface ParseOptions { strategies?: readonly string[] }interface PrintOptions { strategies?: readonly string[]; width?: number }const KEYWORDS: ReadonlySet<string>; // nested, linked, grow, scale, clip
type ParseResult = { ok: true; input: LayoutInput } | { ok: false; error: SyntaxIssue };interface SyntaxIssue { message; offset; length; line; column }Refer to the text language.
ireko/svg
Section titled “ireko/svg”function toSVG(layout: Layout, options?: SvgOptions): string;function mountSvg(container: HTMLElement, options?: RendererOptions): Renderer;function svgSurface(host: HTMLElement, theme: Theme): Surface;ireko/dom
Section titled “ireko/dom”function mountDom(container: HTMLElement, options?: RendererOptions): Renderer;function domSurface(host: HTMLElement, theme: Theme): Surface;ireko/canvas
Section titled “ireko/canvas”function mountCanvas(container: HTMLElement, options?: RendererOptions): Renderer;function canvasSurface(host: HTMLElement, theme: Theme): Surface;function drawFrame(ctx: Context2D, frame: Frame, view: View, theme: Theme, screen: Screen): void;drawFrame draws on any object with the methods of Context2D, for example a canvas on a server.
ireko/render
Section titled “ireko/render”The parts that the live renderers share.
interface Renderer { readonly element: HTMLElement; readonly viewport: Viewport; update(layout: Layout): void; fit(padding?: number): void; select(ids: Iterable<string>): void; pick(point: Point): string | undefined; destroy(): void;}
function mount(container: HTMLElement, create: (host, theme) => Surface, options?: RendererOptions): Renderer;
function createViewport(options?: ViewportOptions): Viewport;interface ViewportOptions { minZoom?: number; maxZoom?: number }interface Viewport { get(): View; // { x, y, k } set(view: Partial<View>): void; zoom(factor: number, at: Point): void; pan(dx: number, dy: number): void; fit(bounds: Rect, width: number, height: number, padding?: number): void; subscribe(listener: (view: View) => void): () => void; toLayout(screen: Point): Point; // a point of the element in the coordinates of the layout attach(element: HTMLElement): () => void; // pan and zoom with the pointer and the wheel}
const lightTheme: Theme;const darkTheme: Theme;function themeOf(partial: Partial<Theme> | undefined, base?: Theme): Theme;
function frameOf(layout: Layout): Frame;function interpolate(from: Frame, to: Layout, t: number): Frame;function easeInOut(t: number): number;function labelAt(points: Point[]): Point; // the middle of a route, for its labelfunction widthOfCanvas(fontFamily: string): (text: string, fontSize: number) => number;
interface FrameNode extends PlacedNode { opacity: number } // a box of one frame of an animationinterface FrameEdge extends PlacedEdge { opacity: number } // an edge of one frame of an animationfunction morph(a: readonly Point[], b: readonly Point[], t: number): Point[]; // moves one polyline to anotherfunction resample(points: readonly Point[], count: number): Point[]; // count points, at equal distances along a polylinefunction pickIn(frame: Frame, p: Point): string | undefined; // the identifier of the top box at a pointfunction isContainer(n: { mode: string; childCount: number }): boolean; // a node in the nested mode with childrenfunction paintOrder(nodes: readonly FrameNode[]): { containers: FrameNode[]; leaves: FrameNode[] }; // the two layers of the paint orderfunction clipRoots(nodes: readonly FrameNode[]): Map<string, FrameNode>; // for each node, the nearest container with the fit clip that holds itfunction haloOf(theme: Theme): string; // the color of the halo of a labelconst LABEL_SCALE: number; // 0.85: the size of the text of an edge label, relative to the text of a nodeireko/svg also exports isContainer.
ireko/react
Section titled “ireko/react”function useLayout(input: LayoutInput, options?: LayoutOptions, engine?: Engine): Layout;function LayoutSvg(props: LayoutSvgProps): ReactElement;function LayoutView(props: LayoutViewProps): ReactElement;interface LayoutSvgProps { layout; theme?; padding?; title?; className?; style? }interface LayoutViewProps { layout; renderer?: RendererKind; theme?; viewport?; duration?; interactive?; selected?; onPick?; className?; style? }type RendererKind = "svg" | "dom" | "canvas"; // the live renderers of LayoutViewuseLayout makes the layout again only when input, options or engine change, so keep them in a memo or a state. LayoutSvg has no state and no effects. LayoutView mounts a live renderer in an effect.
ireko/xyflow
Section titled “ireko/xyflow”function layoutFlow<N extends Node, E extends Edge>(nodes: readonly N[], edges: readonly E[], options?: LayoutFlowOptions): { nodes: N[]; edges: E[]; layout: Layout };function toXYFlow(layout: Layout, options?: ToXYFlowOptions): { nodes: IrekoNode[]; edges: IrekoEdge[] };function PolylineEdge(props: EdgeProps): ReactElement;function GroupNode(props: NodeProps): ReactElement;const edgeTypes: { ireko: typeof PolylineEdge };const nodeTypes: { group: typeof GroupNode };function pathOf(points: readonly Point[]): string; // the SVG path of a polyline
interface ToXYFlowOptions { nodeType?: (node: PlacedNode) => string | undefined; edgeType?: string }interface FlowNodeSpec { layout?: LayoutRef; mode?: Mode; fit?: Fit } // the layout settings of one node of a flowinterface IrekoNodeData extends Record<string, unknown> { label: string; ireko: PlacedNode } // the data of a node that toXYFlow makesinterface IrekoEdgeData extends Record<string, unknown> { points: readonly Point[] } // the data of an edge that toXYFlow or layoutFlow makesRefer to the React Flow guide.
ireko/examples
Section titled “ireko/examples”const examples: readonly Example[];interface Example { name; title; description; input: LayoutInput; options?: LayoutOptions }The gallery shows each example.