one-click-accessibility/modules/scanner/assets/js/rules/index.js
VasylD ad2174ffe3
[APP-1792] Add headings structure (#406)
* New: Add the heading structure components [APP-1792] (#391)

* New: Add the new rules [APP-1792]

* New: Add the BE integration [APP-1792]

* Fix: Fix QA issues [APP-1792]

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* merge latest dev

* add reset to initial

---------

Co-authored-by: Pavlo Kniazevych <139438463+pkniazevych@users.noreply.github.com>
Co-authored-by: Kniazevych <pavlok@elementor.red>
2025-09-24 09:47:57 +02:00

45 lines
1 KiB
JavaScript

import headingHierarchyCheck from './heading-hierarchy-check';
import missingH1Check from './missing-h1-check';
import singleH1Check from './single-h1-check';
export const EA11Y_RULES = Object.freeze({
MISSING_H1_TAG: 'missing_h1_check',
REDUNDANT_H1_TAGS: 'single_h1_check',
INCORRECT_HEADING_HIERARCHY: 'heading_hierarchy_check',
});
export const ea11yRuleSet = Object.freeze([
singleH1Check,
missingH1Check,
headingHierarchyCheck,
]);
/**
* Run all registered custom rules against the document.
*
* @param {Document} document - The document to scan
* @return {Array} Array of rule results (violations, recommendations, passes)
*/
export const runAllEa11yRules = (document) => {
const results = [];
const context = {
dom: {
node: document,
},
};
Object.values(ea11yRuleSet).forEach((rule) => {
try {
const result = rule.run(context);
if (result) {
results.push(result);
}
} catch (error) {
console.error(`Error running custom rule ${rule.id}:`, error);
}
});
return results;
};