@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) 2019 The noVNC Authors
@@ -22,10 +21,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
22
21
  var RREDecoder = /*#__PURE__*/function () {
23
22
  function RREDecoder() {
24
23
  _classCallCheck(this, RREDecoder);
25
-
26
24
  this._subrects = 0;
27
25
  }
28
-
29
26
  _createClass(RREDecoder, [{
30
27
  key: "decodeRect",
31
28
  value: function decodeRect(x, y, width, height, sock, display, depth) {
@@ -33,20 +30,15 @@ var RREDecoder = /*#__PURE__*/function () {
33
30
  if (sock.rQwait("RRE", 4 + 4)) {
34
31
  return false;
35
32
  }
36
-
37
33
  this._subrects = sock.rQshift32();
38
34
  var color = sock.rQshiftBytes(4); // Background
39
-
40
35
  display.fillRect(x, y, width, height, color);
41
36
  }
42
-
43
37
  while (this._subrects > 0) {
44
38
  if (sock.rQwait("RRE", 4 + 8)) {
45
39
  return false;
46
40
  }
47
-
48
41
  var _color = sock.rQshiftBytes(4);
49
-
50
42
  var sx = sock.rQshift16();
51
43
  var sy = sock.rQshift16();
52
44
  var swidth = sock.rQshift16();
@@ -54,12 +46,9 @@ var RREDecoder = /*#__PURE__*/function () {
54
46
  display.fillRect(x + sx, y + sy, swidth, sheight, _color);
55
47
  this._subrects--;
56
48
  }
57
-
58
49
  return true;
59
50
  }
60
51
  }]);
61
-
62
52
  return RREDecoder;
63
53
  }();
64
-
65
54
  exports["default"] = RREDecoder;
@@ -1,45 +1,33 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports["default"] = void 0;
9
-
10
7
  var Log = _interopRequireWildcard(require("../util/logging.js"));
11
-
12
8
  var _inflator = _interopRequireDefault(require("../inflator.js"));
13
-
14
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
19
-
12
+ 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); }
20
13
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
- 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); } }
23
-
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
-
14
+ 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); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
+ 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); }
26
18
  var TightDecoder = /*#__PURE__*/function () {
27
19
  function TightDecoder() {
28
20
  _classCallCheck(this, TightDecoder);
29
-
30
21
  this._ctl = null;
31
22
  this._filter = null;
32
23
  this._numColors = 0;
33
24
  this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
34
-
35
25
  this._len = 0;
36
26
  this._zlibs = [];
37
-
38
27
  for (var i = 0; i < 4; i++) {
39
28
  this._zlibs[i] = new _inflator["default"]();
40
29
  }
41
30
  }
42
-
43
31
  _createClass(TightDecoder, [{
44
32
  key: "decodeRect",
45
33
  value: function decodeRect(x, y, width, height, sock, display, depth) {
@@ -47,23 +35,20 @@ var TightDecoder = /*#__PURE__*/function () {
47
35
  if (sock.rQwait("TIGHT compression-control", 1)) {
48
36
  return false;
49
37
  }
38
+ this._ctl = sock.rQshift8();
50
39
 
51
- this._ctl = sock.rQshift8(); // Reset streams if the server requests it
52
-
40
+ // Reset streams if the server requests it
53
41
  for (var i = 0; i < 4; i++) {
54
42
  if (this._ctl >> i & 1) {
55
43
  this._zlibs[i].reset();
56
-
57
44
  Log.Info("Reset zlib stream " + i);
58
45
  }
59
- } // Figure out filter
60
-
46
+ }
61
47
 
48
+ // Figure out filter
62
49
  this._ctl = this._ctl >> 4;
63
50
  }
64
-
65
51
  var ret;
66
-
67
52
  if (this._ctl === 0x08) {
68
53
  ret = this._fillRect(x, y, width, height, sock, display, depth);
69
54
  } else if (this._ctl === 0x09) {
@@ -75,11 +60,9 @@ var TightDecoder = /*#__PURE__*/function () {
75
60
  } else {
76
61
  throw new Error("Illegal tight compression received (ctl: " + this._ctl + ")");
77
62
  }
78
-
79
63
  if (ret) {
80
64
  this._ctl = null;
81
65
  }
82
-
83
66
  return ret;
84
67
  }
85
68
  }, {
@@ -88,7 +71,6 @@ var TightDecoder = /*#__PURE__*/function () {
88
71
  if (sock.rQwait("TIGHT", 3)) {
89
72
  return false;
90
73
  }
91
-
92
74
  var rQi = sock.rQi;
93
75
  var rQ = sock.rQ;
94
76
  display.fillRect(x, y, width, height, [rQ[rQi], rQ[rQi + 1], rQ[rQi + 2]], false);
@@ -99,11 +81,9 @@ var TightDecoder = /*#__PURE__*/function () {
99
81
  key: "_jpegRect",
100
82
  value: function _jpegRect(x, y, width, height, sock, display, depth) {
101
83
  var data = this._readData(sock);
102
-
103
84
  if (data === null) {
104
85
  return false;
105
86
  }
106
-
107
87
  display.imageRect(x, y, width, height, "image/jpeg", data);
108
88
  return true;
109
89
  }
@@ -120,41 +100,33 @@ var TightDecoder = /*#__PURE__*/function () {
120
100
  if (sock.rQwait("TIGHT", 1)) {
121
101
  return false;
122
102
  }
123
-
124
103
  this._filter = sock.rQshift8();
125
104
  } else {
126
105
  // Implicit CopyFilter
127
106
  this._filter = 0;
128
107
  }
129
108
  }
130
-
131
109
  var streamId = ctl & 0x3;
132
110
  var ret;
133
-
134
111
  switch (this._filter) {
135
112
  case 0:
136
113
  // CopyFilter
137
114
  ret = this._copyFilter(streamId, x, y, width, height, sock, display, depth);
138
115
  break;
139
-
140
116
  case 1:
141
117
  // PaletteFilter
142
118
  ret = this._paletteFilter(streamId, x, y, width, height, sock, display, depth);
143
119
  break;
144
-
145
120
  case 2:
146
121
  // GradientFilter
147
122
  ret = this._gradientFilter(streamId, x, y, width, height, sock, display, depth);
148
123
  break;
149
-
150
124
  default:
151
125
  throw new Error("Illegal tight filter received (ctl: " + this._filter + ")");
152
126
  }
153
-
154
127
  if (ret) {
155
128
  this._filter = null;
156
129
  }
157
-
158
130
  return ret;
159
131
  }
160
132
  }, {
@@ -162,33 +134,24 @@ var TightDecoder = /*#__PURE__*/function () {
162
134
  value: function _copyFilter(streamId, x, y, width, height, sock, display, depth) {
163
135
  var uncompressedSize = width * height * 3;
164
136
  var data;
165
-
166
137
  if (uncompressedSize === 0) {
167
138
  return true;
168
139
  }
169
-
170
140
  if (uncompressedSize < 12) {
171
141
  if (sock.rQwait("TIGHT", uncompressedSize)) {
172
142
  return false;
173
143
  }
174
-
175
144
  data = sock.rQshiftBytes(uncompressedSize);
176
145
  } else {
177
146
  data = this._readData(sock);
178
-
179
147
  if (data === null) {
180
148
  return false;
181
149
  }
182
-
183
150
  this._zlibs[streamId].setInput(data);
184
-
185
151
  data = this._zlibs[streamId].inflate(uncompressedSize);
186
-
187
152
  this._zlibs[streamId].setInput(null);
188
153
  }
189
-
190
154
  var rgbx = new Uint8Array(width * height * 4);
191
-
192
155
  for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
193
156
  rgbx[i] = data[j];
194
157
  rgbx[i + 1] = data[j + 1];
@@ -206,55 +169,43 @@ var TightDecoder = /*#__PURE__*/function () {
206
169
  if (sock.rQwait("TIGHT palette", 1)) {
207
170
  return false;
208
171
  }
209
-
210
172
  var numColors = sock.rQpeek8() + 1;
211
173
  var paletteSize = numColors * 3;
212
-
213
174
  if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
214
175
  return false;
215
176
  }
216
-
217
177
  this._numColors = numColors;
218
178
  sock.rQskipBytes(1);
219
179
  sock.rQshiftTo(this._palette, paletteSize);
220
180
  }
221
-
222
181
  var bpp = this._numColors <= 2 ? 1 : 8;
223
182
  var rowSize = Math.floor((width * bpp + 7) / 8);
224
183
  var uncompressedSize = rowSize * height;
225
184
  var data;
226
-
227
185
  if (uncompressedSize === 0) {
228
186
  return true;
229
187
  }
230
-
231
188
  if (uncompressedSize < 12) {
232
189
  if (sock.rQwait("TIGHT", uncompressedSize)) {
233
190
  return false;
234
191
  }
235
-
236
192
  data = sock.rQshiftBytes(uncompressedSize);
237
193
  } else {
238
194
  data = this._readData(sock);
239
-
240
195
  if (data === null) {
241
196
  return false;
242
197
  }
243
-
244
198
  this._zlibs[streamId].setInput(data);
245
-
246
199
  data = this._zlibs[streamId].inflate(uncompressedSize);
247
-
248
200
  this._zlibs[streamId].setInput(null);
249
- } // Convert indexed (palette based) image data to RGB
250
-
201
+ }
251
202
 
203
+ // Convert indexed (palette based) image data to RGB
252
204
  if (this._numColors == 2) {
253
205
  this._monoRect(x, y, width, height, data, this._palette, display);
254
206
  } else {
255
207
  this._paletteRect(x, y, width, height, data, this._palette, display);
256
208
  }
257
-
258
209
  this._numColors = 0;
259
210
  return true;
260
211
  }
@@ -264,15 +215,12 @@ var TightDecoder = /*#__PURE__*/function () {
264
215
  // Convert indexed (palette based) image data to RGB
265
216
  // TODO: reduce number of calculations inside loop
266
217
  var dest = this._getScratchBuffer(width * height * 4);
267
-
268
218
  var w = Math.floor((width + 7) / 8);
269
219
  var w1 = Math.floor(width / 8);
270
-
271
220
  for (var _y = 0; _y < height; _y++) {
272
221
  var dp = void 0,
273
- sp = void 0,
274
- _x = void 0;
275
-
222
+ sp = void 0,
223
+ _x = void 0;
276
224
  for (_x = 0; _x < w1; _x++) {
277
225
  for (var b = 7; b >= 0; b--) {
278
226
  dp = (_y * width + _x * 8 + 7 - b) * 4;
@@ -283,7 +231,6 @@ var TightDecoder = /*#__PURE__*/function () {
283
231
  dest[dp + 3] = 255;
284
232
  }
285
233
  }
286
-
287
234
  for (var _b = 7; _b >= 8 - width % 8; _b--) {
288
235
  dp = (_y * width + _x * 8 + 7 - _b) * 4;
289
236
  sp = (data[_y * w + _x] >> _b & 1) * 3;
@@ -293,7 +240,6 @@ var TightDecoder = /*#__PURE__*/function () {
293
240
  dest[dp + 3] = 255;
294
241
  }
295
242
  }
296
-
297
243
  display.blitImage(x, y, width, height, dest, 0, false);
298
244
  }
299
245
  }, {
@@ -301,9 +247,7 @@ var TightDecoder = /*#__PURE__*/function () {
301
247
  value: function _paletteRect(x, y, width, height, data, palette, display) {
302
248
  // Convert indexed (palette based) image data to RGB
303
249
  var dest = this._getScratchBuffer(width * height * 4);
304
-
305
250
  var total = width * height * 4;
306
-
307
251
  for (var i = 0, j = 0; i < total; i += 4, j++) {
308
252
  var sp = data[j] * 3;
309
253
  dest[i] = palette[sp];
@@ -311,7 +255,6 @@ var TightDecoder = /*#__PURE__*/function () {
311
255
  dest[i + 2] = palette[sp + 2];
312
256
  dest[i + 3] = 255;
313
257
  }
314
-
315
258
  display.blitImage(x, y, width, height, dest, 0, false);
316
259
  }
317
260
  }, {
@@ -326,27 +269,21 @@ var TightDecoder = /*#__PURE__*/function () {
326
269
  if (sock.rQwait("TIGHT", 3)) {
327
270
  return null;
328
271
  }
329
-
330
272
  var _byte;
331
-
332
273
  _byte = sock.rQshift8();
333
274
  this._len = _byte & 0x7f;
334
-
335
275
  if (_byte & 0x80) {
336
276
  _byte = sock.rQshift8();
337
277
  this._len |= (_byte & 0x7f) << 7;
338
-
339
278
  if (_byte & 0x80) {
340
279
  _byte = sock.rQshift8();
341
280
  this._len |= _byte << 14;
342
281
  }
343
282
  }
344
283
  }
345
-
346
284
  if (sock.rQwait("TIGHT", this._len)) {
347
285
  return null;
348
286
  }
349
-
350
287
  var data = sock.rQshiftBytes(this._len);
351
288
  this._len = 0;
352
289
  return data;
@@ -357,12 +294,9 @@ var TightDecoder = /*#__PURE__*/function () {
357
294
  if (!this._scratchBuffer || this._scratchBuffer.length < size) {
358
295
  this._scratchBuffer = new Uint8Array(size);
359
296
  }
360
-
361
297
  return this._scratchBuffer;
362
298
  }
363
299
  }]);
364
-
365
300
  return TightDecoder;
366
301
  }();
367
-
368
302
  exports["default"] = TightDecoder;
@@ -1,56 +1,38 @@
1
1
  "use strict";
2
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
-
3
+ 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); }
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _tight = _interopRequireDefault(require("./tight.js"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
-
16
- 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); } }
17
-
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
-
20
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
21
-
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
-
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
15
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
24
17
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
25
-
26
18
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
27
-
28
19
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
-
30
20
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
31
-
32
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
-
21
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
34
22
  var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
35
23
  _inherits(TightPNGDecoder, _TightDecoder);
36
-
37
24
  var _super = _createSuper(TightPNGDecoder);
38
-
39
25
  function TightPNGDecoder() {
40
26
  _classCallCheck(this, TightPNGDecoder);
41
-
42
27
  return _super.apply(this, arguments);
43
28
  }
44
-
45
29
  _createClass(TightPNGDecoder, [{
46
30
  key: "_pngRect",
47
31
  value: function _pngRect(x, y, width, height, sock, display, depth) {
48
32
  var data = this._readData(sock);
49
-
50
33
  if (data === null) {
51
34
  return false;
52
35
  }
53
-
54
36
  display.imageRect(x, y, width, height, "image/png", data);
55
37
  return true;
56
38
  }
@@ -60,8 +42,6 @@ var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) {
60
42
  throw new Error("BasicCompression received in TightPNG rect");
61
43
  }
62
44
  }]);
63
-
64
45
  return TightPNGDecoder;
65
46
  }(_tight["default"]);
66
-
67
47
  exports["default"] = TightPNGDecoder;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _inflator = _interopRequireDefault(require("../inflator.js"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ 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); }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
15
+ var ZRLE_TILE_WIDTH = 64;
16
+ var ZRLE_TILE_HEIGHT = 64;
17
+ var ZRLEDecoder = /*#__PURE__*/function () {
18
+ function ZRLEDecoder() {
19
+ _classCallCheck(this, ZRLEDecoder);
20
+ this._length = 0;
21
+ this._inflator = new _inflator["default"]();
22
+ this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
23
+ this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
24
+ }
25
+ _createClass(ZRLEDecoder, [{
26
+ key: "decodeRect",
27
+ value: function decodeRect(x, y, width, height, sock, display, depth) {
28
+ if (this._length === 0) {
29
+ if (sock.rQwait("ZLib data length", 4)) {
30
+ return false;
31
+ }
32
+ this._length = sock.rQshift32();
33
+ }
34
+ if (sock.rQwait("Zlib data", this._length)) {
35
+ return false;
36
+ }
37
+ var data = sock.rQshiftBytes(this._length);
38
+ this._inflator.setInput(data);
39
+ for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
40
+ var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
41
+ for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
42
+ var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
43
+ var tileSize = tw * th;
44
+ var subencoding = this._inflator.inflate(1)[0];
45
+ if (subencoding === 0) {
46
+ // raw data
47
+ var _data = this._readPixels(tileSize);
48
+ display.blitImage(tx, ty, tw, th, _data, 0, false);
49
+ } else if (subencoding === 1) {
50
+ // solid
51
+ var background = this._readPixels(1);
52
+ display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
53
+ } else if (subencoding >= 2 && subencoding <= 16) {
54
+ var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);
55
+ display.blitImage(tx, ty, tw, th, _data2, 0, false);
56
+ } else if (subencoding === 128) {
57
+ var _data3 = this._decodeRLETile(tileSize);
58
+ display.blitImage(tx, ty, tw, th, _data3, 0, false);
59
+ } else if (subencoding >= 130 && subencoding <= 255) {
60
+ var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
61
+ display.blitImage(tx, ty, tw, th, _data4, 0, false);
62
+ } else {
63
+ throw new Error('Unknown subencoding: ' + subencoding);
64
+ }
65
+ }
66
+ }
67
+ this._length = 0;
68
+ return true;
69
+ }
70
+ }, {
71
+ key: "_getBitsPerPixelInPalette",
72
+ value: function _getBitsPerPixelInPalette(paletteSize) {
73
+ if (paletteSize <= 2) {
74
+ return 1;
75
+ } else if (paletteSize <= 4) {
76
+ return 2;
77
+ } else if (paletteSize <= 16) {
78
+ return 4;
79
+ }
80
+ }
81
+ }, {
82
+ key: "_readPixels",
83
+ value: function _readPixels(pixels) {
84
+ var data = this._pixelBuffer;
85
+ var buffer = this._inflator.inflate(3 * pixels);
86
+ for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) {
87
+ data[i] = buffer[j];
88
+ data[i + 1] = buffer[j + 1];
89
+ data[i + 2] = buffer[j + 2];
90
+ data[i + 3] = 255; // Add the Alpha
91
+ }
92
+
93
+ return data;
94
+ }
95
+ }, {
96
+ key: "_decodePaletteTile",
97
+ value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
98
+ var data = this._tileBuffer;
99
+ var palette = this._readPixels(paletteSize);
100
+ var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
101
+ var mask = (1 << bitsPerPixel) - 1;
102
+ var offset = 0;
103
+ var encoded = this._inflator.inflate(1)[0];
104
+ for (var y = 0; y < tileh; y++) {
105
+ var shift = 8 - bitsPerPixel;
106
+ for (var x = 0; x < tilew; x++) {
107
+ if (shift < 0) {
108
+ shift = 8 - bitsPerPixel;
109
+ encoded = this._inflator.inflate(1)[0];
110
+ }
111
+ var indexInPalette = encoded >> shift & mask;
112
+ data[offset] = palette[indexInPalette * 4];
113
+ data[offset + 1] = palette[indexInPalette * 4 + 1];
114
+ data[offset + 2] = palette[indexInPalette * 4 + 2];
115
+ data[offset + 3] = palette[indexInPalette * 4 + 3];
116
+ offset += 4;
117
+ shift -= bitsPerPixel;
118
+ }
119
+ if (shift < 8 - bitsPerPixel && y < tileh - 1) {
120
+ encoded = this._inflator.inflate(1)[0];
121
+ }
122
+ }
123
+ return data;
124
+ }
125
+ }, {
126
+ key: "_decodeRLETile",
127
+ value: function _decodeRLETile(tileSize) {
128
+ var data = this._tileBuffer;
129
+ var i = 0;
130
+ while (i < tileSize) {
131
+ var pixel = this._readPixels(1);
132
+ var length = this._readRLELength();
133
+ for (var j = 0; j < length; j++) {
134
+ data[i * 4] = pixel[0];
135
+ data[i * 4 + 1] = pixel[1];
136
+ data[i * 4 + 2] = pixel[2];
137
+ data[i * 4 + 3] = pixel[3];
138
+ i++;
139
+ }
140
+ }
141
+ return data;
142
+ }
143
+ }, {
144
+ key: "_decodeRLEPaletteTile",
145
+ value: function _decodeRLEPaletteTile(paletteSize, tileSize) {
146
+ var data = this._tileBuffer;
147
+
148
+ // palette
149
+ var palette = this._readPixels(paletteSize);
150
+ var offset = 0;
151
+ while (offset < tileSize) {
152
+ var indexInPalette = this._inflator.inflate(1)[0];
153
+ var length = 1;
154
+ if (indexInPalette >= 128) {
155
+ indexInPalette -= 128;
156
+ length = this._readRLELength();
157
+ }
158
+ if (indexInPalette > paletteSize) {
159
+ throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
160
+ }
161
+ if (offset + length > tileSize) {
162
+ throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
163
+ }
164
+ for (var j = 0; j < length; j++) {
165
+ data[offset * 4] = palette[indexInPalette * 4];
166
+ data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
167
+ data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
168
+ data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
169
+ offset++;
170
+ }
171
+ }
172
+ return data;
173
+ }
174
+ }, {
175
+ key: "_readRLELength",
176
+ value: function _readRLELength() {
177
+ var length = 0;
178
+ var current = 0;
179
+ do {
180
+ current = this._inflator.inflate(1)[0];
181
+ length += current;
182
+ } while (current === 255);
183
+ return length + 1;
184
+ }
185
+ }]);
186
+ return ZRLEDecoder;
187
+ }();
188
+ exports["default"] = ZRLEDecoder;