"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=.7,d=1500;function l(a){return new Promise((r,t)=>{const e=new FileReader;e.onerror=()=>t(e.error??new Error("Failed to read image file.")),e.onload=()=>r(typeof e.result=="string"?e.result:""),e.readAsDataURL(a)})}function c(a){return new Promise((r,t)=>{const e=new Image;e.onerror=()=>t(new Error("Failed to load image file.")),e.onload=()=>r(e),e.src=a})}function m(a,r){const t=Math.min(1,d/Math.max(a,r));return{height:Math.max(1,Math.round(r*t)),width:Math.max(1,Math.round(a*t))}}async function g(a){var i;const r=await l(a);if(!a.type.startsWith("image/")||globalThis.document===void 0)return r;const t=await c(r),{height:e,width:n}=m(t.naturalWidth||t.width,t.naturalHeight||t.height),o=globalThis.document.createElement("canvas");return o.width=n,o.height=e,(i=o.getContext("2d"))==null||i.drawImage(t,0,0,n,e),o.toDataURL("image/jpeg",s)}exports.compressBEditorImageFile=g;
