/** * The type of the details of a shake event. */ export type ShakeEventData = DeviceMotionEvent; /** * The type of the `"shake"` event. */ export type ShakeEvent = CustomEvent & { type: "shake"; }; /** * The type of a handler for the `"shake"` event. */ export type ShakeEventListener = (event: ShakeEvent) => void; /** * The options for constructing a {@linkcode Shake} handler. */ export interface ShakeOptions { /** * Minimum acceleration needed to dispatch an event: * meters per second squared (m/s²). * * https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/acceleration */ threshold: number; /** * After a shake event is dispatched, subsequent events will not be dispatched * until after a duration greater than or equal to this value (milliseconds). */ timeout: number; } /** * A device motion handler that dispatches a `"shake"` event as appropriate. * * Original author: Jesse Jackson - https://github.com/jsejcksn * This part of the code is licensed under CC BY-SA 4.0 */ export declare class Shake extends EventTarget { #private; /** * Construct a new device shake handler. * @param options - The options for the handler. */ constructor(options?: Partial); /** * Add a new shake event listener. * @param type - The type of the event to handle. * @param listener - The event handler to call. * @param options - The options for this handler. */ addEventListener(type: "shake", listener: ShakeEventListener | null, options?: boolean | AddEventListenerOptions): void; /** * Dispatch a shake event. * @param event - The event to dispatch. * @returns true if the event was cancelled, false otherwise. */ dispatchEvent(event: ShakeEvent): boolean; /** * Removes a previously added event listener. * @param type - The type of the event to remove. * @param callback - The event handler to remove. * @param options - The options the event handler was added with. */ removeEventListener(type: "shake", callback: ShakeEventListener | null, options?: EventListenerOptions | boolean): void; /** * Requests approval to handle device motion events. * @returns true if we got approval, false otherwise. */ approve(): Promise; /** * Start handling device shake. * @returns true if we were able to register our handler, false otherwise. */ start(): Promise; /** * Stop handling device shake. */ stop(): void; }