2021-03-29 16:33:29 +00:00
|
|
|
import 'mermaid';
|
2017-11-04 16:59:48 +00:00
|
|
|
import extensionSvc from '../services/extensionSvc';
|
|
|
|
import utils from '../services/utils';
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
logLevel: 5,
|
|
|
|
startOnLoad: false,
|
|
|
|
arrowMarkerAbsolute: false,
|
2021-03-29 16:33:29 +00:00
|
|
|
theme: 'neutral',
|
2017-11-04 16:59:48 +00:00
|
|
|
flowchart: {
|
|
|
|
htmlLabels: true,
|
2018-09-19 16:28:03 +00:00
|
|
|
curve: 'linear',
|
2017-11-04 16:59:48 +00:00
|
|
|
},
|
2018-09-19 16:28:03 +00:00
|
|
|
sequence: {
|
2017-11-04 16:59:48 +00:00
|
|
|
diagramMarginX: 50,
|
|
|
|
diagramMarginY: 10,
|
|
|
|
actorMargin: 50,
|
|
|
|
width: 150,
|
|
|
|
height: 65,
|
|
|
|
boxMargin: 10,
|
|
|
|
boxTextMargin: 5,
|
|
|
|
noteMargin: 10,
|
|
|
|
messageMargin: 35,
|
|
|
|
mirrorActors: true,
|
|
|
|
bottomMarginAdj: 1,
|
|
|
|
useMaxWidth: true,
|
|
|
|
},
|
|
|
|
gantt: {
|
|
|
|
titleTopMargin: 25,
|
|
|
|
barHeight: 20,
|
|
|
|
barGap: 4,
|
|
|
|
topPadding: 50,
|
|
|
|
leftPadding: 75,
|
|
|
|
gridLineStartPadding: 35,
|
|
|
|
fontSize: 11,
|
|
|
|
fontFamily: '"Open-Sans", "sans-serif"',
|
2018-09-19 16:28:03 +00:00
|
|
|
numberSectionStyles: 4,
|
|
|
|
axisFormat: '%Y-%m-%d',
|
2017-11-04 16:59:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const containerElt = document.createElement('div');
|
|
|
|
containerElt.className = 'hidden-rendering-container';
|
|
|
|
document.body.appendChild(containerElt);
|
|
|
|
|
2021-03-29 16:33:29 +00:00
|
|
|
let init = () => {
|
|
|
|
window.mermaid.initialize(config);
|
|
|
|
init = () => {};
|
|
|
|
};
|
2017-11-04 16:59:48 +00:00
|
|
|
|
2021-03-29 16:33:29 +00:00
|
|
|
const render = (elt) => {
|
2017-11-04 16:59:48 +00:00
|
|
|
try {
|
2021-03-29 16:33:29 +00:00
|
|
|
init();
|
|
|
|
const svgId = `mermaid-svg-${utils.uid()}`;
|
|
|
|
window.mermaid.mermaidAPI.render(svgId, elt.textContent, () => {
|
|
|
|
while (elt.firstChild) {
|
|
|
|
elt.removeChild(elt.lastChild);
|
|
|
|
}
|
|
|
|
elt.appendChild(containerElt.querySelector(`#${svgId}`));
|
|
|
|
}, containerElt);
|
2017-11-04 16:59:48 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e); // eslint-disable-line no-console
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extensionSvc.onGetOptions((options, properties) => {
|
|
|
|
options.mermaid = properties.extensions.mermaid.enabled;
|
|
|
|
});
|
|
|
|
|
|
|
|
extensionSvc.onSectionPreview((elt) => {
|
2018-05-06 00:46:33 +00:00
|
|
|
elt.querySelectorAll('.prism.language-mermaid')
|
|
|
|
.cl_each(diagramElt => render(diagramElt.parentNode));
|
2017-11-04 16:59:48 +00:00
|
|
|
});
|