diff --git a/packages/mermaid/src/diagrams/state/stateDb.js b/packages/mermaid/src/diagrams/state/stateDb.js index b0c436457..8e2ec5b81 100644 --- a/packages/mermaid/src/diagrams/state/stateDb.js +++ b/packages/mermaid/src/diagrams/state/stateDb.js @@ -760,6 +760,34 @@ function insertOrUpdateNode(nodes, nodeData) { if (!nodeData.id || nodeData.id === '' || nodeData.id === '') { return; } + + //Populate node style attributes if nodeData has classes defined + if (nodeData.classes) { + nodeData.classes.split(' ').forEach((cssClass) => { + if (classes[cssClass]) { + classes[cssClass].styles.forEach((style) => { + // Populate nodeData with style attributes specifically to be used by rough.js + if (style && style.startsWith('fill:')) { + nodeData.backgroundColor = style.replace('fill:', ''); + } + if (style && style.startsWith('stroke:')) { + nodeData.borderColor = style.replace('stroke:', ''); + } + if (style && style.startsWith('stroke-width:')) { + nodeData.borderWidth = style.replace('stroke-width:', ''); + } + + nodeData.style += style + ';'; + }); + classes[cssClass].textStyles.forEach((style) => { + nodeData.labelStyle += style + ';'; + if (style && style.startsWith('fill:')) { + nodeData.labelTextColor = style.replace('fill:', ''); + } + }); + } + }); + } const existingNodeData = nodes.find((node) => node.id === nodeData.id); if (existingNodeData) { //update the existing nodeData diff --git a/packages/mermaid/src/rendering-util/types.d.ts b/packages/mermaid/src/rendering-util/types.d.ts index 4d10498fe..b07d84edc 100644 --- a/packages/mermaid/src/rendering-util/types.d.ts +++ b/packages/mermaid/src/rendering-util/types.d.ts @@ -44,6 +44,11 @@ interface Node { useRough?: boolean; useHtmlLabels?: boolean; centerLabel?: boolean; + + //Node style properties + backgroundColor?: string; + borderColor?: string; + labelTextColor?: string; } // Common properties for any edge in the system