|
1 | 1 | diff --git a/node_modules/@astrojs/starlight/components/ThemeSelect.astro b/node_modules/@astrojs/starlight/components/ThemeSelect.astro |
2 | | -index a7cd175..d3e9670 100644 |
| 2 | +index d3e9670..ed6c93c 100644 |
3 | 3 | --- a/node_modules/@astrojs/starlight/components/ThemeSelect.astro |
4 | 4 | +++ b/node_modules/@astrojs/starlight/components/ThemeSelect.astro |
5 | | -@@ -48,9 +48,20 @@ import Select from './Select.astro'; |
| 5 | +@@ -47,13 +47,13 @@ import Select from './Select.astro'; |
| 6 | + matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; |
6 | 7 |
|
7 | 8 | /** Update select menu UI, document theme, and local storage state. */ |
8 | | - function onThemeChange(theme: Theme): void { |
9 | | -- StarlightThemeProvider.updatePickers(theme); |
10 | | -- document.documentElement.dataset.theme = theme === 'auto' ? getPreferredColorScheme() : theme; |
11 | | -- storeTheme(theme); |
12 | | -+ StarlightThemeProvider.updatePickers(theme); |
13 | | -+ |
14 | | -+ const resolvedTheme = theme === 'auto' ? getPreferredColorScheme() : theme; |
15 | | -+ const event = new CustomEvent('starlight:theme-change', { |
16 | | -+ cancelable: true, |
17 | | -+ detail: { theme, resolvedTheme }, |
18 | | -+ }); |
19 | | -+ |
20 | | -+ const handled = !document.dispatchEvent(event); |
21 | | -+ if (!handled) { |
22 | | -+ document.documentElement.dataset.theme = resolvedTheme; |
23 | | -+ } |
24 | | -+ |
25 | | -+ storeTheme(theme); |
26 | | - } |
| 9 | +- function onThemeChange(theme: Theme): void { |
| 10 | ++ function onThemeChange(theme: Theme, source: 'initial' | 'media' | 'select'): void { |
| 11 | + StarlightThemeProvider.updatePickers(theme); |
| 12 | + |
| 13 | + const resolvedTheme = theme === 'auto' ? getPreferredColorScheme() : theme; |
| 14 | + const event = new CustomEvent('starlight:theme-change', { |
| 15 | + cancelable: true, |
| 16 | +- detail: { theme, resolvedTheme }, |
| 17 | ++ detail: { theme, resolvedTheme, source }, |
| 18 | + }); |
| 19 | + |
| 20 | + const handled = !document.dispatchEvent(event); |
| 21 | +@@ -66,16 +66,16 @@ import Select from './Select.astro'; |
27 | 22 |
|
28 | 23 | // React to changes in system color scheme. |
| 24 | + matchMedia(`(prefers-color-scheme: light)`).addEventListener('change', () => { |
| 25 | +- if (loadTheme() === 'auto') onThemeChange('auto'); |
| 26 | ++ if (loadTheme() === 'auto') onThemeChange('auto', 'media'); |
| 27 | + }); |
| 28 | + |
| 29 | + class StarlightThemeSelect extends HTMLElement { |
| 30 | + constructor() { |
| 31 | + super(); |
| 32 | +- onThemeChange(loadTheme()); |
| 33 | ++ onThemeChange(loadTheme(), "initial"); |
| 34 | + this.querySelector('select')?.addEventListener('change', (e) => { |
| 35 | + if (e.currentTarget instanceof HTMLSelectElement) { |
| 36 | +- onThemeChange(parseTheme(e.currentTarget.value)); |
| 37 | ++ onThemeChange(parseTheme(e.currentTarget.value), 'select'); |
| 38 | + } |
| 39 | + }); |
| 40 | + } |
0 commit comments