@qualweb/wcag-techniques
Version:
Implementation of the WCAG 2.1 techniques
88 lines (87 loc) • 3.69 kB
JavaScript
;
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__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.WCAGTechniquesTester = void 0;
const evaluation_1 = require("@qualweb/core/evaluation");
const mapping_1 = __importDefault(require("./mapping"));
const techniques = __importStar(require("../techniques"));
class WCAGTechniquesTester extends evaluation_1.Tester {
init(translator) {
for (const technique in techniques) {
const techniqueObject = new techniques[technique](translator);
this.assertions.set(techniqueObject.getCode(), techniqueObject);
this.toExecute[techniqueObject.getCode()] = true;
}
return this;
}
execute(data) {
this.executeTechniques();
this.checkHTMLValidation(data.validation);
this.checkForUnwantedTabs(!!data.newTabWasOpen);
}
executeTechniques() {
var _a;
const selectors = Object.keys(mapping_1.default);
for (const selector of selectors !== null && selectors !== void 0 ? selectors : []) {
for (const technique of (_a = mapping_1.default[selector]) !== null && _a !== void 0 ? _a : []) {
if (this.toExecute[technique]) {
this.executeTechnique(technique, selector);
}
}
}
}
executeTechnique(technique, selector) {
var _a;
const techniqueObject = this.assertions.get(technique);
if (techniqueObject) {
const elements = window.qwPage.getElements(selector);
if (elements.length > 0) {
elements.forEach((element) => { var _a; return (_a = techniqueObject.execute) === null || _a === void 0 ? void 0 : _a.call(techniqueObject, element); });
}
else {
(_a = techniqueObject.execute) === null || _a === void 0 ? void 0 : _a.call(techniqueObject);
}
this.report.addAssertionResult(techniqueObject);
}
}
checkHTMLValidation(validation) {
const t16 = this.assertions.get('QW-WCAG-T16');
if (this.toExecute['QW-WCAG-T16'] && t16) {
t16.validate(validation);
this.report.addAssertionResult(t16);
}
}
checkForUnwantedTabs(newTabWasOpen) {
const t22 = this.assertions.get('QW-WCAG-T22');
if (this.toExecute['QW-WCAG-T22'] && t22) {
t22.validate(newTabWasOpen);
this.report.addAssertionResult(t22);
}
}
}
exports.WCAGTechniquesTester = WCAGTechniquesTester;