/*! 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.wp||!wp.data||!wp.domReady||!window.BICR||!BICR.worker)return;wp.domReady(()=>{let e=!1,n=()=>{if(e)return;let o=wp.data.select("core/block-editor");if(!o||typeof o.getSettings!="function")return;let t=o.getSettings().mediaUpload;if(typeof t!="function"||t.__bicrWrapped)return;let r=s(t);r.__bicrWrapped=!0,e=!0,wp.data.dispatch("core/block-editor").updateSettings({mediaUpload:r}),e=!1,window.console&&console.info&&console.info("ImReso: block editor upload hooked.")};n(),wp.data.subscribe(n)});function s(e){return function(n){let o=n||{},t=o.filesList?Array.from(o.filesList):[];if(!t.length)return e.call(this,o);Promise.all(t.map(a)).then(r=>{let d=r.map(i=>i.saved);e.call(this,Object.assign({},o,{filesList:r.map(i=>i.file),onFileChange:i=>{c(i,d),typeof o.onFileChange=="function"&&o.onFileChange(i)}}))})}}function a(e){if(!BICR.shouldCompress(e))return Promise.resolve({file:e,saved:null});let n=BICR.isConvert(e);return BICR.worker.compress(e,BICR.cfg.opts||{}).then(o=>{let t=o&&o.blob;if(!t||t.size>=e.size&&!n)return{file:e,saved:null};let r=new File([t],BICR.outName(e,t),{type:t.type});return{file:r,saved:{original:e.size,optimized:r.size}}}).catch(()=>({file:e,saved:null}))}function c(e,n){Array.isArray(e)&&e.forEach((o,t)=>{let r=n[t];o&&o.id&&r&&!r.recorded&&(r.recorded=!0,BICR.recordSaving(o.id,r.original,r.optimized))})}})();})();
