jbrowse-plugin-graphgenomeviewer 6.3.1 → 6.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 (77) hide show
  1. package/README.md +2 -2
  2. package/dist/chunks/AddTrackWorkflow-ANWIWCO6.js +2 -0
  3. package/dist/chunks/{AddTrackWorkflow-F5YBOJ3E.js.map → AddTrackWorkflow-ANWIWCO6.js.map} +1 -1
  4. package/dist/chunks/ChooseSamplesDialog-OYAB355I.js +2 -0
  5. package/dist/chunks/{ChooseSamplesDialog-KVTDIA4A.js.map → ChooseSamplesDialog-OYAB355I.js.map} +1 -1
  6. package/dist/chunks/ChooseWalksDialog-HJE4CAKU.js +2 -0
  7. package/dist/chunks/{ChooseWalksDialog-L6QKOT7M.js.map → ChooseWalksDialog-HJE4CAKU.js.map} +1 -1
  8. package/dist/chunks/{GraphGenomeView-VIKLXNQD.js → GraphGenomeView-ZB4ED45M.js} +2 -2
  9. package/dist/chunks/{GraphGenomeView-VIKLXNQD.js.map → GraphGenomeView-ZB4ED45M.js.map} +1 -1
  10. package/dist/chunks/GraphTrackSettingsDialog-UPAINCUZ.js +4 -0
  11. package/dist/chunks/{GraphTrackSettingsDialog-MRMSH2FO.js.map → GraphTrackSettingsDialog-UPAINCUZ.js.map} +1 -1
  12. package/dist/chunks/HighlightColorDialog-LXT72W7R.js +2 -0
  13. package/dist/chunks/{HighlightColorDialog-SABW5OMB.js.map → HighlightColorDialog-LXT72W7R.js.map} +1 -1
  14. package/dist/chunks/LinearGraphDisplay-TQX7ZJZF.js +2 -0
  15. package/dist/chunks/{LinearGraphDisplay-AHCKWNFJ.js.map → LinearGraphDisplay-TQX7ZJZF.js.map} +1 -1
  16. package/dist/chunks/TrackWarningsDialog-YL2UP35Z.js +2 -0
  17. package/dist/chunks/{TrackWarningsDialog-HPHM5S7U.js.map → TrackWarningsDialog-YL2UP35Z.js.map} +1 -1
  18. package/dist/chunks/chunk-64LZZURD.js +2 -0
  19. package/dist/chunks/chunk-64LZZURD.js.map +7 -0
  20. package/dist/chunks/chunk-7KFSWOWX.js +3 -0
  21. package/dist/chunks/chunk-7KFSWOWX.js.map +7 -0
  22. package/dist/chunks/chunk-GB7CF6Z2.js +2 -0
  23. package/dist/chunks/chunk-GB7CF6Z2.js.map +7 -0
  24. package/dist/chunks/chunk-GXQ7NYB3.js +2 -0
  25. package/dist/chunks/chunk-GXQ7NYB3.js.map +7 -0
  26. package/dist/chunks/chunk-JC7I7V6M.js +2 -0
  27. package/dist/chunks/chunk-JC7I7V6M.js.map +7 -0
  28. package/dist/chunks/chunk-NXZT63HN.js +2 -0
  29. package/dist/chunks/chunk-NXZT63HN.js.map +7 -0
  30. package/dist/chunks/chunk-OTI5X5W7.js +2 -0
  31. package/dist/chunks/chunk-OTI5X5W7.js.map +7 -0
  32. package/dist/chunks/chunk-OU6VYHKB.js +2 -0
  33. package/dist/chunks/chunk-OU6VYHKB.js.map +7 -0
  34. package/dist/chunks/chunk-PLV6SE4Y.js +2 -0
  35. package/dist/chunks/chunk-PLV6SE4Y.js.map +7 -0
  36. package/dist/chunks/renderSvg-J7L374ND.js +2 -0
  37. package/dist/chunks/renderSvg-J7L374ND.js.map +7 -0
  38. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js +6 -6
  39. package/dist/jbrowse-plugin-graphgenomeviewer.esm.js.map +4 -4
  40. package/package.json +2 -2
  41. package/src/GraphComputeLayout.ts +2 -9
  42. package/src/GraphGenomeView/components/FacetPanels.tsx +2 -0
  43. package/src/GraphGenomeView/components/GraphCanvas.tsx +2 -0
  44. package/src/GraphGenomeView/components/GraphSettingsDialog.tsx +23 -3
  45. package/src/GraphGenomeView/components/PaneSvg.tsx +828 -0
  46. package/src/GraphGenomeView/components/ReferenceStripOverlay.tsx +23 -5
  47. package/src/GraphGenomeView/components/TubeMapOverlay.tsx +46 -35
  48. package/src/GraphGenomeView/components/usePaneGestures.ts +1 -0
  49. package/src/GraphGenomeView/launchKeys.test.ts +1 -0
  50. package/src/GraphGenomeView/model.test.ts +67 -0
  51. package/src/GraphGenomeView/pane/fitViews.ts +1 -0
  52. package/src/GraphGenomeView/pane/graphViews.ts +4 -0
  53. package/src/GraphGenomeView/pane/loadActions.ts +6 -2
  54. package/src/GraphGenomeView/pane/paneBase.ts +4 -0
  55. package/src/GraphGenomeView/pane/settingActions.ts +34 -12
  56. package/src/GraphGenomeView/viewModel.ts +16 -0
  57. package/src/LinearGraphDisplay/LinearGraphDisplay.test.ts +43 -0
  58. package/src/LinearGraphDisplay/model.ts +24 -1
  59. package/src/LinearGraphDisplay/renderSvg.tsx +27 -0
  60. package/src/version.ts +1 -1
  61. package/dist/chunks/AddTrackWorkflow-F5YBOJ3E.js +0 -2
  62. package/dist/chunks/ChooseSamplesDialog-KVTDIA4A.js +0 -2
  63. package/dist/chunks/ChooseWalksDialog-L6QKOT7M.js +0 -2
  64. package/dist/chunks/GraphTrackSettingsDialog-MRMSH2FO.js +0 -4
  65. package/dist/chunks/HighlightColorDialog-SABW5OMB.js +0 -2
  66. package/dist/chunks/LinearGraphDisplay-AHCKWNFJ.js +0 -2
  67. package/dist/chunks/TrackWarningsDialog-HPHM5S7U.js +0 -2
  68. package/dist/chunks/chunk-2SL675KP.js +0 -3
  69. package/dist/chunks/chunk-2SL675KP.js.map +0 -7
  70. package/dist/chunks/chunk-A6GKF63C.js +0 -2
  71. package/dist/chunks/chunk-A6GKF63C.js.map +0 -7
  72. package/dist/chunks/chunk-B7KMMGFB.js +0 -2
  73. package/dist/chunks/chunk-B7KMMGFB.js.map +0 -7
  74. package/dist/chunks/chunk-GMSOU6VO.js +0 -2
  75. package/dist/chunks/chunk-GMSOU6VO.js.map +0 -7
  76. package/dist/chunks/chunk-TYJTJGPO.js +0 -2
  77. package/dist/chunks/chunk-TYJTJGPO.js.map +0 -7
@@ -0,0 +1,2 @@
1
+ import{c as I,d as Ze,e as j,f as Je,g as V,h as Q,i as Z,k as he,l as pe}from"./chunk-WTOQRUK2.js";import{A as fe,B as ue,C as z,a as G,b as Ke,c as F,d as ze,e as je,f as U,h as Ve,j as Qe,l as le,m as K,x as de,y as P,z as k}from"./chunk-B7GF3TC3.js";import{d as et}from"./chunk-KRXALLQG.js";import{c as Ue}from"./chunk-EHV7EUMI.js";import{c as C}from"./chunk-MYJYGSOH.js";import{a as Ge,b as Hn}from"./chunk-FY3BTKY4.js";var ar=Ge((yc,Wt)=>{Wt.exports=JBrowseExports.mobx});var Gt=Ge((bc,Ht)=>{Ht.exports=JBrowseExports["@jbrowse/core/util/groupKeys"]});function Gn(e){return e.id.endsWith("-")?"-":"+"}function Un(e,t){return t===Gn(e)?e.id:`-${e.id}`}function Kn(e,t){let n=e.map(()=>{}),r=0,o=0;for(;o<e.length&&e[o]!==void 0;o++)n[o]=r,r+=e[o];let s=t;for(let a=e.length-1;a>o&&e[a]!==void 0;a--)s-=e[a],n[a]=s;return n}function zn(e,t){let n=e.path.map(()=>[]);if(e.cs===void 0)return n;let r=Kn(t,e.pathLength),o=(i,c=!1)=>{for(let l=0;l<r.length;l++){let d=r[l],f=t[l];if(d!==void 0&&f!==void 0&&d<=i&&(i<d+f||c&&i===d+f))return{s:l,local:i-d,room:d+f-i}}},s=(i,c)=>{let l=n[i],d=l.at(-1);c.type==="substitution"&&d?.type==="substitution"&&d.pos+d.seq.length===c.pos?d.seq+=c.seq:l.push(c)},a=e.pathStart;for(let i of Ue(e.cs))if(i.op==="match")a+=i.length;else if(i.op==="substitution"){let c=o(a);c&&s(c.s,{type:"substitution",pos:c.local,seq:i.seq}),a+=1}else if(i.op==="insertion"){let c=o(a,a===e.pathEnd);c&&s(c.s,{type:"insertion",pos:c.local,seq:i.seq})}else{let c=i.length;for(;c>0;){let l=o(a),d=l?Math.min(c,l.room):c;l&&s(l.s,{type:"deletion",pos:l.local,length:d}),a+=d,c-=d}}return n}function Us(e,t,n){let r=new Map(e.nodes.map(s=>[s.name,s])),o=[];for(let s of t){let a=s.path.map(d=>r.get(d.name)),i=a.flatMap((d,f)=>d?[f]:[]),c=i[0],l=i.at(-1);if(c!==void 0&&l!==void 0){let d=zn(s,a.map(m=>m?.length)),f=i.map(m=>Un(a[m],s.path[m].strand)),u=a[l].length;o.push({id:n+o.length,name:s.name,type:"read",sourceTrackID:1,sequence:f,sequenceNew:i.map((m,p)=>({nodeName:f[p],mismatches:d[m]})),firstNodeOffset:c===0?s.pathStart:0,finalNodeCoverLength:l===s.path.length-1?u-(s.pathLength-s.pathEnd):u,mapping_quality:s.mappingQuality===255?0:s.mappingQuality,is_secondary:s.secondary,is_reverse:s.strand==="-"})}}return o}var jn=["#6baed6","#4292c6","#2171b5","#08519c"],Vn=["#fb6a4a","#ef3b2c","#cb181d","#a50f15"];function tt(e){let t=e.is_reverse?Vn:jn;return t[e.id%t.length]}var J=8,me=34,ee=12,Qn=60;function Zn({count:e,bounds:t,pixelRows:n,width:r,room:o,columns:s}){function a(c){let l=Math.ceil(e/c),d=Math.floor((r-(c-1)*J)/c),f=(o-l*me-(l-1)*J)/l,u=(d-2*ee)/t.w,m=t.h>0?(f-2*ee)/t.h:1/0,p=n?u:Math.min(u,m),h=n?t.h:t.h*p,g=Math.floor(Math.max(Qn,Math.min(h+2*ee,f)));return{columns:c,width:d,height:g,scale:p,total:l*(g+me)+(l-1)*J}}if(s!==void 0)return a(Math.max(1,Math.min(e,Math.round(s))));let i=a(1);for(let c=2;c<=e;c++){let l=a(c);l.scale>i.scale&&(i=l)}return i}var Jn=[{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 eo(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 nt(e,t){let n=new Map(t.map((o,s)=>[o,s])),r=o=>n.get(o)??t.length;return e.map((o,s)=>({name:o,i:s})).sort((o,s)=>r(o.name)-r(s.name)||o.i-s.i).map(({name:o})=>o)}function to(e,t,n=[]){let r=nt(e,n),o={columns:void 0,count:e.length,cells:e.map(l=>r.indexOf(l))};if(t==="walk")return o;let s=e.map(l=>{let[d,f,u]=l.split("#"),m=Number(f);return u!==void 0&&Number.isInteger(m)&&m>=0?{sample:d,column:Math.max(0,m-1)}:void 0}),a=nt([...new Set(s.flatMap(l=>l?[l.sample]:[]))],n),i=Math.max(1,...s.map(l=>l?l.column+1:1)),c=s.map(l=>l?a.indexOf(l.sample)*i+l.column:-1);return c.includes(-1)||new Set(c).size<c.length?o:{columns:i,count:a.length*i,cells:c}}var no=10;function oo(e,t){let n=e.end-e.start,r=e.longestAlleleLength-e.shortestAlleleLength;return t.find(o=>r<=no*(o.end-o.start)&&(n===0?o.start<=e.start&&e.start<=o.end:Math.min(e.end,o.end)-Math.max(e.start,o.start)>=n/2))}var ro=40;function $(e){return e>=1e4?`${(e/1e3).toFixed(0)} kb`:e>=1e3?`${(e/1e3).toFixed(1)} kb`:`${e} bp`}function so(e,t){let n=$(e),r=$(t),o=r.slice(r.indexOf(" "));return n.endsWith(o)?`${n.slice(0,-o.length)}\u2013${r}`:`${n}\u2013${r}`}function ot(e){return e>=et?"\u22652.1B routes":e>=1e5?`${(e/1e3).toFixed(0)}k routes`:`${e} routes`}function io(e,t=[]){let n=ao(e,t);return e.partial?{...n,label:`${n.label}, partial`}:n}function ao(e,t){let n=e.end-e.start,{shortestAlleleLength:r,longestAlleleLength:o,pathCount:s,segmentCount:a,inversion:i}=e,c=so(r,o);if(a>=ro)return{kind:"superbubble",label:`${c} superbubble, ${a} segments, ${ot(s)}${i?", inv":""}`};if(i)return{kind:"inversion",label:`${$(o)} inv`};let l=o!==r?oo(e,t):void 0;if(l){let f=l.name?` (${l.name})`:"";return{kind:"repeat",label:`${c} repeat array${f}, ${ot(s)}`}}let d=s>2?`, ${s} alleles`:"";return r===o&&r===n?n<=1?{kind:"snp",label:"SNP"}:{kind:"substitution",label:`${$(n)} sub`}:n===0||r===n?{kind:"insertion",label:`\u2264${$(o-n)} ins${d}`}:o===n?{kind:"deletion",label:`${$(n-r)} del${d}`}:{kind:"complex",label:`${$(n)} ref \u2192 ${c}, ${s} alleles`}}var co={snp:"#5b6b7a",substitution:"#5b6b7a",insertion:"#2f8fd6",deletion:"#c94040",inversion:"#e07b00",repeat:"#8e3fbf",superbubble:"#8e3fbf",complex:"#8e3fbf"},lo={snp:"SNP",substitution:"substitution",insertion:"insertion",deletion:"deletion",inversion:"inversion",repeat:"repeat array",superbubble:"superbubble",complex:"site"};function fo(e){return e.segments.split(",").filter(Boolean)}function te(e){return`hsl(${e}, 70%, 50%)`}function ge(e,t){let n=(e-t.start)/(t.end-t.start);return Math.max(0,Math.min(1,n))*Q}var uo=30;function rt({start:e,bp:t,reversed:n},r){let o=ge(e,r),s=ge(e+t,r);if(s-o<1)return[(o+s)/2];let a=Math.ceil((s-o)/uo);return Array.from({length:a+1},(i,c)=>ge(e+t*(n?a-c:c)/a,r))}var xe=Array.from({length:7},(e,t)=>({offset:t/6,color:te(t/6*Q)})),st=`linear-gradient(to right, ${xe.map(e=>`${e.color} ${e.offset*100}%`).join(", ")})`;function R(e,t={},...n){return{tag:e,attrs:t,children:n.filter(r=>!!r||r==="")}}function it(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function ho(e){return it(e).replaceAll('"',"&quot;")}function po(e){if(typeof e=="string")return it(e);let t=Object.entries(e.attrs).filter(([,n])=>n!==void 0).map(([n,r])=>` ${n}="${ho(String(r))}"`).join("");return`<${e.tag}${t}>${e.children.map(po).join("")}</${e.tag}>`}var we="#2f8fd6",Ee="#8e3fbf",Se="#bdbdbd",Y="#1c1c22",ve=12,Re=4,be=12,mo=6,go=3;function X(e){return`${(e/1e3).toFixed(e<1e4?1:0)} kb`}function at(e,t){return t?` \u2248 ${Math.round(e/t)} units`:""}function ct(e,t,n,r){let{bp:o,gapBp:s,complete:a}=e;if(!t)return`${X(o)}${at(o,n)}`;let i=o-t.bp,c=i===0?"":` (${i>0?"+":"\u2212"}${X(Math.abs(i))})`,l=s>0?` \xB7 ${X(s)} outside the cut`:"",d=r?` \xB7 called ${X(r.bp)}${r.spanningReads===0?" \xB7 no spanning read":""}`:"";return`${X(o)}${at(o,n)}${c}${l}${a?"":" \xB7 partial walk"}${d}`}function lt(e,t,n){let r=t+6;return r+e.length*F<n?{x:r,anchor:"start",halo:!1}:{x:t-6,anchor:"end",halo:!0}}function dt(e,t,n){if(t*n<go)return[];let r=[];for(let o=t;o<e;o+=t)r.push(o);return r}function ft(e,t){if(e.gap)return{fill:Se};if(!t)return{fill:e.onReference?we:Ee};if(e.referenceStart===void 0)return{fill:Z};let n=rt({...e,start:e.referenceStart},t);return n.length===1?{fill:te(n[0])}:{stops:n.map(te)}}function Me(e,t,n){return e.reversed?{start:e.start-n,end:e.start-t}:{start:t-e.start,end:n-e.start}}function xo(e,t){return e.reversed?{start:e.start-t,end:e.start}:{start:e.start,end:e.start+t}}function yo(e,t){let n=new Map;for(let r of e){let o=t.get(r.name);if(!r.axis||!o)continue;let s=r.axis,a=({start:i,end:c})=>({start:Math.max(0,i),end:Math.min(r.bp,c)});n.set(r.name,o.map(i=>({name:i.name,...a(Me(s,i.start,i.end)),exons:i.exons.map(c=>a(Me(s,c.start,c.end))).filter(c=>c.end>c.start)})).filter(i=>i.end>i.start).sort((i,c)=>i.start-c.start))}return n}var bo=9,Mo=5.2,wo=8,ut=(e,t)=>Math.min(2,(e-t)/2-1);function ht(e,t){return ut(e,t)>=1}function pt(e,t,n,{rowPx:r=G,barPx:o=ve}={}){if(!ht(r,o))return[];let s=ut(r,o),a=e.map(l=>{let d=t(l.start);return{g:l,x:d,w:Math.max(2,t(l.end)-d)}}),i=[],c=new Set((o>=wo?[...a]:[]).sort((l,d)=>l.w-d.w).filter(({g:l,x:d,w:f})=>{let u=l.name.length*Mo/2,m=[d+f/2-u,d+f/2+u];return 2*u>f+6||i.some(([p,h])=>m[0]<h+2&&m[1]>p-2)?!1:(i.push(m),!0)}));return a.map(l=>({name:l.g.name,x:l.x,y:n-o/2-s,w:l.w,h:o+2*s,exons:l.g.exons.map(d=>({x:t(d.start),w:Math.max(1,t(d.end)-t(d.start))})),label:c.has(l)?{x:l.x+l.w/2,y:n+3,size:bo}:void 0}))}var ye=e=>`${e} row${e===1?"":"s"}`;function Eo(e,t={}){let n=[{swatch:t.ramp?{kind:"bar",fill:t.rampCss??st,ramp:!0}:{kind:"bar",fill:we},label:`on ${e.reference.label}'s path`},{swatch:{kind:"bar",fill:t.ramp?Z:Ee},label:`off ${e.reference.label}'s path`}];return[e.reference,...e.rows].some(r=>r.gapBp>0)&&n.push({swatch:{kind:"gap",fill:Se},label:"walked outside the cut"}),t.genes?.crowded?n.push({swatch:{kind:"gene"},label:"genes left out: too many rows to box them in",note:!0}):t.genes&&(n.push({swatch:{kind:"gene"},label:"genes, each row's own annotation"}),t.genes.untracked&&n.push({swatch:{kind:"gene"},label:`no gene track for ${ye(t.genes.untracked)}`,note:!0}),t.genes.unplaced&&n.push({swatch:{kind:"gene"},label:`no contig coordinates for ${ye(t.genes.unplaced)}`,note:!0}),t.genes.unread&&n.push({swatch:{kind:"gene"},label:`genes not read for the last ${ye(t.genes.unread)}`,note:!0})),n}var mt="#111",gt="#9e9e9e",_e="#c62828";function xt(e){return e.agrees===!1?_e:e.spanningReads===0?gt:mt}function So(e,t,n,r="walk-key"){let o=0,s=e.flatMap((a,i)=>{let c=`${r}-ramp-${i}`,l=!a.note&&a.swatch.kind==="bar"&&a.swatch.ramp?R("linearGradient",{id:c},...xe.map(u=>R("stop",{offset:u.offset,"stop-color":u.color}))):void 0,d=a.note?void 0:a.swatch.kind==="gene"?R("rect",{x:o,y:5,width:18,height:8,fill:"none",stroke:Y,"stroke-width":1.5}):R("rect",{x:o,y:a.swatch.kind==="gap"?7:5,width:18,height:a.swatch.kind==="gap"?Re:8,rx:2,fill:l?`url(#${c})`:a.swatch.fill}),f=R("text",{x:a.note?o:o+23,y:13,"font-style":a.note?"italic":void 0,fill:a.note?"#666":void 0},a.label);return o+=(a.note?0:23)+a.label.length*F+16,[l,d,f].filter(u=>u!==void 0)});return{width:o,tree:R("g",{transform:`translate(${t} ${n})`,"font-family":"Helvetica, Arial, sans-serif","font-size":11},...s)}}function vo(e,t,n=0){let r=t/Math.max(1,e),o=Math.max(n,Math.min(G,r>=1?Math.floor(r):r));return{rowPx:o,barPx:o<=3?o:Math.max(3,Math.round(o*.6)),labelled:o>=be,readouts:o>=be}}function yt(e,t){let n=1/t,r=[],o=[],s=()=>{if(o.length!==0){if(o.length===1)r.push(o[0]);else{let i=0,c=0;for(let f of o)f.onReference?i+=f.bp:c+=f.bp;let l=i>=c,d=o.find(f=>f.onReference===l);r.push({start:o[0].start,bp:i+c,onReference:l,referenceStart:l?d.referenceStart:void 0,...d.reversed?{reversed:!0}:{}})}o=[]}},a=0;for(let i of e){if(i.gap||i.bp>=n){s(),a=0,r.push(i);continue}o.push(i),a+=i.bp,a>=n&&(s(),a=0)}return s(),r}function Ro(e,t,n){return R("g",{class:"row-gene","data-testid":"graph-walk-gene"},R("title",{},e.name),...e.exons.map(r=>R("rect",{x:r.x,y:t-n/2,width:r.w,height:n,fill:Y,opacity:.35})),R("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:Y,"stroke-width":1.5}),e.label&&R("text",{x:e.label.x,y:e.label.y,"font-family":"sans-serif","font-size":e.label.size,"font-weight":600,"text-anchor":"middle",fill:Y,stroke:"white","stroke-width":2.5,"paint-order":"stroke"},e.name))}function _o(e,t,n={}){let r=h=>h*t.scaleX+t.translateX,o=t.rowPx??G,s=t.barPx??ve,a=Math.min(3,Math.max(0,(o-s)/2)),i=h=>h*o*t.scaleY+t.translateY,{origin:c,unit:l,reference:d,rows:f}=e,u=h=>r(c+h),m=n.idPrefix??"walkrow",p=(h,g)=>{let x=i(g);if(x<-s||x>t.height+s)return;let M=yt(h.runs,t.scaleX).flatMap(v=>{let _=ft(v,n.ramp),H=v.gap?Math.min(Re,s):s,D=`${m}-${g}-${v.start}`,He=R("rect",{x:u(v.start),y:x-H/2,width:Math.max(1,v.bp*t.scaleX),height:H,fill:"stops"in _?`url(#${D})`:_.fill});return"stops"in _?[R("linearGradient",{id:D},..._.stops.map((Yn,Wn)=>R("stop",{offset:Wn/(_.stops.length-1),"stop-color":Yn}))),He]:[He]}),w=l&&s>=mo?dt(h.bp,l,t.scaleX).map(v=>R("line",{x1:u(v),x2:u(v),y1:x-s/2,y2:x+s/2,stroke:"white","stroke-width":1})):[],{call:b}=h,E=ct(h,g===0?void 0:d,l,b),y=lt(E,u(h.bp),t.width),S=t.readouts??!0;return R("g",{"data-testid":g===0?"graph-walk-reference":"graph-walk-row"},...M,...w,...pt(n.rowGenes?.get(h.name)??[],u,x,{rowPx:o,barPx:s}).map(v=>Ro(v,x,s)),b&&R("rect",{"data-testid":"graph-walk-call",x:u(b.bp)-1,y:x-s/2-a,width:2,height:s+2*a,fill:xt(b)}),S&&R("text",{x:y.x,y:x+4,"font-family":"sans-serif","font-size":11,fill:b?.agrees===!1?_e:"#333",stroke:y.halo?"white":void 0,"stroke-width":y.halo?3:void 0,"paint-order":"stroke","text-anchor":y.anchor},E))};return R("g",{},...[d,...f].map(p))}var wt=2,ne=8192;function Et(){return typeof devicePixelRatio>"u"?1:Math.min(devicePixelRatio,wt)}var bt=!1;function Mt(e,t,n){let r=Math.round(e*t);return r>ne?(bt||(bt=!0,console.warn(`Canvas ${n} ${r}px exceeds the safe limit ${ne}px and was clamped`)),ne):r}function Ne(e,t,n){let r=Et(),o=Mt(t,r,"width"),s=Mt(n,r,"height");(e.width!==o||e.height!==s)&&(e.width=o,e.height=s);let a=`${t}px`,i=`${n}px`;e.style.width!==a&&(e.style.width=a),e.style.height!==i&&(e.style.height=i)}var pi=class{constructor(e){this.transform=null,this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null,this.highlightFactor=1;let t=e.getContext("2d");if(!t)throw new Error("Canvas 2D context not available");this.canvas=e,this.ctx=t}setErrorHandler(e){}releaseOffscreenTargets(){}resize(e,t){Ne(this.canvas,e,t)}uploadGeometry(e){this.batch=e,this.highlightedEdge=null}setNodeHighlights(e){this.nodeHighlights=e}setEdgeHighlight(e,t){this.highlightedEdge=e,this.highlightFactor=t}updateTransform(e){this.transform=e}render(e){if(!this.transform)return;let n=this.ctx,{width:r,height:o}=n.canvas;e[3]<1&&n.clearRect(0,0,r,o),n.fillStyle=Ze([e[0],e[1],e[2]],e[3]),n.fillRect(0,0,r,o);let s=this.batch;s&&(n.lineCap="round",n.lineJoin="round",this.renderEdges(s),this.renderNodes(s),this.renderArrows(s))}renderEdges(e){let t=this.transform,n=this.ctx,r=this.highlightedEdge===null?void 0:e.edgeCurveRuns.get(this.highlightedEdge);for(let{color:o,items:s}of Oe(e.edgeCurves,(a,i)=>({color:oe(r,i)?j(a.color,this.highlightFactor):a.color,weight:a.thickness,last:oe(r,i)}))){n.strokeStyle=I(o),n.lineWidth=s[0].thickness*2*t.dpr,n.beginPath();for(let a of s){let i=a.curves[0];n.moveTo(i.x0*t.scaleX+t.translateX,i.y0*t.scaleY+t.translateY);for(let c of a.curves)n.bezierCurveTo(c.cx0*t.scaleX+t.translateX,c.cy0*t.scaleY+t.translateY,c.cx1*t.scaleX+t.translateX,c.cy1*t.scaleY+t.translateY,c.x1*t.scaleX+t.translateX,c.y1*t.scaleY+t.translateY)}n.stroke()}}renderNodes(e){let t=this.transform,n=this.ctx,r=new Map;for(let[o,s]of this.nodeHighlights){let a=e.nodeStrokeRuns.get(o);if(a)for(let i=a.start;i<a.start+a.count;i++)r.set(i,s)}for(let{color:o,items:s}of Oe(e.nodeStrokes,(a,i)=>{let c=r.get(i);return{color:c===void 0?a.color:j(a.color,c),weight:a.thickness,last:c!==void 0}})){n.strokeStyle=I(o),n.lineWidth=s[0].thickness*2*t.dpr,n.beginPath();for(let a of s){let i=a.points[0];n.moveTo(i.x*t.scaleX+t.translateX,i.y*t.scaleY+t.translateY);for(let c=1,l=a.points.length;c<l;c++){let d=a.points[c];n.lineTo(d.x*t.scaleX+t.translateX,d.y*t.scaleY+t.translateY)}}n.stroke()}}renderArrows(e){let t=this.transform,n=this.ctx,r=this.highlightedEdge===null?void 0:e.arrowRuns.get(this.highlightedEdge);for(let{color:o,items:s}of Oe(e.arrows,(a,i)=>({color:oe(r,i)?j(a.color,this.highlightFactor):a.color,weight:0,last:oe(r,i)}))){n.fillStyle=I(o),n.beginPath();for(let a of s){let[i,c,l,d]=Oo(a,t);n.moveTo(i.x,i.y),n.lineTo(c.x,c.y),n.lineTo(l.x,l.y),n.lineTo(d.x,d.y),n.closePath()}n.fill()}}dispose(){this.batch=null,this.nodeHighlights=new Map,this.highlightedEdge=null}},No=.25;function Oo(e,t){let n=Math.cos(e.angle),r=Math.sin(e.angle),o=e.x*t.scaleX+t.translateX,s=e.y*t.scaleY+t.translateY,a=e.length*t.dpr,i=e.halfWidth*t.dpr,c=o-n*a,l=s-r*a,d=a*(1-No);return[{x:o,y:s},{x:c-r*i,y:l+n*i},{x:o-n*d,y:s-r*d},{x:c+r*i,y:l-n*i}]}function oe(e,t){return e!==void 0&&t>=e.start&&t<e.start+e.count}function Oe(e,t){let n=new Map,r=new Map;for(let o=0,s=e.length;o<s;o++){let a=e[o],{color:i,weight:c,last:l}=t(a,o),d=l?r:n,f=`${i}:${c}`,u=d.get(f);u?u.items.push(a):d.set(f,{color:i,items:[a]})}return[...n.values(),...r.values()]}var Ao="#daa520",To=1,Co=2,ko=4;function yi(e,t,n,r=o=>o){let o=s=>{let a=t(s)*2;return n?.nodeIds.has(s)?Math.max(a,n.walks.length*ko):a};return e.flatMap(s=>s.exonsByNode.map(({nodeId:a,d:i})=>({key:`${s.gene.name}-${s.gene.start}-${a}`,d:r(i),inner:o(a)+2*To})))}function bi(e,t){if(e.length===0)return;let n=(r,o,s)=>R("path",{d:r.d,fill:"none",stroke:o,"stroke-width":s,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":t.transform?"non-scaling-stroke":void 0});return R("g",{},R("mask",{id:t.id,maskUnits:"userSpaceOnUse",x:0,y:0,width:t.width,height:t.height},R("g",{transform:t.transform},...e.map(r=>n(r,"#fff",r.inner+2*Co)),...e.map(r=>n(r,"#000",r.inner)))),R("rect",{width:t.width,height:t.height,fill:Ao,mask:`url(#${t.id})`}))}function Ae(e,t,n){let r=Math.round(t),o=Math.round(n);return`${e?`${e}:`:""}${P(r)}-${P(o)} (${k(o-r)})`}function $o(e,t){let{field:n}=e.encoding,r=e.range?Ae(e.range.contig,e.range.start,e.range.end):void 0,o=n==="progress"?r:n==="reference"&&t?Ae(t.name,t.start,t.end):void 0,s=e.range?e.range.end-e.range.start:e.bp,a=s-e.bp;return{delta:e.referenceBp===void 0||s===e.referenceBp?"":` ${s>e.referenceBp?"+":"\u2212"}${k(Math.abs(s-e.referenceBp))}`,outside:a>0?`, ${k(a)} outside the cut`:"",reversed:e.reversedBp>0?`, ${k(e.reversedBp)} reversed`:"",shades:n!=="walk",scale:o,hover:o===r?void 0:r}}function Io(e,t,n){let r=e.progress.get(t),o=e.range;if(r===void 0||!o)return;let s=Math.round(o.start+r*(o.end-o.start)-n/2);return`${o.contig}:${P(s)}-${P(s+n)}`}var Lo=50;function St(e,t){return t>0?Math.max(1,e/t):Lo}function Po(e){let t=new Set,n=1/0,r=-1/0;for(let o of e)t.add(o.minY),n=Math.min(n,o.minY),r=Math.max(r,o.minY);return t.size>1?(r-n)/(t.size-1):void 0}function Xo(e,t,n){let r=St(t,e.length);return{x:r,y:n>0?St(n,e.length):Po(e)??r}}function vt(e,t,n,r){return e===void 0?Xo(t,n,r):typeof e=="number"?{x:e,y:e}:e}function qo(e,t,n){let r=e.get(t);r||(r=new Map,e.set(t,r));let o=r.get(n);return o||(o=[],r.set(n,o)),o}function Rt(e,t,n,r,o,s,a){let i=Math.floor(n/t.x),c=Math.floor(o/t.x),l=Math.floor(r/t.y),d=Math.floor(s/t.y);for(let f=i;f<=c;f++)for(let u=l;u<=d;u++)qo(e,f,u).push(a)}function _t(e,t,n,r,o,s){let a=Math.floor((n-o)/t.x),i=Math.floor((n+o)/t.x),c=Math.floor((r-s)/t.y),l=Math.floor((r+s)/t.y),d=[],f=new Set;for(let u=a;u<=i;u++){let m=e.get(u);if(m)for(let p=c;p<=l;p++){let h=m.get(p);if(h)for(let g of h)f.has(g)||(f.add(g),d.push(g))}}return d}var Nt=class{constructor(e,t){this.cells=new Map;let n=[],r=0,o=0;for(let[s,a]of Object.entries(e))for(let i=0;i<a.length-1;i++){let c=a[i],l=a[i+1],d=Math.min(c.x,l.x),f=Math.min(c.y,l.y),u=Math.max(c.x,l.x),m=Math.max(c.y,l.y);r+=u-d,o+=m-f,n.push({entry:{nodeId:s,segmentIdx:i},minX:d,minY:f,maxX:u,maxY:m})}this.cellSize=vt(t,n,r,o);for(let s of n)Rt(this.cells,this.cellSize,s.minX,s.minY,s.maxX,s.maxY,s.entry)}query(e,t,n,r=n){return _t(this.cells,this.cellSize,e,t,n,r)}},Ot=class{constructor(e,t,n,r,o,s,a=0,i,c=!1){this.cells=new Map,this.edgeCurves=Je(e,t,r,s,a,i,c);let l=[],d=0,f=0;for(let u=0;u<t.edges.length;u++){let m=t.edges[u],p=e[m.from],h=e[m.to],g=this.edgeCurves.get(u);if(p?.length&&h?.length&&g){let{minX:x,minY:M,maxX:w,maxY:b}=Ve(g),E=m.pathIds?.length??0;if(n&&E>0){let y=0,S=0;for(let v of K(p,h,E,r))y=Math.max(y,Math.abs(v.x)),S=Math.max(S,Math.abs(v.y));x-=y,M-=S,w+=y,b+=S}d+=w-x,f+=b-M,l.push({ei:u,minX:x,minY:M,maxX:w,maxY:b})}}this.cellSize=vt(o,l,d,f);for(let u of l)Rt(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,r=n){return _t(this.cells,this.cellSize,e,t,n,r)}};function kt(e,t,n,r,o,s){let a=o-n,i=s-r,c=a*a+i*i;if(c===0)return Math.hypot(e-n,t-r);let l=Math.max(0,Math.min(1,((e-n)*a+(t-r)*i)/c));return Math.hypot(e-(n+l*a),t-(r+l*i))}function Bo(e,t,n,r,o,s,a,i,c,l){let d=1/0,f=20,u=n,m=r;for(let p=1;p<=f;p++){let h=p/f,g=1-h,x=g*g*g*n+3*g*g*h*o+3*g*h*h*a+h*h*h*c,M=g*g*g*r+3*g*g*h*s+3*g*h*h*i+h*h*h*l;d=Math.min(d,kt(e,t,u,m,x,M)),u=x,m=M}return d}function Do(e,t,n){return Bo(e,t,n.x0,n.y0,n.cx0,n.cy0,n.cx1,n.cy1,n.x1,n.y1)}function At(e,t,n,r=1){let o=1/0;for(let s of n){let a=Do(e,t,r===1?s:{x0:s.x0,y0:s.y0*r,cx0:s.cx0,cy0:s.cy0*r,cx1:s.cx1,cy1:s.cy1*r,x1:s.x1,y1:s.y1*r});a<o&&(o=a)}return o}var Tt=new WeakMap;function $t(e,t){let n=Tt.get(e);if(n?.version===t)return n.index;let r=new Nt(e);return Tt.set(e,{version:t,index:r}),r}var Ct=new WeakMap;function Fo(e,t,n,r,o,s,a,i=!1){let c=Ct.get(e);if(c?.graph===t&&c.drawPaths===n&&c.scaleX===r.scaleX&&c.scaleY===r.scaleY&&c.version===o&&c.deletions===s&&c.routes===a&&c.stranded===i)return c.index;let l=new Ot(e,t,n,r,void 0,s,o,a,i);return Ct.set(e,{graph:t,drawPaths:n,scaleX:r.scaleX,scaleY:r.scaleY,version:o,index:l,deletions:s,routes:a,stranded:i}),l}var Yo=5;function Ti(e,t,n,r,o=0,s){let a=le(r),i=$t(e,o),c=m=>Math.max(Yo,m)/r.scaleX,l=c(s?.maxHalfWidthPx??0),d=i.query(t,n,l,l/a),f=null,u=1/0;for(let{nodeId:m,segmentIdx:p}of d){let h=e[m],g=kt(t,n*a,h[p].x,h[p].y*a,h[p+1].x,h[p+1].y*a);g<u&&g<c(s?.halfWidthPx(m)??0)&&(u=g,f=m)}return f}function Wo(e,t,n){let r=t.x-e.x,o=t.y-e.y,s=0,a=1;for(let[i,c]of[[-r,e.x-n.x0],[r,n.x1-e.x],[-o,e.y-n.y0],[o,n.y1-e.y]])if(i===0){if(c<0)return!1}else i<0?s=Math.max(s,c/i):a=Math.min(a,c/i);return s<=a}function It(e,t,n=0){let r=$t(e,n),o=s=>({x:s.x*t.scaleX+t.translateX,y:s.y*t.scaleY+t.translateY});return s=>{let a=new Set,i=r.query(((s.x0+s.x1)/2-t.translateX)/t.scaleX,((s.y0+s.y1)/2-t.translateY)/t.scaleY,Math.abs((s.x1-s.x0)/2/t.scaleX),Math.abs((s.y1-s.y0)/2/t.scaleY));for(let{nodeId:c,segmentIdx:l}of i){let d=e[c];!a.has(c)&&Wo(o(d[l]),o(d[l+1]),s)&&a.add(c)}return a}}function Ci(e,t,n,r,o,s,a=0,i,c,l,d=!1){let f=le(o),u=10/o.scaleX,m=Fo(e,t,s,o,a,i,l,d),p=m.query(n,r,u,u/f),h=null,g=u;for(let x of p){let M=t.edges[x],w=e[M.from],b=e[M.to];if(!w?.length||!b?.length||c?.has(x))continue;let E=M.pathIds?.length??0,y=m.getCurves(x);if(!y)continue;let S;if(!s||E===0)S=At(n,r*f,y,f);else{let v=1/0;for(let _ of K(w,b,E,o)){let H=_.x===0&&_.y===0?y:Qe(y,_.x,_.y),D=At(n,r*f,H,f);D<v&&(v=D)}S=v}S<g&&(g=S,h=x)}return h}var Lt=3.4,Te=6,Ho=8,Go=18,Uo=2,Ko=Ke+ze;function Pt(e){let t=e.gene.end-e.gene.start;if(e.covered>=.98)return;let[n,r]=t>=1e6?[1e6,"Mb"]:t>=1e3?[1e3,"kb"]:[1,"bp"],o=s=>+(s/n).toFixed(n===1?0:1);return`${o(e.covered*t)} of ${o(t)} ${r}`}function Xt(e,t,n,r){let o=n/2;return qt(e,s=>s.gene.end-s.gene.start).map(s=>{let{x:a,y:i}=t(s.at),c=Pt(s);return{item:s,x:a,y:i+n+Go,text:c?`${s.gene.name} \xB7 ${c}`:s.gene.name,fallback:c?`${s.gene.name} \u2026`:void 0,stack:Uo,fits:l=>[...r({x0:l.x0-o,x1:l.x1+o,y0:l.y0-o,y1:l.y1+o})].every(d=>s.nodeIds.has(d))}})}function qt(e,t){return[...e].sort((n,r)=>t(r)-t(n))}function zo(e){let{paneWidth:t,canvasHeight:n,translateX:r,translateY:o}=e,{scaleX:s,scaleY:a}=e.axisScale,i={width:t,height:n},c=y=>({x:y.x*s+r,y:y.y*a+o}),l=e.drawnRowLabels.map(({label:y,y:S})=>de(y,S*a+o)),d=e.referenceStripZonePx??0;d>0&&l.push({x0:0,x1:t,y0:0,y1:d}),e.legendSize.width>0&&l.push({x0:t-Te-e.legendSize.width,x1:t,y0:0,y1:d+Te+e.legendSize.height}),e.poppedFrom&&l.push({x0:0,x1:60+e.poppedFrom.label.length*F*1.2,y0:0,y1:44});let f=je(i,l),u=e.drawnRowLabels.length>0,m=u?Math.min(...e.drawnRowLabels.map(y=>y.y)):1/0,p=e.contigThickness*Lt,h=qt(e.bubbleHalos,y=>y.members),g=U(h.map(y=>{let{x:S,y:v}=c({x:y.labelAt.x,y:Math.min(y.labelAt.y,m)}),_=v-p/2-6;return{item:y,x:S,y:u?Math.max(_,Ko):_,text:y.label}}),i,f),x=U(Xt(e.genePins,c,e.contigThickness,It(e.nodePositions??{},{scaleX:s,scaleY:a,translateX:r,translateY:o},e.positionsVersion)),i,f),M=e.nodePositions&&e.labelsNodeSizes?fe({nodePositions:e.nodePositions,nodeLengths:e.nodeLengths,deletions:e.deletions,deletionRoutes:e.deletionRoutes,stranded:e.stranded,alleleDeletions:e.alleleDeletions,axis:e.axisScale,translateX:r,translateY:o,width:t,height:n,version:e.positionsVersion}):{deletions:[],nodes:[]},w=z(M.deletions,f),b=U(h.flatMap(y=>y.routes.map(S=>{let{x:v,y:_}=c(S.at);return{item:{halo:y,route:S},x:v,y:_+4,text:S.text,stack:Ho}})),i,f),E=z(M.nodes,f,ue(t,n));return{bubbles:g,genes:x,routes:b,sizes:[...w,...E]}}function jo(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=new Map;t.nodes.forEach(o=>{let s=n.get(o.name);if(o.order>=0&&s&&C(s)){let{refName:a,start:i}=s.stable;(r.get(a)??r.set(a,[]).get(a)).push({bp0:i,bp1:i+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}});for(let o of r.values())o.sort((s,a)=>s.bp0-a.bp0);return r}function re(e,t,n=!1){let r=0,o=e.length-1;for(;r<o;){let i=r+o>>1,c=e[i].bp1;(n?c<t:c<=t)?r=i+1:o=i}let s=e[r];if(t<=s.bp0)return s.x0;let a=s.bp1-s.bp0;return a>0?s.x0+(Math.min(t,s.bp1)-s.bp0)/a*(s.x1-s.x0):s.x0}function se(e,t,n){let r=re(e,t),o=re(e,n,!0);return{x0:Math.min(r,o),x1:Math.max(r,o)}}function Vo(e){let t;for(let n of e.values())(!t||n.length>t.length)&&(t=n);return t}var Bt=5,Qo=10,Zo=110,Jo=3;function Dt(e){return e?"#b0b0b8":"#55555c"}function er(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 Ft(e){let t=[];for(let n of e)t.every(r=>Math.abs(n.at-r.at)>=(n.width+r.width)/2+Qo)&&t.push(n);return t.map(({text:n,at:r})=>({text:n,at:r}))}function tr(e,t,n,r){let o=e[0],s=e.at(-1);if(!o||!s)return;let a=t(o.x0),i=t(s.x1),c=s.bp1-o.bp0;if(i<=a||c<=0)return;let l=er(c/(i-a)*Zo),d=[],f=[];for(let u=Math.ceil(o.bp0/l)*l;u<=s.bp1;u+=l){let m=Math.round(t(re(e,u)))+.5;if(m>=0&&m<=n){d.push(m);let p=u.toLocaleString("en-US");f.push({text:p,at:m,width:r(p)})}}return{spans:[{x0:a,x1:i}],ticks:d,labels:Ft(f)}}function nr(e,t,n,r){let o=e.map(p=>({box:p,s0:t(p.x0),s1:t(p.x1)})).filter(({s0:p,s1:h})=>h>=0&&p<=n),s=o[0],a=o.at(-1);if(!s||!a)return;let i=(p,h)=>({text:p,at:h,width:r(p)}),c=(p,h)=>i(p.toLocaleString("en-US"),h),l=[],d=[],f=[],u=[];for(let{box:p,s0:h,s1:g}of o){l.push({x0:h,x1:g}),d.push(Math.round(h)+.5),g-h>=Jo&&d.push(Math.round(g)+.5);let x=i(k(p.bp1-p.bp0),(h+g)/2);x.width<=g-h&&f.push(x),p!==s.box&&u.push(c(p.bp0,h))}let m=[c(s.box.bp0,s.s0),c(a.box.bp1,a.s1)];return{spans:l,ticks:d,labels:Ft([...m,...f,...u])}}function Yt(e,t,n,r,o=!1){return(o?tr:nr)(e,t,n,r)}function or(e,t,n,r,o=!1){let{x:s,width:a,darkMode:i}=n;e.font="10px sans-serif";let c=Yt(t,s,a,f=>e.measureText(f).width,o);if(!c)return;let l=Dt(i),d=r+.5;e.strokeStyle=l,e.fillStyle=l,e.lineWidth=1,e.textAlign="center",e.textBaseline="top",e.beginPath();for(let{x0:f,x1:u}of c.spans)e.moveTo(Math.max(0,f),d),e.lineTo(Math.min(a,u),d);for(let f of c.ticks)e.moveTo(f,r),e.lineTo(f,r+Bt);e.stroke();for(let{text:f,at:u}of c.labels)e.fillText(f,u,r+Bt+2)}function rr(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach((o,s)=>{let a=n.get(o.name);if(o.order>=0&&a&&C(a)){let i=a.stable.start;r.push({bp0:i,bp1:i+o.sequenceLength,index:s,node:o})}}),r.sort((o,s)=>o.bp0-s.bp0)}function sr(e,t,n){let r=0,o=e.length-1;for(;r<o;){let s=r+o+1>>1;e[s].bp0<=t?r=s:o=s-1}return[e[r],e[r-1]].find(s=>s&&n.has(s.index)&&s.bp0<=t&&t<=s.bp1)}function mc(e,t,n){let r=rr(e,t),o=[];for(let s of t.tracks){let a=s.name?n.get(s.name):void 0;if(a?.length){let i=new Map;for(let c of s.path)c.node!==null&&c.y!==void 0&&!i.has(c.node)&&i.set(c.node,c.y);for(let c of a){let l=sr(r,c.start,i);if(l){let{node:d,bp0:f,bp1:u}=l,m=p=>d.x+(Math.min(p,u)-f)/(u-f)*d.pixelWidth;o.push({x0:m(c.start),x1:m(c.end),y:i.get(l.index),height:s.width})}}}}return o}function ir(e){return e?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.8)"}function gc(e,t,{x:n,y:r,width:o,darkMode:s}){if(t.length!==0){e.fillStyle=ir(s),e.beginPath();for(let a of t){let i=n(a.x0),c=Math.max(n(a.x1),i+1);if(c>=0&&i<=o){let l=r(a.y);e.rect(i,l,c-i,r(a.y+a.height)-l)}}e.fill()}}var Ut=Hn(Gt(),1),ie=16;function Mc(e){let[t="",...n]=e.split(/\r\n|\r|\n/),r=t.split(" ").slice(1),o=new Map;for(let s of n){if(!s)continue;let[a="",...i]=s.split(" ");a&&!o.has(a)&&o.set(a,{...Object.fromEntries(r.map((c,l)=>[c,i[l]??""])),name:a})}return[...o.values()]}function wc(e){let t=new Set;for(let n of e??[])for(let r of Object.keys(n))r!=="name"&&t.add(r);return[...t]}function Ec(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(r=>typeof r=="string")}:{field:t}}function cr(e){let t=new Set(e.map(n=>n.label)).size;return`${t} haplotype${t===1?"":"s"}`}function Sc(e,t,{field:n,domain:r}){let o=new Map(t.map(c=>[c.name,c[n]??""])),s=new Map;for(let c of e){let l=o.get(c.label)||o.get(c.sample)||"",d=s.get(l);d?d.push(c):s.set(l,[c])}let a=1,i=[...s.keys()].sort((0,Ut.groupKeyComparator)(r)).map(c=>{let l=s.get(c),d={key:c,title:`${c||`${n}: none`} \xB7 ${cr(l)}`,first:a,count:l.length};return a+=l.length,d});return{rows:i.flatMap(c=>s.get(c.key)),sections:i}}function vc(e,t){let n=o=>{let s=-1;for(;s+1<e.length&&e[s+1].first<=o;)s++;return s},r=o=>o*t+(n(o)+1)*ie;return{rowY:r,headers:e.map((o,s)=>({...o,top:(o.first-.5)*t+s*ie})),headersPx:e.length*ie,rowAt(o,s){let a=0;for(let i=-1;i<e.length;i++){let c=i<0?0:e[i].first,l=i<0?Math.min(s,e[0]?.first??s):c+e[i].count,d=(i+1)*ie,f=Math.min(l-1,Math.max(c,Math.round((o-d)/t)));Math.abs(r(f)-o)<Math.abs(r(a)-o)&&(a=f)}return a}}}function lr(e,t){let n=new Map(e.nodes.map(o=>[o.id,o])),r=[];return t.nodes.forEach(o=>{let s=n.get(o.name);o.order>=0&&s&&C(s)&&r.push({node:o.name,bp0:s.stable.start,bp1:s.stable.start+o.sequenceLength,x0:o.x,x1:o.x+o.pixelWidth})}),r}function dr(e,t,n,r){let o=[];for(let s of e){let a=n(s.x0),i=n(s.x1);i>=0&&a<=r&&o.push({node:s.node,top0:t(s.bp0),top1:t(s.bp1),bottom0:a,bottom1:i})}return o}var fr=3;function ur(e,t,n,r){if(t<=0||r<0||r>t)return;let o=r/t,s,a=fr;for(let i of e){let c=i.top0+(i.bottom0-i.top0)*o,l=i.top1+(i.bottom1-i.top1)*o,d=Math.max(0,Math.min(c,l)-n,n-Math.max(c,l));d<a&&(a=d,s=i.node)}return s}function Kt(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 zt(e,t,n){e.moveTo(t.top0,0),e.lineTo(t.bottom0,n),e.moveTo(t.top1,0),e.lineTo(t.bottom1,n)}function hr(e,t,n,{highlightNode:r,darkMode:o}){if(n<=0||t.length===0)return;let s=o?"255,255,255":"0,0,0";e.beginPath();for(let i of t)Kt(e,i,n);e.fillStyle=`rgba(${s},0.07)`,e.fill(),e.beginPath();for(let i of t)zt(e,i,n);e.strokeStyle=`rgba(${s},0.35)`,e.lineWidth=.5,e.stroke();let a=t.find(i=>i.node===r);a&&(e.beginPath(),Kt(e,a,n),e.fillStyle="rgba(255,192,203,0.5)",e.fill(),e.beginPath(),zt(e,a,n),e.strokeStyle="#ff0000",e.lineWidth=1,e.stroke())}function jt(){return{rectangles:[],curves:[],corners:[],verticalRectangles:[]}}var pr=new Set(["_gbwt_ref","unknown"]);function Vt(e){let[t,n,r]=e?.split("#")??[];if(!(t===void 0||t===""||pr.has(t)||n===void 0||!/^\d+$/.test(n)||r===void 0||r===""))return{sample:t,haplotype:Number(n),contig:r}}var fn=!1;function B(...e){fn&&console.log(...e)}var mr=["read_group","sample_name"],Xc=[...mr,"haplotype_sample"];function gr({layers:e,coarsenedReadView:t=!1,showReads:n=!0},r){if(e!==void 0)return e;let o=t&&n,s=a=>a?{stat:"coarsen"}:{};return[{data:"haplotypes",...s(o&&!r)},{data:"reads",...s(o&&r)}]}function Qt(e,t){return e.find(n=>n.data===t)?.stat}function xr(e,t){return{mergeNodes:e.mergeNodes??!0,showReads:e.showReads??!0,coarsenedReadView:e.coarsenedReadView??!1,layers:gr(e,t),ignoreStrand:e.ignoreStrand??!1,nodeWidthOption:e.nodeWidthOption??"normal",charWidth:e.charWidth??8.401,trackWidth:e.trackWidth??15}}function un(e){return{config:e,nodes:[],tracks:[],reads:[],nodeMap:new Map,nodesPerOrder:[],nodeOrders:[],assignments:[],extraLeft:[],extraRight:[],maxOrder:-1,shapes:jt(),imageBounds:{minX:0,maxX:0,minY:0,maxY:0},trackForRuler:void 0,coarsenedEdgeMeta:new Map}}function qc(e,t,n=[],r={}){let o=yr(e,t,n,r);return o&&br(o,r)}var hn=new WeakMap;function yr(e,t,n=[],r={}){let o=wr(e,t,n,r);if(o===void 0)return;let s=pn(o,o.tracks,o.reads,"measure");return s.nodes.forEach((a,i)=>{a.order>=0&&(o.nodes[i].x=a.x)}),hn.set(o,s),o}function br(e,t={}){return Mr(e,Rr(e,t.facet),Er(e,t))}function Mr(e,t,n,r){let o=hn.get(e);return o!==void 0&&t.length===e.tracks.length&&n.length===e.reads.length?o:pn(e,t,n,"topology",r)}function wr(e,t,n,r){let o=un(xr(r,n.length>0));if(!(e.length===0||t.length===0)){structuredClone(e).forEach((s,a)=>{s.seq??="",s.sequenceLength??=s.seq.length,o.nodes[a+1]=s}),o.tracks=structuredClone(t),o.reads=o.config.showReads?structuredClone(n.filter(s=>s.is_secondary!==!0)):[];for(let s=o.tracks.length-1;s>=0;s-=1){let a=o.tracks[s];if(a.type??="haplotype",a.hidden===!0){o.tracks.splice(s,1);continue}a.indexOfFirstBase!==void 0&&(o.trackForRuler=a.name)}if(o.tracks.length!==0)return Nr(o,0),o.nodeMap=tn(o),q(o,o.tracks),q(o,o.reads),ln(o),o.config.mergeNodes&&(nn(o),ke(o),$e(o),gs(o),o.nodeMap=tn(o),ln(o),q(o,o.tracks),q(o,o.reads)),nn(o),jr(o),ke(o),Vr(o),ke(o),$e(o),q(o,o.reads),{options:o.config,nodes:o.nodes,tracks:o.tracks,reads:o.reads,nodeMap:o.nodeMap,maxOrder:Kr(o),trackForRuler:o.trackForRuler}}}function Er(e,{mappingQualityCutoff:t=0,focusReadNames:n=null,facet:r}){let o=n?new Set(n):null;return e.reads.filter(s=>(s.mapping_quality??0)>=t&&(o===null||s.name!==void 0&&o.has(s.name))&&(r===void 0||Sr(r,s)))}function Sr(e,t){return e.by==="haplotype_sample"?"reads"in e:(t[e.by]??null)===e.key}function vr(e){return new Set(e.tracks.filter((t,n)=>n===0||t.name===e.trackForRuler))}function Rr(e,t){if(t?.by!=="haplotype_sample")return e.tracks;let n=vr(e);return e.tracks.filter(r=>n.has(r)||!("reads"in t)&&_r(r)===t.key)}function _r(e){return Vt(e.name)?.sample??null}function pn(e,t,n,r,o={}){let s=un(e.options);e.nodes.forEach((u,m)=>{s.nodes[m]={...u}}),s.tracks=t.map(u=>({...u})),s.reads=n.map(u=>({...u})),s.nodeMap=e.nodeMap,s.maxOrder=e.maxOrder,s.trackForRuler=e.trackForRuler;let{layers:a,ignoreStrand:i}=s.config,c=o.haplotypes??yn,l=Qt(a,"haplotypes")==="coarsen"?fs(s,c):void 0;l!==void 0&&(s.tracks=[l.ref]),as(s),es(s),Or(s);let d=Qt(a,"reads")==="coarsen"&&s.reads.length>0?bn(s,s.reads,"read",o.reads??c+(l?.bands.length??0)):void 0;d!==void 0&&(s.reads=d.bands);let f={};for(let[u,m,p]of[["haplotypes","haplotype",l],["reads","read",d]])p!==void 0&&($e(s,p.bands),q(s,p.bands),f[u]={unit:m,total:p.total,reverse:!i&&p.bands.some(h=>h.is_reverse)});return l!==void 0&&(s.reads=l.bands.concat(s.reads)),s.reads.length>0?(Tr(s),s.tracks=s.tracks.concat(s.reads)):s.nodes.forEach(u=>{u.incomingReads=[],u.outgoingReads=[],u.internalReads=[]}),r==="measure"&&Zr(s),ds(s),B("Tracks:",s.tracks),B("Nodes:",s.nodes),B("Lane assignment:",s.assignments),Yr(s),{nodes:s.nodes,tracks:s.tracks,reads:s.reads,nodeMap:s.nodeMap,shapes:s.shapes,bounds:s.imageBounds,maxOrder:s.maxOrder,trackForRuler:s.trackForRuler,coarsenedEdgeMeta:s.coarsenedEdgeMeta,coarsened:f}}function O(e){return e.startsWith("-")}function A(e){return O(e)?e.substring(1):e}function mn(e){return O(e)?e:`-${e}`}function Ie(e){return O(e)?A(e):mn(e)}function Zt(e){return e>0}function Nr(e,t){let n=new Set,r=new Set;for(let o of e.tracks[t].sequence)O(o)?r.has(A(o))||n.add(A(o)):r.add(o);if(n.size!==0){for(let{sequence:o}of[...e.tracks,...e.reads])for(let s=0;s<o.length;s+=1)n.has(A(o[s]))&&(o[s]=Ie(o[s]));e.nodes.forEach(o=>{n.has(o.name)&&(o.seq=Le(o.seq))})}}function Or(e){e.nodesPerOrder=[];for(let n=0;n<=e.maxOrder;n+=1)e.nodesPerOrder[n]=[];let t=new Map;e.nodes.forEach(n=>{n.y!==void 0&&Jt(t,n.order,n.y+n.contentHeight)}),e.tracks.forEach(n=>{n.type==="haplotype"&&n.path.forEach(r=>{Jt(t,r.order,(r.y??0)+n.width)})}),e.nodes.forEach((n,r)=>{n.order>=0&&n.y===void 0&&(n.y=(t.get(n.order)??0)+25,n.contentHeight=0,e.nodesPerOrder[n.order].push(r))})}function Jt(e,t,n){let r=e.get(t);r===void 0?e.set(t,n):e.set(t,Math.max(r,n))}var ae=7;function Ar(e){e.nodes.forEach(t=>{t.incomingReads=[],t.outgoingReads=[],t.internalReads=[]}),e.reads.forEach((t,n)=>{if((t.width===void 0||t.width===0)&&(t.width=ae),t.path.length===1){let r=t.path[0].node;r!==null&&e.nodes[r].internalReads.push(n)}else t.path.forEach((r,o)=>{if(o===0){let s=t.path[0].node;s!==null&&e.nodes[s].outgoingReads.push([n,o])}else{let s=r.node;s!==null&&e.nodes[s].incomingReads.push([n,o])}})})}function Tr(e){e.reads.forEach(i=>{i.path=gn(e,i)}),Ar(e);let t=e.nodes.filter(i=>i.order>=0);t.sort(Xe);let n=new Map;for(let i=0;i<e.reads.length;i++){let c=e.reads[i],l=c.haplotypeShare===void 0?1:0,d=c.sourceTrackID,f=`${l}:${d}`,u=n.get(f);u===void 0?n.set(f,{layer:l,source:d,reads:new Set([i])}):u.reads.add(i)}let r=[...n.values()].sort((i,c)=>i.layer-c.layer||i.source-c.source),o=r.length>1?ae:0;t.forEach(i=>{for(let{reads:c}of r)Cr(e,c,i,o)});let s=Xr(e),a=[];e.reads.forEach((i,c)=>{let l=i.path.length,d=new Array(l),f;for(let p=0;p<l;p++){p===0?d[p]=void 0:d[p]=f??i.path[0];let h=i.path[p];h.node!==null&&h.node&&(f=h)}let u=new Array(l),m;for(let p=l-1;p>=0;p--){p===l-1?u[p]=void 0:u[p]=m??i.path[l-1];let h=i.path[p];h.node!==null&&h.node&&(m=h)}i.path.forEach((p,h)=>{if(p.y===void 0){let g=d[h],x=u[h],M=!!(x&&g&&(g.order>x.order||x.order===g.order&&x.isForward===g.isForward));p.betweenCycleReverseTraversal=M,a.push({readIndex:c,pathIndex:h,previousY:g?.y,previousNode:g?.node})}})}),a.sort((i,c)=>$r(e,i,c)),a.forEach(i=>{let c=e.reads[i.readIndex],l=c.path[i.pathIndex];l.y=s[l.order],s[l.order]+=c.width}),B("Reads:",e.reads)}function Cr(e,t,n,r){let o=n.incomingReads.filter(([p])=>t.has(p)),s=n.outgoingReads.filter(([p])=>t.has(p)),a=n.internalReads.filter(p=>t.has(p));o.length===0&&s.length===0&&a.length===0&&(r=0);let i=n.y+n.contentHeight+r*2,c=o.map(p=>{let[h,g]=p,x=e.reads[h].path,M=g+1,w;for(let b=1;b<=g;b++){let E=x[g-b]?.y;if(E!==void 0){M=b,w=E;break}}return{entry:p,decisionStep:M,y:w}});c.sort(kr),o=c.map(p=>p.entry);let l=i,d=new Map;o.forEach(p=>{let h=e.reads[p[0]];h.path[p[1]].y=l,en(d,h,p[1],l,n),l+=h.width});let f=l;s.sort((p,h)=>Ir(e,p,h));let u=new Map;l=i,s.forEach(p=>{let h=e.reads[p[0]],g=h.firstNodeOffset??0;h.path[p[1]].y=l,u.set(l,g);let x=d.get(l);x===void 0||x+1<=g?(l+=h.width,f=Math.max(f,l)):(d.set(l,0),o.forEach(M=>{let w=e.reads[M[0]],b=w.path[M[1]];b.y!==void 0&&b.y>=l&&(b.y+=h.width,en(d,w,M[1],b.y,n))}),l+=h.width,f+=h.width)}),a.sort((p,h)=>Pr(e,p,h)),a.forEach(p=>{let h=e.reads[p],g=h.firstNodeOffset??0,x=h.finalNodeCoverLength??0;for(l=i;g<(d.get(l)??-1/0)+2||x>(u.get(l)??1/0)-3;)l+=h.width||ae;h.path[0].y=l,d.set(l,x),f=Math.max(f,l)});let m=f-n.y-n.contentHeight;n.contentHeight+=m,ss(e,n,m)}function kr(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 en(e,t,n,r,o){n===t.path.length-1?e.set(r,t.finalNodeCoverLength??0):e.set(r,o.sequenceLength)}function $r(e,t,n){let r=e.reads[t.readIndex],o=e.reads[n.readIndex],s=r.path[t.pathIndex],a=o.path[n.pathIndex];if(s.order!==a.order)return s.order-a.order;if(r.sourceTrackID!==o.sourceTrackID)return r.sourceTrackID-o.sourceTrackID;if(t.previousNode&&n.previousNode){let f=e.nodes[t.previousNode],u=e.nodes[n.previousNode];if(f&&u&&f.order!==u.order)return f.order-u.order}let i=t.previousY??0,c=n.previousY??0,l=s.betweenCycleReverseTraversal===!0,d=a.betweenCycleReverseTraversal===!0;return l!==d?l?1:-1:l?c-i:i-c}function Ir(e,[t,n],[r,o]){let s=e.reads[t],a=e.reads[r],i,c,l=s.path.length-1,d=a.path.length-1;for(;!i&&l>=0;)i=s.path[l]?.y,l-=1;for(;!c&&d>=0;)c=a.path[d]?.y,d-=1;if(i&&c)return i-c;let f=s.path[n]?.node,u=a.path[o]?.node,m=typeof f=="number"?e.nodes[f]:null,p=typeof u=="number"?e.nodes[u]:null;for(;m&&p&&m===p;){if(n<s.path.length-1){for(n+=1;s.path[n]?.node===null;)n+=1;let g=s.path[n]?.node;m=typeof g=="number"?e.nodes[g]:null}else m=null;if(o<a.path.length-1){for(o+=1;a.path[o]?.node===null;)o+=1;let g=a.path[o]?.node;p=typeof g=="number"?e.nodes[g]:null}else p=null}if(m)return p?Xe(m,p):1;if(p)return-1;let h=(s.firstNodeOffset??0)-(a.firstNodeOffset??0);return h!==0?h:(s.finalNodeCoverLength??0)-(a.finalNodeCoverLength??0)}function Lr(e,t){let n=e.path,r=t.path,o=0,s=0;for(;o<n.length&&s<r.length;){let a=n[o],i=r[s],c=a.order,l=i.order;if(c===l&&a.node&&i.node)return(i.y??0)-(a.y??0);c<l?o+=1:(c>l||(o+=1),s+=1)}return 0}function Pr(e,t,n){let r=e.reads[t],o=e.reads[n],s=r.firstNodeOffset??0,a=o.firstNodeOffset??0;if(s<a)return-1;if(s>a)return 1;let i=r.finalNodeCoverLength??0,c=o.finalNodeCoverLength??0;return i<c?-1:i>c?1:0}function Xr(e){let t=[];for(let n=0;n<=e.maxOrder;n+=1)t.push(0);return e.nodes.forEach(n=>{n.y!==void 0&&(t[n.order]=Math.max(t[n.order],n.y+n.contentHeight+20))}),e.tracks.forEach(n=>{n.path.forEach(r=>{t[r.order]=Math.max(t[r.order],(r.y??0)+n.width)})}),t}function gn(e,t){let n=[],r=(c,l)=>{n.push({order:c,isForward:l,node:null})},o=(c,l,d)=>{n.push({order:c,isForward:l,node:d})},s=Math.abs(t.indexSequence[0]),a=Zt(t.indexSequence[0]),i=e.nodes[s];o(i.order,a,s);for(let c=1;c<t.sequence.length;c+=1){let l=i,d=a;s=Math.abs(t.indexSequence[c]),a=Zt(t.indexSequence[c]),i=e.nodes[s];let{order:f}=i;if(f>l.order){d||r(l.order,!0);for(let u=l.order+1;u<f;u+=1)r(u,!0);a||r(f,!0)}else if(f<l.order){d&&r(l.order,!1);for(let u=l.order-1;u>f;u-=1)r(u,!1);a&&r(f,!1)}else a===d&&r(f,!a);o(f,a,s)}return n}function $e(e,t=e.reads){t.forEach(n=>{let r=0;for(;r<n.sequence.length&&n.sequence[r].startsWith("-");)r+=1;if(r===n.sequence.length){n.is_reverse=!0,n.sequence=n.sequence.reverse();for(let c=0;c<n.sequence.length;c+=1)n.sequence[c]=A(n.sequence[c]);let o=n.sequenceNew??[];o.reverse(),n.sequenceNew=o;for(let c of o)c.nodeName=A(c.nodeName),qr(c.mismatches,Ce(e,c.nodeName).sequenceLength);let s=n.firstNodeOffset??0,a=Ce(e,n.sequence[0]).sequenceLength;n.firstNodeOffset=a-(n.finalNodeCoverLength??0);let i=Ce(e,n.sequence[n.sequence.length-1]).sequenceLength;n.finalNodeCoverLength=i-s}})}function qr(e,t){e.forEach(n=>{Object.assign(n,Br(n,t))})}function Br(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:Le(e.seq)}}}var Dr={A:"T",T:"A",C:"G",G:"C"};function Le(e){let t="";for(let n=e.length-1;n>=0;n-=1)t+=Dr[e.charAt(n)]??"N";return t}function q(e,t){let n=new Map;t.forEach(r=>{r.indexSequence=r.sequence.map(o=>{let s=n.get(o);if(s===void 0){let a=e.nodeMap.get(A(o));if(a===void 0)throw new Error(`Track ${r.name??r.id} visits unknown node ${o}`);s=O(o)?-a:a,n.set(o,s)}return s})})}var Fr=20;function Yr(e){let t={minX:99,maxX:-99,minY:99,maxY:-99};e.nodes.forEach(n=>{n.x!==void 0&&(t.minX=Math.min(t.minX,n.x),t.maxX=Math.max(t.maxX,n.x+Fr+n.pixelWidth)),n.y!==void 0&&(t.minY=Math.min(t.minY,n.y-10),t.maxY=Math.max(t.maxY,n.y+n.contentHeight+10))}),e.tracks.forEach(n=>{n.path.forEach(r=>{let o=r.y??0;t.maxY=Math.max(t.maxY,o+n.width),t.minY=Math.min(t.minY,o)})}),e.imageBounds=t}function Ce(e,t){let n=e.nodeMap.get(A(t)),r=n===void 0?void 0:e.nodes[n];if(r===void 0)throw new Error(`Unknown node ${t}`);return r}function tn(e){let t=new Map;return e.nodes.forEach((n,r)=>{t.set(n.name,r)}),t}function nn(e){let t=e.nodes.map(()=>new Set),n=e.nodes.map(()=>new Set),r=o=>{for(let s=0;s<o.indexSequence.length-1;s+=1){let a=Math.abs(o.indexSequence[s]),i=Math.abs(o.indexSequence[s+1]);t[a].add(i),n[i].add(a)}};e.tracks.forEach(r),e.reads.forEach(r),e.nodes.forEach((o,s)=>{o.successors=Array.from(t[s]),o.predecessors=Array.from(n[s])})}function on(e,t){let n=0,r=0,o=0;t.forEach(s=>{let a=Math.abs(s);if(s<0){let i=e.nodeOrders[a]??=r;i<o&&(o=i),n=i,r=i-1}else{let i=e.nodeOrders[a]??=n;n=i+1,r=i}}),o<0&&Pe(e,-o)}function Wr(e,t){let n=0,r=0;for(;n<t.length&&e.nodeOrders[Math.abs(t[n])]===void 0;)n+=1;if(n>=t.length)return null;let o=t[n],s,a;o>=0?(s=e.nodeOrders[o]-1,a=-1):(s=e.nodeOrders[-o]+1,a=1);for(let i=n-1;i>=0;i-=1){let c=Math.abs(t[i]);e.nodeOrders[c]===void 0&&(e.nodeOrders[c]=s,r=Math.min(r,s),s+=a)}return r<0&&Pe(e,-r),n}var Hr=-1;function Gr(e){let t=[];for(let n of e)t.push(n??Hr);return t}function ke(e){let t,n,r,o,s=0,a=e.tracks.concat(e.reads),i={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}),on(e,e.tracks[0].indexSequence);for(let l=1;l<a.length;l+=1){if(B(`generating order for track ${l+1}`),r=Wr(e,a[l].indexSequence),r===null){l<e.tracks.length?on(e,a[l].indexSequence):(a.splice(l,1),e.reads.splice(l-e.tracks.length,1),l-=1);continue}for(t=zr(a[l].indexSequence);r<t.length;){for(o=r,r+=1;r<t.length&&e.nodeOrders[t[r]]===void 0;)r+=1;if(r<t.length){n=e.nodeOrders[t[o]]+1;for(let d=o+1;d<r;d+=1)e.nodeOrders[t[d]]=n,n+=1;if(e.nodeOrders[t[r]]>e.nodeOrders[t[o]])e.nodeOrders[t[r]]<n&&rn(e,t[r],t[r-1],n);else if(a[l].indexSequence[r]>=0&&!Ur(e,t[r],t[o],i))rn(e,t[r],t[r-1],n);else if(a[l].indexSequence[o]<0||e.nodes[t[o+1]].degree<2&&e.nodeOrders[t[r]]<e.nodeOrders[t[o]]){n=e.nodeOrders[t[o]]-1;for(let d=o+1;d<r;d+=1)e.nodeOrders[t[d]]=n,s=Math.min(s,n),n-=1}}else if(a[l].indexSequence[o]>=0){n=e.nodeOrders[t[o]]+1;for(let d=o+1;d<t.length;d+=1){let f=t[d];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,n+=1)}}else{n=e.nodeOrders[t[o]]-1;for(let d=o+1;d<t.length;d+=1){let f=t[d];e.nodeOrders[f]===void 0&&(e.nodeOrders[f]=n,s=Math.min(s,n),n-=1)}}}}s<0&&Pe(e,-s);let c=Gr(e.nodeOrders);e.nodeOrders=c,c.forEach((l,d)=>{let f=e.nodes[d];f!==void 0&&(f.order=l)})}function Ur(e,t,n,r){r.generation+=1;let{stamp:o,generation:s}=r,a=[t];for(o[t]=s;a.length>0;){let i=a.pop();if(i===n)return!0;for(let c of e.nodes[i].successors)o[c]!==s&&(o[c]=s,a.push(c))}return!1}function Kr(e){let t=-1;return e.nodeOrders.forEach(n=>{n!==void 0&&n>t&&(t=n)}),t}function zr(e){return e.map(t=>Math.abs(t))}function Pe(e,t){e.nodeOrders.forEach((n,r)=>{n!==void 0&&(e.nodeOrders[r]=n+t)})}function rn(e,t,n,r){let o=new Map,s=[[t,r]],a=0;for(;a<s.length;){let[i,c]=s[a];a+=1;let l=e.nodeOrders[i];l!==void 0&&l<c&&(!o.has(i)||o.get(i)<c)&&(o.set(i,c),e.nodes[i].successors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,c+1])}),i!==t&&e.nodes[i].predecessors.forEach(d=>{e.nodeOrders[d]>l&&d!==n&&s.push([d,c+1])}))}o.forEach((i,c)=>{e.nodeOrders[c]=i})}function jr(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 Vr(e){Qr(e,[...e.tracks.slice(1),...e.reads],e.tracks[0])}function Qr(e,t,n){let r=new Int32Array(e.nodes.length),o=new Uint8Array(e.nodes.length);for(let s of n.sequence){let a=O(s)?void 0:e.nodeMap.get(s);a!==void 0&&(o[a]=1)}for(let s of t){let{sequence:a,indexSequence:i}=s,c=i.length-1;for(let l=0;l<=c;l+=1){let d=Math.abs(i[l]);if(o[d]===1)continue;let f=e.nodes[d].order,u=l>0?e.nodes[Math.abs(i[l-1])].order:void 0,m=l<c?e.nodes[Math.abs(i[l+1])].order:void 0,p=O(a[l])?1:-1;(u===void 0||u<f)&&(m===void 0||f<m)&&(r[d]+=p),(u===void 0||u>f)&&(m===void 0||f>m)&&(r[d]-=p)}}for(let s of t){let{sequence:a,indexSequence:i}=s;for(let c=0;c<i.length;c+=1)r[Math.abs(i[c])]>0&&(a[c]=Ie(a[c]),i[c]=-i[c])}e.nodes.forEach((s,a)=>{r[a]>0&&(s.seq=Le(s.seq),s.switched=!0)})}function Zr(e){let t=0,n=20,r=-1,o=e.nodes.slice();o.sort(Xe);let s=Jr(e);o.forEach(a=>{a.order>=0&&(a.order>r&&(r=a.order,t=n+10*s[a.order]),a.x=t,n=Math.max(n,t+40+a.pixelWidth))})}function Jr(e){let t=[],n=[],r=[],o=[];for(let s=0;s<=e.maxOrder;s+=1)t.push(0),n.push(0),r.push(0);e.tracks.forEach(s=>{for(let a=1;a<s.path.length;a+=1){let i=s.path[a],c=s.path[a-1];if(i.order===c.order)i.isForward?t[i.order]=t[i.order]+1:n[i.order]=n[i.order]+1;else{let l=Math.abs((i.y??0)-(c.y??0));r[i.order]=Math.max(l/17.5,r[i.order])}}}),o.push(Math.max(0,t[0]-1));for(let s=1;s<=e.maxOrder;s+=1)o.push(Math.max(Math.max(0,t[s]-1)+Math.max(0,n[s-1]-1),r[s]));return o}function es(e){let t=[],n=[];for(let r=0;r<=e.maxOrder;r+=1)e.assignments[r]=[],n[r]=new Map,t[r]=[];e.tracks.forEach((r,o)=>{r.path=gn(e,r),r.path.forEach((s,a)=>{ts(e,s.order,s.node,o,a,t,n)})});for(let r=0;r<=e.maxOrder;r+=1)os(e,e.assignments[r],r)}function ts(e,t,n,r,o,s,a){let i={trackID:r,segmentID:o,compareToFromSame:s[t][r]??null},c=n===null?void 0:a[t].get(n);if(c===void 0){let l={type:"single",node:n,tracks:[i]};e.assignments[t].push(l),n!==null&&a[t].set(n,l)}else c.type="multiple",c.tracks.push(i);s[t][r]=i}function ns(e,t,n){let r;t.forEach(o=>{o.idealLane=0,o.tracks.forEach(s=>{if(s.segmentID===0)s.idealLane=s.trackID,s.idealY=null;else if(e.tracks[s.trackID].path[s.segmentID-1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID-1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID-1].y;else if(s.segmentID<e.tracks[s.trackID].path.length-1&&e.tracks[s.trackID].path[s.segmentID+1].order===n-1)s.idealLane=e.tracks[s.trackID].path[s.segmentID+1].lane??void 0,s.idealY=e.tracks[s.trackID].path[s.segmentID+1].y;else{for(r=s.segmentID-1;r>=0&&e.tracks[s.trackID].path[r].order!==n-1;)r-=1;r<0?(s.idealLane=s.trackID,s.idealY=null):(s.idealLane=e.tracks[s.trackID].path[r].lane,s.idealY=e.tracks[s.trackID].path[r].y)}o.idealLane+=s.idealLane}),o.idealLane/=o.tracks.length})}function os(e,t,n){let r=0,o=new Set,s=20,a=!1,i=-1;ns(e,t,n),t.sort(sn),t.forEach(c=>{c.node!==null?(e.nodes[c.node].topLane=r,a&&(s-=10),e.nodes[c.node].y=s,e.nodes[c.node].contentHeight=0,a=!1):(a?s-=25:s>20&&(s-=10),a=!0),c.tracks.sort(sn),c.tracks.forEach(l=>{l.lane=r,l.trackID===i&&c.node===null&&a&&(s+=10),e.tracks[l.trackID].path[l.segmentID].lane=r,e.tracks[l.trackID].path[l.segmentID].y=s,typeof l.idealY=="number"&&o.add(l.idealY-s),r+=1,s+=e.tracks[l.trackID].width,c.node!==null&&(e.nodes[c.node].contentHeight+=e.tracks[l.trackID].width),i=l.trackID}),s+=25}),rs(e,t,o)}function rs(e,t,n){let r=0,o=Number.MAX_SAFE_INTEGER;n.forEach(s=>{let a=is(e,t,s);a<o&&(o=a,r=s)}),t.forEach(s=>{s.node!==null&&(e.nodes[s.node].y+=r),s.tracks.forEach(a=>{let i=e.tracks[a.trackID].path[a.segmentID];i.y=i.y+r})})}function ss(e,t,n){t.order<0||e.assignments[t.order]===void 0||(e.assignments[t.order].forEach(r=>{if(r.node!==null){let o=e.nodes[r.node];o!==t&&o.y>t.y&&(o.y+=n,r.tracks.forEach(s=>{let a=e.tracks[s.trackID].path[s.segmentID];a.y=a.y+n}))}else r.tracks.forEach(o=>{let s=e.tracks[o.trackID].path[o.segmentID];s.y>=t.y&&(s.y=s.y+n)})}),e.nodesPerOrder[t.order].length>0&&e.nodesPerOrder[t.order].forEach(r=>{e.nodes[r]!==t&&e.nodes[r].y>t.y&&(e.nodes[r].y+=n)}))}function is(e,t,n){let r=0;return t.forEach(o=>{o.tracks.forEach(s=>{typeof s.idealY=="number"&&e.tracks[s.trackID].type!=="read"&&(r+=Math.abs(s.idealY-n-e.tracks[s.trackID].path[s.segmentID].y)*e.tracks[s.trackID].width)})}),r}function sn(e,t){return e.idealLane!==void 0?t.idealLane!==void 0?e.idealLane<t.idealLane?-1:e.idealLane>t.idealLane?1:0:-1:t.idealLane!==void 0?1:0}function Xe(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 as(e){let t=!0,n=4,r=e.config.trackWidth;for(let o of e.tracks)o.freq!==void 0?o.width=Math.round((Math.log(Math.max(o.freq,1))+1)*n):(o.width=r,o.type!==void 0&&o.type==="read"&&(o.width=n)),o.width!==n&&(t=!1);t&&e.tracks.forEach(o=>{o.freq!==void 0&&(o.width=r)})}function cs(e,t){let n=t.path[0],r=e.nodes[n.node],o=t.firstNodeOffset??0;return qe(r,n.isForward?o:r.sequenceLength-o)}function ls(e,t){let n=t.path[t.path.length-1],r=e.nodes[n.node],o=t.finalNodeCoverLength??0;return qe(r,n.isForward?o:r.sequenceLength-o)}function xn(e,t){return t>e.sequenceLength?null:qe(e,t)}function qe(e,t){let[n,r]=ms(e);if(e.sequenceLength===0)return n;let o=Math.min(Math.max(t,0),e.sequenceLength);return n+o/e.sequenceLength*(r-n)}function ds(e){let t,n,r,o;for(let i=0;i<=e.maxOrder;i+=1)e.extraLeft.push(0),e.extraRight.push(0);let s=[],a=[];e.nodes.forEach(i=>{i.x!==void 0&&(s[i.order]=i.x,a[i.order]===void 0?a[i.order]=i.x+i.pixelWidth:a[i.order]=Math.max(a[i.order],i.x+i.pixelWidth))}),e.tracks.sort(Lr),e.tracks.forEach(i=>{r=i.path[0].y,i.type!=="read"?i.sequence[0].startsWith("-")?t=a[i.path[0].order]+20:t=s[i.path[0].order]-20:t=cs(e,i);for(let c=0;c<i.path.length;c+=1)i.path[c].y!==r&&(i.path[c-1].isForward?n=a[i.path[c-1].order]:n=s[i.path[c-1].order],n!==t&&e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:r,xEnd:Math.max(t,n),yEnd:r+i.width-1,id:i.id,name:i.name,type:i.type}),i.path[c].order-1===i.path[c-1].order?(t=n,n=s[i.path[c].order],o=i.path[c].y,e.shapes.curves.push({xStart:t,yStart:r,xEnd:n+1,yEnd:o,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[c-1].node,nodeEnd:i.path[c].node,orderStart:i.path[c-1].order,orderEnd:i.path[c].order}),t=n,r=o):i.path[c].order+1===i.path[c-1].order?(t=n,n=a[i.path[c].order],o=i.path[c].y,e.shapes.curves.push({xStart:t+1,yStart:r,xEnd:n,yEnd:o,width:i.width,id:i.id,name:i.name,type:i.type,nodeStart:i.path[c-1].node,nodeEnd:i.path[c].node,orderStart:i.path[c-1].order,orderEnd:i.path[c].order}),t=n,r=o):i.path[c-1].isForward?(o=i.path[c].y,cn(e,1,n,r,o,i.width,i.id,i.path[c].order,i.type,i.name),t=a[i.path[c].order],r=i.path[c].y):(o=i.path[c].y,cn(e,-1,n,r,o,i.width,i.id,i.path[c].order,i.type,i.name),t=s[i.path[c].order],r=i.path[c].y));i.type!=="read"?i.path[i.path.length-1].isForward?n=a[i.path[i.path.length-1].order]+20:n=s[i.path[i.path.length-1].order]-20:n=ls(e,i),e.shapes.rectangles.push({xStart:Math.min(t,n),yStart:r,xEnd:Math.max(t,n),yEnd:r+i.width-1,id:i.id,name:i.name,type:i.type})})}var yn=1e9;function bn(e,t,n,r=yn){let o=new Map,s=0,a=e.nodes.length,i=(h,g)=>(h+a)*(2*a+1)+g+a,c=e.config.ignoreStrand;for(let[h,g]of t.entries()){let x=Math.max(g.freq??1,1);s+=x;let M=g.indexSequence;if(!(M.length<2))for(let w=0;w<M.length-1;w+=1){let b=M[w],E=M[w+1],y=e.nodes[Math.abs(b)],S=e.nodes[Math.abs(E)],v=c?Math.min(i(b,E),i(-E,-b)):i(b,E),_=o.get(v);_===void 0?o.set(v,{sSigned:b,dSigned:E,sName:b<0?`-${y.name}`:y.name,dName:E<0?`-${S.name}`:S.name,count:x,crossings:x,sourceTrackID:g.sourceTrackID,lastSource:h}):(_.crossings+=x,_.lastSource!==h&&(_.count+=x,_.lastSource=h))}}let l=0;for(let h of o.values())h.crossings>l&&(l=h.crossings);let d=ae,f=60,u=h=>l<=1?d:d+(f-d)*Math.sqrt(h/l),m=[],p=0;for(let h of o.values()){let g=r+p,x=n==="haplotype"?{count:h.count,total:s}:void 0,M=x===void 0?"":` (${ps(x)})`,w=h.crossings===h.count?"":`, ${h.crossings.toLocaleString()} crossings`,b=`${h.count.toLocaleString()} ${n}${h.count===1?"":"s"}${M}${w}: Node ${h.sName} \u2192 Node ${h.dName}`;e.coarsenedEdgeMeta.set(g,{count:h.count,label:b});let E=e.nodes[Math.abs(h.sSigned)].sequenceLength;m.push({id:g,sourceTrackID:h.sourceTrackID,type:"read",name:b,sequence:[h.sName,h.dName],indexSequence:[],path:[],width:u(h.crossings),firstNodeOffset:E,finalNodeCoverLength:0,sequenceNew:[{nodeName:h.sName,mismatches:[]},{nodeName:h.dName,mismatches:[]}],mapping_quality:0,is_secondary:!1,sample_name:null,read_group:null,score:h.count,haplotypeShare:x}),p+=1}if(fn){let h="?",g=0;e.nodes.forEach(x=>{x.contentHeight>g&&(g=x.contentHeight,h=x.name)}),B(`[coarsened] ${n}s_in=${t.length} edges_out=${m.length} tallestNodeBeforePlace=${h}(${g.toFixed(1)})`)}return{bands:m,total:s}}function fs(e,t){let n=e.trackForRuler===void 0?-1:e.tracks.findIndex(d=>d.name===e.trackForRuler),r=n===-1?0:n,o=e.tracks[r],s=(o.freq??1)-1,a=hs(e,o),i=e.tracks.filter((d,f)=>f!==r).map(d=>us(a,d));if(s>0&&i.push({...o,freq:s}),i.length===0)return;let{bands:c,total:l}=bn(e,i,"haplotype",t);return c.length>0?{ref:o,bands:c,total:l}:void 0}function us(e,t){let n=0;for(let r of t.indexSequence){let o=e[Math.abs(r)];o!==void 0&&o!==0&&(n+=o===Math.sign(r)?1:-1)}return n>=0?t:{...t,sequence:t.sequence.map(Ie).reverse(),indexSequence:t.indexSequence.map(r=>-r).reverse()}}function hs(e,t){let n=new Int8Array(e.nodes.length);for(let r of t.indexSequence){let o=Math.abs(r);n[o]===0&&(n[o]=Math.sign(r))}return n}function ps({count:e,total:t}){let n=e/t;return n<.01?"<1%":n>.99&&e<t?">99%":`${Math.round(n*100)}%`}var an=7;function cn(e,t,n,r,o,s,a,i,c,l){let d=t===1?e.extraRight:e.extraLeft,f=10*d[i],u=n+t*(f+5),m=an,p=Math.min(an,s),h=Math.min(r,o),g=Math.max(r,o),x=t===1?n:u-1,M=t===1?u:n,w=S=>{e.shapes.verticalRectangles.push({xStart:x,yStart:S,xEnd:M,yEnd:S+s-1,id:a,name:l,type:c})};w(r),e.shapes.verticalRectangles.push({xStart:t===1?u+m:u-m-p,yStart:h+s+m-1,xEnd:t===1?u+m+p-1:u-m-1,yEnd:g-m+1,id:a,name:l,type:c}),w(o);let b=u+t*m,E=u+t*(m+p),y=`M ${u} ${g}`;y+=` Q ${b} ${g} ${b} ${g-m}`,y+=` H ${E}`,y+=` Q ${E} ${g+s} ${u} ${g+s}`,y+=" Z ",e.shapes.corners.push({path:y,id:a,type:c}),y=`M ${u} ${h}`,y+=` Q ${E} ${h} ${E} ${h+s+m}`,y+=` H ${b}`,y+=` Q ${b} ${h+s} ${u} ${h+s}`,y+=" Z ",e.shapes.corners.push({path:y,id:a,type:c}),d[i]+=1}function ms(e){let t=e.x-4,n=e.x+e.pixelWidth+4;return[t,n]}function ln(e){switch(e.config.nodeWidthOption){case"compressed":e.nodes.forEach(t=>{t.width=1+Math.log2(Math.max(t.sequenceLength,1)),t.pixelWidth=Math.round((t.width-1)*8.401)});break;case"small":e.nodes.forEach(t=>{t.width=t.sequenceLength/100,t.pixelWidth=Math.max(Math.round((t.width-1)*8.401),0)});break;case"fixed":e.nodes.forEach(t=>{t.width=10,t.pixelWidth=Math.round(t.width*8.401)});break;case"normal":{let t=e.config.charWidth;e.nodes.forEach(n=>{n.width=n.sequenceLength,n.pixelWidth=Math.round(t*Math.max(n.sequenceLength-1,0))});break}default:throw new Error(`${e.config.nodeWidthOption} not implemented`)}}var L=0;function dn(e){return{first:new Int32Array(e),count:new Uint8Array(e)}}function N(e,t,n){let r=e.count[t];r===0?(e.first[t]=n,e.count[t]=1):r===1&&e.first[t]!==n&&(e.count[t]=2)}function W(e,t){return e.count[t]===1?Math.abs(e.first[t]):0}function gs(e){let t=dn(e.nodes.length),n=dn(e.nodes.length),r=new Map,o=f=>{let u=r.get(f);if(u===void 0){let m=e.nodeMap.get(A(f));u=O(f)?-m:m,r.set(f,u)}return u};e.tracks.concat(e.reads).forEach(f=>{let{sequence:u}=f,m=f.type==="haplotype",p=u.length-1,h=L,g=p>=0?o(u[0]):L;for(let x=0;x<=p;x+=1){let M=x<p?o(u[x+1]):L;if(g>0)x>0?(N(t,g,h),h<0&&N(t,g,-h)):m&&N(t,g,L),x<p?(N(n,g,M),M<0&&N(n,g,-M)):m&&N(n,g,L);else{let w=-g;x>0?(N(n,w,-h),h>0&&N(n,w,h)):m&&N(n,w,L),x<p?(N(t,w,-M),M>0&&N(t,w,M)):m&&N(t,w,L)}h=g,g=M}});let a=new Uint8Array(e.nodes.length);e.nodes.forEach((f,u)=>{xs(u,t,n)!==0&&(a[u]=1)});let i=new Int32Array(e.nodes.length),c=new Float64Array(e.nodes.length),l=new Float64Array(e.nodes.length);e.nodes.forEach((f,u)=>{if(a[u]!==1){i[u]=u,l[u]=f.sequenceLength;for(let m=u;ys(m,t,n);)m=W(n,m),i[m]=u,c[m]=f.sequenceLength,f.sequenceLength+=e.nodes[m].sequenceLength,f.seq+=e.nodes[m].seq,l[m]=f.sequenceLength}}),e.reads.forEach(f=>{let{sequence:u}=f,m=f.sequenceNew??u.map(w=>({nodeName:w,mismatches:[]})),p=w=>{let b=Math.abs(o(w));return O(w)?e.nodes[i[b]].sequenceLength-l[b]:c[b]},h=u.length-1;f.firstNodeOffset=(f.firstNodeOffset??0)+p(u[0]),f.finalNodeCoverLength=(f.finalNodeCoverLength??0)+p(u[h]);let g=[],x=[],M=[];u.forEach((w,b)=>{let E=Math.abs(o(w)),{mismatches:y}=m[b],S=p(w);if(y.forEach(v=>{v.pos+=S}),a[E]===1&&!O(w)&&b>0)x.at(-1).mismatches.push(...y);else if(a[E]===1&&O(w)&&b<h)M.push(...y);else{let v=e.nodes[i[E]].name,_=O(w)?mn(v):v;g.push(_),x.push({nodeName:_,mismatches:M.concat(y)}),M=[]}}),f.sequence=g,f.sequenceNew!==void 0&&(f.sequenceNew=x)}),e.tracks.forEach(f=>{let{sequence:u}=f,m=0;for(let p of u)a[Math.abs(o(p))]===0&&(u[m]=p,m+=1);u.length=m});let d=1;for(let f=1;f<e.nodes.length;f+=1)a[f]===0&&(e.nodes[d]=e.nodes[f],d+=1);e.nodes.length=d}function xs(e,t,n){let r=W(t,e);return r!==0&&W(n,r)!==0?r:0}function ys(e,t,n){let r=W(n,e);return r!==0&&W(t,r)!==0}function bs(e,t){let n=new Map;for(let r of e){let o=t(r),s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}return n}function Ms(e,t){return e.xStart<t.xStart?1:e.xStart>t.xStart?-1:e.yStart>t.yStart?1:e.yStart<t.yStart?-1:0}function Be(e){return[e.nodeStart??-1,e.nodeEnd??-1,e.nodeStart===null?e.orderStart:-1,e.nodeEnd===null?e.orderEnd:-1]}function ws(e,t){for(let n=0;n<e.length;n+=1){let r=e[n]-t[n];if(r!==0)return r}return 0}function Mn(e,t){let n=bs(e.filter(r=>r.type===t),r=>Be(r).join(","));return n.forEach(r=>{let o=.3,s=.4/r.length;r.length<=5&&(o=.5,s=0),r.sort(Ms),r.forEach(a=>{let i,c;a.yStart<a.yEnd?(i=a.xStart+(a.xEnd-a.xStart)*(1-o),o+=s,c=a.xStart+(a.xEnd-a.xStart)*(1-o)):(i=a.xStart+(a.xEnd-a.xStart)*o,o+=s,c=a.xStart+(a.xEnd-a.xStart)*o);let l=`M ${a.xStart} ${a.yStart}`;l+=` C ${i} ${a.yStart} ${i} ${a.yEnd} ${a.xEnd} ${a.yEnd}`,l+=` V ${a.yEnd+a.width}`,l+=` C ${c} ${a.yEnd+a.width} ${c} ${a.yStart+a.width} ${a.xStart} ${a.yStart+a.width}`,l+=" Z",a.path=l})}),[...n.values()].sort((r,o)=>ws(Be(r[0]),Be(o[0]))).flat()}function wn(e){let t=`M ${e.x-9} ${e.y} Q ${e.x-9} ${e.y-9} ${e.x} ${e.y-9}`,n=e.x,r=e.y-9;return e.width>1&&(n+=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n+9} ${r} ${n+9} ${r+9}`,n+=9,r+=9,e.contentHeight>0&&(r+=e.contentHeight,t+=` L ${n} ${r}`),t+=` Q ${n} ${r+9} ${n-9} ${r+9}`,n-=9,r+=9,e.width>1&&(n-=e.pixelWidth,t+=` L ${n} ${r}`),t+=` Q ${n-9} ${r} ${n-9} ${r-9}`,n-=9,r-=9,e.contentHeight>0&&(r-=e.contentHeight,t+=` L ${n} ${r}`),t}function Es(e,t){let n=[],r=e.sequenceNew??[];return r.forEach((o,s)=>{let a=t.nodeMap.get(A(o.nodeName)),i=a===void 0?void 0:t.nodes[a],c=s;for(;c<e.path.length&&e.path[c].node!==a;)c+=1;let l=e.path[c]?.y;if(i&&l!==void 0){let d={readId:e.id,y:l,height:e.width,nodeY:i.y},f=u=>xn(i,u);for(let u of o.mismatches){let m=f(u.pos);if(m!==null){if(u.type==="insertion"){let p=s===0&&u.pos===e.firstNodeOffset||s===r.length-1&&u.pos===e.finalNodeCoverLength;n.push({...d,kind:"insertion",x:m,seq:u.seq,softClip:p})}else if(u.type==="deletion"&&u.length!==void 0){let p=f(u.pos+u.length);p!==null&&n.push({...d,kind:"deletion",x0:m,x1:p})}else if(u.type==="substitution"&&u.seq!==void 0){let p=f(u.pos+u.seq.length);p!==null&&n.push({...d,kind:"substitution",x0:m,x1:p,seq:u.seq})}}}}}),n}function En(e){return e.reads.flatMap(t=>Es(t,e))}function Fe(e){let t=e.trim().split(/[\s,]+/),n=[],r=0,o=()=>Number(t[r++]);for(;r<t.length;){let s=t[r++];s==="M"||s==="L"?n.push({op:s,x:o(),y:o()}):s==="H"?n.push({op:s,x:o()}):s==="V"?n.push({op:s,y:o()}):s==="Q"?n.push({op:s,x1:o(),y1:o(),x:o(),y:o()}):s==="C"?n.push({op:s,x1:o(),y1:o(),x2:o(),y2:o(),x:o(),y:o()}):s==="Z"&&n.push({op:s})}return n}function Nn(e){let t=1/0,n=-1/0;for(let r of e)"x"in r&&(t=Math.min(t,r.x),n=Math.max(n,r.x)),"x1"in r&&(t=Math.min(t,r.x1),n=Math.max(n,r.x1));return{x0:t,x1:n}}function Sn(e,t,n){let r=Fe(e);return{commands:r,color:t,track:n,...Nn(r)}}function On(e,t){return new Map(e.tracks.map(n=>[n.id,n.type==="read"?tt(n):t[n.id]]))}function vn(e,t,n){let{shapes:r}=e,o=l=>n.get(l.id),s=l=>t==="haplotype"?l.id:void 0,a=[...r.rectangles,...r.verticalRectangles].filter(l=>l.type===t).map(l=>({color:o(l),track:s(l),x0:l.xStart,x1:l.xEnd+1,y0:l.yStart,y1:l.yEnd+1})),i=Mn(r.curves,t).map(l=>Sn(l.path,o(l),s(l))),c=r.corners.filter(l=>l.type===t).map(l=>Sn(l.path,o(l),s(l)));return{rects:a,shapes:[...i,...c]}}function Ss({layout:e,pathColors:t}){let n=On(e,t),r=[];return e.nodes.forEach(o=>{if(o.order>=0){let s=Fe(wn(o));r.push({name:o.name,commands:s,...Nn(s)})}}),{bounds:e.bounds,layers:[vn(e,"haplotype",n),vn(e,"read",n)],nodes:r,mismatches:En(e).filter(o=>o.kind!=="insertion"||!o.softClip)}}function Rn(e,t,n,r){let o=0,s=0;for(let a of t)switch(a.op){case"M":o=a.x,s=a.y,e.moveTo(n(o),r(s));break;case"L":o=a.x,s=a.y,e.lineTo(n(o),r(s));break;case"H":o=a.x,e.lineTo(n(o),r(s));break;case"V":s=a.y,e.lineTo(n(o),r(s));break;case"Q":o=a.x,s=a.y,e.quadraticCurveTo(n(a.x1),r(a.y1),n(o),r(s));break;case"C":o=a.x,s=a.y,e.bezierCurveTo(n(a.x1),r(a.y1),n(a.x2),r(a.y2),n(o),r(s));break;case"Z":e.closePath();break}}function _n(e,t,n,r,o){let s=new Map;for(let a of t)if(n(a)){let i=r(a),c=s.get(i);c?c.push(a):s.set(i,[a])}for(let a of s.values()){e.fillStyle=r(a[0]),e.beginPath();for(let i of a)o(i);e.fill()}}var vs=12,Rs=.15;function _s(e){return Math.max(Rs,Math.min(1,e/vs))}var Ns=.55;function Os(e,t,n){let{x:r,y:o,width:s}=n,a=d=>r(d.x1)>=0&&r(d.x0)<=s,i=d=>d.track!==void 0&&n.tubeColors?.[d.track]||d.color;e.globalAlpha=1;for(let d of t.layers)_n(e,d.rects,a,i,f=>{let u=r(f.x0),m=o(f.y0);e.rect(u,m,r(f.x1)-u,o(f.y1)-m)}),_n(e,d.shapes,a,i,f=>{Rn(e,f.commands,r,o)});let c=n.darkMode?"#d0d0d0":"#000000",l=n.darkMode?"rgba(40,40,40,0.4)":"rgba(255,255,255,0.4)";e.lineWidth=2*Math.max(.25,Math.min(1,n.yScale));for(let d of t.nodes)if(a(d)){let f=d.name===n.highlightNode;e.beginPath(),Rn(e,d.commands,r,o);let u=f?void 0:n.nodeColors?.get(d.name);e.fillStyle=f?"rgba(255,192,203,0.5)":u??l,e.strokeStyle=f?"#ff0000":c,e.globalAlpha=u?Ns:1,e.fill(),e.globalAlpha=f?1:_s(r(d.x1)-r(d.x0)),e.stroke(),e.globalAlpha=1}Ts(e,t.mismatches,n)}var An=12,As=6;function Tn(e){return An*e>=As}function De(e,{x:t,width:n}){let[r,o]=e.kind==="insertion"?[e.x,e.x]:[e.x0,e.x1];return t(o)>=0&&t(r)<=n}function Ts(e,t,n){let{x:r,y:o,yScale:s,darkMode:a}=n;if(!Tn(s)||t.length===0)return;let i=An*s;e.fillStyle="grey",e.beginPath();for(let c of t)if(c.kind==="deletion"&&De(c,n)){let l=r(c.x0),d=o(c.y);e.rect(l,d,r(c.x1)-l,o(c.y+c.height)-d)}e.fill(),e.font=`${i}px monospace`,e.textBaseline="alphabetic",e.fillStyle=a?"#ffffff":"#000000";for(let c of t)De(c,n)&&(c.kind==="substitution"?e.fillText(c.seq,r(c.x0)+1,o(c.y+c.height)):c.kind==="insertion"&&e.fillText("*",r(c.x)-3,o(c.y+c.height)))}function Cs(e,t){let n=[];for(let r of t){let o=e.get(r.refName),s=o?.[0],a=o?.at(-1);if(!o||!s||!a)continue;let i=Math.max(r.start,s.bp0),c=Math.min(r.end,a.bp1);c<=i||n.push({gene:r,...se(o,i,c),exons:r.exons.filter(l=>l.end>i&&l.start<c).map(l=>se(o,Math.max(l.start,i),Math.min(l.end,c)))})}return n}var Ye=22,ks=4,ce=8,$s="11px sans-serif",Is=8;function Ls(e){let t=e.flatMap(o=>[{x:o.x0,step:1},{x:o.x1,step:-1}]).sort((o,s)=>o.x-s.x||o.step-s.step),n=0,r=0;for(let{step:o}of t)n+=o,r=Math.max(r,n);return Math.min(ks,r)}function Ps(e,t,n,r,o=0){let{x:s,width:a,darkMode:i}=n,c=Math.max(1,Math.floor((r-o)/Ye)),l=[],d=i?"#e0e0e6":"#1c1c22";e.font=$s,e.textAlign="center",e.textBaseline="alphabetic",e.fillStyle=d,e.strokeStyle=d,e.lineWidth=1;let f=t.map(u=>({g:u,s0:s(u.x0),s1:s(u.x1)})).filter(({s0:u,s1:m})=>m>=0&&u<=a).sort((u,m)=>u.s0-m.s0);for(let{g:u,s0:m,s1:p}of f){let h=u.gene.strand>0?" \u2192":u.gene.strand<0?"\u2190 ":"",g=u.gene.strand<0?`${h}${u.gene.name}`:`${u.gene.name}${h}`,x=(Math.max(m,0)+Math.min(p,a))/2,M=e.measureText(g).width/2,w=Math.min(m,x-M),b=Math.max(p,x+M),E=l.findIndex(S=>S+Is<=w);E===-1&&(E=Math.min(l.length,c-1)),l[E]=Math.max(l[E]??-1/0,b);let y=r-E*Ye-ce/2;e.beginPath(),e.moveTo(m,y+.5),e.lineTo(p,y+.5),e.stroke();for(let S of u.exons){let v=s(S.x0);e.fillRect(v,y-ce/2,Math.max(1,s(S.x1)-v),ce)}e.fillText(g,x,y-ce/2-2)}}var T=12,Ln=T+8,Pn=8,Cn=Pn+3,Xs=12;function qs(e,{colorScheme:t,referenceRamp:n,walks:r}){let o={...he(e),referenceRamp:n},s=[];return e.nodes.forEach((a,i)=>{if(C(a)){let c=r?r.map(l=>{let d=l.colors.get(a.id);return d===void 0?V:I(d)}):[I(pe(a,i,t,o))];s.push({node:a.id,bp0:a.stable.start,bp1:a.stable.start+a.length,colors:c,faded:c.includes(V)})}}),s.sort((a,i)=>a.bp0-i.bp0)}function We(e,t,n){let r=t*e.scale+e.translateX,o=n*e.scale+e.translateX;return r<o?[r,o]:[o,r]}var kn=2;function Xn(e,t,n){let r=-t.translateX/t.scale,o=(n-t.translateX)/t.scale,s=Math.min(r,o),a=Math.max(r,o),i=0,c=0;for(let l of e)i+=Math.max(0,Math.min(l.bp1,s)-l.bp0),c+=Math.max(0,l.bp1-Math.max(l.bp0,a));return t.scale>=0?{left:Math.round(i),right:Math.round(c)}:{left:Math.round(c),right:Math.round(i)}}function Bs(e,t,n,r){if(r<0||r>T+kn)return;let o,s=kn;for(let a of e){let[i,c]=We(t,a.bp0,a.bp1),l=Math.max(0,i-n,n-c);l<=s&&(s=l,o=a.node)}return o}function Ds(e,t){let n=e?.[Math.floor(e.length/2)];return n?t(n):void 0}function qn(e,t,n,r){let o=e.map(l=>{let[d,f]=We(t,l.bp0,l.bp1),u=Math.round(d*r);return{colors:l.colors,x0:d,px0:u,px1:Math.max(Math.round(f*r),u+1)}}).filter(l=>l.px1>0&&l.px0<n*r).sort((l,d)=>l.x0-d.x0),s=[],a=-1/0,i=[-1/0,-1/0];for(let{colors:l,px0:d,px1:f}of o){let u=Math.max(d,a);if(f>u){let m=i[0]<u?0:1;i[m]=f,s.push({colors:l,x0:u/r,x1:f/r,tier:m}),a=f}}return(s.length>0?s.at(-1).x1-s[0].x0:0)>=s.length*Xs?s:s.map(({tier:l,...d})=>d)}function $n(e,t,n,r){let o=n>0?t:t-Cn;e.clearRect(o,0,Cn,T);let s=t+n,a=s+n*Pn;e.beginPath(),e.moveTo(s,T/2),e.lineTo(a,0),e.lineTo(a,T),e.closePath(),e.fillStyle=r,e.fill()}function In(e,t,n){return Math.round(e*T*n/t)/n}function Fs(e,t,n,{width:r,lit:o,darkMode:s,dpr:a=1}){let i=s?"#ffffff":"#18181c";e.clearRect(0,0,r,Ln);for(let l of qn(t,n,r,a)){let{tier:d}=l,f=d!==void 0&&l.colors.length===1,u=f?2:l.colors.length;l.colors.forEach((m,p)=>{let h=f?d:p,g=In(h,u,a);e.fillStyle=m,e.fillRect(l.x0,g,l.x1-l.x0,In(h+1,u,a)-g)})}let c=Xn(t,n,r);if(c.left>0&&$n(e,0,1,i),c.right>0&&$n(e,r,-1,i),o){let[l,d]=We(n,o.start,o.end),f=Math.max(d-l,3),u=(l+d)/2-f/2;e.strokeStyle=i,e.lineWidth=1.5,e.strokeRect(u,.75,f,T-1.5),o.anchor&&(e.beginPath(),e.moveTo(u+f/2,T),e.lineTo(o.anchor.x,o.anchor.y),e.lineWidth=1,e.stroke())}}function Ys(e,t){return Math.abs(t-e)<=.1*Math.max(e,t)}function Ws(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0)),s=Array.from({length:n+1},()=>new Array(r+1).fill(!1));for(let i=n-1;i>=0;i--)for(let c=r-1;c>=0;c--){let l=Math.abs(e[i]-t[c])+o[i+1][c+1],d=n-i>r-c?o[i+1][c]:1/0,f=r-c>n-i?o[i][c+1]:1/0;o[i][c]=Math.min(l,d,f),s[i][c]=o[i][c]===l}let a=new Array(n).fill(void 0);for(let i=0,c=0;i<n&&c<r;)s[i][c]?a[i++]=c++:n-i>r-c?i++:c++;return a}function Bn(e,t){return e.map((n,r)=>({item:n,i:r})).sort((n,r)=>t(n.item)-t(r.item))}var Fn=e=>e.spanningReads!==0;function Dn(e,t){return{...t,agrees:e.complete&&Fn(t)?Ys(e.bp,t.bp):void 0}}function Hs(e,t){let n=new Map,r=new Set;e.forEach((i,c)=>{let l=t.find(d=>d.haplotype!==void 0&&d.haplotype===i.haplotype);l&&(r.add(l),n.set(c,Dn(i,l)))});let o=t.filter(i=>i.haplotype===void 0),s=Bn(e,i=>i.bp),a=[[s.filter(i=>i.item.complete),o.filter(Fn)],[s,o]];for(let[i,c]of a){let l=i.filter(f=>!n.has(f.i)),d=Bn(c.filter(f=>!r.has(f)),f=>f.bp);Ws(l.map(f=>f.item.bp),d.map(f=>f.item.bp)).forEach((f,u)=>{if(f!==void 0){let m=l[u],p=d[f].item;r.add(p),n.set(m.i,Dn(m.item,p))}})}return n}function Cl(e,t){if(!t)return e;let n=new Map,r=new Map;for(let o of e)r.set(o.sample,[...r.get(o.sample)??[],o]);for(let[o,s]of r){let a=t[o];if(a)for(let[i,c]of Hs(s,a))n.set(s[i],c)}return e.map(o=>({...o,call:n.get(o)}))}export{ar as a,Gn as b,Un as c,Us as d,jn as e,Vn as f,qc as g,J as h,me as i,ee as j,Zn as k,Jn as l,eo as m,to as n,ie as o,Mc as p,wc as q,Ec as r,Sc as s,vc as t,$ as u,io as v,co as w,lo as x,fo as y,st as z,R as A,po as B,Y as C,ve as D,Re as E,ct as F,Me as G,xo as H,yo as I,ht as J,Eo as K,mt as L,gt as M,_e as N,So as O,vo as P,_o as Q,Et as R,pi as S,Ao as T,yi as U,bi as V,Ae as W,$o as X,Io as Y,Ti as Z,It as _,Ci as $,Lt as aa,Te as ba,Pt as ca,Xt as da,zo as ea,jo as fa,Vo as ga,Dt as ha,or as ia,lr as ja,dr as ka,ur as la,hr as ma,Ss as na,Os as oa,Tn as pa,De as qa,Cs as ra,Ye as sa,Ls as ta,Ps as ua,Ln as va,qs as wa,Xn as xa,Bs as ya,Ds as za,Fs as Aa,mc as Ba,ir as Ca,gc as Da,Cl as Ea};
2
+ //# sourceMappingURL=chunk-GB7CF6Z2.js.map