const l=`(function(){"use strict";function D(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 O(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 j(t,e){return t.length===0?-1:e<=t[0]?0:e>=t[t.length-1]?t.length-1:D(t,e)-1}class E{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 E(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 H(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 L={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=>H(t,e=>e.span),first:t=>t.length===0?null:t.reduce((e,n)=>n.s<e.s?n:e,t[0])};function J(t){return L[t]||L.largestSpan}function N(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 Q(t,e,n,s={}){const{selectionStrategy:l="largestSpan",viewportStart:i=null,viewportEnd:d=null,prevLocalBins:b=null,minStart:z=null,maxEnd:C=null}=s,F=new Set,_=1.05,g=[],f=t.size;if(f===0)return{return_local_bins:t,displayArray:g,showingAllTrees:!1};const M=n/e,h=M<1,x=J(l),m=new E;let a=z,v=C;if(a===null||v===null){a=1/0,v=-1/0;for(const r of t.values())r.s<a&&(a=r.s),r.e>v&&(v=r.e)}const B=h?f:Math.max(1,Math.max(10,Math.ceil(f/M))),q=Math.min(f,B),X=h;if(h){const o=i??a,V=d??v,c=(V-o)/e/f*.9,u=(V-o)/f;let S=0;for(const[y,w]of t.entries()){if(f===1&&b&&b.has(y)){const W=b.get(y);t.set(y,{...W})}else{const tt=(o+(S+.5)*u)/e-c/2,et=m.clone().translate([tt,0,0]).scale([c,1,1]);t.set(y,{...w,modelMatrix:et,visible:!0,position:w.s,span:w.span,precision:2,slotIndex:S,isRepresentative:!0,groupSize:1})}g.push(y),S++}return{return_local_bins:t,displayArray:g,showingAllTrees:X}}const R=i??a,A=((d??v)-R)/q,I=new Map;for(const r of t.values()){const o=Math.min(q-1,Math.max(0,Math.floor((r.midpoint-R)/A)));I.has(o)||I.set(o,[]),I.get(o).push(r)}const Z=new Set,k=A/e/_;for(const[r,o]of I.entries()){const G=R+r*A+A/2;let c;if(l==="centerWeighted"?c=x(o,G):c=x(o),c){const u=c.global_index;Z.add(u);const S=N(o.length,M),w=G/e-k/2,W=m.clone().translate([w,0,0]).scale([k,1,1]);t.set(u,{...c,modelMatrix:W,visible:!0,position:c.s,span:c.span,precision:S,slotIndex:r,isRepresentative:!0,groupSize:o.length}),g.push(u)}for(const u of o)Z.has(u.global_index)||(F.add(u.global_index),t.set(u.global_index,{...u,modelMatrix:null,visible:!1,position:null,span:null,path:null,precision:null,slotIndex:r,isRepresentative:!1,groupSize:o.length}))}return{return_local_bins:t,displayArray:g,invisibleKeys:F,showingAllTrees:X}}let T=null,p=null,K=null;const Y=async t=>{if(T=t.data,T?.intervals){let e=T.intervals;e.length>0&&Array.isArray(e[0])?p=e.map(n=>n[0]):p=e}else p=[]};function $(t,e){if(!p||p.length===0)return{visibleIntervals:[],lo:0,hi:0};const n=j(p,t),s=O(p,e);return{visibleIntervals:p.slice(n,s+1),lo:n,hi:s+1}}function U(t){return Array.from(t.entries()).map(([e,n])=>({key:e,...n,modelMatrix:n.modelMatrix?n.modelMatrix.toArray():null}))}function P(t){const{intervals:e,lo:n=0,start:s,end:l,globalBpPerUnit:i,new_globalBp:d,genome_length:b,displayOptions:z={}}=t,{selectionStrategy:C="largestSpan",showing_all_trees:F=!1}=z;if(!e||e.length===0)return{local_bins:[],displayArray:[],showing_all_trees:!1};const _=new Map;for(let h=0;h<e.length-1;h++){const x=n+h,m=e[h],a=e[h+1];_.set(x,{s:m,e:a,span:a-m,midpoint:(m+a)/2,path:null,global_index:x,precision:null})}const{return_local_bins:g,displayArray:f,showingAllTrees:M}=Q(_,i,d,{selectionStrategy:C,viewportStart:s,viewportEnd:l,prevLocalBins:K,minStart:e[0],maxEnd:e[e.length-1]});return K=g,{local_bins:U(g),displayArray:f,showing_all_trees:M}}onmessage=async t=>{const{type:e,id:n,data:s}=t.data;if(e==="config"&&(await Y({data:s}),postMessage({type:"config",id:n,data:null})),e==="intervals"){const{start:l,end:i}=s,d=$(l,i);postMessage({type:"intervals",id:n,data:d})}if(e==="local-data"){const l=P(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};
