@qualweb/wcag-techniques
Version:
Implementation of the WCAG 2.1 techniques
73 lines (72 loc) • 3.3 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QW_WCAG_T31 = void 0;
const applicability_1 = require("@qualweb/util/applicability");
const evaluation_1 = require("@qualweb/core/evaluation");
const Technique_object_1 = require("../lib/Technique.object");
class QW_WCAG_T31 extends Technique_object_1.Technique {
execute(element) {
var _a;
if (element.getElementTagName() === 'head' ||
((_a = element.getElementParent()) === null || _a === void 0 ? void 0 : _a.getElementTagName()) === 'head' ||
!element.hasTextNode()) {
return;
}
const test = new evaluation_1.Test();
let foundColorProperty = false;
let foundBackgroundProperty = false;
let parent = element;
while (parent !== null) {
const hasColor = parent.hasCSSProperty('color');
const hasBackgroundColor = parent.hasCSSProperty('background-color');
const hasBackgroundImage = parent.hasCSSProperty('background-image');
const hasBackground = parent.hasCSSProperty('background');
if (hasColor && !foundColorProperty) {
foundColorProperty = true;
}
if ((hasBackground || hasBackgroundColor || hasBackgroundImage) && !foundBackgroundProperty) {
foundBackgroundProperty = true;
}
if (foundColorProperty && foundBackgroundProperty) {
parent = null;
}
else {
parent = parent.getElementParent();
}
}
if (foundColorProperty && foundBackgroundProperty) {
test.verdict = evaluation_1.Verdict.PASSED;
test.resultCode = 'P1';
test.addElement(element);
this.addTestResult(test);
}
else if (foundColorProperty) {
test.verdict = evaluation_1.Verdict.FAILED;
test.resultCode = 'F1';
test.addElement(element);
this.addTestResult(test);
}
else if (foundBackgroundProperty) {
test.verdict = evaluation_1.Verdict.FAILED;
test.resultCode = 'F2';
test.addElement(element);
this.addTestResult(test);
}
}
}
exports.QW_WCAG_T31 = QW_WCAG_T31;
__decorate([
applicability_1.ElementExists,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function]),
__metadata("design:returntype", void 0)
], QW_WCAG_T31.prototype, "execute", null);