jbrowse-plugin-graphgenomeviewer 4.0.22 → 4.0.23

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 (50) hide show
  1. package/dist/chunks/AddTrackWorkflow-WYRVQYH2.js +2 -0
  2. package/dist/chunks/{AddTrackWorkflow-NKKGI6SM.js.map → AddTrackWorkflow-WYRVQYH2.js.map} +1 -1
  3. package/dist/chunks/{GbzBaseSyntenyAdapter-HNETLUW4.js → GbzBaseSyntenyAdapter-7ZKFAEJG.js} +2 -2
  4. package/dist/chunks/{GraphGenomeView-GMHRO7E4.js → GraphGenomeView-QXKHSZQJ.js} +2 -2
  5. package/dist/chunks/{GraphGenomeView-GMHRO7E4.js.map → GraphGenomeView-QXKHSZQJ.js.map} +1 -1
  6. package/dist/chunks/LinearGraphDisplay-GMMLJWQ6.js +2 -0
  7. package/dist/chunks/{LinearGraphDisplay-I2OOPQKB.js.map → LinearGraphDisplay-GMMLJWQ6.js.map} +1 -1
  8. package/dist/chunks/{MinigraphBubbleAdapter-FIFZYJ27.js → MinigraphBubbleAdapter-NRDD66AK.js} +2 -2
  9. package/dist/chunks/chunk-75CO6QJZ.js +2 -0
  10. package/dist/chunks/chunk-75CO6QJZ.js.map +7 -0
  11. package/dist/chunks/chunk-NSXARD3R.js +3 -0
  12. package/dist/chunks/chunk-NSXARD3R.js.map +7 -0
  13. package/dist/chunks/chunk-QSH263Y6.js +2 -0
  14. package/dist/chunks/{chunk-DMYUVGGI.js.map → chunk-QSH263Y6.js.map} +4 -4
  15. package/dist/chunks/chunk-SCMIJAAX.js +3 -0
  16. package/dist/chunks/chunk-SCMIJAAX.js.map +7 -0
  17. package/dist/chunks/chunk-XK7OPCRQ.js +2 -0
  18. package/dist/chunks/chunk-XK7OPCRQ.js.map +7 -0
  19. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -1
  20. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  21. package/package.json +2 -2
  22. package/src/GraphGenomeView/components/BubbleHalos.tsx +2 -10
  23. package/src/GraphGenomeView/components/FacetPanels.tsx +50 -95
  24. package/src/GraphGenomeView/components/GraphCanvas.tsx +33 -350
  25. package/src/GraphGenomeView/components/GraphToolbar.tsx +6 -2
  26. package/src/GraphGenomeView/components/ReferenceStripOverlay.tsx +2 -9
  27. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +2 -9
  28. package/src/GraphGenomeView/components/UnpopButton.tsx +1 -2
  29. package/src/GraphGenomeView/components/WalkKey.tsx +52 -0
  30. package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +1 -9
  31. package/src/GraphGenomeView/components/WalkSelect.tsx +2 -2
  32. package/src/GraphGenomeView/components/legendStyles.ts +11 -0
  33. package/src/GraphGenomeView/components/usePaneGestures.ts +274 -0
  34. package/src/GraphGenomeView/model.test.ts +67 -1
  35. package/src/GraphGenomeView/model.ts +254 -176
  36. package/src/LinearGraphDisplay/model.ts +2 -0
  37. package/src/version.ts +1 -1
  38. package/dist/chunks/AddTrackWorkflow-NKKGI6SM.js +0 -2
  39. package/dist/chunks/LinearGraphDisplay-I2OOPQKB.js +0 -2
  40. package/dist/chunks/chunk-2PYVZZ3R.js +0 -3
  41. package/dist/chunks/chunk-2PYVZZ3R.js.map +0 -7
  42. package/dist/chunks/chunk-D7XFR2IV.js +0 -2
  43. package/dist/chunks/chunk-D7XFR2IV.js.map +0 -7
  44. package/dist/chunks/chunk-DMYUVGGI.js +0 -3
  45. package/dist/chunks/chunk-JXSDDOKD.js +0 -3
  46. package/dist/chunks/chunk-JXSDDOKD.js.map +0 -7
  47. package/dist/chunks/chunk-OSTJHAAK.js +0 -2
  48. package/dist/chunks/chunk-OSTJHAAK.js.map +0 -7
  49. /package/dist/chunks/{GbzBaseSyntenyAdapter-HNETLUW4.js.map → GbzBaseSyntenyAdapter-7ZKFAEJG.js.map} +0 -0
  50. /package/dist/chunks/{MinigraphBubbleAdapter-FIFZYJ27.js.map → MinigraphBubbleAdapter-NRDD66AK.js.map} +0 -0
@@ -0,0 +1,2 @@
1
+ import{d as Et}from"./chunk-UQEPPJEO.js";import{c as xt}from"./chunk-SCMIJAAX.js";import{a as Be,f as Mt,g as wt,h as Rn,i as An,l as St,m as Lt,y as Nt,z as an}from"./chunk-VIFXYTIS.js";import{a as Xe,b as v,c as rn,d as Ie,e as ve,f as yt,h as sn}from"./chunk-EFVAQ2KM.js";import{a as on,c as bt,d as gt}from"./chunk-KULNKXPT.js";import{a as tn}from"./chunk-XEJ47DLD.js";import{a as nn,b as se}from"./chunk-FY3BTKY4.js";var At=nn((Ll,Rt)=>{Rt.exports=JBrowseExports["@mui/material/SvgIcon"]});var Fs=nn((hc,so)=>{so.exports=JBrowseExports.mobx});var Qe=nn((wu,Jo)=>{Jo.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var xl=nn((Ed,Pr)=>{Pr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var ae=se(At(),1);function Al(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 Tt(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 In(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 Ot(e){let n=e[Math.floor(e.length/2)];return n?In(n,.5):void 0}function Pt(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 qr(e,n,t){let r=In(e,n),o=In(e,t),s=(t-n)/3,a=Ct(e,n),l=Ct(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 Ct(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 Gt(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([qr(r,a/s,(a+1)/s)])}return t}function vn(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 Tn(e,n){let t=e.length-1;return n==="end"?{at:e[t],inward:e[t-1]}:{at:e[0],inward:e[1]}}var kr=.5,Hr=80;function _t(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 It(e,n){return Math.max(0,n.min-e,e-n.max)}function vt(e,n,t){let r=It(e[0].x,n),o=It(e[e.length-1].x,n);return r===o?t:r<o?"start":"end"}function Xr(e,n){return{from:vt(e,_t(n),"end"),to:vt(n,_t(e),"start")}}var Yr=.75,zr=1.15,jr=.35,Vr=60;function Ur(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,c=0,f=1/0,u=-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(c)&&(c=x);let E=b*l+g*i;f=Math.min(f,E),u=Math.max(u,E)}let d=o.length?u-f:0,h=Math.max(Math.abs(c)*zr/Yr,d*jr),p=s===void 0?h:Math.min(h,s);return c<0?-p:p}function ln({scaleX:e,scaleY:n}){return n/e}var Kr=3;function Cn(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 Dt(e,n,t,r,o=Kr){let s=ln(r),a=Cn(e[e.length-1],n[0],s)??Cn(e[0],e.at(-1),s)??Cn(n[0],n.at(-1),s)??{x:1,y:0},l=[];for(let i=0;i<t;i++){let c=(i-(t-1)/2)*o;l.push({x:-a.y*c,y:a.x*c/s})}return l}function _n(e,n){return e.map(t=>({x:t.x,y:t.y*n}))}function Qr(e,n){for(let t of e)t.y0/=n,t.cy0/=n,t.cy1/=n,t.y1/=n;return e}var Zr=12,Jr=40;function Bt(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(Jr,Math.max(Zr,r/2))/Math.max(n,Number.EPSILON)}function Ft(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function es(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,c=a/i,f=l/i,u=o.x+t,d=o.y+r,h=u+c*n/3,p=d+f*n/3,m=u+c*n,b=d+f*n,g=-f*n/2,x=c*n/2;return[{x0:u,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:u,y1:d}]}function Ye(e,n,t,r,o,s,a=[],l){let i=s.scaleX,c=ln(s),f=l??(s.pixelRows?Vr:void 0);if(c!==1)return Qr(Ye(_n(e,c),_n(n,c),t,r,o*c,{scaleX:i,scaleY:i},_n(a,c),f===void 0?void 0:f*c),c);if(typeof t=="string")return es(Tn(e,t),Bt(e,i),r,o);let u=t?{from:"end",to:"start"}:Xr(e,n),d=Tn(e,u.from),h=Tn(n,u.to),p=d.at,m=h.at,b=p.x+r,g=p.y+o,x=m.x+r,E=m.y+o;if(t){let L=1,S=0;if(d.inward){let J=p.x-d.inward.x,V=p.y-d.inward.y,U=Math.hypot(J,V);U>0&&(L=J/U,S=V/U)}let M=Bt(e,i),N=-S,A=L,C=(p.x+m.x)/2+r+N*M,G=(p.y+m.y)/2+o+A*M,F=b+L*M,$=g+S*M,q=x-L*M,k=E-S*M;return[{x0:b,y0:g,cx0:F,cy0:$,cx1:F+N*M,cy1:$+A*M,x1:C,y1:G},{x0:C,y0:G,cx0:q+N*M,cy0:k+A*M,cx1:q,cy1:k,x1:x,y1:E}]}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)},M=Math.hypot(x-b,E-g),N=(Q,Z,le,Re)=>{let ce=Z.x-Q.x,ue=Z.y-Q.y,ee=Math.hypot(ce,ue),de=ee===0?0:(le*ce+Re*ue)/ee;return Math.max(0,Math.min(M*kr,Hr,de*.5))},A=m.x-p.x,C=m.y-p.y,[G,F]=Tt(L.x,L.y,p.x,p.y,N(L,p,A,C)),[$,q]=Tt(S.x,S.y,m.x,m.y,N(S,m,-A,-C)),k=a.length?Ur(b,g,x,E,a,f):0,J=M===0?1:M,V=(x-b)/J,U=(E-g)/J,Ze=-U*k,I=V*k,P=V*Math.abs(k),K=U*Math.abs(k);return[{x0:b,y0:g,cx0:G+r+Ze-P,cy0:F+o+I-K,cx1:$+r+Ze+P,cy1:q+o+I+K,x1:x,y1:E}]}}var ns=1;function Bn(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?Ye(r,o,n.from===n.to,0,0,t,Bn(e,n.bypassed)):void 0}function ts(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 os(e,n,t){let r=[];if(e)for(let o=yt(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 rs(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 Il(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=ts(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,[c,f]=i?[a,l]:[l,a],u=c.stable.start+c.length,d=f.stable.start,h=d-u;if(h>=ns&&rs(s,a,l,i)){let p=c.stable.refName;r.push({edgeIndex:o,from:s.from,to:s.to,refName:p,start:u,end:d,bp:h,bypassed:os(t.get(p),u,d)})}}}return r}function Oe(e){return e.endsWith("-")?"-":"+"}function Wt(e){return e==="+"?"-":"+"}function ss(e){let n=(e.fromStrand??Oe(e.from))===Oe(e.from)?"end":"start",t=(e.toStrand??Oe(e.to))===Oe(e.to)?"start":"end";return{from:n,to:t}}function Ol(e){let n=e.edges.map(ss),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])),c=[];for(let d of e.nodes){if(a.get(d.id)!==d.id)continue;let h=l.get(d.id);if(!h){c.push(d);continue}let p=h.map(g=>i.get(g)),m=p.filter(v),b=m.length?m.reduce((g,x)=>g.stable.start<=x.stable.start?g:x):p[0];c.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,u=[];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),u.push({from:p,to:m,...b.from==="start"?{fromStrand:Wt(Oe(p))}:{},...b.to==="end"?{toStrand:Wt(Oe(m))}:{}}))}),{graph:{...e,nodes:c,edges:u,paths:void 0,pathVisits:void 0},runs:l}}function Pl(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=Pn(a),i=l.at(-1),c=s.map(d=>Math.max(t(d),0)),f=c.reduce((d,h)=>d+h,0)||s.length,u=0;s.forEach((d,h)=>{let p=f?c[h]/f*i:i/s.length,m=h===s.length-1?i:u+p;r[d]=kt(a,l,u,m),u=m})}return r}function Gl(e,n,t){if(e.length===0)return[];let r=Pn(e),o=r.at(-1);return kt(e,r,n*o,t*o)}function qt(e){let n=Pn(e);return On(e,n,n.at(-1)/2)}function Pn(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 On(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 kt(e,n,t,r){let o=[On(e,n,t)];for(let s=0;s<e.length;s++)n[s]>t&&n[s]<r&&o.push({...e[s]});return o.push(On(e,n,r)),o}function as(e){return e.length*6.2+8}function is(e,n){return e.x0<n.x1&&e.x1>n.x0&&e.y0<n.y1&&e.y1>n.y0}function Ht(e,n){return e.x1<=0||e.x0>=n.width||e.y1<=0||e.y0>=n.height}function ls(e,n){return e.x0>=0&&e.x1<=n.width&&e.y0>=0&&e.y1<=n.height}function Gn(e,n=[]){let t=[...n];return r=>Ht(r,e)||t.some(o=>is(o,r))?!1:(t.push(r),!0)}function cn(e,n,t){let r=[];for(let s of e){let a=as(s.text),l=s.y>n.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(Ht(f,n))break;if(ls(f,n)&&t(f)){r.push({...s,y:c,w:a});break}}}return r}var cs=26,us=4e4,ds=8,fs=8,ps=5.7,hs=6,ms=13,ze=3,un=2;function pn(e){return(e.length*ps+hs+ze)/2}var pe=(ms+ze)/2,bs=pn("1 bp");function dn(e,n,t){return{x0:n-e,x1:n+e,y0:t-pe,y1:t+pe}}function jt(e,n){return{x0:6,x1:6+e.length*6.2+8+ze,y0:n-8-ze/2,y1:n+8+ze/2}}function fn(e,n,t){return t<n?e:Math.min(Math.max(e,n),t)}function hn(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:e>=1e3?`${+(e/1e3).toFixed(1)} kb`:`${e} bp`}function Xt(e){return`${hn(e)} del`}function gs(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 ys(e,n){return Math.abs(n.x)*(e.x1-e.x0)/2+Math.abs(n.y)*(e.y1-e.y0)/2}function xs(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 Ms(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 ws(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 Yt=new WeakMap;function Ss(e,n){let t=Yt.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 Yt.set(e,{nodeLengths:n,order:r}),r}var zt=new WeakMap;function Ls(e,n,t,r){let{scaleX:o,scaleY:s}=t,a=zt.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((c,f)=>f.bp-c.bp)){let c=$t(e,i,t),f=c?Ot(c):void 0;if(c&&f){let{minX:u,minY:d,maxX:h,maxY:p}=Pt(c);l.push({deletion:i,curves:c,apex:f,extent:Math.max((h-u)*o,(p-d)*s)})}}return zt.set(e,{deletions:n,scaleX:o,scaleY:s,version:r,arcs:l}),l}function Vt({nodePositions:e,nodeLengths:n,deletions:t,alleleDeletions:r,axis:o,translateX:s,translateY:a,width:l,height:i,version:c=0}){let{scaleX:f,scaleY:u}=o,d=[],h=[];for(let{deletion:b,curves:g,apex:x,extent:E}of Ls(e,t,o,c))if(E>=cs){let L=Xt(b.bp),S=pn(L),M=dn(S,0,0),N=x.x*f+s,A=x.y*u+a,C=E>=S*2/un,G=gs(g,x,f,u),F=ys(M,G)+fs,$=C?N:fn(N+G.x*F,S,l-S),q=C?A:fn(A+G.y*F,pe,i-pe),k=Math.hypot($-N,q-A),J;if(k>0){let V={x:($-N)/k,y:(q-A)/k},U=xs(M,V);J={arcX:N,arcY:A,labelX:$-V.x*U,labelY:q-V.y*U}}d.push({label:{key:`del:${b.edgeIndex}`,text:L,x:$,y:q,kind:"deletion",leader:J},box:dn(S,$,q)})}let p=new Set,m=[...r??[]].sort((b,g)=>g.bp-b.bp);for(let b of m){let g=ws(b.nodeIds,e);if(!g)continue;let x=Math.max(g.minX*f+s,0),E=Math.min(g.maxX*f+s,l),L=Math.max(g.minY*u+a,0),S=Math.min(g.maxY*u+a,i);if(E<x||S<L)continue;let M=Math.max(E-x,S-L),N=Xt(b.bp),A=pn(N);if(M>=A*2/un){for(let F of b.nodeIds)p.add(F);let C=fn((x+E)/2,A,l-A),G=fn((L+S)/2,pe,i-pe);d.push({label:{key:`alleledel:${b.nodeIds.join(",")}`,text:N,x:C,y:G,kind:"deletion"},box:dn(A,C,G)})}}for(let[b,g]of Ss(e,n)){if(p.has(b))continue;let{x,y:E}=qt(g),L=E*u+a;if(L+pe<=0||L-pe>=i)continue;let S=Ms(g,f,u);if(S<bs*2/un)continue;let M=hn(n.get(b)),N=pn(M);if(S>=N*2/un){let A=x*f+s;h.push({label:{key:`node:${b}`,text:M,x:A,y:L,kind:"node"},box:dn(N,A,L)})}}return{deletions:d,nodes:h}}function Ut(e,n){return Math.max(ds,Math.floor(e*n/us))}function Dn(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 As=3.4,Kt=6,Ts=8,Cs=18,_s=2,Is=15;function Qt(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function zl(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}),c=e.drawnRowLabels.map(({label:M,y:N})=>jt(M,N*a+o)),f=e.referenceStripZonePx??0;f>0&&c.push({x0:0,x1:n,y0:0,y1:f}),e.legendSize.width>0&&c.push({x0:n-Kt-e.legendSize.width,x1:n,y0:0,y1:f+Kt+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*6.2*1.2,y0:0,y1:44});let u=Gn(l,c),d=e.drawnRowLabels.length>0,h=d?Math.min(...e.drawnRowLabels.map(M=>M.y)):1/0,p=e.contigThickness*As,m=Qt(e.bubbleHalos,M=>M.members),b=cn(m.map(M=>{let{x:N,y:A}=i({x:M.labelAt.x,y:Math.min(M.labelAt.y,h)}),C=A-p/2-6;return{item:M,x:N,y:d?Math.max(C,Is):C,text:M.label}}),l,u),g=cn(Qt(e.genePins,M=>M.gene.end-M.gene.start).map(M=>{let{x:N,y:A}=i(M.at);return{item:M,x:N,y:A+e.contigThickness+Cs,text:M.covered<.98?`${M.gene.name} \u2026`:M.gene.name,stack:_s}}),l,u),x=e.nodePositions&&e.labelsNodeSizes?Vt({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:[]},E=Dn(x.deletions,u),L=cn(m.flatMap(M=>M.routes.map(N=>{let{x:A,y:C}=i(N.at);return{item:{halo:M,route:N},x:A,y:C+4,text:N.text,stack:Ts}})),l,u),S=Dn(x.nodes,u,Ut(n,t));return{bubbles:b,genes:g,routes:L,sizes:[...E,...S]}}function Kl(e){return Xe(e)?Zt(e):void 0}function Zt(e){return{sample:on(e.stable.refName),haplotype:bt(e.stable.refName),refName:gt(e.stable.refName),start:e.stable.start,end:e.stable.start+e.length}}function vs(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 Bs(e){return`${e.haplotype??e.sample}\0${e.refName}`}function Ql(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Xe(o)){let s=Zt(o),a=Bs(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=vs(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 Os(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function Zl(e,n){return e.flatMap(t=>{let r=Os(n,t);return r===void 0?[]:[{...t,sample:r}]})}function Jl(e){return`${e.refName}:${e.start+1}-${e.end}`}function Fn(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var Jt=se(tn(),1),eo=(0,ae.createSvgIcon)((0,Jt.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var no=se(tn(),1),to=(0,ae.createSvgIcon)((0,no.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 oo=se(tn(),1),$n=(0,ae.createSvgIcon)((0,oo.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 Ps="Linear genome view",Gs="Linear synteny view",Ds="No synteny track in this session aligns these assemblies";function ro({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(c=>({label:r(c),onClick:o(c)}))}]}function dc({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...ro({label:Ps,icon:$n,entries:e,entryLabel:s=>`${s.sample} ${Fn(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?ro({label:`${Gs} (${o} assemblies)`,icon:eo,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:Ds,onSelect:s=>()=>{r(s.trackId)}}):[]]}function fc({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${Fn(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:to,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:$n,onClick:()=>{r(l)}}))]}function Wn(e){return e.id.endsWith("-")?"-":"+"}function qn(e,n){return n===Wn(e)?e.id:`-${e.id}`}function $s(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 Ws(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=$s(n,e.pathLength),o=(l,i=!1)=>{for(let c=0;c<r.length;c++){let f=r[c],u=n[c];if(f!==void 0&&u!==void 0&&f<=l&&(l<f+u||i&&l===f+u))return{s:c,local:l-f,room:f+u-l}}},s=(l,i)=>{let c=t[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 xt(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 t}function ao(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,u)=>f?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let f=Ws(s,a.map(h=>h?.length)),u=l.map(h=>qn(a[h],s.path[h].strand)),d=a[c].length;o.push({id:t+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:l.map((h,p)=>({nodeName:u[p],mismatches:f[h]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:c===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 qs=["#6baed6","#4292c6","#2171b5","#08519c"],ks=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function io(e){let n=e.is_reverse?ks:qs;return n[e.id%n.length]}var Hs=4;function je(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 Xs({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<Hs&&o.length>0;l++){let i=[];for(let c of o){let f=t.get(c);if(f){for(let u of f)if(!r.has(u)){r.add(u);let d=n.get(u);d&&v(d)?(s=Math.min(s,d.stable.start+d.length),a=Math.max(a,d.stable.start)):i.push(u)}}}o=i}return s===1/0?void 0:{start:Math.min(s,a),end:Math.max(s,a)}}function Ys({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}:Xs({nodeId:e,nodeById:n,neighbors:t})}function lo(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=je(e),r=new Map;for(let o of e.nodes){let s=Ys({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}function mn(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 zs(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 c of t.get(l)??[]){let f=n.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 js(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 Vs(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 c=o.get(i);(c===void 0||l<c)&&(o.set(i,l),s.push(i))}}return o}function Us(e,n,t){let r=Vs(e,n,t),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 u of t.get(c.id)??[]){let d=a.get(u);d&&s.get(u)<i&&(f=Math.max(f,l.get(u)+d.length))}l.set(c.id,f)}return{offsets:l,ordered:o}}function uo(e){let n=new Map(e.nodes.filter(Xe).map(s=>[s.id,s])),t=je(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}=zs(s.id,n,t,r),i=js(l);if(i){let{offsets:c,ordered:f}=Us(a,i.entry,t);o.push({start:i.start,refSpan:i.end-i.start,nodeIds:f.map(u=>u.id),nodeOffsets:f.map(u=>c.get(u.id)),pathLength:f.reduce((u,d)=>Math.max(u,c.get(d.id)+d.length),0)})}}return o.sort((s,a)=>s.start-a.start)}var Ks=1,Qs=.015;function bn({graph:e,span:n,rowY:t,positions:r}){let o=n*Qs,s=uo(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let u=f.refSpan-f.pathLength;u>=Ks&&l.push({nodeIds:f.nodeIds,bp:u});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,E=S=>f.start+S*h,L=t(b);r[p]=h?[{x:E(g),y:L},{x:E(g+b.length),y:L}]:[{x:f.start+m*x,y:L},{x:f.start+(m+1)*x,y:L}]}})}let i=je(e),c=Object.keys(r);for(let f of c){let u=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:u,y:p},{x:u+o,y:p}],c.push(d)}}}return l}function Zs(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 fo(e,n){let t=Ie(e);if(t.length===0)return;let r=sn(t,n),o=Zs(e),s=ve(t),a=bn({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 Js=12,kn=20;function po(e){return 10+8*Math.log2(1+e.length)}function he(e,n){return e<n?-1:e>n?1:0}function mo(e,n){return he(e.at,n.at)||he(e.side,n.side)||he(e.hops,n.hops)}var ho={at:1/0,side:0,hops:0};function ea(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=oa(e);return e.nodes.map(r=>r.id).sort((r,o)=>mo(t.get(r)??ho,t.get(o)??ho)||he(n.get(r).name,n.get(o).name)||he(r,o))}function na(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,u)=>{s.set(f.id,n[u-1]?.id),o.set(f.id,n[u+1]?.id)});let a=n[0]?.id,l=(f,u)=>{let d=o.get(f);o.set(f,u),s.set(u,f),o.set(u,d),d!==void 0&&s.set(d,u)},i=(f,u)=>{let d=s.get(f);d===void 0?(a=u,s.set(u,void 0),o.set(u,f),s.set(f,u)):l(d,u)};for(let f of e.paths??[]){let u=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?u++:d++),h=x)}let p=d>u?[...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 c=[];for(let f=a;f!==void 0;f=o.get(f))c.push(f);return c}function ta(e,n){let t=[...n.entries()].sort(([a,l],[i,c])=>mo(l,c)||he(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 c=!0;for(let f of i){let{hops:u}=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<=u,s.has(p)||(s.add(p),i.push(p))):m.at!==l&&(h||=m.at<l,c&&=m.at<l)}c&&=!d||h}if(c)for(let f of i){let u=n.get(f);n.set(f,{...u,side:-1,hops:-u.hops})}}}function oa(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)=>he(s.stable.start,a.stable.start)||he(s.name,a.name)),o=new Map;return na(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),ta(t,o),o}function ra(e){let n=new Map(e.nodes.map(u=>[u.id,u])),t=ea(e),r=new Map(t.map((u,d)=>[u,d])),o=u=>v(n.get(u)),s=new Map(t.map(u=>[u,[]])),a=new Map(t.map(u=>[u,[]])),l=(u,d)=>{s.get(d).push(u),a.get(u).push(d)};for(let u of e.edges)u.from===u.to||!r.has(u.from)||!r.has(u.to)||(r.get(u.from)<r.get(u.to)?l(u.from,u.to):l(u.to,u.from));let i=t.filter(o);for(let u=1;u<i.length;u++)l(i[u-1],i[u]);let c=new Map;for(let u of t){let d=0;for(let h of s.get(u))d=Math.max(d,c.get(h)+1);c.set(u,d)}for(let u=t.length-1;u>=0;u--){let d=t[u],h=a.get(d);if(o(d)||h.length===0)continue;let p=1/0;for(let g of h)p=Math.min(p,c.get(g));let m=c.get(d),b=Math.max(m,p-1);c.set(d,Math.floor((m+b)/2))}let f=[];for(let u of t)(f[c.get(u)]??=[]).push(u);return{layers:f,layerOf:c,preds:s}}function bo(e){if(!e.nodes.some(v))return;let n=new Map(e.nodes.map(u=>[u.id,u])),t=u=>v(n.get(u)),{layers:r,layerOf:o,preds:s}=ra(e),a=r.map(u=>{let d=0;for(let h of u)d=Math.max(d,po(n.get(h)));return d}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+Js;let c=new Map;for(let u of r){let d=[];for(let p of u){if(t(p)){c.set(p,0);continue}let m=s.get(p).filter(g=>c.has(g)),b=0;for(let g of m)b+=c.get(g)/m.length;d.push({id:p,ideal:b===0?kn: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/kn);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),c.set(p,b*kn)}}let f={};for(let u of e.nodes){let d=o.get(u.id),h=po(u),p=l[d]+a[d]/2,m=c.get(u.id);f[u.id]=[{x:p-h/2,y:m},{x:p+h/2,y:m}]}return{nodePositions:f,referenceAxis:!1,pixelRows:!0}}function sa(e,n){let t=new Map;for(let o of e.nodes)if(rn(o)){let{sample:s}=mn(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 go(e,n,t=[]){let r=Ie(e),o=sa(e,t);if(r.length===0||o.length===0)return;let s=sn(r,n),a=new Map(o.map((d,h)=>[d,h+1])),l=ve(r),i=o.length+1,c=bn({graph:e,span:s,rowY:d=>{let h=d.stable;return((h?a.get(mn(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:mn(r[0].stable.refName).sample,y:0},...o.map(d=>({label:d,y:a.get(d)*20}))];return{nodePositions:l,rowLabels:u,sampleRows:o,referenceAxis:!0,pixelRows:!0,alleleDeletions:c}}function Hn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Ke=!1,yo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Oo(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=>yo[n.id%yo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var B=Oo({}),Vn=null,y=[],w=[],R=[],_=new Map,De=[],T=[],Me=[],Kn=[],Qn=[],ne=-1,D=Hn(),Un={minX:0,maxX:0,minY:0,maxY:0},Ve,gn=new Map;function Po(e,n,t=[],r={}){if(B=Oo(r),Vn=r.bed??null,D=Hn(),Me=[],Kn=[],Qn=[],De=[],Un={minX:0,maxX:0,minY:0,maxY:0},Ve=void 0,gn=new Map,e.length===0||n.length===0)return;let o=Xn(e);y=[],o.forEach((i,c)=>{y[c+1]=i}),w=Xn(n);let s=t.length>0;R=Xn(za(t));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&&(Ve=c.name)}if(w.length===0)return;ia(0),_=wo(),Pe(w),B.showReads&&R.length>0&&Pe(R),Bo(),B.mergeNodesFlag&&(So(),zn(),B.showReads&&R.length>0&&Yn(),Ya(),_=wo(),Bo(),Pe(w),B.showReads&&R.length>0&&Pe(R)),So(),Ta(),Ke&&console.log(`${y.length} nodes.`),zn(),ne=Eo(),Ca(),zn(),ne=Eo();let a=B.showReads&&B.coarsenedReadView&&!s;if(a){let i=Ve===void 0?-1:w.findIndex(u=>u.name===Ve),c=i===-1?0:i,f=w.filter((u,d)=>d!==c);if(f.length>0){let u=Co(f,"haplotype");u.length>0&&(w=[w[c]],R=u)}}$a(),Ba(),B.showExonsFlag&&Vn!==null&&Fa();let l=B.showReads&&B.coarsenedReadView&&R.length>0&&!a;return B.showReads&&R.length>0?(la(),Yn(),Pe(R),l&&(R=Co(R,"read"),Yn(),Pe(R)),ua(),w=w.concat(R)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),Ia(),ka(),Ke&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(Me)),Sa(),{nodes:y,tracks:w,reads:R,nodeMap:_,shapes:D,bounds:Un,maxOrder:ne,trackForRuler:Ve,coarsenedEdgeMeta:gn}}function Ge(e,n="plain"){return B.trackColor(e,n)}function aa(e){return B.trackAlpha(e)}function Xn(e){return structuredClone(e)}function X(e){let n=String(e);return n.length>=1&&n.startsWith("-")}function O(e){return X(e)?String(e).substring(1):e}function me(e){return X(e)?e:`-${e}`}function Go(e){return X(e)?O(e):me(e)}function yn(e){return(e||1/e)>=0}function ia(e){let n=new Set,t=w[e].sequence;for(let r=0;r<t.length;r+=1){let o=t[r];if(X(o)){let s=O(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];X(s)?n.has(O(s))&&(t[o]=O(s)):n.has(s)&&(t[o]=me(s))}}y.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function la(){De=[];for(let n=0;n<=ne;n+=1)De[n]=[];let e=new Map;y.forEach(n=>{n.y!==void 0&&xo(e,n.order,n.y+n.contentHeight)}),w.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{xo(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,De[n.order].push(t))})}function xo(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var xn=7;function ca(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),R.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=xn),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 ua(){ya(),ca();let e=y.slice();e.sort(Mn);let n=new Map;for(let a=0;a<R.length;a++){let l=R[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?xn:0;e.forEach(a=>{if(a)for(let l of t)da(n.get(l),a,r)});let o=ga(),s=[];R.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 u=new Array(i),d;for(let h=i-1;h>=0;h--){h===i-1?u[h]=void 0:u[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=c[p],b=u[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(pa),s.forEach(a=>{let l=R[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Ke&&(console.log("Reads:"),console.log(R))}function da(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=R[m].path,x=b+1,E;for(let L=1;L<=b;L++){let S=g[b-L]?.y;if(S!==void 0){x=L,E=S;break}}return{entry:p,decisionStep:x,y:E}});i.sort(fa),o=i.map(p=>p.entry);let c=l,f=new Map;o.forEach(p=>{let m=R[p[0]];m.path[p[1]].y=c,Mo(f,m,p[1],c,n),c+=m.width});let u=c;s.sort(ha);let d=new Map;c=l,s.forEach(p=>{let m=R[p[0]],b=m.firstNodeOffset??0;m.path[p[1]].y=c,d.set(c,b);let g=f.get(c);g===void 0||g+1<=b?(c+=m.width,u=Math.max(u,c)):(f.set(c,0),o.forEach(x=>{let E=R[x[0]],L=E.path[x[1]];L.y!==void 0&&L.y>=c&&(L.y+=m.width,Mo(f,E,x[1],L.y,n))}),c+=m.width,u+=m.width)}),a.sort(ba),a.forEach(p=>{let m=R[p],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(c=l;b<(f.get(c)??-1/0)+2||g>(d.get(c)??1/0)-3;)c+=m.width||xn;m.path[0].y=c,f.set(c,g),u=Math.max(u,c)});let h=u-n.y-n.contentHeight;n.contentHeight+=h,Da(n,h)}function fa(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 pa(e,n){let t=R[e.readIndex],r=R[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],c=y[n.previousNode];if(i&&c&&i.order!==c.order)return i.order-c.order}let a=e.previousY??0,l=n.previousY??0;return o.betweenCycleReverseTraversal&&s.betweenCycleReverseTraversal?l-a:a-l}function ha([e,n],[t,r]){let o=R[e],s=R[t],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[n]?.node,u=s.path[r]?.node,d=f!=null?y[f]:null,h=u!=null?y[u]: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?Mn(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 ma(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,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 ba(e,n){let t=R[e],r=R[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 ga(){let e=[];for(let n=0;n<=ne;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 ya(){R.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=yn(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=yn(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 Yn(){R.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]=O(e.sequence[a]);let t=e.sequenceNew??[];t.reverse(),e.sequenceNew=t;for(let a of t)a.nodeName=O(a.nodeName),xa(a.mismatches,ie(a.nodeName).sequenceLength);let r=e.firstNodeOffset??0,o=ie(e.sequence[0]).sequenceLength;e.firstNodeOffset=o-(e.finalNodeCoverLength??0);let s=ie(e.sequence[e.sequence.length-1]).sequenceLength;e.finalNodeCoverLength=s-r}})}function xa(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=Do(t.seq).split("").reverse().join(""))})}var Ma={A:"T",T:"A",C:"G",G:"C"};function Do(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=Ma[e.charAt(t)]??"N";return n}function Pe(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=_.get(O(r)),s=y[o]?.switched??!1;s&&(r=Go(r));let a=_.get(O(r));if(a===0)throw new Error("Node "+O(r)+" has prohibited index 0");X(r)!==s?n.indexSequence.push(-a):n.indexSequence.push(a)})})}var wa=20;function Sa(){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+wa+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)})}),Un=e}function ie(e){let n=_.get(O(e)),t=n===void 0?void 0:y[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function wo(){return _=new Map,y.forEach((e,n)=>{e&&_.set(e.name,n)}),_}function So(){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&&R.length>0&&R.forEach(t),y.forEach((r,o)=>{r&&(r.successors=Array.from(e[o]),r.predecessors=Array.from(n[o]))})}function Lo(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 La(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 Ea=-1;function Na(e){let n=[];for(let t of e)n.push(t??Ea);return n}function zn(){let e,n,t,r,o=0,s=B.showReads&&R.length>0?w.concat(R):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)}),Lo(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Ke&&console.log(`generating order for track ${i+1}`),t=La(s[i].indexSequence),t===null){s[i].type==="haplotype"?Lo(s[i].indexSequence):(s.splice(i,1),R.splice(i-w.length,1),i-=1);continue}for(e=Aa(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 c=r+1;c<t;c+=1)T[e[c]]=n,n+=1;if(T[e[t]]>T[e[r]])T[e[t]]<n&&No(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!Ra(e[t],e[r],a))No(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 c=r+1;c<t;c+=1)T[e[c]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=T[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let f=e[c];T[f]===void 0&&(T[f]=n,n+=1)}}else{n=T[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let f=e[c];T[f]===void 0&&(T[f]=n,o=Math.min(o,n),n-=1)}}}}o<0&&Zn(-o);let l=Na(T);T=l,l.forEach((i,c)=>{let f=y[c];f!==void 0&&(f.order=i)})}function Ra(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 Eo(){let e=-1;return T.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function Aa(e){return e.map(n=>Math.abs(n))}function Zn(e){T.forEach((n,t)=>{n!==void 0&&(T[t]=n+e)})}function No(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(c=>{T[c]>i&&c!==n&&o.push([c,l+1])}),a!==e&&y[a].predecessors.forEach(c=>{T[c]>i&&c!==n&&o.push([c,l+1])}))}r.forEach((a,l)=>{T[l]=a})}function Ta(){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 Ca(){let e=w[0],n=w.slice(1,w.length);if(B.showReads&&R.length>0&&(n=n.concat(R)),_a(n,e),B.showReads&&R.length>0){for(let t=0;t<R.length;t++)if(R[t]!==n[t+w.length-1])throw new Error("Read inequality")}}function _a(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=O(s[a]),i=ie(l);if(r&&!r.has(l)){let c=a>0?ie(s[a-1]).order:void 0,f=a<s.length-1?ie(s[a+1]).order:void 0;(c===void 0||c<i.order)&&(f===void 0||i.order<f)&&Ro(t,l,X(s[a])?1:-1),(c===void 0||c>i.order)&&(f===void 0||i.order>f)&&Ro(t,l,X(s[a])?-1:1)}}}for(let o of e)o.sequence.forEach((s,a)=>{let l=t.get(O(s));l!==void 0&&l>0&&(o.sequence[a]=Go(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=ie(s);a.seq=Do(a.seq),a.switched=!0}})}function Ro(e,n,t){e.set(n,(e.get(n)??0)+t)}function Ia(){let e=0,n=20,t=-1,r=y.slice();r.sort(Mn);let o=va();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 va(){let e=[],n=[],t=[],r=[];for(let o=0;o<=ne;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<=ne;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function Ba(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=ne;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)=>{n=Math.abs(i.indexSequence[0]),t=yn(i.indexSequence[0]),r=y[n],i.path=[],i.path.push({order:r.order,lane:null,isForward:t,node:n}),H(r.order,n,c,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=yn(i.indexSequence[f]),r=y[n],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 u=o.order+1;u<r.order;u+=1)i.path.push({order:u,lane:null,isForward:!0,node:null}),H(u,null,c,e,a,l),e+=1;t?(i.path.push({order:r.order,lane:null,isForward:!0,node:n}),H(r.order,n,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:n}),H(r.order,n,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 u=o.order-1;u>r.order;u-=1)i.path.push({order:u,lane:null,isForward:!1,node:null}),H(u,null,c,e,a,l),e+=1;t?(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:n}),H(r.order,n,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!1,node:n}),H(r.order,n,c,e,a,l),e+=1)}else t!==s?(i.path.push({order:r.order,lane:null,isForward:t,node:n}),H(r.order,n,c,e,a,l),e+=1):(i.path.push({order:r.order,lane:null,isForward:!t,node:null}),H(r.order,null,c,e,a,l),e+=1,i.path.push({order:r.order,lane:null,isForward:t,node:n}),H(r.order,n,c,e,a,l),e+=1)});for(let i=0;i<=ne;i+=1)Pa(Me[i],i)}function H(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]};Me[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function Oa(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 Pa(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;Oa(e,n),e.sort(To),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(To),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}),Ga(e,r)}function Ga(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{Ao(e,o)<r&&(r=Ao(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 Da(e,n){e.order<0||Me[e.order]===void 0||(Me[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)})}),De[e.order].length>0&&De[e.order].forEach(t=>{y[t]!==e&&y[t].y>e.y&&(y[t].y+=n)}))}function Ao(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 To(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 Mn(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 Fa(){let e,n,t={};Vn.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 $a(){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 Wa(e){let n=e.path[0],t=y[n.node],r=e.firstNodeOffset??0;return Jn(t,n.isForward?r:t.sequenceLength-r)}function qa(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 Fo(e,n){return n>e.sequenceLength?null:Jn(e,n)}function Jn(e,n){let[t,r]=Xa(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 ka(){let e,n,t,r,o,s,a,l,i;for(let u=0;u<=ne;u+=1)Kn.push(0),Qn.push(0);let c=[],f=[];y.forEach(u=>{u.x!==void 0&&(c[u.order]=u.x,f[u.order]===void 0?f[u.order]=u.x+u.pixelWidth:f[u.order]=Math.max(f[u.order],u.x+u.pixelWidth))}),w.sort(ma),w.forEach(u=>{a="plain",o=Ge(u,a),s=aa(u);let d=a,h=()=>(d!==a&&(d=a,o=Ge(u,a)),o);t=u.path[0].y,u.type!=="read"?u.sequence[0].startsWith("-")?e=f[u.path[0].order]+20:e=c[u.path[0].order]-20:e=Wa(u);for(let p=0;p<u.path.length;p+=1)u.path[p].y===t?u.path[p].features!==void 0&&(i=p>0&&u.path[p-1].order===u.path[p].order,l=_o(u.path[p],c[u.path[p].order],f[u.path[p].order],a,u,e,t,o,i),a=l.highlight,e=l.xStart):(u.path[p-1].isForward?n=f[u.path[p-1].order]:n=c[u.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+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})),u.path[p].order-1===u.path[p-1].order?(e=n,n=c[u.path[p].order],r=u.path[p].y,o=h(),D.curves.push({xStart:e,yStart:t,xEnd:n+1,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=n,t=r):u.path[p].order+1===u.path[p-1].order?(e=n,n=f[u.path[p].order],r=u.path[p].y,o=h(),D.curves.push({xStart:e+1,yStart:t,xEnd:n,yEnd:r,width:u.width,color:o,alpha:s,laneChange:Math.abs(u.path[p].lane-u.path[p-1].lane),id:u.id,name:u.name,type:u.type,nodeStart:u.path[p-1]?.node,nodeEnd:u.path[p]?.node}),e=n,t=r):u.path[p-1].isForward?(r=u.path[p].y,vo(1,n,t,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=f[u.path[p].order],t=u.path[p].y):(r=u.path[p].y,vo(-1,n,t,r,u.width,o,u.id,u.path[p].order,u.type,u.name),e=c[u.path[p].order],t=u.path[p].y),u.path[p].features!==void 0&&(i=u.path[p-1].order===u.path[p].order,l=_o(u.path[p],c[u.path[p].order],f[u.path[p].order],a,u,e,t,o,i),a=l.highlight,e=l.xStart));u.type!=="read"?u.path[u.path.length-1].isForward?n=f[u.path[u.path.length-1].order]+20:n=c[u.path[u.path.length-1].order]-20:n=qa(u),D.rectangles.push({xStart:Math.min(e,n),yStart:t,xEnd:Math.max(e,n),yEnd:t+u.width-1,color:o,alpha:s,id:u.id,name:u.name,type:u.type})})}var Ha=1e9;function Co(e,n){gn=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),x=Math.abs(b),E=y[g],L=y[x];if(!E||!L)continue;let S;if(r){let N=`${m}>${b}`,A=`${-b}>${-m}`;S=N<A?N:A}else S=`${m}>${b}`;let M=t.get(S);M===void 0?t.set(S,{sSigned:m,dSigned:b,sName:m<0?`-${E.name}`:E.name,dName:b<0?`-${L.name}`:L.name,count:1,sourceTrackID:d.sourceTrackID}):M.count+=1}}let o=0;for(let d of t.values())d.count>o&&(o=d.count);let s=xn,a=60,l=d=>o<=1?s:s+(a-s)*Math.sqrt(d/o),i=[],c=0;for(let d of t.values()){let h=Ha+c,p=`${d.count.toLocaleString()} ${n}${d.count===1?"":"s"}: Node ${d.sName} \u2192 Node ${d.dName}`;gn.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}),c+=1}let f="?",u=0;for(let d of y){if(!d)continue;let h=d.contentHeight;h>u&&(u=h,f=d.name)}return Ke&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${u.toFixed(1)})`),i}function _o(e,n,t,r,o,s,a,l,i){let c=r,f,u,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=>{c!==m.type&&(f=Ge(o,c),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,u=Ge(o,m.type),D.featureRectangles.push({xStart:d,yStart:a,xEnd:h,yEnd:a+o.width-1,color:u,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,u=Ge(o,m.type),D.featureRectangles.push({xStart:h,yStart:a,xEnd:d,yEnd:a+o.width-1,color:u,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,c=m.type),(m.end<p-1||m.continue===void 0)&&(f=Ge(o,c),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,c="plain")}),{xStart:s,highlight:c}}var Io=7;function vo(e,n,t,r,o,s,a,l,i,c){let f=e===1?Qn:Kn,u=10*f[l],d=n+e*(u+5),h=Io,p=Math.min(Io,o),m=Math.min(t,r),b=Math.max(t,r),g=e===1?n:d-1,x=e===1?d:n,E=N=>{D.verticalRectangles.push({xStart:g,yStart:N,xEnd:x,yEnd:N+o-1,color:s,id:a,name:c,type:i})};E(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:c,type:i}),E(r);let L=d+e*h,S=d+e*(h+p),M=`M ${d} ${b}`;M+=` Q ${L} ${b} ${L} ${b-h}`,M+=` H ${S}`,M+=` Q ${S} ${b+o} ${d} ${b+o}`,M+=" Z ",D.corners.push({path:M,color:s,id:a,type:i}),M=`M ${d} ${m}`,M+=` Q ${S} ${m} ${S} ${m+o+h}`,M+=` H ${L}`,M+=` Q ${L} ${m+o} ${d} ${m+o}`,M+=" Z ",D.corners.push({path:M,color:s,id:a,type:i}),f[l]+=1}function Xa(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function Bo(){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 Ya(){let e,n,t=Array.from(y,()=>new Set),r=Array.from(y,()=>new Set),o;B.showReads&&R.length>0?o=w.concat(R):o=w,o.forEach(l=>{for(let i=0;i<l.sequence.length;i+=1)X(l.sequence[i])?(e=O(l.sequence[i]),i>0?(n=l.sequence[i-1],X(n)?r[_.get(e)].add(O(n)):(r[_.get(e)].add(n),r[_.get(e)].add(me(n)))):l.type==="haplotype"&&r[_.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],X(n)?t[_.get(e)].add(O(n)):(t[_.get(e)].add(n),t[_.get(e)].add(me(n)))):l.type==="haplotype"&&t[_.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[_.get(l.sequence[i])].add(e),X(e)&&t[_.get(l.sequence[i])].add(O(e))):l.type==="haplotype"&&t[_.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[_.get(l.sequence[i])].add(e),X(e)&&r[_.get(l.sequence[i])].add(O(e))):l.type==="haplotype"&&r[_.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(B.showReads&&R.length>0){let l=y.slice();l.sort(Mn);let i=new Map,c=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},u=d=>{let h=c.get(d);if(h===void 0)throw new Error(`No merge origin recorded for node ${d}`);return h};l.forEach(d=>{let h=Ue(_.get(d.name),s,a);if(h){let p=f(h)+ie(h).sequenceLength;i.set(d.name,p),i.set(me(d.name),p),c.set(d.name,u(h)),c.set(me(d.name),u(h))}else i.set(d.name,0),i.set(me(d.name),0),c.set(d.name,d.name),c.set(me(d.name),d.name)}),R.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=O(d.sequence[p]),b=Ue(_.get(m),s,a);if(b&&jn(_.get(b),s,a))if(p>0){d.sequence.splice(p,1);let g=ie(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]=u(d.sequence[0]);let g=h[0],x=f(g.nodeName);g.mismatches.forEach(E=>{E.pos+=x}),g.nodeName=u(g.nodeName)}}})}for(let l=0;l<y.length;l+=1)if(jn(l,s,a)&&!Ue(l,s,a)){let i=l;for(;jn(i,s,a);)i=_.get(O(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=O(l.sequence[i]);let c=_.get(e);Ue(c,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)Ue(l,s,a)&&y.splice(l,1)}function Ue(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=O(n[e][0]),o=_.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function jn(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=O(t[e][0]),o=_.get(r);return!(n[o].length!==1||n[o][0]==="None")}function za(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 ja(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 Va(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 $o(e,n){let t=ja(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(Va),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 u=`M ${i.xStart} ${i.yStart}`;u+=` C ${c} ${i.yStart} ${c} ${i.yEnd} ${i.xEnd} ${i.yEnd}`,u+=` V ${i.yEnd+i.width}`,u+=` C ${f} ${i.yEnd+i.width} ${f} ${i.yStart+i.width} ${i.xStart} ${i.yStart+i.width}`,u+=" Z",i.path=u})});let r=Array.from(t.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,u=i[0]??0,d=i[1]??0;return c<u?-1:c>u?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 Wo(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 Ua(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 Ka(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=Ua(e),r=(e.paths??[]).map((s,a)=>({path:s,index:a})),o=r.findIndex(s=>Be(s.path.name).name===e.referencePath);return o>0&&r.unshift(...r.splice(o,1)),r.flatMap(({path:s,index:a})=>{let l=Be(s.name).name,i=new Map,c=s.nodeIds.flatMap(f=>{let u=n.get(f);if(!u)return[];let d=i.get(u.name)??0;i.set(u.name,d+1);let h=t.get(`${l} ${u.name}`)?.[d]??Wn(u);return[qn(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Qa(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function Fe(e){return(e.paths?.length??0)>0}var Za=600,Ja=3,ei=15;function ni(e){return Math.max(Ja,Math.min(ei,Math.floor(Za/Math.max(1,e))))}function qo(e){let n=e.paths??[],t=Ka(e),r=e.reads?ao(e,e.reads,n.length):[],o=r.length>0?Lt:St,s=n.map((l,i)=>o(i,n.length)),a=Po(Qa(e),t,r,{nodeWidthOption:"compressed",trackWidth:ni(t.length),trackColor:l=>l.type==="read"?io(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function et(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function ko(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function Ho(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function Xo(e){let n=Fe(e)?qo(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of et(t))s[i.name]=ko(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=Ho(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 ti(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of et(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,c)=>i-c)){let i=r.get(l),c=1/0,f=-1/0;for(let u of i){let d=t.get(u.name);d&&v(d)&&(c=Math.min(c,d.stable.start),f=Math.max(f,d.stable.start+u.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(u=>u.x)),x1:Math.max(...i.map(u=>u.x+u.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 oi(e){return e.nodes.some(v)&&Fe(e)}function Yo(e){let n=oi(e)?qo(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=ti(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of et(t)){let c=s.get(i.order);l[i.name]=ko(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:Ho(t,a)}}function zo(e){return e.sample??on(e.name)}function ri(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:zo(e)}function si(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((c,f)=>{let u=n.get(c);u&&(u.end<=t.start&&u.end>a&&(a=u.end,o=f),u.start>=t.end&&u.start<l&&(l=u.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 jo(e,n,t){let r=e.paths??[],o=r.find(m=>Be(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===Be(o.name).name)?.start??0,l=n&&n.end>n.start?n:void 0,i=new Map,c=a;for(let m of o.nodeIds){let b=s.get(m)??0;i.has(m)||i.set(m,{start:c,end:c+b}),c+=b}let f=l===void 0||[...i.values()].some(m=>m.end<=l.start)&&[...i.values()].some(m=>m.start>=l.end),u=m=>{let{ids:b,complete:g}=si(m.nodeIds,i,l,f),x=[],E=0,L=0,S=0;for(let M of b){let N=s.get(M)??0,A=i.get(M),C=x.at(-1),G=C?.referenceStart,F=A&&G!==void 0&&S>=0&&G+C.bp===A.start,$=A&&G!==void 0&&S<=0&&A.end===G;!A&&C&&!C.onReference?C.bp+=N:F||$?(C.bp+=N,F||(C.referenceStart=A.start,C.reversed=!0),S=F?1:-1):(x.push({start:E,bp:N,onReference:A!==void 0,referenceStart:A?.start}),S=0),E+=N,A||(L+=N)}return{name:m.name,label:ri(m),sample:zo(m),haplotype:m.haplotype,bp:E,offReferenceBp:L,complete:g,runs:x}},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:u(o),rows:r.filter(m=>m!==o&&(d(m)||!h.has(m.name))).map(u).sort((m,b)=>Number(b.complete)-Number(m.complete)||b.bp-m.bp||m.label.localeCompare(b.label))}}var ai=1.3;function ii(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*ai,maxY:e.rows.length*20}}function Vo(e,n){let t=Ie(e),r=jo(e,n);if(t.length===0||!r)return;let o=ve(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:ii(r)}}var li="Force-directed layout",we=e=>e.nodes.some(v),Uo=e=>we(e)&&(e.paths?.length??0)>1,Ko=e=>we(e)&&Fe(e),Qo=e=>we(e)&&e.nodes.some(rn),nt=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:fo,cutMargins:!0,wholeWalks:!1,available:we,drawsLocally:we},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:go,cutMargins:!0,wholeWalks:!1,available:Qo,drawsLocally:Qo},{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:Vo,cutMargins:!1,wholeWalks:!0,available:Uo,drawsLocally:Uo},{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:bo,cutMargins:!1,wholeWalks:!1,available:we,drawsLocally:we},{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:Xo,cutMargins:!1,wholeWalks:!1,available:Fe,drawsLocally:Fe},{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:Yo,cutMargins:!0,wholeWalks:!1,available:Ko,drawsLocally:Ko},{value:"force",label:li,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1}],uu=nt.map(e=>e.value);function du(e,n){return!ci(e).drawsLocally(n)}function ci(e){return nt.find(n=>n.value===e)??nt[0]}var ui=10;function di(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=ui*(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 fi=40;function Se(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function pi(e,n){let t=Se(e),r=Se(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function Zo(e){return e>=Et?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function hu(e,n=[]){let t=hi(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function hi(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=pi(r,o);if(a>=fi)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${Zo(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Se(o)} inv`};let c=o!==r?di(e,n):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${Zo(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Se(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${Se(o-t)} ins${f}`}:o===t?{kind:"deletion",label:`${Se(t-r)} del${f}`}:{kind:"complex",label:`${Se(t)} ref \u2192 ${i}, ${s} alleles`}}var mu={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},bu={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function gu(e){return e.segments.split(",").filter(Boolean)}function xu({count:e,bounds:n,pixelRows:t,width:r,room:o,columns:s}){function a(i){let c=Math.ceil(e/i),f=Math.floor((r-(i-1)*8)/i),u=(o-c*34-(c-1)*8)/c,d=(f-24)/n.w,h=n.h>0?(u-24)/n.h:1/0,p=t?d:Math.min(d,h),m=t?n.h:n.h*p,b=Math.floor(Math.max(60,Math.min(m+24,u)));return{columns:i,width:f,height:b,scale:p,total:c*(b+34)+(c-1)*8}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let l=a(1);for(let i=2;i<=e;i++){let c=a(i);c.scale>l.scale&&(l=c)}return l}var Y=se(Qe(),1);var W=se(Qe(),1);function Le(e,n){return(0,W.packAbgr)((0,W.abgrRed)(e),(0,W.abgrGreen)(e),(0,W.abgrBlue)(e),Math.round((0,W.abgrAlpha)(e)*n))}function Su(e,n){return(0,W.packAbgr)(Math.min(255,Math.round((0,W.abgrRed)(e)*n)),Math.min(255,Math.round((0,W.abgrGreen)(e)*n)),Math.min(255,Math.round((0,W.abgrBlue)(e)*n)),(0,W.abgrAlpha)(e))}var er=new WeakMap;function nr(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=er.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 c=0;c<n.edges.length;c++){let f=n.edges[c],u=e[f.from],d=e[f.to];if(u?.length&&d?.length){let h=r?.get(c);i.set(c,Ye(u,d,Ft(f),0,0,t,h?Bn(e,h):[]))}}return er.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var mi=(0,Y.packAbgr)(119,119,119,217),tr=(0,Y.packAbgr)(136,136,136,217),bi=(0,Y.packAbgr)(24,24,28,240),gi=2.2,at=(0,Y.packAbgr)(160,160,160,255),$e=.18,yi=11,xi=1.2,or=4,tt=1e-6,Mi=7,wi=3,Si=3,Li=1.5,Ei=.5,Ni=.45,ot=12,Ri=1e-6,be=new Float64Array(64),Ee=new Float64Array(64),Ne=new Float64Array(64);function Ai(e,n,t,r){let o=e.length*ot+1;be.length<o&&(be=new Float64Array(o),Ee=new Float64Array(o),Ne=new Float64Array(o));let s=e[e.length-1];be[0]=s.x1,Ee[0]=s.y1,Ne[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<=ot&&l<r;f++){let u=1-(f/ot)**2,d=1-u,h=d*d*d,p=3*d*d*u,m=3*d*u*u,b=u*u*u,g=h*c.x0+p*c.cx0+m*c.cx1+b*c.x1,x=h*c.y0+p*c.cy0+m*c.cy1+b*c.y1;l+=Math.hypot(g-be[a-1],(x-Ee[a-1])*t)*n,be[a]=g,Ee[a]=x,Ne[a]=l,a++}}return a}function rr(e,n){let t=1;for(;t<e-1&&Ne[t]<n;)t++;let r=Ne[t-1],o=Ne[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:be[t-1]+(be[t]-be[t-1])*s,y:Ee[t-1]+(Ee[t]-Ee[t-1])*s}}function Ti({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=Mi+wi*n,c=Ai(e,r,o,t+i),f=Ne[c-1],u=Math.min(t,f),d=f<Ri?Ci(a,r,o):f-u,h=Math.min(1,d/i);if(h<Ei)return;let p=rr(c,u),m=rr(c,u+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):Di(x,o,_i(x,l)),length:i*h,halfWidth:(Si+Li*n)*h,color:s}}function Ci(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 _i(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 rt(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,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else if(o===t.length-1){let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,c=Math.hypot(l,i);c>0&&(s=-i/c,a=l/c)}else{let l=t[o].x-t[o-1].x,i=t[o].y-t[o-1].y,c=Math.hypot(l,i),f=t[o+1].x-t[o].x,u=t[o+1].y-t[o].y,d=Math.hypot(f,u);if(c>0&&d>0){let h=-i/c,p=l/c,m=-u/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 c>0?(s=-i/c,a=l/c):d>0&&(s=-u/d,a=f/d)}r.push({nx:s,ny:a})}return r}function sr(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 wn(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 We(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 Ii=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],vi=[[237,137,44],[158,42,122]],Bi=[[220,50,50],[50,120,220]];function st(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 Oi(e,n){let[t,r,o]=We(Mt(e),Rn,An);return wn(t,r,o,n)}var it=300,Pi=.7,Gi=.5,cr=[60,65,72],lt=(0,Y.packAbgr)(...cr,255),Bu=`rgb(${cr.join(", ")})`;function Ou(e,n){let t=lo(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 ct(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 ut(e,n,t,r){switch(t){case"random":return Oi(e.id,1);case"depth":return st(Ii,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return st(Bi,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):st(vi,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 lt;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=We(a*it,Pi,Gi);return wn(l,i,c,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]=We(o,.75,.5);return wn(s,a,l,1)}default:return(0,Y.packAbgr)(52,152,219,255)}}function Di(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 Fi(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 ar(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 ir=new WeakMap;function $i(e){let n=ir.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=We(wt(s,o.length),Rn,An);t.push(wn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},ir.set(e,n)}return n}var lr=new WeakMap,Wi=new Map;function qi(e){let n=lr.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])}lr.set(e,n)}return n}function Pu(e){let{nodePositions:n,graph:t,nodeById:r,colorScheme:o,contigThickness:s,connectorThickness:a,drawPaths:l,nodeWidth:i="uniform",highlight:c,axis:f,linearLayout:u,viewportBounds:d,referenceRamp:h,deletions:p,hiddenEdges:m,version:b=0}=e,g=i==="depth"?Nt(t):0,x=f.scaleX,E=ln(f),L=nr(n,t,f,p,b),S=[],M=new Map,N=[],A=new Map,C=[],G=new Map,F={...ct(t),referenceRamp:h},$=new Map;if(o==="rainbow")for(let I=0;I<t.nodes.length;I++)$.set(t.nodes[I].id,I);let q=t.paths?.length??0,{pathColorByIndex:k,pathIndexByName:J}=$i(t),V=I=>k[J.get(I)??-1]??tr,U=l&&q>1?qi(t):Wi,Ze=x>(u?1:Ni);for(let I=0;I<t.edges.length;I++){let P=t.edges[I],K=n[P.from],Q=n[P.to],Z=L.get(I);if(!K?.length||!Q?.length||!Z||m?.has(I))continue;let le=P.pathIds?.length??0,ce=p?.get(I)!==void 0,ue=c?.edgeIndexes.has(I)??!1,ee=a/2*(ce?gi:1),de=l&&le>0,ge=ce?bi:mi,te=!c||ue?ge:Le(ge,$e),ke=r.get(P.to),Ae=(ke?an(ke,s,i,g):s)/2,Te=(xe,_e,z,fe)=>{let re=xe===0&&_e===0?Z:vn(Z,xe,_e);if(d&&!ar(re,d))return;if(ce)for(let Ln of Gt(re,yi/x))C.push({curves:Ln,thickness:ee,color:z});else C.push({curves:re,thickness:ee,color:z});let en=Ze&&fe!==void 0?Ti({curves:re,edgeHalfWidth:ee,nodeHalfWidth:Ae,scale:x,yToX:E,color:fe,fromSegments:K,toSegments:Q}):void 0;en&&N.push(en)},ye=C.length,Ce=N.length,oe=c&&ue&&!de?c.walks:void 0;if(oe){let xe=r.get(P.from),_e=xe?an(xe,s,i,g):s,z=Math.max(_e/oe.length,or),fe=rt(K,E),{nx:re,ny:en}=(P.fromStrand==="-"?fe[0]:fe.at(-1))??{nx:0,ny:0},Ln=1/Math.max(x,tt);oe.forEach((En,Wr)=>{if(!En.edgeIndexes.has(I))return;let Nn=(Wr-(oe.length-1)/2)*z*Ln,mt=Nn===0?Z:vn(Z,re*Nn,en*Nn/E);d&&!ar(mt,d)||C.push({curves:mt,thickness:z/2,color:En.colors.get(P.from)??En.colors.get(P.to)??ge})})}else if(!de)Te(0,0,te,te);else{let xe=Dt(K,Q,le,f),_e=Math.floor((le-1)/2);for(let z=0;z<le;z++){let fe=xe[z],re=V(P.pathIds[z]);Te(fe.x,fe.y,c&&!c.names.has(P.pathIds[z])?Le(re,$e):re,z===_e?te:void 0)}}let He=C.length-ye;He>0&&G.set(I,{start:ye,count:He});let Je=N.length-Ce;Je>0&&A.set(I,{start:Ce,count:Je})}for(let[I,P]of Object.entries(n)){let K=r.get(I);if(!K||d&&!Fi(P,d))continue;let Q=c!==void 0&&!c.nodeIds.has(I),Z=Q?at:ut(K,$.get(I)??0,o,F),le=Q?Le(Z,$e):Z,Re=an(K,s,i,g),ce=Re/2,ue=S.length,ee=U.get(I),de=Re/q,ge=P.length>=2,te=c&&!Q&&!ee?.length?c.walks:void 0;if(ge&&te){let Ae=Math.max(Re/te.length,or),Te=rt(P,E),ye=1/Math.max(x,tt);te.forEach((Ce,oe)=>{let He=Ce.colors.get(I);if(He===void 0)return;let Je=(oe-(te.length-1)/2)*Ae*ye;S.push({points:te.length===1?P:sr(P,Te,Je,E),thickness:Ae/2,color:He})})}else if(ge&&ee?.length&&de>=xi){let Ae=rt(P,E),Te=1/Math.max(x,tt);for(let ye of ee){let Ce=(ye-(q-1)/2)*de*Te,oe=k[ye]??tr;S.push({points:sr(P,Ae,Ce,E),thickness:de/2,color:Q?Le(oe,$e):oe})}}else ge&&S.push({points:P,thickness:ce,color:le});let ke=S.length-ue;ke>0&&M.set(I,{start:ue,count:ke})}return{nodeStrokes:S,nodeStrokeRuns:M,arrows:N,arrowRuns:A,edgeCurves:C,edgeCurveRuns:G}}var fr=se(Qe(),1);var qe=10,ki=qe+8,dt=5;function Wu(e,{colorScheme:n,referenceRamp:t,walkNodes:r,walkColors:o}){let s={...ct(e),referenceRamp:t},a=[];return e.nodes.forEach((l,i)=>{if(v(l)){let c=r?o?.get(l.id)??at:ut(l,i,n,s);a.push({node:l.id,bp0:l.stable.start,bp1:l.stable.start+l.length,color:(0,fr.abgrToCssRgba)(r&&!r.has(l.id)?Le(c,$e):c)})}}),a.sort((l,i)=>l.bp0-i.bp0)}function ft(e,n,t){let r=n*e.scale+e.translateX,o=t*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var ur=2;function Hi(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 c of e)l+=Math.max(0,Math.min(c.bp1,s)-c.bp0),i+=Math.max(0,c.bp1-Math.max(c.bp0,a));return n.scale>=0?{left:Math.round(l),right:Math.round(i)}:{left:Math.round(i),right:Math.round(l)}}function qu(e,n,t,r){if(r<0||r>qe+ur)return;let o,s=ur;for(let a of e){let[l,i]=ft(n,a.bp0,a.bp1),c=Math.max(0,l-t,t-i);c<=s&&(s=c,o=a.node)}return o}function ku(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function dr(e,n,t){let r=qe/2,o=n+t*(dt+1);e.moveTo(n+t,r),e.lineTo(o,r-dt/1.4),e.lineTo(o,r+dt/1.4),e.closePath()}function Hu(e,n,t,{width:r,lit:o,darkMode:s}){let a=s?"#ffffff":"#18181c";e.fillStyle=s?"#1f1f1f":"#ffffff",e.fillRect(0,0,r,ki);for(let i of n){let[c,f]=ft(t,i.bp0,i.bp1);f>=0&&c<=r&&(e.fillStyle=i.color,e.fillRect(c,0,Math.max(f-c,1),qe))}let l=Hi(n,t,r);if((l.left>0||l.right>0)&&(e.beginPath(),l.left>0&&dr(e,0,1),l.right>0&&dr(e,r,-1),e.fillStyle=a,e.fill(),e.strokeStyle=s?"#1f1f1f":"#ffffff",e.lineWidth=1,e.stroke()),o){let[i,c]=ft(t,o.start,o.end),f=Math.max(c-i,3),u=(i+c)/2-f/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(u,.75,f,qe-1.5),o.anchor&&(e.beginPath(),e.moveTo(u+f/2,qe),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function ju(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 pt(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 ht(e,n,t){let r=pt(e,n),o=pt(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 pr=5,Xi=10,Yi=110,zi=3;function ji(e){return e?"#b0b0b8":"#55555c"}function Vi(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 hr(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+Xi)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function Ui(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 c=Vi(i/(l-a)*Yi),f=[],u=[];for(let d=Math.ceil(o.bp0/c)*c;d<=s.bp1;d+=c){let h=Math.round(n(pt(e,d)))+.5;if(h>=0&&h<=t){f.push(h);let p=d.toLocaleString("en-US");u.push({text:p,at:h,width:r(p)})}}return{spans:[{x0:a,x1:l}],ticks:f,labels:hr(u)}}function Ki(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),c=[],f=[],u=[],d=[];for(let{box:p,s0:m,s1:b}of o){c.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=zi&&f.push(Math.round(b)+.5);let g=l(hn(p.bp1-p.bp0),(m+b)/2);g.width<=b-m&&u.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:c,ticks:f,labels:hr([...h,...u,...d])}}function Qi(e,n,t,r,o=!1){return(o?Ui:Ki)(e,n,t,r)}function Uu(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=Qi(n,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=ji(l),f=r+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:d}of i.spans)e.moveTo(Math.max(0,u),f),e.lineTo(Math.min(a,d),f);for(let u of i.ticks)e.moveTo(u,r),e.lineTo(u,r+pr);e.stroke();for(let{text:u,at:d}of i.labels)e.fillText(u,d,r+pr+2)}function Zu(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 Ju(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 Zi=3;function ed(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=Zi;for(let l of e){let i=l.top0+(l.bottom0-l.top0)*o,c=l.top1+(l.bottom1-l.top1)*o,f=Math.max(0,Math.min(i,c)-t,t-Math.max(i,c));f<a&&(a=f,s=l.node)}return s}function mr(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 br(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function nd(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)mr(e,l,t);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let l of n)br(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(),mr(e,a,t),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),br(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Ji(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 el(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 rd(e,n,t){let r=Ji(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 c=el(r,i.start,l);if(c){let{node:f,bp0:u,bp1:d}=c,h=p=>f.x+(Math.min(p,d)-u)/(d-u)*f.pixelWidth;o.push({x0:h(i.start),x1:h(i.end),y:l.get(c.index),height:s.width})}}}}return o}function nl(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function sd(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=nl(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 c=r(a.y);e.rect(l,c,i-l,r(a.y+a.height)-c)}}e.fill()}}function tl(e,n){let t=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=n.nodeMap.get(O(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 c=e.path[i]?.y;if(l&&c!==void 0){let f={readId:e.id,y:c,height:e.width,nodeY:l.y},u=d=>Fo(l,d);for(let d of o.mismatches){let h=u(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=u(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=u(d.pos+d.seq.length);p!==null&&t.push({...f,kind:"substitution",x0:h,x1:p,seq:d.seq})}}}}}),t}function gr(e){return e.reads.flatMap(n=>tl(n,e))}function Lr(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 Er(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 yr(e,n,t){let r=Lr(e);return{commands:r,color:n,alpha:t,...Er(r)}}function xr(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=$o(t.curves,n).map(a=>yr(a.path,a.color,a.alpha??1)),s=t.corners.filter(a=>a.type===n).map(a=>yr(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function dd(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=Lr(Wo(t));n.push({name:t.name,commands:r,...Er(r)})}}),{bounds:e.bounds,layers:[xr(e,"haplotype"),xr(e,"read")],nodes:n,mismatches:gr(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function Mr(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 wr(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 ol=12,rl=.15;function sl(e){return Math.max(rl,Math.min(1,e/ol))}function fd(e,n,t){let{x:r,y:o,width:s}=t,a=c=>r(c.x1)>=0&&r(c.x0)<=s;for(let c of n.layers)wr(e,c.rects,a,f=>{let u=r(f.x0),d=o(f.y0);e.rect(u,d,r(f.x1)-u,o(f.y1)-d)}),wr(e,c.shapes,a,f=>{Mr(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 c of n.nodes)if(a(c)){let f=c.name===t.highlightNode;e.beginPath(),Mr(e,c.commands,r,o),e.fillStyle=f?"rgba(255,192,203,0.5)":i,e.strokeStyle=f?"#ff0000":l,e.fill(),e.globalAlpha=f?1:sl(r(c.x1)-r(c.x0)),e.stroke(),e.globalAlpha=1}ll(e,n.mismatches,t)}var Nr=12,al=6;function il(e){return Nr*e>=al}function Sr(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 ll(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!il(s)||n.length===0)return;let l=Nr*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&Sr(i,t)){let c=r(i.x0),f=o(i.y);e.rect(c,f,r(i.x1)-c,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)Sr(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 md(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,...ht(o,l,i),exons:r.exons.filter(c=>c.end>l&&c.start<i).map(c=>ht(o,Math.max(c.start,l),Math.min(c.end,i)))})}return t}var Rr=22,cl=4,Sn=8,ul="11px sans-serif",dl=8;function bd(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(cl,r)}function gd(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/Rr)),c=[],f=l?"#e0e0e6":"#1c1c22";e.font=ul,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let u=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 u){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,E=Math.min(h,g-x),L=Math.max(p,g+x),S=c.findIndex(N=>N+dl<=E);S===-1&&(S=Math.min(c.length,i-1)),c[S]=Math.max(c[S]??-1/0,L);let M=r-S*Rr-Sn/2;e.beginPath(),e.moveTo(h,M+.5),e.lineTo(p,M+.5),e.stroke();for(let N of d.exons){let A=s(N.x0);e.fillRect(A,M-Sn/2,Math.max(1,s(N.x1)-A),Sn)}e.fillText(b,g,M-Sn/2-2)}}var Ir=se(Qe(),1);var fl=[{value:"progress",label:"Progress along the walk"},{value:"walk",label:"One colour for the walk"},{value:"reference",label:"Reference position"}],vr=[{value:"grey",label:"Grey to black",ends:["#a3a3a3","#151515"]},{value:"blue",label:"Cyan to navy",ends:["#6ee0f0","#0b2c7a"]},{value:"red",label:"Yellow to red",ends:["#ffd24a","#b3121b"]},{value:"purple",label:"Pink to plum",ends:["#f5a3d8","#5e1a6e"]},{value:"green",label:"Lime to forest",ends:["#b6e36c","#0b5d3b"]},{value:"rainbow",label:"Rainbow"}],Ar=["blue","red","purple","green"],pl=e=>fl.some(n=>n.value===e),hl=e=>vr.some(n=>n.value===e);function Md(e,n,t,r=!0){let{field:o,scheme:s}=e.color??{},a=pl(o)?o:r?"progress":"walk",l=n?"grey":Ar[t%Ar.length],i=hl(s)?s==="rainbow"&&a!=="reference"?l:s:l;return{field:a,scheme:i}}var Br=.5,ml=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,bl=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function Tr(e){let[n,t,r]=[1,3,5].map(l=>ml(Number.parseInt(e.slice(l,l+2),16)/255)),o=Math.cbrt(.4122214708*n+.5363325363*t+.0514459929*r),s=Math.cbrt(.2119034982*n+.6806995451*t+.1073969566*r),a=Math.cbrt(.0883024619*n+.2817188376*t+.6299787005*r);return[.2104542553*o+.793617785*s-.0040720468*a,1.9779984951*o-2.428592205*s+.4505937099*a,.0259040371*o+.7827717662*s-.808675766*a]}function gl([e,n,t]){let r=(e+.3963377774*n+.2158037573*t)**3,o=(e-.1055613458*n-.0638541728*t)**3,s=(e-.0894841775*n-1.291485548*t)**3;return[4.0767416621*r-3.3077115913*o+.2309699292*s,-1.2684380046*r+2.6097574011*o-.3413193965*s,-.0041960863*r-.7034186147*o+1.707614701*s].map(a=>bl(Math.max(0,Math.min(1,a)))*255)}function Or(e,n){let t=Math.max(0,Math.min(1,n)),r=vr.find(a=>a.value===e);if(!r||!("ends"in r))return We(t*it,.7,.5).map(a=>a*255);let o=Tr(r.ends[0]),s=Tr(r.ends[1]);return gl(o.map((a,l)=>a+(s[l]-a)*t))}function Cr(e,n){let[t,r,o]=Or(e,n).map(Math.round);return`rgb(${t}, ${r}, ${o})`}function _r(e,n){let[t,r,o]=Or(e,n).map(Math.round);return(0,Ir.packAbgr)(t,r,o,255)}function wd({field:e,scheme:n},t){return e==="walk"?_r(n,Br):t===void 0?yl:_r(n,t)}var yl=lt;function Sd({field:e,scheme:n}){return e==="walk"?Cr(n,Br):`linear-gradient(to right, ${Array.from({length:7},(r,o)=>{let s=o/6;return`${Cr(n,s)} ${s*100}%`}).join(", ")})`}function Ml(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function wl(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 c=Math.abs(e[l]-n[i])+o[l+1][i+1],f=t-l>r-i?o[l+1][i]:1/0,u=r-i>t-l?o[l][i+1]:1/0;o[l][i]=Math.min(c,f,u),s[l][i]=o[l][i]===c}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 Gr(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var Fr=e=>e.spanningReads!==0;function Dr(e,n){return{...n,agrees:e.complete&&Fr(n)?Ml(e.bp,n.bp):void 0}}function Sl(e,n){let t=new Map,r=new Set;e.forEach((l,i)=>{let c=n.find(f=>f.haplotype!==void 0&&f.haplotype===l.haplotype);c&&(r.add(c),t.set(i,Dr(l,c)))});let o=n.filter(l=>l.haplotype===void 0),s=Gr(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Fr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!t.has(u.i)),f=Gr(i.filter(u=>!r.has(u)),u=>u.bp);wl(c.map(u=>u.item.bp),f.map(u=>u.item.bp)).forEach((u,d)=>{if(u!==void 0){let h=c[d],p=f[u].item;r.add(p),t.set(h.i,Dr(h.item,p))}})}return t}function Nd(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 $r=se(tn(),1),Td=(0,ae.createSvgIcon)((0,$r.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{ae as a,Fs as b,Qe as c,je as d,Ys as e,ea as f,Wn as g,qs as h,ks as i,Ua as j,jo as k,ii as l,nt as m,uu as n,du as o,ci as p,Se as q,hu as r,mu as s,bu as t,gu as u,Al as v,Pt as w,vn as x,ln as y,Dt as z,Il as A,xu as B,Ol as C,Pl as D,Gl as E,jt as F,hn as G,As as H,Kt as I,zl as J,Su as K,nr as L,it as M,Bu as N,Ou as O,Pu as P,ki as Q,Wu as R,Hi as S,qu as T,ku as U,Hu as V,ju as W,Vu as X,ji as Y,Uu as Z,Zu as _,Ju as $,ed as aa,nd as ba,rd as ca,nl as da,sd as ea,dd as fa,fd as ga,il as ha,Sr as ia,md as ja,Rr as ka,bd as la,gd as ma,fl as na,vr as oa,Md as pa,wd as qa,Sd as ra,xl as sa,Nd as ta,Kl as ua,Ql as va,Os as wa,Zl as xa,Jl as ya,Fn as za,dc as Aa,fc as Ba,Td as Ca};
2
+ //# sourceMappingURL=chunk-75CO6QJZ.js.map