这是一个简单的主题管理插件,允许用户在浅色模式、深色模式及自定义主题之间切换,并实时调整主题的 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.
 
 

2 lines
2.4 KiB

(function(i,f){typeof exports=="object"&&typeof module!="undefined"?module.exports=f():typeof define=="function"&&define.amd?define(f):(i=typeof globalThis!="undefined"?globalThis:i||self,i.themeManager=f())})(this,function(){"use strict";function i(e,n,t,o){function E(l){return l instanceof t?l:new t(function(d){d(l)})}return new(t||(t=Promise))(function(l,d){function k(s){try{m(o.next(s))}catch(p){d(p)}}function C(s){try{m(o.throw(s))}catch(p){d(p)}}function m(s){s.done?l(s.value):E(s.value).then(k,C)}m((o=o.apply(e,n||[])).next())})}typeof SuppressedError=="function"&&SuppressedError;function f(e,n){const t=document.documentElement.getAttribute("data-theme"),o=localStorage.getItem("theme");return t&&e[t]?t:o&&e[o]?o:n}let r={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)"}},c="light";const u=[],g=e=>i(void 0,void 0,void 0,function*(){try{const t=yield(yield fetch(e)).json();t.light&&(r.light=t.light),t.dark&&(r.dark=t.dark),Object.assign(r,t),console.log("\u2705 \u4E3B\u9898\u5DF2\u52A0\u8F7D:",Object.keys(t));const o=localStorage.getItem("theme");o&&r[o]?h(o):h(c)}catch(n){console.error("\u274C \u52A0\u8F7D JSON \u5931\u8D25:",n)}}),h=e=>{if(!r[e]){console.warn(`\u26A0\uFE0F \u4E3B\u9898 "${e}" \u4E0D\u5B58\u5728`);return}c=e,localStorage.setItem("theme",e),document.documentElement.setAttribute("data-theme",e),a(),w()},y=e=>{u.push(e)},b=(e,n)=>{document.documentElement.style.setProperty(e,n)},T=(e,n,t)=>{const o=Object.assign({},r);o[e]||(o[e]={}),o[e]=Object.assign(Object.assign({},o[e]),{[n]:t}),r=o,a()},a=()=>{const e=r[c],n=document.documentElement;for(const t in e)n.style.setProperty(t,e[t])},w=()=>{u.forEach(e=>e(c))};return()=>(c=f(r,c),a(),{themes:r,currentTheme:c,eventListeners:u,loadThemesFromJSON:g,switchTheme:h,onThemeChange:y,setThemeVariable:b,addThemeVariable:T,applyTheme:a})});
//# sourceMappingURL=themeManager.umd.js.map