1function w(b,n,o,e,a,i,h,c=2){const r=[],t=c,s=[[n+e*.2,o-t],[n+e*.4,o-t],[n+e*.6,o-t],[n+e*.8,o-t],[n+e*.2,o+a+t],[n+e*.4,o+a+t],[n+e*.6,o+a+t],[n+e*.8,o+a+t],[n-t,o+a*.2],[n-t,o+a*.5],[n-t,o+a*.8],[n+e+t,o+a*.2],[n+e+t,o+a*.5],[n+e+t,o+a*.8]];for(const[l,f]of s){const m=Math.max(0,Math.min(Math.round(l),i-1)),p=Math.max(0,Math.min(Math.round(f),h-1)),g=b.getImageData(m,p,1,1).data;r.push({r:g[0],g:g[1],b:g[2]})}r.sort((l,f)=>l.r+l.g+l.b-(f.r+f.g+f.b));const d=Math.floor(r.length/2);return r[d]}function I(b,n,o,e,a,i,h,c=2){const r=Math.max(0,Math.floor(n)-c),t=Math.max(0,Math.floor(o)-c),s=Math.min(i-r,Math.ceil(e)+c*2),d=Math.min(h-t,Math.ceil(a)+c*2);if(s<=0||d<=0)return;const l=b.getImageData(r,t,s,d),f=l.data,m=new Uint8ClampedArray(f);for(let p=c;p<d-c;p++)for(let g=c;g<s-c;g++){let u=0,C=0,v=0,M=0;for(let D=-c;D<=c;D++)for(let R=-c;R<=c;R++){const S=((p+D)*s+(g+R))*4;u+=m[S],C+=m[S+1],v+=m[S+2],M++}const x=(p*s+g)*4;f[x]=Math.round(u/M),f[x+1]=Math.round(C/M),f[x+2]=Math.round(v/M)}b.putImageData(l,r,t)}async function $(b,n,o=2){const e=await b.getPage(n),a=e.getViewport({scale:o}),i=document.createElement("canvas");i.width=a.width,i.height=a.height;const h=i.getContext("2d");h.fillStyle="#ffffff",h.fillRect(0,0,i.width,i.height),await e.render({canvasContext:h,viewport:a}).promise;const c=await e.getTextContent();for(const r of c.items){if(!r.str||!r.str.trim())continue;const t=r.transform,s=a.transform,d=s[0]*t[4]+s[2]*t[5]+s[4],l=s[1]*t[4]+s[3]*t[5]+s[5],m=(Math.sqrt(t[2]*t[2]+t[3]*t[3])||Math.abs(t[0]))*o,p=(r.width||0)*o;if(p<=0||m<=0)continue;const g=m*.2,u=d-g,C=l-m-g,v=p+g*2,M=m+g*2,x=w(h,u,C,v,M,i.width,i.height);h.fillStyle=`rgb(${x.r}, ${x.g}, ${x.b})`,h.fillRect(u,C,v,M),I(h,u,C,v,M,i.width,i.height,2)}return i.toDataURL("image/jpeg",.85)}export{$ as extractBackground};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.