@bagelink/vue 1.15.104 → 1.15.106

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.15.104",
4
+ "version": "1.15.106",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -45,6 +45,14 @@ const isDark = ref(false)
45
45
  */
46
46
  const allowDark = ref(false)
47
47
 
48
+ /**
49
+ * Whether this project lets the user manually pick a theme. When false (the
50
+ * default), the app always follows the OS ("system") and ignores any saved
51
+ * manual choice — so it updates live with the OS and never gets stuck on a
52
+ * stale dark/light value. When true, a saved manual choice is honored.
53
+ */
54
+ const manualSelection = ref(false)
55
+
48
56
  const isBrowser = typeof window !== 'undefined'
49
57
 
50
58
  function getSystemPrefersDark() {
@@ -104,14 +112,38 @@ function toggleTheme() {
104
112
  /**
105
113
  * Configure theme behavior for the current app. Call once at startup.
106
114
  *
107
- * @param options.allowDark Enable dark mode for this project (default: false).
108
- * When false, dark / system-dark falls back to light.
115
+ * @param options.allowDark Enable dark mode for this project (default: false).
116
+ * When false, dark / system-dark falls back to light.
117
+ * @param options.manualSelection Whether this project exposes a UI for the user to
118
+ * manually pick a theme (default: false).
119
+ * - false → always follow the OS ("system"); any
120
+ * previously-saved manual choice is ignored, so the
121
+ * app updates live when the OS color scheme changes.
122
+ * - true → honor the user's saved manual choice, and
123
+ * fall back to "system" when they haven't picked one.
109
124
  */
110
- export function configureTheme(options: { allowDark?: boolean } = {}) {
125
+ export function configureTheme(options: { allowDark?: boolean, manualSelection?: boolean } = {}) {
111
126
  if (options.allowDark !== undefined) {
112
127
  allowDark.value = options.allowDark
113
128
  }
114
- // Re-apply with the new policy so a previously-saved dark choice is corrected.
129
+ if (options.manualSelection !== undefined) {
130
+ manualSelection.value = options.manualSelection
131
+ }
132
+
133
+ // Register the matchMedia listener + colorMode watcher now, so OS color-scheme
134
+ // changes are picked up live — even if no component ever calls useTheme()
135
+ // (e.g. projects with no manual theme switcher). Without this, "system" mode
136
+ // wouldn't react until something mounted, forcing a refresh.
137
+ initTheme()
138
+
139
+ // When the project has no manual switcher, force "system" — even if initTheme()
140
+ // already ran earlier (via useTheme) and restored a stale saved value before
141
+ // this config was known.
142
+ if (!manualSelection.value) {
143
+ colorMode.value = 'system'
144
+ }
145
+
146
+ // Re-apply with the new policy so a previously-saved choice is corrected.
115
147
  applyTheme(colorMode.value)
116
148
  }
117
149
 
@@ -152,9 +184,15 @@ function initTheme() {
152
184
  if (initialized || !isBrowser) { return }
153
185
  initialized = true
154
186
 
155
- const saved = window.localStorage.getItem(STORAGE_KEY)
156
- if (themeOptions.value.some(t => t.value === saved)) {
157
- colorMode.value = saved!
187
+ // Only restore a saved manual choice when the project allows manual selection.
188
+ // Otherwise always follow the OS, so the app can't get stuck on a stale value.
189
+ if (manualSelection.value) {
190
+ const saved = window.localStorage.getItem(STORAGE_KEY)
191
+ if (themeOptions.value.some(t => t.value === saved)) {
192
+ colorMode.value = saved!
193
+ }
194
+ } else {
195
+ colorMode.value = 'system'
158
196
  }
159
197
 
160
198
  applyTheme(colorMode.value)
@@ -166,9 +204,11 @@ function initTheme() {
166
204
  }
167
205
  })
168
206
 
169
- // Persist + apply on mode changes
207
+ // Persist + apply on mode changes (persist only matters for manual selection)
170
208
  watch(colorMode, (newMode) => {
171
- localStorage.setItem(STORAGE_KEY, newMode)
209
+ if (manualSelection.value) {
210
+ localStorage.setItem(STORAGE_KEY, newMode)
211
+ }
172
212
  applyTheme(newMode)
173
213
  })
174
214
  }