@eduboxpro/studio 0.1.18 → 0.1.20

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.
@@ -76,29 +76,63 @@ function loadGoogleFonts(fonts) {
76
76
  });
77
77
  }
78
78
 
79
+ const THEME_STORAGE_KEY = 'studio-theme-mode';
79
80
  class StudioConfigService {
80
81
  document = inject(DOCUMENT);
81
82
  config = signal({}, ...(ngDevMode ? [{ debugName: "config" }] : []));
82
83
  themeMode = signal('light', ...(ngDevMode ? [{ debugName: "themeMode" }] : []));
83
84
  constructor() {
85
+ // Load saved theme from localStorage
86
+ this.loadSavedTheme();
84
87
  effect(() => {
85
88
  this.applyTheme(this.config().theme);
86
89
  });
87
90
  }
88
91
  configure(config) {
89
92
  this.config.set(config);
90
- if (config.theme?.mode) {
91
- this.setThemeMode(config.theme.mode);
93
+ // Only set theme mode from config if no saved preference exists
94
+ if (config.theme?.mode && !this.hasSavedTheme()) {
95
+ this.setThemeMode(config.theme.mode, false);
92
96
  }
93
97
  }
94
- setThemeMode(mode) {
98
+ setThemeMode(mode, persist = true) {
95
99
  this.themeMode.set(mode);
96
100
  this.document.documentElement.setAttribute('data-theme', mode);
101
+ if (persist) {
102
+ this.saveTheme(mode);
103
+ }
97
104
  }
98
105
  toggleTheme() {
99
106
  const newMode = this.themeMode() === 'light' ? 'dark' : 'light';
100
107
  this.setThemeMode(newMode);
101
108
  }
109
+ loadSavedTheme() {
110
+ try {
111
+ const savedTheme = localStorage.getItem(THEME_STORAGE_KEY);
112
+ if (savedTheme && (savedTheme === 'light' || savedTheme === 'dark')) {
113
+ this.setThemeMode(savedTheme, false);
114
+ }
115
+ }
116
+ catch {
117
+ // localStorage not available (SSR or private browsing)
118
+ }
119
+ }
120
+ saveTheme(mode) {
121
+ try {
122
+ localStorage.setItem(THEME_STORAGE_KEY, mode);
123
+ }
124
+ catch {
125
+ // localStorage not available
126
+ }
127
+ }
128
+ hasSavedTheme() {
129
+ try {
130
+ return localStorage.getItem(THEME_STORAGE_KEY) !== null;
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ }
102
136
  updateTheme(theme) {
103
137
  this.config.update(cfg => ({
104
138
  ...cfg,