/** * @file Elegant theme context management. Async-aware theming with automatic * context isolation via AsyncLocalStorage. */ import type { AsyncLocalStorage } from 'node:async_hooks'; import type { Theme } from './types.js'; import type { ThemeName } from './presets.js'; import { getNodeAsyncHooks } from '../../node/async-hooks.js'; /** * Theme change event listener signature. */ export type ThemeChangeListener = (theme: Theme) => void; /** * Emit theme change event to listeners. * * @private */ export declare function emitThemeChange(theme: Theme): void; /** * Lazily load the async_hooks module. Aliases the canonical `node/async-hooks` * accessor, the single owner of the bundler-safe require; kept as an export so * this module's surface is unchanged. * * @private */ export declare const getAsyncHooks: typeof getNodeAsyncHooks; /** * Get the active theme from context. * * @example * ;```ts * const theme = getTheme() * console.log(theme.displayName) * ``` * * @returns Current theme */ export declare function getTheme(): Theme; /** * Get the process-scoped AsyncLocalStorage used for theme context isolation. * * Constructed LAZILY (memoized) rather than at module-eval: an * AsyncLocalStorage holds a live native handle, and constructing it at import * time pins that handle into every module transitively importing this leaf — * aborting V8 --build-snapshot serialization. Deferring to first use keeps the * single-store semantics while leaving module import snapshot-safe. * * @private */ export declare function getThemeStorage(): AsyncLocalStorage; /** * Subscribe to theme change events. * * @example * ;```ts * const unsubscribe = onThemeChange(theme => { * console.log('Theme:', theme.displayName) * }) * * // Cleanup * unsubscribe() * ``` * * @param listener - Change handler. * * @returns Unsubscribe function */ export declare function onThemeChange(listener: ThemeChangeListener): () => void; /** * Set the global fallback theme. * * @example * ;```ts * setTheme('socket-firewall') * ``` * * @param theme - Theme name or object. */ export declare function setTheme(theme: Theme | ThemeName): void; /** * Execute async operation with scoped theme. Theme automatically restored on * completion. * * @example * ;```ts * await withTheme('ultra', async () => { * // Operations use Ultra theme * }) * ``` * * @template T - Return type. * * @param theme - Scoped theme. * @param fn - Async operation. * * @returns Operation result */ export declare function withTheme(theme: Theme | ThemeName, fn: () => Promise): Promise; /** * Execute sync operation with scoped theme. Theme automatically restored on * completion. * * @example * ;```ts * const result = withThemeSync('coana', () => { * return processData() * }) * ``` * * @template T - Return type. * * @param theme - Scoped theme. * @param fn - Sync operation. * * @returns Operation result */ export declare function withThemeSync(theme: Theme | ThemeName, fn: () => T): T;