UNPKG

9.41 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 /** Source event object, type TouchEvent, MouseEvent or PointerEvent. */
185 srcEvent: TouchEvent | MouseEvent | PointerEvent;
186
187 /** Target that received the event. */
188 target: HTMLElement;
189
190 /** Primary pointer type, could be touch, mouse, pen or kinect. */
191 pointerType: string;
192
193 /** Event type, matches the INPUT constants. */
194 eventType:
195 | HammerStatic["INPUT_START"]
196 | HammerStatic["INPUT_MOVE"]
197 | HammerStatic["INPUT_END"]
198 | HammerStatic["INPUT_CANCEL"];
199
200 /** true when the first input. */
201 isFirst: boolean;
202
203 /** true when the final (last) input. */
204 isFinal: boolean;
205
206 /** Array with all pointers, including the ended pointers (touchend, mouseup). */
207 pointers: any[];
208
209 /** Array with all new/moved/lost pointers. */
210 changedPointers: any[];
211
212 /** Maximum number of pointers detected in the gesture */
213 maxPointers: number;
214
215 /** Timestamp of a gesture */
216 timeStamp: number;
217
218 /** Reference to the srcEvent.preventDefault() method. Only for experts! */
219 preventDefault: Function;
220}
221
222declare class MouseInput extends HammerInput {
223 constructor(manager: HammerManager, callback: Function);
224}
225
226declare class PointerEventInput extends HammerInput {
227 constructor(manager: HammerManager, callback: Function);
228}
229
230declare class SingleTouchInput extends HammerInput {
231 constructor(manager: HammerManager, callback: Function);
232}
233
234declare class TouchInput extends HammerInput {
235 constructor(manager: HammerManager, callback: Function);
236}
237
238declare class TouchMouseInput extends HammerInput {
239 constructor(manager: HammerManager, callback: Function);
240}
241
242interface RecognizerOptions {
243 direction?: number | undefined;
244 enable?: boolean | ((recognizer: Recognizer, inputData: HammerInput) => boolean) | undefined;
245 event?: string | undefined;
246 interval?: number | undefined;
247 pointers?: number | undefined;
248 posThreshold?: number | undefined;
249 taps?: number | undefined;
250 threshold?: number | undefined;
251 time?: number | undefined;
252 velocity?: number | undefined;
253}
254
255interface RecognizerStatic {
256 new(options?: RecognizerOptions): Recognizer;
257}
258
259interface Recognizer {
260 defaults: any;
261
262 canEmit(): boolean;
263 canRecognizeWith(otherRecognizer: Recognizer): boolean;
264 dropRecognizeWith(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
265 dropRequireFailure(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
266 emit(input: HammerInput): void;
267 getTouchAction(): any[];
268 hasRequireFailures(): boolean;
269 process(inputData: HammerInput): string;
270 recognize(inputData: HammerInput): void;
271 recognizeWith(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
272 requireFailure(otherRecognizer: Recognizer | Recognizer[] | string): Recognizer;
273 reset(): void;
274 set(options?: RecognizerOptions): Recognizer;
275 tryEmit(input: HammerInput): void;
276}
277
278interface AttrRecognizerStatic {
279 attrTest(input: HammerInput): boolean;
280 process(input: HammerInput): any;
281}
282
283interface AttrRecognizer extends Recognizer {
284 new(options?: RecognizerOptions): AttrRecognizer;
285}
286
287interface PanRecognizerStatic {
288 new(options?: RecognizerOptions): PanRecognizer;
289}
290
291interface PanRecognizer extends AttrRecognizer {
292}
293
294interface PinchRecognizerStatic {
295 new(options?: RecognizerOptions): PinchRecognizer;
296}
297
298interface PinchRecognizer extends AttrRecognizer {
299}
300
301interface PressRecognizerStatic {
302 new(options?: RecognizerOptions): PressRecognizer;
303}
304
305interface PressRecognizer extends AttrRecognizer {
306}
307
308interface RotateRecognizerStatic {
309 new(options?: RecognizerOptions): RotateRecognizer;
310}
311
312interface RotateRecognizer extends AttrRecognizer {
313}
314
315interface SwipeRecognizerStatic {
316 new(options?: RecognizerOptions): SwipeRecognizer;
317}
318
319interface SwipeRecognizer extends AttrRecognizer {
320}
321
322interface TapRecognizerStatic {
323 new(options?: RecognizerOptions): TapRecognizer;
324}
325
326interface TapRecognizer extends AttrRecognizer {
327}
328
329declare class TouchAction {
330 constructor(manager: HammerManager, value: string);
331
332 compute(): string;
333 preventDefaults(input: HammerInput): void;
334 preventSrc(srcEvent: any): void;
335 set(value: string): void;
336 update(): void;
337}
338
339interface HammerPoint {
340 x: number;
341 y: number;
342}
343
\No newline at end of file