Skip to content

Quick start

Terminal window
npm install ireko

ireko has no runtime dependencies. The core is approximately 13 KB after minification and gzip. React and React Flow are optional peer dependencies: install them only for ireko/react and ireko/xyflow.

A layout starts from a tree. Use the builder, the text language or plain objects. The three forms give the same input.

import { grid, layout, radial } from "ireko";
const root = grid.nested("system",
radial.nested("web", "home", "cart", "search"),
grid("api", "auth", "orders"),
);
const result = layout({ root });
system nested {
  web radial nested { home cart search }
  api { auth orders }
}
The layout of the three examples above.systemwebhomecartsearchapiauthorders
The layout of the three examples above.Open in the playground →

The result has four parts:

PartContents
nodesOne box for each node, with an absolute position and size. A container comes before the boxes inside it.
edgesOne route for each edge: a list of points from the border of the source to the border of the target.
boundsThe smallest rectangle that holds all boxes and edges.
issuesThe findings of the audit. For a correct input, the list is empty.
import { toSVG } from "ireko/svg";
document.querySelector("#diagram")!.innerHTML = toSVG(result);

toSVG gives a standalone SVG document. It operates in the browser, in Node.js, in a worker and at build time.

The engine examines its own output. It finds overlaps, boxes outside their container and bad options, and puts them in issues. In tests and in CI, use the strict mode: the engine then throws an IrekoError for each error.

import { IrekoError, layout } from "ireko";
try {
layout(input, { strict: true });
} catch (error) {
if (error instanceof IrekoError) console.error(error.issues);
}

The findings reference explains each code.

  • A current browser, or Node.js 22.12 or later.
  • ESM. The package has no CommonJS build.
  • The package includes its types. The core does not need the types of the DOM. Only the renderers need them.