agentic-mermaid 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/agent-core.d.ts +7 -7
- package/dist/agent-core.js +1 -1
- package/dist/agent.d.ts +7 -7
- package/dist/agent.js +1 -1
- package/dist/agentic-mermaid-mcp.js +1 -1
- package/dist/am.js +1 -1
- package/dist/browser-lazy/chunks/{agentic-producer-core-CC6OOLDW.js → agentic-producer-core-ECZ3CMZM.js} +1 -1
- package/dist/browser-lazy/chunks/{architecture-QUFVKYJR.js → architecture-H5LTMKQW.js} +6 -6
- package/dist/browser-lazy/chunks/{block-6J3Q63BO.js → block-566X6FNV.js} +5 -5
- package/dist/browser-lazy/chunks/{builtin-backends-7SOZZHPF.js → builtin-backends-VAFEZXKY.js} +6 -6
- package/dist/browser-lazy/chunks/{c4-SQVBZAKJ.js → c4-ZXFDLBFK.js} +5 -5
- package/dist/browser-lazy/chunks/{chunk-5X6MJX3H.js → chunk-2JQXRKBC.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-E2WMJZNM.js → chunk-37FZNMPR.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-TYZOZXUJ.js → chunk-3JTYTXA6.js} +6 -6
- package/dist/browser-lazy/chunks/{chunk-PQGPS2YV.js → chunk-4NILRBC7.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-AMJLVPUB.js → chunk-5LKPDHPC.js} +2 -2
- package/dist/browser-lazy/chunks/{chunk-BY2CPG6B.js → chunk-62MR3LWJ.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-J7FFAFQF.js → chunk-64JFHCJC.js} +1 -1
- package/dist/browser-lazy/chunks/chunk-6GPDLZFQ.js +1 -0
- package/dist/browser-lazy/chunks/{chunk-VWVZGQE2.js → chunk-6UOOATQR.js} +1 -1
- package/dist/browser-lazy/chunks/chunk-7TTFBJYA.js +1 -0
- package/dist/browser-lazy/chunks/chunk-7UFOFWBA.js +20 -0
- package/dist/browser-lazy/chunks/{chunk-5B2Z7575.js → chunk-A7V5VDKN.js} +1 -1
- package/dist/browser-lazy/chunks/chunk-CPO5P4L2.js +1 -0
- package/dist/browser-lazy/chunks/chunk-EIYLJ4FI.js +20 -0
- package/dist/browser-lazy/chunks/{chunk-X2UYKWKM.js → chunk-G4JBA7HU.js} +3 -3
- package/dist/browser-lazy/chunks/{chunk-2UIA2IME.js → chunk-IUI4DYC3.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-QA6GJQ4X.js → chunk-J57YRC2M.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-BU5LHXNJ.js → chunk-LBXXKLIR.js} +3 -3
- package/dist/browser-lazy/chunks/chunk-NKW2ZNCD.js +1 -0
- package/dist/browser-lazy/chunks/{chunk-ICC7HBJX.js → chunk-O34YYEQV.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-UL6NDWLL.js → chunk-OBI5U5XU.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-YCEICNM6.js → chunk-OFOS57WQ.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-OZ443IVJ.js → chunk-PSZEE64O.js} +7 -7
- package/dist/browser-lazy/chunks/{chunk-SZELX2EJ.js → chunk-PXTLV57R.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-HLWUNUCM.js → chunk-QVSZOF5M.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-2GPK4VFF.js → chunk-TT5GR5EJ.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-DF6765YX.js → chunk-V6I2VGNQ.js} +5 -5
- package/dist/browser-lazy/chunks/{chunk-CN7WTBWB.js → chunk-VRZKI33U.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-2SH76OTH.js → chunk-XHU3A432.js} +1 -1
- package/dist/browser-lazy/chunks/{chunk-NO7ZIVRU.js → chunk-YVNJDVQO.js} +1 -1
- package/dist/browser-lazy/chunks/chunk-Z7UHFVKN.js +6 -0
- package/dist/browser-lazy/chunks/{class-5QA4SCTS.js → class-XIFNVBFE.js} +8 -8
- package/dist/{zenuml/chunks/decode-BWERFDGK.js → browser-lazy/chunks/decode-5MFOG3AZ.js} +1 -1
- package/dist/browser-lazy/chunks/{elk.bundled-L4CADV5W.js → elk.bundled-RYWHIS5N.js} +8 -8
- package/dist/browser-lazy/chunks/er-VEUYJBGG.js +11 -0
- package/dist/browser-lazy/chunks/{eventmodeling-2BPLHWRN.js → eventmodeling-G7DITZX7.js} +10 -10
- package/dist/browser-lazy/chunks/{flowchart-NEIMZTB5.js → flowchart-SSFIU4EU.js} +1 -1
- package/dist/browser-lazy/chunks/{forest-implementation-AEP24AIP.js → forest-implementation-RWFF7XDV.js} +1 -1
- package/dist/browser-lazy/chunks/{gantt-RDPIFYAF.js → gantt-HQNVDX2B.js} +6 -6
- package/dist/browser-lazy/chunks/{gitgraph-N4Y5RYB7.js → gitgraph-Z5MN6M6L.js} +4 -4
- package/dist/browser-lazy/chunks/{ishikawa-LD3YBDJN.js → ishikawa-UEERNFQV.js} +2 -2
- package/dist/browser-lazy/chunks/{journey-6YQR5DJX.js → journey-3BEWWGB5.js} +6 -6
- package/dist/browser-lazy/chunks/{kanban-PLMJ7NBW.js → kanban-2WFNCWLB.js} +10 -10
- package/dist/browser-lazy/chunks/{mermaid-yaml-runtime-QVYX4EWK.js → mermaid-yaml-runtime-IK4ET4BT.js} +8 -8
- package/dist/browser-lazy/chunks/{mindmap-K2UBFO3Y.js → mindmap-R2C6SNYR.js} +4 -4
- package/dist/browser-lazy/chunks/{packet-CUW4QY6Y.js → packet-GMVCI5YZ.js} +3 -3
- package/dist/browser-lazy/chunks/{pie-7F7UUCG3.js → pie-WER45DKC.js} +7 -7
- package/dist/browser-lazy/chunks/{quadrant-TOONO2WC.js → quadrant-NCUPSFKN.js} +4 -4
- package/dist/browser-lazy/chunks/{radar-J6JVWVAX.js → radar-WLYS4YC5.js} +8 -8
- package/dist/browser-lazy/chunks/render-core-42UVWIPF.js +3 -0
- package/dist/browser-lazy/chunks/{requirement-CMAKDJPO.js → requirement-AK3NWMJ6.js} +7 -7
- package/dist/browser-lazy/chunks/{sankey-AWXQEP3F.js → sankey-C2DY6WVU.js} +4 -4
- package/dist/browser-lazy/chunks/{sequence-Q2RJRB4L.js → sequence-D4WJB44W.js} +1 -1
- package/dist/browser-lazy/chunks/{state-WRBFQEDX.js → state-YUQVESE7.js} +2 -2
- package/dist/browser-lazy/chunks/{timeline-D2KILFXM.js → timeline-BMBJJXWR.js} +4 -4
- package/dist/browser-lazy/chunks/{treemap-N3VYX5D4.js → treemap-B66XBZZ6.js} +3 -3
- package/dist/browser-lazy/chunks/{xychart-G73OGK66.js → xychart-HAVFROGT.js} +6 -6
- package/dist/browser-lazy/chunks/{zenuml-H4BXNYXR.js → zenuml-62RLYFWP.js} +7 -7
- package/dist/browser-lazy/index.js +1 -1
- package/dist/browser.global.js +507 -507
- package/dist/{chunk-DQDKA5ND.js → chunk-2DNGDTJD.js} +2 -2
- package/dist/{chunk-GVCHLSHH.js → chunk-4F2UGYTM.js} +2 -2
- package/dist/{chunk-H3NCS2XZ.js → chunk-7XYB2LNC.js} +2 -2
- package/dist/chunk-DOFB572I.js +58 -0
- package/dist/chunk-EHJI3QYE.js +52 -0
- package/dist/{chunk-UA234O4M.js → chunk-HINRNKPO.js} +2 -2
- package/dist/{chunk-JZOJ4YGS.js → chunk-KXMANAST.js} +33 -33
- package/dist/{chunk-7CRDX2QR.js → chunk-U4MT3RRE.js} +2 -2
- package/dist/{chunk-NKNFOREZ.js → chunk-WYIB6BUR.js} +2 -2
- package/dist/{cli-YGGTJZH7.js → cli-ZYIDBYNS.js} +2 -2
- package/dist/{index-EeXqJXr5.d.ts → index-Bvhprdxz.d.ts} +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/{mcp-cli-63DYXTVD.js → mcp-cli-YVDCORWA.js} +2 -2
- package/dist/{paint-certification-6rwQjIv_.d.ts → paint-certification-BoLyr006.d.ts} +2 -2
- package/dist/{server-5NEOHOFS.js → server-4JGAVXR3.js} +2 -2
- package/dist/{svg-styles-BdnoM7AT.d.ts → svg-styles-BnCoXyYe.d.ts} +1 -1
- package/dist/svg-styles.d.ts +1 -1
- package/dist/svg-styles.js +1 -1
- package/dist/svg.d.ts +4 -4
- package/dist/svg.js +1 -1
- package/dist/{types-BcS52Mjt.d.ts → types-CLVJCaH2.d.ts} +1 -1
- package/dist/zenuml/chunks/{appearance-UOQ5KA6O.js → appearance-5RM5MVM2.js} +1 -1
- package/dist/zenuml/chunks/{builtin-backends-KDKE7YHO.js → builtin-backends-UTNWL4N3.js} +11 -11
- package/dist/zenuml/chunks/{chunk-QWX77U7G.js → chunk-3A6S6GNB.js} +2 -2
- package/dist/zenuml/chunks/{chunk-OXQWRSBM.js → chunk-55WS466K.js} +11 -11
- package/dist/zenuml/chunks/chunk-6J4BGPB2.js +29 -0
- package/dist/zenuml/chunks/chunk-CNLL4BGF.js +1 -0
- package/dist/zenuml/chunks/{chunk-RZ6XK5CD.js → chunk-IARQ24W3.js} +13 -13
- package/dist/zenuml/chunks/{chunk-42DXZ5C6.js → chunk-ZNZRIISS.js} +2 -2
- package/dist/{browser-lazy/chunks/decode-63UIZGD2.js → zenuml/chunks/decode-LDNNXEAO.js} +1 -1
- package/dist/zenuml/chunks/{mermaid-yaml-runtime-KZVU74WU.js → mermaid-yaml-runtime-A5CNJ3IE.js} +8 -8
- package/dist/zenuml/chunks/render-core-ECIWU5ZS.js +3 -0
- package/dist/zenuml/chunks/{zenuml-EA2ZFRUX.js → zenuml-N3LZMB2G.js} +8 -8
- package/dist/zenuml.d.ts +2 -2
- package/dist/zenuml.js +1 -1
- package/docs/MCP-DIRECTORY-LISTINGS.md +81 -12
- package/docs/api.md +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +0 -1
- package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +0 -6
- package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +0 -1
- package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +0 -20
- package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +0 -1
- package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +0 -20
- package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +0 -11
- package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +0 -3
- package/dist/chunk-EHCMJUMD.js +0 -52
- package/dist/chunk-OMY6NRQD.js +0 -58
- package/dist/zenuml/chunks/chunk-7TVYPTDW.js +0 -1
- package/dist/zenuml/chunks/chunk-RLJEI7YN.js +0 -29
- package/dist/zenuml/chunks/render-core-V5RQ737O.js +0 -3
- /package/dist/browser-lazy/chunks/{chunk-5FQ534HP.js → chunk-BMZ24VPS.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-2I4UPL7Q.js → chunk-D6MQ7QSU.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-CQE4HQEW.js → chunk-HJVO5VC3.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-LH7HUDKW.js → chunk-L4UC3KGS.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-NMQQMRIR.js → chunk-MFTQWHUB.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-N5ELX7LR.js → chunk-PJJSDGLB.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-CSFUKSU6.js → chunk-QCU5G5PZ.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-VQYYGAXP.js → chunk-TLFX3U6S.js} +0 -0
- /package/dist/browser-lazy/chunks/{chunk-5UVGUSD6.js → chunk-YHMTSXIR.js} +0 -0
- /package/dist/zenuml/chunks/{chunk-EVPSMEKN.js → chunk-GC7IPQ5P.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,b as t,c as i,d as r,e as a,g as n,i as o,j as l}from"./chunk-UL6NDWLL.js";import{a as s,b as h}from"./chunk-LH7HUDKW.js";import{d as g}from"./chunk-5FQ534HP.js";import{e as c}from"./chunk-SZELX2EJ.js";import"./chunk-NO7ZIVRU.js";import{Nb as d,Q as f,Sb as y,Wb as m}from"./chunk-Z3FDIVLN.js";import"./chunk-5UVGUSD6.js";import"./chunk-CSFUKSU6.js";function u(e,t,i){for(let r=0;r<e.length;r++)for(let a=0;a<t.length;a++){i?.(1);let n=e[r],o=t[a];if("circle"===n.kind){if("circle"===o.kind){let e=n.cx-o.cx,t=n.cy-o.cy,i=n.r+o.r;if(n.r>0&&o.r>0&&e*e+t*t<i*i)return!0}else if(x(n.cx,n.cy,n.r,o.points,i))return!0}else if("circle"===o.kind){if(x(o.cx,o.cy,o.r,n.points,i))return!0}else if(function(e,t,i){if(e.length<3||t.length<3)return!1;let r=e[0],a=0;for(let n=0;n<2;n++){let o=0===n?e:t;for(let n=0;n<o.length;n++){i?.(1);let l=o[n],s=o[(n+1)%o.length],h=l.y-s.y,g=s.x-l.x;if(0===h&&0===g)continue;a++;let c=1/0,d=-1/0,f=1/0,y=-1/0;for(let t=0;t<e.length;t++){i?.(1);let a=e[t],n=(a.x-r.x)*h+(a.y-r.y)*g;c=Math.min(c,n),d=Math.max(d,n)}for(let e=0;e<t.length;e++){i?.(1);let a=t[e],n=(a.x-r.x)*h+(a.y-r.y)*g;f=Math.min(f,n),y=Math.max(y,n)}if(Math.min(d,y)<=Math.max(c,f))return!1}}return a>0}(n.points,o.points,i))return!0}return!1}function x(e,t,i,r,a){if(!(i>0)||r.length<3)return!1;let n=0,o=!0,l=0,s=1/0,h=r[0];for(let i=0;i<r.length;i++){a?.(1);let g=r[i],c=r[(i+1)%r.length],d=c.x-g.x,f=c.y-g.y,y=d*(t-g.y)-f*(e-g.x);l+=(g.x-h.x)*(c.y-h.y)-(g.y-h.y)*(c.x-h.x),0!==y&&(0!==n&&Math.sign(y)!==n&&(o=!1),n||=Math.sign(y));let m=d*d+f*f,u=m>0?Math.max(0,Math.min(1,((e-g.x)*d+(t-g.y)*f)/m)):0;s=Math.min(s,(g.x+u*d-e)**2+(g.y+u*f-t)**2)}return 0!==l&&(o||s<i*i)}var p=new WeakMap;function b(e,t,i,r){let a=(e=1)=>{t.pairs-=e,t.pairs<0&&i("agentic local cross-hierarchy obstacle-work limit")},n=(e,r)=>{"work"===r?a(e):(t.arcs-=e,t.arcs<0&&i("agentic local cross-hierarchy visibility-arc limit"))},o=r?r.x:s(e,"x",0,n),l=r?r.y:s(e,"y",0,n),g=(e,t,i)=>e?(i?.(),a(),h(e,t)):null,c=(e,t)=>t<0||t+1>=e.offsets.length,d=(e,t,i)=>t>e.x&&t<e.x+e.width&&i>e.y&&i<e.y+e.height,f=(e,t,i,r,a)=>t===r?t>e.x&&t<e.x+e.width&&Math.max(i,a)>e.y&&Math.min(i,a)<e.y+e.height:i>e.y&&i<e.y+e.height&&Math.max(t,r)>e.x&&Math.min(t,r)<e.x+e.width,y=(e,t,i,r,n)=>{a(2),t?r>e.y&&r<e.y+e.height&&(e.x>=i&&(n.right=Math.min(n.right,e.x)),e.x+e.width<=i&&(n.left=Math.max(n.left,e.x+e.width))):i>e.x&&i<e.x+e.width&&(e.y>=r&&(n.bottom=Math.min(n.bottom,e.y)),e.y+e.height<=r&&(n.top=Math.max(n.top,e.y+e.height)))},m={projectPoint(t,i,r,n){a(4),n.left=r.x,n.right=r.x+r.width,n.top=r.y,n.bottom=r.y+r.height;for(let r=0;r<2;r++){let a=0===r,s=a?l:o,h=g(s,a?i:t);if(s&&null!==h){if(c(s,h))continue;for(let r=s.offsets[h];r<s.offsets[h+1];r++)y(e[s.ordinals[r]],a,t,i,n)}else for(let r of e)y(r,a,t,i,n)}},containsPoint(t,i,r){let n=g(o,t,r),s=g(l,i,r);if(o&&null!==n&&c(o,n)||l&&null!==s&&c(l,s))return!1;let h=o&&null!==n?o.offsets[n+1]-o.offsets[n]:1/0,f=l&&null!==s?l.offsets[s+1]-l.offsets[s]:1/0,y=h<=f?o:l,m=h<=f?n:s;if(y&&null!==m){for(let n=y.offsets[m];n<y.offsets[m+1];n++)if(r?.(),a(),d(e[y.ordinals[n]],t,i))return!0}else for(let n of e)if(r?.(),a(),d(n,t,i))return!0;return!1},entersSegment(t,i,r,n,s){let h=t===r?o:l,d=g(h,t===r?t:i,s);if(h&&null!==d){if(c(h,d))return!1;for(let o=h.offsets[d];o<h.offsets[d+1];o++)if(s?.(),a(),f(e[h.ordinals[o]],t,i,r,n))return!0}else for(let o of e)if(s?.(),a(),f(o,t,i,r,n))return!0;return!1}};return n(4,"capacity"),p.set(m,{boxes:e,containsPoint:m.containsPoint,entersSegment:m.entersSegment,projectPoint:m.projectPoint}),m}function M(e,t,i,r,a,n,o,l,s,h,g,c,d=.5,f=!1){o.arcs-=24+a.length+2,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit");let y=(e=1)=>{o.pairs-=e,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit")},m=e=>{o.arcs-=e,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit")},u=new Float64Array(a.length+2),x=(e,t)=>(--o.swaps<0&&s("agentic local cross-hierarchy coordinate-sort limit"),e===t?0:e-t);y(18);let p=i.stub.x-i.port.x,b=i.stub.y-i.port.y;if(0===p==(0===b))return;let v=0===b,k=Math.sign(v?p:b),S=v?i.port.y:i.port.x,N=v?i.port.x:i.port.y,E=void 0===c?v?i.stub.x:i.stub.y:N+k*c,I=v?e.y:e.x,P=I+(v?e.height:e.width),A=v?e.x:e.y,F=A+(v?e.width:e.height),Y=k<0?A:F;if(!Number.isFinite(d)||d<.5||void 0!==c&&(!Number.isFinite(c)||c<0)||!Number.isFinite(I+P+A+F+S+N+E)||P<=I||F<=A||S<I||S>P||N<A||N>F||E<A||E>F)return;let T=(e,t,i,r,n)=>{y(u.length),u.fill(1/0);let o=2;for(let[l,s]of(u[0]=e,u[1]=t,a)){y(10);let a=v?l.y:l.x,h=v?l.x:l.y,g=v?s.y:s.x,c=v?s.x:s.y,f=i?a:h;(i?a!==g:h!==c)||Math.max(i?h:a,i?c:g)<r-d||Math.min(i?h:a,i?c:g)>n+d||f<=e||f>=t||(u[o++]=f)}u.sort(x);let l=-1/0,s;for(let e=1;e<o;e++){y(5);let t=u[e-1],i=u[e],r=i-t,a=t+r/2;r>2*d&&r>l&&a>t&&a<i&&(l=r,s=a)}return s},X=0;for(let e=0;e<2;e++){if(X>=8)return;let i=0;for(let c of r){y(6);let r=v?c.stub.y-c.port.y:c.stub.x-c.port.x,u=v?c.stub.x-c.port.x:c.stub.y-c.port.y;y(4);let x=1===e;if(x?0!==u||0===r:0!==r||Math.sign(u)!==k)continue;if(++i>4)break;let p=v?c.port.y:c.port.x,b=v?c.port.x:c.port.y,M=v?c.stub.x:c.stub.y,C=v?c.stub.y:c.stub.x;if(y(8),!(p<I||p>P||b<A||b>F||k*(b-N)<=0))for(let e=0;e<2;e++){let i,c=0===e?-1:1,u=c<0?I:P;if(y(),x&&c!==Math.sign(r))continue;let L=Math.min(u,S),O=Math.max(u,S),R=E,W=!1;for(let e=0;e<=t.length;e++){let e=R;for(let i of t){y(12);let t=v?i.y:i.x,r=v?i.x:i.y,a=v?i.height:i.width,n=v?i.width:i.height;if(!Number.isFinite(t+r+a+n)||a<0||n<0)return;t>=O||t+a<=L||(k>0&&r<=R&&r+n>R&&(e=Math.max(e,r+n)),k<0&&r<R&&r+n>=R&&(e=Math.min(e,r)))}if(y(3),e===R){W=!0;break}if((R=e)<A||R>F)break}if(!W)continue;let H=Y;for(let e of t){y(10);let t=v?e.y:e.x,i=v?e.x:e.y,r=v?e.height:e.width,a=v?e.width:e.height;t>=O||t+r<=L||(k>0&&i>=R&&(H=Math.min(H,i)),k<0&&i+a<=R&&(H=Math.max(H,i+a)))}let j=T(Math.min(R,H),Math.max(R,H),!1,L,O);if(y(4),void 0===j||k*(j-E)<=0||k*(b-j)<=0)continue;let z=c<0?P:I,U=Math.min(j,x?b:Y),V=Math.max(j,x?b:Y);for(let e of t){y(10);let t=v?e.y:e.x,i=v?e.x:e.y,r=v?e.height:e.width,a=v?e.width:e.height;i>=V||i+a<=U||t>P||t+r<I||(z=c<0?Math.min(z,Math.max(I,t)):Math.max(z,Math.min(P,t+r)))}if(y(2),c*(u-z)<=0)continue;let B=T(Math.max(Math.min(u,z),L),Math.min(Math.max(u,z),O),!0,U,V);if(void 0===B||c*(B-S)<0)continue;if(x){if(y(4),c*(B-C)<0)continue;if(y(2),X>=8)return;X++,l(5),m(6),i=v?[{x:N,y:S},{x:j,y:S},{x:j,y:B},{x:b,y:B},{x:b,y:p}]:[{x:S,y:N},{x:S,y:j},{x:B,y:j},{x:B,y:b},{x:p,y:b}]}else{let e=Math.min(B,p),r=Math.max(B,p),a=M;for(let i of t){y(10);let t=v?i.y:i.x,n=v?i.x:i.y,o=v?i.height:i.width,l=v?i.width:i.height;t>=r||t+o<=e||n>F||n+l<A||(a=k<0?Math.min(a,Math.max(A,n)):Math.max(a,Math.min(F,n+l)))}if(y(2),k*(Y-a)<=0)continue;let n=T(Math.min(Y,a),Math.max(Y,a),!1,e,r);if(void 0===n)continue;if(y(2),X>=8)return;X++,l(6),m(7),i=v?[{x:N,y:S},{x:j,y:S},{x:j,y:B},{x:n,y:B},{x:n,y:p},{x:b,y:p}]:[{x:S,y:N},{x:S,y:j},{x:B,y:j},{x:B,y:n},{x:p,y:n},{x:p,y:b}]}y(),f&&(y(2*i.length),i.reverse());let D=!0,_=0;for(let e=0;e<i.length;e++){let t=i[e];if(n.containsPoint(t.x,t.y)){D=!1;break}if(0===e)continue;let r=i[e-1],l=r.x===t.x?2:1;if(y(4),r.x===t.x&&r.y===t.y||r.x!==t.x&&r.y!==t.y||n.entersSegment(r.x,r.y,t.x,t.y)||!h(r,t,_||l,l)||(1===e||e===i.length-1)&&!w(r,t,a,d,o,s)){D=!1;break}_=l}if(D){let e=g(i);if(e)return e}}}}}function w(e,t,i,r,a,n){let o=e.x===t.x;for(let[l,s]of i)if(a.pairs-=3,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),!(o!==(l.x===s.x)||(a.pairs-=4,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),Math.abs(o?e.x-l.x:e.y-l.y)>r))&&(a.pairs-=12,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),Math.min(o?Math.max(e.y,t.y):Math.max(e.x,t.x),o?Math.max(l.y,s.y):Math.max(l.x,s.x))-Math.max(o?Math.min(e.y,t.y):Math.min(e.x,t.x),o?Math.min(l.y,s.y):Math.min(l.x,s.x))>=-r))return!1;return!0}function v(e,t,i){let r=0;for(let a=0;a<e.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=e[a];for(e[r++]=n;r>=3;){t.pairs-=12,t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let a=e[r-3],n=e[r-2],o=e[r-1];if(!(a.x===n.x&&n.x===o.x&&n.y>=Math.min(a.y,o.y)&&n.y<=Math.max(a.y,o.y)||a.y===n.y&&n.y===o.y&&n.x>=Math.min(a.x,o.x)&&n.x<=Math.max(a.x,o.x)))break;e[r-2]=o,r--}}return--t.pairs<0&&i("agentic local cross-hierarchy self-check limit"),e.length=r,e}var k=class{constructor(e,t,i,r,a,n,o){this.canvasWidth=i,this.canvasHeight=r,this.work=a,this.reservePoints=n,this.fail=o,this.capacity(e.length+2),this.catalog=Array(e.length),this.rails=[],this.capacity(1),this.onIndexCharge=(e,t)=>"capacity"===t?this.capacity(e):this.charge(e),this.capacity(2),this.x={cross:"x",enabled:!1,seed:null,first:1/0,last:-1/0,memberships:0,safe:!0,domainFirst:NaN,domainLast:NaN,heads:void 0},this.y={cross:"y",enabled:!1,seed:null,first:1/0,last:-1/0,memberships:0,safe:!0,domainFirst:NaN,domainLast:NaN,heads:void 0};for(let i=0;i<e.length;i++)this.charge(),i!==t&&"invisible"!==e[i].style&&this.addGeometry(i,e[i].points);this.seedAxis(this.x),this.seedAxis(this.y),this.updating=!1}canvasWidth;canvasHeight;work;reservePoints;fail;catalog;rails;x;y;revision=0;active;geometrySafe=!0;arcAllocated=1;pointAllocated=0;insertionVisits=0;flatMoves=0;flatSearches=0;seedBuilds=0;failed=!1;updating=!0;lastStart=0;lastCount=0;onIndexCharge;charge(e=1){this.work.pairs-=e,this.work.pairs<0&&(this.failed=!0,this.fail("agentic local cross-hierarchy crossing-work limit"))}capacity(e){this.work.arcs-=e,this.work.arcs<0&&(this.failed=!0,this.fail("agentic local cross-hierarchy visibility-arc limit")),this.arcAllocated+=e}point(){try{this.reservePoints(1),this.pointAllocated++}catch(e){throw this.failed=!0,e}}axisEligible(e){this.charge(8);let t=this.rails.length,i=e.last-e.first+1;return this.geometrySafe&&t>=32&&t<=0x10000000&&e.safe&&Number.isSafeInteger(e.memberships)&&e.memberships<=8*t&&Number.isSafeInteger(i)&&i<=8*t}addTotals(e,t){this.charge(8);let i="x"===e.cross?t.xLow:t.yLow,r="x"===e.cross?t.xHigh:t.yHigh;if(!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||r<i){e.safe=!1;return}e.memberships+=r-i+1,e.first=Math.min(e.first,i),e.last=Math.max(e.last,r),Number.isSafeInteger(e.memberships)||(e.safe=!1)}addGeometry(e,t){if(this.charge(3),!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Duplicate or invalid peer geometry publication");this.capacity(t.length+2);let i=Array(t.length),r=0;for(let e=0;e<t.length;e++){this.charge(4);let a=t[e],n=i[r-1];if(n?.x!==a.x||n.y!==a.y)for(this.point(),i[r++]={x:a.x,y:a.y};r>2;){this.charge(8);let e=i[r-3],t=i[r-2],a=i[r-1];if(!(e.x===t.x&&t.x===a.x&&t.y>=Math.min(e.y,a.y)&&t.y<=Math.max(e.y,a.y)||e.y===t.y&&t.y===a.y&&t.x>=Math.min(e.x,a.x)&&t.x<=Math.max(e.x,a.x)))break;i[r-2]=a,r--}}i.length=r;let a=Math.max(0,r-1),n=0;for(;n<this.rails.length&&(this.charge(),this.flatSearches++,!(this.rails[n].route>e));)n++;this.capacity(a);let o=this.rails.length;this.rails.length=o+a;for(let e=o-1;e>=n;e--)this.charge(),this.flatMoves++,this.rails[e+a]=this.rails[e];for(let t=0;t<a;t++){this.charge(12);let r=i[t],a=i[t+1];this.geometrySafe&&=Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(a.x)&&Number.isFinite(a.y)&&(r.x===a.x||r.y===a.y)&&Number.isFinite(Math.abs(r.x-a.x))&&Number.isFinite(Math.abs(r.y-a.y)),this.capacity(3);let o=[r,a];o.route=e,o.ordinal=t,o.x=Math.min(r.x,a.x)-.5,o.y=Math.min(r.y,a.y)-.5,o.width=Math.abs(r.x-a.x)+1,o.height=Math.abs(r.y-a.y)+1,o.xLow=Math.floor(o.x/128),o.xHigh=Math.floor((o.x+o.width)/128),o.yLow=Math.floor(o.y/128),o.yHigh=Math.floor((o.y+o.height)/128),this.rails[n+t]=o,this.addTotals(this.x,o),this.addTotals(this.y,o)}this.catalog[e]={points:i,segments:a},this.lastStart=n,this.lastCount=a}seedAxis(e){this.charge(12);let t="x"===e.cross?this.canvasWidth:this.canvasHeight,i=Math.min(e.first,Math.floor(-.5/128)),r=Math.max(e.last,Math.floor((t+.5)/128)),a=r-i+1;if(e.domainFirst=i,e.domainLast=r,!(!this.axisEligible(e)||!Number.isFinite(t)||t<0||!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||a>8*this.rails.length)&&(this.seedBuilds++,e.seed=s(this.rails,e.cross,0,this.onIndexCharge),e.seed)){this.capacity(a+1),this.charge(a),e.heads=Array(a).fill(void 0),e.enabled=!0;for(let t=0;t+1<e.seed.offsets.length;t++){this.charge();let i=e.seed.firstCell+t-e.domainFirst;for(let r=e.seed.offsets[t+1]-1;r>=e.seed.offsets[t];r--)this.charge(),this.capacity(1),e.heads[i]={peer:this.rails[e.seed.ordinals[r]],next:e.heads[i]}}}}insert(e,t){let i="x"===e.cross?t.xLow:t.yLow,r="x"===e.cross?t.xHigh:t.yHigh;for(let a=i;a<=r;a++){this.charge(2);let i=a-e.domainFirst,r,n=e.heads[i];for(;n&&(this.charge(2),this.insertionVisits++,!(n.peer.route>t.route||n.peer.route===t.route&&n.peer.ordinal>=t.ordinal));)r=n,n=n.next;this.capacity(1);let o={peer:t,next:n};r?r.next=o:e.heads[i]=o}}assertLease(e){if(this.failed||this.updating||e.released||this.active!==e||e.revision!==this.revision)throw TypeError("Stale peer geometry revision")}acquire(e){if(this.charge(4),this.failed||this.updating||this.active||!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Peer geometry lease is already active or owns its current route");this.capacity(3);let t={index:e,revision:this.revision,released:!1,queries:0,guardCalls:0,guard:void 0,release:void 0};return t.guard=(e,i,r,a)=>this.canTraverse(t,e,i,r,a),t.release=()=>this.release(t),this.charge(),this.active=t,t}enterQuery(e){this.charge(),this.assertLease(e),this.charge(),e.queries++}leaveQuery(e){if(e.released||this.active!==e||e.revision!==this.revision||e.queries<=0)throw this.charge(),TypeError("Peer query lease was not entered or is stale");e.queries--}release(e){if(e.released||this.active!==e||e.revision!==this.revision||e.queries||e.guardCalls)throw this.charge(),TypeError("Cannot release stale peer geometry or an active query");e.released=!0,this.active=void 0}publish(e,t,i){if(this.charge(4),this.failed||this.updating||this.active)throw TypeError("Cannot publish peer geometry while a revision is leased or failed");if(!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Duplicate or invalid peer geometry publication");if(this.updating=!0,!i){this.catalog[e]=null,this.revision++,this.updating=!1;return}this.addGeometry(e,t);let r=this.lastStart,a=this.lastCount;for(let e=0;e<2;e++){let t=0===e?this.x:this.y,i=!0;for(let n=r;n<r+a;n++){this.charge(4);let r=this.rails[n],a=0===e?r.xLow:r.yLow,o=0===e?r.xHigh:r.yHigh;(!Number.isSafeInteger(a)||!Number.isSafeInteger(o)||a<t.domainFirst||o>t.domainLast)&&(i=!1)}if(this.axisEligible(t)&&i||(t.enabled=!1),t.enabled)for(let e=r;e<r+a;e++)this.insert(t,this.rails[e])}this.revision++,this.updating=!1}blocked(e,i,r,a,n){let o=r[0],l=r[1];if(this.charge(),a!==n&&t(e,o,l))return!0;let s=e.x===i.x;if(s===(o.x===l.x)){let t=Math.abs(s?e.x-o.x:e.y-o.y),r=Math.min(s?Math.max(e.y,i.y):Math.max(e.x,i.x),s?Math.max(o.y,l.y):Math.max(o.x,l.x))-Math.max(s?Math.min(e.y,i.y):Math.min(e.x,i.x),s?Math.min(o.y,l.y):Math.min(o.x,l.x));if(t<=.5&&r>.01||0===t&&r>=0)return!0}else{let t=s?e.x:o.x,r=s?o.y:e.y;if((e.x===i.x?1e-7>Math.abs(t-e.x):1e-7>Math.abs(r-e.y))&&t>=Math.min(e.x,i.x)&&t<=Math.max(e.x,i.x)&&r>=Math.min(e.y,i.y)&&r<=Math.max(e.y,i.y)&&(o.x===l.x?1e-7>Math.abs(t-o.x):1e-7>Math.abs(r-o.y))&&t>=Math.min(o.x,l.x)&&t<=Math.max(o.x,l.x)&&r>=Math.min(o.y,l.y)&&r<=Math.max(o.y,l.y)&&(t===o.x&&r===o.y||t===l.x&&r===l.y))return!0}return!1}canTraverse(e,t,i,r,a){this.charge(2),this.assertLease(e),e.guardCalls++;try{let e=t.x===i.x?this.x:this.y,n=t.x===i.x?t.x:t.y,o=Math.floor(n/128);if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(i.x)||!Number.isFinite(i.y)||t.x!==i.x&&t.y!==i.y||!e.enabled||!Number.isSafeInteger(o)){for(let e=0;e<this.rails.length;e++)if(this.blocked(t,i,this.rails[e],r,a))return!1;return!0}if(o<e.domainFirst||o>e.domainLast)return!0;let l=e.heads[o-e.domainFirst];for(;l;){if(this.blocked(t,i,l.peer,r,a))return!1;l=l.next}return!0}finally{e.guardCalls--}}};function S(e,t){let i=[],r=0,a=t=>{e(t),r+=t};return{get vertices(){return r},acquire(e,r){let n;if(!Number.isSafeInteger(e)||e<1)throw TypeError("Invalid sparse query capacity");for(let t of i)r(),!t.active&&t.capacity>=e&&(!n||t.capacity<n.capacity)&&(n=t);if(!n){let r=Math.min(32,e);for(;r<e;)r*=2;Number.isSafeInteger(r)||t("agentic local cross-hierarchy visibility-expansion limit"),a(r),n={active:!1,capacity:r,distance:new Float64Array(r),parents:new Int32Array(r),roots:new Int32Array(r),slots:new Int32Array(r),heapPages:new Map,reserveHeap:a},i.push(n)}return n.active=!0,n}}}function N(e,t,i,r,a,n,o,l,s,h,g=!1,c,d,f,y){o.pairs-=8,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit");let m=Math.max(e.x,Math.min(t.x-2*n,a.x-n)),u=Math.max(e.y,Math.min(t.y-2*n,a.y-n)),x=Math.min(e.x+e.width,Math.max(t.x+t.width+2*n,a.x+n)),p=Math.min(e.y+e.height,Math.max(t.y+t.height+2*n,a.y+n));return(x<=m||p<=u)&&s("cross-hierarchy route has no bounded clear corridor"),E({x:m,y:u,width:x-m,height:p-u},i,r,[a],n,o,l,s,h,g,c,d,f,y)}function E(t,i,r,a,n,o,s,h,g,c=!1,d,f,y,m){let u=t.x+t.width,x=t.y+t.height,b=0,M=e=>{b+e>s&&h("agentic local cross-hierarchy visibility-expansion limit"),g?.(e),b+=e},w=(e=1)=>{o.pairs-=e,o.pairs<0&&h("agentic local cross-hierarchy obstacle-work limit")},v=e=>e.x>=t.x&&e.x<=u&&e.y>=t.y&&e.y<=x,k=i.filter(e=>(w(),e.x<=u&&e.x+e.width>=t.x&&e.y<=x&&e.y+e.height>=t.y));w();let N=k.length>0;for(let e of k){w(8);let t=e.x+e.width,i=e.y+e.height;if(!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(t)||!Number.isFinite(i)||t<=e.x||i<=e.y){N=!1;break}}let I=[],P=new Map,A,F=e=>`${e.x},${e.y}`,Y=e=>{if(d)return!(A??=d()).containsPoint(e.x,e.y);for(let t of k)if(w(),e.x>t.x&&e.x<t.x+t.width&&e.y>t.y&&e.y<t.y+t.height)return!1;return!0},T=e=>{w(),Number.isFinite(e.x+e.y)||h("agentic local cross-hierarchy coordinate limit"),!v(e)||P.has(F(e))||!Y(e)||(M(1),P.set(F(e),I.length),I.push({...e}))},X=e=>{for(let t of[e.x,e.x+e.width])for(let i of[e.y,e.y+e.height])T({x:t,y:i})};for(let e of(X(t),k))X(e);for(let e=0;e<k.length;e++)for(let t=e+1;t<k.length;t++){w();let i=k[e],r=k[t];if(!(i.x>r.x+r.width||r.x>i.x+i.width||i.y>r.y+r.height||r.y>i.y+i.height))for(let[e,t]of[[i,r],[r,i]])for(let i of[e.x,e.x+e.width])for(let r of[t.y,t.y+t.height])w(),i>=t.x&&i<=t.x+t.width&&r>=e.y&&r<=e.y+e.height&&T({x:i,y:r})}for(let e of r)T(e.port),T(e.stub);for(let e of a)T(e);let C=new Set;for(let e of r)w(2),C.add(F(e.port)),C.add(F(e.stub));for(let e of a)w(),C.add(F(e));if(c&&k.length){let e=u,i=t.x,r=x,a=t.y;for(let n of k)w(8),e=Math.min(e,Math.max(t.x,n.x)),i=Math.max(i,Math.min(u,n.x+n.width)),r=Math.min(r,Math.max(t.y,n.y)),a=Math.max(a,Math.min(x,n.y+n.height));w(4);let n=(e,t)=>e+(t-e)/2,o=[...e>t.x?[n(t.x,e)]:[],...i<u?[n(i,u)]:[]],l=[...r>t.y?[n(t.y,r)]:[],...a<x?[n(a,x)]:[]],s=(e,t,i,r,a)=>{if(!y)return e;let o,l=a>e?1:-1;for(let[n,s]of y){w();let h=i?n.x:n.y;(i?n.x!==s.x:n.y!==s.y)||t<Math.min(i?n.y:n.x,i?s.y:s.x)||t>Math.max(i?n.y:n.x,i?s.y:s.x)||Math.abs(h-e)>.5||h<=Math.min(r,a)||h>=Math.max(r,a)||l*(a-h)<=0||(void 0===o||l*(h-o)>0)&&(o=h)}if(void 0===o)return e;let s=a;for(let[e,r]of y){w();let a=i?e.x:e.y;(i?e.x!==r.x:e.y!==r.y)||t<Math.min(i?e.y:e.x,i?r.y:r.x)||t>Math.max(i?e.y:e.x,i?r.y:r.x)||l*(a-o)<=0||l*(s-a)<=0||(s=a)}return n(o,s)};for(let n of o)for(let o of l){let l={x:s(n,o,!0,n<e?t.x:u,n<e?e:i),y:s(o,n,!1,o<r?t.y:x,o<r?r:a)};T(l),w(),C.add(F(l))}}let L=[],O=[],R=[],W=[],H=(e,t,i)=>{if(w(),e.x===t.x&&e.y===t.y)return;--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit");let r=e.y===t.y,a=r?{fixed:e.y,lower:Math.min(e.x,t.x),upper:Math.max(e.x,t.x)}:{fixed:e.x,lower:Math.min(e.y,t.y),upper:Math.max(e.y,t.y)};(r?L:O).push(a),i&&(r?R:W).push(a)},j=I.length,z;d&&(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),z={left:t.x,right:u,top:t.y,bottom:x});for(let e=0;e<j;e++){let i=I[e],r=t.x,a=u,n=t.y,o=x;if(z)(A??=d()).projectPoint(i.x,i.y,t,z),r=z.left,a=z.right,n=z.top,o=z.bottom;else for(let e of k)w(4),i.y>e.y&&i.y<e.y+e.height&&(e.x>=i.x&&(a=Math.min(a,e.x)),e.x+e.width<=i.x&&(r=Math.max(r,e.x+e.width))),i.x>e.x&&i.x<e.x+e.width&&(e.y>=i.y&&(o=Math.min(o,e.y)),e.y+e.height<=i.y&&(n=Math.max(n,e.y+e.height)));let l=C.has(F(i));for(let e of[{x:r,y:i.y},{x:a,y:i.y},{x:i.x,y:n},{x:i.x,y:o}])T(e),H(i,e,l)}let U=(e,t)=>(--o.swaps<0&&h("agentic local cross-hierarchy coordinate-sort limit"),e-t),V=e=>{let t=new Map;for(let i of e){w();let e=t.get(i.fixed)??[];e.push(i),t.set(i.fixed,e)}for(let[e,i]of t){i.sort((e,t)=>U(e.lower,t.lower)||U(e.upper,t.upper));let r=[];for(let e of i){w();let t=r.at(-1);t&&e.lower<=t.upper?t.upper=Math.max(t.upper,e.upper):(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),r.push({...e}))}t.set(e,r)}return{coordinates:[...t.keys()].sort(U),lines:t}},B=(e,t,i)=>{let r=V(t);for(let t of V(e).lines.values())for(let e of t){let t=0,a=r.coordinates.length;for(;t<a;){w();let i=Math.floor((t+a)/2);r.coordinates[i]<e.lower?t=i+1:a=i}for(let a=t;a<r.coordinates.length;a++){w();let t=r.coordinates[a];if(t>e.upper)break;for(let a of r.lines.get(t)){if(w(),a.lower>e.fixed)break;a.upper>=e.fixed&&T(i?{x:t,y:e.fixed}:{x:e.fixed,y:t})}}}return r},D=B(R,O,!0),_=B(W,L,!1),q;try{q=m?.acquire(I.length,w),N&&d&&(w(10),N=function(e,t){if(!e)return!1;let i=p.get(e);return!!i&&i.boxes===t&&Object.getOwnPropertyDescriptor(e,"containsPoint")?.value===i.containsPoint&&Object.getOwnPropertyDescriptor(e,"entersSegment")?.value===i.entersSegment&&Object.getOwnPropertyDescriptor(e,"projectPoint")?.value===i.projectPoint}(A,i));let t=q?void 0:I.map(()=>[]),r=(t,i)=>{if(d)return!(A??=d()).entersSegment(t.x,t.y,i.x,i.y);for(let r of k)if(w(),e(t,i,r))return!1;return!0};for(let e of[1,2]){let i=new Map;for(let a of(I.forEach((t,r)=>{w();let a=1===e?t.y:t.x,n=i.get(a)??[];n.push(r),i.set(a,n)}),i.values())){N&&w();let i=I[a[0]],n=N?(1===e?_:D).lines.get(1===e?i.y:i.x):void 0,l=0;a.sort((t,i)=>(--o.swaps<0&&h("agentic local cross-hierarchy coordinate-sort limit"),1===e?I[t].x-I[i].x:I[t].y-I[i].y));for(let i=1;i<a.length;i++){q?w():(o.arcs-=2,o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"));let s=a[i-1],g=a[i],c=1===e?I[s].x:I[s].y,d=1===e?I[g].x:I[g].y,f;for(;N&&(w(),!(!n||l>=n.length));){let e=n[l];if(w(),e.upper>=c){f=e;break}w(),l++}let y=!1;if(f&&(w(),f.lower<=c&&(w(),y=d<=f.upper)),!y&&!r(I[s],I[g]))continue;let m=Math.abs(I[s].x-I[g].x)+Math.abs(I[s].y-I[g].y);if(q){let t=4*s+(1===e?1:3),i=4*g+2*(1!==e);q.nodes[t]=g,q.distances[t]=m,q.nodes[i]=s,q.distances[i]=m}else t[s].push({node:g,axis:e,distance:m}),t[g].push({node:s,axis:e,distance:m})}}}let a=e=>P.get(F(e))??-1,s=3*I.length,g=f??S(M,h),c=!1,y=0;return{get vertices(){return b},retire(){if(!c){if(y)throw TypeError("Cannot retire a sparse graph during an active query");c=!0,q&&(q.active=!1)}},route(e,i,d=()=>!0,f=()=>!0){if(c)throw TypeError("Cannot query a retired sparse graph");y++;try{let c=a(i);c<0&&h("cross-hierarchy route has no clear anchor"),w(s);let y=g.acquire(s,w);try{let{distance:g,parents:m,roots:u,slots:x,heapPages:p}=y;g.fill(1/0,0,s),m.fill(-1,0,s),u.fill(-1,0,s),x.fill(-1,0,s);let b=0,k=e=>p.get(Math.floor(e/32))[e%32],S=(e,t)=>{let i=Math.floor(e/32),r=p.get(i);if(!r){let e=Math.min(32,y.capacity-32*i);y.reserveHeap(e),r=new Int32Array(e),p.set(i,r)}r[e%32]=t},N=e=>{let t=I[Math.floor(e/3)];return g[e]+Math.abs(t.x-i.x)+Math.abs(t.y-i.y)},E=(e,t)=>{--o.swaps<0&&h("agentic local cross-hierarchy heap-work limit");let i=N(e),r=N(t);return i<r||i===r&&e<t},P=(e,t)=>{let i=k(e);S(e,k(t)),S(t,i),x[k(e)]=e,x[k(t)]=t},A=e=>{let t=x[e];if(-2!==t)for(t<0&&(t=b,S(b++,e),x[e]=t);t>0;){let e=Math.floor((t-1)/2);if(!E(k(t),k(e)))break;P(t,e),t=e}},F=()=>{let e=k(0),t=k(--b);if(x[e]=-2,b){S(0,t),x[t]=0;let e=0;for(;;){let t=2*e+1;if(t>=b||(t+1<b&&E(k(t+1),k(t))&&t++,!E(k(t),k(e))))break;P(e,t),e=t}}return e};for(let t=0;t<e.length;t++){w();let i=e[t],n=a(i.stub);if(n<0||!v(i.port)||!Y(i.port)||!r(i.port,i.stub))continue;let o=i.port.x===i.stub.x?2:+(i.port.y===i.stub.y);if(!o)throw TypeError("Measured terminal lead must be orthogonal");if(!f(i.port,i.stub,o,o))continue;let l=3*n+o,s=Math.abs(i.stub.x-i.port.x)+Math.abs(i.stub.y-i.port.y)+i.penalty;s<g[l]&&(g[l]=s,u[l]=t,A(l))}for(;b;){let i=F(),r=Math.floor(i/3),a=i%3;if(r===c){let t=[],r=i;for(;m[r]>=0;)w(),t.push(I[Math.floor(r/3)]),r=m[r];t.push(I[Math.floor(r/3)],e[u[r]].port);let a=0,n;for(let e of t)w(),(!n||n.x!==e.x||n.y!==e.y)&&a++,n=e;M(a);let o=l(t.reverse());if(d(o))return o}let s=t?.[r];for(let t=0;t<(q?4:s.length);t++){let l,c,d;if(q){let e=4*r+t;if((l=q.nodes[e])<0){w();continue}c=t<2?1:2,d=q.distances[e]}else{let e=s[t];l=e.node,c=e.axis,d=e.distance}if(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),-1===m[i]){w();let t=e[u[i]],a=I[r],n=I[l],o=t.stub.x-t.port.x,s=t.stub.y-t.port.y;if(0!==o&&1===c&&Math.sign(n.x-a.x)===-Math.sign(o)||0!==s&&2===c&&Math.sign(n.y-a.y)===-Math.sign(s))continue}let y=3*l+c,p=g[i]+d+(a===c?0:2*n);-2!==x[y]&&p<g[y]&&f(I[r],I[l],a,c)&&(g[y]=p,m[y]=i,u[y]=u[i],A(y))}}return h("cross-hierarchy route has no bounded clear corridor")}finally{y.active=!1}}finally{y--}}}}catch(e){throw q&&(q.active=!1),e}}var I=class extends Error{},P=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}),A=(e,t,i)=>(t.x===i.x?1e-7>Math.abs(e.x-t.x):1e-7>Math.abs(e.y-t.y))&&e.x>=Math.min(t.x,i.x)&&e.x<=Math.max(t.x,i.x)&&e.y>=Math.min(t.y,i.y)&&e.y<=Math.max(t.y,i.y);function F(e,t,i,r,a=[.5,.25,.75]){let n="LR"===t?"E":"RL"===t?"W":"BT"===t?"N":"S",o=i?n:({N:"S",E:"W",S:"N",W:"E"})[n];return[o,...["N","E","S","W"].filter(e=>e!==o)].flatMap((t,i)=>a.map(a=>{let n="N"===t||"S"===t?{x:e.x+a*e.width,y:"N"===t?e.y:e.y+e.height}:{x:"W"===t?e.x:e.x+e.width,y:e.y+a*e.height},o={x:n.x+("E"===t?r:"W"===t?-r:0),y:n.y+("S"===t?r:"N"===t?-r:0)};return{port:n,stub:o,penalty:i*r*2+Math.abs(a-.5)*r}}))}function Y(e,t,i){for(let r=2;r<e.length;r++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let a=e[r-2],n=e[r-1],o=e[r];if(a.x===n.x&&n.x===o.x&&Math.sign(n.y-a.y)!==Math.sign(o.y-n.y)||a.y===n.y&&n.y===o.y&&Math.sign(n.x-a.x)!==Math.sign(o.x-n.x))return!0}for(let r=1;r<e.length;r++)for(let a=r+2;a<e.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=e[r-1],o=e[r],l=e[a-1],s=e[a];if(n.x===o.x&&l.x===s.x){if(n.x===l.x&&Math.min(Math.max(n.y,o.y),Math.max(l.y,s.y))>=Math.max(Math.min(n.y,o.y),Math.min(l.y,s.y)))return!0}else if(n.y===o.y&&l.y===s.y){if(n.y===l.y&&Math.min(Math.max(n.x,o.x),Math.max(l.x,s.x))>=Math.max(Math.min(n.x,o.x),Math.min(l.x,s.x)))return!0}else{let e=n.x===o.x?n.x:l.x,t=n.x===o.x?l.y:n.y;if(A({x:e,y:t},n,o)&&A({x:e,y:t},l,s))return!0}}return!1}function T(t,i,r,a,n,o,s,h,g,c=()=>!0,d=!1,f){let y=t.x+t.width,m=t.y+t.height,u={},x=()=>{if(h.pairs<=0)throw u;h.pairs--},p=(r,a=!0)=>{if(h.candidates<=0||h.pairs<=0)return;h.candidates--;let n=l(r);for(let e of n)if(!Number.isFinite(e.x+e.y)||e.x<t.x||e.x>y||e.y<t.y||e.y>m)return;if(!Y(n,s,g)){for(let t=1;t<n.length;t++){--s.arcs<0&&g("agentic local cross-hierarchy direct-arc limit");let r=n[t-1],a=n[t];if(f)try{if(f().entersSegment(r.x,r.y,a.x,a.y,x))return}catch(e){if(e===u)return;throw e}else for(let t of i)if(h.pairs<=0||(h.pairs--,--s.pairs<0&&g("agentic local cross-hierarchy direct-pair limit"),e(r,a,t)))return}return!a||c(n)?n:void 0}};if(d){let e=[];for(let t=0;t<3;t++)for(let i=0;i<4;i++){let a=r[3*i+t];p([a.port,a.stub],!1)&&e.push(a)}let t=t=>{if(!(h.pairs<=0||h.candidates<=0))for(let{port:i,stub:r}of e){let e=p([i,r,...t(r),a]);if(e)return e;if(h.pairs<=0||h.candidates<=0)return}};for(let e of[e=>[{x:a.x,y:e.y}],e=>[{x:e.x,y:a.y}]]){let i=t(e);if(i)return i}for(let e of n){let i=[e.x-2*o,e.x+e.width+2*o,e.x-o,e.x+e.width+o],r=[e.y-o,e.y+e.height+o];for(let e of i){let i=t(t=>[{x:e,y:t.y},{x:e,y:a.y}]);if(i)return i}for(let e of r){let i=t(t=>[{x:t.x,y:e},{x:a.x,y:e}]);if(i)return i}for(let e of i)for(let i of r){let r=t(t=>[{x:e,y:t.y},{x:e,y:i},{x:a.x,y:i}]);if(r)return r}if(h.pairs<=0||h.candidates<=0)break}return}for(let e=0;e<3;e++)for(let t=0;t<4;t++){let{port:i,stub:l}=r[3*t+e];if(!p([i,l],!1)){if(h.pairs<=0||h.candidates<=0)return;continue}for(let e of[{x:a.x,y:l.y},{x:l.x,y:a.y}]){let t=p([i,l,e,a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of n){let t=[e.x-o,e.x+e.width+o],r=[e.y-o,e.y+e.height+o];for(let e of t){let t=p([i,l,{x:e,y:l.y},{x:e,y:a.y},a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of r){let t=p([i,l,{x:l.x,y:e},{x:a.x,y:e},a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of t)for(let t of r){let r=p([i,l,{x:e,y:l.y},{x:e,y:t},{x:a.x,y:t},a]);if(r)return r;if(h.pairs<=0||h.candidates<=0)return}}}}var X=class{constructor(e){this.reason=e}reason};function C(e,t,i=1){e.arcs-=i,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit")}function L(e,t,i){i(),t.orthogonal=e.length>=2,t.minX=1/0,t.maxX=-1/0,t.minY=1/0,t.maxY=-1/0;for(let r=0;t.orthogonal&&r<e.length;r++){i(9);let a=e[r];if(!Number.isFinite(a.x)||!Number.isFinite(a.y)||r>0&&a.x!==e[r-1].x&&a.y!==e[r-1].y){t.orthogonal=!1;return}t.minX=Math.min(t.minX,a.x),t.maxX=Math.max(t.maxX,a.x),t.minY=Math.min(t.minY,a.y),t.maxY=Math.max(t.maxY,a.y)}}function O(e,t,i,r){if(!e?.orthogonal||!t?.orthogonal)return!1;i(void 0===r?8:20);let a=e.minX-t.maxX,n=t.minX-e.maxX,o=e.minY-t.maxY,l=t.minY-e.maxY,s=void 0===r?.5:Math.max(.5,r+(Math.abs(e.minX)+Math.abs(e.maxX)+Math.abs(e.minY)+Math.abs(e.maxY)+Math.abs(t.minX)+Math.abs(t.maxX)+Math.abs(t.minY)+Math.abs(t.maxY)+r)*1e-10+1e-9);return Number.isFinite(a)&&Number.isFinite(n)&&Number.isFinite(o)&&Number.isFinite(l)&&(a>s||n>s||o>s||l>s)}function R(e,t,i,a,o,l){let s=(e=1)=>{a.pairs-=e,a.pairs<0&&o("agentic local cross-hierarchy crossing-work limit")};void 0!==e.maximumEdgeStrokeWidth&&C(a,o,2*t.edges.length+3);let h=void 0===e.maximumEdgeStrokeWidth?void 0:e=>C(a,o,e),g=r(e),c=0,d=0,f=0,y=t.edges.map((t,i)=>{s();let r=t.points.length>=2;for(let e=0;r&&e<t.points.length;e++){s();let i=t.points[e];Number.isFinite(i.x)&&Number.isFinite(i.y)&&(!(e>0)||i.x===t.points[e-1].x||i.y===t.points[e-1].y)||(r=!1)}let a=!1!==e.edges[i].visible;return a&&(c+=Math.max(0,t.points.length-1),d+=t.points.length,f++),{...t,style:a?"solid":"invisible",orthogonal:r,covered:!1}}),m;if(void 0!==e.maximumEdgeStrokeWidth&&0===e.maximumEdgeBendRadius){for(let e of(C(a,o,i.size+y.length+1),m=[],i))s(),m.push(e);for(let t=0;t<y.length;t++)s(),!1!==e.edges[t].visible&&(s(),i.has(t)||m.push(t))}let u=m??i,x;if(c>=32){let t=0;for(let i of u)s(),l&&(s(),y[i].orthogonal&&!1!==e.edges[i].visible&&l.has(i))||(t=Math.max(t,y[i].points.length-1));let i=(g*t+1)*c,r=9*d+f+2*y.length+(void 0===e.maximumEdgeStrokeWidth?8:20)*f;if(Number.isSafeInteger(i)&&i>r){C(a,o,y.length),s(y.length),x=Array(y.length);for(let e=0;e<y.length;e++){s();let t=y[e];if("invisible"===t.style||!t.orthogonal)continue;C(a,o);let i={orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};L(t.points,i,s),x[e]=i}}}for(let t of u){let i=y[t],r=i.points,a=i.orthogonal&&!1!==e.edges[t].visible;if(l&&(s(),a&&l.has(t)))continue;let c=0;for(let i=0;i<y.length;i++){s();let r=y[i];l&&s(),r.style=!1===e.edges[i].visible||a&&(r.covered||r.orthogonal&&l?.has(i))?"invisible":"solid",x&&i!==t&&"invisible"!==r.style&&O(x[t],x[i],s,e.maximumEdgeStrokeWidth)&&(r.style="invisible"),i!==t&&"invisible"!==r.style&&(c+=Math.max(0,r.points.length-1))}s(g*Math.max(0,r.length-1)*c+r.length+c+y.length),void 0===n(r,t,y,e,s,h,void 0,g)&&o("cross-hierarchy routes have an uncertified shared contact"),a&&(i.covered=!0)}}function W(i,o,l,s,h,g,c,d,y,m,x,p,b=!1){(b||0===i.maximumEdgeBendRadius)&&function(e,t,i,r,a,n){for(let o=0;o<e.edges.length;o++)for(let l=0;l<2;l++){r.pairs-=10,r.pairs<0&&n("agentic marker endpoint work limit");let s=t.edges[o].points,h=e.edges[o],g=0===l;if(s.length<2)continue;let c=g?0:s.length-1,d=s[c],y=g?s[1]:s.at(-2),m=i[g?h.source:h.target],u,x;if(d.x===y.x&&d.y!==y.y)u="y",x=y.y>d.y?m.y+m.height:m.y;else{if(d.y!==y.y||d.x===y.x)continue;u="x",x=y.x>d.x?m.x+m.width:m.x}d[u]!==x&&(r.arcs-=10,r.pairs-=256,r.arcs<0&&n("agentic marker endpoint capacity limit"),r.pairs<0&&n("agentic marker endpoint work limit"),f(d[u])===f(x)&&(a(1),--r.arcs<0&&n("agentic marker endpoint capacity limit"),r.pairs-=3,r.pairs<0&&n("agentic marker endpoint work limit"),s[c]={x:d.x,y:d.y,[u]:x}))}}(i,o,h,c,d,y),c.arcs-=14,c.arcs<0&&y("agentic marker full-proof capacity limit");let M=(e=1)=>{c.pairs-=e,c.pairs<0&&y("agentic marker full-proof work limit")},w=e=>C(c,y,e),v=new Set;d(4);let k=0;for(let e=0;e<i.edges.length;e++)--c.pairs<0&&y("agentic marker full-proof work limit"),i.edges[e].label&&o.edges[e].labelPosition&&k++;c.arcs-=2*(l.length+s.length+k)+3,c.arcs<0&&y("agentic marker full-proof capacity limit");let S=[],N={x:0,y:0,width:o.width,height:o.height};for(let e=0;e<l.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=l[e],r=(i.nodes[e].paintStrokeWidth??0)/2;S.push({x:t.x-r,y:t.y-r,width:t.width+2*r,height:t.height+2*r})}for(let e=0;e<s.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=s[e],r=(i.groups[e].paintStrokeWidth??0)/2,a=g[e].headerHeight??g[e].padding.top;S.push({x:t.x-r,y:t.y-r,width:t.width+2*r,height:a+2*r})}for(let e=0;e<i.edges.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=i.edges[e].label,r=o.edges[e].labelPosition;t&&r&&S.push({x:r.x-t.width/2-2,y:r.y-t.height/2-2,width:t.width+4,height:t.height+4})}let E={x:0,y:0,width:0,height:0},I=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}],P=(t,a,d,f=!1)=>{let m=i.edges[t],u=o.edges[t];if(M(),f){if(a!==u.points||!1===m.visible||a.length<2)return!1;for(let e=0;e<a.length;e++){M(3);let t=a[e];if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||e&&t.x!==a[e-1].x&&t.y!==a[e-1].y)return!1}}else{if(Y(a,c,y))return!1;for(let e=0;e<a.length;e++){M();let t=a[e];if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||e&&t.x!==a[e-1].x&&t.y!==a[e-1].y)return!1}for(let e=0;e<2;e++){M(8);let t=0===e,i=h[t?m.source:m.target],r=t?a[0]:a.at(-1),n=t?a[1]:a.at(-2),o=t?u.points[0]:u.points.at(-1),l=t?u.points[1]:u.points.at(-2);if(Math.sign(n.x-r.x)!==Math.sign(l.x-o.x)||Math.sign(n.y-r.y)!==Math.sign(l.y-o.y)||Math.abs(n.x-r.x)+Math.abs(n.y-r.y)<Math.min(x,Math.abs(l.x-o.x)+Math.abs(l.y-o.y))||r.x<i.x||r.x>i.x+i.width||r.y<i.y||r.y>i.y+i.height||!(1e-7>Math.abs(r.x-i.x)&&n.y===r.y&&n.x<r.x||1e-7>Math.abs(r.x-i.x-i.width)&&n.y===r.y&&n.x>r.x||1e-7>Math.abs(r.y-i.y)&&n.x===r.x&&n.y<r.y||1e-7>Math.abs(r.y-i.y-i.height)&&n.x===r.x&&n.y>r.y))return!1}let r=!1;if(m.label){if(!u.labelPosition)return!1;for(let e=1;e<u.points.length;e++)if(M(),A(u.labelPosition,u.points[e-1],u.points[e])){r=!0;break}if(m.source!==m.target||r){let e=!1;for(let t=1;t<a.length;t++)if(M(),A(u.labelPosition,a[t-1],a[t])){e=!0;break}if(!e)return!1}}let n=(p??1)/2;for(let h=1;h<a.length;h++){let c=a[h-1],d=a[h];for(let t=0;t<l.length;t++){M(5);let r=l[t],o=t===m.source&&1===h||t===m.target&&h===a.length-1?0:n+(i.nodes[t].paintStrokeWidth??0)/2;if(E.x=r.x-o,E.y=r.y-o,E.width=r.width+2*o,E.height=r.height+2*o,e(c,d,E))return!1}for(let t=0;t<s.length;t++){M(5);let i=s[t],r=g[t].headerHeight??g[t].padding.top;if(E.x=i.x-n,E.y=i.y-n,E.width=i.width+2*n,E.height=r+2*n,r>0&&e(c,d,E))return!1}for(let a=0;a<i.edges.length;a++){M();let n=i.edges[a].label,l=o.edges[a].labelPosition;if(!(!n||!l)&&!(a===t&&r&&A(l,c,d))&&(M(4),E.x=l.x-n.width/2-2,E.y=l.y-n.height/2-2,E.width=n.width+4,E.height=n.height+4,e(c,d,E)))return!1}}}c.arcs-=2*o.edges.length+1,c.arcs<0&&y("agentic marker full-proof capacity limit"),M(3);let b=a===u.points&&!1!==m.visible,k=0,S=o.edges.map((e,r)=>{M();let a=!1!==i.edges[r].visible;return b&&a&&r!==t&&(M(2),v.has(r)&&(a=!1)),r!==t&&a&&(k+=Math.max(0,e.points.length-1)),{...e,style:a?"solid":"invisible"}});return M(r(i)*(a.length-1)*k+a.length+k),void 0!==n(a,t,S,i,M,w,d,r(i))};if(w(1),function(e,i,r,n,o,l,s,h,g,c,d=0,y,m){n.arcs-=18,n.arcs<0&&l("agentic marker seating capacity limit");let x=(e=1)=>{n.pairs-=e,n.pairs<0&&l("agentic marker seating work limit")},p=e=>{n.arcs-=e,n.arcs<0&&l("agentic marker seating capacity limit")},b=[],M=0;for(let t of e)x(),!1!==t.visible&&(M+=+!!t.markerPaint?.start?.length+ +!!t.markerPaint?.end?.length);let w=0,v=0;if(void 0!==c){if(!Number.isFinite(c)||c<=0||!Number.isFinite(d)||d<0)throw TypeError("Invalid measured marker carrier width");for(let t=0;t<i.length;t++){if(x(),!1===e[t].visible)continue;let r=i[t].points;x(2),2===r.length&&v++,w+=Math.max(0,r.length-1);for(let e=1;e+1<r.length;e++){x(4);let t=r[e-1],i=r[e],a=r[e+1];t.x===i.x!=(i.x===a.x)&&w++}}}let k=4*(M+w+4*v+(y?.obstacles.length??0))+8;p(k),x(k);let S=new Float64Array(k);p(2*w+2*i.length+9),o(4);let N=[],E=[],I=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}],P=(c??0)/2,A=(e,t,i)=>{x(13),Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&(t.x===i.x||t.y===i.y)||l("Unsupported measured marker carrier"),e.a=t,e.b=i;let r=P+(e.join?d:0);e.minX=Math.min(t.x,i.x)-r,e.maxX=Math.max(t.x,i.x)+r,e.minY=Math.min(t.y,i.y)-r,e.maxY=Math.max(t.y,i.y)+r},F=e=>{let t=E[e],r=i[e].points;t.minX=t.minY=1/0,t.maxX=t.maxY=-1/0,x(4);for(let e=t.begin;e<t.end;e++){let i=N[e];A(i,r[i.point],i.join?r[i.point]:r[i.point+1]),x(4),t.minX=Math.min(t.minX,i.minX),t.maxX=Math.max(t.maxX,i.maxX),t.minY=Math.min(t.minY,i.minY),t.maxY=Math.max(t.maxY,i.maxY)}};for(let t=0;t<i.length;t++){x();let r=N.length;if(void 0!==c&&!1!==e[t].visible)for(let e=1;e<i[t].points.length;e++)x(),N.push({current:!0,a:i[t].points[e-1],b:i[t].points[e],point:e-1,join:!1,minX:0,maxX:0,minY:0,maxY:0});if(void 0!==c&&!1!==e[t].visible)for(let e=1;e+1<i[t].points.length;e++){x(4);let r=i[t].points[e-1],a=i[t].points[e],n=i[t].points[e+1];r.x===a.x!=(a.x===n.x)&&N.push({current:!0,a:a,b:a,point:e,join:!0,minX:0,maxX:0,minY:0,maxY:0})}E.push({begin:r,end:N.length,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0}),F(t)}p(1);let Y=(e,t)=>{let i=E[e],r=N.length;p(10);for(let e=0;e<3;e++)x(),N.push({current:!0,a:t[e],b:t[e+1],point:e,join:!1,minX:0,maxX:0,minY:0,maxY:0});for(let e=1;e<3;e++)x(),N.push({current:!0,a:t[e],b:t[e],point:e,join:!0,minX:0,maxX:0,minY:0,maxY:0});for(let e=i.begin;e<i.end;e++)x(),N[e].current=!1;i.begin=r,i.end=N.length},T=(e,t)=>(x(5),e.maxX>t.minX&&e.minX<t.maxX&&e.maxY>t.minY&&e.minY<t.maxY),X=(e,t)=>{if(!T(e,t))return!1;let i=t.a,r=t.b,a=I[0].points;return x(8),t.join?(a[0].x=t.minX,a[0].y=t.minY,a[1].x=t.maxX,a[1].y=t.minY,a[2].x=t.maxX,a[2].y=t.maxY,a[3].x=t.minX,a[3].y=t.maxY):i.x===r.x?(a[0].x=t.minX,a[0].y=Math.min(i.y,r.y),a[1].x=t.maxX,a[1].y=a[0].y,a[2].x=t.maxX,a[2].y=Math.max(i.y,r.y),a[3].x=t.minX,a[3].y=a[2].y):(a[0].x=Math.min(i.x,r.x),a[0].y=t.minY,a[1].x=Math.max(i.x,r.x),a[1].y=t.minY,a[2].x=a[1].x,a[2].y=t.maxY,a[3].x=a[0].x,a[3].y=t.maxY),u(e.pieces,I,x)},C=1;for(let e of E)x(4),e.begin<e.end&&(C=Math.max(C,Math.abs(e.minX),Math.abs(e.maxX),Math.abs(e.minY),Math.abs(e.maxY)));for(let e of r)x(4),C=Math.max(C,Math.abs(e.x),Math.abs(e.y),Math.abs(e.x+e.width),Math.abs(e.y+e.height));y&&(x(4),C=Math.max(C,Math.abs(y.bounds.x),Math.abs(y.bounds.y),Math.abs(y.bounds.x+y.bounds.width),Math.abs(y.bounds.y+y.bounds.height)));let L=(C+Math.abs(c??0))*1e-10+1e-9,O=void 0===c?0:(p(5),x(128),Number(f(c))),R=(e,t)=>{if(void 0===c||t.join)return!0;let i=t.a,r=t.b,n=i.x===r.x;n?i.x:i.y,n?i.y:i.x,n?r.y:r.x,n?i.y:i.x,n?r.y:r.x;for(let n=0;n<E.length;n++){if(x(),n===e)continue;let o=E[n];if(x(5),!(t.maxX<o.minX-L||t.minX>o.maxX+L||t.maxY<o.minY-L||t.minY>o.maxY+L))for(let e=o.begin;e<o.end;e++){x();let t=N[e];if(!t.join&&function(e,t,i,r,n,o,l,s){l();let h=e.x===t.x;if(i.x===r.x!==h)return!1;l(2);let g=h?e.x:e.y,c=h?i.x:i.y,d=(Math.abs(g)+Math.abs(c)+Math.abs(n))*1e-10+1e-9;if(Math.abs(g-c)>n+d)return!1;l(2);let y=Math.min(h?e.y:e.x,h?t.y:t.x),m=Math.max(h?e.y:e.x,h?t.y:t.x),u=Math.min(h?i.y:i.x,h?r.y:r.x),x=Math.max(h?i.y:i.x,h?r.y:r.x),p=(Math.abs(y)+Math.abs(m)+Math.abs(u)+Math.abs(x))*1e-10+1e-9;if(Math.min(m,x)<Math.max(y,u)-p)return!1;s(42),l(384);let b=a(f(g),f(c),f(o),l);if(!0!==b)return void 0===b;s(20),l(512);let M=Number(f(h?e.y:e.x)),w=Number(f(h?t.y:t.x)),v=Number(f(h?i.y:i.x)),k=Number(f(h?r.y:r.x));return Math.min(Math.max(M,w),Math.max(v,k))>Math.max(Math.min(M,w),Math.min(v,k))}(i,r,t.a,t.b,c,O,x,p))return!1}}return!0},W={current:!0,a:void 0,b:void 0,point:0,join:!1,minX:0,maxX:0,minY:0,maxY:0},H=(e,t,i,r,a)=>{x(10),Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(i.x)&&Number.isFinite(i.y)||l("Nonfinite measured marker normal");let n=Math.sign(i.x-t.x),s=Math.sign(i.y-t.y);+!n+ +!s!=1&&l("Nonorthogonal measured marker normal");let h=0;for(let t of e)x(),"polygon"===t.kind&&(h+=t.points.length);p(2+2*e.length+h),o(h);let g={owner:r,source:a,pieces:[],minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let i of e)if(x(),"circle"===i.kind){let e=t.x+n*i.cx-s*i.cy,r=t.y+s*i.cx+n*i.cy;g.pieces.push({kind:"circle",cx:e,cy:r,r:i.r}),g.minX=Math.min(g.minX,e-i.r),g.maxX=Math.max(g.maxX,e+i.r),g.minY=Math.min(g.minY,r-i.r),g.maxY=Math.max(g.maxY,r+i.r)}else{let e={kind:"polygon",points:[]};for(let r of i.points){x();let i=t.x+n*r.x-s*r.y,a=t.y+s*r.x+n*r.y;e.points.push({x:i,y:a}),g.minX=Math.min(g.minX,i),g.maxX=Math.max(g.maxX,i),g.minY=Math.min(g.minY,a),g.maxY=Math.max(g.maxY,a)}g.pieces.push(e)}return g};p(M+1);let j=[];for(let t=0;t<e.length;t++)if(x(),!1!==e[t].visible)for(let r=0;r<2;r++){x();let a=0===r?e[t].markerPaint?.start:e[t].markerPaint?.end;if(!a?.length)continue;let n=i[t].points,o=0===r;j.push(H(a,o?n[0]:n.at(-1),o?n[1]:n.at(-2),t,o))}let z=(e,t,r)=>{if(g&&!g(t,r,e.pieces,e))return!1;if(void 0!==c)for(let a=0;a<E.length;a++){x();let n=E[a];if(T(e,n))for(let o=n.begin;o<n.end;o++){x();let n=N[o];if(!(a===t&&(n.join?n.point===(r?1:i[t].points.length-2):r?n.point<=1:n.point>=i[t].points.length-3))&&X(e,n))return!1}}for(let t of b)if(x(5),!(e.maxX<=t.minX||e.minX>=t.maxX||e.maxY<=t.minY||e.minY>=t.maxY)&&u(e.pieces,t.pieces,x))return!1;return!0},U=0;p(3*e.length+2),x(3*e.length);let V=new Uint8Array(3*e.length),B=(r,a,n,l,g,c,f=-1,y,m=-1)=>{let u=!1;for(let b=0;b<E.length&&!u&&U<8;b++){if(x(),y?b!==m:0===g&&b===r)continue;let M=E[b],w=i[b].points;for(let m=M.begin;m<M.end&&!u&&U<8;m++){x(8);let v=N[m],k=v.point;if(v.join||k<1||k+2>=w.length)continue;let I=w[k],Y=w[k+1],T=w[k-1],C=w[k+2],L=I.y===Y.y,O=!1;if(y){x(5);let e=b===f?y.candidateSegment:y.peerSegment;O=e>=k&&e<=k+2}else{if(L!==l)continue;x(4);let e=b===r;if(O=!(e&&(a?k<=1:k>=w.length-3))&&X(n,v),0===g&&!O)continue;for(let t=0;t<2&&!O;t++){x(8);let i=N[M.begin+k+(0===t?-1:1)];e&&(a?i.point<=1:i.point>=w.length-3)||X(n,i)&&(O=!0)}if(!O){x(3);let t=M.begin+w.length-1,i=M.end;for(;t<i;){x(3);let e=t+Math.floor((i-t)/2);N[e].point<k?t=e+1:i=e}for(let i=t;i<M.end&&!O;i++){x(8);let t=N[i];if(t.point>k+1)break;e&&t.point===(a?1:w.length-2)||X(n,t)&&(O=!0)}}}if(!O)continue;let H=L?Math.min(I.x,Y.x):Math.min(I.y,Y.y),z=L?Math.max(I.x,Y.x):Math.max(I.y,Y.y);if(L?T.x!==I.x||C.x!==Y.x:T.y!==I.y||C.y!==Y.y)continue;let V=e[b].label,B=V?i[b].labelPosition:void 0,D=!1,_=!1;if(B&&0===g){let e=!1;for(let i=k-1;i<=k+1;i++)if(x(6),t(B,w[i],w[i+1])){e=!0;break}if(e)continue}else if(B){if(x(18),t(B,I,Y))continue;D=t(B,T,I),_=t(B,Y,C)}let q=L?I.y:I.x,$=L?T.y:T.x,Q=L?C.y:C.x,G=L?c.bounds.y:c.bounds.x,J=G+(L?c.bounds.height:c.bounds.width);if(q===$||q===Q)continue;if(q>$?G=Math.max(G,$):J=Math.min(J,$),q>Q?G=Math.max(G,Q):J=Math.min(J,Q),B&&V&&(D||_)){if(x(),0!==d)continue;x(6);let e=L?B.y:B.x,t=(L?V.height:V.width)/2+2+P,i=e-t,r=e+t,a=!1;for(let e=0;e<2;e++){if(x(12),0===e?!D:!_)continue;let t=0===e?$:Q;if(i<Math.min(t,q)||r>Math.max(t,q)){a=!0;break}if(t<=i)G=Math.max(G,r);else if(t>=r)J=Math.min(J,i);else{a=!0;break}}if(a)continue}if(!(G<J))continue;let K=2;S[0]=G,S[1]=0,S[2]=J,S[3]=0,p(1);let Z=(e,t)=>{x(2),(e=Math.max(G,e))<(t=Math.min(J,t))&&(S[2*K]=e,S[2*K+1]=1,S[2*++K]=t,S[2*K+1]=-1,K++)};if(y){x(12);let e=b===f?y.peerIndex:f,t=b===f?y.peerSegment:y.candidateSegment,i=N[E[e].begin+t-1];Z((L?i.minY:i.minX)-P-.01,(L?i.maxY:i.maxX)+P+.01)}for(let e of c.obstacles)x(5),(L?e.x+e.width+P<H||e.x-P>z:e.y+e.height+P<H||e.y-P>z)||Z((L?e.y:e.x)-P,(L?e.y+e.height:e.x+e.width)+P);for(let e of j)x(5),(L?e.maxX+P<H||e.minX-P>z:e.maxY+P<H||e.minY-P>z)||Z((L?e.minY:e.minX)-P-.01,(L?e.maxY:e.maxX)+P+.01);for(let e=0;e<N.length;e++){x(5);let t=N[e];!t.current||e===m||t.join||t.a.y===t.b.y!==L||(L?t.maxX<H||t.minX>z:t.maxY<H||t.minY>z)||Z((L?t.minY:t.minX)-P-.01,(L?t.maxY:t.maxX)+P+.01)}for(let e=1;e<K;e++){let t=S[2*e],i=S[2*e+1],r=e;for(;r>0&&(x(),!(S[2*(r-1)]<=t));)S[2*r]=S[2*(r-1)],S[2*r+1]=S[2*(r-1)+1],r--;S[2*r]=t,S[2*r+1]=i}let ee=-1,et=-1;for(let e=0;e<8&&U<8;e++){let e=0,t=-1,r=1/0,a=0;for(let i=1;i<K;i++){x(3),e+=S[2*(i-1)+1];let n=S[2*(i-1)],o=S[2*i],l=n+(o-n)/2,s=Math.abs(l-q);0!==e||!(n<o)||l===q||s<ee||s===ee&&i<=et||s<r&&(t=i,r=s,a=l)}if(t<0)break;ee=r,et=t,U++,p(w.length+1),o(2),x(w.length);let n=w.slice(),l={x:I.x,y:I.y},g={x:Y.x,y:Y.y};L?l.y=g.y=a:l.x=g.x=a,n[k]=l,n[k+1]=g;let c=!0;for(let e=k-1;e<=k+1&&c;e++){if(A(W,n[e],n[e+1]),!R(b,W)){c=!1;break}for(let t of j)if(x(2),!(e!==k&&t.owner===b&&(t.source?e<=1:e>=w.length-3))&&X(t,W)){c=!1;break}if(!c)break;if(e!==k){x(6);let t=e===k-1?T:C,i=e===k-1?I:Y,r=e===k-1?l:g,a=Math.abs(i.x-t.x)+Math.abs(i.y-t.y);if(Math.abs(r.x-t.x)+Math.abs(r.y-t.y)>a){for(let t of(A(W,i,r),j))if(x(4),!(t.owner===b&&(t.source?0===e:e===w.length-2))&&t.owner===b&&(t.source?e<=1:e>=w.length-3)&&X(t,W)){c=!1;break}}}}x(4);for(let e=Math.max(1,k-1);e<=Math.min(n.length-2,k+2)&&c;e++){x(4);let t=n[e-1],i=n[e],r=n[e+1];if(t.x===i.x!=(i.x===r.x)){for(let t of(W.join=!0,A(W,i,i),j))if(x(),(t.owner!==b||e===k||e===k+1||e!==(t.source?1:w.length-2))&&X(t,W)){c=!1;break}W.join=!1}}if(!(!c||!s(b,n))){i[b].points=n,F(b),h(b),u=!0;break}}}}return u},D=0;for(let a=0;a<e.length;a++){x();let n=e[a];if(!1!==n.visible)e:for(let e=0;e<2;e++){x();let g=0===e?n.markerPaint?.start:n.markerPaint?.end;if(!g?.length)continue;let m=i[a].points,u=0===e,M=u?m[0]:m.at(-1),w=u?m[1]:m.at(-2),v=j[D++];if(U=0,!z(v,a,u)){let k=r[u?n.source:n.target],I=w.x===M.x,T=I?k.x:k.y,C=T+(I?k.width:k.height),L=I?M.x:M.y,O=(I?v.minX:v.minY)-L,_=(I?v.maxX:v.maxY)-L;for(let L=0;L<2;L++){if(x(),void 0!==c&&y){do{if(x(3),!B(a,u,v,I,L,y))break;if(x(4),m=i[a].points,M=u?m[0]:m.at(-1),w=u?m[1]:m.at(-2),z(v,a,u)){p(1),b.push(v),x(),V[2*a+e]=U;continue e}}while(1===L&&U<8)}let q=2;for(let e of(S[0]=T,S[1]=0,S[2]=C,S[3]=0,b)){if(x(6),I?v.maxY<=e.minY||v.minY>=e.maxY:v.maxX<=e.minX||v.minX>=e.maxX)continue;let t=Math.max(T,(I?e.minX:e.minY)-_-.01),i=Math.min(C,(I?e.maxX:e.maxY)-O+.01);t<i&&(S[2*q]=t,S[2*q+1]=1,S[2*++q]=i,S[2*q+1]=-1,q++)}if(void 0!==c)for(let e=0;e<E.length;e++){if(x(),e===a)continue;let t=E[e];if(!(I?v.maxY<=t.minY||v.minY>=t.maxY:v.maxX<=t.minX||v.minX>=t.maxX))for(let e=t.begin;e<t.end;e++){x(6);let t=N[e];if(I?v.maxY<=t.minY||v.minY>=t.maxY:v.maxX<=t.minX||v.minX>=t.maxX)continue;let i=Math.max(T,(I?t.minX:t.minY)-_-.01),r=Math.min(C,(I?t.maxX:t.maxY)-O+.01);i<r&&(S[2*q]=i,S[2*q+1]=1,S[2*++q]=r,S[2*q+1]=-1,q++)}}for(let e=1;e<q;e++){let t=S[2*e],i=S[2*e+1],r=e;for(;r>0&&(x(),!(S[2*(r-1)]<=t));)S[2*r]=S[2*(r-1)],S[2*r+1]=S[2*(r-1)+1],r--;S[2*r]=t,S[2*r+1]=i}let $=!1,Q=1/0,G=-1,J=-1;for(let e=0;e<8&&U<8;e++){let e=-1,l=0,y=2,N=0;for(let t=1;t<q;t++){x(2),N+=S[2*(t-1)+1];let i=S[2*t]-S[2*(t-1)],r=+(0!==N),a=r>J||r===J&&(i<Q||i===Q&&t>G);i>0&&a&&(r<y||r===y&&i>l)&&(l=i,e=t,y=r)}if(e<0)break;let E=S[2*(e-1)]+l/2;Q=l,G=e,J=y,U++;let T=2===m.length;x(3);let C=0;if(T){let e=I?M.y:M.x,r=I?w.y:w.x,o=Math.sign(r-e),l=o>0?(I?v.maxY:v.maxX)-e:e-(I?v.minY:v.minX),s=0;for(let e of j)x(5),e.owner===a&&e.source!==u&&(s=Math.max(s,o>0?r-(I?e.minY:e.minX):(I?e.maxY:e.maxX)-r));x(10);let h=P+d,g=Math.min(8,Math.abs(r-e)),c=e+o*Math.max(g,l+h),f=r-o*Math.max(g,s+h);if(n.label){x(9);let e=i[a].labelPosition;if(!e||!t(e,M,w))continue;let r=I?e.y:e.x,l=(I?n.label.height:n.label.width)/2+2+P;f=o>0?Math.min(f,r-l):Math.max(f,r+l)}if(!(o*(f-c)>0))continue;C=c+(f-c)/2}p((T?4:m.length)+1),o(T?4:3),x(m.length+6);let L={x:M.x,y:M.y},O={x:w.x,y:w.y};I?(L.x=E,O.x=E,T&&(O.y=C),1e-7>Math.abs(L.y-k.y)?L.y=k.y:1e-7>Math.abs(L.y-k.y-k.height)&&(L.y=k.y+k.height)):(L.y=E,O.y=E,T&&(O.x=C),1e-7>Math.abs(L.x-k.x)?L.x=k.x:1e-7>Math.abs(L.x-k.x-k.width)&&(L.x=k.x+k.width));let V=T?u?[L,O,I?{x:w.x,y:C}:{x:C,y:w.y},w]:[w,I?{x:w.x,y:C}:{x:C,y:w.y},O,L]:m.slice();V[u?0:V.length-1]=L,V[u?1:V.length-2]=O;let B=u?V.length-1:0,_=u?V.length-2:1,K=V[B],Z={x:K.x,y:K.y},ee=r[u?n.target:n.source];if(V[_].x===Z.x?1e-7>Math.abs(Z.y-ee.y)?Z.y=ee.y:1e-7>Math.abs(Z.y-ee.y-ee.height)&&(Z.y=ee.y+ee.height):V[_].y===Z.y&&(1e-7>Math.abs(Z.x-ee.x)?Z.x=ee.x:1e-7>Math.abs(Z.x-ee.x-ee.width)&&(Z.x=ee.x+ee.width)),(Z.x!==K.x||Z.y!==K.y)&&(p(16),x(256),f(Z.x)!==f(K.x)||f(Z.y)!==f(K.y)))continue;V[B]=Z;let et=H(g,L,O,a,u);if(!z(et,a,u))continue;let ei=!0,er=!1;if(void 0!==c){for(let e=1;e<V.length;e++)if(x(),!(!T&&!er&&(u?e>2&&e!==V.length-1:e<V.length-2&&1!==e))){if(A(W,V[e-1],V[e]),!R(a,W)){if(x(5),!er&&!T&&2===e&&4===V.length&&!n.label&&0===d){let t=V[_],i=I?L.y:L.x,r=I?O.y:O.x,n=I?Z.y:Z.x,l=Math.sign(r-i);if(x(6),(I?t.y===r&&t.x===Z.x:t.x===r&&t.y===Z.y)&&l*(n-r)>0){x(10);let s=l>0?(I?et.maxY:et.maxX)-i:i-(I?et.minY:et.minX),h=Math.min(8,Math.abs(r-i)),g=Math.min(8,Math.abs(n-r)),d=0;for(let e of j)x(5),e.owner===a&&e.source!==u&&(d=Math.max(d,l>0?n-(I?e.minY:e.minX):(I?e.maxY:e.maxX)-n));x(8);let f=i+l*Math.max(h,s+P),y=n-l*Math.max(g,d+P),m=r-l*c,b=l>0?Math.min(y,m):Math.max(y,m);if(l*(b-f)>0){x(4);let i=f+(b-f)/2;p(2),o(1);let r={x:t.x,y:t.y};I?O.y=r.y=i:O.x=r.x=i,V[_]=r,er=!0,e=0;continue}}}ei=!1;break}for(let t of T||er?j:b){x(er?4:3);let i=er&&t.owner===a&&t.source===u?et:t;if(!(i.owner===a&&(T||er?i.source?1===e:e===V.length-1:i.source?e<=2:e>=V.length-2))&&X(i,W)){ei=!1;break}}if(!ei)break}}if(ei&&void 0!==c)for(let e=1;e+1<V.length;e++){if(x(),!T&&!er&&(u?e>2&&e!==V.length-2:e<V.length-3&&1!==e))continue;let t=V[e-1],i=V[e],r=V[e+1];if(x(4),t.x===i.x!=(i.x===r.x)){for(let t of(W.join=!0,A(W,i,i),W.join=!1,W.join=!0,T||er?j:b)){x(er?4:3);let i=er&&t.owner===a&&t.source===u?et:t;if(!(!T&&!er&&i.owner===a&&(i.source?1===e:e===V.length-2))&&X(i,W)){ei=!1;break}}if(W.join=!1,!ei)break}}if(!(!ei||!s(a,V))){T&&void 0!==c&&Y(a,V),i[a].points=V,void 0!==c&&F(a),v=et,j[D-1]=et,h(a),$=!0;break}}if(!$){if(0===L)continue;l("No physically clear measured marker seat at occurrence "+a+" role "+e)}break}}p(1),b.push(v),x(),V[2*a+e]=U}}if(m&&y&&void 0!==c&&0===d){p(1);let t={candidateSegment:-1,peerIndex:-1,peerSegment:-1};for(let r=0;r<i.length;r++)if(x(),!1!==e[r].visible)for(;m(r,t);){let i=!1;for(let a=0;a<2&&!i;a++){x(3);let n=0===a?r:t.peerIndex,o=e[n].markerPaint,l=!!(o?.start?.length||o?.end?.length);for(let a=0;a<(l?2:1)&&!i;a++){if(x(4),l&&!(0===a?o?.start?.length:o?.end?.length))continue;let s=l?2*n+a:2*e.length+n;(U=V[s])>=8||(i=B(n,0===a,void 0,!1,1,y,r,t,n),x(),V[s]=U)}}i||l("No physically clear measured sharp contact repair at occurrence "+r)}}}(i.edges,o.edges,h,c,d,y,P,e=>{M(2),v.has(e)||(--c.arcs<0&&y("agentic marker full-proof capacity limit"),v.add(e)),m.has(e)||(c.arcs--,c.arcs<0&&y("agentic marker full-proof capacity limit"),m.add(e))},(e,t,r,a)=>{c.arcs--,c.arcs<0&&y("agentic marker full-proof capacity limit");let n=(e,t,i,n)=>{if(M(5),a.maxX<=e||a.minX>=e+i||a.maxY<=t||a.minY>=t+n)return!0;M(8);let o=I[0].points;return o[0].x=e,o[0].y=t,o[1].x=e+i,o[1].y=t,o[2].x=e+i,o[2].y=t+n,o[3].x=e,o[3].y=t+n,!u(r,I,M)},h=t?i.edges[e].source:i.edges[e].target;for(let e=0;e<l.length;e++){if(M(),e===h)continue;let t=l[e],r=(i.nodes[e].paintStrokeWidth??0)/2;if(!n(t.x-r,t.y-r,t.width+2*r,t.height+2*r))return!1}for(let e=0;e<s.length;e++){M();let t=s[e],r=g[e].headerHeight??g[e].padding.top,a=(i.groups[e].paintStrokeWidth??0)/2;if(r>0&&!n(t.x-a,t.y-a,t.width+2*a,r+2*a))return!1}for(let e=0;e<i.edges.length;e++){M();let t=i.edges[e].label,r=o.edges[e].labelPosition;if(t&&r&&!n(r.x-t.width/2-2,r.y-t.height/2-2,t.width+4,t.height+4))return!1}return!0},p,i.maximumEdgeBendRadius??0,{bounds:N,obstacles:S},0===i.maximumEdgeBendRadius?(e,t)=>(M(5),t.candidateSegment=t.peerIndex=t.peerSegment=-1,!v.has(e)&&(P(e,o.edges[e].points,t,!b)?(w(1),v.add(e),!1):(M(6),(t.peerIndex<0||t.peerIndex>=o.edges.length||t.peerIndex===e||t.candidateSegment<1||t.candidateSegment>=o.edges[e].points.length||t.peerSegment<1||t.peerSegment>=o.edges[t.peerIndex].points.length)&&y("Measured final route violates its owned path or contact reservation"),!0))):void 0),b)for(let e=0;e<o.edges.length;e++)M(2),v.has(e)||(P(e,o.edges[e].points)||y("Measured final route violates its owned path or contact reservation"),--c.arcs<0&&y("agentic marker full-proof capacity limit"),v.add(e));return v}function H(e,t=!1){return(t&&!e.label?1:2)*e.minSpan}function j(e,t){let i=new Uint8Array(e.length),r=new Uint32Array(e.length),a=new Int32Array(e.length),n=[],o=e.length-1;for(let l=0;l<e.length;l++)if(!i[l])for(i[l]=1,n.push(l);n.length;){let l=n.at(-1);if(r[l]<e[l].length){let a=t[e[l][r[l]]];r[l]=r[l]+1,i[a.target]||(i[a.target]=1,n.push(a.target))}else n.pop(),i[l]=2,a[l]=o--}return a}function z(e,t,i){let r=e.length,a=i.length,n=new Int32Array(2*a+1).fill(-1),o=new Int32Array(r).fill(-1),l=new Int32Array(r).fill(-1),s=Uint32Array.from(e,e=>e.length),h=Uint32Array.from(t,e=>e.length),g=new Uint8Array(r).fill(1),c=new Int32Array(r),d=[],f=[],y=0,m=0,u=r-1,x=e=>a+h[e]-s[e],p=e=>{let t=x(e),i=n[t];l[e]=-1,o[e]=i,i>=0&&(l[i]=e),n[t]=e,y=Math.max(y,t)},b=e=>{let t=l[e],i=o[e];t>=0?o[t]=i:n[x(e)]=i,i>=0&&(l[i]=t)},M=r=>{for(let t of(b(r),g[r]=0,e[r])){let e=i[t].source;g[e]&&(b(e),h[e]=h[e]-1,p(e),0===h[e]&&f.push(e))}for(let e of t[r]){let t=i[e].target;g[t]&&(b(t),s[t]=s[t]-1,p(t),0===s[t]&&d.push(t))}};for(let e=r-1;e>=0;e--)p(e),s[e]||d.push(e),h[e]||f.push(e);for(;m<=u;){for(;f.length;){let e=f.pop();g[e]&&(c[e]=u--,M(e))}for(;d.length;){let e=d.pop();g[e]&&(c[e]=m++,M(e))}if(m>u)break;for(;y>=0&&-1===n[y];)y--;let e=n[y];if(void 0===e||e<0)throw TypeError("Feedback ordering lost an active vertex");c[e]=m++,M(e)}return c}var U=class extends Error{};function V(e,t){return Number.isFinite(e)&&(t?e>0:e>=0)}function B(e,t,i,r,a,n){if(t.length>16||t.length+e.junctions.length+e.groups.length>24||i.length>32||e.alignments.length||e.edges.some(e=>void 0!==e.label||"group"===e.source.boundary||"group"===e.target.boundary))return i;let o=8;if(1!==g(i)||n(i))return i;for(let e=0;e<t.length&&o>0;e++){let l=t[e];for(let s=e+1;s<t.length&&o>0;s++){let e=t[s];if(l.parentId===e.parentId&&l.width===e.width&&l.height===e.height)for(let t of["x","y"]){if(o<=0||l[t]===e[t])continue;o--;let s=l[t];if(l[t]=e[t],e[t]=s,a()){let e=r();if(0===g(e)&&!n(e)&&e.every((e,t)=>e.obstacleFree&&(!i[t].sourceFacesTarget||e.sourceFacesTarget)&&(!i[t].targetFacesSource||e.targetFacesSource)))return e}e[t]=l[t],l[t]=s}}}return i}var D=class{#e=new Map;#t=0;#i;constructor(e){this.#i=e}get(e){let t=this.#e.get(e);if(t)return this.#e.delete(e),this.#e.set(e,t),t.value}set(e,t,i){if(i>this.#i)return;let r=this.#e.get(e);for(r&&(this.#e.delete(e),this.#t-=r.weight),this.#e.set(e,{value:t,weight:i}),this.#t+=i;this.#e.size>64||this.#t>this.#i;){let e=this.#e.keys().next().value;this.#t-=this.#e.get(e).weight,this.#e.delete(e)}}},_=globalThis,q=(_.process?.env?.AGENTIC_MERMAID_ELK_CACHE??_.AGENTIC_MERMAID_ELK_CACHE)!=="0";function $(e){return JSON.stringify(e,(e,t)=>void 0===t?"\0undefined":"number"!=typeof t||Number.isFinite(t)?"string"==typeof t&&t.startsWith("\0")?`\0${t}`:t instanceof Map?{mapEntries:[...t]}:t instanceof Set?{setValues:[...t]}:t:`\0${t}`)}var Q=new WeakMap,G=new WeakMap;function J(e){let t=new D(8388608);return i=>{if(!q)return e(i);let r=$(i);if(r.length>1048576)return e(i);let a=t.get(r);if(a)return structuredClone(a);let n=e(i),o=2*r.length+4*JSON.stringify(n).length+512;return o<=8388608&&t.set(r,structuredClone(n),o),n}}function K(a,h,c,d){let f=d,m=G.get(a);try{if(m&&d&&d!==m){m.pairs-=24;let e=d.pairs,t=d.arcs,i=d.swaps;m.pairs=Math.min(m.pairs,e-(1e6-m.pairs)),m.arcs=Math.min(m.arcs,t-(65536-m.arcs)),m.swaps=Math.min(m.swaps,i-(1e6-m.swaps)),(!Number.isFinite(m.pairs)||!Number.isFinite(m.arcs)||!Number.isFinite(m.swaps)||m.pairs<0||m.arcs<0||m.swaps<0)&&c("agentic marker preparation work limit")}d=G.get(a)??d??{pairs:1e6,arcs:65536,swaps:1e6};let f=function a(h,c,d,f={pairs:1e6,arcs:65536,swaps:1e6},m={attempts:128,scorePairs:8e6,loopPairs:2e6,rankPairs:2e5,blockPairs:2e6,routing:{pairs:5e5,arcs:32768,swaps:5e5}}){let{nodes:u,edges:x,padding:p,nodeSpacing:B,layerSpacing:D}=h;if((u.length>4096||x.length>16384)&&d("agentic local graph-size limit"),![p,B,D].every(e=>V(e,!1)))throw TypeError("Measured graph spacing must be finite and nonnegative");if(void 0!==h.edgeSpacing&&!V(h.edgeSpacing,!0))throw TypeError("Measured edge spacing must be finite and positive");if(void 0!==h.minimumTerminalLead&&!V(h.minimumTerminalLead,!0))throw TypeError("Measured terminal lead must be finite and positive");if(void 0!==h.maximumEdgeStrokeWidth&&!V(h.maximumEdgeStrokeWidth,!0))throw TypeError("Measured maximum edge stroke width must be finite and positive");if(void 0!==h.maximumEdgeBendRadius&&!V(h.maximumEdgeBendRadius,!1))throw TypeError("Invalid measured edge bend radius");for(let e of h.nodes)if(void 0!==e.paintStrokeWidth&&!V(e.paintStrokeWidth,!0))throw TypeError("Invalid measured node paint stroke");for(let e of h.nodes)if(void 0!==e.paintCornerRadius&&!V(e.paintCornerRadius,!1))throw TypeError("Invalid measured node corner radius");for(let e of h.nodes)if(void 0!==e.minimumPortSpacing&&!V(e.minimumPortSpacing,!0))throw TypeError("Invalid measured node port spacing");for(let e of h.groups??[])if(void 0!==e.paintStrokeWidth&&!V(e.paintStrokeWidth,!0))throw TypeError("Invalid measured group paint stroke");for(let e of h.groups??[])if(void 0!==e.paintCornerRadius&&!V(e.paintCornerRadius,!1))throw TypeError("Invalid measured group corner radius");for(let e of h.edges)void 0!==e.markerPaint&&function(e){if(!e||"object"!=typeof e)throw TypeError("Invalid measured marker paint");for(let t of[e.start,e.end])if(void 0!==t){if(!Array.isArray(t)||t.length>64)throw TypeError("Invalid measured marker pieces");for(let e of t)if("circle"===e.kind){if(![e.cx,e.cy,e.r].every(e=>Number.isFinite(e*e*16))||!(e.r>0))throw TypeError("Invalid measured marker circle")}else if("polygon"===e.kind){if(!Array.isArray(e.points)||e.points.length<3||e.points.length>32)throw TypeError("Invalid measured marker polygon");for(let t of e.points)if(!Number.isFinite(t.x*t.x*16)||!Number.isFinite(t.y*t.y*16))throw TypeError("Invalid measured marker coordinate");let t=0;for(let i=0;i<e.points.length;i++){let r=e.points[i],a=e.points[(i+1)%e.points.length],n=e.points[(i+2)%e.points.length],o=(a.x-r.x)*(n.y-a.y)-(a.y-r.y)*(n.x-a.x);if(!Number.isFinite(o)||o&&t&&Math.sign(o)!==t)throw TypeError("Nonconvex measured marker polygon");o&&(t=Math.sign(o))}if(!t)throw TypeError("Empty measured marker polygon")}else throw TypeError("Invalid measured marker kind")}}(e.markerPaint);if(!["TD","TB","BT","LR","RL"].includes(h.direction))throw TypeError("Invalid measured graph direction");if(h.groups?.length)return u.length+h.groups.length>4096&&d("agentic local compound-size limit"),function(i,a,n,h,g){let c=i.groups,d=i.nodes.length,f=d+c.length,m=new Int32Array(f).fill(-1),u=Array.from({length:c.length+1},()=>[]),x=Array.from({length:c.length+1},()=>[]),p=new Map,H,j=new Set;for(let e=0;e<f;e++){let t=e<d?i.nodes[e]:c[e-d];if(j.has(t.id))throw TypeError("Measured compound identities must be unique");if(j.add(t.id),void 0!==t.modelOrder&&(!Number.isSafeInteger(t.modelOrder)||t.modelOrder<0))throw TypeError("Invalid measured model order");if(void 0!==t.partition&&(!Number.isSafeInteger(t.partition)||t.partition<0||t.partition>1e4))throw TypeError("Invalid measured partition");let r=t.parent??-1;if(!Number.isInteger(r)||r<-1||r>=c.length||r>=0&&e===d+r)throw TypeError("Invalid measured compound parent");if(e<d){let t=i.nodes[e];if(![t.width,t.height].every(e=>Number.isFinite(e)&&e>0))throw TypeError("Invalid measured compound leaf dimensions")}m[e]=r,u[r+1].push(e)}for(let e=0;e<c.length;e++){let t=new Set;for(let i=e;i>=0;i=m[d+i]){if(t.has(i))throw TypeError("Measured compound parents must be acyclic");t.add(i),t.size>64&&n("agentic local compound-depth limit")}let i=c[e];if(void 0!==i.direction&&!["TD","TB","BT","LR","RL"].includes(i.direction))throw TypeError("Invalid measured compound direction");if(![i.minWidth,...Object.values(i.padding)].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured compound dimensions");if(void 0!==i.headerHeight&&(!Number.isFinite(i.headerHeight)||i.headerHeight<0||i.headerHeight>i.padding.top))throw TypeError("Invalid measured compound header")}for(let e=0;e<i.edges.length;e++){let t=i.edges[e];if(!Number.isInteger(t.source)||!Number.isInteger(t.target)||t.source<0||t.target<0||t.source>=f||t.target>=f)throw TypeError("Invalid measured compound endpoint");if(!Number.isSafeInteger(t.minSpan)||t.minSpan<1||t.label&&![t.label.width,t.label.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured compound edge dimensions");if(void 0!==t.short&&!0!==t.short)throw TypeError("Invalid measured short-edge preference");if(void 0!==t.boundaryMarker&&![t.boundaryMarker.inset,t.boundaryMarker.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured ancestor marker dimensions");let r=m[t.source];if(r!==m[t.target]){let i=new Set([-1]);for(let e=r;e>=0;e=m[d+e])i.add(e);for(r=m[t.target];!i.has(r);)r=m[d+r];let a=e=>{for(;m[e]!==r;)e=d+m[e];return e},n=a(t.source),o=a(t.target);if(n===o){(H??=[]).push(e);continue}p.set(e,{source:n,target:o,host:r})}x[r+1].push(e)}let z=H?function(e,t,i,r){let a=e.groups,n=e.nodes.length,o=Math.max(8,e.edgeSpacing??6,e.minimumTerminalLead??0),l=new Map,s=new Map,h=new Map,g=new Map,c=(e,a)=>{for(let o=t[a];o>=0;o=t[n+o])if(--i.pairs<0&&r("agentic local cross-hierarchy obstacle-work limit"),o===e)return!0;return!1};for(let[t,d]of e.edges.entries()){--i.pairs<0&&r("agentic local cross-hierarchy obstacle-work limit");let e=d.source>=n&&c(d.source-n,d.target),f=d.target>=n&&c(d.target-n,d.source);if(!e&&!f)continue;let m=o;if(1!==d.minSpan){if(!Number.isSafeInteger(d.minSpan)||d.minSpan<1)throw TypeError("Invalid measured compound edge dimensions");let e=y(d.minSpan);(!Number.isSafeInteger(e)||e<0)&&r("agentic local coordinate-range limit"),m=Math.max(o,e)}let u=(e?d.source:d.target)-n,x=a[u],p=s.get(u)??0,b=Math.max(d.label?.height??0,d.boundaryMarker?.height??0),M=b+2*o,w=Math.max(2*o,(d.boundaryMarker?.inset??0)+o);--i.arcs<0&&r("agentic local cross-hierarchy visibility-arc limit"),l.set(t,{edge:t,container:u,interior:e?d.target:d.source,containerEnd:e?"source":"target",rowOffset:x.padding.top+p+o+b/2,labelInset:w,minimumLead:m,...d.label?{label:{...d.label}}:{}}),s.set(u,p+M),h.set(u,Math.max(h.get(u)??0,w+(d.label?.width??0)+2*o)),g.set(u,Math.max(g.get(u)??0,m))}return{connections:l,clearance:o,groups:l.size?a.map((e,t)=>s.has(t)?{...e,headerHeight:e.headerHeight??e.padding.top,padding:{...e.padding,top:e.padding.top+s.get(t),left:Math.max(e.padding.left+h.get(t),g.get(t)+o)}}:e):a}}(i,m,g,n):void 0;if(z){if(H.some(e=>!z.connections.has(e)))throw TypeError("Ancestor planner lost an authored endpoint occurrence");c=z.groups}let U=Array(c.length+1),V=0,B=(e,t)=>{let r=c[e-1],o=r?.direction??t,l=u[e],s=new Map(l.map((e,t)=>[e,t])),h=l.map(e=>{if(e<d){let{id:t,width:r,height:a,partition:n,modelOrder:o,minimumPortSpacing:l}=i.nodes[e];return{id:t,width:r,height:a,partition:n,modelOrder:o,...void 0!==l?{minimumPortSpacing:l}:{}}}let t=B(e-d+1,o);return{id:c[e-d].id,width:t.width,height:t.height,partition:c[e-d].partition,modelOrder:c[e-d].modelOrder}}),g={nodes:h,edges:x[e].map(e=>{let t=i.edges[e],r=p.get(e)??t;return{...t,source:s.get(r.source),target:s.get(r.target)}}),padding:0,direction:o,nodeSpacing:i.nodeSpacing,layerSpacing:i.layerSpacing,edgeSpacing:i.edgeSpacing,...void 0!==i.minimumTerminalLead?{minimumTerminalLead:i.minimumTerminalLead}:{},...i.placementOnly?{placementOnly:!0}:{}};p.size&&x[e].some(e=>p.has(e))&&(g.compactPrivateRanks=!0);let f=a(g);(V+=f.expandedVertices??h.length)>32768&&n("agentic local compound-expansion limit");let y=r?.padding??{top:i.padding,right:i.padding,bottom:i.padding,left:i.padding},m=Math.max(r?.minWidth??0,f.width+y.left+y.right,1),b={direction:o,placed:f,width:m,height:Math.max(f.height+y.top+y.bottom,1),dx:y.left+(m-f.width-y.left-y.right)/2,dy:y.top};return Number.isFinite(b.width+b.height+b.dx+b.dy)||n("agentic local coordinate-range limit"),U[e]=b,b},D=B(0,i.direction),_=Array(d),q=Array(c.length),$=Array(i.edges.length),Q=(e,t,i)=>{let r=U[e],a=t+r.dx,n=i+r.dy;u[e].forEach((e,t)=>{let i=r.placed.nodes[t],o={x:i.x+a,y:i.y+n};if(e<d)_[e]=o;else{let t=e-d,i=U[t+1];q[t]={...o,width:i.width,height:i.height},Q(t+1,o.x,o.y)}}),x[e].forEach((e,t)=>{let i=r.placed.edges[t];$[e]={points:i.points.map(e=>({x:e.x+a,y:e.y+n})),...i.labelPosition?{labelPosition:{x:i.labelPosition.x+a,y:i.labelPosition.y+n}}:{}}})};if(Q(0,0,0),z)for(let e of z.connections.keys())$[e]=function(e,t,i,r){let a=e.connections.get(t),n=i[a.container],o=e.clearance,l=n.y+a.rowOffset;r?.(a.label?3:2);let s=[{x:n.x,y:l},{x:n.x+e.groups[a.container].padding.left-o,y:l}];return{points:"source"===a.containerEnd?s:s.reverse(),...a.label?{labelPosition:{x:n.x+a.labelInset+a.label.width/2,y:l}}:{}}}(z,e,q,e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid ancestor placeholder reservation");V+e>32768&&n("agentic local compound-expansion limit"),V+=e});let G={topology:"layered",width:D.width,height:D.height,nodes:_,groups:q,edges:$,expandedVertices:V},J=!1;if(void 0!==i.maximumEdgeStrokeWidth){for(let e of i.edges)if(--g.pairs<0&&n("agentic marker metadata work limit"),e.markerPaint?.start?.length||e.markerPaint?.end?.length){J=!0;break}}return i.placementOnly?G:p.size||z||J?function(i,a,n,h,g,c,d,f,y){let m=i.nodes.length,u=a.groups,x=i.groups,p=y?.groups??x,H=x.length>16||h.size>16||i.edges.length>128,j=a.edges.reduce((e,t)=>e+t.points.length,0);j>2048&&f("agentic local cross-hierarchy route-point limit");let z=a.expandedVertices??0,U=z,V=e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid compound visibility reservation");z+e>32768&&f("agentic local cross-hierarchy visibility-expansion limit"),z+=e},B,D=()=>B??=S(V,f),_,q=()=>{var e;let t,i;return _??=(e=e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid compound adjacency reservation");c.arcs-=e,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit")},t=[],i=0,{get arcs(){return i},acquire(r,a){let n,o=4*r;for(let e of((!Number.isSafeInteger(o)||o<4||o>0x7fffffff)&&f("agentic local cross-hierarchy visibility-arc limit"),t))a(),!e.active&&e.capacity>=o&&(!n||e.capacity<n.capacity)&&(n=e);return n||(e(o),i+=o,n={active:!1,capacity:o,nodes:new Int32Array(o),distances:new Float64Array(o)},t.push(n)),a(o),n.nodes.fill(-1,0,o),n.distances.fill(0,0,o),n.active=!0,n}})},$=i.maximumEdgeStrokeWidth;void 0!==$&&(C(c,f,2),--c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"));let Q=void 0===$?void 0:e=>C(c,f,e),G=void 0===$?void 0:e=>{c.pairs-=e,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")},J=!1;if(void 0!==$){for(let e of i.edges)if(--c.pairs<0&&f("agentic marker metadata work limit"),e.markerPaint?.start?.length||e.markerPaint?.end?.length){J=!0;break}}let K=Math.max(8,i.edgeSpacing??6),Z=a.nodes.map((e,t)=>({...e,width:i.nodes[t].width,height:i.nodes[t].height})),ee=[...Z,...u],et=new Set,ei=new Set,er,ea,en;for(let[d,S]of h)for(let I=0;I<2;I++){let R,W=!1,B,_=e=>((B??=[]).push(e),e);try{c.pairs-=Z.length+u.length,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let B=i.edges[d],J=a.edges[d],en=l(J.points);if(en.length<2||B.label&&!J.labelPosition)throw TypeError("Compound quotient lost its route or label");let es=B.source!==S.source,eh=B.target!==S.target,eg=(e,t,i=K)=>{let r=Math.abs(e.x-t.x)+Math.abs(e.y-t.y),a=Math.min(i,r/2);return{x:e.x+Math.sign(t.x-e.x)*a,y:e.y+Math.sign(t.y-e.y)*a}},ec=es?eg(en[0],en[1]):en[0],ed=eh?eg(en.at(-1),en.at(-2)):en.at(-1),ef=[ec,...en.slice(1,-1),ed],ey=new Set;for(let e of[B.source,B.target])for(let t=n[e];t>=0;t=n[m+t])ey.add(t);let em=Z.map((e,t)=>t===B.source||t===B.target?e:P(e,K));for(let e=0;e<u.length;e++){let t=u[e];m+e===B.source||m+e===B.target?em.push(t):ey.has(e)?x[e].padding.top>0&&em.push(P({...t,height:y||m>64?p[e].headerHeight??p[e].padding.top:x[e].padding.top},Math.max(2,(i.edgeSpacing??6)/2))):em.push(P(t,K))}let eu=[...em],ex;B.label&&--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit");for(let e=0;e<a.edges.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=a.edges[e],r=i.edges[e];if(r.label&&t.labelPosition){let i=P({x:t.labelPosition.x-r.label.width/2,y:t.labelPosition.y-r.label.height/2,width:r.label.width,height:r.label.height},2);em.push(i),eu.push(i),e===d&&(ex=i)}if(!(e===d||!1===r.visible||y?.connections.has(e)))for(let e=1;e<t.points.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let r=t.points[e-1],a=t.points[e];em.push(P({x:Math.min(r.x,a.x),y:Math.min(r.y,a.y),width:Math.abs(r.x-a.x),height:Math.abs(r.y-a.y)},Math.max(2,(i.edgeSpacing??6)/2)))}}let ep,eb=()=>ep??=(er??=function(e,t){e.arcs-=8,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit");let i=i=>{e.pairs-=i,e.pairs<0&&t("agentic local cross-hierarchy obstacle-work limit")},r=i=>{e.arcs-=i,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit")},a,n=(e,t)=>"capacity"===t?r(e):i(e);return o=>{r(7);let l=e=>{i(3);let t=a?.[e];if(t&&a.boxes.length===o.length){let r=!0;for(let t=0;t<o.length;t++){i(3);let n=a.boxes[t],l=o[t],s=n[e]-0,h=n[e]+("x"===e?n.width:n.height)+0,g=l[e]-0,c=l[e]+("x"===e?l.width:l.height)+0;if(!Object.is(Math.floor(s/128),Math.floor(g/128))||!Object.is(Math.floor(h/128),Math.floor(c/128))){r=!1;break}}if(r)return t}return s(o,e,0,n)},h=l("x"),g=l("y"),c=b(o,e,t,{x:h,y:g});return i(1),a={boxes:o,x:h,y:g},c}}(c,f))(eu),eM=S.host,ew=eM<0?void 0:u[eM],ev=eM<0?void 0:p[eM].padding;c.pairs-=8,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let ek=eM<0?void 0:x[eM].paintCornerRadius,eS=void 0===$||void 0===ek?1/0:($+(x[eM].paintStrokeWidth??0))/2+ek+1,eN=ew&&ev?0===I?{x:ew.x+ev.left,y:ew.y+ev.top,width:ew.width-ev.left-ev.right,height:ew.height-ev.top-ev.bottom}:{x:ew.x+eS,y:ew.y+ev.top,width:ew.width-2*eS,height:ew.height-ev.top-eS}:{x:0,y:0,width:a.width,height:a.height},eE=es?F(ee[B.source],g[n[B.source]+1],!0,K):[],eI=eh?F(ee[B.target],g[n[B.target]+1],!1,K):[],eP=e=>{let t=[];for(let i=n[e];i>=0;i=n[m+i])--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),t.push(u[i]);return t},eA,eF,eY="agentic local cross-hierarchy size limit",eT=e=>{if("agentic local cross-hierarchy visibility-expansion limit"===e||"cross-hierarchy route has no bounded clear corridor"===e||"cross-hierarchy route needs an unsupported self-contact repair"===e)throw new X(e);return f(e)};if(!H)try{let e=es?void 0:[ec],t=eh?void 0:[ed];if(m>64){let i={pairs:Math.min(16384,Math.floor(c.pairs/8)),candidates:64};e||(e=T(eN,em,eE,ec,eP(B.source),K,c,i,f)),t||(t=T(eN,em,eI,ed,eP(B.target),K,c,i,f)?.reverse()),e&&t||f("large cross-hierarchy route has no bounded direct corridor")}if(!e||!t){let i=32768-z,r=function(e,t,i,r,a,n,o,l,s){let h=0,g=e=>{h+e>o&&l("agentic local cross-hierarchy visibility-expansion limit"),s?.(e),h+=e},c=e.x+e.width,d=e.y+e.height,f=t=>t.x>=e.x&&t.x<=c&&t.y>=e.y&&t.y<=d,y=t.filter(t=>(--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),t.x<=c&&t.x+t.width>=e.x&&t.y<=d&&t.y+t.height>=e.y)),m=new Set([e.x,c]),u=new Set([e.y,d]);for(let t of y){for(let i of(--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),[t.x,t.x+t.width]))i>=e.x&&i<=c&&m.add(i);for(let i of[t.y,t.y+t.height])i>=e.y&&i<=d&&u.add(i)}let x=e=>{--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),Number.isFinite(e.x+e.y)||l("agentic local cross-hierarchy coordinate limit"),f(e)&&(m.add(e.x),u.add(e.y))};for(let e of i)x(e.port),x(e.stub);for(let e of r)x(e);let p=(e,t)=>(--n.swaps<0&&l("agentic local cross-hierarchy coordinate-sort limit"),e-t),M=[...m].sort(p),w=[...u].sort(p),v=M.length,k=v*w.length;(!Number.isSafeInteger(3*k)||3*k>0x7fffffff)&&l("agentic local cross-hierarchy coordinate limit");let S=(e=!1)=>{let t=new Map;return{get:e=>t.get(Math.floor(e/32))?.[e%32]??0,set(i,r){let a=Math.floor(i/32),o=t.get(a);if(!o){let i=Math.min(32,k-32*a);e?(n.arcs-=i,n.arcs<0&&l("agentic local cross-hierarchy visibility-arc limit")):g(i),o=new Int8Array(i),t.set(a,o)}o[i%32]=r}}},N=S(),E=S(!0),I=S(!0),P,A=()=>P??=b(y,n,l),F=e=>{let t=N.get(e);if(t)return 1===t;let i=M[e%v],r=w[Math.floor(e/v)];return A().containsPoint(i,r)?(N.set(e,-1),!1):(N.set(e,1),!0)},Y=(e,t,i,r)=>!A().entersSegment(e,t,i,r),T=(e,t)=>Y(M[e%v],w[Math.floor(e/v)],M[t%v],w[Math.floor(t/v)]),X=e=>{let t=M.indexOf(e.x),i=w.indexOf(e.y);return t<0||i<0?-1:i*v+t};return{get vertices(){return h},virtualVertices:3*k,route(e,t){let i=X(t);(i<0||!F(i))&&l("cross-hierarchy route has no clear anchor");let r=new Map,o=new Map,s=e=>{let t=Math.floor(e/32),i=r.get(t);if(!i){let e=Math.min(32,3*k-32*t);g(e),i={distance:new Float64Array(e).fill(1/0),parent:new Int32Array(e).fill(-1),slots:new Int32Array(e).fill(-1),roots:new Int32Array(e).fill(-1)},r.set(t,i)}return i},h=e=>r.get(Math.floor(e/32)),c=e=>h(e)?.distance[e%32]??1/0,d=e=>h(e)?.parent[e%32]??-1,y=e=>h(e)?.slots[e%32]??-1,m=e=>h(e)?.roots[e%32]??-1,u=0,x=e=>o.get(Math.floor(e/32))[e%32],p=(e,t)=>{let i=Math.floor(e/32),r=o.get(i);if(!r){let e=Math.min(32,3*k-32*i);g(e),r=new Int32Array(e),o.set(i,r)}r[e%32]=t},b=e=>{let i=Math.floor(e/3);return c(e)+Math.abs(M[i%v]-t.x)+Math.abs(w[Math.floor(i/v)]-t.y)},S=(e,t)=>(--n.swaps<0&&l("agentic local cross-hierarchy heap-work limit"),b(e)<b(t)||b(e)===b(t)&&e<t),N=(e,t)=>{let i=x(e);p(e,x(t)),p(t,i),s(x(e)).slots[x(e)%32]=e,s(x(t)).slots[x(t)%32]=t},P=e=>{let t=y(e);if(-2!==t)for(t<0&&(t=u,p(u++,e),s(e).slots[e%32]=t);t>0;){let e=Math.floor((t-1)/2);if(!S(x(t),x(e)))break;N(t,e),t=e}},A=()=>{let e=x(0),t=x(--u);if(s(e).slots[e%32]=-2,u){p(0,t),s(t).slots[t%32]=0;let e=0;for(;2*e+1<u;){let t=2*e+1;if(t+1<u&&S(x(t+1),x(t))&&t++,!S(x(t),x(e)))break;N(e,t),e=t}}return e};for(let t=0;t<e.length;t++){let i=e[t],r=X(i.stub);if(r<0||!f(i.port)||!F(r)||!Y(i.port.x,i.port.y,i.stub.x,i.stub.y))continue;let a=3*r+(i.port.x===i.stub.x?2:1),n=Math.abs(i.stub.x-i.port.x)+Math.abs(i.stub.y-i.port.y)+i.penalty;if(n<c(a)){let e=s(a),i=a%32;e.distance[i]=n,e.roots[i]=t,P(a)}}let C=e=>(g(1),{x:M[e%v],y:w[Math.floor(e/v)]});for(;u;){let t=A(),r=Math.floor(t/3),o=t%3;if(r===i){let i=[],r=t;for(;d(r)>=0;)i.push(C(Math.floor(r/3))),r=d(r);i.push(C(Math.floor(r/3))),g(1),i.push({...e[m(r)].port});let a=[];for(let e of i.reverse())if(a.at(-1)?.x!==e.x||a.at(-1)?.y!==e.y)for(a.push(e);a.length>2;){let e=a.at(-3),t=a.at(-2),i=a.at(-1);if(!(e.x===t.x&&t.x===i.x&&t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y)||e.y===t.y&&t.y===i.y&&t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x)))break;a.splice(a.length-2,1)}return a}let h=r%v,f=Math.floor(r/v);for(let e=0;e<4;e++){let i=0===e?h>0?r-1:-1:1===e?h+1<v?r+1:-1:2===e?f>0?r-v:-1:f+1<w.length?r+v:-1,g=e<2?1:2;if(--n.arcs<0&&l("agentic local cross-hierarchy visibility-arc limit"),i<0||!F(i))continue;let d=Math.min(r,i),u=1===g?E:I;if(u.get(d)||u.set(d,T(r,i)?1:-1),1!==u.get(d))continue;let x=3*i+g,p=c(t)+Math.abs(M[r%v]-M[i%v])+Math.abs(w[Math.floor(r/v)]-w[Math.floor(i/v)])+(o===g?0:2*a);if(-2!==y(x)&&p<c(x)){let e=s(x),i=x%32;e.distance[i]=p,e.parent[i]=t,e.roots[i]=m(t),P(x)}}}return l("cross-hierarchy route has no bounded clear corridor")}}}(eN,em,[...eE,...eI],[ec,ed],K,c,i,eT,V);(r.virtualVertices>i||r.virtualVertices>32768-U)&&eT("agentic local cross-hierarchy visibility-expansion limit"),U+=r.virtualVertices,e??=r.route(eE,ec),t??=r.route(eI,ed).reverse()}eA=l([...e,...ef.slice(1,-1),...t]),Y(eA,c,f)&&(eF=eA,eT("cross-hierarchy route needs an unsupported self-contact repair"))}catch(e){if(!(e instanceof X))throw e;eY=e.reason,eA=void 0}if(!eA){var eo,el;let s={pairs:Math.min(16384,Math.floor(c.pairs/8)),candidates:64},m=es?eg(en[0],en[1],2*K):ec,p=eh?eg(en.at(-1),en.at(-2),2*K):ed,b=[m,...en.slice(1,-1),p];B.label&&!b.some((e,t)=>t>0&&A(J.labelPosition,b[t-1],e))&&(m=ec,p=ed,b=ef);let S=a.edges.map((e,t)=>({...e,style:!1===i.edges[t].visible||y?.connections.has(t)||h.has(t)&&!et.has(t)?"invisible":"solid"})),P=function(e,t,i,a,n,l){let s,h,g,c=r(e,l===o?"proposal":"complete"),d=0,f=0,y=0;for(let e=0;e<i.length;e++)--a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),e!==t&&"invisible"!==i[e].style&&(d+=Math.max(0,i[e].points.length-1),f+=i[e].points.length,y++);let m=(e=1)=>{a.pairs-=e,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit")};void 0!==e.maximumEdgeStrokeWidth&&C(a,n);let u=void 0===e.maximumEdgeStrokeWidth?void 0:e=>C(a,n,e),x=r=>(a.pairs-=c*Math.max(0,r.length-1)*d+r.length+d,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),void 0!==l(r,t,i,e,m,u,void 0,c));return d<32?x:r=>{let o=Math.max(0,r.length-1),p=1+9*r.length+(void 0===e.maximumEdgeStrokeWidth?8:20)*y+i.length,b=s?0:9*f+y+3*i.length,M=(c*o+1)*d;if(!Number.isSafeInteger(M)||M<=p+b)return x(r);if(!s){C(a,n,2*i.length),m(2*i.length),s=i.slice(),h=Array(i.length);for(let e=0;e<i.length;e++){m();let r=i[e];if(e===t||"invisible"===r.style)continue;C(a,n);let o={points:r.points,style:r.style,originalStyle:r.style,orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};L(r.points,o,m),s[e]=o,h[e]=o}C(a,n),g={orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0}}L(r,g,m);let w=0;for(let t=0;t<s.length;t++){m();let i=h[t];i&&(i.style=O(g,i,m,e.maximumEdgeStrokeWidth)?"invisible":i.originalStyle,"invisible"!==i.style&&(w+=Math.max(0,i.points.length-1)))}return m(c*o*w+r.length+w),void 0!==l(r,t,s,e,m,u,void 0,c)}}(i,d,S,c,f,o),W=e=>{let t=Y(e,c,f)?function(e,t,i){let r=l(e);for(;;){let e;for(let a=2;a<r.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=r[a-2],o=r[a-1],l=r[a];if(n.x===o.x&&o.x===l.x||n.y===o.y&&o.y===l.y){e=[...r.slice(0,a-1),...r.slice(a)];break}}for(let a=1;!e&&a<r.length;a++)for(let n=a+2;n<r.length;n++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let o=r[a-1],l=r[a],s=r[n-1],h=r[n],g;if(o.x===l.x&&s.x===h.x){let e=Math.max(Math.min(o.y,l.y),Math.min(s.y,h.y)),t=Math.min(Math.max(o.y,l.y),Math.max(s.y,h.y));o.x===s.x&&e<=t&&(g={x:o.x,y:Math.max(e,Math.min(t,o.y))})}else if(o.y===l.y&&s.y===h.y){let e=Math.max(Math.min(o.x,l.x),Math.min(s.x,h.x)),t=Math.min(Math.max(o.x,l.x),Math.max(s.x,h.x));o.y===s.y&&e<=t&&(g={x:Math.max(e,Math.min(t,o.x)),y:o.y})}else{let e={x:o.x===l.x?o.x:s.x,y:o.x===l.x?s.y:o.y};A(e,o,l)&&A(e,s,h)&&(g=e)}if(g){e=[...r.slice(0,a),g,...r.slice(n)];break}}if(!e)return r;r=l(e)}}(e,c,f):e;if(!(t.length<2)){for(let i of[!0,!1]){c.pairs-=4,c.pairs<0&&f("agentic local cross-hierarchy self-check limit");let r=i?e[0]:e.at(-1),a=i?e[1]:e.at(-2),n=i?t[0]:t.at(-1),o=i?t[1]:t.at(-2),l=ee[i?B.source:B.target],s=a.x-r.x,h=a.y-r.y,g=Math.abs(s)+Math.abs(h),d=Math.min(K,g),y={x:r.x+Math.sign(s)*d,y:r.y+Math.sign(h)*d};if(n.x!==r.x||n.y!==r.y||!A(y,n,o)||n.x<l.x-1e-7||n.x>l.x+l.width+1e-7||n.y<l.y-1e-7||n.y>l.y+l.height+1e-7||!(1e-7>Math.abs(n.x-l.x)&&o.y===n.y&&o.x<n.x||1e-7>Math.abs(n.x-l.x-l.width)&&o.y===n.y&&o.x>n.x||1e-7>Math.abs(n.y-l.y)&&o.x===n.x&&o.y<n.y||1e-7>Math.abs(n.y-l.y-l.height)&&o.x===n.x&&o.y>n.y))return}if(!(B.label&&!t.some((e,i)=>i>0&&A(J.labelPosition,t[i-1],e))))return P(t)?t:void 0}};eF&&(eA=W(eF));let H=e=>{if(!eh){let t=l([...e,...b.slice(1)]),i=W(t);return!!i&&(eA=i,!0)}return void 0!==T(eN,eu,eI,p,eP(B.target),K,c,s,f,t=>{let i=l([...e,...b.slice(1,-1),...t.toReversed()]),r=W(i);return!!r&&(eA=r,!0)},!0,eb)},j;if(void 0===$||eA){if(void 0===$)if(eA||B.label)!eA&&es?T(eN,eu,eE,m,eP(B.source),K,c,s,f,H,!0,eb):eA||H([m]);else{let t=F(ee[B.source],g[n[B.source]+1],!0,K),i=F(ee[B.target],g[n[B.target]+1],!1,K),r=[...eP(B.source),...eP(B.target)];for(let a=0;a<3&&!eA&&s.candidates>0;a++)for(let n=0;n<4&&!eA&&s.candidates>0;n++){let o=i[3*n+a],h=!0;for(let t of eu)if(s.pairs--<=0||(--c.pairs<0&&f("agentic local cross-hierarchy direct-pair limit"),e(o.stub,o.port,t))){h=!1;break}h&&T(eN,eu,t,o.stub,r,K,c,s,f,e=>{let t=l([...e,o.port]),i=W(t);return!!i&&(eA=i,!0)},!0,eb)}}}else c.arcs-=32,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),j=()=>{if(eA||B.label)!eA&&es?T(eN,eu,eE,m,eP(B.source),K,c,s,f,H,!0,eb):eA||H([m]);else{let t=F(ee[B.source],g[n[B.source]+1],!0,K),i=F(ee[B.target],g[n[B.target]+1],!1,K),r=[...eP(B.source),...eP(B.target)];for(let a=0;a<3&&!eA&&s.candidates>0;a++)for(let n=0;n<4&&!eA&&s.candidates>0;n++){let o=i[3*n+a],h=!0;for(let t of eu)if(s.pairs--<=0||(--c.pairs<0&&f("agentic local cross-hierarchy direct-pair limit"),e(o.stub,o.port,t))){h=!1;break}h&&T(eN,eu,t,o.stub,r,K,c,s,f,e=>{let t=l([...e,o.port]),i=W(t);return!!i&&(eA=i,!0)},!0,eb)}}};if(!eA)try{let e=(e,t)=>{let r=0,a=0,l=0,s=S.map((t,n)=>{--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let o=i.edges[n],s=o.source===e||o.target===e;s&&(r++,n<d&&a++);let h=s?t.style:"invisible";return n!==d&&"invisible"!==h&&(l+=Math.max(0,t.points.length-1)),{...t,style:h}}),h=[...new Set([(a+1)/(r+1),.5,.25,.75])];return F(ee[e],g[n[e]+1],t,K,h).filter(e=>(c.pairs-=4*l+2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"),void 0!==o(t?[e.port,e.stub]:[e.stub,e.port],d,s,i,G,Q)))},r=(e,t)=>{let r=0,a=0;for(let t=0;t<i.edges.length;t++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let n=i.edges[t];(n.source===e||n.target===e)&&(r++,t<d&&a++)}c.arcs-=8,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),V(8);let o=ee[e],l=g[n[e]+1],s=(a+.5)/(r+1),h="LR"===l?"E":"RL"===l?"W":"BT"===l?"N":"S",y=t?h:"N"===h?"S":"S"===h?"N":"E"===h?"W":"E",m=[,,,,],u=e=>0===e?y:"N"===y?1===e?"E":2===e?"S":"W":"E"===y?1===e?"N":2===e?"S":"W":"S"===y?1===e?"N":2===e?"E":"W":1===e?"N":2===e?"E":"S";for(let e=0;e<4;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=u(e),i="N"===t||"S"===t?{x:o.x+s*o.width,y:"N"===t?o.y:o.y+o.height}:{x:"W"===t?o.x:o.x+o.width,y:o.y+s*o.height},r={x:i.x+("E"===t?2*K:"W"===t?-(2*K):0),y:i.y+("S"===t?2*K:"N"===t?-(2*K):0)};m[e]={port:i,stub:r,penalty:e*K*2+Math.abs(s-.5)*K}}return m},s=W;void 0!==$&&(c.arcs-=4,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),s=e=>W(v(e,c,f)));let h=B.label&&!es?[]:e(B.source,!0),y=B.label&&!eh?[]:e(B.target,!1);ea??=(eo=a.width,el=a.height,c.arcs--,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),new k(S,d,eo,el,c,V,f)),R=ea.acquire(d);let x=ea.rails,I=R.guard,P=e=>{let t=e=>e.x>=eN.x&&e.x<=eN.x+eN.width&&e.y>=eN.y&&e.y<=eN.y+eN.height;for(let i of e){c.pairs-=8,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let{port:e,stub:r}=i;if(!t(e)||!t(r))continue;let a=eb();if(a.containsPoint(e.x,e.y)||a.containsPoint(r.x,r.y)||a.entersSegment(e.x,e.y,r.x,r.y))continue;let n=e.x===r.x?2:+(e.y===r.y);if(!n)throw TypeError("Measured terminal lead must be orthogonal");if(I(e,r,n,n))return!0}return!1},A=e=>{try{return e(),void 0!==eA}catch(e){if(!(e instanceof X))throw e;return eY=e.reason,!1}};if(B.label){if(void 0!==$&&!es&&eh&&ex){c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),ea.enterQuery(R);try{eA=function(e,i,r,a,n,o,l,s,h,g,c,d,f,y,m,u){g.arcs-=24+e.length+1,g.arcs<0&&y("agentic local cross-hierarchy visibility-arc limit");let x=(e=1)=>{g.pairs-=e,g.pairs<0&&y("agentic local cross-hierarchy obstacle-work limit")},p=e=>{g.arcs-=e,g.arcs<0&&y("agentic local cross-hierarchy visibility-arc limit")};if(x(12),e.length<2||!t(r,e.at(-2),e.at(-1)))return;let b=e.at(-2),v=e.at(-1),k=v.x-b.x,S=v.y-b.y;if(0===k==(0===S))return;let N=k>0?a.x+a.width:k<0?a.x:v.x,E=S>0?a.y+a.height:S<0?a.y:v.y;if(x(8),N<Math.min(b.x,v.x)||N>Math.max(b.x,v.x)||E<Math.min(b.y,v.y)||E>Math.max(b.y,v.y))return;let I=e[0],P=e[1],A=P.x-I.x,F=P.y-I.y;if(0===A==(0===F))return;let Y=A>0?i.x+i.width:A<0?i.x:I.x,T=F>0?i.y+i.height:F<0?i.y:I.y;if(x(4),Math.abs(Y-I.x)>1e-7||Math.abs(T-I.y)>1e-7)return;f(3),p(3);let X=e.slice(),C={x:N,y:E};X[0]={x:Y,y:T},X[X.length-1]=C;for(let e=1;e<X.length;e++){let t=X[e-1],i=X[e];if(x(4),!Number.isFinite(t.x+t.y+i.x+i.y)||t.x!==i.x&&t.y!==i.y||!w(t,i,s,d,g,y))return;for(let r of o)if(x(4),(r!==a||e!==X.length-1)&&(t.x===i.x?t.x>r.x&&t.x<r.x+r.width&&Math.max(t.y,i.y)>r.y&&Math.min(t.y,i.y)<r.y+r.height:t.y>r.y&&t.y<r.y+r.height&&Math.max(t.x,i.x)>r.x&&Math.min(t.x,i.x)<r.x+r.width))return}return M(n,o,{port:C,stub:{x:N+Math.sign(k)*c,y:E+Math.sign(S)*c},penalty:0},l,s,h,g,f,y,m,e=>{p(X.length+e.length);let t=Array(X.length+e.length-1);for(let e=0;e<X.length;e++)x(),t[e]=X[e];for(let i=1;i<e.length;i++)x(),t[X.length+i-1]=e[i];let i=0;for(let e=1;e<t.length;e++){let r=t[e-1],a=t[e],n=r.x===a.x?2:1;if(x(4),!m(r,a,i||n,n))return;i=n}return u(t)},0,d)}(b,ee[B.source],J.labelPosition,ex,eN,eu,y,x,eb(),c,K,Math.max(.5,$),V,f,I,s)}finally{ea.leaveQuery(R)}}if(void 0!==$&&(c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")),!eA&&j&&j(),!eA){let e=e=>n[e]<0?ee[e]:u[n[e]],t={roots:y,interiorChannels:!1,paths:[],complete:!1},i={roots:y,interiorChannels:!0,paths:[],complete:!1},a=[],o=(i,r=t)=>{if(!eh){let e=W(l([...i,...b.slice(1)]));return!!e&&(eA=e,!0)}let a=e=>{let t=W(l([...i,...b.slice(1,-1),...e.toReversed()]));return!!t&&(eA=t,!0)};for(let e of r.paths)if(a(e))return!0;if(r.complete)return!1;if(!r.graph&&!P(r.roots))return r.complete=!0,eY="cross-hierarchy route has no bounded clear corridor",!1;let n=A(()=>{r.graph??=_(N(eN,e(B.target),eu,r.roots,p,K,c,32768-z,eT,V,r.interiorChannels,eb,D(),x,q())),ea.enterQuery(R);try{r.graph.route(r.roots,p,e=>(r.late&&--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),r.paths.push(e),a(e)),I)}finally{ea.leaveQuery(R)}});return n||"cross-hierarchy route has no bounded clear corridor"!==eY||(r.complete=!0),(r.complete||n)&&r.graph?.retire(),n},s=(t,i,r)=>P(t)?A(()=>{let a=_(N(eN,e(B.source),eu,t,m,K,c,32768-z,eT,V,i,eb,D(),x,q()));ea.enterQuery(R);try{a.route(t,m,r,I)}finally{try{ea.leaveQuery(R)}finally{a.retire()}}}):(eY="cross-hierarchy route has no bounded clear corridor",!1),g=e=>(a.push(e),o(e));if(es?s(h,!1,g):g([m]),!eA&&"cross-hierarchy route has no bounded clear corridor"===eY){if(eh){for(let e of a)if(o(e,i))break}!eA&&es&&s(h,!0,e=>(--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),a.push(e),o(e)||o(e,i)))}if(!eA&&"cross-hierarchy route has no bounded clear corridor"===eY){let e;if(eh){let t=r(B.target,!1);--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),e={roots:t,interiorChannels:!1,late:!0,paths:[],complete:!1}}if(e){for(let t of a)if(o(t,e))break}!eA&&es&&s(r(B.source,!0),!1,t=>o(t)||eh&&(o(t,i)||o(t,e)))}}}else{if(void 0!==$){c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),ea.enterQuery(R);try{eA=function(e,t,i,r,a,n,o,l,s,h,g,c=.5){o.arcs-=40+a.length+3,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit");let d=(e=1)=>{o.pairs-=e,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit")},f=e=>{o.arcs-=e,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit")},y=new Float64Array(a.length+2),m=(e,t)=>(--o.swaps<0&&s("agentic local cross-hierarchy coordinate-sort limit"),e===t?0:e-t),u=(e,t,i,r,n,o)=>{d(y.length),y.fill(1/0);let l=2;for(let[s,h]of(y[0]=e,y[1]=t,a)){d(10);let a=o?s.y:s.x,g=o?s.x:s.y,f=o?h.y:h.x,m=o?h.x:h.y,u=i?a:g;(i?a!==f:g!==m)||Math.max(i?g:a,i?m:f)<r-c||Math.min(i?g:a,i?m:f)>n+c||u<=e||u>=t||(y[l++]=u)}y.sort(m);let s=-1/0,h;for(let e=1;e<l;e++){d(5);let t=y[e-1],i=y[e],r=i-t,a=t+r/2;r>2*c&&r>s&&a>t&&a<i&&(s=r,h=a)}return h};if(d(2),!Number.isFinite(c)||c<.5)return;d(8);let x=e.x+e.width,p=e.y+e.height;if(!(!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(x)||!Number.isFinite(p)||x<=e.x||p<=e.y)){for(let y=0;y<8;y++){let m=y>=4,b=y%4,v=b%2==0?-1:1,k=b<2?1:-1,S=m?e.y:e.x,N=m?p:x,E=m?e.x:e.y,I=m?x:p,P=v<0?S:N,A=k<0?E:I,F,Y;for(let e of i){d(6);let t=m?e.stub.y-e.port.y:e.stub.x-e.port.x;if((m?e.stub.x-e.port.x:e.stub.y-e.port.y)==0&&Math.sign(t)===v){F=e;break}}for(let e of r){d(6);let t=m?e.stub.y-e.port.y:e.stub.x-e.port.x,i=m?e.stub.x-e.port.x:e.stub.y-e.port.y;if(0===t&&Math.sign(i)===k){Y=e;break}}if(!F||!Y)continue;let T=m?F.port.y:F.port.x,X=m?F.port.x:F.port.y,C=m?F.stub.y:F.stub.x,L=m?Y.port.y:Y.port.x,O=m?Y.port.x:Y.port.y,R=m?Y.stub.x:Y.stub.y;if(d(9),k*(O-X)<=0){f(2);let i=M(e,t,F,[Y],a,n,o,l,s,h,g,void 0,c);if(i)return i;continue}if(T<S||T>N||X<E||X>I||L<S||L>N||O<E||O>I)continue;let W=v<0?N:S,H=Math.min(X,A),j=Math.max(X,A);for(let e of t){d(12);let t=m?e.y:e.x,i=m?e.x:e.y,r=m?e.height:e.width,a=m?e.width:e.height;if(!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(t+r)||!Number.isFinite(i+a)||r<0||a<0)return;i>=j||i+a<=H||t>N||t+r<S||(W=v<0?Math.min(W,Math.max(S,t)):Math.max(W,Math.min(N,t+r)))}if(d(2),v*(P-W)<=0)continue;let z=u(Math.min(P,W),Math.max(P,W),!0,H,j,m);if(d(3),void 0===z||v*(z-C)<0)continue;let U=R,V=Math.min(z,L),B=Math.max(z,L);for(let e of t){d(10);let t=m?e.y:e.x,i=m?e.x:e.y,r=m?e.height:e.width,a=m?e.width:e.height;t>=B||t+r<=V||i>I||i+a<E||(U=k<0?Math.min(U,Math.max(E,i)):Math.max(U,Math.min(I,i+a)))}if(d(2),k*(A-U)<=0)continue;let D=u(Math.min(A,U),Math.max(A,U),!1,V,B,m);if(d(3),void 0===D||k*(D-R)<0)continue;l(5),f(6);let _=m?[{x:X,y:T},{x:X,y:z},{x:D,y:z},{x:D,y:L},{x:O,y:L}]:[{x:T,y:X},{x:z,y:X},{x:z,y:D},{x:L,y:D},{x:L,y:O}],q=!0,$=0;for(let e=0;e<_.length;e++){let t=_[e];if(n.containsPoint(t.x,t.y)){q=!1;break}if(0===e)continue;let i=_[e-1],r=i.x===t.x?2:1;if(d(4),i.x===t.x&&i.y===t.y||i.x!==t.x&&i.y!==t.y||n.entersSegment(i.x,i.y,t.x,t.y)||!h(i,t,$||r,r)||(1===e||e===_.length-1)&&!w(i,t,a,c,o,s)){q=!1;break}$=r}if(q){let e=g(_);if(e)return e}}f(12);for(let y=0;y<4;y++){d(12);let m=y<2,u=y%2==0?-1:1,x,p;for(let e of i){d(6);let t=e.stub.x-e.port.x,i=e.stub.y-e.port.y;if(m?0===t&&Math.sign(i)===u:0===i&&Math.sign(t)===u){x=e;break}}for(let e of r){d(6);let t=e.stub.x-e.port.x,i=e.stub.y-e.port.y;if(m?0===t&&Math.sign(i)===u:0===i&&Math.sign(t)===u){p=e;break}}if(!x||!p)continue;let b=m?x.port.y:x.port.x,w=m?p.port.y:p.port.x;if(d(4),b===w)continue;let v=u*(w-b)<0;f(2);let k=M(e,t,v?p:x,[v?x:p],a,n,o,l,s,h,g,void 0,c,v);if(k)return k}}}(eN,eu,h,y,x,eb(),c,V,f,I,s,Math.max(.5,$))}finally{ea.leaveQuery(R)}}void 0!==$&&(c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")),!eA&&j&&j();let e=e=>{let t=_(E(eN,eu,[...h,...y],[m,p],K,c,32768-z,eT,V,e,eb,D(),x,q()));try{for(let e of y){if(eA)break;eb().entersSegment(e.stub.x,e.stub.y,e.port.x,e.port.y)||A(()=>{ea.enterQuery(R);try{t.route(h,e.stub,t=>{let i=W(l([...t,e.port]));return!!i&&(eA=i,!0)},I)}finally{ea.leaveQuery(R)}})}}finally{t.retire()}};eA||e(!1),eA||"cross-hierarchy route has no bounded clear corridor"!==eY||e(!0)}}catch(e){if(!(e instanceof X))throw e;eY=e.reason}if(!eA){if(0===I&&ew&&ev&&void 0!==$&&void 0!==x[eM].paintStrokeWidth&&eS<ev.left&&eS<ev.right&&eS<ev.bottom&&"cross-hierarchy route has no bounded clear corridor"===eY)continue;f(eY)}ei.add(d)}let eX=eA;B.label&&!eX.some((e,t)=>t>0&&A(J.labelPosition,eX[t-1],e))&&f("cross-hierarchy route lost its reserved label corridor"),(j+=eX.length-J.points.length)>2048&&f("agentic local cross-hierarchy route-point limit"),a.edges[d]={...J,points:eX},et.add(d),W=!0}finally{try{if(B)for(let e of B)e.retire()}finally{R?.release()}}W&&ea&&ea.publish(d,a.edges[d].points,!1!==i.edges[d].visible&&!y?.connections.has(d));break}if(y?.connections.size){let s=new Set;for(let[h,g]of y.connections){let d=i.edges[h],x=a.edges[h],b=a.edges.map((e,t)=>({...e,style:!1===i.edges[t].visible||y.connections.has(t)&&!s.has(t)?"invisible":"solid"})),M=b.reduce((e,t,i)=>e+(i===h||"invisible"===t.style?0:Math.max(0,t.points.length-1)),0),w=new Set;for(let e=n[g.interior];e>=0;e=n[m+e])--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),w.add(e);let v=[...Z];for(let e=0;e<u.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=p[e].headerHeight??p[e].padding.top;w.has(e)?t>0&&v.push({...u[e],height:t}):v.push(u[e])}let k=function(i,r,a,n,o,s){let{work:h,fail:g}=s,c=n.connections.get(o),d=n.clearance,f=i.nodes.length,y=r.groups,m=y[c.container],u=0,x=e=>{u+e>s.remainingVertices&&g("agentic local cross-hierarchy visibility-expansion limit"),s.reserveVertices(e),u+=e},p=()=>{--h.pairs<0&&g("agentic local cross-hierarchy obstacle-work limit")},b=(e,t)=>(x(1),{x:e,y:t}),M=i.nodes.map((e,t)=>(p(),{...r.nodes[t],width:e.width,height:e.height})),w=[...M,...y][c.interior],v=new Set;for(let e=a[c.interior];e>=0;e=a[f+e])p(),v.add(e);let k=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}),S=M.map((e,t)=>(p(),t===c.interior?e:k(e,d)));for(let[e,t]of(y.forEach((e,t)=>{if(p(),v.has(t)){let i=n.groups[t].headerHeight??n.groups[t].padding.top;i>0&&S.push(k({...e,height:i},2))}else S.push(t+f===c.interior?e:k(e,d))}),i.edges.entries())){if(p(),!t.label)continue;let i=n.connections.get(e),a=i&&y[i.container],o=i&&a?a.x+i.labelInset+t.label.width/2:r.edges[e]?.labelPosition?.x,l=i&&a?a.y+i.rowOffset:r.edges[e]?.labelPosition?.y;t.label&&void 0!==o&&void 0!==l&&S.push(k({x:o-t.label.width/2,y:l-t.label.height/2,width:t.label.width,height:t.label.height},2))}let N=n.groups[c.container].headerHeight??n.groups[c.container].padding.top,P={x:m.x,y:m.y+N+2,width:m.width,height:m.height-N-2},A=m.y+c.rowOffset,F=b(m.x,A),Y=b(m.x+n.groups[c.container].padding.left-d,A),T=0,X=0;for(let[e,t]of i.edges.entries())p(),(t.source===c.interior||t.target===c.interior)&&(T++,e<o&&X++);let C=[...new Set([(X+1)/(T+1),.5,.25,.75])],L=[],O=c.interior>=f?n.groups[c.interior-f]:void 0,R=w.y+(O?(O.headerHeight??O.padding.top)+2:0);for(let e of["L","R","B","T"])for(let t of C){if(p(),"T"===e&&O&&(O.headerHeight??O.padding.top)>0)continue;let i="L"===e?w.x:"R"===e?w.x+w.width:w.x+t*w.width,r="T"===e?w.y:"B"===e?w.y+w.height:R+t*(w.y+w.height-R),a=b(i,r),n=b(i+("L"===e?-d:"R"===e?d:0),r+("T"===e?-d:"B"===e?d:0));--h.arcs<0&&g("agentic local cross-hierarchy visibility-arc limit"),L.push({port:a,stub:n,penalty:0})}let W=E(P,S,L,[Y],d,h,s.remainingVertices,e=>{if("cross-hierarchy route has no bounded clear corridor"===e)throw new I(e);return g(e)},x,!1,void 0,s.queryWorkspaces);for(let i of L){let r,a=(e,t)=>{p();let{port:r,stub:a}=i;if(e.x===r.x&&e.y===r.y&&t.x===a.x&&t.y===a.y)return!0;let n=r.y===a.y;if(n?e.y===t.y:e.x===t.x){if(n?e.y!==r.y:e.x!==r.x)return!0;let i=Math.max(Math.min(n?e.x:e.y,n?t.x:t.y),Math.min(n?r.x:r.y,n?a.x:a.y)),o=Math.min(Math.max(n?e.x:e.y,n?t.x:t.y),Math.max(n?r.x:r.y,n?a.x:a.y));return i>o||i===o&&i===(n?a.x:a.y)}let o=n?e.x:r.x,l=n?r.y:e.y;return!(o>=Math.min(e.x,t.x)&&o<=Math.max(e.x,t.x)&&l>=Math.min(e.y,t.y)&&l<=Math.max(e.y,t.y)&&o>=Math.min(r.x,a.x)&&o<=Math.max(r.x,a.x)&&l>=Math.min(r.y,a.y)&&l<=Math.max(r.y,a.y))||o===a.x&&l===a.y};try{W.route([i],Y,i=>{let a="source"===c.containerEnd?[F,...i.toReversed()]:[...i,F],o=0,h;for(let e of a)p(),(!h||h.x!==e.x||h.y!==e.y)&&o++,h=e;x(o);let g=l(a),f="source"===c.containerEnd?g[0]:g.at(-1),u="source"===c.containerEnd?g[1]:g.at(-2);if(f.x!==m.x||f.y!==A||u.y!==A||u.x-f.x<c.minimumLead)return!1;let M="source"===c.containerEnd?g.at(-1):g[0],k="source"===c.containerEnd?g.at(-2):g[1];if(!(M.x>=w.x&&M.x<=w.x+w.width&&M.y>=w.y&&M.y<=w.y+w.height&&(M.x===w.x&&k.y===M.y&&k.x<M.x||M.x===w.x+w.width&&k.y===M.y&&k.x>M.x||M.y===w.y&&k.x===M.x&&k.y<M.y||M.y===w.y+w.height&&k.x===M.x&&k.y>M.y))||Math.abs(k.x-M.x)+Math.abs(k.y-M.y)<d)return!1;let S=c.label?b(m.x+c.labelInset+c.label.width/2,A):void 0;if(S&&!g.some((e,i)=>i>0&&t(S,g[i-1],e)))return!1;for(let[t,i]of y.entries())if(v.has(t)){let r=n.groups[t].headerHeight??n.groups[t].padding.top;for(let t=1;t<g.length;t++)if(p(),r>0&&e(g[t-1],g[t],{...i,height:r}))return!1}let N={points:g,...S?{labelPosition:S}:{}};return!!s.accept(N)&&(r=N,!0)},a)}catch(e){if(!(e instanceof I))throw e}if(r)return r}return g("cross-hierarchy route has no bounded clear corridor")}(i,a,n,y,h,{work:c,remainingVertices:32768-z,reserveVertices:V,queryWorkspaces:D(),fail:f,accept(t){let a=t.points;if(a.length<2||a.some((e,t)=>!Number.isFinite(e.x+e.y)||t>0&&e.x!==a[t-1].x&&e.y!==a[t-1].y))throw TypeError("Ancestor boundary producer returned invalid points");if(Y(a,c,f))return!1;let n="source"===g.containerEnd,l=u[g.container],s=n?a[0]:a.at(-1),m=n?a[1]:a.at(-2),x=p[g.container].headerHeight??p[g.container].padding.top;if(Math.abs(s.x-l.x)>1e-7||s.y<l.y+x||s.y>l.y+l.height||m.y!==s.y||m.x-s.x<g.minimumLead)return!1;let w=n?a.at(-1):a[0],k=n?a.at(-2):a[1],S=ee[g.interior];if(w.x<S.x-1e-7||w.x>S.x+S.width+1e-7||w.y<S.y-1e-7||w.y>S.y+S.height+1e-7||!(1e-7>Math.abs(w.x-S.x)&&k.y===w.y&&k.x<w.x||1e-7>Math.abs(w.x-S.x-S.width)&&k.y===w.y&&k.x>w.x||1e-7>Math.abs(w.y-S.y)&&k.x===w.x&&k.y<w.y||1e-7>Math.abs(w.y-S.y-S.height)&&k.x===w.x&&k.y>w.y)||Math.abs(k.x-w.x)+Math.abs(k.y-w.y)<y.clearance||d.label&&(!t.labelPosition||!a.some((e,i)=>i>0&&A(t.labelPosition,a[i-1],e))))return!1;for(let t=1;t<a.length;t++)for(let i of v)if(--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),e(a[t-1],a[t],i))return!1;return c.pairs-=r(i,"proposal")*Math.max(0,a.length-1)*M+a.length+M,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"),void 0!==o(a,h,b,i,G,Q)}});(j+=k.points.length-x.points.length)>2048&&f("agentic local cross-hierarchy route-point limit"),a.edges[h]={...x,...k},s.add(h),ei.add(h)}}J&&(en=W(i,a,Z,u,ee,p,c,V,f,ei,K,$)),(ei.size||void 0!==$&&0===i.maximumEdgeBendRadius)&&R(i,a,ei,c,f,en);let es=[...h.keys()];if(y?.connections.size){for(let e of y.connections.keys())h.has(e)||es.push(e);es.sort((e,t)=>e-t)}if(J){let e=!1;for(let t of ei)c.pairs-=es.length+1,c.pairs<0&&f("agentic marker full-proof work limit"),es.includes(t)||(--c.arcs<0&&f("agentic marker full-proof capacity limit"),es.push(t),e=!0);e&&es.sort((e,t)=>(--c.pairs<0&&f("agentic marker full-proof work limit"),e-t))}if(J){c.arcs-=i.edges.length+1,c.pairs-=i.edges.length,c.arcs<0&&f("agentic marker full-proof capacity limit"),c.pairs<0&&f("agentic marker full-proof work limit");let e=Array(i.edges.length);for(let t=0;t<i.edges.length;t++)e[t]=t;return{...a,expandedVertices:z,boundaryRoutes:e}}return{...a,expandedVertices:z,boundaryRoutes:es}}(i,G,m,p,U.map(e=>e.direction),g,0,n,z):(void 0!==i.maximumEdgeStrokeWidth&&0===i.maximumEdgeBendRadius&&(--g.arcs<0&&n("agentic local cross-hierarchy visibility-arc limit"),--g.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),R(i,G,new Set,g,n)),G)}(h,e=>a(e,c,d,f,m),d,0,f);let _="LR"===h.direction||"RL"===h.direction,q="BT"===h.direction||"RL"===h.direction,$=new Set,Q=!1;for(let e of u){if(void 0!==e.parent)throw TypeError("Measured parent requires a compound scope");if(void 0!==e.modelOrder){if(!Number.isSafeInteger(e.modelOrder)||e.modelOrder<0)throw TypeError("Invalid measured model order");Q=!0}if(void 0!==e.partition&&(!Number.isSafeInteger(e.partition)||e.partition<0||e.partition>1e4))throw TypeError("Invalid measured partition");if($.has(e.id))throw TypeError("Measured graph node identities must be unique");if($.add(e.id),!V(e.width,!0)||!V(e.height,!0))throw TypeError("Measured node dimensions must be finite and positive")}let G=u.map(()=>[]),J=u.map(()=>[]),K=new Uint32Array(u.length),Z=!1,ee=!1;for(let e=0;e<x.length;e++){let t=x[e];if(!Number.isInteger(t.source)||!Number.isInteger(t.target)||t.source<0||t.source>=u.length||t.target<0||t.target>=u.length)throw TypeError("Measured edge endpoint is outside the node array");if(!Number.isSafeInteger(t.minSpan)||t.minSpan<1)throw TypeError("Measured edge minimum span must be a positive integer");if(void 0!==t.short&&!0!==t.short)throw TypeError("Invalid measured short-edge preference");if(void 0!==t.boundaryMarker&&![t.boundaryMarker.inset,t.boundaryMarker.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured ancestor marker dimensions");if(ee||=!0===t.short,t.label&&(!V(t.label.width,!1)||!V(t.label.height,!1)))throw TypeError("Measured edge label dimensions must be finite and nonnegative");if(t.source===t.target){Z=!0;continue}J[t.source].push(e),G[t.target].push(e),K[t.target]=K[t.target]+1}let et=u.some(e=>(e.partition??0)!==(u[0]?.partition??0));if(et&&x.some(e=>(u[e.source].partition??0)>(u[e.target].partition??0))){let e=x.map(e=>(u[e.source].partition??0)>(u[e.target].partition??0)),t=a({...h,edges:x.map((t,i)=>e[i]?{...t,source:t.target,target:t.source}:t)},c,d,f,m);return{...t,edges:t.edges.map((t,i)=>e[i]?{...t,points:[...t.points].reverse()}:t)}}if(Z){let t=[...u],r=[...x],o=[...h.loopPorts??[]],l=new Int32Array(x.length).fill(-1),s=0;for(let e=0;e<x.length;e++){let i,a=x[e];if(a.source!==a.target)continue;(4096===t.length||16384===r.length)&&d("agentic local loop-expansion limit");do i=`\0agentic-loop:${s++}`;while($.has(i))$.add(i);let n=t.length;t.push({id:i,width:_?1:40,height:_?40:1,...et?{partition:u[a.source].partition??0}:{}}),r[e]={...a,target:n,...a.label?{label:_?{width:a.label.width,height:2*a.label.height+8}:{width:2*a.label.width+8,height:a.label.height}}:{}},l[e]=r.length,o.push([e,r.length]),r.push({source:a.source,target:n,minSpan:a.minSpan})}let y=a({...h,nodes:t,edges:r,loopPorts:o},c,d,f,m);return function(t,r,a){if(a.loopPairs<=0||t.groups?.length||t.nodes.length>256||t.edges.length>128||r.edges.reduce((e,t)=>e+t.points.length,0)>2048)return r;let o=e=>(a.loopPairs-=e)>=0,l="LR"===t.direction||"RL"===t.direction,s="RL"===t.direction||"BT"===t.direction?-1:1,h=l?"x":"y",c=l?"y":"x",d=(e,t)=>l?{x:e,y:t}:{x:t,y:e},f=t.nodes.map((e,t)=>({...r.nodes[t],width:e.width,height:e.height})),y=t.edges.map((e,t)=>{let i=r.edges[t].labelPosition;return e.label&&i?{x:i.x-e.label.width/2,y:i.y-e.label.height/2,width:e.label.width,height:e.label.height}:void 0}),m=r.edges.map((e,i)=>({points:e.points,style:!1===t.edges[i].visible?"invisible":"solid"})),u=()=>m.map(e=>({points:e.points,visible:"invisible"!==e.style})),x=(e,t)=>Math.min(...t.slice(1).map((i,r)=>{let a=t[r],n=Math.max(Math.min(a.x,i.x),Math.min(Math.max(a.x,i.x),e.x)),o=Math.max(Math.min(a.y,i.y),Math.min(Math.max(a.y,i.y),e.y));return Math.abs(e.x-n)+Math.abs(e.y-o)})),p=!1;for(let[b,M]of t.edges.entries()){let w=r.edges[b],v=w.points;if(M.source!==M.target||!1===M.visible||v.length<=4)continue;let k=v[0],S=v.at(-1);if(Math.abs(k[h]-S[h])>1e-7||Math.abs(k[c]-S[c])<8-1e-7)continue;let N=[...f,...y.filter((e,t)=>!!e&&t!==b)],E=[...new Set([...v.map(e=>e[h]),...N.flatMap(e=>l?[e.x-8,e.x+e.width+8]:[e.y-8,e.y+e.height+8]),k[h]+24*s])].filter(e=>(e-k[h])*s>=24);E.sort((e,t)=>(e-t)*s);let I=new Set([b]),P=m.reduce((e,t)=>e+t.points.length,0);if(a.loopPairs-=P*P,a.loopPairs<0)return r;let A=g(u(),I);for(let g of E.slice(0,32)){let f=[{...k},d(g,k[c]),d(g,S[c]),{...S}];if(f.some(e=>e.x<t.padding||e.y<t.padding||e.x>r.width-t.padding||e.y>r.height-t.padding))continue;if(a.loopPairs-=f.length*N.length+f.length*P,a.loopPairs<0)return r;if(f.slice(1).some((t,i)=>N.some(r=>e(f[i],t,r))))continue;let u=w.labelPosition,E=y[b],I=t=>f.slice(1).some((i,r)=>e(f[r],i,t));if(u&&M.label&&(x(u,f)>x(u,v)+1e-7||E&&I(E))){let n=(l?M.label.width:M.label.height)/2,o=(l?M.label.height:M.label.width)/2,f=n+16,y=(g-k[h])*s-n-8;if(f>y)continue;let x=k[h]+s*Math.max(f,Math.min(y,(u[h]-k[h])*s)),p=[d(x,Math.min(k[c],S[c])-o-4),d(x,Math.max(k[c],S[c])+o+4)];for(let n of(p.sort((e,t)=>Math.abs(e.x-w.labelPosition.x)+Math.abs(e.y-w.labelPosition.y)-Math.abs(t.x-w.labelPosition.x)-Math.abs(t.y-w.labelPosition.y)),u=void 0,p)){let o={x:n.x-M.label.width/2,y:n.y-M.label.height/2,width:M.label.width,height:M.label.height};if(a.loopPairs-=N.length+P,a.loopPairs<0)return r;if(!(o.x<t.padding||o.y<t.padding||o.x+o.width>r.width-t.padding||o.y+o.height>r.height-t.padding)&&!(N.some(e=>i(o,e))||I(o)||m.some((t,i)=>i!==b&&"invisible"!==t.style&&t.points.slice(1).some((i,r)=>e(t.points[r],i,o))))){u=n,E=o;break}}if(!u)continue}let F=n(f,b,m,t,o,o);if(a.loopPairs<0)return r;if(!(void 0===F||F>A)){w.points=f,m[b].points=f,u&&(w.labelPosition={...u}),y[b]=E,p=!0;break}}}if(!p)return r;let b=1/0,M=1/0,w=-1/0,v=-1/0,k=(e,t,i=0,r=0)=>{b=Math.min(b,e),M=Math.min(M,t),w=Math.max(w,e+i),v=Math.max(v,t+r)};f.forEach(e=>k(e.x,e.y,e.width,e.height)),r.edges.forEach((e,i)=>{e.points.forEach(e=>k(e.x,e.y));let r=e.labelPosition,a=t.edges[i].label;r&&a&&k(r.x-a.width/2,r.y-a.height/2,a.width,a.height)});let S=t.padding-b,N=t.padding-M;return r.nodes=r.nodes.map(e=>({x:e.x+S,y:e.y+N})),r.edges=r.edges.map(e=>({...e,points:e.points.map(e=>({x:e.x+S,y:e.y+N})),...e.labelPosition?{labelPosition:{x:e.labelPosition.x+S,y:e.labelPosition.y+N}}:{}})),r.width=w-b+2*t.padding,r.height=v-M+2*t.padding,r}(h,{...y,topology:"layered",nodes:y.nodes.slice(0,u.length),edges:y.edges.slice(0,x.length).map((e,t)=>{let i=l[t];if(i<0)return e;let r=y.edges[i].points,a=e.labelPosition;if(a&&x[t].label){let e=_?a.x:a.y,i=_?a.y:a.x,n=-1;for(let t=1;t<r.length;t++){let a=r[t-1],o=r[t],l=_?a.x:a.y,s=_?o.x:o.y,h=_?a.y:a.x;if(h===(_?o.y:o.x)&&e>=Math.min(l,s)&&e<=Math.max(l,s)){n=i<h?-1:1;break}}let o=((_?x[t].label.height:x[t].label.width)/2+4)*n;a=_?{x:a.x,y:a.y+o}:{x:a.x+o,y:a.y}}return{...e,...a?{labelPosition:a}:{},points:e.points.concat([...r].reverse())}})},m)}let ei=!et&&!Q&&!ee&&function(e,t,i,r){if(!e.shareCompleteFans||e.edges.some(e=>e.label||1!==e.minSpan))return;let a=[],n=[];for(let r=0;r<e.nodes.length;r++)if(!t[r].length&&i[r].length)a.push(r);else{if(i[r].length||!t[r].length)return;n.push(r)}if(!a.length||!n.length||1===a.length&&1===n.length||e.edges.length!==a.length*n.length)return;let o=new Map(a.map((e,t)=>[e,t])),l=new Map(n.map((e,t)=>[e,t])),s=new Set;for(let t of e.edges){if(!o.has(t.source)||!l.has(t.target))return;let i=t.source*e.nodes.length+t.target;if(s.has(i))return;s.add(i)}let h="LR"===e.direction||"RL"===e.direction,g="BT"===e.direction||"RL"===e.direction,c=t=>h?e.nodes[t].height:e.nodes[t].width,d=t=>h?e.nodes[t].width:e.nodes[t].height,f=t=>t.reduce((e,t)=>e+c(t),0)+(t.length-1)*e.nodeSpacing,y=f(a),m=f(n),u=Math.max(y,m),x=Math.max(...a.map(d)),p=Math.max(...n.map(d)),b=Math.max(e.layerSpacing,2*Math.max(12,e.edgeSpacing??6)+(e.edgeSpacing??6)),M=x+b+p;Number.isFinite(M+u+2*e.padding)||r("agentic local coordinate-range limit");let w=new Float64Array(e.nodes.length),v=new Float64Array(e.nodes.length);for(let[t,i,r,o]of[[a,y,0,x],[n,m,x+b,p]]){let a=(u-i)/2;for(let i of t)w[i]=a+c(i)/2,v[i]=r+(o-d(i))/2,a+=c(i)+e.nodeSpacing}let k=(t,i)=>h?{x:e.padding+(g?M-i:i),y:e.padding+t}:{x:e.padding+t,y:e.padding+(g?M-i:i)},S=e.nodes.map((e,t)=>k(w[t]-c(t)/2,v[t]+(g?d(t):0))),N=e.edges.map(t=>{if(e.placementOnly&&!e.cycleOriented&&!e.loopPorts?.length)return{points:[]};let i=[],r=u/2,a=x+b/3,n=x+2*b/3;for(let[e,o]of[[w[t.source],v[t.source]+d(t.source)],[w[t.source],a],[r,a],[r,n],[w[t.target],n],[w[t.target],v[t.target]]]){let t=k(e,o),r=i.at(-1),a=i.at(-2);r?.x===t.x&&r.y===t.y||(a&&r&&(a.x===r.x&&r.x===t.x&&(r.y-a.y)*(t.y-r.y)>=0||a.y===r.y&&r.y===t.y&&(r.x-a.x)*(t.x-r.x)>=0)&&i.pop(),i.push(t))}return{points:i}});return{topology:"layered",width:2*e.padding+(h?M:u),height:2*e.padding+(h?u:M),nodes:S,edges:N,expandedVertices:S.length,sharedEdges:e.edges.map((e,t)=>t)}}(h,G,J,d);if(ei)return ei;let er=!et&&!Q&&!ee&&c(h);if(er)return{...er,expandedVertices:u.length};let ea=new Uint32Array(u.length),en=u.flatMap((e,t)=>0===K[t]?[t]:[]),eo=0;for(let e=0;e<en.length;e++){let t=en[e];for(let e of J[t]){let i=x[e],r=ea[t]+H(i,h.compactPrivateRanks);r>=4096&&d("agentic local rank-expansion limit"),ea[i.target]=Math.max(ea[i.target],r),eo=Math.max(eo,r),K[i.target]=K[i.target]-1,0===K[i.target]&&en.push(i.target)}}if(en.length!==u.length){if(et){let e=h.authoredCycleOrder?Uint32Array.from(u,(e,t)=>t):z(G,J,x),t=x.map(t=>(u[t.source].partition??0)===(u[t.target].partition??0)&&e[t.source]>e[t.target]),i=a({...h,cycleOriented:!0,edges:x.map((e,i)=>t[i]?{...e,source:e.target,target:e.source}:e)},c,d,f,m);return{...i,edges:i.edges.map((e,i)=>t[i]?{...e,points:[...e.points].reverse()}:e)}}return function(e,t,i,r,a,n,o){let{nodes:l,edges:s}=e,h=z(t,i,s),c=j(i,s),d=e=>s.reduce((t,i)=>t+ +(e[i.source]>e[i.target]),0),f=(t,i,a,n=!1,o=!1)=>{let h=s.map(e=>t[e.source]>t[e.target]),g=l.map((e,t)=>n?l.length-1-t:t),c=new Uint32Array(l.length);g.forEach((e,t)=>{c[e]=t});let d=s.map((e,t)=>o?s.length-1-t:t),f=new Uint32Array(s.length);d.forEach((e,t)=>{f[e]=t});let y=r({...e,shareCompleteFans:!1,cycleOriented:!0,nodes:g.map(e=>l[e]),edges:d.map(e=>{let t=s[e],i=h[e]?t.target:t.source,r=h[e]?t.source:t.target;return{...t,source:c[i],target:c[r]}}),loopPorts:e.loopPorts?.map(([e,t])=>[f[e],f[t]])},i,a);return{...y,nodes:l.map((e,t)=>y.nodes[c[t]]),edges:s.map((e,t)=>{let i=y.edges[f[t]];return h[t]?{...i,points:[...i.points].reverse()}:i})}};if(e.authoredCycleOrder)return f(Uint32Array.from(l,(e,t)=>t),a,n,!1,!0);let y=d(c)<=d(h)?c:h,m=f(y,a,n);if(l.length>48||s.length>128||s.reduce((e,t)=>e+t.minSpan,0)>128||(m.expandedVertices??0)>1024||o.attempts<=0)return m;let u=e=>{let t=e.edges.reduce((e,t,i)=>e+(!1===s[i].visible?0:t.points.length),0);if(!(t>2048||t*t>o.scorePairs))return o.scorePairs-=t*t,g(e.edges.map((e,t)=>({...e,visible:s[t].visible})))},x=u(m);if(void 0===x||0===x)return m;let p=e=>e.edges.reduce((e,t,i)=>e+(!1===s[i].visible?0:Math.max(0,t.points.length-2)),0),b=p(m),M=m.width*m.height,w=(e,t,i)=>s.map(t=>+(e[t.source]>e[t.target])).join("")+":"+t+":"+i,v=e.compactPrivateRanks&&l.length>16?2:12,k=new Set([w(y,!1,!1)]),S=(l.length<=12?l.map((e,t)=>t):l.length<=20?[0,Math.floor(l.length/4),Math.floor(l.length/2),Math.floor(3*l.length/4),l.length-1]:[]).flatMap(e=>{let r=t=>(t-e+l.length)%l.length,a=s.map(e=>({...e,source:r(e.source),target:r(e.target)})),n=i.slice(e).concat(i.slice(0,e)),o=t.slice(e).concat(t.slice(0,e)),h=j(n,a),g=z(o,n,a);return[Uint32Array.from(l,(e,t)=>h[r(t)]),Uint32Array.from(l,(e,t)=>g[r(t)])]}),N=e.compactPrivateRanks&&l.length>16,E=N&&3>=d(y)?function(e,t,i=2){let r=e.nodes.length,a=e.edges;if(!r||r>20||a.length>48||(t.blockPairs??2e6)<=0)return[];let n=new Uint16Array(r),o=new Uint16Array(r),l=new Uint16Array(r),s=new Float64Array(r),h=new Int32Array(r);for(let e of a)n[e.target]=n[e.target]+1;let g=!1,c=e=>{let i=t.blockPairs??2e6;return i<e?(g=!0,!1):(t.blockPairs=i-e,!0)},d=(t,i,g=-1)=>{if(!c(r+4))return;for(let e of(o.set(n),s.fill(0),[t,i,g]))if(e>=0){let t=a[e];o[t.target]=o[t.target]-1,o[t.source]=o[t.source]+1}let d=0;for(let e=0;e<r;e++)o[e]||(l[d++]=e);for(let r=0;r<d;r++){if(!c(a.length))return;let n=l[r];h[n]=r;for(let r=0;r<a.length;r++){let h=a[r],c=r===t||r===i||r===g,f=c?h.target:h.source,y=c?h.source:h.target;f===n&&(s[y]=Math.max(s[y],s[n]+H(h,e.compactPrivateRanks)),o[y]=o[y]-1,o[y]||(l[d++]=y))}}if(d!==r||!c(a.length))return;let f=0;for(let e of a)f+=Math.abs(s[e.target]-s[e.source]);return{order:h.slice(),span:f}},f=[];for(let e=0;e<a.length&&!g;e++){let t=d(e,-1);t&&f.push(t)}if(f.length||g)return f;for(let e=0;e<a.length&&!g;e++)for(let t=e+1;t<a.length&&!g;t++){let i=d(e,t);i&&f.push(i)}if(f.length||g||i<3)return f;let y=new Uint8Array(a.length),m=new Uint8Array(r),u=new Int32Array(r),x=[],p=new Set,b=()=>{if(g)return;let e=x.slice().sort((e,t)=>e-t).join(",");if(p.has(e))return;p.add(e);let t=(()=>{m.fill(0),u.fill(-1);let e=t=>{m[t]=1;for(let i=0;i<a.length;i++){if(!c(1))return;let r=a[i];if(!(y[i]||r.source!==t)){if(1===m[r.target]){let e=[i];for(let i=t;i!==r.target;){let t=u[i];e.push(t),i=a[t].source}return e}if(0===m[r.target]){u[r.target]=i;let t=e(r.target);if(t||g)return t}}}m[t]=2};for(let t=0;t<r;t++)if(!m[t]){let i=e(t);if(i||g)return i}})();if(!g){if(!t){let e=d(x[0]??-1,x[1]??-1,x[2]??-1);e&&f.push(e);return}if(3!==x.length){for(let e of t)if(y[e]=1,x.push(e),b(),x.pop(),y[e]=0,g)return}}};return b(),f}(e,o,3):[];E.sort((e,t)=>t.span-e.span);let I=[...E.length>1?[E[0].order,E.at(-1).order,...E.slice(1,-1).map(e=>e.order)]:E.map(e=>e.order),h,c,...S,Uint32Array.from(l,(e,t)=>t)],P=E.length?[[!1,!1],[!0,!0],[!0,!1],[!1,!0]]:[[!0,!0],[!0,!1],[!1,!0],[!1,!1]];for(let e=0;e<I.length*P.length;e++){let t=I[N?e%I.length:Math.floor(e/P.length)],[i,r]=P[N?Math.floor(e/I.length):e%P.length],a=w(t,i,r);if(!k.has(a)){if(k.add(a),v--<=0||o.attempts--<=0||o.routing.pairs<0||o.routing.arcs<0||o.routing.swaps<0)return m;try{let e=f(t,e=>{throw new U(e)},o.routing,i,r),a=u(e);if(void 0===a)return m;let n=p(e),l=e.width*e.height;if((a<x||a===x&&(n<b||n===b&&l<M))&&(m=e,x=a,b=n,M=l),0===x)break}catch(e){if(!(e instanceof U))throw e}}}return m}(h,G,J,(e,t,i)=>a(e,c,t,i,m),d,f,m)}let el=ee?new Uint32Array(u.length):void 0,es=ee?new Uint32Array(u.length):void 0;if(ee)for(let e of x){let t=e.short?100:1;el[e.target]=el[e.target]+t,es[e.source]=es[e.source]+t}for(let e=0;!et&&e<4;e++){let e=!1;for(let t of[!0,!1])for(let i=0;i<en.length;i++){let r=en[t?en.length-1-i:i],a=0,n=eo;for(let e of G[r]){let t=x[e];a=Math.max(a,ea[t.source]+H(t,h.compactPrivateRanks))}for(let e of J[r]){let t=x[e];n=Math.min(n,ea[t.target]-H(t,h.compactPrivateRanks))}let o=ee?es[r]>=el[r]:J[r].length>=G[r].length,l=J[r].length&&o?n:a;l!==ea[r]&&(ea[r]=l,e=!0)}if(!e)break}if(et){let e=new Map;for(let t of en){let i=u[t].partition??0,r=e.get(i)??[];r.push(t),e.set(i,r)}let t=0;for(let i of[...e.keys()].sort((e,t)=>e-t)){let r=t;for(let a of e.get(i)){let e=t;for(let t of G[a]){let i=x[t];e=Math.max(e,ea[i.source]+H(i,h.compactPrivateRanks))}e>=4096&&d("agentic local rank-expansion limit"),ea[a]=e,r=Math.max(r,e)}t=r+1}}if(et&&ee){let e=new Map;for(let[t,i]of u.entries()){let r=i.partition??0,a=e.get(r);a?(a.lower=Math.min(a.lower,ea[t]),a.upper=Math.max(a.upper,ea[t])):e.set(r,{lower:ea[t],upper:ea[t]})}for(let t=0;t<4;t++){let t=!1;for(let i of[!0,!1])for(let r=0;r<en.length;r++){let a=en[i?en.length-1-r:r],n=e.get(u[a].partition??0),o=n.lower,l=n.upper;for(let e of G[a]){let t=x[e];o=Math.max(o,ea[t.source]+H(t,h.compactPrivateRanks))}for(let e of J[a]){let t=x[e];l=Math.min(l,ea[t.target]-H(t,h.compactPrivateRanks))}let s=J[a].length&&es[a]>=el[a]?l:o;s!==ea[a]&&(ea[a]=s,t=!0)}if(!t)break}}let eh=!et&&function(e,t,i=!1){let r=e.nodes.length,a=e.edges;if(0===r)return new Float64Array(0);if(t.rankPairs<=0||r>64||a.length>128||a.reduce((e,t)=>e+t.minSpan,0)>128)return;let n=i?Int32Array.from(a,e=>e.short?100:1):new Int32Array(a.length).fill(1),o=new Float64Array(r),l=new Int32Array(r),s=new Int32Array(r);for(let h=0;h<128;h++){o.fill(0),l.fill(-1),s.fill(0);let h=-1;for(let g=0;g<r;g++){h=-1;for(let i=0;i<a.length;i++){let r=a[i];if(t.rankPairs-=2,t.rankPairs<0)return;let g=H(r,e.compactPrivateRanks);o[r.target]<o[r.source]+g&&(o[r.target]=o[r.source]+g,l[r.target]=r.source,s[r.target]=i+1,h=r.target),n[i]>0&&o[r.source]<o[r.target]-g&&(o[r.source]=o[r.target]-g,l[r.source]=r.target,s[r.source]=-i-1,h=r.source)}if(h<0){let t=i?a.reduce((e,t)=>e+(t.short?100:1)*(o[t.target]-o[t.source]),0):a.reduce((e,t)=>e+o[t.target]-o[t.source],0),r=a.reduce((t,i,r)=>t+n[r]*H(i,e.compactPrivateRanks),0);if(t!==r)throw Error(`dual rank mismatch ${t} ${r}`);return o}}let g=h;for(let e=0;e<r;e++)g=l[g];let c=g,d=[],f=1/0,y=0;do{let t=s[g],i=Math.abs(t)-1;if(i<0)throw Error("missing residual predecessor");d.push(t),y+=Math.sign(t)*H(a[i],e.compactPrivateRanks),t<0&&(f=Math.min(f,n[i])),g=l[g]}while(g!==c&&d.length<=r)if(g!==c||y<=0||!Number.isFinite(f)||f<=0)throw Error(`invalid positive residual cycle ${y} ${f}`);for(let e of d)n[Math.abs(e)-1]=n[Math.abs(e)-1]+Math.sign(e)*f}}(h,m,ee);eh&&ea.set(eh),eo=ea.reduce((e,t)=>Math.max(e,t),0);let eg=u.length;for(let e of x)(eg+=ea[e.target]-ea[e.source]-1)>32768&&d("agentic local expanded-graph limit");if(0===u.length)return Number.isFinite(2*p)||d("agentic local coordinate-range limit"),{topology:"layered",width:2*p,height:2*p,nodes:[],edges:[],expandedVertices:0};let ec=u.map((e,t)=>({rank:ea[t],crossSize:_?e.height:e.width,mainSize:_?e.width:e.height,incoming:[],outgoing:[]})),ed=[],ef=[];for(let e=0;e<x.length;e++){let t=x[e],i=[t.source],r=t.label?Math.floor((ea[t.source]+ea[t.target])/2):-1;for(let a=ea[t.source]+1;a<ea[t.target];a++){let n=a===r,o=ec.length;ec.push({rank:a,crossSize:n?(_?t.label.height:t.label.width)+16:4,mainSize:n?_?t.label.width:t.label.height:0,incoming:[],outgoing:[]}),n&&(ef[e]=o),i.push(o)}i.push(t.target);for(let e=1;e<i.length;e++){let t=i[e-1],r=i[e];ec[t].outgoing.push(r),ec[r].incoming.push(t)}ed.push(i)}let ey=Array.from({length:eo+1},()=>[]),em=new Float64Array(ey.length),eu=new Float64Array(ey.length);for(let e=0;e<ec.length;e++)ey[ec[e].rank].push(e);let ex=Q?e=>{let t=e.filter(e=>u[e]?.modelOrder!==void 0);t.sort((e,t)=>u[e].modelOrder-u[t].modelOrder);let i=0;for(let r=0;r<e.length;r++)u[e[r]]?.modelOrder!==void 0&&(e[r]=t[i++])}:void 0;if(ex)for(let e of ey)ex(e);let ep=0;for(let e=0;e<ey.length;e++){let t=ey[e],i=Math.max(0,t.length-1)*B;for(let r of t){let t=ec[r];i+=t.crossSize,eu[e]=Math.max(eu[e],t.mainSize)}em[e]=i,ep=Math.max(ep,i)}let eb=new Float64Array(ec.length),eM=e=>{let t=(ep-em[e])/2,i=ey[e];for(let e=0;e<i.length;e++){let r=i[e],a=ec[r].crossSize;eb[r]=t+a/2,t+=a+B}};for(let e=0;e<ey.length;e++)eM(e);let ew=new Float64Array(ec.length),ev=(e,t)=>{let i=ey[e],r=!0;for(let e=0;e<i.length;e++){let a=i[e],n=t?ec[a].incoming:ec[a].outgoing,o=0;for(let e=0;e<n.length;e++)o+=eb[n[e]];let l=n.length?o/n.length:eb[a];ew[a]=l,r&&=Number.isFinite(l)}if(i.length<=16&&r)for(let e=1;e<i.length;e++){let t=i[e],r=ew[t],a=e;for(;a>0;){let e=i[a-1];if(0>=(ew[e]-r||e-t))break;i[a--]=e}i[a]=t}else i.sort((e,t)=>ew[e]-ew[t]||e-t);ex?.(i),eM(e)},ek=new Uint32Array(ec.length),eS=ey.slice(1).map(e=>new Uint32Array(e.length+1)),eN=()=>{for(let e=0;e<ey.length;e++){let t=ey[e];for(let e=0;e<t.length;e++)ek[t[e]]=e}},eE=()=>{eN();let e=0;for(let t=0;t+1<ey.length;t++){let i=eS[t];i.fill(0);let r=0,a=ey[t];for(let t=0;t<a.length;t++){let n=ec[a[t]].outgoing;for(let t=0;t<n.length;t++){let a=n[t],o=0;for(let e=ek[a]+1;e>0;e-=e&-e)o+=i[e];e+=r-o}for(let e=0;e<n.length;e++)for(let t=ek[n[e]]+1;t<i.length;t+=t&-t)i[t]=i[t]+1;r+=n.length}}return e},eI=eE(),eP=ey.map(e=>[...e]),eA=()=>{let e=eE();e<eI&&(eI=e,eP=ey.map(e=>[...e]))};for(let e=0;e<4;e++){for(let e=1;e<ey.length;e++)ev(e,!0);eA();for(let e=ey.length-2;e>=0;e--)ev(e,!1);eA()}eP.forEach((e,t)=>{ey[t]=e,e.forEach((e,t)=>{ek[e]=t})});let eF=()=>{eN();for(let e=0;e<4;e++){let e=!1;for(let t=0;t<ey.length;t++){let i=ey[t];for(let t=0;t+1<i.length;t++){if(Q&&u[i[t]]?.modelOrder!==void 0&&u[i[t+1]]?.modelOrder!==void 0)continue;let r=ec[i[t]],a=ec[i[t+1]],n=r.incoming.length*a.incoming.length+r.outgoing.length*a.outgoing.length;if(n>f.swaps)continue;f.swaps-=n;let o=0;for(let e=0;e<r.incoming.length;e++)for(let t=0;t<a.incoming.length;t++)o+=Math.sign(ek[r.incoming[e]]-ek[a.incoming[t]]);for(let e=0;e<r.outgoing.length;e++)for(let t=0;t<a.outgoing.length;t++)o+=Math.sign(ek[r.outgoing[e]]-ek[a.outgoing[t]]);if(o>0){let r=i[t],a=i[t+1];i[t]=a,i[t+1]=r,ek[r]=t+1,ek[a]=t,e=!0}}}if(!e)break}};if(eF(),h.compactPrivateRanks&&u.length<=20&&x.length<=64&&ec.length<=256){let e=eE(),t=128;for(let i of ed.map(e=>e.slice(1,-1)).filter(e=>e.length>1).sort((e,t)=>t.length-e.length)){if(0===e)break;let r=new Map(i.map(e=>[ec[e].rank,[...ey[ec[e].rank]]])),a=e,n,o=!1;for(let e of[0,1,.25,.5,.75]){let l=ey.length+ec.length+16*(ec.length-u.length+x.length);if(t--<=0||(m.blockPairs??2e6)<l){o=!0;break}for(let t of(m.blockPairs=(m.blockPairs??2e6)-l,i)){let i=ec[t].rank,a=ey[i],n=r.get(i);for(let e=0;e<a.length;e++)a[e]=n[e];let o=a.indexOf(t),l=Math.floor((a.length-1)*e);if(o<l)for(let e=o;e<l;e++)a[e]=a[e+1];else for(let e=o;e>l;e--)a[e]=a[e-1];a[l]=t}let s=eE();s<a&&(a=s,n=new Map([...r].map(([e])=>[e,[...ey[e]]])))}for(let[e,t]of n??r)ey[e]=t;if(e=a,o)break}}h.compactPrivateRanks&&u.length>12&&u.length<=20&&x.length<=64&&ec.length<=256&&function(e,t,i,r){let a=new Int32Array(t.length);for(let n of i){if((r.blockPairs??2e6)<=0)return;let i=n.slice(1,-1);if(i.length<2||i.some((e,i)=>1!==t[e].incoming.length||1!==t[e].outgoing.length||t[e].incoming[0]!==n[i]||t[e].outgoing[0]!==n[i+2]||t[e].rank!==t[n[i]].rank+1))continue;for(let t of e)for(let e=0;e<t.length;e++)a[t[e]]=e;let o=i.map(i=>e[t[i].rank].filter(e=>e!==i)),l=i.map(e=>a[e]),s=[];for(let r=0;r<=i.length;r++){let o=n[r],l=n[r+1],h=[];for(let n of e[t[o].rank])for(let e of t[n].outgoing){if(n===o&&e===l)continue;let t=a[n],s=a[e];h.push(t-(r>0&&t>a[o]),s-(r<i.length&&s>a[l]))}s.push(Int32Array.from(h))}let h=!1,g=(e,t,a)=>{let n=s[e],o=1+n.length/2;if((r.blockPairs??2e6)<o)return h=!0,1/0;r.blockPairs=(r.blockPairs??2e6)-o;let l=0;for(let r=0;r<n.length;r+=2){let o=n[r],s=n[r+1],h=o+ +(e>0&&o>=t),g=s+ +(e<i.length&&s>=a);(t-h)*(a-g)<0&&l++}return l},c=0;for(let e=0;e<=i.length;e++)c+=g(e,0===e?a[n[0]]:l[e-1],e===i.length?a[n.at(-1)]:l[e]);if(h)return;if(0===c)continue;let d=Float64Array.from({length:o[0].length+1},(e,t)=>g(0,a[n[0]],t)),f=Float64Array.from(d,(e,t)=>Math.abs(t-l[0])),y=[];for(let e=1;e<i.length&&!h;e++){let t=new Float64Array(o[e].length+1).fill(1/0),i=new Int32Array(t.length),r=new Float64Array(t.length).fill(1/0);for(let a=0;a<t.length&&!h;a++)for(let n=0;n<d.length;n++){if(d[n]>=c)continue;let o=d[n]+g(e,n,a),s=f[n]+Math.abs(a-l[e]);if((o<t[a]||o===t[a]&&s<r[a])&&(t[a]=o,i[a]=n,r[a]=s),h)break}d=t,f=r,y.push(i)}if(h)return;let m=1/0,u=1/0,x=0;for(let e=0;e<d.length;e++){let t=d[e]+g(i.length,e,a[n.at(-1)]);(t<m||t===m&&f[e]<u)&&(m=t,u=f[e],x=e)}if(h)return;if(m>=c)continue;let p=new Int32Array(i.length);p[i.length-1]=x;for(let e=i.length-2;e>=0;e--)p[e]=y[e][p[e+1]];for(let r=0;r<i.length;r++){let a=o[r];a.splice(p[r],0,i[r]),e[t[i[r]].rank]=a}}}(ey,ec,ed,m),h.compactPrivateRanks&&!h.cycleOriented&&eF();for(let e=0;e<ey.length;e++)eM(e);let eY=new Int32Array(ec.length).fill(-1),eT=new Int32Array(ec.length).fill(-1);for(let e of ey){let t=-1;for(let i of e)eY[i]=t,i<u.length&&(t=i);t=-1;for(let i=e.length-1;i>=0;i--){let r=e[i];eT[r]=t,r<u.length&&(t=r)}}let eX=new Float64Array(0),eC=Math.min(4,B);for(let e=0;e<4;e++)for(let e of[!0,!1])for(let t=0;t<ey.length;t++){let i=ey[e?t:ey.length-1-t];for(let t=0;t<i.length;t++){let r,a=e?t:i.length-1-t,n=i[a],o=ec[n],l=o.incoming.length+o.outgoing.length;if(!l)continue;if(l<=2){let t=o.incoming[0]??o.outgoing[0],i=1===l?t:2===o.incoming.length?o.incoming[1]:o.outgoing[+(1!==o.incoming.length)],a=eb[t],n=eb[i];r=e?Math.min(a,n):Math.max(a,n)}else{eX.length<l&&(eX=new Float64Array(l));let t=eX.subarray(0,l),i=0,a=!0;for(let e=0;e<o.incoming.length;e++){let r=eb[o.incoming[e]];t[i++]=r,a&&=Number.isFinite(r)&&!Object.is(r,-0)}for(let e=0;e<o.outgoing.length;e++){let r=eb[o.outgoing[e]];t[i++]=r,a&&=Number.isFinite(r)&&!Object.is(r,-0)}r=(a?t.sort():Array.from(t).sort((e,t)=>e-t))[Math.floor((l-Number(e))/2)]}let s=i[a-1],h=i[a+1],g=void 0===s?o.crossSize/2:eb[s]+(ec[s].crossSize+o.crossSize)/2+eC,c=void 0===h?ep-o.crossSize/2:eb[h]-(ec[h].crossSize+o.crossSize)/2-eC;if(n<u.length){let e=eY[n],t=eT[n];e>=0&&(g=Math.max(g,eb[e]+(ec[e].crossSize+o.crossSize)/2+B)),t>=0&&(c=Math.min(c,eb[t]-(ec[t].crossSize+o.crossSize)/2-B))}g<=c&&(eb[n]=Math.max(g,Math.min(c,r)))}}let eL=new Uint32Array(ec.length);for(let e of ey)e.forEach((e,t)=>{eL[e]=t});let eO=Math.min(4,B);for(let e of ed){if(e.length<4)continue;let t=1;for(;t<e.length-1;){let i=-1/0,r=1/0,a=t;for(;a<e.length-1;){let t=e[a],n=ec[t],o=ey[n.rank],l=eL[t],s=o[l-1],h=o[l+1],g=void 0===s?n.crossSize/2:eb[s]+(ec[s].crossSize+n.crossSize)/2+eO,c=void 0===h?ep-n.crossSize/2:eb[h]-(ec[h].crossSize+n.crossSize)/2-eO,d=Math.max(i,g),f=Math.min(r,c);if(d>f)break;i=d,r=f,a++}if(a>t+1){let n=Math.max(i,Math.min(r,(eb[e[t-1]]+eb[e[a]])/2));for(let i=t;i<a;i++)eb[e[i]]=n}t=Math.max(t+1,a)}}let eR=new Float64Array(x.length),eW=new Float64Array(x.length),eH=new Map;for(let e of h.loopPorts??[]){let t=x[e[0]],i=x[e[1]];if(!t||!i||t.source!==i.source)throw TypeError("Invalid measured loop port pair");let r=eH.get(t.source)??[];r.push(e),eH.set(t.source,r)}for(let e=0;e<u.length;e++){let t=ec[e].crossSize,i=(i,r)=>{let a=[...i].sort((e,t)=>{let i=ed[e],a=ed[t],n=r?i[1]:i[i.length-2],o=r?a[1]:a[a.length-2];return eb[n]-eb[o]||e-t}),n=r?eH.get(e):void 0;if(n?.length){let i=new Map(a.map((e,t)=>[e,t])),r=n.map(([e,t])=>[Math.min(i.get(e),i.get(t)),Math.max(i.get(e),i.get(t))]);if(r.some(([e,i])=>t*(i-e)/(a.length+1)<8)){let i=new Float64Array(a.length),n=new Map;for(let[e,t]of r){let i=n.get(t)??[];i.push(e),n.set(t,i)}for(let e=0;e<a.length;e++)for(let t of(i[e]=e?i[e-1]+2:0,n.get(e)??[]))i[e]=Math.max(i[e],i[t]+8);let o=Math.min(8,t/6),l=t-2*o-(i.at(-1)??0);l<0&&d("agentic local loop-attachment capacity"),a.forEach((r,n)=>{eR[r]=eb[e]-t/2+o+i[n]+l*(n+1)/(a.length+1)});return}}void 0!==u[e].minimumPortSpacing&&(f.pairs-=3,f.pairs<0&&d("agentic node port-spacing work limit"));let o=Math.min(8,t/6),l=Math.max(8,u[e].minimumPortSpacing??8);if(!n?.length&&t-2*o>=(a.length-1)*l){let i=eb[e]-t/2+o,n=eb[e]+t/2-o,s=a.map((e,t)=>{let o=ed[e],s=r?o[1]:o[o.length-2];return Math.max(i+t*l,Math.min(n-(a.length-1-t)*l,eb[s]))});for(let e=1;e<s.length;e++)s[e]=Math.max(s[e],s[e-1]+l);a.forEach((e,t)=>{(r?eR:eW)[e]=s[t]});return}for(let i=0;i<a.length;i++){let n=eb[e]-t/2+t*(i+1)/(a.length+1);(r?eR:eW)[a[i]]=n}};i(J[e],!0),i(G[e],!1)}let ej=Math.max(4,D/2),ez=Array.from({length:eo},()=>[]),eU=ed.map((e,t)=>e.slice(1).map((i,r)=>{let a=e[r],n={sourceCross:0===r?eR[t]:eb[a],targetCross:r===e.length-2?eW[t]:eb[i],offset:ej/2,track:0};return ez[ec[a].rank].push(n),n})),eV=ez.map(e=>(void 0!==h.minimumTerminalLead&&(f.pairs-=3,f.pairs<0&&d("agentic terminal-lead work limit")),function(e,t,i,r,a,n,o){let l=e.filter(e=>Math.abs(e.sourceCross-e.targetCross)>.01);if(!l.length)return t;a.pairs-=l.length*e.length,a.pairs<0&&n("agentic local channel-pair limit");let s=e=>Math.min(e.sourceCross,e.targetCross),h=e=>Math.max(e.sourceCross,e.targetCross),g=(e,t)=>Math.min(h(e),h(t))>=Math.max(s(e),s(t))-.5,c=(e,t)=>e>=s(t)-.01&&e<=h(t)+.01,d=l.map(()=>[]),f=l.map(()=>[]),y=[],m=(e,t)=>{--a.arcs<0&&n("agentic local channel-constraint limit");let i=y.length;y.push({source:e,target:t,minSpan:1}),f[e].push(i),d[t].push(i)};for(let e=0;e<l.length;e++)for(let t=e+1;t<l.length;t++){let i=l[e],r=l[t];g(i,r)&&(c(r.sourceCross,i)&&Math.abs(r.sourceCross-i.sourceCross)>.01&&m(t,e),c(r.targetCross,i)&&Math.abs(r.targetCross-i.targetCross)>.01&&m(e,t),c(i.sourceCross,r)&&Math.abs(i.sourceCross-r.sourceCross)>.01&&m(e,t),c(i.targetCross,r)&&Math.abs(i.targetCross-r.targetCross)>.01&&m(t,e))}let u=z(d,f,y),x=l.map((e,t)=>t).sort((e,t)=>u[e]-u[t]||e-t),p=0;for(let e=0;e<x.length;e++){let t=l[x[e]];for(let i=0;i<e;i++){let e=l[x[i]];g(t,e)&&(t.track=Math.max(t.track,e.track+1))}p=Math.max(p,t.track)}let b=!1,M=Math.max(1,Math.min(2,i/2)),w=e.flatMap(e=>[e.sourceCross,e.targetCross]).sort((e,t)=>e-t);for(let t of l){if(!e.some(e=>e!==t&&.5>=Math.abs(e.sourceCross-t.targetCross)&&(.01>=Math.abs(e.sourceCross-e.targetCross)||e.track>=t.track)))continue;let a=t.targetCross-i,o=t.targetCross+i;for(let e=w.length-1;e>=0;e--){let t=w[e];Math.abs(t-a)<M&&(a=t-M)}for(let e of w)Math.abs(e-o)<M&&(o=e+M);let l=a>=0?t.targetCross-a:1/0,s=o<=r?o-t.targetCross:1/0;Number.isFinite(Math.min(l,s))||n("agentic local channel-terminal clearance"),t.targetEscape=s<l||s===l&&t.sourceCross>t.targetCross?o:a,b=!0}let v=Math.max(12,i,o??0),k=2*v+p*i+(b?i:0),S=Math.max(t,k),N=(S-k)/2;for(let t of e)t.offset=v+N+t.track*i,void 0!==t.targetEscape&&(t.targetExit=S-v);return S}(e,ej,h.edgeSpacing??6,ep,f,d,h.minimumTerminalLead))),eB=new Float64Array(ec.length),eD=0;for(let e=0;e<ey.length;e++){for(let t of ey[e])eB[t]=eD+eu[e]/2;eD+=eu[e]+(eV[e]??0)}Number.isFinite(eD+ep+2*p)||d("agentic local coordinate-range limit");let e_=(e,t)=>{let i=p+(q?eD-t:t);return _?{x:i,y:p+e}:{x:p+e,y:i}},eq=u.map((e,t)=>{let i=e_(eb[t],eB[t]);return{x:i.x-e.width/2,y:i.y-e.height/2}}),e$=(e,t)=>{let i=ec[t].crossSize,r=Math.min(8,i/6),a=_?eq[t].y:eq[t].x;return e===eb[t]-i/2+r?a+r:e===eb[t]+i/2-r?a+i-r:p+e},eQ=(e,t)=>{let i=eq[e],r=u[e];return _?i.x+(t!==q?r.width:0):i.y+(t!==q?r.height:0)},eG=!h.placementOnly||h.cycleOriented||h.loopPorts?.length?x.map((e,t)=>{let i=ed[t],r=[],a=(e,t,i,a)=>{let n=e_(e,t);void 0!==i&&(_?n.y=i:n.x=i),void 0!==a&&(_?n.x=a:n.y=a);let o=r.at(-1);if(o?.x===n.x&&o.y===n.y)return;let l=r.at(-2);l&&o&&(l.x===o.x&&o.x===n.x&&(o.y-l.y)*(n.y-o.y)>=0||l.y===o.y&&o.y===n.y&&(o.x-l.x)*(n.x-o.x)>=0)&&r.pop(),r.push(n)};for(let e=1;e<i.length;e++){let r=i[e-1],n=i[e],o=eU[t][e-1],l=o.sourceCross,s=o.targetCross,h=eB[r]+ec[r].mainSize/2,g=eB[n]-ec[n].mainSize/2,c=eB[r]+eu[ec[r].rank]/2,d=c+o.offset,f=r<u.length?e$(l,r):void 0,y=n<u.length?e$(s,n):void 0;a(l,h,f,r<u.length?eQ(r,!0):void 0),a(l,d,f),a(o.targetEscape??s,d,void 0===o.targetEscape?y:void 0),void 0!==o.targetEscape&&(a(o.targetEscape,c+o.targetExit),a(s,c+o.targetExit,y)),a(s,g,y,n<u.length?eQ(n,!1):void 0)}let n=ef[t],o=void 0===n?void 0:e_(eb[n],eB[n]);return{points:r,...o?{labelPosition:o}:{}}}):x.map(()=>({points:[]}));return{topology:"layered",expandedVertices:ec.length,width:2*p+(_?eD:ep),height:2*p+(_?ep:eD),nodes:eq,edges:eG}}(a,h,c,d),u=a.placementOnly?f:function(e,t,i,r,a){if(e.placementOnly||e.groups?.length||void 0===e.maximumEdgeStrokeWidth)return t;let n=!1;for(let t of e.edges)if(--i.pairs<0&&a("agentic marker metadata work limit"),t.markerPaint?.start?.length||t.markerPaint?.end?.length){n=!0;break}if(!n)return 0===e.maximumEdgeBendRadius&&(C(i,a),--i.pairs<0&&a("agentic marker full-proof work limit"),R(e,t,new Set,i,a)),t;let o=e.nodes.length,l=e.edges.length;i.arcs-=3*o+l+7,i.pairs-=2*o+l+4,i.arcs<0&&a("agentic flat marker metadata capacity limit"),i.pairs<0&&a("agentic flat marker metadata work limit");let s=t.expandedVertices??0,h=t.nodes.map((t,i)=>({...t,width:e.nodes[i].width,height:e.nodes[i].height})),g=[...h],c=new Set;for(let e=0;e<l;e++)c.add(e);for(let e of t.edges)--i.pairs<0&&a("agentic flat marker path work limit"),v(e.points,i,a);let d=W(e,t,h,[],g,[],i,e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid measured marker point reservation");s+e>32768&&a("agentic local cross-hierarchy visibility-expansion limit"),s+=e},a,c,Math.max(8,e.edgeSpacing??6),e.maximumEdgeStrokeWidth,!0);R(e,t,c,i,a,d),i.arcs-=l+2,i.pairs-=l,i.arcs<0&&a("agentic marker full-proof capacity limit"),i.pairs<0&&a("agentic marker full-proof work limit");let f=[];for(let e=0;e<l;e++)f.push(e);return{...t,expandedVertices:s,boundaryRoutes:f}}(a,f,d,0,c);return a.placementOnly?u:function(r,a){if("forest"===a.topology||a.sharedEdges?.length||r.edges.length>128||a.edges.reduce((e,t)=>e+t.points.length,0)>2048)return a;let o=r.nodes.map((e,t)=>({...a.nodes[t],width:e.width,height:e.height})),l=(a.groups??[]).map((e,t)=>({...e,height:r.groups[t].padding.top})),s=r.edges.map((e,t)=>{let i=a.edges[t].labelPosition;return e.label&&i?{x:i.x-e.label.width/2-2,y:i.y-e.label.height/2-2,width:e.label.width+4,height:e.label.height+4}:void 0}),h=a.edges.map((e,t)=>({points:e.points,source:String(r.edges[t].source),target:String(r.edges[t].target),style:!1===r.edges[t].visible?"invisible":"solid"})),c=()=>h.map(e=>({points:e.points,visible:"invisible"!==e.style})),d=e=>e.slice(1).reduce((t,i,r)=>t+Math.abs(i.x-e[r].x)+Math.abs(i.y-e[r].y),0),f=(e,t)=>`${Math.sign(t.x-e.x)},${Math.sign(t.y-e.y)}`,y=512,m=8e6,u=e=>(m-=e)>=0;for(let[x,p]of r.edges.entries()){if(a.boundaryRoutes?.includes(x)||p.source===p.target||!1===p.visible||h[x].points.length<5)continue;let b=24,M=[...o,...l,...s.filter((e,t)=>!!e&&t!==x)],w=new Set([x]),v;for(let o=0;o<4;o++){let o=h[x].points,l=a.edges[x].labelPosition,k=[...o],S=-1;if(l){if((S=k.findIndex(e=>e.x===l.x&&e.y===l.y))<0){for(let e=1;e<k.length;e++)if(t(l,k[e-1],k[e])){S=e,k.splice(e,0,{...l});break}}if(S<0)break}let N=[[0,k.length-1],...S>0&&S<k.length-1?[[0,S],[S,k.length-1]]:[]],E=!1;e:for(let[S,I]of N)for(let N=S;N+2<I;N++)for(let S=I;S>N+2;S--)for(let I of[!1,!0]){if((m-=k.length)<0)return a;let P=k[N],A=k[S],F=I?{x:A.x,y:P.y}:{x:P.x,y:A.y},Y=function(e){let t=[];for(let i of e){let e=t.at(-1),r=t.at(-2);e?.x===i.x&&e.y===i.y||(r&&e&&(r.x===e.x&&e.x===i.x&&(e.y-r.y)*(i.y-e.y)>=0||r.y===e.y&&e.y===i.y&&(e.x-r.x)*(i.x-e.x)>=0)&&t.pop(),t.push(i))}return t}([...k.slice(0,N+1),F,...k.slice(S)]);if(Y.length>=o.length||d(Y)>d(o)+1e-7||f(Y[0],Y[1])!==f(o[0],o[1])||f(Y.at(-2),Y.at(-1))!==f(o.at(-2),o.at(-1)))continue;if((m-=Y.length*M.length)<0)return a;if(Y.slice(1).some((t,i)=>M.some(r=>e(Y[i],t,r))))continue;if((m-=Y.length*h.reduce((e,t)=>e+t.points.length,0))<0)return a;let T=h.reduce((e,t)=>e+t.points.length,0);if(b--<=0)break e;if(y--<=0||(m-=T*T)<0)return a;let X=n(Y,x,h,r,u,u);if(m<0)return a;if(void 0===X)continue;let C=l,L=s[x];if(l&&p.label&&!Y.slice(1).some((e,i)=>t(l,Y[i],e))){let t=[];for(let e=1;e<Y.length;e++){let i=Y[e-1],r=Y[e],a=i.y===r.y,n=(a?p.label.width:p.label.height)/2+2,o=Math.min(a?i.x:i.y,a?r.x:r.y)+n,s=Math.max(a?i.x:i.y,a?r.x:r.y)-n;if(o>s)continue;let h=Math.max(o,Math.min(s,a?l.x:l.y));t.push(a?{x:h,y:i.y}:{x:i.x,y:h}),t.push({x:(i.x+r.x)/2,y:(i.y+r.y)/2})}for(let r of(t.sort((e,t)=>Math.abs(e.x-l.x)+Math.abs(e.y-l.y)-Math.abs(t.x-l.x)-Math.abs(t.y-l.y)),C=void 0,t)){let t={x:r.x-p.label.width/2-2,y:r.y-p.label.height/2-2,width:p.label.width+4,height:p.label.height+4};if((m-=M.length+h.reduce((e,t)=>e+t.points.length,0))<0)return a;if(!(t.x<0||t.y<0||t.x+t.width>a.width||t.y+t.height>a.height||M.some(e=>i(t,e)))&&!h.some((i,r)=>r!==x&&"invisible"!==i.style&&i.points.slice(1).some((r,a)=>e(i.points[a],r,t)))){C=r,L=t;break}}if(!C)continue}if(v??=g(c(),w),h[x].points=Y,X>v){h[x].points=o;continue}a.edges[x].points=Y,C&&(a.edges[x].labelPosition={...C}),s[x]=L,v=X,E=!0;break e}if(!E)break}}return a}(a,u)}finally{m&&f&&f!==m&&(f.pairs=m.pairs,f.arcs=m.arcs,f.swaps=m.swaps)}}function Z(e,t,i,r,a,n=!1,o="primary"){let l,{edgeSelectorIndices:s,graphEdgeMarkerPaintRegions:h,DEFAULTS:g,LABEL_PILL_PADDING:d,measureRenderStage:f,graphTextBlock:y,resolveLabelContent:m,groupTitleWidth:u,groupHeaderHeight:x,estimateNodeSize:p,resolveNodeInlineStyle:b,resolveEdgeInlineStyle:M,resolveClassInlineStyle:w,containsNonFiniteNumber:v,finishGraphGeometry:k}=a;t.preserveSubgraphChildOrder&&a.unsupported("family-specific graph geometry");let S={...g,...t},N=[],E={pairs:1e6,arcs:65536,swaps:1e6};E.arcs-=2;let I=(e,t=0)=>{E.pairs-=e,E.arcs-=t,(E.pairs<0||E.arcs<0)&&a.unsupported("agentic marker preparation work limit")},P=f("graph-preparation",()=>{let r,l=[],g=new Map,f=new Map,v=(e,r,a)=>{let n=l.length,o=e.direction??a,s=x(e,i),h=e.concurrencyRegion?t.stateVisual?.dividerMargin??0:0;for(let t of(g.set(e.id,n),N.push(e),l.push({id:e.id,parent:r,direction:o,minWidth:u(e,i),headerHeight:s,padding:{top:s+i.groupPaddingY+h,bottom:i.groupPaddingY+h,left:i.groupPaddingX+h,right:i.groupPaddingX+h}}),e.nodeIds))f.set(t,{parent:n,direction:o});e.children.forEach(e=>v(e,n,o))};e.subgraphs.forEach(t=>v(t,void 0,e.direction));let k=[...e.nodes].map(([r,n])=>{g.has(r)&&a.unsupported("overlapping node and frame identities");let o=f.get(r);return{id:r,...o?{parent:o.parent}:{},...t.nodeSizes?.get(r)??p(r,m(n.label,n.labelContent),n.shape,i,o?.direction??e.direction,t.stateVisual,n.labelBlock)}}),E=new Map(k.map((e,t)=>[e.id,t]));for(let[e,t]of g)E.set(e,k.length+t);let P=new Set;for(let[i,r]of Object.entries(t.layoutHints?.ranks??{})){let t=E.get(i);if(void 0===t||!e.nodes.has(i))throw Error(`LAYOUT_HINT_INVALID: unknown node "${i}"`);if(!Number.isSafeInteger(r)||r<0||r>1e4)throw Error(`LAYOUT_HINT_INVALID: rank for "${i}" must be an integer in [0,10000]`);let a=k[t];a.partition=r,P.add(a.parent??-1)}for(let e of k)P.has(e.parent??-1)&&void 0===e.partition&&(e.partition=0);for(let e of l)P.has(e.parent??-1)&&(e.partition=0);if(t.layoutHints?.adjacent?.length){let i=new Map,r=[...k,...l];r.forEach((e,t)=>{let r=e.parent??-1,a=i.get(r)??[];a.push(t),i.set(r,a)});let a=new Map;for(let e of i.values())e.forEach((e,t)=>a.set(e,t));let n=new Set,o=new Map;for(let i of t.layoutHints.adjacent){if(i.length<2)throw Error("LAYOUT_HINT_INVALID: adjacent needs two or more nodes");let t=i.map(t=>{let i=E.get(t);if(void 0===i||!e.nodes.has(t))throw Error(`LAYOUT_HINT_INVALID: unknown node "${t}"`);return i}),r=k[t[0]].parent??-1;if(t.some(e=>(k[e].parent??-1)!==r))throw Error("LAYOUT_HINT_INVALID: adjacent nodes need the same container");for(let e of t){if(n.has(e))throw Error("LAYOUT_HINT_INVALID: a node cannot repeat in adjacency groups");n.add(e)}let l=o.get(r)??new Map;l.set(Math.min(...t.map(e=>a.get(e))),t),o.set(r,l)}for(let[e,t]of o){let a=0;i.get(e).forEach((e,i)=>{let o=t.get(i);if(o)for(let e of o)r[e].modelOrder=a++;else n.has(e)||(r[e].modelOrder=a++)})}}if(t.layoutHints?.shortEdges?.length){r=new Set;let i=s(e.edges);for(let e of t.layoutHints.shortEdges){let t=i.get(e);if(void 0===t)throw Error(`LAYOUT_HINT_INVALID: unknown edge "${e}"`);r.add(t)}}let A=l.length?(e,t)=>{let i=(e,t)=>{for(let i=t<k.length?k[t].parent:l[t-k.length].parent;void 0!==i;i=l[i].parent)if(i===e)return!0;return!1};return e>=k.length&&i(e-k.length,t)?"start":t>=k.length&&i(t-k.length,e)?"end":void 0}:void 0,F=0,Y=0,T=0;I(0,3*k.length+5);let X=new Float64Array(k.length),C=new Uint32Array(k.length),L=new Uint32Array(k.length),O=new Map,R=e=>{if(I(4+("string"==typeof e?e.length:0),1),"string"==typeof e&&!/^\s*(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(e))return;let t="number"==typeof e?e:Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:void 0},W=e.edges.map((t,o)=>{let l,s=E.get(t.source),g=E.get(t.target);(void 0===s||void 0===g)&&a.unsupported("unknown endpoint");let f=t.label?y(m(t.label,t.labelContent),i,"edge"):void 0,u=A?.(s,g),x,p=M(o,e),b=!n&&"invisible"!==t.style&&(t.hasArrowStart||t.hasArrowEnd),w=R(p?.["stroke-width"]??i.lineWidth*("thick"===t.style?2:1));if("invisible"!==t.style&&void 0!==w&&(T=Math.max(T,w)),(b||u)&&void 0!==w){I(12,15);let e=(p?.stroke??i.edgeStrokeColor)==="none",r=!!p?.["stroke-width"],n=JSON.stringify([u??null,t.style,t.hasArrowStart,t.hasArrowEnd,t.startMarker,t.endMarker,e,r]);if(!(l=O.get(n))){I(e?4096:2048,e?2048:1024);let o=h({...t,id:"marker-room",source:"",target:"",points:"end"===u?[{x:1,y:0},{x:0,y:0}]:[{x:0,y:0},{x:1,y:0}],inlineStyle:r?{"stroke-width":"1"}:void 0},{lineWidth:i.lineWidth,...e?{edgeStrokeColor:"none"}:{}}),s=0,g=0,c=0,d=0,f=0,y=0;for(let e of o){I(18);let t=e.bounds;t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&Number.isFinite(t.y0)&&Number.isFinite(t.y1)&&!(t.x0>t.x1)&&!(t.y0>t.y1)||a.unsupported("agentic marker paint bounds");let i="start"===e.position?"end"===u?1-t.x0:t.x1:"end"===u?t.x1:1-t.x0;"start"===e.position?s=Math.max(s,i):"end"===e.position&&(g=Math.max(g,i)),c=Math.max(c,t.y1-t.y0),e.position===u&&(y++,d=Math.max(d,t.x1),f=Math.max(f,2*Math.max(Math.abs(t.y0),Math.abs(t.y1))))}I(0,7),l={start:s,end:g,span:c,boundaryInset:d,boundaryHeight:f,boundaryCount:y},O.set(n,l)}let{start:o,end:d,span:f}=l;b&&(F=Math.max(F,o+c+i.edgeBendRadius,d+c+i.edgeBendRadius,f),Y=Math.max(Y,o+d),t.hasArrowStart&&s<k.length&&(X[s]=Math.max(X[s],f)),t.hasArrowEnd&&g<k.length&&(X[g]=Math.max(X[g],f)))}if("invisible"!==t.style&&(I(2),s<k.length&&(L[s]=L[s]+1),g<k.length&&(C[g]=C[g]+1)),u){let e="invisible"!==t.style&&("start"===u?t.hasArrowStart:t.hasArrowEnd);!e||l&&l.boundaryCount||a.unsupported("ancestor marker paint bounds"),x={inset:e?l.boundaryInset:0,height:e?l.boundaryHeight:0}}let v=u&&f?Math.max(4,i.lineWidth*("thick"===t.style?2:1)*2):0;return{source:s,target:g,minSpan:t.length??1,...r?.has(o)?{short:!0}:{},...x?{boundaryMarker:x}:{},..."invisible"===t.style?{visible:!1}:{},...f?{label:{width:f.width+2*d+2*v,height:f.height+2*d+2*v}}:{}}}),H=!t.stateVisual&&!l.length&&[...e.nodes.values()].every(e=>"rectangle"===e.shape&&!e.semanticShape)&&e.edges.every((t,i)=>{if(t.label||"solid"!==t.style||t.hasArrowStart||!t.hasArrowEnd||t.endMarker&&"arrow"!==t.endMarker)return!1;let r=M(i,e);return!r||0===Object.keys(r).length}),j=Math.max(i.nodeLineWidth,i.groupLineWidth)/2;for(let[t]of e.nodes){let r=R(b(t,e)?.["stroke-width"]??i.nodeLineWidth);I(3),void 0!==r&&(j=Math.max(j,r/2))}for(let t of N)if(t.stateComposite){let r=R(w(t.id,e)?.["stroke-width"]??i.groupLineWidth);void 0!==r&&(j=Math.max(j,r/2))}let z=j+T/2,U=Math.max(6,i.lineWidth+4),V=F+z>Math.max(12,U)?F+z:void 0;for(let i=0;i<k.length;i++){I(6);let r=k[i],n=e.nodes.get(r.id),o=Math.max(C[i],L[i]),l=X[i]+T;if(o<2||X[i]<=8||"rectangle"!==n.shape||n.semanticShape||t.nodeSizes?.has(r.id))continue;let s=(f.get(r.id)?.direction??e.direction)==="LR"||(f.get(r.id)?.direction??e.direction)==="RL",h=(o-1)*l,g=h<=32?1.5*h:h+16;Number.isFinite(g)||a.unsupported("agentic marker spacing range"),s?r.height=Math.max(r.height,g):r.width=Math.max(r.width,g),r.minimumPortSpacing=l}return Number.isFinite(Y+z)&&Number.isFinite(V??0)&&Number.isFinite(2*(Y+z))||a.unsupported("agentic marker spacing range"),{nodes:k,groups:l,edges:W,shareCompleteFans:H,direction:e.direction,padding:S.padding,nodeSpacing:S.nodeSpacing,layerSpacing:Math.max(S.layerSpacing,2*(Y+z)),edgeSpacing:U,...void 0!==V?{minimumTerminalLead:V}:{},..."authored"===o?{authoredCycleOrder:!0}:"compact"===o?{compactPrivateRanks:!0}:{},...n?{placementOnly:!0}:{}}});I(0,2),G.set(P,E);try{l=f("agentic",()=>r(P))}finally{G.delete(P)}if(l.nodes.length!==P.nodes.length||(l.groups?.length??0)!==P.groups.length||l.edges.length!==e.edges.length||v(l)||l.sharedEdges?.some(t=>!Number.isInteger(t)||t<0||t>=e.edges.length)||!n&&l.edges.some((e,t)=>e.points.length<2||P.edges[t].label&&!e.labelPosition))throw TypeError("Agentic graph producer returned malformed geometry");let A=P.nodes.map((t,i)=>{let r=e.nodes.get(t.id),a=e.classAssignments.get(t.id);return{...r,id:t.id,width:t.width,height:t.height,...l.nodes[i],inlineStyle:b(t.id,e),classNames:a?.split(/\s+/).filter(Boolean)}}),F=n?[]:e.edges.map((t,i)=>({...t,...l.edges[i],edgeIndex:i,inlineStyle:M(i,e),...t.id&&e.classAssignments.has(t.id)?{classNames:e.classAssignments.get(t.id).split(/\s+/).filter(Boolean)}:{}})),Y=N.map((t,i)=>{let r={id:t.id,label:t.label,...t.labelContent?{labelContent:t.labelContent}:{},...l.groups[i],children:[],...t.concurrencyRegion?{concurrencyRegion:!0}:{},...void 0===t.headerMinHeight?{}:{headerMinHeight:t.headerMinHeight},...t.stateComposite?{inlineStyle:w(t.id,e)}:{}};return n&&(r.headerHeight=P.groups[i].headerHeight),r}),T=[];if(Y.forEach((e,t)=>{let i=P.groups[t].parent;void 0===i?T.push(e):Y[i].children.push(e)}),n)return{width:l.width,height:l.height,nodes:A,edges:[],groups:T};let X=k({width:l.width,height:l.height,nodes:A,edges:F,groups:T},e,"forest"===l.topology,S.padding,i,t.stateVisual?.noteMargin??18,void 0,l.sharedEdges).positioned;if(v(X))throw TypeError("Agentic graph pipeline returned non-finite geometry");return X}function ee(e,t,i,r,a){let{countEdgeCrossings:n,countOpposingRouteOverlaps:o,countParallelRouteOverlaps:l,measureLabelConflicts:s}=a,h=e=>e.edges.reduce((e,t)=>e+t.points.length,0);if(e.subgraphs.length||e.nodes.size>20||e.edges.length>64||e.edges.reduce((e,t)=>e+(t.length??1),0)>128||h(i)>2048||0===n(i.edges))return i;et(e,t,{strategy:"agentic-layered",produce:()=>i},a);let g=e=>[s(e,t).total,o(e.edges),l(e.edges),n(e.edges),e.edges.reduce((e,t)=>e+("invisible"===t.style?0:Math.max(0,t.points.length-2)),0),e.width*e.height],c=i,f=g(i);for(let i of("function"==typeof r?[{strategy:"agentic-authored-order",produce:r}]:r).slice(0,2)){let r;try{r=et(e,t,i,a)}catch(e){if(!(e instanceof m)&&!(e instanceof d))throw e;continue}if(h(r)>2048)continue;let n=g(r);for(let e=0;e<f.length;e++){if(n[e]<f[e]){c=r,f=n;break}if(n[e]>f[e])break}if(0===f[3])break}return c}function et(e,t,i,r){let a=r.certifyCandidate(e,t,i,!0);if(!a.certified)throw new d([a.attempt]);return r.retainSelection(e,{selected:a.certified,reason:"first-certified",attempts:1,compared:[{strategy:a.certified.strategy,score:a.certified.score}]})}function ei(e,t,i,r,a){let n=function(e,t,i,r,a){let n=!1!==t.compareRoutePreferences&&!t.stateVisual&&!e.subgraphs.length&&e.nodes.size<=20&&e.edges.length<=64,o,l;if(n&&q&&!a.customTextMeasurementActive()){let n=$([e,t,i,Object.keys(_.process?.env??{}).filter(e=>e.startsWith("APL_")).map(e=>[e,_.process.env[e]]).sort()]);if(n.length<=65536){o=n,(l=Q.get(a))||(l=new D(1048576),Q.set(a,l));let s=l.get(o);if(s)return Z(e,t,i,r,a,!1,s)}}let s=Z(e,t,i,r,a);if(!n)return s;let h=[{strategy:"agentic-authored-order",produce:()=>Z(e,t,i,r,a,!1,"authored")}];e.edges.some(e=>!e.label)&&h.push({strategy:"agentic-compact-ranks",produce:()=>Z(e,t,i,r,a,!1,"compact")});let g=ee(e,i,s,h,a),c=g===s?"primary":g.certification?.strategy==="agentic-authored-order"?"authored":g.certification?.strategy==="agentic-compact-ranks"?"compact":void 0;return o&&l&&c&&l.set(o,c,2*o.length+128),g}(e,t,i,r,a);return et(e,i,{strategy:"agentic-layered",produce:()=>n},a)}function er(e,t,i,r,a){let n=Z(e,t,i,r,a,!0);return{width:n.width,height:n.height,nodes:n.nodes,groups:n.groups}}export{et as certifyOwnedLayoutCandidate,J as createMeasuredLayoutCache,B as improveArchitectureSiblingSlots,K as layoutLayeredGraph,ei as layoutNativeGraphCandidate,er as layoutNativeGraphPlacement,ee as refineOwnedLayoutCandidate};
|
|
1
|
+
import{a as e,b as t,c as i,d as r,e as a,g as n,i as o,j as l}from"./chunk-OBI5U5XU.js";import{a as s,b as h}from"./chunk-L4UC3KGS.js";import{d as g}from"./chunk-BMZ24VPS.js";import{e as c}from"./chunk-PXTLV57R.js";import"./chunk-YVNJDVQO.js";import{Pb as d,Q as f,Ub as y,Yb as m}from"./chunk-EIYLJ4FI.js";import"./chunk-YHMTSXIR.js";import"./chunk-QCU5G5PZ.js";function u(e,t,i){for(let r=0;r<e.length;r++)for(let a=0;a<t.length;a++){i?.(1);let n=e[r],o=t[a];if("circle"===n.kind){if("circle"===o.kind){let e=n.cx-o.cx,t=n.cy-o.cy,i=n.r+o.r;if(n.r>0&&o.r>0&&e*e+t*t<i*i)return!0}else if(x(n.cx,n.cy,n.r,o.points,i))return!0}else if("circle"===o.kind){if(x(o.cx,o.cy,o.r,n.points,i))return!0}else if(function(e,t,i){if(e.length<3||t.length<3)return!1;let r=e[0],a=0;for(let n=0;n<2;n++){let o=0===n?e:t;for(let n=0;n<o.length;n++){i?.(1);let l=o[n],s=o[(n+1)%o.length],h=l.y-s.y,g=s.x-l.x;if(0===h&&0===g)continue;a++;let c=1/0,d=-1/0,f=1/0,y=-1/0;for(let t=0;t<e.length;t++){i?.(1);let a=e[t],n=(a.x-r.x)*h+(a.y-r.y)*g;c=Math.min(c,n),d=Math.max(d,n)}for(let e=0;e<t.length;e++){i?.(1);let a=t[e],n=(a.x-r.x)*h+(a.y-r.y)*g;f=Math.min(f,n),y=Math.max(y,n)}if(Math.min(d,y)<=Math.max(c,f))return!1}}return a>0}(n.points,o.points,i))return!0}return!1}function x(e,t,i,r,a){if(!(i>0)||r.length<3)return!1;let n=0,o=!0,l=0,s=1/0,h=r[0];for(let i=0;i<r.length;i++){a?.(1);let g=r[i],c=r[(i+1)%r.length],d=c.x-g.x,f=c.y-g.y,y=d*(t-g.y)-f*(e-g.x);l+=(g.x-h.x)*(c.y-h.y)-(g.y-h.y)*(c.x-h.x),0!==y&&(0!==n&&Math.sign(y)!==n&&(o=!1),n||=Math.sign(y));let m=d*d+f*f,u=m>0?Math.max(0,Math.min(1,((e-g.x)*d+(t-g.y)*f)/m)):0;s=Math.min(s,(g.x+u*d-e)**2+(g.y+u*f-t)**2)}return 0!==l&&(o||s<i*i)}var p=new WeakMap;function b(e,t,i,r){let a=(e=1)=>{t.pairs-=e,t.pairs<0&&i("agentic local cross-hierarchy obstacle-work limit")},n=(e,r)=>{"work"===r?a(e):(t.arcs-=e,t.arcs<0&&i("agentic local cross-hierarchy visibility-arc limit"))},o=r?r.x:s(e,"x",0,n),l=r?r.y:s(e,"y",0,n),g=(e,t,i)=>e?(i?.(),a(),h(e,t)):null,c=(e,t)=>t<0||t+1>=e.offsets.length,d=(e,t,i)=>t>e.x&&t<e.x+e.width&&i>e.y&&i<e.y+e.height,f=(e,t,i,r,a)=>t===r?t>e.x&&t<e.x+e.width&&Math.max(i,a)>e.y&&Math.min(i,a)<e.y+e.height:i>e.y&&i<e.y+e.height&&Math.max(t,r)>e.x&&Math.min(t,r)<e.x+e.width,y=(e,t,i,r,n)=>{a(2),t?r>e.y&&r<e.y+e.height&&(e.x>=i&&(n.right=Math.min(n.right,e.x)),e.x+e.width<=i&&(n.left=Math.max(n.left,e.x+e.width))):i>e.x&&i<e.x+e.width&&(e.y>=r&&(n.bottom=Math.min(n.bottom,e.y)),e.y+e.height<=r&&(n.top=Math.max(n.top,e.y+e.height)))},m={projectPoint(t,i,r,n){a(4),n.left=r.x,n.right=r.x+r.width,n.top=r.y,n.bottom=r.y+r.height;for(let r=0;r<2;r++){let a=0===r,s=a?l:o,h=g(s,a?i:t);if(s&&null!==h){if(c(s,h))continue;for(let r=s.offsets[h];r<s.offsets[h+1];r++)y(e[s.ordinals[r]],a,t,i,n)}else for(let r of e)y(r,a,t,i,n)}},containsPoint(t,i,r){let n=g(o,t,r),s=g(l,i,r);if(o&&null!==n&&c(o,n)||l&&null!==s&&c(l,s))return!1;let h=o&&null!==n?o.offsets[n+1]-o.offsets[n]:1/0,f=l&&null!==s?l.offsets[s+1]-l.offsets[s]:1/0,y=h<=f?o:l,m=h<=f?n:s;if(y&&null!==m){for(let n=y.offsets[m];n<y.offsets[m+1];n++)if(r?.(),a(),d(e[y.ordinals[n]],t,i))return!0}else for(let n of e)if(r?.(),a(),d(n,t,i))return!0;return!1},entersSegment(t,i,r,n,s){let h=t===r?o:l,d=g(h,t===r?t:i,s);if(h&&null!==d){if(c(h,d))return!1;for(let o=h.offsets[d];o<h.offsets[d+1];o++)if(s?.(),a(),f(e[h.ordinals[o]],t,i,r,n))return!0}else for(let o of e)if(s?.(),a(),f(o,t,i,r,n))return!0;return!1}};return n(4,"capacity"),p.set(m,{boxes:e,containsPoint:m.containsPoint,entersSegment:m.entersSegment,projectPoint:m.projectPoint}),m}function M(e,t,i,r,a,n,o,l,s,h,g,c,d=.5,f=!1){o.arcs-=24+a.length+2,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit");let y=(e=1)=>{o.pairs-=e,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit")},m=e=>{o.arcs-=e,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit")},u=new Float64Array(a.length+2),x=(e,t)=>(--o.swaps<0&&s("agentic local cross-hierarchy coordinate-sort limit"),e===t?0:e-t);y(18);let p=i.stub.x-i.port.x,b=i.stub.y-i.port.y;if(0===p==(0===b))return;let v=0===b,k=Math.sign(v?p:b),S=v?i.port.y:i.port.x,N=v?i.port.x:i.port.y,E=void 0===c?v?i.stub.x:i.stub.y:N+k*c,P=v?e.y:e.x,I=P+(v?e.height:e.width),A=v?e.x:e.y,F=A+(v?e.width:e.height),Y=k<0?A:F;if(!Number.isFinite(d)||d<.5||void 0!==c&&(!Number.isFinite(c)||c<0)||!Number.isFinite(P+I+A+F+S+N+E)||I<=P||F<=A||S<P||S>I||N<A||N>F||E<A||E>F)return;let T=(e,t,i,r,n)=>{y(u.length),u.fill(1/0);let o=2;for(let[l,s]of(u[0]=e,u[1]=t,a)){y(10);let a=v?l.y:l.x,h=v?l.x:l.y,g=v?s.y:s.x,c=v?s.x:s.y,f=i?a:h;(i?a!==g:h!==c)||Math.max(i?h:a,i?c:g)<r-d||Math.min(i?h:a,i?c:g)>n+d||f<=e||f>=t||(u[o++]=f)}u.sort(x);let l=-1/0,s;for(let e=1;e<o;e++){y(5);let t=u[e-1],i=u[e],r=i-t,a=t+r/2;r>2*d&&r>l&&a>t&&a<i&&(l=r,s=a)}return s},X=0;for(let e=0;e<2;e++){if(X>=8)return;let i=0;for(let c of r){y(6);let r=v?c.stub.y-c.port.y:c.stub.x-c.port.x,u=v?c.stub.x-c.port.x:c.stub.y-c.port.y;y(4);let x=1===e;if(x?0!==u||0===r:0!==r||Math.sign(u)!==k)continue;if(++i>4)break;let p=v?c.port.y:c.port.x,b=v?c.port.x:c.port.y,M=v?c.stub.x:c.stub.y,C=v?c.stub.y:c.stub.x;if(y(8),!(p<P||p>I||b<A||b>F||k*(b-N)<=0))for(let e=0;e<2;e++){let i,c=0===e?-1:1,u=c<0?P:I;if(y(),x&&c!==Math.sign(r))continue;let L=Math.min(u,S),O=Math.max(u,S),R=E,W=!1;for(let e=0;e<=t.length;e++){let e=R;for(let i of t){y(12);let t=v?i.y:i.x,r=v?i.x:i.y,a=v?i.height:i.width,n=v?i.width:i.height;if(!Number.isFinite(t+r+a+n)||a<0||n<0)return;t>=O||t+a<=L||(k>0&&r<=R&&r+n>R&&(e=Math.max(e,r+n)),k<0&&r<R&&r+n>=R&&(e=Math.min(e,r)))}if(y(3),e===R){W=!0;break}if((R=e)<A||R>F)break}if(!W)continue;let j=Y;for(let e of t){y(10);let t=v?e.y:e.x,i=v?e.x:e.y,r=v?e.height:e.width,a=v?e.width:e.height;t>=O||t+r<=L||(k>0&&i>=R&&(j=Math.min(j,i)),k<0&&i+a<=R&&(j=Math.max(j,i+a)))}let H=T(Math.min(R,j),Math.max(R,j),!1,L,O);if(y(4),void 0===H||k*(H-E)<=0||k*(b-H)<=0)continue;let z=c<0?I:P,U=Math.min(H,x?b:Y),V=Math.max(H,x?b:Y);for(let e of t){y(10);let t=v?e.y:e.x,i=v?e.x:e.y,r=v?e.height:e.width,a=v?e.width:e.height;i>=V||i+a<=U||t>I||t+r<P||(z=c<0?Math.min(z,Math.max(P,t)):Math.max(z,Math.min(I,t+r)))}if(y(2),c*(u-z)<=0)continue;let B=T(Math.max(Math.min(u,z),L),Math.min(Math.max(u,z),O),!0,U,V);if(void 0===B||c*(B-S)<0)continue;if(x){if(y(4),c*(B-C)<0)continue;if(y(2),X>=8)return;X++,l(5),m(6),i=v?[{x:N,y:S},{x:H,y:S},{x:H,y:B},{x:b,y:B},{x:b,y:p}]:[{x:S,y:N},{x:S,y:H},{x:B,y:H},{x:B,y:b},{x:p,y:b}]}else{let e=Math.min(B,p),r=Math.max(B,p),a=M;for(let i of t){y(10);let t=v?i.y:i.x,n=v?i.x:i.y,o=v?i.height:i.width,l=v?i.width:i.height;t>=r||t+o<=e||n>F||n+l<A||(a=k<0?Math.min(a,Math.max(A,n)):Math.max(a,Math.min(F,n+l)))}if(y(2),k*(Y-a)<=0)continue;let n=T(Math.min(Y,a),Math.max(Y,a),!1,e,r);if(void 0===n)continue;if(y(2),X>=8)return;X++,l(6),m(7),i=v?[{x:N,y:S},{x:H,y:S},{x:H,y:B},{x:n,y:B},{x:n,y:p},{x:b,y:p}]:[{x:S,y:N},{x:S,y:H},{x:B,y:H},{x:B,y:n},{x:p,y:n},{x:p,y:b}]}y(),f&&(y(2*i.length),i.reverse());let _=!0,q=0;for(let e=0;e<i.length;e++){let t=i[e];if(n.containsPoint(t.x,t.y)){_=!1;break}if(0===e)continue;let r=i[e-1],l=r.x===t.x?2:1;if(y(4),r.x===t.x&&r.y===t.y||r.x!==t.x&&r.y!==t.y||n.entersSegment(r.x,r.y,t.x,t.y)||!h(r,t,q||l,l)||(1===e||e===i.length-1)&&!w(r,t,a,d,o,s)){_=!1;break}q=l}if(_){let e=g(i);if(e)return e}}}}}function w(e,t,i,r,a,n){let o=e.x===t.x;for(let[l,s]of i)if(a.pairs-=3,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),!(o!==(l.x===s.x)||(a.pairs-=4,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),Math.abs(o?e.x-l.x:e.y-l.y)>r))&&(a.pairs-=12,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),Math.min(o?Math.max(e.y,t.y):Math.max(e.x,t.x),o?Math.max(l.y,s.y):Math.max(l.x,s.x))-Math.max(o?Math.min(e.y,t.y):Math.min(e.x,t.x),o?Math.min(l.y,s.y):Math.min(l.x,s.x))>=-r))return!1;return!0}function v(e,t,i){let r=0;for(let a=0;a<e.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=e[a];for(e[r++]=n;r>=3;){t.pairs-=12,t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let a=e[r-3],n=e[r-2],o=e[r-1];if(!(a.x===n.x&&n.x===o.x&&n.y>=Math.min(a.y,o.y)&&n.y<=Math.max(a.y,o.y)||a.y===n.y&&n.y===o.y&&n.x>=Math.min(a.x,o.x)&&n.x<=Math.max(a.x,o.x)))break;e[r-2]=o,r--}}return--t.pairs<0&&i("agentic local cross-hierarchy self-check limit"),e.length=r,e}var k=class{constructor(e,t,i,r,a,n,o){this.canvasWidth=i,this.canvasHeight=r,this.work=a,this.reservePoints=n,this.fail=o,this.capacity(e.length+2),this.catalog=Array(e.length),this.rails=[],this.capacity(1),this.onIndexCharge=(e,t)=>"capacity"===t?this.capacity(e):this.charge(e),this.capacity(2),this.x={cross:"x",enabled:!1,seed:null,first:1/0,last:-1/0,memberships:0,safe:!0,domainFirst:NaN,domainLast:NaN,heads:void 0},this.y={cross:"y",enabled:!1,seed:null,first:1/0,last:-1/0,memberships:0,safe:!0,domainFirst:NaN,domainLast:NaN,heads:void 0};for(let i=0;i<e.length;i++)this.charge(),i!==t&&"invisible"!==e[i].style&&this.addGeometry(i,e[i].points);this.seedAxis(this.x),this.seedAxis(this.y),this.updating=!1}canvasWidth;canvasHeight;work;reservePoints;fail;catalog;rails;x;y;revision=0;active;geometrySafe=!0;arcAllocated=1;pointAllocated=0;insertionVisits=0;flatMoves=0;flatSearches=0;seedBuilds=0;failed=!1;updating=!0;lastStart=0;lastCount=0;onIndexCharge;charge(e=1){this.work.pairs-=e,this.work.pairs<0&&(this.failed=!0,this.fail("agentic local cross-hierarchy crossing-work limit"))}capacity(e){this.work.arcs-=e,this.work.arcs<0&&(this.failed=!0,this.fail("agentic local cross-hierarchy visibility-arc limit")),this.arcAllocated+=e}point(){try{this.reservePoints(1),this.pointAllocated++}catch(e){throw this.failed=!0,e}}axisEligible(e){this.charge(8);let t=this.rails.length,i=e.last-e.first+1;return this.geometrySafe&&t>=32&&t<=0x10000000&&e.safe&&Number.isSafeInteger(e.memberships)&&e.memberships<=8*t&&Number.isSafeInteger(i)&&i<=8*t}addTotals(e,t){this.charge(8);let i="x"===e.cross?t.xLow:t.yLow,r="x"===e.cross?t.xHigh:t.yHigh;if(!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||r<i){e.safe=!1;return}e.memberships+=r-i+1,e.first=Math.min(e.first,i),e.last=Math.max(e.last,r),Number.isSafeInteger(e.memberships)||(e.safe=!1)}addGeometry(e,t){if(this.charge(3),!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Duplicate or invalid peer geometry publication");this.capacity(t.length+2);let i=Array(t.length),r=0;for(let e=0;e<t.length;e++){this.charge(4);let a=t[e],n=i[r-1];if(n?.x!==a.x||n.y!==a.y)for(this.point(),i[r++]={x:a.x,y:a.y};r>2;){this.charge(8);let e=i[r-3],t=i[r-2],a=i[r-1];if(!(e.x===t.x&&t.x===a.x&&t.y>=Math.min(e.y,a.y)&&t.y<=Math.max(e.y,a.y)||e.y===t.y&&t.y===a.y&&t.x>=Math.min(e.x,a.x)&&t.x<=Math.max(e.x,a.x)))break;i[r-2]=a,r--}}i.length=r;let a=Math.max(0,r-1),n=0;for(;n<this.rails.length&&(this.charge(),this.flatSearches++,!(this.rails[n].route>e));)n++;this.capacity(a);let o=this.rails.length;this.rails.length=o+a;for(let e=o-1;e>=n;e--)this.charge(),this.flatMoves++,this.rails[e+a]=this.rails[e];for(let t=0;t<a;t++){this.charge(12);let r=i[t],a=i[t+1];this.geometrySafe&&=Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(a.x)&&Number.isFinite(a.y)&&(r.x===a.x||r.y===a.y)&&Number.isFinite(Math.abs(r.x-a.x))&&Number.isFinite(Math.abs(r.y-a.y)),this.capacity(3);let o=[r,a];o.route=e,o.ordinal=t,o.x=Math.min(r.x,a.x)-.5,o.y=Math.min(r.y,a.y)-.5,o.width=Math.abs(r.x-a.x)+1,o.height=Math.abs(r.y-a.y)+1,o.xLow=Math.floor(o.x/128),o.xHigh=Math.floor((o.x+o.width)/128),o.yLow=Math.floor(o.y/128),o.yHigh=Math.floor((o.y+o.height)/128),this.rails[n+t]=o,this.addTotals(this.x,o),this.addTotals(this.y,o)}this.catalog[e]={points:i,segments:a},this.lastStart=n,this.lastCount=a}seedAxis(e){this.charge(12);let t="x"===e.cross?this.canvasWidth:this.canvasHeight,i=Math.min(e.first,Math.floor(-.5/128)),r=Math.max(e.last,Math.floor((t+.5)/128)),a=r-i+1;if(e.domainFirst=i,e.domainLast=r,!(!this.axisEligible(e)||!Number.isFinite(t)||t<0||!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||a>8*this.rails.length)&&(this.seedBuilds++,e.seed=s(this.rails,e.cross,0,this.onIndexCharge),e.seed)){this.capacity(a+1),this.charge(a),e.heads=Array(a).fill(void 0),e.enabled=!0;for(let t=0;t+1<e.seed.offsets.length;t++){this.charge();let i=e.seed.firstCell+t-e.domainFirst;for(let r=e.seed.offsets[t+1]-1;r>=e.seed.offsets[t];r--)this.charge(),this.capacity(1),e.heads[i]={peer:this.rails[e.seed.ordinals[r]],next:e.heads[i]}}}}insert(e,t){let i="x"===e.cross?t.xLow:t.yLow,r="x"===e.cross?t.xHigh:t.yHigh;for(let a=i;a<=r;a++){this.charge(2);let i=a-e.domainFirst,r,n=e.heads[i];for(;n&&(this.charge(2),this.insertionVisits++,!(n.peer.route>t.route||n.peer.route===t.route&&n.peer.ordinal>=t.ordinal));)r=n,n=n.next;this.capacity(1);let o={peer:t,next:n};r?r.next=o:e.heads[i]=o}}assertLease(e){if(this.failed||this.updating||e.released||this.active!==e||e.revision!==this.revision)throw TypeError("Stale peer geometry revision")}acquire(e){if(this.charge(4),this.failed||this.updating||this.active||!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Peer geometry lease is already active or owns its current route");this.capacity(3);let t={index:e,revision:this.revision,released:!1,queries:0,guardCalls:0,guard:void 0,release:void 0};return t.guard=(e,i,r,a)=>this.canTraverse(t,e,i,r,a),t.release=()=>this.release(t),this.charge(),this.active=t,t}enterQuery(e){this.charge(),this.assertLease(e),this.charge(),e.queries++}leaveQuery(e){if(e.released||this.active!==e||e.revision!==this.revision||e.queries<=0)throw this.charge(),TypeError("Peer query lease was not entered or is stale");e.queries--}release(e){if(e.released||this.active!==e||e.revision!==this.revision||e.queries||e.guardCalls)throw this.charge(),TypeError("Cannot release stale peer geometry or an active query");e.released=!0,this.active=void 0}publish(e,t,i){if(this.charge(4),this.failed||this.updating||this.active)throw TypeError("Cannot publish peer geometry while a revision is leased or failed");if(!Number.isInteger(e)||e<0||e>=this.catalog.length||void 0!==this.catalog[e])throw TypeError("Duplicate or invalid peer geometry publication");if(this.updating=!0,!i){this.catalog[e]=null,this.revision++,this.updating=!1;return}this.addGeometry(e,t);let r=this.lastStart,a=this.lastCount;for(let e=0;e<2;e++){let t=0===e?this.x:this.y,i=!0;for(let n=r;n<r+a;n++){this.charge(4);let r=this.rails[n],a=0===e?r.xLow:r.yLow,o=0===e?r.xHigh:r.yHigh;(!Number.isSafeInteger(a)||!Number.isSafeInteger(o)||a<t.domainFirst||o>t.domainLast)&&(i=!1)}if(this.axisEligible(t)&&i||(t.enabled=!1),t.enabled)for(let e=r;e<r+a;e++)this.insert(t,this.rails[e])}this.revision++,this.updating=!1}blocked(e,i,r,a,n){let o=r[0],l=r[1];if(this.charge(),a!==n&&t(e,o,l))return!0;let s=e.x===i.x;if(s===(o.x===l.x)){let t=Math.abs(s?e.x-o.x:e.y-o.y),r=Math.min(s?Math.max(e.y,i.y):Math.max(e.x,i.x),s?Math.max(o.y,l.y):Math.max(o.x,l.x))-Math.max(s?Math.min(e.y,i.y):Math.min(e.x,i.x),s?Math.min(o.y,l.y):Math.min(o.x,l.x));if(t<=.5&&r>.01||0===t&&r>=0)return!0}else{let t=s?e.x:o.x,r=s?o.y:e.y;if((e.x===i.x?1e-7>Math.abs(t-e.x):1e-7>Math.abs(r-e.y))&&t>=Math.min(e.x,i.x)&&t<=Math.max(e.x,i.x)&&r>=Math.min(e.y,i.y)&&r<=Math.max(e.y,i.y)&&(o.x===l.x?1e-7>Math.abs(t-o.x):1e-7>Math.abs(r-o.y))&&t>=Math.min(o.x,l.x)&&t<=Math.max(o.x,l.x)&&r>=Math.min(o.y,l.y)&&r<=Math.max(o.y,l.y)&&(t===o.x&&r===o.y||t===l.x&&r===l.y))return!0}return!1}canTraverse(e,t,i,r,a){this.charge(2),this.assertLease(e),e.guardCalls++;try{let e=t.x===i.x?this.x:this.y,n=t.x===i.x?t.x:t.y,o=Math.floor(n/128);if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(i.x)||!Number.isFinite(i.y)||t.x!==i.x&&t.y!==i.y||!e.enabled||!Number.isSafeInteger(o)){for(let e=0;e<this.rails.length;e++)if(this.blocked(t,i,this.rails[e],r,a))return!1;return!0}if(o<e.domainFirst||o>e.domainLast)return!0;let l=e.heads[o-e.domainFirst];for(;l;){if(this.blocked(t,i,l.peer,r,a))return!1;l=l.next}return!0}finally{e.guardCalls--}}};function S(e,t){let i=[],r=0,a=t=>{e(t),r+=t};return{get vertices(){return r},acquire(e,r){let n;if(!Number.isSafeInteger(e)||e<1)throw TypeError("Invalid sparse query capacity");for(let t of i)r(),!t.active&&t.capacity>=e&&(!n||t.capacity<n.capacity)&&(n=t);if(!n){let r=Math.min(32,e);for(;r<e;)r*=2;Number.isSafeInteger(r)||t("agentic local cross-hierarchy visibility-expansion limit"),a(r),n={active:!1,capacity:r,distance:new Float64Array(r),parents:new Int32Array(r),roots:new Int32Array(r),slots:new Int32Array(r),heapPages:new Map,reserveHeap:a},i.push(n)}return n.active=!0,n}}}function N(e,t,i,r,a,n,o,l,s,h,g=!1,c,d,f,y){o.pairs-=8,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit");let m=Math.max(e.x,Math.min(t.x-2*n,a.x-n)),u=Math.max(e.y,Math.min(t.y-2*n,a.y-n)),x=Math.min(e.x+e.width,Math.max(t.x+t.width+2*n,a.x+n)),p=Math.min(e.y+e.height,Math.max(t.y+t.height+2*n,a.y+n));return(x<=m||p<=u)&&s("cross-hierarchy route has no bounded clear corridor"),E({x:m,y:u,width:x-m,height:p-u},i,r,[a],n,o,l,s,h,g,c,d,f,y)}function E(t,i,r,a,n,o,s,h,g,c=!1,d,f,y,m){let u=t.x+t.width,x=t.y+t.height,b=0,M=e=>{b+e>s&&h("agentic local cross-hierarchy visibility-expansion limit"),g?.(e),b+=e},w=(e=1)=>{o.pairs-=e,o.pairs<0&&h("agentic local cross-hierarchy obstacle-work limit")},v=e=>e.x>=t.x&&e.x<=u&&e.y>=t.y&&e.y<=x,k=i.filter(e=>(w(),e.x<=u&&e.x+e.width>=t.x&&e.y<=x&&e.y+e.height>=t.y));w();let N=k.length>0;for(let e of k){w(8);let t=e.x+e.width,i=e.y+e.height;if(!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(t)||!Number.isFinite(i)||t<=e.x||i<=e.y){N=!1;break}}let P=[],I=new Map,A,F=e=>`${e.x},${e.y}`,Y=e=>{if(d)return!(A??=d()).containsPoint(e.x,e.y);for(let t of k)if(w(),e.x>t.x&&e.x<t.x+t.width&&e.y>t.y&&e.y<t.y+t.height)return!1;return!0},T=e=>{w(),Number.isFinite(e.x+e.y)||h("agentic local cross-hierarchy coordinate limit"),!v(e)||I.has(F(e))||!Y(e)||(M(1),I.set(F(e),P.length),P.push({...e}))},X=e=>{for(let t of[e.x,e.x+e.width])for(let i of[e.y,e.y+e.height])T({x:t,y:i})};for(let e of(X(t),k))X(e);for(let e=0;e<k.length;e++)for(let t=e+1;t<k.length;t++){w();let i=k[e],r=k[t];if(!(i.x>r.x+r.width||r.x>i.x+i.width||i.y>r.y+r.height||r.y>i.y+i.height))for(let[e,t]of[[i,r],[r,i]])for(let i of[e.x,e.x+e.width])for(let r of[t.y,t.y+t.height])w(),i>=t.x&&i<=t.x+t.width&&r>=e.y&&r<=e.y+e.height&&T({x:i,y:r})}for(let e of r)T(e.port),T(e.stub);for(let e of a)T(e);let C=new Set;for(let e of r)w(2),C.add(F(e.port)),C.add(F(e.stub));for(let e of a)w(),C.add(F(e));if(c&&k.length){let e=u,i=t.x,r=x,a=t.y;for(let n of k)w(8),e=Math.min(e,Math.max(t.x,n.x)),i=Math.max(i,Math.min(u,n.x+n.width)),r=Math.min(r,Math.max(t.y,n.y)),a=Math.max(a,Math.min(x,n.y+n.height));w(4);let n=(e,t)=>e+(t-e)/2,o=[...e>t.x?[n(t.x,e)]:[],...i<u?[n(i,u)]:[]],l=[...r>t.y?[n(t.y,r)]:[],...a<x?[n(a,x)]:[]],s=(e,t,i,r,a)=>{if(!y)return e;let o,l=a>e?1:-1;for(let[n,s]of y){w();let h=i?n.x:n.y;(i?n.x!==s.x:n.y!==s.y)||t<Math.min(i?n.y:n.x,i?s.y:s.x)||t>Math.max(i?n.y:n.x,i?s.y:s.x)||Math.abs(h-e)>.5||h<=Math.min(r,a)||h>=Math.max(r,a)||l*(a-h)<=0||(void 0===o||l*(h-o)>0)&&(o=h)}if(void 0===o)return e;let s=a;for(let[e,r]of y){w();let a=i?e.x:e.y;(i?e.x!==r.x:e.y!==r.y)||t<Math.min(i?e.y:e.x,i?r.y:r.x)||t>Math.max(i?e.y:e.x,i?r.y:r.x)||l*(a-o)<=0||l*(s-a)<=0||(s=a)}return n(o,s)};for(let n of o)for(let o of l){let l={x:s(n,o,!0,n<e?t.x:u,n<e?e:i),y:s(o,n,!1,o<r?t.y:x,o<r?r:a)};T(l),w(),C.add(F(l))}}let L=[],O=[],R=[],W=[],j=(e,t,i)=>{if(w(),e.x===t.x&&e.y===t.y)return;--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit");let r=e.y===t.y,a=r?{fixed:e.y,lower:Math.min(e.x,t.x),upper:Math.max(e.x,t.x)}:{fixed:e.x,lower:Math.min(e.y,t.y),upper:Math.max(e.y,t.y)};(r?L:O).push(a),i&&(r?R:W).push(a)},H=P.length,z;d&&(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),z={left:t.x,right:u,top:t.y,bottom:x});for(let e=0;e<H;e++){let i=P[e],r=t.x,a=u,n=t.y,o=x;if(z)(A??=d()).projectPoint(i.x,i.y,t,z),r=z.left,a=z.right,n=z.top,o=z.bottom;else for(let e of k)w(4),i.y>e.y&&i.y<e.y+e.height&&(e.x>=i.x&&(a=Math.min(a,e.x)),e.x+e.width<=i.x&&(r=Math.max(r,e.x+e.width))),i.x>e.x&&i.x<e.x+e.width&&(e.y>=i.y&&(o=Math.min(o,e.y)),e.y+e.height<=i.y&&(n=Math.max(n,e.y+e.height)));let l=C.has(F(i));for(let e of[{x:r,y:i.y},{x:a,y:i.y},{x:i.x,y:n},{x:i.x,y:o}])T(e),j(i,e,l)}let U=(e,t)=>(--o.swaps<0&&h("agentic local cross-hierarchy coordinate-sort limit"),e-t),V=e=>{let t=new Map;for(let i of e){w();let e=t.get(i.fixed)??[];e.push(i),t.set(i.fixed,e)}for(let[e,i]of t){i.sort((e,t)=>U(e.lower,t.lower)||U(e.upper,t.upper));let r=[];for(let e of i){w();let t=r.at(-1);t&&e.lower<=t.upper?t.upper=Math.max(t.upper,e.upper):(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),r.push({...e}))}t.set(e,r)}return{coordinates:[...t.keys()].sort(U),lines:t}},B=(e,t,i)=>{let r=V(t);for(let t of V(e).lines.values())for(let e of t){let t=0,a=r.coordinates.length;for(;t<a;){w();let i=Math.floor((t+a)/2);r.coordinates[i]<e.lower?t=i+1:a=i}for(let a=t;a<r.coordinates.length;a++){w();let t=r.coordinates[a];if(t>e.upper)break;for(let a of r.lines.get(t)){if(w(),a.lower>e.fixed)break;a.upper>=e.fixed&&T(i?{x:t,y:e.fixed}:{x:e.fixed,y:t})}}}return r},_=B(R,O,!0),q=B(W,L,!1),D;try{D=m?.acquire(P.length,w),N&&d&&(w(10),N=function(e,t){if(!e)return!1;let i=p.get(e);return!!i&&i.boxes===t&&Object.getOwnPropertyDescriptor(e,"containsPoint")?.value===i.containsPoint&&Object.getOwnPropertyDescriptor(e,"entersSegment")?.value===i.entersSegment&&Object.getOwnPropertyDescriptor(e,"projectPoint")?.value===i.projectPoint}(A,i));let t=D?void 0:P.map(()=>[]),r=(t,i)=>{if(d)return!(A??=d()).entersSegment(t.x,t.y,i.x,i.y);for(let r of k)if(w(),e(t,i,r))return!1;return!0};for(let e of[1,2]){let i=new Map;for(let a of(P.forEach((t,r)=>{w();let a=1===e?t.y:t.x,n=i.get(a)??[];n.push(r),i.set(a,n)}),i.values())){N&&w();let i=P[a[0]],n=N?(1===e?q:_).lines.get(1===e?i.y:i.x):void 0,l=0;a.sort((t,i)=>(--o.swaps<0&&h("agentic local cross-hierarchy coordinate-sort limit"),1===e?P[t].x-P[i].x:P[t].y-P[i].y));for(let i=1;i<a.length;i++){D?w():(o.arcs-=2,o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"));let s=a[i-1],g=a[i],c=1===e?P[s].x:P[s].y,d=1===e?P[g].x:P[g].y,f;for(;N&&(w(),!(!n||l>=n.length));){let e=n[l];if(w(),e.upper>=c){f=e;break}w(),l++}let y=!1;if(f&&(w(),f.lower<=c&&(w(),y=d<=f.upper)),!y&&!r(P[s],P[g]))continue;let m=Math.abs(P[s].x-P[g].x)+Math.abs(P[s].y-P[g].y);if(D){let t=4*s+(1===e?1:3),i=4*g+2*(1!==e);D.nodes[t]=g,D.distances[t]=m,D.nodes[i]=s,D.distances[i]=m}else t[s].push({node:g,axis:e,distance:m}),t[g].push({node:s,axis:e,distance:m})}}}let a=e=>I.get(F(e))??-1,s=3*P.length,g=f??S(M,h),c=!1,y=0;return{get vertices(){return b},retire(){if(!c){if(y)throw TypeError("Cannot retire a sparse graph during an active query");c=!0,D&&(D.active=!1)}},route(e,i,d=()=>!0,f=()=>!0){if(c)throw TypeError("Cannot query a retired sparse graph");y++;try{let c=a(i);c<0&&h("cross-hierarchy route has no clear anchor"),w(s);let y=g.acquire(s,w);try{let{distance:g,parents:m,roots:u,slots:x,heapPages:p}=y;g.fill(1/0,0,s),m.fill(-1,0,s),u.fill(-1,0,s),x.fill(-1,0,s);let b=0,k=e=>p.get(Math.floor(e/32))[e%32],S=(e,t)=>{let i=Math.floor(e/32),r=p.get(i);if(!r){let e=Math.min(32,y.capacity-32*i);y.reserveHeap(e),r=new Int32Array(e),p.set(i,r)}r[e%32]=t},N=e=>{let t=P[Math.floor(e/3)];return g[e]+Math.abs(t.x-i.x)+Math.abs(t.y-i.y)},E=(e,t)=>{--o.swaps<0&&h("agentic local cross-hierarchy heap-work limit");let i=N(e),r=N(t);return i<r||i===r&&e<t},I=(e,t)=>{let i=k(e);S(e,k(t)),S(t,i),x[k(e)]=e,x[k(t)]=t},A=e=>{let t=x[e];if(-2!==t)for(t<0&&(t=b,S(b++,e),x[e]=t);t>0;){let e=Math.floor((t-1)/2);if(!E(k(t),k(e)))break;I(t,e),t=e}},F=()=>{let e=k(0),t=k(--b);if(x[e]=-2,b){S(0,t),x[t]=0;let e=0;for(;;){let t=2*e+1;if(t>=b||(t+1<b&&E(k(t+1),k(t))&&t++,!E(k(t),k(e))))break;I(e,t),e=t}}return e};for(let t=0;t<e.length;t++){w();let i=e[t],n=a(i.stub);if(n<0||!v(i.port)||!Y(i.port)||!r(i.port,i.stub))continue;let o=i.port.x===i.stub.x?2:+(i.port.y===i.stub.y);if(!o)throw TypeError("Measured terminal lead must be orthogonal");if(!f(i.port,i.stub,o,o))continue;let l=3*n+o,s=Math.abs(i.stub.x-i.port.x)+Math.abs(i.stub.y-i.port.y)+i.penalty;s<g[l]&&(g[l]=s,u[l]=t,A(l))}for(;b;){let i=F(),r=Math.floor(i/3),a=i%3;if(r===c){let t=[],r=i;for(;m[r]>=0;)w(),t.push(P[Math.floor(r/3)]),r=m[r];t.push(P[Math.floor(r/3)],e[u[r]].port);let a=0,n;for(let e of t)w(),(!n||n.x!==e.x||n.y!==e.y)&&a++,n=e;M(a);let o=l(t.reverse());if(d(o))return o}let s=t?.[r];for(let t=0;t<(D?4:s.length);t++){let l,c,d;if(D){let e=4*r+t;if((l=D.nodes[e])<0){w();continue}c=t<2?1:2,d=D.distances[e]}else{let e=s[t];l=e.node,c=e.axis,d=e.distance}if(--o.arcs<0&&h("agentic local cross-hierarchy visibility-arc limit"),-1===m[i]){w();let t=e[u[i]],a=P[r],n=P[l],o=t.stub.x-t.port.x,s=t.stub.y-t.port.y;if(0!==o&&1===c&&Math.sign(n.x-a.x)===-Math.sign(o)||0!==s&&2===c&&Math.sign(n.y-a.y)===-Math.sign(s))continue}let y=3*l+c,p=g[i]+d+(a===c?0:2*n);-2!==x[y]&&p<g[y]&&f(P[r],P[l],a,c)&&(g[y]=p,m[y]=i,u[y]=u[i],A(y))}}return h("cross-hierarchy route has no bounded clear corridor")}finally{y.active=!1}}finally{y--}}}}catch(e){throw D&&(D.active=!1),e}}var P=class extends Error{},I=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}),A=(e,t,i)=>(t.x===i.x?1e-7>Math.abs(e.x-t.x):1e-7>Math.abs(e.y-t.y))&&e.x>=Math.min(t.x,i.x)&&e.x<=Math.max(t.x,i.x)&&e.y>=Math.min(t.y,i.y)&&e.y<=Math.max(t.y,i.y);function F(e,t,i,r,a=[.5,.25,.75]){let n="LR"===t?"E":"RL"===t?"W":"BT"===t?"N":"S",o=i?n:({N:"S",E:"W",S:"N",W:"E"})[n];return[o,...["N","E","S","W"].filter(e=>e!==o)].flatMap((t,i)=>a.map(a=>{let n="N"===t||"S"===t?{x:e.x+a*e.width,y:"N"===t?e.y:e.y+e.height}:{x:"W"===t?e.x:e.x+e.width,y:e.y+a*e.height},o={x:n.x+("E"===t?r:"W"===t?-r:0),y:n.y+("S"===t?r:"N"===t?-r:0)};return{port:n,stub:o,penalty:i*r*2+Math.abs(a-.5)*r}}))}function Y(e,t,i){for(let r=2;r<e.length;r++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let a=e[r-2],n=e[r-1],o=e[r];if(a.x===n.x&&n.x===o.x&&Math.sign(n.y-a.y)!==Math.sign(o.y-n.y)||a.y===n.y&&n.y===o.y&&Math.sign(n.x-a.x)!==Math.sign(o.x-n.x))return!0}for(let r=1;r<e.length;r++)for(let a=r+2;a<e.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=e[r-1],o=e[r],l=e[a-1],s=e[a];if(n.x===o.x&&l.x===s.x){if(n.x===l.x&&Math.min(Math.max(n.y,o.y),Math.max(l.y,s.y))>=Math.max(Math.min(n.y,o.y),Math.min(l.y,s.y)))return!0}else if(n.y===o.y&&l.y===s.y){if(n.y===l.y&&Math.min(Math.max(n.x,o.x),Math.max(l.x,s.x))>=Math.max(Math.min(n.x,o.x),Math.min(l.x,s.x)))return!0}else{let e=n.x===o.x?n.x:l.x,t=n.x===o.x?l.y:n.y;if(A({x:e,y:t},n,o)&&A({x:e,y:t},l,s))return!0}}return!1}function T(t,i,r,a,n,o,s,h,g,c=()=>!0,d=!1,f){let y=t.x+t.width,m=t.y+t.height,u={},x=()=>{if(h.pairs<=0)throw u;h.pairs--},p=(r,a=!0)=>{if(h.candidates<=0||h.pairs<=0)return;h.candidates--;let n=l(r);for(let e of n)if(!Number.isFinite(e.x+e.y)||e.x<t.x||e.x>y||e.y<t.y||e.y>m)return;if(!Y(n,s,g)){for(let t=1;t<n.length;t++){--s.arcs<0&&g("agentic local cross-hierarchy direct-arc limit");let r=n[t-1],a=n[t];if(f)try{if(f().entersSegment(r.x,r.y,a.x,a.y,x))return}catch(e){if(e===u)return;throw e}else for(let t of i)if(h.pairs<=0||(h.pairs--,--s.pairs<0&&g("agentic local cross-hierarchy direct-pair limit"),e(r,a,t)))return}return!a||c(n)?n:void 0}};if(d){let e=[];for(let t=0;t<3;t++)for(let i=0;i<4;i++){let a=r[3*i+t];p([a.port,a.stub],!1)&&e.push(a)}let t=t=>{if(!(h.pairs<=0||h.candidates<=0))for(let{port:i,stub:r}of e){let e=p([i,r,...t(r),a]);if(e)return e;if(h.pairs<=0||h.candidates<=0)return}};for(let e of[e=>[{x:a.x,y:e.y}],e=>[{x:e.x,y:a.y}]]){let i=t(e);if(i)return i}for(let e of n){let i=[e.x-2*o,e.x+e.width+2*o,e.x-o,e.x+e.width+o],r=[e.y-o,e.y+e.height+o];for(let e of i){let i=t(t=>[{x:e,y:t.y},{x:e,y:a.y}]);if(i)return i}for(let e of r){let i=t(t=>[{x:t.x,y:e},{x:a.x,y:e}]);if(i)return i}for(let e of i)for(let i of r){let r=t(t=>[{x:e,y:t.y},{x:e,y:i},{x:a.x,y:i}]);if(r)return r}if(h.pairs<=0||h.candidates<=0)break}return}for(let e=0;e<3;e++)for(let t=0;t<4;t++){let{port:i,stub:l}=r[3*t+e];if(!p([i,l],!1)){if(h.pairs<=0||h.candidates<=0)return;continue}for(let e of[{x:a.x,y:l.y},{x:l.x,y:a.y}]){let t=p([i,l,e,a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of n){let t=[e.x-o,e.x+e.width+o],r=[e.y-o,e.y+e.height+o];for(let e of t){let t=p([i,l,{x:e,y:l.y},{x:e,y:a.y},a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of r){let t=p([i,l,{x:l.x,y:e},{x:a.x,y:e},a]);if(t)return t;if(h.pairs<=0||h.candidates<=0)return}for(let e of t)for(let t of r){let r=p([i,l,{x:e,y:l.y},{x:e,y:t},{x:a.x,y:t},a]);if(r)return r;if(h.pairs<=0||h.candidates<=0)return}}}}var X=class{constructor(e){this.reason=e}reason};function C(e,t,i=1){e.arcs-=i,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit")}function L(e,t,i){i(),t.orthogonal=e.length>=2,t.minX=1/0,t.maxX=-1/0,t.minY=1/0,t.maxY=-1/0;for(let r=0;t.orthogonal&&r<e.length;r++){i(9);let a=e[r];if(!Number.isFinite(a.x)||!Number.isFinite(a.y)||r>0&&a.x!==e[r-1].x&&a.y!==e[r-1].y){t.orthogonal=!1;return}t.minX=Math.min(t.minX,a.x),t.maxX=Math.max(t.maxX,a.x),t.minY=Math.min(t.minY,a.y),t.maxY=Math.max(t.maxY,a.y)}}function O(e,t,i,r){if(!e?.orthogonal||!t?.orthogonal)return!1;i(void 0===r?8:20);let a=e.minX-t.maxX,n=t.minX-e.maxX,o=e.minY-t.maxY,l=t.minY-e.maxY,s=void 0===r?.5:Math.max(.5,r+(Math.abs(e.minX)+Math.abs(e.maxX)+Math.abs(e.minY)+Math.abs(e.maxY)+Math.abs(t.minX)+Math.abs(t.maxX)+Math.abs(t.minY)+Math.abs(t.maxY)+r)*1e-10+1e-9);return Number.isFinite(a)&&Number.isFinite(n)&&Number.isFinite(o)&&Number.isFinite(l)&&(a>s||n>s||o>s||l>s)}function R(e,t,i,a,o,l){let s=(e=1)=>{a.pairs-=e,a.pairs<0&&o("agentic local cross-hierarchy crossing-work limit")};void 0!==e.maximumEdgeStrokeWidth&&C(a,o,2*t.edges.length+3);let h=void 0===e.maximumEdgeStrokeWidth?void 0:e=>C(a,o,e),g=r(e),c=0,d=0,f=0,y=t.edges.map((t,i)=>{s();let r=t.points.length>=2;for(let e=0;r&&e<t.points.length;e++){s();let i=t.points[e];Number.isFinite(i.x)&&Number.isFinite(i.y)&&(!(e>0)||i.x===t.points[e-1].x||i.y===t.points[e-1].y)||(r=!1)}let a=!1!==e.edges[i].visible;return a&&(c+=Math.max(0,t.points.length-1),d+=t.points.length,f++),{...t,style:a?"solid":"invisible",orthogonal:r,covered:!1}}),m;if(void 0!==e.maximumEdgeStrokeWidth&&0===e.maximumEdgeBendRadius){for(let e of(C(a,o,i.size+y.length+1),m=[],i))s(),m.push(e);for(let t=0;t<y.length;t++)s(),!1!==e.edges[t].visible&&(s(),i.has(t)||m.push(t))}let u=m??i,x;if(c>=32){let t=0;for(let i of u)s(),l&&(s(),y[i].orthogonal&&!1!==e.edges[i].visible&&l.has(i))||(t=Math.max(t,y[i].points.length-1));let i=(g*t+1)*c,r=9*d+f+2*y.length+(void 0===e.maximumEdgeStrokeWidth?8:20)*f;if(Number.isSafeInteger(i)&&i>r){C(a,o,y.length),s(y.length),x=Array(y.length);for(let e=0;e<y.length;e++){s();let t=y[e];if("invisible"===t.style||!t.orthogonal)continue;C(a,o);let i={orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};L(t.points,i,s),x[e]=i}}}for(let t of u){let i=y[t],r=i.points,a=i.orthogonal&&!1!==e.edges[t].visible;if(l&&(s(),a&&l.has(t)))continue;let c=0;for(let i=0;i<y.length;i++){s();let r=y[i];l&&s(),r.style=!1===e.edges[i].visible||a&&(r.covered||r.orthogonal&&l?.has(i))?"invisible":"solid",x&&i!==t&&"invisible"!==r.style&&O(x[t],x[i],s,e.maximumEdgeStrokeWidth)&&(r.style="invisible"),i!==t&&"invisible"!==r.style&&(c+=Math.max(0,r.points.length-1))}s(g*Math.max(0,r.length-1)*c+r.length+c+y.length),void 0===n(r,t,y,e,s,h,void 0,g)&&o("cross-hierarchy routes have an uncertified shared contact"),a&&(i.covered=!0)}}function W(i,o,l,s,h,g,c,d,y,m,x,p,b=!1){(b||0===i.maximumEdgeBendRadius)&&function(e,t,i,r,a,n){for(let o=0;o<e.edges.length;o++)for(let l=0;l<2;l++){r.pairs-=10,r.pairs<0&&n("agentic marker endpoint work limit");let s=t.edges[o].points,h=e.edges[o],g=0===l;if(s.length<2)continue;let c=g?0:s.length-1,d=s[c],y=g?s[1]:s.at(-2),m=i[g?h.source:h.target],u,x;if(d.x===y.x&&d.y!==y.y)u="y",x=y.y>d.y?m.y+m.height:m.y;else{if(d.y!==y.y||d.x===y.x)continue;u="x",x=y.x>d.x?m.x+m.width:m.x}d[u]!==x&&(r.arcs-=10,r.pairs-=256,r.arcs<0&&n("agentic marker endpoint capacity limit"),r.pairs<0&&n("agentic marker endpoint work limit"),f(d[u])===f(x)&&(a(1),--r.arcs<0&&n("agentic marker endpoint capacity limit"),r.pairs-=3,r.pairs<0&&n("agentic marker endpoint work limit"),s[c]={x:d.x,y:d.y,[u]:x}))}}(i,o,h,c,d,y),c.arcs-=14,c.arcs<0&&y("agentic marker full-proof capacity limit");let M=(e=1)=>{c.pairs-=e,c.pairs<0&&y("agentic marker full-proof work limit")},w=e=>C(c,y,e),v=new Set;d(4);let k=0;for(let e=0;e<i.edges.length;e++)--c.pairs<0&&y("agentic marker full-proof work limit"),i.edges[e].label&&o.edges[e].labelPosition&&k++;c.arcs-=2*(l.length+s.length+k)+3,c.arcs<0&&y("agentic marker full-proof capacity limit");let S=[],N={x:0,y:0,width:o.width,height:o.height};for(let e=0;e<l.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=l[e],r=(i.nodes[e].paintStrokeWidth??0)/2;S.push({x:t.x-r,y:t.y-r,width:t.width+2*r,height:t.height+2*r})}for(let e=0;e<s.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=s[e],r=(i.groups[e].paintStrokeWidth??0)/2,a=g[e].headerHeight??g[e].padding.top;S.push({x:t.x-r,y:t.y-r,width:t.width+2*r,height:a+2*r})}for(let e=0;e<i.edges.length;e++){--c.pairs<0&&y("agentic marker full-proof work limit");let t=i.edges[e].label,r=o.edges[e].labelPosition;t&&r&&S.push({x:r.x-t.width/2-2,y:r.y-t.height/2-2,width:t.width+4,height:t.height+4})}let E={x:0,y:0,width:0,height:0},P=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}],I=(t,a,d,f=!1)=>{let m=i.edges[t],u=o.edges[t];if(M(),f){if(a!==u.points||!1===m.visible||a.length<2)return!1;for(let e=0;e<a.length;e++){M(3);let t=a[e];if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||e&&t.x!==a[e-1].x&&t.y!==a[e-1].y)return!1}}else{if(Y(a,c,y))return!1;for(let e=0;e<a.length;e++){M();let t=a[e];if(!Number.isFinite(t.x)||!Number.isFinite(t.y)||e&&t.x!==a[e-1].x&&t.y!==a[e-1].y)return!1}for(let e=0;e<2;e++){M(8);let t=0===e,i=h[t?m.source:m.target],r=t?a[0]:a.at(-1),n=t?a[1]:a.at(-2),o=t?u.points[0]:u.points.at(-1),l=t?u.points[1]:u.points.at(-2);if(Math.sign(n.x-r.x)!==Math.sign(l.x-o.x)||Math.sign(n.y-r.y)!==Math.sign(l.y-o.y)||Math.abs(n.x-r.x)+Math.abs(n.y-r.y)<Math.min(x,Math.abs(l.x-o.x)+Math.abs(l.y-o.y))||r.x<i.x||r.x>i.x+i.width||r.y<i.y||r.y>i.y+i.height||!(1e-7>Math.abs(r.x-i.x)&&n.y===r.y&&n.x<r.x||1e-7>Math.abs(r.x-i.x-i.width)&&n.y===r.y&&n.x>r.x||1e-7>Math.abs(r.y-i.y)&&n.x===r.x&&n.y<r.y||1e-7>Math.abs(r.y-i.y-i.height)&&n.x===r.x&&n.y>r.y))return!1}let r=!1;if(m.label){if(!u.labelPosition)return!1;for(let e=1;e<u.points.length;e++)if(M(),A(u.labelPosition,u.points[e-1],u.points[e])){r=!0;break}if(m.source!==m.target||r){let e=!1;for(let t=1;t<a.length;t++)if(M(),A(u.labelPosition,a[t-1],a[t])){e=!0;break}if(!e)return!1}}let n=(p??1)/2;for(let h=1;h<a.length;h++){let c=a[h-1],d=a[h];for(let t=0;t<l.length;t++){M(5);let r=l[t],o=t===m.source&&1===h||t===m.target&&h===a.length-1?0:n+(i.nodes[t].paintStrokeWidth??0)/2;if(E.x=r.x-o,E.y=r.y-o,E.width=r.width+2*o,E.height=r.height+2*o,e(c,d,E))return!1}for(let t=0;t<s.length;t++){M(5);let i=s[t],r=g[t].headerHeight??g[t].padding.top;if(E.x=i.x-n,E.y=i.y-n,E.width=i.width+2*n,E.height=r+2*n,r>0&&e(c,d,E))return!1}for(let a=0;a<i.edges.length;a++){M();let n=i.edges[a].label,l=o.edges[a].labelPosition;if(!(!n||!l)&&!(a===t&&r&&A(l,c,d))&&(M(4),E.x=l.x-n.width/2-2,E.y=l.y-n.height/2-2,E.width=n.width+4,E.height=n.height+4,e(c,d,E)))return!1}}}c.arcs-=2*o.edges.length+1,c.arcs<0&&y("agentic marker full-proof capacity limit"),M(3);let b=a===u.points&&!1!==m.visible,k=0,S=o.edges.map((e,r)=>{M();let a=!1!==i.edges[r].visible;return b&&a&&r!==t&&(M(2),v.has(r)&&(a=!1)),r!==t&&a&&(k+=Math.max(0,e.points.length-1)),{...e,style:a?"solid":"invisible"}});return M(r(i)*(a.length-1)*k+a.length+k),void 0!==n(a,t,S,i,M,w,d,r(i))};if(w(1),function(e,i,r,n,o,l,s,h,g,c,d=0,y,m){n.arcs-=18,n.arcs<0&&l("agentic marker seating capacity limit");let x=(e=1)=>{n.pairs-=e,n.pairs<0&&l("agentic marker seating work limit")},p=e=>{n.arcs-=e,n.arcs<0&&l("agentic marker seating capacity limit")},b=[],M=0;for(let t of e)x(),!1!==t.visible&&(M+=+!!t.markerPaint?.start?.length+ +!!t.markerPaint?.end?.length);let w=0,v=0;if(void 0!==c){if(!Number.isFinite(c)||c<=0||!Number.isFinite(d)||d<0)throw TypeError("Invalid measured marker carrier width");for(let t=0;t<i.length;t++){if(x(),!1===e[t].visible)continue;let r=i[t].points;x(2),2===r.length&&v++,w+=Math.max(0,r.length-1);for(let e=1;e+1<r.length;e++){x(4);let t=r[e-1],i=r[e],a=r[e+1];t.x===i.x!=(i.x===a.x)&&w++}}}let k=4*(M+w+4*v+(y?.obstacles.length??0))+8;p(k),x(k);let S=new Float64Array(k);p(2*w+2*i.length+9),o(4);let N=[],E=[],P=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}],I=(c??0)/2,A=(e,t,i)=>{x(13),Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&(t.x===i.x||t.y===i.y)||l("Unsupported measured marker carrier"),e.a=t,e.b=i;let r=I+(e.join?d:0);e.minX=Math.min(t.x,i.x)-r,e.maxX=Math.max(t.x,i.x)+r,e.minY=Math.min(t.y,i.y)-r,e.maxY=Math.max(t.y,i.y)+r},F=e=>{let t=E[e],r=i[e].points;t.minX=t.minY=1/0,t.maxX=t.maxY=-1/0,x(4);for(let e=t.begin;e<t.end;e++){let i=N[e];A(i,r[i.point],i.join?r[i.point]:r[i.point+1]),x(4),t.minX=Math.min(t.minX,i.minX),t.maxX=Math.max(t.maxX,i.maxX),t.minY=Math.min(t.minY,i.minY),t.maxY=Math.max(t.maxY,i.maxY)}};for(let t=0;t<i.length;t++){x();let r=N.length;if(void 0!==c&&!1!==e[t].visible)for(let e=1;e<i[t].points.length;e++)x(),N.push({current:!0,a:i[t].points[e-1],b:i[t].points[e],point:e-1,join:!1,minX:0,maxX:0,minY:0,maxY:0});if(void 0!==c&&!1!==e[t].visible)for(let e=1;e+1<i[t].points.length;e++){x(4);let r=i[t].points[e-1],a=i[t].points[e],n=i[t].points[e+1];r.x===a.x!=(a.x===n.x)&&N.push({current:!0,a:a,b:a,point:e,join:!0,minX:0,maxX:0,minY:0,maxY:0})}E.push({begin:r,end:N.length,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0}),F(t)}p(1);let Y=(e,t)=>{let i=E[e],r=N.length;p(10);for(let e=0;e<3;e++)x(),N.push({current:!0,a:t[e],b:t[e+1],point:e,join:!1,minX:0,maxX:0,minY:0,maxY:0});for(let e=1;e<3;e++)x(),N.push({current:!0,a:t[e],b:t[e],point:e,join:!0,minX:0,maxX:0,minY:0,maxY:0});for(let e=i.begin;e<i.end;e++)x(),N[e].current=!1;i.begin=r,i.end=N.length},T=(e,t)=>(x(5),e.maxX>t.minX&&e.minX<t.maxX&&e.maxY>t.minY&&e.minY<t.maxY),X=(e,t)=>{if(!T(e,t))return!1;let i=t.a,r=t.b,a=P[0].points;return x(8),t.join?(a[0].x=t.minX,a[0].y=t.minY,a[1].x=t.maxX,a[1].y=t.minY,a[2].x=t.maxX,a[2].y=t.maxY,a[3].x=t.minX,a[3].y=t.maxY):i.x===r.x?(a[0].x=t.minX,a[0].y=Math.min(i.y,r.y),a[1].x=t.maxX,a[1].y=a[0].y,a[2].x=t.maxX,a[2].y=Math.max(i.y,r.y),a[3].x=t.minX,a[3].y=a[2].y):(a[0].x=Math.min(i.x,r.x),a[0].y=t.minY,a[1].x=Math.max(i.x,r.x),a[1].y=t.minY,a[2].x=a[1].x,a[2].y=t.maxY,a[3].x=a[0].x,a[3].y=t.maxY),u(e.pieces,P,x)},C=1;for(let e of E)x(4),e.begin<e.end&&(C=Math.max(C,Math.abs(e.minX),Math.abs(e.maxX),Math.abs(e.minY),Math.abs(e.maxY)));for(let e of r)x(4),C=Math.max(C,Math.abs(e.x),Math.abs(e.y),Math.abs(e.x+e.width),Math.abs(e.y+e.height));y&&(x(4),C=Math.max(C,Math.abs(y.bounds.x),Math.abs(y.bounds.y),Math.abs(y.bounds.x+y.bounds.width),Math.abs(y.bounds.y+y.bounds.height)));let L=(C+Math.abs(c??0))*1e-10+1e-9,O=void 0===c?0:(p(5),x(128),Number(f(c))),R=(e,t)=>{if(void 0===c||t.join)return!0;let i=t.a,r=t.b,n=i.x===r.x;n?i.x:i.y,n?i.y:i.x,n?r.y:r.x,n?i.y:i.x,n?r.y:r.x;for(let n=0;n<E.length;n++){if(x(),n===e)continue;let o=E[n];if(x(5),!(t.maxX<o.minX-L||t.minX>o.maxX+L||t.maxY<o.minY-L||t.minY>o.maxY+L))for(let e=o.begin;e<o.end;e++){x();let t=N[e];if(!t.join&&function(e,t,i,r,n,o,l,s){l();let h=e.x===t.x;if(i.x===r.x!==h)return!1;l(2);let g=h?e.x:e.y,c=h?i.x:i.y,d=(Math.abs(g)+Math.abs(c)+Math.abs(n))*1e-10+1e-9;if(Math.abs(g-c)>n+d)return!1;l(2);let y=Math.min(h?e.y:e.x,h?t.y:t.x),m=Math.max(h?e.y:e.x,h?t.y:t.x),u=Math.min(h?i.y:i.x,h?r.y:r.x),x=Math.max(h?i.y:i.x,h?r.y:r.x),p=(Math.abs(y)+Math.abs(m)+Math.abs(u)+Math.abs(x))*1e-10+1e-9;if(Math.min(m,x)<Math.max(y,u)-p)return!1;s(42),l(384);let b=a(f(g),f(c),f(o),l);if(!0!==b)return void 0===b;s(20),l(512);let M=Number(f(h?e.y:e.x)),w=Number(f(h?t.y:t.x)),v=Number(f(h?i.y:i.x)),k=Number(f(h?r.y:r.x));return Math.min(Math.max(M,w),Math.max(v,k))>Math.max(Math.min(M,w),Math.min(v,k))}(i,r,t.a,t.b,c,O,x,p))return!1}}return!0},W={current:!0,a:void 0,b:void 0,point:0,join:!1,minX:0,maxX:0,minY:0,maxY:0},j=(e,t,i,r,a)=>{x(10),Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(i.x)&&Number.isFinite(i.y)||l("Nonfinite measured marker normal");let n=Math.sign(i.x-t.x),s=Math.sign(i.y-t.y);+!n+ +!s!=1&&l("Nonorthogonal measured marker normal");let h=0;for(let t of e)x(),"polygon"===t.kind&&(h+=t.points.length);p(2+2*e.length+h),o(h);let g={owner:r,source:a,pieces:[],minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let i of e)if(x(),"circle"===i.kind){let e=t.x+n*i.cx-s*i.cy,r=t.y+s*i.cx+n*i.cy;g.pieces.push({kind:"circle",cx:e,cy:r,r:i.r}),g.minX=Math.min(g.minX,e-i.r),g.maxX=Math.max(g.maxX,e+i.r),g.minY=Math.min(g.minY,r-i.r),g.maxY=Math.max(g.maxY,r+i.r)}else{let e={kind:"polygon",points:[]};for(let r of i.points){x();let i=t.x+n*r.x-s*r.y,a=t.y+s*r.x+n*r.y;e.points.push({x:i,y:a}),g.minX=Math.min(g.minX,i),g.maxX=Math.max(g.maxX,i),g.minY=Math.min(g.minY,a),g.maxY=Math.max(g.maxY,a)}g.pieces.push(e)}return g};p(M+1);let H=[];for(let t=0;t<e.length;t++)if(x(),!1!==e[t].visible)for(let r=0;r<2;r++){x();let a=0===r?e[t].markerPaint?.start:e[t].markerPaint?.end;if(!a?.length)continue;let n=i[t].points,o=0===r;H.push(j(a,o?n[0]:n.at(-1),o?n[1]:n.at(-2),t,o))}let z=(e,t,r)=>{if(g&&!g(t,r,e.pieces,e))return!1;if(void 0!==c)for(let a=0;a<E.length;a++){x();let n=E[a];if(T(e,n))for(let o=n.begin;o<n.end;o++){x();let n=N[o];if(!(a===t&&(n.join?n.point===(r?1:i[t].points.length-2):r?n.point<=1:n.point>=i[t].points.length-3))&&X(e,n))return!1}}for(let t of b)if(x(5),!(e.maxX<=t.minX||e.minX>=t.maxX||e.maxY<=t.minY||e.minY>=t.maxY)&&u(e.pieces,t.pieces,x))return!1;return!0},U=0;p(3*e.length+2),x(3*e.length);let V=new Uint8Array(3*e.length),B=(r,a,n,l,g,c,f=-1,y,m=-1)=>{let u=!1;for(let b=0;b<E.length&&!u&&U<8;b++){if(x(),y?b!==m:0===g&&b===r)continue;let M=E[b],w=i[b].points;for(let m=M.begin;m<M.end&&!u&&U<8;m++){x(8);let v=N[m],k=v.point;if(v.join||k<1||k+2>=w.length)continue;let P=w[k],Y=w[k+1],T=w[k-1],C=w[k+2],L=P.y===Y.y,O=!1;if(y){x(5);let e=b===f?y.candidateSegment:y.peerSegment;O=e>=k&&e<=k+2}else{if(L!==l)continue;x(4);let e=b===r;if(O=!(e&&(a?k<=1:k>=w.length-3))&&X(n,v),0===g&&!O)continue;for(let t=0;t<2&&!O;t++){x(8);let i=N[M.begin+k+(0===t?-1:1)];e&&(a?i.point<=1:i.point>=w.length-3)||X(n,i)&&(O=!0)}if(!O){x(3);let t=M.begin+w.length-1,i=M.end;for(;t<i;){x(3);let e=t+Math.floor((i-t)/2);N[e].point<k?t=e+1:i=e}for(let i=t;i<M.end&&!O;i++){x(8);let t=N[i];if(t.point>k+1)break;e&&t.point===(a?1:w.length-2)||X(n,t)&&(O=!0)}}}if(!O)continue;let j=L?Math.min(P.x,Y.x):Math.min(P.y,Y.y),z=L?Math.max(P.x,Y.x):Math.max(P.y,Y.y);if(L?T.x!==P.x||C.x!==Y.x:T.y!==P.y||C.y!==Y.y)continue;let V=e[b].label,B=V?i[b].labelPosition:void 0,_=!1,q=!1;if(B&&0===g){let e=!1;for(let i=k-1;i<=k+1;i++)if(x(6),t(B,w[i],w[i+1])){e=!0;break}if(e)continue}else if(B){if(x(18),t(B,P,Y))continue;_=t(B,T,P),q=t(B,Y,C)}let D=L?P.y:P.x,Q=L?T.y:T.x,$=L?C.y:C.x,G=L?c.bounds.y:c.bounds.x,J=G+(L?c.bounds.height:c.bounds.width);if(D===Q||D===$)continue;if(D>Q?G=Math.max(G,Q):J=Math.min(J,Q),D>$?G=Math.max(G,$):J=Math.min(J,$),B&&V&&(_||q)){if(x(),0!==d)continue;x(6);let e=L?B.y:B.x,t=(L?V.height:V.width)/2+2+I,i=e-t,r=e+t,a=!1;for(let e=0;e<2;e++){if(x(12),0===e?!_:!q)continue;let t=0===e?Q:$;if(i<Math.min(t,D)||r>Math.max(t,D)){a=!0;break}if(t<=i)G=Math.max(G,r);else if(t>=r)J=Math.min(J,i);else{a=!0;break}}if(a)continue}if(!(G<J))continue;let K=2;S[0]=G,S[1]=0,S[2]=J,S[3]=0,p(1);let Z=(e,t)=>{x(2),(e=Math.max(G,e))<(t=Math.min(J,t))&&(S[2*K]=e,S[2*K+1]=1,S[2*++K]=t,S[2*K+1]=-1,K++)};if(y){x(12);let e=b===f?y.peerIndex:f,t=b===f?y.peerSegment:y.candidateSegment,i=N[E[e].begin+t-1];Z((L?i.minY:i.minX)-I-.01,(L?i.maxY:i.maxX)+I+.01)}for(let e of c.obstacles)x(5),(L?e.x+e.width+I<j||e.x-I>z:e.y+e.height+I<j||e.y-I>z)||Z((L?e.y:e.x)-I,(L?e.y+e.height:e.x+e.width)+I);for(let e of H)x(5),(L?e.maxX+I<j||e.minX-I>z:e.maxY+I<j||e.minY-I>z)||Z((L?e.minY:e.minX)-I-.01,(L?e.maxY:e.maxX)+I+.01);for(let e=0;e<N.length;e++){x(5);let t=N[e];!t.current||e===m||t.join||t.a.y===t.b.y!==L||(L?t.maxX<j||t.minX>z:t.maxY<j||t.minY>z)||Z((L?t.minY:t.minX)-I-.01,(L?t.maxY:t.maxX)+I+.01)}for(let e=1;e<K;e++){let t=S[2*e],i=S[2*e+1],r=e;for(;r>0&&(x(),!(S[2*(r-1)]<=t));)S[2*r]=S[2*(r-1)],S[2*r+1]=S[2*(r-1)+1],r--;S[2*r]=t,S[2*r+1]=i}let ee=-1,et=-1;for(let e=0;e<8&&U<8;e++){let e=0,t=-1,r=1/0,a=0;for(let i=1;i<K;i++){x(3),e+=S[2*(i-1)+1];let n=S[2*(i-1)],o=S[2*i],l=n+(o-n)/2,s=Math.abs(l-D);0!==e||!(n<o)||l===D||s<ee||s===ee&&i<=et||s<r&&(t=i,r=s,a=l)}if(t<0)break;ee=r,et=t,U++,p(w.length+1),o(2),x(w.length);let n=w.slice(),l={x:P.x,y:P.y},g={x:Y.x,y:Y.y};L?l.y=g.y=a:l.x=g.x=a,n[k]=l,n[k+1]=g;let c=!0;for(let e=k-1;e<=k+1&&c;e++){if(A(W,n[e],n[e+1]),!R(b,W)){c=!1;break}for(let t of H)if(x(2),!(e!==k&&t.owner===b&&(t.source?e<=1:e>=w.length-3))&&X(t,W)){c=!1;break}if(!c)break;if(e!==k){x(6);let t=e===k-1?T:C,i=e===k-1?P:Y,r=e===k-1?l:g,a=Math.abs(i.x-t.x)+Math.abs(i.y-t.y);if(Math.abs(r.x-t.x)+Math.abs(r.y-t.y)>a){for(let t of(A(W,i,r),H))if(x(4),!(t.owner===b&&(t.source?0===e:e===w.length-2))&&t.owner===b&&(t.source?e<=1:e>=w.length-3)&&X(t,W)){c=!1;break}}}}x(4);for(let e=Math.max(1,k-1);e<=Math.min(n.length-2,k+2)&&c;e++){x(4);let t=n[e-1],i=n[e],r=n[e+1];if(t.x===i.x!=(i.x===r.x)){for(let t of(W.join=!0,A(W,i,i),H))if(x(),(t.owner!==b||e===k||e===k+1||e!==(t.source?1:w.length-2))&&X(t,W)){c=!1;break}W.join=!1}}if(!(!c||!s(b,n))){i[b].points=n,F(b),h(b),u=!0;break}}}}return u},_=0;for(let a=0;a<e.length;a++){x();let n=e[a];if(!1!==n.visible)e:for(let e=0;e<2;e++){x();let g=0===e?n.markerPaint?.start:n.markerPaint?.end;if(!g?.length)continue;let m=i[a].points,u=0===e,M=u?m[0]:m.at(-1),w=u?m[1]:m.at(-2),v=H[_++];if(U=0,!z(v,a,u)){let k=r[u?n.source:n.target],P=w.x===M.x,T=P?k.x:k.y,C=T+(P?k.width:k.height),L=P?M.x:M.y,O=(P?v.minX:v.minY)-L,q=(P?v.maxX:v.maxY)-L;for(let L=0;L<2;L++){if(x(),void 0!==c&&y){do{if(x(3),!B(a,u,v,P,L,y))break;if(x(4),m=i[a].points,M=u?m[0]:m.at(-1),w=u?m[1]:m.at(-2),z(v,a,u)){p(1),b.push(v),x(),V[2*a+e]=U;continue e}}while(1===L&&U<8)}let D=2;for(let e of(S[0]=T,S[1]=0,S[2]=C,S[3]=0,b)){if(x(6),P?v.maxY<=e.minY||v.minY>=e.maxY:v.maxX<=e.minX||v.minX>=e.maxX)continue;let t=Math.max(T,(P?e.minX:e.minY)-q-.01),i=Math.min(C,(P?e.maxX:e.maxY)-O+.01);t<i&&(S[2*D]=t,S[2*D+1]=1,S[2*++D]=i,S[2*D+1]=-1,D++)}if(void 0!==c)for(let e=0;e<E.length;e++){if(x(),e===a)continue;let t=E[e];if(!(P?v.maxY<=t.minY||v.minY>=t.maxY:v.maxX<=t.minX||v.minX>=t.maxX))for(let e=t.begin;e<t.end;e++){x(6);let t=N[e];if(P?v.maxY<=t.minY||v.minY>=t.maxY:v.maxX<=t.minX||v.minX>=t.maxX)continue;let i=Math.max(T,(P?t.minX:t.minY)-q-.01),r=Math.min(C,(P?t.maxX:t.maxY)-O+.01);i<r&&(S[2*D]=i,S[2*D+1]=1,S[2*++D]=r,S[2*D+1]=-1,D++)}}for(let e=1;e<D;e++){let t=S[2*e],i=S[2*e+1],r=e;for(;r>0&&(x(),!(S[2*(r-1)]<=t));)S[2*r]=S[2*(r-1)],S[2*r+1]=S[2*(r-1)+1],r--;S[2*r]=t,S[2*r+1]=i}let Q=!1,$=1/0,G=-1,J=-1;for(let e=0;e<8&&U<8;e++){let e=-1,l=0,y=2,N=0;for(let t=1;t<D;t++){x(2),N+=S[2*(t-1)+1];let i=S[2*t]-S[2*(t-1)],r=+(0!==N),a=r>J||r===J&&(i<$||i===$&&t>G);i>0&&a&&(r<y||r===y&&i>l)&&(l=i,e=t,y=r)}if(e<0)break;let E=S[2*(e-1)]+l/2;$=l,G=e,J=y,U++;let T=2===m.length;x(3);let C=0;if(T){let e=P?M.y:M.x,r=P?w.y:w.x,o=Math.sign(r-e),l=o>0?(P?v.maxY:v.maxX)-e:e-(P?v.minY:v.minX),s=0;for(let e of H)x(5),e.owner===a&&e.source!==u&&(s=Math.max(s,o>0?r-(P?e.minY:e.minX):(P?e.maxY:e.maxX)-r));x(10);let h=I+d,g=Math.min(8,Math.abs(r-e)),c=e+o*Math.max(g,l+h),f=r-o*Math.max(g,s+h);if(n.label){x(9);let e=i[a].labelPosition;if(!e||!t(e,M,w))continue;let r=P?e.y:e.x,l=(P?n.label.height:n.label.width)/2+2+I;f=o>0?Math.min(f,r-l):Math.max(f,r+l)}if(!(o*(f-c)>0))continue;C=c+(f-c)/2}p((T?4:m.length)+1),o(T?4:3),x(m.length+6);let L={x:M.x,y:M.y},O={x:w.x,y:w.y};P?(L.x=E,O.x=E,T&&(O.y=C),1e-7>Math.abs(L.y-k.y)?L.y=k.y:1e-7>Math.abs(L.y-k.y-k.height)&&(L.y=k.y+k.height)):(L.y=E,O.y=E,T&&(O.x=C),1e-7>Math.abs(L.x-k.x)?L.x=k.x:1e-7>Math.abs(L.x-k.x-k.width)&&(L.x=k.x+k.width));let V=T?u?[L,O,P?{x:w.x,y:C}:{x:C,y:w.y},w]:[w,P?{x:w.x,y:C}:{x:C,y:w.y},O,L]:m.slice();V[u?0:V.length-1]=L,V[u?1:V.length-2]=O;let B=u?V.length-1:0,q=u?V.length-2:1,K=V[B],Z={x:K.x,y:K.y},ee=r[u?n.target:n.source];if(V[q].x===Z.x?1e-7>Math.abs(Z.y-ee.y)?Z.y=ee.y:1e-7>Math.abs(Z.y-ee.y-ee.height)&&(Z.y=ee.y+ee.height):V[q].y===Z.y&&(1e-7>Math.abs(Z.x-ee.x)?Z.x=ee.x:1e-7>Math.abs(Z.x-ee.x-ee.width)&&(Z.x=ee.x+ee.width)),(Z.x!==K.x||Z.y!==K.y)&&(p(16),x(256),f(Z.x)!==f(K.x)||f(Z.y)!==f(K.y)))continue;V[B]=Z;let et=j(g,L,O,a,u);if(!z(et,a,u))continue;let ei=!0,er=!1;if(void 0!==c){for(let e=1;e<V.length;e++)if(x(),!(!T&&!er&&(u?e>2&&e!==V.length-1:e<V.length-2&&1!==e))){if(A(W,V[e-1],V[e]),!R(a,W)){if(x(5),!er&&!T&&2===e&&4===V.length&&!n.label&&0===d){let t=V[q],i=P?L.y:L.x,r=P?O.y:O.x,n=P?Z.y:Z.x,l=Math.sign(r-i);if(x(6),(P?t.y===r&&t.x===Z.x:t.x===r&&t.y===Z.y)&&l*(n-r)>0){x(10);let s=l>0?(P?et.maxY:et.maxX)-i:i-(P?et.minY:et.minX),h=Math.min(8,Math.abs(r-i)),g=Math.min(8,Math.abs(n-r)),d=0;for(let e of H)x(5),e.owner===a&&e.source!==u&&(d=Math.max(d,l>0?n-(P?e.minY:e.minX):(P?e.maxY:e.maxX)-n));x(8);let f=i+l*Math.max(h,s+I),y=n-l*Math.max(g,d+I),m=r-l*c,b=l>0?Math.min(y,m):Math.max(y,m);if(l*(b-f)>0){x(4);let i=f+(b-f)/2;p(2),o(1);let r={x:t.x,y:t.y};P?O.y=r.y=i:O.x=r.x=i,V[q]=r,er=!0,e=0;continue}}}ei=!1;break}for(let t of T||er?H:b){x(er?4:3);let i=er&&t.owner===a&&t.source===u?et:t;if(!(i.owner===a&&(T||er?i.source?1===e:e===V.length-1:i.source?e<=2:e>=V.length-2))&&X(i,W)){ei=!1;break}}if(!ei)break}}if(ei&&void 0!==c)for(let e=1;e+1<V.length;e++){if(x(),!T&&!er&&(u?e>2&&e!==V.length-2:e<V.length-3&&1!==e))continue;let t=V[e-1],i=V[e],r=V[e+1];if(x(4),t.x===i.x!=(i.x===r.x)){for(let t of(W.join=!0,A(W,i,i),W.join=!1,W.join=!0,T||er?H:b)){x(er?4:3);let i=er&&t.owner===a&&t.source===u?et:t;if(!(!T&&!er&&i.owner===a&&(i.source?1===e:e===V.length-2))&&X(i,W)){ei=!1;break}}if(W.join=!1,!ei)break}}if(!(!ei||!s(a,V))){T&&void 0!==c&&Y(a,V),i[a].points=V,void 0!==c&&F(a),v=et,H[_-1]=et,h(a),Q=!0;break}}if(!Q){if(0===L)continue;l("No physically clear measured marker seat at occurrence "+a+" role "+e)}break}}p(1),b.push(v),x(),V[2*a+e]=U}}if(m&&y&&void 0!==c&&0===d){p(1);let t={candidateSegment:-1,peerIndex:-1,peerSegment:-1};for(let r=0;r<i.length;r++)if(x(),!1!==e[r].visible)for(;m(r,t);){let i=!1;for(let a=0;a<2&&!i;a++){x(3);let n=0===a?r:t.peerIndex,o=e[n].markerPaint,l=!!(o?.start?.length||o?.end?.length);for(let a=0;a<(l?2:1)&&!i;a++){if(x(4),l&&!(0===a?o?.start?.length:o?.end?.length))continue;let s=l?2*n+a:2*e.length+n;(U=V[s])>=8||(i=B(n,0===a,void 0,!1,1,y,r,t,n),x(),V[s]=U)}}i||l("No physically clear measured sharp contact repair at occurrence "+r)}}}(i.edges,o.edges,h,c,d,y,I,e=>{M(2),v.has(e)||(--c.arcs<0&&y("agentic marker full-proof capacity limit"),v.add(e)),m.has(e)||(c.arcs--,c.arcs<0&&y("agentic marker full-proof capacity limit"),m.add(e))},(e,t,r,a)=>{c.arcs--,c.arcs<0&&y("agentic marker full-proof capacity limit");let n=(e,t,i,n)=>{if(M(5),a.maxX<=e||a.minX>=e+i||a.maxY<=t||a.minY>=t+n)return!0;M(8);let o=P[0].points;return o[0].x=e,o[0].y=t,o[1].x=e+i,o[1].y=t,o[2].x=e+i,o[2].y=t+n,o[3].x=e,o[3].y=t+n,!u(r,P,M)},h=t?i.edges[e].source:i.edges[e].target;for(let e=0;e<l.length;e++){if(M(),e===h)continue;let t=l[e],r=(i.nodes[e].paintStrokeWidth??0)/2;if(!n(t.x-r,t.y-r,t.width+2*r,t.height+2*r))return!1}for(let e=0;e<s.length;e++){M();let t=s[e],r=g[e].headerHeight??g[e].padding.top,a=(i.groups[e].paintStrokeWidth??0)/2;if(r>0&&!n(t.x-a,t.y-a,t.width+2*a,r+2*a))return!1}for(let e=0;e<i.edges.length;e++){M();let t=i.edges[e].label,r=o.edges[e].labelPosition;if(t&&r&&!n(r.x-t.width/2-2,r.y-t.height/2-2,t.width+4,t.height+4))return!1}return!0},p,i.maximumEdgeBendRadius??0,{bounds:N,obstacles:S},0===i.maximumEdgeBendRadius?(e,t)=>(M(5),t.candidateSegment=t.peerIndex=t.peerSegment=-1,!v.has(e)&&(I(e,o.edges[e].points,t,!b)?(w(1),v.add(e),!1):(M(6),(t.peerIndex<0||t.peerIndex>=o.edges.length||t.peerIndex===e||t.candidateSegment<1||t.candidateSegment>=o.edges[e].points.length||t.peerSegment<1||t.peerSegment>=o.edges[t.peerIndex].points.length)&&y("Measured final route violates its owned path or contact reservation"),!0))):void 0),b)for(let e=0;e<o.edges.length;e++)M(2),v.has(e)||(I(e,o.edges[e].points)||y("Measured final route violates its owned path or contact reservation"),--c.arcs<0&&y("agentic marker full-proof capacity limit"),v.add(e));return v}function j(e,t=!1){return(t&&!e.label?1:2)*e.minSpan}function H(e,t){let i=new Uint8Array(e.length),r=new Uint32Array(e.length),a=new Int32Array(e.length),n=[],o=e.length-1;for(let l=0;l<e.length;l++)if(!i[l])for(i[l]=1,n.push(l);n.length;){let l=n.at(-1);if(r[l]<e[l].length){let a=t[e[l][r[l]]];r[l]=r[l]+1,i[a.target]||(i[a.target]=1,n.push(a.target))}else n.pop(),i[l]=2,a[l]=o--}return a}function z(e,t,i){let r=e.length,a=i.length,n=new Int32Array(2*a+1).fill(-1),o=new Int32Array(r).fill(-1),l=new Int32Array(r).fill(-1),s=Uint32Array.from(e,e=>e.length),h=Uint32Array.from(t,e=>e.length),g=new Uint8Array(r).fill(1),c=new Int32Array(r),d=[],f=[],y=0,m=0,u=r-1,x=e=>a+h[e]-s[e],p=e=>{let t=x(e),i=n[t];l[e]=-1,o[e]=i,i>=0&&(l[i]=e),n[t]=e,y=Math.max(y,t)},b=e=>{let t=l[e],i=o[e];t>=0?o[t]=i:n[x(e)]=i,i>=0&&(l[i]=t)},M=r=>{for(let t of(b(r),g[r]=0,e[r])){let e=i[t].source;g[e]&&(b(e),h[e]=h[e]-1,p(e),0===h[e]&&f.push(e))}for(let e of t[r]){let t=i[e].target;g[t]&&(b(t),s[t]=s[t]-1,p(t),0===s[t]&&d.push(t))}};for(let e=r-1;e>=0;e--)p(e),s[e]||d.push(e),h[e]||f.push(e);for(;m<=u;){for(;f.length;){let e=f.pop();g[e]&&(c[e]=u--,M(e))}for(;d.length;){let e=d.pop();g[e]&&(c[e]=m++,M(e))}if(m>u)break;for(;y>=0&&-1===n[y];)y--;let e=n[y];if(void 0===e||e<0)throw TypeError("Feedback ordering lost an active vertex");c[e]=m++,M(e)}return c}var U=class extends Error{};function V(e,t){return Number.isFinite(e)&&(t?e>0:e>=0)}function B(e,t,i,r,a,n){if(t.length>16||t.length+e.junctions.length+e.groups.length>24||i.length>32||e.alignments.length||e.edges.some(e=>void 0!==e.label||"group"===e.source.boundary||"group"===e.target.boundary))return i;let o=8;if(1!==g(i)||n(i))return i;for(let e=0;e<t.length&&o>0;e++){let l=t[e];for(let s=e+1;s<t.length&&o>0;s++){let e=t[s];if(l.parentId===e.parentId&&l.width===e.width&&l.height===e.height)for(let t of["x","y"]){if(o<=0||l[t]===e[t])continue;o--;let s=l[t];if(l[t]=e[t],e[t]=s,a()){let e=r();if(0===g(e)&&!n(e)&&e.every((e,t)=>e.obstacleFree&&(!i[t].sourceFacesTarget||e.sourceFacesTarget)&&(!i[t].targetFacesSource||e.targetFacesSource)))return e}e[t]=l[t],l[t]=s}}}return i}var _=class{#e=new Map;#t=0;#i;constructor(e){this.#i=e}get(e){let t=this.#e.get(e);if(t)return this.#e.delete(e),this.#e.set(e,t),t.value}set(e,t,i){if(i>this.#i)return;let r=this.#e.get(e);for(r&&(this.#e.delete(e),this.#t-=r.weight),this.#e.set(e,{value:t,weight:i}),this.#t+=i;this.#e.size>64||this.#t>this.#i;){let e=this.#e.keys().next().value;this.#t-=this.#e.get(e).weight,this.#e.delete(e)}}},q=globalThis,D=(q.process?.env?.AGENTIC_MERMAID_ELK_CACHE??q.AGENTIC_MERMAID_ELK_CACHE)!=="0";function Q(e){return JSON.stringify(e,(e,t)=>void 0===t?"\0undefined":"number"!=typeof t||Number.isFinite(t)?"string"==typeof t&&t.startsWith("\0")?`\0${t}`:t instanceof Map?{mapEntries:[...t]}:t instanceof Set?{setValues:[...t]}:t:`\0${t}`)}var $=new WeakMap,G=new WeakMap;function J(e){let t=new _(8388608);return i=>{if(!D)return e(i);let r=Q(i);if(r.length>1048576)return e(i);let a=t.get(r);if(a)return structuredClone(a);let n=e(i),o=2*r.length+4*JSON.stringify(n).length+512;return o<=8388608&&t.set(r,structuredClone(n),o),n}}function K(a,h,c,d){let f=d,m=G.get(a);try{if(m&&d&&d!==m){m.pairs-=24;let e=d.pairs,t=d.arcs,i=d.swaps;m.pairs=Math.min(m.pairs,e-(1e6-m.pairs)),m.arcs=Math.min(m.arcs,t-(65536-m.arcs)),m.swaps=Math.min(m.swaps,i-(1e6-m.swaps)),(!Number.isFinite(m.pairs)||!Number.isFinite(m.arcs)||!Number.isFinite(m.swaps)||m.pairs<0||m.arcs<0||m.swaps<0)&&c("agentic marker preparation work limit")}d=G.get(a)??d??{pairs:1e6,arcs:65536,swaps:1e6};let f=function a(h,c,d,f={pairs:1e6,arcs:65536,swaps:1e6},m={attempts:128,scorePairs:8e6,loopPairs:2e6,rankPairs:2e5,blockPairs:2e6,routing:{pairs:5e5,arcs:32768,swaps:5e5}}){let{nodes:u,edges:x,padding:p,nodeSpacing:B,layerSpacing:_}=h;if((u.length>4096||x.length>16384)&&d("agentic local graph-size limit"),![p,B,_].every(e=>V(e,!1)))throw TypeError("Measured graph spacing must be finite and nonnegative");if(void 0!==h.edgeSpacing&&!V(h.edgeSpacing,!0))throw TypeError("Measured edge spacing must be finite and positive");if(void 0!==h.minimumTerminalLead&&!V(h.minimumTerminalLead,!0))throw TypeError("Measured terminal lead must be finite and positive");if(void 0!==h.maximumEdgeStrokeWidth&&!V(h.maximumEdgeStrokeWidth,!0))throw TypeError("Measured maximum edge stroke width must be finite and positive");if(void 0!==h.maximumEdgeBendRadius&&!V(h.maximumEdgeBendRadius,!1))throw TypeError("Invalid measured edge bend radius");for(let e of h.nodes)if(void 0!==e.paintStrokeWidth&&!V(e.paintStrokeWidth,!0))throw TypeError("Invalid measured node paint stroke");for(let e of h.nodes)if(void 0!==e.paintCornerRadius&&!V(e.paintCornerRadius,!1))throw TypeError("Invalid measured node corner radius");for(let e of h.nodes)if(void 0!==e.minimumPortSpacing&&!V(e.minimumPortSpacing,!0))throw TypeError("Invalid measured node port spacing");for(let e of h.groups??[])if(void 0!==e.paintStrokeWidth&&!V(e.paintStrokeWidth,!0))throw TypeError("Invalid measured group paint stroke");for(let e of h.groups??[])if(void 0!==e.paintCornerRadius&&!V(e.paintCornerRadius,!1))throw TypeError("Invalid measured group corner radius");for(let e of h.edges)void 0!==e.markerPaint&&function(e){if(!e||"object"!=typeof e)throw TypeError("Invalid measured marker paint");for(let t of[e.start,e.end])if(void 0!==t){if(!Array.isArray(t)||t.length>64)throw TypeError("Invalid measured marker pieces");for(let e of t)if("circle"===e.kind){if(![e.cx,e.cy,e.r].every(e=>Number.isFinite(e*e*16))||!(e.r>0))throw TypeError("Invalid measured marker circle")}else if("polygon"===e.kind){if(!Array.isArray(e.points)||e.points.length<3||e.points.length>32)throw TypeError("Invalid measured marker polygon");for(let t of e.points)if(!Number.isFinite(t.x*t.x*16)||!Number.isFinite(t.y*t.y*16))throw TypeError("Invalid measured marker coordinate");let t=0;for(let i=0;i<e.points.length;i++){let r=e.points[i],a=e.points[(i+1)%e.points.length],n=e.points[(i+2)%e.points.length],o=(a.x-r.x)*(n.y-a.y)-(a.y-r.y)*(n.x-a.x);if(!Number.isFinite(o)||o&&t&&Math.sign(o)!==t)throw TypeError("Nonconvex measured marker polygon");o&&(t=Math.sign(o))}if(!t)throw TypeError("Empty measured marker polygon")}else throw TypeError("Invalid measured marker kind")}}(e.markerPaint);if(!["TD","TB","BT","LR","RL"].includes(h.direction))throw TypeError("Invalid measured graph direction");if(h.groups?.length)return u.length+h.groups.length>4096&&d("agentic local compound-size limit"),function(i,a,n,h,g){let c=i.groups,d=i.nodes.length,f=d+c.length,m=new Int32Array(f).fill(-1),u=Array.from({length:c.length+1},()=>[]),x=Array.from({length:c.length+1},()=>[]),p=new Map,j,H=new Set;for(let e=0;e<f;e++){let t=e<d?i.nodes[e]:c[e-d];if(H.has(t.id))throw TypeError("Measured compound identities must be unique");if(H.add(t.id),void 0!==t.modelOrder&&(!Number.isSafeInteger(t.modelOrder)||t.modelOrder<0))throw TypeError("Invalid measured model order");if(void 0!==t.partition&&(!Number.isSafeInteger(t.partition)||t.partition<0||t.partition>1e4))throw TypeError("Invalid measured partition");let r=t.parent??-1;if(!Number.isInteger(r)||r<-1||r>=c.length||r>=0&&e===d+r)throw TypeError("Invalid measured compound parent");if(e<d){let t=i.nodes[e];if(![t.width,t.height].every(e=>Number.isFinite(e)&&e>0))throw TypeError("Invalid measured compound leaf dimensions")}m[e]=r,u[r+1].push(e)}for(let e=0;e<c.length;e++){let t=new Set;for(let i=e;i>=0;i=m[d+i]){if(t.has(i))throw TypeError("Measured compound parents must be acyclic");t.add(i),t.size>64&&n("agentic local compound-depth limit")}let i=c[e];if(void 0!==i.direction&&!["TD","TB","BT","LR","RL"].includes(i.direction))throw TypeError("Invalid measured compound direction");if(![i.minWidth,...Object.values(i.padding)].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured compound dimensions");if(void 0!==i.headerHeight&&(!Number.isFinite(i.headerHeight)||i.headerHeight<0||i.headerHeight>i.padding.top))throw TypeError("Invalid measured compound header")}for(let e=0;e<i.edges.length;e++){let t=i.edges[e];if(!Number.isInteger(t.source)||!Number.isInteger(t.target)||t.source<0||t.target<0||t.source>=f||t.target>=f)throw TypeError("Invalid measured compound endpoint");if(!Number.isSafeInteger(t.minSpan)||t.minSpan<1||t.label&&![t.label.width,t.label.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured compound edge dimensions");if(void 0!==t.short&&!0!==t.short)throw TypeError("Invalid measured short-edge preference");if(void 0!==t.boundaryMarker&&![t.boundaryMarker.inset,t.boundaryMarker.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured ancestor marker dimensions");let r=m[t.source];if(r!==m[t.target]){let i=new Set([-1]);for(let e=r;e>=0;e=m[d+e])i.add(e);for(r=m[t.target];!i.has(r);)r=m[d+r];let a=e=>{for(;m[e]!==r;)e=d+m[e];return e},n=a(t.source),o=a(t.target);if(n===o){(j??=[]).push(e);continue}p.set(e,{source:n,target:o,host:r})}x[r+1].push(e)}let z=j?function(e,t,i,r){let a=e.groups,n=e.nodes.length,o=Math.max(8,e.edgeSpacing??6,e.minimumTerminalLead??0),l=new Map,s=new Map,h=new Map,g=new Map,c=(e,a)=>{for(let o=t[a];o>=0;o=t[n+o])if(--i.pairs<0&&r("agentic local cross-hierarchy obstacle-work limit"),o===e)return!0;return!1};for(let[t,d]of e.edges.entries()){--i.pairs<0&&r("agentic local cross-hierarchy obstacle-work limit");let e=d.source>=n&&c(d.source-n,d.target),f=d.target>=n&&c(d.target-n,d.source);if(!e&&!f)continue;let m=o;if(1!==d.minSpan){if(!Number.isSafeInteger(d.minSpan)||d.minSpan<1)throw TypeError("Invalid measured compound edge dimensions");let e=y(d.minSpan);(!Number.isSafeInteger(e)||e<0)&&r("agentic local coordinate-range limit"),m=Math.max(o,e)}let u=(e?d.source:d.target)-n,x=a[u],p=s.get(u)??0,b=Math.max(d.label?.height??0,d.boundaryMarker?.height??0),M=b+2*o,w=Math.max(2*o,(d.boundaryMarker?.inset??0)+o);--i.arcs<0&&r("agentic local cross-hierarchy visibility-arc limit"),l.set(t,{edge:t,container:u,interior:e?d.target:d.source,containerEnd:e?"source":"target",rowOffset:x.padding.top+p+o+b/2,labelInset:w,minimumLead:m,...d.label?{label:{...d.label}}:{}}),s.set(u,p+M),h.set(u,Math.max(h.get(u)??0,w+(d.label?.width??0)+2*o)),g.set(u,Math.max(g.get(u)??0,m))}return{connections:l,clearance:o,groups:l.size?a.map((e,t)=>s.has(t)?{...e,headerHeight:e.headerHeight??e.padding.top,padding:{...e.padding,top:e.padding.top+s.get(t),left:Math.max(e.padding.left+h.get(t),g.get(t)+o)}}:e):a}}(i,m,g,n):void 0;if(z){if(j.some(e=>!z.connections.has(e)))throw TypeError("Ancestor planner lost an authored endpoint occurrence");c=z.groups}let U=Array(c.length+1),V=0,B=(e,t)=>{let r=c[e-1],o=r?.direction??t,l=u[e],s=new Map(l.map((e,t)=>[e,t])),h=l.map(e=>{if(e<d){let{id:t,width:r,height:a,partition:n,modelOrder:o,minimumPortSpacing:l}=i.nodes[e];return{id:t,width:r,height:a,partition:n,modelOrder:o,...void 0!==l?{minimumPortSpacing:l}:{}}}let t=B(e-d+1,o);return{id:c[e-d].id,width:t.width,height:t.height,partition:c[e-d].partition,modelOrder:c[e-d].modelOrder}}),g={nodes:h,edges:x[e].map(e=>{let t=i.edges[e],r=p.get(e)??t;return{...t,source:s.get(r.source),target:s.get(r.target)}}),padding:0,direction:o,nodeSpacing:i.nodeSpacing,layerSpacing:i.layerSpacing,edgeSpacing:i.edgeSpacing,...void 0!==i.minimumTerminalLead?{minimumTerminalLead:i.minimumTerminalLead}:{},...i.placementOnly?{placementOnly:!0}:{}};p.size&&x[e].some(e=>p.has(e))&&(g.compactPrivateRanks=!0);let f=a(g);(V+=f.expandedVertices??h.length)>32768&&n("agentic local compound-expansion limit");let y=r?.padding??{top:i.padding,right:i.padding,bottom:i.padding,left:i.padding},m=Math.max(r?.minWidth??0,f.width+y.left+y.right,1),b={direction:o,placed:f,width:m,height:Math.max(f.height+y.top+y.bottom,1),dx:y.left+(m-f.width-y.left-y.right)/2,dy:y.top};return Number.isFinite(b.width+b.height+b.dx+b.dy)||n("agentic local coordinate-range limit"),U[e]=b,b},_=B(0,i.direction),q=Array(d),D=Array(c.length),Q=Array(i.edges.length),$=(e,t,i)=>{let r=U[e],a=t+r.dx,n=i+r.dy;u[e].forEach((e,t)=>{let i=r.placed.nodes[t],o={x:i.x+a,y:i.y+n};if(e<d)q[e]=o;else{let t=e-d,i=U[t+1];D[t]={...o,width:i.width,height:i.height},$(t+1,o.x,o.y)}}),x[e].forEach((e,t)=>{let i=r.placed.edges[t];Q[e]={points:i.points.map(e=>({x:e.x+a,y:e.y+n})),...i.labelPosition?{labelPosition:{x:i.labelPosition.x+a,y:i.labelPosition.y+n}}:{}}})};if($(0,0,0),z)for(let e of z.connections.keys())Q[e]=function(e,t,i,r){let a=e.connections.get(t),n=i[a.container],o=e.clearance,l=n.y+a.rowOffset;r?.(a.label?3:2);let s=[{x:n.x,y:l},{x:n.x+e.groups[a.container].padding.left-o,y:l}];return{points:"source"===a.containerEnd?s:s.reverse(),...a.label?{labelPosition:{x:n.x+a.labelInset+a.label.width/2,y:l}}:{}}}(z,e,D,e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid ancestor placeholder reservation");V+e>32768&&n("agentic local compound-expansion limit"),V+=e});let G={topology:"layered",width:_.width,height:_.height,nodes:q,groups:D,edges:Q,expandedVertices:V},J=!1;if(void 0!==i.maximumEdgeStrokeWidth){for(let e of i.edges)if(--g.pairs<0&&n("agentic marker metadata work limit"),e.markerPaint?.start?.length||e.markerPaint?.end?.length){J=!0;break}}return i.placementOnly?G:p.size||z||J?function(i,a,n,h,g,c,d,f,y){let m=i.nodes.length,u=a.groups,x=i.groups,p=y?.groups??x,j=x.length>16||h.size>16||i.edges.length>128,H=a.edges.reduce((e,t)=>e+t.points.length,0);H>2048&&f("agentic local cross-hierarchy route-point limit");let z=a.expandedVertices??0,U=z,V=e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid compound visibility reservation");z+e>32768&&f("agentic local cross-hierarchy visibility-expansion limit"),z+=e},B,_=()=>B??=S(V,f),q,D=()=>{var e;let t,i;return q??=(e=e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid compound adjacency reservation");c.arcs-=e,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit")},t=[],i=0,{get arcs(){return i},acquire(r,a){let n,o=4*r;for(let e of((!Number.isSafeInteger(o)||o<4||o>0x7fffffff)&&f("agentic local cross-hierarchy visibility-arc limit"),t))a(),!e.active&&e.capacity>=o&&(!n||e.capacity<n.capacity)&&(n=e);return n||(e(o),i+=o,n={active:!1,capacity:o,nodes:new Int32Array(o),distances:new Float64Array(o)},t.push(n)),a(o),n.nodes.fill(-1,0,o),n.distances.fill(0,0,o),n.active=!0,n}})},Q=i.maximumEdgeStrokeWidth;void 0!==Q&&(C(c,f,2),--c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"));let $=void 0===Q?void 0:e=>C(c,f,e),G=void 0===Q?void 0:e=>{c.pairs-=e,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")},J=!1;if(void 0!==Q){for(let e of i.edges)if(--c.pairs<0&&f("agentic marker metadata work limit"),e.markerPaint?.start?.length||e.markerPaint?.end?.length){J=!0;break}}let K=Math.max(8,i.edgeSpacing??6),Z=a.nodes.map((e,t)=>({...e,width:i.nodes[t].width,height:i.nodes[t].height})),ee=[...Z,...u],et=new Set,ei=new Set,er,ea,en;for(let[d,S]of h)for(let P=0;P<2;P++){let R,W=!1,B,q=e=>((B??=[]).push(e),e);try{c.pairs-=Z.length+u.length,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let B=i.edges[d],J=a.edges[d],en=l(J.points);if(en.length<2||B.label&&!J.labelPosition)throw TypeError("Compound quotient lost its route or label");let es=B.source!==S.source,eh=B.target!==S.target,eg=(e,t,i=K)=>{let r=Math.abs(e.x-t.x)+Math.abs(e.y-t.y),a=Math.min(i,r/2);return{x:e.x+Math.sign(t.x-e.x)*a,y:e.y+Math.sign(t.y-e.y)*a}},ec=es?eg(en[0],en[1]):en[0],ed=eh?eg(en.at(-1),en.at(-2)):en.at(-1),ef=[ec,...en.slice(1,-1),ed],ey=new Set;for(let e of[B.source,B.target])for(let t=n[e];t>=0;t=n[m+t])ey.add(t);let em=Z.map((e,t)=>t===B.source||t===B.target?e:I(e,K));for(let e=0;e<u.length;e++){let t=u[e];m+e===B.source||m+e===B.target?em.push(t):ey.has(e)?x[e].padding.top>0&&em.push(I({...t,height:y||m>64?p[e].headerHeight??p[e].padding.top:x[e].padding.top},Math.max(2,(i.edgeSpacing??6)/2))):em.push(I(t,K))}let eu=[...em],ex;B.label&&--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit");for(let e=0;e<a.edges.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=a.edges[e],r=i.edges[e];if(r.label&&t.labelPosition){let i=I({x:t.labelPosition.x-r.label.width/2,y:t.labelPosition.y-r.label.height/2,width:r.label.width,height:r.label.height},2);em.push(i),eu.push(i),e===d&&(ex=i)}if(!(e===d||!1===r.visible||y?.connections.has(e)))for(let e=1;e<t.points.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let r=t.points[e-1],a=t.points[e];em.push(I({x:Math.min(r.x,a.x),y:Math.min(r.y,a.y),width:Math.abs(r.x-a.x),height:Math.abs(r.y-a.y)},Math.max(2,(i.edgeSpacing??6)/2)))}}let ep,eb=()=>ep??=(er??=function(e,t){e.arcs-=8,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit");let i=i=>{e.pairs-=i,e.pairs<0&&t("agentic local cross-hierarchy obstacle-work limit")},r=i=>{e.arcs-=i,e.arcs<0&&t("agentic local cross-hierarchy visibility-arc limit")},a,n=(e,t)=>"capacity"===t?r(e):i(e);return o=>{r(7);let l=e=>{i(3);let t=a?.[e];if(t&&a.boxes.length===o.length){let r=!0;for(let t=0;t<o.length;t++){i(3);let n=a.boxes[t],l=o[t],s=n[e]-0,h=n[e]+("x"===e?n.width:n.height)+0,g=l[e]-0,c=l[e]+("x"===e?l.width:l.height)+0;if(!Object.is(Math.floor(s/128),Math.floor(g/128))||!Object.is(Math.floor(h/128),Math.floor(c/128))){r=!1;break}}if(r)return t}return s(o,e,0,n)},h=l("x"),g=l("y"),c=b(o,e,t,{x:h,y:g});return i(1),a={boxes:o,x:h,y:g},c}}(c,f))(eu),eM=S.host,ew=eM<0?void 0:u[eM],ev=eM<0?void 0:p[eM].padding;c.pairs-=8,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let ek=eM<0?void 0:x[eM].paintCornerRadius,eS=void 0===Q||void 0===ek?1/0:(Q+(x[eM].paintStrokeWidth??0))/2+ek+1,eN=ew&&ev?0===P?{x:ew.x+ev.left,y:ew.y+ev.top,width:ew.width-ev.left-ev.right,height:ew.height-ev.top-ev.bottom}:{x:ew.x+eS,y:ew.y+ev.top,width:ew.width-2*eS,height:ew.height-ev.top-eS}:{x:0,y:0,width:a.width,height:a.height},eE=es?F(ee[B.source],g[n[B.source]+1],!0,K):[],eP=eh?F(ee[B.target],g[n[B.target]+1],!1,K):[],eI=e=>{let t=[];for(let i=n[e];i>=0;i=n[m+i])--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),t.push(u[i]);return t},eA,eF,eY="agentic local cross-hierarchy size limit",eT=e=>{if("agentic local cross-hierarchy visibility-expansion limit"===e||"cross-hierarchy route has no bounded clear corridor"===e||"cross-hierarchy route needs an unsupported self-contact repair"===e)throw new X(e);return f(e)};if(!j)try{let e=es?void 0:[ec],t=eh?void 0:[ed];if(m>64){let i={pairs:Math.min(16384,Math.floor(c.pairs/8)),candidates:64};e||(e=T(eN,em,eE,ec,eI(B.source),K,c,i,f)),t||(t=T(eN,em,eP,ed,eI(B.target),K,c,i,f)?.reverse()),e&&t||f("large cross-hierarchy route has no bounded direct corridor")}if(!e||!t){let i=32768-z,r=function(e,t,i,r,a,n,o,l,s){let h=0,g=e=>{h+e>o&&l("agentic local cross-hierarchy visibility-expansion limit"),s?.(e),h+=e},c=e.x+e.width,d=e.y+e.height,f=t=>t.x>=e.x&&t.x<=c&&t.y>=e.y&&t.y<=d,y=t.filter(t=>(--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),t.x<=c&&t.x+t.width>=e.x&&t.y<=d&&t.y+t.height>=e.y)),m=new Set([e.x,c]),u=new Set([e.y,d]);for(let t of y){for(let i of(--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),[t.x,t.x+t.width]))i>=e.x&&i<=c&&m.add(i);for(let i of[t.y,t.y+t.height])i>=e.y&&i<=d&&u.add(i)}let x=e=>{--n.pairs<0&&l("agentic local cross-hierarchy obstacle-work limit"),Number.isFinite(e.x+e.y)||l("agentic local cross-hierarchy coordinate limit"),f(e)&&(m.add(e.x),u.add(e.y))};for(let e of i)x(e.port),x(e.stub);for(let e of r)x(e);let p=(e,t)=>(--n.swaps<0&&l("agentic local cross-hierarchy coordinate-sort limit"),e-t),M=[...m].sort(p),w=[...u].sort(p),v=M.length,k=v*w.length;(!Number.isSafeInteger(3*k)||3*k>0x7fffffff)&&l("agentic local cross-hierarchy coordinate limit");let S=(e=!1)=>{let t=new Map;return{get:e=>t.get(Math.floor(e/32))?.[e%32]??0,set(i,r){let a=Math.floor(i/32),o=t.get(a);if(!o){let i=Math.min(32,k-32*a);e?(n.arcs-=i,n.arcs<0&&l("agentic local cross-hierarchy visibility-arc limit")):g(i),o=new Int8Array(i),t.set(a,o)}o[i%32]=r}}},N=S(),E=S(!0),P=S(!0),I,A=()=>I??=b(y,n,l),F=e=>{let t=N.get(e);if(t)return 1===t;let i=M[e%v],r=w[Math.floor(e/v)];return A().containsPoint(i,r)?(N.set(e,-1),!1):(N.set(e,1),!0)},Y=(e,t,i,r)=>!A().entersSegment(e,t,i,r),T=(e,t)=>Y(M[e%v],w[Math.floor(e/v)],M[t%v],w[Math.floor(t/v)]),X=e=>{let t=M.indexOf(e.x),i=w.indexOf(e.y);return t<0||i<0?-1:i*v+t};return{get vertices(){return h},virtualVertices:3*k,route(e,t){let i=X(t);(i<0||!F(i))&&l("cross-hierarchy route has no clear anchor");let r=new Map,o=new Map,s=e=>{let t=Math.floor(e/32),i=r.get(t);if(!i){let e=Math.min(32,3*k-32*t);g(e),i={distance:new Float64Array(e).fill(1/0),parent:new Int32Array(e).fill(-1),slots:new Int32Array(e).fill(-1),roots:new Int32Array(e).fill(-1)},r.set(t,i)}return i},h=e=>r.get(Math.floor(e/32)),c=e=>h(e)?.distance[e%32]??1/0,d=e=>h(e)?.parent[e%32]??-1,y=e=>h(e)?.slots[e%32]??-1,m=e=>h(e)?.roots[e%32]??-1,u=0,x=e=>o.get(Math.floor(e/32))[e%32],p=(e,t)=>{let i=Math.floor(e/32),r=o.get(i);if(!r){let e=Math.min(32,3*k-32*i);g(e),r=new Int32Array(e),o.set(i,r)}r[e%32]=t},b=e=>{let i=Math.floor(e/3);return c(e)+Math.abs(M[i%v]-t.x)+Math.abs(w[Math.floor(i/v)]-t.y)},S=(e,t)=>(--n.swaps<0&&l("agentic local cross-hierarchy heap-work limit"),b(e)<b(t)||b(e)===b(t)&&e<t),N=(e,t)=>{let i=x(e);p(e,x(t)),p(t,i),s(x(e)).slots[x(e)%32]=e,s(x(t)).slots[x(t)%32]=t},I=e=>{let t=y(e);if(-2!==t)for(t<0&&(t=u,p(u++,e),s(e).slots[e%32]=t);t>0;){let e=Math.floor((t-1)/2);if(!S(x(t),x(e)))break;N(t,e),t=e}},A=()=>{let e=x(0),t=x(--u);if(s(e).slots[e%32]=-2,u){p(0,t),s(t).slots[t%32]=0;let e=0;for(;2*e+1<u;){let t=2*e+1;if(t+1<u&&S(x(t+1),x(t))&&t++,!S(x(t),x(e)))break;N(e,t),e=t}}return e};for(let t=0;t<e.length;t++){let i=e[t],r=X(i.stub);if(r<0||!f(i.port)||!F(r)||!Y(i.port.x,i.port.y,i.stub.x,i.stub.y))continue;let a=3*r+(i.port.x===i.stub.x?2:1),n=Math.abs(i.stub.x-i.port.x)+Math.abs(i.stub.y-i.port.y)+i.penalty;if(n<c(a)){let e=s(a),i=a%32;e.distance[i]=n,e.roots[i]=t,I(a)}}let C=e=>(g(1),{x:M[e%v],y:w[Math.floor(e/v)]});for(;u;){let t=A(),r=Math.floor(t/3),o=t%3;if(r===i){let i=[],r=t;for(;d(r)>=0;)i.push(C(Math.floor(r/3))),r=d(r);i.push(C(Math.floor(r/3))),g(1),i.push({...e[m(r)].port});let a=[];for(let e of i.reverse())if(a.at(-1)?.x!==e.x||a.at(-1)?.y!==e.y)for(a.push(e);a.length>2;){let e=a.at(-3),t=a.at(-2),i=a.at(-1);if(!(e.x===t.x&&t.x===i.x&&t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y)||e.y===t.y&&t.y===i.y&&t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x)))break;a.splice(a.length-2,1)}return a}let h=r%v,f=Math.floor(r/v);for(let e=0;e<4;e++){let i=0===e?h>0?r-1:-1:1===e?h+1<v?r+1:-1:2===e?f>0?r-v:-1:f+1<w.length?r+v:-1,g=e<2?1:2;if(--n.arcs<0&&l("agentic local cross-hierarchy visibility-arc limit"),i<0||!F(i))continue;let d=Math.min(r,i),u=1===g?E:P;if(u.get(d)||u.set(d,T(r,i)?1:-1),1!==u.get(d))continue;let x=3*i+g,p=c(t)+Math.abs(M[r%v]-M[i%v])+Math.abs(w[Math.floor(r/v)]-w[Math.floor(i/v)])+(o===g?0:2*a);if(-2!==y(x)&&p<c(x)){let e=s(x),i=x%32;e.distance[i]=p,e.parent[i]=t,e.roots[i]=m(t),I(x)}}}return l("cross-hierarchy route has no bounded clear corridor")}}}(eN,em,[...eE,...eP],[ec,ed],K,c,i,eT,V);(r.virtualVertices>i||r.virtualVertices>32768-U)&&eT("agentic local cross-hierarchy visibility-expansion limit"),U+=r.virtualVertices,e??=r.route(eE,ec),t??=r.route(eP,ed).reverse()}eA=l([...e,...ef.slice(1,-1),...t]),Y(eA,c,f)&&(eF=eA,eT("cross-hierarchy route needs an unsupported self-contact repair"))}catch(e){if(!(e instanceof X))throw e;eY=e.reason,eA=void 0}if(!eA){var eo,el;let s={pairs:Math.min(16384,Math.floor(c.pairs/8)),candidates:64},m=es?eg(en[0],en[1],2*K):ec,p=eh?eg(en.at(-1),en.at(-2),2*K):ed,b=[m,...en.slice(1,-1),p];B.label&&!b.some((e,t)=>t>0&&A(J.labelPosition,b[t-1],e))&&(m=ec,p=ed,b=ef);let S=a.edges.map((e,t)=>({...e,style:!1===i.edges[t].visible||y?.connections.has(t)||h.has(t)&&!et.has(t)?"invisible":"solid"})),I=function(e,t,i,a,n,l){let s,h,g,c=r(e,l===o?"proposal":"complete"),d=0,f=0,y=0;for(let e=0;e<i.length;e++)--a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),e!==t&&"invisible"!==i[e].style&&(d+=Math.max(0,i[e].points.length-1),f+=i[e].points.length,y++);let m=(e=1)=>{a.pairs-=e,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit")};void 0!==e.maximumEdgeStrokeWidth&&C(a,n);let u=void 0===e.maximumEdgeStrokeWidth?void 0:e=>C(a,n,e),x=r=>(a.pairs-=c*Math.max(0,r.length-1)*d+r.length+d,a.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),void 0!==l(r,t,i,e,m,u,void 0,c));return d<32?x:r=>{let o=Math.max(0,r.length-1),p=1+9*r.length+(void 0===e.maximumEdgeStrokeWidth?8:20)*y+i.length,b=s?0:9*f+y+3*i.length,M=(c*o+1)*d;if(!Number.isSafeInteger(M)||M<=p+b)return x(r);if(!s){C(a,n,2*i.length),m(2*i.length),s=i.slice(),h=Array(i.length);for(let e=0;e<i.length;e++){m();let r=i[e];if(e===t||"invisible"===r.style)continue;C(a,n);let o={points:r.points,style:r.style,originalStyle:r.style,orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};L(r.points,o,m),s[e]=o,h[e]=o}C(a,n),g={orthogonal:!1,minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0}}L(r,g,m);let w=0;for(let t=0;t<s.length;t++){m();let i=h[t];i&&(i.style=O(g,i,m,e.maximumEdgeStrokeWidth)?"invisible":i.originalStyle,"invisible"!==i.style&&(w+=Math.max(0,i.points.length-1)))}return m(c*o*w+r.length+w),void 0!==l(r,t,s,e,m,u,void 0,c)}}(i,d,S,c,f,o),W=e=>{let t=Y(e,c,f)?function(e,t,i){let r=l(e);for(;;){let e;for(let a=2;a<r.length;a++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let n=r[a-2],o=r[a-1],l=r[a];if(n.x===o.x&&o.x===l.x||n.y===o.y&&o.y===l.y){e=[...r.slice(0,a-1),...r.slice(a)];break}}for(let a=1;!e&&a<r.length;a++)for(let n=a+2;n<r.length;n++){--t.pairs<0&&i("agentic local cross-hierarchy self-check limit");let o=r[a-1],l=r[a],s=r[n-1],h=r[n],g;if(o.x===l.x&&s.x===h.x){let e=Math.max(Math.min(o.y,l.y),Math.min(s.y,h.y)),t=Math.min(Math.max(o.y,l.y),Math.max(s.y,h.y));o.x===s.x&&e<=t&&(g={x:o.x,y:Math.max(e,Math.min(t,o.y))})}else if(o.y===l.y&&s.y===h.y){let e=Math.max(Math.min(o.x,l.x),Math.min(s.x,h.x)),t=Math.min(Math.max(o.x,l.x),Math.max(s.x,h.x));o.y===s.y&&e<=t&&(g={x:Math.max(e,Math.min(t,o.x)),y:o.y})}else{let e={x:o.x===l.x?o.x:s.x,y:o.x===l.x?s.y:o.y};A(e,o,l)&&A(e,s,h)&&(g=e)}if(g){e=[...r.slice(0,a),g,...r.slice(n)];break}}if(!e)return r;r=l(e)}}(e,c,f):e;if(!(t.length<2)){for(let i of[!0,!1]){c.pairs-=4,c.pairs<0&&f("agentic local cross-hierarchy self-check limit");let r=i?e[0]:e.at(-1),a=i?e[1]:e.at(-2),n=i?t[0]:t.at(-1),o=i?t[1]:t.at(-2),l=ee[i?B.source:B.target],s=a.x-r.x,h=a.y-r.y,g=Math.abs(s)+Math.abs(h),d=Math.min(K,g),y={x:r.x+Math.sign(s)*d,y:r.y+Math.sign(h)*d};if(n.x!==r.x||n.y!==r.y||!A(y,n,o)||n.x<l.x-1e-7||n.x>l.x+l.width+1e-7||n.y<l.y-1e-7||n.y>l.y+l.height+1e-7||!(1e-7>Math.abs(n.x-l.x)&&o.y===n.y&&o.x<n.x||1e-7>Math.abs(n.x-l.x-l.width)&&o.y===n.y&&o.x>n.x||1e-7>Math.abs(n.y-l.y)&&o.x===n.x&&o.y<n.y||1e-7>Math.abs(n.y-l.y-l.height)&&o.x===n.x&&o.y>n.y))return}if(!(B.label&&!t.some((e,i)=>i>0&&A(J.labelPosition,t[i-1],e))))return I(t)?t:void 0}};eF&&(eA=W(eF));let j=e=>{if(!eh){let t=l([...e,...b.slice(1)]),i=W(t);return!!i&&(eA=i,!0)}return void 0!==T(eN,eu,eP,p,eI(B.target),K,c,s,f,t=>{let i=l([...e,...b.slice(1,-1),...t.toReversed()]),r=W(i);return!!r&&(eA=r,!0)},!0,eb)},H;if(void 0===Q||eA){if(void 0===Q)if(eA||B.label)!eA&&es?T(eN,eu,eE,m,eI(B.source),K,c,s,f,j,!0,eb):eA||j([m]);else{let t=F(ee[B.source],g[n[B.source]+1],!0,K),i=F(ee[B.target],g[n[B.target]+1],!1,K),r=[...eI(B.source),...eI(B.target)];for(let a=0;a<3&&!eA&&s.candidates>0;a++)for(let n=0;n<4&&!eA&&s.candidates>0;n++){let o=i[3*n+a],h=!0;for(let t of eu)if(s.pairs--<=0||(--c.pairs<0&&f("agentic local cross-hierarchy direct-pair limit"),e(o.stub,o.port,t))){h=!1;break}h&&T(eN,eu,t,o.stub,r,K,c,s,f,e=>{let t=l([...e,o.port]),i=W(t);return!!i&&(eA=i,!0)},!0,eb)}}}else c.arcs-=32,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),H=()=>{if(eA||B.label)!eA&&es?T(eN,eu,eE,m,eI(B.source),K,c,s,f,j,!0,eb):eA||j([m]);else{let t=F(ee[B.source],g[n[B.source]+1],!0,K),i=F(ee[B.target],g[n[B.target]+1],!1,K),r=[...eI(B.source),...eI(B.target)];for(let a=0;a<3&&!eA&&s.candidates>0;a++)for(let n=0;n<4&&!eA&&s.candidates>0;n++){let o=i[3*n+a],h=!0;for(let t of eu)if(s.pairs--<=0||(--c.pairs<0&&f("agentic local cross-hierarchy direct-pair limit"),e(o.stub,o.port,t))){h=!1;break}h&&T(eN,eu,t,o.stub,r,K,c,s,f,e=>{let t=l([...e,o.port]),i=W(t);return!!i&&(eA=i,!0)},!0,eb)}}};if(!eA)try{let e=(e,t)=>{let r=0,a=0,l=0,s=S.map((t,n)=>{--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let o=i.edges[n],s=o.source===e||o.target===e;s&&(r++,n<d&&a++);let h=s?t.style:"invisible";return n!==d&&"invisible"!==h&&(l+=Math.max(0,t.points.length-1)),{...t,style:h}}),h=[...new Set([(a+1)/(r+1),.5,.25,.75])];return F(ee[e],g[n[e]+1],t,K,h).filter(e=>(c.pairs-=4*l+2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"),void 0!==o(t?[e.port,e.stub]:[e.stub,e.port],d,s,i,G,$)))},r=(e,t)=>{let r=0,a=0;for(let t=0;t<i.edges.length;t++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let n=i.edges[t];(n.source===e||n.target===e)&&(r++,t<d&&a++)}c.arcs-=8,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),V(8);let o=ee[e],l=g[n[e]+1],s=(a+.5)/(r+1),h="LR"===l?"E":"RL"===l?"W":"BT"===l?"N":"S",y=t?h:"N"===h?"S":"S"===h?"N":"E"===h?"W":"E",m=[,,,,],u=e=>0===e?y:"N"===y?1===e?"E":2===e?"S":"W":"E"===y?1===e?"N":2===e?"S":"W":"S"===y?1===e?"N":2===e?"E":"W":1===e?"N":2===e?"E":"S";for(let e=0;e<4;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=u(e),i="N"===t||"S"===t?{x:o.x+s*o.width,y:"N"===t?o.y:o.y+o.height}:{x:"W"===t?o.x:o.x+o.width,y:o.y+s*o.height},r={x:i.x+("E"===t?2*K:"W"===t?-(2*K):0),y:i.y+("S"===t?2*K:"N"===t?-(2*K):0)};m[e]={port:i,stub:r,penalty:e*K*2+Math.abs(s-.5)*K}}return m},s=W;void 0!==Q&&(c.arcs-=4,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),s=e=>W(v(e,c,f)));let h=B.label&&!es?[]:e(B.source,!0),y=B.label&&!eh?[]:e(B.target,!1);ea??=(eo=a.width,el=a.height,c.arcs--,c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),new k(S,d,eo,el,c,V,f)),R=ea.acquire(d);let x=ea.rails,P=R.guard,I=e=>{let t=e=>e.x>=eN.x&&e.x<=eN.x+eN.width&&e.y>=eN.y&&e.y<=eN.y+eN.height;for(let i of e){c.pairs-=8,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let{port:e,stub:r}=i;if(!t(e)||!t(r))continue;let a=eb();if(a.containsPoint(e.x,e.y)||a.containsPoint(r.x,r.y)||a.entersSegment(e.x,e.y,r.x,r.y))continue;let n=e.x===r.x?2:+(e.y===r.y);if(!n)throw TypeError("Measured terminal lead must be orthogonal");if(P(e,r,n,n))return!0}return!1},A=e=>{try{return e(),void 0!==eA}catch(e){if(!(e instanceof X))throw e;return eY=e.reason,!1}};if(B.label){if(void 0!==Q&&!es&&eh&&ex){c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),ea.enterQuery(R);try{eA=function(e,i,r,a,n,o,l,s,h,g,c,d,f,y,m,u){g.arcs-=24+e.length+1,g.arcs<0&&y("agentic local cross-hierarchy visibility-arc limit");let x=(e=1)=>{g.pairs-=e,g.pairs<0&&y("agentic local cross-hierarchy obstacle-work limit")},p=e=>{g.arcs-=e,g.arcs<0&&y("agentic local cross-hierarchy visibility-arc limit")};if(x(12),e.length<2||!t(r,e.at(-2),e.at(-1)))return;let b=e.at(-2),v=e.at(-1),k=v.x-b.x,S=v.y-b.y;if(0===k==(0===S))return;let N=k>0?a.x+a.width:k<0?a.x:v.x,E=S>0?a.y+a.height:S<0?a.y:v.y;if(x(8),N<Math.min(b.x,v.x)||N>Math.max(b.x,v.x)||E<Math.min(b.y,v.y)||E>Math.max(b.y,v.y))return;let P=e[0],I=e[1],A=I.x-P.x,F=I.y-P.y;if(0===A==(0===F))return;let Y=A>0?i.x+i.width:A<0?i.x:P.x,T=F>0?i.y+i.height:F<0?i.y:P.y;if(x(4),Math.abs(Y-P.x)>1e-7||Math.abs(T-P.y)>1e-7)return;f(3),p(3);let X=e.slice(),C={x:N,y:E};X[0]={x:Y,y:T},X[X.length-1]=C;for(let e=1;e<X.length;e++){let t=X[e-1],i=X[e];if(x(4),!Number.isFinite(t.x+t.y+i.x+i.y)||t.x!==i.x&&t.y!==i.y||!w(t,i,s,d,g,y))return;for(let r of o)if(x(4),(r!==a||e!==X.length-1)&&(t.x===i.x?t.x>r.x&&t.x<r.x+r.width&&Math.max(t.y,i.y)>r.y&&Math.min(t.y,i.y)<r.y+r.height:t.y>r.y&&t.y<r.y+r.height&&Math.max(t.x,i.x)>r.x&&Math.min(t.x,i.x)<r.x+r.width))return}return M(n,o,{port:C,stub:{x:N+Math.sign(k)*c,y:E+Math.sign(S)*c},penalty:0},l,s,h,g,f,y,m,e=>{p(X.length+e.length);let t=Array(X.length+e.length-1);for(let e=0;e<X.length;e++)x(),t[e]=X[e];for(let i=1;i<e.length;i++)x(),t[X.length+i-1]=e[i];let i=0;for(let e=1;e<t.length;e++){let r=t[e-1],a=t[e],n=r.x===a.x?2:1;if(x(4),!m(r,a,i||n,n))return;i=n}return u(t)},0,d)}(b,ee[B.source],J.labelPosition,ex,eN,eu,y,x,eb(),c,K,Math.max(.5,Q),V,f,P,s)}finally{ea.leaveQuery(R)}}if(void 0!==Q&&(c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")),!eA&&H&&H(),!eA){let e=e=>n[e]<0?ee[e]:u[n[e]],t={roots:y,interiorChannels:!1,paths:[],complete:!1},i={roots:y,interiorChannels:!0,paths:[],complete:!1},a=[],o=(i,r=t)=>{if(!eh){let e=W(l([...i,...b.slice(1)]));return!!e&&(eA=e,!0)}let a=e=>{let t=W(l([...i,...b.slice(1,-1),...e.toReversed()]));return!!t&&(eA=t,!0)};for(let e of r.paths)if(a(e))return!0;if(r.complete)return!1;if(!r.graph&&!I(r.roots))return r.complete=!0,eY="cross-hierarchy route has no bounded clear corridor",!1;let n=A(()=>{r.graph??=q(N(eN,e(B.target),eu,r.roots,p,K,c,32768-z,eT,V,r.interiorChannels,eb,_(),x,D())),ea.enterQuery(R);try{r.graph.route(r.roots,p,e=>(r.late&&--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),r.paths.push(e),a(e)),P)}finally{ea.leaveQuery(R)}});return n||"cross-hierarchy route has no bounded clear corridor"!==eY||(r.complete=!0),(r.complete||n)&&r.graph?.retire(),n},s=(t,i,r)=>I(t)?A(()=>{let a=q(N(eN,e(B.source),eu,t,m,K,c,32768-z,eT,V,i,eb,_(),x,D()));ea.enterQuery(R);try{a.route(t,m,r,P)}finally{try{ea.leaveQuery(R)}finally{a.retire()}}}):(eY="cross-hierarchy route has no bounded clear corridor",!1),g=e=>(a.push(e),o(e));if(es?s(h,!1,g):g([m]),!eA&&"cross-hierarchy route has no bounded clear corridor"===eY){if(eh){for(let e of a)if(o(e,i))break}!eA&&es&&s(h,!0,e=>(--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),a.push(e),o(e)||o(e,i)))}if(!eA&&"cross-hierarchy route has no bounded clear corridor"===eY){let e;if(eh){let t=r(B.target,!1);--c.arcs<0&&f("agentic local cross-hierarchy visibility-arc limit"),e={roots:t,interiorChannels:!1,late:!0,paths:[],complete:!1}}if(e){for(let t of a)if(o(t,e))break}!eA&&es&&s(r(B.source,!0),!1,t=>o(t)||eh&&(o(t,i)||o(t,e)))}}}else{if(void 0!==Q){c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),ea.enterQuery(R);try{eA=function(e,t,i,r,a,n,o,l,s,h,g,c=.5){o.arcs-=40+a.length+3,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit");let d=(e=1)=>{o.pairs-=e,o.pairs<0&&s("agentic local cross-hierarchy obstacle-work limit")},f=e=>{o.arcs-=e,o.arcs<0&&s("agentic local cross-hierarchy visibility-arc limit")},y=new Float64Array(a.length+2),m=(e,t)=>(--o.swaps<0&&s("agentic local cross-hierarchy coordinate-sort limit"),e===t?0:e-t),u=(e,t,i,r,n,o)=>{d(y.length),y.fill(1/0);let l=2;for(let[s,h]of(y[0]=e,y[1]=t,a)){d(10);let a=o?s.y:s.x,g=o?s.x:s.y,f=o?h.y:h.x,m=o?h.x:h.y,u=i?a:g;(i?a!==f:g!==m)||Math.max(i?g:a,i?m:f)<r-c||Math.min(i?g:a,i?m:f)>n+c||u<=e||u>=t||(y[l++]=u)}y.sort(m);let s=-1/0,h;for(let e=1;e<l;e++){d(5);let t=y[e-1],i=y[e],r=i-t,a=t+r/2;r>2*c&&r>s&&a>t&&a<i&&(s=r,h=a)}return h};if(d(2),!Number.isFinite(c)||c<.5)return;d(8);let x=e.x+e.width,p=e.y+e.height;if(!(!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(x)||!Number.isFinite(p)||x<=e.x||p<=e.y)){for(let y=0;y<8;y++){let m=y>=4,b=y%4,v=b%2==0?-1:1,k=b<2?1:-1,S=m?e.y:e.x,N=m?p:x,E=m?e.x:e.y,P=m?x:p,I=v<0?S:N,A=k<0?E:P,F,Y;for(let e of i){d(6);let t=m?e.stub.y-e.port.y:e.stub.x-e.port.x;if((m?e.stub.x-e.port.x:e.stub.y-e.port.y)==0&&Math.sign(t)===v){F=e;break}}for(let e of r){d(6);let t=m?e.stub.y-e.port.y:e.stub.x-e.port.x,i=m?e.stub.x-e.port.x:e.stub.y-e.port.y;if(0===t&&Math.sign(i)===k){Y=e;break}}if(!F||!Y)continue;let T=m?F.port.y:F.port.x,X=m?F.port.x:F.port.y,C=m?F.stub.y:F.stub.x,L=m?Y.port.y:Y.port.x,O=m?Y.port.x:Y.port.y,R=m?Y.stub.x:Y.stub.y;if(d(9),k*(O-X)<=0){f(2);let i=M(e,t,F,[Y],a,n,o,l,s,h,g,void 0,c);if(i)return i;continue}if(T<S||T>N||X<E||X>P||L<S||L>N||O<E||O>P)continue;let W=v<0?N:S,j=Math.min(X,A),H=Math.max(X,A);for(let e of t){d(12);let t=m?e.y:e.x,i=m?e.x:e.y,r=m?e.height:e.width,a=m?e.width:e.height;if(!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(t+r)||!Number.isFinite(i+a)||r<0||a<0)return;i>=H||i+a<=j||t>N||t+r<S||(W=v<0?Math.min(W,Math.max(S,t)):Math.max(W,Math.min(N,t+r)))}if(d(2),v*(I-W)<=0)continue;let z=u(Math.min(I,W),Math.max(I,W),!0,j,H,m);if(d(3),void 0===z||v*(z-C)<0)continue;let U=R,V=Math.min(z,L),B=Math.max(z,L);for(let e of t){d(10);let t=m?e.y:e.x,i=m?e.x:e.y,r=m?e.height:e.width,a=m?e.width:e.height;t>=B||t+r<=V||i>P||i+a<E||(U=k<0?Math.min(U,Math.max(E,i)):Math.max(U,Math.min(P,i+a)))}if(d(2),k*(A-U)<=0)continue;let _=u(Math.min(A,U),Math.max(A,U),!1,V,B,m);if(d(3),void 0===_||k*(_-R)<0)continue;l(5),f(6);let q=m?[{x:X,y:T},{x:X,y:z},{x:_,y:z},{x:_,y:L},{x:O,y:L}]:[{x:T,y:X},{x:z,y:X},{x:z,y:_},{x:L,y:_},{x:L,y:O}],D=!0,Q=0;for(let e=0;e<q.length;e++){let t=q[e];if(n.containsPoint(t.x,t.y)){D=!1;break}if(0===e)continue;let i=q[e-1],r=i.x===t.x?2:1;if(d(4),i.x===t.x&&i.y===t.y||i.x!==t.x&&i.y!==t.y||n.entersSegment(i.x,i.y,t.x,t.y)||!h(i,t,Q||r,r)||(1===e||e===q.length-1)&&!w(i,t,a,c,o,s)){D=!1;break}Q=r}if(D){let e=g(q);if(e)return e}}f(12);for(let y=0;y<4;y++){d(12);let m=y<2,u=y%2==0?-1:1,x,p;for(let e of i){d(6);let t=e.stub.x-e.port.x,i=e.stub.y-e.port.y;if(m?0===t&&Math.sign(i)===u:0===i&&Math.sign(t)===u){x=e;break}}for(let e of r){d(6);let t=e.stub.x-e.port.x,i=e.stub.y-e.port.y;if(m?0===t&&Math.sign(i)===u:0===i&&Math.sign(t)===u){p=e;break}}if(!x||!p)continue;let b=m?x.port.y:x.port.x,w=m?p.port.y:p.port.x;if(d(4),b===w)continue;let v=u*(w-b)<0;f(2);let k=M(e,t,v?p:x,[v?x:p],a,n,o,l,s,h,g,void 0,c,v);if(k)return k}}}(eN,eu,h,y,x,eb(),c,V,f,P,s,Math.max(.5,Q))}finally{ea.leaveQuery(R)}}void 0!==Q&&(c.pairs-=2,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit")),!eA&&H&&H();let e=e=>{let t=q(E(eN,eu,[...h,...y],[m,p],K,c,32768-z,eT,V,e,eb,_(),x,D()));try{for(let e of y){if(eA)break;eb().entersSegment(e.stub.x,e.stub.y,e.port.x,e.port.y)||A(()=>{ea.enterQuery(R);try{t.route(h,e.stub,t=>{let i=W(l([...t,e.port]));return!!i&&(eA=i,!0)},P)}finally{ea.leaveQuery(R)}})}}finally{t.retire()}};eA||e(!1),eA||"cross-hierarchy route has no bounded clear corridor"!==eY||e(!0)}}catch(e){if(!(e instanceof X))throw e;eY=e.reason}if(!eA){if(0===P&&ew&&ev&&void 0!==Q&&void 0!==x[eM].paintStrokeWidth&&eS<ev.left&&eS<ev.right&&eS<ev.bottom&&"cross-hierarchy route has no bounded clear corridor"===eY)continue;f(eY)}ei.add(d)}let eX=eA;B.label&&!eX.some((e,t)=>t>0&&A(J.labelPosition,eX[t-1],e))&&f("cross-hierarchy route lost its reserved label corridor"),(H+=eX.length-J.points.length)>2048&&f("agentic local cross-hierarchy route-point limit"),a.edges[d]={...J,points:eX},et.add(d),W=!0}finally{try{if(B)for(let e of B)e.retire()}finally{R?.release()}}W&&ea&&ea.publish(d,a.edges[d].points,!1!==i.edges[d].visible&&!y?.connections.has(d));break}if(y?.connections.size){let s=new Set;for(let[h,g]of y.connections){let d=i.edges[h],x=a.edges[h],b=a.edges.map((e,t)=>({...e,style:!1===i.edges[t].visible||y.connections.has(t)&&!s.has(t)?"invisible":"solid"})),M=b.reduce((e,t,i)=>e+(i===h||"invisible"===t.style?0:Math.max(0,t.points.length-1)),0),w=new Set;for(let e=n[g.interior];e>=0;e=n[m+e])--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),w.add(e);let v=[...Z];for(let e=0;e<u.length;e++){--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit");let t=p[e].headerHeight??p[e].padding.top;w.has(e)?t>0&&v.push({...u[e],height:t}):v.push(u[e])}let k=function(i,r,a,n,o,s){let{work:h,fail:g}=s,c=n.connections.get(o),d=n.clearance,f=i.nodes.length,y=r.groups,m=y[c.container],u=0,x=e=>{u+e>s.remainingVertices&&g("agentic local cross-hierarchy visibility-expansion limit"),s.reserveVertices(e),u+=e},p=()=>{--h.pairs<0&&g("agentic local cross-hierarchy obstacle-work limit")},b=(e,t)=>(x(1),{x:e,y:t}),M=i.nodes.map((e,t)=>(p(),{...r.nodes[t],width:e.width,height:e.height})),w=[...M,...y][c.interior],v=new Set;for(let e=a[c.interior];e>=0;e=a[f+e])p(),v.add(e);let k=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}),S=M.map((e,t)=>(p(),t===c.interior?e:k(e,d)));for(let[e,t]of(y.forEach((e,t)=>{if(p(),v.has(t)){let i=n.groups[t].headerHeight??n.groups[t].padding.top;i>0&&S.push(k({...e,height:i},2))}else S.push(t+f===c.interior?e:k(e,d))}),i.edges.entries())){if(p(),!t.label)continue;let i=n.connections.get(e),a=i&&y[i.container],o=i&&a?a.x+i.labelInset+t.label.width/2:r.edges[e]?.labelPosition?.x,l=i&&a?a.y+i.rowOffset:r.edges[e]?.labelPosition?.y;t.label&&void 0!==o&&void 0!==l&&S.push(k({x:o-t.label.width/2,y:l-t.label.height/2,width:t.label.width,height:t.label.height},2))}let N=n.groups[c.container].headerHeight??n.groups[c.container].padding.top,I={x:m.x,y:m.y+N+2,width:m.width,height:m.height-N-2},A=m.y+c.rowOffset,F=b(m.x,A),Y=b(m.x+n.groups[c.container].padding.left-d,A),T=0,X=0;for(let[e,t]of i.edges.entries())p(),(t.source===c.interior||t.target===c.interior)&&(T++,e<o&&X++);let C=[...new Set([(X+1)/(T+1),.5,.25,.75])],L=[],O=c.interior>=f?n.groups[c.interior-f]:void 0,R=w.y+(O?(O.headerHeight??O.padding.top)+2:0);for(let e of["L","R","B","T"])for(let t of C){if(p(),"T"===e&&O&&(O.headerHeight??O.padding.top)>0)continue;let i="L"===e?w.x:"R"===e?w.x+w.width:w.x+t*w.width,r="T"===e?w.y:"B"===e?w.y+w.height:R+t*(w.y+w.height-R),a=b(i,r),n=b(i+("L"===e?-d:"R"===e?d:0),r+("T"===e?-d:"B"===e?d:0));--h.arcs<0&&g("agentic local cross-hierarchy visibility-arc limit"),L.push({port:a,stub:n,penalty:0})}let W=E(I,S,L,[Y],d,h,s.remainingVertices,e=>{if("cross-hierarchy route has no bounded clear corridor"===e)throw new P(e);return g(e)},x,!1,void 0,s.queryWorkspaces);for(let i of L){let r,a=(e,t)=>{p();let{port:r,stub:a}=i;if(e.x===r.x&&e.y===r.y&&t.x===a.x&&t.y===a.y)return!0;let n=r.y===a.y;if(n?e.y===t.y:e.x===t.x){if(n?e.y!==r.y:e.x!==r.x)return!0;let i=Math.max(Math.min(n?e.x:e.y,n?t.x:t.y),Math.min(n?r.x:r.y,n?a.x:a.y)),o=Math.min(Math.max(n?e.x:e.y,n?t.x:t.y),Math.max(n?r.x:r.y,n?a.x:a.y));return i>o||i===o&&i===(n?a.x:a.y)}let o=n?e.x:r.x,l=n?r.y:e.y;return!(o>=Math.min(e.x,t.x)&&o<=Math.max(e.x,t.x)&&l>=Math.min(e.y,t.y)&&l<=Math.max(e.y,t.y)&&o>=Math.min(r.x,a.x)&&o<=Math.max(r.x,a.x)&&l>=Math.min(r.y,a.y)&&l<=Math.max(r.y,a.y))||o===a.x&&l===a.y};try{W.route([i],Y,i=>{let a="source"===c.containerEnd?[F,...i.toReversed()]:[...i,F],o=0,h;for(let e of a)p(),(!h||h.x!==e.x||h.y!==e.y)&&o++,h=e;x(o);let g=l(a),f="source"===c.containerEnd?g[0]:g.at(-1),u="source"===c.containerEnd?g[1]:g.at(-2);if(f.x!==m.x||f.y!==A||u.y!==A||u.x-f.x<c.minimumLead)return!1;let M="source"===c.containerEnd?g.at(-1):g[0],k="source"===c.containerEnd?g.at(-2):g[1];if(!(M.x>=w.x&&M.x<=w.x+w.width&&M.y>=w.y&&M.y<=w.y+w.height&&(M.x===w.x&&k.y===M.y&&k.x<M.x||M.x===w.x+w.width&&k.y===M.y&&k.x>M.x||M.y===w.y&&k.x===M.x&&k.y<M.y||M.y===w.y+w.height&&k.x===M.x&&k.y>M.y))||Math.abs(k.x-M.x)+Math.abs(k.y-M.y)<d)return!1;let S=c.label?b(m.x+c.labelInset+c.label.width/2,A):void 0;if(S&&!g.some((e,i)=>i>0&&t(S,g[i-1],e)))return!1;for(let[t,i]of y.entries())if(v.has(t)){let r=n.groups[t].headerHeight??n.groups[t].padding.top;for(let t=1;t<g.length;t++)if(p(),r>0&&e(g[t-1],g[t],{...i,height:r}))return!1}let N={points:g,...S?{labelPosition:S}:{}};return!!s.accept(N)&&(r=N,!0)},a)}catch(e){if(!(e instanceof P))throw e}if(r)return r}return g("cross-hierarchy route has no bounded clear corridor")}(i,a,n,y,h,{work:c,remainingVertices:32768-z,reserveVertices:V,queryWorkspaces:_(),fail:f,accept(t){let a=t.points;if(a.length<2||a.some((e,t)=>!Number.isFinite(e.x+e.y)||t>0&&e.x!==a[t-1].x&&e.y!==a[t-1].y))throw TypeError("Ancestor boundary producer returned invalid points");if(Y(a,c,f))return!1;let n="source"===g.containerEnd,l=u[g.container],s=n?a[0]:a.at(-1),m=n?a[1]:a.at(-2),x=p[g.container].headerHeight??p[g.container].padding.top;if(Math.abs(s.x-l.x)>1e-7||s.y<l.y+x||s.y>l.y+l.height||m.y!==s.y||m.x-s.x<g.minimumLead)return!1;let w=n?a.at(-1):a[0],k=n?a.at(-2):a[1],S=ee[g.interior];if(w.x<S.x-1e-7||w.x>S.x+S.width+1e-7||w.y<S.y-1e-7||w.y>S.y+S.height+1e-7||!(1e-7>Math.abs(w.x-S.x)&&k.y===w.y&&k.x<w.x||1e-7>Math.abs(w.x-S.x-S.width)&&k.y===w.y&&k.x>w.x||1e-7>Math.abs(w.y-S.y)&&k.x===w.x&&k.y<w.y||1e-7>Math.abs(w.y-S.y-S.height)&&k.x===w.x&&k.y>w.y)||Math.abs(k.x-w.x)+Math.abs(k.y-w.y)<y.clearance||d.label&&(!t.labelPosition||!a.some((e,i)=>i>0&&A(t.labelPosition,a[i-1],e))))return!1;for(let t=1;t<a.length;t++)for(let i of v)if(--c.pairs<0&&f("agentic local cross-hierarchy obstacle-work limit"),e(a[t-1],a[t],i))return!1;return c.pairs-=r(i,"proposal")*Math.max(0,a.length-1)*M+a.length+M,c.pairs<0&&f("agentic local cross-hierarchy crossing-work limit"),void 0!==o(a,h,b,i,G,$)}});(H+=k.points.length-x.points.length)>2048&&f("agentic local cross-hierarchy route-point limit"),a.edges[h]={...x,...k},s.add(h),ei.add(h)}}J&&(en=W(i,a,Z,u,ee,p,c,V,f,ei,K,Q)),(ei.size||void 0!==Q&&0===i.maximumEdgeBendRadius)&&R(i,a,ei,c,f,en);let es=[...h.keys()];if(y?.connections.size){for(let e of y.connections.keys())h.has(e)||es.push(e);es.sort((e,t)=>e-t)}if(J){let e=!1;for(let t of ei)c.pairs-=es.length+1,c.pairs<0&&f("agentic marker full-proof work limit"),es.includes(t)||(--c.arcs<0&&f("agentic marker full-proof capacity limit"),es.push(t),e=!0);e&&es.sort((e,t)=>(--c.pairs<0&&f("agentic marker full-proof work limit"),e-t))}if(J){c.arcs-=i.edges.length+1,c.pairs-=i.edges.length,c.arcs<0&&f("agentic marker full-proof capacity limit"),c.pairs<0&&f("agentic marker full-proof work limit");let e=Array(i.edges.length);for(let t=0;t<i.edges.length;t++)e[t]=t;return{...a,expandedVertices:z,boundaryRoutes:e}}return{...a,expandedVertices:z,boundaryRoutes:es}}(i,G,m,p,U.map(e=>e.direction),g,0,n,z):(void 0!==i.maximumEdgeStrokeWidth&&0===i.maximumEdgeBendRadius&&(--g.arcs<0&&n("agentic local cross-hierarchy visibility-arc limit"),--g.pairs<0&&n("agentic local cross-hierarchy crossing-work limit"),R(i,G,new Set,g,n)),G)}(h,e=>a(e,c,d,f,m),d,0,f);let q="LR"===h.direction||"RL"===h.direction,D="BT"===h.direction||"RL"===h.direction,Q=new Set,$=!1;for(let e of u){if(void 0!==e.parent)throw TypeError("Measured parent requires a compound scope");if(void 0!==e.modelOrder){if(!Number.isSafeInteger(e.modelOrder)||e.modelOrder<0)throw TypeError("Invalid measured model order");$=!0}if(void 0!==e.partition&&(!Number.isSafeInteger(e.partition)||e.partition<0||e.partition>1e4))throw TypeError("Invalid measured partition");if(Q.has(e.id))throw TypeError("Measured graph node identities must be unique");if(Q.add(e.id),!V(e.width,!0)||!V(e.height,!0))throw TypeError("Measured node dimensions must be finite and positive")}let G=u.map(()=>[]),J=u.map(()=>[]),K=new Uint32Array(u.length),Z=!1,ee=!1;for(let e=0;e<x.length;e++){let t=x[e];if(!Number.isInteger(t.source)||!Number.isInteger(t.target)||t.source<0||t.source>=u.length||t.target<0||t.target>=u.length)throw TypeError("Measured edge endpoint is outside the node array");if(!Number.isSafeInteger(t.minSpan)||t.minSpan<1)throw TypeError("Measured edge minimum span must be a positive integer");if(void 0!==t.short&&!0!==t.short)throw TypeError("Invalid measured short-edge preference");if(void 0!==t.boundaryMarker&&![t.boundaryMarker.inset,t.boundaryMarker.height].every(e=>Number.isFinite(e)&&e>=0))throw TypeError("Invalid measured ancestor marker dimensions");if(ee||=!0===t.short,t.label&&(!V(t.label.width,!1)||!V(t.label.height,!1)))throw TypeError("Measured edge label dimensions must be finite and nonnegative");if(t.source===t.target){Z=!0;continue}J[t.source].push(e),G[t.target].push(e),K[t.target]=K[t.target]+1}let et=u.some(e=>(e.partition??0)!==(u[0]?.partition??0));if(et&&x.some(e=>(u[e.source].partition??0)>(u[e.target].partition??0))){let e=x.map(e=>(u[e.source].partition??0)>(u[e.target].partition??0)),t=a({...h,edges:x.map((t,i)=>e[i]?{...t,source:t.target,target:t.source}:t)},c,d,f,m);return{...t,edges:t.edges.map((t,i)=>e[i]?{...t,points:[...t.points].reverse()}:t)}}if(Z){let t=[...u],r=[...x],o=[...h.loopPorts??[]],l=new Int32Array(x.length).fill(-1),s=0;for(let e=0;e<x.length;e++){let i,a=x[e];if(a.source!==a.target)continue;(4096===t.length||16384===r.length)&&d("agentic local loop-expansion limit");do i=`\0agentic-loop:${s++}`;while(Q.has(i))Q.add(i);let n=t.length;t.push({id:i,width:q?1:40,height:q?40:1,...et?{partition:u[a.source].partition??0}:{}}),r[e]={...a,target:n,...a.label?{label:q?{width:a.label.width,height:2*a.label.height+8}:{width:2*a.label.width+8,height:a.label.height}}:{}},l[e]=r.length,o.push([e,r.length]),r.push({source:a.source,target:n,minSpan:a.minSpan})}let y=a({...h,nodes:t,edges:r,loopPorts:o},c,d,f,m);return function(t,r,a){if(a.loopPairs<=0||t.groups?.length||t.nodes.length>256||t.edges.length>128||r.edges.reduce((e,t)=>e+t.points.length,0)>2048)return r;let o=e=>(a.loopPairs-=e)>=0,l="LR"===t.direction||"RL"===t.direction,s="RL"===t.direction||"BT"===t.direction?-1:1,h=l?"x":"y",c=l?"y":"x",d=(e,t)=>l?{x:e,y:t}:{x:t,y:e},f=t.nodes.map((e,t)=>({...r.nodes[t],width:e.width,height:e.height})),y=t.edges.map((e,t)=>{let i=r.edges[t].labelPosition;return e.label&&i?{x:i.x-e.label.width/2,y:i.y-e.label.height/2,width:e.label.width,height:e.label.height}:void 0}),m=r.edges.map((e,i)=>({points:e.points,style:!1===t.edges[i].visible?"invisible":"solid"})),u=()=>m.map(e=>({points:e.points,visible:"invisible"!==e.style})),x=(e,t)=>Math.min(...t.slice(1).map((i,r)=>{let a=t[r],n=Math.max(Math.min(a.x,i.x),Math.min(Math.max(a.x,i.x),e.x)),o=Math.max(Math.min(a.y,i.y),Math.min(Math.max(a.y,i.y),e.y));return Math.abs(e.x-n)+Math.abs(e.y-o)})),p=!1;for(let[b,M]of t.edges.entries()){let w=r.edges[b],v=w.points;if(M.source!==M.target||!1===M.visible||v.length<=4)continue;let k=v[0],S=v.at(-1);if(Math.abs(k[h]-S[h])>1e-7||Math.abs(k[c]-S[c])<8-1e-7)continue;let N=[...f,...y.filter((e,t)=>!!e&&t!==b)],E=[...new Set([...v.map(e=>e[h]),...N.flatMap(e=>l?[e.x-8,e.x+e.width+8]:[e.y-8,e.y+e.height+8]),k[h]+24*s])].filter(e=>(e-k[h])*s>=24);E.sort((e,t)=>(e-t)*s);let P=new Set([b]),I=m.reduce((e,t)=>e+t.points.length,0);if(a.loopPairs-=I*I,a.loopPairs<0)return r;let A=g(u(),P);for(let g of E.slice(0,32)){let f=[{...k},d(g,k[c]),d(g,S[c]),{...S}];if(f.some(e=>e.x<t.padding||e.y<t.padding||e.x>r.width-t.padding||e.y>r.height-t.padding))continue;if(a.loopPairs-=f.length*N.length+f.length*I,a.loopPairs<0)return r;if(f.slice(1).some((t,i)=>N.some(r=>e(f[i],t,r))))continue;let u=w.labelPosition,E=y[b],P=t=>f.slice(1).some((i,r)=>e(f[r],i,t));if(u&&M.label&&(x(u,f)>x(u,v)+1e-7||E&&P(E))){let n=(l?M.label.width:M.label.height)/2,o=(l?M.label.height:M.label.width)/2,f=n+16,y=(g-k[h])*s-n-8;if(f>y)continue;let x=k[h]+s*Math.max(f,Math.min(y,(u[h]-k[h])*s)),p=[d(x,Math.min(k[c],S[c])-o-4),d(x,Math.max(k[c],S[c])+o+4)];for(let n of(p.sort((e,t)=>Math.abs(e.x-w.labelPosition.x)+Math.abs(e.y-w.labelPosition.y)-Math.abs(t.x-w.labelPosition.x)-Math.abs(t.y-w.labelPosition.y)),u=void 0,p)){let o={x:n.x-M.label.width/2,y:n.y-M.label.height/2,width:M.label.width,height:M.label.height};if(a.loopPairs-=N.length+I,a.loopPairs<0)return r;if(!(o.x<t.padding||o.y<t.padding||o.x+o.width>r.width-t.padding||o.y+o.height>r.height-t.padding)&&!(N.some(e=>i(o,e))||P(o)||m.some((t,i)=>i!==b&&"invisible"!==t.style&&t.points.slice(1).some((i,r)=>e(t.points[r],i,o))))){u=n,E=o;break}}if(!u)continue}let F=n(f,b,m,t,o,o);if(a.loopPairs<0)return r;if(!(void 0===F||F>A)){w.points=f,m[b].points=f,u&&(w.labelPosition={...u}),y[b]=E,p=!0;break}}}if(!p)return r;let b=1/0,M=1/0,w=-1/0,v=-1/0,k=(e,t,i=0,r=0)=>{b=Math.min(b,e),M=Math.min(M,t),w=Math.max(w,e+i),v=Math.max(v,t+r)};f.forEach(e=>k(e.x,e.y,e.width,e.height)),r.edges.forEach((e,i)=>{e.points.forEach(e=>k(e.x,e.y));let r=e.labelPosition,a=t.edges[i].label;r&&a&&k(r.x-a.width/2,r.y-a.height/2,a.width,a.height)});let S=t.padding-b,N=t.padding-M;return r.nodes=r.nodes.map(e=>({x:e.x+S,y:e.y+N})),r.edges=r.edges.map(e=>({...e,points:e.points.map(e=>({x:e.x+S,y:e.y+N})),...e.labelPosition?{labelPosition:{x:e.labelPosition.x+S,y:e.labelPosition.y+N}}:{}})),r.width=w-b+2*t.padding,r.height=v-M+2*t.padding,r}(h,{...y,topology:"layered",nodes:y.nodes.slice(0,u.length),edges:y.edges.slice(0,x.length).map((e,t)=>{let i=l[t];if(i<0)return e;let r=y.edges[i].points,a=e.labelPosition;if(a&&x[t].label){let e=q?a.x:a.y,i=q?a.y:a.x,n=-1;for(let t=1;t<r.length;t++){let a=r[t-1],o=r[t],l=q?a.x:a.y,s=q?o.x:o.y,h=q?a.y:a.x;if(h===(q?o.y:o.x)&&e>=Math.min(l,s)&&e<=Math.max(l,s)){n=i<h?-1:1;break}}let o=((q?x[t].label.height:x[t].label.width)/2+4)*n;a=q?{x:a.x,y:a.y+o}:{x:a.x+o,y:a.y}}return{...e,...a?{labelPosition:a}:{},points:e.points.concat([...r].reverse())}})},m)}let ei=!et&&!$&&!ee&&function(e,t,i,r){if(!e.shareCompleteFans||e.edges.some(e=>e.label||1!==e.minSpan))return;let a=[],n=[];for(let r=0;r<e.nodes.length;r++)if(!t[r].length&&i[r].length)a.push(r);else{if(i[r].length||!t[r].length)return;n.push(r)}if(!a.length||!n.length||1===a.length&&1===n.length||e.edges.length!==a.length*n.length)return;let o=new Map(a.map((e,t)=>[e,t])),l=new Map(n.map((e,t)=>[e,t])),s=new Set;for(let t of e.edges){if(!o.has(t.source)||!l.has(t.target))return;let i=t.source*e.nodes.length+t.target;if(s.has(i))return;s.add(i)}let h="LR"===e.direction||"RL"===e.direction,g="BT"===e.direction||"RL"===e.direction,c=t=>h?e.nodes[t].height:e.nodes[t].width,d=t=>h?e.nodes[t].width:e.nodes[t].height,f=t=>t.reduce((e,t)=>e+c(t),0)+(t.length-1)*e.nodeSpacing,y=f(a),m=f(n),u=Math.max(y,m),x=Math.max(...a.map(d)),p=Math.max(...n.map(d)),b=Math.max(e.layerSpacing,2*Math.max(12,e.edgeSpacing??6)+(e.edgeSpacing??6)),M=x+b+p;Number.isFinite(M+u+2*e.padding)||r("agentic local coordinate-range limit");let w=new Float64Array(e.nodes.length),v=new Float64Array(e.nodes.length);for(let[t,i,r,o]of[[a,y,0,x],[n,m,x+b,p]]){let a=(u-i)/2;for(let i of t)w[i]=a+c(i)/2,v[i]=r+(o-d(i))/2,a+=c(i)+e.nodeSpacing}let k=(t,i)=>h?{x:e.padding+(g?M-i:i),y:e.padding+t}:{x:e.padding+t,y:e.padding+(g?M-i:i)},S=e.nodes.map((e,t)=>k(w[t]-c(t)/2,v[t]+(g?d(t):0))),N=e.edges.map(t=>{if(e.placementOnly&&!e.cycleOriented&&!e.loopPorts?.length)return{points:[]};let i=[],r=u/2,a=x+b/3,n=x+2*b/3;for(let[e,o]of[[w[t.source],v[t.source]+d(t.source)],[w[t.source],a],[r,a],[r,n],[w[t.target],n],[w[t.target],v[t.target]]]){let t=k(e,o),r=i.at(-1),a=i.at(-2);r?.x===t.x&&r.y===t.y||(a&&r&&(a.x===r.x&&r.x===t.x&&(r.y-a.y)*(t.y-r.y)>=0||a.y===r.y&&r.y===t.y&&(r.x-a.x)*(t.x-r.x)>=0)&&i.pop(),i.push(t))}return{points:i}});return{topology:"layered",width:2*e.padding+(h?M:u),height:2*e.padding+(h?u:M),nodes:S,edges:N,expandedVertices:S.length,sharedEdges:e.edges.map((e,t)=>t)}}(h,G,J,d);if(ei)return ei;let er=!et&&!$&&!ee&&c(h);if(er)return{...er,expandedVertices:u.length};let ea=new Uint32Array(u.length),en=u.flatMap((e,t)=>0===K[t]?[t]:[]),eo=0;for(let e=0;e<en.length;e++){let t=en[e];for(let e of J[t]){let i=x[e],r=ea[t]+j(i,h.compactPrivateRanks);r>=4096&&d("agentic local rank-expansion limit"),ea[i.target]=Math.max(ea[i.target],r),eo=Math.max(eo,r),K[i.target]=K[i.target]-1,0===K[i.target]&&en.push(i.target)}}if(en.length!==u.length){if(et){let e=h.authoredCycleOrder?Uint32Array.from(u,(e,t)=>t):z(G,J,x),t=x.map(t=>(u[t.source].partition??0)===(u[t.target].partition??0)&&e[t.source]>e[t.target]),i=a({...h,cycleOriented:!0,edges:x.map((e,i)=>t[i]?{...e,source:e.target,target:e.source}:e)},c,d,f,m);return{...i,edges:i.edges.map((e,i)=>t[i]?{...e,points:[...e.points].reverse()}:e)}}return function(e,t,i,r,a,n,o){let{nodes:l,edges:s}=e,h=z(t,i,s),c=H(i,s),d=e=>s.reduce((t,i)=>t+ +(e[i.source]>e[i.target]),0),f=(t,i,a,n=!1,o=!1)=>{let h=s.map(e=>t[e.source]>t[e.target]),g=l.map((e,t)=>n?l.length-1-t:t),c=new Uint32Array(l.length);g.forEach((e,t)=>{c[e]=t});let d=s.map((e,t)=>o?s.length-1-t:t),f=new Uint32Array(s.length);d.forEach((e,t)=>{f[e]=t});let y=r({...e,shareCompleteFans:!1,cycleOriented:!0,nodes:g.map(e=>l[e]),edges:d.map(e=>{let t=s[e],i=h[e]?t.target:t.source,r=h[e]?t.source:t.target;return{...t,source:c[i],target:c[r]}}),loopPorts:e.loopPorts?.map(([e,t])=>[f[e],f[t]])},i,a);return{...y,nodes:l.map((e,t)=>y.nodes[c[t]]),edges:s.map((e,t)=>{let i=y.edges[f[t]];return h[t]?{...i,points:[...i.points].reverse()}:i})}};if(e.authoredCycleOrder)return f(Uint32Array.from(l,(e,t)=>t),a,n,!1,!0);let y=d(c)<=d(h)?c:h,m=f(y,a,n);if(l.length>48||s.length>128||s.reduce((e,t)=>e+t.minSpan,0)>128||(m.expandedVertices??0)>1024||o.attempts<=0)return m;let u=e=>{let t=e.edges.reduce((e,t,i)=>e+(!1===s[i].visible?0:t.points.length),0);if(!(t>2048||t*t>o.scorePairs))return o.scorePairs-=t*t,g(e.edges.map((e,t)=>({...e,visible:s[t].visible})))},x=u(m);if(void 0===x||0===x)return m;let p=e=>e.edges.reduce((e,t,i)=>e+(!1===s[i].visible?0:Math.max(0,t.points.length-2)),0),b=p(m),M=m.width*m.height,w=(e,t,i)=>s.map(t=>+(e[t.source]>e[t.target])).join("")+":"+t+":"+i,v=e.compactPrivateRanks&&l.length>16?2:12,k=new Set([w(y,!1,!1)]),S=(l.length<=12?l.map((e,t)=>t):l.length<=20?[0,Math.floor(l.length/4),Math.floor(l.length/2),Math.floor(3*l.length/4),l.length-1]:[]).flatMap(e=>{let r=t=>(t-e+l.length)%l.length,a=s.map(e=>({...e,source:r(e.source),target:r(e.target)})),n=i.slice(e).concat(i.slice(0,e)),o=t.slice(e).concat(t.slice(0,e)),h=H(n,a),g=z(o,n,a);return[Uint32Array.from(l,(e,t)=>h[r(t)]),Uint32Array.from(l,(e,t)=>g[r(t)])]}),N=e.compactPrivateRanks&&l.length>16,E=N&&3>=d(y)?function(e,t,i=2){let r=e.nodes.length,a=e.edges;if(!r||r>20||a.length>48||(t.blockPairs??2e6)<=0)return[];let n=new Uint16Array(r),o=new Uint16Array(r),l=new Uint16Array(r),s=new Float64Array(r),h=new Int32Array(r);for(let e of a)n[e.target]=n[e.target]+1;let g=!1,c=e=>{let i=t.blockPairs??2e6;return i<e?(g=!0,!1):(t.blockPairs=i-e,!0)},d=(t,i,g=-1)=>{if(!c(r+4))return;for(let e of(o.set(n),s.fill(0),[t,i,g]))if(e>=0){let t=a[e];o[t.target]=o[t.target]-1,o[t.source]=o[t.source]+1}let d=0;for(let e=0;e<r;e++)o[e]||(l[d++]=e);for(let r=0;r<d;r++){if(!c(a.length))return;let n=l[r];h[n]=r;for(let r=0;r<a.length;r++){let h=a[r],c=r===t||r===i||r===g,f=c?h.target:h.source,y=c?h.source:h.target;f===n&&(s[y]=Math.max(s[y],s[n]+j(h,e.compactPrivateRanks)),o[y]=o[y]-1,o[y]||(l[d++]=y))}}if(d!==r||!c(a.length))return;let f=0;for(let e of a)f+=Math.abs(s[e.target]-s[e.source]);return{order:h.slice(),span:f}},f=[];for(let e=0;e<a.length&&!g;e++){let t=d(e,-1);t&&f.push(t)}if(f.length||g)return f;for(let e=0;e<a.length&&!g;e++)for(let t=e+1;t<a.length&&!g;t++){let i=d(e,t);i&&f.push(i)}if(f.length||g||i<3)return f;let y=new Uint8Array(a.length),m=new Uint8Array(r),u=new Int32Array(r),x=[],p=new Set,b=()=>{if(g)return;let e=x.slice().sort((e,t)=>e-t).join(",");if(p.has(e))return;p.add(e);let t=(()=>{m.fill(0),u.fill(-1);let e=t=>{m[t]=1;for(let i=0;i<a.length;i++){if(!c(1))return;let r=a[i];if(!(y[i]||r.source!==t)){if(1===m[r.target]){let e=[i];for(let i=t;i!==r.target;){let t=u[i];e.push(t),i=a[t].source}return e}if(0===m[r.target]){u[r.target]=i;let t=e(r.target);if(t||g)return t}}}m[t]=2};for(let t=0;t<r;t++)if(!m[t]){let i=e(t);if(i||g)return i}})();if(!g){if(!t){let e=d(x[0]??-1,x[1]??-1,x[2]??-1);e&&f.push(e);return}if(3!==x.length){for(let e of t)if(y[e]=1,x.push(e),b(),x.pop(),y[e]=0,g)return}}};return b(),f}(e,o,3):[];E.sort((e,t)=>t.span-e.span);let P=[...E.length>1?[E[0].order,E.at(-1).order,...E.slice(1,-1).map(e=>e.order)]:E.map(e=>e.order),h,c,...S,Uint32Array.from(l,(e,t)=>t)],I=E.length?[[!1,!1],[!0,!0],[!0,!1],[!1,!0]]:[[!0,!0],[!0,!1],[!1,!0],[!1,!1]];for(let e=0;e<P.length*I.length;e++){let t=P[N?e%P.length:Math.floor(e/I.length)],[i,r]=I[N?Math.floor(e/P.length):e%I.length],a=w(t,i,r);if(!k.has(a)){if(k.add(a),v--<=0||o.attempts--<=0||o.routing.pairs<0||o.routing.arcs<0||o.routing.swaps<0)return m;try{let e=f(t,e=>{throw new U(e)},o.routing,i,r),a=u(e);if(void 0===a)return m;let n=p(e),l=e.width*e.height;if((a<x||a===x&&(n<b||n===b&&l<M))&&(m=e,x=a,b=n,M=l),0===x)break}catch(e){if(!(e instanceof U))throw e}}}return m}(h,G,J,(e,t,i)=>a(e,c,t,i,m),d,f,m)}let el=ee?new Uint32Array(u.length):void 0,es=ee?new Uint32Array(u.length):void 0;if(ee)for(let e of x){let t=e.short?100:1;el[e.target]=el[e.target]+t,es[e.source]=es[e.source]+t}for(let e=0;!et&&e<4;e++){let e=!1;for(let t of[!0,!1])for(let i=0;i<en.length;i++){let r=en[t?en.length-1-i:i],a=0,n=eo;for(let e of G[r]){let t=x[e];a=Math.max(a,ea[t.source]+j(t,h.compactPrivateRanks))}for(let e of J[r]){let t=x[e];n=Math.min(n,ea[t.target]-j(t,h.compactPrivateRanks))}let o=ee?es[r]>=el[r]:J[r].length>=G[r].length,l=J[r].length&&o?n:a;l!==ea[r]&&(ea[r]=l,e=!0)}if(!e)break}if(et){let e=new Map;for(let t of en){let i=u[t].partition??0,r=e.get(i)??[];r.push(t),e.set(i,r)}let t=0;for(let i of[...e.keys()].sort((e,t)=>e-t)){let r=t;for(let a of e.get(i)){let e=t;for(let t of G[a]){let i=x[t];e=Math.max(e,ea[i.source]+j(i,h.compactPrivateRanks))}e>=4096&&d("agentic local rank-expansion limit"),ea[a]=e,r=Math.max(r,e)}t=r+1}}if(et&&ee){let e=new Map;for(let[t,i]of u.entries()){let r=i.partition??0,a=e.get(r);a?(a.lower=Math.min(a.lower,ea[t]),a.upper=Math.max(a.upper,ea[t])):e.set(r,{lower:ea[t],upper:ea[t]})}for(let t=0;t<4;t++){let t=!1;for(let i of[!0,!1])for(let r=0;r<en.length;r++){let a=en[i?en.length-1-r:r],n=e.get(u[a].partition??0),o=n.lower,l=n.upper;for(let e of G[a]){let t=x[e];o=Math.max(o,ea[t.source]+j(t,h.compactPrivateRanks))}for(let e of J[a]){let t=x[e];l=Math.min(l,ea[t.target]-j(t,h.compactPrivateRanks))}let s=J[a].length&&es[a]>=el[a]?l:o;s!==ea[a]&&(ea[a]=s,t=!0)}if(!t)break}}let eh=!et&&function(e,t,i=!1){let r=e.nodes.length,a=e.edges;if(0===r)return new Float64Array(0);if(t.rankPairs<=0||r>64||a.length>128||a.reduce((e,t)=>e+t.minSpan,0)>128)return;let n=i?Int32Array.from(a,e=>e.short?100:1):new Int32Array(a.length).fill(1),o=new Float64Array(r),l=new Int32Array(r),s=new Int32Array(r);for(let h=0;h<128;h++){o.fill(0),l.fill(-1),s.fill(0);let h=-1;for(let g=0;g<r;g++){h=-1;for(let i=0;i<a.length;i++){let r=a[i];if(t.rankPairs-=2,t.rankPairs<0)return;let g=j(r,e.compactPrivateRanks);o[r.target]<o[r.source]+g&&(o[r.target]=o[r.source]+g,l[r.target]=r.source,s[r.target]=i+1,h=r.target),n[i]>0&&o[r.source]<o[r.target]-g&&(o[r.source]=o[r.target]-g,l[r.source]=r.target,s[r.source]=-i-1,h=r.source)}if(h<0){let t=i?a.reduce((e,t)=>e+(t.short?100:1)*(o[t.target]-o[t.source]),0):a.reduce((e,t)=>e+o[t.target]-o[t.source],0),r=a.reduce((t,i,r)=>t+n[r]*j(i,e.compactPrivateRanks),0);if(t!==r)throw Error(`dual rank mismatch ${t} ${r}`);return o}}let g=h;for(let e=0;e<r;e++)g=l[g];let c=g,d=[],f=1/0,y=0;do{let t=s[g],i=Math.abs(t)-1;if(i<0)throw Error("missing residual predecessor");d.push(t),y+=Math.sign(t)*j(a[i],e.compactPrivateRanks),t<0&&(f=Math.min(f,n[i])),g=l[g]}while(g!==c&&d.length<=r)if(g!==c||y<=0||!Number.isFinite(f)||f<=0)throw Error(`invalid positive residual cycle ${y} ${f}`);for(let e of d)n[Math.abs(e)-1]=n[Math.abs(e)-1]+Math.sign(e)*f}}(h,m,ee);eh&&ea.set(eh),eo=ea.reduce((e,t)=>Math.max(e,t),0);let eg=u.length;for(let e of x)(eg+=ea[e.target]-ea[e.source]-1)>32768&&d("agentic local expanded-graph limit");if(0===u.length)return Number.isFinite(2*p)||d("agentic local coordinate-range limit"),{topology:"layered",width:2*p,height:2*p,nodes:[],edges:[],expandedVertices:0};let ec=u.map((e,t)=>({rank:ea[t],crossSize:q?e.height:e.width,mainSize:q?e.width:e.height,incoming:[],outgoing:[]})),ed=[],ef=[];for(let e=0;e<x.length;e++){let t=x[e],i=[t.source],r=t.label?Math.floor((ea[t.source]+ea[t.target])/2):-1;for(let a=ea[t.source]+1;a<ea[t.target];a++){let n=a===r,o=ec.length;ec.push({rank:a,crossSize:n?(q?t.label.height:t.label.width)+16:4,mainSize:n?q?t.label.width:t.label.height:0,incoming:[],outgoing:[]}),n&&(ef[e]=o),i.push(o)}i.push(t.target);for(let e=1;e<i.length;e++){let t=i[e-1],r=i[e];ec[t].outgoing.push(r),ec[r].incoming.push(t)}ed.push(i)}let ey=Array.from({length:eo+1},()=>[]),em=new Float64Array(ey.length),eu=new Float64Array(ey.length);for(let e=0;e<ec.length;e++)ey[ec[e].rank].push(e);let ex=$?e=>{let t=e.filter(e=>u[e]?.modelOrder!==void 0);t.sort((e,t)=>u[e].modelOrder-u[t].modelOrder);let i=0;for(let r=0;r<e.length;r++)u[e[r]]?.modelOrder!==void 0&&(e[r]=t[i++])}:void 0;if(ex)for(let e of ey)ex(e);let ep=0;for(let e=0;e<ey.length;e++){let t=ey[e],i=Math.max(0,t.length-1)*B;for(let r of t){let t=ec[r];i+=t.crossSize,eu[e]=Math.max(eu[e],t.mainSize)}em[e]=i,ep=Math.max(ep,i)}let eb=new Float64Array(ec.length),eM=e=>{let t=(ep-em[e])/2,i=ey[e];for(let e=0;e<i.length;e++){let r=i[e],a=ec[r].crossSize;eb[r]=t+a/2,t+=a+B}};for(let e=0;e<ey.length;e++)eM(e);let ew=new Float64Array(ec.length),ev=(e,t)=>{let i=ey[e],r=!0;for(let e=0;e<i.length;e++){let a=i[e],n=t?ec[a].incoming:ec[a].outgoing,o=0;for(let e=0;e<n.length;e++)o+=eb[n[e]];let l=n.length?o/n.length:eb[a];ew[a]=l,r&&=Number.isFinite(l)}if(i.length<=16&&r)for(let e=1;e<i.length;e++){let t=i[e],r=ew[t],a=e;for(;a>0;){let e=i[a-1];if(0>=(ew[e]-r||e-t))break;i[a--]=e}i[a]=t}else i.sort((e,t)=>ew[e]-ew[t]||e-t);ex?.(i),eM(e)},ek=new Uint32Array(ec.length),eS=ey.slice(1).map(e=>new Uint32Array(e.length+1)),eN=()=>{for(let e=0;e<ey.length;e++){let t=ey[e];for(let e=0;e<t.length;e++)ek[t[e]]=e}},eE=()=>{eN();let e=0;for(let t=0;t+1<ey.length;t++){let i=eS[t];i.fill(0);let r=0,a=ey[t];for(let t=0;t<a.length;t++){let n=ec[a[t]].outgoing;for(let t=0;t<n.length;t++){let a=n[t],o=0;for(let e=ek[a]+1;e>0;e-=e&-e)o+=i[e];e+=r-o}for(let e=0;e<n.length;e++)for(let t=ek[n[e]]+1;t<i.length;t+=t&-t)i[t]=i[t]+1;r+=n.length}}return e},eP=eE(),eI=ey.map(e=>[...e]),eA=()=>{let e=eE();e<eP&&(eP=e,eI=ey.map(e=>[...e]))};for(let e=0;e<4;e++){for(let e=1;e<ey.length;e++)ev(e,!0);eA();for(let e=ey.length-2;e>=0;e--)ev(e,!1);eA()}eI.forEach((e,t)=>{ey[t]=e,e.forEach((e,t)=>{ek[e]=t})});let eF=()=>{eN();for(let e=0;e<4;e++){let e=!1;for(let t=0;t<ey.length;t++){let i=ey[t];for(let t=0;t+1<i.length;t++){if($&&u[i[t]]?.modelOrder!==void 0&&u[i[t+1]]?.modelOrder!==void 0)continue;let r=ec[i[t]],a=ec[i[t+1]],n=r.incoming.length*a.incoming.length+r.outgoing.length*a.outgoing.length;if(n>f.swaps)continue;f.swaps-=n;let o=0;for(let e=0;e<r.incoming.length;e++)for(let t=0;t<a.incoming.length;t++)o+=Math.sign(ek[r.incoming[e]]-ek[a.incoming[t]]);for(let e=0;e<r.outgoing.length;e++)for(let t=0;t<a.outgoing.length;t++)o+=Math.sign(ek[r.outgoing[e]]-ek[a.outgoing[t]]);if(o>0){let r=i[t],a=i[t+1];i[t]=a,i[t+1]=r,ek[r]=t+1,ek[a]=t,e=!0}}}if(!e)break}};if(eF(),h.compactPrivateRanks&&u.length<=20&&x.length<=64&&ec.length<=256){let e=eE(),t=128;for(let i of ed.map(e=>e.slice(1,-1)).filter(e=>e.length>1).sort((e,t)=>t.length-e.length)){if(0===e)break;let r=new Map(i.map(e=>[ec[e].rank,[...ey[ec[e].rank]]])),a=e,n,o=!1;for(let e of[0,1,.25,.5,.75]){let l=ey.length+ec.length+16*(ec.length-u.length+x.length);if(t--<=0||(m.blockPairs??2e6)<l){o=!0;break}for(let t of(m.blockPairs=(m.blockPairs??2e6)-l,i)){let i=ec[t].rank,a=ey[i],n=r.get(i);for(let e=0;e<a.length;e++)a[e]=n[e];let o=a.indexOf(t),l=Math.floor((a.length-1)*e);if(o<l)for(let e=o;e<l;e++)a[e]=a[e+1];else for(let e=o;e>l;e--)a[e]=a[e-1];a[l]=t}let s=eE();s<a&&(a=s,n=new Map([...r].map(([e])=>[e,[...ey[e]]])))}for(let[e,t]of n??r)ey[e]=t;if(e=a,o)break}}h.compactPrivateRanks&&u.length>12&&u.length<=20&&x.length<=64&&ec.length<=256&&function(e,t,i,r){let a=new Int32Array(t.length);for(let n of i){if((r.blockPairs??2e6)<=0)return;let i=n.slice(1,-1);if(i.length<2||i.some((e,i)=>1!==t[e].incoming.length||1!==t[e].outgoing.length||t[e].incoming[0]!==n[i]||t[e].outgoing[0]!==n[i+2]||t[e].rank!==t[n[i]].rank+1))continue;for(let t of e)for(let e=0;e<t.length;e++)a[t[e]]=e;let o=i.map(i=>e[t[i].rank].filter(e=>e!==i)),l=i.map(e=>a[e]),s=[];for(let r=0;r<=i.length;r++){let o=n[r],l=n[r+1],h=[];for(let n of e[t[o].rank])for(let e of t[n].outgoing){if(n===o&&e===l)continue;let t=a[n],s=a[e];h.push(t-(r>0&&t>a[o]),s-(r<i.length&&s>a[l]))}s.push(Int32Array.from(h))}let h=!1,g=(e,t,a)=>{let n=s[e],o=1+n.length/2;if((r.blockPairs??2e6)<o)return h=!0,1/0;r.blockPairs=(r.blockPairs??2e6)-o;let l=0;for(let r=0;r<n.length;r+=2){let o=n[r],s=n[r+1],h=o+ +(e>0&&o>=t),g=s+ +(e<i.length&&s>=a);(t-h)*(a-g)<0&&l++}return l},c=0;for(let e=0;e<=i.length;e++)c+=g(e,0===e?a[n[0]]:l[e-1],e===i.length?a[n.at(-1)]:l[e]);if(h)return;if(0===c)continue;let d=Float64Array.from({length:o[0].length+1},(e,t)=>g(0,a[n[0]],t)),f=Float64Array.from(d,(e,t)=>Math.abs(t-l[0])),y=[];for(let e=1;e<i.length&&!h;e++){let t=new Float64Array(o[e].length+1).fill(1/0),i=new Int32Array(t.length),r=new Float64Array(t.length).fill(1/0);for(let a=0;a<t.length&&!h;a++)for(let n=0;n<d.length;n++){if(d[n]>=c)continue;let o=d[n]+g(e,n,a),s=f[n]+Math.abs(a-l[e]);if((o<t[a]||o===t[a]&&s<r[a])&&(t[a]=o,i[a]=n,r[a]=s),h)break}d=t,f=r,y.push(i)}if(h)return;let m=1/0,u=1/0,x=0;for(let e=0;e<d.length;e++){let t=d[e]+g(i.length,e,a[n.at(-1)]);(t<m||t===m&&f[e]<u)&&(m=t,u=f[e],x=e)}if(h)return;if(m>=c)continue;let p=new Int32Array(i.length);p[i.length-1]=x;for(let e=i.length-2;e>=0;e--)p[e]=y[e][p[e+1]];for(let r=0;r<i.length;r++){let a=o[r];a.splice(p[r],0,i[r]),e[t[i[r]].rank]=a}}}(ey,ec,ed,m),h.compactPrivateRanks&&!h.cycleOriented&&eF();for(let e=0;e<ey.length;e++)eM(e);let eY=new Int32Array(ec.length).fill(-1),eT=new Int32Array(ec.length).fill(-1);for(let e of ey){let t=-1;for(let i of e)eY[i]=t,i<u.length&&(t=i);t=-1;for(let i=e.length-1;i>=0;i--){let r=e[i];eT[r]=t,r<u.length&&(t=r)}}let eX=new Float64Array(0),eC=Math.min(4,B);for(let e=0;e<4;e++)for(let e of[!0,!1])for(let t=0;t<ey.length;t++){let i=ey[e?t:ey.length-1-t];for(let t=0;t<i.length;t++){let r,a=e?t:i.length-1-t,n=i[a],o=ec[n],l=o.incoming.length+o.outgoing.length;if(!l)continue;if(l<=2){let t=o.incoming[0]??o.outgoing[0],i=1===l?t:2===o.incoming.length?o.incoming[1]:o.outgoing[+(1!==o.incoming.length)],a=eb[t],n=eb[i];r=e?Math.min(a,n):Math.max(a,n)}else{eX.length<l&&(eX=new Float64Array(l));let t=eX.subarray(0,l),i=0,a=!0;for(let e=0;e<o.incoming.length;e++){let r=eb[o.incoming[e]];t[i++]=r,a&&=Number.isFinite(r)&&!Object.is(r,-0)}for(let e=0;e<o.outgoing.length;e++){let r=eb[o.outgoing[e]];t[i++]=r,a&&=Number.isFinite(r)&&!Object.is(r,-0)}r=(a?t.sort():Array.from(t).sort((e,t)=>e-t))[Math.floor((l-Number(e))/2)]}let s=i[a-1],h=i[a+1],g=void 0===s?o.crossSize/2:eb[s]+(ec[s].crossSize+o.crossSize)/2+eC,c=void 0===h?ep-o.crossSize/2:eb[h]-(ec[h].crossSize+o.crossSize)/2-eC;if(n<u.length){let e=eY[n],t=eT[n];e>=0&&(g=Math.max(g,eb[e]+(ec[e].crossSize+o.crossSize)/2+B)),t>=0&&(c=Math.min(c,eb[t]-(ec[t].crossSize+o.crossSize)/2-B))}g<=c&&(eb[n]=Math.max(g,Math.min(c,r)))}}let eL=new Uint32Array(ec.length);for(let e of ey)e.forEach((e,t)=>{eL[e]=t});let eO=Math.min(4,B);for(let e of ed){if(e.length<4)continue;let t=1;for(;t<e.length-1;){let i=-1/0,r=1/0,a=t;for(;a<e.length-1;){let t=e[a],n=ec[t],o=ey[n.rank],l=eL[t],s=o[l-1],h=o[l+1],g=void 0===s?n.crossSize/2:eb[s]+(ec[s].crossSize+n.crossSize)/2+eO,c=void 0===h?ep-n.crossSize/2:eb[h]-(ec[h].crossSize+n.crossSize)/2-eO,d=Math.max(i,g),f=Math.min(r,c);if(d>f)break;i=d,r=f,a++}if(a>t+1){let n=Math.max(i,Math.min(r,(eb[e[t-1]]+eb[e[a]])/2));for(let i=t;i<a;i++)eb[e[i]]=n}t=Math.max(t+1,a)}}let eR=new Float64Array(x.length),eW=new Float64Array(x.length),ej=new Map;for(let e of h.loopPorts??[]){let t=x[e[0]],i=x[e[1]];if(!t||!i||t.source!==i.source)throw TypeError("Invalid measured loop port pair");let r=ej.get(t.source)??[];r.push(e),ej.set(t.source,r)}for(let e=0;e<u.length;e++){let t=ec[e].crossSize,i=(i,r)=>{let a=[...i].sort((e,t)=>{let i=ed[e],a=ed[t],n=r?i[1]:i[i.length-2],o=r?a[1]:a[a.length-2];return eb[n]-eb[o]||e-t}),n=r?ej.get(e):void 0;if(n?.length){let i=new Map(a.map((e,t)=>[e,t])),r=n.map(([e,t])=>[Math.min(i.get(e),i.get(t)),Math.max(i.get(e),i.get(t))]);if(r.some(([e,i])=>t*(i-e)/(a.length+1)<8)){let i=new Float64Array(a.length),n=new Map;for(let[e,t]of r){let i=n.get(t)??[];i.push(e),n.set(t,i)}for(let e=0;e<a.length;e++)for(let t of(i[e]=e?i[e-1]+2:0,n.get(e)??[]))i[e]=Math.max(i[e],i[t]+8);let o=Math.min(8,t/6),l=t-2*o-(i.at(-1)??0);l<0&&d("agentic local loop-attachment capacity"),a.forEach((r,n)=>{eR[r]=eb[e]-t/2+o+i[n]+l*(n+1)/(a.length+1)});return}}void 0!==u[e].minimumPortSpacing&&(f.pairs-=3,f.pairs<0&&d("agentic node port-spacing work limit"));let o=Math.min(8,t/6),l=Math.max(8,u[e].minimumPortSpacing??8);if(!n?.length&&t-2*o>=(a.length-1)*l){let i=eb[e]-t/2+o,n=eb[e]+t/2-o,s=a.map((e,t)=>{let o=ed[e],s=r?o[1]:o[o.length-2];return Math.max(i+t*l,Math.min(n-(a.length-1-t)*l,eb[s]))});for(let e=1;e<s.length;e++)s[e]=Math.max(s[e],s[e-1]+l);a.forEach((e,t)=>{(r?eR:eW)[e]=s[t]});return}for(let i=0;i<a.length;i++){let n=eb[e]-t/2+t*(i+1)/(a.length+1);(r?eR:eW)[a[i]]=n}};i(J[e],!0),i(G[e],!1)}let eH=Math.max(4,_/2),ez=Array.from({length:eo},()=>[]),eU=ed.map((e,t)=>e.slice(1).map((i,r)=>{let a=e[r],n={sourceCross:0===r?eR[t]:eb[a],targetCross:r===e.length-2?eW[t]:eb[i],offset:eH/2,track:0};return ez[ec[a].rank].push(n),n})),eV=ez.map(e=>(void 0!==h.minimumTerminalLead&&(f.pairs-=3,f.pairs<0&&d("agentic terminal-lead work limit")),function(e,t,i,r,a,n,o){let l=e.filter(e=>Math.abs(e.sourceCross-e.targetCross)>.01);if(!l.length)return t;a.pairs-=l.length*e.length,a.pairs<0&&n("agentic local channel-pair limit");let s=e=>Math.min(e.sourceCross,e.targetCross),h=e=>Math.max(e.sourceCross,e.targetCross),g=(e,t)=>Math.min(h(e),h(t))>=Math.max(s(e),s(t))-.5,c=(e,t)=>e>=s(t)-.01&&e<=h(t)+.01,d=l.map(()=>[]),f=l.map(()=>[]),y=[],m=(e,t)=>{--a.arcs<0&&n("agentic local channel-constraint limit");let i=y.length;y.push({source:e,target:t,minSpan:1}),f[e].push(i),d[t].push(i)};for(let e=0;e<l.length;e++)for(let t=e+1;t<l.length;t++){let i=l[e],r=l[t];g(i,r)&&(c(r.sourceCross,i)&&Math.abs(r.sourceCross-i.sourceCross)>.01&&m(t,e),c(r.targetCross,i)&&Math.abs(r.targetCross-i.targetCross)>.01&&m(e,t),c(i.sourceCross,r)&&Math.abs(i.sourceCross-r.sourceCross)>.01&&m(e,t),c(i.targetCross,r)&&Math.abs(i.targetCross-r.targetCross)>.01&&m(t,e))}let u=z(d,f,y),x=l.map((e,t)=>t).sort((e,t)=>u[e]-u[t]||e-t),p=0;for(let e=0;e<x.length;e++){let t=l[x[e]];for(let i=0;i<e;i++){let e=l[x[i]];g(t,e)&&(t.track=Math.max(t.track,e.track+1))}p=Math.max(p,t.track)}let b=!1,M=Math.max(1,Math.min(2,i/2)),w=e.flatMap(e=>[e.sourceCross,e.targetCross]).sort((e,t)=>e-t);for(let t of l){if(!e.some(e=>e!==t&&.5>=Math.abs(e.sourceCross-t.targetCross)&&(.01>=Math.abs(e.sourceCross-e.targetCross)||e.track>=t.track)))continue;let a=t.targetCross-i,o=t.targetCross+i;for(let e=w.length-1;e>=0;e--){let t=w[e];Math.abs(t-a)<M&&(a=t-M)}for(let e of w)Math.abs(e-o)<M&&(o=e+M);let l=a>=0?t.targetCross-a:1/0,s=o<=r?o-t.targetCross:1/0;Number.isFinite(Math.min(l,s))||n("agentic local channel-terminal clearance"),t.targetEscape=s<l||s===l&&t.sourceCross>t.targetCross?o:a,b=!0}let v=Math.max(12,i,o??0),k=2*v+p*i+(b?i:0),S=Math.max(t,k),N=(S-k)/2;for(let t of e)t.offset=v+N+t.track*i,void 0!==t.targetEscape&&(t.targetExit=S-v);return S}(e,eH,h.edgeSpacing??6,ep,f,d,h.minimumTerminalLead))),eB=new Float64Array(ec.length),e_=0;for(let e=0;e<ey.length;e++){for(let t of ey[e])eB[t]=e_+eu[e]/2;e_+=eu[e]+(eV[e]??0)}Number.isFinite(e_+ep+2*p)||d("agentic local coordinate-range limit");let eq=(e,t)=>{let i=p+(D?e_-t:t);return q?{x:i,y:p+e}:{x:p+e,y:i}},eD=u.map((e,t)=>{let i=eq(eb[t],eB[t]);return{x:i.x-e.width/2,y:i.y-e.height/2}}),eQ=(e,t)=>{let i=ec[t].crossSize,r=Math.min(8,i/6),a=q?eD[t].y:eD[t].x;return e===eb[t]-i/2+r?a+r:e===eb[t]+i/2-r?a+i-r:p+e},e$=(e,t)=>{let i=eD[e],r=u[e];return q?i.x+(t!==D?r.width:0):i.y+(t!==D?r.height:0)},eG=!h.placementOnly||h.cycleOriented||h.loopPorts?.length?x.map((e,t)=>{let i=ed[t],r=[],a=(e,t,i,a)=>{let n=eq(e,t);void 0!==i&&(q?n.y=i:n.x=i),void 0!==a&&(q?n.x=a:n.y=a);let o=r.at(-1);if(o?.x===n.x&&o.y===n.y)return;let l=r.at(-2);l&&o&&(l.x===o.x&&o.x===n.x&&(o.y-l.y)*(n.y-o.y)>=0||l.y===o.y&&o.y===n.y&&(o.x-l.x)*(n.x-o.x)>=0)&&r.pop(),r.push(n)};for(let e=1;e<i.length;e++){let r=i[e-1],n=i[e],o=eU[t][e-1],l=o.sourceCross,s=o.targetCross,h=eB[r]+ec[r].mainSize/2,g=eB[n]-ec[n].mainSize/2,c=eB[r]+eu[ec[r].rank]/2,d=c+o.offset,f=r<u.length?eQ(l,r):void 0,y=n<u.length?eQ(s,n):void 0;a(l,h,f,r<u.length?e$(r,!0):void 0),a(l,d,f),a(o.targetEscape??s,d,void 0===o.targetEscape?y:void 0),void 0!==o.targetEscape&&(a(o.targetEscape,c+o.targetExit),a(s,c+o.targetExit,y)),a(s,g,y,n<u.length?e$(n,!1):void 0)}let n=ef[t],o=void 0===n?void 0:eq(eb[n],eB[n]);return{points:r,...o?{labelPosition:o}:{}}}):x.map(()=>({points:[]}));return{topology:"layered",expandedVertices:ec.length,width:2*p+(q?e_:ep),height:2*p+(q?ep:e_),nodes:eD,edges:eG}}(a,h,c,d),u=a.placementOnly?f:function(e,t,i,r,a){if(e.placementOnly||e.groups?.length||void 0===e.maximumEdgeStrokeWidth)return t;let n=!1;for(let t of e.edges)if(--i.pairs<0&&a("agentic marker metadata work limit"),t.markerPaint?.start?.length||t.markerPaint?.end?.length){n=!0;break}if(!n)return 0===e.maximumEdgeBendRadius&&(C(i,a),--i.pairs<0&&a("agentic marker full-proof work limit"),R(e,t,new Set,i,a)),t;let o=e.nodes.length,l=e.edges.length;i.arcs-=3*o+l+7,i.pairs-=2*o+l+4,i.arcs<0&&a("agentic flat marker metadata capacity limit"),i.pairs<0&&a("agentic flat marker metadata work limit");let s=t.expandedVertices??0,h=t.nodes.map((t,i)=>({...t,width:e.nodes[i].width,height:e.nodes[i].height})),g=[...h],c=new Set;for(let e=0;e<l;e++)c.add(e);for(let e of t.edges)--i.pairs<0&&a("agentic flat marker path work limit"),v(e.points,i,a);let d=W(e,t,h,[],g,[],i,e=>{if(!Number.isSafeInteger(e)||e<0)throw TypeError("Invalid measured marker point reservation");s+e>32768&&a("agentic local cross-hierarchy visibility-expansion limit"),s+=e},a,c,Math.max(8,e.edgeSpacing??6),e.maximumEdgeStrokeWidth,!0);R(e,t,c,i,a,d),i.arcs-=l+2,i.pairs-=l,i.arcs<0&&a("agentic marker full-proof capacity limit"),i.pairs<0&&a("agentic marker full-proof work limit");let f=[];for(let e=0;e<l;e++)f.push(e);return{...t,expandedVertices:s,boundaryRoutes:f}}(a,f,d,0,c);return a.placementOnly?u:function(r,a){if("forest"===a.topology||a.sharedEdges?.length||r.edges.length>128||a.edges.reduce((e,t)=>e+t.points.length,0)>2048)return a;let o=r.nodes.map((e,t)=>({...a.nodes[t],width:e.width,height:e.height})),l=(a.groups??[]).map((e,t)=>({...e,height:r.groups[t].padding.top})),s=r.edges.map((e,t)=>{let i=a.edges[t].labelPosition;return e.label&&i?{x:i.x-e.label.width/2-2,y:i.y-e.label.height/2-2,width:e.label.width+4,height:e.label.height+4}:void 0}),h=a.edges.map((e,t)=>({points:e.points,source:String(r.edges[t].source),target:String(r.edges[t].target),style:!1===r.edges[t].visible?"invisible":"solid"})),c=()=>h.map(e=>({points:e.points,visible:"invisible"!==e.style})),d=e=>e.slice(1).reduce((t,i,r)=>t+Math.abs(i.x-e[r].x)+Math.abs(i.y-e[r].y),0),f=(e,t)=>`${Math.sign(t.x-e.x)},${Math.sign(t.y-e.y)}`,y=512,m=8e6,u=e=>(m-=e)>=0;for(let[x,p]of r.edges.entries()){if(a.boundaryRoutes?.includes(x)||p.source===p.target||!1===p.visible||h[x].points.length<5)continue;let b=24,M=[...o,...l,...s.filter((e,t)=>!!e&&t!==x)],w=new Set([x]),v;for(let o=0;o<4;o++){let o=h[x].points,l=a.edges[x].labelPosition,k=[...o],S=-1;if(l){if((S=k.findIndex(e=>e.x===l.x&&e.y===l.y))<0){for(let e=1;e<k.length;e++)if(t(l,k[e-1],k[e])){S=e,k.splice(e,0,{...l});break}}if(S<0)break}let N=[[0,k.length-1],...S>0&&S<k.length-1?[[0,S],[S,k.length-1]]:[]],E=!1;e:for(let[S,P]of N)for(let N=S;N+2<P;N++)for(let S=P;S>N+2;S--)for(let P of[!1,!0]){if((m-=k.length)<0)return a;let I=k[N],A=k[S],F=P?{x:A.x,y:I.y}:{x:I.x,y:A.y},Y=function(e){let t=[];for(let i of e){let e=t.at(-1),r=t.at(-2);e?.x===i.x&&e.y===i.y||(r&&e&&(r.x===e.x&&e.x===i.x&&(e.y-r.y)*(i.y-e.y)>=0||r.y===e.y&&e.y===i.y&&(e.x-r.x)*(i.x-e.x)>=0)&&t.pop(),t.push(i))}return t}([...k.slice(0,N+1),F,...k.slice(S)]);if(Y.length>=o.length||d(Y)>d(o)+1e-7||f(Y[0],Y[1])!==f(o[0],o[1])||f(Y.at(-2),Y.at(-1))!==f(o.at(-2),o.at(-1)))continue;if((m-=Y.length*M.length)<0)return a;if(Y.slice(1).some((t,i)=>M.some(r=>e(Y[i],t,r))))continue;if((m-=Y.length*h.reduce((e,t)=>e+t.points.length,0))<0)return a;let T=h.reduce((e,t)=>e+t.points.length,0);if(b--<=0)break e;if(y--<=0||(m-=T*T)<0)return a;let X=n(Y,x,h,r,u,u);if(m<0)return a;if(void 0===X)continue;let C=l,L=s[x];if(l&&p.label&&!Y.slice(1).some((e,i)=>t(l,Y[i],e))){let t=[];for(let e=1;e<Y.length;e++){let i=Y[e-1],r=Y[e],a=i.y===r.y,n=(a?p.label.width:p.label.height)/2+2,o=Math.min(a?i.x:i.y,a?r.x:r.y)+n,s=Math.max(a?i.x:i.y,a?r.x:r.y)-n;if(o>s)continue;let h=Math.max(o,Math.min(s,a?l.x:l.y));t.push(a?{x:h,y:i.y}:{x:i.x,y:h}),t.push({x:(i.x+r.x)/2,y:(i.y+r.y)/2})}for(let r of(t.sort((e,t)=>Math.abs(e.x-l.x)+Math.abs(e.y-l.y)-Math.abs(t.x-l.x)-Math.abs(t.y-l.y)),C=void 0,t)){let t={x:r.x-p.label.width/2-2,y:r.y-p.label.height/2-2,width:p.label.width+4,height:p.label.height+4};if((m-=M.length+h.reduce((e,t)=>e+t.points.length,0))<0)return a;if(!(t.x<0||t.y<0||t.x+t.width>a.width||t.y+t.height>a.height||M.some(e=>i(t,e)))&&!h.some((i,r)=>r!==x&&"invisible"!==i.style&&i.points.slice(1).some((r,a)=>e(i.points[a],r,t)))){C=r,L=t;break}}if(!C)continue}if(v??=g(c(),w),h[x].points=Y,X>v){h[x].points=o;continue}a.edges[x].points=Y,C&&(a.edges[x].labelPosition={...C}),s[x]=L,v=X,E=!0;break e}if(!E)break}}return a}(a,u)}finally{m&&f&&f!==m&&(f.pairs=m.pairs,f.arcs=m.arcs,f.swaps=m.swaps)}}function Z(e,t,i,r,a,n=!1,o="primary"){let l,{edgeSelectorIndices:s,graphEdgeMarkerPaintRegions:h,DEFAULTS:g,LABEL_PILL_PADDING:d,measureRenderStage:f,graphTextBlock:y,resolveLabelContent:m,groupTitleWidth:u,groupHeaderHeight:x,estimateNodeSize:p,resolveNodeInlineStyle:b,resolveEdgeInlineStyle:M,resolveClassInlineStyle:w,containsNonFiniteNumber:v,finishGraphGeometry:k}=a;t.preserveSubgraphChildOrder&&a.unsupported("family-specific graph geometry");let S={...g,...t},N=[],E={pairs:1e6,arcs:65536,swaps:1e6};E.arcs-=2;let P=(e,t=0)=>{E.pairs-=e,E.arcs-=t,(E.pairs<0||E.arcs<0)&&a.unsupported("agentic marker preparation work limit")},I=f("graph-preparation",()=>{let r,l=[],g=new Map,f=new Map,v=(e,r,a)=>{let n=l.length,o=e.direction??a,s=x(e,i),h=e.concurrencyRegion?t.stateVisual?.dividerMargin??0:0;for(let t of(g.set(e.id,n),N.push(e),l.push({id:e.id,parent:r,direction:o,minWidth:u(e,i),headerHeight:s,padding:{top:s+i.groupPaddingY+h,bottom:i.groupPaddingY+h,left:i.groupPaddingX+h,right:i.groupPaddingX+h}}),e.nodeIds))f.set(t,{parent:n,direction:o});e.children.forEach(e=>v(e,n,o))};e.subgraphs.forEach(t=>v(t,void 0,e.direction));let k=[...e.nodes].map(([r,n])=>{g.has(r)&&a.unsupported("overlapping node and frame identities");let o=f.get(r);return{id:r,...o?{parent:o.parent}:{},...t.nodeSizes?.get(r)??p(r,m(n.label,n.labelContent),n.shape,i,o?.direction??e.direction,t.stateVisual,n.labelBlock)}}),E=new Map(k.map((e,t)=>[e.id,t]));for(let[e,t]of g)E.set(e,k.length+t);let I=new Set;for(let[i,r]of Object.entries(t.layoutHints?.ranks??{})){let t=E.get(i);if(void 0===t||!e.nodes.has(i))throw Error(`LAYOUT_HINT_INVALID: unknown node "${i}"`);if(!Number.isSafeInteger(r)||r<0||r>1e4)throw Error(`LAYOUT_HINT_INVALID: rank for "${i}" must be an integer in [0,10000]`);let a=k[t];a.partition=r,I.add(a.parent??-1)}for(let e of k)I.has(e.parent??-1)&&void 0===e.partition&&(e.partition=0);for(let e of l)I.has(e.parent??-1)&&(e.partition=0);if(t.layoutHints?.adjacent?.length){let i=new Map,r=[...k,...l];r.forEach((e,t)=>{let r=e.parent??-1,a=i.get(r)??[];a.push(t),i.set(r,a)});let a=new Map;for(let e of i.values())e.forEach((e,t)=>a.set(e,t));let n=new Set,o=new Map;for(let i of t.layoutHints.adjacent){if(i.length<2)throw Error("LAYOUT_HINT_INVALID: adjacent needs two or more nodes");let t=i.map(t=>{let i=E.get(t);if(void 0===i||!e.nodes.has(t))throw Error(`LAYOUT_HINT_INVALID: unknown node "${t}"`);return i}),r=k[t[0]].parent??-1;if(t.some(e=>(k[e].parent??-1)!==r))throw Error("LAYOUT_HINT_INVALID: adjacent nodes need the same container");for(let e of t){if(n.has(e))throw Error("LAYOUT_HINT_INVALID: a node cannot repeat in adjacency groups");n.add(e)}let l=o.get(r)??new Map;l.set(Math.min(...t.map(e=>a.get(e))),t),o.set(r,l)}for(let[e,t]of o){let a=0;i.get(e).forEach((e,i)=>{let o=t.get(i);if(o)for(let e of o)r[e].modelOrder=a++;else n.has(e)||(r[e].modelOrder=a++)})}}if(t.layoutHints?.shortEdges?.length){r=new Set;let i=s(e.edges);for(let e of t.layoutHints.shortEdges){let t=i.get(e);if(void 0===t)throw Error(`LAYOUT_HINT_INVALID: unknown edge "${e}"`);r.add(t)}}let A=l.length?(e,t)=>{let i=(e,t)=>{for(let i=t<k.length?k[t].parent:l[t-k.length].parent;void 0!==i;i=l[i].parent)if(i===e)return!0;return!1};return e>=k.length&&i(e-k.length,t)?"start":t>=k.length&&i(t-k.length,e)?"end":void 0}:void 0,F=0,Y=0,T=0;P(0,3*k.length+5);let X=new Float64Array(k.length),C=new Uint32Array(k.length),L=new Uint32Array(k.length),O=new Map,R=e=>{if(P(4+("string"==typeof e?e.length:0),1),"string"==typeof e&&!/^\s*(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(e))return;let t="number"==typeof e?e:Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:void 0},W=e.edges.map((t,o)=>{let l,s=E.get(t.source),g=E.get(t.target);(void 0===s||void 0===g)&&a.unsupported("unknown endpoint");let f=t.label?y(m(t.label,t.labelContent),i,"edge"):void 0,u=A?.(s,g),x,p=M(o,e),b=!n&&"invisible"!==t.style&&(t.hasArrowStart||t.hasArrowEnd),w=R(p?.["stroke-width"]??i.lineWidth*("thick"===t.style?2:1));if("invisible"!==t.style&&void 0!==w&&(T=Math.max(T,w)),(b||u)&&void 0!==w){P(12,15);let e=(p?.stroke??i.edgeStrokeColor)==="none",r=!!p?.["stroke-width"],n=JSON.stringify([u??null,t.style,t.hasArrowStart,t.hasArrowEnd,t.startMarker,t.endMarker,e,r]);if(!(l=O.get(n))){P(e?4096:2048,e?2048:1024);let o=h({...t,id:"marker-room",source:"",target:"",points:"end"===u?[{x:1,y:0},{x:0,y:0}]:[{x:0,y:0},{x:1,y:0}],inlineStyle:r?{"stroke-width":"1"}:void 0},{lineWidth:i.lineWidth,...e?{edgeStrokeColor:"none"}:{}}),s=0,g=0,c=0,d=0,f=0,y=0;for(let e of o){P(18);let t=e.bounds;t&&Number.isFinite(t.x0)&&Number.isFinite(t.x1)&&Number.isFinite(t.y0)&&Number.isFinite(t.y1)&&!(t.x0>t.x1)&&!(t.y0>t.y1)||a.unsupported("agentic marker paint bounds");let i="start"===e.position?"end"===u?1-t.x0:t.x1:"end"===u?t.x1:1-t.x0;"start"===e.position?s=Math.max(s,i):"end"===e.position&&(g=Math.max(g,i)),c=Math.max(c,t.y1-t.y0),e.position===u&&(y++,d=Math.max(d,t.x1),f=Math.max(f,2*Math.max(Math.abs(t.y0),Math.abs(t.y1))))}P(0,7),l={start:s,end:g,span:c,boundaryInset:d,boundaryHeight:f,boundaryCount:y},O.set(n,l)}let{start:o,end:d,span:f}=l;b&&(F=Math.max(F,o+c+i.edgeBendRadius,d+c+i.edgeBendRadius,f),Y=Math.max(Y,o+d),t.hasArrowStart&&s<k.length&&(X[s]=Math.max(X[s],f)),t.hasArrowEnd&&g<k.length&&(X[g]=Math.max(X[g],f)))}if("invisible"!==t.style&&(P(2),s<k.length&&(L[s]=L[s]+1),g<k.length&&(C[g]=C[g]+1)),u){let e="invisible"!==t.style&&("start"===u?t.hasArrowStart:t.hasArrowEnd);!e||l&&l.boundaryCount||a.unsupported("ancestor marker paint bounds"),x={inset:e?l.boundaryInset:0,height:e?l.boundaryHeight:0}}let v=u&&f?Math.max(4,i.lineWidth*("thick"===t.style?2:1)*2):0;return{source:s,target:g,minSpan:t.length??1,...r?.has(o)?{short:!0}:{},...x?{boundaryMarker:x}:{},..."invisible"===t.style?{visible:!1}:{},...f?{label:{width:f.width+2*d+2*v,height:f.height+2*d+2*v}}:{}}}),j=!t.stateVisual&&!l.length&&[...e.nodes.values()].every(e=>"rectangle"===e.shape&&!e.semanticShape)&&e.edges.every((t,i)=>{if(t.label||"solid"!==t.style||t.hasArrowStart||!t.hasArrowEnd||t.endMarker&&"arrow"!==t.endMarker)return!1;let r=M(i,e);return!r||0===Object.keys(r).length}),H=Math.max(i.nodeLineWidth,i.groupLineWidth)/2;for(let[t]of e.nodes){let r=R(b(t,e)?.["stroke-width"]??i.nodeLineWidth);P(3),void 0!==r&&(H=Math.max(H,r/2))}for(let t of N)if(t.stateComposite){let r=R(w(t.id,e)?.["stroke-width"]??i.groupLineWidth);void 0!==r&&(H=Math.max(H,r/2))}let z=H+T/2,U=Math.max(6,i.lineWidth+4),V=F+z>Math.max(12,U)?F+z:void 0;for(let i=0;i<k.length;i++){P(6);let r=k[i],n=e.nodes.get(r.id),o=Math.max(C[i],L[i]),l=X[i]+T;if(o<2||X[i]<=8||"rectangle"!==n.shape||n.semanticShape||t.nodeSizes?.has(r.id))continue;let s=(f.get(r.id)?.direction??e.direction)==="LR"||(f.get(r.id)?.direction??e.direction)==="RL",h=(o-1)*l,g=h<=32?1.5*h:h+16;Number.isFinite(g)||a.unsupported("agentic marker spacing range"),s?r.height=Math.max(r.height,g):r.width=Math.max(r.width,g),r.minimumPortSpacing=l}return Number.isFinite(Y+z)&&Number.isFinite(V??0)&&Number.isFinite(2*(Y+z))||a.unsupported("agentic marker spacing range"),{nodes:k,groups:l,edges:W,shareCompleteFans:j,direction:e.direction,padding:S.padding,nodeSpacing:S.nodeSpacing,layerSpacing:Math.max(S.layerSpacing,2*(Y+z)),edgeSpacing:U,...void 0!==V?{minimumTerminalLead:V}:{},..."authored"===o?{authoredCycleOrder:!0}:"compact"===o?{compactPrivateRanks:!0}:{},...n?{placementOnly:!0}:{}}});P(0,2),G.set(I,E);try{l=f("agentic",()=>r(I))}finally{G.delete(I)}if(l.nodes.length!==I.nodes.length||(l.groups?.length??0)!==I.groups.length||l.edges.length!==e.edges.length||v(l)||l.sharedEdges?.some(t=>!Number.isInteger(t)||t<0||t>=e.edges.length)||!n&&l.edges.some((e,t)=>e.points.length<2||I.edges[t].label&&!e.labelPosition))throw TypeError("Agentic graph producer returned malformed geometry");let A=I.nodes.map((t,i)=>{let r=e.nodes.get(t.id),a=e.classAssignments.get(t.id);return{...r,id:t.id,width:t.width,height:t.height,...l.nodes[i],inlineStyle:b(t.id,e),classNames:a?.split(/\s+/).filter(Boolean)}}),F=n?[]:e.edges.map((t,i)=>({...t,...l.edges[i],edgeIndex:i,inlineStyle:M(i,e),...t.id&&e.classAssignments.has(t.id)?{classNames:e.classAssignments.get(t.id).split(/\s+/).filter(Boolean)}:{}})),Y=N.map((t,i)=>{let r={id:t.id,label:t.label,...t.labelContent?{labelContent:t.labelContent}:{},...l.groups[i],children:[],...t.concurrencyRegion?{concurrencyRegion:!0}:{},...void 0===t.headerMinHeight?{}:{headerMinHeight:t.headerMinHeight},...t.stateComposite?{inlineStyle:w(t.id,e)}:{}};return n&&(r.headerHeight=I.groups[i].headerHeight),r}),T=[];if(Y.forEach((e,t)=>{let i=I.groups[t].parent;void 0===i?T.push(e):Y[i].children.push(e)}),n)return{width:l.width,height:l.height,nodes:A,edges:[],groups:T};let X=k({width:l.width,height:l.height,nodes:A,edges:F,groups:T},e,"forest"===l.topology,S.padding,i,t.stateVisual?.noteMargin??18,void 0,l.sharedEdges).positioned;if(v(X))throw TypeError("Agentic graph pipeline returned non-finite geometry");return X}function ee(e,t,i,r,a){let{countEdgeCrossings:n,countOpposingRouteOverlaps:o,countParallelRouteOverlaps:l,measureLabelConflicts:s}=a,h=e=>e.edges.reduce((e,t)=>e+t.points.length,0);if(e.subgraphs.length||e.nodes.size>20||e.edges.length>64||e.edges.reduce((e,t)=>e+(t.length??1),0)>128||h(i)>2048||0===n(i.edges))return i;et(e,t,{strategy:"agentic-layered",produce:()=>i},a);let g=e=>[s(e,t).total,o(e.edges),l(e.edges),n(e.edges),e.edges.reduce((e,t)=>e+("invisible"===t.style?0:Math.max(0,t.points.length-2)),0),e.width*e.height],c=i,f=g(i);for(let i of("function"==typeof r?[{strategy:"agentic-authored-order",produce:r}]:r).slice(0,2)){let r;try{r=et(e,t,i,a)}catch(e){if(!(e instanceof m)&&!(e instanceof d))throw e;continue}if(h(r)>2048)continue;let n=g(r);for(let e=0;e<f.length;e++){if(n[e]<f[e]){c=r,f=n;break}if(n[e]>f[e])break}if(0===f[3])break}return c}function et(e,t,i,r){let a=r.certifyCandidate(e,t,i,!0);if(!a.certified)throw new d([a.attempt]);return r.retainSelection(e,{selected:a.certified,reason:"first-certified",attempts:1,compared:[{strategy:a.certified.strategy,score:a.certified.score}]})}function ei(e,t,i,r,a){let n=function(e,t,i,r,a){let n=!1!==t.compareRoutePreferences&&!t.stateVisual&&!e.subgraphs.length&&e.nodes.size<=20&&e.edges.length<=64,o,l;if(n&&D&&!a.customTextMeasurementActive()){let n=Q([e,t,i,Object.keys(q.process?.env??{}).filter(e=>e.startsWith("APL_")).map(e=>[e,q.process.env[e]]).sort()]);if(n.length<=65536){o=n,(l=$.get(a))||(l=new _(1048576),$.set(a,l));let s=l.get(o);if(s)return Z(e,t,i,r,a,!1,s)}}let s=Z(e,t,i,r,a);if(!n)return s;let h=[{strategy:"agentic-authored-order",produce:()=>Z(e,t,i,r,a,!1,"authored")}];e.edges.some(e=>!e.label)&&h.push({strategy:"agentic-compact-ranks",produce:()=>Z(e,t,i,r,a,!1,"compact")});let g=ee(e,i,s,h,a),c=g===s?"primary":g.certification?.strategy==="agentic-authored-order"?"authored":g.certification?.strategy==="agentic-compact-ranks"?"compact":void 0;return o&&l&&c&&l.set(o,c,2*o.length+128),g}(e,t,i,r,a);return et(e,i,{strategy:"agentic-layered",produce:()=>n},a)}function er(e,t,i,r,a){let n=Z(e,t,i,r,a,!0);return{width:n.width,height:n.height,nodes:n.nodes,groups:n.groups}}export{et as certifyOwnedLayoutCandidate,J as createMeasuredLayoutCache,B as improveArchitectureSiblingSlots,K as layoutLayeredGraph,ei as layoutNativeGraphCandidate,er as layoutNativeGraphPlacement,ee as refineOwnedLayoutCandidate};
|