@novnc/novnc
Advanced tools
Comparing version 1.3.0-g8329372 to 1.3.0-g837cc75
@@ -227,2 +227,14 @@ /* | ||
getImageData() { | ||
return this._drawCtx.getImageData(0, 0, this.width, this.height); | ||
} | ||
toDataURL(type, encoderOptions) { | ||
return this._backbuffer.toDataURL(type, encoderOptions); | ||
} | ||
toBlob(callback, type, quality) { | ||
return this._backbuffer.toBlob(callback, type, quality); | ||
} | ||
// Track what parts of the visible canvas that need updating | ||
@@ -229,0 +241,0 @@ _damage(x, y, w, h) { |
@@ -156,2 +156,12 @@ /* | ||
// macOS doesn't send proper key releases if a key is pressed | ||
// while meta is held down | ||
if ((browser.isMac() || browser.isIOS()) && | ||
(e.metaKey && code !== 'MetaLeft' && code !== 'MetaRight')) { | ||
this._sendKeyEvent(keysym, code, true); | ||
this._sendKeyEvent(keysym, code, false); | ||
stopEvent(e); | ||
return; | ||
} | ||
// macOS doesn't send proper key events for modifiers, only | ||
@@ -158,0 +168,0 @@ // state change events. That gets extra confusing for CapsLock |
@@ -158,2 +158,11 @@ # noVNC API | ||
[`RFB.getImageData()`](#rfbgetimagedata) | ||
- Return the current content of the screen as an ImageData array. | ||
[`RFB.toDataURL()`](#rfbtodataurl) | ||
- Return the current content of the screen as data-url encoded image file. | ||
[`RFB.toBlob()`](#rfbtoblob) | ||
- Return the current content of the screen as Blob encoded image file. | ||
### Details | ||
@@ -427,1 +436,53 @@ | ||
- A `DOMString` specifying the clipboard data to send. | ||
#### RFB.getImageData() | ||
The `RFB.getImageData()` method is used to return the current content of the | ||
screen encoded as [`ImageData`](https://developer.mozilla.org/en-US/docs/Web/API/ImageData). | ||
##### Syntax | ||
RFB.getImageData(); | ||
#### RFB.toDataURL() | ||
The `RFB.toDataURL()` method is used to return the current content of the | ||
screen encoded as a data URL that could for example be put in the `src` attribute | ||
of an `img` tag. | ||
##### Syntax | ||
RFB.toDataURL(); | ||
RFB.toDataURL(type); | ||
RFB.toDataURL(type, encoderOptions); | ||
###### Parameters | ||
**`type`** *Optional* | ||
- A string indicating the requested MIME type of the image | ||
**`encoderOptions`** *Optional* | ||
- A number between 0 and 1 indicating the image quality. | ||
#### RFB.toBlob() | ||
The `RFB.toBlob()` method is used to return the current content of the | ||
screen encoded as [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob). | ||
##### Syntax | ||
RFB.toDataURL(callback); | ||
RFB.toDataURL(callback, type); | ||
RFB.toDataURL(callback, type, quality); | ||
###### Parameters | ||
**`callback`** | ||
- A callback function which will receive the resulting [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | ||
as the single argument | ||
**`type`** *Optional* | ||
- A string indicating the requested MIME type of the image | ||
**`encoderOptions`** *Optional* | ||
- A number between 0 and 1 indicating the image quality. |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,9 +8,5 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("./util/logging.js")); | ||
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); } | ||
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; } | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
@@ -30,3 +25,4 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
var length = data.length; | ||
var lengthpad = length % 3; // Convert every three bytes to 4 ascii characters. | ||
var lengthpad = length % 3; | ||
// Convert every three bytes to 4 ascii characters. | ||
@@ -38,7 +34,6 @@ for (var i = 0; i < length - 2; i += 3) { | ||
result += this.toBase64Table[data[i + 2] & 0x3f]; | ||
} // Convert the remaining 1 or 2 bytes, pad out to 4 characters. | ||
} | ||
// Convert the remaining 1 or 2 bytes, pad out to 4 characters. | ||
var j = length - lengthpad; | ||
if (lengthpad === 2) { | ||
@@ -55,54 +50,47 @@ result += this.toBase64Table[data[j] >> 2]; | ||
} | ||
return result; | ||
}, | ||
/* Convert Base64 data to a string */ | ||
/* eslint-disable comma-spacing */ | ||
toBinaryTable: [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1], | ||
/* eslint-enable comma-spacing */ | ||
decode: function decode(data) { | ||
/* eslint-enable comma-spacing */decode: function decode(data) { | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var dataLength = data.indexOf('=') - offset; | ||
if (dataLength < 0) { | ||
dataLength = data.length - offset; | ||
} | ||
/* Every four characters is 3 resulting numbers */ | ||
var resultLength = (dataLength >> 2) * 3 + Math.floor(dataLength % 4 / 1.5); | ||
var result = new Array(resultLength); | ||
// Convert one by one. | ||
var resultLength = (dataLength >> 2) * 3 + Math.floor(dataLength % 4 / 1.5); | ||
var result = new Array(resultLength); // Convert one by one. | ||
var leftbits = 0; // number of bits decoded, but yet to be appended | ||
var leftdata = 0; // bits decoded, but yet to be appended | ||
for (var idx = 0, i = offset; i < data.length; i++) { | ||
var c = this.toBinaryTable[data.charCodeAt(i) & 0x7f]; | ||
var padding = data.charAt(i) === this.base64Pad; // Skip illegal characters and whitespace | ||
var padding = data.charAt(i) === this.base64Pad; | ||
// Skip illegal characters and whitespace | ||
if (c === -1) { | ||
Log.Error("Illegal character code " + data.charCodeAt(i) + " at position " + i); | ||
continue; | ||
} // Collect data into leftdata, update bitcount | ||
} | ||
// Collect data into leftdata, update bitcount | ||
leftdata = leftdata << 6 | c; | ||
leftbits += 6; // If we have 8 or more bits, append 8 bits to the result | ||
leftbits += 6; | ||
// If we have 8 or more bits, append 8 bits to the result | ||
if (leftbits >= 8) { | ||
leftbits -= 8; // Append if not padding. | ||
leftbits -= 8; | ||
// Append if not padding. | ||
if (!padding) { | ||
result[idx++] = leftdata >> leftbits & 0xff; | ||
} | ||
leftdata &= (1 << leftbits) - 1; | ||
} | ||
} // If there are any bits left, the base64 string was corrupted | ||
} | ||
// If there are any bits left, the base64 string was corrupted | ||
if (leftbits) { | ||
@@ -113,3 +101,2 @@ var err = new Error('Corrupted base64 string'); | ||
} | ||
return result; | ||
@@ -119,3 +106,2 @@ } | ||
/* End of Base64 namespace */ | ||
exports["default"] = _default; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
/* | ||
@@ -27,3 +26,2 @@ * noVNC: HTML5 VNC client | ||
} | ||
_createClass(CopyRectDecoder, [{ | ||
@@ -35,10 +33,7 @@ key: "decodeRect", | ||
} | ||
var deltaX = sock.rQshift16(); | ||
var deltaY = sock.rQshift16(); | ||
if (width === 0 || height === 0) { | ||
return true; | ||
} | ||
display.copyImage(deltaX, deltaY, x, y, width, height); | ||
@@ -48,6 +43,4 @@ return true; | ||
}]); | ||
return CopyRectDecoder; | ||
}(); | ||
exports["default"] = CopyRectDecoder; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,19 +7,14 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("../util/logging.js")); | ||
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); } | ||
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; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var HextileDecoder = /*#__PURE__*/function () { | ||
function HextileDecoder() { | ||
_classCallCheck(this, HextileDecoder); | ||
this._tiles = 0; | ||
@@ -31,3 +24,2 @@ this._lastsubencoding = 0; | ||
} | ||
_createClass(HextileDecoder, [{ | ||
@@ -42,14 +34,10 @@ key: "decodeRect", | ||
} | ||
while (this._tiles > 0) { | ||
var bytes = 1; | ||
if (sock.rQwait("HEXTILE", bytes)) { | ||
return false; | ||
} | ||
var rQ = sock.rQ; | ||
var rQi = sock.rQi; | ||
var subencoding = rQ[rQi]; // Peek | ||
if (subencoding > 30) { | ||
@@ -59,3 +47,2 @@ // Raw | ||
} | ||
var currTile = this._totalTiles - this._tiles; | ||
@@ -67,4 +54,5 @@ var tileX = currTile % this._tilesX; | ||
var tw = Math.min(16, x + width - tx); | ||
var th = Math.min(16, y + height - ty); // Figure out how much we are expecting | ||
var th = Math.min(16, y + height - ty); | ||
// Figure out how much we are expecting | ||
if (subencoding & 0x01) { | ||
@@ -78,3 +66,2 @@ // Raw | ||
} | ||
if (subencoding & 0x04) { | ||
@@ -84,3 +71,2 @@ // Foreground | ||
} | ||
if (subencoding & 0x08) { | ||
@@ -93,5 +79,3 @@ // AnySubrects | ||
} | ||
var subrects = rQ[rQi + bytes - 1]; // Peek | ||
if (subencoding & 0x10) { | ||
@@ -105,10 +89,8 @@ // SubrectsColoured | ||
} | ||
if (sock.rQwait("HEXTILE", bytes)) { | ||
return false; | ||
} // We know the encoding and have a whole tile | ||
} | ||
// We know the encoding and have a whole tile | ||
rQi++; | ||
if (subencoding === 0) { | ||
@@ -123,8 +105,7 @@ if (this._lastsubencoding & 0x01) { | ||
// Raw | ||
var pixels = tw * th; // Max sure the image is fully opaque | ||
var pixels = tw * th; | ||
// Max sure the image is fully opaque | ||
for (var i = 0; i < pixels; i++) { | ||
rQ[rQi + i * 4 + 3] = 255; | ||
} | ||
display.blitImage(tx, ty, tw, th, rQ, rQi); | ||
@@ -138,3 +119,2 @@ rQi += bytes - 1; | ||
} | ||
if (subencoding & 0x04) { | ||
@@ -145,5 +125,3 @@ // Foreground | ||
} | ||
this._startTile(tx, ty, tw, th, this._background); | ||
if (subencoding & 0x08) { | ||
@@ -153,6 +131,4 @@ // AnySubrects | ||
rQi++; | ||
for (var s = 0; s < _subrects; s++) { | ||
var color = void 0; | ||
if (subencoding & 0x10) { | ||
@@ -165,3 +141,2 @@ // SubrectsColoured | ||
} | ||
var xy = rQ[rQi]; | ||
@@ -175,10 +150,7 @@ rQi++; | ||
var sh = (wh & 0x0f) + 1; | ||
this._subTile(sx, sy, sw, sh, color); | ||
} | ||
} | ||
this._finishTile(display); | ||
} | ||
sock.rQi = rQi; | ||
@@ -188,6 +160,6 @@ this._lastsubencoding = subencoding; | ||
} | ||
return true; | ||
} // start updating a tile | ||
} | ||
// start updating a tile | ||
}, { | ||
@@ -204,3 +176,2 @@ key: "_startTile", | ||
var data = this._tileBuffer; | ||
for (var i = 0; i < width * height * 4; i += 4) { | ||
@@ -212,4 +183,5 @@ data[i] = red; | ||
} | ||
} // update sub-rectangle of the current tile | ||
} | ||
// update sub-rectangle of the current tile | ||
}, { | ||
@@ -225,3 +197,2 @@ key: "_subTile", | ||
var width = this._tileW; | ||
for (var j = y; j < yend; j++) { | ||
@@ -236,4 +207,5 @@ for (var i = x; i < xend; i++) { | ||
} | ||
} // draw the current tile to the screen | ||
} | ||
// draw the current tile to the screen | ||
}, { | ||
@@ -245,6 +217,4 @@ key: "_finishTile", | ||
}]); | ||
return HextileDecoder; | ||
}(); | ||
exports["default"] = HextileDecoder; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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,3 +25,2 @@ * noVNC: HTML5 VNC client | ||
_classCallCheck(this, JPEGDecoder); | ||
// RealVNC will reuse the quantization tables | ||
@@ -37,3 +35,2 @@ // and Huffman tables, so we need to cache them. | ||
} | ||
_createClass(JPEGDecoder, [{ | ||
@@ -46,5 +43,3 @@ key: "decodeRect", | ||
} | ||
var data = sock.rQshiftBytes(this._jpegLength); | ||
if (this._quantTables.length != 0 && this._huffmanTables.length != 0) { | ||
@@ -60,9 +55,6 @@ // If there are quantization tables and Huffman tables in the JPEG | ||
}); | ||
if (sofIndex == -1) { | ||
throw new Error("Illegal JPEG image without SOF"); | ||
} | ||
var segments = this._segments.slice(0, sofIndex); | ||
segments = segments.concat(this._quantTables.length ? this._quantTables : this._cachedQuantTables); | ||
@@ -72,17 +64,11 @@ segments.push(this._segments[sofIndex]); | ||
var length = 0; | ||
for (var i = 0; i < segments.length; i++) { | ||
length += segments[i].length; | ||
} | ||
var _data = new Uint8Array(length); | ||
length = 0; | ||
for (var _i = 0; _i < segments.length; _i++) { | ||
_data.set(segments[_i], length); | ||
length += segments[_i].length; | ||
} | ||
display.imageRect(x, y, width, height, "image/jpeg", _data); | ||
@@ -98,7 +84,5 @@ return true; | ||
} | ||
if (this._huffmanTables.length != 0) { | ||
this._cachedHuffmanTables = this._huffmanTables; | ||
} | ||
this._quantTables = []; | ||
@@ -109,22 +93,15 @@ this._huffmanTables = []; | ||
var bufferLength = buffer.length; | ||
while (true) { | ||
var j = i; | ||
if (j + 2 > bufferLength) { | ||
return false; | ||
} | ||
if (buffer[j] != 0xFF) { | ||
throw new Error("Illegal JPEG marker received (byte: " + buffer[j] + ")"); | ||
} | ||
var type = buffer[j + 1]; | ||
j += 2; | ||
if (type == 0xD9) { | ||
this._jpegLength = j; | ||
this._segments.push(buffer.slice(i, j)); | ||
return true; | ||
@@ -134,3 +111,2 @@ } else if (type == 0xDA) { | ||
var hasFoundEndOfScan = false; | ||
for (var k = j + 3; k + 1 < bufferLength; k++) { | ||
@@ -143,9 +119,6 @@ if (buffer[k] == 0xFF && buffer[k + 1] != 0x00 && !(buffer[k + 1] >= 0xD0 && buffer[k + 1] <= 0xD7)) { | ||
} | ||
if (!hasFoundEndOfScan) { | ||
return false; | ||
} | ||
this._segments.push(buffer.slice(i, j)); | ||
i = j; | ||
@@ -156,26 +129,18 @@ continue; | ||
this._segments.push(buffer.slice(i, j)); | ||
i = j; | ||
continue; | ||
} | ||
if (j + 2 > bufferLength) { | ||
return false; | ||
} | ||
var length = (buffer[j] << 8) + buffer[j + 1] - 2; | ||
if (length < 0) { | ||
throw new Error("Illegal JPEG length received (length: " + length + ")"); | ||
} | ||
j += 2; | ||
if (j + length > bufferLength) { | ||
return false; | ||
} | ||
j += length; | ||
var segment = buffer.slice(i, j); | ||
if (type == 0xC4) { | ||
@@ -188,5 +153,3 @@ // Huffman tables | ||
} | ||
this._segments.push(segment); | ||
i = j; | ||
@@ -196,6 +159,4 @@ } | ||
}]); | ||
return JPEGDecoder; | ||
}(); | ||
exports["default"] = JPEGDecoder; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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,6 +25,4 @@ * noVNC: HTML5 VNC client | ||
_classCallCheck(this, RawDecoder); | ||
this._lines = 0; | ||
} | ||
_createClass(RawDecoder, [{ | ||
@@ -37,14 +34,10 @@ key: "decodeRect", | ||
} | ||
if (this._lines === 0) { | ||
this._lines = height; | ||
} | ||
var pixelSize = depth == 8 ? 1 : 4; | ||
var bytesPerLine = width * pixelSize; | ||
if (sock.rQwait("RAW", bytesPerLine)) { | ||
return false; | ||
} | ||
var curY = y + (height - this._lines); | ||
@@ -54,7 +47,7 @@ var currHeight = Math.min(this._lines, Math.floor(sock.rQlen / bytesPerLine)); | ||
var data = sock.rQ; | ||
var index = sock.rQi; // Convert data if needed | ||
var index = sock.rQi; | ||
// Convert data if needed | ||
if (depth == 8) { | ||
var newdata = new Uint8Array(pixels * 4); | ||
for (var i = 0; i < pixels; i++) { | ||
@@ -66,27 +59,21 @@ newdata[i * 4 + 0] = (data[index + i] >> 0 & 0x3) * 255 / 3; | ||
} | ||
data = newdata; | ||
index = 0; | ||
} // Max sure the image is fully opaque | ||
} | ||
// Max sure the image is fully opaque | ||
for (var _i = 0; _i < pixels; _i++) { | ||
data[index + _i * 4 + 3] = 255; | ||
} | ||
display.blitImage(x, curY, width, currHeight, data, index); | ||
sock.rQskipBytes(currHeight * bytesPerLine); | ||
this._lines -= currHeight; | ||
if (this._lines > 0) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}]); | ||
return RawDecoder; | ||
}(); | ||
exports["default"] = RawDecoder; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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,6 +25,4 @@ * noVNC: HTML5 VNC client | ||
_classCallCheck(this, RREDecoder); | ||
this._subrects = 0; | ||
} | ||
_createClass(RREDecoder, [{ | ||
@@ -38,9 +35,6 @@ key: "decodeRect", | ||
} | ||
this._subrects = sock.rQshift32(); | ||
var color = sock.rQshiftBytes(4); // Background | ||
display.fillRect(x, y, width, height, color); | ||
} | ||
while (this._subrects > 0) { | ||
@@ -50,5 +44,3 @@ if (sock.rQwait("RRE", 4 + 8)) { | ||
} | ||
var _color = sock.rQshiftBytes(4); | ||
var sx = sock.rQshift16(); | ||
@@ -61,10 +53,7 @@ var sy = sock.rQshift16(); | ||
} | ||
return true; | ||
} | ||
}]); | ||
return RREDecoder; | ||
}(); | ||
exports["default"] = RREDecoder; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,23 +7,16 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("../util/logging.js")); | ||
var _inflator = _interopRequireDefault(require("../inflator.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var TightDecoder = /*#__PURE__*/function () { | ||
function TightDecoder() { | ||
_classCallCheck(this, TightDecoder); | ||
this._ctl = null; | ||
@@ -35,6 +26,4 @@ this._filter = null; | ||
this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel) | ||
this._len = 0; | ||
this._zlibs = []; | ||
for (var i = 0; i < 4; i++) { | ||
@@ -44,3 +33,2 @@ this._zlibs[i] = new _inflator["default"](); | ||
} | ||
_createClass(TightDecoder, [{ | ||
@@ -53,19 +41,16 @@ key: "decodeRect", | ||
} | ||
this._ctl = sock.rQshift8(); | ||
this._ctl = sock.rQshift8(); // Reset streams if the server requests it | ||
// Reset streams if the server requests it | ||
for (var i = 0; i < 4; i++) { | ||
if (this._ctl >> i & 1) { | ||
this._zlibs[i].reset(); | ||
Log.Info("Reset zlib stream " + i); | ||
} | ||
} // Figure out filter | ||
} | ||
// Figure out filter | ||
this._ctl = this._ctl >> 4; | ||
} | ||
var ret; | ||
if (this._ctl === 0x08) { | ||
@@ -82,7 +67,5 @@ ret = this._fillRect(x, y, width, height, sock, display, depth); | ||
} | ||
if (ret) { | ||
this._ctl = null; | ||
} | ||
return ret; | ||
@@ -96,3 +79,2 @@ } | ||
} | ||
var rQi = sock.rQi; | ||
@@ -108,7 +90,5 @@ var rQ = sock.rQ; | ||
var data = this._readData(sock); | ||
if (data === null) { | ||
return false; | ||
} | ||
display.imageRect(x, y, width, height, "image/jpeg", data); | ||
@@ -130,3 +110,2 @@ return true; | ||
} | ||
this._filter = sock.rQshift8(); | ||
@@ -138,6 +117,4 @@ } else { | ||
} | ||
var streamId = ctl & 0x3; | ||
var ret; | ||
switch (this._filter) { | ||
@@ -148,3 +125,2 @@ case 0: | ||
break; | ||
case 1: | ||
@@ -154,3 +130,2 @@ // PaletteFilter | ||
break; | ||
case 2: | ||
@@ -160,11 +135,8 @@ // GradientFilter | ||
break; | ||
default: | ||
throw new Error("Illegal tight filter received (ctl: " + this._filter + ")"); | ||
} | ||
if (ret) { | ||
this._filter = null; | ||
} | ||
return ret; | ||
@@ -177,7 +149,5 @@ } | ||
var data; | ||
if (uncompressedSize === 0) { | ||
return true; | ||
} | ||
if (uncompressedSize < 12) { | ||
@@ -187,20 +157,13 @@ if (sock.rQwait("TIGHT", uncompressedSize)) { | ||
} | ||
data = sock.rQshiftBytes(uncompressedSize); | ||
} else { | ||
data = this._readData(sock); | ||
if (data === null) { | ||
return false; | ||
} | ||
this._zlibs[streamId].setInput(data); | ||
data = this._zlibs[streamId].inflate(uncompressedSize); | ||
this._zlibs[streamId].setInput(null); | ||
} | ||
var rgbx = new Uint8Array(width * height * 4); | ||
for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) { | ||
@@ -223,10 +186,7 @@ rgbx[i] = data[j]; | ||
} | ||
var numColors = sock.rQpeek8() + 1; | ||
var paletteSize = numColors * 3; | ||
if (sock.rQwait("TIGHT palette", 1 + paletteSize)) { | ||
return false; | ||
} | ||
this._numColors = numColors; | ||
@@ -236,3 +196,2 @@ sock.rQskipBytes(1); | ||
} | ||
var bpp = this._numColors <= 2 ? 1 : 8; | ||
@@ -242,7 +201,5 @@ var rowSize = Math.floor((width * bpp + 7) / 8); | ||
var data; | ||
if (uncompressedSize === 0) { | ||
return true; | ||
} | ||
if (uncompressedSize < 12) { | ||
@@ -252,19 +209,14 @@ if (sock.rQwait("TIGHT", uncompressedSize)) { | ||
} | ||
data = sock.rQshiftBytes(uncompressedSize); | ||
} else { | ||
data = this._readData(sock); | ||
if (data === null) { | ||
return false; | ||
} | ||
this._zlibs[streamId].setInput(data); | ||
data = this._zlibs[streamId].inflate(uncompressedSize); | ||
this._zlibs[streamId].setInput(null); | ||
} // Convert indexed (palette based) image data to RGB | ||
} | ||
// Convert indexed (palette based) image data to RGB | ||
if (this._numColors == 2) { | ||
@@ -275,3 +227,2 @@ this._monoRect(x, y, width, height, data, this._palette, display); | ||
} | ||
this._numColors = 0; | ||
@@ -286,11 +237,8 @@ return true; | ||
var dest = this._getScratchBuffer(width * height * 4); | ||
var w = Math.floor((width + 7) / 8); | ||
var w1 = Math.floor(width / 8); | ||
for (var _y = 0; _y < height; _y++) { | ||
var dp = void 0, | ||
sp = void 0, | ||
_x = void 0; | ||
sp = void 0, | ||
_x = void 0; | ||
for (_x = 0; _x < w1; _x++) { | ||
@@ -306,3 +254,2 @@ for (var b = 7; b >= 0; b--) { | ||
} | ||
for (var _b = 7; _b >= 8 - width % 8; _b--) { | ||
@@ -317,3 +264,2 @@ dp = (_y * width + _x * 8 + 7 - _b) * 4; | ||
} | ||
display.blitImage(x, y, width, height, dest, 0, false); | ||
@@ -326,5 +272,3 @@ } | ||
var dest = this._getScratchBuffer(width * height * 4); | ||
var total = width * height * 4; | ||
for (var i = 0, j = 0; i < total; i += 4, j++) { | ||
@@ -337,3 +281,2 @@ var sp = data[j] * 3; | ||
} | ||
display.blitImage(x, y, width, height, dest, 0, false); | ||
@@ -353,12 +296,8 @@ } | ||
} | ||
var _byte; | ||
_byte = sock.rQshift8(); | ||
this._len = _byte & 0x7f; | ||
if (_byte & 0x80) { | ||
_byte = sock.rQshift8(); | ||
this._len |= (_byte & 0x7f) << 7; | ||
if (_byte & 0x80) { | ||
@@ -370,7 +309,5 @@ _byte = sock.rQshift8(); | ||
} | ||
if (sock.rQwait("TIGHT", this._len)) { | ||
return null; | ||
} | ||
var data = sock.rQshiftBytes(this._len); | ||
@@ -386,10 +323,7 @@ this._len = 0; | ||
} | ||
return this._scratchBuffer; | ||
} | ||
}]); | ||
return TightDecoder; | ||
}(); | ||
exports["default"] = TightDecoder; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,38 +8,23 @@ value: true | ||
exports["default"] = void 0; | ||
var _tight = _interopRequireDefault(require("./tight.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
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); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
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); }; } | ||
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); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
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; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var TightPNGDecoder = /*#__PURE__*/function (_TightDecoder) { | ||
_inherits(TightPNGDecoder, _TightDecoder); | ||
var _super = _createSuper(TightPNGDecoder); | ||
function TightPNGDecoder() { | ||
_classCallCheck(this, TightPNGDecoder); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(TightPNGDecoder, [{ | ||
@@ -50,7 +34,5 @@ key: "_pngRect", | ||
var data = this._readData(sock); | ||
if (data === null) { | ||
return false; | ||
} | ||
display.imageRect(x, y, width, height, "image/png", data); | ||
@@ -65,6 +47,4 @@ return true; | ||
}]); | ||
return TightPNGDecoder; | ||
}(_tight["default"]); | ||
exports["default"] = TightPNGDecoder; |
@@ -7,20 +7,15 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _inflator = _interopRequireDefault(require("../inflator.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var ZRLE_TILE_WIDTH = 64; | ||
var ZRLE_TILE_HEIGHT = 64; | ||
var ZRLEDecoder = /*#__PURE__*/function () { | ||
function ZRLEDecoder() { | ||
_classCallCheck(this, ZRLEDecoder); | ||
this._length = 0; | ||
@@ -31,3 +26,2 @@ this._inflator = new _inflator["default"](); | ||
} | ||
_createClass(ZRLEDecoder, [{ | ||
@@ -40,27 +34,18 @@ key: "decodeRect", | ||
} | ||
this._length = sock.rQshift32(); | ||
} | ||
if (sock.rQwait("Zlib data", this._length)) { | ||
return false; | ||
} | ||
var data = sock.rQshiftBytes(this._length); | ||
this._inflator.setInput(data); | ||
for (var ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) { | ||
var th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty); | ||
for (var tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) { | ||
var tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx); | ||
var tileSize = tw * th; | ||
var subencoding = this._inflator.inflate(1)[0]; | ||
if (subencoding === 0) { | ||
// raw data | ||
var _data = this._readPixels(tileSize); | ||
display.blitImage(tx, ty, tw, th, _data, 0, false); | ||
@@ -70,15 +55,11 @@ } else if (subencoding === 1) { | ||
var background = this._readPixels(1); | ||
display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]); | ||
} else if (subencoding >= 2 && subencoding <= 16) { | ||
var _data2 = this._decodePaletteTile(subencoding, tileSize, tw, th); | ||
display.blitImage(tx, ty, tw, th, _data2, 0, false); | ||
} else if (subencoding === 128) { | ||
var _data3 = this._decodeRLETile(tileSize); | ||
display.blitImage(tx, ty, tw, th, _data3, 0, false); | ||
} else if (subencoding >= 130 && subencoding <= 255) { | ||
var _data4 = this._decodeRLEPaletteTile(subencoding - 128, tileSize); | ||
display.blitImage(tx, ty, tw, th, _data4, 0, false); | ||
@@ -90,3 +71,2 @@ } else { | ||
} | ||
this._length = 0; | ||
@@ -110,5 +90,3 @@ return true; | ||
var data = this._pixelBuffer; | ||
var buffer = this._inflator.inflate(3 * pixels); | ||
for (var i = 0, j = 0; i < pixels * 4; i += 4, j += 3) { | ||
@@ -127,15 +105,9 @@ data[i] = buffer[j]; | ||
var data = this._tileBuffer; | ||
var palette = this._readPixels(paletteSize); | ||
var bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize); | ||
var mask = (1 << bitsPerPixel) - 1; | ||
var offset = 0; | ||
var encoded = this._inflator.inflate(1)[0]; | ||
for (var y = 0; y < tileh; y++) { | ||
var shift = 8 - bitsPerPixel; | ||
for (var x = 0; x < tilew; x++) { | ||
@@ -146,3 +118,2 @@ if (shift < 0) { | ||
} | ||
var indexInPalette = encoded >> shift & mask; | ||
@@ -156,3 +127,2 @@ data[offset] = palette[indexInPalette * 4]; | ||
} | ||
if (shift < 8 - bitsPerPixel && y < tileh - 1) { | ||
@@ -162,3 +132,2 @@ encoded = this._inflator.inflate(1)[0]; | ||
} | ||
return data; | ||
@@ -171,8 +140,5 @@ } | ||
var i = 0; | ||
while (i < tileSize) { | ||
var pixel = this._readPixels(1); | ||
var length = this._readRLELength(); | ||
for (var j = 0; j < length; j++) { | ||
@@ -186,3 +152,2 @@ data[i * 4] = pixel[0]; | ||
} | ||
return data; | ||
@@ -193,13 +158,10 @@ } | ||
value: function _decodeRLEPaletteTile(paletteSize, tileSize) { | ||
var data = this._tileBuffer; // palette | ||
var data = this._tileBuffer; | ||
// palette | ||
var palette = this._readPixels(paletteSize); | ||
var offset = 0; | ||
while (offset < tileSize) { | ||
var indexInPalette = this._inflator.inflate(1)[0]; | ||
var length = 1; | ||
if (indexInPalette >= 128) { | ||
@@ -209,11 +171,8 @@ indexInPalette -= 128; | ||
} | ||
if (indexInPalette > paletteSize) { | ||
throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize); | ||
} | ||
if (offset + length > tileSize) { | ||
throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset)); | ||
} | ||
for (var j = 0; j < length; j++) { | ||
@@ -227,3 +186,2 @@ data[offset * 4] = palette[indexInPalette * 4]; | ||
} | ||
return data; | ||
@@ -236,3 +194,2 @@ } | ||
var current = 0; | ||
do { | ||
@@ -242,10 +199,7 @@ current = this._inflator.inflate(1)[0]; | ||
} while (current === 255); | ||
return length + 1; | ||
} | ||
}]); | ||
return ZRLEDecoder; | ||
}(); | ||
exports["default"] = ZRLEDecoder; |
@@ -7,19 +7,14 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _deflate2 = require("../lib/vendor/pako/lib/zlib/deflate.js"); | ||
var _zstream = _interopRequireDefault(require("../lib/vendor/pako/lib/zlib/zstream.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var Deflator = /*#__PURE__*/function () { | ||
function Deflator() { | ||
_classCallCheck(this, Deflator); | ||
this.strm = new _zstream["default"](); | ||
@@ -31,3 +26,2 @@ this.chunkSize = 1024 * 10 * 10; | ||
} | ||
_createClass(Deflator, [{ | ||
@@ -47,12 +41,10 @@ key: "deflate", | ||
var outData = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); | ||
if (lastRet < 0) { | ||
throw new Error("zlib deflate failed"); | ||
} | ||
if (this.strm.avail_in > 0) { | ||
// Read chunks until done | ||
var chunks = [outData]; | ||
var totalLen = outData.length; | ||
do { | ||
@@ -66,16 +58,14 @@ /* eslint-disable camelcase */ | ||
lastRet = (0, _deflate2.deflate)(this.strm, _deflate2.Z_FULL_FLUSH); | ||
if (lastRet < 0) { | ||
throw new Error("zlib deflate failed"); | ||
} | ||
var chunk = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); | ||
totalLen += chunk.length; | ||
chunks.push(chunk); | ||
} while (this.strm.avail_in > 0); // Combine chunks into a single data | ||
} while (this.strm.avail_in > 0); | ||
// Combine chunks into a single data | ||
var newData = new Uint8Array(totalLen); | ||
var offset = 0; | ||
for (var i = 0; i < chunks.length; i++) { | ||
@@ -85,8 +75,6 @@ newData.set(chunks[i], offset); | ||
} | ||
outData = newData; | ||
} | ||
/* eslint-disable camelcase */ | ||
this.strm.input = null; | ||
@@ -100,6 +88,4 @@ this.strm.avail_in = 0; | ||
}]); | ||
return Deflator; | ||
}(); | ||
exports["default"] = Deflator; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
/* | ||
@@ -93,5 +92,6 @@ * Ported from Flashlight VNC ActionScript implementation: | ||
/* eslint-disable comma-spacing */ | ||
// Tables, permutations, S-boxes, etc. | ||
var PC2 = [13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31], | ||
totrot = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; | ||
totrot = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; | ||
var z = 0x0; | ||
@@ -155,35 +155,28 @@ var a, b, c, d, e, f; | ||
var SP8 = [b | f, z | e, a | z, c | f, b | z, b | f, z | d, b | z, a | d, c | z, c | f, a | e, c | e, a | f, z | e, z | d, c | z, b | d, b | e, z | f, a | e, a | d, c | d, c | e, z | f, z | z, z | z, c | d, b | d, b | e, a | f, a | z, a | f, a | z, c | e, z | e, z | d, c | d, z | e, a | f, b | e, z | d, b | d, c | z, c | d, b | z, a | z, b | f, z | z, c | f, a | d, b | d, c | z, b | e, b | f, z | z, c | f, a | e, a | e, z | f, z | f, a | d, b | z, c | e]; | ||
/* eslint-enable comma-spacing */ | ||
var DES = /*#__PURE__*/function () { | ||
function DES(password) { | ||
_classCallCheck(this, DES); | ||
this.keys = []; | ||
this.keys = []; // Set the key. | ||
// Set the key. | ||
var pc1m = [], | ||
pcr = [], | ||
kn = []; | ||
pcr = [], | ||
kn = []; | ||
for (var j = 0, l = 56; j < 56; ++j, l -= 8) { | ||
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1 | ||
var m = l & 0x7; | ||
pc1m[j] = (password[l >>> 3] & 1 << m) !== 0 ? 1 : 0; | ||
} | ||
for (var i = 0; i < 16; ++i) { | ||
var _m = i << 1; | ||
var n = _m + 1; | ||
kn[_m] = kn[n] = 0; | ||
for (var o = 28; o < 59; o += 28) { | ||
for (var _j = o - 28; _j < o; ++_j) { | ||
var _l = _j + totrot[i]; | ||
pcr[_j] = _l < o ? pc1m[_l] : pc1m[_l - 28]; | ||
} | ||
} | ||
for (var _j2 = 0; _j2 < 24; ++_j2) { | ||
@@ -193,3 +186,2 @@ if (pcr[PC2[_j2]] !== 0) { | ||
} | ||
if (pcr[PC2[_j2 + 24]] !== 0) { | ||
@@ -199,5 +191,5 @@ kn[n] |= 1 << 23 - _j2; | ||
} | ||
} // cookey | ||
} | ||
// cookey | ||
for (var _i = 0, rawi = 0, KnLi = 0; _i < 16; ++_i) { | ||
@@ -217,5 +209,5 @@ var raw0 = kn[rawi++]; | ||
} | ||
} // Encrypt 8 bytes of text | ||
} | ||
// Encrypt 8 bytes of text | ||
_createClass(DES, [{ | ||
@@ -226,7 +218,7 @@ key: "enc8", | ||
var i = 0, | ||
l, | ||
r, | ||
x; // left, right, accumulator | ||
l, | ||
r, | ||
x; // left, right, accumulator | ||
// Squash 8 bytes to 2 ints | ||
l = b[i++] << 24 | b[i++] << 16 | b[i++] << 8 | b[i++]; | ||
@@ -251,3 +243,2 @@ r = b[i++] << 24 | b[i++] << 16 | b[i++] << 8 | b[i++]; | ||
l = l << 1 | l >>> 31 & 1; | ||
for (var _i2 = 0, keysi = 0; _i2 < 8; ++_i2) { | ||
@@ -279,3 +270,2 @@ x = r << 28 | r >>> 4; | ||
} | ||
r = r << 31 | r >>> 1; | ||
@@ -297,18 +287,17 @@ x = (l ^ r) & 0xaaaaaaaa; | ||
l ^= x; | ||
r ^= x << 4; // Spread ints to bytes | ||
r ^= x << 4; | ||
// Spread ints to bytes | ||
x = [r, l]; | ||
for (i = 0; i < 8; i++) { | ||
b[i] = (x[i >>> 2] >>> 8 * (3 - i % 4)) % 256; | ||
if (b[i] < 0) { | ||
b[i] += 256; | ||
} // unsigned | ||
} | ||
return b; | ||
} // Encrypt 16 bytes of text using passwd as key | ||
} | ||
// Encrypt 16 bytes of text using passwd as key | ||
}, { | ||
@@ -320,6 +309,4 @@ key: "encrypt", | ||
}]); | ||
return DES; | ||
}(); | ||
exports["default"] = DES; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,51 +7,41 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("./util/logging.js")); | ||
var _base = _interopRequireDefault(require("./base64.js")); | ||
var _int = require("./util/int.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var Display = /*#__PURE__*/function () { | ||
function Display(target) { | ||
_classCallCheck(this, Display); | ||
this._drawCtx = null; | ||
this._renderQ = []; // queue drawing actions for in-oder rendering | ||
this._flushing = false; | ||
this._flushing = false; // the full frame buffer (logical canvas) size | ||
// the full frame buffer (logical canvas) size | ||
this._fbWidth = 0; | ||
this._fbHeight = 0; | ||
this._prevDrawStyle = ""; | ||
Log.Debug(">> Display.constructor"); // The visible canvas | ||
Log.Debug(">> Display.constructor"); | ||
// The visible canvas | ||
this._target = target; | ||
if (!this._target) { | ||
throw new Error("Target must be set"); | ||
} | ||
if (typeof this._target === 'string') { | ||
throw new Error('target must be a DOM element'); | ||
} | ||
if (!this._target.getContext) { | ||
throw new Error("no getContext method"); | ||
} | ||
this._targetCtx = this._target.getContext('2d'); | ||
this._targetCtx = this._target.getContext('2d'); // the visible canvas viewport (i.e. what actually gets seen) | ||
// the visible canvas viewport (i.e. what actually gets seen) | ||
this._viewportLoc = { | ||
@@ -64,4 +52,5 @@ 'x': 0, | ||
'h': this._target.height | ||
}; // The hidden canvas, where we do the actual rendering | ||
}; | ||
// The hidden canvas, where we do the actual rendering | ||
this._backbuffer = document.createElement('canvas'); | ||
@@ -76,12 +65,15 @@ this._drawCtx = this._backbuffer.getContext('2d'); | ||
Log.Debug("User Agent: " + navigator.userAgent); | ||
Log.Debug("<< Display.constructor"); // ===== PROPERTIES ===== | ||
Log.Debug("<< Display.constructor"); | ||
// ===== PROPERTIES ===== | ||
this._scale = 1.0; | ||
this._clipViewport = false; // ===== EVENT HANDLERS ===== | ||
this._clipViewport = false; | ||
// ===== EVENT HANDLERS ===== | ||
this.onflush = function () {}; // A flush request has finished | ||
} | ||
} // ===== PROPERTIES ===== | ||
// ===== PROPERTIES ===== | ||
_createClass(Display, [{ | ||
@@ -101,4 +93,4 @@ key: "scale", | ||
set: function set(viewport) { | ||
this._clipViewport = viewport; // May need to readjust the viewport dimensions | ||
this._clipViewport = viewport; | ||
// May need to readjust the viewport dimensions | ||
var vp = this._viewportLoc; | ||
@@ -117,4 +109,5 @@ this.viewportChangeSize(vp.w, vp.h); | ||
return this._fbHeight; | ||
} // ===== PUBLIC METHODS ===== | ||
} | ||
// ===== PUBLIC METHODS ===== | ||
}, { | ||
@@ -126,38 +119,30 @@ key: "viewportChangePos", | ||
deltaY = Math.floor(deltaY); | ||
if (!this._clipViewport) { | ||
deltaX = -vp.w; // clamped later of out of bounds | ||
deltaY = -vp.h; | ||
} | ||
var vx2 = vp.x + vp.w - 1; | ||
var vy2 = vp.y + vp.h - 1; // Position change | ||
var vy2 = vp.y + vp.h - 1; | ||
// Position change | ||
if (deltaX < 0 && vp.x + deltaX < 0) { | ||
deltaX = -vp.x; | ||
} | ||
if (vx2 + deltaX >= this._fbWidth) { | ||
deltaX -= vx2 + deltaX - this._fbWidth + 1; | ||
} | ||
if (vp.y + deltaY < 0) { | ||
deltaY = -vp.y; | ||
} | ||
if (vy2 + deltaY >= this._fbHeight) { | ||
deltaY -= vy2 + deltaY - this._fbHeight + 1; | ||
} | ||
if (deltaX === 0 && deltaY === 0) { | ||
return; | ||
} | ||
Log.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY); | ||
vp.x += deltaX; | ||
vp.y += deltaY; | ||
this._damage(vp.x, vp.y, vp.w, vp.h); | ||
this.flip(); | ||
@@ -173,16 +158,11 @@ } | ||
} | ||
width = Math.floor(width); | ||
height = Math.floor(height); | ||
if (width > this._fbWidth) { | ||
width = this._fbWidth; | ||
} | ||
if (height > this._fbHeight) { | ||
height = this._fbHeight; | ||
} | ||
var vp = this._viewportLoc; | ||
if (vp.w !== width || vp.h !== height) { | ||
@@ -193,10 +173,10 @@ vp.w = width; | ||
canvas.width = width; | ||
canvas.height = height; // The position might need to be updated if we've grown | ||
canvas.height = height; | ||
// The position might need to be updated if we've grown | ||
this.viewportChangePos(0, 0); | ||
this._damage(vp.x, vp.y, vp.w, vp.h); | ||
this.flip(); | ||
this.flip(); // Update the visible size of the target canvas | ||
// Update the visible size of the target canvas | ||
this._rescale(this._scale); | ||
@@ -211,3 +191,2 @@ } | ||
} | ||
return (0, _int.toSigned32bit)(x / this._scale + this._viewportLoc.x); | ||
@@ -221,3 +200,2 @@ } | ||
} | ||
return (0, _int.toSigned32bit)(y / this._scale + this._viewportLoc.y); | ||
@@ -232,31 +210,42 @@ } | ||
var canvas = this._backbuffer; | ||
if (canvas.width !== width || canvas.height !== height) { | ||
// We have to save the canvas data since changing the size will clear it | ||
var saveImg = null; | ||
if (canvas.width > 0 && canvas.height > 0) { | ||
saveImg = this._drawCtx.getImageData(0, 0, canvas.width, canvas.height); | ||
} | ||
if (canvas.width !== width) { | ||
canvas.width = width; | ||
} | ||
if (canvas.height !== height) { | ||
canvas.height = height; | ||
} | ||
if (saveImg) { | ||
this._drawCtx.putImageData(saveImg, 0, 0); | ||
} | ||
} // Readjust the viewport as it may be incorrectly sized | ||
} | ||
// Readjust the viewport as it may be incorrectly sized | ||
// and positioned | ||
var vp = this._viewportLoc; | ||
this.viewportChangeSize(vp.w, vp.h); | ||
this.viewportChangePos(0, 0); | ||
} // Track what parts of the visible canvas that need updating | ||
} | ||
}, { | ||
key: "getImageData", | ||
value: function getImageData() { | ||
return this._drawCtx.getImageData(0, 0, this.width, this.height); | ||
} | ||
}, { | ||
key: "toDataURL", | ||
value: function toDataURL(type, encoderOptions) { | ||
return this._backbuffer.toDataURL(type, encoderOptions); | ||
} | ||
}, { | ||
key: "toBlob", | ||
value: function toBlob(callback, type, quality) { | ||
return this._backbuffer.toBlob(callback, type, quality); | ||
} | ||
// Track what parts of the visible canvas that need updating | ||
}, { | ||
@@ -268,17 +257,15 @@ key: "_damage", | ||
} | ||
if (y < this._damageBounds.top) { | ||
this._damageBounds.top = y; | ||
} | ||
if (x + w > this._damageBounds.right) { | ||
this._damageBounds.right = x + w; | ||
} | ||
if (y + h > this._damageBounds.bottom) { | ||
this._damageBounds.bottom = y + h; | ||
} | ||
} // Update the visible canvas with the contents of the | ||
} | ||
// Update the visible canvas with the contents of the | ||
// rendering canvas | ||
}, { | ||
@@ -298,3 +285,2 @@ key: "flip", | ||
var vy = y - this._viewportLoc.y; | ||
if (vx < 0) { | ||
@@ -305,3 +291,2 @@ w += vx; | ||
} | ||
if (vy < 0) { | ||
@@ -312,11 +297,8 @@ h += vy; | ||
} | ||
if (vx + w > this._viewportLoc.w) { | ||
w = this._viewportLoc.w - vx; | ||
} | ||
if (vy + h > this._viewportLoc.h) { | ||
h = this._viewportLoc.h - vy; | ||
} | ||
if (w > 0 && h > 0) { | ||
@@ -328,3 +310,2 @@ // FIXME: We may need to disable image smoothing here | ||
} | ||
this._damageBounds.left = this._damageBounds.top = 65535; | ||
@@ -362,5 +343,3 @@ this._damageBounds.right = this._damageBounds.bottom = 0; | ||
this._setFillColor(color); | ||
this._drawCtx.fillRect(x, y, width, height); | ||
this._damage(x, y, width, height); | ||
@@ -394,5 +373,3 @@ } | ||
this._drawCtx.imageSmoothingEnabled = false; | ||
this._drawCtx.drawImage(this._backbuffer, oldX, oldY, w, h, newX, newY, w, h); | ||
this._damage(newX, newY, w, h); | ||
@@ -408,6 +385,4 @@ } | ||
} | ||
var img = new Image(); | ||
img.src = "data: " + mime + ";base64," + _base["default"].encode(arr); | ||
this._renderQPush({ | ||
@@ -431,3 +406,2 @@ 'type': 'img', | ||
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length)); | ||
this._renderQPush({ | ||
@@ -445,5 +419,3 @@ 'type': 'blit', | ||
var img = new ImageData(data, width, height); | ||
this._drawCtx.putImageData(img, x, y); | ||
this._damage(x, y, width, height); | ||
@@ -456,3 +428,2 @@ } | ||
this._drawCtx.drawImage(img, x, y); | ||
this._damage(x, y, img.width, img.height); | ||
@@ -464,3 +435,2 @@ } | ||
var scaleRatio; | ||
if (containerWidth === 0 || containerHeight === 0) { | ||
@@ -472,3 +442,2 @@ scaleRatio = 0; | ||
var fbAspectRatio = vp.w / vp.h; | ||
if (fbAspectRatio >= targetAspectRatio) { | ||
@@ -480,6 +449,6 @@ scaleRatio = containerWidth / vp.w; | ||
} | ||
this._rescale(scaleRatio); | ||
} // ===== PRIVATE METHODS ===== | ||
} | ||
// ===== PRIVATE METHODS ===== | ||
}, { | ||
@@ -489,10 +458,10 @@ key: "_rescale", | ||
this._scale = factor; | ||
var vp = this._viewportLoc; // NB(directxman12): If you set the width directly, or set the | ||
var vp = this._viewportLoc; | ||
// NB(directxman12): If you set the width directly, or set the | ||
// style width to a number, the canvas is cleared. | ||
// However, if you set the style width to a string | ||
// ('NNNpx'), the canvas is scaled without clearing. | ||
var width = factor * vp.w + 'px'; | ||
var height = factor * vp.h + 'px'; | ||
if (this._target.style.width !== width || this._target.style.height !== height) { | ||
@@ -507,3 +476,2 @@ this._target.style.width = width; | ||
var newStyle = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')'; | ||
if (newStyle !== this._prevDrawStyle) { | ||
@@ -518,3 +486,2 @@ this._drawCtx.fillStyle = newStyle; | ||
this._renderQ.push(action); | ||
if (this._renderQ.length === 1) { | ||
@@ -532,3 +499,2 @@ // If this can be rendered immediately it will be, otherwise | ||
this.removeEventListener('load', this._noVNCDisplay._resumeRenderQ); | ||
this._noVNCDisplay._scanRenderQ(); | ||
@@ -540,6 +506,4 @@ } | ||
var ready = true; | ||
while (ready && this._renderQ.length > 0) { | ||
var a = this._renderQ[0]; | ||
switch (a.type) { | ||
@@ -549,15 +513,11 @@ case 'flip': | ||
break; | ||
case 'copy': | ||
this.copyImage(a.oldX, a.oldY, a.x, a.y, a.width, a.height, true); | ||
break; | ||
case 'fill': | ||
this.fillRect(a.x, a.y, a.width, a.height, a.color, true); | ||
break; | ||
case 'blit': | ||
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true); | ||
break; | ||
case 'img': | ||
@@ -569,15 +529,12 @@ if (a.img.complete) { | ||
} | ||
this.drawImage(a.img, a.x, a.y); | ||
} else { | ||
a.img._noVNCDisplay = this; | ||
a.img.addEventListener('load', this._resumeRenderQ); // We need to wait for this image to 'load' | ||
a.img.addEventListener('load', this._resumeRenderQ); | ||
// We need to wait for this image to 'load' | ||
// to keep things in-order | ||
ready = false; | ||
} | ||
break; | ||
} | ||
if (ready) { | ||
@@ -587,3 +544,2 @@ this._renderQ.shift(); | ||
} | ||
if (this._renderQ.length === 0 && this._flushing) { | ||
@@ -595,6 +551,4 @@ this._flushing = false; | ||
}]); | ||
return Display; | ||
}(); | ||
exports["default"] = Display; |
@@ -8,3 +8,2 @@ "use strict"; | ||
exports.encodings = void 0; | ||
/* | ||
@@ -17,2 +16,3 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
var encodings = { | ||
@@ -44,3 +44,2 @@ encodingRaw: 0, | ||
exports.encodings = encodings; | ||
function encodingName(num) { | ||
@@ -50,24 +49,16 @@ switch (num) { | ||
return "Raw"; | ||
case encodings.encodingCopyRect: | ||
return "CopyRect"; | ||
case encodings.encodingRRE: | ||
return "RRE"; | ||
case encodings.encodingHextile: | ||
return "Hextile"; | ||
case encodings.encodingTight: | ||
return "Tight"; | ||
case encodings.encodingZRLE: | ||
return "ZRLE"; | ||
case encodings.encodingTightPNG: | ||
return "TightPNG"; | ||
case encodings.encodingJPEG: | ||
return "JPEG"; | ||
default: | ||
@@ -74,0 +65,0 @@ return "[unknown encoding " + num + "]"; |
@@ -7,19 +7,14 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _inflate2 = require("../lib/vendor/pako/lib/zlib/inflate.js"); | ||
var _zstream = _interopRequireDefault(require("../lib/vendor/pako/lib/zlib/zstream.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var Inflate = /*#__PURE__*/function () { | ||
function Inflate() { | ||
_classCallCheck(this, Inflate); | ||
this.strm = new _zstream["default"](); | ||
@@ -31,3 +26,2 @@ this.chunkSize = 1024 * 10 * 10; | ||
} | ||
_createClass(Inflate, [{ | ||
@@ -38,3 +32,2 @@ key: "setInput", | ||
//FIXME: flush remaining data. | ||
/* eslint-disable camelcase */ | ||
@@ -61,5 +54,4 @@ this.strm.input = null; | ||
} | ||
/* eslint-disable camelcase */ | ||
this.strm.next_out = 0; | ||
@@ -70,11 +62,8 @@ this.strm.avail_out = expected; | ||
var ret = (0, _inflate2.inflate)(this.strm, 0); // Flush argument not used. | ||
if (ret < 0) { | ||
throw new Error("zlib inflate failed"); | ||
} | ||
if (this.strm.next_out != expected) { | ||
throw new Error("Incomplete zlib block"); | ||
} | ||
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out); | ||
@@ -88,6 +77,4 @@ } | ||
}]); | ||
return Inflate; | ||
}(); | ||
exports["default"] = Inflate; |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _keysym = _interopRequireDefault(require("./keysym.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
/* | ||
@@ -25,4 +22,4 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
var DOMKeyTable = {}; | ||
function addStandard(key, standard) { | ||
@@ -33,3 +30,2 @@ if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\""); | ||
} | ||
function addLeftRight(key, left, right) { | ||
@@ -41,3 +37,2 @@ if (left === undefined) throw new Error("Undefined keysym for key \"" + key + "\""); | ||
} | ||
function addNumpad(key, standard, numpad) { | ||
@@ -48,4 +43,5 @@ if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\""); | ||
DOMKeyTable[key] = [standard, standard, standard, numpad]; | ||
} // 3.2. Modifier Keys | ||
} | ||
// 3.2. Modifier Keys | ||
@@ -55,12 +51,14 @@ addLeftRight("Alt", _keysym["default"].XK_Alt_L, _keysym["default"].XK_Alt_R); | ||
addStandard("CapsLock", _keysym["default"].XK_Caps_Lock); | ||
addLeftRight("Control", _keysym["default"].XK_Control_L, _keysym["default"].XK_Control_R); // - Fn | ||
addLeftRight("Control", _keysym["default"].XK_Control_L, _keysym["default"].XK_Control_R); | ||
// - Fn | ||
// - FnLock | ||
addLeftRight("Meta", _keysym["default"].XK_Super_L, _keysym["default"].XK_Super_R); | ||
addStandard("NumLock", _keysym["default"].XK_Num_Lock); | ||
addStandard("ScrollLock", _keysym["default"].XK_Scroll_Lock); | ||
addLeftRight("Shift", _keysym["default"].XK_Shift_L, _keysym["default"].XK_Shift_R); // - Symbol | ||
addLeftRight("Shift", _keysym["default"].XK_Shift_L, _keysym["default"].XK_Shift_R); | ||
// - Symbol | ||
// - SymbolLock | ||
// - Hyper | ||
// - Super | ||
// 3.3. Whitespace Keys | ||
@@ -70,4 +68,6 @@ | ||
addStandard("Tab", _keysym["default"].XK_Tab); | ||
addNumpad(" ", _keysym["default"].XK_space, _keysym["default"].XK_KP_Space); // 3.4. Navigation Keys | ||
addNumpad(" ", _keysym["default"].XK_space, _keysym["default"].XK_KP_Space); | ||
// 3.4. Navigation Keys | ||
addNumpad("ArrowDown", _keysym["default"].XK_Down, _keysym["default"].XK_KP_Down); | ||
@@ -80,23 +80,27 @@ addNumpad("ArrowLeft", _keysym["default"].XK_Left, _keysym["default"].XK_KP_Left); | ||
addNumpad("PageDown", _keysym["default"].XK_Next, _keysym["default"].XK_KP_Next); | ||
addNumpad("PageUp", _keysym["default"].XK_Prior, _keysym["default"].XK_KP_Prior); // 3.5. Editing Keys | ||
addNumpad("PageUp", _keysym["default"].XK_Prior, _keysym["default"].XK_KP_Prior); | ||
addStandard("Backspace", _keysym["default"].XK_BackSpace); // Browsers send "Clear" for the numpad 5 without NumLock because | ||
// 3.5. Editing Keys | ||
addStandard("Backspace", _keysym["default"].XK_BackSpace); | ||
// Browsers send "Clear" for the numpad 5 without NumLock because | ||
// Windows uses VK_Clear for that key. But Unix expects KP_Begin for | ||
// that scenario. | ||
addNumpad("Clear", _keysym["default"].XK_Clear, _keysym["default"].XK_KP_Begin); | ||
addStandard("Copy", _keysym["default"].XF86XK_Copy); // - CrSel | ||
addStandard("Copy", _keysym["default"].XF86XK_Copy); | ||
// - CrSel | ||
addStandard("Cut", _keysym["default"].XF86XK_Cut); | ||
addNumpad("Delete", _keysym["default"].XK_Delete, _keysym["default"].XK_KP_Delete); // - EraseEof | ||
addNumpad("Delete", _keysym["default"].XK_Delete, _keysym["default"].XK_KP_Delete); | ||
// - EraseEof | ||
// - ExSel | ||
addNumpad("Insert", _keysym["default"].XK_Insert, _keysym["default"].XK_KP_Insert); | ||
addStandard("Paste", _keysym["default"].XF86XK_Paste); | ||
addStandard("Redo", _keysym["default"].XK_Redo); | ||
addStandard("Undo", _keysym["default"].XK_Undo); // 3.6. UI Keys | ||
addStandard("Undo", _keysym["default"].XK_Undo); | ||
// 3.6. UI Keys | ||
// - Accept | ||
// - Again (could just be XK_Redo) | ||
// - Attn | ||
addStandard("Cancel", _keysym["default"].XK_Cancel); | ||
@@ -108,9 +112,11 @@ addStandard("ContextMenu", _keysym["default"].XK_Menu); | ||
addStandard("Help", _keysym["default"].XK_Help); | ||
addStandard("Pause", _keysym["default"].XK_Pause); // - Play | ||
addStandard("Pause", _keysym["default"].XK_Pause); | ||
// - Play | ||
// - Props | ||
addStandard("Select", _keysym["default"].XK_Select); | ||
addStandard("ZoomIn", _keysym["default"].XF86XK_ZoomIn); | ||
addStandard("ZoomOut", _keysym["default"].XF86XK_ZoomOut); // 3.7. Device Keys | ||
addStandard("ZoomOut", _keysym["default"].XF86XK_ZoomOut); | ||
// 3.7. Device Keys | ||
addStandard("BrightnessDown", _keysym["default"].XF86XK_MonBrightnessDown); | ||
@@ -125,4 +131,6 @@ addStandard("BrightnessUp", _keysym["default"].XF86XK_MonBrightnessUp); | ||
addStandard("Standby", _keysym["default"].XF86XK_Standby); | ||
addStandard("WakeUp", _keysym["default"].XF86XK_WakeUp); // 3.8. IME and Composition Keys | ||
addStandard("WakeUp", _keysym["default"].XF86XK_WakeUp); | ||
// 3.8. IME and Composition Keys | ||
addStandard("AllCandidates", _keysym["default"].XK_MultipleCandidate); | ||
@@ -132,14 +140,14 @@ addStandard("Alphanumeric", _keysym["default"].XK_Eisu_toggle); | ||
addStandard("Compose", _keysym["default"].XK_Multi_key); | ||
addStandard("Convert", _keysym["default"].XK_Henkan); // - Dead | ||
addStandard("Convert", _keysym["default"].XK_Henkan); | ||
// - Dead | ||
// - FinalMode | ||
addStandard("GroupFirst", _keysym["default"].XK_ISO_First_Group); | ||
addStandard("GroupLast", _keysym["default"].XK_ISO_Last_Group); | ||
addStandard("GroupNext", _keysym["default"].XK_ISO_Next_Group); | ||
addStandard("GroupPrevious", _keysym["default"].XK_ISO_Prev_Group); // - ModeChange (XK_Mode_switch is often used for AltGr) | ||
addStandard("GroupPrevious", _keysym["default"].XK_ISO_Prev_Group); | ||
// - ModeChange (XK_Mode_switch is often used for AltGr) | ||
// - NextCandidate | ||
addStandard("NonConvert", _keysym["default"].XK_Muhenkan); | ||
addStandard("PreviousCandidate", _keysym["default"].XK_PreviousCandidate); // - Process | ||
addStandard("PreviousCandidate", _keysym["default"].XK_PreviousCandidate); | ||
// - Process | ||
addStandard("SingleCandidate", _keysym["default"].XK_SingleCandidate); | ||
@@ -154,3 +162,2 @@ addStandard("HangulMode", _keysym["default"].XK_Hangul); | ||
addStandard("KanaMode", _keysym["default"].XK_Kana_Shift); // could also be _Kana_Lock | ||
addStandard("KanjiMode", _keysym["default"].XK_Kanji); | ||
@@ -160,4 +167,6 @@ addStandard("Katakana", _keysym["default"].XK_Katakana); | ||
addStandard("Zenkaku", _keysym["default"].XK_Zenkaku); | ||
addStandard("ZenkakuHankaku", _keysym["default"].XK_Zenkaku_Hankaku); // 3.9. General-Purpose Function Keys | ||
addStandard("ZenkakuHankaku", _keysym["default"].XK_Zenkaku_Hankaku); | ||
// 3.9. General-Purpose Function Keys | ||
addStandard("F1", _keysym["default"].XK_F1); | ||
@@ -197,16 +206,18 @@ addStandard("F2", _keysym["default"].XK_F2); | ||
addStandard("F34", _keysym["default"].XK_F34); | ||
addStandard("F35", _keysym["default"].XK_F35); // - Soft1... | ||
addStandard("F35", _keysym["default"].XK_F35); | ||
// - Soft1... | ||
// 3.10. Multimedia Keys | ||
// - ChannelDown | ||
// - ChannelUp | ||
addStandard("Close", _keysym["default"].XF86XK_Close); | ||
addStandard("MailForward", _keysym["default"].XF86XK_MailForward); | ||
addStandard("MailReply", _keysym["default"].XF86XK_Reply); | ||
addStandard("MailSend", _keysym["default"].XF86XK_Send); // - MediaClose | ||
addStandard("MailSend", _keysym["default"].XF86XK_Send); | ||
// - MediaClose | ||
addStandard("MediaFastForward", _keysym["default"].XF86XK_AudioForward); | ||
addStandard("MediaPause", _keysym["default"].XF86XK_AudioPause); | ||
addStandard("MediaPlay", _keysym["default"].XF86XK_AudioPlay); // - MediaPlayPause | ||
addStandard("MediaPlay", _keysym["default"].XF86XK_AudioPlay); | ||
// - MediaPlayPause | ||
addStandard("MediaRecord", _keysym["default"].XF86XK_AudioRecord); | ||
@@ -221,6 +232,11 @@ addStandard("MediaRewind", _keysym["default"].XF86XK_AudioRewind); | ||
addStandard("Save", _keysym["default"].XF86XK_Save); | ||
addStandard("SpellCheck", _keysym["default"].XF86XK_Spell); // 3.11. Multimedia Numpad Keys | ||
addStandard("SpellCheck", _keysym["default"].XF86XK_Spell); | ||
// 3.11. Multimedia Numpad Keys | ||
// - Key11 | ||
// - Key12 | ||
// 3.12. Audio Keys | ||
// - AudioBalanceLeft | ||
@@ -236,12 +252,15 @@ // - AudioBalanceRight | ||
// - AudioTrebleUp | ||
addStandard("AudioVolumeDown", _keysym["default"].XF86XK_AudioLowerVolume); | ||
addStandard("AudioVolumeUp", _keysym["default"].XF86XK_AudioRaiseVolume); | ||
addStandard("AudioVolumeMute", _keysym["default"].XF86XK_AudioMute); // - MicrophoneToggle | ||
addStandard("AudioVolumeMute", _keysym["default"].XF86XK_AudioMute); | ||
// - MicrophoneToggle | ||
// - MicrophoneVolumeDown | ||
// - MicrophoneVolumeUp | ||
addStandard("MicrophoneVolumeMute", _keysym["default"].XF86XK_AudioMicMute); | ||
addStandard("MicrophoneVolumeMute", _keysym["default"].XF86XK_AudioMicMute); // 3.13. Speech Keys | ||
// 3.13. Speech Keys | ||
// - SpeechCorrectionList | ||
// - SpeechInputToggle | ||
// 3.14. Application Keys | ||
@@ -251,4 +270,4 @@ | ||
addStandard("LaunchApplication2", _keysym["default"].XF86XK_Calculator); | ||
addStandard("LaunchCalendar", _keysym["default"].XF86XK_Calendar); // - LaunchContacts | ||
addStandard("LaunchCalendar", _keysym["default"].XF86XK_Calendar); | ||
// - LaunchContacts | ||
addStandard("LaunchMail", _keysym["default"].XF86XK_Mail); | ||
@@ -262,4 +281,6 @@ addStandard("LaunchMediaPlayer", _keysym["default"].XF86XK_AudioMedia); | ||
addStandard("LaunchWebCam", _keysym["default"].XF86XK_WebCam); | ||
addStandard("LaunchWordProcessor", _keysym["default"].XF86XK_Word); // 3.15. Browser Keys | ||
addStandard("LaunchWordProcessor", _keysym["default"].XF86XK_Word); | ||
// 3.15. Browser Keys | ||
addStandard("BrowserBack", _keysym["default"].XF86XK_Back); | ||
@@ -271,9 +292,15 @@ addStandard("BrowserFavorites", _keysym["default"].XF86XK_Favorites); | ||
addStandard("BrowserSearch", _keysym["default"].XF86XK_Search); | ||
addStandard("BrowserStop", _keysym["default"].XF86XK_Stop); // 3.16. Mobile Phone Keys | ||
addStandard("BrowserStop", _keysym["default"].XF86XK_Stop); | ||
// 3.16. Mobile Phone Keys | ||
// - A whole bunch... | ||
// 3.17. TV Keys | ||
// - A whole bunch... | ||
// 3.18. Media Controller Keys | ||
// - A whole bunch... | ||
addStandard("Dimmer", _keysym["default"].XF86XK_BrightnessAdjust); | ||
@@ -284,4 +311,6 @@ addStandard("MediaAudioTrack", _keysym["default"].XF86XK_AudioCycleTrack); | ||
addStandard("Subtitle", _keysym["default"].XF86XK_Subtitle); | ||
addStandard("VideoModeNext", _keysym["default"].XF86XK_Next_VMode); // Extra: Numpad | ||
addStandard("VideoModeNext", _keysym["default"].XF86XK_Next_VMode); | ||
// Extra: Numpad | ||
addNumpad("=", _keysym["default"].XK_equal, _keysym["default"].XK_KP_Equal); | ||
@@ -288,0 +317,0 @@ addNumpad("+", _keysym["default"].XK_plus, _keysym["default"].XK_KP_Add); |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = void 0; | ||
/* | ||
@@ -14,3 +13,2 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
/* | ||
@@ -25,8 +23,9 @@ * Fallback mapping between HTML key codes (physical keys) and | ||
*/ | ||
/* eslint-disable key-spacing */ | ||
var _default = { | ||
// 3.1.1.1. Writing System Keys | ||
'Backspace': 'Backspace', | ||
// 3.1.1.2. Functional Keys | ||
'AltLeft': 'Alt', | ||
@@ -46,3 +45,5 @@ 'AltRight': 'Alt', | ||
// FIXME: Japanese/Korean keys | ||
// 3.1.2. Control Pad Section | ||
'Delete': 'Delete', | ||
@@ -56,2 +57,3 @@ 'End': 'End', | ||
// 3.1.3. Arrow Pad Section | ||
'ArrowDown': 'ArrowDown', | ||
@@ -62,2 +64,3 @@ 'ArrowLeft': 'ArrowLeft', | ||
// 3.1.4. Numpad Section | ||
'NumLock': 'NumLock', | ||
@@ -67,2 +70,3 @@ 'NumpadBackspace': 'Backspace', | ||
// 3.1.5. Function Section | ||
'Escape': 'Escape', | ||
@@ -108,2 +112,3 @@ 'F1': 'F1', | ||
// 3.1.6. Media Keys | ||
'BrowserBack': 'BrowserBack', | ||
@@ -110,0 +115,0 @@ 'BrowserFavorites': 'BrowserFavorites', |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
/* | ||
@@ -23,2 +22,3 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
var GH_NOGESTURE = 0; | ||
@@ -35,16 +35,17 @@ var GH_ONETAP = 1; | ||
var GH_ANGLE_THRESHOLD = 90; // Degrees | ||
// Timeout when waiting for gestures (ms) | ||
var GH_MULTITOUCH_TIMEOUT = 250; | ||
var GH_MULTITOUCH_TIMEOUT = 250; // Maximum time between press and release for a tap (ms) | ||
// Maximum time between press and release for a tap (ms) | ||
var GH_TAP_TIMEOUT = 1000; | ||
var GH_TAP_TIMEOUT = 1000; // Timeout when waiting for longpress (ms) | ||
// Timeout when waiting for longpress (ms) | ||
var GH_LONGPRESS_TIMEOUT = 1000; | ||
var GH_LONGPRESS_TIMEOUT = 1000; // Timeout when waiting to decide between PINCH and TWODRAG (ms) | ||
// Timeout when waiting to decide between PINCH and TWODRAG (ms) | ||
var GH_TWOTOUCH_TIMEOUT = 50; | ||
var GestureHandler = /*#__PURE__*/function () { | ||
function GestureHandler() { | ||
_classCallCheck(this, GestureHandler); | ||
this._target = null; | ||
@@ -60,3 +61,2 @@ this._state = GH_INITSTATE; | ||
} | ||
_createClass(GestureHandler, [{ | ||
@@ -67,9 +67,5 @@ key: "attach", | ||
this._target = target; | ||
this._target.addEventListener('touchstart', this._boundEventHandler); | ||
this._target.addEventListener('touchmove', this._boundEventHandler); | ||
this._target.addEventListener('touchend', this._boundEventHandler); | ||
this._target.addEventListener('touchcancel', this._boundEventHandler); | ||
@@ -83,15 +79,8 @@ } | ||
} | ||
this._stopLongpressTimeout(); | ||
this._stopTwoTouchTimeout(); | ||
this._target.removeEventListener('touchstart', this._boundEventHandler); | ||
this._target.removeEventListener('touchmove', this._boundEventHandler); | ||
this._target.removeEventListener('touchend', this._boundEventHandler); | ||
this._target.removeEventListener('touchcancel', this._boundEventHandler); | ||
this._target = null; | ||
@@ -105,3 +94,2 @@ } | ||
e.preventDefault(); | ||
switch (e.type) { | ||
@@ -111,7 +99,5 @@ case 'touchstart': | ||
break; | ||
case 'touchmove': | ||
fn = this._touchMove; | ||
break; | ||
case 'touchend': | ||
@@ -122,3 +108,2 @@ case 'touchcancel': | ||
} | ||
for (var i = 0; i < e.changedTouches.length; i++) { | ||
@@ -136,26 +121,20 @@ var touch = e.changedTouches[i]; | ||
this._ignored.push(id); | ||
return; | ||
} | ||
return; | ||
} // Did it take too long between touches that we should no longer | ||
// Did it take too long between touches that we should no longer | ||
// consider this a single gesture? | ||
if (this._tracked.length > 0 && Date.now() - this._tracked[0].started > GH_MULTITOUCH_TIMEOUT) { | ||
this._state = GH_NOGESTURE; | ||
this._ignored.push(id); | ||
return; | ||
} | ||
return; | ||
} // If we're waiting for fingers to release then we should no longer | ||
// If we're waiting for fingers to release then we should no longer | ||
// recognize new touches | ||
if (this._waitingRelease) { | ||
this._state = GH_NOGESTURE; | ||
this._ignored.push(id); | ||
return; | ||
} | ||
this._tracked.push({ | ||
@@ -171,20 +150,13 @@ id: id, | ||
}); | ||
switch (this._tracked.length) { | ||
case 1: | ||
this._startLongpressTimeout(); | ||
break; | ||
case 2: | ||
this._state &= ~(GH_ONETAP | GH_DRAG | GH_LONGPRESS); | ||
this._stopLongpressTimeout(); | ||
break; | ||
case 3: | ||
this._state &= ~(GH_TWOTAP | GH_TWODRAG | GH_PINCH); | ||
break; | ||
default: | ||
@@ -199,19 +171,19 @@ this._state = GH_NOGESTURE; | ||
return t.id === id; | ||
}); // If this is an update for a touch we're not tracking, ignore it | ||
}); | ||
// If this is an update for a touch we're not tracking, ignore it | ||
if (touch === undefined) { | ||
return; | ||
} // Update the touches last position with the event coordinates | ||
} | ||
// Update the touches last position with the event coordinates | ||
touch.lastX = x; | ||
touch.lastY = y; | ||
var deltaX = x - touch.firstX; | ||
var deltaY = y - touch.firstY; // Update angle when the touch has moved | ||
var deltaY = y - touch.firstY; | ||
// Update angle when the touch has moved | ||
if (touch.firstX !== touch.lastX || touch.firstY !== touch.lastY) { | ||
touch.angle = Math.atan2(deltaY, deltaX) * 180 / Math.PI; | ||
} | ||
if (!this._hasDetectedGesture()) { | ||
@@ -221,19 +193,16 @@ // Ignore moves smaller than the minimum threshold | ||
return; | ||
} // Can't be a tap or long press as we've seen movement | ||
} | ||
// Can't be a tap or long press as we've seen movement | ||
this._state &= ~(GH_ONETAP | GH_TWOTAP | GH_THREETAP | GH_LONGPRESS); | ||
this._stopLongpressTimeout(); | ||
if (this._tracked.length !== 1) { | ||
this._state &= ~GH_DRAG; | ||
} | ||
if (this._tracked.length !== 2) { | ||
this._state &= ~(GH_TWODRAG | GH_PINCH); | ||
} // We need to figure out which of our different two touch gestures | ||
} | ||
// We need to figure out which of our different two touch gestures | ||
// this might be | ||
if (this._tracked.length === 2) { | ||
@@ -243,14 +212,16 @@ // The other touch is the one where the id doesn't match | ||
return t.id !== id; | ||
}); // How far the previous touch point has moved since start | ||
}); | ||
// How far the previous touch point has moved since start | ||
var prevDeltaMove = Math.hypot(prevTouch.firstX - prevTouch.lastX, prevTouch.firstY - prevTouch.lastY); | ||
var prevDeltaMove = Math.hypot(prevTouch.firstX - prevTouch.lastX, prevTouch.firstY - prevTouch.lastY); // We know that the current touch moved far enough, | ||
// We know that the current touch moved far enough, | ||
// but unless both touches moved further than their | ||
// threshold we don't want to disqualify any gestures | ||
if (prevDeltaMove > GH_MOVE_THRESHOLD) { | ||
// The angle difference between the direction of the touch points | ||
var deltaAngle = Math.abs(touch.angle - prevTouch.angle); | ||
deltaAngle = Math.abs((deltaAngle + 180) % 360 - 180); // PINCH or TWODRAG can be eliminated depending on the angle | ||
deltaAngle = Math.abs((deltaAngle + 180) % 360 - 180); | ||
// PINCH or TWODRAG can be eliminated depending on the angle | ||
if (deltaAngle > GH_ANGLE_THRESHOLD) { | ||
@@ -261,3 +232,2 @@ this._state &= ~GH_TWODRAG; | ||
} | ||
if (this._isTwoTouchTimeoutRunning()) { | ||
@@ -272,10 +242,7 @@ this._stopTwoTouchTimeout(); | ||
} | ||
if (!this._hasDetectedGesture()) { | ||
return; | ||
} | ||
this._pushEvent('gesturestart'); | ||
} | ||
this._pushEvent('gesturemove'); | ||
@@ -289,5 +256,5 @@ } | ||
// Remove this touch from ignored | ||
this._ignored.splice(this._ignored.indexOf(id), 1); // And reset the state if there are no more touches | ||
this._ignored.splice(this._ignored.indexOf(id), 1); | ||
// And reset the state if there are no more touches | ||
if (this._ignored.length === 0 && this._tracked.length === 0) { | ||
@@ -297,27 +264,24 @@ this._state = GH_INITSTATE; | ||
} | ||
return; | ||
} | ||
return; | ||
} // We got a touchend before the timer triggered, | ||
// We got a touchend before the timer triggered, | ||
// this cannot result in a gesture anymore. | ||
if (!this._hasDetectedGesture() && this._isTwoTouchTimeoutRunning()) { | ||
this._stopTwoTouchTimeout(); | ||
this._state = GH_NOGESTURE; | ||
} // Some gestures don't trigger until a touch is released | ||
} | ||
// Some gestures don't trigger until a touch is released | ||
if (!this._hasDetectedGesture()) { | ||
// Can't be a gesture that relies on movement | ||
this._state &= ~(GH_DRAG | GH_TWODRAG | GH_PINCH); // Or something that relies on more time | ||
this._state &= ~(GH_DRAG | GH_TWODRAG | GH_PINCH); | ||
// Or something that relies on more time | ||
this._state &= ~GH_LONGPRESS; | ||
this._stopLongpressTimeout(); | ||
if (!this._waitingRelease) { | ||
this._releaseStart = Date.now(); | ||
this._waitingRelease = true; // Can't be a tap that requires more touches than we current have | ||
this._waitingRelease = true; | ||
// Can't be a tap that requires more touches than we current have | ||
switch (this._tracked.length) { | ||
@@ -327,3 +291,2 @@ case 1: | ||
break; | ||
case 2: | ||
@@ -334,5 +297,5 @@ this._state &= ~(GH_ONETAP | GH_THREETAP); | ||
} | ||
} // Waiting for all touches to release? (i.e. some tap) | ||
} | ||
// Waiting for all touches to release? (i.e. some tap) | ||
if (this._waitingRelease) { | ||
@@ -342,5 +305,5 @@ // Were all touches released at roughly the same time? | ||
this._state = GH_NOGESTURE; | ||
} // Did too long time pass between press and release? | ||
} | ||
// Did too long time pass between press and release? | ||
if (this._tracked.some(function (t) { | ||
@@ -351,9 +314,8 @@ return Date.now() - t.started > GH_TAP_TIMEOUT; | ||
} | ||
var touch = this._tracked.find(function (t) { | ||
return t.id === id; | ||
}); | ||
touch.active = false; | ||
touch.active = false; // Are we still waiting for more releases? | ||
// Are we still waiting for more releases? | ||
if (this._hasDetectedGesture()) { | ||
@@ -368,8 +330,7 @@ this._pushEvent('gesturestart'); | ||
} | ||
if (this._hasDetectedGesture()) { | ||
this._pushEvent('gestureend'); | ||
} // Ignore any remaining touches until they are ended | ||
} | ||
// Ignore any remaining touches until they are ended | ||
for (var i = 0; i < this._tracked.length; i++) { | ||
@@ -380,11 +341,11 @@ if (this._tracked[i].active) { | ||
} | ||
this._tracked = []; | ||
this._state = GH_NOGESTURE; // Remove this touch from ignored if it's in there | ||
this._state = GH_NOGESTURE; | ||
// Remove this touch from ignored if it's in there | ||
if (this._ignored.indexOf(id) !== -1) { | ||
this._ignored.splice(this._ignored.indexOf(id), 1); | ||
} // We reset the state if ignored is empty | ||
} | ||
// We reset the state if ignored is empty | ||
if (this._ignored.length === 0) { | ||
@@ -400,12 +361,11 @@ this._state = GH_INITSTATE; | ||
return false; | ||
} // Check to see if the bitmask value is a power of 2 | ||
} | ||
// Check to see if the bitmask value is a power of 2 | ||
// (i.e. only one bit set). If it is, we have a state. | ||
if (this._state & this._state - 1) { | ||
return false; | ||
} // For taps we also need to have all touches released | ||
} | ||
// For taps we also need to have all touches released | ||
// before we've fully detected the gesture | ||
if (this._state & (GH_ONETAP | GH_TWOTAP | GH_THREETAP)) { | ||
@@ -418,3 +378,2 @@ if (this._tracked.some(function (t) { | ||
} | ||
return true; | ||
@@ -426,5 +385,3 @@ } | ||
var _this = this; | ||
this._stopLongpressTimeout(); | ||
this._longpressTimeoutId = setTimeout(function () { | ||
@@ -446,5 +403,3 @@ return _this._longpressTimeout(); | ||
} | ||
this._state = GH_LONGPRESS; | ||
this._pushEvent('gesturestart'); | ||
@@ -456,5 +411,3 @@ } | ||
var _this2 = this; | ||
this._stopTwoTouchTimeout(); | ||
this._twoTouchTimeoutId = setTimeout(function () { | ||
@@ -480,15 +433,13 @@ return _this2._twoTouchTimeout(); | ||
throw new Error("A pinch or two drag gesture failed, no tracked touches"); | ||
} // How far each touch point has moved since start | ||
} | ||
// How far each touch point has moved since start | ||
var avgM = this._getAverageMovement(); | ||
var avgMoveH = Math.abs(avgM.x); | ||
var avgMoveV = Math.abs(avgM.y); | ||
var avgMoveH = Math.abs(avgM.x); | ||
var avgMoveV = Math.abs(avgM.y); // The difference in the distance between where | ||
// The difference in the distance between where | ||
// the touch points started and where they are now | ||
var avgD = this._getAverageDistance(); | ||
var deltaTouchDistance = Math.abs(Math.hypot(avgD.first.x, avgD.first.y) - Math.hypot(avgD.last.x, avgD.last.y)); | ||
if (avgMoveV < deltaTouchDistance && avgMoveH < deltaTouchDistance) { | ||
@@ -499,5 +450,3 @@ this._state = GH_PINCH; | ||
} | ||
this._pushEvent('gesturestart'); | ||
this._pushEvent('gesturemove'); | ||
@@ -510,16 +459,17 @@ } | ||
type: this._stateToGesture(this._state) | ||
}; // For most gesture events the current (average) position is the | ||
}; | ||
// For most gesture events the current (average) position is the | ||
// most useful | ||
var avg = this._getPosition(); | ||
var pos = avg.last; | ||
var pos = avg.last; // However we have a slight distance to detect gestures, so for the | ||
// However we have a slight distance to detect gestures, so for the | ||
// first gesture event we want to use the first positions we saw | ||
if (type === 'gesturestart') { | ||
pos = avg.first; | ||
} // For these gestures, we always want the event coordinates | ||
} | ||
// For these gestures, we always want the event coordinates | ||
// to be where the gesture began, not the current touch location. | ||
switch (this._state) { | ||
@@ -531,10 +481,10 @@ case GH_TWODRAG: | ||
} | ||
detail['clientX'] = pos.x; | ||
detail['clientY'] = pos.y; | ||
detail['clientX'] = pos.x; | ||
detail['clientY'] = pos.y; // FIXME: other coordinates? | ||
// FIXME: other coordinates? | ||
// Some gestures also have a magnitude | ||
if (this._state === GH_PINCH) { | ||
var distance = this._getAverageDistance(); | ||
if (type === 'gesturestart') { | ||
@@ -553,3 +503,2 @@ detail['magnitudeX'] = distance.first.x; | ||
var movement = this._getAverageMovement(); | ||
detail['magnitudeX'] = movement.x; | ||
@@ -559,7 +508,5 @@ detail['magnitudeY'] = movement.y; | ||
} | ||
var gev = new CustomEvent(type, { | ||
detail: detail | ||
}); | ||
this._target.dispatchEvent(gev); | ||
@@ -573,22 +520,15 @@ } | ||
return 'onetap'; | ||
case GH_TWOTAP: | ||
return 'twotap'; | ||
case GH_THREETAP: | ||
return 'threetap'; | ||
case GH_DRAG: | ||
return 'drag'; | ||
case GH_LONGPRESS: | ||
return 'longpress'; | ||
case GH_TWODRAG: | ||
return 'twodrag'; | ||
case GH_PINCH: | ||
return 'pinch'; | ||
} | ||
throw new Error("Unknown gesture state: " + state); | ||
@@ -602,9 +542,7 @@ } | ||
} | ||
var size = this._tracked.length; | ||
var fx = 0, | ||
fy = 0, | ||
lx = 0, | ||
ly = 0; | ||
fy = 0, | ||
lx = 0, | ||
ly = 0; | ||
for (var i = 0; i < this._tracked.length; i++) { | ||
@@ -616,3 +554,2 @@ fx += this._tracked[i].firstX; | ||
} | ||
return { | ||
@@ -635,7 +572,5 @@ first: { | ||
} | ||
var totalH, totalV; | ||
totalH = totalV = 0; | ||
var size = this._tracked.length; | ||
for (var i = 0; i < this._tracked.length; i++) { | ||
@@ -645,3 +580,2 @@ totalH += this._tracked[i].lastX - this._tracked[i].firstX; | ||
} | ||
return { | ||
@@ -657,4 +591,5 @@ x: totalH / size, | ||
throw new Error("Failed to get gesture distance, no tracked touches"); | ||
} // Distance between the first and last tracked touches | ||
} | ||
// Distance between the first and last tracked touches | ||
@@ -679,6 +614,4 @@ var first = this._tracked[0]; | ||
}]); | ||
return GestureHandler; | ||
}(); | ||
exports["default"] = GestureHandler; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,25 +7,16 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("../util/logging.js")); | ||
var _events = require("../util/events.js"); | ||
var KeyboardUtil = _interopRequireWildcard(require("./util.js")); | ||
var _keysym = _interopRequireDefault(require("./keysym.js")); | ||
var browser = _interopRequireWildcard(require("../util/browser.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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; } | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
// | ||
@@ -39,10 +28,8 @@ // Keyboard event handler | ||
_classCallCheck(this, Keyboard); | ||
this._target = target || null; | ||
this._keyDownList = {}; // List of depressed keys | ||
// (even if they are happy) | ||
this._altGrArmed = false; // Windows AltGr detection | ||
this._altGrArmed = false; // Windows AltGr detection | ||
// keep these here so we can refer to them later | ||
this._eventHandlers = { | ||
@@ -52,9 +39,10 @@ 'keyup': this._handleKeyUp.bind(this), | ||
'blur': this._allKeysUp.bind(this) | ||
}; // ===== EVENT HANDLERS ===== | ||
}; | ||
// ===== EVENT HANDLERS ===== | ||
this.onkeyevent = function () {}; // Handler for key press/release | ||
} | ||
} // ===== PRIVATE METHODS ===== | ||
// ===== PRIVATE METHODS ===== | ||
_createClass(Keyboard, [{ | ||
@@ -70,6 +58,4 @@ key: "_sendKeyEvent", | ||
} | ||
delete this._keyDownList[code]; | ||
} | ||
Log.Debug("onkeyevent " + (down ? "down" : "up") + ", keysym: " + keysym, ", code: " + code); | ||
@@ -82,8 +68,7 @@ this.onkeyevent(keysym, code, down); | ||
var code = KeyboardUtil.getKeycode(e); | ||
if (code !== 'Unidentified') { | ||
return code; | ||
} // Unstable, but we don't have anything else to go on | ||
} | ||
// Unstable, but we don't have anything else to go on | ||
if (e.keyCode) { | ||
@@ -94,6 +79,6 @@ // 229 is used for composition events | ||
} | ||
} // A precursor to the final DOM3 standard. Unfortunately it | ||
} | ||
// A precursor to the final DOM3 standard. Unfortunately it | ||
// is not layout independent, so it is as bad as using keyCode | ||
if (e.keyIdentifier) { | ||
@@ -104,10 +89,6 @@ // Non-character key? | ||
} | ||
var codepoint = parseInt(e.keyIdentifier.substr(2), 16); | ||
var _char = String.fromCharCode(codepoint).toUpperCase(); | ||
return 'Platform' + _char.charCodeAt(); | ||
} | ||
return 'Unidentified'; | ||
@@ -119,4 +100,5 @@ } | ||
var code = this._getKeyCode(e); | ||
var keysym = KeyboardUtil.getKeysym(e); | ||
var keysym = KeyboardUtil.getKeysym(e); // Windows doesn't have a proper AltGr, but handles it using | ||
// Windows doesn't have a proper AltGr, but handles it using | ||
// fake Ctrl+Alt. However the remote end might not be Windows, | ||
@@ -126,7 +108,5 @@ // so we need to merge those in to a single AltGr event. We | ||
// each other with a very short time between them (<50ms). | ||
if (this._altGrArmed) { | ||
this._altGrArmed = false; | ||
clearTimeout(this._altGrTimeout); | ||
if (code === "AltRight" && e.timeStamp - this._altGrCtrlTime < 50) { | ||
@@ -144,6 +124,6 @@ // FIXME: We fail to detect this if either Ctrl key is | ||
} | ||
} // We cannot handle keys we cannot track, but we also need | ||
} | ||
// We cannot handle keys we cannot track, but we also need | ||
// to deal with virtual keyboards which omit key info | ||
if (code === 'Unidentified') { | ||
@@ -155,14 +135,12 @@ if (keysym) { | ||
this._sendKeyEvent(keysym, code, true); | ||
this._sendKeyEvent(keysym, code, false); | ||
} | ||
(0, _events.stopEvent)(e); | ||
return; | ||
} // Alt behaves more like AltGraph on macOS, so shuffle the | ||
} | ||
// Alt behaves more like AltGraph on macOS, so shuffle the | ||
// keys around a bit to make things more sane for the remote | ||
// server. This method is used by RealVNC and TigerVNC (and | ||
// possibly others). | ||
if (browser.isMac() || browser.isIOS()) { | ||
@@ -173,11 +151,8 @@ switch (keysym) { | ||
break; | ||
case _keysym["default"].XK_Super_R: | ||
keysym = _keysym["default"].XK_Super_L; | ||
break; | ||
case _keysym["default"].XK_Alt_L: | ||
keysym = _keysym["default"].XK_Mode_switch; | ||
break; | ||
case _keysym["default"].XK_Alt_R: | ||
@@ -187,38 +162,42 @@ keysym = _keysym["default"].XK_ISO_Level3_Shift; | ||
} | ||
} // Is this key already pressed? If so, then we must use the | ||
} | ||
// Is this key already pressed? If so, then we must use the | ||
// same keysym or we'll confuse the server | ||
if (code in this._keyDownList) { | ||
keysym = this._keyDownList[code]; | ||
} | ||
// macOS doesn't send proper key releases if a key is pressed | ||
// while meta is held down | ||
if ((browser.isMac() || browser.isIOS()) && e.metaKey && code !== 'MetaLeft' && code !== 'MetaRight') { | ||
this._sendKeyEvent(keysym, code, true); | ||
this._sendKeyEvent(keysym, code, false); | ||
(0, _events.stopEvent)(e); | ||
return; | ||
} | ||
if (code in this._keyDownList) { | ||
keysym = this._keyDownList[code]; | ||
} // macOS doesn't send proper key events for modifiers, only | ||
// macOS doesn't send proper key events for modifiers, only | ||
// state change events. That gets extra confusing for CapsLock | ||
// which toggles on each press, but not on release. So pretend | ||
// it was a quick press and release of the button. | ||
if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') { | ||
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true); | ||
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false); | ||
(0, _events.stopEvent)(e); | ||
return; | ||
} // Windows doesn't send proper key releases for a bunch of | ||
} | ||
// Windows doesn't send proper key releases for a bunch of | ||
// Japanese IM keys so we have to fake the release right away | ||
var jpBadKeys = [_keysym["default"].XK_Zenkaku_Hankaku, _keysym["default"].XK_Eisu_toggle, _keysym["default"].XK_Katakana, _keysym["default"].XK_Hiragana, _keysym["default"].XK_Romaji]; | ||
if (browser.isWindows() && jpBadKeys.includes(keysym)) { | ||
this._sendKeyEvent(keysym, code, true); | ||
this._sendKeyEvent(keysym, code, false); | ||
(0, _events.stopEvent)(e); | ||
return; | ||
} | ||
(0, _events.stopEvent)(e); | ||
(0, _events.stopEvent)(e); // Possible start of AltGr sequence? (see above) | ||
// Possible start of AltGr sequence? (see above) | ||
if (code === "ControlLeft" && browser.isWindows() && !("ControlLeft" in this._keyDownList)) { | ||
@@ -230,3 +209,2 @@ this._altGrArmed = true; | ||
} | ||
this._sendKeyEvent(keysym, code, true); | ||
@@ -238,28 +216,23 @@ } | ||
(0, _events.stopEvent)(e); | ||
var code = this._getKeyCode(e); | ||
var code = this._getKeyCode(e); // We can't get a release in the middle of an AltGr sequence, so | ||
// We can't get a release in the middle of an AltGr sequence, so | ||
// abort that detection | ||
if (this._altGrArmed) { | ||
this._altGrArmed = false; | ||
clearTimeout(this._altGrTimeout); | ||
this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true); | ||
} // See comment in _handleKeyDown() | ||
} | ||
// See comment in _handleKeyDown() | ||
if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') { | ||
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true); | ||
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false); | ||
return; | ||
} | ||
this._sendKeyEvent(this._keyDownList[code], code, false); | ||
this._sendKeyEvent(this._keyDownList[code], code, false); // Windows has a rather nasty bug where it won't send key | ||
// Windows has a rather nasty bug where it won't send key | ||
// release events for a Shift button if the other Shift is still | ||
// pressed | ||
if (browser.isWindows() && (code === 'ShiftLeft' || code === 'ShiftRight')) { | ||
@@ -269,3 +242,2 @@ if ('ShiftRight' in this._keyDownList) { | ||
} | ||
if ('ShiftLeft' in this._keyDownList) { | ||
@@ -281,3 +253,2 @@ this._sendKeyEvent(this._keyDownList['ShiftLeft'], 'ShiftLeft', false); | ||
clearTimeout(this._altGrTimeout); | ||
this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true); | ||
@@ -289,10 +260,9 @@ } | ||
Log.Debug(">> Keyboard.allKeysUp"); | ||
for (var code in this._keyDownList) { | ||
this._sendKeyEvent(this._keyDownList[code], code, false); | ||
} | ||
Log.Debug("<< Keyboard.allKeysUp"); | ||
} // ===== PUBLIC METHODS ===== | ||
} | ||
// ===== PUBLIC METHODS ===== | ||
}, { | ||
@@ -302,8 +272,10 @@ key: "grab", | ||
//Log.Debug(">> Keyboard.grab"); | ||
this._target.addEventListener('keydown', this._eventHandlers.keydown); | ||
this._target.addEventListener('keyup', this._eventHandlers.keyup); | ||
this._target.addEventListener('keyup', this._eventHandlers.keyup); // Release (key up) if window loses focus | ||
// Release (key up) if window loses focus | ||
window.addEventListener('blur', this._eventHandlers.blur); | ||
window.addEventListener('blur', this._eventHandlers.blur); //Log.Debug("<< Keyboard.grab"); | ||
//Log.Debug("<< Keyboard.grab"); | ||
} | ||
@@ -314,16 +286,15 @@ }, { | ||
//Log.Debug(">> Keyboard.ungrab"); | ||
this._target.removeEventListener('keydown', this._eventHandlers.keydown); | ||
this._target.removeEventListener('keyup', this._eventHandlers.keyup); | ||
window.removeEventListener('blur', this._eventHandlers.blur); | ||
window.removeEventListener('blur', this._eventHandlers.blur); // Release (key up) all keys that are in a down state | ||
// Release (key up) all keys that are in a down state | ||
this._allKeysUp(); | ||
this._allKeysUp(); //Log.Debug(">> Keyboard.ungrab"); | ||
//Log.Debug(">> Keyboard.ungrab"); | ||
} | ||
}]); | ||
return Keyboard; | ||
}(); | ||
exports["default"] = Keyboard; |
@@ -7,21 +7,16 @@ "use strict"; | ||
exports["default"] = void 0; | ||
/* eslint-disable key-spacing */ | ||
var _default = { | ||
XK_VoidSymbol: 0xffffff, | ||
/* Void symbol */ | ||
/* Void symbol */ | ||
XK_BackSpace: 0xff08, | ||
/* Back space, back char */ | ||
XK_Tab: 0xff09, | ||
XK_Linefeed: 0xff0a, | ||
/* Linefeed, LF */ | ||
XK_Clear: 0xff0b, | ||
XK_Return: 0xff0d, | ||
/* Return, enter */ | ||
XK_Pause: 0xff13, | ||
/* Pause, hold */ | ||
@@ -32,8 +27,7 @@ XK_Scroll_Lock: 0xff14, | ||
XK_Delete: 0xffff, | ||
/* Delete, rubout */ | ||
/* International & multi-key character composition */ | ||
XK_Multi_key: 0xff20, | ||
/* Multi-key character compose */ | ||
@@ -44,138 +38,100 @@ XK_Codeinput: 0xff37, | ||
XK_PreviousCandidate: 0xff3e, | ||
/* Japanese keyboard support */ | ||
/* Japanese keyboard support */ | ||
XK_Kanji: 0xff21, | ||
/* Kanji, Kanji convert */ | ||
XK_Muhenkan: 0xff22, | ||
/* Cancel Conversion */ | ||
XK_Henkan_Mode: 0xff23, | ||
/* Start/Stop Conversion */ | ||
XK_Henkan: 0xff23, | ||
/* Alias for Henkan_Mode */ | ||
XK_Romaji: 0xff24, | ||
/* to Romaji */ | ||
XK_Hiragana: 0xff25, | ||
/* to Hiragana */ | ||
XK_Katakana: 0xff26, | ||
/* to Katakana */ | ||
XK_Hiragana_Katakana: 0xff27, | ||
/* Hiragana/Katakana toggle */ | ||
XK_Zenkaku: 0xff28, | ||
/* to Zenkaku */ | ||
XK_Hankaku: 0xff29, | ||
/* to Hankaku */ | ||
XK_Zenkaku_Hankaku: 0xff2a, | ||
/* Zenkaku/Hankaku toggle */ | ||
XK_Touroku: 0xff2b, | ||
/* Add to Dictionary */ | ||
XK_Massyo: 0xff2c, | ||
/* Delete from Dictionary */ | ||
XK_Kana_Lock: 0xff2d, | ||
/* Kana Lock */ | ||
XK_Kana_Shift: 0xff2e, | ||
/* Kana Shift */ | ||
XK_Eisu_Shift: 0xff2f, | ||
/* Alphanumeric Shift */ | ||
XK_Eisu_toggle: 0xff30, | ||
/* Alphanumeric toggle */ | ||
XK_Kanji_Bangou: 0xff37, | ||
/* Codeinput */ | ||
XK_Zen_Koho: 0xff3d, | ||
/* Multiple/All Candidate(s) */ | ||
XK_Mae_Koho: 0xff3e, | ||
/* Previous Candidate */ | ||
/* Cursor control & motion */ | ||
XK_Home: 0xff50, | ||
XK_Left: 0xff51, | ||
/* Move left, left arrow */ | ||
XK_Up: 0xff52, | ||
/* Move up, up arrow */ | ||
XK_Right: 0xff53, | ||
/* Move right, right arrow */ | ||
XK_Down: 0xff54, | ||
/* Move down, down arrow */ | ||
XK_Prior: 0xff55, | ||
/* Prior, previous */ | ||
XK_Page_Up: 0xff55, | ||
XK_Next: 0xff56, | ||
/* Next */ | ||
XK_Page_Down: 0xff56, | ||
XK_End: 0xff57, | ||
/* EOL */ | ||
XK_Begin: 0xff58, | ||
/* BOL */ | ||
/* Misc functions */ | ||
XK_Select: 0xff60, | ||
/* Select, mark */ | ||
XK_Print: 0xff61, | ||
XK_Execute: 0xff62, | ||
/* Execute, run, do */ | ||
XK_Insert: 0xff63, | ||
/* Insert, insert here */ | ||
XK_Undo: 0xff65, | ||
XK_Redo: 0xff66, | ||
/* Redo, again */ | ||
XK_Menu: 0xff67, | ||
XK_Find: 0xff68, | ||
/* Find, search */ | ||
XK_Cancel: 0xff69, | ||
/* Cancel, stop, abort, exit */ | ||
XK_Help: 0xff6a, | ||
/* Help */ | ||
XK_Break: 0xff6b, | ||
XK_Mode_switch: 0xff7e, | ||
/* Character set switch */ | ||
XK_script_switch: 0xff7e, | ||
/* Alias for mode_switch */ | ||
XK_Num_Lock: 0xff7f, | ||
/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */ | ||
/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */ | ||
XK_KP_Space: 0xff80, | ||
/* Space */ | ||
XK_KP_Tab: 0xff89, | ||
XK_KP_Enter: 0xff8d, | ||
/* Enter */ | ||
XK_KP_F1: 0xff91, | ||
/* PF1, KP_A, ... */ | ||
@@ -199,3 +155,2 @@ XK_KP_F2: 0xff92, | ||
XK_KP_Equal: 0xffbd, | ||
/* Equals */ | ||
@@ -205,3 +160,2 @@ XK_KP_Multiply: 0xffaa, | ||
XK_KP_Separator: 0xffac, | ||
/* Separator, often comma */ | ||
@@ -221,3 +175,2 @@ XK_KP_Subtract: 0xffad, | ||
XK_KP_9: 0xffb9, | ||
/* | ||
@@ -229,2 +182,3 @@ * Auxiliary functions; note the duplicate definitions for left and right | ||
*/ | ||
XK_F1: 0xffbe, | ||
@@ -290,45 +244,32 @@ XK_F2: 0xffbf, | ||
XK_R15: 0xffe0, | ||
/* Modifiers */ | ||
/* Modifiers */ | ||
XK_Shift_L: 0xffe1, | ||
/* Left shift */ | ||
XK_Shift_R: 0xffe2, | ||
/* Right shift */ | ||
XK_Control_L: 0xffe3, | ||
/* Left control */ | ||
XK_Control_R: 0xffe4, | ||
/* Right control */ | ||
XK_Caps_Lock: 0xffe5, | ||
/* Caps lock */ | ||
XK_Shift_Lock: 0xffe6, | ||
/* Shift lock */ | ||
/* Shift lock */ | ||
XK_Meta_L: 0xffe7, | ||
/* Left meta */ | ||
XK_Meta_R: 0xffe8, | ||
/* Right meta */ | ||
XK_Alt_L: 0xffe9, | ||
/* Left alt */ | ||
XK_Alt_R: 0xffea, | ||
/* Right alt */ | ||
XK_Super_L: 0xffeb, | ||
/* Left super */ | ||
XK_Super_R: 0xffec, | ||
/* Right super */ | ||
XK_Hyper_L: 0xffed, | ||
/* Left hyper */ | ||
XK_Hyper_R: 0xffee, | ||
/* Right hyper */ | ||
@@ -341,4 +282,4 @@ | ||
*/ | ||
XK_ISO_Level3_Shift: 0xfe03, | ||
/* AltGr */ | ||
@@ -349,3 +290,2 @@ XK_ISO_Next_Group: 0xfe08, | ||
XK_ISO_Last_Group: 0xfe0e, | ||
/* | ||
@@ -356,592 +296,397 @@ * Latin 1 | ||
*/ | ||
XK_space: 0x0020, | ||
/* U+0020 SPACE */ | ||
XK_exclam: 0x0021, | ||
/* U+0021 EXCLAMATION MARK */ | ||
XK_quotedbl: 0x0022, | ||
/* U+0022 QUOTATION MARK */ | ||
XK_numbersign: 0x0023, | ||
/* U+0023 NUMBER SIGN */ | ||
XK_dollar: 0x0024, | ||
/* U+0024 DOLLAR SIGN */ | ||
XK_percent: 0x0025, | ||
/* U+0025 PERCENT SIGN */ | ||
XK_ampersand: 0x0026, | ||
/* U+0026 AMPERSAND */ | ||
XK_apostrophe: 0x0027, | ||
/* U+0027 APOSTROPHE */ | ||
XK_quoteright: 0x0027, | ||
/* deprecated */ | ||
XK_parenleft: 0x0028, | ||
/* U+0028 LEFT PARENTHESIS */ | ||
XK_parenright: 0x0029, | ||
/* U+0029 RIGHT PARENTHESIS */ | ||
XK_asterisk: 0x002a, | ||
/* U+002A ASTERISK */ | ||
XK_plus: 0x002b, | ||
/* U+002B PLUS SIGN */ | ||
XK_comma: 0x002c, | ||
/* U+002C COMMA */ | ||
XK_minus: 0x002d, | ||
/* U+002D HYPHEN-MINUS */ | ||
XK_period: 0x002e, | ||
/* U+002E FULL STOP */ | ||
XK_slash: 0x002f, | ||
/* U+002F SOLIDUS */ | ||
XK_0: 0x0030, | ||
/* U+0030 DIGIT ZERO */ | ||
XK_1: 0x0031, | ||
/* U+0031 DIGIT ONE */ | ||
XK_2: 0x0032, | ||
/* U+0032 DIGIT TWO */ | ||
XK_3: 0x0033, | ||
/* U+0033 DIGIT THREE */ | ||
XK_4: 0x0034, | ||
/* U+0034 DIGIT FOUR */ | ||
XK_5: 0x0035, | ||
/* U+0035 DIGIT FIVE */ | ||
XK_6: 0x0036, | ||
/* U+0036 DIGIT SIX */ | ||
XK_7: 0x0037, | ||
/* U+0037 DIGIT SEVEN */ | ||
XK_8: 0x0038, | ||
/* U+0038 DIGIT EIGHT */ | ||
XK_9: 0x0039, | ||
/* U+0039 DIGIT NINE */ | ||
XK_colon: 0x003a, | ||
/* U+003A COLON */ | ||
XK_semicolon: 0x003b, | ||
/* U+003B SEMICOLON */ | ||
XK_less: 0x003c, | ||
/* U+003C LESS-THAN SIGN */ | ||
XK_equal: 0x003d, | ||
/* U+003D EQUALS SIGN */ | ||
XK_greater: 0x003e, | ||
/* U+003E GREATER-THAN SIGN */ | ||
XK_question: 0x003f, | ||
/* U+003F QUESTION MARK */ | ||
XK_at: 0x0040, | ||
/* U+0040 COMMERCIAL AT */ | ||
XK_A: 0x0041, | ||
/* U+0041 LATIN CAPITAL LETTER A */ | ||
XK_B: 0x0042, | ||
/* U+0042 LATIN CAPITAL LETTER B */ | ||
XK_C: 0x0043, | ||
/* U+0043 LATIN CAPITAL LETTER C */ | ||
XK_D: 0x0044, | ||
/* U+0044 LATIN CAPITAL LETTER D */ | ||
XK_E: 0x0045, | ||
/* U+0045 LATIN CAPITAL LETTER E */ | ||
XK_F: 0x0046, | ||
/* U+0046 LATIN CAPITAL LETTER F */ | ||
XK_G: 0x0047, | ||
/* U+0047 LATIN CAPITAL LETTER G */ | ||
XK_H: 0x0048, | ||
/* U+0048 LATIN CAPITAL LETTER H */ | ||
XK_I: 0x0049, | ||
/* U+0049 LATIN CAPITAL LETTER I */ | ||
XK_J: 0x004a, | ||
/* U+004A LATIN CAPITAL LETTER J */ | ||
XK_K: 0x004b, | ||
/* U+004B LATIN CAPITAL LETTER K */ | ||
XK_L: 0x004c, | ||
/* U+004C LATIN CAPITAL LETTER L */ | ||
XK_M: 0x004d, | ||
/* U+004D LATIN CAPITAL LETTER M */ | ||
XK_N: 0x004e, | ||
/* U+004E LATIN CAPITAL LETTER N */ | ||
XK_O: 0x004f, | ||
/* U+004F LATIN CAPITAL LETTER O */ | ||
XK_P: 0x0050, | ||
/* U+0050 LATIN CAPITAL LETTER P */ | ||
XK_Q: 0x0051, | ||
/* U+0051 LATIN CAPITAL LETTER Q */ | ||
XK_R: 0x0052, | ||
/* U+0052 LATIN CAPITAL LETTER R */ | ||
XK_S: 0x0053, | ||
/* U+0053 LATIN CAPITAL LETTER S */ | ||
XK_T: 0x0054, | ||
/* U+0054 LATIN CAPITAL LETTER T */ | ||
XK_U: 0x0055, | ||
/* U+0055 LATIN CAPITAL LETTER U */ | ||
XK_V: 0x0056, | ||
/* U+0056 LATIN CAPITAL LETTER V */ | ||
XK_W: 0x0057, | ||
/* U+0057 LATIN CAPITAL LETTER W */ | ||
XK_X: 0x0058, | ||
/* U+0058 LATIN CAPITAL LETTER X */ | ||
XK_Y: 0x0059, | ||
/* U+0059 LATIN CAPITAL LETTER Y */ | ||
XK_Z: 0x005a, | ||
/* U+005A LATIN CAPITAL LETTER Z */ | ||
XK_bracketleft: 0x005b, | ||
/* U+005B LEFT SQUARE BRACKET */ | ||
XK_backslash: 0x005c, | ||
/* U+005C REVERSE SOLIDUS */ | ||
XK_bracketright: 0x005d, | ||
/* U+005D RIGHT SQUARE BRACKET */ | ||
XK_asciicircum: 0x005e, | ||
/* U+005E CIRCUMFLEX ACCENT */ | ||
XK_underscore: 0x005f, | ||
/* U+005F LOW LINE */ | ||
XK_grave: 0x0060, | ||
/* U+0060 GRAVE ACCENT */ | ||
XK_quoteleft: 0x0060, | ||
/* deprecated */ | ||
XK_a: 0x0061, | ||
/* U+0061 LATIN SMALL LETTER A */ | ||
XK_b: 0x0062, | ||
/* U+0062 LATIN SMALL LETTER B */ | ||
XK_c: 0x0063, | ||
/* U+0063 LATIN SMALL LETTER C */ | ||
XK_d: 0x0064, | ||
/* U+0064 LATIN SMALL LETTER D */ | ||
XK_e: 0x0065, | ||
/* U+0065 LATIN SMALL LETTER E */ | ||
XK_f: 0x0066, | ||
/* U+0066 LATIN SMALL LETTER F */ | ||
XK_g: 0x0067, | ||
/* U+0067 LATIN SMALL LETTER G */ | ||
XK_h: 0x0068, | ||
/* U+0068 LATIN SMALL LETTER H */ | ||
XK_i: 0x0069, | ||
/* U+0069 LATIN SMALL LETTER I */ | ||
XK_j: 0x006a, | ||
/* U+006A LATIN SMALL LETTER J */ | ||
XK_k: 0x006b, | ||
/* U+006B LATIN SMALL LETTER K */ | ||
XK_l: 0x006c, | ||
/* U+006C LATIN SMALL LETTER L */ | ||
XK_m: 0x006d, | ||
/* U+006D LATIN SMALL LETTER M */ | ||
XK_n: 0x006e, | ||
/* U+006E LATIN SMALL LETTER N */ | ||
XK_o: 0x006f, | ||
/* U+006F LATIN SMALL LETTER O */ | ||
XK_p: 0x0070, | ||
/* U+0070 LATIN SMALL LETTER P */ | ||
XK_q: 0x0071, | ||
/* U+0071 LATIN SMALL LETTER Q */ | ||
XK_r: 0x0072, | ||
/* U+0072 LATIN SMALL LETTER R */ | ||
XK_s: 0x0073, | ||
/* U+0073 LATIN SMALL LETTER S */ | ||
XK_t: 0x0074, | ||
/* U+0074 LATIN SMALL LETTER T */ | ||
XK_u: 0x0075, | ||
/* U+0075 LATIN SMALL LETTER U */ | ||
XK_v: 0x0076, | ||
/* U+0076 LATIN SMALL LETTER V */ | ||
XK_w: 0x0077, | ||
/* U+0077 LATIN SMALL LETTER W */ | ||
XK_x: 0x0078, | ||
/* U+0078 LATIN SMALL LETTER X */ | ||
XK_y: 0x0079, | ||
/* U+0079 LATIN SMALL LETTER Y */ | ||
XK_z: 0x007a, | ||
/* U+007A LATIN SMALL LETTER Z */ | ||
XK_braceleft: 0x007b, | ||
/* U+007B LEFT CURLY BRACKET */ | ||
XK_bar: 0x007c, | ||
/* U+007C VERTICAL LINE */ | ||
XK_braceright: 0x007d, | ||
/* U+007D RIGHT CURLY BRACKET */ | ||
XK_asciitilde: 0x007e, | ||
/* U+007E TILDE */ | ||
/* U+007E TILDE */ | ||
XK_nobreakspace: 0x00a0, | ||
/* U+00A0 NO-BREAK SPACE */ | ||
XK_exclamdown: 0x00a1, | ||
/* U+00A1 INVERTED EXCLAMATION MARK */ | ||
XK_cent: 0x00a2, | ||
/* U+00A2 CENT SIGN */ | ||
XK_sterling: 0x00a3, | ||
/* U+00A3 POUND SIGN */ | ||
XK_currency: 0x00a4, | ||
/* U+00A4 CURRENCY SIGN */ | ||
XK_yen: 0x00a5, | ||
/* U+00A5 YEN SIGN */ | ||
XK_brokenbar: 0x00a6, | ||
/* U+00A6 BROKEN BAR */ | ||
XK_section: 0x00a7, | ||
/* U+00A7 SECTION SIGN */ | ||
XK_diaeresis: 0x00a8, | ||
/* U+00A8 DIAERESIS */ | ||
XK_copyright: 0x00a9, | ||
/* U+00A9 COPYRIGHT SIGN */ | ||
XK_ordfeminine: 0x00aa, | ||
/* U+00AA FEMININE ORDINAL INDICATOR */ | ||
XK_guillemotleft: 0x00ab, | ||
/* U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK */ | ||
XK_notsign: 0x00ac, | ||
/* U+00AC NOT SIGN */ | ||
XK_hyphen: 0x00ad, | ||
/* U+00AD SOFT HYPHEN */ | ||
XK_registered: 0x00ae, | ||
/* U+00AE REGISTERED SIGN */ | ||
XK_macron: 0x00af, | ||
/* U+00AF MACRON */ | ||
XK_degree: 0x00b0, | ||
/* U+00B0 DEGREE SIGN */ | ||
XK_plusminus: 0x00b1, | ||
/* U+00B1 PLUS-MINUS SIGN */ | ||
XK_twosuperior: 0x00b2, | ||
/* U+00B2 SUPERSCRIPT TWO */ | ||
XK_threesuperior: 0x00b3, | ||
/* U+00B3 SUPERSCRIPT THREE */ | ||
XK_acute: 0x00b4, | ||
/* U+00B4 ACUTE ACCENT */ | ||
XK_mu: 0x00b5, | ||
/* U+00B5 MICRO SIGN */ | ||
XK_paragraph: 0x00b6, | ||
/* U+00B6 PILCROW SIGN */ | ||
XK_periodcentered: 0x00b7, | ||
/* U+00B7 MIDDLE DOT */ | ||
XK_cedilla: 0x00b8, | ||
/* U+00B8 CEDILLA */ | ||
XK_onesuperior: 0x00b9, | ||
/* U+00B9 SUPERSCRIPT ONE */ | ||
XK_masculine: 0x00ba, | ||
/* U+00BA MASCULINE ORDINAL INDICATOR */ | ||
XK_guillemotright: 0x00bb, | ||
/* U+00BB RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK */ | ||
XK_onequarter: 0x00bc, | ||
/* U+00BC VULGAR FRACTION ONE QUARTER */ | ||
XK_onehalf: 0x00bd, | ||
/* U+00BD VULGAR FRACTION ONE HALF */ | ||
XK_threequarters: 0x00be, | ||
/* U+00BE VULGAR FRACTION THREE QUARTERS */ | ||
XK_questiondown: 0x00bf, | ||
/* U+00BF INVERTED QUESTION MARK */ | ||
XK_Agrave: 0x00c0, | ||
/* U+00C0 LATIN CAPITAL LETTER A WITH GRAVE */ | ||
XK_Aacute: 0x00c1, | ||
/* U+00C1 LATIN CAPITAL LETTER A WITH ACUTE */ | ||
XK_Acircumflex: 0x00c2, | ||
/* U+00C2 LATIN CAPITAL LETTER A WITH CIRCUMFLEX */ | ||
XK_Atilde: 0x00c3, | ||
/* U+00C3 LATIN CAPITAL LETTER A WITH TILDE */ | ||
XK_Adiaeresis: 0x00c4, | ||
/* U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS */ | ||
XK_Aring: 0x00c5, | ||
/* U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE */ | ||
XK_AE: 0x00c6, | ||
/* U+00C6 LATIN CAPITAL LETTER AE */ | ||
XK_Ccedilla: 0x00c7, | ||
/* U+00C7 LATIN CAPITAL LETTER C WITH CEDILLA */ | ||
XK_Egrave: 0x00c8, | ||
/* U+00C8 LATIN CAPITAL LETTER E WITH GRAVE */ | ||
XK_Eacute: 0x00c9, | ||
/* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */ | ||
XK_Ecircumflex: 0x00ca, | ||
/* U+00CA LATIN CAPITAL LETTER E WITH CIRCUMFLEX */ | ||
XK_Ediaeresis: 0x00cb, | ||
/* U+00CB LATIN CAPITAL LETTER E WITH DIAERESIS */ | ||
XK_Igrave: 0x00cc, | ||
/* U+00CC LATIN CAPITAL LETTER I WITH GRAVE */ | ||
XK_Iacute: 0x00cd, | ||
/* U+00CD LATIN CAPITAL LETTER I WITH ACUTE */ | ||
XK_Icircumflex: 0x00ce, | ||
/* U+00CE LATIN CAPITAL LETTER I WITH CIRCUMFLEX */ | ||
XK_Idiaeresis: 0x00cf, | ||
/* U+00CF LATIN CAPITAL LETTER I WITH DIAERESIS */ | ||
XK_ETH: 0x00d0, | ||
/* U+00D0 LATIN CAPITAL LETTER ETH */ | ||
XK_Eth: 0x00d0, | ||
/* deprecated */ | ||
XK_Ntilde: 0x00d1, | ||
/* U+00D1 LATIN CAPITAL LETTER N WITH TILDE */ | ||
XK_Ograve: 0x00d2, | ||
/* U+00D2 LATIN CAPITAL LETTER O WITH GRAVE */ | ||
XK_Oacute: 0x00d3, | ||
/* U+00D3 LATIN CAPITAL LETTER O WITH ACUTE */ | ||
XK_Ocircumflex: 0x00d4, | ||
/* U+00D4 LATIN CAPITAL LETTER O WITH CIRCUMFLEX */ | ||
XK_Otilde: 0x00d5, | ||
/* U+00D5 LATIN CAPITAL LETTER O WITH TILDE */ | ||
XK_Odiaeresis: 0x00d6, | ||
/* U+00D6 LATIN CAPITAL LETTER O WITH DIAERESIS */ | ||
XK_multiply: 0x00d7, | ||
/* U+00D7 MULTIPLICATION SIGN */ | ||
XK_Oslash: 0x00d8, | ||
/* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */ | ||
XK_Ooblique: 0x00d8, | ||
/* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */ | ||
XK_Ugrave: 0x00d9, | ||
/* U+00D9 LATIN CAPITAL LETTER U WITH GRAVE */ | ||
XK_Uacute: 0x00da, | ||
/* U+00DA LATIN CAPITAL LETTER U WITH ACUTE */ | ||
XK_Ucircumflex: 0x00db, | ||
/* U+00DB LATIN CAPITAL LETTER U WITH CIRCUMFLEX */ | ||
XK_Udiaeresis: 0x00dc, | ||
/* U+00DC LATIN CAPITAL LETTER U WITH DIAERESIS */ | ||
XK_Yacute: 0x00dd, | ||
/* U+00DD LATIN CAPITAL LETTER Y WITH ACUTE */ | ||
XK_THORN: 0x00de, | ||
/* U+00DE LATIN CAPITAL LETTER THORN */ | ||
XK_Thorn: 0x00de, | ||
/* deprecated */ | ||
XK_ssharp: 0x00df, | ||
/* U+00DF LATIN SMALL LETTER SHARP S */ | ||
XK_agrave: 0x00e0, | ||
/* U+00E0 LATIN SMALL LETTER A WITH GRAVE */ | ||
XK_aacute: 0x00e1, | ||
/* U+00E1 LATIN SMALL LETTER A WITH ACUTE */ | ||
XK_acircumflex: 0x00e2, | ||
/* U+00E2 LATIN SMALL LETTER A WITH CIRCUMFLEX */ | ||
XK_atilde: 0x00e3, | ||
/* U+00E3 LATIN SMALL LETTER A WITH TILDE */ | ||
XK_adiaeresis: 0x00e4, | ||
/* U+00E4 LATIN SMALL LETTER A WITH DIAERESIS */ | ||
XK_aring: 0x00e5, | ||
/* U+00E5 LATIN SMALL LETTER A WITH RING ABOVE */ | ||
XK_ae: 0x00e6, | ||
/* U+00E6 LATIN SMALL LETTER AE */ | ||
XK_ccedilla: 0x00e7, | ||
/* U+00E7 LATIN SMALL LETTER C WITH CEDILLA */ | ||
XK_egrave: 0x00e8, | ||
/* U+00E8 LATIN SMALL LETTER E WITH GRAVE */ | ||
XK_eacute: 0x00e9, | ||
/* U+00E9 LATIN SMALL LETTER E WITH ACUTE */ | ||
XK_ecircumflex: 0x00ea, | ||
/* U+00EA LATIN SMALL LETTER E WITH CIRCUMFLEX */ | ||
XK_ediaeresis: 0x00eb, | ||
/* U+00EB LATIN SMALL LETTER E WITH DIAERESIS */ | ||
XK_igrave: 0x00ec, | ||
/* U+00EC LATIN SMALL LETTER I WITH GRAVE */ | ||
XK_iacute: 0x00ed, | ||
/* U+00ED LATIN SMALL LETTER I WITH ACUTE */ | ||
XK_icircumflex: 0x00ee, | ||
/* U+00EE LATIN SMALL LETTER I WITH CIRCUMFLEX */ | ||
XK_idiaeresis: 0x00ef, | ||
/* U+00EF LATIN SMALL LETTER I WITH DIAERESIS */ | ||
XK_eth: 0x00f0, | ||
/* U+00F0 LATIN SMALL LETTER ETH */ | ||
XK_ntilde: 0x00f1, | ||
/* U+00F1 LATIN SMALL LETTER N WITH TILDE */ | ||
XK_ograve: 0x00f2, | ||
/* U+00F2 LATIN SMALL LETTER O WITH GRAVE */ | ||
XK_oacute: 0x00f3, | ||
/* U+00F3 LATIN SMALL LETTER O WITH ACUTE */ | ||
XK_ocircumflex: 0x00f4, | ||
/* U+00F4 LATIN SMALL LETTER O WITH CIRCUMFLEX */ | ||
XK_otilde: 0x00f5, | ||
/* U+00F5 LATIN SMALL LETTER O WITH TILDE */ | ||
XK_odiaeresis: 0x00f6, | ||
/* U+00F6 LATIN SMALL LETTER O WITH DIAERESIS */ | ||
XK_division: 0x00f7, | ||
/* U+00F7 DIVISION SIGN */ | ||
XK_oslash: 0x00f8, | ||
/* U+00F8 LATIN SMALL LETTER O WITH STROKE */ | ||
XK_ooblique: 0x00f8, | ||
/* U+00F8 LATIN SMALL LETTER O WITH STROKE */ | ||
XK_ugrave: 0x00f9, | ||
/* U+00F9 LATIN SMALL LETTER U WITH GRAVE */ | ||
XK_uacute: 0x00fa, | ||
/* U+00FA LATIN SMALL LETTER U WITH ACUTE */ | ||
XK_ucircumflex: 0x00fb, | ||
/* U+00FB LATIN SMALL LETTER U WITH CIRCUMFLEX */ | ||
XK_udiaeresis: 0x00fc, | ||
/* U+00FC LATIN SMALL LETTER U WITH DIAERESIS */ | ||
XK_yacute: 0x00fd, | ||
/* U+00FD LATIN SMALL LETTER Y WITH ACUTE */ | ||
XK_thorn: 0x00fe, | ||
/* U+00FE LATIN SMALL LETTER THORN */ | ||
XK_ydiaeresis: 0x00ff, | ||
/* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */ | ||
@@ -953,10 +698,8 @@ | ||
*/ | ||
XK_Hangul: 0xff31, | ||
/* Hangul start/stop(toggle) */ | ||
XK_Hangul_Hanja: 0xff34, | ||
/* Start Hangul->Hanja Conversion */ | ||
XK_Hangul_Jeonja: 0xff38, | ||
/* Jeonja mode */ | ||
@@ -969,2 +712,3 @@ | ||
*/ | ||
XF86XK_ModeLock: 0x1008FF01, | ||
@@ -971,0 +715,0 @@ XF86XK_MonBrightnessUp: 0x1008FF02, |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = void 0; | ||
/* | ||
@@ -17,2 +16,3 @@ * Mapping from Unicode codepoints to X11/RFB keysyms | ||
/* Functions at the bottom */ | ||
var codepoints = { | ||
@@ -1336,3 +1336,2 @@ 0x0100: 0x03c0, | ||
0x30fc: 0x04b0 // XK_prolongedsound | ||
}; | ||
@@ -1344,12 +1343,11 @@ var _default = { | ||
return u; | ||
} // Lookup table (fairly random) | ||
} | ||
// Lookup table (fairly random) | ||
var keysym = codepoints[u]; | ||
if (keysym !== undefined) { | ||
return keysym; | ||
} // General mapping as final fallback | ||
} | ||
// General mapping as final fallback | ||
return 0x01000000 | u; | ||
@@ -1356,0 +1354,0 @@ } |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,21 +10,11 @@ value: true | ||
exports.getKeysym = getKeysym; | ||
var _keysym = _interopRequireDefault(require("./keysym.js")); | ||
var _keysymdef = _interopRequireDefault(require("./keysymdef.js")); | ||
var _vkeys = _interopRequireDefault(require("./vkeys.js")); | ||
var _fixedkeys = _interopRequireDefault(require("./fixedkeys.js")); | ||
var _domkeytable = _interopRequireDefault(require("./domkeytable.js")); | ||
var browser = _interopRequireWildcard(require("../util/browser.js")); | ||
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); } | ||
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; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
// Get 'KeyboardEvent.code', handling legacy browsers | ||
@@ -42,21 +31,20 @@ function getKeycode(evt) { | ||
return 'MetaLeft'; | ||
case 'OSRight': | ||
return 'MetaRight'; | ||
} | ||
return evt.code; | ||
} | ||
return evt.code; | ||
} // The de-facto standard is to use Windows Virtual-Key codes | ||
// The de-facto standard is to use Windows Virtual-Key codes | ||
// in the 'keyCode' field for non-printable characters | ||
if (evt.keyCode in _vkeys["default"]) { | ||
var code = _vkeys["default"][evt.keyCode]; // macOS has messed up this code for some reason | ||
var code = _vkeys["default"][evt.keyCode]; | ||
// macOS has messed up this code for some reason | ||
if (browser.isMac() && code === 'ContextMenu') { | ||
code = 'MetaRight'; | ||
} // The keyCode doesn't distinguish between left and right | ||
} | ||
// The keyCode doesn't distinguish between left and right | ||
// for the standard modifiers | ||
if (evt.location === 2) { | ||
@@ -66,12 +54,10 @@ switch (code) { | ||
return 'ShiftRight'; | ||
case 'ControlLeft': | ||
return 'ControlRight'; | ||
case 'AltLeft': | ||
return 'AltRight'; | ||
} | ||
} // Nor a bunch of the numpad keys | ||
} | ||
// Nor a bunch of the numpad keys | ||
if (evt.location === 3) { | ||
@@ -81,30 +67,20 @@ switch (code) { | ||
return 'NumpadDecimal'; | ||
case 'Insert': | ||
return 'Numpad0'; | ||
case 'End': | ||
return 'Numpad1'; | ||
case 'ArrowDown': | ||
return 'Numpad2'; | ||
case 'PageDown': | ||
return 'Numpad3'; | ||
case 'ArrowLeft': | ||
return 'Numpad4'; | ||
case 'ArrowRight': | ||
return 'Numpad6'; | ||
case 'Home': | ||
return 'Numpad7'; | ||
case 'ArrowUp': | ||
return 'Numpad8'; | ||
case 'PageUp': | ||
return 'Numpad9'; | ||
case 'Enter': | ||
@@ -114,10 +90,8 @@ return 'NumpadEnter'; | ||
} | ||
return code; | ||
} | ||
return 'Unidentified'; | ||
} // Get 'KeyboardEvent.key', handling legacy browsers | ||
} | ||
// Get 'KeyboardEvent.key', handling legacy browsers | ||
function getKey(evt) { | ||
@@ -130,72 +104,63 @@ // Are we getting a proper key value? | ||
return 'Meta'; | ||
case 'LaunchMyComputer': | ||
return 'LaunchApplication1'; | ||
case 'LaunchCalculator': | ||
return 'LaunchApplication2'; | ||
} // iOS leaks some OS names | ||
} | ||
// iOS leaks some OS names | ||
switch (evt.key) { | ||
case 'UIKeyInputUpArrow': | ||
return 'ArrowUp'; | ||
case 'UIKeyInputDownArrow': | ||
return 'ArrowDown'; | ||
case 'UIKeyInputLeftArrow': | ||
return 'ArrowLeft'; | ||
case 'UIKeyInputRightArrow': | ||
return 'ArrowRight'; | ||
case 'UIKeyInputEscape': | ||
return 'Escape'; | ||
} // Broken behaviour in Chrome | ||
} | ||
// Broken behaviour in Chrome | ||
if (evt.key === '\x00' && evt.code === 'NumpadDecimal') { | ||
return 'Delete'; | ||
} | ||
return evt.key; | ||
} // Try to deduce it based on the physical key | ||
} | ||
// Try to deduce it based on the physical key | ||
var code = getKeycode(evt); | ||
if (code in _fixedkeys["default"]) { | ||
return _fixedkeys["default"][code]; | ||
} // If that failed, then see if we have a printable character | ||
} | ||
// If that failed, then see if we have a printable character | ||
if (evt.charCode) { | ||
return String.fromCharCode(evt.charCode); | ||
} // At this point we have nothing left to go on | ||
} | ||
// At this point we have nothing left to go on | ||
return 'Unidentified'; | ||
} // Get the most reliable keysym value we can get from a key event | ||
} | ||
// Get the most reliable keysym value we can get from a key event | ||
function getKeysym(evt) { | ||
var key = getKey(evt); | ||
if (key === 'Unidentified') { | ||
return null; | ||
} // First look up special keys | ||
} | ||
// First look up special keys | ||
if (key in _domkeytable["default"]) { | ||
var location = evt.location; // Safari screws up location for the right cmd key | ||
var location = evt.location; | ||
// Safari screws up location for the right cmd key | ||
if (key === 'Meta' && location === 0) { | ||
location = 2; | ||
} // And for Clear | ||
} | ||
// And for Clear | ||
if (key === 'Clear' && location === 3) { | ||
var code = getKeycode(evt); | ||
if (code === 'NumLock') { | ||
@@ -205,13 +170,11 @@ location = 0; | ||
} | ||
if (location === undefined || location > 3) { | ||
location = 0; | ||
} // The original Meta key now gets confused with the Windows key | ||
} | ||
// The original Meta key now gets confused with the Windows key | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1020141 | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1232918 | ||
if (key === 'Meta') { | ||
var _code = getKeycode(evt); | ||
if (_code === 'AltLeft') { | ||
@@ -222,18 +185,17 @@ return _keysym["default"].XK_Meta_L; | ||
} | ||
} // macOS has Clear instead of NumLock, but the remote system is | ||
} | ||
// macOS has Clear instead of NumLock, but the remote system is | ||
// probably not macOS, so lying here is probably best... | ||
if (key === 'Clear') { | ||
var _code2 = getKeycode(evt); | ||
if (_code2 === 'NumLock') { | ||
return _keysym["default"].XK_Num_Lock; | ||
} | ||
} // Windows sends alternating symbols for some keys when using a | ||
} | ||
// Windows sends alternating symbols for some keys when using a | ||
// Japanese layout. We have no way of synchronising with the IM | ||
// running on the remote system, so we send some combined keysym | ||
// instead and hope for the best. | ||
if (browser.isWindows()) { | ||
@@ -244,3 +206,2 @@ switch (key) { | ||
return _keysym["default"].XK_Zenkaku_Hankaku; | ||
case 'Romaji': | ||
@@ -251,19 +212,16 @@ case 'KanaMode': | ||
} | ||
return _domkeytable["default"][key][location]; | ||
} // Now we need to look at the Unicode symbol instead | ||
// Special key? (FIXME: Should have been caught earlier) | ||
} | ||
// Now we need to look at the Unicode symbol instead | ||
// Special key? (FIXME: Should have been caught earlier) | ||
if (key.length !== 1) { | ||
return null; | ||
} | ||
var codepoint = key.charCodeAt(); | ||
if (codepoint) { | ||
return _keysymdef["default"].lookup(codepoint); | ||
} | ||
return null; | ||
} |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = void 0; | ||
/* | ||
@@ -14,3 +13,2 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
/* | ||
@@ -125,4 +123,3 @@ * Mapping between Microsoft® Windows® Virtual-Key codes and | ||
0xe1: 'AltRight' // Only when it is AltGraph | ||
}; | ||
exports["default"] = _default; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = void 0; | ||
/* | ||
@@ -17,497 +16,331 @@ * This file is auto-generated from keymaps.csv | ||
"Again": 0xe005, | ||
/* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */ | ||
"AltLeft": 0x38, | ||
/* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */ | ||
"AltRight": 0xe038, | ||
/* html:AltRight (AltRight) -> linux:100 (KEY_RIGHTALT) -> atset1:57400 */ | ||
"ArrowDown": 0xe050, | ||
/* html:ArrowDown (ArrowDown) -> linux:108 (KEY_DOWN) -> atset1:57424 */ | ||
"ArrowLeft": 0xe04b, | ||
/* html:ArrowLeft (ArrowLeft) -> linux:105 (KEY_LEFT) -> atset1:57419 */ | ||
"ArrowRight": 0xe04d, | ||
/* html:ArrowRight (ArrowRight) -> linux:106 (KEY_RIGHT) -> atset1:57421 */ | ||
"ArrowUp": 0xe048, | ||
/* html:ArrowUp (ArrowUp) -> linux:103 (KEY_UP) -> atset1:57416 */ | ||
"AudioVolumeDown": 0xe02e, | ||
/* html:AudioVolumeDown (AudioVolumeDown) -> linux:114 (KEY_VOLUMEDOWN) -> atset1:57390 */ | ||
"AudioVolumeMute": 0xe020, | ||
/* html:AudioVolumeMute (AudioVolumeMute) -> linux:113 (KEY_MUTE) -> atset1:57376 */ | ||
"AudioVolumeUp": 0xe030, | ||
/* html:AudioVolumeUp (AudioVolumeUp) -> linux:115 (KEY_VOLUMEUP) -> atset1:57392 */ | ||
"Backquote": 0x29, | ||
/* html:Backquote (Backquote) -> linux:41 (KEY_GRAVE) -> atset1:41 */ | ||
"Backslash": 0x2b, | ||
/* html:Backslash (Backslash) -> linux:43 (KEY_BACKSLASH) -> atset1:43 */ | ||
"Backspace": 0xe, | ||
/* html:Backspace (Backspace) -> linux:14 (KEY_BACKSPACE) -> atset1:14 */ | ||
"BracketLeft": 0x1a, | ||
/* html:BracketLeft (BracketLeft) -> linux:26 (KEY_LEFTBRACE) -> atset1:26 */ | ||
"BracketRight": 0x1b, | ||
/* html:BracketRight (BracketRight) -> linux:27 (KEY_RIGHTBRACE) -> atset1:27 */ | ||
"BrowserBack": 0xe06a, | ||
/* html:BrowserBack (BrowserBack) -> linux:158 (KEY_BACK) -> atset1:57450 */ | ||
"BrowserFavorites": 0xe066, | ||
/* html:BrowserFavorites (BrowserFavorites) -> linux:156 (KEY_BOOKMARKS) -> atset1:57446 */ | ||
"BrowserForward": 0xe069, | ||
/* html:BrowserForward (BrowserForward) -> linux:159 (KEY_FORWARD) -> atset1:57449 */ | ||
"BrowserHome": 0xe032, | ||
/* html:BrowserHome (BrowserHome) -> linux:172 (KEY_HOMEPAGE) -> atset1:57394 */ | ||
"BrowserRefresh": 0xe067, | ||
/* html:BrowserRefresh (BrowserRefresh) -> linux:173 (KEY_REFRESH) -> atset1:57447 */ | ||
"BrowserSearch": 0xe065, | ||
/* html:BrowserSearch (BrowserSearch) -> linux:217 (KEY_SEARCH) -> atset1:57445 */ | ||
"BrowserStop": 0xe068, | ||
/* html:BrowserStop (BrowserStop) -> linux:128 (KEY_STOP) -> atset1:57448 */ | ||
"CapsLock": 0x3a, | ||
/* html:CapsLock (CapsLock) -> linux:58 (KEY_CAPSLOCK) -> atset1:58 */ | ||
"Comma": 0x33, | ||
/* html:Comma (Comma) -> linux:51 (KEY_COMMA) -> atset1:51 */ | ||
"ContextMenu": 0xe05d, | ||
/* html:ContextMenu (ContextMenu) -> linux:127 (KEY_COMPOSE) -> atset1:57437 */ | ||
"ControlLeft": 0x1d, | ||
/* html:ControlLeft (ControlLeft) -> linux:29 (KEY_LEFTCTRL) -> atset1:29 */ | ||
"ControlRight": 0xe01d, | ||
/* html:ControlRight (ControlRight) -> linux:97 (KEY_RIGHTCTRL) -> atset1:57373 */ | ||
"Convert": 0x79, | ||
/* html:Convert (Convert) -> linux:92 (KEY_HENKAN) -> atset1:121 */ | ||
"Copy": 0xe078, | ||
/* html:Copy (Copy) -> linux:133 (KEY_COPY) -> atset1:57464 */ | ||
"Cut": 0xe03c, | ||
/* html:Cut (Cut) -> linux:137 (KEY_CUT) -> atset1:57404 */ | ||
"Delete": 0xe053, | ||
/* html:Delete (Delete) -> linux:111 (KEY_DELETE) -> atset1:57427 */ | ||
"Digit0": 0xb, | ||
/* html:Digit0 (Digit0) -> linux:11 (KEY_0) -> atset1:11 */ | ||
"Digit1": 0x2, | ||
/* html:Digit1 (Digit1) -> linux:2 (KEY_1) -> atset1:2 */ | ||
"Digit2": 0x3, | ||
/* html:Digit2 (Digit2) -> linux:3 (KEY_2) -> atset1:3 */ | ||
"Digit3": 0x4, | ||
/* html:Digit3 (Digit3) -> linux:4 (KEY_3) -> atset1:4 */ | ||
"Digit4": 0x5, | ||
/* html:Digit4 (Digit4) -> linux:5 (KEY_4) -> atset1:5 */ | ||
"Digit5": 0x6, | ||
/* html:Digit5 (Digit5) -> linux:6 (KEY_5) -> atset1:6 */ | ||
"Digit6": 0x7, | ||
/* html:Digit6 (Digit6) -> linux:7 (KEY_6) -> atset1:7 */ | ||
"Digit7": 0x8, | ||
/* html:Digit7 (Digit7) -> linux:8 (KEY_7) -> atset1:8 */ | ||
"Digit8": 0x9, | ||
/* html:Digit8 (Digit8) -> linux:9 (KEY_8) -> atset1:9 */ | ||
"Digit9": 0xa, | ||
/* html:Digit9 (Digit9) -> linux:10 (KEY_9) -> atset1:10 */ | ||
"Eject": 0xe07d, | ||
/* html:Eject (Eject) -> linux:162 (KEY_EJECTCLOSECD) -> atset1:57469 */ | ||
"End": 0xe04f, | ||
/* html:End (End) -> linux:107 (KEY_END) -> atset1:57423 */ | ||
"Enter": 0x1c, | ||
/* html:Enter (Enter) -> linux:28 (KEY_ENTER) -> atset1:28 */ | ||
"Equal": 0xd, | ||
/* html:Equal (Equal) -> linux:13 (KEY_EQUAL) -> atset1:13 */ | ||
"Escape": 0x1, | ||
/* html:Escape (Escape) -> linux:1 (KEY_ESC) -> atset1:1 */ | ||
"F1": 0x3b, | ||
/* html:F1 (F1) -> linux:59 (KEY_F1) -> atset1:59 */ | ||
"F10": 0x44, | ||
/* html:F10 (F10) -> linux:68 (KEY_F10) -> atset1:68 */ | ||
"F11": 0x57, | ||
/* html:F11 (F11) -> linux:87 (KEY_F11) -> atset1:87 */ | ||
"F12": 0x58, | ||
/* html:F12 (F12) -> linux:88 (KEY_F12) -> atset1:88 */ | ||
"F13": 0x5d, | ||
/* html:F13 (F13) -> linux:183 (KEY_F13) -> atset1:93 */ | ||
"F14": 0x5e, | ||
/* html:F14 (F14) -> linux:184 (KEY_F14) -> atset1:94 */ | ||
"F15": 0x5f, | ||
/* html:F15 (F15) -> linux:185 (KEY_F15) -> atset1:95 */ | ||
"F16": 0x55, | ||
/* html:F16 (F16) -> linux:186 (KEY_F16) -> atset1:85 */ | ||
"F17": 0xe003, | ||
/* html:F17 (F17) -> linux:187 (KEY_F17) -> atset1:57347 */ | ||
"F18": 0xe077, | ||
/* html:F18 (F18) -> linux:188 (KEY_F18) -> atset1:57463 */ | ||
"F19": 0xe004, | ||
/* html:F19 (F19) -> linux:189 (KEY_F19) -> atset1:57348 */ | ||
"F2": 0x3c, | ||
/* html:F2 (F2) -> linux:60 (KEY_F2) -> atset1:60 */ | ||
"F20": 0x5a, | ||
/* html:F20 (F20) -> linux:190 (KEY_F20) -> atset1:90 */ | ||
"F21": 0x74, | ||
/* html:F21 (F21) -> linux:191 (KEY_F21) -> atset1:116 */ | ||
"F22": 0xe079, | ||
/* html:F22 (F22) -> linux:192 (KEY_F22) -> atset1:57465 */ | ||
"F23": 0x6d, | ||
/* html:F23 (F23) -> linux:193 (KEY_F23) -> atset1:109 */ | ||
"F24": 0x6f, | ||
/* html:F24 (F24) -> linux:194 (KEY_F24) -> atset1:111 */ | ||
"F3": 0x3d, | ||
/* html:F3 (F3) -> linux:61 (KEY_F3) -> atset1:61 */ | ||
"F4": 0x3e, | ||
/* html:F4 (F4) -> linux:62 (KEY_F4) -> atset1:62 */ | ||
"F5": 0x3f, | ||
/* html:F5 (F5) -> linux:63 (KEY_F5) -> atset1:63 */ | ||
"F6": 0x40, | ||
/* html:F6 (F6) -> linux:64 (KEY_F6) -> atset1:64 */ | ||
"F7": 0x41, | ||
/* html:F7 (F7) -> linux:65 (KEY_F7) -> atset1:65 */ | ||
"F8": 0x42, | ||
/* html:F8 (F8) -> linux:66 (KEY_F8) -> atset1:66 */ | ||
"F9": 0x43, | ||
/* html:F9 (F9) -> linux:67 (KEY_F9) -> atset1:67 */ | ||
"Find": 0xe041, | ||
/* html:Find (Find) -> linux:136 (KEY_FIND) -> atset1:57409 */ | ||
"Help": 0xe075, | ||
/* html:Help (Help) -> linux:138 (KEY_HELP) -> atset1:57461 */ | ||
"Hiragana": 0x77, | ||
/* html:Hiragana (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */ | ||
"Home": 0xe047, | ||
/* html:Home (Home) -> linux:102 (KEY_HOME) -> atset1:57415 */ | ||
"Insert": 0xe052, | ||
/* html:Insert (Insert) -> linux:110 (KEY_INSERT) -> atset1:57426 */ | ||
"IntlBackslash": 0x56, | ||
/* html:IntlBackslash (IntlBackslash) -> linux:86 (KEY_102ND) -> atset1:86 */ | ||
"IntlRo": 0x73, | ||
/* html:IntlRo (IntlRo) -> linux:89 (KEY_RO) -> atset1:115 */ | ||
"IntlYen": 0x7d, | ||
/* html:IntlYen (IntlYen) -> linux:124 (KEY_YEN) -> atset1:125 */ | ||
"KanaMode": 0x70, | ||
/* html:KanaMode (KanaMode) -> linux:93 (KEY_KATAKANAHIRAGANA) -> atset1:112 */ | ||
"Katakana": 0x78, | ||
/* html:Katakana (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */ | ||
"KeyA": 0x1e, | ||
/* html:KeyA (KeyA) -> linux:30 (KEY_A) -> atset1:30 */ | ||
"KeyB": 0x30, | ||
/* html:KeyB (KeyB) -> linux:48 (KEY_B) -> atset1:48 */ | ||
"KeyC": 0x2e, | ||
/* html:KeyC (KeyC) -> linux:46 (KEY_C) -> atset1:46 */ | ||
"KeyD": 0x20, | ||
/* html:KeyD (KeyD) -> linux:32 (KEY_D) -> atset1:32 */ | ||
"KeyE": 0x12, | ||
/* html:KeyE (KeyE) -> linux:18 (KEY_E) -> atset1:18 */ | ||
"KeyF": 0x21, | ||
/* html:KeyF (KeyF) -> linux:33 (KEY_F) -> atset1:33 */ | ||
"KeyG": 0x22, | ||
/* html:KeyG (KeyG) -> linux:34 (KEY_G) -> atset1:34 */ | ||
"KeyH": 0x23, | ||
/* html:KeyH (KeyH) -> linux:35 (KEY_H) -> atset1:35 */ | ||
"KeyI": 0x17, | ||
/* html:KeyI (KeyI) -> linux:23 (KEY_I) -> atset1:23 */ | ||
"KeyJ": 0x24, | ||
/* html:KeyJ (KeyJ) -> linux:36 (KEY_J) -> atset1:36 */ | ||
"KeyK": 0x25, | ||
/* html:KeyK (KeyK) -> linux:37 (KEY_K) -> atset1:37 */ | ||
"KeyL": 0x26, | ||
/* html:KeyL (KeyL) -> linux:38 (KEY_L) -> atset1:38 */ | ||
"KeyM": 0x32, | ||
/* html:KeyM (KeyM) -> linux:50 (KEY_M) -> atset1:50 */ | ||
"KeyN": 0x31, | ||
/* html:KeyN (KeyN) -> linux:49 (KEY_N) -> atset1:49 */ | ||
"KeyO": 0x18, | ||
/* html:KeyO (KeyO) -> linux:24 (KEY_O) -> atset1:24 */ | ||
"KeyP": 0x19, | ||
/* html:KeyP (KeyP) -> linux:25 (KEY_P) -> atset1:25 */ | ||
"KeyQ": 0x10, | ||
/* html:KeyQ (KeyQ) -> linux:16 (KEY_Q) -> atset1:16 */ | ||
"KeyR": 0x13, | ||
/* html:KeyR (KeyR) -> linux:19 (KEY_R) -> atset1:19 */ | ||
"KeyS": 0x1f, | ||
/* html:KeyS (KeyS) -> linux:31 (KEY_S) -> atset1:31 */ | ||
"KeyT": 0x14, | ||
/* html:KeyT (KeyT) -> linux:20 (KEY_T) -> atset1:20 */ | ||
"KeyU": 0x16, | ||
/* html:KeyU (KeyU) -> linux:22 (KEY_U) -> atset1:22 */ | ||
"KeyV": 0x2f, | ||
/* html:KeyV (KeyV) -> linux:47 (KEY_V) -> atset1:47 */ | ||
"KeyW": 0x11, | ||
/* html:KeyW (KeyW) -> linux:17 (KEY_W) -> atset1:17 */ | ||
"KeyX": 0x2d, | ||
/* html:KeyX (KeyX) -> linux:45 (KEY_X) -> atset1:45 */ | ||
"KeyY": 0x15, | ||
/* html:KeyY (KeyY) -> linux:21 (KEY_Y) -> atset1:21 */ | ||
"KeyZ": 0x2c, | ||
/* html:KeyZ (KeyZ) -> linux:44 (KEY_Z) -> atset1:44 */ | ||
"Lang1": 0x72, | ||
/* html:Lang1 (Lang1) -> linux:122 (KEY_HANGEUL) -> atset1:114 */ | ||
"Lang2": 0x71, | ||
/* html:Lang2 (Lang2) -> linux:123 (KEY_HANJA) -> atset1:113 */ | ||
"Lang3": 0x78, | ||
/* html:Lang3 (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */ | ||
"Lang4": 0x77, | ||
/* html:Lang4 (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */ | ||
"Lang5": 0x76, | ||
/* html:Lang5 (Lang5) -> linux:85 (KEY_ZENKAKUHANKAKU) -> atset1:118 */ | ||
"LaunchApp1": 0xe06b, | ||
/* html:LaunchApp1 (LaunchApp1) -> linux:157 (KEY_COMPUTER) -> atset1:57451 */ | ||
"LaunchApp2": 0xe021, | ||
/* html:LaunchApp2 (LaunchApp2) -> linux:140 (KEY_CALC) -> atset1:57377 */ | ||
"LaunchMail": 0xe06c, | ||
/* html:LaunchMail (LaunchMail) -> linux:155 (KEY_MAIL) -> atset1:57452 */ | ||
"MediaPlayPause": 0xe022, | ||
/* html:MediaPlayPause (MediaPlayPause) -> linux:164 (KEY_PLAYPAUSE) -> atset1:57378 */ | ||
"MediaSelect": 0xe06d, | ||
/* html:MediaSelect (MediaSelect) -> linux:226 (KEY_MEDIA) -> atset1:57453 */ | ||
"MediaStop": 0xe024, | ||
/* html:MediaStop (MediaStop) -> linux:166 (KEY_STOPCD) -> atset1:57380 */ | ||
"MediaTrackNext": 0xe019, | ||
/* html:MediaTrackNext (MediaTrackNext) -> linux:163 (KEY_NEXTSONG) -> atset1:57369 */ | ||
"MediaTrackPrevious": 0xe010, | ||
/* html:MediaTrackPrevious (MediaTrackPrevious) -> linux:165 (KEY_PREVIOUSSONG) -> atset1:57360 */ | ||
"MetaLeft": 0xe05b, | ||
/* html:MetaLeft (MetaLeft) -> linux:125 (KEY_LEFTMETA) -> atset1:57435 */ | ||
"MetaRight": 0xe05c, | ||
/* html:MetaRight (MetaRight) -> linux:126 (KEY_RIGHTMETA) -> atset1:57436 */ | ||
"Minus": 0xc, | ||
/* html:Minus (Minus) -> linux:12 (KEY_MINUS) -> atset1:12 */ | ||
"NonConvert": 0x7b, | ||
/* html:NonConvert (NonConvert) -> linux:94 (KEY_MUHENKAN) -> atset1:123 */ | ||
"NumLock": 0x45, | ||
/* html:NumLock (NumLock) -> linux:69 (KEY_NUMLOCK) -> atset1:69 */ | ||
"Numpad0": 0x52, | ||
/* html:Numpad0 (Numpad0) -> linux:82 (KEY_KP0) -> atset1:82 */ | ||
"Numpad1": 0x4f, | ||
/* html:Numpad1 (Numpad1) -> linux:79 (KEY_KP1) -> atset1:79 */ | ||
"Numpad2": 0x50, | ||
/* html:Numpad2 (Numpad2) -> linux:80 (KEY_KP2) -> atset1:80 */ | ||
"Numpad3": 0x51, | ||
/* html:Numpad3 (Numpad3) -> linux:81 (KEY_KP3) -> atset1:81 */ | ||
"Numpad4": 0x4b, | ||
/* html:Numpad4 (Numpad4) -> linux:75 (KEY_KP4) -> atset1:75 */ | ||
"Numpad5": 0x4c, | ||
/* html:Numpad5 (Numpad5) -> linux:76 (KEY_KP5) -> atset1:76 */ | ||
"Numpad6": 0x4d, | ||
/* html:Numpad6 (Numpad6) -> linux:77 (KEY_KP6) -> atset1:77 */ | ||
"Numpad7": 0x47, | ||
/* html:Numpad7 (Numpad7) -> linux:71 (KEY_KP7) -> atset1:71 */ | ||
"Numpad8": 0x48, | ||
/* html:Numpad8 (Numpad8) -> linux:72 (KEY_KP8) -> atset1:72 */ | ||
"Numpad9": 0x49, | ||
/* html:Numpad9 (Numpad9) -> linux:73 (KEY_KP9) -> atset1:73 */ | ||
"NumpadAdd": 0x4e, | ||
/* html:NumpadAdd (NumpadAdd) -> linux:78 (KEY_KPPLUS) -> atset1:78 */ | ||
"NumpadComma": 0x7e, | ||
/* html:NumpadComma (NumpadComma) -> linux:121 (KEY_KPCOMMA) -> atset1:126 */ | ||
"NumpadDecimal": 0x53, | ||
/* html:NumpadDecimal (NumpadDecimal) -> linux:83 (KEY_KPDOT) -> atset1:83 */ | ||
"NumpadDivide": 0xe035, | ||
/* html:NumpadDivide (NumpadDivide) -> linux:98 (KEY_KPSLASH) -> atset1:57397 */ | ||
"NumpadEnter": 0xe01c, | ||
/* html:NumpadEnter (NumpadEnter) -> linux:96 (KEY_KPENTER) -> atset1:57372 */ | ||
"NumpadEqual": 0x59, | ||
/* html:NumpadEqual (NumpadEqual) -> linux:117 (KEY_KPEQUAL) -> atset1:89 */ | ||
"NumpadMultiply": 0x37, | ||
/* html:NumpadMultiply (NumpadMultiply) -> linux:55 (KEY_KPASTERISK) -> atset1:55 */ | ||
"NumpadParenLeft": 0xe076, | ||
/* html:NumpadParenLeft (NumpadParenLeft) -> linux:179 (KEY_KPLEFTPAREN) -> atset1:57462 */ | ||
"NumpadParenRight": 0xe07b, | ||
/* html:NumpadParenRight (NumpadParenRight) -> linux:180 (KEY_KPRIGHTPAREN) -> atset1:57467 */ | ||
"NumpadSubtract": 0x4a, | ||
/* html:NumpadSubtract (NumpadSubtract) -> linux:74 (KEY_KPMINUS) -> atset1:74 */ | ||
"Open": 0x64, | ||
/* html:Open (Open) -> linux:134 (KEY_OPEN) -> atset1:100 */ | ||
"PageDown": 0xe051, | ||
/* html:PageDown (PageDown) -> linux:109 (KEY_PAGEDOWN) -> atset1:57425 */ | ||
"PageUp": 0xe049, | ||
/* html:PageUp (PageUp) -> linux:104 (KEY_PAGEUP) -> atset1:57417 */ | ||
"Paste": 0x65, | ||
/* html:Paste (Paste) -> linux:135 (KEY_PASTE) -> atset1:101 */ | ||
"Pause": 0xe046, | ||
/* html:Pause (Pause) -> linux:119 (KEY_PAUSE) -> atset1:57414 */ | ||
"Period": 0x34, | ||
/* html:Period (Period) -> linux:52 (KEY_DOT) -> atset1:52 */ | ||
"Power": 0xe05e, | ||
/* html:Power (Power) -> linux:116 (KEY_POWER) -> atset1:57438 */ | ||
"PrintScreen": 0x54, | ||
/* html:PrintScreen (PrintScreen) -> linux:99 (KEY_SYSRQ) -> atset1:84 */ | ||
"Props": 0xe006, | ||
/* html:Props (Props) -> linux:130 (KEY_PROPS) -> atset1:57350 */ | ||
"Quote": 0x28, | ||
/* html:Quote (Quote) -> linux:40 (KEY_APOSTROPHE) -> atset1:40 */ | ||
"ScrollLock": 0x46, | ||
/* html:ScrollLock (ScrollLock) -> linux:70 (KEY_SCROLLLOCK) -> atset1:70 */ | ||
"Semicolon": 0x27, | ||
/* html:Semicolon (Semicolon) -> linux:39 (KEY_SEMICOLON) -> atset1:39 */ | ||
"ShiftLeft": 0x2a, | ||
/* html:ShiftLeft (ShiftLeft) -> linux:42 (KEY_LEFTSHIFT) -> atset1:42 */ | ||
"ShiftRight": 0x36, | ||
/* html:ShiftRight (ShiftRight) -> linux:54 (KEY_RIGHTSHIFT) -> atset1:54 */ | ||
"Slash": 0x35, | ||
/* html:Slash (Slash) -> linux:53 (KEY_SLASH) -> atset1:53 */ | ||
"Sleep": 0xe05f, | ||
/* html:Sleep (Sleep) -> linux:142 (KEY_SLEEP) -> atset1:57439 */ | ||
"Space": 0x39, | ||
/* html:Space (Space) -> linux:57 (KEY_SPACE) -> atset1:57 */ | ||
"Suspend": 0xe025, | ||
/* html:Suspend (Suspend) -> linux:205 (KEY_SUSPEND) -> atset1:57381 */ | ||
"Tab": 0xf, | ||
/* html:Tab (Tab) -> linux:15 (KEY_TAB) -> atset1:15 */ | ||
"Undo": 0xe007, | ||
/* html:Undo (Undo) -> linux:131 (KEY_UNDO) -> atset1:57351 */ | ||
"WakeUp": 0xe063 | ||
/* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */ | ||
"WakeUp": 0xe063 /* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */ | ||
}; | ||
exports["default"] = _default; |
250
lib/ra2.js
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,41 +7,25 @@ value: true | ||
exports["default"] = exports.RSACipher = exports.RA2Cipher = exports.AESEAXCipher = void 0; | ||
var _base = _interopRequireDefault(require("./base64.js")); | ||
var _strings = require("./util/strings.js"); | ||
var _eventtarget = _interopRequireDefault(require("./util/eventtarget.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
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); }; } | ||
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); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
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; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var AESEAXCipher = /*#__PURE__*/function () { | ||
function AESEAXCipher() { | ||
_classCallCheck(this, AESEAXCipher); | ||
this._rawKey = null; | ||
@@ -57,3 +39,2 @@ this._ctrKey = null; | ||
} | ||
_createClass(AESEAXCipher, [{ | ||
@@ -73,7 +54,5 @@ key: "_encryptBlock", | ||
}, this._cbcKey, block); | ||
case 2: | ||
encrypted = _context.sent; | ||
return _context.abrupt("return", new Uint8Array(encrypted).slice(0, 16)); | ||
case 4: | ||
@@ -86,7 +65,5 @@ case "end": | ||
})); | ||
function _encryptBlock(_x) { | ||
return _encryptBlock2.apply(this, arguments); | ||
} | ||
return _encryptBlock; | ||
@@ -105,3 +82,2 @@ }() | ||
return this._encryptBlock(this._zeroBlock); | ||
case 2: | ||
@@ -111,3 +87,2 @@ k1 = _context2.sent; | ||
v = k1[0] >>> 6; | ||
for (i = 0; i < 15; i++) { | ||
@@ -117,3 +92,2 @@ k2[i] = k1[i + 1] >> 6 | k1[i] << 2; | ||
} | ||
lut = [0x0, 0x87, 0x0e, 0x89]; | ||
@@ -125,3 +99,2 @@ k2[14] ^= v >>> 1; | ||
this._k2 = k2; | ||
case 12: | ||
@@ -134,7 +107,5 @@ case "end": | ||
})); | ||
function _initCMAC() { | ||
return _initCMAC2.apply(this, arguments); | ||
} | ||
return _initCMAC; | ||
@@ -157,7 +128,5 @@ }() | ||
}, this._ctrKey, data); | ||
case 2: | ||
encrypted = _context3.sent; | ||
return _context3.abrupt("return", new Uint8Array(encrypted)); | ||
case 4: | ||
@@ -170,7 +139,5 @@ case "end": | ||
})); | ||
function _encryptCTR(_x2, _x3) { | ||
return _encryptCTR2.apply(this, arguments); | ||
} | ||
return _encryptCTR; | ||
@@ -193,7 +160,5 @@ }() | ||
}, this._ctrKey, data); | ||
case 2: | ||
decrypted = _context4.sent; | ||
return _context4.abrupt("return", new Uint8Array(decrypted)); | ||
case 4: | ||
@@ -206,7 +171,5 @@ case "end": | ||
})); | ||
function _decryptCTR(_x4, _x5) { | ||
return _decryptCTR2.apply(this, arguments); | ||
} | ||
return _decryptCTR; | ||
@@ -219,3 +182,2 @@ }() | ||
var n, m, r, cbcData, i, _i, cbcEncrypted, mac; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
@@ -229,5 +191,3 @@ while (1) { | ||
} | ||
return _context5.abrupt("return", null); | ||
case 2: | ||
@@ -240,3 +200,2 @@ n = Math.floor(data.length / 16); | ||
cbcData.set(data, 16); | ||
if (r === 0) { | ||
@@ -248,3 +207,2 @@ for (i = 0; i < 16; i++) { | ||
cbcData[(n + 1) * 16 + r] = 0x80; | ||
for (_i = 0; _i < 16; _i++) { | ||
@@ -254,3 +212,2 @@ cbcData[(n + 1) * 16 + _i] ^= this._k2[_i]; | ||
} | ||
_context5.next = 11; | ||
@@ -261,3 +218,2 @@ return window.crypto.subtle.encrypt({ | ||
}, this._cbcKey, cbcData); | ||
case 11: | ||
@@ -268,3 +224,2 @@ cbcEncrypted = _context5.sent; | ||
return _context5.abrupt("return", mac); | ||
case 15: | ||
@@ -277,7 +232,5 @@ case "end": | ||
})); | ||
function _computeCMAC(_x6, _x7) { | ||
return _computeCMAC2.apply(this, arguments); | ||
} | ||
return _computeCMAC; | ||
@@ -298,3 +251,2 @@ }() | ||
}, false, ["encrypt", "decrypt"]); | ||
case 3: | ||
@@ -306,3 +258,2 @@ this._ctrKey = _context6.sent; | ||
}, false, ["encrypt", "decrypt"]); | ||
case 6: | ||
@@ -312,3 +263,2 @@ this._cbcKey = _context6.sent; | ||
return this._initCMAC(); | ||
case 9: | ||
@@ -321,7 +271,5 @@ case "end": | ||
})); | ||
function setKey(_x8) { | ||
return _setKey.apply(this, arguments); | ||
} | ||
return setKey; | ||
@@ -340,3 +288,2 @@ }() | ||
return this._computeCMAC(nonce, this._prefixBlock0); | ||
case 2: | ||
@@ -346,3 +293,2 @@ nCMAC = _context7.sent; | ||
return this._encryptCTR(message, nCMAC); | ||
case 5: | ||
@@ -352,3 +298,2 @@ encrypted = _context7.sent; | ||
return this._computeCMAC(associatedData, this._prefixBlock1); | ||
case 8: | ||
@@ -358,10 +303,7 @@ adCMAC = _context7.sent; | ||
return this._computeCMAC(encrypted, this._prefixBlock2); | ||
case 11: | ||
mac = _context7.sent; | ||
for (i = 0; i < 16; i++) { | ||
mac[i] ^= nCMAC[i] ^ adCMAC[i]; | ||
} | ||
res = new Uint8Array(16 + encrypted.length); | ||
@@ -371,3 +313,2 @@ res.set(encrypted); | ||
return _context7.abrupt("return", res); | ||
case 17: | ||
@@ -380,7 +321,5 @@ case "end": | ||
})); | ||
function encrypt(_x9, _x10, _x11) { | ||
return _encrypt.apply(this, arguments); | ||
} | ||
return encrypt; | ||
@@ -393,3 +332,2 @@ }() | ||
var nCMAC, adCMAC, computedMac, i, _i2, res; | ||
return _regeneratorRuntime().wrap(function _callee8$(_context8) { | ||
@@ -401,3 +339,2 @@ while (1) { | ||
return this._computeCMAC(nonce, this._prefixBlock0); | ||
case 2: | ||
@@ -407,3 +344,2 @@ nCMAC = _context8.sent; | ||
return this._computeCMAC(associatedData, this._prefixBlock1); | ||
case 5: | ||
@@ -413,10 +349,7 @@ adCMAC = _context8.sent; | ||
return this._computeCMAC(encrypted, this._prefixBlock2); | ||
case 8: | ||
computedMac = _context8.sent; | ||
for (i = 0; i < 16; i++) { | ||
computedMac[i] ^= nCMAC[i] ^ adCMAC[i]; | ||
} | ||
if (!(computedMac.length !== mac.length)) { | ||
@@ -426,8 +359,5 @@ _context8.next = 12; | ||
} | ||
return _context8.abrupt("return", null); | ||
case 12: | ||
_i2 = 0; | ||
case 13: | ||
@@ -438,3 +368,2 @@ if (!(_i2 < mac.length)) { | ||
} | ||
if (!(computedMac[_i2] !== mac[_i2])) { | ||
@@ -444,5 +373,3 @@ _context8.next = 16; | ||
} | ||
return _context8.abrupt("return", null); | ||
case 16: | ||
@@ -452,11 +379,8 @@ _i2++; | ||
break; | ||
case 19: | ||
_context8.next = 21; | ||
return this._decryptCTR(encrypted, nCMAC); | ||
case 21: | ||
res = _context8.sent; | ||
return _context8.abrupt("return", res); | ||
case 23: | ||
@@ -469,24 +393,17 @@ case "end": | ||
})); | ||
function decrypt(_x12, _x13, _x14, _x15) { | ||
return _decrypt.apply(this, arguments); | ||
} | ||
return decrypt; | ||
}() | ||
}]); | ||
return AESEAXCipher; | ||
}(); | ||
exports.AESEAXCipher = AESEAXCipher; | ||
var RA2Cipher = /*#__PURE__*/function () { | ||
function RA2Cipher() { | ||
_classCallCheck(this, RA2Cipher); | ||
this._cipher = new AESEAXCipher(); | ||
this._counter = new Uint8Array(16); | ||
} | ||
_createClass(RA2Cipher, [{ | ||
@@ -502,3 +419,2 @@ key: "setKey", | ||
return this._cipher.setKey(key); | ||
case 2: | ||
@@ -511,7 +427,5 @@ case "end": | ||
})); | ||
function setKey(_x16) { | ||
return _setKey2.apply(this, arguments); | ||
} | ||
return setKey; | ||
@@ -531,10 +445,7 @@ }() | ||
return this._cipher.encrypt(message, ad, this._counter); | ||
case 3: | ||
encrypted = _context10.sent; | ||
for (i = 0; i < 16 && this._counter[i]++ === 255; i++) { | ||
; | ||
} | ||
res = new Uint8Array(message.length + 2 + 16); | ||
@@ -544,3 +455,2 @@ res.set(ad); | ||
return _context10.abrupt("return", res); | ||
case 9: | ||
@@ -553,7 +463,5 @@ case "end": | ||
})); | ||
function makeMessage(_x17) { | ||
return _makeMessage.apply(this, arguments); | ||
} | ||
return makeMessage; | ||
@@ -573,12 +481,8 @@ }() | ||
return this._cipher.decrypt(encrypted, ad, this._counter, mac); | ||
case 3: | ||
res = _context11.sent; | ||
for (i = 0; i < 16 && this._counter[i]++ === 255; i++) { | ||
; | ||
} | ||
return _context11.abrupt("return", res); | ||
case 6: | ||
@@ -591,20 +495,14 @@ case "end": | ||
})); | ||
function receiveMessage(_x18, _x19, _x20) { | ||
return _receiveMessage.apply(this, arguments); | ||
} | ||
return receiveMessage; | ||
}() | ||
}]); | ||
return RA2Cipher; | ||
}(); | ||
exports.RA2Cipher = RA2Cipher; | ||
var RSACipher = /*#__PURE__*/function () { | ||
function RSACipher(keyLength) { | ||
_classCallCheck(this, RSACipher); | ||
this._key = null; | ||
@@ -620,3 +518,2 @@ this._keyLength = keyLength; | ||
} | ||
_createClass(RSACipher, [{ | ||
@@ -633,7 +530,5 @@ key: "_base64urlDecode", | ||
var hex = '0x'; | ||
for (var i = 0; i < arr.length; i++) { | ||
hex += arr[i].toString(16).padStart(2, '0'); | ||
} | ||
return BigInt(hex); | ||
@@ -653,15 +548,11 @@ } | ||
var hex = bigint.toString(16); | ||
if (padLength === 0) { | ||
padLength = Math.ceil(hex.length / 2) * 2; | ||
} | ||
hex = hex.padStart(padLength * 2, '0'); | ||
var length = hex.length / 2; | ||
var arr = new Uint8Array(length); | ||
for (var i = 0; i < length; i++) { | ||
arr[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16); | ||
} | ||
return arr; | ||
@@ -675,6 +566,4 @@ } | ||
} | ||
var r = 1n; | ||
b = b % m; | ||
while (e > 0) { | ||
@@ -684,7 +573,5 @@ if (e % 2n === 1n) { | ||
} | ||
e = e / 2n; | ||
b = b * b % m; | ||
} | ||
return r; | ||
@@ -710,3 +597,2 @@ } | ||
}, true, ["encrypt", "decrypt"]); | ||
case 2: | ||
@@ -716,3 +602,2 @@ this._key = _context12.sent; | ||
return window.crypto.subtle.exportKey("jwk", this._key.privateKey); | ||
case 5: | ||
@@ -726,3 +611,2 @@ privateKey = _context12.sent; | ||
this._dBigInt = this._u8ArrayToBigInt(this._d); | ||
case 12: | ||
@@ -735,7 +619,5 @@ case "end": | ||
})); | ||
function generateKey() { | ||
return _generateKey.apply(this, arguments); | ||
} | ||
return generateKey; | ||
@@ -749,10 +631,6 @@ }() | ||
} | ||
this._n = new Uint8Array(this._keyBytes); | ||
this._e = new Uint8Array(this._keyBytes); | ||
this._n.set(n); | ||
this._e.set(e); | ||
this._nBigInt = this._u8ArrayToBigInt(this._n); | ||
@@ -767,10 +645,7 @@ this._eBigInt = this._u8ArrayToBigInt(this._e); | ||
} | ||
var ps = new Uint8Array(this._keyBytes - message.length - 3); | ||
window.crypto.getRandomValues(ps); | ||
for (var i = 0; i < ps.length; i++) { | ||
ps[i] = Math.floor(ps[i] * 254 / 255 + 1); | ||
} | ||
var em = new Uint8Array(this._keyBytes); | ||
@@ -780,7 +655,4 @@ em[1] = 0x02; | ||
em.set(message, ps.length + 3); | ||
var emBigInt = this._u8ArrayToBigInt(em); | ||
var c = this._modPow(emBigInt, this._eBigInt, this._nBigInt); | ||
return this._bigIntToU8Array(c, this._keyBytes); | ||
@@ -794,15 +666,9 @@ } | ||
} | ||
var msgBigInt = this._u8ArrayToBigInt(message); | ||
var emBigInt = this._modPow(msgBigInt, this._dBigInt, this._nBigInt); | ||
var em = this._bigIntToU8Array(emBigInt, this._keyBytes); | ||
if (em[0] !== 0x00 || em[1] !== 0x02) { | ||
return null; | ||
} | ||
var i = 2; | ||
for (; i < em.length; i++) { | ||
@@ -813,7 +679,5 @@ if (em[i] === 0x00) { | ||
} | ||
if (i === em.length) { | ||
return null; | ||
} | ||
return em.slice(i + 1, em.length); | ||
@@ -842,18 +706,11 @@ } | ||
}]); | ||
return RSACipher; | ||
}(); | ||
exports.RSACipher = RSACipher; | ||
var RSAAESAuthenticationState = /*#__PURE__*/function (_EventTargetMixin) { | ||
_inherits(RSAAESAuthenticationState, _EventTargetMixin); | ||
var _super = _createSuper(RSAAESAuthenticationState); | ||
function RSAAESAuthenticationState(sock, getCredentials) { | ||
var _this; | ||
_classCallCheck(this, RSAAESAuthenticationState); | ||
_this = _super.call(this); | ||
@@ -871,3 +728,2 @@ _this._hasStarted = false; | ||
} | ||
_createClass(RSAAESAuthenticationState, [{ | ||
@@ -877,3 +733,2 @@ key: "_waitSockAsync", | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
@@ -883,3 +738,2 @@ var hasData = function hasData() { | ||
}; | ||
if (hasData()) { | ||
@@ -895,3 +749,2 @@ resolve(); | ||
}; | ||
_this2._sockReject = reject; | ||
@@ -905,3 +758,2 @@ } | ||
var _this3 = this; | ||
return new Promise(function (resolve, reject) { | ||
@@ -916,3 +768,2 @@ _this3._approveServerResolve = resolve; | ||
var _this4 = this; | ||
var hasCredentials = function hasCredentials() { | ||
@@ -924,6 +775,4 @@ if (subtype === 1 && _this4._getCredentials().username !== undefined && _this4._getCredentials().password !== undefined) { | ||
} | ||
return false; | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
@@ -940,3 +789,2 @@ if (hasCredentials()) { | ||
}; | ||
_this4._credentialsReject = reject; | ||
@@ -952,3 +800,2 @@ } | ||
} | ||
if (this._checkCredentials !== null) { | ||
@@ -963,3 +810,2 @@ this._checkCredentials(); | ||
this._approveServerResolve(); | ||
this._approveServerResolve = null; | ||
@@ -973,15 +819,10 @@ } | ||
this._sockReject(new Error("disconnect normally")); | ||
this._sockReject = null; | ||
} | ||
if (this._credentialsReject !== null) { | ||
this._credentialsReject(new Error("disconnect normally")); | ||
this._credentialsReject = null; | ||
} | ||
if (this._approveServerReject !== null) { | ||
this._approveServerReject(new Error("disconnect normally")); | ||
this._approveServerReject = null; | ||
@@ -995,3 +836,2 @@ } | ||
var serverKeyLengthBuffer, serverKeyLength, serverKeyBytes, serverN, serverE, serverRSACipher, serverPublickey, clientKeyLength, clientKeyBytes, clientRSACipher, clientN, clientE, clientPublicKey, clientRandom, clientEncryptedRandom, clientRandomMessage, serverEncryptedRandom, serverRandom, clientSessionKey, serverSessionKey, clientCipher, serverCipher, serverHash, clientHash, serverHashReceived, i, subtype, username, password, credentials, _i3, _i4; | ||
return _regeneratorRuntime().wrap(function _callee13$(_context13) { | ||
@@ -1001,11 +841,9 @@ while (1) { | ||
case 0: | ||
this._hasStarted = true; // 1: Receive server public key | ||
this._hasStarted = true; | ||
// 1: Receive server public key | ||
_context13.next = 3; | ||
return this._waitSockAsync(4); | ||
case 3: | ||
serverKeyLengthBuffer = this._sock.rQslice(0, 4); | ||
serverKeyLength = this._sock.rQshift32(); | ||
if (!(serverKeyLength < 1024)) { | ||
@@ -1015,5 +853,3 @@ _context13.next = 9; | ||
} | ||
throw new Error("RA2: server public key is too short: " + serverKeyLength); | ||
case 9: | ||
@@ -1024,5 +860,3 @@ if (!(serverKeyLength > 8192)) { | ||
} | ||
throw new Error("RA2: server public key is too long: " + serverKeyLength); | ||
case 11: | ||
@@ -1032,3 +866,2 @@ serverKeyBytes = Math.ceil(serverKeyLength / 8); | ||
return this._waitSockAsync(serverKeyBytes * 2); | ||
case 14: | ||
@@ -1042,4 +875,5 @@ serverN = this._sock.rQshiftBytes(serverKeyBytes); | ||
serverPublickey.set(serverN, 4); | ||
serverPublickey.set(serverE, 4 + serverKeyBytes); // verify server public key | ||
serverPublickey.set(serverE, 4 + serverKeyBytes); | ||
// verify server public key | ||
this.dispatchEvent(new CustomEvent("serververification", { | ||
@@ -1053,3 +887,2 @@ detail: { | ||
return this._waitApproveKeyAsync(); | ||
case 25: | ||
@@ -1062,3 +895,2 @@ // 2: Send client public key | ||
return clientRSACipher.generateKey(); | ||
case 30: | ||
@@ -1074,6 +906,5 @@ clientN = clientRSACipher.n; | ||
clientPublicKey.set(clientE, 4 + clientKeyBytes); | ||
this._sock.send(clientPublicKey); | ||
this._sock.send(clientPublicKey); // 3: Send client random | ||
// 3: Send client random | ||
clientRandom = new Uint8Array(16); | ||
@@ -1086,9 +917,7 @@ window.crypto.getRandomValues(clientRandom); | ||
clientRandomMessage.set(clientEncryptedRandom, 2); | ||
this._sock.send(clientRandomMessage); | ||
this._sock.send(clientRandomMessage); // 4: Receive server random | ||
// 4: Receive server random | ||
_context13.next = 50; | ||
return this._waitSockAsync(2); | ||
case 50: | ||
@@ -1099,9 +928,6 @@ if (!(this._sock.rQshift16() !== clientKeyBytes)) { | ||
} | ||
throw new Error("RA2: wrong encrypted message length"); | ||
case 52: | ||
serverEncryptedRandom = this._sock.rQshiftBytes(clientKeyBytes); | ||
serverRandom = clientRSACipher.decrypt(serverEncryptedRandom); | ||
if (!(serverRandom === null || serverRandom.length !== 16)) { | ||
@@ -1111,5 +937,3 @@ _context13.next = 56; | ||
} | ||
throw new Error("RA2: corrupted server encrypted random"); | ||
case 56: | ||
@@ -1125,3 +949,2 @@ // 5: Compute session keys and set ciphers | ||
return window.crypto.subtle.digest("SHA-1", clientSessionKey); | ||
case 64: | ||
@@ -1132,3 +955,2 @@ clientSessionKey = _context13.sent; | ||
return window.crypto.subtle.digest("SHA-1", serverSessionKey); | ||
case 68: | ||
@@ -1140,3 +962,2 @@ serverSessionKey = _context13.sent; | ||
return clientCipher.setKey(clientSessionKey); | ||
case 73: | ||
@@ -1146,3 +967,2 @@ serverCipher = new RA2Cipher(); | ||
return serverCipher.setKey(serverSessionKey); | ||
case 76: | ||
@@ -1158,3 +978,2 @@ // 6: Compute and exchange hashes | ||
return window.crypto.subtle.digest("SHA-1", serverHash); | ||
case 84: | ||
@@ -1164,3 +983,2 @@ serverHash = _context13.sent; | ||
return window.crypto.subtle.digest("SHA-1", clientHash); | ||
case 87: | ||
@@ -1173,11 +991,7 @@ clientHash = _context13.sent; | ||
return clientCipher.makeMessage(clientHash); | ||
case 93: | ||
_context13.t1 = _context13.sent; | ||
_context13.t0.send.call(_context13.t0, _context13.t1); | ||
_context13.next = 97; | ||
return this._waitSockAsync(2 + 20 + 16); | ||
case 97: | ||
@@ -1188,12 +1002,8 @@ if (!(this._sock.rQshift16() !== 20)) { | ||
} | ||
throw new Error("RA2: wrong server hash"); | ||
case 99: | ||
_context13.next = 101; | ||
return serverCipher.receiveMessage(20, this._sock.rQshiftBytes(20), this._sock.rQshiftBytes(16)); | ||
case 101: | ||
serverHashReceived = _context13.sent; | ||
if (!(serverHashReceived === null)) { | ||
@@ -1203,8 +1013,5 @@ _context13.next = 104; | ||
} | ||
throw new Error("RA2: failed to authenticate the message"); | ||
case 104: | ||
i = 0; | ||
case 105: | ||
@@ -1215,3 +1022,2 @@ if (!(i < 20)) { | ||
} | ||
if (!(serverHashReceived[i] !== serverHash[i])) { | ||
@@ -1221,5 +1027,3 @@ _context13.next = 108; | ||
} | ||
throw new Error("RA2: wrong server hash"); | ||
case 108: | ||
@@ -1229,7 +1033,5 @@ i++; | ||
break; | ||
case 111: | ||
_context13.next = 113; | ||
return this._waitSockAsync(2 + 1 + 16); | ||
case 113: | ||
@@ -1240,12 +1042,8 @@ if (!(this._sock.rQshift16() !== 1)) { | ||
} | ||
throw new Error("RA2: wrong subtype"); | ||
case 115: | ||
_context13.next = 117; | ||
return serverCipher.receiveMessage(1, this._sock.rQshiftBytes(1), this._sock.rQshiftBytes(16)); | ||
case 117: | ||
subtype = _context13.sent; | ||
if (!(subtype === null)) { | ||
@@ -1255,8 +1053,5 @@ _context13.next = 120; | ||
} | ||
throw new Error("RA2: failed to authenticate the message"); | ||
case 120: | ||
subtype = subtype[0]; | ||
if (!(subtype === 1)) { | ||
@@ -1266,3 +1061,2 @@ _context13.next = 125; | ||
} | ||
if (this._getCredentials().username === undefined || this._getCredentials().password === undefined) { | ||
@@ -1275,6 +1069,4 @@ this.dispatchEvent(new CustomEvent("credentialsrequired", { | ||
} | ||
_context13.next = 130; | ||
break; | ||
case 125: | ||
@@ -1285,3 +1077,2 @@ if (!(subtype === 2)) { | ||
} | ||
if (this._getCredentials().password === undefined) { | ||
@@ -1294,13 +1085,9 @@ this.dispatchEvent(new CustomEvent("credentialsrequired", { | ||
} | ||
_context13.next = 130; | ||
break; | ||
case 129: | ||
throw new Error("RA2: wrong subtype"); | ||
case 130: | ||
_context13.next = 132; | ||
return this._waitCredentialsAsync(subtype); | ||
case 132: | ||
@@ -1312,3 +1099,2 @@ if (subtype === 1) { | ||
} | ||
password = (0, _strings.encodeUTF8)(this._getCredentials().password).slice(0, 255); | ||
@@ -1318,20 +1104,14 @@ credentials = new Uint8Array(username.length + password.length + 2); | ||
credentials[username.length + 1] = password.length; | ||
for (_i3 = 0; _i3 < username.length; _i3++) { | ||
credentials[_i3 + 1] = username.charCodeAt(_i3); | ||
} | ||
for (_i4 = 0; _i4 < password.length; _i4++) { | ||
credentials[username.length + 2 + _i4] = password.charCodeAt(_i4); | ||
} | ||
_context13.t2 = this._sock; | ||
_context13.next = 142; | ||
return clientCipher.makeMessage(credentials); | ||
case 142: | ||
_context13.t3 = _context13.sent; | ||
_context13.t2.send.call(_context13.t2, _context13.t3); | ||
case 144: | ||
@@ -1344,7 +1124,5 @@ case "end": | ||
})); | ||
function negotiateRA2neAuthAsync() { | ||
return _negotiateRA2neAuthAsync.apply(this, arguments); | ||
} | ||
return negotiateRA2neAuthAsync; | ||
@@ -1361,6 +1139,4 @@ }() | ||
}]); | ||
return RSAAESAuthenticationState; | ||
}(_eventtarget["default"]); | ||
exports["default"] = RSAAESAuthenticationState; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -16,9 +15,5 @@ value: true | ||
exports.supportsCursorURIs = void 0; | ||
var Log = _interopRequireWildcard(require("./logging.js")); | ||
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); } | ||
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; } | ||
/* | ||
@@ -33,5 +28,8 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
// Touch detection | ||
var isTouchDevice = 'ontouchstart' in document.documentElement || // requried for Chrome debugger | ||
document.ontouchstart !== undefined || // required for MS Surface | ||
var isTouchDevice = 'ontouchstart' in document.documentElement || | ||
// requried for Chrome debugger | ||
document.ontouchstart !== undefined || | ||
// required for MS Surface | ||
navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; | ||
@@ -42,13 +40,12 @@ exports.isTouchDevice = isTouchDevice; | ||
window.removeEventListener('touchstart', onFirstTouch, false); | ||
}, false); // The goal is to find a certain physical width, the devicePixelRatio | ||
}, false); | ||
// The goal is to find a certain physical width, the devicePixelRatio | ||
// brings us a bit closer but is not optimal. | ||
var dragThreshold = 10 * (window.devicePixelRatio || 1); | ||
exports.dragThreshold = dragThreshold; | ||
var _supportsCursorURIs = false; | ||
try { | ||
var target = document.createElement('canvas'); | ||
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default'; | ||
if (target.style.cursor.indexOf("url") === 0) { | ||
@@ -63,7 +60,5 @@ Log.Info("Data URI scheme cursor supported"); | ||
} | ||
var supportsCursorURIs = _supportsCursorURIs; | ||
exports.supportsCursorURIs = supportsCursorURIs; | ||
var _hasScrollbarGutter = true; | ||
try { | ||
@@ -74,11 +69,13 @@ // Create invisible container | ||
container.style.overflow = 'scroll'; // forcing scrollbars | ||
document.body.appendChild(container); | ||
document.body.appendChild(container); // Create a div and place it in the container | ||
// Create a div and place it in the container | ||
var child = document.createElement('div'); | ||
container.appendChild(child); | ||
var child = document.createElement('div'); | ||
container.appendChild(child); // Calculate the difference between the container's full width | ||
// Calculate the difference between the container's full width | ||
// and the child's width - the difference is the scrollbars | ||
var scrollbarWidth = container.offsetWidth - child.offsetWidth; | ||
var scrollbarWidth = container.offsetWidth - child.offsetWidth; // Clean up | ||
// Clean up | ||
container.parentNode.removeChild(container); | ||
@@ -89,4 +86,4 @@ _hasScrollbarGutter = scrollbarWidth != 0; | ||
} | ||
var hasScrollbarGutter = _hasScrollbarGutter; | ||
var hasScrollbarGutter = _hasScrollbarGutter; | ||
/* | ||
@@ -98,23 +95,17 @@ * The functions for detection of platforms and browsers below are exported | ||
*/ | ||
exports.hasScrollbarGutter = hasScrollbarGutter; | ||
function isMac() { | ||
return navigator && !!/mac/i.exec(navigator.platform); | ||
} | ||
function isWindows() { | ||
return navigator && !!/win/i.exec(navigator.platform); | ||
} | ||
function isIOS() { | ||
return navigator && (!!/ipad/i.exec(navigator.platform) || !!/iphone/i.exec(navigator.platform) || !!/ipod/i.exec(navigator.platform)); | ||
} | ||
function isSafari() { | ||
return navigator && navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1; | ||
} | ||
function isFirefox() { | ||
return navigator && !!/firefox/i.exec(navigator.userAgent); | ||
} |
@@ -7,28 +7,22 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _browser = require("./browser.js"); | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
var useFallback = !_browser.supportsCursorURIs || _browser.isTouchDevice; | ||
var Cursor = /*#__PURE__*/function () { | ||
function Cursor() { | ||
_classCallCheck(this, Cursor); | ||
this._target = null; | ||
this._canvas = document.createElement('canvas'); | ||
if (useFallback) { | ||
this._canvas.style.position = 'fixed'; | ||
this._canvas.style.zIndex = '65535'; | ||
this._canvas.style.pointerEvents = 'none'; // Can't use "display" because of Firefox bug #1445997 | ||
this._canvas.style.pointerEvents = 'none'; | ||
// Can't use "display" because of Firefox bug #1445997 | ||
this._canvas.style.visibility = 'hidden'; | ||
} | ||
this._position = { | ||
@@ -49,3 +43,2 @@ x: 0, | ||
} | ||
_createClass(Cursor, [{ | ||
@@ -57,5 +50,3 @@ key: "attach", | ||
} | ||
this._target = target; | ||
if (useFallback) { | ||
@@ -67,12 +58,7 @@ document.body.appendChild(this._canvas); | ||
}; | ||
this._target.addEventListener('mouseover', this._eventHandlers.mouseover, options); | ||
this._target.addEventListener('mouseleave', this._eventHandlers.mouseleave, options); | ||
this._target.addEventListener('mousemove', this._eventHandlers.mousemove, options); | ||
this._target.addEventListener('mouseup', this._eventHandlers.mouseup, options); | ||
} | ||
this.clear(); | ||
@@ -86,3 +72,2 @@ } | ||
} | ||
if (useFallback) { | ||
@@ -93,14 +78,8 @@ var options = { | ||
}; | ||
this._target.removeEventListener('mouseover', this._eventHandlers.mouseover, options); | ||
this._target.removeEventListener('mouseleave', this._eventHandlers.mouseleave, options); | ||
this._target.removeEventListener('mousemove', this._eventHandlers.mousemove, options); | ||
this._target.removeEventListener('mouseup', this._eventHandlers.mouseup, options); | ||
document.body.removeChild(this._canvas); | ||
} | ||
this._target = null; | ||
@@ -115,3 +94,2 @@ } | ||
} | ||
this._position.x = this._position.x + this._hotSpot.x - hotx; | ||
@@ -121,5 +99,3 @@ this._position.y = this._position.y + this._hotSpot.y - hoty; | ||
this._hotSpot.y = hoty; | ||
var ctx = this._canvas.getContext('2d'); | ||
this._canvas.width = w; | ||
@@ -130,3 +106,2 @@ this._canvas.height = h; | ||
ctx.putImageData(img, 0, 0); | ||
if (useFallback) { | ||
@@ -136,3 +111,2 @@ this._updatePosition(); | ||
var url = this._canvas.toDataURL(); | ||
this._target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default'; | ||
@@ -151,5 +125,6 @@ } | ||
this._hotSpot.y = 0; | ||
} // Mouse events might be emulated, this allows | ||
} | ||
// Mouse events might be emulated, this allows | ||
// moving the cursor in such cases | ||
}, { | ||
@@ -160,7 +135,6 @@ key: "move", | ||
return; | ||
} // clientX/clientY are relative the _visual viewport_, | ||
} | ||
// clientX/clientY are relative the _visual viewport_, | ||
// but our position is relative the _layout viewport_, | ||
// so try to compensate when we can | ||
if (window.visualViewport) { | ||
@@ -173,7 +147,4 @@ this._position.x = clientX + window.visualViewport.offsetLeft; | ||
} | ||
this._updatePosition(); | ||
var target = document.elementFromPoint(clientX, clientY); | ||
this._updateVisibility(target); | ||
@@ -199,6 +170,4 @@ } | ||
this._updateVisibility(event.target); | ||
this._position.x = event.clientX - this._hotSpot.x; | ||
this._position.y = event.clientY - this._hotSpot.y; | ||
this._updatePosition(); | ||
@@ -210,3 +179,2 @@ } | ||
var _this = this; | ||
// We might get this event because of a drag operation that | ||
@@ -216,4 +184,5 @@ // moved outside of the target. Check what's under the cursor | ||
var target = document.elementFromPoint(event.clientX, event.clientY); | ||
this._updateVisibility(target); | ||
this._updateVisibility(target); // Captures end with a mouseup but we can't know the event order of | ||
// Captures end with a mouseup but we can't know the event order of | ||
// mouseup vs releaseCapture. | ||
@@ -227,4 +196,2 @@ // | ||
// should be visible. | ||
if (this._captureIsActive()) { | ||
@@ -235,8 +202,6 @@ window.setTimeout(function () { | ||
return; | ||
} // Refresh the target from elementFromPoint since queued events | ||
} | ||
// Refresh the target from elementFromPoint since queued events | ||
// might have altered the DOM | ||
target = document.elementFromPoint(event.clientX, event.clientY); | ||
_this._updateVisibility(target); | ||
@@ -259,6 +224,7 @@ }, 0); | ||
} | ||
} // Should we currently display the cursor? | ||
} | ||
// Should we currently display the cursor? | ||
// (i.e. are we over the target, or a child of the target without a | ||
// different cursor set) | ||
}, { | ||
@@ -269,21 +235,17 @@ key: "_shouldShowCursor", | ||
return false; | ||
} // Easy case | ||
} | ||
// Easy case | ||
if (target === this._target) { | ||
return true; | ||
} // Other part of the DOM? | ||
} | ||
// Other part of the DOM? | ||
if (!this._target.contains(target)) { | ||
return false; | ||
} // Has the child its own cursor? | ||
} | ||
// Has the child its own cursor? | ||
// FIXME: How can we tell that a sub element has an | ||
// explicit "cursor: none;"? | ||
if (window.getComputedStyle(target).cursor !== 'none') { | ||
return false; | ||
} | ||
return true; | ||
@@ -299,3 +261,2 @@ } | ||
} | ||
if (this._shouldShowCursor(target)) { | ||
@@ -319,6 +280,4 @@ this._showCursor(); | ||
}]); | ||
return Cursor; | ||
}(); | ||
exports["default"] = Cursor; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.clientToElement = clientToElement; | ||
/* | ||
@@ -20,2 +19,3 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
function clientToElement(x, y, elem) { | ||
@@ -26,4 +26,4 @@ var bounds = elem.getBoundingClientRect(); | ||
y: 0 | ||
}; // Clip to target bounds | ||
}; | ||
// Clip to target bounds | ||
if (x < bounds.left) { | ||
@@ -36,3 +36,2 @@ pos.x = 0; | ||
} | ||
if (y < bounds.top) { | ||
@@ -45,4 +44,3 @@ pos.y = 0; | ||
} | ||
return pos; | ||
} |
@@ -10,3 +10,2 @@ "use strict"; | ||
exports.stopEvent = stopEvent; | ||
/* | ||
@@ -23,23 +22,22 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
function getPointerEvent(e) { | ||
return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e; | ||
} | ||
function stopEvent(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
} // Emulate Element.setCapture() when not supported | ||
} | ||
// Emulate Element.setCapture() when not supported | ||
var _captureRecursion = false; | ||
var _elementForUnflushedEvents = null; | ||
document.captureElement = null; | ||
function _captureProxy(e) { | ||
// Recursion protection as we'll see our own event | ||
if (_captureRecursion) return; // Clone the event as we cannot dispatch an already dispatched event | ||
if (_captureRecursion) return; | ||
// Clone the event as we cannot dispatch an already dispatched event | ||
var newEv = new e.constructor(e.type, e); | ||
_captureRecursion = true; | ||
if (document.captureElement) { | ||
@@ -50,18 +48,19 @@ document.captureElement.dispatchEvent(newEv); | ||
} | ||
_captureRecursion = false; | ||
_captureRecursion = false; // Avoid double events | ||
// Avoid double events | ||
e.stopPropagation(); | ||
e.stopPropagation(); // Respect the wishes of the redirected event handlers | ||
// Respect the wishes of the redirected event handlers | ||
if (newEv.defaultPrevented) { | ||
e.preventDefault(); | ||
} // Implicitly release the capture on button release | ||
} | ||
// Implicitly release the capture on button release | ||
if (e.type === "mouseup") { | ||
releaseCapture(); | ||
} | ||
} // Follow cursor style of target element | ||
} | ||
// Follow cursor style of target element | ||
function _capturedElemChanged() { | ||
@@ -71,5 +70,3 @@ var proxyElem = document.getElementById("noVNC_mouse_capture_elem"); | ||
} | ||
var _captureObserver = new MutationObserver(_capturedElemChanged); | ||
function setCapture(target) { | ||
@@ -84,3 +81,2 @@ if (target.setCapture) { | ||
var proxyElem = document.getElementById("noVNC_mouse_capture_elem"); | ||
if (proxyElem === null) { | ||
@@ -96,5 +92,6 @@ proxyElem = document.createElement("div"); | ||
proxyElem.style.display = "none"; | ||
document.body.appendChild(proxyElem); // This is to make sure callers don't get confused by having | ||
document.body.appendChild(proxyElem); | ||
// This is to make sure callers don't get confused by having | ||
// our blocking element as the target | ||
proxyElem.addEventListener('contextmenu', _captureProxy); | ||
@@ -104,14 +101,13 @@ proxyElem.addEventListener('mousemove', _captureProxy); | ||
} | ||
document.captureElement = target; | ||
document.captureElement = target; // Track cursor and get initial cursor | ||
// Track cursor and get initial cursor | ||
_captureObserver.observe(target, { | ||
attributes: true | ||
}); | ||
_capturedElemChanged(); | ||
proxyElem.style.display = ""; | ||
proxyElem.style.display = ""; // We listen to events on window in order to keep tracking if it | ||
// We listen to events on window in order to keep tracking if it | ||
// happens to leave the viewport | ||
window.addEventListener('mousemove', _captureProxy); | ||
@@ -121,3 +117,2 @@ window.addEventListener('mouseup', _captureProxy); | ||
} | ||
function releaseCapture() { | ||
@@ -130,3 +125,5 @@ if (document.releaseCapture) { | ||
return; | ||
} // There might be events already queued. The event proxy needs | ||
} | ||
// There might be events already queued. The event proxy needs | ||
// access to the captured element for these queued events. | ||
@@ -137,9 +134,5 @@ // E.g. contextmenu (right-click) in Microsoft Edge | ||
// temporary variable that the unflushed events can use. | ||
_elementForUnflushedEvents = document.captureElement; | ||
document.captureElement = null; | ||
_captureObserver.disconnect(); | ||
var proxyElem = document.getElementById("noVNC_mouse_capture_elem"); | ||
@@ -146,0 +139,0 @@ proxyElem.style.display = "none"; |
@@ -7,9 +7,8 @@ "use strict"; | ||
exports["default"] = void 0; | ||
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); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
/* | ||
@@ -25,6 +24,4 @@ * noVNC: HTML5 VNC client | ||
_classCallCheck(this, EventTargetMixin); | ||
this._listeners = new Map(); | ||
} | ||
_createClass(EventTargetMixin, [{ | ||
@@ -36,3 +33,2 @@ key: "addEventListener", | ||
} | ||
this._listeners.get(type).add(callback); | ||
@@ -51,18 +47,13 @@ } | ||
var _this = this; | ||
if (!this._listeners.has(event.type)) { | ||
return true; | ||
} | ||
this._listeners.get(event.type).forEach(function (callback) { | ||
return callback.call(_this, event); | ||
}); | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return EventTargetMixin; | ||
}(); | ||
exports["default"] = EventTargetMixin; |
@@ -8,3 +8,2 @@ "use strict"; | ||
exports.toUnsigned32bit = toUnsigned32bit; | ||
/* | ||
@@ -17,8 +16,8 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
function toUnsigned32bit(toConvert) { | ||
return toConvert >>> 0; | ||
} | ||
function toSigned32bit(toConvert) { | ||
return toConvert | 0; | ||
} |
@@ -9,3 +9,2 @@ "use strict"; | ||
exports.initLogging = initLogging; | ||
/* | ||
@@ -22,20 +21,12 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
var _logLevel = 'warn'; | ||
var Debug = function Debug() {}; | ||
exports.Debug = Debug; | ||
var Info = function Info() {}; | ||
exports.Info = Info; | ||
var Warn = function Warn() {}; | ||
exports.Warn = Warn; | ||
var Error = function Error() {}; | ||
exports.Error = Error; | ||
function initLogging(level) { | ||
@@ -47,5 +38,3 @@ if (typeof level === 'undefined') { | ||
} | ||
exports.Debug = Debug = exports.Info = Info = exports.Warn = Warn = exports.Error = Error = function Error() {}; | ||
if (typeof window.console !== "undefined") { | ||
@@ -56,15 +45,10 @@ /* eslint-disable no-console, no-fallthrough */ | ||
exports.Debug = Debug = console.debug.bind(window.console); | ||
case 'info': | ||
exports.Info = Info = console.info.bind(window.console); | ||
case 'warn': | ||
exports.Warn = Warn = console.warn.bind(window.console); | ||
case 'error': | ||
exports.Error = Error = console.error.bind(window.console); | ||
case 'none': | ||
break; | ||
default: | ||
@@ -74,3 +58,2 @@ throw new window.Error("invalid logging type '" + level + "'"); | ||
/* eslint-enable no-console, no-fallthrough */ | ||
} | ||
@@ -82,4 +65,3 @@ } | ||
} | ||
// Initialize logging level | ||
initLogging(); |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.MD5 = MD5; | ||
/* | ||
@@ -20,2 +19,3 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
function MD5(d) { | ||
@@ -25,75 +25,56 @@ var r = M(V(Y(X(d), 8 * d.length))); | ||
} | ||
function M(d) { | ||
var f = new Uint8Array(d.length); | ||
for (var i = 0; i < d.length; i++) { | ||
f[i] = d.charCodeAt(i); | ||
} | ||
return f; | ||
} | ||
function X(d) { | ||
var r = Array(d.length >> 2); | ||
for (var m = 0; m < r.length; m++) { | ||
r[m] = 0; | ||
} | ||
for (var _m = 0; _m < 8 * d.length; _m += 8) { | ||
r[_m >> 5] |= (255 & d.charCodeAt(_m / 8)) << _m % 32; | ||
} | ||
return r; | ||
} | ||
function V(d) { | ||
var r = ""; | ||
for (var m = 0; m < 32 * d.length; m += 8) { | ||
r += String.fromCharCode(d[m >> 5] >>> m % 32 & 255); | ||
} | ||
return r; | ||
} | ||
function Y(d, g) { | ||
d[g >> 5] |= 128 << g % 32, d[14 + (g + 64 >>> 9 << 4)] = g; | ||
var m = 1732584193, | ||
f = -271733879, | ||
r = -1732584194, | ||
i = 271733878; | ||
f = -271733879, | ||
r = -1732584194, | ||
i = 271733878; | ||
for (var n = 0; n < d.length; n += 16) { | ||
var h = m, | ||
t = f, | ||
_g = r, | ||
e = i; | ||
t = f, | ||
_g = r, | ||
e = i; | ||
f = ii(f = ii(f = ii(f = ii(f = hh(f = hh(f = hh(f = hh(f = gg(f = gg(f = gg(f = gg(f = ff(f = ff(f = ff(f = ff(f, r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 0], 7, -680876936), f, r, d[n + 1], 12, -389564586), m, f, d[n + 2], 17, 606105819), i, m, d[n + 3], 22, -1044525330), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 4], 7, -176418897), f, r, d[n + 5], 12, 1200080426), m, f, d[n + 6], 17, -1473231341), i, m, d[n + 7], 22, -45705983), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 8], 7, 1770035416), f, r, d[n + 9], 12, -1958414417), m, f, d[n + 10], 17, -42063), i, m, d[n + 11], 22, -1990404162), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 12], 7, 1804603682), f, r, d[n + 13], 12, -40341101), m, f, d[n + 14], 17, -1502002290), i, m, d[n + 15], 22, 1236535329), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 1], 5, -165796510), f, r, d[n + 6], 9, -1069501632), m, f, d[n + 11], 14, 643717713), i, m, d[n + 0], 20, -373897302), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 5], 5, -701558691), f, r, d[n + 10], 9, 38016083), m, f, d[n + 15], 14, -660478335), i, m, d[n + 4], 20, -405537848), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 9], 5, 568446438), f, r, d[n + 14], 9, -1019803690), m, f, d[n + 3], 14, -187363961), i, m, d[n + 8], 20, 1163531501), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 13], 5, -1444681467), f, r, d[n + 2], 9, -51403784), m, f, d[n + 7], 14, 1735328473), i, m, d[n + 12], 20, -1926607734), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 5], 4, -378558), f, r, d[n + 8], 11, -2022574463), m, f, d[n + 11], 16, 1839030562), i, m, d[n + 14], 23, -35309556), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 1], 4, -1530992060), f, r, d[n + 4], 11, 1272893353), m, f, d[n + 7], 16, -155497632), i, m, d[n + 10], 23, -1094730640), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 13], 4, 681279174), f, r, d[n + 0], 11, -358537222), m, f, d[n + 3], 16, -722521979), i, m, d[n + 6], 23, 76029189), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 9], 4, -640364487), f, r, d[n + 12], 11, -421815835), m, f, d[n + 15], 16, 530742520), i, m, d[n + 2], 23, -995338651), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 0], 6, -198630844), f, r, d[n + 7], 10, 1126891415), m, f, d[n + 14], 15, -1416354905), i, m, d[n + 5], 21, -57434055), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 12], 6, 1700485571), f, r, d[n + 3], 10, -1894986606), m, f, d[n + 10], 15, -1051523), i, m, d[n + 1], 21, -2054922799), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 8], 6, 1873313359), f, r, d[n + 15], 10, -30611744), m, f, d[n + 6], 15, -1560198380), i, m, d[n + 13], 21, 1309151649), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 4], 6, -145523070), f, r, d[n + 11], 10, -1120210379), m, f, d[n + 2], 15, 718787259), i, m, d[n + 9], 21, -343485551), m = add(m, h), f = add(f, t), r = add(r, _g), i = add(i, e); | ||
} | ||
return Array(m, f, r, i); | ||
} | ||
function cmn(d, g, m, f, r, i) { | ||
return add(rol(add(add(g, d), add(f, i)), r), m); | ||
} | ||
function ff(d, g, m, f, r, i, n) { | ||
return cmn(g & m | ~g & f, d, g, r, i, n); | ||
} | ||
function gg(d, g, m, f, r, i, n) { | ||
return cmn(g & f | m & ~f, d, g, r, i, n); | ||
} | ||
function hh(d, g, m, f, r, i, n) { | ||
return cmn(g ^ m ^ f, d, g, r, i, n); | ||
} | ||
function ii(d, g, m, f, r, i, n) { | ||
return cmn(m ^ (g | ~f), d, g, r, i, n); | ||
} | ||
function add(d, g) { | ||
@@ -103,5 +84,4 @@ var m = (65535 & d) + (65535 & g); | ||
} | ||
function rol(d, g) { | ||
return d << g | d >>> 32 - g; | ||
} |
@@ -8,3 +8,2 @@ "use strict"; | ||
exports.encodeUTF8 = encodeUTF8; | ||
/* | ||
@@ -17,6 +16,6 @@ * noVNC: HTML5 VNC client | ||
*/ | ||
// Decode from UTF-8 | ||
function decodeUTF8(utf8string) { | ||
var allowLatin1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
try { | ||
@@ -32,10 +31,9 @@ return decodeURIComponent(escape(utf8string)); | ||
} | ||
throw e; | ||
} | ||
} // Encode to UTF-8 | ||
} | ||
// Encode to UTF-8 | ||
function encodeUTF8(DOMString) { | ||
return unescape(encodeURIComponent(DOMString)); | ||
} |
@@ -10,3 +10,2 @@ "use strict"; | ||
exports.shrinkBuf = shrinkBuf; | ||
// reduce buffer size, avoiding mem copy | ||
@@ -17,13 +16,9 @@ function shrinkBuf(buf, size) { | ||
} | ||
if (buf.subarray) { | ||
return buf.subarray(0, size); | ||
} | ||
buf.length = size; | ||
return buf; | ||
} | ||
; | ||
function arraySet(dest, src, src_offs, len, dest_offs) { | ||
@@ -33,24 +28,22 @@ if (src.subarray && dest.subarray) { | ||
return; | ||
} // Fallback to ordinary array | ||
} | ||
// Fallback to ordinary array | ||
for (var i = 0; i < len; i++) { | ||
dest[dest_offs + i] = src[src_offs + i]; | ||
} | ||
} // Join array of chunks to single array. | ||
} | ||
// Join array of chunks to single array. | ||
function flattenChunks(chunks) { | ||
var i, l, len, pos, chunk, result; // calculate data length | ||
var i, l, len, pos, chunk, result; | ||
// calculate data length | ||
len = 0; | ||
for (i = 0, l = chunks.length; i < l; i++) { | ||
len += chunks[i].length; | ||
} // join chunks | ||
} | ||
// join chunks | ||
result = new Uint8Array(len); | ||
pos = 0; | ||
for (i = 0, l = chunks.length; i < l; i++) { | ||
@@ -61,6 +54,4 @@ chunk = chunks[i]; | ||
} | ||
return result; | ||
} | ||
var Buf8 = Uint8Array; | ||
@@ -67,0 +58,0 @@ exports.Buf8 = Buf8; |
@@ -7,11 +7,10 @@ "use strict"; | ||
exports["default"] = adler32; | ||
// Note: adler32 takes 12% for level 0 and 2% for level 6. | ||
// It doesn't worth to make additional optimizationa as in original. | ||
// Small size is preferable. | ||
function adler32(adler, buf, len, pos) { | ||
var s1 = adler & 0xffff | 0, | ||
s2 = adler >>> 16 & 0xffff | 0, | ||
n = 0; | ||
s2 = adler >>> 16 & 0xffff | 0, | ||
n = 0; | ||
while (len !== 0) { | ||
@@ -23,3 +22,2 @@ // Set limit ~ twice less than 5552, to keep | ||
len -= n; | ||
do { | ||
@@ -29,8 +27,6 @@ s1 = s1 + buf[pos++] | 0; | ||
} while (--n); | ||
s1 %= 65521; | ||
s2 %= 65521; | ||
} | ||
return s1 | s2 << 16 | 0; | ||
} |
@@ -16,3 +16,2 @@ "use strict"; | ||
Z_TREES: 6, | ||
/* Return codes for the compression/decompression functions. Negative values | ||
@@ -41,3 +40,2 @@ * are errors, positive values are used for special but normal events. | ||
Z_DEFAULT_STRATEGY: 0, | ||
/* Possible values of the data_type field (though see inflate()) */ | ||
@@ -48,7 +46,6 @@ Z_BINARY: 0, | ||
Z_UNKNOWN: 2, | ||
/* The deflate compression method */ | ||
Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null inline, depending on var type | ||
Z_DEFLATED: 8 | ||
//Z_NULL: null // Use -1 or null inline, depending on var type | ||
}; | ||
exports["default"] = _default; |
@@ -7,37 +7,30 @@ "use strict"; | ||
exports["default"] = makeTable; | ||
// Note: we can't get significant speed boost here. | ||
// So write code to minimize size - no pregenerated tables | ||
// and array tools dependencies. | ||
// Use ordinary array, since untyped makes no boost here | ||
function makeTable() { | ||
var c, | ||
table = []; | ||
table = []; | ||
for (var n = 0; n < 256; n++) { | ||
c = n; | ||
for (var k = 0; k < 8; k++) { | ||
c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1; | ||
} | ||
table[n] = c; | ||
} | ||
return table; | ||
} // Create table on load. Just 255 signed longs. Not a problem. | ||
} | ||
// Create table on load. Just 255 signed longs. Not a problem. | ||
var crcTable = makeTable(); | ||
function crc32(crc, buf, len, pos) { | ||
var t = crcTable, | ||
end = pos + len; | ||
end = pos + len; | ||
crc ^= -1; | ||
for (var i = pos; i < end; i++) { | ||
crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF]; | ||
} | ||
return crc ^ -1; // >>> 0; | ||
} |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -18,21 +17,11 @@ value: true | ||
exports.deflateSetHeader = deflateSetHeader; | ||
var utils = _interopRequireWildcard(require("../utils/common.js")); | ||
var trees = _interopRequireWildcard(require("./trees.js")); | ||
var _adler = _interopRequireDefault(require("./adler32.js")); | ||
var _crc = _interopRequireDefault(require("./crc32.js")); | ||
var _messages = _interopRequireDefault(require("./messages.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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; } | ||
/* Public constants ==========================================================*/ | ||
/* ===========================================================================*/ | ||
@@ -43,4 +32,4 @@ | ||
exports.Z_NO_FLUSH = Z_NO_FLUSH; | ||
var Z_PARTIAL_FLUSH = 1; //export const Z_SYNC_FLUSH = 2; | ||
var Z_PARTIAL_FLUSH = 1; | ||
//export const Z_SYNC_FLUSH = 2; | ||
exports.Z_PARTIAL_FLUSH = Z_PARTIAL_FLUSH; | ||
@@ -51,3 +40,4 @@ var Z_FULL_FLUSH = 3; | ||
exports.Z_FINISH = Z_FINISH; | ||
var Z_BLOCK = 5; //export const Z_TREES = 6; | ||
var Z_BLOCK = 5; | ||
//export const Z_TREES = 6; | ||
@@ -57,16 +47,16 @@ /* Return codes for the compression/decompression functions. Negative values | ||
*/ | ||
exports.Z_BLOCK = Z_BLOCK; | ||
var Z_OK = 0; | ||
exports.Z_OK = Z_OK; | ||
var Z_STREAM_END = 1; //export const Z_NEED_DICT = 2; | ||
var Z_STREAM_END = 1; | ||
//export const Z_NEED_DICT = 2; | ||
//export const Z_ERRNO = -1; | ||
exports.Z_STREAM_END = Z_STREAM_END; | ||
var Z_STREAM_ERROR = -2; | ||
exports.Z_STREAM_ERROR = Z_STREAM_ERROR; | ||
var Z_DATA_ERROR = -3; //export const Z_MEM_ERROR = -4; | ||
var Z_DATA_ERROR = -3; | ||
//export const Z_MEM_ERROR = -4; | ||
exports.Z_DATA_ERROR = Z_DATA_ERROR; | ||
var Z_BUF_ERROR = -5; //export const Z_VERSION_ERROR = -6; | ||
var Z_BUF_ERROR = -5; | ||
//export const Z_VERSION_ERROR = -6; | ||
@@ -77,3 +67,2 @@ /* compression levels */ | ||
//export const Z_BEST_COMPRESSION = 9; | ||
exports.Z_BUF_ERROR = Z_BUF_ERROR; | ||
@@ -91,2 +80,3 @@ var Z_DEFAULT_COMPRESSION = -1; | ||
var Z_DEFAULT_STRATEGY = 0; | ||
/* Possible values of the data_type field (though see inflate()) */ | ||
@@ -96,37 +86,28 @@ //export const Z_BINARY = 0; | ||
//export const Z_ASCII = 1; // = Z_TEXT | ||
exports.Z_DEFAULT_STRATEGY = Z_DEFAULT_STRATEGY; | ||
var Z_UNKNOWN = 2; | ||
/* The deflate compression method */ | ||
exports.Z_UNKNOWN = Z_UNKNOWN; | ||
var Z_DEFLATED = 8; | ||
/*============================================================================*/ | ||
exports.Z_DEFLATED = Z_DEFLATED; | ||
var MAX_MEM_LEVEL = 9; | ||
/* Maximum value for memLevel in deflateInit2 */ | ||
var MAX_WBITS = 15; | ||
/* 32K LZ77 window */ | ||
var DEF_MEM_LEVEL = 8; | ||
var LENGTH_CODES = 29; | ||
/* number of length codes, not counting the special END_BLOCK code */ | ||
var LITERALS = 256; | ||
/* number of literal bytes 0..255 */ | ||
var L_CODES = LITERALS + 1 + LENGTH_CODES; | ||
/* number of Literal or Length codes, including the END_BLOCK code */ | ||
var D_CODES = 30; | ||
/* number of distance codes */ | ||
var BL_CODES = 19; | ||
/* number of codes used to transfer the bit lengths */ | ||
var HEAP_SIZE = 2 * L_CODES + 1; | ||
/* maximum heap size */ | ||
var MAX_BITS = 15; | ||
@@ -146,14 +127,7 @@ /* All codes must not exceed MAX_BITS bits */ | ||
var FINISH_STATE = 666; | ||
var BS_NEED_MORE = 1; | ||
/* block not completed, need more input or more output */ | ||
var BS_NEED_MORE = 1; /* block not completed, need more input or more output */ | ||
var BS_BLOCK_DONE = 2; /* block flush performed */ | ||
var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */ | ||
var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ | ||
var BS_BLOCK_DONE = 2; | ||
/* block flush performed */ | ||
var BS_FINISH_STARTED = 3; | ||
/* finish started, need only more output at next deflate */ | ||
var BS_FINISH_DONE = 4; | ||
/* finish done, accept no more input or output */ | ||
var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. | ||
@@ -165,10 +139,7 @@ | ||
} | ||
function rank(f) { | ||
return (f << 1) - (f > 4 ? 9 : 0); | ||
} | ||
function zero(buf) { | ||
var len = buf.length; | ||
while (--len >= 0) { | ||
@@ -178,2 +149,3 @@ buf[len] = 0; | ||
} | ||
/* ========================================================================= | ||
@@ -185,17 +157,13 @@ * Flush as much pending output as possible. All deflate() output goes | ||
*/ | ||
function flush_pending(strm) { | ||
var s = strm.state; //_tr_flush_bits(s); | ||
var s = strm.state; | ||
//_tr_flush_bits(s); | ||
var len = s.pending; | ||
if (len > strm.avail_out) { | ||
len = strm.avail_out; | ||
} | ||
if (len === 0) { | ||
return; | ||
} | ||
utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out); | ||
@@ -207,3 +175,2 @@ strm.next_out += len; | ||
s.pending -= len; | ||
if (s.pending === 0) { | ||
@@ -213,13 +180,11 @@ s.pending_out = 0; | ||
} | ||
function flush_block_only(s, last) { | ||
trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last); | ||
s.block_start = s.strstart; | ||
flush_pending(s.strm); | ||
} | ||
function put_byte(s, b) { | ||
s.pending_buf[s.pending++] = b; | ||
} | ||
/* ========================================================================= | ||
@@ -230,4 +195,2 @@ * Put a short in the pending buffer. The 16-bit value is put in MSB order. | ||
*/ | ||
function putShortMSB(s, b) { | ||
@@ -239,2 +202,3 @@ // put_byte(s, (Byte)(b >> 8)); | ||
} | ||
/* =========================================================================== | ||
@@ -247,19 +211,14 @@ * Read a new buffer from the current input stream, update the adler32 | ||
*/ | ||
function read_buf(strm, buf, start, size) { | ||
var len = strm.avail_in; | ||
if (len > size) { | ||
len = size; | ||
} | ||
if (len === 0) { | ||
return 0; | ||
} | ||
strm.avail_in -= len; | ||
strm.avail_in -= len; // zmemcpy(buf, strm->next_in, len); | ||
// zmemcpy(buf, strm->next_in, len); | ||
utils.arraySet(buf, strm.input, strm.next_in, len, start); | ||
if (strm.state.wrap === 1) { | ||
@@ -270,3 +229,2 @@ strm.adler = (0, _adler["default"])(strm.adler, buf, len, start); | ||
} | ||
strm.next_in += len; | ||
@@ -276,2 +234,3 @@ strm.total_in += len; | ||
} | ||
/* =========================================================================== | ||
@@ -286,26 +245,11 @@ * Set match_start to the longest match starting at the given string and | ||
*/ | ||
function longest_match(s, cur_match) { | ||
var chain_length = s.max_chain_length; | ||
/* max hash chain length */ | ||
var chain_length = s.max_chain_length; /* max hash chain length */ | ||
var scan = s.strstart; /* current string */ | ||
var match; /* matched string */ | ||
var len; /* length of current match */ | ||
var best_len = s.prev_length; /* best match length so far */ | ||
var nice_match = s.nice_match; /* stop if match long enough */ | ||
var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0 /*NIL*/; | ||
var scan = s.strstart; | ||
/* current string */ | ||
var match; | ||
/* matched string */ | ||
var len; | ||
/* length of current match */ | ||
var best_len = s.prev_length; | ||
/* best match length so far */ | ||
var nice_match = s.nice_match; | ||
/* stop if match long enough */ | ||
var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0 | ||
/*NIL*/ | ||
; | ||
var _win = s.window; // shortcut | ||
@@ -315,2 +259,3 @@ | ||
var prev = s.prev; | ||
/* Stop when cur_match becomes <= limit. To simplify the code, | ||
@@ -323,2 +268,3 @@ * we prevent matches with the string of window index 0. | ||
var scan_end = _win[scan + best_len]; | ||
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. | ||
@@ -330,3 +276,2 @@ * It is easy to get rid of this optimization if necessary. | ||
/* Do not waste too much time if we already have a good match: */ | ||
if (s.prev_length >= s.good_match) { | ||
@@ -338,8 +283,7 @@ chain_length >>= 2; | ||
*/ | ||
if (nice_match > s.lookahead) { | ||
nice_match = s.lookahead; | ||
} // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | ||
} | ||
// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); | ||
@@ -349,2 +293,3 @@ do { | ||
match = cur_match; | ||
/* Skip to next match if the match length cannot increase | ||
@@ -362,2 +307,3 @@ * or if the match length is less than 2. Note that the checks below | ||
} | ||
/* The check at best_len-1 can be removed because it will be made | ||
@@ -369,6 +315,5 @@ * again later. (This heuristic is not always a win.) | ||
*/ | ||
scan += 2; | ||
match++; // Assert(*scan == *match, "match[2]?"); | ||
match++; | ||
// Assert(*scan == *match, "match[2]?"); | ||
@@ -378,18 +323,16 @@ /* We check for insufficient lookahead only every 8th comparison; | ||
*/ | ||
do { | ||
// Do nothing | ||
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend); | ||
do {// Do nothing | ||
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend); // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | ||
// Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); | ||
len = MAX_MATCH - (strend - scan); | ||
scan = strend - MAX_MATCH; | ||
if (len > best_len) { | ||
s.match_start = cur_match; | ||
best_len = len; | ||
if (len >= nice_match) { | ||
break; | ||
} | ||
scan_end1 = _win[scan + best_len - 1]; | ||
@@ -399,9 +342,8 @@ scan_end = _win[scan + best_len]; | ||
} while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0); | ||
if (best_len <= s.lookahead) { | ||
return best_len; | ||
} | ||
return s.lookahead; | ||
} | ||
/* =========================================================================== | ||
@@ -417,11 +359,12 @@ * Fill the window when the lookahead becomes insufficient. | ||
*/ | ||
function fill_window(s) { | ||
var _w_size = s.w_size; | ||
var p, n, m, more, str; //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); | ||
var p, n, m, more, str; | ||
//Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); | ||
do { | ||
more = s.window_size - s.lookahead - s.strstart; // JS ints have 32 bit, block below not needed | ||
more = s.window_size - s.lookahead - s.strstart; | ||
// JS ints have 32 bit, block below not needed | ||
/* Deal with !@#$% 64K limit: */ | ||
@@ -443,3 +386,2 @@ //if (sizeof(int) <= 2) { | ||
*/ | ||
if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) { | ||
@@ -450,4 +392,4 @@ utils.arraySet(s.window, s.window, _w_size, _w_size, 0); | ||
/* we now have strstart >= MAX_DIST */ | ||
s.block_start -= _w_size; | ||
s.block_start -= _w_size; | ||
/* Slide the hash table (could be avoided with 32 bit values | ||
@@ -462,3 +404,2 @@ at the expense of memory usage). We slide even when level == 0 | ||
p = n; | ||
do { | ||
@@ -468,6 +409,4 @@ m = s.head[--p]; | ||
} while (--n); | ||
n = _w_size; | ||
p = n; | ||
do { | ||
@@ -480,9 +419,8 @@ m = s.prev[--p]; | ||
} while (--n); | ||
more += _w_size; | ||
} | ||
if (s.strm.avail_in === 0) { | ||
break; | ||
} | ||
/* If there was no sliding: | ||
@@ -500,17 +438,15 @@ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && | ||
//Assert(more >= 2, "more < 2"); | ||
n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more); | ||
s.lookahead += n; | ||
/* Initialize the hash value now that we have some input: */ | ||
if (s.lookahead + s.insert >= MIN_MATCH) { | ||
str = s.strstart - s.insert; | ||
s.ins_h = s.window[str]; | ||
/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */ | ||
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; //#if MIN_MATCH != 3 | ||
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; | ||
//#if MIN_MATCH != 3 | ||
// Call update_hash() MIN_MATCH-3 more times | ||
//#endif | ||
while (s.insert) { | ||
@@ -523,3 +459,2 @@ /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ | ||
s.insert--; | ||
if (s.lookahead + s.insert < MIN_MATCH) { | ||
@@ -533,4 +468,4 @@ break; | ||
*/ | ||
} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0); | ||
} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0); | ||
/* If the WIN_INIT bytes after the end of the current data have never been | ||
@@ -572,4 +507,4 @@ * written, then zero those bytes in order to avoid memory check reports of | ||
// "not enough room for search"); | ||
} | ||
} | ||
/* =========================================================================== | ||
@@ -584,4 +519,2 @@ * Copy without compression as much as possible from the input stream, return | ||
*/ | ||
function deflate_stored(s, flush) { | ||
@@ -592,9 +525,7 @@ /* Stored blocks are limited to 0xffff bytes, pending_buf is limited | ||
var max_block_size = 0xffff; | ||
if (max_block_size > s.pending_buf_size - 5) { | ||
max_block_size = s.pending_buf_size - 5; | ||
} | ||
/* Copy as much as possible from input to output: */ | ||
for (;;) { | ||
@@ -609,8 +540,7 @@ /* Fill the window as much as possible: */ | ||
// } | ||
fill_window(s); | ||
if (s.lookahead === 0 && flush === Z_NO_FLUSH) { | ||
return BS_NEED_MORE; | ||
} | ||
if (s.lookahead === 0) { | ||
@@ -620,13 +550,11 @@ break; | ||
/* flush the current block */ | ||
} //Assert(s->block_start >= 0L, "block gone"); | ||
} | ||
//Assert(s->block_start >= 0L, "block gone"); | ||
// if (s.block_start < 0) throw new Error("block gone"); | ||
s.strstart += s.lookahead; | ||
s.lookahead = 0; | ||
/* Emit a stored block if pending_buf will be full: */ | ||
var max_start = s.block_start + max_block_size; | ||
if (s.strstart === 0 || s.strstart >= max_start) { | ||
@@ -637,5 +565,3 @@ /* strstart == 0 is possible when wraparound on 16-bit machine */ | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -645,3 +571,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -651,8 +576,5 @@ /* Flush if we may have to slide, otherwise block_start may become | ||
*/ | ||
if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -662,3 +584,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -668,7 +589,5 @@ } | ||
s.insert = 0; | ||
if (flush === Z_FINISH) { | ||
/*** FLUSH_BLOCK(s, 1); ***/ | ||
flush_block_only(s, true); | ||
if (s.strm.avail_out === 0) { | ||
@@ -678,11 +597,7 @@ return BS_FINISH_STARTED; | ||
/***/ | ||
return BS_FINISH_DONE; | ||
} | ||
if (s.strstart > s.block_start) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -692,3 +607,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -698,2 +612,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -706,11 +621,6 @@ * Compress as much as possible from the input stream, return the current | ||
*/ | ||
function deflate_fast(s, flush) { | ||
var hash_head; | ||
/* head of the hash chain */ | ||
var hash_head; /* head of the hash chain */ | ||
var bflush; /* set if current block must be flushed */ | ||
var bflush; | ||
/* set if current block must be flushed */ | ||
for (;;) { | ||
@@ -724,21 +634,14 @@ /* Make sure that we always have enough lookahead, except | ||
fill_window(s); | ||
if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { | ||
return BS_NEED_MORE; | ||
} | ||
if (s.lookahead === 0) { | ||
break; | ||
/* flush the current block */ | ||
break; /* flush the current block */ | ||
} | ||
} | ||
/* Insert the string window[strstart .. strstart+2] in the | ||
* dictionary, and set hash_head to the head of the hash chain: | ||
*/ | ||
hash_head = 0 | ||
/*NIL*/ | ||
; | ||
hash_head = 0 /*NIL*/; | ||
if (s.lookahead >= MIN_MATCH) { | ||
@@ -751,10 +654,7 @@ /*** INSERT_STRING(s, s.strstart, hash_head); ***/ | ||
} | ||
/* Find the longest match, discarding those <= prev_length. | ||
* At this point we have always match_length < MIN_MATCH | ||
*/ | ||
if (hash_head !== 0 | ||
/*NIL*/ | ||
&& s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) { | ||
if (hash_head !== 0 /*NIL*/ && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) { | ||
/* To simplify the code, we prevent matches with the string | ||
@@ -775,16 +675,11 @@ * of window index 0 (in particular we have to avoid a match | ||
s.lookahead -= s.match_length; | ||
/* Insert new strings in the hash table only if the match length | ||
* is not too large. This saves time but degrades compression. | ||
*/ | ||
if (s.match_length <= s.max_lazy_match | ||
/*max_insert_length*/ | ||
&& s.lookahead >= MIN_MATCH) { | ||
s.match_length--; | ||
/* string at strstart already in table */ | ||
if (s.match_length <= s.max_lazy_match /*max_insert_length*/ && s.lookahead >= MIN_MATCH) { | ||
s.match_length--; /* string at strstart already in table */ | ||
do { | ||
s.strstart++; | ||
/*** INSERT_STRING(s, s.strstart, hash_head); ***/ | ||
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; | ||
@@ -794,3 +689,2 @@ hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; | ||
/***/ | ||
/* strstart never exceeds WSIZE-MAX_MATCH, so there are | ||
@@ -800,3 +694,2 @@ * always MIN_MATCH bytes ahead. | ||
} while (--s.match_length !== 0); | ||
s.strstart++; | ||
@@ -808,7 +701,7 @@ } else { | ||
/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */ | ||
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; | ||
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; //#if MIN_MATCH != 3 | ||
//#if MIN_MATCH != 3 | ||
// Call UPDATE_HASH() MIN_MATCH-3 more times | ||
//#endif | ||
/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not | ||
@@ -821,3 +714,2 @@ * matter since it will be recomputed at next deflate call. | ||
//Tracevv((stderr,"%c", s.window[s.strstart])); | ||
/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ | ||
@@ -828,7 +720,5 @@ bflush = trees._tr_tally(s, 0, s.window[s.strstart]); | ||
} | ||
if (bflush) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -838,3 +728,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -844,7 +733,5 @@ } | ||
s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1; | ||
if (flush === Z_FINISH) { | ||
/*** FLUSH_BLOCK(s, 1); ***/ | ||
flush_block_only(s, true); | ||
if (s.strm.avail_out === 0) { | ||
@@ -854,11 +741,7 @@ return BS_FINISH_STARTED; | ||
/***/ | ||
return BS_FINISH_DONE; | ||
} | ||
if (s.last_lit) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -868,3 +751,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -874,2 +756,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -880,14 +763,9 @@ * Same as above, but achieves better compression. We use a lazy | ||
*/ | ||
function deflate_slow(s, flush) { | ||
var hash_head; | ||
/* head of hash chain */ | ||
var hash_head; /* head of hash chain */ | ||
var bflush; /* set if current block must be flushed */ | ||
var bflush; | ||
/* set if current block must be flushed */ | ||
var max_insert; | ||
var max_insert; | ||
/* Process the input block. */ | ||
for (;;) { | ||
@@ -901,22 +779,14 @@ /* Make sure that we always have enough lookahead, except | ||
fill_window(s); | ||
if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { | ||
return BS_NEED_MORE; | ||
} | ||
if (s.lookahead === 0) { | ||
break; | ||
} | ||
/* flush the current block */ | ||
} /* flush the current block */ | ||
} | ||
} | ||
/* Insert the string window[strstart .. strstart+2] in the | ||
* dictionary, and set hash_head to the head of the hash chain: | ||
*/ | ||
hash_head = 0 | ||
/*NIL*/ | ||
; | ||
hash_head = 0 /*NIL*/; | ||
if (s.lookahead >= MIN_MATCH) { | ||
@@ -929,15 +799,9 @@ /*** INSERT_STRING(s, s.strstart, hash_head); ***/ | ||
} | ||
/* Find the longest match, discarding those <= prev_length. | ||
*/ | ||
s.prev_length = s.match_length; | ||
s.prev_match = s.match_start; | ||
s.match_length = MIN_MATCH - 1; | ||
if (hash_head !== 0 | ||
/*NIL*/ | ||
&& s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD | ||
/*MAX_DIST(s)*/ | ||
) { | ||
if (hash_head !== 0 /*NIL*/ && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD /*MAX_DIST(s)*/) { | ||
/* To simplify the code, we prevent matches with the string | ||
@@ -950,5 +814,3 @@ * of window index 0 (in particular we have to avoid a match | ||
if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096 | ||
/*TOO_FAR*/ | ||
)) { | ||
if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096 /*TOO_FAR*/)) { | ||
/* If prev_match is also MIN_MATCH, match_start is garbage | ||
@@ -963,7 +825,6 @@ * but we will ignore the current match anyway. | ||
*/ | ||
if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) { | ||
max_insert = s.strstart + s.lookahead - MIN_MATCH; | ||
/* Do not insert strings in hash table beyond this. */ | ||
//check_match(s, s.strstart-1, s.prev_match, s.prev_length); | ||
@@ -973,3 +834,2 @@ | ||
s.prev_length - MIN_MATCH, bflush);***/ | ||
bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH); | ||
@@ -981,6 +841,4 @@ /* Insert in hash table all strings up to the end of the match. | ||
*/ | ||
s.lookahead -= s.prev_length - 1; | ||
s.prev_length -= 2; | ||
do { | ||
@@ -995,11 +853,8 @@ if (++s.strstart <= max_insert) { | ||
} while (--s.prev_length !== 0); | ||
s.match_available = 0; | ||
s.match_length = MIN_MATCH - 1; | ||
s.strstart++; | ||
if (bflush) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1009,3 +864,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1018,6 +872,4 @@ } else if (s.match_available) { | ||
//Tracevv((stderr,"%c", s->window[s->strstart-1])); | ||
/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ | ||
bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); | ||
if (bflush) { | ||
@@ -1031,3 +883,2 @@ /*** FLUSH_BLOCK_ONLY(s, 0) ***/ | ||
s.lookahead--; | ||
if (s.strm.avail_out === 0) { | ||
@@ -1044,8 +895,6 @@ return BS_NEED_MORE; | ||
} | ||
} //Assert (flush != Z_NO_FLUSH, "no flush?"); | ||
} | ||
//Assert (flush != Z_NO_FLUSH, "no flush?"); | ||
if (s.match_available) { | ||
//Tracevv((stderr,"%c", s->window[s->strstart-1])); | ||
/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ | ||
@@ -1055,9 +904,6 @@ bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); | ||
} | ||
s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1; | ||
if (flush === Z_FINISH) { | ||
/*** FLUSH_BLOCK(s, 1); ***/ | ||
flush_block_only(s, true); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1067,11 +913,7 @@ return BS_FINISH_STARTED; | ||
/***/ | ||
return BS_FINISH_DONE; | ||
} | ||
if (s.last_lit) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1081,3 +923,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1087,2 +928,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -1093,16 +935,8 @@ * For Z_RLE, simply look for runs of bytes, generate matches only of distance | ||
*/ | ||
function deflate_rle(s, flush) { | ||
var bflush; | ||
/* set if current block must be flushed */ | ||
var bflush; /* set if current block must be flushed */ | ||
var prev; /* byte at distance one to match */ | ||
var scan, strend; /* scan goes up to strend for length of run */ | ||
var prev; | ||
/* byte at distance one to match */ | ||
var scan, strend; | ||
/* scan goes up to strend for length of run */ | ||
var _win = s.window; | ||
for (;;) { | ||
@@ -1115,39 +949,29 @@ /* Make sure that we always have enough lookahead, except | ||
fill_window(s); | ||
if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) { | ||
return BS_NEED_MORE; | ||
} | ||
if (s.lookahead === 0) { | ||
break; | ||
} | ||
/* flush the current block */ | ||
} /* flush the current block */ | ||
} | ||
} | ||
/* See how many times the previous byte repeats */ | ||
s.match_length = 0; | ||
if (s.lookahead >= MIN_MATCH && s.strstart > 0) { | ||
scan = s.strstart - 1; | ||
prev = _win[scan]; | ||
if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) { | ||
strend = s.strstart + MAX_MATCH; | ||
do {// Do nothing | ||
do { | ||
// Do nothing | ||
} while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend); | ||
s.match_length = MAX_MATCH - (strend - scan); | ||
if (s.match_length > s.lookahead) { | ||
s.match_length = s.lookahead; | ||
} | ||
} //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); | ||
} | ||
//Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); | ||
} | ||
} | ||
/* Emit match if have run of MIN_MATCH or longer, else emit literal */ | ||
if (s.match_length >= MIN_MATCH) { | ||
@@ -1164,3 +988,2 @@ //check_match(s, s.strstart, s.strstart - 1, s.match_length); | ||
//Tracevv((stderr,"%c", s->window[s->strstart])); | ||
/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ | ||
@@ -1171,7 +994,5 @@ bflush = trees._tr_tally(s, 0, s.window[s.strstart]); | ||
} | ||
if (bflush) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1181,3 +1002,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1187,7 +1007,5 @@ } | ||
s.insert = 0; | ||
if (flush === Z_FINISH) { | ||
/*** FLUSH_BLOCK(s, 1); ***/ | ||
flush_block_only(s, true); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1197,11 +1015,7 @@ return BS_FINISH_STARTED; | ||
/***/ | ||
return BS_FINISH_DONE; | ||
} | ||
if (s.last_lit) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1211,3 +1025,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1217,2 +1030,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -1222,7 +1036,4 @@ * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. | ||
*/ | ||
function deflate_huff(s, flush) { | ||
var bflush; | ||
/* set if current block must be flushed */ | ||
var bflush; /* set if current block must be flushed */ | ||
@@ -1233,3 +1044,2 @@ for (;;) { | ||
fill_window(s); | ||
if (s.lookahead === 0) { | ||
@@ -1239,22 +1049,16 @@ if (flush === Z_NO_FLUSH) { | ||
} | ||
break; | ||
/* flush the current block */ | ||
break; /* flush the current block */ | ||
} | ||
} | ||
/* Output a literal byte */ | ||
s.match_length = 0; //Tracevv((stderr,"%c", s->window[s->strstart])); | ||
s.match_length = 0; | ||
//Tracevv((stderr,"%c", s->window[s->strstart])); | ||
/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ | ||
bflush = trees._tr_tally(s, 0, s.window[s.strstart]); | ||
s.lookahead--; | ||
s.strstart++; | ||
if (bflush) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1264,3 +1068,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1270,7 +1073,5 @@ } | ||
s.insert = 0; | ||
if (flush === Z_FINISH) { | ||
/*** FLUSH_BLOCK(s, 1); ***/ | ||
flush_block_only(s, true); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1280,11 +1081,7 @@ return BS_FINISH_STARTED; | ||
/***/ | ||
return BS_FINISH_DONE; | ||
} | ||
if (s.last_lit) { | ||
/*** FLUSH_BLOCK(s, 0); ***/ | ||
flush_block_only(s, false); | ||
if (s.strm.avail_out === 0) { | ||
@@ -1294,3 +1091,2 @@ return BS_NEED_MORE; | ||
/***/ | ||
} | ||
@@ -1300,2 +1096,3 @@ | ||
} | ||
/* Values for max_lazy_match, good_match and max_chain_length, depending on | ||
@@ -1306,4 +1103,2 @@ * the desired pack level (0..9). The values given below have been tuned to | ||
*/ | ||
function Config(good_length, max_lazy, nice_length, max_chain, func) { | ||
@@ -1316,35 +1111,23 @@ this.good_length = good_length; | ||
} | ||
var configuration_table; | ||
configuration_table = [/* good lazy nice chain */ | ||
new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */ | ||
new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */ | ||
new Config(4, 5, 16, 8, deflate_fast), /* 2 */ | ||
new Config(4, 6, 32, 32, deflate_fast), /* 3 */ | ||
var configuration_table; | ||
configuration_table = [ | ||
/* good lazy nice chain */ | ||
new Config(0, 0, 0, 0, deflate_stored), | ||
/* 0 store only */ | ||
new Config(4, 4, 8, 4, deflate_fast), | ||
/* 1 max speed, no lazy matches */ | ||
new Config(4, 5, 16, 8, deflate_fast), | ||
/* 2 */ | ||
new Config(4, 6, 32, 32, deflate_fast), | ||
/* 3 */ | ||
new Config(4, 4, 16, 16, deflate_slow), | ||
/* 4 lazy matches */ | ||
new Config(8, 16, 32, 32, deflate_slow), | ||
/* 5 */ | ||
new Config(8, 16, 128, 128, deflate_slow), | ||
/* 6 */ | ||
new Config(8, 32, 128, 256, deflate_slow), | ||
/* 7 */ | ||
new Config(32, 128, 258, 1024, deflate_slow), | ||
/* 8 */ | ||
new Config(32, 258, 258, 4096, deflate_slow) | ||
/* 9 max compression */ | ||
]; | ||
new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */ | ||
new Config(8, 16, 32, 32, deflate_slow), /* 5 */ | ||
new Config(8, 16, 128, 128, deflate_slow), /* 6 */ | ||
new Config(8, 32, 128, 256, deflate_slow), /* 7 */ | ||
new Config(32, 128, 258, 1024, deflate_slow), /* 8 */ | ||
new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */]; | ||
/* =========================================================================== | ||
* Initialize the "longest match" routines for a new zlib stream | ||
*/ | ||
function lm_init(s) { | ||
s.window_size = 2 * s.w_size; | ||
/*** CLEAR_HASH(s); ***/ | ||
zero(s.head); // Fill with NIL (= 0); | ||
@@ -1354,3 +1137,2 @@ | ||
*/ | ||
s.max_lazy_match = configuration_table[s.level].max_lazy; | ||
@@ -1368,46 +1150,19 @@ s.good_match = configuration_table[s.level].good_length; | ||
} | ||
function DeflateState() { | ||
this.strm = null; | ||
/* pointer back to this zlib stream */ | ||
this.strm = null; /* pointer back to this zlib stream */ | ||
this.status = 0; /* as the name implies */ | ||
this.pending_buf = null; /* output still pending */ | ||
this.pending_buf_size = 0; /* size of pending_buf */ | ||
this.pending_out = 0; /* next pending byte to output to the stream */ | ||
this.pending = 0; /* nb of bytes in the pending buffer */ | ||
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ | ||
this.gzhead = null; /* gzip header information to write */ | ||
this.gzindex = 0; /* where in extra, name, or comment */ | ||
this.method = Z_DEFLATED; /* can only be DEFLATED */ | ||
this.last_flush = -1; /* value of flush param for previous deflate call */ | ||
this.status = 0; | ||
/* as the name implies */ | ||
this.w_size = 0; /* LZ77 window size (32K by default) */ | ||
this.w_bits = 0; /* log2(w_size) (8..16) */ | ||
this.w_mask = 0; /* w_size - 1 */ | ||
this.pending_buf = null; | ||
/* output still pending */ | ||
this.pending_buf_size = 0; | ||
/* size of pending_buf */ | ||
this.pending_out = 0; | ||
/* next pending byte to output to the stream */ | ||
this.pending = 0; | ||
/* nb of bytes in the pending buffer */ | ||
this.wrap = 0; | ||
/* bit 0 true for zlib, bit 1 true for gzip */ | ||
this.gzhead = null; | ||
/* gzip header information to write */ | ||
this.gzindex = 0; | ||
/* where in extra, name, or comment */ | ||
this.method = Z_DEFLATED; | ||
/* can only be DEFLATED */ | ||
this.last_flush = -1; | ||
/* value of flush param for previous deflate call */ | ||
this.w_size = 0; | ||
/* LZ77 window size (32K by default) */ | ||
this.w_bits = 0; | ||
/* log2(w_size) (8..16) */ | ||
this.w_mask = 0; | ||
/* w_size - 1 */ | ||
this.window = null; | ||
@@ -1432,17 +1187,9 @@ /* Sliding window. Input bytes are read into the second half of the window, | ||
this.head = null; | ||
/* Heads of the hash chains or NIL. */ | ||
this.head = null; /* Heads of the hash chains or NIL. */ | ||
this.ins_h = 0; | ||
/* hash index of string to be inserted */ | ||
this.ins_h = 0; /* hash index of string to be inserted */ | ||
this.hash_size = 0; /* number of elements in hash table */ | ||
this.hash_bits = 0; /* log2(hash_size) */ | ||
this.hash_mask = 0; /* hash_size-1 */ | ||
this.hash_size = 0; | ||
/* number of elements in hash table */ | ||
this.hash_bits = 0; | ||
/* log2(hash_size) */ | ||
this.hash_mask = 0; | ||
/* hash_size-1 */ | ||
this.hash_shift = 0; | ||
@@ -1460,20 +1207,9 @@ /* Number of bits by which ins_h must be shifted at each input | ||
this.match_length = 0; | ||
/* length of best match */ | ||
this.match_length = 0; /* length of best match */ | ||
this.prev_match = 0; /* previous match */ | ||
this.match_available = 0; /* set if previous match exists */ | ||
this.strstart = 0; /* start of string to insert */ | ||
this.match_start = 0; /* start of matching string */ | ||
this.lookahead = 0; /* number of valid bytes ahead in window */ | ||
this.prev_match = 0; | ||
/* previous match */ | ||
this.match_available = 0; | ||
/* set if previous match exists */ | ||
this.strstart = 0; | ||
/* start of string to insert */ | ||
this.match_start = 0; | ||
/* start of matching string */ | ||
this.lookahead = 0; | ||
/* number of valid bytes ahead in window */ | ||
this.prev_length = 0; | ||
@@ -1497,3 +1233,2 @@ /* Length of the best match at previous step. Matches not greater than this | ||
//this.max_insert_length = 0; | ||
/* Insert new strings in the hash table only if the match length is not | ||
@@ -1504,13 +1239,9 @@ * greater than this length. This saves time but degrades compression. | ||
this.level = 0; | ||
/* compression level (1..9) */ | ||
this.level = 0; /* compression level (1..9) */ | ||
this.strategy = 0; /* favor or force Huffman coding*/ | ||
this.strategy = 0; | ||
/* favor or force Huffman coding*/ | ||
this.good_match = 0; | ||
/* Use a faster search when the previous match is longer than this */ | ||
this.nice_match = 0; | ||
/* Stop searching when current match exceeds this */ | ||
this.nice_match = 0; /* Stop searching when current match exceeds this */ | ||
@@ -1520,8 +1251,9 @@ /* used by trees.c: */ | ||
/* Didn't use ct_data typedef below to suppress compiler warning */ | ||
// struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ | ||
// struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ | ||
// struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ | ||
// Use flat array of DOUBLE size, with interleaved fata, | ||
// because JS does not support effective | ||
this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); | ||
@@ -1533,26 +1265,15 @@ this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2); | ||
zero(this.bl_tree); | ||
this.l_desc = null; | ||
/* desc. for literal tree */ | ||
this.l_desc = null; /* desc. for literal tree */ | ||
this.d_desc = null; /* desc. for distance tree */ | ||
this.bl_desc = null; /* desc. for bit length tree */ | ||
this.d_desc = null; | ||
/* desc. for distance tree */ | ||
this.bl_desc = null; | ||
/* desc. for bit length tree */ | ||
//ush bl_count[MAX_BITS+1]; | ||
this.bl_count = new utils.Buf16(MAX_BITS + 1); | ||
/* number of codes at each bit length for an optimal tree */ | ||
//int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ | ||
this.heap = new utils.Buf16(2 * L_CODES + 1); | ||
/* heap used to build the Huffman trees */ | ||
this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */ | ||
zero(this.heap); | ||
this.heap_len = 0; | ||
/* number of elements in the heap */ | ||
this.heap_max = 0; | ||
/* element of largest frequency */ | ||
this.heap_len = 0; /* number of elements in the heap */ | ||
this.heap_max = 0; /* element of largest frequency */ | ||
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. | ||
@@ -1563,3 +1284,2 @@ * The same heap array is used to build all trees. | ||
this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1]; | ||
zero(this.depth); | ||
@@ -1569,4 +1289,3 @@ /* Depth of each subtree used as tie breaker for trees of equal frequency | ||
this.l_buf = 0; | ||
/* buffer index for literals or lengths */ | ||
this.l_buf = 0; /* buffer index for literals or lengths */ | ||
@@ -1593,4 +1312,3 @@ this.lit_bufsize = 0; | ||
this.last_lit = 0; | ||
/* running index in l_buf */ | ||
this.last_lit = 0; /* running index in l_buf */ | ||
@@ -1603,14 +1321,7 @@ this.d_buf = 0; | ||
this.opt_len = 0; | ||
/* bit length of current block with optimal trees */ | ||
this.opt_len = 0; /* bit length of current block with optimal trees */ | ||
this.static_len = 0; /* bit length of current block with static trees */ | ||
this.matches = 0; /* number of string matches in current block */ | ||
this.insert = 0; /* bytes at end of window left to insert */ | ||
this.static_len = 0; | ||
/* bit length of current block with static trees */ | ||
this.matches = 0; | ||
/* number of string matches in current block */ | ||
this.insert = 0; | ||
/* bytes at end of window left to insert */ | ||
this.bi_buf = 0; | ||
@@ -1620,3 +1331,2 @@ /* Output buffer. bits are inserted starting at the bottom (least | ||
*/ | ||
this.bi_valid = 0; | ||
@@ -1626,6 +1336,6 @@ /* Number of valid bits in bi_buf. All bits above the last valid bit | ||
*/ | ||
// Used for window memory init. We safely ignore it for JS. That makes | ||
// sense only for pointers and memory check tools. | ||
//this.high_water = 0; | ||
/* High water mark offset in window for initialized bytes -- bytes above | ||
@@ -1640,7 +1350,5 @@ * this are set to zero in order to avoid memory check warnings when | ||
var s; | ||
if (!strm || !strm.state) { | ||
return err(strm, Z_STREAM_ERROR); | ||
} | ||
strm.total_in = strm.total_out = 0; | ||
@@ -1651,3 +1359,2 @@ strm.data_type = Z_UNKNOWN; | ||
s.pending_out = 0; | ||
if (s.wrap < 0) { | ||
@@ -1661,20 +1368,13 @@ s.wrap = -s.wrap; | ||
: 1; // adler32(0, Z_NULL, 0) | ||
s.last_flush = Z_NO_FLUSH; | ||
trees._tr_init(s); | ||
return Z_OK; | ||
} | ||
function deflateReset(strm) { | ||
var ret = deflateResetKeep(strm); | ||
if (ret === Z_OK) { | ||
lm_init(strm.state); | ||
} | ||
return ret; | ||
} | ||
function deflateSetHeader(strm, head) { | ||
@@ -1684,11 +1384,8 @@ if (!strm || !strm.state) { | ||
} | ||
if (strm.state.wrap !== 2) { | ||
return Z_STREAM_ERROR; | ||
} | ||
strm.state.gzhead = head; | ||
return Z_OK; | ||
} | ||
function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { | ||
@@ -1699,9 +1396,6 @@ if (!strm) { | ||
} | ||
var wrap = 1; | ||
if (level === Z_DEFAULT_COMPRESSION) { | ||
level = 6; | ||
} | ||
if (windowBits < 0) { | ||
@@ -1712,12 +1406,8 @@ /* suppress zlib wrapper */ | ||
} else if (windowBits > 15) { | ||
wrap = 2; | ||
/* write gzip wrapper instead */ | ||
wrap = 2; /* write gzip wrapper instead */ | ||
windowBits -= 16; | ||
} | ||
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { | ||
return err(strm, Z_STREAM_ERROR); | ||
} | ||
if (windowBits === 8) { | ||
@@ -1728,3 +1418,2 @@ windowBits = 9; | ||
var s = new DeflateState(); | ||
@@ -1744,16 +1433,20 @@ strm.state = s; | ||
s.head = new utils.Buf16(s.hash_size); | ||
s.prev = new utils.Buf16(s.w_size); // Don't need mem init magic for JS. | ||
s.prev = new utils.Buf16(s.w_size); | ||
// Don't need mem init magic for JS. | ||
//s.high_water = 0; /* nothing written to s->window yet */ | ||
s.lit_bufsize = 1 << memLevel + 6; | ||
/* 16K elements by default */ | ||
s.lit_bufsize = 1 << memLevel + 6; /* 16K elements by default */ | ||
s.pending_buf_size = s.lit_bufsize * 4; //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); | ||
s.pending_buf_size = s.lit_bufsize * 4; | ||
//overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); | ||
//s->pending_buf = (uchf *) overlay; | ||
s.pending_buf = new utils.Buf8(s.pending_buf_size); | ||
s.pending_buf = new utils.Buf8(s.pending_buf_size); // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`) | ||
// It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`) | ||
//s->d_buf = overlay + s->lit_bufsize/sizeof(ush); | ||
s.d_buf = 1 * s.lit_bufsize; | ||
s.d_buf = 1 * s.lit_bufsize; //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; | ||
//s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; | ||
s.l_buf = (1 + 2) * s.lit_bufsize; | ||
@@ -1765,7 +1458,5 @@ s.level = level; | ||
} | ||
function deflateInit(strm, level) { | ||
return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); | ||
} | ||
function deflate(strm, flush) { | ||
@@ -1778,16 +1469,11 @@ var old_flush, s; | ||
} | ||
s = strm.state; | ||
if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE && flush !== Z_FINISH) { | ||
return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR); | ||
} | ||
s.strm = strm; | ||
/* just in case */ | ||
s.strm = strm; /* just in case */ | ||
old_flush = s.last_flush; | ||
s.last_flush = flush; | ||
/* Write the header */ | ||
if (s.status === INIT_STATE) { | ||
@@ -1797,7 +1483,5 @@ if (s.wrap === 2) { | ||
strm.adler = 0; //crc32(0L, Z_NULL, 0); | ||
put_byte(s, 31); | ||
put_byte(s, 139); | ||
put_byte(s, 8); | ||
if (!s.gzhead) { | ||
@@ -1821,3 +1505,2 @@ // s->gzhead == Z_NULL | ||
put_byte(s, s.gzhead.os & 0xff); | ||
if (s.gzhead.extra && s.gzhead.extra.length) { | ||
@@ -1827,15 +1510,13 @@ put_byte(s, s.gzhead.extra.length & 0xff); | ||
} | ||
if (s.gzhead.hcrc) { | ||
strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending, 0); | ||
} | ||
s.gzindex = 0; | ||
s.status = EXTRA_STATE; | ||
} | ||
} else // DEFLATE header | ||
} else | ||
// DEFLATE header | ||
{ | ||
var header = Z_DEFLATED + (s.w_bits - 8 << 4) << 8; | ||
var level_flags = -1; | ||
if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) { | ||
@@ -1850,14 +1531,11 @@ level_flags = 0; | ||
} | ||
header |= level_flags << 6; | ||
if (s.strstart !== 0) { | ||
header |= PRESET_DICT; | ||
} | ||
header += 31 - header % 31; | ||
s.status = BUSY_STATE; | ||
putShortMSB(s, header); | ||
/* Save the adler32 of the preset dictionary: */ | ||
if (s.strstart !== 0) { | ||
@@ -1867,14 +1545,10 @@ putShortMSB(s, strm.adler >>> 16); | ||
} | ||
strm.adler = 1; // adler32(0L, Z_NULL, 0); | ||
} | ||
} //#ifdef GZIP | ||
} | ||
//#ifdef GZIP | ||
if (s.status === EXTRA_STATE) { | ||
if (s.gzhead.extra | ||
/* != Z_NULL*/ | ||
) { | ||
beg = s.pending; | ||
/* start of bytes to update crc */ | ||
if (s.gzhead.extra /* != Z_NULL*/) { | ||
beg = s.pending; /* start of bytes to update crc */ | ||
@@ -1886,6 +1560,4 @@ while (s.gzindex < (s.gzhead.extra.length & 0xffff)) { | ||
} | ||
flush_pending(strm); | ||
beg = s.pending; | ||
if (s.pending === s.pending_buf_size) { | ||
@@ -1895,11 +1567,8 @@ break; | ||
} | ||
put_byte(s, s.gzhead.extra[s.gzindex] & 0xff); | ||
s.gzindex++; | ||
} | ||
if (s.gzhead.hcrc && s.pending > beg) { | ||
strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg); | ||
} | ||
if (s.gzindex === s.gzhead.extra.length) { | ||
@@ -1913,9 +1582,5 @@ s.gzindex = 0; | ||
} | ||
if (s.status === NAME_STATE) { | ||
if (s.gzhead.name | ||
/* != Z_NULL*/ | ||
) { | ||
beg = s.pending; | ||
/* start of bytes to update crc */ | ||
if (s.gzhead.name /* != Z_NULL*/) { | ||
beg = s.pending; /* start of bytes to update crc */ | ||
//int val; | ||
@@ -1928,6 +1593,4 @@ | ||
} | ||
flush_pending(strm); | ||
beg = s.pending; | ||
if (s.pending === s.pending_buf_size) { | ||
@@ -1937,5 +1600,4 @@ val = 1; | ||
} | ||
} // JS specific: little magic to add zero terminator to end of string | ||
} | ||
// JS specific: little magic to add zero terminator to end of string | ||
if (s.gzindex < s.gzhead.name.length) { | ||
@@ -1946,10 +1608,7 @@ val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff; | ||
} | ||
put_byte(s, val); | ||
} while (val !== 0); | ||
if (s.gzhead.hcrc && s.pending > beg) { | ||
strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg); | ||
} | ||
if (val === 0) { | ||
@@ -1963,9 +1622,5 @@ s.gzindex = 0; | ||
} | ||
if (s.status === COMMENT_STATE) { | ||
if (s.gzhead.comment | ||
/* != Z_NULL*/ | ||
) { | ||
beg = s.pending; | ||
/* start of bytes to update crc */ | ||
if (s.gzhead.comment /* != Z_NULL*/) { | ||
beg = s.pending; /* start of bytes to update crc */ | ||
//int val; | ||
@@ -1978,6 +1633,4 @@ | ||
} | ||
flush_pending(strm); | ||
beg = s.pending; | ||
if (s.pending === s.pending_buf_size) { | ||
@@ -1987,5 +1640,4 @@ val = 1; | ||
} | ||
} // JS specific: little magic to add zero terminator to end of string | ||
} | ||
// JS specific: little magic to add zero terminator to end of string | ||
if (s.gzindex < s.gzhead.comment.length) { | ||
@@ -1996,10 +1648,7 @@ val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff; | ||
} | ||
put_byte(s, val); | ||
} while (val !== 0); | ||
if (s.gzhead.hcrc && s.pending > beg) { | ||
strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg); | ||
} | ||
if (val === 0) { | ||
@@ -2012,3 +1661,2 @@ s.status = HCRC_STATE; | ||
} | ||
if (s.status === HCRC_STATE) { | ||
@@ -2019,3 +1667,2 @@ if (s.gzhead.hcrc) { | ||
} | ||
if (s.pending + 2 <= s.pending_buf_size) { | ||
@@ -2025,3 +1672,2 @@ put_byte(s, strm.adler & 0xff); | ||
strm.adler = 0; //crc32(0L, Z_NULL, 0); | ||
s.status = BUSY_STATE; | ||
@@ -2032,10 +1678,8 @@ } | ||
} | ||
} //#endif | ||
} | ||
//#endif | ||
/* Flush as much pending output as possible */ | ||
if (s.pending !== 0) { | ||
flush_pending(strm); | ||
if (strm.avail_out === 0) { | ||
@@ -2051,2 +1695,3 @@ /* Since avail_out is 0, deflate will be called again with | ||
} | ||
/* Make sure there is something to do and avoid duplicate consecutive | ||
@@ -2056,23 +1701,18 @@ * flushes. For repeated and useless calls with Z_FINISH, we keep | ||
*/ | ||
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) { | ||
return err(strm, Z_BUF_ERROR); | ||
} | ||
/* User must not provide more input after the first FINISH: */ | ||
if (s.status === FINISH_STATE && strm.avail_in !== 0) { | ||
return err(strm, Z_BUF_ERROR); | ||
} | ||
/* Start a new block or continue the current one. | ||
*/ | ||
if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH && s.status !== FINISH_STATE) { | ||
var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s.strategy === Z_RLE ? deflate_rle(s, flush) : configuration_table[s.level].func(s, flush); | ||
if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) { | ||
s.status = FINISH_STATE; | ||
} | ||
if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) { | ||
@@ -2099,2 +1739,3 @@ if (strm.avail_out === 0) { | ||
/* FULL_FLUSH or SYNC_FLUSH */ | ||
trees._tr_stored_block(s, 0, 0, false); | ||
@@ -2104,8 +1745,4 @@ /* For a full flush, this empty block will be recognized | ||
*/ | ||
if (flush === Z_FULL_FLUSH) { | ||
/*** CLEAR_HASH(s); ***/ | ||
/* forget history */ | ||
/*** CLEAR_HASH(s); ***/ /* forget history */ | ||
zero(s.head); // Fill with NIL (= 0); | ||
@@ -2120,26 +1757,20 @@ | ||
} | ||
flush_pending(strm); | ||
if (strm.avail_out === 0) { | ||
s.last_flush = -1; | ||
/* avoid BUF_ERROR at next call, see above */ | ||
s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */ | ||
return Z_OK; | ||
} | ||
} | ||
} //Assert(strm->avail_out > 0, "bug2"); | ||
} | ||
//Assert(strm->avail_out > 0, "bug2"); | ||
//if (strm.avail_out <= 0) { throw new Error("bug2");} | ||
if (flush !== Z_FINISH) { | ||
return Z_OK; | ||
} | ||
if (s.wrap <= 0) { | ||
return Z_STREAM_END; | ||
} | ||
/* Write the trailer */ | ||
if (s.wrap === 2) { | ||
@@ -2158,3 +1789,2 @@ put_byte(s, strm.adler & 0xff); | ||
} | ||
flush_pending(strm); | ||
@@ -2164,3 +1794,2 @@ /* If avail_out is zero, the application will call deflate again | ||
*/ | ||
if (s.wrap > 0) { | ||
@@ -2170,27 +1799,17 @@ s.wrap = -s.wrap; | ||
/* write the trailer only once! */ | ||
return s.pending !== 0 ? Z_OK : Z_STREAM_END; | ||
} | ||
function deflateEnd(strm) { | ||
var status; | ||
if (!strm | ||
/*== Z_NULL*/ | ||
|| !strm.state | ||
/*== Z_NULL*/ | ||
) { | ||
if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) { | ||
return Z_STREAM_ERROR; | ||
} | ||
status = strm.state.status; | ||
if (status !== INIT_STATE && status !== EXTRA_STATE && status !== NAME_STATE && status !== COMMENT_STATE && status !== HCRC_STATE && status !== BUSY_STATE && status !== FINISH_STATE) { | ||
return err(strm, Z_STREAM_ERROR); | ||
} | ||
strm.state = null; | ||
return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; | ||
} | ||
/* ========================================================================= | ||
@@ -2200,4 +1819,2 @@ * Initializes the compression dictionary from the given byte | ||
*/ | ||
function deflateSetDictionary(strm, dictionary) { | ||
@@ -2212,20 +1829,12 @@ var dictLength = dictionary.length; | ||
var tmpDict; | ||
if (!strm | ||
/*== Z_NULL*/ | ||
|| !strm.state | ||
/*== Z_NULL*/ | ||
) { | ||
if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) { | ||
return Z_STREAM_ERROR; | ||
} | ||
s = strm.state; | ||
wrap = s.wrap; | ||
if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) { | ||
return Z_STREAM_ERROR; | ||
} | ||
/* when using zlib wrappers, compute Adler-32 for provided dictionary */ | ||
if (wrap === 1) { | ||
@@ -2235,15 +1844,10 @@ /* adler32(strm->adler, dictionary, dictLength); */ | ||
} | ||
s.wrap = 0; /* avoid computing Adler-32 in read_buf */ | ||
s.wrap = 0; | ||
/* avoid computing Adler-32 in read_buf */ | ||
/* if dictionary would fill window, just replace the history */ | ||
if (dictLength >= s.w_size) { | ||
if (wrap === 0) { | ||
/* already empty otherwise */ | ||
/*** CLEAR_HASH(s); ***/ | ||
zero(s.head); // Fill with NIL (= 0); | ||
s.strstart = 0; | ||
@@ -2255,4 +1859,2 @@ s.block_start = 0; | ||
// dictionary = dictionary.slice(dictLength - s.w_size); | ||
tmpDict = new utils.Buf8(s.w_size); | ||
@@ -2264,4 +1866,2 @@ utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0); | ||
/* insert dictionary into window and hash */ | ||
avail = strm.avail_in; | ||
@@ -2274,7 +1874,5 @@ next = strm.next_in; | ||
fill_window(s); | ||
while (s.lookahead >= MIN_MATCH) { | ||
str = s.strstart; | ||
n = s.lookahead - (MIN_MATCH - 1); | ||
do { | ||
@@ -2287,3 +1885,2 @@ /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ | ||
} while (--n); | ||
s.strstart = str; | ||
@@ -2293,3 +1890,2 @@ s.lookahead = MIN_MATCH - 1; | ||
} | ||
s.strstart += s.lookahead; | ||
@@ -2307,4 +1903,4 @@ s.block_start = s.strstart; | ||
} | ||
var deflateInfo = 'pako deflate (from Nodeca project)'; | ||
var deflateInfo = 'pako deflate (from Nodeca project)'; | ||
/* Not implemented | ||
@@ -2318,3 +1914,2 @@ exports.deflateBound = deflateBound; | ||
*/ | ||
exports.deflateInfo = deflateInfo; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = GZheader; | ||
function GZheader() { | ||
@@ -13,17 +12,13 @@ /* true if compressed data believed to be text */ | ||
/* modification time */ | ||
this.time = 0; | ||
/* extra flags (not used when writing a gzip file) */ | ||
this.xflags = 0; | ||
/* operating system */ | ||
this.os = 0; | ||
/* pointer to extra field or Z_NULL if none */ | ||
this.extra = null; | ||
/* extra field length (valid if extra != Z_NULL) */ | ||
this.extra_len = 0; // Actually, we don't need it in JS, | ||
// but leave for few code modifications | ||
// | ||
@@ -36,21 +31,14 @@ // Setup limits is not necessary because in js we should not preallocate memory | ||
// this.extra_max = 0; | ||
/* pointer to zero-terminated file name or Z_NULL */ | ||
this.name = ''; | ||
/* space at name (only when reading header) */ | ||
// this.name_max = 0; | ||
/* pointer to zero-terminated comment or Z_NULL */ | ||
this.comment = ''; | ||
/* space at comment (only when reading header) */ | ||
// this.comm_max = 0; | ||
/* true if there was or will be a header crc */ | ||
this.hcrc = 0; | ||
/* true when done reading gzip header (not used when writing a gzip file) */ | ||
this.done = false; | ||
} |
@@ -8,8 +8,5 @@ "use strict"; | ||
// See state defs from inflate.js | ||
var BAD = 30; | ||
/* got a data error -- remain here until reset */ | ||
var BAD = 30; /* got a data error -- remain here until reset */ | ||
var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ | ||
var TYPE = 12; | ||
/* i: waiting for type bits, including last-flag bit */ | ||
/* | ||
@@ -50,76 +47,29 @@ Decode literal, length, and distance codes and write out the resulting | ||
*/ | ||
function inflate_fast(strm, start) { | ||
var state; | ||
var _in; | ||
/* local strm.input */ | ||
var last; | ||
/* have enough input while in < last */ | ||
var _out; | ||
/* local strm.output */ | ||
var beg; | ||
/* inflate()'s initial strm.output */ | ||
var end; | ||
/* while out < end, enough space available */ | ||
var _in; /* local strm.input */ | ||
var last; /* have enough input while in < last */ | ||
var _out; /* local strm.output */ | ||
var beg; /* inflate()'s initial strm.output */ | ||
var end; /* while out < end, enough space available */ | ||
//#ifdef INFLATE_STRICT | ||
var dmax; | ||
/* maximum distance from zlib header */ | ||
var dmax; /* maximum distance from zlib header */ | ||
//#endif | ||
var wsize; | ||
/* window size or zero if not using window */ | ||
var whave; | ||
/* valid bytes in the window */ | ||
var wnext; | ||
/* window write index */ | ||
var wsize; /* window size or zero if not using window */ | ||
var whave; /* valid bytes in the window */ | ||
var wnext; /* window write index */ | ||
// Use `s_window` instead `window`, avoid conflict with instrumentation tools | ||
var s_window; | ||
/* allocated sliding window, if wsize != 0 */ | ||
var hold; | ||
/* local strm.hold */ | ||
var bits; | ||
/* local strm.bits */ | ||
var lcode; | ||
/* local strm.lencode */ | ||
var dcode; | ||
/* local strm.distcode */ | ||
var lmask; | ||
/* mask for first level of length codes */ | ||
var dmask; | ||
/* mask for first level of distance codes */ | ||
var here; | ||
/* retrieved table entry */ | ||
var op; | ||
/* code bits, operation, extra bits, or */ | ||
var s_window; /* allocated sliding window, if wsize != 0 */ | ||
var hold; /* local strm.hold */ | ||
var bits; /* local strm.bits */ | ||
var lcode; /* local strm.lencode */ | ||
var dcode; /* local strm.distcode */ | ||
var lmask; /* mask for first level of length codes */ | ||
var dmask; /* mask for first level of distance codes */ | ||
var here; /* retrieved table entry */ | ||
var op; /* code bits, operation, extra bits, or */ | ||
/* window position, window bytes to copy */ | ||
var len; | ||
/* match length, unused bytes */ | ||
var dist; | ||
/* match distance */ | ||
var from; | ||
/* where to copy match from */ | ||
var len; /* match length, unused bytes */ | ||
var dist; /* match distance */ | ||
var from; /* where to copy match from */ | ||
var from_source; | ||
@@ -129,5 +79,4 @@ var input, output; // JS specific, because we have no pointers | ||
/* copy state to local variables */ | ||
state = strm.state; //here = state.here; | ||
state = strm.state; | ||
//here = state.here; | ||
_in = strm.next_in; | ||
@@ -139,6 +88,6 @@ input = strm.input; | ||
beg = _out - (start - strm.avail_out); | ||
end = _out + (strm.avail_out - 257); //#ifdef INFLATE_STRICT | ||
dmax = state.dmax; //#endif | ||
end = _out + (strm.avail_out - 257); | ||
//#ifdef INFLATE_STRICT | ||
dmax = state.dmax; | ||
//#endif | ||
wsize = state.wsize; | ||
@@ -154,2 +103,3 @@ whave = state.whave; | ||
dmask = (1 << state.distbits) - 1; | ||
/* decode literals and length/distances until end-of-block or not enough | ||
@@ -165,16 +115,9 @@ input data or output space */ | ||
} | ||
here = lcode[hold & lmask]; | ||
dolen: for (;;) { | ||
// Goto emulation | ||
op = here >>> 24 | ||
/*here.bits*/ | ||
; | ||
op = here >>> 24 /*here.bits*/; | ||
hold >>>= op; | ||
bits -= op; | ||
op = here >>> 16 & 0xff | ||
/*here.op*/ | ||
; | ||
op = here >>> 16 & 0xff /*here.op*/; | ||
if (op === 0) { | ||
@@ -185,13 +128,7 @@ /* literal */ | ||
// "inflate: literal 0x%02x\n", here.val)); | ||
output[_out++] = here & 0xffff | ||
/*here.val*/ | ||
; | ||
output[_out++] = here & 0xffff /*here.val*/; | ||
} else if (op & 16) { | ||
/* length base */ | ||
len = here & 0xffff | ||
/*here.val*/ | ||
; | ||
op &= 15; | ||
/* number of extra bits */ | ||
len = here & 0xffff /*here.val*/; | ||
op &= 15; /* number of extra bits */ | ||
if (op) { | ||
@@ -202,9 +139,7 @@ if (bits < op) { | ||
} | ||
len += hold & (1 << op) - 1; | ||
hold >>>= op; | ||
bits -= op; | ||
} //Tracevv((stderr, "inflate: length %u\n", len)); | ||
} | ||
//Tracevv((stderr, "inflate: length %u\n", len)); | ||
if (bits < 15) { | ||
@@ -216,28 +151,17 @@ hold += input[_in++] << bits; | ||
} | ||
here = dcode[hold & dmask]; | ||
dodist: for (;;) { | ||
// goto emulation | ||
op = here >>> 24 | ||
/*here.bits*/ | ||
; | ||
op = here >>> 24 /*here.bits*/; | ||
hold >>>= op; | ||
bits -= op; | ||
op = here >>> 16 & 0xff | ||
/*here.op*/ | ||
; | ||
op = here >>> 16 & 0xff /*here.op*/; | ||
if (op & 16) { | ||
/* distance base */ | ||
dist = here & 0xffff | ||
/*here.val*/ | ||
; | ||
op &= 15; | ||
/* number of extra bits */ | ||
dist = here & 0xffff /*here.val*/; | ||
op &= 15; /* number of extra bits */ | ||
if (bits < op) { | ||
hold += input[_in++] << bits; | ||
bits += 8; | ||
if (bits < op) { | ||
@@ -248,5 +172,4 @@ hold += input[_in++] << bits; | ||
} | ||
dist += hold & (1 << op) - 1; //#ifdef INFLATE_STRICT | ||
dist += hold & (1 << op) - 1; | ||
//#ifdef INFLATE_STRICT | ||
if (dist > dmax) { | ||
@@ -256,16 +179,11 @@ strm.msg = 'invalid distance too far back'; | ||
break top; | ||
} //#endif | ||
} | ||
//#endif | ||
hold >>>= op; | ||
bits -= op; //Tracevv((stderr, "inflate: distance %u\n", dist)); | ||
op = _out - beg; | ||
/* max distance in output */ | ||
bits -= op; | ||
//Tracevv((stderr, "inflate: distance %u\n", dist)); | ||
op = _out - beg; /* max distance in output */ | ||
if (dist > op) { | ||
/* see if copy from window */ | ||
op = dist - op; | ||
/* distance back in window */ | ||
op = dist - op; /* distance back in window */ | ||
if (op > whave) { | ||
@@ -276,3 +194,5 @@ if (state.sane) { | ||
break top; | ||
} // (!) This block is disabled in zlib defailts, | ||
} | ||
// (!) This block is disabled in zlib defailts, | ||
// don't enable it for binary compatibility | ||
@@ -298,24 +218,16 @@ //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
//#endif | ||
} | ||
from = 0; // window index | ||
from_source = s_window; | ||
if (wnext === 0) { | ||
/* very common case */ | ||
from += wsize - op; | ||
if (op < len) { | ||
/* some from window */ | ||
len -= op; | ||
do { | ||
output[_out++] = s_window[from++]; | ||
} while (--op); | ||
from = _out - dist; | ||
/* rest from output */ | ||
from = _out - dist; /* rest from output */ | ||
from_source = output; | ||
@@ -327,13 +239,9 @@ } | ||
op -= wnext; | ||
if (op < len) { | ||
/* some from end of window */ | ||
len -= op; | ||
do { | ||
output[_out++] = s_window[from++]; | ||
} while (--op); | ||
from = 0; | ||
if (wnext < len) { | ||
@@ -343,10 +251,6 @@ /* some from start of window */ | ||
len -= op; | ||
do { | ||
output[_out++] = s_window[from++]; | ||
} while (--op); | ||
from = _out - dist; | ||
/* rest from output */ | ||
from = _out - dist; /* rest from output */ | ||
from_source = output; | ||
@@ -358,18 +262,12 @@ } | ||
from += wnext - op; | ||
if (op < len) { | ||
/* some from window */ | ||
len -= op; | ||
do { | ||
output[_out++] = s_window[from++]; | ||
} while (--op); | ||
from = _out - dist; | ||
/* rest from output */ | ||
from = _out - dist; /* rest from output */ | ||
from_source = output; | ||
} | ||
} | ||
while (len > 2) { | ||
@@ -381,6 +279,4 @@ output[_out++] = from_source[from++]; | ||
} | ||
if (len) { | ||
output[_out++] = from_source[from++]; | ||
if (len > 1) { | ||
@@ -391,5 +287,3 @@ output[_out++] = from_source[from++]; | ||
} else { | ||
from = _out - dist; | ||
/* copy direct from output */ | ||
from = _out - dist; /* copy direct from output */ | ||
do { | ||
@@ -402,6 +296,4 @@ /* minimum length is three */ | ||
} while (len > 2); | ||
if (len) { | ||
output[_out++] = output[from++]; | ||
if (len > 1) { | ||
@@ -414,5 +306,3 @@ output[_out++] = output[from++]; | ||
/* 2nd level distance code */ | ||
here = dcode[(here & 0xffff | ||
/*here.val*/ | ||
) + (hold & (1 << op) - 1)]; | ||
here = dcode[(here & 0xffff /*here.val*/) + (hold & (1 << op) - 1)]; | ||
continue dodist; | ||
@@ -424,3 +314,2 @@ } else { | ||
} | ||
break; // need to emulate goto via "continue" | ||
@@ -430,5 +319,3 @@ } | ||
/* 2nd level length code */ | ||
here = lcode[(here & 0xffff | ||
/*here.val*/ | ||
) + (hold & (1 << op) - 1)]; | ||
here = lcode[(here & 0xffff /*here.val*/) + (hold & (1 << op) - 1)]; | ||
continue dolen; | ||
@@ -445,9 +332,7 @@ } else if (op & 32) { | ||
} | ||
break; // need to emulate goto via "continue" | ||
} | ||
} while (_in < last && _out < end); | ||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ | ||
len = bits >> 3; | ||
@@ -457,4 +342,4 @@ _in -= len; | ||
hold &= (1 << bits) - 1; | ||
/* update state and return */ | ||
strm.next_in = _in; | ||
@@ -468,3 +353,2 @@ strm.next_out = _out; | ||
} | ||
; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -19,24 +18,15 @@ value: true | ||
exports.inflateSetDictionary = inflateSetDictionary; | ||
var utils = _interopRequireWildcard(require("../utils/common.js")); | ||
var _adler = _interopRequireDefault(require("./adler32.js")); | ||
var _crc = _interopRequireDefault(require("./crc32.js")); | ||
var _inffast = _interopRequireDefault(require("./inffast.js")); | ||
var _inftrees = _interopRequireDefault(require("./inftrees.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
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); } | ||
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; } | ||
var CODES = 0; | ||
var LENS = 1; | ||
var DISTS = 2; | ||
/* Public constants ==========================================================*/ | ||
/* ===========================================================================*/ | ||
@@ -49,3 +39,2 @@ | ||
//export const Z_FULL_FLUSH = 3; | ||
var Z_FINISH = 4; | ||
@@ -56,6 +45,6 @@ exports.Z_FINISH = Z_FINISH; | ||
var Z_TREES = 6; | ||
/* Return codes for the compression/decompression functions. Negative values | ||
* are errors, positive values are used for special but normal events. | ||
*/ | ||
exports.Z_TREES = Z_TREES; | ||
@@ -66,4 +55,4 @@ var Z_OK = 0; | ||
exports.Z_STREAM_END = Z_STREAM_END; | ||
var Z_NEED_DICT = 2; //export const Z_ERRNO = -1; | ||
var Z_NEED_DICT = 2; | ||
//export const Z_ERRNO = -1; | ||
exports.Z_NEED_DICT = Z_NEED_DICT; | ||
@@ -76,227 +65,103 @@ var Z_STREAM_ERROR = -2; | ||
exports.Z_MEM_ERROR = Z_MEM_ERROR; | ||
var Z_BUF_ERROR = -5; //export const Z_VERSION_ERROR = -6; | ||
var Z_BUF_ERROR = -5; | ||
//export const Z_VERSION_ERROR = -6; | ||
/* The deflate compression method */ | ||
exports.Z_BUF_ERROR = Z_BUF_ERROR; | ||
var Z_DEFLATED = 8; | ||
/* STATES ====================================================================*/ | ||
/* ===========================================================================*/ | ||
exports.Z_DEFLATED = Z_DEFLATED; | ||
var HEAD = 1; | ||
/* i: waiting for magic header */ | ||
var HEAD = 1; /* i: waiting for magic header */ | ||
var FLAGS = 2; /* i: waiting for method and flags (gzip) */ | ||
var TIME = 3; /* i: waiting for modification time (gzip) */ | ||
var OS = 4; /* i: waiting for extra flags and operating system (gzip) */ | ||
var EXLEN = 5; /* i: waiting for extra length (gzip) */ | ||
var EXTRA = 6; /* i: waiting for extra bytes (gzip) */ | ||
var NAME = 7; /* i: waiting for end of file name (gzip) */ | ||
var COMMENT = 8; /* i: waiting for end of comment (gzip) */ | ||
var HCRC = 9; /* i: waiting for header crc (gzip) */ | ||
var DICTID = 10; /* i: waiting for dictionary check value */ | ||
var DICT = 11; /* waiting for inflateSetDictionary() call */ | ||
var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ | ||
var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */ | ||
var STORED = 14; /* i: waiting for stored size (length and complement) */ | ||
var COPY_ = 15; /* i/o: same as COPY below, but only first time in */ | ||
var COPY = 16; /* i/o: waiting for input or output to copy stored block */ | ||
var TABLE = 17; /* i: waiting for dynamic block table lengths */ | ||
var LENLENS = 18; /* i: waiting for code length code lengths */ | ||
var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */ | ||
var LEN_ = 20; /* i: same as LEN below, but only first time in */ | ||
var LEN = 21; /* i: waiting for length/lit/eob code */ | ||
var LENEXT = 22; /* i: waiting for length extra bits */ | ||
var DIST = 23; /* i: waiting for distance code */ | ||
var DISTEXT = 24; /* i: waiting for distance extra bits */ | ||
var MATCH = 25; /* o: waiting for output space to copy string */ | ||
var LIT = 26; /* o: waiting for output space to write literal */ | ||
var CHECK = 27; /* i: waiting for 32-bit check value */ | ||
var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */ | ||
var DONE = 29; /* finished check, done -- remain here until reset */ | ||
var BAD = 30; /* got a data error -- remain here until reset */ | ||
var MEM = 31; /* got an inflate() memory error -- remain here until reset */ | ||
var SYNC = 32; /* looking for synchronization bytes to restart inflate() */ | ||
var FLAGS = 2; | ||
/* i: waiting for method and flags (gzip) */ | ||
var TIME = 3; | ||
/* i: waiting for modification time (gzip) */ | ||
var OS = 4; | ||
/* i: waiting for extra flags and operating system (gzip) */ | ||
var EXLEN = 5; | ||
/* i: waiting for extra length (gzip) */ | ||
var EXTRA = 6; | ||
/* i: waiting for extra bytes (gzip) */ | ||
var NAME = 7; | ||
/* i: waiting for end of file name (gzip) */ | ||
var COMMENT = 8; | ||
/* i: waiting for end of comment (gzip) */ | ||
var HCRC = 9; | ||
/* i: waiting for header crc (gzip) */ | ||
var DICTID = 10; | ||
/* i: waiting for dictionary check value */ | ||
var DICT = 11; | ||
/* waiting for inflateSetDictionary() call */ | ||
var TYPE = 12; | ||
/* i: waiting for type bits, including last-flag bit */ | ||
var TYPEDO = 13; | ||
/* i: same, but skip check to exit inflate on new block */ | ||
var STORED = 14; | ||
/* i: waiting for stored size (length and complement) */ | ||
var COPY_ = 15; | ||
/* i/o: same as COPY below, but only first time in */ | ||
var COPY = 16; | ||
/* i/o: waiting for input or output to copy stored block */ | ||
var TABLE = 17; | ||
/* i: waiting for dynamic block table lengths */ | ||
var LENLENS = 18; | ||
/* i: waiting for code length code lengths */ | ||
var CODELENS = 19; | ||
/* i: waiting for length/lit and distance code lengths */ | ||
var LEN_ = 20; | ||
/* i: same as LEN below, but only first time in */ | ||
var LEN = 21; | ||
/* i: waiting for length/lit/eob code */ | ||
var LENEXT = 22; | ||
/* i: waiting for length extra bits */ | ||
var DIST = 23; | ||
/* i: waiting for distance code */ | ||
var DISTEXT = 24; | ||
/* i: waiting for distance extra bits */ | ||
var MATCH = 25; | ||
/* o: waiting for output space to copy string */ | ||
var LIT = 26; | ||
/* o: waiting for output space to write literal */ | ||
var CHECK = 27; | ||
/* i: waiting for 32-bit check value */ | ||
var LENGTH = 28; | ||
/* i: waiting for 32-bit length (gzip) */ | ||
var DONE = 29; | ||
/* finished check, done -- remain here until reset */ | ||
var BAD = 30; | ||
/* got a data error -- remain here until reset */ | ||
var MEM = 31; | ||
/* got an inflate() memory error -- remain here until reset */ | ||
var SYNC = 32; | ||
/* looking for synchronization bytes to restart inflate() */ | ||
/* ===========================================================================*/ | ||
var ENOUGH_LENS = 852; | ||
var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); | ||
var ENOUGH_DISTS = 592; | ||
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); | ||
var MAX_WBITS = 15; | ||
/* 32K LZ77 window */ | ||
var DEF_WBITS = MAX_WBITS; | ||
function zswap32(q) { | ||
return (q >>> 24 & 0xff) + (q >>> 8 & 0xff00) + ((q & 0xff00) << 8) + ((q & 0xff) << 24); | ||
} | ||
function InflateState() { | ||
this.mode = 0; | ||
/* current inflate mode */ | ||
this.last = false; | ||
/* true if processing last block */ | ||
this.wrap = 0; | ||
/* bit 0 true for zlib, bit 1 true for gzip */ | ||
this.havedict = false; | ||
/* true if dictionary provided */ | ||
this.flags = 0; | ||
/* gzip header method and flags (0 if zlib) */ | ||
this.dmax = 0; | ||
/* zlib header max distance (INFLATE_STRICT) */ | ||
this.check = 0; | ||
/* protected copy of check value */ | ||
this.total = 0; | ||
/* protected copy of output count */ | ||
this.mode = 0; /* current inflate mode */ | ||
this.last = false; /* true if processing last block */ | ||
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ | ||
this.havedict = false; /* true if dictionary provided */ | ||
this.flags = 0; /* gzip header method and flags (0 if zlib) */ | ||
this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */ | ||
this.check = 0; /* protected copy of check value */ | ||
this.total = 0; /* protected copy of output count */ | ||
// TODO: may be {} | ||
this.head = null; /* where to save gzip header information */ | ||
this.head = null; | ||
/* where to save gzip header information */ | ||
/* sliding window */ | ||
this.wbits = 0; /* log base 2 of requested window size */ | ||
this.wsize = 0; /* window size or zero if not using window */ | ||
this.whave = 0; /* valid bytes in the window */ | ||
this.wnext = 0; /* window write index */ | ||
this.window = null; /* allocated sliding window, if needed */ | ||
this.wbits = 0; | ||
/* log base 2 of requested window size */ | ||
this.wsize = 0; | ||
/* window size or zero if not using window */ | ||
this.whave = 0; | ||
/* valid bytes in the window */ | ||
this.wnext = 0; | ||
/* window write index */ | ||
this.window = null; | ||
/* allocated sliding window, if needed */ | ||
/* bit accumulator */ | ||
this.hold = 0; /* input bit accumulator */ | ||
this.bits = 0; /* number of bits in "in" */ | ||
this.hold = 0; | ||
/* input bit accumulator */ | ||
this.bits = 0; | ||
/* number of bits in "in" */ | ||
/* for string and stored block copying */ | ||
this.length = 0; /* literal or length of data to copy */ | ||
this.offset = 0; /* distance back to copy string from */ | ||
this.length = 0; | ||
/* literal or length of data to copy */ | ||
this.offset = 0; | ||
/* distance back to copy string from */ | ||
/* for table and code decoding */ | ||
this.extra = 0; /* extra bits needed */ | ||
this.extra = 0; | ||
/* extra bits needed */ | ||
/* fixed and dynamic code tables */ | ||
this.lencode = null; /* starting table for length/literal codes */ | ||
this.distcode = null; /* starting table for distance codes */ | ||
this.lenbits = 0; /* index bits for lencode */ | ||
this.distbits = 0; /* index bits for distcode */ | ||
this.lencode = null; | ||
/* starting table for length/literal codes */ | ||
this.distcode = null; | ||
/* starting table for distance codes */ | ||
this.lenbits = 0; | ||
/* index bits for lencode */ | ||
this.distbits = 0; | ||
/* index bits for distcode */ | ||
/* dynamic table building */ | ||
this.ncode = 0; /* number of code length code lengths */ | ||
this.nlen = 0; /* number of length code lengths */ | ||
this.ndist = 0; /* number of distance code lengths */ | ||
this.have = 0; /* number of code lengths in lens[] */ | ||
this.next = null; /* next available space in codes[] */ | ||
this.ncode = 0; | ||
/* number of code length code lengths */ | ||
this.lens = new utils.Buf16(320); /* temporary storage for code lengths */ | ||
this.work = new utils.Buf16(288); /* work area for code table building */ | ||
this.nlen = 0; | ||
/* number of length code lengths */ | ||
this.ndist = 0; | ||
/* number of distance code lengths */ | ||
this.have = 0; | ||
/* number of code lengths in lens[] */ | ||
this.next = null; | ||
/* next available space in codes[] */ | ||
this.lens = new utils.Buf16(320); | ||
/* temporary storage for code lengths */ | ||
this.work = new utils.Buf16(288); | ||
/* work area for code table building */ | ||
/* | ||
@@ -307,17 +172,7 @@ because we don't have pointers in js, we use lencode and distcode directly | ||
//this.codes = new utils.Buf32(ENOUGH); /* space for code tables */ | ||
this.lendyn = null; | ||
/* dynamic table for length/literal codes (JS specific) */ | ||
this.distdyn = null; | ||
/* dynamic table for distance codes (JS specific) */ | ||
this.sane = 0; | ||
/* if false, allow invalid distance too far */ | ||
this.back = 0; | ||
/* bits back of last unprocessed length/lit */ | ||
this.was = 0; | ||
/* initial length of match */ | ||
this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */ | ||
this.distdyn = null; /* dynamic table for distance codes (JS specific) */ | ||
this.sane = 0; /* if false, allow invalid distance too far */ | ||
this.back = 0; /* bits back of last unprocessed length/lit */ | ||
this.was = 0; /* initial length of match */ | ||
} | ||
@@ -327,12 +182,8 @@ | ||
var state; | ||
if (!strm || !strm.state) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
strm.total_in = strm.total_out = state.total = 0; | ||
strm.msg = ''; | ||
/*Z_NULL*/ | ||
strm.msg = ''; /*Z_NULL*/ | ||
if (state.wrap) { | ||
@@ -342,3 +193,2 @@ /* to support ill-conceived Java test suite */ | ||
} | ||
state.mode = HEAD; | ||
@@ -348,23 +198,18 @@ state.last = 0; | ||
state.dmax = 32768; | ||
state.head = null | ||
/*Z_NULL*/ | ||
; | ||
state.head = null /*Z_NULL*/; | ||
state.hold = 0; | ||
state.bits = 0; //state.lencode = state.distcode = state.next = state.codes; | ||
state.bits = 0; | ||
//state.lencode = state.distcode = state.next = state.codes; | ||
state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS); | ||
state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS); | ||
state.sane = 1; | ||
state.back = -1; //Tracev((stderr, "inflate: reset\n")); | ||
state.back = -1; | ||
//Tracev((stderr, "inflate: reset\n")); | ||
return Z_OK; | ||
} | ||
function inflateReset(strm) { | ||
var state; | ||
if (!strm || !strm.state) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
@@ -376,15 +221,13 @@ state.wsize = 0; | ||
} | ||
function inflateReset2(strm, windowBits) { | ||
var wrap; | ||
var state; | ||
/* get the state */ | ||
if (!strm || !strm.state) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
state = strm.state; | ||
/* extract wrap request from windowBits parameter */ | ||
if (windowBits < 0) { | ||
@@ -395,3 +238,2 @@ wrap = 0; | ||
wrap = (windowBits >> 4) + 1; | ||
if (windowBits < 48) { | ||
@@ -401,15 +243,12 @@ windowBits &= 15; | ||
} | ||
/* set number of window bits, free window if different */ | ||
if (windowBits && (windowBits < 8 || windowBits > 15)) { | ||
return Z_STREAM_ERROR; | ||
} | ||
if (state.window !== null && state.wbits !== windowBits) { | ||
state.window = null; | ||
} | ||
/* update state and reset the rest of it */ | ||
state.wrap = wrap; | ||
@@ -419,25 +258,19 @@ state.wbits = windowBits; | ||
} | ||
function inflateInit2(strm, windowBits) { | ||
var ret; | ||
var state; | ||
if (!strm) { | ||
return Z_STREAM_ERROR; | ||
} //strm.msg = Z_NULL; /* in case we return an error */ | ||
} | ||
//strm.msg = Z_NULL; /* in case we return an error */ | ||
state = new InflateState(); | ||
state = new InflateState(); //if (state === Z_NULL) return Z_MEM_ERROR; | ||
//if (state === Z_NULL) return Z_MEM_ERROR; | ||
//Tracev((stderr, "inflate: allocated\n")); | ||
strm.state = state; | ||
state.window = null | ||
/*Z_NULL*/ | ||
; | ||
state.window = null /*Z_NULL*/; | ||
ret = inflateReset2(strm, windowBits); | ||
if (ret !== Z_OK) { | ||
strm.state = null | ||
/*Z_NULL*/ | ||
; | ||
strm.state = null /*Z_NULL*/; | ||
} | ||
@@ -447,6 +280,6 @@ | ||
} | ||
function inflateInit(strm) { | ||
return inflateInit2(strm, DEF_WBITS); | ||
} | ||
/* | ||
@@ -462,4 +295,2 @@ Return state with length and distance decoding tables and index sizes set to | ||
*/ | ||
var virgin = true; | ||
@@ -474,41 +305,33 @@ var lenfix, distfix; // We have no pointers in JS, so keep tables separate | ||
distfix = new utils.Buf32(32); | ||
/* literal/length table */ | ||
sym = 0; | ||
while (sym < 144) { | ||
state.lens[sym++] = 8; | ||
} | ||
while (sym < 256) { | ||
state.lens[sym++] = 9; | ||
} | ||
while (sym < 280) { | ||
state.lens[sym++] = 7; | ||
} | ||
while (sym < 288) { | ||
state.lens[sym++] = 8; | ||
} | ||
(0, _inftrees["default"])(LENS, state.lens, 0, 288, lenfix, 0, state.work, { | ||
bits: 9 | ||
}); | ||
/* distance table */ | ||
sym = 0; | ||
while (sym < 32) { | ||
state.lens[sym++] = 5; | ||
} | ||
(0, _inftrees["default"])(DISTS, state.lens, 0, 32, distfix, 0, state.work, { | ||
bits: 5 | ||
}); | ||
/* do this just once */ | ||
virgin = false; | ||
} | ||
state.lencode = lenfix; | ||
@@ -519,2 +342,3 @@ state.lenbits = 9; | ||
} | ||
/* | ||
@@ -534,9 +358,7 @@ Update the window with the last wsize (normally 32K) bytes written before | ||
*/ | ||
function updatewindow(strm, src, end, copy) { | ||
var dist; | ||
var state = strm.state; | ||
/* if it hasn't been done already, allocate space for the window */ | ||
if (state.window === null) { | ||
@@ -548,5 +370,4 @@ state.wsize = 1 << state.wbits; | ||
} | ||
/* copy state->wsize or less output bytes into the circular window */ | ||
if (copy >= state.wsize) { | ||
@@ -558,11 +379,8 @@ utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0); | ||
dist = state.wsize - state.wnext; | ||
if (dist > copy) { | ||
dist = copy; | ||
} //zmemcpy(state->window + state->wnext, end - copy, dist); | ||
} | ||
//zmemcpy(state->window + state->wnext, end - copy, dist); | ||
utils.arraySet(state.window, src, end - copy, dist, state.wnext); | ||
copy -= dist; | ||
if (copy) { | ||
@@ -575,7 +393,5 @@ //zmemcpy(state->window, end - copy, copy); | ||
state.wnext += dist; | ||
if (state.wnext === state.wsize) { | ||
state.wnext = 0; | ||
} | ||
if (state.whave < state.wsize) { | ||
@@ -586,73 +402,37 @@ state.whave += dist; | ||
} | ||
return 0; | ||
} | ||
function inflate(strm, flush) { | ||
var state; | ||
var input, output; // input/output buffers | ||
var next; | ||
/* next input INDEX */ | ||
var put; | ||
/* next output INDEX */ | ||
var have, left; | ||
/* available input and output */ | ||
var hold; | ||
/* bit buffer */ | ||
var bits; | ||
/* bits in bit buffer */ | ||
var _in, _out; | ||
/* save starting available input and output */ | ||
var copy; | ||
/* number of stored or match bytes to copy */ | ||
var from; | ||
/* where to copy match bytes from */ | ||
var next; /* next input INDEX */ | ||
var put; /* next output INDEX */ | ||
var have, left; /* available input and output */ | ||
var hold; /* bit buffer */ | ||
var bits; /* bits in bit buffer */ | ||
var _in, _out; /* save starting available input and output */ | ||
var copy; /* number of stored or match bytes to copy */ | ||
var from; /* where to copy match bytes from */ | ||
var from_source; | ||
var here = 0; | ||
/* current decoding table entry */ | ||
var here = 0; /* current decoding table entry */ | ||
var here_bits, here_op, here_val; // paked "here" denormalized (JS specific) | ||
//var last; /* parent table entry */ | ||
var last_bits, last_op, last_val; // paked "last" denormalized (JS specific) | ||
var len; | ||
/* length to copy for repeats, bits to drop */ | ||
var ret; | ||
/* return code */ | ||
var hbuf = new utils.Buf8(4); | ||
/* buffer for gzip header crc calculation */ | ||
var len; /* length to copy for repeats, bits to drop */ | ||
var ret; /* return code */ | ||
var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */ | ||
var opts; | ||
var n; // temporary var for NEED_BITS | ||
var order = | ||
/* permutation of code lengths */ | ||
var order = /* permutation of code lengths */ | ||
[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
if (!strm || !strm.state || !strm.output || !strm.input && strm.avail_in !== 0) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
if (state.mode === TYPE) { | ||
state.mode = TYPEDO; | ||
} | ||
/* skip check */ | ||
} /* skip check */ | ||
//--- LOAD() --- | ||
put = strm.next_out; | ||
@@ -665,3 +445,4 @@ output = strm.output; | ||
hold = state.hold; | ||
bits = state.bits; //--- | ||
bits = state.bits; | ||
//--- | ||
@@ -671,4 +452,4 @@ _in = have; | ||
ret = Z_OK; | ||
inf_leave: // goto emulation | ||
inf_leave: | ||
// goto emulation | ||
for (;;) { | ||
@@ -680,5 +461,4 @@ switch (state.mode) { | ||
break; | ||
} //=== NEEDBITS(16); | ||
} | ||
//=== NEEDBITS(16); | ||
while (bits < 16) { | ||
@@ -688,39 +468,29 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if (state.wrap & 2 && hold === 0x8b1f) { | ||
/* gzip header */ | ||
state.check = 0 | ||
/*crc32(0L, Z_NULL, 0)*/ | ||
; //=== CRC2(state.check, hold); | ||
state.check = 0 /*crc32(0L, Z_NULL, 0)*/; | ||
//=== CRC2(state.check, hold); | ||
hbuf[0] = hold & 0xff; | ||
hbuf[1] = hold >>> 8 & 0xff; | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); //===// | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); | ||
//===// | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = FLAGS; | ||
break; | ||
} | ||
state.flags = 0; | ||
/* expect zlib header */ | ||
state.flags = 0; /* expect zlib header */ | ||
if (state.head) { | ||
state.head.done = false; | ||
} | ||
if (!(state.wrap & 1) || | ||
/* check if zlib header allowed */ | ||
(((hold & 0xff | ||
/*BITS(8)*/ | ||
) << 8) + (hold >> 8)) % 31) { | ||
if (!(state.wrap & 1) || /* check if zlib header allowed */ | ||
(((hold & 0xff /*BITS(8)*/) << 8) + (hold >> 8)) % 31) { | ||
strm.msg = 'incorrect header check'; | ||
@@ -730,19 +500,12 @@ state.mode = BAD; | ||
} | ||
if ((hold & 0x0f | ||
/*BITS(4)*/ | ||
) !== Z_DEFLATED) { | ||
if ((hold & 0x0f /*BITS(4)*/) !== Z_DEFLATED) { | ||
strm.msg = 'unknown compression method'; | ||
state.mode = BAD; | ||
break; | ||
} //--- DROPBITS(4) ---// | ||
} | ||
//--- DROPBITS(4) ---// | ||
hold >>>= 4; | ||
bits -= 4; //---// | ||
len = (hold & 0x0f | ||
/*BITS(4)*/ | ||
) + 8; | ||
bits -= 4; | ||
//---// | ||
len = (hold & 0x0f /*BITS(4)*/) + 8; | ||
if (state.wbits === 0) { | ||
@@ -755,15 +518,11 @@ state.wbits = len; | ||
} | ||
state.dmax = 1 << len; //Tracev((stderr, "inflate: zlib header ok\n")); | ||
strm.adler = state.check = 1 | ||
/*adler32(0L, Z_NULL, 0)*/ | ||
; | ||
state.mode = hold & 0x200 ? DICTID : TYPE; //=== INITBITS(); | ||
state.dmax = 1 << len; | ||
//Tracev((stderr, "inflate: zlib header ok\n")); | ||
strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/; | ||
state.mode = hold & 0x200 ? DICTID : TYPE; | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
break; | ||
case FLAGS: | ||
@@ -775,11 +534,8 @@ //=== NEEDBITS(16); */ | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
state.flags = hold; | ||
if ((state.flags & 0xff) !== Z_DEFLATED) { | ||
@@ -790,3 +546,2 @@ strm.msg = 'unknown compression method'; | ||
} | ||
if (state.flags & 0xe000) { | ||
@@ -797,7 +552,5 @@ strm.msg = 'unknown header flags set'; | ||
} | ||
if (state.head) { | ||
state.head.text = hold >> 8 & 1; | ||
} | ||
if (state.flags & 0x0200) { | ||
@@ -807,13 +560,11 @@ //=== CRC2(state.check, hold); | ||
hbuf[1] = hold >>> 8 & 0xff; | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); //===// | ||
} //=== INITBITS(); | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); | ||
//===// | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = TIME; | ||
/* falls through */ | ||
case TIME: | ||
@@ -825,13 +576,10 @@ //=== NEEDBITS(32); */ | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if (state.head) { | ||
state.head.time = hold; | ||
} | ||
if (state.flags & 0x0200) { | ||
@@ -843,13 +591,11 @@ //=== CRC4(state.check, hold) | ||
hbuf[3] = hold >>> 24 & 0xff; | ||
state.check = (0, _crc["default"])(state.check, hbuf, 4, 0); //=== | ||
} //=== INITBITS(); | ||
state.check = (0, _crc["default"])(state.check, hbuf, 4, 0); | ||
//=== | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = OS; | ||
/* falls through */ | ||
case OS: | ||
@@ -861,9 +607,7 @@ //=== NEEDBITS(16); */ | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if (state.head) { | ||
@@ -873,3 +617,2 @@ state.head.xflags = hold & 0xff; | ||
} | ||
if (state.flags & 0x0200) { | ||
@@ -879,13 +622,11 @@ //=== CRC2(state.check, hold); | ||
hbuf[1] = hold >>> 8 & 0xff; | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); //===// | ||
} //=== INITBITS(); | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); | ||
//===// | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = EXLEN; | ||
/* falls through */ | ||
case EXLEN: | ||
@@ -898,15 +639,11 @@ if (state.flags & 0x0400) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
state.length = hold; | ||
if (state.head) { | ||
state.head.extra_len = hold; | ||
} | ||
if (state.flags & 0x0200) { | ||
@@ -916,30 +653,24 @@ //=== CRC2(state.check, hold); | ||
hbuf[1] = hold >>> 8 & 0xff; | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); //===// | ||
} //=== INITBITS(); | ||
state.check = (0, _crc["default"])(state.check, hbuf, 2, 0); | ||
//===// | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
} else if (state.head) { | ||
state.head.extra = null | ||
/*Z_NULL*/ | ||
; | ||
state.head.extra = null /*Z_NULL*/; | ||
} | ||
state.mode = EXTRA; | ||
/* falls through */ | ||
case EXTRA: | ||
if (state.flags & 0x0400) { | ||
copy = state.length; | ||
if (copy > have) { | ||
copy = have; | ||
} | ||
if (copy) { | ||
if (state.head) { | ||
len = state.head.extra_len - state.length; | ||
if (!state.head.extra) { | ||
@@ -949,8 +680,8 @@ // Use untyped array for more conveniend processing later | ||
} | ||
utils.arraySet(state.head.extra, input, next, // extra field is limited to 65536 bytes | ||
utils.arraySet(state.head.extra, input, next, | ||
// extra field is limited to 65536 bytes | ||
// - no need for additional size check | ||
copy, | ||
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/ | ||
len); //zmemcpy(state.head.extra + len, next, | ||
copy, /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/ | ||
len); | ||
//zmemcpy(state.head.extra + len, next, | ||
// len + copy > state.head.extra_max ? | ||
@@ -963,3 +694,2 @@ // state.head.extra_max - len : copy); | ||
} | ||
have -= copy; | ||
@@ -969,3 +699,2 @@ next += copy; | ||
} | ||
if (state.length) { | ||
@@ -975,8 +704,5 @@ break inf_leave; | ||
} | ||
state.length = 0; | ||
state.mode = NAME; | ||
/* falls through */ | ||
case NAME: | ||
@@ -987,5 +713,3 @@ if (state.flags & 0x0800) { | ||
} | ||
copy = 0; | ||
do { | ||
@@ -995,17 +719,11 @@ // TODO: 2 or 1 bytes? | ||
/* use constant limit because in js we should not preallocate memory */ | ||
if (state.head && len && state.length < 65536 | ||
/*state.head.name_max*/ | ||
) { | ||
if (state.head && len && state.length < 65536 /*state.head.name_max*/) { | ||
state.head.name += String.fromCharCode(len); | ||
} | ||
} while (len && copy < have); | ||
if (state.flags & 0x0200) { | ||
state.check = (0, _crc["default"])(state.check, input, copy, next); | ||
} | ||
have -= copy; | ||
next += copy; | ||
if (len) { | ||
@@ -1017,8 +735,5 @@ break inf_leave; | ||
} | ||
state.length = 0; | ||
state.mode = COMMENT; | ||
/* falls through */ | ||
case COMMENT: | ||
@@ -1029,23 +744,15 @@ if (state.flags & 0x1000) { | ||
} | ||
copy = 0; | ||
do { | ||
len = input[next + copy++]; | ||
/* use constant limit because in js we should not preallocate memory */ | ||
if (state.head && len && state.length < 65536 | ||
/*state.head.comm_max*/ | ||
) { | ||
if (state.head && len && state.length < 65536 /*state.head.comm_max*/) { | ||
state.head.comment += String.fromCharCode(len); | ||
} | ||
} while (len && copy < have); | ||
if (state.flags & 0x0200) { | ||
state.check = (0, _crc["default"])(state.check, input, copy, next); | ||
} | ||
have -= copy; | ||
next += copy; | ||
if (len) { | ||
@@ -1057,7 +764,4 @@ break inf_leave; | ||
} | ||
state.mode = HCRC; | ||
/* falls through */ | ||
case HCRC: | ||
@@ -1070,9 +774,7 @@ if (state.flags & 0x0200) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if (hold !== (state.check & 0xffff)) { | ||
@@ -1082,7 +784,7 @@ strm.msg = 'header crc mismatch'; | ||
break; | ||
} //=== INITBITS(); | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
} | ||
@@ -1094,7 +796,5 @@ | ||
} | ||
strm.adler = state.check = 0; | ||
state.mode = TYPE; | ||
break; | ||
case DICTID: | ||
@@ -1106,18 +806,14 @@ //=== NEEDBITS(32); */ | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
strm.adler = state.check = zswap32(hold); //=== INITBITS(); | ||
} | ||
//===// | ||
strm.adler = state.check = zswap32(hold); | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = DICT; | ||
/* falls through */ | ||
case DICT: | ||
@@ -1131,14 +827,9 @@ if (state.havedict === 0) { | ||
state.hold = hold; | ||
state.bits = bits; //--- | ||
state.bits = bits; | ||
//--- | ||
return Z_NEED_DICT; | ||
} | ||
strm.adler = state.check = 1 | ||
/*adler32(0L, Z_NULL, 0)*/ | ||
; | ||
strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/; | ||
state.mode = TYPE; | ||
/* falls through */ | ||
case TYPE: | ||
@@ -1148,5 +839,3 @@ if (flush === Z_BLOCK || flush === Z_TREES) { | ||
} | ||
/* falls through */ | ||
case TYPEDO: | ||
@@ -1156,9 +845,8 @@ if (state.last) { | ||
hold >>>= bits & 7; | ||
bits -= bits & 7; //---// | ||
bits -= bits & 7; | ||
//---// | ||
state.mode = CHECK; | ||
break; | ||
} //=== NEEDBITS(3); */ | ||
} | ||
//=== NEEDBITS(3); */ | ||
while (bits < 3) { | ||
@@ -1168,19 +856,14 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
state.last = hold & 0x01 | ||
/*BITS(1)*/ | ||
; //--- DROPBITS(1) ---// | ||
} | ||
//===// | ||
state.last = hold & 0x01 /*BITS(1)*/; | ||
//--- DROPBITS(1) ---// | ||
hold >>>= 1; | ||
bits -= 1; //---// | ||
bits -= 1; | ||
//---// | ||
switch (hold & 0x03 | ||
/*BITS(2)*/ | ||
) { | ||
switch (hold & 0x03 /*BITS(2)*/) { | ||
case 0: | ||
@@ -1192,21 +875,16 @@ /* stored block */ | ||
break; | ||
case 1: | ||
/* fixed block */ | ||
fixedtables(state); //Tracev((stderr, "inflate: fixed codes block%s\n", | ||
fixedtables(state); | ||
//Tracev((stderr, "inflate: fixed codes block%s\n", | ||
// state.last ? " (last)" : "")); | ||
state.mode = LEN_; | ||
/* decode codes */ | ||
state.mode = LEN_; /* decode codes */ | ||
if (flush === Z_TREES) { | ||
//--- DROPBITS(2) ---// | ||
hold >>>= 2; | ||
bits -= 2; //---// | ||
bits -= 2; | ||
//---// | ||
break inf_leave; | ||
} | ||
break; | ||
case 2: | ||
@@ -1218,20 +896,17 @@ /* dynamic block */ | ||
break; | ||
case 3: | ||
strm.msg = 'invalid block type'; | ||
state.mode = BAD; | ||
} //--- DROPBITS(2) ---// | ||
} | ||
//--- DROPBITS(2) ---// | ||
hold >>>= 2; | ||
bits -= 2; //---// | ||
bits -= 2; | ||
//---// | ||
break; | ||
case STORED: | ||
//--- BYTEBITS() ---// /* go to byte boundary */ | ||
hold >>>= bits & 7; | ||
bits -= bits & 7; //---// | ||
bits -= bits & 7; | ||
//---// | ||
//=== NEEDBITS(32); */ | ||
while (bits < 32) { | ||
@@ -1241,9 +916,7 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if ((hold & 0xffff) !== (hold >>> 16 ^ 0xffff)) { | ||
@@ -1254,26 +927,19 @@ strm.msg = 'invalid stored block lengths'; | ||
} | ||
state.length = hold & 0xffff; //Tracev((stderr, "inflate: stored length %u\n", | ||
state.length = hold & 0xffff; | ||
//Tracev((stderr, "inflate: stored length %u\n", | ||
// state.length)); | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
state.mode = COPY_; | ||
if (flush === Z_TREES) { | ||
break inf_leave; | ||
} | ||
/* falls through */ | ||
case COPY_: | ||
state.mode = COPY; | ||
/* falls through */ | ||
case COPY: | ||
copy = state.length; | ||
if (copy) { | ||
@@ -1283,14 +949,11 @@ if (copy > have) { | ||
} | ||
if (copy > left) { | ||
copy = left; | ||
} | ||
if (copy === 0) { | ||
break inf_leave; | ||
} //--- zmemcpy(put, next, copy); --- | ||
utils.arraySet(output, input, next, copy, put); //---// | ||
} | ||
//--- zmemcpy(put, next, copy); --- | ||
utils.arraySet(output, input, next, copy, put); | ||
//---// | ||
have -= copy; | ||
@@ -1302,8 +965,6 @@ next += copy; | ||
break; | ||
} //Tracev((stderr, "inflate: stored end\n")); | ||
} | ||
//Tracev((stderr, "inflate: stored end\n")); | ||
state.mode = TYPE; | ||
break; | ||
case TABLE: | ||
@@ -1315,31 +976,23 @@ //=== NEEDBITS(14); */ | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
state.nlen = (hold & 0x1f | ||
/*BITS(5)*/ | ||
) + 257; //--- DROPBITS(5) ---// | ||
} | ||
//===// | ||
state.nlen = (hold & 0x1f /*BITS(5)*/) + 257; | ||
//--- DROPBITS(5) ---// | ||
hold >>>= 5; | ||
bits -= 5; //---// | ||
state.ndist = (hold & 0x1f | ||
/*BITS(5)*/ | ||
) + 1; //--- DROPBITS(5) ---// | ||
bits -= 5; | ||
//---// | ||
state.ndist = (hold & 0x1f /*BITS(5)*/) + 1; | ||
//--- DROPBITS(5) ---// | ||
hold >>>= 5; | ||
bits -= 5; //---// | ||
state.ncode = (hold & 0x0f | ||
/*BITS(4)*/ | ||
) + 4; //--- DROPBITS(4) ---// | ||
bits -= 5; | ||
//---// | ||
state.ncode = (hold & 0x0f /*BITS(4)*/) + 4; | ||
//--- DROPBITS(4) ---// | ||
hold >>>= 4; | ||
bits -= 4; //---// | ||
bits -= 4; | ||
//---// | ||
//#ifndef PKZIP_BUG_WORKAROUND | ||
if (state.nlen > 286 || state.ndist > 30) { | ||
@@ -1349,11 +1002,8 @@ strm.msg = 'too many length or distance symbols'; | ||
break; | ||
} //#endif | ||
} | ||
//#endif | ||
//Tracev((stderr, "inflate: table sizes ok\n")); | ||
state.have = 0; | ||
state.mode = LENLENS; | ||
/* falls through */ | ||
case LENLENS: | ||
@@ -1366,14 +1016,12 @@ while (state.have < state.ncode) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
state.lens[order[state.have++]] = hold & 0x07; //BITS(3); | ||
//--- DROPBITS(3) ---// | ||
hold >>>= 3; | ||
bits -= 3; //---// | ||
bits -= 3; | ||
//---// | ||
} | ||
@@ -1383,8 +1031,7 @@ | ||
state.lens[order[state.have++]] = 0; | ||
} // We have separate tables & no pointers. 2 commented lines below not needed. | ||
} | ||
// We have separate tables & no pointers. 2 commented lines below not needed. | ||
//state.next = state.codes; | ||
//state.lencode = state.next; | ||
// Switch to use dynamic table | ||
state.lencode = state.lendyn; | ||
@@ -1397,3 +1044,2 @@ state.lenbits = 7; | ||
state.lenbits = opts.bits; | ||
if (ret) { | ||
@@ -1403,32 +1049,25 @@ strm.msg = 'invalid code lengths set'; | ||
break; | ||
} //Tracev((stderr, "inflate: code lengths ok\n")); | ||
} | ||
//Tracev((stderr, "inflate: code lengths ok\n")); | ||
state.have = 0; | ||
state.mode = CODELENS; | ||
/* falls through */ | ||
case CODELENS: | ||
while (state.have < state.nlen + state.ndist) { | ||
for (;;) { | ||
here = state.lencode[hold & (1 << state.lenbits) - 1]; | ||
/*BITS(state.lenbits)*/ | ||
here = state.lencode[hold & (1 << state.lenbits) - 1]; /*BITS(state.lenbits)*/ | ||
here_bits = here >>> 24; | ||
here_op = here >>> 16 & 0xff; | ||
here_val = here & 0xffff; | ||
if (here_bits <= bits) { | ||
break; | ||
} //--- PULLBYTE() ---// | ||
} | ||
//--- PULLBYTE() ---// | ||
if (have === 0) { | ||
break inf_leave; | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; //---// | ||
bits += 8; | ||
//---// | ||
} | ||
@@ -1439,4 +1078,4 @@ | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
state.lens[state.have++] = here_val; | ||
@@ -1447,3 +1086,2 @@ } else { | ||
n = here_bits + 2; | ||
while (bits < n) { | ||
@@ -1453,13 +1091,11 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
//--- DROPBITS(here.bits) ---// | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
if (state.have === 0) { | ||
@@ -1470,13 +1106,11 @@ strm.msg = 'invalid bit length repeat'; | ||
} | ||
len = state.lens[state.have - 1]; | ||
copy = 3 + (hold & 0x03); //BITS(2); | ||
//--- DROPBITS(2) ---// | ||
hold >>>= 2; | ||
bits -= 2; //---// | ||
bits -= 2; | ||
//---// | ||
} else if (here_val === 17) { | ||
//=== NEEDBITS(here.bits + 3); | ||
n = here_bits + 3; | ||
while (bits < n) { | ||
@@ -1486,23 +1120,20 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
//--- DROPBITS(here.bits) ---// | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
len = 0; | ||
copy = 3 + (hold & 0x07); //BITS(3); | ||
//--- DROPBITS(3) ---// | ||
hold >>>= 3; | ||
bits -= 3; //---// | ||
bits -= 3; | ||
//---// | ||
} else { | ||
//=== NEEDBITS(here.bits + 7); | ||
n = here_bits + 7; | ||
while (bits < n) { | ||
@@ -1512,19 +1143,17 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
//--- DROPBITS(here.bits) ---// | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
len = 0; | ||
copy = 11 + (hold & 0x7f); //BITS(7); | ||
//--- DROPBITS(7) ---// | ||
hold >>>= 7; | ||
bits -= 7; //---// | ||
bits -= 7; | ||
//---// | ||
} | ||
@@ -1537,3 +1166,2 @@ | ||
} | ||
while (copy--) { | ||
@@ -1544,11 +1172,9 @@ state.lens[state.have++] = len; | ||
} | ||
/* handle error breaks in while */ | ||
if (state.mode === BAD) { | ||
break; | ||
} | ||
/* check for end-of-block code (better have one) */ | ||
if (state.lens[256] === 0) { | ||
@@ -1559,7 +1185,6 @@ strm.msg = 'invalid code -- missing end-of-block'; | ||
} | ||
/* build code tables -- note: do not change the lenbits or distbits | ||
values here (9 and 6) without reading the comments in inftrees.h | ||
concerning the ENOUGH constants, which depend on those values */ | ||
state.lenbits = 9; | ||
@@ -1569,7 +1194,8 @@ opts = { | ||
}; | ||
ret = (0, _inftrees["default"])(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts); // We have separate tables & no pointers. 2 commented lines below not needed. | ||
ret = (0, _inftrees["default"])(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts); | ||
// We have separate tables & no pointers. 2 commented lines below not needed. | ||
// state.next_index = opts.table_index; | ||
state.lenbits = opts.bits; | ||
// state.lencode = state.next; | ||
state.lenbits = opts.bits; // state.lencode = state.next; | ||
if (ret) { | ||
@@ -1580,6 +1206,5 @@ strm.msg = 'invalid literal/lengths set'; | ||
} | ||
state.distbits = 6; //state.distcode.copy(state.codes); | ||
state.distbits = 6; | ||
//state.distcode.copy(state.codes); | ||
// Switch to use dynamic table | ||
state.distcode = state.distdyn; | ||
@@ -1589,7 +1214,8 @@ opts = { | ||
}; | ||
ret = (0, _inftrees["default"])(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts); // We have separate tables & no pointers. 2 commented lines below not needed. | ||
ret = (0, _inftrees["default"])(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts); | ||
// We have separate tables & no pointers. 2 commented lines below not needed. | ||
// state.next_index = opts.table_index; | ||
state.distbits = opts.bits; | ||
// state.distcode = state.next; | ||
state.distbits = opts.bits; // state.distcode = state.next; | ||
if (ret) { | ||
@@ -1599,18 +1225,12 @@ strm.msg = 'invalid distances set'; | ||
break; | ||
} //Tracev((stderr, 'inflate: codes ok\n')); | ||
} | ||
//Tracev((stderr, 'inflate: codes ok\n')); | ||
state.mode = LEN_; | ||
if (flush === Z_TREES) { | ||
break inf_leave; | ||
} | ||
/* falls through */ | ||
case LEN_: | ||
state.mode = LEN; | ||
/* falls through */ | ||
case LEN: | ||
@@ -1624,6 +1244,6 @@ if (have >= 6 && left >= 258) { | ||
state.hold = hold; | ||
state.bits = bits; //--- | ||
(0, _inffast["default"])(strm, _out); //--- LOAD() --- | ||
state.bits = bits; | ||
//--- | ||
(0, _inffast["default"])(strm, _out); | ||
//--- LOAD() --- | ||
put = strm.next_out; | ||
@@ -1636,3 +1256,4 @@ output = strm.output; | ||
hold = state.hold; | ||
bits = state.bits; //--- | ||
bits = state.bits; | ||
//--- | ||
@@ -1642,28 +1263,21 @@ if (state.mode === TYPE) { | ||
} | ||
break; | ||
} | ||
state.back = 0; | ||
for (;;) { | ||
here = state.lencode[hold & (1 << state.lenbits) - 1]; | ||
/*BITS(state.lenbits)*/ | ||
here = state.lencode[hold & (1 << state.lenbits) - 1]; /*BITS(state.lenbits)*/ | ||
here_bits = here >>> 24; | ||
here_op = here >>> 16 & 0xff; | ||
here_val = here & 0xffff; | ||
if (here_bits <= bits) { | ||
break; | ||
} //--- PULLBYTE() ---// | ||
} | ||
//--- PULLBYTE() ---// | ||
if (have === 0) { | ||
break inf_leave; | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; //---// | ||
bits += 8; | ||
//---// | ||
} | ||
@@ -1675,39 +1289,31 @@ | ||
last_val = here_val; | ||
for (;;) { | ||
here = state.lencode[last_val + ((hold & (1 << last_bits + last_op) - 1 | ||
/*BITS(last.bits + last.op)*/ | ||
) >> last_bits)]; | ||
here = state.lencode[last_val + ((hold & (1 << last_bits + last_op) - 1 /*BITS(last.bits + last.op)*/) >> last_bits)]; | ||
here_bits = here >>> 24; | ||
here_op = here >>> 16 & 0xff; | ||
here_val = here & 0xffff; | ||
if (last_bits + here_bits <= bits) { | ||
break; | ||
} //--- PULLBYTE() ---// | ||
} | ||
//--- PULLBYTE() ---// | ||
if (have === 0) { | ||
break inf_leave; | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; //---// | ||
} //--- DROPBITS(last.bits) ---// | ||
bits += 8; | ||
//---// | ||
} | ||
//--- DROPBITS(last.bits) ---// | ||
hold >>>= last_bits; | ||
bits -= last_bits; //---// | ||
bits -= last_bits; | ||
//---// | ||
state.back += last_bits; | ||
} //--- DROPBITS(here.bits) ---// | ||
} | ||
//--- DROPBITS(here.bits) ---// | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
state.back += here_bits; | ||
state.length = here_val; | ||
if (here_op === 0) { | ||
@@ -1720,3 +1326,2 @@ //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? | ||
} | ||
if (here_op & 32) { | ||
@@ -1728,3 +1333,2 @@ //Tracevv((stderr, "inflate: end of block\n")); | ||
} | ||
if (here_op & 64) { | ||
@@ -1735,8 +1339,5 @@ strm.msg = 'invalid literal/length code'; | ||
} | ||
state.extra = here_op & 15; | ||
state.mode = LENEXT; | ||
/* falls through */ | ||
case LENEXT: | ||
@@ -1746,3 +1347,2 @@ if (state.extra) { | ||
n = state.extra; | ||
while (bits < n) { | ||
@@ -1752,46 +1352,35 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
state.length += hold & (1 << state.extra) - 1 | ||
/*BITS(state.extra)*/ | ||
; //--- DROPBITS(state.extra) ---// | ||
} | ||
//===// | ||
state.length += hold & (1 << state.extra) - 1 /*BITS(state.extra)*/; | ||
//--- DROPBITS(state.extra) ---// | ||
hold >>>= state.extra; | ||
bits -= state.extra; //---// | ||
bits -= state.extra; | ||
//---// | ||
state.back += state.extra; | ||
} //Tracevv((stderr, "inflate: length %u\n", state.length)); | ||
} | ||
//Tracevv((stderr, "inflate: length %u\n", state.length)); | ||
state.was = state.length; | ||
state.mode = DIST; | ||
/* falls through */ | ||
case DIST: | ||
for (;;) { | ||
here = state.distcode[hold & (1 << state.distbits) - 1]; | ||
/*BITS(state.distbits)*/ | ||
here = state.distcode[hold & (1 << state.distbits) - 1]; /*BITS(state.distbits)*/ | ||
here_bits = here >>> 24; | ||
here_op = here >>> 16 & 0xff; | ||
here_val = here & 0xffff; | ||
if (here_bits <= bits) { | ||
break; | ||
} //--- PULLBYTE() ---// | ||
} | ||
//--- PULLBYTE() ---// | ||
if (have === 0) { | ||
break inf_leave; | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; //---// | ||
bits += 8; | ||
//---// | ||
} | ||
@@ -1803,38 +1392,30 @@ | ||
last_val = here_val; | ||
for (;;) { | ||
here = state.distcode[last_val + ((hold & (1 << last_bits + last_op) - 1 | ||
/*BITS(last.bits + last.op)*/ | ||
) >> last_bits)]; | ||
here = state.distcode[last_val + ((hold & (1 << last_bits + last_op) - 1 /*BITS(last.bits + last.op)*/) >> last_bits)]; | ||
here_bits = here >>> 24; | ||
here_op = here >>> 16 & 0xff; | ||
here_val = here & 0xffff; | ||
if (last_bits + here_bits <= bits) { | ||
break; | ||
} //--- PULLBYTE() ---// | ||
} | ||
//--- PULLBYTE() ---// | ||
if (have === 0) { | ||
break inf_leave; | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; //---// | ||
} //--- DROPBITS(last.bits) ---// | ||
bits += 8; | ||
//---// | ||
} | ||
//--- DROPBITS(last.bits) ---// | ||
hold >>>= last_bits; | ||
bits -= last_bits; //---// | ||
bits -= last_bits; | ||
//---// | ||
state.back += last_bits; | ||
} //--- DROPBITS(here.bits) ---// | ||
} | ||
//--- DROPBITS(here.bits) ---// | ||
hold >>>= here_bits; | ||
bits -= here_bits; //---// | ||
bits -= here_bits; | ||
//---// | ||
state.back += here_bits; | ||
if (here_op & 64) { | ||
@@ -1845,9 +1426,6 @@ strm.msg = 'invalid distance code'; | ||
} | ||
state.offset = here_val; | ||
state.extra = here_op & 15; | ||
state.mode = DISTEXT; | ||
/* falls through */ | ||
case DISTEXT: | ||
@@ -1857,3 +1435,2 @@ if (state.extra) { | ||
n = state.extra; | ||
while (bits < n) { | ||
@@ -1863,20 +1440,15 @@ if (have === 0) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
state.offset += hold & (1 << state.extra) - 1 | ||
/*BITS(state.extra)*/ | ||
; //--- DROPBITS(state.extra) ---// | ||
} | ||
//===// | ||
state.offset += hold & (1 << state.extra) - 1 /*BITS(state.extra)*/; | ||
//--- DROPBITS(state.extra) ---// | ||
hold >>>= state.extra; | ||
bits -= state.extra; //---// | ||
bits -= state.extra; | ||
//---// | ||
state.back += state.extra; | ||
} //#ifdef INFLATE_STRICT | ||
} | ||
//#ifdef INFLATE_STRICT | ||
if (state.offset > state.dmax) { | ||
@@ -1886,10 +1458,7 @@ strm.msg = 'invalid distance too far back'; | ||
break; | ||
} //#endif | ||
} | ||
//#endif | ||
//Tracevv((stderr, "inflate: distance %u\n", state.offset)); | ||
state.mode = MATCH; | ||
/* falls through */ | ||
case MATCH: | ||
@@ -1899,9 +1468,6 @@ if (left === 0) { | ||
} | ||
copy = _out - left; | ||
if (state.offset > copy) { | ||
/* copy from window */ | ||
copy = state.offset - copy; | ||
if (copy > state.whave) { | ||
@@ -1912,3 +1478,4 @@ if (state.sane) { | ||
break; | ||
} // (!) This block is disabled in zlib defailts, | ||
} | ||
// (!) This block is disabled in zlib defailts, | ||
// don't enable it for binary compatibility | ||
@@ -1928,3 +1495,2 @@ //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
//#endif | ||
} | ||
@@ -1938,7 +1504,5 @@ | ||
} | ||
if (copy > state.length) { | ||
copy = state.length; | ||
} | ||
from_source = state.window; | ||
@@ -1951,20 +1515,14 @@ } else { | ||
} | ||
if (copy > left) { | ||
copy = left; | ||
} | ||
left -= copy; | ||
state.length -= copy; | ||
do { | ||
output[put++] = from_source[from++]; | ||
} while (--copy); | ||
if (state.length === 0) { | ||
state.mode = LEN; | ||
} | ||
break; | ||
case LIT: | ||
@@ -1974,3 +1532,2 @@ if (left === 0) { | ||
} | ||
output[put++] = state.length; | ||
@@ -1980,3 +1537,2 @@ left--; | ||
break; | ||
case CHECK: | ||
@@ -1989,22 +1545,17 @@ if (state.wrap) { | ||
} | ||
have--; // Use '|' insdead of '+' to make sure that result is signed | ||
have--; | ||
// Use '|' insdead of '+' to make sure that result is signed | ||
hold |= input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
_out -= left; | ||
strm.total_out += _out; | ||
state.total += _out; | ||
if (_out) { | ||
strm.adler = state.check = | ||
/*UPDATE(state.check, put - _out, _out);*/ | ||
strm.adler = state.check = /*UPDATE(state.check, put - _out, _out);*/ | ||
state.flags ? (0, _crc["default"])(state.check, output, _out, put - _out) : (0, _adler["default"])(state.check, output, _out, put - _out); | ||
} | ||
_out = left; // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too | ||
_out = left; | ||
// NB: crc32 stored as signed 32-bit int, zswap32 returns signed too | ||
if ((state.flags ? hold : zswap32(hold)) !== state.check) { | ||
@@ -2014,7 +1565,7 @@ strm.msg = 'incorrect data check'; | ||
break; | ||
} //=== INITBITS(); | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
//Tracev((stderr, "inflate: check matches trailer\n")); | ||
@@ -2024,5 +1575,3 @@ } | ||
state.mode = LENGTH; | ||
/* falls through */ | ||
case LENGTH: | ||
@@ -2035,9 +1584,7 @@ if (state.wrap && state.flags) { | ||
} | ||
have--; | ||
hold += input[next++] << bits; | ||
bits += 8; | ||
} //===// | ||
} | ||
//===// | ||
if (hold !== (state.total & 0xffffffff)) { | ||
@@ -2047,7 +1594,7 @@ strm.msg = 'incorrect length check'; | ||
break; | ||
} //=== INITBITS(); | ||
} | ||
//=== INITBITS(); | ||
hold = 0; | ||
bits = 0; //===// | ||
bits = 0; | ||
//===// | ||
//Tracev((stderr, "inflate: length matches trailer\n")); | ||
@@ -2057,24 +1604,20 @@ } | ||
state.mode = DONE; | ||
/* falls through */ | ||
case DONE: | ||
ret = Z_STREAM_END; | ||
break inf_leave; | ||
case BAD: | ||
ret = Z_DATA_ERROR; | ||
break inf_leave; | ||
case MEM: | ||
return Z_MEM_ERROR; | ||
case SYNC: | ||
/* falls through */ | ||
default: | ||
return Z_STREAM_ERROR; | ||
} | ||
} // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" | ||
} | ||
// inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" | ||
/* | ||
@@ -2086,5 +1629,4 @@ Return from inflate(), updating the total counts and the check value. | ||
*/ | ||
//--- RESTORE() --- | ||
strm.next_out = put; | ||
@@ -2095,3 +1637,4 @@ strm.avail_out = left; | ||
state.hold = hold; | ||
state.bits = bits; //--- | ||
state.bits = bits; | ||
//--- | ||
@@ -2104,3 +1647,2 @@ if (state.wsize || _out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH)) { | ||
} | ||
_in -= strm.avail_in; | ||
@@ -2111,51 +1653,36 @@ _out -= strm.avail_out; | ||
state.total += _out; | ||
if (state.wrap && _out) { | ||
strm.adler = state.check = | ||
/*UPDATE(state.check, strm.next_out - _out, _out);*/ | ||
strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/ | ||
state.flags ? (0, _crc["default"])(state.check, output, _out, strm.next_out - _out) : (0, _adler["default"])(state.check, output, _out, strm.next_out - _out); | ||
} | ||
strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0); | ||
if ((_in === 0 && _out === 0 || flush === Z_FINISH) && ret === Z_OK) { | ||
ret = Z_BUF_ERROR; | ||
} | ||
return ret; | ||
} | ||
function inflateEnd(strm) { | ||
if (!strm || !strm.state | ||
/*|| strm->zfree == (free_func)0*/ | ||
) { | ||
if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) { | ||
return Z_STREAM_ERROR; | ||
} | ||
var state = strm.state; | ||
if (state.window) { | ||
state.window = null; | ||
} | ||
strm.state = null; | ||
return Z_OK; | ||
} | ||
function inflateGetHeader(strm, head) { | ||
var state; | ||
/* check state */ | ||
if (!strm || !strm.state) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
if ((state.wrap & 2) === 0) { | ||
return Z_STREAM_ERROR; | ||
} | ||
/* save header structure */ | ||
state.head = head; | ||
@@ -2165,3 +1692,2 @@ head.done = false; | ||
} | ||
function inflateSetDictionary(strm, dictionary) { | ||
@@ -2172,28 +1698,17 @@ var dictLength = dictionary.length; | ||
var ret; | ||
/* check state */ | ||
if (!strm | ||
/* == Z_NULL */ | ||
|| !strm.state | ||
/* == Z_NULL */ | ||
) { | ||
if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { | ||
return Z_STREAM_ERROR; | ||
} | ||
state = strm.state; | ||
if (state.wrap !== 0 && state.mode !== DICT) { | ||
return Z_STREAM_ERROR; | ||
} | ||
/* check for correct dictionary identifier */ | ||
if (state.mode === DICT) { | ||
dictid = 1; | ||
/* adler32(0, null, 0)*/ | ||
dictid = 1; /* adler32(0, null, 0)*/ | ||
/* dictid = adler32(dictid, dictionary, dictLength); */ | ||
dictid = (0, _adler["default"])(dictid, dictionary, dictLength, 0); | ||
if (dictid !== state.check) { | ||
@@ -2205,6 +1720,3 @@ return Z_DATA_ERROR; | ||
existing dictionary if appropriate */ | ||
ret = updatewindow(strm, dictionary, dictLength, dictLength); | ||
if (ret) { | ||
@@ -2214,9 +1726,8 @@ state.mode = MEM; | ||
} | ||
state.havedict = 1; // Tracev((stderr, "inflate: dictionary set\n")); | ||
state.havedict = 1; | ||
// Tracev((stderr, "inflate: dictionary set\n")); | ||
return Z_OK; | ||
} | ||
var inflateInfo = 'pako inflate (from Nodeca project)'; | ||
var inflateInfo = 'pako inflate (from Nodeca project)'; | ||
/* Not implemented | ||
@@ -2231,3 +1742,2 @@ exports.inflateCopy = inflateCopy; | ||
*/ | ||
exports.inflateInfo = inflateInfo; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,12 +8,9 @@ value: true | ||
exports["default"] = inflate_table; | ||
var utils = _interopRequireWildcard(require("../utils/common.js")); | ||
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); } | ||
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; } | ||
var MAXBITS = 15; | ||
var ENOUGH_LENS = 852; | ||
var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); | ||
var ENOUGH_DISTS = 592; | ||
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); | ||
@@ -24,76 +20,39 @@ var CODES = 0; | ||
var DISTS = 2; | ||
var lbase = [ | ||
/* Length codes 257..285 base */ | ||
var lbase = [/* Length codes 257..285 base */ | ||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]; | ||
var lext = [ | ||
/* Length codes 257..285 extra */ | ||
var lext = [/* Length codes 257..285 extra */ | ||
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]; | ||
var dbase = [ | ||
/* Distance codes 0..29 base */ | ||
var dbase = [/* Distance codes 0..29 base */ | ||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]; | ||
var dext = [ | ||
/* Distance codes 0..29 extra */ | ||
var dext = [/* Distance codes 0..29 extra */ | ||
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]; | ||
function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) { | ||
var bits = opts.bits; //here = opts.here; /* table entry for duplication */ | ||
var bits = opts.bits; | ||
//here = opts.here; /* table entry for duplication */ | ||
var len = 0; | ||
/* a code's length in bits */ | ||
var sym = 0; | ||
/* index of code symbols */ | ||
var len = 0; /* a code's length in bits */ | ||
var sym = 0; /* index of code symbols */ | ||
var min = 0, | ||
max = 0; | ||
/* minimum and maximum code lengths */ | ||
var root = 0; | ||
/* number of index bits for root table */ | ||
var curr = 0; | ||
/* number of index bits for current table */ | ||
var drop = 0; | ||
/* code bits to drop for sub-table */ | ||
var left = 0; | ||
/* number of prefix codes available */ | ||
var used = 0; | ||
/* code entries in table used */ | ||
var huff = 0; | ||
/* Huffman code */ | ||
var incr; | ||
/* for incrementing code, index */ | ||
var fill; | ||
/* index for replicating entries */ | ||
var low; | ||
/* low bits for current root entry */ | ||
var mask; | ||
/* mask for low root bits */ | ||
var next; | ||
/* next available space in table */ | ||
var base = null; | ||
/* base value table to use */ | ||
var base_index = 0; // var shoextra; /* extra bits table to use */ | ||
var end; | ||
/* use base and extra for symbol > end */ | ||
max = 0; /* minimum and maximum code lengths */ | ||
var root = 0; /* number of index bits for root table */ | ||
var curr = 0; /* number of index bits for current table */ | ||
var drop = 0; /* code bits to drop for sub-table */ | ||
var left = 0; /* number of prefix codes available */ | ||
var used = 0; /* code entries in table used */ | ||
var huff = 0; /* Huffman code */ | ||
var incr; /* for incrementing code, index */ | ||
var fill; /* index for replicating entries */ | ||
var low; /* low bits for current root entry */ | ||
var mask; /* mask for low root bits */ | ||
var next; /* next available space in table */ | ||
var base = null; /* base value table to use */ | ||
var base_index = 0; | ||
// var shoextra; /* extra bits table to use */ | ||
var end; /* use base and extra for symbol > end */ | ||
var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */ | ||
var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */ | ||
var extra = null; | ||
var extra_index = 0; | ||
var here_bits, here_op, here_val; | ||
/* | ||
@@ -128,15 +87,11 @@ Process a set of code lengths to create a canonical Huffman code. The | ||
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ | ||
for (len = 0; len <= MAXBITS; len++) { | ||
count[len] = 0; | ||
} | ||
for (sym = 0; sym < codes; sym++) { | ||
count[lens[lens_index + sym]]++; | ||
} | ||
/* bound code lengths, force root to be within code lengths */ | ||
root = bits; | ||
for (max = MAXBITS; max >= 1; max--) { | ||
@@ -147,7 +102,5 @@ if (count[max] !== 0) { | ||
} | ||
if (root > max) { | ||
root = max; | ||
} | ||
if (max === 0) { | ||
@@ -158,10 +111,10 @@ /* no symbols to code at all */ | ||
//table.val[opts.table_index++] = 0; //here.val = (var short)0; | ||
table[table_index++] = 1 << 24 | 64 << 16 | 0; //table.op[opts.table_index] = 64; | ||
table[table_index++] = 1 << 24 | 64 << 16 | 0; | ||
//table.op[opts.table_index] = 64; | ||
//table.bits[opts.table_index] = 1; | ||
//table.val[opts.table_index++] = 0; | ||
table[table_index++] = 1 << 24 | 64 << 16 | 0; | ||
opts.bits = 1; | ||
return 0; | ||
/* no symbols, but wait for decoding to report error */ | ||
return 0; /* no symbols, but wait for decoding to report error */ | ||
} | ||
@@ -174,37 +127,27 @@ | ||
} | ||
if (root < min) { | ||
root = min; | ||
} | ||
/* check for an over-subscribed or incomplete set of lengths */ | ||
left = 1; | ||
for (len = 1; len <= MAXBITS; len++) { | ||
left <<= 1; | ||
left -= count[len]; | ||
if (left < 0) { | ||
return -1; | ||
} | ||
/* over-subscribed */ | ||
} /* over-subscribed */ | ||
} | ||
if (left > 0 && (type === CODES || max !== 1)) { | ||
return -1; | ||
/* incomplete set */ | ||
return -1; /* incomplete set */ | ||
} | ||
/* generate offsets into symbol table for each length for sorting */ | ||
offs[1] = 0; | ||
for (len = 1; len < MAXBITS; len++) { | ||
offs[len + 1] = offs[len] + count[len]; | ||
} | ||
/* sort symbols by length, by symbol order within each length */ | ||
for (sym = 0; sym < codes; sym++) { | ||
@@ -215,2 +158,3 @@ if (lens[lens_index + sym] !== 0) { | ||
} | ||
/* | ||
@@ -246,8 +190,4 @@ Create and fill in decoding tables. In this loop, the table being | ||
// to avoid deopts in old v8 | ||
if (type === CODES) { | ||
base = extra = work; | ||
/* dummy value--not used */ | ||
base = extra = work; /* dummy value--not used */ | ||
end = 19; | ||
@@ -266,44 +206,23 @@ } else if (type === LENS) { | ||
} | ||
/* initialize opts for loop */ | ||
huff = 0; /* starting code */ | ||
sym = 0; /* starting code symbol */ | ||
len = min; /* starting code length */ | ||
next = table_index; /* current table to fill in */ | ||
curr = root; /* current table index bits */ | ||
drop = 0; /* current bits to drop from code for index */ | ||
low = -1; /* trigger new sub-table when len > root */ | ||
used = 1 << root; /* use root table entries */ | ||
mask = used - 1; /* mask for comparing low */ | ||
huff = 0; | ||
/* starting code */ | ||
sym = 0; | ||
/* starting code symbol */ | ||
len = min; | ||
/* starting code length */ | ||
next = table_index; | ||
/* current table to fill in */ | ||
curr = root; | ||
/* current table index bits */ | ||
drop = 0; | ||
/* current bits to drop from code for index */ | ||
low = -1; | ||
/* trigger new sub-table when len > root */ | ||
used = 1 << root; | ||
/* use root table entries */ | ||
mask = used - 1; | ||
/* mask for comparing low */ | ||
/* check available table space */ | ||
if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) { | ||
return 1; | ||
} | ||
/* process all codes and make table entries */ | ||
for (;;) { | ||
/* create table entry */ | ||
here_bits = len - drop; | ||
if (work[sym] < end) { | ||
@@ -316,15 +235,10 @@ here_op = 0; | ||
} else { | ||
here_op = 32 + 64; | ||
/* end of block */ | ||
here_op = 32 + 64; /* end of block */ | ||
here_val = 0; | ||
} | ||
/* replicate for those indices with low len bits equal to huff */ | ||
incr = 1 << len - drop; | ||
fill = 1 << curr; | ||
min = fill; | ||
/* save offset to next table */ | ||
min = fill; /* save offset to next table */ | ||
do { | ||
@@ -334,11 +248,8 @@ fill -= incr; | ||
} while (fill !== 0); | ||
/* backwards increment the len-bit code huff */ | ||
incr = 1 << len - 1; | ||
while (huff & incr) { | ||
incr >>= 1; | ||
} | ||
if (incr !== 0) { | ||
@@ -350,7 +261,5 @@ huff &= incr - 1; | ||
} | ||
/* go to next symbol, update count, len */ | ||
sym++; | ||
if (--count[len] === 0) { | ||
@@ -360,8 +269,6 @@ if (len === max) { | ||
} | ||
len = lens[lens_index + work[sym]]; | ||
} | ||
/* create new sub-table if needed */ | ||
if (len > root && (huff & mask) !== low) { | ||
@@ -372,34 +279,25 @@ /* if first time, transition to sub-tables */ | ||
} | ||
/* increment past last table */ | ||
next += min; /* here min is 1 << curr */ | ||
next += min; | ||
/* here min is 1 << curr */ | ||
/* determine length of next table */ | ||
curr = len - drop; | ||
left = 1 << curr; | ||
while (curr + drop < max) { | ||
left -= count[curr + drop]; | ||
if (left <= 0) { | ||
break; | ||
} | ||
curr++; | ||
left <<= 1; | ||
} | ||
/* check for enough space */ | ||
used += 1 << curr; | ||
if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) { | ||
return 1; | ||
} | ||
/* point entry in root table to sub-table */ | ||
low = huff & mask; | ||
@@ -409,11 +307,9 @@ /*table.op[low] = curr; | ||
table.val[low] = next - opts.table_index;*/ | ||
table[low] = root << 24 | curr << 16 | next - table_index | 0; | ||
} | ||
} | ||
/* fill in remaining table entry if code is incomplete (guaranteed to have | ||
at most one remaining entry, since if the code is incomplete, the | ||
maximum code length that was allowed to get this far is one bit) */ | ||
if (huff !== 0) { | ||
@@ -425,10 +321,8 @@ //table.op[next + huff] = 64; /* invalid code marker */ | ||
} | ||
/* set return parameters */ | ||
//opts.table_index += used; | ||
opts.bits = root; | ||
return 0; | ||
} | ||
; |
@@ -9,29 +9,19 @@ "use strict"; | ||
2: 'need dictionary', | ||
/* Z_NEED_DICT 2 */ | ||
1: 'stream end', | ||
/* Z_STREAM_END 1 */ | ||
0: '', | ||
/* Z_OK 0 */ | ||
'-1': 'file error', | ||
/* Z_ERRNO (-1) */ | ||
'-2': 'stream error', | ||
/* Z_STREAM_ERROR (-2) */ | ||
'-3': 'data error', | ||
/* Z_DATA_ERROR (-3) */ | ||
'-4': 'insufficient memory', | ||
/* Z_MEM_ERROR (-4) */ | ||
'-5': 'buffer error', | ||
/* Z_BUF_ERROR (-5) */ | ||
'-6': 'incompatible version' | ||
/* Z_VERSION_ERROR (-6) */ | ||
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ | ||
}; | ||
exports["default"] = _default; |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -13,23 +12,20 @@ value: true | ||
exports._tr_tally = _tr_tally; | ||
var utils = _interopRequireWildcard(require("../utils/common.js")); | ||
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); } | ||
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; } | ||
/* Public constants ==========================================================*/ | ||
/* ===========================================================================*/ | ||
/* ===========================================================================*/ | ||
//var Z_FILTERED = 1; | ||
//var Z_HUFFMAN_ONLY = 2; | ||
//var Z_RLE = 3; | ||
var Z_FIXED = 4; //var Z_DEFAULT_STRATEGY = 0; | ||
var Z_FIXED = 4; | ||
//var Z_DEFAULT_STRATEGY = 0; | ||
/* Possible values of the data_type field (though see inflate()) */ | ||
var Z_BINARY = 0; | ||
var Z_TEXT = 1; //var Z_ASCII = 1; // = Z_TEXT | ||
var Z_TEXT = 1; | ||
//var Z_ASCII = 1; // = Z_TEXT | ||
var Z_UNKNOWN = 2; | ||
var Z_UNKNOWN = 2; | ||
/*============================================================================*/ | ||
@@ -39,8 +35,8 @@ | ||
var len = buf.length; | ||
while (--len >= 0) { | ||
buf[len] = 0; | ||
} | ||
} // From zutil.h | ||
} | ||
// From zutil.h | ||
@@ -55,4 +51,4 @@ var STORED_BLOCK = 0; | ||
/* The minimum and maximum match lengths */ | ||
// From deflate.h | ||
/* =========================================================================== | ||
@@ -106,11 +102,7 @@ * Internal compression state. | ||
/* eslint-disable comma-spacing,array-bracket-spacing */ | ||
var extra_lbits = | ||
/* extra bits for each length code */ | ||
var extra_lbits = /* extra bits for each length code */ | ||
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]; | ||
var extra_dbits = | ||
/* extra bits for each distance code */ | ||
var extra_dbits = /* extra bits for each distance code */ | ||
[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; | ||
var extra_blbits = | ||
/* extra bits for each bit length code */ | ||
var extra_blbits = /* extra bits for each bit length code */ | ||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]; | ||
@@ -127,8 +119,8 @@ var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; | ||
*/ | ||
// We pre-fill arrays with 0 to avoid uninitialized gaps | ||
var DIST_CODE_LEN = 512; | ||
/* see definition of array dist_code below */ | ||
var DIST_CODE_LEN = 512; /* see definition of array dist_code below */ | ||
// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1 | ||
var static_ltree = new Array((L_CODES + 2) * 2); | ||
@@ -149,3 +141,2 @@ zero(static_ltree); | ||
var _dist_code = new Array(DIST_CODE_LEN); | ||
zero(_dist_code); | ||
@@ -158,3 +149,2 @@ /* Distance codes. The first 256 values correspond to the distances | ||
var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1); | ||
zero(_length_code); | ||
@@ -172,34 +162,18 @@ /* length code for each normalized match length (0 == MIN_MATCH) */ | ||
function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) { | ||
this.static_tree = static_tree; | ||
/* static tree or NULL */ | ||
this.static_tree = static_tree; /* static tree or NULL */ | ||
this.extra_bits = extra_bits; /* extra bits for each code or NULL */ | ||
this.extra_base = extra_base; /* base index for extra_bits */ | ||
this.elems = elems; /* max number of elements in the tree */ | ||
this.max_length = max_length; /* max bit length for the codes */ | ||
this.extra_bits = extra_bits; | ||
/* extra bits for each code or NULL */ | ||
this.extra_base = extra_base; | ||
/* base index for extra_bits */ | ||
this.elems = elems; | ||
/* max number of elements in the tree */ | ||
this.max_length = max_length; | ||
/* max bit length for the codes */ | ||
// show if `static_tree` has data or dummy - needed for monomorphic objects | ||
this.has_stree = static_tree && static_tree.length; | ||
} | ||
var static_l_desc; | ||
var static_d_desc; | ||
var static_bl_desc; | ||
function TreeDesc(dyn_tree, stat_desc) { | ||
this.dyn_tree = dyn_tree; | ||
/* the dynamic tree */ | ||
this.max_code = 0; | ||
/* largest code with non zero frequency */ | ||
this.stat_desc = stat_desc; | ||
/* the corresponding static tree */ | ||
this.dyn_tree = dyn_tree; /* the dynamic tree */ | ||
this.max_code = 0; /* largest code with non zero frequency */ | ||
this.stat_desc = stat_desc; /* the corresponding static tree */ | ||
} | ||
@@ -210,2 +184,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -215,4 +190,2 @@ * Output a short LSB first on the stream. | ||
*/ | ||
function put_short(s, w) { | ||
@@ -224,2 +197,3 @@ // put_byte(s, (uch)((w) & 0xff)); | ||
} | ||
/* =========================================================================== | ||
@@ -229,4 +203,2 @@ * Send a value on a given number of bits. | ||
*/ | ||
function send_bits(s, value, length) { | ||
@@ -243,10 +215,6 @@ if (s.bi_valid > Buf_size - length) { | ||
} | ||
function send_code(s, c, tree) { | ||
send_bits(s, tree[c * 2] | ||
/*.Code*/ | ||
, tree[c * 2 + 1] | ||
/*.Len*/ | ||
); | ||
send_bits(s, tree[c * 2] /*.Code*/, tree[c * 2 + 1] /*.Len*/); | ||
} | ||
/* =========================================================================== | ||
@@ -257,7 +225,4 @@ * Reverse the first len bits of a code, using straightforward code (a faster | ||
*/ | ||
function bi_reverse(code, len) { | ||
var res = 0; | ||
do { | ||
@@ -268,10 +233,8 @@ res |= code & 1; | ||
} while (--len > 0); | ||
return res >>> 1; | ||
} | ||
/* =========================================================================== | ||
* Flush the bit buffer, keeping at most 7 bits in it. | ||
*/ | ||
function bi_flush(s) { | ||
@@ -288,2 +251,3 @@ if (s.bi_valid === 16) { | ||
} | ||
/* =========================================================================== | ||
@@ -299,5 +263,4 @@ * Compute the optimal bit lengths for a tree and update the total bit length | ||
*/ | ||
function gen_bitlen(s, desc) // deflate_state *s; | ||
function gen_bitlen(s, desc) | ||
// deflate_state *s; | ||
// tree_desc *desc; /* the tree descriptor */ | ||
@@ -312,41 +275,21 @@ { | ||
var max_length = desc.stat_desc.max_length; | ||
var h; | ||
/* heap index */ | ||
var h; /* heap index */ | ||
var n, m; /* iterate over the tree elements */ | ||
var bits; /* bit length */ | ||
var xbits; /* extra bits */ | ||
var f; /* frequency */ | ||
var overflow = 0; /* number of elements with bit length too large */ | ||
var n, m; | ||
/* iterate over the tree elements */ | ||
var bits; | ||
/* bit length */ | ||
var xbits; | ||
/* extra bits */ | ||
var f; | ||
/* frequency */ | ||
var overflow = 0; | ||
/* number of elements with bit length too large */ | ||
for (bits = 0; bits <= MAX_BITS; bits++) { | ||
s.bl_count[bits] = 0; | ||
} | ||
/* In a first pass, compute the optimal bit lengths (which may | ||
* overflow in the case of the bit length tree). | ||
*/ | ||
tree[s.heap[s.heap_max] * 2 + 1] /*.Len*/ = 0; /* root of the heap */ | ||
tree[s.heap[s.heap_max] * 2 + 1] | ||
/*.Len*/ | ||
= 0; | ||
/* root of the heap */ | ||
for (h = s.heap_max + 1; h < HEAP_SIZE; h++) { | ||
n = s.heap[h]; | ||
bits = tree[tree[n * 2 + 1] | ||
/*.Dad*/ | ||
* 2 + 1] | ||
/*.Len*/ | ||
+ 1; | ||
bits = tree[tree[n * 2 + 1] /*.Dad*/ * 2 + 1] /*.Len*/ + 1; | ||
if (bits > max_length) { | ||
@@ -356,6 +299,3 @@ bits = max_length; | ||
} | ||
tree[n * 2 + 1] | ||
/*.Len*/ | ||
= bits; | ||
tree[n * 2 + 1] /*.Len*/ = bits; | ||
/* We overwrite tree[n].Dad which is no longer needed */ | ||
@@ -365,47 +305,30 @@ | ||
continue; | ||
} | ||
/* not a leaf node */ | ||
} /* not a leaf node */ | ||
s.bl_count[bits]++; | ||
xbits = 0; | ||
if (n >= base) { | ||
xbits = extra[n - base]; | ||
} | ||
f = tree[n * 2] | ||
/*.Freq*/ | ||
; | ||
f = tree[n * 2] /*.Freq*/; | ||
s.opt_len += f * (bits + xbits); | ||
if (has_stree) { | ||
s.static_len += f * (stree[n * 2 + 1] | ||
/*.Len*/ | ||
+ xbits); | ||
s.static_len += f * (stree[n * 2 + 1] /*.Len*/ + xbits); | ||
} | ||
} | ||
if (overflow === 0) { | ||
return; | ||
} // Trace((stderr,"\nbit length overflow\n")); | ||
} | ||
// Trace((stderr,"\nbit length overflow\n")); | ||
/* This happens for example on obj2 and pic of the Calgary corpus */ | ||
/* Find the first bit length which could increase: */ | ||
do { | ||
bits = max_length - 1; | ||
while (s.bl_count[bits] === 0) { | ||
bits--; | ||
} | ||
s.bl_count[bits]--; | ||
/* move one leaf down the tree */ | ||
s.bl_count[bits + 1] += 2; | ||
/* move one overflow item as its brother */ | ||
s.bl_count[bits]--; /* move one leaf down the tree */ | ||
s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ | ||
s.bl_count[max_length]--; | ||
@@ -415,5 +338,5 @@ /* The brother of the overflow item also moves one step up, | ||
*/ | ||
overflow -= 2; | ||
} while (overflow > 0); | ||
/* Now recompute all bit lengths, scanning in increasing frequency. | ||
@@ -424,28 +347,14 @@ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all | ||
*/ | ||
for (bits = max_length; bits !== 0; bits--) { | ||
n = s.bl_count[bits]; | ||
while (n !== 0) { | ||
m = s.heap[--h]; | ||
if (m > max_code) { | ||
continue; | ||
} | ||
if (tree[m * 2 + 1] | ||
/*.Len*/ | ||
!== bits) { | ||
if (tree[m * 2 + 1] /*.Len*/ !== bits) { | ||
// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); | ||
s.opt_len += (bits - tree[m * 2 + 1] | ||
/*.Len*/ | ||
) * tree[m * 2] | ||
/*.Freq*/ | ||
; | ||
tree[m * 2 + 1] | ||
/*.Len*/ | ||
= bits; | ||
s.opt_len += (bits - tree[m * 2 + 1] /*.Len*/) * tree[m * 2] /*.Freq*/; | ||
tree[m * 2 + 1] /*.Len*/ = bits; | ||
} | ||
n--; | ||
@@ -455,2 +364,3 @@ } | ||
} | ||
/* =========================================================================== | ||
@@ -464,24 +374,15 @@ * Generate the codes for a given tree and bit counts (which need not be | ||
*/ | ||
function gen_codes(tree, max_code, bl_count) // ct_data *tree; /* the tree to decorate */ | ||
function gen_codes(tree, max_code, bl_count) | ||
// ct_data *tree; /* the tree to decorate */ | ||
// int max_code; /* largest code with non zero frequency */ | ||
// ushf *bl_count; /* number of codes at each bit length */ | ||
{ | ||
var next_code = new Array(MAX_BITS + 1); | ||
/* next code value for each bit length */ | ||
var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */ | ||
var code = 0; /* running code value */ | ||
var bits; /* bit index */ | ||
var n; /* code index */ | ||
var code = 0; | ||
/* running code value */ | ||
var bits; | ||
/* bit index */ | ||
var n; | ||
/* code index */ | ||
/* The distribution counts are first used to generate the code values | ||
* without bit reversal. | ||
*/ | ||
for (bits = 1; bits <= MAX_BITS; bits++) { | ||
@@ -497,8 +398,4 @@ next_code[bits] = code = code + bl_count[bits - 1] << 1; | ||
for (n = 0; n <= max_code; n++) { | ||
var len = tree[n * 2 + 1] | ||
/*.Len*/ | ||
; | ||
var len = tree[n * 2 + 1] /*.Len*/; | ||
if (len === 0) { | ||
@@ -508,33 +405,21 @@ continue; | ||
/* Now reverse the bits */ | ||
tree[n * 2] /*.Code*/ = bi_reverse(next_code[len]++, len); | ||
tree[n * 2] | ||
/*.Code*/ | ||
= bi_reverse(next_code[len]++, len); //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", | ||
//Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", | ||
// n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); | ||
} | ||
} | ||
/* =========================================================================== | ||
* Initialize the various 'constant' tables. | ||
*/ | ||
function tr_static_init() { | ||
var n; | ||
/* iterates over tree elements */ | ||
var bits; | ||
/* bit counter */ | ||
var length; | ||
/* length value */ | ||
var code; | ||
/* code value */ | ||
var dist; | ||
/* distance index */ | ||
var n; /* iterates over tree elements */ | ||
var bits; /* bit counter */ | ||
var length; /* length value */ | ||
var code; /* code value */ | ||
var dist; /* distance index */ | ||
var bl_count = new Array(MAX_BITS + 1); | ||
/* number of codes at each bit length for an optimal tree */ | ||
// do check in _tr_init() | ||
@@ -544,3 +429,2 @@ //if (static_init_done) return; | ||
/* For some embedded targets, global variables are not initialized: */ | ||
/*#ifdef NO_INIT_GLOBAL_POINTERS | ||
@@ -555,13 +439,10 @@ static_l_desc.static_tree = static_ltree; | ||
/* Initialize the mapping length (0..255) -> length code (0..28) */ | ||
length = 0; | ||
for (code = 0; code < LENGTH_CODES - 1; code++) { | ||
base_length[code] = length; | ||
for (n = 0; n < 1 << extra_lbits[code]; n++) { | ||
_length_code[length++] = code; | ||
} | ||
} //Assert (length == 256, "tr_static_init: length != 256"); | ||
} | ||
//Assert (length == 256, "tr_static_init: length != 256"); | ||
/* Note that the length 255 (match length 258) can be represented | ||
@@ -571,66 +452,44 @@ * in two different ways: code 284 + 5 bits or code 285, so we | ||
*/ | ||
_length_code[length - 1] = code; | ||
_length_code[length - 1] = code; | ||
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */ | ||
dist = 0; | ||
for (code = 0; code < 16; code++) { | ||
base_dist[code] = dist; | ||
for (n = 0; n < 1 << extra_dbits[code]; n++) { | ||
_dist_code[dist++] = code; | ||
} | ||
} //Assert (dist == 256, "tr_static_init: dist != 256"); | ||
dist >>= 7; | ||
/* from now on, all distances are divided by 128 */ | ||
} | ||
//Assert (dist == 256, "tr_static_init: dist != 256"); | ||
dist >>= 7; /* from now on, all distances are divided by 128 */ | ||
for (; code < D_CODES; code++) { | ||
base_dist[code] = dist << 7; | ||
for (n = 0; n < 1 << extra_dbits[code] - 7; n++) { | ||
_dist_code[256 + dist++] = code; | ||
} | ||
} //Assert (dist == 256, "tr_static_init: 256+dist != 512"); | ||
} | ||
//Assert (dist == 256, "tr_static_init: 256+dist != 512"); | ||
/* Construct the codes of the static literal tree */ | ||
for (bits = 0; bits <= MAX_BITS; bits++) { | ||
bl_count[bits] = 0; | ||
} | ||
n = 0; | ||
while (n <= 143) { | ||
static_ltree[n * 2 + 1] | ||
/*.Len*/ | ||
= 8; | ||
static_ltree[n * 2 + 1] /*.Len*/ = 8; | ||
n++; | ||
bl_count[8]++; | ||
} | ||
while (n <= 255) { | ||
static_ltree[n * 2 + 1] | ||
/*.Len*/ | ||
= 9; | ||
static_ltree[n * 2 + 1] /*.Len*/ = 9; | ||
n++; | ||
bl_count[9]++; | ||
} | ||
while (n <= 279) { | ||
static_ltree[n * 2 + 1] | ||
/*.Len*/ | ||
= 7; | ||
static_ltree[n * 2 + 1] /*.Len*/ = 7; | ||
n++; | ||
bl_count[7]++; | ||
} | ||
while (n <= 287) { | ||
static_ltree[n * 2 + 1] | ||
/*.Len*/ | ||
= 8; | ||
static_ltree[n * 2 + 1] /*.Len*/ = 8; | ||
n++; | ||
@@ -643,61 +502,42 @@ bl_count[8]++; | ||
*/ | ||
gen_codes(static_ltree, L_CODES + 1, bl_count); | ||
gen_codes(static_ltree, L_CODES + 1, bl_count); | ||
/* The static distance tree is trivial: */ | ||
for (n = 0; n < D_CODES; n++) { | ||
static_dtree[n * 2 + 1] | ||
/*.Len*/ | ||
= 5; | ||
static_dtree[n * 2] | ||
/*.Code*/ | ||
= bi_reverse(n, 5); | ||
} // Now data ready and we can init static trees | ||
static_dtree[n * 2 + 1] /*.Len*/ = 5; | ||
static_dtree[n * 2] /*.Code*/ = bi_reverse(n, 5); | ||
} | ||
// Now data ready and we can init static trees | ||
static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS); | ||
static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS); | ||
static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); //static_init_done = true; | ||
static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); | ||
//static_init_done = true; | ||
} | ||
/* =========================================================================== | ||
* Initialize a new block. | ||
*/ | ||
function init_block(s) { | ||
var n; | ||
/* iterates over tree elements */ | ||
var n; /* iterates over tree elements */ | ||
/* Initialize the trees. */ | ||
for (n = 0; n < L_CODES; n++) { | ||
s.dyn_ltree[n * 2] | ||
/*.Freq*/ | ||
= 0; | ||
s.dyn_ltree[n * 2] /*.Freq*/ = 0; | ||
} | ||
for (n = 0; n < D_CODES; n++) { | ||
s.dyn_dtree[n * 2] | ||
/*.Freq*/ | ||
= 0; | ||
s.dyn_dtree[n * 2] /*.Freq*/ = 0; | ||
} | ||
for (n = 0; n < BL_CODES; n++) { | ||
s.bl_tree[n * 2] | ||
/*.Freq*/ | ||
= 0; | ||
s.bl_tree[n * 2] /*.Freq*/ = 0; | ||
} | ||
s.dyn_ltree[END_BLOCK * 2] | ||
/*.Freq*/ | ||
= 1; | ||
s.dyn_ltree[END_BLOCK * 2] /*.Freq*/ = 1; | ||
s.opt_len = s.static_len = 0; | ||
s.last_lit = s.matches = 0; | ||
} | ||
/* =========================================================================== | ||
* Flush the bit buffer and align the output on a byte boundary | ||
*/ | ||
function bi_windup(s) { | ||
@@ -710,6 +550,6 @@ if (s.bi_valid > 8) { | ||
} | ||
s.bi_buf = 0; | ||
s.bi_valid = 0; | ||
} | ||
/* =========================================================================== | ||
@@ -719,5 +559,4 @@ * Copy a stored block, storing first the length and its | ||
*/ | ||
function copy_block(s, buf, len, header) //DeflateState *s; | ||
function copy_block(s, buf, len, header) | ||
//DeflateState *s; | ||
//charf *buf; /* the input data */ | ||
@@ -727,4 +566,3 @@ //unsigned len; /* its length */ | ||
{ | ||
bi_windup(s); | ||
/* align on byte boundary */ | ||
bi_windup(s); /* align on byte boundary */ | ||
@@ -734,10 +572,10 @@ if (header) { | ||
put_short(s, ~len); | ||
} // while (len--) { | ||
} | ||
// while (len--) { | ||
// put_byte(s, *buf++); | ||
// } | ||
utils.arraySet(s.pending_buf, s.window, buf, len, s.pending); | ||
s.pending += len; | ||
} | ||
/* =========================================================================== | ||
@@ -747,19 +585,8 @@ * Compares to subtrees, using the tree depth as tie breaker when | ||
*/ | ||
function smaller(tree, n, m, depth) { | ||
var _n2 = n * 2; | ||
var _m2 = m * 2; | ||
return tree[_n2] /*.Freq*/ < tree[_m2] /*.Freq*/ || tree[_n2] /*.Freq*/ === tree[_m2] /*.Freq*/ && depth[n] <= depth[m]; | ||
} | ||
return tree[_n2] | ||
/*.Freq*/ | ||
< tree[_m2] | ||
/*.Freq*/ | ||
|| tree[_n2] | ||
/*.Freq*/ | ||
=== tree[_m2] | ||
/*.Freq*/ | ||
&& depth[n] <= depth[m]; | ||
} | ||
/* =========================================================================== | ||
@@ -771,5 +598,4 @@ * Restore the heap property by moving down the tree starting at node k, | ||
*/ | ||
function pqdownheap(s, tree, k) // deflate_state *s; | ||
function pqdownheap(s, tree, k) | ||
// deflate_state *s; | ||
// ct_data *tree; /* the tree to restore */ | ||
@@ -779,5 +605,3 @@ // int k; /* node to move down */ | ||
var v = s.heap[k]; | ||
var j = k << 1; | ||
/* left son of k */ | ||
var j = k << 1; /* left son of k */ | ||
while (j <= s.heap_len) { | ||
@@ -789,19 +613,17 @@ /* Set j to the smallest of the two sons: */ | ||
/* Exit if v is smaller than both sons */ | ||
if (smaller(tree, v, s.heap[j], s.depth)) { | ||
break; | ||
} | ||
/* Exchange v with the smallest son */ | ||
s.heap[k] = s.heap[j]; | ||
k = j; | ||
/* And continue down the tree, setting j to the left son of k */ | ||
j <<= 1; | ||
} | ||
s.heap[k] = v; | ||
} | ||
s.heap[k] = v; | ||
} // inlined manually | ||
// inlined manually | ||
// var SMALLEST = 1; | ||
@@ -812,23 +634,13 @@ | ||
*/ | ||
function compress_block(s, ltree, dtree) // deflate_state *s; | ||
function compress_block(s, ltree, dtree) | ||
// deflate_state *s; | ||
// const ct_data *ltree; /* literal tree */ | ||
// const ct_data *dtree; /* distance tree */ | ||
{ | ||
var dist; | ||
/* distance of matched string */ | ||
var dist; /* distance of matched string */ | ||
var lc; /* match length or unmatched char (if dist == 0) */ | ||
var lx = 0; /* running index in l_buf */ | ||
var code; /* the code to send */ | ||
var extra; /* number of extra bits to send */ | ||
var lc; | ||
/* match length or unmatched char (if dist == 0) */ | ||
var lx = 0; | ||
/* running index in l_buf */ | ||
var code; | ||
/* the code to send */ | ||
var extra; | ||
/* number of extra bits to send */ | ||
if (s.last_lit !== 0) { | ||
@@ -839,6 +651,4 @@ do { | ||
lx++; | ||
if (dist === 0) { | ||
send_code(s, lc, ltree); | ||
/* send a literal byte */ | ||
send_code(s, lc, ltree); /* send a literal byte */ | ||
//Tracecv(isgraph(lc), (stderr," '%c' ", lc)); | ||
@@ -848,30 +658,20 @@ } else { | ||
code = _length_code[lc]; | ||
send_code(s, code + LITERALS + 1, ltree); | ||
/* send the length code */ | ||
send_code(s, code + LITERALS + 1, ltree); /* send the length code */ | ||
extra = extra_lbits[code]; | ||
if (extra !== 0) { | ||
lc -= base_length[code]; | ||
send_bits(s, lc, extra); | ||
/* send the extra length bits */ | ||
send_bits(s, lc, extra); /* send the extra length bits */ | ||
} | ||
dist--; | ||
/* dist is now the match distance - 1 */ | ||
dist--; /* dist is now the match distance - 1 */ | ||
code = d_code(dist); | ||
//Assert (code < D_CODES, "bad d_code"); | ||
code = d_code(dist); //Assert (code < D_CODES, "bad d_code"); | ||
send_code(s, code, dtree); | ||
/* send the distance code */ | ||
send_code(s, code, dtree); /* send the distance code */ | ||
extra = extra_dbits[code]; | ||
if (extra !== 0) { | ||
dist -= base_dist[code]; | ||
send_bits(s, dist, extra); | ||
/* send the extra distance bits */ | ||
send_bits(s, dist, extra); /* send the extra distance bits */ | ||
} | ||
} | ||
/* literal or match pair ? */ | ||
} /* literal or match pair ? */ | ||
@@ -881,8 +681,7 @@ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ | ||
// "pendingBuf overflow"); | ||
} while (lx < s.last_lit); | ||
} | ||
send_code(s, END_BLOCK, ltree); | ||
} | ||
/* =========================================================================== | ||
@@ -896,5 +695,4 @@ * Construct one Huffman tree and assigns the code bit strings and lengths. | ||
*/ | ||
function build_tree(s, desc) // deflate_state *s; | ||
function build_tree(s, desc) | ||
// deflate_state *s; | ||
// tree_desc *desc; /* the tree descriptor */ | ||
@@ -906,11 +704,6 @@ { | ||
var elems = desc.stat_desc.elems; | ||
var n, m; | ||
/* iterate over heap elements */ | ||
var n, m; /* iterate over heap elements */ | ||
var max_code = -1; /* largest code with non zero frequency */ | ||
var node; /* new node being created */ | ||
var max_code = -1; | ||
/* largest code with non zero frequency */ | ||
var node; | ||
/* new node being created */ | ||
/* Construct the initial heap, with least frequent element in | ||
@@ -920,18 +713,13 @@ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. | ||
*/ | ||
s.heap_len = 0; | ||
s.heap_max = HEAP_SIZE; | ||
for (n = 0; n < elems; n++) { | ||
if (tree[n * 2] | ||
/*.Freq*/ | ||
!== 0) { | ||
if (tree[n * 2] /*.Freq*/ !== 0) { | ||
s.heap[++s.heap_len] = max_code = n; | ||
s.depth[n] = 0; | ||
} else { | ||
tree[n * 2 + 1] | ||
/*.Len*/ | ||
= 0; | ||
tree[n * 2 + 1] /*.Len*/ = 0; | ||
} | ||
} | ||
/* The pkzip format requires that at least one distance code exists, | ||
@@ -942,100 +730,59 @@ * and that at least one bit should be sent even if there is only one | ||
*/ | ||
while (s.heap_len < 2) { | ||
node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0; | ||
tree[node * 2] | ||
/*.Freq*/ | ||
= 1; | ||
tree[node * 2] /*.Freq*/ = 1; | ||
s.depth[node] = 0; | ||
s.opt_len--; | ||
if (has_stree) { | ||
s.static_len -= stree[node * 2 + 1] | ||
/*.Len*/ | ||
; | ||
s.static_len -= stree[node * 2 + 1] /*.Len*/; | ||
} | ||
/* node is 0 or 1 so it does not have extra bits */ | ||
} | ||
desc.max_code = max_code; | ||
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, | ||
* establish sub-heaps of increasing lengths: | ||
*/ | ||
for (n = s.heap_len >> 1 | ||
/*int /2*/ | ||
; n >= 1; n--) { | ||
for (n = s.heap_len >> 1 /*int /2*/; n >= 1; n--) { | ||
pqdownheap(s, tree, n); | ||
} | ||
/* Construct the Huffman tree by repeatedly combining the least two | ||
* frequent nodes. | ||
*/ | ||
node = elems; | ||
/* next internal node of the tree */ | ||
node = elems; /* next internal node of the tree */ | ||
do { | ||
//pqremove(s, tree, n); /* n = node of least frequency */ | ||
/*** pqremove ***/ | ||
n = s.heap[1 | ||
/*SMALLEST*/ | ||
]; | ||
s.heap[1 | ||
/*SMALLEST*/ | ||
] = s.heap[s.heap_len--]; | ||
pqdownheap(s, tree, 1 | ||
/*SMALLEST*/ | ||
); | ||
n = s.heap[1 /*SMALLEST*/]; | ||
s.heap[1 /*SMALLEST*/] = s.heap[s.heap_len--]; | ||
pqdownheap(s, tree, 1 /*SMALLEST*/); | ||
/***/ | ||
m = s.heap[1 | ||
/*SMALLEST*/ | ||
]; | ||
/* m = node of next least frequency */ | ||
m = s.heap[1 /*SMALLEST*/]; /* m = node of next least frequency */ | ||
s.heap[--s.heap_max] = n; | ||
/* keep the nodes sorted by frequency */ | ||
s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */ | ||
s.heap[--s.heap_max] = m; | ||
s.heap[--s.heap_max] = m; | ||
/* Create a new node father of n and m */ | ||
tree[node * 2] /*.Freq*/ = tree[n * 2] /*.Freq*/ + tree[m * 2] /*.Freq*/; | ||
s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1; | ||
tree[n * 2 + 1] /*.Dad*/ = tree[m * 2 + 1] /*.Dad*/ = node; | ||
tree[node * 2] | ||
/*.Freq*/ | ||
= tree[n * 2] | ||
/*.Freq*/ | ||
+ tree[m * 2] | ||
/*.Freq*/ | ||
; | ||
s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1; | ||
tree[n * 2 + 1] | ||
/*.Dad*/ | ||
= tree[m * 2 + 1] | ||
/*.Dad*/ | ||
= node; | ||
/* and insert the new node in the heap */ | ||
s.heap[1 | ||
/*SMALLEST*/ | ||
] = node++; | ||
pqdownheap(s, tree, 1 | ||
/*SMALLEST*/ | ||
); | ||
s.heap[1 /*SMALLEST*/] = node++; | ||
pqdownheap(s, tree, 1 /*SMALLEST*/); | ||
} while (s.heap_len >= 2); | ||
s.heap[--s.heap_max] = s.heap[1 /*SMALLEST*/]; | ||
s.heap[--s.heap_max] = s.heap[1 | ||
/*SMALLEST*/ | ||
]; | ||
/* At this point, the fields freq and dad are set. We can now | ||
* generate the bit lengths. | ||
*/ | ||
gen_bitlen(s, desc); | ||
gen_bitlen(s, desc); | ||
/* The field len is now set, we can generate the bit codes */ | ||
gen_codes(tree, max_code, s.bl_count); | ||
} | ||
/* =========================================================================== | ||
@@ -1045,31 +792,17 @@ * Scan a literal or distance tree to determine the frequencies of the codes | ||
*/ | ||
function scan_tree(s, tree, max_code) // deflate_state *s; | ||
function scan_tree(s, tree, max_code) | ||
// deflate_state *s; | ||
// ct_data *tree; /* the tree to be scanned */ | ||
// int max_code; /* and its largest code of non zero frequency */ | ||
{ | ||
var n; | ||
/* iterates over all tree elements */ | ||
var n; /* iterates over all tree elements */ | ||
var prevlen = -1; /* last emitted length */ | ||
var curlen; /* length of current code */ | ||
var prevlen = -1; | ||
/* last emitted length */ | ||
var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */ | ||
var curlen; | ||
/* length of current code */ | ||
var count = 0; /* repeat count of the current code */ | ||
var max_count = 7; /* max repeat count */ | ||
var min_count = 4; /* min repeat count */ | ||
var nextlen = tree[0 * 2 + 1] | ||
/*.Len*/ | ||
; | ||
/* length of next code */ | ||
var count = 0; | ||
/* repeat count of the current code */ | ||
var max_count = 7; | ||
/* max repeat count */ | ||
var min_count = 4; | ||
/* min repeat count */ | ||
if (nextlen === 0) { | ||
@@ -1079,13 +812,7 @@ max_count = 138; | ||
} | ||
tree[(max_code + 1) * 2 + 1] /*.Len*/ = 0xffff; /* guard */ | ||
tree[(max_code + 1) * 2 + 1] | ||
/*.Len*/ | ||
= 0xffff; | ||
/* guard */ | ||
for (n = 0; n <= max_code; n++) { | ||
curlen = nextlen; | ||
nextlen = tree[(n + 1) * 2 + 1] | ||
/*.Len*/ | ||
; | ||
nextlen = tree[(n + 1) * 2 + 1] /*.Len*/; | ||
@@ -1095,5 +822,3 @@ if (++count < max_count && curlen === nextlen) { | ||
} else if (count < min_count) { | ||
s.bl_tree[curlen * 2] | ||
/*.Freq*/ | ||
+= count; | ||
s.bl_tree[curlen * 2] /*.Freq*/ += count; | ||
} else if (curlen !== 0) { | ||
@@ -1103,3 +828,2 @@ if (curlen !== prevlen) { | ||
} | ||
s.bl_tree[REP_3_6 * 2] /*.Freq*/++; | ||
@@ -1114,3 +838,2 @@ } else if (count <= 10) { | ||
prevlen = curlen; | ||
if (nextlen === 0) { | ||
@@ -1128,2 +851,3 @@ max_count = 138; | ||
} | ||
/* =========================================================================== | ||
@@ -1133,35 +857,18 @@ * Send a literal or distance tree in compressed form, using the codes in | ||
*/ | ||
function send_tree(s, tree, max_code) // deflate_state *s; | ||
function send_tree(s, tree, max_code) | ||
// deflate_state *s; | ||
// ct_data *tree; /* the tree to be scanned */ | ||
// int max_code; /* and its largest code of non zero frequency */ | ||
{ | ||
var n; | ||
/* iterates over all tree elements */ | ||
var n; /* iterates over all tree elements */ | ||
var prevlen = -1; /* last emitted length */ | ||
var curlen; /* length of current code */ | ||
var prevlen = -1; | ||
/* last emitted length */ | ||
var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */ | ||
var curlen; | ||
/* length of current code */ | ||
var count = 0; /* repeat count of the current code */ | ||
var max_count = 7; /* max repeat count */ | ||
var min_count = 4; /* min repeat count */ | ||
var nextlen = tree[0 * 2 + 1] | ||
/*.Len*/ | ||
; | ||
/* length of next code */ | ||
var count = 0; | ||
/* repeat count of the current code */ | ||
var max_count = 7; | ||
/* max repeat count */ | ||
var min_count = 4; | ||
/* min repeat count */ | ||
/* tree[max_code+1].Len = -1; */ | ||
/* guard already set */ | ||
/* tree[max_code+1].Len = -1; */ /* guard already set */ | ||
if (nextlen === 0) { | ||
@@ -1171,8 +878,5 @@ max_count = 138; | ||
} | ||
for (n = 0; n <= max_code; n++) { | ||
curlen = nextlen; | ||
nextlen = tree[(n + 1) * 2 + 1] | ||
/*.Len*/ | ||
; | ||
nextlen = tree[(n + 1) * 2 + 1] /*.Len*/; | ||
@@ -1189,5 +893,4 @@ if (++count < max_count && curlen === nextlen) { | ||
count--; | ||
} //Assert(count >= 3 && count <= 6, " 3_6?"); | ||
} | ||
//Assert(count >= 3 && count <= 6, " 3_6?"); | ||
send_code(s, REP_3_6, s.bl_tree); | ||
@@ -1202,6 +905,4 @@ send_bits(s, count - 3, 2); | ||
} | ||
count = 0; | ||
prevlen = curlen; | ||
if (nextlen === 0) { | ||
@@ -1219,2 +920,3 @@ max_count = 138; | ||
} | ||
/* =========================================================================== | ||
@@ -1224,14 +926,10 @@ * Construct the Huffman tree for the bit lengths and return the index in | ||
*/ | ||
function build_bl_tree(s) { | ||
var max_blindex; | ||
/* index of last bit length code of non zero freq */ | ||
var max_blindex; /* index of last bit length code of non zero freq */ | ||
/* Determine the bit length frequencies for literal and distance trees */ | ||
scan_tree(s, s.dyn_ltree, s.l_desc.max_code); | ||
scan_tree(s, s.dyn_dtree, s.d_desc.max_code); | ||
/* Build the bit length tree: */ | ||
build_tree(s, s.bl_desc); | ||
@@ -1246,7 +944,4 @@ /* opt_len now includes the length of the tree representations, except | ||
*/ | ||
for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) { | ||
if (s.bl_tree[bl_order[max_blindex] * 2 + 1] | ||
/*.Len*/ | ||
!== 0) { | ||
if (s.bl_tree[bl_order[max_blindex] * 2 + 1] /*.Len*/ !== 0) { | ||
break; | ||
@@ -1256,5 +951,4 @@ } | ||
/* Update opt_len to include the bit length tree and counts */ | ||
s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", | ||
s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; | ||
//Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", | ||
// s->opt_len, s->static_len)); | ||
@@ -1264,2 +958,3 @@ | ||
} | ||
/* =========================================================================== | ||
@@ -1270,9 +965,8 @@ * Send the header for a block using dynamic Huffman trees: the counts, the | ||
*/ | ||
function send_all_trees(s, lcodes, dcodes, blcodes) // deflate_state *s; | ||
function send_all_trees(s, lcodes, dcodes, blcodes) | ||
// deflate_state *s; | ||
// int lcodes, dcodes, blcodes; /* number of codes for each tree */ | ||
{ | ||
var rank; | ||
/* index in bl_order */ | ||
var rank; /* index in bl_order */ | ||
//Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); | ||
@@ -1282,26 +976,18 @@ //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, | ||
//Tracev((stderr, "\nbl counts: ")); | ||
send_bits(s, lcodes - 257, 5); | ||
/* not +255 as stated in appnote.txt */ | ||
send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */ | ||
send_bits(s, dcodes - 1, 5); | ||
send_bits(s, blcodes - 4, 4); | ||
/* not -3 as stated in appnote.txt */ | ||
send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */ | ||
for (rank = 0; rank < blcodes; rank++) { | ||
//Tracev((stderr, "\nbl code %2d ", bl_order[rank])); | ||
send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] | ||
/*.Len*/ | ||
, 3); | ||
} //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); | ||
send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] /*.Len*/, 3); | ||
} | ||
//Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); | ||
send_tree(s, s.dyn_ltree, lcodes - 1); | ||
/* literal tree */ | ||
send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */ | ||
//Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); | ||
send_tree(s, s.dyn_dtree, dcodes - 1); | ||
/* distance tree */ | ||
send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */ | ||
//Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); | ||
} | ||
/* =========================================================================== | ||
@@ -1320,4 +1006,2 @@ * Check if the data type is TEXT or BINARY, using the following algorithm: | ||
*/ | ||
function detect_data_type(s) { | ||
@@ -1330,44 +1014,30 @@ /* black_mask is the bit mask of black-listed bytes | ||
var n; | ||
/* Check for non-textual ("black-listed") bytes. */ | ||
for (n = 0; n <= 31; n++, black_mask >>>= 1) { | ||
if (black_mask & 1 && s.dyn_ltree[n * 2] | ||
/*.Freq*/ | ||
!== 0) { | ||
if (black_mask & 1 && s.dyn_ltree[n * 2] /*.Freq*/ !== 0) { | ||
return Z_BINARY; | ||
} | ||
} | ||
/* Check for textual ("white-listed") bytes. */ | ||
if (s.dyn_ltree[9 * 2] | ||
/*.Freq*/ | ||
!== 0 || s.dyn_ltree[10 * 2] | ||
/*.Freq*/ | ||
!== 0 || s.dyn_ltree[13 * 2] | ||
/*.Freq*/ | ||
!== 0) { | ||
if (s.dyn_ltree[9 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[10 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[13 * 2] /*.Freq*/ !== 0) { | ||
return Z_TEXT; | ||
} | ||
for (n = 32; n < LITERALS; n++) { | ||
if (s.dyn_ltree[n * 2] | ||
/*.Freq*/ | ||
!== 0) { | ||
if (s.dyn_ltree[n * 2] /*.Freq*/ !== 0) { | ||
return Z_TEXT; | ||
} | ||
} | ||
/* There are no "black-listed" or "white-listed" bytes: | ||
* this stream either is empty or has tolerated ("gray-listed") bytes only. | ||
*/ | ||
return Z_BINARY; | ||
} | ||
var static_init_done = false; | ||
var static_init_done = false; | ||
/* =========================================================================== | ||
* Initialize the tree data structures for a new zlib stream. | ||
*/ | ||
function _tr_init(s) { | ||
@@ -1378,3 +1048,2 @@ if (!static_init_done) { | ||
} | ||
s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc); | ||
@@ -1385,12 +1054,12 @@ s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc); | ||
s.bi_valid = 0; | ||
/* Initialize the first block of the first file: */ | ||
init_block(s); | ||
} | ||
/* =========================================================================== | ||
* Send a stored block | ||
*/ | ||
function _tr_stored_block(s, buf, stored_len, last) //DeflateState *s; | ||
function _tr_stored_block(s, buf, stored_len, last) | ||
//DeflateState *s; | ||
//charf *buf; /* input block */ | ||
@@ -1400,8 +1069,6 @@ //ulg stored_len; /* length of input block */ | ||
{ | ||
send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); | ||
/* send block type */ | ||
send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */ | ||
copy_block(s, buf, stored_len, true); /* with header */ | ||
} | ||
copy_block(s, buf, stored_len, true); | ||
/* with header */ | ||
} | ||
/* =========================================================================== | ||
@@ -1411,4 +1078,2 @@ * Send one empty static block to give enough lookahead for inflate. | ||
*/ | ||
function _tr_align(s) { | ||
@@ -1419,2 +1084,3 @@ send_bits(s, STATIC_TREES << 1, 3); | ||
} | ||
/* =========================================================================== | ||
@@ -1424,5 +1090,4 @@ * Determine the best encoding for the current block: dynamic trees, static | ||
*/ | ||
function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s; | ||
function _tr_flush_block(s, buf, stored_len, last) | ||
//DeflateState *s; | ||
//charf *buf; /* input block, or NULL if too old */ | ||
@@ -1432,10 +1097,6 @@ //ulg stored_len; /* length of input block */ | ||
{ | ||
var opt_lenb, static_lenb; | ||
/* opt_len and static_len in bytes */ | ||
var opt_lenb, static_lenb; /* opt_len and static_len in bytes */ | ||
var max_blindex = 0; /* index of last bit length code of non zero freq */ | ||
var max_blindex = 0; | ||
/* index of last bit length code of non zero freq */ | ||
/* Build the Huffman trees unless a stored block is forced */ | ||
if (s.level > 0) { | ||
@@ -1446,11 +1107,11 @@ /* Check if the file is binary or text */ | ||
} | ||
/* Construct the literal and distance trees */ | ||
build_tree(s, s.l_desc); // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, | ||
build_tree(s, s.l_desc); | ||
// Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, | ||
// s->static_len)); | ||
build_tree(s, s.d_desc); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, | ||
build_tree(s, s.d_desc); | ||
// Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, | ||
// s->static_len)); | ||
/* At this point, opt_len and static_len are the total bit lengths of | ||
@@ -1463,8 +1124,9 @@ * the compressed block data, excluding the tree representations. | ||
*/ | ||
max_blindex = build_bl_tree(s); | ||
max_blindex = build_bl_tree(s); | ||
/* Determine the best encoding. Compute the block lengths in bytes. */ | ||
opt_lenb = s.opt_len + 3 + 7 >>> 3; | ||
static_lenb = s.static_len + 3 + 7 >>> 3; | ||
opt_lenb = s.opt_len + 3 + 7 >>> 3; | ||
static_lenb = s.static_len + 3 + 7 >>> 3; // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", | ||
// Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", | ||
// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, | ||
@@ -1478,4 +1140,3 @@ // s->last_lit)); | ||
// Assert(buf != (char*)0, "lost buf"); | ||
opt_lenb = static_lenb = stored_len + 5; | ||
/* force a stored block */ | ||
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ | ||
} | ||
@@ -1500,17 +1161,15 @@ | ||
compress_block(s, s.dyn_ltree, s.dyn_dtree); | ||
} // Assert (s->compressed_len == s->bits_sent, "bad compressed size"); | ||
} | ||
// Assert (s->compressed_len == s->bits_sent, "bad compressed size"); | ||
/* The above check is made mod 2^32, for files larger than 512 MB | ||
* and uLong implemented on 32 bits. | ||
*/ | ||
init_block(s); | ||
if (last) { | ||
bi_windup(s); | ||
} // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, | ||
} | ||
// Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, | ||
// s->compressed_len-7*last)); | ||
} | ||
} | ||
/* =========================================================================== | ||
@@ -1520,5 +1179,4 @@ * Save the match info and tally the frequency counts. Return true if | ||
*/ | ||
function _tr_tally(s, dist, lc) // deflate_state *s; | ||
function _tr_tally(s, dist, lc) | ||
// deflate_state *s; | ||
// unsigned dist; /* distance of matched string */ | ||
@@ -1528,2 +1186,3 @@ // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ | ||
//var out_length, in_length, dcode; | ||
s.pending_buf[s.d_buf + s.last_lit * 2] = dist >>> 8 & 0xff; | ||
@@ -1533,3 +1192,2 @@ s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; | ||
s.last_lit++; | ||
if (dist === 0) { | ||
@@ -1541,5 +1199,3 @@ /* lc is the unmatched char */ | ||
/* Here, lc is the match length - MIN_MATCH */ | ||
dist--; | ||
/* dist = match distance - 1 */ | ||
dist--; /* dist = match distance - 1 */ | ||
//Assert((ush)dist < (ush)MAX_DIST(s) && | ||
@@ -1551,4 +1207,7 @@ // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && | ||
s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++; | ||
} // (!) This block is disabled in zlib defailts, | ||
} | ||
// (!) This block is disabled in zlib defailts, | ||
// don't enable it for binary compatibility | ||
//#ifdef TRUNCATE_BLOCK | ||
@@ -1574,3 +1233,2 @@ // /* Try to guess if it is profitable to stop the current block here */ | ||
return s.last_lit === s.lit_bufsize - 1; | ||
@@ -1577,0 +1235,0 @@ /* We avoid equality with lit_bufsize because of wraparound at 64K |
@@ -7,41 +7,25 @@ "use strict"; | ||
exports["default"] = ZStream; | ||
function ZStream() { | ||
/* next input byte */ | ||
this.input = null; // JS specific, because we have no pointers | ||
this.next_in = 0; | ||
/* number of bytes available at input */ | ||
this.avail_in = 0; | ||
/* total number of input bytes read so far */ | ||
this.total_in = 0; | ||
/* next output byte should be put there */ | ||
this.output = null; // JS specific, because we have no pointers | ||
this.next_out = 0; | ||
/* remaining free space at output */ | ||
this.avail_out = 0; | ||
/* total number of bytes output so far */ | ||
this.total_out = 0; | ||
/* last error message, NULL if no error */ | ||
this.msg = '' | ||
/*Z_NULL*/ | ||
; | ||
this.msg = '' /*Z_NULL*/; | ||
/* not visible by applications */ | ||
this.state = null; | ||
/* best guess about the data type: binary or text */ | ||
this.data_type = 2 | ||
/*Z_UNKNOWN*/ | ||
; | ||
this.data_type = 2 /*Z_UNKNOWN*/; | ||
/* adler32 value of the uncompressed data */ | ||
this.adler = 0; | ||
} |
"use strict"; | ||
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); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,27 +7,17 @@ value: true | ||
exports["default"] = void 0; | ||
var Log = _interopRequireWildcard(require("./util/logging.js")); | ||
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); } | ||
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; } | ||
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); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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); } } | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
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); } | ||
// this has performance issues in some versions Chromium, and | ||
@@ -39,5 +27,5 @@ // doesn't gain a tremendous amount of performance increase in Firefox | ||
var MAX_RQ_GROW_SIZE = 40 * 1024 * 1024; // 40 MiB | ||
// Constants pulled from RTCDataChannelState enum | ||
// https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/readyState#RTCDataChannelState_enum | ||
var DataChannel = { | ||
@@ -54,19 +42,15 @@ CONNECTING: "connecting", | ||
CLOSED: [WebSocket.CLOSED, DataChannel.CLOSED] | ||
}; // Properties a raw channel must have, WebSocket and RTCDataChannel are two examples | ||
}; | ||
// Properties a raw channel must have, WebSocket and RTCDataChannel are two examples | ||
var rawChannelProps = ["send", "close", "binaryType", "onerror", "onmessage", "onopen", "protocol", "readyState"]; | ||
var Websock = /*#__PURE__*/function () { | ||
function Websock() { | ||
_classCallCheck(this, Websock); | ||
this._websocket = null; // WebSocket or RTCDataChannel object | ||
this._rQi = 0; // Receive queue index | ||
this._rQlen = 0; // Next write position in the receive queue | ||
this._rQbufferSize = 1024 * 1024 * 4; // Receive queue buffer size (4 MiB) | ||
// called in init: this._rQ = new Uint8Array(this._rQbufferSize); | ||
this._rQ = null; // Receive queue | ||
@@ -76,3 +60,2 @@ | ||
// called in init: this._sQ = new Uint8Array(this._sQbufferSize); | ||
this._sQlen = 0; | ||
@@ -87,5 +70,5 @@ this._sQ = null; // Send queue | ||
}; | ||
} // Getters and Setters | ||
} | ||
// Getters and Setters | ||
_createClass(Websock, [{ | ||
@@ -95,9 +78,6 @@ key: "readyState", | ||
var subState; | ||
if (this._websocket === null) { | ||
return "unused"; | ||
} | ||
subState = this._websocket.readyState; | ||
if (ReadyStates.CONNECTING.includes(subState)) { | ||
@@ -112,3 +92,2 @@ return "connecting"; | ||
} | ||
return "unknown"; | ||
@@ -133,4 +112,5 @@ } | ||
this._rQi = val; | ||
} // Receive Queue | ||
} | ||
// Receive Queue | ||
}, { | ||
@@ -165,4 +145,5 @@ key: "rQlen", | ||
return this._rQshift(4); | ||
} // TODO(directxman12): test performance with these vs a DataView | ||
} | ||
// TODO(directxman12): test performance with these vs a DataView | ||
}, { | ||
@@ -172,7 +153,5 @@ key: "_rQshift", | ||
var res = 0; | ||
for (var _byte = bytes - 1; _byte >= 0; _byte--) { | ||
res += this._rQ[this._rQi++] << _byte * 8; | ||
} | ||
return res; | ||
@@ -186,5 +165,4 @@ } | ||
} | ||
var str = ""; // Handle large arrays in steps to avoid long strings on the stack | ||
var str = ""; | ||
// Handle large arrays in steps to avoid long strings on the stack | ||
for (var i = 0; i < len; i += 4096) { | ||
@@ -194,3 +172,2 @@ var part = this.rQshiftBytes(Math.min(4096, len - i)); | ||
} | ||
return str; | ||
@@ -204,3 +181,2 @@ } | ||
} | ||
this._rQi += len; | ||
@@ -214,5 +190,4 @@ return new Uint8Array(this._rQ.buffer, this._rQi - len, len); | ||
len = this.rQlen; | ||
} // TODO: make this just use set with views when using a ArrayBuffer to store the rQ | ||
} | ||
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ | ||
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len)); | ||
@@ -226,6 +201,7 @@ this._rQi += len; | ||
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start); | ||
} // Check to see if we must wait for 'num' bytes (default to FBU.bytes) | ||
} | ||
// Check to see if we must wait for 'num' bytes (default to FBU.bytes) | ||
// to be available in the receive queue. Return true if we need to | ||
// wait (and possibly print a debug message), otherwise false. | ||
}, { | ||
@@ -239,6 +215,4 @@ key: "rQwait", | ||
} | ||
this._rQi -= goback; | ||
} | ||
return true; // true means need more data | ||
@@ -248,4 +222,5 @@ } | ||
return false; | ||
} // Send Queue | ||
} | ||
// Send Queue | ||
}, { | ||
@@ -256,3 +231,2 @@ key: "flush", | ||
this._websocket.send(this._encodeMessage()); | ||
this._sQlen = 0; | ||
@@ -265,3 +239,2 @@ } | ||
this._sQ.set(arr, this._sQlen); | ||
this._sQlen += arr.length; | ||
@@ -276,4 +249,5 @@ this.flush(); | ||
})); | ||
} // Event Handlers | ||
} | ||
// Event Handlers | ||
}, { | ||
@@ -299,3 +273,2 @@ key: "off", | ||
this._allocateBuffers(); | ||
this._rQi = 0; | ||
@@ -313,10 +286,8 @@ this._websocket = null; | ||
var _this = this; | ||
this.init(); | ||
this.init(); // Must get object and class methods to be compatible with the tests. | ||
// Must get object and class methods to be compatible with the tests. | ||
var channelProps = [].concat(_toConsumableArray(Object.keys(rawChannel)), _toConsumableArray(Object.getOwnPropertyNames(Object.getPrototypeOf(rawChannel)))); | ||
for (var i = 0; i < rawChannelProps.length; i++) { | ||
var prop = rawChannelProps[i]; | ||
if (channelProps.indexOf(prop) < 0) { | ||
@@ -326,32 +297,21 @@ throw new Error('Raw channel missing property: ' + prop); | ||
} | ||
this._websocket = rawChannel; | ||
this._websocket.binaryType = "arraybuffer"; | ||
this._websocket.onmessage = this._recvMessage.bind(this); | ||
this._websocket.onopen = function () { | ||
Log.Debug('>> WebSock.onopen'); | ||
if (_this._websocket.protocol) { | ||
Log.Info("Server choose sub-protocol: " + _this._websocket.protocol); | ||
} | ||
_this._eventHandlers.open(); | ||
Log.Debug("<< WebSock.onopen"); | ||
}; | ||
this._websocket.onclose = function (e) { | ||
Log.Debug(">> WebSock.onclose"); | ||
_this._eventHandlers.close(e); | ||
Log.Debug("<< WebSock.onclose"); | ||
}; | ||
this._websocket.onerror = function (e) { | ||
Log.Debug(">> WebSock.onerror: " + e); | ||
_this._eventHandlers.error(e); | ||
Log.Debug("<< WebSock.onerror: " + e); | ||
@@ -366,10 +326,9 @@ }; | ||
Log.Info("Closing WebSocket connection"); | ||
this._websocket.close(); | ||
} | ||
this._websocket.onmessage = function () {}; | ||
} | ||
} // private methods | ||
} | ||
// private methods | ||
}, { | ||
@@ -381,3 +340,5 @@ key: "_encodeMessage", | ||
return new Uint8Array(this._sQ.buffer, 0, this._sQlen); | ||
} // We want to move all the unread data to the start of the queue, | ||
} | ||
// We want to move all the unread data to the start of the queue, | ||
// e.g. compacting. | ||
@@ -387,3 +348,2 @@ // The function also expands the receive que if needed, and for | ||
// unneccessary copying. | ||
}, { | ||
@@ -396,3 +356,2 @@ key: "_expandCompactRQ", | ||
var resizeNeeded = this._rQbufferSize < requiredBufferSize; | ||
if (resizeNeeded) { | ||
@@ -402,8 +361,7 @@ // Make sure we always *at least* double the buffer size, and have at least space for 8x | ||
this._rQbufferSize = Math.max(this._rQbufferSize * 2, requiredBufferSize); | ||
} // we don't want to grow unboundedly | ||
} | ||
// we don't want to grow unboundedly | ||
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) { | ||
this._rQbufferSize = MAX_RQ_GROW_SIZE; | ||
if (this._rQbufferSize - this.rQlen < minFit) { | ||
@@ -413,7 +371,5 @@ throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit"); | ||
} | ||
if (resizeNeeded) { | ||
var oldRQbuffer = this._rQ.buffer; | ||
this._rQ = new Uint8Array(this._rQbufferSize); | ||
this._rQ.set(new Uint8Array(oldRQbuffer, this._rQi, this._rQlen - this._rQi)); | ||
@@ -423,7 +379,7 @@ } else { | ||
} | ||
this._rQlen = this._rQlen - this._rQi; | ||
this._rQi = 0; | ||
} // push arraybuffer values onto the end of the receive que | ||
} | ||
// push arraybuffer values onto the end of the receive que | ||
}, { | ||
@@ -433,9 +389,6 @@ key: "_DecodeMessage", | ||
var u8 = new Uint8Array(data); | ||
if (u8.length > this._rQbufferSize - this._rQlen) { | ||
this._expandCompactRQ(u8.length); | ||
} | ||
this._rQ.set(u8, this._rQlen); | ||
this._rQlen += u8.length; | ||
@@ -447,6 +400,4 @@ } | ||
this._DecodeMessage(e.data); | ||
if (this.rQlen > 0) { | ||
this._eventHandlers.message(); | ||
if (this._rQlen == this._rQi) { | ||
@@ -463,6 +414,4 @@ // All data has now been processed, this means we | ||
}]); | ||
return Websock; | ||
}(); | ||
exports["default"] = Websock; |
{ | ||
"name": "@novnc/novnc", | ||
"version": "1.3.0-g8329372", | ||
"version": "1.3.0-g837cc75", | ||
"description": "An HTML5 VNC client", | ||
@@ -41,32 +41,32 @@ "browser": "lib/rfb", | ||
"devDependencies": { | ||
"@babel/core": "*", | ||
"@babel/plugin-syntax-dynamic-import": "*", | ||
"@babel/plugin-transform-modules-commonjs": "*", | ||
"@babel/preset-env": "*", | ||
"@babel/cli": "*", | ||
"babel-plugin-import-redirect": "*", | ||
"browserify": "*", | ||
"babelify": "*", | ||
"core-js": "*", | ||
"chai": "*", | ||
"commander": "*", | ||
"es-module-loader": "*", | ||
"eslint": "*", | ||
"fs-extra": "*", | ||
"jsdom": "*", | ||
"karma": "*", | ||
"karma-mocha": "*", | ||
"karma-chrome-launcher": "*", | ||
"@chiragrupani/karma-chromium-edge-launcher": "*", | ||
"karma-firefox-launcher": "*", | ||
"karma-ie-launcher": "*", | ||
"karma-mocha-reporter": "*", | ||
"karma-safari-launcher": "*", | ||
"karma-script-launcher": "*", | ||
"karma-sinon-chai": "*", | ||
"mocha": "*", | ||
"node-getopt": "*", | ||
"po2json": "*", | ||
"sinon": "*", | ||
"sinon-chai": "*" | ||
"@babel/core": "latest", | ||
"@babel/plugin-syntax-dynamic-import": "latest", | ||
"@babel/plugin-transform-modules-commonjs": "latest", | ||
"@babel/preset-env": "latest", | ||
"@babel/cli": "latest", | ||
"babel-plugin-import-redirect": "latest", | ||
"browserify": "latest", | ||
"babelify": "latest", | ||
"core-js": "latest", | ||
"chai": "latest", | ||
"commander": "latest", | ||
"es-module-loader": "latest", | ||
"eslint": "latest", | ||
"fs-extra": "latest", | ||
"jsdom": "latest", | ||
"karma": "latest", | ||
"karma-mocha": "latest", | ||
"karma-chrome-launcher": "latest", | ||
"@chiragrupani/karma-chromium-edge-launcher": "latest", | ||
"karma-firefox-launcher": "latest", | ||
"karma-ie-launcher": "latest", | ||
"karma-mocha-reporter": "latest", | ||
"karma-safari-launcher": "latest", | ||
"karma-script-launcher": "latest", | ||
"karma-sinon-chai": "latest", | ||
"mocha": "latest", | ||
"node-getopt": "latest", | ||
"po2json": "latest", | ||
"sinon": "latest", | ||
"sinon-chai": "latest" | ||
}, | ||
@@ -73,0 +73,0 @@ "dependencies": {}, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
1241414
5
30199
143
6
7
2
36