@uuv/a11y
Version:
A javascript lib for running a11y validation based on multiple reference(RGAA, etc)
150 lines (149 loc) • 5.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const model_1 = require("../../../model");
const query_1 = require("../../../query");
const SELECTOR_ALL_LINK = [
"a",
"[role=link]"
];
const SELECTOR_LINK_TEXT = [
":not(svg) > a[href]:not(:has(img)):not(:has([role=img])):not(:has(object)):not(:has(canvas)):not(:has(svg))",
":not(svg) > [role=link]:not(:has(img)):not(:has([role=img])):not(:has(object)):not(:has(canvas)):not(:has(svg))"
];
const SELECTOR_LINK_CONTAINING_IMAGE = [
":not(svg) > a[href]:has(img)",
":not(svg) > a[href]:has([role=img])",
":not(svg) > a[href]:has(area[href])",
":not(svg) > a[href]:has(object)",
":not(svg) > a[href]:has(canvas)",
":not(svg) > a[href]:has(svg)",
":not(svg) > [role=link]:has(img)",
":not(svg) > [role=link]:has([role=img])",
":not(svg) > [role=link]:has(area[href])",
":not(svg) > [role=link]:has(object)",
":not(svg) > [role=link]:has(canvas)",
":not(svg) > [role=link]:has(svg)"
];
const SELECTOR_LINK_SVG = [
"svg:has(a[href])",
"svg:has(a[xlink-href])"
];
const IMAGE_LINK_QUERY = new query_1.CompliantAttributesQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_CONTAINING_IMAGE
]), [
query_1.AttributeChecker.emptyText()
]);
const COMPOSITE_LINK_QUERY = new query_1.CompliantAttributesQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_CONTAINING_IMAGE
]), [
query_1.AttributeChecker.notEmptyText()
]);
exports.default = [
model_1.AutoCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.1",
elementType: "link",
query: new query_1.AccessibleNameQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_TEXT
]), true),
description: "text link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.ManualCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.1",
elementType: "link",
query: new query_1.AccessibleNameQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_TEXT
]), false),
description: "text link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.AutoCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.2",
elementType: "link",
query: new query_1.AccessibleNameQuery(IMAGE_LINK_QUERY, true),
description: "image link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.ManualCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.2",
elementType: "link",
query: new query_1.AccessibleNameQuery(IMAGE_LINK_QUERY, false),
description: "image link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.ManualCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.3",
elementType: "link",
query: new query_1.AccessibleNameQuery(COMPOSITE_LINK_QUERY, false),
description: "image link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.AutoCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.4",
elementType: "link",
query: new query_1.AccessibleNameQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_SVG
]), true),
description: "svg link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.ManualCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.4",
elementType: "link",
query: new query_1.AccessibleNameQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_SVG
]), false),
description: "svg link must be explicit",
help: "Check link accessible name or link context"
}),
model_1.AutoCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.5",
elementType: "link",
query: new query_1.CompliantAttributesQuery(new query_1.ByTagQuery([
...SELECTOR_LINK_TEXT,
...SELECTOR_LINK_CONTAINING_IMAGE
]), [
query_1.AttributeChecker.accessibleNameNotContainsVisibleText()
]),
description: "Accessible name must contains visible text for text link and image link",
help: "Accessible name must contains visible text for text link and image link"
}),
model_1.ManualCheckA11yRule.from({
criterion: "6.1",
wcag: "1.1.1 A, 2.4.4 A, 2.5.3 A",
id: "6.1.5",
elementType: "link",
query: new query_1.ByTagQuery([
...SELECTOR_LINK_SVG
]),
description: "Accessible name must contains visible text for svg link",
help: "Accessible name must contains visible text for svg link"
}),
model_1.AutoCheckA11yRule.from({
criterion: "6.2",
wcag: "1.1.1 A, 2.4.4 A",
id: "6.2.1",
elementType: "link",
query: new query_1.AccessibleNameQuery(new query_1.ByTagQuery([
...SELECTOR_ALL_LINK
]), true),
description: "Every link must have an accessible name",
help: "Every link must have an accessible name"
})
];