import{r as e}from"./chunk-DpFlLKUR.js";var t=e({addReferenceFromFileViaSw:()=>i,addReferenceFromImageUrlViaSw:()=>a,getReferenceAssetDataUrlViaSw:()=>r,listReferenceAssetsViaSw:()=>n});async function n(){let e=await chrome.runtime.sendMessage({type:`LIST_REFERENCE_ASSETS`});if(!e?.ok||!e.assets)throw Error(e?.error??`读取参考图列表失败`);return e.assets}async function r(e){let t=await chrome.runtime.sendMessage({type:`GET_REFERENCE_ASSET`,payload:{id:e}});if(!t?.ok||!t.dataUrl)throw Error(t?.error??`读取参考图失败`);return t.dataUrl}async function i(e){if(!e.type.startsWith(`image/`))throw Error(`请选择图片文件`);if(e.size>12*1024*1024)throw Error(`图片请小于 12MB`);let t=await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;if(typeof e!=`string`){n(Error(`图片读取失败`));return}let i=e.indexOf(`,`);if(i<0){n(Error(`图片读取失败`));return}t(e.slice(i+1))},r.onerror=()=>n(r.error??Error(`图片读取失败`)),r.readAsDataURL(e)}),n=await chrome.runtime.sendMessage({type:`ADD_REFERENCE_FROM_FILE`,payload:{base64:t,mimeType:e.type,name:e.name.replace(/\.[^.]+$/,``).trim()||e.name}});if(!n?.ok)throw Error(n?.error??n?.message??`上传参考图失败`);return{ok:!0,asset:n.asset,message:n.message}}async function a(e){let t=await chrome.runtime.sendMessage({type:`ADD_REFERENCE_FROM_URL`,payload:{url:e.trim()}});if(!t?.ok)throw Error(t?.error??t?.message??`加入参考图失败`);return{ok:!0,asset:t.asset,message:t.message}}export{t as i,a as n,n as r,i as t};