UNPKG

@antv/layout

Version:
7 lines 315 kB
!function(){"use strict";function t(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 */ const e=Symbol("Comlink.proxy"),r=Symbol("Comlink.endpoint"),n=Symbol("Comlink.releaseProxy"),o=Symbol("Comlink.finalizer"),i=Symbol("Comlink.thrown"),s=t=>"object"==typeof t&&null!==t||"function"==typeof t,a=new Map([["proxy",{canHandle:t=>s(t)&&t[e],serialize(t){const{port1:e,port2:r}=new MessageChannel;return u(t,e),[r,[r]]},deserialize:t=>(t.start(),h(t))}],["throw",{canHandle:t=>s(t)&&i in t,serialize({value:t}){let e;return e=t instanceof Error?{isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:{isError:!1,value:t},[e,[]]},deserialize(t){if(t.isError)throw Object.assign(new Error(t.value.message),t.value);throw t.value}}]]);function u(t,r=globalThis,n=["*"]){r.addEventListener("message",function s(a){if(!a||!a.data)return;if(!function(t,e){for(const r of t){if(e===r||"*"===r)return!0;if(r instanceof RegExp&&r.test(e))return!0}return!1}(n,a.origin))return void console.warn(`Invalid origin '${a.origin}' for comlink proxy`);const{id:h,type:l,path:d}=Object.assign({path:[]},a.data),f=(a.data.argumentList||[]).map(w);let g;try{const r=d.slice(0,-1).reduce((t,e)=>t[e],t),n=d.reduce((t,e)=>t[e],t);switch(l){case"GET":g=n;break;case"SET":r[d.slice(-1)[0]]=w(a.data.value),g=!0;break;case"APPLY":g=n.apply(r,f);break;case"CONSTRUCT":g=function(t){return Object.assign(t,{[e]:!0})}(new n(...f));break;case"ENDPOINT":{const{port1:e,port2:r}=new MessageChannel;u(t,r),g=function(t,e){return m.set(t,e),t}(e,[e])}break;case"RELEASE":g=void 0;break;default:return}}catch(t){g={value:t,[i]:0}}Promise.resolve(g).catch(t=>({value:t,[i]:0})).then(e=>{const[n,i]=y(e);r.postMessage(Object.assign(Object.assign({},n),{id:h}),i),"RELEASE"===l&&(r.removeEventListener("message",s),c(r),o in t&&"function"==typeof t[o]&&t[o]())}).catch(t=>{const[e,n]=y({value:new TypeError("Unserializable return value"),[i]:0});r.postMessage(Object.assign(Object.assign({},e),{id:h}),n)})}),r.start&&r.start()}function c(t){(function(t){return"MessagePort"===t.constructor.name})(t)&&t.close()}function h(t,e){const r=new Map;return t.addEventListener("message",function(t){const{data:e}=t;if(!e||!e.id)return;const n=r.get(e.id);if(n)try{n(e)}finally{r.delete(e.id)}}),p(t,r,[],e)}function l(t){if(t)throw new Error("Proxy has been released and is not useable")}function d(t){return x(t,new Map,{type:"RELEASE"}).then(()=>{c(t)})}const f=new WeakMap,g="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(f.get(t)||0)-1;f.set(t,e),0===e&&d(t)});function p(t,e,o=[],i=function(){}){let s=!1;const a=new Proxy(i,{get(r,i){if(l(s),i===n)return()=>{!function(t){g&&g.unregister(t)}(a),d(t),e.clear(),s=!0};if("then"===i){if(0===o.length)return{then:()=>a};const r=x(t,e,{type:"GET",path:o.map(t=>t.toString())}).then(w);return r.then.bind(r)}return p(t,e,[...o,i])},set(r,n,i){l(s);const[a,u]=y(i);return x(t,e,{type:"SET",path:[...o,n].map(t=>t.toString()),value:a},u).then(w)},apply(n,i,a){l(s);const u=o[o.length-1];if(u===r)return x(t,e,{type:"ENDPOINT"}).then(w);if("bind"===u)return p(t,e,o.slice(0,-1));const[c,h]=v(a);return x(t,e,{type:"APPLY",path:o.map(t=>t.toString()),argumentList:c},h).then(w)},construct(r,n){l(s);const[i,a]=v(n);return x(t,e,{type:"CONSTRUCT",path:o.map(t=>t.toString()),argumentList:i},a).then(w)}});return function(t,e){const r=(f.get(e)||0)+1;f.set(e,r),g&&g.register(t,e,t)}(a,t),a}function v(t){const e=t.map(y);return[e.map(t=>t[0]),(r=e.map(t=>t[1]),Array.prototype.concat.apply([],r))];var r}const m=new WeakMap;function y(t){for(const[e,r]of a)if(r.canHandle(t)){const[n,o]=r.serialize(t);return[{type:"HANDLER",name:e,value:n},o]}return[{type:"RAW",value:t},m.get(t)||[]]}function w(t){switch(t.type){case"HANDLER":return a.get(t.name).deserialize(t.value);case"RAW":return t.value}}function x(t,e,r,n){return new Promise(o=>{const i=new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-");e.set(i,o),t.start&&t.start(),t.postMessage(Object.assign({id:i},r),n)})}function b(t){return"function"==typeof t}function E(t){return null==t}function M(t){return Array.isArray(t)}var N={}.toString,_=function(t,e){return N.call(t)==="[object "+e+"]"},k=function(t){if(!function(t){return"object"==typeof t&&null!==t}(t)||!_(t,"Object"))return!1;if(null===Object.getPrototypeOf(t))return!0;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e};function S(t){return"string"==typeof t}function A(t){return"number"==typeof t}var O={}.toString,z=Object.prototype,j=function(t){if("object"!=typeof t||null===t)return t;var e;if(M(t)){e=[];for(var r=0,n=t.length;r<n;r++)"object"==typeof t[r]&&null!=t[r]?e[r]=j(t[r]):e[r]=t[r]}else for(var o in e={},t)"object"==typeof t[o]&&null!=t[o]?e[o]=j(t[o]):e[o]=t[o];return e};function C(t,e){if(Object.hasOwn)return Object.hasOwn(t,e);if(null==t)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(Object(t),e)}function I(t,e,r,n){for(var o in r=r||0,n=n||5,e)if(C(e,o)){var i=e[o];null!==i&&k(i)?(k(t[o])||(t[o]={}),r<n?I(t[o],i,r+1,n):t[o]=e[o]):M(i)?(t[o]=[],t[o]=t[o].concat(i)):void 0!==i&&(t[o]=i)}}var R=Object.prototype.hasOwnProperty;function T(t){if(E(t))return!0;if(function(t){return null!==t&&"function"!=typeof t&&isFinite(t.length)}(t))return!t.length;var e=function(t){return O.call(t).replace(/^\[object /,"").replace(/]$/,"")}(t);if("Map"===e||"Set"===e)return!t.size;if(function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||z)}(t))return!Object.keys(t).length;for(var r in t)if(R.call(t,r))return!1;return!0}var P=Object.prototype.hasOwnProperty,F=function(t,e){if(null===t||!k(t))return{};var r={};return function(t,e){var r,n;if(t)if(M(t))for(var o=0,i=t.length;o<i&&!1!==e(t[o],o);o++);else if(n=typeof(r=t),null!==r&&"object"===n||"function"===n)for(var s in t)if(t.hasOwnProperty(s)&&!1===e(t[s],s))break}(e,function(e){P.call(t,e)&&(r[e]=t[e])}),r};function L(t,e,r=2){if(1===t.nodeCount()){const n=t.firstNode();n.x=e[0],n.y=e[1],3===r&&(n.z=e[2]||0)}}const D={abs:Math.abs,ceil:Math.ceil,floor:Math.floor,max:Math.max,min:Math.min,round:Math.round,sqrt:Math.sqrt,pow:Math.pow};class q extends Error{constructor(t,e,r){super(t),this.position=e,this.token=r,this.name="ExpressionError"}}var B;!function(t){t[t.STRING=0]="STRING",t[t.NUMBER=1]="NUMBER",t[t.BOOLEAN=2]="BOOLEAN",t[t.NULL=3]="NULL",t[t.IDENTIFIER=4]="IDENTIFIER",t[t.OPERATOR=5]="OPERATOR",t[t.FUNCTION=6]="FUNCTION",t[t.DOT=7]="DOT",t[t.BRACKET_LEFT=8]="BRACKET_LEFT",t[t.BRACKET_RIGHT=9]="BRACKET_RIGHT",t[t.PAREN_LEFT=10]="PAREN_LEFT",t[t.PAREN_RIGHT=11]="PAREN_RIGHT",t[t.COMMA=12]="COMMA",t[t.QUESTION=13]="QUESTION",t[t.COLON=14]="COLON",t[t.DOLLAR=15]="DOLLAR"}(B||(B={}));const V=new Set([32,9,10,13]),$=new Set([43,45,42,47,37,33,38,124,61,60,62]),U=new Map([["true",B.BOOLEAN],["false",B.BOOLEAN],["null",B.NULL]]),G=new Map([["===",!0],["!==",!0],["<=",!0],[">=",!0],["&&",!0],["||",!0],["+",!0],["-",!0],["*",!0],["/",!0],["%",!0],["!",!0],["<",!0],[">",!0]]),W=new Map([[46,B.DOT],[91,B.BRACKET_LEFT],[93,B.BRACKET_RIGHT],[40,B.PAREN_LEFT],[41,B.PAREN_RIGHT],[44,B.COMMA],[63,B.QUESTION],[58,B.COLON],[36,B.DOLLAR]]),Y=new Map;for(const[t,e]of W.entries())Y.set(t,{type:e,value:String.fromCharCode(t)});function H(t){return t>=48&&t<=57}function X(t){return t>=97&&t<=122||t>=65&&t<=90||95===t}function Q(t){return X(t)||H(t)}function K(t){return $.has(t)}var J;!function(t){t[t.Program=0]="Program",t[t.Literal=1]="Literal",t[t.Identifier=2]="Identifier",t[t.MemberExpression=3]="MemberExpression",t[t.CallExpression=4]="CallExpression",t[t.BinaryExpression=5]="BinaryExpression",t[t.UnaryExpression=6]="UnaryExpression",t[t.ConditionalExpression=7]="ConditionalExpression"}(J||(J={}));const Z=new Map([["||",2],["&&",3],["===",4],["!==",4],[">",5],[">=",5],["<",5],["<=",5],["+",6],["-",6],["*",7],["/",7],["%",7],["!",8]]),tt={type:J.Literal,value:null},et={type:J.Literal,value:!0},rt={type:J.Literal,value:!1},nt=t=>{let e=0;const r=t.length,n=()=>e>=r?null:t[e],o=()=>t[e++],i=t=>{const e=n();return null!==e&&e.type===t},s=t=>t.type===B.OPERATOR?Z.get(t.value)||-1:t.type===B.DOT||t.type===B.BRACKET_LEFT?9:t.type===B.QUESTION?1:-1,a=t=>{let r,s;if(o().type===B.DOT){if(!i(B.IDENTIFIER)){const t=n();throw new q("Expected property name",e,t?t.value:"<end of input>")}const t=o();r={type:J.Identifier,name:t.value},s=!1}else{if(r=c(0),!i(B.BRACKET_RIGHT)){const t=n();throw new q("Expected closing bracket",e,t?t.value:"<end of input>")}o(),s=!0}return{type:J.MemberExpression,object:t,property:r,computed:s}},u=()=>{const t=n();if(!t)throw new q("Unexpected end of input",e,"<end of input>");if(t.type===B.OPERATOR&&("!"===t.value||"-"===t.value)){o();const e=u();return{type:J.UnaryExpression,operator:t.value,argument:e,prefix:!0}}switch(t.type){case B.NUMBER:return o(),{type:J.Literal,value:Number(t.value)};case B.STRING:return o(),{type:J.Literal,value:t.value};case B.BOOLEAN:return o(),"true"===t.value?et:rt;case B.NULL:return o(),tt;case B.IDENTIFIER:return o(),{type:J.Identifier,name:t.value};case B.FUNCTION:return(()=>{const t=o(),r=[];if(!i(B.PAREN_LEFT)){const t=n();throw new q("Expected opening parenthesis after function name",e,t?t.value:"<end of input>")}for(o();;){if(i(B.PAREN_RIGHT)){o();break}if(!n()){const t=n();throw new q("Expected closing parenthesis",e,t?t.value:"<end of input>")}if(r.length>0){if(!i(B.COMMA)){const t=n();throw new q("Expected comma between function arguments",e,t?t.value:"<end of input>")}o()}const t=c(0);r.push(t)}return{type:J.CallExpression,callee:{type:J.Identifier,name:t.value},arguments:r}})();case B.PAREN_LEFT:{o();const t=c(0);if(!i(B.PAREN_RIGHT)){const t=n();throw new q("Expected closing parenthesis",e,t?t.value:"<end of input>")}return o(),t}default:throw new q(`Unexpected token: ${t.type}`,e,t.value)}},c=(h=0)=>{let l=u();for(;e<r;){const r=t[e],u=s(r);if(u<=h)break;if(r.type!==B.QUESTION)if(r.type!==B.OPERATOR){if(r.type!==B.DOT&&r.type!==B.BRACKET_LEFT)break;l=a(l)}else{o();const t=c(u);l={type:J.BinaryExpression,operator:r.value,left:l,right:t}}else{o();const t=c(0);if(!i(B.COLON)){const t=n();throw new q("Expected : in conditional expression",e,t?t.value:"<end of input>")}o();const r=c(0);l={type:J.ConditionalExpression,test:l,consequent:t,alternate:r}}}return l},h=c();return{type:J.Program,body:h}},ot=(t,e,r)=>{let n=e;r&&(n={...e,context:{...e.context,...r}});const o=t=>{switch(t.type){case J.Literal:return(t=>t.value)(t);case J.Identifier:return(t=>{if(!(t.name in n.context))throw new q(`Undefined variable: ${t.name}`);return n.context[t.name]})(t);case J.MemberExpression:return(t=>{const e=o(t.object);if(null==e)throw new q("Cannot access property of null or undefined");return e[t.computed?o(t.property):t.property.name]})(t);case J.CallExpression:return(t=>{const e=n.functions[t.callee.name];if(!e)throw new q(`Undefined function: ${t.callee.name}`);return e(...t.arguments.map(t=>o(t)))})(t);case J.BinaryExpression:return(t=>{if("&&"===t.operator){const e=o(t.left);return e?o(t.right):e}if("||"===t.operator)return o(t.left)||o(t.right);const e=o(t.left),r=o(t.right);switch(t.operator){case"+":return e+r;case"-":return e-r;case"*":return e*r;case"/":return e/r;case"%":return e%r;case"===":return e===r;case"!==":return e!==r;case">":return e>r;case">=":return e>=r;case"<":return e<r;case"<=":return e<=r;default:throw new q(`Unknown operator: ${t.operator}`)}})(t);case J.UnaryExpression:return(t=>{const e=o(t.argument);if(t.prefix)switch(t.operator){case"!":return!e;case"-":if("number"!=typeof e)throw new q(`Cannot apply unary - to non-number: ${e}`);return-e;default:throw new q(`Unknown operator: ${t.operator}`)}throw new q(`Postfix operators are not supported: ${t.operator}`)})(t);case J.ConditionalExpression:return(t=>{const e=o(t.test);return o(e?t.consequent:t.alternate)})(t);default:throw new q(`Evaluation error: Unsupported node type: ${t.type}`)}};return o(t.body)};function it(t){const e=(t=>{const e=t,r=e.length,n=new Array(Math.ceil(r/3));let o=0,i=0;function s(t){const n=i+1;i++;let o="",s=!1;for(;i<r;){const r=e.charCodeAt(i);if(r===t)return s||(o=e.substring(n,i)),i++,{type:B.STRING,value:o};92===r?(s||(o=e.substring(n,i),s=!0),i++,o+=e[i]):s&&(o+=e[i]),i++}throw new q(`Unterminated string starting with ${String.fromCharCode(t)}`,i,e.substring(Math.max(0,i-10),i))}function a(){const t=i;for(45===e.charCodeAt(i)&&i++;i<r&&H(e.charCodeAt(i));)i++;if(i<r&&46===e.charCodeAt(i))for(i++;i<r&&H(e.charCodeAt(i));)i++;const n=e.slice(t,i);return{type:B.NUMBER,value:n}}function u(){i++;const t=i;if(i<r&&X(e.charCodeAt(i)))for(i++;i<r&&Q(e.charCodeAt(i));)i++;const n=e.slice(t,i);return{type:B.FUNCTION,value:n}}function c(){const t=i++;for(;i<r&&Q(e.charCodeAt(i));)i++;const n=e.slice(t,i),o=U.get(n);return o?{type:o,value:n}:{type:B.IDENTIFIER,value:n}}function h(){if(i+2<r){const t=e.substring(i,i+3);if(G.has(t))return i+=3,{type:B.OPERATOR,value:t}}if(i+1<r){const t=e.substring(i,i+2);if(G.has(t))return i+=2,{type:B.OPERATOR,value:t}}const t=e[i];if(G.has(t))return i++,{type:B.OPERATOR,value:t};throw new q(`Unknown operator at position ${i}: ${e.substring(i,i+1)}`,i,e.substring(Math.max(0,i-10),i))}for(;i<r;){const t=e.charCodeAt(i);if(l=t,V.has(l)){i++;continue}const d=Y.get(t);if(d)n[o++]=d,i++;else if(34!==t&&39!==t)if(H(t)||45===t&&i+1<r&&H(e.charCodeAt(i+1)))n[o++]=a();else if(64!==t)if(X(t))n[o++]=c();else{if(!K(t))throw new q(`Unexpected character: ${e[i]}`,i,e.substring(Math.max(0,i-10),i));n[o++]=h()}else n[o++]=u();else n[o++]=s(t)}var l;return o===n.length?n:n.slice(0,o)})(t),r=nt(e),n=((t={},e={})=>({context:t,functions:e}))({},D);return(t={})=>ot(r,n,t)}function st(t,e){if("string"!=typeof t)return;const r=t.trim();if(r)try{return it(r),function(t,e={}){return it(t)(e)}(r,e)}catch(t){return}}function at(t){if(!t)return[0,0,0];if(A(t))return[t,t,t];if(Array.isArray(t)&&0===t.length)return[0,0,0];const[e,r=e,n=e]=t;return[e,r,n]}function ut(t,e){if("function"==typeof t)return t;if("string"==typeof t){const r=t;return(...t)=>{const n={};for(let r=0;r<e.length;r++)n[e[r]]=t[r];return st(r,n)}}return()=>t}function ct(t,e,r="node"){if(E(t))return()=>e;if(S(t)){const n=ut(t,[r]);return t=>{const r=n(t);return A(r)?r:e}}return b(t)?t:A(t)?()=>t:()=>e}function ht(t,e=10,r="node"){if(E(t))return()=>e;if(S(t)){const n=ut(t,[r]);return t=>{const r=n(t);return function(t){return!!A(t)||!!Array.isArray(t)&&t.every(t=>A(t))}(r)?r:e}}return b(t)?t:A(t)||Array.isArray(t)?()=>t:()=>e}const lt=(t,e,r=10,n=0)=>{const o=ht(e,n),i=ht(t,r);return t=>{const[e,r,n]=at(i(t)),[s,a,u]=at(o(t));return[e+s,r+a,n+u]}},dt=(t,e)=>{const r=t.nodeCount(),n=Array.from({length:r},()=>[]),o={};let i=0;return t.forEachNode(t=>{o[t.id]=i++}),t.forEachEdge(t=>{const e=o[t.source],r=o[t.target];null!=e&&null!=r&&(n[e].push(r),n[r].push(e))}),n};function ft(t){const e=t.length;new Array(e).fill(0);const r=Array.from({length:e},()=>new Array(e).fill(1/0));for(let n=0;n<e;n++)r[n]=gt(t,n);return r}function gt(t,e){const r=t.length,n=new Array(r).fill(1/0);n[e]=0;const o=new pt;for(o.push([0,e]);!o.empty();){const[e,r]=o.pop();if(e!==n[r])continue;const i=t[r];for(let t=0;t<i.length;t++){const r=i[t],s=e+1;s<n[r]&&(n[r]=s,o.push([s,r]))}}return n}class pt{constructor(){this.data=[]}push(t){this.data.push(t),this.bubbleUp(this.data.length-1)}pop(){const t=this.data[0],e=this.data.pop();return this.data.length>0&&(this.data[0]=e,this.bubbleDown(0)),t}empty(){return 0===this.data.length}bubbleUp(t){const e=this.data;for(;t>0;){const r=t-1>>1;if(e[r][0]<=e[t][0])break;[e[r],e[t]]=[e[t],e[r]],t=r}}bubbleDown(t){const e=this.data,r=e.length;for(;;){const n=2*t+1,o=2*t+2;let i=t;if(n<r&&e[n][0]<e[i][0]&&(i=n),o<r&&e[o][0]<e[i][0]&&(i=o),i===t)break;[e[t],e[i]]=[e[i],e[t]],t=i}}}function vt(t,...e){return e.forEach(e=>{e&&Object.keys(e).forEach(r=>{const n=e[r];void 0!==n&&(t[r]=n)})}),t}function mt(t,e){const r=t.nodes();return r.sort(e),t.setNodeOrder(r),t}function yt(t,e="desc"){return mt(t,(r,n)=>{const o=t.degree(r.id),i=t.degree(n.id);return"asc"===e?o-i:i-o})}function wt(t,e){return mt(t,(r,n)=>{const o=t.originalNode(r.id),i=t.originalNode(n.id);return e(o,i)})}function xt(t,e=!1){const r=t.nodeCount();if(0===r)return t;const n=t.nodes(),o=[n[0]],i={};i[n[0].id]=!0;let s=0,a=0;return t.forEachNode(u=>{if(0!==a){const c=t.degree(u.id,"both"),h=a<r-1?t.degree(n[a+1].id,"both"):0,l=o[s].id,d=t.neighbors(l,"both").includes(u.id);if(a!==r-1&&c===h&&!d||i[u.id]){const s=e?t.successors(l):t.neighbors(l);let a=!1;for(let e=0;e<s.length;e++){const r=s[e],n=t.node(r);if(n&&t.degree(r)===t.degree(u.id)&&!i[r]){o.push(n),i[r]=!0,a=!0;break}}let c=0;for(;!a&&(i[n[c].id]||(o.push(n[c]),i[n[c].id]=!0,a=!0),c++,c!==r););}else o.push(u),i[u.id]=!0,s++}a++}),t.setNodeOrder(o),t}function bt(t){var e;return[t.x,t.y,null!==(e=t.z)&&void 0!==e?e:0]}const Et=t=>{const{width:e,height:r,center:n}=t,o=null!=e?e:"undefined"!=typeof window?window.innerWidth:0,i=null!=r?r:"undefined"!=typeof window?window.innerHeight:0;return{width:o,height:i,center:null!=n?n:[o/2,i/2]}};class Mt{constructor(t,e={}){this.edgeIdCounter=new Map,this.nodeMap=function(t,e){if(!t)throw new Error("Data.nodes is required");const r=new Map;for(const n of t){const t={_original:n};for(const e of Nt){const r=n[e];E(r)||(t[e]=r)}if(e){const r=e(n);for(const e in r){const n=r[e];E(n)||(t[e]=n)}}if(E(t.id))throw new Error("Node is missing id field");r.set(t.id,t)}return r}(t.nodes,e.node),this.edgeMap=function(t,e,r){const n=new Map;for(const o of t){const t={_original:o};for(const e of _t){const r=o[e];E(r)||(t[e]=r)}if(e){const r=e(o);for(const e in r){const n=r[e];E(n)||(t[e]=n)}}if(E(t.source)||E(t.target))throw new Error("Edge is missing source or target field");E(t.id)&&(t.id=null==r?void 0:r(o)),n.set(t.id,t)}return n}(t.edges||[],e.edge,this.getEdgeId.bind(this))}data(){return{nodes:this.nodeMap,edges:this.edgeMap}}replace(t){this.nodeMap=t.nodes,this.edgeMap=t.edges,this.clearCache()}nodes(){return Array.from(this.nodeMap.values())}node(t){return this.nodeMap.get(t)}nodeAt(t){this.indexNodeCache||this.buildNodeIndexCache();const e=this.indexNodeCache.get(t);return e?this.nodeMap.get(e):void 0}nodeIndexOf(t){var e;return this.nodeIndexCache||this.buildNodeIndexCache(),null!==(e=this.nodeIndexCache.get(t))&&void 0!==e?e:-1}firstNode(){return this.nodeMap.values().next().value}forEachNode(t){let e=0;this.nodeMap.forEach(r=>t(r,e++))}originalNode(t){const e=this.nodeMap.get(t);return null==e?void 0:e._original}nodeCount(){return this.nodeMap.size}edges(){return Array.from(this.edgeMap.values())}edge(t){return this.edgeMap.get(t)}firstEdge(){return this.edgeMap.values().next().value}forEachEdge(t){let e=0;this.edgeMap.forEach(r=>t(r,e++))}originalEdge(t){const e=this.edgeMap.get(t);return null==e?void 0:e._original}edgeCount(){return this.edgeMap.size}getEdgeId(t){if(t.id)return t.id;const e=`${t.source}-${t.target}`,r=this.edgeIdCounter.get(e)||0,n=0===r?e:`${e}-${r}`;return this.edgeIdCounter.set(e,r+1),n}degree(t,e="both"){this.degreeCache||this.buildDegreeCache();const r=this.degreeCache.get(t);return r?r[e]:0}neighbors(t,e="both"){if(this.outAdjacencyCache&&this.inAdjacencyCache||this.buildAdjacencyCache(),"out"===e)return Array.from(this.outAdjacencyCache.get(t)||[]);if("in"===e)return Array.from(this.inAdjacencyCache.get(t)||[]);if(this.bothAdjacencyCache)return Array.from(this.bothAdjacencyCache.get(t)||[]);const r=this.inAdjacencyCache.get(t),n=this.outAdjacencyCache.get(t);if(!r&&!n)return[];if(!r)return Array.from(n);if(!n)return Array.from(r);const o=new Set;return r.forEach(t=>o.add(t)),n.forEach(t=>o.add(t)),Array.from(o)}successors(t){return this.neighbors(t,"out")}predecessors(t){return this.neighbors(t,"in")}setNodeOrder(t){const e=new Map;for(const r of t)e.set(r.id,r);this.nodeMap=e,this.nodeIndexCache=void 0,this.indexNodeCache=void 0}clearCache(){this.degreeCache=void 0,this.inAdjacencyCache=void 0,this.outAdjacencyCache=void 0,this.bothAdjacencyCache=void 0,this.nodeIndexCache=void 0,this.indexNodeCache=void 0}buildDegreeCache(){this.degreeCache=new Map;for(const t of this.edges()){const{source:e,target:r}=t;if(t.source===t.target)continue;this.degreeCache.has(e)||this.degreeCache.set(e,{in:0,out:0,both:0});const n=this.degreeCache.get(t.source);n&&(n.out++,n.both++),this.degreeCache.has(r)||this.degreeCache.set(r,{in:0,out:0,both:0});const o=this.degreeCache.get(t.target);o&&(o.in++,o.both++)}}buildAdjacencyCache(){this.inAdjacencyCache=new Map,this.outAdjacencyCache=new Map;for(const t of this.edges())this.nodeMap.has(t.source)&&this.nodeMap.has(t.target)&&(this.outAdjacencyCache.has(t.source)||this.outAdjacencyCache.set(t.source,new Set),this.outAdjacencyCache.get(t.source).add(t.target),this.inAdjacencyCache.has(t.target)||this.inAdjacencyCache.set(t.target,new Set),this.inAdjacencyCache.get(t.target).add(t.source))}buildNodeIndexCache(){this.nodeIndexCache=new Map,this.indexNodeCache=new Map;let t=0;this.nodeMap.forEach((e,r)=>{this.nodeIndexCache.set(r,t),this.indexNodeCache.set(t,r),t++})}destroy(){this.clearCache(),this.nodeMap.clear(),this.edgeMap.clear(),this.edgeIdCounter.clear()}}const Nt=["id","x","y","z","vx","vy","vz","fx","fy","fz","parentId"],_t=["id","source","target","points"];function kt(t,e,r,n=2){t.forEachNode(t=>{E(t.x)&&(t.x=Math.random()*e),E(t.y)&&(t.y=Math.random()*r),3===n&&E(t.z)&&(t.z=Math.random()*Math.min(e,r))})}class St{constructor(t,e={}){this.graph=new Mt(t,e)}export(){return this.graph.data()}replace(t){this.graph.replace(t)}forEachNode(t){this.graph.forEachNode(t)}forEachEdge(t){this.graph.forEachEdge((e,r)=>{e.sourceNode=this.graph.node(e.source),e.targetNode=this.graph.node(e.target),t(e,r)})}destroy(){this.graph.destroy()}}class At{constructor(){this.worker=null,this.workerApi=null}execute(e,r,n){return t(this,void 0,void 0,function*(){if(this.worker||(yield this.initWorker()),!this.workerApi)throw new Error("Worker API not initialized");return yield this.workerApi.execute(e,r,n)})}destroy(){this.workerApi&&this.workerApi.destroy(),this.worker&&(this.worker.terminate(),this.worker=null,this.workerApi=null)}initWorker(){return t(this,void 0,void 0,function*(){const t=this.resolveWorkerPath(),e=t.includes("/lib/")||t.endsWith(".mjs")?"module":"classic";this.worker=new Worker(t,{type:e}),this.workerApi=h(this.worker)})}resolveWorkerPath(){const t=(()=>{if("undefined"==typeof document)return null;const t=document.currentScript;if(null==t?void 0:t.src)return t.src;const e=document.getElementsByTagName("script");for(let t=e.length-1;t>=0;t--){const r=e[t].src;if(r&&(r.includes("index.js")||r.includes("index.min.js")))return r}return null})();if(t){if(t.includes("index.js")||t.includes("index.min.js")){const e=t.replace(/index(\.min)?\.(m?js)(\?.*)?$/,"worker.js");if(e!==t)return e}const e=t.replace(/\/runtime\/[^/]+\.(m?js)(\?.*)?$/,"/worker.js");if(e!==t)return e;const r=t.replace(/\/[^/]+\.(m?js)(\?.*)?$/,"/worker.js");if(r!==t)return r}return"./worker.js"}}class Ot{constructor(t){this.supervisor=null,this.initialOptions=this.mergeOptions(this.getDefaultOptions(),t)}get options(){return this.runtimeOptions||this.initialOptions}mergeOptions(t,e){return Object.assign({},t,e||{})}execute(e,r){return t(this,void 0,void 0,function*(){this.runtimeOptions=this.mergeOptions(this.initialOptions,r);const{node:t,edge:n,enableWorker:o}=this.runtimeOptions;this.context=new St(e,{node:t,edge:n}),this.model=this.context.graph;o&&"undefined"!=typeof Worker?yield this.layoutInWorker(e,this.runtimeOptions):yield this.layout(this.runtimeOptions)})}layoutInWorker(e,r){var n;return t(this,void 0,void 0,function*(){try{this.supervisor||(this.supervisor=new At);const t=yield this.supervisor.execute(this.id,e,r);null===(n=this.context)||void 0===n||n.replace(t)}catch(t){console.error("Layout in worker failed, fallback to main thread layout.",t),yield this.layout(r)}})}forEachNode(t){this.context.forEachNode(t)}forEachEdge(t){this.context.forEachEdge(t)}destroy(){var t;null===(t=this.context)||void 0===t||t.destroy(),this.model=null,this.context=null,this.supervisor&&(this.supervisor.destroy(),this.supervisor=null)}}class zt extends Ot{}class jt{constructor(t={}){this.options=t,this.nodes=new Map,this.edges=new Map,this.inEdges=new Map,this.outEdges=new Map,this.parentMap=new Map,this.childrenMap=new Map,t.tree&&Array.isArray(t.tree)&&t.tree.length>0&&("string"==typeof t.tree[0]?t.tree.forEach(t=>{this.parentMap.set(t,new Map),this.childrenMap.set(t,new Map)}):(this.attachTreeStructure("default"),this.addTree(t.tree))),t.nodes&&t.nodes.forEach(t=>this.addNode(t)),t.edges&&t.edges.forEach(t=>this.addEdge(t))}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.inEdges.set(t.id,new Set),this.outEdges.set(t.id,new Set))}addNodes(t){t.forEach(t=>this.addNode(t))}getNode(t){return this.nodes.get(t)}hasNode(t){return this.nodes.has(t)}removeNode(t){if(!this.nodes.has(t))return;const e=Array.from(this.inEdges.get(t)||[]),r=Array.from(this.outEdges.get(t)||[]);e.forEach(t=>this.removeEdge(t)),r.forEach(t=>this.removeEdge(t)),this.nodes.delete(t),this.inEdges.delete(t),this.outEdges.delete(t),this.parentMap.forEach(e=>{e.delete(t)}),this.childrenMap.forEach(e=>{e.delete(t)})}getAllNodes(){return Array.from(this.nodes.values())}addEdge(t){if(!this.nodes.has(t.source)||!this.nodes.has(t.target))throw new Error(`Cannot add edge ${t.id}: source ${t.source} or target ${t.target} does not exist`);this.edges.set(t.id,t),this.outEdges.get(t.source).add(t.id),this.inEdges.get(t.target).add(t.id)}addEdges(t){t.forEach(t=>this.addEdge(t))}getEdge(t){return this.edges.get(t)}hasEdge(t){return this.edges.has(t)}removeEdge(t){var e,r;const n=this.edges.get(t);n&&(this.edges.delete(t),null===(e=this.outEdges.get(n.source))||void 0===e||e.delete(t),null===(r=this.inEdges.get(n.target))||void 0===r||r.delete(t))}getAllEdges(){return Array.from(this.edges.values())}updateEdgeData(t,e){const r=this.edges.get(t);r&&Object.assign(r.data,e)}updateNodeData(t,e){const r=this.nodes.get(t);r&&Object.assign(r.data,e)}getRelatedEdges(t,e="both"){const r=[];if("in"===e||"both"===e){const e=this.inEdges.get(t);e&&e.forEach(t=>{const e=this.edges.get(t);e&&r.push(e)})}if("out"===e||"both"===e){const e=this.outEdges.get(t);e&&e.forEach(t=>{const e=this.edges.get(t);e&&r.push(e)})}return r}getSuccessors(t){const e=this.outEdges.get(t);if(!e||0===e.size)return[];const r=[];return e.forEach(t=>{const e=this.edges.get(t);if(e){const t=this.nodes.get(e.target);t&&r.push(t)}}),r.length>0?r:[]}getPredecessors(t){const e=this.inEdges.get(t);if(!e||0===e.size)return[];const r=[];return e.forEach(t=>{const e=this.edges.get(t);if(e){const t=this.nodes.get(e.source);t&&r.push(t)}}),r.length>0?r:[]}getNeighbors(t){const e=[...this.getSuccessors(t)||[],...this.getPredecessors(t)||[]],r=Array.from(new Map(e.map(t=>[t.id,t])).values());return r.length>0?r:[]}attachTreeStructure(t){this.parentMap.has(t)||(this.parentMap.set(t,new Map),this.childrenMap.set(t,new Map))}addTree(t,e){var r,n;const o=e||(null!==(n=null===(r=this.options.tree)||void 0===r?void 0:r[0])&&void 0!==n?n:"default");this.hasTreeStructure(o)||this.attachTreeStructure(o);const i=Array.isArray(t)?t:[t],s=(t,e)=>{this.addNode({id:t.id,data:t.data}),void 0!==e&&this.setParent(t.id,e,o),t.children&&t.children.length>0&&t.children.forEach(e=>{s(e,t.id)})};i.forEach(t=>s(t))}hasTreeStructure(t){return this.parentMap.has(t)}setParent(t,e,r){var n,o,i;const s=r||(null!==(o=null===(n=this.options.tree)||void 0===n?void 0:n[0])&&void 0!==o?o:"default");this.parentMap.has(s)||this.attachTreeStructure(s);const a=this.parentMap.get(s),u=this.childrenMap.get(s),c=a.get(t);void 0!==c&&(null===(i=u.get(c))||void 0===i||i.delete(t)),a.set(t,e),u.has(e)||u.set(e,new Set),u.get(e).add(t)}getParent(t,e){var r,n;const o=e||(null!==(n=null===(r=this.options.tree)||void 0===r?void 0:r[0])&&void 0!==n?n:"default");this.parentMap.has(o)||this.attachTreeStructure(o);const i=this.parentMap.get(o);if(!i)return;const s=i.get(t);return void 0===s?null:this.nodes.get(s)}getChildren(t,e){var r,n;const o=e||(null!==(n=null===(r=this.options.tree)||void 0===r?void 0:r[0])&&void 0!==n?n:"default"),i=this.childrenMap.get(o);if(!i)return[];const s=i.get(t);return s?Array.from(s).map(t=>this.nodes.get(t)).filter(t=>void 0!==t):[]}getRoots(t){var e,r;const n=t||(null!==(r=null===(e=this.options.tree)||void 0===e?void 0:e[0])&&void 0!==r?r:"default"),o=this.parentMap.get(n),i=[];return this.nodes.forEach(t=>{o&&void 0!==o.get(t.id)||i.push(t)}),i}dfsTree(t,e){const r=[t],n=new Set;for(;r.length>0;){const t=r.pop();if(n.has(t))continue;const o=this.getNode(t);if(o){n.add(t);if(!0===e(o))continue;const i=this.getChildren(t);for(let t=i.length-1;t>=0;t--)n.has(i[t].id)||r.push(i[t].id)}}}}const Ct=(t,e)=>{if("next"!==t&&"prev"!==t)return e},It=t=>{t.prev.next=t.next,t.next.prev=t.prev,delete t.next,delete t.prev};let Rt=class{constructor(){const t={};t.prev=t,t.next=t.prev,this.shortcut=t}dequeue(){const t=this.shortcut,e=t.prev;if(e&&e!==t)return It(e),e}enqueue(t){const e=this.shortcut;t.prev&&t.next&&It(t),t.next=e.next,e.next.prev=t,e.next=t,t.prev=e}toString(){const t=[],e=this.shortcut;let r=e.prev;for(;r!==e;)t.push(JSON.stringify(r,Ct)),r=null==r?void 0:r.prev;return`[${t.join(", ")}]`}};class Tt extends Rt{}const Pt=()=>1,Ft=(t,e,r)=>{let n=[];const o=e[e.length-1],i=e[0];let s;for(;t.getAllNodes().length;){for(;s=i.dequeue();)Lt(t,e,r,s);for(;s=o.dequeue();)Lt(t,e,r,s);if(t.getAllNodes().length)for(let o=e.length-2;o>0;--o)if(s=e[o].dequeue(),s){n=n.concat(Lt(t,e,r,s,!0));break}}return n},Lt=(t,e,r,n,o)=>{var i,s;const a=[];return t.hasNode(n.v)&&(null===(i=t.getRelatedEdges(n.v,"in"))||void 0===i||i.forEach(n=>{const i=n.data.weight,s=t.getNode(n.source);o&&a.push({v:n.source,w:n.target,in:0,out:0}),void 0===s.data.out&&(s.data.out=0),s.data.out-=i,qt(e,r,Object.assign({v:s.id},s.data))}),null===(s=t.getRelatedEdges(n.v,"out"))||void 0===s||s.forEach(n=>{const o=n.data.weight,i=n.target,s=t.getNode(i);void 0===s.data.in&&(s.data.in=0),s.data.in-=o,qt(e,r,Object.assign({v:s.id},s.data))}),t.removeNode(n.v)),o?a:void 0},Dt=(t,e)=>{const r=new jt;let n=0,o=0;t.getAllNodes().forEach(t=>{r.addNode({id:t.id,data:{v:t.id,in:0,out:0}})}),t.getAllEdges().forEach(t=>{const i=r.getRelatedEdges(t.source,"out").find(e=>e.target===t.target),s=(null==e?void 0:e(t))||1;i?r.updateEdgeData(null==i?void 0:i.id,Object.assign(Object.assign({},i.data),{weight:i.data.weight+s})):r.addEdge({id:t.id,source:t.source,target:t.target,data:{weight:s}}),o=Math.max(o,r.getNode(t.source).data.out+=s),n=Math.max(n,r.getNode(t.target).data.in+=s)});const i=[],s=o+n+3;for(let t=0;t<s;t++)i.push(new Tt);const a=n+1;return r.getAllNodes().forEach(t=>{qt(i,a,Object.assign({v:t.id},r.getNode(t.id).data))}),{buckets:i,zeroIdx:a,graph:r}},qt=(t,e,r)=>{r.out?r.in?t[r.out-r.in+e].enqueue(r):t[t.length-1].enqueue(r):t[0].enqueue(r)},Bt=(t,e)=>{const r=((t,e)=>{var r;if(t.getAllNodes().length<=1)return[];const n=Dt(t,e||Pt);return null===(r=Ft(n.graph,n.buckets,n.zeroIdx).map(e=>t.getRelatedEdges(e.v,"out").filter(({target:t})=>t===e.w)))||void 0===r?void 0:r.flat()})(t,t=>t.data.weight||1);null==r||r.forEach(e=>{const r=e.data;t.removeEdge(e.id),r.forwardName=e.data.name,r.reversed=!0,t.addEdge({id:e.id,source:e.target,target:e.source,data:Object.assign({},r)})})},Vt=(t,e,r,n)=>{let o;do{o=`${n}${Math.random()}`}while(t.hasNode(o));return r.dummy=e,t.addNode({id:o,data:r}),o},$t=t=>{const e=new jt;return t.getAllNodes().forEach(r=>{t.getChildren(r.id).length||e.addNode(Object.assign({},r))}),t.getAllEdges().forEach(t=>{e.addEdge(t)}),e},Ut=(t,e)=>{const r=Number(t.x),n=Number(t.y),o=Number(e.x)-r,i=Number(e.y)-n;let s,a,u=Number(t.width)/2,c=Number(t.height)/2;return o||i?(Math.abs(i)*u>Math.abs(o)*c?(i<0&&(c=-c),s=c*o/i,a=c):(o<0&&(u=-u),s=u,a=u*i/o),{x:r+s,y:n+a}):{x:0,y:0}},Gt=t=>{const e=[],r=Yt(t)+1;for(let t=0;t<r;t++)e.push([]);t.getAllNodes().forEach(t=>{const r=t.data.rank;void 0!==r&&e[r]&&e[r].push(t.id)});for(let n=0;n<r;n++)e[n]=e[n].sort((e,r)=>{return n=t.getNode(e).data.order,o=t.getNode(r).data.order,Number(n)-Number(o);var n,o});return e},Wt=(t,e,r,n)=>{const o={width:0,height:0};return A(r)&&A(n)&&(o.rank=r,o.order=n),Vt(t,"border",o,e)},Yt=t=>{let e;return t.getAllNodes().forEach(t=>{const r=t.data.rank;void 0!==r&&(void 0===e||r>e)&&(e=r)}),e||(e=0),e},Ht=(t,e)=>t.reduce((t,r)=>e(t)>e(r)?r:t),Xt=(t,e,r,n,o,i)=>{if(!n.includes(e.id)){n.push(e.id),r||i.push(e.id);const s=o(e.id);s&&s.forEach(e=>Xt(t,e,r,n,o,i)),r&&i.push(e.id)}},Qt=(t,e,r,n)=>{const o=Array.isArray(e)?e:[e],i=e=>t.getNeighbors(e),s=[],a=[];return o.forEach(e=>{if(!t.hasNode(e.id))throw new Error(`Graph does not have node: ${e}`);Xt(t,e,"post"===r,a,i,s)}),s},Kt=(t,e,r,n,o,i)=>{const s={rank:i,borderType:e,width:0,height:0},a=i-o.data.minRank,u=o.data[e][a-1],c=Vt(t,"border",s,r);o.data[e][a]=c,t.setParent(c,n),u&&t.addEdge({id:`e${Math.random()}`,source:u,target:c,data:{weight:1}})},Jt=t=>{t.getAllNodes().forEach(t=>{Zt(t)}),t.getAllEdges().forEach(t=>{Zt(t)})},Zt=t=>{const e=t.data.width;t.data.width=t.data.height,t.data.height=e},te=t=>{t.getAllNodes().forEach(t=>{ee(t.data)}),t.getAllEdges().forEach(t=>{var e;null===(e=t.data.points)||void 0===e||e.forEach(t=>ee(t)),t.data.hasOwnProperty("y")&&ee(t.data)})},ee=t=>{(null==t?void 0:t.y)&&(t.y=-t.y)},re=t=>{t.getAllNodes().forEach(t=>{ne(t.data)}),t.getAllEdges().forEach(t=>{var e;null===(e=t.data.points)||void 0===e||e.forEach(t=>ne(t)),t.data.hasOwnProperty("x")&&ne(t.data)})},ne=t=>{const e=t.x;t.x=t.y,t.y=e},oe=(t,e,r,n,o,i,s)=>{const a=t.getChildren(s);if(!(null==a?void 0:a.length))return void(s!==e&&t.addEdge({id:`e${Math.random()}`,source:e,target:s,data:{weight:0,minlen:r}}));const u=Wt(t,"_bt"),c=Wt(t,"_bb"),h=t.getNode(s);t.setParent(u,s),h.data.borderTop=u,t.setParent(c,s),h.data.borderBottom=c,null==a||a.forEach(a=>{oe(t,e,r,n,o,i,a.id);const h=a.data.borderTop?a.data.borderTop:a.id,l=a.data.borderBottom?a.data.borderBottom:a.id,d=a.data.borderTop?n:2*n,f=h!==l?1:o-i[s]+1;t.addEdge({id:`e${Math.random()}`,source:u,target:h,data:{minlen:f,weight:d,nestingEdge:!0}}),t.addEdge({id:`e${Math.random()}`,source:l,target:c,data:{minlen:f,weight:d,nestingEdge:!0}})}),t.getParent(s)||t.addEdge({id:`e${Math.random()}`,source:e,target:u,data:{weight:0,minlen:o+i[s]}})},ie=t=>{const e={},r=(n,o)=>{const i=t.getChildren(n);null==i||i.forEach(t=>r(t.id,o+1)),e[n]=o};return t.getRoots().forEach(t=>r(t.id,1)),e},se=t=>{let e=0;return t.getAllEdges().forEach(t=>{e+=t.data.weight}),e},ae="edge-label",ue=(t,e,r)=>{let n=e.source,o=t.getNode(n).data.rank;const i=e.target,s=t.getNode(i).data.rank,a=e.data.labelRank;if(s===o+1)return;let u,c,h;for(t.removeEdge(e.id),h=0,++o;o<s;++h,++o)e.data.points=[],c={originalEdge:e,width:0,height:0,rank:o},u=Vt(t,"edge",c,"_d"),o===a&&(c.width=e.data.width,c.height=e.data.height,c.dummy=ae,c.labelpos=e.data.labelpos),t.addEdge({id:`e${Math.random()}`,source:n,target:u,data:{weight:e.data.weight}}),0===h&&r.push(u),n=u;t.addEdge({id:`e${Math.random()}`,source:n,target:i,data:{weight:e.data.weight}})},ce=t=>{let e;for(;t.hasNode(e=`_root${Math.random()}`););return e},he=(t,e,r)=>{const n=(o=r,i=r.map((t,e)=>e),null==o?void 0:o.reduce((t,e,r)=>(t[e]=i[r],t),{}));var o,i;const s=e.map(e=>{const r=t.getRelatedEdges(e,"out").map(t=>({pos:n[t.target]||0,weight:t.data.weight}));return null==r?void 0:r.sort((t,e)=>t.pos-e.pos)}),a=s.flat().filter(t=>void 0!==t);let u=1;for(;u<r.length;)u<<=1;const c=2*u-1;u-=1;const h=Array(c).fill(0,0,c);let l=0;return null==a||a.forEach(t=>{if(t){let e=t.pos+u;h[e]+=t.weight;let r=0;for(;e>0;)e%2&&(r+=h[e+1]),e=e-1>>1,h[e]+=t.weight;l+=t.weight*r}}),l},le=(t,e)=>{let r=0;for(let n=1;n<(null==e?void 0:e.length);n+=1)r+=he(t,e[n-1],e[n]);return r},de=t=>{const e={},r=t.getAllNodes(),n=r.map(t=>{var e;return null!==(e=t.data.rank)&&void 0!==e?e:-1/0}),o=Math.max(...n),i=[];for(let t=0;t<o+1;t++)i.push([]);const s=r.sort((e,r)=>t.getNode(e.id).data.rank-t.getNode(r.id).data.rank),a=s.filter(e=>void 0!==t.getNode(e.id).data.fixorder),u=a.sort((e,r)=>t.getNode(e.id).data.fixorder-t.getNode(r.id).data.fixorder);return null==u||u.forEach(r=>{isNaN(t.getNode(r.id).data.rank)||i[t.getNode(r.id).data.rank].push(r.id),e[r.id]=!0}),null==s||s.forEach(r=>t.dfsTree(r.id,t=>{if(e.hasOwnProperty(t.id))return!0;e[t.id]=!0,isNaN(t.data.rank)||i[t.data.rank].push(t.id)})),i},fe=t=>{var e,r;const n=[];for(;null==t?void 0:t.length;){const o=t.pop();n.push(o),null===(e=o.in.reverse())||void 0===e||e.forEach(t=>{return(e=o,t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&ge(e,t)})(t);var e}),null===(r=o.out)||void 0===r||r.forEach(e=>{return(r=o,e=>{e.in.push(r),0===--e.indegree&&t.push(e)})(e);var r})}const o=n.filter(t=>!t.merged),i=["vs","i","barycenter","weight"];return o.map(t=>{const e={};return null==i||i.forEach(r=>{void 0!==t[r]&&(e[r]=t[r])}),e})},ge=(t,e)=>{var r;let n=0,o=0;t.weight&&(n+=t.barycenter*t.weight,o+=t.weight),e.weight&&(n+=e.barycenter*e.weight,o+=e.weight),t.vs=null===(r=e.vs)||void 0===r?void 0:r.concat(t.vs),t.barycenter=n/o,t.weight=o,t.i=Math.min(e.i,t.i),e.merged=!0},pe=(t,e,r)=>{let n,o=r;for(;e.length&&(n=e[e.length-1]).i<=o;)e.pop(),null==t||t.push(n.vs),o++;return o},ve=(t,e)=>(r,n)=>{if(void 0!==r.fixorder&&void 0!==n.fixorder)return r.fixorder-n.fixorder;if(r.barycenter<n.barycenter)return-1;if(r.barycenter>n.barycenter)return 1;if(e&&void 0!==r.order&&void 0!==n.order){if(r.order<n.order)return-1;if(r.order>n.order)return 1}return t?n.i-r.i:r.i-n.i},me=(t,e,r,n,o,i)=>{var s,a,u,c;let h=t.getChildren(e).map(t=>t.id);const l=t.getNode(e),d=l?l.data.borderLeft:void 0,f=l?l.data.borderRight:void 0,g={};d&&(h=null==h?void 0:h.filter(t=>t!==d&&t!==f));const p=((t,e)=>e.map(e=>{const r=t.getRelatedEdges(e,"in");if(!(null==r?void 0:r.length))return{v:e};const n={sum:0,weight:0};return null==r||r.forEach(e=>{const r=t.getNode(e.source);n.sum+=e.data.weight*r.data.order,n.weight+=e.data.weight}),{v:e,barycenter:n.sum/n.weight,weight:n.weight}}))(t,h||[]);null==p||p.forEach(e=>{var o;if(null===(o=t.getChildren(e.v))||void 0===o?void 0:o.length){const o=me(t,e.v,r,n,i);g[e.v]=o,o.hasOwnProperty("barycenter")&&we(e,o)}});const v=((t,e)=>{var r,n,o;const i={};null==t||t.forEach((t,e)=>{i[t.v]={i:e,indegree:0,in:[],out:[],vs:[t.v]};const r=i[t.v];void 0!==t.barycenter&&(r.barycenter=t.barycenter,r.weight=t.weight)}),null===(r=e.getAllEdges())||void 0===r||r.forEach(t=>{const e=i[t.source],r=i[t.target];void 0!==e&&void 0!==r&&(r.indegree++,e.out.push(i[t.target]))});const s=null===(o=(n=Object.values(i)).filter)||void 0===o?void 0:o.call(n,t=>!t.indegree);return fe(s)})(p,r);ye(v,g),null===(s=v.filter(t=>t.vs.length>0))||void 0===s||s.forEach(e=>{const r=t.getNode(e.vs[0]);r&&(e.fixorder=r.data.fixorder,e.order=r.data.order)});const m=((t,e,r,n)=>{const o=((t,e)=>{const r={lhs:[],rhs:[]};return null==t||t.forEach(t=>{e(t)?r.lhs.push(t):r.rhs.push(t)}),r})(t,t=>{const e=t.hasOwnProperty("fixorder")&&!isNaN(t.fixorder);return n?!e&&t.hasOwnProperty("barycenter"):e||t.hasOwnProperty("barycenter")}),i=o.lhs,s=o.rhs.sort((t,e)=>-t.i- -e.i),a=[];let u=0,c=0,h=0;null==i||i.sort(ve(!!e,!!r)),h=pe(a,s,h),null==i||i.forEach(t=>{var e;h+=null===(e=t.vs)||void 0===e?void 0:e.length,a.push(t.vs),u+=t.barycenter*t.weight,c+=t.weight,h=pe(a,s,h)});const l={vs:a.flat()};return c&&(l.barycenter=u/c,l.weight=c),l})(v,n,o,i);if(d&&(m.vs=[d,m.vs,f].flat(),null===(a=t.getPredecessors(d))||void 0===a?void 0:a.length)){const e=t.getNode((null===(u=t.getPredecessors(d))||void 0===u?void 0:u[0].id)||""),r=t.getNode((null===(c=t.getPredecessors(f))||void 0===c?void 0:c[0].id)||"");m.hasOwnProperty("barycenter")||(m.barycenter=0,m.weight=0),m.barycenter=(m.barycenter*m.weight+e.data.order+r.data.order)/(m.weight+2),m.weight+=2}return m},ye=(t,e)=>{null==t||t.forEach(t=>{var r;const n=null===(r=t.vs)||void 0===r?void 0:r.map(t=>e[t]?e[t].vs:t);t.vs=n.flat()})},we=(t,e)=>{void 0!==t.barycenter?(t.barycenter=(t.barycenter*t.weight+e.barycenter*e.weight)/(t.weight+e.weight),t.weight+=e.weight):(t.barycenter=e.barycenter,t.weight=e.weight)},xe=(t,e,r)=>e.map(e=>((t,e,r)=>{const n=ce(t),o=new jt;return o.addNode({id:n,data:{}}),t.getAllNodes().forEach(i=>{var s,a;const u=t.getParent(i.id);(i.data.rank===e||i.data.minRank<=e&&e<=i.data.maxRank)&&(o.hasNode(i.id)||o.addNode(Object.assign({},i)),(null==u?void 0:u.id)&&!o.hasNode(null==u?void 0:u.id)&&o.addNode(Object.assign({},u)),o.setParent(i.id,(null==u?void 0:u.id)||n),t.getRelatedEdges(i.id,r).forEach(e=>{const r=e.source===i.id?e.target:e.source;o.hasNode(r)||o.addNode(Object.assign({},t.getNode(r)));const n=o.getRelatedEdges(r,"out").find(({target:t})=>t===i.id),s=void 0!==n?n.data.weight:0;n?o.updateEdgeData(n.id,Object.assign(Object.assign({},n.data),{weight:e.data.weight+s})):o.addEdge({id:e.id,source:r,target:i.id,data:{weight:e.data.weight+s}})}),i.data.hasOwnProperty("minRank")&&o.updateNodeData(i.id,Object.assign(Object.assign({},i.data),{borderLeft:[null===(s=i.data.borderLeft)||void 0===s?void 0:s[e-i.data.minRank]],borderRight:[null===(a=i.data.borderRight)||void 0===a?void 0:a[e-i.data.minRank]]})))}),o})(t,e,r)),be=(t,e,r,n)=>{const o=new jt;null==t||t.forEach(t=>{var i;const s=t.getRoots()[0].id,a=me(t,s,o,e,r,n);for(let e=0;e<(null===(i=a.vs)||void 0===i?void 0:i.length);e++){const r=t.getNode(a.vs[e]);r&&(r.data.order=e)}((t,e,r)=>{const n={};let o;null==r||r.forEach(r=>{let i,s,a=t.getParent(r);for(;a;){if(i=t.getParent(a.id),i?(s=n[i.id],n[i.id]=a.id):(s=o,o=a.id),s&&s!==a.id)return e.hasNode(s)||e.addNode({id:s,data:{}}),e.hasNode(a.id)||e.addNode({id:a.id,data:{}}),void(e.hasEdge(`e${s}-${a.id}`)||e.addEdge({id:`e${s}-${a.id}`,source:s,target:a.id,data:{}}));a=i}})})(t,o,a.vs)})},Ee=(t,e)=>{null==e||e.forEach(e=>{null==e||e.forEach((e,r)=>{t.getNode(e).data.order=r})})},Me=(t,e)=>{const r=(t=>{const e={};let r=0;const n=o=>{const i=r;t.getChildren(o).forEach(t=>n(t.id)),e[o]={low:i,lim:r++}};return t.getRoots().forEach(t=>n(t.id)),e})(t);e.forEach(e=>{var n,o;let i=e,s=t.getNode(i);const a=s.data.originalEdge;if(!a)return;const u=((t,e,r,n)=>{var o,i;const s=[],a=[],u=Math.min(e[r].low,e[n].low),c=Math.max(e[r].lim,e[n].lim);let h,l;h=r;do{h=null===(o=t.getParent(h))||void 0===o?void 0:o.id,s.push(h)}while(h&&(e[h].low>u||c>e[h].lim));for(l=h,h=n;h&&h!==l;)a.push(h),h=null===(i=t.getParent(h))||void 0===i?void 0:i.id;return{lca:l,path:s.concat(a.reverse())}})(t,r,a.source,a.target),c=u.path,h=u.lca;let l=0,d=c[l],f=!0;for(;i!==a.target;){if(s=t.getNode(i),f){for(;d!==h&&(null===(n=t.getNode(d))||void 0===n?void 0:n.data.maxRank)<s.data.rank;)l++,d=c[l];d===h&&(f=!1)}if(!f){for(;l<c.length-1&&(null===(o=t.getNode(c[l+1]))||void 0===o?void 0:o.data.minRank)<=s.data.rank;)l++;d=c[l]}t.hasNode(d)&&t.setParent(i,d),i=t.getSuccessors(i)[0].id}})},Ne=(t,e)=>{const r={};function n(e,n){const o=function(t){return JSON.stringify(t.slice(1))}(e);n.get(o)||(!function(e,n,o,i,s){var a,u;let c;for(let h=n;h<o;h++)c=e[h],(null===(a=t.getNode(c))||void 0===a?void 0:a.data.dummy)&&(null===(u=t.getPredecessors(c))||void 0===u||u.forEach(e=>{const n=t.getNode(e.id);n.data.dummy&&(n.data.order<i||n.data.order>s)&&ke(r,e.id,c)}))}(...e),n.set(o,!0))}const o=(e,r)=>{let o,i=-1,s=0;const a=new Map;return null==r||r.forEach((u,c)=>{var h;if("border"===(null===(h=t.getNode(u))||void 0===h?void 0:h.data.dummy)){const e=t.getPredecessors(u)||[];e.length&&(o=t.getNode(e[0].id).data.order,n([r,s,c,i,o],a),s=c,i=o)}n([r,s,r.length,o,e.length],a)}),r};return(null==e?void 0:e.length)&&e.reduce(o),r},_e=(t,e)=>{var r,n;if(null===(r=t.getNode(e))||void 0===r?void 0:r.data.dummy)return null===(n=t.getPredecessors(e))||void 0===n?void 0:n.find(e=>t.getNode(e.id).data.dummy)},ke=(t,e,r)=>{let n=e,o=r;if(n>o){const t=n;n=o,o=t}let i=t[n];i||(t[n]=i={}),i[o]=!0},Se=(t,e,r)=>{let n=e,o=r;if(n>r){n=r,o=e}return!!t[n]},Ae=(t,e,r,n,o,i)=>{const s=new jt,a=Oe(n,o,i);return null==e||e.forEach(e=>{let n;null==e||e.forEach(e=>{const o=r[e];if(s.hasNode(o)||s.addNode({id:o,data:{}}),n){const i=r[n],u=s.getRelatedEdges(i,"out").find(t=>t.target===o);u?s.updateEdgeData(u.id,Object.assign(Object.assign({},u.data),{weight:Math.max(a(t,e,n),u.data.weight||0)})):s.addEdge({id:`e${Math.random()}`,source:i,target:o,data:{weight:Math.max(a(t,e,n),0)}})}n=e})}),s};const Oe=(t,e,r)=>(n,o,i)=>{const s=n.getNode(o),a=n.getNode(i);let u=0,c=0;if(u+=s.data.width/2,s.data.hasOwnProperty("labelpos"))switch((s.data.labelpos||"").toLowerCase()){case"l":c=-s.data.width/2;break;case"r":c=s.data.width/2}if(c&&(u+=r?c:-c),c=0,u+=(s.data.dummy?e:t)/2,u+=(a.data.dummy?e:t)/2,u+=a.data.width/2,a.data.labelpos)switch((a.data.labelpos||"").toLowerCase()){case"l":c=a.data.width/2;break;case"r":c=-a.data.width/2}return c&&(u+=r?c:-c),c=0,u},ze=(t,e)=>t.getNode(e).data.width||0,je=(t,e)=>{const{align:r,nodesep:n=0,edgesep:o=0}=e||{},i=Gt(t),s=Object.assign(((t,e)=>{const r={},n=(e,n)=>{let o=0,i=0;const s=e.length,a=null==n?void 0:n[(null==n?void 0:n.length)-1];return null==n||n.forEach((e,u)=>{var c;const h=_e(t,e),l=h?t.getNode(h.id).data.order:s;(h||e===a)&&(null===(c=n.slice(i,u+1))||void 0===c||c.forEach(e=>{var n;null===(n=t.getPredecessors(e))||void 0===n||n.forEach(n=>{var i;const s=t.getNode(n.id),a=s.data.order;!(a<o||l<a)||s.data.dummy&&(null===(i=t.getNode(e))||void 0===i?void 0:i.data.dummy)||ke(r,n.id,e)})}),i=u+1,o=l)}),n};return(null==e?void 0:e.length)&&e.reduce(n),r})(t,i),Ne(t,i)),a={};let u=[];["u","d"].forEach(e=>{u="u"===e?i:Object.values(i).reverse(),["l","r"].forEach(r=>{"r"===r&&(u=u.map(t=>Object.values(t).reverse()));const i=("u"===e?t.getPredecessors:t.getSuccessors).bind(t),c=((t,e,r,n)=>{const o={},i={},s={};return null==e||e.forEach(t=>{null==t||t.forEach((t,e)=>{o[t]=t,i[t]=t,s[t]=e})}),null==e||e.forEach(t=>{let e=-1;null==t||t.forEach(t=>{let a=n(t).map(t=>t.id);if(a.length){a=a.sort((t,e)=>s[t]-s[e]);const n=(a.length-1)/2;for(let u=Math.floor(n),c=Math.ceil(n);u<=c;++u){const n=a[u];i[t]===t&&e<s[n]&&!Se(r,t,n)&&(i[n]=t,i[t]=o[t]=o[n],e=s[n])}}})}),{root:o,align:i}})(0,u,s,i),h=((t,e,r,n,o,i,s)=>{var a;const u={},c=Ae(t,e,r,o,i,s),h=s?"borderLeft":"borderRight",l=(t,e)=>{let r=c.getAllNodes(),n=r.pop();const o={};for(;n;)o[n.id]?t(n.id):(o[n.id]=!0,r.push(n),r=r.concat(e(n.id))),n=r.pop()};return l(t=>{u[t]=(c.getRelatedEdges(t,"in")||[]).reduce((t,e)=>Math.max(t,(u[e.source]||0)+e.data.weight),0)},c.getPredecessors.bind(c)),l(e=>{const r=(c.getRelatedEdges(e,"out")||[]).reduce((t,e)=>Math.min(t,(u[e.target]||0)-e.data.weight),Number.POSITIVE_INFINITY),n=t.getNode(e);r!==Number.POSITIVE_INFINITY&&n.data.borderType!==h&&(u[e]=Math.max(u[e],r))},c.getSuccessors.bind(c)),null===(a=Object.values(n))||void 0===a||a.forEach(t=>{u[t]=u[r[t]]}),u})(t,u,c.root,c.align,n,o,"r"===r);"r"===r&&Object.keys(h).forEach(t=>h[t]=-h[t]),a[e+r]=h})});const c=((t,e)=>Ht(Object.values(e),e=>{var r;let n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;return null===(r=Object.keys(e))||void 0===r||r.forEach(r=>{const i=e[r],s=ze(t,r)/2;n=Math.max(i+s,n),o=Math.min(i-s,o)}),n-o}))(t,a);return c&&function(t,e){const r=Object.values(e),n=Math.min(...r),o=Math.max(...r);["u","d"].forEach(r=>{["l","r"].forEach(i=>{const s=r+i,a=t[s];let u;if(a===e)return;const c=Object.values(a);u="l"===i?n-Math.min(...c):o-Math.max(...c),u&&(t[s]={},Object.keys(a).forEach(e=>{t[s][e]=a[e]+u}))})})}(a,c),((t,e)=>{const r={};return Object.keys(t.ul).forEach(n=>{if(e)r[n]=t[e.toLowerCase()][n];else{const e=Object.values(t).map(t=>t[n]);r[n]=(e[0]+e[1])/2}}),r})(a,r)},Ce=(t,e)=>{var r;const n=$t(t);((t,e)=>{const{ranksep:r=0}=e||{},n=Gt(t);let o=0;null==n||n.forEach(e=>{const n=e.map(e=>t.getNode(e).data.height),i=Math.max(...n,0);null==e||e.forEach(e=>{t.getNode(e).data.y=o+i/2}),o+=i+r})})(n,e);const o=je(n,e);null===(r=Object.keys(o))||void 0===r||r.forEach(t=>{n.getNode(t).data.x=o[t]})},Ie=t=>{const e={},r=n=>{var o;const i=t.getNode(n);if(!i)return 0;if(e[n])return i.data.rank;let s;return e[n]=!0,null===(o=t.getRelatedEdges(n,"out"))||void 0===o||o.forEach(t=>{const e=r(t.target)-t.data.minlen;e&&(void 0===s||e<s)&&(s=e)}),s||(s=0),i.data.rank=s,s};t.getAllNodes().filter(e=>0===t.getRelatedEdges(e.id,"in").length).forEach(t=>r(t.id))},Re=(t,e)=>t.getNode(e.target).data.rank-t.getNode(e.source).data.rank-e.data.minlen,Te=(t,e)=>{const r=n=>{e.getRelatedEdges(n,"both").forEach(o=>{const i=o.source,s=n===i?o.target:i;t.hasNode(s)||Re(e,o)||(t.addNode({id:s,data:{}}),t.addEdge({id:o.id,source:n,target:s,data:{}}),r(s))})};return t.getAllNodes().forEach(t=>r(t.id)),t.getAllNodes().length},Pe=(t,e)=>{const r=n=>{var o;null===(o=e.getRelatedEdges(n,"both"))||void 0===o||o.forEach(o=>{const i=o.source,s=n===i?o.target:i;t.hasNode(s)||void 0===e.getNode(s).data.layer&&Re(e,o)||(t.addNode({id:s,data:{}}),t.addEdge({id:o.id,source:n,target:s,data:{}}),r(s))})};return t.getAllNodes().forEach(t=>r(t.id)),t.getAllNodes().length},Fe=(t,e)=>Ht(e.getAllEdges(),r=>t.hasNode(r.source)!==t.hasNode(r.target)?Re(e,r):1/0),Le=(t,e,r)=>{t.getAllNodes().forEach(t=>{const n=e.getNode(t.id);n.data.rank||(n.data.rank=0),n.data.rank+=r})},De=t=>{const e=(t=>{const e=new jt;return t.getAllNodes().forEach(t=>{e.addNode(Object.assign({},t))}),t.getAllEdges().forEach(t=>{const r=e.getRelatedEdges(t.source,"out").find(e=>e.target===t.ta