mirror of
https://ghproxy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-07-21 12:16:59 +08:00
* [APP-1923] change remediation management (#411) * [APP-1988] Add tabs * [APP-1988][APP-1989] add tabs, remove menu item * [APP-1988][APP-1989] add tabs, remove menu item * [APP-1992] add empty state and tab navigation * [APP-1993][APP-1994] Change view for manage AI fixes, change delete confirmation modal * [APP-1996] add view for alt text fixes * [APP-1996] add edit for alt text fixes * [APP-1996] add edit for alt text fixes * [APP-1996] add edit for alt text fixes * [APP-1996] add edit for alt text fixes * [APP-1996] add edit for alt text fixes * [APP-1995] Color contrast form * [APP-2001] add global remediation logic (#415) * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2001] add global remediation logic * [APP-2003] add disable across scans (#418) * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * [APP-2003] add disable across scans * add logs * add logs * add logs * remove logs * remove logs * remove logs * remove logs * remove logs * remove logs * remove logs * remove logs * remove logs * remove logs * change to theme value * change to theme value * change to theme value * change to theme value * add edit mode * add edit mode * add edit mode
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
import {
|
|
BACKGROUND_ELEMENT_CLASS,
|
|
COLOR_ELEMENT_CLASS,
|
|
CURRENT_ELEMENT_CLASS,
|
|
} from '@ea11y-apps/scanner/constants';
|
|
|
|
export const getElementCSSSelector = (element) => {
|
|
if (!element || !(element instanceof Element)) {
|
|
return null;
|
|
}
|
|
|
|
const ignoredClasses = new Set([
|
|
CURRENT_ELEMENT_CLASS,
|
|
COLOR_ELEMENT_CLASS,
|
|
BACKGROUND_ELEMENT_CLASS,
|
|
]);
|
|
|
|
const parts = [];
|
|
|
|
while (element && element.nodeType === Node.ELEMENT_NODE) {
|
|
let selector = element.tagName.toLowerCase();
|
|
|
|
if (element.id) {
|
|
selector += `#${element.id}`;
|
|
parts.unshift(selector);
|
|
break; // Stop at ID
|
|
}
|
|
|
|
// Add classes unless it's <body> or ignored
|
|
if (element.className && element.tagName.toLowerCase() !== 'body') {
|
|
const classList = element.className
|
|
.trim()
|
|
.split(/\s+/)
|
|
.filter((cls) => cls && !ignoredClasses.has(cls));
|
|
if (classList.length) {
|
|
selector += '.' + classList.join('.');
|
|
}
|
|
}
|
|
|
|
// Add :nth-of-type if needed
|
|
const parent = element.parentNode;
|
|
if (
|
|
parent &&
|
|
!(
|
|
parent.tagName?.toLowerCase() === 'body' &&
|
|
element.tagName?.toLowerCase() === 'div'
|
|
)
|
|
) {
|
|
const siblings = Array.from(parent.children).filter(
|
|
(sibling) => sibling.tagName === element.tagName,
|
|
);
|
|
if (siblings.length > 1) {
|
|
const index = siblings.indexOf(element) + 1;
|
|
selector += `:nth-of-type(${index})`;
|
|
}
|
|
}
|
|
|
|
parts.unshift(selector);
|
|
element = element.parentElement;
|
|
}
|
|
|
|
return parts.join(' > ');
|
|
};
|