#5237 Styling fixes

This commit is contained in:
Knut Sveidqvist 2024-06-28 15:27:32 +02:00
parent 3f0ababca6
commit 35797f867f
4 changed files with 8841 additions and 11963 deletions

View File

@ -201,9 +201,9 @@ export const updateLink = function (positions: ('default' | number)[], style: st
if (pos === 'default') {
edges.defaultStyle = style;
} else {
if (utils.isSubstringInArray('fill', style) === -1) {
style.push('fill:none');
}
// if (utils.isSubstringInArray('fill', style) === -1) {
// style.push('fill:none');
// }
edges[pos].style = style;
}
});
@ -807,8 +807,8 @@ const addNodeFromVertex = (
parentId,
padding: config.flowchart?.padding || 8,
cssStyles: vertex.styles,
cssCompiledStyles: getCompiledStyles(vertex.classes),
cssClasses: vertex.classes.join(' '),
cssCompiledStyles: getCompiledStyles(['default', 'node', ...vertex.classes]),
cssClasses: 'default ' + vertex.classes.join(' '),
shape: getTypeFromVertex(vertex),
dir: vertex.dir,
domId: vertex.domId,
@ -888,7 +888,8 @@ export const getData = () => {
const e = getEdges();
e.forEach((rawEdge, index) => {
const { arrowTypeStart, arrowTypeEnd } = destructEdgeType(rawEdge.type);
const styles = e.defaultStyle || [];
const styles = [...(e.defaultStyle || [])];
if (rawEdge.style) {
styles.push(...rawEdge.style);
}

View File

@ -145,7 +145,11 @@ export const createCssStyles = (
}
// create the css styles for the tspan element and the text styles (only if there are textStyles)
if (!isEmpty(styleClassDef.textStyles)) {
cssStyles += cssImportantStyles(styleClassDef.id, 'tspan', styleClassDef.textStyles);
cssStyles += cssImportantStyles(
styleClassDef.id,
'tspan',
(styleClassDef?.textStyles || []).map((s) => s.replace('color', 'fill'))
);
}
});
}

View File

@ -2,6 +2,7 @@
// @ts-nocheck TODO: Fix types
import type { MermaidConfig } from '../config.type.js';
import type { Group } from '../diagram-api/types.js';
import { select } from 'd3';
import type { D3TSpanElement, D3TextElement } from '../diagrams/common/commonTypes.js';
import { log } from '../logger.js';
import { markdownToHTML, markdownToLines } from '../rendering-util/handle-markdown-text.js';
@ -223,14 +224,18 @@ export const createText = async (
const vertexNode = await addHtmlSpan(el, node, width, classes, addSvgBackground);
return vertexNode;
} else {
const structuredText = markdownToLines(text, config);
const structuredText = markdownToLines(text.replace('<br>', '<br/>'), config);
const svgLabel = createFormattedText(
width,
el,
structuredText,
text ? addSvgBackground : false
);
svgLabel.setAttribute('style', style.replace('fill:', 'color:'));
if (style.match('stroke:')) style = style.replace('stroke:', 'lineColor:');
select(svgLabel)
.select('text')
.attr('style', style.replace(/color\:/g, 'fill:'));
// svgLabel.setAttribute('style', style);
return svgLabel;
}
};

20776
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff