agentgui 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ // Theme management for dark/light mode
2
+ class ThemeManager {
3
+ constructor() {
4
+ this.THEME_KEY = 'gmgui-theme';
5
+ this.SYSTEM_DARK_MODE = window.matchMedia('(prefers-color-scheme: dark)');
6
+ this.init();
7
+ }
8
+
9
+ init() {
10
+ // Load saved theme or use system preference
11
+ const savedTheme = localStorage.getItem(this.THEME_KEY);
12
+ const prefersDark = this.SYSTEM_DARK_MODE.matches;
13
+
14
+ if (savedTheme) {
15
+ this.setTheme(savedTheme);
16
+ } else {
17
+ // Use system preference
18
+ this.setTheme(prefersDark ? 'dark' : 'light');
19
+ }
20
+
21
+ // Listen for system theme changes
22
+ this.SYSTEM_DARK_MODE.addEventListener('change', (e) => {
23
+ const savedTheme = localStorage.getItem(this.THEME_KEY);
24
+ // Only auto-switch if user hasn't manually set a preference
25
+ if (!savedTheme) {
26
+ this.setTheme(e.matches ? 'dark' : 'light');
27
+ }
28
+ });
29
+
30
+ // Setup theme toggle button
31
+ const themeToggle = document.getElementById('themeToggle');
32
+ if (themeToggle) {
33
+ themeToggle.addEventListener('click', () => this.toggleTheme());
34
+ }
35
+ }
36
+
37
+ setTheme(theme) {
38
+ if (theme !== 'dark' && theme !== 'light') {
39
+ theme = 'light';
40
+ }
41
+
42
+ document.documentElement.setAttribute('data-theme', theme);
43
+ localStorage.setItem(this.THEME_KEY, theme);
44
+ this.updateThemeIcon(theme);
45
+ }
46
+
47
+ toggleTheme() {
48
+ const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';
49
+ const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
50
+ this.setTheme(newTheme);
51
+ }
52
+
53
+ updateThemeIcon(theme) {
54
+ const icon = document.querySelector('.theme-icon');
55
+ if (icon) {
56
+ icon.textContent = theme === 'dark' ? '☀️' : '🌙';
57
+ }
58
+ }
59
+
60
+ getCurrentTheme() {
61
+ return document.documentElement.getAttribute('data-theme') || 'light';
62
+ }
63
+ }
64
+
65
+ // Initialize theme manager when DOM is ready
66
+ if (document.readyState === 'loading') {
67
+ document.addEventListener('DOMContentLoaded', () => {
68
+ window.themeManager = new ThemeManager();
69
+ });
70
+ } else {
71
+ window.themeManager = new ThemeManager();
72
+ }