(function(){"use strict";function C(c,y,r,M,n,f,T){const i=c.length;if(i===0)return null;const a=new Uint32Array(i),I=new Int32Array(i);let o=0;for(let e=0;e<i;e++){const t=c[e];t>=n&&t<=f&&r[e]>0&&(a[o]=e,I[o]=Math.floor((t-n)/300),o++)}if(o===0)return null;const d=new Map;for(let e=0;e<o;e++){const t=I[e];let s=d.get(t);s||(s=[],d.set(t,s)),s.push(e)}const u=new Float64Array(o);if(T==="share")for(let e=0;e<o;e++)u[e]=r[a[e]];else for(const[,e]of d){let t=0,s=0;for(const m of e){const g=y[a[m]];t+=g,g>s&&(s=g)}const b=t/3e5*100;if(s>0)for(const m of e)u[m]=y[a[m]]/s*b}let h=c[a[0]],A=c[a[0]];for(let e=1;e<o;e++){const t=c[a[e]];t<h&&(h=t),t>A&&(A=t)}const k=f-n||1,l=new Float64Array(o);for(let e=0;e<o;e++)l[e]=u[e];l.sort();const x=l[0],V=l[o-1],O=l[Math.floor(o*.05)],B=l[Math.floor(o*.5)],F=l[Math.min(Math.ceil(o*.95),o-1)],w=new Map;for(let e=0;e<o;e++){const t=Math.round(u[e]*100)/100;w.set(t,(w.get(t)??0)+1)}const N=w.size,R=[...w.entries()].sort((e,t)=>t[1]-e[1]).slice(0,5).map(([e,t])=>({value:e,count:t,percent:t/o*100})),D=0;let p;if(T==="share")p=240;else{const t=Math.ceil(V/5)*5;t<=10?p=10:p=t+5}const S=new Float32Array(o*2),_=new Float32Array(o),E=new Uint8Array(o),U=new Float32Array(o);for(let e=0;e<o;e++){const t=a[e],s=(c[t]-n)/k,m=1-Math.max(0,Math.min(p,u[e]))/p;S[e*2]=s,S[e*2+1]=m,_[e]=u[e],E[e]=M[t]<255?M[t]:255,U[e]=c[t]}return{points:S,rawValues:_,packetTypes:E,timestamps:U,count:o,minTime:h,maxTime:A,minValue:D,maxValue:p,rawMinValue:x,rawMaxValue:V,p5:O,p50:B,p95:F,uniqueValues:N,topValues:R}}self.onmessage=c=>{const{type:y,payload:r}=c.data;if(y!=="compute")return;const M=performance.now();try{const n=C(r.timestamps,r.airtimeMs,r.byteSizes,r.packetTypes,r.startTs,r.endTs,r.mode);if(!n){const a={type:"error",error:"No packets in time range"};self.postMessage(a);return}const f=performance.now()-M,T={type:"result",payload:n,computeTimeMs:f},i=[n.points.buffer,n.rawValues.buffer,n.packetTypes.buffer,n.timestamps.buffer];self.postMessage(T,i)}catch(n){const f={type:"error",error:n instanceof Error?n.message:String(n)};self.postMessage(f)}}})();
