const r=`(function(){"use strict";let l=null,w=null,m=null,A=null,B=null;const H=1.5,j=1e3;function F(a,s,i){if(!a||a.length<s){const r=Math.max(j,Math.ceil(s*H));return new i(r)}return a}function J(a,s,i,r,n,o,d,f){const y=new Map,C=a.length,M=new Map;if(f&&Array.isArray(f)){const e=[...new Set(r)].sort((h,S)=>h-S);e.length>0&&e[0]===0&&!f.includes(0)&&f.length===e.length&&f.forEach((h,S)=>{M.set(S,h)})}for(let e=0;e<C;e++){const p=r[e],h=M.has(p)?M.get(p):p;y.has(h)||y.set(h,[]),y.get(h).push({node_id:a[e],parent_id:s[e],is_tip:i[e],x:n[e],y:o[e],name:d?.[e]||""})}return y}function K(a,s,i){const r=new Map,n=i?.length||0;for(let o=0;o<n;o++){const d=i[o];r.has(d)||r.set(d,[]),r.get(d).push({x:a[o],y:s[o]})}return r}function L(a,s,i,r,n){const o=r?.colorBy;if(!o||!s?.[o]||!i?.[o])return n;const{uniqueValues:d,indices:f,nodeIdToIdx:y}=s[o],C=y?.get(a);if(C===void 0)return n;const M=f[C],e=d[M];if(!r.enabledValues?.includes(e))return[150,150,150,100];const p=i[o][e];return p?[...p.slice(0,3),200]:n}function Q(a){const{node_id:s,parent_id:i,is_tip:r,tree_idx:n,x:o,y:d,name:f,mut_x:y,mut_y:C,mut_tree_idx:M,modelMatrices:e,displayArray:p,metadataArrays:h,metadataColors:S,populationFilter:tt}=a,R=new Map;if(e&&Array.isArray(e))for(const c of e)c.modelMatrix&&R.set(c.key,c.modelMatrix);if(!s||s.length===0||R.size===0)return{pathPositions:new Float64Array(0),pathStartIndices:[0],tipPositions:new Float64Array(0),tipColors:new Uint8Array(0),tipData:[],edgeData:[],edgeCount:0,tipCount:0,mutPositions:new Float64Array(0),mutCount:0};const W=J(s,i,r,n,o,d,f,p),X=K(y,C,M);let b=0,Z=0;for(const[c]of R){const U=W.get(c),I=X.get(c);U&&(b+=U.length),I&&(Z+=I.length)}const et=b*6,nt=b*2,ot=b*4,st=Z*2;l=F(l,et,Float64Array),w=F(w,nt,Float64Array),m=F(m,ot,Uint8Array),A=F(A,b+1,Uint32Array),B=F(B,st,Float64Array);const rt=[150,150,150,200];let _=0,z=0,P=0,k=0,v=0,E=0;A[v++]=0;const V=[],Y=[];for(const[c,U]of R){const I=W.get(c);if(!I||I.length===0)continue;const T=new Map;for(const t of I)T.set(t.node_id,{node_id:t.node_id,x:t.x,y:t.y,is_tip:t.is_tip,parent_id:t.parent_id,name:t.name,children:[]});for(const t of I)if(t.parent_id!==-1){const g=T.get(t.parent_id),u=T.get(t.node_id);g&&u&&g.children.push(u)}const q=U,N=q[0],O=q[12];for(const t of T.values()){if(t.children.length===0)continue;const g=t.y,u=t.x;for(const x of t.children){const G=x.y,it=x.x;l[_++]=g*N+O,l[_++]=u,l[_++]=G*N+O,l[_++]=u,l[_++]=G*N+O,l[_++]=it,A[v++]=_/2,Y.push({tree_idx:c,parent_id:t.node_id,child_id:x.node_id}),k++}}for(const t of T.values())if(t.is_tip){const g=t.y*N+O,u=t.x;w[z++]=g,w[z++]=u;const x=L(t.node_id,h,S,tt,rt);m[P++]=x[0],m[P++]=x[1],m[P++]=x[2],m[P++]=x[3]??200,V.push({node_id:t.node_id,tree_idx:c,position:[g,u],name:t.name})}const D=X.get(c);if(D&&D.length>0)for(const t of D){const g=t.y*N+O,u=t.x;B[E++]=g,B[E++]=u}}return{pathPositions:l.slice(0,_),pathStartIndices:Array.from(A.subarray(0,v)),tipPositions:w.slice(0,z),tipColors:m.slice(0,P),tipData:V,edgeData:Y,edgeCount:k,tipCount:z/2,mutPositions:B.slice(0,E),mutCount:E/2}}function $(){l=null,w=null,m=null,A=null,B=null}onmessage=a=>{const{type:s,id:i,data:r}=a.data;if(s==="compute-render-data")try{const n=Q(r),o=[n.pathPositions.buffer,n.tipPositions.buffer,n.tipColors.buffer,n.mutPositions.buffer];postMessage({type:"render-data-result",id:i,success:!0,data:n},o)}catch(n){console.error("[RenderWorker] Error computing render data:",n),postMessage({type:"render-data-result",id:i,success:!1,error:n.message})}s==="clear-buffers"&&($(),postMessage({type:"clear-buffers-result",id:i,success:!0}))}})();
`,o=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",r],{type:"text/javascript;charset=utf-8"});function s(n){let t;try{if(t=o&&(self.URL||self.webkitURL).createObjectURL(o),!t)throw"";const e=new Worker(t,{name:n?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(r),{name:n?.name})}}export{s as default};
