jbrowse-plugin-graphgenomeviewer 4.0.15 → 4.0.16
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/dist/chunks/{GraphGenomeView-5SMMNFD4.js → GraphGenomeView-V6F3ZCVI.js} +2 -2
- package/dist/chunks/{LinearGraphDisplay-BEOEIUGA.js → LinearGraphDisplay-LDAAPWXR.js} +2 -2
- package/dist/chunks/{chunk-JXAJ7YLT.js → chunk-NMCXEYLU.js} +2 -2
- package/dist/chunks/{chunk-JXAJ7YLT.js.map → chunk-NMCXEYLU.js.map} +3 -3
- package/dist/chunks/{chunk-UQN2NWT5.js → chunk-SH2KJYXT.js} +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
- package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/version.ts +1 -1
- /package/dist/chunks/{GraphGenomeView-5SMMNFD4.js.map → GraphGenomeView-V6F3ZCVI.js.map} +0 -0
- /package/dist/chunks/{LinearGraphDisplay-BEOEIUGA.js.map → LinearGraphDisplay-LDAAPWXR.js.map} +0 -0
- /package/dist/chunks/{chunk-UQN2NWT5.js.map → chunk-SH2KJYXT.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as x}from"./chunk-
|
|
1
|
+
import{a as x}from"./chunk-SH2KJYXT.js";import"./chunk-NMCXEYLU.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-5E7TVPCI.js";import{B as L}from"./chunk-IUIIYSGF.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as s,b as g,c as v,d as G,e as B}from"./chunk-XEJ47DLD.js";import{b as a}from"./chunk-FY3BTKY4.js";var S=a(g(),1);var m=a(G(),1),n=a(v(),1),C=a(g(),1),P=a(L(),1),o=a(s(),1),I=(0,P.makeStyles)()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),b=(0,C.observer)(function({model:e}){let{classes:r}=I();return e.isLoading?(0,o.jsxs)(n.Paper,{className:r.paper,"data-testid":"graph-genome-loading",children:[(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(m.LoadingEllipses,{variant:"h6",message:e.statusMessage}),(0,o.jsx)(n.Button,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),(0,o.jsx)(n.LinearProgress,{variant:"indeterminate"})]}):e.error?(0,o.jsx)(n.Paper,{className:r.paper,children:(0,o.jsx)(m.ErrorBanner,{error:e.error,onReset:()=>{e.retryLoad()}})}):(0,o.jsx)(n.Paper,{className:r.paper,"data-testid":"graph-genome-load-canceled",children:(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(n.Typography,{variant:"h6",children:"Loading canceled"}),(0,o.jsx)(n.Button,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),h=b;var M=a(B(),1),N=a(G(),1),i=a(v(),1),w=a(g(),1),E=a(L(),1),t=a(s(),1),k=`H VN:Z:1.0
|
|
2
2
|
S 1 ACGT
|
|
3
3
|
S 2 GGCC
|
|
4
4
|
S 3 TTAA
|
|
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
|
|
|
7
7
|
L 1 + 3 + 0M
|
|
8
8
|
L 2 + 4 + 0M
|
|
9
9
|
L 3 + 4 + 0M`,z=(0,E.makeStyles)()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),R=(0,w.observer)(function({model:e}){let{classes:r}=z(),[d,T]=(0,M.useState)("");function y(){d.trim()&&e.loadGFAFromLocation({uri:d,locationType:"UriLocation"})}function A(p){let c=p.target.files?.[0];c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return(0,t.jsxs)(i.Paper,{className:r.paper,children:[(0,t.jsx)("div",{className:r.header,children:(0,t.jsx)(i.Typography,{variant:"h6",children:"Load a GFA graph"})}),(0,t.jsxs)("div",{className:r.column,children:[(0,t.jsxs)("div",{className:r.rowCenter,children:[(0,t.jsxs)(i.Button,{variant:"outlined",component:"label",size:"small",children:["Choose file",(0,t.jsx)("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:p=>{A(p)}})]}),(0,t.jsx)(i.Typography,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),(0,t.jsxs)("div",{className:r.rowEnd,children:[(0,t.jsx)(i.TextField,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:d,onChange:p=>{T(p.target.value)},onKeyDown:p=>{p.key==="Enter"&&y()},className:r.flex1}),(0,t.jsx)(i.Button,{variant:"contained",onClick:()=>{y()},disabled:!d.trim(),children:"Open"})]})]}),(0,t.jsx)("div",{className:r.footer,children:(0,t.jsx)(i.Button,{size:"small",onClick:()=>{e.loadGFA(k,"Example graph")},children:"Load 4-node example"})}),e.error?(0,t.jsx)(N.ErrorBanner,{error:e.error}):null]})}),F=R;var l=a(s(),1),U=(0,S.observer)(function({model:e}){return e.hasGraph?(0,l.jsx)(x,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?(0,l.jsx)(h,{model:e}):(0,l.jsxs)(l.Fragment,{children:[e.isLoading?(0,l.jsx)(h,{model:e}):null,(0,l.jsx)("div",{hidden:e.isLoading,children:(0,l.jsx)(F,{model:e})})]})}),O=U;export{O as default};
|
|
10
|
-
//# sourceMappingURL=GraphGenomeView-
|
|
10
|
+
//# sourceMappingURL=GraphGenomeView-V6F3ZCVI.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=LinearGraphDisplay-
|
|
1
|
+
import{a as i}from"./chunk-SH2KJYXT.js";import"./chunk-NMCXEYLU.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-5E7TVPCI.js";import"./chunk-IUIIYSGF.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as e,b as d}from"./chunk-XEJ47DLD.js";import{a as h,b as t}from"./chunk-FY3BTKY4.js";var p=h((l,o)=>{o.exports=JBrowseExports["@jbrowse/display-kit/DisplayChrome"]});var s=t(p(),1),n=t(d(),1);var r=t(e(),1),y=(0,n.observer)(function({model:a}){return(0,r.jsx)(s.DisplayStatusChrome,{model:a,phase:a.displayPhase,drawn:a.painted&&a.geometryPainted,testid:"linear-graph-display","data-layout":a.chosenLayoutMode,"data-cut-tier":a.cutTier,"data-recuts":a.recuts,"data-node-count":a.hasGraph?a.nodeCount:void 0,"data-loading":a.isLoading?"":void 0,style:{width:a.paneWidth,height:a.height,overflow:"hidden"},children:(0,r.jsx)(i,{model:a,ownChrome:!1})})}),c=y;export{c as default};
|
|
2
|
+
//# sourceMappingURL=LinearGraphDisplay-LDAAPWXR.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as dt}from"./chunk-UQEPPJEO.js";import{c as ut}from"./chunk-SCMIJAAX.js";import{i as Le,n as ft,o as pt,p as yn,q as xn,t as ht,u as mt,y as bt,z as Mn}from"./chunk-IUIIYSGF.js";import{a as Ge,b as _,c as Ze,d as ce,e as ue,f as ct,h as Je}from"./chunk-EFVAQ2KM.js";import{a as Qe,c as it,d as lt}from"./chunk-KULNKXPT.js";import{a as Ke}from"./chunk-XEJ47DLD.js";import{a as Ue,b as le}from"./chunk-FY3BTKY4.js";var yt=Ue((al,gt)=>{gt.exports=JBrowseExports["@mui/material/SvgIcon"]});var Ms=Ue((Ql,Jt)=>{Jt.exports=JBrowseExports.mobx});var pn=Ue((su,Vo)=>{Vo.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var tl=Ue((od,xr)=>{xr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var te=le(yt(),1);function ul(e){let n=t=>Math.round(t*100)/100;return e.map((t,r)=>`${r?"L":"M"}${n(t.x)},${n(t.y)}`).join("")}function xt(e,n,t,r,o){let s=Math.hypot(r-n,t-e);if(s===0)return[t,r];let a=(t-e)/s,l=(r-n)/s;return[t+o*a,r+o*l]}function Nn(e,n){let t=1-n,r=t*t*t,o=3*t*t*n,s=3*t*n*n,a=n*n*n;return{x:r*e.x0+o*e.cx0+s*e.cx1+a*e.x1,y:r*e.y0+o*e.cy0+s*e.cy1+a*e.y1}}function Rt(e){let n=e[Math.floor(e.length/2)];return n?Nn(n,.5):void 0}function Et(e){let n=1/0,t=1/0,r=-1/0,o=-1/0;for(let s of e)n=Math.min(n,s.x0,s.cx0,s.cx1,s.x1),r=Math.max(r,s.x0,s.cx0,s.cx1,s.x1),t=Math.min(t,s.y0,s.cy0,s.cy1,s.y1),o=Math.max(o,s.y0,s.cy0,s.cy1,s.y1);return{minX:n,minY:t,maxX:r,maxY:o}}function Rr(e,n,t){let r=Nn(e,n),o=Nn(e,t),s=(t-n)/3,a=Mt(e,n),l=Mt(e,t);return{x0:r.x,y0:r.y,cx0:r.x+a.x*s,cy0:r.y+a.y*s,cx1:o.x-l.x*s,cy1:o.y-l.y*s,x1:o.x,y1:o.y}}function Mt(e,n){let t=1-n,r=3*t*t,o=6*t*n,s=3*n*n;return{x:r*(e.cx0-e.x0)+o*(e.cx1-e.cx0)+s*(e.x1-e.cx1),y:r*(e.cy0-e.y0)+o*(e.cy1-e.cy0)+s*(e.y1-e.cy1)}}function At(e,n){let t=[];for(let r of e){let o=Math.hypot(r.cx0-r.x0,r.cy0-r.y0)+Math.hypot(r.cx1-r.cx0,r.cy1-r.cy0)+Math.hypot(r.x1-r.cx1,r.y1-r.cy1),s=Math.max(3,Math.round(o/n)|1);for(let a=0;a<s;a+=2)t.push([Rr(r,a/s,(a+1)/s)])}return t}function Tt(e,n,t){let r=new Array(e.length);for(let o=0;o<e.length;o++){let s=e[o];r[o]={x0:s.x0+n,y0:s.y0+t,cx0:s.cx0+n,cy0:s.cy0+t,cx1:s.cx1+n,cy1:s.cy1+t,x1:s.x1+n,y1:s.y1+t}}return r}function wn(e,n){let t=e.length-1;return n==="end"?{at:e[t],inward:e[t-1]}:{at:e[0],inward:e[1]}}var Er=.5,Ar=80;function wt(e){let n=1/0,t=-1/0;for(let r of e)n=Math.min(n,r.x),t=Math.max(t,r.x);return{min:n,max:t}}function St(e,n){return Math.max(0,n.min-e,e-n.max)}function Lt(e,n,t){let r=St(e[0].x,n),o=St(e[e.length-1].x,n);return r===o?t:r<o?"start":"end"}function Tr(e,n){return{from:Lt(e,wt(n),"end"),to:Lt(n,wt(e),"start")}}var Cr=.75,Ir=1.15,_r=.35,vr=60;function Br(e,n,t,r,o,s){let a=Math.hypot(t-e,r-n),l=a===0?1:(t-e)/a,i=a===0?0:(r-n)/a,u=0,f=1/0,c=-1/0;for(let m of o){let b=m.x-e,g=m.y-n,x=b*-i+g*l;Math.abs(x)>Math.abs(u)&&(u=x);let R=b*l+g*i;f=Math.min(f,R),c=Math.max(c,R)}let d=o.length?c-f:0,h=Math.max(Math.abs(u)*Ir/Cr,d*_r),p=s===void 0?h:Math.min(h,s);return u<0?-p:p}function en({scaleX:e,scaleY:n}){return n/e}var Or=3;function Sn(e,n,t){let r=n.x-e.x,o=(n.y-e.y)*t,s=Math.hypot(r,o);return s===0?void 0:{x:r/s,y:o/s}}function Ct(e,n,t,r,o=Or){let s=en(r),a=Sn(e[e.length-1],n[0],s)??Sn(e[0],e.at(-1),s)??Sn(n[0],n.at(-1),s)??{x:1,y:0},l=[];for(let i=0;i<t;i++){let u=(i-(t-1)/2)*o;l.push({x:-a.y*u,y:a.x*u/s})}return l}function Ln(e,n){return e.map(t=>({x:t.x,y:t.y*n}))}function Pr(e,n){for(let t of e)t.y0/=n,t.cy0/=n,t.cy1/=n,t.y1/=n;return e}var Gr=12,Dr=40;function Nt(e,n){let t=0;for(let s=1;s<e.length;s++)t+=Math.hypot(e[s].x-e[s-1].x,e[s].y-e[s-1].y);let r=t*n;return Math.min(Dr,Math.max(Gr,r/2))/Math.max(n,Number.EPSILON)}function It(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function $r(e,n,t,r){let{at:o,inward:s}=e,a=s?o.x-s.x:1,l=s?o.y-s.y:0,i=Math.hypot(a,l)||1,u=a/i,f=l/i,c=o.x+t,d=o.y+r,h=c+u*n/3,p=d+f*n/3,m=c+u*n,b=d+f*n,g=-f*n/2,x=u*n/2;return[{x0:c,y0:d,cx0:h,cy0:p,cx1:m+g,cy1:b+x,x1:m,y1:b},{x0:m,y0:b,cx0:m-g,cy0:b-x,cx1:h,cy1:p,x1:c,y1:d}]}function De(e,n,t,r,o,s,a=[],l){let i=s.scaleX,u=en(s),f=l??(s.pixelRows?vr:void 0);if(u!==1)return Pr(De(Ln(e,u),Ln(n,u),t,r,o*u,{scaleX:i,scaleY:i},Ln(a,u),f===void 0?void 0:f*u),u);if(typeof t=="string")return $r(wn(e,t),Nt(e,i),r,o);let c=t?{from:"end",to:"start"}:Tr(e,n),d=wn(e,c.from),h=wn(n,c.to),p=d.at,m=h.at,b=p.x+r,g=p.y+o,x=m.x+r,R=m.y+o;if(t){let N=1,L=0;if(d.inward){let U=p.x-d.inward.x,j=p.y-d.inward.y,V=Math.hypot(U,j);V>0&&(N=U/V,L=j/V)}let S=Nt(e,i),A=-L,M=N,C=(p.x+m.x)/2+r+A*S,B=(p.y+m.y)/2+o+M*S,G=b+N*S,X=g+L*S,F=x-N*S,H=R-L*S;return[{x0:b,y0:g,cx0:G,cy0:X,cx1:G+A*S,cy1:X+M*S,x1:C,y1:B},{x0:C,y0:B,cx0:F+A*S,cy0:H+M*S,cx1:F,cy1:H,x1:x,y1:R}]}else{let N=d.inward??{x:p.x-(m.x-p.x),y:p.y-(m.y-p.y)},L=h.inward??{x:m.x-(p.x-m.x),y:m.y-(p.y-m.y)},S=Math.hypot(x-b,R-g),A=(Z,J,se,_e)=>{let ae=J.x-Z.x,ie=J.y-Z.y,ee=Math.hypot(ae,ie),me=ee===0?0:(se*ae+_e*ie)/ee;return Math.max(0,Math.min(S*Er,Ar,me*.5))},M=m.x-p.x,C=m.y-p.y,[B,G]=xt(N.x,N.y,p.x,p.y,A(N,p,M,C)),[X,F]=xt(L.x,L.y,m.x,m.y,A(L,m,-M,-C)),H=a.length?Br(b,g,x,R,a,f):0,U=S===0?1:S,j=(x-b)/U,V=(R-g)/U,ke=-V*H,O=j*H,$=j*Math.abs(H),K=V*Math.abs(H);return[{x0:b,y0:g,cx0:B+r+ke-$,cy0:G+o+O-K,cx1:X+r+ke+$,cy1:F+o+O+K,x1:x,y1:R}]}}var qr=1;function Rn(e,n){return n.flatMap(t=>e[t]??[])}function _t(e,n,t){let r=e[n.from],o=e[n.to];return r?.length&&o?.length?De(r,o,n.from===n.to,0,0,t,Rn(e,n.bypassed)):void 0}function Fr(e){let n=new Map;for(let t of e.nodes)if(_(t)){let r=n.get(t.stable.refName);r?r.push(t):n.set(t.stable.refName,[t])}for(let t of n.values())t.sort((r,o)=>r.stable.start-o.stable.start);return n}function Hr(e,n,t){let r=[];if(e)for(let o=ct(e,n);o<e.length;o++){let s=e[o];if(s.stable.start>=t)break;s.stable.start+s.length<=t&&r.push(s.id)}return r}function Wr(e,n,t,r){let{fromStrand:o,toStrand:s}=e;if(o===void 0||s===void 0)return!0;let a=o===(n.stable.strand??"+"),l=s===(t.stable.strand??"+");return r?a&&l:!a&&!l}function hl(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fr(e),r=[];for(let o=0;o<e.edges.length;o++){let s=e.edges[o],a=n.get(s.from),l=n.get(s.to);if(a!==void 0&&l!==void 0&&_(a)&&_(l)&&a.stable.refName===l.stable.refName){let i=a.stable.start<=l.stable.start,[u,f]=i?[a,l]:[l,a],c=u.stable.start+u.length,d=f.stable.start,h=d-c;if(h>=qr&&Wr(s,a,l,i)){let p=u.stable.refName;r.push({edgeIndex:o,from:s.from,to:s.to,refName:p,start:c,end:d,bp:h,bypassed:Hr(t.get(p),c,d)})}}}return r}function Ne(e){return e.endsWith("-")?"-":"+"}function vt(e){return e==="+"?"-":"+"}function Xr(e){let n=(e.fromStrand??Ne(e.from))===Ne(e.from)?"end":"start",t=(e.toStrand??Ne(e.to))===Ne(e.to)?"start":"end";return{from:n,to:t}}function gl(e){let n=e.edges.map(Xr),t=new Map,r=(d,h,p)=>{let m=`${d}|${h}`,b=t.get(m);b?b.push(p):t.set(m,[p])};e.edges.forEach((d,h)=>{r(d.from,n[h].from,h),r(d.to,n[h].to,h)});let o=d=>{let h=t.get(`${d}|end`);if(h?.length!==1)return;let p=h[0],m=e.edges[p];return m.from===d&&m.to!==d&&n[p].from==="end"&&n[p].to==="start"&&t.get(`${m.to}|start`)?.length===1?p:void 0},s=new Set,a=new Map,l=new Map;for(let d of e.nodes){let h=t.get(`${d.id}|start`),p=h?.length===1?e.edges[h[0]].from:void 0;if(a.has(d.id)||p!==void 0&&o(p)===h[0])continue;let m=[d.id];for(;;){let b=o(m.at(-1)),g=b===void 0?void 0:e.edges[b].to;if(g===void 0||a.has(g))break;s.add(b),m.push(g)}for(let b of m)a.set(b,d.id);m.length>1&&l.set(d.id,m)}for(let d of e.nodes)a.has(d.id)||a.set(d.id,d.id);let i=new Map(e.nodes.map(d=>[d.id,d])),u=[];for(let d of e.nodes){if(a.get(d.id)!==d.id)continue;let h=l.get(d.id);if(!h){u.push(d);continue}let p=h.map(g=>i.get(g)),m=p.filter(_),b=m.length?m.reduce((g,x)=>g.stable.start<=x.stable.start?g:x):p[0];u.push({id:d.id,name:d.name,length:p.reduce((g,x)=>g+x.length,0),depth:d.depth,stable:b.stable})}let f=new Set,c=[];return e.edges.forEach((d,h)=>{let p=a.get(d.from),m=a.get(d.to),b=n[h],g=`${p}|${b.from}>${m}|${b.to}`;s.has(h)||f.has(g)||(f.add(g),c.push({from:p,to:m,...b.from==="start"?{fromStrand:vt(Ne(p))}:{},...b.to==="end"?{toStrand:vt(Ne(m))}:{}}))}),{graph:{...e,nodes:u,edges:c,paths:void 0,pathVisits:void 0},runs:l}}function yl(e,n,t){let r={...e};for(let[o,s]of n){let a=e[o];if(!a?.length)continue;delete r[o];let l=An(a),i=l.at(-1),u=s.map(d=>Math.max(t(d),0)),f=u.reduce((d,h)=>d+h,0)||s.length,c=0;s.forEach((d,h)=>{let p=f?u[h]/f*i:i/s.length,m=h===s.length-1?i:c+p;r[d]=Ot(a,l,c,m),c=m})}return r}function xl(e,n,t){if(e.length===0)return[];let r=An(e),o=r.at(-1);return Ot(e,r,n*o,t*o)}function Bt(e){let n=An(e);return En(e,n,n.at(-1)/2)}function An(e){let n=[0];for(let t=1;t<e.length;t++)n.push(n[t-1]+Math.hypot(e[t].x-e[t-1].x,e[t].y-e[t-1].y));return n}function En(e,n,t){if(t<=0)return{...e[0]};let r=1;for(;r<n.length&&n[r]<t;)r++;if(r>=n.length)return{...e.at(-1)};let o=n[r]-n[r-1],s=o>0?(t-n[r-1])/o:0,a=e[r-1],l=e[r];return{x:a.x+(l.x-a.x)*s,y:a.y+(l.y-a.y)*s}}function Ot(e,n,t,r){let o=[En(e,n,t)];for(let s=0;s<e.length;s++)n[s]>t&&n[s]<r&&o.push({...e[s]});return o.push(En(e,n,r)),o}function Tn(e){return e.length*6.2+8}function kr(e,n){return e.x0<n.x1&&e.x1>n.x0&&e.y0<n.y1&&e.y1>n.y0}function Pt(e,n){return e.x1<=0||e.x0>=n.width||e.y1<=0||e.y0>=n.height}function Yr(e,n){return e.x0>=0&&e.x1<=n.width&&e.y0>=0&&e.y1<=n.height}function Cn(e,n=[]){let t=[...n];return r=>Pt(r,e)||t.some(o=>kr(o,r))?!1:(t.push(r),!0)}function $e(e,n,t){let r=[];for(let s of e){let a=Tn(s.text),l=s.y>n.height/2?-1:1;for(let i=0;i<=(s.stack??0);i++){let u=s.y+l*i*19,f={x0:s.x-a/2,x1:s.x+a/2,y0:u-11-4,y1:u+4};if(Pt(f,n))break;if(Yr(f,n)&&t(f)){r.push({...s,y:u,w:a});break}}}return r}var zr=26,jr=4e4,Vr=8,Ur=8,Kr=5.7,Qr=6,Zr=13,qe=3,nn=2;function rn(e){return(e.length*Kr+Qr+qe)/2}var de=(Zr+qe)/2,Jr=rn("1 bp");function tn(e,n,t){return{x0:n-e,x1:n+e,y0:t-de,y1:t+de}}function qt(e,n){return{x0:6,x1:6+e.length*6.2+8+qe,y0:n-8-qe/2,y1:n+8+qe/2}}function on(e,n,t){return t<n?e:Math.min(Math.max(e,n),t)}function sn(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:e>=1e3?`${+(e/1e3).toFixed(1)} kb`:`${e} bp`}function Gt(e){return`${sn(e)} del`}function es(e,n,t,r){let o=e[0],s=e[e.length-1],a=(n.x-(o.x0+s.x1)/2)*t,l=(n.y-(o.y0+s.y1)/2)*r,i=Math.hypot(a,l);return i===0?{x:0,y:-1}:{x:a/i,y:l/i}}function ns(e,n){return Math.abs(n.x)*(e.x1-e.x0)/2+Math.abs(n.y)*(e.y1-e.y0)/2}function ts(e,n){let t=(e.x1-e.x0)/2,r=(e.y1-e.y0)/2;return Math.min(n.x===0?1/0:t/Math.abs(n.x),n.y===0?1/0:r/Math.abs(n.y))}function os(e,n,t){let r=0;for(let o=1;o<e.length;o++){let s=e[o-1],a=e[o];r+=Math.hypot((a.x-s.x)*n,(a.y-s.y)*t)}return r}function rs(e,n){let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let a of e)for(let l of n[a]??[])t=Math.min(t,l.x),o=Math.max(o,l.x),r=Math.min(r,l.y),s=Math.max(s,l.y);return t===1/0?void 0:{minX:t,minY:r,maxX:o,maxY:s}}var Dt=new WeakMap;function ss(e,n){let t=Dt.get(e);if(t?.nodeLengths===n)return t.order;let r=Object.entries(e).filter(([o,s])=>s.length>0&&n.has(o)).sort(([o],[s])=>n.get(s)-n.get(o));return Dt.set(e,{nodeLengths:n,order:r}),r}var $t=new WeakMap;function as(e,n,t,r){let{scaleX:o,scaleY:s}=t,a=$t.get(e);if(a?.deletions===n&&a.scaleX===o&&a.scaleY===s&&a.version===r)return a.arcs;let l=[];for(let i of[...n].sort((u,f)=>f.bp-u.bp)){let u=_t(e,i,t),f=u?Rt(u):void 0;if(u&&f){let{minX:c,minY:d,maxX:h,maxY:p}=Et(u);l.push({deletion:i,curves:u,apex:f,extent:Math.max((h-c)*o,(p-d)*s)})}}return $t.set(e,{deletions:n,scaleX:o,scaleY:s,version:r,arcs:l}),l}function Ft({nodePositions:e,nodeLengths:n,deletions:t,alleleDeletions:r,axis:o,translateX:s,translateY:a,width:l,height:i,version:u=0}){let{scaleX:f,scaleY:c}=o,d=[],h=[];for(let{deletion:b,curves:g,apex:x,extent:R}of as(e,t,o,u))if(R>=zr){let N=Gt(b.bp),L=rn(N),S=tn(L,0,0),A=x.x*f+s,M=x.y*c+a,C=R>=L*2/nn,B=es(g,x,f,c),G=ns(S,B)+Ur,X=C?A:on(A+B.x*G,L,l-L),F=C?M:on(M+B.y*G,de,i-de),H=Math.hypot(X-A,F-M),U;if(H>0){let j={x:(X-A)/H,y:(F-M)/H},V=ts(S,j);U={arcX:A,arcY:M,labelX:X-j.x*V,labelY:F-j.y*V}}d.push({label:{key:`del:${b.edgeIndex}`,text:N,x:X,y:F,kind:"deletion",leader:U},box:tn(L,X,F)})}let p=new Set,m=[...r??[]].sort((b,g)=>g.bp-b.bp);for(let b of m){let g=rs(b.nodeIds,e);if(!g)continue;let x=Math.max(g.minX*f+s,0),R=Math.min(g.maxX*f+s,l),N=Math.max(g.minY*c+a,0),L=Math.min(g.maxY*c+a,i);if(R<x||L<N)continue;let S=Math.max(R-x,L-N),A=Gt(b.bp),M=rn(A);if(S>=M*2/nn){for(let G of b.nodeIds)p.add(G);let C=on((x+R)/2,M,l-M),B=on((N+L)/2,de,i-de);d.push({label:{key:`alleledel:${b.nodeIds.join(",")}`,text:A,x:C,y:B,kind:"deletion"},box:tn(M,C,B)})}}for(let[b,g]of ss(e,n)){if(p.has(b))continue;let{x,y:R}=Bt(g),N=R*c+a;if(N+de<=0||N-de>=i)continue;let L=os(g,f,c);if(L<Jr*2/nn)continue;let S=sn(n.get(b)),A=rn(S);if(L>=A*2/nn){let M=x*f+s;h.push({label:{key:`node:${b}`,text:S,x:M,y:N,kind:"node"},box:tn(A,M,N)})}}return{deletions:d,nodes:h}}function Ht(e,n){return Math.max(Vr,Math.floor(e*n/jr))}function In(e,n,t=1/0){let r=[];for(let{label:o,box:s}of e){if(r.length>=t)break;n(s)&&r.push(o)}return r}var ls=3.4,Wt=6,cs=8,us=18,ds=2,fs=60,ps=8,Xt=15;function _n(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function Cl(e){let{paneWidth:n,canvasHeight:t,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:n,height:t},i=M=>({x:M.x*s+r,y:M.y*a+o}),u=e.drawnRowLabels.map(({label:M,y:C})=>qt(M,C*a+o)),f=e.referenceStripZonePx??0;f>0&&u.push({x0:0,x1:n,y0:0,y1:f}),e.legendSize.width>0&&u.push({x0:n-Wt-e.legendSize.width,x1:n,y0:0,y1:f+Wt+e.legendSize.height}),e.poppedFrom&&u.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let c=Cn(l,u),d=e.drawnRowLabels.length>0,h=d?Math.min(...e.drawnRowLabels.map(M=>M.y)):1/0,p=e.contigThickness*ls,m=_n(e.bubbleHalos,M=>M.members),b=$e(m.map(M=>{let{x:C,y:B}=i({x:M.labelAt.x,y:Math.min(M.labelAt.y,h)}),G=B-p/2-6;return{item:M,x:C,y:d?Math.max(G,Xt):G,text:M.label}}),l,c),g=Math.max(2,Math.min(ps,Math.floor((o-fs)/19))),x=$e(_n(e.bubbleGlyphs,M=>M.bubble.end-M.bubble.start).flatMap(M=>{let C=(M.bubble.start+M.bubble.end)/2*s+r,B=Tn(M.label)/2;return C<0||C>n?[]:[{item:{glyph:M,glyphX:C},x:Math.min(Math.max(C,B),n-B),y:Xt,text:M.label,stack:g-1}]}),l,c),R=$e(_n(e.genePins,M=>M.gene.end-M.gene.start).map(M=>{let{x:C,y:B}=i(M.at);return{item:M,x:C,y:B+e.contigThickness+us,text:M.covered<.98?`${M.gene.name} \u2026`:M.gene.name,stack:ds}}),l,c),N=e.nodePositions&&e.labelsNodeSizes?Ft({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:n,height:t,version:e.positionsVersion}):{deletions:[],nodes:[]},L=In(N.deletions,c),S=$e(m.flatMap(M=>M.routes.map(C=>{let{x:B,y:G}=i(C.at);return{item:{halo:M,route:C},x:B,y:G+4,text:C.text,stack:cs}})),l,c),A=In(N.nodes,c,Ht(n,t));return{bubbles:b,glyphs:x,genes:R,routes:S,sizes:[...L,...A]}}function Bl(e){return Ge(e)?zt(e):void 0}function zt(e){return{sample:Qe(e.stable.refName),haplotype:it(e.stable.refName),refName:lt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function hs(e,n){let t=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of t)o=o&&s.start-o.end<=n?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function ms(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ol(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Ge(o)){let s=zt(o),a=ms(s),l=t.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):t.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of t.values()){let s=hs(o.spans,n);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function bs(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function Pl(e,n){return e.flatMap(t=>{let r=bs(n,t);return r===void 0?[]:[{...t,sample:r}]})}function Gl(e){return`${e.refName}:${e.start+1}-${e.end}`}function vn(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var jt=le(Ke(),1),Vt=(0,te.createSvgIcon)((0,jt.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Ut=le(Ke(),1),Kt=(0,te.createSvgIcon)((0,Ut.jsx)("path",{d:"M17 5h-2V3h2zm-2 16h2v-2.59L19.59 21 21 19.59 18.41 17H21v-2h-6zm4-12h2V7h-2zm0 4h2v-2h-2zm-8 8h2v-2h-2zM7 5h2V3H7zM3 17h2v-2H3zm2 4v-2H3c0 1.1.9 2 2 2M19 3v2h2c0-1.1-.9-2-2-2m-8 2h2V3h-2zM3 9h2V7H3zm4 12h2v-2H7zm-4-8h2v-2H3zm0-8h2V3c-1.1 0-2 .9-2 2"}),"HighlightAlt");var Qt=le(Ke(),1),Bn=(0,te.createSvgIcon)((0,Qt.jsx)("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var gs="Linear genome view",ys="Linear synteny view",xs="No synteny track in this session aligns these assemblies";function Zt({label:e,icon:n,entries:t,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=t,i=s?[{label:e,icon:n,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return t.length===0?i:t.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:n,onClick:o(l)}]:[{label:e,icon:n,type:"subMenu",subMenu:t.map(u=>({label:r(u),onClick:o(u)}))}]}function Vl({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...Zt({label:gs,icon:Bn,entries:e,entryLabel:s=>`${s.sample} ${vn(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?Zt({label:`${ys} (${o} assemblies)`,icon:Vt,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:xs,onSelect:s=>()=>{r(s.trackId)}}):[]]}function Ul({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${vn(e.location)}`,target:e}:void 0,n&&n.assembly!==e?.assembly?{label:`Open in ${n.assembly} \u2014 around this node`,target:n}:void 0].filter(a=>a!==void 0);return[...o&&t?[{label:`Highlight in ${t.assembly}`,icon:Kt,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:Bn,onClick:()=>{r(l)}}))]}var ws=10;function Ss(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=ws*(o.end-o.start)&&(t===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=t/2))}var Ls=40;function ge(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Ns(e,n){let t=ge(e),r=ge(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function eo(e){return e>=dt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Jl(e,n=[]){let t=Rs(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function Rs(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=Ns(r,o);if(a>=Ls)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${eo(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${ge(o)} inv`};let u=o!==r?Ss(e,n):void 0;if(u){let c=u.name?` (${u.name})`:"";return{kind:"repeat",label:`${i} repeat array${c}, ${eo(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${ge(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${ge(o-t)} ins${f}`}:o===t?{kind:"deletion",label:`${ge(t-r)} del${f}`}:{kind:"complex",label:`${ge(t)} ref \u2192 ${i}, ${s} alleles`}}var ec={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},nc={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function tc(e){return e.segments.split(",").filter(Boolean)}function On(e){return e.id.endsWith("-")?"-":"+"}function Pn(e,n){return n===On(e)?e.id:`-${e.id}`}function Es(e,n){let t=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)t[o]=r,r+=e[o];let s=n;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],t[a]=s;return t}function As(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=Es(n,e.pathLength),o=(l,i=!1)=>{for(let u=0;u<r.length;u++){let f=r[u],c=n[u];if(f!==void 0&&c!==void 0&&f<=l&&(l<f+c||i&&l===f+c))return{s:u,local:l-f,room:f+c-l}}},s=(l,i)=>{let u=t[l],f=u.at(-1);i.type==="substitution"&&f?.type==="substitution"&&f.pos+f.seq.length===i.pos?f.seq+=i.seq:u.push(i)},a=e.pathStart;for(let l of ut(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let u=o(a),f=u?Math.min(i,u.room):i;u&&s(u.s,{type:"deletion",pos:u.local,length:f}),a+=f,i-=f}}return t}function no(e,n,t){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of n){let a=s.path.map(f=>r.get(f.name)),l=a.flatMap((f,c)=>f?[c]:[]),i=l[0],u=l.at(-1);if(i!==void 0&&u!==void 0){let f=As(s,a.map(h=>h?.length)),c=l.map(h=>Pn(a[h],s.path[h].strand)),d=a[u].length;o.push({id:t+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:c,sequenceNew:l.map((h,p)=>({nodeName:c[p],mismatches:f[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:u===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ts=["#6baed6","#4292c6","#2171b5","#08519c"],Cs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function to(e){let n=e.is_reverse?Cs:Ts;return n[e.id%n.length]}var Is=4;function Fe(e){let n=new Map;function t(r,o){let s=n.get(r);s?s.push(o):n.set(r,[o])}for(let r of e.edges)t(r.from,r.to),t(r.to,r.from);return n}function _s({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<Is&&o.length>0;l++){let i=[];for(let u of o){let f=t.get(u);if(f){for(let c of f)if(!r.has(c)){r.add(c);let d=n.get(c);d&&_(d)?(s=Math.min(s,d.stable.start+d.length),a=Math.max(a,d.stable.start)):i.push(c)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function vs({nodeId:e,nodeById:n,neighbors:t}){let r=n.get(e);return r===void 0?void 0:_(r)?{start:r.stable.start,end:r.stable.start+r.length}:_s({nodeId:e,nodeById:n,neighbors:t})}function oo(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fe(e),r=new Map;for(let o of e.nodes){let s=vs({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}function an(e){let n=e.split("#"),t=n.length>=2?Number(n[1]):Number.NaN;return{sample:n[0]??e,haplotype:Number.isFinite(t)?t:void 0}}function Bs(e,n,t,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=n.get(l);if(i){o.push(i);for(let u of t.get(l)??[]){let f=n.get(u);f&&(f.stable.rank===0?s.push(f):r.has(u)||(r.add(u),a.push(u)))}}}return{members:o,anchors:s}}function Os(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let t=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=t[0],o=t.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Ps(e,n,t){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of t.get(n.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of t.get(a)??[])if(r.has(i)){let u=o.get(i);(u===void 0||l<u)&&(o.set(i,l),s.push(i))}}return o}function Gs(e,n,t){let r=Ps(e,n,t),o=[...e].sort((i,u)=>r.get(i.id)-r.get(u.id)),s=new Map(o.map((i,u)=>[i.id,u])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,u]of o.entries()){let f=0;for(let c of t.get(u.id)??[]){let d=a.get(c);d&&s.get(c)<i&&(f=Math.max(f,l.get(c)+d.length))}l.set(u.id,f)}return{offsets:l,ordered:o}}function so(e){let n=new Map(e.nodes.filter(Ge).map(s=>[s.id,s])),t=Fe(e),r=new Set,o=[];for(let s of n.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Bs(s.id,n,t,r),i=Os(l);if(i){let{offsets:u,ordered:f}=Gs(a,i.entry,t);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:f.map(c=>c.id),nodeOffsets:f.map(c=>u.get(c.id)),pathLength:f.reduce((c,d)=>Math.max(c,u.get(d.id)+d.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ds=1,$s=.015;function ln({graph:e,span:n,rowY:t,positions:r}){let o=n*$s,s=so(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let c=f.refSpan-f.pathLength;c>=Ds&&l.push({nodeIds:f.nodeIds,bp:c});let d=Math.max(f.refSpan,o),h=f.pathLength>0?d/f.pathLength:0;f.nodeIds.forEach((p,m)=>{let b=a.get(p);if(b){let g=f.nodeOffsets[m],x=d/f.nodeIds.length,R=L=>f.start+L*h,N=t(b);r[p]=h?[{x:R(g),y:N},{x:R(g+b.length),y:N}]:[{x:f.start+m*x,y:N},{x:f.start+(m+1)*x,y:N}]}})}let i=Fe(e),u=Object.keys(r);for(let f of u){let c=r[f].at(-1).x;for(let d of i.get(f)??[]){let h=a.get(d);if(h&&!(d in r)){let p=t(h);r[d]=[{x:c,y:p},{x:c+o,y:p}],u.push(d)}}}return l}function qs(e){let n=new Set;for(let t of e.nodes)t.stable&&n.add(t.stable.rank);return new Map([...n].sort((t,r)=>t-r).map((t,r)=>[t,r]))}function ao(e,n){let t=ce(e);if(t.length===0)return;let r=Je(t,n),o=qs(e),s=ue(t),a=ln({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,u])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:u*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Fs=12,Gn=20;function io(e){return 10+8*Math.log2(1+e.length)}function fe(e,n){return e<n?-1:e>n?1:0}function co(e,n){return fe(e.at,n.at)||fe(e.side,n.side)||fe(e.hops,n.hops)}var lo={at:1/0,side:0,hops:0};function Hs(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=ks(e);return e.nodes.map(r=>r.id).sort((r,o)=>co(t.get(r)??lo,t.get(o)??lo)||fe(n.get(r).name,n.get(o).name)||fe(r,o))}function Ws(e,n){let t=new Set(e.nodes.map(f=>f.id)),r=new Map(n.map(f=>[f.id,f.stable.start])),o=new Map,s=new Map;n.forEach((f,c)=>{s.set(f.id,n[c-1]?.id),o.set(f.id,n[c+1]?.id)});let a=n[0]?.id,l=(f,c)=>{let d=o.get(f);o.set(f,c),s.set(c,f),o.set(c,d),d!==void 0&&s.set(d,c)},i=(f,c)=>{let d=s.get(f);d===void 0?(a=c,s.set(c,void 0),o.set(c,f),s.set(f,c)):l(d,c)};for(let f of e.paths??[]){let c=0,d=0,h;for(let g of f.nodeIds){let x=r.get(g);x!==void 0&&(h!==void 0&&x!==h&&(x>h?c++:d++),h=x)}let p=d>c?[...f.nodeIds].reverse():f.nodeIds,m,b=new Set;for(let g of p)if(o.has(g)){if(m===void 0)for(let x of b)i(g,x);m=g}else t.has(g)&&(m===void 0?b.add(g):(l(m,g),m=g))}let u=[];for(let f=a;f!==void 0;f=o.get(f))u.push(f);return u}function Xs(e,n){let t=[...n.entries()].sort(([a,l],[i,u])=>co(l,u)||fe(a,i)).map(([a])=>a),r=t.length;for(let a of t){let l=n.get(a);for(let i of e.get(a)??[])n.has(i)||(n.set(i,{at:l.at,side:1,hops:l.hops+1}),t.push(i))}let o=new Set(t.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=n.get(a),i=[a];s.add(a);let u=!0;for(let f of i){let{hops:c}=n.get(f),d=!0,h=!1;for(let p of e.get(f)??[]){let m=n.get(p);m.at===l&&o.has(p)?(d&&=m.hops<=c,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,u&&=m.at<l)}u&&=!d||h}if(u)for(let f of i){let c=n.get(f);n.set(f,{...c,side:-1,hops:-c.hops})}}}function ks(e){let n=new Set(e.nodes.map(s=>s.id)),t=new Map;for(let s of e.edges)!n.has(s.from)||!n.has(s.to)||((t.get(s.from)??t.set(s.from,[]).get(s.from)).push(s.to),(t.get(s.to)??t.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(_).sort((s,a)=>fe(s.stable.start,a.stable.start)||fe(s.name,a.name)),o=new Map;return Ws(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),Xs(t,o),o}function Ys(e){let n=new Map(e.nodes.map(c=>[c.id,c])),t=Hs(e),r=new Map(t.map((c,d)=>[c,d])),o=c=>_(n.get(c)),s=new Map(t.map(c=>[c,[]])),a=new Map(t.map(c=>[c,[]])),l=(c,d)=>{s.get(d).push(c),a.get(c).push(d)};for(let c of e.edges)c.from===c.to||!r.has(c.from)||!r.has(c.to)||(r.get(c.from)<r.get(c.to)?l(c.from,c.to):l(c.to,c.from));let i=t.filter(o);for(let c=1;c<i.length;c++)l(i[c-1],i[c]);let u=new Map;for(let c of t){let d=0;for(let h of s.get(c))d=Math.max(d,u.get(h)+1);u.set(c,d)}for(let c=t.length-1;c>=0;c--){let d=t[c],h=a.get(d);if(o(d)||h.length===0)continue;let p=1/0;for(let g of h)p=Math.min(p,u.get(g));let m=u.get(d),b=Math.max(m,p-1);u.set(d,Math.floor((m+b)/2))}let f=[];for(let c of t)(f[u.get(c)]??=[]).push(c);return{layers:f,layerOf:u,preds:s}}function uo(e){if(!e.nodes.some(_))return;let n=new Map(e.nodes.map(c=>[c.id,c])),t=c=>_(n.get(c)),{layers:r,layerOf:o,preds:s}=Ys(e),a=r.map(c=>{let d=0;for(let h of c)d=Math.max(d,io(n.get(h)));return d}),l=[],i=0;for(let c=0;c<r.length;c++)l[c]=i,i+=a[c]+Fs;let u=new Map;for(let c of r){let d=[];for(let p of c){if(t(p)){u.set(p,0);continue}let m=s.get(p).filter(g=>u.has(g)),b=0;for(let g of m)b+=u.get(g)/m.length;d.push({id:p,ideal:b===0?Gn:b})}d.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of d){let b=Math.round(m/Gn);b===0&&(b=m>=0?1:-1);for(let g=1;h.has(b);g++)h.has(b+g)?h.has(b-g)||(b-=g):b+=g;h.add(b),u.set(p,b*Gn)}}let f={};for(let c of e.nodes){let d=o.get(c.id),h=io(c),p=l[d]+a[d]/2,m=u.get(c.id);f[c.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function zs(e,n){let t=new Map;for(let o of e.nodes)if(Ze(o)){let{sample:s}=an(o.stable.refName);t.set(s,(t.get(s)??0)+o.length)}let r=new Map(n.map((o,s)=>[o,s]));return[...t.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||t.get(s)-t.get(o)||o.localeCompare(s))}function fo(e,n,t=[]){let r=ce(e),o=zs(e,t);if(r.length===0||o.length===0)return;let s=Je(r,n),a=new Map(o.map((d,h)=>[d,h+1])),l=ue(r),i=o.length+1,u=ln({graph:e,span:s,rowY:d=>{let h=d.stable;return((h?a.get(an(h.refName).sample):void 0)??i)*20},positions:l}),c=[{label:an(r[0].stable.refName).sample,y:0},...o.map(d=>({label:d,y:a.get(d)*20}))];return{nodePositions:l,rowLabels:c,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:u}}function Dn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Xe=!1,po=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Co(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(n=>po[n.id%po.length]),trackAlpha:e.trackAlpha??(()=>1)}}var v=Co({}),Wn=null,y=[],w=[],E=[],I=new Map,Ae=[],T=[],ye=[],kn=[],Yn=[],Q=-1,D=Dn(),Xn={minX:0,maxX:0,minY:0,maxY:0},He,cn=new Map;function Io(e,n,t=[],r={}){if(v=Co(r),Wn=r.bed??null,D=Dn(),ye=[],kn=[],Yn=[],Ae=[],Xn={minX:0,maxX:0,minY:0,maxY:0},He=void 0,cn=new Map,e.length===0||n.length===0)return;let o=$n(e);y=[],o.forEach((i,u)=>{y[u+1]=i}),w=$n(n);let s=t.length>0;E=$n(Ba(t));for(let i=w.length-1;i>=0;i-=1){let u=w[i];if(u.type===void 0&&(u.type="haplotype"),u.hidden===!0){w.splice(i,1);continue}u.indexOfFirstBase!==void 0&&(He=u.name)}if(w.length===0)return;Vs(0),I=bo(),Re(w),v.showReads&&E.length>0&&Re(E),To(),v.mergeNodesFlag&&(go(),Fn(),v.showReads&&E.length>0&&qn(),va(),I=bo(),To(),Re(w),v.showReads&&E.length>0&&Re(E)),go(),ma(),Xe&&console.log(`${y.length} nodes.`),Fn(),Q=xo(),ba(),Fn(),Q=xo();let a=v.showReads&&v.coarsenedReadView&&!s;if(a){let i=He===void 0?-1:w.findIndex(c=>c.name===He),u=i===-1?0:i,f=w.filter((c,d)=>d!==u);if(f.length>0){let c=No(f,"haplotype");c.length>0&&(w=[w[u]],E=c)}}Ea(),Ma(),v.showExonsFlag&&Wn!==null&&Ra();let l=v.showReads&&v.coarsenedReadView&&E.length>0&&!a;return v.showReads&&E.length>0?(Us(),qn(),Re(E),l&&(E=No(E,"read"),qn(),Re(E)),Qs(),w=w.concat(E)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),ya(),Ca(),Xe&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(ye)),ca(),{nodes:y,tracks:w,reads:E,nodeMap:I,shapes:D,bounds:Xn,maxOrder:Q,trackForRuler:He,coarsenedEdgeMeta:cn}}function Ee(e,n="plain"){return v.trackColor(e,n)}function js(e){return v.trackAlpha(e)}function $n(e){return structuredClone(e)}function k(e){let n=String(e);return n.length>=1&&n.startsWith("-")}function P(e){return k(e)?String(e).substring(1):e}function pe(e){return k(e)?e:`-${e}`}function _o(e){return k(e)?P(e):pe(e)}function un(e){return(e||1/e)>=0}function Vs(e){let n=new Set,t=w[e].sequence;for(let r=0;r<t.length;r+=1){let o=t[r];if(k(o)){let s=P(o),a=t.indexOf(s);(a===-1||a>r)&&n.add(s)}}for(let r of w){t=r.sequence;for(let o=0;o<t.length;o+=1){let s=t[o];k(s)?n.has(P(s))&&(t[o]=P(s)):n.has(s)&&(t[o]=pe(s))}}y.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function Us(){Ae=[];for(let n=0;n<=Q;n+=1)Ae[n]=[];let e=new Map;y.forEach(n=>{n.y!==void 0&&ho(e,n.order,n.y+n.contentHeight)}),w.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{ho(e,t.order,(t.y??0)+n.width)})}),y.forEach((n,t)=>{n.order>=0&&n.y===void 0&&(n.y=(e.get(n.order)??0)+25,n.contentHeight=0,Ae[n.order].push(t))})}function ho(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var dn=7;function Ks(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),E.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=dn),e.path.length===1){let t=e.path[0].node;t!==null&&y[t].internalReads.push(n)}else e.path.forEach((t,r)=>{if(r===0){let o=e.path[0].node;o!==null&&y[o].outgoingReads.push([n,r])}else{let o=t.node;o!==null&&y[o].incomingReads.push([n,r])}})})}function Qs(){sa(),Ks();let e=y.slice();e.sort(fn);let n=new Map;for(let a=0;a<E.length;a++){let l=E[a].sourceTrackID,i=n.get(l);i===void 0?n.set(l,[a]):i.push(a)}let t=Array.from(n.keys()).sort((a,l)=>a-l),r=t.length>1?dn:0;e.forEach(a=>{if(a)for(let l of t)Zs(n.get(l),a,r)});let o=ra(),s=[];E.forEach((a,l)=>{let i=a.path.length,u=new Array(i),f;for(let h=0;h<i;h++){h===0?u[h]=void 0:u[h]=f??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(f=p)}let c=new Array(i),d;for(let h=i-1;h>=0;h--){h===i-1?c[h]=void 0:c[h]=d??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(d=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=u[p],b=c[p],g=!!(b&&m&&b.isForward!==void 0&&m.isForward!==void 0&&(m.order>b.order||b.order===m.order&&b.isForward===m.isForward));h.betweenCycleReverseTraversal=g,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(ea),s.forEach(a=>{let l=E[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Xe&&(console.log("Reads:"),console.log(E))}function Zs(e,n,t){let r=new Set(e),o=n.incomingReads.filter(([p])=>r.has(p)),s=n.outgoingReads.filter(([p])=>r.has(p)),a=n.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(t=0);let l=n.y+n.contentHeight+t*2,i=o.map(p=>{let[m,b]=p,g=E[m].path,x=b+1,R;for(let N=1;N<=b;N++){let L=g[b-N]?.y;if(L!==void 0){x=N,R=L;break}}return{entry:p,decisionStep:x,y:R}});i.sort(Js),o=i.map(p=>p.entry);let u=l,f=new Map;o.forEach(p=>{let m=E[p[0]];m.path[p[1]].y=u,mo(f,m,p[1],u,n),u+=m.width});let c=u;s.sort(na);let d=new Map;u=l,s.forEach(p=>{let m=E[p[0]],b=m.firstNodeOffset??0;m.path[p[1]].y=u,d.set(u,b);let g=f.get(u);g===void 0||g+1<=b?(u+=m.width,c=Math.max(c,u)):(f.set(u,0),o.forEach(x=>{let R=E[x[0]],N=R.path[x[1]];N.y!==void 0&&N.y>=u&&(N.y+=m.width,mo(f,R,x[1],N.y,n))}),u+=m.width,c+=m.width)}),a.sort(oa),a.forEach(p=>{let m=E[p],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(u=l;b<(f.get(u)??-1/0)+2||g>(d.get(u)??1/0)-3;)u+=m.width||dn;m.path[0].y=u,f.set(u,g),c=Math.max(c,u)});let h=c-n.y-n.contentHeight;n.contentHeight+=h,Na(n,h)}function Js(e,n){return e.decisionStep!==n.decisionStep?e.decisionStep-n.decisionStep:e.y===void 0||n.y===void 0?(e.y===void 0?0:1)-(n.y===void 0?0:1):e.y-n.y}function mo(e,n,t,r,o){t===n.path.length-1?e.set(r,n.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function ea(e,n){let t=E[e.readIndex],r=E[n.readIndex],o=t.path[e.pathIndex],s=r.path[n.pathIndex];if(o.order!==s.order)return o.order-s.order;if(t.sourceTrackID!==r.sourceTrackID)return t.sourceTrackID-r.sourceTrackID;if(e.previousNode&&n.previousNode){let i=y[e.previousNode],u=y[n.previousNode];if(i&&u&&i.order!==u.order)return i.order-u.order}let a=e.previousY??0,l=n.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function na([e,n],[t,r]){let o=E[e],s=E[t],a,l,i=o.path.length-1,u=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&u>=0;)l=s.path[u]?.y,u-=1;if(a&&l)return a-l;let f=o.path[n]?.node,c=s.path[r]?.node,d=f!=null?y[f]:null,h=c!=null?y[c]:null;for(;d!=null&&h!=null&&d===h;){if(n<o.path.length-1){for(n+=1;o.path[n]?.node===null;)n+=1;let m=o.path[n]?.node;d=m!=null?y[m]:null}else d=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?y[m]:null}else h=null}if(d!=null)return h!=null?fn(d,h):1;if(h!=null)return-1;let p=(o.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(o.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function ta(e,n){if(e.path===void 0||n.path===void 0)return(e.path===void 0?0:1)-(n.path===void 0?0:1);let t=e.path,r=n.path,o=0,s=0;for(;o<t.length&&s<r.length;){let a=t[o],l=r[s],i=a.order,u=l.order;if(i===u&&a.node&&l.node)return(l.y??0)-(a.y??0);i<u?o+=1:(i>u||(o+=1),s+=1)}return 0}function oa(e,n){let t=E[e],r=E[n],o=t.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=t.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function ra(){let e=[];for(let n=0;n<=Q;n+=1)e.push(0);return y.forEach(n=>{n.y!==void 0&&(e[n.order]=Math.max(e[n.order],n.y+n.contentHeight+20))}),w.forEach(n=>{n.path.forEach(t=>{e[t.order]=Math.max(e[t.order],(t.y??0)+n.width)})}),e}function sa(){E.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=un(e.indexSequence[0]),r=y[n],o,s;e.path=[],e.path.push({order:r.order,isForward:t,node:n});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=t,n=Math.abs(e.indexSequence[a]),t=un(e.indexSequence[a]),r=y[n],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});t?e.path.push({order:r.order,isForward:!0,node:n}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:n}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});t?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:n})):e.path.push({order:r.order,isForward:!1,node:n})}else t!==s?e.path.push({order:r.order,isForward:t,node:n}):(e.path.push({order:r.order,isForward:!t,node:null}),e.path.push({order:r.order,isForward:t,node:n}))})}function qn(){E.forEach(e=>{let n=0;for(;n<e.sequence.length&&e.sequence[n].startsWith("-");)n+=1;if(n===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=P(e.sequence[a]);let t=e.sequenceNew??[];t.reverse(),e.sequenceNew=t;for(let a of t)a.nodeName=P(a.nodeName),aa(a.mismatches,oe(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function aa(e,n){e.forEach(t=>{t.type==="insertion"?t.pos=n-t.pos:t.type==="deletion"?t.pos=n-t.pos-(t.length??0):t.type==="substitution"&&(t.pos=n-t.pos-(t.seq?.length??0)),t.seq!==void 0&&(t.seq=vo(t.seq).split("").reverse().join(""))})}var ia={A:"T",T:"A",C:"G",G:"C"};function vo(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=ia[e.charAt(t)]??"N";return n}function Re(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=I.get(P(r)),s=y[o]?.switched??!1;s&&(r=_o(r));let a=I.get(P(r));if(a===0)throw new Error("Node "+P(r)+" has prohibited index 0");k(r)!==s?n.indexSequence.push(-a):n.indexSequence.push(a)})})}var la=20;function ca(){let e={minX:99,maxX:-99,minY:99,maxY:-99};y.forEach(n=>{n&&(n.x!==void 0&&(e.minX=Math.min(e.minX,n.x),e.maxX=Math.max(e.maxX,n.x+la+n.pixelWidth)),n.y!==void 0&&(e.minY=Math.min(e.minY,n.y-10),e.maxY=Math.max(e.maxY,n.y+n.contentHeight+10)))}),w.forEach(n=>{n.path.forEach(t=>{let r=t.y??0;e.maxY=Math.max(e.maxY,r+n.width),e.minY=Math.min(e.minY,r)})}),Xn=e}function oe(e){let n=I.get(P(e)),t=n===void 0?void 0:y[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function bo(){return I=new Map,y.forEach((e,n)=>{e&&I.set(e.name,n)}),I}function go(){let e=y.map(()=>new Set),n=y.map(()=>new Set),t=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),n[a].add(s)}};w.forEach(t),v.showReads&&E.length>0&&E.forEach(t),y.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(n[o]))})}function yo(e){let n=0,t=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){T[s]===void 0&&(T[s]=t);let a=T[s];a<r&&(r=a),n=a,t=a-1}else{T[s]===void 0&&(T[s]=n);let a=T[s];n=a+1,t=a}}),r<0&&zn(-r)}function ua(e){let n=0,t=0;for(;n<e.length&&T[Math.abs(e[n])]===void 0;)n+=1;if(n>=e.length)return null;let r=e[n],o,s;r>=0?(o=T[r]-1,s=-1):(o=T[-r]+1,s=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(e[a]);T[l]===void 0&&(T[l]=o,t=Math.min(t,o),o+=s)}return t<0&&zn(-t),n}var da=-1;function fa(e){let n=[];for(let t of e)n.push(t??da);return n}function Fn(){let e,n,t,r,o=0,s=v.showReads&&E.length>0?w.concat(E):w,a={stamp:new Int32Array(y.length),generation:0};T=new Array(y.length).fill(void 0),y.forEach(i=>{i&&(i.order=void 0)}),yo(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Xe&&console.log(`generating order for track ${i+1}`),t=ua(s[i].indexSequence),t===null){s[i].type==="haplotype"?yo(s[i].indexSequence):(s.splice(i,1),E.splice(i-w.length,1),i-=1);continue}for(e=ha(s[i].indexSequence);t<e.length;){for(r=t,t+=1;t<e.length&&T[e[t]]===void 0;)t+=1;if(t<e.length){n=T[e[r]]+1;for(let u=r+1;u<t;u+=1)T[e[u]]=n,n+=1;if(T[e[t]]>T[e[r]])T[e[t]]<n&&Mo(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!pa(e[t],e[r],a))Mo(e[t],e[t-1],n);else if(s[i].indexSequence[r]<0||y[e[r+1]].degree<2&&T[e[t]]<T[e[r]]){n=T[e[r]]-1;for(let u=r+1;u<t;u+=1)T[e[u]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=T[e[r]]+1;for(let u=r+1;u<e.length;u+=1){let f=e[u];T[f]===void 0&&(T[f]=n,n+=1)}}else{n=T[e[r]]-1;for(let u=r+1;u<e.length;u+=1){let f=e[u];T[f]===void 0&&(T[f]=n,o=Math.min(o,n),n-=1)}}}}o<0&&zn(-o);let l=fa(T);T=l,l.forEach((i,u)=>{let f=y[u];f!==void 0&&(f.order=i)})}function pa(e,n,t){t.generation+=1;let{stamp:r,generation:o}=t,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===n)return!0;for(let l of y[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function xo(){let e=-1;return T.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function ha(e){return e.map(n=>Math.abs(n))}function zn(e){T.forEach((n,t)=>{n!==void 0&&(T[t]=n+e)})}function Mo(e,n,t){let r=new Map,o=[[e,t]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=T[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),y[a].successors.forEach(u=>{T[u]>i&&u!==n&&o.push([u,l+1])}),a!==e&&y[a].predecessors.forEach(u=>{T[u]>i&&u!==n&&o.push([u,l+1])}))}r.forEach((a,l)=>{T[l]=a})}function ma(){y.forEach(e=>{e.tracks=[]}),w.forEach(e=>{e.indexSequence.forEach(n=>{y[Math.abs(n)].tracks.push(e.id)})}),y.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function ba(){let e=w[0],n=w.slice(1,w.length);if(v.showReads&&E.length>0&&(n=n.concat(E)),ga(n,e),v.showReads&&E.length>0){for(let t=0;t<E.length;t++)if(E[t]!==n[t+w.length-1])throw new Error("Read inequality")}}function ga(e,n){let t=new Map,r=n?new Set(n.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=P(s[a]),i=oe(l);if(r&&!r.has(l)){let u=a>0?oe(s[a-1]).order:void 0,f=a<s.length-1?oe(s[a+1]).order:void 0;(u===void 0||u<i.order)&&(f===void 0||i.order<f)&&wo(t,l,k(s[a])?1:-1),(u===void 0||u>i.order)&&(f===void 0||i.order>f)&&wo(t,l,k(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=t.get(P(s));l!==void 0&&l>0&&(o.sequence[a]=_o(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=vo(a.seq),a.switched=!0}})}function wo(e,n,t){e.set(n,(e.get(n)??0)+t)}function ya(){let e=0,n=20,t=-1,r=y.slice();r.sort(fn);let o=xa();r.forEach(s=>{s.order>=0&&(s.order>t&&(t=s.order,e=n+10*o[s.order]),s.x=e,n=Math.max(n,e+40+s.pixelWidth))})}function xa(){let e=[],n=[],t=[],r=[];for(let o=0;o<=Q;o+=1)e.push(0),n.push(0),t.push(0);w.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:n[a.order]=n[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));t[a.order]=Math.max(i/17.5,t[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=Q;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function Ma(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=Q;i+=1){ye[i]=[],l[i]=new Map,a[i]=[];for(let u=0;u<w.length;u+=1)a[i][u]=null}w.forEach((i,u)=>{n=Math.abs(i.indexSequence[0]),t=un(i.indexSequence[0]),r=y[n],i.path=[],i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,0,a,l),e=1;for(let f=1;f<i.sequence.length;f+=1)if(o=r,s=t,n=Math.abs(i.indexSequence[f]),t=un(i.indexSequence[f]),r=y[n],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),W(o.order,null,u,e,a,l),e+=1);for(let c=o.order+1;c<r.order;c+=1)i.path.push({order:c,lane:null,isForward:!0,node:null}),W(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!0,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:n}),W(r.order,n,u,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),W(o.order,null,u,e,a,l),e+=1);for(let c=o.order-1;c>r.order;c-=1)i.path.push({order:c,lane:null,isForward:!1,node:null}),W(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:n}),W(r.order,n,u,e,a,l),e+=1)}else t!==s?(i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!t,node:null}),W(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:t,node:n}),W(r.order,n,u,e,a,l),e+=1)});for(let i=0;i<=Q;i+=1)Sa(ye[i],i)}function W(e,n,t,r,o,s){let a={trackID:t,segmentID:r,compareToFromSame:o[e][t]??null},l=n===null?void 0:s[e].get(n);if(l===void 0){let i={type:"single",node:n,tracks:[a]};ye[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function wa(e,n){let t;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(w[o.trackID].path[o.segmentID-1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<w[o.trackID].path.length-1&&w[o.trackID].path[o.segmentID+1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID+1].y;else{for(t=o.segmentID-1;t>=0&&w[o.trackID].path[t].order!==n-1;)t-=1;t<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=w[o.trackID].path[t].lane??void 0,o.idealY=w[o.trackID].path[t].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Sa(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;wa(e,n),e.sort(Lo),e.forEach(l=>{l.node!==null?(y[l.node].topLane=t,s&&(o-=10),y[l.node].y=o,y[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(Lo),l.tracks.forEach(i=>{i.lane=t,i.trackID===a&&l.node===null&&s&&(o+=10),w[i.trackID].path[i.segmentID].lane=t,w[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),t+=1,o+=w[i.trackID].width,l.node!==null&&(y[l.node].contentHeight+=w[i.trackID].width),a=i.trackID}),o+=25}),La(e,r)}function La(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{So(e,o)<r&&(r=So(e,o),t=o)}),e.forEach(o=>{o.node!==null&&(y[o.node].y+=t),o.tracks.forEach(s=>{let a=w[s.trackID].path[s.segmentID];a.y=a.y+t})})}function Na(e,n){e.order<0||ye[e.order]===void 0||(ye[e.order].forEach(t=>{if(t.node!==null){let r=y[t.node];r!==e&&r.y>e.y&&(r.y+=n,t.tracks.forEach(o=>{let s=w[o.trackID].path[o.segmentID];s.y=s.y+n}))}else t.tracks.forEach(r=>{let o=w[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+n)})}),Ae[e.order].length>0&&Ae[e.order].forEach(t=>{y[t]!==e&&y[t].y>e.y&&(y[t].y+=n)}))}function So(e,n){let t=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&w[o.trackID].type!=="read"&&(t+=Math.abs(o.idealY-n-w[o.trackID].path[o.segmentID].y)*w[o.trackID].width)})}),t}function Lo(e,n){return e.idealLane!==void 0?n.idealLane!==void 0?e.idealLane<n.idealLane?-1:e.idealLane>n.idealLane?1:0:-1:n.idealLane!==void 0?1:0}function fn(e,n){if(!e)return n?-1:0;if(!n)return 1;if(e.order!==void 0){if(n.order!==void 0){if(e.order<n.order)return-1;if(e.order>n.order)return 1;if(e.y!==void 0&&n.y!==void 0){if(e.y<n.y)return-1;if(e.y>n.y)return 1}return 0}return-1}return n.order!==void 0?1:0}function Ra(){let e,n,t={};Wn.forEach(r=>{let o=0;for(;o<w.length&&w[o].name!==r.track;)o+=1;o<w.length&&(e=0,w[o].path.forEach(s=>{s.node!==null&&(t={},n=e+y[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(t.start=0),e<r.start&&n>=r.start&&(t.start=r.start-e),n<=r.end&&n>=r.start&&(t.end=n-e,n<r.end&&(t.continue=!0)),n>r.end&&e<=r.end&&(t.end=r.end-e),t.start!==void 0&&(t.type=r.type,t.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(t)),e=n+1)}))})}function Ea(){let e=!0,n=4,t=v.trackWidth;w.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*n):(r.width=t,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(e=!1)}),e&&w.forEach(r=>{r.freq!==void 0&&(r.width=t)})}function Aa(e){let n=e.path[0],t=y[n.node],r=e.firstNodeOffset??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Ta(e){let n=e.path[e.path.length-1],t=y[n.node],r=e.finalNodeCoverLength??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Bo(e,n){return n>e.sequenceLength?null:jn(e,n)}function jn(e,n){let[t,r]=_a(e);if(e.sequenceLength===0)return t;let o=Math.min(Math.max(n,0),e.sequenceLength);return t+o/e.sequenceLength*(r-t)}function Ca(){let e,n,t,r,o,s,a,l,i;for(let c=0;c<=Q;c+=1)kn.push(0),Yn.push(0);let u=[],f=[];y.forEach(c=>{c.x!==void 0&&(u[c.order]=c.x,f[c.order]===void 0?f[c.order]=c.x+c.pixelWidth:f[c.order]=Math.max(f[c.order],c.x+c.pixelWidth))}),w.sort(ta),w.forEach(c=>{a="plain",o=Ee(c,a),s=js(c);let d=a,h=()=>(d!==a&&(d=a,o=Ee(c,a)),o);t=c.path[0].y,c.type!=="read"?c.sequence[0].startsWith("-")?e=f[c.path[0].order]+20:e=u[c.path[0].order]-20:e=Aa(c);for(let p=0;p<c.path.length;p+=1)c.path[p].y===t?c.path[p].features!==void 0&&(i=p>0&&c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart):(c.path[p-1].isForward?n=f[c.path[p-1].order]:n=u[c.path[p-1].order],n!==e&&(o=h(),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})),c.path[p].order-1===c.path[p-1].order?(e=n,n=u[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e,yStart:t,xEnd:n+1,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p].order+1===c.path[p-1].order?(e=n,n=f[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e+1,yStart:t,xEnd:n,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p-1].isForward?(r=c.path[p].y,Ao(1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=f[c.path[p].order],t=c.path[p].y):(r=c.path[p].y,Ao(-1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=u[c.path[p].order],t=c.path[p].y),c.path[p].features!==void 0&&(i=c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart));c.type!=="read"?c.path[c.path.length-1].isForward?n=f[c.path[c.path.length-1].order]+20:n=u[c.path[c.path.length-1].order]-20:n=Ta(c),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})})}var Ia=1e9;function No(e,n){cn=new Map;let t=new Map,r=v.ignoreStrand;for(let d of e){let h=d.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],b=h[p+1],g=Math.abs(m),x=Math.abs(b),R=y[g],N=y[x];if(!R||!N)continue;let L;if(r){let A=`${m}>${b}`,M=`${-b}>${-m}`;L=A<M?A:M}else L=`${m}>${b}`;let S=t.get(L);S===void 0?t.set(L,{sSigned:m,dSigned:b,sName:m<0?`-${R.name}`:R.name,dName:b<0?`-${N.name}`:N.name,count:1,sourceTrackID:d.sourceTrackID}):S.count+=1}}let o=0;for(let d of t.values())d.count>o&&(o=d.count);let s=dn,a=60,l=d=>o<=1?s:s+(a-s)*Math.sqrt(d/o),i=[],u=0;for(let d of t.values()){let h=Ia+u,p=`${d.count.toLocaleString()} ${n}${d.count===1?"":"s"}: Node ${d.sName} \u2192 Node ${d.dName}`;cn.set(h,{count:d.count,label:p});let m=y[Math.abs(d.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:d.sourceTrackID,type:"read",name:p,sequence:[d.sName,d.dName],indexSequence:[],path:[],width:l(d.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:d.sName,mismatches:[]},{nodeName:d.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:d.count}),u+=1}let f="?",c=0;for(let d of y){if(!d)continue;let h=d.contentHeight;h>c&&(c=h,f=d.name)}return Xe&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${c.toFixed(1)})`),i}function Ro(e,n,t,r,o,s,a,l,i){let u=r,f,c,d,h;n-=8,t+=8;let p=y[e.node].sequenceLength;return e.features.sort((m,b)=>m.start-b.start),e.features.forEach(m=>{u!==m.type&&(f=Ee(o,u),e.isForward?(d=n+Math.round(m.start*(t-n+1)/p),i&&d<n+8&&(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:d,yStart:a,xEnd:h,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),d>s+1&&D.featureRectangles.push({xStart:s,yStart:a,xEnd:d-1,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(d=t-Math.round(m.start*(t-n+1)/p),i&&d>t-8&&(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:h,yStart:a,xEnd:d,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),s>d+1&&D.featureRectangles.push({xStart:d+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=d,u=m.type),(m.end<p-1||m.continue===void 0)&&(f=Ee(o,u),e.isForward?(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=h+1,u="plain")}),{xStart:s,highlight:u}}var Eo=7;function Ao(e,n,t,r,o,s,a,l,i,u){let f=e===1?Yn:kn,c=10*f[l],d=n+e*(c+5),h=Eo,p=Math.min(Eo,o),m=Math.min(t,r),b=Math.max(t,r),g=e===1?n:d-1,x=e===1?d:n,R=A=>{D.verticalRectangles.push({xStart:g,yStart:A,xEnd:x,yEnd:A+o-1,color:s,id:a,name:u,type:i})};R(t),D.verticalRectangles.push({xStart:e===1?d+h:d-h-p,yStart:m+o+h-1,xEnd:e===1?d+h+p-1:d-h-1,yEnd:b-h+1,color:s,id:a,name:u,type:i}),R(r);let N=d+e*h,L=d+e*(h+p),S=`M ${d} ${b}`;S+=` Q ${N} ${b} ${N} ${b-h}`,S+=` H ${L}`,S+=` Q ${L} ${b+o} ${d} ${b+o}`,S+=" Z ",D.corners.push({path:S,color:s,id:a,type:i}),S=`M ${d} ${m}`,S+=` Q ${L} ${m} ${L} ${m+o+h}`,S+=` H ${N}`,S+=` Q ${N} ${m+o} ${d} ${m+o}`,S+=" Z ",D.corners.push({path:S,color:s,id:a,type:i}),f[l]+=1}function _a(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function To(){switch(y.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),v.nodeWidthOption){case"compressed":y.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":y.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":y.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=v.charWidth;y.forEach(n=>{n.width=n.sequenceLength;let t=n.seq?.length??1;n.pixelWidth=Math.round(e*t)});break}default:throw new Error(`${v.nodeWidthOption} not implemented`)}}function va(){let e,n,t=Array.from(y,()=>new Set),r=Array.from(y,()=>new Set),o;v.showReads&&E.length>0?o=w.concat(E):o=w,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)k(l.sequence[i])?(e=P(l.sequence[i]),i>0?(n=l.sequence[i-1],k(n)?r[I.get(e)].add(P(n)):(r[I.get(e)].add(n),r[I.get(e)].add(pe(n)))):l.type==="haplotype"&&r[I.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],k(n)?t[I.get(e)].add(P(n)):(t[I.get(e)].add(n),t[I.get(e)].add(pe(n)))):l.type==="haplotype"&&t[I.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[I.get(l.sequence[i])].add(e),k(e)&&t[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&t[I.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[I.get(l.sequence[i])].add(e),k(e)&&r[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&r[I.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(v.showReads&&E.length>0){let l=y.slice();l.sort(fn);let i=new Map,u=new Map,f=d=>{let h=i.get(d);if(h===void 0)throw new Error(`No merge offset recorded for node ${d}`);return h},c=d=>{let h=u.get(d);if(h===void 0)throw new Error(`No merge origin recorded for node ${d}`);return h};l.forEach(d=>{let h=We(I.get(d.name),s,a);if(h){let p=f(h)+oe(h).sequenceLength;i.set(d.name,p),i.set(pe(d.name),p),u.set(d.name,c(h)),u.set(pe(d.name),c(h))}else i.set(d.name,0),i.set(pe(d.name),0),u.set(d.name,d.name),u.set(pe(d.name),d.name)}),E.forEach(d=>{let h=d.sequenceNew??[];d.firstNodeOffset=(d.firstNodeOffset??0)+f(d.sequence[0]),d.finalNodeCoverLength=(d.finalNodeCoverLength??0)+f(d.sequence[d.sequence.length-1]);for(let p=d.sequence.length-1;p>=0;p-=1){let m=P(d.sequence[p]),b=We(I.get(m),s,a);if(b&&Hn(I.get(b),s,a))if(p>0){d.sequence.splice(p,1);let g=oe(b).sequenceLength;h[p].mismatches.forEach(x=>{x.pos+=g}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{d.sequence[0]=c(d.sequence[0]);let g=h[0],x=f(g.nodeName);g.mismatches.forEach(R=>{R.pos+=x}),g.nodeName=c(g.nodeName)}}})}for(let l=0;l<y.length;l+=1)if(Hn(l,s,a)&&!We(l,s,a)){let i=l;for(;Hn(i,s,a);)i=I.get(P(a[i][0])),y[l].sequenceLength+=y[i].sequenceLength,y[l].seq+=y[i].seq}w.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=P(l.sequence[i]);let u=I.get(e);We(u,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)We(l,s,a)&&y.splice(l,1)}function We(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=P(n[e][0]),o=I.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function Hn(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=P(t[e][0]),o=I.get(r);return!(n[o].length!==1||n[o][0]==="None")}function Ba(e){let n=v.focusReadNames?new Set(v.focusReadNames):null;return e.filter(t=>t.is_secondary!==!0&&(t.mapping_quality??0)>=v.mappingQualityCutoff&&(n===null||t.name!==void 0&&n.has(t.name)))}function Oa(e,n){let t=new Map;for(let r of e){let o=n(r),s=t.get(o);s===void 0?t.set(o,[r]):s.push(r)}return t}function Pa(e,n){return e.xStart<n.xStart?1:e.xStart>n.xStart?-1:e.yStart>n.yStart?1:e.yStart<n.yStart?-1:0}function Oo(e,n){let t=Oa(e.filter(s=>s.type===n),s=>`${s.nodeStart},${s.nodeEnd}`);t.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Pa),s.forEach(i=>{let u,f;i.yStart<i.yEnd?(u=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,f=i.xStart+(i.xEnd-i.xStart)*(1-a)):(u=i.xStart+(i.xEnd-i.xStart)*a,a+=l,f=i.xStart+(i.xEnd-i.xStart)*a);let c=`M ${i.xStart} ${i.yStart}`;c+=` C ${u} ${i.yStart} ${u} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,c+=` V ${i.yEnd+i.width}`,c+=` C ${f} ${i.yEnd+i.width} ${f} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,c+=" Z",i.path=c})});let r=Array.from(t.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),u=l[0]??0,f=l[1]??0,c=i[0]??0,d=i[1]??0;return u<c?-1:u>c?1:f<d?-1:f>d?1:0});let o=[];for(let s of r){let a=t.get(s);a!==void 0&&o.push(...a)}return o}function Po(e){let n=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,t=e.x,r=e.y-9;return e.width>1&&(t+=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t+9} ${r} ${t+9} ${r+9}`,t+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,n+=` L ${t} ${r}`),n+=` Q ${t} ${r+9} ${t-9} ${r+9}`,t-=9,r+=9,e.width>1&&(t-=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t-9} ${r} ${t-9} ${r-9}`,t-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,n+=` L ${t} ${r}`),n}function Ga(e){let n=new Map;for(let[t,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${t}`,a=n.get(s);a?a.push(o.strand):n.set(s,[o.strand])}return n}function Da(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=Ga(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>Le(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=Le(s.name).name,i=new Map,u=s.nodeIds.flatMap(f=>{let c=n.get(f);if(!c)return[];let d=i.get(c.name)??0;i.set(c.name,d+1);let h=t.get(`${l} ${c.name}`)?.[d]??On(c);return[Pn(c,h)]});return u.length>0?[{id:a,name:s.name,sequence:u,sourceTrackID:0,type:"haplotype"}]:[]})}function $a(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function Te(e){return(e.paths?.length??0)>0}var qa=600,Fa=3,Ha=15;function Wa(e){return Math.max(Fa,Math.min(Ha,Math.floor(qa/Math.max(1,e))))}function Go(e){let n=e.paths??[],t=Da(e),r=e.reads?no(e,e.reads,n.length):[],o=r.length>0?mt:ht,s=n.map((l,i)=>o(i,n.length)),a=Io($a(e),t,r,{nodeWidthOption:"compressed",trackWidth:Wa(t.length),trackColor:l=>l.type==="read"?to(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function Vn(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function Do(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function $o(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function qo(e){let n=Te(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of Vn(t))s[i.name]=Do(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=$o(t,o);return{nodePositions:s,tubeMap:{layout:t,yOffset:o,pathColors:r},extent:{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:a,maxY:l}}}function Xa(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of Vn(n)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,u)=>i-u)){let i=r.get(l),u=1/0,f=-1/0;for(let c of i){let d=t.get(c.name);d&&_(d)&&(u=Math.min(u,d.stable.start),f=Math.max(f,d.stable.start+c.sequenceLength))}u===1/0&&(u=f=s),u<s&&(u=s,f=Math.max(s,f)),s=Math.max(s,f),o.push({order:l,x0:Math.min(...i.map(c=>c.x)),x1:Math.max(...i.map(c=>c.x+c.pixelWidth)),bp0:u,bp1:f})}let a=o.find(l=>l.bp0!==-1/0);for(let l of o)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return o}function ka(e){return e.nodes.some(_)&&Te(e)}function Fo(e){let n=ka(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=Xa(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of Vn(t)){let u=s.get(i.order);l[i.name]=Do(i,a,u.bp0,u.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:$o(t,a)}}function Ho(e){let n=ce(e);if(n.length!==0)return{nodePositions:ue(n),referenceAxis:!0,pixelRows:!0}}function Wo(e){return e.sample??Qe(e.name)}function Ya(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Wo(e)}function za(e,n,t,r=!0){if(!t||!r)return{ids:e,complete:!0};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((u,f)=>{let c=n.get(u);c&&(c.end<=t.start&&c.end>a&&(a=c.end,o=f),c.start>=t.end&&c.start<l&&(l=c.start,s=f))}),o<0||s<0)return{ids:e,complete:!1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0}}function Xo(e,n,t){let r=e.paths??[],o=r.find(h=>Le(h.name).name===e.referencePath)??r[0];if(!o||r.length<2)return;let s=new Map(e.nodes.map(h=>[h.id,h.length])),a=e.anchorPaths?.find(h=>h.name===Le(o.name).name)?.start??0,l=n&&n.end>n.start?n:void 0,i=new Map,u=a;for(let h of o.nodeIds){let p=s.get(h)??0;i.has(h)||i.set(h,{start:u,end:u+p}),u+=p}let f=l===void 0||[...i.values()].some(h=>h.end<=l.start)&&[...i.values()].some(h=>h.start>=l.end),c=h=>{let{ids:p,complete:m}=za(h.nodeIds,i,l,f),b=[],g=0,x=0,R=0;for(let N of p){let L=s.get(N)??0,S=i.get(N),A=b.at(-1),M=A?.referenceStart,C=S&&M!==void 0&&R>=0&&M+A.bp===S.start,B=S&&M!==void 0&&R<=0&&S.end===M;!S&&A&&!A.onReference?A.bp+=L:C||B?(A.bp+=L,C||(A.referenceStart=S.start,A.reversed=!0),R=C?1:-1):(b.push({start:g,bp:L,onReference:S!==void 0,referenceStart:S?.start}),R=0),g+=L,S||(x+=L)}return{name:h.name,label:Ya(h),sample:Wo(h),haplotype:h.haplotype,bp:g,offReferenceBp:x,complete:m,runs:b}};return{origin:l?l.start:a,unit:t,reference:c(o),rows:r.filter(h=>h!==o).map(c).sort((h,p)=>Number(p.complete)-Number(h.complete)||p.bp-h.bp||h.label.localeCompare(p.label))}}var ja=1.3;function Va(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*ja,maxY:e.rows.length*20}}function ko(e,n){let t=ce(e),r=Xo(e,n);if(t.length===0||!r)return;let o=ue(t),s=[{label:r.reference.label,y:0},...r.rows.map((a,l)=>({label:a.label,y:(l+1)*20}))];return{nodePositions:o,rowLabels:s,referenceAxis:!0,pixelRows:!0,extent:Va(r)}}var Ua="Force-directed layout",re=e=>e.nodes.some(_),Yo=e=>re(e)&&(e.paths?.length??0)>1,zo=e=>re(e)&&Te(e),jo=e=>re(e)&&e.nodes.some(Ze),Un=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:ao,cutMargins:!0,available:re,drawsLocally:re},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:fo,cutMargins:!0,available:jo,drawsLocally:jo},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, sequence the reference also carries in blue and sequence it does not in purple, so a repeat expansion reads as bar length. Needs W or P lines.",run:ko,cutMargins:!1,available:Yo,drawsLocally:Yo},{value:"ordered",label:"Ordered",description:"x is reference order, not bp: every node gets room, bubbles read as lenses. Needs rGFA tags or a reference path.",run:uo,cutMargins:!1,available:re,drawsLocally:re},{value:"variants",label:"Variant map",description:"The reference as a line with one typed glyph per bubble, from the bubble index or from the graph itself: SNP, indel, deletion, inversion, repeat array. Click a glyph to open the graph inside it.",run:Ho,cutMargins:!0,available:re,drawsLocally:re},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:qo,cutMargins:!1,available:Te,drawsLocally:Te},{value:"tubemapref",label:"Tube map on reference",description:"The tube map with each column at the reference bp it covers, so the tubes line up with the tracks around them. Needs P or W lines and a reference path.",run:Fo,cutMargins:!0,available:zo,drawsLocally:zo},{value:"force",label:Ua,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,available:()=>!0,drawsLocally:()=>!1}],tu=Un.map(e=>e.value);function ou(e,n){return!Ka(e).drawsLocally(n)}function Ka(e){return Un.find(n=>n.value===e)??Un[0]}var Y=le(pn(),1);var q=le(pn(),1);function xe(e,n){return(0,q.packAbgr)((0,q.abgrRed)(e),(0,q.abgrGreen)(e),(0,q.abgrBlue)(e),Math.round((0,q.abgrAlpha)(e)*n))}function au(e,n){return(0,q.packAbgr)(Math.min(255,Math.round((0,q.abgrRed)(e)*n)),Math.min(255,Math.round((0,q.abgrGreen)(e)*n)),Math.min(255,Math.round((0,q.abgrBlue)(e)*n)),(0,q.abgrAlpha)(e))}var Uo=new WeakMap;function Ko(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=Uo.get(e);if(l?.graph===n&&l.scaleX===s&&l.scaleY===a&&l.deletions===r&&l.version===o)return l.curves;let i=new Map;for(let u=0;u<n.edges.length;u++){let f=n.edges[u],c=e[f.from],d=e[f.to];if(c?.length&&d?.length){let h=r?.get(u);i.set(u,De(c,d,It(f),0,0,t,h?Rn(e,h):[]))}}return Uo.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var Qa=(0,Y.packAbgr)(119,119,119,217),Qo=(0,Y.packAbgr)(136,136,136,217),Za=(0,Y.packAbgr)(24,24,28,240),Ja=2.2,ei=(0,Y.packAbgr)(30,30,36,245),ni=1.8,Ce=.18,ti=11,oi=1.2,ri=1e-6,si=7,ai=3,ii=3,li=1.5,ci=.5,ui=.45,Kn=12,di=1e-6,he=new Float64Array(64),Me=new Float64Array(64),we=new Float64Array(64);function fi(e,n,t,r){let o=e.length*Kn+1;he.length<o&&(he=new Float64Array(o),Me=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];he[0]=s.x1,Me[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let u=e[i];for(let f=1;f<=Kn&&l<r;f++){let c=1-(f/Kn)**2,d=1-c,h=d*d*d,p=3*d*d*c,m=3*d*c*c,b=c*c*c,g=h*u.x0+p*u.cx0+m*u.cx1+b*u.x1,x=h*u.y0+p*u.cy0+m*u.cy1+b*u.y1;l+=Math.hypot(g-he[a-1],(x-Me[a-1])*t)*n,he[a]=g,Me[a]=x,we[a]=l,a++}}return a}function Zo(e,n){let t=1;for(;t<e-1&&we[t]<n;)t++;let r=we[t-1],o=we[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:he[t-1]+(he[t]-he[t-1])*s,y:Me[t-1]+(Me[t]-Me[t-1])*s}}function pi({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=si+ai*n,u=fi(e,r,o,t+i),f=we[u-1],c=Math.min(t,f),d=f<di?hi(a,r,o):f-c,h=Math.min(1,d/i);if(h<ci)return;let p=Zo(u,c),m=Zo(u,c+i*h),b=p.x-m.x,g=(p.y-m.y)*o,x=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(b,g)>0?Math.atan2(g,b):Ei(x,o,mi(x,l)),length:i*h,halfWidth:(ii+li*n)*h,color:s}}function hi(e,n,t){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*t);return r*n}function mi(e,n){if(n.length<2)return;let t=n[0],r=n[n.length-1];return Math.hypot(e.x1-t.x,e.y1-t.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:t,to:n[1]}:{from:r,to:n[n.length-2]}}function bi(e,n=1){let t=n===1?e:e.map(o=>({x:o.x,y:o.y*n})),r=[];for(let o=0;o<t.length;o++){let s=0,a=0;if(o===0){let l=t[1].x-t[0].x,i=t[1].y-t[0].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else if(o===t.length-1){let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else{let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i),f=t[o+1].x-t[o].x,c=t[o+1].y-t[o].y,d=Math.hypot(f,c);if(u>0&&d>0){let h=-i/u,p=l/u,m=-c/d,b=f/d;s=(h+m)/2,a=(p+b)/2;let g=h*s+p*a;g>.1&&(s/=g,a/=g)}else u>0?(s=-i/u,a=l/u):d>0&&(s=-c/d,a=f/d)}r.push({nx:s,ny:a})}return r}function gi(e,n,t,r=1){return e.map((o,s)=>({x:o.x+n[s].nx*t,y:o.y+n[s].ny*t/r}))}function hn(e,n,t,r){return(0,Y.packAbgr)(Math.round(e*255),Math.round(n*255),Math.round(t*255),Math.round(r*255))}function mn(e,n,t){let r=(1-Math.abs(2*t-1))*n,o=r*(1-Math.abs(e/60%2-1)),s=t-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var yi=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],xi=[[237,137,44],[158,42,122]],Mi=[[220,50,50],[50,120,220]];function Qn(e,n){let t=Math.max(0,Math.min(1,n))*(e.length-1),r=Math.min(e.length-2,Math.floor(t)),o=t-r,s=e[r],a=e[r+1];return(0,Y.packAbgr)(Math.round(s[0]+(a[0]-s[0])*o),Math.round(s[1]+(a[1]-s[1])*o),Math.round(s[2]+(a[2]-s[2])*o),255)}function wi(e,n){let[t,r,o]=mn(ft(e),yn,xn);return hn(t,r,o,n)}var Si=300,Li=.7,Ni=.5,nr=[60,65,72],Ri=(0,Y.packAbgr)(...nr,255),gu=`rgb(${nr.join(", ")})`;function yu(e,n){let t=oo(e);if(n&&n.end>n.start)return{start:n.start,span:n.end-n.start,midpoints:t};let r=1/0,o=-1/0;for(let s of t.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:t}}function Zn(e){let n=1/0,t=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<n&&(n=a.depth),a.depth>t&&(t=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:n,maxDepth:t,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Jn(e,n,t,r){switch(t){case"random":return wi(e.id,1);case"depth":return Qn(yi,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Qn(Mi,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,Y.packAbgr)(160,160,160,255):e.stable.rank===0?(0,Y.packAbgr)(52,152,219,255):Qn(xi,r.maxRank>1?(e.stable.rank-1)/(r.maxRank-1):0);case"reference-position":{let o=r.referenceRamp,s=o?.midpoints.get(e.id);if(o===void 0||s===void 0)return(0,Y.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Ri;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,u]=mn(a*Si,Li,Ni);return hn(l,i,u,1)}case"grey":return(0,Y.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?n/r.nodeCount*360:0,[s,a,l]=mn(o,.75,.5);return hn(s,a,l,1)}default:return(0,Y.packAbgr)(52,152,219,255)}}function Ei(e,n=1,t){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*n;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return t?Math.atan2((t.to.y-t.from.y)*n,t.to.x-t.from.x):0}function Ai(e,n){let t=!1;for(let r=0;r<e.length-1&&!t;r++){let o=e[r],s=e[r+1];t=Math.max(o.x,s.x)>=n.minX&&Math.min(o.x,s.x)<=n.maxX&&Math.max(o.y,s.y)>=n.minY&&Math.min(o.y,s.y)<=n.maxY}return t}function Ti(e,n){for(let t of e){let r=Math.min(t.x0,t.cx0,t.cx1,t.x1),o=Math.max(t.x0,t.cx0,t.cx1,t.x1),s=Math.min(t.y0,t.cy0,t.cy1,t.y1),a=Math.max(t.y0,t.cy0,t.cy1,t.y1);if(o>=n.minX&&r<=n.maxX&&a>=n.minY&&s<=n.maxY)return!0}return!1}var Jo=new WeakMap;function Ci(e){let n=Jo.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=mn(pt(s,o.length),yn,xn);t.push(hn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},Jo.set(e,n)}return n}var er=new WeakMap,Ii=new Map;function _i(e){let n=er.get(e);if(!n){n=new Map;for(let[t,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=n.get(o);s?s.push(t):n.set(o,[t])}er.set(e,n)}return n}function xu(e){let{nodePositions:n,graph:t,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:u,axis:f,linearLayout:c,viewportBounds:d,referenceRamp:h,deletions:p,hiddenEdges:m,version:b=0}=e,g=i==="depth"?bt(t):0,x=f.scaleX,R=en(f),N=Ko(n,t,f,p,b),L=[],S=new Map,A=[],M=new Map,C=[],B=new Map,G={...Zn(t),referenceRamp:h},X=new Map;if(o==="rainbow")for(let O=0;O<t.nodes.length;O++)X.set(t.nodes[O].id,O);let F=t.paths?.length??0,{pathColorByIndex:H,pathIndexByName:U}=Ci(t),j=O=>H[U.get(O)??-1]??Qo,V=l&&F>1?_i(t):Ii,ke=x>(c?1:ui);for(let O=0;O<t.edges.length;O++){let $=t.edges[O],K=n[$.from],Z=n[$.to],J=N.get(O);if(!K?.length||!Z?.length||!J||m?.has(O))continue;let se=$.pathIds?.length??0,ae=p?.get(O)!==void 0,ie=u?.edgeIndexes.has(O)??!1,ee=a/2*(ae?Ja:1)*(ie?ni:1),me=l&&se>0,ve=ae?Za:Qa,Se=u?ie?ei:xe(ve,Ce):ve,Ye=r.get($.to),gn=(Ye?Mn(Ye,s,i,g):s)/2,Be=(je,Ve,ne,Pe)=>{let be=je===0&&Ve===0?J:Tt(J,je,Ve);if(d&&!Ti(be,d))return;if(ae)for(let Nr of At(be,ti/x))C.push({curves:Nr,thickness:ee,color:ne});else C.push({curves:be,thickness:ee,color:ne});let at=ke&&Pe!==void 0?pi({curves:be,edgeHalfWidth:ee,nodeHalfWidth:gn,scale:x,yToX:R,color:Pe,fromSegments:K,toSegments:Z}):void 0;at&&A.push(at)},ze=C.length,Oe=A.length;if(!me)Be(0,0,Se,Se);else{let je=Ct(K,Z,se,f),Ve=Math.floor((se-1)/2);for(let ne=0;ne<se;ne++){let Pe=je[ne],be=j($.pathIds[ne]);Be(Pe.x,Pe.y,u&&$.pathIds[ne]!==u.name?xe(be,Ce):be,ne===Ve?Se:void 0)}}let rt=C.length-ze;rt>0&&B.set(O,{start:ze,count:rt});let st=A.length-Oe;st>0&&M.set(O,{start:Oe,count:st})}for(let[O,$]of Object.entries(n)){let K=r.get(O);if(!K||d&&!Ai($,d))continue;let Z=Jn(K,X.get(O)??0,o,G),J=u!==void 0&&!u.nodeIds.has(O),se=J?xe(Z,Ce):Z,_e=Mn(K,s,i,g),ae=_e/2,ie=L.length,ee=V.get(O),me=_e/F,ve=$.length>=2;if(ve&&ee?.length&&me>=oi){let Ye=bi($,R),gn=1/Math.max(x,ri);for(let Be of ee){let ze=(Be-(F-1)/2)*me*gn,Oe=H[Be]??Qo;L.push({points:gi($,Ye,ze,R),thickness:me/2,color:J?xe(Oe,Ce):Oe})}}else ve&&L.push({points:$,thickness:ae,color:se});let Se=L.length-ie;Se>0&&S.set(O,{start:ie,count:Se})}return{nodeStrokes:L,nodeStrokeRuns:S,arrows:A,arrowRuns:M,edgeCurves:C,edgeCurveRuns:B}}var rr=le(pn(),1);var Ie=10,vi=Ie+8,et=5;function Nu(e,{colorScheme:n,referenceRamp:t,walkNodes:r}){let o={...Zn(e),referenceRamp:t},s=[];return e.nodes.forEach((a,l)=>{if(_(a)){let i=Jn(a,l,n,o);s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,color:(0,rr.abgrToCssRgba)(r&&!r.has(a.id)?xe(i,Ce):i)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function nt(e,n,t){let r=n*e.scale+e.translateX,o=t*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var tr=2;function Bi(e,n,t){let r=-n.translateX/n.scale,o=(t-n.translateX)/n.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let u of e)l+=Math.max(0,Math.min(u.bp1,s)-u.bp0),i+=Math.max(0,u.bp1-Math.max(u.bp0,a));return n.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function Ru(e,n,t,r){if(r<0||r>Ie+tr)return;let o,s=tr;for(let a of e){let[l,i]=nt(n,a.bp0,a.bp1),u=Math.max(0,l-t,t-i);u<=s&&(s=u,o=a.node)}return o}function Eu(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function or(e,n,t){let r=Ie/2,o=n+t*(et+1);e.moveTo(n+t,r),e.lineTo(o,r-et/1.4),e.lineTo(o,r+et/1.4),e.closePath()}function Au(e,n,t,{width:r,lit:o,darkMode:s}){let a=s?"#ffffff":"#18181c";e.fillStyle=s?"#1f1f1f":"#ffffff",e.fillRect(0,0,r,vi);for(let i of n){let[u,f]=nt(t,i.bp0,i.bp1);f>=0&&u<=r&&(e.fillStyle=i.color,e.fillRect(u,0,Math.max(f-u,1),Ie))}let l=Bi(n,t,r);if((l.left>0||l.right>0)&&(e.beginPath(),l.left>0&&or(e,0,1),l.right>0&&or(e,r,-1),e.fillStyle=a,e.fill(),e.strokeStyle=s?"#1f1f1f":"#ffffff",e.lineWidth=1,e.stroke()),o){let[i,u]=nt(t,o.start,o.end),f=Math.max(u-i,3),c=(i+u)/2-f/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(c,.75,f,Ie-1.5),o.anchor&&(e.beginPath(),e.moveTo(c+f/2,Ie),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function _u(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;n.nodes.forEach(o=>{let s=t.get(o.name);if(o.order>=0&&s&&_(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function tt(e,n,t=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(t?i<n:i<=n)?r=l+1:o=l}let s=e[r];if(n<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(n,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function ot(e,n,t){let r=tt(e,n),o=tt(e,t,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function vu(e){let n;for(let t of e.values())(!n||t.length>n.length)&&(n=t);return n}var sr=5,Oi=10,Pi=110,Gi=3;function Di(e){return e?"#b0b0b8":"#55555c"}function $i(e){let n=10**Math.floor(Math.log10(e)),t=e/n;return(t<=1?1:t<=2?2:t<=5?5:10)*n}function ar(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+Oi)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function qi(e,n,t,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=n(o.x0),l=n(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let u=$i(i/(l-a)*Pi),f=[],c=[];for(let d=Math.ceil(o.bp0/u)*u;d<=s.bp1;d+=u){let h=Math.round(n(tt(e,d)))+.5;if(h>=0&&h<=t){f.push(h);let p=d.toLocaleString("en-US");c.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:f,labels:ar(c)}}function Fi(e,n,t,r){let o=e.map(p=>({box:p,s0:n(p.x0),s1:n(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=t),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),u=[],f=[],c=[],d=[];for(let{box:p,s0:m,s1:b}of o){u.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Gi&&f.push(Math.round(b)+.5);let g=l(sn(p.bp1-p.bp0),(m+b)/2);g.width<=b-m&&c.push(g),p!==s.box&&d.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:u,ticks:f,labels:ar([...h,...c,...d])}}function Hi(e,n,t,r,o=!1){return(o?qi:Fi)(e,n,t,r)}function Bu(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=Hi(n,s,a,c=>e.measureText(c).width,o);if(!i)return;let u=Di(l),f=r+.5;e.strokeStyle=u,e.fillStyle=u,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:c,x1:d}of i.spans)e.moveTo(Math.max(0,c),f),e.lineTo(Math.min(a,d),f);for(let c of i.ticks)e.moveTo(c,r),e.lineTo(c,r+sr);e.stroke();for(let{text:c,at:d}of i.labels)e.fillText(c,d,r+sr+2)}function Gu(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach(o=>{let s=t.get(o.name);o.order>=0&&s&&_(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function Du(e,n,t,r){let o=[];for(let s of e){let a=t(s.x0),l=t(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:n(s.bp0),top1:n(s.bp1),bottom0:a,bottom1:l})}return o}var Wi=3;function $u(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=Wi;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,u=l.top1+(l.bottom1-l.top1)*o,f=Math.max(0,Math.min(i,u)-t,t-Math.max(i,u));f<a&&(a=f,s=l.node)}return s}function ir(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.top1,0),e.lineTo(n.bottom1,t),e.lineTo(n.bottom0,t),e.closePath()}function lr(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function qu(e,n,t,{highlightNode:r,darkMode:o}){if(t<=0||n.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of n)ir(e,l,t);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of n)lr(e,l,t);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=n.find(l=>l.node===r);a&&(e.beginPath(),ir(e,a,t),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),lr(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Xi(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach((o,s)=>{let a=t.get(o.name);if(o.order>=0&&a&&_(a)){let l=a.stable.start;r.push({bp0:l,bp1:l+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function ki(e,n,t){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=n?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&t.has(s.index)&&s.bp0<=n&&n<=s.bp1)}function Wu(e,n,t){let r=Xi(e,n),o=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let u=ki(r,i.start,l);if(u){let{node:f,bp0:c,bp1:d}=u,h=p=>f.x+(Math.min(p,d)-c)/(d-c)*f.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(u.index),height:s.width})}}}}return o}function Yi(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Xu(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=Yi(s),e.beginPath();for(let a of n){let l=t(a.x0),i=Math.max(t(a.x1),l+1);if(i>=0&&l<=o){let u=r(a.y);e.rect(l,u,i-l,r(a.y+a.height)-u)}}e.fill()}}function zi(e,n){let t=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=n.nodeMap.get(P(o.nodeName)),l=a===void 0?void 0:n.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let u=e.path[i]?.y;if(l&&u!==void 0){let f={readId:e.id,y:u,height:e.width,nodeY:l.y},c=d=>Bo(l,d);for(let d of o.mismatches){let h=c(d.pos);if(h!==null){if(d.type==="insertion"){let p=s===0&&d.pos===e.firstNodeOffset||s===r.length-1&&d.pos===e.finalNodeCoverLength;t.push({...f,kind:"insertion",x:h,seq:d.seq,softClip:p})}else if(d.type==="deletion"&&d.length!==void 0){let p=c(d.pos+d.length);p!==null&&t.push({...f,kind:"deletion",x0:h,x1:p})}else if(d.type==="substitution"&&d.seq!==void 0){let p=c(d.pos+d.seq.length);p!==null&&t.push({...f,kind:"substitution",x0:h,x1:p,seq:d.seq})}}}}}),t}function cr(e){return e.reads.flatMap(n=>zi(n,e))}function mr(e){let n=e.trim().split(/[\s,]+/),t=[],r=0,o=()=>Number(n[r++]);for(;r<n.length;){let s=n[r++];s==="M"||s==="L"?t.push({op:s,x:o(),y:o()}):s==="H"?t.push({op:s,x:o()}):s==="V"?t.push({op:s,y:o()}):s==="Q"?t.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?t.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&t.push({op:s})}return t}function br(e){let n=1/0,t=-1/0;for(let r of e)"x"in r&&(n=Math.min(n,r.x),t=Math.max(t,r.x)),"x1"in r&&(n=Math.min(n,r.x1),t=Math.max(t,r.x1));return{x0:n,x1:t}}function ur(e,n,t){let r=mr(e);return{commands:r,color:n,alpha:t,...br(r)}}function dr(e,n){let{shapes:t}=e,r=[...t.rectangles,...t.verticalRectangles].filter(a=>a.type===n).map(a=>({color:a.color,alpha:a.alpha??1,x0:a.xStart,x1:a.xEnd+1,y0:a.yStart,y1:a.yEnd+1})),o=Oo(t.curves,n).map(a=>ur(a.path,a.color,a.alpha??1)),s=t.corners.filter(a=>a.type===n).map(a=>ur(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function Uu(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=mr(Po(t));n.push({name:t.name,commands:r,...br(r)})}}),{bounds:e.bounds,layers:[dr(e,"haplotype"),dr(e,"read")],nodes:n,mismatches:cr(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function fr(e,n,t,r){let o=0,s=0;for(let a of n)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(t(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(t(o),r(s));break;case"H":o=a.x,e.lineTo(t(o),r(s));break;case"V":s=a.y,e.lineTo(t(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(t(a.x1),r(a.y1),t(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(t(a.x1),r(a.y1),t(a.x2),r(a.y2),t(o),r(s));break;case"Z":e.closePath();break}}function pr(e,n,t,r){let o=new Map;for(let s of n)if(t(s)){let a=`${s.color}|${s.alpha}`,l=o.get(a);l?l.push(s):o.set(a,[s])}for(let s of o.values()){e.fillStyle=s[0].color,e.globalAlpha=s[0].alpha,e.beginPath();for(let a of s)r(a);e.fill()}e.globalAlpha=1}var ji=12,Vi=.15;function Ui(e){return Math.max(Vi,Math.min(1,e/ji))}function Ku(e,n,t){let{x:r,y:o,width:s}=t,a=u=>r(u.x1)>=0&&r(u.x0)<=s;for(let u of n.layers)pr(e,u.rects,a,f=>{let c=r(f.x0),d=o(f.y0);e.rect(c,d,r(f.x1)-c,o(f.y1)-d)}),pr(e,u.shapes,a,f=>{fr(e,f.commands,r,o)});let l=t.darkMode?"#d0d0d0":"#000000",i=t.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,t.yScale));for(let u of n.nodes)if(a(u)){let f=u.name===t.highlightNode;e.beginPath(),fr(e,u.commands,r,o),e.fillStyle=f?"rgba(255,192,203,0.5)":i,e.strokeStyle=f?"#ff0000":l,e.fill(),e.globalAlpha=f?1:Ui(r(u.x1)-r(u.x0)),e.stroke(),e.globalAlpha=1}Zi(e,n.mismatches,t)}var gr=12,Ki=6;function Qi(e){return gr*e>=Ki}function hr(e,{x:n,width:t}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return n(o)>=0&&n(r)<=t}function Zi(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!Qi(s)||n.length===0)return;let l=gr*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&hr(i,t)){let u=r(i.x0),f=o(i.y);e.rect(u,f,r(i.x1)-u,o(i.y+i.height)-f)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of n)hr(i,t)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Ju(e,n){let t=[];for(let r of n){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||t.push({gene:r,...ot(o,l,i),exons:r.exons.filter(u=>u.end>l&&u.start<i).map(u=>ot(o,Math.max(u.start,l),Math.min(u.end,i)))})}return t}var yr=22,Ji=4,bn=8,el="11px sans-serif",nl=8;function ed(e){let n=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),t=0,r=0;for(let{step:o}of n)t+=o,r=Math.max(r,t);return Math.min(Ji,r)}function nd(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/yr)),u=[],f=l?"#e0e0e6":"#1c1c22";e.font=el,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let c=n.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:h})=>h>=0&&d<=a).sort((d,h)=>d.s0-h.s0);for(let{g:d,s0:h,s1:p}of c){let m=d.gene.strand>0?" \u2192":d.gene.strand<0?"\u2190 ":"",b=d.gene.strand<0?`${m}${d.gene.name}`:`${d.gene.name}${m}`,g=(Math.max(h,0)+Math.min(p,a))/2,x=e.measureText(b).width/2,R=Math.min(h,g-x),N=Math.max(p,g+x),L=u.findIndex(A=>A+nl<=R);L===-1&&(L=Math.min(u.length,i-1)),u[L]=Math.max(u[L]??-1/0,N);let S=r-L*yr-bn/2;e.beginPath(),e.moveTo(h,S+.5),e.lineTo(p,S+.5),e.stroke();for(let A of d.exons){let M=s(A.x0);e.fillRect(M,S-bn/2,Math.max(1,s(A.x1)-M),bn)}e.fillText(b,g,S-bn/2-2)}}function ol(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function rl(e,n){let t=e.length,r=n.length,o=Array.from({length:t+1},()=>new Array(r+1).fill(0)),s=Array.from({length:t+1},()=>new Array(r+1).fill(!1));for(let l=t-1;l>=0;l--)for(let i=r-1;i>=0;i--){let u=Math.abs(e[l]-n[i])+o[l+1][i+1],f=t-l>r-i?o[l+1][i]:1/0,c=r-i>t-l?o[l][i+1]:1/0;o[l][i]=Math.min(u,f,c),s[l][i]=o[l][i]===u}let a=new Array(t).fill(void 0);for(let l=0,i=0;l<t&&i<r;)s[l][i]?a[l++]=i++:t-l>r-i?l++:i++;return a}function Mr(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var Sr=e=>e.spanningReads!==0;function wr(e,n){return{...n,agrees:e.complete&&Sr(n)?ol(e.bp,n.bp):void 0}}function sl(e,n){let t=new Map,r=new Set;e.forEach((l,i)=>{let u=n.find(f=>f.haplotype!==void 0&&f.haplotype===l.haplotype);u&&(r.add(u),t.set(i,wr(l,u)))});let o=n.filter(l=>l.haplotype===void 0),s=Mr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Sr)],[s,o]];for(let[l,i]of a){let u=l.filter(c=>!t.has(c.i)),f=Mr(i.filter(c=>!r.has(c)),c=>c.bp);rl(u.map(c=>c.item.bp),f.map(c=>c.item.bp)).forEach((c,d)=>{if(c!==void 0){let h=u[d],p=f[c].item;r.add(p),t.set(h.i,wr(h.item,p))}})}return t}function rd(e,n){if(!n)return e;let t=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=n[o];if(a)for(let[l,i]of sl(s,a))t.set(s[l],i)}return e.map(o=>({...o,call:t.get(o)}))}var Lr=le(Ke(),1),id=(0,te.createSvgIcon)((0,Lr.jsx)("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");export{te as a,Ms as b,pn as c,ge as d,Jl as e,ec as f,nc as g,tc as h,ul as i,Et as j,Tt as k,en as l,Ct as m,Hs as n,hl as o,gl as p,yl as q,xl as r,qt as s,sn as t,ls as u,Wt as v,Cl as w,Xo as x,Va as y,Fe as z,vs as A,On as B,Ts as C,Cs as D,Ga as E,Un as F,tu as G,ou as H,Ka as I,au as J,Ko as K,Si as L,gu as M,yu as N,xu as O,vi as P,Nu as Q,Bi as R,Ru as S,Eu as T,Au as U,_u as V,vu as W,Di as X,Bu as Y,Gu as Z,Du as _,$u as $,qu as aa,Wu as ba,Yi as ca,Xu as da,Uu as ea,Ku as fa,Qi as ga,hr as ha,Ju as ia,yr as ja,ed as ka,nd as la,tl as ma,rd as na,Bl as oa,Ol as pa,bs as qa,Pl as ra,Gl as sa,vn as ta,Vl as ua,Ul as va,id as wa};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{d as dt}from"./chunk-UQEPPJEO.js";import{c as ut}from"./chunk-SCMIJAAX.js";import{i as Le,n as ft,o as pt,p as yn,q as xn,t as ht,u as mt,y as bt,z as Mn}from"./chunk-IUIIYSGF.js";import{a as Ge,b as v,c as Ze,d as ce,e as ue,f as ct,h as Je}from"./chunk-EFVAQ2KM.js";import{a as Qe,c as it,d as lt}from"./chunk-KULNKXPT.js";import{a as Ke}from"./chunk-XEJ47DLD.js";import{a as Ue,b as le}from"./chunk-FY3BTKY4.js";var yt=Ue((al,gt)=>{gt.exports=JBrowseExports["@mui/material/SvgIcon"]});var Ms=Ue((Ql,Jt)=>{Jt.exports=JBrowseExports.mobx});var pn=Ue((su,Vo)=>{Vo.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var tl=Ue((od,xr)=>{xr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var te=le(yt(),1);function ul(e){let n=t=>Math.round(t*100)/100;return e.map((t,r)=>`${r?"L":"M"}${n(t.x)},${n(t.y)}`).join("")}function xt(e,n,t,r,o){let s=Math.hypot(r-n,t-e);if(s===0)return[t,r];let a=(t-e)/s,l=(r-n)/s;return[t+o*a,r+o*l]}function Nn(e,n){let t=1-n,r=t*t*t,o=3*t*t*n,s=3*t*n*n,a=n*n*n;return{x:r*e.x0+o*e.cx0+s*e.cx1+a*e.x1,y:r*e.y0+o*e.cy0+s*e.cy1+a*e.y1}}function Rt(e){let n=e[Math.floor(e.length/2)];return n?Nn(n,.5):void 0}function Et(e){let n=1/0,t=1/0,r=-1/0,o=-1/0;for(let s of e)n=Math.min(n,s.x0,s.cx0,s.cx1,s.x1),r=Math.max(r,s.x0,s.cx0,s.cx1,s.x1),t=Math.min(t,s.y0,s.cy0,s.cy1,s.y1),o=Math.max(o,s.y0,s.cy0,s.cy1,s.y1);return{minX:n,minY:t,maxX:r,maxY:o}}function Rr(e,n,t){let r=Nn(e,n),o=Nn(e,t),s=(t-n)/3,a=Mt(e,n),l=Mt(e,t);return{x0:r.x,y0:r.y,cx0:r.x+a.x*s,cy0:r.y+a.y*s,cx1:o.x-l.x*s,cy1:o.y-l.y*s,x1:o.x,y1:o.y}}function Mt(e,n){let t=1-n,r=3*t*t,o=6*t*n,s=3*n*n;return{x:r*(e.cx0-e.x0)+o*(e.cx1-e.cx0)+s*(e.x1-e.cx1),y:r*(e.cy0-e.y0)+o*(e.cy1-e.cy0)+s*(e.y1-e.cy1)}}function At(e,n){let t=[];for(let r of e){let o=Math.hypot(r.cx0-r.x0,r.cy0-r.y0)+Math.hypot(r.cx1-r.cx0,r.cy1-r.cy0)+Math.hypot(r.x1-r.cx1,r.y1-r.cy1),s=Math.max(3,Math.round(o/n)|1);for(let a=0;a<s;a+=2)t.push([Rr(r,a/s,(a+1)/s)])}return t}function Tt(e,n,t){let r=new Array(e.length);for(let o=0;o<e.length;o++){let s=e[o];r[o]={x0:s.x0+n,y0:s.y0+t,cx0:s.cx0+n,cy0:s.cy0+t,cx1:s.cx1+n,cy1:s.cy1+t,x1:s.x1+n,y1:s.y1+t}}return r}function wn(e,n){let t=e.length-1;return n==="end"?{at:e[t],inward:e[t-1]}:{at:e[0],inward:e[1]}}var Er=.5,Ar=80;function wt(e){let n=1/0,t=-1/0;for(let r of e)n=Math.min(n,r.x),t=Math.max(t,r.x);return{min:n,max:t}}function St(e,n){return Math.max(0,n.min-e,e-n.max)}function Lt(e,n,t){let r=St(e[0].x,n),o=St(e[e.length-1].x,n);return r===o?t:r<o?"start":"end"}function Tr(e,n){return{from:Lt(e,wt(n),"end"),to:Lt(n,wt(e),"start")}}var Cr=.75,Ir=1.15,_r=.35,vr=60;function Br(e,n,t,r,o,s){let a=Math.hypot(t-e,r-n),l=a===0?1:(t-e)/a,i=a===0?0:(r-n)/a,u=0,f=1/0,c=-1/0;for(let m of o){let b=m.x-e,g=m.y-n,M=b*-i+g*l;Math.abs(M)>Math.abs(u)&&(u=M);let R=b*l+g*i;f=Math.min(f,R),c=Math.max(c,R)}let d=o.length?c-f:0,h=Math.max(Math.abs(u)*Ir/Cr,d*_r),p=s===void 0?h:Math.min(h,s);return u<0?-p:p}function en({scaleX:e,scaleY:n}){return n/e}var Or=3;function Sn(e,n,t){let r=n.x-e.x,o=(n.y-e.y)*t,s=Math.hypot(r,o);return s===0?void 0:{x:r/s,y:o/s}}function Ct(e,n,t,r,o=Or){let s=en(r),a=Sn(e[e.length-1],n[0],s)??Sn(e[0],e.at(-1),s)??Sn(n[0],n.at(-1),s)??{x:1,y:0},l=[];for(let i=0;i<t;i++){let u=(i-(t-1)/2)*o;l.push({x:-a.y*u,y:a.x*u/s})}return l}function Ln(e,n){return e.map(t=>({x:t.x,y:t.y*n}))}function Pr(e,n){for(let t of e)t.y0/=n,t.cy0/=n,t.cy1/=n,t.y1/=n;return e}var Gr=12,Dr=40;function Nt(e,n){let t=0;for(let s=1;s<e.length;s++)t+=Math.hypot(e[s].x-e[s-1].x,e[s].y-e[s-1].y);let r=t*n;return Math.min(Dr,Math.max(Gr,r/2))/Math.max(n,Number.EPSILON)}function It(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function $r(e,n,t,r){let{at:o,inward:s}=e,a=s?o.x-s.x:1,l=s?o.y-s.y:0,i=Math.hypot(a,l)||1,u=a/i,f=l/i,c=o.x+t,d=o.y+r,h=c+u*n/3,p=d+f*n/3,m=c+u*n,b=d+f*n,g=-f*n/2,M=u*n/2;return[{x0:c,y0:d,cx0:h,cy0:p,cx1:m+g,cy1:b+M,x1:m,y1:b},{x0:m,y0:b,cx0:m-g,cy0:b-M,cx1:h,cy1:p,x1:c,y1:d}]}function De(e,n,t,r,o,s,a=[],l){let i=s.scaleX,u=en(s),f=l??(s.pixelRows?vr:void 0);if(u!==1)return Pr(De(Ln(e,u),Ln(n,u),t,r,o*u,{scaleX:i,scaleY:i},Ln(a,u),f===void 0?void 0:f*u),u);if(typeof t=="string")return $r(wn(e,t),Nt(e,i),r,o);let c=t?{from:"end",to:"start"}:Tr(e,n),d=wn(e,c.from),h=wn(n,c.to),p=d.at,m=h.at,b=p.x+r,g=p.y+o,M=m.x+r,R=m.y+o;if(t){let L=1,S=0;if(d.inward){let U=p.x-d.inward.x,j=p.y-d.inward.y,V=Math.hypot(U,j);V>0&&(L=U/V,S=j/V)}let N=Nt(e,i),A=-S,x=L,T=(p.x+m.x)/2+r+A*N,_=(p.y+m.y)/2+o+x*N,G=b+L*N,$=g+S*N,W=M-L*N,H=R-S*N;return[{x0:b,y0:g,cx0:G,cy0:$,cx1:G+A*N,cy1:$+x*N,x1:T,y1:_},{x0:T,y0:_,cx0:W+A*N,cy0:H+x*N,cx1:W,cy1:H,x1:M,y1:R}]}else{let L=d.inward??{x:p.x-(m.x-p.x),y:p.y-(m.y-p.y)},S=h.inward??{x:m.x-(p.x-m.x),y:m.y-(p.y-m.y)},N=Math.hypot(M-b,R-g),A=(Z,J,se,_e)=>{let ae=J.x-Z.x,ie=J.y-Z.y,ee=Math.hypot(ae,ie),me=ee===0?0:(se*ae+_e*ie)/ee;return Math.max(0,Math.min(N*Er,Ar,me*.5))},x=m.x-p.x,T=m.y-p.y,[_,G]=xt(L.x,L.y,p.x,p.y,A(L,p,x,T)),[$,W]=xt(S.x,S.y,m.x,m.y,A(S,m,-x,-T)),H=a.length?Br(b,g,M,R,a,f):0,U=N===0?1:N,j=(M-b)/U,V=(R-g)/U,ke=-V*H,O=j*H,q=j*Math.abs(H),K=V*Math.abs(H);return[{x0:b,y0:g,cx0:_+r+ke-q,cy0:G+o+O-K,cx1:$+r+ke+q,cy1:W+o+O+K,x1:M,y1:R}]}}var qr=1;function Rn(e,n){return n.flatMap(t=>e[t]??[])}function _t(e,n,t){let r=e[n.from],o=e[n.to];return r?.length&&o?.length?De(r,o,n.from===n.to,0,0,t,Rn(e,n.bypassed)):void 0}function Fr(e){let n=new Map;for(let t of e.nodes)if(v(t)){let r=n.get(t.stable.refName);r?r.push(t):n.set(t.stable.refName,[t])}for(let t of n.values())t.sort((r,o)=>r.stable.start-o.stable.start);return n}function Wr(e,n,t){let r=[];if(e)for(let o=ct(e,n);o<e.length;o++){let s=e[o];if(s.stable.start>=t)break;s.stable.start+s.length<=t&&r.push(s.id)}return r}function Hr(e,n,t,r){let{fromStrand:o,toStrand:s}=e;if(o===void 0||s===void 0)return!0;let a=o===(n.stable.strand??"+"),l=s===(t.stable.strand??"+");return r?a&&l:!a&&!l}function hl(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fr(e),r=[];for(let o=0;o<e.edges.length;o++){let s=e.edges[o],a=n.get(s.from),l=n.get(s.to);if(a!==void 0&&l!==void 0&&v(a)&&v(l)&&a.stable.refName===l.stable.refName){let i=a.stable.start<=l.stable.start,[u,f]=i?[a,l]:[l,a],c=u.stable.start+u.length,d=f.stable.start,h=d-c;if(h>=qr&&Hr(s,a,l,i)){let p=u.stable.refName;r.push({edgeIndex:o,from:s.from,to:s.to,refName:p,start:c,end:d,bp:h,bypassed:Wr(t.get(p),c,d)})}}}return r}function Ne(e){return e.endsWith("-")?"-":"+"}function vt(e){return e==="+"?"-":"+"}function Xr(e){let n=(e.fromStrand??Ne(e.from))===Ne(e.from)?"end":"start",t=(e.toStrand??Ne(e.to))===Ne(e.to)?"start":"end";return{from:n,to:t}}function gl(e){let n=e.edges.map(Xr),t=new Map,r=(d,h,p)=>{let m=`${d}|${h}`,b=t.get(m);b?b.push(p):t.set(m,[p])};e.edges.forEach((d,h)=>{r(d.from,n[h].from,h),r(d.to,n[h].to,h)});let o=d=>{let h=t.get(`${d}|end`);if(h?.length!==1)return;let p=h[0],m=e.edges[p];return m.from===d&&m.to!==d&&n[p].from==="end"&&n[p].to==="start"&&t.get(`${m.to}|start`)?.length===1?p:void 0},s=new Set,a=new Map,l=new Map;for(let d of e.nodes){let h=t.get(`${d.id}|start`),p=h?.length===1?e.edges[h[0]].from:void 0;if(a.has(d.id)||p!==void 0&&o(p)===h[0])continue;let m=[d.id];for(;;){let b=o(m.at(-1)),g=b===void 0?void 0:e.edges[b].to;if(g===void 0||a.has(g))break;s.add(b),m.push(g)}for(let b of m)a.set(b,d.id);m.length>1&&l.set(d.id,m)}for(let d of e.nodes)a.has(d.id)||a.set(d.id,d.id);let i=new Map(e.nodes.map(d=>[d.id,d])),u=[];for(let d of e.nodes){if(a.get(d.id)!==d.id)continue;let h=l.get(d.id);if(!h){u.push(d);continue}let p=h.map(g=>i.get(g)),m=p.filter(v),b=m.length?m.reduce((g,M)=>g.stable.start<=M.stable.start?g:M):p[0];u.push({id:d.id,name:d.name,length:p.reduce((g,M)=>g+M.length,0),depth:d.depth,stable:b.stable})}let f=new Set,c=[];return e.edges.forEach((d,h)=>{let p=a.get(d.from),m=a.get(d.to),b=n[h],g=`${p}|${b.from}>${m}|${b.to}`;s.has(h)||f.has(g)||(f.add(g),c.push({from:p,to:m,...b.from==="start"?{fromStrand:vt(Ne(p))}:{},...b.to==="end"?{toStrand:vt(Ne(m))}:{}}))}),{graph:{...e,nodes:u,edges:c,paths:void 0,pathVisits:void 0},runs:l}}function yl(e,n,t){let r={...e};for(let[o,s]of n){let a=e[o];if(!a?.length)continue;delete r[o];let l=An(a),i=l.at(-1),u=s.map(d=>Math.max(t(d),0)),f=u.reduce((d,h)=>d+h,0)||s.length,c=0;s.forEach((d,h)=>{let p=f?u[h]/f*i:i/s.length,m=h===s.length-1?i:c+p;r[d]=Ot(a,l,c,m),c=m})}return r}function xl(e,n,t){if(e.length===0)return[];let r=An(e),o=r.at(-1);return Ot(e,r,n*o,t*o)}function Bt(e){let n=An(e);return En(e,n,n.at(-1)/2)}function An(e){let n=[0];for(let t=1;t<e.length;t++)n.push(n[t-1]+Math.hypot(e[t].x-e[t-1].x,e[t].y-e[t-1].y));return n}function En(e,n,t){if(t<=0)return{...e[0]};let r=1;for(;r<n.length&&n[r]<t;)r++;if(r>=n.length)return{...e.at(-1)};let o=n[r]-n[r-1],s=o>0?(t-n[r-1])/o:0,a=e[r-1],l=e[r];return{x:a.x+(l.x-a.x)*s,y:a.y+(l.y-a.y)*s}}function Ot(e,n,t,r){let o=[En(e,n,t)];for(let s=0;s<e.length;s++)n[s]>t&&n[s]<r&&o.push({...e[s]});return o.push(En(e,n,r)),o}function Tn(e){return e.length*6.2+8}function kr(e,n){return e.x0<n.x1&&e.x1>n.x0&&e.y0<n.y1&&e.y1>n.y0}function Pt(e,n){return e.x1<=0||e.x0>=n.width||e.y1<=0||e.y0>=n.height}function Yr(e,n){return e.x0>=0&&e.x1<=n.width&&e.y0>=0&&e.y1<=n.height}function Cn(e,n=[]){let t=[...n];return r=>Pt(r,e)||t.some(o=>kr(o,r))?!1:(t.push(r),!0)}function $e(e,n,t){let r=[];for(let s of e){let a=Tn(s.text),l=s.y>n.height/2?-1:1;for(let i=0;i<=(s.stack??0);i++){let u=s.y+l*i*19,f={x0:s.x-a/2,x1:s.x+a/2,y0:u-11-4,y1:u+4};if(Pt(f,n))break;if(Yr(f,n)&&t(f)){r.push({...s,y:u,w:a});break}}}return r}var zr=26,jr=4e4,Vr=8,Ur=8,Kr=5.7,Qr=6,Zr=13,qe=3,nn=2;function rn(e){return(e.length*Kr+Qr+qe)/2}var de=(Zr+qe)/2,Jr=rn("1 bp");function tn(e,n,t){return{x0:n-e,x1:n+e,y0:t-de,y1:t+de}}function qt(e,n){return{x0:6,x1:6+e.length*6.2+8+qe,y0:n-8-qe/2,y1:n+8+qe/2}}function on(e,n,t){return t<n?e:Math.min(Math.max(e,n),t)}function sn(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:e>=1e3?`${+(e/1e3).toFixed(1)} kb`:`${e} bp`}function Gt(e){return`${sn(e)} del`}function es(e,n,t,r){let o=e[0],s=e[e.length-1],a=(n.x-(o.x0+s.x1)/2)*t,l=(n.y-(o.y0+s.y1)/2)*r,i=Math.hypot(a,l);return i===0?{x:0,y:-1}:{x:a/i,y:l/i}}function ns(e,n){return Math.abs(n.x)*(e.x1-e.x0)/2+Math.abs(n.y)*(e.y1-e.y0)/2}function ts(e,n){let t=(e.x1-e.x0)/2,r=(e.y1-e.y0)/2;return Math.min(n.x===0?1/0:t/Math.abs(n.x),n.y===0?1/0:r/Math.abs(n.y))}function os(e,n,t){let r=0;for(let o=1;o<e.length;o++){let s=e[o-1],a=e[o];r+=Math.hypot((a.x-s.x)*n,(a.y-s.y)*t)}return r}function rs(e,n){let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let a of e)for(let l of n[a]??[])t=Math.min(t,l.x),o=Math.max(o,l.x),r=Math.min(r,l.y),s=Math.max(s,l.y);return t===1/0?void 0:{minX:t,minY:r,maxX:o,maxY:s}}var Dt=new WeakMap;function ss(e,n){let t=Dt.get(e);if(t?.nodeLengths===n)return t.order;let r=Object.entries(e).filter(([o,s])=>s.length>0&&n.has(o)).sort(([o],[s])=>n.get(s)-n.get(o));return Dt.set(e,{nodeLengths:n,order:r}),r}var $t=new WeakMap;function as(e,n,t,r){let{scaleX:o,scaleY:s}=t,a=$t.get(e);if(a?.deletions===n&&a.scaleX===o&&a.scaleY===s&&a.version===r)return a.arcs;let l=[];for(let i of[...n].sort((u,f)=>f.bp-u.bp)){let u=_t(e,i,t),f=u?Rt(u):void 0;if(u&&f){let{minX:c,minY:d,maxX:h,maxY:p}=Et(u);l.push({deletion:i,curves:u,apex:f,extent:Math.max((h-c)*o,(p-d)*s)})}}return $t.set(e,{deletions:n,scaleX:o,scaleY:s,version:r,arcs:l}),l}function Ft({nodePositions:e,nodeLengths:n,deletions:t,alleleDeletions:r,axis:o,translateX:s,translateY:a,width:l,height:i,version:u=0}){let{scaleX:f,scaleY:c}=o,d=[],h=[];for(let{deletion:b,curves:g,apex:M,extent:R}of as(e,t,o,u))if(R>=zr){let L=Gt(b.bp),S=rn(L),N=tn(S,0,0),A=M.x*f+s,x=M.y*c+a,T=R>=S*2/nn,_=es(g,M,f,c),G=ns(N,_)+Ur,$=T?A:on(A+_.x*G,S,l-S),W=T?x:on(x+_.y*G,de,i-de),H=Math.hypot($-A,W-x),U;if(H>0){let j={x:($-A)/H,y:(W-x)/H},V=ts(N,j);U={arcX:A,arcY:x,labelX:$-j.x*V,labelY:W-j.y*V}}d.push({label:{key:`del:${b.edgeIndex}`,text:L,x:$,y:W,kind:"deletion",leader:U},box:tn(S,$,W)})}let p=new Set,m=[...r??[]].sort((b,g)=>g.bp-b.bp);for(let b of m){let g=rs(b.nodeIds,e);if(!g)continue;let M=Math.max(g.minX*f+s,0),R=Math.min(g.maxX*f+s,l),L=Math.max(g.minY*c+a,0),S=Math.min(g.maxY*c+a,i);if(R<M||S<L)continue;let N=Math.max(R-M,S-L),A=Gt(b.bp),x=rn(A);if(N>=x*2/nn){for(let G of b.nodeIds)p.add(G);let T=on((M+R)/2,x,l-x),_=on((L+S)/2,de,i-de);d.push({label:{key:`alleledel:${b.nodeIds.join(",")}`,text:A,x:T,y:_,kind:"deletion"},box:tn(x,T,_)})}}for(let[b,g]of ss(e,n)){if(p.has(b))continue;let{x:M,y:R}=Bt(g),L=R*c+a;if(L+de<=0||L-de>=i)continue;let S=os(g,f,c);if(S<Jr*2/nn)continue;let N=sn(n.get(b)),A=rn(N);if(S>=A*2/nn){let x=M*f+s;h.push({label:{key:`node:${b}`,text:N,x,y:L,kind:"node"},box:tn(A,x,L)})}}return{deletions:d,nodes:h}}function Wt(e,n){return Math.max(Vr,Math.floor(e*n/jr))}function In(e,n,t=1/0){let r=[];for(let{label:o,box:s}of e){if(r.length>=t)break;n(s)&&r.push(o)}return r}var ls=3.4,Ht=6,cs=8,us=18,ds=2,fs=60,ps=8,Xt=15;function _n(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function Cl(e){let{paneWidth:n,canvasHeight:t,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:n,height:t},i=x=>({x:x.x*s+r,y:x.y*a+o}),u=e.drawnRowLabels.map(({label:x,y:T})=>qt(x,T*a+o)),f=e.referenceStripZonePx??0;f>0&&u.push({x0:0,x1:n,y0:0,y1:f}),e.legendSize.width>0&&u.push({x0:n-Ht-e.legendSize.width,x1:n,y0:0,y1:f+Ht+e.legendSize.height}),e.poppedFrom&&u.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let c=Cn(l,u),d=e.drawnRowLabels.length>0,h=d?Math.min(...e.drawnRowLabels.map(x=>x.y)):1/0,p=e.contigThickness*ls,m=_n(e.bubbleHalos,x=>x.members),b=$e(m.map(x=>{let{x:T,y:_}=i({x:x.labelAt.x,y:Math.min(x.labelAt.y,h)}),G=_-p/2-6;return{item:x,x:T,y:d?Math.max(G,Xt):G,text:x.label}}),l,c),g=Math.max(2,Math.min(ps,Math.floor((o-fs)/19))),M=$e(_n(e.bubbleGlyphs,x=>x.bubble.end-x.bubble.start).flatMap(x=>{let T=(x.bubble.start+x.bubble.end)/2*s+r,_=Tn(x.label)/2;return T<0||T>n?[]:[{item:{glyph:x,glyphX:T},x:Math.min(Math.max(T,_),n-_),y:Xt,text:x.label,stack:g-1}]}),l,c),R=$e(_n(e.genePins,x=>x.gene.end-x.gene.start).map(x=>{let{x:T,y:_}=i(x.at);return{item:x,x:T,y:_+e.contigThickness+us,text:x.covered<.98?`${x.gene.name} \u2026`:x.gene.name,stack:ds}}),l,c),L=e.nodePositions&&e.labelsNodeSizes?Ft({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:n,height:t,version:e.positionsVersion}):{deletions:[],nodes:[]},S=In(L.deletions,c),N=$e(m.flatMap(x=>x.routes.map(T=>{let{x:_,y:G}=i(T.at);return{item:{halo:x,route:T},x:_,y:G+4,text:T.text,stack:cs}})),l,c),A=In(L.nodes,c,Wt(n,t));return{bubbles:b,glyphs:M,genes:R,routes:N,sizes:[...S,...A]}}function Bl(e){return Ge(e)?zt(e):void 0}function zt(e){return{sample:Qe(e.stable.refName),haplotype:it(e.stable.refName),refName:lt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function hs(e,n){let t=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of t)o=o&&s.start-o.end<=n?{start:o.start,end:Math.max(o.end,s.end)}:{start:s.start,end:s.end},(!r||o.end-o.start>r.end-r.start)&&(r=o);return r}function ms(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ol(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Ge(o)){let s=zt(o),a=ms(s),l=t.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):t.set(a,{sample:s.sample,haplotype:s.haplotype,refName:s.refName,rank:o.stable.rank,spans:[{start:s.start,end:s.end}]})}let r=new Map;for(let o of t.values()){let s=hs(o.spans,n);if(s){let a={sample:o.sample,haplotype:o.haplotype,refName:o.refName,start:s.start,end:s.end,rank:o.rank,nodeCount:o.spans.length},l=o.haplotype??o.sample,i=r.get(l);(!i||a.nodeCount>i.nodeCount)&&r.set(l,a)}}return[...r.values()].sort((o,s)=>+(o.rank!==0)-+(s.rank!==0)||o.sample.localeCompare(s.sample)||(o.haplotype??"").localeCompare(s.haplotype??""))}function bs(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function Pl(e,n){return e.flatMap(t=>{let r=bs(n,t);return r===void 0?[]:[{...t,sample:r}]})}function Gl(e){return`${e.refName}:${e.start+1}-${e.end}`}function vn(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var jt=le(Ke(),1),Vt=(0,te.createSvgIcon)((0,jt.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Ut=le(Ke(),1),Kt=(0,te.createSvgIcon)((0,Ut.jsx)("path",{d:"M17 5h-2V3h2zm-2 16h2v-2.59L19.59 21 21 19.59 18.41 17H21v-2h-6zm4-12h2V7h-2zm0 4h2v-2h-2zm-8 8h2v-2h-2zM7 5h2V3H7zM3 17h2v-2H3zm2 4v-2H3c0 1.1.9 2 2 2M19 3v2h2c0-1.1-.9-2-2-2m-8 2h2V3h-2zM3 9h2V7H3zm4 12h2v-2H7zm-4-8h2v-2H3zm0-8h2V3c-1.1 0-2 .9-2 2"}),"HighlightAlt");var Qt=le(Ke(),1),Bn=(0,te.createSvgIcon)((0,Qt.jsx)("path",{d:"M3 16h5v-2H3zm6.5 0h5v-2h-5zm6.5 0h5v-2h-5zM3 20h2v-2H3zm4 0h2v-2H7zm4 0h2v-2h-2zm4 0h2v-2h-2zm4 0h2v-2h-2zM3 12h8v-2H3zm10 0h8v-2h-8zM3 4v4h18V4z"}),"LineStyle");var gs="Linear genome view",ys="Linear synteny view",xs="No synteny track in this session aligns these assemblies";function Zt({label:e,icon:n,entries:t,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=t,i=s?[{label:e,icon:n,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return t.length===0?i:t.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:n,onClick:o(l)}]:[{label:e,icon:n,type:"subMenu",subMenu:t.map(u=>({label:r(u),onClick:o(u)}))}]}function Vl({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...Zt({label:gs,icon:Bn,entries:e,entryLabel:s=>`${s.sample} ${vn(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?Zt({label:`${ys} (${o} assemblies)`,icon:Vt,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:xs,onSelect:s=>()=>{r(s.trackId)}}):[]]}function Ul({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${vn(e.location)}`,target:e}:void 0,n&&n.assembly!==e?.assembly?{label:`Open in ${n.assembly} \u2014 around this node`,target:n}:void 0].filter(a=>a!==void 0);return[...o&&t?[{label:`Highlight in ${t.assembly}`,icon:Kt,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:Bn,onClick:()=>{r(l)}}))]}var ws=10;function Ss(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=ws*(o.end-o.start)&&(t===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=t/2))}var Ls=40;function ge(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Ns(e,n){let t=ge(e),r=ge(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function eo(e){return e>=dt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Jl(e,n=[]){let t=Rs(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function Rs(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=Ns(r,o);if(a>=Ls)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${eo(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${ge(o)} inv`};let u=o!==r?Ss(e,n):void 0;if(u){let c=u.name?` (${u.name})`:"";return{kind:"repeat",label:`${i} repeat array${c}, ${eo(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${ge(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${ge(o-t)} ins${f}`}:o===t?{kind:"deletion",label:`${ge(t-r)} del${f}`}:{kind:"complex",label:`${ge(t)} ref \u2192 ${i}, ${s} alleles`}}var ec={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},nc={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function tc(e){return e.segments.split(",").filter(Boolean)}function On(e){return e.id.endsWith("-")?"-":"+"}function Pn(e,n){return n===On(e)?e.id:`-${e.id}`}function Es(e,n){let t=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)t[o]=r,r+=e[o];let s=n;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],t[a]=s;return t}function As(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=Es(n,e.pathLength),o=(l,i=!1)=>{for(let u=0;u<r.length;u++){let f=r[u],c=n[u];if(f!==void 0&&c!==void 0&&f<=l&&(l<f+c||i&&l===f+c))return{s:u,local:l-f,room:f+c-l}}},s=(l,i)=>{let u=t[l],f=u.at(-1);i.type==="substitution"&&f?.type==="substitution"&&f.pos+f.seq.length===i.pos?f.seq+=i.seq:u.push(i)},a=e.pathStart;for(let l of ut(e.cs))if(l.op==="match")a+=l.length;else if(l.op==="substitution"){let i=o(a);i&&s(i.s,{type:"substitution",pos:i.local,seq:l.seq}),a+=1}else if(l.op==="insertion"){let i=o(a,a===e.pathEnd);i&&s(i.s,{type:"insertion",pos:i.local,seq:l.seq})}else{let i=l.length;for(;i>0;){let u=o(a),f=u?Math.min(i,u.room):i;u&&s(u.s,{type:"deletion",pos:u.local,length:f}),a+=f,i-=f}}return t}function no(e,n,t){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of n){let a=s.path.map(f=>r.get(f.name)),l=a.flatMap((f,c)=>f?[c]:[]),i=l[0],u=l.at(-1);if(i!==void 0&&u!==void 0){let f=As(s,a.map(h=>h?.length)),c=l.map(h=>Pn(a[h],s.path[h].strand)),d=a[u].length;o.push({id:t+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:c,sequenceNew:l.map((h,p)=>({nodeName:c[p],mismatches:f[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:u===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ts=["#6baed6","#4292c6","#2171b5","#08519c"],Cs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function to(e){let n=e.is_reverse?Cs:Ts;return n[e.id%n.length]}var Is=4;function Fe(e){let n=new Map;function t(r,o){let s=n.get(r);s?s.push(o):n.set(r,[o])}for(let r of e.edges)t(r.from,r.to),t(r.to,r.from);return n}function _s({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<Is&&o.length>0;l++){let i=[];for(let u of o){let f=t.get(u);if(f){for(let c of f)if(!r.has(c)){r.add(c);let d=n.get(c);d&&v(d)?(s=Math.min(s,d.stable.start+d.length),a=Math.max(a,d.stable.start)):i.push(c)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function vs({nodeId:e,nodeById:n,neighbors:t}){let r=n.get(e);return r===void 0?void 0:v(r)?{start:r.stable.start,end:r.stable.start+r.length}:_s({nodeId:e,nodeById:n,neighbors:t})}function oo(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Fe(e),r=new Map;for(let o of e.nodes){let s=vs({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}function an(e){let n=e.split("#"),t=n.length>=2?Number(n[1]):Number.NaN;return{sample:n[0]??e,haplotype:Number.isFinite(t)?t:void 0}}function Bs(e,n,t,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=n.get(l);if(i){o.push(i);for(let u of t.get(l)??[]){let f=n.get(u);f&&(f.stable.rank===0?s.push(f):r.has(u)||(r.add(u),a.push(u)))}}}return{members:o,anchors:s}}function Os(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let t=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=t[0],o=t.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function Ps(e,n,t){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of t.get(n.id)??[])r.has(a)&&(o.set(a,0),s.push(a));if(s.length===0)for(let a of e)o.set(a.id,0),s.push(a.id);for(let a of s){let l=o.get(a)+r.get(a).length;for(let i of t.get(a)??[])if(r.has(i)){let u=o.get(i);(u===void 0||l<u)&&(o.set(i,l),s.push(i))}}return o}function Gs(e,n,t){let r=Ps(e,n,t),o=[...e].sort((i,u)=>r.get(i.id)-r.get(u.id)),s=new Map(o.map((i,u)=>[i.id,u])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,u]of o.entries()){let f=0;for(let c of t.get(u.id)??[]){let d=a.get(c);d&&s.get(c)<i&&(f=Math.max(f,l.get(c)+d.length))}l.set(u.id,f)}return{offsets:l,ordered:o}}function so(e){let n=new Map(e.nodes.filter(Ge).map(s=>[s.id,s])),t=Fe(e),r=new Set,o=[];for(let s of n.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=Bs(s.id,n,t,r),i=Os(l);if(i){let{offsets:u,ordered:f}=Gs(a,i.entry,t);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:f.map(c=>c.id),nodeOffsets:f.map(c=>u.get(c.id)),pathLength:f.reduce((c,d)=>Math.max(c,u.get(d.id)+d.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ds=1,$s=.015;function ln({graph:e,span:n,rowY:t,positions:r}){let o=n*$s,s=so(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let c=f.refSpan-f.pathLength;c>=Ds&&l.push({nodeIds:f.nodeIds,bp:c});let d=Math.max(f.refSpan,o),h=f.pathLength>0?d/f.pathLength:0;f.nodeIds.forEach((p,m)=>{let b=a.get(p);if(b){let g=f.nodeOffsets[m],M=d/f.nodeIds.length,R=S=>f.start+S*h,L=t(b);r[p]=h?[{x:R(g),y:L},{x:R(g+b.length),y:L}]:[{x:f.start+m*M,y:L},{x:f.start+(m+1)*M,y:L}]}})}let i=Fe(e),u=Object.keys(r);for(let f of u){let c=r[f].at(-1).x;for(let d of i.get(f)??[]){let h=a.get(d);if(h&&!(d in r)){let p=t(h);r[d]=[{x:c,y:p},{x:c+o,y:p}],u.push(d)}}}return l}function qs(e){let n=new Set;for(let t of e.nodes)t.stable&&n.add(t.stable.rank);return new Map([...n].sort((t,r)=>t-r).map((t,r)=>[t,r]))}function ao(e,n){let t=ce(e);if(t.length===0)return;let r=Je(t,n),o=qs(e),s=ue(t),a=ln({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,u])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:u*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Fs=12,Gn=20;function io(e){return 10+8*Math.log2(1+e.length)}function fe(e,n){return e<n?-1:e>n?1:0}function co(e,n){return fe(e.at,n.at)||fe(e.side,n.side)||fe(e.hops,n.hops)}var lo={at:1/0,side:0,hops:0};function Ws(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=ks(e);return e.nodes.map(r=>r.id).sort((r,o)=>co(t.get(r)??lo,t.get(o)??lo)||fe(n.get(r).name,n.get(o).name)||fe(r,o))}function Hs(e,n){let t=new Set(e.nodes.map(f=>f.id)),r=new Map(n.map(f=>[f.id,f.stable.start])),o=new Map,s=new Map;n.forEach((f,c)=>{s.set(f.id,n[c-1]?.id),o.set(f.id,n[c+1]?.id)});let a=n[0]?.id,l=(f,c)=>{let d=o.get(f);o.set(f,c),s.set(c,f),o.set(c,d),d!==void 0&&s.set(d,c)},i=(f,c)=>{let d=s.get(f);d===void 0?(a=c,s.set(c,void 0),o.set(c,f),s.set(f,c)):l(d,c)};for(let f of e.paths??[]){let c=0,d=0,h;for(let g of f.nodeIds){let M=r.get(g);M!==void 0&&(h!==void 0&&M!==h&&(M>h?c++:d++),h=M)}let p=d>c?[...f.nodeIds].reverse():f.nodeIds,m,b=new Set;for(let g of p)if(o.has(g)){if(m===void 0)for(let M of b)i(g,M);m=g}else t.has(g)&&(m===void 0?b.add(g):(l(m,g),m=g))}let u=[];for(let f=a;f!==void 0;f=o.get(f))u.push(f);return u}function Xs(e,n){let t=[...n.entries()].sort(([a,l],[i,u])=>co(l,u)||fe(a,i)).map(([a])=>a),r=t.length;for(let a of t){let l=n.get(a);for(let i of e.get(a)??[])n.has(i)||(n.set(i,{at:l.at,side:1,hops:l.hops+1}),t.push(i))}let o=new Set(t.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=n.get(a),i=[a];s.add(a);let u=!0;for(let f of i){let{hops:c}=n.get(f),d=!0,h=!1;for(let p of e.get(f)??[]){let m=n.get(p);m.at===l&&o.has(p)?(d&&=m.hops<=c,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,u&&=m.at<l)}u&&=!d||h}if(u)for(let f of i){let c=n.get(f);n.set(f,{...c,side:-1,hops:-c.hops})}}}function ks(e){let n=new Set(e.nodes.map(s=>s.id)),t=new Map;for(let s of e.edges)!n.has(s.from)||!n.has(s.to)||((t.get(s.from)??t.set(s.from,[]).get(s.from)).push(s.to),(t.get(s.to)??t.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(v).sort((s,a)=>fe(s.stable.start,a.stable.start)||fe(s.name,a.name)),o=new Map;return Hs(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),Xs(t,o),o}function Ys(e){let n=new Map(e.nodes.map(c=>[c.id,c])),t=Ws(e),r=new Map(t.map((c,d)=>[c,d])),o=c=>v(n.get(c)),s=new Map(t.map(c=>[c,[]])),a=new Map(t.map(c=>[c,[]])),l=(c,d)=>{s.get(d).push(c),a.get(c).push(d)};for(let c of e.edges)c.from===c.to||!r.has(c.from)||!r.has(c.to)||(r.get(c.from)<r.get(c.to)?l(c.from,c.to):l(c.to,c.from));let i=t.filter(o);for(let c=1;c<i.length;c++)l(i[c-1],i[c]);let u=new Map;for(let c of t){let d=0;for(let h of s.get(c))d=Math.max(d,u.get(h)+1);u.set(c,d)}for(let c=t.length-1;c>=0;c--){let d=t[c],h=a.get(d);if(o(d)||h.length===0)continue;let p=1/0;for(let g of h)p=Math.min(p,u.get(g));let m=u.get(d),b=Math.max(m,p-1);u.set(d,Math.floor((m+b)/2))}let f=[];for(let c of t)(f[u.get(c)]??=[]).push(c);return{layers:f,layerOf:u,preds:s}}function uo(e){if(!e.nodes.some(v))return;let n=new Map(e.nodes.map(c=>[c.id,c])),t=c=>v(n.get(c)),{layers:r,layerOf:o,preds:s}=Ys(e),a=r.map(c=>{let d=0;for(let h of c)d=Math.max(d,io(n.get(h)));return d}),l=[],i=0;for(let c=0;c<r.length;c++)l[c]=i,i+=a[c]+Fs;let u=new Map;for(let c of r){let d=[];for(let p of c){if(t(p)){u.set(p,0);continue}let m=s.get(p).filter(g=>u.has(g)),b=0;for(let g of m)b+=u.get(g)/m.length;d.push({id:p,ideal:b===0?Gn:b})}d.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of d){let b=Math.round(m/Gn);b===0&&(b=m>=0?1:-1);for(let g=1;h.has(b);g++)h.has(b+g)?h.has(b-g)||(b-=g):b+=g;h.add(b),u.set(p,b*Gn)}}let f={};for(let c of e.nodes){let d=o.get(c.id),h=io(c),p=l[d]+a[d]/2,m=u.get(c.id);f[c.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function zs(e,n){let t=new Map;for(let o of e.nodes)if(Ze(o)){let{sample:s}=an(o.stable.refName);t.set(s,(t.get(s)??0)+o.length)}let r=new Map(n.map((o,s)=>[o,s]));return[...t.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||t.get(s)-t.get(o)||o.localeCompare(s))}function fo(e,n,t=[]){let r=ce(e),o=zs(e,t);if(r.length===0||o.length===0)return;let s=Je(r,n),a=new Map(o.map((d,h)=>[d,h+1])),l=ue(r),i=o.length+1,u=ln({graph:e,span:s,rowY:d=>{let h=d.stable;return((h?a.get(an(h.refName).sample):void 0)??i)*20},positions:l}),c=[{label:an(r[0].stable.refName).sample,y:0},...o.map(d=>({label:d,y:a.get(d)*20}))];return{nodePositions:l,rowLabels:c,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:u}}function Dn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Xe=!1,po=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Co(e){return{mergeNodesFlag:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,mappingQualityCutoff:e.mappingQualityCutoff??0,focusReadNames:e.focusReadNames??null,showExonsFlag:e.showExons??!1,trackColor:e.trackColor??(n=>po[n.id%po.length]),trackAlpha:e.trackAlpha??(()=>1)}}var B=Co({}),Hn=null,y=[],w=[],E=[],I=new Map,Ae=[],C=[],ye=[],kn=[],Yn=[],Q=-1,D=Dn(),Xn={minX:0,maxX:0,minY:0,maxY:0},We,cn=new Map;function Io(e,n,t=[],r={}){if(B=Co(r),Hn=r.bed??null,D=Dn(),ye=[],kn=[],Yn=[],Ae=[],Xn={minX:0,maxX:0,minY:0,maxY:0},We=void 0,cn=new Map,e.length===0||n.length===0)return;let o=$n(e);y=[],o.forEach((i,u)=>{y[u+1]=i}),w=$n(n);let s=t.length>0;E=$n(Ba(t));for(let i=w.length-1;i>=0;i-=1){let u=w[i];if(u.type===void 0&&(u.type="haplotype"),u.hidden===!0){w.splice(i,1);continue}u.indexOfFirstBase!==void 0&&(We=u.name)}if(w.length===0)return;Vs(0),I=bo(),Re(w),B.showReads&&E.length>0&&Re(E),To(),B.mergeNodesFlag&&(go(),Fn(),B.showReads&&E.length>0&&qn(),va(),I=bo(),To(),Re(w),B.showReads&&E.length>0&&Re(E)),go(),ma(),Xe&&console.log(`${y.length} nodes.`),Fn(),Q=xo(),ba(),Fn(),Q=xo();let a=B.showReads&&B.coarsenedReadView&&!s;if(a){let i=We===void 0?-1:w.findIndex(c=>c.name===We),u=i===-1?0:i,f=w.filter((c,d)=>d!==u);if(f.length>0){let c=No(f,"haplotype");c.length>0&&(w=[w[u]],E=c)}}Ea(),Ma(),B.showExonsFlag&&Hn!==null&&Ra();let l=B.showReads&&B.coarsenedReadView&&E.length>0&&!a;return B.showReads&&E.length>0?(Us(),qn(),Re(E),l&&(E=No(E,"read"),qn(),Re(E)),Qs(),w=w.concat(E)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),ya(),Ca(),Xe&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(ye)),ca(),{nodes:y,tracks:w,reads:E,nodeMap:I,shapes:D,bounds:Xn,maxOrder:Q,trackForRuler:We,coarsenedEdgeMeta:cn}}function Ee(e,n="plain"){return B.trackColor(e,n)}function js(e){return B.trackAlpha(e)}function $n(e){return structuredClone(e)}function k(e){let n=String(e);return n.length>=1&&n.startsWith("-")}function P(e){return k(e)?String(e).substring(1):e}function pe(e){return k(e)?e:`-${e}`}function _o(e){return k(e)?P(e):pe(e)}function un(e){return(e||1/e)>=0}function Vs(e){let n=new Set,t=w[e].sequence;for(let r=0;r<t.length;r+=1){let o=t[r];if(k(o)){let s=P(o),a=t.indexOf(s);(a===-1||a>r)&&n.add(s)}}for(let r of w){t=r.sequence;for(let o=0;o<t.length;o+=1){let s=t[o];k(s)?n.has(P(s))&&(t[o]=P(s)):n.has(s)&&(t[o]=pe(s))}}y.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function Us(){Ae=[];for(let n=0;n<=Q;n+=1)Ae[n]=[];let e=new Map;y.forEach(n=>{n.y!==void 0&&ho(e,n.order,n.y+n.contentHeight)}),w.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{ho(e,t.order,(t.y??0)+n.width)})}),y.forEach((n,t)=>{n.order>=0&&n.y===void 0&&(n.y=(e.get(n.order)??0)+25,n.contentHeight=0,Ae[n.order].push(t))})}function ho(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var dn=7;function Ks(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),E.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=dn),e.path.length===1){let t=e.path[0].node;t!==null&&y[t].internalReads.push(n)}else e.path.forEach((t,r)=>{if(r===0){let o=e.path[0].node;o!==null&&y[o].outgoingReads.push([n,r])}else{let o=t.node;o!==null&&y[o].incomingReads.push([n,r])}})})}function Qs(){sa(),Ks();let e=y.slice();e.sort(fn);let n=new Map;for(let a=0;a<E.length;a++){let l=E[a].sourceTrackID,i=n.get(l);i===void 0?n.set(l,[a]):i.push(a)}let t=Array.from(n.keys()).sort((a,l)=>a-l),r=t.length>1?dn:0;e.forEach(a=>{if(a)for(let l of t)Zs(n.get(l),a,r)});let o=ra(),s=[];E.forEach((a,l)=>{let i=a.path.length,u=new Array(i),f;for(let h=0;h<i;h++){h===0?u[h]=void 0:u[h]=f??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(f=p)}let c=new Array(i),d;for(let h=i-1;h>=0;h--){h===i-1?c[h]=void 0:c[h]=d??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(d=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=u[p],b=c[p],g=!!(b&&m&&b.isForward!==void 0&&m.isForward!==void 0&&(m.order>b.order||b.order===m.order&&b.isForward===m.isForward));h.betweenCycleReverseTraversal=g,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(ea),s.forEach(a=>{let l=E[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Xe&&(console.log("Reads:"),console.log(E))}function Zs(e,n,t){let r=new Set(e),o=n.incomingReads.filter(([p])=>r.has(p)),s=n.outgoingReads.filter(([p])=>r.has(p)),a=n.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(t=0);let l=n.y+n.contentHeight+t*2,i=o.map(p=>{let[m,b]=p,g=E[m].path,M=b+1,R;for(let L=1;L<=b;L++){let S=g[b-L]?.y;if(S!==void 0){M=L,R=S;break}}return{entry:p,decisionStep:M,y:R}});i.sort(Js),o=i.map(p=>p.entry);let u=l,f=new Map;o.forEach(p=>{let m=E[p[0]];m.path[p[1]].y=u,mo(f,m,p[1],u,n),u+=m.width});let c=u;s.sort(na);let d=new Map;u=l,s.forEach(p=>{let m=E[p[0]],b=m.firstNodeOffset??0;m.path[p[1]].y=u,d.set(u,b);let g=f.get(u);g===void 0||g+1<=b?(u+=m.width,c=Math.max(c,u)):(f.set(u,0),o.forEach(M=>{let R=E[M[0]],L=R.path[M[1]];L.y!==void 0&&L.y>=u&&(L.y+=m.width,mo(f,R,M[1],L.y,n))}),u+=m.width,c+=m.width)}),a.sort(oa),a.forEach(p=>{let m=E[p],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(u=l;b<(f.get(u)??-1/0)+2||g>(d.get(u)??1/0)-3;)u+=m.width||dn;m.path[0].y=u,f.set(u,g),c=Math.max(c,u)});let h=c-n.y-n.contentHeight;n.contentHeight+=h,Na(n,h)}function Js(e,n){return e.decisionStep!==n.decisionStep?e.decisionStep-n.decisionStep:e.y===void 0||n.y===void 0?(e.y===void 0?0:1)-(n.y===void 0?0:1):e.y-n.y}function mo(e,n,t,r,o){t===n.path.length-1?e.set(r,n.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function ea(e,n){let t=E[e.readIndex],r=E[n.readIndex],o=t.path[e.pathIndex],s=r.path[n.pathIndex];if(o.order!==s.order)return o.order-s.order;if(t.sourceTrackID!==r.sourceTrackID)return t.sourceTrackID-r.sourceTrackID;if(e.previousNode&&n.previousNode){let i=y[e.previousNode],u=y[n.previousNode];if(i&&u&&i.order!==u.order)return i.order-u.order}let a=e.previousY??0,l=n.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function na([e,n],[t,r]){let o=E[e],s=E[t],a,l,i=o.path.length-1,u=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&u>=0;)l=s.path[u]?.y,u-=1;if(a&&l)return a-l;let f=o.path[n]?.node,c=s.path[r]?.node,d=f!=null?y[f]:null,h=c!=null?y[c]:null;for(;d!=null&&h!=null&&d===h;){if(n<o.path.length-1){for(n+=1;o.path[n]?.node===null;)n+=1;let m=o.path[n]?.node;d=m!=null?y[m]:null}else d=null;if(r<s.path.length-1){for(r+=1;s.path[r]?.node===null;)r+=1;let m=s.path[r]?.node;h=m!=null?y[m]:null}else h=null}if(d!=null)return h!=null?fn(d,h):1;if(h!=null)return-1;let p=(o.firstNodeOffset??0)-(s.firstNodeOffset??0);return p!==0?p:(o.finalNodeCoverLength??0)-(s.finalNodeCoverLength??0)}function ta(e,n){if(e.path===void 0||n.path===void 0)return(e.path===void 0?0:1)-(n.path===void 0?0:1);let t=e.path,r=n.path,o=0,s=0;for(;o<t.length&&s<r.length;){let a=t[o],l=r[s],i=a.order,u=l.order;if(i===u&&a.node&&l.node)return(l.y??0)-(a.y??0);i<u?o+=1:(i>u||(o+=1),s+=1)}return 0}function oa(e,n){let t=E[e],r=E[n],o=t.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=t.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function ra(){let e=[];for(let n=0;n<=Q;n+=1)e.push(0);return y.forEach(n=>{n.y!==void 0&&(e[n.order]=Math.max(e[n.order],n.y+n.contentHeight+20))}),w.forEach(n=>{n.path.forEach(t=>{e[t.order]=Math.max(e[t.order],(t.y??0)+n.width)})}),e}function sa(){E.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=un(e.indexSequence[0]),r=y[n],o,s;e.path=[],e.path.push({order:r.order,isForward:t,node:n});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=t,n=Math.abs(e.indexSequence[a]),t=un(e.indexSequence[a]),r=y[n],r.order>o.order){s||e.path.push({order:o.order,isForward:!0,node:null});for(let l=o.order+1;l<r.order;l+=1)e.path.push({order:l,isForward:!0,node:null});t?e.path.push({order:r.order,isForward:!0,node:n}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:n}))}else if(r.order<o.order){s&&e.path.push({order:o.order,isForward:!1,node:null});for(let l=o.order-1;l>r.order;l-=1)e.path.push({order:l,isForward:!1,node:null});t?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:n})):e.path.push({order:r.order,isForward:!1,node:n})}else t!==s?e.path.push({order:r.order,isForward:t,node:n}):(e.path.push({order:r.order,isForward:!t,node:null}),e.path.push({order:r.order,isForward:t,node:n}))})}function qn(){E.forEach(e=>{let n=0;for(;n<e.sequence.length&&e.sequence[n].startsWith("-");)n+=1;if(n===e.sequence.length){e.is_reverse=!0,e.sequence=e.sequence.reverse();for(let a=0;a<e.sequence.length;a+=1)e.sequence[a]=P(e.sequence[a]);let t=e.sequenceNew??[];t.reverse(),e.sequenceNew=t;for(let a of t)a.nodeName=P(a.nodeName),aa(a.mismatches,oe(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=oe(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=oe(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function aa(e,n){e.forEach(t=>{t.type==="insertion"?t.pos=n-t.pos:t.type==="deletion"?t.pos=n-t.pos-(t.length??0):t.type==="substitution"&&(t.pos=n-t.pos-(t.seq?.length??0)),t.seq!==void 0&&(t.seq=vo(t.seq).split("").reverse().join(""))})}var ia={A:"T",T:"A",C:"G",G:"C"};function vo(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=ia[e.charAt(t)]??"N";return n}function Re(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=I.get(P(r)),s=y[o]?.switched??!1;s&&(r=_o(r));let a=I.get(P(r));if(a===0)throw new Error("Node "+P(r)+" has prohibited index 0");k(r)!==s?n.indexSequence.push(-a):n.indexSequence.push(a)})})}var la=20;function ca(){let e={minX:99,maxX:-99,minY:99,maxY:-99};y.forEach(n=>{n&&(n.x!==void 0&&(e.minX=Math.min(e.minX,n.x),e.maxX=Math.max(e.maxX,n.x+la+n.pixelWidth)),n.y!==void 0&&(e.minY=Math.min(e.minY,n.y-10),e.maxY=Math.max(e.maxY,n.y+n.contentHeight+10)))}),w.forEach(n=>{n.path.forEach(t=>{let r=t.y??0;e.maxY=Math.max(e.maxY,r+n.width),e.minY=Math.min(e.minY,r)})}),Xn=e}function oe(e){let n=I.get(P(e)),t=n===void 0?void 0:y[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function bo(){return I=new Map,y.forEach((e,n)=>{e&&I.set(e.name,n)}),I}function go(){let e=y.map(()=>new Set),n=y.map(()=>new Set),t=r=>{for(let o=0;o<r.indexSequence.length-1;o+=1){let s=Math.abs(r.indexSequence[o]),a=Math.abs(r.indexSequence[o+1]);e[s].add(a),n[a].add(s)}};w.forEach(t),B.showReads&&E.length>0&&E.forEach(t),y.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(n[o]))})}function yo(e){let n=0,t=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){C[s]===void 0&&(C[s]=t);let a=C[s];a<r&&(r=a),n=a,t=a-1}else{C[s]===void 0&&(C[s]=n);let a=C[s];n=a+1,t=a}}),r<0&&zn(-r)}function ua(e){let n=0,t=0;for(;n<e.length&&C[Math.abs(e[n])]===void 0;)n+=1;if(n>=e.length)return null;let r=e[n],o,s;r>=0?(o=C[r]-1,s=-1):(o=C[-r]+1,s=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(e[a]);C[l]===void 0&&(C[l]=o,t=Math.min(t,o),o+=s)}return t<0&&zn(-t),n}var da=-1;function fa(e){let n=[];for(let t of e)n.push(t??da);return n}function Fn(){let e,n,t,r,o=0,s=B.showReads&&E.length>0?w.concat(E):w,a={stamp:new Int32Array(y.length),generation:0};C=new Array(y.length).fill(void 0),y.forEach(i=>{i&&(i.order=void 0)}),yo(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Xe&&console.log(`generating order for track ${i+1}`),t=ua(s[i].indexSequence),t===null){s[i].type==="haplotype"?yo(s[i].indexSequence):(s.splice(i,1),E.splice(i-w.length,1),i-=1);continue}for(e=ha(s[i].indexSequence);t<e.length;){for(r=t,t+=1;t<e.length&&C[e[t]]===void 0;)t+=1;if(t<e.length){n=C[e[r]]+1;for(let u=r+1;u<t;u+=1)C[e[u]]=n,n+=1;if(C[e[t]]>C[e[r]])C[e[t]]<n&&Mo(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!pa(e[t],e[r],a))Mo(e[t],e[t-1],n);else if(s[i].indexSequence[r]<0||y[e[r+1]].degree<2&&C[e[t]]<C[e[r]]){n=C[e[r]]-1;for(let u=r+1;u<t;u+=1)C[e[u]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=C[e[r]]+1;for(let u=r+1;u<e.length;u+=1){let f=e[u];C[f]===void 0&&(C[f]=n,n+=1)}}else{n=C[e[r]]-1;for(let u=r+1;u<e.length;u+=1){let f=e[u];C[f]===void 0&&(C[f]=n,o=Math.min(o,n),n-=1)}}}}o<0&&zn(-o);let l=fa(C);C=l,l.forEach((i,u)=>{let f=y[u];f!==void 0&&(f.order=i)})}function pa(e,n,t){t.generation+=1;let{stamp:r,generation:o}=t,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===n)return!0;for(let l of y[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function xo(){let e=-1;return C.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function ha(e){return e.map(n=>Math.abs(n))}function zn(e){C.forEach((n,t)=>{n!==void 0&&(C[t]=n+e)})}function Mo(e,n,t){let r=new Map,o=[[e,t]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=C[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),y[a].successors.forEach(u=>{C[u]>i&&u!==n&&o.push([u,l+1])}),a!==e&&y[a].predecessors.forEach(u=>{C[u]>i&&u!==n&&o.push([u,l+1])}))}r.forEach((a,l)=>{C[l]=a})}function ma(){y.forEach(e=>{e.tracks=[]}),w.forEach(e=>{e.indexSequence.forEach(n=>{y[Math.abs(n)].tracks.push(e.id)})}),y.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function ba(){let e=w[0],n=w.slice(1,w.length);if(B.showReads&&E.length>0&&(n=n.concat(E)),ga(n,e),B.showReads&&E.length>0){for(let t=0;t<E.length;t++)if(E[t]!==n[t+w.length-1])throw new Error("Read inequality")}}function ga(e,n){let t=new Map,r=n?new Set(n.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=P(s[a]),i=oe(l);if(r&&!r.has(l)){let u=a>0?oe(s[a-1]).order:void 0,f=a<s.length-1?oe(s[a+1]).order:void 0;(u===void 0||u<i.order)&&(f===void 0||i.order<f)&&wo(t,l,k(s[a])?1:-1),(u===void 0||u>i.order)&&(f===void 0||i.order>f)&&wo(t,l,k(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=t.get(P(s));l!==void 0&&l>0&&(o.sequence[a]=_o(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=vo(a.seq),a.switched=!0}})}function wo(e,n,t){e.set(n,(e.get(n)??0)+t)}function ya(){let e=0,n=20,t=-1,r=y.slice();r.sort(fn);let o=xa();r.forEach(s=>{s.order>=0&&(s.order>t&&(t=s.order,e=n+10*o[s.order]),s.x=e,n=Math.max(n,e+40+s.pixelWidth))})}function xa(){let e=[],n=[],t=[],r=[];for(let o=0;o<=Q;o+=1)e.push(0),n.push(0),t.push(0);w.forEach(o=>{for(let s=1;s<o.path.length;s+=1){let a=o.path[s],l=o.path[s-1];if(a.order===l.order)a.isForward?e[a.order]=e[a.order]+1:n[a.order]=n[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));t[a.order]=Math.max(i/17.5,t[a.order])}}}),r.push(Math.max(0,e[0]-1));for(let o=1;o<=Q;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function Ma(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=Q;i+=1){ye[i]=[],l[i]=new Map,a[i]=[];for(let u=0;u<w.length;u+=1)a[i][u]=null}w.forEach((i,u)=>{n=Math.abs(i.indexSequence[0]),t=un(i.indexSequence[0]),r=y[n],i.path=[],i.path.push({order:r.order,lane:null,isForward:t,node:n}),X(r.order,n,u,0,a,l),e=1;for(let f=1;f<i.sequence.length;f+=1)if(o=r,s=t,n=Math.abs(i.indexSequence[f]),t=un(i.indexSequence[f]),r=y[n],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),X(o.order,null,u,e,a,l),e+=1);for(let c=o.order+1;c<r.order;c+=1)i.path.push({order:c,lane:null,isForward:!0,node:null}),X(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!0,node:n}),X(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),X(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:n}),X(r.order,n,u,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),X(o.order,null,u,e,a,l),e+=1);for(let c=o.order-1;c>r.order;c-=1)i.path.push({order:c,lane:null,isForward:!1,node:null}),X(c,null,u,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),X(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:n}),X(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:n}),X(r.order,n,u,e,a,l),e+=1)}else t!==s?(i.path.push({order:r.order,lane:null,isForward:t,node:n}),X(r.order,n,u,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!t,node:null}),X(r.order,null,u,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:t,node:n}),X(r.order,n,u,e,a,l),e+=1)});for(let i=0;i<=Q;i+=1)Sa(ye[i],i)}function X(e,n,t,r,o,s){let a={trackID:t,segmentID:r,compareToFromSame:o[e][t]??null},l=n===null?void 0:s[e].get(n);if(l===void 0){let i={type:"single",node:n,tracks:[a]};ye[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function wa(e,n){let t;e.forEach(r=>{r.idealLane=0,r.tracks.forEach(o=>{if(o.segmentID===0)o.idealLane=o.trackID,o.idealY=null;else if(w[o.trackID].path[o.segmentID-1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID-1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID-1].y;else if(o.segmentID<w[o.trackID].path.length-1&&w[o.trackID].path[o.segmentID+1].order===n-1)o.idealLane=w[o.trackID].path[o.segmentID+1].lane??void 0,o.idealY=w[o.trackID].path[o.segmentID+1].y;else{for(t=o.segmentID-1;t>=0&&w[o.trackID].path[t].order!==n-1;)t-=1;t<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=w[o.trackID].path[t].lane??void 0,o.idealY=w[o.trackID].path[t].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Sa(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;wa(e,n),e.sort(Lo),e.forEach(l=>{l.node!==null?(y[l.node].topLane=t,s&&(o-=10),y[l.node].y=o,y[l.node].contentHeight=0,s=!1):(s?o-=25:o>20&&(o-=10),s=!0),l.tracks.sort(Lo),l.tracks.forEach(i=>{i.lane=t,i.trackID===a&&l.node===null&&s&&(o+=10),w[i.trackID].path[i.segmentID].lane=t,w[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),t+=1,o+=w[i.trackID].width,l.node!==null&&(y[l.node].contentHeight+=w[i.trackID].width),a=i.trackID}),o+=25}),La(e,r)}function La(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{So(e,o)<r&&(r=So(e,o),t=o)}),e.forEach(o=>{o.node!==null&&(y[o.node].y+=t),o.tracks.forEach(s=>{let a=w[s.trackID].path[s.segmentID];a.y=a.y+t})})}function Na(e,n){e.order<0||ye[e.order]===void 0||(ye[e.order].forEach(t=>{if(t.node!==null){let r=y[t.node];r!==e&&r.y>e.y&&(r.y+=n,t.tracks.forEach(o=>{let s=w[o.trackID].path[o.segmentID];s.y=s.y+n}))}else t.tracks.forEach(r=>{let o=w[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+n)})}),Ae[e.order].length>0&&Ae[e.order].forEach(t=>{y[t]!==e&&y[t].y>e.y&&(y[t].y+=n)}))}function So(e,n){let t=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&w[o.trackID].type!=="read"&&(t+=Math.abs(o.idealY-n-w[o.trackID].path[o.segmentID].y)*w[o.trackID].width)})}),t}function Lo(e,n){return e.idealLane!==void 0?n.idealLane!==void 0?e.idealLane<n.idealLane?-1:e.idealLane>n.idealLane?1:0:-1:n.idealLane!==void 0?1:0}function fn(e,n){if(!e)return n?-1:0;if(!n)return 1;if(e.order!==void 0){if(n.order!==void 0){if(e.order<n.order)return-1;if(e.order>n.order)return 1;if(e.y!==void 0&&n.y!==void 0){if(e.y<n.y)return-1;if(e.y>n.y)return 1}return 0}return-1}return n.order!==void 0?1:0}function Ra(){let e,n,t={};Hn.forEach(r=>{let o=0;for(;o<w.length&&w[o].name!==r.track;)o+=1;o<w.length&&(e=0,w[o].path.forEach(s=>{s.node!==null&&(t={},n=e+y[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(t.start=0),e<r.start&&n>=r.start&&(t.start=r.start-e),n<=r.end&&n>=r.start&&(t.end=n-e,n<r.end&&(t.continue=!0)),n>r.end&&e<=r.end&&(t.end=r.end-e),t.start!==void 0&&(t.type=r.type,t.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(t)),e=n+1)}))})}function Ea(){let e=!0,n=4,t=B.trackWidth;w.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*n):(r.width=t,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(e=!1)}),e&&w.forEach(r=>{r.freq!==void 0&&(r.width=t)})}function Aa(e){let n=e.path[0],t=y[n.node],r=e.firstNodeOffset??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Ta(e){let n=e.path[e.path.length-1],t=y[n.node],r=e.finalNodeCoverLength??0;return jn(t,n.isForward?r:t.sequenceLength-r)}function Bo(e,n){return n>e.sequenceLength?null:jn(e,n)}function jn(e,n){let[t,r]=_a(e);if(e.sequenceLength===0)return t;let o=Math.min(Math.max(n,0),e.sequenceLength);return t+o/e.sequenceLength*(r-t)}function Ca(){let e,n,t,r,o,s,a,l,i;for(let c=0;c<=Q;c+=1)kn.push(0),Yn.push(0);let u=[],f=[];y.forEach(c=>{c.x!==void 0&&(u[c.order]=c.x,f[c.order]===void 0?f[c.order]=c.x+c.pixelWidth:f[c.order]=Math.max(f[c.order],c.x+c.pixelWidth))}),w.sort(ta),w.forEach(c=>{a="plain",o=Ee(c,a),s=js(c);let d=a,h=()=>(d!==a&&(d=a,o=Ee(c,a)),o);t=c.path[0].y,c.type!=="read"?c.sequence[0].startsWith("-")?e=f[c.path[0].order]+20:e=u[c.path[0].order]-20:e=Aa(c);for(let p=0;p<c.path.length;p+=1)c.path[p].y===t?c.path[p].features!==void 0&&(i=p>0&&c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart):(c.path[p-1].isForward?n=f[c.path[p-1].order]:n=u[c.path[p-1].order],n!==e&&(o=h(),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})),c.path[p].order-1===c.path[p-1].order?(e=n,n=u[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e,yStart:t,xEnd:n+1,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p].order+1===c.path[p-1].order?(e=n,n=f[c.path[p].order],r=c.path[p].y,o=h(),D.curves.push({xStart:e+1,yStart:t,xEnd:n,yEnd:r,width:c.width,color:o,alpha:s,laneChange:Math.abs(c.path[p].lane-c.path[p-1].lane),id:c.id,name:c.name,type:c.type,nodeStart:c.path[p-1]?.node,nodeEnd:c.path[p]?.node}),e=n,t=r):c.path[p-1].isForward?(r=c.path[p].y,Ao(1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=f[c.path[p].order],t=c.path[p].y):(r=c.path[p].y,Ao(-1,n,t,r,c.width,o,c.id,c.path[p].order,c.type,c.name),e=u[c.path[p].order],t=c.path[p].y),c.path[p].features!==void 0&&(i=c.path[p-1].order===c.path[p].order,l=Ro(c.path[p],u[c.path[p].order],f[c.path[p].order],a,c,e,t,o,i),a=l.highlight,e=l.xStart));c.type!=="read"?c.path[c.path.length-1].isForward?n=f[c.path[c.path.length-1].order]+20:n=u[c.path[c.path.length-1].order]-20:n=Ta(c),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+c.width-1,color:o,alpha:s,id:c.id,name:c.name,type:c.type})})}var Ia=1e9;function No(e,n){cn=new Map;let t=new Map,r=B.ignoreStrand;for(let d of e){let h=d.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],b=h[p+1],g=Math.abs(m),M=Math.abs(b),R=y[g],L=y[M];if(!R||!L)continue;let S;if(r){let A=`${m}>${b}`,x=`${-b}>${-m}`;S=A<x?A:x}else S=`${m}>${b}`;let N=t.get(S);N===void 0?t.set(S,{sSigned:m,dSigned:b,sName:m<0?`-${R.name}`:R.name,dName:b<0?`-${L.name}`:L.name,count:1,sourceTrackID:d.sourceTrackID}):N.count+=1}}let o=0;for(let d of t.values())d.count>o&&(o=d.count);let s=dn,a=60,l=d=>o<=1?s:s+(a-s)*Math.sqrt(d/o),i=[],u=0;for(let d of t.values()){let h=Ia+u,p=`${d.count.toLocaleString()} ${n}${d.count===1?"":"s"}: Node ${d.sName} \u2192 Node ${d.dName}`;cn.set(h,{count:d.count,label:p});let m=y[Math.abs(d.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:d.sourceTrackID,type:"read",name:p,sequence:[d.sName,d.dName],indexSequence:[],path:[],width:l(d.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:d.sName,mismatches:[]},{nodeName:d.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:d.count}),u+=1}let f="?",c=0;for(let d of y){if(!d)continue;let h=d.contentHeight;h>c&&(c=h,f=d.name)}return Xe&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${c.toFixed(1)})`),i}function Ro(e,n,t,r,o,s,a,l,i){let u=r,f,c,d,h;n-=8,t+=8;let p=y[e.node].sequenceLength;return e.features.sort((m,b)=>m.start-b.start),e.features.forEach(m=>{u!==m.type&&(f=Ee(o,u),e.isForward?(d=n+Math.round(m.start*(t-n+1)/p),i&&d<n+8&&(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:d,yStart:a,xEnd:h,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),d>s+1&&D.featureRectangles.push({xStart:s,yStart:a,xEnd:d-1,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(d=t-Math.round(m.start*(t-n+1)/p),i&&d>t-8&&(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,c=Ee(o,m.type),D.featureRectangles.push({xStart:h,yStart:a,xEnd:d,yEnd:a+o.width-1,color:c,id:o.id,name:o.name,type:o.type})),s>d+1&&D.featureRectangles.push({xStart:d+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=d,u=m.type),(m.end<p-1||m.continue===void 0)&&(f=Ee(o,u),e.isForward?(h=n+Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:s,yStart:a,xEnd:h,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(h=t-Math.round((m.end+1)*(t-n+1)/p)-1,D.featureRectangles.push({xStart:h,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=h+1,u="plain")}),{xStart:s,highlight:u}}var Eo=7;function Ao(e,n,t,r,o,s,a,l,i,u){let f=e===1?Yn:kn,c=10*f[l],d=n+e*(c+5),h=Eo,p=Math.min(Eo,o),m=Math.min(t,r),b=Math.max(t,r),g=e===1?n:d-1,M=e===1?d:n,R=A=>{D.verticalRectangles.push({xStart:g,yStart:A,xEnd:M,yEnd:A+o-1,color:s,id:a,name:u,type:i})};R(t),D.verticalRectangles.push({xStart:e===1?d+h:d-h-p,yStart:m+o+h-1,xEnd:e===1?d+h+p-1:d-h-1,yEnd:b-h+1,color:s,id:a,name:u,type:i}),R(r);let L=d+e*h,S=d+e*(h+p),N=`M ${d} ${b}`;N+=` Q ${L} ${b} ${L} ${b-h}`,N+=` H ${S}`,N+=` Q ${S} ${b+o} ${d} ${b+o}`,N+=" Z ",D.corners.push({path:N,color:s,id:a,type:i}),N=`M ${d} ${m}`,N+=` Q ${S} ${m} ${S} ${m+o+h}`,N+=` H ${L}`,N+=` Q ${L} ${m+o} ${d} ${m+o}`,N+=" Z ",D.corners.push({path:N,color:s,id:a,type:i}),f[l]+=1}function _a(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function To(){switch(y.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),B.nodeWidthOption){case"compressed":y.forEach(e=>{e.width=1+Math.log(e.sequenceLength)/Math.log(2),e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"small":y.forEach(e=>{e.width=e.sequenceLength/100,e.pixelWidth=Math.round((e.width-1)*8.401)});break;case"fixed":y.forEach(e=>{e.width=10,e.pixelWidth=Math.round(e.width*8.401)});break;case"normal":{let e=B.charWidth;y.forEach(n=>{n.width=n.sequenceLength;let t=n.seq?.length??1;n.pixelWidth=Math.round(e*t)});break}default:throw new Error(`${B.nodeWidthOption} not implemented`)}}function va(){let e,n,t=Array.from(y,()=>new Set),r=Array.from(y,()=>new Set),o;B.showReads&&E.length>0?o=w.concat(E):o=w,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)k(l.sequence[i])?(e=P(l.sequence[i]),i>0?(n=l.sequence[i-1],k(n)?r[I.get(e)].add(P(n)):(r[I.get(e)].add(n),r[I.get(e)].add(pe(n)))):l.type==="haplotype"&&r[I.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],k(n)?t[I.get(e)].add(P(n)):(t[I.get(e)].add(n),t[I.get(e)].add(pe(n)))):l.type==="haplotype"&&t[I.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[I.get(l.sequence[i])].add(e),k(e)&&t[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&t[I.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[I.get(l.sequence[i])].add(e),k(e)&&r[I.get(l.sequence[i])].add(P(e))):l.type==="haplotype"&&r[I.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(B.showReads&&E.length>0){let l=y.slice();l.sort(fn);let i=new Map,u=new Map,f=d=>{let h=i.get(d);if(h===void 0)throw new Error(`No merge offset recorded for node ${d}`);return h},c=d=>{let h=u.get(d);if(h===void 0)throw new Error(`No merge origin recorded for node ${d}`);return h};l.forEach(d=>{let h=He(I.get(d.name),s,a);if(h){let p=f(h)+oe(h).sequenceLength;i.set(d.name,p),i.set(pe(d.name),p),u.set(d.name,c(h)),u.set(pe(d.name),c(h))}else i.set(d.name,0),i.set(pe(d.name),0),u.set(d.name,d.name),u.set(pe(d.name),d.name)}),E.forEach(d=>{let h=d.sequenceNew??[];d.firstNodeOffset=(d.firstNodeOffset??0)+f(d.sequence[0]),d.finalNodeCoverLength=(d.finalNodeCoverLength??0)+f(d.sequence[d.sequence.length-1]);for(let p=d.sequence.length-1;p>=0;p-=1){let m=P(d.sequence[p]),b=He(I.get(m),s,a);if(b&&Wn(I.get(b),s,a))if(p>0){d.sequence.splice(p,1);let g=oe(b).sequenceLength;h[p].mismatches.forEach(M=>{M.pos+=g}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{d.sequence[0]=c(d.sequence[0]);let g=h[0],M=f(g.nodeName);g.mismatches.forEach(R=>{R.pos+=M}),g.nodeName=c(g.nodeName)}}})}for(let l=0;l<y.length;l+=1)if(Wn(l,s,a)&&!He(l,s,a)){let i=l;for(;Wn(i,s,a);)i=I.get(P(a[i][0])),y[l].sequenceLength+=y[i].sequenceLength,y[l].seq+=y[i].seq}w.forEach(l=>{for(let i=l.sequence.length-1;i>=0;i-=1){e=P(l.sequence[i]);let u=I.get(e);He(u,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)He(l,s,a)&&y.splice(l,1)}function He(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=P(n[e][0]),o=I.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function Wn(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=P(t[e][0]),o=I.get(r);return!(n[o].length!==1||n[o][0]==="None")}function Ba(e){let n=B.focusReadNames?new Set(B.focusReadNames):null;return e.filter(t=>t.is_secondary!==!0&&(t.mapping_quality??0)>=B.mappingQualityCutoff&&(n===null||t.name!==void 0&&n.has(t.name)))}function Oa(e,n){let t=new Map;for(let r of e){let o=n(r),s=t.get(o);s===void 0?t.set(o,[r]):s.push(r)}return t}function Pa(e,n){return e.xStart<n.xStart?1:e.xStart>n.xStart?-1:e.yStart>n.yStart?1:e.yStart<n.yStart?-1:0}function Oo(e,n){let t=Oa(e.filter(s=>s.type===n),s=>`${s.nodeStart},${s.nodeEnd}`);t.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(Pa),s.forEach(i=>{let u,f;i.yStart<i.yEnd?(u=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,f=i.xStart+(i.xEnd-i.xStart)*(1-a)):(u=i.xStart+(i.xEnd-i.xStart)*a,a+=l,f=i.xStart+(i.xEnd-i.xStart)*a);let c=`M ${i.xStart} ${i.yStart}`;c+=` C ${u} ${i.yStart} ${u} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,c+=` V ${i.yEnd+i.width}`,c+=` C ${f} ${i.yEnd+i.width} ${f} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,c+=" Z",i.path=c})});let r=Array.from(t.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),u=l[0]??0,f=l[1]??0,c=i[0]??0,d=i[1]??0;return u<c?-1:u>c?1:f<d?-1:f>d?1:0});let o=[];for(let s of r){let a=t.get(s);a!==void 0&&o.push(...a)}return o}function Po(e){let n=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,t=e.x,r=e.y-9;return e.width>1&&(t+=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t+9} ${r} ${t+9} ${r+9}`,t+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,n+=` L ${t} ${r}`),n+=` Q ${t} ${r+9} ${t-9} ${r+9}`,t-=9,r+=9,e.width>1&&(t-=e.pixelWidth,n+=` L ${t} ${r}`),n+=` Q ${t-9} ${r} ${t-9} ${r-9}`,t-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,n+=` L ${t} ${r}`),n}function Ga(e){let n=new Map;for(let[t,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${t}`,a=n.get(s);a?a.push(o.strand):n.set(s,[o.strand])}return n}function Da(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=Ga(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>Le(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=Le(s.name).name,i=new Map,u=s.nodeIds.flatMap(f=>{let c=n.get(f);if(!c)return[];let d=i.get(c.name)??0;i.set(c.name,d+1);let h=t.get(`${l} ${c.name}`)?.[d]??On(c);return[Pn(c,h)]});return u.length>0?[{id:a,name:s.name,sequence:u,sourceTrackID:0,type:"haplotype"}]:[]})}function $a(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function Te(e){return(e.paths?.length??0)>0}var qa=600,Fa=3,Wa=15;function Ha(e){return Math.max(Fa,Math.min(Wa,Math.floor(qa/Math.max(1,e))))}function Go(e){let n=e.paths??[],t=Da(e),r=e.reads?no(e,e.reads,n.length):[],o=r.length>0?mt:ht,s=n.map((l,i)=>o(i,n.length)),a=Io($a(e),t,r,{nodeWidthOption:"compressed",trackWidth:Ha(t.length),trackColor:l=>l.type==="read"?to(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function Vn(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function Do(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function $o(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function qo(e){let n=Te(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of Vn(t))s[i.name]=Do(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=$o(t,o);return{nodePositions:s,tubeMap:{layout:t,yOffset:o,pathColors:r},extent:{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:a,maxY:l}}}function Xa(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of Vn(n)){let i=r.get(l.order);i?i.push(l):r.set(l.order,[l])}let o=[],s=-1/0;for(let l of[...r.keys()].sort((i,u)=>i-u)){let i=r.get(l),u=1/0,f=-1/0;for(let c of i){let d=t.get(c.name);d&&v(d)&&(u=Math.min(u,d.stable.start),f=Math.max(f,d.stable.start+c.sequenceLength))}u===1/0&&(u=f=s),u<s&&(u=s,f=Math.max(s,f)),s=Math.max(s,f),o.push({order:l,x0:Math.min(...i.map(c=>c.x)),x1:Math.max(...i.map(c=>c.x+c.pixelWidth)),bp0:u,bp1:f})}let a=o.find(l=>l.bp0!==-1/0);for(let l of o)l.bp0===-1/0&&(l.bp0=l.bp1=a?.bp0??0);return o}function ka(e){return e.nodes.some(v)&&Te(e)}function Fo(e){let n=ka(e)?Go(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=Xa(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of Vn(t)){let u=s.get(i.order);l[i.name]=Do(i,a,u.bp0,u.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:$o(t,a)}}function Wo(e){let n=ce(e);if(n.length!==0)return{nodePositions:ue(n),referenceAxis:!0,pixelRows:!0}}function Ho(e){return e.sample??Qe(e.name)}function Ya(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Ho(e)}function za(e,n,t,r=!0){if(!t||!r)return{ids:e,complete:!0};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((u,f)=>{let c=n.get(u);c&&(c.end<=t.start&&c.end>a&&(a=c.end,o=f),c.start>=t.end&&c.start<l&&(l=c.start,s=f))}),o<0||s<0)return{ids:e,complete:!1};let i=e.slice(Math.min(o,s)+1,Math.max(o,s));return{ids:o<s?i:i.reverse(),complete:!0}}function Xo(e,n,t){let r=e.paths??[],o=r.find(m=>Le(m.name).name===e.referencePath)??r[0];if(!o||r.length<2)return;let s=new Map(e.nodes.map(m=>[m.id,m.length])),a=e.anchorPaths?.find(m=>m.name===Le(o.name).name)?.start??0,l=n&&n.end>n.start?n:void 0,i=new Map,u=a;for(let m of o.nodeIds){let b=s.get(m)??0;i.has(m)||i.set(m,{start:u,end:u+b}),u+=b}let f=l===void 0||[...i.values()].some(m=>m.end<=l.start)&&[...i.values()].some(m=>m.start>=l.end),c=m=>{let{ids:b,complete:g}=za(m.nodeIds,i,l,f),M=[],R=0,L=0,S=0;for(let N of b){let A=s.get(N)??0,x=i.get(N),T=M.at(-1),_=T?.referenceStart,G=x&&_!==void 0&&S>=0&&_+T.bp===x.start,$=x&&_!==void 0&&S<=0&&x.end===_;!x&&T&&!T.onReference?T.bp+=A:G||$?(T.bp+=A,G||(T.referenceStart=x.start,T.reversed=!0),S=G?1:-1):(M.push({start:R,bp:A,onReference:x!==void 0,referenceStart:x?.start}),S=0),R+=A,x||(L+=A)}return{name:m.name,label:Ya(m),sample:Ho(m),haplotype:m.haplotype,bp:R,offReferenceBp:L,complete:g,runs:M}},d=m=>m.nodeIds.some(b=>i.has(b)),h=new Set(r.filter(m=>m!==o&&d(m)).map(m=>m.name));return{origin:l?l.start:a,unit:t,reference:c(o),rows:r.filter(m=>m!==o&&(d(m)||!h.has(m.name))).map(c).sort((m,b)=>Number(b.complete)-Number(m.complete)||b.bp-m.bp||m.label.localeCompare(b.label))}}var ja=1.3;function Va(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*ja,maxY:e.rows.length*20}}function ko(e,n){let t=ce(e),r=Xo(e,n);if(t.length===0||!r)return;let o=ue(t),s=[{label:r.reference.label,y:0},...r.rows.map((a,l)=>({label:a.label,y:(l+1)*20}))];return{nodePositions:o,rowLabels:s,referenceAxis:!0,pixelRows:!0,extent:Va(r)}}var Ua="Force-directed layout",re=e=>e.nodes.some(v),Yo=e=>re(e)&&(e.paths?.length??0)>1,zo=e=>re(e)&&Te(e),jo=e=>re(e)&&e.nodes.some(Ze),Un=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:ao,cutMargins:!0,available:re,drawsLocally:re},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:fo,cutMargins:!0,available:jo,drawsLocally:jo},{value:"walkrows",label:"Walk rows",description:"x is each walk's own bp: one bar per haplotype, sequence the reference also carries in blue and sequence it does not in purple, so a repeat expansion reads as bar length. Needs W or P lines.",run:ko,cutMargins:!1,available:Yo,drawsLocally:Yo},{value:"ordered",label:"Ordered",description:"x is reference order, not bp: every node gets room, bubbles read as lenses. Needs rGFA tags or a reference path.",run:uo,cutMargins:!1,available:re,drawsLocally:re},{value:"variants",label:"Variant map",description:"The reference as a line with one typed glyph per bubble, from the bubble index or from the graph itself: SNP, indel, deletion, inversion, repeat array. Click a glyph to open the graph inside it.",run:Wo,cutMargins:!0,available:re,drawsLocally:re},{value:"tubemap",label:"Tube map",description:"sequenceTubeMap: every path a coloured tube through boxed nodes, columns in node order and node widths log-scaled. Needs P or W lines.",run:qo,cutMargins:!1,available:Te,drawsLocally:Te},{value:"tubemapref",label:"Tube map on reference",description:"The tube map with each column at the reference bp it covers, so the tubes line up with the tracks around them. Needs P or W lines and a reference path.",run:Fo,cutMargins:!0,available:zo,drawsLocally:zo},{value:"force",label:Ua,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,available:()=>!0,drawsLocally:()=>!1}],tu=Un.map(e=>e.value);function ou(e,n){return!Ka(e).drawsLocally(n)}function Ka(e){return Un.find(n=>n.value===e)??Un[0]}var Y=le(pn(),1);var F=le(pn(),1);function xe(e,n){return(0,F.packAbgr)((0,F.abgrRed)(e),(0,F.abgrGreen)(e),(0,F.abgrBlue)(e),Math.round((0,F.abgrAlpha)(e)*n))}function au(e,n){return(0,F.packAbgr)(Math.min(255,Math.round((0,F.abgrRed)(e)*n)),Math.min(255,Math.round((0,F.abgrGreen)(e)*n)),Math.min(255,Math.round((0,F.abgrBlue)(e)*n)),(0,F.abgrAlpha)(e))}var Uo=new WeakMap;function Ko(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=Uo.get(e);if(l?.graph===n&&l.scaleX===s&&l.scaleY===a&&l.deletions===r&&l.version===o)return l.curves;let i=new Map;for(let u=0;u<n.edges.length;u++){let f=n.edges[u],c=e[f.from],d=e[f.to];if(c?.length&&d?.length){let h=r?.get(u);i.set(u,De(c,d,It(f),0,0,t,h?Rn(e,h):[]))}}return Uo.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var Qa=(0,Y.packAbgr)(119,119,119,217),Qo=(0,Y.packAbgr)(136,136,136,217),Za=(0,Y.packAbgr)(24,24,28,240),Ja=2.2,ei=(0,Y.packAbgr)(30,30,36,245),ni=1.8,Ce=.18,ti=11,oi=1.2,ri=1e-6,si=7,ai=3,ii=3,li=1.5,ci=.5,ui=.45,Kn=12,di=1e-6,he=new Float64Array(64),Me=new Float64Array(64),we=new Float64Array(64);function fi(e,n,t,r){let o=e.length*Kn+1;he.length<o&&(he=new Float64Array(o),Me=new Float64Array(o),we=new Float64Array(o));let s=e[e.length-1];he[0]=s.x1,Me[0]=s.y1,we[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let u=e[i];for(let f=1;f<=Kn&&l<r;f++){let c=1-(f/Kn)**2,d=1-c,h=d*d*d,p=3*d*d*c,m=3*d*c*c,b=c*c*c,g=h*u.x0+p*u.cx0+m*u.cx1+b*u.x1,M=h*u.y0+p*u.cy0+m*u.cy1+b*u.y1;l+=Math.hypot(g-he[a-1],(M-Me[a-1])*t)*n,he[a]=g,Me[a]=M,we[a]=l,a++}}return a}function Zo(e,n){let t=1;for(;t<e-1&&we[t]<n;)t++;let r=we[t-1],o=we[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:he[t-1]+(he[t]-he[t-1])*s,y:Me[t-1]+(Me[t]-Me[t-1])*s}}function pi({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=si+ai*n,u=fi(e,r,o,t+i),f=we[u-1],c=Math.min(t,f),d=f<di?hi(a,r,o):f-c,h=Math.min(1,d/i);if(h<ci)return;let p=Zo(u,c),m=Zo(u,c+i*h),b=p.x-m.x,g=(p.y-m.y)*o,M=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(b,g)>0?Math.atan2(g,b):Ei(M,o,mi(M,l)),length:i*h,halfWidth:(ii+li*n)*h,color:s}}function hi(e,n,t){let r=0;for(let o=1;o<e.length;o++)r+=Math.hypot(e[o].x-e[o-1].x,(e[o].y-e[o-1].y)*t);return r*n}function mi(e,n){if(n.length<2)return;let t=n[0],r=n[n.length-1];return Math.hypot(e.x1-t.x,e.y1-t.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:t,to:n[1]}:{from:r,to:n[n.length-2]}}function bi(e,n=1){let t=n===1?e:e.map(o=>({x:o.x,y:o.y*n})),r=[];for(let o=0;o<t.length;o++){let s=0,a=0;if(o===0){let l=t[1].x-t[0].x,i=t[1].y-t[0].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else if(o===t.length-1){let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i);u>0&&(s=-i/u,a=l/u)}else{let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,u=Math.hypot(l,i),f=t[o+1].x-t[o].x,c=t[o+1].y-t[o].y,d=Math.hypot(f,c);if(u>0&&d>0){let h=-i/u,p=l/u,m=-c/d,b=f/d;s=(h+m)/2,a=(p+b)/2;let g=h*s+p*a;g>.1&&(s/=g,a/=g)}else u>0?(s=-i/u,a=l/u):d>0&&(s=-c/d,a=f/d)}r.push({nx:s,ny:a})}return r}function gi(e,n,t,r=1){return e.map((o,s)=>({x:o.x+n[s].nx*t,y:o.y+n[s].ny*t/r}))}function hn(e,n,t,r){return(0,Y.packAbgr)(Math.round(e*255),Math.round(n*255),Math.round(t*255),Math.round(r*255))}function mn(e,n,t){let r=(1-Math.abs(2*t-1))*n,o=r*(1-Math.abs(e/60%2-1)),s=t-r/2,a=0,l=0,i=0;return e<60?(a=r,l=o):e<120?(a=o,l=r):e<180?(l=r,i=o):e<240?(l=o,i=r):e<300?(a=o,i=r):(a=r,i=o),[a+s,l+s,i+s]}var yi=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],xi=[[237,137,44],[158,42,122]],Mi=[[220,50,50],[50,120,220]];function Qn(e,n){let t=Math.max(0,Math.min(1,n))*(e.length-1),r=Math.min(e.length-2,Math.floor(t)),o=t-r,s=e[r],a=e[r+1];return(0,Y.packAbgr)(Math.round(s[0]+(a[0]-s[0])*o),Math.round(s[1]+(a[1]-s[1])*o),Math.round(s[2]+(a[2]-s[2])*o),255)}function wi(e,n){let[t,r,o]=mn(ft(e),yn,xn);return hn(t,r,o,n)}var Si=300,Li=.7,Ni=.5,nr=[60,65,72],Ri=(0,Y.packAbgr)(...nr,255),gu=`rgb(${nr.join(", ")})`;function yu(e,n){let t=oo(e);if(n&&n.end>n.start)return{start:n.start,span:n.end-n.start,midpoints:t};let r=1/0,o=-1/0;for(let s of t.values())r=Math.min(r,s),o=Math.max(o,s);return{start:r===1/0?0:r,span:o>r?o-r:1,midpoints:t}}function Zn(e){let n=1/0,t=-1/0,r=1/0,o=-1/0,s=0;for(let a of e.nodes)a.stable!==void 0&&a.stable.rank>s&&(s=a.stable.rank),a.depth<n&&(n=a.depth),a.depth>t&&(t=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:n,maxDepth:t,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Jn(e,n,t,r){switch(t){case"random":return wi(e.id,1);case"depth":return Qn(yi,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Qn(Mi,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,Y.packAbgr)(160,160,160,255):e.stable.rank===0?(0,Y.packAbgr)(52,152,219,255):Qn(xi,r.maxRank>1?(e.stable.rank-1)/(r.maxRank-1):0);case"reference-position":{let o=r.referenceRamp,s=o?.midpoints.get(e.id);if(o===void 0||s===void 0)return(0,Y.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Ri;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,u]=mn(a*Si,Li,Ni);return hn(l,i,u,1)}case"grey":return(0,Y.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?n/r.nodeCount*360:0,[s,a,l]=mn(o,.75,.5);return hn(s,a,l,1)}default:return(0,Y.packAbgr)(52,152,219,255)}}function Ei(e,n=1,t){let r=[[e.cx1,e.cy1],[e.cx0,e.cy0],[e.x0,e.y0]];for(let[o,s]of r){let a=e.x1-o,l=(e.y1-s)*n;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return t?Math.atan2((t.to.y-t.from.y)*n,t.to.x-t.from.x):0}function Ai(e,n){let t=!1;for(let r=0;r<e.length-1&&!t;r++){let o=e[r],s=e[r+1];t=Math.max(o.x,s.x)>=n.minX&&Math.min(o.x,s.x)<=n.maxX&&Math.max(o.y,s.y)>=n.minY&&Math.min(o.y,s.y)<=n.maxY}return t}function Ti(e,n){for(let t of e){let r=Math.min(t.x0,t.cx0,t.cx1,t.x1),o=Math.max(t.x0,t.cx0,t.cx1,t.x1),s=Math.min(t.y0,t.cy0,t.cy1,t.y1),a=Math.max(t.y0,t.cy0,t.cy1,t.y1);if(o>=n.minX&&r<=n.maxX&&a>=n.minY&&s<=n.maxY)return!0}return!1}var Jo=new WeakMap;function Ci(e){let n=Jo.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=mn(pt(s,o.length),yn,xn);t.push(hn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},Jo.set(e,n)}return n}var er=new WeakMap,Ii=new Map;function _i(e){let n=er.get(e);if(!n){n=new Map;for(let[t,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=n.get(o);s?s.push(t):n.set(o,[t])}er.set(e,n)}return n}function xu(e){let{nodePositions:n,graph:t,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:u,axis:f,linearLayout:c,viewportBounds:d,referenceRamp:h,deletions:p,hiddenEdges:m,version:b=0}=e,g=i==="depth"?bt(t):0,M=f.scaleX,R=en(f),L=Ko(n,t,f,p,b),S=[],N=new Map,A=[],x=new Map,T=[],_=new Map,G={...Zn(t),referenceRamp:h},$=new Map;if(o==="rainbow")for(let O=0;O<t.nodes.length;O++)$.set(t.nodes[O].id,O);let W=t.paths?.length??0,{pathColorByIndex:H,pathIndexByName:U}=Ci(t),j=O=>H[U.get(O)??-1]??Qo,V=l&&W>1?_i(t):Ii,ke=M>(c?1:ui);for(let O=0;O<t.edges.length;O++){let q=t.edges[O],K=n[q.from],Z=n[q.to],J=L.get(O);if(!K?.length||!Z?.length||!J||m?.has(O))continue;let se=q.pathIds?.length??0,ae=p?.get(O)!==void 0,ie=u?.edgeIndexes.has(O)??!1,ee=a/2*(ae?Ja:1)*(ie?ni:1),me=l&&se>0,ve=ae?Za:Qa,Se=u?ie?ei:xe(ve,Ce):ve,Ye=r.get(q.to),gn=(Ye?Mn(Ye,s,i,g):s)/2,Be=(je,Ve,ne,Pe)=>{let be=je===0&&Ve===0?J:Tt(J,je,Ve);if(d&&!Ti(be,d))return;if(ae)for(let Nr of At(be,ti/M))T.push({curves:Nr,thickness:ee,color:ne});else T.push({curves:be,thickness:ee,color:ne});let at=ke&&Pe!==void 0?pi({curves:be,edgeHalfWidth:ee,nodeHalfWidth:gn,scale:M,yToX:R,color:Pe,fromSegments:K,toSegments:Z}):void 0;at&&A.push(at)},ze=T.length,Oe=A.length;if(!me)Be(0,0,Se,Se);else{let je=Ct(K,Z,se,f),Ve=Math.floor((se-1)/2);for(let ne=0;ne<se;ne++){let Pe=je[ne],be=j(q.pathIds[ne]);Be(Pe.x,Pe.y,u&&q.pathIds[ne]!==u.name?xe(be,Ce):be,ne===Ve?Se:void 0)}}let rt=T.length-ze;rt>0&&_.set(O,{start:ze,count:rt});let st=A.length-Oe;st>0&&x.set(O,{start:Oe,count:st})}for(let[O,q]of Object.entries(n)){let K=r.get(O);if(!K||d&&!Ai(q,d))continue;let Z=Jn(K,$.get(O)??0,o,G),J=u!==void 0&&!u.nodeIds.has(O),se=J?xe(Z,Ce):Z,_e=Mn(K,s,i,g),ae=_e/2,ie=S.length,ee=V.get(O),me=_e/W,ve=q.length>=2;if(ve&&ee?.length&&me>=oi){let Ye=bi(q,R),gn=1/Math.max(M,ri);for(let Be of ee){let ze=(Be-(W-1)/2)*me*gn,Oe=H[Be]??Qo;S.push({points:gi(q,Ye,ze,R),thickness:me/2,color:J?xe(Oe,Ce):Oe})}}else ve&&S.push({points:q,thickness:ae,color:se});let Se=S.length-ie;Se>0&&N.set(O,{start:ie,count:Se})}return{nodeStrokes:S,nodeStrokeRuns:N,arrows:A,arrowRuns:x,edgeCurves:T,edgeCurveRuns:_}}var rr=le(pn(),1);var Ie=10,vi=Ie+8,et=5;function Nu(e,{colorScheme:n,referenceRamp:t,walkNodes:r}){let o={...Zn(e),referenceRamp:t},s=[];return e.nodes.forEach((a,l)=>{if(v(a)){let i=Jn(a,l,n,o);s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,color:(0,rr.abgrToCssRgba)(r&&!r.has(a.id)?xe(i,Ce):i)})}}),s.sort((a,l)=>a.bp0-l.bp0)}function nt(e,n,t){let r=n*e.scale+e.translateX,o=t*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var tr=2;function Bi(e,n,t){let r=-n.translateX/n.scale,o=(t-n.translateX)/n.scale,s=Math.min(r,o),a=Math.max(r,o),l=0,i=0;for(let u of e)l+=Math.max(0,Math.min(u.bp1,s)-u.bp0),i+=Math.max(0,u.bp1-Math.max(u.bp0,a));return n.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function Ru(e,n,t,r){if(r<0||r>Ie+tr)return;let o,s=tr;for(let a of e){let[l,i]=nt(n,a.bp0,a.bp1),u=Math.max(0,l-t,t-i);u<=s&&(s=u,o=a.node)}return o}function Eu(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function or(e,n,t){let r=Ie/2,o=n+t*(et+1);e.moveTo(n+t,r),e.lineTo(o,r-et/1.4),e.lineTo(o,r+et/1.4),e.closePath()}function Au(e,n,t,{width:r,lit:o,darkMode:s}){let a=s?"#ffffff":"#18181c";e.fillStyle=s?"#1f1f1f":"#ffffff",e.fillRect(0,0,r,vi);for(let i of n){let[u,f]=nt(t,i.bp0,i.bp1);f>=0&&u<=r&&(e.fillStyle=i.color,e.fillRect(u,0,Math.max(f-u,1),Ie))}let l=Bi(n,t,r);if((l.left>0||l.right>0)&&(e.beginPath(),l.left>0&&or(e,0,1),l.right>0&&or(e,r,-1),e.fillStyle=a,e.fill(),e.strokeStyle=s?"#1f1f1f":"#ffffff",e.lineWidth=1,e.stroke()),o){let[i,u]=nt(t,o.start,o.end),f=Math.max(u-i,3),c=(i+u)/2-f/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(c,.75,f,Ie-1.5),o.anchor&&(e.beginPath(),e.moveTo(c+f/2,Ie),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function _u(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;n.nodes.forEach(o=>{let s=t.get(o.name);if(o.order>=0&&s&&v(s)){let{refName:a,start:l}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:l,bp1:l+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function tt(e,n,t=!1){let r=0,o=e.length-1;for(;r<o;){let l=r+o>>1,i=e[l].bp1;(t?i<n:i<=n)?r=l+1:o=l}let s=e[r];if(n<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(n,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function ot(e,n,t){let r=tt(e,n),o=tt(e,t,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function vu(e){let n;for(let t of e.values())(!n||t.length>n.length)&&(n=t);return n}var sr=5,Oi=10,Pi=110,Gi=3;function Di(e){return e?"#b0b0b8":"#55555c"}function $i(e){let n=10**Math.floor(Math.log10(e)),t=e/n;return(t<=1?1:t<=2?2:t<=5?5:10)*n}function ar(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+Oi)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function qi(e,n,t,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=n(o.x0),l=n(s.x1),i=s.bp1-o.bp0;if(l<=a||i<=0)return;let u=$i(i/(l-a)*Pi),f=[],c=[];for(let d=Math.ceil(o.bp0/u)*u;d<=s.bp1;d+=u){let h=Math.round(n(tt(e,d)))+.5;if(h>=0&&h<=t){f.push(h);let p=d.toLocaleString("en-US");c.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:f,labels:ar(c)}}function Fi(e,n,t,r){let o=e.map(p=>({box:p,s0:n(p.x0),s1:n(p.x1)})).filter(({s0:p,s1:m})=>m>=0&&p<=t),s=o[0],a=o.at(-1);if(!s||!a)return;let l=(p,m)=>({text:p,at:m,width:r(p)}),i=(p,m)=>l(p.toLocaleString("en-US"),m),u=[],f=[],c=[],d=[];for(let{box:p,s0:m,s1:b}of o){u.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Gi&&f.push(Math.round(b)+.5);let g=l(sn(p.bp1-p.bp0),(m+b)/2);g.width<=b-m&&c.push(g),p!==s.box&&d.push(i(p.bp0,m))}let h=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:u,ticks:f,labels:ar([...h,...c,...d])}}function Wi(e,n,t,r,o=!1){return(o?qi:Fi)(e,n,t,r)}function Bu(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=Wi(n,s,a,c=>e.measureText(c).width,o);if(!i)return;let u=Di(l),f=r+.5;e.strokeStyle=u,e.fillStyle=u,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:c,x1:d}of i.spans)e.moveTo(Math.max(0,c),f),e.lineTo(Math.min(a,d),f);for(let c of i.ticks)e.moveTo(c,r),e.lineTo(c,r+sr);e.stroke();for(let{text:c,at:d}of i.labels)e.fillText(c,d,r+sr+2)}function Gu(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach(o=>{let s=t.get(o.name);o.order>=0&&s&&v(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function Du(e,n,t,r){let o=[];for(let s of e){let a=t(s.x0),l=t(s.x1);l>=0&&a<=r&&o.push({node:s.node,top0:n(s.bp0),top1:n(s.bp1),bottom0:a,bottom1:l})}return o}var Hi=3;function $u(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=Hi;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,u=l.top1+(l.bottom1-l.top1)*o,f=Math.max(0,Math.min(i,u)-t,t-Math.max(i,u));f<a&&(a=f,s=l.node)}return s}function ir(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.top1,0),e.lineTo(n.bottom1,t),e.lineTo(n.bottom0,t),e.closePath()}function lr(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function qu(e,n,t,{highlightNode:r,darkMode:o}){if(t<=0||n.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let l of n)ir(e,l,t);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of n)lr(e,l,t);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=n.find(l=>l.node===r);a&&(e.beginPath(),ir(e,a,t),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),lr(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Xi(e,n){let t=new Map(e.nodes.map(o=>[o.id,o])),r=[];return n.nodes.forEach((o,s)=>{let a=t.get(o.name);if(o.order>=0&&a&&v(a)){let l=a.stable.start;r.push({bp0:l,bp1:l+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function ki(e,n,t){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=n?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&t.has(s.index)&&s.bp0<=n&&n<=s.bp1)}function Hu(e,n,t){let r=Xi(e,n),o=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let l=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!l.has(i.node)&&l.set(i.node,i.y);for(let i of a){let u=ki(r,i.start,l);if(u){let{node:f,bp0:c,bp1:d}=u,h=p=>f.x+(Math.min(p,d)-c)/(d-c)*f.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(u.index),height:s.width})}}}}return o}function Yi(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Xu(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=Yi(s),e.beginPath();for(let a of n){let l=t(a.x0),i=Math.max(t(a.x1),l+1);if(i>=0&&l<=o){let u=r(a.y);e.rect(l,u,i-l,r(a.y+a.height)-u)}}e.fill()}}function zi(e,n){let t=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=n.nodeMap.get(P(o.nodeName)),l=a===void 0?void 0:n.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let u=e.path[i]?.y;if(l&&u!==void 0){let f={readId:e.id,y:u,height:e.width,nodeY:l.y},c=d=>Bo(l,d);for(let d of o.mismatches){let h=c(d.pos);if(h!==null){if(d.type==="insertion"){let p=s===0&&d.pos===e.firstNodeOffset||s===r.length-1&&d.pos===e.finalNodeCoverLength;t.push({...f,kind:"insertion",x:h,seq:d.seq,softClip:p})}else if(d.type==="deletion"&&d.length!==void 0){let p=c(d.pos+d.length);p!==null&&t.push({...f,kind:"deletion",x0:h,x1:p})}else if(d.type==="substitution"&&d.seq!==void 0){let p=c(d.pos+d.seq.length);p!==null&&t.push({...f,kind:"substitution",x0:h,x1:p,seq:d.seq})}}}}}),t}function cr(e){return e.reads.flatMap(n=>zi(n,e))}function mr(e){let n=e.trim().split(/[\s,]+/),t=[],r=0,o=()=>Number(n[r++]);for(;r<n.length;){let s=n[r++];s==="M"||s==="L"?t.push({op:s,x:o(),y:o()}):s==="H"?t.push({op:s,x:o()}):s==="V"?t.push({op:s,y:o()}):s==="Q"?t.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?t.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&t.push({op:s})}return t}function br(e){let n=1/0,t=-1/0;for(let r of e)"x"in r&&(n=Math.min(n,r.x),t=Math.max(t,r.x)),"x1"in r&&(n=Math.min(n,r.x1),t=Math.max(t,r.x1));return{x0:n,x1:t}}function ur(e,n,t){let r=mr(e);return{commands:r,color:n,alpha:t,...br(r)}}function dr(e,n){let{shapes:t}=e,r=[...t.rectangles,...t.verticalRectangles].filter(a=>a.type===n).map(a=>({color:a.color,alpha:a.alpha??1,x0:a.xStart,x1:a.xEnd+1,y0:a.yStart,y1:a.yEnd+1})),o=Oo(t.curves,n).map(a=>ur(a.path,a.color,a.alpha??1)),s=t.corners.filter(a=>a.type===n).map(a=>ur(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function Uu(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=mr(Po(t));n.push({name:t.name,commands:r,...br(r)})}}),{bounds:e.bounds,layers:[dr(e,"haplotype"),dr(e,"read")],nodes:n,mismatches:cr(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function fr(e,n,t,r){let o=0,s=0;for(let a of n)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(t(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(t(o),r(s));break;case"H":o=a.x,e.lineTo(t(o),r(s));break;case"V":s=a.y,e.lineTo(t(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(t(a.x1),r(a.y1),t(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(t(a.x1),r(a.y1),t(a.x2),r(a.y2),t(o),r(s));break;case"Z":e.closePath();break}}function pr(e,n,t,r){let o=new Map;for(let s of n)if(t(s)){let a=`${s.color}|${s.alpha}`,l=o.get(a);l?l.push(s):o.set(a,[s])}for(let s of o.values()){e.fillStyle=s[0].color,e.globalAlpha=s[0].alpha,e.beginPath();for(let a of s)r(a);e.fill()}e.globalAlpha=1}var ji=12,Vi=.15;function Ui(e){return Math.max(Vi,Math.min(1,e/ji))}function Ku(e,n,t){let{x:r,y:o,width:s}=t,a=u=>r(u.x1)>=0&&r(u.x0)<=s;for(let u of n.layers)pr(e,u.rects,a,f=>{let c=r(f.x0),d=o(f.y0);e.rect(c,d,r(f.x1)-c,o(f.y1)-d)}),pr(e,u.shapes,a,f=>{fr(e,f.commands,r,o)});let l=t.darkMode?"#d0d0d0":"#000000",i=t.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,t.yScale));for(let u of n.nodes)if(a(u)){let f=u.name===t.highlightNode;e.beginPath(),fr(e,u.commands,r,o),e.fillStyle=f?"rgba(255,192,203,0.5)":i,e.strokeStyle=f?"#ff0000":l,e.fill(),e.globalAlpha=f?1:Ui(r(u.x1)-r(u.x0)),e.stroke(),e.globalAlpha=1}Zi(e,n.mismatches,t)}var gr=12,Ki=6;function Qi(e){return gr*e>=Ki}function hr(e,{x:n,width:t}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return n(o)>=0&&n(r)<=t}function Zi(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!Qi(s)||n.length===0)return;let l=gr*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&hr(i,t)){let u=r(i.x0),f=o(i.y);e.rect(u,f,r(i.x1)-u,o(i.y+i.height)-f)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of n)hr(i,t)&&(i.kind==="substitution"?e.fillText(i.seq,r(i.x0)+1,o(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",r(i.x)-3,o(i.y+i.height)))}function Ju(e,n){let t=[];for(let r of n){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let l=Math.max(r.start,s.bp0),i=Math.min(r.end,a.bp1);i<=l||t.push({gene:r,...ot(o,l,i),exons:r.exons.filter(u=>u.end>l&&u.start<i).map(u=>ot(o,Math.max(u.start,l),Math.min(u.end,i)))})}return t}var yr=22,Ji=4,bn=8,el="11px sans-serif",nl=8;function ed(e){let n=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),t=0,r=0;for(let{step:o}of n)t+=o,r=Math.max(r,t);return Math.min(Ji,r)}function nd(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/yr)),u=[],f=l?"#e0e0e6":"#1c1c22";e.font=el,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let c=n.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:h})=>h>=0&&d<=a).sort((d,h)=>d.s0-h.s0);for(let{g:d,s0:h,s1:p}of c){let m=d.gene.strand>0?" \u2192":d.gene.strand<0?"\u2190 ":"",b=d.gene.strand<0?`${m}${d.gene.name}`:`${d.gene.name}${m}`,g=(Math.max(h,0)+Math.min(p,a))/2,M=e.measureText(b).width/2,R=Math.min(h,g-M),L=Math.max(p,g+M),S=u.findIndex(A=>A+nl<=R);S===-1&&(S=Math.min(u.length,i-1)),u[S]=Math.max(u[S]??-1/0,L);let N=r-S*yr-bn/2;e.beginPath(),e.moveTo(h,N+.5),e.lineTo(p,N+.5),e.stroke();for(let A of d.exons){let x=s(A.x0);e.fillRect(x,N-bn/2,Math.max(1,s(A.x1)-x),bn)}e.fillText(b,g,N-bn/2-2)}}function ol(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function rl(e,n){let t=e.length,r=n.length,o=Array.from({length:t+1},()=>new Array(r+1).fill(0)),s=Array.from({length:t+1},()=>new Array(r+1).fill(!1));for(let l=t-1;l>=0;l--)for(let i=r-1;i>=0;i--){let u=Math.abs(e[l]-n[i])+o[l+1][i+1],f=t-l>r-i?o[l+1][i]:1/0,c=r-i>t-l?o[l][i+1]:1/0;o[l][i]=Math.min(u,f,c),s[l][i]=o[l][i]===u}let a=new Array(t).fill(void 0);for(let l=0,i=0;l<t&&i<r;)s[l][i]?a[l++]=i++:t-l>r-i?l++:i++;return a}function Mr(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var Sr=e=>e.spanningReads!==0;function wr(e,n){return{...n,agrees:e.complete&&Sr(n)?ol(e.bp,n.bp):void 0}}function sl(e,n){let t=new Map,r=new Set;e.forEach((l,i)=>{let u=n.find(f=>f.haplotype!==void 0&&f.haplotype===l.haplotype);u&&(r.add(u),t.set(i,wr(l,u)))});let o=n.filter(l=>l.haplotype===void 0),s=Mr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Sr)],[s,o]];for(let[l,i]of a){let u=l.filter(c=>!t.has(c.i)),f=Mr(i.filter(c=>!r.has(c)),c=>c.bp);rl(u.map(c=>c.item.bp),f.map(c=>c.item.bp)).forEach((c,d)=>{if(c!==void 0){let h=u[d],p=f[c].item;r.add(p),t.set(h.i,wr(h.item,p))}})}return t}function rd(e,n){if(!n)return e;let t=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=n[o];if(a)for(let[l,i]of sl(s,a))t.set(s[l],i)}return e.map(o=>({...o,call:t.get(o)}))}var Lr=le(Ke(),1),id=(0,te.createSvgIcon)((0,Lr.jsx)("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"}),"Settings");export{te as a,Ms as b,pn as c,ge as d,Jl as e,ec as f,nc as g,tc as h,ul as i,Et as j,Tt as k,en as l,Ct as m,Ws as n,hl as o,gl as p,yl as q,xl as r,qt as s,sn as t,ls as u,Ht as v,Cl as w,Xo as x,Va as y,Fe as z,vs as A,On as B,Ts as C,Cs as D,Ga as E,Un as F,tu as G,ou as H,Ka as I,au as J,Ko as K,Si as L,gu as M,yu as N,xu as O,vi as P,Nu as Q,Bi as R,Ru as S,Eu as T,Au as U,_u as V,vu as W,Di as X,Bu as Y,Gu as Z,Du as _,$u as $,qu as aa,Hu as ba,Yi as ca,Xu as da,Uu as ea,Ku as fa,Qi as ga,hr as ha,Ju as ia,yr as ja,ed as ka,nd as la,tl as ma,rd as na,Bl as oa,Ol as pa,bs as qa,Pl as ra,Gl as sa,vn as ta,Vl as ua,Ul as va,id as wa};
|
|
2
|
+
//# sourceMappingURL=chunk-NMCXEYLU.js.map
|