UNPKG

@qualweb/act-rules

Version:

ACT rules module for qualweb web accessibility evaluator

95 lines (94 loc) 4.4 kB
"use strict"; 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_ACT_R69 = void 0; const applicability_1 = require("@qualweb/util/applicability"); const evaluation_1 = require("@qualweb/core/evaluation"); const AtomicRule_object_1 = require("../lib/AtomicRule.object"); class QW_ACT_R69 extends AtomicRule_object_1.AtomicRule { execute(element) { const test = new evaluation_1.Test(); if (element.hasCSSProperty('word-spacing') || this.findParentWithCSSProperty(element) !== null) { const styleAttribute = element.getElementAttribute('style'); const declaredWordSpacing = this.parseStyle(styleAttribute); const computedRawWordSpacing = element.getCSSProperty('word-spacing'); const computedWordSpacing = element.getElementStyleProperty('word-spacing', null); const fontSize = element.getElementStyleProperty('font-size', null); if (element.hasCSSProperty('word-spacing') && !this.isImportant(computedRawWordSpacing, element)) { test.verdict = evaluation_1.Verdict.PASSED; test.resultCode = 'P1'; } else if (this.isWide(computedWordSpacing, fontSize)) { test.verdict = evaluation_1.Verdict.PASSED; test.resultCode = 'P2'; } else if (!this.isCascade(declaredWordSpacing, computedRawWordSpacing)) { test.verdict = evaluation_1.Verdict.PASSED; test.resultCode = 'P3'; } else { test.verdict = evaluation_1.Verdict.FAILED; test.resultCode = 'F1'; } test.addElement(element, true, false, true); this.addTestResult(test); } } parseStyle(style) { if (style === null) { style = ''; } const startLS = style.indexOf('word-spacing:'); let endLS = style.indexOf(';', startLS); if (endLS === -1) { endLS = style.length; } return style === null || style === void 0 ? void 0 : style.substring(startLS + 13, endLS); } isImportant(cssValue, element) { if (cssValue.value === 'inherit' || cssValue.value === 'unset') { const parent = this.findParentWithCSSProperty(element.getElementParent()); if (parent === null) return false; return this.isImportant(parent === null || parent === void 0 ? void 0 : parent.getCSSProperty('word-spacing'), parent); } return cssValue.important; } isWide(wordSpacing, fontSize) { const spacing = parseFloat(wordSpacing.slice(0, -2)); const font = parseFloat(fontSize.slice(0, -2)); return spacing >= font * 0.16; } isCascade(declaredStyle, computedStyle) { if (computedStyle && computedStyle.value) { return declaredStyle.includes(computedStyle.value); } return false; } findParentWithCSSProperty(element) { while (element !== null) { if (element === null || element === void 0 ? void 0 : element.getCSSProperty('word-spacing')) { return element; } element = element.getElementParent(); } return null; } } exports.QW_ACT_R69 = QW_ACT_R69; __decorate([ applicability_1.ElementExists, applicability_1.ElementIsVisible, applicability_1.ElementHasTextNode, __metadata("design:type", Function), __metadata("design:paramtypes", [Function]), __metadata("design:returntype", void 0) ], QW_ACT_R69.prototype, "execute", null);