UNPKG

@allystudio/color-vision-simulator

Version:

Color vision deficiency simulator for accessibility testing and design

94 lines (90 loc) 3.01 kB
type ColorVisionType = 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia' | 'normal'; declare const COLOR_VISION_PRESETS: { readonly PROTANOPIA: "protanopia"; readonly DEUTERANOPIA: "deuteranopia"; readonly TRITANOPIA: "tritanopia"; readonly ACHROMATOPSIA: "achromatopsia"; readonly NORMAL: "normal"; }; interface SimulatorState { isActive: boolean; visionType: ColorVisionType; } interface SimulatorOptions { /** Custom overlay ID (default: "color-vision-simulator-overlay") */ overlayId?: string; /** Custom styles ID (default: "color-vision-simulator-styles") */ stylesId?: string; /** Custom z-index for overlay (default: 2147483647) */ zIndex?: number; /** Whether to use direct HTML filter for better performance (default: true) */ useDirectFilter?: boolean; } interface StateChangeEvent { isActive: boolean; visionType: ColorVisionType; } type StateChangeCallback = (state: StateChangeEvent) => void; /** * Creates a color vision simulator for testing color vision deficiencies * Uses CSS filters to simulate different types of color blindness */ declare function createColorVisionSimulator(options?: SimulatorOptions): { /** * Start the color vision deficiency simulation */ start(): void; /** * Stop the color vision deficiency simulation */ stop(): void; /** * Toggle the simulation on/off */ toggle(): void; /** * Set the type of color vision deficiency to simulate */ setVisionType(type: ColorVisionType): void; /** * Set both vision type and active state at once */ configure(visionType: ColorVisionType, isActive: boolean): void; /** * Get the current vision type being simulated */ getVisionType(): ColorVisionType; /** * Check if the simulator is currently active */ isActive(): boolean; /** * Get the current state of the simulator */ getState(): SimulatorState; /** * Subscribe to state changes */ onStateChange(callback: StateChangeCallback): () => void; /** * Clean up the simulator and remove all DOM elements */ destroy(): void; }; /** * Get or create singleton simulator instance */ declare function getSingletonSimulator(options?: SimulatorOptions): ReturnType<typeof createColorVisionSimulator>; /** * Destroy singleton instance */ declare function destroySingletonSimulator(): void; /** * Format color vision type for display */ declare function formatColorVisionType(type: ColorVisionType): string; /** * Get a description of the color vision deficiency */ declare function getColorVisionDescription(type: ColorVisionType): string; export { COLOR_VISION_PRESETS, type ColorVisionType, type SimulatorOptions, type SimulatorState, type StateChangeCallback, type StateChangeEvent, createColorVisionSimulator, destroySingletonSimulator, formatColorVisionType, getColorVisionDescription, getSingletonSimulator };