ireko

中文文档
0.1.3发布于 2026/11/04MITTypeScriptES Module零依赖构建来源已验证

Composable graph and tree layout for TypeScript. Select a layout for each container, and get boxes and routed edges for any renderer.

原始使用文档
文档目录11 节
  1. Install
  2. Use it
  3. Two ideas
  4. A text language
  5. Entry points
  6. React
  7. React Flow sub-flows
  8. When to use another library
  9. Requirements
  10. Links
  11. License

ireko

Composable graph and tree layout for TypeScript. Select a layout for each container, and get boxes and routed edges for any renderer.

A system architecture laid out by ireko: nested containers with services, and extra edges between them

Guide · Playground · Gallery · API · React Flow

ireko (入れ子) is the Japanese word for a set of boxes that fit inside each other. The library lays out trees of nested boxes: a grid of rings of trees, an architecture diagram, a tidy organization chart or React Flow sub-flows. It has no runtime dependencies. The core is approximately 13 kB after minification and gzip.

Install

npm install ireko

Use it

import { grid, layout, radial } from "ireko";
import { toSVG } from "ireko/svg";

const root = grid.nested("system",
  radial.nested("web", "home", "cart", "search"),
  grid("api", "auth", "orders"),
);
const result = layout({ root, edges: [{ source: "cart", target: "orders", label: "checkout" }] });

result.nodes;  // a box for each node: { id, x, y, width, height, container, depth, ... }
result.edges;  // a route for each edge: { source, target, kind, points, label }
// The router avoid draws edges around the other boxes: layout(input, { router: "avoid" })
result.issues; // the findings of the audit: [] for this input
document.body.innerHTML = toSVG(result);

Two ideas

Each node with children selects two things:

  • A strategy: how to arrange its children. grid puts them in rows and columns. radial puts them on a ring. tree makes a tidy tree, for example an organization chart. layers makes a flowchart from the edges between the children.
  • A mode: where its children go. In the linked mode, they are around the node, and edges connect them. In the nested mode, they are inside the box of the node.

You can add your own strategy to the engine. The opt-in strategy force from ireko/strategies/force arranges a network with no hierarchy. Register it with createEngine.

The two choices apply to one node only, so each container has its own layout. The engine measures each subtree before it places it, so no two subtrees overlap. Each layout examines itself, and puts each problem in issues.

A text language

The same input in a few lines. The playground uses it.

import { layout } from "ireko";
import { toSVG } from "ireko/svg";
import { parse } from "ireko/text";

const parsed = parse(`
  system nested {
    web radial nested { home cart search }
    api { auth orders }
  }
  cart -> orders "checkout"
`);
if (parsed.ok) document.body.innerHTML = toSVG(layout(parsed.input));

Entry points

ImportContents
irekoThe engine, the strategies, the routers, the audit and the builder. It imports nothing.
ireko/textparse and print for the text language
ireko/svgtoSVG (a string, also on a server) and mountSvg (a live view)
ireko/dommountDom: a live view with one element for each box
ireko/canvasmountCanvas: a live view on a canvas, for large layouts
ireko/renderThe themes, the viewport and the animation of the live views
ireko/reactuseLayout, LayoutSvg and LayoutView
ireko/xyflowlayoutFlow, toXYFlow, PolylineEdge and GroupNode for React Flow 12
ireko/examplesThe inputs of the gallery

A live view has pan, zoom, selection and an animation from one layout to the next.

React

import { LayoutView, useLayout } from "ireko/react";

function Diagram({ input }) {
  const result = useLayout(input); // keep input in a memo or a state
  return <LayoutView layout={result} style={{ height: 400 }} onPick={(id) => console.log(id)} />;
}

LayoutSvg draws a static SVG with no effects, so it works with server rendering.

React Flow sub-flows

layoutFlow gives each group (a node with parentId children) a size that holds its children, and gives each node a position. Each group can have its own strategy.

import { ReactFlow } from "@xyflow/react";
import { edgeTypes, layoutFlow, nodeTypes } from "ireko/xyflow";

const { nodes, edges } = layoutFlow(myNodes, myEdges, {
  nodeSpec: (node) => (node.id === "server" ? { layout: "radial" } : undefined),
});

<ReactFlow nodes={nodes} edges={edges} nodeTypes={nodeTypes} edgeTypes={edgeTypes} fitView />;

The React Flow guide has a live demo.

When to use another library

This library lays out trees of containers. For a large directed graph with layers, for example a flow chart with long chains, use dagre or ELK. This library has no crossing reduction, no ports and no routing around obstacles. The comparison has the details.

Requirements

  • A current browser, or Node.js 22.12 or later
  • ESM only
  • React 18 or later for ireko/react, and @xyflow/react 12 for ireko/xyflow. Both are optional peer dependencies.

License

MIT

版本与发布记录

ireko 共发布 5 个版本,首次发布于 2026/10/17;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.3latest2026/11/041 天前
0.1.22026/10/2511 天前
0.1.12026/10/2016 天前
0.1.02026/10/1719 天前
0.0.0-stage2026/10/1719 天前

关于 ireko 的常见问题

ireko 是什么?

Composable graph and tree layout for TypeScript. Select a layout for each container, and get boxes and routed edges for any renderer.

如何安装 ireko?

在项目目录运行 npm install ireko,或使用 pnpm add / yarn add / bun add。

ireko 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

ireko 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

ireko 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

ireko 可以商用吗?

ireko 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

ireko 还在维护吗?

最新版本 0.1.3 发布于 2026/11/04(1 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/10/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。