leptos_helios/accessibility/
mod.rs

1//! Accessibility Module
2//!
3//! This module provides WCAG 2.1 AA compliance, screen reader support,
4//! keyboard navigation, and performance optimization capabilities.
5
6pub mod alt_text;
7pub mod errors;
8pub mod keyboard;
9pub mod performance;
10pub mod screen_reader;
11pub mod wcag;
12
13// Re-export main types and functions
14pub use alt_text::*;
15pub use errors::*;
16pub use keyboard::*;
17pub use performance::*;
18pub use screen_reader::*;
19pub use wcag::*;
20
21// Common types used across all accessibility features
22// use crate::chart::{ChartSpec, MarkType}; // Currently unused
23// use polars::prelude::DataFrame; // Currently unused
24use serde::{Deserialize, Serialize};
25use std::collections::HashMap;
26
27/// Accessibility configuration
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct AccessibilityConfig {
30    pub wcag_level: WCAGLevel,
31    pub screen_reader: ScreenReaderSupport,
32    pub keyboard_nav: KeyboardNavigation,
33    pub color_vision: ColorVisionSupport,
34    pub motion: MotionPreferences,
35    pub focus_management: FocusManagement,
36    pub alternative_formats: AlternativeFormats,
37}
38
39impl Default for AccessibilityConfig {
40    fn default() -> Self {
41        Self {
42            wcag_level: WCAGLevel::AA,
43            screen_reader: ScreenReaderSupport::default(),
44            keyboard_nav: KeyboardNavigation::default(),
45            color_vision: ColorVisionSupport::default(),
46            motion: MotionPreferences::default(),
47            focus_management: FocusManagement::default(),
48            alternative_formats: AlternativeFormats::default(),
49        }
50    }
51}
52
53/// Screen reader support configuration for enhanced accessibility
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct ScreenReaderSupport {
56    pub enabled: bool,
57    pub generate_alt_text: bool,
58    pub create_data_tables: bool,
59    pub provide_summaries: bool,
60    pub announce_updates: bool,
61    pub aria_labels: bool,
62    pub structured_navigation: bool,
63}
64
65impl Default for ScreenReaderSupport {
66    fn default() -> Self {
67        Self {
68            enabled: true,
69            generate_alt_text: true,
70            create_data_tables: true,
71            provide_summaries: true,
72            announce_updates: true,
73            aria_labels: true,
74            structured_navigation: true,
75        }
76    }
77}
78
79/// Keyboard navigation configuration
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct KeyboardNavigation {
82    pub enabled: bool,
83    pub tab_order: bool,
84    pub arrow_key_navigation: bool,
85    pub skip_links: bool,
86    pub focus_indicators: bool,
87    pub escape_handling: bool,
88    pub custom_shortcuts: HashMap<String, String>,
89}
90
91impl Default for KeyboardNavigation {
92    fn default() -> Self {
93        Self {
94            enabled: true,
95            tab_order: true,
96            arrow_key_navigation: true,
97            skip_links: true,
98            focus_indicators: true,
99            escape_handling: true,
100            custom_shortcuts: HashMap::new(),
101        }
102    }
103}
104
105/// Color vision support configuration
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct ColorVisionSupport {
108    pub enabled: bool,
109    pub colorblind_friendly: bool,
110    pub high_contrast: bool,
111    pub pattern_fills: bool,
112    pub text_labels: bool,
113    pub color_alternatives: Vec<String>,
114}
115
116impl Default for ColorVisionSupport {
117    fn default() -> Self {
118        Self {
119            enabled: true,
120            colorblind_friendly: true,
121            high_contrast: true,
122            pattern_fills: true,
123            text_labels: true,
124            color_alternatives: vec![
125                "#FF6B6B".to_string(), // Red
126                "#4ECDC4".to_string(), // Teal
127                "#45B7D1".to_string(), // Blue
128                "#96CEB4".to_string(), // Green
129                "#FFEAA7".to_string(), // Yellow
130                "#DDA0DD".to_string(), // Purple
131            ],
132        }
133    }
134}
135
136/// Motion preferences for accessibility
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub struct MotionPreferences {
139    pub respect_reduced_motion: bool,
140    pub animation_duration_ms: u32,
141    pub transition_duration_ms: u32,
142    pub disable_animations: bool,
143    pub reduce_parallax: bool,
144}
145
146impl Default for MotionPreferences {
147    fn default() -> Self {
148        Self {
149            respect_reduced_motion: true,
150            animation_duration_ms: 300,
151            transition_duration_ms: 150,
152            disable_animations: false,
153            reduce_parallax: true,
154        }
155    }
156}
157
158/// Focus management configuration
159#[derive(Debug, Clone, Serialize, Deserialize)]
160pub struct FocusManagement {
161    pub enabled: bool,
162    pub focus_trap: bool,
163    pub focus_restoration: bool,
164    pub focus_indicators: bool,
165    pub tab_index_management: bool,
166    pub aria_live_regions: bool,
167}
168
169impl Default for FocusManagement {
170    fn default() -> Self {
171        Self {
172            enabled: true,
173            focus_trap: true,
174            focus_restoration: true,
175            focus_indicators: true,
176            tab_index_management: true,
177            aria_live_regions: true,
178        }
179    }
180}
181
182/// Alternative formats configuration
183#[derive(Debug, Clone, Serialize, Deserialize)]
184pub struct AlternativeFormats {
185    pub data_tables: bool,
186    pub text_descriptions: bool,
187    pub sonification: bool,
188    pub tactile_graphics: bool,
189    pub high_contrast_version: bool,
190}
191
192impl Default for AlternativeFormats {
193    fn default() -> Self {
194        Self {
195            data_tables: true,
196            text_descriptions: true,
197            sonification: false,     // Advanced feature
198            tactile_graphics: false, // Advanced feature
199            high_contrast_version: true,
200        }
201    }
202}
203
204/// Alternative data table representation
205#[derive(Debug, Clone, Serialize, Deserialize)]
206pub struct DataTable {
207    pub title: String,
208    pub summary: String,
209    pub headers: Vec<String>,
210    pub rows: Vec<Vec<String>>,
211    pub caption: Option<String>,
212    pub scope_attributes: HashMap<String, String>,
213}