feat: calculate els position among siblings (assume parent el)

This commit is contained in:
karishmas6
2024-06-05 23:25:31 +05:30
parent e752166343
commit ae4d58ab0b

View File

@@ -361,6 +361,33 @@ export const getSelectors = async (page: Page, coordinates: Coordinates) => {
};
}
function index(input: Element): number | null {
const parent = input.parentNode;
if (!parent) {
return null;
}
let child = parent.firstChild;
if (!child) {
return null;
}
let i = 0;
while (child) {
if (child.nodeType === Node.ELEMENT_NODE) {
i++;
}
if (child === input) {
break;
}
child = child.nextSibling;
}
return i;
}
};