@novnc/novnc 1.3.0 → 1.4.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AUTHORS +2 -2
  2. package/LICENSE.txt +1 -1
  3. package/README.md +23 -7
  4. package/core/decoders/jpeg.js +141 -0
  5. package/core/decoders/raw.js +1 -1
  6. package/core/decoders/zrle.js +185 -0
  7. package/core/des.js +1 -1
  8. package/core/display.js +12 -0
  9. package/core/encodings.js +4 -0
  10. package/core/input/keyboard.js +10 -0
  11. package/core/ra2.js +567 -0
  12. package/core/rfb.js +469 -84
  13. package/core/util/browser.js +56 -7
  14. package/core/util/cursor.js +4 -0
  15. package/core/util/md5.js +79 -0
  16. package/docs/API.md +318 -157
  17. package/lib/base64.js +20 -34
  18. package/lib/decoders/copyrect.js +5 -12
  19. package/lib/decoders/hextile.js +17 -47
  20. package/lib/decoders/jpeg.js +149 -0
  21. package/lib/decoders/raw.js +10 -23
  22. package/lib/decoders/rre.js +5 -16
  23. package/lib/decoders/tight.js +13 -79
  24. package/lib/decoders/tightpng.js +8 -28
  25. package/lib/decoders/zrle.js +188 -0
  26. package/lib/deflator.js +9 -23
  27. package/lib/des.js +24 -37
  28. package/lib/display.js +62 -108
  29. package/lib/encodings.js +7 -8
  30. package/lib/inflator.js +6 -19
  31. package/lib/input/domkeytable.js +77 -48
  32. package/lib/input/fixedkeys.js +8 -3
  33. package/lib/input/gesturehandler.js +86 -153
  34. package/lib/input/keyboard.js +62 -91
  35. package/lib/input/keysym.js +14 -270
  36. package/lib/input/keysymdef.js +5 -7
  37. package/lib/input/util.js +43 -85
  38. package/lib/input/vkeys.js +0 -3
  39. package/lib/input/xtscancodes.js +1 -168
  40. package/lib/ra2.js +1005 -0
  41. package/lib/rfb.js +795 -923
  42. package/lib/util/browser.js +66 -29
  43. package/lib/util/cursor.js +29 -66
  44. package/lib/util/element.js +3 -5
  45. package/lib/util/events.js +23 -30
  46. package/lib/util/eventtarget.js +5 -14
  47. package/lib/util/int.js +1 -2
  48. package/lib/util/logging.js +1 -19
  49. package/lib/util/md5.js +77 -0
  50. package/lib/util/strings.js +3 -5
  51. package/lib/vendor/pako/lib/utils/common.js +8 -17
  52. package/lib/vendor/pako/lib/zlib/adler32.js +3 -7
  53. package/lib/vendor/pako/lib/zlib/constants.js +2 -5
  54. package/lib/vendor/pako/lib/zlib/crc32.js +5 -12
  55. package/lib/vendor/pako/lib/zlib/deflate.js +213 -618
  56. package/lib/vendor/pako/lib/zlib/gzheader.js +1 -13
  57. package/lib/vendor/pako/lib/zlib/inffast.js +60 -176
  58. package/lib/vendor/pako/lib/zlib/inflate.js +398 -888
  59. package/lib/vendor/pako/lib/zlib/inftrees.js +63 -169
  60. package/lib/vendor/pako/lib/zlib/messages.js +1 -11
  61. package/lib/vendor/pako/lib/zlib/trees.js +246 -588
  62. package/lib/vendor/pako/lib/zlib/zstream.js +2 -18
  63. package/lib/websock.js +37 -88
  64. package/package.json +32 -35
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
7
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
-
10
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
-
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
-
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
13
  /*
15
14
  * noVNC: HTML5 VNC client
16
15
  * Copyright (C) 2020 The noVNC Authors
@@ -19,6 +18,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
19
18
  * See README.md for usage and integration instructions.
20
19
  *
21
20
  */
21
+
22
22
  var GH_NOGESTURE = 0;
23
23
  var GH_ONETAP = 1;
24
24
  var GH_TWOTAP = 2;
@@ -30,20 +30,21 @@ var GH_PINCH = 64;
30
30
  var GH_INITSTATE = 127;
31
31
  var GH_MOVE_THRESHOLD = 50;
32
32
  var GH_ANGLE_THRESHOLD = 90; // Degrees
33
- // Timeout when waiting for gestures (ms)
34
33
 
35
- var GH_MULTITOUCH_TIMEOUT = 250; // Maximum time between press and release for a tap (ms)
34
+ // Timeout when waiting for gestures (ms)
35
+ var GH_MULTITOUCH_TIMEOUT = 250;
36
36
 
37
- var GH_TAP_TIMEOUT = 1000; // Timeout when waiting for longpress (ms)
37
+ // Maximum time between press and release for a tap (ms)
38
+ var GH_TAP_TIMEOUT = 1000;
38
39
 
39
- var GH_LONGPRESS_TIMEOUT = 1000; // Timeout when waiting to decide between PINCH and TWODRAG (ms)
40
+ // Timeout when waiting for longpress (ms)
41
+ var GH_LONGPRESS_TIMEOUT = 1000;
40
42
 
43
+ // Timeout when waiting to decide between PINCH and TWODRAG (ms)
41
44
  var GH_TWOTOUCH_TIMEOUT = 50;
42
-
43
45
  var GestureHandler = /*#__PURE__*/function () {
44
46
  function GestureHandler() {
45
47
  _classCallCheck(this, GestureHandler);
46
-
47
48
  this._target = null;
48
49
  this._state = GH_INITSTATE;
49
50
  this._tracked = [];
@@ -54,19 +55,14 @@ var GestureHandler = /*#__PURE__*/function () {
54
55
  this._twoTouchTimeoutId = null;
55
56
  this._boundEventHandler = this._eventHandler.bind(this);
56
57
  }
57
-
58
58
  _createClass(GestureHandler, [{
59
59
  key: "attach",
60
60
  value: function attach(target) {
61
61
  this.detach();
62
62
  this._target = target;
63
-
64
63
  this._target.addEventListener('touchstart', this._boundEventHandler);
65
-
66
64
  this._target.addEventListener('touchmove', this._boundEventHandler);
67
-
68
65
  this._target.addEventListener('touchend', this._boundEventHandler);
69
-
70
66
  this._target.addEventListener('touchcancel', this._boundEventHandler);
71
67
  }
72
68
  }, {
@@ -75,19 +71,12 @@ var GestureHandler = /*#__PURE__*/function () {
75
71
  if (!this._target) {
76
72
  return;
77
73
  }
78
-
79
74
  this._stopLongpressTimeout();
80
-
81
75
  this._stopTwoTouchTimeout();
82
-
83
76
  this._target.removeEventListener('touchstart', this._boundEventHandler);
84
-
85
77
  this._target.removeEventListener('touchmove', this._boundEventHandler);
86
-
87
78
  this._target.removeEventListener('touchend', this._boundEventHandler);
88
-
89
79
  this._target.removeEventListener('touchcancel', this._boundEventHandler);
90
-
91
80
  this._target = null;
92
81
  }
93
82
  }, {
@@ -96,22 +85,18 @@ var GestureHandler = /*#__PURE__*/function () {
96
85
  var fn;
97
86
  e.stopPropagation();
98
87
  e.preventDefault();
99
-
100
88
  switch (e.type) {
101
89
  case 'touchstart':
102
90
  fn = this._touchStart;
103
91
  break;
104
-
105
92
  case 'touchmove':
106
93
  fn = this._touchMove;
107
94
  break;
108
-
109
95
  case 'touchend':
110
96
  case 'touchcancel':
111
97
  fn = this._touchEnd;
112
98
  break;
113
99
  }
114
-
115
100
  for (var i = 0; i < e.changedTouches.length; i++) {
116
101
  var touch = e.changedTouches[i];
117
102
  fn.call(this, touch.identifier, touch.clientX, touch.clientY);
@@ -124,30 +109,24 @@ var GestureHandler = /*#__PURE__*/function () {
124
109
  // or we're in a cleanup state
125
110
  if (this._hasDetectedGesture() || this._state === GH_NOGESTURE) {
126
111
  this._ignored.push(id);
127
-
128
112
  return;
129
- } // Did it take too long between touches that we should no longer
130
- // consider this a single gesture?
131
-
113
+ }
132
114
 
115
+ // Did it take too long between touches that we should no longer
116
+ // consider this a single gesture?
133
117
  if (this._tracked.length > 0 && Date.now() - this._tracked[0].started > GH_MULTITOUCH_TIMEOUT) {
134
118
  this._state = GH_NOGESTURE;
135
-
136
119
  this._ignored.push(id);
137
-
138
120
  return;
139
- } // If we're waiting for fingers to release then we should no longer
140
- // recognize new touches
141
-
121
+ }
142
122
 
123
+ // If we're waiting for fingers to release then we should no longer
124
+ // recognize new touches
143
125
  if (this._waitingRelease) {
144
126
  this._state = GH_NOGESTURE;
145
-
146
127
  this._ignored.push(id);
147
-
148
128
  return;
149
129
  }
150
-
151
130
  this._tracked.push({
152
131
  id: id,
153
132
  started: Date.now(),
@@ -158,24 +137,17 @@ var GestureHandler = /*#__PURE__*/function () {
158
137
  lastY: y,
159
138
  angle: 0
160
139
  });
161
-
162
140
  switch (this._tracked.length) {
163
141
  case 1:
164
142
  this._startLongpressTimeout();
165
-
166
143
  break;
167
-
168
144
  case 2:
169
145
  this._state &= ~(GH_ONETAP | GH_DRAG | GH_LONGPRESS);
170
-
171
146
  this._stopLongpressTimeout();
172
-
173
147
  break;
174
-
175
148
  case 3:
176
149
  this._state &= ~(GH_TWOTAP | GH_TWODRAG | GH_PINCH);
177
150
  break;
178
-
179
151
  default:
180
152
  this._state = GH_NOGESTURE;
181
153
  }
@@ -185,66 +157,64 @@ var GestureHandler = /*#__PURE__*/function () {
185
157
  value: function _touchMove(id, x, y) {
186
158
  var touch = this._tracked.find(function (t) {
187
159
  return t.id === id;
188
- }); // If this is an update for a touch we're not tracking, ignore it
189
-
160
+ });
190
161
 
162
+ // If this is an update for a touch we're not tracking, ignore it
191
163
  if (touch === undefined) {
192
164
  return;
193
- } // Update the touches last position with the event coordinates
194
-
165
+ }
195
166
 
167
+ // Update the touches last position with the event coordinates
196
168
  touch.lastX = x;
197
169
  touch.lastY = y;
198
170
  var deltaX = x - touch.firstX;
199
- var deltaY = y - touch.firstY; // Update angle when the touch has moved
171
+ var deltaY = y - touch.firstY;
200
172
 
173
+ // Update angle when the touch has moved
201
174
  if (touch.firstX !== touch.lastX || touch.firstY !== touch.lastY) {
202
175
  touch.angle = Math.atan2(deltaY, deltaX) * 180 / Math.PI;
203
176
  }
204
-
205
177
  if (!this._hasDetectedGesture()) {
206
178
  // Ignore moves smaller than the minimum threshold
207
179
  if (Math.hypot(deltaX, deltaY) < GH_MOVE_THRESHOLD) {
208
180
  return;
209
- } // Can't be a tap or long press as we've seen movement
210
-
181
+ }
211
182
 
183
+ // Can't be a tap or long press as we've seen movement
212
184
  this._state &= ~(GH_ONETAP | GH_TWOTAP | GH_THREETAP | GH_LONGPRESS);
213
-
214
185
  this._stopLongpressTimeout();
215
-
216
186
  if (this._tracked.length !== 1) {
217
187
  this._state &= ~GH_DRAG;
218
188
  }
219
-
220
189
  if (this._tracked.length !== 2) {
221
190
  this._state &= ~(GH_TWODRAG | GH_PINCH);
222
- } // We need to figure out which of our different two touch gestures
223
- // this might be
224
-
191
+ }
225
192
 
193
+ // We need to figure out which of our different two touch gestures
194
+ // this might be
226
195
  if (this._tracked.length === 2) {
227
196
  // The other touch is the one where the id doesn't match
228
197
  var prevTouch = this._tracked.find(function (t) {
229
198
  return t.id !== id;
230
- }); // How far the previous touch point has moved since start
199
+ });
231
200
 
201
+ // How far the previous touch point has moved since start
202
+ var prevDeltaMove = Math.hypot(prevTouch.firstX - prevTouch.lastX, prevTouch.firstY - prevTouch.lastY);
232
203
 
233
- var prevDeltaMove = Math.hypot(prevTouch.firstX - prevTouch.lastX, prevTouch.firstY - prevTouch.lastY); // We know that the current touch moved far enough,
204
+ // We know that the current touch moved far enough,
234
205
  // but unless both touches moved further than their
235
206
  // threshold we don't want to disqualify any gestures
236
-
237
207
  if (prevDeltaMove > GH_MOVE_THRESHOLD) {
238
208
  // The angle difference between the direction of the touch points
239
209
  var deltaAngle = Math.abs(touch.angle - prevTouch.angle);
240
- deltaAngle = Math.abs((deltaAngle + 180) % 360 - 180); // PINCH or TWODRAG can be eliminated depending on the angle
210
+ deltaAngle = Math.abs((deltaAngle + 180) % 360 - 180);
241
211
 
212
+ // PINCH or TWODRAG can be eliminated depending on the angle
242
213
  if (deltaAngle > GH_ANGLE_THRESHOLD) {
243
214
  this._state &= ~GH_TWODRAG;
244
215
  } else {
245
216
  this._state &= ~GH_PINCH;
246
217
  }
247
-
248
218
  if (this._isTwoTouchTimeoutRunning()) {
249
219
  this._stopTwoTouchTimeout();
250
220
  }
@@ -254,14 +224,11 @@ var GestureHandler = /*#__PURE__*/function () {
254
224
  this._startTwoTouchTimeout();
255
225
  }
256
226
  }
257
-
258
227
  if (!this._hasDetectedGesture()) {
259
228
  return;
260
229
  }
261
-
262
230
  this._pushEvent('gesturestart');
263
231
  }
264
-
265
232
  this._pushEvent('gesturemove');
266
233
  }
267
234
  }, {
@@ -270,70 +237,65 @@ var GestureHandler = /*#__PURE__*/function () {
270
237
  // Check if this is an ignored touch
271
238
  if (this._ignored.indexOf(id) !== -1) {
272
239
  // Remove this touch from ignored
273
- this._ignored.splice(this._ignored.indexOf(id), 1); // And reset the state if there are no more touches
274
-
240
+ this._ignored.splice(this._ignored.indexOf(id), 1);
275
241
 
242
+ // And reset the state if there are no more touches
276
243
  if (this._ignored.length === 0 && this._tracked.length === 0) {
277
244
  this._state = GH_INITSTATE;
278
245
  this._waitingRelease = false;
279
246
  }
280
-
281
247
  return;
282
- } // We got a touchend before the timer triggered,
283
- // this cannot result in a gesture anymore.
284
-
248
+ }
285
249
 
250
+ // We got a touchend before the timer triggered,
251
+ // this cannot result in a gesture anymore.
286
252
  if (!this._hasDetectedGesture() && this._isTwoTouchTimeoutRunning()) {
287
253
  this._stopTwoTouchTimeout();
288
-
289
254
  this._state = GH_NOGESTURE;
290
- } // Some gestures don't trigger until a touch is released
291
-
255
+ }
292
256
 
257
+ // Some gestures don't trigger until a touch is released
293
258
  if (!this._hasDetectedGesture()) {
294
259
  // Can't be a gesture that relies on movement
295
- this._state &= ~(GH_DRAG | GH_TWODRAG | GH_PINCH); // Or something that relies on more time
296
-
260
+ this._state &= ~(GH_DRAG | GH_TWODRAG | GH_PINCH);
261
+ // Or something that relies on more time
297
262
  this._state &= ~GH_LONGPRESS;
298
-
299
263
  this._stopLongpressTimeout();
300
-
301
264
  if (!this._waitingRelease) {
302
265
  this._releaseStart = Date.now();
303
- this._waitingRelease = true; // Can't be a tap that requires more touches than we current have
266
+ this._waitingRelease = true;
304
267
 
268
+ // Can't be a tap that requires more touches than we current have
305
269
  switch (this._tracked.length) {
306
270
  case 1:
307
271
  this._state &= ~(GH_TWOTAP | GH_THREETAP);
308
272
  break;
309
-
310
273
  case 2:
311
274
  this._state &= ~(GH_ONETAP | GH_THREETAP);
312
275
  break;
313
276
  }
314
277
  }
315
- } // Waiting for all touches to release? (i.e. some tap)
316
-
278
+ }
317
279
 
280
+ // Waiting for all touches to release? (i.e. some tap)
318
281
  if (this._waitingRelease) {
319
282
  // Were all touches released at roughly the same time?
320
283
  if (Date.now() - this._releaseStart > GH_MULTITOUCH_TIMEOUT) {
321
284
  this._state = GH_NOGESTURE;
322
- } // Did too long time pass between press and release?
323
-
285
+ }
324
286
 
287
+ // Did too long time pass between press and release?
325
288
  if (this._tracked.some(function (t) {
326
289
  return Date.now() - t.started > GH_TAP_TIMEOUT;
327
290
  })) {
328
291
  this._state = GH_NOGESTURE;
329
292
  }
330
-
331
293
  var touch = this._tracked.find(function (t) {
332
294
  return t.id === id;
333
295
  });
296
+ touch.active = false;
334
297
 
335
- touch.active = false; // Are we still waiting for more releases?
336
-
298
+ // Are we still waiting for more releases?
337
299
  if (this._hasDetectedGesture()) {
338
300
  this._pushEvent('gesturestart');
339
301
  } else {
@@ -343,26 +305,25 @@ var GestureHandler = /*#__PURE__*/function () {
343
305
  }
344
306
  }
345
307
  }
346
-
347
308
  if (this._hasDetectedGesture()) {
348
309
  this._pushEvent('gestureend');
349
- } // Ignore any remaining touches until they are ended
350
-
310
+ }
351
311
 
312
+ // Ignore any remaining touches until they are ended
352
313
  for (var i = 0; i < this._tracked.length; i++) {
353
314
  if (this._tracked[i].active) {
354
315
  this._ignored.push(this._tracked[i].id);
355
316
  }
356
317
  }
357
-
358
318
  this._tracked = [];
359
- this._state = GH_NOGESTURE; // Remove this touch from ignored if it's in there
319
+ this._state = GH_NOGESTURE;
360
320
 
321
+ // Remove this touch from ignored if it's in there
361
322
  if (this._ignored.indexOf(id) !== -1) {
362
323
  this._ignored.splice(this._ignored.indexOf(id), 1);
363
- } // We reset the state if ignored is empty
364
-
324
+ }
365
325
 
326
+ // We reset the state if ignored is empty
366
327
  if (this._ignored.length === 0) {
367
328
  this._state = GH_INITSTATE;
368
329
  this._waitingRelease = false;
@@ -373,16 +334,15 @@ var GestureHandler = /*#__PURE__*/function () {
373
334
  value: function _hasDetectedGesture() {
374
335
  if (this._state === GH_NOGESTURE) {
375
336
  return false;
376
- } // Check to see if the bitmask value is a power of 2
337
+ }
338
+ // Check to see if the bitmask value is a power of 2
377
339
  // (i.e. only one bit set). If it is, we have a state.
378
-
379
-
380
340
  if (this._state & this._state - 1) {
381
341
  return false;
382
- } // For taps we also need to have all touches released
383
- // before we've fully detected the gesture
384
-
342
+ }
385
343
 
344
+ // For taps we also need to have all touches released
345
+ // before we've fully detected the gesture
386
346
  if (this._state & (GH_ONETAP | GH_TWOTAP | GH_THREETAP)) {
387
347
  if (this._tracked.some(function (t) {
388
348
  return t.active;
@@ -390,16 +350,13 @@ var GestureHandler = /*#__PURE__*/function () {
390
350
  return false;
391
351
  }
392
352
  }
393
-
394
353
  return true;
395
354
  }
396
355
  }, {
397
356
  key: "_startLongpressTimeout",
398
357
  value: function _startLongpressTimeout() {
399
358
  var _this = this;
400
-
401
359
  this._stopLongpressTimeout();
402
-
403
360
  this._longpressTimeoutId = setTimeout(function () {
404
361
  return _this._longpressTimeout();
405
362
  }, GH_LONGPRESS_TIMEOUT);
@@ -416,18 +373,14 @@ var GestureHandler = /*#__PURE__*/function () {
416
373
  if (this._hasDetectedGesture()) {
417
374
  throw new Error("A longpress gesture failed, conflict with a different gesture");
418
375
  }
419
-
420
376
  this._state = GH_LONGPRESS;
421
-
422
377
  this._pushEvent('gesturestart');
423
378
  }
424
379
  }, {
425
380
  key: "_startTwoTouchTimeout",
426
381
  value: function _startTwoTouchTimeout() {
427
382
  var _this2 = this;
428
-
429
383
  this._stopTwoTouchTimeout();
430
-
431
384
  this._twoTouchTimeoutId = setTimeout(function () {
432
385
  return _this2._twoTouchTimeout();
433
386
  }, GH_TWOTOUCH_TIMEOUT);
@@ -448,27 +401,23 @@ var GestureHandler = /*#__PURE__*/function () {
448
401
  value: function _twoTouchTimeout() {
449
402
  if (this._tracked.length === 0) {
450
403
  throw new Error("A pinch or two drag gesture failed, no tracked touches");
451
- } // How far each touch point has moved since start
452
-
404
+ }
453
405
 
406
+ // How far each touch point has moved since start
454
407
  var avgM = this._getAverageMovement();
455
-
456
408
  var avgMoveH = Math.abs(avgM.x);
457
- var avgMoveV = Math.abs(avgM.y); // The difference in the distance between where
458
- // the touch points started and where they are now
409
+ var avgMoveV = Math.abs(avgM.y);
459
410
 
411
+ // The difference in the distance between where
412
+ // the touch points started and where they are now
460
413
  var avgD = this._getAverageDistance();
461
-
462
414
  var deltaTouchDistance = Math.abs(Math.hypot(avgD.first.x, avgD.first.y) - Math.hypot(avgD.last.x, avgD.last.y));
463
-
464
415
  if (avgMoveV < deltaTouchDistance && avgMoveH < deltaTouchDistance) {
465
416
  this._state = GH_PINCH;
466
417
  } else {
467
418
  this._state = GH_TWODRAG;
468
419
  }
469
-
470
420
  this._pushEvent('gesturestart');
471
-
472
421
  this._pushEvent('gesturemove');
473
422
  }
474
423
  }, {
@@ -476,34 +425,35 @@ var GestureHandler = /*#__PURE__*/function () {
476
425
  value: function _pushEvent(type) {
477
426
  var detail = {
478
427
  type: this._stateToGesture(this._state)
479
- }; // For most gesture events the current (average) position is the
480
- // most useful
428
+ };
481
429
 
430
+ // For most gesture events the current (average) position is the
431
+ // most useful
482
432
  var avg = this._getPosition();
433
+ var pos = avg.last;
483
434
 
484
- var pos = avg.last; // However we have a slight distance to detect gestures, so for the
435
+ // However we have a slight distance to detect gestures, so for the
485
436
  // first gesture event we want to use the first positions we saw
486
-
487
437
  if (type === 'gesturestart') {
488
438
  pos = avg.first;
489
- } // For these gestures, we always want the event coordinates
490
- // to be where the gesture began, not the current touch location.
491
-
439
+ }
492
440
 
441
+ // For these gestures, we always want the event coordinates
442
+ // to be where the gesture began, not the current touch location.
493
443
  switch (this._state) {
494
444
  case GH_TWODRAG:
495
445
  case GH_PINCH:
496
446
  pos = avg.first;
497
447
  break;
498
448
  }
499
-
500
449
  detail['clientX'] = pos.x;
501
- detail['clientY'] = pos.y; // FIXME: other coordinates?
502
- // Some gestures also have a magnitude
450
+ detail['clientY'] = pos.y;
503
451
 
452
+ // FIXME: other coordinates?
453
+
454
+ // Some gestures also have a magnitude
504
455
  if (this._state === GH_PINCH) {
505
456
  var distance = this._getAverageDistance();
506
-
507
457
  if (type === 'gesturestart') {
508
458
  detail['magnitudeX'] = distance.first.x;
509
459
  detail['magnitudeY'] = distance.first.y;
@@ -517,16 +467,13 @@ var GestureHandler = /*#__PURE__*/function () {
517
467
  detail['magnitudeY'] = 0.0;
518
468
  } else {
519
469
  var movement = this._getAverageMovement();
520
-
521
470
  detail['magnitudeX'] = movement.x;
522
471
  detail['magnitudeY'] = movement.y;
523
472
  }
524
473
  }
525
-
526
474
  var gev = new CustomEvent(type, {
527
475
  detail: detail
528
476
  });
529
-
530
477
  this._target.dispatchEvent(gev);
531
478
  }
532
479
  }, {
@@ -535,26 +482,19 @@ var GestureHandler = /*#__PURE__*/function () {
535
482
  switch (state) {
536
483
  case GH_ONETAP:
537
484
  return 'onetap';
538
-
539
485
  case GH_TWOTAP:
540
486
  return 'twotap';
541
-
542
487
  case GH_THREETAP:
543
488
  return 'threetap';
544
-
545
489
  case GH_DRAG:
546
490
  return 'drag';
547
-
548
491
  case GH_LONGPRESS:
549
492
  return 'longpress';
550
-
551
493
  case GH_TWODRAG:
552
494
  return 'twodrag';
553
-
554
495
  case GH_PINCH:
555
496
  return 'pinch';
556
497
  }
557
-
558
498
  throw new Error("Unknown gesture state: " + state);
559
499
  }
560
500
  }, {
@@ -563,20 +503,17 @@ var GestureHandler = /*#__PURE__*/function () {
563
503
  if (this._tracked.length === 0) {
564
504
  throw new Error("Failed to get gesture position, no tracked touches");
565
505
  }
566
-
567
506
  var size = this._tracked.length;
568
507
  var fx = 0,
569
- fy = 0,
570
- lx = 0,
571
- ly = 0;
572
-
508
+ fy = 0,
509
+ lx = 0,
510
+ ly = 0;
573
511
  for (var i = 0; i < this._tracked.length; i++) {
574
512
  fx += this._tracked[i].firstX;
575
513
  fy += this._tracked[i].firstY;
576
514
  lx += this._tracked[i].lastX;
577
515
  ly += this._tracked[i].lastY;
578
516
  }
579
-
580
517
  return {
581
518
  first: {
582
519
  x: fx / size,
@@ -594,16 +531,13 @@ var GestureHandler = /*#__PURE__*/function () {
594
531
  if (this._tracked.length === 0) {
595
532
  throw new Error("Failed to get gesture movement, no tracked touches");
596
533
  }
597
-
598
534
  var totalH, totalV;
599
535
  totalH = totalV = 0;
600
536
  var size = this._tracked.length;
601
-
602
537
  for (var i = 0; i < this._tracked.length; i++) {
603
538
  totalH += this._tracked[i].lastX - this._tracked[i].firstX;
604
539
  totalV += this._tracked[i].lastY - this._tracked[i].firstY;
605
540
  }
606
-
607
541
  return {
608
542
  x: totalH / size,
609
543
  y: totalV / size
@@ -614,8 +548,9 @@ var GestureHandler = /*#__PURE__*/function () {
614
548
  value: function _getAverageDistance() {
615
549
  if (this._tracked.length === 0) {
616
550
  throw new Error("Failed to get gesture distance, no tracked touches");
617
- } // Distance between the first and last tracked touches
551
+ }
618
552
 
553
+ // Distance between the first and last tracked touches
619
554
 
620
555
  var first = this._tracked[0];
621
556
  var last = this._tracked[this._tracked.length - 1];
@@ -635,8 +570,6 @@ var GestureHandler = /*#__PURE__*/function () {
635
570
  };
636
571
  }
637
572
  }]);
638
-
639
573
  return GestureHandler;
640
574
  }();
641
-
642
575
  exports["default"] = GestureHandler;