mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 15:59:51 +02:00
Improved style handling
This commit is contained in:
51
src/utils.js
51
src/utils.js
@@ -36,8 +36,8 @@ module.exports.cloneCssStyles = function(svg, classes){
|
|||||||
var usedStyles = "";
|
var usedStyles = "";
|
||||||
var sheets = document.styleSheets;
|
var sheets = document.styleSheets;
|
||||||
for (var i = 0; i < sheets.length; i++) {
|
for (var i = 0; i < sheets.length; i++) {
|
||||||
// Avoid multiple inclusion on pages with multiple graphs
|
// Only clone css from stylesheets intended for mermaid
|
||||||
if (sheets[i].title != 'mermaid-svg-internal-css') {
|
if (sheets[i].title == 'mermaid') {
|
||||||
var rules = sheets[i].cssRules;
|
var rules = sheets[i].cssRules;
|
||||||
for (var j = 0; j < rules.length; j++) {
|
for (var j = 0; j < rules.length; j++) {
|
||||||
var rule = rules[j];
|
var rule = rules[j];
|
||||||
@@ -57,12 +57,22 @@ module.exports.cloneCssStyles = function(svg, classes){
|
|||||||
for (var className in classes) {
|
for (var className in classes) {
|
||||||
if (classes.hasOwnProperty(className) && typeof(className) != "undefined") {
|
if (classes.hasOwnProperty(className) && typeof(className) != "undefined") {
|
||||||
if (className === 'default') {
|
if (className === 'default') {
|
||||||
defaultStyles = '.node' + ' { ' + classes[className].styles.join("; ") + '; }\n';
|
if (classes.default.styles instanceof Array) {
|
||||||
|
defaultStyles += '.node' + ' { ' + classes[className].styles.join("; ") + '; }\n';
|
||||||
|
}
|
||||||
|
if (classes.default.nodeLabelStyles instanceof Array) {
|
||||||
|
defaultStyles += '.node text ' + ' { ' + classes[className].nodeLabelStyles.join("; ") + '; }\n';
|
||||||
|
}
|
||||||
|
if (classes.default.edgeLabelStyles instanceof Array) {
|
||||||
|
defaultStyles += '.edgeLabel text ' + ' { ' + classes[className].edgeLabelStyles.join("; ") + '; }\n';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (classes[className].styles instanceof Array) {
|
||||||
embeddedStyles += '.' + className + ' { ' + classes[className].styles.join("; ") + '; }\n';
|
embeddedStyles += '.' + className + ' { ' + classes[className].styles.join("; ") + '; }\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (usedStyles !== "" || defaultStyles !== "" || embeddedStyles !== "") {
|
if (usedStyles !== "" || defaultStyles !== "" || embeddedStyles !== "") {
|
||||||
var s = document.createElement('style');
|
var s = document.createElement('style');
|
||||||
@@ -82,3 +92,38 @@ module.exports.cloneCssStyles = function(svg, classes){
|
|||||||
svg.insertBefore(s, svg.firstChild);
|
svg.insertBefore(s, svg.firstChild);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var equals = function (val, variable){
|
||||||
|
if(typeof variable === 'undefined'){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return (val === variable);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var mermaid_config_exists = function() {
|
||||||
|
return (typeof mermaid_config !== 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
var mermaid_config_item_exists = function(item) {
|
||||||
|
return mermaid_config_exists() && (typeof mermaid_config[item] !== 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.config = {};
|
||||||
|
|
||||||
|
module.exports.config.startOnLoad = function() {
|
||||||
|
if (mermaid_config_item_exists(startOnLoad)) {
|
||||||
|
return mermaid_config.startOnLoad === true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.config.labelStyle = function() {
|
||||||
|
if (mermaid_config_item_exists(labelStyle)) {
|
||||||
|
return mermaid_config.labelStyle === 'html';
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user