import{p as C}from"./XWxoP7r2.js";import{_ as q,$,a0 as g,a1 as y,a2 as d,a3 as B}from"./Bxv1kRJt.js";function S(){const{storage:s}=q();async function K(t,e="",n=!1){const a=t.replaceAll("/",":");if(n)return await f(`${a}:.keep_dir`,""),a;{const o=g(a)||".md",i=$(a),r=i.split(":").map(w=>y(w,{lower:!1})).join(":"),c=a.replace(`${i}:`,"").replace(o,""),p=y(c);if(o===".md"){const{content:w,data:F}=C(e||""),j=`${c[0].toUpperCase()}${c.slice(1)}`;Object.keys(F).length||(e=["---",`title: ${j}`,"---","","## "].join(`
`)+w)}const _=(await m(`${r}:${p}${o}`)).replace(/^:/,"");return await f(_,e),_}}async function m(t){if(!await s.hasItem(t))return t;const e=$(t),n=d(t),a=g(t),o=n?.replace(a,""),i=await s.getKeys(e);let r=0;for(const c of i.filter(p=>!p.replace(`${e}:`,"").includes(":")))d(c)?.replace(/-\d\./,".")===n&&r++;return r?`${e}:${o}-${r}${a}`:t}async function I(t){const e=await s.getItem(t);return await K(await m(t),e)}async function h(t,e,n=!1){const a=g(e),o=e.replace(a,""),i=t.replace(/[^:]*$/,y(o)+a);if(n){const r=await s.getKeys(t);for(const c of r)await l(c,`${i}:${d(c)}`)}else return await l(t,i)}async function u(t,e=!1){if(!e)await s.removeItem(t);else{const n=await s.getKeys(t);for(const a of n)await s.removeItem(a)}}async function l(t,e){if(t===e)return;const n=await s.getItem(t);await u(t);const a=await m(e);return await f(a,n,{previousPath:t.endsWith(":.keep_dir")?null:t}),a}async function x(t,e){const n=$(t),a=await s.getKeys(t);if(a.length)for(const o of a){const i=o.replace(`${n}:`,"");await l(`${n}:${i}`,`${e}:${i}`)}else{const o=t.split(":").pop();return await l(t,`${e}:${o}`)}}async function b(t){const e=await s.getItem(t,{original:!0});e===null?await u(t):await f(t,e)}async function f(t,e,n){e instanceof Blob&&(e=await B(e)),await s.setItem(t,e,n)}return{newKey:K,duplicateKey:I,renameKey:h,removeKey:u,moveKey:x,restoreKey:b}}export{S as u};
