jbrowse-plugin-graphgenomeviewer 7.2.0 → 7.2.1

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 (110) hide show
  1. package/dist/chunks/GbzBaseSyntenyAdapter-FXMGIM7Z.js +2 -0
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-NB6WBBZH.js.map → GbzBaseSyntenyAdapter-FXMGIM7Z.js.map} +3 -3
  3. package/dist/chunks/{GraphGenomeView-4O5F5I37.js → GraphGenomeView-WJ3FIDY2.js} +2 -2
  4. package/dist/chunks/{GraphTrackSettingsDialog-WZEJAF7F.js → GraphTrackSettingsDialog-ZW7ALMDV.js} +2 -2
  5. package/dist/chunks/{HighlightColorDialog-SRT2FPXP.js → HighlightColorDialog-VBZRUKD5.js} +2 -2
  6. package/dist/chunks/{LinearGraphDisplay-Z33PVCJL.js → LinearGraphDisplay-SPOPTJEN.js} +2 -2
  7. package/dist/chunks/MinigraphBubbleAdapter-QCOMFPLL.js +2 -0
  8. package/dist/chunks/{MinigraphBubbleAdapter-HDLUZ6YF.js.map → MinigraphBubbleAdapter-QCOMFPLL.js.map} +1 -1
  9. package/dist/chunks/RgfaTabixAdapter-O3NMNRZ2.js +2 -0
  10. package/dist/chunks/RgfaTabixAdapter-O3NMNRZ2.js.map +7 -0
  11. package/dist/chunks/WalkTabixSyntenyAdapter-I3PY6HJ2.js +2 -0
  12. package/dist/chunks/{WalkTabixSyntenyAdapter-WBHOZLAN.js.map → WalkTabixSyntenyAdapter-I3PY6HJ2.js.map} +1 -1
  13. package/dist/chunks/chunk-2M4XYSLG.js +2 -0
  14. package/dist/chunks/chunk-2M4XYSLG.js.map +7 -0
  15. package/dist/chunks/{chunk-JLGPQO5L.js → chunk-2O3YVA2I.js} +2 -2
  16. package/dist/chunks/{chunk-CWNJR5XB.js → chunk-44CJ2N3N.js} +1 -1
  17. package/dist/chunks/{chunk-CWNJR5XB.js.map → chunk-44CJ2N3N.js.map} +1 -1
  18. package/dist/chunks/chunk-6KUHGRHU.js +2 -0
  19. package/dist/chunks/chunk-6KUHGRHU.js.map +7 -0
  20. package/dist/chunks/chunk-6MUBJVBG.js +2 -0
  21. package/dist/chunks/chunk-6MUBJVBG.js.map +7 -0
  22. package/dist/chunks/{chunk-GUXZESDR.js → chunk-7HWHWPRW.js} +1 -1
  23. package/dist/chunks/{chunk-GUXZESDR.js.map → chunk-7HWHWPRW.js.map} +1 -1
  24. package/dist/chunks/chunk-B2EP6FOQ.js +3 -0
  25. package/dist/chunks/chunk-B2EP6FOQ.js.map +7 -0
  26. package/dist/chunks/{chunk-44HZPYGC.js → chunk-BXRTG7FU.js} +2 -2
  27. package/dist/chunks/{chunk-44HZPYGC.js.map → chunk-BXRTG7FU.js.map} +1 -1
  28. package/dist/chunks/{chunk-HLKZCTQ3.js → chunk-DBPEUVUC.js} +1 -1
  29. package/dist/chunks/{chunk-HLKZCTQ3.js.map → chunk-DBPEUVUC.js.map} +1 -1
  30. package/dist/chunks/{chunk-FME624X3.js → chunk-DUR437TH.js} +2 -2
  31. package/dist/chunks/{chunk-FME624X3.js.map → chunk-DUR437TH.js.map} +1 -1
  32. package/dist/chunks/{chunk-6WA6WF6A.js → chunk-FIRQAKMX.js} +1 -1
  33. package/dist/chunks/{chunk-6WA6WF6A.js.map → chunk-FIRQAKMX.js.map} +1 -1
  34. package/dist/chunks/chunk-JCAZTNYG.js +2 -0
  35. package/dist/chunks/chunk-JCAZTNYG.js.map +7 -0
  36. package/dist/chunks/chunk-N74HGPAW.js +3 -0
  37. package/dist/chunks/chunk-N74HGPAW.js.map +7 -0
  38. package/dist/chunks/chunk-PEDWEPNK.js +2 -0
  39. package/dist/chunks/chunk-PEDWEPNK.js.map +7 -0
  40. package/dist/chunks/chunk-PYQG3JHP.js +3 -0
  41. package/dist/chunks/chunk-PYQG3JHP.js.map +7 -0
  42. package/dist/chunks/chunk-RFDSEB2X.js +4 -0
  43. package/dist/chunks/chunk-RFDSEB2X.js.map +7 -0
  44. package/dist/chunks/{chunk-O7Y7LYN6.js → chunk-RW775LQN.js} +2 -2
  45. package/dist/chunks/{chunk-O7Y7LYN6.js.map → chunk-RW775LQN.js.map} +1 -1
  46. package/dist/chunks/{chunk-N4WBX2OS.js → chunk-VQ77X5QU.js} +2 -2
  47. package/dist/chunks/{chunk-N4WBX2OS.js.map → chunk-VQ77X5QU.js.map} +1 -1
  48. package/dist/chunks/{chunk-LXCMWL7B.js → chunk-WUSKVEA6.js} +2 -2
  49. package/dist/chunks/{chunk-LXCMWL7B.js.map → chunk-WUSKVEA6.js.map} +1 -1
  50. package/dist/chunks/{chunk-ZNT7TQLN.js → chunk-YKSUKPYY.js} +2 -2
  51. package/dist/chunks/chunk-YKSUKPYY.js.map +7 -0
  52. package/dist/chunks/{renderSvg-RRWCAEGF.js → renderSvg-WD6YDV2I.js} +2 -2
  53. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +4 -4
  54. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  55. package/package.json +3 -3
  56. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.test.ts +2 -2
  57. package/src/GbzBaseSyntenyAdapter/GbzBaseSyntenyAdapter.ts +1 -1
  58. package/src/GetSubgraph.ts +1 -1
  59. package/src/GraphGenomeView/genes/genes.test.ts +20 -2
  60. package/src/GraphGenomeView/legendSections.test.ts +1 -1
  61. package/src/GraphGenomeView/legendSections.ts +1 -7
  62. package/src/GraphGenomeView/model.test.ts +1 -2
  63. package/src/GraphGenomeView/pane/graphViews.ts +24 -35
  64. package/src/GraphGenomeView/pane/loadActions.ts +4 -3
  65. package/src/GraphGenomeView/pane/paneBase.ts +1 -1
  66. package/src/GraphGenomeView/subgraphLoad.test.ts +41 -1
  67. package/src/GraphGenomeView/walkRowsCut.ts +10 -44
  68. package/src/RgfaTabixAdapter/RgfaTabixAdapter.test.ts +23 -4
  69. package/src/RgfaTabixAdapter/RgfaTabixAdapter.ts +2 -3
  70. package/src/RgfaTabixAdapter/bubbleTier.test.ts +1 -1
  71. package/src/RgfaTabixAdapter/walkCut.ts +20 -0
  72. package/src/RgfaTabixAdapter/walkFiles.test.ts +2 -2
  73. package/src/RgfaTabixAdapter/walkReader.ts +1 -1
  74. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.test.ts +1 -1
  75. package/src/version.ts +1 -1
  76. package/dist/chunks/GbzBaseSyntenyAdapter-NB6WBBZH.js +0 -2
  77. package/dist/chunks/MinigraphBubbleAdapter-HDLUZ6YF.js +0 -2
  78. package/dist/chunks/RgfaTabixAdapter-XZRTWQMZ.js +0 -3
  79. package/dist/chunks/RgfaTabixAdapter-XZRTWQMZ.js.map +0 -7
  80. package/dist/chunks/WalkTabixSyntenyAdapter-WBHOZLAN.js +0 -2
  81. package/dist/chunks/chunk-BWP3XYKD.js +0 -2
  82. package/dist/chunks/chunk-BWP3XYKD.js.map +0 -7
  83. package/dist/chunks/chunk-EDSIYH4H.js +0 -2
  84. package/dist/chunks/chunk-EDSIYH4H.js.map +0 -7
  85. package/dist/chunks/chunk-III4GT4G.js +0 -2
  86. package/dist/chunks/chunk-III4GT4G.js.map +0 -7
  87. package/dist/chunks/chunk-N5GYTUIL.js +0 -3
  88. package/dist/chunks/chunk-N5GYTUIL.js.map +0 -7
  89. package/dist/chunks/chunk-PA4HKAUJ.js +0 -2
  90. package/dist/chunks/chunk-PA4HKAUJ.js.map +0 -7
  91. package/dist/chunks/chunk-PFAHNHMM.js +0 -2
  92. package/dist/chunks/chunk-PFAHNHMM.js.map +0 -7
  93. package/dist/chunks/chunk-UFQTIWSN.js +0 -4
  94. package/dist/chunks/chunk-UFQTIWSN.js.map +0 -7
  95. package/dist/chunks/chunk-VDHDEEMF.js +0 -2
  96. package/dist/chunks/chunk-VDHDEEMF.js.map +0 -7
  97. package/dist/chunks/chunk-WGVATZLM.js +0 -3
  98. package/dist/chunks/chunk-WGVATZLM.js.map +0 -7
  99. package/dist/chunks/chunk-ZNT7TQLN.js.map +0 -7
  100. package/src/RgfaTabixAdapter/rgfaBed.test.ts +0 -254
  101. package/src/RgfaTabixAdapter/rgfaBed.ts +0 -314
  102. package/src/RgfaTabixAdapter/rgfaCut.ts +0 -139
  103. package/src/RgfaTabixAdapter/walkRowRuns.test.ts +0 -192
  104. package/src/RgfaTabixAdapter/walkRowRuns.ts +0 -520
  105. /package/dist/chunks/{GraphGenomeView-4O5F5I37.js.map → GraphGenomeView-WJ3FIDY2.js.map} +0 -0
  106. /package/dist/chunks/{GraphTrackSettingsDialog-WZEJAF7F.js.map → GraphTrackSettingsDialog-ZW7ALMDV.js.map} +0 -0
  107. /package/dist/chunks/{HighlightColorDialog-SRT2FPXP.js.map → HighlightColorDialog-VBZRUKD5.js.map} +0 -0
  108. /package/dist/chunks/{LinearGraphDisplay-Z33PVCJL.js.map → LinearGraphDisplay-SPOPTJEN.js.map} +0 -0
  109. /package/dist/chunks/{chunk-JLGPQO5L.js.map → chunk-2O3YVA2I.js.map} +0 -0
  110. /package/dist/chunks/{renderSvg-RRWCAEGF.js.map → renderSvg-WD6YDV2I.js.map} +0 -0
@@ -0,0 +1,2 @@
1
+ import{a as ft,c as ut,g as T,l as lt,r as q}from"./chunk-6MUBJVBG.js";import{b as dt}from"./chunk-7HWHWPRW.js";function J(){let t=new WeakMap;return(n,o,e)=>{let c=t.get(n);if(c?.deps.length===o.length&&c.deps.every((r,a)=>Object.is(r,o[a])))return c.value;let s=e();return t.set(n,{deps:o,value:s}),s}}var yt=11,Gt=6.2,D=4;function U(t){return t.length*Gt+D*2}function Ft(t,n){return t.x0<n.x1&&t.x1>n.x0&&t.y0<n.y1&&t.y1>n.y0}function xt(t,n){return t.x1<=0||t.x0>=n.width||t.y1<=0||t.y0>=n.height}function jt(t,n){return t.x0>=0&&t.x1<=n.width&&t.y0>=0&&t.y1<=n.height}function ht(t,n=[]){let o=[...n];return e=>xt(e,t)||o.some(c=>Ft(c,e))?!1:(o.push(e),!0)}function zn(t,n,o){let e=[],c=yt+D*2,s=(r,a)=>{let u=U(a),f=r.y>n.height/2?-1:1;for(let l=0;l<=(r.stack??0);l++){let y=r.y+f*l*c,x={x0:r.x-u/2,x1:r.x+u/2,y0:y-yt-D,y1:y+D};if(xt(x,n))return;if(jt(x,n)&&(r.fits?.(x)??!0)&&o(x))return{...r,text:a,y,w:u}}};for(let r of t){let a=s(r,r.text)??(r.fallback===void 0?void 0:s(r,r.fallback));a&&e.push(a)}return e}var pt=20;function Vn(t){let n=o=>Math.round(o*100)/100;return t.map((o,e)=>`${e?"L":"M"}${n(o.x)},${n(o.y)}`).join("")}function mt(t,n,o,e,c){let s=Math.hypot(e-n,o-t);if(s===0)return[o,e];let r=(o-t)/s,a=(e-n)/s;return[o+c*r,e+c*a]}function Q(t,n){let o=1-n,e=o*o*o,c=3*o*o*n,s=3*o*n*n,r=n*n*n;return{x:e*t.x0+c*t.cx0+s*t.cx1+r*t.x1,y:e*t.y0+c*t.cy0+s*t.cy1+r*t.y1}}function Lt(t){let n=t[Math.floor(t.length/2)];return n?Q(n,.5):void 0}function Et(t){let n=1/0,o=1/0,e=-1/0,c=-1/0;for(let s of t)n=Math.min(n,s.x0,s.cx0,s.cx1,s.x1),e=Math.max(e,s.x0,s.cx0,s.cx1,s.x1),o=Math.min(o,s.y0,s.cy0,s.cy1,s.y1),c=Math.max(c,s.y0,s.cy0,s.cy1,s.y1);return{minX:n,minY:o,maxX:e,maxY:c}}function zt(t,n,o){let e=Q(t,n),c=Q(t,o),s=(o-n)/3,r=Mt(t,n),a=Mt(t,o);return{x0:e.x,y0:e.y,cx0:e.x+r.x*s,cy0:e.y+r.y*s,cx1:c.x-a.x*s,cy1:c.y-a.y*s,x1:c.x,y1:c.y}}function Mt(t,n){let o=1-n,e=3*o*o,c=6*o*n,s=3*n*n;return{x:e*(t.cx0-t.x0)+c*(t.cx1-t.cx0)+s*(t.x1-t.cx1),y:e*(t.cy0-t.y0)+c*(t.cy1-t.cy0)+s*(t.y1-t.cy1)}}function Kn(t,n){let o=t.map(r=>Math.hypot(r.cx0-r.x0,r.cy0-r.y0)+Math.hypot(r.cx1-r.cx0,r.cy1-r.cy0)+Math.hypot(r.x1-r.cx1,r.y1-r.cy1)),e=o.reduce((r,a)=>r+a,0),c=Math.max(3,Math.round(e/n)|1),s=[];for(let r=0;r<c;r+=2){let a=r/c*e,u=(r+1)/c*e,f=[],l=0;t.forEach((y,x)=>{let i=o[x],d=l+i;i>0&&d>a&&l<u&&f.push(zt(y,Math.max(0,(a-l)/i),Math.min(1,(u-l)/i))),l=d}),f.length&&s.push(f)}return s}function Qn(t,n,o){let e=new Array(t.length);for(let c=0;c<t.length;c++){let s=t[c];e[c]={x0:s.x0+n,y0:s.y0+o,cx0:s.cx0+n,cy0:s.cy0+o,cx1:s.cx1+n,cy1:s.cy1+o,x1:s.x1+n,y1:s.y1+o}}return e}function k(t,n){let o=t.length-1;return n==="end"?{at:t[o],inward:t[o-1]}:{at:t[0],inward:t[1]}}var qt=.5,Jt=80;function H(t){return t.endsWith("-")?"-":"+"}function W(t){let n=(o,e)=>(e??H(o))===H(o);return{from:n(t.from,t.fromStrand)?"end":"start",to:n(t.to,t.toStrand)?"start":"end"}}function bt(t){let n=1/0,o=-1/0;for(let e of t)n=Math.min(n,e.x),o=Math.max(o,e.x);return{min:n,max:o}}function vt(t,n){return Math.max(0,n.min-t,t-n.max)}function gt(t,n,o){let e=vt(t[0].x,n),c=vt(t[t.length-1].x,n);return e===c?o:e<c?"start":"end"}function Ut(t,n){return{from:gt(t,bt(n),"end"),to:gt(n,bt(t),"start")}}var wt=new WeakMap;function Vt(t,n){let o=wt.get(t);o||(o=new WeakMap,wt.set(t,o));let e=o.get(n);return e||(e=Ut(t,n),o.set(n,e)),e}var Kt=.75,Qt=1.15,Zt=.35,tn=3*pt;function nn(t,n,o,e,c,s){let r=Math.hypot(o-t,e-n),a=r===0?1:(o-t)/r,u=r===0?0:(e-n)/r,f=0,l=1/0,y=-1/0;for(let h of c){let m=h.x-t,b=h.y-n,p=m*-u+b*a;Math.abs(p)>Math.abs(f)&&(f=p);let M=m*a+b*u;l=Math.min(l,M),y=Math.max(y,M)}let x=c.length?y-l:0,i=Math.max(Math.abs(f)*Qt/Kt,x*Zt),d=s===void 0?i:Math.min(i,s);return f<0?-d:d}function It({scaleX:t,scaleY:n}){return n/t}var on=3;function V(t,n,o){let e=n.x-t.x,c=(n.y-t.y)*o,s=Math.hypot(e,c);return s===0?void 0:{x:e/s,y:c/s}}function Zn(t,n,o,e){let c=It(e),s=on/Math.max(e.scaleX,1e-6),r=V(t[t.length-1],n[0],c)??V(t[0],t.at(-1),c)??V(n[0],n.at(-1),c)??{x:1,y:0},a=[];for(let u=0;u<o;u++){let f=(u-(o-1)/2)*s;a.push({x:-r.y*f,y:r.x*f/c})}return a}function K(t,n){return t.map(o=>({x:o.x,y:o.y*n}))}function en(t,n){for(let o of t)o.y0/=n,o.cy0/=n,o.cy1/=n,o.y1/=n;return t}function Z(t,n,o){let e=0;for(let c=1;c<t.length;c++){let s=t[c-1],r=t[c];e+=Math.hypot((r.x-s.x)*n,(r.y-s.y)*o)}return e}var rn=12,sn=40;function At(t,n){let o=Z(t,n,n);return Math.min(sn,Math.max(rn,o/2))/Math.max(n,Number.EPSILON)}function cn(t){return t.from!==t.to?!1:t.fromStrand&&t.toStrand&&t.fromStrand!==t.toStrand?t.fromStrand==="+"?"end":"start":!0}function Ot(t,n=!1){let o=cn(t);if(!n)return o;let e=W(t);return o===!1?e:e.from===e.to?e.from:!0}function an(t,n){let{at:o,inward:e}=t,c=e?o.x-e.x:1,s=e?o.y-e.y:0,r=Math.hypot(c,s)||1,a=c/r,u=s/r,f=o.x,l=o.y,y=f+a*n/3,x=l+u*n/3,i=f+a*n,d=l+u*n,h=-u*n/2,m=a*n/2;return[{x0:f,y0:l,cx0:y,cy0:x,cx1:i+h,cy1:d+m,x1:i,y1:d},{x0:i,y0:d,cx0:i-h,cy0:d-m,cx1:y,cy1:x,x1:f,y1:l}]}function tt(t,n,o,e,c=[],s){let r=e.scaleX,a=It(e),u=s??(e.pixelRows?tn:void 0);if(o===!1&&(o=Vt(t,n)),a!==1)return en(tt(K(t,a),K(n,a),o,{scaleX:r,scaleY:r},K(c,a),u===void 0?void 0:u*a),a);if(typeof o=="string")return an(k(t,o),At(t,r));let f=o===!0,l=o===!0?{from:"end",to:"start"}:o,y=k(t,l.from),x=k(n,l.to),i=y.at,d=x.at,h=i.x,m=i.y,b=d.x,p=d.y;if(f){let M=1,A=0;if(y.inward){let X=i.x-y.inward.x,P=i.y-y.inward.y,S=Math.hypot(X,P);S>0&&(M=X/S,A=P/S)}let v=At(t,r),_=-A,w=M,E=(i.x+d.x)/2+_*v,L=(i.y+d.y)/2+w*v,g=h+M*v,N=m+A*v,O=b-M*v,I=p-A*v;return[{x0:h,y0:m,cx0:g,cy0:N,cx1:g+_*v,cy1:N+w*v,x1:E,y1:L},{x0:E,y0:L,cx0:O+_*v,cy0:I+w*v,cx1:O,cy1:I,x1:b,y1:p}]}else{let M=y.inward??{x:i.x-(d.x-i.x),y:i.y-(d.y-i.y)},A=x.inward??{x:d.x-(i.x-d.x),y:d.y-(i.y-d.y)},v=Math.hypot(b-h,p-m),_=(rt,st,Wt,Yt)=>{let ct=st.x-rt.x,at=st.y-rt.y,it=Math.hypot(ct,at),Dt=it===0?0:(Wt*ct+Yt*at)/it;return Math.max(0,Math.min(v*qt,Jt,Dt*.5))},w=d.x-i.x,E=d.y-i.y,[L,g]=mt(M.x,M.y,i.x,i.y,_(M,i,w,E)),[N,O]=mt(A.x,A.y,d.x,d.y,_(A,d,-w,-E)),I=c.length?nn(h,m,b,p,c,u):0,X=v===0?1:v,P=(b-h)/X,S=(p-m)/X,$=-S*I,C=P*I,R=P*Math.abs(I),et=S*Math.abs(I);return[{x0:h,y0:m,cx0:L+$-R,cy0:g+C-et,cx1:N+$+R,cy1:O+C+et,x1:b,y1:p}]}}function _t(t,n){let o=t[0],e=t.at(-1);return Math.hypot(o.x-n.x,o.y-n.y)<Math.hypot(e.x-n.x,e.y-n.y)?"start":"end"}function Xt(t,n,o,e){let c=k(t,e?.from??_t(t,o[0])),s=k(n,e?.to??_t(n,o.at(-1))),r=[c.at,...o,s.at],a=f=>{let l=r[f],y=i=>Math.hypot(i.x-l.x,i.y-l.y),x=(i,d)=>{let h=i?y(i):0,m=y(d);return h===0?{x:d.x-l.x,y:d.y-l.y}:{x:(l.x-i.x)/h*m,y:(l.y-i.y)/h*m}};if(f===0)return x(c.inward,r[1]);if(f===r.length-1){let i=x(s.inward,r[f-1]);return{x:-i.x,y:-i.y}}return{x:(r[f+1].x-r[f-1].x)/2,y:(r[f+1].y-r[f-1].y)/2}},u=[];for(let f=0;f<r.length-1;f++){let l=r[f],y=r[f+1],x=a(f),i=a(f+1);u.push({x0:l.x,y0:l.y,cx0:l.x+x.x/3,cy0:l.y+x.y/3,cx1:y.x-i.x/3,cy1:y.y-i.y/3,x1:y.x,y1:y.y})}return u}function Pt(t){return t==="+"?"-":"+"}function ro(t,n=new Set){let o=t.edges.map(W),e=new Map,c=(i,d,h)=>{ft(e,`${i}|${d}`,h)};t.edges.forEach((i,d)=>{c(i.from,o[d].from,d),c(i.to,o[d].to,d)});let s=i=>{let d=e.get(`${i}|end`);if(d?.length!==1)return;let h=d[0],m=t.edges[h];return m.from===i&&m.to!==i&&!n.has(i)&&!n.has(m.to)&&o[h].from==="end"&&o[h].to==="start"&&e.get(`${m.to}|start`)?.length===1?h:void 0},r=new Set,a=new Map,u=new Map;for(let i of t.nodes){let d=e.get(`${i.id}|start`),h=d?.length===1?t.edges[d[0]].from:void 0;if(a.has(i.id)||h!==void 0&&s(h)===d[0])continue;let m=[i.id];for(;;){let b=s(m.at(-1)),p=b===void 0?void 0:t.edges[b].to;if(p===void 0||a.has(p))break;r.add(b),m.push(p)}for(let b of m)a.set(b,i.id);m.length>1&&u.set(i.id,m)}for(let i of t.nodes)a.has(i.id)||a.set(i.id,i.id);let f=new Map(t.nodes.map(i=>[i.id,i])),l=[];for(let i of t.nodes){if(a.get(i.id)!==i.id)continue;let d=u.get(i.id);if(!d){l.push(i);continue}let h=d.map(p=>f.get(p)),m=h.filter(T),b=m.length?m.reduce((p,M)=>p.stable.start<=M.stable.start?p:M):h[0];l.push({id:i.id,name:i.name,length:h.reduce((p,M)=>p+M.length,0),depth:i.depth,stable:b.stable})}let y=new Set,x=[];return t.edges.forEach((i,d)=>{let h=a.get(i.from),m=a.get(i.to),b=o[d],p=`${h}|${b.from}>${m}|${b.to}`;r.has(d)||y.has(p)||(y.add(p),x.push({from:h,to:m,...b.from==="start"?{fromStrand:Pt(H(h))}:{},...b.to==="end"?{toStrand:Pt(H(m))}:{}}))}),{graph:{...t,nodes:l,edges:x,paths:void 0,pathVisits:void 0},runs:u}}function so(t,n,o){let e={...t};for(let[c,s]of n){let r=t[c];if(!r?.length)continue;delete e[c];let a=ot(r),u=a.at(-1),f=s.map(x=>Math.max(o(x),0)),l=f.reduce((x,i)=>x+i,0),y=0;s.forEach((x,i)=>{let d=l?f[i]/l*u:u/s.length,h=i===s.length-1?u:y+d;e[x]=St(r,a,y,h),y=h})}return e}function co(t,n,o){if(t.length===0)return[];let e=ot(t),c=e.at(-1);return St(t,e,n*c,o*c)}function Nt(t){let n=ot(t);return nt(t,n,n.at(-1)/2)}function ot(t){let n=[0];for(let o=1;o<t.length;o++)n.push(n[o-1]+Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y));return n}function nt(t,n,o){if(o<=0)return{...t[0]};let e=1;for(;e<n.length&&n[e]<o;)e++;if(e>=n.length)return{...t.at(-1)};let c=n[e]-n[e-1],s=c>0?(o-n[e-1])/c:0,r=t[e-1],a=t[e];return{x:r.x+(a.x-r.x)*s,y:r.y+(a.y-r.y)*s}}function St(t,n,o,e){let c=[nt(t,n,o)];for(let s=0;s<t.length;s++)n[s]>o&&n[s]<e&&c.push({...t[s]});return c.push(nt(t,n,e)),c}var fn=1;function un(t,n){return n.flatMap(o=>t[o]??[])}function Ct(t,n,o,e,c,s){let r=t[n.from],a=t[n.to];if(!(!r?.length||!a?.length))return c?Xt(r,a,c,s?W(n):void 0):tt(r,a,Ot(n,s),o,e?un(t,e):[])}function ln(t){let n=ut(t.nodes.filter(T),o=>o.stable.refName);for(let o of n.values())o.sort((e,c)=>e.stable.start-c.stable.start);return n}function dn(t,n,o){let e=[];if(t)for(let c=lt(t,n);c<t.length;c++){let s=t[c];if(s.stable.start>=o)break;s.stable.start+s.length<=o&&e.push(s.id)}return e}function yn(t,n,o,e){let{fromStrand:c,toStrand:s}=t;if(c===void 0||s===void 0)return!0;let r=c===(n.stable.strand??"+"),a=s===(o.stable.strand??"+");return e?r&&a:!r&&!a}function lo(t){let n=new Map(t.nodes.map(c=>[c.id,c])),o=ln(t),e=[];for(let c=0;c<t.edges.length;c++){let s=t.edges[c],r=n.get(s.from),a=n.get(s.to);if(r!==void 0&&a!==void 0&&T(r)&&T(a)&&r.stable.refName===a.stable.refName){let u=r.stable.start<=a.stable.start,[f,l]=u?[r,a]:[a,r],y=f.stable.start+f.length,x=l.stable.start,i=x-y;if(i>=fn&&yn(s,r,a,u)){let d=f.stable.refName;e.push({edgeIndex:c,from:s.from,to:s.to,...s.fromStrand?{fromStrand:s.fromStrand}:{},...s.toStrand?{toStrand:s.toStrand}:{},refName:d,start:y,end:x,bp:i,bypassed:dn(o.get(d),y,x)})}}}return e}function xn(t,n){let o=new Map,e=r=>{let a=r;for(;o.has(a);)a=o.get(a);return a!==r&&o.set(r,a),a},c=(r,a)=>{let[u,f]=[e(r),e(a)];return u!==f&&o.set(u,f),u!==f},s=new Set(n.map(r=>r.edgeIndex));return t.edges.forEach((r,a)=>{s.has(a)||c(r.from,r.to)}),new Set(n.filter(r=>!c(r.from,r.to)).map(r=>r.edgeIndex))}var Bt=new WeakMap;function yo(t,n,o=!0){let e=Bt.get(n);e||(e=new Map,Bt.set(n,e));let c=e.get(o);if(!c){let s=o?new Set:xn(t,n);c={shown:n.filter(r=>!s.has(r.edgeIndex)),bypassed:new Map(n.map(r=>[r.edgeIndex,r.bypassed])),hidden:s},e.set(o,c)}return c}var hn=26,pn=4e4,mn=8,Mn=8,bn=5.7,vn=6,gn=13,Y=3,G=2;function z(t){return(t.length*bn+vn+Y)/2}var B=(gn+Y)/2,wn=z("1 bp");function F(t,n,o){return{x0:n-t,x1:n+t,y0:o-B,y1:o+B}}function vo(t,n){return{x0:6,x1:6+U(t)+Y,y0:n-8-Y/2,y1:n+8+Y/2}}function j(t,n,o){return o<n?t:Math.min(Math.max(t,n),o)}function Rt(t){return String(t).replace(/\B(?=(\d{3})+$)/g,",")}function kt(t){let[n,o]=t>=1e6?[t/1e6,"Mb"]:t>=1e3?[t/1e3,"kb"]:[];return n===void 0?`${t} bp`:`${+n.toFixed(n>=100?0:1)} ${o}`}function Tt(t){return`${kt(t)} del`}function An(t,n,o,e){let c=t[0],s=t[t.length-1],r=(n.x-(c.x0+s.x1)/2)*o,a=(n.y-(c.y0+s.y1)/2)*e,u=Math.hypot(r,a);return u===0?{x:0,y:-1}:{x:r/u,y:a/u}}function _n(t,n){return Math.abs(n.x)*(t.x1-t.x0)/2+Math.abs(n.y)*(t.y1-t.y0)/2}function Ln(t,n){let o=(t.x1-t.x0)/2,e=(t.y1-t.y0)/2;return Math.min(n.x===0?1/0:o/Math.abs(n.x),n.y===0?1/0:e/Math.abs(n.y))}function En(t,n){let o=1/0,e=1/0,c=-1/0,s=-1/0;for(let r of t)for(let a of n[r]??[])o=Math.min(o,a.x),c=Math.max(c,a.x),e=Math.min(e,a.y),s=Math.max(s,a.y);return o===1/0?void 0:{minX:o,minY:e,maxX:c,maxY:s}}var In=J();function On(t,n){return In(t,[n],()=>Object.entries(t).filter(([o,e])=>e.length>0&&n.has(o)).sort(([o],[e])=>n.get(e)-n.get(o)))}var Xn=J();function Pn(t,n,o,e,c,s){let{scaleX:r,scaleY:a}=o;return Xn(t,[n,c,s,r,a,e],()=>{let u=[];for(let f of[...n].sort((l,y)=>y.bp-l.bp)){let l=Ct(t,f,o,f.bypassed,c?.[f.edgeIndex],s),y=l?Lt(l):void 0;if(l&&y){let{minX:x,minY:i,maxX:d,maxY:h}=Et(l);u.push({deletion:f,curves:l,apex:y,extent:Math.max((d-x)*r,(h-i)*a)})}}return u})}function Nn({nodePositions:t,nodeLengths:n,deletions:o,deletionRoutes:e,stranded:c=!1,alleleDeletions:s,axis:r,translateX:a,translateY:u,width:f,height:l,version:y=0}){let{scaleX:x,scaleY:i}=r,d=[],h=[];for(let{deletion:p,curves:M,apex:A,extent:v}of Pn(t,o,r,y,e,c))if(v>=hn){let _=Tt(p.bp),w=z(_),E=F(w,0,0),L=A.x*x+a,g=A.y*i+u;if(L<0||L>f||g<0||g>l)continue;let N=v>=w*2/G,O=An(M,A,x,i),I=_n(E,O)+Mn,X=N?L:j(L+O.x*I,w,f-w),P=N?g:j(g+O.y*I,B,l-B),S=Math.hypot(X-L,P-g),$;if(S>0){let C={x:(X-L)/S,y:(P-g)/S},R=Ln(E,C);$={arcX:L,arcY:g,labelX:X-C.x*R,labelY:P-C.y*R}}d.push({label:{key:`del:${p.edgeIndex}`,text:_,x:X,y:P,kind:"deletion",leader:$},box:F(w,X,P)})}let m=new Set,b=[...s??[]].sort((p,M)=>M.bp-p.bp);for(let p of b){let M=En(p.nodeIds,t);if(!M)continue;let A=Math.max(M.minX*x+a,0),v=Math.min(M.maxX*x+a,f),_=Math.max(M.minY*i+u,0),w=Math.min(M.maxY*i+u,l);if(v<A||w<_)continue;let E=Math.max(v-A,w-_),L=Tt(p.bp),g=z(L);if(E>=g*2/G){for(let I of p.nodeIds)m.add(I);let N=j((A+v)/2,g,f-g),O=j((_+w)/2,B,l-B);d.push({label:{key:`alleledel:${p.nodeIds.join(",")}`,text:L,x:N,y:O,kind:"deletion"},box:F(g,N,O)})}}for(let[p,M]of On(t,n)){if(m.has(p))continue;let{x:A,y:v}=Nt(M),_=v*i+u;if(_+B<=0||_-B>=l)continue;let w=Z(M,x,i);if(w<wn*2/G)continue;let E=kt(n.get(p)),L=z(E);if(w>=L*2/G){let g=A*x+a;h.push({label:{key:`node:${p}`,text:E,x:g,y:_,kind:"node"},box:F(L,g,_)})}}return{deletions:d,nodes:h}}function Sn(t,n){return Math.max(mn,Math.floor(t*n/pn))}function $t(t,n,o=1/0){let e=[];for(let{label:c,box:s}of t){if(e.length>=o)break;n(s)&&e.push(c)}return e}function go({reserved:t,take:n,...o}){n??=ht(o,t);let{deletions:e,nodes:c}=Nn(o);return[...$t(e,n),...$t(c,n,Sn(o.width,o.height))]}function Eo(t){let n=0;for(let o=0;o<t.length;o++)n=t.charCodeAt(o)+((n<<5)-n);return Math.abs(n%360)}function Bn(t,n){return t*360/n}var Cn=.7,Tn=.5,$n=16;function Io(t){return t>0&&t<=$n}function Rn(t,n){return`hsl(${Bn(t,n)}, ${Cn*100}%, ${Tn*100}%)`}function Oo(t,n){return`hsl(0, 0%, ${n>1?25+45*t/(n-1):45}%)`}function kn(t){let n=q(t).name.split("#"),o=n.join("#");if(n.length>=3&&dt(n[0])){let e=n.slice(2).join("#");return[e,e,o]}return[n[0],n.slice(0,2).join("#"),o]}function Hn(t,n){let{start:o}=q(t);return n.map(e=>`${e} @${Rt(o)}`)}function Xo(t,n){let o=new Map;t.forEach((u,f)=>{o.has(u.name)||o.set(u.name,f)});let e=[...o].map(([u,f])=>({name:u,i:f})),c=e.map(u=>kn(u.name)),s=[0,1,2].flatMap(u=>[e.map((f,l)=>c[l][u]),e.map((f,l)=>Hn(f.name,c[l])[u])]),a=s.find(u=>new Set(u).size===e.length)??s.at(-1);return e.map(({name:u,i:f},l)=>({name:u,label:a[l],color:n?.[f]??Rn(f,t.length)}))}function Po(t){let n=new Map;return new Map([...t].sort((o,e)=>o.label.localeCompare(e.label)).map(o=>{let e=(n.get(o.label)??0)+1;return n.set(o.label,e),[o.name,e>1?`${o.label} (${e})`:o.label]}))}var So=[{value:"depth",label:"By depth",description:"Thicker the more paths carry a node, on the square root of its depth against the mean. A graph with one depth everywhere draws uniform."},{value:"uniform",label:"Uniform",description:"Every node the same thickness."}],Wn=.3,Ht=3;function Yn(t){let n=0,o=0;for(let e of t.nodes)n+=e.depth*e.length,o+=e.length;return o>0?n/o:0}function Dn(t,n){return!(n>0)||!(t.depth>0)?1:Math.min(Ht,Math.max(Wn,Math.sqrt(t.depth/n)))}function Gn(t,n,o,e){return n*(o==="depth"?Dn(t,e):1)}function Fn(t,n){return t*(n==="depth"?Ht:1)}function Bo(t,n,o,e){let c=t?Yn(t):0;return{maxHalfWidthPx:Fn(o,e)/2,halfWidthPx:s=>{let r=n?.get(s);return r?Gn(r,o,e,c)/2:o/2}}}export{J as a,yt as b,Gt as c,D as d,U as e,ht as f,zn as g,pt as h,Vn as i,Et as j,Kn as k,Qn as l,H as m,W as n,It as o,Zn as p,Z as q,ro as r,so as s,co as t,Ct as u,lo as v,yo as w,vo as x,Rt as y,kt as z,go as A,Eo as B,Bn as C,Cn as D,Tn as E,$n as F,Io as G,Rn as H,Oo as I,Xo as J,Po as K,So as L,Yn as M,Gn as N,Bo as O};
2
+ //# sourceMappingURL=chunk-PEDWEPNK.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-HMXCN6PG.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-AB35TJST.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-CPMHA4W5.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-UBQSRCWR.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-BZFOFC4D.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-CGMSKIEO.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-PFRQBCGC.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-3GP3KT5L.js", "../../node_modules/.pnpm/@jbrowse+bandage-core@11.4.0/node_modules/@jbrowse/bandage-core/dist/chunks/chunk-CRCD3ODN.js"],
4
+ "sourcesContent": ["// src/util/weakMemo.ts\nfunction weakMemo() {\n const cache = /* @__PURE__ */ new WeakMap();\n return (key, deps, compute) => {\n const hit = cache.get(key);\n if (hit?.deps.length === deps.length && hit.deps.every((d, i) => Object.is(d, deps[i]))) {\n return hit.value;\n }\n const value = compute();\n cache.set(key, { deps, value });\n return value;\n };\n}\n\nexport {\n weakMemo\n};\n", "// src/overlayLabels.ts\nvar LABEL_PX = 11;\nvar LABEL_CHAR_PX = 6.2;\nvar LABEL_PAD = 4;\nfunction labelWidth(text) {\n return text.length * LABEL_CHAR_PX + LABEL_PAD * 2;\n}\nfunction overlaps(a, b) {\n return a.x0 < b.x1 && a.x1 > b.x0 && a.y0 < b.y1 && a.y1 > b.y0;\n}\nfunction offFrame(box, frame) {\n return box.x1 <= 0 || box.x0 >= frame.width || box.y1 <= 0 || box.y0 >= frame.height;\n}\nfunction insideFrame(box, frame) {\n return box.x0 >= 0 && box.x1 <= frame.width && box.y0 >= 0 && box.y1 <= frame.height;\n}\nfunction occupancy(frame, reserved = []) {\n const placed = [...reserved];\n return (box) => {\n if (offFrame(box, frame) || placed.some((p) => overlaps(p, box))) {\n return false;\n }\n placed.push(box);\n return true;\n };\n}\nfunction placeLabels(candidates, frame, take) {\n const out = [];\n const row = LABEL_PX + LABEL_PAD * 2;\n const place = (c, text) => {\n const w = labelWidth(text);\n const direction = c.y > frame.height / 2 ? -1 : 1;\n for (let tries = 0; tries <= (c.stack ?? 0); tries++) {\n const y = c.y + direction * tries * row;\n const box = {\n x0: c.x - w / 2,\n x1: c.x + w / 2,\n y0: y - LABEL_PX - LABEL_PAD,\n y1: y + LABEL_PAD\n };\n if (offFrame(box, frame)) {\n return void 0;\n }\n if (insideFrame(box, frame) && (c.fits?.(box) ?? true) && take(box)) {\n return { ...c, text, y, w };\n }\n }\n return void 0;\n };\n for (const c of candidates) {\n const placed = place(c, c.text) ?? (c.fallback === void 0 ? void 0 : place(c, c.fallback));\n if (placed) {\n out.push(placed);\n }\n }\n return out;\n}\n\nexport {\n LABEL_PX,\n LABEL_CHAR_PX,\n LABEL_PAD,\n labelWidth,\n overlaps,\n occupancy,\n placeLabels\n};\n", "// src/layout/rowSpacing.ts\nvar ROW_HEIGHT_PX = 20;\n\nexport {\n ROW_HEIGHT_PX\n};\n", "import {\n ROW_HEIGHT_PX\n} from \"./chunk-CPMHA4W5.js\";\n\n// src/util/geometry.ts\nfunction svgPath(points) {\n const round = (v) => Math.round(v * 100) / 100;\n return points.map((p, i) => `${i ? \"L\" : \"M\"}${round(p.x)},${round(p.y)}`).join(\"\");\n}\nfunction projectLine(x1, y1, x2, y2, distance) {\n const d = Math.hypot(y2 - y1, x2 - x1);\n if (d === 0) {\n return [x2, y2];\n }\n const vx = (x2 - x1) / d;\n const vy = (y2 - y1) / d;\n return [x2 + distance * vx, y2 + distance * vy];\n}\nfunction curvePointAt(c, t) {\n const u = 1 - t;\n const a = u * u * u;\n const b = 3 * u * u * t;\n const d = 3 * u * t * t;\n const e = t * t * t;\n return {\n x: a * c.x0 + b * c.cx0 + d * c.cx1 + e * c.x1,\n y: a * c.y0 + b * c.cy0 + d * c.cy1 + e * c.y1\n };\n}\nfunction curveMidpoint(curves) {\n const mid = curves[Math.floor(curves.length / 2)];\n return mid ? curvePointAt(mid, 0.5) : void 0;\n}\nfunction curveBounds(curves) {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const c of curves) {\n minX = Math.min(minX, c.x0, c.cx0, c.cx1, c.x1);\n maxX = Math.max(maxX, c.x0, c.cx0, c.cx1, c.x1);\n minY = Math.min(minY, c.y0, c.cy0, c.cy1, c.y1);\n maxY = Math.max(maxY, c.y0, c.cy0, c.cy1, c.y1);\n }\n return { minX, minY, maxX, maxY };\n}\nfunction subCurve(c, t0, t1) {\n const p0 = curvePointAt(c, t0);\n const p1 = curvePointAt(c, t1);\n const dt = (t1 - t0) / 3;\n const d0 = curveTangentAt(c, t0);\n const d1 = curveTangentAt(c, t1);\n return {\n x0: p0.x,\n y0: p0.y,\n cx0: p0.x + d0.x * dt,\n cy0: p0.y + d0.y * dt,\n cx1: p1.x - d1.x * dt,\n cy1: p1.y - d1.y * dt,\n x1: p1.x,\n y1: p1.y\n };\n}\nfunction curveTangentAt(c, t) {\n const u = 1 - t;\n const a = 3 * u * u;\n const b = 6 * u * t;\n const d = 3 * t * t;\n return {\n x: a * (c.cx0 - c.x0) + b * (c.cx1 - c.cx0) + d * (c.x1 - c.cx1),\n y: a * (c.cy0 - c.y0) + b * (c.cy1 - c.cy0) + d * (c.y1 - c.cy1)\n };\n}\nfunction dashCurves(curves, dashWorld) {\n const lengths = curves.map(\n (c) => Math.hypot(c.cx0 - c.x0, c.cy0 - c.y0) + Math.hypot(c.cx1 - c.cx0, c.cy1 - c.cy0) + Math.hypot(c.x1 - c.cx1, c.y1 - c.cy1)\n );\n const total = lengths.reduce((a, b) => a + b, 0);\n const spans = Math.max(3, Math.round(total / dashWorld) | 1);\n const out = [];\n for (let i = 0; i < spans; i += 2) {\n const from = i / spans * total;\n const to = (i + 1) / spans * total;\n const dash = [];\n let start = 0;\n curves.forEach((c, k) => {\n const length = lengths[k];\n const end = start + length;\n if (length > 0 && end > from && start < to) {\n dash.push(\n subCurve(\n c,\n Math.max(0, (from - start) / length),\n Math.min(1, (to - start) / length)\n )\n );\n }\n start = end;\n });\n if (dash.length) {\n out.push(dash);\n }\n }\n return out;\n}\nfunction translateCurves(curves, dx, dy) {\n const out = new Array(curves.length);\n for (let i = 0; i < curves.length; i++) {\n const c = curves[i];\n out[i] = {\n x0: c.x0 + dx,\n y0: c.y0 + dy,\n cx0: c.cx0 + dx,\n cy0: c.cy0 + dy,\n cx1: c.cx1 + dx,\n cy1: c.cy1 + dy,\n x1: c.x1 + dx,\n y1: c.y1 + dy\n };\n }\n return out;\n}\nfunction attachment(segments, side) {\n const last = segments.length - 1;\n return side === \"end\" ? { at: segments[last], inward: segments[last - 1] } : { at: segments[0], inward: segments[1] };\n}\nvar TANGENT_SPAN_FACTOR = 0.5;\nvar MAX_TANGENT = 80;\nfunction ownStrand(id) {\n return id.endsWith(\"-\") ? \"-\" : \"+\";\n}\nfunction strandSides(edge) {\n const own = (id, strand) => (strand ?? ownStrand(id)) === ownStrand(id);\n return {\n from: own(edge.from, edge.fromStrand) ? \"end\" : \"start\",\n to: own(edge.to, edge.toStrand) ? \"start\" : \"end\"\n };\n}\nfunction spanOf(segments) {\n let min = Infinity;\n let max = -Infinity;\n for (const s of segments) {\n min = Math.min(min, s.x);\n max = Math.max(max, s.x);\n }\n return { min, max };\n}\nfunction distanceToSpan(x, span) {\n return Math.max(0, span.min - x, x - span.max);\n}\nfunction facingSide(segments, other, tieBreak) {\n const startGap = distanceToSpan(segments[0].x, other);\n const endGap = distanceToSpan(segments[segments.length - 1].x, other);\n return startGap === endGap ? tieBreak : startGap < endGap ? \"start\" : \"end\";\n}\nfunction facingSides(fromSegments, toSegments) {\n return {\n from: facingSide(fromSegments, spanOf(toSegments), \"end\"),\n to: facingSide(toSegments, spanOf(fromSegments), \"start\")\n };\n}\nvar laidSides = /* @__PURE__ */ new WeakMap();\nfunction heldFacingSides(fromSegments, toSegments) {\n let byTo = laidSides.get(fromSegments);\n if (!byTo) {\n byTo = /* @__PURE__ */ new WeakMap();\n laidSides.set(fromSegments, byTo);\n }\n let sides = byTo.get(toSegments);\n if (!sides) {\n sides = facingSides(fromSegments, toSegments);\n byTo.set(toSegments, sides);\n }\n return sides;\n}\nvar APEX_FRACTION = 0.75;\nvar BOW_CLEARANCE = 1.15;\nvar ALONG_FRACTION = 0.35;\nvar MAX_ROW_BOW_PX = 3 * ROW_HEIGHT_PX;\nfunction bowAround(p1x, p1y, p2x, p2y, toward, maxBow) {\n const chord = Math.hypot(p2x - p1x, p2y - p1y);\n const ux = chord === 0 ? 1 : (p2x - p1x) / chord;\n const uy = chord === 0 ? 0 : (p2y - p1y) / chord;\n let reach = 0;\n let minAlong = Infinity;\n let maxAlong = -Infinity;\n for (const p of toward) {\n const dx = p.x - p1x;\n const dy = p.y - p1y;\n const perp = dx * -uy + dy * ux;\n if (Math.abs(perp) > Math.abs(reach)) {\n reach = perp;\n }\n const along = dx * ux + dy * uy;\n minAlong = Math.min(minAlong, along);\n maxAlong = Math.max(maxAlong, along);\n }\n const span = toward.length ? maxAlong - minAlong : 0;\n const uncapped = Math.max(\n Math.abs(reach) * BOW_CLEARANCE / APEX_FRACTION,\n span * ALONG_FRACTION\n );\n const size = maxBow === void 0 ? uncapped : Math.min(uncapped, maxBow);\n return reach < 0 ? -size : size;\n}\nfunction yToXOf({ scaleX, scaleY }) {\n return scaleY / scaleX;\n}\nvar PATH_RIBBON_SPACING_PX = 3;\nfunction drawnDirection(a, b, yToX) {\n const dx = b.x - a.x;\n const dy = (b.y - a.y) * yToX;\n const len = Math.hypot(dx, dy);\n return len === 0 ? void 0 : { x: dx / len, y: dy / len };\n}\nfunction pathRibbonOffsets(fromSegments, toSegments, count, axis) {\n const yToX = yToXOf(axis);\n const spacing = PATH_RIBBON_SPACING_PX / Math.max(axis.scaleX, 1e-6);\n const dir = drawnDirection(\n fromSegments[fromSegments.length - 1],\n toSegments[0],\n yToX\n ) ?? drawnDirection(fromSegments[0], fromSegments.at(-1), yToX) ?? drawnDirection(toSegments[0], toSegments.at(-1), yToX) ?? { x: 1, y: 0 };\n const offsets = [];\n for (let i = 0; i < count; i++) {\n const distance = (i - (count - 1) / 2) * spacing;\n offsets.push({ x: -dir.y * distance, y: dir.x * distance / yToX });\n }\n return offsets;\n}\nfunction scaleYOf(points, yToX) {\n return points.map((p) => ({ x: p.x, y: p.y * yToX }));\n}\nfunction unscaleYOf(curves, yToX) {\n for (const c of curves) {\n c.y0 /= yToX;\n c.cy0 /= yToX;\n c.cy1 /= yToX;\n c.y1 /= yToX;\n }\n return curves;\n}\nfunction polylinePx(points, scaleX, scaleY) {\n let total = 0;\n for (let i = 1; i < points.length; i++) {\n const a = points[i - 1];\n const b = points[i];\n total += Math.hypot((b.x - a.x) * scaleX, (b.y - a.y) * scaleY);\n }\n return total;\n}\nvar SELF_LOOP_MIN_PX = 12;\nvar SELF_LOOP_MAX_PX = 40;\nfunction selfLoopReach(segments, scale) {\n const nodePx = polylinePx(segments, scale, scale);\n const reachPx = Math.min(\n SELF_LOOP_MAX_PX,\n Math.max(SELF_LOOP_MIN_PX, nodePx / 2)\n );\n return reachPx / Math.max(scale, Number.EPSILON);\n}\nfunction selfLinkOf(edge) {\n if (edge.from !== edge.to) {\n return false;\n }\n return edge.fromStrand && edge.toStrand && edge.fromStrand !== edge.toStrand ? edge.fromStrand === \"+\" ? \"end\" : \"start\" : true;\n}\nfunction edgeJoinOf(edge, stranded = false) {\n const self = selfLinkOf(edge);\n if (!stranded) {\n return self;\n }\n const sides = strandSides(edge);\n return self === false ? sides : sides.from === sides.to ? sides.from : true;\n}\nfunction hairpinCurves(attach, reach) {\n const { at, inward } = attach;\n const dx = inward ? at.x - inward.x : 1;\n const dy = inward ? at.y - inward.y : 0;\n const len = Math.hypot(dx, dy) || 1;\n const ux = dx / len;\n const uy = dy / len;\n const px = at.x;\n const py = at.y;\n const nearX = px + ux * reach / 3;\n const nearY = py + uy * reach / 3;\n const apexX = px + ux * reach;\n const apexY = py + uy * reach;\n const sideX = -uy * reach / 2;\n const sideY = ux * reach / 2;\n return [\n {\n x0: px,\n y0: py,\n cx0: nearX,\n cy0: nearY,\n cx1: apexX + sideX,\n cy1: apexY + sideY,\n x1: apexX,\n y1: apexY\n },\n {\n x0: apexX,\n y0: apexY,\n cx0: apexX - sideX,\n cy0: apexY - sideY,\n cx1: nearX,\n cy1: nearY,\n x1: px,\n y1: py\n }\n ];\n}\nfunction computeEdgeCurves(fromSegments, toSegments, join, axis, bypassed = [], maxBowIn) {\n const scale = axis.scaleX;\n const yToX = yToXOf(axis);\n const maxBow = maxBowIn ?? (axis.pixelRows ? MAX_ROW_BOW_PX : void 0);\n if (join === false) {\n join = heldFacingSides(fromSegments, toSegments);\n }\n if (yToX !== 1) {\n return unscaleYOf(\n computeEdgeCurves(\n scaleYOf(fromSegments, yToX),\n scaleYOf(toSegments, yToX),\n join,\n { scaleX: scale, scaleY: scale },\n scaleYOf(bypassed, yToX),\n // the cap is a y measure and the body works in x units, so it converts\n // with everything else that crosses this boundary\n maxBow === void 0 ? void 0 : maxBow * yToX\n ),\n yToX\n );\n }\n if (typeof join === \"string\") {\n return hairpinCurves(\n attachment(fromSegments, join),\n selfLoopReach(fromSegments, scale)\n );\n }\n const loop = join === true;\n const sides = join === true ? { from: \"end\", to: \"start\" } : join;\n const fromAttach = attachment(fromSegments, sides.from);\n const toAttach = attachment(toSegments, sides.to);\n const fromEnd = fromAttach.at;\n const toStart = toAttach.at;\n const p1x = fromEnd.x;\n const p1y = fromEnd.y;\n const p2x = toStart.x;\n const p2y = toStart.y;\n if (loop) {\n let segDirX = 1;\n let segDirY = 0;\n if (fromAttach.inward) {\n const dx = fromEnd.x - fromAttach.inward.x;\n const dy = fromEnd.y - fromAttach.inward.y;\n const len = Math.hypot(dx, dy);\n if (len > 0) {\n segDirX = dx / len;\n segDirY = dy / len;\n }\n }\n const ext = selfLoopReach(fromSegments, scale);\n const perpX = -segDirY;\n const perpY = segDirX;\n const midX = (fromEnd.x + toStart.x) / 2 + perpX * ext;\n const midY = (fromEnd.y + toStart.y) / 2 + perpY * ext;\n const cp1x = p1x + segDirX * ext;\n const cp1y = p1y + segDirY * ext;\n const cp2x = p2x - segDirX * ext;\n const cp2y = p2y - segDirY * ext;\n return [\n {\n x0: p1x,\n y0: p1y,\n cx0: cp1x,\n cy0: cp1y,\n cx1: cp1x + perpX * ext,\n cy1: cp1y + perpY * ext,\n x1: midX,\n y1: midY\n },\n {\n x0: midX,\n y0: midY,\n cx0: cp2x + perpX * ext,\n cy0: cp2y + perpY * ext,\n cx1: cp2x,\n cy1: cp2y,\n x1: p2x,\n y1: p2y\n }\n ];\n } else {\n const fromPrev = fromAttach.inward ?? {\n x: fromEnd.x - (toStart.x - fromEnd.x),\n y: fromEnd.y - (toStart.y - fromEnd.y)\n };\n const toNext = toAttach.inward ?? {\n x: toStart.x - (fromEnd.x - toStart.x),\n y: toStart.y - (fromEnd.y - toStart.y)\n };\n const dist = Math.hypot(p2x - p1x, p2y - p1y);\n const tangentProj = (prev, at, towardX, towardY) => {\n const dx = at.x - prev.x;\n const dy = at.y - prev.y;\n const len = Math.hypot(dx, dy);\n const along = len === 0 ? 0 : (towardX * dx + towardY * dy) / len;\n return Math.max(\n 0,\n Math.min(dist * TANGENT_SPAN_FACTOR, MAX_TANGENT, along * 0.5)\n );\n };\n const towardToX = toStart.x - fromEnd.x;\n const towardToY = toStart.y - fromEnd.y;\n const [cx1, cy1] = projectLine(\n fromPrev.x,\n fromPrev.y,\n fromEnd.x,\n fromEnd.y,\n tangentProj(fromPrev, fromEnd, towardToX, towardToY)\n );\n const [cx2, cy2] = projectLine(\n toNext.x,\n toNext.y,\n toStart.x,\n toStart.y,\n tangentProj(toNext, toStart, -towardToX, -towardToY)\n );\n const bulge = bypassed.length ? bowAround(p1x, p1y, p2x, p2y, bypassed, maxBow) : 0;\n const chordLen = dist === 0 ? 1 : dist;\n const ux = (p2x - p1x) / chordLen;\n const uy = (p2y - p1y) / chordLen;\n const bulgeX = -uy * bulge;\n const bulgeY = ux * bulge;\n const spreadX = ux * Math.abs(bulge);\n const spreadY = uy * Math.abs(bulge);\n return [\n {\n x0: p1x,\n y0: p1y,\n cx0: cx1 + bulgeX - spreadX,\n cy0: cy1 + bulgeY - spreadY,\n cx1: cx2 + bulgeX + spreadX,\n cy1: cy2 + bulgeY + spreadY,\n x1: p2x,\n y1: p2y\n }\n ];\n }\n}\nfunction nearerEnd(segments, to) {\n const start = segments[0];\n const end = segments.at(-1);\n return Math.hypot(start.x - to.x, start.y - to.y) < Math.hypot(end.x - to.x, end.y - to.y) ? \"start\" : \"end\";\n}\nfunction routedEdgeCurves(fromSegments, toSegments, route, sides) {\n const fromAttach = attachment(\n fromSegments,\n sides?.from ?? nearerEnd(fromSegments, route[0])\n );\n const toAttach = attachment(\n toSegments,\n sides?.to ?? nearerEnd(toSegments, route.at(-1))\n );\n const points = [fromAttach.at, ...route, toAttach.at];\n const tangent = (i) => {\n const p = points[i];\n const span = (q) => Math.hypot(q.x - p.x, q.y - p.y);\n const along = (inward, next) => {\n const len = inward ? span(inward) : 0;\n const reach = span(next);\n return len === 0 ? { x: next.x - p.x, y: next.y - p.y } : {\n x: (p.x - inward.x) / len * reach,\n y: (p.y - inward.y) / len * reach\n };\n };\n if (i === 0) {\n return along(fromAttach.inward, points[1]);\n }\n if (i === points.length - 1) {\n const out = along(toAttach.inward, points[i - 1]);\n return { x: -out.x, y: -out.y };\n }\n return {\n x: (points[i + 1].x - points[i - 1].x) / 2,\n y: (points[i + 1].y - points[i - 1].y) / 2\n };\n };\n const curves = [];\n for (let i = 0; i < points.length - 1; i++) {\n const a = points[i];\n const b = points[i + 1];\n const ta = tangent(i);\n const tb = tangent(i + 1);\n curves.push({\n x0: a.x,\n y0: a.y,\n cx0: a.x + ta.x / 3,\n cy0: a.y + ta.y / 3,\n cx1: b.x - tb.x / 3,\n cy1: b.y - tb.y / 3,\n x1: b.x,\n y1: b.y\n });\n }\n return curves;\n}\n\nexport {\n svgPath,\n projectLine,\n curvePointAt,\n curveMidpoint,\n curveBounds,\n dashCurves,\n translateCurves,\n ownStrand,\n strandSides,\n bowAround,\n yToXOf,\n PATH_RIBBON_SPACING_PX,\n pathRibbonOffsets,\n polylinePx,\n selfLinkOf,\n edgeJoinOf,\n computeEdgeCurves,\n routedEdgeCurves\n};\n", "import {\n ownStrand,\n strandSides\n} from \"./chunk-UBQSRCWR.js\";\nimport {\n pushTo\n} from \"./chunk-BSOZW3FC.js\";\nimport {\n isBackbone\n} from \"./chunk-RJWPJCIB.js\";\n\n// src/layout/mergeRuns.ts\nfunction flip(strand) {\n return strand === \"+\" ? \"-\" : \"+\";\n}\nfunction mergeRuns(graph, alone = /* @__PURE__ */ new Set()) {\n const sides = graph.edges.map(strandSides);\n const at = /* @__PURE__ */ new Map();\n const attach = (id, side, ei) => {\n pushTo(at, `${id}|${side}`, ei);\n };\n graph.edges.forEach((edge, ei) => {\n attach(edge.from, sides[ei].from, ei);\n attach(edge.to, sides[ei].to, ei);\n });\n const joinAfter = (a) => {\n const out = at.get(`${a}|end`);\n if (out?.length !== 1) {\n return void 0;\n }\n const ei = out[0];\n const edge = graph.edges[ei];\n return edge.from === a && edge.to !== a && !alone.has(a) && !alone.has(edge.to) && sides[ei].from === \"end\" && sides[ei].to === \"start\" && at.get(`${edge.to}|start`)?.length === 1 ? ei : void 0;\n };\n const joined = /* @__PURE__ */ new Set();\n const runOf = /* @__PURE__ */ new Map();\n const runs = /* @__PURE__ */ new Map();\n for (const node of graph.nodes) {\n const into = at.get(`${node.id}|start`);\n const pred = into?.length === 1 ? graph.edges[into[0]].from : void 0;\n if (runOf.has(node.id) || pred !== void 0 && joinAfter(pred) === into[0]) {\n continue;\n }\n const run = [node.id];\n for (; ; ) {\n const ei = joinAfter(run.at(-1));\n const next = ei === void 0 ? void 0 : graph.edges[ei].to;\n if (next === void 0 || runOf.has(next)) {\n break;\n }\n joined.add(ei);\n run.push(next);\n }\n for (const id of run) {\n runOf.set(id, node.id);\n }\n if (run.length > 1) {\n runs.set(node.id, run);\n }\n }\n for (const node of graph.nodes) {\n if (!runOf.has(node.id)) {\n runOf.set(node.id, node.id);\n }\n }\n const byId = new Map(graph.nodes.map((n) => [n.id, n]));\n const nodes = [];\n for (const node of graph.nodes) {\n if (runOf.get(node.id) !== node.id) {\n continue;\n }\n const run = runs.get(node.id);\n if (!run) {\n nodes.push(node);\n continue;\n }\n const members = run.map((id) => byId.get(id));\n const backbone = members.filter(isBackbone);\n const first = backbone.length ? backbone.reduce((a, b) => a.stable.start <= b.stable.start ? a : b) : members[0];\n nodes.push({\n id: node.id,\n name: node.name,\n length: members.reduce((sum, n) => sum + n.length, 0),\n depth: node.depth,\n stable: first.stable\n });\n }\n const seen = /* @__PURE__ */ new Set();\n const edges = [];\n graph.edges.forEach((edge, ei) => {\n const from = runOf.get(edge.from);\n const to = runOf.get(edge.to);\n const side = sides[ei];\n const key = `${from}|${side.from}>${to}|${side.to}`;\n if (joined.has(ei) || seen.has(key)) {\n return;\n }\n seen.add(key);\n edges.push({\n from,\n to,\n ...side.from === \"start\" ? { fromStrand: flip(ownStrand(from)) } : {},\n ...side.to === \"end\" ? { toStrand: flip(ownStrand(to)) } : {}\n });\n });\n return {\n graph: { ...graph, nodes, edges, paths: void 0, pathVisits: void 0 },\n runs\n };\n}\nfunction splitRuns(positions, runs, weightOf) {\n const out = { ...positions };\n for (const [id, members] of runs) {\n const line = positions[id];\n if (!line?.length) {\n continue;\n }\n delete out[id];\n const arc = arcPrefix(line);\n const total = arc.at(-1);\n const weights = members.map((m) => Math.max(weightOf(m), 0));\n const weightSum = weights.reduce((a, b) => a + b, 0);\n let from = 0;\n members.forEach((member, k) => {\n const share = weightSum ? weights[k] / weightSum * total : total / members.length;\n const to = k === members.length - 1 ? total : from + share;\n out[member] = slice(line, arc, from, to);\n from = to;\n });\n }\n return out;\n}\nfunction polylineSlice(line, from, to) {\n if (line.length === 0) {\n return [];\n }\n const arc = arcPrefix(line);\n const total = arc.at(-1);\n return slice(line, arc, from * total, to * total);\n}\nfunction polylineMidpoint(line) {\n const arc = arcPrefix(line);\n return pointAt(line, arc, arc.at(-1) / 2);\n}\nfunction arcPrefix(line) {\n const arc = [0];\n for (let i = 1; i < line.length; i++) {\n arc.push(\n arc[i - 1] + Math.hypot(line[i].x - line[i - 1].x, line[i].y - line[i - 1].y)\n );\n }\n return arc;\n}\nfunction pointAt(line, arc, s) {\n if (s <= 0) {\n return { ...line[0] };\n }\n let i = 1;\n while (i < arc.length && arc[i] < s) {\n i++;\n }\n if (i >= arc.length) {\n return { ...line.at(-1) };\n }\n const span = arc[i] - arc[i - 1];\n const t = span > 0 ? (s - arc[i - 1]) / span : 0;\n const a = line[i - 1];\n const b = line[i];\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n}\nfunction slice(line, arc, from, to) {\n const points = [pointAt(line, arc, from)];\n for (let i = 0; i < line.length; i++) {\n if (arc[i] > from && arc[i] < to) {\n points.push({ ...line[i] });\n }\n }\n points.push(pointAt(line, arc, to));\n return points;\n}\n\nexport {\n mergeRuns,\n splitRuns,\n polylineSlice,\n polylineMidpoint\n};\n", "import {\n computeEdgeCurves,\n edgeJoinOf,\n routedEdgeCurves,\n strandSides\n} from \"./chunk-UBQSRCWR.js\";\nimport {\n groupBy\n} from \"./chunk-BSOZW3FC.js\";\nimport {\n firstNodeAtOrAfter,\n isBackbone\n} from \"./chunk-RJWPJCIB.js\";\n\n// src/deletionEdges.ts\nvar MIN_DELETION_BP = 1;\nfunction bypassedPoints(nodePositions, bypassed) {\n return bypassed.flatMap((id) => nodePositions[id] ?? []);\n}\nfunction edgeCurvesOf(nodePositions, edge, axis, bypassed, route, stranded) {\n const from = nodePositions[edge.from];\n const to = nodePositions[edge.to];\n if (!from?.length || !to?.length) {\n return void 0;\n }\n return route ? routedEdgeCurves(\n from,\n to,\n route,\n stranded ? strandSides(edge) : void 0\n ) : computeEdgeCurves(\n from,\n to,\n edgeJoinOf(edge, stranded),\n axis,\n bypassed ? bypassedPoints(nodePositions, bypassed) : []\n );\n}\nfunction backboneBySequence(graph) {\n const bySequence = groupBy(\n graph.nodes.filter(isBackbone),\n (node) => node.stable.refName\n );\n for (const list of bySequence.values()) {\n list.sort((a, b) => a.stable.start - b.stable.start);\n }\n return bySequence;\n}\nfunction bypassedNodes(nodes, start, end) {\n const bypassed = [];\n if (nodes) {\n for (let i = firstNodeAtOrAfter(nodes, start); i < nodes.length; i++) {\n const node = nodes[i];\n if (node.stable.start >= end) {\n break;\n }\n if (node.stable.start + node.length <= end) {\n bypassed.push(node.id);\n }\n }\n }\n return bypassed;\n}\nfunction skipsBetween(edge, from, to, forwards) {\n const { fromStrand, toStrand } = edge;\n if (fromStrand === void 0 || toStrand === void 0) {\n return true;\n }\n const leavesRight = fromStrand === (from.stable.strand ?? \"+\");\n const arrivesLeft = toStrand === (to.stable.strand ?? \"+\");\n return forwards ? leavesRight && arrivesLeft : !leavesRight && !arrivesLeft;\n}\nfunction deletionEdges(graph) {\n const byId = new Map(graph.nodes.map((n) => [n.id, n]));\n const backbone = backboneBySequence(graph);\n const found = [];\n for (let edgeIndex = 0; edgeIndex < graph.edges.length; edgeIndex++) {\n const edge = graph.edges[edgeIndex];\n const from = byId.get(edge.from);\n const to = byId.get(edge.to);\n if (from !== void 0 && to !== void 0 && isBackbone(from) && isBackbone(to) && from.stable.refName === to.stable.refName) {\n const forwards = from.stable.start <= to.stable.start;\n const [left, right] = forwards ? [from, to] : [to, from];\n const start = left.stable.start + left.length;\n const end = right.stable.start;\n const bp = end - start;\n if (bp >= MIN_DELETION_BP && skipsBetween(edge, from, to, forwards)) {\n const refName = left.stable.refName;\n found.push({\n edgeIndex,\n from: edge.from,\n to: edge.to,\n ...edge.fromStrand ? { fromStrand: edge.fromStrand } : {},\n ...edge.toStrand ? { toStrand: edge.toStrand } : {},\n refName,\n start,\n end,\n bp,\n bypassed: bypassedNodes(backbone.get(refName), start, end)\n });\n }\n }\n }\n return found;\n}\nfunction closableDeletions(graph, deletions) {\n const parent = /* @__PURE__ */ new Map();\n const root = (id) => {\n let r = id;\n while (parent.has(r)) {\n r = parent.get(r);\n }\n if (r !== id) {\n parent.set(id, r);\n }\n return r;\n };\n const join = (a, b) => {\n const [ra, rb] = [root(a), root(b)];\n if (ra !== rb) {\n parent.set(ra, rb);\n }\n return ra !== rb;\n };\n const candidates = new Set(deletions.map((d) => d.edgeIndex));\n graph.edges.forEach((e, ei) => {\n if (!candidates.has(ei)) {\n join(e.from, e.to);\n }\n });\n return new Set(\n deletions.filter((d) => !join(d.from, d.to)).map((d) => d.edgeIndex)\n );\n}\nvar drawings = /* @__PURE__ */ new WeakMap();\nfunction deletionDrawing(graph, deletions, show = true) {\n let byShow = drawings.get(deletions);\n if (!byShow) {\n byShow = /* @__PURE__ */ new Map();\n drawings.set(deletions, byShow);\n }\n let drawing = byShow.get(show);\n if (!drawing) {\n const hidden = show ? /* @__PURE__ */ new Set() : closableDeletions(graph, deletions);\n drawing = {\n shown: deletions.filter((d) => !hidden.has(d.edgeIndex)),\n bypassed: new Map(deletions.map((d) => [d.edgeIndex, d.bypassed])),\n hidden\n };\n byShow.set(show, drawing);\n }\n return drawing;\n}\n\nexport {\n edgeCurvesOf,\n deletionEdges,\n closableDeletions,\n deletionDrawing\n};\n", "import {\n weakMemo\n} from \"./chunk-HMXCN6PG.js\";\nimport {\n labelWidth,\n occupancy\n} from \"./chunk-AB35TJST.js\";\nimport {\n polylineMidpoint\n} from \"./chunk-BZFOFC4D.js\";\nimport {\n edgeCurvesOf\n} from \"./chunk-CGMSKIEO.js\";\nimport {\n curveBounds,\n curveMidpoint,\n polylinePx\n} from \"./chunk-UBQSRCWR.js\";\n\n// src/graphLabels.ts\nvar MIN_DELETION_LABEL_PX = 26;\nvar PX_PER_NODE_LABEL = 4e4;\nvar MIN_NODE_LABELS = 8;\nvar LEADER_GAP_PX = 8;\nvar LABEL_CHAR_PX = 5.7;\nvar LABEL_PAD_PX = 6;\nvar LABEL_HEIGHT_PX = 13;\nvar LABEL_GAP_PX = 3;\nvar MAX_LABEL_OVERHANG = 2;\nfunction labelHalfWidth(text) {\n return (text.length * LABEL_CHAR_PX + LABEL_PAD_PX + LABEL_GAP_PX) / 2;\n}\nvar LABEL_HALF_HEIGHT = (LABEL_HEIGHT_PX + LABEL_GAP_PX) / 2;\nvar MIN_LABEL_HALF_WIDTH = labelHalfWidth(\"1 bp\");\nfunction boxAt(halfW, x, y) {\n return {\n x0: x - halfW,\n x1: x + halfW,\n y0: y - LABEL_HALF_HEIGHT,\n y1: y + LABEL_HALF_HEIGHT\n };\n}\nfunction rowLabelBox(text, screenY) {\n return {\n x0: 6,\n x1: 6 + labelWidth(text) + LABEL_GAP_PX,\n y0: screenY - 8 - LABEL_GAP_PX / 2,\n y1: screenY + 8 + LABEL_GAP_PX / 2\n };\n}\nfunction clamp(v, lo, hi) {\n return hi < lo ? v : Math.min(Math.max(v, lo), hi);\n}\nfunction groupDigits(n) {\n return String(n).replace(/\\B(?=(\\d{3})+$)/g, \",\");\n}\nfunction formatBp(bp) {\n const [value, unit] = bp >= 1e6 ? [bp / 1e6, \"Mb\"] : bp >= 1e3 ? [bp / 1e3, \"kb\"] : [];\n if (value === void 0) {\n return `${bp} bp`;\n }\n return `${+value.toFixed(value >= 100 ? 0 : 1)} ${unit}`;\n}\nfunction deletionText(bp) {\n return `${formatBp(bp)} del`;\n}\nfunction arcOutward(curves, apex, scaleX, scaleY) {\n const first = curves[0];\n const last = curves[curves.length - 1];\n const dx = (apex.x - (first.x0 + last.x1) / 2) * scaleX;\n const dy = (apex.y - (first.y0 + last.y1) / 2) * scaleY;\n const len = Math.hypot(dx, dy);\n return len === 0 ? { x: 0, y: -1 } : { x: dx / len, y: dy / len };\n}\nfunction boxSupport(box, dir) {\n return Math.abs(dir.x) * (box.x1 - box.x0) / 2 + Math.abs(dir.y) * (box.y1 - box.y0) / 2;\n}\nfunction boxRayCrossing(box, dir) {\n const halfW = (box.x1 - box.x0) / 2;\n const halfH = (box.y1 - box.y0) / 2;\n return Math.min(\n dir.x === 0 ? Infinity : halfW / Math.abs(dir.x),\n dir.y === 0 ? Infinity : halfH / Math.abs(dir.y)\n );\n}\nfunction runBounds(nodeIds, nodePositions) {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const id of nodeIds) {\n for (const p of nodePositions[id] ?? []) {\n minX = Math.min(minX, p.x);\n maxX = Math.max(maxX, p.x);\n minY = Math.min(minY, p.y);\n maxY = Math.max(maxY, p.y);\n }\n }\n return minX === Infinity ? void 0 : { minX, minY, maxX, maxY };\n}\nvar nodeOrderCache = weakMemo();\nfunction labelOrder(nodePositions, nodeLengths) {\n return nodeOrderCache(\n nodePositions,\n [nodeLengths],\n () => Object.entries(nodePositions).filter(([id, segments]) => segments.length > 0 && nodeLengths.has(id)).sort(([a], [b]) => nodeLengths.get(b) - nodeLengths.get(a))\n );\n}\nvar arcCache = weakMemo();\nfunction arcPlacements(nodePositions, deletions, axis, version, routes, stranded) {\n const { scaleX, scaleY } = axis;\n return arcCache(\n nodePositions,\n [deletions, routes, stranded, scaleX, scaleY, version],\n () => {\n const arcs = [];\n for (const deletion of [...deletions].sort((a, b) => b.bp - a.bp)) {\n const curves = edgeCurvesOf(\n nodePositions,\n deletion,\n axis,\n deletion.bypassed,\n routes?.[deletion.edgeIndex],\n stranded\n );\n const apex = curves ? curveMidpoint(curves) : void 0;\n if (curves && apex) {\n const { minX, minY, maxX, maxY } = curveBounds(curves);\n arcs.push({\n deletion,\n curves,\n apex,\n // in screen px, so the two axes' units cannot be added by accident\n extent: Math.max((maxX - minX) * scaleX, (maxY - minY) * scaleY)\n });\n }\n }\n return arcs;\n }\n );\n}\nfunction sizeLabelCandidates({\n nodePositions,\n nodeLengths,\n deletions,\n deletionRoutes,\n stranded = false,\n alleleDeletions,\n axis,\n translateX,\n translateY,\n width,\n height,\n version = 0\n}) {\n const { scaleX, scaleY } = axis;\n const deletionCandidates = [];\n const nodeCandidates = [];\n for (const { deletion, curves, apex, extent } of arcPlacements(\n nodePositions,\n deletions,\n axis,\n version,\n deletionRoutes,\n stranded\n )) {\n if (extent >= MIN_DELETION_LABEL_PX) {\n const text = deletionText(deletion.bp);\n const halfW = labelHalfWidth(text);\n const box = boxAt(halfW, 0, 0);\n const arcX = apex.x * scaleX + translateX;\n const arcY = apex.y * scaleY + translateY;\n if (arcX < 0 || arcX > width || arcY < 0 || arcY > height) {\n continue;\n }\n const fits = extent >= halfW * 2 / MAX_LABEL_OVERHANG;\n const bow = arcOutward(curves, apex, scaleX, scaleY);\n const offset = boxSupport(box, bow) + LEADER_GAP_PX;\n const x = fits ? arcX : clamp(arcX + bow.x * offset, halfW, width - halfW);\n const y = fits ? arcY : clamp(\n arcY + bow.y * offset,\n LABEL_HALF_HEIGHT,\n height - LABEL_HALF_HEIGHT\n );\n const away = Math.hypot(x - arcX, y - arcY);\n let leader;\n if (away > 0) {\n const dir = { x: (x - arcX) / away, y: (y - arcY) / away };\n const crossing = boxRayCrossing(box, dir);\n leader = {\n arcX,\n arcY,\n labelX: x - dir.x * crossing,\n labelY: y - dir.y * crossing\n };\n }\n deletionCandidates.push({\n label: {\n key: `del:${deletion.edgeIndex}`,\n text,\n x,\n y,\n kind: \"deletion\",\n leader\n },\n box: boxAt(halfW, x, y)\n });\n }\n }\n const labelledByDeletion = /* @__PURE__ */ new Set();\n const alleleRuns = [...alleleDeletions ?? []].sort((a, b) => b.bp - a.bp);\n for (const run of alleleRuns) {\n const drawn = runBounds(run.nodeIds, nodePositions);\n if (!drawn) {\n continue;\n }\n const shownLeft = Math.max(drawn.minX * scaleX + translateX, 0);\n const shownRight = Math.min(drawn.maxX * scaleX + translateX, width);\n const shownTop = Math.max(drawn.minY * scaleY + translateY, 0);\n const shownBottom = Math.min(drawn.maxY * scaleY + translateY, height);\n if (shownRight < shownLeft || shownBottom < shownTop) {\n continue;\n }\n const extent = Math.max(shownRight - shownLeft, shownBottom - shownTop);\n const text = deletionText(run.bp);\n const halfW = labelHalfWidth(text);\n if (extent >= halfW * 2 / MAX_LABEL_OVERHANG) {\n for (const id of run.nodeIds) {\n labelledByDeletion.add(id);\n }\n const x = clamp((shownLeft + shownRight) / 2, halfW, width - halfW);\n const y = clamp(\n (shownTop + shownBottom) / 2,\n LABEL_HALF_HEIGHT,\n height - LABEL_HALF_HEIGHT\n );\n deletionCandidates.push({\n label: {\n key: `alleledel:${run.nodeIds.join(\",\")}`,\n text,\n x,\n y,\n kind: \"deletion\"\n },\n box: boxAt(halfW, x, y)\n });\n }\n }\n for (const [id, segments] of labelOrder(nodePositions, nodeLengths)) {\n if (labelledByDeletion.has(id)) {\n continue;\n }\n const { x, y } = polylineMidpoint(segments);\n const screenY = y * scaleY + translateY;\n if (screenY + LABEL_HALF_HEIGHT <= 0 || screenY - LABEL_HALF_HEIGHT >= height) {\n continue;\n }\n const drawn = polylinePx(segments, scaleX, scaleY);\n if (drawn < MIN_LABEL_HALF_WIDTH * 2 / MAX_LABEL_OVERHANG) {\n continue;\n }\n const text = formatBp(nodeLengths.get(id));\n const halfW = labelHalfWidth(text);\n if (drawn >= halfW * 2 / MAX_LABEL_OVERHANG) {\n const screenX = x * scaleX + translateX;\n nodeCandidates.push({\n label: {\n key: `node:${id}`,\n text,\n x: screenX,\n y: screenY,\n kind: \"node\"\n },\n box: boxAt(halfW, screenX, screenY)\n });\n }\n }\n return { deletions: deletionCandidates, nodes: nodeCandidates };\n}\nfunction nodeLabelBudget(width, height) {\n return Math.max(\n MIN_NODE_LABELS,\n Math.floor(width * height / PX_PER_NODE_LABEL)\n );\n}\nfunction placeSizeLabels(candidates, take, budget = Infinity) {\n const labels = [];\n for (const { label, box } of candidates) {\n if (labels.length >= budget) {\n break;\n }\n if (take(box)) {\n labels.push(label);\n }\n }\n return labels;\n}\nfunction graphLabels({\n reserved,\n take,\n ...args\n}) {\n take ??= occupancy(args, reserved);\n const { deletions, nodes } = sizeLabelCandidates(args);\n return [\n ...placeSizeLabels(deletions, take),\n ...placeSizeLabels(nodes, take, nodeLabelBudget(args.width, args.height))\n ];\n}\n\nexport {\n rowLabelBox,\n groupDigits,\n formatBp,\n sizeLabelCandidates,\n nodeLabelBudget,\n placeSizeLabels,\n graphLabels\n};\n", "import {\n pathOrigin\n} from \"./chunk-B5X2RLJG.js\";\nimport {\n groupDigits\n} from \"./chunk-PFRQBCGC.js\";\nimport {\n isGenericSample\n} from \"./chunk-4XWZNPQ2.js\";\n\n// src/pathColors.ts\nfunction nameHue(name) {\n let hash = 0;\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash);\n }\n return Math.abs(hash % 360);\n}\nfunction pathHueAt(index, count) {\n return index * 360 / count;\n}\nvar PATH_SATURATION = 0.7;\nvar PATH_LIGHTNESS = 0.5;\nvar MAX_PATH_COLORS = 16;\nfunction pathColorsLegible(pathCount) {\n return pathCount > 0 && pathCount <= MAX_PATH_COLORS;\n}\nfunction pathCssColor(index, count) {\n return `hsl(${pathHueAt(index, count)}, ${PATH_SATURATION * 100}%, ${PATH_LIGHTNESS * 100}%)`;\n}\nfunction pathGreyCssColor(index, count) {\n const lightness = count > 1 ? 25 + 45 * index / (count - 1) : 45;\n return `hsl(0, 0%, ${lightness}%)`;\n}\nfunction labelTiers(name) {\n const parts = pathOrigin(name).name.split(\"#\");\n const full = parts.join(\"#\");\n if (parts.length >= 3 && isGenericSample(parts[0])) {\n const contig = parts.slice(2).join(\"#\");\n return [contig, contig, full];\n }\n return [parts[0], parts.slice(0, 2).join(\"#\"), full];\n}\nfunction offsetTiers(name, tiers) {\n const { start } = pathOrigin(name);\n return tiers.map((t) => `${t} @${groupDigits(start)}`);\n}\nfunction pathLegend(paths, colors) {\n const firstOf = /* @__PURE__ */ new Map();\n paths.forEach((path, i) => {\n if (!firstOf.has(path.name)) {\n firstOf.set(path.name, i);\n }\n });\n const entries = [...firstOf].map(([name, i]) => ({ name, i }));\n const named = entries.map((e) => labelTiers(e.name));\n const candidates = [0, 1, 2].flatMap((t) => [\n entries.map((_, k) => named[k][t]),\n entries.map((e, k) => offsetTiers(e.name, named[k])[t])\n ]);\n const distinct = candidates.find(\n (labels2) => new Set(labels2).size === entries.length\n );\n const labels = distinct ?? candidates.at(-1);\n return entries.map(({ name, i }, k) => ({\n name,\n label: labels[k],\n color: colors?.[i] ?? pathCssColor(i, paths.length)\n }));\n}\nfunction walkLabelsOf(entries) {\n const seen = /* @__PURE__ */ new Map();\n return new Map(\n [...entries].sort((a, b) => a.label.localeCompare(b.label)).map((e) => {\n const n = (seen.get(e.label) ?? 0) + 1;\n seen.set(e.label, n);\n return [e.name, n > 1 ? `${e.label} (${n})` : e.label];\n })\n );\n}\n\nexport {\n nameHue,\n pathHueAt,\n PATH_SATURATION,\n PATH_LIGHTNESS,\n MAX_PATH_COLORS,\n pathColorsLegible,\n pathCssColor,\n pathGreyCssColor,\n pathLegend,\n walkLabelsOf\n};\n", "// src/nodeWidths.ts\nvar NODE_WIDTHS = [\n {\n value: \"depth\",\n label: \"By depth\",\n description: \"Thicker the more paths carry a node, on the square root of its depth against the mean. A graph with one depth everywhere draws uniform.\"\n },\n {\n value: \"uniform\",\n label: \"Uniform\",\n description: \"Every node the same thickness.\"\n }\n];\nvar MIN_FACTOR = 0.3;\nvar MAX_FACTOR = 3;\nfunction meanDepth(graph) {\n let weighted = 0;\n let length = 0;\n for (const node of graph.nodes) {\n weighted += node.depth * node.length;\n length += node.length;\n }\n return length > 0 ? weighted / length : 0;\n}\nfunction depthWidthFactor(node, mean) {\n if (!(mean > 0) || !(node.depth > 0)) {\n return 1;\n }\n return Math.min(\n MAX_FACTOR,\n Math.max(MIN_FACTOR, Math.sqrt(node.depth / mean))\n );\n}\nfunction nodeWidthPx(node, contigThickness, nodeWidth, mean) {\n return contigThickness * (nodeWidth === \"depth\" ? depthWidthFactor(node, mean) : 1);\n}\nfunction maxNodeWidthPx(contigThickness, nodeWidth) {\n return contigThickness * (nodeWidth === \"depth\" ? MAX_FACTOR : 1);\n}\nfunction nodeInk(graph, nodeById, contigThickness, nodeWidth) {\n const mean = graph ? meanDepth(graph) : 0;\n return {\n maxHalfWidthPx: maxNodeWidthPx(contigThickness, nodeWidth) / 2,\n halfWidthPx: (id) => {\n const node = nodeById?.get(id);\n return node ? nodeWidthPx(node, contigThickness, nodeWidth, m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,EAAiBC,EAAW,CAClD,OAAOD,GAAmBC,IAAc,QAAUV,GAAa,EACjE,CACA,SAASY,GAAQV,EAAOW,EAAUJ,EAAiBC,EAAW,CAC5D,IAAMH,EAAOL,EAAQD,GAAUC,CAAK,EAAI,EACxC,MAAO,CACL,eAAgBS,GAAeF,EAAiBC,CAAS,EAAI,EAC7D,YAAcI,GAAO,CACnB,IAAMT,EAAOQ,GAAU,IAAIC,CAAE,EAC7B,OAAOT,EAAOG,GAAYH,EAAMI,EAAiBC,EAAWH,CAAI,EAAI,EAAIE,EAAkB,CAC5F,CACF,CACF",
6
+ "names": ["weakMemo", "cache", "key", "deps", "compute", "hit", "d", "i", "value", "LABEL_PX", "LABEL_CHAR_PX", "LABEL_PAD", "labelWidth", "text", "overlaps", "a", "b", "offFrame", "box", "frame", "insideFrame", "occupancy", "reserved", "placed", "p", "placeLabels", "candidates", "take", "out", "row", "place", "c", "w", "direction", "tries", "ROW_HEIGHT_PX", "svgPath", "points", "round", "v", "p", "i", "projectLine", "x1", "y1", "x2", "y2", "distance", "d", "vx", "vy", "curvePointAt", "c", "t", "u", "a", "b", "e", "curveMidpoint", "curves", "mid", "curveBounds", "minX", "minY", "maxX", "maxY", "subCurve", "t0", "t1", "p0", "p1", "dt", "d0", "curveTangentAt", "d1", "dashCurves", "dashWorld", "lengths", "total", "spans", "out", "from", "to", "dash", "start", "k", "length", "end", "translateCurves", "dx", "dy", "attachment", "segments", "side", "last", "TANGENT_SPAN_FACTOR", "MAX_TANGENT", "ownStrand", "id", "strandSides", "edge", "own", "strand", "spanOf", "min", "max", "s", "distanceToSpan", "x", "span", "facingSide", "other", "tieBreak", "startGap", "endGap", "facingSides", "fromSegments", "toSegments", "laidSides", "heldFacingSides", "byTo", "sides", "APEX_FRACTION", "BOW_CLEARANCE", "ALONG_FRACTION", "MAX_ROW_BOW_PX", "ROW_HEIGHT_PX", "bowAround", "p1x", "p1y", "p2x", "p2y", "toward", "maxBow", "chord", "ux", "uy", "reach", "minAlong", "maxAlong", "perp", "along", "uncapped", "size", "yToXOf", "scaleX", "scaleY", "PATH_RIBBON_SPACING_PX", "drawnDirection", "yToX", "len", "pathRibbonOffsets", "count", "axis", "spacing", "dir", "offsets", "scaleYOf", "unscaleYOf", "polylinePx", "SELF_LOOP_MIN_PX", "SELF_LOOP_MAX_PX", "selfLoopReach", "scale", "nodePx", "selfLinkOf", "edgeJoinOf", "stranded", "self", "hairpinCurves", "attach", "at", "inward", "px", "py", "nearX", "nearY", "apexX", "apexY", "sideX", "sideY", "computeEdgeCurves", "join", "bypassed", "maxBowIn", "loop", "fromAttach", "toAttach", "fromEnd", "toStart", "segDirX", "segDirY", "ext", "perpX", "perpY", "midX", "midY", "cp1x", "cp1y", "cp2x", "cp2y", "fromPrev", "toNext", "dist", "tangentProj", "prev", "towardX", "towardY", "towardToX", "towardToY", "cx1", "cy1", "cx2", "cy2", "bulge", "chordLen", "bulgeX", "bulgeY", "spreadX", "spreadY", "nearerEnd", "routedEdgeCurves", "route", "tangent", "q", "next", "ta", "tb", "flip", "strand", "mergeRuns", "graph", "alone", "sides", "strandSides", "at", "attach", "id", "side", "ei", "pushTo", "edge", "joinAfter", "a", "out", "joined", "runOf", "runs", "node", "into", "pred", "run", "next", "byId", "n", "nodes", "members", "backbone", "isBackbone", "first", "b", "sum", "seen", "edges", "from", "to", "key", "ownStrand", "splitRuns", "positions", "weightOf", "line", "arc", "arcPrefix", "total", "weights", "m", "weightSum", "member", "k", "share", "slice", "polylineSlice", "polylineMidpoint", "pointAt", "i", "s", "span", "t", "points", "MIN_DELETION_BP", "bypassedPoints", "nodePositions", "bypassed", "id", "edgeCurvesOf", "edge", "axis", "route", "stranded", "from", "to", "routedEdgeCurves", "strandSides", "computeEdgeCurves", "edgeJoinOf", "backboneBySequence", "graph", "bySequence", "groupBy", "isBackbone", "node", "list", "a", "b", "bypassedNodes", "nodes", "start", "end", "i", "firstNodeAtOrAfter", "skipsBetween", "forwards", "fromStrand", "toStrand", "leavesRight", "arrivesLeft", "deletionEdges", "byId", "n", "backbone", "found", "edgeIndex", "left", "right", "bp", "refName", "closableDeletions", "deletions", "parent", "root", "r", "join", "ra", "rb", "candidates", "d", "e", "ei", "drawings", "deletionDrawing", "show", "byShow", "drawing", "hidden", "MIN_DELETION_LABEL_PX", "PX_PER_NODE_LABEL", "MIN_NODE_LABELS", "LEADER_GAP_PX", "LABEL_CHAR_PX", "LABEL_PAD_PX", "LABEL_HEIGHT_PX", "LABEL_GAP_PX", "MAX_LABEL_OVERHANG", "labelHalfWidth", "text", "LABEL_HALF_HEIGHT", "MIN_LABEL_HALF_WIDTH", "boxAt", "halfW", "x", "y", "rowLabelBox", "screenY", "labelWidth", "clamp", "v", "lo", "hi", "groupDigits", "n", "formatBp", "bp", "value", "unit", "deletionText", "arcOutward", "curves", "apex", "scaleX", "scaleY", "first", "last", "dx", "dy", "len", "boxSupport", "box", "dir", "boxRayCrossing", "halfH", "runBounds", "nodeIds", "nodePositions", "minX", "minY", "maxX", "maxY", "id", "p", "nodeOrderCache", "weakMemo", "labelOrder", "nodeLengths", "segments", "a", "b", "arcCache", "arcPlacements", "deletions", "axis", "version", "routes", "stranded", "arcs", "deletion", "edgeCurvesOf", "curveMidpoint", "curveBounds", "sizeLabelCandidates", "deletionRoutes", "alleleDeletions", "translateX", "translateY", "width", "height", "deletionCandidates", "nodeCandidates", "extent", "arcX", "arcY", "fits", "bow", "offset", "away", "leader", "crossing", "labelledByDeletion", "alleleRuns", "run", "drawn", "shownLeft", "shownRight", "shownTop", "shownBottom", "polylineMidpoint", "polylinePx", "screenX", "nodeLabelBudget", "placeSizeLabels", "candidates", "take", "budget", "labels", "label", "graphLabels", "reserved", "args", "occupancy", "nodes", "nameHue", "name", "hash", "i", "pathHueAt", "index", "count", "PATH_SATURATION", "PATH_LIGHTNESS", "MAX_PATH_COLORS", "pathColorsLegible", "pathCount", "pathCssColor", "pathGreyCssColor", "labelTiers", "parts", "pathOrigin", "full", "isGenericSample", "contig", "offsetTiers", "tiers", "start", "t", "groupDigits", "pathLegend", "paths", "colors", "firstOf", "path", "entries", "named", "e", "candidates", "_", "k", "labels", "labels2", "walkLabelsOf", "seen", "a", "b", "n", "NODE_WIDTHS", "MIN_FACTOR", "MAX_FACTOR", "meanDepth", "graph", "weighted", "length", "node", "depthWidthFactor", "mean", "nodeWidthPx", "contigThickness", "nodeWidth", "maxNodeWidthPx", "nodeInk", "nodeById", "id"]
7
+ }
@@ -0,0 +1,3 @@
1
+ import{a as Re,d as W,e as Qe,g as H,h as et,i as vn,j as En,k as Sn,l as kn,m as Te,o as _e,q as tt,r as nt}from"./chunk-2M4XYSLG.js";import{a as cn,c as ln,e as Oe,f as ot,g as Rn,i as Tn,j as _n}from"./chunk-44CJ2N3N.js";import{A as Je,H as wn,I as Mn,a as je,b as dn,c as de,d as fn,f as un,g as Ve,h as Se,j as pn,l as hn,m as Ke,n as mn,o as ze,p as ke,r as gn,s as bn,v as xn,w as yn,x as Ze,y as ne,z as A}from"./chunk-PEDWEPNK.js";import{e as On}from"./chunk-FIRQAKMX.js";import{a as on,d as an}from"./chunk-VQ77X5QU.js";import{c as Y,d as te,g as tn,j as We,k as ve,l as rn,m as sn}from"./chunk-6KUHGRHU.js";import{a as ee,c as Zt,d as V,e as Ge,f as Jt,g as O,q as nn,r as L,s as He,v as Ue}from"./chunk-6MUBJVBG.js";import{d as Qt,e as en,f as le}from"./chunk-7HWHWPRW.js";import{a as Ye}from"./chunk-IKJZPPOA.js";import{g as E}from"./chunk-NDRLCGPC.js";import{b as Ee}from"./chunk-YU7T5WOQ.js";var Ae=8,rt=34,Ne=12,Ur=60;function jr({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function i(c){let l=Math.ceil(e/c),f=Math.floor((o-(c-1)*Ae)/c),u=(r-l*rt-(l-1)*Ae)/l,d=(f-2*Ne)/t.w,p=t.h>0?(u-2*Ne)/t.h:1/0,h=n?d:Math.min(d,p),m=n?t.h:t.h*h,b=Math.floor(Math.max(Ur,Math.min(m+2*Ne,u)));return{columns:c,width:f,height:b,scale:h,total:l*(b+rt)+(l-1)*Ae}}if(s!==void 0)return i(Math.max(1,Math.min(e,Math.round(s))));let a=i(1);for(let c=2;c<=e;c++){let l=i(c);l.scale>a.scale&&(a=l)}return a}var Vr=[{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 Kr(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 An(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 zr(e,t,n=[]){let o=An(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 f=en(l);return f&&Number.isInteger(f.haplotype)&&f.haplotype>=0?{sample:f.sample,column:Math.max(0,f.haplotype-1)}:void 0}),i=An([...new Set(s.flatMap(l=>l?[l.sample]:[]))],n),a=Math.max(1,...s.map(l=>l?l.column+1:1)),c=s.map(l=>l?i.indexOf(l.sample)*a+l.column:-1);return c.includes(-1)||new Set(c).size<c.length?r:{columns:a,count:i.length*a,cells:c}}function Nn(e,t){let n=e.nodes.filter(b=>O(b)&&(t[b.id]?.length??0)>0);if(n.length<2)return t;let o=n.map(b=>{let g=t[b.id],x=g[Math.floor(g.length/2)];return{x:x.x,y:x.y,r:b.stable.start+b.length/2,w:b.length}}),r=o.reduce((b,g)=>b+g.w,0);if(r===0)return t;let s=o.reduce((b,g)=>b+g.x*g.w,0)/r,i=o.reduce((b,g)=>b+g.y*g.w,0)/r,a=o.reduce((b,g)=>b+g.r*g.w,0)/r,c=0,l=0;for(let b of o)c+=b.w*(b.x-s)*(b.r-a),l+=b.w*(b.y-i)*(b.r-a);let f=-Math.atan2(l,c),u=Math.cos(f),d=Math.sin(f),p={};for(let[b,g]of Object.entries(t))p[b]=g.map(x=>{let M=x.x-s,y=x.y-i;return{x:s+u*M-d*y,y:i+d*M+u*y}});let h=0,m=0;for(let b of e.nodes)if(!O(b))for(let g of p[b.id]??[])g.y>i?h++:m++;if(m>h)for(let b of Object.values(p))for(let g of b)g.y=2*i-g.y;return p}var Pn=30;function Zr(e,t){let{opts:n}=t,o=new Map(t.nodes.map(d=>[d.id,Oe(n,d.length)])),r=d=>o.get(d)??n.minimumNodeLength,s=e.nodes.filter(O).sort((d,p)=>d.stable.start-p.stable.start),i=new Map,a=0;for(let d of s)i.set(d.id,{x:a,y:0}),a+=r(d.id)+n.edgeLength;let c=Re(e),l=new Map(s.map(d=>[d.id,0])),f=s.map(d=>d.id);for(let d of f){let p=i.get(d),h=l.get(d)+1;for(let m of c.get(d)??[])l.has(m)||(l.set(m,h),i.set(m,{x:p.x+r(d)/2,y:Pn*h}),f.push(m))}let u=0;for(let d of e.nodes)i.has(d.id)||i.set(d.id,{x:u++*a/e.nodes.length,y:Pn*3});return i}function $n(e,t){let n=Zr(e,t);return t.nodes.map(o=>({...o,...n.get(o.id)}))}var Jr=Math.PI/24;function Cn(e,t){let n=e[t-1],o=e[t],r=e[t+1];if(!n||!r)return 0;let s=Math.abs(Math.atan2(r.y-o.y,r.x-o.x)-Math.atan2(o.y-n.y,o.x-n.x));return s>Math.PI?2*Math.PI-s:s}function Qr(e,t,n,o,r){let s=(h,m)=>Math.max(Math.hypot(m.x-h.x,m.y-h.y)**.5,1e-9),i=s(e,t),a=i+s(t,n),c=a+s(n,o),l=i+r*(a-i),f=(h,m,b,g)=>{let x=(l-b)/(g-b);return{x:h.x+(m.x-h.x)*x,y:h.y+(m.y-h.y)*x}},u=f(e,t,0,i),d=f(t,n,i,a),p=f(n,o,a,c);return f(f(u,d,0,a),f(d,p,i,c),i,a)}var Ln=(e,t)=>({x:2*t.x-e.x,y:2*t.y-e.y});function In(e){if(e.length<3)return e;let t=[e[0]];for(let n=0;n+1<e.length;n++){let o=e[n],r=e[n+1],s=Math.ceil(Math.max(Cn(e,n),Cn(e,n+1))/Jr),i=e[n-1]??Ln(r,o),a=e[n+2]??Ln(o,r);for(let c=1;c<s;c++)t.push(Qr(i,o,r,a,c/s));t.push(r)}return t}var es=.5;function Bn(e,t,n=new Set){let o=new Map(t.map(s=>[s.edgeIndex,`${cn}${s.edgeIndex}`])),r=[];return e.edges.forEach((s,i)=>{let a=o.get(i);if(!n.has(i))if(a===void 0)r.push(s);else{let{fromStrand:c,toStrand:l}=s;r.push({from:s.from,to:a,...c?{fromStrand:c}:{}},{from:a,to:s.to,...l?{toStrand:l}:{}})}}),{graph:{...e,nodes:[...e.nodes,...[...o.values()].map(s=>({id:s,name:s,length:0,depth:0}))],edges:r},routes:o,ids:new Set(o.values())}}function Xn(e,t,n,o,r){let s=new Map(e.nodes.map(i=>[i.id,i.length]));return t.map(i=>{let a=i.bypassed.reduce((f,u)=>f+(s.get(u)??0),0),c=Math.max(r.minimumNodeLength,o(a)*es),l=n.get(i.edgeIndex);return{id:l,name:l,length:Math.round(c*1e6/r.nodeLengthPerMegabase),depth:0}})}function Dn(e,t){let n={...e},o={};for(let[r,s]of t){let i=n[s];delete n[s],i?.length&&(o[r]=i)}return{nodePositions:n,deletionRoutes:o}}function ts(e,t){let n=e.indexOf(":"),o=e.indexOf(":",n+1);if(n!==-1&&o!==-1){let r=e.slice(0,n),s=e.slice(n+1,o),i=e.slice(o+1);s==="i"||s==="f"?t[r]=+i:s==="Z"&&(t[r]=i)}}function fe(e){let t={};for(let n of e)ts(n,t);return t}function qn(e){let{SN:t,SO:n,SR:o}=e.tags;return typeof t=="string"&&typeof n=="number"&&typeof o=="number"?{refName:t,start:n,rank:o}:void 0}var Fn=62,ns=60;function os(e){let t=[],n="+",o=0;function r(s){s>o&&t.push({id:e.slice(o,s),strand:n})}for(let s=0;s<e.length;s++){let i=e.charCodeAt(s);(i===Fn||i===ns)&&(r(s),n=i===Fn?"+":"-",o=s+1)}return r(e.length),t}function Gn(e){let t={nodes:[],links:[],paths:[],walks:[],header:[],id:""};for(let n of e.split(`
2
+ `)){let o=n.endsWith("\r")?n.slice(0,-1):n,r=o.split(" ",1)[0];if(r==="H"){let[,...s]=o.split(" ");t.header.push(fe(s))}else if(r==="S"){let[,s,...i]=o.split(" "),a,c,l,f=!1,u=i[0]??"*";/^\d+$/.test(u)?(a=+u,c=i[1]??"*",l=i.slice(2)):(f=!0,c=u,a=c==="*"?0:c.length,l=i.slice(1));let d=fe(l);f&&"LN"in d&&(a=+d.LN),t.nodes.push({id:s,length:a,sequence:c,tags:d})}else if(r==="E"){let[,,s,i,,,,,a,...c]=o.split(" ");s&&i&&t.links.push({source:s.slice(0,-1),target:i.slice(0,-1),strand1:s.at(-1),strand2:i.at(-1),cigar:a??"*",tags:fe(c)})}else if(r==="L"){let[,s,i,a,c,l,...f]=o.split(" ");s&&a&&c&&t.links.push({source:s,target:a,strand1:i,strand2:c,cigar:l??"*",tags:fe(f)})}else if(r==="W"){let[,s,i,a,c,l,f,...u]=o.split(" ");s&&i&&a&&c&&l&&f&&t.walks.push({sample:s,haplotype:+i,contig:a,start:c==="*"?-1:+c,end:l==="*"?-1:+l,segments:os(f),tags:fe(u)})}else if(r==="P"){let[,s,i,...a]=o.split(" ");s&&i&&t.paths.push({name:s,path:i,rest:a})}}return t}function rs(e,t){let n=new Map,o=new Map;function r(i,a){n.has(i)||n.set(i,a)}function s(i,a){let c=o.get(i);c===void 0&&r(i,a),o.set(i,(c??0)+1)}for(let i of e.links)r(i.source,i.strand1==="-"?"-":"+"),r(i.target,i.strand2==="-"?"-":"+");for(let{steps:i}of t)for(let a of i)s(a.id,a.strand);for(let i of e.walks)for(let a of i.segments)s(a.id,a.strand);return{canonical:n,traversals:o}}var Yn=e=>e.start===-1?0:e.start;function ss(e){return{...L(e.name),steps:e.path.split(",").map(t=>({id:t.slice(0,-1),strand:t.endsWith("-")?"-":"+"}))}}function is(e,t){return[...t,...e.walks.map(n=>({name:`${n.sample}#${n.haplotype}#${n.contig}`,start:Yn(n),steps:n.segments}))]}function as(e){let t=e.tags.SM;if(typeof t!="string")return;let n=t.split(",").map(o=>o.trim()).filter(Boolean);return n.length>0?n:void 0}var ue=e=>typeof e=="number"&&e>0?e:void 0;function cs({tags:e,length:t}){let n=ue(e.RC)??ue(e.FC)??ue(e.KC);return ue(e.dp)??ue(e.DP)??(n!==void 0&&t>0?n/t:void 0)}function ls(e,t,n){return{id:`${e.id}${t}`,name:e.id,length:e.length,depth:n,stable:qn(e),samples:as(e)}}function Wn(e,t="Imported GFA"){let n=[],o=[],r=e.paths.map(ss),{canonical:s,traversals:i}=rs(e,r),a=new Map,c=g=>{let x=a.get(g);return x===void 0&&(x=`${g}${s.get(g)??"+"}`,a.set(g,x)),x},l=new Map;for(let g of e.nodes){if(l.has(g.id))continue;l.set(g.id,g.length);let x=cs(g)??Math.max(i.get(g.id)??1,1);n.push(ls(g,s.get(g.id)??"+",x))}for(let g of e.links)o.push({from:c(g.source),to:c(g.target),fromStrand:g.strand1==="-"?"-":"+",toStrand:g.strand2==="-"?"-":"+"});let f=[],u=new Map,d=(g,x)=>u.get(g)?.get(x);function p(g,x,M){let y=u.get(g);y||(y=new Map,u.set(g,y)),y.set(x,M)}let h=o.map(g=>{let x=d(g.from,g.to);return x||(x=new Set,p(g.from,g.to,x),p(g.to,g.from,x)),x});function m(g,x){for(let M=0;M<g.length-1;M++)d(g[M],g[M+1])?.add(x)}e.paths.forEach(({name:g},x)=>{let{start:M,steps:y}=r[x],w=y.map(v=>c(v.id));f.push({name:g,nodeIds:w,start:M}),m(w,g)});for(let g of e.walks){let x=g.segments.map(y=>c(y.id)),M=`${g.sample}#${g.haplotype}#${g.contig}`;f.push({name:M,nodeIds:x,start:Yn(g),sample:g.sample,haplotype:g.haplotype,contig:g.contig,...tn(g.tags)}),m(x,M)}o.forEach((g,x)=>{let M=h[x];M.size>0&&(g.pathIds=[...M])});let b=e.paths.length>0||e.walks.length>0?He(is(e,r),g=>l.get(g)??0):void 0;return{name:t,nodes:n,edges:o,paths:f.length>0?f:void 0,anchorPaths:b?.anchorPaths,pathVisits:b?.pathVisits,anchoredBy:n.some(g=>g.stable)?"tags":void 0}}function ds(e,t){if(typeof e!="string")return We(e,t);let n=on(e);return n?We(n,t):Wn(Gn(e),t)}function Fl(e,t,n={}){let o=Ue(ds(e,t),n.referencePath);if(o.nodes.length===0)throw new Error(`No graph segments in ${t}`);if(n.maxNodes!==void 0&&o.nodes.length>n.maxNodes)throw new Error(`Graph too large to draw: ${o.nodes.length.toLocaleString()} nodes (limit ${n.maxNodes.toLocaleString()}). Zoom in to a smaller region, or raise maxGraphNodes on this view.`);return o}var K={engine:"fmmm",quality:2,linearLayout:!1,bubbleSpread:"auto",spacing:1,componentSeparation:1,showDeletionEdges:!0};function Hn(e={}){return{engine:e.engine??K.engine,quality:e.quality??K.quality,linearLayout:e.linearLayout??K.linearLayout,bubbleSpread:e.bubbleSpread??K.bubbleSpread,spacing:e.spacing??K.spacing,componentSeparation:e.componentSeparation??K.componentSeparation,showDeletionEdges:e.showDeletionEdges??K.showDeletionEdges}}var fs=15;function us(e,t,n){let o=e.nodes.some(O),r=Hn(n),s={...t,opts:{...t.opts,edgeLength:t.opts.edgeLength*r.spacing}};return{graph:{nodes:o?$n(e,s):s.nodes,edges:e.edges},options:{quality:r.quality,linearLayout:r.linearLayout,...s.opts,componentSeparation:fs*r.componentSeparation,...o?{rotateComponents:!1}:{},engine:r.engine}}}function st(e,t){let n=e.nodes.some(O);return[...Object.values(Hn(t)),n,e.referencePath??""].join("|")}async function Un(e,t,n){let o=_n(t.bubbleSpread),{shown:r,hidden:s}=yn(e,xn(e),t.showDeletionEdges!==!1),i=Bn(e,r,s),a=gn(i.graph,i.ids),c={...a.graph,nodes:a.graph.nodes.filter(x=>!i.ids.has(x.id))},l=ot(c,o),{result:f,duration:u}=await n(us(a.graph,{...l,nodes:[...l.nodes,...Xn(e,r,i.routes,Rn(c,o),l.opts)]},t)),d=ot(e,o),p=new Map(d.nodes.map(x=>[x.id,Oe(d.opts,x.length)])),h=Object.fromEntries(Object.entries(f.nodePositions).map(([x,M])=>[x,In(M)])),m=bn(h,a.runs,x=>p.get(x)??0),{nodePositions:b,deletionRoutes:g}=Dn(e.nodes.some(O)?Nn(e,m):m,i.routes);return{result:{...f,nodePositions:b,stranded:!0,...r.length?{deletionRoutes:g,extent:jn(g)}:{}},duration:u}}function jn(e){let t=1/0,n=1/0,o=-1/0,r=-1/0;for(let s of Object.values(e))for(let i of s)t=Math.min(t,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x),r=Math.max(r,i.y);return{minX:t,minY:n,maxX:o,maxY:r}}var pe=40,ps=1e-6,hs=100;function it(e){return Math.max(ps,Math.min(hs,e))}function ms(e,t,n,o=pe){let r=t-e.h*n;return o-e.minY*n+Math.max(0,r)/2}function ql(e,t,n,o,{minScale:r=0,padLeft:s=pe,padTop:i=pe,padRight:a=pe,padBottom:c=pe}={}){let l=t-s-a,f=n-i-c;if(l<=0||f<=0||!(e.w>0||!o&&e.h>0))return;let u=e.w>0?l/e.w:1/0,d=e.h>0?f/e.h:1/0,p=it(Math.max(r,o?u:Math.min(u,d))),h=l-e.w*p;return{scale:p,translateX:s-e.minX*p+Math.max(0,h)/2,translateY:ms(e,f,o?1:p,i)}}function Gl(e,t={}){let{minX:n,minY:o,maxX:r,maxY:s}=jn(e.nodePositions),{region:i}=t;e.referenceAxis&&i&&i.end>i.start&&(n=i.start,r=i.end);let a=t.extent??e.extent;return a&&(n=Math.min(n,a.minX??n),o=Math.min(o,a.minY??o),r=Math.max(r,a.maxX??r),s=Math.max(s,a.maxY??s)),{minX:n,minY:o,w:r-n,h:s-o}}var gs=4;function at(e=gs){let t=new WeakMap,n=o=>{let r=t.get(o);return r||(r=new Map,t.set(o,r)),r};return{layout(o,r,s){let i=n(o),a=st(o,r),c=i.get(a);if(c)return c.run;i.size>=e&&i.delete(i.keys().next().value);let l=performance.now(),f={run:Un(o,r,s).then(u=>(f.done=u.result,{...u,duration:u.duration||performance.now()-l}))};return f.run.catch(()=>{i.get(a)===f&&i.delete(a)}),i.set(a,f),f.run},ready(o,r){return t.get(o)?.get(st(o,r))?.done},inherit(o,r){let s=t.get(o);s&&o!==r&&t.set(r,s)}}}function bs(e,t){return{scaleX:e,scaleY:t?1:e,pixelRows:t}}function ct(e,t,n,o){return{minX:-e.translateX/t.scaleX,minY:-e.translateY/t.scaleY,maxX:(n-e.translateX)/t.scaleX,maxY:(o-e.translateY)/t.scaleY}}function xs(e,t){let n=(e.maxX-e.minX)*t,o=(e.maxY-e.minY)*t;return{minX:e.minX-n,minY:e.minY-o,maxX:e.maxX+n,maxY:e.maxY+o}}function ys(e,t){return t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY}function ws(e,t,n,o,r){let s=it(e.scale*t),i=s/e.scale;return{scale:s,translateX:n-(n-e.translateX)*i,translateY:r?e.translateY:o-(o-e.translateY)*i}}function Ms(e,t,n,o){return{x:(e-n.translateX)/o.scaleX,y:(t-n.translateY)/o.scaleY}}var z=JBrowseExports["@jbrowse/render-core/RenderLifecycleMixin"],vs=e=>z!=null&&e in Object(z)?z[e]:Object.assign(function(){throw new Error("This JBrowse does not provide '"+e+"' from '@jbrowse/render-core/RenderLifecycleMixin' to plugins: GraphGenomeView was built for a different JBrowse version, so update the plugin or JBrowse")},{jbrowseHostMissing:e}),Vn=vs("RenderLifecycleMixin"),Wd=z&&z.__esModule?z.default:z;function Kn(e){return t=>e.includes(t)?t:void 0}function jd(e){return E.snapshotProcessor(E.maybe(E.enumeration(e)),{preProcessor:Kn(e)})}function Pe(e,t){return E.snapshotProcessor(E.optional(E.enumeration(e),t),{preProcessor:Kn(e)})}var rf=600,sf=160,af=[1,1,1,1],cf="rgb(255, 255, 255)",lf=5,df=new Set(["tubemap","tubemapref"]),ff=Ee(()=>import("./ChooseSamplesDialog-JRN4YLBY.js")),uf=Ee(()=>import("./ChooseWalksDialog-SM326TOX.js")),pf=Ee(()=>import("./HighlightColorDialog-VBZRUKD5.js")),hf=12,mf=[{bp:0,label:"None"},{bp:3,label:"Under 3 bp"},{bp:10,label:"Under 10 bp"},{bp:50,label:"Under 50 bp, leaving structural variants"},{bp:1e3,label:"Under 1 kb"}];function gf(e){if(typeof e.uri=="string")return e.uri;let n=e.segmentsLocation?.uri;return typeof n=="string"&&n.endsWith(Ye)?n.slice(0,-Ye.length):void 0}var bf=1.15,xf=1.6,yf=150,wf=1,Mf=40,vf=[{value:"each",label:"A tube per haplotype"},{value:"grouped",label:"A tube per haplotype, grouped by route"},{value:"bundled",label:"A tube per route"}],Es={nodeStrokes:[],nodeStrokeRuns:new Map,arrows:[],arrowRuns:new Map,edgeCurves:[],edgeCurveRuns:new Map};function Ef(...e){}var Ss=5e6;function Sf(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:`${Math.round(e/1e3)} kb`}var ks=2e4;function kf(e){return("uri"in e?e.uri.split(/[?#]/)[0]:"localPath"in e?e.localPath:"name"in e?e.name:"").split(/[\\/]/).at(-1)??""}function Rf(e){return e&&"uri"in e&&e.uri?new URL(e.uri,e.baseUri??window.location.href).href:void 0}function Tf(e){return e.builtViewport!==void 0&&e.paintedViewport===e.builtViewport&&e.builtViewport.viewportDirty===e.viewportDirty&&!e.viewportRebuildPending}function _f(e){let{width:t,height:n}=e.viewBox;return ct(e,e.axisScale,t,n)}var Of=at(),Af=E.compose("GraphPane",Vn(),E.model({layoutQuality:E.optional(E.number,2),layoutEngine:Pe(ln,"fmmm"),linearLayout:E.optional(E.boolean,!1),bubbleSpread:Pe(Tn,"auto"),tubeMapFold:E.optional(E.number,0),tubeMapRoutes:Pe(["each","grouped","bundled"],"each"),tubeMapColorBy:E.optional(E.string,""),geneTrackId:E.optional(E.string,""),repeatTrackId:E.optional(E.string,""),repeatKey:E.optional(E.string,""),walkLayers:E.optional(E.frozen(),[]),referencePath:E.optional(E.string,""),showPerf:E.optional(E.boolean,!1),connectorThickness:E.optional(E.number,2),scale:E.optional(E.number,1),translateX:E.optional(E.number,0),translateY:E.optional(E.number,0),paneHeight:E.maybe(E.number),maxGraphNodes:E.optional(E.number,ks),connectedViewId:E.maybe(E.string),maxRegionBp:E.optional(E.number,Ss),subgraphContext:E.optional(E.number,1),subgraphHaplotypes:E.maybe(E.frozen())})).volatile(()=>({graph:void 0,walkCut:void 0,graphRegion:void 0,loadedReferencePath:void 0,layoutResult:void 0,drawnLayoutMode:void 0,legendSize:{width:0,height:0},indexBubbles:void 0,foldedBelowBp:void 0,geneTrackFeatures:void 0,walkGeneFeatures:void 0,walkRowSampleTable:void 0,repeatArrays:void 0,handledLayoutMode:void 0,openBubbles:[],error:void 0,isLoading:!1,loadCanceled:!1,statusMessage:"",hoveredNode:null,hoveredAt:null,hoveredTube:null,hoveredPanel:null,hoveredRowWalks:[],hoveredBubble:null,pointerInPane:!1,stripHover:null,hoveredWalkRow:null,hoveredEdge:null,selectedNode:null,viewportDirty:0,positionsVersion:0,morphEntering:void 0,drawnBatch:Es,builtViewport:void 0,paintedViewport:void 0,draggingNode:null,isPanning:!1,viewportOwner:"fit",viewportDirtyTimer:void 0,positionsDirtyFrame:0,lastFetchMs:void 0,readsShown:void 0,lastLayoutMs:void 0,lastGeometryMs:void 0,lastGeometryStrokeCount:void 0,viewportRebuildPending:!1}));var zn=2,Zn=8192;function oe(e=0,t=0){let n=typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,zn);return Math.min(n,Zn/Math.max(e,t,1))}function lt(e,t,n){let o=oe(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 i=`${t}px`,a=`${n}px`;return e.style.width!==i&&(e.style.width=i),e.style.height!==a&&(e.style.height=a),o}var Lf=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=lt(this.canvas,e,t)/oe()}uploadGeometry(e){this.batch=e,this.highlightedEdge=null}setNodeHighlights(e){this.nodeHighlights=e}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t}updateTransform(e){this.transform=e}fitted(){let e=this.transform,t=this.fit;return!e||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){let t=this.fitted();if(!t)return;let n=this.ctx,{width:o,height:r}=n.canvas;e[3]<1&&n.clearRect(0,0,o,r),n.fillStyle=Qe([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 i=this.highlightFactor,a=this.edgeRun(s.edgeCurveRuns);for(let{color:f,items:u}of re(s.edgeCurves,(d,p)=>({color:$e(a,p)?H(d.color,i):d.color,weight:d.thickness,last:$e(a,p)})))this.strokeCurves(u,f,t);let c=this.liftedStrokes(s);for(let{color:f,items:u}of re(s.nodeStrokes,(d,p)=>{let h=c.get(p);return{color:h===void 0?d.color:H(d.color,h),weight:d.thickness,last:h!==void 0}}))this.strokeNodes(u,f,t);let l=this.edgeRun(s.arrowRuns);for(let{color:f,items:u}of re(s.arrows,(d,p)=>({color:$e(l,p)?H(d.color,i):d.color,weight:0,last:$e(l,p)})))this.fillArrows(u,f,t)}renderHighlights(){let e=this.ctx;e.clearRect(0,0,e.canvas.width,e.canvas.height);let t=this.batch,n=this.fitted();if(!n||!t)return;e.lineCap="round",e.lineJoin="round";let o=this.highlightFactor,r=Jn(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:c}of re(r,l=>({color:H(l.color,o),weight:l.thickness,last:!1})))this.strokeCurves(c,a,n);let s=[...this.liftedStrokes(t)];for(let{color:a,items:c}of re(s,([l,f])=>({color:H(t.nodeStrokes[l].color,f),weight:t.nodeStrokes[l].thickness,last:!1})))this.strokeNodes(c.map(([l])=>t.nodeStrokes[l]),a,n);let i=Jn(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:c}of re(i,l=>({color:H(l.color,o),weight:0,last:!1})))this.fillArrows(c,a,n)}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,n){let o=this.ctx;o.strokeStyle=W(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 i of r.curves)o.bezierCurveTo(i.cx0*n.scaleX+n.translateX,i.cy0*n.scaleY+n.translateY,i.cx1*n.scaleX+n.translateX,i.cy1*n.scaleY+n.translateY,i.x1*n.scaleX+n.translateX,i.y1*n.scaleY+n.translateY)}o.stroke()}strokeNodes(e,t,n){let o=this.ctx;o.strokeStyle=W(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 i=1,a=r.points.length;i<a;i++){let c=r.points[i];o.lineTo(c.x*n.scaleX+n.translateX,c.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t,n){let o=this.ctx;o.fillStyle=W(t),o.beginPath();for(let r of e){let[s,i,a,c]=Ts(r,n);o.moveTo(s.x,s.y),o.lineTo(i.x,i.y),o.lineTo(a.x,a.y),o.lineTo(c.x,c.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},Rs=.25;function Ts(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,i=e.length*t.dpr,a=e.halfWidth*t.dpr,c=r-n*i,l=s-o*i,f=i*(1-Rs);return[{x:r,y:s},{x:c-o*a,y:l+n*a},{x:r-n*f,y:s-o*f},{x:c+o*a,y:l-n*a}]}function Jn(e,t){return t?e.slice(t.start,t.start+t.count):[]}function $e(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function re(e,t){let n=new Map,o=new Map;for(let r=0,s=e.length;r<s;r++){let i=e[r],{color:a,weight:c,last:l}=t(i,r),f=l?o:n,u=`${a}:${c}`,d=f.get(u);d?d.items.push(i):f.set(u,{color:a,items:[i]})}return[...n.values(),...o.values()]}var N=e=>+e.toFixed(1),_s=e=>+e.toFixed(3);function Os(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 dt(e,t){let{color:n,opacity:o}=Os(t);return`${e}="${n}"${o<1?` ${e}-opacity="${_s(o)}"`:""}`}var Qn=.5,eo=.25;function Xf(e,t){let n=[],o=[],r=(l,f)=>{let u={d:`M${N(l)} ${N(f)}`,segments:0,x0:l,x1:l,y0:f,y1:f};return o.push(u),u},s=l=>{let f=o.at(-1)??r(l[0],l[1]);for(let u=0;u<l.length;u+=2)f.x0=Math.min(f.x0,l[u]),f.x1=Math.max(f.x1,l[u]),f.y0=Math.min(f.y0,l[u+1]),f.y1=Math.max(f.y1,l[u+1]);return f.segments++,f},i=l=>{let f=new Set;return o.map(u=>{if(!l||u.x1-u.x0>=Qn||u.y1-u.y0>=Qn)return u.d;let d=(u.x0+u.x1)/2,p=(u.y0+u.y1)/2,h=`${Math.round(d/eo)} ${Math.round(p/eo)}`;return u.segments===0||f.has(h)?"":(f.add(h),`M${N(d)} ${N(p)}h0`)}).join("")},a={canvas:void 0,fillStyle:"#000",strokeStyle:"#000",lineWidth:1,lineCap:"butt",lineJoin:"miter",beginPath(){o=[]},moveTo(l,f){r(l,f)},lineTo(l,f){s([l,f]).d+=`L${N(l)} ${N(f)}`},bezierCurveTo(l,f,u,d,p,h){s([l,f,u,d,p,h]).d+=`C${N(l)} ${N(f)} ${N(u)} ${N(d)} ${N(p)} ${N(h)}`},closePath(){let l=o.at(-1);l&&(l.d+="Z")},stroke(){let l=i(a.lineCap!=="butt");l&&n.push(`<path d="${l}" fill="none" ${dt("stroke",a.strokeStyle)} stroke-width="${N(a.lineWidth)}" stroke-linecap="${a.lineCap}" stroke-linejoin="${a.lineJoin}"/>`)},fill(){let l=i(!1);l&&n.push(`<path d="${l}" ${dt("fill",a.fillStyle)}/>`)},clearRect(){n.length=0},fillRect(l,f,u,d){n.push(`<rect x="${N(l)}" y="${N(f)}" width="${N(u)}" height="${N(d)}" ${dt("fill",a.fillStyle)}/>`)}},c={width:e,height:t,style:{},getContext:()=>a};return a.canvas=c,{canvas:c,markup:()=>n.join("")}}var As=50;function to(e,t){return t>0?Math.max(1,e/t):As}function Ns(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=to(t,e.length);return{x:o,y:n>0?to(n,e.length):Ns(e)??o}}function Ps(e,t,n,o){return e===void 0?no(t,n,o):typeof e=="number"?{x:e,y:e}:e}function $s(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 oo(e,t,n,o,r,s,i){let a=Math.floor(n/t.x),c=Math.floor(r/t.x),l=Math.floor(o/t.y),f=Math.floor(s/t.y);for(let u=a;u<=c;u++)for(let d=l;d<=f;d++)$s(e,u,d).push(i)}function ro(e,t,n,o,r,s){let i=Math.floor((n-r)/t.x),a=Math.floor((n+r)/t.x),c=Math.floor((o-s)/t.y),l=Math.floor((o+s)/t.y),f=[],u=new Set;for(let d=i;d<=a;d++){let p=e.get(d);if(p)for(let h=c;h<=l;h++){let m=p.get(h);if(m)for(let b of m)u.has(b)||(u.add(b),f.push(b))}}return f}var so=class{constructor(e,t){this.cells=new Map;let n=[],o=0,r=0;for(let[s,i]of Object.entries(e))for(let a=0;a<i.length-1;a++){let c=i[a],l=i[a+1],f=Math.min(c.x,l.x),u=Math.min(c.y,l.y),d=Math.max(c.x,l.x),p=Math.max(c.y,l.y);o+=d-f,r+=p-u,n.push({entry:{nodeId:s,segmentIdx:a},minX:f,minY:u,maxX:d,maxY:p})}this.cellSize=Ps(t,n,o,r);for(let s of n)oo(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return ro(this.cells,this.cellSize,e,t,n,o)}},io=class{constructor(e,t,n,o,r,s=0,i,a=!1){this.cells=new Map,this.edgeCurves=kn(e,t,o,r,s,i,a);let c=[],l=0,f=0;for(let u=0;u<t.edges.length;u++){let d=t.edges[u],p=e[d.from],h=e[d.to],m=this.edgeCurves.get(u);if(p?.length&&h?.length&&m){let{minX:b,minY:g,maxX:x,maxY:M}=pn(m),y=d.pathIds?.length??0;if(n&&y>0){let w=0,v=0;for(let S of ke(p,h,y,o))w=Math.max(w,Math.abs(S.x)),v=Math.max(v,Math.abs(S.y));b-=w,g-=v,x+=w,M+=v}l+=x-b,f+=M-g,c.push({ei:u,minX:b,minY:g,maxX:x,maxY:M})}}this.cellSize=no(c,l,f);for(let u of c)oo(this.cells,this.cellSize,u.minX,u.minY,u.maxX,u.maxY,u.ei)}getCurves(e){return this.edgeCurves.get(e)}query(e,t,n,o=n){return ro(this.cells,this.cellSize,e,t,n,o)}};function co(e,t,n,o,r,s){let i=r-n,a=s-o,c=i*i+a*a;if(c===0)return Math.hypot(e-n,t-o);let l=Math.max(0,Math.min(1,((e-n)*i+(t-o)*a)/c));return Math.hypot(e-(n+l*i),t-(o+l*a))}function Cs(e,t,n){let o=1/0,r=20,s=n.x0,i=n.y0;for(let a=1;a<=r;a++){let c=a/r,l=1-c,f=l*l*l*n.x0+3*l*l*c*n.cx0+3*l*c*c*n.cx1+c*c*c*n.x1,u=l*l*l*n.y0+3*l*l*c*n.cy0+3*l*c*c*n.cy1+c*c*c*n.y1;o=Math.min(o,co(e,t,s,i,f,u)),s=f,i=u}return o}function ao(e,t,n,o=1){let r=1/0;for(let s of n){let i=Cs(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});i<r&&(r=i)}return r}var Ls=je();function lo(e,t){return Ls(e,[t],()=>new so(e))}var Is=je();function Bs(e,t,n,o,r,s,i,a=!1){return Is(e,[t,n,o.scaleX,o.scaleY,r,s,i,a],()=>new io(e,t,n,o,s,r,i,a))}var Xs=5;function Vf(e,t,n,o,r=0,s){let i=ze(o),a=lo(e,r),c=p=>Math.max(Xs,p)/o.scaleX,l=c(s?.maxHalfWidthPx??0),f=a.query(t,n,l,l/i),u=null,d=1/0;for(let{nodeId:p,segmentIdx:h}of f){let m=e[p],b=co(t,n*i,m[h].x,m[h].y*i,m[h+1].x,m[h+1].y*i);b<d&&b<c(s?.halfWidthPx(p)??0)&&(d=b,u=p)}return u}function Ds(e,t,n){let o=t.x-e.x,r=t.y-e.y,s=0,i=1;for(let[a,c]of[[-o,e.x-n.x0],[o,n.x1-e.x],[-r,e.y-n.y0],[r,n.y1-e.y]])if(a===0){if(c<0)return!1}else a<0?s=Math.max(s,c/a):i=Math.min(i,c/a);return s<=i}function fo(e,t,n=0){let o=lo(e,n),r=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let i=new Set,a=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:c,segmentIdx:l}of a){let f=e[c];!i.has(c)&&Ds(r(f[l]),r(f[l+1]),s)&&i.add(c)}return i}}function Kf(e,t,n,o,r,s,i=0,a,c,l,f=!1){let u=ze(r),d=10/r.scaleX,p=Bs(e,t,s,r,i,a,l,f),h=p.query(n,o,d,d/u),m=null,b=d;for(let g of h){let x=t.edges[g],M=e[x.from],y=e[x.to];if(!M?.length||!y?.length||c?.has(g))continue;let w=x.pathIds?.length??0,v=p.getCurves(g);if(!v)continue;let S;if(!s||w===0)S=ao(n,o*u,v,u);else{let T=1/0;for(let R of ke(M,y,w,r)){let B=R.x===0&&R.y===0?v:hn(v,R.x,R.y),q=ao(n,o*u,B,u);q<T&&(T=q)}S=T}S<b&&(b=S,m=g)}return m}var uo=3.4,ft=6,Fs=18,qs=2,Gs=3,Ys=dn+fn;function po(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 ho(e,t,n,o){let r=n/2;return mo(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:i,y:a}=t(s.at),c=po(s);return{item:s,x:i,y:a+n+Fs,text:c?`${s.gene.name} \xB7 ${c}`:s.gene.name,fallback:c?`${s.gene.name} \u2026`:void 0,stack:qs,fits:l=>[...o({x0:l.x0-r,x1:l.x1+r,y0:l.y0-r,y1:l.y1+r})].every(f=>s.nodeIds.has(f))}})}function mo(e,t){return[...e].sort((n,o)=>t(o)-t(n))}function Ws(e){let{paneWidth:t,canvasHeight:n,translateX:o,translateY:r}=e,{scaleX:s,scaleY:i}=e.axisScale,a={width:t,height:n},c=w=>({x:w.x*s+o,y:w.y*i+r}),l=e.drawnRowLabels.map(({label:w,y:v})=>Ze(w,v*i+r)),f=e.referenceStripZonePx??0;f>0&&l.push({x0:0,x1:t,y0:0,y1:f}),e.legendSize.width>0&&l.push({x0:t-ft-e.legendSize.width,x1:t,y0:0,y1:f+ft+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*de*1.2,y0:0,y1:44});let u=un(a,l),d=e.drawnRowLabels.length>0,p=d?Math.min(...e.drawnRowLabels.map(w=>w.y)):1/0,h=e.contigThickness*uo,m=(w,v)=>{let{x:S,y:T}=c({x:w.labelAt.x,y:Math.min(w.labelAt.y,p)}),R=T-h/2-v;return{x:S,y:d?Math.max(R,Ys):R}},b=mo(e.bubbleHalos.filter(w=>!w.tick),w=>w.whole?-1:w.members),g=Ve(b.map(w=>({item:w,...m(w,6),text:w.label,fallback:w.label.includes(",")?w.label.split(",")[0]:void 0,stack:Gs})),a,u),x=e.bubbleHalos.filter(w=>w.tick&&!w.whole).map(w=>({item:w,...m(w,2)})).filter(w=>w.x>=0&&w.x<=t&&w.y>=0&&w.y<=n),M=Ve(ho(e.genePins,c,e.contigThickness,fo(e.nodePositions??{},{scaleX:s,scaleY:i,translateX:o,translateY:r},e.positionsVersion)),a,u),y=e.nodePositions&&e.labelsNodeSizes?Je({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,take:u}):[];return{bubbles:g,ticks:x,genes:M,sizes:y}}var Z=JBrowseExports.mobx,se=e=>Z!=null&&e in Object(Z)?Z[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 gu=se("autorun");var bu=se("computed");var go=se("observable");var xu=se("reaction");var bo=se("runInAction");var yu=se("untracked");var wu=Z&&Z.__esModule?Z.default:Z;function ut(e){return e.id.endsWith("-")?"-":"+"}function pt(e,t){return t===ut(e)?e.id:`-${e.id}`}function Hs(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 i=e.length-1;i>r&&e[i]!==void 0;i--)s-=e[i],n[i]=s;return n}function Us(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let o=Hs(t,e.pathLength),r=o.flatMap((d,p)=>d===void 0?[]:[p]),s=d=>o[r[d]],i=d=>s(d)+t[r[d]],a=0,c=d=>{for(;a<r.length&&i(a)<d;)a++;for(let p=a;p<r.length&&s(p)<=d;p++){let h=i(p);if(d<h)return{s:r[p],local:d-s(p),room:h-d}}},l=d=>{for(let p=a;p<r.length;p++)if(s(p)>d)return s(p)-d;return 1/0},f=(d,p)=>{let h=n[d],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 d of an(e.cs))if(d.op==="match")u+=d.length;else if(d.op==="substitution"){let p=c(u);p&&f(p.s,{type:"substitution",pos:p.local,seq:d.seq}),u+=1}else if(d.op==="insertion"){let p=u>e.pathStart&&u<e.pathEnd?c(u):void 0;p&&f(p.s,{type:"insertion",pos:p.local,seq:d.seq})}else{let p=d.length;for(;p>0;){let h=c(u),m=Math.min(p,h?h.room:l(u));h&&f(h.s,{type:"deletion",pos:h.local,length:m}),u+=m,p-=m}}return n}function xo(e,t,n){let o=new Map(e.nodes.map(s=>[s.name,s])),r=[];for(let s of t){let i=s.path.map(f=>o.get(f.name)),a=i.flatMap((f,u)=>f?[u]:[]),c=a[0],l=a.at(-1);if(c!==void 0&&l!==void 0){let f=Us(s,i.map(p=>p?.length)),u=a.map(p=>pt(i[p],s.path[p].strand)),d=i[l].length;r.push({id:n+r.length,name:s.name,type:"read",sourceTrackID:1,sequence:u,sequenceNew:a.map((p,h)=>({nodeName:u[h],mismatches:f[p]})),firstNodeOffset:c===0?s.pathStart:0,finalNodeCoverLength:l===s.path.length-1?d-(s.pathLength-s.pathEnd):d,mapping_quality:s.mappingQuality===255?void 0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return r}var js=["#6baed6","#4292c6","#2171b5","#08519c"],Vs=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function yo(e){let t=e.is_reverse?Vs:js;return t[e.id%t.length]}function _(e,t={},...n){return{tag:e,attrs:t,children:n.filter(o=>!!o||o==="")}}function wo(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function Ks(e){return wo(e).replaceAll('"',"&quot;")}function zs(e){if(typeof e=="string")return wo(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${Ks(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(zs).join("")}</${e.tag}>`}var yt="#2f8fd6",wt="#8e3fbf",Mo="#bdbdbd",vo="#8a8a8a",Eo="#e2e2e2",he="#1c1c22",Mt=12,gt=4,So=1,bt=12,Zs=6,Js=3;function U(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function Qs(e){let t=Math.abs(e);return`${e>0?"+":"\u2212"}${t<1e3?`${t} bp`:U(t)}`}function ht(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}var ei=({refName:e,start:t})=>`${Qt(e)}:${t<1e6?`${Math.round(t/1e3)} kb`:`${(t/1e6).toFixed(1)} Mb`}`;function ti(e,t){let n=(t??[]).filter(i=>i.gap);if(e<=0)return"";if(!n.some(i=>i.cause))return` \xB7 ${U(e)} ${te}`;let o=i=>n.filter(a=>a.cause===i).reduce((a,c)=>a+c.bp,0),r=[...new Set(n.flatMap(i=>i.chunk?[ei(i.chunk)]:[]))];return[[o("missing"),Y.missing],[o("elsewhere"),`on nodes filed near ${r[0]}${r.length>1?` and ${r.length-1} more place${r.length>2?"s":""}`:""}`],[o("unknown"),Y.unknown],[o(void 0),te]].filter(([i])=>i>0).map(([i,a])=>` \xB7 ${U(i)} ${a}`).join("")}function ko(e,t,n,o){let{bp:r,gapBp:s,complete:i,stop:a}=e;if(!t)return`${U(r)}${ht(r,n)}`;let c=ti(s,e.runs),l=o?` \xB7 called ${U(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(i){let d=r-t.bp,p=d===0?"":` (${Qs(d)})`;return`${U(r)}${ht(r,n)}${p}${c}${l}`}let f=n?"repeat":"window";if(a?.contigEnds&&r===0)return`contig ends ${a.shortBp>0?`${U(a.shortBp)} before`:"at"} the ${f}${l}`;let u=a?a.contigEnds?`contig ends inside the ${f}`:"does not rejoin the reference within the extracted subgraph":"partial walk";return`\u2265 ${U(r)}${ht(r,n)} \xB7 ${u}${c}${l}`}function Ro(e,t,n){let o=t+6;return o+e.length*de<n?{x:o,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function To(e,t,n){if(t*n<Js)return[];let o=[];for(let r=t;r<e;r+=t)o.push(r);return o}function me(e){return e==="missing"?{fill:vo,px:So,label:Y.missing}:e==="unknown"?{fill:Eo,px:gt,label:Y.unknown}:{fill:Mo,px:gt,label:te}}function _o(e,t){if(e.gap)return{fill:me(e.cause).fill};if(!t)return{fill:e.onReference?yt:wt};if(e.referenceStart===void 0)return{fill:_e};let n=vn({...e,start:e.referenceStart},t);return n.length===1?{fill:et(n[0])}:{stops:n.map(et)}}function xt(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function ni(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function oi(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,i=({start:a,end:c})=>({start:Math.max(0,a),end:Math.min(o.bp,c)});n.set(o.name,r.map(a=>({name:a.name,...i(xt(s,a.start,a.end)),exons:a.exons.map(c=>i(xt(s,c.start,c.end))).filter(c=>c.end>c.start)})).filter(a=>a.end>a.start).sort((a,c)=>a.start-c.start))}return n}var ri=9,si=5.2,ii=8,Oo=(e,t)=>Math.min(2,(e-t)/2-1);function Ao(e,t){return Oo(e,t)>=1}function No(e,t,n,{rowPx:o=Se,barPx:r=Mt}={}){if(!Ao(o,r))return[];let s=Oo(o,r),i=e.map(l=>{let f=t(l.start);return{g:l,x:f,w:Math.max(2,t(l.end)-f)}}),a=[],c=new Set((r>=ii?[...i]:[]).sort((l,f)=>l.w-f.w).filter(({g:l,x:f,w:u})=>{let d=l.name.length*si/2,p=[f+u/2-d,f+u/2+d];return 2*d>u+6||a.some(([h,m])=>p[0]<m+2&&p[1]>h-2)?!1:(a.push(p),!0)}));return i.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(f=>({x:t(f.start),w:Math.max(1,t(f.end)-t(f.start))})),label:c.has(l)?{x:l.x+l.w/2,y:n+3,size:ri}:void 0}))}var mt=e=>`${e} row${e===1?"":"s"}`;function ai(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??Sn,ramp:!0}:{kind:"bar",fill:yt},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?_e:wt},label:`off ${e.reference.label}'s path`}],o=[e.reference,...e.rows].flatMap(s=>s.runs.filter(i=>i.gap)),r=new Set(o.map(s=>me(s.cause).label));for(let s of[void 0,"missing","unknown"]){let{fill:i,px:a,label:c}=me(s);r.has(c)&&n.push({swatch:{kind:"gap",fill:i,px:a},label:c})}return 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 ${mt(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${mt(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${mt(t.genes.unread)}`,note:!0})),n}var Po="#111",$o="#9e9e9e",vt="#c62828";function Co(e){return e.agrees===!1?vt:e.spanningReads===0?$o:Po}function ci(e,t,n,o="walk-key"){let r=0,s=e.flatMap((i,a)=>{let c=`${o}-ramp-${a}`,l=!i.note&&i.swatch.kind==="bar"&&i.swatch.ramp?_("linearGradient",{id:c},...En.map(d=>_("stop",{offset:d.offset,"stop-color":d.color}))):void 0,f=i.note?void 0:i.swatch.kind==="gene"?_("rect",{x:r,y:5,width:18,height:8,fill:"none",stroke:he,"stroke-width":1.5}):_("rect",{x:r,y:i.swatch.kind==="gap"?9-i.swatch.px/2:5,width:18,height:i.swatch.kind==="gap"?i.swatch.px:8,rx:2,fill:l?`url(#${c})`:i.swatch.fill}),u=_("text",{x:i.note?r:r+23,y:13,"font-style":i.note?"italic":void 0,fill:i.note?"#666":void 0},i.label);return r+=(i.note?0:23)+i.label.length*de+16,[l,f,u].filter(d=>d!==void 0)});return{width:r,tree:_("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function li(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(Se,o>=1?Math.floor(o):o));return{rowPx:r,barPx:r<=3?r:Math.max(3,Math.round(r*.6)),labelled:r>=bt,readouts:r>=bt}}function Lo(e,t){let n=1/t,o=[],r=[],s=()=>{if(r.length!==0){if(r.length===1)o.push(r[0]);else{let a=0,c=0;for(let u of r)u.onReference?a+=u.bp:c+=u.bp;let l=a>=c,f=r.find(u=>u.onReference===l);o.push({start:r[0].start,bp:a+c,onReference:l,referenceStart:l?f.referenceStart:void 0,...f.reversed?{reversed:!0}:{}})}r=[]}},i=0;for(let a of e){if(a.gap||a.bp>=n){s(),i=0,o.push(a);continue}r.push(a),i+=a.bp,i>=n&&(s(),i=0)}return s(),o}function di(e,t,n){return _("g",{class:"row-gene","data-testid":"graph-walk-gene"},_("title",{},e.name),...e.exons.map(o=>_("rect",{x:o.x,y:t-n/2,width:o.w,height:n,fill:he,opacity:.35})),_("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:he,"stroke-width":1.5}),e.label&&_("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:he,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function ge(e,t,n={}){let o=m=>m*t.scaleX+t.translateX,r=t.rowPx??Se,s=t.barPx??Mt,i=Math.min(3,Math.max(0,(r-s)/2)),a=m=>m*r*t.scaleY+t.translateY,{origin:c,unit:l,reference:f,rows:u}=e,d=m=>o(c+m),p=n.idPrefix??"walkrow",h=(m,b)=>{let g=a(b);if(g<-s||g>t.height+s)return;let x=t.bars===!1?[]:m.runs,M=Lo(x,t.scaleX).flatMap(R=>{let B=_o(R,n.ramp),q=R.gap?Math.min(me(R.cause).px,s):s,ye=`${p}-${b}-${R.start}`,ae=_("rect",{x:d(R.start),y:g-q/2,width:Math.max(1,R.bp*t.scaleX),height:q,fill:"stops"in B?`url(#${ye})`:B.fill});return"stops"in B?[_("linearGradient",{id:ye},...B.stops.map((we,k)=>_("stop",{offset:k/(B.stops.length-1),"stop-color":we}))),ae]:[ae]}),y=l&&s>=Zs?To(m.bp,l,t.scaleX).map(R=>_("line",{x1:d(R),x2:d(R),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:w}=m,v=ko(m,b===0?void 0:f,l,w),S=Ro(v,d(m.bp),t.width),T=t.readouts??!0;return _("g",{"data-testid":b===0?"graph-walk-reference":"graph-walk-row"},...M,...y,...No(n.rowGenes?.get(m.name)??[],d,g,{rowPx:r,barPx:s}).map(R=>di(R,g,s)),w&&_("rect",{"data-testid":"graph-walk-call",x:d(w.bp)-1,y:g-s/2-i,width:2,height:s+2*i,fill:Co(w)}),T&&_("text",{x:S.x,y:g+4,"font-family":"sans-serif","font-size":11,fill:w?.agrees===!1?vt:"#333",stroke:S.halo?"white":void 0,"stroke-width":S.halo?3:void 0,"paint-order":"stroke","text-anchor":S.anchor},v))};return _("g",{},...[f,...u].map(h))}var fi=10;function ui(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=fi*(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 pi=40;function hi(e,t){let n=A(e),o=A(t),r=o.slice(o.indexOf(" "));return n.endsWith(r)?`${n.slice(0,-r.length)}\u2013${o}`:`${n}\u2013${o}`}function Et(e){return e>=On?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function mi(e,t=[]){let n=gi(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function gi(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:i,inversion:a}=e,c=hi(o,r);if(i>=pi)return{kind:"superbubble",label:`${c} superbubble, ${i} segments, ${Et(s)}${a?", inv":""}`};if(a)return{kind:"inversion",label:`${A(r)} inv`};if(e.offReference)return o===r?Io(o):{kind:"complex",label:`${c}, ${Et(s)}`};let l=r!==o?ui(e,t):void 0;if(l){let u=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${c} repeat array${u}, ${Et(s)}`}}let f=s>2?`, ${s} alleles`:"";return o===r&&o===n?Io(n):n===0||o===n?{kind:"insertion",label:`\u2264${A(r-n)} ins${f}`}:r===n?{kind:"deletion",label:`${A(n-o)} del${f}`}:{kind:"complex",label:`${A(n)} ref \u2192 ${c}, ${s} alleles`}}function Io(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${A(e)} sub`}}var bi={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},xi={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function yi(e){return e.segments.split(",").filter(Boolean)}function St({graph:e,layout:t}){let n=new Map(e.nodes.map(r=>[r.id,r])),o=new Map;t.nodes.forEach((r,s)=>{let i=n.get(r.name);if(r.order>=0&&i&&O(i)){let{refName:a,start:c}=i.stable;ee(o,a,{name:r.name,index:s,bp0:c,bp1:c+i.length,x0:r.x,x1:r.x+r.pixelWidth})}});for(let r of o.values())r.sort((s,i)=>s.bp0-i.bp0);return o}function Ce(e,t,n=!1){let o=V(e.length-1,r=>n?e[r].bp1<t:e[r].bp1<=t);return be(e[o],t)}function be(e,t){let n=e.bp1-e.bp0;return t<=e.bp0||n<=0?e.x0:e.x0+(Math.min(t,e.bp1)-e.bp0)/n*(e.x1-e.x0)}function Le(e,t,n){let o=Ce(e,t),r=Ce(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function wi(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Bo=5,Mi=10,vi=110,Ei=3;function Xo(e){return e?"#b0b0b8":"#55555c"}function Si(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 Do(e){let t=[];for(let n of e)t.every(o=>Math.abs(n.at-o.at)>=(n.width+o.width)/2+Mi)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function ki(e,t,n,o){let r=e[0],s=e.at(-1);if(!r||!s)return;let i=t(r.x0),a=t(s.x1),c=s.bp1-r.bp0;if(a<=i||c<=0)return;let l=Si(c/(a-i)*vi),f=[],u=[];for(let d=Math.ceil(r.bp0/l)*l;d<=s.bp1;d+=l){let p=Math.round(t(Ce(e,d)))+.5;if(p>=0&&p<=n){f.push(p);let h=d.toLocaleString("en-US");u.push({text:h,at:p,width:o(h)})}}return{spans:[{x0:i,x1:a}],ticks:f,labels:Do(u)}}function Ri(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],i=r.at(-1);if(!s||!i)return;let a=(h,m)=>({text:h,at:m,width:o(h)}),c=(h,m)=>a(h.toLocaleString("en-US"),m),l=[],f=[],u=[],d=[];for(let{box:h,s0:m,s1:b}of r){l.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Ei&&f.push(Math.round(b)+.5);let g=a(A(h.bp1-h.bp0),(m+b)/2);g.width<=b-m&&u.push(g),h!==s.box&&d.push(c(h.bp0,m))}let p=[c(s.box.bp0,s.s0),c(i.box.bp1,i.s1)];return{spans:l,ticks:f,labels:Do([...p,...u,...d])}}function Fo(e,t,n,o,r=!1){return(r?ki:Ri)(e,t,n,o)}function Ti(e,t,n,o,r=!1){let{x:s,width:i,darkMode:a}=n;e.font="10px sans-serif";let c=Fo(t,s,i,u=>e.measureText(u).width,r);if(!c)return;let l=Xo(a),f=o+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:d}of c.spans)e.moveTo(Math.max(0,u),f),e.lineTo(Math.min(i,d),f);for(let u of c.ticks)e.moveTo(u,o),e.lineTo(u,o+Bo);e.stroke();for(let{text:u,at:d}of c.labels)e.fillText(u,d,o+Bo+2)}function _i(e,t,n,o){let r=[];for(let s of e){let i=n(s.x0),a=n(s.x1);a>=0&&i<=o&&r.push({node:s.name,top0:t(s.bp0),top1:t(s.bp1),bottom0:i,bottom1:a})}return r}var Oi=3;function Ai(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,i=Oi;for(let a of e){let c=a.top0+(a.bottom0-a.top0)*r,l=a.top1+(a.bottom1-a.top1)*r,f=Math.max(0,Math.min(c,l)-n,n-Math.max(c,l));f<i&&(i=f,s=a.node)}return s}function qo(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 Go(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function Ni(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 i of t)qo(e,i,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let i of t)Go(e,i,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke(),Yo(e,t,n,o)}function Yo(e,t,n,o){let r=n>0&&o?t.find(s=>s.node===o):void 0;r&&(e.beginPath(),qo(e,r,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),Go(e,r,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function Wo(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}var Pi=new Set(["_gbwt_ref","unknown"]);function Ho(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||Pi.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var $i=["read_group","sample_name"],Pp=[...$i,"haplotype_sample"],Ie=8.401;function Ci({layers:e,coarsenedReadView:t=!1,showReads:n=!0},o){if(e!==void 0)return e;let r=t&&n,s=i=>i?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(r&&!o)},{data:"reads",...s(r&&o)}]}function Uo(e,t){return e.find(n=>n.data===t)?.stat}function Li(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:Ci(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??Ie,trackWidth:e.trackWidth??15,freqWidth:e.freqWidth??"log"}}function Ii(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}function sr(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:Ii(),trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function ir(e,t,n=[],o={}){let r=Bi(e,t,n,o);return r&&Xi(r,o)}var ar=new WeakMap;function Bi(e,t,n=[],o={}){let r=Fi(e,t,n,o);if(r===void 0)return;let s=cr(r,r.tracks,r.reads,"measure");return s.nodes.forEach((i,a)=>{i.order>=0&&(r.nodes[a].x=i.x)}),ar.set(r,s),r}function Xi(e,t={}){return Di(e,Wi(e,t.facet),qi(e,t))}function Di(e,t,n,o){let r=ar.get(e);return r!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?r:cr(e,t,n,"topology",o)}function Fi(e,t,n,o){let r=sr(Li(o,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,i)=>{s.seq??="",s.sequenceLength??=s.seq.length,r.nodes[i+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 i=r.tracks[s];if(i.type??="haplotype",i.hidden===!0){r.tracks.splice(s,1);continue}i.indexOfFirstBase!==void 0&&(r.trackForRuler=i.name)}if(r.tracks.length!==0)return Ui(r,0),r.nodeMap=zo(r),ie(r,r.tracks),ie(r,r.reads),or(r),r.config.mergeNodes&&(Zo(r),Rt(r),_t(r),La(r),r.nodeMap=zo(r),or(r),ie(r,r.tracks),ie(r,r.reads)),Zo(r),pa(r),Rt(r),ha(r),Rt(r),_t(r),ie(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:fa(r),trackForRuler:r.trackForRuler}}}function qi(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||Gi(o,s)))}function Gi(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Yi(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Wi(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Yi(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Hi(o)===t.key)}function Hi(e){return Ho(e.name)?.sample??null}function cr(e,t,n,o,r={}){let s=sr(e.options);e.nodes.forEach((d,p)=>{s.nodes[p]={...d}}),s.tracks=t.map(d=>({...d})),s.reads=n.map(d=>({...d})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:i,ignoreStrand:a}=s.config,c=r.haplotypes??_a,l=Uo(i,"haplotypes")==="coarsen"?Oa(s,c):void 0;l!==void 0&&(s.tracks=[l.ref]),Ra(s),ya(s),ji(s);let f=Uo(i,"reads")==="coarsen"&&s.reads.length>0?pr(s,s.reads,"read",r.reads??c+(l?.bands.length??0)):void 0;f!==void 0&&(s.reads=f.bands);let u={};for(let[d,p,h]of[["haplotypes","haplotype",l],["reads","read",f]])h!==void 0&&(_t(s,h.bands),ie(s,h.bands),u[d]={unit:p,total:h.total,reverse:!a&&h.bands.some(m=>m.is_reverse)});return l!==void 0&&(s.reads=l.bands.concat(s.reads)),Ki(s),s.tracks=s.tracks.concat(s.reads),o==="measure"&&ga(s),Ta(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:sa(s),maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:u}}function P(e){return e.startsWith("-")}function $(e){return P(e)?e.substring(1):e}function lr(e){return P(e)?e:`-${e}`}function Ot(e){return P(e)?$(e):lr(e)}function jo(e){return e>0}function Ui(e,t){let n=new Set,o=new Set;for(let r of e.tracks[t].sequence)P(r)?o.has($(r))||n.add($(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($(r[s]))&&(r[s]=Ot(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Pt(r.seq))})}}function ji(e){e.nodesPerOrder=Array.from({length:e.maxOrder+1},()=>[]);let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&Vo(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(o=>{Vo(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 Vo(e,t,n){let o=e.get(t);o===void 0?e.set(t,n):e.set(t,Math.max(o,n))}var At=7;function Vi(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{(t.width===void 0||t.width===0)&&(t.width=At),t.path.forEach((o,r)=>{if(o.node===null)return;let s=e.nodes[o.node];t.path.length===1?s.internalReads.push(n):r===0?s.outgoingReads.push([n,r]):s.incomingReads.push([n,r])})})}function Ki(e){e.reads.forEach(a=>{a.path=dr(e,a)}),Vi(e);let t=e.nodes.filter(a=>a.order>=0);t.sort(Ct);let n=new Map;for(let a=0;a<e.reads.length;a++){let c=e.reads[a],l=c.haplotypeShare===void 0?1:0,f=c.sourceTrackID,u=`${l}:${f}`,d=n.get(u);d===void 0?n.set(u,{layer:l,source:f,reads:new Set([a])}):d.reads.add(a)}let o=[...n.values()].sort((a,c)=>a.layer-c.layer||a.source-c.source),r=o.length>1?At:0;t.forEach(a=>{for(let{reads:c}of o)zi(e,c,a,r)});let s=na(e),i=[];e.reads.forEach((a,c)=>{let l=[],f=[],u;a.path.forEach((d,p)=>{l[p]=u,d.node!==null&&(u=d)}),u=void 0;for(let d=a.path.length-1;d>=0;d-=1)f[d]=u,a.path[d].node!==null&&(u=a.path[d]);a.path.forEach((d,p)=>{if(d.y===void 0){let h=l[p],m=f[p],b=!!(m&&h&&(h.order>m.order||m.order===h.order&&m.isForward===h.isForward));d.betweenCycleReverseTraversal=b,i.push({readIndex:c,pathIndex:p,previousY:h?.y,previousNode:h?.node})}})}),i.sort((a,c)=>Ji(e,a,c)),i.forEach(a=>{let c=e.reads[a.readIndex],l=c.path[a.pathIndex];l.y=s[l.order],s[l.order]+=c.width})}function zi(e,t,n,o){let r=n.incomingReads.filter(([h])=>t.has(h)),s=n.outgoingReads.filter(([h])=>t.has(h)),i=n.internalReads.filter(h=>t.has(h));r.length===0&&s.length===0&&i.length===0&&(o=0);let a=n.y+n.contentHeight+o*2,c=r.map(h=>{let[m,b]=h,g=e.reads[m].path,x=b+1,M;for(let y=1;y<=b;y++){let w=g[b-y]?.y;if(w!==void 0){x=y,M=w;break}}return{entry:h,decisionStep:x,y:M}});c.sort(Zi),r=c.map(h=>h.entry);let l=a,f=new Map;r.forEach(h=>{let m=e.reads[h[0]];m.path[h[1]].y=l,Ko(f,m,h[1],l,n),l+=m.width});let u=l;s.sort((h,m)=>Qi(e,h,m));let d=new Map;l=a,s.forEach(h=>{let m=e.reads[h[0]],b=m.firstNodeOffset??0;m.path[h[1]].y=l,d.set(l,b);let g=f.get(l);g===void 0||g+1<=b?(l+=m.width,u=Math.max(u,l)):(f.set(l,0),r.forEach(x=>{let M=e.reads[x[0]],y=M.path[x[1]];y.y!==void 0&&y.y>=l&&(y.y+=m.width,Ko(f,M,x[1],y.y,n))}),l+=m.width,u+=m.width)}),i.sort((h,m)=>ta(e,h,m)),i.forEach(h=>{let m=e.reads[h],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(l=a;b<(f.get(l)??-1/0)+2||g>(d.get(l)??1/0)-3;)l+=m.width;m.path[0].y=l,f.set(l,g),u=Math.max(u,l)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,Sa(e,n,p)}function Zi(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 Ko(e,t,n,o,r){e.set(o,n===t.path.length-1?t.finalNodeCoverLength??0:r.sequenceLength)}function Ji(e,t,n){let o=e.reads[t.readIndex],r=e.reads[n.readIndex],s=o.path[t.pathIndex],i=r.path[n.pathIndex];if(s.order!==i.order)return s.order-i.order;if(o.sourceTrackID!==r.sourceTrackID)return o.sourceTrackID-r.sourceTrackID;if(t.previousNode&&n.previousNode){let u=e.nodes[t.previousNode],d=e.nodes[n.previousNode];if(u&&d&&u.order!==d.order)return u.order-d.order}let a=t.previousY??0,c=n.previousY??0,l=s.betweenCycleReverseTraversal===!0,f=i.betweenCycleReverseTraversal===!0;return l!==f?l?1:-1:l?c-a:a-c}function Qi(e,[t,n],[o,r]){let s=e.reads[t],i=e.reads[o],a=s.path.findLast(p=>p.y!==void 0)?.y,c=i.path.findLast(p=>p.y!==void 0)?.y;if(a!==void 0&&c!==void 0)return a-c;let l=(p,h)=>{let m=p.path[h]?.node;return m==null?null:e.nodes[m]??null},f=(p,h)=>{let m=h+1;for(;p.path[m]?.node===null;)m+=1;return m},u=l(s,n),d=l(i,r);for(;u!==null&&u===d;)n=f(s,n),r=f(i,r),u=l(s,n),d=l(i,r);return u!==null&&d!==null?Ct(u,d):u!==null||d!==null?u===null?-1:1:(s.firstNodeOffset??0)-(i.firstNodeOffset??0)||(s.finalNodeCoverLength??0)-(i.finalNodeCoverLength??0)}function ea(e,t){let n=e.path,o=t.path,r=0,s=0;for(;r<n.length&&s<o.length;){let i=n[r],a=o[s],c=i.order,l=a.order;if(c===l&&i.node&&a.node)return(a.y??0)-(i.y??0);c<l?r+=1:(c>l||(r+=1),s+=1)}return 0}function ta(e,t,n){let o=e.reads[t],r=e.reads[n];return(o.firstNodeOffset??0)-(r.firstNodeOffset??0)||(o.finalNodeCoverLength??0)-(r.finalNodeCoverLength??0)}function na(e){let t=new Array(e.maxOrder+1).fill(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 dr(e,t){let n=[],o=(c,l)=>{n.push({order:c,isForward:l,node:null})},r=(c,l,f)=>{n.push({order:c,isForward:l,node:f})},s=Math.abs(t.indexSequence[0]),i=jo(t.indexSequence[0]),a=e.nodes[s];r(a.order,i,s);for(let c=1;c<t.sequence.length;c+=1){let l=a,f=i;s=Math.abs(t.indexSequence[c]),i=jo(t.indexSequence[c]),a=e.nodes[s];let{order:u}=a;if(u>l.order){f||o(l.order,!0);for(let d=l.order+1;d<u;d+=1)o(d,!0);i||o(u,!0)}else if(u<l.order){f&&o(l.order,!1);for(let d=l.order-1;d>u;d-=1)o(d,!1);i&&o(u,!1)}else i===f&&o(u,!i);r(u,i,s)}return n}function _t(e,t=e.reads){t.forEach(n=>{if(!n.sequence.every(P))return;n.is_reverse=n.is_reverse!==!0,n.sequence=n.sequence.toReversed().map($),n.sequenceNew!==void 0&&(n.sequenceNew=n.sequenceNew.toReversed());for(let i of n.sequenceNew??[]){i.nodeName=$(i.nodeName);let{sequenceLength:a}=kt(e,i.nodeName);i.mismatches=i.mismatches.map(c=>Nt(c,a))}let o=n.firstNodeOffset??0,r=kt(e,n.sequence[0]).sequenceLength,s=kt(e,n.sequence.at(-1)).sequenceLength;n.firstNodeOffset=r-(n.finalNodeCoverLength??0),n.finalNodeCoverLength=s-o})}function Nt(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:Pt(e.seq)}}}var oa={A:"T",T:"A",C:"G",G:"C"};function Pt(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=oa[e.charAt(n)]??"N";return t}function ie(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 i=e.nodeMap.get($(r));if(i===void 0)throw new Error(`Track ${o.name??o.id} visits unknown node ${r}`);s=P(r)?-i:i,n.set(r,s)}return s})})}var ra=20;function sa(e){let t={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0},{rectangles:n,verticalRectangles:o,curves:r}=e.shapes;for(let s of[n,o,r])for(let{xStart:i,xEnd:a}of s)t.minX=Math.min(t.minX,i,a),t.maxX=Math.max(t.maxX,i,a);return 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+ra+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(i=>{let a=i.y??0;t.maxY=Math.max(t.maxY,a+s.width),t.minY=Math.min(t.minY,a)})}),t}function kt(e,t){let n=e.nodeMap.get($(t)),o=n===void 0?void 0:e.nodes[n];if(o===void 0)throw new Error(`Unknown node ${t}`);return o}function zo(e){let t=new Map;return e.nodes.forEach((n,o)=>{t.set(n.name,o)}),t}function Zo(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 i=Math.abs(r.indexSequence[s]),a=Math.abs(r.indexSequence[s+1]);t[i].add(a),n[a].add(i)}};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 Jo(e,t){let n=0,o=0,r=0;t.forEach(s=>{let i=Math.abs(s);if(s<0){let a=e.nodeOrders[i]??=o;a<r&&(r=a),n=a,o=a-1}else{let a=e.nodeOrders[i]??=n;n=a+1,o=a}}),r<0&&$t(e,-r)}function ia(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,i;r>=0?(s=e.nodeOrders[r]-1,i=-1):(s=e.nodeOrders[-r]+1,i=1);for(let a=n-1;a>=0;a-=1){let c=Math.abs(t[a]);e.nodeOrders[c]===void 0&&(e.nodeOrders[c]=s,o=Math.min(o,s),s+=i)}return o<0&&$t(e,-o),n}var aa=-1;function ca(e){return Array.from(e,t=>t??aa)}function la(e){let t=[...new Set(e.filter(o=>o>=0))].sort((o,r)=>o-r),n=new Map(t.map((o,r)=>[o,r]));return e.map(o=>n.get(o)??o)}function Rt(e){let t,n,o,r,s=0,i=e.tracks.concat(e.reads),a={stamp:new Int32Array(e.nodes.length),generation:0};e.nodeOrders=new Array(e.nodes.length).fill(void 0),e.nodes.forEach(c=>{c.order=void 0}),Jo(e,e.tracks[0].indexSequence);for(let c=1;c<i.length;c+=1){if(o=ia(e,i[c].indexSequence),o===null){c<e.tracks.length?Jo(e,i[c].indexSequence):(i.splice(c,1),e.reads.splice(c-e.tracks.length,1),c-=1);continue}for(t=ua(i[c].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 l=r+1;l<o;l+=1)e.nodeOrders[t[l]]=n,n+=1;if(e.nodeOrders[t[o]]>e.nodeOrders[t[r]])e.nodeOrders[t[o]]<n&&Qo(e,t[o],t[o-1],n);else if(i[c].indexSequence[o]>=0&&!da(e,t[o],t[r],a))Qo(e,t[o],t[o-1],n);else if(i[c].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 l=r+1;l<o;l+=1)e.nodeOrders[t[l]]=n,s=Math.min(s,n),n-=1}}else if(i[c].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let l=r+1;l<t.length;l+=1){let f=t[l];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let l=r+1;l<t.length;l+=1){let f=t[l];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,s=Math.min(s,n),n-=1)}}}}s<0&&$t(e,-s),e.nodeOrders=la(ca(e.nodeOrders)),e.nodes.forEach((c,l)=>{c.order=e.nodeOrders[l]})}function da(e,t,n,o){o.generation+=1;let{stamp:r,generation:s}=o,i=[t];for(r[t]=s;i.length>0;){let a=i.pop();if(a===n)return!0;for(let c of e.nodes[a].successors)r[c]!==s&&(r[c]=s,i.push(c))}return!1}function fa(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function ua(e){return e.map(t=>Math.abs(t))}function $t(e,t){e.nodeOrders.forEach((n,o)=>{n!==void 0&&(e.nodeOrders[o]=n+t)})}function Qo(e,t,n,o){let r=new Map,s=[[t,o]],i=0;for(;i<s.length;){let[a,c]=s[i];i+=1;let l=e.nodeOrders[a];l!==void 0&&l<c&&(r.get(a)??-1/0)<c&&(r.set(a,c),e.nodes[a].successors.forEach(f=>{e.nodeOrders[f]>l&&f!==n&&s.push([f,c+1])}),a!==t&&e.nodes[a].predecessors.forEach(f=>{e.nodeOrders[f]>l&&f!==n&&s.push([f,c+1])}))}r.forEach((a,c)=>{e.nodeOrders[c]=a})}function pa(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 ha(e){ma(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function ma(e,t,n){let o=new Int32Array(e.nodes.length),r=new Uint8Array(e.nodes.length);for(let s of n.sequence){let i=P(s)?void 0:e.nodeMap.get(s);i!==void 0&&(r[i]=1)}for(let s of t){let{sequence:i,indexSequence:a}=s,c=a.length-1;for(let l=0;l<=c;l+=1){let f=Math.abs(a[l]);if(r[f]===1)continue;let u=e.nodes[f].order,d=l>0?e.nodes[Math.abs(a[l-1])].order:void 0,p=l<c?e.nodes[Math.abs(a[l+1])].order:void 0,h=P(i[l])?1:-1;(d===void 0||d<u)&&(p===void 0||u<p)&&(o[f]+=h),(d===void 0||d>u)&&(p===void 0||u>p)&&(o[f]-=h)}}for(let s of t){let{sequence:i,indexSequence:a}=s;for(let c=0;c<a.length;c+=1)o[Math.abs(a[c])]>0&&(i[c]=Ot(i[c]),a[c]=-a[c])}e.nodes.forEach((s,i)=>{o[i]>0&&(s.seq=Pt(s.seq),s.switched=!0)})}function ga(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort(Ct);let s=xa(e);r.forEach(i=>{i.order>=0&&(i.order>o&&(o=i.order,t=n+10*s[i.order]),i.x=t,n=Math.max(n,t+40+i.pixelWidth))})}var Tt=35;function ba(e){return e<=Tt?e/17.5:Tt/17.5*Math.sqrt(e/Tt)}function xa(e){let t=e.maxOrder+1,n=new Array(t).fill(0),o=new Array(t).fill(0),r=new Array(t).fill(0),s=[];e.tracks.forEach(i=>{for(let a=1;a<i.path.length;a+=1){let c=i.path[a],l=i.path[a-1];c.order===l.order?c.isForward?n[c.order]+=1:o[c.order]+=1:r[c.order]=Math.max(ba(Math.abs((c.y??0)-(l.y??0))),r[c.order])}}),s.push(Math.max(0,n[0]-1));for(let i=1;i<=e.maxOrder;i+=1)s.push(Math.max(Math.max(0,n[i]-1)+Math.max(0,o[i-1]-1),r[i]));return s}function ya(e){e.assignments=Array.from({length:e.maxOrder+1},()=>[]);let t=new Map;e.tracks.forEach((n,o)=>{n.path=dr(e,n),n.path.forEach(({order:r,node:s},i)=>{let a={trackID:o,segmentID:i},c=s===null?void 0:t.get(s);if(c===void 0){let l={node:s,tracks:[a]};e.assignments[r].push(l),s!==null&&t.set(s,l)}else c.tracks.push(a)})});for(let n=0;n<=e.maxOrder;n+=1)va(e,e.assignments[n],n)}function wa(e,t,n){t.forEach(o=>{let r=0;o.tracks.forEach(s=>{let i=Ma(e.tracks[s.trackID].path,s.segmentID,n-1);s.idealLane=i===void 0?s.trackID:i.lane,s.idealY=i===void 0?null:i.y,r+=s.idealLane}),o.idealLane=r/o.tracks.length})}function Ma(e,t,n){if(t!==0)return e[t-1].order===n?e[t-1]:e[t+1]?.order===n?e[t+1]:e.slice(0,t).findLast(o=>o.order===n)}function va(e,t,n){let o=0,r=new Set,s=20,i=!1,a=-1;wa(e,t,n),t.sort(er),t.forEach(c=>{let l=c.node===null?void 0:e.nodes[c.node];l!==void 0?(i&&(s-=10),l.y=s,l.contentHeight=0,i=!1):(i?s-=25:s>20&&(s-=10),i=!0),c.tracks.sort(er),c.tracks.forEach(f=>{let{path:u,width:d}=e.tracks[f.trackID];f.trackID===a&&l===void 0&&i&&(s+=10),u[f.segmentID].lane=o,u[f.segmentID].y=s,typeof f.idealY=="number"&&r.add(f.idealY-s),o+=1,s+=d,l!==void 0&&(l.contentHeight+=d),a=f.trackID}),s+=25}),Ea(e,t,r)}function Ea(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let i=ka(e,t,s);i<r&&(r=i,o=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=o),s.tracks.forEach(i=>{let a=e.tracks[i.trackID].path[i.segmentID];a.y=a.y+o})})}function Sa(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 i=e.tracks[s.trackID].path[s.segmentID];i.y=i.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].forEach(o=>{let r=e.nodes[o];r!==t&&r.y>t.y&&(r.y+=n)}))}function ka(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{let{type:i,path:a,width:c}=e.tracks[s.trackID];typeof s.idealY=="number"&&i!=="read"&&(o+=Math.abs(s.idealY-n-a[s.segmentID].y)*c)})}),o}function er(e,t){return e.idealLane===void 0||t.idealLane===void 0?+(e.idealLane===void 0)-+(t.idealLane===void 0):e.idealLane-t.idealLane}function Ct(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 Ra(e){let n=e.config.trackWidth;if(e.config.freqWidth==="linear"){for(let o of e.tracks)o.width=o.type==="read"?4:Math.max(1,Math.round(o.freq??1))*n;return}for(let o of e.tracks)o.width=o.freq!==void 0?Math.round((Math.log(Math.max(o.freq,1))+1)*4):o.type==="read"?4:n;e.tracks.every(o=>o.width===4)&&e.tracks.forEach(o=>{o.freq!==void 0&&(o.width=n)})}function tr(e,t,n){let o=e.nodes[t.node];return ur(o,t.isForward?n:o.sequenceLength-n)}function fr(e,t){return t>e.sequenceLength?null:ur(e,t)}function ur(e,t){let[n,o]=Ca(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 Ta(e){e.extraLeft=new Array(e.maxOrder+1).fill(0),e.extraRight=new Array(e.maxOrder+1).fill(0);let t=[],n=[];e.nodes.forEach(r=>{r.x!==void 0&&(t[r.order]=r.x,n[r.order]=Math.max(n[r.order]??-1/0,r.x+r.pixelWidth))});let o=e.tracks[0];e.tracks.sort(ea),e.tracks.forEach(r=>{let{id:s,name:i,type:a,width:c,path:l}=r,f=(g,x,M)=>{e.shapes.rectangles.push({xStart:Math.min(g,x),yStart:M,xEnd:Math.max(g,x),yEnd:M+c-1,id:s,name:i,type:a})},u=g=>g.isForward?n[g.order]:t[g.order],d=l[0],p=d.y,h=a==="read"?tr(e,d,r.firstNodeOffset??0):d.isForward?t[d.order]-20:n[d.order]+20;for(let g=1;g<l.length;g+=1){let x=l[g-1],M=l[g];if(M.y===p)continue;let y=u(x);y!==h&&f(h,y,p);let w=M.y,v=M.order-x.order;if(v===1||v===-1){let S=v===1?t[M.order]:n[M.order];e.shapes.curves.push({xStart:v===1?y:y+1,yStart:p,xEnd:v===1?S+1:S,yEnd:w,width:c,id:s,name:i,type:a,nodeStart:x.node,nodeEnd:M.node,orderStart:x.order,orderEnd:M.order,...r===o?{reference:!0}:{}}),h=S}else $a(e,r,x.isForward?1:-1,y,p,w,M.order),h=y;p=w}let m=l[l.length-1],b=a==="read"?tr(e,m,r.finalNodeCoverLength??0):u(m)+(m.isForward?20:-20);f(h,b,p)})}var _a=1e9;function pr(e,t,n,o){let r=new Map,s=0,i=e.nodes.length,a=(m,b)=>(m+i)*(2*i+1)+b+i,c=e.config.ignoreStrand;for(let[m,b]of t.entries()){let g=Math.max(b.freq??1,1);s+=g;let x=b.indexSequence;if(!(x.length<2))for(let M=0;M<x.length-1;M+=1){let y=x[M],w=x[M+1],v=e.nodes[Math.abs(y)],S=e.nodes[Math.abs(w)],T=c?Math.min(a(y,w),a(-w,-y)):a(y,w),R=r.get(T);R===void 0?r.set(T,{sSigned:y,dSigned:w,sName:y<0?`-${v.name}`:v.name,dName:w<0?`-${S.name}`:S.name,count:g,crossings:g,sourceTrackID:b.sourceTrackID,lastSource:m}):(R.crossings+=g,R.lastSource!==m&&(R.count+=g,R.lastSource=m))}}let l=0;for(let m of r.values())m.crossings>l&&(l=m.crossings);let f=At,u=60,d=m=>l<=1?f:f+(u-f)*Math.sqrt(m/l),p=[],h=0;for(let m of r.values()){let b=o+h,g=n==="haplotype"?{count:m.count,total:s}:void 0,x=g===void 0?"":` (${Pa(g)})`,M=m.crossings===m.count?"":`, ${m.crossings.toLocaleString()} crossings`,y=`${m.count.toLocaleString()} ${n}${m.count===1?"":"s"}${x}${M}: Node ${m.sName} \u2192 Node ${m.dName}`;e.coarsenedEdgeMeta.set(b,{count:m.count,label:y});let w=e.nodes[Math.abs(m.sSigned)].sequenceLength;p.push({id:b,sourceTrackID:m.sourceTrackID,type:"read",name:y,sequence:[m.sName,m.dName],indexSequence:[],path:[],width:d(m.crossings),firstNodeOffset:w,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:g}),h+=1}return{bands:p,total:s}}function Oa(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(f=>f.name===e.trackForRuler),o=n===-1?0:n,r=e.tracks[o],s=(r.freq??1)-1,i=Na(e,r),a=e.tracks.filter((f,u)=>u!==o).map(f=>Aa(i,f));if(s>0&&a.push({...r,freq:s}),a.length===0)return;let{bands:c,total:l}=pr(e,a,"haplotype",t);return c.length>0?{ref:r,bands:c,total:l}:void 0}function Aa(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(Ot).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function Na(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 Pa({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var nr=7;function $a(e,{width:t,id:n,name:o,type:r},s,i,a,c,l){let f=s===1?e.extraRight:e.extraLeft,u=10*f[l],d=i+s*(u+5),p=nr,h=Math.min(nr,t),m=Math.min(a,c),b=Math.max(a,c),g=s===1?i:d-1,x=s===1?d:i,M=S=>{e.shapes.verticalRectangles.push({xStart:g,yStart:S,xEnd:x,yEnd:S+t-1,id:n,name:o,type:r})};M(a),e.shapes.verticalRectangles.push({xStart:s===1?d+p:d-p-h,yStart:m+t+p-1,xEnd:s===1?d+p+h-1:d-p-1,yEnd:b-p+1,id:n,name:o,type:r}),M(c);let y=d+s*p,w=d+s*(p+h),v=`M ${d} ${b}`;v+=` Q ${y} ${b} ${y} ${b-p}`,v+=` H ${w}`,v+=` Q ${w} ${b+t} ${d} ${b+t}`,v+=" Z ",e.shapes.corners.push({path:v,id:n,name:o,type:r}),v=`M ${d} ${m}`,v+=` Q ${w} ${m} ${w} ${m+t+p}`,v+=` H ${y}`,v+=` Q ${y} ${m+t} ${d} ${m+t}`,v+=" Z ",e.shapes.corners.push({path:v,id:n,name:o,type:r}),f[l]+=1}function Ca(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function or(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)*Ie)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*Ie),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*Ie)});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 J=0;function rr(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function I(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 xe(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function La(e){let t=rr(e.nodes.length),n=rr(e.nodes.length),o=new Map,r=u=>{let d=o.get(u);if(d===void 0){let p=e.nodeMap.get($(u));d=P(u)?-p:p,o.set(u,d)}return d};e.tracks.concat(e.reads).forEach(u=>{let{sequence:d}=u,p=u.type==="haplotype",h=d.length-1,m=J,b=h>=0?r(d[0]):J;for(let g=0;g<=h;g+=1){let x=g<h?r(d[g+1]):J;if(b>0)g>0?(I(t,b,m),m<0&&I(t,b,-m)):p&&I(t,b,J),g<h?(I(n,b,x),x<0&&I(n,b,-x)):p&&I(n,b,J);else{let M=-b;g>0?(I(n,M,-m),m>0&&I(n,M,m)):p&&I(n,M,J),g<h?(I(t,M,-x),x>0&&I(t,M,x)):p&&I(t,M,J)}m=b,b=x}});let i=new Uint8Array(e.nodes.length);e.nodes.forEach((u,d)=>{Ia(d,t,n)&&(i[d]=1)});let a=new Int32Array(e.nodes.length),c=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((u,d)=>{if(i[d]!==1){a[d]=d,l[d]=u.sequenceLength;for(let p=d;Ba(p,t,n);)p=xe(n,p),a[p]=d,c[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:d}=u,p=u.sequenceNew??d.map(M=>({nodeName:M,mismatches:[]})),h=M=>{let y=Math.abs(r(M));return P(M)?e.nodes[a[y]].sequenceLength-l[y]:c[y]},m=d.length-1;u.firstNodeOffset=(u.firstNodeOffset??0)+h(d[0]),u.finalNodeCoverLength=(u.finalNodeCoverLength??0)+h(d[m]);let b=[],g=[],x=[];d.forEach((M,y)=>{let w=Math.abs(r(M)),{mismatches:v}=p[y],S=h(M);if(v.forEach(T=>{T.pos+=S}),i[w]===1&&!P(M)&&y>0)g.at(-1).mismatches.push(...v);else if(i[w]===1&&P(M)&&y<m)x.push(...v);else{let T=e.nodes[a[w]].name,R=P(M)?lr(T):T;b.push(R),g.push({nodeName:R,mismatches:x.concat(v)}),x=[]}}),u.sequence=b,u.sequenceNew!==void 0&&(u.sequenceNew=g)}),e.tracks.forEach(u=>{let{sequence:d}=u,p=0;for(let h of d)i[Math.abs(r(h))]===0&&(d[p]=h,p+=1);d.length=p});let f=1;for(let u=1;u<e.nodes.length;u+=1)i[u]===0&&(e.nodes[f]=e.nodes[u],f+=1);e.nodes.length=f}function Ia(e,t,n){let o=xe(t,e);return o!==0&&xe(n,o)!==0}function Ba(e,t,n){let o=xe(n,e);return o!==0&&xe(t,o)!==0}function Xa(e,t){return t.xStart-e.xStart||e.yStart-t.yStart}function Lt(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function Da(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 hr=.75,Be=.8;function Fa(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(d=>{let p=Math.abs(d.yEnd-d.yStart),h=p/Math.hypot(p,o)*Math.min(d.width,Be*hr*o);return Math.max(r,h/(hr*o))}),i=d=>s.reduce((p,h,m)=>p+(d(e[m])?h:0),0),a=i(d=>d.reference===!0),c=i(d=>d.reference!==!0),l=a>Be?Be/a:1,f=Be-a*l,u=c>f?f/c:1;return s.map((d,p)=>d*(e[p].reference?l:u))}function mr(e,t,{gapWidth:n=1/0}={}){let o=Wo(e.filter(r=>r.type===t),r=>Lt(r).join(","));return o.forEach(r=>{r.sort(Xa);let s=Fa(r,n),i=.5-s.reduce((a,c)=>a+c,0)/2;r.forEach((a,c)=>{let l=p=>a.xStart+(a.xEnd-a.xStart)*(a.yStart<a.yEnd?1-p:p),f=l(i);i+=s[c];let u=l(i),d=`M ${a.xStart} ${a.yStart}`;d+=` C ${f} ${a.yStart} ${f} ${a.yEnd} ${a.xEnd} ${a.yEnd}`,d+=` V ${a.yEnd+a.width}`,d+=` C ${u} ${a.yEnd+a.width} ${u} ${a.yStart+a.width} ${a.xStart} ${a.yStart+a.width}`,d+=" Z",a.path=d})}),[...o.values()].sort((r,s)=>Da(Lt(r[0]),Lt(s[0]))).flat()}function gr(e,t=16){let n=e.match(/[A-Za-z]|-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/g)??[],o=[],r=0,s=0,i=0,a=()=>Number(n[i++]);for(;i<n.length;){let c=n[i++];if(c==="M"||c==="L")r=a(),s=a(),o.push([r,s]);else if(c==="H")r=a(),o.push([r,s]);else if(c==="V")s=a(),o.push([r,s]);else if(c==="C"){let[l,f,u,d,p,h]=[a(),a(),a(),a(),a(),a()];for(let m=1;m<=t;m+=1){let b=m/t,g=1-b,x=g*g*g,M=3*g*g*b,y=3*g*b*b,w=b*b*b;o.push([x*r+M*l+y*u+w*p,x*s+M*f+y*d+w*h])}r=p,s=h}else if(c==="Q"){let[l,f,u,d]=[a(),a(),a(),a()];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*f+h*h*d])}r=u,s=d}else if(c!=="Z")throw new Error(`flattenPath: unsupported path command ${c}`)}return o}function br(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 It(e){let t=new Map(e.nodes.map(r=>[r.id,r])),n=e.pathVisits,o=n?.replay();return(e.paths??[]).map(r=>{let s=n?.pathIndex(L(r.name).name)??-1;return r.nodeIds.flatMap(i=>{let a=t.get(i);if(!a)return[];let c=n&&o?o(n.slot(a.name),s):-1;return[{node:a,strand:c>=0?n.strand(c):ut(a)}]})})}function qa(e){let t=It(e),n=(e.paths??[]).flatMap((s,i)=>{let a=t[i].map(c=>pt(c.node,c.strand));return a.length>0?[{id:i,name:s.name,sequence:a,sourceTrackID:0,type:"haplotype",...s.members?{freq:s.members.length}:{}}]:[]}),o=ve(e),r=n.findIndex(s=>L(s.name).name===o);return r>0&&n.unshift(...n.splice(r,1)),n}function Ga(e){return e.nodes.map(t=>({name:t.id,seq:"",sequenceLength:Math.max(1,t.length)}))}function yr(e){return(e.paths?.length??0)>0}var Ya=600,Wa=3,Ha=15;function Ua(e){return Math.max(Wa,Math.min(Ha,Math.floor(Ya/Math.max(1,e))))}function ja(e){let t=new Set,n=new Set;for(let o of e?.sequence??[])P(o)?n.has($(o))||t.add($(o)):n.add(o);return t}function Va(e,t,n){let o=ja(n[0]),r=new Map;for(let{sequence:c,is_secondary:l}of n)l||c.forEach((f,u)=>{let d=$(f),h=P(f)!==o.has(d)?c[u+1]:c[u-1];!t.nodeMap.has(d)&&h!==void 0&&r.set(d,$(h))});let s=new Map(e.nodes.map(c=>[c.id,Math.max(1,c.length)])),i=new Map([...r].map(([c,l])=>[l,c])),a=new Map;for(let c of i.keys()){let l=t.nodeMap.get(c);if(l!==void 0){let f=[c];for(let d=i.get(c);d!==void 0;d=i.get(d))f.push(d);f.reduce((d,p)=>d+(s.get(p)??0),0)===t.nodes[l].sequenceLength&&a.set(c,f)}}return{members:a,flipped:o}}var Ka={start:"end",end:"start"},xr={"+":"-","-":"+"};function za(e,{members:t,flipped:n}){if(t.size===0)return e;let o=new Map(e.nodes.map(d=>[d.id,d])),r=new Map,s=new Set,i=(d,p)=>n.has(d)?Ka[p]:p;for(let[d,p]of t)p.forEach((h,m)=>{r.set(h,d);let b=p[m+1];b!==void 0&&s.add(`${h}:${i(h,"end")} ${b}:${i(b,"start")}`)});let a=new Set([...r].filter(([d,p])=>d!==p).map(([d])=>d)),c=e.nodes.flatMap(d=>{let p=t.get(d.id);if(!p)return a.has(d.id)?[]:[d];let h=p.map(b=>o.get(b)),m=h.flatMap(b=>b.stable?[b.stable.start]:[]);return[{...d,length:h.reduce((b,g)=>b+g.length,0),stable:d.stable&&{...d.stable,start:Math.min(...m)}}]}),l=(d,p,h)=>i(p,i(d,h))==="end"?Ke(p):xr[Ke(p)],f=e.edges.flatMap(d=>{let p=mn(d),h=`${d.from}:${p.from}`,m=`${d.to}:${p.to}`;if(s.has(`${h} ${m}`)||s.has(`${m} ${h}`))return[];let b=r.get(d.from),g=r.get(d.to);return[{...d,...b===void 0?{}:{from:b,fromStrand:l(d.from,b,p.from)},...g===void 0?{}:{to:g,toStrand:xr[l(d.to,g,p.to)]}}]}),u=new Set([...a].map(d=>o.get(d)?.name??d));return{...e,nodes:c,edges:f,paths:e.paths?.map(d=>({...d,nodeIds:d.nodeIds.filter(p=>!a.has(p))})),pathVisits:e.pathVisits?.filter(()=>!0,d=>!u.has(d))}}function wr(e){let t=e.paths??[],n=qa(e),o=e.reads?xo(e,e.reads,t.length):[],r=o.length>0?Mn:wn,s=t.map((f,u)=>r(u,t.length)),i=t.some(f=>f.members),a=t.reduce((f,u)=>f+(u.members?.length??1),0),c=ir(Ga(e),n,o,{nodeWidthOption:"compressed",trackWidth:Ua(i?a:n.length),...i?{freqWidth:"linear"}:{}});if(!c)return;let l=Va(e,c,[...n,...o]);return{layout:c,pathColors:s,members:l.members,graph:za(e,l)}}function Bt(e){let t=[];return e.nodes.forEach(n=>{n.order>=0&&t.push(n)}),t}function Mr(e,t,n,o){let r=e.y+e.contentHeight/2-t;return[{x:n,y:r},{x:o,y:r}]}function vr(e,t){return{minY:e.bounds.minY-t,maxY:e.bounds.maxY-t}}function Wp(e){let t=yr(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=n.bounds.minY,s={};for(let c of Bt(n))s[c.name]=Mr(c,r,c.x,c.x+c.pixelWidth);let{minY:i,maxY:a}=vr(n,r);return{nodePositions:s,tubeMap:{layout:n,yOffset:r,...o},extent:{minX:n.bounds.minX,maxX:n.bounds.maxX,minY:i,maxY:a}}}function Za(e,t){let n=new Map(e.nodes.map(a=>[a.id,a])),o=Zt(Bt(t),a=>a.order),r=[],s=-1/0;for(let a of[...o.keys()].sort((c,l)=>c-l)){let c=o.get(a),l=1/0,f=-1/0;for(let u of c){let d=n.get(u.name);d&&O(d)&&(l=Math.min(l,d.stable.start),f=Math.max(f,d.stable.start+d.length))}l===1/0&&(l=f=s),l<s&&(l=s,f=Math.max(s,f)),s=Math.max(s,f),r.push({order:a,x0:Math.min(...c.map(u=>u.x)),x1:Math.max(...c.map(u=>u.x+u.pixelWidth)),bp0:l,bp1:f})}let i=r.find(a=>a.bp0!==-1/0);for(let a of r)a.bp0===-1/0&&(a.bp0=a.bp1=i?.bp0??0);return r}function Ja(e){return yr(e)&&e.nodes.some(O)}function Hp(e){let t=Ja(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=Za(o.graph,n),s=new Map(r.map(c=>[c.order,c])),i=n.bounds.minY,a={};for(let c of Bt(n)){let l=s.get(c.order);a[c.name]=Mr(c,i,l.bp0,l.bp1)}return{nodePositions:a,tubeMap:{layout:n,yOffset:i,columns:r,...o},referenceAxis:!0,pixelRows:!0,extent:vr(n,i)}}function Qa(e,t){let n=[],o=()=>({a:-1/0,b:1/0,detour:[],bp:0}),r=[o()];for(let{node:s,strand:i}of t){let a=r.at(-1),c=n.at(-1);if(O(s)){let l=s.stable.start,f=l+s.length,u=i!==(s.stable.strand??"+"),d=c!==void 0&&a.detour.length===0;d&&!c.inverted&&!u&&c.end===l?c.end=f:d&&c.inverted&&u&&c.start===f?c.start=l:(n.push({start:l,end:f,inverted:u}),r.push(o()))}else a.detour.push({node:s,strand:i}),a.bp+=s.length}return n.forEach((s,i)=>{r[i].b=s.start,r[i+1].a=s.end}),{path:e,runs:n,gaps:r}}function Xt(e,t){return Number.isFinite(e.a)&&Number.isFinite(e.b)&&e.b>=e.a&&Math.max(e.b-e.a,e.bp)<t}function Er(e,t,n){let o=V(e.length,r=>e[r]<=t);return o<e.length&&e[o]<n}function ec(e){let t=new Map;for(let n=1;n<e.length;n++){let o=e[n-1],r=e[n],s=o.stable.start+o.length;s!==r.stable.start&&(t.set(s,"reference-gap"),t.set(r.stable.start,"reference-gap"))}return t}function tc(e,t,n){let o=(s,i)=>{Number.isFinite(s)&&!n.has(s)&&n.set(s,i)};for(let{runs:s,gaps:i}of e){let a=s[0],c=s.at(-1);a&&c&&(o(a.start,"walk-end"),o(c.end,"walk-end"));for(let l of s)l.inverted&&l.end-l.start>=t&&(o(l.start,"inversion"),o(l.end,"inversion"));for(let l of i)l.b<l.a?(o(l.a,"backward"),o(l.b,"backward")):Xt(l,t)||(o(l.a,"variant"),o(l.b,"variant"))}let r=e.flatMap(({runs:s,gaps:i})=>[...i.filter(a=>Xt(a,t)).map(a=>[a.a,a.b]),...s.filter(a=>a.inverted&&a.end-a.start<t).map(a=>[a.start,a.end])]);for(let s=!0;s;){s=!1;let i=[...n.keys()].sort((a,c)=>a-c);for(let[a,c]of r)Er(i,a,c)&&(s||=!n.has(a)||!n.has(c),o(a,"overlap"),o(c,"overlap"))}return n}function nc(e,t){let n=[],o=[],r=()=>{let s=o[0],i=o.at(-1);if(s&&i){let a=s.stable.start,c=i.stable.start+i.length,l=`${a}-${c}`;n.push({node:{id:`${l}+`,name:l,length:c-a,depth:0,stable:{refName:s.stable.refName,start:a,rank:0,strand:"+"}},members:o})}o=[]};for(let s of e)t.has(s.stable.start)&&r(),o.push(s);return r(),n}function Dt(e,t,n){return Math.max(0,V(e.length,o=>t(e[o])<=n)-1)}function Jp(e,t){let n=e.nodes.filter(O).sort((y,w)=>y.stable.start-w.stable.start),o=e.paths??[];if(n.length===0||o.length===0)return;let r=It(e),s=o.map((y,w)=>Qa(y,r[w])),i=tc(s,t,ec(n)),a=[...i.keys()].sort((y,w)=>y-w),c=nc(n,i),l=y=>Dt(c,w=>w.node.stable.start,y),f=new Map,u=new Map;for(let y of c){f.set(y.node.id,y.members.map(w=>w.id));for(let w of y.members)u.set(w.id,y.node.id)}let d=new Map,p=y=>{let w=`${y.a} ${y.b} ${y.detour.map(S=>S.node.id+S.strand).join(",")}`,v=d.get(w);if(!v){let S=`r${d.size}`;v={id:`${S}+`,name:S,length:y.bp,depth:0,stable:{refName:n[0].stable.refName,start:Number.isFinite(y.a)?y.a:y.b,rank:1,strand:"+"}},d.set(w,v),f.set(v.id,y.detour.map(T=>T.node.id));for(let T of y.detour)u.has(T.node.id)||u.set(T.node.id,v.id)}return v},h=new Map,m=[],b=new nn,g=new Map,x=new Map;for(let{path:y,runs:w,gaps:v}of s){let S=[],T=[],R=!1,B=(k,X)=>{let C=S.at(-1);R&&C?.node===k&&C.strand===X||S.push({node:k,strand:X}),R=!0},q=k=>{R=!1,k.detour.length>0&&(B(p(k),"+"),R=!1)},ye=k=>{(k.bp>0||k.b>k.a)&&T.push({start:k.a,end:k.b,bp:k.bp});let X=c[l(k.b>k.a?k.a:k.a-1)];for(let C of k.detour)u.has(C.node.id)||(u.set(C.node.id,X.node.id),f.get(X.node.id).push(C.node.id))};w.forEach((k,X)=>{let C=v[X];Xt(C,t)&&!Er(a,C.a,C.b)?ye(C):q(C);let G=l(k.start),ce=l(k.end-1),Me=k.end-k.start<t;if(k.inverted&&!Me){R=!1;for(let j=ce;j>=G;j--)B(c[j].node,"-");R=!1}else{k.inverted&&T.push({start:k.start,end:k.end,bp:k.end-k.start,inverted:!0});for(let j=G;j<=ce;j++)B(c[j].node,"+")}}),q(v.at(-1));let ae=L(y.name).name,we=0;S.forEach(({node:k,strand:X},C)=>{x.set(k.id,(x.get(k.id)??0)+1),b.add(k.name,ae,y.sample??ae,we,X==="-"),we+=k.length;let G=S[C+1];if(G){let ce=`${k.id}${X} ${G.node.id}${G.strand}`,Me=g.get(ce);Me?Me.pathIds.push(y.name):g.set(ce,{from:k.id,to:G.node.id,fromStrand:X,toStrand:G.strand,pathIds:[y.name]})}}),m.push({...y,nodeIds:S.map(k=>k.node.id)}),h.set(y.name,T)}let M=[...c.map(y=>y.node),...d.values()].filter(y=>x.has(y.id)).map(y=>({...y,depth:x.get(y.id)}));return{graph:{...e,nodes:M,edges:[...g.values()],paths:m,pathVisits:b.build(),reads:void 0},members:f,coarseOf:u,deviations:h,cuts:i}}function th(e,t){return t?e.filter(n=>t.includes(n.sample)).sort((n,o)=>t.indexOf(n.sample)-t.indexOf(o.sample)||n.label.localeCompare(o.label)):e}function nh(e,t,n,o={}){let r=rn(e,t,o);return r&&sn(r,n)}function oc(e,t,n){let o=Dt(e,r=>r.bp0,t);return[e[o],e[o-1]].find(r=>r&&n.has(r.index)&&r.bp0<=t&&t<=r.bp1)}function rc(e,t){let n=new Map;for(let[r,s]of t)for(let i of s)ee(n,L(r).name,i);let o=new Map;for(let r of e.paths??[])if(r.members){let s=new Map;for(let i of r.members.flatMap(a=>n.get(a)??[]))s.set(`${i.start}-${i.end}`,i);o.set(r.name,[...s.values()])}else o.set(r.name,t.get(r.name)??[]);return o}function Th(e,t){let{graph:n,layout:o}=e,r=[...St(e).values()].flat().sort((a,c)=>a.bp0-c.bp0),s=rc(n,t),i=[];for(let a of o.tracks){let c=a.name?s.get(a.name):void 0;if(c?.length){let l=new Map;for(let f of a.path)f.node!==null&&f.y!==void 0&&!l.has(f.node)&&l.set(f.node,f.y);for(let f of c){let u=oc(r,f.start,l);u&&i.push({x0:be(u,f.start),x1:be(u,f.end),y:l.get(u.index),height:a.width})}}}return i}function sc(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function _h(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=sc(s),e.beginPath();for(let i of t){let a=n(i.x0),c=Math.max(n(i.x1),a+1);if(c>=0&&a<=r){let l=o(i.y);e.rect(a,l,c-a,o(i.y+i.height)-l)}}e.fill()}}function ic(e,t){let n=[],o=e.sequenceNew??[],r=e.path.filter(s=>s.node!==null);return o.forEach((s,i)=>{let a=t.nodeMap.get($(s.nodeName)),c=a===void 0?void 0:t.nodes[a],l=r[i];if(c&&l?.y!==void 0){let f={readId:e.id,y:l.y,height:e.width},u=d=>fr(c,d);for(let d of s.mismatches){let p=l.isForward?d:Nt(d,c.sequenceLength),h=u(p.pos);if(h!==null){if(p.type==="insertion")n.push({...f,kind:"insertion",x:h,seq:p.seq});else if(p.type==="deletion"&&p.length!==void 0){let m=u(p.pos+p.length);m!==null&&n.push({...f,kind:"deletion",x0:h,x1:m,length:p.length})}else if(p.type==="substitution"&&p.seq!==void 0){let m=u(p.pos+p.seq.length);m!==null&&n.push({...f,kind:"substitution",x0:h,x1:m,seq:p.seq})}}}}}),n}function Sr(e){return e.reads.flatMap(t=>ic(t,e))}var Ft=24,ac=.5,cc=e=>e.bp1>e.bp0;function $h(e,t){let n=e.filter(cc);if(n.length===0){let l=e[0];return l?[{tx:l.x0,sx:t(l.bp0)}]:[]}let o=[],r=[],s=[];n.forEach((l,f)=>{o.push(l.x0,l.x1),r.push(t(l.bp0),t(l.bp1)),s.push(f===0?0:Math.min(l.x0-n[f-1].x1,Ft),0)});let i=r.at(-1)-r[0],a=s.reduce((l,f)=>l+f,0),c=a>0?Math.min(1,ac*i/a):1;return lc(r,s,c).map((l,f)=>({tx:o[f],sx:l}))}function lc(e,t,n){let o=[],r=0;for(let i of t)r+=i*n,o.push(r);let s=[];return e.forEach((i,a)=>{let c={mean:i-o[a],n:1},l=s.at(-1);for(;l&&l.mean>=c.mean;){s.pop();let f=l.n+c.n;c={mean:(l.mean*l.n+c.mean*c.n)/f,n:f},l=s.at(-1)}s.push(c)}),s.flatMap(i=>Array(i.n).fill(i.mean)).map((i,a)=>i+o[a])}function Ch(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=1+V(n-2,l=>e[l+1].tx<=t),i=e[s-1],a=e[s],c=a.tx-i.tx;return c>0?i.sx+(t-i.tx)/c*(a.sx-i.sx):i.sx}function Yt(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 _r(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 kr(e,t,n,o,r){let s=Yt(e);return{commands:s,outline:gr(e,12),color:t,id:n,haplotype:o,reference:r,..._r(s)}}function Or(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?yo(n):t[n.id]]))}function Rr(e,t,n,o,r){let{shapes:s}=e,i=t==="haplotype",a=d=>n.get(d.id),c=d=>i&&o.has(d.id),l=[...s.rectangles,...s.verticalRectangles].filter(d=>d.type===t).map(d=>({color:a(d),id:d.id,haplotype:i,reference:c(d),x0:d.xStart,x1:d.xEnd+1,y0:d.yStart,y1:d.yEnd+1})),f=mr(s.curves,t,{gapWidth:r}).map(d=>kr(d.path,a(d),d.id,i,c(d))),u=s.corners.filter(d=>d.type===t).map(d=>kr(d.path,a(d),d.id,i,c(d)));return{rects:l,shapes:[...f,...u]}}function dc(e){let t=new Set,n=e&&ve(e);return e?.paths?.forEach((o,r)=>{L(o.name).name===n&&t.add(r)}),t}function fc({layout:e,pathColors:t,graph:n,columns:o}){let r=Or(e,t),s=dc(n),i=o?Ft:void 0,a=[];return e.nodes.forEach(c=>{if(c.order>=0){let l=Yt(br(c));a.push({name:c.name,commands:l,..._r(l)})}}),{bounds:e.bounds,layers:[Rr(e,"haplotype",r,s,i),Rr(e,"read",r,s,i)],nodes:a,mismatches:Sr(e)}}function qt(e,t,n,o){let r=0,s=0;for(let i of t)switch(i.op){case"M":r=i.x,s=i.y,e.moveTo(n(r),o(s));break;case"L":r=i.x,s=i.y,e.lineTo(n(r),o(s));break;case"H":r=i.x,e.lineTo(n(r),o(s));break;case"V":s=i.y,e.lineTo(n(r),o(s));break;case"Q":r=i.x,s=i.y,e.quadraticCurveTo(n(i.x1),o(i.y1),n(r),o(s));break;case"C":r=i.x,s=i.y,e.bezierCurveTo(n(i.x1),o(i.y1),n(i.x2),o(i.y2),n(r),o(s));break;case"Z":e.closePath();break}}function Tr(e,t,n,o,r){let s=new Map;for(let i of t)n(i)&&ee(s,o(i),i);for(let i of s.values()){e.fillStyle=o(i[0]),e.beginPath();for(let a of i)r(a);e.fill()}}var uc=12,pc=.15;function hc(e){return Math.max(pc,Math.min(1,e/uc))}var mc=.55;function gc(e,t,n){let{x:o,y:r,width:s}=n,i=f=>o(f.x1)>=0&&o(f.x0)<=s,a=f=>f.haplotype&&n.tubeColors?.[f.id]||f.color;e.globalAlpha=1;for(let f of t.layers)for(let u of[!1,!0]){let d=p=>p.reference===u;Tr(e,f.rects,p=>d(p)&&i(p),a,p=>{let h=o(p.x0),m=r(p.y0);e.rect(h,m,o(p.x1)-h,r(p.y1)-m)}),Tr(e,f.shapes,p=>d(p)&&i(p),a,p=>{qt(e,p.commands,o,r)})}let c=n.darkMode?"#d0d0d0":"#000000",l=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=Ar(n);for(let f of t.nodes)if(i(f)&&f.name!==n.highlightNode){e.beginPath(),qt(e,f.commands,o,r);let u=n.nodeColors?.get(f.name);e.fillStyle=u??l,e.strokeStyle=c,e.globalAlpha=u?mc:1,e.fill(),e.globalAlpha=hc(o(f.x1)-o(f.x0)),e.stroke(),e.globalAlpha=1}Xe(e,t,n),xc(e,t.mismatches,n)}function Ar(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function Xe(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),qt(e,o.commands,n.x,n.y),e.globalAlpha=1,e.lineWidth=Ar(n),e.fillStyle="rgba(255,192,203,0.5)",e.strokeStyle="#ff0000",e.fill(),e.stroke())}var Nr=12,bc=6;function Wt(e){return Nr*e>=bc}function Gt(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 xc(e,t,n){let{x:o,y:r,yScale:s,darkMode:i}=n;if(!Wt(s)||t.length===0)return;let a=Nr*s;e.fillStyle="grey",e.beginPath();for(let c of t)if(c.kind==="deletion"&&Gt(c,n)){let l=o(c.x0),f=r(c.y);e.rect(l,f,o(c.x1)-l,r(c.y+c.height)-f)}e.fill(),e.font=`${a}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=i?"#ffffff":"#000000";for(let c of t)Gt(c,n)&&(c.kind==="substitution"?e.fillText(c.seq,o(c.x0)+1,r(c.y+c.height)):c.kind==="insertion"&&e.fillText("*",o(c.x)-3,r(c.y+c.height)))}function yc(e,t,n){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[c,l]=e[s];a>n!=l>n&&t<(c-i)*(n-a)/(l-a)+i&&(o=!o)}return o}function wc(e,{x:t,y:n},o,r){for(let s=e.layers.length-1;s>=0;s--){let{rects:i,shapes:a}=e.layers[s];for(let c of[!0,!1]){for(let l of i)if(l.reference===c&&t(l.x0)<=o&&o<=t(l.x1)&&n(l.y0)<=r&&r<=n(l.y1))return l.id;for(let l of a)if(l.reference===c&&t(l.x0)<=o&&o<=t(l.x1)&&yc(l.outline.map(([f,u])=>[t(f),n(u)]),o,r))return l.id}}}var Mc=4;function vc(e,t,n,o){let{x:r,y:s,yScale:i}=t;return Wt(i)?e.mismatches.find(a=>s(a.y)<=o&&o<=s(a.y+a.height)&&(a.kind==="insertion"?Math.abs(r(a.x)-n)<=Mc:r(a.x0)<=n&&n<=r(a.x1))):void 0}var Q=JBrowseExports["@jbrowse/core/util/groupKeys"],Ec=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 De=Ec("groupKeyComparator");var Nm=Q&&Q.__esModule?Q.default:Q;var Fe=16;function Lm(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[i="",...a]=s.split(" ");i&&!r.has(i)&&r.set(i,{...Object.fromEntries(o.map((c,l)=>[c,a[l]??""])),name:i})}return[...r.values()]}function Im(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 Bm(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 Ht(e,t){return`${e} ${t}${e===1?"":"s"}`}function Ut(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return(o,r)=>n.get(o)||n.get(r)||""}function jt(e,t,{field:n,domain:o},r,s){let i=new Map;for(let a of e){let c=t(a),l=i.get(c);l?l.push(a):i.set(c,[a])}return[...i.keys()].sort(De(o)).map(a=>{let c=i.get(a),l=new Set(c.map(s)).size;return{key:a,members:c,title:`${a||`${n}: none`} \xB7 ${Ht(l,r)}`}})}function Xm(e,t,n){let o=Ut(n.field,t),r=jt(e,a=>o(a.label,a.sample),n,"haplotype",a=>a.label),s=1,i=r.map(({key:a,members:c,title:l})=>{let f={key:a,title:l,first:s,count:c.length};return s+=c.length,f});return{rows:r.flatMap(a=>a.members),sections:i}}function Dm(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)*Fe;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*Fe})),headersPx:e.length*Fe,rowAt(r,s){let i=0;for(let a=-1;a<e.length;a++){let c=a<0?0:e[a].first,l=a<0?Math.min(s,e[0]?.first??s):c+e[a].count,f=(a+1)*Fe,u=Math.min(l-1,Math.max(c,Math.round((r-f)/t)));Math.abs(o(u)-r)<Math.abs(o(i)-r)&&(i=u)}return i}}}function Fm(e,t,n,o,r){return t.length===0?[ge(e,o,r)]:[ge({...e,rows:[]},o,r),...t.flatMap((s,i)=>ge({...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${i}`}).children.filter(c=>typeof c!="string"&&c.attrs["data-testid"]!=="graph-walk-reference"))]}function Sc(e,t,n,o){let r=[],s=[],i=[e];for(o.add(e);i.length>0;){let a=i.pop(),c=t.get(a);if(c){r.push(c);for(let l of n.get(a)??[]){let f=t.get(l);f&&(f.stable.rank===Ge?s.push(f):o.has(l)||(o.add(l),i.push(l)))}}}return{members:r,anchors:s}}function kc(e){if(new Set(e.map(a=>a.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((a,c)=>a.stable.start-c.stable.start),o=n[0],r=n.at(-1),s=o.stable.start+o.length,i=r.stable.start;return i>=s?{start:s,end:i,entry:o}:void 0}function Rc(e,t,n){let o=new Map(e.map(i=>[i.id,i])),r=new Map,s=[];for(let i of n.get(t.id)??[])o.has(i)&&(r.set(i,0),s.push(i));if(s.length===0)for(let i of e)r.set(i.id,0),s.push(i.id);for(let i of s){let a=r.get(i)+o.get(i).length;for(let c of n.get(i)??[])if(o.has(c)){let l=r.get(c);(l===void 0||a<l)&&(r.set(c,a),s.push(c))}}return r}function Tc(e,t,n){let o=Rc(e,t,n),r=[...e].sort((c,l)=>o.get(c.id)-o.get(l.id)),s=new Map(r.map((c,l)=>[c.id,l])),i=new Map(e.map(c=>[c.id,c])),a=new Map;for(let[c,l]of r.entries()){let f=0;for(let u of n.get(l.id)??[]){let d=i.get(u);d&&s.get(u)<c&&(f=Math.max(f,a.get(u)+d.length))}a.set(l.id,f)}return{offsets:a,ordered:r}}function _c(e){let t=new Map(e.nodes.filter(Jt).map(s=>[s.id,s])),n=Re(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==Ge&&!o.has(s.id)){let{members:i,anchors:a}=Sc(s.id,t,n,o),c=kc(a);if(c){let{offsets:l,ordered:f}=Tc(i,c.entry,n);r.push({start:c.start,refSpan:c.end-c.start,nodeIds:f.map(u=>u.id),nodeOffsets:f.map(u=>l.get(u.id)),pathLength:f.reduce((u,d)=>Math.max(u,l.get(d.id)+d.length),0)})}}return r.sort((s,i)=>s.start-i.start)}var Oc=28,Pr="#4d4d4d",Ac="#5b8cc4",Nc=[Ac,"#82abd9"],hg=["#8c8c8c","#adadad"],Pc="12px sans-serif",mg=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],D=e=>L(e).name;function gg(e,t,n=Nc){let o=0;return e.map(r=>D(r.name)===t?Pr:n[o++%n.length])}var $c=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#76b7b2","#edc948","#9c755f","#ff9da7","#bab0ac"],$r="#c8c8c8";function bg(e){let t=[...new Set(e)].filter(n=>n!=="").sort(De());return new Map(t.map((n,o)=>[n,$c[o]??$r]))}function xg(e,t,n,o){return e.map(r=>{let s=D(r.name);return s===t?Pr:o.get(n(r.members?.[0]??s))??$r})}function Cc(e,t){let n=Ut(e,t);return o=>{let{sample:r,haplotype:s}=le(o);return n(`${r}#${s}`,r)}}function yg(e,t){let n=(e.paths??[]).map(c=>c.name).filter(c=>D(c)!==e.referencePath);if(t.by==="column"){let c=Cc(t.field,t.table);return jt(n,l=>c(D(l)),t,"sample",l=>le(D(l)).sample).map(({key:l,members:f,title:u})=>({key:l,paths:f,label:u}))}let o=t.by==="sample"?c=>le(c).sample:c=>c,r=new Map;for(let c of n){let l=o(D(c)),f=r.get(l);f?f.push(c):r.set(l,[c])}let s=t.domain??[],i=new Map(s.map((c,l)=>[c,l])),a=c=>i.get(c)??s.length;return[...r].map(([c,l],f)=>({key:c,paths:l,i:f})).sort((c,l)=>a(c.key)-a(l.key)||c.i-l.i).map(({key:c,paths:l})=>({key:c,paths:l}))}function wg(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 Mg(e,t,n,o,r){let s=e.flatMap(u=>{let d=t(u);return d?[{id:u,...d}]:[]});if(s.length===0)return;let i=Math.min(...s.map(u=>u.start)),a=Math.max(...s.map(u=>u.end)),c=o>n?(r-n)/(o-n):0,l=i+Math.min(1,Math.max(0,c))*(a-i),f=u=>l<u.start?u.start-l:l>=u.end?l-u.end+1:0;return s.reduce((u,d)=>f(d)<f(u)?d:u).id}function vg(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=D(r.name);if(s!==e.referencePath)for(let i of r.members??[s])n.add(i),r.nodeIds.includes(t)&&o.add(i)}return{here:o.size,of:n.size}}var Lc="bold 11px sans-serif",Ic=80,Bc=9;function Eg(e,t,n,{x:o,y:r,width:s}){let i=n.paths??[];if(!i.some(c=>c.members))return;let a=new Map;i.forEach((c,l)=>{D(c.name)!==n.referencePath&&a.set(l,c.members?.length??1)}),e.font=Lc,e.textAlign="left",e.textBaseline="middle",e.fillStyle="#0b1f3a";for(let c of t.layers[0]?.rects??[]){let l=a.get(c.id),f=Math.max(0,o(c.x0)),u=Math.min(s,o(c.x1)),d=r(c.y0),p=r(c.y1);l!==void 0&&u-f>=Ic&&p-d>=Bc&&e.fillText(`\xD7${l}`,f+4,(d+p)/2)}}var Xc="10px sans-serif",Dc=1e3;function Sg(e,t,{x:n,y:o,width:r}){if(!t.columns)return;let s=new Map(t.graph.nodes.map(c=>[c.id,c.length]));e.font=Xc;let i=new Map;t.layout.nodes.forEach(c=>{let l=s.get(c.name)??0,f=n(c.x),u=n(c.x+c.pixelWidth),d=A(l);if(c.order>=0&&l>=Dc&&u-f<e.measureText(d).width){let p=(o(c.y)+o(c.y+c.contentHeight))/2,h=`${Math.round(u)}:${d}`,m=i.get(h);m?(m.count++,m.mid=Math.max(m.mid,p)):i.set(h,{text:d,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 a=[];for(let{text:c,right:l,mid:f,count:u}of i.values()){let d=u>1?`${c} each`:c,p={x0:l+3,x1:l+3+e.measureText(d).width,y0:f-6,y1:f+6};p.x1<=r&&!a.some(h=>h.x0<p.x1&&p.x0<h.x1&&h.y0<p.y1&&p.y0<h.y1)&&(a.push(p),e.strokeText(d,p.x0,f),e.fillText(d,p.x0,f))}}function kg(e,t,n,{width:o,lit:r}){t.forEach((s,i)=>{let a=n?.[i];a&&(r&&Xe(e,s.picture,{...s.frame,width:o,highlightNode:a.box}),e.font=Pc,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${a.here} of ${Ht(a.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4))})}function Rg(e,t){let n=new Set(t),o=(e.paths??[]).filter(l=>n.has(l.name)||D(l.name)===e.referencePath),r=new Set(o.map(l=>D(l.name))),s=new Set(o.flatMap(l=>l.nodeIds)),i=e.nodes.filter(l=>s.has(l.id)),a=new Set(i.map(l=>l.name)),c=e.pathVisits?.filter(l=>r.has(l),l=>a.has(l));return{...e,nodes:i,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:c,reads:void 0}}function Tg(e,t){let n=[],o={},r=0,s=1/0,i=-1/0;for(let{key:a,paths:c,label:l,result:f}of t){let u=f?.tubeMap,d=f?.extent;if(u&&d){let p=r+Oc,h=(d.maxY??0)-(d.minY??0);n.push({key:a,paths:c,label:l,result:{...f,tubeMap:u},top:p,height:h});let m=p-(d.minY??0);for(let[b,g]of Object.entries(f.nodePositions))o[b]=g.map(x=>({x:x.x,y:x.y+m}));r=p+h,s=Math.min(s,d.minX??s),i=Math.max(i,d.maxX??i)}}return n.length>1?{...e,nodePositions:o,extent:{...s<=i?{minX:s,maxX:i}:{},minY:0,maxY:r},tubeMapPanels:n}:e}var Fc="#daa520",qc=1,Gc=2,Yc=4;function Ag(e,t,n,o=r=>r){let r=s=>{let i=t(s)*2;return n?.nodeIds.has(s)?Math.max(i,n.walks.length*Yc):i};return e.flatMap(s=>s.exonsByNode.map(({nodeId:i,d:a})=>({key:`${s.gene.name}-${s.gene.start}-${i}`,d:o(a),inner:r(i)+2*qc})))}function Ng(e,t){if(e.length===0)return;let n=(o,r,s)=>_("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 _("g",{},_("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},_("g",{transform:t.transform},...e.map(o=>n(o,"#fff",o.inner+2*Gc)),...e.map(o=>n(o,"#000",o.inner)))),_("rect",{width:t.width,height:t.height,fill:Fc,mask:`url(#${t.id})`}))}function Vt(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${ne(o)}-${ne(r)} (${A(r-o)})`}function Wc(e,t){let{field:n}=e.encoding,o=e.range?Vt(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?Vt(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,i=s-e.bp-e.missingBp-e.unknownBp,a=[[e.missingBp,Y.missing],[e.unknownBp,Y.unknown],[i,te]];return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${A(Math.abs(s-e.referenceBp))}`,gaps:a.filter(([c])=>c>0).map(([c,l])=>`, ${A(c)} ${l}`).join(""),reversed:e.reversedBp>0?`, ${A(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function Hc(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}:${ne(s)}-${ne(s+n)}`}function Uc(e,t){let n=[];for(let o of t){let r=e.get(o.refName),s=r?.[0],i=r?.at(-1);if(!r||!s||!i)continue;let a=Math.max(o.start,s.bp0),c=Math.min(o.end,i.bp1);c<=a||n.push({gene:o,...Le(r,a,c),exons:o.exons.filter(l=>l.end>a&&l.start<c).map(l=>Le(r,Math.max(l.start,a),Math.min(l.end,c)))})}return n}var Kt=22,jc=4,qe=8,Vc="11px sans-serif",Kc=8;function zc(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(jc,o)}function Zc(e,t,n,o,r=0){let{x:s,width:i,darkMode:a}=n,c=Math.max(1,Math.floor((o-r)/Kt)),l=[],f=a?"#e0e0e6":"#1c1c22";e.font=Vc,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=f,e.strokeStyle=f,e.lineWidth=1;let u=t.map(d=>({g:d,s0:s(d.x0),s1:s(d.x1)})).filter(({s0:d,s1:p})=>p>=0&&d<=i).sort((d,p)=>d.s0-p.s0);for(let{g:d,s0:p,s1:h}of u){let m=d.gene.strand>0?" \u2192":d.gene.strand<0?"\u2190 ":"",b=d.gene.strand<0?`${m}${d.gene.name}`:`${d.gene.name}${m}`,g=(Math.max(p,0)+Math.min(h,i))/2,x=e.measureText(b).width/2,M=Math.min(p,g-x),y=Math.max(h,g+x),w=l.findIndex(S=>S+Kc<=M);w===-1&&(w=Math.min(l.length,c-1)),l[w]=Math.max(l[w]??-1/0,y);let v=o-w*Kt-qe/2;e.beginPath(),e.moveTo(p,v+.5),e.lineTo(h,v+.5),e.stroke();for(let S of d.exons){let T=s(S.x0);e.fillRect(T,v-qe/2,Math.max(1,s(S.x1)-T),qe)}e.fillText(b,g,v-qe/2-2)}}var F=12,Xr=F+8,Dr=8,Cr=Dr+3,Jc=12;function Qc(e,{colorScheme:t,referenceRamp:n,walks:o}){let r=tt(e,n),s=[];return e.nodes.forEach((i,a)=>{if(O(i)){let c=o?o.map(l=>{let f=l.colors.get(i.id);return f===void 0?Te:W(f)}):[W(nt(i,a,t,r))];s.push({node:i.id,bp0:i.stable.start,bp1:i.stable.start+i.length,colors:c,faded:c.includes(Te)})}}),s.sort((i,a)=>i.bp0-a.bp0)}function zt(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var Lr=2;function Fr(e,t,n){let o=-t.translateX/t.scale,r=(n-t.translateX)/t.scale,s=Math.min(o,r),i=Math.max(o,r),a=0,c=0;for(let l of e)a+=Math.max(0,Math.min(l.bp1,s)-l.bp0),c+=Math.max(0,l.bp1-Math.max(l.bp0,i));return t.scale>=0?{left:Math.round(a),right:Math.round(c)}:{left:Math.round(c),right:Math.round(a)}}function el(e,t,n,o){if(o<0||o>F+Lr)return;let r,s=Lr;for(let i of e){let[a,c]=zt(t,i.bp0,i.bp1),l=Math.max(0,a-n,n-c);l<=s&&(s=l,r=i.node)}return r}function tl(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function qr(e,t,n,o){let r=e.map(l=>{let[f,u]=zt(t,l.bp0,l.bp1),d=Math.round(f*o);return{colors:l.colors,x0:f,px0:d,px1:Math.max(Math.round(u*o),d+1)}}).filter(l=>l.px1>0&&l.px0<n*o).sort((l,f)=>l.x0-f.x0),s=[],i=-1/0,a=[-1/0,-1/0];for(let{colors:l,px0:f,px1:u}of r){let d=Math.max(f,i);if(u>d){let p=a[0]<d?0:1;a[p]=u,s.push({colors:l,x0:d/o,x1:u/o,tier:p}),i=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Jc?s:s.map(({tier:l,...f})=>f)}function Ir(e,t,n,o){let r=n>0?t:t-Cr;e.clearRect(r,0,Cr,F);let s=t+n,i=s+n*Dr;e.beginPath(),e.moveTo(s,F/2),e.lineTo(i,0),e.lineTo(i,F),e.closePath(),e.fillStyle=o,e.fill()}function Br(e,t,n){return Math.round(e*F*n/t)/n}function nl(e,t,n,{width:o,lit:r,darkMode:s,dpr:i=1}){let a=s?"#ffffff":"#18181c";e.clearRect(0,0,o,Xr);for(let l of qr(t,n,o,i)){let{tier:f}=l,u=f!==void 0&&l.colors.length===1,d=u?2:l.colors.length;l.colors.forEach((p,h)=>{let m=u?f:h,b=Br(m,d,i);e.fillStyle=p,e.fillRect(l.x0,b,l.x1-l.x0,Br(m+1,d,i)-b)})}let c=Fr(t,n,o);if(c.left>0&&Ir(e,0,1,a),c.right>0&&Ir(e,o,-1,a),r){let[l,f]=zt(n,r.start,r.end),u=Math.max(f-l,3),d=(l+f)/2-u/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(d,.75,u,F-1.5),r.anchor&&(e.beginPath(),e.moveTo(d+u/2,F),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function ol(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function rl(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 a=n-1;a>=0;a--)for(let c=o-1;c>=0;c--){let l=Math.abs(e[a]-t[c])+r[a+1][c+1],f=n-a>o-c?r[a+1][c]:1/0,u=o-c>n-a?r[a][c+1]:1/0;r[a][c]=Math.min(l,f,u),s[a][c]=r[a][c]===l}let i=new Array(n).fill(void 0);for(let a=0,c=0;a<n&&c<o;)s[a][c]?i[a++]=c++:n-a>o-c?a++:c++;return i}function Gr(e,t){return e.map((n,o)=>({item:n,i:o})).sort((n,o)=>t(n.item)-t(o.item))}var Yr=e=>e.spanningReads!==0;function sl(e,t){return{...t,agrees:e.complete&&Yr(t)?ol(e.bp,t.bp):void 0}}function il(e,t){let n=new Map,o=new Set,r=Gr(e,i=>i.bp),s=(i,a)=>{let c=[[i.filter(l=>l.item.complete),a.filter(Yr)],[i,a]];for(let[l,f]of c){let u=l.filter(p=>!n.has(p.i)),d=Gr(f.filter(p=>!o.has(p)),p=>p.bp);rl(u.map(p=>p.item.bp),d.map(p=>p.item.bp)).forEach((p,h)=>{if(p!==void 0){let m=u[h],b=d[p].item;o.add(b),n.set(m.i,sl(m.item,b))}})}};for(let i of new Set(t.flatMap(a=>a.haplotype??[])))s(r.filter(a=>a.item.haplotype===i),t.filter(a=>a.haplotype===i));return s(r,t.filter(i=>i.haplotype===void 0)),n}function f0(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 i=t[r];if(i)for(let[a,c]of il(s,i))n.set(s[a],c)}return e.map(r=>({...r,call:n.get(r)}))}var Wr=go.box(typeof devicePixelRatio>"u"?1:devicePixelRatio);function Hr(){matchMedia(`(resolution: ${devicePixelRatio}dppx)`).addEventListener("change",()=>{bo(()=>{Wr.set(devicePixelRatio)}),Hr()},{once:!0})}typeof matchMedia=="function"&&Hr();function b0(e=0,t=0){return Wr.get(),oe(e,t)}export{gu as a,bu as b,xu as c,yu as d,js as e,Vs as f,It as g,yr as h,Wp as i,Ja as j,Hp as k,_c as l,th as m,nh as n,jd as o,Pe as p,_ as q,Ks as r,zs as s,he as t,Mt as u,gt as v,So as w,ko as x,me as y,_o as z,xt as A,ni as B,oi as C,Ao as D,ai as E,Po as F,$o as G,vt as H,ci as I,li as J,Lo as K,ge as L,Ae as M,rt as N,Ne as O,jr as P,Vr as Q,Kr as R,zr as S,Fl as T,K as U,Hn as V,pe as W,it as X,ms as Y,ql as Z,Gl as _,bs as $,xs as aa,ys as ba,ws as ca,Ms as da,rf as ea,sf as fa,af as ga,cf as ha,lf as ia,df as ja,ff as ka,uf as la,pf as ma,hf as na,mf as oa,gf as pa,bf as qa,xf as ra,yf as sa,wf as ta,Mf as ua,vf as va,Es as wa,Ef as xa,Sf as ya,kf as za,Rf as Aa,Tf as Ba,_f as Ca,Of as Da,Af as Ea,mi as Fa,bi as Ga,xi as Ha,yi as Ia,Jp as Ja,St as Ka,wi as La,Xo as Ma,Ti as Na,_i as Oa,Ai as Pa,Ni as Qa,Yo as Ra,Th as Sa,sc as Ta,_h as Ua,$h as Va,Ch as Wa,fc as Xa,gc as Ya,Xe as Za,Wt as _a,Gt as $a,wc as ab,vc as bb,Fe as cb,Lm as db,Im as eb,Bm as fb,Xm as gb,Dm as hb,Fm as ib,Oc as jb,Pr as kb,Ac as lb,hg as mb,Pc as nb,mg as ob,gg as pb,$r as qb,bg as rb,xg as sb,Cc as tb,yg as ub,wg as vb,Mg as wb,vg as xb,Eg as yb,Sg as zb,kg as Ab,Rg as Bb,Tg as Cb,lt as Db,Lf as Eb,Xf as Fb,Fc as Gb,Ag as Hb,Ng as Ib,Vf as Jb,fo as Kb,Kf as Lb,uo as Mb,ft as Nb,po as Ob,ho as Pb,Ws as Qb,Vt as Rb,Wc as Sb,Hc as Tb,Uc as Ub,Kt as Vb,zc as Wb,Zc as Xb,Xr as Yb,Qc as Zb,Fr as _b,el as $b,tl as ac,nl as bc,f0 as cc,b0 as dc};
3
+ //# sourceMappingURL=chunk-PYQG3JHP.js.map