function s(e){if(!e)return 0;const a=(e.match(/[\u4e00-\u9fff]/g)||[]).length,r=e.length-a;return a+Math.ceil(r/4)}function n(e){const a=/^data:([^;,]+);base64,(.+)$/s.exec(e);if(!a)throw new Error("Invalid image data URL");return{mediaType:a[1],base64:a[2]}}function o(e){const a=e.endsWith("==")?2:e.endsWith("=")?1:0;return Math.max(0,Math.floor(e.length*3/4)-a)}async function i(e){return new Promise((a,r)=>{const t=new FileReader;t.onload=()=>{typeof t.result=="string"?a(t.result):r(new Error("Failed to convert image to data URL"))},t.onerror=()=>r(t.error||new Error("Failed to read image blob")),t.readAsDataURL(e)})}function d(e,a){const r=n(e),t=a?.mediaType||r.mediaType;return{dataUrl:e,mediaType:t,base64:r.base64,byteSize:o(r.base64),source:a?.source}}export{i as b,d,s as e};
