From 1f64302ae213b4c057fb4268288fbc72ea705fe7 Mon Sep 17 00:00:00 2001 From: Dan Fallon Date: Sun, 20 Nov 2022 22:42:26 -0600 Subject: [PATCH] Use stylis to prepend idSelector code previously manually inserted idSelector before the generated CSS. This could produce incorrect CSS. Adding & in front of rules will ensure that it behaves properly. Stylis seems permissive about the lack of nesting selector, but fails if there is no selector at all. (e.g. "{...props...}") We should probably do this for each diagram's style.ts files as well --- packages/mermaid/src/mermaidAPI.ts | 4 ++-- packages/mermaid/src/styles.ts | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 0df1da305f..d9ef9a5618 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -510,7 +510,7 @@ const render = function ( ); const style1 = document.createElement('style'); - style1.innerHTML = `${idSelector} ` + rules; + style1.innerHTML = rules; svg.insertBefore(style1, firstChild); // ------------------------------------------------------------------------------- @@ -706,7 +706,7 @@ const renderAsync = async function ( ); const style1 = document.createElement('style'); - style1.innerHTML = `${idSelector} ` + rules; + style1.innerHTML = rules; svg.insertBefore(style1, firstChild); // ------------------------------------------------------------------------------- diff --git a/packages/mermaid/src/styles.ts b/packages/mermaid/src/styles.ts index 0c4a7e1a58..055f63be5d 100644 --- a/packages/mermaid/src/styles.ts +++ b/packages/mermaid/src/styles.ts @@ -53,7 +53,7 @@ const getStyles = ( } else { log.warn(`No theme found for ${type}`); } - return ` { + return ` & { font-family: ${options.fontFamily}; font-size: ${options.fontSize}; fill: ${options.textColor} @@ -61,40 +61,40 @@ const getStyles = ( /* Classes common for multiple diagrams */ - .error-icon { + & .error-icon { fill: ${options.errorBkgColor}; } - .error-text { + & .error-text { fill: ${options.errorTextColor}; stroke: ${options.errorTextColor}; } - .edge-thickness-normal { + & .edge-thickness-normal { stroke-width: 2px; } - .edge-thickness-thick { + & .edge-thickness-thick { stroke-width: 3.5px } - .edge-pattern-solid { + & .edge-pattern-solid { stroke-dasharray: 0; } - .edge-pattern-dashed{ + & .edge-pattern-dashed{ stroke-dasharray: 3; } .edge-pattern-dotted { stroke-dasharray: 2; } - .marker { + & .marker { fill: ${options.lineColor}; stroke: ${options.lineColor}; } - .marker.cross { + & .marker.cross { stroke: ${options.lineColor}; } - svg { + & svg { font-family: ${options.fontFamily}; font-size: ${options.fontSize}; }