/*! ImReso: Unlimited Target-Size Image Compressor — plugin code (c) ImageResizer.cc, GPLv2 or later. Bundled third-party code keeps its own licence: see licenses/ and readme.txt. */
(()=>{(()=>{let o=window.BICR_CFG||{};window.BICR=window.BICR||{};let d=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent||""),c=null,m=0,a=new Map,u=Promise.resolve();function w(){let r=new Worker(o.workerUrl,{type:"module"});return r.onmessage=e=>{let n=e.data||{},t=a.get(n.id);t&&(a.delete(n.id),n.error?t.reject(new Error(n.error)):t.resolve({blob:n.blob,meta:n.meta}))},r.onerror=()=>{a.forEach(e=>{e.reject(new Error("worker error"))}),a.clear(),c=null},r}function p(r,e){let n=u.then(()=>l(r,e));return u=n.then(()=>{},()=>{}),n}function l(r,e){if(typeof Worker>"u"||typeof OffscreenCanvas>"u")return Promise.reject(new Error("worker/OffscreenCanvas unsupported"));c||(c=w());let n=++m,t={id:n,file:r,opts:{format:(e==null?void 0:e.format)||"webp",quality:(e==null?void 0:e.quality)||72,maxDim:e&&typeof e.maxDim=="number"?e.maxDim:1920,targetBytes:e&&typeof e.targetBytes=="number"?e.targetBytes:0,noAvif:d}};return new Promise((i,s)=>{a.set(n,{resolve:i,reject:s}),c.postMessage(t)})}function f(r){let e=(r.name||"").toLowerCase(),n=(r.type||"").toLowerCase(),t=e.includes(".")?e.slice(e.lastIndexOf(".")+1):"",i=(s,B)=>s.test(n)||B.includes(t);return i(/^image\/(heic|heif)/,["heic","heif"])||i(/^image\/tiff/,["tif","tiff"])||i(/^image\/bmp/,["bmp"])?"convert":i(/^image\/(jpeg|png|webp|avif)$/,["jpg","jpeg","png","webp","avif"])?"recompress":"skip"}function g(r){return f(r)==="convert"}function C(r){let e=f(r);return e==="convert"?!0:e==="recompress"?r.size>(o.minBytes||10240):!1}function v(r,e){let n=(e.type.split("/")[1]||"img").replace("jpeg","jpg");return`${r.name.replace(/\.\w+$/,"")}.${n}`}function y(r,e,n){if(!o.ajax||!o.ajax.url||!r||!e||!n)return;let t=new FormData;t.append("action","bicr_record"),t.append("_wpnonce",o.ajax.nonce||""),t.append("attachment_id",String(r)),t.append("original",String(e)),t.append("optimized",String(n)),fetch(o.ajax.url,{method:"POST",credentials:"same-origin",body:t}).catch(()=>{})}window.BICR.worker={compress:p},window.BICR.shouldCompress=C,window.BICR.isConvert=g,window.BICR.outName=v,window.BICR.recordSaving=y,window.BICR.cfg=o})();})();
