UNPKG

@sv-use/core

Version:

A collection of Svelte 5 utilities.

30 lines (29 loc) 911 B
import { normalizeValue } from '../__internal__/utils.svelte.js'; import { defaultNavigator } from '../__internal__/configurable.js'; /** * Reactive vibrate. * @param options Additional options to customize the behavior. * @see https://svelte-librarian.github.io/sv-use/docs/core/create-vibration */ export function createVibration(options = {}) { const { pattern = [], navigator = defaultNavigator } = options; const isSupported = $derived(typeof navigator !== 'undefined' && 'vibrate' in navigator); const _pattern = $derived(normalizeValue(pattern)); function vibrate() { if (!isSupported) return; navigator.vibrate(_pattern); } function stop() { if (!isSupported) return; navigator.vibrate(0); } return { get isSupported() { return isSupported; }, vibrate, stop }; }