@novnc/novnc 1.0.0 → 1.2.0

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 (87) hide show
  1. package/AUTHORS +13 -0
  2. package/LICENSE.txt +2 -1
  3. package/README.md +69 -3
  4. package/core/base64.js +35 -41
  5. package/core/decoders/copyrect.js +22 -0
  6. package/core/decoders/hextile.js +137 -0
  7. package/core/decoders/raw.js +56 -0
  8. package/core/decoders/rre.js +44 -0
  9. package/core/decoders/tight.js +315 -0
  10. package/core/decoders/tightpng.js +27 -0
  11. package/core/deflator.js +85 -0
  12. package/core/des.js +90 -95
  13. package/core/display.js +254 -297
  14. package/core/encodings.js +7 -3
  15. package/core/inflator.js +48 -20
  16. package/core/input/domkeytable.js +21 -24
  17. package/core/input/fixedkeys.js +3 -1
  18. package/core/input/gesturehandler.js +567 -0
  19. package/core/input/keyboard.js +194 -120
  20. package/core/input/keysym.js +2 -0
  21. package/core/input/keysymdef.js +3 -3
  22. package/core/input/util.js +53 -12
  23. package/core/input/vkeys.js +2 -1
  24. package/core/rfb.js +1937 -1496
  25. package/core/util/browser.js +80 -29
  26. package/core/util/cursor.js +253 -0
  27. package/core/util/element.js +32 -0
  28. package/core/util/events.js +59 -55
  29. package/core/util/eventtarget.js +25 -30
  30. package/core/util/int.js +15 -0
  31. package/core/util/logging.js +21 -16
  32. package/core/util/polyfill.js +15 -8
  33. package/core/util/strings.js +21 -8
  34. package/core/websock.js +145 -167
  35. package/docs/API.md +31 -10
  36. package/lib/base64.js +115 -0
  37. package/lib/decoders/copyrect.js +44 -0
  38. package/lib/decoders/hextile.js +173 -0
  39. package/lib/decoders/raw.js +78 -0
  40. package/lib/decoders/rre.js +65 -0
  41. package/lib/decoders/tight.js +350 -0
  42. package/lib/decoders/tightpng.js +67 -0
  43. package/lib/deflator.js +99 -0
  44. package/lib/des.js +314 -0
  45. package/lib/display.js +733 -0
  46. package/lib/encodings.js +64 -0
  47. package/lib/inflator.js +87 -0
  48. package/lib/input/domkeytable.js +282 -0
  49. package/lib/input/fixedkeys.js +123 -0
  50. package/lib/input/gesturehandler.js +642 -0
  51. package/lib/input/keyboard.js +429 -0
  52. package/lib/input/keysym.js +1135 -0
  53. package/lib/input/keysymdef.js +1354 -0
  54. package/lib/input/util.js +304 -0
  55. package/lib/input/vkeys.js +127 -0
  56. package/lib/input/xtscancodes.js +505 -0
  57. package/lib/rfb.js +3448 -0
  58. package/lib/util/browser.js +131 -0
  59. package/lib/util/cursor.js +314 -0
  60. package/lib/util/element.js +43 -0
  61. package/lib/util/events.js +142 -0
  62. package/lib/util/eventtarget.js +64 -0
  63. package/lib/util/int.js +22 -0
  64. package/lib/util/logging.js +79 -0
  65. package/lib/util/polyfill.js +72 -0
  66. package/lib/util/strings.js +38 -0
  67. package/lib/vendor/pako/lib/utils/common.js +67 -0
  68. package/lib/vendor/pako/lib/zlib/adler32.js +33 -0
  69. package/lib/vendor/pako/lib/zlib/constants.js +51 -0
  70. package/lib/vendor/pako/lib/zlib/crc32.js +42 -0
  71. package/lib/vendor/pako/lib/zlib/deflate.js +2159 -0
  72. package/lib/vendor/pako/lib/zlib/gzheader.js +53 -0
  73. package/lib/vendor/pako/lib/zlib/inffast.js +445 -0
  74. package/lib/vendor/pako/lib/zlib/inflate.js +2114 -0
  75. package/lib/vendor/pako/lib/zlib/inftrees.js +418 -0
  76. package/lib/vendor/pako/lib/zlib/messages.js +36 -0
  77. package/lib/vendor/pako/lib/zlib/trees.js +1499 -0
  78. package/lib/vendor/pako/lib/zlib/zstream.js +46 -0
  79. package/lib/vendor/promise.js +255 -0
  80. package/lib/websock.js +374 -0
  81. package/package.json +48 -28
  82. package/vendor/pako/lib/zlib/deflate.js +30 -30
  83. package/vendor/pako/lib/zlib/inflate.js +17 -17
  84. package/core/input/mouse.js +0 -280
  85. package/docs/API-internal.md +0 -125
  86. package/docs/EMBEDDING.md +0 -83
  87. package/docs/VERSION +0 -1
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.isMac = isMac;
9
+ exports.isWindows = isWindows;
10
+ exports.isIOS = isIOS;
11
+ exports.isSafari = isSafari;
12
+ exports.isIE = isIE;
13
+ exports.isEdge = isEdge;
14
+ exports.isFirefox = isFirefox;
15
+ exports.hasScrollbarGutter = exports.supportsImageMetadata = exports.supportsCursorURIs = exports.dragThreshold = exports.isTouchDevice = void 0;
16
+
17
+ var Log = _interopRequireWildcard(require("./logging.js"));
18
+
19
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
20
+
21
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+
23
+ /*
24
+ * noVNC: HTML5 VNC client
25
+ * Copyright (C) 2019 The noVNC Authors
26
+ * Licensed under MPL 2.0 (see LICENSE.txt)
27
+ *
28
+ * See README.md for usage and integration instructions.
29
+ *
30
+ * Browser feature support detection
31
+ */
32
+ // Touch detection
33
+ var isTouchDevice = 'ontouchstart' in document.documentElement || // requried for Chrome debugger
34
+ document.ontouchstart !== undefined || // required for MS Surface
35
+ navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
36
+ exports.isTouchDevice = isTouchDevice;
37
+ window.addEventListener('touchstart', function onFirstTouch() {
38
+ exports.isTouchDevice = isTouchDevice = true;
39
+ window.removeEventListener('touchstart', onFirstTouch, false);
40
+ }, false); // The goal is to find a certain physical width, the devicePixelRatio
41
+ // brings us a bit closer but is not optimal.
42
+
43
+ var dragThreshold = 10 * (window.devicePixelRatio || 1);
44
+ exports.dragThreshold = dragThreshold;
45
+ var _supportsCursorURIs = false;
46
+
47
+ try {
48
+ var target = document.createElement('canvas');
49
+ target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
50
+
51
+ if (target.style.cursor.indexOf("url") === 0) {
52
+ Log.Info("Data URI scheme cursor supported");
53
+ _supportsCursorURIs = true;
54
+ } else {
55
+ Log.Warn("Data URI scheme cursor not supported");
56
+ }
57
+ } catch (exc) {
58
+ Log.Error("Data URI scheme cursor test exception: " + exc);
59
+ }
60
+
61
+ var supportsCursorURIs = _supportsCursorURIs;
62
+ exports.supportsCursorURIs = supportsCursorURIs;
63
+ var _supportsImageMetadata = false;
64
+
65
+ try {
66
+ new ImageData(new Uint8ClampedArray(4), 1, 1);
67
+ _supportsImageMetadata = true;
68
+ } catch (ex) {// ignore failure
69
+ }
70
+
71
+ var supportsImageMetadata = _supportsImageMetadata;
72
+ exports.supportsImageMetadata = supportsImageMetadata;
73
+ var _hasScrollbarGutter = true;
74
+
75
+ try {
76
+ // Create invisible container
77
+ var container = document.createElement('div');
78
+ container.style.visibility = 'hidden';
79
+ container.style.overflow = 'scroll'; // forcing scrollbars
80
+
81
+ document.body.appendChild(container); // Create a div and place it in the container
82
+
83
+ var child = document.createElement('div');
84
+ container.appendChild(child); // Calculate the difference between the container's full width
85
+ // and the child's width - the difference is the scrollbars
86
+
87
+ var scrollbarWidth = container.offsetWidth - child.offsetWidth; // Clean up
88
+
89
+ container.parentNode.removeChild(container);
90
+ _hasScrollbarGutter = scrollbarWidth != 0;
91
+ } catch (exc) {
92
+ Log.Error("Scrollbar test exception: " + exc);
93
+ }
94
+
95
+ var hasScrollbarGutter = _hasScrollbarGutter;
96
+ /*
97
+ * The functions for detection of platforms and browsers below are exported
98
+ * but the use of these should be minimized as much as possible.
99
+ *
100
+ * It's better to use feature detection than platform detection.
101
+ */
102
+
103
+ exports.hasScrollbarGutter = hasScrollbarGutter;
104
+
105
+ function isMac() {
106
+ return navigator && !!/mac/i.exec(navigator.platform);
107
+ }
108
+
109
+ function isWindows() {
110
+ return navigator && !!/win/i.exec(navigator.platform);
111
+ }
112
+
113
+ function isIOS() {
114
+ return navigator && (!!/ipad/i.exec(navigator.platform) || !!/iphone/i.exec(navigator.platform) || !!/ipod/i.exec(navigator.platform));
115
+ }
116
+
117
+ function isSafari() {
118
+ return navigator && navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1;
119
+ }
120
+
121
+ function isIE() {
122
+ return navigator && !!/trident/i.exec(navigator.userAgent);
123
+ }
124
+
125
+ function isEdge() {
126
+ return navigator && !!/edge/i.exec(navigator.userAgent);
127
+ }
128
+
129
+ function isFirefox() {
130
+ return navigator && !!/firefox/i.exec(navigator.userAgent);
131
+ }
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _browser = require("./browser.js");
9
+
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+
12
+ 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); } }
13
+
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
+
16
+ var useFallback = !_browser.supportsCursorURIs || _browser.isTouchDevice;
17
+
18
+ var Cursor = /*#__PURE__*/function () {
19
+ function Cursor() {
20
+ _classCallCheck(this, Cursor);
21
+
22
+ this._target = null;
23
+ this._canvas = document.createElement('canvas');
24
+
25
+ if (useFallback) {
26
+ this._canvas.style.position = 'fixed';
27
+ this._canvas.style.zIndex = '65535';
28
+ this._canvas.style.pointerEvents = 'none'; // Can't use "display" because of Firefox bug #1445997
29
+
30
+ this._canvas.style.visibility = 'hidden';
31
+ }
32
+
33
+ this._position = {
34
+ x: 0,
35
+ y: 0
36
+ };
37
+ this._hotSpot = {
38
+ x: 0,
39
+ y: 0
40
+ };
41
+ this._eventHandlers = {
42
+ 'mouseover': this._handleMouseOver.bind(this),
43
+ 'mouseleave': this._handleMouseLeave.bind(this),
44
+ 'mousemove': this._handleMouseMove.bind(this),
45
+ 'mouseup': this._handleMouseUp.bind(this)
46
+ };
47
+ }
48
+
49
+ _createClass(Cursor, [{
50
+ key: "attach",
51
+ value: function attach(target) {
52
+ if (this._target) {
53
+ this.detach();
54
+ }
55
+
56
+ this._target = target;
57
+
58
+ if (useFallback) {
59
+ document.body.appendChild(this._canvas); // FIXME: These don't fire properly except for mouse
60
+ /// movement in IE. We want to also capture element
61
+ // movement, size changes, visibility, etc.
62
+
63
+ var options = {
64
+ capture: true,
65
+ passive: true
66
+ };
67
+
68
+ this._target.addEventListener('mouseover', this._eventHandlers.mouseover, options);
69
+
70
+ this._target.addEventListener('mouseleave', this._eventHandlers.mouseleave, options);
71
+
72
+ this._target.addEventListener('mousemove', this._eventHandlers.mousemove, options);
73
+
74
+ this._target.addEventListener('mouseup', this._eventHandlers.mouseup, options);
75
+ }
76
+
77
+ this.clear();
78
+ }
79
+ }, {
80
+ key: "detach",
81
+ value: function detach() {
82
+ if (!this._target) {
83
+ return;
84
+ }
85
+
86
+ if (useFallback) {
87
+ var options = {
88
+ capture: true,
89
+ passive: true
90
+ };
91
+
92
+ this._target.removeEventListener('mouseover', this._eventHandlers.mouseover, options);
93
+
94
+ this._target.removeEventListener('mouseleave', this._eventHandlers.mouseleave, options);
95
+
96
+ this._target.removeEventListener('mousemove', this._eventHandlers.mousemove, options);
97
+
98
+ this._target.removeEventListener('mouseup', this._eventHandlers.mouseup, options);
99
+
100
+ document.body.removeChild(this._canvas);
101
+ }
102
+
103
+ this._target = null;
104
+ }
105
+ }, {
106
+ key: "change",
107
+ value: function change(rgba, hotx, hoty, w, h) {
108
+ if (w === 0 || h === 0) {
109
+ this.clear();
110
+ return;
111
+ }
112
+
113
+ this._position.x = this._position.x + this._hotSpot.x - hotx;
114
+ this._position.y = this._position.y + this._hotSpot.y - hoty;
115
+ this._hotSpot.x = hotx;
116
+ this._hotSpot.y = hoty;
117
+
118
+ var ctx = this._canvas.getContext('2d');
119
+
120
+ this._canvas.width = w;
121
+ this._canvas.height = h;
122
+ var img;
123
+
124
+ try {
125
+ // IE doesn't support this
126
+ img = new ImageData(new Uint8ClampedArray(rgba), w, h);
127
+ } catch (ex) {
128
+ img = ctx.createImageData(w, h);
129
+ img.data.set(new Uint8ClampedArray(rgba));
130
+ }
131
+
132
+ ctx.clearRect(0, 0, w, h);
133
+ ctx.putImageData(img, 0, 0);
134
+
135
+ if (useFallback) {
136
+ this._updatePosition();
137
+ } else {
138
+ var url = this._canvas.toDataURL();
139
+
140
+ this._target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
141
+ }
142
+ }
143
+ }, {
144
+ key: "clear",
145
+ value: function clear() {
146
+ this._target.style.cursor = 'none';
147
+ this._canvas.width = 0;
148
+ this._canvas.height = 0;
149
+ this._position.x = this._position.x + this._hotSpot.x;
150
+ this._position.y = this._position.y + this._hotSpot.y;
151
+ this._hotSpot.x = 0;
152
+ this._hotSpot.y = 0;
153
+ } // Mouse events might be emulated, this allows
154
+ // moving the cursor in such cases
155
+
156
+ }, {
157
+ key: "move",
158
+ value: function move(clientX, clientY) {
159
+ if (!useFallback) {
160
+ return;
161
+ } // clientX/clientY are relative the _visual viewport_,
162
+ // but our position is relative the _layout viewport_,
163
+ // so try to compensate when we can
164
+
165
+
166
+ if (window.visualViewport) {
167
+ this._position.x = clientX + window.visualViewport.offsetLeft;
168
+ this._position.y = clientY + window.visualViewport.offsetTop;
169
+ } else {
170
+ this._position.x = clientX;
171
+ this._position.y = clientY;
172
+ }
173
+
174
+ this._updatePosition();
175
+
176
+ var target = document.elementFromPoint(clientX, clientY);
177
+
178
+ this._updateVisibility(target);
179
+ }
180
+ }, {
181
+ key: "_handleMouseOver",
182
+ value: function _handleMouseOver(event) {
183
+ // This event could be because we're entering the target, or
184
+ // moving around amongst its sub elements. Let the move handler
185
+ // sort things out.
186
+ this._handleMouseMove(event);
187
+ }
188
+ }, {
189
+ key: "_handleMouseLeave",
190
+ value: function _handleMouseLeave(event) {
191
+ // Check if we should show the cursor on the element we are leaving to
192
+ this._updateVisibility(event.relatedTarget);
193
+ }
194
+ }, {
195
+ key: "_handleMouseMove",
196
+ value: function _handleMouseMove(event) {
197
+ this._updateVisibility(event.target);
198
+
199
+ this._position.x = event.clientX - this._hotSpot.x;
200
+ this._position.y = event.clientY - this._hotSpot.y;
201
+
202
+ this._updatePosition();
203
+ }
204
+ }, {
205
+ key: "_handleMouseUp",
206
+ value: function _handleMouseUp(event) {
207
+ var _this = this;
208
+
209
+ // We might get this event because of a drag operation that
210
+ // moved outside of the target. Check what's under the cursor
211
+ // now and adjust visibility based on that.
212
+ var target = document.elementFromPoint(event.clientX, event.clientY);
213
+
214
+ this._updateVisibility(target); // Captures end with a mouseup but we can't know the event order of
215
+ // mouseup vs releaseCapture.
216
+ //
217
+ // In the cases when releaseCapture comes first, the code above is
218
+ // enough.
219
+ //
220
+ // In the cases when the mouseup comes first, we need wait for the
221
+ // browser to flush all events and then check again if the cursor
222
+ // should be visible.
223
+
224
+
225
+ if (this._captureIsActive()) {
226
+ window.setTimeout(function () {
227
+ // We might have detached at this point
228
+ if (!_this._target) {
229
+ return;
230
+ } // Refresh the target from elementFromPoint since queued events
231
+ // might have altered the DOM
232
+
233
+
234
+ target = document.elementFromPoint(event.clientX, event.clientY);
235
+
236
+ _this._updateVisibility(target);
237
+ }, 0);
238
+ }
239
+ }
240
+ }, {
241
+ key: "_showCursor",
242
+ value: function _showCursor() {
243
+ if (this._canvas.style.visibility === 'hidden') {
244
+ this._canvas.style.visibility = '';
245
+ }
246
+ }
247
+ }, {
248
+ key: "_hideCursor",
249
+ value: function _hideCursor() {
250
+ if (this._canvas.style.visibility !== 'hidden') {
251
+ this._canvas.style.visibility = 'hidden';
252
+ }
253
+ } // Should we currently display the cursor?
254
+ // (i.e. are we over the target, or a child of the target without a
255
+ // different cursor set)
256
+
257
+ }, {
258
+ key: "_shouldShowCursor",
259
+ value: function _shouldShowCursor(target) {
260
+ if (!target) {
261
+ return false;
262
+ } // Easy case
263
+
264
+
265
+ if (target === this._target) {
266
+ return true;
267
+ } // Other part of the DOM?
268
+
269
+
270
+ if (!this._target.contains(target)) {
271
+ return false;
272
+ } // Has the child its own cursor?
273
+ // FIXME: How can we tell that a sub element has an
274
+ // explicit "cursor: none;"?
275
+
276
+
277
+ if (window.getComputedStyle(target).cursor !== 'none') {
278
+ return false;
279
+ }
280
+
281
+ return true;
282
+ }
283
+ }, {
284
+ key: "_updateVisibility",
285
+ value: function _updateVisibility(target) {
286
+ // When the cursor target has capture we want to show the cursor.
287
+ // So, if a capture is active - look at the captured element instead.
288
+ if (this._captureIsActive()) {
289
+ target = document.captureElement;
290
+ }
291
+
292
+ if (this._shouldShowCursor(target)) {
293
+ this._showCursor();
294
+ } else {
295
+ this._hideCursor();
296
+ }
297
+ }
298
+ }, {
299
+ key: "_updatePosition",
300
+ value: function _updatePosition() {
301
+ this._canvas.style.left = this._position.x + "px";
302
+ this._canvas.style.top = this._position.y + "px";
303
+ }
304
+ }, {
305
+ key: "_captureIsActive",
306
+ value: function _captureIsActive() {
307
+ return document.captureElement && document.documentElement.contains(document.captureElement);
308
+ }
309
+ }]);
310
+
311
+ return Cursor;
312
+ }();
313
+
314
+ exports.default = Cursor;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clientToElement = clientToElement;
7
+
8
+ /*
9
+ * noVNC: HTML5 VNC client
10
+ * Copyright (C) 2020 The noVNC Authors
11
+ * Licensed under MPL 2.0 (see LICENSE.txt)
12
+ *
13
+ * See README.md for usage and integration instructions.
14
+ */
15
+
16
+ /*
17
+ * HTML element utility functions
18
+ */
19
+ function clientToElement(x, y, elem) {
20
+ var bounds = elem.getBoundingClientRect();
21
+ var pos = {
22
+ x: 0,
23
+ y: 0
24
+ }; // Clip to target bounds
25
+
26
+ if (x < bounds.left) {
27
+ pos.x = 0;
28
+ } else if (x >= bounds.right) {
29
+ pos.x = bounds.width - 1;
30
+ } else {
31
+ pos.x = x - bounds.left;
32
+ }
33
+
34
+ if (y < bounds.top) {
35
+ pos.y = 0;
36
+ } else if (y >= bounds.bottom) {
37
+ pos.y = bounds.height - 1;
38
+ } else {
39
+ pos.y = y - bounds.top;
40
+ }
41
+
42
+ return pos;
43
+ }
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPointerEvent = getPointerEvent;
7
+ exports.stopEvent = stopEvent;
8
+ exports.setCapture = setCapture;
9
+ exports.releaseCapture = releaseCapture;
10
+
11
+ /*
12
+ * noVNC: HTML5 VNC client
13
+ * Copyright (C) 2018 The noVNC Authors
14
+ * Licensed under MPL 2.0 (see LICENSE.txt)
15
+ *
16
+ * See README.md for usage and integration instructions.
17
+ */
18
+
19
+ /*
20
+ * Cross-browser event and position routines
21
+ */
22
+ function getPointerEvent(e) {
23
+ return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
24
+ }
25
+
26
+ function stopEvent(e) {
27
+ e.stopPropagation();
28
+ e.preventDefault();
29
+ } // Emulate Element.setCapture() when not supported
30
+
31
+
32
+ var _captureRecursion = false;
33
+ var _elementForUnflushedEvents = null;
34
+ document.captureElement = null;
35
+
36
+ function _captureProxy(e) {
37
+ // Recursion protection as we'll see our own event
38
+ if (_captureRecursion) return; // Clone the event as we cannot dispatch an already dispatched event
39
+
40
+ var newEv = new e.constructor(e.type, e);
41
+ _captureRecursion = true;
42
+
43
+ if (document.captureElement) {
44
+ document.captureElement.dispatchEvent(newEv);
45
+ } else {
46
+ _elementForUnflushedEvents.dispatchEvent(newEv);
47
+ }
48
+
49
+ _captureRecursion = false; // Avoid double events
50
+
51
+ e.stopPropagation(); // Respect the wishes of the redirected event handlers
52
+
53
+ if (newEv.defaultPrevented) {
54
+ e.preventDefault();
55
+ } // Implicitly release the capture on button release
56
+
57
+
58
+ if (e.type === "mouseup") {
59
+ releaseCapture();
60
+ }
61
+ } // Follow cursor style of target element
62
+
63
+
64
+ function _capturedElemChanged() {
65
+ var proxyElem = document.getElementById("noVNC_mouse_capture_elem");
66
+ proxyElem.style.cursor = window.getComputedStyle(document.captureElement).cursor;
67
+ }
68
+
69
+ var _captureObserver = new MutationObserver(_capturedElemChanged);
70
+
71
+ function setCapture(target) {
72
+ if (target.setCapture) {
73
+ target.setCapture();
74
+ document.captureElement = target; // IE releases capture on 'click' events which might not trigger
75
+
76
+ target.addEventListener('mouseup', releaseCapture);
77
+ } else {
78
+ // Release any existing capture in case this method is
79
+ // called multiple times without coordination
80
+ releaseCapture();
81
+ var proxyElem = document.getElementById("noVNC_mouse_capture_elem");
82
+
83
+ if (proxyElem === null) {
84
+ proxyElem = document.createElement("div");
85
+ proxyElem.id = "noVNC_mouse_capture_elem";
86
+ proxyElem.style.position = "fixed";
87
+ proxyElem.style.top = "0px";
88
+ proxyElem.style.left = "0px";
89
+ proxyElem.style.width = "100%";
90
+ proxyElem.style.height = "100%";
91
+ proxyElem.style.zIndex = 10000;
92
+ proxyElem.style.display = "none";
93
+ document.body.appendChild(proxyElem); // This is to make sure callers don't get confused by having
94
+ // our blocking element as the target
95
+
96
+ proxyElem.addEventListener('contextmenu', _captureProxy);
97
+ proxyElem.addEventListener('mousemove', _captureProxy);
98
+ proxyElem.addEventListener('mouseup', _captureProxy);
99
+ }
100
+
101
+ document.captureElement = target; // Track cursor and get initial cursor
102
+
103
+ _captureObserver.observe(target, {
104
+ attributes: true
105
+ });
106
+
107
+ _capturedElemChanged();
108
+
109
+ proxyElem.style.display = ""; // We listen to events on window in order to keep tracking if it
110
+ // happens to leave the viewport
111
+
112
+ window.addEventListener('mousemove', _captureProxy);
113
+ window.addEventListener('mouseup', _captureProxy);
114
+ }
115
+ }
116
+
117
+ function releaseCapture() {
118
+ if (document.releaseCapture) {
119
+ document.releaseCapture();
120
+ document.captureElement = null;
121
+ } else {
122
+ if (!document.captureElement) {
123
+ return;
124
+ } // There might be events already queued. The event proxy needs
125
+ // access to the captured element for these queued events.
126
+ // E.g. contextmenu (right-click) in Microsoft Edge
127
+ //
128
+ // Before removing the capturedElem pointer we save it to a
129
+ // temporary variable that the unflushed events can use.
130
+
131
+
132
+ _elementForUnflushedEvents = document.captureElement;
133
+ document.captureElement = null;
134
+
135
+ _captureObserver.disconnect();
136
+
137
+ var proxyElem = document.getElementById("noVNC_mouse_capture_elem");
138
+ proxyElem.style.display = "none";
139
+ window.removeEventListener('mousemove', _captureProxy);
140
+ window.removeEventListener('mouseup', _captureProxy);
141
+ }
142
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
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
+
14
+ /*
15
+ * noVNC: HTML5 VNC client
16
+ * Copyright (C) 2019 The noVNC Authors
17
+ * Licensed under MPL 2.0 (see LICENSE.txt)
18
+ *
19
+ * See README.md for usage and integration instructions.
20
+ */
21
+ var EventTargetMixin = /*#__PURE__*/function () {
22
+ function EventTargetMixin() {
23
+ _classCallCheck(this, EventTargetMixin);
24
+
25
+ this._listeners = new Map();
26
+ }
27
+
28
+ _createClass(EventTargetMixin, [{
29
+ key: "addEventListener",
30
+ value: function addEventListener(type, callback) {
31
+ if (!this._listeners.has(type)) {
32
+ this._listeners.set(type, new Set());
33
+ }
34
+
35
+ this._listeners.get(type).add(callback);
36
+ }
37
+ }, {
38
+ key: "removeEventListener",
39
+ value: function removeEventListener(type, callback) {
40
+ if (this._listeners.has(type)) {
41
+ this._listeners.get(type).delete(callback);
42
+ }
43
+ }
44
+ }, {
45
+ key: "dispatchEvent",
46
+ value: function dispatchEvent(event) {
47
+ var _this = this;
48
+
49
+ if (!this._listeners.has(event.type)) {
50
+ return true;
51
+ }
52
+
53
+ this._listeners.get(event.type).forEach(function (callback) {
54
+ return callback.call(_this, event);
55
+ });
56
+
57
+ return !event.defaultPrevented;
58
+ }
59
+ }]);
60
+
61
+ return EventTargetMixin;
62
+ }();
63
+
64
+ exports.default = EventTargetMixin;