mirror of
https://github.com/oxynote/oxynote.git
synced 2026-10-17 10:59:20 +02:00
27 lines
486 B
TypeScript
27 lines
486 B
TypeScript
export function waitForHtmlElementById(id: string, timeoutMs: number) {
|
|
if (typeof document === "undefined") {
|
|
return Promise.resolve(null)
|
|
}
|
|
|
|
return new Promise<HTMLElement | null>((resolve) => {
|
|
const start = performance.now()
|
|
|
|
const check = () => {
|
|
const el = document.getElementById(id)
|
|
if (el) {
|
|
resolve(el)
|
|
return
|
|
}
|
|
|
|
if (performance.now() - start >= timeoutMs) {
|
|
resolve(null)
|
|
return
|
|
}
|
|
|
|
requestAnimationFrame(check)
|
|
}
|
|
|
|
check()
|
|
})
|
|
}
|