Diagrams
A Mermaid source, drawn by Pele
A fence tagged mermaid is the whole API. Pele renders it at
build time, so the drawing is in the HTML and the fence stays copyable.
| Pele role | The page's role |
|---|---|
--pele-bg | --card |
--pele-fg | --foreground |
--pele-muted | --muted-foreground |
--pele-line | --border-strong |
--pele-surface | --muted |
--pele-accent | --ring |
--pele-border | --border |
Every value is a var(), so the surface decides the colours.
A source Pele cannot read prints the parser's sentence with the source under it:
This diagram could not be read
No diagram type detected for the given text.
this is not a diagram
The Diagram component
A diagram is a drawing, and
the Diagram component is what draws one. You give it
a Mermaid source and it renders the diagram, themed in the library's own
colours.
The renderer is Pele — a zero-dependency Mermaid renderer
that needs no DOM. Measured in a plain Node process, with typeof document and
typeof window both undefined, a flowchart rendered to a 403×64 SVG.
import { Diagram } from "@gpuixui/components/diagram";
<Diagram
aria-label="The render path"
source={"flowchart LR\n A[Author] --> B[Component]"}
caption="How a component becomes a picture"
/>;The theme roles
The component reads the theme's colours and bakes them into the drawing as
literal values, because a raster resolves no custom property — and Pele writes
its palette twice, as the public --pele-* set and an internal --_* set.
| Pele role | The library's role |
|---|---|
--pele-bg | card |
--pele-fg | foreground |
--pele-muted | muted-foreground |
--pele-line | border-strong |
--pele-surface | muted |
--pele-surface-alt | accent |
--pele-accent | primary |
--pele-border | border |
The three roles that are not colours — --pele-radius, --pele-font and
--pele-font-mono — are given literal values, because a raster carries no
font of its own.
Interactive diagrams
The same Pele render, with a zoom/pan canvas. The drawing below is live — wheel or the buttons to zoom, drag to pan.
import { DiagramView } from "@/components/diagram/DiagramView";
import { ZoomPan } from "@/components/diagram/ZoomPan";
<ZoomPan
controls={({ zoomIn, zoomOut, resetZoom, centerView, scalePercent }) => (
<>…</>
)}
>
<DiagramView chart={source} config={{ theme: "ocean" }} />
</ZoomPan>;DiagramView
| Prop | Type | Default |
|---|---|---|
chart | string | required |
config.theme | "default" | "dark" | "forest" | "neutral" | "base" or a named palette | "default" |
config.themeVariables | Partial<DiagramThemeVariables> | none |
config.fontFamily | string | Pele's default |
config.fontSize | number | Pele's default |
config.maxWidth | number | none |
config.responsive | boolean | true |
label | string | "Diagram" |
onSuccess | (svg: string) => void | none |
onError | (message: string) => void | none |
className | string | — |
themeVariables keeps Mermaid's names (primaryColor, primaryTextColor,
primaryBorderColor, background, textColor, lineColor,
secondaryColor, tertiaryColor) and maps them to Pele's roles, so a config
copied from Mermaid keeps working. A variable Pele has no role for is ignored
rather than painted as a property nothing reads.
Playground
Edit the source, switch a template, pick a theme, then zoom, fit or reset. Copy and download take the rendered SVG Pele produced.
import { DiagramPlayground } from "@/components/diagram/DiagramPlayground";
<DiagramPlayground defaultValue={source} />;The preview renders one deferred value behind the editor, so typing stays smooth while the diagram still follows the source. Pele is synchronous, so the picture appears on the same render as its source; there is no spinner state to show.
Themes
default reads the page's roles, so it follows the light/dark switch without a
second render. A named theme sets the --pele-* properties on the diagram's
wrapper; the SVG is not rendered again.
| Theme | Character |
|---|---|
default | the page's own roles |
dark | slate surfaces and near-white ink |
forest | green surfaces on a pale page |
neutral | grey, no hue |
base | indigo accent |
emerald, teal, lime, mint | green family |
coral, amber, crimson, bronze | warm family |
ocean, sky, indigo | cool family |
violet, rose | purple / pink |
slate, charcoal | dark family |
The category
This is the Graphics category: the things the library draws.
| Page | What it is |
|---|---|
| Charts | bar, line, area, pie, radar and radial charts, on the GPU |
| Icons | the glyph set and its two accessibility rules |
| Diagrams | this page — the Diagram component |
The charts are TanStack Charts' scene compiler, compiled to a document the runtime's own renderer paints; the icons are the library's own set; the diagrams are Pele's renderer, on the same document route. One category, one paint path.
Edit this page on GitHubapps/docs/content/docs/graphics/diagrams.mdx