mirror of
https://ghproxy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-07-21 12:16:59 +08:00
* 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>
45 lines
1 KiB
JavaScript
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;
|
|
};
|