import{cP as e,cQ as n}from"./index-D_yusBPL.js";function t(e){const n=String(e.name||e.path?.split(/[\\/]/).pop()||"import.dat");if("string"!=typeof e.base64)throw new Error(e.error||"open file failed");const t=function(e){const n=atob(e.replace(/\s+/g,"")),t=new Uint8Array(n.length);for(let r=0;r<n.length;r+=1)t[r]=n.charCodeAt(r);return t}(e.base64),r=new ArrayBuffer(t.length);return new Uint8Array(r).set(t),new File([r],n,{type:e.mime||"application/octet-stream"})}function r(e){return new Promise(n=>{const t=document.createElement("input");let r,i=!1;const o=e=>{i||(i=!0,void 0!==r&&(window.clearTimeout(r),r=void 0),t.onchange=null,t.removeEventListener("cancel",a),window.removeEventListener("focus",c,!0),t.remove(),n(e))},a=()=>{t.value="",o(null)},c=()=>{i||(void 0!==r&&window.clearTimeout(r),r=window.setTimeout(()=>{i||a()},500))};t.type="file",t.style.display="none",e.accept?.trim()&&(t.accept=e.accept.trim()),t.onchange=()=>{const e=t.files?.[0]??null;t.value="",o(e)},t.addEventListener("cancel",a),window.addEventListener("focus",c,!0),document.body.appendChild(t),t.click()})}async function i(n={}){const i=await e({accept:n.accept});if(i){if(i.canceled)return null;if(i.ok)return t(i);throw new Error(i.error||"open file failed")}return await r(n)}async function o(e){const r=String(e.path||"").trim();if(!r)return null;const i=await n(r);if(!i)return null;if(i.canceled)return null;if(i.ok)return t({...i,name:i.name||e.name,path:i.path||r});throw new Error(i.error||"open file failed")}async function a(n={}){const t=await e({accept:n.accept,readContent:!1});if(t){if(t.canceled)return null;if(t.ok)return function(e){const n=String(e.path||"").trim();if(!n)throw new Error(e.error||"open file failed");const t=String(e.name||n.split(/[\\/]/).pop()||"import.dat");return{desktopPath:n,name:t,mime:e.mime||void 0,size:"number"==typeof e.size?e.size:void 0}}(t);throw new Error(t.error||"open file failed")}const i=await r(n);return i?{file:i,name:i.name,mime:i.type||void 0,size:i.size}:null}export{a,i as p,o as r};
