forked from taye/interact.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
315 lines (286 loc) · 7.39 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Type definitions for interact.js
// Project: http://interactjs.io/
// Definitions by: Gaspard Bucher <feature-space.com>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace interact {
interface Position {
x: number
y: number
}
interface SnapPosition {
x: number
y: number
range?: number
}
interface Rect {
top: number
left: number
bottom: number
right: number
}
interface Rect2 {
x: number
y: number
width: number
height: number
}
interface Rect3 {
width: number
height: number
}
interface SnapFunction {
( x: number, y: number ) : SnapPosition
}
type SnapTarget = SnapPosition | SnapFunction
type SnapOptions = {
targets?: SnapTarget[]
// target range
range?: number
// self points for snappin [0,0] = top-left, [1,1] = bottom righ
relativePoints?: Position[]
// startCoords = offset snapping from drag start page position
offset?: Position | 'startCoords'
}
interface InertiaOption {
resistance?: number
minSpeed?: number
endSpeed?: number
allowResume?: boolean
zeroResumeDelta?: boolean
smoothEndDuration?: number
}
type InertiaOptions = InertiaOption | boolean
interface AutoScrollOption {
container?: DOMElement
margin?: number
distance?: number
interval?: number
}
type AutoScrollOptions = AutoScrollOption | boolean
type CSSSelector = string
type DOMElement = any
type RestrictOption = {
// where to drag over
restriction?: Rect | Rect2 | CSSSelector | DOMElement | 'self' | 'parent'
// what part of self is allowed to drag over
elementRect?: Rect
// restrict just before the end drag
endOnly?: boolean
}
interface RestrictSizeOption {
min?: Rect3
max?: Rect3
}
interface EdgeOptions {
top?: boolean | CSSSelector | DOMElement
left?: boolean | CSSSelector | DOMElement
bottom?: boolean | CSSSelector | DOMElement
right?: boolean | CSSSelector | DOMElement
}
interface DraggableOptions {
enabled?: boolean
max?: number
maxPerElement?: number
manualStart?: boolean
snap?: SnapOptions
restrict?: RestrictOption
inertia?: InertiaOptions
autoScroll?: AutoScrollOptions
axis?: 'x' | 'y'
onstart?: Listener
onmove?: Listener
oninertiastart?: Listener
onend?: Listener
}
interface ResizableOptions {
max?: number
maxPerElement?: number
manualStart?: boolean
snap?: SnapOptions
snapSize?: SnapOptions
restrict?: RestrictOption
inertia?: InertiaOptions
autoScroll?: AutoScrollOptions
restrictSize?: RestrictSizeOption
square?: boolean
edges?: EdgeOptions
// deprecated
axis?: 'x' | 'y'
//
invert?: 'none' | 'negate' | 'reposition'
squareResize?: boolean
onstart?: Listener
onmove?: Listener
oninertiastart?: Listener
onend?: Listener
}
interface GesturableOptions {
enabled?: boolean,
max?: Number,
maxPerElement?: Number,
manualStart?: Boolean,
restrict?: RestrictOption
onstart?: Listener
onmove?: Listener
onend?: Listener
}
interface DropFunctionChecker {
( dragEvent: any // related drag operation
, event: any // touch or mouse EventEmitter
, dropped: boolean // default checker result
, dropzone: Interactable // dropzone interactable
, dropElement: DOMElement // drop zone element
, draggable: Interactable // draggable's Interactable
, draggableElement: DOMElement // dragged element
) : boolean
}
interface DropZoneOptions {
accept?: CSSSelector
// How the overlap is checked on the drop zone
overlap?: 'pointer' | 'center' | number
checker?: DropFunctionChecker
ondropactivate?: Listener
ondropdeactivate?: Listener
ondragenter?: Listener
ondragleave?: Listener
ondropmove?: Listener
ondrop?: Listener
}
interface InteractEvent {
// For other things specific to each event (See W3C), use
// event [ 'bubbles' ] instead of event.bubbles
// on every touch/drag event
type: string
target: DOMElement
relatedTarget: DOMElement
currentTarget: DOMElement
preventDefault ()
pageX: number
pageY: number
clientX: number
clientY: number
screenX: number
screenY: number
button: number
buttons: number
ctrlKey: boolean
shiftKey: boolean
altKey: boolean
metaKey: boolean
// added by interact.js
interactable: Interactable
interaction: any
x0: number
y0: number
clientX0: number
clientY0: number
dx: number
dy: number
velocityX: number
velocityY: number
speed: number
timeStamp: any
// drag
dragEnter?: DOMElement
dragLeave?: DOMElement
// resize
axes: Position
// gestureend
distance: number
angle: number
da: number // angle change
scale: number // ratio of distance start to current event
ds: number // scale change
box: Rect // enclosing box of all points
}
interface Listener {
( e: InteractEvent ): void
}
type OnEventName =
'dragstart'
| 'dragmove'
| 'draginertiastart'
| 'dragend'
| 'resizestart'
| 'resizemove'
| 'resizeinertiastart'
| 'resizeend'
| 'gesturestart'
| 'gesturemove'
| 'gestureend'
// drop
| 'dropactivate'
| 'dropdeactivate'
| 'dragenter'
| 'dragleave'
| 'dropmove'
| 'drop'
// pointer events
| 'down'
| 'move'
| 'up'
| 'cancel'
| 'tap'
| 'doubletap'
| 'hold'
interface OnEventFunctions {
dragstart?: Listener
dragmove?: Listener
draginertiastart?: Listener
dragend?: Listener
resizestart?: Listener
resizemove?: Listener
resizeinertiastart?: Listener
resizeend?: Listener
gesturestart?: Listener
gesturemove?: Listener
gestureend?: Listener
// drop
dropactivate?: Listener
dropdeactivate?: Listener
dragenter?: Listener
dragleave?: Listener
dropmove?: Listener
drop?: Listener
// pointer events
down?: Listener
move?: Listener
up?: Listener
cancel?: Listener
tap?: Listener
doubletap?: Listener
hold?: Listener
}
type OnEvent = OnEventName | OnEventName[]
interface Interactable {
draggable ( opt: DraggableOptions ) : Interactable
resizable ( opt: ResizableOptions ) : Interactable
gesturable ( opt: GesturableOptions ) : Interactable
dropzone ( opt: DropZoneOptions ) : Interactable
on ( opt: OnEvent, listener?: Listener ) : Interactable
on ( opt: OnEventFunctions ) : Interactable
styleCursor ( yesno: boolean ) : Interactable
test ( x : SnapFunction )
}
interface InteractOptions {
context: DOMElement
}
interface InteractStatic {
( el: DOMElement | CSSSelector, opts?: InteractOptions ): Interactable
on ( opt: OnEvent | OnEventFunctions, listener?: Listener ) : Interactable
supportsTouch () : boolean
supportsPointerEvent () : boolean
stop ( event: any ) : InteractStatic
pointerMoveTolerance ( tol?: number ) : number | InteractStatic
createSnapGrid ( grid: { x: number, y: number, range: number, offset?: Position, limits?: Rect } ) : SnapFunction
// TODO
isSet ( any ) : any
off ( any ) : any
debug ( any ) : any
addDocument ( any ) : any
removeDocument ( any ) : any
}
}
declare var interact:interact.InteractStatic;
export as namespace interact;
export = interact;