/*! 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. */
(()=>{(()=>{if(!window.plupload||!plupload.Uploader||!window.BICR||!BICR.worker||plupload.Uploader.__bicrWrapped)return;let d=new WeakSet,s=new WeakMap,c=plupload.Uploader;function a(o){let e=new c(o);try{e.bind("FilesAdded",g,null,999),e.bind("FileUploaded",u)}catch{}return e}a.prototype=c.prototype;for(let o of Object.keys(c))try{a[o]=c[o]}catch{}a.__bicrWrapped=!0,plupload.Uploader=a;function u(o,e,i){try{let n=e.getNative?e.getNative():null,t=n&&s.get(n);if(!t)return;let r=f(i.response);r&&BICR.recordSaving(r,t.original,t.optimized)}catch{}}function f(o){let e=JSON.parse(o);return typeof e=="number"?e:e&&e.data&&e.data.id?e.data.id:0}function g(o,e){for(let i=e.length-1;i>=0;i--){let n=e[i],t=n.getNative?n.getNative():null;if(!(!t||d.has(t))){if(!BICR.shouldCompress(t)){d.add(t);continue}o.removeFile(n),e.splice(i,1),m(o,t,BICR.isConvert(t))}}}function m(o,e,i){BICR.worker.compress(e,BICR.cfg.opts||{}).then(n=>{let t=n==null?void 0:n.blob;if(!t||t.size>=e.size&&!i){p(o,e);return}let r=new File([t],BICR.outName(e,t),{type:t.type});d.add(r),s.set(r,{original:e.size,optimized:r.size}),o.addFile(r),B(e,r)}).catch(()=>p(o,e))}function p(o,e){d.add(e),o.addFile(e)}function B(o,e){var i,n;try{let t=Math.round((1-e.size/o.size)*100),h=(((i=BICR.cfg.i18n)==null?void 0:i.saved)||"ImReso: optimized %1$s \u2192 %2$s (saved %3$s%%)").replace("%1$s",l(o.size)).replace("%2$s",l(e.size)).replace("%3$s",String(t));(n=window.console)!=null&&n.info&&console.info(h)}catch{}}function l(o){return o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(0)} KB`:`${(o/1024/1024).toFixed(1)} MB`}})();})();
