@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
81 lines (80 loc) • 1.83 kB
TypeScript
import type { Theme } from './types';
import { type ThemeName } from './themes';
/**
* Theme change event listener signature.
*/
export type ThemeChangeListener = (theme: Theme) => void;
/**
* Set the global fallback theme.
*
* @param theme - Theme name or object
*
* @example
* ```ts
* setTheme('socket-firewall')
* ```
*/
export declare function setTheme(theme: Theme | ThemeName): void;
/**
* Get the active theme from context.
*
* @returns Current theme
*
* @example
* ```ts
* const theme = getTheme()
* console.log(theme.displayName)
* ```
*/
export declare function getTheme(): Theme;
/**
* Execute async operation with scoped theme.
* Theme automatically restored on completion.
*
* @template T - Return type
* @param theme - Scoped theme
* @param fn - Async operation
* @returns Operation result
*
* @example
* ```ts
* await withTheme('ultra', async () => {
* // Operations use Ultra theme
* })
* ```
*/
export declare function withTheme<T>(theme: Theme | ThemeName, fn: () => Promise<T>): Promise<T>;
/**
* Execute sync operation with scoped theme.
* Theme automatically restored on completion.
*
* @template T - Return type
* @param theme - Scoped theme
* @param fn - Sync operation
* @returns Operation result
*
* @example
* ```ts
* const result = withThemeSync('coana', () => {
* return processData()
* })
* ```
*/
export declare function withThemeSync<T>(theme: Theme | ThemeName, fn: () => T): T;
/**
* Subscribe to theme change events.
*
* @param listener - Change handler
* @returns Unsubscribe function
*
* @example
* ```ts
* const unsubscribe = onThemeChange((theme) => {
* console.log('Theme:', theme.displayName)
* })
*
* // Cleanup
* unsubscribe()
* ```
*/
export declare function onThemeChange(listener: ThemeChangeListener): () => void;