jbrowse-plugin-graphgenomeviewer 4.0.12 → 4.0.13

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.
Files changed (61) hide show
  1. package/README.md +21 -5
  2. package/dist/chunks/GbzBaseSyntenyAdapter-Y5NBXK7P.js +8 -0
  3. package/dist/chunks/{GbzBaseSyntenyAdapter-5ZQ2IPHJ.js.map → GbzBaseSyntenyAdapter-Y5NBXK7P.js.map} +3 -3
  4. package/dist/chunks/{GraphGenomeView-SRR7EJFX.js → GraphGenomeView-TTQEJJQD.js} +2 -2
  5. package/dist/chunks/{GraphGenomeView-SRR7EJFX.js.map → GraphGenomeView-TTQEJJQD.js.map} +1 -1
  6. package/dist/chunks/GraphTrackSettingsDialog-3A2PKZRI.js +4 -0
  7. package/dist/chunks/{GraphTrackSettingsDialog-LZITZ3VD.js.map → GraphTrackSettingsDialog-3A2PKZRI.js.map} +1 -1
  8. package/dist/chunks/LinearGraphDisplay-MJ5XZFE5.js +2 -0
  9. package/dist/chunks/{LinearGraphDisplay-J3KVTK4C.js.map → LinearGraphDisplay-MJ5XZFE5.js.map} +1 -1
  10. package/dist/chunks/{MinigraphBubbleAdapter-QTXGK7DW.js → MinigraphBubbleAdapter-APC7JYOM.js} +2 -2
  11. package/dist/chunks/{RgfaTabixAdapter-O3ERR2GY.js → RgfaTabixAdapter-4E365PXO.js} +2 -2
  12. package/dist/chunks/{chunk-LGGAXAS6.js → chunk-5DP7IXD3.js} +2 -2
  13. package/dist/chunks/chunk-CJ56O2VG.js +2 -0
  14. package/dist/chunks/chunk-CJ56O2VG.js.map +7 -0
  15. package/dist/chunks/chunk-EFVAQ2KM.js +2 -0
  16. package/dist/chunks/chunk-EFVAQ2KM.js.map +7 -0
  17. package/dist/chunks/chunk-IFRDWMQ2.js +2 -0
  18. package/dist/chunks/chunk-IFRDWMQ2.js.map +7 -0
  19. package/dist/chunks/chunk-JAQ2RQAE.js +2 -0
  20. package/dist/chunks/{chunk-QRVREF7H.js.map → chunk-JAQ2RQAE.js.map} +4 -4
  21. package/dist/chunks/{chunk-WETM2CD7.js → chunk-LA7MQS33.js} +2 -2
  22. package/dist/chunks/chunk-M4YEAXSR.js +2 -0
  23. package/dist/chunks/chunk-M4YEAXSR.js.map +7 -0
  24. package/dist/chunks/chunk-XDOIZTY6.js +4 -0
  25. package/dist/chunks/chunk-XDOIZTY6.js.map +7 -0
  26. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
  27. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  28. package/package.json +3 -3
  29. package/src/GraphGenomeView/components/GraphCanvas.tsx +4 -11
  30. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +117 -4
  31. package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +261 -44
  32. package/src/GraphGenomeView/components/referenceRampCss.test.ts +27 -0
  33. package/src/GraphGenomeView/components/referenceRampCss.ts +39 -0
  34. package/src/GraphGenomeView/genes/genes.test.ts +9 -2
  35. package/src/GraphGenomeView/host.test.ts +25 -2
  36. package/src/GraphGenomeView/host.ts +9 -7
  37. package/src/GraphGenomeView/model.test.ts +383 -4
  38. package/src/GraphGenomeView/model.ts +413 -88
  39. package/src/GraphGenomeView/repeats/repeatFeatures.test.ts +75 -0
  40. package/src/GraphGenomeView/repeats/repeatFeatures.ts +156 -8
  41. package/src/GraphGenomeView/repeats/walkCalls.test.ts +18 -0
  42. package/src/GraphGenomeView/repeats/walkCalls.ts +35 -18
  43. package/src/GraphGenomeView/subgraphLoad.test.ts +1 -0
  44. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +165 -6
  45. package/src/LinearGraphDisplay/model.ts +61 -1
  46. package/src/gaf/gafFile.test.ts +18 -0
  47. package/src/version.ts +1 -1
  48. package/dist/chunks/GbzBaseSyntenyAdapter-5ZQ2IPHJ.js +0 -8
  49. package/dist/chunks/GraphTrackSettingsDialog-LZITZ3VD.js +0 -4
  50. package/dist/chunks/LinearGraphDisplay-J3KVTK4C.js +0 -2
  51. package/dist/chunks/chunk-ADEBM7AA.js +0 -2
  52. package/dist/chunks/chunk-ADEBM7AA.js.map +0 -7
  53. package/dist/chunks/chunk-J7CABMMI.js +0 -2
  54. package/dist/chunks/chunk-J7CABMMI.js.map +0 -7
  55. package/dist/chunks/chunk-LBHU3DHN.js +0 -4
  56. package/dist/chunks/chunk-LBHU3DHN.js.map +0 -7
  57. package/dist/chunks/chunk-QRVREF7H.js +0 -2
  58. /package/dist/chunks/{MinigraphBubbleAdapter-QTXGK7DW.js.map → MinigraphBubbleAdapter-APC7JYOM.js.map} +0 -0
  59. /package/dist/chunks/{RgfaTabixAdapter-O3ERR2GY.js.map → RgfaTabixAdapter-4E365PXO.js.map} +0 -0
  60. /package/dist/chunks/{chunk-LGGAXAS6.js.map → chunk-5DP7IXD3.js.map} +0 -0
  61. /package/dist/chunks/{chunk-WETM2CD7.js.map → chunk-LA7MQS33.js.map} +0 -0
@@ -1,2 +0,0 @@
1
- import{c as tn}from"./chunk-VAGPKHHS.js";import{c as Jt}from"./chunk-SCMIJAAX.js";import{A as rn,E as sn,F as mt,a as ve,b as P,c as Ue,d as le,e as ce,f as en,h as Qe,q as Le,u as nn,v as on,w as pt,x as ht}from"./chunk-ADEBM7AA.js";import{a as Ke,b as Qt,c as Zt}from"./chunk-MUK3KYB4.js";import{a as Ve}from"./chunk-XEJ47DLD.js";import{a as je,b as ge}from"./chunk-FY3BTKY4.js";var ln=je((wi,an)=>{an.exports=JBrowseExports["@mui/material/SvgIcon"]});var At=je((ki,$n)=>{$n.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var qs=je((Cl,Zn)=>{Zn.exports=JBrowseExports.mobx});var bi=je((Wc,Jo)=>{Jo.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var ne=ge(ln(),1);function Ei(e){let t=n=>Math.round(n*100)/100;return e.map((n,r)=>`${r?"L":"M"}${t(n.x)},${t(n.y)}`).join("")}function cn(e,t,n,r,o){let s=Math.hypot(r-t,n-e);if(s===0)return[n,r];let a=(n-e)/s,l=(r-t)/s;return[n+o*a,r+o*l]}function xt(e,t){let n=1-t,r=n*n*n,o=3*n*n*t,s=3*n*t*t,a=t*t*t;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 mn(e){let t=e[Math.floor(e.length/2)];return t?xt(t,.5):void 0}function gn(e){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let s of e)t=Math.min(t,s.x0,s.cx0,s.cx1,s.x1),r=Math.max(r,s.x0,s.cx0,s.cx1,s.x1),n=Math.min(n,s.y0,s.cy0,s.cy1,s.y1),o=Math.max(o,s.y0,s.cy0,s.cy1,s.y1);return{minX:t,minY:n,maxX:r,maxY:o}}function rr(e,t,n){let r=xt(e,t),o=xt(e,n),s=(n-t)/3,a=dn(e,t),l=dn(e,n);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 dn(e,t){let n=1-t,r=3*n*n,o=6*n*t,s=3*t*t;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 bn(e,t){let n=[];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/t)|1);for(let a=0;a<s;a+=2)n.push([rr(r,a/s,(a+1)/s)])}return n}function yn(e,t,n){let r=new Array(e.length);for(let o=0;o<e.length;o++){let s=e[o];r[o]={x0:s.x0+t,y0:s.y0+n,cx0:s.cx0+t,cy0:s.cy0+n,cx1:s.cx1+t,cy1:s.cy1+n,x1:s.x1+t,y1:s.y1+n}}return r}function gt(e,t){let n=e.length-1;return t==="end"?{at:e[n],inward:e[n-1]}:{at:e[0],inward:e[1]}}var sr=.5,ar=80;function un(e){let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.x),n=Math.max(n,r.x);return{min:t,max:n}}function fn(e,t){return Math.max(0,t.min-e,e-t.max)}function pn(e,t,n){let r=fn(e[0].x,t),o=fn(e[e.length-1].x,t);return r===o?n:r<o?"start":"end"}function ir(e,t){return{from:pn(e,un(t),"end"),to:pn(t,un(e),"start")}}var lr=.75,cr=1.15,dr=.35,ur=60;function fr(e,t,n,r,o,s){let a=Math.hypot(n-e,r-t),l=a===0?1:(n-e)/a,i=a===0?0:(r-t)/a,c=0,f=1/0,d=-1/0;for(let m of o){let g=m.x-e,b=m.y-t,x=g*-i+b*l;Math.abs(x)>Math.abs(c)&&(c=x);let E=g*l+b*i;f=Math.min(f,E),d=Math.max(d,E)}let u=o.length?d-f:0,h=Math.max(Math.abs(c)*cr/lr,u*dr),p=s===void 0?h:Math.min(h,s);return c<0?-p:p}function Ze({scaleX:e,scaleY:t}){return t/e}var pr=3;function bt(e,t,n){let r=t.x-e.x,o=(t.y-e.y)*n,s=Math.hypot(r,o);return s===0?void 0:{x:r/s,y:o/s}}function xn(e,t,n,r,o=pr){let s=Ze(r),a=bt(e[e.length-1],t[0],s)??bt(e[0],e.at(-1),s)??bt(t[0],t.at(-1),s)??{x:1,y:0},l=[];for(let i=0;i<n;i++){let c=(i-(n-1)/2)*o;l.push({x:-a.y*c,y:a.x*c/s})}return l}function yt(e,t){return e.map(n=>({x:n.x,y:n.y*t}))}function hr(e,t){for(let n of e)n.y0/=t,n.cy0/=t,n.cy1/=t,n.y1/=t;return e}var mr=12,gr=40;function hn(e,t){let n=0;for(let s=1;s<e.length;s++)n+=Math.hypot(e[s].x-e[s-1].x,e[s].y-e[s-1].y);let r=n*t;return Math.min(gr,Math.max(mr,r/2))/Math.max(t,Number.EPSILON)}function Mn(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function br(e,t,n,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,c=a/i,f=l/i,d=o.x+n,u=o.y+r,h=d+c*t/3,p=u+f*t/3,m=d+c*t,g=u+f*t,b=-f*t/2,x=c*t/2;return[{x0:d,y0:u,cx0:h,cy0:p,cx1:m+b,cy1:g+x,x1:m,y1:g},{x0:m,y0:g,cx0:m-b,cy0:g-x,cx1:h,cy1:p,x1:d,y1:u}]}function Be(e,t,n,r,o,s,a=[],l){let i=s.scaleX,c=Ze(s),f=l??(s.pixelRows?ur:void 0);if(c!==1)return hr(Be(yt(e,c),yt(t,c),n,r,o*c,{scaleX:i,scaleY:i},yt(a,c),f===void 0?void 0:f*c),c);if(typeof n=="string")return br(gt(e,n),hn(e,i),r,o);let d=n?{from:"end",to:"start"}:ir(e,t),u=gt(e,d.from),h=gt(t,d.to),p=u.at,m=h.at,g=p.x+r,b=p.y+o,x=m.x+r,E=m.y+o;if(n){let L=1,N=0;if(u.inward){let K=p.x-u.inward.x,j=p.y-u.inward.y,V=Math.hypot(K,j);V>0&&(L=K/V,N=j/V)}let R=hn(e,i),M=-N,A=L,_=(p.x+m.x)/2+r+M*R,B=(p.y+m.y)/2+o+A*R,k=g+L*R,W=b+N*R,q=x-L*R,F=E-N*R;return[{x0:g,y0:b,cx0:k,cy0:W,cx1:k+M*R,cy1:W+A*R,x1:_,y1:B},{x0:_,y0:B,cx0:q+M*R,cy0:F+A*R,cx1:q,cy1:F,x1:x,y1:E}]}else{let L=u.inward??{x:p.x-(m.x-p.x),y:p.y-(m.y-p.y)},N=h.inward??{x:m.x-(p.x-m.x),y:m.y-(p.y-m.y)},R=Math.hypot(x-g,E-b),M=(Z,J,se,Ie)=>{let ae=J.x-Z.x,ie=J.y-Z.y,ee=Math.hypot(ae,ie),he=ee===0?0:(se*ae+Ie*ie)/ee;return Math.max(0,Math.min(R*sr,ar,he*.5))},A=m.x-p.x,_=m.y-p.y,[B,k]=cn(L.x,L.y,p.x,p.y,M(L,p,A,_)),[W,q]=cn(N.x,N.y,m.x,m.y,M(N,m,-A,-_)),F=a.length?fr(g,b,x,E,a,f):0,K=R===0?1:R,j=(x-g)/K,V=(E-b)/K,We=-V*F,O=j*F,$=j*Math.abs(F),U=V*Math.abs(F);return[{x0:g,y0:b,cx0:B+r+We-$,cy0:k+o+O-U,cx1:W+r+We+$,cy1:q+o+O+U,x1:x,y1:E}]}}var yr=1;function Mt(e,t){return t.flatMap(n=>e[n]??[])}function wn(e,t,n){let r=e[t.from],o=e[t.to];return r?.length&&o?.length?Be(r,o,t.from===t.to,0,0,n,Mt(e,t.bypassed)):void 0}function xr(e){let t=new Map;for(let n of e.nodes)if(P(n)){let r=t.get(n.stable.refName);r?r.push(n):t.set(n.stable.refName,[n])}for(let n of t.values())n.sort((r,o)=>r.stable.start-o.stable.start);return t}function Mr(e,t,n){let r=[];if(e)for(let o=en(e,t);o<e.length;o++){let s=e[o];if(s.stable.start>=n)break;s.stable.start+s.length<=n&&r.push(s.id)}return r}function wr(e,t,n,r){let{fromStrand:o,toStrand:s}=e;if(o===void 0||s===void 0)return!0;let a=o===(t.stable.strand??"+"),l=s===(n.stable.strand??"+");return r?a&&l:!a&&!l}function Ci(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=xr(e),r=[];for(let o=0;o<e.edges.length;o++){let s=e.edges[o],a=t.get(s.from),l=t.get(s.to);if(a!==void 0&&l!==void 0&&P(a)&&P(l)&&a.stable.refName===l.stable.refName){let i=a.stable.start<=l.stable.start,[c,f]=i?[a,l]:[l,a],d=c.stable.start+c.length,u=f.stable.start,h=u-d;if(h>=yr&&wr(s,a,l,i)){let p=c.stable.refName;r.push({edgeIndex:o,from:s.from,to:s.to,refName:p,start:d,end:u,bp:h,bypassed:Mr(n.get(p),d,u)})}}}return r}function Ne(e){return e.endsWith("-")?"-":"+"}function Ln(e){return e==="+"?"-":"+"}function Lr(e){let t=(e.fromStrand??Ne(e.from))===Ne(e.from)?"end":"start",n=(e.toStrand??Ne(e.to))===Ne(e.to)?"start":"end";return{from:t,to:n}}function Oi(e){let t=e.edges.map(Lr),n=new Map,r=(u,h,p)=>{let m=`${u}|${h}`,g=n.get(m);g?g.push(p):n.set(m,[p])};e.edges.forEach((u,h)=>{r(u.from,t[h].from,h),r(u.to,t[h].to,h)});let o=u=>{let h=n.get(`${u}|end`);if(h?.length!==1)return;let p=h[0],m=e.edges[p];return m.from===u&&m.to!==u&&t[p].from==="end"&&t[p].to==="start"&&n.get(`${m.to}|start`)?.length===1?p:void 0},s=new Set,a=new Map,l=new Map;for(let u of e.nodes){let h=n.get(`${u.id}|start`),p=h?.length===1?e.edges[h[0]].from:void 0;if(a.has(u.id)||p!==void 0&&o(p)===h[0])continue;let m=[u.id];for(;;){let g=o(m.at(-1)),b=g===void 0?void 0:e.edges[g].to;if(b===void 0||a.has(b))break;s.add(g),m.push(b)}for(let g of m)a.set(g,u.id);m.length>1&&l.set(u.id,m)}for(let u of e.nodes)a.has(u.id)||a.set(u.id,u.id);let i=new Map(e.nodes.map(u=>[u.id,u])),c=[];for(let u of e.nodes){if(a.get(u.id)!==u.id)continue;let h=l.get(u.id);if(!h){c.push(u);continue}let p=h.map(b=>i.get(b)),m=p.filter(P),g=m.length?m.reduce((b,x)=>b.stable.start<=x.stable.start?b:x):p[0];c.push({id:u.id,name:u.name,length:p.reduce((b,x)=>b+x.length,0),depth:u.depth,stable:g.stable})}let f=new Set,d=[];return e.edges.forEach((u,h)=>{let p=a.get(u.from),m=a.get(u.to),g=t[h],b=`${p}|${g.from}>${m}|${g.to}`;s.has(h)||f.has(b)||(f.add(b),d.push({from:p,to:m,...g.from==="start"?{fromStrand:Ln(Ne(p))}:{},...g.to==="end"?{toStrand:Ln(Ne(m))}:{}}))}),{graph:{...e,nodes:c,edges:d,paths:void 0,pathVisits:void 0},runs:l}}function vi(e,t,n){let r={...e};for(let[o,s]of t){let a=e[o];if(!a?.length)continue;delete r[o];let l=Lt(a),i=l.at(-1),c=s.map(u=>Math.max(n(u),0)),f=c.reduce((u,h)=>u+h,0)||s.length,d=0;s.forEach((u,h)=>{let p=f?c[h]/f*i:i/s.length,m=h===s.length-1?i:d+p;r[u]=Sn(a,l,d,m),d=m})}return r}function Bi(e,t,n){if(e.length===0)return[];let r=Lt(e),o=r.at(-1);return Sn(e,r,t*o,n*o)}function Nn(e){let t=Lt(e);return wt(e,t,t.at(-1)/2)}function Lt(e){let t=[0];for(let n=1;n<e.length;n++)t.push(t[n-1]+Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y));return t}function wt(e,t,n){if(n<=0)return{...e[0]};let r=1;for(;r<t.length&&t[r]<n;)r++;if(r>=t.length)return{...e.at(-1)};let o=t[r]-t[r-1],s=o>0?(n-t[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 Sn(e,t,n,r){let o=[wt(e,t,n)];for(let s=0;s<e.length;s++)t[s]>n&&t[s]<r&&o.push({...e[s]});return o.push(wt(e,t,r)),o}function Nt(e){return e.length*6.2+8}function Nr(e,t){return e.x0<t.x1&&e.x1>t.x0&&e.y0<t.y1&&e.y1>t.y0}function En(e,t){return e.x1<=0||e.x0>=t.width||e.y1<=0||e.y0>=t.height}function Sr(e,t){return e.x0>=0&&e.x1<=t.width&&e.y0>=0&&e.y1<=t.height}function St(e,t=[]){let n=[...t];return r=>En(r,e)||n.some(o=>Nr(o,r))?!1:(n.push(r),!0)}function Pe(e,t,n){let r=[];for(let s of e){let a=Nt(s.text),l=s.y>t.height/2?-1:1;for(let i=0;i<=(s.stack??0);i++){let c=s.y+l*i*19,f={x0:s.x-a/2,x1:s.x+a/2,y0:c-11-4,y1:c+4};if(En(f,t))break;if(Sr(f,t)&&n(f)){r.push({...s,y:c,w:a});break}}}return r}var Er=26,Rr=4e4,Ar=8,Ir=8,Cr=5.7,Tr=6,_r=13,Ge=3,Je=2;function nt(e){return(e.length*Cr+Tr+Ge)/2}var de=(_r+Ge)/2,Or=nt("1 bp");function et(e,t,n){return{x0:t-e,x1:t+e,y0:n-de,y1:n+de}}function Cn(e,t){return{x0:6,x1:6+e.length*6.2+8+Ge,y0:t-8-Ge/2,y1:t+8+Ge/2}}function tt(e,t,n){return n<t?e:Math.min(Math.max(e,t),n)}function Tn(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:e>=1e3?`${+(e/1e3).toFixed(1)} kb`:`${e} bp`}function Rn(e){return`${Tn(e)} del`}function vr(e,t,n,r){let o=e[0],s=e[e.length-1],a=(t.x-(o.x0+s.x1)/2)*n,l=(t.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 Br(e,t){return Math.abs(t.x)*(e.x1-e.x0)/2+Math.abs(t.y)*(e.y1-e.y0)/2}function Pr(e,t){let n=(e.x1-e.x0)/2,r=(e.y1-e.y0)/2;return Math.min(t.x===0?1/0:n/Math.abs(t.x),t.y===0?1/0:r/Math.abs(t.y))}function Gr(e,t,n){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)*t,(a.y-s.y)*n)}return r}function $r(e,t){let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let a of e)for(let l of t[a]??[])n=Math.min(n,l.x),o=Math.max(o,l.x),r=Math.min(r,l.y),s=Math.max(s,l.y);return n===1/0?void 0:{minX:n,minY:r,maxX:o,maxY:s}}var An=new WeakMap;function Dr(e,t){let n=An.get(e);if(n?.nodeLengths===t)return n.order;let r=Object.entries(e).filter(([o,s])=>s.length>0&&t.has(o)).sort(([o],[s])=>t.get(s)-t.get(o));return An.set(e,{nodeLengths:t,order:r}),r}var In=new WeakMap;function qr(e,t,n,r){let{scaleX:o,scaleY:s}=n,a=In.get(e);if(a?.deletions===t&&a.scaleX===o&&a.scaleY===s&&a.version===r)return a.arcs;let l=[];for(let i of[...t].sort((c,f)=>f.bp-c.bp)){let c=wn(e,i,n),f=c?mn(c):void 0;if(c&&f){let{minX:d,minY:u,maxX:h,maxY:p}=gn(c);l.push({deletion:i,curves:c,apex:f,extent:Math.max((h-d)*o,(p-u)*s)})}}return In.set(e,{deletions:t,scaleX:o,scaleY:s,version:r,arcs:l}),l}function _n({nodePositions:e,nodeLengths:t,deletions:n,alleleDeletions:r,axis:o,translateX:s,translateY:a,width:l,height:i,version:c=0}){let{scaleX:f,scaleY:d}=o,u=[],h=[];for(let{deletion:g,curves:b,apex:x,extent:E}of qr(e,n,o,c))if(E>=Er){let L=Rn(g.bp),N=nt(L),R=et(N,0,0),M=x.x*f+s,A=x.y*d+a,_=E>=N*2/Je,B=vr(b,x,f,d),k=Br(R,B)+Ir,W=_?M:tt(M+B.x*k,N,l-N),q=_?A:tt(A+B.y*k,de,i-de),F=Math.hypot(W-M,q-A),K;if(F>0){let j={x:(W-M)/F,y:(q-A)/F},V=Pr(R,j);K={arcX:M,arcY:A,labelX:W-j.x*V,labelY:q-j.y*V}}u.push({label:{key:`del:${g.edgeIndex}`,text:L,x:W,y:q,kind:"deletion",leader:K},box:et(N,W,q)})}let p=new Set,m=[...r??[]].sort((g,b)=>b.bp-g.bp);for(let g of m){let b=$r(g.nodeIds,e);if(!b)continue;let x=Math.max(b.minX*f+s,0),E=Math.min(b.maxX*f+s,l),L=Math.max(b.minY*d+a,0),N=Math.min(b.maxY*d+a,i);if(E<x||N<L)continue;let R=Math.max(E-x,N-L),M=Rn(g.bp),A=nt(M);if(R>=A*2/Je){for(let k of g.nodeIds)p.add(k);let _=tt((x+E)/2,A,l-A),B=tt((L+N)/2,de,i-de);u.push({label:{key:`alleledel:${g.nodeIds.join(",")}`,text:M,x:_,y:B,kind:"deletion"},box:et(A,_,B)})}}for(let[g,b]of Dr(e,t)){if(p.has(g))continue;let{x,y:E}=Nn(b),L=E*d+a;if(L+de<=0||L-de>=i)continue;let N=Gr(b,f,d);if(N<Or*2/Je)continue;let R=Tn(t.get(g)),M=nt(R);if(N>=M*2/Je){let A=x*f+s;h.push({label:{key:`node:${g}`,text:R,x:A,y:L,kind:"node"},box:et(M,A,L)})}}return{deletions:u,nodes:h}}function On(e,t){return Math.max(Ar,Math.floor(e*t/Rr))}function Et(e,t,n=1/0){let r=[];for(let{label:o,box:s}of e){if(r.length>=n)break;t(s)&&r.push(o)}return r}var Hr=3.4,vn=6,Wr=8,Yr=18,Xr=2,zr=60,kr=8,Bn=15;function Rt(e,t){return[...e].sort((n,r)=>t(r)-t(n))}function Xi(e){let{paneWidth:t,canvasHeight:n,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,l={width:t,height:n},i=M=>({x:M.x*s+r,y:M.y*a+o}),c=e.drawnRowLabels.map(({label:M,y:A})=>Cn(M,A*a+o));e.legendSize.width>0&&c.push({x0:t-vn-e.legendSize.width,x1:t,y0:0,y1:vn+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let f=St(l,c),d=e.drawnRowLabels.length>0,u=d?Math.min(...e.drawnRowLabels.map(M=>M.y)):1/0,h=e.contigThickness*Hr,p=Rt(e.bubbleHalos,M=>M.members),m=Pe(p.map(M=>{let{x:A,y:_}=i({x:M.labelAt.x,y:Math.min(M.labelAt.y,u)}),B=_-h/2-6;return{item:M,x:A,y:d?Math.max(B,Bn):B,text:M.label}}),l,f),g=Math.max(2,Math.min(kr,Math.floor((o-zr)/19))),b=Pe(Rt(e.bubbleGlyphs,M=>M.bubble.end-M.bubble.start).flatMap(M=>{let A=(M.bubble.start+M.bubble.end)/2*s+r,_=Nt(M.label)/2;return A<0||A>t?[]:[{item:{glyph:M,glyphX:A},x:Math.min(Math.max(A,_),t-_),y:Bn,text:M.label,stack:g-1}]}),l,f),x=Pe(Rt(e.genePins,M=>M.gene.end-M.gene.start).map(M=>{let{x:A,y:_}=i(M.at);return{item:M,x:A,y:_+e.contigThickness+Yr,text:M.covered<.98?`${M.gene.name} \u2026`:M.gene.name,stack:Xr}}),l,f),E=e.nodePositions&&e.labelsNodeSizes?_n({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.showDeletionEdges?e.deletions:[],alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},L=Et(E.deletions,f),N=Pe(p.flatMap(M=>M.routes.map(A=>{let{x:_,y:B}=i(A.at);return{item:{halo:M,route:A},x:_,y:B+4,text:A.text,stack:Wr}})),l,f),R=Et(E.nodes,f,On(t,n));return{bubbles:m,glyphs:b,genes:x,routes:N,sizes:[...L,...R]}}var Y=ge(At(),1);var D=ge(At(),1);function $e(e,t){return(0,D.packAbgr)((0,D.abgrRed)(e),(0,D.abgrGreen)(e),(0,D.abgrBlue)(e),Math.round((0,D.abgrAlpha)(e)*t))}function ji(e,t){return(0,D.packAbgr)(Math.min(255,Math.round((0,D.abgrRed)(e)*t)),Math.min(255,Math.round((0,D.abgrGreen)(e)*t)),Math.min(255,Math.round((0,D.abgrBlue)(e)*t)),(0,D.abgrAlpha)(e))}var jr=4;function De(e){let t=new Map;function n(r,o){let s=t.get(r);s?s.push(o):t.set(r,[o])}for(let r of e.edges)n(r.from,r.to),n(r.to,r.from);return t}function Vr({nodeId:e,nodeById:t,neighbors:n}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<jr&&o.length>0;l++){let i=[];for(let c of o){let f=n.get(c);if(f){for(let d of f)if(!r.has(d)){r.add(d);let u=t.get(d);u&&P(u)?(s=Math.min(s,u.stable.start+u.length),a=Math.max(a,u.stable.start)):i.push(d)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function Kr({nodeId:e,nodeById:t,neighbors:n}){let r=t.get(e);return r===void 0?void 0:P(r)?{start:r.stable.start,end:r.stable.start+r.length}:Vr({nodeId:e,nodeById:t,neighbors:n})}function Dn(e){let t=new Map(e.nodes.map(o=>[o.id,o])),n=De(e),r=new Map;for(let o of e.nodes){let s=Kr({nodeId:o.id,nodeById:t,neighbors:n});s&&r.set(o.id,(s.start+s.end)/2)}return r}var qn=new WeakMap;function Fn(e,t,n,r,o){let{scaleX:s,scaleY:a}=n,l=qn.get(e);if(l?.graph===t&&l.scaleX===s&&l.scaleY===a&&l.deletions===r&&l.version===o)return l.curves;let i=new Map;for(let c=0;c<t.edges.length;c++){let f=t.edges[c],d=e[f.from],u=e[f.to];if(d?.length&&u?.length){let h=r?.get(c);i.set(c,Be(d,u,Mn(f),0,0,n,h?Mt(e,h):[]))}}return qn.set(e,{graph:t,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var Ur=(0,Y.packAbgr)(119,119,119,217),Hn=(0,Y.packAbgr)(136,136,136,217),Qr=(0,Y.packAbgr)(24,24,28,240),Zr=2.2,Jr=(0,Y.packAbgr)(30,30,36,245),es=1.8,ot=.18,ts=11,ns=1.2,os=1e-6,rs=7,ss=3,as=3,is=1.5,ls=.5,cs=.45,It=12,ds=1e-6,ue=new Float64Array(64),be=new Float64Array(64),ye=new Float64Array(64);function us(e,t,n,r){let o=e.length*It+1;ue.length<o&&(ue=new Float64Array(o),be=new Float64Array(o),ye=new Float64Array(o));let s=e[e.length-1];ue[0]=s.x1,be[0]=s.y1,ye[0]=0;let a=1,l=0;for(let i=e.length-1;i>=0&&l<r;i--){let c=e[i];for(let f=1;f<=It&&l<r;f++){let d=1-(f/It)**2,u=1-d,h=u*u*u,p=3*u*u*d,m=3*u*d*d,g=d*d*d,b=h*c.x0+p*c.cx0+m*c.cx1+g*c.x1,x=h*c.y0+p*c.cy0+m*c.cy1+g*c.y1;l+=Math.hypot(b-ue[a-1],(x-be[a-1])*n)*t,ue[a]=b,be[a]=x,ye[a]=l,a++}}return a}function Wn(e,t){let n=1;for(;n<e-1&&ye[n]<t;)n++;let r=ye[n-1],o=ye[n],s=o>r?Math.min(1,Math.max(0,(t-r)/(o-r))):0;return{x:ue[n-1]+(ue[n]-ue[n-1])*s,y:be[n-1]+(be[n]-be[n-1])*s}}function fs({curves:e,edgeHalfWidth:t,nodeHalfWidth:n,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=rs+ss*t,c=us(e,r,o,n+i),f=ye[c-1],d=Math.min(n,f),u=f<ds?ps(a,r,o):f-d,h=Math.min(1,u/i);if(h<ls)return;let p=Wn(c,d),m=Wn(c,d+i*h),g=p.x-m.x,b=(p.y-m.y)*o,x=e[e.length-1];return{x:p.x,y:p.y,angle:Math.hypot(g,b)>0?Math.atan2(b,g):As(x,o,hs(x,l)),length:i*h,halfWidth:(as+is*t)*h,color:s}}function ps(e,t,n){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)*n);return r*t}function hs(e,t){if(t.length<2)return;let n=t[0],r=t[t.length-1];return Math.hypot(e.x1-n.x,e.y1-n.y)<=Math.hypot(e.x1-r.x,e.y1-r.y)?{from:n,to:t[1]}:{from:r,to:t[t.length-2]}}function ms(e,t=1){let n=t===1?e:e.map(o=>({x:o.x,y:o.y*t})),r=[];for(let o=0;o<n.length;o++){let s=0,a=0;if(o===0){let l=n[1].x-n[0].x,i=n[1].y-n[0].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===n.length-1){let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=n[o].x-n[o-1].x,i=n[o].y-n[o-1].y,c=Math.hypot(l,i),f=n[o+1].x-n[o].x,d=n[o+1].y-n[o].y,u=Math.hypot(f,d);if(c>0&&u>0){let h=-i/c,p=l/c,m=-d/u,g=f/u;s=(h+m)/2,a=(p+g)/2;let b=h*s+p*a;b>.1&&(s/=b,a/=b)}else c>0?(s=-i/c,a=l/c):u>0&&(s=-d/u,a=f/u)}r.push({nx:s,ny:a})}return r}function gs(e,t,n,r=1){return e.map((o,s)=>({x:o.x+t[s].nx*n,y:o.y+t[s].ny*n/r}))}function rt(e,t,n,r){return(0,Y.packAbgr)(Math.round(e*255),Math.round(t*255),Math.round(n*255),Math.round(r*255))}function st(e,t,n){let r=(1-Math.abs(2*n-1))*t,o=r*(1-Math.abs(e/60%2-1)),s=n-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 bs=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],ys=[[237,137,44],[158,42,122]],xs=[[220,50,50],[50,120,220]];function Ct(e,t){let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),o=n-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 Ms(e,t){let[n,r,o]=st(nn(e),pt,ht);return rt(n,r,o,t)}var ws=300,Ls=.7,Ns=.5,Ss=(0,Y.packAbgr)(60,65,72,255);function al(e,t){let n=Dn(e);if(t&&t.end>t.start)return{start:t.start,span:t.end-t.start,midpoints:n};let r=1/0,o=-1/0;for(let s of n.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:n}}function Es(e){let t=1/0,n=-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<t&&(t=a.depth),a.depth>n&&(n=a.depth),a.length<r&&(r=a.length),a.length>o&&(o=a.length);return{minDepth:t,maxDepth:n,minLength:r,maxLength:o,maxRank:s,nodeCount:e.nodes.length}}function Rs(e,t,n,r){switch(n){case"random":return Ms(e.id,1);case"depth":return Ct(bs,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return Ct(xs,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):Ct(ys,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 Ss;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=st(a*ws,Ls,Ns);return rt(l,i,c,1)}case"grey":return(0,Y.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?t/r.nodeCount*360:0,[s,a,l]=st(o,.75,.5);return rt(s,a,l,1)}default:return(0,Y.packAbgr)(52,152,219,255)}}function As(e,t=1,n){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)*t;if(Math.hypot(a,l)>0)return Math.atan2(l,a)}return n?Math.atan2((n.to.y-n.from.y)*t,n.to.x-n.from.x):0}function Is(e,t){let n=!1;for(let r=0;r<e.length-1&&!n;r++){let o=e[r],s=e[r+1];n=Math.max(o.x,s.x)>=t.minX&&Math.min(o.x,s.x)<=t.maxX&&Math.max(o.y,s.y)>=t.minY&&Math.min(o.y,s.y)<=t.maxY}return n}function Cs(e,t){for(let n of e){let r=Math.min(n.x0,n.cx0,n.cx1,n.x1),o=Math.max(n.x0,n.cx0,n.cx1,n.x1),s=Math.min(n.y0,n.cy0,n.cy1,n.y1),a=Math.max(n.y0,n.cy0,n.cy1,n.y1);if(o>=t.minX&&r<=t.maxX&&a>=t.minY&&s<=t.maxY)return!0}return!1}var Yn=new WeakMap;function Ts(e){let t=Yn.get(e);if(!t){let n=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=st(on(s,o.length),pt,ht);n.push(rt(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}t={pathColorByIndex:n,pathIndexByName:r},Yn.set(e,t)}return t}var Xn=new WeakMap,_s=new Map;function Os(e){let t=Xn.get(e);if(!t){t=new Map;for(let[n,r]of(e.paths??[]).entries())for(let o of new Set(r.nodeIds)){let s=t.get(o);s?s.push(n):t.set(o,[n])}Xn.set(e,t)}return t}function il(e){let{nodePositions:t,graph:n,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:f,linearLayout:d,viewportBounds:u,referenceRamp:h,deletions:p,hiddenEdges:m,version:g=0}=e,b=i==="depth"?sn(n):0,x=f.scaleX,E=Ze(f),L=Fn(t,n,f,p,g),N=[],R=new Map,M=[],A=new Map,_=[],B=new Map,k={...Es(n),referenceRamp:h},W=new Map;if(o==="rainbow")for(let O=0;O<n.nodes.length;O++)W.set(n.nodes[O].id,O);let q=n.paths?.length??0,{pathColorByIndex:F,pathIndexByName:K}=Ts(n),j=O=>F[K.get(O)??-1]??Hn,V=l&&q>1?Os(n):_s,We=x>(d?1:cs);for(let O=0;O<n.edges.length;O++){let $=n.edges[O],U=t[$.from],Z=t[$.to],J=L.get(O);if(!U?.length||!Z?.length||!J||m?.has(O))continue;let se=$.pathIds?.length??0,ae=p?.get(O)!==void 0,ie=c?.edgeIndexes.has(O)??!1,ee=a/2*(ae?Zr:1)*(ie?es:1),he=l&&se>0,Ce=ae?Qr:Ur,we=c?ie?Jr:$e(Ce,ot):Ce,Ye=r.get($.to),ft=(Ye?mt(Ye,s,i,b):s)/2,Te=(ze,ke,te,Oe)=>{let me=ze===0&&ke===0?J:yn(J,ze,ke);if(u&&!Cs(me,u))return;if(ae)for(let or of bn(me,ts/x))_.push({curves:or,thickness:ee,color:te});else _.push({curves:me,thickness:ee,color:te});let Ut=We&&Oe!==void 0?fs({curves:me,edgeHalfWidth:ee,nodeHalfWidth:ft,scale:x,yToX:E,color:Oe,fromSegments:U,toSegments:Z}):void 0;Ut&&M.push(Ut)},Xe=_.length,_e=M.length;if(!he)Te(0,0,we,we);else{let ze=xn(U,Z,se,f),ke=Math.floor((se-1)/2);for(let te=0;te<se;te++){let Oe=ze[te],me=j($.pathIds[te]);Te(Oe.x,Oe.y,c&&$.pathIds[te]!==c.name?$e(me,ot):me,te===ke?we:void 0)}}let Vt=_.length-Xe;Vt>0&&B.set(O,{start:Xe,count:Vt});let Kt=M.length-_e;Kt>0&&A.set(O,{start:_e,count:Kt})}for(let[O,$]of Object.entries(t)){let U=r.get(O);if(!U||u&&!Is($,u))continue;let Z=Rs(U,W.get(O)??0,o,k),J=c!==void 0&&!c.nodeIds.has(O),se=J?$e(Z,ot):Z,Ie=mt(U,s,i,b),ae=Ie/2,ie=N.length,ee=V.get(O),he=Ie/q,Ce=$.length>=2;if(Ce&&ee?.length&&he>=ns){let Ye=ms($,E),ft=1/Math.max(x,os);for(let Te of ee){let Xe=(Te-(q-1)/2)*he*ft,_e=F[Te]??Hn;N.push({points:gs($,Ye,Xe,E),thickness:he/2,color:J?$e(_e,ot):_e})}}else Ce&&N.push({points:$,thickness:ae,color:se});let we=N.length-ie;we>0&&R.set(O,{start:ie,count:we})}return{nodeStrokes:N,nodeStrokeRuns:R,arrows:M,arrowRuns:A,edgeCurves:_,edgeCurveRuns:B}}function ul(e){return ve(e)?zn(e):void 0}function zn(e){return{sample:Ke(e.stable.refName),haplotype:Qt(e.stable.refName),refName:Zt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function vs(e,t){let n=[...e].sort((s,a)=>s.start-a.start),r,o;for(let s of n)o=o&&s.start-o.end<=t?{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 Bs(e){return`${e.haplotype??e.sample}\0${e.refName}`}function fl(e,{maxGap:t=1/0}={}){let n=new Map;for(let o of e.nodes)if(ve(o)){let s=zn(o),a=Bs(s),l=n.get(a);l?(l.spans.push({start:s.start,end:s.end}),l.rank=Math.min(l.rank,o.stable.rank)):n.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 n.values()){let s=vs(o.spans,t);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 Ps(e,t){return(t.haplotype===void 0?void 0:e(t.haplotype))??e(t.sample)}function pl(e,t){return e.flatMap(n=>{let r=Ps(t,n);return r===void 0?[]:[{...n,sample:r}]})}function hl(e){return`${e.refName}:${e.start+1}-${e.end}`}function Tt(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var kn=ge(Ve(),1),jn=(0,ne.createSvgIcon)((0,kn.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var Vn=ge(Ve(),1),Kn=(0,ne.createSvgIcon)((0,Vn.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 Un=ge(Ve(),1),_t=(0,ne.createSvgIcon)((0,Un.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",$s="Linear synteny view",Ds="No synteny track in this session aligns these assemblies";function Qn({label:e,icon:t,entries:n,entryLabel:r,onSelect:o,disabledHelpText:s,nameTheOnlyEntry:a=!0}){let[l]=n,i=s?[{label:e,icon:t,disabled:!0,disabledHelpText:s,onClick:()=>{}}]:[];return n.length===0?i:n.length===1&&l?[{label:a?`${e} \u2014 ${r(l)}`:e,icon:t,onClick:o(l)}]:[{label:e,icon:t,type:"subMenu",subMenu:n.map(c=>({label:r(c),onClick:o(c)}))}]}function Rl({contributors:e,syntenyTracks:t,onShowLinear:n,onShowSynteny:r}){let o=t[0]?.coverage??e.length;return[...Qn({label:Gs,icon:_t,entries:e,entryLabel:s=>`${s.sample} ${Tt(s)}`,onSelect:s=>()=>{n({location:s,assembly:s.sample})}}),...e.length>=2?Qn({label:`${$s} (${o} assemblies)`,icon:jn,entries:t,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Ds,onSelect:s=>()=>{r(s.trackId)}}):[]]}function Al({own:e,reference:t,highlight:n,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Tt(e.location)}`,target:e}:void 0,t&&t.assembly!==e?.assembly?{label:`Open in ${t.assembly} \u2014 around this node`,target:t}:void 0].filter(a=>a!==void 0);return[...o&&n?[{label:`Highlight in ${n.assembly}`,icon:Kn,onClick:()=>{o(n)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:_t,onClick:()=>{r(l)}}))]}var Fs=10;function Hs(e,t){let n=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>r<=Fs*(o.end-o.start)&&(n===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=n/2))}var Ws=40;function xe(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function Ys(e,t){let n=xe(e),r=xe(t),o=r.slice(r.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${r}`:`${n}\u2013${r}`}function Jn(e){return e>=tn?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function _l(e,t=[]){let n=Xs(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function Xs(e,t){let n=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=Ys(r,o);if(a>=Ws)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${Jn(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${xe(o)} inv`};let c=o!==r?Hs(e,t):void 0;if(c){let d=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${d}, ${Jn(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${xe(n)} sub`}:n===0||r===n?{kind:"insertion",label:`\u2264${xe(o-n)} ins${f}`}:o===n?{kind:"deletion",label:`${xe(n-r)} del${f}`}:{kind:"complex",label:`${xe(n)} ref \u2192 ${i}, ${s} alleles`}}var Ol={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},vl={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function Bl(e){return e.segments.split(",").filter(Boolean)}function at(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function zs(e,t,n,r){let o=[],s=[],a=[e];for(r.add(e);a.length>0;){let l=a.pop(),i=t.get(l);if(i){o.push(i);for(let c of n.get(l)??[]){let f=t.get(c);f&&(f.stable.rank===0?s.push(f):r.has(c)||(r.add(c),a.push(c)))}}}return{members:o,anchors:s}}function ks(e){if(new Set(e.map(l=>l.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((l,i)=>l.stable.start-i.stable.start),r=n[0],o=n.at(-1),s=r.stable.start+r.length,a=o.stable.start;return a>=s?{start:s,end:a,entry:r}:void 0}function js(e,t,n){let r=new Map(e.map(a=>[a.id,a])),o=new Map,s=[];for(let a of n.get(t.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 n.get(a)??[])if(r.has(i)){let c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function Vs(e,t,n){let r=js(e,t,n),o=[...e].sort((i,c)=>r.get(i.id)-r.get(c.id)),s=new Map(o.map((i,c)=>[i.id,c])),a=new Map(e.map(i=>[i.id,i])),l=new Map;for(let[i,c]of o.entries()){let f=0;for(let d of n.get(c.id)??[]){let u=a.get(d);u&&s.get(d)<i&&(f=Math.max(f,l.get(d)+u.length))}l.set(c.id,f)}return{offsets:l,ordered:o}}function to(e){let t=new Map(e.nodes.filter(ve).map(s=>[s.id,s])),n=De(e),r=new Set,o=[];for(let s of t.values())if(s.stable.rank!==0&&!r.has(s.id)){let{members:a,anchors:l}=zs(s.id,t,n,r),i=ks(l);if(i){let{offsets:c,ordered:f}=Vs(a,i.entry,n);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:f.map(d=>d.id),nodeOffsets:f.map(d=>c.get(d.id)),pathLength:f.reduce((d,u)=>Math.max(d,c.get(u.id)+u.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ks=1,Us=.015;function it({graph:e,span:t,rowY:n,positions:r}){let o=t*Us,s=to(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let d=f.refSpan-f.pathLength;d>=Ks&&l.push({nodeIds:f.nodeIds,bp:d});let u=Math.max(f.refSpan,o),h=f.pathLength>0?u/f.pathLength:0;f.nodeIds.forEach((p,m)=>{let g=a.get(p);if(g){let b=f.nodeOffsets[m],x=u/f.nodeIds.length,E=N=>f.start+N*h,L=n(g);r[p]=h?[{x:E(b),y:L},{x:E(b+g.length),y:L}]:[{x:f.start+m*x,y:L},{x:f.start+(m+1)*x,y:L}]}})}let i=De(e),c=Object.keys(r);for(let f of c){let d=r[f].at(-1).x;for(let u of i.get(f)??[]){let h=a.get(u);if(h&&!(u in r)){let p=n(h);r[u]=[{x:d,y:p},{x:d+o,y:p}],c.push(u)}}}return l}function Qs(e){let t=new Set;for(let n of e.nodes)n.stable&&t.add(n.stable.rank);return new Map([...t].sort((n,r)=>n-r).map((n,r)=>[n,r]))}function no(e,t){let n=le(e);if(n.length===0)return;let r=Qe(n,t),o=Qs(e),s=ce(n),a=it({graph:e,span:r,rowY:i=>(i.stable?o.get(i.stable.rank)??o.size:o.size)*20,positions:s}),l=[...o].map(([i,c])=>({label:i===0?"Reference (rank 0)":`Rank ${i}`,y:c*20}));return{nodePositions:s,rowLabels:l,referenceAxis:!0,pixelRows:!0,alleleDeletions:a}}var Zs=12,Ot=20;function oo(e){return 10+8*Math.log2(1+e.length)}function fe(e,t){return e<t?-1:e>t?1:0}function so(e,t){return fe(e.at,t.at)||fe(e.side,t.side)||fe(e.hops,t.hops)}var ro={at:1/0,side:0,hops:0};function Js(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=na(e);return e.nodes.map(r=>r.id).sort((r,o)=>so(n.get(r)??ro,n.get(o)??ro)||fe(t.get(r).name,t.get(o).name)||fe(r,o))}function ea(e,t){let n=new Set(e.nodes.map(f=>f.id)),r=new Map(t.map(f=>[f.id,f.stable.start])),o=new Map,s=new Map;t.forEach((f,d)=>{s.set(f.id,t[d-1]?.id),o.set(f.id,t[d+1]?.id)});let a=t[0]?.id,l=(f,d)=>{let u=o.get(f);o.set(f,d),s.set(d,f),o.set(d,u),u!==void 0&&s.set(u,d)},i=(f,d)=>{let u=s.get(f);u===void 0?(a=d,s.set(d,void 0),o.set(d,f),s.set(f,d)):l(u,d)};for(let f of e.paths??[]){let d=0,u=0,h;for(let b of f.nodeIds){let x=r.get(b);x!==void 0&&(h!==void 0&&x!==h&&(x>h?d++:u++),h=x)}let p=u>d?[...f.nodeIds].reverse():f.nodeIds,m,g=new Set;for(let b of p)if(o.has(b)){if(m===void 0)for(let x of g)i(b,x);m=b}else n.has(b)&&(m===void 0?g.add(b):(l(m,b),m=b))}let c=[];for(let f=a;f!==void 0;f=o.get(f))c.push(f);return c}function ta(e,t){let n=[...t.entries()].sort(([a,l],[i,c])=>so(l,c)||fe(a,i)).map(([a])=>a),r=n.length;for(let a of n){let l=t.get(a);for(let i of e.get(a)??[])t.has(i)||(t.set(i,{at:l.at,side:1,hops:l.hops+1}),n.push(i))}let o=new Set(n.slice(r)),s=new Set;for(let a of o){if(s.has(a))continue;let{at:l}=t.get(a),i=[a];s.add(a);let c=!0;for(let f of i){let{hops:d}=t.get(f),u=!0,h=!1;for(let p of e.get(f)??[]){let m=t.get(p);m.at===l&&o.has(p)?(u&&=m.hops<=d,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!u||h}if(c)for(let f of i){let d=t.get(f);t.set(f,{...d,side:-1,hops:-d.hops})}}}function na(e){let t=new Set(e.nodes.map(s=>s.id)),n=new Map;for(let s of e.edges)!t.has(s.from)||!t.has(s.to)||((n.get(s.from)??n.set(s.from,[]).get(s.from)).push(s.to),(n.get(s.to)??n.set(s.to,[]).get(s.to)).push(s.from));let r=e.nodes.filter(P).sort((s,a)=>fe(s.stable.start,a.stable.start)||fe(s.name,a.name)),o=new Map;return ea(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),ta(n,o),o}function oa(e){let t=new Map(e.nodes.map(d=>[d.id,d])),n=Js(e),r=new Map(n.map((d,u)=>[d,u])),o=d=>P(t.get(d)),s=new Map(n.map(d=>[d,[]])),a=new Map(n.map(d=>[d,[]])),l=(d,u)=>{s.get(u).push(d),a.get(d).push(u)};for(let d of e.edges)d.from===d.to||!r.has(d.from)||!r.has(d.to)||(r.get(d.from)<r.get(d.to)?l(d.from,d.to):l(d.to,d.from));let i=n.filter(o);for(let d=1;d<i.length;d++)l(i[d-1],i[d]);let c=new Map;for(let d of n){let u=0;for(let h of s.get(d))u=Math.max(u,c.get(h)+1);c.set(d,u)}for(let d=n.length-1;d>=0;d--){let u=n[d],h=a.get(u);if(o(u)||h.length===0)continue;let p=1/0;for(let b of h)p=Math.min(p,c.get(b));let m=c.get(u),g=Math.max(m,p-1);c.set(u,Math.floor((m+g)/2))}let f=[];for(let d of n)(f[c.get(d)]??=[]).push(d);return{layers:f,layerOf:c,preds:s}}function ao(e){if(!e.nodes.some(P))return;let t=new Map(e.nodes.map(d=>[d.id,d])),n=d=>P(t.get(d)),{layers:r,layerOf:o,preds:s}=oa(e),a=r.map(d=>{let u=0;for(let h of d)u=Math.max(u,oo(t.get(h)));return u}),l=[],i=0;for(let d=0;d<r.length;d++)l[d]=i,i+=a[d]+Zs;let c=new Map;for(let d of r){let u=[];for(let p of d){if(n(p)){c.set(p,0);continue}let m=s.get(p).filter(b=>c.has(b)),g=0;for(let b of m)g+=c.get(b)/m.length;u.push({id:p,ideal:g===0?Ot:g})}u.sort((p,m)=>p.ideal-m.ideal);let h=new Set([0]);for(let{id:p,ideal:m}of u){let g=Math.round(m/Ot);g===0&&(g=m>=0?1:-1);for(let b=1;h.has(g);b++)h.has(g+b)?h.has(g-b)||(g-=b):g+=b;h.add(g),c.set(p,g*Ot)}}let f={};for(let d of e.nodes){let u=o.get(d.id),h=oo(d),p=l[u]+a[u]/2,m=c.get(d.id);f[d.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function ra(e,t){let n=new Map;for(let o of e.nodes)if(Ue(o)){let{sample:s}=at(o.stable.refName);n.set(s,(n.get(s)??0)+o.length)}let r=new Map(t.map((o,s)=>[o,s]));return[...n.keys()].sort((o,s)=>(r.get(o)??1/0)-(r.get(s)??1/0)||n.get(s)-n.get(o)||o.localeCompare(s))}function io(e,t,n=[]){let r=le(e),o=ra(e,n);if(r.length===0||o.length===0)return;let s=Qe(r,t),a=new Map(o.map((u,h)=>[u,h+1])),l=ce(r),i=o.length+1,c=it({graph:e,span:s,rowY:u=>{let h=u.stable;return((h?a.get(at(h.refName).sample):void 0)??i)*20},positions:l}),d=[{label:at(r[0].stable.refName).sample,y:0},...o.map(u=>({label:u,y:a.get(u)*20}))];return{nodePositions:l,rowLabels:d,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function vt(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var He=!1,lo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Eo(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??(t=>lo[t.id%lo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var T=Eo({}),Dt=null,y=[],w=[],S=[],C=new Map,Re=[],I=[],Me=[],Ft=[],Ht=[],Q=-1,G=vt(),qt={minX:0,maxX:0,minY:0,maxY:0},qe,lt=new Map;function Ro(e,t,n=[],r={}){if(T=Eo(r),Dt=r.bed??null,G=vt(),Me=[],Ft=[],Ht=[],Re=[],qt={minX:0,maxX:0,minY:0,maxY:0},qe=void 0,lt=new Map,e.length===0||t.length===0)return;let o=Bt(e);y=[],o.forEach((i,c)=>{y[c+1]=i}),w=Bt(t);let s=n.length>0;S=Bt(za(n));for(let i=w.length-1;i>=0;i-=1){let c=w[i];if(c.type===void 0&&(c.type="haplotype"),c.hidden===!0){w.splice(i,1);continue}c.indexOfFirstBase!==void 0&&(qe=c.name)}if(w.length===0)return;aa(0),C=fo(),Se(w),T.showReads&&S.length>0&&Se(S),So(),T.mergeNodesFlag&&(po(),Gt(),T.showReads&&S.length>0&&Pt(),Xa(),C=fo(),So(),Se(w),T.showReads&&S.length>0&&Se(S)),po(),Aa(),He&&console.log(`${y.length} nodes.`),Gt(),Q=mo(),Ia(),Gt(),Q=mo();let a=T.showReads&&T.coarsenedReadView&&!s;if(a){let i=qe===void 0?-1:w.findIndex(d=>d.name===qe),c=i===-1?0:i,f=w.filter((d,u)=>u!==c);if(f.length>0){let d=Mo(f,"haplotype");d.length>0&&(w=[w[c]],S=d)}}Da(),Oa(),T.showExonsFlag&&Dt!==null&&$a();let l=T.showReads&&T.coarsenedReadView&&S.length>0&&!a;return T.showReads&&S.length>0?(ia(),Pt(),Se(S),l&&(S=Mo(S,"read"),Pt(),Se(S)),ca(),w=w.concat(S)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),Ta(),Ha(),He&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(Me)),wa(),{nodes:y,tracks:w,reads:S,nodeMap:C,shapes:G,bounds:qt,maxOrder:Q,trackForRuler:qe,coarsenedEdgeMeta:lt}}function Ee(e,t="plain"){return T.trackColor(e,t)}function sa(e){return T.trackAlpha(e)}function Bt(e){return structuredClone(e)}function X(e){let t=String(e);return t.length>=1&&t.startsWith("-")}function v(e){return X(e)?String(e).substring(1):e}function pe(e){return X(e)?e:`-${e}`}function Ao(e){return X(e)?v(e):pe(e)}function ct(e){return(e||1/e)>=0}function aa(e){let t=new Set,n=w[e].sequence;for(let r=0;r<n.length;r+=1){let o=n[r];if(X(o)){let s=v(o),a=n.indexOf(s);(a===-1||a>r)&&t.add(s)}}for(let r of w){n=r.sequence;for(let o=0;o<n.length;o+=1){let s=n[o];X(s)?t.has(v(s))&&(n[o]=v(s)):t.has(s)&&(n[o]=pe(s))}}y.forEach(r=>{r&&t.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function ia(){Re=[];for(let t=0;t<=Q;t+=1)Re[t]=[];let e=new Map;y.forEach(t=>{t.y!==void 0&&co(e,t.order,t.y+t.contentHeight)}),w.forEach(t=>{t.type==="haplotype"&&t.path.forEach(n=>{co(e,n.order,(n.y??0)+t.width)})}),y.forEach((t,n)=>{t.order>=0&&t.y===void 0&&(t.y=(e.get(t.order)??0)+25,t.contentHeight=0,Re[t.order].push(n))})}function co(e,t,n){let r=e.get(t);r===void 0?e.set(t,n):e.set(t,Math.max(r,n))}var dt=7;function la(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),S.forEach((e,t)=>{if((e.width===void 0||e.width===0)&&(e.width=dt),e.path.length===1){let n=e.path[0].node;n!==null&&y[n].internalReads.push(t)}else e.path.forEach((n,r)=>{if(r===0){let o=e.path[0].node;o!==null&&y[o].outgoingReads.push([t,r])}else{let o=n.node;o!==null&&y[o].incomingReads.push([t,r])}})})}function ca(){ba(),la();let e=y.slice();e.sort(ut);let t=new Map;for(let a=0;a<S.length;a++){let l=S[a].sourceTrackID,i=t.get(l);i===void 0?t.set(l,[a]):i.push(a)}let n=Array.from(t.keys()).sort((a,l)=>a-l),r=n.length>1?dt:0;e.forEach(a=>{if(a)for(let l of n)da(t.get(l),a,r)});let o=ga(),s=[];S.forEach((a,l)=>{let i=a.path.length,c=new Array(i),f;for(let h=0;h<i;h++){h===0?c[h]=void 0:c[h]=f??a.path[0];let p=a.path[h];p.node!==null&&p.node&&(f=p)}let d=new Array(i),u;for(let h=i-1;h>=0;h--){h===i-1?d[h]=void 0:d[h]=u??a.path[i-1];let p=a.path[h];p.node!==null&&p.node&&(u=p)}a.path.forEach((h,p)=>{if(h.y===void 0){let m=c[p],g=d[p],b=!!(g&&m&&g.isForward!==void 0&&m.isForward!==void 0&&(m.order>g.order||g.order===m.order&&g.isForward===m.isForward));h.betweenCycleReverseTraversal=b,s.push({readIndex:l,pathIndex:p,previousY:m?.y,previousNode:m?.node})}})}),s.sort(fa),s.forEach(a=>{let l=S[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),He&&(console.log("Reads:"),console.log(S))}function da(e,t,n){let r=new Set(e),o=t.incomingReads.filter(([p])=>r.has(p)),s=t.outgoingReads.filter(([p])=>r.has(p)),a=t.internalReads.filter(p=>r.has(p));o.length===0&&s.length===0&&a.length===0&&(n=0);let l=t.y+t.contentHeight+n*2,i=o.map(p=>{let[m,g]=p,b=S[m].path,x=g+1,E;for(let L=1;L<=g;L++){let N=b[g-L]?.y;if(N!==void 0){x=L,E=N;break}}return{entry:p,decisionStep:x,y:E}});i.sort(ua),o=i.map(p=>p.entry);let c=l,f=new Map;o.forEach(p=>{let m=S[p[0]];m.path[p[1]].y=c,uo(f,m,p[1],c,t),c+=m.width});let d=c;s.sort(pa);let u=new Map;c=l,s.forEach(p=>{let m=S[p[0]],g=m.firstNodeOffset??0;m.path[p[1]].y=c,u.set(c,g);let b=f.get(c);b===void 0||b+1<=g?(c+=m.width,d=Math.max(d,c)):(f.set(c,0),o.forEach(x=>{let E=S[x[0]],L=E.path[x[1]];L.y!==void 0&&L.y>=c&&(L.y+=m.width,uo(f,E,x[1],L.y,t))}),c+=m.width,d+=m.width)}),a.sort(ma),a.forEach(p=>{let m=S[p],g=m.firstNodeOffset??0,b=m.finalNodeCoverLength??0;for(c=l;g<(f.get(c)??-1/0)+2||b>(u.get(c)??1/0)-3;)c+=m.width||dt;m.path[0].y=c,f.set(c,b),d=Math.max(d,c)});let h=d-t.y-t.contentHeight;t.contentHeight+=h,Ga(t,h)}function ua(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function uo(e,t,n,r,o){n===t.path.length-1?e.set(r,t.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function fa(e,t){let n=S[e.readIndex],r=S[t.readIndex],o=n.path[e.pathIndex],s=r.path[t.pathIndex];if(o.order!==s.order)return o.order-s.order;if(n.sourceTrackID!==r.sourceTrackID)return n.sourceTrackID-r.sourceTrackID;if(e.previousNode&&t.previousNode){let i=y[e.previousNode],c=y[t.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=t.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function pa([e,t],[n,r]){let o=S[e],s=S[n],a,l,i=o.path.length-1,c=s.path.length-1;for(;!a&&i>=0;)a=o.path[i]?.y,i-=1;for(;!l&&c>=0;)l=s.path[c]?.y,c-=1;if(a&&l)return a-l;let f=o.path[t]?.node,d=s.path[r]?.node,u=f!=null?y[f]:null,h=d!=null?y[d]:null;for(;u!=null&&h!=null&&u===h;){if(t<o.path.length-1){for(t+=1;o.path[t]?.node===null;)t+=1;let m=o.path[t]?.node;u=m!=null?y[m]:null}else u=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(u!=null)return h!=null?ut(u,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 ha(e,t){if(e.path===void 0||t.path===void 0)return(e.path===void 0?0:1)-(t.path===void 0?0:1);let n=e.path,r=t.path,o=0,s=0;for(;o<n.length&&s<r.length;){let a=n[o],l=r[s],i=a.order,c=l.order;if(i===c&&a.node&&l.node)return(l.y??0)-(a.y??0);i<c?o+=1:(i>c||(o+=1),s+=1)}return 0}function ma(e,t){let n=S[e],r=S[t],o=n.firstNodeOffset??0,s=r.firstNodeOffset??0;if(o<s)return-1;if(o>s)return 1;let a=n.finalNodeCoverLength??0,l=r.finalNodeCoverLength??0;return a<l?-1:a>l?1:0}function ga(){let e=[];for(let t=0;t<=Q;t+=1)e.push(0);return y.forEach(t=>{t.y!==void 0&&(e[t.order]=Math.max(e[t.order],t.y+t.contentHeight+20))}),w.forEach(t=>{t.path.forEach(n=>{e[n.order]=Math.max(e[n.order],(n.y??0)+t.width)})}),e}function ba(){S.forEach(e=>{let t=Math.abs(e.indexSequence[0]),n=ct(e.indexSequence[0]),r=y[t],o,s;e.path=[],e.path.push({order:r.order,isForward:n,node:t});for(let a=1;a<e.sequence.length;a+=1)if(o=r,s=n,t=Math.abs(e.indexSequence[a]),n=ct(e.indexSequence[a]),r=y[t],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});n?e.path.push({order:r.order,isForward:!0,node:t}):(e.path.push({order:r.order,isForward:!0,node:null}),e.path.push({order:r.order,isForward:!1,node:t}))}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});n?(e.path.push({order:r.order,isForward:!1,node:null}),e.path.push({order:r.order,isForward:!0,node:t})):e.path.push({order:r.order,isForward:!1,node:t})}else n!==s?e.path.push({order:r.order,isForward:n,node:t}):(e.path.push({order:r.order,isForward:!n,node:null}),e.path.push({order:r.order,isForward:n,node:t}))})}function Pt(){S.forEach(e=>{let t=0;for(;t<e.sequence.length&&e.sequence[t].startsWith("-");)t+=1;if(t===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]=v(e.sequence[a]);let n=e.sequenceNew??[];n.reverse(),e.sequenceNew=n;for(let a of n)a.nodeName=v(a.nodeName),ya(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 ya(e,t){e.forEach(n=>{n.type==="insertion"?n.pos=t-n.pos:n.type==="deletion"?n.pos=t-n.pos-(n.length??0):n.type==="substitution"&&(n.pos=t-n.pos-(n.seq?.length??0)),n.seq!==void 0&&(n.seq=Io(n.seq).split("").reverse().join(""))})}var xa={A:"T",T:"A",C:"G",G:"C"};function Io(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=xa[e.charAt(n)]??"N";return t}function Se(e){e.forEach(t=>{t.indexSequence=[],t.sequence.forEach(n=>{let r=n,o=C.get(v(r)),s=y[o]?.switched??!1;s&&(r=Ao(r));let a=C.get(v(r));if(a===0)throw new Error("Node "+v(r)+" has prohibited index 0");X(r)!==s?t.indexSequence.push(-a):t.indexSequence.push(a)})})}var Ma=20;function wa(){let e={minX:99,maxX:-99,minY:99,maxY:-99};y.forEach(t=>{t&&(t.x!==void 0&&(e.minX=Math.min(e.minX,t.x),e.maxX=Math.max(e.maxX,t.x+Ma+t.pixelWidth)),t.y!==void 0&&(e.minY=Math.min(e.minY,t.y-10),e.maxY=Math.max(e.maxY,t.y+t.contentHeight+10)))}),w.forEach(t=>{t.path.forEach(n=>{let r=n.y??0;e.maxY=Math.max(e.maxY,r+t.width),e.minY=Math.min(e.minY,r)})}),qt=e}function oe(e){let t=C.get(v(e)),n=t===void 0?void 0:y[t];if(n===void 0)throw new Error(`Unknown node ${e}`);return n}function fo(){return C=new Map,y.forEach((e,t)=>{e&&C.set(e.name,t)}),C}function po(){let e=y.map(()=>new Set),t=y.map(()=>new Set),n=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),t[a].add(s)}};w.forEach(n),T.showReads&&S.length>0&&S.forEach(n),y.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(t[o]))})}function ho(e){let t=0,n=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){I[s]===void 0&&(I[s]=n);let a=I[s];a<r&&(r=a),t=a,n=a-1}else{I[s]===void 0&&(I[s]=t);let a=I[s];t=a+1,n=a}}),r<0&&Wt(-r)}function La(e){let t=0,n=0;for(;t<e.length&&I[Math.abs(e[t])]===void 0;)t+=1;if(t>=e.length)return null;let r=e[t],o,s;r>=0?(o=I[r]-1,s=-1):(o=I[-r]+1,s=1);for(let a=t-1;a>=0;a-=1){let l=Math.abs(e[a]);I[l]===void 0&&(I[l]=o,n=Math.min(n,o),o+=s)}return n<0&&Wt(-n),t}var Na=-1;function Sa(e){let t=[];for(let n of e)t.push(n??Na);return t}function Gt(){let e,t,n,r,o=0,s=T.showReads&&S.length>0?w.concat(S):w,a={stamp:new Int32Array(y.length),generation:0};I=new Array(y.length).fill(void 0),y.forEach(i=>{i&&(i.order=void 0)}),ho(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(He&&console.log(`generating order for track ${i+1}`),n=La(s[i].indexSequence),n===null){s[i].type==="haplotype"?ho(s[i].indexSequence):(s.splice(i,1),S.splice(i-w.length,1),i-=1);continue}for(e=Ra(s[i].indexSequence);n<e.length;){for(r=n,n+=1;n<e.length&&I[e[n]]===void 0;)n+=1;if(n<e.length){t=I[e[r]]+1;for(let c=r+1;c<n;c+=1)I[e[c]]=t,t+=1;if(I[e[n]]>I[e[r]])I[e[n]]<t&&go(e[n],e[n-1],t);else if(s[i].indexSequence[n]>=0&&!Ea(e[n],e[r],a))go(e[n],e[n-1],t);else if(s[i].indexSequence[r]<0||y[e[r+1]].degree<2&&I[e[n]]<I[e[r]]){t=I[e[r]]-1;for(let c=r+1;c<n;c+=1)I[e[c]]=t,o=Math.min(o,t),t-=1}}else if(s[i].indexSequence[r]>=0){t=I[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let f=e[c];I[f]===void 0&&(I[f]=t,t+=1)}}else{t=I[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let f=e[c];I[f]===void 0&&(I[f]=t,o=Math.min(o,t),t-=1)}}}}o<0&&Wt(-o);let l=Sa(I);I=l,l.forEach((i,c)=>{let f=y[c];f!==void 0&&(f.order=i)})}function Ea(e,t,n){n.generation+=1;let{stamp:r,generation:o}=n,s=[e];for(r[e]=o;s.length>0;){let a=s.pop();if(a===t)return!0;for(let l of y[a].successors)r[l]!==o&&(r[l]=o,s.push(l))}return!1}function mo(){let e=-1;return I.forEach(t=>{t!==void 0&&t>e&&(e=t)}),e}function Ra(e){return e.map(t=>Math.abs(t))}function Wt(e){I.forEach((t,n)=>{t!==void 0&&(I[n]=t+e)})}function go(e,t,n){let r=new Map,o=[[e,n]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=I[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),y[a].successors.forEach(c=>{I[c]>i&&c!==t&&o.push([c,l+1])}),a!==e&&y[a].predecessors.forEach(c=>{I[c]>i&&c!==t&&o.push([c,l+1])}))}r.forEach((a,l)=>{I[l]=a})}function Aa(){y.forEach(e=>{e.tracks=[]}),w.forEach(e=>{e.indexSequence.forEach(t=>{y[Math.abs(t)].tracks.push(e.id)})}),y.forEach(e=>{e.tracks!==void 0&&(e.degree=e.tracks.length)})}function Ia(){let e=w[0],t=w.slice(1,w.length);if(T.showReads&&S.length>0&&(t=t.concat(S)),Ca(t,e),T.showReads&&S.length>0){for(let n=0;n<S.length;n++)if(S[n]!==t[n+w.length-1])throw new Error("Read inequality")}}function Ca(e,t){let n=new Map,r=t?new Set(t.sequence):null;for(let o of e){let s=o.sequence;for(let a=0;a<s.length;a+=1){let l=v(s[a]),i=oe(l);if(r&&!r.has(l)){let c=a>0?oe(s[a-1]).order:void 0,f=a<s.length-1?oe(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(f===void 0||i.order<f)&&bo(n,l,X(s[a])?1:-1),(c===void 0||c>i.order)&&(f===void 0||i.order>f)&&bo(n,l,X(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=n.get(v(s));l!==void 0&&l>0&&(o.sequence[a]=Ao(s),o.indexSequence[a]=-o.indexSequence[a])});n.forEach((o,s)=>{if(o>0){let a=oe(s);a.seq=Io(a.seq),a.switched=!0}})}function bo(e,t,n){e.set(t,(e.get(t)??0)+n)}function Ta(){let e=0,t=20,n=-1,r=y.slice();r.sort(ut);let o=_a();r.forEach(s=>{s.order>=0&&(s.order>n&&(n=s.order,e=t+10*o[s.order]),s.x=e,t=Math.max(t,e+40+s.pixelWidth))})}function _a(){let e=[],t=[],n=[],r=[];for(let o=0;o<=Q;o+=1)e.push(0),t.push(0),n.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:t[a.order]=t[a.order]+1;else{let i=Math.abs((a.y??0)-(l.y??0));n[a.order]=Math.max(i/17.5,n[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,t[o-1]-1),n[o]));return r}function Oa(){let e,t,n,r,o,s,a=[],l=[];for(let i=0;i<=Q;i+=1){Me[i]=[],l[i]=new Map,a[i]=[];for(let c=0;c<w.length;c+=1)a[i][c]=null}w.forEach((i,c)=>{t=Math.abs(i.indexSequence[0]),n=ct(i.indexSequence[0]),r=y[t],i.path=[],i.path.push({order:r.order,lane:null,isForward:n,node:t}),H(r.order,t,c,0,a,l),e=1;for(let f=1;f<i.sequence.length;f+=1)if(o=r,s=n,t=Math.abs(i.indexSequence[f]),n=ct(i.indexSequence[f]),r=y[t],r.order>o.order){s||(i.path.push({order:o.order,lane:null,isForward:!0,node:null}),H(o.order,null,c,e,a,l),e+=1);for(let d=o.order+1;d<r.order;d+=1)i.path.push({order:d,lane:null,isForward:!0,node:null}),H(d,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!0,node:t}),H(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!0,node:null}),H(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!1,node:t}),H(r.order,t,c,e,a,l),e+=1)}else if(r.order<o.order){s&&(i.path.push({order:o.order,lane:null,isForward:!1,node:null}),H(o.order,null,c,e,a,l),e+=1);for(let d=o.order-1;d>r.order;d-=1)i.path.push({order:d,lane:null,isForward:!1,node:null}),H(d,null,c,e,a,l),e+=1;n?(i.path.push({order:r.order,lane:null,isForward:!1,node:null}),H(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:!0,node:t}),H(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:t}),H(r.order,t,c,e,a,l),e+=1)}else n!==s?(i.path.push({order:r.order,lane:null,isForward:n,node:t}),H(r.order,t,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!n,node:null}),H(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:n,node:t}),H(r.order,t,c,e,a,l),e+=1)});for(let i=0;i<=Q;i+=1)Ba(Me[i],i)}function H(e,t,n,r,o,s){let a={trackID:n,segmentID:r,compareToFromSame:o[e][n]??null},l=t===null?void 0:s[e].get(t);if(l===void 0){let i={type:"single",node:t,tracks:[a]};Me[e].push(i),t!==null&&s[e].set(t,i)}else l.type="multiple",l.tracks.push(a);o[e][n]=a}function va(e,t){let n;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===t-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===t-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(n=o.segmentID-1;n>=0&&w[o.trackID].path[n].order!==t-1;)n-=1;n<0?(o.idealLane=o.trackID,o.idealY=null):(o.idealLane=w[o.trackID].path[n].lane??void 0,o.idealY=w[o.trackID].path[n].y)}r.idealLane+=o.idealLane}),r.idealLane/=r.tracks.length})}function Ba(e,t){let n=0,r=new Set,o=20,s=!1,a=-1;va(e,t),e.sort(xo),e.forEach(l=>{l.node!==null?(y[l.node].topLane=n,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(xo),l.tracks.forEach(i=>{i.lane=n,i.trackID===a&&l.node===null&&s&&(o+=10),w[i.trackID].path[i.segmentID].lane=n,w[i.trackID].path[i.segmentID].y=o,i.idealY!=null&&r.add(i.idealY-o),n+=1,o+=w[i.trackID].width,l.node!==null&&(y[l.node].contentHeight+=w[i.trackID].width),a=i.trackID}),o+=25}),Pa(e,r)}function Pa(e,t){let n=0,r=Number.MAX_SAFE_INTEGER;t.forEach(o=>{yo(e,o)<r&&(r=yo(e,o),n=o)}),e.forEach(o=>{o.node!==null&&(y[o.node].y+=n),o.tracks.forEach(s=>{let a=w[s.trackID].path[s.segmentID];a.y=a.y+n})})}function Ga(e,t){e.order<0||Me[e.order]===void 0||(Me[e.order].forEach(n=>{if(n.node!==null){let r=y[n.node];r!==e&&r.y>e.y&&(r.y+=t,n.tracks.forEach(o=>{let s=w[o.trackID].path[o.segmentID];s.y=s.y+t}))}else n.tracks.forEach(r=>{let o=w[r.trackID].path[r.segmentID];o.y>=e.y&&(o.y=o.y+t)})}),Re[e.order].length>0&&Re[e.order].forEach(n=>{y[n]!==e&&y[n].y>e.y&&(y[n].y+=t)}))}function yo(e,t){let n=0;return e.forEach(r=>{r.tracks.forEach(o=>{o.idealY!=null&&w[o.trackID].type!=="read"&&(n+=Math.abs(o.idealY-t-w[o.trackID].path[o.segmentID].y)*w[o.trackID].width)})}),n}function xo(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function ut(e,t){if(!e)return t?-1:0;if(!t)return 1;if(e.order!==void 0){if(t.order!==void 0){if(e.order<t.order)return-1;if(e.order>t.order)return 1;if(e.y!==void 0&&t.y!==void 0){if(e.y<t.y)return-1;if(e.y>t.y)return 1}return 0}return-1}return t.order!==void 0?1:0}function $a(){let e,t,n={};Dt.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&&(n={},t=e+y[s.node].sequenceLength-1,e>=r.start&&e<=r.end&&(n.start=0),e<r.start&&t>=r.start&&(n.start=r.start-e),t<=r.end&&t>=r.start&&(n.end=t-e,t<r.end&&(n.continue=!0)),t>r.end&&e<=r.end&&(n.end=r.end-e),n.start!==void 0&&(n.type=r.type,n.name=r.name,s.features===void 0&&(s.features=[]),s.features.push(n)),e=t+1)}))})}function Da(){let e=!0,t=4,n=T.trackWidth;w.forEach(r=>{r.freq!==void 0?r.width=Math.round((Math.log(r.freq)+1)*t):(r.width=n,r.type!==void 0&&r.type==="read"&&(r.width=t)),r.width!==t&&(e=!1)}),e&&w.forEach(r=>{r.freq!==void 0&&(r.width=n)})}function qa(e){let t=e.path[0],n=y[t.node],r=e.firstNodeOffset??0;return Yt(n,t.isForward?r:n.sequenceLength-r)}function Fa(e){let t=e.path[e.path.length-1],n=y[t.node],r=e.finalNodeCoverLength??0;return Yt(n,t.isForward?r:n.sequenceLength-r)}function Co(e,t){return t>e.sequenceLength?null:Yt(e,t)}function Yt(e,t){let[n,r]=Ya(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(r-n)}function Ha(){let e,t,n,r,o,s,a,l,i;for(let d=0;d<=Q;d+=1)Ft.push(0),Ht.push(0);let c=[],f=[];y.forEach(d=>{d.x!==void 0&&(c[d.order]=d.x,f[d.order]===void 0?f[d.order]=d.x+d.pixelWidth:f[d.order]=Math.max(f[d.order],d.x+d.pixelWidth))}),w.sort(ha),w.forEach(d=>{a="plain",o=Ee(d,a),s=sa(d);let u=a,h=()=>(u!==a&&(u=a,o=Ee(d,a)),o);n=d.path[0].y,d.type!=="read"?d.sequence[0].startsWith("-")?e=f[d.path[0].order]+20:e=c[d.path[0].order]-20:e=qa(d);for(let p=0;p<d.path.length;p+=1)d.path[p].y===n?d.path[p].features!==void 0&&(i=p>0&&d.path[p-1].order===d.path[p].order,l=wo(d.path[p],c[d.path[p].order],f[d.path[p].order],a,d,e,n,o,i),a=l.highlight,e=l.xStart):(d.path[p-1].isForward?t=f[d.path[p-1].order]:t=c[d.path[p-1].order],t!==e&&(o=h(),G.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+d.width-1,color:o,alpha:s,id:d.id,name:d.name,type:d.type})),d.path[p].order-1===d.path[p-1].order?(e=t,t=c[d.path[p].order],r=d.path[p].y,o=h(),G.curves.push({xStart:e,yStart:n,xEnd:t+1,yEnd:r,width:d.width,color:o,alpha:s,laneChange:Math.abs(d.path[p].lane-d.path[p-1].lane),id:d.id,name:d.name,type:d.type,nodeStart:d.path[p-1]?.node,nodeEnd:d.path[p]?.node}),e=t,n=r):d.path[p].order+1===d.path[p-1].order?(e=t,t=f[d.path[p].order],r=d.path[p].y,o=h(),G.curves.push({xStart:e+1,yStart:n,xEnd:t,yEnd:r,width:d.width,color:o,alpha:s,laneChange:Math.abs(d.path[p].lane-d.path[p-1].lane),id:d.id,name:d.name,type:d.type,nodeStart:d.path[p-1]?.node,nodeEnd:d.path[p]?.node}),e=t,n=r):d.path[p-1].isForward?(r=d.path[p].y,No(1,t,n,r,d.width,o,d.id,d.path[p].order,d.type,d.name),e=f[d.path[p].order],n=d.path[p].y):(r=d.path[p].y,No(-1,t,n,r,d.width,o,d.id,d.path[p].order,d.type,d.name),e=c[d.path[p].order],n=d.path[p].y),d.path[p].features!==void 0&&(i=d.path[p-1].order===d.path[p].order,l=wo(d.path[p],c[d.path[p].order],f[d.path[p].order],a,d,e,n,o,i),a=l.highlight,e=l.xStart));d.type!=="read"?d.path[d.path.length-1].isForward?t=f[d.path[d.path.length-1].order]+20:t=c[d.path[d.path.length-1].order]-20:t=Fa(d),G.rectangles.push({xStart:Math.min(e,t),yStart:n,xEnd:Math.max(e,t),yEnd:n+d.width-1,color:o,alpha:s,id:d.id,name:d.name,type:d.type})})}var Wa=1e9;function Mo(e,t){lt=new Map;let n=new Map,r=T.ignoreStrand;for(let u of e){let h=u.indexSequence;if(!(!h||h.length<2))for(let p=0;p<h.length-1;p+=1){let m=h[p],g=h[p+1],b=Math.abs(m),x=Math.abs(g),E=y[b],L=y[x];if(!E||!L)continue;let N;if(r){let M=`${m}>${g}`,A=`${-g}>${-m}`;N=M<A?M:A}else N=`${m}>${g}`;let R=n.get(N);R===void 0?n.set(N,{sSigned:m,dSigned:g,sName:m<0?`-${E.name}`:E.name,dName:g<0?`-${L.name}`:L.name,count:1,sourceTrackID:u.sourceTrackID}):R.count+=1}}let o=0;for(let u of n.values())u.count>o&&(o=u.count);let s=dt,a=60,l=u=>o<=1?s:s+(a-s)*Math.sqrt(u/o),i=[],c=0;for(let u of n.values()){let h=Wa+c,p=`${u.count.toLocaleString()} ${t}${u.count===1?"":"s"}: Node ${u.sName} \u2192 Node ${u.dName}`;lt.set(h,{count:u.count,label:p});let m=y[Math.abs(u.sSigned)]?.sequenceLength??0;i.push({id:h,sourceTrackID:u.sourceTrackID,type:"read",name:p,sequence:[u.sName,u.dName],indexSequence:[],path:[],width:l(u.count),firstNodeOffset:m,finalNodeCoverLength:0,sequenceNew:[{nodeName:u.sName,mismatches:[]},{nodeName:u.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:u.count}),c+=1}let f="?",d=0;for(let u of y){if(!u)continue;let h=u.contentHeight;h>d&&(d=h,f=u.name)}return He&&console.log(`[coarsened] ${t}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${d.toFixed(1)})`),i}function wo(e,t,n,r,o,s,a,l,i){let c=r,f,d,u,h;t-=8,n+=8;let p=y[e.node].sequenceLength;return e.features.sort((m,g)=>m.start-g.start),e.features.forEach(m=>{c!==m.type&&(f=Ee(o,c),e.isForward?(u=t+Math.round(m.start*(n-t+1)/p),i&&u<t+8&&(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,d=Ee(o,m.type),G.featureRectangles.push({xStart:u,yStart:a,xEnd:h,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),u>s+1&&G.featureRectangles.push({xStart:s,yStart:a,xEnd:u-1,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})):(u=n-Math.round(m.start*(n-t+1)/p),i&&u>n-8&&(h=n-Math.round((m.end+1)*(n-t+1)/p)-1,d=Ee(o,m.type),G.featureRectangles.push({xStart:h,yStart:a,xEnd:u,yEnd:a+o.width-1,color:d,id:o.id,name:o.name,type:o.type})),s>u+1&&G.featureRectangles.push({xStart:u+1,yStart:a,xEnd:s,yEnd:a+o.width-1,color:f,id:o.id,name:o.name,type:o.type})),s=u,c=m.type),(m.end<p-1||m.continue===void 0)&&(f=Ee(o,c),e.isForward?(h=t+Math.round((m.end+1)*(n-t+1)/p)-1,G.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=n-Math.round((m.end+1)*(n-t+1)/p)-1,G.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,c="plain")}),{xStart:s,highlight:c}}var Lo=7;function No(e,t,n,r,o,s,a,l,i,c){let f=e===1?Ht:Ft,d=10*f[l],u=t+e*(d+5),h=Lo,p=Math.min(Lo,o),m=Math.min(n,r),g=Math.max(n,r),b=e===1?t:u-1,x=e===1?u:t,E=M=>{G.verticalRectangles.push({xStart:b,yStart:M,xEnd:x,yEnd:M+o-1,color:s,id:a,name:c,type:i})};E(n),G.verticalRectangles.push({xStart:e===1?u+h:u-h-p,yStart:m+o+h-1,xEnd:e===1?u+h+p-1:u-h-1,yEnd:g-h+1,color:s,id:a,name:c,type:i}),E(r);let L=u+e*h,N=u+e*(h+p),R=`M ${u} ${g}`;R+=` Q ${L} ${g} ${L} ${g-h}`,R+=` H ${N}`,R+=` Q ${N} ${g+o} ${u} ${g+o}`,R+=" Z ",G.corners.push({path:R,color:s,id:a,type:i}),R=`M ${u} ${m}`,R+=` Q ${N} ${m} ${N} ${m+o+h}`,R+=` H ${L}`,R+=` Q ${L} ${m+o} ${u} ${m+o}`,R+=" Z ",G.corners.push({path:R,color:s,id:a,type:i}),f[l]+=1}function Ya(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function So(){switch(y.forEach(e=>{e.sequenceLength===void 0&&(e.sequenceLength=e.seq.length)}),T.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=T.charWidth;y.forEach(t=>{t.width=t.sequenceLength;let n=t.seq?.length??1;t.pixelWidth=Math.round(e*n)});break}default:throw new Error(`${T.nodeWidthOption} not implemented`)}}function Xa(){let e,t,n=Array.from(y,()=>new Set),r=Array.from(y,()=>new Set),o;T.showReads&&S.length>0?o=w.concat(S):o=w,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)X(l.sequence[i])?(e=v(l.sequence[i]),i>0?(t=l.sequence[i-1],X(t)?r[C.get(e)].add(v(t)):(r[C.get(e)].add(t),r[C.get(e)].add(pe(t)))):l.type==="haplotype"&&r[C.get(e)].add("None"),i<l.sequence.length-1?(t=l.sequence[i+1],X(t)?n[C.get(e)].add(v(t)):(n[C.get(e)].add(t),n[C.get(e)].add(pe(t)))):l.type==="haplotype"&&n[C.get(e)].add("None")):(i>0?(e=l.sequence[i-1],n[C.get(l.sequence[i])].add(e),X(e)&&n[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&n[C.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[C.get(l.sequence[i])].add(e),X(e)&&r[C.get(l.sequence[i])].add(v(e))):l.type==="haplotype"&&r[C.get(l.sequence[i])].add("None"))});let s=n.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(T.showReads&&S.length>0){let l=y.slice();l.sort(ut);let i=new Map,c=new Map,f=u=>{let h=i.get(u);if(h===void 0)throw new Error(`No merge offset recorded for node ${u}`);return h},d=u=>{let h=c.get(u);if(h===void 0)throw new Error(`No merge origin recorded for node ${u}`);return h};l.forEach(u=>{let h=Fe(C.get(u.name),s,a);if(h){let p=f(h)+oe(h).sequenceLength;i.set(u.name,p),i.set(pe(u.name),p),c.set(u.name,d(h)),c.set(pe(u.name),d(h))}else i.set(u.name,0),i.set(pe(u.name),0),c.set(u.name,u.name),c.set(pe(u.name),u.name)}),S.forEach(u=>{let h=u.sequenceNew??[];u.firstNodeOffset=(u.firstNodeOffset??0)+f(u.sequence[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+f(u.sequence[u.sequence.length-1]);for(let p=u.sequence.length-1;p>=0;p-=1){let m=v(u.sequence[p]),g=Fe(C.get(m),s,a);if(g&&$t(C.get(g),s,a))if(p>0){u.sequence.splice(p,1);let b=oe(g).sequenceLength;h[p].mismatches.forEach(x=>{x.pos+=b}),h[p-1].mismatches=h[p-1].mismatches.concat(h[p].mismatches),h.splice(p,1)}else{u.sequence[0]=d(u.sequence[0]);let b=h[0],x=f(b.nodeName);b.mismatches.forEach(E=>{E.pos+=x}),b.nodeName=d(b.nodeName)}}})}for(let l=0;l<y.length;l+=1)if($t(l,s,a)&&!Fe(l,s,a)){let i=l;for(;$t(i,s,a);)i=C.get(v(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=v(l.sequence[i]);let c=C.get(e);Fe(c,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)Fe(l,s,a)&&y.splice(l,1)}function Fe(e,t,n){if(t[e].length!==1||t[e][0]==="None")return!1;let r=v(t[e][0]),o=C.get(r);return n[o].length!==1||n[o][0]==="None"?!1:r}function $t(e,t,n){if(n[e].length!==1||n[e][0]==="None")return!1;let r=v(n[e][0]),o=C.get(r);return!(t[o].length!==1||t[o][0]==="None")}function za(e){let t=T.focusReadNames?new Set(T.focusReadNames):null;return e.filter(n=>n.is_secondary!==!0&&(n.mapping_quality??0)>=T.mappingQualityCutoff&&(t===null||n.name!==void 0&&t.has(n.name)))}function ka(e,t){let n=new Map;for(let r of e){let o=t(r),s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}return n}function ja(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function To(e,t){let n=ka(e.filter(s=>s.type===t),s=>`${s.nodeStart},${s.nodeEnd}`);n.forEach(s=>{let a=.3,l=.4/s.length;s.length<=5&&(a=.5,l=0),s.sort(ja),s.forEach(i=>{let c,f;i.yStart<i.yEnd?(c=i.xStart+(i.xEnd-i.xStart)*(1-a),a+=l,f=i.xStart+(i.xEnd-i.xStart)*(1-a)):(c=i.xStart+(i.xEnd-i.xStart)*a,a+=l,f=i.xStart+(i.xEnd-i.xStart)*a);let d=`M ${i.xStart} ${i.yStart}`;d+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,d+=` V ${i.yEnd+i.width}`,d+=` C ${f} ${i.yEnd+i.width} ${f} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,d+=" Z",i.path=d})});let r=Array.from(n.keys());r.sort(function(s,a){let l=s.split(",").map(Number),i=a.split(",").map(Number),c=l[0]??0,f=l[1]??0,d=i[0]??0,u=i[1]??0;return c<d?-1:c>d?1:f<u?-1:f>u?1:0});let o=[];for(let s of r){let a=n.get(s);a!==void 0&&o.push(...a)}return o}function _o(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,r=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n+9} ${r} ${n+9} ${r+9}`,n+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight-0,t+=` L ${n} ${r}`),t+=` Q ${n} ${r+9} ${n-9} ${r+9}`,n-=9,r+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n-9} ${r} ${n-9} ${r-9}`,n-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight-0,t+=` L ${n} ${r}`),t}function Xt(e){return e.id.endsWith("-")?"-":"+"}function zt(e,t){return t===Xt(e)?e.id:`-${e.id}`}function Va(e,t){let n=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=r,r+=e[o];let s=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Ka(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let r=Va(t,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let f=r[c],d=t[c];if(f!==void 0&&d!==void 0&&f<=l&&(l<f+d||i&&l===f+d))return{s:c,local:l-f,room:f+d-l}}},s=(l,i)=>{let c=n[l],f=c.at(-1);i.type==="substitution"&&f?.type==="substitution"&&f.pos+f.seq.length===i.pos?f.seq+=i.seq:c.push(i)},a=e.pathStart;for(let l of Jt(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 c=o(a),f=c?Math.min(i,c.room):i;c&&s(c.s,{type:"deletion",pos:c.local,length:f}),a+=f,i-=f}}return n}function Oo(e,t,n){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of t){let a=s.path.map(f=>r.get(f.name)),l=a.flatMap((f,d)=>f?[d]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let f=Ka(s,a.map(h=>h?.length)),d=l.map(h=>zt(a[h],s.path[h].strand)),u=a[c].length;o.push({id:n+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:d,sequenceNew:l.map((h,p)=>({nodeName:d[p],mismatches:f[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===s.path.length-1?u-(s.pathLength-s.pathEnd):u,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var Ua=["#6baed6","#4292c6","#2171b5","#08519c"],Qa=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function vo(e){let t=e.is_reverse?Qa:Ua;return t[e.id%t.length]}function Za(e){let t=new Map;for(let[n,r]of e.pathVisits??[])for(let o of r){let s=`${o.path} ${n}`,a=t.get(s);a?a.push(o.strand):t.set(s,[o.strand])}return t}function Ja(e){let t=new Map(e.nodes.map(s=>[s.id,s])),n=Za(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,c=s.nodeIds.flatMap(f=>{let d=t.get(f);if(!d)return[];let u=i.get(d.name)??0;i.set(d.name,u+1);let h=n.get(`${l} ${d.name}`)?.[u]??Xt(d);return[zt(d,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function ei(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function Ae(e){return(e.paths?.length??0)>0}var ti=600,ni=3,oi=15;function ri(e){return Math.max(ni,Math.min(oi,Math.floor(ti/Math.max(1,e))))}function Bo(e){let t=e.paths??[],n=Ja(e),r=e.reads?Oo(e,e.reads,t.length):[];return Ro(ei(e),n,r,{nodeWidthOption:"compressed",trackWidth:ri(n.length),trackColor:o=>o.type==="read"?vo(o):rn(o.id,t.length)})}function kt(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function Po(e,t,n,r){let o=e.y+e.contentHeight/2-t;return[{x:n,y:o},{x:r,y:o}]}function Go(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function $o(e){let t=Ae(e)?Bo(e):void 0;if(!t)return;let n=t.bounds.minY,r={};for(let a of kt(t))r[a.name]=Po(a,n,a.x,a.x+a.pixelWidth);let{minY:o,maxY:s}=Go(t,n);return{nodePositions:r,tubeMap:{layout:t,yOffset:n},extent:{minX:t.bounds.minX,maxX:t.bounds.maxX,minY:o,maxY:s}}}function si(e,t){let n=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of kt(t)){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,c)=>i-c)){let i=r.get(l),c=1/0,f=-1/0;for(let d of i){let u=n.get(d.name);u&&P(u)&&(c=Math.min(c,u.stable.start),f=Math.max(f,u.stable.start+d.sequenceLength))}c===1/0&&(c=f=s),c<s&&(c=s,f=Math.max(s,f)),s=Math.max(s,f),o.push({order:l,x0:Math.min(...i.map(d=>d.x)),x1:Math.max(...i.map(d=>d.x+d.pixelWidth)),bp0:c,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 ai(e){return e.nodes.some(P)&&Ae(e)}function Do(e){let t=ai(e)?Bo(e):void 0;if(!t)return;let n=si(e,t),r=new Map(n.map(a=>[a.order,a])),o=t.bounds.minY,s={};for(let a of kt(t)){let l=r.get(a.order);s[a.name]=Po(a,o,l.bp0,l.bp1)}return{nodePositions:s,tubeMap:{layout:t,yOffset:o,columns:n},referenceAxis:!0,pixelRows:!0,extent:Go(t,o)}}function qo(e){let t=le(e);if(t.length!==0)return{nodePositions:ce(t),referenceAxis:!0,pixelRows:!0}}function Fo(e){return e.sample??Ke(e.name)}function ii(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:Fo(e)}function li(e,t,n,r=!0){if(!n||!r)return{ids:e,complete:!0};let o=-1,s=-1,a=-1/0,l=1/0;if(e.forEach((c,f)=>{let d=t.get(c);d&&(d.end<=n.start&&d.end>a&&(a=d.end,o=f),d.start>=n.end&&d.start<l&&(l=d.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 Ho(e,t,n){let r=e.paths??[],o=r.find(p=>Le(p.name).name===e.referencePath)??r[0];if(!o||r.length<2)return;let s=new Map(e.nodes.map(p=>[p.id,p.length])),a=new Set(o.nodeIds),l=e.anchorPaths?.find(p=>p.name===Le(o.name).name)?.start??0,i=t&&t.end>t.start?t:void 0,c=new Map,f=l;for(let p of o.nodeIds){let m=s.get(p)??0;c.has(p)||c.set(p,{start:f,end:f+m}),f+=m}let d=i===void 0||[...c.values()].some(p=>p.end<=i.start)&&[...c.values()].some(p=>p.start>=i.end),u=p=>{let{ids:m,complete:g}=li(p.nodeIds,c,i,d),b=[],x=0,E=0;for(let L of m){let N=s.get(L)??0,R=a.has(L),M=b.at(-1);M?.onReference===R?M.bp+=N:b.push({start:x,bp:N,onReference:R}),x+=N,R||(E+=N)}return{name:p.name,label:ii(p),sample:Fo(p),bp:x,offReferenceBp:E,complete:g,runs:b}};return{origin:i?i.start:l,unit:n,reference:u(o),rows:r.filter(p=>p!==o).map(u).sort((p,m)=>Number(m.complete)-Number(p.complete)||m.bp-p.bp||p.label.localeCompare(m.label))}}var ci=1.3;function di(e){let t=e.reference.bp;for(let n of e.rows)t=Math.max(t,n.bp);return{maxX:e.origin+t*ci,maxY:e.rows.length*20}}function Wo(e,t){let n=le(e),r=Ho(e,t);if(n.length===0||!r)return;let o=ce(n),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:di(r)}}var ui="Force-directed layout",re=e=>e.nodes.some(P),Yo=e=>re(e)&&(e.paths?.length??0)>1,Xo=e=>re(e)&&Ae(e),zo=e=>re(e)&&e.nodes.some(Ue),jt=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:no,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:io,cutMargins:!0,available:zo,drawsLocally:zo},{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:Wo,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:ao,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:qo,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:$o,cutMargins:!1,available:Ae,drawsLocally:Ae},{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:Do,cutMargins:!0,available:Xo,drawsLocally:Xo},{value:"force",label:ui,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,available:()=>!0,drawsLocally:()=>!1}],Oc=jt.map(e=>e.value);function vc(e,t){return!fi(e).drawsLocally(t)}function fi(e){return jt.find(t=>t.value===e)??jt[0]}function pi(e,t){let n=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=t.nodeMap.get(v(o.nodeName)),l=a===void 0?void 0:t.nodes[a],i=s;for(;i<e.path.length&&e.path[i].node!==a;)i+=1;let c=e.path[i]?.y;if(l&&c!==void 0){let f={readId:e.id,y:c,height:e.width,nodeY:l.y},d=u=>Co(l,u);for(let u of o.mismatches){let h=d(u.pos);if(h!==null){if(u.type==="insertion"){let p=s===0&&u.pos===e.firstNodeOffset||s===r.length-1&&u.pos===e.finalNodeCoverLength;n.push({...f,kind:"insertion",x:h,seq:u.seq,softClip:p})}else if(u.type==="deletion"&&u.length!==void 0){let p=d(u.pos+u.length);p!==null&&n.push({...f,kind:"deletion",x0:h,x1:p})}else if(u.type==="substitution"&&u.seq!==void 0){let p=d(u.pos+u.seq.length);p!==null&&n.push({...f,kind:"substitution",x0:h,x1:p,seq:u.seq})}}}}}),n}function ko(e){return e.reads.flatMap(t=>pi(t,e))}function Qo(e){let t=e.trim().split(/[\s,]+/),n=[],r=0,o=()=>Number(t[r++]);for(;r<t.length;){let s=t[r++];s==="M"||s==="L"?n.push({op:s,x:o(),y:o()}):s==="H"?n.push({op:s,x:o()}):s==="V"?n.push({op:s,y:o()}):s==="Q"?n.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?n.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&n.push({op:s})}return n}function Zo(e){let t=1/0,n=-1/0;for(let r of e)"x"in r&&(t=Math.min(t,r.x),n=Math.max(n,r.x)),"x1"in r&&(t=Math.min(t,r.x1),n=Math.max(n,r.x1));return{x0:t,x1:n}}function jo(e,t,n){let r=Qo(e);return{commands:r,color:t,alpha:n,...Zo(r)}}function Vo(e,t){let{shapes:n}=e,r=[...n.rectangles,...n.verticalRectangles].filter(a=>a.type===t).map(a=>({color:a.color,alpha:a.alpha??1,x0:a.xStart,x1:a.xEnd+1,y0:a.yStart,y1:a.yEnd+1})),o=To(n.curves,t).map(a=>jo(a.path,a.color,a.alpha??1)),s=n.corners.filter(a=>a.type===t).map(a=>jo(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function qc(e){let t=[];return e.nodes.forEach(n=>{if(n.order>=0){let r=Qo(_o(n));t.push({name:n.name,commands:r,...Zo(r)})}}),{layers:[Vo(e,"haplotype"),Vo(e,"read")],nodes:t,mismatches:ko(e).filter(n=>n.kind!=="insertion"||!n.softClip)}}function Ko(e,t,n,r){let o=0,s=0;for(let a of t)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(n(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(n(o),r(s));break;case"H":o=a.x,e.lineTo(n(o),r(s));break;case"V":s=a.y,e.lineTo(n(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),r(a.y1),n(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(n(a.x1),r(a.y1),n(a.x2),r(a.y2),n(o),r(s));break;case"Z":e.closePath();break}}function Uo(e,t,n,r){let o=new Map;for(let s of t)if(n(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}function Fc(e,t,n){let{x:r,y:o,width:s}=n,a=c=>r(c.x1)>=0&&r(c.x0)<=s;for(let c of t.layers)Uo(e,c.rects,a,f=>{let d=r(f.x0),u=o(f.y0);e.rect(d,u,r(f.x1)-d,o(f.y1)-u)}),Uo(e,c.shapes,a,f=>{Ko(e,f.commands,r,o)});let l=n.darkMode?"#d0d0d0":"#000000",i=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,n.yScale));for(let c of t.nodes)if(a(c)){let f=c.name===n.highlightNode;e.beginPath(),Ko(e,c.commands,r,o),e.fillStyle=f?"rgba(255,192,203,0.5)":i,e.strokeStyle=f?"#ff0000":l,e.fill(),e.stroke()}gi(e,t.mismatches,n)}var hi=12,mi=6;function gi(e,t,{x:n,y:r,yScale:o,width:s,darkMode:a}){let l=hi*o;if(l<mi||t.length===0)return;let i=(c,f)=>n(f)>=0&&n(c)<=s;e.fillStyle="grey",e.beginPath();for(let c of t)if(c.kind==="deletion"&&i(c.x0,c.x1)){let f=n(c.x0),d=r(c.y);e.rect(f,d,n(c.x1)-f,r(c.y+c.height)-d)}e.fill(),e.font=`${l}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let c of t)c.kind==="substitution"&&i(c.x0,c.x1)?e.fillText(c.seq,n(c.x0)+1,r(c.y+c.height)):c.kind==="insertion"&&i(c.x,c.x)&&e.fillText("*",n(c.x)-3,r(c.y+c.height))}function yi(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function xi(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0)),s=Array.from({length:n+1},()=>new Array(r+1).fill(!1));for(let l=n-1;l>=0;l--)for(let i=r-1;i>=0;i--){let c=Math.abs(e[l]-t[i])+o[l+1][i+1],f=n-l>r-i?o[l+1][i]:1/0,d=r-i>n-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,f,d),s[l][i]=o[l][i]===c}let a=new Array(n).fill(void 0);for(let l=0,i=0;l<n&&i<r;)s[l][i]?a[l++]=i++:n-l>r-i?l++:i++;return a}function er(e,t){return e.map((n,r)=>({item:n,i:r})).sort((n,r)=>t(n.item)-t(r.item))}var tr=e=>e.spanningReads!==0;function Mi(e,t){let n=new Map,r=new Set,o=er(e,a=>a.bp),s=[[o.filter(a=>a.item.complete),t.filter(tr)],[o,t]];for(let[a,l]of s){let i=a.filter(f=>!n.has(f.i)),c=er(l.filter(f=>!r.has(f)),f=>f.bp);xi(i.map(f=>f.item.bp),c.map(f=>f.item.bp)).forEach((f,d)=>{if(f!==void 0){let u=i[d],h=c[f].item;r.add(h),n.set(u.i,{...h,agrees:u.item.complete&&tr(h)?yi(u.item.bp,h.bp):void 0})}})}return n}function Yc(e,t){if(!t)return e;let n=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=t[o];if(a)for(let[l,i]of Mi(s,a))n.set(s[l],i)}return e.map(o=>({...o,call:n.get(o)}))}var nr=ge(Ve(),1),kc=(0,ne.createSvgIcon)((0,nr.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{ne as a,qs as b,At as c,xe as d,_l as e,Ol as f,vl as g,Bl as h,Ei as i,gn as j,yn as k,Ze as l,xn as m,Js as n,Ci as o,Oi as p,vi as q,Bi as r,Tn as s,Hr as t,vn as u,Xi as v,Ho as w,di as x,De as y,Kr as z,jt as A,Oc as B,vc as C,fi as D,ji as E,Fn as F,ws as G,al as H,il as I,qc as J,Fc as K,bi as L,Yc as M,ul as N,fl as O,Ps as P,pl as Q,hl as R,Tt as S,Rl as T,Al as U,kc as V};
2
- //# sourceMappingURL=chunk-J7CABMMI.js.map