"undefined"!=typeof d3&&!function(){DtdDiagram=function(e){var n=this;DtdDiagram.diagrams.push(n),n.opts=e||{},t.then(function(){return n.initialize()}).then(function(){return n.update(n.root)})["catch"](function(t){console.error(t.stack)})},DtdDiagram.diagrams=[],DtdDiagram.auto_start=!0;var t=DtdDiagram.document_ready=new Promise(function(t){document.addEventListener("DOMContentLoaded",t)});t.then(function(){DtdDiagram.auto_start&&0==DtdDiagram.diagrams.length&&new DtdDiagram});var e=20;DtdDiagram.default_options={dtd_json_file:"dtd.json",root_element:null,tag_doc_base:"doc/#p=",tag_doc_url:function(t){var e=t.type,n=t.name;return"other"==e||"element"==e&&n.startsWith("mml:")&&"mml:math"!=n?null:t.diagram.tag_doc_base+("attribute"==e?"attr-":"elem-")+n.replace(":","_")},min_canvas_width:800,min_canvas_height:400,group_separation:1.4,duration:500,rebase_handler:null},DtdDiagram.prototype.initialize=function(){var t=this;t.last_id=0;var n=t.opts,a=n.container||"dtd-diagram",r=t.container_dom="string"==typeof a?document.getElementById(a):a;if(!r)return void console.error("Something wrong with the specifier for the diagram's DOM element");var i=t.container_d3=d3.select(r),o=r.getAttribute("data-options"),d=o?JSON.parse(o):{};DtdDiagram.extend(t,DtdDiagram.default_options,d,n);var s=t.min_canvas_width,c=t.min_canvas_height;i.style({width:s+e+"px",height:c+e+"px"});var l=t.svg=i.append("svg"),h=l.append("defs");h.append("defs").html(' '),h.append("defs").html(' '),h.append("defs").html(' '),h.append("defs").html(' ');var u=t.canvas=new DtdDiagram.Box(-c/2,0,c/2,s);l.attr({xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",width:u.width(),height:u.height()}),t.svg_g=l.append("g").attr({transform:"translate(0, "+-u.top+")"});t.engine=d3.layout.flextree().nodeSize(function(t){return[DtdDiagram.Node.node_height,t.y_size()]}).separation(function(e,n){var a=e.elem_parent==n.elem_parent?1:t.group_separation;return a}),t.diagonal=d3.svg.diagonal().source(function(t,e){var n=t.source;t.target;return{x:n.x+(n.has_content()&&"attribute"==t.target.type?-6:n.has_attributes()&&"attribute"!=t.target.type?6:0),y:n.y+n.width()}}).projection(function(t){return[t.y,t.x]});return new Promise(function(e,n){var a=t.dtd_json_file;d3.json(a,function(r,i){if(r)n(new Error("Error reading DTD file '"+a+"': "+r.statusText));else{t.dtd_json=i;try{t.initialize_root(),e()}catch(o){n(o)}}})})},DtdDiagram.prototype.initialize_root=function(){var t=this,e=t.root_element;if(e&&!t.dtd_json.elements[e])throw t.root=null,new Error("Can't find a declaration for element "+e+" in the DTD.");var n=t.root=DtdDiagram.Node.factory(t,{name:e||t.dtd_json.root,type:"element"},null);t.root.x0=0,t.root.y0=0,n.expand()};var n=DtdDiagram.transition_promise=function(t){var e=0;return new Promise(function(n,a){t.empty()?n():t.each(function(){++e}).each("end",function(){--e||n()})})};DtdDiagram.prototype.rebase=function(t){var e,n=this;null==t||"string"==typeof t?(n.root_element=t,n.initialize_root(),e=n.root):(e=n.root=t,e.redraw=!0,e.q=null,delete e._width),n.update(t)},DtdDiagram.prototype.update=function(t){var e=this;e.src_node=t;var a=[],r=e.engine,i=r.nodes(e.root);DtdDiagram.Node.start_update(e,i),e.nodes_enter.each(function(t){t.draw_enter(this)}),e.nodes_update.each(function(t){a.push(t.transition_update())}),e.nodes_exit.each(function(t){a.push(t.transition_exit())});var o=r.links(i),d=e.svg_g.selectAll("path.link").data(o,function(t){return t.target.id}),s={x:t.x0,y:t.y0,width:function(){return 0},has_content:function(){return!1},has_attributes:function(){return!1}},c=e.diagonal;d.enter().insert("path","g").attr("class","link").attr("d",function(t){return c({source:s,target:s})});var l=e.duration;a.push(n(d.transition().duration(l).attr("d",c))),a.push(n(d.exit().transition().duration(l).attr("d",function(t){return c({source:s,target:s})}).remove()));var h=DtdDiagram.Canvas;a.push(DtdDiagram.Canvas.scroll_resize(e)),e.canvas=e.new_canvas.copy(),Promise.all(a).then(function(t){h.finish(e)},function(t){console.error("Problem during transistions: "+t.stack)}),i.forEach(function(t){t.x0=t.x,t.y0=t.y})},DtdDiagram.extend=function(){for(var t=arguments[0],e=1;er;++r)n+=e("M",0,0)+a(d,t+2*r*Math.PI/5);return n}(),c=2.3,l=Math.PI/3,h=-c*Math.sin(l),u=-c*(1+Math.cos(l)),f=2,p=e("M",h,u)+n(c,-h,-u,1)+e("l",0,f)+"m 0,3 "+n(.5,1e-4,0,1)+"z";DtdDiagram.HasQNode={initialize:function(){"q"in this||(this.q=null)},has_q:function(){return!!this.q},q_width:function(){return this.has_q()?r:0},draw_enter_q:function(t){var e=this;if(e.has_q()){var n=e.q,a="*"==n?s:"+"==n?o:p;e.gs.append("g").attr("transform","translate("+t+",0)").append("path").attr({"class":"q",d:a})}}}}(),"undefined"!=typeof DtdDiagram&&!function(){var t=DtdDiagram.Node,e=DtdDiagram.HasLabelNode,n=DtdDiagram.HasQNode,a=15,r=DtdDiagram.ElementNode=function(){};t.register("element",r),r.content_click_handler=function(t){t.toggle_content(),t.diagram.update(t)},r.attributes_click_handler=function(t){t.toggle_attributes(),t.diagram.update(t)},r.rebase_click_handler=function(t){"function"==typeof t.diagram.rebase_handler&&t.diagram.rebase_handler(t),t.content_expanded||t.attributes_expanded||(t.expand_content(),t.expand_attributes()),t.diagram.rebase(t)},DtdDiagram.extend(r.prototype,t.methods,e,n,{initialize:function(){var e=this,a=e.diagram;n.initialize.call(e),e.content=null,e.content_expanded=!1,e.attributes_expanded=!1;var r=e.declaration=a.dtd_json.elements[e.name];"object"!=typeof r&&(console.error("Can't find a declaration for element "+e.name+" in the DTD."),r=e.declaration=null);var i=e.attributes=[];r&&r.attributes&&r.attributes.forEach(function(n){i.push(t.factory(a,n,e))})},init_content:function(){var e=this,n=e.diagram,a=e.declaration,r=e.content=[];a&&a.content&&a.content.children&&a.content.children.forEach(function(a){r.push(t.factory(n,a,e))})},get_content:function(){return null==this.content&&this.init_content(),this.content},has_content:function(){return null==this.content&&this.init_content(),this.content.length>0},has_attributes:function(){return this.attributes.length>0},toggle_content:function(){this.content_expanded=!this.content_expanded,this.set_children()},expand_content:function(){this.content_expanded=!0,this.set_children()},toggle_attributes:function(){this.attributes_expanded=!this.attributes_expanded,this.set_children()},expand_attributes:function(){this.attributes_expanded=!0,this.set_children()},expand:function(){this.content_expanded=this.attributes_expanded=!0,this.set_children()},set_children:function(){var t=this.content_expanded,e=this.attributes_expanded;t||e?!t&&e?this.children=this.attributes:t&&!e?this.children=this.get_content():this.children=this.attributes.concat(this.get_content()):this.children=[],this.gs&&(this.gs.select(".cb rect").attr("class",t?"expanded":"collapsed"),this.gs.select(".ab rect").attr("class",e?"expanded":"collapsed"))},compute_width:function(){return this.q_width()+(this.has_content()||this.has_attributes()?a:0)+this.label_width()},draw_enter:function(){var e=this,n=(e.diagram,e.gs),a=t.node_box_height;n.append("rect").attr({"data-id":e.id,"class":"box",width:e.width(),height:a,y:-a/2,rx:6,ry:6}),e.draw_enter_label(),e.draw_enter_q(t.node_text_margin),e.has_content()&&e.draw_button("cb",e.has_attributes()?a/4-.5:0,r.content_click_handler),e.has_attributes()&&e.draw_button("ab",e.has_content()?-a/4+.5:0,r.attributes_click_handler);var i=n.append("g").attr({"class":"button rebase",transform:"translate(2, -16)"});i.append("rect").attr({"class":"collapsed",width:10,height:5,x:0,y:0,rx:2.5,ry:2.5,transform:"translate(0,5)"}).on("click",r.rebase_click_handler)},draw_button:function(e,n,r){var i=this,o=(i.diagram,i.gs),d=t.node_box_height,s=i.width(),c=o.append("g").attr({"class":"button "+e,transform:"translate("+(s-a-2)+","+(n+d/4-16.2)+")"}),l="cb"==e?i.content_expanded:i.attributes_expanded,h=l?"expanded":"collapsed";c.append("rect").attr({"class":h,width:15,height:10,x:0,y:0,rx:5,ry:5,transform:"translate(0,5)"}).on("click",r),"cb"==e?c.append("g").attr("transform","translate(-0.56249982,0)").attr("pointer-events","none").html(' '):c.append("path").attr("pointer-events","none").attr("d","m 8.136125,11.77975 c -5.6e-6,-0.07466 0.00466,-0.139997 0.014,-0.196 -0.3546719,0.550669 -0.9006713,0.826002 -1.638,0.826 -0.4480035,2e-6 -0.8120031,-0.149331 -1.092,-0.448 -0.2706692,-0.307997 -0.4060024,-0.704663 -0.406,-1.19 -2.4e-6,-0.8493287 0.3079973,-1.5959946 0.924,-2.24 0.615996,-0.6533266 1.3299953,-0.979993 2.142,-0.98 0.186661,7e-6 0.3919941,0.028007 0.616,0.084 l 0.28,0.07 c 0.037327,0.018674 0.083994,0.028007 0.14,0.028 0.04666,6.9e-6 0.1259933,-0.023326 0.238,-0.07 0.1493264,-0.065326 0.2566596,-0.097993 0.322,-0.098 0.1399928,7e-6 0.2099927,0.060674 0.21,0.182 -7.3e-6,0.028007 -0.00934,0.07934 -0.028,0.154 l -0.07,0.266 -0.798,2.982 c -0.028006,0.112003 -0.042006,0.20067 -0.042,0.266 -6.4e-6,0.168003 0.08866,0.252003 0.266,0.252 0.3453264,3e-6 0.667326,-0.223997 0.966,-0.672 0.419992,-0.625329 0.629992,-1.3486617 0.63,-2.17 -8e-6,-0.7746601 -0.256675,-1.4186595 -0.77,-1.932 -0.504007,-0.5133251 -1.1433397,-0.7699915 -1.918,-0.77 -1.0920045,8.5e-6 -2.0440035,0.4386747 -2.856,1.316 -0.8026686,0.8680063 -1.2040015,1.8900053 -1.204,3.066 -1.5e-6,0.91467 0.2939982,1.680002 0.882,2.296 0.587997,0.606668 1.3253296,0.910001 2.212,0.91 0.5226616,10e-7 0.9519945,-0.06067 1.288,-0.182 0.3453271,-0.130665 0.77466,-0.382665 1.288,-0.756 0.1866593,-0.139998 0.340659,-0.209998 0.462,-0.21 0.177326,2e-6 0.265992,0.084 0.266,0.252 -8e-6,0.177335 -0.121341,0.359335 -0.364,0.546 -0.9240066,0.728001 -1.9413389,1.092 -3.052,1.092 -1.1293367,0 -2.0720024,-0.373333 -2.828,-1.12 -0.7466676,-0.755998 -1.1200005,-1.698664 -1.12,-2.828 -5e-7,-1.3626612 0.503999,-2.5479934 1.512,-3.556 1.0173303,-1.0173247 2.2166624,-1.5259908 3.598,-1.526 1.0453267,9.2e-6 1.894659,0.3080089 2.548,0.924 0.662658,0.6160076 0.993991,1.4186735 0.994,2.408 -9e-6,1.1106714 -0.406009,2.081337 -1.218,2.912 -0.494674,0.504002 -1.0126736,0.756002 -1.554,0.756 -0.2426728,2e-6 -0.4433393,-0.06066 -0.602,-0.182 -0.1586723,-0.121331 -0.2380056,-0.275331 -0.238,-0.462 m 0.294,-1.904 0.378,-1.4 c -0.2800059,-0.1399937 -0.5506723,-0.2099937 -0.812,-0.21 -0.5413382,6.3e-6 -1.0173377,0.2380061 -1.428,0.714 -0.4013369,0.4760051 -0.6020034,1.031338 -0.602,1.666 -3.4e-6,0.644003 0.2799963,0.966003 0.84,0.966 0.7746617,3e-6 1.3159945,-0.578663 1.624,-1.736")},transition_update:function(){this.redraw&&(this.gs.html(""),this.draw_enter(),this.redraw=!1),t.methods.transition_update.call(this)}})}(),"undefined"!=typeof DtdDiagram&&!function(){var t=DtdDiagram.Node,e=21,n=DtdDiagram.AttributeNode=function(){};t.register("attribute",n),DtdDiagram.extend(n.prototype,t.methods,DtdDiagram.HasLabelNode,{draw_enter:function(){var t=this;t.gs.append("ellipse").attr({"data-id":t.id,"class":"box",cx:t.width()/2,cy:0,rx:t.width()/2,ry:e/2}),t.draw_enter_label()}})}(),"undefined"!=typeof DtdDiagram&&!function(){var t=DtdDiagram.Node,e=DtdDiagram.HasQNode,n=20,a="0,0 "+n/2+","+-n/2+" "+n+",0 "+n/2+","+n/2,r=DtdDiagram.ChoiceNode=function(){};t.register("choice",r),DtdDiagram.extend(r.prototype,t.methods,e,{initialize:function(){var n=this;e.initialize.call(n),(n.spec.children||[]).forEach(function(e){n.children.push(t.factory(n.diagram,e,n.elem_parent))})},width:function(){return n},draw_enter:function(){this.gs.append("polygon").attr({"class":"choice",points:a}),this.draw_enter_q(n/2)}})}(),"undefined"!=typeof DtdDiagram&&!function(){var t=DtdDiagram.Node,e=DtdDiagram.HasQNode,n=t.path,a=t.arc,r=13,i=8,o=n("M",0,i/2,"v",-i)+a(r/2,r,0)+n("v",i)+a(r/2,-r,0)+"z",d=DtdDiagram.SeqNode=function(){};t.register("seq",d),DtdDiagram.extend(d.prototype,t.methods,e,{initialize:function(){var n=this;e.initialize.call(n),(n.spec.children||[]).forEach(function(e){n.children.push(t.factory(n.diagram,e,n.elem_parent))})},width:function(){return r},draw_enter:function(){this.gs.append("path").attr({"class":"seq",d:o}),this.draw_enter_q(r/2)}})}(),"undefined"!=typeof DtdDiagram&&!function(){var t=DtdDiagram.Node,e=18,n=DtdDiagram.OtherNode=function(){};t.register("other",n),DtdDiagram.extend(n.prototype,t.methods,DtdDiagram.HasLabelNode,{draw_enter:function(){var t=this;t.gs.append("g").attr("transform","skewX(-15)").append("rect").attr({"data-id":t.id,"class":"box",width:t.width(),height:e,y:-e/2,rx:3,ry:3}),t.draw_enter_label()}})}(),"undefined"!=typeof DtdDiagram&&!function(){function t(t){var e=t.container_dom,n=t.new_canvas,a=n.width(),r=n.height();t.svg.style({width:a,height:r}),e.style.display="none",e.style.display="block"}function e(t,e){return function(){var n=d3.interpolateNumber(this.scrollTop,t),a=d3.interpolateNumber(this.scrollLeft,e);return function(t){this.scrollTop=n(t),this.scrollLeft=a(t)}}}function n(n){var a=n.new_viewport,r=n.container_dom;return n.embiggenning&&t(n),new_scroll_top=a.top-n.new_canvas.top,new_scroll_left=a.left,new Promise(function(t,a){r.scrollTop!=new_scroll_top||r.scrollLeft!=new_scroll_left?n.container_d3.transition().duration(n.duration).tween("uniquetweenname1",e(new_scroll_top,new_scroll_left)).each("end",function(){t("done scroll_canvas to "+new_scroll_top+", "+new_scroll_left)}):t("scroll_canvas: nothing to do")})}var a=DtdDiagram.Canvas={dropshadow_margin:5};a.scroll_resize=function(t){return r(t),Promise.all([n(t),new Promise(function(e,n){t.svg_g.transition().duration(t.duration).attr({transform:"translate(0, "+-t.new_canvas.top+")"}).each("end",function(){e("done transitioning svg coordinates")})})])},a.finish=function(e){e.embiggenning||t(e)};var r=function(t){var e=DtdDiagram.Box,n=t.root,r=t.min_canvas_height,i=t.min_canvas_width,o=t.src_node,d=t.canvas,s=t.new_drawing=n.tree_extents();s.bottom+=a.dropshadow_margin;var c=s.height()>=r?s.top:(s.bottom+s.top-r)/2,l=s.height()>=r?s.bottom:c+r,h=t.new_canvas=new e(c,s.left,l,s.width()>=i?s.right:s.left+i),u=o.extents(),f=o.tree_extents(),p=f.copy();if(p.width()>i&&(p.right=p.left+i),p.height()>r){var g=p.vcenter(),_=g-r/2,m=g+r/2,D=u.top<_?u.top-_:u.bottom>m?u.bottom-m:0;p.top=_+D,p.bottom=m+D}var v=t.container_dom,w=v.scrollTop,x=v.scrollLeft,y=t.viewport=new e(w+d.top,x,w+d.top+r,x+i),b=t.new_viewport=y.copy();b.vmove(p.topb.bottom?p.bottom-b.bottom:0),b.vmove(h.top>b.top?h.top-b.top:h.bottomb.right?p.right-b.right:0),b.hmove(h.left>b.left?h.left-b.left:h.rightd.width()||h.height()>d.height()}}();