import { type IEventEmitter } from '@breadstone/mosaik-elements'; import { type ITheme, type ThemeMode, type ThemeScheme, type ThemeSemantic } from '@breadstone/mosaik-themes'; import type { IThemeApplyOptions, IThemeEventDetail, IThemeProvider, IThemeServiceConfig } from './IThemeService'; /** * Service for managing theme CSS variables throughout the application. * Provides methods to apply theme properties globally to the document. * * Uses a singleton pattern - access via `ThemeService.instance`. * * @example * ```typescript * // Configure service globally before use (optional) * ThemeService.configure({ * styleId: 'my-theme-vars', * autoInitialize: true * }); * * // Use the singleton instance * ThemeService.instance.applyTheme(myTheme); * * // Or apply individual parts (theme name is derived from stored state) * ThemeService.instance.applyScheme(theme.scheme); // global scope * ThemeService.instance.applyPalette(theme.palette); // global scope * ThemeService.instance.applyLayout(theme.layout); // global scope * ThemeService.instance.applyFontFamily('Arial'); // global scope * * // Subscribe to theme changes * ThemeService.instance.themeChanged.subscribe((detail) => { * console.log('Theme changed:', detail.theme); * }); * ``` * * @public */ export declare class ThemeService { private static _instance; private static _config; private readonly _globalStyleSheet; private readonly _providers; private readonly _themeStates; private readonly _themeChanged; private readonly _schemeChanged; private readonly _paletteChanged; private _initialized; /** * Constructs a new instance of the `ThemeService` class. * Use `ThemeService.instance` to access the singleton instance. * * @private */ private constructor(); /** * Returns the singleton instance of the ThemeService. * Creates the instance on first access using the current configuration. * * @public * @static * @readonly */ static get instance(): ThemeService; /** * Gets whether the service has been initialized. * * @public * @readonly */ get isInitialized(): boolean; /** * Event emitter that fires when the theme changes. * * @public * @readonly */ get themeChanged(): IEventEmitter; /** * Event emitter that fires when the scheme changes. * * @public * @readonly */ get schemeChanged(): IEventEmitter; /** * Event emitter that fires when the palette changes. * * @public * @readonly */ get paletteChanged(): IEventEmitter; /** * Configures the theme service globally. * Must be called before accessing the singleton instance. * * @public * @static * @param config Configuration options for the theme service. * @returns The ThemeService class for chaining. * @throws Error if called after the instance has already been created. * * @example * ```typescript * ThemeService.configure({ * styleId: 'my-custom-theme-vars', * autoInitialize: false * }); * ``` */ static configure(config: Partial): typeof ThemeService; /** * Resets the singleton instance. * Useful for testing or when the service needs to be re-configured. * * @public * @static */ static reset(): void; /** * Initializes the service. * Must be called before applying any theme properties (unless autoInitialize is enabled). * * @public */ initialize(): void; /** * Disposes of the service and cleans up resources. * * @public */ dispose(): void; /** * Registers a theme provider with the service. * If a theme state already exists for the provider's name, the provider * will be synchronized with that state. Otherwise, if the provider has a theme, * it will be used to initialize the state for that name. * * @public * @param provider The theme provider to register. */ registerProvider(provider: IThemeProvider): void; /** * Unregisters a theme provider from the service. * * @public * @param provider The theme provider to unregister. */ unregisterProvider(provider: IThemeProvider): void; /** * Checks whether a theme exists for the specified name. * For the global scope (no name), this also returns true if a default theme is configured. * * @public * @param name Optional name for scoped themes. Use `null` or omit for global scope. * @returns `true` if a theme is set for the specified scope, `false` otherwise. */ hasTheme(name?: string | null): boolean; /** * Gets the current theme for the specified name. * If no name is provided (undefined), returns the theme for the global/default scope (null key). * * The method uses the following fallback chain: * 1. Theme state from `_themeStates` map * 2. Theme from the first matching provider * 3. Default theme from configuration (global scope only) * * @public * @param name Optional name for scoped themes. Use `null` or omit for global scope. * @returns The current theme. * @throws Error if no theme is set for the specified scope and no default theme is configured. */ getTheme(name?: string | null): ITheme; /** * Gets the current theme name from the document element. * * @public * @returns The current theme name or `null` if not set. */ getDocumentTheme(): string | null; /** * Gets the current theme mode from the document element. * * @public * @returns The current theme mode or `null` if not set. */ getDocumentThemeMode(): ThemeMode | null; /** * Applies the complete theme. * If name is provided, only providers with that name are notified. * If name is not provided (undefined), only providers without a name (null) are notified. * * @public * @param theme The theme to apply. * @param name Optional name for scoped application. * @param options Optional settings to control notification behavior. */ applyTheme(theme: ITheme, name?: string | null, options?: IThemeApplyOptions): void; /** * Applies the scheme (light/dark mode color roles) from the theme. * Uses the theme name from the stored state for the specified scope. * * @public * @param scheme The scheme to apply. * @param name Optional name for scoped application. */ applyScheme(scheme: ITheme['scheme'], name?: string | null): void; /** * Applies the color palette from the theme. * Uses the theme name from the stored state for the specified scope. * * @public * @param palette The palette to apply. * @param name Optional name for scoped application. */ applyPalette(palette: ITheme['palette'], name?: string | null): void; /** * Applies the font family from the theme. * Uses the theme name and typography keys from the stored state for the specified scope. * * @public * @param fontFamily The font family to apply. * @param name Optional name for scoped application. */ applyFontFamily(fontFamily: ITheme['fontFamily'], name?: string | null): void; /** * Applies the typography settings from the theme. * Uses the theme name and font family from the stored state for the specified scope. * * @public * @param typography The typography settings to apply. * @param name Optional name for scoped application. */ applyTypography(typography: ITheme['typography'], name?: string | null): void; /** * Applies the layout settings from the theme. * Uses the theme name from the stored state for the specified scope. * * @public * @param layout The layout settings to apply. * @param name Optional name for scoped application. */ applyLayout(layout: ITheme['layout'], name?: string | null): void; /** * Applies the elevation (shadow) settings from the theme. * Uses the theme name from the stored state for the specified scope. * * @public * @param elevation The elevation settings to apply. * @param name Optional name for scoped application. */ applyElevation(elevation: ITheme['elevation'], name?: string | null): void; /** * Gets the current theme mode from the document. * * @public * @returns The current theme mode ('light' or 'dark'). */ getCurrentThemeMode(): ThemeMode; /** * Replaces the scheme with the specified key. * This is useful when you want to replace a specific scheme in the theme. * If the name is provided, only providers with that name are notified. * If name is not provided (undefined), only providers without a name (null) are notified. * * @public * @param mode The theme mode to replace. * @param scheme The scheme color roles to replace. * @param name Optional name for scoped replacement. * @param options Optional settings to control notification behavior. */ replaceScheme(mode: ThemeMode, scheme: Partial, name?: string | null, options?: IThemeApplyOptions): void; /** * Replaces the palette with the specified key. * This is useful when you want to replace a specific palette in the theme. * If themeId is provided, only providers with that ID are notified. * If themeId is not provided (undefined), only providers without an ID (null) are notified. * * @public * @param mode The theme mode to replace. * @param semantic The semantic color roles to replace. * @param name Optional name for scoped replacement. * @param options Optional settings to control notification behavior. */ replacePalette(mode: ThemeMode, semantic: Partial, name?: string | null, options?: IThemeApplyOptions): void; /** * Sets a CSS variable. * * @private * @param property The CSS variable name (e.g., `--my-var`). * @param value The value to set. * @param options Optional settings for where to apply the variable. */ private setCssVariable; /** * Sets a CSS variable globally and on all provider elements. * For providers with global=false, only sets locally on the element. * * @private * @param property The CSS variable name. * @param value The value to set. * @param providers The providers to set the variable on. * @param applyGlobally Whether to apply the variable globally. */ private setCssVariableWithProviders; /** * Converts a camelCase string to kebab-case. * * @private * @param value The value to convert. * @returns The kebab-case string. */ private toKebabCase; /** * Normalizes a CssLength value to a px string. * * @private * @param value The value to normalize. * @returns The normalized px string. */ private normalizeCssLength; /** * Ensures that the service has been initialized. * * @private */ private ensureInitialized; /** * Gets all providers that match the specified theme ID. * If themeId is null, returns providers without an ID. * * @private * @param themeId The theme ID to filter by. * @returns Array of matching providers. */ private getProvidersForName; /** * Gets the theme name for CSS variable prefixing from the stored state. * Falls back to the default theme name from configuration if no state exists for the given scope. * * @private * @param name The scope name (null for global scope). * @returns The theme name for CSS variable prefixing. */ private getThemeNameForScope; /** * Creates a deep clone of a theme object. * * @private * @param theme The theme to clone. * @returns A deep clone of the theme. */ private cloneTheme; } //# sourceMappingURL=ThemeService.d.ts.map