UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

66 lines (65 loc) • 3.23 kB
import { Point } from '../geometry/Point.js'; export type DomEventOf<K extends string> = K extends `${infer A} ${infer B}` ? DomEventOf<A> | DomEventOf<B> : K extends keyof HTMLElementEventMap ? HTMLElementEventMap[K] : Event; export type DomEventListener<K extends string> = (e: DomEventOf<K>) => void; export type DomEventListenerMap = { [K in keyof HTMLElementEventMap]?: (e: HTMLElementEventMap[K]) => void; } & { [type: string]: (e: any) => void; }; export declare function on<K extends string>(el: EventTarget, types: K, fn: DomEventListener<K>, context?: unknown): void; export declare function on(el: EventTarget, eventMap: DomEventListenerMap, context?: unknown): void; export declare function off<K extends string>(el: EventTarget, types: K, fn: DomEventListener<K>, context?: unknown): void; export declare function off(el: EventTarget, eventMap: DomEventListenerMap, context?: unknown): void; export declare function off(el: EventTarget, types: string): void; export declare function off(el: EventTarget): void; /** * Stop the given event from propagation to parent elements. Used inside the listener functions: * ```js * DomEvent.on(div, 'click', DomEvent.stopPropagation); * ``` * Given a Leaflet event, it stops the map from handling the original DOM event. * @param {Event | {originalEvent: Event}} e */ export declare function stopPropagation(e: Event | { originalEvent: Event; }): void; /** * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants). * @param {HTMLElement} el */ export declare function disableScrollPropagation(el: HTMLElement): void; /** * Adds `stopPropagation` to the element's `'dblclick'`, `'contextmenu'` and `'pointerdown'` * events (plus browser variants). For `'click'` events, prevents the map from handling the * click while still allowing the native DOM click event to propagate normally. * @param {HTMLElement} el */ export declare function disableClickPropagation(el: HTMLElement): void; /** * Prevents the default action of the DOM Event `e` from happening (such as following * a link in the href of the a element, or doing a POST request with page reload * when a `<form>` is submitted). Use it inside listener functions. * @param {Event} e */ export declare function preventDefault(e: Event): void; /** * Does `stopPropagation` and `preventDefault` at the same time. Given a Leaflet event, it only stops propagation: * the default action of the original DOM event still happens. * @param {Event | {originalEvent: Event}} e */ export declare function stop(e: Event | { originalEvent: Event; }): void; /** * Gets normalized pointer position from a DOM event relative to the `container` * (border excluded) or to the whole page if not specified. * @param {MouseEvent} e * @param {HTMLElement} [container] */ export declare function getPointerPosition(e: MouseEvent, container?: HTMLElement): Point; /** * Gets normalized wheel delta from a wheel DOM event, in vertical pixels scrolled (negative if scrolling down). * Events from pointing devices without precise scrolling are mapped to a best guess of 60 pixels. * @param {WheelEvent} e */ export declare function getWheelDelta(e: WheelEvent): number;