@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
34 lines (33 loc) • 1.04 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { waitForThemed } from "./element-themed";
const MAX_CLICK_ATTEMPTS = 3;
export async function delegateClick(host, callback) {
try {
if (!host.hasAttribute('data-themed')) {
await waitForThemed(host);
}
await callback();
}
catch (_a) {
throw new Error(`The interactive element inside the KoliBri web component could not be clicked. Try calling the click method on the web component after a short delay again.`);
}
}
function isElementVisible(element) {
if (!element)
return false;
const rect = element.getBoundingClientRect();
return rect.width > 0 && rect.height > 0;
}
export async function setClick(element) {
let attempts = 0;
do {
if (element) {
element.click();
}
await new Promise((r) => requestAnimationFrame(r));
attempts++;
} while (!isElementVisible(element) && attempts < MAX_CLICK_ATTEMPTS);
}
//# sourceMappingURL=element-click.js.map