"use strict";exports.id=6041,exports.ids=[6041],exports.modules={36041:(a,b,c)=>{c.d(b,{O4:()=>B,e:()=>y,getPluginRegistry:()=>s,getThemeRegistry:()=>A,hy:()=>C,jH:()=>x,rO:()=>v,sd:()=>t,updatePluginMeta:()=>w,updateThemeMeta:()=>D,vc:()=>E,xP:()=>F});var d=c(51455),e=c(73024),f=c(77598),g=c(76760),h=c.n(g),i=c(76266),j=c(45580);function k(){return h().join((0,j.WI)(),"plugins")}function l(){return h().join((0,j.WI)(),"themes")}async function m(a){(0,e.existsSync)(a)||await (0,d.mkdir)(a,{recursive:!0})}async function n(a,b){try{let b=await (0,d.readFile)(a,"utf-8");return JSON.parse(b)}catch(c){if("ENOENT"===c.code)return b;return i.v.warn(`Failed to read ${a}`,{error:c instanceof Error?c.message:"Unknown error"}),b}}async function o(a,b){let c=h().dirname(a);await m(c);let e=a+".tmp";await (0,d.writeFile)(e,JSON.stringify(b,null,2),"utf-8"),await (0,d.rename)(e,a)}let p=()=>h().join(k(),"registry.json"),q=/^[0-9a-f]{64}$/;async function r(a){let b=!1;for(let c of a.plugins){if(!c.bundleHash||q.test(c.bundleHash))continue;let a=h().join(k(),`${c.id}.js`);try{let b=await (0,d.readFile)(a);c.bundleHash=(0,f.createHash)("sha256").update(b).digest("hex")}catch{delete c.bundleHash}b=!0}return b}async function s(){let a=await n(p(),{plugins:[]});if(await r(a))try{await o(p(),a)}catch{}return a}async function t(a){return(await s()).plugins.find(b=>b.id===a)||null}let u=/^[a-z0-9][a-z0-9-]*[a-z0-9]$/;async function v(a,b){if((0,j.Bz)("install plugin"),!u.test(a.id))throw Error("Invalid plugin id");let c=k();await m(c);let e=h().join(c,`${a.id}.js`);await (0,d.writeFile)(e,b,"utf-8");let g=(0,f.createHash)("sha256").update(b).digest("hex"),i=new Date().toISOString(),l=await s(),n=l.plugins.findIndex(b=>b.id===a.id),q={...a,bundleHash:g,updatedAt:i,installedAt:n>=0?l.plugins[n].installedAt:a.installedAt};n>=0?l.plugins[n]=q:l.plugins.push(q),await o(p(),l)}async function w(a,b){(0,j.Bz)("update plugin metadata");let c=await s(),d=c.plugins.findIndex(b=>b.id===a);return d<0?null:(c.plugins[d]={...c.plugins[d],...b,updatedAt:new Date().toISOString()},await o(p(),c),c.plugins[d])}async function x(a){(0,j.Bz)("delete plugin");let b=await s(),c=b.plugins.findIndex(b=>b.id===a);if(c<0)return!1;b.plugins.splice(c,1),await o(p(),b);let e=h().join(k(),`${a}.js`);try{await (0,d.unlink)(e)}catch{}return!0}async function y(a){let b=h().join(k(),`${a}.js`);try{return await (0,d.readFile)(b,"utf-8")}catch{return null}}let z=()=>h().join(l(),"registry.json");async function A(){return n(z(),{themes:[]})}async function B(a){return(await A()).themes.find(b=>b.id===a)||null}async function C(a,b){if((0,j.Bz)("install theme"),!u.test(a.id))throw Error("Invalid theme id");let c=l();await m(c);let e=h().join(c,`${a.id}.css`);await (0,d.writeFile)(e,b,"utf-8");let f=await A(),g=f.themes.findIndex(b=>b.id===a.id);g>=0?f.themes[g]=a:f.themes.push(a),await o(z(),f)}async function D(a,b){(0,j.Bz)("update theme metadata");let c=await A(),d=c.themes.findIndex(b=>b.id===a);return d<0?null:(c.themes[d]={...c.themes[d],...b,updatedAt:new Date().toISOString()},await o(z(),c),c.themes[d])}async function E(a){(0,j.Bz)("delete theme");let b=await A(),c=b.themes.findIndex(b=>b.id===a);if(c<0)return!1;b.themes.splice(c,1),await o(z(),b);let e=h().join(l(),`${a}.css`);try{await (0,d.unlink)(e)}catch{}return!0}async function F(a){let b=h().join(l(),`${a}.css`);try{return await (0,d.readFile)(b,"utf-8")}catch{return null}}}};