# IRenderer

Import it from `@grafloria/renderer`.

Renderer interface — the contract for a DIAGRAM renderer: it turns the model
plus a viewport into a visual representation (a VNode tree in SVG mode).

This is the only renderer interface. A second `IRenderer` used to live in
`core/renderer.interface.ts` describing a different layer — a VNode → DOM
*consumer* (initialize/render/clear/destroy against a container) — together
with an unused stack (SVGRendererV2, a throwing Canvas stub, HybridRenderer,
RendererFactory, RendererStrategyManager). Nothing in production implemented
it: the real VNode → DOM layer is the patcher in `vnode/patch.ts`. The stack
is deleted; the useful vocabulary it defined is kept below, as OPTIONAL
members here, so capability detection / export / hit-testing / text
measurement have a home when a renderer actually implements them.

```ts
interface IRenderer
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `mode` | `'svg' \| 'canvas'` |  | Renderer mode |
| `capabilities?` | `RendererCapabilities` |  | Optional: capability flags for runtime feature detection, so callers can ask instead of assuming (e.g. "can this renderer do foreignObject?"). |

**Members**

- `render(viewport: Rectangle, zoom: number): VNode | void` — Render diagram to visual representation
- `getPerformanceMetrics(): PerformanceMetrics` — Get performance metrics
- `dispose(): void` — Dispose renderer and clean up resources
- `hitTest?(x: number, y: number): VNode | null` — Optional: element at a coordinate (selection, hover, click routing).
- `measureText?(text: string, style: TextStyle): TextMetrics` — Optional: measure text for layout (wrapping, ellipsis, shape-fit). Implementations are expected to cache.
- `export?(format: ExportFormat, options?: ExportOptions): Promise<string>` — Optional: export the rendered diagram as an image or SVG string.

`'svg'` returns a STANDALONE, styles-inlined SVG document (no `var(--…)`, no
external references) — pure, deterministic and DOM-free, so it runs on a
server. The raster formats return a `data:` URL and need a rasterizer (see
{@link ExportOptions.rasterBackend}).

Implemented by `SVGRenderer` (see `export/`).
