/*! * ZUI: ZUI FlowChart View - v1.10.0 - 2022-06-09 * http://openzui.com * GitHub: https://github.com/easysoft/zui.git * Copyright (c) 2022 cnezsoft.com; Licensed MIT */ !function(){"use strict";var t="function";Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(t){var e=this.length,o=Number(arguments[1]);for(isNaN(o)?o=e-1:(o=o<0?Math.ceil(o):Math.floor(o),o<0?o+=e:o>=e&&(o=e-1));o>-1;o--)if(o in this&&this[o]===t)return o;return-1}),Array.prototype.every||(Array.prototype.every=function(e){var o=this.length;if(typeof e!=t)throw new TypeError;for(var r=arguments[1],i=0;i>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;i>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;i-1)throw new Error('FlowChart: Do not allow ":" in element id "'+o+'".');if(o.indexOf(".")>-1)throw new Error('FlowChart: Do not allow "." in element id "'+o+'".');return o}return t.zui.uuid()},type:function(t,e){return e.name},text:function(t,o,r){return null===t&&(t="function"==typeof o.text?o.text(o,r):o.text),t===e||null===t?"":String(t)},order:function(t,o){return t===e?(o.isRelation?1e4:0)+u++:t},data:function(e,o,r){var i=t.extend({},e);return t.each(r,function(t,e){o.props[t]||(i[t]=e)}),i},style:"object",textStyle:"object",className:"string",visible:!1,$ele:!1,$text:!1,bounds:!1,elementType:!1,isRelation:!1,isNode:!1,flowChart:!1},y=t.extend({lineStyle:"string",lineWidth:"int",lineColor:"string",lineShape:"string",arrowSize:"int",position:function(e){return e&&"object"==typeof e&&e.shape&&"object"==typeof e.shape?t.extend({custom:!0},e):{}},from:function(t){return t&&(t=t.split(".")[0]),t},to:function(t){return t&&(t=t.split(".")[0]),t},fromPort:function(t,o,r){return t!==e&&null!==t&&t.length||!r.from||(t=r.from.split(".")[1]),t},toPort:function(t,o,r){return t!==e&&null!==t&&t.length||!r.to||(t=r.to.split(".")[1]),t},fromIndex:!1,toIndex:!1,fromNode:!1,toNode:!1,beginSideRels:!1,endSideRels:!1},g),v=t.extend({borderStyle:"string",borderWidth:"int",borderColor:"string",shapeStyle:"object",restPortsCounter:"object",position:function(e){return e&&"object"==typeof e&&(["left","top","centerLeft","centerTop","minHeight"].forEach(function(t){if("string"==typeof e[t]){var o=Number.parseInt(e[t]);Number.isNaN(o)||(e[t]=o)}}),"number"==typeof e.left&&"number"==typeof e.top||"number"==typeof e.centerLeft&&"number"==typeof e.centerTop||m[e.direction]&&"string"==typeof e.from)?t.extend({custom:!0},e):{}},hideArrowToSelf:"bool",width:"int",height:"int",maxWidth:"int",minWidth:"int",siblingsIndex:!1,fromRels:!1,toRels:!1,children:!1,parents:!1},g),w={top:1,bottom:1,left:1,right:1},b={top:3,bottom:3,left:1,right:1},x=[{from:"top1",to:"bottom1"},{from:"bottom1",to:"top1"},{from:"top1",to:"right1"},{from:"top1",to:"left1"},{from:"right1",to:"bottom1"},{from:"left1",to:"bottom1"}],C=[{from:"top3",to:"bottom3"},{from:"top2",to:"bottom2"},{from:"bottom2",to:"top2"},{from:"bottom1",to:"top1"},{from:"top3",to:"right1"},{from:"right1",to:"bottom3"},{from:"bottom1",to:"left1"},{from:"left1",to:"top1"},{from:"top2",to:"right1"},{from:"right1",to:"bottom2"},{from:"bottom2",to:"left1"},{from:"left1",to:"top2"}],E={relation:{props:y},rectangle:{shape:"rectangle",style:{borderRadius:"2px",borderStyle:"solid",borderWidth:1,borderColor:"#333"},textStyle:{lineHeight:1,minHeight:38,padding:6},props:v,ports:b,linkSelfPairs:C},box:{shape:"box",style:{borderRadius:"20px",borderStyle:"solid",borderWidth:1,borderColor:"#333"},textStyle:{lineHeight:1,minHeight:38,padding:6},props:v,ports:b,linkSelfPairs:C},diamond:{shape:"diamond",style:{borderWidth:0},textStyle:{lineHeight:1,minHeight:38,padding:"9px 20px"},shapeStyle:{fill:"#fff",strokeWidth:1,stroke:"#333"},props:v,ports:w},circle:{shape:"circle",minWidth:40,textStyle:{lineHeight:1,minHeight:38,padding:"6px 10px"},style:{borderRadius:"50%",borderStyle:"solid",borderWidth:1,borderColor:"#333",minWidth:40},props:v,ports:w,linkSelfPairs:x},connection:{minWidth:0,style:{padding:2},textStyle:{lineHeight:1,minHeight:12},shape:"connection",hideArrowToSelf:!0,props:v,quickAdd:!1,ports:w,linkSelfPairs:x},dot:{shape:"dot",width:16,height:16,shapeStyle:{borderRadius:"50%",borderStyle:"solid",borderWidth:1,borderColor:"#333",minWidth:0,minHeight:0,maxWidth:"none",maxHeight:"none",overflow:"visible"},props:t.extend({textPosition:"string"},v),ports:w,linkSelfPairs:x}},R={relation:{type:"relation"},action:{type:"rectangle"},start:{type:"box",beginType:!0},stop:{type:"box",endType:!0},judge:{type:"diamond"},result:{type:"circle"},connection:{type:"connection"},point:{type:"dot"}},T=function(o,r,i){"number"==typeof o?o={space:o}:"string"==typeof o&&(o={name:o}),t.extend(this,o),r=r||o.side,this.side=m[r]?r:"right",this.name=o.name,this.displayName,this.empty="string"!=typeof this.name||!this.name.length,this.direction="out"===o.direction?"out":"in"===o.direction?"in":"in-out",this.space=this.space===e?1:this.space,this.spaceBegin=o.spaceBegin||0,this.spaceEnd=o.spaceEnd||0,this.lineColor,this.lineWidth,this.lineStyle,this.lineLength,this.index=i,this.rest,this.maxLinkCount=this.rest?1:this.maxLinkCount?Math.max(1,this.maxLinkCount):1,this.free=!this.rest&&this.free!==!1,this.restMinIndex=this.restMinIndex===e?1:this.restMinIndex,this.restInitialCount=this.restInitialCount===e?1:this.restInitialCount};T.prototype.getMaxRestCount=function(){return this.rest===!0?Number.MAX_SAFE_INTEGER:this.rest&&"number"==typeof this.rest?this.rest:0},T.prototype.getRestNameRegex=function(){if(this.rest)return this._restNameRegex||(this._restNameRegex=new RegExp("^"+this.name.replace("*","(\\d+)")+"$")),this._restNameRegex},T.prototype.getRestPortIndex=function(t){var e=this.getRestNameRegex();if(e){var o=t.match(e)[1];if("string"==typeof o&&o.length)return o=Number.parseInt(o),Number.isNaN(o)?null:Math.max(0,o-this.restMinIndex)}},T.prototype.isMatchRestName=function(t){return!!this.rest&&this.getRestNameRegex().test(t)},T.prototype.getRestPortNameByIndex=function(t){return this.name.replace("*",t+this.restMinIndex)},T.prototype.getRestPortAt=function(t){return this.rest?this.getRestPortByName(this.getRestPortNameByIndex(t),t):null},T.prototype.getRestPortByName=function(t,e){if(this.isMatchRestName(t)){this._restPorts||(this._restPorts={});var o=this._restPorts[t];if(o)return o;var r=this.exportPort();return r.name=t,r.rest=!1,r._restPort=!0,r.maxLinkCount=1,e>=this.restMinIndex&&delete r.spaceBegin,o=new T(r),this._restPorts[t]=o,o}return null},T.prototype.exportPort=function(){var e={},o=this;return t.each(o,function(t){"_"!==t[0]&&(e[t]=o[t])}),e},T.createPortsMap=function(e){if(!e)return null;var o,r={$all:{},$free:[],$list:[],$rest:[]};return t.each(m,function(i){var n=e[i];if("number"==typeof n){for(var a=[],l=1;l<=n;++l)a.push(i+l);n=a}n&&!t.isArray(n)&&(n=[n]),n&&n.length&&(o=!0,r[i]=n.map(function(t,e){var o=new T(t,i,e);return o.empty||(r.$all[o.name]=o,r.$list.push(o),o.free&&r.$free.push(o),o.rest&&r.$rest.push(o)),o}))}),o?r:null};var S=function(e,o){t.extend(this,o.getElementData(e)),this.id,this.type,this.basicType,this.text,this.order,this.data,this.style,this.textStyle,this.className,this.visible,this.isRelation,this.isNode,this.flowChart,this.elementType,this.bounds=this.position?{left:this.position.left,top:this.position.top,minHeight:this.position.minHeight,shape:this.position.shape}:{},this.position,this.$ele,this.$text,this.lineStyle,this.lineWidth,this.lineColor,this.showTextOnSide,this.arrowSize,this.from,this.to,this.fromIndex,this.toIndex,this.fromNode,this.toNode,this.beginSideRels,this.endSideRels,this.shapeStyle,this.hideArrowToSelf,this.borderStyle,this.borderWidth,this.borderColor,this.width,this.maxWidth,this.minWidth,this.height,this.siblingsIndex,this.fromRels,this.toRels,this.children,this.parents};S.sort=function(t){return t.sort(function(t,e){return t.order-e.order})},S.prototype.exportData=function(){var o={},r=this;return t.each(r.elementType.props,function(t,i){if(i)if("position"===t){if(r.position.custom){var n=r.getBounds(),a=n.hasPosition?r.flowChart.options.exportDetailPosition?{left:n.left,top:n.top,right:n.right,bottom:n.bottom}:{left:n.left,top:n.top}:r.getPosition();n.minHeight&&(a.minHeight=n.minHeight),o[t]=a}}else{var l=r[t];l!==e&&(o[t]=l)}}),o},S.prototype.getBounds=function(){if(this._boundsCache)return this._boundsCache;var e=this.bounds,o=this.isNode&&"number"==typeof e.left&&"number"==typeof e.top,r=t.extend({hasPosition:o},e);return o&&(r.right=e.left+e.width,r.bottom=e.top+e.height,r.centerLeft=e.left+e.width/2,r.centerTop=e.top+e.height/2),this._boundsCache=r,r},S.prototype.changeType=function(t){var e=this;"string"==typeof t&&(t=e.flowChart.types[t]),t&&(e.type=t.name,e.basicType=t.type,e.isRelation=t.isRelation,e.isNode=t.isNode,e.elementType=t)},S.prototype.setBounds=function(o){var r=this,i=0,n=0,a=0,l=r.bounds;if("number"==typeof o.top&&(l.top=o.top,i+=1),"number"==typeof o.left&&(l.left=o.left,i+=2),"number"==typeof o.width&&o.width>=0&&(l.width=o.width,n+=1),"number"==typeof o.height&&o.height>=0&&(l.height=o.height,n+=2),"number"==typeof o.minHeight&&(l.minHeight=o.minHeight,n+=4),(3===i||7===i)&&3===n){var s=r.flowChart.bounds;s.left=Math.min(s.left,l.left),s.top=Math.min(s.top,l.top),s.width=Math.max(s.width,l.left+l.width),s.height=Math.max(l.minHeight||0,Math.max(s.height,l.top+l.height))}this.isRelation&&o.shape&&"object"==typeof o.shape&&(l.shape=t.extend({},l.shape,o.shape),t.each(l.shape,function(t){l.shape[t]&&a++}),a&&(r.position=r.position?t.extend(r.position,{custom:!0}):{custom:!0})),(r.isNode&&i||a)&&r.position.custom===e&&(r.position.custom=!0),(i||n||a)&&(r._boundsCache=null)},S.prototype.isIntersectWith=function(t){if(!this.isNode||!t.isNode)return!1;var e=this.getBounds(),o=t.getBounds();return!(o.righte.right||o.bottome.bottom)},S.prototype.initBeforeRender=function(){var t=this;t.isNode&&(delete t.siblingsIndex,t.fromRels=[],t.toRels=[],t.children=[],t.parents=[])},S.prototype.getFromNodeOfRelation=function(){var t=this;return!t.fromNode&&t.from&&(t.fromNode=t.flowChart.getElement(t.from)),t.fromNode},S.prototype.getToNodeOfRelation=function(){var t=this;return!t.toNode&&t.to&&(t.toNode=t.flowChart.getElement(t.to)),t.toNode},S.prototype.getPortsInfoOfRelation=function(){var o=this;if(o._relationPortsInfo===e){var r=o.getFromNodeOfRelation(),i=o.getToNodeOfRelation();if(r&&i){var n,l;if(o.fromPort&&(n=r.getPortByName(o.fromPort)),o.toPort&&(l=i.getPortByName(o.toPort)),o.flowChart.options.allowFreePorts&&!o.fromPort||!o.toPort){var s=r.getBounds(),h=i.getBounds(),p={left:(s.centerLeft+h.centerLeft)/2,top:(s.centerTop+h.centerTop)/2},f=function(e){var r,i=e.$ports.find(".flowchart-port-free"),n=Number.MAX_VALUE;if(i.length&&i.each(function(){var e=t(this),i=e.find(".flowchart-port-dot"),l=o.flowChart.getPositionOf(i,!0),s=a(l,p);s0),o.$text=d;var u=o.getFromNodeOfRelation(),m=o.getToNodeOfRelation(),g=o.isActive(),y=s(o.lineStyle,o.elementType.lineStyle,i.relationLineStyle),v=s(o.lineShape,o.elementType.lineShape,i.relationLineShape),w=g?i.activeColor:s(o.lineColor,o.elementType.lineColor,i.relationLineColor),b=s(o.lineWidth,o.elementType.lineWidth,i.relationLineWidth),x=s(o.showArrow,o.elementType.showArrow);x===e&&(x=!i.hideArrowToResult||"result"!==m.type);var C=s(o.arrowSize,o.elementType.arrowSize,i.relationArrowSize),E="begin"===x||"both"===x?C:0,R=x===!0||"end"===x||"both"===x?C:0,T=t.extend({},o.elementType.shapeStyle,o.shapeStyle);if(n.attr("data-shape",v),o.elementType.render){var S=t.extend({},i.relationStyle,o.elementType.style,o.style);return o.elementType.render.call(o,n,{style:S,shapeStyle:T,portsInfo:o.getPortsInfoOfRelation(),textStyle:f,lineStyle:y,isActive:g,lineSize:b,lineColor:w,beginArrow:E,endArrow:R,relation:o})}var P=o.getPortsInfoOfRelation(),N=u.$get('.flowchart-port[data-name="'+P.fromPort.name+'"]'),M=m.$get('.flowchart-port[data-name="'+P.toPort.name+'"]'),k=r.getPositionOf(N),A=r.getPositionOf(M),_=N.data("centerOffset"),I=M.data("centerOffset");k=l(k,_),A=l(A,I),k.top=Math.floor(k.top),k.left=Math.floor(k.left),A.top=Math.floor(A.top),A.left=Math.floor(A.left),o.setBounds({left:Math.min(k.left,A.left),top:Math.min(k.top,A.top),width:Math.max(b,Math.abs(k.left-A.left)),height:Math.max(b,Math.abs(k.top-A.top))});var L=o.getBounds(),D={left:k.left,top:k.top,offsetLeft:k.left-L.left,offsetTop:k.top-L.top,arrow:E,side:P.fromPort.side},B={left:A.left,top:A.top,offsetLeft:A.left-L.left,offsetTop:A.top-L.top,arrow:R,side:P.toPort.side},z=o.$get(".flowchart-relation-lines").empty();o.relationLineID="flowchart-"+r.id+"-line-"+o.id,r.drawRelationLine(o.relationLineID,D,B,{shapeStyle:T,style:y,width:b,color:w,shape:v,isActive:g,activeColor:i.activeColor,relation:o,className:"flowchart-relation-line"+(g?" flowchart-relation-line-active":""),bounds:L},z,d),n.css({top:L.top,left:L.left,width:L.width,height:L.height}),r.callCallback("onRenderRelation",[n,o])},S.prototype.getText=function(){var t=this.text;return this.elementType.textFormatter?t=this.elementType.textFormatter(t,this):(t===e&&(t=this.elementType.text),t=t===e||null===t?"":String(t)),t},S.prototype.appendRestPortHolder=function(t){var e=this.elementType.getPortByName(t);e&&this.restPortsCounter&&(this.restPortsCounter[e.name]=(this.restPortsCounter[e.name]||0)+1,this.freshRender())},S.prototype.deleteRestPort=function(t){for(var e=this,o=e.elementType.getPortByName(t),r=e.getRestPorts(o,!1),i=r.length-1;i>0;--i){var n=r[i];if(n.name===t)break;var a=e.getRelationsByPort(n.name);if(a&&a.length){var l=r[i-1];a.forEach(function(t){t.from===e.id&&t.fromPort===n.name?t.fromPort=l.name:t.to===e.id&&t.toPort===n.name&&(t.toPort=l.name)})}}e.restPortsCounter[o.name]-=1,e.freshRender()},S.prototype.getRelationsByPort=function(t){var e=this,o=[];return e.fromRels&&e.fromRels.length&&e.fromRels.forEach(function(e){e.fromPort&&e.fromPort===t&&o.push(e)}),e.toRels&&e.toRels.length&&e.toRels.forEach(function(e){e.toPort&&e.toPort===t&&o.push(e)}),o},S.prototype.getRestPorts=function(t,o){if("string"==typeof t&&(t=this.getPortByName(t)),t.rest){o===e&&(o=!0);var r=this;r.restPortsCounter||(r.restPortsCounter={}),r.restPortsCounter[t.name]||(r.restPortsCounter[t.name]=t.restInitialCount);var i={},n=r.restPortsCounter[t.name]-1;r.fromRels&&r.fromRels.length&&r.fromRels.forEach(function(e){if(e.fromPort&&t.isMatchRestName(e.fromPort)){for(var o=t.getRestPortIndex(e.fromPort);i[o];)o++;i[o]=1,n=Math.max(o,n),e.fromPort=t.getRestPortNameByIndex(o)}}),r.toRels&&r.toRels.length&&r.toRels.forEach(function(e){if(e.toPort&&t.isMatchRestName(e.toPort)){for(var o=t.getRestPortIndex(e.toPort);i[o];)o++;i[o]=1,n=Math.max(o,n),e.toPort=t.getRestPortNameByIndex(o)}}),r.restPortsCounter[t.name]=n+1;for(var a=[],l=0;l<=n;++l){var s=t.getRestPortAt(a.length);s._restHolder=!1,s._restIndex=a.length,a.push(s)}if(o&&n','
','
','
','
',r.linkSelf?'':"",""].join("")).appendTo(a)),o.$ports=l;var h={left:0,right:0,top:0,bottom:0},p=n.portSpaceSize||20,f={left:[],right:[],top:[],bottom:[]},d=function(t,e){var o={size:Math.floor(e.space*p),begin:Math.floor(e.spaceBegin*p),end:Math.floor(e.spaceEnd*p),offset:h[t],port:e};if(o.total=o.size+o.begin+o.end,h[t]+=o.total,f[t].push(o),e.empty)return void(o.empty=!0)},c=function(e,i,a,l){var h=a.port,p=a.size*l,f=a.begin*l,d=a.offset*l,c=s(h.lineLength,r.portLineLength,n.portLineLength),u=Math.max(1,s(h.lineWidth,r.portLineWidth,n.portLineWidth)),m=s(h.lineStyle,r.portLineStyle,n.portLineStyle),g=s(h.lineColor,r.portLineColor,n.portLineColor),y={},v={width:0,height:0},w={width:u+8,height:u+8},b={};"left"===i||"right"===i?(y.top=d+f,y.width=c+2*w.width,y.left="left"===i?0-y.width:0,y.height=p,c&&(v.top=Math.floor((p-u)/2),v["left"===i?"right":"left"]=0,v.width=c,v.borderBottomStyle=m,v.borderBottomWidth=u,v.borderBottomColor=g),w.top=Math.floor((p-w.height)/2),w[i]=y.width-c-w.width,b.top=p/2,b.left="left"===i?y.width-v.width:v.width):(y.left=d+f,y.height=c+2*w.width,y.top="top"===i?0-y.height:0,y.width=p,c&&(v.left=Math.floor((p-u)/2),v["top"===i?"bottom":"top"]=0,v.height=c,v.borderRightStyle=m,v.borderRightWidth=u,v.borderRightColor=g),w.left=Math.floor((p-w.width)/2),w[i]=y.height-c-w.height,b.top="top"===i?y.height-v.height:v.height,b.left=p/2);var x=e.find('.flowchart-port[data-id="'+o.id+'"]');x.length?x.attr({"data-name":h.name}).removeClass("flowchart-port-expired"):(x=t(n.portTemplate.format({id:o.id,name:h.name,side:i})),x.css(y).appendTo(e).attr("title",h.name)),c&&t('
').css(v).appendTo(x),x.data("centerOffset",b).toggleClass("flowchart-port-free",h.free).append(t('
').css(w)),x.toggleClass("flowchart-port-rest-holder",!!h._restHolder),x.toggleClass("flowchart-port-rest",!!h._restPort),h._restPort&&!h._restHolder&&x.toggleClass("flowchart-port-rest-empty",!o.getRelationsByPort(h.name).length)};t.each(h,function(t){var e=i[t];e&&e.forEach(function(e){return e.rest?o.getRestPorts(e).forEach(d.bind(null,t)):void d(t,e)})}),t.each(f,function(t){var o=l.find(".flowchart-ports-"+t),r=f[t];if(!r||!r.length)return void o.empty();o.find(".flowchart-port").addClass("flowchart-port-expired");var i=h[t],a=1;n.autoAdjustPortSpace&&("left"===t||"right"===t)&&e.minHeight>0&&i')}o.$ele=l,l.data(o.data),l.toggleClass("flowchart-has-ports",n.hasPorts()).toggleClass("flowchart-resizable",n.resizable).toggleClass("flowchart-active",a),t.each(this.getClassMap(),function(t,e){l.toggleClass(t,!!e)});var d=t.extend({},i.nodeTextStyle,n.textStyle,o.textStyle,{transform:"none",maxHeight:"none"}),c=l.find(".flowchart-text"),u=o.getText(),m="string"==typeof u&&u.length>0;c.css(d).text(m?u:" ").toggleClass("flowchart-has-text",m),o.$text=c,l.attr("title",u);var g=o.getBounds().minHeight||0,y=s(o.minWidth,n.minWidth,i.nodeMinWidth);l.css({maxHeight:Math.max(g,s(o.height,n.height,i.nodeHeight)),maxWidth:s(o.maxWidth,n.maxWidth,i.nodeMaxWidth),minWidth:y,minHeight:g,width:s(o.width,n.width),height:Math.max(g,s(o.height,n.height))});var v=t.extend({},i.nodeStyle,n.style,o.style),w=t.extend({background:i.nodeBackground},n.shapeStyle,o.shapeStyle,{borderStyle:o.borderStyle,borderWidth:o.borderWidth,borderColor:a?i.activeColor:o.borderColor});if(n.render)n.render.call(o,l,n,{style:v,shapeStyle:w,textStyle:d,text:u});else if(n.hasPorts()&&o.renderPorts({style:v,shapeStyle:w,textStyle:d,text:u,minHeight:g,minWidth:y}),"diamond"===n.shape){l.css(v);var b={width:l.outerWidth(),height:l.outerHeight()},x=l.children(".flowchart-shape,svg").first();x.length||(x=t('').appendTo(l));var C=x.children("polygon");a&&(w.borderWidth=2),C.css(p(w));var E=[[0,b.height/2],[b.width/2,0],[b.width,b.height/2],[b.width/2,b.height]],R=[];E.forEach(function(e){R.push(t.isArray(e)?e.join(","):e)}),C.attr("points",R.join(" ")),x.css(b).show()}else if("dot"===n.shape){l.css(t.extend(v,w));var T={position:"absolute"};"top"===o.textPosition?T.bottom="100%":T.top="100%",c.css(T)}else"connection"===n.shape?(u?c.css("position","relative"):(w.padding=0,c.css("position","absolute")),l.css(t.extend(v,w))):l.css(t.extend(v,w));r.callCallback("onRenderNode",[l,o]);var S=l.outerHeight(),P=l.outerWidth();o.setBounds({width:P,height:S});var N=c.outerHeight();if(i.autoScaleText){var M=S/N;M<1&&c.css({transform:"scale("+M+")"})}else c.css("max-height",S).toggleClass("flowchart-node-text-limit",S1?n.find(function(t){var e=i.getRelationsByPort(t.from),o=e.length&&e.find(function(e){return e.isLinkSelf()&&(t.from===e.fromPort&&t.to===e.toPort||t.to===e.fromPort&&t.from===e.toPort)});return!o}):n[0]}else if("number"==typeof t){var n=i.elementType.linkSelfPairs;t=n[t%n.length]}if(t){if(o!==e&&null!==o||(o=""),!r)if(i.flowChart.options.defaultCycleRelation)r=i.flowChart.options.defaultCycleRelation;else{var a=i.flowChart.findElementType(function(t){return t.cycle});a&&(r=a.name)}if(!r)return;var a=i.flowChart.getElementType(r);if(!a)return;i.flowChart.addRelation(i,t.from,i,t.to,o,r,{position:{shape:{arrX:2,arrY:2}}})}}};var P=function(e){t.isArray(e)?e.unshift(!0,this):e=[!0,this,e],t.extend.apply(null,e),this.isRelation="relation"===this.type,this.isNode=!this.isRelation,this.props,this.style,this.textStyle,this.shape,this.shapeStyle,this.hideArrowToSelf,this.height,this.maxWidth,this.minWidth,this.render,this.template,this.text,this.edit,this.desc,this.ports=T.createPortsMap(this.ports),this.resizable,this.linkSelf,this.cycle,this.linkSelfPairs};P.prototype.getPortByName=function(t,e){var o=this,r=o.ports;if(r){var i=r.$all[t];if(i)return i;if(r.$rest.length)for(var n=0;n').appendTo(h));var b="flowchart-canvas-"+s.id;if(w.attr("id",b).toggleClass("flowchart-allow-free-ports",!!p.allowFreePorts),s.$canvas=w,p.width!==e&&h.css("width",p.width),p.height!==e&&"auto"!==p.height&&h.css("height",p.height),s.draggableEnable=!!t.fn.draggable,s.draggableEnable){if(p.draggable&&p.readonly!==!0){var x=function(e){var o={},r=s._dragCtrlPoint.data("name");if("por"===r){o=t.extend({porX:0,porY:0},s._dragElement.getBounds().shape);var i=s._dragElement.position.porx,n=s._dragElement.position.pory;i&&(o.porX+=e.smallOffset.x/i),n&&(o.porY+=e.smallOffset.y/n)}else if("arr"===r){o=t.extend({arrX:0,arrY:0},s._dragElement.getBounds().shape);var a=s._dragElement.position.arcd,l=s._dragElement.position.acdd;o["x"===l?"arrX":"arrY"]+=e.smallOffset[l]/a}else{var h=t.extend({bboX:0,bboY:0,bcoX:0,bcoY:0,beoX:0,beoY:0},s._dragElement.getBounds().shape);o["b"+r+"oX"]=h["b"+r+"oX"]+e.smallOffset.x,o["b"+r+"oY"]=h["b"+r+"oY"]+e.smallOffset.y}s._dragElement.setBounds({shape:o}),s._dragElement.render()},C=function(t){var e=s._dragElement.getSize().height,o=e+t.smallOffset.y;s._dragElement.setBounds({minHeight:o,height:o}),s._dragElement.freshRender()};w.draggable({move:!1,container:"#"+b,selector:".flowchart-node,.flowchart-relation-line-ctrl-point,.flowchart-relation-text",stopPropagation:!0,drag:function(e){if(!s._dragElement){var o=t(e.element),i=o.data("id"),n=null;if(o.hasClass("flowchart-relation-text")?(i=o.closest(".flowchart-relation").data("id"),n=t(r.getElementById("flowchart-"+s.id+"-line-"+i)).find(".flowchart-relation-primary-ctrl-point"),n.length||(n=null)):t(e.event.target).hasClass("flowchart-resize-handler")?s._dragResizeHandler=o:n=o.hasClass("flowchart-relation-line-ctrl-point")?o:null,null===i)return!1;var a=s.getElement(i);a.isNode&&a.moveToTop(),s._dragCtrlPoint=n,s._dragElement=a}s._dragCtrlPoint?x(e):s._dragResizeHandler?C(e):s.setElementBounds(s._dragElement.id,e.pos)},finish:function(e){s._dragElement&&(s._dragCtrlPoint?x(e):s._dragResizeHandler?C(e):(t(e.element).addClass("flowchart-dragged"),s.setElementBounds(s._dragElement.id,e.pos))),s._dragElement=null,s._dragCtrlPoint=null,s._dragResizeHandler=null},mouseButton:"left",before:function(e){var o=!s.isPreventDragNode;return(!o||!t(e.event.target).closest(".flowchart-ports-side").length)&&o}})}if(!p.readonly){var T,S,M,k,A,_,I,L,D,B,z,H=null;w.droppable({container:"#"+b,target:".flowchart-port,.flowchart-node",selector:".flowchart-port-dot",mouseButton:"left",nested:!0,flex:!1,before:function(t){s.isPreventDragNode=!0},start:function(e){T=t(e.element).closest(".flowchart-port"),S=T.closest(".flowchart-node"),H=S.data("id"),B=T.data("name");var o=s.getElement(H);D=o.getRelationsByPort(B).filter(function(t){return s.isElementActive(t.id)}),D&&D.length?(D=D[0],z=D.from===H?"from":"to",H=D["from"===z?"to":"from"],B=D[("from"===z?"to":"from")+"Port"],S=s.$findElement(H),T=S.find('.flowchart-port[data-name="'+B+'"]')):D=null,A=l(s.getPositionOf(T),T.data("centerOffset")),T.addClass("flowchart-drag-active"),S.addClass("flowchart-drag-active"),_=w.find(".flowchart-link-line"),_.length||(_=t('').appendTo(w)),I=_.show().attr({width:w.width(),height:w.height()}).find("line"),D&&(D.hide(!0),D.render()),L=!1},drag:function(e){if(M&&M.removeClass("flowchart-drop-active"),k&&k.removeClass("flowchart-drop-active"),k=null,M=null,e.isIn&&e.target){var o=t(e.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");i.length&&i.data("id")!==H&&(k=i.addClass("flowchart-drop-active"),M=r.addClass("flowchart-drop-active"))}var n={left:e.position.left+8,top:e.position.top+8};I.attr({x1:A.left,y1:A.top,x2:n.left,y2:n.top})},drop:function(e){if(e.target){var o=t(e.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");if(i.length){var n=i.data("id");if(n!==H){var a=r.data("name");if(z)n&&a&&(D[z]=n,D[z+"Port"]=a);else{var l=p.confirmRelationType;if(l&&t.zui.ContextMenu){var h=[{label:s.lang.selectRelationType,disabled:!0}];"string"==typeof l&&(l=l.split(",")),t.isArray(l)?l.forEach(function(t){var e=s.types[t];e.isRelation&&!e.internal&&h.push({label:e.displayName||t,relationType:t})}):t.each(s.types,function(t,e){e.isRelation&&!e.internal&&h.push({label:e.displayName||t,relationType:t})});var f=H,d=B;if("string"==typeof f&&(f=s.getElement(f)),"string"==typeof n&&(n=s.getElement(n)),!f||!n||f===n)return;if(!(p.allowFreePorts||d&&a))return;t.zui.ContextMenu.show(h,{event:e.event,onClickItem:function(t){s.addRelation(f,d,n,a,null,t.relationType)}})}else s.addRelation(H,B,n,a)}}L=!0}}},always:function(e){if(s.isPreventDragNode=!1,T&&T.removeClass("flowchart-drag-active"),S&&S.removeClass("flowchart-drag-active"),M&&M.removeClass("flowchart-drop-active"),k&&k.removeClass("flowchart-drop-active"),_&&_.hide(),p.quickAdd&&!L&&(e.cancel||a(e.position,A)<20)){var o=t(e.event.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");s.addNode(p.defaultNodeType||"action",i.data("id"),r.data("name"),null,r.data("side"))}D&&D.show(),H=null,B=null,S=null,T=null,z=null,D=null}})}}if(!p.readonly&&p.addFromDrop){if("string"==typeof p.addFromDrop){var W=t(p.addFromDrop),$=function(e){var o=t(e.target).closest('[draggable="true"]').data();o.type&&(e.originalEvent.dataTransfer.setData("text",JSON.stringify(o)),h.addClass("flowchart-drag-start"),e.originalEvent.dataTransfer.effectAllowed="copy")},O=function(t){h.removeClass("flowchart-drag-start").removeClass("flowchart-drag-over")};W.is('[draggable="true"]')?W.on("dragstart",$).on("dragend",O):W.on("dragstart",'[draggable="true"]',$).on("dragend",'[draggable="true"]',O)}var X=function(e){p.onDragOver&&p.onDragOver.call(s,e)===!1||(h.toggleClass("flowchart-drag-over",!!t(e.target).closest(".flowchart-canvas").length),e.originalEvent.dataTransfer.effectAllowed="copy",e.preventDefault())};w.on("dragenter",X).on("dragover",X).on("dragleave",function(e){p.onDragLeave&&p.onDragLeave.call(s,e)===!1||h.toggleClass("flowchart-drag-over",!t(e.target).closest(".flowchart-canvas").length)}).on("drop",function(r){if(!p.onDrop||p.onDrop.call(s,r)!==!1){r.preventDefault();var i=r.originalEvent.dataTransfer.getData("text");if(i){try{i=t.parseJSON(i)}catch(r){console.error('FlowChart: Cannot get correct "newElement" data from drop event\'s dataTransfer.',i,r)}if(i&&"object"==typeof i&&i.type){var n=w.offset();r.clientX===e&&(r=r.originalEvent),s.addElement(t.extend({position:{centerLeft:r.clientX-n.left+t(o).scrollLeft(),centerTop:r.clientY-n.top+t(o).scrollTop()},text:null},i))}else console.warn('FlowChart: Data format error in "newElement" data from drop event\'s dataTransfer.',i)}}})}if(!p.readonly){p.doubleClickToEdit&&w.on("dblclick",".flowchart-element,.flowchart-relation-line",function(e){var o,r=t(this);t.isFunction(p.doubleClickToEdit)&&(o=p.doubleClickToEdit(s.getElement(r.data("id")),s,e)),o||s.focusElementText(r.data("id")),e.preventDefault()});var j=null;w.on("input",".flowchart-text[contenteditable=true]",function(e){var o=t(this);j&&(clearTimeout(j),j=null);var r=o.text();j=setTimeout(function(){var t=o.closest(".flowchart-element");s.setElementText(t.data("id"),r,!0)},1e3)}).on("keydown",function(t){if(13===t.keyCode&&!t.shiftKey)return t.preventDefault(),s.blurElementText(),!1}).on("blur",".flowchart-text",function(e){j&&(clearTimeout(j),j=null);var o=t(this),r=o.closest(".flowchart-element");s.setElementText(r.data("id"),o.text())})}p.showContextMenu&&t.zui.ContextMenu&&(w.on("mousedown",".flowchart-element,.flowchart-relation-line",function(e){2===e.button&&s.showContextMenu(t(this).data("id"),e),e.preventDefault(),e.returnValue=!1}).on("contextmenu",function(t){return t.preventDefault(),t.returnValue=!1,!1}),t(r).on("change",".flowchart-"+s.id+"-type-selector",function(){var e=t(this),o=e.data("id"),r=s.getElement(o);r&&(r.changeType(e.val()),s.render(r)),t.zui.ContextMenu.hide()})),w.on("click",function(e){var o=t(e.target),r=o.closest(".flowchart-element,.flowchart-relation-line");if(r.length){if(r.hasClass("flowchart-dragged"))return void r.removeClass("flowchart-dragged");var i=s.getElement(r.data("id"));if(i){var n=!1;if(!p.readonly)if(o.is(".flowchart-link-self-btn"))i.linkSelf(),n=!0;else{var a=o.closest(".flowchart-port-rest-holder");if(a.length)i.appendRestPortHolder(a.data("name")),n=!0;else{var l=o.closest(".flowchart-port-delete-handler");l.length&&(i.deleteRestPort(l.parent().data("name")),n=!0)}}if(!n){if(p.onClickElement)try{p.onClickElement(i,r)}catch(e){console.error('FlowChart: Call callback function "onClickElement" error.',e)}p.activeOnClick&&s.activeElement(i)}}}else s.unactiveElements()}),s.updateStyle(),s.elements={},this.activedElements={};var F=h.find(".flowchart-svg-canvas");F.length||(F=t('').prependTo(w)),s.$svg=F,s.$svgMarkers=F.find("defs"),s.nodeZIndex=5,s.callCallback("onCreate",[p]),s.update(p.data,!0,!0),s.render(null,!0),s.callCallback("afterCreate",[this]),s.created=!0};N.prototype.newZIndex=function(){return this.nodeZIndex++},N.prototype.callCallback=function(t,e){var o,r=this;return r.plugins&&r.plugins.forEach(function(i){var n=N.plugins[i];n&&n[t]&&(o=n[t].apply(r,e))}),r.options[t]&&(o=r.options[t].apply(r,e)),o},N.prototype.getPositionOf=function(e,o){var r=this.$canvas.offset();if(!e)return r;var i;i=e instanceof S?e.$get():t(e);var n=i.offset(),a={left:n.left-r.left,top:n.top-r.top};return o&&(a.left+=i.width()/2,a.top+=i.height()/2),a},N.prototype.updateStyle=function(){var t=this,e=t.id,o=["#{id} {background: #fff; transition: box-shadow .2s;}","#{id}.flowchart-drag-start {box-shadow: inset 0 0 3px {activeColor}!important}","#{id}.flowchart-drag-over {box-shadow: inset 0 0 0 2px {activeColor}!important}","#{id} .flowchart-port-dot {opacity: 0; background: {activeColor}; border-radius: 50%; transition: .2s opacity, .2s transform; cursor: pointer;}","#{id} .flowchart-element:hover .flowchart-port-dot {opacity: 0.7}","#{id} .flowchart-element.flowchart-drop-active .flowchart-port-dot {opacity: 0.5; transform: scale(2); background: #333}","#{id} .flowchart-element.flowchart-drop-active .flowchart-drop-active > .flowchart-port-dot {background: {activeColor}}","#{id} .flowchart-element .flowchart-port-dot:hover, #{id} .flowchart-element .flowchart-drag-active > .flowchart-port-dot, #{id} .flowchart-element .flowchart-drop-active > .flowchart-port-dot {opacity: 1; transform: scale(2)}","#{id} .flowchart-node.flowchart-active,","#{id} .flowchart-node.flowchart-drag-active,","#{id} .flowchart-allow-free-ports .flowchart-node.flowchart-drop-active","{border-color: {activeColor}!important; box-shadow: 0 0 0 2px {activeColor}!important}",'#{id} .flowchart-node.flowchart-active[data-basic-type="diamond"] {box-shadow: none!important}',"#{id} .flowchart-relation {pointer-events: none}","#{id} .flowchart-relation.flowchart-element-focused {pointer-events: auto}",'#{id} .flowchart-relation:before {content: " "; display: block; top: -4px; right: -4px; bottom: -4px; left: -4px; position: absolute; border-radius: 50%;}',"#{id} .flowchart-relation-text {min-height: 14px; min-width: 12px; opacity: 0; pointer-events: auto}","#{id} .flowchart-relation-text.flowchart-has-text {opacity: 1; display: -webkit-box!important; -webkit-line-clamp: 2!important; -webkit-box-orient: vertical!important; overflow: hidden!important}",'#{id} .flowchart-relation[data-shape="polyline"] .flowchart-relation-text,','#{id} .flowchart-relation[data-shape="bessel"] .flowchart-relation-text,','#{id} .flowchart-relation[data-shape="arc"] .flowchart-relation-text {cursor: move}','#{id} .flowchart-relation-text.flowchart-has-text[data-shape="arc"] {white-space: nowrap;}',"#{id} .flowchart-node-text.flowchart-node-text-limit {align-items: flex-start!important; line-height: 1.3!important; pading-top: 5px!important; display: -webkit-box!important; -webkit-line-clamp: 2!important; -webkit-box-orient: vertical!important;}","#{id} .flowchart-element-focused .flowchart-relation-text {opacity: 1; pointer-events: auto; border: 1px solid {activeColor}}","#{id} .flowchart-svg-canvas .flowchart-relation-line:hover {stroke: {activeColor}!important}","#{id} .flowchart-port-expired {display: none!important}",'#{id} .flowchart-link-self-btn {position: absolute; bottom: -10px; right: -12px; width: 16px; height: 16px; border-radius: 8px; background: {activeColor}; opacity: 0; transition: .2s opacity; cursor: pointer; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAAAbFBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8+T+BWAAAAI3RSTlMAKzOqA7VVF9/aYl4iHRkI+PTUpXZwUhLlzMaZh/Whi4REQwySiHwAAAC4SURBVCjPtZLHDsIwEEQTx07vvVHf//8jPkBwUHxAgjnYGj1pNTta56fKPC+zQhfc72CR6ycVwgdfiNQg+RpR69/jKe/N2hNYoGygWnr3cOwFVGAJJKCRtrSKqLCVEEBsXdqHwQo7RnvRLeG+vmnKN5NQShP2UJjR7yZcqA0XocyWK66GjSHZjFRUgQHlTPmiRQPdLl8QgrrpVEMcwnnHNJ2BMhwBVvm5q4wjAFDi+HSStusH5/96AG7KECHX9nREAAAAAElFTkSuQmCC"); background-size: 14px 14px; background-repeat: no-repeat; background-position: center;}',"#{id} .flowchart-element:hover .flowchart-link-self-btn {opacity: .7;}","#{id} .flowchart-element .flowchart-link-self-btn:hover {opacity: 1;}","#{id} .flowchart-relation-line-ctrl-point {cursor: move; visibility: hidden}","#{id} .flowchart-relation-line:hover .flowchart-relation-line-ctrl-point,","#{id} .flowchart-relation-line-active .flowchart-relation-line-ctrl-point {visibility: visible; z-index: 10}","#{id} .flowchart-resize-handler {display: none}","#{id} .flowchart-resizable .flowchart-resize-handler {display: block; position: absolute; left: 0; right: 0; height: 6px; bottom: -3px; z-index: 100; cursor: ns-resize; transition: opacity .4s; border-radius: 3px; background: {activeColor}; opacity: 0;}","#{id} .flowchart-resizable .flowchart-resize-handler:hover {opacity: 0.4}"];t.plugins&&t.plugins.forEach(function(e){var r=N.plugins[e];r&&r.style&&o.push("function"==typeof r.style?r.style.call(t):r.style)}),o=o.join("\n").format({id:e,activeColor:t.options.activeColor});var i=r.getElementById("flowchartStyle-"+e);if(!i){var n=r.head||r.getElementsByTagName("head")[0],i=r.createElement("style");n.appendChild(i),i.type="text/css",i.id="flowchartStyle-"+e}i.styleSheet?i.styleSheet.cssText=o:i.appendChild(r.createTextNode(o))},N.prototype.createRelation=function(t){var e=this.types[t.type]||this.types[this.options.defaultRelationType];return e.createElement(t,this)},N.prototype.createElements=function(e){var o=this,r=o.types;if(e instanceof S)return[e];var i;"relation"===e.type&&(i=r[o.options.defaultRelationType]),i||(i=r[e.type]||r[o.options.defaultNodeType]);var n=i.createElement(e,o),a=[n];if(n.isNode){if(e.from){var l=t.isArray(e.from)?e.from:[e.from];l.forEach(function(t){var e=t.split(":");a.push(o.createRelation({from:e[0],to:l.length>2?n.id+"."+e[1]:n.id,text:e[l.length>2?2:1]}))})}if(e.to){var s=t.isArray(e.to)?e.to:[e.to];t.each(s,function(t,e){var r=e.split(":");a.push(o.createRelation({to:r[0],text:r[l.length>2?2:1],from:l.length>2?n.id+"."+fromInfo[1]:n.id}))})}}return a},N.prototype.activeElement=function(t,e){var o=this;"string"==typeof t&&(t=o.getElement(t)),e||o.unactiveElements([t.id]),t&&!o.isElementActive(t.id)&&(o.activedElements[t.id]=t,t.active(t.isNode),o.callCallback("onActiveElement",[t]))},N.prototype.unactiveElement=function(t){var e=this;"string"==typeof t&&(t=e.getElement(t)),t&&(delete this.activedElements[t.id],t.unactive(),e.callCallback("onUnactiveElement",[t]))},N.prototype.getActiveElements=function(e){var o=[];return this.activedElements&&t.each(this.activedElements,function(t,r){e&&e!==r.type||o.push(r)}),o},N.prototype.unactiveElements=function(e){var o,r=this;e&&("string"==typeof e&&(e=e.split(",")),o={},e.forEach(function(t){"object"==typeof t?o[t.id]=1:o[t]=1})),t.each(r.activedElements,function(t,e){o&&o[t]||r.unactiveElement(e)}),r.blurElementText()},N.prototype.isElementActive=function(t){return"object"==typeof t&&(t=t.id),!!this.activedElements[t]},N.prototype.blurElementText=function(){var t=this;if(t._focusedElement){var e=t.getElement(t._focusedElement);e&&e.blurText(),t._focusedElement=null}},N.prototype.focusElementText=function(t){var e=this;"string"==typeof t&&(t=e.getElement(t)),t&&(e.blurElementText(),e.activeElement(t),t.focusText(),e._focusedElement=t.id)},N.prototype.showContextMenu=function(e,o){var r=this;if("string"==typeof e&&(e=r.getElement(e)),e){var i=[];if(!r.options.readonly){var n=[];t.each(r.types,function(t,o){o.isNode!==e.isNode||o.internal||n.push("'+(o.displayName||o.name)+"")}),i.push({id:"type",html:['
',''+r.lang.type+"",'