From d14905d74690ca3986e5bc39c270652106865fe1 Mon Sep 17 00:00:00 2001 From: Tariq Soliman Date: Thu, 19 Aug 2021 13:47:56 -0700 Subject: [PATCH] Make PNG.js a module --- dist/lithosphere.js | 16 +- dist/src/constants.d.ts | 1 - dist/src/controls/altitude.d.ts | 0 dist/src/controls/compass.d.ts | 15 - dist/src/controls/controls.d.ts | 0 dist/src/controls/coordinates.d.ts | 19 - dist/src/controls/crop.d.ts | 0 dist/src/controls/exaggerate.d.ts | 18 - dist/src/controls/home.d.ts | 13 - dist/src/controls/index.d.ts | 29 - dist/src/controls/layers.d.ts | 17 - dist/src/controls/link.d.ts | 29 - dist/src/controls/observe.d.ts | 23 - dist/src/controls/walk.d.ts | 16 - dist/src/core/cameras.d.ts | 58 -- dist/src/core/events.d.ts | 50 -- dist/src/core/renderer.d.ts | 8 - dist/src/core/shaders.d.ts | 7 - dist/src/layers/clamped.d.ts | 10 - dist/src/layers/curtain.d.ts | 0 dist/src/layers/index.d.ts | 34 - dist/src/layers/model.d.ts | 0 dist/src/layers/overlay.d.ts | 0 dist/src/layers/tile.d.ts | 8 - dist/src/layers/tile3d.d.ts | 10 - dist/src/layers/vector.d.ts | 11 - dist/src/parsers/demt.d.ts | 0 dist/src/parsers/rgba.d.ts | 2 - dist/src/parsers/tif.d.ts | 1 - dist/src/secondary/OrbitControls.d.ts | 5 - dist/src/secondary/PNG/png.d.ts | 16 + dist/src/secondary/PNG/zlib.d.ts | 0 dist/src/secondary/PointerLockControls.d.ts | 1 - dist/src/secondary/loadingScreen.d.ts | 7 - dist/src/secondary/sprites.d.ts | 8 - dist/src/utils/index.d.ts | 22 - dist/src/utils/paths.d.ts | 20 - package.json | 2 +- src/parsers/rgba.ts | 3 +- src/secondary/PNG/png.ts | 949 ++++++++++---------- src/secondary/PNG/zlib.ts | 4 +- 41 files changed, 497 insertions(+), 935 deletions(-) delete mode 100644 dist/src/constants.d.ts delete mode 100644 dist/src/controls/altitude.d.ts delete mode 100644 dist/src/controls/compass.d.ts delete mode 100644 dist/src/controls/controls.d.ts delete mode 100644 dist/src/controls/coordinates.d.ts delete mode 100644 dist/src/controls/crop.d.ts delete mode 100644 dist/src/controls/exaggerate.d.ts delete mode 100644 dist/src/controls/home.d.ts delete mode 100644 dist/src/controls/index.d.ts delete mode 100644 dist/src/controls/layers.d.ts delete mode 100644 dist/src/controls/link.d.ts delete mode 100644 dist/src/controls/observe.d.ts delete mode 100644 dist/src/controls/walk.d.ts delete mode 100644 dist/src/core/cameras.d.ts delete mode 100644 dist/src/core/events.d.ts delete mode 100644 dist/src/core/renderer.d.ts delete mode 100644 dist/src/core/shaders.d.ts delete mode 100644 dist/src/layers/clamped.d.ts delete mode 100644 dist/src/layers/curtain.d.ts delete mode 100644 dist/src/layers/index.d.ts delete mode 100644 dist/src/layers/model.d.ts delete mode 100644 dist/src/layers/overlay.d.ts delete mode 100644 dist/src/layers/tile.d.ts delete mode 100644 dist/src/layers/tile3d.d.ts delete mode 100644 dist/src/layers/vector.d.ts delete mode 100644 dist/src/parsers/demt.d.ts delete mode 100644 dist/src/parsers/tif.d.ts delete mode 100644 dist/src/secondary/OrbitControls.d.ts delete mode 100644 dist/src/secondary/PNG/zlib.d.ts delete mode 100644 dist/src/secondary/PointerLockControls.d.ts delete mode 100644 dist/src/secondary/loadingScreen.d.ts delete mode 100644 dist/src/secondary/sprites.d.ts delete mode 100644 dist/src/utils/index.d.ts delete mode 100644 dist/src/utils/paths.d.ts diff --git a/dist/lithosphere.js b/dist/lithosphere.js index 451b05b..3068d7d 100644 --- a/dist/lithosphere.js +++ b/dist/lithosphere.js @@ -2056,7 +2056,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return RGBAParser; });\n/* harmony import */ var _secondary_PNG_zlib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../secondary/PNG/zlib */ \"./src/secondary/PNG/zlib.ts\");\n/* harmony import */ var _secondary_PNG_zlib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_secondary_PNG_zlib__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _secondary_PNG_png__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../secondary/PNG/png */ \"./src/secondary/PNG/png.ts\");\n/* harmony import */ var _secondary_PNG_png__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_secondary_PNG_png__WEBPACK_IMPORTED_MODULE_1__);\n\n\nfunction RGBAParser(tilePath, layerObj, xyz, tileResolution, numberOfVertices) {\n return new Promise(function (resolve, reject) {\n PNG.load(tilePath, {\n withCredentials: false\n }, function (img) {\n if (img == false) {\n reject();\n return;\n }\n\n var rgbaArr = img.decode();\n var heightArr = [];\n\n for (var i = 0; i < rgbaArr.length; i += 4) {\n heightArr.push(RGBAto32({\n r: rgbaArr[i],\n g: rgbaArr[i + 1],\n b: rgbaArr[i + 2],\n a: rgbaArr[i + 3]\n }));\n }\n\n resolve(heightArr);\n }, function (err) {\n reject();\n });\n });\n}\n\nfunction RGBAto32(rgba) {\n return decodeFloat(asByteString(rgba.r.toString(2)) + asByteString(rgba.g.toString(2)) + asByteString(rgba.b.toString(2)) + asByteString(rgba.a.toString(2)));\n}\n\nfunction asByteString(byte) {\n var byteString = byte;\n\n while (byteString.length < 8) {\n byteString = '0' + byteString;\n }\n\n return byteString;\n}\n\nfunction decodeFloat(binary) {\n if (binary.length < 32) binary = ('00000000000000000000000000000000' + binary).substr(binary.length);\n var sign = binary.charAt(0) == '1' ? -1 : 1;\n var exponent = parseInt(binary.substr(1, 8), 2) - 127;\n var significandBase = binary.substr(9);\n var significandBin = '1' + significandBase;\n var i = 0;\n var val = 1;\n var significand = 0;\n\n if (exponent == -127) {\n if (significandBase.indexOf('1') == -1) return 0;else {\n exponent = -126;\n significandBin = '0' + significandBase;\n }\n }\n\n while (i < significandBin.length) {\n significand += val * parseInt(significandBin.charAt(i));\n val = val / 2;\n i++;\n }\n\n return sign * significand * Math.pow(2, exponent);\n}\n\n//# sourceURL=webpack://LithoSphere/./src/parsers/rgba.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return RGBAParser; });\n/* harmony import */ var _secondary_PNG_png__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../secondary/PNG/png */ \"./src/secondary/PNG/png.ts\");\n\nfunction RGBAParser(tilePath, layerObj, xyz, tileResolution, numberOfVertices) {\n return new Promise(function (resolve, reject) {\n _secondary_PNG_png__WEBPACK_IMPORTED_MODULE_0__[\"default\"].load(tilePath, {\n withCredentials: false\n }, function (img) {\n if (img == false) {\n reject();\n return;\n }\n\n var rgbaArr = img.decode();\n var heightArr = [];\n\n for (var i = 0; i < rgbaArr.length; i += 4) {\n heightArr.push(RGBAto32({\n r: rgbaArr[i],\n g: rgbaArr[i + 1],\n b: rgbaArr[i + 2],\n a: rgbaArr[i + 3]\n }));\n }\n\n resolve(heightArr);\n }, function (err) {\n reject();\n });\n });\n}\n\nfunction RGBAto32(rgba) {\n return decodeFloat(asByteString(rgba.r.toString(2)) + asByteString(rgba.g.toString(2)) + asByteString(rgba.b.toString(2)) + asByteString(rgba.a.toString(2)));\n}\n\nfunction asByteString(byte) {\n var byteString = byte;\n\n while (byteString.length < 8) {\n byteString = '0' + byteString;\n }\n\n return byteString;\n}\n\nfunction decodeFloat(binary) {\n if (binary.length < 32) binary = ('00000000000000000000000000000000' + binary).substr(binary.length);\n var sign = binary.charAt(0) == '1' ? -1 : 1;\n var exponent = parseInt(binary.substr(1, 8), 2) - 127;\n var significandBase = binary.substr(9);\n var significandBin = '1' + significandBase;\n var i = 0;\n var val = 1;\n var significand = 0;\n\n if (exponent == -127) {\n if (significandBase.indexOf('1') == -1) return 0;else {\n exponent = -126;\n significandBin = '0' + significandBase;\n }\n }\n\n while (i < significandBin.length) {\n significand += val * parseInt(significandBin.charAt(i));\n val = val / 2;\n i++;\n }\n\n return sign * significand * Math.pow(2, exponent);\n}\n\n//# sourceURL=webpack://LithoSphere/./src/parsers/rgba.ts?"); /***/ }), @@ -2088,10 +2088,11 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /*!**********************************!*\ !*** ./src/secondary/PNG/png.ts ***! \**********************************/ -/*! no static exports found */ -/***/ (function(module, exports) { +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { -eval("window.PNG = function () {\n var APNG_DISPOSE_OP_BACKGROUND = 1;\n var APNG_DISPOSE_OP_PREVIOUS = 2;\n var APNG_BLEND_OP_SOURCE = 0;\n var scratchCanvas = document.createElement('canvas');\n var scratchCtx = scratchCanvas.getContext('2d');\n\n var makeImage = function (imageData) {\n scratchCtx.width = imageData.width;\n scratchCtx.height = imageData.height;\n scratchCtx.clearRect(0, 0, imageData.width, imageData.height);\n scratchCtx.putImageData(imageData, 0, 0);\n var img = new Image();\n img.src = scratchCanvas.toDataURL();\n return img;\n };\n\n var PNG = function () {\n function PNG(data1) {\n var i;\n this.data = data1;\n this.pos = 8;\n this.palette = [];\n this.imgData = [];\n this.transparency = {};\n this.animation = null;\n this.text = {};\n var frame = null;\n\n while (true) {\n var data;\n var chunkSize = this.readUInt32();\n var section = '';\n\n for (i = 0; i < 4; i++) {\n section += String.fromCharCode(this.data[this.pos++]);\n }\n\n switch (section) {\n case 'IHDR':\n this.width = this.readUInt32();\n this.height = this.readUInt32();\n this.bits = this.data[this.pos++];\n this.colorType = this.data[this.pos++];\n this.compressionMethod = this.data[this.pos++];\n this.filterMethod = this.data[this.pos++];\n this.interlaceMethod = this.data[this.pos++];\n break;\n\n case 'acTL':\n this.animation = {\n numFrames: this.readUInt32(),\n numPlays: this.readUInt32() || Infinity,\n frames: []\n };\n break;\n\n case 'PLTE':\n this.palette = this.read(chunkSize);\n break;\n\n case 'fcTL':\n if (frame) {\n this.animation.frames.push(frame);\n }\n\n this.pos += 4;\n frame = {\n width: this.readUInt32(),\n height: this.readUInt32(),\n xOffset: this.readUInt32(),\n yOffset: this.readUInt32()\n };\n var delayNum = this.readUInt16();\n var delayDen = this.readUInt16() || 100;\n frame.delay = 1000 * delayNum / delayDen;\n frame.disposeOp = this.data[this.pos++];\n frame.blendOp = this.data[this.pos++];\n frame.data = [];\n break;\n\n case 'IDAT':\n case 'fdAT':\n if (section === 'fdAT') {\n this.pos += 4;\n chunkSize -= 4;\n }\n\n data = frame && frame.data || this.imgData;\n\n for (i = 0; i < chunkSize; i++) {\n data.push(this.data[this.pos++]);\n }\n\n break;\n\n case 'tRNS':\n this.transparency = {};\n\n switch (this.colorType) {\n case 3:\n this.transparency.indexed = this.read(chunkSize);\n var short = 255 - this.transparency.indexed.length;\n\n if (short > 0) {\n for (i = 0; i < short; i++) {\n this.transparency.indexed.push(255);\n }\n }\n\n break;\n\n case 0:\n this.transparency.grayscale = this.read(chunkSize)[0];\n break;\n\n case 2:\n this.transparency.rgb = this.read(chunkSize);\n break;\n }\n\n break;\n\n case 'tEXt':\n var text = this.read(chunkSize);\n var index = text.indexOf(0);\n var key = String.fromCharCode.apply(String, text.slice(0, index));\n this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));\n break;\n\n case 'IEND':\n if (frame) {\n this.animation.frames.push(frame);\n }\n\n switch (this.colorType) {\n case 0:\n case 3:\n case 4:\n this.colors = 1;\n break;\n\n case 2:\n case 6:\n this.colors = 3;\n break;\n }\n\n this.hasAlphaChannel = [4, 6].includes(this.colorType);\n var colors = this.colors + (this.hasAlphaChannel ? 1 : 0);\n this.pixelBitlength = this.bits * colors;\n\n switch (this.colors) {\n case 1:\n this.colorSpace = 'DeviceGray';\n break;\n\n case 3:\n this.colorSpace = 'DeviceRGB';\n break;\n }\n\n this.imgData = new Uint8Array(this.imgData);\n return;\n break;\n\n default:\n this.pos += chunkSize;\n }\n\n this.pos += 4;\n\n if (this.pos > this.data.length) {\n throw new Error('Incomplete or corrupt PNG file');\n }\n }\n }\n\n PNG.load = function (url, options, callback, failureCallback) {\n var xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.responseType = 'arraybuffer';\n xhr.withCredentials = options.withCredentials;\n\n xhr.onload = function () {\n var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);\n\n if (xhr.status !== 404) {\n var png = new PNG(data);\n return typeof callback === 'function' ? callback(png) : undefined;\n } else if (typeof failureCallback === 'function') failureCallback(xhr.status);\n };\n\n return xhr.send();\n };\n\n PNG.prototype.read = function (bytes) {\n var result = new Array(bytes);\n\n for (var i = 0; i < bytes; i++) {\n result[i] = this.data[this.pos++];\n }\n\n return result;\n };\n\n PNG.prototype.readUInt32 = function () {\n var b1 = this.data[this.pos++] << 24;\n var b2 = this.data[this.pos++] << 16;\n var b3 = this.data[this.pos++] << 8;\n var b4 = this.data[this.pos++];\n return b1 | b2 | b3 | b4;\n };\n\n PNG.prototype.readUInt16 = function () {\n var b1 = this.data[this.pos++] << 8;\n var b2 = this.data[this.pos++];\n return b1 | b2;\n };\n\n PNG.prototype.decodePixels = function (data) {\n if (data == null) {\n data = this.imgData;\n }\n\n if (data.length === 0) {\n return new Uint8Array(0);\n }\n\n data = new FlateStream(data);\n data = data.getBytes();\n\n var _a = this,\n width = _a.width,\n height = _a.height;\n\n var pixelBytes = this.pixelBitlength / 8;\n var pixels = new Uint8Array(width * height * pixelBytes);\n var length = data.length;\n var pos = 0;\n\n function pass(x0, y0, dx, dy, singlePass) {\n if (singlePass === void 0) {\n singlePass = false;\n }\n\n var w = Math.ceil((width - x0) / dx);\n var h = Math.ceil((height - y0) / dy);\n var scanlineLength = pixelBytes * w;\n var buffer = singlePass ? pixels : new Uint8Array(scanlineLength * h);\n var row = 0;\n var c = 0;\n\n while (row < h && pos < length) {\n var byte, col, i, left, upper;\n\n switch (data[pos++]) {\n case 0:\n for (i = 0; i < scanlineLength; i++) {\n buffer[c++] = data[pos++];\n }\n\n break;\n\n case 1:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n buffer[c++] = (byte + left) % 256;\n }\n\n break;\n\n case 2:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n buffer[c++] = (upper + byte) % 256;\n }\n\n break;\n\n case 3:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n buffer[c++] = (byte + Math.floor((left + upper) / 2)) % 256;\n }\n\n break;\n\n case 4:\n for (i = 0; i < scanlineLength; i++) {\n var paeth, upperLeft;\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n\n if (row === 0) {\n upper = upperLeft = 0;\n } else {\n upper = buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n upperLeft = col && buffer[(row - 1) * scanlineLength + (col - 1) * pixelBytes + i % pixelBytes];\n }\n\n var p = left + upper - upperLeft;\n var pa = Math.abs(p - left);\n var pb = Math.abs(p - upper);\n var pc = Math.abs(p - upperLeft);\n\n if (pa <= pb && pa <= pc) {\n paeth = left;\n } else if (pb <= pc) {\n paeth = upper;\n } else {\n paeth = upperLeft;\n }\n\n buffer[c++] = (byte + paeth) % 256;\n }\n\n break;\n\n default:\n throw new Error(\"Invalid filter algorithm: \" + data[pos - 1]);\n }\n\n if (!singlePass) {\n var pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes;\n var bufferPos = row * scanlineLength;\n\n for (i = 0; i < w; i++) {\n for (var j = 0; j < pixelBytes; j++) pixels[pixelsPos++] = buffer[bufferPos++];\n\n pixelsPos += (dx - 1) * pixelBytes;\n }\n }\n\n row++;\n }\n }\n\n if (this.interlaceMethod === 1) {\n pass(0, 0, 8, 8);\n pass(4, 0, 8, 8);\n pass(0, 4, 4, 8);\n pass(2, 0, 4, 4);\n pass(0, 2, 2, 4);\n pass(1, 0, 2, 2);\n pass(0, 1, 1, 2);\n } else {\n pass(0, 0, 1, 1, true);\n }\n\n return pixels;\n };\n\n PNG.prototype.decodePalette = function () {\n var palette = this.palette;\n var length = palette.length;\n var transparency = this.transparency.indexed || [];\n var ret = new Uint8Array((transparency.length || 0) + length);\n var pos = 0;\n var c = 0;\n\n for (var i = 0; i < length; i += 3) {\n var left;\n ret[pos++] = palette[i];\n ret[pos++] = palette[i + 1];\n ret[pos++] = palette[i + 2];\n ret[pos++] = (left = transparency[c++]) != null ? left : 255;\n }\n\n return ret;\n };\n\n PNG.prototype.copyToImageData = function (imageData, pixels) {\n var j, k;\n var colors = this.colors;\n var palette = null;\n var alpha = this.hasAlphaChannel;\n\n if (this.palette.length) {\n palette = this._decodedPalette || (this._decodedPalette = this.decodePalette());\n colors = 4;\n alpha = true;\n }\n\n var data = imageData.data || imageData;\n var length = data.length;\n var input = palette || pixels;\n var i = j = 0;\n\n if (colors === 1) {\n while (i < length) {\n k = palette ? pixels[i / 4] * 4 : j;\n var v = input[k++];\n data[i++] = v;\n data[i++] = v;\n data[i++] = v;\n data[i++] = alpha ? input[k++] : 255;\n j = k;\n }\n } else {\n while (i < length) {\n k = palette ? pixels[i / 4] * 4 : j;\n data[i++] = input[k++];\n data[i++] = input[k++];\n data[i++] = input[k++];\n data[i++] = alpha ? input[k++] : 255;\n j = k;\n }\n }\n };\n\n PNG.prototype.decode = function () {\n var ret = new Uint8Array(this.width * this.height * 4);\n this.copyToImageData(ret, this.decodePixels());\n return ret;\n };\n\n PNG.prototype.decodeFrames = function (ctx) {\n if (!this.animation) {\n return;\n }\n\n for (var i = 0; i < this.animation.frames.length; i++) {\n var frame = this.animation.frames[i];\n var imageData = ctx.createImageData(frame.width, frame.height);\n var pixels = this.decodePixels(new Uint8Array(frame.data));\n this.copyToImageData(imageData, pixels);\n frame.imageData = imageData;\n frame.image = makeImage(imageData);\n }\n };\n\n PNG.prototype.renderFrame = function (ctx, number) {\n var frames = this.animation.frames;\n var frame = frames[number];\n var prev = frames[number - 1];\n\n if (number === 0) {\n ctx.clearRect(0, 0, this.width, this.height);\n }\n\n if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_BACKGROUND) {\n ctx.clearRect(prev.xOffset, prev.yOffset, prev.width, prev.height);\n } else if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_PREVIOUS) {\n ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset);\n }\n\n if (frame.blendOp === APNG_BLEND_OP_SOURCE) {\n ctx.clearRect(frame.xOffset, frame.yOffset, frame.width, frame.height);\n }\n\n return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset);\n };\n\n PNG.prototype.animate = function (ctx) {\n var _this = this;\n\n var frameNumber = 0;\n var _a = this.animation,\n numFrames = _a.numFrames,\n frames = _a.frames,\n numPlays = _a.numPlays;\n\n var doFrame = function () {\n var f = frameNumber++ % numFrames;\n var frame = frames[f];\n\n _this.renderFrame(ctx, f);\n\n if (numFrames > 1 && frameNumber / numFrames < numPlays) {\n _this.animation._timeout = setTimeout(doFrame, frame.delay);\n }\n };\n\n doFrame();\n };\n\n PNG.prototype.stopAnimation = function () {\n return clearTimeout(this.animation && this.animation._timeout);\n };\n\n PNG.prototype.render = function (canvas) {\n if (canvas._png) {\n canvas._png.stopAnimation();\n }\n\n canvas._png = this;\n canvas.width = this.width;\n canvas.height = this.height;\n var ctx = canvas.getContext('2d');\n\n if (this.animation) {\n this.decodeFrames(ctx);\n return this.animate(ctx);\n } else {\n var data = ctx.createImageData(this.width, this.height);\n this.copyToImageData(data, this.decodePixels());\n return ctx.putImageData(data, 0, 0);\n }\n };\n\n return PNG;\n }();\n\n return PNG;\n}();\n\n//# sourceURL=webpack://LithoSphere/./src/secondary/PNG/png.ts?"); +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _zlib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./zlib */ \"./src/secondary/PNG/zlib.ts\");\n\nvar APNG_DISPOSE_OP_BACKGROUND = 1;\nvar APNG_DISPOSE_OP_PREVIOUS = 2;\nvar APNG_BLEND_OP_SOURCE = 0;\nvar scratchCanvas = document.createElement('canvas');\nvar scratchCtx = scratchCanvas.getContext('2d');\n\nvar makeImage = function (imageData) {\n scratchCtx.width = imageData.width;\n scratchCtx.height = imageData.height;\n scratchCtx.clearRect(0, 0, imageData.width, imageData.height);\n scratchCtx.putImageData(imageData, 0, 0);\n var img = new Image();\n img.src = scratchCanvas.toDataURL();\n return img;\n};\n\nvar PNG = function () {\n function PNG(data1) {\n var i;\n this.data = data1;\n this.pos = 8;\n this.palette = [];\n this.imgData = [];\n this.transparency = {};\n this.animation = null;\n this.text = {};\n var frame = null;\n\n while (true) {\n var data;\n var chunkSize = this.readUInt32();\n var section = '';\n\n for (i = 0; i < 4; i++) {\n section += String.fromCharCode(this.data[this.pos++]);\n }\n\n switch (section) {\n case 'IHDR':\n this.width = this.readUInt32();\n this.height = this.readUInt32();\n this.bits = this.data[this.pos++];\n this.colorType = this.data[this.pos++];\n this.compressionMethod = this.data[this.pos++];\n this.filterMethod = this.data[this.pos++];\n this.interlaceMethod = this.data[this.pos++];\n break;\n\n case 'acTL':\n this.animation = {\n numFrames: this.readUInt32(),\n numPlays: this.readUInt32() || Infinity,\n frames: []\n };\n break;\n\n case 'PLTE':\n this.palette = this.read(chunkSize);\n break;\n\n case 'fcTL':\n if (frame) {\n this.animation.frames.push(frame);\n }\n\n this.pos += 4;\n frame = {\n width: this.readUInt32(),\n height: this.readUInt32(),\n xOffset: this.readUInt32(),\n yOffset: this.readUInt32()\n };\n var delayNum = this.readUInt16();\n var delayDen = this.readUInt16() || 100;\n frame.delay = 1000 * delayNum / delayDen;\n frame.disposeOp = this.data[this.pos++];\n frame.blendOp = this.data[this.pos++];\n frame.data = [];\n break;\n\n case 'IDAT':\n case 'fdAT':\n if (section === 'fdAT') {\n this.pos += 4;\n chunkSize -= 4;\n }\n\n data = frame && frame.data || this.imgData;\n\n for (i = 0; i < chunkSize; i++) {\n data.push(this.data[this.pos++]);\n }\n\n break;\n\n case 'tRNS':\n this.transparency = {};\n\n switch (this.colorType) {\n case 3:\n this.transparency.indexed = this.read(chunkSize);\n var short = 255 - this.transparency.indexed.length;\n\n if (short > 0) {\n for (i = 0; i < short; i++) {\n this.transparency.indexed.push(255);\n }\n }\n\n break;\n\n case 0:\n this.transparency.grayscale = this.read(chunkSize)[0];\n break;\n\n case 2:\n this.transparency.rgb = this.read(chunkSize);\n break;\n }\n\n break;\n\n case 'tEXt':\n var text = this.read(chunkSize);\n var index = text.indexOf(0);\n var key = String.fromCharCode.apply(String, text.slice(0, index));\n this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));\n break;\n\n case 'IEND':\n if (frame) {\n this.animation.frames.push(frame);\n }\n\n switch (this.colorType) {\n case 0:\n case 3:\n case 4:\n this.colors = 1;\n break;\n\n case 2:\n case 6:\n this.colors = 3;\n break;\n }\n\n this.hasAlphaChannel = [4, 6].includes(this.colorType);\n var colors = this.colors + (this.hasAlphaChannel ? 1 : 0);\n this.pixelBitlength = this.bits * colors;\n\n switch (this.colors) {\n case 1:\n this.colorSpace = 'DeviceGray';\n break;\n\n case 3:\n this.colorSpace = 'DeviceRGB';\n break;\n }\n\n this.imgData = new Uint8Array(this.imgData);\n return;\n break;\n\n default:\n this.pos += chunkSize;\n }\n\n this.pos += 4;\n\n if (this.pos > this.data.length) {\n throw new Error('Incomplete or corrupt PNG file');\n }\n }\n }\n\n PNG.load = function (url, options, callback, failureCallback) {\n var xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.responseType = 'arraybuffer';\n xhr.withCredentials = options.withCredentials;\n\n xhr.onload = function () {\n var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);\n\n if (xhr.status !== 404) {\n var png = new PNG(data);\n return typeof callback === 'function' ? callback(png) : undefined;\n } else if (typeof failureCallback === 'function') failureCallback(xhr.status);\n };\n\n return xhr.send();\n };\n\n PNG.prototype.read = function (bytes) {\n var result = new Array(bytes);\n\n for (var i = 0; i < bytes; i++) {\n result[i] = this.data[this.pos++];\n }\n\n return result;\n };\n\n PNG.prototype.readUInt32 = function () {\n var b1 = this.data[this.pos++] << 24;\n var b2 = this.data[this.pos++] << 16;\n var b3 = this.data[this.pos++] << 8;\n var b4 = this.data[this.pos++];\n return b1 | b2 | b3 | b4;\n };\n\n PNG.prototype.readUInt16 = function () {\n var b1 = this.data[this.pos++] << 8;\n var b2 = this.data[this.pos++];\n return b1 | b2;\n };\n\n PNG.prototype.decodePixels = function (data) {\n if (data == null) {\n data = this.imgData;\n }\n\n if (data.length === 0) {\n return new Uint8Array(0);\n }\n\n data = new _zlib__WEBPACK_IMPORTED_MODULE_0__[\"FlateStream\"](data);\n data = data.getBytes();\n\n var _a = this,\n width = _a.width,\n height = _a.height;\n\n var pixelBytes = this.pixelBitlength / 8;\n var pixels = new Uint8Array(width * height * pixelBytes);\n var length = data.length;\n var pos = 0;\n\n function pass(x0, y0, dx, dy, singlePass) {\n if (singlePass === void 0) {\n singlePass = false;\n }\n\n var w = Math.ceil((width - x0) / dx);\n var h = Math.ceil((height - y0) / dy);\n var scanlineLength = pixelBytes * w;\n var buffer = singlePass ? pixels : new Uint8Array(scanlineLength * h);\n var row = 0;\n var c = 0;\n\n while (row < h && pos < length) {\n var byte, col, i, left, upper;\n\n switch (data[pos++]) {\n case 0:\n for (i = 0; i < scanlineLength; i++) {\n buffer[c++] = data[pos++];\n }\n\n break;\n\n case 1:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n buffer[c++] = (byte + left) % 256;\n }\n\n break;\n\n case 2:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n buffer[c++] = (upper + byte) % 256;\n }\n\n break;\n\n case 3:\n for (i = 0; i < scanlineLength; i++) {\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n upper = row && buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n buffer[c++] = (byte + Math.floor((left + upper) / 2)) % 256;\n }\n\n break;\n\n case 4:\n for (i = 0; i < scanlineLength; i++) {\n var paeth, upperLeft;\n byte = data[pos++];\n col = (i - i % pixelBytes) / pixelBytes;\n left = i < pixelBytes ? 0 : buffer[c - pixelBytes];\n\n if (row === 0) {\n upper = upperLeft = 0;\n } else {\n upper = buffer[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];\n upperLeft = col && buffer[(row - 1) * scanlineLength + (col - 1) * pixelBytes + i % pixelBytes];\n }\n\n var p = left + upper - upperLeft;\n var pa = Math.abs(p - left);\n var pb = Math.abs(p - upper);\n var pc = Math.abs(p - upperLeft);\n\n if (pa <= pb && pa <= pc) {\n paeth = left;\n } else if (pb <= pc) {\n paeth = upper;\n } else {\n paeth = upperLeft;\n }\n\n buffer[c++] = (byte + paeth) % 256;\n }\n\n break;\n\n default:\n throw new Error(\"Invalid filter algorithm: \" + data[pos - 1]);\n }\n\n if (!singlePass) {\n var pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes;\n var bufferPos = row * scanlineLength;\n\n for (i = 0; i < w; i++) {\n for (var j = 0; j < pixelBytes; j++) pixels[pixelsPos++] = buffer[bufferPos++];\n\n pixelsPos += (dx - 1) * pixelBytes;\n }\n }\n\n row++;\n }\n }\n\n if (this.interlaceMethod === 1) {\n pass(0, 0, 8, 8);\n pass(4, 0, 8, 8);\n pass(0, 4, 4, 8);\n pass(2, 0, 4, 4);\n pass(0, 2, 2, 4);\n pass(1, 0, 2, 2);\n pass(0, 1, 1, 2);\n } else {\n pass(0, 0, 1, 1, true);\n }\n\n return pixels;\n };\n\n PNG.prototype.decodePalette = function () {\n var palette = this.palette;\n var length = palette.length;\n var transparency = this.transparency.indexed || [];\n var ret = new Uint8Array((transparency.length || 0) + length);\n var pos = 0;\n var c = 0;\n\n for (var i = 0; i < length; i += 3) {\n var left;\n ret[pos++] = palette[i];\n ret[pos++] = palette[i + 1];\n ret[pos++] = palette[i + 2];\n ret[pos++] = (left = transparency[c++]) != null ? left : 255;\n }\n\n return ret;\n };\n\n PNG.prototype.copyToImageData = function (imageData, pixels) {\n var j, k;\n var colors = this.colors;\n var palette = null;\n var alpha = this.hasAlphaChannel;\n\n if (this.palette.length) {\n palette = this._decodedPalette || (this._decodedPalette = this.decodePalette());\n colors = 4;\n alpha = true;\n }\n\n var data = imageData.data || imageData;\n var length = data.length;\n var input = palette || pixels;\n var i = j = 0;\n\n if (colors === 1) {\n while (i < length) {\n k = palette ? pixels[i / 4] * 4 : j;\n var v = input[k++];\n data[i++] = v;\n data[i++] = v;\n data[i++] = v;\n data[i++] = alpha ? input[k++] : 255;\n j = k;\n }\n } else {\n while (i < length) {\n k = palette ? pixels[i / 4] * 4 : j;\n data[i++] = input[k++];\n data[i++] = input[k++];\n data[i++] = input[k++];\n data[i++] = alpha ? input[k++] : 255;\n j = k;\n }\n }\n };\n\n PNG.prototype.decode = function () {\n var ret = new Uint8Array(this.width * this.height * 4);\n this.copyToImageData(ret, this.decodePixels());\n return ret;\n };\n\n PNG.prototype.decodeFrames = function (ctx) {\n if (!this.animation) {\n return;\n }\n\n for (var i = 0; i < this.animation.frames.length; i++) {\n var frame = this.animation.frames[i];\n var imageData = ctx.createImageData(frame.width, frame.height);\n var pixels = this.decodePixels(new Uint8Array(frame.data));\n this.copyToImageData(imageData, pixels);\n frame.imageData = imageData;\n frame.image = makeImage(imageData);\n }\n };\n\n PNG.prototype.renderFrame = function (ctx, number) {\n var frames = this.animation.frames;\n var frame = frames[number];\n var prev = frames[number - 1];\n\n if (number === 0) {\n ctx.clearRect(0, 0, this.width, this.height);\n }\n\n if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_BACKGROUND) {\n ctx.clearRect(prev.xOffset, prev.yOffset, prev.width, prev.height);\n } else if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_PREVIOUS) {\n ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset);\n }\n\n if (frame.blendOp === APNG_BLEND_OP_SOURCE) {\n ctx.clearRect(frame.xOffset, frame.yOffset, frame.width, frame.height);\n }\n\n return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset);\n };\n\n PNG.prototype.animate = function (ctx) {\n var _this = this;\n\n var frameNumber = 0;\n var _a = this.animation,\n numFrames = _a.numFrames,\n frames = _a.frames,\n numPlays = _a.numPlays;\n\n var doFrame = function () {\n var f = frameNumber++ % numFrames;\n var frame = frames[f];\n\n _this.renderFrame(ctx, f);\n\n if (numFrames > 1 && frameNumber / numFrames < numPlays) {\n _this.animation._timeout = setTimeout(doFrame, frame.delay);\n }\n };\n\n doFrame();\n };\n\n PNG.prototype.stopAnimation = function () {\n return clearTimeout(this.animation && this.animation._timeout);\n };\n\n PNG.prototype.render = function (canvas) {\n if (canvas._png) {\n canvas._png.stopAnimation();\n }\n\n canvas._png = this;\n canvas.width = this.width;\n canvas.height = this.height;\n var ctx = canvas.getContext('2d');\n\n if (this.animation) {\n this.decodeFrames(ctx);\n return this.animate(ctx);\n } else {\n var data = ctx.createImageData(this.width, this.height);\n this.copyToImageData(data, this.decodePixels());\n return ctx.putImageData(data, 0, 0);\n }\n };\n\n return PNG;\n}();\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (PNG);\n\n//# sourceURL=webpack://LithoSphere/./src/secondary/PNG/png.ts?"); /***/ }), @@ -2099,10 +2100,11 @@ eval("window.PNG = function () {\n var APNG_DISPOSE_OP_BACKGROUND = 1;\n var A /*!***********************************!*\ !*** ./src/secondary/PNG/zlib.ts ***! \***********************************/ -/*! no static exports found */ -/***/ (function(module, exports) { +/*! exports provided: FlateStream */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { -eval("window.DecodeStream = function () {\n function constructor() {\n this.pos = 0;\n this.bufferLength = 0;\n this.eof = false;\n this.buffer = null;\n }\n\n constructor.prototype = {\n ensureBuffer: function decodestream_ensureBuffer(requested) {\n var buffer = this.buffer;\n var current = buffer ? buffer.byteLength : 0;\n if (requested < current) return buffer;\n var size = 512;\n\n while (size < requested) size <<= 1;\n\n var buffer2 = new Uint8Array(size);\n\n for (var i = 0; i < current; ++i) buffer2[i] = buffer[i];\n\n return this.buffer = buffer2;\n },\n getByte: function decodestream_getByte() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return this.buffer[this.pos++];\n },\n getBytes: function decodestream_getBytes(length) {\n var pos = this.pos;\n\n if (length) {\n this.ensureBuffer(pos + length);\n var end = pos + length;\n\n while (!this.eof && this.bufferLength < end) this.readBlock();\n\n var bufEnd = this.bufferLength;\n if (end > bufEnd) end = bufEnd;\n } else {\n while (!this.eof) this.readBlock();\n\n var end = this.bufferLength;\n }\n\n this.pos = end;\n return this.buffer.subarray(pos, end);\n },\n lookChar: function decodestream_lookChar() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return String.fromCharCode(this.buffer[this.pos]);\n },\n getChar: function decodestream_getChar() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return String.fromCharCode(this.buffer[this.pos++]);\n },\n makeSubStream: function decodestream_makeSubstream(start, length, dict) {\n var end = start + length;\n\n while (this.bufferLength <= end && !this.eof) this.readBlock();\n\n return new Stream(this.buffer, start, length, dict);\n },\n skip: function decodestream_skip(n) {\n if (!n) n = 1;\n this.pos += n;\n },\n reset: function decodestream_reset() {\n this.pos = 0;\n }\n };\n return constructor;\n}();\n\nwindow.FlateStream = function () {\n var codeLenCodeMap = new Uint32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n var lengthDecode = new Uint32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);\n var distDecode = new Uint32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);\n var fixedLitCodeTab = [new Uint32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];\n var fixedDistCodeTab = [new Uint32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];\n\n function error(e) {\n throw new Error(e);\n }\n\n function constructor(bytes) {\n var bytesPos = 0;\n var cmf = bytes[bytesPos++];\n var flg = bytes[bytesPos++];\n if (cmf == -1 || flg == -1) error('Invalid header in flate stream');\n if ((cmf & 0x0f) != 0x08) error('Unknown compression method in flate stream');\n if (((cmf << 8) + flg) % 31 != 0) error('Bad FCHECK in flate stream');\n if (flg & 0x20) error('FDICT bit set in flate stream');\n this.bytes = bytes;\n this.bytesPos = bytesPos;\n this.codeSize = 0;\n this.codeBuf = 0;\n DecodeStream.call(this);\n }\n\n constructor.prototype = Object.create(DecodeStream.prototype);\n\n constructor.prototype.getBits = function (bits) {\n var codeSize = this.codeSize;\n var codeBuf = this.codeBuf;\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n var b;\n\n while (codeSize < bits) {\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad encoding in flate stream');\n codeBuf |= b << codeSize;\n codeSize += 8;\n }\n\n b = codeBuf & (1 << bits) - 1;\n this.codeBuf = codeBuf >> bits;\n this.codeSize = codeSize -= bits;\n this.bytesPos = bytesPos;\n return b;\n };\n\n constructor.prototype.getCode = function (table) {\n var codes = table[0];\n var maxLen = table[1];\n var codeSize = this.codeSize;\n var codeBuf = this.codeBuf;\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n\n while (codeSize < maxLen) {\n var b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad encoding in flate stream');\n codeBuf |= b << codeSize;\n codeSize += 8;\n }\n\n var code = codes[codeBuf & (1 << maxLen) - 1];\n var codeLen = code >> 16;\n var codeVal = code & 0xffff;\n if (codeSize == 0 || codeSize < codeLen || codeLen == 0) error('Bad encoding in flate stream');\n this.codeBuf = codeBuf >> codeLen;\n this.codeSize = codeSize - codeLen;\n this.bytesPos = bytesPos;\n return codeVal;\n };\n\n constructor.prototype.generateHuffmanTable = function (lengths) {\n var n = lengths.length;\n var maxLen = 0;\n\n for (var i = 0; i < n; ++i) {\n if (lengths[i] > maxLen) maxLen = lengths[i];\n }\n\n var size = 1 << maxLen;\n var codes = new Uint32Array(size);\n\n for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {\n for (var val = 0; val < n; ++val) {\n if (lengths[val] == len) {\n var code2 = 0;\n var t = code;\n\n for (var i = 0; i < len; ++i) {\n code2 = code2 << 1 | t & 1;\n t >>= 1;\n }\n\n for (var i = code2; i < size; i += skip) codes[i] = len << 16 | val;\n\n ++code;\n }\n }\n }\n\n return [codes, maxLen];\n };\n\n constructor.prototype.readBlock = function () {\n function repeat(stream, array, len, offset, what) {\n var repeat = stream.getBits(len) + offset;\n\n while (repeat-- > 0) array[i++] = what;\n }\n\n var hdr = this.getBits(3);\n if (hdr & 1) this.eof = true;\n hdr >>= 1;\n\n if (hdr == 0) {\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n var b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n var blockLen = b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n blockLen |= b << 8;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n var check = b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n check |= b << 8;\n if (check != (~blockLen & 0xffff)) error('Bad uncompressed block length in flate stream');\n this.codeBuf = 0;\n this.codeSize = 0;\n var bufferLength = this.bufferLength;\n var buffer = this.ensureBuffer(bufferLength + blockLen);\n var end = bufferLength + blockLen;\n this.bufferLength = end;\n\n for (var n = bufferLength; n < end; ++n) {\n if (typeof (b = bytes[bytesPos++]) == 'undefined') {\n this.eof = true;\n break;\n }\n\n buffer[n] = b;\n }\n\n this.bytesPos = bytesPos;\n return;\n }\n\n var litCodeTable;\n var distCodeTable;\n\n if (hdr == 1) {\n litCodeTable = fixedLitCodeTab;\n distCodeTable = fixedDistCodeTab;\n } else if (hdr == 2) {\n var numLitCodes = this.getBits(5) + 257;\n var numDistCodes = this.getBits(5) + 1;\n var numCodeLenCodes = this.getBits(4) + 4;\n var codeLenCodeLengths = Array(codeLenCodeMap.length);\n var i = 0;\n\n while (i < numCodeLenCodes) codeLenCodeLengths[codeLenCodeMap[i++]] = this.getBits(3);\n\n var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);\n var len = 0;\n var i = 0;\n var codes = numLitCodes + numDistCodes;\n var codeLengths = new Array(codes);\n\n while (i < codes) {\n var code = this.getCode(codeLenCodeTab);\n\n if (code == 16) {\n repeat(this, codeLengths, 2, 3, len);\n } else if (code == 17) {\n repeat(this, codeLengths, 3, 3, len = 0);\n } else if (code == 18) {\n repeat(this, codeLengths, 7, 11, len = 0);\n } else {\n codeLengths[i++] = len = code;\n }\n }\n\n litCodeTable = this.generateHuffmanTable(codeLengths.slice(0, numLitCodes));\n distCodeTable = this.generateHuffmanTable(codeLengths.slice(numLitCodes, codes));\n } else {\n error('Unknown block type in flate stream');\n }\n\n var buffer = this.buffer;\n var limit = buffer ? buffer.length : 0;\n var pos = this.bufferLength;\n\n while (true) {\n var code1 = this.getCode(litCodeTable);\n\n if (code1 < 256) {\n if (pos + 1 >= limit) {\n buffer = this.ensureBuffer(pos + 1);\n limit = buffer.length;\n }\n\n buffer[pos++] = code1;\n continue;\n }\n\n if (code1 == 256) {\n this.bufferLength = pos;\n return;\n }\n\n code1 -= 257;\n code1 = lengthDecode[code1];\n var code2 = code1 >> 16;\n if (code2 > 0) code2 = this.getBits(code2);\n var len = (code1 & 0xffff) + code2;\n code1 = this.getCode(distCodeTable);\n code1 = distDecode[code1];\n code2 = code1 >> 16;\n if (code2 > 0) code2 = this.getBits(code2);\n var dist = (code1 & 0xffff) + code2;\n\n if (pos + len >= limit) {\n buffer = this.ensureBuffer(pos + len);\n limit = buffer.length;\n }\n\n for (var k = 0; k < len; ++k, ++pos) buffer[pos] = buffer[pos - dist];\n }\n };\n\n return constructor;\n}();\n\n//# sourceURL=webpack://LithoSphere/./src/secondary/PNG/zlib.ts?"); +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"FlateStream\", function() { return FlateStream; });\nvar DecodeStream = function () {\n function constructor() {\n this.pos = 0;\n this.bufferLength = 0;\n this.eof = false;\n this.buffer = null;\n }\n\n constructor.prototype = {\n ensureBuffer: function decodestream_ensureBuffer(requested) {\n var buffer = this.buffer;\n var current = buffer ? buffer.byteLength : 0;\n if (requested < current) return buffer;\n var size = 512;\n\n while (size < requested) size <<= 1;\n\n var buffer2 = new Uint8Array(size);\n\n for (var i = 0; i < current; ++i) buffer2[i] = buffer[i];\n\n return this.buffer = buffer2;\n },\n getByte: function decodestream_getByte() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return this.buffer[this.pos++];\n },\n getBytes: function decodestream_getBytes(length) {\n var pos = this.pos;\n\n if (length) {\n this.ensureBuffer(pos + length);\n var end = pos + length;\n\n while (!this.eof && this.bufferLength < end) this.readBlock();\n\n var bufEnd = this.bufferLength;\n if (end > bufEnd) end = bufEnd;\n } else {\n while (!this.eof) this.readBlock();\n\n var end = this.bufferLength;\n }\n\n this.pos = end;\n return this.buffer.subarray(pos, end);\n },\n lookChar: function decodestream_lookChar() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return String.fromCharCode(this.buffer[this.pos]);\n },\n getChar: function decodestream_getChar() {\n var pos = this.pos;\n\n while (this.bufferLength <= pos) {\n if (this.eof) return null;\n this.readBlock();\n }\n\n return String.fromCharCode(this.buffer[this.pos++]);\n },\n makeSubStream: function decodestream_makeSubstream(start, length, dict) {\n var end = start + length;\n\n while (this.bufferLength <= end && !this.eof) this.readBlock();\n\n return new Stream(this.buffer, start, length, dict);\n },\n skip: function decodestream_skip(n) {\n if (!n) n = 1;\n this.pos += n;\n },\n reset: function decodestream_reset() {\n this.pos = 0;\n }\n };\n return constructor;\n}();\n\nvar FlateStream = function () {\n var codeLenCodeMap = new Uint32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n var lengthDecode = new Uint32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);\n var distDecode = new Uint32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);\n var fixedLitCodeTab = [new Uint32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];\n var fixedDistCodeTab = [new Uint32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];\n\n function error(e) {\n throw new Error(e);\n }\n\n function constructor(bytes) {\n var bytesPos = 0;\n var cmf = bytes[bytesPos++];\n var flg = bytes[bytesPos++];\n if (cmf == -1 || flg == -1) error('Invalid header in flate stream');\n if ((cmf & 0x0f) != 0x08) error('Unknown compression method in flate stream');\n if (((cmf << 8) + flg) % 31 != 0) error('Bad FCHECK in flate stream');\n if (flg & 0x20) error('FDICT bit set in flate stream');\n this.bytes = bytes;\n this.bytesPos = bytesPos;\n this.codeSize = 0;\n this.codeBuf = 0;\n DecodeStream.call(this);\n }\n\n constructor.prototype = Object.create(DecodeStream.prototype);\n\n constructor.prototype.getBits = function (bits) {\n var codeSize = this.codeSize;\n var codeBuf = this.codeBuf;\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n var b;\n\n while (codeSize < bits) {\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad encoding in flate stream');\n codeBuf |= b << codeSize;\n codeSize += 8;\n }\n\n b = codeBuf & (1 << bits) - 1;\n this.codeBuf = codeBuf >> bits;\n this.codeSize = codeSize -= bits;\n this.bytesPos = bytesPos;\n return b;\n };\n\n constructor.prototype.getCode = function (table) {\n var codes = table[0];\n var maxLen = table[1];\n var codeSize = this.codeSize;\n var codeBuf = this.codeBuf;\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n\n while (codeSize < maxLen) {\n var b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad encoding in flate stream');\n codeBuf |= b << codeSize;\n codeSize += 8;\n }\n\n var code = codes[codeBuf & (1 << maxLen) - 1];\n var codeLen = code >> 16;\n var codeVal = code & 0xffff;\n if (codeSize == 0 || codeSize < codeLen || codeLen == 0) error('Bad encoding in flate stream');\n this.codeBuf = codeBuf >> codeLen;\n this.codeSize = codeSize - codeLen;\n this.bytesPos = bytesPos;\n return codeVal;\n };\n\n constructor.prototype.generateHuffmanTable = function (lengths) {\n var n = lengths.length;\n var maxLen = 0;\n\n for (var i = 0; i < n; ++i) {\n if (lengths[i] > maxLen) maxLen = lengths[i];\n }\n\n var size = 1 << maxLen;\n var codes = new Uint32Array(size);\n\n for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {\n for (var val = 0; val < n; ++val) {\n if (lengths[val] == len) {\n var code2 = 0;\n var t = code;\n\n for (var i = 0; i < len; ++i) {\n code2 = code2 << 1 | t & 1;\n t >>= 1;\n }\n\n for (var i = code2; i < size; i += skip) codes[i] = len << 16 | val;\n\n ++code;\n }\n }\n }\n\n return [codes, maxLen];\n };\n\n constructor.prototype.readBlock = function () {\n function repeat(stream, array, len, offset, what) {\n var repeat = stream.getBits(len) + offset;\n\n while (repeat-- > 0) array[i++] = what;\n }\n\n var hdr = this.getBits(3);\n if (hdr & 1) this.eof = true;\n hdr >>= 1;\n\n if (hdr == 0) {\n var bytes = this.bytes;\n var bytesPos = this.bytesPos;\n var b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n var blockLen = b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n blockLen |= b << 8;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n var check = b;\n if (typeof (b = bytes[bytesPos++]) == 'undefined') error('Bad block header in flate stream');\n check |= b << 8;\n if (check != (~blockLen & 0xffff)) error('Bad uncompressed block length in flate stream');\n this.codeBuf = 0;\n this.codeSize = 0;\n var bufferLength = this.bufferLength;\n var buffer = this.ensureBuffer(bufferLength + blockLen);\n var end = bufferLength + blockLen;\n this.bufferLength = end;\n\n for (var n = bufferLength; n < end; ++n) {\n if (typeof (b = bytes[bytesPos++]) == 'undefined') {\n this.eof = true;\n break;\n }\n\n buffer[n] = b;\n }\n\n this.bytesPos = bytesPos;\n return;\n }\n\n var litCodeTable;\n var distCodeTable;\n\n if (hdr == 1) {\n litCodeTable = fixedLitCodeTab;\n distCodeTable = fixedDistCodeTab;\n } else if (hdr == 2) {\n var numLitCodes = this.getBits(5) + 257;\n var numDistCodes = this.getBits(5) + 1;\n var numCodeLenCodes = this.getBits(4) + 4;\n var codeLenCodeLengths = Array(codeLenCodeMap.length);\n var i = 0;\n\n while (i < numCodeLenCodes) codeLenCodeLengths[codeLenCodeMap[i++]] = this.getBits(3);\n\n var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);\n var len = 0;\n var i = 0;\n var codes = numLitCodes + numDistCodes;\n var codeLengths = new Array(codes);\n\n while (i < codes) {\n var code = this.getCode(codeLenCodeTab);\n\n if (code == 16) {\n repeat(this, codeLengths, 2, 3, len);\n } else if (code == 17) {\n repeat(this, codeLengths, 3, 3, len = 0);\n } else if (code == 18) {\n repeat(this, codeLengths, 7, 11, len = 0);\n } else {\n codeLengths[i++] = len = code;\n }\n }\n\n litCodeTable = this.generateHuffmanTable(codeLengths.slice(0, numLitCodes));\n distCodeTable = this.generateHuffmanTable(codeLengths.slice(numLitCodes, codes));\n } else {\n error('Unknown block type in flate stream');\n }\n\n var buffer = this.buffer;\n var limit = buffer ? buffer.length : 0;\n var pos = this.bufferLength;\n\n while (true) {\n var code1 = this.getCode(litCodeTable);\n\n if (code1 < 256) {\n if (pos + 1 >= limit) {\n buffer = this.ensureBuffer(pos + 1);\n limit = buffer.length;\n }\n\n buffer[pos++] = code1;\n continue;\n }\n\n if (code1 == 256) {\n this.bufferLength = pos;\n return;\n }\n\n code1 -= 257;\n code1 = lengthDecode[code1];\n var code2 = code1 >> 16;\n if (code2 > 0) code2 = this.getBits(code2);\n var len = (code1 & 0xffff) + code2;\n code1 = this.getCode(distCodeTable);\n code1 = distDecode[code1];\n code2 = code1 >> 16;\n if (code2 > 0) code2 = this.getBits(code2);\n var dist = (code1 & 0xffff) + code2;\n\n if (pos + len >= limit) {\n buffer = this.ensureBuffer(pos + len);\n limit = buffer.length;\n }\n\n for (var k = 0; k < len; ++k, ++pos) buffer[pos] = buffer[pos - dist];\n }\n };\n\n return constructor;\n}();\n\n//# sourceURL=webpack://LithoSphere/./src/secondary/PNG/zlib.ts?"); /***/ }), diff --git a/dist/src/constants.d.ts b/dist/src/constants.d.ts deleted file mode 100644 index f719e40..0000000 --- a/dist/src/constants.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const NO_DATA_VALUE_INTERNAL = -1100101; diff --git a/dist/src/controls/altitude.d.ts b/dist/src/controls/altitude.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/controls/compass.d.ts b/dist/src/controls/compass.d.ts deleted file mode 100644 index 1647cdc..0000000 --- a/dist/src/controls/compass.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -export default class Compass { - _: Private; - p: any; - name: string; - corner: Corners; - constructor(parent: any, name: string); - getControl: () => string; - attachEvents: () => void; - onUpdate: () => void; - setDirection: () => void; -} -export {}; diff --git a/dist/src/controls/controls.d.ts b/dist/src/controls/controls.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/controls/coordinates.d.ts b/dist/src/controls/coordinates.d.ts deleted file mode 100644 index ea00e2c..0000000 --- a/dist/src/controls/coordinates.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -interface Params { - existingDivId?: string; -} -export default class Coordinates { - _: Private; - p: any; - name: string; - params: Params; - corner: Corners; - constructor(parent: any, name: string, params?: object); - getControl: () => string; - attachEvents: () => void; - onUpdate: () => void; - private updateMouseCoords; -} -export {}; diff --git a/dist/src/controls/crop.d.ts b/dist/src/controls/crop.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/controls/exaggerate.d.ts b/dist/src/controls/exaggerate.d.ts deleted file mode 100644 index f2c1d1e..0000000 --- a/dist/src/controls/exaggerate.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -export default class Exaggerate { - _: Private; - id: string; - p: any; - name: string; - corner: Corners; - exaggeration: number; - constructor(parent: any, name: string); - getControl: () => string; - attachEvents: () => void; - private getInactiveContent; - private getActiveContent; - setExaggeration: (multiplier: number) => void; -} -export {}; diff --git a/dist/src/controls/home.d.ts b/dist/src/controls/home.d.ts deleted file mode 100644 index 47bcf19..0000000 --- a/dist/src/controls/home.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Corners } from '../generalTypes'; -interface Private { -} -export default class Home { - _: Private; - p: any; - name: string; - corner: Corners; - constructor(parent: any, name: string); - getControl: () => string; - attachEvents: () => void; -} -export {}; diff --git a/dist/src/controls/index.d.ts b/dist/src/controls/index.d.ts deleted file mode 100644 index 37d3725..0000000 --- a/dist/src/controls/index.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Corners } from '../generalTypes'; -export default class Controls { - p: any; - controlContainer: HTMLElement; - corners: { - TopLeft: HTMLElement; - TopRight: HTMLElement; - BottomLeft: HTMLElement; - BottomRight: HTMLElement; - }; - activeControls: any; - compass: any; - coordinates: any; - home: any; - layers: any; - exaggerate: any; - observe: any; - walk: any; - link: any; - constructor(parent: any); - addControl: (name: string, control: any, params?: object, corner?: Corners) => any; - removeControl: (name: any) => void; - _onUpdateEvent: () => void; - _onMove: (lng: any, lat: any, height: any) => void; - _onMouseMove: (lng: any, lat: any, height: any) => void; - _onMouseOut: (e?: any) => void; - _onFirstPersonUpdate: () => void; - _onOrbitalUpdate: (e?: any) => void; -} diff --git a/dist/src/controls/layers.d.ts b/dist/src/controls/layers.d.ts deleted file mode 100644 index f9d1646..0000000 --- a/dist/src/controls/layers.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -export default class Layers { - _: Private; - id: string; - p: any; - name: string; - corner: Corners; - constructor(parent: any, name: string); - getControl: () => string; - attachEvents: () => void; - private getInactiveContent; - private getActiveContent; - private attachEventsInternal; -} -export {}; diff --git a/dist/src/controls/link.d.ts b/dist/src/controls/link.d.ts deleted file mode 100644 index 054ff1d..0000000 --- a/dist/src/controls/link.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Corners } from '../generalTypes'; -import { Object3D } from 'three'; -interface Private { - linkPanned: boolean; - linkPannedTimeout: any; - targetPoint?: Object3D; -} -export default class Link { - _: Private; - p: any; - name: string; - params: any; - corner: Corners; - return: any; - constructor(parent: any, name: string, params?: object); - getControl: () => string; - attachEvents: () => void; - getReturn: () => any; - onMove: (lng: any, lat: any, height: any) => void; - onMouseMove: (lng: any, lat: any, height: any) => void; - onMouseOut: () => void; - onFirstPersonUpdate: () => void; - onOrbitalUpdate: () => void; - setLink: (latlng?: any, style?: any, spriteId?: string) => void; - linkMove: (lng: number, lat: number) => void; - linkMouseMove: (lng: number, lat: number) => void; - linkMouseOut: () => void; -} -export {}; diff --git a/dist/src/controls/observe.d.ts b/dist/src/controls/observe.d.ts deleted file mode 100644 index ff6c83c..0000000 --- a/dist/src/controls/observe.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -export default class Observe { - _: Private; - p: any; - name: string; - id: string; - helpDiv: HTMLElement; - corner: Corners; - constructor(parent: any, name: string); - getControl: () => string; - private getInactiveContent; - private getActiveContent; - attachEvents: () => void; - private setCamera; - private leaveObserver; - private getObserverValues; - private keydownObserverSettings; - private toggleFOVOverlay; - private updateFOVOverlayBounds; -} -export {}; diff --git a/dist/src/controls/walk.d.ts b/dist/src/controls/walk.d.ts deleted file mode 100644 index df7bcef..0000000 --- a/dist/src/controls/walk.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Corners } from '../generalTypes.d.ts'; -interface Private { -} -export default class Walk { - _: Private; - p: any; - name: string; - helpDiv: HTMLElement; - corner: Corners; - constructor(parent: any, name: string); - getControl: () => string; - attachEvents: () => void; - private setCamera; - private leaveWalking; -} -export {}; diff --git a/dist/src/core/cameras.d.ts b/dist/src/core/cameras.d.ts deleted file mode 100644 index 11443e5..0000000 --- a/dist/src/core/cameras.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Vector2, Vector3 } from 'three'; -interface Private { - keepNear: boolean; - crosshair: HTMLElement; -} -interface Orbit { - camera: any; - controls: any; - near: number; - far: number; -} -interface FirstPerson { - camera: any; - controls: any; - lockControls: boolean; - height: 3; -} -export default class Camera { - _: Private; - container: HTMLElement; - sceneContainer: HTMLElement; - camera: any; - controls: any; - orbit: Orbit; - firstPerson: FirstPerson; - isFirstPerson: boolean; - isShift: boolean; - moveForward?: boolean; - moveBackward?: boolean; - moveLeft?: boolean; - moveRight?: boolean; - canJump?: boolean; - prevTime?: number; - velocity?: Vector3; - constructor(container: HTMLElement, sceneContainer: HTMLElement, scene: any, projection: any); - reset(): void; - _init(scene: any, projection: any): void; - swap(lockControls: any, skipLock: any): void; - private inToFirstPerson; - private outFromFirstPerson; - private toggleCrosshair; - private requestPointerLocking; - setupEvents(): void; - onKeyDown: (event: KeyboardEvent) => void; - onKeyUp: (event: KeyboardEvent) => void; - updateSize: () => void; - setNearFarPlane: (farther: any, near: any, far: any, keepNear: any) => void; - setFirstPersonHeight: (height: any) => void; - getFirstPersonFocalLength: () => number; - setFirstPersonFocalLength: (focalLength: any) => void; - getFirstPersonFOV: () => number; - setFirstPersonFOV: (fov: any) => void; - getFirstPersonAspect: () => number; - setFirstPersonAspect: (aspect: any) => void; - setCameraAzimuthElevation: (az: any, el: any, cameraIsFirstPerson: any) => void; - update: () => Vector2; -} -export {}; diff --git a/dist/src/core/events.d.ts b/dist/src/core/events.d.ts deleted file mode 100644 index 32da82c..0000000 --- a/dist/src/core/events.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -interface Private { - mouseXY: { - x: number; - y: number; - }; - prevMouseXY: { - x: number; - y: number; - }; - containerXY: { - x: number; - y: number; - }; - lastZoomDelta: number; - desiredZoom: number; - zoomedSince: number; - zoomWait: number; - highlightTimeout: any; -} -export default class Events { - _: Private; - p: any; - activeFeature: any; - hoveredFeature: any; - hoverInfo: HTMLElement; - constructor(parent: any); - _init(): void; - _rotateGlobe: (e: any, prevXY?: any) => void; - private _rotateAroundArbAxis; - private _rotateGlobe_MouseDown; - private _rotateGlobe_MouseUp; - _checkDesiredZoom(): void; - private _setZoom; - _onZoom: (e?: any) => void; - _onTouchZoom: (e: any) => void; - _matchPlanetsLODToPlanet(): void; - _refreshFrontGroupRotation(): void; - private _onClick; - _onMouseMove: (e?: any) => void; - private _updateMouseCoords; - private updateHoverInfoPosition; - private _highlightFeature; - private _unhighlightHoveredFeature; - private setHoveredFeature; - private clearHoveredFeature; - private setActiveFeature; - private clearActiveFeature; - _attenuate(): void; -} -export {}; diff --git a/dist/src/core/renderer.d.ts b/dist/src/core/renderer.d.ts deleted file mode 100644 index a928eea..0000000 --- a/dist/src/core/renderer.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default class Renderer { - renderer: any; - container: HTMLElement; - constructor(container: HTMLElement); - _init(): void; - updateSize: () => void; - remove(): void; -} diff --git a/dist/src/core/shaders.d.ts b/dist/src/core/shaders.d.ts deleted file mode 100644 index da70435..0000000 --- a/dist/src/core/shaders.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ShaderMaterial } from 'three'; -declare const Shaders: { - simplePoint: () => ShaderMaterial; - multiTexture: (textures: any, fadeIn?: boolean) => ShaderMaterial; - atmosphere: (color?: string) => ShaderMaterial; -}; -export default Shaders; diff --git a/dist/src/layers/clamped.d.ts b/dist/src/layers/clamped.d.ts deleted file mode 100644 index 3efb0f4..0000000 --- a/dist/src/layers/clamped.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { XYZ } from '../generalTypes.d.ts'; -export default class ClampedLayerer { - p: any; - constructor(parent: any); - add: (layerObj: any, callback?: Function) => void; - toggle: (name: string, on?: boolean) => boolean; - setOpacity: (name: string, opacity: number) => boolean; - remove: (name: string) => boolean; - getClampedTexture: (i: number, xyz: XYZ) => any; -} diff --git a/dist/src/layers/curtain.d.ts b/dist/src/layers/curtain.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/layers/index.d.ts b/dist/src/layers/index.d.ts deleted file mode 100644 index 3bc8652..0000000 --- a/dist/src/layers/index.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -import Tile3dLayerer from './tile3d'; -import TileLayerer from './tile'; -import ClampedLayerer from './clamped'; -import VectorLayerer from './vector'; -interface Private { - layerers: { - tile3d: Tile3dLayerer; - tile: TileLayerer; - clamped: ClampedLayerer; - vector: VectorLayerer; - }; -} -export default class Layers { - _: Private; - p: any; - baseStyle: any; - tile3d: any; - tile: any; - clamped: any; - vector: any; - all: any; - constructor(parent: any); - _reset(): void; - addLayer: (type: string, layerObj: any, callback?: Function, sI?: number) => void; - removeLayer: (name: string) => boolean; - toggleLayer: (name: string, on?: boolean) => boolean; - setLayerOpacity: (name: string, opacity: number) => boolean; - findHighestMaxZoom: () => number; - findLowestMinZoom: () => number; - private getFeatureStyleProp; - getLayerByName: (layerName: string) => any; - getFeatureStyle: (layer: any, feature: any, isStrokeless?: boolean) => any; -} -export {}; diff --git a/dist/src/layers/model.d.ts b/dist/src/layers/model.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/layers/overlay.d.ts b/dist/src/layers/overlay.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/layers/tile.d.ts b/dist/src/layers/tile.d.ts deleted file mode 100644 index 69d5db6..0000000 --- a/dist/src/layers/tile.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default class TileLayerer { - p: any; - constructor(parent: any); - add: (layerObj: any) => void; - toggle: (name: string, on?: boolean) => boolean; - setOpacity: (name: string, opacity: number) => boolean; - remove: (name: string) => boolean; -} diff --git a/dist/src/layers/tile3d.d.ts b/dist/src/layers/tile3d.d.ts deleted file mode 100644 index 63e0a75..0000000 --- a/dist/src/layers/tile3d.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export default class Tile3dLayerer { - p: any; - constructor(parent: any); - add: (layerObj: any) => void; - toggle: (name: string, on?: boolean) => boolean; - setOpacity: (name: string, opacity: number) => boolean; - remove: (name: string) => boolean; - private generateTile3ds; - private localizeTile3ds; -} diff --git a/dist/src/layers/vector.d.ts b/dist/src/layers/vector.d.ts deleted file mode 100644 index 8b5ff02..0000000 --- a/dist/src/layers/vector.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export default class VectorLayerer { - p: any; - baseStyle: any; - constructor(parent: any); - add: (layerObj: any, callback?: Function) => void; - toggle: (name: string, on?: boolean) => boolean; - setOpacity: (name: string, opacity: number) => boolean; - remove: (name: string) => boolean; - private generateVectors; - private geomTo; -} diff --git a/dist/src/parsers/demt.d.ts b/dist/src/parsers/demt.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/parsers/rgba.d.ts b/dist/src/parsers/rgba.d.ts index 8786057..78d8857 100644 --- a/dist/src/parsers/rgba.d.ts +++ b/dist/src/parsers/rgba.d.ts @@ -1,3 +1 @@ -import '../secondary/PNG/zlib'; -import '../secondary/PNG/png'; export default function RGBAParser(tilePath: string, layerObj?: any, xyz?: any, tileResolution?: number, numberOfVertices?: number): Promise; diff --git a/dist/src/parsers/tif.d.ts b/dist/src/parsers/tif.d.ts deleted file mode 100644 index 60e1e10..0000000 --- a/dist/src/parsers/tif.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function TifParser(tilePath: string, layerObj?: any, xyz?: any, tileResolution?: number, numberOfVertices?: number): Promise; diff --git a/dist/src/secondary/OrbitControls.d.ts b/dist/src/secondary/OrbitControls.d.ts deleted file mode 100644 index cd0b176..0000000 --- a/dist/src/secondary/OrbitControls.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare function OrbitControls(object: any, domElement: any): void; -declare namespace OrbitControls { - var prototype: any; -} -export default OrbitControls; diff --git a/dist/src/secondary/PNG/png.d.ts b/dist/src/secondary/PNG/png.d.ts index e69de29..60f1afc 100644 --- a/dist/src/secondary/PNG/png.d.ts +++ b/dist/src/secondary/PNG/png.d.ts @@ -0,0 +1,16 @@ +export default class PNG { + static load(url: any, options: any, callback: any, failureCallback: any): void; + constructor(data1: any); + read(bytes: any): any[]; + readUInt32(): number; + readUInt16(): number; + decodePixels(data: any): Uint8Array; + decodePalette(): Uint8Array; + copyToImageData(imageData: any, pixels: any): void; + decode(): Uint8Array; + decodeFrames(ctx: any): void; + renderFrame(ctx: any, number: any): any; + animate(ctx: any): void; + stopAnimation(): void; + render(canvas: any): any; +} diff --git a/dist/src/secondary/PNG/zlib.d.ts b/dist/src/secondary/PNG/zlib.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/src/secondary/PointerLockControls.d.ts b/dist/src/secondary/PointerLockControls.d.ts deleted file mode 100644 index 6ee89e9..0000000 --- a/dist/src/secondary/PointerLockControls.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function PointerLockControls(camera: any): void; diff --git a/dist/src/secondary/loadingScreen.d.ts b/dist/src/secondary/loadingScreen.d.ts deleted file mode 100644 index 46b2871..0000000 --- a/dist/src/secondary/loadingScreen.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import './loadingScreen.scss'; -export default class Controls { - p: any; - loadingContainer: HTMLElement; - constructor(parent: any); - end: (name: any) => void; -} diff --git a/dist/src/secondary/sprites.d.ts b/dist/src/secondary/sprites.d.ts deleted file mode 100644 index e9fd951..0000000 --- a/dist/src/secondary/sprites.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Sprite } from 'three'; -declare const Sprites: { - spriteMaterials: {}; - makeMarkerSprite: (parameters: any, id: any, forceNewMaterial?: boolean) => Sprite; - makeMarkerMaterial: (parameters: any, id: any, forceNewMaterial?: boolean) => any; - makeTextSprite: (message: any, parameters: any) => Sprite; -}; -export default Sprites; diff --git a/dist/src/utils/index.d.ts b/dist/src/utils/index.d.ts deleted file mode 100644 index 94f2302..0000000 --- a/dist/src/utils/index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { XY, XYZ } from '../generalTypes'; -declare const Utils: { - getIn: (obj: any, keyArray: string[], notSetValue?: any) => any; - mod: (n: number, m: number) => number; - findHighestMaxZoom: (tileLayers: any) => number; - findLowestMinZoom: (tileLayers: any) => number; - isInExtent: (xyz: XYZ, bb: any, projection: any) => boolean; - clone: (obj: any) => any; - capitalizeFirstLetter: (string: string) => string; - getExtension: (string: string) => string; - getRadiansPerPixel: (zoom: number) => number; - lastTileContains: any[]; - tileContains: (xyz: any, z: number, useLast?: boolean) => any; - tileIsContained(xyzContainer: any, xyzContained: any, useLast?: boolean): boolean; - arrayAverage(array: any, key: string): number; - hexToRGB(hex: string): any; - rotatePoint(pt: any, center: any, angle: any): XY; - rotateAroundArbAxis(object: any, axis: any, radians: any, noPremultiply?: boolean): void; - getParamString(params: any, baseUrl: string, isUppercase?: boolean): string; - isArray(object: any): boolean; -}; -export default Utils; diff --git a/dist/src/utils/paths.d.ts b/dist/src/utils/paths.d.ts deleted file mode 100644 index b5778e1..0000000 --- a/dist/src/utils/paths.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -declare const Paths: { - buildPath: (format: string, basePath: string, tD: any, projection: any, tileResolution: number, trueTileResolution: number, options?: any, asObject?: boolean) => any; - wmsExtension: { - defaultWmsParams: { - SERVICE: string; - REQUEST: string; - FORMAT: string; - TRANSPARENT: boolean; - VERSION: string; - WIDTH: any; - HEIGHT: any; - }; - extensionOptions: { - crsCode: string; - uppercase: boolean; - }; - buildPath: (basePath: string, xyz: any, projection: any, tileResolution: number, trueTileResolution: number, options: any) => string; - }; -}; -export default Paths; diff --git a/package.json b/package.json index 39f2dec..43bcc4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lithosphere", - "version": "1.0.1", + "version": "1.0.2", "description": "LithoSphere is a GIS JavaScript library for building 3D tile-based globes in the web browser.", "author": "Tariq Soliman", "license": "Apache-2.0", diff --git a/src/parsers/rgba.ts b/src/parsers/rgba.ts index 267b910..f8db4f5 100644 --- a/src/parsers/rgba.ts +++ b/src/parsers/rgba.ts @@ -5,8 +5,7 @@ * Generated by gdal2customtiles_v3.py (name might change a bit if you're from the future) */ -import '../secondary/PNG/zlib' -import '../secondary/PNG/png' +import PNG from '../secondary/PNG/png' //import { NO_DATA_VALUE_INTERNAL } from '../constants' //import Utils from '../utils' diff --git a/src/secondary/PNG/png.ts b/src/secondary/PNG/png.ts index cda091d..5c746bf 100644 --- a/src/secondary/PNG/png.ts +++ b/src/secondary/PNG/png.ts @@ -20,389 +20,383 @@ // @ts-nocheck -window.PNG = (function () { - //let APNG_DISPOSE_OP_NONE = 0 - let APNG_DISPOSE_OP_BACKGROUND = 1 - let APNG_DISPOSE_OP_PREVIOUS = 2 - let APNG_BLEND_OP_SOURCE = 0 - //let APNG_BLEND_OP_OVER = 1 - let scratchCanvas = document.createElement('canvas') - let scratchCtx = scratchCanvas.getContext('2d') - let makeImage = function (imageData) { - scratchCtx.width = imageData.width - scratchCtx.height = imageData.height - scratchCtx.clearRect(0, 0, imageData.width, imageData.height) - scratchCtx.putImageData(imageData, 0, 0) - - const img = new Image() - img.src = scratchCanvas.toDataURL() - return img +import { FlateStream } from './zlib' + +//let APNG_DISPOSE_OP_NONE = 0 +let APNG_DISPOSE_OP_BACKGROUND = 1 +let APNG_DISPOSE_OP_PREVIOUS = 2 +let APNG_BLEND_OP_SOURCE = 0 +//let APNG_BLEND_OP_OVER = 1 +let scratchCanvas = document.createElement('canvas') +let scratchCtx = scratchCanvas.getContext('2d') +let makeImage = function (imageData) { + scratchCtx.width = imageData.width + scratchCtx.height = imageData.height + scratchCtx.clearRect(0, 0, imageData.width, imageData.height) + scratchCtx.putImageData(imageData, 0, 0) + + const img = new Image() + img.src = scratchCanvas.toDataURL() + return img +} + +export default class PNG { + static load(url, options, callback, failureCallback) { + const xhr = new XMLHttpRequest() + xhr.open('GET', url, true) + xhr.responseType = 'arraybuffer' + xhr.withCredentials = options.withCredentials + xhr.onload = () => { + const data = new Uint8Array( + xhr.response || xhr.mozResponseArrayBuffer + ) + if (xhr.status !== 404) { + const png = new PNG(data) + return typeof callback === 'function' + ? callback(png) + : undefined + } else if (typeof failureCallback === 'function') + failureCallback(xhr.status) + } + + return xhr.send() } - class PNG { - static load(url, options, callback, failureCallback) { - const xhr = new XMLHttpRequest() - xhr.open('GET', url, true) - xhr.responseType = 'arraybuffer' - xhr.withCredentials = options.withCredentials - xhr.onload = () => { - const data = new Uint8Array( - xhr.response || xhr.mozResponseArrayBuffer - ) - if (xhr.status !== 404) { - const png = new PNG(data) - return typeof callback === 'function' - ? callback(png) - : undefined - } else if (typeof failureCallback === 'function') - failureCallback(xhr.status) + constructor(data1) { + let i + this.data = data1 + this.pos = 8 // Skip the default header + + this.palette = [] + this.imgData = [] + this.transparency = {} + this.animation = null + this.text = {} + let frame = null + + while (true) { + var data + let chunkSize = this.readUInt32() + let section = '' + for (i = 0; i < 4; i++) { + section += String.fromCharCode(this.data[this.pos++]) } - return xhr.send() - } + switch (section) { + case 'IHDR': + // we can grab interesting values from here (like width, height, etc) + this.width = this.readUInt32() + this.height = this.readUInt32() + this.bits = this.data[this.pos++] + this.colorType = this.data[this.pos++] + this.compressionMethod = this.data[this.pos++] + this.filterMethod = this.data[this.pos++] + this.interlaceMethod = this.data[this.pos++] + break + + case 'acTL': + // we have an animated PNG + this.animation = { + numFrames: this.readUInt32(), + numPlays: this.readUInt32() || Infinity, + frames: [], + } + break - constructor(data1) { - let i - this.data = data1 - this.pos = 8 // Skip the default header - - this.palette = [] - this.imgData = [] - this.transparency = {} - this.animation = null - this.text = {} - let frame = null - - while (true) { - var data - let chunkSize = this.readUInt32() - let section = '' - for (i = 0; i < 4; i++) { - section += String.fromCharCode(this.data[this.pos++]) - } + case 'PLTE': + this.palette = this.read(chunkSize) + break - switch (section) { - case 'IHDR': - // we can grab interesting values from here (like width, height, etc) - this.width = this.readUInt32() - this.height = this.readUInt32() - this.bits = this.data[this.pos++] - this.colorType = this.data[this.pos++] - this.compressionMethod = this.data[this.pos++] - this.filterMethod = this.data[this.pos++] - this.interlaceMethod = this.data[this.pos++] - break + case 'fcTL': + if (frame) { + this.animation.frames.push(frame) + } - case 'acTL': - // we have an animated PNG - this.animation = { - numFrames: this.readUInt32(), - numPlays: this.readUInt32() || Infinity, - frames: [], - } - break + this.pos += 4 // skip sequence number + frame = { + width: this.readUInt32(), + height: this.readUInt32(), + xOffset: this.readUInt32(), + yOffset: this.readUInt32(), + } - case 'PLTE': - this.palette = this.read(chunkSize) - break + var delayNum = this.readUInt16() + var delayDen = this.readUInt16() || 100 + frame.delay = (1000 * delayNum) / delayDen - case 'fcTL': - if (frame) { - this.animation.frames.push(frame) - } + frame.disposeOp = this.data[this.pos++] + frame.blendOp = this.data[this.pos++] + frame.data = [] + break + case 'IDAT': + case 'fdAT': + if (section === 'fdAT') { this.pos += 4 // skip sequence number - frame = { - width: this.readUInt32(), - height: this.readUInt32(), - xOffset: this.readUInt32(), - yOffset: this.readUInt32(), - } - - var delayNum = this.readUInt16() - var delayDen = this.readUInt16() || 100 - frame.delay = (1000 * delayNum) / delayDen - - frame.disposeOp = this.data[this.pos++] - frame.blendOp = this.data[this.pos++] - frame.data = [] - break - - case 'IDAT': - case 'fdAT': - if (section === 'fdAT') { - this.pos += 4 // skip sequence number - chunkSize -= 4 - } - - data = (frame && frame.data) || this.imgData - for (i = 0; i < chunkSize; i++) { - data.push(this.data[this.pos++]) - } - break + chunkSize -= 4 + } - case 'tRNS': - // This chunk can only occur once and it must occur after the - // PLTE chunk and before the IDAT chunk. - this.transparency = {} - switch (this.colorType) { - case 3: - // Indexed color, RGB. Each byte in this chunk is an alpha for - // the palette index in the PLTE ("palette") chunk up until the - // last non-opaque entry. Set up an array, stretching over all - // palette entries which will be 0 (opaque) or 1 (transparent). - this.transparency.indexed = this.read(chunkSize) - var short = - 255 - this.transparency.indexed.length - if (short > 0) { - for (i = 0; i < short; i++) { - this.transparency.indexed.push(255) - } + data = (frame && frame.data) || this.imgData + for (i = 0; i < chunkSize; i++) { + data.push(this.data[this.pos++]) + } + break + + case 'tRNS': + // This chunk can only occur once and it must occur after the + // PLTE chunk and before the IDAT chunk. + this.transparency = {} + switch (this.colorType) { + case 3: + // Indexed color, RGB. Each byte in this chunk is an alpha for + // the palette index in the PLTE ("palette") chunk up until the + // last non-opaque entry. Set up an array, stretching over all + // palette entries which will be 0 (opaque) or 1 (transparent). + this.transparency.indexed = this.read(chunkSize) + var short = 255 - this.transparency.indexed.length + if (short > 0) { + for (i = 0; i < short; i++) { + this.transparency.indexed.push(255) } - break - case 0: - // Greyscale. Corresponding to entries in the PLTE chunk. - // Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1 - this.transparency.grayscale = this.read( - chunkSize - )[0] - break - case 2: - // True color with proper alpha channel. - this.transparency.rgb = this.read(chunkSize) - break - } - break - - case 'tEXt': - var text = this.read(chunkSize) - var index = text.indexOf(0) - var key = String.fromCharCode.apply( - String, - text.slice(0, index) - ) - this.text[key] = String.fromCharCode.apply( - String, - text.slice(index + 1) - ) - break + } + break + case 0: + // Greyscale. Corresponding to entries in the PLTE chunk. + // Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1 + this.transparency.grayscale = this.read( + chunkSize + )[0] + break + case 2: + // True color with proper alpha channel. + this.transparency.rgb = this.read(chunkSize) + break + } + break + + case 'tEXt': + var text = this.read(chunkSize) + var index = text.indexOf(0) + var key = String.fromCharCode.apply( + String, + text.slice(0, index) + ) + this.text[key] = String.fromCharCode.apply( + String, + text.slice(index + 1) + ) + break + + case 'IEND': + if (frame) { + this.animation.frames.push(frame) + } - case 'IEND': - if (frame) { - this.animation.frames.push(frame) - } + // we've got everything we need! + switch (this.colorType) { + case 0: + case 3: + case 4: + this.colors = 1 + break + case 2: + case 6: + this.colors = 3 + break + } - // we've got everything we need! - switch (this.colorType) { - case 0: - case 3: - case 4: - this.colors = 1 - break - case 2: - case 6: - this.colors = 3 - break - } + this.hasAlphaChannel = [4, 6].includes(this.colorType) + var colors = this.colors + (this.hasAlphaChannel ? 1 : 0) + this.pixelBitlength = this.bits * colors - this.hasAlphaChannel = [4, 6].includes(this.colorType) - var colors = - this.colors + (this.hasAlphaChannel ? 1 : 0) - this.pixelBitlength = this.bits * colors - - switch (this.colors) { - case 1: - this.colorSpace = 'DeviceGray' - break - case 3: - this.colorSpace = 'DeviceRGB' - break - } + switch (this.colors) { + case 1: + this.colorSpace = 'DeviceGray' + break + case 3: + this.colorSpace = 'DeviceRGB' + break + } - this.imgData = new Uint8Array(this.imgData) - return - break + this.imgData = new Uint8Array(this.imgData) + return + break - default: - // unknown (or unimportant) section, skip it - this.pos += chunkSize - } + default: + // unknown (or unimportant) section, skip it + this.pos += chunkSize + } - this.pos += 4 // Skip the CRC + this.pos += 4 // Skip the CRC - if (this.pos > this.data.length) { - throw new Error('Incomplete or corrupt PNG file') - } + if (this.pos > this.data.length) { + throw new Error('Incomplete or corrupt PNG file') } } + } - read(bytes) { - const result = new Array(bytes) - for (let i = 0; i < bytes; i++) { - result[i] = this.data[this.pos++] - } - return result + read(bytes) { + const result = new Array(bytes) + for (let i = 0; i < bytes; i++) { + result[i] = this.data[this.pos++] } + return result + } - readUInt32() { - const b1 = this.data[this.pos++] << 24 - const b2 = this.data[this.pos++] << 16 - const b3 = this.data[this.pos++] << 8 - const b4 = this.data[this.pos++] - return b1 | b2 | b3 | b4 - } + readUInt32() { + const b1 = this.data[this.pos++] << 24 + const b2 = this.data[this.pos++] << 16 + const b3 = this.data[this.pos++] << 8 + const b4 = this.data[this.pos++] + return b1 | b2 | b3 | b4 + } + + readUInt16() { + const b1 = this.data[this.pos++] << 8 + const b2 = this.data[this.pos++] + return b1 | b2 + } - readUInt16() { - const b1 = this.data[this.pos++] << 8 - const b2 = this.data[this.pos++] - return b1 | b2 + decodePixels(data) { + if (data == null) { + data = this.imgData + } + if (data.length === 0) { + return new Uint8Array(0) } - decodePixels(data) { - if (data == null) { - data = this.imgData - } - if (data.length === 0) { - return new Uint8Array(0) - } + data = new FlateStream(data) + data = data.getBytes() - data = new FlateStream(data) - data = data.getBytes() - - const { width, height } = this - const pixelBytes = this.pixelBitlength / 8 - - const pixels = new Uint8Array(width * height * pixelBytes) - const { length } = data - let pos = 0 - - function pass(x0, y0, dx, dy, singlePass = false) { - const w = Math.ceil((width - x0) / dx) - const h = Math.ceil((height - y0) / dy) - const scanlineLength = pixelBytes * w - const buffer = singlePass - ? pixels - : new Uint8Array(scanlineLength * h) - let row = 0 - let c = 0 - while (row < h && pos < length) { - var byte, col, i, left, upper - switch (data[pos++]) { - case 0: // None - for (i = 0; i < scanlineLength; i++) { - buffer[c++] = data[pos++] - } - break + const { width, height } = this + const pixelBytes = this.pixelBitlength / 8 - case 1: // Sub - for (i = 0; i < scanlineLength; i++) { - byte = data[pos++] - left = - i < pixelBytes ? 0 : buffer[c - pixelBytes] - buffer[c++] = (byte + left) % 256 - } - break + const pixels = new Uint8Array(width * height * pixelBytes) + const { length } = data + let pos = 0 + + function pass(x0, y0, dx, dy, singlePass = false) { + const w = Math.ceil((width - x0) / dx) + const h = Math.ceil((height - y0) / dy) + const scanlineLength = pixelBytes * w + const buffer = singlePass + ? pixels + : new Uint8Array(scanlineLength * h) + let row = 0 + let c = 0 + while (row < h && pos < length) { + var byte, col, i, left, upper + switch (data[pos++]) { + case 0: // None + for (i = 0; i < scanlineLength; i++) { + buffer[c++] = data[pos++] + } + break - case 2: // Up - for (i = 0; i < scanlineLength; i++) { - byte = data[pos++] - col = (i - (i % pixelBytes)) / pixelBytes + case 1: // Sub + for (i = 0; i < scanlineLength; i++) { + byte = data[pos++] + left = i < pixelBytes ? 0 : buffer[c - pixelBytes] + buffer[c++] = (byte + left) % 256 + } + break + + case 2: // Up + for (i = 0; i < scanlineLength; i++) { + byte = data[pos++] + col = (i - (i % pixelBytes)) / pixelBytes + upper = + row && + buffer[ + (row - 1) * scanlineLength + + col * pixelBytes + + (i % pixelBytes) + ] + buffer[c++] = (upper + byte) % 256 + } + break + + case 3: // Average + for (i = 0; i < scanlineLength; i++) { + byte = data[pos++] + col = (i - (i % pixelBytes)) / pixelBytes + left = i < pixelBytes ? 0 : buffer[c - pixelBytes] + upper = + row && + buffer[ + (row - 1) * scanlineLength + + col * pixelBytes + + (i % pixelBytes) + ] + buffer[c++] = + (byte + Math.floor((left + upper) / 2)) % 256 + } + break + + case 4: // Paeth + for (i = 0; i < scanlineLength; i++) { + var paeth, upperLeft + byte = data[pos++] + col = (i - (i % pixelBytes)) / pixelBytes + left = i < pixelBytes ? 0 : buffer[c - pixelBytes] + + if (row === 0) { + upper = upperLeft = 0 + } else { upper = - row && buffer[ (row - 1) * scanlineLength + col * pixelBytes + (i % pixelBytes) ] - buffer[c++] = (upper + byte) % 256 - } - break - - case 3: // Average - for (i = 0; i < scanlineLength; i++) { - byte = data[pos++] - col = (i - (i % pixelBytes)) / pixelBytes - left = - i < pixelBytes ? 0 : buffer[c - pixelBytes] - upper = - row && + upperLeft = + col && buffer[ (row - 1) * scanlineLength + - col * pixelBytes + + (col - 1) * pixelBytes + (i % pixelBytes) ] - buffer[c++] = - (byte + Math.floor((left + upper) / 2)) % - 256 } - break - - case 4: // Paeth - for (i = 0; i < scanlineLength; i++) { - var paeth, upperLeft - byte = data[pos++] - col = (i - (i % pixelBytes)) / pixelBytes - left = - i < pixelBytes ? 0 : buffer[c - pixelBytes] - - if (row === 0) { - upper = upperLeft = 0 - } else { - upper = - buffer[ - (row - 1) * scanlineLength + - col * pixelBytes + - (i % pixelBytes) - ] - upperLeft = - col && - buffer[ - (row - 1) * scanlineLength + - (col - 1) * pixelBytes + - (i % pixelBytes) - ] - } - - const p = left + upper - upperLeft - const pa = Math.abs(p - left) - const pb = Math.abs(p - upper) - const pc = Math.abs(p - upperLeft) - - if (pa <= pb && pa <= pc) { - paeth = left - } else if (pb <= pc) { - paeth = upper - } else { - paeth = upperLeft - } - buffer[c++] = (byte + paeth) % 256 + const p = left + upper - upperLeft + const pa = Math.abs(p - left) + const pb = Math.abs(p - upper) + const pc = Math.abs(p - upperLeft) + + if (pa <= pb && pa <= pc) { + paeth = left + } else if (pb <= pc) { + paeth = upper + } else { + paeth = upperLeft } - break - default: - throw new Error( - `Invalid filter algorithm: ${data[pos - 1]}` - ) - } - - if (!singlePass) { - let pixelsPos = - ((y0 + row * dy) * width + x0) * pixelBytes - let bufferPos = row * scanlineLength - for (i = 0; i < w; i++) { - for (let j = 0; j < pixelBytes; j++) - pixels[pixelsPos++] = buffer[bufferPos++] - pixelsPos += (dx - 1) * pixelBytes + buffer[c++] = (byte + paeth) % 256 } - } + break - row++ + default: + throw new Error( + `Invalid filter algorithm: ${data[pos - 1]}` + ) + } + + if (!singlePass) { + let pixelsPos = ((y0 + row * dy) * width + x0) * pixelBytes + let bufferPos = row * scanlineLength + for (i = 0; i < w; i++) { + for (let j = 0; j < pixelBytes; j++) + pixels[pixelsPos++] = buffer[bufferPos++] + pixelsPos += (dx - 1) * pixelBytes + } } + + row++ } + } - if (this.interlaceMethod === 1) { - /* + if (this.interlaceMethod === 1) { + /* 1 6 4 6 2 6 4 6 7 7 7 7 7 7 7 7 5 6 5 6 5 6 5 6 @@ -412,180 +406,173 @@ window.PNG = (function () { 5 6 5 6 5 6 5 6 7 7 7 7 7 7 7 7 */ - pass(0, 0, 8, 8) // 1 - pass(4, 0, 8, 8) // 2 - pass(0, 4, 4, 8) // 3 - pass(2, 0, 4, 4) // 4 - pass(0, 2, 2, 4) // 5 - pass(1, 0, 2, 2) // 6 - pass(0, 1, 1, 2) // 7 - } else { - pass(0, 0, 1, 1, true) - } - - return pixels + pass(0, 0, 8, 8) // 1 + pass(4, 0, 8, 8) // 2 + pass(0, 4, 4, 8) // 3 + pass(2, 0, 4, 4) // 4 + pass(0, 2, 2, 4) // 5 + pass(1, 0, 2, 2) // 6 + pass(0, 1, 1, 2) // 7 + } else { + pass(0, 0, 1, 1, true) } - decodePalette() { - const { palette } = this - const { length } = palette - const transparency = this.transparency.indexed || [] - const ret = new Uint8Array((transparency.length || 0) + length) - let pos = 0 - let c = 0 + return pixels + } - for (let i = 0; i < length; i += 3) { - var left - ret[pos++] = palette[i] - ret[pos++] = palette[i + 1] - ret[pos++] = palette[i + 2] - ret[pos++] = (left = transparency[c++]) != null ? left : 255 - } + decodePalette() { + const { palette } = this + const { length } = palette + const transparency = this.transparency.indexed || [] + const ret = new Uint8Array((transparency.length || 0) + length) + let pos = 0 + let c = 0 + + for (let i = 0; i < length; i += 3) { + var left + ret[pos++] = palette[i] + ret[pos++] = palette[i + 1] + ret[pos++] = palette[i + 2] + ret[pos++] = (left = transparency[c++]) != null ? left : 255 + } - return ret + return ret + } + + copyToImageData(imageData, pixels) { + let j, k + let { colors } = this + let palette = null + let alpha = this.hasAlphaChannel + + if (this.palette.length) { + palette = + this._decodedPalette || + (this._decodedPalette = this.decodePalette()) + colors = 4 + alpha = true } - copyToImageData(imageData, pixels) { - let j, k - let { colors } = this - let palette = null - let alpha = this.hasAlphaChannel - - if (this.palette.length) { - palette = - this._decodedPalette || - (this._decodedPalette = this.decodePalette()) - colors = 4 - alpha = true + const data = imageData.data || imageData + const { length } = data + const input = palette || pixels + let i = (j = 0) + + if (colors === 1) { + while (i < length) { + k = palette ? pixels[i / 4] * 4 : j + const v = input[k++] + data[i++] = v + data[i++] = v + data[i++] = v + data[i++] = alpha ? input[k++] : 255 + j = k } - - const data = imageData.data || imageData - const { length } = data - const input = palette || pixels - let i = (j = 0) - - if (colors === 1) { - while (i < length) { - k = palette ? pixels[i / 4] * 4 : j - const v = input[k++] - data[i++] = v - data[i++] = v - data[i++] = v - data[i++] = alpha ? input[k++] : 255 - j = k - } - } else { - while (i < length) { - k = palette ? pixels[i / 4] * 4 : j - data[i++] = input[k++] - data[i++] = input[k++] - data[i++] = input[k++] - data[i++] = alpha ? input[k++] : 255 - j = k - } + } else { + while (i < length) { + k = palette ? pixels[i / 4] * 4 : j + data[i++] = input[k++] + data[i++] = input[k++] + data[i++] = input[k++] + data[i++] = alpha ? input[k++] : 255 + j = k } } + } - decode() { - const ret = new Uint8Array(this.width * this.height * 4) - this.copyToImageData(ret, this.decodePixels()) - return ret - } + decode() { + const ret = new Uint8Array(this.width * this.height * 4) + this.copyToImageData(ret, this.decodePixels()) + return ret + } - decodeFrames(ctx) { - if (!this.animation) { - return - } + decodeFrames(ctx) { + if (!this.animation) { + return + } - for (let i = 0; i < this.animation.frames.length; i++) { - const frame = this.animation.frames[i] - const imageData = ctx.createImageData(frame.width, frame.height) - const pixels = this.decodePixels(new Uint8Array(frame.data)) + for (let i = 0; i < this.animation.frames.length; i++) { + const frame = this.animation.frames[i] + const imageData = ctx.createImageData(frame.width, frame.height) + const pixels = this.decodePixels(new Uint8Array(frame.data)) - this.copyToImageData(imageData, pixels) - frame.imageData = imageData - frame.image = makeImage(imageData) - } + this.copyToImageData(imageData, pixels) + frame.imageData = imageData + frame.image = makeImage(imageData) } + } - renderFrame(ctx, number) { - const { frames } = this.animation - const frame = frames[number] - const prev = frames[number - 1] + renderFrame(ctx, number) { + const { frames } = this.animation + const frame = frames[number] + const prev = frames[number - 1] - // if we're on the first frame, clear the canvas - if (number === 0) { - ctx.clearRect(0, 0, this.width, this.height) - } - - // check the previous frame's dispose operation - if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_BACKGROUND) { - ctx.clearRect( - prev.xOffset, - prev.yOffset, - prev.width, - prev.height - ) - } else if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_PREVIOUS) { - ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset) - } + // if we're on the first frame, clear the canvas + if (number === 0) { + ctx.clearRect(0, 0, this.width, this.height) + } - // APNG_BLEND_OP_SOURCE overwrites the previous data - if (frame.blendOp === APNG_BLEND_OP_SOURCE) { - ctx.clearRect( - frame.xOffset, - frame.yOffset, - frame.width, - frame.height - ) - } + // check the previous frame's dispose operation + if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_BACKGROUND) { + ctx.clearRect(prev.xOffset, prev.yOffset, prev.width, prev.height) + } else if ((prev && prev.disposeOp) === APNG_DISPOSE_OP_PREVIOUS) { + ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset) + } - // draw the current frame - return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset) + // APNG_BLEND_OP_SOURCE overwrites the previous data + if (frame.blendOp === APNG_BLEND_OP_SOURCE) { + ctx.clearRect( + frame.xOffset, + frame.yOffset, + frame.width, + frame.height + ) } - animate(ctx) { - let frameNumber = 0 - const { numFrames, frames, numPlays } = this.animation + // draw the current frame + return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset) + } - const doFrame = () => { - const f = frameNumber++ % numFrames - const frame = frames[f] - this.renderFrame(ctx, f) + animate(ctx) { + let frameNumber = 0 + const { numFrames, frames, numPlays } = this.animation - if (numFrames > 1 && frameNumber / numFrames < numPlays) { - this.animation._timeout = setTimeout(doFrame, frame.delay) - } - } + const doFrame = () => { + const f = frameNumber++ % numFrames + const frame = frames[f] + this.renderFrame(ctx, f) - doFrame() + if (numFrames > 1 && frameNumber / numFrames < numPlays) { + this.animation._timeout = setTimeout(doFrame, frame.delay) + } } - stopAnimation() { - return clearTimeout(this.animation && this.animation._timeout) - } + doFrame() + } - render(canvas) { - // if this canvas was displaying another image before, - // stop the animation on it - if (canvas._png) { - canvas._png.stopAnimation() - } + stopAnimation() { + return clearTimeout(this.animation && this.animation._timeout) + } - canvas._png = this - canvas.width = this.width - canvas.height = this.height - const ctx = canvas.getContext('2d') - - if (this.animation) { - this.decodeFrames(ctx) - return this.animate(ctx) - } else { - const data = ctx.createImageData(this.width, this.height) - this.copyToImageData(data, this.decodePixels()) - return ctx.putImageData(data, 0, 0) - } + render(canvas) { + // if this canvas was displaying another image before, + // stop the animation on it + if (canvas._png) { + canvas._png.stopAnimation() + } + + canvas._png = this + canvas.width = this.width + canvas.height = this.height + const ctx = canvas.getContext('2d') + + if (this.animation) { + this.decodeFrames(ctx) + return this.animate(ctx) + } else { + const data = ctx.createImageData(this.width, this.height) + this.copyToImageData(data, this.decodePixels()) + return ctx.putImageData(data, 0, 0) } } - return PNG -})() +} diff --git a/src/secondary/PNG/zlib.ts b/src/secondary/PNG/zlib.ts index 0a630da..61ffac5 100644 --- a/src/secondary/PNG/zlib.ts +++ b/src/secondary/PNG/zlib.ts @@ -32,7 +32,7 @@ // @ts-nocheck -window.DecodeStream = (function () { +const DecodeStream = (function () { function constructor() { this.pos = 0 this.bufferLength = 0 @@ -116,7 +116,7 @@ window.DecodeStream = (function () { return constructor })() -window.FlateStream = (function () { +export const FlateStream = (function () { var codeLenCodeMap = new Uint32Array([ 16, 17,