mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
var parser=function(){function t(){this.yy={}}var e=function(t,e,s,i){for(s=s||{},i=t.length;i--;s[t[i]]=e);return s},s=[1,3],i=[1,7],r=[1,8],n=[8,12,24],a=[1,24],o=[8,19,21,23],l=[1,48],h=[1,43],c=[1,49],y=[1,45],u=[1,44],d=[1,46],p=[1,47],f=[1,53],g=[8,29],m=[6,8,15,17,24,29,31,32,33],_={trace:function(){},yy:{},symbols_:{error:2,expressions:3,graph:4,EOF:5,SPACE:6,edge:7,";":8,styleStatement:9,vertex:10,link:11,PIPE:12,text:13,STYLE:14,ALPHA:15,stylesOpt:16,HEX:17,SQS:18,SQE:19,PS:20,PE:21,DIAMOND_START:22,DIAMOND_STOP:23,MINUS:24,ARROW_POINT:25,ARROW_CIRCLE:26,ARROW_CROSS:27,style:28,COMMA:29,styleComponent:30,COLON:31,NUM:32,UNIT:33,colordef:34,COLOR:35,borderWidth:36,borderStyle:37,BORDER_STYLE:38,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",6:"SPACE",8:";",12:"PIPE",14:"STYLE",15:"ALPHA",17:"HEX",18:"SQS",19:"SQE",20:"PS",21:"PE",22:"DIAMOND_START",23:"DIAMOND_STOP",24:"MINUS",25:"ARROW_POINT",26:"ARROW_CIRCLE",27:"ARROW_CROSS",29:"COMMA",31:"COLON",32:"NUM",33:"UNIT",35:"COLOR",38:"BORDER_STYLE"},productions_:[0,[3,2],[4,2],[4,3],[4,2],[7,1],[7,5],[7,3],[7,1],[9,5],[9,5],[10,4],[10,4],[10,4],[10,1],[13,3],[13,3],[13,2],[13,1],[11,3],[11,3],[11,3],[11,3],[16,1],[16,3],[28,1],[28,2],[30,1],[30,1],[30,1],[30,1],[30,1],[30,1],[30,1],[34,1],[34,1],[36,2],[37,1]],performAction:function(t,e,s,i,r,n){var a=n.length-1;switch(r){case 1:return n[a-1];case 2:case 3:this.$=n[a];break;case 4:this.$=n[a-1];break;case 5:this.$="ya";break;case 6:i.addLink(n[a-4],n[a-2],n[a-3],n[a]),this.$="oy";break;case 7:i.addLink(n[a-2],n[a],n[a-1]),this.$="oy";break;case 8:this.$="yo";break;case 9:this.$=n[a-4],i.addVertex(n[a-2],void 0,void 0,n[a]);break;case 10:console.log("In parser - style: "+n[a]),this.$=n[a-4],i.updateLink(n[a-2],n[a]);break;case 11:this.$=n[a-3],i.addVertex(n[a-3],n[a-1],"square");break;case 12:this.$=n[a-3],i.addVertex(n[a-3],n[a-1],"round");break;case 13:this.$=n[a-3],i.addVertex(n[a-3],n[a-1],"diamond");break;case 14:this.$=n[a],i.addVertex(n[a]);break;case 15:this.$=n[a-2]+" "+n[a];break;case 16:this.$=n[a-2]+"-"+n[a];break;case 17:this.$=n[a-1];break;case 18:case 37:this.$=n[a];break;case 19:this.$={type:"arrow"};break;case 20:this.$={type:"arrow_circle"};break;case 21:this.$={type:"arrow_cross"};break;case 22:this.$={type:"arrow_open"};break;case 23:this.$=[n[a]];break;case 24:n[a-2].push(n[a]),this.$=n[a-2];break;case 25:this.$=n[a];break;case 26:this.$=n[a-1]+n[a];break;case 27:case 28:case 29:case 30:case 31:case 32:case 33:this.$=n[a];break;case 34:case 35:this.$=t;break;case 36:this.$=n[a-1]+""+n[a]}},table:[{3:1,4:2,6:s,7:4,9:5,10:6,14:i,15:r},{1:[3]},{5:[1,9]},{4:10,6:s,7:4,9:5,10:6,14:i,15:r},{8:[1,11]},{8:[2,5]},{8:[2,8],11:12,24:[1,13]},{6:[1,14]},e(n,[2,14],{18:[1,15],20:[1,16],22:[1,17]}),{1:[2,1]},{5:[2,2]},{4:18,5:[2,4],6:s,7:4,9:5,10:6,14:i,15:r},{10:19,15:r},{24:[1,20]},{15:[1,21],17:[1,22]},{13:23,15:a},{13:25,15:a},{13:26,15:a},{5:[2,3]},{8:[2,7],12:[1,27]},{24:[1,31],25:[1,28],26:[1,29],27:[1,30]},{6:[1,32]},{6:[1,33]},{19:[1,34]},e(o,[2,18],{6:[1,35],24:[1,36]}),{21:[1,37]},{23:[1,38]},{13:39,15:a},{15:[2,19]},{15:[2,20]},{15:[2,21]},{15:[2,22]},{6:l,15:h,16:40,17:c,24:y,28:41,30:42,31:u,32:d,33:p},{6:l,15:h,16:50,17:c,24:y,28:41,30:42,31:u,32:d,33:p},e(n,[2,11]),e(o,[2,17],{13:51,15:a}),{13:52,15:a},e(n,[2,12]),e(n,[2,13]),{8:[2,6]},{8:[2,9],29:f},e(g,[2,23],{30:54,6:l,15:h,17:c,24:y,31:u,32:d,33:p}),e(m,[2,25]),e(m,[2,27]),e(m,[2,28]),e(m,[2,29]),e(m,[2,30]),e(m,[2,31]),e(m,[2,32]),e(m,[2,33]),{8:[2,10],29:f},e(o,[2,15]),e(o,[2,16]),{6:l,15:h,17:c,24:y,28:55,30:42,31:u,32:d,33:p},e(m,[2,26]),e(g,[2,24],{30:54,6:l,15:h,17:c,24:y,31:u,32:d,33:p})],defaultActions:{5:[2,5],9:[2,1],10:[2,2],18:[2,3],28:[2,19],29:[2,20],30:[2,21],31:[2,22],39:[2,6]},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,i=[0],r=[null],n=[],a=this.table,o="",l=0,h=0,c=0,y=2,u=1,d=n.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;n.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,b,x,v,S,E,O,w,A,I={};;){if(x=i[i.length-1],this.defaultActions[x]?v=this.defaultActions[x]:((null===k||"undefined"==typeof k)&&(k=e()),v=a[x]&&a[x][k]),"undefined"==typeof v||!v.length||!v[0]){var $="";A=[];for(E in a[x])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: "+x+", token: "+k);switch(v[0]){case 1:i.push(k),r.push(p.yytext),n.push(p.yylloc),i.push(v[1]),k=null,b?(k=b,b=null):(h=p.yyleng,o=p.yytext,l=p.yylineno,m=p.yylloc,c>0&&c--);break;case 2:if(O=this.productions_[v[1]][1],I.$=r[r.length-O],I._$={first_line:n[n.length-(O||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(O||1)].first_column,last_column:n[n.length-1].last_column},_&&(I._$.range=[n[n.length-(O||1)].range[0],n[n.length-1].range[1]]),S=this.performAction.apply(I,[o,h,l,f.yy,v[1],r,n].concat(d)),"undefined"!=typeof S)return S;O&&(i=i.slice(0,-1*O*2),r=r.slice(0,-1*O),n=n.slice(0,-1*O)),i.push(this.productions_[v[1]][0]),r.push(I.$),n.push(I._$),w=a[i[i.length-2]][i[i.length-1]],i.push(w);break;case 3:return!0}}return!0}},k=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 i=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 r=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===i.length?this.yylloc.first_column:0)+i[i.length-s.length].length-s[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[r[0],r[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,i,r;if(this.options.backtrack_lexer&&(r={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&&(r.yylloc.range=this.yylloc.range.slice(0))),i=t[0].match(/(?:\r\n?|\n).*/g),i&&(this.yylineno+=i.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:i?i[i.length-1].length-i[i.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 n in r)this[n]=r[n];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var t,e,s,i;this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),n=0;n<r.length;n++)if(s=this._input.match(this.rules[r[n]]),s&&(!e||s[0].length>e[0].length)){if(e=s,i=n,this.options.backtrack_lexer){if(t=this.test_match(s,r[n]),t!==!1)return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?(t=this.test_match(e,r[i]),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,i){switch(s){case 0:return 14;case 1:return 17;case 2:return 32;case 3:return"BRKT";case 4:return 33;case 5:return 33;case 6:return 33;case 7:return 31;case 8:return 24;case 9:return 8;case 10:return 29;case 11:return 27;case 12:return 25;case 13:return 26;case 14:return 15;case 15:return 12;case 16:return 20;case 17:return 21;case 18:return 18;case 19:return 19;case 20:return 22;case 21:return 23;case 22:return 6;case 23:return"NEWLINE";case 24:return 5}},rules:[/^(?:style\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],inclusive:!0}}};return t}();return _.lexer=k,t.prototype=_,_.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,i){console.log("Got node "+t+" "+s+" "+e+" styles: "+JSON.stringify(i)),"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 i&&null!==i&&(console.log("Adding style: "+i),i.forEach(function(e){mermaid.vertices[t].styles.push(e)}))},getVertices:function(){return mermaid.vertices},addLink:function(t,e,s,i){var r={start:t,end:e,type:void 0,text:""};"undefined"!=typeof i&&(r.text=i),"undefined"!=typeof s&&(r.type=s.type),mermaid.edges.push(r)},updateLink:function(t,e){var s=t.substr(1);console.log("Got link style for "+s+" style "+e),mermaid.edges[s].style=e},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 i,r=t[s];console.log(r.styles.length);var n,a="";for(n=0;n<r.styles.length;n++)"undefined"!=typeof r.styles[n]&&(a=a+r.styles[n]+";");i=void 0===r.text?r.id:r.text,console.log('g.setNode("'+r.id+'", { label: "'+i+'" });'),"round"===r.type?e.setNode(r.id,{label:i,rx:5,ry:5,style:a}):"diamond"===r.type?e.setNode(r.id,{shape:"question",label:i,rx:0,ry:0,style:a}):e.setNode(r.id,{label:i,rx:0,ry:0,style:a})})},mermaid.addEdges=function(t,e){t.forEach(function(t){var s,i;s="undefined"==typeof t.type?"arrow":t.type,"undefined"==typeof t.style?i="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(),i=mermaid.graph.getEdges();console.log(i);var r=(Object.keys(s),(new dagreD3.graphlib.Graph).setGraph({marginx:20,marginy:20}).setDefaultEdgeLabel(function(){return{}}));console.log(r),this.addVertices(s,r),this.addEdges(i,r);var n=new dagreD3.render;n.shapes().question=function(t,e,s){var i=e.width,r=3*e.height,n=[{x:i/2,y:0},{x:i,y:-r/2},{x:i/2,y:-r},{x:0,y:-r/2}];return shapeSvg=t.insert("polygon",":first-child").attr("points",n.map(function(t){return t.x+","+t.y}).join(" ")).style("fill","#fff").style("stroke","#333").attr("rx",5).attr("ry",5).attr("transform","translate("+-i/2+","+2*r/4+")"),s.intersect=function(t){return dagreD3.intersect.polygon(s,n,t)},shapeSvg};var a=d3.select("#"+e);svgGroup=d3.select("#"+e+" g"),n(d3.select("#"+e+" g"),r);(a.attr("width")-r.graph().width)/2;a.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,r=t[i];s="mermaidChart"+e,e++;var n=r.textContent.trim();console.log(r),r.innerHTML='<svg id="'+s+'" width="100%"><g /></svg>',this.drawChart(n,s)}},mermaid.init(); |