这是一个简单的主题管理插件,允许用户在浅色模式、深色模式及自定义主题之间切换,并实时调整主题的 CSS 变量。该插件通过加载 JSON 配置文件来管理不同的主题样式,并提供了便捷的界面让用户动态更改颜色。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
2.1 KiB

function b(e,r,t,o){function m(l){return l instanceof t?l:new t(function(a){a(l)})}return new(t||(t=Promise))(function(l,a){function p(c){try{i(o.next(c))}catch(d){a(d)}}function g(c){try{i(o.throw(c))}catch(d){a(d)}}function i(c){c.done?l(c.value):m(c.value).then(p,g)}i((o=o.apply(e,r||[])).next())})}typeof SuppressedError=="function"&&SuppressedError;function y(e,r){const t=document.documentElement.getAttribute("data-theme"),o=localStorage.getItem("theme");return t&&e[t]?t:o&&e[o]?o:r}let n={light:{"--background-color":"#ffffff","--text-color":"#303133","--primary-color":"#409EFF","--secondary-color":"#545c64","--border-color":"#DCDFE6","--accent-color":"#ff6600","--success-color":"#67C23A","--warning-color":"#E6A23C","--error-color":"#F56C6C","--shadow-color":"rgba(0, 0, 0, 0.1)"},dark:{"--background-color":"#121212","--text-color":"#ffffff","--primary-color":"#bb86fc","--secondary-color":"#03DAC6","--border-color":"#333333","--accent-color":"#ff4081","--success-color":"#4caf50","--warning-color":"#ffeb3b","--error-color":"#f44336","--shadow-color":"rgba(0, 0, 0, 0.7)"}},s="light";const u=[],T=e=>b(void 0,void 0,void 0,function*(){try{const t=yield(yield fetch(e)).json();t.light&&(n.light=t.light),t.dark&&(n.dark=t.dark),Object.assign(n,t),console.log("\u2705 \u4E3B\u9898\u5DF2\u52A0\u8F7D:",Object.keys(t));const o=localStorage.getItem("theme");o&&n[o]?h(o):h(s)}catch(r){console.error("\u274C \u52A0\u8F7D JSON \u5931\u8D25:",r)}}),h=e=>{if(!n[e]){console.warn(`\u26A0\uFE0F \u4E3B\u9898 "${e}" \u4E0D\u5B58\u5728`);return}s=e,localStorage.setItem("theme",e),document.documentElement.setAttribute("data-theme",e),f(),C()},w=e=>{u.push(e)},E=(e,r)=>{document.documentElement.style.setProperty(e,r)},k=(e,r,t)=>{const o=Object.assign({},n);o[e]||(o[e]={}),o[e]=Object.assign(Object.assign({},o[e]),{[r]:t}),n=o,f()},f=()=>{const e=n[s],r=document.documentElement;for(const t in e)r.style.setProperty(t,e[t])},C=()=>{u.forEach(e=>e(s))},S=()=>(s=y(n,s),f(),{themes:n,currentTheme:s,eventListeners:u,loadThemesFromJSON:T,switchTheme:h,onThemeChange:w,setThemeVariable:E,addThemeVariable:k,applyTheme:f});export{S as default};
//# sourceMappingURL=themeManager.js.map