d3-dag
Version:
Layout algorithms for visualizing directed acylic graphs.
19 lines • 113 kB
JavaScript
// d3-dag Version 1.1.0. Copyright 2023 Erik Brinkman.
"use strict";var ri=Object.create;var je=Object.defineProperty,oi=Object.defineProperties,ii=Object.getOwnPropertyDescriptor,ai=Object.getOwnPropertyDescriptors,si=Object.getOwnPropertyNames,lt=Object.getOwnPropertySymbols,ui=Object.getPrototypeOf,Xt=Object.prototype.hasOwnProperty,Un=Object.prototype.propertyIsEnumerable;var Yt=(e,t)=>{if(t=Symbol[e])return t;throw Error("Symbol."+e+" is not defined")};var An=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))Xt.call(t,n)&&An(e,n,t[n]);if(lt)for(var n of lt(t))Un.call(t,n)&&An(e,n,t[n]);return e},R=(e,t)=>oi(e,ai(t));var V=(e,t)=>{var n={};for(var r in e)Xt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&<)for(var r of lt(e))t.indexOf(r)<0&&Un.call(e,r)&&(n[r]=e[r]);return n};var H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),di=(e,t)=>{for(var n in t)je(e,n,{get:t[n],enumerable:!0})},En=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of si(t))!Xt.call(e,i)&&i!==n&&je(e,i,{get:()=>t[i],enumerable:!(r=ii(t,i))||r.enumerable});return e};var jn=(e,t,n)=>(n=e!=null?ri(ui(e)):{},En(t||!e||!e.__esModule?je(n,"default",{value:e,enumerable:!0}):n,e)),li=e=>En(je({},"__esModule",{value:!0}),e);var en=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var C=(e,t,n)=>(en(e,t,"read from private field"),n?n.call(e):t.get(e)),F=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},P=(e,t,n,r)=>(en(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var se=(e,t,n)=>(en(e,t,"access private method"),n);var fi=function(e,t){this[0]=e,this[1]=t};var Y=e=>{var t=e[Yt("asyncIterator")],n=!1,r,i={};return t==null?(t=e[Yt("iterator")](),r=o=>i[o]=a=>t[o](a)):(t=t.call(e),r=o=>i[o]=a=>{if(n){if(n=!1,o==="throw")throw a;return a}return n=!0,{done:!1,value:new fi(new Promise(s=>{var u=t[o](a);if(!(u instanceof Object))throw TypeError("Object expected");s(u)}),1)}}),i[Yt("iterator")]=()=>i,r("next"),"throw"in t?r("throw"):i.throw=o=>{throw o},"return"in t&&r("return"),i};var bn=H((au,mr)=>{"use strict";function hr(e,t,n,r){this.feasible=n,this.evaluation=t,this.bounded=r,this._tableau=e}mr.exports=hr;hr.prototype.generateSolutionSet=function(){for(var e={},t=this._tableau,n=t.varIndexByRow,r=t.variablesPerIndex,i=t.matrix,o=t.rhsColumn,a=t.height-1,s=Math.round(1/t.precision),u=1;u<=a;u+=1){var d=n[u],l=r[d];if(!(l===void 0||l.isSlack===!0)){var f=i[u][o];e[l.id]=Math.round((Number.EPSILON+f)*s)/s}}return e}});var Nr=H((su,yr)=>{"use strict";var gr=bn();function wt(e,t,n,r,i){gr.call(this,e,t,n,r),this.iter=i}yr.exports=wt;wt.prototype=Object.create(gr.prototype);wt.constructor=wt});var pe=H((uu,br)=>{"use strict";var Gi=bn(),Mi=Nr();function ge(e){this.model=null,this.matrix=null,this.width=0,this.height=0,this.costRowIndex=0,this.rhsColumn=0,this.variablesPerIndex=[],this.unrestrictedVars=null,this.feasible=!0,this.evaluation=0,this.simplexIters=0,this.varIndexByRow=null,this.varIndexByCol=null,this.rowByVarIndex=null,this.colByVarIndex=null,this.precision=e||1e-8,this.optionalObjectives=[],this.objectivesByPriority={},this.savedState=null,this.availableIndexes=[],this.lastElementIndex=0,this.variables=null,this.nVars=0,this.bounded=!0,this.unboundedVarIndex=null,this.branchAndCutIterations=0}br.exports=ge;ge.prototype.solve=function(){return this.model.getNumberOfIntegerVariables()>0?this.branchAndCut():this.simplex(),this.updateVariableValues(),this.getSolution()};function xn(e,t){this.priority=e,this.reducedCosts=new Array(t);for(var n=0;n<t;n+=1)this.reducedCosts[n]=0}xn.prototype.copy=function(){var e=new xn(this.priority,this.reducedCosts.length);return e.reducedCosts=this.reducedCosts.slice(),e};ge.prototype.setOptionalObjective=function(e,t,n){var r=this.objectivesByPriority[e];if(r===void 0){var i=Math.max(this.width,t+1);r=new xn(e,i),this.objectivesByPriority[e]=r,this.optionalObjectives.push(r),this.optionalObjectives.sort(function(o,a){return o.priority-a.priority})}r.reducedCosts[t]=n};ge.prototype.initialize=function(e,t,n,r){this.variables=n,this.unrestrictedVars=r,this.width=e,this.height=t;for(var i=new Array(e),o=0;o<e;o++)i[o]=0;this.matrix=new Array(t);for(var a=0;a<t;a++)this.matrix[a]=i.slice();this.varIndexByRow=new Array(this.height),this.varIndexByCol=new Array(this.width),this.varIndexByRow[0]=-1,this.varIndexByCol[0]=-1,this.nVars=e+t-2,this.rowByVarIndex=new Array(this.nVars),this.colByVarIndex=new Array(this.nVars),this.lastElementIndex=this.nVars};ge.prototype._resetMatrix=function(){var e=this.model.variables,t=this.model.constraints,n=e.length,r=t.length,i,o,a=this.matrix[0],s=this.model.isMinimization===!0?-1:1;for(i=0;i<n;i+=1){var u=e[i],d=u.priority,l=s*u.cost;d===0?a[i+1]=l:this.setOptionalObjective(d,i+1,l),o=e[i].index,this.rowByVarIndex[o]=-1,this.colByVarIndex[o]=i+1,this.varIndexByCol[i+1]=o}for(var f=1,p=0;p<r;p+=1){var m=t[p],g=m.index;this.rowByVarIndex[g]=f,this.colByVarIndex[g]=-1,this.varIndexByRow[f]=g;var c,b,y,h=m.terms,N=h.length,v=this.matrix[f++];if(m.isUpperBound){for(c=0;c<N;c+=1)b=h[c],y=this.colByVarIndex[b.variable.index],v[y]=b.coefficient;v[0]=m.rhs}else{for(c=0;c<N;c+=1)b=h[c],y=this.colByVarIndex[b.variable.index],v[y]=-b.coefficient;v[0]=-m.rhs}}};ge.prototype.setModel=function(e){this.model=e;var t=e.nVariables+1,n=e.nConstraints+1;return this.initialize(t,n,e.variables,e.unrestrictedVariables),this._resetMatrix(),this};ge.prototype.getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};ge.prototype.density=function(){for(var e=0,t=this.matrix,n=0;n<this.height;n++)for(var r=t[n],i=0;i<this.width;i++)r[i]!==0&&(e+=1);return e/(this.height*this.width)};ge.prototype.setEvaluation=function(){var e=Math.round(1/this.precision),t=this.matrix[this.costRowIndex][this.rhsColumn],n=Math.round((Number.EPSILON+t)*e)/e;this.evaluation=n,this.simplexIters===0&&(this.bestPossibleEval=n)};ge.prototype.getSolution=function(){var e=this.model.isMinimization===!0?this.evaluation:-this.evaluation;return this.model.getNumberOfIntegerVariables()>0?new Mi(this,e,this.feasible,this.bounded,this.branchAndCutIterations):new Gi(this,e,this.feasible,this.bounded)}});var xr=H(()=>{"use strict";var rt=pe();rt.prototype.simplex=function(){return this.bounded=!0,this.phase1(),this.feasible===!0&&this.phase2(),this};rt.prototype.phase1=function(){for(var e=this.model.checkForCycles,t=[],n=this.matrix,r=this.rhsColumn,i=this.width-1,o=this.height-1,a,s=0;;){for(var u=0,d=-this.precision,l=1;l<=o;l++){a=this.unrestrictedVars[this.varIndexByRow[l]]===!0;var f=n[l][r];f<d&&(d=f,u=l)}if(u===0)return this.feasible=!0,s;for(var p=0,m=-1/0,g=n[0],c=n[u],b=1;b<=i;b++){var y=c[b];if(a=this.unrestrictedVars[this.varIndexByCol[b]]===!0,a||y<-this.precision){var h=-g[b]/y;m<h&&(m=h,p=b)}}if(p===0)return this.feasible=!1,s;if(e){t.push([this.varIndexByRow[u],this.varIndexByCol[p]]);var N=this.checkForCycles(t);if(N.length>0)return this.model.messages.push("Cycle in phase 1"),this.model.messages.push("Start :"+N[0]),this.model.messages.push("Length :"+N[1]),this.feasible=!1,s}this.pivot(u,p),s+=1}};rt.prototype.phase2=function(){for(var e=this.model.checkForCycles,t=[],n=this.matrix,r=this.rhsColumn,i=this.width-1,o=this.height-1,a=this.precision,s=this.optionalObjectives.length,u=null,d=0,l,f;;){var p=n[this.costRowIndex];s>0&&(u=[]);for(var m=0,g=a,c=!1,b=1;b<=i;b++){if(l=p[b],f=this.unrestrictedVars[this.varIndexByCol[b]]===!0,s>0&&-a<l&&l<a){u.push(b);continue}if(f&&l<0){-l>g&&(g=-l,m=b,c=!0);continue}l>g&&(g=l,m=b,c=!1)}if(s>0)for(var y=0;m===0&&u.length>0&&y<s;){var h=[],N=this.optionalObjectives[y].reducedCosts;g=a;for(var v=0;v<u.length;v++){if(b=u[v],l=N[b],f=this.unrestrictedVars[this.varIndexByCol[b]]===!0,-a<l&&l<a){h.push(b);continue}if(f&&l<0){-l>g&&(g=-l,m=b,c=!0);continue}l>g&&(g=l,m=b,c=!1)}u=h,y+=1}if(m===0)return this.setEvaluation(),this.simplexIters+=1,d;for(var L=0,k=1/0,w=this.varIndexByRow,S=1;S<=o;S++){var O=n[S],I=O[r],z=O[m];if(!(-a<z&&z<a)){if(z>0&&a>I&&I>-a){k=0,L=S;break}var M=c?-I/z:I/z;M>a&&k>M&&(k=M,L=S)}}if(k===1/0)return this.evaluation=-1/0,this.bounded=!1,this.unboundedVarIndex=this.varIndexByCol[m],d;if(e){t.push([this.varIndexByRow[L],this.varIndexByCol[m]]);var $=this.checkForCycles(t);if($.length>0)return this.model.messages.push("Cycle in phase 2"),this.model.messages.push("Start :"+$[0]),this.model.messages.push("Length :"+$[1]),this.feasible=!1,d}this.pivot(L,m,!0),d+=1}};var kn=[];rt.prototype.pivot=function(e,t){var n=this.matrix,r=n[e][t],i=this.height-1,o=this.width-1,a=this.varIndexByRow[e],s=this.varIndexByCol[t];this.varIndexByRow[e]=s,this.varIndexByCol[t]=a,this.rowByVarIndex[s]=e,this.rowByVarIndex[a]=-1,this.colByVarIndex[s]=-1,this.colByVarIndex[a]=t;for(var u=n[e],d=0,l=0;l<=o;l++)u[l]>=-1e-16&&u[l]<=1e-16?u[l]=0:(u[l]/=r,kn[d]=l,d+=1);u[t]=1/r;for(var f,p,m,g=this.precision,c=0;c<=i;c++)if(c!==e&&!(n[c][t]>=-1e-16&&n[c][t]<=1e-16)){var b=n[c];if(f=b[t],f>=-1e-16&&f<=1e-16)f!==0&&(b[t]=0);else{for(p=0;p<d;p++)l=kn[p],m=u[l],m>=-1e-16&&m<=1e-16?m!==0&&(u[l]=0):b[l]=b[l]-f*m;b[t]=-f/r}}var y=this.optionalObjectives.length;if(y>0)for(var h=0;h<y;h+=1){var N=this.optionalObjectives[h].reducedCosts;if(f=N[t],f!==0){for(p=0;p<d;p++)l=kn[p],m=u[l],m!==0&&(N[l]=N[l]-f*m);N[t]=-f/r}}};rt.prototype.checkForCycles=function(e){for(var t=0;t<e.length-1;t++)for(var n=t+1;n<e.length;n++){var r=e[t],i=e[n];if(r[0]===i[0]&&r[1]===i[1]){if(n-t>e.length-n)break;for(var o=!0,a=1;a<n-t;a++){var s=e[t+a],u=e[n+a];if(s[0]!==u[0]||s[1]!==u[1]){o=!1;break}}if(o)return[t,n-t]}}return[]}});var Dt=H((fu,wr)=>{"use strict";function vn(e,t,n,r){this.id=e,this.cost=t,this.index=n,this.value=0,this.priority=r}function kr(e,t,n,r){vn.call(this,e,t,n,r)}kr.prototype.isInteger=!0;function Ln(e,t){vn.call(this,e,0,t,0)}Ln.prototype.isSlack=!0;function vr(e,t){this.variable=e,this.coefficient=t}function Lr(e,t,n){return n===0||n==="required"?null:(t=t||1,n=n||1,e.isMinimization===!1&&(t=-t),e.addVariable(t,"r"+e.relaxationIndex++,!1,!1,n))}function Te(e,t,n,r){this.slack=new Ln("s"+n,n),this.index=n,this.model=r,this.rhs=e,this.isUpperBound=t,this.terms=[],this.termsByVarIndex={},this.relaxation=null}Te.prototype.addTerm=function(e,t){var n=t.index,r=this.termsByVarIndex[n];if(r===void 0)r=new vr(t,e),this.termsByVarIndex[n]=r,this.terms.push(r),this.isUpperBound===!0&&(e=-e),this.model.updateConstraintCoefficient(this,t,e);else{var i=r.coefficient+e;this.setVariableCoefficient(i,t)}return this};Te.prototype.removeTerm=function(e){return this};Te.prototype.setRightHandSide=function(e){if(e!==this.rhs){var t=e-this.rhs;this.isUpperBound===!0&&(t=-t),this.rhs=e,this.model.updateRightHandSide(this,t)}return this};Te.prototype.setVariableCoefficient=function(e,t){var n=t.index;if(n===-1){console.warn("[Constraint.setVariableCoefficient] Trying to change coefficient of inexistant variable.");return}var r=this.termsByVarIndex[n];if(r===void 0)this.addTerm(e,t);else if(e!==r.coefficient){var i=e-r.coefficient;this.isUpperBound===!0&&(i=-i),r.coefficient=e,this.model.updateConstraintCoefficient(this,t,i)}return this};Te.prototype.relax=function(e,t){this.relaxation=Lr(this.model,e,t),this._relax(this.relaxation)};Te.prototype._relax=function(e){e!==null&&(this.isUpperBound?this.setVariableCoefficient(-1,e):this.setVariableCoefficient(1,e))};function Ue(e,t){this.upperBound=e,this.lowerBound=t,this.model=e.model,this.rhs=e.rhs,this.relaxation=null}Ue.prototype.isEquality=!0;Ue.prototype.addTerm=function(e,t){return this.upperBound.addTerm(e,t),this.lowerBound.addTerm(e,t),this};Ue.prototype.removeTerm=function(e){return this.upperBound.removeTerm(e),this.lowerBound.removeTerm(e),this};Ue.prototype.setRightHandSide=function(e){this.upperBound.setRightHandSide(e),this.lowerBound.setRightHandSide(e),this.rhs=e};Ue.prototype.relax=function(e,t){this.relaxation=Lr(this.model,e,t),this.upperBound.relaxation=this.relaxation,this.upperBound._relax(this.relaxation),this.lowerBound.relaxation=this.relaxation,this.lowerBound._relax(this.relaxation)};wr.exports={Constraint:Te,Variable:vn,IntegerVariable:kr,SlackVariable:Ln,Equality:Ue,Term:vr}});var Dr=H(()=>{"use strict";var St=pe(),wn=Dt().SlackVariable;St.prototype.addCutConstraints=function(e){for(var t=e.length,n=this.height,r=n+t,i=n;i<r;i+=1)this.matrix[i]===void 0&&(this.matrix[i]=this.matrix[i-1].slice());this.height=r,this.nVars=this.width+this.height-2;for(var o,a=this.width-1,s=0;s<t;s+=1){var u=e[s],d=n+s,l=u.type==="min"?-1:1,f=u.varIndex,p=this.rowByVarIndex[f],m=this.matrix[d];if(p===-1){for(m[this.rhsColumn]=l*u.value,o=1;o<=a;o+=1)m[o]=0;m[this.colByVarIndex[f]]=l}else{var g=this.matrix[p],c=g[this.rhsColumn];for(m[this.rhsColumn]=l*(u.value-c),o=1;o<=a;o+=1)m[o]=-l*g[o]}var b=this.getNewElementIndex();this.varIndexByRow[d]=b,this.rowByVarIndex[b]=d,this.colByVarIndex[b]=-1,this.variablesPerIndex[b]=new wn("s"+b,b),this.nVars+=1}};St.prototype._addLowerBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,n=this.matrix,r=this.variablesPerIndex[this.varIndexByRow[e]];if(!r.isInteger)return!1;var i=n[e][this.rhsColumn],o=i-Math.floor(i);if(o<this.precision||1-this.precision<o)return!1;var a=this.height;n[a]=n[a-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[a]=s,this.rowByVarIndex[s]=a,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new wn("s"+s,s),n[a][this.rhsColumn]=Math.floor(i);for(var u=1;u<this.varIndexByCol.length;u+=1){var d=this.variablesPerIndex[this.varIndexByCol[u]];if(!d.isInteger)n[a][u]=Math.min(0,n[e][u]/(1-o));else{var l=n[e][u],f=Math.floor(l)+Math.max(0,l-Math.floor(l)-o)/(1-o);n[a][u]=f}}for(var p=0;p<this.width;p+=1)n[a][p]-=n[e][p];return!0};St.prototype._addUpperBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,n=this.matrix,r=this.variablesPerIndex[this.varIndexByRow[e]];if(!r.isInteger)return!1;var i=n[e][this.rhsColumn],o=i-Math.floor(i);if(o<this.precision||1-this.precision<o)return!1;var a=this.height;n[a]=n[a-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[a]=s,this.rowByVarIndex[s]=a,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new wn("s"+s,s),n[a][this.rhsColumn]=-o;for(var u=1;u<this.varIndexByCol.length;u+=1){var d=this.variablesPerIndex[this.varIndexByCol[u]],l=n[e][u],f=l-Math.floor(l);d.isInteger?f<=o?n[a][u]=-f:n[a][u]=-(1-f)*o/f:l>=0?n[a][u]=-l:n[a][u]=l*o/(1-o)}return!0};St.prototype.applyMIRCuts=function(){}});var Sr=H(()=>{"use strict";var ye=pe();ye.prototype._putInBase=function(e){var t=this.rowByVarIndex[e];if(t===-1){for(var n=this.colByVarIndex[e],r=1;r<this.height;r+=1){var i=this.matrix[r][n];if(i<-this.precision||this.precision<i){t=r;break}}this.pivot(t,n)}return t};ye.prototype._takeOutOfBase=function(e){var t=this.colByVarIndex[e];if(t===-1){for(var n=this.rowByVarIndex[e],r=this.matrix[n],i=1;i<this.height;i+=1){var o=r[i];if(o<-this.precision||this.precision<o){t=i;break}}this.pivot(n,t)}return t};ye.prototype.updateVariableValues=function(){for(var e=this.variables.length,t=Math.round(1/this.precision),n=0;n<e;n+=1){var r=this.variables[n],i=r.index,o=this.rowByVarIndex[i];if(o===-1)r.value=0;else{var a=this.matrix[o][this.rhsColumn];r.value=Math.round((a+Number.EPSILON)*t)/t}}};ye.prototype.updateRightHandSide=function(e,t){var n=this.height-1,r=this.rowByVarIndex[e.index];if(r===-1){for(var i=this.colByVarIndex[e.index],o=0;o<=n;o+=1){var a=this.matrix[o];a[this.rhsColumn]-=t*a[i]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var d=this.optionalObjectives[u].reducedCosts;d[this.rhsColumn]-=t*d[i]}}else this.matrix[r][this.rhsColumn]-=t};ye.prototype.updateConstraintCoefficient=function(e,t,n){if(e.index===t.index)throw new Error("[Tableau.updateConstraintCoefficient] constraint index should not be equal to variable index !");var r=this._putInBase(e.index),i=this.colByVarIndex[t.index];if(i===-1)for(var o=this.rowByVarIndex[t.index],a=0;a<this.width;a+=1)this.matrix[r][a]+=n*this.matrix[o][a];else this.matrix[r][i]-=n};ye.prototype.updateCost=function(e,t){var n=e.index,r=this.width-1,i=this.colByVarIndex[n];if(i===-1){var o=this.matrix[this.rowByVarIndex[n]],a;if(e.priority===0){var s=this.matrix[0];for(a=0;a<=r;a+=1)s[a]+=t*o[a]}else{var u=this.objectivesByPriority[e.priority].reducedCosts;for(a=0;a<=r;a+=1)u[a]+=t*o[a]}}else this.matrix[0][i]-=t};ye.prototype.addConstraint=function(e){var t=e.isUpperBound?1:-1,n=this.height,r=this.matrix[n];r===void 0&&(r=this.matrix[0].slice(),this.matrix[n]=r);for(var i=this.width-1,o=0;o<=i;o+=1)r[o]=0;r[this.rhsColumn]=t*e.rhs;for(var a=e.terms,s=a.length,u=0;u<s;u+=1){var d=a[u],l=d.coefficient,f=d.variable.index,p=this.rowByVarIndex[f];if(p===-1)r[this.colByVarIndex[f]]+=t*l;else{var m=this.matrix[p],g=m[this.rhsColumn];for(o=0;o<=i;o+=1)r[o]-=t*l*m[o]}}var c=e.index;this.varIndexByRow[n]=c,this.rowByVarIndex[c]=n,this.colByVarIndex[c]=-1,this.height+=1};ye.prototype.removeConstraint=function(e){var t=e.index,n=this.height-1,r=this._putInBase(t),i=this.matrix[n];this.matrix[n]=this.matrix[r],this.matrix[r]=i,this.varIndexByRow[r]=this.varIndexByRow[n],this.varIndexByRow[n]=-1,this.rowByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.slack.index=-1,this.height-=1};ye.prototype.addVariable=function(e){var t=this.height-1,n=this.width,r=this.model.isMinimization===!0?-e.cost:e.cost,i=e.priority,o=this.optionalObjectives.length;if(o>0)for(var a=0;a<o;a+=1)this.optionalObjectives[a].reducedCosts[n]=0;i===0?this.matrix[0][n]=r:(this.setOptionalObjective(i,n,r),this.matrix[0][n]=0);for(var s=1;s<=t;s+=1)this.matrix[s][n]=0;var u=e.index;this.varIndexByCol[n]=u,this.rowByVarIndex[u]=-1,this.colByVarIndex[u]=n,this.width+=1};ye.prototype.removeVariable=function(e){var t=e.index,n=this._takeOutOfBase(t),r=this.width-1;if(n!==r){for(var i=this.height-1,o=0;o<=i;o+=1){var a=this.matrix[o];a[n]=a[r]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var d=this.optionalObjectives[u].reducedCosts;d[n]=d[r]}var l=this.varIndexByCol[r];this.varIndexByCol[n]=l,this.colByVarIndex[l]=n}this.varIndexByCol[r]=-1,this.colByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.index=-1,this.width-=1}});var Or=H(()=>{"use strict";var Ri=pe();Ri.prototype.log=function(e,t){console.log("****",e,"****"),console.log("Nb Variables",this.width-1),console.log("Nb Constraints",this.height-1),console.log("Basic Indexes",this.varIndexByRow),console.log("Non Basic Indexes",this.varIndexByCol),console.log("Rows",this.rowByVarIndex),console.log("Cols",this.colByVarIndex);var n=5,r="",i=[" "],o,a,s,u,d,l,f,p,m,g,c,b,y;for(a=1;a<this.width;a+=1)l=this.varIndexByCol[a],d=this.variablesPerIndex[l],d===void 0?f="c"+l:f=d.id,p=f.length,m=Math.abs(p-5),g=" ",c=" ",p>5?g+=" ":c+=" ",i[a]=g,r+=c+f;console.log(r);var h,N=this.matrix[this.costRowIndex],v=" ";for(o=1;o<this.width;o+=1)h=" ",v+=h,v+=i[o],v+=N[o].toFixed(n);for(h=" ",v+=h+i[0]+N[0].toFixed(n),console.log(v+" Z"),u=1;u<this.height;u+=1){for(b=this.matrix[u],y=" ",a=1;a<this.width;a+=1)h=" ",y+=h+i[a]+b[a].toFixed(n);h=" ",y+=h+i[0]+b[0].toFixed(n),l=this.varIndexByRow[u],d=this.variablesPerIndex[l],d===void 0?f="c"+l:f=d.id,console.log(y+" "+f)}console.log("");var L=this.optionalObjectives.length;if(L>0){console.log(" Optional objectives:");for(var k=0;k<L;k+=1){var w=this.optionalObjectives[k].reducedCosts,S="";for(o=1;o<this.width;o+=1)h=w[o]<0?"":" ",S+=h,S+=i[o],S+=w[o].toFixed(n);h=w[0]<0?"":" ",S+=h+i[0]+w[0].toFixed(n),console.log(S+" z"+k)}}return console.log("Feasible?",this.feasible),console.log("evaluation",this.evaluation),this}});var Ir=H(()=>{"use strict";var Ot=pe();Ot.prototype.copy=function(){var e=new Ot(this.precision);e.width=this.width,e.height=this.height,e.nVars=this.nVars,e.model=this.model,e.variables=this.variables,e.variablesPerIndex=this.variablesPerIndex,e.unrestrictedVars=this.unrestrictedVars,e.lastElementIndex=this.lastElementIndex,e.varIndexByRow=this.varIndexByRow.slice(),e.varIndexByCol=this.varIndexByCol.slice(),e.rowByVarIndex=this.rowByVarIndex.slice(),e.colByVarIndex=this.colByVarIndex.slice(),e.availableIndexes=this.availableIndexes.slice();for(var t=[],n=0;n<this.optionalObjectives.length;n++)t[n]=this.optionalObjectives[n].copy();e.optionalObjectives=t;for(var r=this.matrix,i=new Array(this.height),o=0;o<this.height;o++)i[o]=r[o].slice();return e.matrix=i,e};Ot.prototype.save=function(){this.savedState=this.copy()};Ot.prototype.restore=function(){if(this.savedState!==null){var e=this.savedState,t=e.matrix;this.nVars=e.nVars,this.model=e.model,this.variables=e.variables,this.variablesPerIndex=e.variablesPerIndex,this.unrestrictedVars=e.unrestrictedVars,this.lastElementIndex=e.lastElementIndex,this.width=e.width,this.height=e.height;var n,r;for(n=0;n<this.height;n+=1){var i=t[n],o=this.matrix[n];for(r=0;r<this.width;r+=1)o[r]=i[r]}var a=e.varIndexByRow;for(r=0;r<this.height;r+=1)this.varIndexByRow[r]=a[r];for(;this.varIndexByRow.length>this.height;)this.varIndexByRow.pop();var s=e.varIndexByCol;for(n=0;n<this.width;n+=1)this.varIndexByCol[n]=s[n];for(;this.varIndexByCol.length>this.width;)this.varIndexByCol.pop();for(var u=e.rowByVarIndex,d=e.colByVarIndex,l=0;l<this.nVars;l+=1)this.rowByVarIndex[l]=u[l],this.colByVarIndex[l]=d[l];if(e.optionalObjectives.length>0&&this.optionalObjectives.length>0){this.optionalObjectives=[],this.optionalObjectivePerPriority={};for(var f=0;f<e.optionalObjectives.length;f++){var p=e.optionalObjectives[f].copy();this.optionalObjectives[f]=p,this.optionalObjectivePerPriority[p.priority]=p}}}}});var Gr=H(()=>{"use strict";var Cr=pe();function Tr(e,t){this.index=e,this.value=t}Cr.prototype.getMostFractionalVar=function(){for(var e=0,t=null,n=null,r=.5,i=this.model.integerVariables,o=i.length,a=0;a<o;a++){var s=i[a].index,u=this.rowByVarIndex[s];if(u!==-1){var d=this.matrix[u][this.rhsColumn],l=Math.abs(d-Math.round(d));e<l&&(e=l,t=s,n=d)}}return new Tr(t,n)};Cr.prototype.getFractionalVarWithLowestCost=function(){for(var e=1/0,t=null,n=null,r=this.model.integerVariables,i=r.length,o=0;o<i;o++){var a=r[o],s=a.index,u=this.rowByVarIndex[s];if(u!==-1){var d=this.matrix[u][this.rhsColumn];if(Math.abs(d-Math.round(d))>this.precision){var l=a.cost;e>l&&(e=l,t=s,n=d)}}}return new Tr(t,n)}});var Mr=H(()=>{"use strict";var Dn=pe();Dn.prototype.countIntegerValues=function(){for(var e=0,t=1;t<this.height;t+=1)if(this.variablesPerIndex[this.varIndexByRow[t]].isInteger){var n=this.matrix[t][this.rhsColumn];n=n-Math.floor(n),n<this.precision&&-n<this.precision&&(e+=1)}return e};Dn.prototype.isIntegral=function(){for(var e=this.model.integerVariables,t=e.length,n=0;n<t;n++){var r=this.rowByVarIndex[e[n].index];if(r!==-1){var i=this.matrix[r][this.rhsColumn];if(Math.abs(i-Math.round(i))>this.precision)return!1}}return!0};Dn.prototype.computeFractionalVolume=function(e){for(var t=-1,n=1;n<this.height;n+=1)if(this.variablesPerIndex[this.varIndexByRow[n]].isInteger){var r=this.matrix[n][this.rhsColumn];r=Math.abs(r);var i=Math.min(r-Math.floor(r),Math.floor(r+1));if(i<this.precision){if(!e)return 0}else t===-1?t=r:t*=r}return t===-1?0:t}});var zr=H((wu,Rr)=>{"use strict";xr();Dr();Sr();Or();Ir();Gr();Mr();Rr.exports=pe()});var On=H(()=>{"use strict";var Vr=pe();function Br(e,t,n){this.type=e,this.varIndex=t,this.value=n}function Sn(e,t){this.relaxedEvaluation=e,this.cuts=t}function zi(e,t){return t.relaxedEvaluation-e.relaxedEvaluation}Vr.prototype.applyCuts=function(e){if(this.restore(),this.addCutConstraints(e),this.simplex(),this.model.useMIRCuts)for(var t=!0;t;){var n=this.computeFractionalVolume(!0);this.applyMIRCuts(),this.simplex();var r=this.computeFractionalVolume(!0);r>=.9*n&&(t=!1)}};Vr.prototype.branchAndCut=function(){var e=[],t=0,n=this.model.tolerance,r=!0,i=1e99;this.model.timeout&&(i=Date.now()+this.model.timeout);for(var o=1/0,a=null,s=[],u=0;u<this.optionalObjectives.length;u+=1)s.push(1/0);var d=new Sn(-1/0,[]),l;for(e.push(d);e.length>0&&r===!0&&Date.now()<i;)if(this.model.isMinimization?l=this.bestPossibleEval*(1+n):l=this.bestPossibleEval*(1-n),n>0&&o<l&&(r=!1),d=e.pop(),!(d.relaxedEvaluation>o)){var f=d.cuts;if(this.applyCuts(f),t++,this.feasible!==!1){var p=this.evaluation;if(!(p>o)){if(p===o){for(var m=!0,g=0;g<this.optionalObjectives.length&&!(this.optionalObjectives[g].reducedCosts[0]>s[g]);g+=1)if(this.optionalObjectives[g].reducedCosts[0]<s[g]){m=!1;break}if(m)continue}if(this.isIntegral()===!0){if(this.__isIntegral=!0,t===1){this.branchAndCutIterations=t;return}a=d,o=p;for(var c=0;c<this.optionalObjectives.length;c+=1)s[c]=this.optionalObjectives[c].reducedCosts[0]}else{t===1&&this.save();for(var b=this.getMostFractionalVar(),y=b.index,h=[],N=[],v=f.length,L=0;L<v;L+=1){var k=f[L];k.varIndex===y?k.type==="min"?N.push(k):h.push(k):(h.push(k),N.push(k))}var w=Math.ceil(b.value),S=Math.floor(b.value),O=new Br("min",y,w);h.push(O);var I=new Br("max",y,S);N.push(I),e.push(new Sn(p,h)),e.push(new Sn(p,N)),e.sort(zi)}}}}a!==null&&this.applyCuts(a.cuts),this.branchAndCutIterations=t}});var _r=H((Cu,Pr)=>{"use strict";var Bi=pe(),Ou=On(),ot=Dt(),It=ot.Constraint,$r=ot.Equality,Vi=ot.Variable,$i=ot.IntegerVariable,Iu=ot.Term;function J(e,t){this.tableau=new Bi(e),this.name=t,this.variables=[],this.integerVariables=[],this.unrestrictedVariables={},this.constraints=[],this.nConstraints=0,this.nVariables=0,this.isMinimization=!0,this.tableauInitialized=!1,this.relaxationIndex=1,this.useMIRCuts=!1,this.checkForCycles=!0,this.messages=[]}Pr.exports=J;J.prototype.minimize=function(){return this.isMinimization=!0,this};J.prototype.maximize=function(){return this.isMinimization=!1,this};J.prototype._getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};J.prototype._addConstraint=function(e){var t=e.slack;this.tableau.variablesPerIndex[t.index]=t,this.constraints.push(e),this.nConstraints+=1,this.tableauInitialized===!0&&this.tableau.addConstraint(e)};J.prototype.smallerThan=function(e){var t=new It(e,!0,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};J.prototype.greaterThan=function(e){var t=new It(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};J.prototype.equal=function(e){var t=new It(e,!0,this.tableau.getNewElementIndex(),this);this._addConstraint(t);var n=new It(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(n),new $r(t,n)};J.prototype.addVariable=function(e,t,n,r,i){if(typeof i=="string")switch(i){case"required":i=0;break;case"strong":i=1;break;case"medium":i=2;break;case"weak":i=3;break;default:i=0;break}var o=this.tableau.getNewElementIndex();t==null&&(t="v"+o),e==null&&(e=0),i==null&&(i=0);var a;return n?(a=new $i(t,e,o,i),this.integerVariables.push(a)):a=new Vi(t,e,o,i),this.variables.push(a),this.tableau.variablesPerIndex[o]=a,r&&(this.unrestrictedVariables[o]=!0),this.nVariables+=1,this.tableauInitialized===!0&&this.tableau.addVariable(a),a};J.prototype._removeConstraint=function(e){var t=this.constraints.indexOf(e);if(t===-1){console.warn("[Model.removeConstraint] Constraint not present in model");return}this.constraints.splice(t,1),this.nConstraints-=1,this.tableauInitialized===!0&&this.tableau.removeConstraint(e),e.relaxation&&this.removeVariable(e.relaxation)};J.prototype.removeConstraint=function(e){return e.isEquality?(this._removeConstraint(e.upperBound),this._removeConstraint(e.lowerBound)):this._removeConstraint(e),this};J.prototype.removeVariable=function(e){var t=this.variables.indexOf(e);if(t===-1){console.warn("[Model.removeVariable] Variable not present in model");return}return this.variables.splice(t,1),this.tableauInitialized===!0&&this.tableau.removeVariable(e),this};J.prototype.updateRightHandSide=function(e,t){return this.tableauInitialized===!0&&this.tableau.updateRightHandSide(e,t),this};J.prototype.updateConstraintCoefficient=function(e,t,n){return this.tableauInitialized===!0&&this.tableau.updateConstraintCoefficient(e,t,n),this};J.prototype.setCost=function(e,t){var n=e-t.cost;return this.isMinimization===!1&&(n=-n),t.cost=e,this.tableau.updateCost(t,n),this};J.prototype.loadJson=function(e){this.isMinimization=e.opType!=="max";for(var t=e.variables,n=e.constraints,r={},i={},o=Object.keys(n),a=o.length,s=0;s<a;s+=1){var u=o[s],d=n[u],l=d.equal,f=d.weight,p=d.priority,m=f!==void 0||p!==void 0,g,c;if(l===void 0){var b=d.min;b!==void 0&&(g=this.greaterThan(b),r[u]=g,m&&g.relax(f,p));var y=d.max;y!==void 0&&(c=this.smallerThan(y),i[u]=c,m&&c.relax(f,p))}else{g=this.greaterThan(l),r[u]=g,c=this.smallerThan(l),i[u]=c;var h=new $r(g,c);m&&h.relax(f,p)}}var N=Object.keys(t),v=N.length;this.tolerance=e.tolerance||0,e.timeout&&(this.timeout=e.timeout),e.options&&(e.options.timeout&&(this.timeout=e.options.timeout),this.tolerance===0&&(this.tolerance=e.options.tolerance||0),e.options.useMIRCuts&&(this.useMIRCuts=e.options.useMIRCuts),typeof e.options.exitOnCycles=="undefined"?this.checkForCycles=!0:this.checkForCycles=e.options.exitOnCycles);for(var L=e.ints||{},k=e.binaries||{},w=e.unrestricted||{},S=e.optimize,O=0;O<v;O+=1){var I=N[O],z=t[I],M=z[S]||0,$=!!k[I],_=!!L[I]||$,W=!!w[I],B=this.addVariable(M,I,_,W);$&&this.smallerThan(1).addTerm(1,B);var Z=Object.keys(z);for(s=0;s<Z.length;s+=1){var E=Z[s];if(E!==S){var j=z[E],U=r[E];U!==void 0&&U.addTerm(j,B);var ne=i[E];ne!==void 0&&ne.addTerm(j,B)}}}return this};J.prototype.getNumberOfIntegerVariables=function(){return this.integerVariables.length};J.prototype.solve=function(){return this.tableauInitialized===!1&&(this.tableau.setModel(this),this.tableauInitialized=!0),this.tableau.solve()};J.prototype.isFeasible=function(){return this.tableau.feasible};J.prototype.save=function(){return this.tableau.save()};J.prototype.restore=function(){return this.tableau.restore()};J.prototype.activateMIRCuts=function(e){this.useMIRCuts=e};J.prototype.debug=function(e){this.checkForCycles=e};J.prototype.log=function(e){return this.tableau.log(e)}});var Ar=H(Wr=>{"use strict";Wr.CleanObjectiveAttributes=function(e){var t,n,r;if(typeof e.optimize=="string")if(e.constraints[e.optimize]){t=Math.random();for(n in e.variables)e.variables[n][e.optimize]&&(e.variables[n][t]=e.variables[n][e.optimize]);return e.constraints[t]=e.constraints[e.optimize],delete e.constraints[e.optimize],e}else return e;else{for(r in e.optimize)if(e.constraints[r])if(e.constraints[r]==="equal")delete e.optimize[r];else{t=Math.random();for(n in e.variables)e.variables[n][r]&&(e.variables[n][t]=e.variables[n][r]);e.constraints[t]=e.constraints[r],delete e.constraints[r]}return e}}});var Ct=H((Gu,Ur)=>{"use strict";function Pi(e){var t={is_blank:/^\W{0,}$/,is_objective:/(max|min)(imize){0,}\:/i,is_int:/^(?!\/\*)\W{0,}int/i,is_bin:/^(?!\/\*)\W{0,}bin/i,is_constraint:/(\>|\<){0,}\=/i,is_unrestricted:/^\S{0,}unrestricted/i,parse_lhs:/(\-|\+){0,1}\s{0,1}\d{0,}\.{0,}\d{0,}\s{0,}[A-Za-z]\S{0,}/gi,parse_rhs:/(\-|\+){0,1}\d{1,}\.{0,}\d{0,}\W{0,}\;{0,1}$/i,parse_dir:/(\>|\<){0,}\=/gi,parse_int:/[^\s|^\,]+/gi,parse_bin:/[^\s|^\,]+/gi,get_num:/(\-|\+){0,1}(\W|^)\d+\.{0,1}\d{0,}/g,get_word:/[A-Za-z].*/},n={opType:"",optimize:"_obj",constraints:{},variables:{}},r={">=":"min","<=":"max","=":"equal"},i="",o=0,a=null,s="",u="",d="",l=0;typeof e=="string"&&(e=e.split(`
`));for(var f=0;f<e.length;f++)if(d="__"+f,i=e[f],o=0,a=null,t.is_objective.test(i))n.opType=i.match(/(max|min)/gi)[0],a=i.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}).slice(1),a.forEach(function(g){s=g.match(t.get_num),s===null?g.substr(0,1)==="-"?s=-1:s=1:s=s[0],s=parseFloat(s),u=g.match(t.get_word)[0].replace(/\;$/,""),n.variables[u]=n.variables[u]||{},n.variables[u]._obj=s});else if(t.is_int.test(i))a=i.match(t.parse_int).slice(1),n.ints=n.ints||{},a.forEach(function(g){g=g.replace(";",""),n.ints[g]=1});else if(t.is_bin.test(i))a=i.match(t.parse_bin).slice(1),n.binaries=n.binaries||{},a.forEach(function(g){g=g.replace(";",""),n.binaries[g]=1});else if(t.is_constraint.test(i)){var p=i.indexOf(":"),m=p===-1?i:i.slice(p+1);a=m.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}),a.forEach(function(g){s=g.match(t.get_num),s===null?g.substr(0,1)==="-"?s=-1:s=1:s=s[0],s=parseFloat(s),u=g.match(t.get_word)[0],n.variables[u]=n.variables[u]||{},n.variables[u][d]=s}),l=parseFloat(i.match(t.parse_rhs)[0]),i=r[i.match(t.parse_dir)[0]],n.constraints[d]=n.constraints[d]||{},n.constraints[d][i]=l}else t.is_unrestricted.test(i)&&(a=i.match(t.parse_int).slice(1),n.unrestricted=n.unrestricted||{},a.forEach(function(g){g=g.replace(";",""),n.unrestricted[g]=1}));return n}function _i(e){if(!e)throw new Error("Solver requires a model to operate on");var t="",n=[],r=1,i={max:"<=",min:">=",equal:"="},o=new RegExp("[^A-Za-z0-9_[{}/.&#$%~'@^]","gi");if(e.opType){t+=e.opType+":";for(var a in e.variables)e.variables[a][a]=e.variables[a][a]?e.variables[a][a]:1,e.variables[a][e.optimize]&&(t+=" "+e.variables[a][e.optimize]+" "+a.replace(o,"_"))}else t+="max:";t+=`;
`;for(var s in e.constraints)for(var u in e.constraints[s])if(typeof i[u]!="undefined"){for(var d in e.variables)typeof e.variables[d][s]!="undefined"&&(t+=" "+e.variables[d][s]+" "+d.replace(o,"_"));t+=" "+i[u]+" "+e.constraints[s][u],t+=`;
`}if(e.ints){t+=`
`;for(var l in e.ints)t+="int "+l.replace(o,"_")+`;
`}if(e.unrestricted){t+=`
`;for(var f in e.unrestricted)t+="unrestricted "+f.replace(o,"_")+`;
`}return t}Ur.exports=function(e){return e.length?Pi(e):_i(e)}});var Er=H(()=>{"use strict"});var jr=H(()=>{"use strict"});var Hr=H(In=>{"use strict";In.reformat=Ct();function qr(e){return e=e.replace("\\r\\n",`\r
`),e=e.split(`\r
`),e=e.filter(function(t){var n;return n=new RegExp(" 0$","gi"),!(n.test(t)===!0||(n=new RegExp("\\d$","gi"),n.test(t)===!1))}).map(function(t){return t.split(/\:{0,1} +(?=\d)/)}).reduce(function(t,n,r){return t[n[0]]=n[1],t},{}),e}In.solve=function(e){return new Promise(function(t,n){typeof window!="undefined"&&n("Function Not Available in Browser");var r=Ct()(e);e.external||n("Data for this function must be contained in the 'external' attribute. Not seeing anything there."),e.external.binPath||n("No Executable | Binary path provided in arguments as 'binPath'"),e.external.args||n("No arguments array for cli | bash provided on 'args' attribute"),e.external.tempName||n("No 'tempName' given. This is necessary to produce a staging file for the solver to operate on");var i=Er();i.writeFile(e.external.tempName,r,function(o,a){if(o)n(o);else{var s=jr().execFile;e.external.args.push(e.external.tempName),s(e.external.binPath,e.external.args,function(u,d){if(u)if(u.code===1)t(qr(d));else{var l={"-2":"Out of Memory",1:"SUBOPTIMAL",2:"INFEASIBLE",3:"UNBOUNDED",4:"DEGENERATE",5:"NUMFAILURE",6:"USER-ABORT",7:"TIMEOUT",9:"PRESOLVED",25:"ACCURACY ERROR",255:"FILE-ERROR"},f={code:u.code,meaning:l[u.code],data:d};n(f)}else t(qr(d))})}})})}});var Zr=H(($u,Fr)=>{"use strict";Fr.exports={lpsolve:Hr()}});var Cn=H((Pu,Jr)=>{"use strict";Jr.exports=function(e,t){var n=t.optimize,r=JSON.parse(JSON.stringify(t.optimize)),i=Object.keys(t.optimize),o,a=0,s={},u="",d={},l=[],f,p,m,g,c;for(delete t.optimize,f=0;f<i.length;f++)r[i[f]]=0;for(f=0;f<i.length;f++){t.optimize=i[f],t.opType=n[i[f]],o=e.Solve(t,void 0,void 0,!0);for(g in i)if(!t.variables[i[g]]){o[i[g]]=o[i[g]]?o[i[g]]:0;for(m in t.variables)t.variables[m][i[g]]&&o[m]&&(o[i[g]]+=o[m]*t.variables[m][i[g]])}for(u="base",p=0;p<i.length;p++)o[i[p]]?u+="-"+(o[i[p]]*1e3|0)/1e3:u+="-0";if(!s[u]){for(s[u]=1,a++,p=0;p<i.length;p++)o[i[p]]&&(r[i[p]]+=o[i[p]]);delete o.feasible,delete o.result,l.push(o)}}for(f=0;f<i.length;f++)t.constraints[i[f]]={equal:r[i[f]]/a};t.optimize="cheater-"+Math.random(),t.opType="max";for(f in t.variables)t.variables[f].cheater=1;for(f in l)for(m in l[f])d[m]=d[m]||{min:1e99,max:-1e99};for(f in d)for(m in l)l[m][f]?(l[m][f]>d[f].max&&(d[f].max=l[m][f]),l[m][f]<d[f].min&&(d[f].min=l[m][f])):(l[m][f]=0,d[f].min=0);return o=e.Solve(t,void 0,void 0,!0),{midpoint:o,vertices:l,ranges:d}}});var Yr=H((_u,Kr)=>{"use strict";var Wi=zr(),Tn=_r(),Ai=On(),Mt=Dt(),Qr=Ar(),Ui=Mt.Constraint,Ei=Mt.Variable,ji=Mt.Numeral,qi=Mt.Term,Tt=Zr(),Gt=function(){"use strict";this.Model=Tn,this.branchAndCut=Ai,this.Constraint=Ui,this.Variable=Ei,this.Numeral=ji,this.Term=qi,this.Tableau=Wi,this.lastSolvedModel=null,this.External=Tt,this.Solve=function(e,t,n,r){if(r)for(var i in Qr)e=Qr[i](e);if(!e)throw new Error("Solver requires a model to operate on");if(typeof e.optimize=="object"&&Object.keys(e.optimize>1))return Cn()(this,e);if(e.external){var o=Object.keys(Tt);if(o=JSON.stringify(o),!e.external.solver)throw new Error("The model you provided has an 'external' object that doesn't have a solver attribute. Use one of the following:"+o);if(!Tt[e.external.solver])throw new Error("No support (yet) for "+e.external.solver+". Please use one of these instead:"+o);return Tt[e.external.solver].solve(e)}else{e instanceof Tn||(e=new Tn(t).loadJson(e));var a=e.solve();if(this.lastSolvedModel=e,a.solutionSet=a.generateSolutionSet(),n)return a;var s={};return s.feasible=a.feasible,s.result=a.evaluation,s.bounded=a.bounded,a._tableau.__isIntegral&&(s.isIntegral=!0),Object.keys(a.solutionSet).forEach(function(u){a.solutionSet[u]!==0&&(s[u]=a.solutionSet[u])}),s}},this.ReformatLP=Ct(),this.MultiObjective=function(e){return Cn()(this,e)}};typeof define=="function"?define([],function(){return new Gt}):typeof window=="object"?window.solver=new Gt:typeof self=="object"&&(self.solver=new Gt);Kr.exports=new Gt});var oo=H((td,ro)=>{"use strict";var at=1e-60,to,no;do at+=at,to=1+.1*at,no=1+.2*at;while(to<=1||no<=1);ro.exports=at});var ao=H((nd,io)=>{"use strict";function Fi(e,t,n){let r,i;for(let o=1;o<=n;o+=1){e[o][o]=1/e[o][o],i=-e[o][o];for(let a=1;a<o;a+=1)e[a][o]*=i;if(r=o+1,n<r)break;for(let a=r;a<=n;a+=1){i=e[o][a],e[o][a]=0;for(let s=1;s<=o;s+=1)e[s][a]+=i*e[s][o]}}}io.exports=Fi});var uo=H((rd,so)=>{"use strict";function Zi(e,t,n,r){let i,o;for(i=1;i<=n;i+=1){o=0;for(let a=1;a<i;a+=1)o+=e[a][i]*r[a];r[i]=(r[i]-o)/e[i][i]}for(let a=1;a<=n;a+=1){i=n+1-a,r[i]/=e[i][i],o=-r[i];for(let s=1;s<i;s+=1)r[s]+=o*e[s][i]}}so.exports=Zi});var fo=H((od,lo)=>{"use strict";function Ji(e,t,n,r){let i,o,a;for(let s=1;s<=n;s+=1){if(r[1]=s,a=0,i=s-1,i<1){if(a=e[s][s]-a,a<=0)break;e[s][s]=Math.sqrt(a)}else{for(let u=1;u<=i;u+=1){o=e[u][s];for(let d=1;d<u;d+=1)o-=e[d][s]*e[d][u];o/=e[u][u],e[u][s]=o,a+=o*o}if(a=e[s][s]-a,a<=0)break;e[s][s]=Math.sqrt(a)}r[1]=0}}lo.exports=Ji});var po=H((id,co)=>{"use strict";var Gn=oo(),Qi=ao(),Ki=uo(),Yi=fo();function Xi(e,t,n,r,i,o,a,s,u,d,l,f,p,m=0,g,c,b){let y,h,N,v,L,k,w,S,O,I,z,M,$,_,W=Math.min(r,l),B=2*r+W*(W+5)/2+2*l+1;for(let x=1;x<=r;x+=1)c[x]=t[x];for(let x=r+1;x<=B;x+=1)c[x]=0;for(let x=1;x<=l;x+=1)p[x]=0,o[x]=0;let Z=[];if(b[1]===0){if(Yi(e,n,r,Z),Z[1]!==0){b[1]=2;return}Ki(e,n,r,t),Qi(e,n,r)}else{for(let x=1;x<=r;x+=1){i[x]=0;for(let G=1;G<=x;G+=1)i[x]+=e[G][x]*t[G]}for(let x=1;x<=r;x+=1){t[x]=0;for(let G=x;G<=r;G+=1)t[x]+=e[x][G]*i[G]}}a[1]=0;for(let x=1;x<=r;x+=1){i[x]=t[x],a[1]+=c[x]*i[x],c[x]=0;for(let G=x+1;G<=r;G+=1)e[G][x]=0}a[1]=-a[1]/2,b[1]=0;let E=r,j=E+r,U=j+W,ne=U+W+1,ee=ne+W*(W+1)/2,ve=ee+l;for(let x=1;x<=l;x+=1){k=0;for(let G=1;G<=r;G+=1)k+=s[G][x]*s[G][x];c[ve+x]=Math.sqrt(k)}v=m,g[1]=0,g[2]=0;function Xo(){g[1]+=1,B=ee;for(let x=1;x<=l;x+=1){B+=1,k=-u[x];for(let G=1;G<=r;G+=1)k+=s[G][x]*i[G];if(Math.abs(k)<Gn&&(k=0),x>f)c[B]=k;else if(c[B]=-Math.abs(k),k>0){for(let G=1;G<=r;G+=1)s[G][x]=-s[G][x];u[x]=-u[x]}}for(let x=1;x<=v;x+=1)c[ee+p[x]]=0;N=0,L=0;for(let x=1;x<=l;x+=1)c[ee+x]<L*c[ve+x]&&(N=x,L=c[ee+x]/c[ve+x]);if(N===0){for(let x=1;x<=v;x+=1)o[p[x]]=c[U+x];return 999}return 0}function ei(){for(let x=1;x<=r;x+=1){k=0;for(let G=1;G<=r;G+=1)k+=e[G][x]*s[G][N];c[x]=k}y=E;for(let x=1;x<=r;x+=1)c[y+x]=0;for(let x=v+1;x<=r;x+=1)for(let G=1;G<=r;G+=1)c[y+G]=c[y+G]+e[G][x]*c[x];M=!0;for(let x=v;x>=1;x-=1){k=c[x],B=ne+x*(x+3)/2,y=B-x;for(let G=x+1;G<=v;G+=1)k-=c[B]*c[j+G],B+=G;k/=c[y],c[j+x]=k,!(p[x]<=f)&&(k<=0||(M=!1,h=x))}if(!M){w=c[U+h]/c[j+h];for(let x=1;x<=v;x+=1)p[x]<=f||c[j+x]<=0||(L=c[U+x]/c[j+x],L<w&&(w=L,h=x))}k=0;for(let x=E+1;x<=E+r;x+=1)k+=c[x]*c[x];if(Math.abs(k)<=Gn){if(M)return b[1]=1,999;for(let x=1;x<=v;x+=1)c[U+x]=c[U+x]-w*c[j+x];return c[U+v+1]=c[U+v+1]+w,700}k=0;for(let x=1;x<=r;x+=1)k+=c[E+x]*s[x][N];S=-c[ee+N]/k,$=!0,M||w<S&&(S=w,$=!1);for(let x=1;x<=r;x+=1)i[x]+=S*c[E+x],Math.abs(i[x])<Gn&&(i[x]=0);a[1]+=S*k*(S/2+c[U+v+1]);for(let x=1;x<=v;x+=1)c[U+x]=c[U+x]-S*c[j+x];if(c[U+v+1]=c[U+v+1]+S,$){v+=1,p[v]=N,B=ne+(v-1)*v/2+1;for(let x=1;x<=v-1;x+=1)c[B]=c[x],B+=1;if(v===r)c[B]=c[r];else{for(let x=r;x>=v+1;x-=1)if(c[x]!==0&&(O=Math.max(Math.abs(c[x-1]),Math.abs(c[x])),I=Math.min(Math.abs(c[x-1]),Math.abs(c[x])),c[x-1]>=0?L=Math.abs(O*Math.sqrt(1+I*I/(O*O))):L=-Math.abs(O*Math.sqrt(1+I*I/(O*O))),O=c[x-1]/L,I=c[x]/L,O!==1))if(O===0){c[x-1]=I*L;for(let G=1;G<=r;G+=1)L=e[G][x-1],e[G][x-1]=e[G][x],e[G][x]=L}else{c[x-1]=L,z=I/(1+O);for(let G=1;G<=r;G+=1)L=O*e[G][x-1]+I*e[G][x],e[G][x]=z*(e[G][x-1]+L)-e[G][x],e[G][x-1]=L}c[B]=c[v]}}else{k=-u[N];for(let x=1;x<=r;x+=1)k+=i[x]*s[x][N];if(N>f)c[ee+N]=k;else if(c[ee+N]=-Math.abs(k),k>0){for(let x=1;x<=r;x+=1)s[x][N]=-s[x][N];u[N]=-u[N]}return 700}return 0}function ti(){if(B=ne+h*(h+1)/2+1,y=B+h,c[y]===0||(O=Math.max(Math.abs(c[y-1]),Math.abs(c[y])),I=Math.min(Math.abs(c[y-1]),Math.abs(c[y])),c[y-1]>=0?L=Math.abs(O*Math.sqrt(1+I*I/(O*O))):L=-Math.abs(O*Math.sqrt(1+I*I/(O*O))),O=c[y-1]/L,I=c[y]/L,O===1))return 798;if(O===0){for(let x=h+1;x<=v;x+=1)L=c[y-1],c[y-1]=c[y],c[y]=L,y+=x;for(let x=1;x<=r;x+=1)L=e[x][h],e[x][h]=e[x][h+1],e[x][h+1]=L}else{z=I/(1+O);for(let x=h+1;x<=v;x+=1)L=O*c[y-1]+I*c[y],c[y]=z*(c[y-1]+L)-c[y],c[y-1]=L,y+=x;for(let x=1;x<=r;x+=1)L=O*e[x][h]+I*e[x][h+1],e[x][h+1]=z*(e[x][h]+L)-e[x][h+1],e[x][h]=L}return 0}function ni(){y=B-h;for(let x=1;x<=h;x+=1)c[y]=c[B],B+=1,y+=1;return c[U+h]=c[U+h+1],p[h]=p[h+1],h+=1,h<v?797:0}function Wn(){return c[U+v]=c[U+v+1],c[U+v+1]=0,p[v]=0,v-=1,g[2]+=1,0}for(_=0;;){if(_=Xo(),_===999)return;for(;_=ei(),_!==0;){if(_===999)return;if(_===700)if(h===v)Wn();else{for(;ti(),_=ni(),_===797;);Wn()}}}}co.exports=Xi});var mo=H(ho=>{"use strict";var ea=po();function ta(e,t,n,r=[],i=0,o=[0,0]){let a=[],s=[],u=[],d=[],l=[],f=[],p="",m=e.length-1,g=n[1].length-1;if(!r)for(let y=1;y<=g;y+=1)r[y]=0;if(m!==e[1].length-1&&(p="Dmat is not symmetric!"),m!==t.length-1&&(p="Dmat and dvec are incompatible!"),m!==n.length-1&&(p="Amat and dvec are incompatible!"),g!==r.length-1&&(p="Amat and bvec are incompatible!"),(i>g||i<0)&&(p="Value of meq is invalid!"),p!=="")return{message:p};for(let y=1;y<=g;y+=1)s[y]=0,d[y]=0;let c=0,b=Math.min(m,g);for(let y=1;y<=m;y+=1)u[y]=0;a[1]=0;for(let y=1;y<=2*m+b*(b+5)/2+2*g+1;y+=1)l[y]=0;for(let y=1;y<=2;y+=1)f[y]=0;return ea(e,t,m,m,u,d,a,n,r,m,g,i,s,c,f,l,o),o[1]===1&&(p="constraints are inconsistent, no solution!"),o[1]===2&&(p="matrix D in quadratic function is not positive definite!"),{solution:u,Lagrangian:d,value:a,unconstrained_solution:t,iterations:f,iact:s,message:p}}ho.solveQP=ta});var yo=H((sd,go)=>{"use strict";go.exports=mo()});var ya={};di(ya,{aggMean:()=>Bt,aggMedian:()=>No,aggWeightedMedian:()=>Mn,cachedNodeSize:()=>it,coordCenter:()=>Mo,coordGreedy:()=>Bo,coordQuad:()=>Vo,coordSimplex:()=>At,coordTopological:()=>Po,decrossDfs:()=>st,decrossOpt:()=>_o,decrossTwoLayer:()=>Ht,graph:()=>ie,graphConnect:()=>rr,graphHierarchy:()=>ar,graphJson:()=>Kn,graphStratify:()=>dr,grid:()=>pr,laneGreedy:()=>Lt,laneOpt:()=>eo,layerSeparation:()=>Ft,layeringLongestPath:()=>Wo,layeringSimplex:()=>Zt,layeringTopological:()=>Uo,shapeEllipse:()=>Zo,shapeRect:()=>_n,sizedSeparation:()=>Et,splitNodeSize:()=>zt,sugiNodeLength:()=>Kt,sugifyCompact:()=>Co,sugifyLayer:()=>Jt,sugiyama:()=>Go,tweakFlip:()=>Fo,tweakGrid:()=>Ho,tweakShape:()=>Jo,tweakSize:()=>qo,twolayerAgg:()=>Vt,twolayerGreedy:()=>Ut,twolayerOpt:()=>jo,unsugify:()=>Qt,zherebko:()=>Yo});module.exports=li(ya);function qn(e,t){if(t.size!==e.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Hn(e){for(let t of e)return t}function qe(e){for(let t of e)return e.delete(t),t}function Re(e,t,n){let r=e.get(t);r===void 0?e.set(t,[n]):r.push(n)}function ft(e,t,n){let r=e.get(t);r===void 0?e.set(t,new Set([n])):r.add(n)}function tn(e,t,n){let r=e.get(t);r!==void 0&&(r.delete(n),r.size||e.delete(t))}var{toString:ci}=Object.prototype;function nn(e){return ci.call(e)==="[object RegExp]"}function rn(e){let t=typeof e;return e!==null&&(t==="object"||t==="function")}var{propertyIsEnumerable:pi}=Object.prototype;function on(e){return[...Object.keys(e),...Object.getOwnPropertySymbols(e).filter(t=>pi.call(e,t))]}function an(e,t,n){let r=[];return function i(o,a={},s=""){let u=a.indent||" ",d;a.inlineCharacterLimit===void 0?d={newline:`
`,newlineOrSpace:`
`,pad:s,indent:s+u}:d={newline:"@@__STRINGIFY_OBJECT_NEW_LINE__@@",newlineOrSpace:"@@__STRINGIFY_OBJECT_NEW_LINE_OR_SPACE__@@",pad:"@@__STRINGIFY_OBJECT_PAD__@@",indent:"@@__STRINGIFY_OBJECT_INDENT__@@"};let l=f=>{if(a.inlineCharacterLimit===void 0)return f;let p=f.replace(new RegExp(d.newline,"g"),"").replace(new RegExp(d.newlineOrSpace,"g")," ").replace(new RegExp(d.pad+"|"+d.indent,"g"),"");return p.length<=a.inlineCharacterLimit?p:f.replace(new RegExp(d.newline+"|"+d.newlineOrSpace,"g"),`
`).replace(new RegExp(d.pad,"g"),s).replace(new RegExp(d.indent,"g"),s+u)};if(r.includes(o))return'"[Circular]"';if(o==null||typeof o=="number"||typeof o=="boolean"||typeof o=="function"||typeof o=="symbol"||nn(o))return String(o);if(o instanceof Date)return`new Date('${o.toISOString()}')`;if(Array.isArray(o)){if(o.length===0)return"[]";r.push(o);let f="["+d.newline+o.map((p,m)=>{let g=o.length-1===m?d.newline:","+d.newlineOrSpace,c=i(p,a,s+u);return a.transform&&(c=a.transform(o,m,c)),d.indent+c+g}).join("")+d.pad+"]";return r.pop(),l(f)}if(rn(o)){let f=on(o);if(a.filter&&(f=f.filter(m=>a.filter(o,m))),f.length===0)return"{}";r.push(o);let p="{"+d.newline+f.map((m,g)=>{let c=f.length-1===g?d.newline:","+d.newlineOrSpace,b=typeof m=="symbol",y=!b&&/^[a-z$_][$\w]*$/i.test(m),h=b||y?m:i(m,a),N=i(o[m],a,s+u);return a.transform&&(N=a.transform(o,m,N)),d.indent+String(h)+": "+N+c}).join("")+d.pad+"}";return r.pop(),l(p)}return o=o.replace(/\\/g,"\\\\"),o=String(o).replace(/[\r\n]/g,f=>f===`
`?"\\n":"\\r"),a.singleQuotes===!1?(o=o.replace(/"/g,'\\"'),`"${o}"`):(o=o.replace(/'/g,"\\'"),`'${o}'`)}(e,t,n)}function*Oe(e,...t){let n=new Set,r;for(;(r=t.pop())!==void 0;)n.has(r)||(yield r,n.add(r),t.push(...e(r)))}function sn(e,t){let n=[];for(let[r,i]of K(t))n.push(e[r]),n.push(i);return n.push(e[e.length-1]),n.join("")}function D(e,...t){let n=A(t,r=>an(r,{indent:" ",singleQuotes:!1,inlineCharacterLimit:60}));return new Error(sn(e,n))}function Fn(e){return`internal error: ${e}; if you encounter this please submit an issue at: https://github.com/erikbrinkman/d3-dag/issues`}function te(e,...t){let n=A(t,r=>r.toString());return new Error(Fn(sn(e,n)))}function oe(e,t,...n){let[r,...i]=e,o=A(n,u=>u.toString()),a=sn(i,o),s=t.name||"anonymous";return new Error("d3dagBuiltin"in t?Fn(`builtin ${r}'${s}'${a}`):`custom ${r}'${s}'${a}`)}function*K(e){let t=0;for(let n of e)yield[t++,n]}function*Ne(e,t){for(let[n,r]of K(e))yield*Y(t(r,n))}function Zn(e,t,n){let r=n;for(let[i,o]of K(e))r=t(r,o,i);return r}function*A(e,t){for(let[n,r]of K(e))yield t(r,n)}function*be(e,t){for(let[n,r]of K(e))t(r,n)&&(yield r)}function un(e,t){for(let[n,r]of K(e))if(t(r,n))return!0;return!1}function Jn(e,t){return!un(e,(n,r)=>!t(n,r))}function*hi(e,t,n,r){let i=Math.min(n,e.length);for(let o=t;o<i;o+=r)yield e[o]}function*mi(e,t,n,r){let i=Math.max(n,-1);for(let o=t;o>i;o+=r)yield e[o]}function q(e,t=0,n=e.length,r=1){if(r>0)return hi(e,t,n,r);if(r<0)return mi(e,t,n,r);throw D`can't slice with zero stride`}function*ue(...e){for(let t of e)yield*Y(t)}function*Q(e){let t=e[Symbol.iterator](),n=t.next();if(!n.done){let r=n.value,i;for(;!(i=t.next()).done;)yield[r,i.value],r=i.value}}function Qn(e){for(let t of e)return t}function ct(e){return typeof e=="object"&&e!==null&&Symbol.iterator in e&&typeof e[Symbol.iterator]=="function"}function gi(e){if(typeof e!="object"||e===null)return!1;let t="x"in e?e.x:void 0,n="y"in e?e.y:void 0,r="data"in e?e.data:void 0;if(typeof t!="number"&&t!==void 0||typeof n!="number"&&n!==void 0)return!1;let i={x:t,y:n,data:r};return!0}function yi(e){if(!Array.isArray(e)||e.length!==2)return!1;let t=e,[n,r]=t;return typeof n=="number"&&typeof r=="number"}function Ni(e){if(typeof e!="object"||e===null||!("source"in e)||!("target"in e)||!("points"in e))return!1;let{source:t,target:n,points:r}=e,i="data"in e?e.data:void 0;if(typeof t!="number"||typeof n!="number"||!Array.isArray(r)||!r.every(yi))return!1;let o={source:t,target:n,points:r,data:i};return!0}function ln(e){let t=[],n,r=new Map;for(let[a,s]of K(e.nodes()))r.set(s,a),t.push({x:s.ux,y:s.uy,data:s.data}),s===e&&(n=a);let i=[];for(let{source:a,target:s,data:u,points:d}of e.links())i.push({source:r.get(a),target:r.get(s),points:d,data:u});return{nodes:t,links:i,index:n,v:1}}function bi(e,t,n,r,i){let o=ie(),a=e.map(({x:s,y:u,data:d})=>{let l=o.node(r(d));return l.ux=s,l.uy=u,l});for(let{source:s,target:u,points:d,data:l}of t){let f=o.link(a[s],a[u],i(l));f.points=d.map(([p,m])=>[p,m])}return n===void 0?o:a[n]}function dn(e){function t(i){if(typeof i!="object"||i===null)throw D`parsedJson was null or wasn't an object: ${i}`;if(!("nodes"in i)||!("links"in i))throw D`parsedJson didn't have 'nodes' and 'links' properties: ${i}`;let{nodes:o,links:a}=i,s="index"in i?i.index:void 0;if(!Array.isArray(o)||!Array.isArray(a))throw D`'nodes' and 'links' weren't arrays: ${i}`;if(!o.every(gi)||!a.every(Ni)||s!==void 0&&typeof s!="number")throw D`'nodes' and 'links' didn't have the appropriate structure: ${i}`;return bi(o,a,s,e.nodeDatum,e.linkDatum)}function n(i){if(i===void 0)return e.nodeDatum;{let o=e,{nodeDatum:a}=o,s=V(o,["nodeDatum"]);return dn(T({nodeDatum:i},s))}}t.nodeDatum=n;function r(i){if(i===void 0)return e.linkDatum;{let o=e,{linkDatum:a}=o,s=V(o,["linkDatum"]);return dn(T({linkDatum:i},s))}}return t.linkDatum=r,t}function Kn(...e){if(e.length)throw D`got arguments to graphJson(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`graphJson()(...)\``;return dn({nodeDatum:t=>t,linkDatum:t=>t})}var fn=class{constructor(t,n,r,i="inactive"){this.node=t;this.indeg=n;this.outdeg=r;this.stat=i}bucket(){let t=this.indeg===0?-1/0:this.outdeg===0?1/0:this.indeg-this.outdeg;return this.stat==="top"?Math.min(t,0):this.stat==="bottom"?Math.max(t,0):t}isTop(){return this.indeg<=this.outdeg&&this.stat!=="bottom"||this.stat==="top"}};function Yn(e,t){let n=e[t];if(n===void 0){let r=new Set;return e[t]=r,r}else return n}function Xn(e){var n;let t;for(;e.length&&!((n=t=e[e.length-1])!=null&&n.size);)e.pop();return t||void 0}function nr(e,t=()=>{}){let n=new Map,r=new Map,i=new Set,o=new Set,a=[],s=[];function u(N){return N===-1/0?i:N===1/0?o:N<=0?Yn(a,-N):Yn(s,N-1)}for(let N of e){let v=N.nparentLinks(),L=N.nchildLinks(),k=new fn(N,v,L),w=t(N);n.set(N,k),w===void 0?(k.stat="active",u(k.bucket()).add(k)):ft(r,w,k)}let d=[...r].sort(([N],[v])=>N-v).map(([,N])=>N),l=0,f=d.length,p=d.length?d[l++]:new Set,m=d.length>1?d[--f]:new Set;for(let N of p)N.stat="top",u(N.bucket()).add(N);for(let N of m)N.stat="bottom",u(N.bucket()).add(N);function g(){var k;let N;if(N=(k=qe(i))!=null?k:qe(o))return N;let v=Xn(a),L=Xn(s);if(L)return qe(a.length>s.length?v:L);if(v)return qe(v)}let c=Array(n.size),b=0,y=n.size,h;for(;h=g();){let{node:N}=h,v=h.isTop()?b++:--y;h.stat="ranked",c[v]=N;for(let[L,k]of N.parentCounts()){let w=n.get(L);u(w.bucket()).delete(w),w.outdeg-=k,w.stat!=="ranked"&&w.stat!=="inactive"&&u(w.bucket()).add(w)}for(let[L,k]of N.childCounts()){let w=n.get(L);u(w.bucket()).delete(w),w.indeg-=k,w.stat!=="ranked"&&w.stat!=="inactive"&&u(w.bucket()).add(w)}if(p.delete(h),!p.size&&l<f){p=d[l++];for(let L of p)L.stat="top",u(L.bucket()).add(L)}if(m.delete(h),!m.size&&l<f){m=d[--f];for(let L of m)L.stat="bottom",u(L.bucket()).add(L)}}return c}function er(e,t){let n=new Set,r=new Set,i=[],o;for(let a of e)if(!r.has(a)){for(i.push(a);o=i.pop();)n.delete(o),!r.has(o)&&(r.add(o),i.push(...t(o)));n.add(a)}return n}function xi(e){let t=new Map(A(e,i=>[i,i.nparents()])),n=[...A(be(t,([,i])=>i===0),([i])=>i)];for(let i of n)t.delete(i);let r;for(;r=n.pop();)for(let i of r.children()){let o=t.get(i)-1;o?t.set(i,o):(t.delete(i),n.push(i))}return!t.size}var Be,Ve,$e,ce,Fe,Ze,ht,mt,gt,cn=class{constructor(){F(this,Be,0);F(this,Ve,0);F(this,$e,0);F(this,ce,!0);F(this,Fe,new Set);F(this,Ze,new Set);F(this,ht,()=>{P(this,Be,C(this,Be)-1)});F(this,mt,(t,n)=>{P(this,Ve,C(this,Ve)+1),t?P(this,$e,C(this,$e)+1):!n&&C(this,ce)===!0&&P(this,ce,null)});F(this,gt,t=>{P(this,Ve,C(this,Ve)-1),t?P(this,$e,C(this,$e)-1):C(this,ce)===!1&&P(this,ce,null)})}*nodes(){for(let t of this.split())yield*Y(t.nodes())}topological(t){return nr(this.nodes(),t)}*links(){for(let t of this.nodes())yield*Y(t.childLinks())}nnodes(){return C(this,Be)}nlinks(){return C(this,Ve)}*roots(){for(let t of this.split())yield*Y(t.roots())}*leaves(){for(let t of this.split())yield*Y(t.leaves())}*split(){yield*Y(C(this,Fe));let t;for(;t=Hn(C(this,Ze));)yield t,t.nnodes()}connected(){let t=!1;for(let n of this.split()){if(t)return!1;t=!0}return!0}multi(){return!!C(this,$e)}acyclic(){if(C(this,ce)===null){for(let t of this.split())if(!t.acyclic())return P(this,ce,!1),!1;return P(this,ce,!0),!0}else return C(this,ce)}node(t){return P(this,Be,C(this,Be)+1),new pt(this,C(this,Fe),C(this,Ze),C(this,ht),C(this,mt),C(this,gt),t)}link(t,n,r){return t.link(t,n,r)}toJSON(){return ln(this)}};Be=new WeakMap,Ve=new WeakMap,$e=new WeakMap,ce=new WeakMap,Fe=new WeakMap,Ze=new WeakMap,ht=new WeakMap,mt=new WeakMap,gt=new WeakMap;function tr(e){for(let t of e.values())for(let n of t)return n}function ze(e){return e instanceof pt}var re,Je,Qe,Ke,xe,we,Ie,Pe,de,_e,le,ae,X,Ce,He,he,Le,yt,pt=class{constructor(t,n,r,i,o,a,s){this.data=s;F(this,Ce);F(this,he);F(this,re,void 0);F(this,Je,void 0);F(this,Qe,void 0);F(this,Ke,void 0);F(this,xe,void 0);F(this,we,void 0);F(this,Ie,0);F(this,Pe,0);F(this,de,new Map);F(this,_e,0);F(this,le,new Map);F(this,ae,void 0);F(this,X,void 0);F(this,yt,t=>{var o,a;let{source:n,target:r}=t,i=n.nchildLinksTo(r)>1;if(i){P(n,Ie,C(n,Ie)-1);let s=se(o=n,he,Le).call(o);s.nlinks-=1,s.multis-=1}else{let s=se(a=n,Ce,He).call(a);P(s,X,null),C(this,xe).delete(s),C(this,we).add(n),P(n,ae,n),P(n,X,null),C(this,we).add(r),P(r,ae,r),P(r,X,null)}C(this,Ke).call(this,i),tn(C(n,le),r,t),P(n,_e,C(n,_e)-1),tn(C(r,de),n,t),P(r,Pe,C(r,Pe)-1)});P(this,re,t),P(this,xe,n),P(this,we,r),P(this,Je,i),P(this,Qe,o),P(this,Ke,a),P(this,ae,this),P(this,X,{nnodes:1,nlinks:0,multis:0,acyclic:!0,roots:[this],leaves:[this]}),C(this,xe).add(this)}get x(){if(this.ux===void 0)throw D`can't get \`x\` when \`ux\` is undefined`;return this.ux}set x(t){this.ux=t}get y(){if(this.uy===void 0)throw D`can't get \`y\` when \`uy\` is undefined`;return this.uy}set y(t){this.uy=t}*nodes(){yield*Y(Oe(t=>ue(t.children(),t.parents()),this))}topological(t){return nr(this.nodes(),t)}*links(){for(let t of this.nodes())yield*Y(t.childLinks())}nnodes(){return se(this,he,Le).call(this).nnodes}nlinks(){return se(this,he,Le).call(this).nlinks}*split(){yield this}connected(){return!0}multi(){return se(this,he,Le).call(this).multis>0}acyclic(){let t=se(this,he,Le).call(this);return t.acyclic===null?t.acyclic=xi(this.nodes()):t.acyclic}node(t){if(C(this,re))return C(this,re).node(t);throw D`can't add a node from a deleted node`}link(t,n,r){var i,o;if(C(this,re)){if(t===n)throw D`tried to create a link between the same node, but self loops are not supported`;if(ze(t)&&ze(n)&&C(t,re)===C(n,re)&&C(this,re)===C(t,re)){let a=new pn(C(this,re),t,n,C(this,yt),r),s=t.nchildLinksTo(n)>0,u=se(i=t,Ce,He).call(i),d=C(u,X),l=se(o=n,Ce,He).call(o),f=C(l,X);if(s&&d)P(t,Ie,C(t,Ie)+1),d.nlinks+=1,d.multis+=1;else if(s)P(t,Ie,C(t,Ie)+1);else if(u===l&&d)d.nlinks+=1,d.acyclic===!0&&(d.acyclic=null);else if(u!==l&&d&&f){let[p,m,g,c]=d.nnodes>f.nnodes?[u,d,l,f]:[l,f,u,d];C(this,xe).delete(g),P(g,ae,p),P(g,X,void 0),m.nnodes+=c.nnodes,m.nlinks+=c.nlinks+1,m.multis+=c.multis,m.acyclic=m.acyclic===!1||c.acyclic===!1?!1:m.acyclic===!0&&c.acyclic===!0?!0:null,m.roots=null,m.leaves=null}else u!==l&&(P(u,X,null),P(l,X,null));return C(this,Qe).call(this,s,u!==l),P(t,_e,C(t,_e)+1),ft(C(t,le),n,a),P(n,Pe,C(n,Pe)+1),ft(C(n,de),t,a),a}else throw D`when creating a link, both source and target must be current members of the same graph, and can't have been deleted`}else throw D`can't add a link from a deleted node`}nparents(){return C(this,de).size}nchildren(){return C(this,le).size}nparentLinks(){return C(this,Pe)}nchildLinks(){return C(this,_e)}nparentLinksTo(t){var n,r;return ze(t)&&(r=(n=C(this,de).get(t))==null?void 0:n.size)!=null?r:0}*parentLinksTo(t){if(ze(t)){let n=C(this,de).get(t);n&&(yield*Y(n))}}nchildLinksTo(t){var n,r;return ze(t)&&(r=(n=C(this,le).get(t))==null?void 0:n.size)!=null?r:0}*childLinksTo(t){if(ze(t)){let n=C(this,le).get(t);n&&(yield*Y(n))}}*parents(){yield*Y(C(this,de).keys())}*children(){yield*Y(C(this,le).keys())}*parentCounts(){for(let[t,n]of C(this,de))yield[t,n.size]}*childCounts(){for(let[t,n]of C(this,le))yield[t,n.size]}*parentLinks(){for(let t of C(this,de).values())yield*Y(t)}*childLinks(){for(let t of C(this,le).values())yield*Y(t)}*ancestors(){yield*Y(Oe(t=>t.parents(),this))}*descendants(){yield*Y(Oe(t=>t.children(),this))}*roots(){let t=se(this,he,Le).call(this);t.roots||(t.roots=[...er(this.nodes(),n=>n.children())]),yield*Y(t.roots)}*leaves(){let t=se(this,he,Le).call(this);t.leaves||(t.leaves=[...er(this.nodes(),n=>n.parents())]),yield*Y(t.leaves)}parent(t,n){return this.link(t,this,n)}child(t,n){return this.link(this,t,n)}delete(){if(C(this,re)){let t;for(;t=tr(C(this,le));)t.delete();for(;t=tr(C(this,de));)t.delete();C(this,xe).delete(this),C(this,we).delete(this),C(this,Je).call(this),P(this,re,null),P(this,X,null)}}toJSON(){return ln(this)}};re=new WeakMap,Je=new WeakMap,Qe=new WeakMap,Ke=new WeakMap,xe=new WeakMap,we=new WeakMap,Ie=new WeakMap,Pe=new WeakMap,de=new WeakMap,_e=new WeakMap,le=new WeakMap,ae=new WeakMap,X=new WeakMap,Ce=new WeakSet,He=function(){let t=this;for(;C(t,ae)!==t;)P(t,ae,C(C(t,ae),ae)),t=C(t,ae);return t},he=new WeakSet,Le=function(){let t=se(this,Ce,He).call(this);if(C(t,X)===void 0)throw te`undefined cached info`;if(C(t,X)!==null)return C(t,X);{let n=0,r=0,i=0;for(let o of this.nodes())n+=1,r+=o.nchildLinks(),i+=C(o,Ie),P(o,ae,this),P(o,X,void 0),C(this,we).delete(o);return C(this,xe).add(this),P(this,X,{nnodes:n,nlinks:r,multis:i,acyclic:null,roots:null,leaves:null})}},yt=new WeakMap;var We,Ye,pn=class{constructor(t,n,r,i,o){this.source=n;this.target=r;this.data=o;F(this,We,void 0);F(this,Ye,void 0);this.points=[];P(this,We,t),P(this,Ye,i)}delete(){C(this,We)&&(C(this,Ye).call(this,this),P(this,We,null))}};We=new WeakMap,Ye=new WeakMap;function ie(){return new cn}function Xe(e){if(typeof e!="string")throw D`id is supposed to be type string but got type ${typeof e}`;return e}function et(e){function t(a){let s=ie(),u=new Map;for(let[d,l]of a.entries()){let f=Xe(e.sourceId(l,d)),p=u.get(f);p===void 0&&(p=s.node(e.nodeDatum(f,d)),u.set(f,p));let m=Xe(e.targetId(l,d)),g=u.get(m);g===void 0&&(g=s.node(e.nodeDatum(m,d)),u.set(m,g)),(f!==m||!e.single)&&s.link(p,g,l)}return s}function n(a){if(a===void 0)return e.sourceId;{let s=e,{sourceId:u}=s,d=V(s,["sourceId"]);return et(R(T({},d),{sourceId:a}))}}t.sourceId=n;function r(a){if(a===void 0)return e.targetId;{let s=e,{targetId:u}=s,d=V(s,["targetId"]);return et(R(T({},d),{targetId:a}))}}t.targetId=r;function i(a){if(a===void 0)return e.nodeDatum;{let s=e,{nodeDatum:u}=s,d=V(s,["nodeDatum"]);return et(R(T({},d),{nodeDatum:a}))}}t.nodeDatum=i;function o(a){return a===void 0?e.single:et(R(T({},e),{single:a}))}return t.single=o,t}function ki(e){if(typeof e!="object"||e===null||!(0 in e))throw D`default source id expected datum[0] to exist but got datum: ${e}; you should check the data you're passing to \`graphConnect()\` to make sure it looks like \`[[source_id, target_id], ...]\` or set a custom accessor with \`graphConnect().source(d => ...).target(d => ...)\``;let t=e[0];if(typeof t=="string")return t;throw D`default source id expected datum[0] to be a string but got datum: ${e}; you should check the data you're passing to \`graphConnect()\` to make sure it looks like \`[[source_id, target_id], ...]\` or set a custom accessor with \`graphConnect().source(d => ...).target(d => ...)\``}function vi(e){if(typeof e!="object"||e===null||!(1 in e))throw D`default target id expected datum[1] to exist but got datum: ${e}; you should check the data you're passing to \`graphConnect()\` to make sure it looks like \`[[source_id, target_id], ...]\` or set a custom accessor with \`graphConnect().source(d => ...).target(d => ...)\``;let t=e[1];if(typeof t=="string")return t;throw D`default target id expected datum[1] to be a string but got datum: ${e}; you should check the data you're passing to \`graphConnect()\` to make sure it looks like \`[[source_id, target_id], ...]\` or set a custom accessor with \`graphConnect().source(d => ...).target(d => ...)\``}function Li(e){return e}function rr(...e){if(e.length)throw D`got arguments to graphConnect(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`graphConnect()(...)\``;return et({sourceId:ki,targetId:vi,nodeDatum:Li,single:!1})}function hn(e,t){function n(...o){var f,p;let a=ie(),s=new Map,u=[],d=0;for(let m of o)if(!s.has(m)){let g=a.node(m);s.set(m,g);for(let[c,b]of(f=t(m,d++))!=null?f:[])u.push([g,c,b])}let l;for(;l=u.pop();){let[m,g,c]=l,b=s.get(g);if(b)a.link(m,b,c);else{let y=a.node(g);s.set(g,y),a.link(m,y,c);let h=(p=t(g,d++))!=null?p:[];for(let[N,v]of h)u.push([y,N,v])}}return a}function r(o){return o===void 0?e:hn(o,ir(o))}n.children=r;function i(o){return o===void 0?t:hn(wi(o),o)}return n.childrenData=i,n}function ir(e){function t(n,r){var i;return A((i=e(n,r))!=null?i:[],o=>[o,void 0])}return t.wrapped=e,t}function wi(e){function t(n,r){var i;return A((i=e(n,r))!=null?i:[],([o])=>o)}return t.wrapped=e,t}function Di(e){if(typeof e!="object"||e===null)return!1;if("children"in e){let{children:t}=e;return t===void 0||ct(t)}else return!0}function or(e){if(Di(e))return e.children;throw D`datum did not have an iterable children field, and no custom children accessor was specified; try calling \`graphHierarchy().children(d => ...)\` to set a custom children accessor`}function ar(...e){if(e.length)throw D`got arguments to graphHierarchy(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`graphHierarchy()(...)\``;return hn(or,ir(or))}function Nt(e){function t(o){var d;let a=ie(),s=new Map,u=[];for(let[l,f]of o.entries()){let p=Xe(e.id(f,l)),m=a.node(f),g=(d=e.parentData(f,l))!=null?d:[];for(let[c,b]of g)u.push([c,m,b]);if(s.has(p))throw D`found a duplicate id: ${n}, but ids passed to \`graphStratify()\` must be unique`;s.set(p,m)}for(let[l,f,p]of u){let m=s.get(l);if(!m)throw D`missing id: ${l}; this id was references in a node's parentIds, but no node with that id exists`;a.link(m,f,p)}return a}function n(o){if(o===void 0)return e.id;{let a=e,{id:s}=a,u=V(a,["id"]);return Nt(R(T({},u),{id:o}))}}t.id=n;function r(o){if(o===void 0)return e.parentData;{let a=e,{parentIds:s,parentData:u}=a,d=V(a,["parentIds","parentData"]);return Nt(R(T({},d),{parentIds:Si(o),parentData:o}))}}t.parentData=r;function i(o){if(o===void 0)return e.parentIds;{let a=e,{parentIds:s,parentData:u}=a,d=V(a,["parentIds","parentData"]);return Nt(R(T({},d),{parentIds:o,parentData:ur(o)}))}}return t.parentIds=i,t}function ur(e){function t(n,r){var i;return A((i=e(n,r))!=null?i:[],o=>[o,void 0])}return t.wrapped=e,t}function Si(e){function t(n,r){var i;return A((i=e(n,r))!=null?i:[],([o])=>o)}return t.wrapped=e,t}function Oi(e){if(typeof e!="object"||e===null||!("id"in e))throw D`datum did not have an id field, and no id accessor was specified; try calling \`graphStratify().id(d => d...)\` to set a custom id accessor`;let{id:t}=e;if(typeof t=="string")return t;throw D`datum has an id field that was not a string, and no id accessor was specified; try calling \`graphStratify().id(d => d...)\` to set a custom id accessor`}function sr(e){if(typeof e!="object"||e===null)throw D`default parentIds function expected datum to be an object but got: ${e}; try setting a custom accessor for parentIds with \`graphStratify().parentIds(d => ...)\``;if(!("parentIds"in e))return;let{parentIds:t}=e;if(t===void 0||ct(t)&&Jn(t,n=>typeof n=="string"))return t;throw D`default parentIds function expected parentIds to be an iterable of strings but got: ${t}; try setting a custom accessor for parentIds with \`graphStratify().parentIds(d => ...)\``}function dr(...e){if(e.length)throw D`got arguments to graphStratify(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`graphStratify()(...)\``;return Nt({id:Oi,parentIds:sr,parentData:ur(sr)})}function De(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function*lr(e,t){if(t===void 0)for(let n of e)n!=null&&(n=+n)>=n&&(yield n);else{let n=-1;for(let r of e)(r=t(r,++n,e))!=null&&(r=+r)>=r&&(yield r)}}function fr(e=De){if(e===De)return mn;if(typeof e!="function")throw new TypeError("compare is not a function");return(t,n)=>{let r=e(t,n);return r||r===0?r:(e(n,n)===0)-(e(t,t)===0)}}function mn(e,t){return(e==null||!(e>=e))-(t==null||!(t>=t))||(e<t?-1:e>t?1:0)}function bt(e,t){let n;if(t===void 0)for(let r of e)r!=null&&(n<r||n===void 0&&r>=r)&&(n=r);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n<i||n===void 0&&i>=i)&&(n=i)}return n}function xt(e,t){let n;if(t===void 0)for(let r of e)r!=null&&(n>r||n===void 0&&r>=r)&&(n=r);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n>i||n===void 0&&i>=i)&&(n=i)}return n}function kt(e,t,n=0,r=1/0,i){if(t=Math.floor(t),n=Math.floor(Math.max(0,n)),r=Math.floor(Math.min(e.length-1,r)),!(n<=t&&t<=r))return e;for(i=i===void 0?mn:fr(i);r>n;){if(r-n>600){let u=r-n+1,d=t-n+1,l=Math.log(u),f=.5*Math.exp(2*l/3),p=.5*Math.sqrt(l*f*(u-f)/u)*(d-u/2<0?-1:1),m=Math.max(n,Math.floor(t-d*f/u+p)),g=Math.min(r,Math.floor(t+(u-d)*f/u+p));kt(e,t,m,g,i)}let o=e[t],a=n,s=r;for(tt(e,n,t),i(e[r],o)>0&&tt(e,n,r);a<s;){for(tt(e,a,s),++a,--s;i(e[a],o)<0;)++a;for(;i(e[s],o)>0;)--s}i(e[n],o)===0?tt(e,n,s):(++s,tt(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}return e}function tt(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function gn(e,t,n){if(e=Float64Array.from(lr(e,n)),!(!(r=e.length)||isNaN(t=+t))){if(t<=0||r<2)return xt(e);if(t>=1)return bt(e);var r,i=(r-1)*t,o=Math.floor(i),a=bt(kt(e,o).subarray(0,o+1)),s=xt(e.subarray(o+1));return a+(s-a)*(i-o)}}function Se(e,t){return gn(e,.5,t)}function nt(e,t=De){let n,r=!1;if(t.length===1){let i;for(let o of e){let a=t(o);(r?De(a,i)<0:De(a,a)===0)&&(n=o,i=a,r=!0)}}else for(let i of e)(r?t(i,n)<0:t(i,i)===0)&&(n=i,r=!0);return n}function me(e){return new Set(be(ue(e.children(),e.parents()),t=>t.y>e.y))}function cr(e,t){for(let i of e){if(i.ux===void 0)throw oe`lane ${t} didn't assign an x to every node`;if(i.x<0)throw oe`lane ${t} assigned an x less than 0: ${i.x}`}let n=new Set(e.map(i=>i.x));if(!qn(n,new Set(A(n,(i,o)=>o)))){let i=[...n].sort((o,a)=>o-a).join(", ");throw oe`lane ${t} didn't assign increasing positive integers for x coordinates: ${i}`}let r=new Map;for(let[i,o]of e.entries()){let a=r.get(o);if(a!==void 0){for(let s of q(e,a+1,i))if(s.x===o.x)throw oe`lane ${t} assigned nodes to an overlapping lane: ${o.x}`}for(let s of o.children())r.has(s)||r.set(s,i)}return n.size}var yn=class{constructor(t){this.uncompressed=t;this.indices=[]}getIndex(t,n){var a;let r=[];for(let[s,u]of this.indices.entries())u<=t&&r.push(s);this.uncompressed&&r.push(this.indices.length);let i=n===void 0?0:n,o=(a=nt(r,s=>[Math.abs(i-s),s]))!=null?a:this.indices.length;return this.setIndex(o,t),o}setIndex(t,n){this.indices[t]=n}offset(){return 0}},Nn=class{constructor(t){this.uncompressed=t;this.posIndices=[0];this.negIndices=[]}nextNeg(){return-this.negIndices.length-1}nextPos(){return this.posIndices.length}getIndex(t,n){var s;let r=[];for(let[u,d]of this.negIndices.entries())d<=t&&r.push(-u-1);for(let[u,d]of this.posIndices.entries())d<=t&&r.push(u);this.uncompressed&&(r.push(this.nextNeg()),r.push(this.nextPos()));let i=n===void 0?0:n,o=this.negIndices.length<this.posIndices.length-1?this.nextNeg():this.nextPos(),a=(s=nt(r,u=>[Math.abs(i-u),Math.abs(u),-u]))!=null?s:o;return this.setIndex(a,t),a}setIndex(t,n){t<0?this.negIndices[-t-1]=n:this.posIndices[t]=n}offset(){return this.negIndices.length}};function Ii(e,t){return t?new Nn(!e):new yn(!e)}function Ci(e,t){for(let r of e){r.ux===void 0&&(r.x=t.getIndex(r.y));for(let i of[...me(r)].sort((o,a)=>a.y-o.y))i.ux===void 0&&(i.x=t.getIndex(r.y,r.x),t.setIndex(i.x,i.y))}let n=t.offset();for(let r of e)r.x+=n}function Ti(e,t){let n=new Map;for(let i of e)for(let o of me(i)){let a=n.get(o);(a===void 0||i.y<a.y)&&n.set(o,i)}for(let i of q(e,e.length-1,-1,-1)){if(i.ux===void 0){let a=Se(A(me(i),s=>s.x));i.x=t.getIndex(e.length-i.y,a)}let o=n.get(i);o!==void 0&&(o.ux===void 0&&(o.x=i.x),t.setIndex(i.x,e.length-o.y))}let r=t.offset();for(let i of e)i.x+=r}function vt(e,t,n){function r(s){for(let d of s)d.ux=void 0;let u=Ii(t,n);e?Ci(s,u):Ti(s,u)}function i(s){return s===void 0?e:vt(s,t,n)}r.topDown=i;function o(s){return s===void 0?t:vt(e,s,n)}r.compressed=o;function a(s){return s===void 0?n:vt(e,t,s)}return r.bidirectional=a,r.d3dagBuiltin=!0,r}function Lt(...e){if(e.length)throw D`got arguments to laneGreedy(${e}); you probably forgot to construct laneGreedy before passing to lane: \`grid().lane(laneGreedy())\``;return vt(!0,!0,!1)}function Ae(e,t){function n(u){let d;if(!u.nnodes())d={width:0,height:0};else{let l=u.topological(e.rank);for(let[b,y]of l.entries())y.y=b;e.lane(l);let f=cr(l,e.lane),{xgap:p,ygap:m}=t,g,c;if(typeof e.nodeSize=="function"){let b=Array(f).fill(0);c=-m;for(let y of l){let[h,N]=e.nodeSize(y);if(h<=0||N<=0)throw D`nodeSize must be positive, but got: [${h}, ${N}]`;b[y.x]=Math.max(b[y.x],h),c+=m,y.y=c+N/2,c+=N}g=-p;for(let[y,h]of b.entries())g+=p,b[y]=g+h/2,g+=h;for(let y of l)y.x=b[y.x]}else{let[b,y]=e.nodeSize;for(let h of l)h.x=(h.x+.5)*b+h.x*p,h.y=(h.y+.5)*y+h.y*m;g=f*(b+p)-p,c=l.length*(y+m)-m}for(let b of u.links()){let{source:y,target:h,points:N}=b;N.splice(0),y.x===h.x?N.push([y.x,y.y],[h.x,h.y]):(N.push([y.x,y.y]),y.y<h.y?N.push([h.x,y.y]):N.push([y.x,h.y]),N.push([h.x,h.y]))}d={width:g,height:c}}for(let l of e.tweaks)d=l(u,d);return d}function r(u){if(u===void 0)return e.lane;{let d=e,{lane:l}=d,f=V(d,["lane"]);return Ae(R(T({},f),{lane:u}),t)}}n.lane=r;function i(u){if(u===void 0)return e.rank;{let d=e,{rank:l}=d,f=V(d,["rank"]);return Ae(R(T({},f),{rank:u}),t)}}n.rank=i;function o(u){if(u===void 0)return e.tweaks;{let d=e,{tweaks:l}=d,f=V(d,["tweaks"]);return Ae(R(T({},f),{tweaks:u}),t)}}n.tweaks=o;function a(u){if(u===void 0)return e.nodeSize;if(typeof u!="function"&&(u[0]<=0||u[1]<=0)){let[l,f]=u;throw D`constant nodeSize must be positive, but got: [${l}, ${f}]`}else{let d=e,{nodeSize:l}=d,f=V(d,["nodeSize"]);return Ae(R(T({},f),{nodeSize:u}),t)}}n.nodeSize=a;function s(u){if(u!==void 0){let[d,l]=u;if(d<0||l<0)throw D`gaps must be non-negative, but got [${d}, ${l}]`;return Ae(e,{xgap:d,ygap:l})}else{let{xgap:d,ygap:l}=t;return[d,l]}}return n.gap=s,n}function pr(...e){if(e.length)throw D`got arguments to grid(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`grid()(...)\``;return Ae({lane:Lt(),rank:()=>{},nodeSize:[1,1],tweaks:[]},{xgap:1,ygap:1})}var Xr=jn(Yr());function fe(e,t,n,r,i={}){let s=Xr.Solve.call({},{optimize:e,opType:t,constraints:r,variables:n,ints:i}),{feasible:o}=s,a=V(s,["feasible"]);if(!o)throw te`could not find a feasible simplex solution`;return a}function Hi(e){let t=[],n=new Set;for(let r of e){if(!n.has(r)){let i=t.findIndex(a=>a<=r.y),o=i===-1?t.length:i;t[o]=r.y}for(let i of[...me(r)].sort((o,a)=>a.y-o.y))if(!n.has(i)){let o=t.findIndex(s=>s<=r.y),a=o===-1?t.length:o;t[a]=i.y,n.add(i)}}return t.length}function Rt(e){function t(o){var c,b,y;let a={},s={},u={},d=new Map(A(o,(h,N)=>[h,N])),l=e.compressed?Hi(o):Math.max(o.length-1,1);for(let h of o.keys())a[h]={opt:0,[h]:1},s[h]={max:l-1};let f=new Map;for(let[h,N]of o.entries()){let v=f.get(N);if(v!==void 0)for(let[L,k]of o.slice(v+1,h).entries()){let w=L+v+1,S=`${h}-${w}-above`;a[S]={opt:0,[S]:1},s[S]={max:1},u[S]=1;let O=`${S}-span`;a[h][O]=1,a[w][O]=-1,a[S][O]=-l,s[O]={min:1-l,max:-1};for(let I of me(k)){if(I===N)continue;let z=d.get(I),M=`${S}-${z}-cross`;a[M]={opt:1,[M]:1},s[M]={max:1},u[M]=1;let $=`${M}-left`;a[h][$]=-1,a[z][$]=1,a[S][$]=l,a[M][$]=-l,s[$]={max:l};let _=`${M}-right`;a[h][_]=-1,a[z][_]=1,a[S][_]=l,a[M][_]=l,s[_]={min:0}}}for(let L of me(N))f.has(L)||f.set(L,h)}if(e.dist){let h=o.reduce((N,v)=>N+me(v).size,0);for(let[N,v]of o.entries())for(let L of me(v)){let k=d.get(L),w=`${N}-${k}-dist`;a[w]={opt:1/h};let S=`${w}-upper`;a[N][S]=1,a[k][S]=-1,a[w][S]=-l,s[S]={max:0};let O=`${w}-lower`;a[N][O]=1,a[k][O]=-1,a[w][O]=l,s[O]={min:0}}}let p=Object.keys(a).length,m=Object.keys(s).length;if(e.check!=="oom"&&p>2e3)throw D`size of dag to decrossOpt is too large and will likely crash instead of complete; you probably want to use a cheaper decrossing strategy for sugiyama like \`sugiyama().decross(decrossTwoLayer())\`, but if you still want to continue you can suppress this check with \`sugiyama().decross(decrossOp().check("oom"))\``;if(e.check==="fast"&&(p>1e3||m>5e3))throw D`size of dag to decrossOpt is too large and will likely not complete; you probably want to use a cheaper decrossing strategy for sugiyama like \`sugiyama().decross(decrossTwoLayer())\`, but if you still want to continue you can suppress this check with \`sugiyama().decross(decrossOp().check("slow"))\``;let g=fe("opt","min",a,s,u);if(e.compressed)for(let[h,N]of o.entries())N.x=(c=g[h])!=null?c:0;else{let h=new Set;for(let v of o.keys())h.add((b=g[v])!=null?b:0);let N=new Map(A([...h].sort(),(v,L)=>[v,L]));for(let[v,L]of o.entries())L.x=N.get((y=g[v])!=null?y:0)}}function n(o){return o===void 0?e.compressed:Rt(R(T({},e),{compressed:o}))}t.compressed=n;function r(o){return o===void 0?e.dist:Rt(R(T({},e),{dist:o}))}t.dist=r;function i(o){return o===void 0?e.check:Rt(R(T({},e),{check:o}))}return t.check=i,t.d3dagBuiltin=!0,t}function eo(...e){if(e.length)throw D`got arguments to laneOpt(${e}); you probably forgot to construct laneOpt before passing to lane: \`grid().lane(laneOpt())\`, note the trailing "()"`;return Rt({compressed:!1,dist:!0,check:"fast"})}function it(e){if(typeof e!="function"){let[t,n]=e;if(t<=0||n<=0)throw D`all node sizes must be positive, but got width ${t} and height ${n}`;return()=>[t,n]}else{let t=new Map;return r=>{let i=t.get(r);if(i===void 0){i=e(r);let[o,a]=i;if(o<=0||a<=0)throw D`all node sizes must be positive, but got width ${o} and height ${a} for node with data: ${r.data}; make sure the callback passed to \`sugiyama().nodeSize(...)\` is doing that`;t.set(r,i)}return i}}}function zt(e){if(typeof e!="function"){let[t,n]=e;return[()=>t,()=>n]}else{let t=e;return[n=>t(n)[0],n=>t(n)[1]]}}var xo=jn(yo());function Bt(e){let t=0,n=0;for(let r of e)n++,t+=(r-t)/n;return n?t:void 0}function No(e){return Se([...e])}function Mn(e){let t=[...e];if(t.sort((n,r)=>n-r),t.length!==0){if(t.length===2)return(t[0]+t[1])/2;if(t.length%2===0){let n=t.length/2,r=t[0],i=t[n-1],o=t[n],a=t[t.length-1],s=i-r,u=a-o;return(i*u+o*s)/(s+u)}else return t[(t.length-1)/2]}}function na(e,t){let n=new Map;for(let l of e){let f=t.get(l);f!==void 0&&Re(n,f,l)}let r=[...n.entries()].sort(([l],[f])=>l-f).flatMap(([,l])=>l),i=new Map(e.map((l,f)=>[l,f])),o=e.filter(l=>t.get(l)===void 0),a=new Array(o.length).fill(null);function s(l,f,p,m){if(f<=l)return;let g=Math.floor((l+f)/2),c=o[g],b=i.get(c),y=0,h=[y];for(let v=p;v<m;++v)y+=i.get(r[v])<b?-1:1,h.push(y);let N=p+h.indexOf(Math.min(...h));a[g]=N,s(l,g,p,N),s(g+1,f,N,m)}s(0,o.length,0,r.length),a.push(r.length+1);let u=0,d=0;for(let[l,f]of r.entries()){for(;a[d]==l;)e[u++]=o[d++];e[u++]=f}for(;a[d]==r.length;)e[u++]=o[d++]}function bo({aggregate:e}){function t(r,i,o){let[a,s]=o?[i,r]:[r,i],u=o?f=>f.parents():f=>f.children(),d=new Map(s.map((f,p)=>[f,p])),l=new Map(a.map(f=>{let p=d.get(f),m=p!=null?p:e(A(u(f),g=>d.get(g)));return[f,m]}));na(a,l)}function n(r){return r===void 0?e:bo({aggregate:r})}return t.aggregator=n,t.d3dagBuiltin=!0,t}function Vt(...e){if(e.length)throw D`got arguments to twolayerAgg(${e}); you probably forgot to construct twolayerAgg before passing to order: \`decrossTwoLayer().order(twolayerAgg())\`, note the trailing "()"`;return bo({aggregate:Mn})}function ra(e,t,n,r,i){if(!t.length)return[];let o=[[0]],a=[0],s=[[0]],u=[0];for(let f of e){let p=[0];p.push(...f),o.push(p)}a.push(...t),s.push(...t.map(()=>[0]));for(let f of n)for(let[p,m]of f.entries())s[p+1].push(-m);u.push(...r.map(f=>-f));let{solution:d,message:l}=(0,xo.solveQP)(o,a,s,u,i);if(l.length)throw te`quadratic program failed: ${l}`;return d.shift(),d}function $t(e,t,n,r,i=0){t.pop(),e.pop(),e.forEach(a=>a.pop()),n.forEach(a=>a.pop());let o=ra(e,t,n,r,i);return o.push(0),o}function ko(e){let t=new Map,n=0;for(let r of e)for(let i of r)t.has(i)||t.set(i,n++);return t}function Pt(e,t,n,r=0){let i=1+Math.max(...t.values()),o=Array(i).fill(null).map((d,l)=>Array(i).fill(null).map((f,p)=>l===p?r:0)),a=Array(i).fill(0),s=[],u=[];for(let d of e)for(let[l,f]of Q(d)){let p=t.get(l),m=t.get(f),g=Array(i).fill(0);g[p]=1,g[m]=-1,s.push(g),u.push(-n(l,f))}return[o,a,s,u]}function vo(e,t,n,r){e[n][n]+=r,e[n][t]-=r,e[t][n]-=r,e[t][t]+=r}function _t(e,t,n,r,i,o){let a=i+o;e[r][r]+=o*o,e[r][n]-=o*a,e[r][t]+=o*i,e[n][r]-=a*o,e[n][n]+=a*a,e[n][t]-=a*i,e[t][r]+=i*o,e[t][n]-=i*a,e[t][t]+=i*i}function Wt(e,t,n,r){for(let[a,s]of n)a.x=r[s];let i=1/0,o=-1/0;for(let a of e){let s=a[0],u=a[a.length-1];i=Math.min(i,s.x-t(void 0,s)),o=Math.max(o,u.x+t(u,void 0))}for(let a of n.keys())a.x-=i;return o-i}function Ge(e){return Bt(Ne(e,t=>A(t.children(),n=>n.y-t.y)))}function Lo([e,t,n]){if(e<=0||t<=0||n<=0)throw D`simplex weights must be positive, but got: ${e}, ${t}, ${n}`}function oa(e,t){if(typeof t!="function"){let[n,r,i]=t;return(o,a)=>{switch(+(o.data.role==="node")+ +(a.data.role==="node")){case 0:return i;case 1:return r;case 2:return n;default:throw te`invalid count`}}}else{let n=new Map;for(let r of Ne(e,i=>i))if(r.data.role==="node"){let i=r.data.node,o=new Map;for(let a of i.childLinks()){let{target:s}=a,u=t(a);Lo(u),o.set(s,u)}n.set(i,o)}return(r,i)=>{if(r.data.role==="link"){let{source:o,target:a}=r.data.link,[,s,u]=n.get(o).get(a);return i.data.role==="link"?u:s}else if(i.data.role==="link"){let{source:o,target:a}=i.data.link,[,s]=n.get(o).get(a);return s}else{let[o]=n.get(r.data.node).get(i.data.node);return o}}}}function wo(e){function t(r,i){var b;let o={},a={},s=oa(r,e.weight),u=new Map,d=0;for(let y of r)for(let h of y)if(!u.has(h)){let N=`${d++}`;u.set(h,N),o[N]={}}function l(y){return u.get(y)}for(let y of r)for(let[h,N]of Q(y)){let v=l(h),L=l(N),k=`layer ${v} -> ${L}`,w=i(h,N);a[k]={min:w},o[v][k]=-1,o[L][k]=1}let f=Ge(u.keys());for(let y of u.keys()){let h=l(y);for(let N of y.children()){let v=l(N),L=`link ${h} -> ${v}`,k=`${L} parent`;a[k]={min:0};let w=`${L} child`;a[w]={min:0},o[h][k]=1,o[h][w]=-1,o[v][k]=-1,o[v][w]=1;let S=s(y,N),O=(N.y-y.y)/f;o[L]={opt:S/O,[k]:1,[w]:1}}}let p=fe("opt","min",o,a);for(let[y,h]of u)y.x=(b=p[h])!=null?b:0;let m=0,g=0;for(let y of r){let h=y[0];m=Math.min(m,h.x-i(void 0,h));let N=y[y.length-1];g=Math.max(g,N.x+i(N,void 0))}for(let y of u.keys())y.x-=m;let c=g-m;if(c<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;return c}function n(r){if(r===void 0)return e.weight;{typeof r!="function"&&Lo(r);let i=e,{weight:o}=i,a=V(i,["weight"]);return wo(R(T({},a),{weight:r}))}}return t.weight=n,t.d3dagBuiltin=!0,t}function At(...e){if(e.length)throw D`got arguments to coordSimplex(${e}); you probably forgot to construct coordSimplex before passing to coord: \`sugiyama().coord(coordSimplex())\`, note the trailing "()"`;return wo({weight:[1,2,8]})}function Do(e,t){let n=new Map,r=new Map(e.map((o,a)=>[o,a]));function i(o,a){var u;let s=(u=n.get(o))==null?void 0:u.get(a);if(s!==void 0)return s;if(r.has(o)||r.has(a))return-1/0;{let d=0;for(let[p,m]of t(o)){let g=r.get(p);for(let[c,b]of t(a)){let y=r.get(c);d+=Math.sign(g-y)*m*b}}let l=n.get(o);l===void 0?n.set(o,new Map([[a,d]])):l.set(a,d);let f=n.get(a);return f===void 0?n.set(a,new Map([[o,-d]])):f.set(o,-d),d}}return i}function ia(e,t){let n=[[0,e.length]],r;for(;r=n.pop();){let[i,o]=r;if(i>=o)continue;let a=0,s=o;for(let u=i;u<o-1;++u){let d=t(e[u],e[u+1]);d>a&&(a=d,s=u)}if(s!==o){let u=e[s+1];e[s+1]=e[s],e[s]=u,n.push([i,s],[s+2,o])}}}function aa(e,t){let n=Array(e.length*(e.length-1)/2);for(;;){let r=0;for(let d=1;d<e.length;++d){let l=0,f=r;for(let p=d-1;p>=0;--p)n[f]=l,l+=t(e[p],e[d]),f-=e.length-p-1;r+=e.length-d}let i=0,o=0,a=0,s=0;for(let d=0;d<e.length-1;++d){let l=0;for(let f=d+1;f<e.length;++f){l+=t(e[d],e[f]);let p=n[i++]+l;p>o&&(o=p,a=d,s=f)}}if(o===0)break;let u=e[s];e[s]=e[a],e[a]=u}}function Rn({baseOp:e,doScan:t}){function n(o,a,s){e(o,a,s);let u=s?a:o,d=s?Do(o,l=>l.parentCounts()):Do(a,l=>l.childCounts());t?aa(u,d):ia(u,d)}function r(o){return o===void 0?e:Rn({baseOp:o,doScan:t})}n.base=r;function i(o){return o===void 0?t:Rn({baseOp:e,doScan:o})}return n.scan=i,n.d3dagBuiltin=!0,n}function Ut(...e){if(e.length)throw D`got arguments to twolayerGreedy(${e}); you probably forgot to construct twolayerGreedy before passing to order: \`decrossTwoLayer().order(twolayerGreedy())\`, note the trailing "()"`;return Rn({baseOp:()=>{},doScan:!1})}function Et(e,t){function n(r,i){let o=r?e(r):0,a=i?e(i):0,s=(o+a)/2;return r&&i?s+t:s}return n}function jt(e){let t=0;for(let[n,r]of Q(e)){let i=new Map(r.map((o,a)=>[o,a]));for(let[o,a]of n.entries())for(let s of n.slice(o+1))for(let[u,d]of a.childCounts())for(let[l,f]of s.childCounts())u!==l&&i.get(u)>i.get(l)&&(t+=d*f)}return t}function So(e){function t(r){let i;e.topDown?i=Oe(o=>[...o.children()].sort((a,s)=>s.nchildren()-a.nchildren()),...Ne(r,o=>[...be(o,a=>!a.nparents())].sort((a,s)=>s.nchildren()-a.nchildren()))):i=Oe(o=>[...o.parents()].sort((a,s)=>s.nparents()-a.nparents()),...Ne(q(r,r.length-1,-1,-1),o=>[...be(o,a=>!a.nchildren())].sort((a,s)=>s.nparents()-a.nparents())));for(let o of r)o.splice(0);for(let o of i){let{data:a}=o;if(a.role==="node")for(let s=a.topLayer;s<=a.bottomLayer;++s)r[s].push(o);else r[a.layer].push(o)}}function n(r){return r===void 0?e.topDown:So({topDown:r})}return t.topDown=n,t.d3dagBuiltin=!0,t}function st(...e){if(e.length)throw D`got arguments to decrossDfs(${e}); you probably forgot to construct decrossDfs before passing to decross: \`sugiyama().decross(decrossDfs())\`, note the trailing "()"`;return So({topDown:!0})}function qt(e){function t(o){let a=o.slice().reverse(),s=o.map(l=>l.slice()),u=jt(s),d=e.inits.length?e.inits:[()=>{}];for(let l of d){l(o);let f=!0;for(let p=0;p<e.passes&&f;++p){f=!1;for(let[c,b]of Q(o)){let y=b.slice();e.order(c,b,!0),b.some((h,N)=>y[N]!==h)&&(f=!0)}let m=jt(o);m<u&&(u=m,s=o.map(c=>c.slice()));for(let[c,b]of Q(a)){let y=b.slice();e.order(b,c,!1),b.some((h,N)=>y[N]!==h)&&(f=!0)}let g=jt(o);g<u&&(u=g,s=o.map(c=>c.slice()))}}o.splice(0,o.length,...s)}function n(o){if(o===void 0)return e.order;{let a=e,{order:s}=a,u=V(a,["order"]);return qt(R(T({},u),{order:o}))}}t.order=n;function r(o){if(o===void 0)return[...e.inits];{let a=e,{inits:s}=a,u=V(a,["inits"]);return qt(R(T({},u),{inits:o}))}}t.inits=r;function i(o){if(o===void 0)return e.passes;if(o<=0)throw D`number of passes must be positive`;return qt(R(T({},e),{passes:o}))}return t.passes=i,t.d3dagBuiltin=!0,t}function Ht(...e){if(e.length)throw D`got arguments to decrossTwoLayer(${e}); you probably forgot to construct decrossTwoLayer before passing to decross: \`sugiyama().decross(decrossTwoLayer())\`, note the trailing "()"`;return qt({order:Ut().base(Vt()),inits:[st().topDown(!0),st().topDown(!1)],passes:24})}function Ft(e,t){return+!!(e&&t)}function zn(e){function t(i,o){var y;let a={},s={},u=new Map(A(i.nodes(),(h,N)=>[h,N.toString()]));function d(h){return u.get(h)}function l(h){return a[d(h)]}function f(h,N,v,L,k=0){let w=l(N),S=l(v),O=`${h}: ${d(N)} -> ${d(v)}`;s[O]={min:L},w[O]=-1,S[O]=1,w.opt+=k,S.opt-=k}function p(h,N,v){f(`${h} before`,N,v,0),f(`${h} after`,v,N,0)}let m=[],g=new Map;for(let h of i.nodes()){let N=d(h);a[N]={opt:0};let v=e.rank(h);v!==void 0&&m.push([v,h]);let L=e.group(h);if(L!==void 0){let k=g.get(L);k?k.push(h):g.set(L,[h])}}let c=new Set;for(let h of i.topological(e.rank)){for(let[N,v]of h.childCounts())c.has(N)?f("link",N,h,o(N,h),v):f("link",h,N,o(h,N),v);c.add(h)}let b=m.sort(([h],[N])=>h-N);for(let[[h,N],[v,L]]of Q(b))h<v?f("rank",N,L,o(N,L)):p("rank",N,L);for(let h of g.values())for(let[N,v]of Q(h))p("group",N,v);try{let h=fe("opt","max",a,s,{}),N=0,v=0;for(let L of i.nodes()){let k=(y=h[d(L)])!=null?y:0;L.y=k,N=Math.min(N,k-o(void 0,L)),v=Math.max(v,k+o(L,void 0))}for(let L of i.nodes())L.y-=N;return v-N}catch(h){throw g.size?D`could not find a feasible simplex layout; this is likely due to group constraints producing an infeasible layout, try relaxing the functions you're passing to \`layeringSimplex().group(...)\``:te`could not find a feasible simplex solution`}}function n(i){if(i===void 0)return e.rank;{let o=e,{rank:a}=o,s=V(o,["rank"]);return zn(R(T({},s),{rank:i}))}}t.rank=n;function r(i){if(i===void 0)return e.group;{let o=e,{group:a}=o,s=V(o,["group"]);return zn(R(T({},s),{group:i}))}}return t.group=r,t.d3dagBuiltin=!0,t}function Oo(){}function Zt(...e){if(e.length)throw D`got arguments to layeringSimplex(${e}); you probably forgot to construct layeringSimplex before passing to layering: \`sugiyama().layering(layeringSimplex())\`, note the trailing "()"`;return zn({rank:Oo,group:Oo})}function Io(e,t,n,r){for(let[o,[a,s]]of t){let u=a.bottomLayer;for(let d of o.childLinks()){let[l,f]=t.get(d.target),p=l.topLayer;if(p>u){let m=s;for(let g=u+1;g<p;++g){let c=e.node({link:d,layer:g,role:"link"});m.child(c,void 0),m=c}m.child(f)}else if(p<u){let m=f;for(let g=p+1;g<u;++g){let c=e.node({link:d,layer:g,role:"link"});m.child(c,void 0),m=c}m.child(s)}else throw oe`layering ${r} assigned nodes with an edge to the same layer`}}let i=Array(n).fill(null).map(()=>[]);for(let o of e.nodes()){let{data:a}=o;if(a.role==="node"){let{topLayer:s,bottomLayer:u}=a;for(let d=s;d<=u;++d)i[d].push(o)}else{let{layer:s}=a;i[s].push(o)}}for(let o of i)if(!o.length)throw oe`layering ${r} didn't assign a node to every layer`;return i}function Jt(e,t,n,r,i){let o=ie(),a=Array(r).fill(!1),s=new Map;for(let p of e.nodes()){let m=p.uy;if(m===void 0)throw oe`layering ${i} didn't assign a layer to a node`;if(m<0||m>=r)throw oe`layering ${i} assigned node an invalid layer: ${m}`;{let g=ue(p.parentCounts(),p.childCounts());!a[m]&&un(g,([{uy:b},y])=>y>1&&b===m-1)&&(a[m]=!0);let c={node:p,topLayer:m,bottomLayer:m,role:"node"};s.set(p,[c,o.node(c)])}}let u=0,d=a.map(p=>u+=+p);for(let[p]of s.values()){let m=d[p.topLayer];p.topLayer+=m,p.bottomLayer+=m}let l=Io(o,s,r+u,i),f=-n;for(let p of l){f+=n;let m=Math.max(-n,...A(p,({data:c})=>c.role==="node"?t(c.node):-1/0)),g=f+m/2;for(let c of p)c.y=g;f+=m}return[l,f]}function Co(e,t,n,r){let i=ie(),o=[0,n],a=new Map;for(let b of e.nodes()){let y=b.uy;if(y===void 0)throw oe`layering ${r} didn't assign a y coordinate to every node`;{let h=t(b)/2,N=y-h,v=y+h,L={node:b,topLayer:N,bottomLayer:v,role:"node"};a.set(b,[L,i.node(L)]),o.push(N,v)}}o.sort((b,y)=>b-y);let s=n/a.size*.001,u=[],d=new Map,l=0,f=0;for(let b of o)b>l+s&&(u.push(l),l=b,f++),d.set(b,f);u.push(l);let p=Array(u.length).fill(!1);for(let[b,[{topLayer:y}]]of a){let h=d.get(y),N=h-1;for(let[v,L]of ue(b.childCounts(),b.parentCounts()))if(L>1){let[{bottomLayer:k}]=a.get(v);if(d.get(k)===N){p[h]||(p[h]=!0,u.push((y+k)/2));break}}}u.sort((b,y)=>b-y);let m=0,g=p.map(b=>m+=+b);for(let[b,y]of d)d.set(b,y+g[y]);for(let[b]of a.values())b.topLayer=d.get(b.topLayer),b.bottomLayer=d.get(b.bottomLayer);let c=Io(i,a,u.length,r);for(let b of c)for(let y of b)y.data.role==="node"?y.y=y.data.node.y:y.y=u[y.data.layer];return c}function Qt(e){for(let t of e)for(let n of t)if(n.data.role==="node"){let{node:r}=n.data;r.x=n.x,r.y=n.y;for(let i of n.children()){let o=[[n.x,n.y]],a;for(;i.data.role==="link";)a=i.data.link,o.push([i.x,i.y]),[i]=i.children();o.push([i.x,i.y]);let s=i.data.node,u=ue(r.childLinksTo(s),r.parentLinksTo(s));a||([a]=u),a.source!==r&&o.reverse(),a.points.splice(0,a.points.length,...o)}}}function Kt(e,t=0){return({data:n})=>n.role==="node"?e(n.node):t}function To(e,t,n,r,i=.001){for(let o of e){for(let a of o)if(a.ux===void 0)throw oe`coord ${r} didn't assign an x to every node`;for(let[[a,s],[u,d]]of Q(ue([[void 0,0]],A(o,l=>[l,l.x]),[[void 0,n]])))if(d-s<t(a,u)-i)throw oe`coord ${r} assigned nodes too close for separation`}}function Me(e,t){function n(d){let l;if(!d.nnodes())l={width:0,height:0};else{let[f,p]=zt(it(e.nodeSize)),[m,g]=t.gap,c=e.layering(d,Ft)+1,[b,y]=Jt(d,p,g,c,e.layering);e.decross(b);let h=Et(Kt(f),m),N=e.coord(b,h);To(b,h,N,e.coord),Qt(b),l={width:N,height:y}}for(let f of e.tweaks)l=f(d,l);return l}function r(d){if(d===void 0)return e.layering;{let l=e,{layering:f}=l,p=V(l,["layering"]);return Me(R(T({},p),{layering:d}),t)}}n.layering=r;function i(d){if(d===void 0)return e.decross;{let l=e,{decross:f}=l,p=V(l,["decross"]);return Me(R(T({},p),{decross:d}),t)}}n.decross=i;function o(d){if(d===void 0)return e.coord;{let l=e,{coord:f}=l,p=V(l,["coord"]);return Me(R(T({},p),{coord:d}),t)}}n.coord=o;function a(d){if(d===void 0)return e.tweaks;{let l=e,{tweaks:f}=l,p=V(l,["tweaks"]);return Me(R(T({},p),{tweaks:d}),t)}}n.tweaks=a;function s(d){if(d===void 0)return e.nodeSize;if(typeof d!="function"&&(d[0]<=0||d[1]<=0)){let[f,p]=d;throw D`constant nodeSize must be positive, but got: [${f}, ${p}]`}else{let l=e,{nodeSize:f}=l,p=V(l,["nodeSize"]);return Me(R(T({},p),{nodeSize:d}),t)}}n.nodeSize=s;function u(d){if(d!==void 0){let[l,f]=d;if(l<0||f<0)throw D`gap width (${l}) and height (${f}) must be non-negative`;return Me(e,R(T({},t),{gap:d}))}else{let[l,f]=t.gap;return[l,f]}}return n.gap=u,n}function Go(...e){if(e.length)throw D`got arguments to sugiyama(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`sugiyama()(...)\``;return Me({layering:Zt(),decross:Ht(),coord:At(),nodeSize:[1,1],tweaks:[]},{gap:[1,1]})}function Mo(...e){if(e.length)throw D`got arguments to coordCenter(${e}); you probably forgot to construct coordCenter before passing to coord: \`sugiyama().coord(coordCenter())\`, note the trailing "()"`;function t(n,r){let i=n.map(a=>{let s=0,u;for(let d of a)s+=r(u,d),d.x=s,u=d;return s+=r(u,void 0),s}),o=Math.max(...i);if(o<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;for(let[a,s]of n.entries()){let u=i[a],d=(o-u)/2;for(let l of s)l.x+=d}return o}return t.d3dagBuiltin=!0,t}function Ro(e,t){for(let n of e){let r=Se([...A(t(n),({x:i})=>i)]);r!==void 0&&(n.x=r)}}function zo(e,t){for(let n of e){let[r]=t(n);n.data.role==="link"&&r.data.role==="link"&&(n.x=r.x)}}function ut(e,t){let n=e[e.length-1],r=n.x,i=[r];for(let o of q(e,e.length-2,-1,-1)){let a=Math.min(o.x,r-t(n,o));i.push(a),n=o,r=a}i.reverse(),n=e[0],r=n.x,n.x=(r+i[0])/2;for(let[o,a]of K(q(e,1))){let s=Math.max(a.x,r+t(n,a));a.x=(s+i[o+1])/2,n=a,r=s}}function sa(e,t){for(let[n,r]of e.entries()){let i=t[n];for(let[o,{x:a}]of r.entries())if(i[o]!==a)return!1}return!0}function Bo(...e){if(e.length)throw D`got arguments to coordGreedy(${e}); you probably forgot to construct coordGreedy before passing to coord: \`sugiyama().coord(coordGreedy())\`, note the trailing "()"`;function t(n,r){let i=0,o=0,a=new Set;for(let l of n)for(let f of l)a.has(f)||(a.add(f),f.ux!==void 0&&(i+=(f.ux-i)/++o));for(let l of n){let f=0,p=0;for(let g of l)g.ux!==void 0&&(f+=(g.ux-f)/++p);let m=p?f:i;for(let g of l)g.ux===void 0&&(g.ux=m);ut(l,r)}for(let l of q(n,1))Ro(l,f=>f.parents()),ut(l,r);for(let l of q(n,n.length-2,-1,-1))Ro(l,f=>f.children()),ut(l,r);for(let l=0;l<n.length;++l){let f=n.map(p=>p.map(({x:m})=>m));for(let p of q(n,1))zo(p,m=>m.parents()),ut(p,r);for(let p of q(n,n.length-2,-1,-1))zo(p,m=>m.children()),ut(p,r);if(sa(n,f))break}let s=1/0,u=-1/0;for(let l of n){let f=l[0];s=Math.min(s,f.x-r(void 0,f));let p=l[l.length-1];u=Math.max(u,p.x+r(p,void 0))}for(let l of a)l.x-=s;let d=u-s;if(d<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;return d}return t.d3dagBuiltin=!0,t}function ua(e,t){if(typeof e!="function")return()=>e;{let n=new Map;for(let r of Ne(t,i=>i))if(r.data.role==="node"){let i=r.data.node,o=new Map;for(let a of i.childLinks()){let s=e(a);if(s<0)throw D`link weights must be non-negative; double check the accessor passed into \`coordQuad().vertWeak(...)\``;o.set(a.target,s)}n.set(i,o)}return(r,i)=>n.get(r).get(i)}}function Bn(e,t,n){if(typeof e!="function")return()=>e;{let r=new Map;return i=>{let o=r.get(i);if(o===void 0){let a=e(i);if(a<0)throw new Error(`${t} weights must be non-negative; double check the accessor passed into \`coordQuad().${n}(...)\``);return r.set(i,a),a}else return o}}}function Ee(e){function t(s,u){let d=ko(s),[l,f,p,m]=Pt(s,d,u,e.comp),g=ua(e.vertWeak,s),c=Bn(e.vertStrong,"link","vertStrong"),b=Bn(e.linkCurve,"link","linkCurve"),y=Bn(e.nodeCurve,"node","nodeCurve"),h=Ge(d.keys());for(let[v,L]of d){let k=v.data,w=k.role==="node"?k.node:k.link.source;for(let S of v.children()){let O=d.get(S),I=S.data,z=I.role==="node"?I.node:I.link.target,M=k.role==="node"?g(w,z):c(k.link),$=I.role==="node"?g(w,z):c(I.link),_=I.role==="node"?y(I.node):b(I.link),W=(S.y-v.y)/h;vo(l,L,O,(M+$)/W);for(let B of S.children()){let Z=d.get(B),E=(B.y-S.y)/h;_t(l,L,O,Z,_/W,_/E)}}}let N;try{let v=$t(l,f,p,m);N=Wt(s,u,d,v)}catch(v){throw typeof v=="string"?te`${v}`:te`undefined quadprog exception`}if(N<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;return N}function n(s){if(s===void 0)return e.vertWeak;if(typeof s=="number"&&s<0)throw D`vertWeak must be non-negative but was: ${s}`;{let u=e,{vertWeak:d}=u,l=V(u,["vertWeak"]);return Ee(R(T({},l),{vertWeak:s}))}}t.vertWeak=n;function r(s){if(s===void 0)return e.vertStrong;if(typeof s=="number"&&s<0)throw D`vertStrong must be non-negative but was: ${s}`;{let u=e,{vertStrong:d}=u,l=V(u,["vertStrong"]);return Ee(R(T({},l),{vertStrong:s}))}}t.vertStrong=r;function i(s){if(s===void 0)return e.linkCurve;if(typeof s=="number"&&s<0)throw D`linkCurve must be non-negative but was: ${s}`;{let u=e,{linkCurve:d}=u,l=V(u,["linkCurve"]);return Ee(R(T({},l),{linkCurve:s}))}}t.linkCurve=i;function o(s){if(s===void 0)return e.nodeCurve;if(typeof s=="number"&&s<0)throw D`nodeCurve must be non-negative but was: ${s}`;{let u=e,{nodeCurve:d}=u,l=V(u,["nodeCurve"]);return Ee(R(T({},l),{nodeCurve:s}))}}t.nodeCurve=o;function a(s){if(s===void 0)return e.comp;if(s<=0)throw D`compress weight must be positive, but was: ${s}`;return Ee(R(T({},e),{comp:s}))}return t.compress=a,t.d3dagBuiltin=!0,t}function Vo(...e){if(e.length)throw D`got arguments to coordQuad(${e}); you probably forgot to construct coordQuad before passing to coord: \`sugiyama().coord(coordQuad())\`, note the trailing "()"`;return Ee({vertWeak:1,vertStrong:0,linkCurve:1,nodeCurve:0,comp:1e-6})}function $o(e){function t(r,i){for(let o of r)if(o.reduce((s,u)=>s+ +(u.data.role==="node"),0)>1)throw D`topological() only works with a topological layering, make sure you've set up sugiyama as \`sugiyama().layering(layeringTopological())\``;if(e.simp){let o={center:{}},a={},s=new Map,u=0;for(let c of r){let b=!0;for(let y of c)if(y.data.role==="link"){let h=`${u++}`;s.set(y,[h,b]),o[h]={}}else s.set(y,["center",!1]),b=!1}let d=c=>s.get(c);for(let c of r)for(let[b,y]of Q(c)){let[h,N]=d(b),[v,L]=d(y),k=`layer ${h} -> ${v}`,w=i(b,y);a[k]={min:w},o[h][k]=N?1:-1,o[v][k]=L?-1:1}let l=Ge(s.keys());for(let c of r)for(let b of c){let[y,h]=d(b);if(y!=="center")for(let N of b.children()){let[v,L]=d(N);if(v!=="center"){let k=`link ${y} -> ${v}`,w=`${k} parent`;a[w]={min:0};let S=`${k} child`;a[S]={min:0},o[y][w]=h?-1:1,o[y][S]=h?1:-1,o[v][w]=L?1:-1,o[v][S]=L?-1:1;let O=(N.y-b.y)/l;o[k]={opt:1/O,[w]:1,[S]:1}}}}delete o.center;let f=fe("opt","min",o,a);for(let[c,[b,y]]of s){let h=f[b];c.x=h===void 0?0:y?-h:h}let p=0,m=0;for(let c of r){let b=c[0];p=Math.min(p,b.x-i(void 0,b));let y=c[c.length-1];m=Math.max(m,y.x+i(y,void 0))}for(let c of s.keys())c.x-=p;let g=m-p;if(g<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;return g}else{let o=new Map,a=0;for(let g of r)for(let c of g)c.data.role==="link"&&o.set(c,a++);for(let g of r)for(let c of g)c.data.role==="node"&&o.set(c,a);let[s,u,d,l]=Pt(r,o,i),f=Ge(o.keys());for(let g of o.keys()){let c=o.get(g);for(let b of g.children()){let y=o.get(b),h=(b.y-g.y)/f;if(b.data.role==="link")for(let N of b.children()){let v=o.get(N),L=(N.y-b.y)/f;_t(s,c,y,v,1/h,1/L)}}}let p=$t(s,u,d,l),m=Wt(r,i,o,p);if(m<=0)throw D`must assign nonzero width to at least one node; double check the callback passed to \`sugiyama().nodeSize(...)\``;return m}}function n(r){return r===void 0?e.simp:$o(R(T({},e),{simp:r}))}return t.straight=n,t.d3dagBuiltin=!0,t}function Po(...e){if(e.length)throw D`got arguments to coordTopological(${e}); you probably forgot to construct coordTopological before passing to coord: \`sugiyama().coord(coordTopological())\`, note the trailing "()"`;return $o({simp:!0})}function da(e){var s,u;let t=[],n=new Map,r=new Map;for(let d of e){let[l]=d;l!==t[t.length-1]&&t.push(l);for(let f of q(d,1)){let p=(s=r.get(f))!=null?s:0;r.set(f,p+1)}for(let[f,p]of Q(d))Re(n,f,p)}let i=new Map,o=0,a;for(;a=t.pop();){i.set(a,o++);for(let d of(u=n.get(a))!=null?u:[]){let l=r.get(d)-1;r.set(d,l),l||t.push(d)}}return i}function Vn(e){function t(i){var L;let o=i.reduce((k,w)=>k+w.length*Math.max(w.length-1,0)/2,0),a=[];if(e.dist)for(let[k,w]of Q(i)){let S=w.filter(M=>!M.nparents()),O=k.map(M=>[...M.children()]);a.push([S,O]);let I=k.filter(M=>!M.nchildren()),z=w.map(M=>[...M.parents()]);a.push([I,z])}let s=da(i),u=new Map;function d(k,w){var O;let S=`${k} => ${w}`;return(O=u.get(S))!=null?O:S}let l=new Map;for(let[k,w]of K(q(i,0,i.length-1)))for(let S of w){if(S.data.role!=="node"||S.data.bottomLayer===k)continue;let O=s.get(S),I=!0;for(let z of w)if(z===S)I=!1;else if(z.data.role!=="node"||z.data.bottomLayer===k){let M=s.get(z),$=I?d(M,O):d(O,M);for(let _ of z.children()){let W=s.get(_),B=I?d(W,O):d(O,W);l.set(B,$)}}}let f=new Map;for(let[k,w]of l){let S=w,O;for(;O=l.get(S);)S=O;let I=f.get(S);I?I.push(k):f.set(S,[S,k])}for(let k of f.values()){let w=`{ ${k.join(" & ")} }`;for(let S of k)u.set(S,w)}let m=1/(a.reduce((k,[w,S])=>S.reduce((O,I)=>O+I.length*I.length,0)*w.length,0)/4+1),g=m/(o+1),c={},b={},y={};for(let k of i){for(let[w,S]of k.entries()){let O=s.get(S);for(let I of q(k,w+1)){let z=s.get(I),M=d(O,z);y[M]=1,b[M]={max:1},c[M]={opt:g,[M]:1}}}for(let[w,S]of k.entries()){let O=s.get(S);for(let[I,z]of K(q(k,w+1))){let M=s.get(z);for(let $ of k.slice(w+I+2)){let _=s.get($),W=d(O,M),B=d(O,_),Z=d(M,_),E=`tri: ${O} - ${M} - ${_}`,j=`${E} +`,U=`${E} -`;b[j]={max:1},c[W][j]=1,c[B][j]=-1,c[Z][j]=1,b[U]={min:0},c[W][U]=1,c[B][U]=-1,c[Z][U]=1}}}}for(let[k,w]of K(q(i,0,i.length-1)))for(let[S,O]of w.entries()){if(O.data.role==="node"&&O.data.bottomLayer!==k)continue;let I=s.get(O);for(let z of q(w,S+1)){if(z.data.role==="node"&&z.data.bottomLayer!==k)continue;let M=s.get(z),$=d(I,M),_=new Map;for(let[W,B]of O.childCounts()){let Z=s.get(W);for(let[E,j]of z.childCounts()){if(W===E)continue;let U=s.get(E),ne=Math.sign(Z-U),ee=ne<0?d(Z,U):d(U,Z),ve=(L=_.get(ee))!=null?L:0;_.set(ee,ne*B*j+ve)}}for(let[W,B]of _){let Z=`slack: ${$} : ${W}`,E=`${Z} +`,j=`${Z} -`;B<0?(c[Z]={opt:-B,[E]:1,[j]:1},b[E]={min:0},c[$][E]=1,c[W][E]=-1,b[j]={min:0},c[$][j]=-1,c[W][j]=1):B>0&&(c[Z]={opt:B,[E]:1,[j]:1},b[E]={min:1},c[$][E]=1,c[W][E]=1,b[j]={min:-1},c[$][j]=-1,c[W][j]=-1)}}}for(let[k,w]of a)for(let S of k){let O=s.get(S);for(let I of w)for(let[z,M]of K(I)){let $=s.get(M);for(let _ of q(I,z+1)){let W=s.get(_),B=`dist: ${$} - ${O} - ${W}`,Z=`${B} :normal`,E=`${B} :reversed`;c[B]={opt:m,[Z]:1,[E]:1};let j=0;for(let[U,ne]of[[$,O],[$,W],[O,W]]){let ee=Math.sign(U-ne),ve=ee<0?d(U,ne):d(ne,U);j+=ee,c[ve][Z]=-ee,c[ve][E]=ee}b[Z]={min:(j+1)/-2},b[E]={min:(j-1)/2}}}}let h=Object.keys(c).length,N=Object.keys(b).length;if(e.check!=="oom"&&h>2e3)throw D`size of dag to decrossOpt is too large and will likely crash instead of complete; you probably want to use a cheaper decrossing strategy for sugiyama like \`sugiyama().decross(decrossTwoLayer())\`, but if you still want to continue you can suppress this check with \`sugiyama().decross(decrossOp().check("oom"))\``;if(e.check==="fast"&&(h>1e3||N>5e3))throw D`size of dag to decrossOpt is too large and will likely not complete; you probably want to use a cheaper decrossing strategy for sugiyama like \`sugiyama().decross(decrossTwoLayer())\`, but if you still want to continue you can suppress this check with \`sugiyama().decross(decrossOp().check("slow"))\``;let v=fe("opt","min",c,b,y);if(!v.bounded)throw te`optimization result was not bounded`;for(let k of i)k.sort((w,S)=>{let O=s.get(w),I=s.get(S);return O<I?v[d(O,I)]||-1:-(v[d(I,O)]||-1)})}function n(i){return i===void 0?e.check:Vn(R(T({},e),{check:i}))}t.check=n;function r(i){return i===void 0?e.dist:Vn(R(T({},e),{dist:i}))}return t.dist=r,t.d3dagBuiltin=!0,t}function _o(...e){if(e.length)throw D`got arguments to decrossOpt(${e}); you probably forgot to construct decrossOpt before passing to decross: \`sugiyama().decross(decrossOpt())\`, note the trailing "()"`;return Vn({check:"fast",dist:!1})}function $n(e,t){function n(o,a){let s=0,u=o.topological(e.rank);for(let d of u)d.uy=void 0;t.topDown&&u.reverse();for(let d of u){let l=Math.max(a(void 0,d),...A(ue(d.parents(),d.children()),f=>{var p;return((p=f.uy)!=null?p:-1/0)+a(f,d)}));s=Math.max(s,l+a(d,void 0)),d.y=l}for(let d of u.reverse()){let l=Math.min(...A(be(ue(d.parents(),d.children()),f=>d.y<f.y),f=>f.y-a(f,d)));l!==1/0&&(d.y=l)}if(t.topDown)for(let d of u)d.y=s-d.y;return s}function r(o){if(o===void 0)return e.rank;{let a=e,{rank:s}=a,u=V(a,["rank"]);return $n(R(T({},u),{rank:o}),t)}}n.rank=r;function i(o){return o===void 0?t.topDown:$n(e,R(T({},t),{topDown:o}))}return n.topDown=i,n.d3dagBuiltin=!0,n}function la(){}function Wo(...e){if(e.length)throw D`got arguments to layeringLongestPath(${e}); you probably forgot to construct layeringLongestPath before passing to layering: \`sugiyama().layering(layeringLongestPath())\`, note the trailing "()"`;return $n({rank:la},{topDown:!0})}function Ao(e){function t(r,i){let o=0,a;for(let s of r.topological(e.rank))o+=i(a,s),s.y=o,a=s;return o+=i(a,void 0),o}function n(r){if(r===void 0)return e.rank;{let i=e,{rank:o}=i,a=V(i,["rank"]);return Ao(R(T({},a),{rank:r}))}}return t.rank=n,t.d3dagBuiltin=!0,t}function fa(){}function Uo(...e){if(e.length)throw D`got arguments to layeringTopological(${e}); you probably forgot to construct layeringTopological before passing to layering: \`sugiyama().layering(layeringTopological())\`, note the trailing "()"`;return Ao({rank:fa})}function ke(e,t){return`${e} => ${t}`}function Eo(e,t,n,r,{dist:i,check:o}){let a=i?e.filter(h=>!Qn(r(h))):[],s=new Map;if(i)for(let h of e)for(let[N]of r(h))Re(s,N,h);let u=Math.max(e.length*(e.length-1)/2,0),l=Zn(s.values(),(h,N)=>h+N.length*N.length,0)*a.length/4,f={},p={},m={},g=1/(l+1),c=g/(u+1);for(let[h,N]of K(q(e,0,e.length-1))){let v=t.get(N);for(let L of q(e,h+1)){let k=t.get(L),w=ke(v,k);m[w]=1,p[w]={max:1},f[w]={opt:c,[w]:1}}}for(let[h,N]of K(q(e,0,e.length-1))){let v=t.get(N);for(let[L,k]of K(q(e,h+1))){let w=t.get(k);for(let S of q(e,h+L+2)){let O=t.get(S),I=ke(v,w),z=ke(v,O),M=ke(w,O),$=`tri: ${v} - ${w} - ${O}`,_=`${$} +`,W=`${$} -`;p[_]={max:1},f[I][_]=1,f[z][_]=-1,f[M][_]=1,p[W]={min:0},f[I][W]=1,f[z][W]=-1,f[M][W]=1}}}for(let[h,N]of K(q(e,0,e.length-1))){let v=t.get(N);for(let L of q(e,h+1)){let k=t.get(L),w=ke(v,k);for(let[S,O]of r(N)){let I=n.get(S);for(let[z,M]of r(L)){if(S===z)continue;let $=n.get(z);f[w].opt+=Math.sign($-I)*O*M}}}}for(let h of a){let N=t.get(h);for(let v of s.values())for(let[L,k]of K(v)){let w=t.get(k);for(let S of q(v,L+1)){let O=t.get(S),I=`dist: ${w} - ${N} - ${O}`,z=`${I} :normal`,M=`${I} :reversed`;f[I]={opt:g,[z]:1,[M]:1};let $=0;for(let[_,W]of[[w,N],[w,O],[N,O]]){let B=_<W?ke(_,W):ke(W,_),Z=Math.sign(_-W);$+=Z,f[B][z]=-Z,f[B][M]=Z}p[z]={min:($+1)/-2},p[M]={min:($-1)/2}}}}let b=Object.keys(f).length,y=Object.keys(p).length;if(o!=="oom"&&b>1200)throw D`size of dag to twolayerOpt is too large and will likely crash instead of complete; you probably want to use a cheaper twolayer strategy for sugiyama like \`decrossTwoLayer(twolayerAgg())\`, but if you still want to continue you can suppress this check with \`decrossTwoLayer().order(twolayerOpt().check("oom"))\``;if(o==="fast"&&(b>400||y>1e3))throw D`size of dag to twolayerOpt is too large and will likely not finish; you probably want to use a cheaper twolayer strategy for sugiyama like \`decrossTwoLayer(twolayerAgg())\`, but if you still want to continue you can suppress this check with \`decrossTwoLayer().order(twolayerOpt().check("slow"))\``;return fe("opt","min",f,p,m)}function Pn(e){function t(i,o,a){let[s,u]=a?[o,i]:[i,o],d=a?c=>c.parentCounts():c=>c.childCounts(),l=new Map(A(s,(c,b)=>[c,b])),f=new Map(A(u,(c,b)=>[c,b])),p={},m=[];for(let c of s)if(f.has(c)){let b=Eo(m,l,f,d,e);Object.assign(p,b),m.length=0}else m.push(c);let g=Eo(m,l,f,d,e);Object.assign(p,g),s.sort((c,b)=>{let y=l.get(c),h=l.get(b);return y<h?p[ke(y,h)]||-1:-(p[ke(h,y)]||-1)})}function n(i){return i===void 0?e.check:Pn(R(T({},e),{check:i}))}t.check=n;function r(i){return i===void 0?e.dist:Pn(R(T({},e),{dist:i}))}return t.dist=r,t.d3dagBuiltin=!0,t}function jo(...e){if(e.length)throw D`got arguments to twolayerOpt(${e}); you probably forgot to construct twolayerOpt before passing to order: \`decrossTwoLayer().order(twolayerOpt())\`, note the trailing "()"`;return Pn({check:"fast",dist:!1})}function qo(e){let{width:t,height:n}=e;function r(i,o){let{width:a,height:s}=o,u=t/a,d=n/s;for(let l of i.nodes())l.x*=u,l.y*=d;for(let l of i.links())for(let f of l.points)f[0]*=u,f[1]*=d;return e}return r}function Ho(e){let[t,n]=e;function r(i,o){for(let a of i.links()){let[s,u,d,l]=a.points;if(l!==void 0)throw D`link points had more than three points: ${a.points.length}; tweakGridPoints can only be applied to grid layouts`;if(d!==void 0){let[f,p]=s,[m,g]=u,[c,b]=d;a.points=[s,[m+t*Math.sign(f-m),g+n*Math.sign(p-g)],u,[m+t*Math.sign(c-m),g+n*Math.sign(b-g)],d]}}return o}return r}function ca(e,t){for(let i of e.nodes()){let o=i.x;i.x=i.y,i.y=o}for(let i of e.links())for(let o of i.points){let[a]=o;o[0]=o[1],o[1]=a}let{width:n,height:r}=t;return{width:r,height:n}}function pa(e,t){let{height:n}=t;for(let r of e.nodes())r.y=n-r.y;for(let r of e.links())for(let i of r.points)i[1]=n-i[1];return t}function ha(e,t){let{width:n}=t;for(let r of e.nodes())r.x=n-r.x;for(let r of e.links())for(let i of r.points)i[0]=n-i[0];return t}function Fo(e="diagonal"){if(e==="diagonal")return ca;if(e==="vertical")return pa;if(e==="horizontal")return ha;throw D`invalid tweakFlip style: ${e}`}function _n(e,t,n,r){let[i,o]=e,[a,s]=t,[u,d]=n,[l,f]=r,p=i-a/2,m=i+a/2,g=o-s/2,c=o+s/2;function b(N,v){let L=0;return N<p?L|=1:N>m&&(L|=2),v<g?L|=4:v>c&&(L|=8),L}let y=b(u,d),h=b(l,f);if(!h)throw D`line from [${u}, ${d}] -> [${l}, ${f}] ended inside rectangle centered at [${i}, ${o}] with size [${a}, ${s}]`;for(;;){if(h){if(y&h)return[u,d];h&8?(l=u+(l-u)*(c-d)/(f-d),f=c):h&4?(l=u+(l-u)*(g-d)/(f-d),f=g):h&2?(f=d+(f-d)*(m-u)/(l-u),l=m):(f=d+(f-d)*(p-u)/(l-u),l=p)}else return[l,f];h=b(l,f)}}function Zo(e,t,n,r){let[i,o]=e,[a,s]=t,[u,d]=n,[l,f]=r,p=a/2,m=s/2,g=l-u,c=u-i,b=f-d,y=d-o,h=p*p,N=m*m,v=h*b*b+N*g*g,L=g*y-b*c,k=v-L*L;if(k>=0){let w=p*m*Math.sqrt(k),S=g*c*N+b*y*h,O=(S+w)/-v,I=(S-w)/-v;if(O<1&&1<I)throw D`line from [${u}, ${d}] -> [${l}, ${f}] ended inside ellipse at [${i}, ${o}] with size [${a}, ${s}]`;return 0<=I&&I<=1?[I*g+u,I*b+d]:[u,d]}else return[u,d]}function Jo(e,t=_n){function n(r,i){for(let o of r.nodes()){let a=[o.x,o.y],s=typeof e=="function"?e(o):e;for(let{points:u}of o.parentLinks()){let[d,l]=u.slice(-2),f=t(a,s,l,d);u.splice(-1,1,f)}for(let{points:u}of o.childLinks()){let[d,l]=u,f=t(a,s,d,l);u.splice(0,1,f)}}return i}return n}function*ma(e){for(let t of e.parentLinks()){let{source:n}=t;n.y<e.y&&(yield[n,e,t])}for(let t of e.childLinks()){let{target:n}=t;n.y<e.y&&(yield[n,e,t])}}function Qo(e,t){let n=e.findIndex(r=>r<t);return n>=0?n:e.length}function Ko(e,t){let n=[];for(let[a,s]of Q(e)){let u=!1;for(let d of ma(s)){let[l]=d;a===l&&!u?u=!0:n.push(d)}}n.sort(([a,s],[u,d])=>s.y-d.y||u.y-a.y);let r=[],i=[],o=new Map;for(let[a,s,u]of n){let d=Qo(i,a.y),l=Qo(r,a.y);d<l?(o.set(u,-d-1),i[d]=s.y-t):(o.set(u,l+1),r[l]=s.y-t)}return o}function ga(e){return typeof e=="function"?e:()=>e}function dt(e,t){function n(s){var d;let u;if(!s.nnodes())u={width:0,height:0};else{let{xgap:l,ygap:f}=t,p=ga(e.nodeSize),m=[...s.topological(e.rank)],g=-f,c=0;for(let k of m){let[w,S]=p(k);if(w<=0||S<=0)throw D`constant nodeSize must be positive, but got: [${w}, ${S}]`;c=Math.max(c,w),g+=f,k.y=g+S/2,g+=S}let b=g,y=Math.min(...A(Q(m),([k,w])=>(w.y-k.y)/(k.nchildLinksTo(w)+k.nparentLinksTo(w)>1?2:1))),h=Ko(m,y*1.5),N=0,v=0;for(let k of h.values())N=Math.min(N,k),v=Math.max(v,k);let L=-N*l+c/2;for(let k of m)k.x=L;for(let k of s.links()){let w=(d=h.get(k))!=null?d:0,{source:S,target:O,points:I}=k;if(I.splice(0),I.push([S.x,S.y]),w!==0){let z=(w-N)*l+(w>0?c:0),M=S.y+y,$=O.y-y;$-M>.001*y?I.push([z,M],[z,$]):I.push([z,M])}I.push([O.x,O.y])}u={width:(v-N)*l+c,height:b}}for(let l of e.tweaks)u=l(s,u);return u}function r(s){if(s===void 0)return e.rank;{let u=e,{rank:d}=u,l=V(u,["rank"]);return dt(R(T({},l),{rank:s}),t)}}n.rank=r;function i(s){if(s===void 0)return e.tweaks;{let u=e,{tweaks:d}=u,l=V(u,["tweaks"]);return dt(R(T({},l),{tweaks:s}),t)}}n.tweaks=i;function o(s){if(s===void 0)return e.nodeSize;if(typeof s!="function"&&(s[0]<=0||s[1]<=0)){let[d,l]=s;throw D`constant nodeSize must be positive, but got: [${d}, ${l}]`}else{let u=e,{nodeSize:d}=u,l=V(u,["nodeSize"]);return dt(R(T({},l),{nodeSize:s}),t)}}n.nodeSize=o;function a(s){if(s!==void 0){let[u,d]=s;if(u<0||d<0)throw D`gap width (${u}) and height (${d}) must be non-negative`;return dt(e,R(T({},t),{xgap:u,ygap:d}))}else{let{xgap:u,ygap:d}=t;return[u,d]}}return n.gap=a,n}function Yo(...e){if(e.length)throw D`got arguments to zherebko(${e}), but constructor takes no arguments; these were probably meant as data which should be called as \`zherebko()(...)\``;return dt({rank:()=>{},nodeSize:[1,1],tweaks:[]},{xgap:1,ygap:1})}0&&(module.exports={aggMean,aggMedian,aggWeightedMedian,cachedNodeSize,coordCenter,coordGreedy,coordQuad,coordSimplex,coordTopological,decrossDfs,decrossOpt,decrossTwoLayer,graph,graphConnect,graphHierarchy,graphJson,graphStratify,grid,laneGreedy,laneOpt,layerSeparation,layeringLongestPath,layeringSimplex,layeringTopological,shapeEllipse,shapeRect,sizedSeparation,splitNodeSize,sugiNodeLength,sugifyCompact,sugifyLayer,sugiyama,tweakFlip,tweakGrid,tweakShape,tweakSize,twolayerAgg,twolayerGreedy,twolayerOpt,unsugify,zherebko});