import type { Theme } from '../../theming/types.js'; import type { IconCallback, IconMeta, IconReferencePair, SvgIcon } from './registry/types.js'; /** * Global singleton registry for managing SVG icons and their references. * * @remarks * The IconsRegistry class handles: * - Registration and storage of SVG icons in collections * - Icon reference/alias management with theme-based resolution * - Notification of icon changes to subscribed components * - Cross-context synchronization via BroadcastChannel * - Batched notifications for performance optimization * * This is a singleton managed via Symbol.for to ensure a single instance * across the entire application, even with multiple bundle instances. * * @internal This class is not directly exposed. Use the exported functions instead. */ declare class IconsRegistry { /** Set of callbacks subscribed to icon change notifications */ private readonly _listeners; /** Set of pending icon:collection keys awaiting notification */ private readonly _pendingNotifications; /** Map of icon references/aliases by collection and name */ private readonly _references; /** Map of registered SVG icons by collection and name */ private readonly _collections; /** Parser for converting SVG text to icon metadata */ private readonly _svgIconParser; /** Broadcast channel manager for cross-context synchronization */ private readonly _broadcast; /** Flag indicating if a notification microtask is scheduled */ private _notificationScheduled; /** * Registers an SVG icon in the registry. * * @param name - The unique name for the icon within its collection * @param iconText - The SVG markup as a string * @param collection - The collection to register the icon in (default: 'default') * * @remarks * This method: * 1. Parses the SVG text into icon metadata * 2. Stores the icon in the specified collection * 3. Broadcasts the registration to other contexts * 4. Notifies subscribed components (batched) * * @throws Will throw if the SVG text is malformed */ register(name: string, iconText: string, collection?: string): void; /** * Subscribes a callback to icon change notifications. * * @param callback - Function to call when icons are registered or updated * * @remarks * The callback receives the icon name and collection when changes occur. * Notifications are batched using microtasks for performance. */ subscribe(callback: IconCallback): void; /** * Unsubscribes a callback from icon change notifications. * * @param callback - The previously subscribed callback to remove */ unsubscribe(callback: IconCallback): void; /** * Sets an icon reference/alias. * * @param options - Configuration for the icon reference * * @remarks * Icon references allow icons to be aliased with different names. * They can be: * - User-set (external: true) - higher priority, synced across contexts * - System-set (external: false) - used internally, not synced * * When overwrite is true, the reference is stored and subscribers are notified. * When external is true, the reference is broadcast to other contexts. */ setIconRef(options: IconReferencePair): void; /** * Gets the icon reference, resolving aliases based on the provided theme. * * @param name - The icon name or alias * @param collection - The collection name * @param theme - The theme to use for resolving aliases * @returns The resolved icon metadata (without the internal 'external' flag) */ getIconRef(name: string, collection: string, theme?: Theme): IconMeta; /** * Retrieves an icon from the registry. * * @param name - The icon name * @param collection - The collection name (default: 'default') * @returns The SVG icon metadata, or undefined if not found * * @remarks * Use `getIconRef` first to resolve aliases before calling this method. */ get(name: string, collection?: string): SvgIcon | undefined; /** * Schedules a batched notification for icon changes. * * @param name - The icon name that changed * @param collection - The collection name * * @remarks * Notifications are batched in a microtask queue to avoid excessive * listener calls when multiple icons are registered synchronously. * Duplicate icon:collection pairs are automatically deduplicated. * * @internal */ private _notifyAll; /** * Flushes pending notifications to all subscribed listeners. * * @remarks * This method is called as a microtask after icons are registered. * It processes all pending icon:collection pairs and notifies listeners. * * @internal */ private _flushNotifications; } /** * Gets the global icon registry singleton instance. * * @returns The IconsRegistry singleton * * @remarks * This function ensures only one instance of the registry exists globally, * even across multiple bundle instances. The registry is stored on globalThis * using a well-known Symbol. * * @example * ```typescript * const registry = getIconRegistry(); * registry.subscribe((name, collection) => { * console.log(`Icon ${name} changed in ${collection}`); * }); * ``` */ export declare function getIconRegistry(): IconsRegistry; /** * Registers an icon by fetching it from a URL. * * @param name - The unique name for the icon * @param url - The URL to fetch the SVG icon from * @param collection - The collection to register the icon in (default: 'default') * * @returns A promise that resolves when the icon is registered * * @throws If the HTTP request fails or returns a non-OK status * * @remarks * This function fetches SVG content from the provided URL and registers it * in the icon registry. The icon becomes immediately available to all icon * components in the application. * * @example * ```typescript * // Register an icon from a URL * await registerIcon('custom-icon', '/assets/icons/custom.svg'); * * // Use in HTML * // * ``` */ export declare function registerIcon(name: string, url: string, collection?: string): Promise; /** * Registers an icon from SVG text content. * * @param name - The unique name for the icon * @param iconText - The SVG markup as a string * @param collection - The collection to register the icon in (default: 'default') * * @throws If the SVG text is malformed or doesn't contain an SVG element * * @remarks * This is the preferred method for registering icons when you have the SVG * content directly (e.g., from a bundled asset or inline string). The icon * becomes immediately available to all icon components. * * The SVG text is parsed to extract viewBox, title, and other metadata. * * @example * ```typescript * const iconSvg = ''; * registerIconFromText('my-icon', iconSvg, 'custom'); * * // Use in HTML * // * ``` */ export declare function registerIconFromText(name: string, iconText: string, collection?: string): void; /** * Sets an icon reference/alias that points to another icon. * * @param name - The alias name * @param collection - The collection for the alias * @param icon - The target icon metadata (name and collection) * * @remarks * Icon references allow you to create aliases that point to other icons. * This is useful for: * - Creating semantic names (e.g., 'close' → 'x') * - Overriding default icon mappings * - Providing fallbacks for missing icons * * User-set references are marked as external and have higher priority than * theme-based aliases. They are also synchronized across browsing contexts. * * @example * ```typescript * // Register target icon * registerIconFromText('x-mark', '...'); * * // Create an alias * setIconRef('close', 'default', { * name: 'x-mark', * collection: 'default' * }); * * // Both work the same way: * // * // * ``` */ export declare function setIconRef(name: string, collection: string, icon: IconMeta): void; export {};