UNPKG

a11yanalyze

Version:

A command-line tool for developers and QA engineers to test web pages and websites for WCAG 2.2 AA accessibility compliance

167 lines 7.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VpatReporter = void 0; exports.registerCustomHelpers = registerCustomHelpers; const handlebars_1 = __importDefault(require("handlebars")); // Register built-in Handlebars helpers for template customization handlebars_1.default.registerHelper('formatDate', function (date, format) { const d = date ? new Date(date) : new Date(); return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); }); handlebars_1.default.registerHelper('ifEquals', function (a, b, options) { return a === b ? options.fn(this) : options.inverse(this); }); handlebars_1.default.registerHelper('toUpper', function (str) { return (str || '').toUpperCase(); }); handlebars_1.default.registerHelper('toLower', function (str) { return (str || '').toLowerCase(); }); handlebars_1.default.registerHelper('toTitle', function (str) { return (str || '').replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()); }); handlebars_1.default.registerHelper('pluralize', function (count, singular, plural) { return count === 1 ? singular : (plural || singular + 's'); }); handlebars_1.default.registerHelper('ifOdd', function (index, options) { return index % 2 === 1 ? options.fn(this) : options.inverse(this); }); // Export a function to allow user-defined helpers in the future function registerCustomHelpers(helpers) { Object.entries(helpers).forEach(([name, fn]) => handlebars_1.default.registerHelper(name, fn)); } class VpatReporter { static generateJsonReport(component, scanResult, vpatVersion = 'TastySoft Design System VPAT2 Form 2025') { // Map scan results to VPAT criteria (stub: real mapping would be more detailed) const criteria = scanResult.issues.map((issue) => ({ id: issue.wcagReference || issue.id, name: issue.message || issue.id, status: VpatReporter.mapSeverityToStatus(issue.severity), remarks: (issue.remediation || '') + (issue.helpUrl ? ` [More info](${issue.helpUrl})` : ''), })); // Add Not Applicable/Not Evaluated for missing criteria (stub) // ... const keyboardNav = scanResult.keyboardNavigation; const screenReaderSim = scanResult.screenReaderSimulation; const cognitive = scanResult.cognitiveAccessibility; const summary = VpatReporter.summarize(criteria); const report = { component, vpatVersion, criteria, summary }; if (keyboardNav) { report.keyboardNavigation = keyboardNav; } if (screenReaderSim) { report.screenReaderSimulation = screenReaderSim; } if (cognitive) { report.cognitiveAccessibility = cognitive; } return report; } static generateMarkdownReport(report) { let md = `# ${report.vpatVersion} - ${report.component}\n\n`; md += '| Criterion | Name | Status | Remarks/Explanations |\n'; md += '|-----------|------|--------|----------------------|\n'; for (const c of report.criteria) { md += `| ${c.id} | ${c.name} | ${c.status} | ${c.remarks.replace(/\n/g, ' ')} |\n`; } md += '\n**Summary:** \n'; md += `- Supports: ${report.summary.supports} \n`; md += `- Partially Supports: ${report.summary.partiallySupports} \n`; md += `- Does Not Support: ${report.summary.doesNotSupport} \n`; md += `- Not Applicable: ${report.summary.notApplicable} \n`; md += `- Not Evaluated: ${report.summary.notEvaluated} \n`; if (report.keyboardNavigation) { md += '\n**Keyboard Navigation Findings:**\n'; md += `- Issues: ${report.keyboardNavigation.issues.length}\n`; md += `- Unreachable Elements: ${report.keyboardNavigation.unreachableElements.length}\n`; md += `- Focus Traps: ${report.keyboardNavigation.focusTraps.length}\n`; md += `- Missing Focus Indicators: ${report.keyboardNavigation.missingFocusIndicators.length}\n`; // Focus management details const focusRelated = report.keyboardNavigation.issues.filter((i) => i.includes('focus') || i.includes('indicator')); if (focusRelated.length > 0) { md += '\n - Focus Management/Indicator Issues:'; focusRelated.forEach((issue) => { md += `\n - ${issue}`; }); } if (report.keyboardNavigation.issues.length > 0) { md += '\n'; report.keyboardNavigation.issues.forEach((issue) => { md += ` - ${issue}\n`; }); } } if (report.screenReaderSimulation) { md += '\n**Screen Reader Simulation Findings:**\n'; md += `- Findings: ${report.screenReaderSimulation.summary.length}\n`; md += `- Missing Names: ${report.screenReaderSimulation.missingNames.length}\n`; md += `- Ambiguous Roles: ${report.screenReaderSimulation.ambiguousRoles.length}\n`; md += `- Skipped Elements: ${report.screenReaderSimulation.skippedElements.length}\n`; if (report.screenReaderSimulation.summary.length > 0) { md += '\n'; report.screenReaderSimulation.summary.forEach((issue) => { md += ` - ${issue}\n`; }); } } if (report.cognitiveAccessibility) { md += '\n**Cognitive Accessibility Findings:**\n'; report.cognitiveAccessibility.summary.forEach((line) => { md += `- ${line}\n`; }); } return md; } static generateCustomReport(report, template) { const compiled = handlebars_1.default.compile(template); return compiled(report); } static mapSeverityToStatus(severity) { switch (severity) { case 'critical': case 'serious': return 'Does Not Support'; case 'moderate': return 'Partially Supports'; case 'minor': case 'warning': return 'Supports'; default: return 'Supports'; } } static summarize(criteria) { const summary = { supports: 0, partiallySupports: 0, doesNotSupport: 0, notApplicable: 0, notEvaluated: 0, }; for (const c of criteria) { switch (c.status) { case 'Supports': summary.supports++; break; case 'Partially Supports': summary.partiallySupports++; break; case 'Does Not Support': summary.doesNotSupport++; break; case 'Not Applicable': summary.notApplicable++; break; case 'Not Evaluated': summary.notEvaluated++; break; } } return summary; } } exports.VpatReporter = VpatReporter; //# sourceMappingURL=vpat-reporter.js.map