jbrowse-plugin-graphgenomeviewer 7.4.4 → 7.5.0

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 (129) hide show
  1. package/dist/chunks/{GbzBaseSyntenyAdapter-A5MNPCKX.js → GbzBaseSyntenyAdapter-4KVWVUN6.js} +2 -2
  2. package/dist/chunks/{GbzBaseSyntenyAdapter-A5MNPCKX.js.map → GbzBaseSyntenyAdapter-4KVWVUN6.js.map} +1 -1
  3. package/dist/chunks/{GraphGenomeView-SEAPDRXS.js → GraphGenomeView-KI4FQ5A7.js} +2 -2
  4. package/dist/chunks/GraphTrackSettingsDialog-UQNMDXTE.js +4 -0
  5. package/dist/chunks/GraphTrackSettingsDialog-UQNMDXTE.js.map +7 -0
  6. package/dist/chunks/{HighlightColorDialog-QAYWLO5I.js → HighlightColorDialog-D4RCUCUF.js} +2 -2
  7. package/dist/chunks/LinearGraphDisplay-RPZUZSM2.js +2 -0
  8. package/dist/chunks/{LinearGraphDisplay-ZC4BQ27J.js.map → LinearGraphDisplay-RPZUZSM2.js.map} +2 -2
  9. package/dist/chunks/{MinigraphBubbleAdapter-3QM4XV47.js → MinigraphBubbleAdapter-TJYI7KEN.js} +2 -2
  10. package/dist/chunks/RgfaTabixAdapter-5ZMJLFZP.js +2 -0
  11. package/dist/chunks/RgfaTabixAdapter-5ZMJLFZP.js.map +7 -0
  12. package/dist/chunks/{WalkFormsAdapter-FT2SW4H6.js → WalkFormsAdapter-CAJOWOEX.js} +2 -2
  13. package/dist/chunks/WalkTabixSyntenyAdapter-VI3KA2GX.js +2 -0
  14. package/dist/chunks/{WalkTabixSyntenyAdapter-3WRVNDLB.js.map → WalkTabixSyntenyAdapter-VI3KA2GX.js.map} +2 -2
  15. package/dist/chunks/{chunk-6WUWQX2P.js → chunk-22ANI2KL.js} +2 -2
  16. package/dist/chunks/{chunk-6WUWQX2P.js.map → chunk-22ANI2KL.js.map} +1 -1
  17. package/dist/chunks/chunk-42KD4AVY.js +2 -0
  18. package/dist/chunks/{chunk-HCDKP3IP.js.map → chunk-42KD4AVY.js.map} +4 -4
  19. package/dist/chunks/chunk-4NIWMRKH.js +2 -0
  20. package/dist/chunks/{chunk-S333HOG5.js.map → chunk-4NIWMRKH.js.map} +4 -4
  21. package/dist/chunks/chunk-BCOXRUNQ.js +3 -0
  22. package/dist/chunks/chunk-BCOXRUNQ.js.map +7 -0
  23. package/dist/chunks/chunk-DAPI7M4M.js +4 -0
  24. package/dist/chunks/chunk-DAPI7M4M.js.map +7 -0
  25. package/dist/chunks/{chunk-G53BI7VK.js → chunk-DEWZOJSC.js} +2 -2
  26. package/dist/chunks/{chunk-G53BI7VK.js.map → chunk-DEWZOJSC.js.map} +1 -1
  27. package/dist/chunks/{chunk-6SWXMRAV.js → chunk-FCMXEFJA.js} +1 -1
  28. package/dist/chunks/{chunk-6SWXMRAV.js.map → chunk-FCMXEFJA.js.map} +1 -1
  29. package/dist/chunks/{chunk-P3FBI5ML.js → chunk-GYY6LF5L.js} +1 -1
  30. package/dist/chunks/{chunk-P3FBI5ML.js.map → chunk-GYY6LF5L.js.map} +1 -1
  31. package/dist/chunks/{chunk-HF4H6LQI.js → chunk-HHMJNAA3.js} +2 -2
  32. package/dist/chunks/{chunk-XXBE4IFZ.js → chunk-HTTONSO4.js} +2 -2
  33. package/dist/chunks/{chunk-XXBE4IFZ.js.map → chunk-HTTONSO4.js.map} +1 -1
  34. package/dist/chunks/{chunk-MUONTMYZ.js → chunk-K4JL57NR.js} +2 -2
  35. package/dist/chunks/chunk-KOC23YNN.js +4 -0
  36. package/dist/chunks/chunk-KOC23YNN.js.map +7 -0
  37. package/dist/chunks/{chunk-OJWBLPPH.js → chunk-LTNFVL2F.js} +2 -2
  38. package/dist/chunks/chunk-OZEKEYT3.js +2 -0
  39. package/dist/chunks/{chunk-6VNU7SD4.js.map → chunk-OZEKEYT3.js.map} +4 -4
  40. package/dist/chunks/{chunk-KIYRMZWP.js → chunk-POUV7OPY.js} +2 -2
  41. package/dist/chunks/{chunk-KIYRMZWP.js.map → chunk-POUV7OPY.js.map} +1 -1
  42. package/dist/chunks/{chunk-LE7FZM6Y.js → chunk-SPL3UO2D.js} +2 -2
  43. package/dist/chunks/{chunk-LE7FZM6Y.js.map → chunk-SPL3UO2D.js.map} +1 -1
  44. package/dist/chunks/chunk-UR2MJJUP.js +2 -0
  45. package/dist/chunks/chunk-VTMJQFN5.js +2 -0
  46. package/dist/chunks/chunk-VTMJQFN5.js.map +7 -0
  47. package/dist/chunks/{chunk-2KVE7YAS.js → chunk-XZGYJ3JC.js} +1 -1
  48. package/dist/chunks/{chunk-2KVE7YAS.js.map → chunk-XZGYJ3JC.js.map} +1 -1
  49. package/dist/chunks/{chunk-7RJMG6I2.js → chunk-Z3IKZAYC.js} +1 -1
  50. package/dist/chunks/{chunk-7RJMG6I2.js.map → chunk-Z3IKZAYC.js.map} +1 -1
  51. package/dist/chunks/{chunk-FTXDTU27.js → chunk-ZV5FNOHS.js} +3 -3
  52. package/dist/chunks/{chunk-FTXDTU27.js.map → chunk-ZV5FNOHS.js.map} +2 -2
  53. package/dist/chunks/{renderSvg-ZIUOPWJQ.js → renderSvg-3PPAEMBT.js} +2 -2
  54. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +4 -3
  55. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  56. package/package.json +2 -2
  57. package/src/GraphComputeLayout.test.ts +24 -0
  58. package/src/GraphComputeLayout.ts +4 -2
  59. package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +16 -0
  60. package/src/GraphGenomeView/components/WalkRowsOverlay.tsx +83 -0
  61. package/src/GraphGenomeView/components/usePaneGestures.test.tsx +82 -5
  62. package/src/GraphGenomeView/components/usePaneGestures.ts +10 -4
  63. package/src/GraphGenomeView/graphLayers.ts +14 -1
  64. package/src/GraphGenomeView/legendSections.ts +32 -0
  65. package/src/GraphGenomeView/model.test.ts +292 -4
  66. package/src/GraphGenomeView/model.ts +3 -10
  67. package/src/GraphGenomeView/nodeSize.test.ts +21 -5
  68. package/src/GraphGenomeView/nodeSize.ts +24 -8
  69. package/src/GraphGenomeView/pane/fitViews.ts +5 -1
  70. package/src/GraphGenomeView/pane/graphViews.ts +96 -16
  71. package/src/GraphGenomeView/pane/launchActions.ts +55 -11
  72. package/src/GraphGenomeView/pane/launchViews.ts +46 -0
  73. package/src/GraphGenomeView/pane/loadActions.ts +85 -25
  74. package/src/GraphGenomeView/pane/morph.test.ts +25 -1
  75. package/src/GraphGenomeView/pane/morph.ts +3 -1
  76. package/src/GraphGenomeView/pane/paneBase.ts +5 -0
  77. package/src/GraphGenomeView/pane/renderingActions.ts +61 -2
  78. package/src/GraphGenomeView/pane/settingActions.ts +62 -4
  79. package/src/GraphGenomeView/pane/walkRowViews.ts +17 -6
  80. package/src/GraphGenomeView/tubeMapPanels.ts +2 -1
  81. package/src/GraphGenomeView/viewModel.ts +4 -6
  82. package/src/GraphGenomeView/walkRowBlocks.ts +50 -0
  83. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +35 -5
  84. package/src/LinearGraphDisplay/components/GraphStatusChrome.test.tsx +18 -0
  85. package/src/LinearGraphDisplay/components/GraphStatusChrome.tsx +4 -2
  86. package/src/LinearGraphDisplay/components/SubgraphHaplotypesField.test.tsx +41 -1
  87. package/src/LinearGraphDisplay/components/SubgraphHaplotypesField.tsx +33 -19
  88. package/src/LinearGraphDisplay/configSchema.ts +4 -3
  89. package/src/RgfaTabixAdapter/RgfaTabixAdapter.ts +2 -9
  90. package/src/WalkTabixSyntenyAdapter/WalkTabixSyntenyAdapter.ts +3 -6
  91. package/src/hoverSync/graphViewHighlights.test.ts +53 -0
  92. package/src/hoverSync/graphViewHighlights.ts +25 -0
  93. package/src/hoverSync/lgvHover.test.ts +100 -1
  94. package/src/hoverSync/lgvHover.ts +77 -6
  95. package/src/launchFromGraph/contributors.test.ts +52 -0
  96. package/src/launchFromGraph/contributors.ts +105 -1
  97. package/src/launchFromGraph/launchFromGraph.ts +2 -2
  98. package/src/panSNTabix.test.ts +28 -0
  99. package/src/panSNTabix.ts +26 -8
  100. package/src/version.ts +1 -1
  101. package/dist/chunks/GraphTrackSettingsDialog-EVIIGC5G.js +0 -6
  102. package/dist/chunks/GraphTrackSettingsDialog-EVIIGC5G.js.map +0 -7
  103. package/dist/chunks/LinearGraphDisplay-ZC4BQ27J.js +0 -2
  104. package/dist/chunks/RgfaTabixAdapter-XSOIEWBK.js +0 -2
  105. package/dist/chunks/RgfaTabixAdapter-XSOIEWBK.js.map +0 -7
  106. package/dist/chunks/WalkTabixSyntenyAdapter-3WRVNDLB.js +0 -2
  107. package/dist/chunks/chunk-6VNU7SD4.js +0 -2
  108. package/dist/chunks/chunk-GRTN25B6.js +0 -3
  109. package/dist/chunks/chunk-GRTN25B6.js.map +0 -7
  110. package/dist/chunks/chunk-HCDKP3IP.js +0 -2
  111. package/dist/chunks/chunk-LE43I4PT.js +0 -4
  112. package/dist/chunks/chunk-LE43I4PT.js.map +0 -7
  113. package/dist/chunks/chunk-QV7SSOMJ.js +0 -2
  114. package/dist/chunks/chunk-S333HOG5.js +0 -2
  115. package/dist/chunks/chunk-VZQ6VOUP.js +0 -2
  116. package/dist/chunks/chunk-VZQ6VOUP.js.map +0 -7
  117. package/dist/chunks/chunk-WLRRI35A.js +0 -3
  118. package/dist/chunks/chunk-WLRRI35A.js.map +0 -7
  119. package/src/launchFromGraph/launchTracks.test.ts +0 -95
  120. package/src/launchFromGraph/launchTracks.ts +0 -49
  121. /package/dist/chunks/{GraphGenomeView-SEAPDRXS.js.map → GraphGenomeView-KI4FQ5A7.js.map} +0 -0
  122. /package/dist/chunks/{HighlightColorDialog-QAYWLO5I.js.map → HighlightColorDialog-D4RCUCUF.js.map} +0 -0
  123. /package/dist/chunks/{MinigraphBubbleAdapter-3QM4XV47.js.map → MinigraphBubbleAdapter-TJYI7KEN.js.map} +0 -0
  124. /package/dist/chunks/{WalkFormsAdapter-FT2SW4H6.js.map → WalkFormsAdapter-CAJOWOEX.js.map} +0 -0
  125. /package/dist/chunks/{chunk-HF4H6LQI.js.map → chunk-HHMJNAA3.js.map} +0 -0
  126. /package/dist/chunks/{chunk-MUONTMYZ.js.map → chunk-K4JL57NR.js.map} +0 -0
  127. /package/dist/chunks/{chunk-OJWBLPPH.js.map → chunk-LTNFVL2F.js.map} +0 -0
  128. /package/dist/chunks/{chunk-QV7SSOMJ.js.map → chunk-UR2MJJUP.js.map} +0 -0
  129. /package/dist/chunks/{renderSvg-ZIUOPWJQ.js.map → renderSvg-3PPAEMBT.js.map} +0 -0
@@ -0,0 +1,3 @@
1
+ import{a as ke,g as U,h as tt,j,k as nt,l as Sn,m as kn,n as Rn,o as Tn,p as Oe,r as Ae,u as ot,v as rt}from"./chunk-VTMJQFN5.js";import{a as an,c as cn,e as _e,f as et,g as Mn,i as vn,j as En}from"./chunk-XZGYJ3JC.js";import{A as xn,B as Je,C as oe,D as A,E as Qe,L as yn,M as wn,a as Re,c as ln,g as dn,h as H,i as fn,j as Ke,k as Te,m as ze,n as un,o as de,p as pn,r as hn,s as Ze,t as mn,u as gn,z as bn}from"./chunk-4NIWMRKH.js";import{e as _n}from"./chunk-GYY6LF5L.js";import{a as nn,d as sn}from"./chunk-POUV7OPY.js";import{c as D,d as ne,g as en,j as Ue,k as Ee,l as on,m as rn}from"./chunk-DEWZOJSC.js";import{a as te,c as zt,d as K,e as We,f as Zt,g as O,q as tn,r as I,s as je,v as Ve}from"./chunk-SPL3UO2D.js";import{d as Jt,e as Qt,f as le}from"./chunk-FCMXEFJA.js";import{a as He}from"./chunk-IKJZPPOA.js";import{g as E}from"./chunk-NDRLCGPC.js";import{b as Se}from"./chunk-YU7T5WOQ.js";var Ne=8,st=34,Pe=12,Ur=60;function jr({count:e,bounds:t,pixelRows:n,width:o,room:r,columns:s}){function i(l){let c=Math.ceil(e/l),f=Math.floor((o-(l-1)*Ne)/l),u=(r-c*st-(c-1)*Ne)/c,d=(f-2*Pe)/t.w,p=t.h>0?(u-2*Pe)/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*Pe,u)));return{columns:l,width:f,height:b,scale:h,total:c*(b+st)+(c-1)*Ne}}if(s!==void 0)return i(Math.max(1,Math.min(e,Math.round(s))));let a=i(1);if(n)return a;for(let l=2;l<=e;l++){let c=i(l);c.scale>a.scale&&(a=c)}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 On(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=On(e,n),r={columns:void 0,count:e.length,cells:e.map(c=>o.indexOf(c))};if(t==="walk")return r;let s=e.map(c=>{let f=Qt(c);return f&&Number.isInteger(f.haplotype)&&f.haplotype>=0?{sample:f.sample,column:Math.max(0,f.haplotype-1)}:void 0}),i=On([...new Set(s.flatMap(c=>c?[c.sample]:[]))],n),a=Math.max(1,...s.map(c=>c?c.column+1:1)),l=s.map(c=>c?i.indexOf(c.sample)*a+c.column:-1);return l.includes(-1)||new Set(l).size<l.length?r:{columns:a,count:i.length*a,cells:l}}var Zr=Math.PI/24;function An(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 Jr(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),l=a+s(n,o),c=i+r*(a-i),f=(h,m,b,g)=>{let x=(c-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,l);return f(f(u,d,0,a),f(d,p,i,l),i,a)}var Nn=(e,t)=>({x:2*t.x-e.x,y:2*t.y-e.y});function Pn(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(An(e,n),An(e,n+1))/Zr),i=e[n-1]??Nn(r,o),a=e[n+2]??Nn(o,r);for(let l=1;l<s;l++)t.push(Jr(i,o,r,a,l/s));t.push(r)}return t}function $n(e,t){let o=e.nodes.filter(O).filter(b=>(t[b.id]?.length??0)>0).flatMap(b=>{let g=t[b.id],x=g.length-1,M=H(b.id)===(b.stable.strand??"+");return g.map((y,w)=>{let v=x===0?.5:w/x;return{x:y.x,y:y.y,r:b.stable.start+b.length*(M?v:1-v),w:b.length/g.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,l=0,c=0;for(let b of o)l+=b.w*(b.x-s)*(b.r-a),c+=b.w*(b.y-i)*(b.r-a);if(l===0&&c===0)return t;let f=-Math.atan2(c,l),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 Cn=30;function Qr(e,t){let{opts:n}=t,o=new Map(t.nodes.map(d=>[d.id,_e(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 l=ke(e),c=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=c.get(d)+1;for(let m of l.get(d)??[])c.has(m)||(c.set(m,h),i.set(m,{x:p.x+r(d)/2,y:Cn*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:Cn*3});return i}function In(e,t){let n=Qr(e,t);return t.nodes.map(o=>({...o,...n.get(o.id)}))}var es=.5;function Ln(e,t,n=new Set){let o=new Map(t.map(s=>[s.edgeIndex,`${an}${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:l,toStrand:c}=s;r.push({from:s.from,to:a,...l?{fromStrand:l}:{}},{from:a,to:s.to,...c?{toStrand:c}:{}})}}),{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 Bn(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),l=Math.max(r.minimumNodeLength,o(a)*es),c=n.get(i.edgeIndex);return{id:c,name:c,length:Math.round(l*1e6/r.nodeLengthPerMegabase),depth:0}})}function Xn(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 Fn(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 Dn=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===Dn||i===ns)&&(r(s),n=i===Dn?"+":"-",o=s+1)}return r(e.length),t}function qn(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.indexOf(" "),s=r===-1?o:o.slice(0,r);if(s==="H"){let[,...i]=o.split(" ");t.header.push(fe(i))}else if(s==="S"){let[,i,...a]=o.split(" "),l,c,f,u=!1,d=a[0]??"*";/^\d+$/.test(d)?(l=+d,c=a[1]??"*",f=a.slice(2)):(u=!0,c=d,l=c==="*"?0:c.length,f=a.slice(1));let p=fe(f);u&&"LN"in p&&(l=+p.LN),t.nodes.push({id:i,length:l,sequence:c,tags:p})}else if(s==="E"){let[,,i,a,,,,,l,...c]=o.split(" ");i&&a&&t.links.push({source:i.slice(0,-1),target:a.slice(0,-1),strand1:i.at(-1),strand2:a.at(-1),cigar:l??"*",tags:fe(c)})}else if(s==="L"){let[,i,a,l,c,f,...u]=o.split(" ");i&&l&&c&&t.links.push({source:i,target:l,strand1:a,strand2:c,cigar:f??"*",tags:fe(u)})}else if(s==="W"){let[,i,a,l,c,f,u,...d]=o.split(" ");i&&a&&l&&c&&f&&u&&t.walks.push({sample:i,haplotype:+a,contig:l,start:c==="*"?-1:+c,end:f==="*"?-1:+f,segments:os(u),tags:fe(d)})}else if(s==="P"){let[,i,a,...l]=o.split(" ");i&&a&&t.paths.push({name:i,path:a,rest:l})}}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 l=o.get(i);l===void 0&&r(i,a),o.set(i,(l??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 Gn=e=>e.start===-1?0:e.start;function ss(e){return{...I(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:Gn(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:Fn(e),samples:as(e)}}function Yn(e,t="Imported GFA"){let n=[],o=[],r=e.paths.map(ss),{canonical:s,traversals:i}=rs(e,r),a=new Map,l=g=>{let x=a.get(g);return x===void 0&&(x=`${g}${s.get(g)??"+"}`,a.set(g,x)),x},c=new Map;for(let g of e.nodes){if(c.has(g.id))continue;c.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:l(g.source),to:l(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=>l(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=>l(y.id)),M=`${g.sample}#${g.haplotype}#${g.contig}`;f.push({name:M,nodeIds:x,start:Gn(g),sample:g.sample,haplotype:g.haplotype,contig:g.contig,...en(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?je(is(e,r),g=>c.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 Ue(e,t);let n=nn(e);return n?Ue(n,t):Yn(qn(e),t)}function Gl(e,t,n={}){let o=ds(e,t);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 Ve(o,n.referencePath)}var z={engine:"fmmm",quality:2,linearLayout:!1,bubbleSpread:"auto",spacing:1,componentSeparation:1,showDeletionEdges:!0};function Wn(e={}){return{engine:e.engine??z.engine,quality:e.quality??z.quality,linearLayout:e.linearLayout??z.linearLayout,bubbleSpread:e.bubbleSpread??z.bubbleSpread,spacing:e.spacing??z.spacing,componentSeparation:e.componentSeparation??z.componentSeparation,showDeletionEdges:e.showDeletionEdges??z.showDeletionEdges}}var fs=15;function us(e,t,n){let o=e.nodes.some(O),r=Wn(n),s={...t,opts:{...t.opts,edgeLength:t.opts.edgeLength*r.spacing}};return{graph:{nodes:o?In(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 it(e,t){let n=e.nodes.some(O);return[...Object.values(Wn(t)),n,e.referencePath??""].join("|")}async function Hn(e,t,n){let o=En(t.bubbleSpread),{shown:r,hidden:s}=xn(e,bn(e),t.showDeletionEdges!==!1),i=Ln(e,r,s),a=mn(i.graph,i.ids),l={...a.graph,nodes:a.graph.nodes.filter(x=>!i.ids.has(x.id))},c=et(l,o),{result:f,duration:u}=await n(us(a.graph,{...c,nodes:[...c.nodes,...Bn(e,r,i.routes,Mn(l,o),c.opts)]},t)),d=et(e,o),p=new Map(d.nodes.map(x=>[x.id,_e(d.opts,x.length)])),h=Object.fromEntries(Object.entries(f.nodePositions).map(([x,M])=>[x,Pn(M)])),m=gn(h,a.runs,x=>p.get(x)??0),{nodePositions:b,deletionRoutes:g}=Xn(e.nodes.some(O)?$n(e,m):m,i.routes);return{result:{...f,nodePositions:b,stranded:!0,...r.length?{deletionRoutes:g,extent:Un(g)}:{}},duration:u}}function Un(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 at(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 Yl(e,t,n,o,{minScale:r=0,padLeft:s=pe,padTop:i=pe,padRight:a=pe,padBottom:l=pe}={}){let c=t-s-a,f=n-i-l;if(c<=0||f<=0||!(e.w>0||!o&&e.h>0))return;let u=e.w>0?c/e.w:1/0,d=e.h>0?f/e.h:1/0,p=at(Math.max(r,o?u:Math.min(u,d))),h=c-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 Wl(e,t={}){let{minX:n,minY:o,maxX:r,maxY:s}=Un(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 ct(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=it(o,r),l=i.get(a);if(l)return l.run;i.size>=e&&i.delete(i.keys().next().value);let c=performance.now(),f={run:Hn(o,r,s).then(u=>(f.done=u.result,{...u,duration:u.duration||performance.now()-c}))};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(it(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 lt(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=at(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}),jn=vs("RenderLifecycleMixin"),Vd=Z&&Z.__esModule?Z.default:Z;function Vn(e){return t=>e.includes(t)?t:void 0}function Zd(e){return E.snapshotProcessor(E.maybe(E.enumeration(e)),{preProcessor:Vn(e)})}function $e(e,t){return E.snapshotProcessor(E.optional(E.enumeration(e),t),{preProcessor:Vn(e)})}var lf=600,df=160,ff=[1,1,1,1],uf="rgb(255, 255, 255)",pf=5,hf=new Set(["tubemap","tubemapref"]),mf=Se(()=>import("./ChooseSamplesDialog-JRN4YLBY.js")),gf=Se(()=>import("./ChooseWalksDialog-SM326TOX.js")),bf=Se(()=>import("./HighlightColorDialog-D4RCUCUF.js")),xf=12,yf=[{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 wf(e){if(typeof e.uri=="string")return e.uri;let n=e.segmentsLocation?.uri;return typeof n=="string"&&n.endsWith(He)?n.slice(0,-He.length):void 0}var Mf=1.15,vf=1.6,Ef=150,Sf=1,kf=40,Rf=40,Tf=[{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 _f(...e){}var Ss=5e6;function Of(e){return e>=1e6?`${+(e/1e6).toFixed(1)} Mb`:`${Math.round(e/1e3)} kb`}var ks=2e4;function Af(e){return("uri"in e?e.uri.split(/[?#]/)[0]:"localPath"in e?e.localPath:"name"in e?e.name:"").split(/[\\/]/).at(-1)??""}function Nf(e){return e.builtViewport!==void 0&&e.paintedViewport===e.builtViewport&&e.builtViewport.viewportDirty===e.viewportDirty&&!e.viewportRebuildPending}function Pf(e){let{width:t,height:n}=e.viewBox;return lt(e,e.axisScale,t,n)}var $f=ct(),Cf=E.compose("GraphPane",jn(),E.model({layoutQuality:E.optional(E.number,2),layoutEngine:$e(cn,"fmmm"),linearLayout:E.optional(E.boolean,!1),bubbleSpread:$e(vn,"auto"),tubeMapFold:E.optional(E.number,0),tubeMapRoutes:$e(["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()),expandedWalks:E.optional(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,ownGeneFeatures: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 N=e=>+e.toFixed(1),Rs=e=>+e.toFixed(3);function Ts(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}=Ts(t);return`${e}="${n}"${o<1?` ${e}-opacity="${Rs(o)}"`:""}`}var Kn=.5,zn=.25;function Lf(e,t){let n=[],o=[],r=(c,f)=>{let u={d:`M${N(c)} ${N(f)}`,segments:0,x0:c,x1:c,y0:f,y1:f};return o.push(u),u},s=c=>{let f=o.at(-1)??r(c[0],c[1]);for(let u=0;u<c.length;u+=2)f.x0=Math.min(f.x0,c[u]),f.x1=Math.max(f.x1,c[u]),f.y0=Math.min(f.y0,c[u+1]),f.y1=Math.max(f.y1,c[u+1]);return f.segments++,f},i=c=>{let f=new Set;return o.map(u=>{if(!c||u.x1-u.x0>=Kn||u.y1-u.y0>=Kn)return u.d;let d=(u.x0+u.x1)/2,p=(u.y0+u.y1)/2,h=`${Math.round(d/zn)} ${Math.round(p/zn)}`;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(c,f){r(c,f)},lineTo(c,f){s([c,f]).d+=`L${N(c)} ${N(f)}`},bezierCurveTo(c,f,u,d,p,h){s([c,f,u,d,p,h]).d+=`C${N(c)} ${N(f)} ${N(u)} ${N(d)} ${N(p)} ${N(h)}`},closePath(){let c=o.at(-1);c&&(c.d+="Z")},stroke(){let c=i(a.lineCap!=="butt");c&&n.push(`<path d="${c}" fill="none" ${dt("stroke",a.strokeStyle)} stroke-width="${N(a.lineWidth)}" stroke-linecap="${a.lineCap}" stroke-linejoin="${a.lineJoin}"/>`)},fill(){let c=i(!1);c&&n.push(`<path d="${c}" ${dt("fill",a.fillStyle)}/>`)},clearRect(){n.length=0},fillRect(c,f,u,d){n.push(`<rect x="${N(c)}" y="${N(f)}" width="${N(u)}" height="${N(d)}" ${dt("fill",a.fillStyle)}/>`)}},l={width:e,height:t,style:{},getContext:()=>a};return a.canvas=l,{canvas:l,markup:()=>n.join("")}}var Zn=2,Jn=8192;function re(e=0,t=0){let n=typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,Zn);return Math.min(n,Jn/Math.max(e,t,1))}function ft(e,t,n){let o=re(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 qf=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1,this.fit=1,this.painted=null;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=ft(this.canvas,e,t)/re()}uploadGeometry(e){this.batch=e,this.highlightedEdge=null,this.painted=null}setNodeHighlights(e){this.nodeHighlights=e,this.painted=null}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t,this.painted=null}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),e[3]>0&&(n.fillStyle=tt([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{edges:i,nodes:a,arrows:l}=this.paintedGroups(s);for(let{color:c,items:f}of i)this.strokeCurves(f,c,t);for(let{color:c,items:f}of a)this.strokeNodes(f,c,t);for(let{color:c,items:f}of l)this.fillArrows(f,c,t)}paintedGroups(e){if(this.painted)return this.painted;let t=this.highlightFactor,n=this.edgeRun(e.edgeCurveRuns),o=this.edgeRun(e.arrowRuns),r=this.liftedStrokes(e);return this.painted={edges:se(e.edgeCurves,(s,i)=>({color:Ce(n,i)?j(s.color,t):s.color,weight:s.thickness,last:Ce(n,i)})),nodes:se(e.nodeStrokes,(s,i)=>{let a=r.get(i);return{color:a===void 0?s.color:j(s.color,a),weight:s.thickness,last:a!==void 0}}),arrows:se(e.arrows,(s,i)=>({color:Ce(o,i)?j(s.color,t):s.color,weight:0,last:Ce(o,i)}))}}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=Qn(t.edgeCurves,this.edgeRun(t.edgeCurveRuns));for(let{color:a,items:l}of se(r,c=>({color:j(c.color,o),weight:c.thickness,last:!1})))this.strokeCurves(l,a,n);let s=[...this.liftedStrokes(t)];for(let{color:a,items:l}of se(s,([c,f])=>({color:j(t.nodeStrokes[c].color,f),weight:t.nodeStrokes[c].thickness,last:!1})))this.strokeNodes(l.map(([c])=>t.nodeStrokes[c]),a,n);let i=Qn(t.arrows,this.edgeRun(t.arrowRuns));for(let{color:a,items:l}of se(i,c=>({color:j(c.color,o),weight:0,last:!1})))this.fillArrows(l,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=U(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=U(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 l=r.points[i];o.lineTo(l.x*n.scaleX+n.translateX,l.y*n.scaleY+n.translateY)}}o.stroke()}fillArrows(e,t,n){let o=this.ctx;o.fillStyle=U(t),o.beginPath();for(let r of e){let[s,i,a,l]=Os(r,n);o.moveTo(s.x,s.y),o.lineTo(i.x,i.y),o.lineTo(a.x,a.y),o.lineTo(l.x,l.y),o.closePath()}o.fill()}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.painted=null}},_s=.25;function Os(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,l=r-n*i,c=s-o*i,f=i*(1-_s);return[{x:r,y:s},{x:l-o*a,y:c+n*a},{x:r-n*f,y:s-o*f},{x:l+o*a,y:c-n*a}]}function Qn(e,t){return t?e.slice(t.start,t.start+t.count):[]}function Ce(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function se(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:l,last:c}=t(i,r),f=c?o:n,u=`${a}:${l}`,d=f.get(u);d?d.items.push(i):f.set(u,{color:a,items:[i]})}return[...n.values(),...o.values()]}var As=50;function eo(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 to(e,t,n){let o=eo(t,e.length);return{x:o,y:n>0?eo(n,e.length):Ns(e)??o}}function Ps(e,t,n,o){return e===void 0?to(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 no(e,t,n,o,r,s,i){let a=Math.floor(n/t.x),l=Math.floor(r/t.x),c=Math.floor(o/t.y),f=Math.floor(s/t.y);for(let u=a;u<=l;u++)for(let d=c;d<=f;d++)$s(e,u,d).push(i)}function oo(e,t,n,o,r,s){let i=Math.floor((n-r)/t.x),a=Math.floor((n+r)/t.x),l=Math.floor((o-s)/t.y),c=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=l;h<=c;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 ro=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 l=i[a],c=i[a+1],f=Math.min(l.x,c.x),u=Math.min(l.y,c.y),d=Math.max(l.x,c.x),p=Math.max(l.y,c.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)no(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,o=n){return oo(this.cells,this.cellSize,e,t,n,o)}},so=class{constructor(e,t,n,o,r,s=0,i,a=!1){this.cells=new Map,this.edgeCurves=Tn(e,t,o,r,s,i,a);let l=[],c=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}=ln(m),y=d.pathIds?.length??0;if(n&&y>0){let w=0,v=0;for(let S of Te(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}c+=x-b,f+=M-g,l.push({ei:u,minX:b,minY:g,maxX:x,maxY:M})}}this.cellSize=to(l,c,f);for(let u of l)no(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 oo(this.cells,this.cellSize,e,t,n,o)}};function ao(e,t,n,o,r,s){let i=r-n,a=s-o,l=i*i+a*a;if(l===0)return Math.hypot(e-n,t-o);let c=Math.max(0,Math.min(1,((e-n)*i+(t-o)*a)/l));return Math.hypot(e-(n+c*i),t-(o+c*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 l=a/r,c=1-l,f=c*c*c*n.x0+3*c*c*l*n.cx0+3*c*l*l*n.cx1+l*l*l*n.x1,u=c*c*c*n.y0+3*c*c*l*n.cy0+3*c*l*l*n.cy1+l*l*l*n.y1;o=Math.min(o,ao(e,t,s,i,f,u)),s=f,i=u}return o}function io(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 Is=ze();function co(e,t){return Is(e,[t],()=>new ro(e))}var Ls=ze();function Bs(e,t,n,o,r,s,i,a=!1){return Ls(e,[t,n,o.scaleX,o.scaleY,r,s,i,a],()=>new so(e,t,n,o,s,r,i,a))}var Xs=5;function Jf(e,t,n,o,r=0,s){let i=Ke(o),a=co(e,r),l=p=>Math.max(Xs,p)/o.scaleX,c=l(s?.maxHalfWidthPx??0),f=a.query(t,n,c,c/i),u=null,d=1/0;for(let{nodeId:p,segmentIdx:h}of f){let m=e[p],b=ao(t,n*i,m[h].x,m[h].y*i,m[h+1].x,m[h+1].y*i);b<d&&b<l(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,l]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(l<0)return!1}else a<0?s=Math.max(s,l/a):i=Math.min(i,l/a);return s<=i}function lo(e,t,n=0){let o=co(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:l,segmentIdx:c}of a){let f=e[l];!i.has(l)&&Ds(r(f[c]),r(f[c+1]),s)&&i.add(l)}return i}}function Qf(e,t,n,o,r,s,i=0,a,l,c,f=!1){let u=Ke(r),d=10/r.scaleX,p=Bs(e,t,s,r,i,a,c,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||l?.has(g))continue;let w=x.pathIds?.length??0,v=p.getCurves(g);if(!v)continue;let S;if(!s||w===0)S=io(n,o*u,v,u);else{let k=1/0;for(let T of Te(M,y,w,r)){let G=T.x===0&&T.y===0?v:dn(v,T.x,T.y),Y=io(n,o*u,G,u);Y<k&&(k=Y)}S=k}S<b&&(b=S,m=g)}return m}var fo=3.4,ut=6,Fs=18,qs=2,Gs=3,Ys=un+pn;function uo(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,o]=t>=999500?[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 po(e,t,n,o){let r=n/2;return ho(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:i,y:a}=t(s.at),l=uo(s);return{item:s,x:i,y:a+n+Fs,text:l?`${s.gene.name} \xB7 ${l}`:s.gene.name,fallback:l?`${s.gene.name} \u2026`:void 0,stack:qs,fits:c=>[...o({x0:c.x0-r,x1:c.x1+r,y0:c.y0-r,y1:c.y1+r})].every(f=>s.nodeIds.has(f))}})}function ho(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},l=w=>({x:w.x*s+o,y:w.y*i+r}),c=e.drawnRowLabels.map(({label:w,y:v})=>Je(w,v*i+r)),f=e.referenceStripZonePx??0;f>0&&c.push({x0:0,x1:t,y0:0,y1:f}),e.legendSize.width>0&&c.push({x0:t-ut-e.legendSize.width,x1:t,y0:0,y1:f+ut+e.legendSize.height}),e.poppedFrom&&c.push({x0:0,x1:60+e.poppedFrom.label.length*de*1.2,y0:0,y1:44});let u=hn(a,c),d=e.drawnRowLabels.length>0,p=d?Math.min(...e.drawnRowLabels.map(w=>w.y)):1/0,h=e.contigThickness*fo,m=(w,v)=>{let{x:S,y:k}=l({x:w.labelAt.x,y:Math.min(w.labelAt.y,p)}),T=k-h/2-v;return{x:S,y:d?Math.max(T,Ys):T}},b=ho(e.bubbleHalos.filter(w=>!w.tick),w=>w.whole?-1:w.members),g=Ze(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).map(w=>({item:w,...m(w,2)})).filter(w=>w.x>=0&&w.x<=t&&w.y>=0&&w.y<=n),M=Ze(po(e.genePins,l,e.contigThickness,lo(e.nodePositions??{},{scaleX:s,scaleY:i,translateX:o,translateY:r},e.positionsVersion)),a,u),y=e.nodePositions&&e.labelsNodeSizes?Qe({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 J=JBrowseExports.mobx,ie=e=>J!=null&&e in Object(J)?J[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 Su=ie("autorun");var ku=ie("computed");var mo=ie("observable");var Ru=ie("reaction");var go=ie("runInAction");var Tu=ie("untracked");var _u=J&&J.__esModule?J.default:J;function pt(e,t){return t===H(e.id)?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,l=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}}},c=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 sn(e.cs))if(d.op==="match")u+=d.length;else if(d.op==="substitution"){let p=l(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?l(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=l(u),m=Math.min(p,h?h.room:c(u));h&&f(h.s,{type:"deletion",pos:h.local,length:m}),u+=m,p-=m}}return n}function bo(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]:[]),l=a[0],c=a.at(-1);if(l!==void 0&&c!==void 0){let f=Us(s,i.map(p=>p?.length)),u=a.map(p=>pt(i[p],s.path[p].strand)),d=i[c].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:l===0?s.pathStart:0,finalNodeCoverLength:c===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 xo(e){let t=e.is_reverse?Vs:js;return t[e.id%t.length]}var Ks=10;function zs(e,t){let n=e.end-e.start,o=e.longestAlleleLength-e.shortestAlleleLength;return t.find(r=>o<=Ks*(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 Zs=40;function Js(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 ht(e){return e>=_n?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function Qs(e,t=[]){let n=ei(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function ei(e,t){let n=e.end-e.start,{shortestAlleleLength:o,longestAlleleLength:r,pathCount:s,segmentCount:i,inversion:a}=e,l=Js(o,r);if(i>=Zs)return{kind:"superbubble",label:`${l} superbubble, ${i} segments, ${ht(s)}${a?", inv":""}`};if(a)return{kind:"inversion",label:`${A(r)} inv`};if(e.offReference)return o===r?yo(o):{kind:"complex",label:`${l}, ${ht(s)}`};let c=r!==o?zs(e,t):void 0;if(c){let u=c.name?` (${c.name})`:"";return{kind:"repeat",label:`${l} repeat array${u}, ${ht(s)}`}}let f=s>2?`, ${s} alleles`:"";return o===r&&o===n?yo(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 ${l}, ${s} alleles`}}function yo(e){return e<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${A(e)} sub`}}var ti={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},ni={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function oi(e){return e.segments.split(",").filter(Boolean)}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 ri(e){return wo(e).replaceAll('"',"&quot;")}function si(e){if(typeof e=="string")return wo(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,o])=>` ${n}="${ri(String(o))}"`).join("");return`<${e.tag}${t}>${e.children.map(si).join("")}</${e.tag}>`}var yt="#2f8fd6",wt="#8e3fbf",Mo="#bdbdbd",vo="#8a8a8a",Eo="#e2e2e2",So="#d9a441",he="#1c1c22",Mt=12,Ie=4,ko=1,bt=12,ii=6,ai=3;function F(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function ci(e){let t=Math.abs(e);return`${e>0?"+":"\u2212"}${t<1e3?`${t} bp`:F(t)}`}function mt(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}var li=({refName:e,start:t})=>`${Jt(e)}:${t<1e6?`${Math.round(t/1e3)} kb`:`${(t/1e6).toFixed(1)} Mb`}`;function di(e){return e<1e3?`${e}`:`${Math.round(e/1e3)} k`}function fi(e,t,n=0){if(e<=0)return"";let o=(t??[]).filter(l=>l.gap);if(!o.some(l=>l.cause))return` \xB7 ${F(e)} ${ne}`;let r=l=>o.filter(c=>c.cause===l).reduce((c,f)=>c+f.bp,0),s=[...new Set(o.flatMap(l=>l.chunk?[li(l.chunk)]:[]))],i=[[r("missing"),D.missing],[r("elsewhere"),`on nodes filed near ${s[0]}${s.length>1?` and ${s.length-1} more place${s.length>2?"s":""}`:""}`],[r("unknown"),D.unknown],[r(void 0),ne]],a=r("abridged");return(a>0?` \xB7 ${di(n)} steps, ${F(a)} not loaded`:"")+i.filter(([l])=>l>0).map(([l,c])=>` \xB7 ${F(l)} ${c}`).join("")}function Ro(e,t,n,o){let{bp:r,gapBp:s,complete:i,stop:a}=e;if(!t)return`${F(r)}${mt(r,n)}`;let l=fi(s,e.runs,e.abridgedSteps),c=o?` \xB7 called ${F(o.bp)}${o.spanningReads===0?" \xB7 no spanning read":""}`:"";if(i){let d=r-t.bp,p=d===0?"":` (${ci(d)})`;return`${F(r)}${mt(r,n)}${p}${l}${c}`}let f=n?"repeat":"window";if(a?.contigEnds&&r===0)return`contig ends ${a.shortBp>0?`${F(a.shortBp)} before`:"at"} the ${f}${c}`;let u=a?a.contigEnds?`contig ends inside the ${f}`:"does not rejoin the reference within the extracted subgraph":"partial walk";return`\u2265 ${F(r)}${mt(r,n)} \xB7 ${u}${l}${c}`}function To(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 _o(e,t,n){if(t*n<ai)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:ko,label:D.missing}:e==="unknown"?{fill:Eo,px:Ie,label:D.unknown}:e==="abridged"?{fill:So,px:Ie,label:D.abridged}:{fill:Mo,px:Ie,label:ne}}function Oo(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:Ae};let n=Sn({...e,start:e.referenceStart},t);return n.length===1?{fill:nt(n[0])}:{stops:n.map(nt)}}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 ui(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function pi(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:l})=>({start:Math.max(0,a),end:Math.min(o.bp,l)});n.set(o.name,r.map(a=>({name:a.name,...i(xt(s,a.start,a.end)),exons:a.exons.map(l=>i(xt(s,l.start,l.end))).filter(l=>l.end>l.start)})).filter(a=>a.end>a.start).sort((a,l)=>a.start-l.start))}return n}var hi=9,mi=5.2,gi=8,Ao=(e,t)=>Math.min(2,(e-t)/2-1);function No(e,t){return Ao(e,t)>=1}function Po(e,t,n,{rowPx:o=Re,barPx:r=Mt}={}){if(!No(o,r))return[];let s=Ao(o,r),i=e.map(c=>{let f=t(c.start);return{g:c,x:f,w:Math.max(2,t(c.end)-f)}}),a=[],l=new Set((r>=gi?[...i]:[]).sort((c,f)=>c.w-f.w).filter(({g:c,x:f,w:u})=>{let d=c.name.length*mi/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(c=>({name:c.g.name,x:c.x,y:n-r/2-s,w:c.w,h:r+2*s,exons:c.g.exons.map(f=>({x:t(f.start),w:Math.max(1,t(f.end)-t(f.start))})),label:l.has(c)?{x:c.x+c.w/2,y:n+3,size:hi}:void 0}))}var gt=e=>`${e} row${e===1?"":"s"}`;function bi(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??Rn,ramp:!0}:{kind:"bar",fill:yt},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Ae: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","abridged"]){let{fill:i,px:a,label:l}=me(s);r.has(l)&&n.push({swatch:{kind:"gap",fill:i,px:a},label:l})}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 ${gt(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${gt(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${gt(t.genes.unread)}`,note:!0})),n}var $o="#111",Co="#9e9e9e",vt="#c62828";function Io(e){return e.agrees===!1?vt:e.spanningReads===0?Co:$o}function xi(e,t,n,o="walk-key"){let r=0,s=e.flatMap((i,a)=>{let l=`${o}-ramp-${a}`,c=!i.note&&i.swatch.kind==="bar"&&i.swatch.ramp?_("linearGradient",{id:l},...kn.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:c?`url(#${l})`: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,[c,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 yi(e,t,n=0){let o=t/Math.max(1,e),r=Math.max(n,Math.min(Re,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,l=0;for(let u of r)u.onReference?a+=u.bp:l+=u.bp;let c=a>=l,f=r.find(u=>u.onReference===c);o.push({start:r[0].start,bp:a+l,onReference:c,referenceStart:c?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 wi(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??Re,s=t.barPx??Mt,i=Math.min(3,Math.max(0,(r-s)/2)),a=m=>m*r*t.scaleY+t.translateY,{origin:l,unit:c,reference:f,rows:u}=e,d=m=>o(l+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(k=>{let T=Oo(k,n.ramp),G=k.gap?Math.min(me(k.cause).px,s):s,Y=`${p}-${b}-${k.start}`,ye=_("rect",{x:d(k.start),y:g-G/2,width:Math.max(1,k.bp*t.scaleX),height:G,fill:"stops"in T?`url(#${Y})`:T.fill});return"stops"in T?[_("linearGradient",{id:Y},...T.stops.map((we,Me)=>_("stop",{offset:Me/(T.stops.length-1),"stop-color":we}))),ye]:[ye]}),y=c&&s>=ii?_o(m.bp,c,t.scaleX).map(k=>_("line",{x1:d(k),x2:d(k),y1:g-s/2,y2:g+s/2,stroke:"white","stroke-width":1})):[],{call:w}=m,v=t.readouts??!0?{text:Ro(m,b===0?void 0:f,c,w)}:void 0,S=v&&To(v.text,d(m.bp),t.width);return _("g",{"data-testid":b===0?"graph-walk-reference":"graph-walk-row"},...M,...y,...Po(n.rowGenes?.get(m.name)??[],d,g,{rowPx:r,barPx:s}).map(k=>wi(k,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:Io(w)}),v&&S&&_("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.text))};return _("g",{},...[f,...u].map(h))}function Et({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:l}=i.stable;te(o,a,{name:r.name,index:s,bp0:l,bp1:l+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 Le(e,t,n=!1){let o=K(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 Be(e,t,n){let o=Le(e,t),r=Le(e,n,!0);return{x0:Math.min(o,r),x1:Math.max(o,r)}}function Mi(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Bo=5,vi=10,Ei=110,Si=3;function Xo(e){return e?"#b0b0b8":"#55555c"}function ki(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+vi)&&t.push(n);return t.map(({text:n,at:o})=>({text:n,at:o}))}function Ri(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),l=s.bp1-r.bp0;if(a<=i||l<=0)return;let c=ki(l/(a-i)*Ei),f=[],u=[];for(let d=Math.ceil(r.bp0/c)*c;d<=s.bp1;d+=c){let p=Math.round(t(Le(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 Ti(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)}),l=(h,m)=>a(h.toLocaleString("en-US"),m),c=[],f=[],u=[],d=[];for(let{box:h,s0:m,s1:b}of r){c.push({x0:m,x1:b}),f.push(Math.round(m)+.5),b-m>=Si&&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(l(h.bp0,m))}let p=[l(s.box.bp0,s.s0),l(i.box.bp1,i.s1)];return{spans:c,ticks:f,labels:Do([...p,...u,...d])}}function Fo(e,t,n,o,r=!1){return(r?Ri:Ti)(e,t,n,o)}function _i(e,t,n,o,r=!1){let{x:s,width:i,darkMode:a}=n;e.font="10px sans-serif";let l=Fo(t,s,i,u=>e.measureText(u).width,r);if(!l)return;let c=Xo(a),f=o+.5;e.strokeStyle=c,e.fillStyle=c,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:u,x1:d}of l.spans)e.moveTo(Math.max(0,u),f),e.lineTo(Math.min(i,d),f);for(let u of l.ticks)e.moveTo(u,o),e.lineTo(u,o+Bo);e.stroke();for(let{text:u,at:d}of l.labels)e.fillText(u,d,o+Bo+2)}function Oi(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 Ai=3;function Ni(e,t,n,o){if(t<=0||o<0||o>t)return;let r=o/t,s,i=Ai;for(let a of e){let l=a.top0+(a.bottom0-a.top0)*r,c=a.top1+(a.bottom1-a.top1)*r,f=Math.max(0,Math.min(l,c)-n,n-Math.max(l,c));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 Pi(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 $i=new Set(["_gbwt_ref","unknown"]);function Ho(e){let[t,n,o]=e?.split("#")??[];if(!(t===void 0||t===""||$i.has(t)||n===void 0||!/^\d+$/.test(n)||o===void 0||o===""))return{sample:t,haplotype:Number(n),contig:o}}var Ci=["read_group","sample_name"],Qp=[...Ci,"haplotype_sample"],Xe=8.401;function Ii({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:Ii(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??Xe,trackWidth:e.trackWidth??15,freqWidth:e.freqWidth??"log"}}function Bi(){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:Bi(),trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function ir(e,t,n=[],o={}){let r=Xi(e,t,n,o);return r&&Di(r,o)}var ar=new WeakMap;function Xi(e,t,n=[],o={}){let r=qi(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 Di(e,t={}){return Fi(e,Hi(e,t.facet),Gi(e,t))}function Fi(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 qi(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 ji(r,0),r.nodeMap=zo(r),ae(r,r.tracks),ae(r,r.reads),or(r),r.config.mergeNodes&&(Zo(r),kt(r),Tt(r),La(r),r.nodeMap=zo(r),or(r),ae(r,r.tracks),ae(r,r.reads)),Zo(r),ha(r),kt(r),ma(r),kt(r),Tt(r),ae(r,r.reads),{options:r.config,nodes:r.nodes,tracks:r.tracks,reads:r.reads,nodeMap:r.nodeMap,maxOrder:ua(r),trackForRuler:r.trackForRuler}}}function Gi(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||Yi(o,s)))}function Yi(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function Wi(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Hi(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=Wi(e);return e.tracks.filter(o=>n.has(o)||!("reads"in t)&&Ui(o)===t.key)}function Ui(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,l=r.haplotypes??Oa,c=Uo(i,"haplotypes")==="coarsen"?Aa(s,l):void 0;c!==void 0&&(s.tracks=[c.ref]),Ta(s),wa(s),Vi(s);let f=Uo(i,"reads")==="coarsen"&&s.reads.length>0?pr(s,s.reads,"read",r.reads??l+(c?.bands.length??0)):void 0;f!==void 0&&(s.reads=f.bands);let u={};for(let[d,p,h]of[["haplotypes","haplotype",c],["reads","read",f]])h!==void 0&&(Tt(s,h.bands),ae(s,h.bands),u[d]={unit:p,total:h.total,reverse:!a&&h.bands.some(m=>m.is_reverse)});return c!==void 0&&(s.reads=c.bands.concat(s.reads)),zi(s),s.tracks=s.tracks.concat(s.reads),o==="measure"&&ba(s),_a(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:ia(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 _t(e){return P(e)?$(e):lr(e)}function jo(e){return e>0}function ji(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]=_t(r[s]));e.nodes.forEach(r=>{n.has(r.name)&&(r.seq=Nt(r.seq))})}}function Vi(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 Ot=7;function Ki(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=Ot),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 zi(e){e.reads.forEach(a=>{a.path=dr(e,a)}),Ki(e);let t=e.nodes.filter(a=>a.order>=0);t.sort($t);let n=new Map;for(let a=0;a<e.reads.length;a++){let l=e.reads[a],c=l.haplotypeShare===void 0?1:0,f=l.sourceTrackID,u=`${c}:${f}`,d=n.get(u);d===void 0?n.set(u,{layer:c,source:f,reads:new Set([a])}):d.reads.add(a)}let o=[...n.values()].sort((a,l)=>a.layer-l.layer||a.source-l.source),r=o.length>1?Ot:0;t.forEach(a=>{for(let{reads:l}of o)Zi(e,l,a,r)});let s=oa(e),i=[];e.reads.forEach((a,l)=>{let c=[],f=[],u;a.path.forEach((d,p)=>{c[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=c[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:l,pathIndex:p,previousY:h?.y,previousNode:h?.node})}})}),i.sort((a,l)=>Qi(e,a,l)),i.forEach(a=>{let l=e.reads[a.readIndex],c=l.path[a.pathIndex];c.y=s[c.order],s[c.order]+=l.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,l=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}});l.sort(Ji),r=l.map(h=>h.entry);let c=a,f=new Map;r.forEach(h=>{let m=e.reads[h[0]];m.path[h[1]].y=c,Ko(f,m,h[1],c,n),c+=m.width});let u=c;s.sort((h,m)=>ea(e,h,m));let d=new Map;c=a,s.forEach(h=>{let m=e.reads[h[0]],b=m.firstNodeOffset??0;m.path[h[1]].y=c,d.set(c,b);let g=f.get(c);g===void 0||g+1<=b?(c+=m.width,u=Math.max(u,c)):(f.set(c,0),r.forEach(x=>{let M=e.reads[x[0]],y=M.path[x[1]];y.y!==void 0&&y.y>=c&&(y.y+=m.width,Ko(f,M,x[1],y.y,n))}),c+=m.width,u+=m.width)}),i.sort((h,m)=>na(e,h,m)),i.forEach(h=>{let m=e.reads[h],b=m.firstNodeOffset??0,g=m.finalNodeCoverLength??0;for(c=a;b<(f.get(c)??-1/0)+2||g>(d.get(c)??1/0)-3;)c+=m.width;m.path[0].y=c,f.set(c,g),u=Math.max(u,c)});let p=u-n.y-n.contentHeight;n.contentHeight+=p,ka(e,n,p)}function Ji(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 Qi(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,l=n.previousY??0,c=s.betweenCycleReverseTraversal===!0,f=i.betweenCycleReverseTraversal===!0;return c!==f?c?1:-1:c?l-a:a-l}function ea(e,[t,n],[o,r]){let s=e.reads[t],i=e.reads[o],a=s.path.findLast(p=>p.y!==void 0)?.y,l=i.path.findLast(p=>p.y!==void 0)?.y;if(a!==void 0&&l!==void 0)return a-l;let c=(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=c(s,n),d=c(i,r);for(;u!==null&&u===d;)n=f(s,n),r=f(i,r),u=c(s,n),d=c(i,r);return u!==null&&d!==null?$t(u,d):u!==null||d!==null?u===null?-1:1:(s.firstNodeOffset??0)-(i.firstNodeOffset??0)||(s.finalNodeCoverLength??0)-(i.finalNodeCoverLength??0)}function ta(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],l=i.order,c=a.order;if(l===c&&i.node&&a.node)return(a.y??0)-(i.y??0);l<c?r+=1:(l>c||(r+=1),s+=1)}return 0}function na(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 oa(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=(l,c)=>{n.push({order:l,isForward:c,node:null})},r=(l,c,f)=>{n.push({order:l,isForward:c,node:f})},s=Math.abs(t.indexSequence[0]),i=jo(t.indexSequence[0]),a=e.nodes[s];r(a.order,i,s);for(let l=1;l<t.sequence.length;l+=1){let c=a,f=i;s=Math.abs(t.indexSequence[l]),i=jo(t.indexSequence[l]),a=e.nodes[s];let{order:u}=a;if(u>c.order){f||o(c.order,!0);for(let d=c.order+1;d<u;d+=1)o(d,!0);i||o(u,!0)}else if(u<c.order){f&&o(c.order,!1);for(let d=c.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 Tt(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}=St(e,i.nodeName);i.mismatches=i.mismatches.map(l=>At(l,a))}let o=n.firstNodeOffset??0,r=St(e,n.sequence[0]).sequenceLength,s=St(e,n.sequence.at(-1)).sequenceLength;n.firstNodeOffset=r-(n.finalNodeCoverLength??0),n.finalNodeCoverLength=s-o})}function At(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:Nt(e.seq)}}}var ra={A:"T",T:"A",C:"G",G:"C"};function Nt(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=ra[e.charAt(n)]??"N";return t}function ae(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 sa=20;function ia(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+sa+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 St(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&&Pt(e,-r)}function aa(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 l=Math.abs(t[a]);e.nodeOrders[l]===void 0&&(e.nodeOrders[l]=s,o=Math.min(o,s),s+=i)}return o<0&&Pt(e,-o),n}var ca=-1;function la(e){return Array.from(e,t=>t??ca)}function da(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 kt(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(l=>{l.order=void 0}),Jo(e,e.tracks[0].indexSequence);for(let l=1;l<i.length;l+=1){if(o=aa(e,i[l].indexSequence),o===null){l<e.tracks.length?Jo(e,i[l].indexSequence):(i.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=pa(i[l].indexSequence);o<t.length;){for(r=o,o+=1;o<t.length&&e.nodeOrders[t[o]]===void 0;)o+=1;if(o<t.length){n=e.nodeOrders[t[r]]+1;for(let c=r+1;c<o;c+=1)e.nodeOrders[t[c]]=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[l].indexSequence[o]>=0&&!fa(e,t[o],t[r],a))Qo(e,t[o],t[o-1],n);else if(i[l].indexSequence[r]<0||e.nodes[t[r+1]].degree<2&&e.nodeOrders[t[o]]<e.nodeOrders[t[r]]){n=e.nodeOrders[t[r]]-1;for(let c=r+1;c<o;c+=1)e.nodeOrders[t[c]]=n,s=Math.min(s,n),n-=1}}else if(i[l].indexSequence[r]>=0){n=e.nodeOrders[t[r]]+1;for(let c=r+1;c<t.length;c+=1){let f=t[c];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,n+=1)}}else{n=e.nodeOrders[t[r]]-1;for(let c=r+1;c<t.length;c+=1){let f=t[c];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,s=Math.min(s,n),n-=1)}}}}s<0&&Pt(e,-s),e.nodeOrders=da(la(e.nodeOrders)),e.nodes.forEach((l,c)=>{l.order=e.nodeOrders[c]})}function fa(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 l of e.nodes[a].successors)r[l]!==s&&(r[l]=s,i.push(l))}return!1}function ua(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function pa(e){return e.map(t=>Math.abs(t))}function Pt(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,l]=s[i];i+=1;let c=e.nodeOrders[a];c!==void 0&&c<l&&(r.get(a)??-1/0)<l&&(r.set(a,l),e.nodes[a].successors.forEach(f=>{e.nodeOrders[f]>c&&f!==n&&s.push([f,l+1])}),a!==t&&e.nodes[a].predecessors.forEach(f=>{e.nodeOrders[f]>c&&f!==n&&s.push([f,l+1])}))}r.forEach((a,l)=>{e.nodeOrders[l]=a})}function ha(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 ma(e){ga(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function ga(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,l=a.length-1;for(let c=0;c<=l;c+=1){let f=Math.abs(a[c]);if(r[f]===1)continue;let u=e.nodes[f].order,d=c>0?e.nodes[Math.abs(a[c-1])].order:void 0,p=c<l?e.nodes[Math.abs(a[c+1])].order:void 0,h=P(i[c])?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 l=0;l<a.length;l+=1)o[Math.abs(a[l])]>0&&(i[l]=_t(i[l]),a[l]=-a[l])}e.nodes.forEach((s,i)=>{o[i]>0&&(s.seq=Nt(s.seq),s.switched=!0)})}function ba(e){let t=0,n=20,o=-1,r=e.nodes.slice();r.sort($t);let s=ya(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 Rt=35;function xa(e){return e<=Rt?e/17.5:Rt/17.5*Math.sqrt(e/Rt)}function ya(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 l=i.path[a],c=i.path[a-1];l.order===c.order?l.isForward?n[l.order]+=1:o[l.order]+=1:r[l.order]=Math.max(xa(Math.abs((l.y??0)-(c.y??0))),r[l.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 wa(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},l=s===null?void 0:t.get(s);if(l===void 0){let c={node:s,tracks:[a]};e.assignments[r].push(c),s!==null&&t.set(s,c)}else l.tracks.push(a)})});for(let n=0;n<=e.maxOrder;n+=1)Ea(e,e.assignments[n],n)}function Ma(e,t,n){t.forEach(o=>{let r=0;o.tracks.forEach(s=>{let i=va(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 va(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 Ea(e,t,n){let o=0,r=new Set,s=20,i=!1,a=-1;Ma(e,t,n),t.sort(er),t.forEach(l=>{let c=l.node===null?void 0:e.nodes[l.node];c!==void 0?(i&&(s-=10),c.y=s,c.contentHeight=0,i=!1):(i?s-=25:s>20&&(s-=10),i=!0),l.tracks.sort(er),l.tracks.forEach(f=>{let{path:u,width:d}=e.tracks[f.trackID];f.trackID===a&&c===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,c!==void 0&&(c.contentHeight+=d),a=f.trackID}),s+=25}),Sa(e,t,r)}function Sa(e,t,n){let o=0,r=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let i=Ra(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 ka(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 Ra(e,t,n){let o=0;return t.forEach(r=>{r.tracks.forEach(s=>{let{type:i,path:a,width:l}=e.tracks[s.trackID];typeof s.idealY=="number"&&i!=="read"&&(o+=Math.abs(s.idealY-n-a[s.segmentID].y)*l)})}),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 $t(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 Ta(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]=Ia(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 _a(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(ta),e.tracks.forEach(r=>{let{id:s,name:i,type:a,width:l,path:c}=r,f=(g,x,M)=>{e.shapes.rectangles.push({xStart:Math.min(g,x),yStart:M,xEnd:Math.max(g,x),yEnd:M+l-1,id:s,name:i,type:a})},u=g=>g.isForward?n[g.order]:t[g.order],d=c[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<c.length;g+=1){let x=c[g-1],M=c[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:l,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 Ca(e,r,x.isForward?1:-1,y,p,w,M.order),h=y;p=w}let m=c[c.length-1],b=a==="read"?tr(e,m,r.finalNodeCoverLength??0):u(m)+(m.isForward?20:-20);f(h,b,p)})}var Oa=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,l=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)],k=l?Math.min(a(y,w),a(-w,-y)):a(y,w),T=r.get(k);T===void 0?r.set(k,{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}):(T.crossings+=g,T.lastSource!==m&&(T.count+=g,T.lastSource=m))}}let c=0;for(let m of r.values())m.crossings>c&&(c=m.crossings);let f=Ot,u=60,d=m=>c<=1?f:f+(u-f)*Math.sqrt(m/c),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?"":` (${$a(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 Aa(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=Pa(e,r),a=e.tracks.filter((f,u)=>u!==o).map(f=>Na(i,f));if(s>0&&a.push({...r,freq:s}),a.length===0)return;let{bands:l,total:c}=pr(e,a,"haplotype",t);return l.length>0?{ref:r,bands:l,total:c}:void 0}function Na(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(_t).reverse(),indexSequence:t.indexSequence.map(o=>-o).reverse()}}function Pa(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 $a({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 Ca(e,{width:t,id:n,name:o,type:r},s,i,a,l,c){let f=s===1?e.extraRight:e.extraLeft,u=10*f[c],d=i+s*(u+5),p=nr,h=Math.min(nr,t),m=Math.min(a,l),b=Math.max(a,l),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(l);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[c]+=1}function Ia(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)*Xe)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*Xe),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*Xe)});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 Q=0;function rr(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function L(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=Q,b=h>=0?r(d[0]):Q;for(let g=0;g<=h;g+=1){let x=g<h?r(d[g+1]):Q;if(b>0)g>0?(L(t,b,m),m<0&&L(t,b,-m)):p&&L(t,b,Q),g<h?(L(n,b,x),x<0&&L(n,b,-x)):p&&L(n,b,Q);else{let M=-b;g>0?(L(n,M,-m),m>0&&L(n,M,m)):p&&L(n,M,Q),g<h?(L(t,M,-x),x>0&&L(t,M,x)):p&&L(t,M,Q)}m=b,b=x}});let i=new Uint8Array(e.nodes.length);e.nodes.forEach((u,d)=>{Ba(d,t,n)&&(i[d]=1)});let a=new Int32Array(e.nodes.length),l=new Float64Array(e.nodes.length),c=new Float64Array(e.nodes.length);e.nodes.forEach((u,d)=>{if(i[d]!==1){a[d]=d,c[d]=u.sequenceLength;for(let p=d;Xa(p,t,n);)p=xe(n,p),a[p]=d,l[p]=u.sequenceLength,u.sequenceLength+=e.nodes[p].sequenceLength,u.seq+=e.nodes[p].seq,c[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-c[y]:l[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(k=>{k.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 k=e.nodes[a[w]].name,T=P(M)?lr(k):k;b.push(T),g.push({nodeName:T,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 Ba(e,t,n){let o=xe(t,e);return o!==0&&xe(n,o)!==0}function Xa(e,t,n){let o=xe(n,e);return o!==0&&xe(t,o)!==0}function Da(e,t){return t.xStart-e.xStart||e.yStart-t.yStart}function Ct(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function Fa(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,De=.8;function qa(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,De*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),l=i(d=>d.reference!==!0),c=a>De?De/a:1,f=De-a*c,u=l>f?f/l:1;return s.map((d,p)=>d*(e[p].reference?c:u))}function mr(e,t,{gapWidth:n=1/0}={}){let o=Wo(e.filter(r=>r.type===t),r=>Ct(r).join(","));return o.forEach(r=>{r.sort(Da);let s=qa(r,n),i=.5-s.reduce((a,l)=>a+l,0)/2;r.forEach((a,l)=>{let c=p=>a.xStart+(a.xEnd-a.xStart)*(a.yStart<a.yEnd?1-p:p),f=c(i);i+=s[l];let u=c(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)=>Fa(Ct(r[0]),Ct(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 l=n[i++];if(l==="M"||l==="L")r=a(),s=a(),o.push([r,s]);else if(l==="H")r=a(),o.push([r,s]);else if(l==="V")s=a(),o.push([r,s]);else if(l==="C"){let[c,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*c+y*u+w*p,x*s+M*f+y*d+w*h])}r=p,s=h}else if(l==="Q"){let[c,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*c+h*h*u,m*m*s+2*m*h*f+h*h*d])}r=u,s=d}else if(l!=="Z")throw new Error(`flattenPath: unsupported path command ${l}`)}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(I(r.name).name)??-1;return r.nodeIds.flatMap(i=>{let a=t.get(i);if(!a)return[];let l=n&&o?o(n.slot(a.name),s):-1;return[{node:a,strand:l>=0?n.strand(l):H(a.id)}]})})}function Ga(e){let t=It(e),n=(e.paths??[]).flatMap((s,i)=>{let a=t[i].map(l=>pt(l.node,l.strand));return a.length>0?[{id:i,name:s.name,sequence:a,sourceTrackID:0,type:"haplotype",...s.members?{freq:s.members.length}:{}}]:[]}),o=Ee(e),r=n.findIndex(s=>I(s.name).name===o);return r>0&&n.unshift(...n.splice(r,1)),n}function Ya(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 Wa=600,Ha=3,Ua=15;function ja(e){return Math.max(Ha,Math.min(Ua,Math.floor(Wa/Math.max(1,e))))}function Va(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 Ka(e,t,n){let o=Va(n[0]),r=new Map;for(let{sequence:l,is_secondary:c}of n)c||l.forEach((f,u)=>{let d=$(f),h=P(f)!==o.has(d)?l[u+1]:l[u-1];!t.nodeMap.has(d)&&h!==void 0&&r.set(d,$(h))});let s=new Map(e.nodes.map(l=>[l.id,Math.max(1,l.length)])),i=new Map([...r].map(([l,c])=>[c,l])),a=new Map;for(let l of i.keys()){let c=t.nodeMap.get(l);if(c!==void 0){let f=[l];for(let d=i.get(l);d!==void 0;d=i.get(d))f.push(d);f.reduce((d,p)=>d+(s.get(p)??0),0)===t.nodes[c].sequenceLength&&a.set(l,f)}}return{members:a,flipped:o}}var za={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)?za[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)),l=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)}}]}),c=(d,p,h)=>i(p,i(d,h))==="end"?H(p):xr[H(p)],f=e.edges.flatMap(d=>{let p=fn(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:c(d.from,b,p.from)},...g===void 0?{}:{to:g,toStrand:xr[c(d.to,g,p.to)]}}]}),u=new Set([...a].map(d=>o.get(d)?.name??d));return{...e,nodes:l,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=Ga(e),o=e.reads?bo(e,e.reads,t.length):[],r=o.length>0?wn:yn,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),l=ir(Ya(e),n,o,{nodeWidthOption:"compressed",trackWidth:ja(i?a:n.length),...i?{freqWidth:"linear"}:{}});if(!l)return;let c=Ka(e,l,[...n,...o]);return{layout:l,pathColors:s,members:c.members,graph:Za(e,c)}}function Lt(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 fh(e){let t=yr(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=n.bounds.minY,s={};for(let l of Lt(n))s[l.name]=Mr(l,r,l.x,l.x+l.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 Ja(e,t){let n=new Map(e.nodes.map(a=>[a.id,a])),o=zt(Lt(t),a=>a.order),r=[],s=-1/0;for(let a of[...o.keys()].sort((l,c)=>l-c)){let l=o.get(a),c=1/0,f=-1/0;for(let u of l){let d=n.get(u.name);d&&O(d)&&(c=Math.min(c,d.stable.start),f=Math.max(f,d.stable.start+d.length))}c===1/0&&(c=f=s),c<s&&(c=s,f=Math.max(s,f)),s=Math.max(s,f),r.push({order:a,x0:Math.min(...l.map(u=>u.x)),x1:Math.max(...l.map(u=>u.x+u.pixelWidth)),bp0:c,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 Qa(e){return yr(e)&&e.nodes.some(O)}function uh(e){let t=Qa(e)?wr(e):void 0;if(!t)return;let{layout:n,...o}=t,r=Ja(o.graph,n),s=new Map(r.map(l=>[l.order,l])),i=n.bounds.minY,a={};for(let l of Lt(n)){let c=s.get(l.order);a[l.name]=Mr(l,i,c.bp0,c.bp1)}return{nodePositions:a,tubeMap:{layout:n,yOffset:i,columns:r,...o},referenceAxis:!0,pixelRows:!0,extent:vr(n,i)}}function ec(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),l=n.at(-1);if(O(s)){let c=s.stable.start,f=c+s.length,u=i!==(s.stable.strand??"+"),d=l!==void 0&&a.detour.length===0;d&&!l.inverted&&!u&&l.end===c?l.end=f:d&&l.inverted&&u&&l.start===f?l.start=c:(n.push({start:c,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 Bt(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=K(e.length,r=>e[r]<=t);return o<e.length&&e[o]<n}function tc(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 nc(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],l=s.at(-1);a&&l&&(o(a.start,"walk-end"),o(l.end,"walk-end"));for(let c of s)c.inverted&&c.end-c.start>=t&&(o(c.start,"inversion"),o(c.end,"inversion"));for(let c of i)c.b<c.a?(o(c.a,"backward"),o(c.b,"backward")):Bt(c,t)||(o(c.a,"variant"),o(c.b,"variant"))}let r=e.flatMap(({runs:s,gaps:i})=>[...i.filter(a=>Bt(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,l)=>a-l);for(let[a,l]of r)Er(i,a,l)&&(s||=!n.has(a)||!n.has(l),o(a,"overlap"),o(l,"overlap"))}return n}function oc(e,t){let n=[],o=[],r=()=>{let s=o[0],i=o.at(-1);if(s&&i){let a=s.stable.start,l=i.stable.start+i.length,c=`${a}-${l}`;n.push({node:{id:`${c}+`,name:c,length:l-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 Xt(e,t,n){return Math.max(0,K(e.length,o=>t(e[o])<=n)-1)}function yh(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)=>ec(y,r[w])),i=nc(s,t,tc(n)),a=[...i.keys()].sort((y,w)=>y-w),l=oc(n,i),c=y=>Xt(l,w=>w.node.stable.start,y),f=new Map,u=new Map;for(let y of l){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(k=>k.node.id));for(let k of y.detour)u.has(k.node.id)||u.set(k.node.id,v.id)}return v},h=new Map,m=[],b=new tn,g=new Map,x=new Map;for(let{path:y,runs:w,gaps:v}of s){let S=[],k=[],T=!1,G=(R,B)=>{let C=S.at(-1);T&&C?.node===R&&C.strand===B||S.push({node:R,strand:B}),T=!0},Y=R=>{T=!1,R.detour.length>0&&(G(p(R),"+"),T=!1)},ye=R=>{(R.bp>0||R.b>R.a)&&k.push({start:R.a,end:R.b,bp:R.bp});let B=l[c(R.b>R.a?R.a:R.a-1)];for(let C of R.detour)u.has(C.node.id)||(u.set(C.node.id,B.node.id),f.get(B.node.id).push(C.node.id))};w.forEach((R,B)=>{let C=v[B];Bt(C,t)&&!Er(a,C.a,C.b)?ye(C):Y(C);let W=c(R.start),ce=c(R.end-1),ve=R.end-R.start<t;if(R.inverted&&!ve){T=!1;for(let V=ce;V>=W;V--)G(l[V].node,"-");T=!1}else{R.inverted&&k.push({start:R.start,end:R.end,bp:R.end-R.start,inverted:!0});for(let V=W;V<=ce;V++)G(l[V].node,"+")}}),Y(v.at(-1));let we=I(y.name).name,Me=0;S.forEach(({node:R,strand:B},C)=>{x.set(R.id,(x.get(R.id)??0)+1),b.add(R.name,we,y.sample??we,Me,B==="-"),Me+=R.length;let W=S[C+1];if(W){let ce=`${R.id}${B} ${W.node.id}${W.strand}`,ve=g.get(ce);ve?ve.pathIds.push(y.name):g.set(ce,{from:R.id,to:W.node.id,fromStrand:B,toStrand:W.strand,pathIds:[y.name]})}}),m.push({...y,nodeIds:S.map(R=>R.node.id)}),h.set(y.name,k)}let M=[...l.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 vh(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 Eh(e,t,n,o={}){let r=on(e,t,o);return r&&rn(r,n)}function rc(e,t,n){let o=Xt(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 sc(e,t){let n=new Map;for(let[r,s]of t)for(let i of s)te(n,I(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 Kh(e,t){let{graph:n,layout:o}=e,r=[...Et(e).values()].flat().sort((a,l)=>a.bp0-l.bp0),s=sc(n,t),i=[];for(let a of o.tracks){let l=a.name?s.get(a.name):void 0;if(l?.length){let c=new Map;for(let f of a.path)f.node!==null&&f.y!==void 0&&!c.has(f.node)&&c.set(f.node,f.y);for(let f of l){let u=rc(r,f.start,c);u&&i.push({x0:be(u,f.start),x1:be(u,f.end),y:c.get(u.index),height:a.width})}}}return i}function ic(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function zh(e,t,{x:n,y:o,width:r,darkMode:s}){if(t.length!==0){e.fillStyle=ic(s),e.beginPath();for(let i of t){let a=n(i.x0),l=Math.max(n(i.x1),a+1);if(l>=0&&a<=r){let c=o(i.y);e.rect(a,c,l-a,o(i.y+i.height)-c)}}e.fill()}}function ac(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)),l=a===void 0?void 0:t.nodes[a],c=r[i];if(l&&c?.y!==void 0){let f={readId:e.id,y:c.y,height:e.width},u=d=>fr(l,d);for(let d of s.mismatches){let p=c.isForward?d:At(d,l.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=>ac(t,e))}var Dt=24,cc=.5,lc=e=>e.bp1>e.bp0;function tm(e,t){let n=e.filter(lc);if(n.length===0){let c=e[0];return c?[{tx:c.x0,sx:t(c.bp0)}]:[]}let o=[],r=[],s=[];n.forEach((c,f)=>{o.push(c.x0,c.x1),r.push(t(c.bp0),t(c.bp1)),s.push(f===0?0:Math.min(c.x0-n[f-1].x1,Dt),0)});let i=r.at(-1)-r[0],a=s.reduce((c,f)=>c+f,0),l=a>0?Math.min(1,cc*i/a):1;return dc(r,s,l).map((c,f)=>({tx:o[f],sx:c}))}function dc(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 l={mean:i-o[a],n:1},c=s.at(-1);for(;c&&c.mean>=l.mean;){s.pop();let f=c.n+l.n;l={mean:(c.mean*c.n+l.mean*l.n)/f,n:f},c=s.at(-1)}s.push(l)}),s.flatMap(i=>Array(i.n).fill(i.mean)).map((i,a)=>i+o[a])}function nm(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+K(n-2,c=>e[c+1].tx<=t),i=e[s-1],a=e[s],l=a.tx-i.tx;return l>0?i.sx+(t-i.tx)/l*(a.sx-i.sx):i.sx}function Gt(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=Gt(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"?xo(n):t[n.id]]))}function Rr(e,t,n,o,r){let{shapes:s}=e,i=t==="haplotype",a=d=>n.get(d.id),l=d=>i&&o.has(d.id),c=[...s.rectangles,...s.verticalRectangles].filter(d=>d.type===t).map(d=>({color:a(d),id:d.id,haplotype:i,reference:l(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,l(d))),u=s.corners.filter(d=>d.type===t).map(d=>kr(d.path,a(d),d.id,i,l(d)));return{rects:c,shapes:[...f,...u]}}function fc(e){let t=new Set,n=e&&Ee(e);return e?.paths?.forEach((o,r)=>{I(o.name).name===n&&t.add(r)}),t}function uc({layout:e,pathColors:t,graph:n,columns:o}){let r=Or(e,t),s=fc(n),i=o?Dt:void 0,a=[];return e.nodes.forEach(l=>{if(l.order>=0){let c=Gt(br(l));a.push({name:l.name,commands:c,..._r(c)})}}),{bounds:e.bounds,layers:[Rr(e,"haplotype",r,s,i),Rr(e,"read",r,s,i)],nodes:a,mismatches:Sr(e)}}function Ft(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)&&te(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 pc=12,hc=.15;function mc(e){return Math.max(hc,Math.min(1,e/pc))}var gc=.55;function bc(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=>{Ft(e,p.commands,o,r)})}let l=n.darkMode?"#d0d0d0":"#000000",c=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(),Ft(e,f.commands,o,r);let u=n.nodeColors?.get(f.name);e.fillStyle=u??c,e.strokeStyle=l,e.globalAlpha=u?gc:1,e.fill(),e.globalAlpha=mc(o(f.x1)-o(f.x0)),e.stroke(),e.globalAlpha=1}Fe(e,t,n),yc(e,t.mismatches,n)}function Ar(e){return 2*Math.max(.25,Math.min(1,e.yScale))}function Fe(e,t,n){let o=n.highlightNode?t.nodes.find(r=>r.name===n.highlightNode):void 0;o&&(e.beginPath(),Ft(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,xc=6;function Yt(e){return Nr*e>=xc}function qt(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 yc(e,t,n){let{x:o,y:r,yScale:s,darkMode:i}=n;if(!Yt(s)||t.length===0)return;let a=Nr*s;e.fillStyle="grey",e.beginPath();for(let l of t)if(l.kind==="deletion"&&qt(l,n)){let c=o(l.x0),f=r(l.y);e.rect(c,f,o(l.x1)-c,r(l.y+l.height)-f)}e.fill(),e.font=`${a}px monospace`,e.textAlign="left",e.textBaseline="alphabetic",e.fillStyle=i?"#ffffff":"#000000";for(let l of t)qt(l,n)&&(l.kind==="substitution"?e.fillText(l.seq,o(l.x0)+1,r(l.y+l.height)):l.kind==="insertion"&&e.fillText("*",o(l.x)-3,r(l.y+l.height)))}function wc(e,t,n){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[l,c]=e[s];a>n!=c>n&&t<(l-i)*(n-a)/(c-a)+i&&(o=!o)}return o}function Mc(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 l of[!0,!1]){for(let c of i)if(c.reference===l&&t(c.x0)<=o&&o<=t(c.x1)&&n(c.y0)<=r&&r<=n(c.y1))return c.id;for(let c of a)if(c.reference===l&&t(c.x0)<=o&&o<=t(c.x1)&&wc(c.outline.map(([f,u])=>[t(f),n(u)]),o,r))return c.id}}}var vc=4;function Ec(e,t,n,o){let{x:r,y:s,yScale:i}=t;return Yt(i)?e.mismatches.find(a=>s(a.y)<=o&&o<=s(a.y+a.height)&&(a.kind==="insertion"?Math.abs(r(a.x)-n)<=vc:r(a.x0)<=n&&n<=r(a.x1))):void 0}var ee=JBrowseExports["@jbrowse/core/util/groupKeys"],Sc=e=>ee!=null&&e in Object(ee)?ee[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 qe=Sc("groupKeyComparator");var rg=ee&&ee.__esModule?ee.default:ee;var Ge=16;function cg(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((l,c)=>[l,a[c]??""])),name:i})}return[...r.values()]}function lg(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 dg(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 Wt(e,t){return`${e} ${t}${e===1?"":"s"}`}function Ht(e,t){let n=new Map(t.map(o=>[o.name,o[e]??""]));return(o,r)=>n.get(o)||n.get(r)||""}function Ut(e,t,{field:n,domain:o},r,s){let i=new Map;for(let a of e){let l=t(a),c=i.get(l);c?c.push(a):i.set(l,[a])}return[...i.keys()].sort(qe(o)).map(a=>{let l=i.get(a),c=new Set(l.map(s)).size;return{key:a,members:l,title:`${a||`${n}: none`} \xB7 ${Wt(c,r)}`}})}function fg(e,t,n){let o=Ht(n.field,t),r=Ut(e,a=>o(a.label,a.sample),n,"haplotype",a=>a.label),s=1,i=r.map(({key:a,members:l,title:c})=>{let f={key:a,title:c,first:s,count:l.length};return s+=l.length,f});return{rows:r.flatMap(a=>a.members),sections:i}}function ug(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)*Ge;return{rowY:o,headers:e.map((r,s)=>({...r,top:(r.first-.5)*t+s*Ge})),headersPx:e.length*Ge,rowAt(r,s){let i=0;for(let a=-1;a<e.length;a++){let l=a<0?0:e[a].first,c=a<0?Math.min(s,e[0]?.first??s):l+e[a].count,f=(a+1)*Ge,u=Math.min(c-1,Math.max(l,Math.round((r-f)/t)));Math.abs(o(u)-r)<Math.abs(o(i)-r)&&(i=u)}return i}}}function pg(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(l=>typeof l!="string"&&l.attrs["data-testid"]!=="graph-walk-reference"))]}function kc(e,t,n,o){let r=[],s=[],i=[e];for(o.add(e);i.length>0;){let a=i.pop(),l=t.get(a);if(l){r.push(l);for(let c of n.get(a)??[]){let f=t.get(c);f&&(f.stable.rank===We?s.push(f):o.has(c)||(o.add(c),i.push(c)))}}}return{members:r,anchors:s}}function Rc(e){if(new Set(e.map(a=>a.stable.refName)).size!==1||e.length<2)return;let n=[...e].sort((a,l)=>a.stable.start-l.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 Tc(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 l of n.get(i)??[])if(o.has(l)){let c=r.get(l);(c===void 0||a<c)&&(r.set(l,a),s.push(l))}}return r}function _c(e,t,n){let o=Tc(e,t,n),r=[...e].sort((l,c)=>o.get(l.id)-o.get(c.id)),s=new Map(r.map((l,c)=>[l.id,c])),i=new Map(e.map(l=>[l.id,l])),a=new Map;for(let[l,c]of r.entries()){let f=0;for(let u of n.get(c.id)??[]){let d=i.get(u);d&&s.get(u)<l&&(f=Math.max(f,a.get(u)+d.length))}a.set(c.id,f)}return{offsets:a,ordered:r}}function Oc(e){let t=new Map(e.nodes.filter(Zt).map(s=>[s.id,s])),n=ke(e),o=new Set,r=[];for(let s of t.values())if(s.stable.rank!==We&&!o.has(s.id)){let{members:i,anchors:a}=kc(s.id,t,n,o),l=Rc(a);if(l){let{offsets:c,ordered:f}=_c(i,l.entry,n);r.push({start:l.start,refSpan:l.end-l.start,nodeIds:f.map(u=>u.id),nodeOffsets:f.map(u=>c.get(u.id)),pathLength:f.reduce((u,d)=>Math.max(u,c.get(d.id)+d.length),0)})}}return r.sort((s,i)=>s.start-i.start)}var Ac=28,Pr="#4d4d4d",Nc="#5b8cc4",Pc=[Nc,"#82abd9"],Gg=["#8c8c8c","#adadad"],$c="12px sans-serif",Yg=[{field:"",label:"None"},{field:"sample",label:"A panel per sample"},{field:"walk",label:"A panel per haplotype"}],X=e=>I(e).name;function Wg(e,t,n=Pc){let o=0;return e.map(r=>X(r.name)===t?Pr:n[o++%n.length])}var Cc=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#76b7b2","#edc948","#9c755f","#ff9da7","#bab0ac"],$r="#c8c8c8";function Hg(e){let t=[...new Set(e)].filter(n=>n!=="").sort(qe());return new Map(t.map((n,o)=>[n,Cc[o]??$r]))}function Ug(e,t,n,o){return e.map(r=>{let s=X(r.name);return s===t?Pr:o.get(n(r.members?.[0]??s))??$r})}function Ic(e,t){let n=Ht(e,t);return o=>{let{sample:r,haplotype:s}=le(o);return n(`${r}#${s}`,r)}}function jg(e,t){let n=(e.paths??[]).map(l=>l.name).filter(l=>X(l)!==e.referencePath);if(t.by==="column"){let l=Ic(t.field,t.table);return Ut(n,c=>l(X(c)),t,"sample",c=>le(X(c)).sample).map(({key:c,members:f,title:u})=>({key:c,paths:f,label:u}))}let o=t.by==="sample"?l=>le(l).sample:l=>l,r=new Map;for(let l of n){let c=o(X(l)),f=r.get(c);f?f.push(l):r.set(c,[l])}let s=t.domain??[],i=new Map(s.map((l,c)=>[l,c])),a=l=>i.get(l)??s.length;return[...r].map(([l,c],f)=>({key:l,paths:c,i:f})).sort((l,c)=>a(l.key)-a(c.key)||l.i-c.i).map(({key:l,paths:c})=>({key:l,paths:c}))}function Vg(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 Kg(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=s.reduce((u,d)=>Math.min(u,d.start),1/0),a=s.reduce((u,d)=>Math.max(u,d.end),-1/0),l=o>n?(r-n)/(o-n):0,c=i+Math.min(1,Math.max(0,l))*(a-i),f=u=>c<u.start?u.start-c:c>=u.end?c-u.end+1:0;return s.reduce((u,d)=>f(d)<f(u)?d:u).id}function zg(e,t){let n=new Set,o=new Set;for(let r of e.paths??[]){let s=X(r.name);if(s!==e.referencePath){let i=r.nodeIds.includes(t);for(let a of r.members??[s])n.add(a),i&&o.add(a)}}return{here:o.size,of:n.size}}var Lc="bold 11px sans-serif",Bc=80,Xc=9;function Zg(e,t,n,{x:o,y:r,width:s}){let i=n.paths??[];if(!i.some(l=>l.members))return;let a=new Map;i.forEach((l,c)=>{X(l.name)!==n.referencePath&&a.set(c,l.members?.length??1)}),e.font=Lc,e.textAlign="left",e.textBaseline="middle",e.fillStyle="#0b1f3a";for(let l of t.layers[0]?.rects??[]){let c=a.get(l.id),f=Math.max(0,o(l.x0)),u=Math.min(s,o(l.x1)),d=r(l.y0),p=r(l.y1);c!==void 0&&u-f>=Bc&&p-d>=Xc&&e.fillText(`\xD7${c}`,f+4,(d+p)/2)}}var Dc="10px sans-serif",Fc=1e3;function Jg(e,t,{x:n,y:o,width:r}){if(!t.columns)return;let s=new Map(t.graph.nodes.map(l=>[l.id,l.length]));e.font=Dc;let i=new Map;t.layout.nodes.forEach(l=>{let c=s.get(l.name)??0,f=n(l.x),u=n(l.x+l.pixelWidth),d=A(c);if(l.order>=0&&c>=Fc&&u-f<e.measureText(d).width){let p=(o(l.y)+o(l.y+l.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:l,right:c,mid:f,count:u}of i.values()){let d=u>1?`${l} each`:l,p={x0:c+3,x1:c+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 Qg(e,t,n,{width:o,lit:r}){t.forEach((s,i)=>{let a=n?.[i];a&&(r&&Fe(e,s.picture,{...s.frame,width:o,highlightNode:a.box}),e.font=$c,e.textAlign="left",e.textBaseline="top",e.fillStyle="#c00000",e.fillText(` \xB7 ${a.here} of ${Wt(a.of,"haplotype")} here`,6+e.measureText(s.label).width,s.titleTop+4))})}function e0(e,t){let n=new Set(t),o=(e.paths??[]).filter(c=>n.has(c.name)||X(c.name)===e.referencePath),r=new Set(o.map(c=>X(c.name))),s=new Set(o.flatMap(c=>c.nodeIds)),i=e.nodes.filter(c=>s.has(c.id)),a=new Set(i.map(c=>c.name)),l=e.pathVisits?.filter(c=>r.has(c),c=>a.has(c));return{...e,nodes:i,edges:e.edges.filter(c=>s.has(c.from)&&s.has(c.to)),paths:o,anchorPaths:e.anchorPaths?.filter(c=>r.has(c.name)),pathVisits:l,reads:void 0}}function t0(e,t){let n=[],o={},r=0,s=1/0,i=-1/0;for(let{key:a,paths:l,label:c,result:f}of t){let u=f?.tubeMap,d=f?.extent;if(u&&d){let p=r+Ac,h=(d.maxY??0)-(d.minY??0);n.push({key:a,paths:l,label:c,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 qc="#daa520",Gc=1,Yc=2,Wc=4;function r0(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*Wc):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*Gc})))}function s0(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*Yc)),...e.map(o=>n(o,"#000",o.inner)))),_("rect",{width:t.width,height:t.height,fill:qc,mask:`url(#${t.id})`}))}function jt(e,t,n){let o=Math.round(t),r=Math.round(n);return`${e?`${e}:`:""}${oe(o+1)}-${oe(r)} (${A(r-o)})`}function Hc(e,t){let{field:n}=e.encoding,o=e.range?jt(e.range.contig,e.range.start,e.range.end):void 0,r=n==="progress"?o:n==="reference"&&t?jt(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,D.missing],[e.unknownBp,D.unknown],[i,ne]];return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${A(Math.abs(s-e.referenceBp))}`,gaps:a.filter(([l])=>l>0).map(([l,c])=>`, ${A(l)} ${c}`).join(""),reversed:e.reversedBp>0?`, ${A(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:r,hover:r===o?void 0:o}}function Uc(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}:${oe(s+1)}-${oe(s+n)}`}function jc(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),l=Math.min(o.end,i.bp1);l<=a||n.push({gene:o,...Be(r,a,l),exons:o.exons.filter(c=>c.end>a&&c.start<l).map(c=>Be(r,Math.max(c.start,a),Math.min(c.end,l)))})}return n}var Vt=22,Vc=4,Ye=8,Kc="11px sans-serif",zc=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(Vc,o)}function Jc(e,t,n,o,r=0){let{x:s,width:i,darkMode:a}=n,l=Math.max(1,Math.floor((o-r)/Vt)),c=[],f=a?"#e0e0e6":"#1c1c22";e.font=Kc,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=c.findIndex(S=>S+zc<=M);w===-1&&(w=Math.min(c.length,l-1)),c[w]=Math.max(c[w]??-1/0,y);let v=o-w*Vt-Ye/2;e.beginPath(),e.moveTo(p,v+.5),e.lineTo(h,v+.5),e.stroke();for(let S of d.exons){let k=s(S.x0);e.fillRect(k,v-Ye/2,Math.max(1,s(S.x1)-k),Ye)}e.fillText(b,g,v-Ye/2-2)}}var q=12,Xr=q+8,Dr=8,Cr=Dr+3,Qc=12;function el(e,{colorScheme:t,referenceRamp:n,walks:o}){let r=ot(e,n),s=[];return e.nodes.forEach((i,a)=>{if(O(i)){let l=o?o.map(c=>{let f=c.colors.get(i.id);return f===void 0?Oe:U(f)}):[U(rt(i,a,t,r))];s.push({node:i.id,bp0:i.stable.start,bp1:i.stable.start+i.length,colors:l,faded:l.includes(Oe)})}}),s.sort((i,a)=>i.bp0-a.bp0)}function Kt(e,t,n){let o=t*e.scale+e.translateX,r=n*e.scale+e.translateX;return o<r?[o,r]:[r,o]}var Ir=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,l=0;for(let c of e)a+=Math.max(0,Math.min(c.bp1,s)-c.bp0),l+=Math.max(0,c.bp1-Math.max(c.bp0,i));return t.scale>=0?{left:Math.round(a),right:Math.round(l)}:{left:Math.round(l),right:Math.round(a)}}function tl(e,t,n,o){if(o<0||o>q+Ir)return;let r,s=Ir;for(let i of e){let[a,l]=Kt(t,i.bp0,i.bp1),c=Math.max(0,a-n,n-l);c<=s&&(s=c,r=i.node)}return r}function nl(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(c=>{let[f,u]=Kt(t,c.bp0,c.bp1),d=Math.round(f*o);return{colors:c.colors,x0:f,px0:d,px1:Math.max(Math.round(u*o),d+1)}}).filter(c=>c.px1>0&&c.px0<n*o).sort((c,f)=>c.x0-f.x0),s=[],i=-1/0,a=[-1/0,-1/0];for(let{colors:c,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:c,x0:d/o,x1:u/o,tier:p}),i=u}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Qc?s:s.map(({tier:c,...f})=>f)}function Lr(e,t,n,o){let r=n>0?t:t-Cr;e.clearRect(r,0,Cr,q);let s=t+n,i=s+n*Dr;e.beginPath(),e.moveTo(s,q/2),e.lineTo(i,0),e.lineTo(i,q),e.closePath(),e.fillStyle=o,e.fill()}function Br(e,t,n){return Math.round(e*q*n/t)/n}function ol(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 c of qr(t,n,o,i)){let{tier:f}=c,u=f!==void 0&&c.colors.length===1,d=u?2:c.colors.length;c.colors.forEach((p,h)=>{let m=u?f:h,b=Br(m,d,i);e.fillStyle=p,e.fillRect(c.x0,b,c.x1-c.x0,Br(m+1,d,i)-b)})}let l=Fr(t,n,o);if(l.left>0&&Lr(e,0,1,a),l.right>0&&Lr(e,o,-1,a),r){let[c,f]=Kt(n,r.start,r.end),u=Math.max(f-c,3),d=(c+f)/2-u/2;e.strokeStyle=a,e.lineWidth=1.5,e.strokeRect(d,.75,u,q-1.5),r.anchor&&(e.beginPath(),e.moveTo(d+u/2,q),e.lineTo(r.anchor.x,r.anchor.y),e.lineWidth=1,e.stroke())}}function rl(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function sl(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 l=o-1;l>=0;l--){let c=Math.abs(e[a]-t[l])+r[a+1][l+1],f=n-a>o-l?r[a+1][l]:1/0,u=o-l>n-a?r[a][l+1]:1/0;r[a][l]=Math.min(c,f,u),s[a][l]=r[a][l]===c}let i=new Array(n).fill(void 0);for(let a=0,l=0;a<n&&l<o;)s[a][l]?i[a++]=l++:n-a>o-l?a++:l++;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 il(e,t){return{...t,agrees:e.complete&&Yr(t)?rl(e.bp,t.bp):void 0}}function al(e,t){let n=new Map,o=new Set,r=Gr(e,i=>i.bp),s=(i,a)=>{let l=[[i.filter(c=>c.item.complete),a.filter(Yr)],[i,a]];for(let[c,f]of l){let u=c.filter(p=>!n.has(p.i)),d=Gr(f.filter(p=>!o.has(p)),p=>p.bp);sl(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,il(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 ex(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,l]of al(s,i))n.set(s[a],l)}return e.map(r=>({...r,call:n.get(r)}))}var Wr=mo.box(typeof devicePixelRatio>"u"?1:devicePixelRatio);function Hr(){matchMedia(`(resolution: ${devicePixelRatio}dppx)`).addEventListener("change",()=>{go(()=>{Wr.set(devicePixelRatio)}),Hr()},{once:!0})}typeof matchMedia=="function"&&Hr();function ix(e=0,t=0){return Wr.get(),re(e,t)}export{Su as a,ku as b,Ru as c,Tu as d,Oc as e,js as f,Vs as g,It as h,yr as i,fh as j,Qa as k,uh as l,vh as m,Eh as n,Zd as o,$e as p,Ne as q,st as r,Pe as s,jr as t,Vr as u,Kr as v,zr as w,Gl as x,z as y,Wn as z,pe as A,at as B,ms as C,Yl as D,Wl as E,bs as F,xs as G,ys as H,ws as I,Ms as J,lf as K,df as L,ff as M,uf as N,pf as O,hf as P,mf as Q,gf as R,bf as S,xf as T,yf as U,wf as V,Mf as W,vf as X,Ef as Y,Sf as Z,kf as _,Rf as $,Tf as aa,Es as ba,_f as ca,Of as da,Af as ea,Nf as fa,Pf as ga,$f as ha,Cf as ia,Qs as ja,ti as ka,ni as la,oi as ma,yh as na,_ as oa,ri as pa,si as qa,he as ra,Mt as sa,Ie as ta,ko as ua,Ro as va,me as wa,Oo as xa,xt as ya,ui as za,pi as Aa,No as Ba,bi as Ca,$o as Da,Co as Ea,vt as Fa,xi as Ga,yi as Ha,Lo as Ia,ge as Ja,Et as Ka,Mi as La,Xo as Ma,_i as Na,Oi as Oa,Ni as Pa,Pi as Qa,Yo as Ra,Kh as Sa,ic as Ta,zh as Ua,tm as Va,nm as Wa,uc as Xa,bc as Ya,Fe as Za,Yt as _a,qt as $a,Mc as ab,Ec as bb,Ge as cb,cg as db,lg as eb,dg as fb,fg as gb,ug as hb,pg as ib,Ac as jb,Pr as kb,Nc as lb,Gg as mb,$c as nb,Yg as ob,Wg as pb,$r as qb,Hg as rb,Ug as sb,Ic as tb,jg as ub,Vg as vb,Kg as wb,zg as xb,Zg as yb,Jg as zb,Qg as Ab,e0 as Bb,t0 as Cb,Lf as Db,ft as Eb,qf as Fb,qc as Gb,r0 as Hb,s0 as Ib,Jf as Jb,lo as Kb,Qf as Lb,fo as Mb,ut as Nb,uo as Ob,po as Pb,Ws as Qb,jt as Rb,Hc as Sb,Uc as Tb,jc as Ub,Vt as Vb,Zc as Wb,Jc as Xb,Xr as Yb,el as Zb,Fr as _b,tl as $b,nl as ac,ol as bc,ex as cc,ix as dc};
3
+ //# sourceMappingURL=chunk-BCOXRUNQ.js.map