import { useEffect } from 'react'; import { isNavigator, noop } from './misc/util'; var isVibrationApiSupported = isNavigator && 'vibrate' in navigator; function useVibrate(enabled, pattern, loop) { if (enabled === void 0) { enabled = true; } if (pattern === void 0) { pattern = [1000, 1000]; } if (loop === void 0) { loop = true; } useEffect(function () { var interval; if (enabled) { navigator.vibrate(pattern); if (loop) { var duration = pattern instanceof Array ? pattern.reduce(function (a, b) { return a + b; }) : pattern; interval = setInterval(function () { navigator.vibrate(pattern); }, duration); } } return function () { if (enabled) { navigator.vibrate(0); if (loop) { clearInterval(interval); } } }; }, [enabled]); } export default isVibrationApiSupported ? useVibrate : noop;