@@ -12,6 +12,7 @@ import {
1212} from "../interfaces.js" ;
1313
1414import type { Diagram } from "mermaid/dist/Diagram.js" ;
15+ import { DiagramStyleClassDef } from "mermaid/dist/diagram-api/types.js" ;
1516
1617export interface Flowchart {
1718 type : "flowchart" ;
@@ -74,7 +75,11 @@ const parseSubGraph = (data: any, containerEl: Element): SubGraph => {
7475 } ;
7576} ;
7677
77- const parseVertex = ( data : any , containerEl : Element ) : Vertex | undefined => {
78+ const parseVertex = (
79+ data : any ,
80+ containerEl : Element ,
81+ classes : { [ key : string ] : DiagramStyleClassDef }
82+ ) : Vertex | undefined => {
7883 // Find Vertex element
7984 const el : SVGSVGElement | null = containerEl . querySelector (
8085 `[id*="flowchart-${ data . id } -"]`
@@ -117,6 +122,7 @@ const parseVertex = (data: any, containerEl: Element): Vertex | undefined => {
117122 const value = property . split ( ":" ) [ 1 ] . trim ( ) ;
118123 containerStyle [ key ] = value ;
119124 } ) ;
125+
120126 const labelStyle : Vertex [ "labelStyle" ] = { } ;
121127 labelStyleText ?. split ( ";" ) . forEach ( ( property ) => {
122128 if ( ! property ) {
@@ -128,6 +134,19 @@ const parseVertex = (data: any, containerEl: Element): Vertex | undefined => {
128134 labelStyle [ key ] = value ;
129135 } ) ;
130136
137+ if ( data . classes ) {
138+ const classDef = classes [ data . classes ] ;
139+ if ( classDef ) {
140+ classDef . styles ?. forEach ( ( style ) => {
141+ const [ key , value ] = style . split ( ":" ) ;
142+ containerStyle [ key . trim ( ) as CONTAINER_STYLE_PROPERTY ] = value . trim ( ) ;
143+ } ) ;
144+ classDef . textStyles ?. forEach ( ( style ) => {
145+ const [ key , value ] = style . split ( ":" ) ;
146+ labelStyle [ key . trim ( ) as LABEL_STYLE_PROPERTY ] = value . trim ( ) ;
147+ } ) ;
148+ }
149+ }
131150 return {
132151 id : data . id ,
133152 labelType : data . labelType ,
@@ -230,8 +249,9 @@ export const parseMermaidFlowChartDiagram = (
230249 //@ts -ignore
231250 const mermaidParser = diagram . parser . yy ;
232251 const vertices = mermaidParser . getVertices ( ) ;
252+ const classes = mermaidParser . getClasses ( ) ;
233253 Object . keys ( vertices ) . forEach ( ( id ) => {
234- vertices [ id ] = parseVertex ( vertices [ id ] , containerEl ) ;
254+ vertices [ id ] = parseVertex ( vertices [ id ] , containerEl , classes ) ;
235255 } ) ;
236256
237257 // Track the count of edges based on the edge id
0 commit comments