mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-13 04:19:44 +02:00
This commit is contained in:
@@ -74,11 +74,6 @@ function parse(text) {
|
|||||||
try {
|
try {
|
||||||
text = text + '\n';
|
text = text + '\n';
|
||||||
const cnf = configApi.getConfig();
|
const cnf = configApi.getConfig();
|
||||||
const graphInit = utils.detectInit(text, cnf);
|
|
||||||
if (graphInit) {
|
|
||||||
reinitialize(graphInit);
|
|
||||||
log.info('reinit ', graphInit);
|
|
||||||
}
|
|
||||||
const graphType = utils.detectType(text, cnf);
|
const graphType = utils.detectType(text, cnf);
|
||||||
let parser;
|
let parser;
|
||||||
|
|
||||||
@@ -90,10 +85,6 @@ function parse(text) {
|
|||||||
parser.parser.yy = gitGraphAst;
|
parser.parser.yy = gitGraphAst;
|
||||||
break;
|
break;
|
||||||
case 'flowchart':
|
case 'flowchart':
|
||||||
flowDb.clear();
|
|
||||||
parser = flowParser;
|
|
||||||
parser.parser.yy = flowDb;
|
|
||||||
break;
|
|
||||||
case 'flowchart-v2':
|
case 'flowchart-v2':
|
||||||
flowDb.clear();
|
flowDb.clear();
|
||||||
parser = flowParser;
|
parser = flowParser;
|
||||||
@@ -109,17 +100,11 @@ function parse(text) {
|
|||||||
parser.parser.yy = ganttDb;
|
parser.parser.yy = ganttDb;
|
||||||
break;
|
break;
|
||||||
case 'class':
|
case 'class':
|
||||||
parser = classParser;
|
|
||||||
parser.parser.yy = classDb;
|
|
||||||
break;
|
|
||||||
case 'classDiagram':
|
case 'classDiagram':
|
||||||
parser = classParser;
|
parser = classParser;
|
||||||
parser.parser.yy = classDb;
|
parser.parser.yy = classDb;
|
||||||
break;
|
break;
|
||||||
case 'state':
|
case 'state':
|
||||||
parser = stateParser;
|
|
||||||
parser.parser.yy = stateDb;
|
|
||||||
break;
|
|
||||||
case 'stateDiagram':
|
case 'stateDiagram':
|
||||||
parser = stateParser;
|
parser = stateParser;
|
||||||
parser.parser.yy = stateDb;
|
parser.parser.yy = stateDb;
|
||||||
@@ -261,7 +246,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
txt = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa';
|
txt = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa';
|
||||||
}
|
}
|
||||||
|
|
||||||
// let d3Iframe;
|
|
||||||
let root = select('body');
|
let root = select('body');
|
||||||
|
|
||||||
// In regular execurtion the container will be the div with a mermaid class
|
// In regular execurtion the container will be the div with a mermaid class
|
||||||
@@ -274,7 +258,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
.attr('id', 'i' + id)
|
.attr('id', 'i' + id)
|
||||||
.attr('style', 'width: 100%; height: 100%;')
|
.attr('style', 'width: 100%; height: 100%;')
|
||||||
.attr('sandbox', '');
|
.attr('sandbox', '');
|
||||||
// const iframeBody = ;
|
|
||||||
root = select(iframe.nodes()[0].contentDocument.body);
|
root = select(iframe.nodes()[0].contentDocument.body);
|
||||||
root.node().style.margin = 0;
|
root.node().style.margin = 0;
|
||||||
}
|
}
|
||||||
@@ -326,15 +309,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (cnf.securityLevel === 'sandbox') {
|
|
||||||
// const iframe = select('body')
|
|
||||||
// .append('iframe')
|
|
||||||
// .attr('id', 'i' + id)
|
|
||||||
// .attr('sandbox', '');
|
|
||||||
// // const iframeBody = ;
|
|
||||||
// root = select(iframe.nodes()[0].contentDocument.body);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Add the tmp div used for rendering with the id `d${id}`
|
// Add the tmp div used for rendering with the id `d${id}`
|
||||||
// d+id it will contain a svg with the id "id"
|
// d+id it will contain a svg with the id "id"
|
||||||
|
|
||||||
@@ -346,7 +320,7 @@ const render = function (id, _txt, cb, container) {
|
|||||||
.attr('id', 'i' + id)
|
.attr('id', 'i' + id)
|
||||||
.attr('style', 'width: 100%; height: 100%;')
|
.attr('style', 'width: 100%; height: 100%;')
|
||||||
.attr('sandbox', '');
|
.attr('sandbox', '');
|
||||||
// const iframeBody = ;
|
|
||||||
root = select(iframe.nodes()[0].contentDocument.body);
|
root = select(iframe.nodes()[0].contentDocument.body);
|
||||||
root.node().style.margin = 0;
|
root.node().style.margin = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -426,8 +400,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// log.warn(cnf.themeVariables);
|
|
||||||
|
|
||||||
const stylis = (selector, styles) => serialize(compile(`${selector}{${styles}}`), stringify);
|
const stylis = (selector, styles) => serialize(compile(`${selector}{${styles}}`), stringify);
|
||||||
const rules = stylis(`#${id}`, getStyles(graphType, userStyles, cnf.themeVariables));
|
const rules = stylis(`#${id}`, getStyles(graphType, userStyles, cnf.themeVariables));
|
||||||
|
|
||||||
@@ -435,23 +407,9 @@ const render = function (id, _txt, cb, container) {
|
|||||||
style1.innerHTML = `#${id} ` + rules;
|
style1.innerHTML = `#${id} ` + rules;
|
||||||
svg.insertBefore(style1, firstChild);
|
svg.insertBefore(style1, firstChild);
|
||||||
|
|
||||||
// Verify that the generated svgs are ok before removing this
|
|
||||||
|
|
||||||
// const style2 = document.createElement('style');
|
|
||||||
// const cs = window.getComputedStyle(svg);
|
|
||||||
// style2.innerHTML = `#d${id} * {
|
|
||||||
// color: ${cs.color};
|
|
||||||
// // font: ${cs.font};
|
|
||||||
// // font-family: Arial;
|
|
||||||
// // font-size: 24px;
|
|
||||||
// }`;
|
|
||||||
// svg.insertBefore(style2, firstChild);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (graphType) {
|
switch (graphType) {
|
||||||
case 'gitGraph':
|
case 'gitGraph':
|
||||||
// cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
|
||||||
//gitGraphRenderer.setConf(cnf.git);
|
|
||||||
gitGraphRenderer.draw(txt, id, false);
|
gitGraphRenderer.draw(txt, id, false);
|
||||||
break;
|
break;
|
||||||
case 'flowchart':
|
case 'flowchart':
|
||||||
@@ -508,8 +466,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
infoRenderer.draw(txt, id, pkg.version);
|
infoRenderer.draw(txt, id, pkg.version);
|
||||||
break;
|
break;
|
||||||
case 'pie':
|
case 'pie':
|
||||||
//cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
|
||||||
//pieRenderer.setConf(cnf.pie);
|
|
||||||
pieRenderer.draw(txt, id, pkg.version);
|
pieRenderer.draw(txt, id, pkg.version);
|
||||||
break;
|
break;
|
||||||
case 'er':
|
case 'er':
|
||||||
@@ -526,7 +482,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// errorRenderer.setConf(cnf.class);
|
|
||||||
errorRenderer.draw(id, pkg.version);
|
errorRenderer.draw(id, pkg.version);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -557,7 +512,6 @@ const render = function (id, _txt, cb, container) {
|
|||||||
let width = '100%';
|
let width = '100%';
|
||||||
let height = '100%';
|
let height = '100%';
|
||||||
if (svgEl) {
|
if (svgEl) {
|
||||||
// width = svgEl.viewBox.baseVal.width + 'px';
|
|
||||||
height = svgEl.viewBox.baseVal.height + 'px';
|
height = svgEl.viewBox.baseVal.height + 'px';
|
||||||
}
|
}
|
||||||
svgCode = `<iframe style="width:${width};height:${height};border:0;margin:0;" src="data:text/html;base64,${btoa(
|
svgCode = `<iframe style="width:${width};height:${height};border:0;margin:0;" src="data:text/html;base64,${btoa(
|
||||||
@@ -651,7 +605,6 @@ const handleDirective = function (p, directive, type) {
|
|||||||
log.debug('sanitize in handleDirective', directive.args);
|
log.debug('sanitize in handleDirective', directive.args);
|
||||||
directiveSanitizer(directive.args);
|
directiveSanitizer(directive.args);
|
||||||
log.debug('sanitize in handleDirective (done)', directive.args);
|
log.debug('sanitize in handleDirective (done)', directive.args);
|
||||||
reinitialize(directive.args);
|
|
||||||
configApi.addDirective(directive.args);
|
configApi.addDirective(directive.args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -679,7 +632,6 @@ const handleDirective = function (p, directive, type) {
|
|||||||
function updateRendererConfigs(conf) {
|
function updateRendererConfigs(conf) {
|
||||||
// Todo remove, all diagrams should get config on demoand from the config object, no need for this
|
// Todo remove, all diagrams should get config on demoand from the config object, no need for this
|
||||||
|
|
||||||
// gitGraphRenderer.setConf(conf.git); // Todo Remove all of these
|
|
||||||
flowRenderer.setConf(conf.flowchart);
|
flowRenderer.setConf(conf.flowchart);
|
||||||
flowRendererV2.setConf(conf.flowchart);
|
flowRendererV2.setConf(conf.flowchart);
|
||||||
if (typeof conf['sequenceDiagram'] !== 'undefined') {
|
if (typeof conf['sequenceDiagram'] !== 'undefined') {
|
||||||
@@ -691,33 +643,14 @@ function updateRendererConfigs(conf) {
|
|||||||
stateRenderer.setConf(conf.state);
|
stateRenderer.setConf(conf.state);
|
||||||
stateRendererV2.setConf(conf.state);
|
stateRendererV2.setConf(conf.state);
|
||||||
infoRenderer.setConf(conf.class);
|
infoRenderer.setConf(conf.class);
|
||||||
// pieRenderer.setConf(conf.class);
|
|
||||||
erRenderer.setConf(conf.er);
|
erRenderer.setConf(conf.er);
|
||||||
journeyRenderer.setConf(conf.journey);
|
journeyRenderer.setConf(conf.journey);
|
||||||
requirementRenderer.setConf(conf.requirement);
|
requirementRenderer.setConf(conf.requirement);
|
||||||
errorRenderer.setConf(conf.class);
|
errorRenderer.setConf(conf.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** To be removed */
|
|
||||||
function reinitialize() {
|
|
||||||
// `mermaidAPI.reinitialize: v${pkg.version}`,
|
|
||||||
// JSON.stringify(options),
|
|
||||||
// options.themeVariables.primaryColor;
|
|
||||||
// // if (options.theme && theme[options.theme]) {
|
|
||||||
// // options.themeVariables = theme[options.theme].getThemeVariables(options.themeVariables);
|
|
||||||
// // }
|
|
||||||
// // Set default options
|
|
||||||
// const config =
|
|
||||||
// typeof options === 'object' ? configApi.setConfig(options) : configApi.getSiteConfig();
|
|
||||||
// updateRendererConfigs(config);
|
|
||||||
// setLogLevel(config.logLevel);
|
|
||||||
// log.debug('mermaidAPI.reinitialize: ', config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param {any} options */
|
/** @param {any} options */
|
||||||
function initialize(options) {
|
function initialize(options) {
|
||||||
// console.warn(`mermaidAPI.initialize: v${pkg.version} `, options);
|
|
||||||
|
|
||||||
// Handle legacy location of font-family configuration
|
// Handle legacy location of font-family configuration
|
||||||
if (options && options.fontFamily) {
|
if (options && options.fontFamily) {
|
||||||
if (!options.themeVariables) {
|
if (!options.themeVariables) {
|
||||||
@@ -743,7 +676,6 @@ function initialize(options) {
|
|||||||
|
|
||||||
updateRendererConfigs(config);
|
updateRendererConfigs(config);
|
||||||
setLogLevel(config.logLevel);
|
setLogLevel(config.logLevel);
|
||||||
// log.debug('mermaidAPI.initialize: ', config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mermaidAPI = Object.freeze({
|
const mermaidAPI = Object.freeze({
|
||||||
@@ -751,16 +683,12 @@ const mermaidAPI = Object.freeze({
|
|||||||
parse,
|
parse,
|
||||||
parseDirective,
|
parseDirective,
|
||||||
initialize,
|
initialize,
|
||||||
reinitialize,
|
|
||||||
getConfig: configApi.getConfig,
|
getConfig: configApi.getConfig,
|
||||||
setConfig: configApi.setConfig,
|
setConfig: configApi.setConfig,
|
||||||
getSiteConfig: configApi.getSiteConfig,
|
getSiteConfig: configApi.getSiteConfig,
|
||||||
updateSiteConfig: configApi.updateSiteConfig,
|
updateSiteConfig: configApi.updateSiteConfig,
|
||||||
reset: () => {
|
reset: () => {
|
||||||
// console.warn('reset');
|
|
||||||
configApi.reset();
|
configApi.reset();
|
||||||
// const siteConfig = configApi.getSiteConfig();
|
|
||||||
// updateRendererConfigs(siteConfig);
|
|
||||||
},
|
},
|
||||||
globalReset: () => {
|
globalReset: () => {
|
||||||
configApi.reset(configApi.defaultConfig);
|
configApi.reset(configApi.defaultConfig);
|
||||||
|
Reference in New Issue
Block a user