Functions
Import these from @grafloria/engine.
Functions
applyArchitectureModel
Put sides, arrows, icons, group frames and junctions on the model the flowchart pipeline built — and lay it out.
tsfunction applyArchitectureModel(diagram: DiagramModel, model: MermaidArchitectureModel): void
applyBlockGrid
Put the grid on the model the flowchart pipeline built — metadata.grid on the
diagram and every nested block — mark it block-beta, and lay it out.
tsfunction applyBlockGrid(diagram: DiagramModel, model: MermaidBlockModel): void
architectureModelToFlowchart
The same diagram as Grafloria flowchart text: a subgraph per group (nested), a node per service.
tsfunction architectureModelToFlowchart(model: MermaidArchitectureModel): string
blockModelToFlowchart
The same diagram as Grafloria flowchart text: every block a node line, every nested block a subgraph.
tsfunction blockModelToFlowchart(model: MermaidBlockModel): string
classModelFromDiagram
tsfunction classModelFromDiagram(diagram: DiagramModel): MermaidClassModel
classModelToDiagram
tsfunction classModelToDiagram(model: MermaidClassModel): DiagramModel
createToken
Helper to create tokens
tsfunction createToken(
type: TokenType,
value: string,
line: number,
column: number,
startIndex: number,
endIndex: number
): Token
erMarkers
Map a parsed cardinality pair onto the kit's explicit marker pair.
tsfunction erMarkers(rel: MermaidErRelationship): { tail: ErCardinalityMarker; head: ErCardinalityMarker }
erModelFromDiagram
Read the Mermaid ER model back off a DiagramModel (for generation).
tsfunction erModelFromDiagram(diagram: DiagramModel): MermaidErModel
erModelToDiagram
Build a DiagramModel from a parsed ER model.
tsfunction erModelToDiagram(model: MermaidErModel): DiagramModel
erSpecFrom
Project the Mermaid model onto the diagram kit's erDiagram() options.
tsfunction erSpecFrom(model: MermaidErModel): ErSpec
generateArchitectureFromDiagram
Write an architecture-beta diagram back as architecture-beta: groups, services, junctions, sided edges.
tsfunction generateArchitectureFromDiagram(diagram: DiagramModel): string
generateBlockFromDiagram
Write a block-beta diagram back as block-beta: its grid, its blocks as written, its edges and styles.
tsfunction generateBlockFromDiagram(diagram: DiagramModel): string
generateClassFromDiagram
tsfunction generateClassFromDiagram(diagram: DiagramModel): string
generateErFromDiagram
Generate an erDiagram body directly from a DiagramModel.
tsfunction generateErFromDiagram(diagram: DiagramModel): string
generateMermaidClass
tsfunction generateMermaidClass(model: MermaidClassModel): string
generateMermaidEr
Emit a valid Mermaid erDiagram body. Two rules here are not style choices —
both were found by running the export through real Mermaid 11.16 (the oracle):
- THE LABEL IS ALWAYS WRITTEN, AND ALWAYS QUOTED. It is not optional
(
A ||--o{ Bis a parse error, so an unlabelled relationship needs: ""), and Mermaid's ER lexer treatsone,many,zero, … as CARDINALITY keywords even in label position —: onefails,: "one"parses. Quoting unconditionally makes the whole reserved-word class disappear. - NO
id["alias"]ENTITY ALIAS. We parse it (it is forward syntax), but Mermaid 11.16 rejects it, and emitting a body real Mermaid cannot read breaks the governing invariant. The display name rides in the%%grafloria:sidecar instead — Tier 3, exactly what it is for.
tsfunction generateMermaidEr(model: MermaidErModel): string
generateMermaidState
Emit a valid stateDiagram-v2 body. The scoped pseudo-states are collapsed
back to [*], which is the only spelling Mermaid accepts — writing
__start__ would export a body that renders as a real state called
"start", i.e. a different diagram.
tsfunction generateMermaidState(model: MermaidStateModel): string
generateStateFromDiagram
tsfunction generateStateFromDiagram(diagram: DiagramModel): string
isClassDef
tsfunction isClassDef(node: ASTNode): node is ClassDefNode
isEdgeDefinition
tsfunction isEdgeDefinition(node: ASTNode): node is EdgeDefinitionNode
isNodeDefinition
Type guard helpers
tsfunction isNodeDefinition(node: ASTNode): node is NodeDefinitionNode
isStyleNode
tsfunction isStyleNode(node: ASTNode): node is StyleNode
isSubgraph
tsfunction isSubgraph(node: ASTNode): node is SubgraphNode
parseMermaidArchitecture
tsfunction parseMermaidArchitecture(text: string): MermaidArchitectureModel
parseMermaidBlock
tsfunction parseMermaidBlock(text: string): MermaidBlockModel
parseMermaidClass
Parse a classDiagram body. Unknown lines (click, style, namespace,
callback, future syntax) are skipped — never turned into a class.
tsfunction parseMermaidClass(text: string): MermaidClassModel
parseMermaidEr
Parse an erDiagram body into the Mermaid-shaped model. Lines that are not
grammar (styling directives, future syntax) are SKIPPED, never nodified.
tsfunction parseMermaidEr(text: string): MermaidErModel
parseMermaidState
Parse a state-diagram body. stateDiagram (v1) and stateDiagram-v2 share
this grammar — v2 is a different LAYOUT engine in Mermaid, not a different
syntax, so refusing v1 would be arbitrary.
tsfunction parseMermaidState(text: string): MermaidStateModel
stateModelFromDiagram
tsfunction stateModelFromDiagram(diagram: DiagramModel): MermaidStateModel
stateModelToDiagram
tsfunction stateModelToDiagram(model: MermaidStateModel): DiagramModel
umlRelationKind
Operator → (kit kind, whether the kit's ends are the REVERSE of Mermaid's), derived from the grammar rather than enumerated. This reproduces the previous 17-row table exactly and covers the other 55 spellings for free.
tsfunction umlRelationKind(operator: string): { kind: UmlKind; reversed: boolean }
umlSpecFrom
Project onto umlDiagram() options — this is where Mermaid's
arrowhead-first operators are flipped into the kit's from→to convention.
tsfunction umlSpecFrom(model: MermaidClassModel): UmlSpec
Was this page helpful?