mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-09 10:36:43 +02:00
Refactor code in lib/ folder
This commit is contained in:
@@ -9,7 +9,6 @@ var path = require('path')
|
|||||||
var PHANTOM_VERSION = '^2.1.0'
|
var PHANTOM_VERSION = '^2.1.0'
|
||||||
|
|
||||||
var info = chalk.blue.bold
|
var info = chalk.blue.bold
|
||||||
// var note = chalk.green.bold
|
|
||||||
|
|
||||||
module.exports = (function () {
|
module.exports = (function () {
|
||||||
return new Cli()
|
return new Cli()
|
||||||
@@ -63,7 +62,6 @@ function Cli (options) {
|
|||||||
Cli.prototype.parse = function (argv, next) {
|
Cli.prototype.parse = function (argv, next) {
|
||||||
this.errors = [] // clear errors
|
this.errors = [] // clear errors
|
||||||
var options = parseArgs(argv, this.options)
|
var options = parseArgs(argv, this.options)
|
||||||
// var phantom
|
|
||||||
|
|
||||||
if (options.version) {
|
if (options.version) {
|
||||||
var pkg = require('../package.json')
|
var pkg = require('../package.json')
|
||||||
@@ -148,7 +146,6 @@ Cli.prototype.parse = function (argv, next) {
|
|||||||
|
|
||||||
function createCheckPhantom (_phantomPath) {
|
function createCheckPhantom (_phantomPath) {
|
||||||
var phantomPath = _phantomPath
|
var phantomPath = _phantomPath
|
||||||
// var phantomVersion
|
|
||||||
|
|
||||||
return function checkPhantom (_next) {
|
return function checkPhantom (_next) {
|
||||||
var next = _next || function () { }
|
var next = _next || function () { }
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
// var os = require('os')
|
|
||||||
// var fs = require('fs')
|
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
var spawn = require('child_process').spawn
|
var spawn = require('child_process').spawn
|
||||||
|
|
||||||
|
@@ -74,7 +74,6 @@ files.forEach(function (file) {
|
|||||||
var oParser = new window.DOMParser()
|
var oParser = new window.DOMParser()
|
||||||
var oDOM
|
var oDOM
|
||||||
var svgContent
|
var svgContent
|
||||||
var allElements
|
|
||||||
|
|
||||||
console.log('ready to execute png: ' + filename + '.png ')
|
console.log('ready to execute png: ' + filename + '.png ')
|
||||||
|
|
||||||
@@ -93,13 +92,6 @@ files.forEach(function (file) {
|
|||||||
resolveSVGElement(oDOM.firstChild)
|
resolveSVGElement(oDOM.firstChild)
|
||||||
setSVGStyle(oDOM.firstChild, options.css)
|
setSVGStyle(oDOM.firstChild, options.css)
|
||||||
|
|
||||||
// traverse the SVG, and replace all foreignObject elements
|
|
||||||
// can be removed when https://github.com/knsv/mermaid/issues/58 is resolved
|
|
||||||
allElements = traverse(oDOM)
|
|
||||||
for (var i = 0, len = allElements.length; i < len; i++) {
|
|
||||||
resolveForeignObjects(allElements[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputPath = options.outputDir + fs.separator + filename + options.outputSuffix
|
var outputPath = options.outputDir + fs.separator + filename + options.outputSuffix
|
||||||
if (options.png) {
|
if (options.png) {
|
||||||
page.viewportSize = {
|
page.viewportSize = {
|
||||||
@@ -139,37 +131,12 @@ function logger (_verbose) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function traverse (obj) {
|
|
||||||
var tree = []
|
|
||||||
|
|
||||||
tree.push(obj)
|
|
||||||
visit(obj)
|
|
||||||
|
|
||||||
function visit (node) {
|
|
||||||
if (node && node.hasChildNodes()) {
|
|
||||||
var child = node.firstChild
|
|
||||||
while (child) {
|
|
||||||
if (child.nodeType === 1 && child.nodeName !== 'SCRIPT') {
|
|
||||||
tree.push(child)
|
|
||||||
visit(child)
|
|
||||||
}
|
|
||||||
child = child.nextSibling
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tree
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveSVGElement (element) {
|
function resolveSVGElement (element) {
|
||||||
var prefix = {
|
var prefix = {
|
||||||
xmlns: 'http://www.w3.org/2000/xmlns/',
|
xmlns: 'http://www.w3.org/2000/xmlns/',
|
||||||
xlink: 'http://www.w3.org/1999/xlink',
|
xlink: 'http://www.w3.org/1999/xlink',
|
||||||
svg: 'http://www.w3.org/2000/svg'
|
svg: 'http://www.w3.org/2000/svg'
|
||||||
}
|
}
|
||||||
// var doctype = '<!DOCTYPE svg:svg PUBLIC' +
|
|
||||||
// ' "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"' +
|
|
||||||
// ' "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
|
|
||||||
|
|
||||||
element.setAttribute('version', '1.1')
|
element.setAttribute('version', '1.1')
|
||||||
// removing attributes so they aren't doubled up
|
// removing attributes so they aren't doubled up
|
||||||
@@ -191,38 +158,12 @@ function setSVGStyle (svg, css) {
|
|||||||
styles[0].textContent = css
|
styles[0].textContent = css
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveForeignObjects (element) {
|
|
||||||
// return
|
|
||||||
// var children
|
|
||||||
// var textElement
|
|
||||||
// var textSpan
|
|
||||||
|
|
||||||
// if (element.tagName === 'foreignObject') {
|
|
||||||
// textElement = document.createElement('text')
|
|
||||||
// textSpan = document.createElement('tspan')
|
|
||||||
// textSpan.setAttribute(
|
|
||||||
// 'style'
|
|
||||||
// , 'font-size: 11.5pt; font-family: "sans-serif";'
|
|
||||||
// )
|
|
||||||
// textSpan.setAttribute('x', 0)
|
|
||||||
// textSpan.setAttribute('y', 14.5)
|
|
||||||
// textSpan.textContent = element.textContent
|
|
||||||
|
|
||||||
// textElement.appendChild(textSpan)
|
|
||||||
// element.parentElement.appendChild(textElement)
|
|
||||||
// element.parentElement.removeChild(element)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// The sandboxed function that's executed in-page by phantom
|
// The sandboxed function that's executed in-page by phantom
|
||||||
function executeInPage (data) {
|
function executeInPage (data) {
|
||||||
var xmlSerializer = new window.XMLSerializer()
|
var xmlSerializer = new window.XMLSerializer()
|
||||||
var contents = data.contents
|
var contents = data.contents
|
||||||
var sequenceConfig = JSON.stringify(data.sequenceConfig)
|
var sequenceConfig = JSON.stringify(data.sequenceConfig)
|
||||||
var ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1')
|
var ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1')
|
||||||
// var toRemove
|
|
||||||
// var el
|
|
||||||
// var elContent
|
|
||||||
var svg
|
var svg
|
||||||
var svgValue
|
var svgValue
|
||||||
var boundingBox
|
var boundingBox
|
||||||
@@ -286,6 +227,5 @@ function executeInPage (data) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
svgValue = xmlSerializer.serializeToString(svg) + '\n'
|
svgValue = xmlSerializer.serializeToString(svg) + '\n'
|
||||||
// console.log('confWidth: '+document.head.outerHTML);
|
|
||||||
return svgValue
|
return svgValue
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user