mirror of
https://github.com/glanceapp/glance.git
synced 2025-07-13 13:06:14 +02:00
34 lines
882 B
JavaScript
34 lines
882 B
JavaScript
export function throttledDebounce(callback, maxDebounceTimes, debounceDelay) {
|
|
let debounceTimeout;
|
|
let timesDebounced = 0;
|
|
|
|
return function () {
|
|
if (timesDebounced == maxDebounceTimes) {
|
|
clearTimeout(debounceTimeout);
|
|
timesDebounced = 0;
|
|
callback();
|
|
return;
|
|
}
|
|
|
|
clearTimeout(debounceTimeout);
|
|
timesDebounced++;
|
|
|
|
debounceTimeout = setTimeout(() => {
|
|
timesDebounced = 0;
|
|
callback();
|
|
}, debounceDelay);
|
|
};
|
|
};
|
|
|
|
export function isElementVisible(element) {
|
|
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
|
|
}
|
|
|
|
export function clamp(value, min, max) {
|
|
return Math.min(Math.max(value, min), max);
|
|
}
|
|
|
|
export function openURLInNewTab(url) {
|
|
window.open(url, '_blank', 'noopener,noreferrer')?.focus();
|
|
}
|