@erd-studio/renderer 0.4.0 → 0.4.1

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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to `@erd-studio/renderer`. While `0.x`, a breaking change bumps the minor version.
4
4
 
5
+ ## 0.4.1
6
+
7
+ ### Added
8
+ - **`ErdCanvas` prop `routingWorkerUrl`** (optional) and the routing worker as its own file, **`@erd-studio/renderer/edge-routing-worker.js`** (a new `exports` entry; the same code the canvas inlines). A host whose CSP refuses a blob worker but allows its own scripts (`script-src 'self'` with no `worker-src`, as some app-hosting platforms set) serves that file from its own origin and passes its URL, and diagrams over 100 lines route in the worker again instead of keeping simple lines past 150 lines. Without the prop nothing changes: the worker starts from the inlined code through a blob URL. The canvas store gains the optional `routingWorkerUrl` (absent or null by default, so a host that hand-builds `CanvasState` needs no change). No `DisplaySubjectArea` change, no new `--vscode-*` variables, and the viewer still posts nothing.
9
+
5
10
  ## 0.4.0
6
11
 
7
12
  ### Added
package/README.md CHANGED
@@ -44,7 +44,8 @@ function Diagram({ domain }: { domain: DisplaySubjectArea }) {
44
44
  | `onLayoutModifiedChange(modified)` | Called when the layout starts or stops differing from the domain's positions (a node moved; `resetLayout()`, a new domain, or a node moved back). |
45
45
  | `onReady()` | Called once, after the first nodes are measured and fitted into view (straight away for an empty domain). |
46
46
  | `logicalOnly` | Draw the diagram of a project with no dbt project (default `false`): tables, lines and the selection ring take neutral theme colours instead of the logical stage's blue, so the layer badge carries the colour, and the legend leaves out the Physical stage, ghosts, provenance chips and comparison colours. |
47
- | `lineStyle` | How relationship lines are drawn (default `'curved'`; `LINE_STYLES` lists both, `LineStyle` is the type). Both route every line around the tables in its way. `'curved'`: soft curves, a halo where two lines cross (the line underneath is cut), and a faint dashed "x-ray" where a line has no way round a table. `'hops'`: square corners and a small hop where two lines cross. Any other value reads as `'curved'`. A view preference: readers cannot change it, and nothing is posted. Diagrams over 100 lines are routed in a Web Worker started from a blob URL, so allow `worker-src blob:` in the page's CSP: with it any size is routed (2,000 tables in about 1.5 s) without pausing the page; without it, diagrams up to 150 lines route on the main thread and larger ones keep simple lines. |
47
+ | `lineStyle` | How relationship lines are drawn (default `'curved'`; `LINE_STYLES` lists both, `LineStyle` is the type). Both route every line around the tables in its way. `'curved'`: soft curves, a halo where two lines cross (the line underneath is cut), and a faint dashed "x-ray" where a line has no way round a table. `'hops'`: square corners and a small hop where two lines cross. Any other value reads as `'curved'`. A view preference: readers cannot change it, and nothing is posted. Diagrams over 100 lines are routed in a Web Worker: from `routingWorkerUrl` when given, else from a blob URL (allow `worker-src blob:` in the page's CSP). With a worker any size is routed (2,000 tables in about 1.5 s) without pausing the page; without one, diagrams up to 150 lines route on the main thread and larger ones keep simple lines. |
48
+ | `routingWorkerUrl` | The URL of your copy of `@erd-studio/renderer/edge-routing-worker.js` (the routing worker as a classic script), served from the page's own origin. Set it when your CSP refuses a blob worker but allows your own scripts (`script-src 'self'` and no `worker-src`, as some app-hosting platforms set): diagrams over 100 lines then route in that worker. With Vite: `import routingWorkerUrl from '@erd-studio/renderer/edge-routing-worker.js?url'`. Read once, when the canvas mounts; if the file cannot start a worker, the canvas falls back to the blob, then to the main thread. |
48
49
  | `className`, `style` | Applied to the canvas's wrapper element, which fills its parent. |
49
50
 
50
51
  The ref exposes `resetLayout()`, which puts every node back at its position in the domain with its original edge sides.
@@ -4223,19 +4223,36 @@ function routeAll(input, options, ctx = {}) {
4223
4223
  function inlinedWorkerCode() {
4224
4224
  return '"use strict";(()=>{var Ce=Object.defineProperty;var ve=(n,t,o)=>t in n?Ce(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var K=(n,t,o)=>ve(n,typeof t!="symbol"?t+"":t,o);var Oe="curved";function Ie(n){return n==="curved"||n==="hops"}var Le={curved:{crossings:"halo",underTables:"xray",corners:"curved"},hops:{crossings:"hops",underTables:"hidden",corners:"rounded"}};function jn(n){return Le[Ie(n)?n:Oe]}function qt(n,t,o){switch(t){case"top":return{x:n.x,y:n.y-o};case"bottom":return{x:n.x,y:n.y+o};case"left":return{x:n.x-o,y:n.y};case"right":return{x:n.x+o,y:n.y}}}var Zt=["right","left","bottom","top"];function Vt(n){return n==="left"||n==="right"?0:1}function Tt(n){return n==="right"||n==="bottom"?1:-1}function Ne(n,t){switch(t){case"left":return n.x;case"right":return n.x+n.width;case"top":return n.y;case"bottom":return n.y+n.height}}function Wt(n,t){return Vt(t)===0?[n.y,n.y+n.height]:[n.x,n.x+n.width]}function Pt(n,t){let[o,e]=Wt(n,t),r=Math.min(20,(e-o)/2);return[o+r,e-r]}function Qn(n,t){let[o,e]=Wt(n,t);return(o+e)/2}function Jn(n,t,o){let e=Ne(n,t)+Tt(t)*20;return Vt(t)===0?{x:e,y:o}:{x:o,y:e}}function En(n,t){switch(t){case"right":return{x:n.x-20,y:n.y,side:t};case"left":return{x:n.x+20,y:n.y,side:t};case"bottom":return{x:n.x,y:n.y-20,side:t};case"top":return{x:n.x,y:n.y+20,side:t}}}function sn(n,t,o,e){return n.x-t<o.x+o.width+e&&o.x-e<n.x+n.width+t&&n.y-t<o.y+o.height+e&&o.y-e<n.y+n.height+t}function $t(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=e,s=Math.abs(r.x-c.x)<.01&&Math.abs(c.x-o.x)<.01,i=Math.abs(r.y-c.y)<.01&&Math.abs(c.y-o.y)<.01;if(s||i){t[t.length-1]={x:o.x,y:o.y};continue}}t.push({x:o.x,y:o.y})}}return t}function te(n,t,o,e){let r=o.x+e,c=o.x+o.width-e,s=o.y+e,i=o.y+o.height-e;if(c<=r||i<=s)return!1;if(Math.abs(n.x-t.x)<.01){if(n.x<=r||n.x>=c)return!1;let a=Math.min(n.y,t.y),f=Math.max(n.y,t.y);return Math.min(f,i)-Math.max(a,s)>0}if(Math.abs(n.y-t.y)<.01){if(n.y<=s||n.y>=i)return!1;let a=Math.min(n.x,t.x),f=Math.max(n.x,t.x);return Math.min(f,c)-Math.max(a,r)>0}for(let a=.05;a<1;a+=.05){let f=n.x+(t.x-n.x)*a,u=n.y+(t.y-n.y)*a;if(f>r&&f<c&&u>s&&u<i)return!0}return!1}var It=class{constructor(t,o=160){this.rects=t;K(this,"x0");K(this,"y0");K(this,"cols");K(this,"rows");K(this,"cells");K(this,"seen");K(this,"stamp",0);K(this,"cell");let e=1/0,r=1/0,c=-1/0,s=-1/0;for(let i of t)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x+i.width),s=Math.max(s,i.y+i.height);t.length||(e=r=0,c=s=1),this.x0=e,this.y0=r,this.cell=Math.max(o,Math.max(c-e,s-r)/256),o=this.cell,this.cols=Math.max(1,Math.ceil((c-e)/o)+1),this.rows=Math.max(1,Math.ceil((s-r)/o)+1),this.cells=Array.from({length:this.cols*this.rows},()=>[]),this.seen=new Uint32Array(t.length),t.forEach((i,a)=>{let[f,u]=this.cellOf(i.x,i.y),[l,h]=this.cellOf(i.x+i.width,i.y+i.height);for(let m=u;m<=h;m++)for(let d=f;d<=l;d++)this.cells[m*this.cols+d].push(a)})}cellOf(t,o){let e=Math.min(this.cols-1,Math.max(0,Math.floor((t-this.x0)/this.cell))),r=Math.min(this.rows-1,Math.max(0,Math.floor((o-this.y0)/this.cell)));return[e,r]}query(t,o,e,r,c=[]){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let[s,i]=this.cellOf(t,o),[a,f]=this.cellOf(e,r);for(let u=i;u<=f;u++)for(let l=s;l<=a;l++)for(let h of this.cells[u*this.cols+l])this.seen[h]!==this.stamp&&(this.seen[h]=this.stamp,c.push(h));return c}};function Ue(n){let t=Float64Array.from(n.filter(r=>Number.isFinite(r))).sort(),o=[],e=-1/0;for(let r of t)r-e>1&&(o.push(r),e=r);return Float64Array.from(o)}function wn(n,t,o){let e=Array.from(Ue(n)),r=Float64Array.from(t.filter(a=>Number.isFinite(a))).sort(),c=[],s=0;for(let a of r){for(;s<e.length&&e[s]<a-o;)s++;s<e.length&&Math.abs(e[s]-a)<=o||s>0&&Math.abs(e[s-1]-a)<=o||c.length&&a-c[c.length-1]<=o||c.push(a)}return Float64Array.from([...e,...c]).sort()}function Rt(n,t){let o=0,e=n.length-1,r=-1;for(;o<=e;){let c=o+e>>1;n[c]<=t+1e-6?(r=c,o=c+1):e=c-1}return r}function Nt(n,t){let o=0,e=n.length-1,r=n.length;for(;o<=e;){let c=o+e>>1;n[c]>=t-1e-6?(r=c,e=c-1):o=c+1}return r}var Et=null;function an(n,t){let o=n.length*t.length;if(!Et||Et.hBlk.length<o){let r=Math.max(o,Math.ceil((Et?.hBlk.length??0)*1.5));Et={hBlk:new Uint16Array(r),vBlk:new Uint16Array(r),hUse:new Uint8Array(r),vUse:new Uint8Array(r),hZone:new Uint8Array(r),vZone:new Uint8Array(r)}}let e={xs:n,ys:t,nx:n.length,ny:t.length,hBlk:Et.hBlk.subarray(0,o),vBlk:Et.vBlk.subarray(0,o),hUse:Et.hUse.subarray(0,o),vUse:Et.vUse.subarray(0,o),hZone:Et.hZone.subarray(0,o),vZone:Et.vZone.subarray(0,o)};return e.hBlk.fill(0),e.vBlk.fill(0),e.hUse.fill(0),e.vUse.fill(0),e.hZone.fill(0),e.vZone.fill(0),e}function un(n,t,o,e,r,c){let s=Rt(n.xs,t),i=Rt(n.xs,e),a=Rt(n.ys,o),f=Rt(n.ys,r);if(s<0||a<0||i<=s||f<=a)return;let{nx:u,hBlk:l,vBlk:h}=n;for(let m=a+1;m<f;m++){let d=m*u;for(let y=s;y<i;y++)l[d+y]+=c}for(let m=a;m<f;m++){let d=m*u;for(let y=s+1;y<i;y++)h[d+y]+=c}}function ne(n,t){for(let o=1;o<t.length;o++){let e=t[o-1],r=t[o],c=e<r?e:r;Math.abs(e-r)===1?n.hUse[c]<255&&n.hUse[c]++:n.vUse[c]<255&&n.vUse[c]++}}function Lt(n,t){let o=0,e=n.length;for(;o<e;){let r=o+e>>1;n[r]>t?e=r:o=r+1}return o}function Qt(n,t,o,e,r,c){ee(n,n.hZone,n.vZone,t,o,e,r,c)}function Ht(n,t,o,e,r,c){ee(n,n.hBlk,n.vBlk,t,o,e,r,c)}function ee(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,ny:l}=n,h=.5,m=Lt(f,r+h),d=Lt(f,s-h)-1,y=Math.max(0,Lt(a,e+h)-1),P=Math.min(u-2,Lt(a,c-h-1e-9)-1);for(let A=m;A<=d&&A<l;A++){let w=A*u;for(let C=y;C<=P;C++)a[C+1]>e+h&&a[C]<c-h&&(t[w+C]+=i)}let b=Lt(a,e+h),p=Lt(a,c-h)-1,R=Math.max(0,Lt(f,r+h)-1),S=Math.min(l-2,Lt(f,s-h-1e-9)-1);for(let A=R;A<=S;A++){if(!(f[A+1]>r+h&&f[A]<s-h))continue;let w=A*u;for(let C=b;C<=p&&C<u;C++)o[w+C]+=i}}function cn(n,t,o){let e=Rt(n,t),r=-1,c=o;for(let s of[e,e+1]){if(s<0||s>=n.length)continue;let i=Math.abs(n[s]-t);i<=c&&(r=s,c=i)}return r}function kn(n,t,o=.01){let{xs:e,ys:r,nx:c,hUse:s,vUse:i}=n;for(let a=1;a<t.length;a++){let f=t[a-1],u=t[a];if(Math.abs(f.y-u.y)<.01){let l=cn(r,f.y,o);if(l<0)continue;let h=Math.max(0,Rt(e,Math.min(f.x,u.x))),m=Math.min(c-1,Nt(e,Math.max(f.x,u.x)));for(let d=h;d<m;d++)s[l*c+d]<255&&s[l*c+d]++}else if(Math.abs(f.x-u.x)<.01){let l=cn(e,f.x,o);if(l<0)continue;let h=Math.max(0,Rt(r,Math.min(f.y,u.y))),m=Math.min(n.ny-1,Nt(r,Math.max(f.y,u.y)));for(let d=h;d<m;d++)i[d*c+l]<255&&i[d*c+l]++}}}var re=(n,t)=>n*2+(t>0?0:1),vn=class{constructor(){K(this,"f",new Float64Array(1024));K(this,"g",new Float64Array(1024));K(this,"s",new Int32Array(1024));K(this,"size",0);K(this,"topF",0);K(this,"topG",0);K(this,"topS",0)}clear(){this.size=0}grow(){let t=this.f.length*2,o=new Float64Array(t),e=new Float64Array(t),r=new Int32Array(t);o.set(this.f),e.set(this.g),r.set(this.s),this.f=o,this.g=e,this.s=r}push(t,o,e){this.size===this.f.length&&this.grow();let r=this.size++,c=this.f,s=this.g,i=this.s;for(;r>0;){let a=r-1>>1;if(c[a]<t||c[a]===t&&s[a]>=e)break;c[r]=c[a],s[r]=s[a],i[r]=i[a],r=a}c[r]=t,s[r]=e,i[r]=o}pop(){let t=this.f,o=this.g,e=this.s;this.topF=t[0],this.topG=o[0],this.topS=e[0];let r=--this.size;if(r===0)return;let c=t[r],s=o[r],i=e[r],a=0;for(;;){let f=2*a+1;if(f>=r)break;let u=f+1,l=f;if(u<r&&(t[u]<t[f]||t[u]===t[f]&&o[u]>o[f])&&(l=u),t[l]>c||t[l]===c&&o[l]<=s)break;t[a]=t[l],o[a]=o[l],e[a]=e[l],a=l}t[a]=c,o[a]=s,e[a]=i}},ln=class{constructor(){K(this,"cap",0);K(this,"gScore",new Float64Array(0));K(this,"stamp",new Uint32Array(0));K(this,"parent",new Int32Array(0));K(this,"seedOf",new Int32Array(0));K(this,"goalStamp",new Uint32Array(0));K(this,"goalOf",new Int32Array(0));K(this,"id",0);K(this,"heap",new vn);K(this,"lastPops",0);K(this,"targetBuf",new Float64Array(20));K(this,"zeroBuf",new Uint8Array(0))}zeros(t){return this.zeroBuf.length<t&&(this.zeroBuf=new Uint8Array(t)),this.zeroBuf}ensure(t){if(t*4<=this.cap)return;let o=Math.max(t*4,Math.ceil(this.cap*1.5));this.cap=o,this.gScore=new Float64Array(o),this.stamp=new Uint32Array(o),this.parent=new Int32Array(o),this.seedOf=new Int32Array(o),this.goalStamp=new Uint32Array(o>>2),this.goalOf=new Int32Array(o>>2),this.id=0}search(t,o,e,r,c=!0,s=1.1,i=80){let{xs:a,ys:f,nx:u,ny:l,hBlk:h,vBlk:m,hUse:d,vUse:y}=t,P=c?t.hZone:this.zeros(u*l),b=c?t.vZone:this.zeros(u*l),p=2,R=0;this.ensure(u*l),++this.id>=4294967280&&(this.stamp.fill(0),this.goalStamp.fill(0),this.id=1);let S=this.id,{gScore:A,stamp:w,parent:C,seedOf:v,goalStamp:k,goalOf:N,heap:B}=this;B.clear(),this.lastPops=0;let U=this.targetBuf,Y=0;for(let z=0;z<e.length;z++){let L=e[z],F=L.node;(k[F]!==S||L.cost<e[N[F]].cost)&&(k[F]=S,N[F]=z);let V=L.orient===0?1:0,Q=L.dir,T=0;for(;T<Y&&!(U[T*5]===V&&U[T*5+1]===Q);)T++;T===Y?(U[T*5]=V,U[T*5+1]=Q,U[T*5+2]=(V?L.point.x:L.point.y)*Q,U[T*5+3]=L.c,U[T*5+4]=L.c,Y++):(L.c<U[T*5+3]&&(U[T*5+3]=L.c),L.c>U[T*5+4]&&(U[T*5+4]=L.c))}let G=s,lt=(z,L,F)=>{let V=F<2?1:0,Q=F&1?-1:1,T=1/0;for(let ot=0;ot<Y;ot++){let it=ot*5,H=U[it],et=U[it+1],xt=U[it+2],Ct=U[it+3],Dt=U[it+4],kt=(H?z:L)*et,At=H?L:z,Xt=kt<xt-.5,St=At<Ct?Ct-At:At>Dt?At-Dt:0,vt;V===H?Q*et>0?vt=Xt?St===0?0:2:4:vt=2:Xt?St===0?vt=1:vt=At<Ct&&Q>0||At>Dt&&Q<0?1:3:vt=3;let Kt=(xt>kt?xt-kt:kt-xt)+St+vt*40;Kt<T&&(T=Kt)}return T*G};for(let z=0;z<o.length;z++){let L=o[z],F=re(L.orient,L.dir),V=L.node*4+F;if(w[V]===S&&A[V]<=L.cost)continue;w[V]=S,A[V]=L.cost,C[V]=-1,v[V]=z;let Q=L.node%u;B.push(L.cost+lt(a[Q],f[(L.node-Q)/u],F),V,L.cost)}let q=0,nt=0,at=0,_=0,j=(z,L,F,V,Q,T,ot,it)=>{let H=at+Q*(1+.25*T+(it?p:0))+(V>>1!==_>>1?40:0)+(ot?i:0),et=z*4+V;w[et]===S&&H>=A[et]-1e-9||(w[et]=S,A[et]=H,C[et]=nt,B.push(H+lt(L,F,V),et,H))};for(;B.size>0;){B.pop();let z=B.topS;if(z<0)return this.lastPops=q,this.build(-1-z,o,e,B.topF);let L=B.topG;if(L>A[z]+1e-9)continue;if(++q>r)return this.lastPops=q,null;let F=z>>2,V=z&3;if(nt=z,at=L,_=V,k[F]===S){let H=e[N[F]],et=re(H.orient,H.dir),xt=-1;V===et?xt=L+H.cost:V>>1!==et>>1&&(xt=L+40+H.cost),xt>=0&&B.push(xt,-1-z,xt)}let Q=F%u,T=(F-Q)/u,ot=a[Q],it=f[T];if(V!==1&&Q+1<u&&h[F]===0&&!(P[F]&R)){let H=F+1,et=a[Q+1];j(H,et,it,0,et-ot,d[F],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F])}if(V!==0&&Q>0&&h[F-1]===0&&!(P[F-1]&R)){let H=F-1,et=a[Q-1];j(H,et,it,1,ot-et,d[H],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F-1])}if(V!==3&&T+1<l&&m[F]===0&&!(b[F]&R)){let H=F+u,et=f[T+1];j(H,ot,et,2,et-it,y[F],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F])}if(V!==2&&T>0&&m[F-u]===0&&!(b[F-u]&R)){let H=F-u,et=f[T-1];j(H,ot,et,3,it-et,y[H],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F-u])}}return this.lastPops=q,null}build(t,o,e,r){let c=[],s=t,i=o[0];for(let f=0;f<1e6;f++){c.push(s>>2);let u=this.parent[s];if(u<0){i=o[this.seedOf[s]];break}s=u}c.reverse();let a=e[this.goalOf[t>>2]];return{nodes:c,src:i,tgt:a,cost:r}}};var Ut=.01,ie=[];function xn(n,t){return Math.abs(n[t].x-n[t+1].x)<Ut}var ct=(n,t)=>n?t.x:t.y,st=(n,t)=>n?t.y:t.x;function _n(n,t,o,e,r,c,s,i){let a=e-i,f=e+i,u=o?n.buckets.query(e-i-s,r-s,e+i+s,c+s,ie):n.buckets.query(r-s,e-i-s,c+s,e+i+s,ie),l=t.ignore;for(let h=0;h<u.length;h++){let m=u[h];if(l&&l.has(m))continue;let d=n.rects[m],y=m>=n.zoneFrom?1:m===t.own[0]||m===t.own[1]?Math.max(s,29):s,P=o?d.y:d.x;if((o?d.y+d.height:d.x+d.width)+y<=r+.5||P-y>=c-.5)continue;let p=o?d.x:d.y,R=o?d.x+d.width:d.y+d.height;R<=e+.5?R+y>a&&(a=R+y):p>=e-.5&&p-y<f&&(f=p-y)}return[Math.min(a,e),Math.max(f,e)]}function mn(n,t,o,e){o?(n[t]={x:e,y:n[t].y},n[t+1]={x:e,y:n[t+1].y}):(n[t]={x:n[t].x,y:e},n[t+1]={x:n[t+1].x,y:e})}function ae(n,t){for(let o=0;o<n.length;o++){let e=n[o];for(let r=0;r<12&&Ge(n,o,t);r++)e.pts=$t(e.pts)}}function Ge(n,t,o){let e=n[t].pts,r=e.length-2;for(let c=1;c<r;c++){let s=!xn(e,c),i=Math.sign(st(s,e[c])-st(s,e[c-1])),a=Math.sign(st(s,e[c+2])-st(s,e[c+1]));if(!(i===0||i!==a)&&(ce(n,t,c-1,-1,s,ct(s,e[c+1]),o)||ce(n,t,c+1,1,s,ct(s,e[c]),o)))return!0}return!1}function ce(n,t,o,e,r,c,s){let i=n[t],a=i.pts,f=a.length-2,u=ct(r,a[o]);if(Math.abs(c-u)<.5)return!1;let l=o+e;if(l<0||l>f){let[R,S]=o===0?Pt(i.src,i.srcSide):Pt(i.tgt,i.tgtSide);if(c<R-.01||c>S+.01)return!1}else{let R=e<0?a[o-1]:a[o+2],S=e<0?a[o]:a[o+1],A=ct(r,S)-ct(r,R),w=c-ct(r,R);if(A===0||Math.sign(A)!==Math.sign(w))return!1;let C=l===0||l===f;if(Math.abs(w)<(C?10:10)-.01)return!1}let h=Math.min(st(r,a[o]),st(r,a[o+1])),m=Math.max(st(r,a[o]),st(r,a[o+1])),[d,y]=_n(s,i,r,u,h,m,16,Math.abs(c-u)+1);if(c<d-.01||c>y+.01)return!1;let P=dn(n,t,o),b=a[o],p=a[o+1];return mn(a,o,r,c),Fn(n,t,o),dn(n,t,o)>P?(a[o]=b,a[o+1]=p,!1):!0}function Be(n,t,o,e){let r=Math.abs(n.x-t.x)<Ut,c=Math.abs(o.x-e.x)<Ut;if(r===c)return!1;let[s,i,a,f]=r?[n,t,o,e]:[o,e,n,t],u=s.x,l=a.y;return u>Math.min(a.x,f.x)+Ut&&u<Math.max(a.x,f.x)-Ut&&l>Math.min(s.y,i.y)+Ut&&l<Math.max(s.y,i.y)-Ut}var ht=class ht{constructor(t){K(this,"cells",new Map);K(this,"seen",new Uint32Array(0));K(this,"stamp",0);this.seen=new Uint32Array(t.length),t.forEach((o,e)=>{for(let r=1;r<o.pts.length;r++)this.add(e,o.pts[r-1],o.pts[r])})}static cellOf(t){let o=Math.floor(t/ht.CELL);return Math.max(-ht.LIMIT,Math.min(ht.LIMIT,Number.isFinite(o)?o:0))}static key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=ht.cellOf(Math.min(o.x,e.x)),c=ht.cellOf(Math.max(o.x,e.x)),s=ht.cellOf(Math.min(o.y,e.y)),i=ht.cellOf(Math.max(o.y,e.y));for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=ht.key(f,a),l=this.cells.get(u);l?l.includes(t)||l.push(t):this.cells.set(u,[t])}}near(t,o,e,r,c){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=ht.cellOf(t),i=ht.cellOf(e),a=ht.cellOf(o),f=ht.cellOf(r);for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(ht.key(l,u));if(h)for(let m of h)this.seen[m]!==this.stamp&&(this.seen[m]=this.stamp,c.push(m))}return c}};K(ht,"CELL",200),K(ht,"LIMIT",28672);var Ln=ht,Nn=new WeakMap;function ze(n){let t=Nn.get(n);return t||(t=new Ln(n),Nn.set(n,t)),t}function Fn(n,t,o){let e=Nn.get(n);if(!e)return;let r=n[t].pts;for(let c=Math.max(1,o);c<=Math.min(r.length-1,o+2);c++)e.add(t,r[c-1],r[c])}var $e=[];function dn(n,t,o){let e=n[t].pts,r=0,c=Math.max(0,o-1),s=Math.min(e.length-2,o+1),i=1/0,a=1/0,f=-1/0,u=-1/0;for(let l=c;l<=s+1;l++)i=Math.min(i,e[l].x),a=Math.min(a,e[l].y),f=Math.max(f,e[l].x),u=Math.max(u,e[l].y);for(let l of ze(n).near(i,a,f,u,$e)){if(l===t)continue;let h=n[l].pts;for(let m=1;m<h.length;m++){let d=h[m-1],y=h[m];if(!(Math.max(d.x,y.x)<i||Math.min(d.x,y.x)>f||Math.max(d.y,y.y)<a||Math.min(d.y,y.y)>u))for(let P=c;P<=s;P++)Be(e[P],e[P+1],d,y)&&r++}}return r}function Dn(n,t,o){for(let e=0;e<n.length;e++){let r=n[e],c=r.pts,s=c.length-2;for(let i=1;i<s;i++){if(xn(c,i)!==t)continue;let a=c[i-1],f=c[i],u=c[i+1],l=c[i+2],h=ct(t,f),m=Math.sign(h-ct(t,a)),d=Math.sign(ct(t,l)-ct(t,u));if(m===0||m!==d)continue;let y=i-1===0?10:10,P=i+1===s?10:10,b=m>0?ct(t,a)+y:ct(t,l)+P,p=m>0?ct(t,l)-P:ct(t,a)-y;if(b>p)continue;let R=Math.max(Math.abs(b-h),Math.abs(p-h))+1,S=Math.min(st(t,f),st(t,u)),A=Math.max(st(t,f),st(t,u)),[w,C]=_n(o,r,t,h,S,A,16,R);if(b=Math.max(b,w),p=Math.min(p,C),b>p)continue;let v=(b+p)/2;if(Math.abs(v-h)<=.5)continue;let k=dn(n,e,i);mn(c,i,t,v),Fn(n,e,i),dn(n,e,i)>k&&mn(c,i,t,h)}}}function hn(n,t,o,e){return(st(e,n[t+1])-st(e,n[t]))*o>0?t+2>=n.length?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t+2])-ct(e,n[t+1])),next:t+1}:t===0?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t-1])-ct(e,n[t])),next:t-1}}function Un(n,t,o,e,r,c){let s=xn(n,t),i=(h,m)=>r>0?Math.max(st(s,h[m]),st(s,h[m+1])):Math.min(st(s,h[m]),st(s,h[m+1])),a=(i(n,t)-i(o,e))*r;if(a>.5){let h=hn(o,e,r,s).dir;return h===0?0:h>0?-1:1}if(a<-.5){let h=hn(n,t,r,s).dir;return h===0?0:h>0?1:-1}let f=hn(n,t,r,s),u=hn(o,e,r,s);if(f.dir===0||u.dir===0)return 0;if(f.dir!==u.dir)return f.dir<u.dir?-1:1;if(c>=8||f.next<0||u.next<0)return 0;let l=Un(n,f.next,o,u.next,f.dir,c+1);return l===0?0:-l*r*f.dir}function Tn(n,t,o){let e=Xe(n,t,o),r=e.length;if(r<2)return;let c=[],s=new Set,i=new Int32Array(r);for(let b=0;b<r;b++)i[b]=b;let a=b=>{for(;i[b]!==b;)i[b]=i[i[b]],b=i[b];return b},f=(b,p)=>{let R=a(b),S=a(p);R!==S&&(i[R<S?S:R]=R<S?R:S)},u=(b,p,R)=>{let S=b<p?b*r+p:p*r+b;if(s.has(S))return;s.add(S);let A=e[b],w=e[p],C=He(A,w),v=A.c<w.c||A.c===w.c&&b<p?-1:1;if(R){let lt=n[A.p].pts,q=n[w.p].pts,nt=Un(lt,A.k,q,w.k,1,0);nt===0&&(nt=Un(lt,A.k,q,w.k,-1,0)),nt===0&&(nt=Math.abs(A.c-w.c)>3?A.c<w.c?-1:1:Ke(n,A,w,t)),v=nt<0?-1:1}let k=n[A.p],N=n[w.p],U=k.src===N.src&&k.tgt===N.tgt||k.src===N.tgt&&k.tgt===N.src?30:C?24:12,[Y,G]=v<0?[A,w]:[w,A];Y.lb+U/2>G.ub&&G.lb+U/2<=Y.ub&&(v=v<0?1:-1),c.push({a:b,b:p,sep:U,order:v}),f(b,p)},l=e.map((b,p)=>p).sort((b,p)=>e[b].c-e[p].c||b-p);for(let b=0;b<r;b++){let p=e[l[b]];for(let R=b+1;R<r;R++){let S=e[l[R]];if(S.c-p.c>3)break;p.p!==S.p&&On(p,S)&&u(l[b],l[R],!0)}}let h=new Map;e.forEach((b,p)=>{for(let R of[b.keyA,b.keyB]){if(!R)continue;let S=h.get(R);S?S.push(p):h.set(R,[p])}});for(let b of h.values())for(let p=0;p<b.length;p++)for(let R=p+1;R<b.length;R++)e[b[p]].p!==e[b[R]].p&&u(b[p],b[R],!0);let m=new Float64Array(r);for(let b=0;b<r;b++)m[b]=Math.min(Math.max(e[b].c,e[b].lb),e[b].ub);let d=b=>{let p=new Map;for(let S=0;S<r;S++){let A=a(S);if(!b.has(A))continue;let w=p.get(A);w?w.push(S):p.set(A,[S])}let R=new Map;for(let S of c){let A=a(S.a);if(!b.has(A))continue;let w=R.get(A);w?w.push(S):R.set(A,[S])}return{members:p,groupRels:R}},y=(b,p)=>{if(b.length<2)return;let R=Ye(b,p,e,n),S=new Map,A=()=>(S.clear(),R.forEach((C,v)=>S.set(C,v)),p.map(C=>{let v=S.get(C.a)<S.get(C.b),k=v?C.a:C.b,N=v?C.b:C.a,B=C.order<0!==v;return{u:k,v:N,sep:Math.max(0,Math.min(C.sep,e[N].ub-e[k].lb)),broken:B}})),w=A();ue(R,w,e,0)||(R=[...b].sort((C,v)=>e[C].c-e[v].c||n[e[C].p].rank-n[e[v].p].rank||e[C].k-e[v].k),w=A()),qe(R,w,e,m)},P=new Set;for(let b=0;b<r;b++)P.add(a(b));{let{members:b,groupRels:p}=d(P);for(let R of P)y(b.get(R)??[],p.get(R)??[])}for(let b=0;b<8;b++){let p=new Set,R=e.map((k,N)=>N).sort((k,N)=>m[k]-m[N]||k-N);for(let k=0;k<r;k++){let N=R[k];for(let B=k+1;B<r;B++){let U=R[B];if(m[U]-m[N]>=12-.01)break;a(N)===a(U)||e[N].p===e[U].p||!On(e[N],e[U])||(u(N,U,Math.abs(e[N].c-e[U].c)<=3),p.add(a(N)))}}let S=[];for(let k=0;k<r;k++){let N=l[k];for(let B=k+1;B<r;B++){let U=l[B];if(e[U].c-e[N].c>40)break;let Y=N<U?N:U,G=N<U?U:N;if(a(Y)===a(G)||e[Y].p===e[G].p)continue;let lt=e[Y].c-e[G].c,q=m[Y]-m[G];lt*q>=0||!On(e[Y],e[G])||S.push(Y,G)}}let A=Array.from({length:S.length/2},(k,N)=>N).sort((k,N)=>S[2*k]-S[2*N]||S[2*k+1]-S[2*N+1]);for(let k of A){let N=S[2*k],B=S[2*k+1];a(N)!==a(B)&&(u(N,B,!1),p.add(a(N)))}if(!p.size)break;let w=new Set;for(let k of p)w.add(a(k));let{members:C,groupRels:v}=d(w);for(let k of w)y(C.get(k)??[],v.get(k)??[])}for(let b=0;b<r;b++){let p=e[b];Math.abs(m[b]-ct(t,n[p.p].pts[p.k]))>1e-6&&(mn(n[p.p].pts,p.k,t,m[b]),Fn(n,p.p,p.k))}}function On(n,t){return Math.min(n.hi,t.hi)-Math.max(n.lo,t.lo)>=-1}function He(n,t){return n.keyA!==""&&(n.keyA===t.keyA||n.keyA===t.keyB)||n.keyB!==""&&(n.keyB===t.keyA||n.keyB===t.keyB)}function Xe(n,t,o){let e=[],r=(c,s)=>`${c.id}\\0${s}`;for(let c=0;c<n.length;c++){let s=n[c],i=s.pts,a=i.length-2;for(let f=0;f<=a;f++){if(xn(i,f)!==t)continue;let u=ct(t,i[f]),l=Math.min(st(t,i[f]),st(t,i[f+1])),h=Math.max(st(t,i[f]),st(t,i[f+1]));if(h-l<Ut)continue;let[m,d]=_n(o,s,t,u,l,h,16,120),y="",P="";if(f===0){let[b,p]=Pt(s.src,s.srcSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),y=r(s.src,s.srcSide)}if(f===a){let[b,p]=Pt(s.tgt,s.tgtSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),P=r(s.tgt,s.tgtSide)}if(f===1){let b=ct(t,i[0]);Tt(s.srcSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}if(f===a-1){let b=ct(t,i[a+1]);Tt(s.tgtSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}for(let b of[f-2,f+2]){if(b<0||b>a)continue;let p=ct(t,i[b]),R=Math.abs(p-u),S=Math.max(0,(R-Math.min(R,10))/2);p<u?m=Math.max(m,u-S):p>u&&(d=Math.min(d,u+S))}e.push({p:c,k:f,c:u,lo:l,hi:h,keyA:y,keyB:P,lb:m,ub:d,w:y||P?3:1})}}return e}function Ke(n,t,o,e){let r=n[t.p].rank<=n[o.p].rank?t:o,c=n[r.p].pts,s=Math.sign(st(e,c[r.k+1])-st(e,c[r.k]))||1,a=(e?s:-s)<0;return(r===t?a:!a)?-1:1}function Ye(n,t,o,e){let r=n.length,c=new Map;n.forEach((l,h)=>c.set(l,h));let s=new Int32Array(r),i=Array.from({length:r},()=>[]);for(let l of t){let h=c.get(l.order<0?l.a:l.b),m=c.get(l.order<0?l.b:l.a);i[h].push(m),s[m]++}let a=(l,h)=>{let m=o[n[l]],d=o[n[h]];if(m.c!==d.c)return m.c<d.c;let y=e[m.p].rank,P=e[d.p].rank;return y!==P?y<P:m.k<d.k},f=new Uint8Array(r),u=[];for(let l=0;l<r;l++){let h=-1;for(let m=0;m<r;m++)f[m]||s[m]!==0||(h<0||a(m,h))&&(h=m);if(h<0)for(let m=0;m<r;m++)f[m]||(h<0||s[m]<s[h]||s[m]===s[h]&&a(m,h))&&(h=m);f[h]=1,u.push(n[h]);for(let m of i[h])s[m]--}return u}function qe(n,t,o,e){let r=Ze(n,t.filter(c=>!c.broken),o);for(let c of n)e[c]=Math.min(Math.max(o[c].c,o[c].lb),o[c].ub);for(let c=0;c<100;c++){let s=0;for(let{u:i,v:a,sep:f}of t){let u=f*r,l=e[i],h=e[a],m=u-(h-l);if(m<=.001)continue;m>s&&(s=m);let d=o[i],y=o[a],P=m*y.w/(d.w+y.w),b=m-P,p=l-d.lb,R=y.ub-h;P>p&&(b+=P-p,P=p),b>R&&(P=Math.min(p,P+(b-R)),b=R),e[i]=l-Math.max(0,P),e[a]=h+Math.max(0,b)}if(s<.05)break}}function ue(n,t,o,e){let r=new Map;for(let s of t){let i=r.get(s.v);i?i.push({u:s.u,sep:s.sep}):r.set(s.v,[{u:s.u,sep:s.sep}])}let c=new Map;for(let s of n){let i=o[s].lb;for(let{u:a,sep:f}of r.get(s)??[]){let u=c.get(a);u!==void 0&&(i=Math.max(i,u+f*e))}if(i>o[s].ub+1e-6)return!1;c.set(s,i)}return!0}function Ze(n,t,o){let e=s=>ue(n,t,o,s);if(e(1))return 1;let r=0,c=1;for(let s=0;s<10;s++){let i=(r+c)/2;e(i)?r=i:c=i}return r}var Qe=55,Je=18,gn={halfWidth:34,height:28,anchorRoom:8};function Jt(){let n={memo:null,searcher:new ln};return{route:t=>eo(n,t),reset:()=>{n.memo=null}}}var _t=n=>`${n.x},${n.y},${n.width},${n.height}`,Ft=58+2*12;function le(n,t,o){let e=Math.min(t.x,o.x),r=Math.min(t.y,o.y),c=Math.max(t.x+t.width,o.x+o.width),s=Math.max(t.y+t.height,o.y+o.height);for(let i of n)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x),s=Math.max(s,i.y);return{x0:e-Ft,y0:r-Ft,x1:c+Ft,y1:s+Ft}}function to(n,t,o){let e=n.length;for(let r=0;r<e;r++){let c=n[r],s=c.x+c.width,i=c.y+c.height,a=1/0,f=1/0;for(let u=0;u<e;u++){if(r===u)continue;let l=n[u];l.x>=s&&l.y<i-16&&c.y<l.y+l.height-16&&l.x<a&&(a=l.x),l.y>=i&&l.x<s-16&&c.x<l.x+l.width-16&&l.y<f&&(f=l.y)}a<1/0&&a-s>2*16&&t.push((s+a)/2),f<1/0&&f-i>2*16&&o.push((i+f)/2)}}function no(n){let t=Qe+Je*n.loopIndex,o=qt(n.sourceAnchor,n.sourceAnchor.side,20),e=qt(n.targetAnchor,n.targetAnchor.side,20),r=Math.min(o.x,e.x)-gn.anchorRoom,c=Math.max(o.x,e.x)+.75*t+gn.halfWidth,s=Math.min(o.y,e.y)-.75*t-gn.height,i=Math.max(o.y,e.y)+gn.anchorRoom;return{id:`${n.id}#loop`,x:r,y:s,width:c-r,height:i-s,kind:"annotation"}}function fe(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,hBlk:l,vBlk:h,hUse:m,vUse:d}=n,y=Vt(o),P=Tt(o),[b,p]=Pt(t,o),R=Qn(t,o),S=y===0?f:a,A=y===0?a:f,w=Nt(S,b-1),C=Rt(S,p+1);for(let v=w;v<=C;v++){let k=S[v],N=Jn(t,o,k),B=y===0?N.x:N.y,U,Y,G;if(P>0){if(U=Nt(A,B+10),U>=A.length)continue;Y=Math.max(0,Rt(A,B)),G=U-1}else{if(U=Rt(A,B-10),U<0)continue;Y=U,G=Math.min(A.length-1,Nt(A,B))-1}let lt=!0,q=0;for(let _=Y;_<=G&&lt;_++){let j=y===0?v*u+_:_*u+v;if(lt=(y===0?l[j]:h[j])===0,!lt)break;let z=y===0?m[j]:d[j];z&&(q+=.25*z*Math.abs(A[_+1]-A[_])),_>Y&&(y===0?j>=u&&d[j]>0&&d[j-u]>0:j%u>0&&m[j]>0&&m[j-1]>0)&&(q+=80*3)}if(!lt)continue;{let _=B-P*20,j=Math.min(_,B),z=Math.max(_,B);for(let L=Nt(A,j+.5);L<A.length&&A[L]<=z+.5;L++)(y===0?v>0&&d[v*u+L]>0&&d[(v-1)*u+L]>0:v>0&&m[L*u+v]>0&&m[L*u+v-1]>0)&&(q+=80*3)}if(c)for(let _ of c){if(_.other===s)continue;let j=1-Math.abs(k-_.c)/24;j>0&&(q+=400*j)}i&&(q+=i.side===o?2*Math.abs(k-i.c):100);let nt=y===0?v*u+U:U*u+v,at=k-R;r.push({side:o,c:k,point:N,node:nt,orient:y,dir:e?-P:P,cost:1.1*Math.abs(at)+.002*at*at+Math.abs(A[U]-B)+q,lane:v,legLo:Y,legHi:G})}}function he(n,t,o){let[e,r]=Pt(n,o),[c,s]=Pt(t,o),i=Math.max(e,c),a=Math.min(r,s);return i<=a?(i+a)/2:null}function pn(n,t,o,e=.01){let r=Vt(t),c=r===0?n.xs:n.ys,s=r===0?n.ys:n.xs,i=r===0?o.y:o.x,a=cn(s,i,e);if(a<0)return;let f=r===0?o.x:o.y,u=f-Tt(t)*20,l=Math.min(f,u),h=Math.max(f,u),m=Math.max(0,Rt(c,l)-1),d=Math.min(c.length-2,Nt(c,h)),{nx:y,hUse:P,vUse:b}=n;for(let p=m;p<=d;p++){if(c[p+1]<=l+.5||c[p]>=h-.5)continue;let R=r===0?a*y+p:p*y+a;r===0?P[R]<255&&P[R]++:b[R]<255&&b[R]++}}function me(n,t){let{nx:o,hUse:e,vUse:r}=n;for(let c=t.legLo;c<=t.legHi;c++)if(t.orient===0){let s=t.lane*o+c;e[s]<255&&e[s]++}else{let s=c*o+t.lane;r[s]<255&&r[s]++}}function Mn(n,t){switch(t){case"top":return{x0:n.x,y0:n.y-42,x1:n.x+n.width,y1:n.y};case"bottom":return{x0:n.x,y0:n.y+n.height,x1:n.x+n.width,y1:n.y+n.height+42};case"left":return{x0:n.x-42,y0:n.y,x1:n.x,y1:n.y+n.height};case"right":return{x0:n.x+n.width,y0:n.y,x1:n.x+n.width+42,y1:n.y+n.height}}}function Gn(n){let t=qt(n.sourceAnchor,n.sourceAnchor.side,20),o=qt(n.targetAnchor,n.targetAnchor.side,20),r=n.sourceAnchor.side==="left"||n.sourceAnchor.side==="right"?[t,{x:(t.x+o.x)/2,y:t.y},{x:(t.x+o.x)/2,y:o.y},o]:[t,{x:t.x,y:(t.y+o.y)/2},{x:o.x,y:(t.y+o.y)/2},o];return{sourceAnchor:n.sourceAnchor,targetAnchor:n.targetAnchor,points:$t(r)}}function de(n,t,o,e,r){let c=[];for(let s=1;s<n.length;s++){let i=n[s-1],a=n[s];e.query(Math.min(i.x,a.x),Math.min(i.y,a.y),Math.max(i.x,a.x),Math.max(i.y,a.y),c);for(let f of c)if(!(f>=o||r&&r.has(f))&&te(i,a,t[f],.5))return!0}return!1}var ye=n=>Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.width)&&Number.isFinite(n.height)&&n.width>=0&&n.height>=0,xe=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function eo(n,t){let o=t.obstacles.every(ye)?t.obstacles:t.obstacles.filter(ye),e=new Map;o.forEach((x,g)=>e.set(x.id,g));let r={lines:new Map,fallbacks:new Set,relaxed:new Map,stats:{gridX:0,gridY:0,pops:0,reused:0}},c=t.edges.filter(x=>!x.isSelfLoop&&x.source!==x.target&&e.has(x.source)&&e.has(x.target));if(!c.length)return r;let s=[...o];for(let x of t.edges)(x.isSelfLoop||x.source===x.target)&&e.has(x.source)&&xe(x.sourceAnchor)&&xe(x.targetAnchor)&&s.push(no(x));let i=new Map;[...c].sort((x,g)=>x.id<g.id?-1:x.id>g.id?1:0).forEach((x,g)=>i.set(x.id,g));let a=x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)];return Math.abs(g.x+g.width/2-M.x-M.width/2)+Math.abs(g.y+g.height/2-M.y-M.height/2)},f=[...c].sort((x,g)=>a(x)-a(g)||i.get(x.id)-i.get(g.id)),u=n.memo,l={rects:new Map(s.map(x=>[x.id,x])),routes:new Map},h=[];if(u){for(let x of s){let g=u.rects.get(x.id);(!g||_t(g)!==_t(x))&&(h.push(x),g&&h.push(g))}for(let[x,g]of u.rects)l.rects.has(x)||h.push(g)}let m=x=>{if(!u||h.length>s.length/2)return null;let g=u.routes.get(x.id);if(!g||g.srcKey!==_t(o[e.get(x.source)])||g.tgtKey!==_t(o[e.get(x.target)]))return null;for(let M of h){if(!(M.x<g.reach.x1&&M.x+M.width>g.reach.x0&&M.y<g.reach.y1&&M.y+M.height>g.reach.y0))continue;let E=M.x-Ft,I=M.y-Ft,O=M.x+M.width+Ft,D=M.y+M.height+Ft,W=g.pts;if(!W.length)return null;for(let Z=1;Z<W.length;Z++){let $=W[Z-1],X=W[Z];if(Math.max($.x,X.x)>E&&Math.min($.x,X.x)<O&&Math.max($.y,X.y)>I&&Math.min($.y,X.y)<D)return null}}return g},d=new Map,y=[];for(let x of f){let g=m(x);g?d.set(x.id,g):y.push(x)}let P=new Map,b=[],p=[];if(u&&h.length<=8){let x=(g,M,E)=>{let I=u.rects.get(g),O=o[e.get(g)];if(!I||I.width!==O.width||I.height!==O.height)return null;let D=M==="left"||M==="right",W=(D?E.y:E.x)-Wt(I,M)[0],[Z,$]=Pt(O,M),X=Math.min($,Math.max(Z,Wt(O,M)[0]+W));return(D?p:b).push(X),{side:M,c:X}};for(let g of y){let M=u.routes.get(g.id);!M||M.fallback||M.pts.length<2||P.set(g.id,{src:x(g.source,M.srcSide,M.pts[0]),tgt:x(g.target,M.tgtSide,M.pts[M.pts.length-1])})}}let R=2*30,S=new Set;for(let x of c)S.add(e.get(x.source)),S.add(e.get(x.target));let A=s.map(x=>({x0:x.x-16,y0:x.y-16,x1:x.x+x.width+16,y1:x.y+x.height+16})),w=1/0,C=1/0,v=-1/0,k=-1/0;for(let x of s)w=Math.min(w,x.x),C=Math.min(C,x.y),v=Math.max(v,x.x+x.width),k=Math.max(k,x.y+x.height);let N=c.map(x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)],E=[],I=[],O=he(g,M,"left");O!==null&&I.push(O);let D=he(g,M,"top");D!==null&&E.push(D),M.x>g.x+g.width?E.push((g.x+g.width+M.x)/2):g.x>M.x+M.width&&E.push((M.x+M.width+g.x)/2),M.y>g.y+g.height?I.push((g.y+g.height+M.y)/2):g.y>M.y+M.height&&I.push((M.y+M.height+g.y)/2);let W=Math.min(g.x,M.x),Z=Math.min(g.y,M.y);return{xs:E,ys:I,box:{id:x.id,x:W,y:Z,width:Math.max(g.x+g.width,M.x+M.width)-W,height:Math.max(g.y+g.height,M.y+M.height)-Z,kind:"annotation"}}}),B=(x,g,M,E)=>{let I=[...M,...b],O=[...E,...p],D=[],W=[],Z=[];for(let $ of x){let X=s[$];I.push(A[$].x0,A[$].x1),O.push(A[$].y0,A[$].y1),$<o.length&&(Z.push(X),S.has($)&&(D.push(X.x+X.width/2),W.push(X.y+X.height/2)))}to(Z,D,W);for(let $ of g)D.push(...N[$].xs),W.push(...N[$].ys);return{xs:wn(I,D,12),ys:wn(O,W,12)}},U=s.map((x,g)=>g),Y=s.length>150,G;if(Y)G=an(new Float64Array(0),new Float64Array(0));else{let{xs:x,ys:g}=B(U,c.map((M,E)=>E),[w-R,v+R],[C-R,k+R]);G=an(x,g),r.stats.gridX=G.nx,r.stats.gridY=G.ny;for(let M=0;M<s.length;M++)un(G,A[M].x0,A[M].y0,A[M].x1,A[M].y1,1)}let lt=(x,g)=>un(G,A[x].x0,A[x].y0,A[x].x1,A[x].y1,g),q=Y?new It(s,320):null,nt=Y?new It(N.map(x=>x.box),320):null,at=[],_=Y?new Bn(400):null,j=Y?o.flatMap(x=>Zt.map(g=>{let M=Mn(x,g);return{id:"",x:M.x0,y:M.y0,width:M.x1-M.x0,height:M.y1-M.y0,kind:"annotation"}})):null,z=Y?new It(j,320):null,L=Y?new Uint8Array(o.length*4):null,F=(x,g)=>{L&&(L[e.get(x.id)*4+Zt.indexOf(g)]=1)},V=[],Q=(x,g,M)=>{let E=Math.min(x.x,g.x)-M,I=Math.min(x.y,g.y)-M,O=Math.max(x.x+x.width,g.x+g.width)+M,D=Math.max(x.y+x.height,g.y+g.height)+M,W=E<=w-R&&I<=C-R&&O>=v+R&&D>=k+R;W&&(E=w-R,I=C-R,O=v+R,D=k+R),q.query(E,I,O,D,V);let Z=[];for(let ut of V){let tt=A[ut];tt.x1<E||tt.x0>O||tt.y1<I||tt.y0>D||Z.push(ut)}nt.query(E,I,O,D,V);let $=V.slice(),X=_.query(E,I,O,D),J=[E,O],rt=[I,D];for(let ut of X){let tt=at[ut].pts;for(let Bt=1;Bt<tt.length;Bt++){let mt=tt[Bt-1],zt=tt[Bt];Math.max(mt.x,zt.x)<E||Math.min(mt.x,zt.x)>O||Math.max(mt.y,zt.y)<I||Math.min(mt.y,zt.y)>D||(Math.abs(mt.y-zt.y)<.01&&mt.y>I&&mt.y<D?rt.push(mt.y):Math.abs(mt.x-zt.x)<.01&&mt.x>E&&mt.x<O&&J.push(mt.x))}}let{xs:dt,ys:ft}=B(Z,$,J,rt),Ot=E,en=I,on=O,rn=D;for(let ut of Z)Ot=Math.min(Ot,A[ut].x0),en=Math.min(en,A[ut].y0),on=Math.max(on,A[ut].x1),rn=Math.max(rn,A[ut].y1);let Zn=(ut,tt,Bt)=>ut.filter(mt=>mt>=tt-1e-6&&mt<=Bt+1e-6),Vn=Zn(dt,Ot,on),Wn=Zn(ft,en,rn);if(Vn.length*Wn.length>15e5)return null;let gt=an(Vn,Wn);for(let ut of Z)un(gt,A[ut].x0,A[ut].y0,A[ut].x1,A[ut].y1,1);let pt=1e9;Ot<E&&Ht(gt,-pt,-pt,E,pt,1),on>O&&Ht(gt,O,-pt,pt,pt,1),en<I&&Ht(gt,-pt,-pt,pt,I,1),rn>D&&Ht(gt,-pt,D,pt,pt,1),z.query(E,I,O,D,V);for(let ut of V){if(!L[ut])continue;let tt=j[ut];tt.x+tt.width<E||tt.x>O||tt.y+tt.height<I||tt.y>D||Qt(gt,tt.x,tt.y,tt.x+tt.width,tt.y+tt.height,1)}for(let ut of X){let tt=at[ut];kn(gt,tt.pts,1),pn(gt,tt.srcSide,tt.pts[0],1),pn(gt,tt.tgtSide,tt.pts[tt.pts.length-1],1)}return r.stats.gridX=Math.max(r.stats.gridX,gt.nx),r.stats.gridY=Math.max(r.stats.gridY,gt.ny),{grid:gt,whole:W,box:[E,I,O,D]}},T=[],ot=[],it=[],H=new Set,et=new Set,xt=[],Ct=new Map,Dt=(x,g,M,E)=>{let I=`${x.id}\\0${g}`,O=Ct.get(I);O?O.push({c:M,other:E}):Ct.set(I,[{c:M,other:E}])};for(let x of t.edges){if(!(x.isSelfLoop||x.source===x.target)||!e.has(x.source))continue;let g=o[e.get(x.source)];for(let M of[x.sourceAnchor,x.targetAnchor])Dt(g,M.side,M.side==="left"||M.side==="right"?M.y:M.x,"")}let kt=(x,g)=>{for(let M of Zt){if(!H.has(`${x.id}\\0${M}`))continue;let E=Mn(x,M);Qt(G,E.x0,E.y0,E.x1,E.y1,g)}},At=(x,g,M,E,I=!1)=>{T.length=0,ot.length=0;let O=o[x],D=o[g];for(let J of Zt)fe(G,O,J,!1,T,Ct.get(`${O.id}\\0${J}`),D.id,E?.src??null),fe(G,D,J,!0,ot,Ct.get(`${D.id}\\0${J}`),O.id,E?.tgt??null);if(!T.length||!ot.length)return null;let W=(J,rt)=>Ht(G,J.x-29,J.y-29,J.x+J.width+29,J.y+J.height+29,rt);kt(O,-1),g!==x&&kt(D,-1),W(O,1),g!==x&&W(D,1);let Z=Math.abs(O.x+O.width/2-D.x-D.width/2)+Math.abs(O.y+O.height/2-D.y-D.height/2),$=Math.min(1,Math.max(0,(Z-(Y?1200:1600))/1200)),X=n.searcher.search(G,T,ot,4e4,M,I?3:1.1+(Y?.9:.3)*$,I?80*.1:80*(1-(Y?.85:.7)*$));return W(O,-1),g!==x&&W(D,-1),kt(O,1),g!==x&&kt(D,1),r.stats.pops+=n.searcher.lastPops,X},Xt=(x,g,M,E,I,O)=>{let D=o[e.get(x.source)],W=o[e.get(x.target)];if(Y){let $=at.length;at.push({pts:g.map(X=>({x:X.x,y:X.y})),srcSide:M,tgtSide:E});for(let X=1;X<g.length;X++)_.add($,g[X-1],g[X])}else O?(ne(G,O.nodes),me(G,O.src),me(G,O.tgt)):kn(G,g),pn(G,M,g[0]),pn(G,E,g[g.length-1]);let Z=($,X)=>X==="left"||X==="right"?$.y:$.x;Dt(D,M,Z(g[0],M),W.id),Dt(W,E,Z(g[g.length-1],E),D.id);for(let[$,X]of[[D,M],[W,E]]){let J=`${$.id}\\0${X}`,rt=Mn($,X);H.has(J)||(H.add(J),F($,X),Y||Qt(G,rt.x0,rt.y0,rt.x1,rt.y1,1)),!et.has(J)&&(et.add(J),xt.push({id:`${J}#zone`,x:rt.x0,y:rt.y0,width:rt.x1-rt.x0,height:rt.y1-rt.y0,kind:"annotation"}))}I&&I.size&&r.relaxed.set(x.id,new Set([...I].map($=>o[$].id))),it.push({spec:x,path:{pts:g,src:D,srcSide:M,tgt:W,tgtSide:E,rank:i.get(x.id),ignore:I&&I.size?I:null,own:[e.get(x.source),e.get(x.target)]}}),l.routes.set(x.id,{srcKey:_t(D),tgtKey:_t(W),pts:g.slice(),srcSide:M,tgtSide:E,ignore:I&&I.size?[...I].map($=>o[$].id):null,fallback:!1,reach:le(g,D,W)})};for(let x of c)for(let[g,M]of[[x.source,x.sourceAnchor.side],[x.target,x.targetAnchor.side]]){let E=o[e.get(g)],I=`${E.id}\\0${M}`;if(H.has(I)||(H.add(I),F(E,M),Y))continue;let O=Mn(E,M);Qt(G,O.x0,O.y0,O.x1,O.y1,1)}for(let x of f){let g=d.get(x.id);if(!g)continue;if(r.stats.reused++,g.fallback){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,g);continue}let M=g.ignore?new Set(g.ignore.map(E=>e.get(E)).filter(E=>E!==void 0)):null;Xt(x,g.pts.map(E=>({x:E.x,y:E.y})),g.srcSide,g.tgtSide,M,null)}for(let x of y){let g=e.get(x.source),M=e.get(x.target),E=o[g],I=o[M],O=P.get(x.id),D=()=>At(g,M,!0,O)??null,W=()=>{let J=46,rt=new Set;for(let ft=0;ft<o.length;ft++)ft===g||ft===M||(sn(o[ft],0,E,J)||sn(o[ft],0,I,J))&&rt.add(ft);if(sn(E,0,I,J)&&(rt.add(g),rt.add(M)),!rt.size)return null;for(let ft of rt)lt(ft,-1);let dt=At(g,M,!1,O);for(let ft of rt)lt(ft,1);return dt?{found:dt,ignore:rt}:null},Z=null,$=null,X=null;if(Y){let J=400,rt=!1;for(;;){let dt=Q(E,I,J);if(!dt)break;G=dt.grid,rt=!0;let ft=D();if(ft){if(Z=ft,X=Rn(ft,G),dt.whole||!oo(X,dt.box))break}else if(n.searcher.lastPops>4e4){let Ot=At(g,M,!0,O,!0);Ot&&(Z=Ot,X=Rn(Ot,G));break}else if(dt.whole)break;J*=2.5}if(!Z&&rt){let dt=W();dt&&({found:Z,ignore:$}=dt,X=Rn(dt.found,G))}}else{if(Z=D(),!Z){let J=W();J&&({found:Z,ignore:$}=J)}Z&&(X=Rn(Z,G))}if(!Z){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,{srcKey:_t(E),tgtKey:_t(I),pts:[],srcSide:x.sourceAnchor.side,tgtSide:x.targetAnchor.side,ignore:null,fallback:!0,reach:le([],E,I)});continue}Xt(x,X,Z.src.side,Z.tgt.side,$&&$.size?$:null,Z)}n.memo=l,it.sort((x,g)=>x.path.rank-g.path.rank);let St=it.map(x=>x.path),vt=St.map(x=>x.pts.slice()),Kt=[...s,...xt],Yt={rects:Kt,buckets:new It(Kt),zoneFrom:s.length};ae(St,Yt),Dn(St,!0,Yt),Tn(St,!0,Yt),Dn(St,!1,Yt),Tn(St,!1,Yt);let qn=new It(s);return it.forEach(({spec:x,path:g},M)=>{let E=$t(g.pts);if((E.length<2||de(E,s,o.length,qn,g.ignore))&&(E=vt[M]),de(E,s,o.length,qn,g.ignore)){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x));return}r.lines.set(x.id,{sourceAnchor:En(E[0],g.srcSide),targetAnchor:En(E[E.length-1],g.tgtSide),points:E})}),r}function Rn(n,t){let o=[n.src.point];for(let e of n.nodes){let r=e%t.nx;o.push({x:t.xs[r],y:t.ys[(e-r)/t.nx]})}return o.push(n.tgt.point),$t(o)}function oo(n,t){let[o,e,r,c]=t;for(let s of n)if(s.x<=o+.5||s.y<=e+.5||s.x>=r-.5||s.y>=c-.5)return!0;return!1}var Bn=class{constructor(t){this.cell=t;K(this,"cells",new Map);K(this,"everywhere",new Set);K(this,"seen",new Uint32Array(64));K(this,"stamp",0)}key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=Math.floor(Math.min(o.x,e.x)/this.cell),c=Math.floor(Math.max(o.x,e.x)/this.cell),s=Math.floor(Math.min(o.y,e.y)/this.cell),i=Math.floor(Math.max(o.y,e.y)/this.cell);if(!Number.isFinite(r+c+s+i)||(c-r+1)*(i-s+1)>4096||Math.abs(r)>28672||Math.abs(c)>28672||Math.abs(s)>28672||Math.abs(i)>28672){this.everywhere.add(t);return}for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=this.key(f,a),l=this.cells.get(u);l?l[l.length-1]!==t&&l.push(t):this.cells.set(u,[t])}}query(t,o,e,r){let c=[...this.everywhere];++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=Math.max(-28672,Math.floor(t/this.cell)),i=Math.min(28672,Math.floor(e/this.cell)),a=Math.max(-28672,Math.floor(o/this.cell)),f=Math.min(28672,Math.floor(r/this.cell));if((i-s+1)*(f-a+1)>1<<20){let u=new Set(this.everywhere);for(let l of this.cells.values())for(let h of l)u.add(h);return[...u]}for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(this.key(l,u));if(h)for(let m of h){if(m>=this.seen.length){let d=new Uint32Array(Math.max(m+1,this.seen.length*2));d.set(this.seen),this.seen=d}this.seen[m]===this.stamp||this.everywhere.has(m)||(this.seen[m]=this.stamp,c.push(m))}}return c}};function zn(n){let t=[];for(let e=0;e<n.length;e++){let r=n[e];for(let c=0;c+1<r.length;c++){let s=r[c],i=r[c+1],a=Math.hypot(i.x-s.x,i.y-s.y);a<2*.75||t.push({line:e,seg:c,ax:s.x,ay:s.y,bx:i.x,by:i.y,len:a,minX:Math.min(s.x,i.x),maxX:Math.max(s.x,i.x),minY:Math.min(s.y,i.y),maxY:Math.max(s.y,i.y)})}}t.sort((e,r)=>e.minX-r.minX);let o=[];for(let e=0;e<t.length;e++){let r=t[e];for(let c=e+1;c<t.length;c++){let s=t[c];if(s.minX>r.maxX)break;if(s.line===r.line||s.minY>r.maxY||s.maxY<r.minY)continue;let i=r.bx-r.ax,a=r.by-r.ay,f=s.bx-s.ax,u=s.by-s.ay,l=i*u-a*f;if(Math.abs(l)<.02*r.len*s.len)continue;let h=s.ax-r.ax,m=s.ay-r.ay,d=(h*u-m*f)/l,y=(h*a-m*i)/l,P=d*r.len,b=y*s.len;P<=.75||P>=r.len-.75||b<=.75||b>=s.len-.75||o.push({x:r.ax+i*d,y:r.ay+a*d,a:{line:r.line,seg:r.seg,d:P},b:{line:s.line,seg:s.seg,d:b}})}}return o}function $n(n,t,o){let e=n.length,r=new Float64Array(Math.max(0,e-1));for(let i=0;i+1<e;i++)r[i]=Math.hypot(n[i+1].x-n[i].x,n[i+1].y-n[i].y);let c=new Float64Array(e),s=new Float64Array(e);if(t==="sharp")return{segLen:r,rIn:c,rOut:s};for(let i=1;i<e-1;i++){let a=r[i-1],f=r[i];if(t==="rounded"){let y=Math.min(8,a/2,f/2);c[i]=y,s[i]=y;continue}let u=i-1===0?a-4:a/2,l=i===e-2?f-4:f/2,h=Math.max(0,Math.min(40,u)),m=Math.max(0,Math.min(40,l)),d=Math.min(h,m);h=Math.min(h,d*2),m=Math.min(m,d*2),o&&o.length&&h>8&&([h,m]=so(n[i-1],n[i],n[i+1],h,m,o)),c[i]=h,s[i]=m}return{segLen:r,rIn:c,rOut:s}}function tn(n,t,o,e,r){let c=Math.hypot(t.x-n.x,t.y-n.y)||1,s=Math.hypot(o.x-t.x,o.y-t.y)||1,i={x:t.x-(t.x-n.x)/c*e,y:t.y-(t.y-n.y)/c*e},a={x:t.x+(o.x-t.x)/s*r,y:t.y+(o.y-t.y)/s*r},f={x:i.x+(t.x-i.x)*.5523,y:i.y+(t.y-i.y)*.5523},u={x:a.x+(t.x-a.x)*.5523,y:a.y+(t.y-a.y)*.5523};return{a:i,c1:f,c2:u,b:a}}var ro=[.2,.35,.5,.65,.8];function so(n,t,o,e,r,c){let s=Math.max(e,r)+6,i=[];for(let a of c)a.x>t.x+s||a.x+a.width<t.x-s||a.y>t.y+s||a.y+a.height<t.y-s||t.x>a.x-6&&t.x<a.x+a.width+6&&t.y>a.y-6&&t.y<a.y+a.height+6||i.push(a);if(!i.length)return[e,r];for(let a=0;a<5;a++){let{a:f,c1:u,c2:l,b:h}=tn(n,t,o,e,r),m=!1;for(let d of ro){let y=1-d,P=y*y*y*f.x+3*y*y*d*u.x+3*y*d*d*l.x+d*d*d*h.x,b=y*y*y*f.y+3*y*y*d*u.y+3*y*d*d*l.y+d*d*d*h.y;for(let p of i)if(P>p.x-6&&P<p.x+p.width+6&&b>p.y-6&&b<p.y+p.height+6){m=!0;break}if(m)break}if(!m)return[e,r];if(e*=.7,r*=.7,Math.max(e,r)<=8)break}return[Math.min(e,8),Math.min(r,8)]}var An=10,Hn=.75;function io(n,t,o,e,r,c,s){let i=1-s;return n==="rounded"?{x:i*i*t.x+2*i*s*c.x+s*s*r.x,y:i*i*t.y+2*i*s*c.y+s*s*r.y}:{x:i*i*i*t.x+3*i*i*s*o.x+3*i*s*s*e.x+s*s*s*r.x,y:i*i*i*t.y+3*i*i*s*o.y+3*i*s*s*e.y+s*s*s*r.y}}function be(n){let t=1/0,o=-1/0,e=1/0,r=-1/0;for(let c of n.pts)c.x<t&&(t=c.x),c.x>o&&(o=c.x),c.y<e&&(e=c.y),c.y>r&&(r=c.y);return{...n,minX:t,maxX:o,minY:e,maxY:r}}function Sn(n,t,o){if(o==="sharp")return[];let e=[],r=0;for(let s=0;s<n.length;s++){let i=n[s],a=t[s];for(let f=0;f+1<i.length;f++){let u=a.segLen[f];if(u<=0)continue;let l=a.rOut[f],h=u-a.rIn[f+1];if(h-l>2*Hn){let d=i[f],y=i[f+1],P=(y.x-d.x)/u,b=(y.y-d.y)/u;e.push(be({line:s,index:f,curve:!1,pts:[{x:d.x+P*l,y:d.y+b*l},{x:d.x+P*h,y:d.y+b*h}],offset:l}))}let m=f+1;if(m<i.length-1&&(a.rIn[m]>0||a.rOut[m]>0)){let d=tn(i[m-1],i[m],i[m+1],a.rIn[m],a.rOut[m]),y=[];for(let P=0;P<=An;P++)y.push(io(o,d.a,d.c1,d.c2,d.b,i[m],P/An));e.push(be({line:s,index:m,curve:!0,pts:y,offset:0})),r++}}}if(!r)return[];e.sort((s,i)=>s.minX-i.minX);let c=[];for(let s=0;s<e.length;s++){let i=e[s];for(let a=s+1;a<e.length;a++){let f=e[a];if(f.minX>i.maxX)break;if(i.curve===f.curve||i.line===f.line||f.minY>i.maxY||f.maxY<i.minY)continue;let u=i.curve?i:f,l=i.curve?f:i,[h,m]=l.pts,d=m.x-h.x,y=m.y-h.y,P=Math.hypot(d,y);for(let b=0;b<An;b++){let p=u.pts[b],R=u.pts[b+1],S=R.x-p.x,A=R.y-p.y,w=S*y-A*d;if(Math.abs(w)<1e-9)continue;let C=h.x-p.x,v=h.y-p.y,k=(C*y-v*d)/w,N=(C*A-v*S)/w;if(k<0||k>=1)continue;let B=N*P;B<=Hn||B>=P-Hn||c.push({x:h.x+d*N,y:h.y+y*N,straight:{line:l.line,seg:l.index,d:l.offset+B},curve:{line:u.line,vertex:u.index,t:(b+k)/An}})}}}return c}var Kn=6,ao=6,uo=14;function lo(n){let t=n&&Number.isFinite(n)&&n>0?n:1;return Math.min(uo,Math.max(Kn,ao/t))}var fo=4.5,Xn=3,ge=4,ho=4,pe=36,Me=16,mo=16;function yo(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=t[t.length-1],s=(c.x-r.x)*(o.y-r.y)-(c.y-r.y)*(o.x-r.x),i=(c.x-r.x)*(o.x-c.x)+(c.y-r.y)*(o.y-c.y);if(Math.abs(s)<.01&&i>=0){t[t.length-1]=o;continue}}t.push(o)}}return t}var Ae=(n,t=Kn)=>n==="hop"?t:fo;function xo(n,t){let o=n.segLen.length-1,e=n.rOut[t]+(t===0?ge:Xn),r=n.segLen[t]-n.rIn[t+1]-(t===o?ge:Xn);return[e,r]}function Pn(n,t){let o=n[t],e=n[t+1],r=Math.hypot(e.x-o.x,e.y-o.y);return r>0?Math.abs(e.x-o.x)/r:0}function bo(n,t,o,e,r,c,s){let i=Ae(r,s),a=t.map(()=>[]),f=r==="hop"?s:2,u=(h,m)=>{let[d,y]=xo(o[h.line],h.seg);return h.d-m>=d&&h.d+m<=y},l=h=>{let m=a[h.line][h.seg];m?m.push(h.d):a[h.line][h.seg]=[h.d]};for(let h of n){let m=Pn(t[h.a.line],h.a.seg),d=Pn(t[h.b.line],h.b.seg),y=Math.abs(m-d)>.001?m>d:e[h.a.line]>e[h.b.line],P=y?h.a:h.b,b=y?h.b:h.a,[p,R]=r==="hop"?[P,b]:[b,P];u(p,i)&&u(R,f)?l(p):u(R,i)&&u(p,f)&&l(R)}if(r!=="hop")for(let h of c)u(h.straight,i)&&l(h.straight);return a}function go(n,t){n.sort((e,r)=>e-r);let o=[];for(let e of n){let r=o[o.length-1];r&&e-t-r[1]<ho?r[1]=Math.max(r[1],e+t):o.push([e-t,e+t])}return o}var Re=n=>String(Math.round(n*100)/100),yt=n=>`${Re(n.x)},${Re(n.y)}`,Gt=(n,t)=>Math.hypot(t.x-n.x,t.y-n.y);function po(n,t){let o=t,e=-n;return Math.abs(e)>.05?e>0&&(o=-o,e=-e):o<0&&(o=-o,e=-e),{x:o,y:e}}function Mo(n,t){let{pieces:o}=n,e=0,r=o.length-1;for(;e<r;){let f=e+r>>1;o[f].pos1<t?e=f+1:r=f}let c=o[e],s=c.pos1-c.pos0,i=s>0?Math.min(1,Math.max(0,(t-c.pos0)/s)):0,a=1-i;switch(c.kind){case"L":return{x:c.a.x+(c.b.x-c.a.x)*i,y:c.a.y+(c.b.y-c.a.y)*i};case"Q":return{x:a*a*c.a.x+2*a*i*c.c.x+i*i*c.b.x,y:a*a*c.a.y+2*a*i*c.c.y+i*i*c.b.y};case"C":return{x:a*a*a*c.a.x+3*a*a*i*c.c1.x+3*a*i*i*c.c2.x+i*i*i*c.b.x,y:a*a*a*c.a.y+3*a*a*i*c.c1.y+3*a*i*i*c.c2.y+i*i*i*c.b.y}}}function Ro(n,t,o){let e=n.knots[t];if(!e||!e.length)return 0;let r=e[0];for(let c of e){if(c[0]>o)break;r=c}return r[1]+Math.max(0,o-r[0])}function Ao(n,t,o,e,r,c,s=Kn){let i=n.length;if(i===0)return{d:"",pieces:[],knots:[],cornerPos:[],length:0};let a=e??$n(n,t,o),f=`M ${yt(n[0])}`,u=null,l=[],h=[],m=[],d=0,y=n[0],P=r?Ae(r,s):0,b=R=>{f+=R,u!==null&&(u+=R)};for(let R=0;R+1<i;R++){let S=n[R],A=n[R+1],w=a.segLen[R];if(w<=0)continue;let C=(A.x-S.x)/w,v=(A.y-S.y)/w,k=q=>({x:S.x+C*q,y:S.y+v*q});if(R>0){let q=a.rIn[R],nt=a.rOut[R];if(q>0||nt>0){let at=n[R-1],_=tn(at,S,A,q,nt),j=d;t==="rounded"?(b(` Q ${yt(S)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,S)+Gt(S,_.b))/2,l.push({pos0:j,pos1:d,kind:"Q",a:y,c:S,b:_.b})):(b(` C ${yt(_.c1)} ${yt(_.c2)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,_.c1)+Gt(_.c1,_.c2)+Gt(_.c2,_.b))/2,l.push({pos0:j,pos1:d,kind:"C",a:y,c1:_.c1,c2:_.c2,b:_.b})),y=_.b,m[R]=[j,d]}}let N=a.rOut[R],B=w-a.rIn[R+1],U=N,Y=[[U,d]];h[R]=Y;let G=q=>{if(q<=U+1e-6)return;let nt=k(q);b(` L ${yt(nt)}`),l.push({pos0:d,pos1:d+(q-U),kind:"L",a:y,b:nt}),d+=q-U,U=q,y=nt},lt=r?c[R]:void 0;if(lt&&lt.length)for(let[q,nt]of go(lt,P)){G(q);let at=k(q),_=k(nt);if(r==="cut")u===null&&(u=f),f+=` L ${yt(_)}`,u+=` M ${yt(_)}`,l.push({pos0:d,pos1:d+(nt-q),kind:"L",a:at,b:_}),d+=nt-q;else{let j=po(C,v),z=s,L=.5523*z,F=(T,ot,it)=>({x:T.x+C*ot+j.x*it,y:T.y+v*ot+j.y*it}),V=Math.PI*z/2,Q=(T,ot,it,H)=>{b(` C ${yt(ot)} ${yt(it)} ${yt(H)}`),l.push({pos0:d,pos1:d+V,kind:"C",a:T,c1:ot,c2:it,b:H}),d+=V};if(nt-q<=2*z+.01){let T=F(at,z,z);Q(at,F(at,0,L),F(T,-L,0),T),Q(T,F(T,L,0),F(_,0,L),_)}else{let T=F(at,z,z),ot=F(_,-z,z);Q(at,F(at,0,L),F(T,-L,0),T),b(` L ${yt(ot)}`),l.push({pos0:d,pos1:d+(nt-q-2*z),kind:"L",a:T,b:ot}),d+=nt-q-2*z,Q(ot,F(ot,L,0),F(_,0,L),_)}}U=nt,y=_,Y.push([U,d])}G(B)}let p={d:f,pieces:l,knots:h,cornerPos:m,length:d};return u!==null&&(p.strokeD=u),p}function So(n,t){let o=n.length/2,e=Math.min(mo,n.length/2);t.push([-1/0,e],[n.length-e,1/0]),t.sort((i,a)=>i[0]-a[0]||i[1]-a[1]);let r=o,c=-1/0,s=-1/0;for(let[i,a]of t)if(i>s){if(c<o&&o<s)break;c=i,s=a}else s=Math.max(s,a);if(c<o&&o<s){let i=c>=e,a=s<=n.length-e;i&&(!a||o-c<=s-o)?r=c:a&&(r=s)}return Mo(n,r)}function Po(n,t,o,e){let r=e+Xn,c=2,s=(a,f,u)=>{let l=t[a],h=l.segLen[f];if(u<r||h-u<r)return;let m=Math.max(0,u-r),d=Math.max(0,h-u-r);f>0&&l.rOut[f]>m&&(l.rOut[f]=m,l.rIn[f]=Math.min(l.rIn[f],Math.max(m,8)*c)),f+1<n[a].length-1&&l.rIn[f+1]>d&&(l.rIn[f+1]=d,l.rOut[f+1]=Math.min(l.rOut[f+1],Math.max(d,8)*c))},i=zn(n);for(let a of i)s(a.a.line,a.a.seg,a.a.d),s(a.b.line,a.b.seg,a.b.d);if(o!=="curved")return{crossings:i,curveCrossings:Sn(n,t,o)};for(let a=0;;a++){let f=Sn(n,t,o);if(!f.length||a===3)return{crossings:i,curveCrossings:f};let u=!1;for(let l of f){let h=t[l.curve.line],m=l.curve.vertex;Math.max(h.rIn[m],h.rOut[m])<=8+.01||(h.rIn[m]=Math.max(Math.min(h.rIn[m],8),h.rIn[m]*.6),h.rOut[m]=Math.max(Math.min(h.rOut[m],8),h.rOut[m]*.6),u=!0)}if(!u)return{crossings:i,curveCrossings:f}}}var Eo=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function Se(n,t){let o=[...n.keys()].filter(y=>n.get(y).points.every(Eo)),e=o.map(y=>yo(n.get(y).points)),r=e.map(y=>$n(y,t.corners,t.obstacles)),c=lo(t.zoom),s=t.crossings==="hops"&&t.corners!=="sharp"&&e.length>1?Po(e,r,t.corners,c):null,i=y=>{let P=r[y.line];return y.d>=P.rOut[y.seg]&&y.d<=P.segLen[y.seg]-P.rIn[y.seg+1]},a=e.length>1?(s?.crossings??zn(e)).filter(y=>i(y.a)&&i(y.b)):[],f=e.length>1?s?.curveCrossings??Sn(e,r,t.corners):[],u=t.crossings==="hops"?"hop":t.crossings==="halo"?"cut":null,l=u?bo(a,e,r,o,u,f,c):e.map(()=>[]),h=e.map(()=>[]),m=e.map(()=>[]);for(let y of a)h[y.a.line].push(y.a),h[y.b.line].push(y.b);for(let y of f)h[y.straight.line].push(y.straight),m[y.curve.line].push(y.curve);let d=new Map;for(let y=0;y<o.length;y++){let P=e[y];if(P.length<2){let A=P[0]??{x:0,y:0};d.set(o[y],{d:`M ${yt(A)}`,mid:A,halo:t.crossings==="halo"?!0:void 0});continue}let b=Ao(P,t.corners,t.obstacles,r[y],u,l[y],c),p=h[y].map(A=>{let w=Ro(b,A.seg,A.d),C=Pn(P,A.seg)>.7?pe:Me;return[w-C,w+C]});for(let A of m[y]){let w=b.cornerPos[A.vertex];if(!w)continue;let C=w[0]+(w[1]-w[0])*A.t,v=Pn(P,A.t<.5?A.vertex-1:A.vertex)>.7?pe:Me;p.push([C-v,C+v])}let R=So(b,p),S={d:b.d,mid:R};t.crossings==="halo"&&(S.halo=!0),b.strokeD&&(S.strokeD=b.strokeD),d.set(o[y],S)}return d}function wo(n,t,o,e,r,c,s,i){let a=0,f=1,u=[-o,o,-e,e],l=[n-r,s-n,t-c,i-t];for(let h=0;h<4;h++){if(u[h]===0){if(l[h]<=0)return null;continue}let m=l[h]/u[h];if(u[h]<0){if(m>f)return null;m>a&&(a=m)}else{if(m<a)return null;m<f&&(f=m)}}return f>a?[a,f]:null}function Pe(n,t,o,e){let r=e;for(;r<n.length-2&&t[r+1]<o;)r++;let c=t[r+1]-t[r],s=c>0?(o-t[r])/c:0,i=n[r],a=n[r+1];return{p:{x:i.x+(a.x-i.x)*s,y:i.y+(a.y-i.y)*s},seg:r}}function Ee(n,t,o){let e=n.points;if(e.length<2||o.length===0)return[];let r=[0];for(let u=1;u<e.length;u++)r.push(r[u-1]+Math.hypot(e[u].x-e[u-1].x,e[u].y-e[u-1].y));let c=[];for(let u=0;u<e.length-1;u++){let l=e[u],h=e[u+1],m=r[u+1]-r[u];if(!(m>0)||!Number.isFinite(m))continue;let d=h.x-l.x,y=h.y-l.y,P=Math.min(l.x,h.x),b=Math.max(l.x,h.x),p=Math.min(l.y,h.y),R=Math.max(l.y,h.y);for(let S of o){let A=S.x+1,w=S.y+1,C=S.x+S.width-1,v=S.y+S.height-1;if(!(C>A)||!(v>w)||!Number.isFinite(C-A)||!Number.isFinite(v-w)||b<=A||P>=C||R<=w||p>=v||y===0&&(l.y-S.y<6||S.y+S.height-l.y<6)||d===0&&(l.x-S.x<6||S.x+S.width-l.x<6))continue;let k=wo(l.x,l.y,d,y,A,w,C,v);k&&c.push([r[u]+k[0]*m,r[u]+k[1]*m,S.id!==t?.source&&S.id!==t?.target])}}if(c.length===0)return[];c.sort((u,l)=>u[0]-l[0]);let s=[];for(let u of c){let l=s[s.length-1];l&&u[0]-l[1]<12?(u[1]>l[1]&&(l[1]=u[1]),u[2]&&(l[2]=!0)):s.push([u[0],u[1],u[2]])}let i=r[r.length-1];if(!Number.isFinite(i))return[];let a=[],f=0;for(let[u,l,h]of s){if(l-u<6||t&&!h&&(u<.5||l>i-.5))continue;let m=Pe(e,r,u,f),d=Pe(e,r,l,m.seg),y=[m.p];for(let P=m.seg+1;P<=d.seg;P++)y.push(e[P]);y.push(d.p),a.push(ko(y)),f=d.seg}return a}function ko(n){let t=[];for(let o of n){let e=t[t.length-1];e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01||t.push(o)}return t}function Yn(n,t,o){try{return n()}catch(e){return o(e),t}}function we(n,t,o={}){let e=o.now??(()=>0),r=o.onError??(()=>{}),c=o.router??Jt(),s=e(),i=Yn(()=>c.route(n).lines,new Map,l=>{c.reset(),r(l)}),a=Yn(()=>Se(i,{crossings:t.crossings,corners:t.corners,obstacles:n.obstacles,zoom:o.zoom??1}),new Map,r),f=new Map(n.edges.map(l=>[l.id,l])),u=new Map;for(let[l,h]of i){let m=a.get(l);if(!m)continue;let d=f.get(l),y=t.underTables==="xray"&&d?Yn(()=>Ee(h,d,n.obstacles),[],r):void 0,P={...h,d:m.d,mid:m.mid,halo:m.halo,tunnels:y&&y.length?y:void 0};m.strokeD&&(P.strokeD=m.strokeD),u.set(l,P)}return{edges:u,millis:e()-s}}var Co=Jt(),ke=self;ke.onmessage=n=>{let t=n.data;if(!t||t.type!=="route")return;let o,e=we(t.input,jn(t.style),{router:Co,now:()=>performance.now(),zoom:t.zoom,onError:r=>{o??(o=r instanceof Error?r.message:String(r))}});ke.postMessage({seq:t.seq,edges:e.edges,millis:e.millis,error:o})};})();\n'.length > 0 ? '"use strict";(()=>{var Ce=Object.defineProperty;var ve=(n,t,o)=>t in n?Ce(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var K=(n,t,o)=>ve(n,typeof t!="symbol"?t+"":t,o);var Oe="curved";function Ie(n){return n==="curved"||n==="hops"}var Le={curved:{crossings:"halo",underTables:"xray",corners:"curved"},hops:{crossings:"hops",underTables:"hidden",corners:"rounded"}};function jn(n){return Le[Ie(n)?n:Oe]}function qt(n,t,o){switch(t){case"top":return{x:n.x,y:n.y-o};case"bottom":return{x:n.x,y:n.y+o};case"left":return{x:n.x-o,y:n.y};case"right":return{x:n.x+o,y:n.y}}}var Zt=["right","left","bottom","top"];function Vt(n){return n==="left"||n==="right"?0:1}function Tt(n){return n==="right"||n==="bottom"?1:-1}function Ne(n,t){switch(t){case"left":return n.x;case"right":return n.x+n.width;case"top":return n.y;case"bottom":return n.y+n.height}}function Wt(n,t){return Vt(t)===0?[n.y,n.y+n.height]:[n.x,n.x+n.width]}function Pt(n,t){let[o,e]=Wt(n,t),r=Math.min(20,(e-o)/2);return[o+r,e-r]}function Qn(n,t){let[o,e]=Wt(n,t);return(o+e)/2}function Jn(n,t,o){let e=Ne(n,t)+Tt(t)*20;return Vt(t)===0?{x:e,y:o}:{x:o,y:e}}function En(n,t){switch(t){case"right":return{x:n.x-20,y:n.y,side:t};case"left":return{x:n.x+20,y:n.y,side:t};case"bottom":return{x:n.x,y:n.y-20,side:t};case"top":return{x:n.x,y:n.y+20,side:t}}}function sn(n,t,o,e){return n.x-t<o.x+o.width+e&&o.x-e<n.x+n.width+t&&n.y-t<o.y+o.height+e&&o.y-e<n.y+n.height+t}function $t(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=e,s=Math.abs(r.x-c.x)<.01&&Math.abs(c.x-o.x)<.01,i=Math.abs(r.y-c.y)<.01&&Math.abs(c.y-o.y)<.01;if(s||i){t[t.length-1]={x:o.x,y:o.y};continue}}t.push({x:o.x,y:o.y})}}return t}function te(n,t,o,e){let r=o.x+e,c=o.x+o.width-e,s=o.y+e,i=o.y+o.height-e;if(c<=r||i<=s)return!1;if(Math.abs(n.x-t.x)<.01){if(n.x<=r||n.x>=c)return!1;let a=Math.min(n.y,t.y),f=Math.max(n.y,t.y);return Math.min(f,i)-Math.max(a,s)>0}if(Math.abs(n.y-t.y)<.01){if(n.y<=s||n.y>=i)return!1;let a=Math.min(n.x,t.x),f=Math.max(n.x,t.x);return Math.min(f,c)-Math.max(a,r)>0}for(let a=.05;a<1;a+=.05){let f=n.x+(t.x-n.x)*a,u=n.y+(t.y-n.y)*a;if(f>r&&f<c&&u>s&&u<i)return!0}return!1}var It=class{constructor(t,o=160){this.rects=t;K(this,"x0");K(this,"y0");K(this,"cols");K(this,"rows");K(this,"cells");K(this,"seen");K(this,"stamp",0);K(this,"cell");let e=1/0,r=1/0,c=-1/0,s=-1/0;for(let i of t)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x+i.width),s=Math.max(s,i.y+i.height);t.length||(e=r=0,c=s=1),this.x0=e,this.y0=r,this.cell=Math.max(o,Math.max(c-e,s-r)/256),o=this.cell,this.cols=Math.max(1,Math.ceil((c-e)/o)+1),this.rows=Math.max(1,Math.ceil((s-r)/o)+1),this.cells=Array.from({length:this.cols*this.rows},()=>[]),this.seen=new Uint32Array(t.length),t.forEach((i,a)=>{let[f,u]=this.cellOf(i.x,i.y),[l,h]=this.cellOf(i.x+i.width,i.y+i.height);for(let m=u;m<=h;m++)for(let d=f;d<=l;d++)this.cells[m*this.cols+d].push(a)})}cellOf(t,o){let e=Math.min(this.cols-1,Math.max(0,Math.floor((t-this.x0)/this.cell))),r=Math.min(this.rows-1,Math.max(0,Math.floor((o-this.y0)/this.cell)));return[e,r]}query(t,o,e,r,c=[]){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let[s,i]=this.cellOf(t,o),[a,f]=this.cellOf(e,r);for(let u=i;u<=f;u++)for(let l=s;l<=a;l++)for(let h of this.cells[u*this.cols+l])this.seen[h]!==this.stamp&&(this.seen[h]=this.stamp,c.push(h));return c}};function Ue(n){let t=Float64Array.from(n.filter(r=>Number.isFinite(r))).sort(),o=[],e=-1/0;for(let r of t)r-e>1&&(o.push(r),e=r);return Float64Array.from(o)}function wn(n,t,o){let e=Array.from(Ue(n)),r=Float64Array.from(t.filter(a=>Number.isFinite(a))).sort(),c=[],s=0;for(let a of r){for(;s<e.length&&e[s]<a-o;)s++;s<e.length&&Math.abs(e[s]-a)<=o||s>0&&Math.abs(e[s-1]-a)<=o||c.length&&a-c[c.length-1]<=o||c.push(a)}return Float64Array.from([...e,...c]).sort()}function Rt(n,t){let o=0,e=n.length-1,r=-1;for(;o<=e;){let c=o+e>>1;n[c]<=t+1e-6?(r=c,o=c+1):e=c-1}return r}function Nt(n,t){let o=0,e=n.length-1,r=n.length;for(;o<=e;){let c=o+e>>1;n[c]>=t-1e-6?(r=c,e=c-1):o=c+1}return r}var Et=null;function an(n,t){let o=n.length*t.length;if(!Et||Et.hBlk.length<o){let r=Math.max(o,Math.ceil((Et?.hBlk.length??0)*1.5));Et={hBlk:new Uint16Array(r),vBlk:new Uint16Array(r),hUse:new Uint8Array(r),vUse:new Uint8Array(r),hZone:new Uint8Array(r),vZone:new Uint8Array(r)}}let e={xs:n,ys:t,nx:n.length,ny:t.length,hBlk:Et.hBlk.subarray(0,o),vBlk:Et.vBlk.subarray(0,o),hUse:Et.hUse.subarray(0,o),vUse:Et.vUse.subarray(0,o),hZone:Et.hZone.subarray(0,o),vZone:Et.vZone.subarray(0,o)};return e.hBlk.fill(0),e.vBlk.fill(0),e.hUse.fill(0),e.vUse.fill(0),e.hZone.fill(0),e.vZone.fill(0),e}function un(n,t,o,e,r,c){let s=Rt(n.xs,t),i=Rt(n.xs,e),a=Rt(n.ys,o),f=Rt(n.ys,r);if(s<0||a<0||i<=s||f<=a)return;let{nx:u,hBlk:l,vBlk:h}=n;for(let m=a+1;m<f;m++){let d=m*u;for(let y=s;y<i;y++)l[d+y]+=c}for(let m=a;m<f;m++){let d=m*u;for(let y=s+1;y<i;y++)h[d+y]+=c}}function ne(n,t){for(let o=1;o<t.length;o++){let e=t[o-1],r=t[o],c=e<r?e:r;Math.abs(e-r)===1?n.hUse[c]<255&&n.hUse[c]++:n.vUse[c]<255&&n.vUse[c]++}}function Lt(n,t){let o=0,e=n.length;for(;o<e;){let r=o+e>>1;n[r]>t?e=r:o=r+1}return o}function Qt(n,t,o,e,r,c){ee(n,n.hZone,n.vZone,t,o,e,r,c)}function Ht(n,t,o,e,r,c){ee(n,n.hBlk,n.vBlk,t,o,e,r,c)}function ee(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,ny:l}=n,h=.5,m=Lt(f,r+h),d=Lt(f,s-h)-1,y=Math.max(0,Lt(a,e+h)-1),P=Math.min(u-2,Lt(a,c-h-1e-9)-1);for(let A=m;A<=d&&A<l;A++){let w=A*u;for(let C=y;C<=P;C++)a[C+1]>e+h&&a[C]<c-h&&(t[w+C]+=i)}let b=Lt(a,e+h),p=Lt(a,c-h)-1,R=Math.max(0,Lt(f,r+h)-1),S=Math.min(l-2,Lt(f,s-h-1e-9)-1);for(let A=R;A<=S;A++){if(!(f[A+1]>r+h&&f[A]<s-h))continue;let w=A*u;for(let C=b;C<=p&&C<u;C++)o[w+C]+=i}}function cn(n,t,o){let e=Rt(n,t),r=-1,c=o;for(let s of[e,e+1]){if(s<0||s>=n.length)continue;let i=Math.abs(n[s]-t);i<=c&&(r=s,c=i)}return r}function kn(n,t,o=.01){let{xs:e,ys:r,nx:c,hUse:s,vUse:i}=n;for(let a=1;a<t.length;a++){let f=t[a-1],u=t[a];if(Math.abs(f.y-u.y)<.01){let l=cn(r,f.y,o);if(l<0)continue;let h=Math.max(0,Rt(e,Math.min(f.x,u.x))),m=Math.min(c-1,Nt(e,Math.max(f.x,u.x)));for(let d=h;d<m;d++)s[l*c+d]<255&&s[l*c+d]++}else if(Math.abs(f.x-u.x)<.01){let l=cn(e,f.x,o);if(l<0)continue;let h=Math.max(0,Rt(r,Math.min(f.y,u.y))),m=Math.min(n.ny-1,Nt(r,Math.max(f.y,u.y)));for(let d=h;d<m;d++)i[d*c+l]<255&&i[d*c+l]++}}}var re=(n,t)=>n*2+(t>0?0:1),vn=class{constructor(){K(this,"f",new Float64Array(1024));K(this,"g",new Float64Array(1024));K(this,"s",new Int32Array(1024));K(this,"size",0);K(this,"topF",0);K(this,"topG",0);K(this,"topS",0)}clear(){this.size=0}grow(){let t=this.f.length*2,o=new Float64Array(t),e=new Float64Array(t),r=new Int32Array(t);o.set(this.f),e.set(this.g),r.set(this.s),this.f=o,this.g=e,this.s=r}push(t,o,e){this.size===this.f.length&&this.grow();let r=this.size++,c=this.f,s=this.g,i=this.s;for(;r>0;){let a=r-1>>1;if(c[a]<t||c[a]===t&&s[a]>=e)break;c[r]=c[a],s[r]=s[a],i[r]=i[a],r=a}c[r]=t,s[r]=e,i[r]=o}pop(){let t=this.f,o=this.g,e=this.s;this.topF=t[0],this.topG=o[0],this.topS=e[0];let r=--this.size;if(r===0)return;let c=t[r],s=o[r],i=e[r],a=0;for(;;){let f=2*a+1;if(f>=r)break;let u=f+1,l=f;if(u<r&&(t[u]<t[f]||t[u]===t[f]&&o[u]>o[f])&&(l=u),t[l]>c||t[l]===c&&o[l]<=s)break;t[a]=t[l],o[a]=o[l],e[a]=e[l],a=l}t[a]=c,o[a]=s,e[a]=i}},ln=class{constructor(){K(this,"cap",0);K(this,"gScore",new Float64Array(0));K(this,"stamp",new Uint32Array(0));K(this,"parent",new Int32Array(0));K(this,"seedOf",new Int32Array(0));K(this,"goalStamp",new Uint32Array(0));K(this,"goalOf",new Int32Array(0));K(this,"id",0);K(this,"heap",new vn);K(this,"lastPops",0);K(this,"targetBuf",new Float64Array(20));K(this,"zeroBuf",new Uint8Array(0))}zeros(t){return this.zeroBuf.length<t&&(this.zeroBuf=new Uint8Array(t)),this.zeroBuf}ensure(t){if(t*4<=this.cap)return;let o=Math.max(t*4,Math.ceil(this.cap*1.5));this.cap=o,this.gScore=new Float64Array(o),this.stamp=new Uint32Array(o),this.parent=new Int32Array(o),this.seedOf=new Int32Array(o),this.goalStamp=new Uint32Array(o>>2),this.goalOf=new Int32Array(o>>2),this.id=0}search(t,o,e,r,c=!0,s=1.1,i=80){let{xs:a,ys:f,nx:u,ny:l,hBlk:h,vBlk:m,hUse:d,vUse:y}=t,P=c?t.hZone:this.zeros(u*l),b=c?t.vZone:this.zeros(u*l),p=2,R=0;this.ensure(u*l),++this.id>=4294967280&&(this.stamp.fill(0),this.goalStamp.fill(0),this.id=1);let S=this.id,{gScore:A,stamp:w,parent:C,seedOf:v,goalStamp:k,goalOf:N,heap:B}=this;B.clear(),this.lastPops=0;let U=this.targetBuf,Y=0;for(let z=0;z<e.length;z++){let L=e[z],F=L.node;(k[F]!==S||L.cost<e[N[F]].cost)&&(k[F]=S,N[F]=z);let V=L.orient===0?1:0,Q=L.dir,T=0;for(;T<Y&&!(U[T*5]===V&&U[T*5+1]===Q);)T++;T===Y?(U[T*5]=V,U[T*5+1]=Q,U[T*5+2]=(V?L.point.x:L.point.y)*Q,U[T*5+3]=L.c,U[T*5+4]=L.c,Y++):(L.c<U[T*5+3]&&(U[T*5+3]=L.c),L.c>U[T*5+4]&&(U[T*5+4]=L.c))}let G=s,lt=(z,L,F)=>{let V=F<2?1:0,Q=F&1?-1:1,T=1/0;for(let ot=0;ot<Y;ot++){let it=ot*5,H=U[it],et=U[it+1],xt=U[it+2],Ct=U[it+3],Dt=U[it+4],kt=(H?z:L)*et,At=H?L:z,Xt=kt<xt-.5,St=At<Ct?Ct-At:At>Dt?At-Dt:0,vt;V===H?Q*et>0?vt=Xt?St===0?0:2:4:vt=2:Xt?St===0?vt=1:vt=At<Ct&&Q>0||At>Dt&&Q<0?1:3:vt=3;let Kt=(xt>kt?xt-kt:kt-xt)+St+vt*40;Kt<T&&(T=Kt)}return T*G};for(let z=0;z<o.length;z++){let L=o[z],F=re(L.orient,L.dir),V=L.node*4+F;if(w[V]===S&&A[V]<=L.cost)continue;w[V]=S,A[V]=L.cost,C[V]=-1,v[V]=z;let Q=L.node%u;B.push(L.cost+lt(a[Q],f[(L.node-Q)/u],F),V,L.cost)}let q=0,nt=0,at=0,_=0,j=(z,L,F,V,Q,T,ot,it)=>{let H=at+Q*(1+.25*T+(it?p:0))+(V>>1!==_>>1?40:0)+(ot?i:0),et=z*4+V;w[et]===S&&H>=A[et]-1e-9||(w[et]=S,A[et]=H,C[et]=nt,B.push(H+lt(L,F,V),et,H))};for(;B.size>0;){B.pop();let z=B.topS;if(z<0)return this.lastPops=q,this.build(-1-z,o,e,B.topF);let L=B.topG;if(L>A[z]+1e-9)continue;if(++q>r)return this.lastPops=q,null;let F=z>>2,V=z&3;if(nt=z,at=L,_=V,k[F]===S){let H=e[N[F]],et=re(H.orient,H.dir),xt=-1;V===et?xt=L+H.cost:V>>1!==et>>1&&(xt=L+40+H.cost),xt>=0&&B.push(xt,-1-z,xt)}let Q=F%u,T=(F-Q)/u,ot=a[Q],it=f[T];if(V!==1&&Q+1<u&&h[F]===0&&!(P[F]&R)){let H=F+1,et=a[Q+1];j(H,et,it,0,et-ot,d[F],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F])}if(V!==0&&Q>0&&h[F-1]===0&&!(P[F-1]&R)){let H=F-1,et=a[Q-1];j(H,et,it,1,ot-et,d[H],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F-1])}if(V!==3&&T+1<l&&m[F]===0&&!(b[F]&R)){let H=F+u,et=f[T+1];j(H,ot,et,2,et-it,y[F],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F])}if(V!==2&&T>0&&m[F-u]===0&&!(b[F-u]&R)){let H=F-u,et=f[T-1];j(H,ot,et,3,it-et,y[H],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F-u])}}return this.lastPops=q,null}build(t,o,e,r){let c=[],s=t,i=o[0];for(let f=0;f<1e6;f++){c.push(s>>2);let u=this.parent[s];if(u<0){i=o[this.seedOf[s]];break}s=u}c.reverse();let a=e[this.goalOf[t>>2]];return{nodes:c,src:i,tgt:a,cost:r}}};var Ut=.01,ie=[];function xn(n,t){return Math.abs(n[t].x-n[t+1].x)<Ut}var ct=(n,t)=>n?t.x:t.y,st=(n,t)=>n?t.y:t.x;function _n(n,t,o,e,r,c,s,i){let a=e-i,f=e+i,u=o?n.buckets.query(e-i-s,r-s,e+i+s,c+s,ie):n.buckets.query(r-s,e-i-s,c+s,e+i+s,ie),l=t.ignore;for(let h=0;h<u.length;h++){let m=u[h];if(l&&l.has(m))continue;let d=n.rects[m],y=m>=n.zoneFrom?1:m===t.own[0]||m===t.own[1]?Math.max(s,29):s,P=o?d.y:d.x;if((o?d.y+d.height:d.x+d.width)+y<=r+.5||P-y>=c-.5)continue;let p=o?d.x:d.y,R=o?d.x+d.width:d.y+d.height;R<=e+.5?R+y>a&&(a=R+y):p>=e-.5&&p-y<f&&(f=p-y)}return[Math.min(a,e),Math.max(f,e)]}function mn(n,t,o,e){o?(n[t]={x:e,y:n[t].y},n[t+1]={x:e,y:n[t+1].y}):(n[t]={x:n[t].x,y:e},n[t+1]={x:n[t+1].x,y:e})}function ae(n,t){for(let o=0;o<n.length;o++){let e=n[o];for(let r=0;r<12&&Ge(n,o,t);r++)e.pts=$t(e.pts)}}function Ge(n,t,o){let e=n[t].pts,r=e.length-2;for(let c=1;c<r;c++){let s=!xn(e,c),i=Math.sign(st(s,e[c])-st(s,e[c-1])),a=Math.sign(st(s,e[c+2])-st(s,e[c+1]));if(!(i===0||i!==a)&&(ce(n,t,c-1,-1,s,ct(s,e[c+1]),o)||ce(n,t,c+1,1,s,ct(s,e[c]),o)))return!0}return!1}function ce(n,t,o,e,r,c,s){let i=n[t],a=i.pts,f=a.length-2,u=ct(r,a[o]);if(Math.abs(c-u)<.5)return!1;let l=o+e;if(l<0||l>f){let[R,S]=o===0?Pt(i.src,i.srcSide):Pt(i.tgt,i.tgtSide);if(c<R-.01||c>S+.01)return!1}else{let R=e<0?a[o-1]:a[o+2],S=e<0?a[o]:a[o+1],A=ct(r,S)-ct(r,R),w=c-ct(r,R);if(A===0||Math.sign(A)!==Math.sign(w))return!1;let C=l===0||l===f;if(Math.abs(w)<(C?10:10)-.01)return!1}let h=Math.min(st(r,a[o]),st(r,a[o+1])),m=Math.max(st(r,a[o]),st(r,a[o+1])),[d,y]=_n(s,i,r,u,h,m,16,Math.abs(c-u)+1);if(c<d-.01||c>y+.01)return!1;let P=dn(n,t,o),b=a[o],p=a[o+1];return mn(a,o,r,c),Fn(n,t,o),dn(n,t,o)>P?(a[o]=b,a[o+1]=p,!1):!0}function Be(n,t,o,e){let r=Math.abs(n.x-t.x)<Ut,c=Math.abs(o.x-e.x)<Ut;if(r===c)return!1;let[s,i,a,f]=r?[n,t,o,e]:[o,e,n,t],u=s.x,l=a.y;return u>Math.min(a.x,f.x)+Ut&&u<Math.max(a.x,f.x)-Ut&&l>Math.min(s.y,i.y)+Ut&&l<Math.max(s.y,i.y)-Ut}var ht=class ht{constructor(t){K(this,"cells",new Map);K(this,"seen",new Uint32Array(0));K(this,"stamp",0);this.seen=new Uint32Array(t.length),t.forEach((o,e)=>{for(let r=1;r<o.pts.length;r++)this.add(e,o.pts[r-1],o.pts[r])})}static cellOf(t){let o=Math.floor(t/ht.CELL);return Math.max(-ht.LIMIT,Math.min(ht.LIMIT,Number.isFinite(o)?o:0))}static key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=ht.cellOf(Math.min(o.x,e.x)),c=ht.cellOf(Math.max(o.x,e.x)),s=ht.cellOf(Math.min(o.y,e.y)),i=ht.cellOf(Math.max(o.y,e.y));for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=ht.key(f,a),l=this.cells.get(u);l?l.includes(t)||l.push(t):this.cells.set(u,[t])}}near(t,o,e,r,c){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=ht.cellOf(t),i=ht.cellOf(e),a=ht.cellOf(o),f=ht.cellOf(r);for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(ht.key(l,u));if(h)for(let m of h)this.seen[m]!==this.stamp&&(this.seen[m]=this.stamp,c.push(m))}return c}};K(ht,"CELL",200),K(ht,"LIMIT",28672);var Ln=ht,Nn=new WeakMap;function ze(n){let t=Nn.get(n);return t||(t=new Ln(n),Nn.set(n,t)),t}function Fn(n,t,o){let e=Nn.get(n);if(!e)return;let r=n[t].pts;for(let c=Math.max(1,o);c<=Math.min(r.length-1,o+2);c++)e.add(t,r[c-1],r[c])}var $e=[];function dn(n,t,o){let e=n[t].pts,r=0,c=Math.max(0,o-1),s=Math.min(e.length-2,o+1),i=1/0,a=1/0,f=-1/0,u=-1/0;for(let l=c;l<=s+1;l++)i=Math.min(i,e[l].x),a=Math.min(a,e[l].y),f=Math.max(f,e[l].x),u=Math.max(u,e[l].y);for(let l of ze(n).near(i,a,f,u,$e)){if(l===t)continue;let h=n[l].pts;for(let m=1;m<h.length;m++){let d=h[m-1],y=h[m];if(!(Math.max(d.x,y.x)<i||Math.min(d.x,y.x)>f||Math.max(d.y,y.y)<a||Math.min(d.y,y.y)>u))for(let P=c;P<=s;P++)Be(e[P],e[P+1],d,y)&&r++}}return r}function Dn(n,t,o){for(let e=0;e<n.length;e++){let r=n[e],c=r.pts,s=c.length-2;for(let i=1;i<s;i++){if(xn(c,i)!==t)continue;let a=c[i-1],f=c[i],u=c[i+1],l=c[i+2],h=ct(t,f),m=Math.sign(h-ct(t,a)),d=Math.sign(ct(t,l)-ct(t,u));if(m===0||m!==d)continue;let y=i-1===0?10:10,P=i+1===s?10:10,b=m>0?ct(t,a)+y:ct(t,l)+P,p=m>0?ct(t,l)-P:ct(t,a)-y;if(b>p)continue;let R=Math.max(Math.abs(b-h),Math.abs(p-h))+1,S=Math.min(st(t,f),st(t,u)),A=Math.max(st(t,f),st(t,u)),[w,C]=_n(o,r,t,h,S,A,16,R);if(b=Math.max(b,w),p=Math.min(p,C),b>p)continue;let v=(b+p)/2;if(Math.abs(v-h)<=.5)continue;let k=dn(n,e,i);mn(c,i,t,v),Fn(n,e,i),dn(n,e,i)>k&&mn(c,i,t,h)}}}function hn(n,t,o,e){return(st(e,n[t+1])-st(e,n[t]))*o>0?t+2>=n.length?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t+2])-ct(e,n[t+1])),next:t+1}:t===0?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t-1])-ct(e,n[t])),next:t-1}}function Un(n,t,o,e,r,c){let s=xn(n,t),i=(h,m)=>r>0?Math.max(st(s,h[m]),st(s,h[m+1])):Math.min(st(s,h[m]),st(s,h[m+1])),a=(i(n,t)-i(o,e))*r;if(a>.5){let h=hn(o,e,r,s).dir;return h===0?0:h>0?-1:1}if(a<-.5){let h=hn(n,t,r,s).dir;return h===0?0:h>0?1:-1}let f=hn(n,t,r,s),u=hn(o,e,r,s);if(f.dir===0||u.dir===0)return 0;if(f.dir!==u.dir)return f.dir<u.dir?-1:1;if(c>=8||f.next<0||u.next<0)return 0;let l=Un(n,f.next,o,u.next,f.dir,c+1);return l===0?0:-l*r*f.dir}function Tn(n,t,o){let e=Xe(n,t,o),r=e.length;if(r<2)return;let c=[],s=new Set,i=new Int32Array(r);for(let b=0;b<r;b++)i[b]=b;let a=b=>{for(;i[b]!==b;)i[b]=i[i[b]],b=i[b];return b},f=(b,p)=>{let R=a(b),S=a(p);R!==S&&(i[R<S?S:R]=R<S?R:S)},u=(b,p,R)=>{let S=b<p?b*r+p:p*r+b;if(s.has(S))return;s.add(S);let A=e[b],w=e[p],C=He(A,w),v=A.c<w.c||A.c===w.c&&b<p?-1:1;if(R){let lt=n[A.p].pts,q=n[w.p].pts,nt=Un(lt,A.k,q,w.k,1,0);nt===0&&(nt=Un(lt,A.k,q,w.k,-1,0)),nt===0&&(nt=Math.abs(A.c-w.c)>3?A.c<w.c?-1:1:Ke(n,A,w,t)),v=nt<0?-1:1}let k=n[A.p],N=n[w.p],U=k.src===N.src&&k.tgt===N.tgt||k.src===N.tgt&&k.tgt===N.src?30:C?24:12,[Y,G]=v<0?[A,w]:[w,A];Y.lb+U/2>G.ub&&G.lb+U/2<=Y.ub&&(v=v<0?1:-1),c.push({a:b,b:p,sep:U,order:v}),f(b,p)},l=e.map((b,p)=>p).sort((b,p)=>e[b].c-e[p].c||b-p);for(let b=0;b<r;b++){let p=e[l[b]];for(let R=b+1;R<r;R++){let S=e[l[R]];if(S.c-p.c>3)break;p.p!==S.p&&On(p,S)&&u(l[b],l[R],!0)}}let h=new Map;e.forEach((b,p)=>{for(let R of[b.keyA,b.keyB]){if(!R)continue;let S=h.get(R);S?S.push(p):h.set(R,[p])}});for(let b of h.values())for(let p=0;p<b.length;p++)for(let R=p+1;R<b.length;R++)e[b[p]].p!==e[b[R]].p&&u(b[p],b[R],!0);let m=new Float64Array(r);for(let b=0;b<r;b++)m[b]=Math.min(Math.max(e[b].c,e[b].lb),e[b].ub);let d=b=>{let p=new Map;for(let S=0;S<r;S++){let A=a(S);if(!b.has(A))continue;let w=p.get(A);w?w.push(S):p.set(A,[S])}let R=new Map;for(let S of c){let A=a(S.a);if(!b.has(A))continue;let w=R.get(A);w?w.push(S):R.set(A,[S])}return{members:p,groupRels:R}},y=(b,p)=>{if(b.length<2)return;let R=Ye(b,p,e,n),S=new Map,A=()=>(S.clear(),R.forEach((C,v)=>S.set(C,v)),p.map(C=>{let v=S.get(C.a)<S.get(C.b),k=v?C.a:C.b,N=v?C.b:C.a,B=C.order<0!==v;return{u:k,v:N,sep:Math.max(0,Math.min(C.sep,e[N].ub-e[k].lb)),broken:B}})),w=A();ue(R,w,e,0)||(R=[...b].sort((C,v)=>e[C].c-e[v].c||n[e[C].p].rank-n[e[v].p].rank||e[C].k-e[v].k),w=A()),qe(R,w,e,m)},P=new Set;for(let b=0;b<r;b++)P.add(a(b));{let{members:b,groupRels:p}=d(P);for(let R of P)y(b.get(R)??[],p.get(R)??[])}for(let b=0;b<8;b++){let p=new Set,R=e.map((k,N)=>N).sort((k,N)=>m[k]-m[N]||k-N);for(let k=0;k<r;k++){let N=R[k];for(let B=k+1;B<r;B++){let U=R[B];if(m[U]-m[N]>=12-.01)break;a(N)===a(U)||e[N].p===e[U].p||!On(e[N],e[U])||(u(N,U,Math.abs(e[N].c-e[U].c)<=3),p.add(a(N)))}}let S=[];for(let k=0;k<r;k++){let N=l[k];for(let B=k+1;B<r;B++){let U=l[B];if(e[U].c-e[N].c>40)break;let Y=N<U?N:U,G=N<U?U:N;if(a(Y)===a(G)||e[Y].p===e[G].p)continue;let lt=e[Y].c-e[G].c,q=m[Y]-m[G];lt*q>=0||!On(e[Y],e[G])||S.push(Y,G)}}let A=Array.from({length:S.length/2},(k,N)=>N).sort((k,N)=>S[2*k]-S[2*N]||S[2*k+1]-S[2*N+1]);for(let k of A){let N=S[2*k],B=S[2*k+1];a(N)!==a(B)&&(u(N,B,!1),p.add(a(N)))}if(!p.size)break;let w=new Set;for(let k of p)w.add(a(k));let{members:C,groupRels:v}=d(w);for(let k of w)y(C.get(k)??[],v.get(k)??[])}for(let b=0;b<r;b++){let p=e[b];Math.abs(m[b]-ct(t,n[p.p].pts[p.k]))>1e-6&&(mn(n[p.p].pts,p.k,t,m[b]),Fn(n,p.p,p.k))}}function On(n,t){return Math.min(n.hi,t.hi)-Math.max(n.lo,t.lo)>=-1}function He(n,t){return n.keyA!==""&&(n.keyA===t.keyA||n.keyA===t.keyB)||n.keyB!==""&&(n.keyB===t.keyA||n.keyB===t.keyB)}function Xe(n,t,o){let e=[],r=(c,s)=>`${c.id}\\0${s}`;for(let c=0;c<n.length;c++){let s=n[c],i=s.pts,a=i.length-2;for(let f=0;f<=a;f++){if(xn(i,f)!==t)continue;let u=ct(t,i[f]),l=Math.min(st(t,i[f]),st(t,i[f+1])),h=Math.max(st(t,i[f]),st(t,i[f+1]));if(h-l<Ut)continue;let[m,d]=_n(o,s,t,u,l,h,16,120),y="",P="";if(f===0){let[b,p]=Pt(s.src,s.srcSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),y=r(s.src,s.srcSide)}if(f===a){let[b,p]=Pt(s.tgt,s.tgtSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),P=r(s.tgt,s.tgtSide)}if(f===1){let b=ct(t,i[0]);Tt(s.srcSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}if(f===a-1){let b=ct(t,i[a+1]);Tt(s.tgtSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}for(let b of[f-2,f+2]){if(b<0||b>a)continue;let p=ct(t,i[b]),R=Math.abs(p-u),S=Math.max(0,(R-Math.min(R,10))/2);p<u?m=Math.max(m,u-S):p>u&&(d=Math.min(d,u+S))}e.push({p:c,k:f,c:u,lo:l,hi:h,keyA:y,keyB:P,lb:m,ub:d,w:y||P?3:1})}}return e}function Ke(n,t,o,e){let r=n[t.p].rank<=n[o.p].rank?t:o,c=n[r.p].pts,s=Math.sign(st(e,c[r.k+1])-st(e,c[r.k]))||1,a=(e?s:-s)<0;return(r===t?a:!a)?-1:1}function Ye(n,t,o,e){let r=n.length,c=new Map;n.forEach((l,h)=>c.set(l,h));let s=new Int32Array(r),i=Array.from({length:r},()=>[]);for(let l of t){let h=c.get(l.order<0?l.a:l.b),m=c.get(l.order<0?l.b:l.a);i[h].push(m),s[m]++}let a=(l,h)=>{let m=o[n[l]],d=o[n[h]];if(m.c!==d.c)return m.c<d.c;let y=e[m.p].rank,P=e[d.p].rank;return y!==P?y<P:m.k<d.k},f=new Uint8Array(r),u=[];for(let l=0;l<r;l++){let h=-1;for(let m=0;m<r;m++)f[m]||s[m]!==0||(h<0||a(m,h))&&(h=m);if(h<0)for(let m=0;m<r;m++)f[m]||(h<0||s[m]<s[h]||s[m]===s[h]&&a(m,h))&&(h=m);f[h]=1,u.push(n[h]);for(let m of i[h])s[m]--}return u}function qe(n,t,o,e){let r=Ze(n,t.filter(c=>!c.broken),o);for(let c of n)e[c]=Math.min(Math.max(o[c].c,o[c].lb),o[c].ub);for(let c=0;c<100;c++){let s=0;for(let{u:i,v:a,sep:f}of t){let u=f*r,l=e[i],h=e[a],m=u-(h-l);if(m<=.001)continue;m>s&&(s=m);let d=o[i],y=o[a],P=m*y.w/(d.w+y.w),b=m-P,p=l-d.lb,R=y.ub-h;P>p&&(b+=P-p,P=p),b>R&&(P=Math.min(p,P+(b-R)),b=R),e[i]=l-Math.max(0,P),e[a]=h+Math.max(0,b)}if(s<.05)break}}function ue(n,t,o,e){let r=new Map;for(let s of t){let i=r.get(s.v);i?i.push({u:s.u,sep:s.sep}):r.set(s.v,[{u:s.u,sep:s.sep}])}let c=new Map;for(let s of n){let i=o[s].lb;for(let{u:a,sep:f}of r.get(s)??[]){let u=c.get(a);u!==void 0&&(i=Math.max(i,u+f*e))}if(i>o[s].ub+1e-6)return!1;c.set(s,i)}return!0}function Ze(n,t,o){let e=s=>ue(n,t,o,s);if(e(1))return 1;let r=0,c=1;for(let s=0;s<10;s++){let i=(r+c)/2;e(i)?r=i:c=i}return r}var Qe=55,Je=18,gn={halfWidth:34,height:28,anchorRoom:8};function Jt(){let n={memo:null,searcher:new ln};return{route:t=>eo(n,t),reset:()=>{n.memo=null}}}var _t=n=>`${n.x},${n.y},${n.width},${n.height}`,Ft=58+2*12;function le(n,t,o){let e=Math.min(t.x,o.x),r=Math.min(t.y,o.y),c=Math.max(t.x+t.width,o.x+o.width),s=Math.max(t.y+t.height,o.y+o.height);for(let i of n)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x),s=Math.max(s,i.y);return{x0:e-Ft,y0:r-Ft,x1:c+Ft,y1:s+Ft}}function to(n,t,o){let e=n.length;for(let r=0;r<e;r++){let c=n[r],s=c.x+c.width,i=c.y+c.height,a=1/0,f=1/0;for(let u=0;u<e;u++){if(r===u)continue;let l=n[u];l.x>=s&&l.y<i-16&&c.y<l.y+l.height-16&&l.x<a&&(a=l.x),l.y>=i&&l.x<s-16&&c.x<l.x+l.width-16&&l.y<f&&(f=l.y)}a<1/0&&a-s>2*16&&t.push((s+a)/2),f<1/0&&f-i>2*16&&o.push((i+f)/2)}}function no(n){let t=Qe+Je*n.loopIndex,o=qt(n.sourceAnchor,n.sourceAnchor.side,20),e=qt(n.targetAnchor,n.targetAnchor.side,20),r=Math.min(o.x,e.x)-gn.anchorRoom,c=Math.max(o.x,e.x)+.75*t+gn.halfWidth,s=Math.min(o.y,e.y)-.75*t-gn.height,i=Math.max(o.y,e.y)+gn.anchorRoom;return{id:`${n.id}#loop`,x:r,y:s,width:c-r,height:i-s,kind:"annotation"}}function fe(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,hBlk:l,vBlk:h,hUse:m,vUse:d}=n,y=Vt(o),P=Tt(o),[b,p]=Pt(t,o),R=Qn(t,o),S=y===0?f:a,A=y===0?a:f,w=Nt(S,b-1),C=Rt(S,p+1);for(let v=w;v<=C;v++){let k=S[v],N=Jn(t,o,k),B=y===0?N.x:N.y,U,Y,G;if(P>0){if(U=Nt(A,B+10),U>=A.length)continue;Y=Math.max(0,Rt(A,B)),G=U-1}else{if(U=Rt(A,B-10),U<0)continue;Y=U,G=Math.min(A.length-1,Nt(A,B))-1}let lt=!0,q=0;for(let _=Y;_<=G&&lt;_++){let j=y===0?v*u+_:_*u+v;if(lt=(y===0?l[j]:h[j])===0,!lt)break;let z=y===0?m[j]:d[j];z&&(q+=.25*z*Math.abs(A[_+1]-A[_])),_>Y&&(y===0?j>=u&&d[j]>0&&d[j-u]>0:j%u>0&&m[j]>0&&m[j-1]>0)&&(q+=80*3)}if(!lt)continue;{let _=B-P*20,j=Math.min(_,B),z=Math.max(_,B);for(let L=Nt(A,j+.5);L<A.length&&A[L]<=z+.5;L++)(y===0?v>0&&d[v*u+L]>0&&d[(v-1)*u+L]>0:v>0&&m[L*u+v]>0&&m[L*u+v-1]>0)&&(q+=80*3)}if(c)for(let _ of c){if(_.other===s)continue;let j=1-Math.abs(k-_.c)/24;j>0&&(q+=400*j)}i&&(q+=i.side===o?2*Math.abs(k-i.c):100);let nt=y===0?v*u+U:U*u+v,at=k-R;r.push({side:o,c:k,point:N,node:nt,orient:y,dir:e?-P:P,cost:1.1*Math.abs(at)+.002*at*at+Math.abs(A[U]-B)+q,lane:v,legLo:Y,legHi:G})}}function he(n,t,o){let[e,r]=Pt(n,o),[c,s]=Pt(t,o),i=Math.max(e,c),a=Math.min(r,s);return i<=a?(i+a)/2:null}function pn(n,t,o,e=.01){let r=Vt(t),c=r===0?n.xs:n.ys,s=r===0?n.ys:n.xs,i=r===0?o.y:o.x,a=cn(s,i,e);if(a<0)return;let f=r===0?o.x:o.y,u=f-Tt(t)*20,l=Math.min(f,u),h=Math.max(f,u),m=Math.max(0,Rt(c,l)-1),d=Math.min(c.length-2,Nt(c,h)),{nx:y,hUse:P,vUse:b}=n;for(let p=m;p<=d;p++){if(c[p+1]<=l+.5||c[p]>=h-.5)continue;let R=r===0?a*y+p:p*y+a;r===0?P[R]<255&&P[R]++:b[R]<255&&b[R]++}}function me(n,t){let{nx:o,hUse:e,vUse:r}=n;for(let c=t.legLo;c<=t.legHi;c++)if(t.orient===0){let s=t.lane*o+c;e[s]<255&&e[s]++}else{let s=c*o+t.lane;r[s]<255&&r[s]++}}function Mn(n,t){switch(t){case"top":return{x0:n.x,y0:n.y-42,x1:n.x+n.width,y1:n.y};case"bottom":return{x0:n.x,y0:n.y+n.height,x1:n.x+n.width,y1:n.y+n.height+42};case"left":return{x0:n.x-42,y0:n.y,x1:n.x,y1:n.y+n.height};case"right":return{x0:n.x+n.width,y0:n.y,x1:n.x+n.width+42,y1:n.y+n.height}}}function Gn(n){let t=qt(n.sourceAnchor,n.sourceAnchor.side,20),o=qt(n.targetAnchor,n.targetAnchor.side,20),r=n.sourceAnchor.side==="left"||n.sourceAnchor.side==="right"?[t,{x:(t.x+o.x)/2,y:t.y},{x:(t.x+o.x)/2,y:o.y},o]:[t,{x:t.x,y:(t.y+o.y)/2},{x:o.x,y:(t.y+o.y)/2},o];return{sourceAnchor:n.sourceAnchor,targetAnchor:n.targetAnchor,points:$t(r)}}function de(n,t,o,e,r){let c=[];for(let s=1;s<n.length;s++){let i=n[s-1],a=n[s];e.query(Math.min(i.x,a.x),Math.min(i.y,a.y),Math.max(i.x,a.x),Math.max(i.y,a.y),c);for(let f of c)if(!(f>=o||r&&r.has(f))&&te(i,a,t[f],.5))return!0}return!1}var ye=n=>Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.width)&&Number.isFinite(n.height)&&n.width>=0&&n.height>=0,xe=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function eo(n,t){let o=t.obstacles.every(ye)?t.obstacles:t.obstacles.filter(ye),e=new Map;o.forEach((x,g)=>e.set(x.id,g));let r={lines:new Map,fallbacks:new Set,relaxed:new Map,stats:{gridX:0,gridY:0,pops:0,reused:0}},c=t.edges.filter(x=>!x.isSelfLoop&&x.source!==x.target&&e.has(x.source)&&e.has(x.target));if(!c.length)return r;let s=[...o];for(let x of t.edges)(x.isSelfLoop||x.source===x.target)&&e.has(x.source)&&xe(x.sourceAnchor)&&xe(x.targetAnchor)&&s.push(no(x));let i=new Map;[...c].sort((x,g)=>x.id<g.id?-1:x.id>g.id?1:0).forEach((x,g)=>i.set(x.id,g));let a=x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)];return Math.abs(g.x+g.width/2-M.x-M.width/2)+Math.abs(g.y+g.height/2-M.y-M.height/2)},f=[...c].sort((x,g)=>a(x)-a(g)||i.get(x.id)-i.get(g.id)),u=n.memo,l={rects:new Map(s.map(x=>[x.id,x])),routes:new Map},h=[];if(u){for(let x of s){let g=u.rects.get(x.id);(!g||_t(g)!==_t(x))&&(h.push(x),g&&h.push(g))}for(let[x,g]of u.rects)l.rects.has(x)||h.push(g)}let m=x=>{if(!u||h.length>s.length/2)return null;let g=u.routes.get(x.id);if(!g||g.srcKey!==_t(o[e.get(x.source)])||g.tgtKey!==_t(o[e.get(x.target)]))return null;for(let M of h){if(!(M.x<g.reach.x1&&M.x+M.width>g.reach.x0&&M.y<g.reach.y1&&M.y+M.height>g.reach.y0))continue;let E=M.x-Ft,I=M.y-Ft,O=M.x+M.width+Ft,D=M.y+M.height+Ft,W=g.pts;if(!W.length)return null;for(let Z=1;Z<W.length;Z++){let $=W[Z-1],X=W[Z];if(Math.max($.x,X.x)>E&&Math.min($.x,X.x)<O&&Math.max($.y,X.y)>I&&Math.min($.y,X.y)<D)return null}}return g},d=new Map,y=[];for(let x of f){let g=m(x);g?d.set(x.id,g):y.push(x)}let P=new Map,b=[],p=[];if(u&&h.length<=8){let x=(g,M,E)=>{let I=u.rects.get(g),O=o[e.get(g)];if(!I||I.width!==O.width||I.height!==O.height)return null;let D=M==="left"||M==="right",W=(D?E.y:E.x)-Wt(I,M)[0],[Z,$]=Pt(O,M),X=Math.min($,Math.max(Z,Wt(O,M)[0]+W));return(D?p:b).push(X),{side:M,c:X}};for(let g of y){let M=u.routes.get(g.id);!M||M.fallback||M.pts.length<2||P.set(g.id,{src:x(g.source,M.srcSide,M.pts[0]),tgt:x(g.target,M.tgtSide,M.pts[M.pts.length-1])})}}let R=2*30,S=new Set;for(let x of c)S.add(e.get(x.source)),S.add(e.get(x.target));let A=s.map(x=>({x0:x.x-16,y0:x.y-16,x1:x.x+x.width+16,y1:x.y+x.height+16})),w=1/0,C=1/0,v=-1/0,k=-1/0;for(let x of s)w=Math.min(w,x.x),C=Math.min(C,x.y),v=Math.max(v,x.x+x.width),k=Math.max(k,x.y+x.height);let N=c.map(x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)],E=[],I=[],O=he(g,M,"left");O!==null&&I.push(O);let D=he(g,M,"top");D!==null&&E.push(D),M.x>g.x+g.width?E.push((g.x+g.width+M.x)/2):g.x>M.x+M.width&&E.push((M.x+M.width+g.x)/2),M.y>g.y+g.height?I.push((g.y+g.height+M.y)/2):g.y>M.y+M.height&&I.push((M.y+M.height+g.y)/2);let W=Math.min(g.x,M.x),Z=Math.min(g.y,M.y);return{xs:E,ys:I,box:{id:x.id,x:W,y:Z,width:Math.max(g.x+g.width,M.x+M.width)-W,height:Math.max(g.y+g.height,M.y+M.height)-Z,kind:"annotation"}}}),B=(x,g,M,E)=>{let I=[...M,...b],O=[...E,...p],D=[],W=[],Z=[];for(let $ of x){let X=s[$];I.push(A[$].x0,A[$].x1),O.push(A[$].y0,A[$].y1),$<o.length&&(Z.push(X),S.has($)&&(D.push(X.x+X.width/2),W.push(X.y+X.height/2)))}to(Z,D,W);for(let $ of g)D.push(...N[$].xs),W.push(...N[$].ys);return{xs:wn(I,D,12),ys:wn(O,W,12)}},U=s.map((x,g)=>g),Y=s.length>150,G;if(Y)G=an(new Float64Array(0),new Float64Array(0));else{let{xs:x,ys:g}=B(U,c.map((M,E)=>E),[w-R,v+R],[C-R,k+R]);G=an(x,g),r.stats.gridX=G.nx,r.stats.gridY=G.ny;for(let M=0;M<s.length;M++)un(G,A[M].x0,A[M].y0,A[M].x1,A[M].y1,1)}let lt=(x,g)=>un(G,A[x].x0,A[x].y0,A[x].x1,A[x].y1,g),q=Y?new It(s,320):null,nt=Y?new It(N.map(x=>x.box),320):null,at=[],_=Y?new Bn(400):null,j=Y?o.flatMap(x=>Zt.map(g=>{let M=Mn(x,g);return{id:"",x:M.x0,y:M.y0,width:M.x1-M.x0,height:M.y1-M.y0,kind:"annotation"}})):null,z=Y?new It(j,320):null,L=Y?new Uint8Array(o.length*4):null,F=(x,g)=>{L&&(L[e.get(x.id)*4+Zt.indexOf(g)]=1)},V=[],Q=(x,g,M)=>{let E=Math.min(x.x,g.x)-M,I=Math.min(x.y,g.y)-M,O=Math.max(x.x+x.width,g.x+g.width)+M,D=Math.max(x.y+x.height,g.y+g.height)+M,W=E<=w-R&&I<=C-R&&O>=v+R&&D>=k+R;W&&(E=w-R,I=C-R,O=v+R,D=k+R),q.query(E,I,O,D,V);let Z=[];for(let ut of V){let tt=A[ut];tt.x1<E||tt.x0>O||tt.y1<I||tt.y0>D||Z.push(ut)}nt.query(E,I,O,D,V);let $=V.slice(),X=_.query(E,I,O,D),J=[E,O],rt=[I,D];for(let ut of X){let tt=at[ut].pts;for(let Bt=1;Bt<tt.length;Bt++){let mt=tt[Bt-1],zt=tt[Bt];Math.max(mt.x,zt.x)<E||Math.min(mt.x,zt.x)>O||Math.max(mt.y,zt.y)<I||Math.min(mt.y,zt.y)>D||(Math.abs(mt.y-zt.y)<.01&&mt.y>I&&mt.y<D?rt.push(mt.y):Math.abs(mt.x-zt.x)<.01&&mt.x>E&&mt.x<O&&J.push(mt.x))}}let{xs:dt,ys:ft}=B(Z,$,J,rt),Ot=E,en=I,on=O,rn=D;for(let ut of Z)Ot=Math.min(Ot,A[ut].x0),en=Math.min(en,A[ut].y0),on=Math.max(on,A[ut].x1),rn=Math.max(rn,A[ut].y1);let Zn=(ut,tt,Bt)=>ut.filter(mt=>mt>=tt-1e-6&&mt<=Bt+1e-6),Vn=Zn(dt,Ot,on),Wn=Zn(ft,en,rn);if(Vn.length*Wn.length>15e5)return null;let gt=an(Vn,Wn);for(let ut of Z)un(gt,A[ut].x0,A[ut].y0,A[ut].x1,A[ut].y1,1);let pt=1e9;Ot<E&&Ht(gt,-pt,-pt,E,pt,1),on>O&&Ht(gt,O,-pt,pt,pt,1),en<I&&Ht(gt,-pt,-pt,pt,I,1),rn>D&&Ht(gt,-pt,D,pt,pt,1),z.query(E,I,O,D,V);for(let ut of V){if(!L[ut])continue;let tt=j[ut];tt.x+tt.width<E||tt.x>O||tt.y+tt.height<I||tt.y>D||Qt(gt,tt.x,tt.y,tt.x+tt.width,tt.y+tt.height,1)}for(let ut of X){let tt=at[ut];kn(gt,tt.pts,1),pn(gt,tt.srcSide,tt.pts[0],1),pn(gt,tt.tgtSide,tt.pts[tt.pts.length-1],1)}return r.stats.gridX=Math.max(r.stats.gridX,gt.nx),r.stats.gridY=Math.max(r.stats.gridY,gt.ny),{grid:gt,whole:W,box:[E,I,O,D]}},T=[],ot=[],it=[],H=new Set,et=new Set,xt=[],Ct=new Map,Dt=(x,g,M,E)=>{let I=`${x.id}\\0${g}`,O=Ct.get(I);O?O.push({c:M,other:E}):Ct.set(I,[{c:M,other:E}])};for(let x of t.edges){if(!(x.isSelfLoop||x.source===x.target)||!e.has(x.source))continue;let g=o[e.get(x.source)];for(let M of[x.sourceAnchor,x.targetAnchor])Dt(g,M.side,M.side==="left"||M.side==="right"?M.y:M.x,"")}let kt=(x,g)=>{for(let M of Zt){if(!H.has(`${x.id}\\0${M}`))continue;let E=Mn(x,M);Qt(G,E.x0,E.y0,E.x1,E.y1,g)}},At=(x,g,M,E,I=!1)=>{T.length=0,ot.length=0;let O=o[x],D=o[g];for(let J of Zt)fe(G,O,J,!1,T,Ct.get(`${O.id}\\0${J}`),D.id,E?.src??null),fe(G,D,J,!0,ot,Ct.get(`${D.id}\\0${J}`),O.id,E?.tgt??null);if(!T.length||!ot.length)return null;let W=(J,rt)=>Ht(G,J.x-29,J.y-29,J.x+J.width+29,J.y+J.height+29,rt);kt(O,-1),g!==x&&kt(D,-1),W(O,1),g!==x&&W(D,1);let Z=Math.abs(O.x+O.width/2-D.x-D.width/2)+Math.abs(O.y+O.height/2-D.y-D.height/2),$=Math.min(1,Math.max(0,(Z-(Y?1200:1600))/1200)),X=n.searcher.search(G,T,ot,4e4,M,I?3:1.1+(Y?.9:.3)*$,I?80*.1:80*(1-(Y?.85:.7)*$));return W(O,-1),g!==x&&W(D,-1),kt(O,1),g!==x&&kt(D,1),r.stats.pops+=n.searcher.lastPops,X},Xt=(x,g,M,E,I,O)=>{let D=o[e.get(x.source)],W=o[e.get(x.target)];if(Y){let $=at.length;at.push({pts:g.map(X=>({x:X.x,y:X.y})),srcSide:M,tgtSide:E});for(let X=1;X<g.length;X++)_.add($,g[X-1],g[X])}else O?(ne(G,O.nodes),me(G,O.src),me(G,O.tgt)):kn(G,g),pn(G,M,g[0]),pn(G,E,g[g.length-1]);let Z=($,X)=>X==="left"||X==="right"?$.y:$.x;Dt(D,M,Z(g[0],M),W.id),Dt(W,E,Z(g[g.length-1],E),D.id);for(let[$,X]of[[D,M],[W,E]]){let J=`${$.id}\\0${X}`,rt=Mn($,X);H.has(J)||(H.add(J),F($,X),Y||Qt(G,rt.x0,rt.y0,rt.x1,rt.y1,1)),!et.has(J)&&(et.add(J),xt.push({id:`${J}#zone`,x:rt.x0,y:rt.y0,width:rt.x1-rt.x0,height:rt.y1-rt.y0,kind:"annotation"}))}I&&I.size&&r.relaxed.set(x.id,new Set([...I].map($=>o[$].id))),it.push({spec:x,path:{pts:g,src:D,srcSide:M,tgt:W,tgtSide:E,rank:i.get(x.id),ignore:I&&I.size?I:null,own:[e.get(x.source),e.get(x.target)]}}),l.routes.set(x.id,{srcKey:_t(D),tgtKey:_t(W),pts:g.slice(),srcSide:M,tgtSide:E,ignore:I&&I.size?[...I].map($=>o[$].id):null,fallback:!1,reach:le(g,D,W)})};for(let x of c)for(let[g,M]of[[x.source,x.sourceAnchor.side],[x.target,x.targetAnchor.side]]){let E=o[e.get(g)],I=`${E.id}\\0${M}`;if(H.has(I)||(H.add(I),F(E,M),Y))continue;let O=Mn(E,M);Qt(G,O.x0,O.y0,O.x1,O.y1,1)}for(let x of f){let g=d.get(x.id);if(!g)continue;if(r.stats.reused++,g.fallback){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,g);continue}let M=g.ignore?new Set(g.ignore.map(E=>e.get(E)).filter(E=>E!==void 0)):null;Xt(x,g.pts.map(E=>({x:E.x,y:E.y})),g.srcSide,g.tgtSide,M,null)}for(let x of y){let g=e.get(x.source),M=e.get(x.target),E=o[g],I=o[M],O=P.get(x.id),D=()=>At(g,M,!0,O)??null,W=()=>{let J=46,rt=new Set;for(let ft=0;ft<o.length;ft++)ft===g||ft===M||(sn(o[ft],0,E,J)||sn(o[ft],0,I,J))&&rt.add(ft);if(sn(E,0,I,J)&&(rt.add(g),rt.add(M)),!rt.size)return null;for(let ft of rt)lt(ft,-1);let dt=At(g,M,!1,O);for(let ft of rt)lt(ft,1);return dt?{found:dt,ignore:rt}:null},Z=null,$=null,X=null;if(Y){let J=400,rt=!1;for(;;){let dt=Q(E,I,J);if(!dt)break;G=dt.grid,rt=!0;let ft=D();if(ft){if(Z=ft,X=Rn(ft,G),dt.whole||!oo(X,dt.box))break}else if(n.searcher.lastPops>4e4){let Ot=At(g,M,!0,O,!0);Ot&&(Z=Ot,X=Rn(Ot,G));break}else if(dt.whole)break;J*=2.5}if(!Z&&rt){let dt=W();dt&&({found:Z,ignore:$}=dt,X=Rn(dt.found,G))}}else{if(Z=D(),!Z){let J=W();J&&({found:Z,ignore:$}=J)}Z&&(X=Rn(Z,G))}if(!Z){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,{srcKey:_t(E),tgtKey:_t(I),pts:[],srcSide:x.sourceAnchor.side,tgtSide:x.targetAnchor.side,ignore:null,fallback:!0,reach:le([],E,I)});continue}Xt(x,X,Z.src.side,Z.tgt.side,$&&$.size?$:null,Z)}n.memo=l,it.sort((x,g)=>x.path.rank-g.path.rank);let St=it.map(x=>x.path),vt=St.map(x=>x.pts.slice()),Kt=[...s,...xt],Yt={rects:Kt,buckets:new It(Kt),zoneFrom:s.length};ae(St,Yt),Dn(St,!0,Yt),Tn(St,!0,Yt),Dn(St,!1,Yt),Tn(St,!1,Yt);let qn=new It(s);return it.forEach(({spec:x,path:g},M)=>{let E=$t(g.pts);if((E.length<2||de(E,s,o.length,qn,g.ignore))&&(E=vt[M]),de(E,s,o.length,qn,g.ignore)){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x));return}r.lines.set(x.id,{sourceAnchor:En(E[0],g.srcSide),targetAnchor:En(E[E.length-1],g.tgtSide),points:E})}),r}function Rn(n,t){let o=[n.src.point];for(let e of n.nodes){let r=e%t.nx;o.push({x:t.xs[r],y:t.ys[(e-r)/t.nx]})}return o.push(n.tgt.point),$t(o)}function oo(n,t){let[o,e,r,c]=t;for(let s of n)if(s.x<=o+.5||s.y<=e+.5||s.x>=r-.5||s.y>=c-.5)return!0;return!1}var Bn=class{constructor(t){this.cell=t;K(this,"cells",new Map);K(this,"everywhere",new Set);K(this,"seen",new Uint32Array(64));K(this,"stamp",0)}key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=Math.floor(Math.min(o.x,e.x)/this.cell),c=Math.floor(Math.max(o.x,e.x)/this.cell),s=Math.floor(Math.min(o.y,e.y)/this.cell),i=Math.floor(Math.max(o.y,e.y)/this.cell);if(!Number.isFinite(r+c+s+i)||(c-r+1)*(i-s+1)>4096||Math.abs(r)>28672||Math.abs(c)>28672||Math.abs(s)>28672||Math.abs(i)>28672){this.everywhere.add(t);return}for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=this.key(f,a),l=this.cells.get(u);l?l[l.length-1]!==t&&l.push(t):this.cells.set(u,[t])}}query(t,o,e,r){let c=[...this.everywhere];++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=Math.max(-28672,Math.floor(t/this.cell)),i=Math.min(28672,Math.floor(e/this.cell)),a=Math.max(-28672,Math.floor(o/this.cell)),f=Math.min(28672,Math.floor(r/this.cell));if((i-s+1)*(f-a+1)>1<<20){let u=new Set(this.everywhere);for(let l of this.cells.values())for(let h of l)u.add(h);return[...u]}for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(this.key(l,u));if(h)for(let m of h){if(m>=this.seen.length){let d=new Uint32Array(Math.max(m+1,this.seen.length*2));d.set(this.seen),this.seen=d}this.seen[m]===this.stamp||this.everywhere.has(m)||(this.seen[m]=this.stamp,c.push(m))}}return c}};function zn(n){let t=[];for(let e=0;e<n.length;e++){let r=n[e];for(let c=0;c+1<r.length;c++){let s=r[c],i=r[c+1],a=Math.hypot(i.x-s.x,i.y-s.y);a<2*.75||t.push({line:e,seg:c,ax:s.x,ay:s.y,bx:i.x,by:i.y,len:a,minX:Math.min(s.x,i.x),maxX:Math.max(s.x,i.x),minY:Math.min(s.y,i.y),maxY:Math.max(s.y,i.y)})}}t.sort((e,r)=>e.minX-r.minX);let o=[];for(let e=0;e<t.length;e++){let r=t[e];for(let c=e+1;c<t.length;c++){let s=t[c];if(s.minX>r.maxX)break;if(s.line===r.line||s.minY>r.maxY||s.maxY<r.minY)continue;let i=r.bx-r.ax,a=r.by-r.ay,f=s.bx-s.ax,u=s.by-s.ay,l=i*u-a*f;if(Math.abs(l)<.02*r.len*s.len)continue;let h=s.ax-r.ax,m=s.ay-r.ay,d=(h*u-m*f)/l,y=(h*a-m*i)/l,P=d*r.len,b=y*s.len;P<=.75||P>=r.len-.75||b<=.75||b>=s.len-.75||o.push({x:r.ax+i*d,y:r.ay+a*d,a:{line:r.line,seg:r.seg,d:P},b:{line:s.line,seg:s.seg,d:b}})}}return o}function $n(n,t,o){let e=n.length,r=new Float64Array(Math.max(0,e-1));for(let i=0;i+1<e;i++)r[i]=Math.hypot(n[i+1].x-n[i].x,n[i+1].y-n[i].y);let c=new Float64Array(e),s=new Float64Array(e);if(t==="sharp")return{segLen:r,rIn:c,rOut:s};for(let i=1;i<e-1;i++){let a=r[i-1],f=r[i];if(t==="rounded"){let y=Math.min(8,a/2,f/2);c[i]=y,s[i]=y;continue}let u=i-1===0?a-4:a/2,l=i===e-2?f-4:f/2,h=Math.max(0,Math.min(40,u)),m=Math.max(0,Math.min(40,l)),d=Math.min(h,m);h=Math.min(h,d*2),m=Math.min(m,d*2),o&&o.length&&h>8&&([h,m]=so(n[i-1],n[i],n[i+1],h,m,o)),c[i]=h,s[i]=m}return{segLen:r,rIn:c,rOut:s}}function tn(n,t,o,e,r){let c=Math.hypot(t.x-n.x,t.y-n.y)||1,s=Math.hypot(o.x-t.x,o.y-t.y)||1,i={x:t.x-(t.x-n.x)/c*e,y:t.y-(t.y-n.y)/c*e},a={x:t.x+(o.x-t.x)/s*r,y:t.y+(o.y-t.y)/s*r},f={x:i.x+(t.x-i.x)*.5523,y:i.y+(t.y-i.y)*.5523},u={x:a.x+(t.x-a.x)*.5523,y:a.y+(t.y-a.y)*.5523};return{a:i,c1:f,c2:u,b:a}}var ro=[.2,.35,.5,.65,.8];function so(n,t,o,e,r,c){let s=Math.max(e,r)+6,i=[];for(let a of c)a.x>t.x+s||a.x+a.width<t.x-s||a.y>t.y+s||a.y+a.height<t.y-s||t.x>a.x-6&&t.x<a.x+a.width+6&&t.y>a.y-6&&t.y<a.y+a.height+6||i.push(a);if(!i.length)return[e,r];for(let a=0;a<5;a++){let{a:f,c1:u,c2:l,b:h}=tn(n,t,o,e,r),m=!1;for(let d of ro){let y=1-d,P=y*y*y*f.x+3*y*y*d*u.x+3*y*d*d*l.x+d*d*d*h.x,b=y*y*y*f.y+3*y*y*d*u.y+3*y*d*d*l.y+d*d*d*h.y;for(let p of i)if(P>p.x-6&&P<p.x+p.width+6&&b>p.y-6&&b<p.y+p.height+6){m=!0;break}if(m)break}if(!m)return[e,r];if(e*=.7,r*=.7,Math.max(e,r)<=8)break}return[Math.min(e,8),Math.min(r,8)]}var An=10,Hn=.75;function io(n,t,o,e,r,c,s){let i=1-s;return n==="rounded"?{x:i*i*t.x+2*i*s*c.x+s*s*r.x,y:i*i*t.y+2*i*s*c.y+s*s*r.y}:{x:i*i*i*t.x+3*i*i*s*o.x+3*i*s*s*e.x+s*s*s*r.x,y:i*i*i*t.y+3*i*i*s*o.y+3*i*s*s*e.y+s*s*s*r.y}}function be(n){let t=1/0,o=-1/0,e=1/0,r=-1/0;for(let c of n.pts)c.x<t&&(t=c.x),c.x>o&&(o=c.x),c.y<e&&(e=c.y),c.y>r&&(r=c.y);return{...n,minX:t,maxX:o,minY:e,maxY:r}}function Sn(n,t,o){if(o==="sharp")return[];let e=[],r=0;for(let s=0;s<n.length;s++){let i=n[s],a=t[s];for(let f=0;f+1<i.length;f++){let u=a.segLen[f];if(u<=0)continue;let l=a.rOut[f],h=u-a.rIn[f+1];if(h-l>2*Hn){let d=i[f],y=i[f+1],P=(y.x-d.x)/u,b=(y.y-d.y)/u;e.push(be({line:s,index:f,curve:!1,pts:[{x:d.x+P*l,y:d.y+b*l},{x:d.x+P*h,y:d.y+b*h}],offset:l}))}let m=f+1;if(m<i.length-1&&(a.rIn[m]>0||a.rOut[m]>0)){let d=tn(i[m-1],i[m],i[m+1],a.rIn[m],a.rOut[m]),y=[];for(let P=0;P<=An;P++)y.push(io(o,d.a,d.c1,d.c2,d.b,i[m],P/An));e.push(be({line:s,index:m,curve:!0,pts:y,offset:0})),r++}}}if(!r)return[];e.sort((s,i)=>s.minX-i.minX);let c=[];for(let s=0;s<e.length;s++){let i=e[s];for(let a=s+1;a<e.length;a++){let f=e[a];if(f.minX>i.maxX)break;if(i.curve===f.curve||i.line===f.line||f.minY>i.maxY||f.maxY<i.minY)continue;let u=i.curve?i:f,l=i.curve?f:i,[h,m]=l.pts,d=m.x-h.x,y=m.y-h.y,P=Math.hypot(d,y);for(let b=0;b<An;b++){let p=u.pts[b],R=u.pts[b+1],S=R.x-p.x,A=R.y-p.y,w=S*y-A*d;if(Math.abs(w)<1e-9)continue;let C=h.x-p.x,v=h.y-p.y,k=(C*y-v*d)/w,N=(C*A-v*S)/w;if(k<0||k>=1)continue;let B=N*P;B<=Hn||B>=P-Hn||c.push({x:h.x+d*N,y:h.y+y*N,straight:{line:l.line,seg:l.index,d:l.offset+B},curve:{line:u.line,vertex:u.index,t:(b+k)/An}})}}}return c}var Kn=6,ao=6,uo=14;function lo(n){let t=n&&Number.isFinite(n)&&n>0?n:1;return Math.min(uo,Math.max(Kn,ao/t))}var fo=4.5,Xn=3,ge=4,ho=4,pe=36,Me=16,mo=16;function yo(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=t[t.length-1],s=(c.x-r.x)*(o.y-r.y)-(c.y-r.y)*(o.x-r.x),i=(c.x-r.x)*(o.x-c.x)+(c.y-r.y)*(o.y-c.y);if(Math.abs(s)<.01&&i>=0){t[t.length-1]=o;continue}}t.push(o)}}return t}var Ae=(n,t=Kn)=>n==="hop"?t:fo;function xo(n,t){let o=n.segLen.length-1,e=n.rOut[t]+(t===0?ge:Xn),r=n.segLen[t]-n.rIn[t+1]-(t===o?ge:Xn);return[e,r]}function Pn(n,t){let o=n[t],e=n[t+1],r=Math.hypot(e.x-o.x,e.y-o.y);return r>0?Math.abs(e.x-o.x)/r:0}function bo(n,t,o,e,r,c,s){let i=Ae(r,s),a=t.map(()=>[]),f=r==="hop"?s:2,u=(h,m)=>{let[d,y]=xo(o[h.line],h.seg);return h.d-m>=d&&h.d+m<=y},l=h=>{let m=a[h.line][h.seg];m?m.push(h.d):a[h.line][h.seg]=[h.d]};for(let h of n){let m=Pn(t[h.a.line],h.a.seg),d=Pn(t[h.b.line],h.b.seg),y=Math.abs(m-d)>.001?m>d:e[h.a.line]>e[h.b.line],P=y?h.a:h.b,b=y?h.b:h.a,[p,R]=r==="hop"?[P,b]:[b,P];u(p,i)&&u(R,f)?l(p):u(R,i)&&u(p,f)&&l(R)}if(r!=="hop")for(let h of c)u(h.straight,i)&&l(h.straight);return a}function go(n,t){n.sort((e,r)=>e-r);let o=[];for(let e of n){let r=o[o.length-1];r&&e-t-r[1]<ho?r[1]=Math.max(r[1],e+t):o.push([e-t,e+t])}return o}var Re=n=>String(Math.round(n*100)/100),yt=n=>`${Re(n.x)},${Re(n.y)}`,Gt=(n,t)=>Math.hypot(t.x-n.x,t.y-n.y);function po(n,t){let o=t,e=-n;return Math.abs(e)>.05?e>0&&(o=-o,e=-e):o<0&&(o=-o,e=-e),{x:o,y:e}}function Mo(n,t){let{pieces:o}=n,e=0,r=o.length-1;for(;e<r;){let f=e+r>>1;o[f].pos1<t?e=f+1:r=f}let c=o[e],s=c.pos1-c.pos0,i=s>0?Math.min(1,Math.max(0,(t-c.pos0)/s)):0,a=1-i;switch(c.kind){case"L":return{x:c.a.x+(c.b.x-c.a.x)*i,y:c.a.y+(c.b.y-c.a.y)*i};case"Q":return{x:a*a*c.a.x+2*a*i*c.c.x+i*i*c.b.x,y:a*a*c.a.y+2*a*i*c.c.y+i*i*c.b.y};case"C":return{x:a*a*a*c.a.x+3*a*a*i*c.c1.x+3*a*i*i*c.c2.x+i*i*i*c.b.x,y:a*a*a*c.a.y+3*a*a*i*c.c1.y+3*a*i*i*c.c2.y+i*i*i*c.b.y}}}function Ro(n,t,o){let e=n.knots[t];if(!e||!e.length)return 0;let r=e[0];for(let c of e){if(c[0]>o)break;r=c}return r[1]+Math.max(0,o-r[0])}function Ao(n,t,o,e,r,c,s=Kn){let i=n.length;if(i===0)return{d:"",pieces:[],knots:[],cornerPos:[],length:0};let a=e??$n(n,t,o),f=`M ${yt(n[0])}`,u=null,l=[],h=[],m=[],d=0,y=n[0],P=r?Ae(r,s):0,b=R=>{f+=R,u!==null&&(u+=R)};for(let R=0;R+1<i;R++){let S=n[R],A=n[R+1],w=a.segLen[R];if(w<=0)continue;let C=(A.x-S.x)/w,v=(A.y-S.y)/w,k=q=>({x:S.x+C*q,y:S.y+v*q});if(R>0){let q=a.rIn[R],nt=a.rOut[R];if(q>0||nt>0){let at=n[R-1],_=tn(at,S,A,q,nt),j=d;t==="rounded"?(b(` Q ${yt(S)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,S)+Gt(S,_.b))/2,l.push({pos0:j,pos1:d,kind:"Q",a:y,c:S,b:_.b})):(b(` C ${yt(_.c1)} ${yt(_.c2)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,_.c1)+Gt(_.c1,_.c2)+Gt(_.c2,_.b))/2,l.push({pos0:j,pos1:d,kind:"C",a:y,c1:_.c1,c2:_.c2,b:_.b})),y=_.b,m[R]=[j,d]}}let N=a.rOut[R],B=w-a.rIn[R+1],U=N,Y=[[U,d]];h[R]=Y;let G=q=>{if(q<=U+1e-6)return;let nt=k(q);b(` L ${yt(nt)}`),l.push({pos0:d,pos1:d+(q-U),kind:"L",a:y,b:nt}),d+=q-U,U=q,y=nt},lt=r?c[R]:void 0;if(lt&&lt.length)for(let[q,nt]of go(lt,P)){G(q);let at=k(q),_=k(nt);if(r==="cut")u===null&&(u=f),f+=` L ${yt(_)}`,u+=` M ${yt(_)}`,l.push({pos0:d,pos1:d+(nt-q),kind:"L",a:at,b:_}),d+=nt-q;else{let j=po(C,v),z=s,L=.5523*z,F=(T,ot,it)=>({x:T.x+C*ot+j.x*it,y:T.y+v*ot+j.y*it}),V=Math.PI*z/2,Q=(T,ot,it,H)=>{b(` C ${yt(ot)} ${yt(it)} ${yt(H)}`),l.push({pos0:d,pos1:d+V,kind:"C",a:T,c1:ot,c2:it,b:H}),d+=V};if(nt-q<=2*z+.01){let T=F(at,z,z);Q(at,F(at,0,L),F(T,-L,0),T),Q(T,F(T,L,0),F(_,0,L),_)}else{let T=F(at,z,z),ot=F(_,-z,z);Q(at,F(at,0,L),F(T,-L,0),T),b(` L ${yt(ot)}`),l.push({pos0:d,pos1:d+(nt-q-2*z),kind:"L",a:T,b:ot}),d+=nt-q-2*z,Q(ot,F(ot,L,0),F(_,0,L),_)}}U=nt,y=_,Y.push([U,d])}G(B)}let p={d:f,pieces:l,knots:h,cornerPos:m,length:d};return u!==null&&(p.strokeD=u),p}function So(n,t){let o=n.length/2,e=Math.min(mo,n.length/2);t.push([-1/0,e],[n.length-e,1/0]),t.sort((i,a)=>i[0]-a[0]||i[1]-a[1]);let r=o,c=-1/0,s=-1/0;for(let[i,a]of t)if(i>s){if(c<o&&o<s)break;c=i,s=a}else s=Math.max(s,a);if(c<o&&o<s){let i=c>=e,a=s<=n.length-e;i&&(!a||o-c<=s-o)?r=c:a&&(r=s)}return Mo(n,r)}function Po(n,t,o,e){let r=e+Xn,c=2,s=(a,f,u)=>{let l=t[a],h=l.segLen[f];if(u<r||h-u<r)return;let m=Math.max(0,u-r),d=Math.max(0,h-u-r);f>0&&l.rOut[f]>m&&(l.rOut[f]=m,l.rIn[f]=Math.min(l.rIn[f],Math.max(m,8)*c)),f+1<n[a].length-1&&l.rIn[f+1]>d&&(l.rIn[f+1]=d,l.rOut[f+1]=Math.min(l.rOut[f+1],Math.max(d,8)*c))},i=zn(n);for(let a of i)s(a.a.line,a.a.seg,a.a.d),s(a.b.line,a.b.seg,a.b.d);if(o!=="curved")return{crossings:i,curveCrossings:Sn(n,t,o)};for(let a=0;;a++){let f=Sn(n,t,o);if(!f.length||a===3)return{crossings:i,curveCrossings:f};let u=!1;for(let l of f){let h=t[l.curve.line],m=l.curve.vertex;Math.max(h.rIn[m],h.rOut[m])<=8+.01||(h.rIn[m]=Math.max(Math.min(h.rIn[m],8),h.rIn[m]*.6),h.rOut[m]=Math.max(Math.min(h.rOut[m],8),h.rOut[m]*.6),u=!0)}if(!u)return{crossings:i,curveCrossings:f}}}var Eo=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function Se(n,t){let o=[...n.keys()].filter(y=>n.get(y).points.every(Eo)),e=o.map(y=>yo(n.get(y).points)),r=e.map(y=>$n(y,t.corners,t.obstacles)),c=lo(t.zoom),s=t.crossings==="hops"&&t.corners!=="sharp"&&e.length>1?Po(e,r,t.corners,c):null,i=y=>{let P=r[y.line];return y.d>=P.rOut[y.seg]&&y.d<=P.segLen[y.seg]-P.rIn[y.seg+1]},a=e.length>1?(s?.crossings??zn(e)).filter(y=>i(y.a)&&i(y.b)):[],f=e.length>1?s?.curveCrossings??Sn(e,r,t.corners):[],u=t.crossings==="hops"?"hop":t.crossings==="halo"?"cut":null,l=u?bo(a,e,r,o,u,f,c):e.map(()=>[]),h=e.map(()=>[]),m=e.map(()=>[]);for(let y of a)h[y.a.line].push(y.a),h[y.b.line].push(y.b);for(let y of f)h[y.straight.line].push(y.straight),m[y.curve.line].push(y.curve);let d=new Map;for(let y=0;y<o.length;y++){let P=e[y];if(P.length<2){let A=P[0]??{x:0,y:0};d.set(o[y],{d:`M ${yt(A)}`,mid:A,halo:t.crossings==="halo"?!0:void 0});continue}let b=Ao(P,t.corners,t.obstacles,r[y],u,l[y],c),p=h[y].map(A=>{let w=Ro(b,A.seg,A.d),C=Pn(P,A.seg)>.7?pe:Me;return[w-C,w+C]});for(let A of m[y]){let w=b.cornerPos[A.vertex];if(!w)continue;let C=w[0]+(w[1]-w[0])*A.t,v=Pn(P,A.t<.5?A.vertex-1:A.vertex)>.7?pe:Me;p.push([C-v,C+v])}let R=So(b,p),S={d:b.d,mid:R};t.crossings==="halo"&&(S.halo=!0),b.strokeD&&(S.strokeD=b.strokeD),d.set(o[y],S)}return d}function wo(n,t,o,e,r,c,s,i){let a=0,f=1,u=[-o,o,-e,e],l=[n-r,s-n,t-c,i-t];for(let h=0;h<4;h++){if(u[h]===0){if(l[h]<=0)return null;continue}let m=l[h]/u[h];if(u[h]<0){if(m>f)return null;m>a&&(a=m)}else{if(m<a)return null;m<f&&(f=m)}}return f>a?[a,f]:null}function Pe(n,t,o,e){let r=e;for(;r<n.length-2&&t[r+1]<o;)r++;let c=t[r+1]-t[r],s=c>0?(o-t[r])/c:0,i=n[r],a=n[r+1];return{p:{x:i.x+(a.x-i.x)*s,y:i.y+(a.y-i.y)*s},seg:r}}function Ee(n,t,o){let e=n.points;if(e.length<2||o.length===0)return[];let r=[0];for(let u=1;u<e.length;u++)r.push(r[u-1]+Math.hypot(e[u].x-e[u-1].x,e[u].y-e[u-1].y));let c=[];for(let u=0;u<e.length-1;u++){let l=e[u],h=e[u+1],m=r[u+1]-r[u];if(!(m>0)||!Number.isFinite(m))continue;let d=h.x-l.x,y=h.y-l.y,P=Math.min(l.x,h.x),b=Math.max(l.x,h.x),p=Math.min(l.y,h.y),R=Math.max(l.y,h.y);for(let S of o){let A=S.x+1,w=S.y+1,C=S.x+S.width-1,v=S.y+S.height-1;if(!(C>A)||!(v>w)||!Number.isFinite(C-A)||!Number.isFinite(v-w)||b<=A||P>=C||R<=w||p>=v||y===0&&(l.y-S.y<6||S.y+S.height-l.y<6)||d===0&&(l.x-S.x<6||S.x+S.width-l.x<6))continue;let k=wo(l.x,l.y,d,y,A,w,C,v);k&&c.push([r[u]+k[0]*m,r[u]+k[1]*m,S.id!==t?.source&&S.id!==t?.target])}}if(c.length===0)return[];c.sort((u,l)=>u[0]-l[0]);let s=[];for(let u of c){let l=s[s.length-1];l&&u[0]-l[1]<12?(u[1]>l[1]&&(l[1]=u[1]),u[2]&&(l[2]=!0)):s.push([u[0],u[1],u[2]])}let i=r[r.length-1];if(!Number.isFinite(i))return[];let a=[],f=0;for(let[u,l,h]of s){if(l-u<6||t&&!h&&(u<.5||l>i-.5))continue;let m=Pe(e,r,u,f),d=Pe(e,r,l,m.seg),y=[m.p];for(let P=m.seg+1;P<=d.seg;P++)y.push(e[P]);y.push(d.p),a.push(ko(y)),f=d.seg}return a}function ko(n){let t=[];for(let o of n){let e=t[t.length-1];e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01||t.push(o)}return t}function Yn(n,t,o){try{return n()}catch(e){return o(e),t}}function we(n,t,o={}){let e=o.now??(()=>0),r=o.onError??(()=>{}),c=o.router??Jt(),s=e(),i=Yn(()=>c.route(n).lines,new Map,l=>{c.reset(),r(l)}),a=Yn(()=>Se(i,{crossings:t.crossings,corners:t.corners,obstacles:n.obstacles,zoom:o.zoom??1}),new Map,r),f=new Map(n.edges.map(l=>[l.id,l])),u=new Map;for(let[l,h]of i){let m=a.get(l);if(!m)continue;let d=f.get(l),y=t.underTables==="xray"&&d?Yn(()=>Ee(h,d,n.obstacles),[],r):void 0,P={...h,d:m.d,mid:m.mid,halo:m.halo,tunnels:y&&y.length?y:void 0};m.strokeD&&(P.strokeD=m.strokeD),u.set(l,P)}return{edges:u,millis:e()-s}}var Co=Jt(),ke=self;ke.onmessage=n=>{let t=n.data;if(!t||t.type!=="route")return;let o,e=we(t.input,jn(t.style),{router:Co,now:()=>performance.now(),zoom:t.zoom,onError:r=>{o??(o=r instanceof Error?r.message:String(r))}});ke.postMessage({seq:t.seq,edges:e.edges,millis:e.millis,error:o})};})();\n' : null;
4225
4225
  }
4226
- var createRoutingWorker = (events) => {
4226
+ function workerFromUrl(url) {
4227
+ if (!url || typeof Worker === "undefined") return null;
4228
+ try {
4229
+ return new Worker(url);
4230
+ } catch {
4231
+ return null;
4232
+ }
4233
+ }
4234
+ function workerFromInlinedCode() {
4227
4235
  const code = inlinedWorkerCode();
4228
4236
  if (!code || typeof Worker === "undefined" || typeof Blob === "undefined" || typeof URL?.createObjectURL !== "function") {
4229
4237
  return null;
4230
4238
  }
4231
- let worker;
4232
4239
  try {
4233
4240
  const url = URL.createObjectURL(new Blob([code], { type: "text/javascript" }));
4234
- worker = new Worker(url);
4241
+ const worker = new Worker(url);
4235
4242
  URL.revokeObjectURL(url);
4243
+ return worker;
4236
4244
  } catch {
4237
4245
  return null;
4238
4246
  }
4247
+ }
4248
+ function routingWorkerFactory(url) {
4249
+ return (events) => {
4250
+ const worker = workerFromUrl(url) ?? workerFromInlinedCode();
4251
+ return worker ? handleFor(worker, events) : null;
4252
+ };
4253
+ }
4254
+ var createRoutingWorker = routingWorkerFactory(null);
4255
+ function handleFor(worker, events) {
4239
4256
  let alive = true;
4240
4257
  const fail = (err) => {
4241
4258
  if (!alive) return;
@@ -4266,7 +4283,7 @@ var createRoutingWorker = (events) => {
4266
4283
  worker.terminate();
4267
4284
  }
4268
4285
  };
4269
- };
4286
+ }
4270
4287
 
4271
4288
  // src/lib/edgeRouting/index.ts
4272
4289
  var DRAG_REROUTE_BUDGET_MS = 12;
@@ -4576,7 +4593,7 @@ function EdgeRouter() {
4576
4593
  const root = storeApi.getState().domNode;
4577
4594
  if (root) root.dataset.edgeRouting = `${update2.pass} ${Math.round(update2.millis)}ms ${update2.routes?.size ?? 0}`;
4578
4595
  };
4579
- engine.current ?? (engine.current = createEdgeRoutingEngine({ worker: createRoutingWorker, onUpdate: apply }));
4596
+ engine.current ?? (engine.current = createEdgeRoutingEngine({ worker: routingWorkerFactory(canvas.getState().routingWorkerUrl), onUpdate: apply }));
4580
4597
  const { nodeLookup, edges } = storeApi.getState();
4581
4598
  const dragging = /* @__PURE__ */ new Set();
4582
4599
  for (const node of nodeLookup.values()) if (node.dragging && !node.hidden) dragging.add(node.id);
@@ -10368,7 +10385,8 @@ var ErdCanvas = forwardRef(function ErdCanvas2(props, ref) {
10368
10385
  () => createCanvasStore({
10369
10386
  domain: renderable,
10370
10387
  logicalOnly: props.logicalOnly === true,
10371
- lineStyle: isLineStyle(props.lineStyle) ? props.lineStyle : DEFAULT_LINE_STYLE
10388
+ lineStyle: isLineStyle(props.lineStyle) ? props.lineStyle : DEFAULT_LINE_STYLE,
10389
+ routingWorkerUrl: typeof props.routingWorkerUrl === "string" && props.routingWorkerUrl !== "" ? props.routingWorkerUrl : null
10372
10390
  })
10373
10391
  );
10374
10392
  return /* @__PURE__ */ jsx23(CanvasStoreProvider, { store, children: /* @__PURE__ */ jsx23(CanvasEnvironmentProvider, { host: NOOP_CANVAS_HOST, viewer: true, children: /* @__PURE__ */ jsx23(ReactFlowProvider, { children: /* @__PURE__ */ jsx23(ErdCanvasInner, { ...props, domain: renderable, handleRef: ref }) }) }) });
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var Ce=Object.defineProperty;var ve=(n,t,o)=>t in n?Ce(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var K=(n,t,o)=>ve(n,typeof t!="symbol"?t+"":t,o);var Oe="curved";function Ie(n){return n==="curved"||n==="hops"}var Le={curved:{crossings:"halo",underTables:"xray",corners:"curved"},hops:{crossings:"hops",underTables:"hidden",corners:"rounded"}};function jn(n){return Le[Ie(n)?n:Oe]}function qt(n,t,o){switch(t){case"top":return{x:n.x,y:n.y-o};case"bottom":return{x:n.x,y:n.y+o};case"left":return{x:n.x-o,y:n.y};case"right":return{x:n.x+o,y:n.y}}}var Zt=["right","left","bottom","top"];function Vt(n){return n==="left"||n==="right"?0:1}function Tt(n){return n==="right"||n==="bottom"?1:-1}function Ne(n,t){switch(t){case"left":return n.x;case"right":return n.x+n.width;case"top":return n.y;case"bottom":return n.y+n.height}}function Wt(n,t){return Vt(t)===0?[n.y,n.y+n.height]:[n.x,n.x+n.width]}function Pt(n,t){let[o,e]=Wt(n,t),r=Math.min(20,(e-o)/2);return[o+r,e-r]}function Qn(n,t){let[o,e]=Wt(n,t);return(o+e)/2}function Jn(n,t,o){let e=Ne(n,t)+Tt(t)*20;return Vt(t)===0?{x:e,y:o}:{x:o,y:e}}function En(n,t){switch(t){case"right":return{x:n.x-20,y:n.y,side:t};case"left":return{x:n.x+20,y:n.y,side:t};case"bottom":return{x:n.x,y:n.y-20,side:t};case"top":return{x:n.x,y:n.y+20,side:t}}}function sn(n,t,o,e){return n.x-t<o.x+o.width+e&&o.x-e<n.x+n.width+t&&n.y-t<o.y+o.height+e&&o.y-e<n.y+n.height+t}function $t(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=e,s=Math.abs(r.x-c.x)<.01&&Math.abs(c.x-o.x)<.01,i=Math.abs(r.y-c.y)<.01&&Math.abs(c.y-o.y)<.01;if(s||i){t[t.length-1]={x:o.x,y:o.y};continue}}t.push({x:o.x,y:o.y})}}return t}function te(n,t,o,e){let r=o.x+e,c=o.x+o.width-e,s=o.y+e,i=o.y+o.height-e;if(c<=r||i<=s)return!1;if(Math.abs(n.x-t.x)<.01){if(n.x<=r||n.x>=c)return!1;let a=Math.min(n.y,t.y),f=Math.max(n.y,t.y);return Math.min(f,i)-Math.max(a,s)>0}if(Math.abs(n.y-t.y)<.01){if(n.y<=s||n.y>=i)return!1;let a=Math.min(n.x,t.x),f=Math.max(n.x,t.x);return Math.min(f,c)-Math.max(a,r)>0}for(let a=.05;a<1;a+=.05){let f=n.x+(t.x-n.x)*a,u=n.y+(t.y-n.y)*a;if(f>r&&f<c&&u>s&&u<i)return!0}return!1}var It=class{constructor(t,o=160){this.rects=t;K(this,"x0");K(this,"y0");K(this,"cols");K(this,"rows");K(this,"cells");K(this,"seen");K(this,"stamp",0);K(this,"cell");let e=1/0,r=1/0,c=-1/0,s=-1/0;for(let i of t)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x+i.width),s=Math.max(s,i.y+i.height);t.length||(e=r=0,c=s=1),this.x0=e,this.y0=r,this.cell=Math.max(o,Math.max(c-e,s-r)/256),o=this.cell,this.cols=Math.max(1,Math.ceil((c-e)/o)+1),this.rows=Math.max(1,Math.ceil((s-r)/o)+1),this.cells=Array.from({length:this.cols*this.rows},()=>[]),this.seen=new Uint32Array(t.length),t.forEach((i,a)=>{let[f,u]=this.cellOf(i.x,i.y),[l,h]=this.cellOf(i.x+i.width,i.y+i.height);for(let m=u;m<=h;m++)for(let d=f;d<=l;d++)this.cells[m*this.cols+d].push(a)})}cellOf(t,o){let e=Math.min(this.cols-1,Math.max(0,Math.floor((t-this.x0)/this.cell))),r=Math.min(this.rows-1,Math.max(0,Math.floor((o-this.y0)/this.cell)));return[e,r]}query(t,o,e,r,c=[]){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let[s,i]=this.cellOf(t,o),[a,f]=this.cellOf(e,r);for(let u=i;u<=f;u++)for(let l=s;l<=a;l++)for(let h of this.cells[u*this.cols+l])this.seen[h]!==this.stamp&&(this.seen[h]=this.stamp,c.push(h));return c}};function Ue(n){let t=Float64Array.from(n.filter(r=>Number.isFinite(r))).sort(),o=[],e=-1/0;for(let r of t)r-e>1&&(o.push(r),e=r);return Float64Array.from(o)}function wn(n,t,o){let e=Array.from(Ue(n)),r=Float64Array.from(t.filter(a=>Number.isFinite(a))).sort(),c=[],s=0;for(let a of r){for(;s<e.length&&e[s]<a-o;)s++;s<e.length&&Math.abs(e[s]-a)<=o||s>0&&Math.abs(e[s-1]-a)<=o||c.length&&a-c[c.length-1]<=o||c.push(a)}return Float64Array.from([...e,...c]).sort()}function Rt(n,t){let o=0,e=n.length-1,r=-1;for(;o<=e;){let c=o+e>>1;n[c]<=t+1e-6?(r=c,o=c+1):e=c-1}return r}function Nt(n,t){let o=0,e=n.length-1,r=n.length;for(;o<=e;){let c=o+e>>1;n[c]>=t-1e-6?(r=c,e=c-1):o=c+1}return r}var Et=null;function an(n,t){let o=n.length*t.length;if(!Et||Et.hBlk.length<o){let r=Math.max(o,Math.ceil((Et?.hBlk.length??0)*1.5));Et={hBlk:new Uint16Array(r),vBlk:new Uint16Array(r),hUse:new Uint8Array(r),vUse:new Uint8Array(r),hZone:new Uint8Array(r),vZone:new Uint8Array(r)}}let e={xs:n,ys:t,nx:n.length,ny:t.length,hBlk:Et.hBlk.subarray(0,o),vBlk:Et.vBlk.subarray(0,o),hUse:Et.hUse.subarray(0,o),vUse:Et.vUse.subarray(0,o),hZone:Et.hZone.subarray(0,o),vZone:Et.vZone.subarray(0,o)};return e.hBlk.fill(0),e.vBlk.fill(0),e.hUse.fill(0),e.vUse.fill(0),e.hZone.fill(0),e.vZone.fill(0),e}function un(n,t,o,e,r,c){let s=Rt(n.xs,t),i=Rt(n.xs,e),a=Rt(n.ys,o),f=Rt(n.ys,r);if(s<0||a<0||i<=s||f<=a)return;let{nx:u,hBlk:l,vBlk:h}=n;for(let m=a+1;m<f;m++){let d=m*u;for(let y=s;y<i;y++)l[d+y]+=c}for(let m=a;m<f;m++){let d=m*u;for(let y=s+1;y<i;y++)h[d+y]+=c}}function ne(n,t){for(let o=1;o<t.length;o++){let e=t[o-1],r=t[o],c=e<r?e:r;Math.abs(e-r)===1?n.hUse[c]<255&&n.hUse[c]++:n.vUse[c]<255&&n.vUse[c]++}}function Lt(n,t){let o=0,e=n.length;for(;o<e;){let r=o+e>>1;n[r]>t?e=r:o=r+1}return o}function Qt(n,t,o,e,r,c){ee(n,n.hZone,n.vZone,t,o,e,r,c)}function Ht(n,t,o,e,r,c){ee(n,n.hBlk,n.vBlk,t,o,e,r,c)}function ee(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,ny:l}=n,h=.5,m=Lt(f,r+h),d=Lt(f,s-h)-1,y=Math.max(0,Lt(a,e+h)-1),P=Math.min(u-2,Lt(a,c-h-1e-9)-1);for(let A=m;A<=d&&A<l;A++){let w=A*u;for(let C=y;C<=P;C++)a[C+1]>e+h&&a[C]<c-h&&(t[w+C]+=i)}let b=Lt(a,e+h),p=Lt(a,c-h)-1,R=Math.max(0,Lt(f,r+h)-1),S=Math.min(l-2,Lt(f,s-h-1e-9)-1);for(let A=R;A<=S;A++){if(!(f[A+1]>r+h&&f[A]<s-h))continue;let w=A*u;for(let C=b;C<=p&&C<u;C++)o[w+C]+=i}}function cn(n,t,o){let e=Rt(n,t),r=-1,c=o;for(let s of[e,e+1]){if(s<0||s>=n.length)continue;let i=Math.abs(n[s]-t);i<=c&&(r=s,c=i)}return r}function kn(n,t,o=.01){let{xs:e,ys:r,nx:c,hUse:s,vUse:i}=n;for(let a=1;a<t.length;a++){let f=t[a-1],u=t[a];if(Math.abs(f.y-u.y)<.01){let l=cn(r,f.y,o);if(l<0)continue;let h=Math.max(0,Rt(e,Math.min(f.x,u.x))),m=Math.min(c-1,Nt(e,Math.max(f.x,u.x)));for(let d=h;d<m;d++)s[l*c+d]<255&&s[l*c+d]++}else if(Math.abs(f.x-u.x)<.01){let l=cn(e,f.x,o);if(l<0)continue;let h=Math.max(0,Rt(r,Math.min(f.y,u.y))),m=Math.min(n.ny-1,Nt(r,Math.max(f.y,u.y)));for(let d=h;d<m;d++)i[d*c+l]<255&&i[d*c+l]++}}}var re=(n,t)=>n*2+(t>0?0:1),vn=class{constructor(){K(this,"f",new Float64Array(1024));K(this,"g",new Float64Array(1024));K(this,"s",new Int32Array(1024));K(this,"size",0);K(this,"topF",0);K(this,"topG",0);K(this,"topS",0)}clear(){this.size=0}grow(){let t=this.f.length*2,o=new Float64Array(t),e=new Float64Array(t),r=new Int32Array(t);o.set(this.f),e.set(this.g),r.set(this.s),this.f=o,this.g=e,this.s=r}push(t,o,e){this.size===this.f.length&&this.grow();let r=this.size++,c=this.f,s=this.g,i=this.s;for(;r>0;){let a=r-1>>1;if(c[a]<t||c[a]===t&&s[a]>=e)break;c[r]=c[a],s[r]=s[a],i[r]=i[a],r=a}c[r]=t,s[r]=e,i[r]=o}pop(){let t=this.f,o=this.g,e=this.s;this.topF=t[0],this.topG=o[0],this.topS=e[0];let r=--this.size;if(r===0)return;let c=t[r],s=o[r],i=e[r],a=0;for(;;){let f=2*a+1;if(f>=r)break;let u=f+1,l=f;if(u<r&&(t[u]<t[f]||t[u]===t[f]&&o[u]>o[f])&&(l=u),t[l]>c||t[l]===c&&o[l]<=s)break;t[a]=t[l],o[a]=o[l],e[a]=e[l],a=l}t[a]=c,o[a]=s,e[a]=i}},ln=class{constructor(){K(this,"cap",0);K(this,"gScore",new Float64Array(0));K(this,"stamp",new Uint32Array(0));K(this,"parent",new Int32Array(0));K(this,"seedOf",new Int32Array(0));K(this,"goalStamp",new Uint32Array(0));K(this,"goalOf",new Int32Array(0));K(this,"id",0);K(this,"heap",new vn);K(this,"lastPops",0);K(this,"targetBuf",new Float64Array(20));K(this,"zeroBuf",new Uint8Array(0))}zeros(t){return this.zeroBuf.length<t&&(this.zeroBuf=new Uint8Array(t)),this.zeroBuf}ensure(t){if(t*4<=this.cap)return;let o=Math.max(t*4,Math.ceil(this.cap*1.5));this.cap=o,this.gScore=new Float64Array(o),this.stamp=new Uint32Array(o),this.parent=new Int32Array(o),this.seedOf=new Int32Array(o),this.goalStamp=new Uint32Array(o>>2),this.goalOf=new Int32Array(o>>2),this.id=0}search(t,o,e,r,c=!0,s=1.1,i=80){let{xs:a,ys:f,nx:u,ny:l,hBlk:h,vBlk:m,hUse:d,vUse:y}=t,P=c?t.hZone:this.zeros(u*l),b=c?t.vZone:this.zeros(u*l),p=2,R=0;this.ensure(u*l),++this.id>=4294967280&&(this.stamp.fill(0),this.goalStamp.fill(0),this.id=1);let S=this.id,{gScore:A,stamp:w,parent:C,seedOf:v,goalStamp:k,goalOf:N,heap:B}=this;B.clear(),this.lastPops=0;let U=this.targetBuf,Y=0;for(let z=0;z<e.length;z++){let L=e[z],F=L.node;(k[F]!==S||L.cost<e[N[F]].cost)&&(k[F]=S,N[F]=z);let V=L.orient===0?1:0,Q=L.dir,T=0;for(;T<Y&&!(U[T*5]===V&&U[T*5+1]===Q);)T++;T===Y?(U[T*5]=V,U[T*5+1]=Q,U[T*5+2]=(V?L.point.x:L.point.y)*Q,U[T*5+3]=L.c,U[T*5+4]=L.c,Y++):(L.c<U[T*5+3]&&(U[T*5+3]=L.c),L.c>U[T*5+4]&&(U[T*5+4]=L.c))}let G=s,lt=(z,L,F)=>{let V=F<2?1:0,Q=F&1?-1:1,T=1/0;for(let ot=0;ot<Y;ot++){let it=ot*5,H=U[it],et=U[it+1],xt=U[it+2],Ct=U[it+3],Dt=U[it+4],kt=(H?z:L)*et,At=H?L:z,Xt=kt<xt-.5,St=At<Ct?Ct-At:At>Dt?At-Dt:0,vt;V===H?Q*et>0?vt=Xt?St===0?0:2:4:vt=2:Xt?St===0?vt=1:vt=At<Ct&&Q>0||At>Dt&&Q<0?1:3:vt=3;let Kt=(xt>kt?xt-kt:kt-xt)+St+vt*40;Kt<T&&(T=Kt)}return T*G};for(let z=0;z<o.length;z++){let L=o[z],F=re(L.orient,L.dir),V=L.node*4+F;if(w[V]===S&&A[V]<=L.cost)continue;w[V]=S,A[V]=L.cost,C[V]=-1,v[V]=z;let Q=L.node%u;B.push(L.cost+lt(a[Q],f[(L.node-Q)/u],F),V,L.cost)}let q=0,nt=0,at=0,_=0,j=(z,L,F,V,Q,T,ot,it)=>{let H=at+Q*(1+.25*T+(it?p:0))+(V>>1!==_>>1?40:0)+(ot?i:0),et=z*4+V;w[et]===S&&H>=A[et]-1e-9||(w[et]=S,A[et]=H,C[et]=nt,B.push(H+lt(L,F,V),et,H))};for(;B.size>0;){B.pop();let z=B.topS;if(z<0)return this.lastPops=q,this.build(-1-z,o,e,B.topF);let L=B.topG;if(L>A[z]+1e-9)continue;if(++q>r)return this.lastPops=q,null;let F=z>>2,V=z&3;if(nt=z,at=L,_=V,k[F]===S){let H=e[N[F]],et=re(H.orient,H.dir),xt=-1;V===et?xt=L+H.cost:V>>1!==et>>1&&(xt=L+40+H.cost),xt>=0&&B.push(xt,-1-z,xt)}let Q=F%u,T=(F-Q)/u,ot=a[Q],it=f[T];if(V!==1&&Q+1<u&&h[F]===0&&!(P[F]&R)){let H=F+1,et=a[Q+1];j(H,et,it,0,et-ot,d[F],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F])}if(V!==0&&Q>0&&h[F-1]===0&&!(P[F-1]&R)){let H=F-1,et=a[Q-1];j(H,et,it,1,ot-et,d[H],T>0&&T+1<l&&y[H]>0&&y[H-u]>0,P[F-1])}if(V!==3&&T+1<l&&m[F]===0&&!(b[F]&R)){let H=F+u,et=f[T+1];j(H,ot,et,2,et-it,y[F],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F])}if(V!==2&&T>0&&m[F-u]===0&&!(b[F-u]&R)){let H=F-u,et=f[T-1];j(H,ot,et,3,it-et,y[H],Q>0&&Q+1<u&&d[H]>0&&d[H-1]>0,b[F-u])}}return this.lastPops=q,null}build(t,o,e,r){let c=[],s=t,i=o[0];for(let f=0;f<1e6;f++){c.push(s>>2);let u=this.parent[s];if(u<0){i=o[this.seedOf[s]];break}s=u}c.reverse();let a=e[this.goalOf[t>>2]];return{nodes:c,src:i,tgt:a,cost:r}}};var Ut=.01,ie=[];function xn(n,t){return Math.abs(n[t].x-n[t+1].x)<Ut}var ct=(n,t)=>n?t.x:t.y,st=(n,t)=>n?t.y:t.x;function _n(n,t,o,e,r,c,s,i){let a=e-i,f=e+i,u=o?n.buckets.query(e-i-s,r-s,e+i+s,c+s,ie):n.buckets.query(r-s,e-i-s,c+s,e+i+s,ie),l=t.ignore;for(let h=0;h<u.length;h++){let m=u[h];if(l&&l.has(m))continue;let d=n.rects[m],y=m>=n.zoneFrom?1:m===t.own[0]||m===t.own[1]?Math.max(s,29):s,P=o?d.y:d.x;if((o?d.y+d.height:d.x+d.width)+y<=r+.5||P-y>=c-.5)continue;let p=o?d.x:d.y,R=o?d.x+d.width:d.y+d.height;R<=e+.5?R+y>a&&(a=R+y):p>=e-.5&&p-y<f&&(f=p-y)}return[Math.min(a,e),Math.max(f,e)]}function mn(n,t,o,e){o?(n[t]={x:e,y:n[t].y},n[t+1]={x:e,y:n[t+1].y}):(n[t]={x:n[t].x,y:e},n[t+1]={x:n[t+1].x,y:e})}function ae(n,t){for(let o=0;o<n.length;o++){let e=n[o];for(let r=0;r<12&&Ge(n,o,t);r++)e.pts=$t(e.pts)}}function Ge(n,t,o){let e=n[t].pts,r=e.length-2;for(let c=1;c<r;c++){let s=!xn(e,c),i=Math.sign(st(s,e[c])-st(s,e[c-1])),a=Math.sign(st(s,e[c+2])-st(s,e[c+1]));if(!(i===0||i!==a)&&(ce(n,t,c-1,-1,s,ct(s,e[c+1]),o)||ce(n,t,c+1,1,s,ct(s,e[c]),o)))return!0}return!1}function ce(n,t,o,e,r,c,s){let i=n[t],a=i.pts,f=a.length-2,u=ct(r,a[o]);if(Math.abs(c-u)<.5)return!1;let l=o+e;if(l<0||l>f){let[R,S]=o===0?Pt(i.src,i.srcSide):Pt(i.tgt,i.tgtSide);if(c<R-.01||c>S+.01)return!1}else{let R=e<0?a[o-1]:a[o+2],S=e<0?a[o]:a[o+1],A=ct(r,S)-ct(r,R),w=c-ct(r,R);if(A===0||Math.sign(A)!==Math.sign(w))return!1;let C=l===0||l===f;if(Math.abs(w)<(C?10:10)-.01)return!1}let h=Math.min(st(r,a[o]),st(r,a[o+1])),m=Math.max(st(r,a[o]),st(r,a[o+1])),[d,y]=_n(s,i,r,u,h,m,16,Math.abs(c-u)+1);if(c<d-.01||c>y+.01)return!1;let P=dn(n,t,o),b=a[o],p=a[o+1];return mn(a,o,r,c),Fn(n,t,o),dn(n,t,o)>P?(a[o]=b,a[o+1]=p,!1):!0}function Be(n,t,o,e){let r=Math.abs(n.x-t.x)<Ut,c=Math.abs(o.x-e.x)<Ut;if(r===c)return!1;let[s,i,a,f]=r?[n,t,o,e]:[o,e,n,t],u=s.x,l=a.y;return u>Math.min(a.x,f.x)+Ut&&u<Math.max(a.x,f.x)-Ut&&l>Math.min(s.y,i.y)+Ut&&l<Math.max(s.y,i.y)-Ut}var ht=class ht{constructor(t){K(this,"cells",new Map);K(this,"seen",new Uint32Array(0));K(this,"stamp",0);this.seen=new Uint32Array(t.length),t.forEach((o,e)=>{for(let r=1;r<o.pts.length;r++)this.add(e,o.pts[r-1],o.pts[r])})}static cellOf(t){let o=Math.floor(t/ht.CELL);return Math.max(-ht.LIMIT,Math.min(ht.LIMIT,Number.isFinite(o)?o:0))}static key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=ht.cellOf(Math.min(o.x,e.x)),c=ht.cellOf(Math.max(o.x,e.x)),s=ht.cellOf(Math.min(o.y,e.y)),i=ht.cellOf(Math.max(o.y,e.y));for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=ht.key(f,a),l=this.cells.get(u);l?l.includes(t)||l.push(t):this.cells.set(u,[t])}}near(t,o,e,r,c){c.length=0,++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=ht.cellOf(t),i=ht.cellOf(e),a=ht.cellOf(o),f=ht.cellOf(r);for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(ht.key(l,u));if(h)for(let m of h)this.seen[m]!==this.stamp&&(this.seen[m]=this.stamp,c.push(m))}return c}};K(ht,"CELL",200),K(ht,"LIMIT",28672);var Ln=ht,Nn=new WeakMap;function ze(n){let t=Nn.get(n);return t||(t=new Ln(n),Nn.set(n,t)),t}function Fn(n,t,o){let e=Nn.get(n);if(!e)return;let r=n[t].pts;for(let c=Math.max(1,o);c<=Math.min(r.length-1,o+2);c++)e.add(t,r[c-1],r[c])}var $e=[];function dn(n,t,o){let e=n[t].pts,r=0,c=Math.max(0,o-1),s=Math.min(e.length-2,o+1),i=1/0,a=1/0,f=-1/0,u=-1/0;for(let l=c;l<=s+1;l++)i=Math.min(i,e[l].x),a=Math.min(a,e[l].y),f=Math.max(f,e[l].x),u=Math.max(u,e[l].y);for(let l of ze(n).near(i,a,f,u,$e)){if(l===t)continue;let h=n[l].pts;for(let m=1;m<h.length;m++){let d=h[m-1],y=h[m];if(!(Math.max(d.x,y.x)<i||Math.min(d.x,y.x)>f||Math.max(d.y,y.y)<a||Math.min(d.y,y.y)>u))for(let P=c;P<=s;P++)Be(e[P],e[P+1],d,y)&&r++}}return r}function Dn(n,t,o){for(let e=0;e<n.length;e++){let r=n[e],c=r.pts,s=c.length-2;for(let i=1;i<s;i++){if(xn(c,i)!==t)continue;let a=c[i-1],f=c[i],u=c[i+1],l=c[i+2],h=ct(t,f),m=Math.sign(h-ct(t,a)),d=Math.sign(ct(t,l)-ct(t,u));if(m===0||m!==d)continue;let y=i-1===0?10:10,P=i+1===s?10:10,b=m>0?ct(t,a)+y:ct(t,l)+P,p=m>0?ct(t,l)-P:ct(t,a)-y;if(b>p)continue;let R=Math.max(Math.abs(b-h),Math.abs(p-h))+1,S=Math.min(st(t,f),st(t,u)),A=Math.max(st(t,f),st(t,u)),[w,C]=_n(o,r,t,h,S,A,16,R);if(b=Math.max(b,w),p=Math.min(p,C),b>p)continue;let v=(b+p)/2;if(Math.abs(v-h)<=.5)continue;let k=dn(n,e,i);mn(c,i,t,v),Fn(n,e,i),dn(n,e,i)>k&&mn(c,i,t,h)}}}function hn(n,t,o,e){return(st(e,n[t+1])-st(e,n[t]))*o>0?t+2>=n.length?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t+2])-ct(e,n[t+1])),next:t+1}:t===0?{dir:0,next:-1}:{dir:Math.sign(ct(e,n[t-1])-ct(e,n[t])),next:t-1}}function Un(n,t,o,e,r,c){let s=xn(n,t),i=(h,m)=>r>0?Math.max(st(s,h[m]),st(s,h[m+1])):Math.min(st(s,h[m]),st(s,h[m+1])),a=(i(n,t)-i(o,e))*r;if(a>.5){let h=hn(o,e,r,s).dir;return h===0?0:h>0?-1:1}if(a<-.5){let h=hn(n,t,r,s).dir;return h===0?0:h>0?1:-1}let f=hn(n,t,r,s),u=hn(o,e,r,s);if(f.dir===0||u.dir===0)return 0;if(f.dir!==u.dir)return f.dir<u.dir?-1:1;if(c>=8||f.next<0||u.next<0)return 0;let l=Un(n,f.next,o,u.next,f.dir,c+1);return l===0?0:-l*r*f.dir}function Tn(n,t,o){let e=Xe(n,t,o),r=e.length;if(r<2)return;let c=[],s=new Set,i=new Int32Array(r);for(let b=0;b<r;b++)i[b]=b;let a=b=>{for(;i[b]!==b;)i[b]=i[i[b]],b=i[b];return b},f=(b,p)=>{let R=a(b),S=a(p);R!==S&&(i[R<S?S:R]=R<S?R:S)},u=(b,p,R)=>{let S=b<p?b*r+p:p*r+b;if(s.has(S))return;s.add(S);let A=e[b],w=e[p],C=He(A,w),v=A.c<w.c||A.c===w.c&&b<p?-1:1;if(R){let lt=n[A.p].pts,q=n[w.p].pts,nt=Un(lt,A.k,q,w.k,1,0);nt===0&&(nt=Un(lt,A.k,q,w.k,-1,0)),nt===0&&(nt=Math.abs(A.c-w.c)>3?A.c<w.c?-1:1:Ke(n,A,w,t)),v=nt<0?-1:1}let k=n[A.p],N=n[w.p],U=k.src===N.src&&k.tgt===N.tgt||k.src===N.tgt&&k.tgt===N.src?30:C?24:12,[Y,G]=v<0?[A,w]:[w,A];Y.lb+U/2>G.ub&&G.lb+U/2<=Y.ub&&(v=v<0?1:-1),c.push({a:b,b:p,sep:U,order:v}),f(b,p)},l=e.map((b,p)=>p).sort((b,p)=>e[b].c-e[p].c||b-p);for(let b=0;b<r;b++){let p=e[l[b]];for(let R=b+1;R<r;R++){let S=e[l[R]];if(S.c-p.c>3)break;p.p!==S.p&&On(p,S)&&u(l[b],l[R],!0)}}let h=new Map;e.forEach((b,p)=>{for(let R of[b.keyA,b.keyB]){if(!R)continue;let S=h.get(R);S?S.push(p):h.set(R,[p])}});for(let b of h.values())for(let p=0;p<b.length;p++)for(let R=p+1;R<b.length;R++)e[b[p]].p!==e[b[R]].p&&u(b[p],b[R],!0);let m=new Float64Array(r);for(let b=0;b<r;b++)m[b]=Math.min(Math.max(e[b].c,e[b].lb),e[b].ub);let d=b=>{let p=new Map;for(let S=0;S<r;S++){let A=a(S);if(!b.has(A))continue;let w=p.get(A);w?w.push(S):p.set(A,[S])}let R=new Map;for(let S of c){let A=a(S.a);if(!b.has(A))continue;let w=R.get(A);w?w.push(S):R.set(A,[S])}return{members:p,groupRels:R}},y=(b,p)=>{if(b.length<2)return;let R=Ye(b,p,e,n),S=new Map,A=()=>(S.clear(),R.forEach((C,v)=>S.set(C,v)),p.map(C=>{let v=S.get(C.a)<S.get(C.b),k=v?C.a:C.b,N=v?C.b:C.a,B=C.order<0!==v;return{u:k,v:N,sep:Math.max(0,Math.min(C.sep,e[N].ub-e[k].lb)),broken:B}})),w=A();ue(R,w,e,0)||(R=[...b].sort((C,v)=>e[C].c-e[v].c||n[e[C].p].rank-n[e[v].p].rank||e[C].k-e[v].k),w=A()),qe(R,w,e,m)},P=new Set;for(let b=0;b<r;b++)P.add(a(b));{let{members:b,groupRels:p}=d(P);for(let R of P)y(b.get(R)??[],p.get(R)??[])}for(let b=0;b<8;b++){let p=new Set,R=e.map((k,N)=>N).sort((k,N)=>m[k]-m[N]||k-N);for(let k=0;k<r;k++){let N=R[k];for(let B=k+1;B<r;B++){let U=R[B];if(m[U]-m[N]>=12-.01)break;a(N)===a(U)||e[N].p===e[U].p||!On(e[N],e[U])||(u(N,U,Math.abs(e[N].c-e[U].c)<=3),p.add(a(N)))}}let S=[];for(let k=0;k<r;k++){let N=l[k];for(let B=k+1;B<r;B++){let U=l[B];if(e[U].c-e[N].c>40)break;let Y=N<U?N:U,G=N<U?U:N;if(a(Y)===a(G)||e[Y].p===e[G].p)continue;let lt=e[Y].c-e[G].c,q=m[Y]-m[G];lt*q>=0||!On(e[Y],e[G])||S.push(Y,G)}}let A=Array.from({length:S.length/2},(k,N)=>N).sort((k,N)=>S[2*k]-S[2*N]||S[2*k+1]-S[2*N+1]);for(let k of A){let N=S[2*k],B=S[2*k+1];a(N)!==a(B)&&(u(N,B,!1),p.add(a(N)))}if(!p.size)break;let w=new Set;for(let k of p)w.add(a(k));let{members:C,groupRels:v}=d(w);for(let k of w)y(C.get(k)??[],v.get(k)??[])}for(let b=0;b<r;b++){let p=e[b];Math.abs(m[b]-ct(t,n[p.p].pts[p.k]))>1e-6&&(mn(n[p.p].pts,p.k,t,m[b]),Fn(n,p.p,p.k))}}function On(n,t){return Math.min(n.hi,t.hi)-Math.max(n.lo,t.lo)>=-1}function He(n,t){return n.keyA!==""&&(n.keyA===t.keyA||n.keyA===t.keyB)||n.keyB!==""&&(n.keyB===t.keyA||n.keyB===t.keyB)}function Xe(n,t,o){let e=[],r=(c,s)=>`${c.id}\0${s}`;for(let c=0;c<n.length;c++){let s=n[c],i=s.pts,a=i.length-2;for(let f=0;f<=a;f++){if(xn(i,f)!==t)continue;let u=ct(t,i[f]),l=Math.min(st(t,i[f]),st(t,i[f+1])),h=Math.max(st(t,i[f]),st(t,i[f+1]));if(h-l<Ut)continue;let[m,d]=_n(o,s,t,u,l,h,16,120),y="",P="";if(f===0){let[b,p]=Pt(s.src,s.srcSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),y=r(s.src,s.srcSide)}if(f===a){let[b,p]=Pt(s.tgt,s.tgtSide);m=Math.max(m,Math.min(b,u)),d=Math.min(d,Math.max(p,u)),P=r(s.tgt,s.tgtSide)}if(f===1){let b=ct(t,i[0]);Tt(s.srcSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}if(f===a-1){let b=ct(t,i[a+1]);Tt(s.tgtSide)>0?m=Math.max(m,Math.min(u,b+10)):d=Math.min(d,Math.max(u,b-10))}for(let b of[f-2,f+2]){if(b<0||b>a)continue;let p=ct(t,i[b]),R=Math.abs(p-u),S=Math.max(0,(R-Math.min(R,10))/2);p<u?m=Math.max(m,u-S):p>u&&(d=Math.min(d,u+S))}e.push({p:c,k:f,c:u,lo:l,hi:h,keyA:y,keyB:P,lb:m,ub:d,w:y||P?3:1})}}return e}function Ke(n,t,o,e){let r=n[t.p].rank<=n[o.p].rank?t:o,c=n[r.p].pts,s=Math.sign(st(e,c[r.k+1])-st(e,c[r.k]))||1,a=(e?s:-s)<0;return(r===t?a:!a)?-1:1}function Ye(n,t,o,e){let r=n.length,c=new Map;n.forEach((l,h)=>c.set(l,h));let s=new Int32Array(r),i=Array.from({length:r},()=>[]);for(let l of t){let h=c.get(l.order<0?l.a:l.b),m=c.get(l.order<0?l.b:l.a);i[h].push(m),s[m]++}let a=(l,h)=>{let m=o[n[l]],d=o[n[h]];if(m.c!==d.c)return m.c<d.c;let y=e[m.p].rank,P=e[d.p].rank;return y!==P?y<P:m.k<d.k},f=new Uint8Array(r),u=[];for(let l=0;l<r;l++){let h=-1;for(let m=0;m<r;m++)f[m]||s[m]!==0||(h<0||a(m,h))&&(h=m);if(h<0)for(let m=0;m<r;m++)f[m]||(h<0||s[m]<s[h]||s[m]===s[h]&&a(m,h))&&(h=m);f[h]=1,u.push(n[h]);for(let m of i[h])s[m]--}return u}function qe(n,t,o,e){let r=Ze(n,t.filter(c=>!c.broken),o);for(let c of n)e[c]=Math.min(Math.max(o[c].c,o[c].lb),o[c].ub);for(let c=0;c<100;c++){let s=0;for(let{u:i,v:a,sep:f}of t){let u=f*r,l=e[i],h=e[a],m=u-(h-l);if(m<=.001)continue;m>s&&(s=m);let d=o[i],y=o[a],P=m*y.w/(d.w+y.w),b=m-P,p=l-d.lb,R=y.ub-h;P>p&&(b+=P-p,P=p),b>R&&(P=Math.min(p,P+(b-R)),b=R),e[i]=l-Math.max(0,P),e[a]=h+Math.max(0,b)}if(s<.05)break}}function ue(n,t,o,e){let r=new Map;for(let s of t){let i=r.get(s.v);i?i.push({u:s.u,sep:s.sep}):r.set(s.v,[{u:s.u,sep:s.sep}])}let c=new Map;for(let s of n){let i=o[s].lb;for(let{u:a,sep:f}of r.get(s)??[]){let u=c.get(a);u!==void 0&&(i=Math.max(i,u+f*e))}if(i>o[s].ub+1e-6)return!1;c.set(s,i)}return!0}function Ze(n,t,o){let e=s=>ue(n,t,o,s);if(e(1))return 1;let r=0,c=1;for(let s=0;s<10;s++){let i=(r+c)/2;e(i)?r=i:c=i}return r}var Qe=55,Je=18,gn={halfWidth:34,height:28,anchorRoom:8};function Jt(){let n={memo:null,searcher:new ln};return{route:t=>eo(n,t),reset:()=>{n.memo=null}}}var _t=n=>`${n.x},${n.y},${n.width},${n.height}`,Ft=58+2*12;function le(n,t,o){let e=Math.min(t.x,o.x),r=Math.min(t.y,o.y),c=Math.max(t.x+t.width,o.x+o.width),s=Math.max(t.y+t.height,o.y+o.height);for(let i of n)e=Math.min(e,i.x),r=Math.min(r,i.y),c=Math.max(c,i.x),s=Math.max(s,i.y);return{x0:e-Ft,y0:r-Ft,x1:c+Ft,y1:s+Ft}}function to(n,t,o){let e=n.length;for(let r=0;r<e;r++){let c=n[r],s=c.x+c.width,i=c.y+c.height,a=1/0,f=1/0;for(let u=0;u<e;u++){if(r===u)continue;let l=n[u];l.x>=s&&l.y<i-16&&c.y<l.y+l.height-16&&l.x<a&&(a=l.x),l.y>=i&&l.x<s-16&&c.x<l.x+l.width-16&&l.y<f&&(f=l.y)}a<1/0&&a-s>2*16&&t.push((s+a)/2),f<1/0&&f-i>2*16&&o.push((i+f)/2)}}function no(n){let t=Qe+Je*n.loopIndex,o=qt(n.sourceAnchor,n.sourceAnchor.side,20),e=qt(n.targetAnchor,n.targetAnchor.side,20),r=Math.min(o.x,e.x)-gn.anchorRoom,c=Math.max(o.x,e.x)+.75*t+gn.halfWidth,s=Math.min(o.y,e.y)-.75*t-gn.height,i=Math.max(o.y,e.y)+gn.anchorRoom;return{id:`${n.id}#loop`,x:r,y:s,width:c-r,height:i-s,kind:"annotation"}}function fe(n,t,o,e,r,c,s,i){let{xs:a,ys:f,nx:u,hBlk:l,vBlk:h,hUse:m,vUse:d}=n,y=Vt(o),P=Tt(o),[b,p]=Pt(t,o),R=Qn(t,o),S=y===0?f:a,A=y===0?a:f,w=Nt(S,b-1),C=Rt(S,p+1);for(let v=w;v<=C;v++){let k=S[v],N=Jn(t,o,k),B=y===0?N.x:N.y,U,Y,G;if(P>0){if(U=Nt(A,B+10),U>=A.length)continue;Y=Math.max(0,Rt(A,B)),G=U-1}else{if(U=Rt(A,B-10),U<0)continue;Y=U,G=Math.min(A.length-1,Nt(A,B))-1}let lt=!0,q=0;for(let _=Y;_<=G&&lt;_++){let j=y===0?v*u+_:_*u+v;if(lt=(y===0?l[j]:h[j])===0,!lt)break;let z=y===0?m[j]:d[j];z&&(q+=.25*z*Math.abs(A[_+1]-A[_])),_>Y&&(y===0?j>=u&&d[j]>0&&d[j-u]>0:j%u>0&&m[j]>0&&m[j-1]>0)&&(q+=80*3)}if(!lt)continue;{let _=B-P*20,j=Math.min(_,B),z=Math.max(_,B);for(let L=Nt(A,j+.5);L<A.length&&A[L]<=z+.5;L++)(y===0?v>0&&d[v*u+L]>0&&d[(v-1)*u+L]>0:v>0&&m[L*u+v]>0&&m[L*u+v-1]>0)&&(q+=80*3)}if(c)for(let _ of c){if(_.other===s)continue;let j=1-Math.abs(k-_.c)/24;j>0&&(q+=400*j)}i&&(q+=i.side===o?2*Math.abs(k-i.c):100);let nt=y===0?v*u+U:U*u+v,at=k-R;r.push({side:o,c:k,point:N,node:nt,orient:y,dir:e?-P:P,cost:1.1*Math.abs(at)+.002*at*at+Math.abs(A[U]-B)+q,lane:v,legLo:Y,legHi:G})}}function he(n,t,o){let[e,r]=Pt(n,o),[c,s]=Pt(t,o),i=Math.max(e,c),a=Math.min(r,s);return i<=a?(i+a)/2:null}function pn(n,t,o,e=.01){let r=Vt(t),c=r===0?n.xs:n.ys,s=r===0?n.ys:n.xs,i=r===0?o.y:o.x,a=cn(s,i,e);if(a<0)return;let f=r===0?o.x:o.y,u=f-Tt(t)*20,l=Math.min(f,u),h=Math.max(f,u),m=Math.max(0,Rt(c,l)-1),d=Math.min(c.length-2,Nt(c,h)),{nx:y,hUse:P,vUse:b}=n;for(let p=m;p<=d;p++){if(c[p+1]<=l+.5||c[p]>=h-.5)continue;let R=r===0?a*y+p:p*y+a;r===0?P[R]<255&&P[R]++:b[R]<255&&b[R]++}}function me(n,t){let{nx:o,hUse:e,vUse:r}=n;for(let c=t.legLo;c<=t.legHi;c++)if(t.orient===0){let s=t.lane*o+c;e[s]<255&&e[s]++}else{let s=c*o+t.lane;r[s]<255&&r[s]++}}function Mn(n,t){switch(t){case"top":return{x0:n.x,y0:n.y-42,x1:n.x+n.width,y1:n.y};case"bottom":return{x0:n.x,y0:n.y+n.height,x1:n.x+n.width,y1:n.y+n.height+42};case"left":return{x0:n.x-42,y0:n.y,x1:n.x,y1:n.y+n.height};case"right":return{x0:n.x+n.width,y0:n.y,x1:n.x+n.width+42,y1:n.y+n.height}}}function Gn(n){let t=qt(n.sourceAnchor,n.sourceAnchor.side,20),o=qt(n.targetAnchor,n.targetAnchor.side,20),r=n.sourceAnchor.side==="left"||n.sourceAnchor.side==="right"?[t,{x:(t.x+o.x)/2,y:t.y},{x:(t.x+o.x)/2,y:o.y},o]:[t,{x:t.x,y:(t.y+o.y)/2},{x:o.x,y:(t.y+o.y)/2},o];return{sourceAnchor:n.sourceAnchor,targetAnchor:n.targetAnchor,points:$t(r)}}function de(n,t,o,e,r){let c=[];for(let s=1;s<n.length;s++){let i=n[s-1],a=n[s];e.query(Math.min(i.x,a.x),Math.min(i.y,a.y),Math.max(i.x,a.x),Math.max(i.y,a.y),c);for(let f of c)if(!(f>=o||r&&r.has(f))&&te(i,a,t[f],.5))return!0}return!1}var ye=n=>Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.width)&&Number.isFinite(n.height)&&n.width>=0&&n.height>=0,xe=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function eo(n,t){let o=t.obstacles.every(ye)?t.obstacles:t.obstacles.filter(ye),e=new Map;o.forEach((x,g)=>e.set(x.id,g));let r={lines:new Map,fallbacks:new Set,relaxed:new Map,stats:{gridX:0,gridY:0,pops:0,reused:0}},c=t.edges.filter(x=>!x.isSelfLoop&&x.source!==x.target&&e.has(x.source)&&e.has(x.target));if(!c.length)return r;let s=[...o];for(let x of t.edges)(x.isSelfLoop||x.source===x.target)&&e.has(x.source)&&xe(x.sourceAnchor)&&xe(x.targetAnchor)&&s.push(no(x));let i=new Map;[...c].sort((x,g)=>x.id<g.id?-1:x.id>g.id?1:0).forEach((x,g)=>i.set(x.id,g));let a=x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)];return Math.abs(g.x+g.width/2-M.x-M.width/2)+Math.abs(g.y+g.height/2-M.y-M.height/2)},f=[...c].sort((x,g)=>a(x)-a(g)||i.get(x.id)-i.get(g.id)),u=n.memo,l={rects:new Map(s.map(x=>[x.id,x])),routes:new Map},h=[];if(u){for(let x of s){let g=u.rects.get(x.id);(!g||_t(g)!==_t(x))&&(h.push(x),g&&h.push(g))}for(let[x,g]of u.rects)l.rects.has(x)||h.push(g)}let m=x=>{if(!u||h.length>s.length/2)return null;let g=u.routes.get(x.id);if(!g||g.srcKey!==_t(o[e.get(x.source)])||g.tgtKey!==_t(o[e.get(x.target)]))return null;for(let M of h){if(!(M.x<g.reach.x1&&M.x+M.width>g.reach.x0&&M.y<g.reach.y1&&M.y+M.height>g.reach.y0))continue;let E=M.x-Ft,I=M.y-Ft,O=M.x+M.width+Ft,D=M.y+M.height+Ft,W=g.pts;if(!W.length)return null;for(let Z=1;Z<W.length;Z++){let $=W[Z-1],X=W[Z];if(Math.max($.x,X.x)>E&&Math.min($.x,X.x)<O&&Math.max($.y,X.y)>I&&Math.min($.y,X.y)<D)return null}}return g},d=new Map,y=[];for(let x of f){let g=m(x);g?d.set(x.id,g):y.push(x)}let P=new Map,b=[],p=[];if(u&&h.length<=8){let x=(g,M,E)=>{let I=u.rects.get(g),O=o[e.get(g)];if(!I||I.width!==O.width||I.height!==O.height)return null;let D=M==="left"||M==="right",W=(D?E.y:E.x)-Wt(I,M)[0],[Z,$]=Pt(O,M),X=Math.min($,Math.max(Z,Wt(O,M)[0]+W));return(D?p:b).push(X),{side:M,c:X}};for(let g of y){let M=u.routes.get(g.id);!M||M.fallback||M.pts.length<2||P.set(g.id,{src:x(g.source,M.srcSide,M.pts[0]),tgt:x(g.target,M.tgtSide,M.pts[M.pts.length-1])})}}let R=2*30,S=new Set;for(let x of c)S.add(e.get(x.source)),S.add(e.get(x.target));let A=s.map(x=>({x0:x.x-16,y0:x.y-16,x1:x.x+x.width+16,y1:x.y+x.height+16})),w=1/0,C=1/0,v=-1/0,k=-1/0;for(let x of s)w=Math.min(w,x.x),C=Math.min(C,x.y),v=Math.max(v,x.x+x.width),k=Math.max(k,x.y+x.height);let N=c.map(x=>{let g=o[e.get(x.source)],M=o[e.get(x.target)],E=[],I=[],O=he(g,M,"left");O!==null&&I.push(O);let D=he(g,M,"top");D!==null&&E.push(D),M.x>g.x+g.width?E.push((g.x+g.width+M.x)/2):g.x>M.x+M.width&&E.push((M.x+M.width+g.x)/2),M.y>g.y+g.height?I.push((g.y+g.height+M.y)/2):g.y>M.y+M.height&&I.push((M.y+M.height+g.y)/2);let W=Math.min(g.x,M.x),Z=Math.min(g.y,M.y);return{xs:E,ys:I,box:{id:x.id,x:W,y:Z,width:Math.max(g.x+g.width,M.x+M.width)-W,height:Math.max(g.y+g.height,M.y+M.height)-Z,kind:"annotation"}}}),B=(x,g,M,E)=>{let I=[...M,...b],O=[...E,...p],D=[],W=[],Z=[];for(let $ of x){let X=s[$];I.push(A[$].x0,A[$].x1),O.push(A[$].y0,A[$].y1),$<o.length&&(Z.push(X),S.has($)&&(D.push(X.x+X.width/2),W.push(X.y+X.height/2)))}to(Z,D,W);for(let $ of g)D.push(...N[$].xs),W.push(...N[$].ys);return{xs:wn(I,D,12),ys:wn(O,W,12)}},U=s.map((x,g)=>g),Y=s.length>150,G;if(Y)G=an(new Float64Array(0),new Float64Array(0));else{let{xs:x,ys:g}=B(U,c.map((M,E)=>E),[w-R,v+R],[C-R,k+R]);G=an(x,g),r.stats.gridX=G.nx,r.stats.gridY=G.ny;for(let M=0;M<s.length;M++)un(G,A[M].x0,A[M].y0,A[M].x1,A[M].y1,1)}let lt=(x,g)=>un(G,A[x].x0,A[x].y0,A[x].x1,A[x].y1,g),q=Y?new It(s,320):null,nt=Y?new It(N.map(x=>x.box),320):null,at=[],_=Y?new Bn(400):null,j=Y?o.flatMap(x=>Zt.map(g=>{let M=Mn(x,g);return{id:"",x:M.x0,y:M.y0,width:M.x1-M.x0,height:M.y1-M.y0,kind:"annotation"}})):null,z=Y?new It(j,320):null,L=Y?new Uint8Array(o.length*4):null,F=(x,g)=>{L&&(L[e.get(x.id)*4+Zt.indexOf(g)]=1)},V=[],Q=(x,g,M)=>{let E=Math.min(x.x,g.x)-M,I=Math.min(x.y,g.y)-M,O=Math.max(x.x+x.width,g.x+g.width)+M,D=Math.max(x.y+x.height,g.y+g.height)+M,W=E<=w-R&&I<=C-R&&O>=v+R&&D>=k+R;W&&(E=w-R,I=C-R,O=v+R,D=k+R),q.query(E,I,O,D,V);let Z=[];for(let ut of V){let tt=A[ut];tt.x1<E||tt.x0>O||tt.y1<I||tt.y0>D||Z.push(ut)}nt.query(E,I,O,D,V);let $=V.slice(),X=_.query(E,I,O,D),J=[E,O],rt=[I,D];for(let ut of X){let tt=at[ut].pts;for(let Bt=1;Bt<tt.length;Bt++){let mt=tt[Bt-1],zt=tt[Bt];Math.max(mt.x,zt.x)<E||Math.min(mt.x,zt.x)>O||Math.max(mt.y,zt.y)<I||Math.min(mt.y,zt.y)>D||(Math.abs(mt.y-zt.y)<.01&&mt.y>I&&mt.y<D?rt.push(mt.y):Math.abs(mt.x-zt.x)<.01&&mt.x>E&&mt.x<O&&J.push(mt.x))}}let{xs:dt,ys:ft}=B(Z,$,J,rt),Ot=E,en=I,on=O,rn=D;for(let ut of Z)Ot=Math.min(Ot,A[ut].x0),en=Math.min(en,A[ut].y0),on=Math.max(on,A[ut].x1),rn=Math.max(rn,A[ut].y1);let Zn=(ut,tt,Bt)=>ut.filter(mt=>mt>=tt-1e-6&&mt<=Bt+1e-6),Vn=Zn(dt,Ot,on),Wn=Zn(ft,en,rn);if(Vn.length*Wn.length>15e5)return null;let gt=an(Vn,Wn);for(let ut of Z)un(gt,A[ut].x0,A[ut].y0,A[ut].x1,A[ut].y1,1);let pt=1e9;Ot<E&&Ht(gt,-pt,-pt,E,pt,1),on>O&&Ht(gt,O,-pt,pt,pt,1),en<I&&Ht(gt,-pt,-pt,pt,I,1),rn>D&&Ht(gt,-pt,D,pt,pt,1),z.query(E,I,O,D,V);for(let ut of V){if(!L[ut])continue;let tt=j[ut];tt.x+tt.width<E||tt.x>O||tt.y+tt.height<I||tt.y>D||Qt(gt,tt.x,tt.y,tt.x+tt.width,tt.y+tt.height,1)}for(let ut of X){let tt=at[ut];kn(gt,tt.pts,1),pn(gt,tt.srcSide,tt.pts[0],1),pn(gt,tt.tgtSide,tt.pts[tt.pts.length-1],1)}return r.stats.gridX=Math.max(r.stats.gridX,gt.nx),r.stats.gridY=Math.max(r.stats.gridY,gt.ny),{grid:gt,whole:W,box:[E,I,O,D]}},T=[],ot=[],it=[],H=new Set,et=new Set,xt=[],Ct=new Map,Dt=(x,g,M,E)=>{let I=`${x.id}\0${g}`,O=Ct.get(I);O?O.push({c:M,other:E}):Ct.set(I,[{c:M,other:E}])};for(let x of t.edges){if(!(x.isSelfLoop||x.source===x.target)||!e.has(x.source))continue;let g=o[e.get(x.source)];for(let M of[x.sourceAnchor,x.targetAnchor])Dt(g,M.side,M.side==="left"||M.side==="right"?M.y:M.x,"")}let kt=(x,g)=>{for(let M of Zt){if(!H.has(`${x.id}\0${M}`))continue;let E=Mn(x,M);Qt(G,E.x0,E.y0,E.x1,E.y1,g)}},At=(x,g,M,E,I=!1)=>{T.length=0,ot.length=0;let O=o[x],D=o[g];for(let J of Zt)fe(G,O,J,!1,T,Ct.get(`${O.id}\0${J}`),D.id,E?.src??null),fe(G,D,J,!0,ot,Ct.get(`${D.id}\0${J}`),O.id,E?.tgt??null);if(!T.length||!ot.length)return null;let W=(J,rt)=>Ht(G,J.x-29,J.y-29,J.x+J.width+29,J.y+J.height+29,rt);kt(O,-1),g!==x&&kt(D,-1),W(O,1),g!==x&&W(D,1);let Z=Math.abs(O.x+O.width/2-D.x-D.width/2)+Math.abs(O.y+O.height/2-D.y-D.height/2),$=Math.min(1,Math.max(0,(Z-(Y?1200:1600))/1200)),X=n.searcher.search(G,T,ot,4e4,M,I?3:1.1+(Y?.9:.3)*$,I?80*.1:80*(1-(Y?.85:.7)*$));return W(O,-1),g!==x&&W(D,-1),kt(O,1),g!==x&&kt(D,1),r.stats.pops+=n.searcher.lastPops,X},Xt=(x,g,M,E,I,O)=>{let D=o[e.get(x.source)],W=o[e.get(x.target)];if(Y){let $=at.length;at.push({pts:g.map(X=>({x:X.x,y:X.y})),srcSide:M,tgtSide:E});for(let X=1;X<g.length;X++)_.add($,g[X-1],g[X])}else O?(ne(G,O.nodes),me(G,O.src),me(G,O.tgt)):kn(G,g),pn(G,M,g[0]),pn(G,E,g[g.length-1]);let Z=($,X)=>X==="left"||X==="right"?$.y:$.x;Dt(D,M,Z(g[0],M),W.id),Dt(W,E,Z(g[g.length-1],E),D.id);for(let[$,X]of[[D,M],[W,E]]){let J=`${$.id}\0${X}`,rt=Mn($,X);H.has(J)||(H.add(J),F($,X),Y||Qt(G,rt.x0,rt.y0,rt.x1,rt.y1,1)),!et.has(J)&&(et.add(J),xt.push({id:`${J}#zone`,x:rt.x0,y:rt.y0,width:rt.x1-rt.x0,height:rt.y1-rt.y0,kind:"annotation"}))}I&&I.size&&r.relaxed.set(x.id,new Set([...I].map($=>o[$].id))),it.push({spec:x,path:{pts:g,src:D,srcSide:M,tgt:W,tgtSide:E,rank:i.get(x.id),ignore:I&&I.size?I:null,own:[e.get(x.source),e.get(x.target)]}}),l.routes.set(x.id,{srcKey:_t(D),tgtKey:_t(W),pts:g.slice(),srcSide:M,tgtSide:E,ignore:I&&I.size?[...I].map($=>o[$].id):null,fallback:!1,reach:le(g,D,W)})};for(let x of c)for(let[g,M]of[[x.source,x.sourceAnchor.side],[x.target,x.targetAnchor.side]]){let E=o[e.get(g)],I=`${E.id}\0${M}`;if(H.has(I)||(H.add(I),F(E,M),Y))continue;let O=Mn(E,M);Qt(G,O.x0,O.y0,O.x1,O.y1,1)}for(let x of f){let g=d.get(x.id);if(!g)continue;if(r.stats.reused++,g.fallback){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,g);continue}let M=g.ignore?new Set(g.ignore.map(E=>e.get(E)).filter(E=>E!==void 0)):null;Xt(x,g.pts.map(E=>({x:E.x,y:E.y})),g.srcSide,g.tgtSide,M,null)}for(let x of y){let g=e.get(x.source),M=e.get(x.target),E=o[g],I=o[M],O=P.get(x.id),D=()=>At(g,M,!0,O)??null,W=()=>{let J=46,rt=new Set;for(let ft=0;ft<o.length;ft++)ft===g||ft===M||(sn(o[ft],0,E,J)||sn(o[ft],0,I,J))&&rt.add(ft);if(sn(E,0,I,J)&&(rt.add(g),rt.add(M)),!rt.size)return null;for(let ft of rt)lt(ft,-1);let dt=At(g,M,!1,O);for(let ft of rt)lt(ft,1);return dt?{found:dt,ignore:rt}:null},Z=null,$=null,X=null;if(Y){let J=400,rt=!1;for(;;){let dt=Q(E,I,J);if(!dt)break;G=dt.grid,rt=!0;let ft=D();if(ft){if(Z=ft,X=Rn(ft,G),dt.whole||!oo(X,dt.box))break}else if(n.searcher.lastPops>4e4){let Ot=At(g,M,!0,O,!0);Ot&&(Z=Ot,X=Rn(Ot,G));break}else if(dt.whole)break;J*=2.5}if(!Z&&rt){let dt=W();dt&&({found:Z,ignore:$}=dt,X=Rn(dt.found,G))}}else{if(Z=D(),!Z){let J=W();J&&({found:Z,ignore:$}=J)}Z&&(X=Rn(Z,G))}if(!Z){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x)),l.routes.set(x.id,{srcKey:_t(E),tgtKey:_t(I),pts:[],srcSide:x.sourceAnchor.side,tgtSide:x.targetAnchor.side,ignore:null,fallback:!0,reach:le([],E,I)});continue}Xt(x,X,Z.src.side,Z.tgt.side,$&&$.size?$:null,Z)}n.memo=l,it.sort((x,g)=>x.path.rank-g.path.rank);let St=it.map(x=>x.path),vt=St.map(x=>x.pts.slice()),Kt=[...s,...xt],Yt={rects:Kt,buckets:new It(Kt),zoneFrom:s.length};ae(St,Yt),Dn(St,!0,Yt),Tn(St,!0,Yt),Dn(St,!1,Yt),Tn(St,!1,Yt);let qn=new It(s);return it.forEach(({spec:x,path:g},M)=>{let E=$t(g.pts);if((E.length<2||de(E,s,o.length,qn,g.ignore))&&(E=vt[M]),de(E,s,o.length,qn,g.ignore)){r.fallbacks.add(x.id),r.lines.set(x.id,Gn(x));return}r.lines.set(x.id,{sourceAnchor:En(E[0],g.srcSide),targetAnchor:En(E[E.length-1],g.tgtSide),points:E})}),r}function Rn(n,t){let o=[n.src.point];for(let e of n.nodes){let r=e%t.nx;o.push({x:t.xs[r],y:t.ys[(e-r)/t.nx]})}return o.push(n.tgt.point),$t(o)}function oo(n,t){let[o,e,r,c]=t;for(let s of n)if(s.x<=o+.5||s.y<=e+.5||s.x>=r-.5||s.y>=c-.5)return!0;return!1}var Bn=class{constructor(t){this.cell=t;K(this,"cells",new Map);K(this,"everywhere",new Set);K(this,"seen",new Uint32Array(64));K(this,"stamp",0)}key(t,o){return(t+32768)*65536+(o+32768)}add(t,o,e){let r=Math.floor(Math.min(o.x,e.x)/this.cell),c=Math.floor(Math.max(o.x,e.x)/this.cell),s=Math.floor(Math.min(o.y,e.y)/this.cell),i=Math.floor(Math.max(o.y,e.y)/this.cell);if(!Number.isFinite(r+c+s+i)||(c-r+1)*(i-s+1)>4096||Math.abs(r)>28672||Math.abs(c)>28672||Math.abs(s)>28672||Math.abs(i)>28672){this.everywhere.add(t);return}for(let a=s;a<=i;a++)for(let f=r;f<=c;f++){let u=this.key(f,a),l=this.cells.get(u);l?l[l.length-1]!==t&&l.push(t):this.cells.set(u,[t])}}query(t,o,e,r){let c=[...this.everywhere];++this.stamp===4294967295&&(this.seen.fill(0),this.stamp=1);let s=Math.max(-28672,Math.floor(t/this.cell)),i=Math.min(28672,Math.floor(e/this.cell)),a=Math.max(-28672,Math.floor(o/this.cell)),f=Math.min(28672,Math.floor(r/this.cell));if((i-s+1)*(f-a+1)>1<<20){let u=new Set(this.everywhere);for(let l of this.cells.values())for(let h of l)u.add(h);return[...u]}for(let u=a;u<=f;u++)for(let l=s;l<=i;l++){let h=this.cells.get(this.key(l,u));if(h)for(let m of h){if(m>=this.seen.length){let d=new Uint32Array(Math.max(m+1,this.seen.length*2));d.set(this.seen),this.seen=d}this.seen[m]===this.stamp||this.everywhere.has(m)||(this.seen[m]=this.stamp,c.push(m))}}return c}};function zn(n){let t=[];for(let e=0;e<n.length;e++){let r=n[e];for(let c=0;c+1<r.length;c++){let s=r[c],i=r[c+1],a=Math.hypot(i.x-s.x,i.y-s.y);a<2*.75||t.push({line:e,seg:c,ax:s.x,ay:s.y,bx:i.x,by:i.y,len:a,minX:Math.min(s.x,i.x),maxX:Math.max(s.x,i.x),minY:Math.min(s.y,i.y),maxY:Math.max(s.y,i.y)})}}t.sort((e,r)=>e.minX-r.minX);let o=[];for(let e=0;e<t.length;e++){let r=t[e];for(let c=e+1;c<t.length;c++){let s=t[c];if(s.minX>r.maxX)break;if(s.line===r.line||s.minY>r.maxY||s.maxY<r.minY)continue;let i=r.bx-r.ax,a=r.by-r.ay,f=s.bx-s.ax,u=s.by-s.ay,l=i*u-a*f;if(Math.abs(l)<.02*r.len*s.len)continue;let h=s.ax-r.ax,m=s.ay-r.ay,d=(h*u-m*f)/l,y=(h*a-m*i)/l,P=d*r.len,b=y*s.len;P<=.75||P>=r.len-.75||b<=.75||b>=s.len-.75||o.push({x:r.ax+i*d,y:r.ay+a*d,a:{line:r.line,seg:r.seg,d:P},b:{line:s.line,seg:s.seg,d:b}})}}return o}function $n(n,t,o){let e=n.length,r=new Float64Array(Math.max(0,e-1));for(let i=0;i+1<e;i++)r[i]=Math.hypot(n[i+1].x-n[i].x,n[i+1].y-n[i].y);let c=new Float64Array(e),s=new Float64Array(e);if(t==="sharp")return{segLen:r,rIn:c,rOut:s};for(let i=1;i<e-1;i++){let a=r[i-1],f=r[i];if(t==="rounded"){let y=Math.min(8,a/2,f/2);c[i]=y,s[i]=y;continue}let u=i-1===0?a-4:a/2,l=i===e-2?f-4:f/2,h=Math.max(0,Math.min(40,u)),m=Math.max(0,Math.min(40,l)),d=Math.min(h,m);h=Math.min(h,d*2),m=Math.min(m,d*2),o&&o.length&&h>8&&([h,m]=so(n[i-1],n[i],n[i+1],h,m,o)),c[i]=h,s[i]=m}return{segLen:r,rIn:c,rOut:s}}function tn(n,t,o,e,r){let c=Math.hypot(t.x-n.x,t.y-n.y)||1,s=Math.hypot(o.x-t.x,o.y-t.y)||1,i={x:t.x-(t.x-n.x)/c*e,y:t.y-(t.y-n.y)/c*e},a={x:t.x+(o.x-t.x)/s*r,y:t.y+(o.y-t.y)/s*r},f={x:i.x+(t.x-i.x)*.5523,y:i.y+(t.y-i.y)*.5523},u={x:a.x+(t.x-a.x)*.5523,y:a.y+(t.y-a.y)*.5523};return{a:i,c1:f,c2:u,b:a}}var ro=[.2,.35,.5,.65,.8];function so(n,t,o,e,r,c){let s=Math.max(e,r)+6,i=[];for(let a of c)a.x>t.x+s||a.x+a.width<t.x-s||a.y>t.y+s||a.y+a.height<t.y-s||t.x>a.x-6&&t.x<a.x+a.width+6&&t.y>a.y-6&&t.y<a.y+a.height+6||i.push(a);if(!i.length)return[e,r];for(let a=0;a<5;a++){let{a:f,c1:u,c2:l,b:h}=tn(n,t,o,e,r),m=!1;for(let d of ro){let y=1-d,P=y*y*y*f.x+3*y*y*d*u.x+3*y*d*d*l.x+d*d*d*h.x,b=y*y*y*f.y+3*y*y*d*u.y+3*y*d*d*l.y+d*d*d*h.y;for(let p of i)if(P>p.x-6&&P<p.x+p.width+6&&b>p.y-6&&b<p.y+p.height+6){m=!0;break}if(m)break}if(!m)return[e,r];if(e*=.7,r*=.7,Math.max(e,r)<=8)break}return[Math.min(e,8),Math.min(r,8)]}var An=10,Hn=.75;function io(n,t,o,e,r,c,s){let i=1-s;return n==="rounded"?{x:i*i*t.x+2*i*s*c.x+s*s*r.x,y:i*i*t.y+2*i*s*c.y+s*s*r.y}:{x:i*i*i*t.x+3*i*i*s*o.x+3*i*s*s*e.x+s*s*s*r.x,y:i*i*i*t.y+3*i*i*s*o.y+3*i*s*s*e.y+s*s*s*r.y}}function be(n){let t=1/0,o=-1/0,e=1/0,r=-1/0;for(let c of n.pts)c.x<t&&(t=c.x),c.x>o&&(o=c.x),c.y<e&&(e=c.y),c.y>r&&(r=c.y);return{...n,minX:t,maxX:o,minY:e,maxY:r}}function Sn(n,t,o){if(o==="sharp")return[];let e=[],r=0;for(let s=0;s<n.length;s++){let i=n[s],a=t[s];for(let f=0;f+1<i.length;f++){let u=a.segLen[f];if(u<=0)continue;let l=a.rOut[f],h=u-a.rIn[f+1];if(h-l>2*Hn){let d=i[f],y=i[f+1],P=(y.x-d.x)/u,b=(y.y-d.y)/u;e.push(be({line:s,index:f,curve:!1,pts:[{x:d.x+P*l,y:d.y+b*l},{x:d.x+P*h,y:d.y+b*h}],offset:l}))}let m=f+1;if(m<i.length-1&&(a.rIn[m]>0||a.rOut[m]>0)){let d=tn(i[m-1],i[m],i[m+1],a.rIn[m],a.rOut[m]),y=[];for(let P=0;P<=An;P++)y.push(io(o,d.a,d.c1,d.c2,d.b,i[m],P/An));e.push(be({line:s,index:m,curve:!0,pts:y,offset:0})),r++}}}if(!r)return[];e.sort((s,i)=>s.minX-i.minX);let c=[];for(let s=0;s<e.length;s++){let i=e[s];for(let a=s+1;a<e.length;a++){let f=e[a];if(f.minX>i.maxX)break;if(i.curve===f.curve||i.line===f.line||f.minY>i.maxY||f.maxY<i.minY)continue;let u=i.curve?i:f,l=i.curve?f:i,[h,m]=l.pts,d=m.x-h.x,y=m.y-h.y,P=Math.hypot(d,y);for(let b=0;b<An;b++){let p=u.pts[b],R=u.pts[b+1],S=R.x-p.x,A=R.y-p.y,w=S*y-A*d;if(Math.abs(w)<1e-9)continue;let C=h.x-p.x,v=h.y-p.y,k=(C*y-v*d)/w,N=(C*A-v*S)/w;if(k<0||k>=1)continue;let B=N*P;B<=Hn||B>=P-Hn||c.push({x:h.x+d*N,y:h.y+y*N,straight:{line:l.line,seg:l.index,d:l.offset+B},curve:{line:u.line,vertex:u.index,t:(b+k)/An}})}}}return c}var Kn=6,ao=6,uo=14;function lo(n){let t=n&&Number.isFinite(n)&&n>0?n:1;return Math.min(uo,Math.max(Kn,ao/t))}var fo=4.5,Xn=3,ge=4,ho=4,pe=36,Me=16,mo=16;function yo(n){let t=[];for(let o of n){let e=t[t.length-1];if(!(e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01)){if(t.length>=2){let r=t[t.length-2],c=t[t.length-1],s=(c.x-r.x)*(o.y-r.y)-(c.y-r.y)*(o.x-r.x),i=(c.x-r.x)*(o.x-c.x)+(c.y-r.y)*(o.y-c.y);if(Math.abs(s)<.01&&i>=0){t[t.length-1]=o;continue}}t.push(o)}}return t}var Ae=(n,t=Kn)=>n==="hop"?t:fo;function xo(n,t){let o=n.segLen.length-1,e=n.rOut[t]+(t===0?ge:Xn),r=n.segLen[t]-n.rIn[t+1]-(t===o?ge:Xn);return[e,r]}function Pn(n,t){let o=n[t],e=n[t+1],r=Math.hypot(e.x-o.x,e.y-o.y);return r>0?Math.abs(e.x-o.x)/r:0}function bo(n,t,o,e,r,c,s){let i=Ae(r,s),a=t.map(()=>[]),f=r==="hop"?s:2,u=(h,m)=>{let[d,y]=xo(o[h.line],h.seg);return h.d-m>=d&&h.d+m<=y},l=h=>{let m=a[h.line][h.seg];m?m.push(h.d):a[h.line][h.seg]=[h.d]};for(let h of n){let m=Pn(t[h.a.line],h.a.seg),d=Pn(t[h.b.line],h.b.seg),y=Math.abs(m-d)>.001?m>d:e[h.a.line]>e[h.b.line],P=y?h.a:h.b,b=y?h.b:h.a,[p,R]=r==="hop"?[P,b]:[b,P];u(p,i)&&u(R,f)?l(p):u(R,i)&&u(p,f)&&l(R)}if(r!=="hop")for(let h of c)u(h.straight,i)&&l(h.straight);return a}function go(n,t){n.sort((e,r)=>e-r);let o=[];for(let e of n){let r=o[o.length-1];r&&e-t-r[1]<ho?r[1]=Math.max(r[1],e+t):o.push([e-t,e+t])}return o}var Re=n=>String(Math.round(n*100)/100),yt=n=>`${Re(n.x)},${Re(n.y)}`,Gt=(n,t)=>Math.hypot(t.x-n.x,t.y-n.y);function po(n,t){let o=t,e=-n;return Math.abs(e)>.05?e>0&&(o=-o,e=-e):o<0&&(o=-o,e=-e),{x:o,y:e}}function Mo(n,t){let{pieces:o}=n,e=0,r=o.length-1;for(;e<r;){let f=e+r>>1;o[f].pos1<t?e=f+1:r=f}let c=o[e],s=c.pos1-c.pos0,i=s>0?Math.min(1,Math.max(0,(t-c.pos0)/s)):0,a=1-i;switch(c.kind){case"L":return{x:c.a.x+(c.b.x-c.a.x)*i,y:c.a.y+(c.b.y-c.a.y)*i};case"Q":return{x:a*a*c.a.x+2*a*i*c.c.x+i*i*c.b.x,y:a*a*c.a.y+2*a*i*c.c.y+i*i*c.b.y};case"C":return{x:a*a*a*c.a.x+3*a*a*i*c.c1.x+3*a*i*i*c.c2.x+i*i*i*c.b.x,y:a*a*a*c.a.y+3*a*a*i*c.c1.y+3*a*i*i*c.c2.y+i*i*i*c.b.y}}}function Ro(n,t,o){let e=n.knots[t];if(!e||!e.length)return 0;let r=e[0];for(let c of e){if(c[0]>o)break;r=c}return r[1]+Math.max(0,o-r[0])}function Ao(n,t,o,e,r,c,s=Kn){let i=n.length;if(i===0)return{d:"",pieces:[],knots:[],cornerPos:[],length:0};let a=e??$n(n,t,o),f=`M ${yt(n[0])}`,u=null,l=[],h=[],m=[],d=0,y=n[0],P=r?Ae(r,s):0,b=R=>{f+=R,u!==null&&(u+=R)};for(let R=0;R+1<i;R++){let S=n[R],A=n[R+1],w=a.segLen[R];if(w<=0)continue;let C=(A.x-S.x)/w,v=(A.y-S.y)/w,k=q=>({x:S.x+C*q,y:S.y+v*q});if(R>0){let q=a.rIn[R],nt=a.rOut[R];if(q>0||nt>0){let at=n[R-1],_=tn(at,S,A,q,nt),j=d;t==="rounded"?(b(` Q ${yt(S)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,S)+Gt(S,_.b))/2,l.push({pos0:j,pos1:d,kind:"Q",a:y,c:S,b:_.b})):(b(` C ${yt(_.c1)} ${yt(_.c2)} ${yt(_.b)}`),d+=(Gt(_.a,_.b)+Gt(_.a,_.c1)+Gt(_.c1,_.c2)+Gt(_.c2,_.b))/2,l.push({pos0:j,pos1:d,kind:"C",a:y,c1:_.c1,c2:_.c2,b:_.b})),y=_.b,m[R]=[j,d]}}let N=a.rOut[R],B=w-a.rIn[R+1],U=N,Y=[[U,d]];h[R]=Y;let G=q=>{if(q<=U+1e-6)return;let nt=k(q);b(` L ${yt(nt)}`),l.push({pos0:d,pos1:d+(q-U),kind:"L",a:y,b:nt}),d+=q-U,U=q,y=nt},lt=r?c[R]:void 0;if(lt&&lt.length)for(let[q,nt]of go(lt,P)){G(q);let at=k(q),_=k(nt);if(r==="cut")u===null&&(u=f),f+=` L ${yt(_)}`,u+=` M ${yt(_)}`,l.push({pos0:d,pos1:d+(nt-q),kind:"L",a:at,b:_}),d+=nt-q;else{let j=po(C,v),z=s,L=.5523*z,F=(T,ot,it)=>({x:T.x+C*ot+j.x*it,y:T.y+v*ot+j.y*it}),V=Math.PI*z/2,Q=(T,ot,it,H)=>{b(` C ${yt(ot)} ${yt(it)} ${yt(H)}`),l.push({pos0:d,pos1:d+V,kind:"C",a:T,c1:ot,c2:it,b:H}),d+=V};if(nt-q<=2*z+.01){let T=F(at,z,z);Q(at,F(at,0,L),F(T,-L,0),T),Q(T,F(T,L,0),F(_,0,L),_)}else{let T=F(at,z,z),ot=F(_,-z,z);Q(at,F(at,0,L),F(T,-L,0),T),b(` L ${yt(ot)}`),l.push({pos0:d,pos1:d+(nt-q-2*z),kind:"L",a:T,b:ot}),d+=nt-q-2*z,Q(ot,F(ot,L,0),F(_,0,L),_)}}U=nt,y=_,Y.push([U,d])}G(B)}let p={d:f,pieces:l,knots:h,cornerPos:m,length:d};return u!==null&&(p.strokeD=u),p}function So(n,t){let o=n.length/2,e=Math.min(mo,n.length/2);t.push([-1/0,e],[n.length-e,1/0]),t.sort((i,a)=>i[0]-a[0]||i[1]-a[1]);let r=o,c=-1/0,s=-1/0;for(let[i,a]of t)if(i>s){if(c<o&&o<s)break;c=i,s=a}else s=Math.max(s,a);if(c<o&&o<s){let i=c>=e,a=s<=n.length-e;i&&(!a||o-c<=s-o)?r=c:a&&(r=s)}return Mo(n,r)}function Po(n,t,o,e){let r=e+Xn,c=2,s=(a,f,u)=>{let l=t[a],h=l.segLen[f];if(u<r||h-u<r)return;let m=Math.max(0,u-r),d=Math.max(0,h-u-r);f>0&&l.rOut[f]>m&&(l.rOut[f]=m,l.rIn[f]=Math.min(l.rIn[f],Math.max(m,8)*c)),f+1<n[a].length-1&&l.rIn[f+1]>d&&(l.rIn[f+1]=d,l.rOut[f+1]=Math.min(l.rOut[f+1],Math.max(d,8)*c))},i=zn(n);for(let a of i)s(a.a.line,a.a.seg,a.a.d),s(a.b.line,a.b.seg,a.b.d);if(o!=="curved")return{crossings:i,curveCrossings:Sn(n,t,o)};for(let a=0;;a++){let f=Sn(n,t,o);if(!f.length||a===3)return{crossings:i,curveCrossings:f};let u=!1;for(let l of f){let h=t[l.curve.line],m=l.curve.vertex;Math.max(h.rIn[m],h.rOut[m])<=8+.01||(h.rIn[m]=Math.max(Math.min(h.rIn[m],8),h.rIn[m]*.6),h.rOut[m]=Math.max(Math.min(h.rOut[m],8),h.rOut[m]*.6),u=!0)}if(!u)return{crossings:i,curveCrossings:f}}}var Eo=n=>Number.isFinite(n.x)&&Number.isFinite(n.y);function Se(n,t){let o=[...n.keys()].filter(y=>n.get(y).points.every(Eo)),e=o.map(y=>yo(n.get(y).points)),r=e.map(y=>$n(y,t.corners,t.obstacles)),c=lo(t.zoom),s=t.crossings==="hops"&&t.corners!=="sharp"&&e.length>1?Po(e,r,t.corners,c):null,i=y=>{let P=r[y.line];return y.d>=P.rOut[y.seg]&&y.d<=P.segLen[y.seg]-P.rIn[y.seg+1]},a=e.length>1?(s?.crossings??zn(e)).filter(y=>i(y.a)&&i(y.b)):[],f=e.length>1?s?.curveCrossings??Sn(e,r,t.corners):[],u=t.crossings==="hops"?"hop":t.crossings==="halo"?"cut":null,l=u?bo(a,e,r,o,u,f,c):e.map(()=>[]),h=e.map(()=>[]),m=e.map(()=>[]);for(let y of a)h[y.a.line].push(y.a),h[y.b.line].push(y.b);for(let y of f)h[y.straight.line].push(y.straight),m[y.curve.line].push(y.curve);let d=new Map;for(let y=0;y<o.length;y++){let P=e[y];if(P.length<2){let A=P[0]??{x:0,y:0};d.set(o[y],{d:`M ${yt(A)}`,mid:A,halo:t.crossings==="halo"?!0:void 0});continue}let b=Ao(P,t.corners,t.obstacles,r[y],u,l[y],c),p=h[y].map(A=>{let w=Ro(b,A.seg,A.d),C=Pn(P,A.seg)>.7?pe:Me;return[w-C,w+C]});for(let A of m[y]){let w=b.cornerPos[A.vertex];if(!w)continue;let C=w[0]+(w[1]-w[0])*A.t,v=Pn(P,A.t<.5?A.vertex-1:A.vertex)>.7?pe:Me;p.push([C-v,C+v])}let R=So(b,p),S={d:b.d,mid:R};t.crossings==="halo"&&(S.halo=!0),b.strokeD&&(S.strokeD=b.strokeD),d.set(o[y],S)}return d}function wo(n,t,o,e,r,c,s,i){let a=0,f=1,u=[-o,o,-e,e],l=[n-r,s-n,t-c,i-t];for(let h=0;h<4;h++){if(u[h]===0){if(l[h]<=0)return null;continue}let m=l[h]/u[h];if(u[h]<0){if(m>f)return null;m>a&&(a=m)}else{if(m<a)return null;m<f&&(f=m)}}return f>a?[a,f]:null}function Pe(n,t,o,e){let r=e;for(;r<n.length-2&&t[r+1]<o;)r++;let c=t[r+1]-t[r],s=c>0?(o-t[r])/c:0,i=n[r],a=n[r+1];return{p:{x:i.x+(a.x-i.x)*s,y:i.y+(a.y-i.y)*s},seg:r}}function Ee(n,t,o){let e=n.points;if(e.length<2||o.length===0)return[];let r=[0];for(let u=1;u<e.length;u++)r.push(r[u-1]+Math.hypot(e[u].x-e[u-1].x,e[u].y-e[u-1].y));let c=[];for(let u=0;u<e.length-1;u++){let l=e[u],h=e[u+1],m=r[u+1]-r[u];if(!(m>0)||!Number.isFinite(m))continue;let d=h.x-l.x,y=h.y-l.y,P=Math.min(l.x,h.x),b=Math.max(l.x,h.x),p=Math.min(l.y,h.y),R=Math.max(l.y,h.y);for(let S of o){let A=S.x+1,w=S.y+1,C=S.x+S.width-1,v=S.y+S.height-1;if(!(C>A)||!(v>w)||!Number.isFinite(C-A)||!Number.isFinite(v-w)||b<=A||P>=C||R<=w||p>=v||y===0&&(l.y-S.y<6||S.y+S.height-l.y<6)||d===0&&(l.x-S.x<6||S.x+S.width-l.x<6))continue;let k=wo(l.x,l.y,d,y,A,w,C,v);k&&c.push([r[u]+k[0]*m,r[u]+k[1]*m,S.id!==t?.source&&S.id!==t?.target])}}if(c.length===0)return[];c.sort((u,l)=>u[0]-l[0]);let s=[];for(let u of c){let l=s[s.length-1];l&&u[0]-l[1]<12?(u[1]>l[1]&&(l[1]=u[1]),u[2]&&(l[2]=!0)):s.push([u[0],u[1],u[2]])}let i=r[r.length-1];if(!Number.isFinite(i))return[];let a=[],f=0;for(let[u,l,h]of s){if(l-u<6||t&&!h&&(u<.5||l>i-.5))continue;let m=Pe(e,r,u,f),d=Pe(e,r,l,m.seg),y=[m.p];for(let P=m.seg+1;P<=d.seg;P++)y.push(e[P]);y.push(d.p),a.push(ko(y)),f=d.seg}return a}function ko(n){let t=[];for(let o of n){let e=t[t.length-1];e&&Math.abs(e.x-o.x)<.01&&Math.abs(e.y-o.y)<.01||t.push(o)}return t}function Yn(n,t,o){try{return n()}catch(e){return o(e),t}}function we(n,t,o={}){let e=o.now??(()=>0),r=o.onError??(()=>{}),c=o.router??Jt(),s=e(),i=Yn(()=>c.route(n).lines,new Map,l=>{c.reset(),r(l)}),a=Yn(()=>Se(i,{crossings:t.crossings,corners:t.corners,obstacles:n.obstacles,zoom:o.zoom??1}),new Map,r),f=new Map(n.edges.map(l=>[l.id,l])),u=new Map;for(let[l,h]of i){let m=a.get(l);if(!m)continue;let d=f.get(l),y=t.underTables==="xray"&&d?Yn(()=>Ee(h,d,n.obstacles),[],r):void 0,P={...h,d:m.d,mid:m.mid,halo:m.halo,tunnels:y&&y.length?y:void 0};m.strokeD&&(P.strokeD=m.strokeD),u.set(l,P)}return{edges:u,millis:e()-s}}var Co=Jt(),ke=self;ke.onmessage=n=>{let t=n.data;if(!t||t.type!=="route")return;let o,e=we(t.input,jn(t.style),{router:Co,now:()=>performance.now(),zoom:t.zoom,onError:r=>{o??(o=r instanceof Error?r.message:String(r))}});ke.postMessage({seq:t.seq,edges:e.edges,millis:e.millis,error:o})};})();
package/dist/editor.js CHANGED
@@ -70,7 +70,7 @@ import {
70
70
  useLongPressDrag,
71
71
  usePrefersReducedMotion,
72
72
  useSend
73
- } from "./chunk-7VFJNN4P.js";
73
+ } from "./chunk-JDL3BFJZ.js";
74
74
  import "./chunk-QZGU5NZH.js";
75
75
  import "./chunk-6XQXDZ4R.js";
76
76
  import {
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  toDbmlRich,
13
13
  toMermaid,
14
14
  transformSubjectArea
15
- } from "./chunk-7VFJNN4P.js";
15
+ } from "./chunk-JDL3BFJZ.js";
16
16
  import "./chunk-64BVOHOR.js";
17
17
  import {
18
18
  DEFAULT_LINE_STYLE,
@@ -64,6 +64,15 @@ export interface ErdCanvasProps {
64
64
  * reads as `curved`.
65
65
  */
66
66
  lineStyle?: LineStyle;
67
+ /**
68
+ * The URL of the host's copy of `@erd-studio/renderer/edge-routing-worker.js`,
69
+ * served from the page's own origin. Diagrams over 100 lines route in that
70
+ * worker. Without it the worker starts from a blob URL, which a CSP with no
71
+ * `blob:` for workers (only `script-src 'self'`) refuses, so larger diagrams route
72
+ * on the main thread and those over 150 lines keep simple lines. Read once,
73
+ * when the canvas mounts.
74
+ */
75
+ routingWorkerUrl?: string;
67
76
  className?: string;
68
77
  style?: CSSProperties;
69
78
  }
@@ -21,7 +21,7 @@ export { buildRoutingInput, routingInputKey, draggingNodesKey } from './input.js
21
21
  export { createAvoidRouter, type AvoidRouter } from './routers/orthogonalAvoid.js';
22
22
  export * from './lineStyle.js';
23
23
  export { routeAll, type RouteAllOptions } from './routeAll.js';
24
- export { createRoutingWorker, type RoutingWorkerFactory, type RoutingWorkerHandle, type RoutingWorkerEvents } from './worker/client.js';
24
+ export { createRoutingWorker, routingWorkerFactory, type RoutingWorkerFactory, type RoutingWorkerHandle, type RoutingWorkerEvents } from './worker/client.js';
25
25
  export type { WorkerRouteRequest, WorkerRouteResult } from './worker/protocol.js';
26
26
  /**
27
27
  * A pass during a drag slower than this (ms) is too slow to run on every
@@ -2,11 +2,19 @@
2
2
  * Starts a canvas's line-routing worker, or says it cannot (returns null) so
3
3
  * the canvas routes on the main thread with a lower cap instead.
4
4
  *
5
- * The worker's code is inlined at build time as `__ERD_EDGE_ROUTING_WORKER__`
6
- * (the extension's `esbuild.js` and the package's `build.mjs` both define
7
- * it). Where it is not defined (unit tests, a consumer bundling the source
8
- * itself), where `Worker` or blob URLs are missing, or where the page's CSP
9
- * refuses a blob worker, there is no worker.
5
+ * Two ways to start it, tried in this order:
6
+ * - from a URL the host serves the worker file at (`ErdCanvas`'s
7
+ * `routingWorkerUrl`; the package publishes the file as
8
+ * `@erd-studio/renderer/edge-routing-worker.js`). A page whose CSP allows
9
+ * its own scripts (`script-src 'self'`) but not `blob:` (as some app-hosting
10
+ * platforms set it)
11
+ * can run a same-origin worker file;
12
+ * - from the code inlined at build time as `__ERD_EDGE_ROUTING_WORKER__` (the
13
+ * extension's `esbuild.js` and the package's `build.mjs` both define it),
14
+ * through a blob URL: a VS Code webview cannot load a worker from a file.
15
+ * Where neither starts (unit tests, no `Worker`, a CSP that refuses both, or
16
+ * a URL worker that fails to load, which `onFailure` reports), the canvas
17
+ * routes on the main thread.
10
18
  */
11
19
  import type { WorkerRouteRequest, WorkerRouteResult } from './protocol.js';
12
20
  export interface RoutingWorkerEvents {
@@ -20,4 +28,11 @@ export interface RoutingWorkerHandle {
20
28
  }
21
29
  /** Starts a worker for one canvas. */
22
30
  export type RoutingWorkerFactory = (events: RoutingWorkerEvents) => RoutingWorkerHandle | null;
31
+ /**
32
+ * A worker factory that starts from `url` (the host's copy of
33
+ * `edge-routing-worker.js`) when given one, else, or when that cannot start,
34
+ * from the inlined code.
35
+ */
36
+ export declare function routingWorkerFactory(url?: string | null): RoutingWorkerFactory;
37
+ /** Starts a worker from the inlined code (no host URL). */
23
38
  export declare const createRoutingWorker: RoutingWorkerFactory;
@@ -142,6 +142,14 @@ export interface CanvasState {
142
142
  * a line missing from it) means `FkEdge` draws its smooth-step fallback.
143
143
  */
144
144
  edgeRoutes: Map<string, RoutedEdge> | null;
145
+ /**
146
+ * Where the host serves the line-routing worker file
147
+ * (`@erd-studio/renderer/edge-routing-worker.js`), for a page whose CSP
148
+ * refuses a blob worker. Read once, when the canvas starts its router.
149
+ * Absent or null: the worker starts from the inlined code, as before.
150
+ * Optional, so a host that hand-builds `CanvasState` need not add it.
151
+ */
152
+ routingWorkerUrl?: string | null;
145
153
  }
146
154
  export interface CanvasActions {
147
155
  setSearchQuery: (query: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erd-studio/renderer",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "ERD Studio's React Flow canvas: the entity-relationship diagram renderer shared by the VS Code extension, with a read-only viewer mode.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -32,6 +32,7 @@
32
32
  "default": "./dist/sizing.js"
33
33
  },
34
34
  "./styles.css": "./dist/styles.css",
35
+ "./edge-routing-worker.js": "./dist/edge-routing-worker.js",
35
36
  "./package.json": "./package.json"
36
37
  },
37
38
  "files": [