/** * Optimized algorithms for CAPTCHA generation with enhanced performance. * * This module provides high-performance implementations of core CAPTCHA algorithms * including decoy generation, coordinate calculation, canvas operation batching, * and memory-efficient data structures. */ import { DistributionPattern, DecoyConfig, CoordinateConfig, CanvasOperationConfig, AlgorithmConfig } from "./constants"; /** * Coordinate cache for reusable coordinate sets. */ declare class CoordinateCache { private cache; private accessOrder; /** * Generates a cache key for coordinate parameters. */ private generateKey; /** * Retrieves cached coordinates or generates new ones. */ get(width: number, height: number, size: number, pattern: DistributionPattern): number[][]; /** * Stores coordinates in cache with LRU eviction. */ private set; /** * Generates coordinates based on distribution pattern. */ private generateCoordinates; /** * Clears the coordinate cache. */ clear(): void; /** * Gets cache statistics. */ getStats(): { size: number; hitRate: number; maxSize: number; }; } export { CoordinateCache }; /** * Optimized decoy generation with configurable strategies. */ export declare class OptimizedDecoyGenerator { private config; constructor(config?: DecoyConfig); /** * Calculates optimal number of decoy characters based on strategy. */ calculateDecoyCount(width: number, height: number, textLength: number, fontSize: number): number; /** * Calculates canvas complexity score for adaptive strategy. */ private calculateComplexityScore; /** * Generates intelligent decoy positions with spacing optimization. */ generateDecoyPositions(count: number, width: number, height: number, existingPositions?: number[][]): number[][]; /** * Checks if a decoy position is valid (no excessive overlap). */ private isValidDecoyPosition; /** * Updates decoy configuration. */ updateConfig(config: Partial): void; } /** * Optimized coordinate calculation with caching and distribution patterns. */ export declare class OptimizedCoordinateCalculator { private config; private cache; constructor(config?: CoordinateConfig); /** * Calculates optimized coordinates with caching support. */ calculateCoordinates(width: number, height: number, size: number): number[][]; /** * Generates coordinates based on distribution pattern (no caching). */ private generateCoordinates; /** * Generates clustered coordinate distribution. */ private generateClusteredCoordinates; /** * Generates grid-based coordinate distribution. */ private generateGridCoordinates; /** * Updates coordinate configuration. */ updateConfig(config: Partial): void; /** * Clears the coordinate cache. */ clearCache(): void; } /** * Canvas operation batcher for optimized rendering. */ export declare class CanvasOperationBatcher { private config; private operations; private profilingData; constructor(config?: CanvasOperationConfig); /** * Adds an operation to the batch. */ addOperation(operation: CanvasOperation): void; /** * Executes all batched operations on the canvas context. */ flush(): void; /** * Executes operations with optional batching optimization. */ private executeOperations; /** * Generates a style key for grouping operations. */ private getStyleKey; /** * Applies style properties to canvas context. */ private applyStyle; /** * Executes a single operation. */ private executeSingleOperation; /** * Executes operation without applying style (for grouped operations). */ private executeOperationWithoutStyle; /** * Gets profiling data if enabled. */ getProfilingData(): ProfilingData | null; /** * Updates batcher configuration. */ updateConfig(config: Partial): void; } /** * Memory-efficient object pooling for algorithm calculations. */ export declare class AlgorithmMemoryPool { private pool; private createFn; private resetFn?; private maxSize; constructor(createFn: () => T, resetFn?: (obj: T) => void, maxSize?: number); /** * Acquires an object from the pool or creates a new one. */ acquire(): T; /** * Returns an object to the pool for reuse. */ release(obj: T): void; /** * Gets pool statistics. */ getStats(): { available: number; maxSize: number; utilization: number; }; /** * Clears the pool. */ clear(): void; } /** * Canvas operation interface for batching. */ interface CanvasOperation { type: 'fillText' | 'strokeText' | 'fillRect' | 'strokeRect' | 'beginPath' | 'moveTo' | 'lineTo' | 'stroke'; x?: number; y?: number; text?: string; width?: number; height?: number; font?: string; fillStyle?: string; globalAlpha?: number; } /** * Profiling data interface. */ interface ProfilingData { totalOperations: number; batchedOperations: number; stateChanges: number; renderTime: number; } /** * Global algorithm configuration manager. */ export declare class AlgorithmConfigManager { private static instance; private config; private constructor(); static getInstance(): AlgorithmConfigManager; /** * Gets the current algorithm configuration. */ getConfig(): AlgorithmConfig; /** * Updates the algorithm configuration. */ updateConfig(config: Partial): void; /** * Merges configuration objects recursively. */ mergeConfig(target: AlgorithmConfig, source: Partial): AlgorithmConfig; /** * Resets configuration to defaults. */ resetToDefaults(): void; } export declare const algorithmConfigManager: AlgorithmConfigManager;