@govtechsg/oobee 0.10.36 → 0.10.42

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 (39) hide show
  1. package/.github/workflows/docker-test.yml +1 -1
  2. package/DETAILS.md +3 -3
  3. package/INTEGRATION.md +142 -53
  4. package/README.md +17 -0
  5. package/REPORTS.md +362 -0
  6. package/exclusions.txt +4 -1
  7. package/package.json +2 -2
  8. package/src/constants/cliFunctions.ts +0 -7
  9. package/src/constants/common.ts +39 -1
  10. package/src/constants/constants.ts +9 -8
  11. package/src/crawlers/commonCrawlerFunc.ts +95 -220
  12. package/src/crawlers/crawlDomain.ts +10 -23
  13. package/src/crawlers/crawlLocalFile.ts +2 -0
  14. package/src/crawlers/crawlSitemap.ts +6 -4
  15. package/src/crawlers/custom/escapeCssSelector.ts +10 -0
  16. package/src/crawlers/custom/evaluateAltText.ts +13 -0
  17. package/src/crawlers/custom/extractAndGradeText.ts +0 -2
  18. package/src/crawlers/custom/extractText.ts +28 -0
  19. package/src/crawlers/custom/findElementByCssSelector.ts +46 -0
  20. package/src/crawlers/custom/flagUnlabelledClickableElements.ts +982 -842
  21. package/src/crawlers/custom/framesCheck.ts +51 -0
  22. package/src/crawlers/custom/getAxeConfiguration.ts +126 -0
  23. package/src/crawlers/custom/gradeReadability.ts +30 -0
  24. package/src/crawlers/custom/xPathToCss.ts +178 -0
  25. package/src/crawlers/pdfScanFunc.ts +67 -26
  26. package/src/mergeAxeResults.ts +535 -132
  27. package/src/npmIndex.ts +130 -62
  28. package/src/screenshotFunc/htmlScreenshotFunc.ts +1 -1
  29. package/src/screenshotFunc/pdfScreenshotFunc.ts +34 -1
  30. package/src/static/ejs/partials/components/ruleOffcanvas.ejs +1 -1
  31. package/src/static/ejs/partials/components/scanAbout.ejs +1 -1
  32. package/src/static/ejs/partials/footer.ejs +3 -3
  33. package/src/static/ejs/partials/scripts/reportSearch.ejs +112 -74
  34. package/src/static/ejs/partials/scripts/ruleOffcanvas.ejs +2 -2
  35. package/src/static/ejs/partials/summaryMain.ejs +3 -3
  36. package/src/static/ejs/report.ejs +3 -3
  37. package/src/utils.ts +289 -13
  38. package/src/xPathToCssCypress.ts +178 -0
  39. package/src/crawlers/customAxeFunctions.ts +0 -82
package/src/utils.ts CHANGED
@@ -7,7 +7,10 @@ import constants, {
7
7
  destinationPath,
8
8
  getIntermediateScreenshotsPath,
9
9
  } from './constants/constants.js';
10
- import { silentLogger } from './logs.js';
10
+ import { consoleLogger, silentLogger } from './logs.js';
11
+ import { getAxeConfiguration } from './crawlers/custom/getAxeConfiguration.js';
12
+ import axe from 'axe-core';
13
+ import { Rule, RuleMetadata } from 'axe-core';
11
14
 
12
15
  export const getVersion = () => {
13
16
  const loadJSON = filePath =>
@@ -178,18 +181,6 @@ export const cleanUp = async pathToDelete => {
178
181
  fs.removeSync(pathToDelete);
179
182
  };
180
183
 
181
- /* istanbul ignore next */
182
- // export const getFormattedTime = () =>
183
- // new Date().toLocaleTimeString('en-GB', {
184
- // year: 'numeric',
185
- // month: 'short',
186
- // day: 'numeric',
187
- // hour12: true,
188
- // hour: 'numeric',
189
- // minute: '2-digit',
190
- // timeZoneName: "longGeneric",
191
- // });
192
-
193
184
  export const getWcagPassPercentage = (
194
185
  wcagViolations: string[],
195
186
  showEnableWcagAaa: boolean
@@ -228,6 +219,291 @@ export const getWcagPassPercentage = (
228
219
  };
229
220
  };
230
221
 
222
+ export interface ScanPagesDetail {
223
+ oobeeAppVersion?: string;
224
+ pagesAffected: PageDetail[];
225
+ pagesNotAffected: PageDetail[];
226
+ scannedPagesCount: number;
227
+ pagesNotScanned: PageDetail[];
228
+ pagesNotScannedCount: number;
229
+ }
230
+
231
+ export interface PageDetail {
232
+ pageTitle: string;
233
+ url: string;
234
+ totalOccurrencesFailedIncludingNeedsReview: number;
235
+ totalOccurrencesFailedExcludingNeedsReview: number;
236
+ totalOccurrencesMustFix?: number;
237
+ totalOccurrencesGoodToFix?: number;
238
+ totalOccurrencesNeedsReview: number;
239
+ totalOccurrencesPassed: number;
240
+ occurrencesExclusiveToNeedsReview: boolean;
241
+ typesOfIssuesCount: number;
242
+ typesOfIssuesExcludingNeedsReviewCount: number;
243
+ categoriesPresent: IssueCategory[];
244
+ conformance?: string[]; // WCAG levels as flexible strings
245
+ typesOfIssues: IssueDetail[];
246
+ }
247
+
248
+ export type IssueCategory = "mustFix" | "goodToFix" | "needsReview" | "passed";
249
+
250
+ export interface IssueDetail {
251
+ ruleId: string;
252
+ wcagConformance: string[];
253
+ occurrencesMustFix?: number;
254
+ occurrencesGoodToFix?: number;
255
+ occurrencesNeedsReview?: number;
256
+ occurrencesPassed: number;
257
+ }
258
+
259
+ export const getProgressPercentage = (
260
+ scanPagesDetail: ScanPagesDetail,
261
+ showEnableWcagAaa: boolean
262
+ ): {
263
+ averageProgressPercentageAA: string;
264
+ averageProgressPercentageAAandAAA: string;
265
+ } => {
266
+ const pages = scanPagesDetail.pagesAffected || [];
267
+
268
+ const progressPercentagesAA = pages.map((page: any) => {
269
+ const violations: string[] = page.conformance;
270
+ return getWcagPassPercentage(violations, showEnableWcagAaa).passPercentageAA;
271
+ });
272
+
273
+ const progressPercentagesAAandAAA = pages.map((page: any) => {
274
+ const violations: string[] = page.conformance;
275
+ return getWcagPassPercentage(violations, showEnableWcagAaa).passPercentageAAandAAA;
276
+ });
277
+
278
+ const totalAA = progressPercentagesAA.reduce((sum, p) => sum + parseFloat(p), 0);
279
+ const avgAA = progressPercentagesAA.length ? totalAA / progressPercentagesAA.length : 0;
280
+
281
+ const totalAAandAAA = progressPercentagesAAandAAA.reduce((sum, p) => sum + parseFloat(p), 0);
282
+ const avgAAandAAA = progressPercentagesAAandAAA.length ? totalAAandAAA / progressPercentagesAAandAAA.length : 0;
283
+
284
+ return {
285
+ averageProgressPercentageAA: avgAA.toFixed(2),
286
+ averageProgressPercentageAAandAAA: avgAAandAAA.toFixed(2),
287
+ };
288
+ };
289
+
290
+ export const getTotalRulesCount = async (
291
+ enableWcagAaa: boolean,
292
+ disableOobee: boolean
293
+ ): Promise<{
294
+ totalRulesMustFix: number;
295
+ totalRulesGoodToFix: number;
296
+ totalRulesMustFixAndGoodToFix: number;
297
+ }> => {
298
+ const axeConfig = getAxeConfiguration({
299
+ enableWcagAaa,
300
+ gradingReadabilityFlag: '',
301
+ disableOobee,
302
+ });
303
+
304
+ // Get default rules from axe-core
305
+ const defaultRules = await axe.getRules();
306
+
307
+ // Merge custom rules with default rules, converting RuleMetadata to Rule
308
+ const mergedRules: Rule[] = defaultRules.map((defaultRule) => {
309
+ const customRule = axeConfig.rules.find((r) => r.id === defaultRule.ruleId);
310
+ if (customRule) {
311
+ // Merge properties from customRule into defaultRule (RuleMetadata) to create a Rule
312
+ return {
313
+ id: defaultRule.ruleId,
314
+ enabled: customRule.enabled,
315
+ selector: customRule.selector,
316
+ any: customRule.any,
317
+ tags: defaultRule.tags,
318
+ metadata: customRule.metadata, // Use custom metadata if it exists
319
+ };
320
+ } else {
321
+ // Convert defaultRule (RuleMetadata) to Rule
322
+ return {
323
+ id: defaultRule.ruleId,
324
+ enabled: true, // Default to true if not overridden
325
+ tags: defaultRule.tags,
326
+ // No metadata here, since defaultRule.metadata might not exist
327
+ };
328
+ }
329
+ });
330
+
331
+ // Add any custom rules that don't override the default rules
332
+ axeConfig.rules.forEach(customRule => {
333
+ if (!mergedRules.some(mergedRule => mergedRule.id === customRule.id)) {
334
+ // Ensure customRule is of type Rule
335
+ const rule: Rule = {
336
+ id: customRule.id,
337
+ enabled: customRule.enabled,
338
+ selector: customRule.selector,
339
+ any: customRule.any,
340
+ tags: customRule.tags,
341
+ metadata: customRule.metadata,
342
+ // Add other properties if needed
343
+ };
344
+ mergedRules.push(rule);
345
+ }
346
+ });
347
+
348
+ // Apply the merged configuration to axe-core
349
+ await axe.configure({ ...axeConfig, rules: mergedRules });
350
+
351
+ const rules = await axe.getRules();
352
+
353
+ // ... (rest of your logic)
354
+ let totalRulesMustFix = 0;
355
+ let totalRulesGoodToFix = 0;
356
+
357
+ const wcagRegex = /^wcag\d+a+$/;
358
+
359
+ // Use mergedRules instead of rules to check enabled property
360
+ mergedRules.forEach((rule) => {
361
+ if (!rule.enabled) {
362
+ return;
363
+ }
364
+
365
+ if (rule.id === 'frame-tested') return; // Ignore 'frame-tested' rule
366
+
367
+ const tags = rule.tags || [];
368
+
369
+ // Skip experimental and deprecated rules
370
+ if (tags.includes('experimental') || tags.includes('deprecated')) {
371
+ return;
372
+ }
373
+
374
+ let conformance = tags.filter(tag => tag.startsWith('wcag') || tag === 'best-practice');
375
+
376
+ // Ensure conformance level is sorted correctly
377
+ if (conformance.length > 0 && conformance[0] !== 'best-practice' && !wcagRegex.test(conformance[0])) {
378
+ conformance.sort((a, b) => {
379
+ if (wcagRegex.test(a) && !wcagRegex.test(b)) {
380
+ return -1;
381
+ }
382
+ if (!wcagRegex.test(a) && wcagRegex.test(b)) {
383
+ return 1;
384
+ }
385
+ return 0;
386
+ });
387
+ }
388
+
389
+ if (conformance.includes('best-practice')) {
390
+ // console.log(`${totalRulesMustFix} Good To Fix: ${rule.id}`);
391
+
392
+ totalRulesGoodToFix++; // Categorized as "Good to Fix"
393
+ } else {
394
+ // console.log(`${totalRulesMustFix} Must Fix: ${rule.id}`);
395
+
396
+ totalRulesMustFix++; // Otherwise, it's "Must Fix"
397
+ }
398
+ });
399
+
400
+ return {
401
+ totalRulesMustFix,
402
+ totalRulesGoodToFix,
403
+ totalRulesMustFixAndGoodToFix: totalRulesMustFix + totalRulesGoodToFix,
404
+ };
405
+ };
406
+
407
+ export const getIssuesPercentage = async (
408
+ scanPagesDetail: ScanPagesDetail,
409
+ enableWcagAaa: boolean,
410
+ disableOobee: boolean
411
+ ): Promise<{
412
+ avgTypesOfIssuesPercentageOfTotalRulesAtMustFix: string;
413
+ avgTypesOfIssuesPercentageOfTotalRulesAtGoodToFix: string;
414
+ avgTypesOfIssuesPercentageOfTotalRulesAtMustFixAndGoodToFix: string;
415
+ totalRulesMustFix: number;
416
+ totalRulesGoodToFix: number;
417
+ totalRulesMustFixAndGoodToFix: number;
418
+ avgTypesOfIssuesCountAtMustFix: string;
419
+ avgTypesOfIssuesCountAtGoodToFix: string;
420
+ avgTypesOfIssuesCountAtMustFixAndGoodToFix: string;
421
+ pagesAffectedPerRule: Record<string, number>;
422
+ pagesPercentageAffectedPerRule: Record<string, string>;
423
+ }> => {
424
+ const pages = scanPagesDetail.pagesAffected || [];
425
+ const totalPages = pages.length;
426
+
427
+ const pagesAffectedPerRule: Record<string, number> = {};
428
+
429
+ pages.forEach((page) => {
430
+ page.typesOfIssues.forEach((issue) => {
431
+ if ((issue.occurrencesMustFix || issue.occurrencesGoodToFix) > 0) {
432
+ pagesAffectedPerRule[issue.ruleId] = (pagesAffectedPerRule[issue.ruleId] || 0) + 1;
433
+ }
434
+ });
435
+ });
436
+
437
+ const pagesPercentageAffectedPerRule: Record<string, string> = {};
438
+ for (const [ruleId, count] of Object.entries(pagesAffectedPerRule)) {
439
+ pagesPercentageAffectedPerRule[ruleId] = totalPages > 0 ? ((count / totalPages) * 100).toFixed(2) : "0.00";
440
+ }
441
+
442
+ const typesOfIssuesCountAtMustFix = pages.map((page) =>
443
+ page.typesOfIssues.filter((issue) => (issue.occurrencesMustFix || 0) > 0).length
444
+ );
445
+
446
+ const typesOfIssuesCountAtGoodToFix = pages.map((page) =>
447
+ page.typesOfIssues.filter((issue) => (issue.occurrencesGoodToFix || 0) > 0).length
448
+ );
449
+
450
+ const typesOfIssuesCountSumMustFixAndGoodToFix = pages.map(
451
+ (_, index) =>
452
+ (typesOfIssuesCountAtMustFix[index] || 0) +
453
+ (typesOfIssuesCountAtGoodToFix[index] || 0)
454
+ );
455
+
456
+ const { totalRulesMustFix, totalRulesGoodToFix, totalRulesMustFixAndGoodToFix } = await getTotalRulesCount(
457
+ enableWcagAaa,
458
+ disableOobee
459
+ );
460
+
461
+ const avgMustFixPerPage = totalPages > 0
462
+ ? typesOfIssuesCountAtMustFix.reduce((sum, count) => sum + count, 0) / totalPages
463
+ : 0;
464
+
465
+ const avgGoodToFixPerPage = totalPages > 0
466
+ ? typesOfIssuesCountAtGoodToFix.reduce((sum, count) => sum + count, 0) / totalPages
467
+ : 0;
468
+
469
+ const avgMustFixAndGoodToFixPerPage = totalPages > 0
470
+ ? typesOfIssuesCountSumMustFixAndGoodToFix.reduce((sum, count) => sum + count, 0) / totalPages
471
+ : 0;
472
+
473
+ const avgTypesOfIssuesPercentageOfTotalRulesAtMustFix =
474
+ totalRulesMustFix > 0
475
+ ? ((avgMustFixPerPage / totalRulesMustFix) * 100).toFixed(2)
476
+ : "0.00";
477
+
478
+ const avgTypesOfIssuesPercentageOfTotalRulesAtGoodToFix =
479
+ totalRulesGoodToFix > 0
480
+ ? ((avgGoodToFixPerPage / totalRulesGoodToFix) * 100).toFixed(2)
481
+ : "0.00";
482
+
483
+ const avgTypesOfIssuesPercentageOfTotalRulesAtMustFixAndGoodToFix =
484
+ totalRulesMustFixAndGoodToFix > 0
485
+ ? ((avgMustFixAndGoodToFixPerPage / totalRulesMustFixAndGoodToFix) * 100).toFixed(2)
486
+ : "0.00";
487
+
488
+ const avgTypesOfIssuesCountAtMustFix = avgMustFixPerPage.toFixed(2);
489
+ const avgTypesOfIssuesCountAtGoodToFix = avgGoodToFixPerPage.toFixed(2);
490
+ const avgTypesOfIssuesCountAtMustFixAndGoodToFix = avgMustFixAndGoodToFixPerPage.toFixed(2);
491
+
492
+ return {
493
+ avgTypesOfIssuesCountAtMustFix,
494
+ avgTypesOfIssuesCountAtGoodToFix,
495
+ avgTypesOfIssuesCountAtMustFixAndGoodToFix,
496
+ avgTypesOfIssuesPercentageOfTotalRulesAtMustFix,
497
+ avgTypesOfIssuesPercentageOfTotalRulesAtGoodToFix,
498
+ avgTypesOfIssuesPercentageOfTotalRulesAtMustFixAndGoodToFix,
499
+ totalRulesMustFix,
500
+ totalRulesGoodToFix,
501
+ totalRulesMustFixAndGoodToFix,
502
+ pagesAffectedPerRule,
503
+ pagesPercentageAffectedPerRule,
504
+ };
505
+ };
506
+
231
507
  export const getFormattedTime = inputDate => {
232
508
  if (inputDate) {
233
509
  return inputDate.toLocaleTimeString('en-GB', {
@@ -0,0 +1,178 @@
1
+ export function xPathToCss(expr: string) {
2
+ const isValidXPath = expr =>
3
+ typeof expr !== 'undefined' &&
4
+ expr.replace(/[\s-_=]/g, '') !== '' &&
5
+ expr.length ===
6
+ expr.replace(
7
+ /[-_\w:.]+\(\)\s*=|=\s*[-_\w:.]+\(\)|\sor\s|\sand\s|\[(?:[^\/\]]+[\/\[]\/?.+)+\]|starts-with\(|\[.*last\(\)\s*[-\+<>=].+\]|number\(\)|not\(|count\(|text\(|first\(|normalize-space|[^\/]following-sibling|concat\(|descendant::|parent::|self::|child::|/gi,
8
+ '',
9
+ ).length;
10
+
11
+ const getValidationRegex = () => {
12
+ let regex =
13
+ '(?P<node>' +
14
+ '(' +
15
+ '^id\\(["\\\']?(?P<idvalue>%(value)s)["\\\']?\\)' + // special case! `id(idValue)`
16
+ '|' +
17
+ '(?P<nav>//?(?:following-sibling::)?)(?P<tag>%(tag)s)' + // `//div`
18
+ '(\\[(' +
19
+ '(?P<matched>(?P<mattr>@?%(attribute)s=["\\\'](?P<mvalue>%(value)s))["\\\']' + // `[@id="well"]` supported and `[text()="yes"]` is not
20
+ '|' +
21
+ '(?P<contained>contains\\((?P<cattr>@?%(attribute)s,\\s*["\\\'](?P<cvalue>%(value)s)["\\\']\\))' + // `[contains(@id, "bleh")]` supported and `[contains(text(), "some")]` is not
22
+ ')\\])?' +
23
+ '(\\[\\s*(?P<nth>\\d+|last\\(\\s*\\))\\s*\\])?' +
24
+ ')' +
25
+ ')';
26
+
27
+ const subRegexes = {
28
+ tag: '([a-zA-Z][a-zA-Z0-9:-]*|\\*)',
29
+ attribute: '[.a-zA-Z_:][-\\w:.]*(\\(\\))?)',
30
+ value: '\\s*[\\w/:][-/\\w\\s,:;.]*',
31
+ };
32
+
33
+ Object.keys(subRegexes).forEach(key => {
34
+ regex = regex.replace(new RegExp(`%\\(${key}\\)s`, 'gi'), subRegexes[key]);
35
+ });
36
+
37
+ regex = regex.replace(
38
+ /\?P<node>|\?P<idvalue>|\?P<nav>|\?P<tag>|\?P<matched>|\?P<mattr>|\?P<mvalue>|\?P<contained>|\?P<cattr>|\?P<cvalue>|\?P<nth>/gi,
39
+ '',
40
+ );
41
+
42
+ return new RegExp(regex, 'gi');
43
+ };
44
+
45
+ const preParseXpath = expr =>
46
+ expr.replace(
47
+ /contains\s*\(\s*concat\(["']\s+["']\s*,\s*@class\s*,\s*["']\s+["']\)\s*,\s*["']\s+([a-zA-Z0-9-_]+)\s+["']\)/gi,
48
+ '@class="$1"',
49
+ );
50
+
51
+ function escapeCssIdSelectors(cssSelector) {
52
+ return cssSelector.replace(/#([^ >]+)/g, (match, id) => {
53
+ // Escape special characters in the id part
54
+ return `#${id.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, '\\$&')}`;
55
+ });
56
+ }
57
+ if (!expr) {
58
+ throw new Error('Missing XPath expression');
59
+ }
60
+
61
+ expr = preParseXpath(expr);
62
+
63
+ if (!isValidXPath(expr)) {
64
+ console.error(`Invalid or unsupported XPath: ${expr}`);
65
+ // do not throw error so that this function proceeds to convert xpath that it does not support
66
+ // for example, //*[@id="google_ads_iframe_/4654/dweb/imu1/homepage/landingpage/na_0"]/html/body/div[1]/a
67
+ // becomes #google_ads_iframe_/4654/dweb/imu1/homepage/landingpage/na_0 > html > body > div:first-of-type > div > a
68
+ // which is invalid because the slashes in the id selector are not escaped
69
+ // throw new Error('Invalid or unsupported XPath: ' + expr);
70
+ }
71
+
72
+ const xPathArr = expr.split('|');
73
+ const prog = getValidationRegex();
74
+ const cssSelectors = [];
75
+ let xindex = 0;
76
+
77
+ while (xPathArr[xindex]) {
78
+ const css = [];
79
+ let position = 0;
80
+ let nodes;
81
+
82
+ while ((nodes = prog.exec(xPathArr[xindex]))) {
83
+ let attr;
84
+
85
+ if (!nodes && position === 0) {
86
+ throw new Error(`Invalid or unsupported XPath: ${expr}`);
87
+ }
88
+
89
+ const match = {
90
+ node: nodes[5],
91
+ idvalue: nodes[12] || nodes[3],
92
+ nav: nodes[4],
93
+ tag: nodes[5],
94
+ matched: nodes[7],
95
+ mattr: nodes[10] || nodes[14],
96
+ mvalue: nodes[12] || nodes[16],
97
+ contained: nodes[13],
98
+ cattr: nodes[14],
99
+ cvalue: nodes[16],
100
+ nth: nodes[18],
101
+ };
102
+
103
+ let nav = '';
104
+
105
+ if (position != 0 && match.nav) {
106
+ if (~match.nav.indexOf('following-sibling::')) {
107
+ nav = ' + ';
108
+ } else {
109
+ nav = match.nav == '//' ? ' ' : ' > ';
110
+ }
111
+ }
112
+
113
+ const tag = match.tag === '*' ? '' : match.tag || '';
114
+
115
+ if (match.contained) {
116
+ if (match.cattr.indexOf('@') === 0) {
117
+ attr = `[${match.cattr.replace(/^@/, '')}*="${match.cvalue}"]`;
118
+ } else {
119
+ throw new Error(`Invalid or unsupported XPath attribute: ${match.cattr}`);
120
+ }
121
+ } else if (match.matched) {
122
+ switch (match.mattr) {
123
+ case '@id':
124
+ attr = `#${match.mvalue.replace(/^\s+|\s+$/, '').replace(/\s/g, '#')}`;
125
+ break;
126
+ case '@class':
127
+ attr = `.${match.mvalue.replace(/^\s+|\s+$/, '').replace(/\s/g, '.')}`;
128
+ break;
129
+ case 'text()':
130
+ case '.':
131
+ throw new Error(`Invalid or unsupported XPath attribute: ${match.mattr}`);
132
+ default:
133
+ if (match.mattr.indexOf('@') !== 0) {
134
+ throw new Error(`Invalid or unsupported XPath attribute: ${match.mattr}`);
135
+ }
136
+ if (match.mvalue.indexOf(' ') !== -1) {
137
+ match.mvalue = `\"${match.mvalue.replace(/^\s+|\s+$/, '')}\"`;
138
+ }
139
+ attr = `[${match.mattr.replace('@', '')}="${match.mvalue}"]`;
140
+ break;
141
+ }
142
+ } else if (match.idvalue) {
143
+ attr = `#${match.idvalue.replace(/\s/, '#')}`;
144
+ } else {
145
+ attr = '';
146
+ }
147
+
148
+ let nth = '';
149
+
150
+ if (match.nth) {
151
+ if (match.nth.indexOf('last') === -1) {
152
+ if (isNaN(parseInt(match.nth, 10))) {
153
+ throw new Error(`Invalid or unsupported XPath attribute: ${match.nth}`);
154
+ }
155
+ nth = parseInt(match.nth, 10) !== 1 ? `:nth-of-type(${match.nth})` : ':first-of-type';
156
+ } else {
157
+ nth = ':last-of-type';
158
+ }
159
+ }
160
+
161
+ css.push(nav + tag + attr + nth);
162
+ position++;
163
+ }
164
+
165
+ const result = css.join('');
166
+
167
+ if (result === '') {
168
+ throw new Error('Invalid or unsupported XPath');
169
+ }
170
+
171
+ cssSelectors.push(result);
172
+ xindex++;
173
+ }
174
+
175
+ // return cssSelectors.join(', ');
176
+ const originalResult = cssSelectors.join(', ');
177
+ return escapeCssIdSelectors(originalResult);
178
+ }
@@ -1,82 +0,0 @@
1
- import { Spec } from 'axe-core';
2
-
3
- // Custom Axe Functions for axe.config
4
- export const customAxeConfig: Spec = {
5
- branding: {
6
- application: 'oobee',
7
- },
8
- checks: [
9
- {
10
- id: 'oobee-confusing-alt-text',
11
- metadata: {
12
- impact: 'serious',
13
- messages: {
14
- pass: 'The image alt text is probably useful.',
15
- fail: "The image alt text set as 'img', 'image', 'picture', 'photo', or 'graphic' is confusing or not useful.",
16
- },
17
- },
18
- },
19
- {
20
- id: 'oobee-accessible-label',
21
- metadata: {
22
- impact: 'serious',
23
- messages: {
24
- pass: 'The clickable element has an accessible label.',
25
- fail: 'The clickable element does not have an accessible label.',
26
- },
27
- },
28
- },
29
- {
30
- id: 'oobee-grading-text-contents',
31
- metadata: {
32
- impact: 'moderate',
33
- messages: {
34
- pass: 'The text content is easy to understand.',
35
- fail: 'The text content is potentially difficult to undersatnd.',
36
- },
37
- },
38
- },
39
- ],
40
- rules: [
41
- { id: 'target-size', enabled: true },
42
- {
43
- id: 'oobee-confusing-alt-text',
44
- selector: 'img[alt]',
45
- enabled: true,
46
- any: ['oobee-confusing-alt-text'],
47
- tags: ['wcag2a', 'wcag111'],
48
- metadata: {
49
- description: 'Ensures image alt text is clear and useful.',
50
- help: 'Image alt text must not be vague or unhelpful.',
51
- helpUrl: 'https://www.deque.com/blog/great-alt-text-introduction/',
52
- },
53
- },
54
- {
55
- id: 'oobee-accessible-label',
56
- // selector: '*', // to be set with the checker function output xpaths converted to css selectors
57
- enabled: true,
58
- any: ['oobee-accessible-label'],
59
- tags: ['wcag2a', 'wcag211', 'wcag412'],
60
- metadata: {
61
- description: 'Ensures clickable elements have an accessible label.',
62
- help: 'Clickable elements must have accessible labels.',
63
- helpUrl: 'https://www.deque.com/blog/accessible-aria-buttons',
64
- },
65
- },
66
- {
67
- id: 'oobee-grading-text-contents',
68
- selector: 'html',
69
- enabled: true,
70
- any: ['oobee-grading-text-contents'],
71
- tags: ['wcag2aaa', 'wcag315'],
72
- metadata: {
73
- description:
74
- 'Text content should be easy to understand for individuals with education levels up to university graduates. If the text content is difficult to understand, provide supplemental content or a version that is easy to understand.',
75
- help: 'Text content should be clear and plain to ensure that it is easily understood.',
76
- helpUrl: 'https://www.wcag.com/uncategorized/3-1-5-reading-level/',
77
- },
78
- },
79
- ],
80
- };
81
-
82
- export default customAxeConfig;