UNPKG

9.49 kBTypeScriptView Raw
1declare var Hammer: HammerStatic;
2
3declare module "hammerjs" {
4 export = Hammer;
5}
6
7interface HammerStatic {
8 new(element: HTMLElement | SVGElement, options?: HammerOptions): HammerManager;
9
10 defaults: HammerDefaults;
11
12 VERSION: number;
13
14 INPUT_START: 1;
15 INPUT_MOVE: 2;
16 INPUT_END: 4;
17 INPUT_CANCEL: 8;
18
19 STATE_POSSIBLE: 1;
20 STATE_BEGAN: 2;
21 STATE_CHANGED: 4;
22 STATE_ENDED: 8;
23 STATE_RECOGNIZED: 8; // same as STATE_ENDED
24 STATE_CANCELLED: 16;
25 STATE_FAILED: 32;
26
27 DIRECTION_NONE: 1;
28 DIRECTION_LEFT: 2;
29 DIRECTION_RIGHT: 4;
30 DIRECTION_UP: 8;
31 DIRECTION_DOWN: 16;
32 DIRECTION_HORIZONTAL: 6; // DIRECTION_LEFT | DIRECTION_RIGHT
33 DIRECTION_VERTICAL: 24; // DIRECTION_UP | DIRECTION_DOWN
34 DIRECTION_ALL: 30; // DIRECTION_HORIZONTAL | DIRECTION_VERTICAL
35
36 Manager: HammerManagerConstructor;
37 Input: HammerInput;
38 TouchAction: TouchAction;
39
40 TouchInput: TouchInput;
41 MouseInput: MouseInput;
42 PointerEventInput: PointerEventInput;
43 TouchMouseInput: TouchMouseInput;
44 SingleTouchInput: SingleTouchInput;
45
46 Recognizer: RecognizerStatic;
47 AttrRecognizer: AttrRecognizerStatic;
48 Tap: TapRecognizerStatic;
49 Pan: PanRecognizerStatic;
50 Swipe: SwipeRecognizerStatic;
51 Pinch: PinchRecognizerStatic;
52 Rotate: RotateRecognizerStatic;
53 Press: PressRecognizerStatic;
54
55 on(target: EventTarget, types: string, handler: Function): void;
56 off(target: EventTarget, types: string, handler: Function): void;
57 each(obj: any, iterator: Function, context: any): void;
58 merge(dest: any, src: any): any;
59 extend(dest: any, src: any, merge: boolean): any;
60 inherit(child: Function, base: Function, properties: any): any;
61 bindFn(fn: Function, context: any): Function;
62 prefixed(obj: any, property: string): string;
63}
64
65type RecognizerTuple =
66 | [RecognizerStatic]
67 | [RecognizerStatic, RecognizerOptions]
68 | [RecognizerStatic, RecognizerOptions, string | string[]]
69 | [RecognizerStatic, RecognizerOptions, string | string[], (string | Recognizer) | Array<string | Recognizer>];
70
71interface HammerDefaults extends HammerOptions {
72 domEvents: boolean;
73 enable: boolean;
74 preset: RecognizerTuple[];
75 touchAction: string;
76 cssProps: CssProps;
77
78 inputClass: HammerInput;
79 inputTarget: EventTarget;
80}
81
82interface CssProps {
83 contentZooming: string;
84 tapHighlightColor: string;
85 touchCallout: string;
86 touchSelect: string;
87 userDrag: string;
88 userSelect: string;
89}
90
91interface HammerOptions {
92 cssProps?: CssProps | undefined;
93 domEvents?: boolean | undefined;
94 enable?: boolean | ((manager: HammerManager) => boolean) | undefined;
95 preset?: RecognizerTuple[] | undefined;
96 touchAction?: string | undefined;
97 recognizers?: RecognizerTuple[] | undefined;
98
99 inputClass?: HammerInput | undefined;
100 inputTarget?: EventTarget | undefined;
101}
102
103interface HammerManagerConstructor {
104 new(element: EventTarget, options?: HammerOptions): HammerManager;
105}
106
107interface HammerListener {
108 (event: HammerInput): void;
109}
110
111interface HammerManager {
112 add(recogniser: Recognizer): Recognizer;
113 add(recogniser: Recognizer): HammerManager;
114 add(recogniser: Recognizer[]): Recognizer;
115 add(recogniser: Recognizer[]): HammerManager;
116 destroy(): void;
117 emit(event: string, data: any): void;
118 get(recogniser: Recognizer): Recognizer;
119 get(recogniser: string): Recognizer;
120 off(events: string, handler?: HammerListener): void;
121 on(events: string, handler: HammerListener): void;
122 recognize(inputData: any): void;
123 remove(recogniser: Recognizer): HammerManager;
124 remove(recogniser: string): HammerManager;
125 set(options: HammerOptions): HammerManager;
126 stop(force: boolean): void;
127}
128
129declare class HammerInput {
130 constructor(manager: HammerManager, callback: Function);
131
132 destroy(): void;
133 handler(): void;
134 init(): void;
135
136 /** Name of the event. Like panstart. */
137 type: string;
138
139 /** Movement of the X axis. */
140 deltaX: number;
141
142 /** Movement of the Y axis. */
143 deltaY: number;
144
145 /** Total time in ms since the first input. */
146 deltaTime: number;
147
148 /** Distance moved. */
149 distance: number;
150
151 /** Angle moved. */
152 angle: number;
153
154 /** Velocity on the X axis, in px/ms. */
155 velocityX: number;
156
157 /** Velocity on the Y axis, in px/ms */
158 velocityY: number;
159
160 /** Highest velocityX/Y value. */
161 velocity: number;
162
163 overallVelocity: number;
164
165 overallVelocityX: number;
166
167 overallVelocityY: number;
168
169 /** Direction moved. Matches the DIRECTION constants. */
170 direction: number;
171
172 /** Direction moved from it's starting point. Matches the DIRECTION constants. */
173 offsetDirection: number;
174
175 /** Scaling that has been done when multi-touch. 1 on a single touch. */
176 scale: number;
177
178 /** Rotation that has been done when multi-touch. 0 on a single touch. */
179 rotation: number;
180
181 /** Center position for multi-touch, or just the single pointer. */
182 center: HammerPoint;
183
184 /** The amount of multi-taps being recognized. */
185 tapCount?: number;
186
187 /** Source event object, type TouchEvent, MouseEvent or PointerEvent. */
188 srcEvent: TouchEvent | MouseEvent | PointerEvent;
189
190 /** Target that received the event. */
191 target: HTMLElement;
192
193 /** Primary pointer type, could be touch, mouse, pen or kinect. */
194 pointerType: string;
195
196 /** Event type, matches the INPUT constants. */
197 eventType:
198 | HammerStatic["INPUT_START"]
199 | HammerStatic["INPUT_MOVE"]
200 | HammerStatic["INPUT_END"]
201 | HammerStatic["INPUT_CANCEL"];
202
203 /** true when the first input. */
204 isFirst: boolean;
205
206 /** true when the final (last) input. */
207 isFinal: boolean;
208
209 /** Array with all pointers, including the ended pointers (touchend, mouseup). */
210 pointers: any[];
211
212 /** Array with all new/moved/lost pointers. */
213 changedPointers: any[];
214
215 /** Maximum number of pointers detected in the gesture */
216 maxPointers: number;
217
218 /** Timestamp of a gesture */
219 timeStamp: number;
220
221 /** Reference to the srcEvent.preventDefault() method. Only for experts! */
222 preventDefault: Function;
223}
224
225declare class MouseInput extends HammerInput {
226 constructor(manager: HammerManager, callback: Function);
227}
228
229declare class PointerEventInput extends HammerInput {
230 constructor(manager: HammerManager, callback: Function);
231}
232
233declare class SingleTouchInput extends HammerInput {
234 constructor(manager: HammerManager, callback: Function);
235}
236
237declare class TouchInput extends HammerInput {
238 constructor(manager: HammerManager, callback: Function);
239}
240
241declare class TouchMouseInput extends HammerInput {
242 constructor(manager: HammerManager, callback: Function);
243}
244
245interface RecognizerOptions {
246 direction?: number | undefined;
247 enable?: boolean | ((recognizer: Recognizer, inputData: HammerInput) => boolean) | undefined;
248 event?: string | undefined;
249 interval?: number | undefined;
250 pointers?: number | undefined;
251 posThreshold?: number | undefined;
252 taps?: number | undefined;
253 threshold?: number | undefined;
254 time?: number | undefined;
255 velocity?: number | undefined;
256}
257
258interface RecognizerStatic {
259 new(options?: RecognizerOptions): Recognizer;
260}
261
262interface Recognizer {
263 defaults: any;
264
265 canEmit(): boolean;
266 canRecognizeWith(otherRecognizer: Recognizer): boolean;
267 dropRecognizeWith(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
268 dropRequireFailure(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
269 emit(input: HammerInput): void;
270 getTouchAction(): any[];
271 hasRequireFailures(): boolean;
272 process(inputData: HammerInput): string;
273 recognize(inputData: HammerInput): void;
274 recognizeWith(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
275 requireFailure(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
276 reset(): void;
277 set(options?: RecognizerOptions): Recognizer;
278 tryEmit(input: HammerInput): void;
279}
280
281interface AttrRecognizerStatic {
282 attrTest(input: HammerInput): boolean;
283 process(input: HammerInput): any;
284}
285
286interface AttrRecognizer extends Recognizer {
287 new(options?: RecognizerOptions): AttrRecognizer;
288}
289
290interface PanRecognizerStatic {
291 new(options?: RecognizerOptions): PanRecognizer;
292}
293
294interface PanRecognizer extends AttrRecognizer {
295}
296
297interface PinchRecognizerStatic {
298 new(options?: RecognizerOptions): PinchRecognizer;
299}
300
301interface PinchRecognizer extends AttrRecognizer {
302}
303
304interface PressRecognizerStatic {
305 new(options?: RecognizerOptions): PressRecognizer;
306}
307
308interface PressRecognizer extends AttrRecognizer {
309}
310
311interface RotateRecognizerStatic {
312 new(options?: RecognizerOptions): RotateRecognizer;
313}
314
315interface RotateRecognizer extends AttrRecognizer {
316}
317
318interface SwipeRecognizerStatic {
319 new(options?: RecognizerOptions): SwipeRecognizer;
320}
321
322interface SwipeRecognizer extends AttrRecognizer {
323}
324
325interface TapRecognizerStatic {
326 new(options?: RecognizerOptions): TapRecognizer;
327}
328
329interface TapRecognizer extends AttrRecognizer {
330}
331
332declare class TouchAction {
333 constructor(manager: HammerManager, value: string);
334
335 compute(): string;
336 preventDefaults(input: HammerInput): void;
337 preventSrc(srcEvent: any): void;
338 set(value: string): void;
339 update(): void;
340}
341
342interface HammerPoint {
343 x: number;
344 y: number;
345}
346
\No newline at end of file