mermaid/dist/mermaid.slim.min.js
2014-11-16 09:02:03 +01:00

1 line
16 KiB
JavaScript

var parser=function(){function t(){this.yy={}}var e=function(t,e,s,n){for(s=s||{},n=t.length;n--;s[t[n]]=e);return s},s=[1,7],n=[2,10],i=[1,14],r=[1,15],a=[1,11],o=[6,9],l=[11,26,27,36],h=[11,30,31,32,33],c=[11,18,21,23,30,31,32,33],y=[11,18,21,23,26,27,30,31,32,33],u=[26,27],d=[26,27,34],p=[1,43],f=[20,22,24,34],g=[1,64],m=[1,59],_=[1,62],k=[1,61],x=[1,65],b=[1,60],v=[1,63],S=[1,69],E=[11,40],I=[9,11,26,27,35,38,40,42,43],w={trace:function(){},yy:{},symbols_:{error:2,expressions:3,graphConfig:4,statements:5,EOF:6,spaceList:7,GRAPH:8,SPACE:9,DIR:10,SEMI:11,statement:12,verticeStatement:13,styleStatement:14,vertex:15,link:16,alphaNum:17,SQS:18,text:19,SQE:20,PS:21,PE:22,DIAMOND_START:23,DIAMOND_STOP:24,alphaNumToken:25,ALPHA:26,NUM:27,linkStatement:28,arrowText:29,ARROW_POINT:30,ARROW_CIRCLE:31,ARROW_CROSS:32,ARROW_OPEN:33,PIPE:34,MINUS:35,STYLE:36,stylesOpt:37,HEX:38,style:39,COMMA:40,styleComponent:41,COLON:42,UNIT:43,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",8:"GRAPH",9:"SPACE",10:"DIR",11:"SEMI",18:"SQS",20:"SQE",21:"PS",22:"PE",23:"DIAMOND_START",24:"DIAMOND_STOP",26:"ALPHA",27:"NUM",30:"ARROW_POINT",31:"ARROW_CIRCLE",32:"ARROW_CROSS",33:"ARROW_OPEN",34:"PIPE",35:"MINUS",36:"STYLE",38:"HEX",40:"COMMA",42:"COLON",43:"UNIT"},productions_:[0,[3,3],[3,4],[4,4],[5,3],[5,1],[7,2],[7,1],[12,2],[12,2],[13,0],[13,3],[13,1],[15,4],[15,4],[15,4],[15,1],[17,1],[17,2],[25,1],[25,1],[16,2],[16,1],[28,1],[28,1],[28,1],[28,1],[29,3],[19,3],[19,3],[19,2],[19,1],[14,5],[14,5],[37,1],[37,3],[39,1],[39,2],[41,1],[41,1],[41,1],[41,1],[41,1],[41,1],[41,1]],performAction:function(t,e,s,n,i,r){var a=r.length-1;switch(i){case 2:this.$=r[a-3];break;case 3:console.log("In graph config"),n.setDirection(r[a-1]),this.$=r[a-1];break;case 11:console.log("In vertexStatement"),n.addLink(r[a-2],r[a],r[a-1]),this.$="oy";break;case 12:console.log("In vertexStatement ... "),this.$="yo";break;case 13:this.$=r[a-3],n.addVertex(r[a-3],r[a-1],"square");break;case 14:this.$=r[a-3],n.addVertex(r[a-3],r[a-1],"round");break;case 15:this.$=r[a-3],n.addVertex(r[a-3],r[a-1],"diamond");break;case 16:console.log("In vertex"),this.$=r[a],n.addVertex(r[a]);break;case 17:case 19:case 20:case 36:this.$=r[a];break;case 18:this.$=r[a-1]+""+r[a];break;case 21:r[a-1].text=r[a],this.$=r[a-1];break;case 22:case 31:this.$=r[a];break;case 23:this.$={type:"arrow"};break;case 24:this.$={type:"arrow_circle"};break;case 25:this.$={type:"arrow_cross"};break;case 26:this.$={type:"arrow_open"};break;case 27:console.log("Nice link text here: "+r[a-1]),this.$=r[a-1];break;case 28:this.$=r[a-2]+" "+r[a];break;case 29:this.$=r[a-2]+"-"+r[a];break;case 30:this.$=r[a-1];break;case 32:this.$=r[a-4],n.addVertex(r[a-2],void 0,void 0,r[a]);break;case 33:console.log("In parser - style: "+r[a]),this.$=r[a-4],n.updateLink(r[a-2],r[a]);break;case 34:this.$=[r[a]];break;case 35:r[a-2].push(r[a]),this.$=r[a-2];break;case 37:this.$=r[a-1]+r[a];break;case 38:case 39:case 40:case 41:case 42:case 43:case 44:this.$=r[a]}},table:[{3:1,4:2,8:[1,3]},{1:[3]},{5:4,7:5,9:s,11:n,12:6,13:8,14:9,15:10,17:12,25:13,26:i,27:r,36:a},{9:[1,16]},{6:[1,17],7:18,9:s},{5:19,11:n,12:6,13:8,14:9,15:10,17:12,25:13,26:i,27:r,36:a},e(o,[2,5]),e(l,[2,7],{7:20,9:s}),{11:[1,21]},{11:[1,22]},{11:[2,12],16:23,28:24,30:[1,25],31:[1,26],32:[1,27],33:[1,28]},{9:[1,29]},e(h,[2,16],{18:[1,30],21:[1,31],23:[1,32]}),e(c,[2,17],{25:13,17:33,26:i,27:r}),e(y,[2,19]),e(y,[2,20]),{10:[1,34]},{1:[2,1]},{11:n,12:35,13:8,14:9,15:10,17:12,25:13,26:i,27:r,36:a},{6:[1,36],7:18,9:s},e(l,[2,6]),e(o,[2,8]),e(o,[2,9]),{15:37,17:12,25:13,26:i,27:r},e(u,[2,22],{29:38,34:[1,39]}),e(d,[2,23]),e(d,[2,24]),e(d,[2,25]),e(d,[2,26]),{26:[1,40],38:[1,41]},{19:42,26:p},{19:44,26:p},{19:45,26:p},e(c,[2,18]),{11:[1,46]},e(o,[2,4]),{1:[2,2]},{11:[2,11]},e(u,[2,21]),{19:47,26:p},{9:[1,48]},{9:[1,49]},{20:[1,50]},e(f,[2,31],{9:[1,51],35:[1,52]}),{22:[1,53]},{24:[1,54]},e([9,11,26,27,36],[2,3]),{34:[1,55]},{9:g,26:m,27:_,35:k,37:56,38:x,39:57,41:58,42:b,43:v},{9:g,26:m,27:_,35:k,37:66,38:x,39:57,41:58,42:b,43:v},e(h,[2,13]),e(f,[2,30],{19:67,26:p}),{19:68,26:p},e(h,[2,14]),e(h,[2,15]),e(u,[2,27]),{11:[2,32],40:S},e(E,[2,34],{41:70,9:g,26:m,27:_,35:k,38:x,42:b,43:v}),e(I,[2,36]),e(I,[2,38]),e(I,[2,39]),e(I,[2,40]),e(I,[2,41]),e(I,[2,42]),e(I,[2,43]),e(I,[2,44]),{11:[2,33],40:S},e(f,[2,28]),e(f,[2,29]),{9:g,26:m,27:_,35:k,38:x,39:71,41:58,42:b,43:v},e(I,[2,37]),e(E,[2,35],{41:70,9:g,26:m,27:_,35:k,38:x,42:b,43:v})],defaultActions:{17:[2,1],36:[2,2],37:[2,11]},parseError:function(t,e){if(!e.recoverable)throw new Error(t);this.trace(t)},parse:function(t){function e(){var t;return t=p.lex()||u,"number"!=typeof t&&(t=s.symbols_[t]||t),t}var s=this,n=[0],i=[null],r=[],a=this.table,o="",l=0,h=0,c=0,y=2,u=1,d=r.slice.call(arguments,1),p=Object.create(this.lexer),f={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(f.yy[g]=this.yy[g]);p.setInput(t,f.yy),f.yy.lexer=p,f.yy.parser=this,"undefined"==typeof p.yylloc&&(p.yylloc={});var m=p.yylloc;r.push(m);var _=p.options&&p.options.ranges;this.parseError="function"==typeof f.yy.parseError?f.yy.parseError:Object.getPrototypeOf(this).parseError;for(var k,x,b,v,S,E,I,w,A,O={};;){if(b=n[n.length-1],this.defaultActions[b]?v=this.defaultActions[b]:((null===k||"undefined"==typeof k)&&(k=e()),v=a[b]&&a[b][k]),"undefined"==typeof v||!v.length||!v[0]){var $="";A=[];for(E in a[b])this.terminals_[E]&&E>y&&A.push("'"+this.terminals_[E]+"'");$=p.showPosition?"Parse error on line "+(l+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[k]||k)+"'":"Parse error on line "+(l+1)+": Unexpected "+(k==u?"end of input":"'"+(this.terminals_[k]||k)+"'"),this.parseError($,{text:p.match,token:this.terminals_[k]||k,line:p.yylineno,loc:m,expected:A})}if(v[0]instanceof Array&&v.length>1)throw new Error("Parse Error: multiple actions possible at state: "+b+", token: "+k);switch(v[0]){case 1:n.push(k),i.push(p.yytext),r.push(p.yylloc),n.push(v[1]),k=null,x?(k=x,x=null):(h=p.yyleng,o=p.yytext,l=p.yylineno,m=p.yylloc,c>0&&c--);break;case 2:if(I=this.productions_[v[1]][1],O.$=i[i.length-I],O._$={first_line:r[r.length-(I||1)].first_line,last_line:r[r.length-1].last_line,first_column:r[r.length-(I||1)].first_column,last_column:r[r.length-1].last_column},_&&(O._$.range=[r[r.length-(I||1)].range[0],r[r.length-1].range[1]]),S=this.performAction.apply(O,[o,h,l,f.yy,v[1],i,r].concat(d)),"undefined"!=typeof S)return S;I&&(n=n.slice(0,-1*I*2),i=i.slice(0,-1*I),r=r.slice(0,-1*I)),n.push(this.productions_[v[1]][0]),i.push(O.$),r.push(O._$),w=a[n[n.length-2]][n[n.length-1]],n.push(w);break;case 3:return!0}}return!0}},A=function(){var t={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t;var e=t.match(/(?:\r\n?|\n).*/g);return e?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,s=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var n=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),s.length-1&&(this.yylineno-=s.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:s?(s.length===n.length?this.yylloc.first_column:0)+n[n.length-s.length].length-s[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var s,n,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),n=t[0].match(/(?:\r\n?|\n).*/g),n&&(this.yylineno+=n.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:n?n[n.length-1].length-n[n.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],s=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),s)return s;if(this._backtrack){for(var r in i)this[r]=i[r];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var t,e,s,n;this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),r=0;r<i.length;r++)if(s=this._input.match(this.rules[i[r]]),s&&(!e||s[0].length>e[0].length)){if(e=s,n=r,this.options.backtrack_lexer){if(t=this.test_match(s,i[r]),t!==!1)return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?(t=this.test_match(e,i[n]),t!==!1?t:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var t=this.next();return t?t:this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){var t=this.conditionStack.length-1;return t>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return t=this.conditionStack.length-1-Math.abs(t||0),t>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,s,n){switch(s){case 0:return 36;case 1:return 8;case 2:return 10;case 3:return 10;case 4:return 38;case 5:return 27;case 6:return"BRKT";case 7:return 43;case 8:return 43;case 9:return 43;case 10:return 42;case 11:return 11;case 12:return 40;case 13:return 32;case 14:return 30;case 15:return 31;case 16:return 33;case 17:return 26;case 18:return 34;case 19:return 21;case 20:return 22;case 21:return 18;case 22:return 20;case 23:return 23;case 24:return 24;case 25:return 9;case 26:return"NEWLINE";case 27:return 6}},rules:[/^(?:style\b)/,/^(?:graph\b)/,/^(?:LR\b)/,/^(?:TD\b)/,/^(?:#[a-f0-9]+)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?:px\b)/,/^(?:pt\b)/,/^(?:dot\b)/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:==[x])/,/^(?:==>)/,/^(?:==[o])/,/^(?:===)/,/^(?:[a-zåäöæøA-ZÅÄÖÆØ\-]+)/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\s)/,/^(?:\n)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],inclusive:!0}}};return t}();return w.lexer=A,t.prototype=w,w.Parser=t,new t}();"undefined"!=typeof require&&"undefined"!=typeof exports&&(exports.parser=parser,exports.Parser=parser.Parser,exports.parse=function(){return parser.parse.apply(parser,arguments)},exports.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var e=require("fs").readFileSync(require("path").normalize(t[1]),"utf8");return exports.parser.parse(e)},"undefined"!=typeof module&&require.main===module&&exports.main(process.argv.slice(1)));var mermaid;"undefined"==typeof mermaid&&(mermaid={}),mermaid.vertices={},mermaid.edges=[],mermaid.graph={addVertex:function(t,e,s,n){console.log("Got node "+t+" "+s+" "+e+" styles: "+JSON.stringify(n)),"undefined"==typeof mermaid.vertices[t]&&(mermaid.vertices[t]={id:t,styles:[]}),"undefined"!=typeof e&&(mermaid.vertices[t].text=e),"undefined"!=typeof s&&(mermaid.vertices[t].type=s),"undefined"!=typeof n&&null!==n&&(console.log("Adding style: "+n),n.forEach(function(e){mermaid.vertices[t].styles.push(e)}))},getVertices:function(){return mermaid.vertices},addLink:function(t,e,s,n){var i={start:t,end:e,type:void 0,text:""},n=s.text;"undefined"!=typeof n&&(i.text=n),"undefined"!=typeof s&&(i.type=s.type),mermaid.edges.push(i)},updateLink:function(t,e){var s=t.substr(1);console.log("Got link style for "+s+" style "+e),mermaid.edges[s].style=e},setDirection:function(t){mermaid.direction=t},getEdges:function(){return mermaid.edges},clear:function(){mermaid.vertices={},mermaid.edges=[]},defaultStyle:function(){return"fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;"}};var mermaid;"undefined"==typeof mermaid&&(mermaid={}),mermaid.addVertices=function(t,e){var s=Object.keys(t);s.forEach(function(s){var n,i=t[s];console.log(i.styles.length);var r,a="";for(r=0;r<i.styles.length;r++)"undefined"!=typeof i.styles[r]&&(a=a+i.styles[r]+";");n=void 0===i.text?i.id:i.text,console.log('g.setNode("'+i.id+'", { label: "'+n+'" });'),"round"===i.type?e.setNode(i.id,{label:n,rx:5,ry:5,style:a}):"diamond"===i.type?e.setNode(i.id,{shape:"question",label:n,rx:0,ry:0,style:a}):e.setNode(i.id,{label:n,rx:0,ry:0,style:a})})},mermaid.addEdges=function(t,e){t.forEach(function(t){var s,n;s="undefined"==typeof t.type?"arrow":t.type,"undefined"==typeof t.style?n="arrow":s=t.type;"undefined"===t.text?"undefined"==typeof t.style?e.setEdge(t.start,t.end,{arrowheadStyle:"fill: #333"}):e.setEdge(t.start,t.end,{style:t.style,arrowheadStyle:"fill: #333"}):"undefined"==typeof t.style?e.setEdge(t.start,t.end,{label:t.text,arrowheadStyle:"fill: #333"}):e.setEdge(t.start,t.end,{style:t.style,arrowheadStyle:"fill: #333",label:t.text}),console.log('g.setEdge("'+t.start+'","'+t.end+'") ---')})},mermaid.drawChart=function(t,e){console.log("drawing char with id:"+e),console.log(t),mermaid.graph.clear(),parser.yy=mermaid.graph;parser.parse(t);var s=mermaid.graph.getVertices(),n=mermaid.graph.getEdges();console.log(n);{var i;Object.keys(s)}i=mermaid.direction,"undefined"==typeof i&&(i="TD");var r=(new dagreD3.graphlib.Graph).setGraph({rankdir:i,marginx:20,marginy:20}).setDefaultEdgeLabel(function(){return{}});console.log(r),this.addVertices(s,r),this.addEdges(n,r);var a=new dagreD3.render;a.shapes().question=function(t,e,s){var n=e.width,i=3*e.height,r=[{x:n/2,y:0},{x:n,y:-i/2},{x:n/2,y:-i},{x:0,y:-i/2}];return shapeSvg=t.insert("polygon",":first-child").attr("points",r.map(function(t){return t.x+","+t.y}).join(" ")).style("fill","#fff").style("stroke","#333").attr("rx",5).attr("ry",5).attr("transform","translate("+-n/2+","+2*i/4+")"),s.intersect=function(t){return dagreD3.intersect.polygon(s,r,t)},shapeSvg};var o=d3.select("#"+e);svgGroup=d3.select("#"+e+" g"),a(d3.select("#"+e+" g"),r);(o.attr("width")-r.graph().width)/2;o.attr("height",r.graph().height+40)},mermaid.init=function(){var t=document.querySelectorAll(".mermaid"),e=0;for(i=0;i<t.length;i++){var s,n=t[i];s="mermaidChart"+e,e++;var r=n.textContent.trim();console.log(n),n.innerHTML='<svg id="'+s+'" width="100%"><g /></svg>',this.drawChart(r,s)}},mermaid.init();