// ============================================================================
// Stylescape | Theme Toggler
// ============================================================================
// Manages light / dark / auto theme switching with localStorage persistence.
// Binds checkboxes, two-state buttons (aria-pressed) and three-state cycle
// buttons, including the `ss-c-theme-toggle` module.
// ============================================================================
/**
* Theme values written to ``. `"auto"` follows
* `prefers-color-scheme`; no attribute means light.
*/
export type Theme = "dark" | "light" | "auto";
/**
* Configuration options for theme toggling
*/
export interface ThemeTogglerOptions {
/** Custom storage key for theme preference */
storageKey?: string;
/** Custom attribute name on element */
themeAttribute?: string;
/** Default theme if none is stored */
defaultTheme?: Theme;
/** Callback when theme changes */
onChange?: (theme: Theme) => void;
}
const TOGGLE_SELECTOR =
'[data-theme-toggle], .ss-c-theme-toggle, [data-ss="theme-toggle"]';
const DARK_QUERY = "(prefers-color-scheme: dark)";
const CYCLE: Theme[] = ["light", "dark", "auto"];
/**
* Static utility class for managing the page theme.
* Persists the user's choice in localStorage (key `preferredTheme`).
*
* Controls:
* - ``: checked while the page is dark.
* - `