jbrowse-plugin-graphgenomeviewer 4.0.20 → 4.0.21

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 (29) hide show
  1. package/dist/chunks/{GbzBaseSyntenyAdapter-KKSNCZXY.js → GbzBaseSyntenyAdapter-7ZKFAEJG.js} +2 -2
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-KKSNCZXY.js.map → GbzBaseSyntenyAdapter-7ZKFAEJG.js.map} +2 -2
  3. package/dist/chunks/{GraphGenomeView-YKR42OER.js → GraphGenomeView-CLUMXH4K.js} +2 -2
  4. package/dist/chunks/{GraphTrackSettingsDialog-2QV6TPX7.js → GraphTrackSettingsDialog-QF5OMTCH.js} +2 -2
  5. package/dist/chunks/{LinearGraphDisplay-AFTQJKEI.js → LinearGraphDisplay-4CMVCEM5.js} +2 -2
  6. package/dist/chunks/chunk-3FGJLRG2.js +2 -0
  7. package/dist/chunks/chunk-3FGJLRG2.js.map +7 -0
  8. package/dist/chunks/{chunk-ERKI3TAL.js → chunk-3SZJ4AFI.js} +3 -3
  9. package/dist/chunks/{chunk-5E7TVPCI.js → chunk-CLRXQ6BM.js} +2 -2
  10. package/dist/chunks/chunk-VIFXYTIS.js +2 -0
  11. package/dist/chunks/chunk-VIFXYTIS.js.map +7 -0
  12. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +2 -2
  13. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +3 -3
  14. package/package.json +2 -2
  15. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +1 -1
  16. package/src/GetSubgraph.ts +3 -0
  17. package/src/GraphGenomeView/viewModel.ts +15 -0
  18. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +23 -2
  19. package/src/LinearGraphDisplay/model.ts +7 -2
  20. package/src/version.ts +1 -1
  21. package/dist/chunks/chunk-47UXFQEI.js +0 -2
  22. package/dist/chunks/chunk-47UXFQEI.js.map +0 -7
  23. package/dist/chunks/chunk-IUIIYSGF.js +0 -2
  24. package/dist/chunks/chunk-IUIIYSGF.js.map +0 -7
  25. /package/dist/chunks/{GraphGenomeView-YKR42OER.js.map → GraphGenomeView-CLUMXH4K.js.map} +0 -0
  26. /package/dist/chunks/{GraphTrackSettingsDialog-2QV6TPX7.js.map → GraphTrackSettingsDialog-QF5OMTCH.js.map} +0 -0
  27. /package/dist/chunks/{LinearGraphDisplay-AFTQJKEI.js.map → LinearGraphDisplay-4CMVCEM5.js.map} +0 -0
  28. /package/dist/chunks/{chunk-ERKI3TAL.js.map → chunk-3SZJ4AFI.js.map} +0 -0
  29. /package/dist/chunks/{chunk-5E7TVPCI.js.map → chunk-CLRXQ6BM.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as x}from"./chunk-ERKI3TAL.js";import"./chunk-47UXFQEI.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-5E7TVPCI.js";import{B as L}from"./chunk-IUIIYSGF.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as s,b as g,c as v,d as G,e as B}from"./chunk-XEJ47DLD.js";import{b as a}from"./chunk-FY3BTKY4.js";var S=a(g(),1);var m=a(G(),1),n=a(v(),1),C=a(g(),1),P=a(L(),1),o=a(s(),1),I=(0,P.makeStyles)()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),b=(0,C.observer)(function({model:e}){let{classes:r}=I();return e.isLoading?(0,o.jsxs)(n.Paper,{className:r.paper,"data-testid":"graph-genome-loading",children:[(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(m.LoadingEllipses,{variant:"h6",message:e.statusMessage}),(0,o.jsx)(n.Button,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),(0,o.jsx)(n.LinearProgress,{variant:"indeterminate"})]}):e.error?(0,o.jsx)(n.Paper,{className:r.paper,children:(0,o.jsx)(m.ErrorBanner,{error:e.error,onReset:()=>{e.retryLoad()}})}):(0,o.jsx)(n.Paper,{className:r.paper,"data-testid":"graph-genome-load-canceled",children:(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(n.Typography,{variant:"h6",children:"Loading canceled"}),(0,o.jsx)(n.Button,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),h=b;var M=a(B(),1),N=a(G(),1),i=a(v(),1),w=a(g(),1),E=a(L(),1),t=a(s(),1),k=`H VN:Z:1.0
1
+ import{a as x}from"./chunk-3SZJ4AFI.js";import"./chunk-3FGJLRG2.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-CLRXQ6BM.js";import{B as L}from"./chunk-VIFXYTIS.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as s,b as g,c as v,d as G,e as B}from"./chunk-XEJ47DLD.js";import{b as a}from"./chunk-FY3BTKY4.js";var S=a(g(),1);var m=a(G(),1),n=a(v(),1),C=a(g(),1),P=a(L(),1),o=a(s(),1),I=(0,P.makeStyles)()({paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto",display:"flex",flexDirection:"column",gap:12},row:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8}}),b=(0,C.observer)(function({model:e}){let{classes:r}=I();return e.isLoading?(0,o.jsxs)(n.Paper,{className:r.paper,"data-testid":"graph-genome-loading",children:[(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(m.LoadingEllipses,{variant:"h6",message:e.statusMessage}),(0,o.jsx)(n.Button,{size:"small","data-testid":"graph-genome-cancel",onClick:()=>{e.cancelLoad()},children:"Cancel"})]}),(0,o.jsx)(n.LinearProgress,{variant:"indeterminate"})]}):e.error?(0,o.jsx)(n.Paper,{className:r.paper,children:(0,o.jsx)(m.ErrorBanner,{error:e.error,onReset:()=>{e.retryLoad()}})}):(0,o.jsx)(n.Paper,{className:r.paper,"data-testid":"graph-genome-load-canceled",children:(0,o.jsxs)("div",{className:r.row,children:[(0,o.jsx)(n.Typography,{variant:"h6",children:"Loading canceled"}),(0,o.jsx)(n.Button,{variant:"contained",size:"small","data-testid":"graph-genome-retry",onClick:()=>{e.retryLoad()},children:"Retry"})]})})}),h=b;var M=a(B(),1),N=a(G(),1),i=a(v(),1),w=a(g(),1),E=a(L(),1),t=a(s(),1),k=`H VN:Z:1.0
2
2
  S 1 ACGT
3
3
  S 2 GGCC
4
4
  S 3 TTAA
@@ -7,4 +7,4 @@ L 1 + 2 + 0M
7
7
  L 1 + 3 + 0M
8
8
  L 2 + 4 + 0M
9
9
  L 3 + 4 + 0M`,z=(0,E.makeStyles)()({column:{display:"flex",flexDirection:"column",gap:8},rowEnd:{display:"flex",gap:8,alignItems:"flex-end"},rowCenter:{display:"flex",gap:8,alignItems:"center"},flex1:{flex:1},paper:{padding:16,margin:8,maxWidth:560,marginInline:"auto"},header:{marginBottom:12},footer:{marginTop:12,display:"flex",justifyContent:"flex-end"}}),R=(0,w.observer)(function({model:e}){let{classes:r}=z(),[d,T]=(0,M.useState)("");function y(){d.trim()&&e.loadGFAFromLocation({uri:d,locationType:"UriLocation"})}function A(p){let c=p.target.files?.[0];c&&c.text().then(f=>e.loadGFA(f,c.name)).catch(f=>{e.setError(f)})}return(0,t.jsxs)(i.Paper,{className:r.paper,children:[(0,t.jsx)("div",{className:r.header,children:(0,t.jsx)(i.Typography,{variant:"h6",children:"Load a GFA graph"})}),(0,t.jsxs)("div",{className:r.column,children:[(0,t.jsxs)("div",{className:r.rowCenter,children:[(0,t.jsxs)(i.Button,{variant:"outlined",component:"label",size:"small",children:["Choose file",(0,t.jsx)("input",{type:"file",accept:".gfa,.gfa1,.gfa2",hidden:!0,onChange:p=>{A(p)}})]}),(0,t.jsx)(i.Typography,{variant:"caption",color:"text.secondary",children:"Whole-file GFA; best for small/medium graphs."})]}),(0,t.jsxs)("div",{className:r.rowEnd,children:[(0,t.jsx)(i.TextField,{size:"small",label:"URL",placeholder:"https://example.com/graph.gfa",value:d,onChange:p=>{T(p.target.value)},onKeyDown:p=>{p.key==="Enter"&&y()},className:r.flex1}),(0,t.jsx)(i.Button,{variant:"contained",onClick:()=>{y()},disabled:!d.trim(),children:"Open"})]})]}),(0,t.jsx)("div",{className:r.footer,children:(0,t.jsx)(i.Button,{size:"small",onClick:()=>{e.loadGFA(k,"Example graph")},children:"Load 4-node example"})}),e.error?(0,t.jsx)(N.ErrorBanner,{error:e.error}):null]})}),F=R;var l=a(s(),1),U=(0,S.observer)(function({model:e}){return e.hasGraph?(0,l.jsx)(x,{model:e}):e.canRetryLoad&&(e.error||e.loadCanceled)?(0,l.jsx)(h,{model:e}):(0,l.jsxs)(l.Fragment,{children:[e.isLoading?(0,l.jsx)(h,{model:e}):null,(0,l.jsx)("div",{hidden:e.isLoading,children:(0,l.jsx)(F,{model:e})})]})}),O=U;export{O as default};
10
- //# sourceMappingURL=GraphGenomeView-YKR42OER.js.map
10
+ //# sourceMappingURL=GraphGenomeView-CLUMXH4K.js.map
@@ -1,4 +1,4 @@
1
- import{a as g}from"./chunk-5E7TVPCI.js";import{B as f}from"./chunk-IUIIYSGF.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as l,b as m,c as y,e as x}from"./chunk-XEJ47DLD.js";import{b as o}from"./chunk-FY3BTKY4.js";var a=o(y(),1),b=o(m(),1),S=o(f(),1),n=o(l(),1),L=(0,S.makeStyles)()({section:{marginBottom:24},formControl:{minWidth:200}}),w=[{value:0,label:"None"},{value:1,label:"1 hop"},{value:2,label:"2 hops"}],k=(0,b.observer)(function({model:e}){let{classes:t}=L();return(0,n.jsxs)("div",{className:t.section,children:[(0,n.jsxs)(a.FormControl,{className:t.formControl,children:[(0,n.jsx)(a.InputLabel,{children:"Graph context"}),(0,n.jsx)(a.Select,{value:e.subgraphContext,label:"Graph context","data-testid":"graph-context-select",onChange:p=>{e.setSubgraphContext(p.target.value),e.cut()},children:w.map(({value:p,label:u})=>(0,n.jsx)(a.MenuItem,{value:p,children:u},p))})]}),(0,n.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"How far the cut follows links out of the region, one hop by default. A detour that leaves the reference before the window and rejoins after it is indexed under its own sequence, so at none its middle is missing and the one bubble draws as two unrelated stubs. Each hop costs a query per off-reference segment already reached."})]})}),v=k;var C=o(x(),1),d=o(y(),1),c=o(m(),1),G=o(f(),1),i=o(l(),1),T=(0,G.makeStyles)()({section:{marginBottom:24}});function M(r){let e=r.split(/[\s,]+/).map(t=>t.trim()).filter(t=>t!=="");return e.length===0?void 0:e}var F=(0,c.observer)(function({model:e}){let[t,p]=(0,C.useState)(e.chosenHaplotypes?.join(", ")??""),u=()=>{let s=M(t)??[];s.join(`
1
+ import{a as g}from"./chunk-CLRXQ6BM.js";import{B as f}from"./chunk-VIFXYTIS.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as l,b as m,c as y,e as x}from"./chunk-XEJ47DLD.js";import{b as o}from"./chunk-FY3BTKY4.js";var a=o(y(),1),b=o(m(),1),S=o(f(),1),n=o(l(),1),L=(0,S.makeStyles)()({section:{marginBottom:24},formControl:{minWidth:200}}),w=[{value:0,label:"None"},{value:1,label:"1 hop"},{value:2,label:"2 hops"}],k=(0,b.observer)(function({model:e}){let{classes:t}=L();return(0,n.jsxs)("div",{className:t.section,children:[(0,n.jsxs)(a.FormControl,{className:t.formControl,children:[(0,n.jsx)(a.InputLabel,{children:"Graph context"}),(0,n.jsx)(a.Select,{value:e.subgraphContext,label:"Graph context","data-testid":"graph-context-select",onChange:p=>{e.setSubgraphContext(p.target.value),e.cut()},children:w.map(({value:p,label:u})=>(0,n.jsx)(a.MenuItem,{value:p,children:u},p))})]}),(0,n.jsx)(a.Typography,{variant:"caption",color:"text.secondary",children:"How far the cut follows links out of the region, one hop by default. A detour that leaves the reference before the window and rejoins after it is indexed under its own sequence, so at none its middle is missing and the one bubble draws as two unrelated stubs. Each hop costs a query per off-reference segment already reached."})]})}),v=k;var C=o(x(),1),d=o(y(),1),c=o(m(),1),G=o(f(),1),i=o(l(),1),T=(0,G.makeStyles)()({section:{marginBottom:24}});function M(r){let e=r.split(/[\s,]+/).map(t=>t.trim()).filter(t=>t!=="");return e.length===0?void 0:e}var F=(0,c.observer)(function({model:e}){let[t,p]=(0,C.useState)(e.chosenHaplotypes?.join(", ")??""),u=()=>{let s=M(t)??[];s.join(`
2
2
  `)===(e.chosenHaplotypes??[]).join(`
3
3
  `)||(e.setSubgraphHaplotypes(s),e.cut())};return(0,i.jsx)(d.TextField,{fullWidth:!0,label:"Haplotypes",placeholder:"every haplotype",value:t,slotProps:{htmlInput:{"data-testid":"graph-haplotypes-field"}},onChange:s=>{p(s.target.value)},onBlur:()=>{u()},onKeyDown:s=>{s.key==="Enter"&&u()}})}),N=(0,c.observer)(function({model:e}){let{classes:t}=T();return e.adapterConfig.type==="GbzBaseSyntenyAdapter"?(0,i.jsxs)("div",{className:t.section,children:[(0,i.jsx)(F,{model:e},e.chosenHaplotypes?.join(",")??""),(0,i.jsx)(d.Typography,{variant:"caption",color:"text.secondary",children:"The haplotypes the cut is for, as lane assembly names or PanSN prefixes (HG002#1, or HG002 for both), separated by commas. The cut keeps their walks and the nodes those walks visit, with the reference. Empty is every haplotype."})]}):null}),H=N;var h=o(l(),1);function B({model:r,open:e,onClose:t}){return(0,h.jsxs)(g,{model:r,open:e,onClose:t,children:[(0,h.jsx)(v,{model:r}),(0,h.jsx)(H,{model:r})]})}export{B as default};
4
- //# sourceMappingURL=GraphTrackSettingsDialog-2QV6TPX7.js.map
4
+ //# sourceMappingURL=GraphTrackSettingsDialog-QF5OMTCH.js.map
@@ -1,2 +1,2 @@
1
- import{a as i}from"./chunk-ERKI3TAL.js";import"./chunk-47UXFQEI.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-5E7TVPCI.js";import"./chunk-IUIIYSGF.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as e,b as d}from"./chunk-XEJ47DLD.js";import{a as h,b as t}from"./chunk-FY3BTKY4.js";var p=h((l,o)=>{o.exports=JBrowseExports["@jbrowse/display-kit/DisplayChrome"]});var s=t(p(),1),n=t(d(),1);var r=t(e(),1),y=(0,n.observer)(function({model:a}){return(0,r.jsx)(s.DisplayStatusChrome,{model:a,phase:a.displayPhase,drawn:a.painted&&a.geometryPainted,testid:"linear-graph-display","data-layout":a.chosenLayoutMode,"data-cut-tier":a.cutTier,"data-recuts":a.recuts,"data-node-count":a.hasGraph?a.nodeCount:void 0,"data-loading":a.isLoading?"":void 0,style:{width:a.paneWidth,height:a.height,overflow:"hidden"},children:(0,r.jsx)(i,{model:a,ownChrome:!1})})}),c=y;export{c as default};
2
- //# sourceMappingURL=LinearGraphDisplay-AFTQJKEI.js.map
1
+ import{a as i}from"./chunk-3SZJ4AFI.js";import"./chunk-3FGJLRG2.js";import"./chunk-UQEPPJEO.js";import"./chunk-SCMIJAAX.js";import"./chunk-FCWXYIFC.js";import"./chunk-CLRXQ6BM.js";import"./chunk-VIFXYTIS.js";import"./chunk-EFVAQ2KM.js";import"./chunk-KULNKXPT.js";import{a as e,b as d}from"./chunk-XEJ47DLD.js";import{a as h,b as t}from"./chunk-FY3BTKY4.js";var p=h((l,o)=>{o.exports=JBrowseExports["@jbrowse/display-kit/DisplayChrome"]});var s=t(p(),1),n=t(d(),1);var r=t(e(),1),y=(0,n.observer)(function({model:a}){return(0,r.jsx)(s.DisplayStatusChrome,{model:a,phase:a.displayPhase,drawn:a.painted&&a.geometryPainted,testid:"linear-graph-display","data-layout":a.chosenLayoutMode,"data-cut-tier":a.cutTier,"data-recuts":a.recuts,"data-node-count":a.hasGraph?a.nodeCount:void 0,"data-loading":a.isLoading?"":void 0,style:{width:a.paneWidth,height:a.height,overflow:"hidden"},children:(0,r.jsx)(i,{model:a,ownChrome:!1})})}),c=y;export{c as default};
2
+ //# sourceMappingURL=LinearGraphDisplay-4CMVCEM5.js.map
@@ -0,0 +1,2 @@
1
+ import{d as Nt}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 Et,z as an}from"./chunk-VIFXYTIS.js";import{a as Xe,b as v,c as rn,d as _e,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((gl,Rt)=>{Rt.exports=JBrowseExports["@mui/material/SvgIcon"]});var je=nn((kl,Zt)=>{Zt.exports=JBrowseExports["@jbrowse/core/util/colorBits"]});var ma=nn((vc,Lo)=>{Lo.exports=JBrowseExports.mobx});var pl=nn((gd,vr)=>{vr.exports=JBrowseExports["@jbrowse/render-core/canvas2dUtils"]});var ae=se(At(),1);function wl(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 Ct(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 _n(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?_n(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 $r(e,n,t){let r=_n(e,n),o=_n(e,t),s=(t-n)/3,a=Tt(e,n),l=Tt(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 Tt(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([$r(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 Cn(e,n){let t=e.length-1;return n==="end"?{at:e[t],inward:e[t-1]}:{at:e[0],inward:e[1]}}var Fr=.5,Wr=80;function It(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 _t(e,n){return Math.max(0,n.min-e,e-n.max)}function vt(e,n,t){let r=_t(e[0].x,n),o=_t(e[e.length-1].x,n);return r===o?t:r<o?"start":"end"}function qr(e,n){return{from:vt(e,It(n),"end"),to:vt(n,It(e),"start")}}var kr=.75,Hr=1.15,Xr=.35,Yr=60;function zr(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 N=b*l+g*i;f=Math.min(f,N),u=Math.max(u,N)}let d=o.length?u-f:0,h=Math.max(Math.abs(c)*Hr/kr,d*Xr),p=s===void 0?h:Math.min(h,s);return c<0?-p:p}function ln({scaleX:e,scaleY:n}){return n/e}var jr=3;function Tn(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=jr){let s=ln(r),a=Tn(e[e.length-1],n[0],s)??Tn(e[0],e.at(-1),s)??Tn(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 In(e,n){return e.map(t=>({x:t.x,y:t.y*n}))}function Vr(e,n){for(let t of e)t.y0/=n,t.cy0/=n,t.cy1/=n,t.y1/=n;return e}var Ur=12,Kr=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(Kr,Math.max(Ur,r/2))/Math.max(n,Number.EPSILON)}function $t(e){return e.from!==e.to?!1:e.fromStrand&&e.toStrand&&e.fromStrand!==e.toStrand?e.fromStrand==="+"?"end":"start":!0}function Qr(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?Yr:void 0);if(c!==1)return Vr(Ye(In(e,c),In(n,c),t,r,o*c,{scaleX:i,scaleY:i},In(a,c),f===void 0?void 0:f*c),c);if(typeof t=="string")return Qr(Cn(e,t),Bt(e,i),r,o);let u=t?{from:"end",to:"start"}:qr(e,n),d=Cn(e,u.from),h=Cn(n,u.to),p=d.at,m=h.at,b=p.x+r,g=p.y+o,x=m.x+r,N=m.y+o;if(t){let L=1,S=0;if(d.inward){let Z=p.x-d.inward.x,U=p.y-d.inward.y,K=Math.hypot(Z,U);K>0&&(L=Z/K,S=U/K)}let M=Bt(e,i),E=-S,A=L,T=(p.x+m.x)/2+r+E*M,G=(p.y+m.y)/2+o+A*M,$=b+L*M,F=g+S*M,q=x-L*M,k=N-S*M;return[{x0:b,y0:g,cx0:$,cy0:F,cx1:$+E*M,cy1:F+A*M,x1:T,y1:G},{x0:T,y0:G,cx0:q+E*M,cy0:k+A*M,cx1:q,cy1:k,x1:x,y1:N}]}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,N-g),E=(ne,Y,le,Re)=>{let ce=Y.x-ne.x,ue=Y.y-ne.y,J=Math.hypot(ce,ue),de=J===0?0:(le*ce+Re*ue)/J;return Math.max(0,Math.min(M*Fr,Wr,de*.5))},A=m.x-p.x,T=m.y-p.y,[G,$]=Ct(L.x,L.y,p.x,p.y,E(L,p,A,T)),[F,q]=Ct(S.x,S.y,m.x,m.y,E(S,m,-A,-T)),k=a.length?zr(b,g,x,N,a,f):0,Z=M===0?1:M,U=(x-b)/Z,K=(N-g)/Z,Ze=-K*k,_=U*k,P=U*Math.abs(k),Q=K*Math.abs(k);return[{x0:b,y0:g,cx0:G+r+Ze-P,cy0:$+o+_-Q,cx1:F+r+Ze+P,cy1:q+o+_+Q,x1:x,y1:N}]}}var Zr=1;function Bn(e,n){return n.flatMap(t=>e[t]??[])}function Ft(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 Jr(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 es(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 ns(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 El(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Jr(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>=Zr&&ns(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:es(t.get(p),u,d)})}}}return r}function Oe(e){return e.endsWith("-")?"-":"+"}function Wt(e){return e==="+"?"-":"+"}function ts(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 Cl(e){let n=e.edges.map(ts),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 Tl(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 Il(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 os(e){return e.length*6.2+8}function rs(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 ss(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=>rs(o,r))?!1:(t.push(r),!0)}function cn(e,n,t){let r=[];for(let s of e){let a=os(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(ss(f,n)&&t(f)){r.push({...s,y:c,w:a});break}}}return r}var as=26,is=4e4,ls=8,cs=8,us=5.7,ds=6,fs=13,ze=3,un=2;function pn(e){return(e.length*us+ds+ze)/2}var pe=(fs+ze)/2,ps=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 hs(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 ms(e,n){return Math.abs(n.x)*(e.x1-e.x0)/2+Math.abs(n.y)*(e.y1-e.y0)/2}function bs(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 gs(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 ys(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 xs(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 Ms(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=Ft(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:N}of Ms(e,t,o,c))if(N>=as){let L=Xt(b.bp),S=pn(L),M=dn(S,0,0),E=x.x*f+s,A=x.y*u+a,T=N>=S*2/un,G=hs(g,x,f,u),$=ms(M,G)+cs,F=T?E:fn(E+G.x*$,S,l-S),q=T?A:fn(A+G.y*$,pe,i-pe),k=Math.hypot(F-E,q-A),Z;if(k>0){let U={x:(F-E)/k,y:(q-A)/k},K=bs(M,U);Z={arcX:E,arcY:A,labelX:F-U.x*K,labelY:q-U.y*K}}d.push({label:{key:`del:${b.edgeIndex}`,text:L,x:F,y:q,kind:"deletion",leader:Z},box:dn(S,F,q)})}let p=new Set,m=[...r??[]].sort((b,g)=>g.bp-b.bp);for(let b of m){let g=ys(b.nodeIds,e);if(!g)continue;let x=Math.max(g.minX*f+s,0),N=Math.min(g.maxX*f+s,l),L=Math.max(g.minY*u+a,0),S=Math.min(g.maxY*u+a,i);if(N<x||S<L)continue;let M=Math.max(N-x,S-L),E=Xt(b.bp),A=pn(E);if(M>=A*2/un){for(let $ of b.nodeIds)p.add($);let T=fn((x+N)/2,A,l-A),G=fn((L+S)/2,pe,i-pe);d.push({label:{key:`alleledel:${b.nodeIds.join(",")}`,text:E,x:T,y:G,kind:"deletion"},box:dn(A,T,G)})}}for(let[b,g]of xs(e,n)){if(p.has(b))continue;let{x,y:N}=qt(g),L=N*u+a;if(L+pe<=0||L-pe>=i)continue;let S=gs(g,f,u);if(S<ps*2/un)continue;let M=hn(n.get(b)),E=pn(M);if(S>=E*2/un){let A=x*f+s;h.push({label:{key:`node:${b}`,text:M,x:A,y:L,kind:"node"},box:dn(E,A,L)})}}return{deletions:d,nodes:h}}function Ut(e,n){return Math.max(ls,Math.floor(e*n/is))}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 Ns=3.4,Kt=6,Es=8,Rs=18,As=2,Cs=15;function Qt(e,n){return[...e].sort((t,r)=>n(r)-n(t))}function Wl(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:E})=>jt(M,E*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*Ns,m=Qt(e.bubbleHalos,M=>M.members),b=cn(m.map(M=>{let{x:E,y:A}=i({x:M.labelAt.x,y:Math.min(M.labelAt.y,h)}),T=A-p/2-6;return{item:M,x:E,y:d?Math.max(T,Cs):T,text:M.label}}),l,u),g=cn(Qt(e.genePins,M=>M.gene.end-M.gene.start).map(M=>{let{x:E,y:A}=i(M.at);return{item:M,x:E,y:A+e.contigThickness+Rs,text:M.covered<.98?`${M.gene.name} \u2026`:M.gene.name,stack:As}}),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:[]},N=Dn(x.deletions,u),L=cn(m.flatMap(M=>M.routes.map(E=>{let{x:A,y:T}=i(E.at);return{item:{halo:M,route:E},x:A,y:T+4,text:E.text,stack:Es}})),l,u),S=Dn(x.nodes,u,Ut(n,t));return{bubbles:b,genes:g,routes:L,sizes:[...N,...S]}}var ho=se(je(),1);var V=se(je(),1);var W=se(je(),1);function Me(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 Hl(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 Ts=4;function Ve(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 Is({nodeId:e,nodeById:n,neighbors:t}){let r=new Set([e]),o=[e],s=1/0,a=-1/0;for(let l=0;l<Ts&&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 _s({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}:Is({nodeId:e,nodeById:n,neighbors:t})}function Jt(e){let n=new Map(e.nodes.map(o=>[o.id,o])),t=Ve(e),r=new Map;for(let o of e.nodes){let s=_s({nodeId:o.id,nodeById:n,neighbors:t});s&&r.set(o.id,(s.start+s.end)/2)}return r}var eo=new WeakMap;function no(e,n,t,r,o){let{scaleX:s,scaleY:a}=t,l=eo.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,$t(f),0,0,t,h?Bn(e,h):[]))}}return eo.set(e,{graph:n,scaleX:s,scaleY:a,deletions:r,version:o,curves:i}),i}var vs=(0,V.packAbgr)(119,119,119,217),to=(0,V.packAbgr)(136,136,136,217),Bs=(0,V.packAbgr)(24,24,28,240),Os=2.2,Pe=.18,Ps=11,Gs=1.2,oo=3,$n=1e-6,Ds=7,$s=3,Fs=3,Ws=1.5,qs=.5,ks=.45,Fn=12,Hs=1e-6,he=new Float64Array(64),we=new Float64Array(64),Se=new Float64Array(64);function Xs(e,n,t,r){let o=e.length*Fn+1;he.length<o&&(he=new Float64Array(o),we=new Float64Array(o),Se=new Float64Array(o));let s=e[e.length-1];he[0]=s.x1,we[0]=s.y1,Se[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<=Fn&&l<r;f++){let u=1-(f/Fn)**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-he[a-1],(x-we[a-1])*t)*n,he[a]=g,we[a]=x,Se[a]=l,a++}}return a}function ro(e,n){let t=1;for(;t<e-1&&Se[t]<n;)t++;let r=Se[t-1],o=Se[t],s=o>r?Math.min(1,Math.max(0,(n-r)/(o-r))):0;return{x:he[t-1]+(he[t]-he[t-1])*s,y:we[t-1]+(we[t]-we[t-1])*s}}function Ys({curves:e,edgeHalfWidth:n,nodeHalfWidth:t,scale:r,yToX:o,color:s,fromSegments:a,toSegments:l}){let i=Ds+$s*n,c=Xs(e,r,o,t+i),f=Se[c-1],u=Math.min(t,f),d=f<Hs?zs(a,r,o):f-u,h=Math.min(1,d/i);if(h<qs)return;let p=ro(c,u),m=ro(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):na(x,o,js(x,l)),length:i*h,halfWidth:(Fs+Ws*n)*h,color:s}}function zs(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 js(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 Wn(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 so(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 mn(e,n,t,r){return(0,V.packAbgr)(Math.round(e*255),Math.round(n*255),Math.round(t*255),Math.round(r*255))}function Ge(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 Vs=[[68,1,84],[59,82,139],[33,145,140],[94,201,98],[253,231,37]],Us=[[237,137,44],[158,42,122]],Ks=[[220,50,50],[50,120,220]];function qn(e,n){let t=Math.max(0,Math.min(1,n))*(e.length-1),r=Math.min(e.length-2,Math.floor(t)),o=t-r,s=e[r],a=e[r+1];return(0,V.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 Qs(e,n){let[t,r,o]=Ge(Mt(e),Rn,An);return mn(t,r,o,n)}var kn=300,Zs=.7,Js=.5,co=[60,65,72],Hn=(0,V.packAbgr)(...co,255),ea=`rgb(${co.join(", ")})`;function tc(e,n){let t=Jt(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 Xn(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 Yn(e,n,t,r){switch(t){case"random":return Qs(e.id,1);case"depth":return qn(Vs,r.maxDepth>r.minDepth?(e.depth-r.minDepth)/(r.maxDepth-r.minDepth):.5);case"node-length":return qn(Ks,r.maxLength>r.minLength?(e.length-r.minLength)/(r.maxLength-r.minLength):.5);case"stable-rank":return e.stable===void 0?(0,V.packAbgr)(160,160,160,255):e.stable.rank===0?(0,V.packAbgr)(52,152,219,255):qn(Us,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,V.packAbgr)(160,160,160,255);if(e.stable!==void 0&&e.stable.rank>0)return Hn;let a=Math.max(0,Math.min(1,(s-o.start)/o.span)),[l,i,c]=Ge(a*kn,Zs,Js);return mn(l,i,c,1)}case"grey":return(0,V.packAbgr)(160,160,160,255);case"rainbow":{let o=r.nodeCount>1?n/r.nodeCount*360:0,[s,a,l]=Ge(o,.75,.5);return mn(s,a,l,1)}default:return(0,V.packAbgr)(52,152,219,255)}}function na(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 ta(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 ao(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 io=new WeakMap;function oa(e){let n=io.get(e);if(!n){let t=[],r=new Map,o=e.paths??[];for(let s=0;s<o.length;s++){let[a,l,i]=Ge(wt(s,o.length),Rn,An);t.push(mn(a,l,i,.85)),r.has(o[s].name)||r.set(o[s].name,s)}n={pathColorByIndex:t,pathIndexByName:r},io.set(e,n)}return n}var lo=new WeakMap,ra=new Map;function sa(e){let n=lo.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])}lo.set(e,n)}return n}function oc(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"?Et(t):0,x=f.scaleX,N=ln(f),L=no(n,t,f,p,b),S=[],M=new Map,E=[],A=new Map,T=[],G=new Map,$={...Xn(t),referenceRamp:h},F=new Map;if(o==="rainbow")for(let _=0;_<t.nodes.length;_++)F.set(t.nodes[_].id,_);let q=t.paths?.length??0,{pathColorByIndex:k,pathIndexByName:Z}=oa(t),U=_=>k[Z.get(_)??-1]??to,K=l&&q>1?sa(t):ra,Ze=x>(u?1:ks);for(let _=0;_<t.edges.length;_++){let P=t.edges[_],Q=n[P.from],ne=n[P.to],Y=L.get(_);if(!Q?.length||!ne?.length||!Y||m?.has(_))continue;let le=P.pathIds?.length??0,ce=p?.get(_)!==void 0,ue=c?.edgeIndexes.has(_)??!1,J=a/2*(ce?Os:1),de=l&&le>0,ge=ce?Bs:vs,te=!c||ue?ge:Me(ge,Pe),ke=r.get(P.to),Ae=(ke?an(ke,s,i,g):s)/2,Ce=(xe,Ie,z,fe)=>{let re=xe===0&&Ie===0?Y:vn(Y,xe,Ie);if(d&&!ao(re,d))return;if(ce)for(let Ln of Gt(re,Ps/x))T.push({curves:Ln,thickness:J,color:z});else T.push({curves:re,thickness:J,color:z});let en=Ze&&fe!==void 0?Ys({curves:re,edgeHalfWidth:J,nodeHalfWidth:Ae,scale:x,yToX:N,color:fe,fromSegments:Q,toSegments:ne}):void 0;en&&E.push(en)},ye=T.length,Te=E.length,oe=c&&ue&&!de?c.walks:void 0;if(oe){let xe=r.get(P.from),Ie=xe?an(xe,s,i,g):s,z=Math.max(Ie/oe.length,oo),fe=Wn(Q,N),{nx:re,ny:en}=(P.fromStrand==="-"?fe[0]:fe.at(-1))??{nx:0,ny:0},Ln=1/Math.max(x,$n);oe.forEach((Nn,Dr)=>{if(!Nn.edgeIndexes.has(_))return;let En=(Dr-(oe.length-1)/2)*z*Ln,mt=En===0?Y:vn(Y,re*En,en*En/N);d&&!ao(mt,d)||T.push({curves:mt,thickness:z/2,color:Nn.colors.get(P.from)??Nn.colors.get(P.to)??ge})})}else if(!de)Ce(0,0,te,te);else{let xe=Dt(Q,ne,le,f),Ie=Math.floor((le-1)/2);for(let z=0;z<le;z++){let fe=xe[z],re=U(P.pathIds[z]);Ce(fe.x,fe.y,c&&!c.names.has(P.pathIds[z])?Me(re,Pe):re,z===Ie?te:void 0)}}let He=T.length-ye;He>0&&G.set(_,{start:ye,count:He});let Je=E.length-Te;Je>0&&A.set(_,{start:Te,count:Je})}for(let[_,P]of Object.entries(n)){let Q=r.get(_);if(!Q||d&&!ta(P,d))continue;let ne=Yn(Q,F.get(_)??0,o,$),Y=c!==void 0&&!c.nodeIds.has(_),le=Y?Me(ne,Pe):ne,Re=an(Q,s,i,g),ce=Re/2,ue=S.length,J=K.get(_),de=Re/q,ge=P.length>=2,te=c&&!Y&&!J?.length?c.walks:void 0;if(ge&&te){let Ae=Math.max(Re/te.length,oo),Ce=Wn(P,N),ye=1/Math.max(x,$n);te.forEach((Te,oe)=>{let He=Te.colors.get(_);if(He===void 0)return;let Je=(oe-(te.length-1)/2)*Ae*ye;S.push({points:te.length===1?P:so(P,Ce,Je,N),thickness:Ae/2,color:He})})}else if(ge&&J?.length&&de>=Gs){let Ae=Wn(P,N),Ce=1/Math.max(x,$n);for(let ye of J){let Te=(ye-(q-1)/2)*de*Ce,oe=k[ye]??to;S.push({points:so(P,Ae,Te,N),thickness:de/2,color:Y?Me(oe,Pe):oe})}}else ge&&S.push({points:P,thickness:ce,color:le});let ke=S.length-ue;ke>0&&M.set(_,{start:ue,count:ke})}return{nodeStrokes:S,nodeStrokeRuns:M,arrows:E,arrowRuns:A,edgeCurves:T,edgeCurveRuns:G}}var aa=[{value:"progress",label:"Progress along the walk",legend:"pale where the walk starts, deep where it ends"},{value:"reference",label:"Reference position",legend:"along the reference left to right, charcoal off it"},{value:"strand",label:"Strand against the reference",legend:"pale where the walk runs as the reference does, deep where reversed"},{value:"visits",label:"Visits",legend:"pale where the walk passes once, deep four times or more"}],ia=[{value:"rainbow",label:"Rainbow"},{value:"blues",label:"Blues",hue:215},{value:"reds",label:"Reds",hue:0},{value:"greens",label:"Greens",hue:130},{value:"oranges",label:"Oranges",hue:30},{value:"purples",label:"Purples",hue:280},{value:"greys",label:"Greys"}],uo=["blues","reds","greens","oranges","purples"];function ac(e,n,t){return{field:e.color?.field??(n?"reference":"progress"),scheme:e.color?.scheme??(n?"rainbow":uo[t%uo.length])}}var fo=.82,la=.28;function mo(e,n){let t=Math.max(0,Math.min(1,n));if(e==="rainbow")return{h:t*kn,s:.7,l:.5};let r=ia.find(s=>s.value===e),o=fo+(la-fo)*t;return r&&"hue"in r?{h:r.hue,s:.75,l:o}:{h:0,s:0,l:o}}function zn(e,n){let{h:t,s:r,l:o}=mo(e,n);return`hsl(${t}, ${r*100}%, ${o*100}%)`}function ic(e,n){let{h:t,s:r,l:o}=mo(e,n),[s,a,l]=Ge(t,r,o);return(0,ho.packAbgr)(Math.round(s*255),Math.round(a*255),Math.round(l*255),255)}var lc=Hn;var po={same:.2,reversed:.95};function cc({field:e,scheme:n}){if(e==="strand"){let r=zn(n,po.same),o=zn(n,po.reversed);return`linear-gradient(to right, ${r} 50%, ${o} 50%)`}return`linear-gradient(to right, ${Array.from({length:7},(r,o)=>{let s=o/6;return`${zn(n,s)} ${s*100}%`}).join(", ")})`}function uc(e){return aa.find(n=>n.value===e).legend}function hc(e){return Xe(e)?bo(e):void 0}function bo(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 ca(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 ua(e){return`${e.haplotype??e.sample}\0${e.refName}`}function mc(e,{maxGap:n=1/0}={}){let t=new Map;for(let o of e.nodes)if(Xe(o)){let s=bo(o),a=ua(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=ca(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 da(e,n){return(n.haplotype===void 0?void 0:e(n.haplotype))??e(n.sample)}function bc(e,n){return e.flatMap(t=>{let r=da(n,t);return r===void 0?[]:[{...t,sample:r}]})}function gc(e){return`${e.refName}:${e.start+1}-${e.end}`}function jn(e){return`${e.refName}:${(e.start+1).toLocaleString()}-${e.end.toLocaleString()}`}var go=se(tn(),1),yo=(0,ae.createSvgIcon)((0,go.jsx)("path",{d:"M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z"}),"CompareArrows");var xo=se(tn(),1),Mo=(0,ae.createSvgIcon)((0,xo.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 wo=se(tn(),1),Vn=(0,ae.createSvgIcon)((0,wo.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 fa="Linear genome view",pa="Linear synteny view",ha="No synteny track in this session aligns these assemblies";function So({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 Tc({contributors:e,syntenyTracks:n,onShowLinear:t,onShowSynteny:r}){let o=n[0]?.coverage??e.length;return[...So({label:fa,icon:Vn,entries:e,entryLabel:s=>`${s.sample} ${jn(s)}`,onSelect:s=>()=>{t({location:s,assembly:s.sample})}}),...e.length>=2?So({label:`${pa} (${o} assemblies)`,icon:yo,entries:n,entryLabel:s=>s.coverage<o?`${s.name} (${s.coverage} of ${o})`:s.name,nameTheOnlyEntry:!1,disabledHelpText:ha,onSelect:s=>()=>{r(s.trackId)}}):[]]}function Ic({own:e,reference:n,highlight:t,onShowLinear:r,onHighlight:o}){let s=[e?{label:`Open in ${e.assembly} \u2014 ${jn(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:Mo,onClick:()=>{o(t)}}]:[],...s.map(({label:a,target:l})=>({label:a,icon:Vn,onClick:()=>{r(l)}}))]}function Un(e){return e.id.endsWith("-")?"-":"+"}function Kn(e,n){return n===Un(e)?e.id:`-${e.id}`}function ba(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 ga(e,n){let t=e.path.map(()=>[]);if(e.cs===void 0)return t;let r=ba(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 No(e,n,t){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of n){let a=s.path.map(f=>r.get(f.name)),l=a.flatMap((f,u)=>f?[u]:[]),i=l[0],c=l.at(-1);if(i!==void 0&&c!==void 0){let f=ga(s,a.map(h=>h?.length)),u=l.map(h=>Kn(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 ya=["#6baed6","#4292c6","#2171b5","#08519c"],xa=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Eo(e){let n=e.is_reverse?xa:ya;return n[e.id%n.length]}function bn(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 Ma(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 wa(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 Sa(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 La(e,n,t){let r=Sa(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 Ao(e){let n=new Map(e.nodes.filter(Xe).map(s=>[s.id,s])),t=Ve(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}=Ma(s.id,n,t,r),i=wa(l);if(i){let{offsets:c,ordered:f}=La(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 Na=1,Ea=.015;function gn({graph:e,span:n,rowY:t,positions:r}){let o=n*Ea,s=Ao(e),a=new Map(e.nodes.map(f=>[f.id,f])),l=[];for(let f of s){let u=f.refSpan-f.pathLength;u>=Na&&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,N=S=>f.start+S*h,L=t(b);r[p]=h?[{x:N(g),y:L},{x:N(g+b.length),y:L}]:[{x:f.start+m*x,y:L},{x:f.start+(m+1)*x,y:L}]}})}let i=Ve(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 Ra(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 Co(e,n){let t=_e(e);if(t.length===0)return;let r=sn(t,n),o=Ra(e),s=ve(t),a=gn({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 Aa=12,Qn=20;function To(e){return 10+8*Math.log2(1+e.length)}function me(e,n){return e<n?-1:e>n?1:0}function _o(e,n){return me(e.at,n.at)||me(e.side,n.side)||me(e.hops,n.hops)}var Io={at:1/0,side:0,hops:0};function Ca(e){let n=new Map(e.nodes.map(r=>[r.id,r])),t=_a(e);return e.nodes.map(r=>r.id).sort((r,o)=>_o(t.get(r)??Io,t.get(o)??Io)||me(n.get(r).name,n.get(o).name)||me(r,o))}function Ta(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 Ia(e,n){let t=[...n.entries()].sort(([a,l],[i,c])=>_o(l,c)||me(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 _a(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)=>me(s.stable.start,a.stable.start)||me(s.name,a.name)),o=new Map;return Ta(e,r).forEach((s,a)=>{o.set(s,{at:a,side:0,hops:0})}),Ia(t,o),o}function va(e){let n=new Map(e.nodes.map(u=>[u.id,u])),t=Ca(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 vo(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}=va(e),a=r.map(u=>{let d=0;for(let h of u)d=Math.max(d,To(n.get(h)));return d}),l=[],i=0;for(let u=0;u<r.length;u++)l[u]=i,i+=a[u]+Aa;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?Qn: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/Qn);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*Qn)}}let f={};for(let u of e.nodes){let d=o.get(u.id),h=To(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 Ba(e,n){let t=new Map;for(let o of e.nodes)if(rn(o)){let{sample:s}=bn(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 Bo(e,n,t=[]){let r=_e(e),o=Ba(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=gn({graph:e,span:s,rowY:d=>{let h=d.stable;return((h?a.get(bn(h.refName).sample):void 0)??i)*20},positions:l}),u=[{label:bn(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 Zn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[],featureRectangles:[]}}var Qe=!1,Oo=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f"];function Ko(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=>Oo[n.id%Oo.length]),trackAlpha:e.trackAlpha??(()=>1)}}var B=Ko({}),ot=null,y=[],w=[],R=[],I=new Map,Fe=[],C=[],Le=[],st=[],at=[],ee=-1,D=Zn(),rt={minX:0,maxX:0,minY:0,maxY:0},Ue,yn=new Map;function Qo(e,n,t=[],r={}){if(B=Ko(r),ot=r.bed??null,D=Zn(),Le=[],st=[],at=[],Fe=[],rt={minX:0,maxX:0,minY:0,maxY:0},Ue=void 0,yn=new Map,e.length===0||n.length===0)return;let o=Jn(e);y=[],o.forEach((i,c)=>{y[c+1]=i}),w=Jn(n);let s=t.length>0;R=Jn(Mi(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&&(Ue=c.name)}if(w.length===0)return;Pa(0),I=Do(),De(w),B.showReads&&R.length>0&&De(R),Uo(),B.mergeNodesFlag&&($o(),nt(),B.showReads&&R.length>0&&et(),xi(),I=Do(),Uo(),De(w),B.showReads&&R.length>0&&De(R)),$o(),ti(),Qe&&console.log(`${y.length} nodes.`),nt(),ee=Wo(),oi(),nt(),ee=Wo();let a=B.showReads&&B.coarsenedReadView&&!s;if(a){let i=Ue===void 0?-1:w.findIndex(u=>u.name===Ue),c=i===-1?0:i,f=w.filter((u,d)=>d!==c);if(f.length>0){let u=Yo(f,"haplotype");u.length>0&&(w=[w[c]],R=u)}}pi(),ii(),B.showExonsFlag&&ot!==null&&fi();let l=B.showReads&&B.coarsenedReadView&&R.length>0&&!a;return B.showReads&&R.length>0?(Ga(),et(),De(R),l&&(R=Yo(R,"read"),et(),De(R)),$a(),w=w.concat(R)):y.forEach(i=>{i&&(i.incomingReads=[],i.outgoingReads=[],i.internalReads=[])}),si(),bi(),Qe&&(console.log("Tracks:"),console.log(w),console.log("Nodes:"),console.log(y),console.log("Lane assignment:"),console.log(Le)),Ka(),{nodes:y,tracks:w,reads:R,nodeMap:I,shapes:D,bounds:rt,maxOrder:ee,trackForRuler:Ue,coarsenedEdgeMeta:yn}}function $e(e,n="plain"){return B.trackColor(e,n)}function Oa(e){return B.trackAlpha(e)}function Jn(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 be(e){return X(e)?e:`-${e}`}function Zo(e){return X(e)?O(e):be(e)}function xn(e){return(e||1/e)>=0}function Pa(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]=be(s))}}y.forEach(r=>{r&&n.has(r.name)&&(r.seq=r.seq.split("").reverse().join(""))})}function Ga(){Fe=[];for(let n=0;n<=ee;n+=1)Fe[n]=[];let e=new Map;y.forEach(n=>{n.y!==void 0&&Po(e,n.order,n.y+n.contentHeight)}),w.forEach(n=>{n.type==="haplotype"&&n.path.forEach(t=>{Po(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,Fe[n.order].push(t))})}function Po(e,n,t){let r=e.get(n);r===void 0?e.set(n,t):e.set(n,Math.max(r,t))}var Mn=7;function Da(){y.forEach(e=>{e&&(e.incomingReads=[],e.outgoingReads=[],e.internalReads=[])}),R.forEach((e,n)=>{if((e.width===void 0||e.width===0)&&(e.width=Mn),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 $a(){za(),Da();let e=y.slice();e.sort(wn);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?Mn:0;e.forEach(a=>{if(a)for(let l of t)Fa(n.get(l),a,r)});let o=Ya(),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(qa),s.forEach(a=>{let l=R[a.readIndex],i=l.path[a.pathIndex];i.y=o[i.order],o[i.order]+=l.width}),Qe&&(console.log("Reads:"),console.log(R))}function Fa(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,N;for(let L=1;L<=b;L++){let S=g[b-L]?.y;if(S!==void 0){x=L,N=S;break}}return{entry:p,decisionStep:x,y:N}});i.sort(Wa),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,Go(f,m,p[1],c,n),c+=m.width});let u=c;s.sort(ka);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 N=R[x[0]],L=N.path[x[1]];L.y!==void 0&&L.y>=c&&(L.y+=m.width,Go(f,N,x[1],L.y,n))}),c+=m.width,u+=m.width)}),a.sort(Xa),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||Mn;m.path[0].y=c,f.set(c,g),u=Math.max(u,c)});let h=u-n.y-n.contentHeight;n.contentHeight+=h,di(n,h)}function Wa(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 Go(e,n,t,r,o){t===n.path.length-1?e.set(r,n.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function qa(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 ka([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?wn(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 Ha(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 Xa(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 Ya(){let e=[];for(let n=0;n<=ee;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 za(){R.forEach(e=>{let n=Math.abs(e.indexSequence[0]),t=xn(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=xn(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 et(){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),ja(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 ja(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=Jo(t.seq).split("").reverse().join(""))})}var Va={A:"T",T:"A",C:"G",G:"C"};function Jo(e){let n="";for(let t=e.length-1;t>=0;t-=1)n+=Va[e.charAt(t)]??"N";return n}function De(e){e.forEach(n=>{n.indexSequence=[],n.sequence.forEach(t=>{let r=t,o=I.get(O(r)),s=y[o]?.switched??!1;s&&(r=Zo(r));let a=I.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 Ua=20;function Ka(){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+Ua+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)})}),rt=e}function ie(e){let n=I.get(O(e)),t=n===void 0?void 0:y[n];if(t===void 0)throw new Error(`Unknown node ${e}`);return t}function Do(){return I=new Map,y.forEach((e,n)=>{e&&I.set(e.name,n)}),I}function $o(){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 Fo(e){let n=0,t=0,r=0;e.forEach(o=>{let s=Math.abs(o);if(o<0){C[s]===void 0&&(C[s]=t);let a=C[s];a<r&&(r=a),n=a,t=a-1}else{C[s]===void 0&&(C[s]=n);let a=C[s];n=a+1,t=a}}),r<0&&it(-r)}function Qa(e){let n=0,t=0;for(;n<e.length&&C[Math.abs(e[n])]===void 0;)n+=1;if(n>=e.length)return null;let r=e[n],o,s;r>=0?(o=C[r]-1,s=-1):(o=C[-r]+1,s=1);for(let a=n-1;a>=0;a-=1){let l=Math.abs(e[a]);C[l]===void 0&&(C[l]=o,t=Math.min(t,o),o+=s)}return t<0&&it(-t),n}var Za=-1;function Ja(e){let n=[];for(let t of e)n.push(t??Za);return n}function nt(){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};C=new Array(y.length).fill(void 0),y.forEach(i=>{i&&(i.order=void 0)}),Fo(w[0].indexSequence);for(let i=1;i<s.length;i+=1){if(Qe&&console.log(`generating order for track ${i+1}`),t=Qa(s[i].indexSequence),t===null){s[i].type==="haplotype"?Fo(s[i].indexSequence):(s.splice(i,1),R.splice(i-w.length,1),i-=1);continue}for(e=ni(s[i].indexSequence);t<e.length;){for(r=t,t+=1;t<e.length&&C[e[t]]===void 0;)t+=1;if(t<e.length){n=C[e[r]]+1;for(let c=r+1;c<t;c+=1)C[e[c]]=n,n+=1;if(C[e[t]]>C[e[r]])C[e[t]]<n&&qo(e[t],e[t-1],n);else if(s[i].indexSequence[t]>=0&&!ei(e[t],e[r],a))qo(e[t],e[t-1],n);else if(s[i].indexSequence[r]<0||y[e[r+1]].degree<2&&C[e[t]]<C[e[r]]){n=C[e[r]]-1;for(let c=r+1;c<t;c+=1)C[e[c]]=n,o=Math.min(o,n),n-=1}}else if(s[i].indexSequence[r]>=0){n=C[e[r]]+1;for(let c=r+1;c<e.length;c+=1){let f=e[c];C[f]===void 0&&(C[f]=n,n+=1)}}else{n=C[e[r]]-1;for(let c=r+1;c<e.length;c+=1){let f=e[c];C[f]===void 0&&(C[f]=n,o=Math.min(o,n),n-=1)}}}}o<0&&it(-o);let l=Ja(C);C=l,l.forEach((i,c)=>{let f=y[c];f!==void 0&&(f.order=i)})}function ei(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 Wo(){let e=-1;return C.forEach(n=>{n!==void 0&&n>e&&(e=n)}),e}function ni(e){return e.map(n=>Math.abs(n))}function it(e){C.forEach((n,t)=>{n!==void 0&&(C[t]=n+e)})}function qo(e,n,t){let r=new Map,o=[[e,t]],s=0;for(;s<o.length;){let[a,l]=o[s];s+=1;let i=C[a];i!==void 0&&i<l&&(!r.has(a)||r.get(a)<l)&&(r.set(a,l),y[a].successors.forEach(c=>{C[c]>i&&c!==n&&o.push([c,l+1])}),a!==e&&y[a].predecessors.forEach(c=>{C[c]>i&&c!==n&&o.push([c,l+1])}))}r.forEach((a,l)=>{C[l]=a})}function ti(){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 oi(){let e=w[0],n=w.slice(1,w.length);if(B.showReads&&R.length>0&&(n=n.concat(R)),ri(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 ri(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)&&ko(t,l,X(s[a])?1:-1),(c===void 0||c>i.order)&&(f===void 0||i.order>f)&&ko(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]=Zo(s),o.indexSequence[a]=-o.indexSequence[a])});t.forEach((o,s)=>{if(o>0){let a=ie(s);a.seq=Jo(a.seq),a.switched=!0}})}function ko(e,n,t){e.set(n,(e.get(n)??0)+t)}function si(){let e=0,n=20,t=-1,r=y.slice();r.sort(wn);let o=ai();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 ai(){let e=[],n=[],t=[],r=[];for(let o=0;o<=ee;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<=ee;o+=1)r.push(Math.max(Math.max(0,e[o]-1)+Math.max(0,n[o-1]-1),t[o]));return r}function ii(){let e,n,t,r,o,s,a=[],l=[];for(let i=0;i<=ee;i+=1){Le[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=xn(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=xn(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<=ee;i+=1)ci(Le[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]};Le[e].push(i),n!==null&&s[e].set(n,i)}else l.type="multiple",l.tracks.push(a);o[e][t]=a}function li(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 ci(e,n){let t=0,r=new Set,o=20,s=!1,a=-1;li(e,n),e.sort(Xo),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(Xo),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}),ui(e,r)}function ui(e,n){let t=0,r=Number.MAX_SAFE_INTEGER;n.forEach(o=>{Ho(e,o)<r&&(r=Ho(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 di(e,n){e.order<0||Le[e.order]===void 0||(Le[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)})}),Fe[e.order].length>0&&Fe[e.order].forEach(t=>{y[t]!==e&&y[t].y>e.y&&(y[t].y+=n)}))}function Ho(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 Xo(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 wn(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 fi(){let e,n,t={};ot.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 pi(){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 hi(e){let n=e.path[0],t=y[n.node],r=e.firstNodeOffset??0;return lt(t,n.isForward?r:t.sequenceLength-r)}function mi(e){let n=e.path[e.path.length-1],t=y[n.node],r=e.finalNodeCoverLength??0;return lt(t,n.isForward?r:t.sequenceLength-r)}function er(e,n){return n>e.sequenceLength?null:lt(e,n)}function lt(e,n){let[t,r]=yi(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 bi(){let e,n,t,r,o,s,a,l,i;for(let u=0;u<=ee;u+=1)st.push(0),at.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(Ha),w.forEach(u=>{a="plain",o=$e(u,a),s=Oa(u);let d=a,h=()=>(d!==a&&(d=a,o=$e(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=hi(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=zo(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=zo(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=mi(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 gi=1e9;function Yo(e,n){yn=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),N=y[g],L=y[x];if(!N||!L)continue;let S;if(r){let E=`${m}>${b}`,A=`${-b}>${-m}`;S=E<A?E:A}else S=`${m}>${b}`;let M=t.get(S);M===void 0?t.set(S,{sSigned:m,dSigned:b,sName:m<0?`-${N.name}`:N.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=Mn,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=gi+c,p=`${d.count.toLocaleString()} ${n}${d.count===1?"":"s"}: Node ${d.sName} \u2192 Node ${d.dName}`;yn.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 Qe&&console.log(`[coarsened] ${n}s_in=${e.length} edges_out=${i.length} tallestNodeBeforePlace=${f}(${u.toFixed(1)})`),i}function zo(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=$e(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=$e(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=$e(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=$e(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 jo=7;function Vo(e,n,t,r,o,s,a,l,i,c){let f=e===1?at:st,u=10*f[l],d=n+e*(u+5),h=jo,p=Math.min(jo,o),m=Math.min(t,r),b=Math.max(t,r),g=e===1?n:d-1,x=e===1?d:n,N=E=>{D.verticalRectangles.push({xStart:g,yStart:E,xEnd:x,yEnd:E+o-1,color:s,id:a,name:c,type:i})};N(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}),N(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 yi(e){let n=e.x-4,t=e.x+e.pixelWidth+4;return[n,t]}function Uo(){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 xi(){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[I.get(e)].add(O(n)):(r[I.get(e)].add(n),r[I.get(e)].add(be(n)))):l.type==="haplotype"&&r[I.get(e)].add("None"),i<l.sequence.length-1?(n=l.sequence[i+1],X(n)?t[I.get(e)].add(O(n)):(t[I.get(e)].add(n),t[I.get(e)].add(be(n)))):l.type==="haplotype"&&t[I.get(e)].add("None")):(i>0?(e=l.sequence[i-1],t[I.get(l.sequence[i])].add(e),X(e)&&t[I.get(l.sequence[i])].add(O(e))):l.type==="haplotype"&&t[I.get(l.sequence[i])].add("None"),i<l.sequence.length-1?(e=l.sequence[i+1],r[I.get(l.sequence[i])].add(e),X(e)&&r[I.get(l.sequence[i])].add(O(e))):l.type==="haplotype"&&r[I.get(l.sequence[i])].add("None"))});let s=t.map(l=>Array.from(l)),a=r.map(l=>Array.from(l));if(B.showReads&&R.length>0){let l=y.slice();l.sort(wn);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=Ke(I.get(d.name),s,a);if(h){let p=f(h)+ie(h).sequenceLength;i.set(d.name,p),i.set(be(d.name),p),c.set(d.name,u(h)),c.set(be(d.name),u(h))}else i.set(d.name,0),i.set(be(d.name),0),c.set(d.name,d.name),c.set(be(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=Ke(I.get(m),s,a);if(b&&tt(I.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(N=>{N.pos+=x}),g.nodeName=u(g.nodeName)}}})}for(let l=0;l<y.length;l+=1)if(tt(l,s,a)&&!Ke(l,s,a)){let i=l;for(;tt(i,s,a);)i=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=I.get(e);Ke(c,s,a)&&l.sequence.splice(i,1)}});for(let l=y.length-1;l>=0;l-=1)Ke(l,s,a)&&y.splice(l,1)}function Ke(e,n,t){if(n[e].length!==1||n[e][0]==="None")return!1;let r=O(n[e][0]),o=I.get(r);return t[o].length!==1||t[o][0]==="None"?!1:r}function tt(e,n,t){if(t[e].length!==1||t[e][0]==="None")return!1;let r=O(t[e][0]),o=I.get(r);return!(n[o].length!==1||n[o][0]==="None")}function Mi(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 wi(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 Si(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 nr(e,n){let t=wi(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(Si),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 tr(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 Li(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 Ni(e){let n=new Map(e.nodes.map(s=>[s.id,s])),t=Li(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]??Un(u);return[Kn(u,h)]});return c.length>0?[{id:a,name:s.name,sequence:c,sourceTrackID:0,type:"haplotype"}]:[]})}function Ei(e){return e.nodes.map(n=>({name:n.id,seq:"",sequenceLength:Math.max(1,n.length)}))}function We(e){return(e.paths?.length??0)>0}var Ri=600,Ai=3,Ci=15;function Ti(e){return Math.max(Ai,Math.min(Ci,Math.floor(Ri/Math.max(1,e))))}function or(e){let n=e.paths??[],t=Ni(e),r=e.reads?No(e,e.reads,n.length):[],o=r.length>0?Lt:St,s=n.map((l,i)=>o(i,n.length)),a=Qo(Ei(e),t,r,{nodeWidthOption:"compressed",trackWidth:Ti(t.length),trackColor:l=>l.type==="read"?Eo(l):s[l.id]});return a?{layout:a,pathColors:s}:void 0}function ct(e){let n=[];return e.nodes.forEach(t=>{t.order>=0&&n.push(t)}),n}function rr(e,n,t,r){let o=e.y+e.contentHeight/2-n;return[{x:t,y:o},{x:r,y:o}]}function sr(e,n){return{minY:e.bounds.minY-n,maxY:e.bounds.maxY-n}}function ar(e){let n=We(e)?or(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=t.bounds.minY,s={};for(let i of ct(t))s[i.name]=rr(i,o,i.x,i.x+i.pixelWidth);let{minY:a,maxY:l}=sr(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 Ii(e,n){let t=new Map(e.nodes.map(l=>[l.id,l])),r=new Map;for(let l of ct(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 _i(e){return e.nodes.some(v)&&We(e)}function ir(e){let n=_i(e)?or(e):void 0;if(!n)return;let{layout:t,pathColors:r}=n,o=Ii(e,t),s=new Map(o.map(i=>[i.order,i])),a=t.bounds.minY,l={};for(let i of ct(t)){let c=s.get(i.order);l[i.name]=rr(i,a,c.bp0,c.bp1)}return{nodePositions:l,tubeMap:{layout:t,yOffset:a,columns:o,pathColors:r},referenceAxis:!0,pixelRows:!0,extent:sr(t,a)}}function lr(e){return e.sample??on(e.name)}function vi(e){return e.haplotype!==void 0&&e.sample!==void 0?`${e.sample}#${e.haplotype}`:lr(e)}function Bi(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 cr(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}=Bi(m.nodeIds,i,l,f),x=[],N=0,L=0,S=0;for(let M of b){let E=s.get(M)??0,A=i.get(M),T=x.at(-1),G=T?.referenceStart,$=A&&G!==void 0&&S>=0&&G+T.bp===A.start,F=A&&G!==void 0&&S<=0&&A.end===G;!A&&T&&!T.onReference?T.bp+=E:$||F?(T.bp+=E,$||(T.referenceStart=A.start,T.reversed=!0),S=$?1:-1):(x.push({start:N,bp:E,onReference:A!==void 0,referenceStart:A?.start}),S=0),N+=E,A||(L+=E)}return{name:m.name,label:vi(m),sample:lr(m),haplotype:m.haplotype,bp:N,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 Oi=1.3;function Pi(e){let n=e.reference.bp;for(let t of e.rows)n=Math.max(n,t.bp);return{maxX:e.origin+n*Oi,maxY:e.rows.length*20}}function ur(e,n){let t=_e(e),r=cr(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:Pi(r)}}var Gi="Force-directed layout",Ne=e=>e.nodes.some(v),dr=e=>Ne(e)&&(e.paths?.length??0)>1,fr=e=>Ne(e)&&We(e),pr=e=>Ne(e)&&e.nodes.some(rn),ut=[{value:"auto",label:"Anchored",description:"x is reference bp, one row per stable rank. Needs rGFA tags or a reference path.",run:Co,cutMargins:!0,wholeWalks:!1,available:Ne,drawsLocally:Ne},{value:"samplerows",label:"Sample rows",description:"x is reference bp, one row per contributing assembly. Needs rGFA tags or a reference path.",run:Bo,cutMargins:!0,wholeWalks:!1,available:pr,drawsLocally:pr},{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:ur,cutMargins:!1,wholeWalks:!0,available:dr,drawsLocally:dr},{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:vo,cutMargins:!1,wholeWalks:!1,available:Ne,drawsLocally:Ne},{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:ar,cutMargins:!1,wholeWalks:!1,available:We,drawsLocally:We},{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:ir,cutMargins:!0,wholeWalks:!1,available:fr,drawsLocally:fr},{value:"force",label:Gi,description:"OGDF FMMM, via the external Bandage engine.",run:()=>{},cutMargins:!1,wholeWalks:!1,available:()=>!0,drawsLocally:()=>!1}],Ru=ut.map(e=>e.value);function Au(e,n){return!Di(e).drawsLocally(n)}function Di(e){return ut.find(n=>n.value===e)??ut[0]}var $i=10;function Fi(e,n){let t=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return n.find(o=>r<=$i*(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 Wi=40;function Ee(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function qi(e,n){let t=Ee(e),r=Ee(n),o=r.slice(r.indexOf(" "));return t.endsWith(o)?`${t.slice(0,-o.length)}\u2013${r}`:`${t}\u2013${r}`}function hr(e){return e>=Nt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Iu(e,n=[]){let t=ki(e,n);return e.partial?{...t,label:`${t.label}, partial`}:t}function ki(e,n){let t=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:l}=e,i=qi(r,o);if(a>=Wi)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${hr(s)}${l?", inv":""}`};if(l)return{kind:"inversion",label:`${Ee(o)} inv`};let c=o!==r?Fi(e,n):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${hr(s)}`}}let f=s>2?`, ${s} alleles`:"";return r===o&&r===t?t<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${Ee(t)} sub`}:t===0||r===t?{kind:"insertion",label:`\u2264${Ee(o-t)} ins${f}`}:o===t?{kind:"deletion",label:`${Ee(t-r)} del${f}`}:{kind:"complex",label:`${Ee(t)} ref \u2192 ${i}, ${s} alleles`}}var _u={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},vu={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function Bu(e){return e.segments.split(",").filter(Boolean)}var gr=se(je(),1);var qe=10,Hi=qe+8,dt=5;function $u(e,{colorScheme:n,referenceRamp:t,walkNodes:r}){let o={...Xn(e),referenceRamp:t},s=[];return e.nodes.forEach((a,l)=>{if(v(a)){let i=Yn(a,l,n,o);s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,color:(0,gr.abgrToCssRgba)(r&&!r.has(a.id)?Me(i,Pe):i)})}}),s.sort((a,l)=>a.bp0-l.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 mr=2;function Xi(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 Fu(e,n,t,r){if(r<0||r>qe+mr)return;let o,s=mr;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 Wu(e,n){let t=e?.[Math.floor(e.length/2)];return t?n(t):void 0}function br(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 qu(e,n,t,{width:r,lit:o,darkMode:s}){let a=s?"#ffffff":"#18181c";e.fillStyle=s?"#1f1f1f":"#ffffff",e.fillRect(0,0,r,Hi);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=Xi(n,t,r);if((l.left>0||l.right>0)&&(e.beginPath(),l.left>0&&br(e,0,1),l.right>0&&br(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 Yu(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 zu(e){let n;for(let t of e.values())(!n||t.length>n.length)&&(n=t);return n}var yr=5,Yi=10,zi=110,ji=3;function Vi(e){return e?"#b0b0b8":"#55555c"}function Ui(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 xr(e){let n=[];for(let t of e)n.every(r=>Math.abs(t.at-r.at)>=(t.width+r.width)/2+Yi)&&n.push(t);return n.map(({text:t,at:r})=>({text:t,at:r}))}function Ki(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=Ui(i/(l-a)*zi),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:xr(u)}}function Qi(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>=ji&&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:xr([...h,...u,...d])}}function Zi(e,n,t,r,o=!1){return(o?Ki:Qi)(e,n,t,r)}function ju(e,n,t,r,o=!1){let{x:s,width:a,darkMode:l}=t;e.font="10px sans-serif";let i=Zi(n,s,a,u=>e.measureText(u).width,o);if(!i)return;let c=Vi(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+yr);e.stroke();for(let{text:u,at:d}of i.labels)e.fillText(u,d,r+yr+2)}function Ku(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 Qu(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 Ji=3;function Zu(e,n,t,r){if(n<=0||r<0||r>n)return;let o=r/n,s,a=Ji;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 wr(e,n,t){e.moveTo(n.top0,0),e.lineTo(n.bottom0,t),e.moveTo(n.top1,0),e.lineTo(n.bottom1,t)}function Ju(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)wr(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(),wr(e,a,t),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function el(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 nl(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 td(e,n,t){let r=el(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=nl(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 tl(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function od(e,n,{x:t,y:r,width:o,darkMode:s}){if(n.length!==0){e.fillStyle=tl(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 ol(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=>er(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 Sr(e){return e.reads.flatMap(n=>ol(n,e))}function Cr(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 Tr(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 Lr(e,n,t){let r=Cr(e);return{commands:r,color:n,alpha:t,...Tr(r)}}function Nr(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=nr(t.curves,n).map(a=>Lr(a.path,a.color,a.alpha??1)),s=t.corners.filter(a=>a.type===n).map(a=>Lr(a.path,a.color,1));return{rects:r,shapes:[...o,...s]}}function cd(e){let n=[];return e.nodes.forEach(t=>{if(t.order>=0){let r=Cr(tr(t));n.push({name:t.name,commands:r,...Tr(r)})}}),{bounds:e.bounds,layers:[Nr(e,"haplotype"),Nr(e,"read")],nodes:n,mismatches:Sr(e).filter(t=>t.kind!=="insertion"||!t.softClip)}}function Er(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 Rr(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 rl=12,sl=.15;function al(e){return Math.max(sl,Math.min(1,e/rl))}function ud(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)Rr(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)}),Rr(e,c.shapes,a,f=>{Er(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(),Er(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:al(r(c.x1)-r(c.x0)),e.stroke(),e.globalAlpha=1}cl(e,n.mismatches,t)}var Ir=12,il=6;function ll(e){return Ir*e>=il}function Ar(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 cl(e,n,t){let{x:r,y:o,yScale:s,darkMode:a}=t;if(!ll(s)||n.length===0)return;let l=Ir*s;e.fillStyle="grey",e.beginPath();for(let i of n)if(i.kind==="deletion"&&Ar(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)Ar(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 pd(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 _r=22,ul=4,Sn=8,dl="11px sans-serif",fl=8;function hd(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(ul,r)}function md(e,n,t,r,o=0){let{x:s,width:a,darkMode:l}=t,i=Math.max(1,Math.floor((r-o)/_r)),c=[],f=l?"#e0e0e6":"#1c1c22";e.font=dl,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,N=Math.min(h,g-x),L=Math.max(p,g+x),S=c.findIndex(E=>E+fl<=N);S===-1&&(S=Math.min(c.length,i-1)),c[S]=Math.max(c[S]??-1/0,L);let M=r-S*_r-Sn/2;e.beginPath(),e.moveTo(h,M+.5),e.lineTo(p,M+.5),e.stroke();for(let E of d.exons){let A=s(E.x0);e.fillRect(A,M-Sn/2,Math.max(1,s(E.x1)-A),Sn)}e.fillText(b,g,M-Sn/2-2)}}function hl(e,n){return Math.abs(n-e)<=.1*Math.max(e,n)}function ml(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 Br(e,n){return e.map((t,r)=>({item:t,i:r})).sort((t,r)=>n(t.item)-n(r.item))}var Pr=e=>e.spanningReads!==0;function Or(e,n){return{...n,agrees:e.complete&&Pr(n)?hl(e.bp,n.bp):void 0}}function bl(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,Or(l,c)))});let o=n.filter(l=>l.haplotype===void 0),s=Br(e,l=>l.bp),a=[[s.filter(l=>l.item.complete),o.filter(Pr)],[s,o]];for(let[l,i]of a){let c=l.filter(u=>!t.has(u.i)),f=Br(i.filter(u=>!r.has(u)),u=>u.bp);ml(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,Or(h.item,p))}})}return t}function yd(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 bl(s,a))t.set(s[l],i)}return e.map(o=>({...o,call:t.get(o)}))}var Gr=se(tn(),1),wd=(0,ae.createSvgIcon)((0,Gr.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,ma as b,je as c,Ve as d,_s as e,Ca as f,Un as g,ya as h,xa as i,Li as j,cr as k,Pi as l,ut as m,Ru as n,Au as o,Di as p,Ee as q,Iu as r,_u as s,vu as t,Bu as u,wl as v,Pt as w,vn as x,ln as y,Dt as z,El as A,Cl as B,Tl as C,Il as D,jt as E,hn as F,Ns as G,Kt as H,Wl as I,Hl as J,no as K,kn as L,ea as M,tc as N,oc as O,Hi as P,$u as Q,Xi as R,Fu as S,Wu as T,qu as U,Yu as V,zu as W,Vi as X,ju as Y,Ku as Z,Qu as _,Zu as $,Ju as aa,td as ba,tl as ca,od as da,cd as ea,ud as fa,ll as ga,Ar as ha,pd as ia,_r as ja,hd as ka,md as la,aa as ma,ia as na,ac as oa,ic as pa,lc as qa,po as ra,cc as sa,uc as ta,pl as ua,yd as va,hc as wa,mc as xa,da as ya,bc as za,gc as Aa,jn as Ba,Tc as Ca,Ic as Da,wd as Ea};
2
+ //# sourceMappingURL=chunk-3FGJLRG2.js.map