const l=`(function(){"use strict";function k(t,e){let n=0,s=t.length-1,l=t.length;for(;n<=s;){const i=n+s>>1;t[i]>=e?(l=i,s=i-1):n=i+1}return l}function D(t,e){let n=0,s=t.length;for(;n<s;){const l=n+s>>1;t[l]<=e?n=l+1:s=l}return n}function K(t,e){return t.length===0?-1:e<=t[0]?0:e>=t[t.length-1]?t.length-1:k(t,e)-1}class C{constructor(e=null){e?this.elements=new Float64Array(e):this.elements=new Float64Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}clone(){return new C(this.elements)}translate(e){const[n,s,l]=e;return this.elements[12]+=n,this.elements[13]+=s,this.elements[14]+=l,this}scale(e){const[n,s,l]=e;return this.elements[0]*=n,this.elements[5]*=s,this.elements[10]*=l,this}toArray(){return Array.from(this.elements)}}function N(t,e){if(t.length===0)return null;if(t.length===1)return t[0];const n=t.map(e),s=n.reduce((i,d)=>i+d,0);if(s===0)return t[0];let l=Math.random()*s;for(let i=0;i<t.length;i++)if(l-=n[i],l<=0)return t[i];return t[t.length-1]}const R={largestSpan:t=>t.length===0?null:t.reduce((e,n)=>n.span>e.span?n:e,t[0]),centerWeighted:(t,e)=>t.length===0?null:t.reduce((n,s)=>{const l=Math.abs(n.midpoint-e);return Math.abs(s.midpoint-e)<l?s:n},t[0]),spanWeightedRandom:t=>N(t,e=>e.span),first:t=>t.length===0?null:t.reduce((e,n)=>n.s<e.s?n:e,t[0])};function O(t){return R[t]||R.largestSpan}function j(t,e){if(t===1&&e<=1)return 3;const n=Math.log10(Math.max(1,t)),s=Math.log10(Math.max(1,e));return Math.max(1,Math.min(3,3-Math.floor(n+s/2)))}function H(t,e,n,s={}){const{selectionStrategy:l="largestSpan",viewportStart:i=null,viewportEnd:d=null,prevLocalBins:w=null}=s,b=new Set,E=1.05,v=[],x=n/e,M=x<1,_=O(l),A=new C,r=[];let m=1/0,y=-1/0;for(const[c,o]of t.entries()){const{s:p,e:g}=o,a=g-p,u=(p+g)/2;r.push({idx:Number(c),s:p,e:g,span:a,midpoint:u,bin:o}),m=Math.min(m,p),y=Math.max(y,g)}if(r.length===0)return{return_local_bins:t,displayArray:v,showingAllTrees:!1};r.sort((c,o)=>c.s-o.s);const B=M?r.length:Math.max(1,Math.max(10,Math.ceil(r.length/x))),L=Math.min(r.length,B),q=M;if(M){const o=i??m,p=d??y,a=(p-o)/e/r.length*.9,u=(p-o)/r.length;for(let S=0;S<r.length;S++){const h=r[S];if(r.length===1&&w&&w.has(h.idx)){const T=w.get(h.idx);t.set(h.idx,{...T})}else{const U=(o+(S+.5)*u)/e-a/2,P=A.clone().translate([U,0,0]).scale([a,1,1]);t.set(h.idx,{...h.bin,modelMatrix:P,visible:!0,position:h.s,span:h.span,precision:2,slotIndex:S,isRepresentative:!0,groupSize:1})}v.push(h.idx)}return{return_local_bins:t,displayArray:v,showingAllTrees:q}}const F=i??m,I=((d??y)-F)/L,W=new Map;for(const c of r){const o=Math.min(L-1,Math.max(0,Math.floor((c.midpoint-F)/I)));W.has(o)||W.set(o,[]),W.get(o).push(c)}const X=new Set,Z=I/e/E;for(const[c,o]of W.entries()){const g=F+c*I+I/2;let a;if(l==="centerWeighted"?a=_(o,g):a=_(o),a){X.add(a.idx);const u=j(o.length,x),h=g/e-Z/2,T=A.clone().translate([h,0,0]).scale([Z,1,1]);t.set(a.idx,{...a.bin,modelMatrix:T,visible:!0,position:a.s,span:a.span,precision:u,slotIndex:c,isRepresentative:!0,groupSize:o.length}),v.push(a.idx)}for(const u of o)X.has(u.idx)||(b.add(u.idx),t.set(u.idx,{...u.bin,modelMatrix:null,visible:!1,position:null,span:null,path:null,precision:null,slotIndex:c,isRepresentative:!1,groupSize:o.length}))}return{return_local_bins:t,displayArray:v,invisibleKeys:b,showingAllTrees:q}}let z=null,f=null,V=null;const J=async t=>{if(z=t.data,z?.intervals){let e=z.intervals;e.length>0&&Array.isArray(e[0])?f=e.map(n=>n[0]):f=e}else f=[]};function Q(t,e){if(!f||f.length===0)return{visibleIntervals:[],lo:0,hi:0};const n=K(f,t),s=D(f,e);return{visibleIntervals:f.slice(n,s+1),lo:n,hi:s+1}}function Y(t){return Array.from(t.entries()).map(([e,n])=>({key:e,...n,modelMatrix:n.modelMatrix?n.modelMatrix.toArray():null}))}function $(t){const{intervals:e,lo:n=0,start:s,end:l,globalBpPerUnit:i,new_globalBp:d,genome_length:w,displayOptions:b={}}=t,{selectionStrategy:E="largestSpan",showing_all_trees:v=!1}=b;if(!e||e.length===0)return{local_bins:[],displayArray:[],showing_all_trees:!1};const x=new Map;for(let r=0;r<e.length-1;r++){const m=n+r,y=e[r],G=e[r+1];x.set(m,{s:y,e:G,path:null,global_index:m,precision:null})}const{return_local_bins:M,displayArray:_,showingAllTrees:A}=H(x,i,d,{selectionStrategy:E,viewportStart:s,viewportEnd:l,prevLocalBins:V});return V=M,{local_bins:Y(M),displayArray:_,showing_all_trees:A}}onmessage=async t=>{const{type:e,id:n,data:s}=t.data;if(e==="config"&&(await J({data:s}),postMessage({type:"config",id:n,data:null})),e==="intervals"){const{start:l,end:i}=s,d=Q(l,i);postMessage({type:"intervals",id:n,data:d})}if(e==="local-data"){const l=$(s);postMessage({type:"local-data",id:n,data:l})}}})();
`,s=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",l],{type:"text/javascript;charset=utf-8"});function r(n){let e;try{if(e=s&&(self.URL||self.webkitURL).createObjectURL(s),!e)throw"";const t=new Worker(e,{name:n?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(l),{name:n?.name})}}export{r as default};
