UNPKG

@uuv/a11y

Version:

A javascript lib for running a11y validation based on multiple reference(RGAA, etc)

87 lines (86 loc) 3.26 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WcagChecker = void 0; const rxjs_1 = require("rxjs"); const model_1 = require("../../model"); const uuv_a11y_result_1 = require("../../model/uuv-a11y-result"); const axe_core_1 = __importDefault(require("axe-core")); const WcagHelper = __importStar(require("./wcag-helper")); class WcagChecker { url; options; constructor(url, options) { this.url = url; this.options = options; } validate(name, script, location) { return (0, rxjs_1.from)(axe_core_1.default.run({ ...this.options })) .pipe((0, rxjs_1.map)(axeResult => { const violations = this.options?.includedImpacts ? axeResult.violations.filter(issue => issue?.impact && this.options?.includedImpacts?.includes(issue.impact)) : axeResult.violations; let issues = []; [ ...violations ].forEach(violation => { issues = issues.concat(WcagHelper.fromAxeToUvvA11yIssue(violation)); }); return { name, script, location, result: { date: (new Date()).getTime(), reference: model_1.A11yReferenceEnum.WCAG_WEB, issues, status: this.computeStatus(issues) } }; })); } computeStatus(issues) { if (issues.find(issue => issue.type === uuv_a11y_result_1.IssueType.Error)) { return model_1.A11yResultStatus.ERROR; } return model_1.A11yResultStatus.SUCCESS; } } exports.WcagChecker = WcagChecker;