mirror of https://github.com/lukechilds/docs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
829 B
43 lines
829 B
const canUseDOM = !!(
|
|
typeof window !== 'undefined' &&
|
|
window.document &&
|
|
window.document.createElement
|
|
);
|
|
|
|
let isEnabled = false;
|
|
|
|
const HOVER_THRESHOLD_MS = 1000;
|
|
let lastTouchTimestamp = 0;
|
|
|
|
function enableHover() {
|
|
if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
|
|
return;
|
|
}
|
|
isEnabled = true;
|
|
}
|
|
|
|
function disableHover() {
|
|
lastTouchTimestamp = Date.now();
|
|
if (isEnabled) {
|
|
isEnabled = false;
|
|
}
|
|
}
|
|
|
|
if (canUseDOM) {
|
|
document.addEventListener('touchstart', disableHover, {
|
|
capture: true,
|
|
passive: true,
|
|
});
|
|
document.addEventListener('touchmove', disableHover, {
|
|
capture: true,
|
|
passive: true,
|
|
});
|
|
document.addEventListener('mousemove', enableHover, {
|
|
capture: true,
|
|
passive: true,
|
|
});
|
|
}
|
|
|
|
export function isHoverEnabled() {
|
|
return isEnabled;
|
|
}
|
|
|