import * as _angular_core from '@angular/core'; import { EnvironmentProviders } from '@angular/core'; import { ConfigDependencies, ConfigProvider } from '@odx/angular/utils'; import * as rxjs from 'rxjs'; /** * Determines whether the user's system preferences indicate a preference for dark themes. * This is achieved by querying the '(prefers-color-scheme: dark)' media feature, which reflects * the user's preference for a light or dark color scheme in their operating system's UI. * * @param {Window} view - The window object, typically `window`, from which to access the matchMedia method. * @returns {boolean} `true` if the user prefers a dark theme, otherwise `false`. * * @example * Example usage in a web application to toggle themes: * ```ts * if (prefersDarkTheme(window)) { * document.body.classList.add('dark-theme'); * } else { * document.body.classList.remove('dark-theme'); * } * ``` */ declare function prefersDarkTheme(view: Window): boolean; type Theme = (typeof Theme)[keyof typeof Theme]; declare const Theme: { readonly DARK: "dark"; readonly LIGHT: "light"; }; declare const availableThemes: ("dark" | "light")[]; /** * Resolves the specified theme by checking if it exists in the predefined list of available themes. * This function ensures that only valid themes are used in the application, providing a safeguard * against invalid theme names and facilitating the dynamic application of themes. * * @param {string | null} [theme] - The name of the theme to resolve. It's optional and can be `null`. * @returns {Theme | null} - Returns the resolved `Theme` object if the theme is found within the list of `availableThemes`; * otherwise, returns `null` to indicate the theme is not recognized or available. * * @example * ```ts * // Assuming 'dark' and 'light' are in the availableThemes array * console.log(resolveTheme('dark')); // Outputs the 'dark' Theme object * console.log(resolveTheme('unknown')); // Outputs null * * // Using resolveTheme to apply a user-selected theme * const userSelectedTheme = getUserSelectedTheme(); // This function gets the user's theme choice * const themeToApply = resolveTheme(userSelectedTheme); * if (themeToApply) { * applyTheme(themeToApply); // This function applies the resolved theme to the application * } else { * console.warn('Selected theme is not available.'); * } * ``` */ declare function resolveTheme(theme?: string | null): Theme | null; /** * The key used to store the selected theme in `Storage`. * This constant ensures consistent access to the theme setting across the application. */ declare const THEME_STORAGE_NAME = "@odx/angular/theming:SelectedTheme"; /** * Saves the specified theme to storage. This function abstracts the storage interaction, * providing a fail-safe mechanism to avoid exceptions if the storage is not available. * * @param {Storage | null | undefined} storage - The storage mechanism to use, typically `localStorage` or `sessionStorage`. * @param {Theme} theme - The theme to save. Should be a value that is recognized by the application's theming system. * @throws Will silently catch and ignore any exceptions caused by storage limitations or permissions. * * @example * ```ts * // Example usage with localStorage * saveTheme(localStorage, 'dark'); * * // Using sessionStorage instead * saveTheme(sessionStorage, 'light'); * ``` */ declare function saveTheme(storage: Storage | null | undefined, theme: Theme): void; /** * Reads the theme from storage, attempting to resolve it to a valid application theme. * If the theme cannot be found or is invalid, `null` is returned. This function also provides * error handling for any storage access issues, ensuring the application can gracefully handle * scenarios where storage is not available or accessible. * * @param {Storage | null} [storage] - The storage mechanism to use, typically `localStorage` or `sessionStorage`. * @returns {Theme | null} - The resolved theme if found and valid; otherwise, `null`. * @throws Will silently catch and ignore any exceptions caused by storage access, returning `null`. * * @example * ```ts * // Reading theme from localStorage * const theme = readTheme(localStorage); * if (theme) { * applyTheme(theme); // Assuming applyTheme is a function to apply the theme * } else { * console.warn('No saved theme found or theme is invalid.'); * } * ``` */ declare function readTheme(storage?: Storage | null): Theme | null; /** * Defines the structure for theming configuration options in the application. */ interface ThemingConfig { /** * Determines whether the theme should be auto-detected based on system preferences. */ autoDetect: boolean; /** * Specifies the default theme to be used if auto-detection is not enabled or fails. */ defaultTheme: Theme; /** * The storage mechanism (like `localStorage` or `sessionStorage`) to persist theme settings, * or `null` to disable persistence. */ storage?: Storage | null; } /** * Utility created by `createConfigTokens` for managing theming configuration tokens and functions. * Provides easy access to theming configuration, default values, and dependency injection utilities. */ declare const ThemingConfig: _angular_core.InjectionToken>; declare const injectThemingConfig: () => ThemingConfig; declare const provideThemingConfig: >>(config: ConfigProvider, D>) => _angular_core.FactoryProvider | _angular_core.ValueProvider; /** * Provides the theming configuration to the application and initializes the `ThemingService` * based on the provided configuration. This function simplifies the setup of a dynamic theming * system, integrating with Angular's environment initializers to ensure proper initialization. * * @template D - The dependencies required by the theming configuration, if any. * @param {ConfigProvider, D>} config - The theming configuration or a configuration factory provider. * @returns {EnvironmentProviders} An array of providers for setting up theming in the application. * * @example * ```ts * // Providing a simple theming configuration * provideTheming({ * autoDetect: true, * defaultTheme: Theme.DARK, * storage: localStorage, * }); * * // Providing a theming configuration with dependencies * provideTheming({ * useFactory: (deps: Dependencies) => ({ * autoDetect: deps.setting, * defaultTheme: Theme.DARK, * storage: localStorage, * }), * deps: [SomeDependency], * }); * ``` */ declare function provideTheming>(config: ConfigProvider, D>): EnvironmentProviders; declare const THEME_ATTRIBUTE_NAME = "odxTheme"; /** * Manages theming for the application. It allows for dynamic theme selection, automatically saves theme preferences, * and applies the user's preferred theme or the default theme based on configuration settings. * * The service leverages the BehaviorSubject pattern to reactively handle theme changes across the application, * ensuring that subscribers are notified whenever the theme changes. It also interacts with the DOM directly * to apply the current theme and with the provided storage mechanism to persist theme preferences. */ declare class ThemingService { private readonly config; private readonly document; private readonly windowRef; private readonly theme$$; /** * An observable stream of the current theme, emitting values whenever the theme changes. * Subscribers to this observable can react to theme changes in real-time. * * @emits {Theme} The currently selected theme. */ readonly theme$: rxjs.Observable; constructor(); /** * Selects and applies a given theme by updating the BehaviorSubject and persisting the preference. * * @param {Theme} theme - The theme to apply. */ selectTheme(theme: Theme): void; /** * Retrieves the currently selected theme. * * @returns {Theme} The currently selected theme. */ getSelectedTheme(): Theme; /** * Toggles between dark and light themes, depending on the current theme. */ toggleDarkMode(): void; /** * Enables the dark mode theme. */ enableDarkMode(): void; /** * Enables the light mode theme. */ enableLightMode(): void; private getInitialTheme; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵprov: _angular_core.ɵɵInjectableDeclaration; } export { THEME_ATTRIBUTE_NAME, THEME_STORAGE_NAME, Theme, ThemingConfig, ThemingService, availableThemes, injectThemingConfig, prefersDarkTheme, provideTheming, provideThemingConfig, readTheme, resolveTheme, saveTheme };