UNPKG

@ordojs/accessibility

Version:

Comprehensive accessibility system for OrdoJS with ARIA generation, automated testing, and screen reader support

236 lines (234 loc) 6.13 kB
import { EventEmitter } from 'events'; // src/screen-reader/index.ts var ScreenReaderManager = class extends EventEmitter { config; announcements; liveRegions; isInitialized; /** * Create a new ScreenReaderManager instance * * @param config - Screen reader configuration */ constructor(config) { super(); this.config = config; this.announcements = /* @__PURE__ */ new Map(); this.liveRegions = /* @__PURE__ */ new Map(); this.isInitialized = false; } /** * Initialize the screen reader manager */ async initialize() { if (this.isInitialized) { console.warn("Screen reader manager is already initialized"); return; } try { await this.initializeScreenReader(); this.isInitialized = true; console.log("Screen reader manager initialized successfully"); this.emit("initialized"); } catch (error) { console.error("Failed to initialize screen reader manager:", error); this.emit("error", error); throw error; } } /** * Announce message to screen readers * * @param message - Message to announce * @param options - Announcement options * @returns Announcement ID */ announce(message, options = {}) { const announcementId = `announcement_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; const announcement = { id: announcementId, message, priority: options.priority || "polite", type: options.type || "status", timestamp: /* @__PURE__ */ new Date() }; if (options.duration !== void 0) { announcement.duration = options.duration; } if (options.element) { announcement.element = options.element; } if (options.context) { announcement.context = options.context; } this.announcements.set(announcementId, announcement); this.emit("announcementCreated", announcement); return announcementId; } /** * Create live region * * @param regionId - Region ID * @param element - Element selector * @param options - Region options * @returns Live region */ createLiveRegion(regionId, element, options = {}) { const region = { id: regionId, type: options.type || "status", priority: options.priority || "polite", element, content: "", atomic: options.atomic || false, relevant: options.relevant || "additions", busy: options.busy || false }; if (options.expanded !== void 0) { region.expanded = options.expanded; } if (options.controls) { region.controls = options.controls; } if (options.describedBy) { region.describedBy = options.describedBy; } if (options.label) { region.label = options.label; } this.liveRegions.set(regionId, region); this.emit("liveRegionCreated", region); return region; } /** * Update live region content * * @param regionId - Region ID * @param content - New content * @param options - Update options */ updateLiveRegion(regionId, content, options = {}) { const region = this.liveRegions.get(regionId); if (region) { region.content = content; if (options.busy !== void 0) { region.busy = options.busy; } if (options.expanded !== void 0) { region.expanded = options.expanded; } this.liveRegions.set(regionId, region); this.emit("liveRegionUpdated", region); } } /** * Remove live region * * @param regionId - Region ID */ removeLiveRegion(regionId) { const region = this.liveRegions.get(regionId); if (region) { this.liveRegions.delete(regionId); this.emit("liveRegionRemoved", region); } } /** * Get live region by ID * * @param regionId - Region ID * @returns Live region or undefined */ getLiveRegion(regionId) { return this.liveRegions.get(regionId); } /** * Get all live regions * * @returns Array of live regions */ getAllLiveRegions() { return Array.from(this.liveRegions.values()); } /** * Get announcement by ID * * @param announcementId - Announcement ID * @returns Announcement or undefined */ getAnnouncement(announcementId) { return this.announcements.get(announcementId); } /** * Get all announcements * * @returns Array of announcements */ getAllAnnouncements() { return Array.from(this.announcements.values()); } /** * Clear announcements */ clearAnnouncements() { this.announcements.clear(); this.emit("announcementsCleared"); } /** * Get screen reader manager statistics * * @returns Statistics */ getStats() { const announcementsByType = {}; const liveRegionsByType = {}; for (const announcement of this.announcements.values()) { announcementsByType[announcement.type] = (announcementsByType[announcement.type] || 0) + 1; } for (const region of this.liveRegions.values()) { liveRegionsByType[region.type] = (liveRegionsByType[region.type] || 0) + 1; } return { totalAnnouncements: this.announcements.size, totalLiveRegions: this.liveRegions.size, announcementsByType, liveRegionsByType }; } /** * Initialize screen reader support */ async initializeScreenReader() { console.log("Initializing screen reader support..."); if (this.config.announcements) { this.setupAnnouncements(); } if (this.config.liveRegions) { this.setupLiveRegions(); } if (this.config.ariaLabels || this.config.ariaDescriptions || this.config.ariaLandmarks) { this.setupARIASupport(); } } /** * Setup announcements */ setupAnnouncements() { console.log("Setting up announcements..."); } /** * Setup live regions */ setupLiveRegions() { console.log("Setting up live regions..."); } /** * Setup ARIA support */ setupARIASupport() { console.log("Setting up ARIA support..."); } }; export { ScreenReaderManager }; //# sourceMappingURL=index.mjs.map //# sourceMappingURL=index.mjs.map