UNPKG

react-a11y-inspector

Version:

An advanced React accessibility inspection tool with real-time monitoring, screen reader simulation, and customizable rules.

22 lines (19 loc) 629 B
import tinycolor from 'tinycolor2'; export const checkContrast = () => { const issues = []; document.querySelectorAll('*').forEach((el) => { const style = getComputedStyle(el); const fgColor = tinycolor(style.color); const bgColor = tinycolor(style.backgroundColor); const contrast = tinycolor.readability(bgColor, fgColor); if (contrast < 4.5) { issues.push({ type: 'Low Contrast', message: `Text in ${el.tagName} has low contrast (ratio: ${contrast.toFixed(2)}).`, severity: 'Critical', element: el, }); } }); return issues; };