ash-theme-manager
v1.0.0
Published
Lightweight vanilla JS theme manager with system dark mode sync
Maintainers
Readme
Simple Theme Manager
A lightweight, framework-agnostic JavaScript theme manager with:
- ✅ System dark mode detection
- ✅ LocalStorage persistence
- ✅ Customizable attribute format
- ✅ Framework-friendly cleanup
- ✅ TypeScript support
Install
npm install ash-theme-managerBasic Usage
import ThemeManager from "simple-theme-manager";
const tm = new ThemeManager({
themes: ["base", "ocean", "sunset"],
});
tm.toggleMode();
tm.setTheme("ocean");Custom attribute format
const tm = new ThemeManager({
toAttribute: (theme, mode) => `${mode}:${theme}`,
});Result:
<html data-theme="dark:ocean"></html>API
| Method | Description |
| -------------- | ---------------------- |
| getTheme() | Get current theme |
| getMode() | Get light/dark mode |
| setTheme(t) | Set theme |
| setMode(m) | Set light/dark |
| toggleMode() | Switch mode |
| reset() | Clear storage |
| destroy() | Remove system listener |
