File size: 1,074 Bytes
11fcc5a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import { get } from "svelte/store";
import { device } from "$lib/device";
import settings from "$lib/state/settings";
const canUseHaptics = () => {
return device.supports.haptics && !get(settings).accessibility.disableHaptics;
}
export const hapticSwitch = () => {
if (!canUseHaptics()) return;
try {
const label = document.createElement("label");
label.ariaHidden = "true";
label.style.display = "none";
const input = document.createElement("input");
input.type = "checkbox";
input.setAttribute("switch", "");
label.appendChild(input);
document.head.appendChild(label);
label.click();
document.head.removeChild(label);
} catch {
// ignore
}
}
export const hapticConfirm = () => {
if (!canUseHaptics()) return;
hapticSwitch();
setTimeout(() => hapticSwitch(), 120);
}
export const hapticError = () => {
if (!canUseHaptics()) return;
hapticSwitch();
setTimeout(() => hapticSwitch(), 120);
setTimeout(() => hapticSwitch(), 240);
}
|