@qualweb/cui-checks 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/CuiChecksModule.d.ts +10 -0
  2. package/dist/CuiChecksModule.d.ts.map +1 -0
  3. package/dist/CuiChecksModule.js +19 -0
  4. package/dist/CuiChecksRunner.d.ts +9 -0
  5. package/dist/CuiChecksRunner.d.ts.map +1 -0
  6. package/dist/CuiChecksRunner.js +18 -0
  7. package/dist/__webpack/cui.bundle.js +1 -0
  8. package/dist/checks/QW-CUI-C1.d.ts +7 -0
  9. package/dist/checks/QW-CUI-C1.d.ts.map +1 -0
  10. package/dist/checks/QW-CUI-C1.js +32 -0
  11. package/dist/checks/index.d.ts +2 -0
  12. package/dist/checks/index.d.ts.map +1 -0
  13. package/dist/checks/index.js +17 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +7 -0
  17. package/dist/lib/CUIChecksTester.object.d.ts +9 -0
  18. package/dist/lib/CUIChecksTester.object.d.ts.map +1 -0
  19. package/dist/lib/CUIChecksTester.object.js +71 -0
  20. package/dist/lib/Check.object.d.ts +21 -0
  21. package/dist/lib/Check.object.d.ts.map +1 -0
  22. package/dist/lib/Check.object.js +76 -0
  23. package/dist/lib/checks.json +25 -0
  24. package/dist/lib/mapping.d.ts +5 -0
  25. package/dist/lib/mapping.d.ts.map +1 -0
  26. package/dist/lib/mapping.js +5 -0
  27. package/package.json +24 -20
  28. package/.mocharc.js +0 -3
  29. package/CHANGELOG.md +0 -11
  30. package/compile-rules.js +0 -23
  31. package/cui-checks.schema.json +0 -115
  32. package/dist/cui.bundle.js +0 -1
  33. package/src/index.ts +0 -121
  34. package/src/lib/Check.object.ts +0 -105
  35. package/src/lib/Test.object.ts +0 -40
  36. package/src/lib/decorator.ts +0 -463
  37. package/src/lib/rules.json +0 -25
  38. package/src/lib/rules.ts +0 -5
  39. package/src/rules/QW-CUI-C1.ts +0 -46
  40. package/tsconfig.json +0 -43
  41. package/tsconfig.prod.json +0 -20
  42. package/validate-rules.js +0 -42
  43. package/webpack.config.js +0 -30
package/src/index.ts DELETED
@@ -1,121 +0,0 @@
1
- import {
2
- CUIOptions,
3
- CUIChecksReport
4
- } from '@qualweb/cui-checks';
5
- import { Translate } from '@qualweb/locale';
6
- import * as rules from './lib/rules';
7
- import Check from './lib/Check.object';
8
-
9
- class CUIChecks {
10
- private readonly rules: { [rule: string]: Check };
11
- private readonly rulesToExecute: { [rule: string]: boolean };
12
-
13
- private readonly report: CUIChecksReport;
14
-
15
- constructor(locale: Translate, options?: CUIOptions) {
16
- this.rules = {};
17
- this.rulesToExecute = {};
18
- this.report = {
19
- type: 'cui-checks',
20
- metadata: {
21
- passed: 0,
22
- warning: 0,
23
- failed: 0,
24
- inapplicable: 0
25
- },
26
- assertions: {}
27
- };
28
-
29
- for (const rule of Object.keys(rules) || []) {
30
- const _rule = rule.replace(/_/g, '-');
31
- //@ts-ignore
32
- this.rules[_rule] = new rules[rule](locale);
33
- this.rulesToExecute[_rule] = true;
34
- }
35
-
36
- if (options) {
37
- this.configure(options);
38
- }
39
- }
40
-
41
- public configure(options: CUIOptions): void {
42
- this.resetConfiguration();
43
- if (options.rules) {
44
- options.rules = options.rules.map((r: string) => {
45
- return r.toLowerCase().startsWith('qw') ? r.toUpperCase().trim() : r.trim();
46
- });
47
- }
48
- if (options.exclude) {
49
- options.exclude = options.exclude.map((r: string) => {
50
- return r.toLowerCase().startsWith('qw') ? r.toUpperCase().trim() : r.trim();
51
- });
52
- }
53
-
54
- for (const rule of Object.keys(this.rules) || []) {
55
- if (options.principles && options.principles.length !== 0) {
56
- if (options.levels && options.levels.length !== 0) {
57
- if (!this.rules[rule].hasPrincipleAndLevels(options.principles, options.levels)) {
58
- this.rulesToExecute[rule] = false;
59
- }
60
- } else if (!this.rules[rule].hasPrincipleAndLevels(options.principles, ['A', 'AA', 'AAA'])) {
61
- this.rulesToExecute[rule] = false;
62
- }
63
- } else if (options.levels && options.levels.length !== 0) {
64
- if (
65
- !this.rules[rule].hasPrincipleAndLevels(
66
- ['Perceivable', 'Operable', 'Understandable', 'Robust'],
67
- options.levels
68
- )
69
- ) {
70
- this.rulesToExecute[rule] = false;
71
- }
72
- }
73
- if (!options.principles && !options.levels) {
74
- if (options.rules && options.rules.length !== 0) {
75
- if (!options.rules.includes(rule) && !options.rules.includes(this.rules[rule]?.getRuleMapping())) {
76
- this.rulesToExecute[rule] = false;
77
- } else {
78
- this.rulesToExecute[rule] = true;
79
- }
80
- }
81
- } else {
82
- if (options.rules && options.rules.length !== 0) {
83
- if (options.rules.includes(rule) || options.rules.includes(this.rules[rule]?.getRuleMapping())) {
84
- this.rulesToExecute[rule] = true;
85
- }
86
- }
87
- }
88
- if (options.exclude && options.exclude.length !== 0) {
89
- if (options.exclude.includes(rule) || options.exclude.includes(this.rules[rule]?.getRuleMapping())) {
90
- this.rulesToExecute[rule] = false;
91
- }
92
- }
93
- }
94
- }
95
-
96
- public resetConfiguration(): void {
97
- for (const rule in this.rulesToExecute ?? {}) {
98
- this.rulesToExecute[rule] = true;
99
- }
100
- }
101
-
102
- public executeRule(rule: string, selector: string): void {
103
- const elements = window.qwPage.getElements(selector);
104
- if (elements.length > 0) {
105
- for (const elem of elements ?? []) {
106
- this.rules[rule].execute(elem);
107
- }
108
- } else {
109
- this.rules[rule].execute(undefined);
110
- }
111
-
112
- this.report.assertions[rule] = this.rules[rule].getFinalResults();
113
- this.report.metadata[this.report.assertions[rule].metadata.outcome]++;
114
- }
115
-
116
- public getReport(): CUIChecksReport {
117
- return this.report;
118
- }
119
- }
120
-
121
- export { CUIChecks };
@@ -1,105 +0,0 @@
1
- import { CUICheck, TranslationValues } from '@qualweb/cui-checks';
2
- import { Translate } from '@qualweb/locale';
3
- import { Level, Principle } from '@qualweb/evaluation';
4
-
5
- import Test from '@qualweb/act-rules/src/lib/Test.object';
6
-
7
- abstract class Check {
8
- protected readonly rule: CUICheck;
9
- protected readonly locale: Translate;
10
-
11
- constructor(rule: CUICheck, locale: Translate) {
12
- this.rule = rule;
13
- this.locale = locale;
14
- }
15
-
16
- abstract execute(element: typeof window.qwElement | undefined): void;
17
-
18
- public getRuleMapping(): string {
19
- return this.rule.mapping;
20
- }
21
-
22
- public hasPrincipleAndLevels(principles: Array<Principle>, levels: Array<Level>): boolean {
23
- let has = false;
24
- for (const sc of this.rule.metadata['success-criteria'] ?? []) {
25
- if (principles.includes(sc.principle) && levels.includes(sc.level)) {
26
- has = true;
27
- }
28
- }
29
- return has;
30
- }
31
-
32
- public getFinalResults(): CUICheck {
33
- this.outcomeRule();
34
- return this.rule;
35
- }
36
-
37
- protected getNumberOfPassedResults(): number {
38
- return this.rule.metadata.passed;
39
- }
40
-
41
- protected getNumberOfWarningResults(): number {
42
- return this.rule.metadata.warning;
43
- }
44
-
45
- protected getNumberOfFailedResults(): number {
46
- return this.rule.metadata.failed;
47
- }
48
-
49
- protected addTestResult(test: Test): void {
50
- if (!test.description || test.description.trim() === '') {
51
- test.description = this.getTranslation(test.resultCode);
52
- }
53
-
54
- this.rule.results.push(test);
55
-
56
- if (test.verdict && test.verdict !== 'inapplicable') {
57
- this.rule.metadata[test.verdict]++;
58
- }
59
- }
60
-
61
- protected getTranslation(resultCode: string, values?: TranslationValues): string {
62
- let translation = '';
63
- if (this.locale.translate['act-rules']?.[this.rule.code]?.results?.[resultCode]) {
64
- translation = <string>this.locale.translate['act-rules'][this.rule.code].results?.[resultCode];
65
- } else {
66
- translation = <string>this.locale.fallback['act-rules']?.[this.rule.code].results?.[resultCode];
67
- }
68
-
69
- if (values) {
70
- for (const key of Object.keys(values) || []) {
71
- translation = translation.replace(new RegExp(`{${key}}`, 'g'), values[key].toString());
72
- }
73
- }
74
-
75
- return translation;
76
- }
77
-
78
- private outcomeRule(): void {
79
- if (this.rule.metadata.failed > 0) {
80
- this.rule.metadata.outcome = 'failed';
81
- } else if (this.rule.metadata.warning > 0) {
82
- this.rule.metadata.outcome = 'warning';
83
- } else if (this.rule.metadata.passed > 0) {
84
- this.rule.metadata.outcome = 'passed';
85
- } else {
86
- this.rule.metadata.outcome = 'inapplicable';
87
- this.rule.metadata.inapplicable = 1;
88
- }
89
-
90
- if (this.rule.results.length > 0) {
91
- this.addDescription();
92
- }
93
- }
94
-
95
- private addDescription(): void {
96
- for (const result of this.rule.results ?? []) {
97
- if (result.verdict === this.rule.metadata.outcome) {
98
- this.rule.metadata.description = result.description;
99
- break;
100
- }
101
- }
102
- }
103
- }
104
-
105
- export = Check;
@@ -1,40 +0,0 @@
1
- import { CUICheckResult, CUIElement } from '@qualweb/cui-checks';
2
-
3
- class Test implements CUICheckResult {
4
- verdict: 'passed' | 'failed' | 'warning' | 'inapplicable';
5
- description: string;
6
- resultCode: string;
7
- elements: Array<CUIElement>;
8
- attributes: Array<string>;
9
-
10
- constructor(verdict?: 'passed' | 'failed' | 'warning', description?: string, resultCode?: string) {
11
- this.verdict = verdict ?? 'inapplicable';
12
- this.description = description ?? '';
13
- this.resultCode = resultCode ?? 'I1';
14
- this.elements = new Array<CUICheckResult>();
15
- this.attributes = new Array<string>();
16
- }
17
-
18
- public addElement(element: typeof window.qwElement, withText = true, fullElement = false, aName?: boolean): void {
19
- const htmlCode = element.getElementHtmlCode(withText, fullElement);
20
- const pointer = element.getElementSelector();
21
- let accessibleName: string | undefined;
22
- if (aName) {
23
- accessibleName = window.AccessibilityUtils.getAccessibleName(element);
24
- }
25
- this.elements.push({ htmlCode, pointer, accessibleName });
26
- }
27
-
28
- public addElements(
29
- elements: Array<typeof window.qwElement>,
30
- withText = true,
31
- fullElement = false,
32
- aName?: boolean
33
- ): void {
34
- for (const element of elements ?? []) {
35
- this.addElement(element, withText, fullElement, aName);
36
- }
37
- }
38
- }
39
-
40
- export = Test;