@@ -64,6 +64,7 @@ function createPointerEvent(
64
64
altKey = false ,
65
65
buttons = buttonsType . none ,
66
66
ctrlKey = false ,
67
+ detail = 1 ,
67
68
height,
68
69
metaKey = false ,
69
70
movementX = 0 ,
@@ -76,6 +77,8 @@ function createPointerEvent(
76
77
pressure = 0 ,
77
78
preventDefault = emptyFunction ,
78
79
pointerType = 'mouse' ,
80
+ screenX,
81
+ screenY,
79
82
shiftKey = false ,
80
83
tangentialPressure = 0 ,
81
84
tiltX = 0 ,
@@ -87,22 +90,19 @@ function createPointerEvent(
87
90
} = { } ,
88
91
) {
89
92
const modifierState = { altKey, ctrlKey, metaKey, shiftKey} ;
93
+ const isMouse = pointerType === 'mouse' ;
90
94
91
95
return createEvent ( type , {
92
96
altKey,
93
97
buttons,
94
98
clientX : x ,
95
99
clientY : y ,
96
100
ctrlKey,
101
+ detail,
97
102
getModifierState ( keyArg ) {
98
103
createGetModifierState ( keyArg , modifierState ) ;
99
104
} ,
100
- height :
101
- pointerType === 'mouse'
102
- ? 1
103
- : height != null
104
- ? height
105
- : defaultPointerSize ,
105
+ height : isMouse ? 1 : height != null ? height : defaultPointerSize ,
106
106
metaKey,
107
107
movementX,
108
108
movementY,
@@ -114,15 +114,16 @@ function createPointerEvent(
114
114
pointerType,
115
115
pressure,
116
116
preventDefault,
117
- screenX : x ,
118
- screenY : y + defaultBrowserChromeSize ,
117
+ releasePointerCapture : emptyFunction ,
118
+ screenX : screenX === 0 ? screenX : x ,
119
+ screenY : screenY === 0 ? screenY : y + defaultBrowserChromeSize ,
120
+ setPointerCapture : emptyFunction ,
119
121
shiftKey,
120
122
tangentialPressure,
121
123
tiltX,
122
124
tiltY,
123
125
twist,
124
- width :
125
- pointerType === 'mouse' ? 1 : width != null ? width : defaultPointerSize ,
126
+ width : isMouse ? 1 : width != null ? width : defaultPointerSize ,
126
127
} ) ;
127
128
}
128
129
@@ -158,6 +159,7 @@ function createMouseEvent(
158
159
altKey = false ,
159
160
buttons = buttonsType . none ,
160
161
ctrlKey = false ,
162
+ detail = 1 ,
161
163
metaKey = false ,
162
164
movementX = 0 ,
163
165
movementY = 0 ,
@@ -166,81 +168,107 @@ function createMouseEvent(
166
168
pageX,
167
169
pageY,
168
170
preventDefault = emptyFunction ,
171
+ screenX,
172
+ screenY,
169
173
shiftKey = false ,
170
174
x = 0 ,
171
175
y = 0 ,
172
176
} = { } ,
173
- virtual = false ,
174
177
) {
175
178
const modifierState = { altKey, ctrlKey, metaKey, shiftKey} ;
176
179
177
180
return createEvent ( type , {
178
181
altKey,
179
182
buttons,
180
- clientX : virtual ? 0 : x ,
181
- clientY : virtual ? 0 : y ,
183
+ clientX : x ,
184
+ clientY : y ,
182
185
ctrlKey,
183
- detail : virtual ? 0 : 1 ,
186
+ detail,
184
187
getModifierState ( keyArg ) {
185
188
createGetModifierState ( keyArg , modifierState ) ;
186
189
} ,
187
190
metaKey,
188
- movementX : virtual ? 0 : movementX ,
189
- movementY : virtual ? 0 : movementY ,
190
- offsetX : virtual ? 0 : offsetX ,
191
- offsetY : virtual ? 0 : offsetY ,
192
- pageX : virtual ? 0 : pageX || x ,
193
- pageY : virtual ? 0 : pageY || y ,
191
+ movementX,
192
+ movementY,
193
+ offsetX,
194
+ offsetY,
195
+ pageX : pageX || x ,
196
+ pageY : pageY || y ,
194
197
preventDefault,
195
- screenX : virtual ? 0 : x ,
196
- screenY : virtual ? 0 : y + defaultBrowserChromeSize ,
198
+ screenX : screenX === 0 ? screenX : x ,
199
+ screenY : screenY === 0 ? screenY : y + defaultBrowserChromeSize ,
197
200
shiftKey,
198
201
} ) ;
199
202
}
200
203
201
- function createTouchEvent (
202
- type ,
203
- {
204
- altKey = false ,
205
- ctrlKey = false ,
206
- height = defaultPointerSize ,
207
- metaKey = false ,
208
- pageX,
209
- pageY,
210
- pointerId = 1 ,
211
- preventDefault = emptyFunction ,
212
- shiftKey = false ,
213
- twist = 0 ,
214
- width = defaultPointerSize ,
215
- x = 0 ,
216
- y = 0 ,
217
- } = { } ,
218
- ) {
219
- const touch = {
220
- clientX : x ,
221
- clientY : y ,
222
- force : 1 ,
223
- identifier : pointerId ,
224
- pageX : pageX || x ,
225
- pageY : pageY || y ,
226
- radiusX : width / 2 ,
227
- radiusY : height / 2 ,
228
- rotationAngle : twist ,
229
- screenX : x ,
230
- screenY : y + defaultBrowserChromeSize ,
231
- } ;
204
+ function createTouchEvent ( type , payload ) {
205
+ const touchesPayload = Array . isArray ( payload ) ? payload : [ payload ] ;
206
+ const firstTouch = touchesPayload [ 0 ] ;
207
+ let altKey = false ;
208
+ let ctrlKey = false ;
209
+ let metaKey = false ;
210
+ let preventDefault = emptyFunction ;
211
+ let shiftKey = false ;
212
+ if ( firstTouch != null ) {
213
+ if ( firstTouch . altKey != null ) {
214
+ altKey = firstTouch . altKey ;
215
+ }
216
+ if ( firstTouch . ctrlKey != null ) {
217
+ ctrlKey = firstTouch . ctrlKey ;
218
+ }
219
+ if ( firstTouch . metaKey != null ) {
220
+ metaKey = firstTouch . metaKey ;
221
+ }
222
+ if ( firstTouch . preventDefault != null ) {
223
+ preventDefault = firstTouch . preventDefault ;
224
+ }
225
+ if ( firstTouch . shiftKey != null ) {
226
+ shiftKey = firstTouch . shiftKey ;
227
+ }
228
+ }
229
+
230
+ const touches = touchesPayload . map (
231
+ ( {
232
+ height = defaultPointerSize ,
233
+ pageX,
234
+ pageY,
235
+ pointerId = 1 ,
236
+ twist = 0 ,
237
+ width = defaultPointerSize ,
238
+ x = 0 ,
239
+ y = 0 ,
240
+ } = { } ) => {
241
+ return {
242
+ clientX : x ,
243
+ clientY : y ,
244
+ force : 1 ,
245
+ identifier : pointerId ,
246
+ pageX : pageX || x ,
247
+ pageY : pageY || y ,
248
+ radiusX : width / 2 ,
249
+ radiusY : height / 2 ,
250
+ rotationAngle : twist ,
251
+ screenX : x ,
252
+ screenY : y + defaultBrowserChromeSize ,
253
+ } ;
254
+ } ,
255
+ ) ;
232
256
233
- const activeTouch = type !== 'touchend' ? [ touch ] : null ;
257
+ const activeTouches = type !== 'touchend' ? touches : null ;
234
258
235
259
return createEvent ( type , {
236
260
altKey,
237
- changedTouches : [ touch ] ,
261
+ changedTouches : touches ,
238
262
ctrlKey,
263
+ detail : 0 ,
239
264
metaKey,
240
265
preventDefault,
241
266
shiftKey,
242
- targetTouches : activeTouch ,
243
- touches : activeTouch ,
267
+ sourceCapabilities : {
268
+ firesTouchEvents : true ,
269
+ } ,
270
+ targetTouches : activeTouches ,
271
+ touches : activeTouches ,
244
272
} ) ;
245
273
}
246
274
@@ -253,11 +281,24 @@ export function blur({relatedTarget} = {}) {
253
281
}
254
282
255
283
export function click ( payload ) {
256
- return createMouseEvent ( 'click' , payload , false ) ;
284
+ return createMouseEvent ( 'click' , payload ) ;
257
285
}
258
286
259
287
export function virtualclick ( payload ) {
260
- return createMouseEvent ( 'click' , payload , true ) ;
288
+ return createMouseEvent ( 'click' , {
289
+ ...payload ,
290
+ buttons : 0 ,
291
+ detail : 0 ,
292
+ height : 1 ,
293
+ pageX : 0 ,
294
+ pageY : 0 ,
295
+ pressure : 0 ,
296
+ screenX : 0 ,
297
+ screenY : 0 ,
298
+ width : 1 ,
299
+ x : 0 ,
300
+ y : 0 ,
301
+ } ) ;
261
302
}
262
303
263
304
export function contextmenu ( payload ) {
@@ -301,11 +342,24 @@ export function lostpointercapture(payload) {
301
342
}
302
343
303
344
export function pointercancel ( payload ) {
304
- return createPointerEvent ( 'pointercancel' , payload ) ;
345
+ return createPointerEvent ( 'pointercancel' , {
346
+ ...payload ,
347
+ buttons : 0 ,
348
+ detail : 0 ,
349
+ height : 1 ,
350
+ pageX : 0 ,
351
+ pageY : 0 ,
352
+ pressure : 0 ,
353
+ screenX : 0 ,
354
+ screenY : 0 ,
355
+ width : 1 ,
356
+ x : 0 ,
357
+ y : 0 ,
358
+ } ) ;
305
359
}
306
360
307
361
export function pointerdown ( payload ) {
308
- const isTouch = payload != null && payload . pointerType === 'mouse ' ;
362
+ const isTouch = payload != null && payload . pointerType === 'touch ' ;
309
363
return createPointerEvent ( 'pointerdown' , {
310
364
buttons : buttonsType . primary ,
311
365
pressure : isTouch ? 1 : 0.5 ,
@@ -337,6 +391,7 @@ export function pointerup(payload) {
337
391
return createPointerEvent ( 'pointerup' , {
338
392
...payload ,
339
393
buttons : buttonsType . none ,
394
+ pressure : 0 ,
340
395
} ) ;
341
396
}
342
397
0 commit comments