UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

122 lines 3.67 kB
/** * Default lazy-loaded directive registry */ export declare function createDirectiveRegistry(): DirectiveLoaderRegistry; /** * Create a lazy module that loads on first access */ export declare function createLazyModule<T>(loader: ModuleLoader<T>): { get: () => Promise<T> isLoaded: () => boolean preload: () => Promise<void> }; /** * Batch load multiple modules with progress callback */ export declare function batchLoad<T>(loader: LazyLoader<T>, names: string[], onProgress?: (loaded: number, total: number, name: string) => void): Promise<Map<string, T>>; /** * Global lazy loader instance */ export declare const globalLoader: LazyLoader<unknown>; /** * Global directive registry */ export declare const directiveRegistry: DirectiveLoaderRegistry; /** * Lazy loader options */ export declare interface LazyLoaderOptions { preload?: string[] timeout?: number debug?: boolean onError?: (name: string, error: Error) => void } /** * Directive processor interface */ export declare interface DirectiveProcessor { process: (content: string, params?: string, context?: Record<string, unknown>) => string | Promise<string> name?: string hasEndTag?: boolean } /** * Lazy Loading for Directive Processors * * Provides lazy loading capabilities for directive processors to reduce * initial load time and memory usage. * * ## Features * * - On-demand loading of directive processors * - Module caching to prevent re-imports * - Support for both sync and async loading * - Automatic dependency resolution * * ## Usage * * ```typescript * const loader = new LazyLoader() * * // Register lazy directive * loader.register('markdown', () => import('./markdown')) * * // Load when needed * const markdown = await loader.load('markdown') * ``` * * @module lazy-loader */ /** * Module loader function */ export type ModuleLoader<T = unknown> = () => Promise<T> | T /** * Module status */ export type ModuleStatus = 'pending' | 'loading' | 'loaded' | 'error' /** * Lazy loader for directive processors */ export declare class LazyLoader<T = unknown> { private modules: Map<string, ModuleInfo<T>>; private options: LazyLoaderOptions; constructor(options?: LazyLoaderOptions); register(name: string, loader: ModuleLoader<T>, dependencies?: string[]): void; registerAll(modules: Record<string, ModuleLoader<T>>): void; has(name: string): boolean; getStatus(name: string): ModuleStatus | null; isLoaded(name: string): boolean; load(name: string): Promise<T>; loadAll(names: string[]): Promise<T[]>; loadSync(name: string): T; preload(names: string[]): Promise<void>; unload(name: string): boolean; unloadAll(): void; getStats(): { registered: number loaded: number pending: number errors: number totalLoadTime: number modules: Array<{ name: string status: ModuleStatus loadCount: number loadTime?: number }> }; private loadWithTimeout(name: string, loader: ModuleLoader<T>): Promise<T>; } /** * Lazy loader specifically for directive processors */ export declare class DirectiveLoaderRegistry { private loader: LazyLoader<DirectiveProcessor | { default: DirectiveProcessor }>; private directiveMap: Map<string, string>; constructor(options?: LazyLoaderOptions); registerDirective(directiveName: string, moduleName: string, loader: ModuleLoader<DirectiveProcessor | { default: DirectiveProcessor }>): void; getProcessor(directiveName: string): Promise<DirectiveProcessor | null>; hasDirective(directiveName: string): boolean; getDirectiveNames(): string[]; preloadDirectives(directiveNames: string[]): Promise<void>; }