-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.d.ts
239 lines (203 loc) · 5.69 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Type definitions for OdoPointer
// Project: odopod-code-library
// Definitions by: Glen Cheney <https://github.com/Vestride>
import { Coordinate } from '@odopod/odo-helpers';
export as namespace OdoPointer;
export = OdoPointer;
declare class OdoPointer {
/**
* An abstraction layer for adding pointer events and calculating drag values.
* @param {HTMLElement} element Element to watch.
* @param {object} options Options object.
* @throws {TypeError} Throws when the element parameter isn't an element.
*/
constructor(element: HTMLElement, options?: OdoPointer.Options);
/** Main element for this class */
element: HTMLElement;
options: OdoPointer.Options;
/*~
*~ From tiny emitter
*~ https://github.com/scottcorgan/tiny-emitter/blob/master/index.d.ts
*/
on(event: string, callback: Function, ctx?: any): OdoPointer;
once(event: string, callback: Function, ctx?: any): OdoPointer;
emit(event: string, ...args: any[]): OdoPointer;
off(event: string, callback?: Function): OdoPointer;
/**
* Starting location of the drag.
* @type {Coordinate}
*/
pageStart: Coordinate;
/**
* Current position of mouse or touch relative to the document.
* @type {Coordinate}
*/
page: Coordinate;
/**
* Current position of drag relative to target's parent.
* @type {Coordinate}
*/
delta: Coordinate;
/**
* Time in milliseconds when the drag started.
* @type {number}
*/
startTime: number;
/**
* Length of the drag in milliseconds.
* @type {number}
*/
deltaTime: number;
/**
* The current velocity of the drag.
* @type {Coordinate}
*/
velocity: Coordinate;
/**
* The element to which the move and up events will be bound to. If a pointer
* is being used inside a modal which stops events from bubbling to the body,
* this property should be changed to an element which *will* receive the events.
* @type {Document|Element}
*/
dragEventTarget: Document | Element;
/**
* Whether dragging is enabled. If false, touch|mouse|pointer events are ignored.
*/
isEnabled: boolean;
/**
* Friction to apply to dragging. A value of zero would result in no dragging,
* 0.5 would result in the draggable element moving half as far as the user
* dragged, and 1 is a 1:1 ratio with user movement.
*/
friction: number;
listen(): void;
/**
* Whether the draggable axis is the x direction.
*/
isXAxis(): boolean;
/**
* Whether the draggable axis is the y direction.
*/
isYAxis(): boolean;
/**
* Whether the draggable axis is for both axis.
*/
isBothAxis(): boolean;
/**
* Apply a friction value to a coordinate, reducing its value.
* This modifies the coordinate given to it.
* @param {Coordinate} coordinate The coordinate to scale.
* @return {Coordinate} Position multiplied by friction.
*/
applyFriction(coordinate: Coordinate): Coordinate;
/**
* Determine whether the draggable event has enough velocity to be
* considered a swipe.
* @param {Coordinate} velocity Object with x and y properties for velocity.
* @param {number} [threshold] Threshold to check against. Defaults to the swipe
* velocity constant. Must be zero or a positive number.
* @return {boolean}
*/
hasVelocity(velocity: Coordinate, threshold?: number): boolean;
/**
* Remove event listeners and element references.
*/
dispose(): void;
}
declare namespace OdoPointer {
export interface Options {
axis?: OdoPointer.Axis,
preventEventDefault?: boolean,
}
export class Event {
constructor(options: {
type: string;
target: Element;
currentTarget: Element;
start: Coordinate;
end: Coordinate;
delta: Coordinate;
deltaTime: number;
axis: OdoPointer.Axis;
currentVelocity: Coordinate;
});
type: string;
target: Element;
currentTarget: Element;
start: Coordinate;
end: Coordinate;
delta: Coordinate;
deltaTime: number;
axis: OdoPointer.Axis;
velocity: Coordinate;
currentVelocity: Coordinate;
distance: number;
direction: OdoPointer.Direction;
isDirectionOnAxis: boolean;
didMoveOnAxis: boolean;
axisDirection: string;
position: { pixel: Coordinate, percent: Coordinate };
defaultPrevented: boolean;
preventDefault(): void;
}
/**
* Whether the event is from a touch.
* @param {object} evt Event object.
* @return {boolean}
*/
function isTouchEvent(evt: object): boolean;
/**
* Possible drag directions.
*/
enum Direction {
RIGHT = 'right',
LEFT = 'left',
UP = 'up',
DOWN = 'down',
NONE = 'no_movement',
}
enum Axis {
X = 'x',
Y = 'y',
BOTH = 'xy',
}
/**
* Events emitted by pointer instances.
*/
enum EventType {
START = 'odopointer:start',
MOVE = 'odopointer:move',
END = 'odopointer:end',
}
enum TouchAction {
x = 'pan-y',
y = 'pan-x',
xy = 'none',
}
/**
* Default options for each instance.
*/
const Defaults: OdoPointer.Options;
/**
* The current velocity property will be clamped to this value (pixels/millisecond).
*/
let MAX_VELOCITY: number;
/**
* When the pointer is down, an interval starts to track the current velocity.
*/
let VELOCITY_INTERVAL: number;
/**
* Velocity required for a movement to be considered a swipe.
*/
let SWIPE_VELOCITY: number;
/**
* The scroll/drag amount (pixels) required on the draggable axis before
* stopping further page scrolling/movement.
*/
let LOCK_THRESHOLD: number;
/**
* The scroll/drag amount (pixels) required on the opposite draggable axis
* before dragging is deactivated for the rest of the interaction.
*/
let DRAG_THRESHOLD: number;
}