UNPKG

pangu

Version:

Opinionated paranoid text spacing: automatically inserts whitespace between CJK (Chinese, Japanese, Korean) and ANS (alphabetical letters, numerical digits and symbols)

44 lines (43 loc) • 1.4 kB
//#region src/browser/scheduling/timing.ts function once(func) { let executed = false; return function(...args) { if (executed) return; executed = true; return func(...args); }; } function debounce(func, delay, mustRunDelay = Infinity) { let timer = null; let startTime = null; return function(...args) { const currentTime = Date.now(); if (timer) clearTimeout(timer); if (!startTime) startTime = currentTime; if (currentTime - startTime >= mustRunDelay) { func(...args); startTime = currentTime; } else timer = window.setTimeout(() => { func(...args); }, delay); }; } function waitForVideosToLoad(delayMs, onLoaded) { const videos = Array.from(document.getElementsByTagName("video")).filter((video) => video.getClientRects().length > 0); if (videos.length === 0) setTimeout(onLoaded, delayMs); else if (videos.every((video) => video.readyState >= 3)) setTimeout(onLoaded, delayMs); else { let loadedCount = 0; const videoCount = videos.length; const checkAllLoaded = () => { loadedCount++; if (loadedCount >= videoCount) setTimeout(onLoaded, delayMs); }; for (const video of videos) if (video.readyState >= 3) checkAllLoaded(); else video.addEventListener("loadeddata", checkAllLoaded, { once: true }); setTimeout(onLoaded, delayMs + 5e3); } } //#endregion export { debounce, once, waitForVideosToLoad }; //# sourceMappingURL=timing.js.map