neumorphic-peripheral
Version:
A lightweight, framework-agnostic JavaScript/TypeScript library for beautiful neumorphic styling
183 lines • 4.98 kB
TypeScript
/**
* Performance optimization utilities for Neumorphic Peripheral
*
* This module provides tools for optimizing component performance,
* monitoring bundle size, and implementing efficient patterns.
*/
export interface PerformanceMetrics {
componentInitTime: number;
renderTime: number;
eventHandlerTime: number;
memoryUsage: number;
bundleSize: number;
}
declare class PerformanceMonitor {
private metrics;
private observers;
private resizeObservers;
/**
* Measure component initialization time
*/
measureInit<T>(componentName: string, initFunction: () => T): T;
/**
* Measure render time for DOM operations
*/
measureRender(componentName: string, renderFunction: () => void): void;
/**
* Measure event handler performance
*/
measureEventHandler(componentName: string, eventHandler: (...args: any[]) => any): (...args: any[]) => any;
/**
* Monitor memory usage
*/
measureMemory(componentName: string): void;
/**
* Get performance metrics for a component
*/
getMetrics(componentName: string): PerformanceMetrics | undefined;
/**
* Get all performance metrics
*/
getAllMetrics(): Record<string, PerformanceMetrics>;
/**
* Reset metrics for a component
*/
resetMetrics(componentName: string): void;
/**
* Clear all metrics
*/
clearAllMetrics(): void;
private updateMetric;
/**
* Clean up observers
*/
cleanup(): void;
}
export declare const performanceMonitor: PerformanceMonitor;
/**
* Lazy loading utilities
*/
export declare class LazyLoader {
private loadedComponents;
private intersectionObserver?;
constructor();
/**
* Lazy load a component when it enters viewport
*/
lazyLoad(element: HTMLElement, componentLoader: () => Promise<any>, componentName: string): Promise<any>;
private setupIntersectionObserver;
/**
* Clean up resources
*/
cleanup(): void;
}
/**
* Throttling and debouncing utilities
*/
export declare class ThrottleDebounce {
private throttleTimers;
private debounceTimers;
/**
* Throttle function execution
*/
throttle<T extends (...args: any[]) => any>(key: string, func: T, limit: number): (...args: Parameters<T>) => void;
/**
* Debounce function execution
*/
debounce<T extends (...args: any[]) => any>(key: string, func: T, delay: number): (...args: Parameters<T>) => void;
/**
* Clear all timers
*/
cleanup(): void;
}
/**
* Virtual scrolling for large lists
*/
export declare class VirtualScroller {
private container;
private itemHeight;
private visibleItems;
private totalItems;
private renderItem;
private scrollTop;
constructor(container: HTMLElement, itemHeight: number, renderItem: (index: number) => HTMLElement);
/**
* Set total number of items
*/
setTotalItems(count: number): void;
/**
* Update visible items based on scroll position
*/
private updateVisibleItems;
private setupScrollListener;
private updateContainer;
/**
* Clean up event listeners
*/
cleanup(): void;
}
/**
* Bundle size analyzer
*/
export declare class BundleSizeAnalyzer {
/**
* Estimate bundle size of imported modules
*/
static analyzeBundleSize(): Promise<{
core: number;
components: Record<string, number>;
total: number;
}>;
/**
* Track actual bundle size in production
*/
static trackBundleSize(): void;
private static estimateModuleSize;
/**
* Recommend optimizations based on usage
*/
static getOptimizationRecommendations(usedComponents: string[]): string[];
}
/**
* Memory leak detection and prevention
*/
export declare class MemoryManager {
private componentReferences;
private globalListeners;
/**
* Track component event listeners for cleanup
*/
trackEventListener(element: HTMLElement, event: string, listener: EventListener): void;
/**
* Clean up all listeners for an element
*/
cleanupElement(element: HTMLElement): void;
/**
* Detect potential memory leaks
*/
detectMemoryLeaks(): {
potentialLeaks: number;
recommendations: string[];
};
/**
* Force garbage collection (if available)
*/
forceGarbageCollection(): void;
}
export declare const lazyLoader: LazyLoader;
export declare const throttleDebounce: ThrottleDebounce;
export declare const memoryManager: MemoryManager;
/**
* Performance optimization decorators
*/
export declare function withPerformanceMonitoring(componentName: string): <T extends {
new (...args: any[]): {};
}>(constructor: T) => {
new (...args: any[]): {};
} & T;
/**
* Cleanup utility for preventing memory leaks
*/
export declare function autoCleanup(): void;
export {};
//# sourceMappingURL=performance.d.ts.map