UNPKG

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