"use strict";Liferay.Loader.define("portal-workflow-kaleo-designer-web$dagre@0.8.2/lib/position/bk",["module","exports","require","../lodash","../graphlib","../util"],(function(n,r,e){window;{var o=e("../lodash"),t=e("../graphlib").Graph,i=e("../util");function findType1Conflicts(n,r){var e={};return o.reduce(r,(function visitLayer(r,t){var i=0,a=0,c=r.length,f=o.last(t);return o.forEach(t,(function(r,u){var d=function findOtherInnerSegmentNode(n,r){if(n.node(r).dummy)return o.find(n.predecessors(r),(function(r){return n.node(r).dummy}))}(n,r),s=d?n.node(d).order:c;(d||r===f)&&(o.forEach(t.slice(a,u+1),(function(r){o.forEach(n.predecessors(r),(function(o){var t=n.node(o),a=t.order;!(a<i||s<a)||t.dummy&&n.node(r).dummy||addConflict(e,o,r)}))})),a=u+1,i=s)})),t})),e}function findType2Conflicts(n,r){var e={};function scan(r,t,i,a,c){var f;o.forEach(o.range(t,i),(function(t){f=r[t],n.node(f).dummy&&o.forEach(n.predecessors(f),(function(r){var o=n.node(r);o.dummy&&(o.order<a||o.order>c)&&addConflict(e,r,f)}))}))}return o.reduce(r,(function visitLayer(r,e){var t,i=-1,a=0;return o.forEach(e,(function(o,c){if("border"===n.node(o).dummy){var f=n.predecessors(o);f.length&&(t=n.node(f[0]).order,scan(e,a,c,i,t),a=c,i=t)}scan(e,a,e.length,t,r.length)})),e})),e}function addConflict(n,r,e){if(r>e){var o=r;r=e,e=o}var t=n[r];t||(n[r]=t={}),t[e]=!0}function hasConflict(n,r,e){if(r>e){var t=r;r=e,e=t}return o.has(n[r],e)}function verticalAlignment(n,r,e,t){var i={},a={},c={};return o.forEach(r,(function(n){o.forEach(n,(function(n,r){i[n]=n,a[n]=n,c[n]=r}))})),o.forEach(r,(function(n){var r=-1;o.forEach(n,(function(n){var f=t(n);if(f.length)for(var u=((f=o.sortBy(f,(function(n){return c[n]}))).length-1)/2,d=Math.floor(u),s=Math.ceil(u);d<=s;++d){var l=f[d];a[n]===n&&r<c[l]&&!hasConflict(e,n,l)&&(a[l]=n,a[n]=i[n]=i[l],r=c[l])}}))})),{root:i,align:a}}function horizontalCompaction(n,r,e,i,a){var c={},f=function buildBlockGraph(n,r,e,i){var a=new t,c=n.graph(),f=function sep(n,r,e){return function(t,i,a){var c,f=t.node(i),u=t.node(a),d=0;if(d+=f.width/2,o.has(f,"labelpos"))switch(f.labelpos.toLowerCase()){case"l":c=-f.width/2;break;case"r":c=f.width/2}if(c&&(d+=e?c:-c),c=0,d+=(f.dummy?r:n)/2,d+=(u.dummy?r:n)/2,d+=u.width/2,o.has(u,"labelpos"))switch(u.labelpos.toLowerCase()){case"l":c=u.width/2;break;case"r":c=-u.width/2}return c&&(d+=e?c:-c),c=0,d}}(c.nodesep,c.edgesep,i);return o.forEach(r,(function(r){var t;o.forEach(r,(function(r){var o=e[r];if(a.setNode(o),t){var i=e[t],c=a.edge(i,o);a.setEdge(i,o,Math.max(f(n,r,t),c||0))}t=r}))})),a}(n,r,e,a),u=a?"borderLeft":"borderRight";function iterate(n,r){for(var e=f.nodes(),o=e.pop(),t={};o;)t[o]?n(o):(t[o]=!0,e.push(o),e=e.concat(r(o))),o=e.pop()}return iterate((function pass1(n){c[n]=f.inEdges(n).reduce((function(n,r){return Math.max(n,c[r.v]+f.edge(r))}),0)}),o.bind(f.predecessors,f)),iterate((function pass2(r){var e=f.outEdges(r).reduce((function(n,r){return Math.min(n,c[r.w]-f.edge(r))}),Number.POSITIVE_INFINITY),o=n.node(r);e!==Number.POSITIVE_INFINITY&&o.borderType!==u&&(c[r]=Math.max(c[r],e))}),o.bind(f.successors,f)),o.forEach(i,(function(n){c[n]=c[e[n]]})),c}function findSmallestWidthAlignment(n,r){return o.minBy(o.values(r),(function(r){var e=Number.NEGATIVE_INFINITY,t=Number.POSITIVE_INFINITY;return o.forIn(r,(function(r,o){var i=function width(n,r){return n.node(r).width}(n,o)/2;e=Math.max(r+i,e),t=Math.min(r-i,t)})),e-t}))}function alignCoordinates(n,r){var e=o.values(r),t=o.min(e),i=o.max(e);o.forEach(["u","d"],(function(e){o.forEach(["l","r"],(function(a){var c,f=e+a,u=n[f];if(u!==r){var d=o.values(u);(c="l"===a?t-o.min(d):i-o.max(d))&&(n[f]=o.mapValues(u,(function(n){return n+c})))}}))}))}function balance(n,r){return o.mapValues(n.ul,(function(e,t){if(r)return n[r.toLowerCase()][t];var i=o.sortBy(o.map(n,t));return(i[1]+i[2])/2}))}n.exports={positionX:function positionX(n){var r,e=i.buildLayerMatrix(n),t=o.merge(findType1Conflicts(n,e),findType2Conflicts(n,e)),a={};o.forEach(["u","d"],(function(i){r="u"===i?e:o.values(e).reverse(),o.forEach(["l","r"],(function(e){"r"===e&&(r=o.map(r,(function(n){return o.values(n).reverse()})));var c=o.bind("u"===i?n.predecessors:n.successors,n),f=verticalAlignment(0,r,t,c),u=horizontalCompaction(n,r,f.root,f.align,"r"===e);"r"===e&&(u=o.mapValues(u,(function(n){return-n}))),a[i+e]=u}))}));var c=findSmallestWidthAlignment(n,a);return alignCoordinates(a,c),balance(a,n.graph().align)},findType1Conflicts:findType1Conflicts,findType2Conflicts:findType2Conflicts,addConflict:addConflict,hasConflict:hasConflict,verticalAlignment:verticalAlignment,horizontalCompaction:horizontalCompaction,alignCoordinates:alignCoordinates,findSmallestWidthAlignment:findSmallestWidthAlignment,balance:balance}}}));
//# sourceMappingURL=bk.js.map