@novnc/novnc 1.2.0-test → 1.3.0-g1075cd8
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 +9 -151
- package/core/encodings.js +4 -0
- package/core/input/domkeytable.js +25 -21
- package/core/input/keyboard.js +12 -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 +332 -114
- 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 +46 -6
- package/docs/LIBRARY.md +3 -7
- package/lib/base64.js +5 -5
- package/lib/decoders/copyrect.js +8 -3
- package/lib/decoders/hextile.js +65 -9
- package/lib/decoders/jpeg.js +188 -0
- package/lib/decoders/raw.js +14 -5
- package/lib/decoders/rre.js +3 -3
- package/lib/decoders/tight.js +40 -22
- package/lib/decoders/tightpng.js +10 -10
- package/lib/decoders/zrle.js +234 -0
- package/lib/deflator.js +5 -5
- package/lib/des.js +3 -3
- package/lib/display.js +47 -214
- package/lib/encodings.js +8 -0
- package/lib/inflator.js +5 -5
- package/lib/input/domkeytable.js +197 -194
- package/lib/input/fixedkeys.js +2 -2
- package/lib/input/gesturehandler.js +3 -3
- package/lib/input/keyboard.js +40 -160
- package/lib/input/keysym.js +2 -2
- package/lib/input/keysymdef.js +2 -2
- package/lib/input/util.js +35 -80
- package/lib/input/vkeys.js +2 -4
- package/lib/input/xtscancodes.js +11 -5
- package/lib/ra2.js +1257 -0
- package/lib/rfb.js +656 -306
- package/lib/util/browser.js +9 -27
- package/lib/util/cursor.js +5 -17
- package/lib/util/events.js +3 -5
- package/lib/util/eventtarget.js +4 -4
- package/lib/util/int.js +1 -1
- package/lib/util/logging.js +2 -2
- package/lib/util/md5.js +103 -0
- package/lib/vendor/pako/lib/utils/common.js +2 -2
- package/lib/vendor/pako/lib/zlib/adler32.js +1 -1
- package/lib/vendor/pako/lib/zlib/constants.js +2 -2
- package/lib/vendor/pako/lib/zlib/crc32.js +1 -1
- package/lib/vendor/pako/lib/zlib/deflate.js +114 -113
- package/lib/vendor/pako/lib/zlib/gzheader.js +1 -1
- package/lib/vendor/pako/lib/zlib/inffast.js +5 -5
- package/lib/vendor/pako/lib/zlib/inflate.js +51 -49
- package/lib/vendor/pako/lib/zlib/inftrees.js +4 -4
- package/lib/vendor/pako/lib/zlib/messages.js +2 -2
- package/lib/vendor/pako/lib/zlib/trees.js +5 -5
- package/lib/vendor/pako/lib/zlib/zstream.js +1 -1
- package/lib/websock.js +107 -46
- 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
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _inflator = _interopRequireDefault(require("../inflator.js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
|
|
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, descriptor.key, descriptor); } }
|
|
15
|
+
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
|
+
|
|
18
|
+
var ZRLE_TILE_WIDTH = 64;
|
|
19
|
+
var ZRLE_TILE_HEIGHT = 64;
|
|
20
|
+
|
|
21
|
+
var ZRLEDecoder = /*#__PURE__*/function () {
|
|
22
|
+
function ZRLEDecoder() {
|
|
23
|
+
_classCallCheck(this, ZRLEDecoder);
|
|
24
|
+
|
|
25
|
+
this._length = 0;
|
|
26
|
+
this._inflator = new _inflator["default"]();
|
|
27
|
+
this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
28
|
+
this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_createClass(ZRLEDecoder, [{
|
|
32
|
+
key: "decodeRect",
|
|
33
|
+
value: function decodeRect(x, y, width, height, sock, display, depth) {
|
|
34
|
+
if (this._length === 0) {
|
|
35
|
+
if (sock.rQwait("ZLib data length", 4)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this._length = sock.rQshift32();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (sock.rQwait("Zlib data", this._length)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var data = sock.rQshiftBytes(this._length);
|
|
47
|
+
|
|
48
|
+
this._inflator.setInput(data);
|
|
49
|
+
|
|
50
|
+
for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
|
|
51
|
+
var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
|
|
52
|
+
|
|
53
|
+
for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
|
|
54
|
+
var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
|
|
55
|
+
var tileSize = tw * th;
|
|
56
|
+
|
|
57
|
+
var subencoding = this._inflator.inflate(1)[0];
|
|
58
|
+
|
|
59
|
+
if (subencoding === 0) {
|
|
60
|
+
// raw data
|
|
61
|
+
var _data = this._readPixels(tileSize);
|
|
62
|
+
|
|
63
|
+
display.blitImage(tx, ty, tw, th, _data, 0, false);
|
|
64
|
+
} else if (subencoding === 1) {
|
|
65
|
+
// solid
|
|
66
|
+
var background = this._readPixels(1);
|
|
67
|
+
|
|
68
|
+
display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
|
|
69
|
+
} else if (subencoding >= 2 && subencoding <= 16) {
|
|
70
|
+
var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th);
|
|
71
|
+
|
|
72
|
+
display.blitImage(tx, ty, tw, th, _data2, 0, false);
|
|
73
|
+
} else if (subencoding === 128) {
|
|
74
|
+
var _data3 = this._decodeRLETile(tileSize);
|
|
75
|
+
|
|
76
|
+
display.blitImage(tx, ty, tw, th, _data3, 0, false);
|
|
77
|
+
} else if (subencoding >= 130 && subencoding <= 255) {
|
|
78
|
+
var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
|
|
79
|
+
|
|
80
|
+
display.blitImage(tx, ty, tw, th, _data4, 0, false);
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error('Unknown subencoding: ' + subencoding);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this._length = 0;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "_getBitsPerPixelInPalette",
|
|
92
|
+
value: function _getBitsPerPixelInPalette(paletteSize) {
|
|
93
|
+
if (paletteSize <= 2) {
|
|
94
|
+
return 1;
|
|
95
|
+
} else if (paletteSize <= 4) {
|
|
96
|
+
return 2;
|
|
97
|
+
} else if (paletteSize <= 16) {
|
|
98
|
+
return 4;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "_readPixels",
|
|
103
|
+
value: function _readPixels(pixels) {
|
|
104
|
+
var data = this._pixelBuffer;
|
|
105
|
+
|
|
106
|
+
var buffer = this._inflator.inflate(3 * pixels);
|
|
107
|
+
|
|
108
|
+
for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) {
|
|
109
|
+
data[i] = buffer[j];
|
|
110
|
+
data[i + 1] = buffer[j + 1];
|
|
111
|
+
data[i + 2] = buffer[j + 2];
|
|
112
|
+
data[i + 3] = 255; // Add the Alpha
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return data;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "_decodePaletteTile",
|
|
119
|
+
value: function _decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
|
|
120
|
+
var data = this._tileBuffer;
|
|
121
|
+
|
|
122
|
+
var palette = this._readPixels(paletteSize);
|
|
123
|
+
|
|
124
|
+
var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
|
|
125
|
+
|
|
126
|
+
var mask = (1 << bitsPerPixel) - 1;
|
|
127
|
+
var offset = 0;
|
|
128
|
+
|
|
129
|
+
var encoded = this._inflator.inflate(1)[0];
|
|
130
|
+
|
|
131
|
+
for (var y = 0; y < tileh; y++) {
|
|
132
|
+
var shift = 8 - bitsPerPixel;
|
|
133
|
+
|
|
134
|
+
for (var x = 0; x < tilew; x++) {
|
|
135
|
+
if (shift < 0) {
|
|
136
|
+
shift = 8 - bitsPerPixel;
|
|
137
|
+
encoded = this._inflator.inflate(1)[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var indexInPalette = encoded >> shift & mask;
|
|
141
|
+
data[offset] = palette[indexInPalette * 4];
|
|
142
|
+
data[offset + 1] = palette[indexInPalette * 4 + 1];
|
|
143
|
+
data[offset + 2] = palette[indexInPalette * 4 + 2];
|
|
144
|
+
data[offset + 3] = palette[indexInPalette * 4 + 3];
|
|
145
|
+
offset += 4;
|
|
146
|
+
shift -= bitsPerPixel;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (shift < 8 - bitsPerPixel && y < tileh - 1) {
|
|
150
|
+
encoded = this._inflator.inflate(1)[0];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "_decodeRLETile",
|
|
158
|
+
value: function _decodeRLETile(tileSize) {
|
|
159
|
+
var data = this._tileBuffer;
|
|
160
|
+
var i = 0;
|
|
161
|
+
|
|
162
|
+
while (i < tileSize) {
|
|
163
|
+
var pixel = this._readPixels(1);
|
|
164
|
+
|
|
165
|
+
var length = this._readRLELength();
|
|
166
|
+
|
|
167
|
+
for (var j = 0; j < length; j++) {
|
|
168
|
+
data[i * 4] = pixel[0];
|
|
169
|
+
data[i * 4 + 1] = pixel[1];
|
|
170
|
+
data[i * 4 + 2] = pixel[2];
|
|
171
|
+
data[i * 4 + 3] = pixel[3];
|
|
172
|
+
i++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "_decodeRLEPaletteTile",
|
|
180
|
+
value: function _decodeRLEPaletteTile(paletteSize, tileSize) {
|
|
181
|
+
var data = this._tileBuffer; // palette
|
|
182
|
+
|
|
183
|
+
var palette = this._readPixels(paletteSize);
|
|
184
|
+
|
|
185
|
+
var offset = 0;
|
|
186
|
+
|
|
187
|
+
while (offset < tileSize) {
|
|
188
|
+
var indexInPalette = this._inflator.inflate(1)[0];
|
|
189
|
+
|
|
190
|
+
var length = 1;
|
|
191
|
+
|
|
192
|
+
if (indexInPalette >= 128) {
|
|
193
|
+
indexInPalette -= 128;
|
|
194
|
+
length = this._readRLELength();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (indexInPalette > paletteSize) {
|
|
198
|
+
throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (offset + length > tileSize) {
|
|
202
|
+
throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (var j = 0; j < length; j++) {
|
|
206
|
+
data[offset * 4] = palette[indexInPalette * 4];
|
|
207
|
+
data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
|
|
208
|
+
data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
|
|
209
|
+
data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
|
|
210
|
+
offset++;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return data;
|
|
215
|
+
}
|
|
216
|
+
}, {
|
|
217
|
+
key: "_readRLELength",
|
|
218
|
+
value: function _readRLELength() {
|
|
219
|
+
var length = 0;
|
|
220
|
+
var current = 0;
|
|
221
|
+
|
|
222
|
+
do {
|
|
223
|
+
current = this._inflator.inflate(1)[0];
|
|
224
|
+
length += current;
|
|
225
|
+
} while (current === 255);
|
|
226
|
+
|
|
227
|
+
return length + 1;
|
|
228
|
+
}
|
|
229
|
+
}]);
|
|
230
|
+
|
|
231
|
+
return ZRLEDecoder;
|
|
232
|
+
}();
|
|
233
|
+
|
|
234
|
+
exports["default"] = ZRLEDecoder;
|
package/lib/deflator.js
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _deflate2 = require("../lib/vendor/pako/lib/zlib/deflate.js");
|
|
9
9
|
|
|
10
10
|
var _zstream = _interopRequireDefault(require("../lib/vendor/pako/lib/zlib/zstream.js"));
|
|
11
11
|
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
15
|
|
|
16
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
17
|
|
|
18
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
19
|
|
|
20
20
|
var Deflator = /*#__PURE__*/function () {
|
|
21
21
|
function Deflator() {
|
|
22
22
|
_classCallCheck(this, Deflator);
|
|
23
23
|
|
|
24
|
-
this.strm = new _zstream
|
|
24
|
+
this.strm = new _zstream["default"]();
|
|
25
25
|
this.chunkSize = 1024 * 10 * 10;
|
|
26
26
|
this.outputBuffer = new Uint8Array(this.chunkSize);
|
|
27
27
|
this.windowBits = 5;
|
|
@@ -96,4 +96,4 @@ var Deflator = /*#__PURE__*/function () {
|
|
|
96
96
|
return Deflator;
|
|
97
97
|
}();
|
|
98
98
|
|
|
99
|
-
exports
|
|
99
|
+
exports["default"] = Deflator;
|
package/lib/des.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
9
|
|
|
10
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
11
|
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
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
13
|
|
|
14
14
|
/*
|
|
15
15
|
* Ported from Flashlight VNC ActionScript implementation:
|
|
@@ -311,4 +311,4 @@ var DES = /*#__PURE__*/function () {
|
|
|
311
311
|
return DES;
|
|
312
312
|
}();
|
|
313
313
|
|
|
314
|
-
exports
|
|
314
|
+
exports["default"] = DES;
|
package/lib/display.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
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); }
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports
|
|
8
|
+
exports["default"] = void 0;
|
|
9
9
|
|
|
10
10
|
var Log = _interopRequireWildcard(require("./util/logging.js"));
|
|
11
11
|
|
|
12
12
|
var _base = _interopRequireDefault(require("./base64.js"));
|
|
13
13
|
|
|
14
|
-
var _browser = require("./util/browser.js");
|
|
15
|
-
|
|
16
14
|
var _int = require("./util/int.js");
|
|
17
15
|
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
17
|
|
|
20
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
18
|
+
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); }
|
|
21
19
|
|
|
22
|
-
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
|
|
20
|
+
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; }
|
|
23
21
|
|
|
24
22
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
23
|
|
|
26
24
|
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); } }
|
|
27
25
|
|
|
28
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
27
|
|
|
30
28
|
var Display = /*#__PURE__*/function () {
|
|
31
29
|
function Display(target) {
|
|
@@ -39,10 +37,6 @@ var Display = /*#__PURE__*/function () {
|
|
|
39
37
|
this._fbWidth = 0;
|
|
40
38
|
this._fbHeight = 0;
|
|
41
39
|
this._prevDrawStyle = "";
|
|
42
|
-
this._tile = null;
|
|
43
|
-
this._tile16x16 = null;
|
|
44
|
-
this._tileX = 0;
|
|
45
|
-
this._tileY = 0;
|
|
46
40
|
Log.Debug(">> Display.constructor"); // The visible canvas
|
|
47
41
|
|
|
48
42
|
this._target = target;
|
|
@@ -76,13 +70,7 @@ var Display = /*#__PURE__*/function () {
|
|
|
76
70
|
right: this._backbuffer.width,
|
|
77
71
|
bottom: this._backbuffer.height
|
|
78
72
|
};
|
|
79
|
-
Log.Debug("User Agent: " + navigator.userAgent);
|
|
80
|
-
|
|
81
|
-
if (!('createImageData' in this._drawCtx)) {
|
|
82
|
-
throw new Error("Canvas does not support createImageData");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this._tile16x16 = this._drawCtx.createImageData(16, 16);
|
|
73
|
+
Log.Debug("User Agent: " + navigator.userAgent);
|
|
86
74
|
Log.Debug("<< Display.constructor"); // ===== PROPERTIES =====
|
|
87
75
|
|
|
88
76
|
this._scale = 1.0;
|
|
@@ -94,8 +82,38 @@ var Display = /*#__PURE__*/function () {
|
|
|
94
82
|
|
|
95
83
|
|
|
96
84
|
_createClass(Display, [{
|
|
85
|
+
key: "scale",
|
|
86
|
+
get: function get() {
|
|
87
|
+
return this._scale;
|
|
88
|
+
},
|
|
89
|
+
set: function set(scale) {
|
|
90
|
+
this._rescale(scale);
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "clipViewport",
|
|
94
|
+
get: function get() {
|
|
95
|
+
return this._clipViewport;
|
|
96
|
+
},
|
|
97
|
+
set: function set(viewport) {
|
|
98
|
+
this._clipViewport = viewport; // May need to readjust the viewport dimensions
|
|
99
|
+
|
|
100
|
+
var vp = this._viewportLoc;
|
|
101
|
+
this.viewportChangeSize(vp.w, vp.h);
|
|
102
|
+
this.viewportChangePos(0, 0);
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "width",
|
|
106
|
+
get: function get() {
|
|
107
|
+
return this._fbWidth;
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "height",
|
|
111
|
+
get: function get() {
|
|
112
|
+
return this._fbHeight;
|
|
113
|
+
} // ===== PUBLIC METHODS =====
|
|
114
|
+
|
|
115
|
+
}, {
|
|
97
116
|
key: "viewportChangePos",
|
|
98
|
-
// ===== PUBLIC METHODS =====
|
|
99
117
|
value: function viewportChangePos(deltaX, deltaY) {
|
|
100
118
|
var vp = this._viewportLoc;
|
|
101
119
|
deltaX = Math.floor(deltaX);
|
|
@@ -371,7 +389,7 @@ var Display = /*#__PURE__*/function () {
|
|
|
371
389
|
}
|
|
372
390
|
|
|
373
391
|
var img = new Image();
|
|
374
|
-
img.src = "data: " + mime + ";base64," + _base
|
|
392
|
+
img.src = "data: " + mime + ";base64," + _base["default"].encode(arr);
|
|
375
393
|
|
|
376
394
|
this._renderQPush({
|
|
377
395
|
'type': 'img',
|
|
@@ -381,61 +399,6 @@ var Display = /*#__PURE__*/function () {
|
|
|
381
399
|
'width': width,
|
|
382
400
|
'height': height
|
|
383
401
|
});
|
|
384
|
-
} // start updating a tile
|
|
385
|
-
|
|
386
|
-
}, {
|
|
387
|
-
key: "startTile",
|
|
388
|
-
value: function startTile(x, y, width, height, color) {
|
|
389
|
-
this._tileX = x;
|
|
390
|
-
this._tileY = y;
|
|
391
|
-
|
|
392
|
-
if (width === 16 && height === 16) {
|
|
393
|
-
this._tile = this._tile16x16;
|
|
394
|
-
} else {
|
|
395
|
-
this._tile = this._drawCtx.createImageData(width, height);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
var red = color[2];
|
|
399
|
-
var green = color[1];
|
|
400
|
-
var blue = color[0];
|
|
401
|
-
var data = this._tile.data;
|
|
402
|
-
|
|
403
|
-
for (var i = 0; i < width * height * 4; i += 4) {
|
|
404
|
-
data[i] = red;
|
|
405
|
-
data[i + 1] = green;
|
|
406
|
-
data[i + 2] = blue;
|
|
407
|
-
data[i + 3] = 255;
|
|
408
|
-
}
|
|
409
|
-
} // update sub-rectangle of the current tile
|
|
410
|
-
|
|
411
|
-
}, {
|
|
412
|
-
key: "subTile",
|
|
413
|
-
value: function subTile(x, y, w, h, color) {
|
|
414
|
-
var red = color[2];
|
|
415
|
-
var green = color[1];
|
|
416
|
-
var blue = color[0];
|
|
417
|
-
var xend = x + w;
|
|
418
|
-
var yend = y + h;
|
|
419
|
-
var data = this._tile.data;
|
|
420
|
-
var width = this._tile.width;
|
|
421
|
-
|
|
422
|
-
for (var j = y; j < yend; j++) {
|
|
423
|
-
for (var i = x; i < xend; i++) {
|
|
424
|
-
var p = (i + j * width) * 4;
|
|
425
|
-
data[p] = red;
|
|
426
|
-
data[p + 1] = green;
|
|
427
|
-
data[p + 2] = blue;
|
|
428
|
-
data[p + 3] = 255;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
} // draw the current tile to the screen
|
|
432
|
-
|
|
433
|
-
}, {
|
|
434
|
-
key: "finishTile",
|
|
435
|
-
value: function finishTile() {
|
|
436
|
-
this._drawCtx.putImageData(this._tile, this._tileX, this._tileY);
|
|
437
|
-
|
|
438
|
-
this._damage(this._tileX, this._tileY, this._tile.width, this._tile.height);
|
|
439
402
|
}
|
|
440
403
|
}, {
|
|
441
404
|
key: "blitImage",
|
|
@@ -456,51 +419,13 @@ var Display = /*#__PURE__*/function () {
|
|
|
456
419
|
'height': height
|
|
457
420
|
});
|
|
458
421
|
} else {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}, {
|
|
463
|
-
key: "blitRgbImage",
|
|
464
|
-
value: function blitRgbImage(x, y, width, height, arr, offset, fromQueue) {
|
|
465
|
-
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
466
|
-
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
467
|
-
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
468
|
-
// this probably isn't getting called *nearly* as much
|
|
469
|
-
var newArr = new Uint8Array(width * height * 3);
|
|
470
|
-
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
422
|
+
// NB(directxman12): arr must be an Type Array view
|
|
423
|
+
var data = new Uint8ClampedArray(arr.buffer, arr.byteOffset + offset, width * height * 4);
|
|
424
|
+
var img = new ImageData(data, width, height);
|
|
471
425
|
|
|
472
|
-
this.
|
|
473
|
-
'type': 'blitRgb',
|
|
474
|
-
'data': newArr,
|
|
475
|
-
'x': x,
|
|
476
|
-
'y': y,
|
|
477
|
-
'width': width,
|
|
478
|
-
'height': height
|
|
479
|
-
});
|
|
480
|
-
} else {
|
|
481
|
-
this._rgbImageData(x, y, width, height, arr, offset);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}, {
|
|
485
|
-
key: "blitRgbxImage",
|
|
486
|
-
value: function blitRgbxImage(x, y, width, height, arr, offset, fromQueue) {
|
|
487
|
-
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
488
|
-
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
489
|
-
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
490
|
-
// this probably isn't getting called *nearly* as much
|
|
491
|
-
var newArr = new Uint8Array(width * height * 4);
|
|
492
|
-
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
426
|
+
this._drawCtx.putImageData(img, x, y);
|
|
493
427
|
|
|
494
|
-
this.
|
|
495
|
-
'type': 'blitRgbx',
|
|
496
|
-
'data': newArr,
|
|
497
|
-
'x': x,
|
|
498
|
-
'y': y,
|
|
499
|
-
'width': width,
|
|
500
|
-
'height': height
|
|
501
|
-
});
|
|
502
|
-
} else {
|
|
503
|
-
this._rgbxImageData(x, y, width, height, arr, offset);
|
|
428
|
+
this._damage(x, y, width, height);
|
|
504
429
|
}
|
|
505
430
|
}
|
|
506
431
|
}, {
|
|
@@ -552,66 +477,13 @@ var Display = /*#__PURE__*/function () {
|
|
|
552
477
|
}, {
|
|
553
478
|
key: "_setFillColor",
|
|
554
479
|
value: function _setFillColor(color) {
|
|
555
|
-
var newStyle = 'rgb(' + color[
|
|
480
|
+
var newStyle = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')';
|
|
556
481
|
|
|
557
482
|
if (newStyle !== this._prevDrawStyle) {
|
|
558
483
|
this._drawCtx.fillStyle = newStyle;
|
|
559
484
|
this._prevDrawStyle = newStyle;
|
|
560
485
|
}
|
|
561
486
|
}
|
|
562
|
-
}, {
|
|
563
|
-
key: "_rgbImageData",
|
|
564
|
-
value: function _rgbImageData(x, y, width, height, arr, offset) {
|
|
565
|
-
var img = this._drawCtx.createImageData(width, height);
|
|
566
|
-
|
|
567
|
-
var data = img.data;
|
|
568
|
-
|
|
569
|
-
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
|
570
|
-
data[i] = arr[j];
|
|
571
|
-
data[i + 1] = arr[j + 1];
|
|
572
|
-
data[i + 2] = arr[j + 2];
|
|
573
|
-
data[i + 3] = 255; // Alpha
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
this._drawCtx.putImageData(img, x, y);
|
|
577
|
-
|
|
578
|
-
this._damage(x, y, img.width, img.height);
|
|
579
|
-
}
|
|
580
|
-
}, {
|
|
581
|
-
key: "_bgrxImageData",
|
|
582
|
-
value: function _bgrxImageData(x, y, width, height, arr, offset) {
|
|
583
|
-
var img = this._drawCtx.createImageData(width, height);
|
|
584
|
-
|
|
585
|
-
var data = img.data;
|
|
586
|
-
|
|
587
|
-
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
|
|
588
|
-
data[i] = arr[j + 2];
|
|
589
|
-
data[i + 1] = arr[j + 1];
|
|
590
|
-
data[i + 2] = arr[j];
|
|
591
|
-
data[i + 3] = 255; // Alpha
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
this._drawCtx.putImageData(img, x, y);
|
|
595
|
-
|
|
596
|
-
this._damage(x, y, img.width, img.height);
|
|
597
|
-
}
|
|
598
|
-
}, {
|
|
599
|
-
key: "_rgbxImageData",
|
|
600
|
-
value: function _rgbxImageData(x, y, width, height, arr, offset) {
|
|
601
|
-
// NB(directxman12): arr must be an Type Array view
|
|
602
|
-
var img;
|
|
603
|
-
|
|
604
|
-
if (_browser.supportsImageMetadata) {
|
|
605
|
-
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
|
606
|
-
} else {
|
|
607
|
-
img = this._drawCtx.createImageData(width, height);
|
|
608
|
-
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4));
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
this._drawCtx.putImageData(img, x, y);
|
|
612
|
-
|
|
613
|
-
this._damage(x, y, img.width, img.height);
|
|
614
|
-
}
|
|
615
487
|
}, {
|
|
616
488
|
key: "_renderQPush",
|
|
617
489
|
value: function _renderQPush(action) {
|
|
@@ -657,17 +529,8 @@ var Display = /*#__PURE__*/function () {
|
|
|
657
529
|
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
658
530
|
break;
|
|
659
531
|
|
|
660
|
-
case 'blitRgb':
|
|
661
|
-
this.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
662
|
-
break;
|
|
663
|
-
|
|
664
|
-
case 'blitRgbx':
|
|
665
|
-
this.blitRgbxImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
666
|
-
break;
|
|
667
|
-
|
|
668
532
|
case 'img':
|
|
669
|
-
|
|
670
|
-
if (a.img.complete && a.img.width !== 0 && a.img.height !== 0) {
|
|
533
|
+
if (a.img.complete) {
|
|
671
534
|
if (a.img.width !== a.width || a.img.height !== a.height) {
|
|
672
535
|
Log.Error("Decoded image has incorrect dimensions. Got " + a.img.width + "x" + a.img.height + ". Expected " + a.width + "x" + a.height + ".");
|
|
673
536
|
return;
|
|
@@ -695,39 +558,9 @@ var Display = /*#__PURE__*/function () {
|
|
|
695
558
|
this.onflush();
|
|
696
559
|
}
|
|
697
560
|
}
|
|
698
|
-
}, {
|
|
699
|
-
key: "scale",
|
|
700
|
-
get: function get() {
|
|
701
|
-
return this._scale;
|
|
702
|
-
},
|
|
703
|
-
set: function set(scale) {
|
|
704
|
-
this._rescale(scale);
|
|
705
|
-
}
|
|
706
|
-
}, {
|
|
707
|
-
key: "clipViewport",
|
|
708
|
-
get: function get() {
|
|
709
|
-
return this._clipViewport;
|
|
710
|
-
},
|
|
711
|
-
set: function set(viewport) {
|
|
712
|
-
this._clipViewport = viewport; // May need to readjust the viewport dimensions
|
|
713
|
-
|
|
714
|
-
var vp = this._viewportLoc;
|
|
715
|
-
this.viewportChangeSize(vp.w, vp.h);
|
|
716
|
-
this.viewportChangePos(0, 0);
|
|
717
|
-
}
|
|
718
|
-
}, {
|
|
719
|
-
key: "width",
|
|
720
|
-
get: function get() {
|
|
721
|
-
return this._fbWidth;
|
|
722
|
-
}
|
|
723
|
-
}, {
|
|
724
|
-
key: "height",
|
|
725
|
-
get: function get() {
|
|
726
|
-
return this._fbHeight;
|
|
727
|
-
}
|
|
728
561
|
}]);
|
|
729
562
|
|
|
730
563
|
return Display;
|
|
731
564
|
}();
|
|
732
565
|
|
|
733
|
-
exports
|
|
566
|
+
exports["default"] = Display;
|
package/lib/encodings.js
CHANGED
|
@@ -19,7 +19,9 @@ var encodings = {
|
|
|
19
19
|
encodingRRE: 2,
|
|
20
20
|
encodingHextile: 5,
|
|
21
21
|
encodingTight: 7,
|
|
22
|
+
encodingZRLE: 16,
|
|
22
23
|
encodingTightPNG: -260,
|
|
24
|
+
encodingJPEG: 21,
|
|
23
25
|
pseudoEncodingQualityLevel9: -23,
|
|
24
26
|
pseudoEncodingQualityLevel0: -32,
|
|
25
27
|
pseudoEncodingDesktopSize: -223,
|
|
@@ -55,9 +57,15 @@ function encodingName(num) {
|
|
|
55
57
|
case encodings.encodingTight:
|
|
56
58
|
return "Tight";
|
|
57
59
|
|
|
60
|
+
case encodings.encodingZRLE:
|
|
61
|
+
return "ZRLE";
|
|
62
|
+
|
|
58
63
|
case encodings.encodingTightPNG:
|
|
59
64
|
return "TightPNG";
|
|
60
65
|
|
|
66
|
+
case encodings.encodingJPEG:
|
|
67
|
+
return "JPEG";
|
|
68
|
+
|
|
61
69
|
default:
|
|
62
70
|
return "[unknown encoding " + num + "]";
|
|
63
71
|
}
|