const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./referenceAssetApi-DkwBTFi6.js","./chunk-DpFlLKUR.js"])))=>i.map(i=>d[i]);
import{t as e}from"./userFacingCopy-BFx0qruN.js";import{t}from"./preload-helper-1219HbaE.js";var n=`xyxp_reference_assets`,r=1,i=`assets`,a=1600,o=.82;function s(){return new Promise((e,t)=>{let a=indexedDB.open(n,r);a.onerror=()=>t(a.error??Error(`参考图库打开失败`)),a.onupgradeneeded=()=>{let e=a.result;if(!e.objectStoreNames.contains(i)){let t=e.createObjectStore(i,{keyPath:`id`});t.createIndex(`sourceUrl`,`sourceUrl`,{unique:!1}),t.createIndex(`createdAt`,`createdAt`,{unique:!1})}},a.onsuccess=()=>e(a.result)})}async function c(){let e=await s();return await new Promise((t,n)=>{let r=e.transaction(i,`readonly`),a=r.objectStore(i).getAll();a.onsuccess=()=>{let e=a.result??[];e.sort((e,t)=>t.createdAt.localeCompare(e.createdAt)),t(e)},a.onerror=()=>n(a.error??Error(`读取参考图失败`)),r.oncomplete=()=>e.close()})}async function l(e){let t=await s();return await new Promise((n,r)=>{let a=t.transaction(i,`readonly`),o=a.objectStore(i).get(e.trim());o.onsuccess=()=>n(o.result??null),o.onerror=()=>r(o.error??Error(`读取参考图失败`)),a.oncomplete=()=>t.close()})}async function u(e){let t=e.trim();return t?(await c()).find(e=>e.sourceUrl?.trim()===t)??null:null}async function d(e){let t=await s();return await new Promise((n,r)=>{let a=t.transaction(i,`readwrite`);a.objectStore(i).delete(e.trim()),a.oncomplete=()=>{t.close(),n()},a.onerror=()=>r(a.error??Error(`删除参考图失败`))})}function f(e){let t=new Date().toISOString(),n=e.sourceUrl?.trim(),r=e.name?.trim();if(!r&&n)try{r=new URL(n).pathname.split(`/`).pop()||`参考图`}catch{r=`参考图`}return{id:`ref_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`,name:r||`参考图 ${t.slice(0,16).replace(`T`,` `)}`,sourceUrl:n||void 0,dataUrl:e.dataUrl,width:0,height:0,createdAt:t}}async function p(e){let t=await createImageBitmap(await(await fetch(e)).blob());try{return{width:t.width,height:t.height}}finally{t.close()}}async function m(e,t){let n=new Uint8Array(await e.arrayBuffer()),r=``,i=32768;for(let e=0;e<n.length;e+=i)r+=String.fromCharCode(...n.subarray(e,e+i));return`data:${t};base64,${btoa(r)}`}async function h(e){let t=await createImageBitmap(await(await fetch(e)).blob());try{let e=Math.max(t.width,t.height),n=e>a?a/e:1,r=Math.max(1,Math.round(t.width*n)),i=Math.max(1,Math.round(t.height*n)),s=new OffscreenCanvas(r,i),c=s.getContext(`2d`);if(!c)throw Error(`无法处理图片`);return c.drawImage(t,0,0,r,i),await m(await s.convertToBlob({type:`image/jpeg`,quality:o}),`image/jpeg`)}finally{t.close()}}function g(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;if(typeof e!=`string`||!e.startsWith(`data:`)){n(Error(`图片读取失败`));return}t(e)},r.onerror=()=>n(r.error??Error(`图片读取失败`)),r.readAsDataURL(e)})}var _=12*1024*1024;async function v(e){if(!e.type.startsWith(`image/`))throw Error(`请选择图片文件`);if(e.size>_)throw Error(`图片请小于 12MB`);return await y({dataUrl:await g(e),name:e.name.replace(/\.[^.]+$/,``).trim()||e.name})}async function y(e){let t=e.sourceUrl?.trim();if(t){let e=await u(t);if(e)return e}let n=await h(e.dataUrl.trim()),r=f({...e,dataUrl:n}),a=await p(n);r.width=a.width,r.height=a.height;let o=await s();return await new Promise((e,t)=>{let n=o.transaction(i,`readwrite`);n.objectStore(i).put(r),n.oncomplete=()=>{o.close(),e(r)},n.onerror=()=>t(n.error??Error(`保存参考图失败`))})}async function b(e){if(!e?.assetId?.trim())return;let n=await l(e.assetId);if(n?.dataUrl)return n.dataUrl;let{getReferenceAssetDataUrlViaSw:r}=await t(async()=>{let{getReferenceAssetDataUrlViaSw:e}=await import(`./referenceAssetApi-DkwBTFi6.js`).then(e=>e.i);return{getReferenceAssetDataUrlViaSw:e}},__vite__mapDeps([0,1]),import.meta.url);return await r(e.assetId)}var x=`xyxp_publish_batch`;function S(){return`batch-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function C(t,n){let r=new Date(n),i=String(r.getHours()).padStart(2,`0`),a=String(r.getMinutes()).padStart(2,`0`);return e.multiPublishTabGroup(t,i,a)}var w=1500,T=25e3;export{C as a,d as c,c as d,b as f,S as i,u as l,w as n,y as o,x as r,v as s,T as t,l as u};