-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
htmlcs.ts
85 lines (78 loc) · 1.87 KB
/
htmlcs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const run = async (options) => {
return new Promise((resolve, reject) => {
if (
// @ts-ignore
typeof window.define === "function" &&
// @ts-ignore
window.define.amd &&
typeof window.require === "function"
) {
// @ts-ignore module load
window.require(["htmlcs"], (htmlcs) => {
Object.keys(htmlcs).forEach((key) => {
window[key] = htmlcs[key];
});
window.HTMLCS = htmlcs.HTMLCS;
});
}
// map standards to window
if (
!(
!options.rules ||
(options.rules && !options.rules.length) ||
options.standard === "Section508"
)
) {
for (const rule of options.rules) {
if (window.HTMLCS_WCAG2AAA.sniffs.includes(rule)) {
window[`HTMLCS_${options.standard}`].sniffs[0].include.push(rule);
} else {
console.error(`${rule} is not a valid WCAG 2.1 rule`);
}
}
}
// todo: remove complete rules from running
// @ts-ignore
window.HTMLCS.process(
options.standard || "WCAG2AA",
(options.rootElement &&
window.document.querySelector(options.rootElement)) ||
window.document,
(error) => {
if (error) {
return reject(error);
}
// @ts-ignore
resolve(window.HTMLCS.messages);
},
(error) => reject(error),
options.language,
);
});
};
const htmlcsRunner = {
en: {
scripts: [require.resolve("fast_htmlcs/build/HTMLCS.js")],
run,
},
};
// hard code locales to the list to htmlcs locales not EN
const htmlcsLocales = [
"ar",
"fr",
"es",
"it",
"ja",
"nl",
"pl",
"ko",
"zh_CN",
"zh_TW",
];
for (const lang of htmlcsLocales) {
htmlcsRunner[lang.replace("_", "-")] = {
scripts: [require.resolve(`fast_htmlcs/build/HTMLCS.${lang}.js`)],
run,
};
}
export { htmlcsRunner, htmlcsLocales };