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