(() => { if (typeof window === 'undefined') { return; } const storageKey = 'theme-preference'; const root = document.documentElement; const media = window.matchMedia('(prefers-color-scheme: dark)'); const apply = (theme) => { const actual = theme === 'auto' ? (media.matches ? 'dark' : 'light') : theme; root.dataset.theme = theme; root.classList.toggle('dark', actual === 'dark'); root.classList.toggle('light', actual === 'light'); document.querySelectorAll('[data-theme-toggle]').forEach((toggle) => { var _a, _b, _c, _d; const labelAuto = (_a = toggle.dataset.themeLabelAuto) !== null && _a !== void 0 ? _a : 'Auto'; const labelLight = (_b = toggle.dataset.themeLabelLight) !== null && _b !== void 0 ? _b : 'Light'; const labelDark = (_c = toggle.dataset.themeLabelDark) !== null && _c !== void 0 ? _c : 'Dark'; const labelTitle = (_d = toggle.dataset.themeLabelTitle) !== null && _d !== void 0 ? _d : 'Theme'; const indicator = toggle.querySelector('[data-theme-indicator]'); const label = toggle.querySelector('[data-theme-label]'); if (indicator) { indicator.classList.toggle('bg-slate-300', actual === 'light'); indicator.classList.toggle('bg-slate-900', actual === 'dark'); } if (label) { label.textContent = theme === 'auto' ? labelAuto : actual === 'dark' ? labelDark : labelLight; } const text = (label && label.textContent) || (theme === 'auto' ? labelAuto : actual === 'dark' ? labelDark : labelLight); toggle.setAttribute('aria-label', `${labelTitle}: ${text}`); }); }; const load = () => { try { const stored = window.localStorage.getItem(storageKey); if (stored === 'auto' || stored === 'light' || stored === 'dark') { return stored; } } catch (error) { // ignore storage access errors } return 'auto'; }; const save = (theme) => { try { window.localStorage.setItem(storageKey, theme); } catch (error) { // ignore storage errors } }; const cycle = (theme) => { if (theme === 'auto') return 'light'; if (theme === 'light') return 'dark'; return 'auto'; }; let current = load(); apply(current); const initialize = () => { const toggles = document.querySelectorAll('[data-theme-toggle]'); toggles.forEach((button) => { button.addEventListener('click', () => { current = cycle(current); save(current); apply(current); }); }); const handleMediaChange = () => { if (current === 'auto') { apply('auto'); } }; if (typeof media.addEventListener === 'function') { media.addEventListener('change', handleMediaChange); } else { const legacyAddListener = media.addListener; if (typeof legacyAddListener === 'function') { legacyAddListener.call(media, () => handleMediaChange()); } } }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initialize, { once: true }); } else { initialize(); } })(); export {};