const fs=require('node:fs'),vm=require('node:vm'),assert=require('node:assert/strict');const sandbox={window:{}};vm.runInNewContext(fs.readFileSync('PlotLine/wwwroot/js/context-relationship-layout.js','utf8'),sandbox);const engine=sandbox.window.PlotDirectorContextRelationshipLayout; const nodes=Array.from({length:15},(_,i)=>({id:i+1,name:'Person '+(i+1),birthDate:i===6?'2000-01-01':i===7?'2002-01-01':null}));let seq=0;const links=[];function add(a,b,type,reciprocal=false){links.push({id:++seq,a,b,type,reciprocal});return seq;} add(1,2,'Spouse',true);add(1,3,'Parent');add(2,3,'Parent');add(3,4,'Spouse',true);add(3,5,'Parent');add(4,5,'Parent');add(5,6,'Spouse',true);add(5,10,'Former spouse',true);add(5,7,'Biological Parent');add(6,7,'Biological Parent');add(5,8,'Parent');add(6,8,'Parent');add(5,9,'Parent');add(10,9,'Parent');add(11,7,'Adoptive Parent');add(12,7,'Step Parent');add(3,15,'Child');add(1,14,'Grandparent');add(13,14,'Cousin'); const layout=engine.family(nodes,links),p=layout.positions;assert(p[1].y
0);assert(layout.routes.some(r=>r.kind==='adoptive'));assert(layout.routes.some(r=>r.kind==='step'));
// Orthogonal connectors may cross with a visual bridge, but must not enter an unrelated card.
for(const route of layout.routes){const edge=links.find(l=>l.id===route.id);let cursor={x:0,y:0};const parts=[...route.d.matchAll(/([MHV])\s*(-?[\d.]+)(?:\s+(-?[\d.]+))?/g)];for(const part of parts){const next=part[1]==='M'?{x:+part[2],y:+part[3]}:part[1]==='H'?{x:+part[2],y:cursor.y}:{x:cursor.x,y:+part[2]};if(part[1]!=='M')for(const n of nodes){if(n.id===edge.a||n.id===edge.b)continue;const rect=p[n.id],inside=cursor.x===next.x?cursor.x>rect.x+1&&cursor.x