@qualweb/act-rules
Version:
ACT rules module for qualweb web accessibility evaluator
151 lines (150 loc) • 6.78 kB
JavaScript
"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 (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.ACTRulesTester = void 0;
const evaluation_1 = require("@qualweb/core/evaluation");
const mapping_1 = __importDefault(require("./mapping"));
const mappingComposite_1 = __importDefault(require("./mappingComposite"));
const rules = __importStar(require("../rules"));
class ACTRulesTester extends evaluation_1.Tester {
init(translator) {
for (const rule in rules) {
const ruleObject = new rules[rule](translator);
this.assertions.set(ruleObject.getCode(), ruleObject);
this.toExecute[ruleObject.getCode()] = true;
}
return this;
}
execute() {
this.executeAtomicRules();
this.executeCompositeRules();
}
configureCompositeRules() {
var _a;
for (const code in mappingComposite_1.default) {
const compositeRule = mappingComposite_1.default[code];
if (this.toExecute[code]) {
for (const atomicRule of (_a = compositeRule.rules) !== null && _a !== void 0 ? _a : []) {
this.toExecute[atomicRule] = true;
}
}
}
}
executeAtomicRules() {
var _a;
const selectors = Object.keys(mapping_1.default);
for (const selector of selectors !== null && selectors !== void 0 ? selectors : []) {
for (const rule of (_a = mapping_1.default[selector]) !== null && _a !== void 0 ? _a : []) {
if (this.toExecute[rule]) {
this.executeRule(rule, selector);
}
}
}
}
executeRule(rule, selector) {
var _a;
const ruleToExecute = this.assertions.get(rule);
if (ruleToExecute) {
const elements = window.qwPage.getElements(selector);
if (elements.length > 0) {
elements.forEach((element) => { var _a; return (_a = ruleToExecute === null || ruleToExecute === void 0 ? void 0 : ruleToExecute.execute) === null || _a === void 0 ? void 0 : _a.call(ruleToExecute, element); });
}
else {
(_a = ruleToExecute === null || ruleToExecute === void 0 ? void 0 : ruleToExecute.execute) === null || _a === void 0 ? void 0 : _a.call(ruleToExecute);
}
this.report.addAssertionResult(ruleToExecute);
}
}
executeCompositeRules() {
Object.entries(mappingComposite_1.default).forEach(([key, rule]) => {
if (this.toExecute[key]) {
this.executeCompositeRule(key, rule.selector, rule.rules, rule.implementation);
}
});
}
executeCompositeRule(rule, selector, atomicRules, implementation) {
var _a;
const ruleToExecute = this.assertions.get(rule);
if (ruleToExecute) {
const atomicRulesReport = new Array();
for (const atomicRule of atomicRules !== null && atomicRules !== void 0 ? atomicRules : []) {
atomicRulesReport.push(this.report.getAssertions(atomicRule));
}
const elements = window.qwPage.getElements(selector);
if (elements.length > 0) {
for (const elem of elements || []) {
if (implementation === 'conjunction') {
ruleToExecute.conjunction(elem, atomicRulesReport);
}
else if (implementation === 'disjunction') {
ruleToExecute.disjunction(elem, atomicRulesReport);
}
else {
ruleToExecute.execute(elem, atomicRulesReport);
}
}
}
else {
(_a = ruleToExecute === null || ruleToExecute === void 0 ? void 0 : ruleToExecute.execute) === null || _a === void 0 ? void 0 : _a.call(ruleToExecute);
}
this.report.addAssertionResult(ruleToExecute);
}
}
validateMetaElements(metaElements) {
var _a, _b;
if (this.toExecute['QW-ACT-R4'] || this.toExecute['QW-ACT-R71']) {
const r4 = this.assertions.get('QW-ACT-R4');
const r71 = this.assertions.get('QW-ACT-R71');
for (const elem of metaElements !== null && metaElements !== void 0 ? metaElements : []) {
if (this.toExecute['QW-ACT-R4']) {
(_a = r4 === null || r4 === void 0 ? void 0 : r4.execute) === null || _a === void 0 ? void 0 : _a.call(r4, elem);
}
if (this.toExecute['QW-ACT-R71']) {
(_b = r71 === null || r71 === void 0 ? void 0 : r71.execute) === null || _b === void 0 ? void 0 : _b.call(r71, elem);
}
}
if (this.toExecute['QW-ACT-R4'] && r4) {
this.report.addAssertionResult(r4);
}
if (this.toExecute['QW_ACT_R71'] && r71) {
this.report.addAssertionResult(r71);
}
}
}
validateZoomedTextNodeNotClippedWithCSSOverflow() {
if (this.toExecute['QW-ACT-R40']) {
const r40 = this.assertions.get('QW-ACT-R40');
if (r40) {
const elements = window.qwPage.getElements('body *');
elements.forEach((element) => { var _a; return (_a = r40 === null || r40 === void 0 ? void 0 : r40.execute) === null || _a === void 0 ? void 0 : _a.call(r40, element); });
this.report.addAssertionResult(r40);
}
}
}
}
exports.ACTRulesTester = ACTRulesTester;