jbrowse-plugin-graphgenomeviewer 7.1.2 → 7.1.3

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 (41) hide show
  1. package/dist/chunks/{GraphGenomeView-NJ5XCREB.js → GraphGenomeView-LX7GDEDM.js} +2 -2
  2. package/dist/chunks/{LinearGraphDisplay-TXTKAACH.js → LinearGraphDisplay-QLPIRKPR.js} +2 -2
  3. package/dist/chunks/{WalkTabixSyntenyAdapter-U53JLYVU.js → WalkTabixSyntenyAdapter-GH6NYQTF.js} +2 -2
  4. package/dist/chunks/{WalkTabixSyntenyAdapter-U53JLYVU.js.map → WalkTabixSyntenyAdapter-GH6NYQTF.js.map} +1 -1
  5. package/dist/chunks/{chunk-NWJYLP6Z.js → chunk-6PC7WKLS.js} +2 -2
  6. package/dist/chunks/chunk-BHSELHTZ.js +2 -0
  7. package/dist/chunks/chunk-BHSELHTZ.js.map +7 -0
  8. package/dist/chunks/{chunk-WEGWTC52.js → chunk-LBY7U6OJ.js} +2 -2
  9. package/dist/chunks/{chunk-WEGWTC52.js.map → chunk-LBY7U6OJ.js.map} +4 -4
  10. package/dist/chunks/chunk-LVQUQSAH.js +3 -0
  11. package/dist/chunks/chunk-LVQUQSAH.js.map +7 -0
  12. package/dist/chunks/chunk-PJ43KEV6.js +2 -0
  13. package/dist/chunks/chunk-PJ43KEV6.js.map +7 -0
  14. package/dist/chunks/renderSvg-GGJXJHCS.js +2 -0
  15. package/dist/chunks/renderSvg-GGJXJHCS.js.map +7 -0
  16. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +3 -3
  17. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  18. package/package.json +1 -1
  19. package/src/GbzBaseSyntenyAdapter/configSchema.ts +2 -2
  20. package/src/GetSubgraph.ts +1 -1
  21. package/src/GraphGenomeView/components/Legend.tsx +3 -121
  22. package/src/GraphGenomeView/components/LegendSwatch.tsx +237 -0
  23. package/src/GraphGenomeView/components/PaneSvg.tsx +2 -189
  24. package/src/GraphGenomeView/components/WalkStrip.tsx +1 -1
  25. package/src/GraphTrack/index.ts +2 -2
  26. package/src/LinearGraphDisplay/denseWindow.ts +0 -14
  27. package/src/LinearGraphDisplay/model.ts +2 -1
  28. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts +1 -1
  29. package/src/nodeLimitError.ts +12 -0
  30. package/src/version.ts +1 -1
  31. package/dist/chunks/chunk-2MCOY3YG.js +0 -3
  32. package/dist/chunks/chunk-2MCOY3YG.js.map +0 -7
  33. package/dist/chunks/chunk-MURN3JPK.js +0 -2
  34. package/dist/chunks/chunk-MURN3JPK.js.map +0 -7
  35. package/dist/chunks/chunk-WCGVUZWP.js +0 -2
  36. package/dist/chunks/chunk-WCGVUZWP.js.map +0 -7
  37. package/dist/chunks/renderSvg-KSQI5DH6.js +0 -2
  38. package/dist/chunks/renderSvg-KSQI5DH6.js.map +0 -7
  39. /package/dist/chunks/{GraphGenomeView-NJ5XCREB.js.map → GraphGenomeView-LX7GDEDM.js.map} +0 -0
  40. /package/dist/chunks/{LinearGraphDisplay-TXTKAACH.js.map → LinearGraphDisplay-QLPIRKPR.js.map} +0 -0
  41. /package/dist/chunks/{chunk-NWJYLP6Z.js.map → chunk-6PC7WKLS.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- import{a as gt,d as L,e as Re,g as I,h as Et,i as ne,j as oe,k as re,m as _e,n as Te}from"./chunk-FITPB5X6.js";import{D as Ee,E as G,F as T,G as ve,H as Se,I as te,a as Z,d as U,j as xt,k as j,l as bt,n as yt,o as we,q as wt,s as Mt,v as Me,w as ee}from"./chunk-WAMBI7OX.js";import{e as vt}from"./chunk-W6EQLQ6H.js";import{c as mt}from"./chunk-N6PQZSAX.js";import{a as ye,b as ht,c as Q}from"./chunk-TUKJRVBS.js";var se=8,Oe=34,ie=12,po=60;function ho({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function a(i){let l=Math.ceil(e/i),d=Math.floor((o-(i-1)*se)/i),u=(r-l*Oe-(l-1)*se)/l,f=(d-2*ie)/t.w,p=t.h>0?(u-2*ie)/t.h:1/0,h=n?f:Math.min(f,p),m=n?t.h:t.h*h,g=Math.floor(Math.max(po,Math.min(m+2*ie,u)));return{columns:i,width:d,height:g,scale:h,total:l*(g+Oe)+(l-1)*se}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let c=a(1);for(let i=2;i<=e;i++){let l=a(i);l.scale>c.scale&&(c=l)}return c}var mo=[{value:"",label:"None",description:"Every lifted walk in one drawing"},{value:"walk",label:"A panel per walk",description:"One panel per lifted walk, side by side"},{value:"sample",label:"A row per sample",description:"A row per sample, a column per haplotype"}];function go(e){let t=typeof e=="string"?{field:e}:e??{};return{field:t.field==="walk"||t.field==="sample"?t.field:"",domain:[...t.domain??[]],...t.columns===void 0?{}:{columns:t.columns}}}function St(e,t){let n=new Map(t.map((r,s)=>[r,s])),o=r=>n.get(r)??t.length;return e.map((r,s)=>({name:r,i:s})).sort((r,s)=>o(r.name)-o(s.name)||r.i-s.i).map(({name:r})=>r)}function xo(e,t,n=[]){let o=St(e,n),r={columns:void 0,count:e.length,cells:e.map(l=>o.indexOf(l))};if(t==="walk")return r;let s=e.map(l=>{let[d,u,f]=l.split("#"),p=Number(u);return f!==void 0&&Number.isInteger(p)&&p>=0?{sample:d,column:Math.max(0,p-1)}:void 0}),a=St([...new Set(s.flatMap(l=>l?[l.sample]:[]))],n),c=Math.max(1,...s.map(l=>l?l.column+1:1)),i=s.map(l=>l?a.indexOf(l.sample)*c+l.column:-1);return i.includes(-1)||new Set(i).size<i.length?r:{columns:c,count:a.length*c,cells:i}}function Ae({graph:e,layout:t}){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach((r,s)=>{let a=n.get(r.name);if(r.order>=0&&a&&Q(a)){let{refName:c,start:i}=a.stable;(o.get(c)??o.set(c,[]).get(c)).push({name:r.name,index:s,bp0:i,bp1:i+a.length,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,a)=>s.bp0-a.bp0);return o}function ae(e,t,n=!1){let o=0,r=e.length-1;for(;o<r;){let c=o+r>>1,i=e[c].bp1;(n?i<t:i<=t)?o=c+1:r=c}let s=e[o];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function ce(e,t,n){let o=ae(e,t),r=ae(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function bo(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Rt=5,yo=10,wo=110,Mo=3;function _t(e){return e?"#b0b0b8":"#55555c"}function Eo(e){let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<=1?1:n<=2?2:n<=5?5:10)*t}function Tt(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+yo)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function vo(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let a=t(r.x0),c=t(s.x1),i=s.bp1-r.bp0;if(c<=a||i<=0)return;let l=Eo(i/(c-a)*wo),d=[],u=[];for(let f=Math.ceil(r.bp0/l)*l;f<=s.bp1;f+=l){let p=Math.round(t(ae(e,f)))+.5;if(p>=0&&p<=n){d.push(p);let h=f.toLocaleString("en-US");u.push({text:h,at:p,width:o(h)})}}return{spans:[{x0:a,x1:c}],ticks:d,labels:Tt(u)}}function So(e,t,n,o){let r=e.map(h=>({box:h,s0:t(h.x0),s1:t(h.x1)})).filter(({s0:h,s1:m})=>m>=0&&h<=n),s=r[0],a=r.at(-1);if(!s||!a)return;let c=(h,m)=>({text:h,at:m,width:o(h)}),i=(h,m)=>c(h.toLocaleString("en-US"),m),l=[],d=[],u=[],f=[];for(let{box:h,s0:m,s1:g}of r){l.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=Mo&&d.push(Math.round(g)+.5);let x=c(T(h.bp1-h.bp0),(m+g)/2);x.width<=g-m&&u.push(x),h!==s.box&&f.push(i(h.bp0,m))}let p=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:l,ticks:d,labels:Tt([...p,...u,...f])}}function Ot(e,t,n,o,r=!1){return(r?vo:So)(e,t,n,o)}function Ro(e,t,n,o,r=!1){let{x:s,width:a,darkMode:c}=n;e.font="10px sans-serif";let i=Ot(t,s,a,u=>e.measureText(u).width,r);if(!i)return;let l=_t(c),d=o+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:f}of i.spans)e.moveTo(Math.max(0,u),d),e.lineTo(Math.min(a,f),d);for(let u of i.ticks)e.moveTo(u,o),e.lineTo(u,o+Rt);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,o+Rt+2)}var O=e=>+e.toFixed(1);function _o(e){let t=/^rgba?\(([^,]+),([^,]+),([^,)]+)(?:,([^)]+))?\)$/.exec(e.replaceAll(" ",""));if(!t)return{color:e,opacity:1};let n=t[4]===void 0?1:Number(t[4]);return{color:`rgb(${t[1]},${t[2]},${t[3]})`,opacity:n}}function ke(e,t){let{color:n,opacity:o}=_o(t);return`${e}="${n}"${o<1?` ${e}-opacity="${O(o)}"`:""}`}var At=.5,kt=.25;function Ji(e,t){let n=[],o=[],r=(l,d)=>{let u={d:`M${O(l)} ${O(d)}`,segments:0,x0:l,x1:l,y0:d,y1:d};return o.push(u),u},s=l=>{let d=o.at(-1)??r(l[0],l[1]);for(let u=0;u<l.length;u+=2)d.x0=Math.min(d.x0,l[u]),d.x1=Math.max(d.x1,l[u]),d.y0=Math.min(d.y0,l[u+1]),d.y1=Math.max(d.y1,l[u+1]);return d.segments++,d},a=l=>{let d=new Set;return o.map(u=>{if(!l||u.x1-u.x0>=At||u.y1-u.y0>=At)return u.d;let f=(u.x0+u.x1)/2,p=(u.y0+u.y1)/2,h=`${Math.round(f/kt)} ${Math.round(p/kt)}`;return u.segments===0||d.has(h)?"":(d.add(h),`M${O(f)} ${O(p)}h0`)}).join("")},c={canvas:void 0,fillStyle:"#000",strokeStyle:"#000",lineWidth:1,lineCap:"butt",lineJoin:"miter",beginPath(){o=[]},moveTo(l,d){r(l,d)},lineTo(l,d){s([l,d]).d+=`L${O(l)} ${O(d)}`},bezierCurveTo(l,d,u,f,p,h){s([l,d,u,f,p,h]).d+=`C${O(l)} ${O(d)} ${O(u)} ${O(f)} ${O(p)} ${O(h)}`},closePath(){let l=o.at(-1);l&&(l.d+="Z")},stroke(){let l=a(c.lineCap!=="butt");l&&n.push(`<path d="${l}" fill="none" ${ke("stroke",c.strokeStyle)} stroke-width="${O(c.lineWidth)}" stroke-linecap="${c.lineCap}" stroke-linejoin="${c.lineJoin}"/>`)},fill(){let l=a(!1);l&&n.push(`<path d="${l}" ${ke("fill",c.fillStyle)}/>`)},clearRect(){n.length=0},fillRect(l,d,u,f){n.push(`<rect x="${O(l)}" y="${O(d)}" width="${O(u)}" height="${O(f)}" ${ke("fill",c.fillStyle)}/>`)}},i={width:e,height:t,style:{},getContext:()=>c};return c.canvas=i,{canvas:i,markup:()=>n.join("")}}var Nt=2,Ct=8192;function le(e=0,t=0){let n=typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,Nt);return Math.min(n,Ct/Math.max(e,t,1))}function Ne(e,t,n){let o=le(t,n),r=Math.round(t*o),s=Math.round(n*o);(e.width!==r||e.height!==s)&&(e.width=r,e.height=s);let a=`${t}px`,c=`${n}px`;return e.style.width!==a&&(e.style.width=a),e.style.height!==c&&(e.style.height=c),o}var na=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1,this.fit=1;let t=e.getContext("2d");if(!t)throw new Error("Canvas 2D context not available");this.canvas=e,this.ctx=t}setErrorHandler(e){}releaseOffscreenTargets(){}resize(e,t){this.fit=Ne(this.canvas,e,t)/le()}uploadGeometry(e){this.batch=e,this.highlightedEdge=null}setNodeHighlights(e){this.nodeHighlights=e}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t}updateTransform(e){let t=this.fit;this.transform=t===1?e:{...e,scaleX:e.scaleX*t,scaleY:e.scaleY*t,translateX:e.translateX*t,translateY:e.translateY*t,dpr:e.dpr*t}}render(e){if(!this.transform)return;let n=this.ctx,{width:o,height:r}=n.canvas;e[3]<1&&n.clearRect(0,0,o,r),n.fillStyle=Re([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,o,r);let s=this.batch;if(!s)return;n.lineCap="round",n.lineJoin="round";let a=this.highlightFactor,c=this.edgeRun(s.edgeCurveRuns);for(let{color:d,items:u}of Y(s.edgeCurves,(f,p)=>({color:fe(c,p)?I(f.color,a):f.color,weight:f.thickness,last:fe(c,p)})))this.strokeCurves(u,d);let i=this.liftedStrokes(s);for(let{color:d,items:u}of Y(s.nodeStrokes,(f,p)=>{let h=i.get(p);return{color:h===void 0?f.color:I(f.color,h),weight:f.thickness,last:h!==void 0}}))this.strokeNodes(u,d);let l=this.edgeRun(s.arrowRuns);for(let{color:d,items:u}of Y(s.arrows,(f,p)=>({color:fe(l,p)?I(f.color,a):f.color,weight:0,last:fe(l,p)})))this.fillArrows(u,d)}renderHighlights(){let e=this.ctx;e.clearRect(0,0,e.canvas.width,e.canvas.height);let t=this.batch;if(!this.transform||!t)return;e.lineCap="round",e.lineJoin="round";let n=this.highlightFactor,o=$t(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:c}of Y(o,i=>({color:I(i.color,n),weight:i.thickness,last:!1})))this.strokeCurves(c,a);let r=[...this.liftedStrokes(t)];for(let{color:a,items:c}of Y(r,([i,l])=>({color:I(t.nodeStrokes[i].color,l),weight:t.nodeStrokes[i].thickness,last:!1})))this.strokeNodes(c.map(([i])=>t.nodeStrokes[i]),a);let s=$t(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:c}of Y(s,i=>({color:I(i.color,n),weight:0,last:!1})))this.fillArrows(c,a)}edgeRun(e){return this.highlightedEdge===null?void 0:e.get(this.highlightedEdge)}liftedStrokes(e){let t=new Map;for(let[n,o]of this.nodeHighlights){let r=e.nodeStrokeRuns.get(n);if(r)for(let s=r.start;s<r.start+r.count;s++)t.set(s,o)}return t}strokeCurves(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.curves[0];o.moveTo(s.x0*n.scaleX+n.translateX,s.y0*n.scaleY+n.translateY);for(let a of r.curves)o.bezierCurveTo(a.cx0*n.scaleX+n.translateX,a.cy0*n.scaleY+n.translateY,a.cx1*n.scaleX+n.translateX,a.cy1*n.scaleY+n.translateY,a.x1*n.scaleX+n.translateX,a.y1*n.scaleY+n.translateY)}o.stroke()}strokeNodes(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.points[0];o.moveTo(s.x*n.scaleX+n.translateX,s.y*n.scaleY+n.translateY);for(let a=1,c=r.points.length;a<c;a++){let i=r.points[a];o.lineTo(i.x*n.scaleX+n.translateX,i.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t){let n=this.transform,o=this.ctx;o.fillStyle=L(t),o.beginPath();for(let r of e){let[s,a,c,i]=Oo(r,n);o.moveTo(s.x,s.y),o.lineTo(a.x,a.y),o.lineTo(c.x,c.y),o.lineTo(i.x,i.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},To=.25;function Oo(e,t){let n=Math.cos(e.angle),o=Math.sin(e.angle),r=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,c=e.halfWidth*t.dpr,i=r-n*a,l=s-o*a,d=a*(1-To);return[{x:r,y:s},{x:i-o*c,y:l+n*c},{x:r-n*d,y:s-o*d},{x:i+o*c,y:l-n*c}]}function $t(e,t){return t?e.slice(t.start,t.start+t.count):[]}function fe(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function Y(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let a=e[r],{color:c,weight:i,last:l}=t(a,r),d=l?o:n,u=`${c}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:c,items:[a]})}return[...n.values(),...o.values()]}var Ao=50;function Pt(e,t){return t>0?Math.max(1,e/t):Ao}function ko(e){let t=new Set,n=1/0,o=-1/0;for(let r of e)t.add(r.minY),n=Math.min(n,r.minY),o=Math.max(o,r.minY);return t.size>1?(o-n)/(t.size-1):void 0}function No(e,t,n){let o=Pt(t,e.length);return{x:o,y:n>0?Pt(n,e.length):ko(e)??o}}function Lt(e,t,n,o){return e===void 0?No(t,n,o):typeof e=="number"?{x:e,y:e}:e}function Co(e,t,n){let o=e.get(t);o||(o=new Map,e.set(t,o));let r=o.get(n);return r||(r=[],o.set(n,r)),r}function It(e,t,n,o,r,s,a){let c=Math.floor(n/t.x),i=Math.floor(r/t.x),l=Math.floor(o/t.y),d=Math.floor(s/t.y);for(let u=c;u<=i;u++)for(let f=l;f<=d;f++)Co(e,u,f).push(a)}function Bt(e,t,n,o,r,s){let a=Math.floor((n-r)/t.x),c=Math.floor((n+r)/t.x),i=Math.floor((o-s)/t.y),l=Math.floor((o+s)/t.y),d=[],u=new Set;for(let f=a;f<=c;f++){let p=e.get(f);if(p)for(let h=i;h<=l;h++){let m=p.get(h);if(m)for(let g of m)u.has(g)||(u.add(g),d.push(g))}}return d}var Xt=class{constructor(e,t){this.cells=new Map;let n=[],o=0,r=0;for(let[s,a]of Object.entries(e))for(let c=0;c<a.length-1;c++){let i=a[c],l=a[c+1],d=Math.min(i.x,l.x),u=Math.min(i.y,l.y),f=Math.max(i.x,l.x),p=Math.max(i.y,l.y);o+=f-d,r+=p-u,n.push({entry:{nodeId:s,segmentIdx:c},minX:d,minY:u,maxX:f,maxY:p})}this.cellSize=Lt(t,n,o,r);for(let s of n)It(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return Bt(this.cells,this.cellSize,e,t,n,o)}},Dt=class{constructor(e,t,n,o,r,s,a=0,c,i=!1){this.cells=new Map,this.edgeCurves=Et(e,t,o,s,a,c,i);let l=[],d=0,u=0;for(let f=0;f<t.edges.length;f++){let p=t.edges[f],h=e[p.from],m=e[p.to],g=this.edgeCurves.get(f);if(h?.length&&m?.length&&g){let{minX:x,minY:y,maxX:M,maxY:w}=wt(g),v=p.pathIds?.length??0;if(n&&v>0){let E=0,b=0;for(let S of ee(h,m,v,o))E=Math.max(E,Math.abs(S.x)),b=Math.max(b,Math.abs(S.y));x-=E,y-=b,M+=E,w+=b}d+=M-x,u+=w-y,l.push({ei:f,minX:x,minY:y,maxX:M,maxY:w})}}this.cellSize=Lt(r,l,d,u);for(let f of l)It(this.cells,this.cellSize,f.minX,f.minY,f.maxX,f.maxY,f.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,o=n){return Bt(this.cells,this.cellSize,e,t,n,o)}};function Yt(e,t,n,o,r,s){let a=r-n,c=s-o,i=a*a+c*c;if(i===0)return Math.hypot(e-n,t-o);let l=Math.max(0,Math.min(1,((e-n)*a+(t-o)*c)/i));return Math.hypot(e-(n+l*a),t-(o+l*c))}function $o(e,t,n,o,r,s,a,c,i,l){let d=1/0,u=20,f=n,p=o;for(let h=1;h<=u;h++){let m=h/u,g=1-m,x=g*g*g*n+3*g*g*m*r+3*g*m*m*a+m*m*m*i,y=g*g*g*o+3*g*g*m*s+3*g*m*m*c+m*m*m*l;d=Math.min(d,Yt(e,t,f,p,x,y)),f=x,p=y}return d}function Po(e,t,n){return $o(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function qt(e,t,n,o=1){let r=1/0;for(let s of n){let a=Po(e,t,o===1?s:{x0:s.x0,y0:s.y0*o,cx0:s.cx0,cy0:s.cy0*o,cx1:s.cx1,cy1:s.cy1*o,x1:s.x1,y1:s.y1*o});a<r&&(r=a)}return r}var Ft=new WeakMap;function Wt(e,t){let n=Ft.get(e);if(n?.version===t)return n.index;let o=new Xt(e);return Ft.set(e,{version:t,index:o}),o}var Gt=new WeakMap;function Lo(e,t,n,o,r,s,a,c=!1){let i=Gt.get(e);if(i?.graph===t&&i.drawPaths===n&&i.scaleX===o.scaleX&&i.scaleY===o.scaleY&&i.version===r&&i.deletions===s&&i.routes===a&&i.stranded===c)return i.index;let l=new Dt(e,t,n,o,void 0,s,r,a,c);return Gt.set(e,{graph:t,drawPaths:n,scaleX:o.scaleX,scaleY:o.scaleY,version:r,index:l,deletions:s,routes:a,stranded:c}),l}var Io=5;function ua(e,t,n,o,r=0,s){let a=Me(o),c=Wt(e,r),i=p=>Math.max(Io,p)/o.scaleX,l=i(s?.maxHalfWidthPx??0),d=c.query(t,n,l,l/a),u=null,f=1/0;for(let{nodeId:p,segmentIdx:h}of d){let m=e[p],g=Yt(t,n*a,m[h].x,m[h].y*a,m[h+1].x,m[h+1].y*a);g<f&&g<i(s?.halfWidthPx(p)??0)&&(f=g,u=p)}return u}function Bo(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,a=1;for(let[c,i]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(c===0){if(i<0)return!1}else c<0?s=Math.max(s,i/c):a=Math.min(a,i/c);return s<=a}function Ht(e,t,n=0){let o=Wt(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let a=new Set,c=o.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:i,segmentIdx:l}of c){let d=e[i];!a.has(i)&&Bo(r(d[l]),r(d[l+1]),s)&&a.add(i)}return a}}function pa(e,t,n,o,r,s,a=0,c,i,l,d=!1){let u=Me(r),f=10/r.scaleX,p=Lo(e,t,s,r,a,c,l,d),h=p.query(n,o,f,f/u),m=null,g=f;for(let x of h){let y=t.edges[x],M=e[y.from],w=e[y.to];if(!M?.length||!w?.length||i?.has(x))continue;let v=y.pathIds?.length??0,E=p.getCurves(x);if(!E)continue;let b;if(!s||v===0)b=qt(n,o*u,E,u);else{let S=1/0;for(let _ of ee(M,w,v,r)){let F=_.x===0&&_.y===0?E:Mt(E,_.x,_.y),P=qt(n,o*u,F,u);P<S&&(S=P)}b=S}b<g&&(g=b,m=x)}return m}var Ut=3.4,Ce=6,Xo=18,Do=2,qo=3,Fo=xt+bt;function jt(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],r=s=>+(s/n).toFixed(n===1?0:1);return`${r(e.covered*t)} of ${r(t)} ${o}`}function Kt(e,t,n,o){let r=n/2;return zt(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:a,y:c}=t(s.at),i=jt(s);return{item:s,x:a,y:c+n+Xo,text:i?`${s.gene.name} \xB7 ${i}`:s.gene.name,fallback:i?`${s.gene.name} \u2026`:void 0,stack:Do,fits:l=>[...o({x0:l.x0-r,x1:l.x1+r,y0:l.y0-r,y1:l.y1+r})].every(d=>s.nodeIds.has(d))}})}function zt(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Go(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:a}=e.axisScale,c={width:t,height:n},i=b=>({x:b.x*s+o,y:b.y*a+r}),l=e.drawnRowLabels.map(({label:b,y:S})=>Ee(b,S*a+r)),d=e.referenceStripZonePx??0;d>0&&l.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&l.push({x0:t-Ce-e.legendSize.width,x1:t,y0:0,y1:d+Ce+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*j*1.2,y0:0,y1:44});let u=yt(c,l),f=e.drawnRowLabels.length>0,p=f?Math.min(...e.drawnRowLabels.map(b=>b.y)):1/0,h=e.contigThickness*Ut,m=(b,S)=>{let{x:_,y:F}=i({x:b.labelAt.x,y:Math.min(b.labelAt.y,p)}),P=F-h/2-S;return{x:_,y:f?Math.max(P,Fo):P}},g=zt(e.bubbleHalos.filter(b=>!b.tick),b=>b.whole?-1:b.members),x=we(g.map(b=>({item:b,...m(b,6),text:b.label,fallback:b.label.includes(",")?b.label.split(",")[0]:void 0,stack:qo})),c,u),y=e.bubbleHalos.filter(b=>b.tick&&!b.whole).map(b=>({item:b,...m(b,2)})).filter(b=>b.x>=0&&b.x<=t&&b.y>=0&&b.y<=n),M=we(Kt(e.genePins,i,e.contigThickness,Ht(e.nodePositions??{},{scaleX:s,scaleY:a,translateX:o,translateY:r},e.positionsVersion)),c,u),w=e.nodePositions&&e.labelsNodeSizes?ve({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:o,translateY:r,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},v=te(w.deletions,u),E=te(w.nodes,u,Se(t,n));return{bubbles:x,ticks:y,genes:M,sizes:[...v,...E]}}var X=JBrowseExports.mobx,de=e=>X!=null&&e in Object(X)?X[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from 'mobx' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var Na=de("autorun");var Ca=de("computed");var $a=de("reaction");var Pa=de("untracked");var La=X&&X.__esModule?X.default:X;function Yo(e){return e.id.endsWith("-")?"-":"+"}function Wo(e,t){return t===Yo(e)?e.id:`-${e.id}`}function Ho(e,t){let n=e.map(()=>{}),o=0,r=0;for(;r<e.length&&e[r]!==void 0;r++)n[r]=o,o+=e[r];let s=t;for(let a=e.length-1;a>r&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Uo(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=Ho(t,e.pathLength),r=o.flatMap((f,p)=>f===void 0?[]:[p]),s=f=>o[r[f]],a=f=>s(f)+t[r[f]],c=0,i=(f,p=!1)=>{for(;c<r.length&&a(c)<f;)c++;for(let h=c;h<r.length&&s(h)<=f;h++){let m=a(h);if(f<m||p&&f===m)return{s:r[h],local:f-s(h),room:m-f}}},l=f=>{for(let p=c;p<r.length;p++)if(s(p)>f)return s(p)-f;return 1/0},d=(f,p)=>{let h=n[f],m=h.at(-1);p.type==="substitution"&&m?.type==="substitution"&&m.pos+m.seq.length===p.pos?m.seq+=p.seq:h.push(p)},u=e.pathStart;for(let f of mt(e.cs))if(f.op==="match")u+=f.length;else if(f.op==="substitution"){let p=i(u);p&&d(p.s,{type:"substitution",pos:p.local,seq:f.seq}),u+=1}else if(f.op==="insertion"){let p=i(u,u===e.pathEnd);p&&d(p.s,{type:"insertion",pos:p.local,seq:f.seq})}else{let p=f.length;for(;p>0;){let h=i(u),m=Math.min(p,h?h.room:l(u));h&&d(h.s,{type:"deletion",pos:h.local,length:m}),u+=m,p-=m}}return n}function Xa(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let a=s.path.map(d=>o.get(d.name)),c=a.flatMap((d,u)=>d?[u]:[]),i=c[0],l=c.at(-1);if(i!==void 0&&l!==void 0){let d=Uo(s,a.map(p=>p?.length)),u=c.map(p=>Wo(a[p],s.path[p].strand)),f=a[l].length;r.push({id:n+r.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:c.map((p,h)=>({nodeName:u[h],mismatches:d[p]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:l===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?void 0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return r}var jo=["#6baed6","#4292c6","#2171b5","#08519c"],Ko=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Vt(e){let t=e.is_reverse?Ko:jo;return t[e.id%t.length]}function ue(e){return`hsl(${e}, 70%, 50%)`}function $e(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*oe}var zo=30;function Jt({start:e,bp:t,reversed:n},o){let r=$e(e,o),s=$e(e+t,o);if(s-r<1)return[(r+s)/2];let a=Math.ceil((s-r)/zo);return Array.from({length:a+1},(c,i)=>$e(e+t*(n?a-i:i)/a,o))}var Pe=Array.from({length:7},(e,t)=>({offset:t/6,color:ue(t/6*oe)})),Qt=`linear-gradient(to right, ${Pe.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function R(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function Zt(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function Vo(e){return Zt(e).replaceAll('"',"&quot;")}function Jo(e){if(typeof e=="string")return Zt(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${Vo(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(Jo).join("")}</${e.tag}>`}var De="#2f8fd6",qe="#8e3fbf",Fe="#bdbdbd",K="#1c1c22",Ge=12,Ye=4,Be=12,Qo=6,Zo=3;function B(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function er(e){let t=Math.abs(e);return`${e>0?"+":"\u2212"}${t<1e3?`${t} bp`:B(t)}`}function Le(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function en(e,t,n,o){let{bp:r,gapBp:s,complete:a,stop:c}=e;if(!t)return`${B(r)}${Le(r,n)}`;let i=s>0?` \xB7 ${B(s)} outside the cut`:"",l=o?` \xB7 called ${B(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(a){let f=r-t.bp,p=f===0?"":` (${er(f)})`;return`${B(r)}${Le(r,n)}${p}${i}${l}`}let d=n?"repeat":"window";if(c?.contigEnds&&r===0)return`contig ends ${c.shortBp>0?`${B(c.shortBp)} before`:"at"} the ${d}${l}`;let u=c?c.contigEnds?`contig ends inside the ${d}`:"does not rejoin the reference within the cut":"partial walk";return`\u2265 ${B(r)}${Le(r,n)} \xB7 ${u}${i}${l}`}function tn(e,t,n){let o=t+6;return o+e.length*j<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function nn(e,t,n){if(t*n<Zo)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function on(e,t){if(e.gap)return{fill:Fe};if(!t)return{fill:e.onReference?De:qe};if(e.referenceStart===void 0)return{fill:re};let n=Jt({...e,start:e.referenceStart},t);return n.length===1?{fill:ue(n[0])}:{stops:n.map(ue)}}function Xe(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function tr(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function nr(e,t){let n=new Map;for(let o of e){let r=t.get(o.name);if(!o.axis||!r)continue;let s=o.axis,a=({start:c,end:i})=>({start:Math.max(0,c),end:Math.min(o.bp,i)});n.set(o.name,r.map(c=>({name:c.name,...a(Xe(s,c.start,c.end)),exons:c.exons.map(i=>a(Xe(s,i.start,i.end))).filter(i=>i.end>i.start)})).filter(c=>c.end>c.start).sort((c,i)=>c.start-i.start))}return n}var or=9,rr=5.2,sr=8,rn=(e,t)=>Math.min(2,(e-t)/2-1);function sn(e,t){return rn(e,t)>=1}function an(e,t,n,{rowPx:o=Z,barPx:r=Ge}={}){if(!sn(o,r))return[];let s=rn(o,r),a=e.map(l=>{let d=t(l.start);return{g:l,x:d,w:Math.max(2,t(l.end)-d)}}),c=[],i=new Set((r>=sr?[...a]:[]).sort((l,d)=>l.w-d.w).filter(({g:l,x:d,w:u})=>{let f=l.name.length*rr/2,p=[d+u/2-f,d+u/2+f];return 2*f>u+6||c.some(([h,m])=>p[0]<m+2&&p[1]>h-2)?!1:(c.push(p),!0)}));return a.map(l=>({name:l.g.name,x:l.x,y:n-r/2-s,w:l.w,h:r+2*s,exons:l.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:i.has(l)?{x:l.x+l.w/2,y:n+3,size:or}:void 0}))}var Ie=e=>`${e} row${e===1?"":"s"}`;function ir(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??Qt,ramp:!0}:{kind:"bar",fill:De},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?re:qe},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(o=>o.gapBp>0)&&n.push({swatch:{kind:"gap",fill:Fe},label:"walked outside the cut"}),t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):t.genes&&(n.push({swatch:{kind:"gene"},label:"gene"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${Ie(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${Ie(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${Ie(t.genes.unread)}`,note:!0})),n}var cn="#111",ln="#9e9e9e",We="#c62828";function fn(e){return e.agrees===!1?We:e.spanningReads===0?ln:cn}function ar(e,t,n,o="walk-key"){let r=0,s=e.flatMap((a,c)=>{let i=`${o}-ramp-${c}`,l=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?R("linearGradient",{id:i},...Pe.map(f=>R("stop",{offset:f.offset,"stop-color":f.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?R("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:K,"stroke-width":1.5}):R("rect",{x:r,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Ye:8,rx:2,fill:l?`url(#${i})`:a.swatch.fill}),u=R("text",{x:a.note?r:r+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return r+=(a.note?0:23)+a.label.length*j+16,[l,d,u].filter(f=>f!==void 0)});return{width:r,tree:R("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function cr(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(Z,o>=1?Math.floor(o):o));return{rowPx:r,barPx:r<=3?r:Math.max(3,Math.round(r*.6)),labelled:r>=Be,readouts:r>=Be}}function dn(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let c=0,i=0;for(let u of r)u.onReference?c+=u.bp:i+=u.bp;let l=c>=i,d=r.find(u=>u.onReference===l);o.push({start:r[0].start,bp:c+i,onReference:l,referenceStart:l?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}r=[]}},a=0;for(let c of e){if(c.gap||c.bp>=n){s(),a=0,o.push(c);continue}r.push(c),a+=c.bp,a>=n&&(s(),a=0)}return s(),o}function lr(e,t,n){return R("g",{class:"row-gene","data-testid":"graph-walk-gene"},R("title",{},e.name),...e.exons.map(o=>R("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:K,opacity:.35})),R("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:K,"stroke-width":1.5}),e.label&&R("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:K,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function z(e,t,n={}){let o=m=>m*t.scaleX+t.translateX,r=t.rowPx??Z,s=t.barPx??Ge,a=Math.min(3,Math.max(0,(r-s)/2)),c=m=>m*r*t.scaleY+t.translateY,{origin:i,unit:l,reference:d,rows:u}=e,f=m=>o(i+m),p=n.idPrefix??"walkrow",h=(m,g)=>{let x=c(g);if(x<-s||x>t.height+s)return;let y=dn(m.runs,t.scaleX).flatMap(S=>{let _=on(S,n.ramp),F=S.gap?Math.min(Ye,s):s,P=`${p}-${g}-${S.start}`,pt=R("rect",{x:f(S.start),y:x-F/2,width:Math.max(1,S.bp*t.scaleX),height:F,fill:"stops"in _?`url(#${P})`:_.fill});return"stops"in _?[R("linearGradient",{id:P},..._.stops.map((fo,uo)=>R("stop",{offset:uo/(_.stops.length-1),"stop-color":fo}))),pt]:[pt]}),M=l&&s>=Qo?nn(m.bp,l,t.scaleX).map(S=>R("line",{x1:f(S),x2:f(S),y1:x-s/2,y2:x+s/2,stroke:"white","stroke-width":1})):[],{call:w}=m,v=en(m,g===0?void 0:d,l,w),E=tn(v,f(m.bp),t.width),b=t.readouts??!0;return R("g",{"data-testid":g===0?"graph-walk-reference":"graph-walk-row"},...y,...M,...an(n.rowGenes?.get(m.name)??[],f,x,{rowPx:r,barPx:s}).map(S=>lr(S,x,s)),w&&R("rect",{"data-testid":"graph-walk-call",x:f(w.bp)-1,y:x-s/2-a,width:2,height:s+2*a,fill:fn(w)}),b&&R("text",{x:E.x,y:x+4,"font-family":"sans-serif","font-size":11,fill:w?.agrees===!1?We:"#333",stroke:E.halo?"white":void 0,"stroke-width":E.halo?3:void 0,"paint-order":"stroke","text-anchor":E.anchor},v))};return R("g",{},...[d,...u].map(h))}var fr=10;function dr(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=fr*(r.end-r.start)&&(n===0?r.start<=e.start&&e.start<=r.end:Math.min(e.end,r.end)-Math.max(e.start,r.start)>=n/2))}var ur=40;function pr(e,t){let n=T(e),o=T(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function He(e){return e>=vt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function hr(e,t=[]){let n=mr(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function mr(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:a,inversion:c}=e,i=pr(o,r);if(a>=ur)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${He(s)}${c?", inv":""}`};if(c)return{kind:"inversion",label:`${T(r)} inv`};if(e.offReference)return o===r?un(o):{kind:"complex",label:`${i}, ${He(s)}`};let l=r!==o?dr(e,t):void 0;if(l){let u=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${He(s)}`}}let d=s>2?`, ${s} alleles`:"";return o===r&&o===n?un(n):n===0||o===n?{kind:"insertion",label:`\u2264${T(r-n)} ins${d}`}:r===n?{kind:"deletion",label:`${T(n-o)} del${d}`}:{kind:"complex",label:`${T(n)} ref \u2192 ${i}, ${s} alleles`}}function un(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${T(e)} sub`}}var gr={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},xr={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function br(e){return e.segments.split(",").filter(Boolean)}function yr(e,t,n,o){let r=[];for(let s of e){let a=n(s.x0),c=n(s.x1);c>=0&&a<=o&&r.push({node:s.name,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:c})}return r}var wr=3;function Mr(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,a=wr;for(let c of e){let i=c.top0+(c.bottom0-c.top0)*r,l=c.top1+(c.bottom1-c.top1)*r,d=Math.max(0,Math.min(i,l)-n,n-Math.max(i,l));d<a&&(a=d,s=c.node)}return s}function pn(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.top1,0),e.lineTo(t.bottom1,n),e.lineTo(t.bottom0,n),e.closePath()}function hn(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function Er(e,t,n,{highlightNode:o,darkMode:r}){if(n<=0||t.length===0)return;let s=r?"255,255,255":"0,0,0";e.beginPath();for(let a of t)pn(e,a,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let a of t)hn(e,a,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke(),mn(e,t,n,o)}function mn(e,t,n,o){let r=n>0&&o?t.find(s=>s.node===o):void 0;r&&(e.beginPath(),pn(e,r,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),hn(e,r,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function vr(e,t,n){let o=0,r=e.length-1;for(;o<r;){let s=o+r+1>>1;e[s].bp0<=t?o=s:r=s-1}return[e[o],e[o-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function kc(e,t){let{layout:n}=e,o=[...Ae(e).values()].flat().sort((s,a)=>s.bp0-a.bp0),r=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let c=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!c.has(i.node)&&c.set(i.node,i.y);for(let i of a){let l=vr(o,i.start,c);if(l){let{bp0:d,bp1:u,x0:f,x1:p,index:h}=l,m=g=>f+(Math.min(g,u)-d)/(u-d)*(p-f);r.push({x0:m(i.start),x1:m(i.end),y:c.get(h),height:s.width})}}}}return r}function Sr(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Nc(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=Sr(s),e.beginPath();for(let a of t){let c=n(a.x0),i=Math.max(n(a.x1),c+1);if(i>=0&&c<=r){let l=o(a.y);e.rect(c,l,i-c,o(a.y+a.height)-l)}}e.fill()}}function gn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}var Rr=new Set(["_gbwt_ref","unknown"]);function xn(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||Rr.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var Nn=!1;function H(...e){Nn&&console.log(...e)}var _r=["read_group","sample_name"],Bc=[..._r,"haplotype_sample"];function Tr({layers:e,coarsenedReadView:t=!1,showReads:n=!0},o){if(e!==void 0)return e;let r=t&&n,s=a=>a?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(r&&!o)},{data:"reads",...s(r&&o)}]}function bn(e,t){return e.find(n=>n.data===t)?.stat}function Or(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:Tr(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,freqWidth:e.freqWidth??"log"}}function Cn(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:gn(),imageBounds:{minX:0,maxX:0,minY:0,maxY:0},trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function Xc(e,t,n=[],o={}){let r=Ar(e,t,n,o);return r&&kr(r,o)}var $n=new WeakMap;function Ar(e,t,n=[],o={}){let r=Cr(e,t,n,o);if(r===void 0)return;let s=Pn(r,r.tracks,r.reads,"measure");return s.nodes.forEach((a,c)=>{a.order>=0&&(r.nodes[c].x=a.x)}),$n.set(r,s),r}function kr(e,t={}){return Nr(e,Ir(e,t.facet),$r(e,t))}function Nr(e,t,n,o){let r=$n.get(e);return r!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?r:Pn(e,t,n,"topology",o)}function Cr(e,t,n,o){let r=Cn(Or(o,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,a)=>{s.seq??="",s.sequenceLength??=s.seq.length,r.nodes[a+1]=s}),r.tracks=structuredClone(t),r.reads=r.config.showReads?structuredClone(n.filter(s=>s.is_secondary!==!0)):[];for(let s=r.tracks.length-1;s>=0;s-=1){let a=r.tracks[s];if(a.type??="haplotype",a.hidden===!0){r.tracks.splice(s,1);continue}a.indexOfFirstBase!==void 0&&(r.trackForRuler=a.name)}if(r.tracks.length!==0)return Xr(r,0),r.nodeMap=En(r),W(r,r.tracks),W(r,r.reads),An(r),r.config.mergeNodes&&(vn(r),je(r),ze(r),Os(r),r.nodeMap=En(r),An(r),W(r,r.tracks),W(r,r.reads)),vn(r),is(r),je(r),as(r),je(r),ze(r),W(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:rs(r),trackForRuler:r.trackForRuler}}}function $r(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:o}){let r=n?new Set(n):null;return e.reads.filter(s=>(s.mapping_quality??0)>=t&&(r===null||s.name!==void 0&&r.has(s.name))&&(o===void 0||Pr(o,s)))}function Pr(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Lr(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Ir(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Lr(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Br(o)===t.key)}function Br(e){return xn(e.name)?.sample??null}function Pn(e,t,n,o,r={}){let s=Cn(e.options);e.nodes.forEach((f,p)=>{s.nodes[p]={...f}}),s.tracks=t.map(f=>({...f})),s.reads=n.map(f=>({...f})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:a,ignoreStrand:c}=s.config,i=r.haplotypes??Xn,l=bn(a,"haplotypes")==="coarsen"?vs(s,i):void 0;l!==void 0&&(s.tracks=[l.ref]),ys(s),us(s),Dr(s);let d=bn(a,"reads")==="coarsen"&&s.reads.length>0?Dn(s,s.reads,"read",r.reads??i+(l?.bands.length??0)):void 0;d!==void 0&&(s.reads=d.bands);let u={};for(let[f,p,h]of[["haplotypes","haplotype",l],["reads","read",d]])h!==void 0&&(ze(s,h.bands),W(s,h.bands),u[f]={unit:p,total:h.total,reverse:!c&&h.bands.some(m=>m.is_reverse)});return l!==void 0&&(s.reads=l.bands.concat(s.reads)),s.reads.length>0?(Fr(s),s.tracks=s.tracks.concat(s.reads)):s.nodes.forEach(f=>{f.incomingReads=[],f.outgoingReads=[],f.internalReads=[]}),o==="measure"&&ls(s),Es(s),H("Tracks:",s.tracks),H("Nodes:",s.nodes),H("Lane assignment:",s.assignments),Zr(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:s.imageBounds,maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:u}}function k(e){return e.startsWith("-")}function N(e){return k(e)?e.substring(1):e}function Ln(e){return k(e)?e:`-${e}`}function Ve(e){return k(e)?N(e):Ln(e)}function yn(e){return e>0}function Xr(e,t){let n=new Set,o=new Set;for(let r of e.tracks[t].sequence)k(r)?o.has(N(r))||n.add(N(r)):o.add(r);if(n.size!==0){for(let{sequence:r}of[...e.tracks,...e.reads])for(let s=0;s<r.length;s+=1)n.has(N(r[s]))&&(r[s]=Ve(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Je(r.seq))})}}function Dr(e){e.nodesPerOrder=[];for(let n=0;n<=e.maxOrder;n+=1)e.nodesPerOrder[n]=[];let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&wn(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(o=>{wn(t,o.order,(o.y??0)+n.width)})}),e.nodes.forEach((n,o)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(o))})}function wn(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var pe=7;function qr(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{if((t.width===void 0||t.width===0)&&(t.width=pe),t.path.length===1){let o=t.path[0].node;o!==null&&e.nodes[o].internalReads.push(n)}else t.path.forEach((o,r)=>{if(r===0){let s=t.path[0].node;s!==null&&e.nodes[s].outgoingReads.push([n,r])}else{let s=o.node;s!==null&&e.nodes[s].incomingReads.push([n,r])}})})}function Fr(e){e.reads.forEach(c=>{c.path=In(e,c)}),qr(e);let t=e.nodes.filter(c=>c.order>=0);t.sort(Ze);let n=new Map;for(let c=0;c<e.reads.length;c++){let i=e.reads[c],l=i.haplotypeShare===void 0?1:0,d=i.sourceTrackID,u=`${l}:${d}`,f=n.get(u);f===void 0?n.set(u,{layer:l,source:d,reads:new Set([c])}):f.reads.add(c)}let o=[...n.values()].sort((c,i)=>c.layer-i.layer||c.source-i.source),r=o.length>1?pe:0;t.forEach(c=>{for(let{reads:i}of o)Gr(e,i,c,r)});let s=Kr(e),a=[];e.reads.forEach((c,i)=>{let l=c.path.length,d=new Array(l),u;for(let h=0;h<l;h++){h===0?d[h]=void 0:d[h]=u??c.path[0];let m=c.path[h];m.node!==null&&m.node&&(u=m)}let f=new Array(l),p;for(let h=l-1;h>=0;h--){h===l-1?f[h]=void 0:f[h]=p??c.path[l-1];let m=c.path[h];m.node!==null&&m.node&&(p=m)}c.path.forEach((h,m)=>{if(h.y===void 0){let g=d[m],x=f[m],y=!!(x&&g&&(g.order>x.order||x.order===g.order&&x.isForward===g.isForward));h.betweenCycleReverseTraversal=y,a.push({readIndex:i,pathIndex:m,previousY:g?.y,previousNode:g?.node})}})}),a.sort((c,i)=>Wr(e,c,i)),a.forEach(c=>{let i=e.reads[c.readIndex],l=i.path[c.pathIndex];l.y=s[l.order],s[l.order]+=i.width}),H("Reads:",e.reads)}function Gr(e,t,n,o){let r=n.incomingReads.filter(([h])=>t.has(h)),s=n.outgoingReads.filter(([h])=>t.has(h)),a=n.internalReads.filter(h=>t.has(h));r.length===0&&s.length===0&&a.length===0&&(o=0);let c=n.y+n.contentHeight+o*2,i=r.map(h=>{let[m,g]=h,x=e.reads[m].path,y=g+1,M;for(let w=1;w<=g;w++){let v=x[g-w]?.y;if(v!==void 0){y=w,M=v;break}}return{entry:h,decisionStep:y,y:M}});i.sort(Yr),r=i.map(h=>h.entry);let l=c,d=new Map;r.forEach(h=>{let m=e.reads[h[0]];m.path[h[1]].y=l,Mn(d,m,h[1],l,n),l+=m.width});let u=l;s.sort((h,m)=>Hr(e,h,m));let f=new Map;l=c,s.forEach(h=>{let m=e.reads[h[0]],g=m.firstNodeOffset??0;m.path[h[1]].y=l,f.set(l,g);let x=d.get(l);x===void 0||x+1<=g?(l+=m.width,u=Math.max(u,l)):(d.set(l,0),r.forEach(y=>{let M=e.reads[y[0]],w=M.path[y[1]];w.y!==void 0&&w.y>=l&&(w.y+=m.width,Mn(d,M,y[1],w.y,n))}),l+=m.width,u+=m.width)}),a.sort((h,m)=>jr(e,h,m)),a.forEach(h=>{let m=e.reads[h],g=m.firstNodeOffset??0,x=m.finalNodeCoverLength??0;for(l=c;g<(d.get(l)??-1/0)+2||x>(f.get(l)??1/0)-3;)l+=m.width||pe;m.path[0].y=l,d.set(l,x),u=Math.max(u,l)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,xs(e,n,p)}function Yr(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function Mn(e,t,n,o,r){n===t.path.length-1?e.set(o,t.finalNodeCoverLength??0):e.set(o,r.sequenceLength)}function Wr(e,t,n){let o=e.reads[t.readIndex],r=e.reads[n.readIndex],s=o.path[t.pathIndex],a=r.path[n.pathIndex];if(s.order!==a.order)return s.order-a.order;if(o.sourceTrackID!==r.sourceTrackID)return o.sourceTrackID-r.sourceTrackID;if(t.previousNode&&n.previousNode){let u=e.nodes[t.previousNode],f=e.nodes[n.previousNode];if(u&&f&&u.order!==f.order)return u.order-f.order}let c=t.previousY??0,i=n.previousY??0,l=s.betweenCycleReverseTraversal===!0,d=a.betweenCycleReverseTraversal===!0;return l!==d?l?1:-1:l?i-c:c-i}function Hr(e,[t,n],[o,r]){let s=e.reads[t],a=e.reads[o],c,i,l=s.path.length-1,d=a.path.length-1;for(;c===void 0&&l>=0;)c=s.path[l]?.y,l-=1;for(;i===void 0&&d>=0;)i=a.path[d]?.y,d-=1;if(c!==void 0&&i!==void 0)return c-i;let u=s.path[n]?.node,f=a.path[r]?.node,p=typeof u=="number"?e.nodes[u]:null,h=typeof f=="number"?e.nodes[f]:null;for(;p&&h&&p===h;){if(n<s.path.length-1){for(n+=1;s.path[n]?.node===null;)n+=1;let g=s.path[n]?.node;p=typeof g=="number"?e.nodes[g]:null}else p=null;if(r<a.path.length-1){for(r+=1;a.path[r]?.node===null;)r+=1;let g=a.path[r]?.node;h=typeof g=="number"?e.nodes[g]:null}else h=null}if(p)return h?Ze(p,h):1;if(h)return-1;let m=(s.firstNodeOffset??0)-(a.firstNodeOffset??0);return m!==0?m:(s.finalNodeCoverLength??0)-(a.finalNodeCoverLength??0)}function Ur(e,t){let n=e.path,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let a=n[r],c=o[s],i=a.order,l=c.order;if(i===l&&a.node&&c.node)return(c.y??0)-(a.y??0);i<l?r+=1:(i>l||(r+=1),s+=1)}return 0}function jr(e,t,n){let o=e.reads[t],r=e.reads[n],s=o.firstNodeOffset??0,a=r.firstNodeOffset??0;if(s<a)return-1;if(s>a)return 1;let c=o.finalNodeCoverLength??0,i=r.finalNodeCoverLength??0;return c<i?-1:c>i?1:0}function Kr(e){let t=[];for(let n=0;n<=e.maxOrder;n+=1)t.push(0);return e.nodes.forEach(n=>{n.y!==void 0&&(t[n.order]=Math.max(t[n.order],n.y+n.contentHeight+20))}),e.tracks.forEach(n=>{n.path.forEach(o=>{t[o.order]=Math.max(t[o.order],(o.y??0)+n.width)})}),t}function In(e,t){let n=[],o=(i,l)=>{n.push({order:i,isForward:l,node:null})},r=(i,l,d)=>{n.push({order:i,isForward:l,node:d})},s=Math.abs(t.indexSequence[0]),a=yn(t.indexSequence[0]),c=e.nodes[s];r(c.order,a,s);for(let i=1;i<t.sequence.length;i+=1){let l=c,d=a;s=Math.abs(t.indexSequence[i]),a=yn(t.indexSequence[i]),c=e.nodes[s];let{order:u}=c;if(u>l.order){d||o(l.order,!0);for(let f=l.order+1;f<u;f+=1)o(f,!0);a||o(u,!0)}else if(u<l.order){d&&o(l.order,!1);for(let f=l.order-1;f>u;f-=1)o(f,!1);a&&o(u,!1)}else a===d&&o(u,!a);r(u,a,s)}return n}function ze(e,t=e.reads){t.forEach(n=>{let o=0;for(;o<n.sequence.length&&n.sequence[o].startsWith("-");)o+=1;if(o===n.sequence.length){n.is_reverse=!0,n.sequence=n.sequence.reverse();for(let i=0;i<n.sequence.length;i+=1)n.sequence[i]=N(n.sequence[i]);let r=n.sequenceNew??[];r.reverse(),n.sequenceNew=r;for(let i of r)i.nodeName=N(i.nodeName),zr(i.mismatches,Ue(e,i.nodeName).sequenceLength);let s=n.firstNodeOffset??0,a=Ue(e,n.sequence[0]).sequenceLength;n.firstNodeOffset=a-(n.finalNodeCoverLength??0);let c=Ue(e,n.sequence[n.sequence.length-1]).sequenceLength;n.finalNodeCoverLength=c-s}})}function zr(e,t){e.forEach(n=>{Object.assign(n,Vr(n,t))})}function Vr(e,t){let n=e.type==="insertion"?0:e.type==="deletion"?e.length??0:e.seq?.length??0;return{...e,pos:t-e.pos-n,...e.seq!==void 0&&{seq:Je(e.seq)}}}var Jr={A:"T",T:"A",C:"G",G:"C"};function Je(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Jr[e.charAt(n)]??"N";return t}function W(e,t){let n=new Map;t.forEach(o=>{o.indexSequence=o.sequence.map(r=>{let s=n.get(r);if(s===void 0){let a=e.nodeMap.get(N(r));if(a===void 0)throw new Error(`Track ${o.name??o.id} visits unknown node ${r}`);s=k(r)?-a:a,n.set(r,s)}return s})})}var Qr=20;function Zr(e){let t={minX:99,maxX:-99,minY:99,maxY:-99},{rectangles:n,verticalRectangles:o,curves:r}=e.shapes;for(let s of[n,o,r])for(let{xStart:a,xEnd:c}of s)t.minX=Math.min(t.minX,a,c),t.maxX=Math.max(t.maxX,a,c);e.nodes.forEach(s=>{s.x!==void 0&&(t.minX=Math.min(t.minX,s.x-9),t.maxX=Math.max(t.maxX,s.x+Qr+s.pixelWidth)),s.y!==void 0&&(t.minY=Math.min(t.minY,s.y-10),t.maxY=Math.max(t.maxY,s.y+s.contentHeight+10))}),e.tracks.forEach(s=>{s.path.forEach(a=>{let c=a.y??0;t.maxY=Math.max(t.maxY,c+s.width),t.minY=Math.min(t.minY,c)})}),e.imageBounds=t}function Ue(e,t){let n=e.nodeMap.get(N(t)),o=n===void 0?void 0:e.nodes[n];if(o===void 0)throw new Error(`Unknown node ${t}`);return o}function En(e){let t=new Map;return e.nodes.forEach((n,o)=>{t.set(n.name,o)}),t}function vn(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),o=r=>{for(let s=0;s<r.indexSequence.length-1;s+=1){let a=Math.abs(r.indexSequence[s]),c=Math.abs(r.indexSequence[s+1]);t[a].add(c),n[c].add(a)}};e.tracks.forEach(o),e.reads.forEach(o),e.nodes.forEach((r,s)=>{r.successors=Array.from(t[s]),r.predecessors=Array.from(n[s])})}function Sn(e,t){let n=0,o=0,r=0;t.forEach(s=>{let a=Math.abs(s);if(s<0){let c=e.nodeOrders[a]??=o;c<r&&(r=c),n=c,o=c-1}else{let c=e.nodeOrders[a]??=n;n=c+1,o=c}}),r<0&&Qe(e,-r)}function es(e,t){let n=0,o=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let r=t[n],s,a;r>=0?(s=e.nodeOrders[r]-1,a=-1):(s=e.nodeOrders[-r]+1,a=1);for(let c=n-1;c>=0;c-=1){let i=Math.abs(t[c]);e.nodeOrders[i]===void 0&&(e.nodeOrders[i]=s,o=Math.min(o,s),s+=a)}return o<0&&Qe(e,-o),n}var ts=-1;function ns(e){let t=[];for(let n of e)t.push(n??ts);return t}function je(e){let t,n,o,r,s=0,a=e.tracks.concat(e.reads),c={stamp:new Int32Array(e.nodes.length),generation:0};e.nodeOrders=new Array(e.nodes.length).fill(void 0),e.nodes.forEach(l=>{l.order=void 0}),Sn(e,e.tracks[0].indexSequence);for(let l=1;l<a.length;l+=1){if(H(`generating order for track ${l+1}`),o=es(e,a[l].indexSequence),o===null){l<e.tracks.length?Sn(e,a[l].indexSequence):(a.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=ss(a[l].indexSequence);o<t.length;){for(r=o,o+=1;o<t.length&&e.nodeOrders[t[o]]===void 0;)o+=1;if(o<t.length){n=e.nodeOrders[t[r]]+1;for(let d=r+1;d<o;d+=1)e.nodeOrders[t[d]]=n,n+=1;if(e.nodeOrders[t[o]]>e.nodeOrders[t[r]])e.nodeOrders[t[o]]<n&&Rn(e,t[o],t[o-1],n);else if(a[l].indexSequence[o]>=0&&!os(e,t[o],t[r],c))Rn(e,t[o],t[o-1],n);else if(a[l].indexSequence[r]<0||e.nodes[t[r+1]].degree<2&&e.nodeOrders[t[o]]<e.nodeOrders[t[r]]){n=e.nodeOrders[t[r]]-1;for(let d=r+1;d<o;d+=1)e.nodeOrders[t[d]]=n,s=Math.min(s,n),n-=1}}else if(a[l].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let d=r+1;d<t.length;d+=1){let u=t[d];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let d=r+1;d<t.length;d+=1){let u=t[d];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,s=Math.min(s,n),n-=1)}}}}s<0&&Qe(e,-s);let i=ns(e.nodeOrders);e.nodeOrders=i,i.forEach((l,d)=>{let u=e.nodes[d];u!==void 0&&(u.order=l)})}function os(e,t,n,o){o.generation+=1;let{stamp:r,generation:s}=o,a=[t];for(r[t]=s;a.length>0;){let c=a.pop();if(c===n)return!0;for(let i of e.nodes[c].successors)r[i]!==s&&(r[i]=s,a.push(i))}return!1}function rs(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function ss(e){return e.map(t=>Math.abs(t))}function Qe(e,t){e.nodeOrders.forEach((n,o)=>{n!==void 0&&(e.nodeOrders[o]=n+t)})}function Rn(e,t,n,o){let r=new Map,s=[[t,o]],a=0;for(;a<s.length;){let[c,i]=s[a];a+=1;let l=e.nodeOrders[c];l!==void 0&&l<i&&(!r.has(c)||r.get(c)<i)&&(r.set(c,i),e.nodes[c].successors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,i+1])}),c!==t&&e.nodes[c].predecessors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,i+1])}))}r.forEach((c,i)=>{e.nodeOrders[i]=c})}function is(e){e.nodes.forEach(t=>{t.tracks=[]}),e.tracks.forEach(t=>{t.indexSequence.forEach(n=>{e.nodes[Math.abs(n)].tracks.push(t.id)})}),e.nodes.forEach(t=>{t.degree=t.tracks.length})}function as(e){cs(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function cs(e,t,n){let o=new Int32Array(e.nodes.length),r=new Uint8Array(e.nodes.length);for(let s of n.sequence){let a=k(s)?void 0:e.nodeMap.get(s);a!==void 0&&(r[a]=1)}for(let s of t){let{sequence:a,indexSequence:c}=s,i=c.length-1;for(let l=0;l<=i;l+=1){let d=Math.abs(c[l]);if(r[d]===1)continue;let u=e.nodes[d].order,f=l>0?e.nodes[Math.abs(c[l-1])].order:void 0,p=l<i?e.nodes[Math.abs(c[l+1])].order:void 0,h=k(a[l])?1:-1;(f===void 0||f<u)&&(p===void 0||u<p)&&(o[d]+=h),(f===void 0||f>u)&&(p===void 0||u>p)&&(o[d]-=h)}}for(let s of t){let{sequence:a,indexSequence:c}=s;for(let i=0;i<c.length;i+=1)o[Math.abs(c[i])]>0&&(a[i]=Ve(a[i]),c[i]=-c[i])}e.nodes.forEach((s,a)=>{o[a]>0&&(s.seq=Je(s.seq),s.switched=!0)})}function ls(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort(Ze);let s=ds(e);r.forEach(a=>{a.order>=0&&(a.order>o&&(o=a.order,t=n+10*s[a.order]),a.x=t,n=Math.max(n,t+40+a.pixelWidth))})}var Ke=35;function fs(e){return e<=Ke?e/17.5:Ke/17.5*Math.sqrt(e/Ke)}function ds(e){let t=[],n=[],o=[],r=[];for(let s=0;s<=e.maxOrder;s+=1)t.push(0),n.push(0),o.push(0);e.tracks.forEach(s=>{for(let a=1;a<s.path.length;a+=1){let c=s.path[a],i=s.path[a-1];c.order===i.order?c.isForward?t[c.order]=t[c.order]+1:n[c.order]=n[c.order]+1:o[c.order]=Math.max(fs(Math.abs((c.y??0)-(i.y??0))),o[c.order])}}),r.push(Math.max(0,t[0]-1));for(let s=1;s<=e.maxOrder;s+=1)r.push(Math.max(Math.max(0,t[s]-1)+Math.max(0,n[s-1]-1),o[s]));return r}function us(e){let t=[],n=[];for(let o=0;o<=e.maxOrder;o+=1)e.assignments[o]=[],n[o]=new Map,t[o]=[];e.tracks.forEach((o,r)=>{o.path=In(e,o),o.path.forEach((s,a)=>{ps(e,s.order,s.node,r,a,t,n)})});for(let o=0;o<=e.maxOrder;o+=1)ms(e,e.assignments[o],o)}function ps(e,t,n,o,r,s,a){let c={trackID:o,segmentID:r,compareToFromSame:s[t][o]??null},i=n===null?void 0:a[t].get(n);if(i===void 0){let l={type:"single",node:n,tracks:[c]};e.assignments[t].push(l),n!==null&&a[t].set(n,l)}else i.type="multiple",i.tracks.push(c);s[t][o]=c}function hs(e,t,n){let o;t.forEach(r=>{r.idealLane=0,r.tracks.forEach(s=>{if(s.segmentID===0)s.idealLane=s.trackID,s.idealY=null;else if(e.tracks[s.trackID].path[s.segmentID-1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID-1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID-1].y;else if(s.segmentID<e.tracks[s.trackID].path.length-1&&e.tracks[s.trackID].path[s.segmentID+1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID+1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID+1].y;else{for(o=s.segmentID-1;o>=0&&e.tracks[s.trackID].path[o].order!==n-1;)o-=1;o<0?(s.idealLane=s.trackID,s.idealY=null):(s.idealLane=e.tracks[s.trackID].path[o].lane,s.idealY=e.tracks[s.trackID].path[o].y)}r.idealLane+=s.idealLane}),r.idealLane/=r.tracks.length})}function ms(e,t,n){let o=0,r=new Set,s=20,a=!1,c=-1;hs(e,t,n),t.sort(_n),t.forEach(i=>{i.node!==null?(e.nodes[i.node].topLane=o,a&&(s-=10),e.nodes[i.node].y=s,e.nodes[i.node].contentHeight=0,a=!1):(a?s-=25:s>20&&(s-=10),a=!0),i.tracks.sort(_n),i.tracks.forEach(l=>{l.lane=o,l.trackID===c&&i.node===null&&a&&(s+=10),e.tracks[l.trackID].path[l.segmentID].lane=o,e.tracks[l.trackID].path[l.segmentID].y=s,typeof l.idealY=="number"&&r.add(l.idealY-s),o+=1,s+=e.tracks[l.trackID].width,i.node!==null&&(e.nodes[i.node].contentHeight+=e.tracks[l.trackID].width),c=l.trackID}),s+=25}),gs(e,t,r)}function gs(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let a=bs(e,t,s);a<r&&(r=a,o=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=o),s.tracks.forEach(a=>{let c=e.tracks[a.trackID].path[a.segmentID];c.y=c.y+o})})}function xs(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(o=>{if(o.node!==null){let r=e.nodes[o.node];r!==t&&r.y>t.y&&(r.y+=n,o.tracks.forEach(s=>{let a=e.tracks[s.trackID].path[s.segmentID];a.y=a.y+n}))}else o.tracks.forEach(r=>{let s=e.tracks[r.trackID].path[r.segmentID];s.y>=t.y&&(s.y=s.y+n)})}),e.nodesPerOrder[t.order].length>0&&e.nodesPerOrder[t.order].forEach(o=>{e.nodes[o]!==t&&e.nodes[o].y>t.y&&(e.nodes[o].y+=n)}))}function bs(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{typeof s.idealY=="number"&&e.tracks[s.trackID].type!=="read"&&(o+=Math.abs(s.idealY-n-e.tracks[s.trackID].path[s.segmentID].y)*e.tracks[s.trackID].width)})}),o}function _n(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function Ze(e,t){return e.order!==t.order?e.order-t.order:e.y!==void 0&&t.y!==void 0?e.y-t.y:0}function ys(e){let t=!0,n=4,o=e.config.trackWidth;if(e.config.freqWidth==="linear"){for(let r of e.tracks)r.width=r.type==="read"?n:Math.max(1,Math.round(r.freq??1))*o;return}for(let r of e.tracks)r.freq!==void 0?r.width=Math.round((Math.log(Math.max(r.freq,1))+1)*n):(r.width=o,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(t=!1);t&&e.tracks.forEach(r=>{r.freq!==void 0&&(r.width=o)})}function ws(e,t){let n=t.path[0],o=e.nodes[n.node],r=t.firstNodeOffset??0;return et(o,n.isForward?r:o.sequenceLength-r)}function Ms(e,t){let n=t.path[t.path.length-1],o=e.nodes[n.node],r=t.finalNodeCoverLength??0;return et(o,n.isForward?r:o.sequenceLength-r)}function Bn(e,t){return t>e.sequenceLength?null:et(e,t)}function et(e,t){let[n,o]=Ts(e);if(e.sequenceLength===0)return n;let r=Math.min(Math.max(t,0),e.sequenceLength);return n+r/e.sequenceLength*(o-n)}function Es(e){let t,n,o,r;for(let i=0;i<=e.maxOrder;i+=1)e.extraLeft.push(0),e.extraRight.push(0);let s=[],a=[];e.nodes.forEach(i=>{i.x!==void 0&&(s[i.order]=i.x,a[i.order]===void 0?a[i.order]=i.x+i.pixelWidth:a[i.order]=Math.max(a[i.order],i.x+i.pixelWidth))});let c=e.tracks[0];e.tracks.sort(Ur),e.tracks.forEach(i=>{o=i.path[0].y,i.type!=="read"?i.sequence[0].startsWith("-")?t=a[i.path[0].order]+20:t=s[i.path[0].order]-20:t=ws(e,i);for(let l=0;l<i.path.length;l+=1)i.path[l].y!==o&&(i.path[l-1].isForward?n=a[i.path[l-1].order]:n=s[i.path[l-1].order],n!==t&&e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+i.width-1,id:i.id,name:i.name,type:i.type}),i.path[l].order-1===i.path[l-1].order?(t=n,n=s[i.path[l].order],r=i.path[l].y,e.shapes.curves.push({xStart:t,yStart:o,xEnd:n+1,yEnd:r,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[l-1].node,nodeEnd:i.path[l].node,orderStart:i.path[l-1].order,orderEnd:i.path[l].order,...i===c?{reference:!0}:{}}),t=n,o=r):i.path[l].order+1===i.path[l-1].order?(t=n,n=a[i.path[l].order],r=i.path[l].y,e.shapes.curves.push({xStart:t+1,yStart:o,xEnd:n,yEnd:r,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[l-1].node,nodeEnd:i.path[l].node,orderStart:i.path[l-1].order,orderEnd:i.path[l].order,...i===c?{reference:!0}:{}}),t=n,o=r):i.path[l-1].isForward?(r=i.path[l].y,On(e,1,n,o,r,i.width,i.id,i.path[l].order,i.type,i.name),t=a[i.path[l].order],o=i.path[l].y):(r=i.path[l].y,On(e,-1,n,o,r,i.width,i.id,i.path[l].order,i.type,i.name),t=s[i.path[l].order],o=i.path[l].y));i.type!=="read"?i.path[i.path.length-1].isForward?n=a[i.path[i.path.length-1].order]+20:n=s[i.path[i.path.length-1].order]-20:n=Ms(e,i),e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+i.width-1,id:i.id,name:i.name,type:i.type})})}var Xn=1e9;function Dn(e,t,n,o=Xn){let r=new Map,s=0,a=e.nodes.length,c=(m,g)=>(m+a)*(2*a+1)+g+a,i=e.config.ignoreStrand;for(let[m,g]of t.entries()){let x=Math.max(g.freq??1,1);s+=x;let y=g.indexSequence;if(!(y.length<2))for(let M=0;M<y.length-1;M+=1){let w=y[M],v=y[M+1],E=e.nodes[Math.abs(w)],b=e.nodes[Math.abs(v)],S=i?Math.min(c(w,v),c(-v,-w)):c(w,v),_=r.get(S);_===void 0?r.set(S,{sSigned:w,dSigned:v,sName:w<0?`-${E.name}`:E.name,dName:v<0?`-${b.name}`:b.name,count:x,crossings:x,sourceTrackID:g.sourceTrackID,lastSource:m}):(_.crossings+=x,_.lastSource!==m&&(_.count+=x,_.lastSource=m))}}let l=0;for(let m of r.values())m.crossings>l&&(l=m.crossings);let d=pe,u=60,f=m=>l<=1?d:d+(u-d)*Math.sqrt(m/l),p=[],h=0;for(let m of r.values()){let g=o+h,x=n==="haplotype"?{count:m.count,total:s}:void 0,y=x===void 0?"":` (${_s(x)})`,M=m.crossings===m.count?"":`, ${m.crossings.toLocaleString()} crossings`,w=`${m.count.toLocaleString()} ${n}${m.count===1?"":"s"}${y}${M}: Node ${m.sName} \u2192 Node ${m.dName}`;e.coarsenedEdgeMeta.set(g,{count:m.count,label:w});let v=e.nodes[Math.abs(m.sSigned)].sequenceLength;p.push({id:g,sourceTrackID:m.sourceTrackID,type:"read",name:w,sequence:[m.sName,m.dName],indexSequence:[],path:[],width:f(m.crossings),firstNodeOffset:v,finalNodeCoverLength:0,sequenceNew:[{nodeName:m.sName,mismatches:[]},{nodeName:m.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:m.count,haplotypeShare:x}),h+=1}if(Nn){let m="?",g=0;e.nodes.forEach(x=>{x.contentHeight>g&&(g=x.contentHeight,m=x.name)}),H(`[coarsened] ${n}s_in=${t.length} edges_out=${p.length} tallestNodeBeforePlace=${m}(${g.toFixed(1)})`)}return{bands:p,total:s}}function vs(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(d=>d.name===e.trackForRuler),o=n===-1?0:n,r=e.tracks[o],s=(r.freq??1)-1,a=Rs(e,r),c=e.tracks.filter((d,u)=>u!==o).map(d=>Ss(a,d));if(s>0&&c.push({...r,freq:s}),c.length===0)return;let{bands:i,total:l}=Dn(e,c,"haplotype",t);return i.length>0?{ref:r,bands:i,total:l}:void 0}function Ss(e,t){let n=0;for(let o of t.indexSequence){let r=e[Math.abs(o)];r!==void 0&&r!==0&&(n+=r===Math.sign(o)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(Ve).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function Rs(e,t){let n=new Int8Array(e.nodes.length);for(let o of t.indexSequence){let r=Math.abs(o);n[r]===0&&(n[r]=Math.sign(o))}return n}function _s({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var Tn=7;function On(e,t,n,o,r,s,a,c,i,l){let d=t===1?e.extraRight:e.extraLeft,u=10*d[c],f=n+t*(u+5),p=Tn,h=Math.min(Tn,s),m=Math.min(o,r),g=Math.max(o,r),x=t===1?n:f-1,y=t===1?f:n,M=b=>{e.shapes.verticalRectangles.push({xStart:x,yStart:b,xEnd:y,yEnd:b+s-1,id:a,name:l,type:i})};M(o),e.shapes.verticalRectangles.push({xStart:t===1?f+p:f-p-h,yStart:m+s+p-1,xEnd:t===1?f+p+h-1:f-p-1,yEnd:g-p+1,id:a,name:l,type:i}),M(r);let w=f+t*p,v=f+t*(p+h),E=`M ${f} ${g}`;E+=` Q ${w} ${g} ${w} ${g-p}`,E+=` H ${v}`,E+=` Q ${v} ${g+s} ${f} ${g+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:i}),E=`M ${f} ${m}`,E+=` Q ${v} ${m} ${v} ${m+s+p}`,E+=` H ${w}`,E+=` Q ${w} ${m+s} ${f} ${m+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:i}),d[c]+=1}function Ts(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function An(e){switch(e.config.nodeWidthOption){case"compressed":e.nodes.forEach(t=>{t.width=1+Math.log2(Math.max(t.sequenceLength,1)),t.pixelWidth=Math.round((t.width-1)*8.401)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*8.401),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*8.401)});break;case"normal":{let t=e.config.charWidth;e.nodes.forEach(n=>{n.width=n.sequenceLength,n.pixelWidth=Math.round(t*Math.max(n.sequenceLength-1,0))});break}default:throw new Error(`${e.config.nodeWidthOption} not implemented`)}}var D=0;function kn(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function A(e,t,n){let o=e.count[t];o===0?(e.first[t]=n,e.count[t]=1):o===1&&e.first[t]!==n&&(e.count[t]=2)}function V(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function Os(e){let t=kn(e.nodes.length),n=kn(e.nodes.length),o=new Map,r=u=>{let f=o.get(u);if(f===void 0){let p=e.nodeMap.get(N(u));f=k(u)?-p:p,o.set(u,f)}return f};e.tracks.concat(e.reads).forEach(u=>{let{sequence:f}=u,p=u.type==="haplotype",h=f.length-1,m=D,g=h>=0?r(f[0]):D;for(let x=0;x<=h;x+=1){let y=x<h?r(f[x+1]):D;if(g>0)x>0?(A(t,g,m),m<0&&A(t,g,-m)):p&&A(t,g,D),x<h?(A(n,g,y),y<0&&A(n,g,-y)):p&&A(n,g,D);else{let M=-g;x>0?(A(n,M,-m),m>0&&A(n,M,m)):p&&A(n,M,D),x<h?(A(t,M,-y),y>0&&A(t,M,y)):p&&A(t,M,D)}m=g,g=y}});let a=new Uint8Array(e.nodes.length);e.nodes.forEach((u,f)=>{As(f,t,n)!==0&&(a[f]=1)});let c=new Int32Array(e.nodes.length),i=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((u,f)=>{if(a[f]!==1){c[f]=f,l[f]=u.sequenceLength;for(let p=f;ks(p,t,n);)p=V(n,p),c[p]=f,i[p]=u.sequenceLength,u.sequenceLength+=e.nodes[p].sequenceLength,u.seq+=e.nodes[p].seq,l[p]=u.sequenceLength}}),e.reads.forEach(u=>{let{sequence:f}=u,p=u.sequenceNew??f.map(M=>({nodeName:M,mismatches:[]})),h=M=>{let w=Math.abs(r(M));return k(M)?e.nodes[c[w]].sequenceLength-l[w]:i[w]},m=f.length-1;u.firstNodeOffset=(u.firstNodeOffset??0)+h(f[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+h(f[m]);let g=[],x=[],y=[];f.forEach((M,w)=>{let v=Math.abs(r(M)),{mismatches:E}=p[w],b=h(M);if(E.forEach(S=>{S.pos+=b}),a[v]===1&&!k(M)&&w>0)x.at(-1).mismatches.push(...E);else if(a[v]===1&&k(M)&&w<m)y.push(...E);else{let S=e.nodes[c[v]].name,_=k(M)?Ln(S):S;g.push(_),x.push({nodeName:_,mismatches:y.concat(E)}),y=[]}}),u.sequence=g,u.sequenceNew!==void 0&&(u.sequenceNew=x)}),e.tracks.forEach(u=>{let{sequence:f}=u,p=0;for(let h of f)a[Math.abs(r(h))]===0&&(f[p]=h,p+=1);f.length=p});let d=1;for(let u=1;u<e.nodes.length;u+=1)a[u]===0&&(e.nodes[d]=e.nodes[u],d+=1);e.nodes.length=d}function As(e,t,n){let o=V(t,e);return o!==0&&V(n,o)!==0?o:0}function ks(e,t,n){let o=V(n,e);return o!==0&&V(t,o)!==0}function Ns(e,t){let n=new Map;for(let o of e){let r=t(o),s=n.get(r);s===void 0?n.set(r,[o]):s.push(o)}return n}function Cs(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function tt(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function $s(e,t){for(let n=0;n<e.length;n+=1){let o=e[n]-t[n];if(o!==0)return o}return 0}var qn=.75,he=.8;function Ps(e,t){let n=e[0],o=Math.min(Math.abs(n.xEnd-n.xStart),t);if(o===0)return e.map(()=>0);let r=e.length>5?.4/e.length:0,s=e.map(f=>{let p=Math.abs(f.yEnd-f.yStart),h=p/Math.hypot(p,o)*Math.min(f.width,he*qn*o);return Math.max(r,h/(qn*o))}),a=f=>s.reduce((p,h,m)=>p+(f(e[m])?h:0),0),c=a(f=>f.reference===!0),i=a(f=>f.reference!==!0),l=c>he?he/c:1,d=he-c*l,u=i>d?d/i:1;return s.map((f,p)=>f*(e[p].reference?l:u))}function Fn(e,t,{gapWidth:n=1/0}={}){let o=Ns(e.filter(r=>r.type===t),r=>tt(r).join(","));return o.forEach(r=>{r.sort(Cs);let s=Ps(r,n),a=.5-s.reduce((c,i)=>c+i,0)/2;r.forEach((c,i)=>{let l=p=>c.xStart+(c.xEnd-c.xStart)*(c.yStart<c.yEnd?1-p:p),d=l(a);a+=s[i];let u=l(a),f=`M ${c.xStart} ${c.yStart}`;f+=` C ${d} ${c.yStart} ${d} ${c.yEnd} ${c.xEnd} ${c.yEnd}`,f+=` V ${c.yEnd+c.width}`,f+=` C ${u} ${c.yEnd+c.width} ${u} ${c.yStart+c.width} ${c.xStart} ${c.yStart+c.width}`,f+=" Z",c.path=f})}),[...o.values()].sort((r,s)=>$s(tt(r[0]),tt(s[0]))).flat()}function Gn(e,t=16){let n=e.match(/[A-Za-z]|-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/g)??[],o=[],r=0,s=0,a=0,c=()=>Number(n[a++]);for(;a<n.length;){let i=n[a++];if(i==="M"||i==="L")r=c(),s=c(),o.push([r,s]);else if(i==="H")r=c(),o.push([r,s]);else if(i==="V")s=c(),o.push([r,s]);else if(i==="C"){let[l,d,u,f,p,h]=[c(),c(),c(),c(),c(),c()];for(let m=1;m<=t;m+=1){let g=m/t,x=1-g,y=x*x*x,M=3*x*x*g,w=3*x*g*g,v=g*g*g;o.push([y*r+M*l+w*u+v*p,y*s+M*d+w*f+v*h])}r=p,s=h}else if(i==="Q"){let[l,d,u,f]=[c(),c(),c(),c()];for(let p=1;p<=t;p+=1){let h=p/t,m=1-h;o.push([m*m*r+2*m*h*l+h*h*u,m*m*s+2*m*h*d+h*h*f])}r=u,s=f}else if(i!=="Z")throw new Error(`flattenPath: unsupported path command ${i}`)}return o}function Yn(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,o=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n+9} ${o} ${n+9} ${o+9}`,n+=9,o+=9,e.contentHeight>0&&(o+=e.contentHeight,t+=` L ${n} ${o}`),t+=` Q ${n} ${o+9} ${n-9} ${o+9}`,n-=9,o+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n-9} ${o} ${n-9} ${o-9}`,n-=9,o-=9,e.contentHeight>0&&(o-=e.contentHeight,t+=` L ${n} ${o}`),t}function Ls(e,t){let n=[],o=e.sequenceNew??[],r=e.path.filter(s=>s.node!==null);return o.forEach((s,a)=>{let c=t.nodeMap.get(N(s.nodeName)),i=c===void 0?void 0:t.nodes[c],l=r[a]?.y;if(i&&l!==void 0){let d={readId:e.id,y:l,height:e.width},u=f=>Bn(i,f);for(let f of s.mismatches){let p=u(f.pos);if(p!==null){if(f.type==="insertion"){let h=a===0&&f.pos===e.firstNodeOffset||a===o.length-1&&f.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:p,seq:f.seq,softClip:h})}else if(f.type==="deletion"&&f.length!==void 0){let h=u(f.pos+f.length);h!==null&&n.push({...d,kind:"deletion",x0:p,x1:h,length:f.length})}else if(f.type==="substitution"&&f.seq!==void 0){let h=u(f.pos+f.seq.length);h!==null&&n.push({...d,kind:"substitution",x0:p,x1:h,seq:f.seq})}}}}}),n}function Wn(e){return e.reads.flatMap(t=>Ls(t,e))}var nt=24,Is=.5,Bs=e=>e.bp1>e.bp0;function Yc(e,t){let n=e.filter(Bs);if(n.length===0){let l=e[0];return l?[{tx:l.x0,sx:t(l.bp0)}]:[]}let o=[],r=[],s=[];n.forEach((l,d)=>{o.push(l.x0,l.x1),r.push(t(l.bp0),t(l.bp1)),s.push(d===0?0:Math.min(l.x0-n[d-1].x1,nt),0)});let a=r.at(-1)-r[0],c=s.reduce((l,d)=>l+d,0),i=c>0?Math.min(1,Is*a/c):1;return Xs(r,s,i).map((l,d)=>({tx:o[d],sx:l}))}function Xs(e,t,n){let o=[],r=0;for(let a of t)r+=a*n,o.push(r);let s=[];return e.forEach((a,c)=>{let i={mean:a-o[c],n:1},l=s.at(-1);for(;l&&l.mean>=i.mean;){s.pop();let d=l.n+i.n;i={mean:(l.mean*l.n+i.mean*i.n)/d,n:d},l=s.at(-1)}s.push(i)}),s.flatMap(a=>Array(a.n).fill(a.mean)).map((a,c)=>a+o[c])}function Wc(e,t){let n=e.length;if(n===0)return t;let o=e[0],r=e[n-1];if(t<=o.tx)return o.sx+(t-o.tx);if(t>=r.tx)return r.sx+(t-r.tx);let s=0,a=n-1;for(;a-s>1;){let d=s+a>>1;e[d].tx<=t?s=d:a=d}let c=e[s],i=e[a],l=i.tx-c.tx;return l>0?c.sx+(t-c.tx)/l*(i.sx-c.sx):c.sx}function st(e){let t=e.trim().split(/[\s,]+/),n=[],o=0,r=()=>Number(t[o++]);for(;o<t.length;){let s=t[o++];s==="M"||s==="L"?n.push({op:s,x:r(),y:r()}):s==="H"?n.push({op:s,x:r()}):s==="V"?n.push({op:s,y:r()}):s==="Q"?n.push({op:s,x1:r(),y1:r(),x:r(),y:r()}):s==="C"?n.push({op:s,x1:r(),y1:r(),x2:r(),y2:r(),x:r(),y:r()}):s==="Z"&&n.push({op:s})}return n}function Kn(e){let t=1/0,n=-1/0;for(let o of e)"x"in o&&(t=Math.min(t,o.x),n=Math.max(n,o.x)),"x1"in o&&(t=Math.min(t,o.x1),n=Math.max(n,o.x1));return{x0:t,x1:n}}function Hn(e,t,n,o,r){let s=st(e);return{commands:s,outline:Gn(e,12),color:t,id:n,haplotype:o,reference:r,...Kn(s)}}function zn(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?Vt(n):t[n.id]]))}function Un(e,t,n,o,r){let{shapes:s}=e,a=t==="haplotype",c=f=>n.get(f.id),i=f=>a&&o.has(f.id),l=[...s.rectangles,...s.verticalRectangles].filter(f=>f.type===t).map(f=>({color:c(f),id:f.id,haplotype:a,reference:i(f),x0:f.xStart,x1:f.xEnd+1,y0:f.yStart,y1:f.yEnd+1})),d=Fn(s.curves,t,{gapWidth:r}).map(f=>Hn(f.path,c(f),f.id,a,i(f))),u=s.corners.filter(f=>f.type===t).map(f=>Hn(f.path,c(f),f.id,a,i(f)));return{rects:l,shapes:[...d,...u]}}function Ds(e){let t=new Set;return e?.paths?.forEach((n,o)=>{U(n.name).name===e.referencePath&&t.add(o)}),t}function qs({layout:e,pathColors:t,graph:n,columns:o}){let r=zn(e,t),s=Ds(n),a=o?nt:void 0,c=[];return e.nodes.forEach(i=>{if(i.order>=0){let l=st(Yn(i));c.push({name:i.name,commands:l,...Kn(l)})}}),{bounds:e.bounds,layers:[Un(e,"haplotype",r,s,a),Un(e,"read",r,s,a)],nodes:c,mismatches:Wn(e).filter(i=>i.kind!=="insertion"||!i.softClip)}}function ot(e,t,n,o){let r=0,s=0;for(let a of t)switch(a.op){case"M":r=a.x,s=a.y,e.moveTo(n(r),o(s));break;case"L":r=a.x,s=a.y,e.lineTo(n(r),o(s));break;case"H":r=a.x,e.lineTo(n(r),o(s));break;case"V":s=a.y,e.lineTo(n(r),o(s));break;case"Q":r=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),o(a.y1),n(r),o(s));break;case"C":r=a.x,s=a.y,e.bezierCurveTo(n(a.x1),o(a.y1),n(a.x2),o(a.y2),n(r),o(s));break;case"Z":e.closePath();break}}function jn(e,t,n,o,r){let s=new Map;for(let a of t)if(n(a)){let c=o(a),i=s.get(c);i?i.push(a):s.set(c,[a])}for(let a of s.values()){e.fillStyle=o(a[0]),e.beginPath();for(let c of a)r(c);e.fill()}}var Fs=12,Gs=.15;function Ys(e){return Math.max(Gs,Math.min(1,e/Fs))}var Ws=.55;function Hs(e,t,n){let{x:o,y:r,width:s}=n,a=d=>o(d.x1)>=0&&o(d.x0)<=s,c=d=>d.haplotype&&n.tubeColors?.[d.id]||d.color;e.globalAlpha=1;for(let d of t.layers)for(let u of[!1,!0]){let f=p=>p.reference===u;jn(e,d.rects,p=>f(p)&&a(p),c,p=>{let h=o(p.x0),m=r(p.y0);e.rect(h,m,o(p.x1)-h,r(p.y1)-m)}),jn(e,d.shapes,p=>f(p)&&a(p),c,p=>{ot(e,p.commands,o,r)})}let i=n.darkMode?"#d0d0d0":"#000000",l=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=Vn(n);for(let d of t.nodes)if(a(d)&&d.name!==n.highlightNode){e.beginPath(),ot(e,d.commands,o,r);let u=n.nodeColors?.get(d.name);e.fillStyle=u??l,e.strokeStyle=i,e.globalAlpha=u?Ws:1,e.fill(),e.globalAlpha=Ys(o(d.x1)-o(d.x0)),e.stroke(),e.globalAlpha=1}me(e,t,n),js(e,t.mismatches,n)}function Vn(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function me(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),ot(e,o.commands,n.x,n.y),e.globalAlpha=1,e.lineWidth=Vn(n),e.fillStyle="rgba(255,192,203,0.5)",e.strokeStyle="#ff0000",e.fill(),e.stroke())}var Jn=12,Us=6;function it(e){return Jn*e>=Us}function rt(e,{x:t,width:n}){let[o,r]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(r)>=0&&t(o)<=n}function js(e,t,n){let{x:o,y:r,yScale:s,darkMode:a}=n;if(!it(s)||t.length===0)return;let c=Jn*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&rt(i,n)){let l=o(i.x0),d=r(i.y);e.rect(l,d,o(i.x1)-l,r(i.y+i.height)-d)}e.fill(),e.font=`${c}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of t)rt(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,o(i.x0)+1,r(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",o(i.x)-3,r(i.y+i.height)))}function Ks(e,t,n){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[a,c]=e[r],[i,l]=e[s];c>n!=l>n&&t<(i-a)*(n-c)/(l-c)+a&&(o=!o)}return o}function zs(e,{x:t,y:n},o,r){for(let s=e.layers.length-1;s>=0;s--){let{rects:a,shapes:c}=e.layers[s];for(let i of[!0,!1]){for(let l of a)if(l.reference===i&&t(l.x0)<=o&&o<=t(l.x1)&&n(l.y0)<=r&&r<=n(l.y1))return l.id;for(let l of c)if(l.reference===i&&t(l.x0)<=o&&o<=t(l.x1)&&Ks(l.outline.map(([d,u])=>[t(d),n(u)]),o,r))return l.id}}}var Vs=4;function Js(e,t,n,o){let{x:r,y:s,yScale:a}=t;return it(a)?e.mismatches.find(c=>s(c.y)<=o&&o<=s(c.y+c.height)&&(c.kind==="insertion"?Math.abs(r(c.x)-n)<=Vs:r(c.x0)<=n&&n<=r(c.x1))):void 0}var q=JBrowseExports["@jbrowse/core/util/groupKeys"],Qs=e=>q!=null&&e in Object(q)?q[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/core/util/groupKeys' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var ge=Qs("groupKeyComparator");var Al=q&&q.__esModule?q.default:q;var xe=16;function $l(e){let[t="",...n]=e.split(/\r\n|\r|\n/),o=t.split(" ").slice(1),r=new Map;for(let s of n){if(!s)continue;let[a="",...c]=s.split(" ");a&&!r.has(a)&&r.set(a,{...Object.fromEntries(o.map((i,l)=>[i,c[l]??""])),name:a})}return[...r.values()]}function Pl(e){let t=new Set;for(let n of e??[])for(let o of Object.keys(n))o!=="name"&&t.add(o);return[...t]}function Ll(e){if(typeof e=="string")return e?{field:e}:void 0;let{field:t,domain:n}=e??{};if(!(typeof t!="string"||!t))return Array.isArray(n)?{field:t,domain:n.filter(o=>typeof o=="string")}:{field:t}}function at(e,t){return`${e} ${t}${e===1?"":"s"}`}function ct(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return(o,r)=>n.get(o)||n.get(r)||""}function lt(e,t,{field:n,domain:o},r,s){let a=new Map;for(let c of e){let i=t(c),l=a.get(i);l?l.push(c):a.set(i,[c])}return[...a.keys()].sort(ge(o)).map(c=>{let i=a.get(c),l=new Set(i.map(s)).size;return{key:c,members:i,title:`${c||`${n}: none`} \xB7 ${at(l,r)}`}})}function Il(e,t,n){let o=ct(n.field,t),r=lt(e,c=>o(c.label,c.sample),n,"haplotype",c=>c.label),s=1,a=r.map(({key:c,members:i,title:l})=>{let d={key:c,title:l,first:s,count:i.length};return s+=i.length,d});return{rows:r.flatMap(c=>c.members),sections:a}}function Bl(e,t){let n=r=>{let s=-1;for(;s+1<e.length&&e[s+1].first<=r;)s++;return s},o=r=>r*t+(n(r)+1)*xe;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*xe})),headersPx:e.length*xe,rowAt(r,s){let a=0;for(let c=-1;c<e.length;c++){let i=c<0?0:e[c].first,l=c<0?Math.min(s,e[0]?.first??s):i+e[c].count,d=(c+1)*xe,u=Math.min(l-1,Math.max(i,Math.round((r-d)/t)));Math.abs(o(u)-r)<Math.abs(o(a)-r)&&(a=u)}return a}}}function Xl(e,t,n,o,r){return t.length===0?[z(e,o,r)]:[z({...e,rows:[]},o,r),...t.flatMap((s,a)=>z({...e,rows:e.rows.slice(s.first-1,s.first-1+s.count)},{...o,translateY:o.translateY+(n(s.first)-o.rowPx)*o.scaleY},{...r,idPrefix:`${r.idPrefix}-s${a}`}).children.filter(i=>typeof i!="string"&&i.attrs["data-testid"]!=="graph-walk-reference"))]}function J(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function Zs(e,t,n,o){let r=[],s=[],a=[e];for(o.add(e);a.length>0;){let c=a.pop(),i=t.get(c);if(i){r.push(i);for(let l of n.get(c)??[]){let d=t.get(l);d&&(d.stable.rank===ye?s.push(d):o.has(l)||(o.add(l),a.push(l)))}}}return{members:r,anchors:s}}function ei(e){if(new Set(e.map(c=>c.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((c,i)=>c.stable.start-i.stable.start),o=n[0],r=n.at(-1),s=o.stable.start+o.length,a=r.stable.start;return a>=s?{start:s,end:a,entry:o}:void 0}function ti(e,t,n){let o=new Map(e.map(a=>[a.id,a])),r=new Map,s=[];for(let a of n.get(t.id)??[])o.has(a)&&(r.set(a,0),s.push(a));if(s.length===0)for(let a of e)r.set(a.id,0),s.push(a.id);for(let a of s){let c=r.get(a)+o.get(a).length;for(let i of n.get(a)??[])if(o.has(i)){let l=r.get(i);(l===void 0||c<l)&&(r.set(i,c),s.push(i))}}return r}function ni(e,t,n){let o=ti(e,t,n),r=[...e].sort((i,l)=>o.get(i.id)-o.get(l.id)),s=new Map(r.map((i,l)=>[i.id,l])),a=new Map(e.map(i=>[i.id,i])),c=new Map;for(let[i,l]of r.entries()){let d=0;for(let u of n.get(l.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,c.get(u)+f.length))}c.set(l.id,d)}return{offsets:c,ordered:r}}function oi(e){let t=new Map(e.nodes.filter(ht).map(s=>[s.id,s])),n=gt(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==ye&&!o.has(s.id)){let{members:a,anchors:c}=Zs(s.id,t,n,o),i=ei(c);if(i){let{offsets:l,ordered:d}=ni(a,i.entry,n);r.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>l.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,l.get(f.id)+f.length),0)})}}return r.sort((s,a)=>s.start-a.start)}var ri=28,Qn="#4d4d4d",si="#5b8cc4",ii=[si,"#82abd9"],ff=["#8c8c8c","#adadad"],ai="12px sans-serif",df=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],C=e=>U(e).name;function uf(e,t,n=ii){let o=0;return e.map(r=>C(r.name)===t?Qn:n[o++%n.length])}var ci=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#76b7b2","#edc948","#9c755f","#ff9da7","#bab0ac"],Zn="#c8c8c8";function pf(e){let t=[...new Set(e)].filter(n=>n!=="").sort(ge());return new Map(t.map((n,o)=>[n,ci[o]??Zn]))}function hf(e,t,n,o){return e.map(r=>{let s=C(r.name);return s===t?Qn:o.get(n(r.members?.[0]??s))??Zn})}function li(e,t){let n=ct(e,t);return o=>{let{sample:r,haplotype:s}=J(o);return n(`${r}#${s}`,r)}}function mf(e,t){let n=(e.paths??[]).map(i=>i.name).filter(i=>C(i)!==e.referencePath);if(t.by==="column"){let i=li(t.field,t.table);return lt(n,l=>i(C(l)),t,"sample",l=>J(C(l)).sample).map(({key:l,members:d,title:u})=>({key:l,paths:d,label:u}))}let o=t.by==="sample"?i=>J(i).sample:i=>i,r=new Map;for(let i of n){let l=o(C(i)),d=r.get(l);d?d.push(i):r.set(l,[i])}let s=t.domain??[],a=new Map(s.map((i,l)=>[i,l])),c=i=>a.get(i)??s.length;return[...r].map(([i,l],d)=>({key:i,paths:l,i:d})).sort((i,l)=>c(i.key)-c(l.key)||i.i-l.i).map(({key:i,paths:l})=>({key:i,paths:l}))}function gf(e,t){if(e.graph.nodes.some(n=>n.id===t))return t;for(let[n,o]of e.members)if(o.includes(t))return n}function xf(e,t,n,o,r){let s=e.flatMap(u=>{let f=t(u);return f?[{id:u,...f}]:[]});if(s.length===0)return;let a=Math.min(...s.map(u=>u.start)),c=Math.max(...s.map(u=>u.end)),i=o>n?(r-n)/(o-n):0,l=a+Math.min(1,Math.max(0,i))*(c-a),d=u=>l<u.start?u.start-l:l>=u.end?l-u.end+1:0;return s.reduce((u,f)=>d(f)<d(u)?f:u).id}function bf(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=C(r.name);if(s!==e.referencePath)for(let a of r.members??[s])n.add(a),r.nodeIds.includes(t)&&o.add(a)}return{here:o.size,of:n.size}}var fi="bold 11px sans-serif",di=80,ui=9;function yf(e,t,n,{x:o,y:r,width:s}){let a=n.paths??[];if(!a.some(i=>i.members))return;let c=new Map;a.forEach((i,l)=>{C(i.name)!==n.referencePath&&c.set(l,i.members?.length??1)}),e.font=fi,e.textAlign="left",e.textBaseline="middle",e.fillStyle="#0b1f3a";for(let i of t.layers[0]?.rects??[]){let l=c.get(i.id),d=Math.max(0,o(i.x0)),u=Math.min(s,o(i.x1)),f=r(i.y0),p=r(i.y1);l!==void 0&&u-d>=di&&p-f>=ui&&e.fillText(`\xD7${l}`,d+4,(f+p)/2)}}var pi="10px sans-serif",hi=1e3;function wf(e,t,{x:n,y:o,width:r}){if(!t.columns)return;let s=new Map(t.graph.nodes.map(i=>[i.id,i.length]));e.font=pi;let a=new Map;t.layout.nodes.forEach(i=>{let l=s.get(i.name)??0,d=n(i.x),u=n(i.x+i.pixelWidth),f=T(l);if(i.order>=0&&l>=hi&&u-d<e.measureText(f).width){let p=(o(i.y)+o(i.y+i.contentHeight))/2,h=`${Math.round(u)}:${f}`,m=a.get(h);m?(m.count++,m.mid=Math.max(m.mid,p)):a.set(h,{text:f,right:u,mid:p,count:1})}}),e.textAlign="left",e.textBaseline="middle",e.lineJoin="round",e.lineWidth=3,e.strokeStyle="rgba(255,255,255,0.9)",e.fillStyle="rgba(0,0,0,0.75)";let c=[];for(let{text:i,right:l,mid:d,count:u}of a.values()){let f=u>1?`${i} each`:i,p={x0:l+3,x1:l+3+e.measureText(f).width,y0:d-6,y1:d+6};p.x1<=r&&!c.some(h=>h.x0<p.x1&&p.x0<h.x1&&h.y0<p.y1&&p.y0<h.y1)&&(c.push(p),e.strokeText(f,p.x0,d),e.fillText(f,p.x0,d))}}function Mf(e,t,n,{width:o,lit:r}){t.forEach((s,a)=>{let c=n?.[a];c&&(r&&me(e,s.picture,{...s.frame,width:o,highlightNode:c.box}),e.font=ai,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${c.here} of ${at(c.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4))})}function Ef(e,t){let n=new Set(t),o=(e.paths??[]).filter(l=>n.has(l.name)||C(l.name)===e.referencePath),r=new Set(o.map(l=>C(l.name))),s=new Set(o.flatMap(l=>l.nodeIds)),a=e.nodes.filter(l=>s.has(l.id)),c=new Set(a.map(l=>l.name)),i=e.pathVisits?.filter(l=>r.has(l),l=>c.has(l));return{...e,nodes:a,edges:e.edges.filter(l=>s.has(l.from)&&s.has(l.to)),paths:o,anchorPaths:e.anchorPaths?.filter(l=>r.has(l.name)),pathVisits:i,reads:void 0}}function vf(e,t){let n=[],o={},r=0,s=1/0,a=-1/0;for(let{key:c,paths:i,label:l,result:d}of t){let u=d?.tubeMap,f=d?.extent;if(u&&f){let p=r+ri,h=(f.maxY??0)-(f.minY??0);n.push({key:c,paths:i,label:l,result:{...d,tubeMap:u},top:p,height:h});let m=p-(f.minY??0);for(let[g,x]of Object.entries(d.nodePositions))o[g]=x.map(y=>({x:y.x,y:y.y+m}));r=p+h,s=Math.min(s,f.minX??s),a=Math.max(a,f.maxX??a)}}return n.length>1?{...e,nodePositions:o,extent:{...s<=a?{minX:s,maxX:a}:{},minY:0,maxY:r},tubeMapPanels:n}:e}var mi="#daa520",gi=1,xi=2,bi=4;function _f(e,t,n,o=r=>r){let r=s=>{let a=t(s)*2;return n?.nodeIds.has(s)?Math.max(a,n.walks.length*bi):a};return e.flatMap(s=>s.exonsByNode.map(({nodeId:a,d:c})=>({key:`${s.gene.name}-${s.gene.start}-${a}`,d:o(c),inner:r(a)+2*gi})))}function Tf(e,t){if(e.length===0)return;let n=(o,r,s)=>R("path",{d:o.d,fill:"none",stroke:r,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return R("g",{},R("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},R("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*xi)),...e.map(o=>n(o,"#000",o.inner)))),R("rect",{width:t.width,height:t.height,fill:mi,mask:`url(#${t.id})`}))}function ft(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${G(o)}-${G(r)} (${T(r-o)})`}function yi(e,t){let{field:n}=e.encoding,o=e.range?ft(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?ft(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${T(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${T(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${T(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function wi(e,t,n){let o=e.progress.get(t),r=e.range;if(o===void 0||!r)return;let s=Math.round(r.start+o*(r.end-r.start)-n/2);return`${r.contig}:${G(s)}-${G(s+n)}`}function Mi(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],a=r?.at(-1);if(!r||!s||!a)continue;let c=Math.max(o.start,s.bp0),i=Math.min(o.end,a.bp1);i<=c||n.push({gene:o,...ce(r,c,i),exons:o.exons.filter(l=>l.end>c&&l.start<i).map(l=>ce(r,Math.max(l.start,c),Math.min(l.end,i)))})}return n}var dt=22,Ei=4,be=8,vi="11px sans-serif",Si=8;function Ri(e){let t=e.flatMap(r=>[{x:r.x0,step:1},{x:r.x1,step:-1}]).sort((r,s)=>r.x-s.x||r.step-s.step),n=0,o=0;for(let{step:r}of t)n+=r,o=Math.max(o,n);return Math.min(Ei,o)}function _i(e,t,n,o,r=0){let{x:s,width:a,darkMode:c}=n,i=Math.max(1,Math.floor((o-r)/dt)),l=[],d=c?"#e0e0e6":"#1c1c22";e.font=vi,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=t.map(f=>({g:f,s0:s(f.x0),s1:s(f.x1)})).filter(({s0:f,s1:p})=>p>=0&&f<=a).sort((f,p)=>f.s0-p.s0);for(let{g:f,s0:p,s1:h}of u){let m=f.gene.strand>0?" \u2192":f.gene.strand<0?"\u2190 ":"",g=f.gene.strand<0?`${m}${f.gene.name}`:`${f.gene.name}${m}`,x=(Math.max(p,0)+Math.min(h,a))/2,y=e.measureText(g).width/2,M=Math.min(p,x-y),w=Math.max(h,x+y),v=l.findIndex(b=>b+Si<=M);v===-1&&(v=Math.min(l.length,i-1)),l[v]=Math.max(l[v]??-1/0,w);let E=o-v*dt-be/2;e.beginPath(),e.moveTo(p,E+.5),e.lineTo(h,E+.5),e.stroke();for(let b of f.exons){let S=s(b.x0);e.fillRect(S,E-be/2,Math.max(1,s(b.x1)-S),be)}e.fillText(g,x,E-be/2-2)}}var $=12,ro=$+8,so=8,eo=so+3,Ti=12;function Oi(e,{colorScheme:t,referenceRamp:n,walks:o}){let r={..._e(e),referenceRamp:n},s=[];return e.nodes.forEach((a,c)=>{if(Q(a)){let i=o?o.map(l=>{let d=l.colors.get(a.id);return d===void 0?ne:L(d)}):[L(Te(a,c,t,r))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(ne)})}}),s.sort((a,c)=>a.bp0-c.bp0)}function ut(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var to=2;function io(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),a=Math.max(o,r),c=0,i=0;for(let l of e)c+=Math.max(0,Math.min(l.bp1,s)-l.bp0),i+=Math.max(0,l.bp1-Math.max(l.bp0,a));return t.scale>=0?{left:Math.round(c),right:Math.round(i)}:{left:Math.round(i),right:Math.round(c)}}function Ai(e,t,n,o){if(o<0||o>$+to)return;let r,s=to;for(let a of e){let[c,i]=ut(t,a.bp0,a.bp1),l=Math.max(0,c-n,n-i);l<=s&&(s=l,r=a.node)}return r}function ki(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function ao(e,t,n,o){let r=e.map(l=>{let[d,u]=ut(t,l.bp0,l.bp1),f=Math.round(d*o);return{colors:l.colors,x0:d,px0:f,px1:Math.max(Math.round(u*o),f+1)}}).filter(l=>l.px1>0&&l.px0<n*o).sort((l,d)=>l.x0-d.x0),s=[],a=-1/0,c=[-1/0,-1/0];for(let{colors:l,px0:d,px1:u}of r){let f=Math.max(d,a);if(u>f){let p=c[0]<f?0:1;c[p]=u,s.push({colors:l,x0:f/o,x1:u/o,tier:p}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Ti?s:s.map(({tier:l,...d})=>d)}function no(e,t,n,o){let r=n>0?t:t-eo;e.clearRect(r,0,eo,$);let s=t+n,a=s+n*so;e.beginPath(),e.moveTo(s,$/2),e.lineTo(a,0),e.lineTo(a,$),e.closePath(),e.fillStyle=o,e.fill()}function oo(e,t,n){return Math.round(e*$*n/t)/n}function Ni(e,t,n,{width:o,lit:r,darkMode:s,dpr:a=1}){let c=s?"#ffffff":"#18181c";e.clearRect(0,0,o,ro);for(let l of ao(t,n,o,a)){let{tier:d}=l,u=d!==void 0&&l.colors.length===1,f=u?2:l.colors.length;l.colors.forEach((p,h)=>{let m=u?d:h,g=oo(m,f,a);e.fillStyle=p,e.fillRect(l.x0,g,l.x1-l.x0,oo(m+1,f,a)-g)})}let i=io(t,n,o);if(i.left>0&&no(e,0,1,c),i.right>0&&no(e,o,-1,c),r){let[l,d]=ut(n,r.start,r.end),u=Math.max(d-l,3),f=(l+d)/2-u/2;e.strokeStyle=c,e.lineWidth=1.5,e.strokeRect(f,.75,u,$-1.5),r.anchor&&(e.beginPath(),e.moveTo(f+u/2,$),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function Ci(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function $i(e,t){let n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0)),s=Array.from({length:n+1},()=>new Array(o+1).fill(!1));for(let c=n-1;c>=0;c--)for(let i=o-1;i>=0;i--){let l=Math.abs(e[c]-t[i])+r[c+1][i+1],d=n-c>o-i?r[c+1][i]:1/0,u=o-i>n-c?r[c][i+1]:1/0;r[c][i]=Math.min(l,d,u),s[c][i]=r[c][i]===l}let a=new Array(n).fill(void 0);for(let c=0,i=0;c<n&&i<o;)s[c][i]?a[c++]=i++:n-c>o-i?c++:i++;return a}function co(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var lo=e=>e.spanningReads!==0;function Pi(e,t){return{...t,agrees:e.complete&&lo(t)?Ci(e.bp,t.bp):void 0}}function Li(e,t){let n=new Map,o=new Set,r=co(e,a=>a.bp),s=(a,c)=>{let i=[[a.filter(l=>l.item.complete),c.filter(lo)],[a,c]];for(let[l,d]of i){let u=l.filter(p=>!n.has(p.i)),f=co(d.filter(p=>!o.has(p)),p=>p.bp);$i(u.map(p=>p.item.bp),f.map(p=>p.item.bp)).forEach((p,h)=>{if(p!==void 0){let m=u[h],g=f[p].item;o.add(g),n.set(m.i,Pi(m.item,g))}})}};for(let a of new Set(t.flatMap(c=>c.haplotype??[])))s(r.filter(c=>c.item.haplotype===a),t.filter(c=>c.haplotype===a));return s(r,t.filter(a=>a.haplotype===void 0)),n}function Wd(e,t){if(!t)return e;let n=new Map,o=new Map;for(let r of e){let s=o.get(r.sample);s?s.push(r):o.set(r.sample,[r])}for(let[r,s]of o){let a=t[r];if(a)for(let[c,i]of Li(s,a))n.set(s[c],i)}return e.map(r=>({...r,call:n.get(r)}))}export{Na as a,Ca as b,$a as c,Pa as d,J as e,oi as f,Yo as g,Wo as h,Xa as i,jo as j,Ko as k,Xc as l,k as m,N as n,Pe as o,Qt as p,R as q,Vo as r,Jo as s,K as t,Ge as u,Ye as v,en as w,on as x,Xe as y,tr as z,nr as A,sn as B,ir as C,cn as D,ln as E,We as F,ar as G,cr as H,dn as I,z as J,se as K,Oe as L,ie as M,ho as N,mo as O,go as P,xo as Q,hr as R,gr as S,xr as T,br as U,le as V,Ne as W,Ae as X,bo as Y,_t as Z,Ro as _,yr as $,Mr as aa,Er as ba,mn as ca,kc as da,Sr as ea,Nc as fa,Yc as ga,Wc as ha,qs as ia,Hs as ja,me as ka,it as la,rt as ma,zs as na,Js as oa,xe as pa,$l as qa,Pl as ra,Ll as sa,Il as ta,Bl as ua,Xl as va,ri as wa,Qn as xa,si as ya,ff as za,ai as Aa,df as Ba,uf as Ca,Zn as Da,pf as Ea,hf as Fa,li as Ga,mf as Ha,gf as Ia,xf as Ja,bf as Ka,yf as La,wf as Ma,Mf as Na,Ef as Oa,vf as Pa,Ji as Qa,na as Ra,mi as Sa,_f as Ta,Tf as Ua,ua as Va,Ht as Wa,pa as Xa,Ut as Ya,Ce as Za,jt as _a,Kt as $a,Go as ab,ft as bb,yi as cb,wi as db,Mi as eb,dt as fb,Ri as gb,_i as hb,ro as ib,Oi as jb,io as kb,Ai as lb,ki as mb,Ni as nb,Wd as ob};
2
- //# sourceMappingURL=chunk-WEGWTC52.js.map
1
+ import{a as gt,d as L,e as Re,g as I,h as Et,i as ne,j as oe,k as re,m as _e,n as Te}from"./chunk-FITPB5X6.js";import{D as Ee,E as G,F as T,G as ve,H as Se,I as te,a as Z,d as U,j as xt,k as j,l as bt,n as yt,o as we,q as wt,s as Mt,v as Me,w as ee}from"./chunk-WAMBI7OX.js";import{e as vt}from"./chunk-W6EQLQ6H.js";import{c as mt}from"./chunk-N6PQZSAX.js";import{a as ye,b as ht,c as Q}from"./chunk-TUKJRVBS.js";var se=8,Oe=34,ie=12,po=60;function ho({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function a(i){let l=Math.ceil(e/i),d=Math.floor((o-(i-1)*se)/i),u=(r-l*Oe-(l-1)*se)/l,f=(d-2*ie)/t.w,p=t.h>0?(u-2*ie)/t.h:1/0,h=n?f:Math.min(f,p),m=n?t.h:t.h*h,g=Math.floor(Math.max(po,Math.min(m+2*ie,u)));return{columns:i,width:d,height:g,scale:h,total:l*(g+Oe)+(l-1)*se}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let c=a(1);for(let i=2;i<=e;i++){let l=a(i);l.scale>c.scale&&(c=l)}return c}var mo=[{value:"",label:"None",description:"Every lifted walk in one drawing"},{value:"walk",label:"A panel per walk",description:"One panel per lifted walk, side by side"},{value:"sample",label:"A row per sample",description:"A row per sample, a column per haplotype"}];function go(e){let t=typeof e=="string"?{field:e}:e??{};return{field:t.field==="walk"||t.field==="sample"?t.field:"",domain:[...t.domain??[]],...t.columns===void 0?{}:{columns:t.columns}}}function St(e,t){let n=new Map(t.map((r,s)=>[r,s])),o=r=>n.get(r)??t.length;return e.map((r,s)=>({name:r,i:s})).sort((r,s)=>o(r.name)-o(s.name)||r.i-s.i).map(({name:r})=>r)}function xo(e,t,n=[]){let o=St(e,n),r={columns:void 0,count:e.length,cells:e.map(l=>o.indexOf(l))};if(t==="walk")return r;let s=e.map(l=>{let[d,u,f]=l.split("#"),p=Number(u);return f!==void 0&&Number.isInteger(p)&&p>=0?{sample:d,column:Math.max(0,p-1)}:void 0}),a=St([...new Set(s.flatMap(l=>l?[l.sample]:[]))],n),c=Math.max(1,...s.map(l=>l?l.column+1:1)),i=s.map(l=>l?a.indexOf(l.sample)*c+l.column:-1);return i.includes(-1)||new Set(i).size<i.length?r:{columns:c,count:a.length*c,cells:i}}var O=e=>+e.toFixed(1);function bo(e){let t=/^rgba?\(([^,]+),([^,]+),([^,)]+)(?:,([^)]+))?\)$/.exec(e.replaceAll(" ",""));if(!t)return{color:e,opacity:1};let n=t[4]===void 0?1:Number(t[4]);return{color:`rgb(${t[1]},${t[2]},${t[3]})`,opacity:n}}function Ae(e,t){let{color:n,opacity:o}=bo(t);return`${e}="${n}"${o<1?` ${e}-opacity="${O(o)}"`:""}`}var Rt=.5,_t=.25;function Di(e,t){let n=[],o=[],r=(l,d)=>{let u={d:`M${O(l)} ${O(d)}`,segments:0,x0:l,x1:l,y0:d,y1:d};return o.push(u),u},s=l=>{let d=o.at(-1)??r(l[0],l[1]);for(let u=0;u<l.length;u+=2)d.x0=Math.min(d.x0,l[u]),d.x1=Math.max(d.x1,l[u]),d.y0=Math.min(d.y0,l[u+1]),d.y1=Math.max(d.y1,l[u+1]);return d.segments++,d},a=l=>{let d=new Set;return o.map(u=>{if(!l||u.x1-u.x0>=Rt||u.y1-u.y0>=Rt)return u.d;let f=(u.x0+u.x1)/2,p=(u.y0+u.y1)/2,h=`${Math.round(f/_t)} ${Math.round(p/_t)}`;return u.segments===0||d.has(h)?"":(d.add(h),`M${O(f)} ${O(p)}h0`)}).join("")},c={canvas:void 0,fillStyle:"#000",strokeStyle:"#000",lineWidth:1,lineCap:"butt",lineJoin:"miter",beginPath(){o=[]},moveTo(l,d){r(l,d)},lineTo(l,d){s([l,d]).d+=`L${O(l)} ${O(d)}`},bezierCurveTo(l,d,u,f,p,h){s([l,d,u,f,p,h]).d+=`C${O(l)} ${O(d)} ${O(u)} ${O(f)} ${O(p)} ${O(h)}`},closePath(){let l=o.at(-1);l&&(l.d+="Z")},stroke(){let l=a(c.lineCap!=="butt");l&&n.push(`<path d="${l}" fill="none" ${Ae("stroke",c.strokeStyle)} stroke-width="${O(c.lineWidth)}" stroke-linecap="${c.lineCap}" stroke-linejoin="${c.lineJoin}"/>`)},fill(){let l=a(!1);l&&n.push(`<path d="${l}" ${Ae("fill",c.fillStyle)}/>`)},clearRect(){n.length=0},fillRect(l,d,u,f){n.push(`<rect x="${O(l)}" y="${O(d)}" width="${O(u)}" height="${O(f)}" ${Ae("fill",c.fillStyle)}/>`)}},i={width:e,height:t,style:{},getContext:()=>c};return c.canvas=i,{canvas:i,markup:()=>n.join("")}}var Tt=2,Ot=8192;function ae(e=0,t=0){let n=typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,Tt);return Math.min(n,Ot/Math.max(e,t,1))}function ke(e,t,n){let o=ae(t,n),r=Math.round(t*o),s=Math.round(n*o);(e.width!==r||e.height!==s)&&(e.width=r,e.height=s);let a=`${t}px`,c=`${n}px`;return e.style.width!==a&&(e.style.width=a),e.style.height!==c&&(e.style.height=c),o}var Wi=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1,this.fit=1;let t=e.getContext("2d");if(!t)throw new Error("Canvas 2D context not available");this.canvas=e,this.ctx=t}setErrorHandler(e){}releaseOffscreenTargets(){}resize(e,t){this.fit=ke(this.canvas,e,t)/ae()}uploadGeometry(e){this.batch=e,this.highlightedEdge=null}setNodeHighlights(e){this.nodeHighlights=e}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t}updateTransform(e){let t=this.fit;this.transform=t===1?e:{...e,scaleX:e.scaleX*t,scaleY:e.scaleY*t,translateX:e.translateX*t,translateY:e.translateY*t,dpr:e.dpr*t}}render(e){if(!this.transform)return;let n=this.ctx,{width:o,height:r}=n.canvas;e[3]<1&&n.clearRect(0,0,o,r),n.fillStyle=Re([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,o,r);let s=this.batch;if(!s)return;n.lineCap="round",n.lineJoin="round";let a=this.highlightFactor,c=this.edgeRun(s.edgeCurveRuns);for(let{color:d,items:u}of Y(s.edgeCurves,(f,p)=>({color:ce(c,p)?I(f.color,a):f.color,weight:f.thickness,last:ce(c,p)})))this.strokeCurves(u,d);let i=this.liftedStrokes(s);for(let{color:d,items:u}of Y(s.nodeStrokes,(f,p)=>{let h=i.get(p);return{color:h===void 0?f.color:I(f.color,h),weight:f.thickness,last:h!==void 0}}))this.strokeNodes(u,d);let l=this.edgeRun(s.arrowRuns);for(let{color:d,items:u}of Y(s.arrows,(f,p)=>({color:ce(l,p)?I(f.color,a):f.color,weight:0,last:ce(l,p)})))this.fillArrows(u,d)}renderHighlights(){let e=this.ctx;e.clearRect(0,0,e.canvas.width,e.canvas.height);let t=this.batch;if(!this.transform||!t)return;e.lineCap="round",e.lineJoin="round";let n=this.highlightFactor,o=At(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:c}of Y(o,i=>({color:I(i.color,n),weight:i.thickness,last:!1})))this.strokeCurves(c,a);let r=[...this.liftedStrokes(t)];for(let{color:a,items:c}of Y(r,([i,l])=>({color:I(t.nodeStrokes[i].color,l),weight:t.nodeStrokes[i].thickness,last:!1})))this.strokeNodes(c.map(([i])=>t.nodeStrokes[i]),a);let s=At(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:c}of Y(s,i=>({color:I(i.color,n),weight:0,last:!1})))this.fillArrows(c,a)}edgeRun(e){return this.highlightedEdge===null?void 0:e.get(this.highlightedEdge)}liftedStrokes(e){let t=new Map;for(let[n,o]of this.nodeHighlights){let r=e.nodeStrokeRuns.get(n);if(r)for(let s=r.start;s<r.start+r.count;s++)t.set(s,o)}return t}strokeCurves(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.curves[0];o.moveTo(s.x0*n.scaleX+n.translateX,s.y0*n.scaleY+n.translateY);for(let a of r.curves)o.bezierCurveTo(a.cx0*n.scaleX+n.translateX,a.cy0*n.scaleY+n.translateY,a.cx1*n.scaleX+n.translateX,a.cy1*n.scaleY+n.translateY,a.x1*n.scaleX+n.translateX,a.y1*n.scaleY+n.translateY)}o.stroke()}strokeNodes(e,t){let n=this.transform,o=this.ctx;o.strokeStyle=L(t),o.lineWidth=e[0].thickness*2*n.dpr,o.beginPath();for(let r of e){let s=r.points[0];o.moveTo(s.x*n.scaleX+n.translateX,s.y*n.scaleY+n.translateY);for(let a=1,c=r.points.length;a<c;a++){let i=r.points[a];o.lineTo(i.x*n.scaleX+n.translateX,i.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t){let n=this.transform,o=this.ctx;o.fillStyle=L(t),o.beginPath();for(let r of e){let[s,a,c,i]=wo(r,n);o.moveTo(s.x,s.y),o.lineTo(a.x,a.y),o.lineTo(c.x,c.y),o.lineTo(i.x,i.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},yo=.25;function wo(e,t){let n=Math.cos(e.angle),o=Math.sin(e.angle),r=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,c=e.halfWidth*t.dpr,i=r-n*a,l=s-o*a,d=a*(1-yo);return[{x:r,y:s},{x:i-o*c,y:l+n*c},{x:r-n*d,y:s-o*d},{x:i+o*c,y:l-n*c}]}function At(e,t){return t?e.slice(t.start,t.start+t.count):[]}function ce(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function Y(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let a=e[r],{color:c,weight:i,last:l}=t(a,r),d=l?o:n,u=`${c}:${i}`,f=d.get(u);f?f.items.push(a):d.set(u,{color:c,items:[a]})}return[...n.values(),...o.values()]}var Mo=50;function kt(e,t){return t>0?Math.max(1,e/t):Mo}function Eo(e){let t=new Set,n=1/0,o=-1/0;for(let r of e)t.add(r.minY),n=Math.min(n,r.minY),o=Math.max(o,r.minY);return t.size>1?(o-n)/(t.size-1):void 0}function vo(e,t,n){let o=kt(t,e.length);return{x:o,y:n>0?kt(n,e.length):Eo(e)??o}}function Nt(e,t,n,o){return e===void 0?vo(t,n,o):typeof e=="number"?{x:e,y:e}:e}function So(e,t,n){let o=e.get(t);o||(o=new Map,e.set(t,o));let r=o.get(n);return r||(r=[],o.set(n,r)),r}function Ct(e,t,n,o,r,s,a){let c=Math.floor(n/t.x),i=Math.floor(r/t.x),l=Math.floor(o/t.y),d=Math.floor(s/t.y);for(let u=c;u<=i;u++)for(let f=l;f<=d;f++)So(e,u,f).push(a)}function $t(e,t,n,o,r,s){let a=Math.floor((n-r)/t.x),c=Math.floor((n+r)/t.x),i=Math.floor((o-s)/t.y),l=Math.floor((o+s)/t.y),d=[],u=new Set;for(let f=a;f<=c;f++){let p=e.get(f);if(p)for(let h=i;h<=l;h++){let m=p.get(h);if(m)for(let g of m)u.has(g)||(u.add(g),d.push(g))}}return d}var Pt=class{constructor(e,t){this.cells=new Map;let n=[],o=0,r=0;for(let[s,a]of Object.entries(e))for(let c=0;c<a.length-1;c++){let i=a[c],l=a[c+1],d=Math.min(i.x,l.x),u=Math.min(i.y,l.y),f=Math.max(i.x,l.x),p=Math.max(i.y,l.y);o+=f-d,r+=p-u,n.push({entry:{nodeId:s,segmentIdx:c},minX:d,minY:u,maxX:f,maxY:p})}this.cellSize=Nt(t,n,o,r);for(let s of n)Ct(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return $t(this.cells,this.cellSize,e,t,n,o)}},Lt=class{constructor(e,t,n,o,r,s,a=0,c,i=!1){this.cells=new Map,this.edgeCurves=Et(e,t,o,s,a,c,i);let l=[],d=0,u=0;for(let f=0;f<t.edges.length;f++){let p=t.edges[f],h=e[p.from],m=e[p.to],g=this.edgeCurves.get(f);if(h?.length&&m?.length&&g){let{minX:x,minY:y,maxX:M,maxY:w}=wt(g),v=p.pathIds?.length??0;if(n&&v>0){let E=0,b=0;for(let S of ee(h,m,v,o))E=Math.max(E,Math.abs(S.x)),b=Math.max(b,Math.abs(S.y));x-=E,y-=b,M+=E,w+=b}d+=M-x,u+=w-y,l.push({ei:f,minX:x,minY:y,maxX:M,maxY:w})}}this.cellSize=Nt(r,l,d,u);for(let f of l)Ct(this.cells,this.cellSize,f.minX,f.minY,f.maxX,f.maxY,f.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,o=n){return $t(this.cells,this.cellSize,e,t,n,o)}};function Dt(e,t,n,o,r,s){let a=r-n,c=s-o,i=a*a+c*c;if(i===0)return Math.hypot(e-n,t-o);let l=Math.max(0,Math.min(1,((e-n)*a+(t-o)*c)/i));return Math.hypot(e-(n+l*a),t-(o+l*c))}function Ro(e,t,n,o,r,s,a,c,i,l){let d=1/0,u=20,f=n,p=o;for(let h=1;h<=u;h++){let m=h/u,g=1-m,x=g*g*g*n+3*g*g*m*r+3*g*m*m*a+m*m*m*i,y=g*g*g*o+3*g*g*m*s+3*g*m*m*c+m*m*m*l;d=Math.min(d,Dt(e,t,f,p,x,y)),f=x,p=y}return d}function _o(e,t,n){return Ro(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function It(e,t,n,o=1){let r=1/0;for(let s of n){let a=_o(e,t,o===1?s:{x0:s.x0,y0:s.y0*o,cx0:s.cx0,cy0:s.cy0*o,cx1:s.cx1,cy1:s.cy1*o,x1:s.x1,y1:s.y1*o});a<r&&(r=a)}return r}var Bt=new WeakMap;function qt(e,t){let n=Bt.get(e);if(n?.version===t)return n.index;let o=new Pt(e);return Bt.set(e,{version:t,index:o}),o}var Xt=new WeakMap;function To(e,t,n,o,r,s,a,c=!1){let i=Xt.get(e);if(i?.graph===t&&i.drawPaths===n&&i.scaleX===o.scaleX&&i.scaleY===o.scaleY&&i.version===r&&i.deletions===s&&i.routes===a&&i.stranded===c)return i.index;let l=new Lt(e,t,n,o,void 0,s,r,a,c);return Xt.set(e,{graph:t,drawPaths:n,scaleX:o.scaleX,scaleY:o.scaleY,version:r,index:l,deletions:s,routes:a,stranded:c}),l}var Oo=5;function ea(e,t,n,o,r=0,s){let a=Me(o),c=qt(e,r),i=p=>Math.max(Oo,p)/o.scaleX,l=i(s?.maxHalfWidthPx??0),d=c.query(t,n,l,l/a),u=null,f=1/0;for(let{nodeId:p,segmentIdx:h}of d){let m=e[p],g=Dt(t,n*a,m[h].x,m[h].y*a,m[h+1].x,m[h+1].y*a);g<f&&g<i(s?.halfWidthPx(p)??0)&&(f=g,u=p)}return u}function Ao(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,a=1;for(let[c,i]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(c===0){if(i<0)return!1}else c<0?s=Math.max(s,i/c):a=Math.min(a,i/c);return s<=a}function Ft(e,t,n=0){let o=qt(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let a=new Set,c=o.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:i,segmentIdx:l}of c){let d=e[i];!a.has(i)&&Ao(r(d[l]),r(d[l+1]),s)&&a.add(i)}return a}}function ta(e,t,n,o,r,s,a=0,c,i,l,d=!1){let u=Me(r),f=10/r.scaleX,p=To(e,t,s,r,a,c,l,d),h=p.query(n,o,f,f/u),m=null,g=f;for(let x of h){let y=t.edges[x],M=e[y.from],w=e[y.to];if(!M?.length||!w?.length||i?.has(x))continue;let v=y.pathIds?.length??0,E=p.getCurves(x);if(!E)continue;let b;if(!s||v===0)b=It(n,o*u,E,u);else{let S=1/0;for(let _ of ee(M,w,v,r)){let F=_.x===0&&_.y===0?E:Mt(E,_.x,_.y),P=It(n,o*u,F,u);P<S&&(S=P)}b=S}b<g&&(g=b,m=x)}return m}var Gt=3.4,Ne=6,ko=18,No=2,Co=3,$o=xt+bt;function Yt(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],r=s=>+(s/n).toFixed(n===1?0:1);return`${r(e.covered*t)} of ${r(t)} ${o}`}function Wt(e,t,n,o){let r=n/2;return Ht(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:a,y:c}=t(s.at),i=Yt(s);return{item:s,x:a,y:c+n+ko,text:i?`${s.gene.name} \xB7 ${i}`:s.gene.name,fallback:i?`${s.gene.name} \u2026`:void 0,stack:No,fits:l=>[...o({x0:l.x0-r,x1:l.x1+r,y0:l.y0-r,y1:l.y1+r})].every(d=>s.nodeIds.has(d))}})}function Ht(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Po(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:a}=e.axisScale,c={width:t,height:n},i=b=>({x:b.x*s+o,y:b.y*a+r}),l=e.drawnRowLabels.map(({label:b,y:S})=>Ee(b,S*a+r)),d=e.referenceStripZonePx??0;d>0&&l.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&l.push({x0:t-Ne-e.legendSize.width,x1:t,y0:0,y1:d+Ne+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*j*1.2,y0:0,y1:44});let u=yt(c,l),f=e.drawnRowLabels.length>0,p=f?Math.min(...e.drawnRowLabels.map(b=>b.y)):1/0,h=e.contigThickness*Gt,m=(b,S)=>{let{x:_,y:F}=i({x:b.labelAt.x,y:Math.min(b.labelAt.y,p)}),P=F-h/2-S;return{x:_,y:f?Math.max(P,$o):P}},g=Ht(e.bubbleHalos.filter(b=>!b.tick),b=>b.whole?-1:b.members),x=we(g.map(b=>({item:b,...m(b,6),text:b.label,fallback:b.label.includes(",")?b.label.split(",")[0]:void 0,stack:Co})),c,u),y=e.bubbleHalos.filter(b=>b.tick&&!b.whole).map(b=>({item:b,...m(b,2)})).filter(b=>b.x>=0&&b.x<=t&&b.y>=0&&b.y<=n),M=we(Wt(e.genePins,i,e.contigThickness,Ft(e.nodePositions??{},{scaleX:s,scaleY:a,translateX:o,translateY:r},e.positionsVersion)),c,u),w=e.nodePositions&&e.labelsNodeSizes?ve({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:o,translateY:r,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},v=te(w.deletions,u),E=te(w.nodes,u,Se(t,n));return{bubbles:x,ticks:y,genes:M,sizes:[...v,...E]}}var X=JBrowseExports.mobx,le=e=>X!=null&&e in Object(X)?X[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from 'mobx' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var ya=le("autorun");var wa=le("computed");var Ma=le("reaction");var Ea=le("untracked");var va=X&&X.__esModule?X.default:X;function Lo(e){return e.id.endsWith("-")?"-":"+"}function Io(e,t){return t===Lo(e)?e.id:`-${e.id}`}function Bo(e,t){let n=e.map(()=>{}),o=0,r=0;for(;r<e.length&&e[r]!==void 0;r++)n[r]=o,o+=e[r];let s=t;for(let a=e.length-1;a>r&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function Xo(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=Bo(t,e.pathLength),r=o.flatMap((f,p)=>f===void 0?[]:[p]),s=f=>o[r[f]],a=f=>s(f)+t[r[f]],c=0,i=(f,p=!1)=>{for(;c<r.length&&a(c)<f;)c++;for(let h=c;h<r.length&&s(h)<=f;h++){let m=a(h);if(f<m||p&&f===m)return{s:r[h],local:f-s(h),room:m-f}}},l=f=>{for(let p=c;p<r.length;p++)if(s(p)>f)return s(p)-f;return 1/0},d=(f,p)=>{let h=n[f],m=h.at(-1);p.type==="substitution"&&m?.type==="substitution"&&m.pos+m.seq.length===p.pos?m.seq+=p.seq:h.push(p)},u=e.pathStart;for(let f of mt(e.cs))if(f.op==="match")u+=f.length;else if(f.op==="substitution"){let p=i(u);p&&d(p.s,{type:"substitution",pos:p.local,seq:f.seq}),u+=1}else if(f.op==="insertion"){let p=i(u,u===e.pathEnd);p&&d(p.s,{type:"insertion",pos:p.local,seq:f.seq})}else{let p=f.length;for(;p>0;){let h=i(u),m=Math.min(p,h?h.room:l(u));h&&d(h.s,{type:"deletion",pos:h.local,length:m}),u+=m,p-=m}}return n}function _a(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let a=s.path.map(d=>o.get(d.name)),c=a.flatMap((d,u)=>d?[u]:[]),i=c[0],l=c.at(-1);if(i!==void 0&&l!==void 0){let d=Xo(s,a.map(p=>p?.length)),u=c.map(p=>Io(a[p],s.path[p].strand)),f=a[l].length;r.push({id:n+r.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:c.map((p,h)=>({nodeName:u[h],mismatches:d[p]})),firstNodeOffset:i===0?s.pathStart:0,finalNodeCoverLength:l===s.path.length-1?f-(s.pathLength-s.pathEnd):f,mapping_quality:s.mappingQuality===255?void 0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return r}var Do=["#6baed6","#4292c6","#2171b5","#08519c"],qo=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function Ut(e){let t=e.is_reverse?qo:Do;return t[e.id%t.length]}function fe(e){return`hsl(${e}, 70%, 50%)`}function Ce(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*oe}var Fo=30;function jt({start:e,bp:t,reversed:n},o){let r=Ce(e,o),s=Ce(e+t,o);if(s-r<1)return[(r+s)/2];let a=Math.ceil((s-r)/Fo);return Array.from({length:a+1},(c,i)=>Ce(e+t*(n?a-i:i)/a,o))}var $e=Array.from({length:7},(e,t)=>({offset:t/6,color:fe(t/6*oe)})),Kt=`linear-gradient(to right, ${$e.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function R(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function zt(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function Go(e){return zt(e).replaceAll('"',"&quot;")}function Yo(e){if(typeof e=="string")return zt(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${Go(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(Yo).join("")}</${e.tag}>`}var Xe="#2f8fd6",De="#8e3fbf",qe="#bdbdbd",K="#1c1c22",Fe=12,Ge=4,Ie=12,Wo=6,Ho=3;function B(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Uo(e){let t=Math.abs(e);return`${e>0?"+":"\u2212"}${t<1e3?`${t} bp`:B(t)}`}function Pe(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function Vt(e,t,n,o){let{bp:r,gapBp:s,complete:a,stop:c}=e;if(!t)return`${B(r)}${Pe(r,n)}`;let i=s>0?` \xB7 ${B(s)} outside the cut`:"",l=o?` \xB7 called ${B(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(a){let f=r-t.bp,p=f===0?"":` (${Uo(f)})`;return`${B(r)}${Pe(r,n)}${p}${i}${l}`}let d=n?"repeat":"window";if(c?.contigEnds&&r===0)return`contig ends ${c.shortBp>0?`${B(c.shortBp)} before`:"at"} the ${d}${l}`;let u=c?c.contigEnds?`contig ends inside the ${d}`:"does not rejoin the reference within the cut":"partial walk";return`\u2265 ${B(r)}${Pe(r,n)} \xB7 ${u}${i}${l}`}function Jt(e,t,n){let o=t+6;return o+e.length*j<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function Qt(e,t,n){if(t*n<Ho)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function Zt(e,t){if(e.gap)return{fill:qe};if(!t)return{fill:e.onReference?Xe:De};if(e.referenceStart===void 0)return{fill:re};let n=jt({...e,start:e.referenceStart},t);return n.length===1?{fill:fe(n[0])}:{stops:n.map(fe)}}function Be(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function jo(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function Ko(e,t){let n=new Map;for(let o of e){let r=t.get(o.name);if(!o.axis||!r)continue;let s=o.axis,a=({start:c,end:i})=>({start:Math.max(0,c),end:Math.min(o.bp,i)});n.set(o.name,r.map(c=>({name:c.name,...a(Be(s,c.start,c.end)),exons:c.exons.map(i=>a(Be(s,i.start,i.end))).filter(i=>i.end>i.start)})).filter(c=>c.end>c.start).sort((c,i)=>c.start-i.start))}return n}var zo=9,Vo=5.2,Jo=8,en=(e,t)=>Math.min(2,(e-t)/2-1);function tn(e,t){return en(e,t)>=1}function nn(e,t,n,{rowPx:o=Z,barPx:r=Fe}={}){if(!tn(o,r))return[];let s=en(o,r),a=e.map(l=>{let d=t(l.start);return{g:l,x:d,w:Math.max(2,t(l.end)-d)}}),c=[],i=new Set((r>=Jo?[...a]:[]).sort((l,d)=>l.w-d.w).filter(({g:l,x:d,w:u})=>{let f=l.name.length*Vo/2,p=[d+u/2-f,d+u/2+f];return 2*f>u+6||c.some(([h,m])=>p[0]<m+2&&p[1]>h-2)?!1:(c.push(p),!0)}));return a.map(l=>({name:l.g.name,x:l.x,y:n-r/2-s,w:l.w,h:r+2*s,exons:l.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:i.has(l)?{x:l.x+l.w/2,y:n+3,size:zo}:void 0}))}var Le=e=>`${e} row${e===1?"":"s"}`;function Qo(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??Kt,ramp:!0}:{kind:"bar",fill:Xe},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?re:De},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(o=>o.gapBp>0)&&n.push({swatch:{kind:"gap",fill:qe},label:"walked outside the cut"}),t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):t.genes&&(n.push({swatch:{kind:"gene"},label:"gene"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${Le(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${Le(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${Le(t.genes.unread)}`,note:!0})),n}var on="#111",rn="#9e9e9e",Ye="#c62828";function sn(e){return e.agrees===!1?Ye:e.spanningReads===0?rn:on}function Zo(e,t,n,o="walk-key"){let r=0,s=e.flatMap((a,c)=>{let i=`${o}-ramp-${c}`,l=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?R("linearGradient",{id:i},...$e.map(f=>R("stop",{offset:f.offset,"stop-color":f.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?R("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:K,"stroke-width":1.5}):R("rect",{x:r,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Ge:8,rx:2,fill:l?`url(#${i})`:a.swatch.fill}),u=R("text",{x:a.note?r:r+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return r+=(a.note?0:23)+a.label.length*j+16,[l,d,u].filter(f=>f!==void 0)});return{width:r,tree:R("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function er(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(Z,o>=1?Math.floor(o):o));return{rowPx:r,barPx:r<=3?r:Math.max(3,Math.round(r*.6)),labelled:r>=Ie,readouts:r>=Ie}}function an(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let c=0,i=0;for(let u of r)u.onReference?c+=u.bp:i+=u.bp;let l=c>=i,d=r.find(u=>u.onReference===l);o.push({start:r[0].start,bp:c+i,onReference:l,referenceStart:l?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}r=[]}},a=0;for(let c of e){if(c.gap||c.bp>=n){s(),a=0,o.push(c);continue}r.push(c),a+=c.bp,a>=n&&(s(),a=0)}return s(),o}function tr(e,t,n){return R("g",{class:"row-gene","data-testid":"graph-walk-gene"},R("title",{},e.name),...e.exons.map(o=>R("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:K,opacity:.35})),R("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:K,"stroke-width":1.5}),e.label&&R("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:K,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function z(e,t,n={}){let o=m=>m*t.scaleX+t.translateX,r=t.rowPx??Z,s=t.barPx??Fe,a=Math.min(3,Math.max(0,(r-s)/2)),c=m=>m*r*t.scaleY+t.translateY,{origin:i,unit:l,reference:d,rows:u}=e,f=m=>o(i+m),p=n.idPrefix??"walkrow",h=(m,g)=>{let x=c(g);if(x<-s||x>t.height+s)return;let y=an(m.runs,t.scaleX).flatMap(S=>{let _=Zt(S,n.ramp),F=S.gap?Math.min(Ge,s):s,P=`${p}-${g}-${S.start}`,pt=R("rect",{x:f(S.start),y:x-F/2,width:Math.max(1,S.bp*t.scaleX),height:F,fill:"stops"in _?`url(#${P})`:_.fill});return"stops"in _?[R("linearGradient",{id:P},..._.stops.map((fo,uo)=>R("stop",{offset:uo/(_.stops.length-1),"stop-color":fo}))),pt]:[pt]}),M=l&&s>=Wo?Qt(m.bp,l,t.scaleX).map(S=>R("line",{x1:f(S),x2:f(S),y1:x-s/2,y2:x+s/2,stroke:"white","stroke-width":1})):[],{call:w}=m,v=Vt(m,g===0?void 0:d,l,w),E=Jt(v,f(m.bp),t.width),b=t.readouts??!0;return R("g",{"data-testid":g===0?"graph-walk-reference":"graph-walk-row"},...y,...M,...nn(n.rowGenes?.get(m.name)??[],f,x,{rowPx:r,barPx:s}).map(S=>tr(S,x,s)),w&&R("rect",{"data-testid":"graph-walk-call",x:f(w.bp)-1,y:x-s/2-a,width:2,height:s+2*a,fill:sn(w)}),b&&R("text",{x:E.x,y:x+4,"font-family":"sans-serif","font-size":11,fill:w?.agrees===!1?Ye:"#333",stroke:E.halo?"white":void 0,"stroke-width":E.halo?3:void 0,"paint-order":"stroke","text-anchor":E.anchor},v))};return R("g",{},...[d,...u].map(h))}var nr=10;function or(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=nr*(r.end-r.start)&&(n===0?r.start<=e.start&&e.start<=r.end:Math.min(e.end,r.end)-Math.max(e.start,r.start)>=n/2))}var rr=40;function sr(e,t){let n=T(e),o=T(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function We(e){return e>=vt?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function ir(e,t=[]){let n=ar(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function ar(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:a,inversion:c}=e,i=sr(o,r);if(a>=rr)return{kind:"superbubble",label:`${i} superbubble, ${a} segments, ${We(s)}${c?", inv":""}`};if(c)return{kind:"inversion",label:`${T(r)} inv`};if(e.offReference)return o===r?cn(o):{kind:"complex",label:`${i}, ${We(s)}`};let l=r!==o?or(e,t):void 0;if(l){let u=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${i} repeat array${u}, ${We(s)}`}}let d=s>2?`, ${s} alleles`:"";return o===r&&o===n?cn(n):n===0||o===n?{kind:"insertion",label:`\u2264${T(r-n)} ins${d}`}:r===n?{kind:"deletion",label:`${T(n-o)} del${d}`}:{kind:"complex",label:`${T(n)} ref \u2192 ${i}, ${s} alleles`}}function cn(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${T(e)} sub`}}var cr={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},lr={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function fr(e){return e.segments.split(",").filter(Boolean)}function He({graph:e,layout:t}){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach((r,s)=>{let a=n.get(r.name);if(r.order>=0&&a&&Q(a)){let{refName:c,start:i}=a.stable;(o.get(c)??o.set(c,[]).get(c)).push({name:r.name,index:s,bp0:i,bp1:i+a.length,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,a)=>s.bp0-a.bp0);return o}function de(e,t,n=!1){let o=0,r=e.length-1;for(;o<r;){let c=o+r>>1,i=e[c].bp1;(n?i<t:i<=t)?o=c+1:r=c}let s=e[o];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function ue(e,t,n){let o=de(e,t),r=de(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function dr(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var ln=5,ur=10,pr=110,hr=3;function fn(e){return e?"#b0b0b8":"#55555c"}function mr(e){let t=10**Math.floor(Math.log10(e)),n=e/t;return(n<=1?1:n<=2?2:n<=5?5:10)*t}function dn(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+ur)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function gr(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let a=t(r.x0),c=t(s.x1),i=s.bp1-r.bp0;if(c<=a||i<=0)return;let l=mr(i/(c-a)*pr),d=[],u=[];for(let f=Math.ceil(r.bp0/l)*l;f<=s.bp1;f+=l){let p=Math.round(t(de(e,f)))+.5;if(p>=0&&p<=n){d.push(p);let h=f.toLocaleString("en-US");u.push({text:h,at:p,width:o(h)})}}return{spans:[{x0:a,x1:c}],ticks:d,labels:dn(u)}}function xr(e,t,n,o){let r=e.map(h=>({box:h,s0:t(h.x0),s1:t(h.x1)})).filter(({s0:h,s1:m})=>m>=0&&h<=n),s=r[0],a=r.at(-1);if(!s||!a)return;let c=(h,m)=>({text:h,at:m,width:o(h)}),i=(h,m)=>c(h.toLocaleString("en-US"),m),l=[],d=[],u=[],f=[];for(let{box:h,s0:m,s1:g}of r){l.push({x0:m,x1:g}),d.push(Math.round(m)+.5),g-m>=hr&&d.push(Math.round(g)+.5);let x=c(T(h.bp1-h.bp0),(m+g)/2);x.width<=g-m&&u.push(x),h!==s.box&&f.push(i(h.bp0,m))}let p=[i(s.box.bp0,s.s0),i(a.box.bp1,a.s1)];return{spans:l,ticks:d,labels:dn([...p,...u,...f])}}function un(e,t,n,o,r=!1){return(r?gr:xr)(e,t,n,o)}function br(e,t,n,o,r=!1){let{x:s,width:a,darkMode:c}=n;e.font="10px sans-serif";let i=un(t,s,a,u=>e.measureText(u).width,r);if(!i)return;let l=fn(c),d=o+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:f}of i.spans)e.moveTo(Math.max(0,u),d),e.lineTo(Math.min(a,f),d);for(let u of i.ticks)e.moveTo(u,o),e.lineTo(u,o+ln);e.stroke();for(let{text:u,at:f}of i.labels)e.fillText(u,f,o+ln+2)}function yr(e,t,n,o){let r=[];for(let s of e){let a=n(s.x0),c=n(s.x1);c>=0&&a<=o&&r.push({node:s.name,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:c})}return r}var wr=3;function Mr(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,a=wr;for(let c of e){let i=c.top0+(c.bottom0-c.top0)*r,l=c.top1+(c.bottom1-c.top1)*r,d=Math.max(0,Math.min(i,l)-n,n-Math.max(i,l));d<a&&(a=d,s=c.node)}return s}function pn(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.top1,0),e.lineTo(t.bottom1,n),e.lineTo(t.bottom0,n),e.closePath()}function hn(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function Er(e,t,n,{highlightNode:o,darkMode:r}){if(n<=0||t.length===0)return;let s=r?"255,255,255":"0,0,0";e.beginPath();for(let a of t)pn(e,a,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let a of t)hn(e,a,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke(),mn(e,t,n,o)}function mn(e,t,n,o){let r=n>0&&o?t.find(s=>s.node===o):void 0;r&&(e.beginPath(),pn(e,r,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),hn(e,r,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function vr(e,t,n){let o=0,r=e.length-1;for(;o<r;){let s=o+r+1>>1;e[s].bp0<=t?o=s:r=s-1}return[e[o],e[o-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function kc(e,t){let{layout:n}=e,o=[...He(e).values()].flat().sort((s,a)=>s.bp0-a.bp0),r=[];for(let s of n.tracks){let a=s.name?t.get(s.name):void 0;if(a?.length){let c=new Map;for(let i of s.path)i.node!==null&&i.y!==void 0&&!c.has(i.node)&&c.set(i.node,i.y);for(let i of a){let l=vr(o,i.start,c);if(l){let{bp0:d,bp1:u,x0:f,x1:p,index:h}=l,m=g=>f+(Math.min(g,u)-d)/(u-d)*(p-f);r.push({x0:m(i.start),x1:m(i.end),y:c.get(h),height:s.width})}}}}return r}function Sr(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function Nc(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=Sr(s),e.beginPath();for(let a of t){let c=n(a.x0),i=Math.max(n(a.x1),c+1);if(i>=0&&c<=r){let l=o(a.y);e.rect(c,l,i-c,o(a.y+a.height)-l)}}e.fill()}}function gn(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}var Rr=new Set(["_gbwt_ref","unknown"]);function xn(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||Rr.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var Nn=!1;function H(...e){Nn&&console.log(...e)}var _r=["read_group","sample_name"],Bc=[..._r,"haplotype_sample"];function Tr({layers:e,coarsenedReadView:t=!1,showReads:n=!0},o){if(e!==void 0)return e;let r=t&&n,s=a=>a?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(r&&!o)},{data:"reads",...s(r&&o)}]}function bn(e,t){return e.find(n=>n.data===t)?.stat}function Or(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:Tr(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15,freqWidth:e.freqWidth??"log"}}function Cn(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:gn(),imageBounds:{minX:0,maxX:0,minY:0,maxY:0},trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function Xc(e,t,n=[],o={}){let r=Ar(e,t,n,o);return r&&kr(r,o)}var $n=new WeakMap;function Ar(e,t,n=[],o={}){let r=Cr(e,t,n,o);if(r===void 0)return;let s=Pn(r,r.tracks,r.reads,"measure");return s.nodes.forEach((a,c)=>{a.order>=0&&(r.nodes[c].x=a.x)}),$n.set(r,s),r}function kr(e,t={}){return Nr(e,Ir(e,t.facet),$r(e,t))}function Nr(e,t,n,o){let r=$n.get(e);return r!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?r:Pn(e,t,n,"topology",o)}function Cr(e,t,n,o){let r=Cn(Or(o,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,a)=>{s.seq??="",s.sequenceLength??=s.seq.length,r.nodes[a+1]=s}),r.tracks=structuredClone(t),r.reads=r.config.showReads?structuredClone(n.filter(s=>s.is_secondary!==!0)):[];for(let s=r.tracks.length-1;s>=0;s-=1){let a=r.tracks[s];if(a.type??="haplotype",a.hidden===!0){r.tracks.splice(s,1);continue}a.indexOfFirstBase!==void 0&&(r.trackForRuler=a.name)}if(r.tracks.length!==0)return Xr(r,0),r.nodeMap=En(r),W(r,r.tracks),W(r,r.reads),An(r),r.config.mergeNodes&&(vn(r),je(r),ze(r),Os(r),r.nodeMap=En(r),An(r),W(r,r.tracks),W(r,r.reads)),vn(r),is(r),je(r),as(r),je(r),ze(r),W(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:rs(r),trackForRuler:r.trackForRuler}}}function $r(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:o}){let r=n?new Set(n):null;return e.reads.filter(s=>(s.mapping_quality??0)>=t&&(r===null||s.name!==void 0&&r.has(s.name))&&(o===void 0||Pr(o,s)))}function Pr(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Lr(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Ir(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Lr(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Br(o)===t.key)}function Br(e){return xn(e.name)?.sample??null}function Pn(e,t,n,o,r={}){let s=Cn(e.options);e.nodes.forEach((f,p)=>{s.nodes[p]={...f}}),s.tracks=t.map(f=>({...f})),s.reads=n.map(f=>({...f})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:a,ignoreStrand:c}=s.config,i=r.haplotypes??Xn,l=bn(a,"haplotypes")==="coarsen"?vs(s,i):void 0;l!==void 0&&(s.tracks=[l.ref]),ys(s),us(s),Dr(s);let d=bn(a,"reads")==="coarsen"&&s.reads.length>0?Dn(s,s.reads,"read",r.reads??i+(l?.bands.length??0)):void 0;d!==void 0&&(s.reads=d.bands);let u={};for(let[f,p,h]of[["haplotypes","haplotype",l],["reads","read",d]])h!==void 0&&(ze(s,h.bands),W(s,h.bands),u[f]={unit:p,total:h.total,reverse:!c&&h.bands.some(m=>m.is_reverse)});return l!==void 0&&(s.reads=l.bands.concat(s.reads)),s.reads.length>0?(Fr(s),s.tracks=s.tracks.concat(s.reads)):s.nodes.forEach(f=>{f.incomingReads=[],f.outgoingReads=[],f.internalReads=[]}),o==="measure"&&ls(s),Es(s),H("Tracks:",s.tracks),H("Nodes:",s.nodes),H("Lane assignment:",s.assignments),Zr(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:s.imageBounds,maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:u}}function k(e){return e.startsWith("-")}function N(e){return k(e)?e.substring(1):e}function Ln(e){return k(e)?e:`-${e}`}function Ve(e){return k(e)?N(e):Ln(e)}function yn(e){return e>0}function Xr(e,t){let n=new Set,o=new Set;for(let r of e.tracks[t].sequence)k(r)?o.has(N(r))||n.add(N(r)):o.add(r);if(n.size!==0){for(let{sequence:r}of[...e.tracks,...e.reads])for(let s=0;s<r.length;s+=1)n.has(N(r[s]))&&(r[s]=Ve(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Je(r.seq))})}}function Dr(e){e.nodesPerOrder=[];for(let n=0;n<=e.maxOrder;n+=1)e.nodesPerOrder[n]=[];let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&wn(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(o=>{wn(t,o.order,(o.y??0)+n.width)})}),e.nodes.forEach((n,o)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(o))})}function wn(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var pe=7;function qr(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{if((t.width===void 0||t.width===0)&&(t.width=pe),t.path.length===1){let o=t.path[0].node;o!==null&&e.nodes[o].internalReads.push(n)}else t.path.forEach((o,r)=>{if(r===0){let s=t.path[0].node;s!==null&&e.nodes[s].outgoingReads.push([n,r])}else{let s=o.node;s!==null&&e.nodes[s].incomingReads.push([n,r])}})})}function Fr(e){e.reads.forEach(c=>{c.path=In(e,c)}),qr(e);let t=e.nodes.filter(c=>c.order>=0);t.sort(Ze);let n=new Map;for(let c=0;c<e.reads.length;c++){let i=e.reads[c],l=i.haplotypeShare===void 0?1:0,d=i.sourceTrackID,u=`${l}:${d}`,f=n.get(u);f===void 0?n.set(u,{layer:l,source:d,reads:new Set([c])}):f.reads.add(c)}let o=[...n.values()].sort((c,i)=>c.layer-i.layer||c.source-i.source),r=o.length>1?pe:0;t.forEach(c=>{for(let{reads:i}of o)Gr(e,i,c,r)});let s=Kr(e),a=[];e.reads.forEach((c,i)=>{let l=c.path.length,d=new Array(l),u;for(let h=0;h<l;h++){h===0?d[h]=void 0:d[h]=u??c.path[0];let m=c.path[h];m.node!==null&&m.node&&(u=m)}let f=new Array(l),p;for(let h=l-1;h>=0;h--){h===l-1?f[h]=void 0:f[h]=p??c.path[l-1];let m=c.path[h];m.node!==null&&m.node&&(p=m)}c.path.forEach((h,m)=>{if(h.y===void 0){let g=d[m],x=f[m],y=!!(x&&g&&(g.order>x.order||x.order===g.order&&x.isForward===g.isForward));h.betweenCycleReverseTraversal=y,a.push({readIndex:i,pathIndex:m,previousY:g?.y,previousNode:g?.node})}})}),a.sort((c,i)=>Wr(e,c,i)),a.forEach(c=>{let i=e.reads[c.readIndex],l=i.path[c.pathIndex];l.y=s[l.order],s[l.order]+=i.width}),H("Reads:",e.reads)}function Gr(e,t,n,o){let r=n.incomingReads.filter(([h])=>t.has(h)),s=n.outgoingReads.filter(([h])=>t.has(h)),a=n.internalReads.filter(h=>t.has(h));r.length===0&&s.length===0&&a.length===0&&(o=0);let c=n.y+n.contentHeight+o*2,i=r.map(h=>{let[m,g]=h,x=e.reads[m].path,y=g+1,M;for(let w=1;w<=g;w++){let v=x[g-w]?.y;if(v!==void 0){y=w,M=v;break}}return{entry:h,decisionStep:y,y:M}});i.sort(Yr),r=i.map(h=>h.entry);let l=c,d=new Map;r.forEach(h=>{let m=e.reads[h[0]];m.path[h[1]].y=l,Mn(d,m,h[1],l,n),l+=m.width});let u=l;s.sort((h,m)=>Hr(e,h,m));let f=new Map;l=c,s.forEach(h=>{let m=e.reads[h[0]],g=m.firstNodeOffset??0;m.path[h[1]].y=l,f.set(l,g);let x=d.get(l);x===void 0||x+1<=g?(l+=m.width,u=Math.max(u,l)):(d.set(l,0),r.forEach(y=>{let M=e.reads[y[0]],w=M.path[y[1]];w.y!==void 0&&w.y>=l&&(w.y+=m.width,Mn(d,M,y[1],w.y,n))}),l+=m.width,u+=m.width)}),a.sort((h,m)=>jr(e,h,m)),a.forEach(h=>{let m=e.reads[h],g=m.firstNodeOffset??0,x=m.finalNodeCoverLength??0;for(l=c;g<(d.get(l)??-1/0)+2||x>(f.get(l)??1/0)-3;)l+=m.width||pe;m.path[0].y=l,d.set(l,x),u=Math.max(u,l)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,xs(e,n,p)}function Yr(e,t){return e.decisionStep!==t.decisionStep?e.decisionStep-t.decisionStep:e.y===void 0||t.y===void 0?(e.y===void 0?0:1)-(t.y===void 0?0:1):e.y-t.y}function Mn(e,t,n,o,r){n===t.path.length-1?e.set(o,t.finalNodeCoverLength??0):e.set(o,r.sequenceLength)}function Wr(e,t,n){let o=e.reads[t.readIndex],r=e.reads[n.readIndex],s=o.path[t.pathIndex],a=r.path[n.pathIndex];if(s.order!==a.order)return s.order-a.order;if(o.sourceTrackID!==r.sourceTrackID)return o.sourceTrackID-r.sourceTrackID;if(t.previousNode&&n.previousNode){let u=e.nodes[t.previousNode],f=e.nodes[n.previousNode];if(u&&f&&u.order!==f.order)return u.order-f.order}let c=t.previousY??0,i=n.previousY??0,l=s.betweenCycleReverseTraversal===!0,d=a.betweenCycleReverseTraversal===!0;return l!==d?l?1:-1:l?i-c:c-i}function Hr(e,[t,n],[o,r]){let s=e.reads[t],a=e.reads[o],c,i,l=s.path.length-1,d=a.path.length-1;for(;c===void 0&&l>=0;)c=s.path[l]?.y,l-=1;for(;i===void 0&&d>=0;)i=a.path[d]?.y,d-=1;if(c!==void 0&&i!==void 0)return c-i;let u=s.path[n]?.node,f=a.path[r]?.node,p=typeof u=="number"?e.nodes[u]:null,h=typeof f=="number"?e.nodes[f]:null;for(;p&&h&&p===h;){if(n<s.path.length-1){for(n+=1;s.path[n]?.node===null;)n+=1;let g=s.path[n]?.node;p=typeof g=="number"?e.nodes[g]:null}else p=null;if(r<a.path.length-1){for(r+=1;a.path[r]?.node===null;)r+=1;let g=a.path[r]?.node;h=typeof g=="number"?e.nodes[g]:null}else h=null}if(p)return h?Ze(p,h):1;if(h)return-1;let m=(s.firstNodeOffset??0)-(a.firstNodeOffset??0);return m!==0?m:(s.finalNodeCoverLength??0)-(a.finalNodeCoverLength??0)}function Ur(e,t){let n=e.path,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let a=n[r],c=o[s],i=a.order,l=c.order;if(i===l&&a.node&&c.node)return(c.y??0)-(a.y??0);i<l?r+=1:(i>l||(r+=1),s+=1)}return 0}function jr(e,t,n){let o=e.reads[t],r=e.reads[n],s=o.firstNodeOffset??0,a=r.firstNodeOffset??0;if(s<a)return-1;if(s>a)return 1;let c=o.finalNodeCoverLength??0,i=r.finalNodeCoverLength??0;return c<i?-1:c>i?1:0}function Kr(e){let t=[];for(let n=0;n<=e.maxOrder;n+=1)t.push(0);return e.nodes.forEach(n=>{n.y!==void 0&&(t[n.order]=Math.max(t[n.order],n.y+n.contentHeight+20))}),e.tracks.forEach(n=>{n.path.forEach(o=>{t[o.order]=Math.max(t[o.order],(o.y??0)+n.width)})}),t}function In(e,t){let n=[],o=(i,l)=>{n.push({order:i,isForward:l,node:null})},r=(i,l,d)=>{n.push({order:i,isForward:l,node:d})},s=Math.abs(t.indexSequence[0]),a=yn(t.indexSequence[0]),c=e.nodes[s];r(c.order,a,s);for(let i=1;i<t.sequence.length;i+=1){let l=c,d=a;s=Math.abs(t.indexSequence[i]),a=yn(t.indexSequence[i]),c=e.nodes[s];let{order:u}=c;if(u>l.order){d||o(l.order,!0);for(let f=l.order+1;f<u;f+=1)o(f,!0);a||o(u,!0)}else if(u<l.order){d&&o(l.order,!1);for(let f=l.order-1;f>u;f-=1)o(f,!1);a&&o(u,!1)}else a===d&&o(u,!a);r(u,a,s)}return n}function ze(e,t=e.reads){t.forEach(n=>{let o=0;for(;o<n.sequence.length&&n.sequence[o].startsWith("-");)o+=1;if(o===n.sequence.length){n.is_reverse=!0,n.sequence=n.sequence.reverse();for(let i=0;i<n.sequence.length;i+=1)n.sequence[i]=N(n.sequence[i]);let r=n.sequenceNew??[];r.reverse(),n.sequenceNew=r;for(let i of r)i.nodeName=N(i.nodeName),zr(i.mismatches,Ue(e,i.nodeName).sequenceLength);let s=n.firstNodeOffset??0,a=Ue(e,n.sequence[0]).sequenceLength;n.firstNodeOffset=a-(n.finalNodeCoverLength??0);let c=Ue(e,n.sequence[n.sequence.length-1]).sequenceLength;n.finalNodeCoverLength=c-s}})}function zr(e,t){e.forEach(n=>{Object.assign(n,Vr(n,t))})}function Vr(e,t){let n=e.type==="insertion"?0:e.type==="deletion"?e.length??0:e.seq?.length??0;return{...e,pos:t-e.pos-n,...e.seq!==void 0&&{seq:Je(e.seq)}}}var Jr={A:"T",T:"A",C:"G",G:"C"};function Je(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Jr[e.charAt(n)]??"N";return t}function W(e,t){let n=new Map;t.forEach(o=>{o.indexSequence=o.sequence.map(r=>{let s=n.get(r);if(s===void 0){let a=e.nodeMap.get(N(r));if(a===void 0)throw new Error(`Track ${o.name??o.id} visits unknown node ${r}`);s=k(r)?-a:a,n.set(r,s)}return s})})}var Qr=20;function Zr(e){let t={minX:99,maxX:-99,minY:99,maxY:-99},{rectangles:n,verticalRectangles:o,curves:r}=e.shapes;for(let s of[n,o,r])for(let{xStart:a,xEnd:c}of s)t.minX=Math.min(t.minX,a,c),t.maxX=Math.max(t.maxX,a,c);e.nodes.forEach(s=>{s.x!==void 0&&(t.minX=Math.min(t.minX,s.x-9),t.maxX=Math.max(t.maxX,s.x+Qr+s.pixelWidth)),s.y!==void 0&&(t.minY=Math.min(t.minY,s.y-10),t.maxY=Math.max(t.maxY,s.y+s.contentHeight+10))}),e.tracks.forEach(s=>{s.path.forEach(a=>{let c=a.y??0;t.maxY=Math.max(t.maxY,c+s.width),t.minY=Math.min(t.minY,c)})}),e.imageBounds=t}function Ue(e,t){let n=e.nodeMap.get(N(t)),o=n===void 0?void 0:e.nodes[n];if(o===void 0)throw new Error(`Unknown node ${t}`);return o}function En(e){let t=new Map;return e.nodes.forEach((n,o)=>{t.set(n.name,o)}),t}function vn(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),o=r=>{for(let s=0;s<r.indexSequence.length-1;s+=1){let a=Math.abs(r.indexSequence[s]),c=Math.abs(r.indexSequence[s+1]);t[a].add(c),n[c].add(a)}};e.tracks.forEach(o),e.reads.forEach(o),e.nodes.forEach((r,s)=>{r.successors=Array.from(t[s]),r.predecessors=Array.from(n[s])})}function Sn(e,t){let n=0,o=0,r=0;t.forEach(s=>{let a=Math.abs(s);if(s<0){let c=e.nodeOrders[a]??=o;c<r&&(r=c),n=c,o=c-1}else{let c=e.nodeOrders[a]??=n;n=c+1,o=c}}),r<0&&Qe(e,-r)}function es(e,t){let n=0,o=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let r=t[n],s,a;r>=0?(s=e.nodeOrders[r]-1,a=-1):(s=e.nodeOrders[-r]+1,a=1);for(let c=n-1;c>=0;c-=1){let i=Math.abs(t[c]);e.nodeOrders[i]===void 0&&(e.nodeOrders[i]=s,o=Math.min(o,s),s+=a)}return o<0&&Qe(e,-o),n}var ts=-1;function ns(e){let t=[];for(let n of e)t.push(n??ts);return t}function je(e){let t,n,o,r,s=0,a=e.tracks.concat(e.reads),c={stamp:new Int32Array(e.nodes.length),generation:0};e.nodeOrders=new Array(e.nodes.length).fill(void 0),e.nodes.forEach(l=>{l.order=void 0}),Sn(e,e.tracks[0].indexSequence);for(let l=1;l<a.length;l+=1){if(H(`generating order for track ${l+1}`),o=es(e,a[l].indexSequence),o===null){l<e.tracks.length?Sn(e,a[l].indexSequence):(a.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=ss(a[l].indexSequence);o<t.length;){for(r=o,o+=1;o<t.length&&e.nodeOrders[t[o]]===void 0;)o+=1;if(o<t.length){n=e.nodeOrders[t[r]]+1;for(let d=r+1;d<o;d+=1)e.nodeOrders[t[d]]=n,n+=1;if(e.nodeOrders[t[o]]>e.nodeOrders[t[r]])e.nodeOrders[t[o]]<n&&Rn(e,t[o],t[o-1],n);else if(a[l].indexSequence[o]>=0&&!os(e,t[o],t[r],c))Rn(e,t[o],t[o-1],n);else if(a[l].indexSequence[r]<0||e.nodes[t[r+1]].degree<2&&e.nodeOrders[t[o]]<e.nodeOrders[t[r]]){n=e.nodeOrders[t[r]]-1;for(let d=r+1;d<o;d+=1)e.nodeOrders[t[d]]=n,s=Math.min(s,n),n-=1}}else if(a[l].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let d=r+1;d<t.length;d+=1){let u=t[d];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let d=r+1;d<t.length;d+=1){let u=t[d];e.nodeOrders[u]===void 0&&(e.nodeOrders[u]=n,s=Math.min(s,n),n-=1)}}}}s<0&&Qe(e,-s);let i=ns(e.nodeOrders);e.nodeOrders=i,i.forEach((l,d)=>{let u=e.nodes[d];u!==void 0&&(u.order=l)})}function os(e,t,n,o){o.generation+=1;let{stamp:r,generation:s}=o,a=[t];for(r[t]=s;a.length>0;){let c=a.pop();if(c===n)return!0;for(let i of e.nodes[c].successors)r[i]!==s&&(r[i]=s,a.push(i))}return!1}function rs(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function ss(e){return e.map(t=>Math.abs(t))}function Qe(e,t){e.nodeOrders.forEach((n,o)=>{n!==void 0&&(e.nodeOrders[o]=n+t)})}function Rn(e,t,n,o){let r=new Map,s=[[t,o]],a=0;for(;a<s.length;){let[c,i]=s[a];a+=1;let l=e.nodeOrders[c];l!==void 0&&l<i&&(!r.has(c)||r.get(c)<i)&&(r.set(c,i),e.nodes[c].successors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,i+1])}),c!==t&&e.nodes[c].predecessors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,i+1])}))}r.forEach((c,i)=>{e.nodeOrders[i]=c})}function is(e){e.nodes.forEach(t=>{t.tracks=[]}),e.tracks.forEach(t=>{t.indexSequence.forEach(n=>{e.nodes[Math.abs(n)].tracks.push(t.id)})}),e.nodes.forEach(t=>{t.degree=t.tracks.length})}function as(e){cs(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function cs(e,t,n){let o=new Int32Array(e.nodes.length),r=new Uint8Array(e.nodes.length);for(let s of n.sequence){let a=k(s)?void 0:e.nodeMap.get(s);a!==void 0&&(r[a]=1)}for(let s of t){let{sequence:a,indexSequence:c}=s,i=c.length-1;for(let l=0;l<=i;l+=1){let d=Math.abs(c[l]);if(r[d]===1)continue;let u=e.nodes[d].order,f=l>0?e.nodes[Math.abs(c[l-1])].order:void 0,p=l<i?e.nodes[Math.abs(c[l+1])].order:void 0,h=k(a[l])?1:-1;(f===void 0||f<u)&&(p===void 0||u<p)&&(o[d]+=h),(f===void 0||f>u)&&(p===void 0||u>p)&&(o[d]-=h)}}for(let s of t){let{sequence:a,indexSequence:c}=s;for(let i=0;i<c.length;i+=1)o[Math.abs(c[i])]>0&&(a[i]=Ve(a[i]),c[i]=-c[i])}e.nodes.forEach((s,a)=>{o[a]>0&&(s.seq=Je(s.seq),s.switched=!0)})}function ls(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort(Ze);let s=ds(e);r.forEach(a=>{a.order>=0&&(a.order>o&&(o=a.order,t=n+10*s[a.order]),a.x=t,n=Math.max(n,t+40+a.pixelWidth))})}var Ke=35;function fs(e){return e<=Ke?e/17.5:Ke/17.5*Math.sqrt(e/Ke)}function ds(e){let t=[],n=[],o=[],r=[];for(let s=0;s<=e.maxOrder;s+=1)t.push(0),n.push(0),o.push(0);e.tracks.forEach(s=>{for(let a=1;a<s.path.length;a+=1){let c=s.path[a],i=s.path[a-1];c.order===i.order?c.isForward?t[c.order]=t[c.order]+1:n[c.order]=n[c.order]+1:o[c.order]=Math.max(fs(Math.abs((c.y??0)-(i.y??0))),o[c.order])}}),r.push(Math.max(0,t[0]-1));for(let s=1;s<=e.maxOrder;s+=1)r.push(Math.max(Math.max(0,t[s]-1)+Math.max(0,n[s-1]-1),o[s]));return r}function us(e){let t=[],n=[];for(let o=0;o<=e.maxOrder;o+=1)e.assignments[o]=[],n[o]=new Map,t[o]=[];e.tracks.forEach((o,r)=>{o.path=In(e,o),o.path.forEach((s,a)=>{ps(e,s.order,s.node,r,a,t,n)})});for(let o=0;o<=e.maxOrder;o+=1)ms(e,e.assignments[o],o)}function ps(e,t,n,o,r,s,a){let c={trackID:o,segmentID:r,compareToFromSame:s[t][o]??null},i=n===null?void 0:a[t].get(n);if(i===void 0){let l={type:"single",node:n,tracks:[c]};e.assignments[t].push(l),n!==null&&a[t].set(n,l)}else i.type="multiple",i.tracks.push(c);s[t][o]=c}function hs(e,t,n){let o;t.forEach(r=>{r.idealLane=0,r.tracks.forEach(s=>{if(s.segmentID===0)s.idealLane=s.trackID,s.idealY=null;else if(e.tracks[s.trackID].path[s.segmentID-1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID-1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID-1].y;else if(s.segmentID<e.tracks[s.trackID].path.length-1&&e.tracks[s.trackID].path[s.segmentID+1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID+1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID+1].y;else{for(o=s.segmentID-1;o>=0&&e.tracks[s.trackID].path[o].order!==n-1;)o-=1;o<0?(s.idealLane=s.trackID,s.idealY=null):(s.idealLane=e.tracks[s.trackID].path[o].lane,s.idealY=e.tracks[s.trackID].path[o].y)}r.idealLane+=s.idealLane}),r.idealLane/=r.tracks.length})}function ms(e,t,n){let o=0,r=new Set,s=20,a=!1,c=-1;hs(e,t,n),t.sort(_n),t.forEach(i=>{i.node!==null?(e.nodes[i.node].topLane=o,a&&(s-=10),e.nodes[i.node].y=s,e.nodes[i.node].contentHeight=0,a=!1):(a?s-=25:s>20&&(s-=10),a=!0),i.tracks.sort(_n),i.tracks.forEach(l=>{l.lane=o,l.trackID===c&&i.node===null&&a&&(s+=10),e.tracks[l.trackID].path[l.segmentID].lane=o,e.tracks[l.trackID].path[l.segmentID].y=s,typeof l.idealY=="number"&&r.add(l.idealY-s),o+=1,s+=e.tracks[l.trackID].width,i.node!==null&&(e.nodes[i.node].contentHeight+=e.tracks[l.trackID].width),c=l.trackID}),s+=25}),gs(e,t,r)}function gs(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let a=bs(e,t,s);a<r&&(r=a,o=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=o),s.tracks.forEach(a=>{let c=e.tracks[a.trackID].path[a.segmentID];c.y=c.y+o})})}function xs(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(o=>{if(o.node!==null){let r=e.nodes[o.node];r!==t&&r.y>t.y&&(r.y+=n,o.tracks.forEach(s=>{let a=e.tracks[s.trackID].path[s.segmentID];a.y=a.y+n}))}else o.tracks.forEach(r=>{let s=e.tracks[r.trackID].path[r.segmentID];s.y>=t.y&&(s.y=s.y+n)})}),e.nodesPerOrder[t.order].length>0&&e.nodesPerOrder[t.order].forEach(o=>{e.nodes[o]!==t&&e.nodes[o].y>t.y&&(e.nodes[o].y+=n)}))}function bs(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{typeof s.idealY=="number"&&e.tracks[s.trackID].type!=="read"&&(o+=Math.abs(s.idealY-n-e.tracks[s.trackID].path[s.segmentID].y)*e.tracks[s.trackID].width)})}),o}function _n(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function Ze(e,t){return e.order!==t.order?e.order-t.order:e.y!==void 0&&t.y!==void 0?e.y-t.y:0}function ys(e){let t=!0,n=4,o=e.config.trackWidth;if(e.config.freqWidth==="linear"){for(let r of e.tracks)r.width=r.type==="read"?n:Math.max(1,Math.round(r.freq??1))*o;return}for(let r of e.tracks)r.freq!==void 0?r.width=Math.round((Math.log(Math.max(r.freq,1))+1)*n):(r.width=o,r.type!==void 0&&r.type==="read"&&(r.width=n)),r.width!==n&&(t=!1);t&&e.tracks.forEach(r=>{r.freq!==void 0&&(r.width=o)})}function ws(e,t){let n=t.path[0],o=e.nodes[n.node],r=t.firstNodeOffset??0;return et(o,n.isForward?r:o.sequenceLength-r)}function Ms(e,t){let n=t.path[t.path.length-1],o=e.nodes[n.node],r=t.finalNodeCoverLength??0;return et(o,n.isForward?r:o.sequenceLength-r)}function Bn(e,t){return t>e.sequenceLength?null:et(e,t)}function et(e,t){let[n,o]=Ts(e);if(e.sequenceLength===0)return n;let r=Math.min(Math.max(t,0),e.sequenceLength);return n+r/e.sequenceLength*(o-n)}function Es(e){let t,n,o,r;for(let i=0;i<=e.maxOrder;i+=1)e.extraLeft.push(0),e.extraRight.push(0);let s=[],a=[];e.nodes.forEach(i=>{i.x!==void 0&&(s[i.order]=i.x,a[i.order]===void 0?a[i.order]=i.x+i.pixelWidth:a[i.order]=Math.max(a[i.order],i.x+i.pixelWidth))});let c=e.tracks[0];e.tracks.sort(Ur),e.tracks.forEach(i=>{o=i.path[0].y,i.type!=="read"?i.sequence[0].startsWith("-")?t=a[i.path[0].order]+20:t=s[i.path[0].order]-20:t=ws(e,i);for(let l=0;l<i.path.length;l+=1)i.path[l].y!==o&&(i.path[l-1].isForward?n=a[i.path[l-1].order]:n=s[i.path[l-1].order],n!==t&&e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+i.width-1,id:i.id,name:i.name,type:i.type}),i.path[l].order-1===i.path[l-1].order?(t=n,n=s[i.path[l].order],r=i.path[l].y,e.shapes.curves.push({xStart:t,yStart:o,xEnd:n+1,yEnd:r,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[l-1].node,nodeEnd:i.path[l].node,orderStart:i.path[l-1].order,orderEnd:i.path[l].order,...i===c?{reference:!0}:{}}),t=n,o=r):i.path[l].order+1===i.path[l-1].order?(t=n,n=a[i.path[l].order],r=i.path[l].y,e.shapes.curves.push({xStart:t+1,yStart:o,xEnd:n,yEnd:r,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[l-1].node,nodeEnd:i.path[l].node,orderStart:i.path[l-1].order,orderEnd:i.path[l].order,...i===c?{reference:!0}:{}}),t=n,o=r):i.path[l-1].isForward?(r=i.path[l].y,On(e,1,n,o,r,i.width,i.id,i.path[l].order,i.type,i.name),t=a[i.path[l].order],o=i.path[l].y):(r=i.path[l].y,On(e,-1,n,o,r,i.width,i.id,i.path[l].order,i.type,i.name),t=s[i.path[l].order],o=i.path[l].y));i.type!=="read"?i.path[i.path.length-1].isForward?n=a[i.path[i.path.length-1].order]+20:n=s[i.path[i.path.length-1].order]-20:n=Ms(e,i),e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:o,xEnd:Math.max(t,n),yEnd:o+i.width-1,id:i.id,name:i.name,type:i.type})})}var Xn=1e9;function Dn(e,t,n,o=Xn){let r=new Map,s=0,a=e.nodes.length,c=(m,g)=>(m+a)*(2*a+1)+g+a,i=e.config.ignoreStrand;for(let[m,g]of t.entries()){let x=Math.max(g.freq??1,1);s+=x;let y=g.indexSequence;if(!(y.length<2))for(let M=0;M<y.length-1;M+=1){let w=y[M],v=y[M+1],E=e.nodes[Math.abs(w)],b=e.nodes[Math.abs(v)],S=i?Math.min(c(w,v),c(-v,-w)):c(w,v),_=r.get(S);_===void 0?r.set(S,{sSigned:w,dSigned:v,sName:w<0?`-${E.name}`:E.name,dName:v<0?`-${b.name}`:b.name,count:x,crossings:x,sourceTrackID:g.sourceTrackID,lastSource:m}):(_.crossings+=x,_.lastSource!==m&&(_.count+=x,_.lastSource=m))}}let l=0;for(let m of r.values())m.crossings>l&&(l=m.crossings);let d=pe,u=60,f=m=>l<=1?d:d+(u-d)*Math.sqrt(m/l),p=[],h=0;for(let m of r.values()){let g=o+h,x=n==="haplotype"?{count:m.count,total:s}:void 0,y=x===void 0?"":` (${_s(x)})`,M=m.crossings===m.count?"":`, ${m.crossings.toLocaleString()} crossings`,w=`${m.count.toLocaleString()} ${n}${m.count===1?"":"s"}${y}${M}: Node ${m.sName} \u2192 Node ${m.dName}`;e.coarsenedEdgeMeta.set(g,{count:m.count,label:w});let v=e.nodes[Math.abs(m.sSigned)].sequenceLength;p.push({id:g,sourceTrackID:m.sourceTrackID,type:"read",name:w,sequence:[m.sName,m.dName],indexSequence:[],path:[],width:f(m.crossings),firstNodeOffset:v,finalNodeCoverLength:0,sequenceNew:[{nodeName:m.sName,mismatches:[]},{nodeName:m.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:m.count,haplotypeShare:x}),h+=1}if(Nn){let m="?",g=0;e.nodes.forEach(x=>{x.contentHeight>g&&(g=x.contentHeight,m=x.name)}),H(`[coarsened] ${n}s_in=${t.length} edges_out=${p.length} tallestNodeBeforePlace=${m}(${g.toFixed(1)})`)}return{bands:p,total:s}}function vs(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(d=>d.name===e.trackForRuler),o=n===-1?0:n,r=e.tracks[o],s=(r.freq??1)-1,a=Rs(e,r),c=e.tracks.filter((d,u)=>u!==o).map(d=>Ss(a,d));if(s>0&&c.push({...r,freq:s}),c.length===0)return;let{bands:i,total:l}=Dn(e,c,"haplotype",t);return i.length>0?{ref:r,bands:i,total:l}:void 0}function Ss(e,t){let n=0;for(let o of t.indexSequence){let r=e[Math.abs(o)];r!==void 0&&r!==0&&(n+=r===Math.sign(o)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(Ve).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function Rs(e,t){let n=new Int8Array(e.nodes.length);for(let o of t.indexSequence){let r=Math.abs(o);n[r]===0&&(n[r]=Math.sign(o))}return n}function _s({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var Tn=7;function On(e,t,n,o,r,s,a,c,i,l){let d=t===1?e.extraRight:e.extraLeft,u=10*d[c],f=n+t*(u+5),p=Tn,h=Math.min(Tn,s),m=Math.min(o,r),g=Math.max(o,r),x=t===1?n:f-1,y=t===1?f:n,M=b=>{e.shapes.verticalRectangles.push({xStart:x,yStart:b,xEnd:y,yEnd:b+s-1,id:a,name:l,type:i})};M(o),e.shapes.verticalRectangles.push({xStart:t===1?f+p:f-p-h,yStart:m+s+p-1,xEnd:t===1?f+p+h-1:f-p-1,yEnd:g-p+1,id:a,name:l,type:i}),M(r);let w=f+t*p,v=f+t*(p+h),E=`M ${f} ${g}`;E+=` Q ${w} ${g} ${w} ${g-p}`,E+=` H ${v}`,E+=` Q ${v} ${g+s} ${f} ${g+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:i}),E=`M ${f} ${m}`,E+=` Q ${v} ${m} ${v} ${m+s+p}`,E+=` H ${w}`,E+=` Q ${w} ${m+s} ${f} ${m+s}`,E+=" Z ",e.shapes.corners.push({path:E,id:a,type:i}),d[c]+=1}function Ts(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function An(e){switch(e.config.nodeWidthOption){case"compressed":e.nodes.forEach(t=>{t.width=1+Math.log2(Math.max(t.sequenceLength,1)),t.pixelWidth=Math.round((t.width-1)*8.401)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*8.401),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*8.401)});break;case"normal":{let t=e.config.charWidth;e.nodes.forEach(n=>{n.width=n.sequenceLength,n.pixelWidth=Math.round(t*Math.max(n.sequenceLength-1,0))});break}default:throw new Error(`${e.config.nodeWidthOption} not implemented`)}}var D=0;function kn(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function A(e,t,n){let o=e.count[t];o===0?(e.first[t]=n,e.count[t]=1):o===1&&e.first[t]!==n&&(e.count[t]=2)}function V(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function Os(e){let t=kn(e.nodes.length),n=kn(e.nodes.length),o=new Map,r=u=>{let f=o.get(u);if(f===void 0){let p=e.nodeMap.get(N(u));f=k(u)?-p:p,o.set(u,f)}return f};e.tracks.concat(e.reads).forEach(u=>{let{sequence:f}=u,p=u.type==="haplotype",h=f.length-1,m=D,g=h>=0?r(f[0]):D;for(let x=0;x<=h;x+=1){let y=x<h?r(f[x+1]):D;if(g>0)x>0?(A(t,g,m),m<0&&A(t,g,-m)):p&&A(t,g,D),x<h?(A(n,g,y),y<0&&A(n,g,-y)):p&&A(n,g,D);else{let M=-g;x>0?(A(n,M,-m),m>0&&A(n,M,m)):p&&A(n,M,D),x<h?(A(t,M,-y),y>0&&A(t,M,y)):p&&A(t,M,D)}m=g,g=y}});let a=new Uint8Array(e.nodes.length);e.nodes.forEach((u,f)=>{As(f,t,n)!==0&&(a[f]=1)});let c=new Int32Array(e.nodes.length),i=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((u,f)=>{if(a[f]!==1){c[f]=f,l[f]=u.sequenceLength;for(let p=f;ks(p,t,n);)p=V(n,p),c[p]=f,i[p]=u.sequenceLength,u.sequenceLength+=e.nodes[p].sequenceLength,u.seq+=e.nodes[p].seq,l[p]=u.sequenceLength}}),e.reads.forEach(u=>{let{sequence:f}=u,p=u.sequenceNew??f.map(M=>({nodeName:M,mismatches:[]})),h=M=>{let w=Math.abs(r(M));return k(M)?e.nodes[c[w]].sequenceLength-l[w]:i[w]},m=f.length-1;u.firstNodeOffset=(u.firstNodeOffset??0)+h(f[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+h(f[m]);let g=[],x=[],y=[];f.forEach((M,w)=>{let v=Math.abs(r(M)),{mismatches:E}=p[w],b=h(M);if(E.forEach(S=>{S.pos+=b}),a[v]===1&&!k(M)&&w>0)x.at(-1).mismatches.push(...E);else if(a[v]===1&&k(M)&&w<m)y.push(...E);else{let S=e.nodes[c[v]].name,_=k(M)?Ln(S):S;g.push(_),x.push({nodeName:_,mismatches:y.concat(E)}),y=[]}}),u.sequence=g,u.sequenceNew!==void 0&&(u.sequenceNew=x)}),e.tracks.forEach(u=>{let{sequence:f}=u,p=0;for(let h of f)a[Math.abs(r(h))]===0&&(f[p]=h,p+=1);f.length=p});let d=1;for(let u=1;u<e.nodes.length;u+=1)a[u]===0&&(e.nodes[d]=e.nodes[u],d+=1);e.nodes.length=d}function As(e,t,n){let o=V(t,e);return o!==0&&V(n,o)!==0?o:0}function ks(e,t,n){let o=V(n,e);return o!==0&&V(t,o)!==0}function Ns(e,t){let n=new Map;for(let o of e){let r=t(o),s=n.get(r);s===void 0?n.set(r,[o]):s.push(o)}return n}function Cs(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function tt(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function $s(e,t){for(let n=0;n<e.length;n+=1){let o=e[n]-t[n];if(o!==0)return o}return 0}var qn=.75,he=.8;function Ps(e,t){let n=e[0],o=Math.min(Math.abs(n.xEnd-n.xStart),t);if(o===0)return e.map(()=>0);let r=e.length>5?.4/e.length:0,s=e.map(f=>{let p=Math.abs(f.yEnd-f.yStart),h=p/Math.hypot(p,o)*Math.min(f.width,he*qn*o);return Math.max(r,h/(qn*o))}),a=f=>s.reduce((p,h,m)=>p+(f(e[m])?h:0),0),c=a(f=>f.reference===!0),i=a(f=>f.reference!==!0),l=c>he?he/c:1,d=he-c*l,u=i>d?d/i:1;return s.map((f,p)=>f*(e[p].reference?l:u))}function Fn(e,t,{gapWidth:n=1/0}={}){let o=Ns(e.filter(r=>r.type===t),r=>tt(r).join(","));return o.forEach(r=>{r.sort(Cs);let s=Ps(r,n),a=.5-s.reduce((c,i)=>c+i,0)/2;r.forEach((c,i)=>{let l=p=>c.xStart+(c.xEnd-c.xStart)*(c.yStart<c.yEnd?1-p:p),d=l(a);a+=s[i];let u=l(a),f=`M ${c.xStart} ${c.yStart}`;f+=` C ${d} ${c.yStart} ${d} ${c.yEnd} ${c.xEnd} ${c.yEnd}`,f+=` V ${c.yEnd+c.width}`,f+=` C ${u} ${c.yEnd+c.width} ${u} ${c.yStart+c.width} ${c.xStart} ${c.yStart+c.width}`,f+=" Z",c.path=f})}),[...o.values()].sort((r,s)=>$s(tt(r[0]),tt(s[0]))).flat()}function Gn(e,t=16){let n=e.match(/[A-Za-z]|-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/g)??[],o=[],r=0,s=0,a=0,c=()=>Number(n[a++]);for(;a<n.length;){let i=n[a++];if(i==="M"||i==="L")r=c(),s=c(),o.push([r,s]);else if(i==="H")r=c(),o.push([r,s]);else if(i==="V")s=c(),o.push([r,s]);else if(i==="C"){let[l,d,u,f,p,h]=[c(),c(),c(),c(),c(),c()];for(let m=1;m<=t;m+=1){let g=m/t,x=1-g,y=x*x*x,M=3*x*x*g,w=3*x*g*g,v=g*g*g;o.push([y*r+M*l+w*u+v*p,y*s+M*d+w*f+v*h])}r=p,s=h}else if(i==="Q"){let[l,d,u,f]=[c(),c(),c(),c()];for(let p=1;p<=t;p+=1){let h=p/t,m=1-h;o.push([m*m*r+2*m*h*l+h*h*u,m*m*s+2*m*h*d+h*h*f])}r=u,s=f}else if(i!=="Z")throw new Error(`flattenPath: unsupported path command ${i}`)}return o}function Yn(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,o=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n+9} ${o} ${n+9} ${o+9}`,n+=9,o+=9,e.contentHeight>0&&(o+=e.contentHeight,t+=` L ${n} ${o}`),t+=` Q ${n} ${o+9} ${n-9} ${o+9}`,n-=9,o+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${o}`),t+=` Q ${n-9} ${o} ${n-9} ${o-9}`,n-=9,o-=9,e.contentHeight>0&&(o-=e.contentHeight,t+=` L ${n} ${o}`),t}function Ls(e,t){let n=[],o=e.sequenceNew??[],r=e.path.filter(s=>s.node!==null);return o.forEach((s,a)=>{let c=t.nodeMap.get(N(s.nodeName)),i=c===void 0?void 0:t.nodes[c],l=r[a]?.y;if(i&&l!==void 0){let d={readId:e.id,y:l,height:e.width},u=f=>Bn(i,f);for(let f of s.mismatches){let p=u(f.pos);if(p!==null){if(f.type==="insertion"){let h=a===0&&f.pos===e.firstNodeOffset||a===o.length-1&&f.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:p,seq:f.seq,softClip:h})}else if(f.type==="deletion"&&f.length!==void 0){let h=u(f.pos+f.length);h!==null&&n.push({...d,kind:"deletion",x0:p,x1:h,length:f.length})}else if(f.type==="substitution"&&f.seq!==void 0){let h=u(f.pos+f.seq.length);h!==null&&n.push({...d,kind:"substitution",x0:p,x1:h,seq:f.seq})}}}}}),n}function Wn(e){return e.reads.flatMap(t=>Ls(t,e))}var nt=24,Is=.5,Bs=e=>e.bp1>e.bp0;function Yc(e,t){let n=e.filter(Bs);if(n.length===0){let l=e[0];return l?[{tx:l.x0,sx:t(l.bp0)}]:[]}let o=[],r=[],s=[];n.forEach((l,d)=>{o.push(l.x0,l.x1),r.push(t(l.bp0),t(l.bp1)),s.push(d===0?0:Math.min(l.x0-n[d-1].x1,nt),0)});let a=r.at(-1)-r[0],c=s.reduce((l,d)=>l+d,0),i=c>0?Math.min(1,Is*a/c):1;return Xs(r,s,i).map((l,d)=>({tx:o[d],sx:l}))}function Xs(e,t,n){let o=[],r=0;for(let a of t)r+=a*n,o.push(r);let s=[];return e.forEach((a,c)=>{let i={mean:a-o[c],n:1},l=s.at(-1);for(;l&&l.mean>=i.mean;){s.pop();let d=l.n+i.n;i={mean:(l.mean*l.n+i.mean*i.n)/d,n:d},l=s.at(-1)}s.push(i)}),s.flatMap(a=>Array(a.n).fill(a.mean)).map((a,c)=>a+o[c])}function Wc(e,t){let n=e.length;if(n===0)return t;let o=e[0],r=e[n-1];if(t<=o.tx)return o.sx+(t-o.tx);if(t>=r.tx)return r.sx+(t-r.tx);let s=0,a=n-1;for(;a-s>1;){let d=s+a>>1;e[d].tx<=t?s=d:a=d}let c=e[s],i=e[a],l=i.tx-c.tx;return l>0?c.sx+(t-c.tx)/l*(i.sx-c.sx):c.sx}function st(e){let t=e.trim().split(/[\s,]+/),n=[],o=0,r=()=>Number(t[o++]);for(;o<t.length;){let s=t[o++];s==="M"||s==="L"?n.push({op:s,x:r(),y:r()}):s==="H"?n.push({op:s,x:r()}):s==="V"?n.push({op:s,y:r()}):s==="Q"?n.push({op:s,x1:r(),y1:r(),x:r(),y:r()}):s==="C"?n.push({op:s,x1:r(),y1:r(),x2:r(),y2:r(),x:r(),y:r()}):s==="Z"&&n.push({op:s})}return n}function Kn(e){let t=1/0,n=-1/0;for(let o of e)"x"in o&&(t=Math.min(t,o.x),n=Math.max(n,o.x)),"x1"in o&&(t=Math.min(t,o.x1),n=Math.max(n,o.x1));return{x0:t,x1:n}}function Hn(e,t,n,o,r){let s=st(e);return{commands:s,outline:Gn(e,12),color:t,id:n,haplotype:o,reference:r,...Kn(s)}}function zn(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?Ut(n):t[n.id]]))}function Un(e,t,n,o,r){let{shapes:s}=e,a=t==="haplotype",c=f=>n.get(f.id),i=f=>a&&o.has(f.id),l=[...s.rectangles,...s.verticalRectangles].filter(f=>f.type===t).map(f=>({color:c(f),id:f.id,haplotype:a,reference:i(f),x0:f.xStart,x1:f.xEnd+1,y0:f.yStart,y1:f.yEnd+1})),d=Fn(s.curves,t,{gapWidth:r}).map(f=>Hn(f.path,c(f),f.id,a,i(f))),u=s.corners.filter(f=>f.type===t).map(f=>Hn(f.path,c(f),f.id,a,i(f)));return{rects:l,shapes:[...d,...u]}}function Ds(e){let t=new Set;return e?.paths?.forEach((n,o)=>{U(n.name).name===e.referencePath&&t.add(o)}),t}function qs({layout:e,pathColors:t,graph:n,columns:o}){let r=zn(e,t),s=Ds(n),a=o?nt:void 0,c=[];return e.nodes.forEach(i=>{if(i.order>=0){let l=st(Yn(i));c.push({name:i.name,commands:l,...Kn(l)})}}),{bounds:e.bounds,layers:[Un(e,"haplotype",r,s,a),Un(e,"read",r,s,a)],nodes:c,mismatches:Wn(e).filter(i=>i.kind!=="insertion"||!i.softClip)}}function ot(e,t,n,o){let r=0,s=0;for(let a of t)switch(a.op){case"M":r=a.x,s=a.y,e.moveTo(n(r),o(s));break;case"L":r=a.x,s=a.y,e.lineTo(n(r),o(s));break;case"H":r=a.x,e.lineTo(n(r),o(s));break;case"V":s=a.y,e.lineTo(n(r),o(s));break;case"Q":r=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),o(a.y1),n(r),o(s));break;case"C":r=a.x,s=a.y,e.bezierCurveTo(n(a.x1),o(a.y1),n(a.x2),o(a.y2),n(r),o(s));break;case"Z":e.closePath();break}}function jn(e,t,n,o,r){let s=new Map;for(let a of t)if(n(a)){let c=o(a),i=s.get(c);i?i.push(a):s.set(c,[a])}for(let a of s.values()){e.fillStyle=o(a[0]),e.beginPath();for(let c of a)r(c);e.fill()}}var Fs=12,Gs=.15;function Ys(e){return Math.max(Gs,Math.min(1,e/Fs))}var Ws=.55;function Hs(e,t,n){let{x:o,y:r,width:s}=n,a=d=>o(d.x1)>=0&&o(d.x0)<=s,c=d=>d.haplotype&&n.tubeColors?.[d.id]||d.color;e.globalAlpha=1;for(let d of t.layers)for(let u of[!1,!0]){let f=p=>p.reference===u;jn(e,d.rects,p=>f(p)&&a(p),c,p=>{let h=o(p.x0),m=r(p.y0);e.rect(h,m,o(p.x1)-h,r(p.y1)-m)}),jn(e,d.shapes,p=>f(p)&&a(p),c,p=>{ot(e,p.commands,o,r)})}let i=n.darkMode?"#d0d0d0":"#000000",l=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=Vn(n);for(let d of t.nodes)if(a(d)&&d.name!==n.highlightNode){e.beginPath(),ot(e,d.commands,o,r);let u=n.nodeColors?.get(d.name);e.fillStyle=u??l,e.strokeStyle=i,e.globalAlpha=u?Ws:1,e.fill(),e.globalAlpha=Ys(o(d.x1)-o(d.x0)),e.stroke(),e.globalAlpha=1}me(e,t,n),js(e,t.mismatches,n)}function Vn(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function me(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),ot(e,o.commands,n.x,n.y),e.globalAlpha=1,e.lineWidth=Vn(n),e.fillStyle="rgba(255,192,203,0.5)",e.strokeStyle="#ff0000",e.fill(),e.stroke())}var Jn=12,Us=6;function it(e){return Jn*e>=Us}function rt(e,{x:t,width:n}){let[o,r]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(r)>=0&&t(o)<=n}function js(e,t,n){let{x:o,y:r,yScale:s,darkMode:a}=n;if(!it(s)||t.length===0)return;let c=Jn*s;e.fillStyle="grey",e.beginPath();for(let i of t)if(i.kind==="deletion"&&rt(i,n)){let l=o(i.x0),d=r(i.y);e.rect(l,d,o(i.x1)-l,r(i.y+i.height)-d)}e.fill(),e.font=`${c}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let i of t)rt(i,n)&&(i.kind==="substitution"?e.fillText(i.seq,o(i.x0)+1,r(i.y+i.height)):i.kind==="insertion"&&e.fillText("*",o(i.x)-3,r(i.y+i.height)))}function Ks(e,t,n){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[a,c]=e[r],[i,l]=e[s];c>n!=l>n&&t<(i-a)*(n-c)/(l-c)+a&&(o=!o)}return o}function zs(e,{x:t,y:n},o,r){for(let s=e.layers.length-1;s>=0;s--){let{rects:a,shapes:c}=e.layers[s];for(let i of[!0,!1]){for(let l of a)if(l.reference===i&&t(l.x0)<=o&&o<=t(l.x1)&&n(l.y0)<=r&&r<=n(l.y1))return l.id;for(let l of c)if(l.reference===i&&t(l.x0)<=o&&o<=t(l.x1)&&Ks(l.outline.map(([d,u])=>[t(d),n(u)]),o,r))return l.id}}}var Vs=4;function Js(e,t,n,o){let{x:r,y:s,yScale:a}=t;return it(a)?e.mismatches.find(c=>s(c.y)<=o&&o<=s(c.y+c.height)&&(c.kind==="insertion"?Math.abs(r(c.x)-n)<=Vs:r(c.x0)<=n&&n<=r(c.x1))):void 0}var q=JBrowseExports["@jbrowse/core/util/groupKeys"],Qs=e=>q!=null&&e in Object(q)?q[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/core/util/groupKeys' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e});var ge=Qs("groupKeyComparator");var Al=q&&q.__esModule?q.default:q;var xe=16;function $l(e){let[t="",...n]=e.split(/\r\n|\r|\n/),o=t.split(" ").slice(1),r=new Map;for(let s of n){if(!s)continue;let[a="",...c]=s.split(" ");a&&!r.has(a)&&r.set(a,{...Object.fromEntries(o.map((i,l)=>[i,c[l]??""])),name:a})}return[...r.values()]}function Pl(e){let t=new Set;for(let n of e??[])for(let o of Object.keys(n))o!=="name"&&t.add(o);return[...t]}function Ll(e){if(typeof e=="string")return e?{field:e}:void 0;let{field:t,domain:n}=e??{};if(!(typeof t!="string"||!t))return Array.isArray(n)?{field:t,domain:n.filter(o=>typeof o=="string")}:{field:t}}function at(e,t){return`${e} ${t}${e===1?"":"s"}`}function ct(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return(o,r)=>n.get(o)||n.get(r)||""}function lt(e,t,{field:n,domain:o},r,s){let a=new Map;for(let c of e){let i=t(c),l=a.get(i);l?l.push(c):a.set(i,[c])}return[...a.keys()].sort(ge(o)).map(c=>{let i=a.get(c),l=new Set(i.map(s)).size;return{key:c,members:i,title:`${c||`${n}: none`} \xB7 ${at(l,r)}`}})}function Il(e,t,n){let o=ct(n.field,t),r=lt(e,c=>o(c.label,c.sample),n,"haplotype",c=>c.label),s=1,a=r.map(({key:c,members:i,title:l})=>{let d={key:c,title:l,first:s,count:i.length};return s+=i.length,d});return{rows:r.flatMap(c=>c.members),sections:a}}function Bl(e,t){let n=r=>{let s=-1;for(;s+1<e.length&&e[s+1].first<=r;)s++;return s},o=r=>r*t+(n(r)+1)*xe;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*xe})),headersPx:e.length*xe,rowAt(r,s){let a=0;for(let c=-1;c<e.length;c++){let i=c<0?0:e[c].first,l=c<0?Math.min(s,e[0]?.first??s):i+e[c].count,d=(c+1)*xe,u=Math.min(l-1,Math.max(i,Math.round((r-d)/t)));Math.abs(o(u)-r)<Math.abs(o(a)-r)&&(a=u)}return a}}}function Xl(e,t,n,o,r){return t.length===0?[z(e,o,r)]:[z({...e,rows:[]},o,r),...t.flatMap((s,a)=>z({...e,rows:e.rows.slice(s.first-1,s.first-1+s.count)},{...o,translateY:o.translateY+(n(s.first)-o.rowPx)*o.scaleY},{...r,idPrefix:`${r.idPrefix}-s${a}`}).children.filter(i=>typeof i!="string"&&i.attrs["data-testid"]!=="graph-walk-reference"))]}function J(e){let t=e.split("#"),n=t.length>=2?Number(t[1]):Number.NaN;return{sample:t[0]??e,haplotype:Number.isFinite(n)?n:void 0}}function Zs(e,t,n,o){let r=[],s=[],a=[e];for(o.add(e);a.length>0;){let c=a.pop(),i=t.get(c);if(i){r.push(i);for(let l of n.get(c)??[]){let d=t.get(l);d&&(d.stable.rank===ye?s.push(d):o.has(l)||(o.add(l),a.push(l)))}}}return{members:r,anchors:s}}function ei(e){if(new Set(e.map(c=>c.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((c,i)=>c.stable.start-i.stable.start),o=n[0],r=n.at(-1),s=o.stable.start+o.length,a=r.stable.start;return a>=s?{start:s,end:a,entry:o}:void 0}function ti(e,t,n){let o=new Map(e.map(a=>[a.id,a])),r=new Map,s=[];for(let a of n.get(t.id)??[])o.has(a)&&(r.set(a,0),s.push(a));if(s.length===0)for(let a of e)r.set(a.id,0),s.push(a.id);for(let a of s){let c=r.get(a)+o.get(a).length;for(let i of n.get(a)??[])if(o.has(i)){let l=r.get(i);(l===void 0||c<l)&&(r.set(i,c),s.push(i))}}return r}function ni(e,t,n){let o=ti(e,t,n),r=[...e].sort((i,l)=>o.get(i.id)-o.get(l.id)),s=new Map(r.map((i,l)=>[i.id,l])),a=new Map(e.map(i=>[i.id,i])),c=new Map;for(let[i,l]of r.entries()){let d=0;for(let u of n.get(l.id)??[]){let f=a.get(u);f&&s.get(u)<i&&(d=Math.max(d,c.get(u)+f.length))}c.set(l.id,d)}return{offsets:c,ordered:r}}function oi(e){let t=new Map(e.nodes.filter(ht).map(s=>[s.id,s])),n=gt(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==ye&&!o.has(s.id)){let{members:a,anchors:c}=Zs(s.id,t,n,o),i=ei(c);if(i){let{offsets:l,ordered:d}=ni(a,i.entry,n);r.push({start:i.start,refSpan:i.end-i.start,nodeIds:d.map(u=>u.id),nodeOffsets:d.map(u=>l.get(u.id)),pathLength:d.reduce((u,f)=>Math.max(u,l.get(f.id)+f.length),0)})}}return r.sort((s,a)=>s.start-a.start)}var ri=28,Qn="#4d4d4d",si="#5b8cc4",ii=[si,"#82abd9"],ff=["#8c8c8c","#adadad"],ai="12px sans-serif",df=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],C=e=>U(e).name;function uf(e,t,n=ii){let o=0;return e.map(r=>C(r.name)===t?Qn:n[o++%n.length])}var ci=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#76b7b2","#edc948","#9c755f","#ff9da7","#bab0ac"],Zn="#c8c8c8";function pf(e){let t=[...new Set(e)].filter(n=>n!=="").sort(ge());return new Map(t.map((n,o)=>[n,ci[o]??Zn]))}function hf(e,t,n,o){return e.map(r=>{let s=C(r.name);return s===t?Qn:o.get(n(r.members?.[0]??s))??Zn})}function li(e,t){let n=ct(e,t);return o=>{let{sample:r,haplotype:s}=J(o);return n(`${r}#${s}`,r)}}function mf(e,t){let n=(e.paths??[]).map(i=>i.name).filter(i=>C(i)!==e.referencePath);if(t.by==="column"){let i=li(t.field,t.table);return lt(n,l=>i(C(l)),t,"sample",l=>J(C(l)).sample).map(({key:l,members:d,title:u})=>({key:l,paths:d,label:u}))}let o=t.by==="sample"?i=>J(i).sample:i=>i,r=new Map;for(let i of n){let l=o(C(i)),d=r.get(l);d?d.push(i):r.set(l,[i])}let s=t.domain??[],a=new Map(s.map((i,l)=>[i,l])),c=i=>a.get(i)??s.length;return[...r].map(([i,l],d)=>({key:i,paths:l,i:d})).sort((i,l)=>c(i.key)-c(l.key)||i.i-l.i).map(({key:i,paths:l})=>({key:i,paths:l}))}function gf(e,t){if(e.graph.nodes.some(n=>n.id===t))return t;for(let[n,o]of e.members)if(o.includes(t))return n}function xf(e,t,n,o,r){let s=e.flatMap(u=>{let f=t(u);return f?[{id:u,...f}]:[]});if(s.length===0)return;let a=Math.min(...s.map(u=>u.start)),c=Math.max(...s.map(u=>u.end)),i=o>n?(r-n)/(o-n):0,l=a+Math.min(1,Math.max(0,i))*(c-a),d=u=>l<u.start?u.start-l:l>=u.end?l-u.end+1:0;return s.reduce((u,f)=>d(f)<d(u)?f:u).id}function bf(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=C(r.name);if(s!==e.referencePath)for(let a of r.members??[s])n.add(a),r.nodeIds.includes(t)&&o.add(a)}return{here:o.size,of:n.size}}var fi="bold 11px sans-serif",di=80,ui=9;function yf(e,t,n,{x:o,y:r,width:s}){let a=n.paths??[];if(!a.some(i=>i.members))return;let c=new Map;a.forEach((i,l)=>{C(i.name)!==n.referencePath&&c.set(l,i.members?.length??1)}),e.font=fi,e.textAlign="left",e.textBaseline="middle",e.fillStyle="#0b1f3a";for(let i of t.layers[0]?.rects??[]){let l=c.get(i.id),d=Math.max(0,o(i.x0)),u=Math.min(s,o(i.x1)),f=r(i.y0),p=r(i.y1);l!==void 0&&u-d>=di&&p-f>=ui&&e.fillText(`\xD7${l}`,d+4,(f+p)/2)}}var pi="10px sans-serif",hi=1e3;function wf(e,t,{x:n,y:o,width:r}){if(!t.columns)return;let s=new Map(t.graph.nodes.map(i=>[i.id,i.length]));e.font=pi;let a=new Map;t.layout.nodes.forEach(i=>{let l=s.get(i.name)??0,d=n(i.x),u=n(i.x+i.pixelWidth),f=T(l);if(i.order>=0&&l>=hi&&u-d<e.measureText(f).width){let p=(o(i.y)+o(i.y+i.contentHeight))/2,h=`${Math.round(u)}:${f}`,m=a.get(h);m?(m.count++,m.mid=Math.max(m.mid,p)):a.set(h,{text:f,right:u,mid:p,count:1})}}),e.textAlign="left",e.textBaseline="middle",e.lineJoin="round",e.lineWidth=3,e.strokeStyle="rgba(255,255,255,0.9)",e.fillStyle="rgba(0,0,0,0.75)";let c=[];for(let{text:i,right:l,mid:d,count:u}of a.values()){let f=u>1?`${i} each`:i,p={x0:l+3,x1:l+3+e.measureText(f).width,y0:d-6,y1:d+6};p.x1<=r&&!c.some(h=>h.x0<p.x1&&p.x0<h.x1&&h.y0<p.y1&&p.y0<h.y1)&&(c.push(p),e.strokeText(f,p.x0,d),e.fillText(f,p.x0,d))}}function Mf(e,t,n,{width:o,lit:r}){t.forEach((s,a)=>{let c=n?.[a];c&&(r&&me(e,s.picture,{...s.frame,width:o,highlightNode:c.box}),e.font=ai,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${c.here} of ${at(c.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4))})}function Ef(e,t){let n=new Set(t),o=(e.paths??[]).filter(l=>n.has(l.name)||C(l.name)===e.referencePath),r=new Set(o.map(l=>C(l.name))),s=new Set(o.flatMap(l=>l.nodeIds)),a=e.nodes.filter(l=>s.has(l.id)),c=new Set(a.map(l=>l.name)),i=e.pathVisits?.filter(l=>r.has(l),l=>c.has(l));return{...e,nodes:a,edges:e.edges.filter(l=>s.has(l.from)&&s.has(l.to)),paths:o,anchorPaths:e.anchorPaths?.filter(l=>r.has(l.name)),pathVisits:i,reads:void 0}}function vf(e,t){let n=[],o={},r=0,s=1/0,a=-1/0;for(let{key:c,paths:i,label:l,result:d}of t){let u=d?.tubeMap,f=d?.extent;if(u&&f){let p=r+ri,h=(f.maxY??0)-(f.minY??0);n.push({key:c,paths:i,label:l,result:{...d,tubeMap:u},top:p,height:h});let m=p-(f.minY??0);for(let[g,x]of Object.entries(d.nodePositions))o[g]=x.map(y=>({x:y.x,y:y.y+m}));r=p+h,s=Math.min(s,f.minX??s),a=Math.max(a,f.maxX??a)}}return n.length>1?{...e,nodePositions:o,extent:{...s<=a?{minX:s,maxX:a}:{},minY:0,maxY:r},tubeMapPanels:n}:e}var mi="#daa520",gi=1,xi=2,bi=4;function _f(e,t,n,o=r=>r){let r=s=>{let a=t(s)*2;return n?.nodeIds.has(s)?Math.max(a,n.walks.length*bi):a};return e.flatMap(s=>s.exonsByNode.map(({nodeId:a,d:c})=>({key:`${s.gene.name}-${s.gene.start}-${a}`,d:o(c),inner:r(a)+2*gi})))}function Tf(e,t){if(e.length===0)return;let n=(o,r,s)=>R("path",{d:o.d,fill:"none",stroke:r,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return R("g",{},R("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},R("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*xi)),...e.map(o=>n(o,"#000",o.inner)))),R("rect",{width:t.width,height:t.height,fill:mi,mask:`url(#${t.id})`}))}function ft(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${G(o)}-${G(r)} (${T(r-o)})`}function yi(e,t){let{field:n}=e.encoding,o=e.range?ft(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?ft(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${T(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${T(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${T(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function wi(e,t,n){let o=e.progress.get(t),r=e.range;if(o===void 0||!r)return;let s=Math.round(r.start+o*(r.end-r.start)-n/2);return`${r.contig}:${G(s)}-${G(s+n)}`}function Mi(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],a=r?.at(-1);if(!r||!s||!a)continue;let c=Math.max(o.start,s.bp0),i=Math.min(o.end,a.bp1);i<=c||n.push({gene:o,...ue(r,c,i),exons:o.exons.filter(l=>l.end>c&&l.start<i).map(l=>ue(r,Math.max(l.start,c),Math.min(l.end,i)))})}return n}var dt=22,Ei=4,be=8,vi="11px sans-serif",Si=8;function Ri(e){let t=e.flatMap(r=>[{x:r.x0,step:1},{x:r.x1,step:-1}]).sort((r,s)=>r.x-s.x||r.step-s.step),n=0,o=0;for(let{step:r}of t)n+=r,o=Math.max(o,n);return Math.min(Ei,o)}function _i(e,t,n,o,r=0){let{x:s,width:a,darkMode:c}=n,i=Math.max(1,Math.floor((o-r)/dt)),l=[],d=c?"#e0e0e6":"#1c1c22";e.font=vi,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let u=t.map(f=>({g:f,s0:s(f.x0),s1:s(f.x1)})).filter(({s0:f,s1:p})=>p>=0&&f<=a).sort((f,p)=>f.s0-p.s0);for(let{g:f,s0:p,s1:h}of u){let m=f.gene.strand>0?" \u2192":f.gene.strand<0?"\u2190 ":"",g=f.gene.strand<0?`${m}${f.gene.name}`:`${f.gene.name}${m}`,x=(Math.max(p,0)+Math.min(h,a))/2,y=e.measureText(g).width/2,M=Math.min(p,x-y),w=Math.max(h,x+y),v=l.findIndex(b=>b+Si<=M);v===-1&&(v=Math.min(l.length,i-1)),l[v]=Math.max(l[v]??-1/0,w);let E=o-v*dt-be/2;e.beginPath(),e.moveTo(p,E+.5),e.lineTo(h,E+.5),e.stroke();for(let b of f.exons){let S=s(b.x0);e.fillRect(S,E-be/2,Math.max(1,s(b.x1)-S),be)}e.fillText(g,x,E-be/2-2)}}var $=12,ro=$+8,so=8,eo=so+3,Ti=12;function Oi(e,{colorScheme:t,referenceRamp:n,walks:o}){let r={..._e(e),referenceRamp:n},s=[];return e.nodes.forEach((a,c)=>{if(Q(a)){let i=o?o.map(l=>{let d=l.colors.get(a.id);return d===void 0?ne:L(d)}):[L(Te(a,c,t,r))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:i,faded:i.includes(ne)})}}),s.sort((a,c)=>a.bp0-c.bp0)}function ut(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var to=2;function io(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),a=Math.max(o,r),c=0,i=0;for(let l of e)c+=Math.max(0,Math.min(l.bp1,s)-l.bp0),i+=Math.max(0,l.bp1-Math.max(l.bp0,a));return t.scale>=0?{left:Math.round(c),right:Math.round(i)}:{left:Math.round(i),right:Math.round(c)}}function Ai(e,t,n,o){if(o<0||o>$+to)return;let r,s=to;for(let a of e){let[c,i]=ut(t,a.bp0,a.bp1),l=Math.max(0,c-n,n-i);l<=s&&(s=l,r=a.node)}return r}function ki(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function ao(e,t,n,o){let r=e.map(l=>{let[d,u]=ut(t,l.bp0,l.bp1),f=Math.round(d*o);return{colors:l.colors,x0:d,px0:f,px1:Math.max(Math.round(u*o),f+1)}}).filter(l=>l.px1>0&&l.px0<n*o).sort((l,d)=>l.x0-d.x0),s=[],a=-1/0,c=[-1/0,-1/0];for(let{colors:l,px0:d,px1:u}of r){let f=Math.max(d,a);if(u>f){let p=c[0]<f?0:1;c[p]=u,s.push({colors:l,x0:f/o,x1:u/o,tier:p}),a=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Ti?s:s.map(({tier:l,...d})=>d)}function no(e,t,n,o){let r=n>0?t:t-eo;e.clearRect(r,0,eo,$);let s=t+n,a=s+n*so;e.beginPath(),e.moveTo(s,$/2),e.lineTo(a,0),e.lineTo(a,$),e.closePath(),e.fillStyle=o,e.fill()}function oo(e,t,n){return Math.round(e*$*n/t)/n}function Ni(e,t,n,{width:o,lit:r,darkMode:s,dpr:a=1}){let c=s?"#ffffff":"#18181c";e.clearRect(0,0,o,ro);for(let l of ao(t,n,o,a)){let{tier:d}=l,u=d!==void 0&&l.colors.length===1,f=u?2:l.colors.length;l.colors.forEach((p,h)=>{let m=u?d:h,g=oo(m,f,a);e.fillStyle=p,e.fillRect(l.x0,g,l.x1-l.x0,oo(m+1,f,a)-g)})}let i=io(t,n,o);if(i.left>0&&no(e,0,1,c),i.right>0&&no(e,o,-1,c),r){let[l,d]=ut(n,r.start,r.end),u=Math.max(d-l,3),f=(l+d)/2-u/2;e.strokeStyle=c,e.lineWidth=1.5,e.strokeRect(f,.75,u,$-1.5),r.anchor&&(e.beginPath(),e.moveTo(f+u/2,$),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function Ci(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function $i(e,t){let n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0)),s=Array.from({length:n+1},()=>new Array(o+1).fill(!1));for(let c=n-1;c>=0;c--)for(let i=o-1;i>=0;i--){let l=Math.abs(e[c]-t[i])+r[c+1][i+1],d=n-c>o-i?r[c+1][i]:1/0,u=o-i>n-c?r[c][i+1]:1/0;r[c][i]=Math.min(l,d,u),s[c][i]=r[c][i]===l}let a=new Array(n).fill(void 0);for(let c=0,i=0;c<n&&i<o;)s[c][i]?a[c++]=i++:n-c>o-i?c++:i++;return a}function co(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var lo=e=>e.spanningReads!==0;function Pi(e,t){return{...t,agrees:e.complete&&lo(t)?Ci(e.bp,t.bp):void 0}}function Li(e,t){let n=new Map,o=new Set,r=co(e,a=>a.bp),s=(a,c)=>{let i=[[a.filter(l=>l.item.complete),c.filter(lo)],[a,c]];for(let[l,d]of i){let u=l.filter(p=>!n.has(p.i)),f=co(d.filter(p=>!o.has(p)),p=>p.bp);$i(u.map(p=>p.item.bp),f.map(p=>p.item.bp)).forEach((p,h)=>{if(p!==void 0){let m=u[h],g=f[p].item;o.add(g),n.set(m.i,Pi(m.item,g))}})}};for(let a of new Set(t.flatMap(c=>c.haplotype??[])))s(r.filter(c=>c.item.haplotype===a),t.filter(c=>c.haplotype===a));return s(r,t.filter(a=>a.haplotype===void 0)),n}function Wd(e,t){if(!t)return e;let n=new Map,o=new Map;for(let r of e){let s=o.get(r.sample);s?s.push(r):o.set(r.sample,[r])}for(let[r,s]of o){let a=t[r];if(a)for(let[c,i]of Li(s,a))n.set(s[c],i)}return e.map(r=>({...r,call:n.get(r)}))}export{ya as a,wa as b,Ma as c,Ea as d,J as e,oi as f,Lo as g,Io as h,_a as i,Do as j,qo as k,Xc as l,k as m,N as n,$e as o,Kt as p,R as q,Go as r,Yo as s,K as t,Fe as u,Ge as v,Vt as w,Zt as x,Be as y,jo as z,Ko as A,tn as B,Qo as C,on as D,rn as E,Ye as F,Zo as G,er as H,an as I,z as J,se as K,Oe as L,ie as M,ho as N,mo as O,go as P,xo as Q,ir as R,cr as S,lr as T,fr as U,ae as V,ke as W,He as X,dr as Y,fn as Z,br as _,yr as $,Mr as aa,Er as ba,mn as ca,kc as da,Sr as ea,Nc as fa,Yc as ga,Wc as ha,qs as ia,Hs as ja,me as ka,it as la,rt as ma,zs as na,Js as oa,xe as pa,$l as qa,Pl as ra,Ll as sa,Il as ta,Bl as ua,Xl as va,ri as wa,Qn as xa,si as ya,ff as za,ai as Aa,df as Ba,uf as Ca,Zn as Da,pf as Ea,hf as Fa,li as Ga,mf as Ha,gf as Ia,xf as Ja,bf as Ka,yf as La,wf as Ma,Mf as Na,Ef as Oa,vf as Pa,Di as Qa,Wi as Ra,mi as Sa,_f as Ta,Tf as Ua,ea as Va,Ft as Wa,ta as Xa,Gt as Ya,Ne as Za,Yt as _a,Wt as $a,Po as ab,ft as bb,yi as cb,wi as db,Mi as eb,dt as fb,Ri as gb,_i as hb,ro as ib,Oi as jb,io as kb,Ai as lb,ki as mb,Ni as nb,Wd as ob};
2
+ //# sourceMappingURL=chunk-LBY7U6OJ.js.map