# `<llumi-mermaid>`

Renders a [Mermaid](https://mermaid.js.org) diagram from a definition string with
[pele](https://pele.run) (every Mermaid 12.1 diagram type; each type's code loads on
first use), with trackpad/mouse pan + zoom and a fit-to-view button. React: `Mermaid` in
`mermaid.react.tsx`.

## Usage

```html
<llumi-mermaid>
  graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Done]
    B -->|No| D[Retry]
</llumi-mermaid>
```

The diagram source is the element's **light-DOM text content** — whitespace is
automatically dedented. Re-renders whenever the text content changes.

## Theming

No properties. Colors and fonts are pele's CSS variables, set on `:host` from the
llumi tokens, so the diagram follows the llumi light/dark theme. Override any of them
on the element ([all variables](https://pele.run/theming)):

```css
llumi-mermaid {
  --pele-accent: oklch(55% 0.2 260);
  --pele-line: var(--llumi-color-fg);
}
```

| Variable | Default |
|----------|---------|
| `--pele-bg` | `--llumi-color-bg` |
| `--pele-fg` | `--llumi-color-fg` |
| `--pele-muted`, `--pele-line` | `--llumi-color-muted` |
| `--pele-surface` | `--llumi-color-surface` |
| `--pele-surface-alt` | `--llumi-color-bg` |
| `--pele-border` | `--llumi-color-border` |
| `--pele-accent` | `--llumi-color-accent` |
| `--pele-radius` | `--llumi-radius-sm` |
| `--pele-font`, `--pele-font-mono` | `--llumi-font-sans`, `--llumi-font-mono` |

Text is measured with `--pele-font` / `--pele-font-mono` at render time: change them
before the diagram renders, or re-set its text to re-render.

## Events

| Event | Detail | When |
|-------|--------|------|
| `llumi-mermaid-render` | — | A diagram rendered successfully. |
| `llumi-mermaid-error` | `{ error: string }` | The definition failed to parse (pele `PeleError` message); the error box is shown instead of the diagram. |

Both bubble and cross shadow boundaries (`composed: true`).

## Interaction

- **Pan:** two-finger scroll (trackpad) / drag.
- **Zoom:** pinch (trackpad) or ctrl+wheel; scale clamped to `[0.25, 4]`.
- **Fit:** the top-right button resets the view.

## Dependencies

`lit`, `pele`, `d3-selection`, `d3-zoom`, `d3-transition`.

```js
import "@llumi/ui/mermaid.mjs"; // npm / esm.sh
```

## React

```tsx
import { Mermaid } from "./mermaid.react";

<Mermaid code={"graph TD\n  A --> B"} onError={(error) => report(error)} />
```

Props: `code` (the definition, rendered as the element's text), `onRender()`, `onError(error)`, `ref` (the `LlumiMermaid` element), `className`
and `style`.
